Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nes_nic.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2006 - 2011 Intel Corporation. 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 <linux/slab.h>
44 #include <net/tcp.h>
45 
46 #include <net/inet_common.h>
47 #include <linux/inet.h>
48 
49 #include "nes.h"
50 
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}
56 };
57 
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}
61 };
62 
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}
65 };
66 
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}
69 };
70 
71 static struct nic_qp_map nic_qp_mapping_4[] = {
72  {28,8,0,0},{32,12,0,0}
73 };
74 
75 static struct nic_qp_map nic_qp_mapping_5[] = {
76  {29,9,1,0},{33,13,1,0}
77 };
78 
79 static struct nic_qp_map nic_qp_mapping_6[] = {
80  {30,10,2,0},{34,14,2,0}
81 };
82 
83 static struct nic_qp_map nic_qp_mapping_7[] = {
84  {31,11,3,0},{35,15,3,0}
85 };
86 
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
90 };
91 
92 static const u32 default_msg = NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK
94 static int debug = -1;
95 static int nics_per_function = 1;
96 
100 static int nes_netdev_poll(struct napi_struct *napi, int budget)
101 {
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;
105 
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;
111 
112  nes_nic_ce_handler(nesdev, nescq);
113 
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);
126  }
127  return nescq->rx_pkts_indicated;
128 }
129 
130 
135 static int nes_netdev_open(struct net_device *netdev)
136 {
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;
147  unsigned long flags;
148 
149  assert(nesdev != NULL);
150 
151  if (nesvnic->netdev_open == 1)
152  return 0;
153 
154  if (netif_msg_ifup(nesvnic))
155  printk(KERN_INFO PFX "%s: enabling interface\n", netdev->name);
156 
157  ret = nes_init_nic_qp(nesdev, netdev);
158  if (ret) {
159  return ret;
160  }
161 
162  netif_carrier_off(netdev);
163  netif_stop_queue(netdev);
164 
165  if ((!nesvnic->of_device_registered) && (nesvnic->rdma_enabled)) {
166  nesvnic->nesibdev = nes_init_ofa_device(netdev);
167  if (nesvnic->nesibdev == NULL) {
168  printk(KERN_ERR PFX "%s: nesvnic->nesibdev alloc failed", netdev->name);
169  } else {
170  nesvnic->nesibdev->nesvnic = nesvnic;
171  ret = nes_register_ofa_device(nesvnic->nesibdev);
172  if (ret) {
173  printk(KERN_ERR PFX "%s: Unable to register RDMA device, ret = %d\n",
174  netdev->name, ret);
175  }
176  }
177  }
178  /* Set packet filters */
179  nic_active_bit = 1 << nesvnic->nic_index;
180  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
181  nic_active |= nic_active_bit;
182  nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
183  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
184  nic_active |= nic_active_bit;
185  nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
186  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
187  nic_active |= nic_active_bit;
188  nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
189 
190  macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
191  macaddr_high += (u16)netdev->dev_addr[1];
192 
193  macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
194  macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
195  macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
196  macaddr_low += (u32)netdev->dev_addr[5];
197 
198  /* Program the various MAC regs */
199  for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
200  if (nesvnic->qp_nic_index[i] == 0xf) {
201  break;
202  }
203  nes_debug(NES_DBG_NETDEV, "i=%d, perfect filter table index= %d, PERF FILTER LOW"
204  " (Addr:%08X) = %08X, HIGH = %08X.\n",
205  i, nesvnic->qp_nic_index[i],
207  (nesvnic->qp_nic_index[i] * 8),
208  macaddr_low,
209  (u32)macaddr_high | NES_MAC_ADDR_VALID |
210  ((((u32)nesvnic->nic_index) << 16)));
211  nes_write_indexed(nesdev,
212  NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
213  macaddr_low);
214  nes_write_indexed(nesdev,
215  NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
216  (u32)macaddr_high | NES_MAC_ADDR_VALID |
217  ((((u32)nesvnic->nic_index) << 16)));
218  }
219 
220 
221  nes_write32(nesdev->regs+NES_CQE_ALLOC, NES_CQE_ALLOC_NOTIFY_NEXT |
222  nesvnic->nic_cq.cq_number);
223  nes_read32(nesdev->regs+NES_CQE_ALLOC);
224  list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
225  first_nesvnic = container_of(list_pos, struct nes_vnic, list);
226  if (first_nesvnic->netdev_open == 1)
227  break;
228  }
229  if (first_nesvnic->netdev_open == 0) {
230  nes_debug(NES_DBG_INIT, "Setting up MAC interrupt mask.\n");
231  nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK + (0x200 * nesdev->mac_index),
234  first_nesvnic = nesvnic;
235  }
236 
237  if (first_nesvnic->linkup) {
238  /* Enable network packets */
239  nesvnic->linkup = 1;
240  netif_start_queue(netdev);
241  netif_carrier_on(netdev);
242  }
243 
244  spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
245  if (nesdev->nesadapter->phy_type[nesdev->mac_index] == NES_PHY_TYPE_SFP_D) {
246  nesdev->link_recheck = 1;
247  mod_delayed_work(system_wq, &nesdev->work,
249  }
250  spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
251 
252  spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags);
253  if (nesvnic->of_device_registered) {
254  nesdev->nesadapter->send_term_ok = 1;
255  if (nesvnic->linkup == 1) {
256  if (nesdev->iw_status == 0) {
257  nesdev->iw_status = 1;
258  nes_port_ibevent(nesvnic);
259  }
260  } else {
261  nesdev->iw_status = 0;
262  }
263  }
264  spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags);
265 
266  napi_enable(&nesvnic->napi);
267  nesvnic->netdev_open = 1;
268 
269  return 0;
270 }
271 
272 
276 static int nes_netdev_stop(struct net_device *netdev)
277 {
278  struct nes_vnic *nesvnic = netdev_priv(netdev);
279  struct nes_device *nesdev = nesvnic->nesdev;
280  u32 nic_active_mask;
281  u32 nic_active;
282  struct nes_vnic *first_nesvnic = NULL;
283  struct list_head *list_pos, *list_temp;
284  unsigned long flags;
285 
286  nes_debug(NES_DBG_SHUTDOWN, "nesvnic=%p, nesdev=%p, netdev=%p %s\n",
287  nesvnic, nesdev, netdev, netdev->name);
288  if (nesvnic->netdev_open == 0)
289  return 0;
290 
291  if (netif_msg_ifdown(nesvnic))
292  printk(KERN_INFO PFX "%s: disabling interface\n", netdev->name);
293  netif_carrier_off(netdev);
294 
295  /* Disable network packets */
296  napi_disable(&nesvnic->napi);
297  netif_stop_queue(netdev);
298  list_for_each_safe(list_pos, list_temp, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]) {
299  first_nesvnic = container_of(list_pos, struct nes_vnic, list);
300  if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic))
301  break;
302  }
303 
304  if ((first_nesvnic->netdev_open == 1) && (first_nesvnic != nesvnic) &&
305  (PCI_FUNC(first_nesvnic->nesdev->pcidev->devfn) !=
306  PCI_FUNC(nesvnic->nesdev->pcidev->devfn))) {
307  nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+
308  (0x200*nesdev->mac_index), 0xffffffff);
309  nes_write_indexed(first_nesvnic->nesdev,
311  (0x200*first_nesvnic->nesdev->mac_index),
314  } else {
315  nes_write_indexed(nesdev, NES_IDX_MAC_INT_MASK+(0x200*nesdev->mac_index), 0xffffffff);
316  }
317 
318  nic_active_mask = ~((u32)(1 << nesvnic->nic_index));
319  nes_write_indexed(nesdev, NES_IDX_PERFECT_FILTER_HIGH+
320  (nesvnic->perfect_filter_index*8), 0);
321  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_ACTIVE);
322  nic_active &= nic_active_mask;
323  nes_write_indexed(nesdev, NES_IDX_NIC_ACTIVE, nic_active);
324  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
325  nic_active &= nic_active_mask;
326  nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
327  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE);
328  nic_active &= nic_active_mask;
329  nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ENABLE, nic_active);
330  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
331  nic_active &= nic_active_mask;
332  nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
333  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON);
334  nic_active &= nic_active_mask;
335  nes_write_indexed(nesdev, NES_IDX_NIC_BROADCAST_ON, nic_active);
336 
337  spin_lock_irqsave(&nesvnic->port_ibevent_lock, flags);
338  if (nesvnic->of_device_registered) {
339  nesdev->nesadapter->send_term_ok = 0;
340  nesdev->iw_status = 0;
341  if (nesvnic->linkup == 1)
342  nes_port_ibevent(nesvnic);
343  }
344  del_timer_sync(&nesvnic->event_timer);
345  nesvnic->event_timer.function = NULL;
346  spin_unlock_irqrestore(&nesvnic->port_ibevent_lock, flags);
347 
348  nes_destroy_nic_qp(nesvnic);
349 
350  nesvnic->netdev_open = 0;
351 
352  return 0;
353 }
354 
355 
359 static int nes_nic_send(struct sk_buff *skb, struct net_device *netdev)
360 {
361  struct nes_vnic *nesvnic = netdev_priv(netdev);
362  struct nes_device *nesdev = nesvnic->nesdev;
363  struct nes_hw_nic *nesnic = &nesvnic->nic;
364  struct nes_hw_nic_sq_wqe *nic_sqe;
365  struct tcphdr *tcph;
366  __le16 *wqe_fragment_length;
367  u32 wqe_misc;
368  u16 wqe_fragment_index = 1; /* first fragment (0) is used by copy buffer */
369  u16 skb_fragment_index;
370  dma_addr_t bus_address;
371 
372  nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
373  wqe_fragment_length = (__le16 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX];
374 
375  /* setup the VLAN tag if present */
376  if (vlan_tx_tag_present(skb)) {
377  nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
378  netdev->name, vlan_tx_tag_get(skb));
380  wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
381  } else
382  wqe_misc = 0;
383 
384  /* bump past the vlan tag */
385  wqe_fragment_length++;
386  /* wqe_fragment_address = (u64 *)&nic_sqe->wqe_words[NES_NIC_SQ_WQE_FRAG0_LOW_IDX]; */
387  wqe_misc |= NES_NIC_SQ_WQE_COMPLETION;
388 
389  if (skb->ip_summed == CHECKSUM_PARTIAL) {
390  if (skb_is_gso(skb)) {
391  tcph = tcp_hdr(skb);
392  /* nes_debug(NES_DBG_NIC_TX, "%s: TSO request... is_gso = %u seg size = %u\n",
393  netdev->name, skb_is_gso(skb), skb_shinfo(skb)->gso_size); */
394  wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE | (u16)skb_shinfo(skb)->gso_size;
395  set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
396  ((u32)tcph->doff) |
397  (((u32)(((unsigned char *)tcph) - skb->data)) << 4));
398  }
399  } else { /* CHECKSUM_HW */
400  wqe_misc |= NES_NIC_SQ_WQE_DISABLE_CHKSUM;
401  }
402 
403  set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
404  skb->len);
405  memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
406  skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE), skb_headlen(skb)));
407  wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
408  skb_headlen(skb)));
409  wqe_fragment_length[1] = 0;
410  if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
411  if ((skb_shinfo(skb)->nr_frags + 1) > 4) {
412  nes_debug(NES_DBG_NIC_TX, "%s: Packet with %u fragments not sent, skb_headlen=%u\n",
413  netdev->name, skb_shinfo(skb)->nr_frags + 2, skb_headlen(skb));
414  kfree_skb(skb);
415  nesvnic->tx_sw_dropped++;
416  return NETDEV_TX_LOCKED;
417  }
418  set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
419  bus_address = pci_map_single(nesdev->pcidev, skb->data + NES_FIRST_FRAG_SIZE,
420  skb_headlen(skb) - NES_FIRST_FRAG_SIZE, PCI_DMA_TODEVICE);
421  wqe_fragment_length[wqe_fragment_index++] =
422  cpu_to_le16(skb_headlen(skb) - NES_FIRST_FRAG_SIZE);
423  wqe_fragment_length[wqe_fragment_index] = 0;
424  set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
425  ((u64)(bus_address)));
426  nesnic->tx_skb[nesnic->sq_head] = skb;
427  }
428 
429  if (skb_headlen(skb) == skb->len) {
430  if (skb_headlen(skb) <= NES_FIRST_FRAG_SIZE) {
432  nesnic->tx_skb[nesnic->sq_head] = skb;
433  }
434  } else {
435  /* Deal with Fragments */
436  nesnic->tx_skb[nesnic->sq_head] = skb;
437  for (skb_fragment_index = 0; skb_fragment_index < skb_shinfo(skb)->nr_frags;
438  skb_fragment_index++) {
439  skb_frag_t *frag =
440  &skb_shinfo(skb)->frags[skb_fragment_index];
441  bus_address = skb_frag_dma_map(&nesdev->pcidev->dev,
442  frag, 0, skb_frag_size(frag),
443  DMA_TO_DEVICE);
444  wqe_fragment_length[wqe_fragment_index] =
445  cpu_to_le16(skb_frag_size(&skb_shinfo(skb)->frags[skb_fragment_index]));
446  set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
447  bus_address);
448  wqe_fragment_index++;
449  if (wqe_fragment_index < 5)
450  wqe_fragment_length[wqe_fragment_index] = 0;
451  }
452  }
453 
454  set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX, wqe_misc);
455  nesnic->sq_head++;
456  nesnic->sq_head &= nesnic->sq_size - 1;
457 
458  return NETDEV_TX_OK;
459 }
460 
461 
465 static int nes_netdev_start_xmit(struct sk_buff *skb, struct net_device *netdev)
466 {
467  struct nes_vnic *nesvnic = netdev_priv(netdev);
468  struct nes_device *nesdev = nesvnic->nesdev;
469  struct nes_hw_nic *nesnic = &nesvnic->nic;
470  struct nes_hw_nic_sq_wqe *nic_sqe;
471  struct tcphdr *tcph;
472  /* struct udphdr *udph; */
473 #define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS
474  /* 64K segment plus overflow on each side */
475  dma_addr_t tso_bus_address[NES_MAX_TSO_FRAGS];
476  dma_addr_t bus_address;
477  u32 tso_frag_index;
478  u32 tso_frag_count;
479  u32 tso_wqe_length;
480  u32 curr_tcp_seq;
481  u32 wqe_count=1;
482  u32 send_rc;
483  struct iphdr *iph;
484  __le16 *wqe_fragment_length;
485  u32 nr_frags;
486  u32 original_first_length;
487  /* u64 *wqe_fragment_address; */
488  /* first fragment (0) is used by copy buffer */
489  u16 wqe_fragment_index=1;
490  u16 hoffset;
491  u16 nhoffset;
492  u16 wqes_needed;
493  u16 wqes_available;
494  u32 wqe_misc;
495 
496  /*
497  * nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
498  * " (%u frags), tso_size=%u\n",
499  * netdev->name, skb->len, skb_headlen(skb),
500  * skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
501  */
502 
503  if (!netif_carrier_ok(netdev))
504  return NETDEV_TX_OK;
505 
506  if (netif_queue_stopped(netdev))
507  return NETDEV_TX_BUSY;
508 
509  /* Check if SQ is full */
510  if ((((nesnic->sq_tail+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) == 1) {
511  if (!netif_queue_stopped(netdev)) {
512  netif_stop_queue(netdev);
513  barrier();
514  if ((((((volatile u16)nesnic->sq_tail)+(nesnic->sq_size*2))-nesnic->sq_head) & (nesnic->sq_size - 1)) != 1) {
515  netif_start_queue(netdev);
516  goto sq_no_longer_full;
517  }
518  }
519  nesvnic->sq_full++;
520  return NETDEV_TX_BUSY;
521  }
522 
523 sq_no_longer_full:
524  nr_frags = skb_shinfo(skb)->nr_frags;
525  if (skb_headlen(skb) > NES_FIRST_FRAG_SIZE) {
526  nr_frags++;
527  }
528  /* Check if too many fragments */
529  if (unlikely((nr_frags > 4))) {
530  if (skb_is_gso(skb)) {
531  nesvnic->segmented_tso_requests++;
532  nesvnic->tso_requests++;
533  /* Basically 4 fragments available per WQE with extended fragments */
534  wqes_needed = nr_frags >> 2;
535  wqes_needed += (nr_frags&3)?1:0;
536  wqes_available = (((nesnic->sq_tail+nesnic->sq_size)-nesnic->sq_head) - 1) &
537  (nesnic->sq_size - 1);
538 
539  if (unlikely(wqes_needed > wqes_available)) {
540  if (!netif_queue_stopped(netdev)) {
541  netif_stop_queue(netdev);
542  barrier();
543  wqes_available = (((((volatile u16)nesnic->sq_tail)+nesnic->sq_size)-nesnic->sq_head) - 1) &
544  (nesnic->sq_size - 1);
545  if (wqes_needed <= wqes_available) {
546  netif_start_queue(netdev);
547  goto tso_sq_no_longer_full;
548  }
549  }
550  nesvnic->sq_full++;
551  nes_debug(NES_DBG_NIC_TX, "%s: HNIC SQ full- TSO request has too many frags!\n",
552  netdev->name);
553  return NETDEV_TX_BUSY;
554  }
555 tso_sq_no_longer_full:
556  /* Map all the buffers */
557  for (tso_frag_count=0; tso_frag_count < skb_shinfo(skb)->nr_frags;
558  tso_frag_count++) {
559  skb_frag_t *frag =
560  &skb_shinfo(skb)->frags[tso_frag_count];
561  tso_bus_address[tso_frag_count] =
562  skb_frag_dma_map(&nesdev->pcidev->dev,
563  frag, 0, skb_frag_size(frag),
564  DMA_TO_DEVICE);
565  }
566 
567  tso_frag_index = 0;
568  curr_tcp_seq = ntohl(tcp_hdr(skb)->seq);
569  hoffset = skb_transport_header(skb) - skb->data;
570  nhoffset = skb_network_header(skb) - skb->data;
571  original_first_length = hoffset + ((((struct tcphdr *)skb_transport_header(skb))->doff)<<2);
572 
573  for (wqe_count=0; wqe_count<((u32)wqes_needed); wqe_count++) {
574  tso_wqe_length = 0;
575  nic_sqe = &nesnic->sq_vbase[nesnic->sq_head];
576  wqe_fragment_length =
578  /* setup the VLAN tag if present */
579  if (vlan_tx_tag_present(skb)) {
580  nes_debug(NES_DBG_NIC_TX, "%s: VLAN packet to send... VLAN = %08X\n",
581  netdev->name, vlan_tx_tag_get(skb) );
583  wqe_fragment_length[0] = (__force __le16) vlan_tx_tag_get(skb);
584  } else
585  wqe_misc = 0;
586 
587  /* bump past the vlan tag */
588  wqe_fragment_length++;
589 
590  /* Assumes header totally fits in allocated buffer and is in first fragment */
591  if (original_first_length > NES_FIRST_FRAG_SIZE) {
592  nes_debug(NES_DBG_NIC_TX, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
593  original_first_length, NES_FIRST_FRAG_SIZE);
594  nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
595  " (%u frags), is_gso = %u tso_size=%u\n",
596  netdev->name,
597  skb->len, skb_headlen(skb),
598  skb_shinfo(skb)->nr_frags, skb_is_gso(skb), skb_shinfo(skb)->gso_size);
599  }
600  memcpy(&nesnic->first_frag_vbase[nesnic->sq_head].buffer,
601  skb->data, min(((unsigned int)NES_FIRST_FRAG_SIZE),
602  original_first_length));
603  iph = (struct iphdr *)
604  (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[nhoffset]);
605  tcph = (struct tcphdr *)
606  (&nesnic->first_frag_vbase[nesnic->sq_head].buffer[hoffset]);
607  if ((wqe_count+1)!=(u32)wqes_needed) {
608  tcph->fin = 0;
609  tcph->psh = 0;
610  tcph->rst = 0;
611  tcph->urg = 0;
612  }
613  if (wqe_count) {
614  tcph->syn = 0;
615  }
616  tcph->seq = htonl(curr_tcp_seq);
617  wqe_fragment_length[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE),
618  original_first_length));
619 
620  wqe_fragment_index = 1;
621  if ((wqe_count==0) && (skb_headlen(skb) > original_first_length)) {
622  set_bit(nesnic->sq_head, nesnic->first_frag_overflow);
623  bus_address = pci_map_single(nesdev->pcidev, skb->data + original_first_length,
624  skb_headlen(skb) - original_first_length, PCI_DMA_TODEVICE);
625  wqe_fragment_length[wqe_fragment_index++] =
626  cpu_to_le16(skb_headlen(skb) - original_first_length);
627  wqe_fragment_length[wqe_fragment_index] = 0;
628  set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG1_LOW_IDX,
629  bus_address);
630  tso_wqe_length += skb_headlen(skb) -
631  original_first_length;
632  }
633  while (wqe_fragment_index < 5) {
634  wqe_fragment_length[wqe_fragment_index] =
635  cpu_to_le16(skb_frag_size(&skb_shinfo(skb)->frags[tso_frag_index]));
636  set_wqe_64bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_FRAG0_LOW_IDX+(2*wqe_fragment_index),
637  (u64)tso_bus_address[tso_frag_index]);
638  wqe_fragment_index++;
639  tso_wqe_length += skb_frag_size(&skb_shinfo(skb)->frags[tso_frag_index++]);
640  if (wqe_fragment_index < 5)
641  wqe_fragment_length[wqe_fragment_index] = 0;
642  if (tso_frag_index == tso_frag_count)
643  break;
644  }
645  if ((wqe_count+1) == (u32)wqes_needed) {
646  nesnic->tx_skb[nesnic->sq_head] = skb;
647  } else {
648  nesnic->tx_skb[nesnic->sq_head] = NULL;
649  }
650  wqe_misc |= NES_NIC_SQ_WQE_COMPLETION | (u16)skb_shinfo(skb)->gso_size;
651  if ((tso_wqe_length + original_first_length) > skb_shinfo(skb)->gso_size) {
652  wqe_misc |= NES_NIC_SQ_WQE_LSO_ENABLE;
653  } else {
654  iph->tot_len = htons(tso_wqe_length + original_first_length - nhoffset);
655  }
656 
657  set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_MISC_IDX,
658  wqe_misc);
659  set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_LSO_INFO_IDX,
660  ((u32)tcph->doff) | (((u32)hoffset) << 4));
661 
662  set_wqe_32bit_value(nic_sqe->wqe_words, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX,
663  tso_wqe_length + original_first_length);
664  curr_tcp_seq += tso_wqe_length;
665  nesnic->sq_head++;
666  nesnic->sq_head &= nesnic->sq_size-1;
667  }
668  } else {
669  nesvnic->linearized_skbs++;
670  hoffset = skb_transport_header(skb) - skb->data;
671  nhoffset = skb_network_header(skb) - skb->data;
672  skb_linearize(skb);
673  skb_set_transport_header(skb, hoffset);
674  skb_set_network_header(skb, nhoffset);
675  send_rc = nes_nic_send(skb, netdev);
676  if (send_rc != NETDEV_TX_OK)
677  return NETDEV_TX_OK;
678  }
679  } else {
680  send_rc = nes_nic_send(skb, netdev);
681  if (send_rc != NETDEV_TX_OK)
682  return NETDEV_TX_OK;
683  }
684 
685  barrier();
686 
687  if (wqe_count)
688  nes_write32(nesdev->regs+NES_WQE_ALLOC,
689  (wqe_count << 24) | (1 << 23) | nesvnic->nic.qp_id);
690 
691  netdev->trans_start = jiffies;
692 
693  return NETDEV_TX_OK;
694 }
695 
696 
700 static struct net_device_stats *nes_netdev_get_stats(struct net_device *netdev)
701 {
702  struct nes_vnic *nesvnic = netdev_priv(netdev);
703  struct nes_device *nesdev = nesvnic->nesdev;
704  u64 u64temp;
705  u32 u32temp;
706 
707  u32temp = nes_read_indexed(nesdev,
708  NES_IDX_ENDNODE0_NSTAT_RX_DISCARD + (nesvnic->nic_index*0x200));
709  nesvnic->netstats.rx_dropped += u32temp;
710  nesvnic->endnode_nstat_rx_discard += u32temp;
711 
712  u64temp = (u64)nes_read_indexed(nesdev,
714  u64temp += ((u64)nes_read_indexed(nesdev,
715  NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
716 
717  nesvnic->endnode_nstat_rx_octets += u64temp;
718  nesvnic->netstats.rx_bytes += u64temp;
719 
720  u64temp = (u64)nes_read_indexed(nesdev,
722  u64temp += ((u64)nes_read_indexed(nesdev,
723  NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
724 
725  nesvnic->endnode_nstat_rx_frames += u64temp;
726  nesvnic->netstats.rx_packets += u64temp;
727 
728  u64temp = (u64)nes_read_indexed(nesdev,
730  u64temp += ((u64)nes_read_indexed(nesdev,
731  NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI + (nesvnic->nic_index*0x200))) << 32;
732 
733  nesvnic->endnode_nstat_tx_octets += u64temp;
734  nesvnic->netstats.tx_bytes += u64temp;
735 
736  u64temp = (u64)nes_read_indexed(nesdev,
738  u64temp += ((u64)nes_read_indexed(nesdev,
739  NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI + (nesvnic->nic_index*0x200))) << 32;
740 
741  nesvnic->endnode_nstat_tx_frames += u64temp;
742  nesvnic->netstats.tx_packets += u64temp;
743 
744  u32temp = nes_read_indexed(nesdev,
745  NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
746  nesvnic->netstats.rx_dropped += u32temp;
747  nesvnic->nesdev->mac_rx_errors += u32temp;
748  nesvnic->nesdev->mac_rx_short_frames += u32temp;
749 
750  u32temp = nes_read_indexed(nesdev,
751  NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
752  nesvnic->netstats.rx_dropped += u32temp;
753  nesvnic->nesdev->mac_rx_errors += u32temp;
754  nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
755 
756  u32temp = nes_read_indexed(nesdev,
757  NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
758  nesvnic->netstats.rx_dropped += u32temp;
759  nesvnic->nesdev->mac_rx_errors += u32temp;
760  nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
761 
762  u32temp = nes_read_indexed(nesdev,
763  NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
764  nesvnic->netstats.rx_dropped += u32temp;
765  nesvnic->nesdev->mac_rx_errors += u32temp;
766  nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
767 
768  u32temp = nes_read_indexed(nesdev,
769  NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
770  nesvnic->netstats.rx_length_errors += u32temp;
771  nesvnic->nesdev->mac_rx_errors += u32temp;
772 
773  u32temp = nes_read_indexed(nesdev,
774  NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
775  nesvnic->nesdev->mac_rx_errors += u32temp;
776  nesvnic->nesdev->mac_rx_crc_errors += u32temp;
777  nesvnic->netstats.rx_crc_errors += u32temp;
778 
779  u32temp = nes_read_indexed(nesdev,
780  NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
781  nesvnic->nesdev->mac_tx_errors += u32temp;
782  nesvnic->netstats.tx_errors += u32temp;
783 
784  return &nesvnic->netstats;
785 }
786 
787 
791 static void nes_netdev_tx_timeout(struct net_device *netdev)
792 {
793  struct nes_vnic *nesvnic = netdev_priv(netdev);
794 
795  if (netif_msg_timer(nesvnic))
796  nes_debug(NES_DBG_NIC_TX, "%s: tx timeout\n", netdev->name);
797 }
798 
799 
803 static int nes_netdev_set_mac_address(struct net_device *netdev, void *p)
804 {
805  struct nes_vnic *nesvnic = netdev_priv(netdev);
806  struct nes_device *nesdev = nesvnic->nesdev;
807  struct sockaddr *mac_addr = p;
808  int i;
809  u32 macaddr_low;
810  u16 macaddr_high;
811 
812  if (!is_valid_ether_addr(mac_addr->sa_data))
813  return -EADDRNOTAVAIL;
814 
815  memcpy(netdev->dev_addr, mac_addr->sa_data, netdev->addr_len);
816  printk(PFX "%s: Address length = %d, Address = %pM\n",
817  __func__, netdev->addr_len, mac_addr->sa_data);
818  macaddr_high = ((u16)netdev->dev_addr[0]) << 8;
819  macaddr_high += (u16)netdev->dev_addr[1];
820  macaddr_low = ((u32)netdev->dev_addr[2]) << 24;
821  macaddr_low += ((u32)netdev->dev_addr[3]) << 16;
822  macaddr_low += ((u32)netdev->dev_addr[4]) << 8;
823  macaddr_low += (u32)netdev->dev_addr[5];
824 
825  for (i = 0; i < NES_MAX_PORT_COUNT; i++) {
826  if (nesvnic->qp_nic_index[i] == 0xf) {
827  break;
828  }
829  nes_write_indexed(nesdev,
830  NES_IDX_PERFECT_FILTER_LOW + (nesvnic->qp_nic_index[i] * 8),
831  macaddr_low);
832  nes_write_indexed(nesdev,
833  NES_IDX_PERFECT_FILTER_HIGH + (nesvnic->qp_nic_index[i] * 8),
834  (u32)macaddr_high | NES_MAC_ADDR_VALID |
835  ((((u32)nesvnic->nic_index) << 16)));
836  }
837  return 0;
838 }
839 
840 
841 static void set_allmulti(struct nes_device *nesdev, u32 nic_active_bit)
842 {
843  u32 nic_active;
844 
845  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
846  nic_active |= nic_active_bit;
847  nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
848  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
849  nic_active &= ~nic_active_bit;
850  nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
851 }
852 
853 #define get_addr(addrs, index) ((addrs) + (index) * ETH_ALEN)
854 
858 static void nes_netdev_set_multicast_list(struct net_device *netdev)
859 {
860  struct nes_vnic *nesvnic = netdev_priv(netdev);
861  struct nes_device *nesdev = nesvnic->nesdev;
862  struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
863  u32 nic_active_bit;
864  u32 nic_active;
865  u32 perfect_filter_register_address;
866  u32 macaddr_low;
867  u16 macaddr_high;
868  u8 mc_all_on = 0;
869  u8 mc_index;
870  int mc_nic_index = -1;
871  u8 pft_entries_preallocated = max(nesadapter->adapter_fcn_count *
872  nics_per_function, 4);
873  u8 max_pft_entries_avaiable = NES_PFT_SIZE - pft_entries_preallocated;
874  unsigned long flags;
875  int mc_count = netdev_mc_count(netdev);
876 
877  spin_lock_irqsave(&nesadapter->resource_lock, flags);
878  nic_active_bit = 1 << nesvnic->nic_index;
879 
880  if (netdev->flags & IFF_PROMISC) {
881  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
882  nic_active |= nic_active_bit;
883  nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
884  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
885  nic_active |= nic_active_bit;
886  nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
887  mc_all_on = 1;
888  } else if ((netdev->flags & IFF_ALLMULTI) ||
889  (nesvnic->nic_index > 3)) {
890  set_allmulti(nesdev, nic_active_bit);
891  mc_all_on = 1;
892  } else {
893  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL);
894  nic_active &= ~nic_active_bit;
895  nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL, nic_active);
896  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
897  nic_active &= ~nic_active_bit;
898  nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
899  }
900 
901  nes_debug(NES_DBG_NIC_RX, "Number of MC entries = %d, Promiscuous = %d, All Multicast = %d.\n",
902  mc_count, !!(netdev->flags & IFF_PROMISC),
903  !!(netdev->flags & IFF_ALLMULTI));
904  if (!mc_all_on) {
905  char *addrs;
906  int i;
907  struct netdev_hw_addr *ha;
908 
909  addrs = kmalloc(ETH_ALEN * mc_count, GFP_ATOMIC);
910  if (!addrs) {
911  set_allmulti(nesdev, nic_active_bit);
912  goto unlock;
913  }
914  i = 0;
915  netdev_for_each_mc_addr(ha, netdev)
916  memcpy(get_addr(addrs, i++), ha->addr, ETH_ALEN);
917 
918  perfect_filter_register_address = NES_IDX_PERFECT_FILTER_LOW +
919  pft_entries_preallocated * 0x8;
920  for (i = 0, mc_index = 0; mc_index < max_pft_entries_avaiable;
921  mc_index++) {
922  while (i < mc_count && nesvnic->mcrq_mcast_filter &&
923  ((mc_nic_index = nesvnic->mcrq_mcast_filter(nesvnic,
924  get_addr(addrs, i++))) == 0));
925  if (mc_nic_index < 0)
926  mc_nic_index = nesvnic->nic_index;
927  while (nesadapter->pft_mcast_map[mc_index] < 16 &&
928  nesadapter->pft_mcast_map[mc_index] !=
929  nesvnic->nic_index &&
930  mc_index < max_pft_entries_avaiable) {
932  "mc_index=%d skipping nic_index=%d, "
933  "used for=%d \n", mc_index,
934  nesvnic->nic_index,
935  nesadapter->pft_mcast_map[mc_index]);
936  mc_index++;
937  }
938  if (mc_index >= max_pft_entries_avaiable)
939  break;
940  if (i < mc_count) {
941  char *addr = get_addr(addrs, i++);
942 
943  nes_debug(NES_DBG_NIC_RX, "Assigning MC Address %pM to register 0x%04X nic_idx=%d\n",
944  addr,
945  perfect_filter_register_address+(mc_index * 8),
946  mc_nic_index);
947  macaddr_high = ((u16) addr[0]) << 8;
948  macaddr_high += (u16) addr[1];
949  macaddr_low = ((u32) addr[2]) << 24;
950  macaddr_low += ((u32) addr[3]) << 16;
951  macaddr_low += ((u32) addr[4]) << 8;
952  macaddr_low += (u32) addr[5];
953  nes_write_indexed(nesdev,
954  perfect_filter_register_address+(mc_index * 8),
955  macaddr_low);
956  nes_write_indexed(nesdev,
957  perfect_filter_register_address+4+(mc_index * 8),
958  (u32)macaddr_high | NES_MAC_ADDR_VALID |
959  ((((u32)(1<<mc_nic_index)) << 16)));
960  nesadapter->pft_mcast_map[mc_index] =
961  nesvnic->nic_index;
962  } else {
963  nes_debug(NES_DBG_NIC_RX, "Clearing MC Address at register 0x%04X\n",
964  perfect_filter_register_address+(mc_index * 8));
965  nes_write_indexed(nesdev,
966  perfect_filter_register_address+4+(mc_index * 8),
967  0);
968  nesadapter->pft_mcast_map[mc_index] = 255;
969  }
970  }
971  kfree(addrs);
972  /* PFT is not large enough */
973  if (i < mc_count)
974  set_allmulti(nesdev, nic_active_bit);
975  }
976 
977 unlock:
978  spin_unlock_irqrestore(&nesadapter->resource_lock, flags);
979 }
980 
981 
985 static int nes_netdev_change_mtu(struct net_device *netdev, int new_mtu)
986 {
987  struct nes_vnic *nesvnic = netdev_priv(netdev);
988  struct nes_device *nesdev = nesvnic->nesdev;
989  int ret = 0;
990  u8 jumbomode = 0;
991  u32 nic_active;
992  u32 nic_active_bit;
993  u32 uc_all_active;
994  u32 mc_all_active;
995 
996  if ((new_mtu < ETH_ZLEN) || (new_mtu > max_mtu))
997  return -EINVAL;
998 
999  netdev->mtu = new_mtu;
1000  nesvnic->max_frame_size = new_mtu + VLAN_ETH_HLEN;
1001 
1002  if (netdev->mtu > 1500) {
1003  jumbomode=1;
1004  }
1005  nes_nic_init_timer_defaults(nesdev, jumbomode);
1006 
1007  if (netif_running(netdev)) {
1008  nic_active_bit = 1 << nesvnic->nic_index;
1009  mc_all_active = nes_read_indexed(nesdev,
1010  NES_IDX_NIC_MULTICAST_ALL) & nic_active_bit;
1011  uc_all_active = nes_read_indexed(nesdev,
1012  NES_IDX_NIC_UNICAST_ALL) & nic_active_bit;
1013 
1014  nes_netdev_stop(netdev);
1015  nes_netdev_open(netdev);
1016 
1017  nic_active = nes_read_indexed(nesdev,
1019  nic_active |= mc_all_active;
1020  nes_write_indexed(nesdev, NES_IDX_NIC_MULTICAST_ALL,
1021  nic_active);
1022 
1023  nic_active = nes_read_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL);
1024  nic_active |= uc_all_active;
1025  nes_write_indexed(nesdev, NES_IDX_NIC_UNICAST_ALL, nic_active);
1026  }
1027 
1028  return ret;
1029 }
1030 
1031 
1032 static const char nes_ethtool_stringset[][ETH_GSTRING_LEN] = {
1033  "Link Change Interrupts",
1034  "Linearized SKBs",
1035  "T/GSO Requests",
1036  "Pause Frames Sent",
1037  "Pause Frames Received",
1038  "Internal Routing Errors",
1039  "SQ SW Dropped SKBs",
1040  "SQ Full",
1041  "Segmented TSO Requests",
1042  "Rx Symbol Errors",
1043  "Rx Jabber Errors",
1044  "Rx Oversized Frames",
1045  "Rx Short Frames",
1046  "Rx Length Errors",
1047  "Rx CRC Errors",
1048  "Rx Port Discard",
1049  "Endnode Rx Discards",
1050  "Endnode Rx Octets",
1051  "Endnode Rx Frames",
1052  "Endnode Tx Octets",
1053  "Endnode Tx Frames",
1054  "Tx Errors",
1055  "mh detected",
1056  "mh pauses",
1057  "Retransmission Count",
1058  "CM Connects",
1059  "CM Accepts",
1060  "Disconnects",
1061  "Connected Events",
1062  "Connect Requests",
1063  "CM Rejects",
1064  "ModifyQP Timeouts",
1065  "CreateQPs",
1066  "SW DestroyQPs",
1067  "DestroyQPs",
1068  "CM Closes",
1069  "CM Packets Sent",
1070  "CM Packets Bounced",
1071  "CM Packets Created",
1072  "CM Packets Rcvd",
1073  "CM Packets Dropped",
1074  "CM Packets Retrans",
1075  "CM Listens Created",
1076  "CM Listens Destroyed",
1077  "CM Backlog Drops",
1078  "CM Loopbacks",
1079  "CM Nodes Created",
1080  "CM Nodes Destroyed",
1081  "CM Accel Drops",
1082  "CM Resets Received",
1083  "Free 4Kpbls",
1084  "Free 256pbls",
1085  "Timer Inits",
1086  "LRO aggregated",
1087  "LRO flushed",
1088  "LRO no_desc",
1089  "PAU CreateQPs",
1090  "PAU DestroyQPs",
1091 };
1092 #define NES_ETHTOOL_STAT_COUNT ARRAY_SIZE(nes_ethtool_stringset)
1093 
1094 
1098 static int nes_netdev_get_sset_count(struct net_device *netdev, int stringset)
1099 {
1100  if (stringset == ETH_SS_STATS)
1101  return NES_ETHTOOL_STAT_COUNT;
1102  else
1103  return -EINVAL;
1104 }
1105 
1106 
1110 static void nes_netdev_get_strings(struct net_device *netdev, u32 stringset,
1111  u8 *ethtool_strings)
1112 {
1113  if (stringset == ETH_SS_STATS)
1114  memcpy(ethtool_strings,
1115  &nes_ethtool_stringset,
1116  sizeof(nes_ethtool_stringset));
1117 }
1118 
1119 
1124 static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
1125  struct ethtool_stats *target_ethtool_stats, u64 *target_stat_values)
1126 {
1127  u64 u64temp;
1128  struct nes_vnic *nesvnic = netdev_priv(netdev);
1129  struct nes_device *nesdev = nesvnic->nesdev;
1130  struct nes_adapter *nesadapter = nesdev->nesadapter;
1131  u32 nic_count;
1132  u32 u32temp;
1133  u32 index = 0;
1134 
1135  target_ethtool_stats->n_stats = NES_ETHTOOL_STAT_COUNT;
1136  target_stat_values[index] = nesvnic->nesdev->link_status_interrupts;
1137  target_stat_values[++index] = nesvnic->linearized_skbs;
1138  target_stat_values[++index] = nesvnic->tso_requests;
1139 
1140  u32temp = nes_read_indexed(nesdev,
1141  NES_IDX_MAC_TX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1142  nesvnic->nesdev->mac_pause_frames_sent += u32temp;
1143  target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_sent;
1144 
1145  u32temp = nes_read_indexed(nesdev,
1146  NES_IDX_MAC_RX_PAUSE_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1147  nesvnic->nesdev->mac_pause_frames_received += u32temp;
1148 
1149  u32temp = nes_read_indexed(nesdev,
1150  NES_IDX_PORT_RX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1151  nesvnic->nesdev->port_rx_discards += u32temp;
1152  nesvnic->netstats.rx_dropped += u32temp;
1153 
1154  u32temp = nes_read_indexed(nesdev,
1155  NES_IDX_PORT_TX_DISCARDS + (nesvnic->nesdev->mac_index*0x40));
1156  nesvnic->nesdev->port_tx_discards += u32temp;
1157  nesvnic->netstats.tx_dropped += u32temp;
1158 
1159  u32temp = nes_read_indexed(nesdev,
1160  NES_IDX_MAC_RX_SHORT_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1161  nesvnic->netstats.rx_dropped += u32temp;
1162  nesvnic->nesdev->mac_rx_errors += u32temp;
1163  nesvnic->nesdev->mac_rx_short_frames += u32temp;
1164 
1165  u32temp = nes_read_indexed(nesdev,
1166  NES_IDX_MAC_RX_OVERSIZED_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1167  nesvnic->netstats.rx_dropped += u32temp;
1168  nesvnic->nesdev->mac_rx_errors += u32temp;
1169  nesvnic->nesdev->mac_rx_oversized_frames += u32temp;
1170 
1171  u32temp = nes_read_indexed(nesdev,
1172  NES_IDX_MAC_RX_JABBER_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1173  nesvnic->netstats.rx_dropped += u32temp;
1174  nesvnic->nesdev->mac_rx_errors += u32temp;
1175  nesvnic->nesdev->mac_rx_jabber_frames += u32temp;
1176 
1177  u32temp = nes_read_indexed(nesdev,
1178  NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1179  nesvnic->netstats.rx_dropped += u32temp;
1180  nesvnic->nesdev->mac_rx_errors += u32temp;
1181  nesvnic->nesdev->mac_rx_symbol_err_frames += u32temp;
1182 
1183  u32temp = nes_read_indexed(nesdev,
1184  NES_IDX_MAC_RX_LENGTH_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1185  nesvnic->netstats.rx_length_errors += u32temp;
1186  nesvnic->nesdev->mac_rx_errors += u32temp;
1187 
1188  u32temp = nes_read_indexed(nesdev,
1189  NES_IDX_MAC_RX_CRC_ERR_FRAMES + (nesvnic->nesdev->mac_index*0x200));
1190  nesvnic->nesdev->mac_rx_errors += u32temp;
1191  nesvnic->nesdev->mac_rx_crc_errors += u32temp;
1192  nesvnic->netstats.rx_crc_errors += u32temp;
1193 
1194  u32temp = nes_read_indexed(nesdev,
1195  NES_IDX_MAC_TX_ERRORS + (nesvnic->nesdev->mac_index*0x200));
1196  nesvnic->nesdev->mac_tx_errors += u32temp;
1197  nesvnic->netstats.tx_errors += u32temp;
1198 
1199  for (nic_count = 0; nic_count < NES_MAX_PORT_COUNT; nic_count++) {
1200  if (nesvnic->qp_nic_index[nic_count] == 0xf)
1201  break;
1202 
1203  u32temp = nes_read_indexed(nesdev,
1205  (nesvnic->qp_nic_index[nic_count]*0x200));
1206  nesvnic->netstats.rx_dropped += u32temp;
1207  nesvnic->endnode_nstat_rx_discard += u32temp;
1208 
1209  u64temp = (u64)nes_read_indexed(nesdev,
1211  (nesvnic->qp_nic_index[nic_count]*0x200));
1212  u64temp += ((u64)nes_read_indexed(nesdev,
1214  (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1215 
1216  nesvnic->endnode_nstat_rx_octets += u64temp;
1217  nesvnic->netstats.rx_bytes += u64temp;
1218 
1219  u64temp = (u64)nes_read_indexed(nesdev,
1221  (nesvnic->qp_nic_index[nic_count]*0x200));
1222  u64temp += ((u64)nes_read_indexed(nesdev,
1224  (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1225 
1226  nesvnic->endnode_nstat_rx_frames += u64temp;
1227  nesvnic->netstats.rx_packets += u64temp;
1228 
1229  u64temp = (u64)nes_read_indexed(nesdev,
1231  (nesvnic->qp_nic_index[nic_count]*0x200));
1232  u64temp += ((u64)nes_read_indexed(nesdev,
1234  (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1235 
1236  nesvnic->endnode_nstat_tx_octets += u64temp;
1237  nesvnic->netstats.tx_bytes += u64temp;
1238 
1239  u64temp = (u64)nes_read_indexed(nesdev,
1241  (nesvnic->qp_nic_index[nic_count]*0x200));
1242  u64temp += ((u64)nes_read_indexed(nesdev,
1244  (nesvnic->qp_nic_index[nic_count]*0x200))) << 32;
1245 
1246  nesvnic->endnode_nstat_tx_frames += u64temp;
1247  nesvnic->netstats.tx_packets += u64temp;
1248 
1249  u32temp = nes_read_indexed(nesdev,
1250  NES_IDX_IPV4_TCP_REXMITS + (nesvnic->qp_nic_index[nic_count]*0x200));
1251  nesvnic->endnode_ipv4_tcp_retransmits += u32temp;
1252  }
1253 
1254  target_stat_values[++index] = nesvnic->nesdev->mac_pause_frames_received;
1255  target_stat_values[++index] = nesdev->nesadapter->nic_rx_eth_route_err;
1256  target_stat_values[++index] = nesvnic->tx_sw_dropped;
1257  target_stat_values[++index] = nesvnic->sq_full;
1258  target_stat_values[++index] = nesvnic->segmented_tso_requests;
1259  target_stat_values[++index] = nesvnic->nesdev->mac_rx_symbol_err_frames;
1260  target_stat_values[++index] = nesvnic->nesdev->mac_rx_jabber_frames;
1261  target_stat_values[++index] = nesvnic->nesdev->mac_rx_oversized_frames;
1262  target_stat_values[++index] = nesvnic->nesdev->mac_rx_short_frames;
1263  target_stat_values[++index] = nesvnic->netstats.rx_length_errors;
1264  target_stat_values[++index] = nesvnic->nesdev->mac_rx_crc_errors;
1265  target_stat_values[++index] = nesvnic->nesdev->port_rx_discards;
1266  target_stat_values[++index] = nesvnic->endnode_nstat_rx_discard;
1267  target_stat_values[++index] = nesvnic->endnode_nstat_rx_octets;
1268  target_stat_values[++index] = nesvnic->endnode_nstat_rx_frames;
1269  target_stat_values[++index] = nesvnic->endnode_nstat_tx_octets;
1270  target_stat_values[++index] = nesvnic->endnode_nstat_tx_frames;
1271  target_stat_values[++index] = nesvnic->nesdev->mac_tx_errors;
1272  target_stat_values[++index] = mh_detected;
1273  target_stat_values[++index] = mh_pauses_sent;
1274  target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
1275  target_stat_values[++index] = atomic_read(&cm_connects);
1276  target_stat_values[++index] = atomic_read(&cm_accepts);
1277  target_stat_values[++index] = atomic_read(&cm_disconnects);
1278  target_stat_values[++index] = atomic_read(&cm_connecteds);
1279  target_stat_values[++index] = atomic_read(&cm_connect_reqs);
1280  target_stat_values[++index] = atomic_read(&cm_rejects);
1281  target_stat_values[++index] = atomic_read(&mod_qp_timouts);
1282  target_stat_values[++index] = atomic_read(&qps_created);
1283  target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
1284  target_stat_values[++index] = atomic_read(&qps_destroyed);
1285  target_stat_values[++index] = atomic_read(&cm_closes);
1286  target_stat_values[++index] = cm_packets_sent;
1287  target_stat_values[++index] = cm_packets_bounced;
1288  target_stat_values[++index] = cm_packets_created;
1289  target_stat_values[++index] = cm_packets_received;
1290  target_stat_values[++index] = cm_packets_dropped;
1291  target_stat_values[++index] = cm_packets_retrans;
1292  target_stat_values[++index] = atomic_read(&cm_listens_created);
1293  target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
1294  target_stat_values[++index] = cm_backlog_drops;
1295  target_stat_values[++index] = atomic_read(&cm_loopbacks);
1296  target_stat_values[++index] = atomic_read(&cm_nodes_created);
1297  target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
1298  target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
1299  target_stat_values[++index] = atomic_read(&cm_resets_recvd);
1300  target_stat_values[++index] = nesadapter->free_4kpbl;
1301  target_stat_values[++index] = nesadapter->free_256pbl;
1302  target_stat_values[++index] = int_mod_timer_init;
1303  target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
1304  target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
1305  target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
1306  target_stat_values[++index] = atomic_read(&pau_qps_created);
1307  target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
1308 }
1309 
1313 static void nes_netdev_get_drvinfo(struct net_device *netdev,
1314  struct ethtool_drvinfo *drvinfo)
1315 {
1316  struct nes_vnic *nesvnic = netdev_priv(netdev);
1317  struct nes_adapter *nesadapter = nesvnic->nesdev->nesadapter;
1318 
1319  strcpy(drvinfo->driver, DRV_NAME);
1320  strcpy(drvinfo->bus_info, pci_name(nesvnic->nesdev->pcidev));
1321  sprintf(drvinfo->fw_version, "%u.%u", nesadapter->firmware_version>>16,
1322  nesadapter->firmware_version & 0x000000ff);
1323  strcpy(drvinfo->version, DRV_VERSION);
1324  drvinfo->testinfo_len = 0;
1325  drvinfo->eedump_len = 0;
1326  drvinfo->regdump_len = 0;
1327 }
1328 
1329 
1333 static int nes_netdev_set_coalesce(struct net_device *netdev,
1334  struct ethtool_coalesce *et_coalesce)
1335 {
1336  struct nes_vnic *nesvnic = netdev_priv(netdev);
1337  struct nes_device *nesdev = nesvnic->nesdev;
1338  struct nes_adapter *nesadapter = nesdev->nesadapter;
1339  struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1340  unsigned long flags;
1341 
1342  spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1343  if (et_coalesce->rx_max_coalesced_frames_low) {
1344  shared_timer->threshold_low = et_coalesce->rx_max_coalesced_frames_low;
1345  }
1346  if (et_coalesce->rx_max_coalesced_frames_irq) {
1347  shared_timer->threshold_target = et_coalesce->rx_max_coalesced_frames_irq;
1348  }
1349  if (et_coalesce->rx_max_coalesced_frames_high) {
1350  shared_timer->threshold_high = et_coalesce->rx_max_coalesced_frames_high;
1351  }
1352  if (et_coalesce->rx_coalesce_usecs_low) {
1353  shared_timer->timer_in_use_min = et_coalesce->rx_coalesce_usecs_low;
1354  }
1355  if (et_coalesce->rx_coalesce_usecs_high) {
1356  shared_timer->timer_in_use_max = et_coalesce->rx_coalesce_usecs_high;
1357  }
1358  spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1359 
1360  /* using this to drive total interrupt moderation */
1361  nesadapter->et_rx_coalesce_usecs_irq = et_coalesce->rx_coalesce_usecs_irq;
1362  if (et_coalesce->use_adaptive_rx_coalesce) {
1363  nesadapter->et_use_adaptive_rx_coalesce = 1;
1365  nesadapter->et_rx_coalesce_usecs_irq = 0;
1366  if (et_coalesce->pkt_rate_low) {
1367  nesadapter->et_pkt_rate_low = et_coalesce->pkt_rate_low;
1368  }
1369  } else {
1370  nesadapter->et_use_adaptive_rx_coalesce = 0;
1371  nesadapter->timer_int_limit = NES_TIMER_INT_LIMIT;
1372  if (nesadapter->et_rx_coalesce_usecs_irq) {
1373  nes_write32(nesdev->regs+NES_PERIODIC_CONTROL,
1374  0x80000000 | ((u32)(nesadapter->et_rx_coalesce_usecs_irq*8)));
1375  }
1376  }
1377  return 0;
1378 }
1379 
1380 
1384 static int nes_netdev_get_coalesce(struct net_device *netdev,
1385  struct ethtool_coalesce *et_coalesce)
1386 {
1387  struct nes_vnic *nesvnic = netdev_priv(netdev);
1388  struct nes_device *nesdev = nesvnic->nesdev;
1389  struct nes_adapter *nesadapter = nesdev->nesadapter;
1390  struct ethtool_coalesce temp_et_coalesce;
1391  struct nes_hw_tune_timer *shared_timer = &nesadapter->tune_timer;
1392  unsigned long flags;
1393 
1394  memset(&temp_et_coalesce, 0, sizeof(temp_et_coalesce));
1395  temp_et_coalesce.rx_coalesce_usecs_irq = nesadapter->et_rx_coalesce_usecs_irq;
1396  temp_et_coalesce.use_adaptive_rx_coalesce = nesadapter->et_use_adaptive_rx_coalesce;
1397  temp_et_coalesce.rate_sample_interval = nesadapter->et_rate_sample_interval;
1398  temp_et_coalesce.pkt_rate_low = nesadapter->et_pkt_rate_low;
1399  spin_lock_irqsave(&nesadapter->periodic_timer_lock, flags);
1400  temp_et_coalesce.rx_max_coalesced_frames_low = shared_timer->threshold_low;
1401  temp_et_coalesce.rx_max_coalesced_frames_irq = shared_timer->threshold_target;
1402  temp_et_coalesce.rx_max_coalesced_frames_high = shared_timer->threshold_high;
1403  temp_et_coalesce.rx_coalesce_usecs_low = shared_timer->timer_in_use_min;
1404  temp_et_coalesce.rx_coalesce_usecs_high = shared_timer->timer_in_use_max;
1405  if (nesadapter->et_use_adaptive_rx_coalesce) {
1406  temp_et_coalesce.rx_coalesce_usecs_irq = shared_timer->timer_in_use;
1407  }
1408  spin_unlock_irqrestore(&nesadapter->periodic_timer_lock, flags);
1409  memcpy(et_coalesce, &temp_et_coalesce, sizeof(*et_coalesce));
1410  return 0;
1411 }
1412 
1413 
1417 static void nes_netdev_get_pauseparam(struct net_device *netdev,
1418  struct ethtool_pauseparam *et_pauseparam)
1419 {
1420  struct nes_vnic *nesvnic = netdev_priv(netdev);
1421 
1422  et_pauseparam->autoneg = 0;
1423  et_pauseparam->rx_pause = (nesvnic->nesdev->disable_rx_flow_control == 0) ? 1:0;
1424  et_pauseparam->tx_pause = (nesvnic->nesdev->disable_tx_flow_control == 0) ? 1:0;
1425 }
1426 
1427 
1431 static int nes_netdev_set_pauseparam(struct net_device *netdev,
1432  struct ethtool_pauseparam *et_pauseparam)
1433 {
1434  struct nes_vnic *nesvnic = netdev_priv(netdev);
1435  struct nes_device *nesdev = nesvnic->nesdev;
1436  u32 u32temp;
1437 
1438  if (et_pauseparam->autoneg) {
1439  /* TODO: should return unsupported */
1440  return 0;
1441  }
1442  if ((et_pauseparam->tx_pause == 1) && (nesdev->disable_tx_flow_control == 1)) {
1443  u32temp = nes_read_indexed(nesdev,
1444  NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
1446  nes_write_indexed(nesdev,
1447  NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
1448  nesdev->disable_tx_flow_control = 0;
1449  } else if ((et_pauseparam->tx_pause == 0) && (nesdev->disable_tx_flow_control == 0)) {
1450  u32temp = nes_read_indexed(nesdev,
1451  NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200));
1453  nes_write_indexed(nesdev,
1454  NES_IDX_MAC_TX_CONFIG + (nesdev->mac_index*0x200), u32temp);
1455  nesdev->disable_tx_flow_control = 1;
1456  }
1457  if ((et_pauseparam->rx_pause == 1) && (nesdev->disable_rx_flow_control == 1)) {
1458  u32temp = nes_read_indexed(nesdev,
1459  NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
1461  nes_write_indexed(nesdev,
1462  NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
1463  nesdev->disable_rx_flow_control = 0;
1464  } else if ((et_pauseparam->rx_pause == 0) && (nesdev->disable_rx_flow_control == 0)) {
1465  u32temp = nes_read_indexed(nesdev,
1466  NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40));
1468  nes_write_indexed(nesdev,
1469  NES_IDX_MPP_DEBUG + (nesdev->mac_index*0x40), u32temp);
1470  nesdev->disable_rx_flow_control = 1;
1471  }
1472 
1473  return 0;
1474 }
1475 
1476 
1480 static int nes_netdev_get_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1481 {
1482  struct nes_vnic *nesvnic = netdev_priv(netdev);
1483  struct nes_device *nesdev = nesvnic->nesdev;
1484  struct nes_adapter *nesadapter = nesdev->nesadapter;
1485  u32 mac_index = nesdev->mac_index;
1486  u8 phy_type = nesadapter->phy_type[mac_index];
1487  u8 phy_index = nesadapter->phy_index[mac_index];
1488  u16 phy_data;
1489 
1490  et_cmd->duplex = DUPLEX_FULL;
1491  et_cmd->port = PORT_MII;
1492  et_cmd->maxtxpkt = 511;
1493  et_cmd->maxrxpkt = 511;
1494 
1495  if (nesadapter->OneG_Mode) {
1496  ethtool_cmd_speed_set(et_cmd, SPEED_1000);
1497  if (phy_type == NES_PHY_TYPE_PUMA_1G) {
1500  et_cmd->autoneg = AUTONEG_DISABLE;
1501  et_cmd->transceiver = XCVR_INTERNAL;
1502  et_cmd->phy_address = mac_index;
1503  } else {
1504  unsigned long flags;
1509  spin_lock_irqsave(&nesadapter->phy_lock, flags);
1510  nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
1511  spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1512  if (phy_data & 0x1000)
1513  et_cmd->autoneg = AUTONEG_ENABLE;
1514  else
1515  et_cmd->autoneg = AUTONEG_DISABLE;
1516  et_cmd->transceiver = XCVR_EXTERNAL;
1517  et_cmd->phy_address = phy_index;
1518  }
1519  return 0;
1520  }
1521  if ((phy_type == NES_PHY_TYPE_ARGUS) ||
1522  (phy_type == NES_PHY_TYPE_SFP_D) ||
1523  (phy_type == NES_PHY_TYPE_KR)) {
1524  et_cmd->transceiver = XCVR_EXTERNAL;
1525  et_cmd->port = PORT_FIBRE;
1526  et_cmd->supported = SUPPORTED_FIBRE;
1527  et_cmd->advertising = ADVERTISED_FIBRE;
1528  et_cmd->phy_address = phy_index;
1529  } else {
1530  et_cmd->transceiver = XCVR_INTERNAL;
1533  et_cmd->phy_address = mac_index;
1534  }
1535  ethtool_cmd_speed_set(et_cmd, SPEED_10000);
1536  et_cmd->autoneg = AUTONEG_DISABLE;
1537  return 0;
1538 }
1539 
1540 
1544 static int nes_netdev_set_settings(struct net_device *netdev, struct ethtool_cmd *et_cmd)
1545 {
1546  struct nes_vnic *nesvnic = netdev_priv(netdev);
1547  struct nes_device *nesdev = nesvnic->nesdev;
1548  struct nes_adapter *nesadapter = nesdev->nesadapter;
1549 
1550  if ((nesadapter->OneG_Mode) &&
1551  (nesadapter->phy_type[nesdev->mac_index] != NES_PHY_TYPE_PUMA_1G)) {
1552  unsigned long flags;
1553  u16 phy_data;
1554  u8 phy_index = nesadapter->phy_index[nesdev->mac_index];
1555 
1556  spin_lock_irqsave(&nesadapter->phy_lock, flags);
1557  nes_read_1G_phy_reg(nesdev, 0, phy_index, &phy_data);
1558  if (et_cmd->autoneg) {
1559  /* Turn on Full duplex, Autoneg, and restart autonegotiation */
1560  phy_data |= 0x1300;
1561  } else {
1562  /* Turn off autoneg */
1563  phy_data &= ~0x1000;
1564  }
1565  nes_write_1G_phy_reg(nesdev, 0, phy_index, phy_data);
1566  spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1567  }
1568 
1569  return 0;
1570 }
1571 
1572 
1573 static const struct ethtool_ops nes_ethtool_ops = {
1574  .get_link = ethtool_op_get_link,
1575  .get_settings = nes_netdev_get_settings,
1576  .set_settings = nes_netdev_set_settings,
1577  .get_strings = nes_netdev_get_strings,
1578  .get_sset_count = nes_netdev_get_sset_count,
1579  .get_ethtool_stats = nes_netdev_get_ethtool_stats,
1580  .get_drvinfo = nes_netdev_get_drvinfo,
1581  .get_coalesce = nes_netdev_get_coalesce,
1582  .set_coalesce = nes_netdev_set_coalesce,
1583  .get_pauseparam = nes_netdev_get_pauseparam,
1584  .set_pauseparam = nes_netdev_set_pauseparam,
1585 };
1586 
1587 static void nes_vlan_mode(struct net_device *netdev, struct nes_device *nesdev, netdev_features_t features)
1588 {
1589  struct nes_adapter *nesadapter = nesdev->nesadapter;
1590  u32 u32temp;
1591  unsigned long flags;
1592 
1593  spin_lock_irqsave(&nesadapter->phy_lock, flags);
1594 
1595  nes_debug(NES_DBG_NETDEV, "%s: %s\n", __func__, netdev->name);
1596 
1597  /* Enable/Disable VLAN Stripping */
1598  u32temp = nes_read_indexed(nesdev, NES_IDX_PCIX_DIAG);
1599  if (features & NETIF_F_HW_VLAN_RX)
1600  u32temp &= 0xfdffffff;
1601  else
1602  u32temp |= 0x02000000;
1603 
1604  nes_write_indexed(nesdev, NES_IDX_PCIX_DIAG, u32temp);
1605  spin_unlock_irqrestore(&nesadapter->phy_lock, flags);
1606 }
1607 
1608 static netdev_features_t nes_fix_features(struct net_device *netdev, netdev_features_t features)
1609 {
1610  /*
1611  * Since there is no support for separate rx/tx vlan accel
1612  * enable/disable make sure tx flag is always in same state as rx.
1613  */
1614  if (features & NETIF_F_HW_VLAN_RX)
1615  features |= NETIF_F_HW_VLAN_TX;
1616  else
1617  features &= ~NETIF_F_HW_VLAN_TX;
1618 
1619  return features;
1620 }
1621 
1622 static int nes_set_features(struct net_device *netdev, netdev_features_t features)
1623 {
1624  struct nes_vnic *nesvnic = netdev_priv(netdev);
1625  struct nes_device *nesdev = nesvnic->nesdev;
1626  u32 changed = netdev->features ^ features;
1627 
1628  if (changed & NETIF_F_HW_VLAN_RX)
1629  nes_vlan_mode(netdev, nesdev, features);
1630 
1631  return 0;
1632 }
1633 
1634 static const struct net_device_ops nes_netdev_ops = {
1635  .ndo_open = nes_netdev_open,
1636  .ndo_stop = nes_netdev_stop,
1637  .ndo_start_xmit = nes_netdev_start_xmit,
1638  .ndo_get_stats = nes_netdev_get_stats,
1639  .ndo_tx_timeout = nes_netdev_tx_timeout,
1640  .ndo_set_mac_address = nes_netdev_set_mac_address,
1641  .ndo_set_rx_mode = nes_netdev_set_multicast_list,
1642  .ndo_change_mtu = nes_netdev_change_mtu,
1643  .ndo_validate_addr = eth_validate_addr,
1644  .ndo_fix_features = nes_fix_features,
1645  .ndo_set_features = nes_set_features,
1646 };
1647 
1651 struct net_device *nes_netdev_init(struct nes_device *nesdev,
1652  void __iomem *mmio_addr)
1653 {
1654  u64 u64temp;
1655  struct nes_vnic *nesvnic;
1656  struct net_device *netdev;
1657  struct nic_qp_map *curr_qp_map;
1658  u8 phy_type = nesdev->nesadapter->phy_type[nesdev->mac_index];
1659 
1660  netdev = alloc_etherdev(sizeof(struct nes_vnic));
1661  if (!netdev) {
1662  printk(KERN_ERR PFX "nesvnic etherdev alloc failed");
1663  return NULL;
1664  }
1665  nesvnic = netdev_priv(netdev);
1666 
1667  nes_debug(NES_DBG_INIT, "netdev = %p, %s\n", netdev, netdev->name);
1668 
1669  SET_NETDEV_DEV(netdev, &nesdev->pcidev->dev);
1670 
1671  netdev->watchdog_timeo = NES_TX_TIMEOUT;
1672  netdev->irq = nesdev->pcidev->irq;
1673  netdev->mtu = ETH_DATA_LEN;
1674  netdev->hard_header_len = ETH_HLEN;
1675  netdev->addr_len = ETH_ALEN;
1676  netdev->type = ARPHRD_ETHER;
1677  netdev->netdev_ops = &nes_netdev_ops;
1678  netdev->ethtool_ops = &nes_ethtool_ops;
1679  netif_napi_add(netdev, &nesvnic->napi, nes_netdev_poll, 128);
1680  nes_debug(NES_DBG_INIT, "Enabling VLAN Insert/Delete.\n");
1681 
1682  /* Fill in the port structure */
1683  nesvnic->netdev = netdev;
1684  nesvnic->nesdev = nesdev;
1685  nesvnic->msg_enable = netif_msg_init(debug, default_msg);
1686  nesvnic->netdev_index = nesdev->netdev_count;
1687  nesvnic->perfect_filter_index = nesdev->nesadapter->netdev_count;
1688  nesvnic->max_frame_size = netdev->mtu + netdev->hard_header_len + VLAN_HLEN;
1689 
1690  curr_qp_map = nic_qp_mapping_per_function[PCI_FUNC(nesdev->pcidev->devfn)];
1691  nesvnic->nic.qp_id = curr_qp_map[nesdev->netdev_count].qpid;
1692  nesvnic->nic_index = curr_qp_map[nesdev->netdev_count].nic_index;
1693  nesvnic->logical_port = curr_qp_map[nesdev->netdev_count].logical_port;
1694 
1695  /* Setup the burned in MAC address */
1696  u64temp = (u64)nesdev->nesadapter->mac_addr_low;
1697  u64temp += ((u64)nesdev->nesadapter->mac_addr_high) << 32;
1698  u64temp += nesvnic->nic_index;
1699  netdev->dev_addr[0] = (u8)(u64temp>>40);
1700  netdev->dev_addr[1] = (u8)(u64temp>>32);
1701  netdev->dev_addr[2] = (u8)(u64temp>>24);
1702  netdev->dev_addr[3] = (u8)(u64temp>>16);
1703  netdev->dev_addr[4] = (u8)(u64temp>>8);
1704  netdev->dev_addr[5] = (u8)u64temp;
1705  memcpy(netdev->perm_addr, netdev->dev_addr, 6);
1706 
1708  if ((nesvnic->logical_port < 2) || (nesdev->nesadapter->hw_rev != NE020_REV))
1709  netdev->hw_features |= NETIF_F_TSO;
1710 
1712  netdev->hw_features |= NETIF_F_LRO;
1713 
1714  nes_debug(NES_DBG_INIT, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
1715  " nic_index = %d, logical_port = %d, mac_index = %d.\n",
1716  nesvnic, (unsigned long)netdev->features, nesvnic->nic.qp_id,
1717  nesvnic->nic_index, nesvnic->logical_port, nesdev->mac_index);
1718 
1719  if (nesvnic->nesdev->nesadapter->port_count == 1 &&
1720  nesvnic->nesdev->nesadapter->adapter_fcn_count == 1) {
1721 
1722  nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1723  nesvnic->qp_nic_index[1] = nesvnic->nic_index + 1;
1725  nesvnic->qp_nic_index[2] = 0xf;
1726  nesvnic->qp_nic_index[3] = 0xf;
1727  } else {
1728  nesvnic->qp_nic_index[2] = nesvnic->nic_index + 2;
1729  nesvnic->qp_nic_index[3] = nesvnic->nic_index + 3;
1730  }
1731  } else {
1732  if (nesvnic->nesdev->nesadapter->port_count == 2 ||
1733  (nesvnic->nesdev->nesadapter->port_count == 1 &&
1734  nesvnic->nesdev->nesadapter->adapter_fcn_count == 2)) {
1735  nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1736  nesvnic->qp_nic_index[1] = nesvnic->nic_index
1737  + 2;
1738  nesvnic->qp_nic_index[2] = 0xf;
1739  nesvnic->qp_nic_index[3] = 0xf;
1740  } else {
1741  nesvnic->qp_nic_index[0] = nesvnic->nic_index;
1742  nesvnic->qp_nic_index[1] = 0xf;
1743  nesvnic->qp_nic_index[2] = 0xf;
1744  nesvnic->qp_nic_index[3] = 0xf;
1745  }
1746  }
1747  nesvnic->next_qp_nic_index = 0;
1748 
1749  if (nesdev->netdev_count == 0) {
1750  nesvnic->rdma_enabled = 1;
1751  } else {
1752  nesvnic->rdma_enabled = 0;
1753  }
1754  nesvnic->nic_cq.cq_number = nesvnic->nic.qp_id;
1755  init_timer(&nesvnic->event_timer);
1756  nesvnic->event_timer.function = NULL;
1757  spin_lock_init(&nesvnic->tx_lock);
1758  spin_lock_init(&nesvnic->port_ibevent_lock);
1759  nesdev->netdev[nesdev->netdev_count] = netdev;
1760 
1761  nes_debug(NES_DBG_INIT, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
1762  nesvnic, nesdev->mac_index);
1763  list_add_tail(&nesvnic->list, &nesdev->nesadapter->nesvnic_list[nesdev->mac_index]);
1764 
1765  if ((nesdev->netdev_count == 0) &&
1766  ((PCI_FUNC(nesdev->pcidev->devfn) == nesdev->mac_index) ||
1767  ((phy_type == NES_PHY_TYPE_PUMA_1G) &&
1768  (((PCI_FUNC(nesdev->pcidev->devfn) == 1) && (nesdev->mac_index == 2)) ||
1769  ((PCI_FUNC(nesdev->pcidev->devfn) == 2) && (nesdev->mac_index == 1)))))) {
1770  u32 u32temp;
1771  u32 link_mask = 0;
1772  u32 link_val = 0;
1773  u16 temp_phy_data;
1774  u16 phy_data = 0;
1775  unsigned long flags;
1776 
1777  u32temp = nes_read_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1778  (0x200 * (nesdev->mac_index & 1)));
1779  if (phy_type != NES_PHY_TYPE_PUMA_1G) {
1780  u32temp |= 0x00200000;
1781  nes_write_indexed(nesdev, NES_IDX_PHY_PCS_CONTROL_STATUS0 +
1782  (0x200 * (nesdev->mac_index & 1)), u32temp);
1783  }
1784 
1785  /* Check and set linkup here. This is for back to back */
1786  /* configuration where second port won't get link interrupt */
1787  switch (phy_type) {
1788  case NES_PHY_TYPE_PUMA_1G:
1789  if (nesdev->mac_index < 2) {
1790  link_mask = 0x01010000;
1791  link_val = 0x01010000;
1792  } else {
1793  link_mask = 0x02020000;
1794  link_val = 0x02020000;
1795  }
1796  break;
1797  case NES_PHY_TYPE_SFP_D:
1798  spin_lock_irqsave(&nesdev->nesadapter->phy_lock, flags);
1799  nes_read_10G_phy_reg(nesdev,
1800  nesdev->nesadapter->phy_index[nesdev->mac_index],
1801  1, 0x9003);
1802  temp_phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1803  nes_read_10G_phy_reg(nesdev,
1804  nesdev->nesadapter->phy_index[nesdev->mac_index],
1805  3, 0x0021);
1806  nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1807  nes_read_10G_phy_reg(nesdev,
1808  nesdev->nesadapter->phy_index[nesdev->mac_index],
1809  3, 0x0021);
1810  phy_data = (u16)nes_read_indexed(nesdev, NES_IDX_MAC_MDIO_CONTROL);
1811  spin_unlock_irqrestore(&nesdev->nesadapter->phy_lock, flags);
1812  phy_data = (!temp_phy_data && (phy_data == 0x8000)) ? 0x4 : 0x0;
1813  break;
1814  default:
1815  link_mask = 0x0f1f0000;
1816  link_val = 0x0f0f0000;
1817  break;
1818  }
1819 
1820  u32temp = nes_read_indexed(nesdev,
1822  (0x200 * (nesdev->mac_index & 1)));
1823 
1824  if (phy_type == NES_PHY_TYPE_SFP_D) {
1825  if (phy_data & 0x0004)
1826  nesvnic->linkup = 1;
1827  } else {
1828  if ((u32temp & link_mask) == link_val)
1829  nesvnic->linkup = 1;
1830  }
1831 
1832  /* clear the MAC interrupt status, assumes direct logical to physical mapping */
1833  u32temp = nes_read_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index));
1834  nes_debug(NES_DBG_INIT, "Phy interrupt status = 0x%X.\n", u32temp);
1835  nes_write_indexed(nesdev, NES_IDX_MAC_INT_STATUS + (0x200 * nesdev->mac_index), u32temp);
1836 
1837  nes_init_phy(nesdev);
1838  }
1839 
1840  nes_vlan_mode(netdev, nesdev, netdev->features);
1841 
1842  return netdev;
1843 }
1844 
1845 
1849 void nes_netdev_destroy(struct net_device *netdev)
1850 {
1851  struct nes_vnic *nesvnic = netdev_priv(netdev);
1852 
1853  /* make sure 'stop' method is called by Linux stack */
1854  /* nes_netdev_stop(netdev); */
1855 
1856  list_del(&nesvnic->list);
1857 
1858  if (nesvnic->of_device_registered) {
1859  nes_destroy_ofa_device(nesvnic->nesibdev);
1860  }
1861 
1862  free_netdev(netdev);
1863 }
1864 
1865 
1869 int nes_nic_cm_xmit(struct sk_buff *skb, struct net_device *netdev)
1870 {
1871  int ret;
1872 
1873  skb->dev = netdev;
1874  ret = dev_queue_xmit(skb);
1875  if (ret) {
1876  nes_debug(NES_DBG_CM, "Bad return code from dev_queue_xmit %d\n", ret);
1877  }
1878 
1879  return ret;
1880 }