2 * Copyright (c) 2006 - 2011 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
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/module.h>
35 #include <linux/moduleparam.h>
36 #include <linux/netdevice.h>
37 #include <linux/etherdevice.h>
39 #include <linux/tcp.h>
40 #include <linux/if_arp.h>
41 #include <linux/if_vlan.h>
42 #include <linux/ethtool.h>
43 #include <linux/slab.h>
46 #include <net/inet_common.h>
47 #include <linux/inet.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;
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) {
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
);
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
135 static int nes_netdev_open(struct net_device
*netdev
)
139 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
140 struct nes_device
*nesdev
= nesvnic
->nesdev
;
143 struct nes_vnic
*first_nesvnic
= NULL
;
146 struct list_head
*list_pos
, *list_temp
;
149 assert(nesdev
!= NULL
);
151 if (nesvnic
->netdev_open
== 1)
154 if (netif_msg_ifup(nesvnic
))
155 printk(KERN_INFO PFX
"%s: enabling interface\n", netdev
->name
);
157 ret
= nes_init_nic_qp(nesdev
, netdev
);
162 netif_carrier_off(netdev
);
163 netif_stop_queue(netdev
);
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
);
170 nesvnic
->nesibdev
->nesvnic
= nesvnic
;
171 ret
= nes_register_ofa_device(nesvnic
->nesibdev
);
173 printk(KERN_ERR PFX
"%s: Unable to register RDMA device, ret = %d\n",
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
);
190 macaddr_high
= ((u16
)netdev
->dev_addr
[0]) << 8;
191 macaddr_high
+= (u16
)netdev
->dev_addr
[1];
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];
198 /* Program the various MAC regs */
199 for (i
= 0; i
< NES_MAX_PORT_COUNT
; i
++) {
200 if (nesvnic
->qp_nic_index
[i
] == 0xf) {
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
],
206 NES_IDX_PERFECT_FILTER_LOW
+
207 (nesvnic
->qp_nic_index
[i
] * 8),
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),
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)));
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)
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
),
232 ~(NES_MAC_INT_LINK_STAT_CHG
| NES_MAC_INT_XGMII_EXT
|
233 NES_MAC_INT_TX_UNDERFLOW
| NES_MAC_INT_TX_ERROR
));
234 first_nesvnic
= nesvnic
;
237 if (first_nesvnic
->linkup
) {
238 /* Enable network packets */
240 netif_start_queue(netdev
);
241 netif_carrier_on(netdev
);
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
,
248 NES_LINK_RECHECK_DELAY
);
250 spin_unlock_irqrestore(&nesdev
->nesadapter
->phy_lock
, flags
);
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
);
261 nesdev
->iw_status
= 0;
264 spin_unlock_irqrestore(&nesvnic
->port_ibevent_lock
, flags
);
266 napi_enable(&nesvnic
->napi
);
267 nesvnic
->netdev_open
= 1;
276 static int nes_netdev_stop(struct net_device
*netdev
)
278 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
279 struct nes_device
*nesdev
= nesvnic
->nesdev
;
282 struct nes_vnic
*first_nesvnic
= NULL
;
283 struct list_head
*list_pos
, *list_temp
;
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)
291 if (netif_msg_ifdown(nesvnic
))
292 printk(KERN_INFO PFX
"%s: disabling interface\n", netdev
->name
);
293 netif_carrier_off(netdev
);
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
))
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
,
310 NES_IDX_MAC_INT_MASK
+
311 (0x200*first_nesvnic
->nesdev
->mac_index
),
312 ~(NES_MAC_INT_LINK_STAT_CHG
| NES_MAC_INT_XGMII_EXT
|
313 NES_MAC_INT_TX_UNDERFLOW
| NES_MAC_INT_TX_ERROR
));
315 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_MASK
+(0x200*nesdev
->mac_index
), 0xffffffff);
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
);
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
);
344 del_timer_sync(&nesvnic
->event_timer
);
345 nesvnic
->event_timer
.function
= NULL
;
346 spin_unlock_irqrestore(&nesvnic
->port_ibevent_lock
, flags
);
348 nes_destroy_nic_qp(nesvnic
);
350 nesvnic
->netdev_open
= 0;
359 static bool nes_nic_send(struct sk_buff
*skb
, struct net_device
*netdev
)
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
;
366 __le16
*wqe_fragment_length
;
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
;
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
];
375 /* setup the VLAN tag if present */
376 if (skb_vlan_tag_present(skb
)) {
377 nes_debug(NES_DBG_NIC_TX
, "%s: VLAN packet to send... VLAN = %08X\n",
378 netdev
->name
, skb_vlan_tag_get(skb
));
379 wqe_misc
= NES_NIC_SQ_WQE_TAGVALUE_ENABLE
;
380 wqe_fragment_length
[0] = (__force __le16
) skb_vlan_tag_get(skb
);
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
;
389 if (skb
->ip_summed
== CHECKSUM_PARTIAL
) {
390 if (skb_is_gso(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
,
397 (((u32
)(((unsigned char *)tcph
) - skb
->data
)) << 4));
399 } else { /* CHECKSUM_HW */
400 wqe_misc
|= NES_NIC_SQ_WQE_DISABLE_CHKSUM
;
403 set_wqe_32bit_value(nic_sqe
->wqe_words
, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX
,
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
),
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
));
415 nesvnic
->tx_sw_dropped
++;
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
;
429 if (skb_headlen(skb
) == skb
->len
) {
430 if (skb_headlen(skb
) <= NES_FIRST_FRAG_SIZE
) {
431 nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_LENGTH_2_1_IDX
] = 0;
432 nesnic
->tx_skb
[nesnic
->sq_head
] = skb
;
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
++) {
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
),
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
),
448 wqe_fragment_index
++;
449 if (wqe_fragment_index
< 5)
450 wqe_fragment_length
[wqe_fragment_index
] = 0;
454 set_wqe_32bit_value(nic_sqe
->wqe_words
, NES_NIC_SQ_WQE_MISC_IDX
, wqe_misc
);
456 nesnic
->sq_head
&= nesnic
->sq_size
- 1;
462 * nes_netdev_start_xmit
464 static int nes_netdev_start_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
466 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
467 struct nes_device
*nesdev
= nesvnic
->nesdev
;
468 struct nes_hw_nic
*nesnic
= &nesvnic
->nic
;
469 struct nes_hw_nic_sq_wqe
*nic_sqe
;
471 /* struct udphdr *udph; */
472 #define NES_MAX_TSO_FRAGS MAX_SKB_FRAGS
473 /* 64K segment plus overflow on each side */
474 dma_addr_t tso_bus_address
[NES_MAX_TSO_FRAGS
];
475 dma_addr_t bus_address
;
482 __le16
*wqe_fragment_length
;
484 u32 original_first_length
;
485 /* u64 *wqe_fragment_address; */
486 /* first fragment (0) is used by copy buffer */
487 u16 wqe_fragment_index
=1;
495 * nes_debug(NES_DBG_NIC_TX, "%s Request to tx NIC packet length %u, headlen %u,"
496 * " (%u frags), tso_size=%u\n",
497 * netdev->name, skb->len, skb_headlen(skb),
498 * skb_shinfo(skb)->nr_frags, skb_is_gso(skb));
501 if (netif_queue_stopped(netdev
))
502 return NETDEV_TX_BUSY
;
504 /* Check if SQ is full */
505 if ((((nesnic
->sq_tail
+(nesnic
->sq_size
*2))-nesnic
->sq_head
) & (nesnic
->sq_size
- 1)) == 1) {
506 if (!netif_queue_stopped(netdev
)) {
507 netif_stop_queue(netdev
);
509 if ((((((volatile u16
)nesnic
->sq_tail
)+(nesnic
->sq_size
*2))-nesnic
->sq_head
) & (nesnic
->sq_size
- 1)) != 1) {
510 netif_start_queue(netdev
);
511 goto sq_no_longer_full
;
515 return NETDEV_TX_BUSY
;
519 nr_frags
= skb_shinfo(skb
)->nr_frags
;
520 if (skb_headlen(skb
) > NES_FIRST_FRAG_SIZE
) {
523 /* Check if too many fragments */
524 if (unlikely((nr_frags
> 4))) {
525 if (skb_is_gso(skb
)) {
526 nesvnic
->segmented_tso_requests
++;
527 nesvnic
->tso_requests
++;
528 /* Basically 4 fragments available per WQE with extended fragments */
529 wqes_needed
= nr_frags
>> 2;
530 wqes_needed
+= (nr_frags
&3)?1:0;
531 wqes_available
= (((nesnic
->sq_tail
+nesnic
->sq_size
)-nesnic
->sq_head
) - 1) &
532 (nesnic
->sq_size
- 1);
534 if (unlikely(wqes_needed
> wqes_available
)) {
535 if (!netif_queue_stopped(netdev
)) {
536 netif_stop_queue(netdev
);
538 wqes_available
= (((((volatile u16
)nesnic
->sq_tail
)+nesnic
->sq_size
)-nesnic
->sq_head
) - 1) &
539 (nesnic
->sq_size
- 1);
540 if (wqes_needed
<= wqes_available
) {
541 netif_start_queue(netdev
);
542 goto tso_sq_no_longer_full
;
546 nes_debug(NES_DBG_NIC_TX
, "%s: HNIC SQ full- TSO request has too many frags!\n",
548 return NETDEV_TX_BUSY
;
550 tso_sq_no_longer_full
:
551 /* Map all the buffers */
552 for (tso_frag_count
=0; tso_frag_count
< skb_shinfo(skb
)->nr_frags
;
555 &skb_shinfo(skb
)->frags
[tso_frag_count
];
556 tso_bus_address
[tso_frag_count
] =
557 skb_frag_dma_map(&nesdev
->pcidev
->dev
,
558 frag
, 0, skb_frag_size(frag
),
563 curr_tcp_seq
= ntohl(tcp_hdr(skb
)->seq
);
564 hoffset
= skb_transport_header(skb
) - skb
->data
;
565 nhoffset
= skb_network_header(skb
) - skb
->data
;
566 original_first_length
= hoffset
+ ((((struct tcphdr
*)skb_transport_header(skb
))->doff
)<<2);
568 for (wqe_count
=0; wqe_count
<((u32
)wqes_needed
); wqe_count
++) {
570 nic_sqe
= &nesnic
->sq_vbase
[nesnic
->sq_head
];
571 wqe_fragment_length
=
572 (__le16
*)&nic_sqe
->wqe_words
[NES_NIC_SQ_WQE_LENGTH_0_TAG_IDX
];
573 /* setup the VLAN tag if present */
574 if (skb_vlan_tag_present(skb
)) {
575 nes_debug(NES_DBG_NIC_TX
, "%s: VLAN packet to send... VLAN = %08X\n",
577 skb_vlan_tag_get(skb
));
578 wqe_misc
= NES_NIC_SQ_WQE_TAGVALUE_ENABLE
;
579 wqe_fragment_length
[0] = (__force __le16
) skb_vlan_tag_get(skb
);
583 /* bump past the vlan tag */
584 wqe_fragment_length
++;
586 /* Assumes header totally fits in allocated buffer and is in first fragment */
587 if (original_first_length
> NES_FIRST_FRAG_SIZE
) {
588 nes_debug(NES_DBG_NIC_TX
, "ERROR: SKB header too big, headlen=%u, FIRST_FRAG_SIZE=%u\n",
589 original_first_length
, NES_FIRST_FRAG_SIZE
);
590 nes_debug(NES_DBG_NIC_TX
, "%s Request to tx NIC packet length %u, headlen %u,"
591 " (%u frags), is_gso = %u tso_size=%u\n",
593 skb
->len
, skb_headlen(skb
),
594 skb_shinfo(skb
)->nr_frags
, skb_is_gso(skb
), skb_shinfo(skb
)->gso_size
);
596 memcpy(&nesnic
->first_frag_vbase
[nesnic
->sq_head
].buffer
,
597 skb
->data
, min(((unsigned int)NES_FIRST_FRAG_SIZE
),
598 original_first_length
));
599 iph
= (struct iphdr
*)
600 (&nesnic
->first_frag_vbase
[nesnic
->sq_head
].buffer
[nhoffset
]);
601 tcph
= (struct tcphdr
*)
602 (&nesnic
->first_frag_vbase
[nesnic
->sq_head
].buffer
[hoffset
]);
603 if ((wqe_count
+1)!=(u32
)wqes_needed
) {
612 tcph
->seq
= htonl(curr_tcp_seq
);
613 wqe_fragment_length
[0] = cpu_to_le16(min(((unsigned int)NES_FIRST_FRAG_SIZE
),
614 original_first_length
));
616 wqe_fragment_index
= 1;
617 if ((wqe_count
==0) && (skb_headlen(skb
) > original_first_length
)) {
618 set_bit(nesnic
->sq_head
, nesnic
->first_frag_overflow
);
619 bus_address
= pci_map_single(nesdev
->pcidev
, skb
->data
+ original_first_length
,
620 skb_headlen(skb
) - original_first_length
, PCI_DMA_TODEVICE
);
621 wqe_fragment_length
[wqe_fragment_index
++] =
622 cpu_to_le16(skb_headlen(skb
) - original_first_length
);
623 wqe_fragment_length
[wqe_fragment_index
] = 0;
624 set_wqe_64bit_value(nic_sqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG1_LOW_IDX
,
626 tso_wqe_length
+= skb_headlen(skb
) -
627 original_first_length
;
629 while (wqe_fragment_index
< 5) {
630 wqe_fragment_length
[wqe_fragment_index
] =
631 cpu_to_le16(skb_frag_size(&skb_shinfo(skb
)->frags
[tso_frag_index
]));
632 set_wqe_64bit_value(nic_sqe
->wqe_words
, NES_NIC_SQ_WQE_FRAG0_LOW_IDX
+(2*wqe_fragment_index
),
633 (u64
)tso_bus_address
[tso_frag_index
]);
634 wqe_fragment_index
++;
635 tso_wqe_length
+= skb_frag_size(&skb_shinfo(skb
)->frags
[tso_frag_index
++]);
636 if (wqe_fragment_index
< 5)
637 wqe_fragment_length
[wqe_fragment_index
] = 0;
638 if (tso_frag_index
== tso_frag_count
)
641 if ((wqe_count
+1) == (u32
)wqes_needed
) {
642 nesnic
->tx_skb
[nesnic
->sq_head
] = skb
;
644 nesnic
->tx_skb
[nesnic
->sq_head
] = NULL
;
646 wqe_misc
|= NES_NIC_SQ_WQE_COMPLETION
| (u16
)skb_shinfo(skb
)->gso_size
;
647 if ((tso_wqe_length
+ original_first_length
) > skb_shinfo(skb
)->gso_size
) {
648 wqe_misc
|= NES_NIC_SQ_WQE_LSO_ENABLE
;
650 iph
->tot_len
= htons(tso_wqe_length
+ original_first_length
- nhoffset
);
653 set_wqe_32bit_value(nic_sqe
->wqe_words
, NES_NIC_SQ_WQE_MISC_IDX
,
655 set_wqe_32bit_value(nic_sqe
->wqe_words
, NES_NIC_SQ_WQE_LSO_INFO_IDX
,
656 ((u32
)tcph
->doff
) | (((u32
)hoffset
) << 4));
658 set_wqe_32bit_value(nic_sqe
->wqe_words
, NES_NIC_SQ_WQE_TOTAL_LENGTH_IDX
,
659 tso_wqe_length
+ original_first_length
);
660 curr_tcp_seq
+= tso_wqe_length
;
662 nesnic
->sq_head
&= nesnic
->sq_size
-1;
665 hoffset
= skb_transport_header(skb
) - skb
->data
;
666 nhoffset
= skb_network_header(skb
) - skb
->data
;
667 if (skb_linearize(skb
)) {
668 nesvnic
->tx_sw_dropped
++;
672 nesvnic
->linearized_skbs
++;
673 skb_set_transport_header(skb
, hoffset
);
674 skb_set_network_header(skb
, nhoffset
);
675 if (!nes_nic_send(skb
, netdev
))
679 if (!nes_nic_send(skb
, netdev
))
686 nes_write32(nesdev
->regs
+NES_WQE_ALLOC
,
687 (wqe_count
<< 24) | (1 << 23) | nesvnic
->nic
.qp_id
);
689 netif_trans_update(netdev
);
696 * nes_netdev_get_stats
698 static struct net_device_stats
*nes_netdev_get_stats(struct net_device
*netdev
)
700 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
701 struct nes_device
*nesdev
= nesvnic
->nesdev
;
705 u32temp
= nes_read_indexed(nesdev
,
706 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD
+ (nesvnic
->nic_index
*0x200));
707 nesvnic
->netstats
.rx_dropped
+= u32temp
;
708 nesvnic
->endnode_nstat_rx_discard
+= u32temp
;
710 u64temp
= (u64
)nes_read_indexed(nesdev
,
711 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO
+ (nesvnic
->nic_index
*0x200));
712 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
713 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI
+ (nesvnic
->nic_index
*0x200))) << 32;
715 nesvnic
->endnode_nstat_rx_octets
+= u64temp
;
716 nesvnic
->netstats
.rx_bytes
+= u64temp
;
718 u64temp
= (u64
)nes_read_indexed(nesdev
,
719 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO
+ (nesvnic
->nic_index
*0x200));
720 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
721 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI
+ (nesvnic
->nic_index
*0x200))) << 32;
723 nesvnic
->endnode_nstat_rx_frames
+= u64temp
;
724 nesvnic
->netstats
.rx_packets
+= u64temp
;
726 u64temp
= (u64
)nes_read_indexed(nesdev
,
727 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO
+ (nesvnic
->nic_index
*0x200));
728 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
729 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI
+ (nesvnic
->nic_index
*0x200))) << 32;
731 nesvnic
->endnode_nstat_tx_octets
+= u64temp
;
732 nesvnic
->netstats
.tx_bytes
+= u64temp
;
734 u64temp
= (u64
)nes_read_indexed(nesdev
,
735 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO
+ (nesvnic
->nic_index
*0x200));
736 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
737 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI
+ (nesvnic
->nic_index
*0x200))) << 32;
739 nesvnic
->endnode_nstat_tx_frames
+= u64temp
;
740 nesvnic
->netstats
.tx_packets
+= u64temp
;
742 u32temp
= nes_read_indexed(nesdev
,
743 NES_IDX_MAC_RX_SHORT_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
744 nesvnic
->netstats
.rx_dropped
+= u32temp
;
745 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
746 nesvnic
->nesdev
->mac_rx_short_frames
+= u32temp
;
748 u32temp
= nes_read_indexed(nesdev
,
749 NES_IDX_MAC_RX_OVERSIZED_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
750 nesvnic
->netstats
.rx_dropped
+= u32temp
;
751 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
752 nesvnic
->nesdev
->mac_rx_oversized_frames
+= u32temp
;
754 u32temp
= nes_read_indexed(nesdev
,
755 NES_IDX_MAC_RX_JABBER_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
756 nesvnic
->netstats
.rx_dropped
+= u32temp
;
757 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
758 nesvnic
->nesdev
->mac_rx_jabber_frames
+= u32temp
;
760 u32temp
= nes_read_indexed(nesdev
,
761 NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
762 nesvnic
->netstats
.rx_dropped
+= u32temp
;
763 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
764 nesvnic
->nesdev
->mac_rx_symbol_err_frames
+= u32temp
;
766 u32temp
= nes_read_indexed(nesdev
,
767 NES_IDX_MAC_RX_LENGTH_ERR_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
768 nesvnic
->netstats
.rx_length_errors
+= u32temp
;
769 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
771 u32temp
= nes_read_indexed(nesdev
,
772 NES_IDX_MAC_RX_CRC_ERR_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
773 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
774 nesvnic
->nesdev
->mac_rx_crc_errors
+= u32temp
;
775 nesvnic
->netstats
.rx_crc_errors
+= u32temp
;
777 u32temp
= nes_read_indexed(nesdev
,
778 NES_IDX_MAC_TX_ERRORS
+ (nesvnic
->nesdev
->mac_index
*0x200));
779 nesvnic
->nesdev
->mac_tx_errors
+= u32temp
;
780 nesvnic
->netstats
.tx_errors
+= u32temp
;
782 return &nesvnic
->netstats
;
787 * nes_netdev_tx_timeout
789 static void nes_netdev_tx_timeout(struct net_device
*netdev
)
791 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
793 if (netif_msg_timer(nesvnic
))
794 nes_debug(NES_DBG_NIC_TX
, "%s: tx timeout\n", netdev
->name
);
799 * nes_netdev_set_mac_address
801 static int nes_netdev_set_mac_address(struct net_device
*netdev
, void *p
)
803 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
804 struct nes_device
*nesdev
= nesvnic
->nesdev
;
805 struct sockaddr
*mac_addr
= p
;
810 if (!is_valid_ether_addr(mac_addr
->sa_data
))
811 return -EADDRNOTAVAIL
;
813 memcpy(netdev
->dev_addr
, mac_addr
->sa_data
, netdev
->addr_len
);
814 printk(PFX
"%s: Address length = %d, Address = %pM\n",
815 __func__
, netdev
->addr_len
, mac_addr
->sa_data
);
816 macaddr_high
= ((u16
)netdev
->dev_addr
[0]) << 8;
817 macaddr_high
+= (u16
)netdev
->dev_addr
[1];
818 macaddr_low
= ((u32
)netdev
->dev_addr
[2]) << 24;
819 macaddr_low
+= ((u32
)netdev
->dev_addr
[3]) << 16;
820 macaddr_low
+= ((u32
)netdev
->dev_addr
[4]) << 8;
821 macaddr_low
+= (u32
)netdev
->dev_addr
[5];
823 for (i
= 0; i
< NES_MAX_PORT_COUNT
; i
++) {
824 if (nesvnic
->qp_nic_index
[i
] == 0xf) {
827 nes_write_indexed(nesdev
,
828 NES_IDX_PERFECT_FILTER_LOW
+ (nesvnic
->qp_nic_index
[i
] * 8),
830 nes_write_indexed(nesdev
,
831 NES_IDX_PERFECT_FILTER_HIGH
+ (nesvnic
->qp_nic_index
[i
] * 8),
832 (u32
)macaddr_high
| NES_MAC_ADDR_VALID
|
833 ((((u32
)nesvnic
->nic_index
) << 16)));
839 static void set_allmulti(struct nes_device
*nesdev
, u32 nic_active_bit
)
843 nic_active
= nes_read_indexed(nesdev
, NES_IDX_NIC_MULTICAST_ALL
);
844 nic_active
|= nic_active_bit
;
845 nes_write_indexed(nesdev
, NES_IDX_NIC_MULTICAST_ALL
, nic_active
);
846 nic_active
= nes_read_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
);
847 nic_active
&= ~nic_active_bit
;
848 nes_write_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
, nic_active
);
851 #define get_addr(addrs, index) ((addrs) + (index) * ETH_ALEN)
854 * nes_netdev_set_multicast_list
856 static void nes_netdev_set_multicast_list(struct net_device
*netdev
)
858 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
859 struct nes_device
*nesdev
= nesvnic
->nesdev
;
860 struct nes_adapter
*nesadapter
= nesvnic
->nesdev
->nesadapter
;
863 u32 perfect_filter_register_address
;
868 int mc_nic_index
= -1;
869 u8 pft_entries_preallocated
= max(nesadapter
->adapter_fcn_count
*
870 nics_per_function
, 4);
871 u8 max_pft_entries_avaiable
= NES_PFT_SIZE
- pft_entries_preallocated
;
873 int mc_count
= netdev_mc_count(netdev
);
875 spin_lock_irqsave(&nesadapter
->resource_lock
, flags
);
876 nic_active_bit
= 1 << nesvnic
->nic_index
;
878 if (netdev
->flags
& IFF_PROMISC
) {
879 nic_active
= nes_read_indexed(nesdev
, NES_IDX_NIC_MULTICAST_ALL
);
880 nic_active
|= nic_active_bit
;
881 nes_write_indexed(nesdev
, NES_IDX_NIC_MULTICAST_ALL
, nic_active
);
882 nic_active
= nes_read_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
);
883 nic_active
|= nic_active_bit
;
884 nes_write_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
, nic_active
);
886 } else if ((netdev
->flags
& IFF_ALLMULTI
) ||
887 (nesvnic
->nic_index
> 3)) {
888 set_allmulti(nesdev
, nic_active_bit
);
891 nic_active
= nes_read_indexed(nesdev
, NES_IDX_NIC_MULTICAST_ALL
);
892 nic_active
&= ~nic_active_bit
;
893 nes_write_indexed(nesdev
, NES_IDX_NIC_MULTICAST_ALL
, nic_active
);
894 nic_active
= nes_read_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
);
895 nic_active
&= ~nic_active_bit
;
896 nes_write_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
, nic_active
);
899 nes_debug(NES_DBG_NIC_RX
, "Number of MC entries = %d, Promiscuous = %d, All Multicast = %d.\n",
900 mc_count
, !!(netdev
->flags
& IFF_PROMISC
),
901 !!(netdev
->flags
& IFF_ALLMULTI
));
905 struct netdev_hw_addr
*ha
;
907 addrs
= kmalloc(ETH_ALEN
* mc_count
, GFP_ATOMIC
);
909 set_allmulti(nesdev
, nic_active_bit
);
913 netdev_for_each_mc_addr(ha
, netdev
)
914 memcpy(get_addr(addrs
, i
++), ha
->addr
, ETH_ALEN
);
916 perfect_filter_register_address
= NES_IDX_PERFECT_FILTER_LOW
+
917 pft_entries_preallocated
* 0x8;
918 for (i
= 0, mc_index
= 0; mc_index
< max_pft_entries_avaiable
;
920 while (i
< mc_count
&& nesvnic
->mcrq_mcast_filter
&&
921 ((mc_nic_index
= nesvnic
->mcrq_mcast_filter(nesvnic
,
922 get_addr(addrs
, i
++))) == 0));
923 if (mc_nic_index
< 0)
924 mc_nic_index
= nesvnic
->nic_index
;
925 while (nesadapter
->pft_mcast_map
[mc_index
] < 16 &&
926 nesadapter
->pft_mcast_map
[mc_index
] !=
927 nesvnic
->nic_index
&&
928 mc_index
< max_pft_entries_avaiable
) {
929 nes_debug(NES_DBG_NIC_RX
,
930 "mc_index=%d skipping nic_index=%d, used for=%d\n",
931 mc_index
, nesvnic
->nic_index
,
932 nesadapter
->pft_mcast_map
[mc_index
]);
935 if (mc_index
>= max_pft_entries_avaiable
)
938 char *addr
= get_addr(addrs
, i
++);
940 nes_debug(NES_DBG_NIC_RX
, "Assigning MC Address %pM to register 0x%04X nic_idx=%d\n",
942 perfect_filter_register_address
+(mc_index
* 8),
944 macaddr_high
= ((u8
) addr
[0]) << 8;
945 macaddr_high
+= (u8
) addr
[1];
946 macaddr_low
= ((u8
) addr
[2]) << 24;
947 macaddr_low
+= ((u8
) addr
[3]) << 16;
948 macaddr_low
+= ((u8
) addr
[4]) << 8;
949 macaddr_low
+= (u8
) addr
[5];
951 nes_write_indexed(nesdev
,
952 perfect_filter_register_address
+(mc_index
* 8),
954 nes_write_indexed(nesdev
,
955 perfect_filter_register_address
+4+(mc_index
* 8),
956 (u32
)macaddr_high
| NES_MAC_ADDR_VALID
|
957 ((((u32
)(1<<mc_nic_index
)) << 16)));
958 nesadapter
->pft_mcast_map
[mc_index
] =
961 nes_debug(NES_DBG_NIC_RX
, "Clearing MC Address at register 0x%04X\n",
962 perfect_filter_register_address
+(mc_index
* 8));
963 nes_write_indexed(nesdev
,
964 perfect_filter_register_address
+4+(mc_index
* 8),
966 nesadapter
->pft_mcast_map
[mc_index
] = 255;
970 /* PFT is not large enough */
972 set_allmulti(nesdev
, nic_active_bit
);
976 spin_unlock_irqrestore(&nesadapter
->resource_lock
, flags
);
981 * nes_netdev_change_mtu
983 static int nes_netdev_change_mtu(struct net_device
*netdev
, int new_mtu
)
985 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
986 struct nes_device
*nesdev
= nesvnic
->nesdev
;
993 netdev
->mtu
= new_mtu
;
994 nesvnic
->max_frame_size
= new_mtu
+ VLAN_ETH_HLEN
;
996 if (netdev
->mtu
> ETH_DATA_LEN
) {
999 nes_nic_init_timer_defaults(nesdev
, jumbomode
);
1001 if (netif_running(netdev
)) {
1002 nic_active_bit
= 1 << nesvnic
->nic_index
;
1003 mc_all_active
= nes_read_indexed(nesdev
,
1004 NES_IDX_NIC_MULTICAST_ALL
) & nic_active_bit
;
1005 uc_all_active
= nes_read_indexed(nesdev
,
1006 NES_IDX_NIC_UNICAST_ALL
) & nic_active_bit
;
1008 nes_netdev_stop(netdev
);
1009 nes_netdev_open(netdev
);
1011 nic_active
= nes_read_indexed(nesdev
,
1012 NES_IDX_NIC_MULTICAST_ALL
);
1013 nic_active
|= mc_all_active
;
1014 nes_write_indexed(nesdev
, NES_IDX_NIC_MULTICAST_ALL
,
1017 nic_active
= nes_read_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
);
1018 nic_active
|= uc_all_active
;
1019 nes_write_indexed(nesdev
, NES_IDX_NIC_UNICAST_ALL
, nic_active
);
1026 static const char nes_ethtool_stringset
[][ETH_GSTRING_LEN
] = {
1027 "Link Change Interrupts",
1030 "Pause Frames Sent",
1031 "Pause Frames Received",
1032 "Internal Routing Errors",
1033 "SQ SW Dropped SKBs",
1035 "Segmented TSO Requests",
1038 "Rx Oversized Frames",
1043 "Endnode Rx Discards",
1044 "Endnode Rx Octets",
1045 "Endnode Rx Frames",
1046 "Endnode Tx Octets",
1047 "Endnode Tx Frames",
1051 "Retransmission Count",
1058 "ModifyQP Timeouts",
1064 "CM Packets Bounced",
1065 "CM Packets Created",
1067 "CM Packets Dropped",
1068 "CM Packets Retrans",
1069 "CM Listens Created",
1070 "CM Listens Destroyed",
1074 "CM Nodes Destroyed",
1076 "CM Resets Received",
1083 #define NES_ETHTOOL_STAT_COUNT ARRAY_SIZE(nes_ethtool_stringset)
1087 * nes_netdev_get_sset_count
1089 static int nes_netdev_get_sset_count(struct net_device
*netdev
, int stringset
)
1091 if (stringset
== ETH_SS_STATS
)
1092 return NES_ETHTOOL_STAT_COUNT
;
1099 * nes_netdev_get_strings
1101 static void nes_netdev_get_strings(struct net_device
*netdev
, u32 stringset
,
1102 u8
*ethtool_strings
)
1104 if (stringset
== ETH_SS_STATS
)
1105 memcpy(ethtool_strings
,
1106 &nes_ethtool_stringset
,
1107 sizeof(nes_ethtool_stringset
));
1112 * nes_netdev_get_ethtool_stats
1115 static void nes_netdev_get_ethtool_stats(struct net_device
*netdev
,
1116 struct ethtool_stats
*target_ethtool_stats
, u64
*target_stat_values
)
1119 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1120 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1121 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1126 target_ethtool_stats
->n_stats
= NES_ETHTOOL_STAT_COUNT
;
1127 target_stat_values
[index
] = nesvnic
->nesdev
->link_status_interrupts
;
1128 target_stat_values
[++index
] = nesvnic
->linearized_skbs
;
1129 target_stat_values
[++index
] = nesvnic
->tso_requests
;
1131 u32temp
= nes_read_indexed(nesdev
,
1132 NES_IDX_MAC_TX_PAUSE_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1133 nesvnic
->nesdev
->mac_pause_frames_sent
+= u32temp
;
1134 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_pause_frames_sent
;
1136 u32temp
= nes_read_indexed(nesdev
,
1137 NES_IDX_MAC_RX_PAUSE_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1138 nesvnic
->nesdev
->mac_pause_frames_received
+= u32temp
;
1140 u32temp
= nes_read_indexed(nesdev
,
1141 NES_IDX_PORT_RX_DISCARDS
+ (nesvnic
->nesdev
->mac_index
*0x40));
1142 nesvnic
->nesdev
->port_rx_discards
+= u32temp
;
1143 nesvnic
->netstats
.rx_dropped
+= u32temp
;
1145 u32temp
= nes_read_indexed(nesdev
,
1146 NES_IDX_PORT_TX_DISCARDS
+ (nesvnic
->nesdev
->mac_index
*0x40));
1147 nesvnic
->nesdev
->port_tx_discards
+= u32temp
;
1148 nesvnic
->netstats
.tx_dropped
+= u32temp
;
1150 u32temp
= nes_read_indexed(nesdev
,
1151 NES_IDX_MAC_RX_SHORT_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1152 nesvnic
->netstats
.rx_dropped
+= u32temp
;
1153 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
1154 nesvnic
->nesdev
->mac_rx_short_frames
+= u32temp
;
1156 u32temp
= nes_read_indexed(nesdev
,
1157 NES_IDX_MAC_RX_OVERSIZED_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1158 nesvnic
->netstats
.rx_dropped
+= u32temp
;
1159 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
1160 nesvnic
->nesdev
->mac_rx_oversized_frames
+= u32temp
;
1162 u32temp
= nes_read_indexed(nesdev
,
1163 NES_IDX_MAC_RX_JABBER_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1164 nesvnic
->netstats
.rx_dropped
+= u32temp
;
1165 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
1166 nesvnic
->nesdev
->mac_rx_jabber_frames
+= u32temp
;
1168 u32temp
= nes_read_indexed(nesdev
,
1169 NES_IDX_MAC_RX_SYMBOL_ERR_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1170 nesvnic
->netstats
.rx_dropped
+= u32temp
;
1171 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
1172 nesvnic
->nesdev
->mac_rx_symbol_err_frames
+= u32temp
;
1174 u32temp
= nes_read_indexed(nesdev
,
1175 NES_IDX_MAC_RX_LENGTH_ERR_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1176 nesvnic
->netstats
.rx_length_errors
+= u32temp
;
1177 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
1179 u32temp
= nes_read_indexed(nesdev
,
1180 NES_IDX_MAC_RX_CRC_ERR_FRAMES
+ (nesvnic
->nesdev
->mac_index
*0x200));
1181 nesvnic
->nesdev
->mac_rx_errors
+= u32temp
;
1182 nesvnic
->nesdev
->mac_rx_crc_errors
+= u32temp
;
1183 nesvnic
->netstats
.rx_crc_errors
+= u32temp
;
1185 u32temp
= nes_read_indexed(nesdev
,
1186 NES_IDX_MAC_TX_ERRORS
+ (nesvnic
->nesdev
->mac_index
*0x200));
1187 nesvnic
->nesdev
->mac_tx_errors
+= u32temp
;
1188 nesvnic
->netstats
.tx_errors
+= u32temp
;
1190 for (nic_count
= 0; nic_count
< NES_MAX_PORT_COUNT
; nic_count
++) {
1191 if (nesvnic
->qp_nic_index
[nic_count
] == 0xf)
1194 u32temp
= nes_read_indexed(nesdev
,
1195 NES_IDX_ENDNODE0_NSTAT_RX_DISCARD
+
1196 (nesvnic
->qp_nic_index
[nic_count
]*0x200));
1197 nesvnic
->netstats
.rx_dropped
+= u32temp
;
1198 nesvnic
->endnode_nstat_rx_discard
+= u32temp
;
1200 u64temp
= (u64
)nes_read_indexed(nesdev
,
1201 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_LO
+
1202 (nesvnic
->qp_nic_index
[nic_count
]*0x200));
1203 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
1204 NES_IDX_ENDNODE0_NSTAT_RX_OCTETS_HI
+
1205 (nesvnic
->qp_nic_index
[nic_count
]*0x200))) << 32;
1207 nesvnic
->endnode_nstat_rx_octets
+= u64temp
;
1208 nesvnic
->netstats
.rx_bytes
+= u64temp
;
1210 u64temp
= (u64
)nes_read_indexed(nesdev
,
1211 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_LO
+
1212 (nesvnic
->qp_nic_index
[nic_count
]*0x200));
1213 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
1214 NES_IDX_ENDNODE0_NSTAT_RX_FRAMES_HI
+
1215 (nesvnic
->qp_nic_index
[nic_count
]*0x200))) << 32;
1217 nesvnic
->endnode_nstat_rx_frames
+= u64temp
;
1218 nesvnic
->netstats
.rx_packets
+= u64temp
;
1220 u64temp
= (u64
)nes_read_indexed(nesdev
,
1221 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_LO
+
1222 (nesvnic
->qp_nic_index
[nic_count
]*0x200));
1223 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
1224 NES_IDX_ENDNODE0_NSTAT_TX_OCTETS_HI
+
1225 (nesvnic
->qp_nic_index
[nic_count
]*0x200))) << 32;
1227 nesvnic
->endnode_nstat_tx_octets
+= u64temp
;
1228 nesvnic
->netstats
.tx_bytes
+= u64temp
;
1230 u64temp
= (u64
)nes_read_indexed(nesdev
,
1231 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_LO
+
1232 (nesvnic
->qp_nic_index
[nic_count
]*0x200));
1233 u64temp
+= ((u64
)nes_read_indexed(nesdev
,
1234 NES_IDX_ENDNODE0_NSTAT_TX_FRAMES_HI
+
1235 (nesvnic
->qp_nic_index
[nic_count
]*0x200))) << 32;
1237 nesvnic
->endnode_nstat_tx_frames
+= u64temp
;
1238 nesvnic
->netstats
.tx_packets
+= u64temp
;
1240 u32temp
= nes_read_indexed(nesdev
,
1241 NES_IDX_IPV4_TCP_REXMITS
+ (nesvnic
->qp_nic_index
[nic_count
]*0x200));
1242 nesvnic
->endnode_ipv4_tcp_retransmits
+= u32temp
;
1245 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_pause_frames_received
;
1246 target_stat_values
[++index
] = nesdev
->nesadapter
->nic_rx_eth_route_err
;
1247 target_stat_values
[++index
] = nesvnic
->tx_sw_dropped
;
1248 target_stat_values
[++index
] = nesvnic
->sq_full
;
1249 target_stat_values
[++index
] = nesvnic
->segmented_tso_requests
;
1250 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_rx_symbol_err_frames
;
1251 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_rx_jabber_frames
;
1252 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_rx_oversized_frames
;
1253 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_rx_short_frames
;
1254 target_stat_values
[++index
] = nesvnic
->netstats
.rx_length_errors
;
1255 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_rx_crc_errors
;
1256 target_stat_values
[++index
] = nesvnic
->nesdev
->port_rx_discards
;
1257 target_stat_values
[++index
] = nesvnic
->endnode_nstat_rx_discard
;
1258 target_stat_values
[++index
] = nesvnic
->endnode_nstat_rx_octets
;
1259 target_stat_values
[++index
] = nesvnic
->endnode_nstat_rx_frames
;
1260 target_stat_values
[++index
] = nesvnic
->endnode_nstat_tx_octets
;
1261 target_stat_values
[++index
] = nesvnic
->endnode_nstat_tx_frames
;
1262 target_stat_values
[++index
] = nesvnic
->nesdev
->mac_tx_errors
;
1263 target_stat_values
[++index
] = mh_detected
;
1264 target_stat_values
[++index
] = mh_pauses_sent
;
1265 target_stat_values
[++index
] = nesvnic
->endnode_ipv4_tcp_retransmits
;
1266 target_stat_values
[++index
] = atomic_read(&cm_connects
);
1267 target_stat_values
[++index
] = atomic_read(&cm_accepts
);
1268 target_stat_values
[++index
] = atomic_read(&cm_disconnects
);
1269 target_stat_values
[++index
] = atomic_read(&cm_connecteds
);
1270 target_stat_values
[++index
] = atomic_read(&cm_connect_reqs
);
1271 target_stat_values
[++index
] = atomic_read(&cm_rejects
);
1272 target_stat_values
[++index
] = atomic_read(&mod_qp_timouts
);
1273 target_stat_values
[++index
] = atomic_read(&qps_created
);
1274 target_stat_values
[++index
] = atomic_read(&sw_qps_destroyed
);
1275 target_stat_values
[++index
] = atomic_read(&qps_destroyed
);
1276 target_stat_values
[++index
] = atomic_read(&cm_closes
);
1277 target_stat_values
[++index
] = cm_packets_sent
;
1278 target_stat_values
[++index
] = cm_packets_bounced
;
1279 target_stat_values
[++index
] = cm_packets_created
;
1280 target_stat_values
[++index
] = cm_packets_received
;
1281 target_stat_values
[++index
] = cm_packets_dropped
;
1282 target_stat_values
[++index
] = cm_packets_retrans
;
1283 target_stat_values
[++index
] = atomic_read(&cm_listens_created
);
1284 target_stat_values
[++index
] = atomic_read(&cm_listens_destroyed
);
1285 target_stat_values
[++index
] = cm_backlog_drops
;
1286 target_stat_values
[++index
] = atomic_read(&cm_loopbacks
);
1287 target_stat_values
[++index
] = atomic_read(&cm_nodes_created
);
1288 target_stat_values
[++index
] = atomic_read(&cm_nodes_destroyed
);
1289 target_stat_values
[++index
] = atomic_read(&cm_accel_dropped_pkts
);
1290 target_stat_values
[++index
] = atomic_read(&cm_resets_recvd
);
1291 target_stat_values
[++index
] = nesadapter
->free_4kpbl
;
1292 target_stat_values
[++index
] = nesadapter
->free_256pbl
;
1293 target_stat_values
[++index
] = int_mod_timer_init
;
1294 target_stat_values
[++index
] = atomic_read(&pau_qps_created
);
1295 target_stat_values
[++index
] = atomic_read(&pau_qps_destroyed
);
1299 * nes_netdev_get_drvinfo
1301 static void nes_netdev_get_drvinfo(struct net_device
*netdev
,
1302 struct ethtool_drvinfo
*drvinfo
)
1304 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1305 struct nes_adapter
*nesadapter
= nesvnic
->nesdev
->nesadapter
;
1307 strlcpy(drvinfo
->driver
, DRV_NAME
, sizeof(drvinfo
->driver
));
1308 strlcpy(drvinfo
->bus_info
, pci_name(nesvnic
->nesdev
->pcidev
),
1309 sizeof(drvinfo
->bus_info
));
1310 snprintf(drvinfo
->fw_version
, sizeof(drvinfo
->fw_version
),
1311 "%u.%u", nesadapter
->firmware_version
>> 16,
1312 nesadapter
->firmware_version
& 0x000000ff);
1313 strlcpy(drvinfo
->version
, DRV_VERSION
, sizeof(drvinfo
->version
));
1318 * nes_netdev_set_coalesce
1320 static int nes_netdev_set_coalesce(struct net_device
*netdev
,
1321 struct ethtool_coalesce
*et_coalesce
)
1323 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1324 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1325 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1326 struct nes_hw_tune_timer
*shared_timer
= &nesadapter
->tune_timer
;
1327 unsigned long flags
;
1329 spin_lock_irqsave(&nesadapter
->periodic_timer_lock
, flags
);
1330 if (et_coalesce
->rx_max_coalesced_frames_low
) {
1331 shared_timer
->threshold_low
= et_coalesce
->rx_max_coalesced_frames_low
;
1333 if (et_coalesce
->rx_max_coalesced_frames_irq
) {
1334 shared_timer
->threshold_target
= et_coalesce
->rx_max_coalesced_frames_irq
;
1336 if (et_coalesce
->rx_max_coalesced_frames_high
) {
1337 shared_timer
->threshold_high
= et_coalesce
->rx_max_coalesced_frames_high
;
1339 if (et_coalesce
->rx_coalesce_usecs_low
) {
1340 shared_timer
->timer_in_use_min
= et_coalesce
->rx_coalesce_usecs_low
;
1342 if (et_coalesce
->rx_coalesce_usecs_high
) {
1343 shared_timer
->timer_in_use_max
= et_coalesce
->rx_coalesce_usecs_high
;
1345 spin_unlock_irqrestore(&nesadapter
->periodic_timer_lock
, flags
);
1347 /* using this to drive total interrupt moderation */
1348 nesadapter
->et_rx_coalesce_usecs_irq
= et_coalesce
->rx_coalesce_usecs_irq
;
1349 if (et_coalesce
->use_adaptive_rx_coalesce
) {
1350 nesadapter
->et_use_adaptive_rx_coalesce
= 1;
1351 nesadapter
->timer_int_limit
= NES_TIMER_INT_LIMIT_DYNAMIC
;
1352 nesadapter
->et_rx_coalesce_usecs_irq
= 0;
1353 if (et_coalesce
->pkt_rate_low
) {
1354 nesadapter
->et_pkt_rate_low
= et_coalesce
->pkt_rate_low
;
1357 nesadapter
->et_use_adaptive_rx_coalesce
= 0;
1358 nesadapter
->timer_int_limit
= NES_TIMER_INT_LIMIT
;
1359 if (nesadapter
->et_rx_coalesce_usecs_irq
) {
1360 nes_write32(nesdev
->regs
+NES_PERIODIC_CONTROL
,
1361 0x80000000 | ((u32
)(nesadapter
->et_rx_coalesce_usecs_irq
*8)));
1369 * nes_netdev_get_coalesce
1371 static int nes_netdev_get_coalesce(struct net_device
*netdev
,
1372 struct ethtool_coalesce
*et_coalesce
)
1374 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1375 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1376 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1377 struct ethtool_coalesce temp_et_coalesce
;
1378 struct nes_hw_tune_timer
*shared_timer
= &nesadapter
->tune_timer
;
1379 unsigned long flags
;
1381 memset(&temp_et_coalesce
, 0, sizeof(temp_et_coalesce
));
1382 temp_et_coalesce
.rx_coalesce_usecs_irq
= nesadapter
->et_rx_coalesce_usecs_irq
;
1383 temp_et_coalesce
.use_adaptive_rx_coalesce
= nesadapter
->et_use_adaptive_rx_coalesce
;
1384 temp_et_coalesce
.rate_sample_interval
= nesadapter
->et_rate_sample_interval
;
1385 temp_et_coalesce
.pkt_rate_low
= nesadapter
->et_pkt_rate_low
;
1386 spin_lock_irqsave(&nesadapter
->periodic_timer_lock
, flags
);
1387 temp_et_coalesce
.rx_max_coalesced_frames_low
= shared_timer
->threshold_low
;
1388 temp_et_coalesce
.rx_max_coalesced_frames_irq
= shared_timer
->threshold_target
;
1389 temp_et_coalesce
.rx_max_coalesced_frames_high
= shared_timer
->threshold_high
;
1390 temp_et_coalesce
.rx_coalesce_usecs_low
= shared_timer
->timer_in_use_min
;
1391 temp_et_coalesce
.rx_coalesce_usecs_high
= shared_timer
->timer_in_use_max
;
1392 if (nesadapter
->et_use_adaptive_rx_coalesce
) {
1393 temp_et_coalesce
.rx_coalesce_usecs_irq
= shared_timer
->timer_in_use
;
1395 spin_unlock_irqrestore(&nesadapter
->periodic_timer_lock
, flags
);
1396 memcpy(et_coalesce
, &temp_et_coalesce
, sizeof(*et_coalesce
));
1402 * nes_netdev_get_pauseparam
1404 static void nes_netdev_get_pauseparam(struct net_device
*netdev
,
1405 struct ethtool_pauseparam
*et_pauseparam
)
1407 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1409 et_pauseparam
->autoneg
= 0;
1410 et_pauseparam
->rx_pause
= (nesvnic
->nesdev
->disable_rx_flow_control
== 0) ? 1:0;
1411 et_pauseparam
->tx_pause
= (nesvnic
->nesdev
->disable_tx_flow_control
== 0) ? 1:0;
1416 * nes_netdev_set_pauseparam
1418 static int nes_netdev_set_pauseparam(struct net_device
*netdev
,
1419 struct ethtool_pauseparam
*et_pauseparam
)
1421 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1422 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1425 if (et_pauseparam
->autoneg
) {
1426 /* TODO: should return unsupported */
1429 if ((et_pauseparam
->tx_pause
== 1) && (nesdev
->disable_tx_flow_control
== 1)) {
1430 u32temp
= nes_read_indexed(nesdev
,
1431 NES_IDX_MAC_TX_CONFIG
+ (nesdev
->mac_index
*0x200));
1432 u32temp
|= NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE
;
1433 nes_write_indexed(nesdev
,
1434 NES_IDX_MAC_TX_CONFIG
+ (nesdev
->mac_index
*0x200), u32temp
);
1435 nesdev
->disable_tx_flow_control
= 0;
1436 } else if ((et_pauseparam
->tx_pause
== 0) && (nesdev
->disable_tx_flow_control
== 0)) {
1437 u32temp
= nes_read_indexed(nesdev
,
1438 NES_IDX_MAC_TX_CONFIG
+ (nesdev
->mac_index
*0x200));
1439 u32temp
&= ~NES_IDX_MAC_TX_CONFIG_ENABLE_PAUSE
;
1440 nes_write_indexed(nesdev
,
1441 NES_IDX_MAC_TX_CONFIG
+ (nesdev
->mac_index
*0x200), u32temp
);
1442 nesdev
->disable_tx_flow_control
= 1;
1444 if ((et_pauseparam
->rx_pause
== 1) && (nesdev
->disable_rx_flow_control
== 1)) {
1445 u32temp
= nes_read_indexed(nesdev
,
1446 NES_IDX_MPP_DEBUG
+ (nesdev
->mac_index
*0x40));
1447 u32temp
&= ~NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE
;
1448 nes_write_indexed(nesdev
,
1449 NES_IDX_MPP_DEBUG
+ (nesdev
->mac_index
*0x40), u32temp
);
1450 nesdev
->disable_rx_flow_control
= 0;
1451 } else if ((et_pauseparam
->rx_pause
== 0) && (nesdev
->disable_rx_flow_control
== 0)) {
1452 u32temp
= nes_read_indexed(nesdev
,
1453 NES_IDX_MPP_DEBUG
+ (nesdev
->mac_index
*0x40));
1454 u32temp
|= NES_IDX_MPP_DEBUG_PORT_DISABLE_PAUSE
;
1455 nes_write_indexed(nesdev
,
1456 NES_IDX_MPP_DEBUG
+ (nesdev
->mac_index
*0x40), u32temp
);
1457 nesdev
->disable_rx_flow_control
= 1;
1465 * nes_netdev_get_settings
1467 static int nes_netdev_get_link_ksettings(struct net_device
*netdev
,
1468 struct ethtool_link_ksettings
*cmd
)
1470 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1471 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1472 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1473 u32 mac_index
= nesdev
->mac_index
;
1474 u8 phy_type
= nesadapter
->phy_type
[mac_index
];
1475 u8 phy_index
= nesadapter
->phy_index
[mac_index
];
1477 u32 supported
, advertising
;
1479 cmd
->base
.duplex
= DUPLEX_FULL
;
1480 cmd
->base
.port
= PORT_MII
;
1482 if (nesadapter
->OneG_Mode
) {
1483 cmd
->base
.speed
= SPEED_1000
;
1484 if (phy_type
== NES_PHY_TYPE_PUMA_1G
) {
1485 supported
= SUPPORTED_1000baseT_Full
;
1486 advertising
= ADVERTISED_1000baseT_Full
;
1487 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
1488 cmd
->base
.phy_address
= mac_index
;
1490 unsigned long flags
;
1492 supported
= SUPPORTED_1000baseT_Full
1493 | SUPPORTED_Autoneg
;
1494 advertising
= ADVERTISED_1000baseT_Full
1495 | ADVERTISED_Autoneg
;
1496 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
1497 nes_read_1G_phy_reg(nesdev
, 0, phy_index
, &phy_data
);
1498 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
1499 if (phy_data
& 0x1000)
1500 cmd
->base
.autoneg
= AUTONEG_ENABLE
;
1502 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
1503 cmd
->base
.phy_address
= phy_index
;
1505 ethtool_convert_legacy_u32_to_link_mode(
1506 cmd
->link_modes
.supported
, supported
);
1507 ethtool_convert_legacy_u32_to_link_mode(
1508 cmd
->link_modes
.advertising
, advertising
);
1511 if ((phy_type
== NES_PHY_TYPE_ARGUS
) ||
1512 (phy_type
== NES_PHY_TYPE_SFP_D
) ||
1513 (phy_type
== NES_PHY_TYPE_KR
)) {
1514 cmd
->base
.port
= PORT_FIBRE
;
1515 supported
= SUPPORTED_FIBRE
;
1516 advertising
= ADVERTISED_FIBRE
;
1517 cmd
->base
.phy_address
= phy_index
;
1519 supported
= SUPPORTED_10000baseT_Full
;
1520 advertising
= ADVERTISED_10000baseT_Full
;
1521 cmd
->base
.phy_address
= mac_index
;
1523 cmd
->base
.speed
= SPEED_10000
;
1524 cmd
->base
.autoneg
= AUTONEG_DISABLE
;
1525 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.supported
,
1527 ethtool_convert_legacy_u32_to_link_mode(cmd
->link_modes
.advertising
,
1535 * nes_netdev_set_settings
1538 nes_netdev_set_link_ksettings(struct net_device
*netdev
,
1539 const struct ethtool_link_ksettings
*cmd
)
1541 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1542 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1543 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1545 if ((nesadapter
->OneG_Mode
) &&
1546 (nesadapter
->phy_type
[nesdev
->mac_index
] != NES_PHY_TYPE_PUMA_1G
)) {
1547 unsigned long flags
;
1549 u8 phy_index
= nesadapter
->phy_index
[nesdev
->mac_index
];
1551 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
1552 nes_read_1G_phy_reg(nesdev
, 0, phy_index
, &phy_data
);
1553 if (cmd
->base
.autoneg
) {
1554 /* Turn on Full duplex, Autoneg, and restart autonegotiation */
1557 /* Turn off autoneg */
1558 phy_data
&= ~0x1000;
1560 nes_write_1G_phy_reg(nesdev
, 0, phy_index
, phy_data
);
1561 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
1568 static const struct ethtool_ops nes_ethtool_ops
= {
1569 .get_link
= ethtool_op_get_link
,
1570 .get_strings
= nes_netdev_get_strings
,
1571 .get_sset_count
= nes_netdev_get_sset_count
,
1572 .get_ethtool_stats
= nes_netdev_get_ethtool_stats
,
1573 .get_drvinfo
= nes_netdev_get_drvinfo
,
1574 .get_coalesce
= nes_netdev_get_coalesce
,
1575 .set_coalesce
= nes_netdev_set_coalesce
,
1576 .get_pauseparam
= nes_netdev_get_pauseparam
,
1577 .set_pauseparam
= nes_netdev_set_pauseparam
,
1578 .get_link_ksettings
= nes_netdev_get_link_ksettings
,
1579 .set_link_ksettings
= nes_netdev_set_link_ksettings
,
1582 static void nes_vlan_mode(struct net_device
*netdev
, struct nes_device
*nesdev
, netdev_features_t features
)
1584 struct nes_adapter
*nesadapter
= nesdev
->nesadapter
;
1586 unsigned long flags
;
1588 spin_lock_irqsave(&nesadapter
->phy_lock
, flags
);
1590 nes_debug(NES_DBG_NETDEV
, "%s: %s\n", __func__
, netdev
->name
);
1592 /* Enable/Disable VLAN Stripping */
1593 u32temp
= nes_read_indexed(nesdev
, NES_IDX_PCIX_DIAG
);
1594 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
1595 u32temp
&= 0xfdffffff;
1597 u32temp
|= 0x02000000;
1599 nes_write_indexed(nesdev
, NES_IDX_PCIX_DIAG
, u32temp
);
1600 spin_unlock_irqrestore(&nesadapter
->phy_lock
, flags
);
1603 static netdev_features_t
nes_fix_features(struct net_device
*netdev
, netdev_features_t features
)
1606 * Since there is no support for separate rx/tx vlan accel
1607 * enable/disable make sure tx flag is always in same state as rx.
1609 if (features
& NETIF_F_HW_VLAN_CTAG_RX
)
1610 features
|= NETIF_F_HW_VLAN_CTAG_TX
;
1612 features
&= ~NETIF_F_HW_VLAN_CTAG_TX
;
1617 static int nes_set_features(struct net_device
*netdev
, netdev_features_t features
)
1619 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1620 struct nes_device
*nesdev
= nesvnic
->nesdev
;
1621 u32 changed
= netdev
->features
^ features
;
1623 if (changed
& NETIF_F_HW_VLAN_CTAG_RX
)
1624 nes_vlan_mode(netdev
, nesdev
, features
);
1629 static const struct net_device_ops nes_netdev_ops
= {
1630 .ndo_open
= nes_netdev_open
,
1631 .ndo_stop
= nes_netdev_stop
,
1632 .ndo_start_xmit
= nes_netdev_start_xmit
,
1633 .ndo_get_stats
= nes_netdev_get_stats
,
1634 .ndo_tx_timeout
= nes_netdev_tx_timeout
,
1635 .ndo_set_mac_address
= nes_netdev_set_mac_address
,
1636 .ndo_set_rx_mode
= nes_netdev_set_multicast_list
,
1637 .ndo_change_mtu
= nes_netdev_change_mtu
,
1638 .ndo_validate_addr
= eth_validate_addr
,
1639 .ndo_fix_features
= nes_fix_features
,
1640 .ndo_set_features
= nes_set_features
,
1644 * nes_netdev_init - initialize network device
1646 struct net_device
*nes_netdev_init(struct nes_device
*nesdev
,
1647 void __iomem
*mmio_addr
)
1650 struct nes_vnic
*nesvnic
;
1651 struct net_device
*netdev
;
1652 struct nic_qp_map
*curr_qp_map
;
1653 u8 phy_type
= nesdev
->nesadapter
->phy_type
[nesdev
->mac_index
];
1655 netdev
= alloc_etherdev(sizeof(struct nes_vnic
));
1657 printk(KERN_ERR PFX
"nesvnic etherdev alloc failed");
1660 nesvnic
= netdev_priv(netdev
);
1662 nes_debug(NES_DBG_INIT
, "netdev = %p, %s\n", netdev
, netdev
->name
);
1664 SET_NETDEV_DEV(netdev
, &nesdev
->pcidev
->dev
);
1666 netdev
->watchdog_timeo
= NES_TX_TIMEOUT
;
1667 netdev
->irq
= nesdev
->pcidev
->irq
;
1668 netdev
->max_mtu
= NES_MAX_MTU
;
1669 netdev
->hard_header_len
= ETH_HLEN
;
1670 netdev
->addr_len
= ETH_ALEN
;
1671 netdev
->type
= ARPHRD_ETHER
;
1672 netdev
->netdev_ops
= &nes_netdev_ops
;
1673 netdev
->ethtool_ops
= &nes_ethtool_ops
;
1674 netif_napi_add(netdev
, &nesvnic
->napi
, nes_netdev_poll
, 128);
1675 nes_debug(NES_DBG_INIT
, "Enabling VLAN Insert/Delete.\n");
1677 /* Fill in the port structure */
1678 nesvnic
->netdev
= netdev
;
1679 nesvnic
->nesdev
= nesdev
;
1680 nesvnic
->msg_enable
= netif_msg_init(debug
, default_msg
);
1681 nesvnic
->netdev_index
= nesdev
->netdev_count
;
1682 nesvnic
->perfect_filter_index
= nesdev
->nesadapter
->netdev_count
;
1683 nesvnic
->max_frame_size
= netdev
->mtu
+ netdev
->hard_header_len
+ VLAN_HLEN
;
1685 curr_qp_map
= nic_qp_mapping_per_function
[PCI_FUNC(nesdev
->pcidev
->devfn
)];
1686 nesvnic
->nic
.qp_id
= curr_qp_map
[nesdev
->netdev_count
].qpid
;
1687 nesvnic
->nic_index
= curr_qp_map
[nesdev
->netdev_count
].nic_index
;
1688 nesvnic
->logical_port
= curr_qp_map
[nesdev
->netdev_count
].logical_port
;
1690 /* Setup the burned in MAC address */
1691 u64temp
= (u64
)nesdev
->nesadapter
->mac_addr_low
;
1692 u64temp
+= ((u64
)nesdev
->nesadapter
->mac_addr_high
) << 32;
1693 u64temp
+= nesvnic
->nic_index
;
1694 netdev
->dev_addr
[0] = (u8
)(u64temp
>>40);
1695 netdev
->dev_addr
[1] = (u8
)(u64temp
>>32);
1696 netdev
->dev_addr
[2] = (u8
)(u64temp
>>24);
1697 netdev
->dev_addr
[3] = (u8
)(u64temp
>>16);
1698 netdev
->dev_addr
[4] = (u8
)(u64temp
>>8);
1699 netdev
->dev_addr
[5] = (u8
)u64temp
;
1701 netdev
->hw_features
= NETIF_F_SG
| NETIF_F_IP_CSUM
| NETIF_F_RXCSUM
| NETIF_F_HW_VLAN_CTAG_RX
;
1702 if ((nesvnic
->logical_port
< 2) || (nesdev
->nesadapter
->hw_rev
!= NE020_REV
))
1703 netdev
->hw_features
|= NETIF_F_TSO
;
1705 netdev
->features
= netdev
->hw_features
| NETIF_F_HIGHDMA
| NETIF_F_HW_VLAN_CTAG_TX
;
1707 nes_debug(NES_DBG_INIT
, "nesvnic = %p, reported features = 0x%lX, QPid = %d,"
1708 " nic_index = %d, logical_port = %d, mac_index = %d.\n",
1709 nesvnic
, (unsigned long)netdev
->features
, nesvnic
->nic
.qp_id
,
1710 nesvnic
->nic_index
, nesvnic
->logical_port
, nesdev
->mac_index
);
1712 if (nesvnic
->nesdev
->nesadapter
->port_count
== 1 &&
1713 nesvnic
->nesdev
->nesadapter
->adapter_fcn_count
== 1) {
1715 nesvnic
->qp_nic_index
[0] = nesvnic
->nic_index
;
1716 nesvnic
->qp_nic_index
[1] = nesvnic
->nic_index
+ 1;
1717 if (nes_drv_opt
& NES_DRV_OPT_DUAL_LOGICAL_PORT
) {
1718 nesvnic
->qp_nic_index
[2] = 0xf;
1719 nesvnic
->qp_nic_index
[3] = 0xf;
1721 nesvnic
->qp_nic_index
[2] = nesvnic
->nic_index
+ 2;
1722 nesvnic
->qp_nic_index
[3] = nesvnic
->nic_index
+ 3;
1725 if (nesvnic
->nesdev
->nesadapter
->port_count
== 2 ||
1726 (nesvnic
->nesdev
->nesadapter
->port_count
== 1 &&
1727 nesvnic
->nesdev
->nesadapter
->adapter_fcn_count
== 2)) {
1728 nesvnic
->qp_nic_index
[0] = nesvnic
->nic_index
;
1729 nesvnic
->qp_nic_index
[1] = nesvnic
->nic_index
1731 nesvnic
->qp_nic_index
[2] = 0xf;
1732 nesvnic
->qp_nic_index
[3] = 0xf;
1734 nesvnic
->qp_nic_index
[0] = nesvnic
->nic_index
;
1735 nesvnic
->qp_nic_index
[1] = 0xf;
1736 nesvnic
->qp_nic_index
[2] = 0xf;
1737 nesvnic
->qp_nic_index
[3] = 0xf;
1740 nesvnic
->next_qp_nic_index
= 0;
1742 if (nesdev
->netdev_count
== 0) {
1743 nesvnic
->rdma_enabled
= 1;
1745 nesvnic
->rdma_enabled
= 0;
1747 nesvnic
->nic_cq
.cq_number
= nesvnic
->nic
.qp_id
;
1748 timer_setup(&nesvnic
->event_timer
, NULL
, 0);
1749 spin_lock_init(&nesvnic
->tx_lock
);
1750 spin_lock_init(&nesvnic
->port_ibevent_lock
);
1751 nesdev
->netdev
[nesdev
->netdev_count
] = netdev
;
1753 nes_debug(NES_DBG_INIT
, "Adding nesvnic (%p) to the adapters nesvnic_list for MAC%d.\n",
1754 nesvnic
, nesdev
->mac_index
);
1755 list_add_tail(&nesvnic
->list
, &nesdev
->nesadapter
->nesvnic_list
[nesdev
->mac_index
]);
1757 if ((nesdev
->netdev_count
== 0) &&
1758 ((PCI_FUNC(nesdev
->pcidev
->devfn
) == nesdev
->mac_index
) ||
1759 ((phy_type
== NES_PHY_TYPE_PUMA_1G
) &&
1760 (((PCI_FUNC(nesdev
->pcidev
->devfn
) == 1) && (nesdev
->mac_index
== 2)) ||
1761 ((PCI_FUNC(nesdev
->pcidev
->devfn
) == 2) && (nesdev
->mac_index
== 1)))))) {
1767 unsigned long flags
;
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 */
1780 case NES_PHY_TYPE_PUMA_1G
:
1781 if (nesdev
->mac_index
< 2) {
1782 link_mask
= 0x01010000;
1783 link_val
= 0x01010000;
1785 link_mask
= 0x02020000;
1786 link_val
= 0x02020000;
1789 case NES_PHY_TYPE_SFP_D
:
1790 spin_lock_irqsave(&nesdev
->nesadapter
->phy_lock
, flags
);
1791 nes_read_10G_phy_reg(nesdev
,
1792 nesdev
->nesadapter
->phy_index
[nesdev
->mac_index
],
1794 temp_phy_data
= (u16
)nes_read_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
);
1795 nes_read_10G_phy_reg(nesdev
,
1796 nesdev
->nesadapter
->phy_index
[nesdev
->mac_index
],
1798 nes_read_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
);
1799 nes_read_10G_phy_reg(nesdev
,
1800 nesdev
->nesadapter
->phy_index
[nesdev
->mac_index
],
1802 phy_data
= (u16
)nes_read_indexed(nesdev
, NES_IDX_MAC_MDIO_CONTROL
);
1803 spin_unlock_irqrestore(&nesdev
->nesadapter
->phy_lock
, flags
);
1804 phy_data
= (!temp_phy_data
&& (phy_data
== 0x8000)) ? 0x4 : 0x0;
1807 link_mask
= 0x0f1f0000;
1808 link_val
= 0x0f0f0000;
1812 u32temp
= nes_read_indexed(nesdev
,
1813 NES_IDX_PHY_PCS_CONTROL_STATUS0
+
1814 (0x200 * (nesdev
->mac_index
& 1)));
1816 if (phy_type
== NES_PHY_TYPE_SFP_D
) {
1817 if (phy_data
& 0x0004)
1818 nesvnic
->linkup
= 1;
1820 if ((u32temp
& link_mask
) == link_val
)
1821 nesvnic
->linkup
= 1;
1824 /* clear the MAC interrupt status, assumes direct logical to physical mapping */
1825 u32temp
= nes_read_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
+ (0x200 * nesdev
->mac_index
));
1826 nes_debug(NES_DBG_INIT
, "Phy interrupt status = 0x%X.\n", u32temp
);
1827 nes_write_indexed(nesdev
, NES_IDX_MAC_INT_STATUS
+ (0x200 * nesdev
->mac_index
), u32temp
);
1829 nes_init_phy(nesdev
);
1832 nes_vlan_mode(netdev
, nesdev
, netdev
->features
);
1839 * nes_netdev_destroy - destroy network device structure
1841 void nes_netdev_destroy(struct net_device
*netdev
)
1843 struct nes_vnic
*nesvnic
= netdev_priv(netdev
);
1845 /* make sure 'stop' method is called by Linux stack */
1846 /* nes_netdev_stop(netdev); */
1848 list_del(&nesvnic
->list
);
1850 if (nesvnic
->of_device_registered
) {
1851 nes_destroy_ofa_device(nesvnic
->nesibdev
);
1854 free_netdev(netdev
);
1859 * nes_nic_cm_xmit -- CM calls this to send out pkts
1861 int nes_nic_cm_xmit(struct sk_buff
*skb
, struct net_device
*netdev
)
1866 ret
= dev_queue_xmit(skb
);
1868 nes_debug(NES_DBG_CM
, "Bad return code from dev_queue_xmit %d\n", ret
);