]> err.no Git - linux-2.6/blob - drivers/infiniband/hw/nes/nes_nic.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6
[linux-2.6] / drivers / infiniband / hw / nes / nes_nic.c
1 /*
2  * Copyright (c) 2006 - 2008 NetEffect, Inc. All rights reserved.
3  *
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:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
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.
22  *
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
30  * SOFTWARE.
31  *
32  */
33
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
38 #include <linux/ip.h>
39 #include <linux/tcp.h>
40 #include <linux/if_arp.h>
41 #include <linux/if_vlan.h>
42 #include <linux/ethtool.h>
43 #include <net/tcp.h>
44
45 #include <net/inet_common.h>
46 #include <linux/inet.h>
47
48 #include "nes.h"
49
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}
55 };
56
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}
60 };
61
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}
64 };
65
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}
68 };
69
70 static struct nic_qp_map nic_qp_mapping_4[] = {
71         {28,8,0,0},{32,12,0,0}
72 };
73
74 static struct nic_qp_map nic_qp_mapping_5[] = {
75         {29,9,1,0},{33,13,1,0}
76 };
77
78 static struct nic_qp_map nic_qp_mapping_6[] = {
79         {30,10,2,0},{34,14,2,0}
80 };
81
82 static struct nic_qp_map nic_qp_mapping_7[] = {
83         {31,11,3,0},{35,15,3,0}
84 };
85
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
89 };
90
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;
94
95 /**
96  * nes_netdev_poll
97  */
98 static int nes_netdev_poll(struct napi_struct *napi, int budget)
99 {
100         struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi);
101         struct net_device *netdev = nesvnic->netdev;
102         struct nes_device *nesdev = nesvnic->nesdev;
103         struct nes_hw_nic_cq *nescq = &nesvnic->nic_cq;
104
105         nesvnic->budget = budget;
106         nescq->cqes_pending = 0;
107         nescq->rx_cqes_completed = 0;
108         nescq->cqe_allocs_pending = 0;
109         nescq->rx_pkts_indicated = 0;
110
111         nes_nic_ce_handler(nesdev, nescq);
112
113         if (nescq->cqes_pending == 0) {
114                 netif_rx_complete(netdev, napi);
115                 /* clear out completed cqes and arm */
116                 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
117                                 nescq->cq_number | (nescq->cqe_allocs_pending << 16));
118                 nes_read32(nesdev->regs+NES_CQE_ALLOC);
119         } else {
120                 /* clear out completed cqes but don't arm */
121                 nes_write32(nesdev->regs+NES_CQE_ALLOC,
122                                 nescq->cq_number | (nescq->cqe_allocs_pending << 16));
123                 nes_debug(NES_DBG_NETDEV, "%s: exiting with work pending\n",
124                                 nesvnic->netdev->name);
125         }
126         return nescq->rx_pkts_indicated;
127 }
128
129
130 /**
131  * nes_netdev_open - Activate the network interface; ifconfig
132  * ethx up.
133  */
134 static int nes_netdev_open(struct net_device *netdev)
135 {
136         u32 macaddr_low;
137         u16 macaddr_high;
138         struct nes_vnic *nesvnic = netdev_priv(netdev);
139         struct nes_device *nesdev = nesvnic->nesdev;
140         int ret;
141         int i;
142         struct nes_vnic *first_nesvnic = NULL;
143         u32 nic_active_bit;
144         u32 nic_active;
145         struct list_head *list_pos, *list_temp;
146
147         assert(nesdev != NULL);
148
149         if (nesvnic->netdev_open == 1)
150                 return 0;
151
152         if (netif_msg_ifup(nesvnic))
153                 printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name);
154
155         ret = nes_init_nic_qp(nesdev, netdev);
156         if (ret) {
157                 return ret;
158         }
159
160         netif_carrier_off(netdev);
161         netif_stop_queue(netdev);
162
163         if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) {
164                 nesvnic->nesibdev = nes_init_ofa_device(netdev);
165                 if (nesvnic->nesibdev == NULL) {
166                         printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name);
167                 } else {
168                         nesvnic->nesibdev->nesvnic = nesvnic;
169                         ret = nes_register_ofa_device(nesvnic->nesibdev);
170                         if (ret) {
171                                 printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n",
172                                                 netdev->name, ret);
173                         }
174                 }
175         }
176         /* Set packet filters */
177         nic_active_bit = 1 << nesvnic->nic_index;
178         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
179         nic_active |= nic_active_bit;
180         nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
181         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
182         nic_active |= nic_active_bit;
183         nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
184         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
185         nic_active |= nic_active_bit;
186         nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
187
188         macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
189         macaddr_high += (u16)netdev->dev_addr[1];
190         macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
191         macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
192         macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
193         macaddr_low += (u32)netdev->dev_addr[5];
194
195         /* Program the various MAC regs */
196         for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
197                 if (nesvnic->qp_nic_index[i] == 0xf) {
198                         break;
199                 }
200                 nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW"
201                                 " (Addr:%08X) = %08X, HIGH = %08X.\n",
202                                 i, nesvnic->qp_nic_index[i],
203                                 NES_IDX_PERFECT_FILTER_LOW+((nesvnic->perfect_filter_index + i) * 8),
204                                 macaddr_low,
205                                 (u32)macaddr_high | NES_MAC_ADDR_VALID |
206                                 ((((u32)nesvnic->nic_index) << 16)));
207                 nes_write_indexed(nesdev,
208                                 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
209                                 macaddr_low);
210                 nes_write_indexed(nesdev,
211                                 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
212                                 (u32)macaddr_high | NES_MAC_ADDR_VALID |
213                                 ((((u32)nesvnic->nic_index) << 16)));
214         }
215
216
217         nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
218                         nesvnic->nic_cq.cq_number);
219         nes_read32(nesdev->regs+NES_CQE_ALLOC);
220         list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
221                 first_nesvnic = container_of(list_pos, struct nes_vnic, list);
222                 if (first_nesvnic->netdev_open == 1)
223                         break;
224         }
225         if (first_nesvnic->netdev_open == 0) {
226                 nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n");
227                 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index),
228                                 ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
229                                 NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
230                 first_nesvnic = nesvnic;
231         }
232         if (first_nesvnic->linkup) {
233                 /* Enable network packets */
234                 nesvnic->linkup = 1;
235                 netif_start_queue(netdev);
236                 netif_carrier_on(netdev);
237         }
238         napi_enable(&nesvnic->napi);
239         nesvnic->netdev_open = 1;
240
241         return 0;
242 }
243
244
245 /**
246  * nes_netdev_stop
247  */
248 static int nes_netdev_stop(struct net_device *netdev)
249 {
250         struct nes_vnic *nesvnic = netdev_priv(netdev);
251         struct nes_device *nesdev = nesvnic->nesdev;
252         u32 nic_active_mask;
253         u32 nic_active;
254         struct nes_vnic *first_nesvnic = NULL;
255         struct list_head *list_pos, *list_temp;
256
257         nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n",
258                         nesvnic, nesdev, netdev, netdev->name);
259         if (nesvnic->netdev_open == 0)
260                 return 0;
261
262         if (netif_msg_ifdown(nesvnic))
263                 printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);
264
265         /* Disable network packets */
266         napi_disable(&nesvnic->napi);
267         netif_stop_queue(netdev);
268         list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
269                 first_nesvnic = container_of(list_pos, struct nes_vnic, list);
270                 if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic))
271                         break;
272         }
273
274         if (first_nesvnic->netdev_open == 0)
275                 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
276         else if ((first_nesvnic != nesvnic) &&
277                  (PCI_FUNC(first_nesvnic->nesdev->pcidev->devfn) != PCI_FUNC(nesvnic->nesdev->pcidev->devfn))) {
278                 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index), 0xffffffff);
279                 nes_write_indexed(first_nesvnic->nesdev, NES_IDX_MAC_INT_MASK + (0x200 * first_nesvnic->nesdev->mac_index),
280                                 ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
281                                 NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
282         }
283
284         nic_active_mask = ~((u32)(1 << nesvnic->nic_index));
285         nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+
286                         (nesvnic->perfect_filter_index*8), 0);
287         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
288         nic_active &= nic_active_mask;
289         nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
290         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
291         nic_active &= nic_active_mask;
292         nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
293         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
294         nic_active &= nic_active_mask;
295         nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
296         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
297         nic_active &= nic_active_mask;
298         nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
299         nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
300         nic_active &= nic_active_mask;
301         nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
302
303
304         if (nesvnic->of_device_registered) {
305                 nes_destroy_ofa_device(nesvnic->nesibdev);
306                 nesvnic->nesibdev = NULL;
307                 nesvnic->of_device_registered = 0;
308         }
309         nes_destroy_nic_qp(nesvnic);
310
311         nesvnic->netdev_open = 0;
312
313         return 0;
314 }
315
316
317 /**
318  * nes_nic_send
319  */
320 static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev)
321 {
322         struct nes_vnic *nesvnic = netdev_priv(netdev);
323         struct nes_device *nesdev = nesvnic->nesdev;
324         struct nes_hw_nic *nesnic = &nesvnic->nic;
325         struct nes_hw_nic_sq_wqe *nic_sqe;
326         struct tcphdr *tcph;
327         __le16 *wqe_fragment_length;
328         u32 wqe_misc;
329         u16 wqe_fragment_index = 1;     /* first fragment (0) is used by copy buffer */
330         u16 skb_fragment_index;
331         dma_addr_t bus_address;
332
333         nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
334         wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
335
336         /* setup the VLAN tag if present */
337         if (vlan_tx_tag_present(skb)) {
338                 nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
339                                 netdev->name, vlan_tx_tag_get(skb));
340                 wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
341                 wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
342         } else
343                 wqe_misc = 0;
344
345         /* bump past the vlan tag */
346         wqe_fragment_length++;
347         /*      wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */
348
349         if (skb->ip_summed == CHECKSUM_PARTIAL) {
350                 tcph = tcp_hdr(skb);
351                 if (1) {
352                         if (skb_is_gso(skb)) {
353                                 /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... seg size = %u\n",
354                                                 netdev->name, skb_is_gso(skb)); */
355                                 wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE |
356                                                 NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
357                                 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
358                                                 ((u32)tcph->doff) |
359                                                 (((u32)(((unsigned char *)tcph) - skb->data)) << 4));
360                         } else {
361                                 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION;
362                         }
363                 }
364         } else {        /* CHECKSUM_HW */
365                 wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM | NES_NIC_SQ_WQE_COMPLETION;
366         }
367
368         set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
369                                 skb->len);
370         memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
371                         skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb)));
372         wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
373                         skb_headlen(skb)));
374         wqe_fragment_length[1] = 0;
375         if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
376                 if ((skb_shinfo(skb)->nr_frags + 1) > 4) {
377                         nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n",
378                                         netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb));
379                         kfree_skb(skb);
380                         nesvnic->tx_sw_dropped++;
381                         return NETDEV_TX_LOCKED;
382                 }
383                 set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
384                 bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE,
385                                 skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE);
386                 wqe_fragment_length[wqe_fragment_index++] =
387                                 cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE);
388                 wqe_fragment_length[wqe_fragment_index] = 0;
389                 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
390                                 ((u64)(bus_address)));
391                 nesnic->tx_skb[nesnic->sq_head] = skb;
392         }
393
394         if (skb_headlen(skb) == skb->len) {
395                 if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) {
396                         nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0;
397                         nesnic->tx_skb[nesnic->sq_head] = NULL;
398                         dev_kfree_skb(skb);
399                 }
400         } else {
401                 /* Deal with Fragments */
402                 nesnic->tx_skb[nesnic->sq_head] = skb;
403                 for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags;
404                                 skb_fragment_index++) {
405                         bus_address = pci_map_page( nesdev->pcidev,
406                                         skb_shinfo(skb)->frags[skb_fragment_index].page,
407                                         skb_shinfo(skb)->frags[skb_fragment_index].page_offset,
408                                         skb_shinfo(skb)->frags[skb_fragment_index].size,
409                                         PCI_DMA_TODEVICE);
410                         wqe_fragment_length[wqe_fragment_index] =
411                                         cpu_to_le16(skb_shinfo(skb)->frags[skb_fragment_index].size);
412                         set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
413                                 bus_address);
414                         wqe_fragment_index++;
415                         if (wqe_fragment_index < 5)
416                                 wqe_fragment_length[wqe_fragment_index] = 0;
417                 }
418         }
419
420         set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc);
421         nesnic->sq_head++;
422         nesnic->sq_head &= nesnic->sq_size - 1;
423
424         return NETDEV_TX_OK;
425 }
426
427
428 /**
429  * nes_netdev_start_xmit
430  */
431 static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev)
432 {
433         struct nes_vnic *nesvnic = netdev_priv(netdev);
434         struct nes_device *nesdev = nesvnic->nesdev;
435         struct nes_hw_nic *nesnic = &nesvnic->nic;
436         struct nes_hw_nic_sq_wqe *nic_sqe;
437         struct tcphdr *tcph;
438         /* struct udphdr *udph; */
439 #define NES_MAX_TSO_FRAGS 18
440         /* 64K segment plus overflow on each side */
441         dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS];
442         dma_addr_t bus_address;
443         u32 tso_frag_index;
444         u32 tso_frag_count;
445         u32 tso_wqe_length;
446         u32 curr_tcp_seq;
447         u32 wqe_count=1;
448         u32 send_rc;
449         struct iphdr *iph;
450         unsigned long flags;
451         __le16 *wqe_fragment_length;
452         u32 nr_frags;
453         u32 original_first_length;
454 //      u64 *wqe_fragment_address;
455         /* first fragment (0) is used by copy buffer */
456         u16 wqe_fragment_index=1;
457         u16 hoffset;
458         u16 nhoffset;
459         u16 wqes_needed;
460         u16 wqes_available;
461         u32 old_head;
462         u32 wqe_misc;
463
464         /* nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
465                         " (%u frags), tso_size=%u\n",
466                         netdev->name, skb->len, skb_headlen(skb),
467                         skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
468         */
469
470         if (!netif_carrier_ok(netdev))
471                 return NETDEV_TX_OK;
472
473         if (netif_queue_stopped(netdev))
474                 return NETDEV_TX_BUSY;
475
476         local_irq_save(flags);
477         if (!spin_trylock(&nesnic->sq_lock)) {
478                 local_irq_restore(flags);
479                 nesvnic->sq_locked++;
480                 return NETDEV_TX_LOCKED;
481         }
482
483         /* Check if SQ is full */
484         if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) {
485                 if (!netif_queue_stopped(netdev)) {
486                         netif_stop_queue(netdev);
487                         barrier();
488                         if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) {
489                                 netif_start_queue(netdev);
490                                 goto sq_no_longer_full;
491                         }
492                 }
493                 nesvnic->sq_full++;
494                 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
495                 return NETDEV_TX_BUSY;
496         }
497
498 sq_no_longer_full:
499         nr_frags = skb_shinfo(skb)->nr_frags;
500         if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
501                 nr_frags++;
502         }
503         /* Check if too many fragments */
504         if (unlikely((nr_frags > 4))) {
505                 if (skb_is_gso(skb)) {
506                         nesvnic->segmented_tso_requests++;
507                         nesvnic->tso_requests++;
508                         old_head = nesnic->sq_head;
509                         /* Basically 4 fragments available per WQE with extended fragments */
510                         wqes_needed = nr_frags >> 2;
511                         wqes_needed += (nr_frags&3)?1:0;
512                         wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) &
513                                         (nesnic->sq_size - 1);
514
515                         if (unlikely(wqes_needed > wqes_available)) {
516                                 if (!netif_queue_stopped(netdev)) {
517                                         netif_stop_queue(netdev);
518                                         barrier();
519                                         wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) &
520                                                 (nesnic->sq_size - 1);
521                                         if (wqes_needed <= wqes_available) {
522                                                 netif_start_queue(netdev);
523                                                 goto tso_sq_no_longer_full;
524                                         }
525                                 }
526                                 nesvnic->sq_full++;
527                                 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
528                                 nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n",
529                                                 netdev->name);
530                                 return NETDEV_TX_BUSY;
531                         }
532 tso_sq_no_longer_full:
533                         /* Map all the buffers */
534                         for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags;
535                                         tso_frag_count++) {
536                                 tso_bus_address[tso_frag_count] = pci_map_page( nesdev->pcidev,
537                                                 skb_shinfo(skb)->frags[tso_frag_count].page,
538                                                 skb_shinfo(skb)->frags[tso_frag_count].page_offset,
539                                                 skb_shinfo(skb)->frags[tso_frag_count].size,
540                                                 PCI_DMA_TODEVICE);
541                         }
542
543                         tso_frag_index = 0;
544                         curr_tcp_seq = ntohl(tcp_hdr(skb)->seq);
545                         hoffset = skb_transport_header(skb) - skb->data;
546                         nhoffset = skb_network_header(skb) - skb->data;
547                         original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2);
548
549                         for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) {
550                                 tso_wqe_length = 0;
551                                 nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
552                                 wqe_fragment_length =
553                                                 (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
554                                 /* setup the VLAN tag if present */
555                                 if (vlan_tx_tag_present(skb)) {
556                                         nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
557                                                         netdev->name, vlan_tx_tag_get(skb) );
558                                         wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
559                                         wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
560                                 } else
561                                         wqe_misc = 0;
562
563                                 /* bump past the vlan tag */
564                                 wqe_fragment_length++;
565
566                                 /* Assumes header totally fits in allocated buffer and is in first fragment */
567                                 if (original_first_length > NES_FIRST_FRAG_SIZE) {
568                                         nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
569                                                         original_first_length, NES_FIRST_FRAG_SIZE);
570                                         nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
571                                                         " (%u frags), tso_size=%u\n",
572                                                         netdev->name,
573                                                         skb->len, skb_headlen(skb),
574                                                         skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
575                                 }
576                                 memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
577                                                 skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE),
578                                                 original_first_length));
579                                 iph = (struct iphdr *)
580                                 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]);
581                                 tcph = (struct tcphdr *)
582                                 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]);
583                                 if ((wqe_count+1)!=(u32)wqes_needed) {
584                                         tcph->fin = 0;
585                                         tcph->psh = 0;
586                                         tcph->rst = 0;
587                                         tcph->urg = 0;
588                                 }
589                                 if (wqe_count) {
590                                         tcph->syn = 0;
591                                 }
592                                 tcph->seq = htonl(curr_tcp_seq);
593                                 wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
594                                                 original_first_length));
595
596                                 wqe_fragment_index = 1;
597                                 if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) {
598                                         set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
599                                         bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length,
600                                                         skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE);
601                                         wqe_fragment_length[wqe_fragment_index++] =
602                                                 cpu_to_le16(skb_headlen(skb) - original_first_length);
603                                         wqe_fragment_length[wqe_fragment_index] = 0;
604                                         set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
605                                                                         bus_address);
606                                 }
607                                 while (wqe_fragment_index < 5) {
608                                         wqe_fragment_length[wqe_fragment_index] =
609                                                         cpu_to_le16(skb_shinfo(skb)->frags[tso_frag_index].size);
610                                         set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
611                                                 (u64)tso_bus_address[tso_frag_index]);
612                                         wqe_fragment_index++;
613                                         tso_wqe_length += skb_shinfo(skb)->frags[tso_frag_index++].size;
614                                         if (wqe_fragment_index < 5)
615                                                 wqe_fragment_length[wqe_fragment_index] = 0;
616                                         if (tso_frag_index == tso_frag_count)
617                                                 break;
618                                 }
619                                 if ((wqe_count+1) == (u32)wqes_needed) {
620                                         nesnic->tx_skb[nesnic->sq_head] = skb;
621                                 } else {
622                                         nesnic->tx_skb[nesnic->sq_head] = NULL;
623                                 }
624                                 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
625                                 if ((tso_wqe_length + original_first_length) > skb_is_gso(skb)) {
626                                         wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE;
627                                 } else {
628                                         iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset);
629                                 }
630
631                                 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX,
632                                                  wqe_misc);
633                                 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
634                                                 ((u32)tcph->doff) | (((u32)hoffset) << 4));
635
636                                 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
637                                                 tso_wqe_length + original_first_length);
638                                 curr_tcp_seq += tso_wqe_length;
639                                 nesnic->sq_head++;
640                                 nesnic->sq_head &= nesnic->sq_size-1;
641                         }
642                 } else {
643                         nesvnic->linearized_skbs++;
644                         hoffset = skb_transport_header(skb) - skb->data;
645                         nhoffset = skb_network_header(skb) - skb->data;
646                         skb_linearize(skb);
647                         skb_set_transport_header(skb, hoffset);
648                         skb_set_network_header(skb, nhoffset);
649                         send_rc = nes_nic_send(skb, netdev);
650                         if (send_rc != NETDEV_TX_OK) {
651                                 spin_unlock_irqrestore(&nesnic->sq_lock, flags);
652                                 return NETDEV_TX_OK;
653                         }
654                 }
655         } else {
656                 send_rc = nes_nic_send(skb, netdev);
657                 if (send_rc != NETDEV_TX_OK) {
658                         spin_unlock_irqrestore(&nesnic->sq_lock, flags);
659                         return NETDEV_TX_OK;
660                 }
661         }
662
663         barrier();
664
665         if (wqe_count)
666                 nes_write32(nesdev->regs+NES_WQE_ALLOC,
667                                 (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id);
668
669         netdev->trans_start = jiffies;
670         spin_unlock_irqrestore(&nesnic->sq_lock, flags);
671
672         return NETDEV_TX_OK;
673 }
674
675
676 /**
677  * nes_netdev_get_stats
678  */
679 static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev)
680 {
681         struct nes_vnic *nesvnic = netdev_priv(netdev);
682         struct nes_device *nesdev = nesvnic->nesdev;
683         u64 u64temp;
684         u32 u32temp;
685
686         u32temp = nes_read_indexed(nesdev,
687                         NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200));
688         nesvnic->netstats.rx_dropped += u32temp;
689         nesvnic->endnode_nstat_rx_discard += u32temp;
690
691         u64temp = (u64)nes_read_indexed(nesdev,
692                         NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO + (nesvnic->nic_index*0x200));
693         u64temp += ((u64)nes_read_indexed(nesdev,
694                         NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
695
696         nesvnic->endnode_nstat_rx_octets += u64temp;
697         nesvnic->netstats.rx_bytes += u64temp;
698
699         u64temp = (u64)nes_read_indexed(nesdev,
700                         NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO + (nesvnic->nic_index*0x200));
701         u64temp += ((u64)nes_read_indexed(nesdev,
702                         NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
703
704         nesvnic->endnode_nstat_rx_frames += u64temp;
705         nesvnic->netstats.rx_packets += u64temp;
706
707         u64temp = (u64)nes_read_indexed(nesdev,
708                         NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO + (nesvnic->nic_index*0x200));
709         u64temp += ((u64)nes_read_indexed(nesdev,
710                         NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
711
712         nesvnic->endnode_nstat_tx_octets += u64temp;
713         nesvnic->netstats.tx_bytes += u64temp;
714
715         u64temp = (u64)nes_read_indexed(nesdev,
716                         NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO + (nesvnic->nic_index*0x200));
717         u64temp += ((u64)nes_read_indexed(nesdev,
718                         NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
719
720         nesvnic->endnode_nstat_tx_frames += u64temp;
721         nesvnic->netstats.tx_packets += u64temp;
722
723         u32temp = nes_read_indexed(nesdev,
724                         NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
725         nesvnic->netstats.rx_dropped += u32temp;
726         nesvnic->nesdev->mac_rx_errors += u32temp;
727         nesvnic->nesdev->mac_rx_short_frames += u32temp;
728
729         u32temp = nes_read_indexed(nesdev,
730                         NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
731         nesvnic->netstats.rx_dropped += u32temp;
732         nesvnic->nesdev->mac_rx_errors += u32temp;
733         nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
734
735         u32temp = nes_read_indexed(nesdev,
736                         NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
737         nesvnic->netstats.rx_dropped += u32temp;
738         nesvnic->nesdev->mac_rx_errors += u32temp;
739         nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
740
741         u32temp = nes_read_indexed(nesdev,
742                         NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
743         nesvnic->netstats.rx_dropped += u32temp;
744         nesvnic->nesdev->mac_rx_errors += u32temp;
745         nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
746
747         u32temp = nes_read_indexed(nesdev,
748                         NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
749         nesvnic->netstats.rx_length_errors += u32temp;
750         nesvnic->nesdev->mac_rx_errors += u32temp;
751
752         u32temp = nes_read_indexed(nesdev,
753                         NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
754         nesvnic->nesdev->mac_rx_errors += u32temp;
755         nesvnic->nesdev->mac_rx_crc_errors += u32temp;
756         nesvnic->netstats.rx_crc_errors += u32temp;
757
758         u32temp = nes_read_indexed(nesdev,
759                         NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
760         nesvnic->nesdev->mac_tx_errors += u32temp;
761         nesvnic->netstats.tx_errors += u32temp;
762
763         return &nesvnic->netstats;
764 }
765
766
767 /**
768  * nes_netdev_tx_timeout
769  */
770 static void nes_netdev_tx_timeout(struct net_device *netdev)
771 {
772         struct nes_vnic *nesvnic = netdev_priv(netdev);
773
774         if (netif_msg_timer(nesvnic))
775                 nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name);
776 }
777
778
779 /**
780  * nes_netdev_set_mac_address
781  */
782 static int nes_netdev_set_mac_address(struct net_device *netdev, void *p)
783 {
784         struct nes_vnic *nesvnic = netdev_priv(netdev);
785         struct nes_device *nesdev = nesvnic->nesdev;
786         struct sockaddr *mac_addr = p;
787         int i;
788         u32 macaddr_low;
789         u16 macaddr_high;
790
791         if (!is_valid_ether_addr(mac_addr->sa_data))
792                 return -EADDRNOTAVAIL;
793
794         memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
795         printk(PFX "%s: Address length = %d, Address = %02X%02X%02X%02X%02X%02X..\n",
796                    __func__, netdev->addr_len,
797                    mac_addr->sa_data[0], mac_addr->sa_data[1],
798                    mac_addr->sa_data[2], mac_addr->sa_data[3],
799                    mac_addr->sa_data[4], mac_addr->sa_data[5]);
800         macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
801         macaddr_high += (u16)netdev->dev_addr[1];
802         macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
803         macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
804         macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
805         macaddr_low += (u32)netdev->dev_addr[5];
806
807         for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
808                 if (nesvnic->qp_nic_index[i] == 0xf) {
809                         break;
810                 }
811                 nes_write_indexed(nesdev,
812                                 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
813                                 macaddr_low);
814                 nes_write_indexed(nesdev,
815                                 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
816                                 (u32)macaddr_high | NES_MAC_ADDR_VALID |
817                                 ((((u32)nesvnic->nic_index) << 16)));
818         }
819         return 0;
820 }
821
822
823 /**
824  * nes_netdev_set_multicast_list
825  */
826 static void nes_netdev_set_multicast_list(struct net_device *netdev)
827 {
828         struct nes_vnic *nesvnic = netdev_priv(netdev);
829         struct nes_device *nesdev = nesvnic->nesdev;
830         struct dev_mc_list *multicast_addr;
831         u32 nic_active_bit;
832         u32 nic_active;
833         u32 perfect_filter_register_address;
834         u32 macaddr_low;
835         u16 macaddr_high;
836         u8 mc_all_on = 0;
837         u8 mc_index;
838         int mc_nic_index = -1;
839
840         nic_active_bit = 1 << nesvnic->nic_index;
841
842         if (netdev->flags & IFF_PROMISC) {
843                 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
844                 nic_active |= nic_active_bit;
845                 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
846                 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
847                 nic_active |= nic_active_bit;
848                 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
849                 mc_all_on = 1;
850         } else if ((netdev->flags & IFF_ALLMULTI) || (netdev->mc_count > NES_MULTICAST_PF_MAX) ||
851                            (nesvnic->nic_index > 3)) {
852                 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
853                 nic_active |= nic_active_bit;
854                 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
855                 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
856                 nic_active &= ~nic_active_bit;
857                 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
858                 mc_all_on = 1;
859         } else {
860                 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
861                 nic_active &= ~nic_active_bit;
862                 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
863                 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
864                 nic_active &= ~nic_active_bit;
865                 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
866         }
867
868         nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscous = %d, All Multicast = %d.\n",
869                           netdev->mc_count, (netdev->flags & IFF_PROMISC)?1:0,
870                           (netdev->flags & IFF_ALLMULTI)?1:0);
871         if (!mc_all_on) {
872                 multicast_addr = netdev->mc_list;
873                 perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW + 0x80;
874                 perfect_filter_register_address += nesvnic->nic_index*0x40;
875                 for (mc_index=0; mc_index < NES_MULTICAST_PF_MAX; mc_index++) {
876                         while (multicast_addr && nesvnic->mcrq_mcast_filter && ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic, multicast_addr->dmi_addr)) == 0))
877                                 multicast_addr = multicast_addr->next;
878                         if (mc_nic_index < 0)
879                                 mc_nic_index = nesvnic->nic_index;
880                         if (multicast_addr) {
881                                 nes_debug(NES_DBG_NIC_RX, "Assigning MC Address = %02X%02X%02X%02X%02X%02X to register 0x%04X nic_idx=%d\n",
882                                                   multicast_addr->dmi_addr[0], multicast_addr->dmi_addr[1],
883                                                   multicast_addr->dmi_addr[2], multicast_addr->dmi_addr[3],
884                                                   multicast_addr->dmi_addr[4], multicast_addr->dmi_addr[5],
885                                                   perfect_filter_register_address+(mc_index * 8), mc_nic_index);
886                                 macaddr_high = ((u16)multicast_addr->dmi_addr[0]) << 8;
887                                 macaddr_high += (u16)multicast_addr->dmi_addr[1];
888                                 macaddr_low = ((u32)multicast_addr->dmi_addr[2]) << 24;
889                                 macaddr_low += ((u32)multicast_addr->dmi_addr[3]) << 16;
890                                 macaddr_low += ((u32)multicast_addr->dmi_addr[4]) << 8;
891                                 macaddr_low += (u32)multicast_addr->dmi_addr[5];
892                                 nes_write_indexed(nesdev,
893                                                 perfect_filter_register_address+(mc_index * 8),
894                                                 macaddr_low);
895                                 nes_write_indexed(nesdev,
896                                                 perfect_filter_register_address+4+(mc_index * 8),
897                                                 (u32)macaddr_high | NES_MAC_ADDR_VALID |
898                                                 ((((u32)(1<<mc_nic_index)) << 16)));
899                                 multicast_addr = multicast_addr->next;
900                         } else {
901                                 nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n",
902                                                   perfect_filter_register_address+(mc_index * 8));
903                                 nes_write_indexed(nesdev,
904                                                 perfect_filter_register_address+4+(mc_index * 8),
905                                                 0);
906                         }
907                 }
908         }
909 }
910
911
912 /**
913  * nes_netdev_change_mtu
914  */
915 static int nes_netdev_change_mtu(struct net_device *netdev,     int     new_mtu)
916 {
917         struct nes_vnic *nesvnic = netdev_priv(netdev);
918         struct nes_device *nesdev =     nesvnic->nesdev;
919         int     ret     = 0;
920         u8 jumbomode=0;
921
922         if ((new_mtu < ETH_ZLEN) ||     (new_mtu > max_mtu))
923                 return -EINVAL;
924
925         netdev->mtu     = new_mtu;
926         nesvnic->max_frame_size = new_mtu + VLAN_ETH_HLEN;
927
928         if (netdev->mtu > 1500) {
929                 jumbomode=1;
930         }
931         nes_nic_init_timer_defaults(nesdev,     jumbomode);
932
933         if (netif_running(netdev)) {
934                 nes_netdev_stop(netdev);
935                 nes_netdev_open(netdev);
936         }
937
938         return ret;
939 }
940
941 #define NES_ETHTOOL_STAT_COUNT 55
942 static const char nes_ethtool_stringset[NES_ETHTOOL_STAT_COUNT][ETH_GSTRING_LEN] = {
943         "Link Change Interrupts",
944         "Linearized SKBs",
945         "T/GSO Requests",
946         "Pause Frames Sent",
947         "Pause Frames Received",
948         "Internal Routing Errors",
949         "SQ SW Dropped SKBs",
950         "SQ Locked",
951         "SQ Full",
952         "Segmented TSO Requests",
953         "Rx Symbol Errors",
954         "Rx Jabber Errors",
955         "Rx Oversized Frames",
956         "Rx Short Frames",
957         "Endnode Rx Discards",
958         "Endnode Rx Octets",
959         "Endnode Rx Frames",
960         "Endnode Tx Octets",
961         "Endnode Tx Frames",
962         "mh detected",
963         "mh pauses",
964         "Retransmission Count",
965         "CM Connects",
966         "CM Accepts",
967         "Disconnects",
968         "Connected Events",
969         "Connect Requests",
970         "CM Rejects",
971         "ModifyQP Timeouts",
972         "CreateQPs",
973         "SW DestroyQPs",
974         "DestroyQPs",
975         "CM Closes",
976         "CM Packets Sent",
977         "CM Packets Bounced",
978         "CM Packets Created",
979         "CM Packets Rcvd",
980         "CM Packets Dropped",
981         "CM Packets Retrans",
982         "CM Listens Created",
983         "CM Listens Destroyed",
984         "CM Backlog Drops",
985         "CM Loopbacks",
986         "CM Nodes Created",
987         "CM Nodes Destroyed",
988         "CM Accel Drops",
989         "CM Resets Received",
990         "Timer Inits",
991         "CQ Depth 1",
992         "CQ Depth 4",
993         "CQ Depth 16",
994         "CQ Depth 24",
995         "CQ Depth 32",
996         "CQ Depth 128",
997         "CQ Depth 256",
998 };
999
1000
1001 /**
1002  * nes_netdev_get_rx_csum
1003  */
1004 static u32 nes_netdev_get_rx_csum (struct net_device *netdev)
1005 {
1006         struct nes_vnic *nesvnic = netdev_priv(netdev);
1007
1008         if (nesvnic->rx_checksum_disabled)
1009                 return 0;
1010         else
1011                 return 1;
1012 }
1013
1014
1015 /**
1016  * nes_netdev_set_rc_csum
1017  */
1018 static int nes_netdev_set_rx_csum(struct net_device *netdev, u32 enable)
1019 {
1020         struct nes_vnic *nesvnic = netdev_priv(netdev);
1021
1022         if (enable)
1023                 nesvnic->rx_checksum_disabled = 0;
1024         else
1025                 nesvnic->rx_checksum_disabled = 1;
1026         return 0;
1027 }
1028
1029
1030 /**
1031  * nes_netdev_get_stats_count
1032  */
1033 static int nes_netdev_get_stats_count(struct net_device *netdev)
1034 {
1035         return NES_ETHTOOL_STAT_COUNT;
1036 }
1037
1038
1039 /**
1040  * nes_netdev_get_strings
1041  */
1042 static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset,
1043                 u8 *ethtool_strings)
1044 {
1045         if (stringset == ETH_SS_STATS)
1046                 memcpy(ethtool_strings,
1047                                 &nes_ethtool_stringset,
1048                                 sizeof(nes_ethtool_stringset));
1049 }
1050
1051
1052 /**
1053  * nes_netdev_get_ethtool_stats
1054  */
1055 static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
1056                 struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values)
1057 {
1058         u64 u64temp;
1059         struct nes_vnic *nesvnic = netdev_priv(netdev);
1060         struct nes_device *nesdev = nesvnic->nesdev;
1061         u32 nic_count;
1062         u32 u32temp;
1063
1064         target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
1065         target_stat_values[0] = nesvnic->nesdev->link_status_interrupts;
1066         target_stat_values[1] = nesvnic->linearized_skbs;
1067         target_stat_values[2] = nesvnic->tso_requests;
1068
1069         u32temp = nes_read_indexed(nesdev,
1070                         NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1071         nesvnic->nesdev->mac_pause_frames_sent += u32temp;
1072         target_stat_values[3] = nesvnic->nesdev->mac_pause_frames_sent;
1073
1074         u32temp = nes_read_indexed(nesdev,
1075                         NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1076         nesvnic->nesdev->mac_pause_frames_received += u32temp;
1077
1078         u32temp = nes_read_indexed(nesdev,
1079                         NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1080         nesvnic->nesdev->port_rx_discards += u32temp;
1081         nesvnic->netstats.rx_dropped += u32temp;
1082
1083         u32temp = nes_read_indexed(nesdev,
1084                         NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1085         nesvnic->nesdev->port_tx_discards += u32temp;
1086         nesvnic->netstats.tx_dropped += u32temp;
1087
1088         for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) {
1089                 if (nesvnic->qp_nic_index[nic_count] == 0xf)
1090                         break;
1091
1092                 u32temp = nes_read_indexed(nesdev,
1093                                 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD +
1094                                 (nesvnic->qp_nic_index[nic_count]*0x200));
1095                 nesvnic->netstats.rx_dropped += u32temp;
1096                 nesvnic->endnode_nstat_rx_discard += u32temp;
1097
1098                 u64temp = (u64)nes_read_indexed(nesdev,
1099                                 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO +
1100                                 (nesvnic->qp_nic_index[nic_count]*0x200));
1101                 u64temp += ((u64)nes_read_indexed(nesdev,
1102                                 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI +
1103                                 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1104
1105                 nesvnic->endnode_nstat_rx_octets += u64temp;
1106                 nesvnic->netstats.rx_bytes += u64temp;
1107
1108                 u64temp = (u64)nes_read_indexed(nesdev,
1109                                 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO +
1110                                 (nesvnic->qp_nic_index[nic_count]*0x200));
1111                 u64temp += ((u64)nes_read_indexed(nesdev,
1112                                 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI +
1113                                 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1114
1115                 nesvnic->endnode_nstat_rx_frames += u64temp;
1116                 nesvnic->netstats.rx_packets += u64temp;
1117
1118                 u64temp = (u64)nes_read_indexed(nesdev,
1119                                 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO +
1120                                 (nesvnic->qp_nic_index[nic_count]*0x200));
1121                 u64temp += ((u64)nes_read_indexed(nesdev,
1122                                 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI +
1123                                 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1124
1125                 nesvnic->endnode_nstat_tx_octets += u64temp;
1126                 nesvnic->netstats.tx_bytes += u64temp;
1127
1128                 u64temp = (u64)nes_read_indexed(nesdev,
1129                                 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO +
1130                                 (nesvnic->qp_nic_index[nic_count]*0x200));
1131                 u64temp += ((u64)nes_read_indexed(nesdev,
1132                                 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI +
1133                                 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1134
1135                 nesvnic->endnode_nstat_tx_frames += u64temp;
1136                 nesvnic->netstats.tx_packets += u64temp;
1137
1138                 u32temp = nes_read_indexed(nesdev,
1139                                 NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200));
1140                 nesvnic->endnode_ipv4_tcp_retransmits += u32temp;
1141         }
1142
1143         target_stat_values[4] = nesvnic->nesdev->mac_pause_frames_received;
1144         target_stat_values[5] = nesdev->nesadapter->nic_rx_eth_route_err;
1145         target_stat_values[6] = nesvnic->tx_sw_dropped;
1146         target_stat_values[7] = nesvnic->sq_locked;
1147         target_stat_values[8] = nesvnic->sq_full;
1148         target_stat_values[9] = nesvnic->segmented_tso_requests;
1149         target_stat_values[10] = nesvnic->nesdev->mac_rx_symbol_err_frames;
1150         target_stat_values[11] = nesvnic->nesdev->mac_rx_jabber_frames;
1151         target_stat_values[12] = nesvnic->nesdev->mac_rx_oversized_frames;
1152         target_stat_values[13] = nesvnic->nesdev->mac_rx_short_frames;
1153         target_stat_values[14] = nesvnic->endnode_nstat_rx_discard;
1154         target_stat_values[15] = nesvnic->endnode_nstat_rx_octets;
1155         target_stat_values[16] = nesvnic->endnode_nstat_rx_frames;
1156         target_stat_values[17] = nesvnic->endnode_nstat_tx_octets;
1157         target_stat_values[18] = nesvnic->endnode_nstat_tx_frames;
1158         target_stat_values[19] = mh_detected;
1159         target_stat_values[20] = mh_pauses_sent;
1160         target_stat_values[21] = nesvnic->endnode_ipv4_tcp_retransmits;
1161         target_stat_values[22] = atomic_read(&cm_connects);
1162         target_stat_values[23] = atomic_read(&cm_accepts);
1163         target_stat_values[24] = atomic_read(&cm_disconnects);
1164         target_stat_values[25] = atomic_read(&cm_connecteds);
1165         target_stat_values[26] = atomic_read(&cm_connect_reqs);
1166         target_stat_values[27] = atomic_read(&cm_rejects);
1167         target_stat_values[28] = atomic_read(&mod_qp_timouts);
1168         target_stat_values[29] = atomic_read(&qps_created);
1169         target_stat_values[30] = atomic_read(&sw_qps_destroyed);
1170         target_stat_values[31] = atomic_read(&qps_destroyed);
1171         target_stat_values[32] = atomic_read(&cm_closes);
1172         target_stat_values[33] = cm_packets_sent;
1173         target_stat_values[34] = cm_packets_bounced;
1174         target_stat_values[35] = cm_packets_created;
1175         target_stat_values[36] = cm_packets_received;
1176         target_stat_values[37] = cm_packets_dropped;
1177         target_stat_values[38] = cm_packets_retrans;
1178         target_stat_values[39] = cm_listens_created;
1179         target_stat_values[40] = cm_listens_destroyed;
1180         target_stat_values[41] = cm_backlog_drops;
1181         target_stat_values[42] = atomic_read(&cm_loopbacks);
1182         target_stat_values[43] = atomic_read(&cm_nodes_created);
1183         target_stat_values[44] = atomic_read(&cm_nodes_destroyed);
1184         target_stat_values[45] = atomic_read(&cm_accel_dropped_pkts);
1185         target_stat_values[46] = atomic_read(&cm_resets_recvd);
1186         target_stat_values[47] = int_mod_timer_init;
1187         target_stat_values[48] = int_mod_cq_depth_1;
1188         target_stat_values[49] = int_mod_cq_depth_4;
1189         target_stat_values[50] = int_mod_cq_depth_16;
1190         target_stat_values[51] = int_mod_cq_depth_24;
1191         target_stat_values[52] = int_mod_cq_depth_32;
1192         target_stat_values[53] = int_mod_cq_depth_128;
1193         target_stat_values[54] = int_mod_cq_depth_256;
1194
1195 }
1196
1197
1198 /**
1199  * nes_netdev_get_drvinfo
1200  */
1201 static void nes_netdev_get_drvinfo(struct net_device *netdev,
1202                 struct ethtool_drvinfo *drvinfo)
1203 {
1204         struct nes_vnic *nesvnic = netdev_priv(netdev);
1205
1206         strcpy(drvinfo->driver, DRV_NAME);
1207         strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
1208         strcpy(drvinfo->fw_version, "TBD");
1209         strcpy(drvinfo->version, DRV_VERSION);
1210         drvinfo->n_stats = nes_netdev_get_stats_count(netdev);
1211         drvinfo->testinfo_len = 0;
1212         drvinfo->eedump_len = 0;
1213         drvinfo->regdump_len = 0;
1214 }
1215
1216
1217 /**
1218  * nes_netdev_set_coalesce
1219  */
1220 static int nes_netdev_set_coalesce(struct net_device *netdev,
1221                 struct ethtool_coalesce *et_coalesce)
1222 {
1223         struct nes_vnic *nesvnic = netdev_priv(netdev);
1224         struct nes_device *nesdev =     nesvnic->nesdev;
1225         struct nes_adapter *nesadapter = nesdev->nesadapter;
1226         struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1227         unsigned long flags;
1228
1229         spin_lock_irqsave(&nesadapter->periodic_timer_lock,     flags);
1230         if (et_coalesce->rx_max_coalesced_frames_low) {
1231                 shared_timer->threshold_low      = et_coalesce->rx_max_coalesced_frames_low;
1232         }
1233         if (et_coalesce->rx_max_coalesced_frames_irq) {
1234                 shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq;
1235         }
1236         if (et_coalesce->rx_max_coalesced_frames_high) {
1237                 shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high;
1238         }
1239         if (et_coalesce->rx_coalesce_usecs_low) {
1240                 shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low;
1241         }
1242         if (et_coalesce->rx_coalesce_usecs_high) {
1243                 shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high;
1244         }
1245         spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1246
1247         /* using this to drive total interrupt moderation */
1248         nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq;
1249         if (et_coalesce->use_adaptive_rx_coalesce) {
1250                 nesadapter->et_use_adaptive_rx_coalesce = 1;
1251                 nesadapter->timer_int_limit     = NES_TIMER_INT_LIMIT_DYNAMIC;
1252                 nesadapter->et_rx_coalesce_usecs_irq = 0;
1253                 if (et_coalesce->pkt_rate_low) {
1254                         nesadapter->et_pkt_rate_low     = et_coalesce->pkt_rate_low;
1255                 }
1256         } else {
1257                 nesadapter->et_use_adaptive_rx_coalesce = 0;
1258                 nesadapter->timer_int_limit     = NES_TIMER_INT_LIMIT;
1259                 if (nesadapter->et_rx_coalesce_usecs_irq) {
1260                         nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
1261                                         0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8)));
1262                 }
1263         }
1264         return 0;
1265 }
1266
1267
1268 /**
1269  * nes_netdev_get_coalesce
1270  */
1271 static int nes_netdev_get_coalesce(struct net_device *netdev,
1272                 struct ethtool_coalesce *et_coalesce)
1273 {
1274         struct nes_vnic *nesvnic = netdev_priv(netdev);
1275         struct nes_device *nesdev =     nesvnic->nesdev;
1276         struct nes_adapter *nesadapter = nesdev->nesadapter;
1277         struct ethtool_coalesce temp_et_coalesce;
1278         struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1279         unsigned long flags;
1280
1281         memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce));
1282         temp_et_coalesce.rx_coalesce_usecs_irq = nesadapter->et_rx_coalesce_usecs_irq;
1283         temp_et_coalesce.use_adaptive_rx_coalesce =     nesadapter->et_use_adaptive_rx_coalesce;
1284         temp_et_coalesce.rate_sample_interval = nesadapter->et_rate_sample_interval;
1285         temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low;
1286         spin_lock_irqsave(&nesadapter->periodic_timer_lock,     flags);
1287         temp_et_coalesce.rx_max_coalesced_frames_low =  shared_timer->threshold_low;
1288         temp_et_coalesce.rx_max_coalesced_frames_irq =  shared_timer->threshold_target;
1289         temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
1290         temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min;
1291         temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max;
1292         if (nesadapter->et_use_adaptive_rx_coalesce) {
1293                 temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use;
1294         }
1295         spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1296         memcpy(et_coalesce,     &temp_et_coalesce, sizeof(*et_coalesce));
1297         return 0;
1298 }
1299
1300
1301 /**
1302  * nes_netdev_get_pauseparam
1303  */
1304 static void nes_netdev_get_pauseparam(struct net_device *netdev,
1305                 struct ethtool_pauseparam *et_pauseparam)
1306 {
1307         struct nes_vnic *nesvnic = netdev_priv(netdev);
1308
1309         et_pauseparam->autoneg = 0;
1310         et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0;
1311         et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0;
1312 }
1313
1314
1315 /**
1316  * nes_netdev_set_pauseparam
1317  */
1318 static int nes_netdev_set_pauseparam(struct net_device *netdev,
1319                 struct ethtool_pauseparam *et_pauseparam)
1320 {
1321         struct nes_vnic *nesvnic = netdev_priv(netdev);
1322         struct nes_device *nesdev = nesvnic->nesdev;
1323         u32 u32temp;
1324
1325         if (et_pauseparam->autoneg) {
1326                 /* TODO: should return unsupported */
1327                 return 0;
1328         }
1329         if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) {
1330                 u32temp = nes_read_indexed(nesdev,
1331                                 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
1332                 u32temp |= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
1333                 nes_write_indexed(nesdev,
1334                                 NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE + (nesdev->mac_index*0x200), u32temp);
1335                 nesdev->disable_tx_flow_control = 0;
1336         } else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) {
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 = 1;
1343         }
1344         if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) {
1345                 u32temp = nes_read_indexed(nesdev,
1346                                 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
1347                 u32temp &= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
1348                 nes_write_indexed(nesdev,
1349                                 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
1350                 nesdev->disable_rx_flow_control = 0;
1351         } else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) {
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 = 1;
1358         }
1359
1360         return 0;
1361 }
1362
1363
1364 /**
1365  * nes_netdev_get_settings
1366  */
1367 static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1368 {
1369         struct nes_vnic *nesvnic = netdev_priv(netdev);
1370         struct nes_device *nesdev = nesvnic->nesdev;
1371         struct nes_adapter *nesadapter = nesdev->nesadapter;
1372         u16 phy_data;
1373
1374         et_cmd->duplex = DUPLEX_FULL;
1375         et_cmd->port = PORT_MII;
1376         if (nesadapter->OneG_Mode) {
1377                 et_cmd->supported = SUPPORTED_1000baseT_Full|SUPPORTED_Autoneg;
1378                 et_cmd->advertising = ADVERTISED_1000baseT_Full|ADVERTISED_Autoneg;
1379                 et_cmd->speed = SPEED_1000;
1380                 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
1381                                 &phy_data);
1382                 if (phy_data&0x1000) {
1383                         et_cmd->autoneg = AUTONEG_ENABLE;
1384                 } else {
1385                         et_cmd->autoneg = AUTONEG_DISABLE;
1386                 }
1387                 et_cmd->transceiver = XCVR_EXTERNAL;
1388                 et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
1389         } else {
1390                 if (nesadapter->phy_type[nesvnic->logical_port] == NES_PHY_TYPE_IRIS) {
1391                         et_cmd->transceiver = XCVR_EXTERNAL;
1392                         et_cmd->port = PORT_FIBRE;
1393                         et_cmd->supported = SUPPORTED_FIBRE;
1394                         et_cmd->advertising = ADVERTISED_FIBRE;
1395                         et_cmd->phy_address = nesadapter->phy_index[nesdev->mac_index];
1396                 } else {
1397                         et_cmd->transceiver = XCVR_INTERNAL;
1398                         et_cmd->supported = SUPPORTED_10000baseT_Full;
1399                         et_cmd->advertising = ADVERTISED_10000baseT_Full;
1400                         et_cmd->phy_address = nesdev->mac_index;
1401                 }
1402                 et_cmd->speed = SPEED_10000;
1403                 et_cmd->autoneg = AUTONEG_DISABLE;
1404         }
1405         et_cmd->maxtxpkt = 511;
1406         et_cmd->maxrxpkt = 511;
1407         return 0;
1408 }
1409
1410
1411 /**
1412  * nes_netdev_set_settings
1413  */
1414 static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1415 {
1416         struct nes_vnic *nesvnic = netdev_priv(netdev);
1417         struct nes_device *nesdev = nesvnic->nesdev;
1418         struct nes_adapter *nesadapter = nesdev->nesadapter;
1419         u16 phy_data;
1420
1421         if (nesadapter->OneG_Mode) {
1422                 nes_read_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
1423                                 &phy_data);
1424                 if (et_cmd->autoneg) {
1425                         /* Turn on Full duplex, Autoneg, and restart autonegotiation */
1426                         phy_data |= 0x1300;
1427                 } else {
1428                         // Turn off autoneg
1429                         phy_data &= ~0x1000;
1430                 }
1431                 nes_write_1G_phy_reg(nesdev, 0, nesadapter->phy_index[nesdev->mac_index],
1432                                 phy_data);
1433         }
1434
1435         return 0;
1436 }
1437
1438
1439 static struct ethtool_ops nes_ethtool_ops = {
1440         .get_link = ethtool_op_get_link,
1441         .get_settings = nes_netdev_get_settings,
1442         .set_settings = nes_netdev_set_settings,
1443         .get_tx_csum = ethtool_op_get_tx_csum,
1444         .get_rx_csum = nes_netdev_get_rx_csum,
1445         .get_sg = ethtool_op_get_sg,
1446         .get_strings = nes_netdev_get_strings,
1447         .get_stats_count = nes_netdev_get_stats_count,
1448         .get_ethtool_stats = nes_netdev_get_ethtool_stats,
1449         .get_drvinfo = nes_netdev_get_drvinfo,
1450         .get_coalesce = nes_netdev_get_coalesce,
1451         .set_coalesce = nes_netdev_set_coalesce,
1452         .get_pauseparam = nes_netdev_get_pauseparam,
1453         .set_pauseparam = nes_netdev_set_pauseparam,
1454         .set_tx_csum = ethtool_op_set_tx_csum,
1455         .set_rx_csum = nes_netdev_set_rx_csum,
1456         .set_sg = ethtool_op_set_sg,
1457         .get_tso = ethtool_op_get_tso,
1458         .set_tso = ethtool_op_set_tso,
1459 };
1460
1461
1462 static void nes_netdev_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
1463 {
1464         struct nes_vnic *nesvnic = netdev_priv(netdev);
1465         struct nes_device *nesdev = nesvnic->nesdev;
1466         struct nes_adapter *nesadapter = nesdev->nesadapter;
1467         u32 u32temp;
1468         unsigned long flags;
1469
1470         spin_lock_irqsave(&nesadapter->phy_lock, flags);
1471         nesvnic->vlan_grp = grp;
1472
1473         nes_debug(NES_DBG_NETDEV, "%s: %s\n", __func__, netdev->name);
1474
1475         /* Enable/Disable VLAN Stripping */
1476         u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
1477         if (grp)
1478                 u32temp &= 0xfdffffff;
1479         else
1480                 u32temp |= 0x02000000;
1481
1482         nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
1483         spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1484 }
1485
1486
1487 /**
1488  * nes_netdev_init - initialize network device
1489  */
1490 struct net_device *nes_netdev_init(struct nes_device *nesdev,
1491                 void __iomem *mmio_addr)
1492 {
1493         u64 u64temp;
1494         struct nes_vnic *nesvnic = NULL;
1495         struct net_device *netdev;
1496         struct nic_qp_map *curr_qp_map;
1497         u32 u32temp;
1498         u16 phy_data;
1499         u16 temp_phy_data;
1500
1501         netdev = alloc_etherdev(sizeof(struct nes_vnic));
1502         if (!netdev) {
1503                 printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
1504                 return NULL;
1505         }
1506
1507         nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name);
1508
1509         SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev);
1510
1511         nesvnic = netdev_priv(netdev);
1512         memset(nesvnic, 0, sizeof(*nesvnic));
1513
1514         netdev->open = nes_netdev_open;
1515         netdev->stop = nes_netdev_stop;
1516         netdev->hard_start_xmit = nes_netdev_start_xmit;
1517         netdev->get_stats = nes_netdev_get_stats;
1518         netdev->tx_timeout = nes_netdev_tx_timeout;
1519         netdev->set_mac_address = nes_netdev_set_mac_address;
1520         netdev->set_multicast_list = nes_netdev_set_multicast_list;
1521         netdev->change_mtu = nes_netdev_change_mtu;
1522         netdev->watchdog_timeo = NES_TX_TIMEOUT;
1523         netdev->irq = nesdev->pcidev->irq;
1524         netdev->mtu = ETH_DATA_LEN;
1525         netdev->hard_header_len = ETH_HLEN;
1526         netdev->addr_len = ETH_ALEN;
1527         netdev->type = ARPHRD_ETHER;
1528         netdev->features = NETIF_F_HIGHDMA;
1529         netdev->ethtool_ops = &nes_ethtool_ops;
1530         netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128);
1531         nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n");
1532         netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
1533         netdev->vlan_rx_register = nes_netdev_vlan_rx_register;
1534         netdev->features |= NETIF_F_LLTX;
1535
1536         /* Fill in the port structure */
1537         nesvnic->netdev = netdev;
1538         nesvnic->nesdev = nesdev;
1539         nesvnic->msg_enable = netif_msg_init(debug, default_msg);
1540         nesvnic->netdev_index = nesdev->netdev_count;
1541         nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count;
1542         nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN;
1543
1544         curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)];
1545         nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid;
1546         nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index;
1547         nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port;
1548
1549         /* Setup the burned in MAC address */
1550         u64temp = (u64)nesdev->nesadapter->mac_addr_low;
1551         u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32;
1552         u64temp += nesvnic->nic_index;
1553         netdev->dev_addr[0] = (u8)(u64temp>>40);
1554         netdev->dev_addr[1] = (u8)(u64temp>>32);
1555         netdev->dev_addr[2] = (u8)(u64temp>>24);
1556         netdev->dev_addr[3] = (u8)(u64temp>>16);
1557         netdev->dev_addr[4] = (u8)(u64temp>>8);
1558         netdev->dev_addr[5] = (u8)u64temp;
1559         memcpy(netdev->perm_addr, netdev->dev_addr, 6);
1560
1561         if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV)) {
1562                 netdev->features |= NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
1563                 netdev->features |= NETIF_F_GSO | NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
1564         } else {
1565                 netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
1566         }
1567
1568         nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
1569                         " nic_index = %d, logical_port = %d, mac_index = %d.\n",
1570                         nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id,
1571                         nesvnic->nic_index, nesvnic->logical_port,  nesdev->mac_index);
1572
1573         if (nesvnic->nesdev->nesadapter->port_count == 1) {
1574                 nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1575                 nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1;
1576                 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) {
1577                         nesvnic->qp_nic_index[2] = 0xf;
1578                         nesvnic->qp_nic_index[3] = 0xf;
1579                 } else {
1580                         nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2;
1581                         nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3;
1582                 }
1583         } else {
1584                 if (nesvnic->nesdev->nesadapter->port_count == 2) {
1585                         nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1586                         nesvnic->qp_nic_index[1] = nesvnic->nic_index + 2;
1587                         nesvnic->qp_nic_index[2] = 0xf;
1588                         nesvnic->qp_nic_index[3] = 0xf;
1589                 } else {
1590                         nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1591                         nesvnic->qp_nic_index[1] = 0xf;
1592                         nesvnic->qp_nic_index[2] = 0xf;
1593                         nesvnic->qp_nic_index[3] = 0xf;
1594                 }
1595         }
1596         nesvnic->next_qp_nic_index = 0;
1597
1598         if (nesdev->netdev_count == 0) {
1599                 nesvnic->rdma_enabled = 1;
1600         } else {
1601                 nesvnic->rdma_enabled = 0;
1602         }
1603         nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id;
1604         spin_lock_init(&nesvnic->tx_lock);
1605         nesdev->netdev[nesdev->netdev_count] = netdev;
1606
1607         nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
1608                         nesvnic, nesdev->mac_index);
1609         list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]);
1610
1611         if ((nesdev->netdev_count == 0) &&
1612             (PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index)) {
1613                 nes_debug(NES_DBG_INIT, "Setting up PHY interrupt mask. Using register index 0x%04X\n",
1614                                 NES_IDX_PHY_PCS_CONTROL_STATUS0+(0x200*(nesvnic->logical_port&1)));
1615                 u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1616                                 (0x200*(nesvnic->logical_port&1)));
1617                 u32temp |= 0x00200000;
1618                 nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1619                                 (0x200*(nesvnic->logical_port&1)), u32temp);
1620                 u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1621                                 (0x200*(nesvnic->logical_port&1)) );
1622                 if ((u32temp&0x0f1f0000) == 0x0f0f0000) {
1623                         if (nesdev->nesadapter->phy_type[nesvnic->logical_port] == NES_PHY_TYPE_IRIS) {
1624                                 nes_init_phy(nesdev);
1625                                 nes_read_10G_phy_reg(nesdev, 1,
1626                                                 nesdev->nesadapter->phy_index[nesvnic->logical_port]);
1627                                 temp_phy_data = (u16)nes_read_indexed(nesdev,
1628                                                                         NES_IDX_MAC_MDIO_CONTROL);
1629                                 u32temp = 20;
1630                                 do {
1631                                         nes_read_10G_phy_reg(nesdev, 1,
1632                                                         nesdev->nesadapter->phy_index[nesvnic->logical_port]);
1633                                         phy_data = (u16)nes_read_indexed(nesdev,
1634                                                                         NES_IDX_MAC_MDIO_CONTROL);
1635                                         if ((phy_data == temp_phy_data) || (!(--u32temp)))
1636                                                 break;
1637                                         temp_phy_data = phy_data;
1638                                 } while (1);
1639                                 if (phy_data & 4) {
1640                                         nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
1641                                         nesvnic->linkup = 1;
1642                                 } else {
1643                                         nes_debug(NES_DBG_INIT, "The Link is DOWN!!.\n");
1644                                 }
1645                         } else {
1646                                 nes_debug(NES_DBG_INIT, "The Link is UP!!.\n");
1647                                 nesvnic->linkup = 1;
1648                         }
1649                 }
1650                 /* clear the MAC interrupt status, assumes direct logical to physical mapping */
1651                 u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index));
1652                 nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
1653                 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp);
1654
1655                 if (nesdev->nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_IRIS)
1656                         nes_init_phy(nesdev);
1657
1658         }
1659
1660         return netdev;
1661 }
1662
1663
1664 /**
1665  * nes_netdev_destroy - destroy network device structure
1666  */
1667 void nes_netdev_destroy(struct net_device *netdev)
1668 {
1669         struct nes_vnic *nesvnic = netdev_priv(netdev);
1670
1671         /* make sure 'stop' method is called by Linux stack */
1672         /* nes_netdev_stop(netdev); */
1673
1674         list_del(&nesvnic->list);
1675
1676         if (nesvnic->of_device_registered) {
1677                 nes_destroy_ofa_device(nesvnic->nesibdev);
1678         }
1679
1680         free_netdev(netdev);
1681 }
1682
1683
1684 /**
1685  * nes_nic_cm_xmit -- CM calls this to send out pkts
1686  */
1687 int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev)
1688 {
1689         int ret;
1690
1691         skb->dev = netdev;
1692         ret = dev_queue_xmit(skb);
1693         if (ret) {
1694                 nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret);
1695         }
1696
1697         return ret;
1698 }