2 * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
39 #include <linux/tcp.h>
40 #include <linux/if_arp.h>
41 #include <linux/if_vlan.h>
42 #include <linux/ethtool.h>
45 #include <net/inet_common.h>
46 #include <linux/inet.h>
50 static struct nic_qp_map nic_qp_mapping_0[] = {
51 {16,0,0,1},{24,4,0,0},{28,8,0,0},{32,12,0,0},
52 {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0},
53 {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
54 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
57 static struct nic_qp_map nic_qp_mapping_1[] = {
58 {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
59 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
62 static struct nic_qp_map nic_qp_mapping_2[] = {
63 {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0}
66 static struct nic_qp_map nic_qp_mapping_3[] = {
67 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
70 static struct nic_qp_map nic_qp_mapping_4[] = {
71 {28,8,0,0},{32,12,0,0}
74 static struct nic_qp_map nic_qp_mapping_5[] = {
75 {29,9,1,0},{33,13,1,0}
78 static struct nic_qp_map nic_qp_mapping_6[] = {
79 {30,10,2,0},{34,14,2,0}
82 static struct nic_qp_map nic_qp_mapping_7[] = {
83 {31,11,3,0},{35,15,3,0}
86 static struct nic_qp_map *nic_qp_mapping_per_function[] = {
87 nic_qp_mapping_0, nic_qp_mapping_1, nic_qp_mapping_2, nic_qp_mapping_3,
88 nic_qp_mapping_4, nic_qp_mapping_5, nic_qp_mapping_6, nic_qp_mapping_7
91 static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
92 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
93 static int debug = -1;
96 static int nes_netdev_open(struct net_device *);
97 static int nes_netdev_stop(struct net_device *);
98 static int nes_netdev_start_xmit(struct sk_buff *, struct net_device *);
99 static struct net_device_stats *nes_netdev_get_stats(struct net_device *);
100 static void nes_netdev_tx_timeout(struct net_device *);
101 static int nes_netdev_set_mac_address(struct net_device *, void *);
102 static int nes_netdev_change_mtu(struct net_device *, int);
107 static int nes_netdev_poll(struct napi_struct *napi, int budget)
109 struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi);
110 struct net_device *netdev = nesvnic->netdev;
111 struct nes_device *nesdev = nesvnic->nesdev;
112 struct nes_hw_nic_cq *nescq = &nesvnic->nic_cq;
114 nesvnic->budget = budget;
115 nescq->cqes_pending = 0;
116 nescq->rx_cqes_completed = 0;
117 nescq->cqe_allocs_pending = 0;
118 nescq->rx_pkts_indicated = 0;
120 nes_nic_ce_handler(nesdev, nescq);
122 if (nescq->cqes_pending == 0) {
123 netif_rx_complete(netdev, napi);
124 /* clear out completed cqes and arm */
125 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
126 nescq->cq_number | (nescq->cqe_allocs_pending << 16));
127 nes_read32(nesdev->regs+NES_CQE_ALLOC);
129 /* clear out completed cqes but don't arm */
130 nes_write32(nesdev->regs+NES_CQE_ALLOC,
131 nescq->cq_number | (nescq->cqe_allocs_pending << 16));
132 nes_debug(NES_DBG_NETDEV, "%s: exiting with work pending\n",
133 nesvnic->netdev->name);
135 return nescq->rx_pkts_indicated;
140 * nes_netdev_open - Activate the network interface; ifconfig
143 static int nes_netdev_open(struct net_device *netdev)
147 struct nes_vnic *nesvnic = netdev_priv(netdev);
148 struct nes_device *nesdev = nesvnic->nesdev;
151 struct nes_vnic *first_nesvnic;
155 assert(nesdev != NULL);
157 first_nesvnic = list_entry(nesdev->nesadapter->nesvnic_list[nesdev->mac_index].next,
158 struct nes_vnic, list);
160 if (netif_msg_ifup(nesvnic))
161 printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name);
163 ret = nes_init_nic_qp(nesdev, netdev);
168 netif_carrier_off(netdev);
169 netif_stop_queue(netdev);
171 if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) {
172 nesvnic->nesibdev = nes_init_ofa_device(netdev);
173 if (nesvnic->nesibdev == NULL) {
174 printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name);
176 nesvnic->nesibdev->nesvnic = nesvnic;
177 ret = nes_register_ofa_device(nesvnic->nesibdev);
179 printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n",
184 /* Set packet filters */
185 nic_active_bit = 1 << nesvnic->nic_index;
186 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
187 nic_active |= nic_active_bit;
188 nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
189 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
190 nic_active |= nic_active_bit;
191 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
192 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
193 nic_active |= nic_active_bit;
194 nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
196 macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
197 macaddr_high += (u16)netdev->dev_addr[1];
198 macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
199 macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
200 macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
201 macaddr_low += (u32)netdev->dev_addr[5];
203 /* Program the various MAC regs */
204 for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
205 if (nesvnic->qp_nic_index[i] == 0xf) {
208 nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW"
209 " (Addr:%08X) = %08X, HIGH = %08X.\n",
210 i, nesvnic->qp_nic_index[i],
211 NES_IDX_PERFECT_FILTER_LOW+((nesvnic->perfect_filter_index + i) * 8),
213 (u32)macaddr_high | NES_MAC_ADDR_VALID |
214 ((((u32)nesvnic->nic_index) << 16)));
215 nes_write_indexed(nesdev,
216 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
218 nes_write_indexed(nesdev,
219 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
220 (u32)macaddr_high | NES_MAC_ADDR_VALID |
221 ((((u32)nesvnic->nic_index) << 16)));
225 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
226 nesvnic->nic_cq.cq_number);
227 nes_read32(nesdev->regs+NES_CQE_ALLOC);
229 if (first_nesvnic->linkup) {
230 /* Enable network packets */
232 netif_start_queue(netdev);
233 netif_carrier_on(netdev);
235 napi_enable(&nesvnic->napi);
236 nesvnic->netdev_open = 1;
245 static int nes_netdev_stop(struct net_device *netdev)
247 struct nes_vnic *nesvnic = netdev_priv(netdev);
248 struct nes_device *nesdev = nesvnic->nesdev;
252 nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n",
253 nesvnic, nesdev, netdev, netdev->name);
254 if (nesvnic->netdev_open == 0)
257 if (netif_msg_ifdown(nesvnic))
258 printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);
260 /* Disable network packets */
261 napi_disable(&nesvnic->napi);
262 netif_stop_queue(netdev);
263 if ((nesdev->netdev[0] == netdev) & (nesvnic->logical_port == nesdev->mac_index)) {
264 nes_write_indexed(nesdev,
265 NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
268 nic_active_mask = ~((u32)(1 << nesvnic->nic_index));
269 nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+
270 (nesvnic->perfect_filter_index*8), 0);
271 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
272 nic_active &= nic_active_mask;
273 nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
274 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
275 nic_active &= nic_active_mask;
276 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
277 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
278 nic_active &= nic_active_mask;
279 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
280 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
281 nic_active &= nic_active_mask;
282 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
283 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
284 nic_active &= nic_active_mask;
285 nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
288 if (nesvnic->of_device_registered) {
289 nes_destroy_ofa_device(nesvnic->nesibdev);
290 nesvnic->nesibdev = NULL;
291 nesvnic->of_device_registered = 0;
293 nes_destroy_nic_qp(nesvnic);
295 nesvnic->netdev_open = 0;
304 static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev)
306 struct nes_vnic *nesvnic = netdev_priv(netdev);
307 struct nes_device *nesdev = nesvnic->nesdev;
308 struct nes_hw_nic *nesnic = &nesvnic->nic;
309 struct nes_hw_nic_sq_wqe *nic_sqe;
311 __le16 *wqe_fragment_length;
313 u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
314 u16 skb_fragment_index;
315 dma_addr_t bus_address;
317 nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
318 wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
320 /* setup the VLAN tag if present */
321 if (vlan_tx_tag_present(skb)) {
322 nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
323 netdev->name, vlan_tx_tag_get(skb));
324 wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
325 wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
329 /* bump past the vlan tag */
330 wqe_fragment_length++;
331 /* wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */
333 if (skb->ip_summed == CHECKSUM_PARTIAL) {
336 if (skb_is_gso(skb)) {
337 /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... seg size = %u\n",
338 netdev->name, skb_is_gso(skb)); */
339 wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE |
340 NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
341 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
343 (((u32)(((unsigned char *)tcph) - skb->data)) << 4));
345 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION;
348 } else { /* CHECKSUM_HW */
349 wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM | NES_NIC_SQ_WQE_COMPLETION;
352 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
354 memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
355 skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb)));
356 wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
358 wqe_fragment_length[1] = 0;
359 if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
360 if ((skb_shinfo(skb)->nr_frags + 1) > 4) {
361 nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n",
362 netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb));
364 nesvnic->tx_sw_dropped++;
365 return NETDEV_TX_LOCKED;
367 set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
368 bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE,
369 skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE);
370 wqe_fragment_length[wqe_fragment_index++] =
371 cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE);
372 wqe_fragment_length[wqe_fragment_index] = 0;
373 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
374 ((u64)(bus_address)));
375 nesnic->tx_skb[nesnic->sq_head] = skb;
378 if (skb_headlen(skb) == skb->len) {
379 if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) {
380 nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0;
381 nesnic->tx_skb[nesnic->sq_head] = NULL;
385 /* Deal with Fragments */
386 nesnic->tx_skb[nesnic->sq_head] = skb;
387 for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags;
388 skb_fragment_index++) {
389 bus_address = pci_map_page( nesdev->pcidev,
390 skb_shinfo(skb)->frags[skb_fragment_index].page,
391 skb_shinfo(skb)->frags[skb_fragment_index].page_offset,
392 skb_shinfo(skb)->frags[skb_fragment_index].size,
394 wqe_fragment_length[wqe_fragment_index] =
395 cpu_to_le16(skb_shinfo(skb)->frags[skb_fragment_index].size);
396 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
398 wqe_fragment_index++;
399 if (wqe_fragment_index < 5)
400 wqe_fragment_length[wqe_fragment_index] = 0;
404 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc);
406 nesnic->sq_head &= nesnic->sq_size - 1;
413 * nes_netdev_start_xmit
415 static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev)
417 struct nes_vnic *nesvnic = netdev_priv(netdev);
418 struct nes_device *nesdev = nesvnic->nesdev;
419 struct nes_hw_nic *nesnic = &nesvnic->nic;
420 struct nes_hw_nic_sq_wqe *nic_sqe;
422 /* struct udphdr *udph; */
423 #define NES_MAX_TSO_FRAGS 18
424 /* 64K segment plus overflow on each side */
425 dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS];
426 dma_addr_t bus_address;
435 __le16 *wqe_fragment_length;
437 u32 original_first_length;
438 // u64 *wqe_fragment_address;
439 /* first fragment (0) is used by copy buffer */
440 u16 wqe_fragment_index=1;
448 /* nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
449 " (%u frags), tso_size=%u\n",
450 netdev->name, skb->len, skb_headlen(skb),
451 skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
454 if (!netif_carrier_ok(netdev))
457 if (netif_queue_stopped(netdev))
458 return NETDEV_TX_BUSY;
460 local_irq_save(flags);
461 if (!spin_trylock(&nesnic->sq_lock)) {
462 local_irq_restore(flags);
463 nesvnic->sq_locked++;
464 return NETDEV_TX_LOCKED;
467 /* Check if SQ is full */
468 if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) {
469 if (!netif_queue_stopped(netdev)) {
470 netif_stop_queue(netdev);
472 if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) {
473 netif_start_queue(netdev);
474 goto sq_no_longer_full;
478 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
479 return NETDEV_TX_BUSY;
483 nr_frags = skb_shinfo(skb)->nr_frags;
484 if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
487 /* Check if too many fragments */
488 if (unlikely((nr_frags > 4))) {
489 if (skb_is_gso(skb)) {
490 nesvnic->segmented_tso_requests++;
491 nesvnic->tso_requests++;
492 old_head = nesnic->sq_head;
493 /* Basically 4 fragments available per WQE with extended fragments */
494 wqes_needed = nr_frags >> 2;
495 wqes_needed += (nr_frags&3)?1:0;
496 wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) &
497 (nesnic->sq_size - 1);
499 if (unlikely(wqes_needed > wqes_available)) {
500 if (!netif_queue_stopped(netdev)) {
501 netif_stop_queue(netdev);
503 wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) &
504 (nesnic->sq_size - 1);
505 if (wqes_needed <= wqes_available) {
506 netif_start_queue(netdev);
507 goto tso_sq_no_longer_full;
511 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
512 nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n",
514 return NETDEV_TX_BUSY;
516 tso_sq_no_longer_full:
517 /* Map all the buffers */
518 for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags;
520 tso_bus_address[tso_frag_count] = pci_map_page( nesdev->pcidev,
521 skb_shinfo(skb)->frags[tso_frag_count].page,
522 skb_shinfo(skb)->frags[tso_frag_count].page_offset,
523 skb_shinfo(skb)->frags[tso_frag_count].size,
528 curr_tcp_seq = ntohl(tcp_hdr(skb)->seq);
529 hoffset = skb_transport_header(skb) - skb->data;
530 nhoffset = skb_network_header(skb) - skb->data;
531 original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2);
533 for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) {
535 nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
536 wqe_fragment_length =
537 (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
538 /* setup the VLAN tag if present */
539 if (vlan_tx_tag_present(skb)) {
540 nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
541 netdev->name, vlan_tx_tag_get(skb) );
542 wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
543 wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
547 /* bump past the vlan tag */
548 wqe_fragment_length++;
550 /* Assumes header totally fits in allocated buffer and is in first fragment */
551 if (original_first_length > NES_FIRST_FRAG_SIZE) {
552 nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
553 original_first_length, NES_FIRST_FRAG_SIZE);
554 nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
555 " (%u frags), tso_size=%u\n",
557 skb->len, skb_headlen(skb),
558 skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
560 memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
561 skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE),
562 original_first_length));
563 iph = (struct iphdr *)
564 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]);
565 tcph = (struct tcphdr *)
566 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]);
567 if ((wqe_count+1)!=(u32)wqes_needed) {
576 tcph->seq = htonl(curr_tcp_seq);
577 wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
578 original_first_length));
580 wqe_fragment_index = 1;
581 if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) {
582 set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
583 bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length,
584 skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE);
585 wqe_fragment_length[wqe_fragment_index++] =
586 cpu_to_le16(skb_headlen(skb) - original_first_length);
587 wqe_fragment_length[wqe_fragment_index] = 0;
588 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
591 while (wqe_fragment_index < 5) {
592 wqe_fragment_length[wqe_fragment_index] =
593 cpu_to_le16(skb_shinfo(skb)->frags[tso_frag_index].size);
594 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
595 (u64)tso_bus_address[tso_frag_index]);
596 wqe_fragment_index++;
597 tso_wqe_length += skb_shinfo(skb)->frags[tso_frag_index++].size;
598 if (wqe_fragment_index < 5)
599 wqe_fragment_length[wqe_fragment_index] = 0;
600 if (tso_frag_index == tso_frag_count)
603 if ((wqe_count+1) == (u32)wqes_needed) {
604 nesnic->tx_skb[nesnic->sq_head] = skb;
606 nesnic->tx_skb[nesnic->sq_head] = NULL;
608 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
609 if ((tso_wqe_length + original_first_length) > skb_is_gso(skb)) {
610 wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE;
612 iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset);
615 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX,
617 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
618 ((u32)tcph->doff) | (((u32)hoffset) << 4));
620 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
621 tso_wqe_length + original_first_length);
622 curr_tcp_seq += tso_wqe_length;
624 nesnic->sq_head &= nesnic->sq_size-1;
627 nesvnic->linearized_skbs++;
628 hoffset = skb_transport_header(skb) - skb->data;
629 nhoffset = skb_network_header(skb) - skb->data;
631 skb_set_transport_header(skb, hoffset);
632 skb_set_network_header(skb, nhoffset);
633 send_rc = nes_nic_send(skb, netdev);
634 if (send_rc != NETDEV_TX_OK) {
635 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
640 send_rc = nes_nic_send(skb, netdev);
641 if (send_rc != NETDEV_TX_OK) {
642 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
650 nes_write32(nesdev->regs+NES_WQE_ALLOC,
651 (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id);
653 netdev->trans_start = jiffies;
654 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
661 * nes_netdev_get_stats
663 static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev)
665 struct nes_vnic *nesvnic = netdev_priv(netdev);
666 struct nes_device *nesdev = nesvnic->nesdev;
670 u32temp = nes_read_indexed(nesdev,
671 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200));
672 nesvnic->netstats.rx_dropped += u32temp;
673 nesvnic->endnode_nstat_rx_discard += u32temp;
675 u64temp = (u64)nes_read_indexed(nesdev,
676 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + (nesvnic->nic_index*0x200));
677 u64temp += ((u64)nes_read_indexed(nesdev,
678 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
680 nesvnic->endnode_nstat_rx_octets += u64temp;
681 nesvnic->netstats.rx_bytes += u64temp;
683 u64temp = (u64)nes_read_indexed(nesdev,
684 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + (nesvnic->nic_index*0x200));
685 u64temp += ((u64)nes_read_indexed(nesdev,
686 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
688 nesvnic->endnode_nstat_rx_frames += u64temp;
689 nesvnic->netstats.rx_packets += u64temp;
691 u64temp = (u64)nes_read_indexed(nesdev,
692 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + (nesvnic->nic_index*0x200));
693 u64temp += ((u64)nes_read_indexed(nesdev,
694 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
696 nesvnic->endnode_nstat_tx_octets += u64temp;
697 nesvnic->netstats.tx_bytes += u64temp;
699 u64temp = (u64)nes_read_indexed(nesdev,
700 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + (nesvnic->nic_index*0x200));
701 u64temp += ((u64)nes_read_indexed(nesdev,
702 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
704 nesvnic->endnode_nstat_tx_frames += u64temp;
705 nesvnic->netstats.tx_packets += u64temp;
707 u32temp = nes_read_indexed(nesdev,
708 NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
709 nesvnic->netstats.rx_dropped += u32temp;
710 nesvnic->nesdev->mac_rx_errors += u32temp;
711 nesvnic->nesdev->mac_rx_short_frames += u32temp;
713 u32temp = nes_read_indexed(nesdev,
714 NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
715 nesvnic->netstats.rx_dropped += u32temp;
716 nesvnic->nesdev->mac_rx_errors += u32temp;
717 nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
719 u32temp = nes_read_indexed(nesdev,
720 NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
721 nesvnic->netstats.rx_dropped += u32temp;
722 nesvnic->nesdev->mac_rx_errors += u32temp;
723 nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
725 u32temp = nes_read_indexed(nesdev,
726 NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
727 nesvnic->netstats.rx_dropped += u32temp;
728 nesvnic->nesdev->mac_rx_errors += u32temp;
729 nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
731 u32temp = nes_read_indexed(nesdev,
732 NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
733 nesvnic->netstats.rx_length_errors += u32temp;
734 nesvnic->nesdev->mac_rx_errors += u32temp;
736 u32temp = nes_read_indexed(nesdev,
737 NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
738 nesvnic->nesdev->mac_rx_errors += u32temp;
739 nesvnic->nesdev->mac_rx_crc_errors += u32temp;
740 nesvnic->netstats.rx_crc_errors += u32temp;
742 u32temp = nes_read_indexed(nesdev,
743 NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
744 nesvnic->nesdev->mac_tx_errors += u32temp;
745 nesvnic->netstats.tx_errors += u32temp;
747 return &nesvnic->netstats;
752 * nes_netdev_tx_timeout
754 static void nes_netdev_tx_timeout(struct net_device *netdev)
756 struct nes_vnic *nesvnic = netdev_priv(netdev);
758 if (netif_msg_timer(nesvnic))
759 nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name);
764 * nes_netdev_set_mac_address
766 static int nes_netdev_set_mac_address(struct net_device *netdev, void *p)
768 struct nes_vnic *nesvnic = netdev_priv(netdev);
769 struct nes_device *nesdev = nesvnic->nesdev;
770 struct sockaddr *mac_addr = p;
775 if (!is_valid_ether_addr(mac_addr->sa_data))
776 return -EADDRNOTAVAIL;
778 memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
779 printk(PFX "%s: Address length = %d, Address = %02X%02X%02X%02X%02X%02X..\n",
780 __FUNCTION__, netdev->addr_len,
781 mac_addr->sa_data[0], mac_addr->sa_data[1],
782 mac_addr->sa_data[2], mac_addr->sa_data[3],
783 mac_addr->sa_data[4], mac_addr->sa_data[5]);
784 macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
785 macaddr_high += (u16)netdev->dev_addr[1];
786 macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
787 macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
788 macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
789 macaddr_low += (u32)netdev->dev_addr[5];
791 for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
792 if (nesvnic->qp_nic_index[i] == 0xf) {
795 nes_write_indexed(nesdev,
796 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
798 nes_write_indexed(nesdev,
799 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
800 (u32)macaddr_high | NES_MAC_ADDR_VALID |
801 ((((u32)nesvnic->nic_index) << 16)));
808 * nes_netdev_set_multicast_list
810 void nes_netdev_set_multicast_list(struct net_device *netdev)
812 struct nes_vnic *nesvnic = netdev_priv(netdev);
813 struct nes_device *nesdev = nesvnic->nesdev;
814 struct dev_mc_list *multicast_addr;
817 u32 perfect_filter_register_address;
822 int mc_nic_index = -1;
824 nic_active_bit = 1 << nesvnic->nic_index;
826 if (netdev->flags & IFF_PROMISC) {
827 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
828 nic_active |= nic_active_bit;
829 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
830 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
831 nic_active |= nic_active_bit;
832 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
834 } else if ((netdev->flags & IFF_ALLMULTI) || (netdev->mc_count > NES_MULTICAST_PF_MAX) ||
835 (nesvnic->nic_index > 3)) {
836 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
837 nic_active |= nic_active_bit;
838 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
839 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
840 nic_active &= ~nic_active_bit;
841 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
844 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
845 nic_active &= ~nic_active_bit;
846 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
847 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
848 nic_active &= ~nic_active_bit;
849 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
852 nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscous = %d, All Multicast = %d.\n",
853 netdev->mc_count, (netdev->flags & IFF_PROMISC)?1:0,
854 (netdev->flags & IFF_ALLMULTI)?1:0);
856 multicast_addr = netdev->mc_list;
857 perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW + 0x80;
858 perfect_filter_register_address += nesvnic->nic_index*0x40;
859 for (mc_index=0; mc_index < NES_MULTICAST_PF_MAX; mc_index++) {
860 while (multicast_addr && nesvnic->mcrq_mcast_filter && ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic, multicast_addr->dmi_addr)) == 0))
861 multicast_addr = multicast_addr->next;
863 if (mc_nic_index < 0)
864 mc_nic_index = nesvnic->nic_index;
865 if (multicast_addr) {
866 nes_debug(NES_DBG_NIC_RX, "Assigning MC Address = %02X%02X%02X%02X%02X%02X to register 0x%04X nic_idx=%d\n",
867 multicast_addr->dmi_addr[0], multicast_addr->dmi_addr[1],
868 multicast_addr->dmi_addr[2], multicast_addr->dmi_addr[3],
869 multicast_addr->dmi_addr[4], multicast_addr->dmi_addr[5],
870 perfect_filter_register_address+(mc_index * 8), mc_nic_index);
871 macaddr_high = ((u16)multicast_addr->dmi_addr[0]) << 8;
872 macaddr_high += (u16)multicast_addr->dmi_addr[1];
873 macaddr_low = ((u32)multicast_addr->dmi_addr[2]) << 24;
874 macaddr_low += ((u32)multicast_addr->dmi_addr[3]) << 16;
875 macaddr_low += ((u32)multicast_addr->dmi_addr[4]) << 8;
876 macaddr_low += (u32)multicast_addr->dmi_addr[5];
877 nes_write_indexed(nesdev,
878 perfect_filter_register_address+(mc_index * 8),
880 nes_write_indexed(nesdev,
881 perfect_filter_register_address+4+(mc_index * 8),
882 (u32)macaddr_high | NES_MAC_ADDR_VALID |
883 ((((u32)(1<<mc_nic_index)) << 16)));
884 multicast_addr = multicast_addr->next;
886 nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n",
887 perfect_filter_register_address+(mc_index * 8));
888 nes_write_indexed(nesdev,
889 perfect_filter_register_address+4+(mc_index * 8),
898 * nes_netdev_change_mtu
900 static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
902 struct nes_vnic *nesvnic = netdev_priv(netdev);
903 struct nes_device *nesdev = nesvnic->nesdev;
907 if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu))
910 netdev->mtu = new_mtu;
911 nesvnic->max_frame_size = new_mtu+ETH_HLEN;
913 if (netdev->mtu > 1500) {
916 nes_nic_init_timer_defaults(nesdev, jumbomode);
918 if (netif_running(netdev)) {
919 nes_netdev_stop(netdev);
920 nes_netdev_open(netdev);
928 * nes_netdev_exit - destroy network device
930 void nes_netdev_exit(struct nes_vnic *nesvnic)
932 struct net_device *netdev = nesvnic->netdev;
933 struct nes_ib_device *nesibdev = nesvnic->nesibdev;
935 nes_debug(NES_DBG_SHUTDOWN, "\n");
937 // destroy the ibdevice if RDMA enabled
938 if ((nesvnic->rdma_enabled)&&(nesvnic->of_device_registered)) {
939 nes_destroy_ofa_device( nesibdev );
940 nesvnic->of_device_registered = 0;
941 nesvnic->nesibdev = NULL;
943 unregister_netdev(netdev);
944 nes_debug(NES_DBG_SHUTDOWN, "\n");
948 #define NES_ETHTOOL_STAT_COUNT 55
949 static const char nes_ethtool_stringset[NES_ETHTOOL_STAT_COUNT][ETH_GSTRING_LEN] = {
950 "Link Change Interrupts",
954 "Pause Frames Received",
955 "Internal Routing Errors",
956 "SQ SW Dropped SKBs",
959 "Segmented TSO Requests",
962 "Rx Oversized Frames",
964 "Endnode Rx Discards",
971 "Retransmission Count",
984 "CM Packets Bounced",
985 "CM Packets Created",
987 "CM Packets Dropped",
988 "CM Packets Retrans",
989 "CM Listens Created",
990 "CM Listens Destroyed",
994 "CM Nodes Destroyed",
996 "CM Resets Received",
1009 * nes_netdev_get_rx_csum
1011 static u32 nes_netdev_get_rx_csum (struct net_device *netdev)
1013 struct nes_vnic *nesvnic = netdev_priv(netdev);
1015 if (nesvnic->rx_checksum_disabled)
1023 * nes_netdev_set_rc_csum
1025 static int nes_netdev_set_rx_csum(struct net_device *netdev, u32 enable)
1027 struct nes_vnic *nesvnic = netdev_priv(netdev);
1030 nesvnic->rx_checksum_disabled = 0;
1032 nesvnic->rx_checksum_disabled = 1;
1038 * nes_netdev_get_stats_count
1040 static int nes_netdev_get_stats_count(struct net_device *netdev)
1042 return NES_ETHTOOL_STAT_COUNT;
1047 * nes_netdev_get_strings
1049 static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset,
1050 u8 *ethtool_strings)
1052 if (stringset == ETH_SS_STATS)
1053 memcpy(ethtool_strings,
1054 &nes_ethtool_stringset,
1055 sizeof(nes_ethtool_stringset));
1060 * nes_netdev_get_ethtool_stats
1062 static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
1063 struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values)
1066 struct nes_vnic *nesvnic = netdev_priv(netdev);
1067 struct nes_device *nesdev = nesvnic->nesdev;
1071 target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
1072 target_stat_values[0] = nesvnic->nesdev->link_status_interrupts;
1073 target_stat_values[1] = nesvnic->linearized_skbs;
1074 target_stat_values[2] = nesvnic->tso_requests;
1076 u32temp = nes_read_indexed(nesdev,
1077 NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1078 nesvnic->nesdev->mac_pause_frames_sent += u32temp;
1079 target_stat_values[3] = nesvnic->nesdev->mac_pause_frames_sent;
1081 u32temp = nes_read_indexed(nesdev,
1082 NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1083 nesvnic->nesdev->mac_pause_frames_received += u32temp;
1085 u32temp = nes_read_indexed(nesdev,
1086 NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1087 nesvnic->nesdev->port_rx_discards += u32temp;
1088 nesvnic->netstats.rx_dropped += u32temp;
1090 u32temp = nes_read_indexed(nesdev,
1091 NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1092 nesvnic->nesdev->port_tx_discards += u32temp;
1093 nesvnic->netstats.tx_dropped += u32temp;
1095 for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) {
1096 if (nesvnic->qp_nic_index[nic_count] == 0xf)
1099 u32temp = nes_read_indexed(nesdev,
1100 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD +
1101 (nesvnic->qp_nic_index[nic_count]*0x200));
1102 nesvnic->netstats.rx_dropped += u32temp;
1103 nesvnic->endnode_nstat_rx_discard += u32temp;
1105 u64temp = (u64)nes_read_indexed(nesdev,
1106 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO +
1107 (nesvnic->qp_nic_index[nic_count]*0x200));
1108 u64temp += ((u64)nes_read_indexed(nesdev,
1109 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI +
1110 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1112 nesvnic->endnode_nstat_rx_octets += u64temp;
1113 nesvnic->netstats.rx_bytes += u64temp;
1115 u64temp = (u64)nes_read_indexed(nesdev,
1116 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO +
1117 (nesvnic->qp_nic_index[nic_count]*0x200));
1118 u64temp += ((u64)nes_read_indexed(nesdev,
1119 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI +
1120 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1122 nesvnic->endnode_nstat_rx_frames += u64temp;
1123 nesvnic->netstats.rx_packets += u64temp;
1125 u64temp = (u64)nes_read_indexed(nesdev,
1126 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO +
1127 (nesvnic->qp_nic_index[nic_count]*0x200));
1128 u64temp += ((u64)nes_read_indexed(nesdev,
1129 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI +
1130 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1132 nesvnic->endnode_nstat_tx_octets += u64temp;
1133 nesvnic->netstats.tx_bytes += u64temp;
1135 u64temp = (u64)nes_read_indexed(nesdev,
1136 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO +
1137 (nesvnic->qp_nic_index[nic_count]*0x200));
1138 u64temp += ((u64)nes_read_indexed(nesdev,
1139 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI +
1140 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1142 nesvnic->endnode_nstat_tx_frames += u64temp;
1143 nesvnic->netstats.tx_packets += u64temp;
1145 u32temp = nes_read_indexed(nesdev,
1146 NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200));
1147 nesvnic->endnode_ipv4_tcp_retransmits += u32temp;
1150 target_stat_values[4] = nesvnic->nesdev->mac_pause_frames_received;
1151 target_stat_values[5] = nesdev->nesadapter->nic_rx_eth_route_err;
1152 target_stat_values[6] = nesvnic->tx_sw_dropped;
1153 target_stat_values[7] = nesvnic->sq_locked;
1154 target_stat_values[8] = nesvnic->sq_full;
1155 target_stat_values[9] = nesvnic->segmented_tso_requests;
1156 target_stat_values[10] = nesvnic->nesdev->mac_rx_symbol_err_frames;
1157 target_stat_values[11] = nesvnic->nesdev->mac_rx_jabber_frames;
1158 target_stat_values[12] = nesvnic->nesdev->mac_rx_oversized_frames;
1159 target_stat_values[13] = nesvnic->nesdev->mac_rx_short_frames;
1160 target_stat_values[14] = nesvnic->endnode_nstat_rx_discard;
1161 target_stat_values[15] = nesvnic->endnode_nstat_rx_octets;
1162 target_stat_values[16] = nesvnic->endnode_nstat_rx_frames;
1163 target_stat_values[17] = nesvnic->endnode_nstat_tx_octets;
1164 target_stat_values[18] = nesvnic->endnode_nstat_tx_frames;
1165 target_stat_values[19] = mh_detected;
1166 target_stat_values[20] = mh_pauses_sent;
1167 target_stat_values[21] = nesvnic->endnode_ipv4_tcp_retransmits;
1168 target_stat_values[22] = atomic_read(&cm_connects);
1169 target_stat_values[23] = atomic_read(&cm_accepts);
1170 target_stat_values[24] = atomic_read(&cm_disconnects);
1171 target_stat_values[25] = atomic_read(&cm_connecteds);
1172 target_stat_values[26] = atomic_read(&cm_connect_reqs);
1173 target_stat_values[27] = atomic_read(&cm_rejects);
1174 target_stat_values[28] = atomic_read(&mod_qp_timouts);
1175 target_stat_values[29] = atomic_read(&qps_created);
1176 target_stat_values[30] = atomic_read(&sw_qps_destroyed);
1177 target_stat_values[31] = atomic_read(&qps_destroyed);
1178 target_stat_values[32] = atomic_read(&cm_closes);
1179 target_stat_values[33] = cm_packets_sent;
1180 target_stat_values[34] = cm_packets_bounced;
1181 target_stat_values[35] = cm_packets_created;
1182 target_stat_values[36] = cm_packets_received;
1183 target_stat_values[37] = cm_packets_dropped;
1184 target_stat_values[38] = cm_packets_retrans;
1185 target_stat_values[39] = cm_listens_created;
1186 target_stat_values[40] = cm_listens_destroyed;
1187 target_stat_values[41] = cm_backlog_drops;
1188 target_stat_values[42] = atomic_read(&cm_loopbacks);
1189 target_stat_values[43] = atomic_read(&cm_nodes_created);
1190 target_stat_values[44] = atomic_read(&cm_nodes_destroyed);
1191 target_stat_values[45] = atomic_read(&cm_accel_dropped_pkts);
1192 target_stat_values[46] = atomic_read(&cm_resets_recvd);
1193 target_stat_values[47] = int_mod_timer_init;
1194 target_stat_values[48] = int_mod_cq_depth_1;
1195 target_stat_values[49] = int_mod_cq_depth_4;
1196 target_stat_values[50] = int_mod_cq_depth_16;
1197 target_stat_values[51] = int_mod_cq_depth_24;
1198 target_stat_values[52] = int_mod_cq_depth_32;
1199 target_stat_values[53] = int_mod_cq_depth_128;
1200 target_stat_values[54] = int_mod_cq_depth_256;
1206 * nes_netdev_get_drvinfo
1208 static void nes_netdev_get_drvinfo(struct net_device *netdev,
1209 struct ethtool_drvinfo *drvinfo)
1211 struct nes_vnic *nesvnic = netdev_priv(netdev);
1213 strcpy(drvinfo->driver, DRV_NAME);
1214 strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
1215 strcpy(drvinfo->fw_version, "TBD");
1216 strcpy(drvinfo->version, DRV_VERSION);
1217 drvinfo->n_stats = nes_netdev_get_stats_count(netdev);
1218 drvinfo->testinfo_len = 0;
1219 drvinfo->eedump_len = 0;
1220 drvinfo->regdump_len = 0;
1225 * nes_netdev_set_coalesce
1227 static int nes_netdev_set_coalesce(struct net_device *netdev,
1228 struct ethtool_coalesce *et_coalesce)
1230 struct nes_vnic *nesvnic = netdev_priv(netdev);
1231 struct nes_device *nesdev = nesvnic->nesdev;
1232 struct nes_adapter *nesadapter = nesdev->nesadapter;
1233 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1234 unsigned long flags;
1236 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1237 if (et_coalesce->rx_max_coalesced_frames_low) {
1238 shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low;
1240 if (et_coalesce->rx_max_coalesced_frames_irq) {
1241 shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq;
1243 if (et_coalesce->rx_max_coalesced_frames_high) {
1244 shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high;
1246 if (et_coalesce->rx_coalesce_usecs_low) {
1247 shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low;
1249 if (et_coalesce->rx_coalesce_usecs_high) {
1250 shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high;
1252 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1254 /* using this to drive total interrupt moderation */
1255 nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq;
1256 if (et_coalesce->use_adaptive_rx_coalesce) {
1257 nesadapter->et_use_adaptive_rx_coalesce = 1;
1258 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
1259 nesadapter->et_rx_coalesce_usecs_irq = 0;
1260 if (et_coalesce->pkt_rate_low) {
1261 nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low;
1264 nesadapter->et_use_adaptive_rx_coalesce = 0;
1265 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
1266 if (nesadapter->et_rx_coalesce_usecs_irq) {
1267 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
1268 0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8)));
1276 * nes_netdev_get_coalesce
1278 static int nes_netdev_get_coalesce(struct net_device *netdev,
1279 struct ethtool_coalesce *et_coalesce)
1281 struct nes_vnic *nesvnic = netdev_priv(netdev);
1282 struct nes_device *nesdev = nesvnic->nesdev;
1283 struct nes_adapter *nesadapter = nesdev->nesadapter;
1284 struct ethtool_coalesce temp_et_coalesce;
1285 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1286 unsigned long flags;
1288 memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce));
1289 temp_et_coalesce.rx_coalesce_usecs_irq = nesadapter->et_rx_coalesce_usecs_irq;
1290 temp_et_coalesce.use_adaptive_rx_coalesce = nesadapter->et_use_adaptive_rx_coalesce;
1291 temp_et_coalesce.rate_sample_interval = nesadapter->et_rate_sample_interval;
1292 temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low;
1293 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1294 temp_et_coalesce.rx_max_coalesced_frames_low = shared_timer->threshold_low;
1295 temp_et_coalesce.rx_max_coalesced_frames_irq = shared_timer->threshold_target;
1296 temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
1297 temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min;
1298 temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max;
1299 if (nesadapter->et_use_adaptive_rx_coalesce) {
1300 temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use;
1302 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1303 memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce));
1309 * nes_netdev_get_pauseparam
1311 static void nes_netdev_get_pauseparam(struct net_device *netdev,
1312 struct ethtool_pauseparam *et_pauseparam)
1314 struct nes_vnic *nesvnic = netdev_priv(netdev);
1316 et_pauseparam->autoneg = 0;
1317 et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0;
1318 et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0;
1323 * nes_netdev_set_pauseparam
1325 static int nes_netdev_set_pauseparam(struct net_device *netdev,
1326 struct ethtool_pauseparam *et_pauseparam)
1328 struct nes_vnic *nesvnic = netdev_priv(netdev);
1329 struct nes_device *nesdev = nesvnic->nesdev;
1332 if (et_pauseparam->autoneg) {
1333 /* TODO: should return unsupported */
1336 if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) {
1337 u32temp = nes_read_indexed(nesdev,
1338 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
1339 u32temp |= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
1340 nes_write_indexed(nesdev,
1341 NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp);
1342 nesdev->disable_tx_flow_control = 0;
1343 } else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) {
1344 u32temp = nes_read_indexed(nesdev,
1345 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
1346 u32temp &= ~NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
1347 nes_write_indexed(nesdev,
1348 NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp);
1349 nesdev->disable_tx_flow_control = 1;
1351 if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) {
1352 u32temp = nes_read_indexed(nesdev,
1353 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
1354 u32temp &= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
1355 nes_write_indexed(nesdev,
1356 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
1357 nesdev->disable_rx_flow_control = 0;
1358 } else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) {
1359 u32temp = nes_read_indexed(nesdev,
1360 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
1361 u32temp |= NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
1362 nes_write_indexed(nesdev,
1363 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
1364 nesdev->disable_rx_flow_control = 1;
1372 * nes_netdev_get_settings
1374 static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1376 struct nes_vnic *nesvnic = netdev_priv(netdev);
1377 struct nes_device *nesdev = nesvnic->nesdev;
1378 struct nes_adapter *nesadapter = nesdev->nesadapter;
1381 et_cmd->duplex = DUPLEX_FULL;
1382 et_cmd->port = PORT_MII;
1383 if (nesadapter->OneG_Mode) {
1384 et_cmd->supported = SUPPORTED_1000baseT_Full|SUPPORTED_Autoneg;
1385 et_cmd->advertising = ADVERTISED_1000baseT_Full|ADVERTISED_Autoneg;
1386 et_cmd->speed = SPEED_1000;
1387 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
1389 if (phy_data&0x1000) {
1390 et_cmd->autoneg = AUTONEG_ENABLE;
1392 et_cmd->autoneg = AUTONEG_DISABLE;
1394 et_cmd->transceiver = XCVR_EXTERNAL;
1395 et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
1397 if (nesadapter->phy_type[nesvnic->logical_port] == NES_PHY_TYPE_IRIS) {
1398 et_cmd->transceiver = XCVR_EXTERNAL;
1399 et_cmd->port = PORT_FIBRE;
1400 et_cmd->supported = SUPPORTED_FIBRE;
1401 et_cmd->advertising = ADVERTISED_FIBRE;
1402 et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
1404 et_cmd->transceiver = XCVR_INTERNAL;
1405 et_cmd->supported = SUPPORTED_10000baseT_Full;
1406 et_cmd->advertising = ADVERTISED_10000baseT_Full;
1407 et_cmd->phy_address = nesdev->mac_index;
1409 et_cmd->speed = SPEED_10000;
1410 et_cmd->autoneg = AUTONEG_DISABLE;
1412 et_cmd->maxtxpkt = 511;
1413 et_cmd->maxrxpkt = 511;
1419 * nes_netdev_set_settings
1421 static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1423 struct nes_vnic *nesvnic = netdev_priv(netdev);
1424 struct nes_device *nesdev = nesvnic->nesdev;
1425 struct nes_adapter *nesadapter = nesdev->nesadapter;
1428 if (nesadapter->OneG_Mode) {
1429 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
1431 if (et_cmd->autoneg) {
1432 /* Turn on Full duplex, Autoneg, and restart autonegotiation */
1436 phy_data &= ~0x1000;
1438 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
1446 static struct ethtool_ops nes_ethtool_ops = {
1447 .get_link = ethtool_op_get_link,
1448 .get_settings = nes_netdev_get_settings,
1449 .set_settings = nes_netdev_set_settings,
1450 .get_tx_csum = ethtool_op_get_tx_csum,
1451 .get_rx_csum = nes_netdev_get_rx_csum,
1452 .get_sg = ethtool_op_get_sg,
1453 .get_strings = nes_netdev_get_strings,
1454 .get_stats_count = nes_netdev_get_stats_count,
1455 .get_ethtool_stats = nes_netdev_get_ethtool_stats,
1456 .get_drvinfo = nes_netdev_get_drvinfo,
1457 .get_coalesce = nes_netdev_get_coalesce,
1458 .set_coalesce = nes_netdev_set_coalesce,
1459 .get_pauseparam = nes_netdev_get_pauseparam,
1460 .set_pauseparam = nes_netdev_set_pauseparam,
1461 .set_tx_csum = ethtool_op_set_tx_csum,
1462 .set_rx_csum = nes_netdev_set_rx_csum,
1463 .set_sg = ethtool_op_set_sg,
1464 .get_tso = ethtool_op_get_tso,
1465 .set_tso = ethtool_op_set_tso,
1469 static void nes_netdev_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
1471 struct nes_vnic *nesvnic = netdev_priv(netdev);
1472 struct nes_device *nesdev = nesvnic->nesdev;
1475 nesvnic->vlan_grp = grp;
1477 /* Enable/Disable VLAN Stripping */
1478 u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
1480 u32temp &= 0xfdffffff;
1482 u32temp |= 0x02000000;
1484 nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
1489 * nes_netdev_init - initialize network device
1491 struct net_device *nes_netdev_init(struct nes_device *nesdev,
1492 void __iomem *mmio_addr)
1495 struct nes_vnic *nesvnic = NULL;
1496 struct net_device *netdev;
1497 struct nic_qp_map *curr_qp_map;
1502 netdev = alloc_etherdev(sizeof(struct nes_vnic));
1504 printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
1508 nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name);
1510 SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev);
1512 nesvnic = netdev_priv(netdev);
1513 memset(nesvnic, 0, sizeof(*nesvnic));
1515 netdev->open = nes_netdev_open;
1516 netdev->stop = nes_netdev_stop;
1517 netdev->hard_start_xmit = nes_netdev_start_xmit;
1518 netdev->get_stats = nes_netdev_get_stats;
1519 netdev->tx_timeout = nes_netdev_tx_timeout;
1520 netdev->set_mac_address = nes_netdev_set_mac_address;
1521 netdev->set_multicast_list = nes_netdev_set_multicast_list;
1522 netdev->change_mtu = nes_netdev_change_mtu;
1523 netdev->watchdog_timeo = NES_TX_TIMEOUT;
1524 netdev->irq = nesdev->pcidev->irq;
1525 netdev->mtu = ETH_DATA_LEN;
1526 netdev->hard_header_len = ETH_HLEN;
1527 netdev->addr_len = ETH_ALEN;
1528 netdev->type = ARPHRD_ETHER;
1529 netdev->features = NETIF_F_HIGHDMA;
1530 netdev->ethtool_ops = &nes_ethtool_ops;
1531 netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128);
1532 nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n");
1533 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
1534 netdev->vlan_rx_register = nes_netdev_vlan_rx_register;
1535 netdev->features |= NETIF_F_LLTX;
1537 /* Fill in the port structure */
1538 nesvnic->netdev = netdev;
1539 nesvnic->nesdev = nesdev;
1540 nesvnic->msg_enable = netif_msg_init(debug, default_msg);
1541 nesvnic->netdev_index = nesdev->netdev_count;
1542 nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count;
1543 nesvnic->max_frame_size = netdev->mtu+netdev->hard_header_len;
1545 curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)];
1546 nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid;
1547 nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index;
1548 nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port;
1550 /* Setup the burned in MAC address */
1551 u64temp = (u64)nesdev->nesadapter->mac_addr_low;
1552 u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32;
1553 u64temp += nesvnic->nic_index;
1554 netdev->dev_addr[0] = (u8)(u64temp>>40);
1555 netdev->dev_addr[1] = (u8)(u64temp>>32);
1556 netdev->dev_addr[2] = (u8)(u64temp>>24);
1557 netdev->dev_addr[3] = (u8)(u64temp>>16);
1558 netdev->dev_addr[4] = (u8)(u64temp>>8);
1559 netdev->dev_addr[5] = (u8)u64temp;
1560 memcpy(netdev->perm_addr, netdev->dev_addr, 6);
1562 if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV)) {
1563 netdev->features |= NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
1564 netdev->features |= NETIF_F_GSO | NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
1566 netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
1569 nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
1570 " nic_index = %d, logical_port = %d, mac_index = %d.\n",
1571 nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id,
1572 nesvnic->nic_index, nesvnic->logical_port, nesdev->mac_index);
1574 if (nesvnic->nesdev->nesadapter->port_count == 1) {
1575 nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1576 nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1;
1577 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) {
1578 nesvnic->qp_nic_index[2] = 0xf;
1579 nesvnic->qp_nic_index[3] = 0xf;
1581 nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2;
1582 nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3;
1585 if (nesvnic->nesdev->nesadapter->port_count == 2) {
1586 nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1587 nesvnic->qp_nic_index[1] = nesvnic->nic_index + 2;
1588 nesvnic->qp_nic_index[2] = 0xf;
1589 nesvnic->qp_nic_index[3] = 0xf;
1591 nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1592 nesvnic->qp_nic_index[1] = 0xf;
1593 nesvnic->qp_nic_index[2] = 0xf;
1594 nesvnic->qp_nic_index[3] = 0xf;
1597 nesvnic->next_qp_nic_index = 0;
1599 if (nesdev->netdev_count == 0) {
1600 nesvnic->rdma_enabled = 1;
1602 nesvnic->rdma_enabled = 0;
1604 nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id;
1605 spin_lock_init(&nesvnic->tx_lock);
1606 nesdev->netdev[nesdev->netdev_count] = netdev;
1608 nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
1609 nesvnic, nesdev->mac_index);
1610 list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]);
1612 if ((nesdev->netdev_count == 0) &&
1613 (PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index)) {
1614 nes_debug(NES_DBG_INIT, "Setting up PHY interrupt mask. Using register index 0x%04X\n",
1615 NES_IDX_PHY_PCS_CONTROL_STATUS0+(0x200*(nesvnic->logical_port&1)));
1616 u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1617 (0x200*(nesvnic->logical_port&1)));
1618 u32temp |= 0x00200000;
1619 nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1620 (0x200*(nesvnic->logical_port&1)), u32temp);
1621 u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1622 (0x200*(nesvnic->logical_port&1)) );
1623 if ((u32temp&0x0f1f0000) == 0x0f0f0000) {
1624 if (nesdev->nesadapter->phy_type[nesvnic->logical_port] == NES_PHY_TYPE_IRIS) {
1625 nes_init_phy(nesdev);
1626 nes_read_10G_phy_reg(nesdev, 1,
1627 nesdev->nesadapter->phy_index[nesvnic->logical_port]);
1628 temp_phy_data = (u16)nes_read_indexed(nesdev,
1629 NES_IDX_MAC_MDIO_CONTROL);
1632 nes_read_10G_phy_reg(nesdev, 1,
1633 nesdev->nesadapter->phy_index[nesvnic->logical_port]);
1634 phy_data = (u16)nes_read_indexed(nesdev,
1635 NES_IDX_MAC_MDIO_CONTROL);
1636 if ((phy_data == temp_phy_data) || (!(--u32temp)))
1638 temp_phy_data = phy_data;
1641 nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
1642 nesvnic->linkup = 1;
1644 nes_debug(NES_DBG_INIT, "The Link is DOWN!!.\n");
1647 nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
1648 nesvnic->linkup = 1;
1651 nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n");
1652 /* clear the MAC interrupt status, assumes direct logical to physical mapping */
1653 u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS+(0x200*nesvnic->logical_port));
1654 nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
1655 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS+(0x200*nesvnic->logical_port), u32temp);
1657 if (nesdev->nesadapter->phy_type[nesvnic->logical_port] != NES_PHY_TYPE_IRIS)
1658 nes_init_phy(nesdev);
1660 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesvnic->logical_port),
1661 ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
1662 NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
1670 * nes_netdev_destroy - destroy network device structure
1672 void nes_netdev_destroy(struct net_device *netdev)
1674 struct nes_vnic *nesvnic = netdev_priv(netdev);
1676 /* make sure 'stop' method is called by Linux stack */
1677 /* nes_netdev_stop(netdev); */
1679 list_del(&nesvnic->list);
1681 if (nesvnic->of_device_registered) {
1682 nes_destroy_ofa_device(nesvnic->nesibdev);
1685 free_netdev(netdev);
1690 * nes_nic_cm_xmit -- CM calls this to send out pkts
1692 int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev)
1697 ret = dev_queue_xmit(skb);
1699 nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret);