Staging: zram: fix up some sysfs attribute permissions
[zen-stable.git] / drivers / infiniband / hw / nes / nes_nic.c
blob3892e2c0e95a57b38f2bd0258355d43540003e14
1 /*
2 * Copyright (c) 2006 - 2009 Intel Corporation. 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
12 * conditions are met:
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
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
30 * SOFTWARE.
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 <linux/slab.h>
44 #include <net/tcp.h>
46 #include <net/inet_common.h>
47 #include <linux/inet.h>
49 #include "nes.h"
51 static struct nic_qp_map nic_qp_mapping_0[] = {
52 {16,0,0,1},{24,4,0,0},{28,8,0,0},{32,12,0,0},
53 {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0},
54 {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
55 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
58 static struct nic_qp_map nic_qp_mapping_1[] = {
59 {18,1,1,1},{25,5,1,0},{29,9,1,0},{33,13,1,0},
60 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
63 static struct nic_qp_map nic_qp_mapping_2[] = {
64 {20,2,2,1},{26,6,2,0},{30,10,2,0},{34,14,2,0}
67 static struct nic_qp_map nic_qp_mapping_3[] = {
68 {22,3,3,1},{27,7,3,0},{31,11,3,0},{35,15,3,0}
71 static struct nic_qp_map nic_qp_mapping_4[] = {
72 {28,8,0,0},{32,12,0,0}
75 static struct nic_qp_map nic_qp_mapping_5[] = {
76 {29,9,1,0},{33,13,1,0}
79 static struct nic_qp_map nic_qp_mapping_6[] = {
80 {30,10,2,0},{34,14,2,0}
83 static struct nic_qp_map nic_qp_mapping_7[] = {
84 {31,11,3,0},{35,15,3,0}
87 static struct nic_qp_map *nic_qp_mapping_per_function[] = {
88 nic_qp_mapping_0, nic_qp_mapping_1, nic_qp_mapping_2, nic_qp_mapping_3,
89 nic_qp_mapping_4, nic_qp_mapping_5, nic_qp_mapping_6, nic_qp_mapping_7
92 static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
93 | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN;
94 static int debug = -1;
95 static int nics_per_function = 1;
97 /**
98 * nes_netdev_poll
100 static int nes_netdev_poll(struct napi_struct *napi, int budget)
102 struct nes_vnic *nesvnic = container_of(napi, struct nes_vnic, napi);
103 struct nes_device *nesdev = nesvnic->nesdev;
104 struct nes_hw_nic_cq *nescq = &nesvnic->nic_cq;
106 nesvnic->budget = budget;
107 nescq->cqes_pending = 0;
108 nescq->rx_cqes_completed = 0;
109 nescq->cqe_allocs_pending = 0;
110 nescq->rx_pkts_indicated = 0;
112 nes_nic_ce_handler(nesdev, nescq);
114 if (nescq->cqes_pending == 0) {
115 napi_complete(napi);
116 /* clear out completed cqes and arm */
117 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
118 nescq->cq_number | (nescq->cqe_allocs_pending << 16));
119 nes_read32(nesdev->regs+NES_CQE_ALLOC);
120 } else {
121 /* clear out completed cqes but don't arm */
122 nes_write32(nesdev->regs+NES_CQE_ALLOC,
123 nescq->cq_number | (nescq->cqe_allocs_pending << 16));
124 nes_debug(NES_DBG_NETDEV, "%s: exiting with work pending\n",
125 nesvnic->netdev->name);
127 return nescq->rx_pkts_indicated;
132 * nes_netdev_open - Activate the network interface; ifconfig
133 * ethx up.
135 static int nes_netdev_open(struct net_device *netdev)
137 u32 macaddr_low;
138 u16 macaddr_high;
139 struct nes_vnic *nesvnic = netdev_priv(netdev);
140 struct nes_device *nesdev = nesvnic->nesdev;
141 int ret;
142 int i;
143 struct nes_vnic *first_nesvnic = NULL;
144 u32 nic_active_bit;
145 u32 nic_active;
146 struct list_head *list_pos, *list_temp;
148 assert(nesdev != NULL);
150 if (nesvnic->netdev_open == 1)
151 return 0;
153 if (netif_msg_ifup(nesvnic))
154 printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name);
156 ret = nes_init_nic_qp(nesdev, netdev);
157 if (ret) {
158 return ret;
161 netif_carrier_off(netdev);
162 netif_stop_queue(netdev);
164 if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) {
165 nesvnic->nesibdev = nes_init_ofa_device(netdev);
166 if (nesvnic->nesibdev == NULL) {
167 printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name);
168 } else {
169 nesvnic->nesibdev->nesvnic = nesvnic;
170 ret = nes_register_ofa_device(nesvnic->nesibdev);
171 if (ret) {
172 printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n",
173 netdev->name, ret);
177 /* Set packet filters */
178 nic_active_bit = 1 << nesvnic->nic_index;
179 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
180 nic_active |= nic_active_bit;
181 nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
182 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
183 nic_active |= nic_active_bit;
184 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
185 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
186 nic_active |= nic_active_bit;
187 nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
189 macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
190 macaddr_high += (u16)netdev->dev_addr[1];
192 macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
193 macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
194 macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
195 macaddr_low += (u32)netdev->dev_addr[5];
197 /* Program the various MAC regs */
198 for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
199 if (nesvnic->qp_nic_index[i] == 0xf) {
200 break;
202 nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW"
203 " (Addr:%08X) = %08X, HIGH = %08X.\n",
204 i, nesvnic->qp_nic_index[i],
205 NES_IDX_PERFECT_FILTER_LOW+
206 (nesvnic->qp_nic_index[i] * 8),
207 macaddr_low,
208 (u32)macaddr_high | NES_MAC_ADDR_VALID |
209 ((((u32)nesvnic->nic_index) << 16)));
210 nes_write_indexed(nesdev,
211 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
212 macaddr_low);
213 nes_write_indexed(nesdev,
214 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
215 (u32)macaddr_high | NES_MAC_ADDR_VALID |
216 ((((u32)nesvnic->nic_index) << 16)));
220 nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
221 nesvnic->nic_cq.cq_number);
222 nes_read32(nesdev->regs+NES_CQE_ALLOC);
223 list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
224 first_nesvnic = container_of(list_pos, struct nes_vnic, list);
225 if (first_nesvnic->netdev_open == 1)
226 break;
228 if (first_nesvnic->netdev_open == 0) {
229 nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n");
230 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index),
231 ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
232 NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
233 first_nesvnic = nesvnic;
236 if (nesvnic->of_device_registered) {
237 nesdev->iw_status = 1;
238 nesdev->nesadapter->send_term_ok = 1;
239 nes_port_ibevent(nesvnic);
242 if (first_nesvnic->linkup) {
243 /* Enable network packets */
244 nesvnic->linkup = 1;
245 netif_start_queue(netdev);
246 netif_carrier_on(netdev);
248 napi_enable(&nesvnic->napi);
249 nesvnic->netdev_open = 1;
251 return 0;
256 * nes_netdev_stop
258 static int nes_netdev_stop(struct net_device *netdev)
260 struct nes_vnic *nesvnic = netdev_priv(netdev);
261 struct nes_device *nesdev = nesvnic->nesdev;
262 u32 nic_active_mask;
263 u32 nic_active;
264 struct nes_vnic *first_nesvnic = NULL;
265 struct list_head *list_pos, *list_temp;
267 nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n",
268 nesvnic, nesdev, netdev, netdev->name);
269 if (nesvnic->netdev_open == 0)
270 return 0;
272 if (netif_msg_ifdown(nesvnic))
273 printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);
274 netif_carrier_off(netdev);
276 /* Disable network packets */
277 napi_disable(&nesvnic->napi);
278 netif_stop_queue(netdev);
279 list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
280 first_nesvnic = container_of(list_pos, struct nes_vnic, list);
281 if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic))
282 break;
285 if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic) &&
286 (PCI_FUNC(first_nesvnic->nesdev->pcidev->devfn) !=
287 PCI_FUNC(nesvnic->nesdev->pcidev->devfn))) {
288 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+
289 (0x200*nesdev->mac_index), 0xffffffff);
290 nes_write_indexed(first_nesvnic->nesdev,
291 NES_IDX_MAC_INT_MASK+
292 (0x200*first_nesvnic->nesdev->mac_index),
293 ~(NES_MAC_INT_LINK_STAT_CHG | NES_MAC_INT_XGMII_EXT |
294 NES_MAC_INT_TX_UNDERFLOW | NES_MAC_INT_TX_ERROR));
295 } else {
296 nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
299 nic_active_mask = ~((u32)(1 << nesvnic->nic_index));
300 nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+
301 (nesvnic->perfect_filter_index*8), 0);
302 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
303 nic_active &= nic_active_mask;
304 nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
305 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
306 nic_active &= nic_active_mask;
307 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
308 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
309 nic_active &= nic_active_mask;
310 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
311 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
312 nic_active &= nic_active_mask;
313 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
314 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
315 nic_active &= nic_active_mask;
316 nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
319 if (nesvnic->of_device_registered) {
320 nesdev->nesadapter->send_term_ok = 0;
321 nesdev->iw_status = 0;
322 nes_port_ibevent(nesvnic);
324 nes_destroy_nic_qp(nesvnic);
326 nesvnic->netdev_open = 0;
328 return 0;
333 * nes_nic_send
335 static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev)
337 struct nes_vnic *nesvnic = netdev_priv(netdev);
338 struct nes_device *nesdev = nesvnic->nesdev;
339 struct nes_hw_nic *nesnic = &nesvnic->nic;
340 struct nes_hw_nic_sq_wqe *nic_sqe;
341 struct tcphdr *tcph;
342 __le16 *wqe_fragment_length;
343 u32 wqe_misc;
344 u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
345 u16 skb_fragment_index;
346 dma_addr_t bus_address;
348 nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
349 wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
351 /* setup the VLAN tag if present */
352 if (vlan_tx_tag_present(skb)) {
353 nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
354 netdev->name, vlan_tx_tag_get(skb));
355 wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
356 wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
357 } else
358 wqe_misc = 0;
360 /* bump past the vlan tag */
361 wqe_fragment_length++;
362 /* wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */
364 if (skb->ip_summed == CHECKSUM_PARTIAL) {
365 tcph = tcp_hdr(skb);
366 if (1) {
367 if (skb_is_gso(skb)) {
368 /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... seg size = %u\n",
369 netdev->name, skb_is_gso(skb)); */
370 wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE |
371 NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
372 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
373 ((u32)tcph->doff) |
374 (((u32)(((unsigned char *)tcph) - skb->data)) << 4));
375 } else {
376 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION;
379 } else { /* CHECKSUM_HW */
380 wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM | NES_NIC_SQ_WQE_COMPLETION;
383 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
384 skb->len);
385 memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
386 skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb)));
387 wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
388 skb_headlen(skb)));
389 wqe_fragment_length[1] = 0;
390 if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
391 if ((skb_shinfo(skb)->nr_frags + 1) > 4) {
392 nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n",
393 netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb));
394 kfree_skb(skb);
395 nesvnic->tx_sw_dropped++;
396 return NETDEV_TX_LOCKED;
398 set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
399 bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE,
400 skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE);
401 wqe_fragment_length[wqe_fragment_index++] =
402 cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE);
403 wqe_fragment_length[wqe_fragment_index] = 0;
404 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
405 ((u64)(bus_address)));
406 nesnic->tx_skb[nesnic->sq_head] = skb;
409 if (skb_headlen(skb) == skb->len) {
410 if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) {
411 nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_2_1_IDX] = 0;
412 nesnic->tx_skb[nesnic->sq_head] = skb;
414 } else {
415 /* Deal with Fragments */
416 nesnic->tx_skb[nesnic->sq_head] = skb;
417 for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags;
418 skb_fragment_index++) {
419 bus_address = pci_map_page( nesdev->pcidev,
420 skb_shinfo(skb)->frags[skb_fragment_index].page,
421 skb_shinfo(skb)->frags[skb_fragment_index].page_offset,
422 skb_shinfo(skb)->frags[skb_fragment_index].size,
423 PCI_DMA_TODEVICE);
424 wqe_fragment_length[wqe_fragment_index] =
425 cpu_to_le16(skb_shinfo(skb)->frags[skb_fragment_index].size);
426 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
427 bus_address);
428 wqe_fragment_index++;
429 if (wqe_fragment_index < 5)
430 wqe_fragment_length[wqe_fragment_index] = 0;
434 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc);
435 nesnic->sq_head++;
436 nesnic->sq_head &= nesnic->sq_size - 1;
438 return NETDEV_TX_OK;
443 * nes_netdev_start_xmit
445 static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev)
447 struct nes_vnic *nesvnic = netdev_priv(netdev);
448 struct nes_device *nesdev = nesvnic->nesdev;
449 struct nes_hw_nic *nesnic = &nesvnic->nic;
450 struct nes_hw_nic_sq_wqe *nic_sqe;
451 struct tcphdr *tcph;
452 /* struct udphdr *udph; */
453 #define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS
454 /* 64K segment plus overflow on each side */
455 dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS];
456 dma_addr_t bus_address;
457 u32 tso_frag_index;
458 u32 tso_frag_count;
459 u32 tso_wqe_length;
460 u32 curr_tcp_seq;
461 u32 wqe_count=1;
462 u32 send_rc;
463 struct iphdr *iph;
464 __le16 *wqe_fragment_length;
465 u32 nr_frags;
466 u32 original_first_length;
467 /* u64 *wqe_fragment_address; */
468 /* first fragment (0) is used by copy buffer */
469 u16 wqe_fragment_index=1;
470 u16 hoffset;
471 u16 nhoffset;
472 u16 wqes_needed;
473 u16 wqes_available;
474 u32 wqe_misc;
477 * nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
478 * " (%u frags), tso_size=%u\n",
479 * netdev->name, skb->len, skb_headlen(skb),
480 * skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
483 if (!netif_carrier_ok(netdev))
484 return NETDEV_TX_OK;
486 if (netif_queue_stopped(netdev))
487 return NETDEV_TX_BUSY;
489 /* Check if SQ is full */
490 if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) {
491 if (!netif_queue_stopped(netdev)) {
492 netif_stop_queue(netdev);
493 barrier();
494 if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) {
495 netif_start_queue(netdev);
496 goto sq_no_longer_full;
499 nesvnic->sq_full++;
500 return NETDEV_TX_BUSY;
503 sq_no_longer_full:
504 nr_frags = skb_shinfo(skb)->nr_frags;
505 if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
506 nr_frags++;
508 /* Check if too many fragments */
509 if (unlikely((nr_frags > 4))) {
510 if (skb_is_gso(skb)) {
511 nesvnic->segmented_tso_requests++;
512 nesvnic->tso_requests++;
513 /* Basically 4 fragments available per WQE with extended fragments */
514 wqes_needed = nr_frags >> 2;
515 wqes_needed += (nr_frags&3)?1:0;
516 wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) &
517 (nesnic->sq_size - 1);
519 if (unlikely(wqes_needed > wqes_available)) {
520 if (!netif_queue_stopped(netdev)) {
521 netif_stop_queue(netdev);
522 barrier();
523 wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) &
524 (nesnic->sq_size - 1);
525 if (wqes_needed <= wqes_available) {
526 netif_start_queue(netdev);
527 goto tso_sq_no_longer_full;
530 nesvnic->sq_full++;
531 nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n",
532 netdev->name);
533 return NETDEV_TX_BUSY;
535 tso_sq_no_longer_full:
536 /* Map all the buffers */
537 for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags;
538 tso_frag_count++) {
539 tso_bus_address[tso_frag_count] = pci_map_page( nesdev->pcidev,
540 skb_shinfo(skb)->frags[tso_frag_count].page,
541 skb_shinfo(skb)->frags[tso_frag_count].page_offset,
542 skb_shinfo(skb)->frags[tso_frag_count].size,
543 PCI_DMA_TODEVICE);
546 tso_frag_index = 0;
547 curr_tcp_seq = ntohl(tcp_hdr(skb)->seq);
548 hoffset = skb_transport_header(skb) - skb->data;
549 nhoffset = skb_network_header(skb) - skb->data;
550 original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2);
552 for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) {
553 tso_wqe_length = 0;
554 nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
555 wqe_fragment_length =
556 (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
557 /* setup the VLAN tag if present */
558 if (vlan_tx_tag_present(skb)) {
559 nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
560 netdev->name, vlan_tx_tag_get(skb) );
561 wqe_misc = NES_NIC_SQ_WQE_TAGVALUE_ENABLE;
562 wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
563 } else
564 wqe_misc = 0;
566 /* bump past the vlan tag */
567 wqe_fragment_length++;
569 /* Assumes header totally fits in allocated buffer and is in first fragment */
570 if (original_first_length > NES_FIRST_FRAG_SIZE) {
571 nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
572 original_first_length, NES_FIRST_FRAG_SIZE);
573 nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
574 " (%u frags), tso_size=%u\n",
575 netdev->name,
576 skb->len, skb_headlen(skb),
577 skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
579 memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
580 skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE),
581 original_first_length));
582 iph = (struct iphdr *)
583 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]);
584 tcph = (struct tcphdr *)
585 (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]);
586 if ((wqe_count+1)!=(u32)wqes_needed) {
587 tcph->fin = 0;
588 tcph->psh = 0;
589 tcph->rst = 0;
590 tcph->urg = 0;
592 if (wqe_count) {
593 tcph->syn = 0;
595 tcph->seq = htonl(curr_tcp_seq);
596 wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
597 original_first_length));
599 wqe_fragment_index = 1;
600 if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) {
601 set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
602 bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length,
603 skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE);
604 wqe_fragment_length[wqe_fragment_index++] =
605 cpu_to_le16(skb_headlen(skb) - original_first_length);
606 wqe_fragment_length[wqe_fragment_index] = 0;
607 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
608 bus_address);
609 tso_wqe_length += skb_headlen(skb) -
610 original_first_length;
612 while (wqe_fragment_index < 5) {
613 wqe_fragment_length[wqe_fragment_index] =
614 cpu_to_le16(skb_shinfo(skb)->frags[tso_frag_index].size);
615 set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
616 (u64)tso_bus_address[tso_frag_index]);
617 wqe_fragment_index++;
618 tso_wqe_length += skb_shinfo(skb)->frags[tso_frag_index++].size;
619 if (wqe_fragment_index < 5)
620 wqe_fragment_length[wqe_fragment_index] = 0;
621 if (tso_frag_index == tso_frag_count)
622 break;
624 if ((wqe_count+1) == (u32)wqes_needed) {
625 nesnic->tx_skb[nesnic->sq_head] = skb;
626 } else {
627 nesnic->tx_skb[nesnic->sq_head] = NULL;
629 wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_is_gso(skb);
630 if ((tso_wqe_length + original_first_length) > skb_is_gso(skb)) {
631 wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE;
632 } else {
633 iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset);
636 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX,
637 wqe_misc);
638 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
639 ((u32)tcph->doff) | (((u32)hoffset) << 4));
641 set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
642 tso_wqe_length + original_first_length);
643 curr_tcp_seq += tso_wqe_length;
644 nesnic->sq_head++;
645 nesnic->sq_head &= nesnic->sq_size-1;
647 } else {
648 nesvnic->linearized_skbs++;
649 hoffset = skb_transport_header(skb) - skb->data;
650 nhoffset = skb_network_header(skb) - skb->data;
651 skb_linearize(skb);
652 skb_set_transport_header(skb, hoffset);
653 skb_set_network_header(skb, nhoffset);
654 send_rc = nes_nic_send(skb, netdev);
655 if (send_rc != NETDEV_TX_OK)
656 return NETDEV_TX_OK;
658 } else {
659 send_rc = nes_nic_send(skb, netdev);
660 if (send_rc != NETDEV_TX_OK)
661 return NETDEV_TX_OK;
664 barrier();
666 if (wqe_count)
667 nes_write32(nesdev->regs+NES_WQE_ALLOC,
668 (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id);
670 netdev->trans_start = jiffies;
672 return NETDEV_TX_OK;
677 * nes_netdev_get_stats
679 static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev)
681 struct nes_vnic *nesvnic = netdev_priv(netdev);
682 struct nes_device *nesdev = nesvnic->nesdev;
683 u64 u64temp;
684 u32 u32temp;
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;
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;
696 nesvnic->endnode_nstat_rx_octets += u64temp;
697 nesvnic->netstats.rx_bytes += u64temp;
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;
704 nesvnic->endnode_nstat_rx_frames += u64temp;
705 nesvnic->netstats.rx_packets += u64temp;
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;
712 nesvnic->endnode_nstat_tx_octets += u64temp;
713 nesvnic->netstats.tx_bytes += u64temp;
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;
720 nesvnic->endnode_nstat_tx_frames += u64temp;
721 nesvnic->netstats.tx_packets += u64temp;
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;
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;
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;
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;
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;
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;
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;
763 return &nesvnic->netstats;
768 * nes_netdev_tx_timeout
770 static void nes_netdev_tx_timeout(struct net_device *netdev)
772 struct nes_vnic *nesvnic = netdev_priv(netdev);
774 if (netif_msg_timer(nesvnic))
775 nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name);
780 * nes_netdev_set_mac_address
782 static int nes_netdev_set_mac_address(struct net_device *netdev, void *p)
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;
791 if (!is_valid_ether_addr(mac_addr->sa_data))
792 return -EADDRNOTAVAIL;
794 memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
795 printk(PFX "%s: Address length = %d, Address = %pM\n",
796 __func__, netdev->addr_len, mac_addr->sa_data);
797 macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
798 macaddr_high += (u16)netdev->dev_addr[1];
799 macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
800 macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
801 macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
802 macaddr_low += (u32)netdev->dev_addr[5];
804 for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
805 if (nesvnic->qp_nic_index[i] == 0xf) {
806 break;
808 nes_write_indexed(nesdev,
809 NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
810 macaddr_low);
811 nes_write_indexed(nesdev,
812 NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
813 (u32)macaddr_high | NES_MAC_ADDR_VALID |
814 ((((u32)nesvnic->nic_index) << 16)));
816 return 0;
820 static void set_allmulti(struct nes_device *nesdev, u32 nic_active_bit)
822 u32 nic_active;
824 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
825 nic_active |= nic_active_bit;
826 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
827 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
828 nic_active &= ~nic_active_bit;
829 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
832 #define get_addr(addrs, index) ((addrs) + (index) * ETH_ALEN)
835 * nes_netdev_set_multicast_list
837 static void nes_netdev_set_multicast_list(struct net_device *netdev)
839 struct nes_vnic *nesvnic = netdev_priv(netdev);
840 struct nes_device *nesdev = nesvnic->nesdev;
841 struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
842 u32 nic_active_bit;
843 u32 nic_active;
844 u32 perfect_filter_register_address;
845 u32 macaddr_low;
846 u16 macaddr_high;
847 u8 mc_all_on = 0;
848 u8 mc_index;
849 int mc_nic_index = -1;
850 u8 pft_entries_preallocated = max(nesadapter->adapter_fcn_count *
851 nics_per_function, 4);
852 u8 max_pft_entries_avaiable = NES_PFT_SIZE - pft_entries_preallocated;
853 unsigned long flags;
854 int mc_count = netdev_mc_count(netdev);
856 spin_lock_irqsave(&nesadapter->resource_lock, flags);
857 nic_active_bit = 1 << nesvnic->nic_index;
859 if (netdev->flags & IFF_PROMISC) {
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 mc_all_on = 1;
867 } else if ((netdev->flags & IFF_ALLMULTI) ||
868 (nesvnic->nic_index > 3)) {
869 set_allmulti(nesdev, nic_active_bit);
870 mc_all_on = 1;
871 } else {
872 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
873 nic_active &= ~nic_active_bit;
874 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
875 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
876 nic_active &= ~nic_active_bit;
877 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
880 nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscous = %d, All Multicast = %d.\n",
881 mc_count, !!(netdev->flags & IFF_PROMISC),
882 !!(netdev->flags & IFF_ALLMULTI));
883 if (!mc_all_on) {
884 char *addrs;
885 int i;
886 struct netdev_hw_addr *ha;
888 addrs = kmalloc(ETH_ALEN * mc_count, GFP_ATOMIC);
889 if (!addrs) {
890 set_allmulti(nesdev, nic_active_bit);
891 goto unlock;
893 i = 0;
894 netdev_for_each_mc_addr(ha, netdev)
895 memcpy(get_addr(addrs, i++), ha->addr, ETH_ALEN);
897 perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW +
898 pft_entries_preallocated * 0x8;
899 for (i = 0, mc_index = 0; mc_index < max_pft_entries_avaiable;
900 mc_index++) {
901 while (i < mc_count && nesvnic->mcrq_mcast_filter &&
902 ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic,
903 get_addr(addrs, i++))) == 0));
904 if (mc_nic_index < 0)
905 mc_nic_index = nesvnic->nic_index;
906 while (nesadapter->pft_mcast_map[mc_index] < 16 &&
907 nesadapter->pft_mcast_map[mc_index] !=
908 nesvnic->nic_index &&
909 mc_index < max_pft_entries_avaiable) {
910 nes_debug(NES_DBG_NIC_RX,
911 "mc_index=%d skipping nic_index=%d,\
912 used for=%d \n", mc_index,
913 nesvnic->nic_index,
914 nesadapter->pft_mcast_map[mc_index]);
915 mc_index++;
917 if (mc_index >= max_pft_entries_avaiable)
918 break;
919 if (i < mc_count) {
920 char *addr = get_addr(addrs, i++);
922 nes_debug(NES_DBG_NIC_RX, "Assigning MC Address %pM to register 0x%04X nic_idx=%d\n",
923 addr,
924 perfect_filter_register_address+(mc_index * 8),
925 mc_nic_index);
926 macaddr_high = ((u16) addr[0]) << 8;
927 macaddr_high += (u16) addr[1];
928 macaddr_low = ((u32) addr[2]) << 24;
929 macaddr_low += ((u32) addr[3]) << 16;
930 macaddr_low += ((u32) addr[4]) << 8;
931 macaddr_low += (u32) addr[5];
932 nes_write_indexed(nesdev,
933 perfect_filter_register_address+(mc_index * 8),
934 macaddr_low);
935 nes_write_indexed(nesdev,
936 perfect_filter_register_address+4+(mc_index * 8),
937 (u32)macaddr_high | NES_MAC_ADDR_VALID |
938 ((((u32)(1<<mc_nic_index)) << 16)));
939 nesadapter->pft_mcast_map[mc_index] =
940 nesvnic->nic_index;
941 } else {
942 nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n",
943 perfect_filter_register_address+(mc_index * 8));
944 nes_write_indexed(nesdev,
945 perfect_filter_register_address+4+(mc_index * 8),
947 nesadapter->pft_mcast_map[mc_index] = 255;
950 kfree(addrs);
951 /* PFT is not large enough */
952 if (i < mc_count)
953 set_allmulti(nesdev, nic_active_bit);
956 unlock:
957 spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
962 * nes_netdev_change_mtu
964 static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
966 struct nes_vnic *nesvnic = netdev_priv(netdev);
967 struct nes_device *nesdev = nesvnic->nesdev;
968 int ret = 0;
969 u8 jumbomode = 0;
970 u32 nic_active;
971 u32 nic_active_bit;
972 u32 uc_all_active;
973 u32 mc_all_active;
975 if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu))
976 return -EINVAL;
978 netdev->mtu = new_mtu;
979 nesvnic->max_frame_size = new_mtu + VLAN_ETH_HLEN;
981 if (netdev->mtu > 1500) {
982 jumbomode=1;
984 nes_nic_init_timer_defaults(nesdev, jumbomode);
986 if (netif_running(netdev)) {
987 nic_active_bit = 1 << nesvnic->nic_index;
988 mc_all_active = nes_read_indexed(nesdev,
989 NES_IDX_NIC_MULTICAST_ALL) & nic_active_bit;
990 uc_all_active = nes_read_indexed(nesdev,
991 NES_IDX_NIC_UNICAST_ALL) & nic_active_bit;
993 nes_netdev_stop(netdev);
994 nes_netdev_open(netdev);
996 nic_active = nes_read_indexed(nesdev,
997 NES_IDX_NIC_MULTICAST_ALL);
998 nic_active |= mc_all_active;
999 nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL,
1000 nic_active);
1002 nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
1003 nic_active |= uc_all_active;
1004 nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
1007 return ret;
1011 static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = {
1012 "Link Change Interrupts",
1013 "Linearized SKBs",
1014 "T/GSO Requests",
1015 "Pause Frames Sent",
1016 "Pause Frames Received",
1017 "Internal Routing Errors",
1018 "SQ SW Dropped SKBs",
1019 "SQ Full",
1020 "Segmented TSO Requests",
1021 "Rx Symbol Errors",
1022 "Rx Jabber Errors",
1023 "Rx Oversized Frames",
1024 "Rx Short Frames",
1025 "Rx Length Errors",
1026 "Rx CRC Errors",
1027 "Rx Port Discard",
1028 "Endnode Rx Discards",
1029 "Endnode Rx Octets",
1030 "Endnode Rx Frames",
1031 "Endnode Tx Octets",
1032 "Endnode Tx Frames",
1033 "Tx Errors",
1034 "mh detected",
1035 "mh pauses",
1036 "Retransmission Count",
1037 "CM Connects",
1038 "CM Accepts",
1039 "Disconnects",
1040 "Connected Events",
1041 "Connect Requests",
1042 "CM Rejects",
1043 "ModifyQP Timeouts",
1044 "CreateQPs",
1045 "SW DestroyQPs",
1046 "DestroyQPs",
1047 "CM Closes",
1048 "CM Packets Sent",
1049 "CM Packets Bounced",
1050 "CM Packets Created",
1051 "CM Packets Rcvd",
1052 "CM Packets Dropped",
1053 "CM Packets Retrans",
1054 "CM Listens Created",
1055 "CM Listens Destroyed",
1056 "CM Backlog Drops",
1057 "CM Loopbacks",
1058 "CM Nodes Created",
1059 "CM Nodes Destroyed",
1060 "CM Accel Drops",
1061 "CM Resets Received",
1062 "Free 4Kpbls",
1063 "Free 256pbls",
1064 "Timer Inits",
1065 "LRO aggregated",
1066 "LRO flushed",
1067 "LRO no_desc",
1069 #define NES_ETHTOOL_STAT_COUNT ARRAY_SIZE(nes_ethtool_stringset)
1072 * nes_netdev_get_rx_csum
1074 static u32 nes_netdev_get_rx_csum (struct net_device *netdev)
1076 struct nes_vnic *nesvnic = netdev_priv(netdev);
1078 if (nesvnic->rx_checksum_disabled)
1079 return 0;
1080 else
1081 return 1;
1086 * nes_netdev_set_rc_csum
1088 static int nes_netdev_set_rx_csum(struct net_device *netdev, u32 enable)
1090 struct nes_vnic *nesvnic = netdev_priv(netdev);
1092 if (enable)
1093 nesvnic->rx_checksum_disabled = 0;
1094 else
1095 nesvnic->rx_checksum_disabled = 1;
1096 return 0;
1101 * nes_netdev_get_sset_count
1103 static int nes_netdev_get_sset_count(struct net_device *netdev, int stringset)
1105 if (stringset == ETH_SS_STATS)
1106 return NES_ETHTOOL_STAT_COUNT;
1107 else
1108 return -EINVAL;
1113 * nes_netdev_get_strings
1115 static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset,
1116 u8 *ethtool_strings)
1118 if (stringset == ETH_SS_STATS)
1119 memcpy(ethtool_strings,
1120 &nes_ethtool_stringset,
1121 sizeof(nes_ethtool_stringset));
1126 * nes_netdev_get_ethtool_stats
1129 static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
1130 struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values)
1132 u64 u64temp;
1133 struct nes_vnic *nesvnic = netdev_priv(netdev);
1134 struct nes_device *nesdev = nesvnic->nesdev;
1135 struct nes_adapter *nesadapter = nesdev->nesadapter;
1136 u32 nic_count;
1137 u32 u32temp;
1138 u32 index = 0;
1140 target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
1141 target_stat_values[index] = nesvnic->nesdev->link_status_interrupts;
1142 target_stat_values[++index] = nesvnic->linearized_skbs;
1143 target_stat_values[++index] = nesvnic->tso_requests;
1145 u32temp = nes_read_indexed(nesdev,
1146 NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1147 nesvnic->nesdev->mac_pause_frames_sent += u32temp;
1148 target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_sent;
1150 u32temp = nes_read_indexed(nesdev,
1151 NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1152 nesvnic->nesdev->mac_pause_frames_received += u32temp;
1154 u32temp = nes_read_indexed(nesdev,
1155 NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1156 nesvnic->nesdev->port_rx_discards += u32temp;
1157 nesvnic->netstats.rx_dropped += u32temp;
1159 u32temp = nes_read_indexed(nesdev,
1160 NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1161 nesvnic->nesdev->port_tx_discards += u32temp;
1162 nesvnic->netstats.tx_dropped += u32temp;
1164 u32temp = nes_read_indexed(nesdev,
1165 NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1166 nesvnic->netstats.rx_dropped += u32temp;
1167 nesvnic->nesdev->mac_rx_errors += u32temp;
1168 nesvnic->nesdev->mac_rx_short_frames += u32temp;
1170 u32temp = nes_read_indexed(nesdev,
1171 NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1172 nesvnic->netstats.rx_dropped += u32temp;
1173 nesvnic->nesdev->mac_rx_errors += u32temp;
1174 nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
1176 u32temp = nes_read_indexed(nesdev,
1177 NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1178 nesvnic->netstats.rx_dropped += u32temp;
1179 nesvnic->nesdev->mac_rx_errors += u32temp;
1180 nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
1182 u32temp = nes_read_indexed(nesdev,
1183 NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1184 nesvnic->netstats.rx_dropped += u32temp;
1185 nesvnic->nesdev->mac_rx_errors += u32temp;
1186 nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
1188 u32temp = nes_read_indexed(nesdev,
1189 NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1190 nesvnic->netstats.rx_length_errors += u32temp;
1191 nesvnic->nesdev->mac_rx_errors += u32temp;
1193 u32temp = nes_read_indexed(nesdev,
1194 NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1195 nesvnic->nesdev->mac_rx_errors += u32temp;
1196 nesvnic->nesdev->mac_rx_crc_errors += u32temp;
1197 nesvnic->netstats.rx_crc_errors += u32temp;
1199 u32temp = nes_read_indexed(nesdev,
1200 NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
1201 nesvnic->nesdev->mac_tx_errors += u32temp;
1202 nesvnic->netstats.tx_errors += u32temp;
1204 for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) {
1205 if (nesvnic->qp_nic_index[nic_count] == 0xf)
1206 break;
1208 u32temp = nes_read_indexed(nesdev,
1209 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD +
1210 (nesvnic->qp_nic_index[nic_count]*0x200));
1211 nesvnic->netstats.rx_dropped += u32temp;
1212 nesvnic->endnode_nstat_rx_discard += u32temp;
1214 u64temp = (u64)nes_read_indexed(nesdev,
1215 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO +
1216 (nesvnic->qp_nic_index[nic_count]*0x200));
1217 u64temp += ((u64)nes_read_indexed(nesdev,
1218 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI +
1219 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1221 nesvnic->endnode_nstat_rx_octets += u64temp;
1222 nesvnic->netstats.rx_bytes += u64temp;
1224 u64temp = (u64)nes_read_indexed(nesdev,
1225 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO +
1226 (nesvnic->qp_nic_index[nic_count]*0x200));
1227 u64temp += ((u64)nes_read_indexed(nesdev,
1228 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI +
1229 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1231 nesvnic->endnode_nstat_rx_frames += u64temp;
1232 nesvnic->netstats.rx_packets += u64temp;
1234 u64temp = (u64)nes_read_indexed(nesdev,
1235 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO +
1236 (nesvnic->qp_nic_index[nic_count]*0x200));
1237 u64temp += ((u64)nes_read_indexed(nesdev,
1238 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI +
1239 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1241 nesvnic->endnode_nstat_tx_octets += u64temp;
1242 nesvnic->netstats.tx_bytes += u64temp;
1244 u64temp = (u64)nes_read_indexed(nesdev,
1245 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO +
1246 (nesvnic->qp_nic_index[nic_count]*0x200));
1247 u64temp += ((u64)nes_read_indexed(nesdev,
1248 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI +
1249 (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1251 nesvnic->endnode_nstat_tx_frames += u64temp;
1252 nesvnic->netstats.tx_packets += u64temp;
1254 u32temp = nes_read_indexed(nesdev,
1255 NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200));
1256 nesvnic->endnode_ipv4_tcp_retransmits += u32temp;
1259 target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_received;
1260 target_stat_values[++index] = nesdev->nesadapter->nic_rx_eth_route_err;
1261 target_stat_values[++index] = nesvnic->tx_sw_dropped;
1262 target_stat_values[++index] = nesvnic->sq_full;
1263 target_stat_values[++index] = nesvnic->segmented_tso_requests;
1264 target_stat_values[++index] = nesvnic->nesdev->mac_rx_symbol_err_frames;
1265 target_stat_values[++index] = nesvnic->nesdev->mac_rx_jabber_frames;
1266 target_stat_values[++index] = nesvnic->nesdev->mac_rx_oversized_frames;
1267 target_stat_values[++index] = nesvnic->nesdev->mac_rx_short_frames;
1268 target_stat_values[++index] = nesvnic->netstats.rx_length_errors;
1269 target_stat_values[++index] = nesvnic->nesdev->mac_rx_crc_errors;
1270 target_stat_values[++index] = nesvnic->nesdev->port_rx_discards;
1271 target_stat_values[++index] = nesvnic->endnode_nstat_rx_discard;
1272 target_stat_values[++index] = nesvnic->endnode_nstat_rx_octets;
1273 target_stat_values[++index] = nesvnic->endnode_nstat_rx_frames;
1274 target_stat_values[++index] = nesvnic->endnode_nstat_tx_octets;
1275 target_stat_values[++index] = nesvnic->endnode_nstat_tx_frames;
1276 target_stat_values[++index] = nesvnic->nesdev->mac_tx_errors;
1277 target_stat_values[++index] = mh_detected;
1278 target_stat_values[++index] = mh_pauses_sent;
1279 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
1280 target_stat_values[++index] = atomic_read(&cm_connects);
1281 target_stat_values[++index] = atomic_read(&cm_accepts);
1282 target_stat_values[++index] = atomic_read(&cm_disconnects);
1283 target_stat_values[++index] = atomic_read(&cm_connecteds);
1284 target_stat_values[++index] = atomic_read(&cm_connect_reqs);
1285 target_stat_values[++index] = atomic_read(&cm_rejects);
1286 target_stat_values[++index] = atomic_read(&mod_qp_timouts);
1287 target_stat_values[++index] = atomic_read(&qps_created);
1288 target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
1289 target_stat_values[++index] = atomic_read(&qps_destroyed);
1290 target_stat_values[++index] = atomic_read(&cm_closes);
1291 target_stat_values[++index] = cm_packets_sent;
1292 target_stat_values[++index] = cm_packets_bounced;
1293 target_stat_values[++index] = cm_packets_created;
1294 target_stat_values[++index] = cm_packets_received;
1295 target_stat_values[++index] = cm_packets_dropped;
1296 target_stat_values[++index] = cm_packets_retrans;
1297 target_stat_values[++index] = atomic_read(&cm_listens_created);
1298 target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
1299 target_stat_values[++index] = cm_backlog_drops;
1300 target_stat_values[++index] = atomic_read(&cm_loopbacks);
1301 target_stat_values[++index] = atomic_read(&cm_nodes_created);
1302 target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
1303 target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
1304 target_stat_values[++index] = atomic_read(&cm_resets_recvd);
1305 target_stat_values[++index] = nesadapter->free_4kpbl;
1306 target_stat_values[++index] = nesadapter->free_256pbl;
1307 target_stat_values[++index] = int_mod_timer_init;
1308 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
1309 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
1310 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
1314 * nes_netdev_get_drvinfo
1316 static void nes_netdev_get_drvinfo(struct net_device *netdev,
1317 struct ethtool_drvinfo *drvinfo)
1319 struct nes_vnic *nesvnic = netdev_priv(netdev);
1320 struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
1322 strcpy(drvinfo->driver, DRV_NAME);
1323 strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
1324 sprintf(drvinfo->fw_version, "%u.%u", nesadapter->firmware_version>>16,
1325 nesadapter->firmware_version & 0x000000ff);
1326 strcpy(drvinfo->version, DRV_VERSION);
1327 drvinfo->testinfo_len = 0;
1328 drvinfo->eedump_len = 0;
1329 drvinfo->regdump_len = 0;
1334 * nes_netdev_set_coalesce
1336 static int nes_netdev_set_coalesce(struct net_device *netdev,
1337 struct ethtool_coalesce *et_coalesce)
1339 struct nes_vnic *nesvnic = netdev_priv(netdev);
1340 struct nes_device *nesdev = nesvnic->nesdev;
1341 struct nes_adapter *nesadapter = nesdev->nesadapter;
1342 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1343 unsigned long flags;
1345 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1346 if (et_coalesce->rx_max_coalesced_frames_low) {
1347 shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low;
1349 if (et_coalesce->rx_max_coalesced_frames_irq) {
1350 shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq;
1352 if (et_coalesce->rx_max_coalesced_frames_high) {
1353 shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high;
1355 if (et_coalesce->rx_coalesce_usecs_low) {
1356 shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low;
1358 if (et_coalesce->rx_coalesce_usecs_high) {
1359 shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high;
1361 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1363 /* using this to drive total interrupt moderation */
1364 nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq;
1365 if (et_coalesce->use_adaptive_rx_coalesce) {
1366 nesadapter->et_use_adaptive_rx_coalesce = 1;
1367 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT_DYNAMIC;
1368 nesadapter->et_rx_coalesce_usecs_irq = 0;
1369 if (et_coalesce->pkt_rate_low) {
1370 nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low;
1372 } else {
1373 nesadapter->et_use_adaptive_rx_coalesce = 0;
1374 nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
1375 if (nesadapter->et_rx_coalesce_usecs_irq) {
1376 nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
1377 0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8)));
1380 return 0;
1385 * nes_netdev_get_coalesce
1387 static int nes_netdev_get_coalesce(struct net_device *netdev,
1388 struct ethtool_coalesce *et_coalesce)
1390 struct nes_vnic *nesvnic = netdev_priv(netdev);
1391 struct nes_device *nesdev = nesvnic->nesdev;
1392 struct nes_adapter *nesadapter = nesdev->nesadapter;
1393 struct ethtool_coalesce temp_et_coalesce;
1394 struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1395 unsigned long flags;
1397 memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce));
1398 temp_et_coalesce.rx_coalesce_usecs_irq = nesadapter->et_rx_coalesce_usecs_irq;
1399 temp_et_coalesce.use_adaptive_rx_coalesce = nesadapter->et_use_adaptive_rx_coalesce;
1400 temp_et_coalesce.rate_sample_interval = nesadapter->et_rate_sample_interval;
1401 temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low;
1402 spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1403 temp_et_coalesce.rx_max_coalesced_frames_low = shared_timer->threshold_low;
1404 temp_et_coalesce.rx_max_coalesced_frames_irq = shared_timer->threshold_target;
1405 temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
1406 temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min;
1407 temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max;
1408 if (nesadapter->et_use_adaptive_rx_coalesce) {
1409 temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use;
1411 spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1412 memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce));
1413 return 0;
1418 * nes_netdev_get_pauseparam
1420 static void nes_netdev_get_pauseparam(struct net_device *netdev,
1421 struct ethtool_pauseparam *et_pauseparam)
1423 struct nes_vnic *nesvnic = netdev_priv(netdev);
1425 et_pauseparam->autoneg = 0;
1426 et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0;
1427 et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0;
1432 * nes_netdev_set_pauseparam
1434 static int nes_netdev_set_pauseparam(struct net_device *netdev,
1435 struct ethtool_pauseparam *et_pauseparam)
1437 struct nes_vnic *nesvnic = netdev_priv(netdev);
1438 struct nes_device *nesdev = nesvnic->nesdev;
1439 u32 u32temp;
1441 if (et_pauseparam->autoneg) {
1442 /* TODO: should return unsupported */
1443 return 0;
1445 if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) {
1446 u32temp = nes_read_indexed(nesdev,
1447 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
1448 u32temp |= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
1449 nes_write_indexed(nesdev,
1450 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
1451 nesdev->disable_tx_flow_control = 0;
1452 } else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) {
1453 u32temp = nes_read_indexed(nesdev,
1454 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
1455 u32temp &= ~NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE;
1456 nes_write_indexed(nesdev,
1457 NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
1458 nesdev->disable_tx_flow_control = 1;
1460 if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) {
1461 u32temp = nes_read_indexed(nesdev,
1462 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
1463 u32temp &= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
1464 nes_write_indexed(nesdev,
1465 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
1466 nesdev->disable_rx_flow_control = 0;
1467 } else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) {
1468 u32temp = nes_read_indexed(nesdev,
1469 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
1470 u32temp |= NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE;
1471 nes_write_indexed(nesdev,
1472 NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
1473 nesdev->disable_rx_flow_control = 1;
1476 return 0;
1481 * nes_netdev_get_settings
1483 static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1485 struct nes_vnic *nesvnic = netdev_priv(netdev);
1486 struct nes_device *nesdev = nesvnic->nesdev;
1487 struct nes_adapter *nesadapter = nesdev->nesadapter;
1488 u32 mac_index = nesdev->mac_index;
1489 u8 phy_type = nesadapter->phy_type[mac_index];
1490 u8 phy_index = nesadapter->phy_index[mac_index];
1491 u16 phy_data;
1493 et_cmd->duplex = DUPLEX_FULL;
1494 et_cmd->port = PORT_MII;
1495 et_cmd->maxtxpkt = 511;
1496 et_cmd->maxrxpkt = 511;
1498 if (nesadapter->OneG_Mode) {
1499 et_cmd->speed = SPEED_1000;
1500 if (phy_type == NES_PHY_TYPE_PUMA_1G) {
1501 et_cmd->supported = SUPPORTED_1000baseT_Full;
1502 et_cmd->advertising = ADVERTISED_1000baseT_Full;
1503 et_cmd->autoneg = AUTONEG_DISABLE;
1504 et_cmd->transceiver = XCVR_INTERNAL;
1505 et_cmd->phy_address = mac_index;
1506 } else {
1507 unsigned long flags;
1508 et_cmd->supported = SUPPORTED_1000baseT_Full
1509 | SUPPORTED_Autoneg;
1510 et_cmd->advertising = ADVERTISED_1000baseT_Full
1511 | ADVERTISED_Autoneg;
1512 spin_lock_irqsave(&nesadapter->phy_lock, flags);
1513 nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
1514 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1515 if (phy_data & 0x1000)
1516 et_cmd->autoneg = AUTONEG_ENABLE;
1517 else
1518 et_cmd->autoneg = AUTONEG_DISABLE;
1519 et_cmd->transceiver = XCVR_EXTERNAL;
1520 et_cmd->phy_address = phy_index;
1522 return 0;
1524 if ((phy_type == NES_PHY_TYPE_ARGUS) ||
1525 (phy_type == NES_PHY_TYPE_SFP_D) ||
1526 (phy_type == NES_PHY_TYPE_KR)) {
1527 et_cmd->transceiver = XCVR_EXTERNAL;
1528 et_cmd->port = PORT_FIBRE;
1529 et_cmd->supported = SUPPORTED_FIBRE;
1530 et_cmd->advertising = ADVERTISED_FIBRE;
1531 et_cmd->phy_address = phy_index;
1532 } else {
1533 et_cmd->transceiver = XCVR_INTERNAL;
1534 et_cmd->supported = SUPPORTED_10000baseT_Full;
1535 et_cmd->advertising = ADVERTISED_10000baseT_Full;
1536 et_cmd->phy_address = mac_index;
1538 et_cmd->speed = SPEED_10000;
1539 et_cmd->autoneg = AUTONEG_DISABLE;
1540 return 0;
1545 * nes_netdev_set_settings
1547 static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1549 struct nes_vnic *nesvnic = netdev_priv(netdev);
1550 struct nes_device *nesdev = nesvnic->nesdev;
1551 struct nes_adapter *nesadapter = nesdev->nesadapter;
1553 if ((nesadapter->OneG_Mode) &&
1554 (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) {
1555 unsigned long flags;
1556 u16 phy_data;
1557 u8 phy_index = nesadapter->phy_index[nesdev->mac_index];
1559 spin_lock_irqsave(&nesadapter->phy_lock, flags);
1560 nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
1561 if (et_cmd->autoneg) {
1562 /* Turn on Full duplex, Autoneg, and restart autonegotiation */
1563 phy_data |= 0x1300;
1564 } else {
1565 /* Turn off autoneg */
1566 phy_data &= ~0x1000;
1568 nes_write_1G_phy_reg(nesdev, 0, phy_index, phy_data);
1569 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1572 return 0;
1576 static int nes_netdev_set_flags(struct net_device *netdev, u32 flags)
1578 return ethtool_op_set_flags(netdev, flags, ETH_FLAG_LRO);
1582 static const struct ethtool_ops nes_ethtool_ops = {
1583 .get_link = ethtool_op_get_link,
1584 .get_settings = nes_netdev_get_settings,
1585 .set_settings = nes_netdev_set_settings,
1586 .get_tx_csum = ethtool_op_get_tx_csum,
1587 .get_rx_csum = nes_netdev_get_rx_csum,
1588 .get_sg = ethtool_op_get_sg,
1589 .get_strings = nes_netdev_get_strings,
1590 .get_sset_count = nes_netdev_get_sset_count,
1591 .get_ethtool_stats = nes_netdev_get_ethtool_stats,
1592 .get_drvinfo = nes_netdev_get_drvinfo,
1593 .get_coalesce = nes_netdev_get_coalesce,
1594 .set_coalesce = nes_netdev_set_coalesce,
1595 .get_pauseparam = nes_netdev_get_pauseparam,
1596 .set_pauseparam = nes_netdev_set_pauseparam,
1597 .set_tx_csum = ethtool_op_set_tx_csum,
1598 .set_rx_csum = nes_netdev_set_rx_csum,
1599 .set_sg = ethtool_op_set_sg,
1600 .get_tso = ethtool_op_get_tso,
1601 .set_tso = ethtool_op_set_tso,
1602 .get_flags = ethtool_op_get_flags,
1603 .set_flags = nes_netdev_set_flags,
1607 static void nes_netdev_vlan_rx_register(struct net_device *netdev, struct vlan_group *grp)
1609 struct nes_vnic *nesvnic = netdev_priv(netdev);
1610 struct nes_device *nesdev = nesvnic->nesdev;
1611 struct nes_adapter *nesadapter = nesdev->nesadapter;
1612 u32 u32temp;
1613 unsigned long flags;
1615 spin_lock_irqsave(&nesadapter->phy_lock, flags);
1616 nesvnic->vlan_grp = grp;
1618 nes_debug(NES_DBG_NETDEV, "%s: %s\n", __func__, netdev->name);
1620 /* Enable/Disable VLAN Stripping */
1621 u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
1622 if (grp)
1623 u32temp &= 0xfdffffff;
1624 else
1625 u32temp |= 0x02000000;
1627 nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
1628 spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1631 static const struct net_device_ops nes_netdev_ops = {
1632 .ndo_open = nes_netdev_open,
1633 .ndo_stop = nes_netdev_stop,
1634 .ndo_start_xmit = nes_netdev_start_xmit,
1635 .ndo_get_stats = nes_netdev_get_stats,
1636 .ndo_tx_timeout = nes_netdev_tx_timeout,
1637 .ndo_set_mac_address = nes_netdev_set_mac_address,
1638 .ndo_set_multicast_list = nes_netdev_set_multicast_list,
1639 .ndo_change_mtu = nes_netdev_change_mtu,
1640 .ndo_validate_addr = eth_validate_addr,
1641 .ndo_vlan_rx_register = nes_netdev_vlan_rx_register,
1645 * nes_netdev_init - initialize network device
1647 struct net_device *nes_netdev_init(struct nes_device *nesdev,
1648 void __iomem *mmio_addr)
1650 u64 u64temp;
1651 struct nes_vnic *nesvnic;
1652 struct net_device *netdev;
1653 struct nic_qp_map *curr_qp_map;
1654 u8 phy_type = nesdev->nesadapter->phy_type[nesdev->mac_index];
1656 netdev = alloc_etherdev(sizeof(struct nes_vnic));
1657 if (!netdev) {
1658 printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
1659 return NULL;
1661 nesvnic = netdev_priv(netdev);
1663 nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name);
1665 SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev);
1667 netdev->watchdog_timeo = NES_TX_TIMEOUT;
1668 netdev->irq = nesdev->pcidev->irq;
1669 netdev->mtu = ETH_DATA_LEN;
1670 netdev->hard_header_len = ETH_HLEN;
1671 netdev->addr_len = ETH_ALEN;
1672 netdev->type = ARPHRD_ETHER;
1673 netdev->features = NETIF_F_HIGHDMA;
1674 netdev->netdev_ops = &nes_netdev_ops;
1675 netdev->ethtool_ops = &nes_ethtool_ops;
1676 netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128);
1677 nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n");
1678 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
1680 /* Fill in the port structure */
1681 nesvnic->netdev = netdev;
1682 nesvnic->nesdev = nesdev;
1683 nesvnic->msg_enable = netif_msg_init(debug, default_msg);
1684 nesvnic->netdev_index = nesdev->netdev_count;
1685 nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count;
1686 nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN;
1688 curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)];
1689 nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid;
1690 nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index;
1691 nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port;
1693 /* Setup the burned in MAC address */
1694 u64temp = (u64)nesdev->nesadapter->mac_addr_low;
1695 u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32;
1696 u64temp += nesvnic->nic_index;
1697 netdev->dev_addr[0] = (u8)(u64temp>>40);
1698 netdev->dev_addr[1] = (u8)(u64temp>>32);
1699 netdev->dev_addr[2] = (u8)(u64temp>>24);
1700 netdev->dev_addr[3] = (u8)(u64temp>>16);
1701 netdev->dev_addr[4] = (u8)(u64temp>>8);
1702 netdev->dev_addr[5] = (u8)u64temp;
1703 memcpy(netdev->perm_addr, netdev->dev_addr, 6);
1705 if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV)) {
1706 netdev->features |= NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
1707 netdev->features |= NETIF_F_GSO | NETIF_F_TSO | NETIF_F_SG | NETIF_F_IP_CSUM;
1708 } else {
1709 netdev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
1712 nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
1713 " nic_index = %d, logical_port = %d, mac_index = %d.\n",
1714 nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id,
1715 nesvnic->nic_index, nesvnic->logical_port, nesdev->mac_index);
1717 if (nesvnic->nesdev->nesadapter->port_count == 1 &&
1718 nesvnic->nesdev->nesadapter->adapter_fcn_count == 1) {
1720 nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1721 nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1;
1722 if (nes_drv_opt & NES_DRV_OPT_DUAL_LOGICAL_PORT) {
1723 nesvnic->qp_nic_index[2] = 0xf;
1724 nesvnic->qp_nic_index[3] = 0xf;
1725 } else {
1726 nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2;
1727 nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3;
1729 } else {
1730 if (nesvnic->nesdev->nesadapter->port_count == 2 ||
1731 (nesvnic->nesdev->nesadapter->port_count == 1 &&
1732 nesvnic->nesdev->nesadapter->adapter_fcn_count == 2)) {
1733 nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1734 nesvnic->qp_nic_index[1] = nesvnic->nic_index
1735 + 2;
1736 nesvnic->qp_nic_index[2] = 0xf;
1737 nesvnic->qp_nic_index[3] = 0xf;
1738 } else {
1739 nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1740 nesvnic->qp_nic_index[1] = 0xf;
1741 nesvnic->qp_nic_index[2] = 0xf;
1742 nesvnic->qp_nic_index[3] = 0xf;
1745 nesvnic->next_qp_nic_index = 0;
1747 if (nesdev->netdev_count == 0) {
1748 nesvnic->rdma_enabled = 1;
1749 } else {
1750 nesvnic->rdma_enabled = 0;
1752 nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id;
1753 spin_lock_init(&nesvnic->tx_lock);
1754 nesdev->netdev[nesdev->netdev_count] = netdev;
1756 nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
1757 nesvnic, nesdev->mac_index);
1758 list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]);
1760 if ((nesdev->netdev_count == 0) &&
1761 ((PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index) ||
1762 ((phy_type == NES_PHY_TYPE_PUMA_1G) &&
1763 (((PCI_FUNC(nesdev->pcidev->devfn) == 1) && (nesdev->mac_index == 2)) ||
1764 ((PCI_FUNC(nesdev->pcidev->devfn) == 2) && (nesdev->mac_index == 1)))))) {
1765 u32 u32temp;
1766 u32 link_mask;
1767 u32 link_val;
1769 u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1770 (0x200 * (nesdev->mac_index & 1)));
1771 if (phy_type != NES_PHY_TYPE_PUMA_1G) {
1772 u32temp |= 0x00200000;
1773 nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1774 (0x200 * (nesdev->mac_index & 1)), u32temp);
1777 /* Check and set linkup here. This is for back to back */
1778 /* configuration where second port won't get link interrupt */
1779 switch (phy_type) {
1780 case NES_PHY_TYPE_PUMA_1G:
1781 if (nesdev->mac_index < 2) {
1782 link_mask = 0x01010000;
1783 link_val = 0x01010000;
1784 } else {
1785 link_mask = 0x02020000;
1786 link_val = 0x02020000;
1788 break;
1789 default:
1790 link_mask = 0x0f1f0000;
1791 link_val = 0x0f0f0000;
1792 break;
1795 u32temp = nes_read_indexed(nesdev,
1796 NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1797 (0x200 * (nesdev->mac_index & 1)));
1798 if ((u32temp & link_mask) == link_val)
1799 nesvnic->linkup = 1;
1801 /* clear the MAC interrupt status, assumes direct logical to physical mapping */
1802 u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index));
1803 nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
1804 nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp);
1806 nes_init_phy(nesdev);
1809 return netdev;
1814 * nes_netdev_destroy - destroy network device structure
1816 void nes_netdev_destroy(struct net_device *netdev)
1818 struct nes_vnic *nesvnic = netdev_priv(netdev);
1820 /* make sure 'stop' method is called by Linux stack */
1821 /* nes_netdev_stop(netdev); */
1823 list_del(&nesvnic->list);
1825 if (nesvnic->of_device_registered) {
1826 nes_destroy_ofa_device(nesvnic->nesibdev);
1829 free_netdev(netdev);
1834 * nes_nic_cm_xmit -- CM calls this to send out pkts
1836 int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev)
1838 int ret;
1840 skb->dev = netdev;
1841 ret = dev_queue_xmit(skb);
1842 if (ret) {
1843 nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret);
1846 return ret;