1 /******************************************************************************
2 * This software may be used and distributed according to the terms of
3 * the GNU General Public License (GPL), incorporated herein by reference.
4 * Drivers based on or derived from this code fall under the GPL and must
5 * retain the authorship, copyright and license notice. This file is not
6 * a complete program and may only be used when the entire operating
7 * system is licensed under the GPL.
8 * See the file COPYING in this distribution for more information.
10 * vxge-main.c: Driver for Neterion Inc's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2009 Neterion Inc.
14 * The module loadable parameters that are supported by the driver and a brief
15 * explanation of all the variables:
17 * Strip VLAN Tag enable/disable. Instructs the device to remove
18 * the VLAN tag from all received tagged frames that are not
19 * replicated at the internal L2 switch.
20 * 0 - Do not strip the VLAN tag.
21 * 1 - Strip the VLAN tag.
24 * Enable learning the mac address of the guest OS interface in
25 * a virtualization environment.
30 * Maximum number of port to be supported.
34 * This configures the maximum no of VPATH configures for each
36 * MIN - 1 and MAX - 17
39 * This configures maximum no of Device function to be enabled.
40 * MIN - 1 and MAX - 17
42 ******************************************************************************/
44 #include <linux/if_vlan.h>
45 #include <linux/pci.h>
46 #include <linux/slab.h>
47 #include <linux/tcp.h>
49 #include <linux/netdevice.h>
50 #include <linux/etherdevice.h>
51 #include "vxge-main.h"
54 MODULE_LICENSE("Dual BSD/GPL");
55 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
56 "Virtualized Server Adapter");
58 static DEFINE_PCI_DEVICE_TABLE(vxge_id_table
) = {
59 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_WIN
, PCI_ANY_ID
,
61 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_UNI
, PCI_ANY_ID
,
66 MODULE_DEVICE_TABLE(pci
, vxge_id_table
);
68 VXGE_MODULE_PARAM_INT(vlan_tag_strip
, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
);
69 VXGE_MODULE_PARAM_INT(addr_learn_en
, VXGE_HW_MAC_ADDR_LEARN_DEFAULT
);
70 VXGE_MODULE_PARAM_INT(max_config_port
, VXGE_MAX_CONFIG_PORT
);
71 VXGE_MODULE_PARAM_INT(max_config_vpath
, VXGE_USE_DEFAULT
);
72 VXGE_MODULE_PARAM_INT(max_mac_vpath
, VXGE_MAX_MAC_ADDR_COUNT
);
73 VXGE_MODULE_PARAM_INT(max_config_dev
, VXGE_MAX_CONFIG_DEV
);
75 static u16 vpath_selector
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
76 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
77 static unsigned int bw_percentage
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
78 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS
- 1)] = 0xFF};
79 module_param_array(bw_percentage
, uint
, NULL
, 0);
81 static struct vxge_drv_config
*driver_config
;
83 static inline int is_vxge_card_up(struct vxgedev
*vdev
)
85 return test_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
88 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo
*fifo
)
90 unsigned long flags
= 0;
91 struct sk_buff
**skb_ptr
= NULL
;
92 struct sk_buff
**temp
;
93 #define NR_SKB_COMPLETED 128
94 struct sk_buff
*completed
[NR_SKB_COMPLETED
];
101 if (spin_trylock_irqsave(&fifo
->tx_lock
, flags
)) {
102 vxge_hw_vpath_poll_tx(fifo
->handle
, &skb_ptr
,
103 NR_SKB_COMPLETED
, &more
);
104 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
107 for (temp
= completed
; temp
!= skb_ptr
; temp
++)
108 dev_kfree_skb_irq(*temp
);
112 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev
*vdev
)
116 /* Complete all transmits */
117 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
118 VXGE_COMPLETE_VPATH_TX(&vdev
->vpaths
[i
].fifo
);
121 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev
*vdev
)
124 struct vxge_ring
*ring
;
126 /* Complete all receives*/
127 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
128 ring
= &vdev
->vpaths
[i
].ring
;
129 vxge_hw_vpath_poll_rx(ring
->handle
);
134 * MultiQ manipulation helper functions
136 void vxge_stop_all_tx_queue(struct vxgedev
*vdev
)
139 struct net_device
*dev
= vdev
->ndev
;
141 if (vdev
->config
.tx_steering_type
!= TX_MULTIQ_STEERING
) {
142 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
143 vdev
->vpaths
[i
].fifo
.queue_state
= VPATH_QUEUE_STOP
;
145 netif_tx_stop_all_queues(dev
);
148 void vxge_stop_tx_queue(struct vxge_fifo
*fifo
)
150 struct net_device
*dev
= fifo
->ndev
;
152 struct netdev_queue
*txq
= NULL
;
153 if (fifo
->tx_steering_type
== TX_MULTIQ_STEERING
)
154 txq
= netdev_get_tx_queue(dev
, fifo
->driver_id
);
156 txq
= netdev_get_tx_queue(dev
, 0);
157 fifo
->queue_state
= VPATH_QUEUE_STOP
;
160 netif_tx_stop_queue(txq
);
163 void vxge_start_all_tx_queue(struct vxgedev
*vdev
)
166 struct net_device
*dev
= vdev
->ndev
;
168 if (vdev
->config
.tx_steering_type
!= TX_MULTIQ_STEERING
) {
169 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
170 vdev
->vpaths
[i
].fifo
.queue_state
= VPATH_QUEUE_START
;
172 netif_tx_start_all_queues(dev
);
175 static void vxge_wake_all_tx_queue(struct vxgedev
*vdev
)
178 struct net_device
*dev
= vdev
->ndev
;
180 if (vdev
->config
.tx_steering_type
!= TX_MULTIQ_STEERING
) {
181 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
182 vdev
->vpaths
[i
].fifo
.queue_state
= VPATH_QUEUE_START
;
184 netif_tx_wake_all_queues(dev
);
187 void vxge_wake_tx_queue(struct vxge_fifo
*fifo
, struct sk_buff
*skb
)
189 struct net_device
*dev
= fifo
->ndev
;
191 int vpath_no
= fifo
->driver_id
;
192 struct netdev_queue
*txq
= NULL
;
193 if (fifo
->tx_steering_type
== TX_MULTIQ_STEERING
) {
194 txq
= netdev_get_tx_queue(dev
, vpath_no
);
195 if (netif_tx_queue_stopped(txq
))
196 netif_tx_wake_queue(txq
);
198 txq
= netdev_get_tx_queue(dev
, 0);
199 if (fifo
->queue_state
== VPATH_QUEUE_STOP
)
200 if (netif_tx_queue_stopped(txq
)) {
201 fifo
->queue_state
= VPATH_QUEUE_START
;
202 netif_tx_wake_queue(txq
);
208 * vxge_callback_link_up
210 * This function is called during interrupt context to notify link up state
214 vxge_callback_link_up(struct __vxge_hw_device
*hldev
)
216 struct net_device
*dev
= hldev
->ndev
;
217 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
219 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
220 vdev
->ndev
->name
, __func__
, __LINE__
);
221 printk(KERN_NOTICE
"%s: Link Up\n", vdev
->ndev
->name
);
222 vdev
->stats
.link_up
++;
224 netif_carrier_on(vdev
->ndev
);
225 vxge_wake_all_tx_queue(vdev
);
227 vxge_debug_entryexit(VXGE_TRACE
,
228 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
232 * vxge_callback_link_down
234 * This function is called during interrupt context to notify link down state
238 vxge_callback_link_down(struct __vxge_hw_device
*hldev
)
240 struct net_device
*dev
= hldev
->ndev
;
241 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
243 vxge_debug_entryexit(VXGE_TRACE
,
244 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
245 printk(KERN_NOTICE
"%s: Link Down\n", vdev
->ndev
->name
);
247 vdev
->stats
.link_down
++;
248 netif_carrier_off(vdev
->ndev
);
249 vxge_stop_all_tx_queue(vdev
);
251 vxge_debug_entryexit(VXGE_TRACE
,
252 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
260 static struct sk_buff
*
261 vxge_rx_alloc(void *dtrh
, struct vxge_ring
*ring
, const int skb_size
)
263 struct net_device
*dev
;
265 struct vxge_rx_priv
*rx_priv
;
268 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
269 ring
->ndev
->name
, __func__
, __LINE__
);
271 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
273 /* try to allocate skb first. this one may fail */
274 skb
= netdev_alloc_skb(dev
, skb_size
+
275 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
277 vxge_debug_mem(VXGE_ERR
,
278 "%s: out of memory to allocate SKB", dev
->name
);
279 ring
->stats
.skb_alloc_fail
++;
283 vxge_debug_mem(VXGE_TRACE
,
284 "%s: %s:%d Skb : 0x%p", ring
->ndev
->name
,
285 __func__
, __LINE__
, skb
);
287 skb_reserve(skb
, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
290 rx_priv
->skb_data
= NULL
;
291 rx_priv
->data_size
= skb_size
;
292 vxge_debug_entryexit(VXGE_TRACE
,
293 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
301 static int vxge_rx_map(void *dtrh
, struct vxge_ring
*ring
)
303 struct vxge_rx_priv
*rx_priv
;
306 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
307 ring
->ndev
->name
, __func__
, __LINE__
);
308 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
310 rx_priv
->skb_data
= rx_priv
->skb
->data
;
311 dma_addr
= pci_map_single(ring
->pdev
, rx_priv
->skb_data
,
312 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
314 if (unlikely(pci_dma_mapping_error(ring
->pdev
, dma_addr
))) {
315 ring
->stats
.pci_map_fail
++;
318 vxge_debug_mem(VXGE_TRACE
,
319 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
320 ring
->ndev
->name
, __func__
, __LINE__
,
321 (unsigned long long)dma_addr
);
322 vxge_hw_ring_rxd_1b_set(dtrh
, dma_addr
, rx_priv
->data_size
);
324 rx_priv
->data_dma
= dma_addr
;
325 vxge_debug_entryexit(VXGE_TRACE
,
326 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
332 * vxge_rx_initial_replenish
333 * Allocation of RxD as an initial replenish procedure.
335 static enum vxge_hw_status
336 vxge_rx_initial_replenish(void *dtrh
, void *userdata
)
338 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
339 struct vxge_rx_priv
*rx_priv
;
341 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
342 ring
->ndev
->name
, __func__
, __LINE__
);
343 if (vxge_rx_alloc(dtrh
, ring
,
344 VXGE_LL_MAX_FRAME_SIZE(ring
->ndev
)) == NULL
)
347 if (vxge_rx_map(dtrh
, ring
)) {
348 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
349 dev_kfree_skb(rx_priv
->skb
);
353 vxge_debug_entryexit(VXGE_TRACE
,
354 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
360 vxge_rx_complete(struct vxge_ring
*ring
, struct sk_buff
*skb
, u16 vlan
,
361 int pkt_length
, struct vxge_hw_ring_rxd_info
*ext_info
)
364 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
365 ring
->ndev
->name
, __func__
, __LINE__
);
366 skb_record_rx_queue(skb
, ring
->driver_id
);
367 skb
->protocol
= eth_type_trans(skb
, ring
->ndev
);
369 ring
->stats
.rx_frms
++;
370 ring
->stats
.rx_bytes
+= pkt_length
;
372 if (skb
->pkt_type
== PACKET_MULTICAST
)
373 ring
->stats
.rx_mcast
++;
375 vxge_debug_rx(VXGE_TRACE
,
376 "%s: %s:%d skb protocol = %d",
377 ring
->ndev
->name
, __func__
, __LINE__
, skb
->protocol
);
379 if (ring
->gro_enable
) {
380 if (ring
->vlgrp
&& ext_info
->vlan
&&
381 (ring
->vlan_tag_strip
==
382 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
))
383 vlan_gro_receive(ring
->napi_p
, ring
->vlgrp
,
384 ext_info
->vlan
, skb
);
386 napi_gro_receive(ring
->napi_p
, skb
);
388 if (ring
->vlgrp
&& vlan
&&
389 (ring
->vlan_tag_strip
==
390 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
))
391 vlan_hwaccel_receive_skb(skb
, ring
->vlgrp
, vlan
);
393 netif_receive_skb(skb
);
395 vxge_debug_entryexit(VXGE_TRACE
,
396 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
399 static inline void vxge_re_pre_post(void *dtr
, struct vxge_ring
*ring
,
400 struct vxge_rx_priv
*rx_priv
)
402 pci_dma_sync_single_for_device(ring
->pdev
,
403 rx_priv
->data_dma
, rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
405 vxge_hw_ring_rxd_1b_set(dtr
, rx_priv
->data_dma
, rx_priv
->data_size
);
406 vxge_hw_ring_rxd_pre_post(ring
->handle
, dtr
);
409 static inline void vxge_post(int *dtr_cnt
, void **first_dtr
,
410 void *post_dtr
, struct __vxge_hw_ring
*ringh
)
412 int dtr_count
= *dtr_cnt
;
413 if ((*dtr_cnt
% VXGE_HW_RXSYNC_FREQ_CNT
) == 0) {
415 vxge_hw_ring_rxd_post_post_wmb(ringh
, *first_dtr
);
416 *first_dtr
= post_dtr
;
418 vxge_hw_ring_rxd_post_post(ringh
, post_dtr
);
420 *dtr_cnt
= dtr_count
;
426 * If the interrupt is because of a received frame or if the receive ring
427 * contains fresh as yet un-processed frames, this function is called.
430 vxge_rx_1b_compl(struct __vxge_hw_ring
*ringh
, void *dtr
,
431 u8 t_code
, void *userdata
)
433 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
434 struct net_device
*dev
= ring
->ndev
;
435 unsigned int dma_sizes
;
436 void *first_dtr
= NULL
;
442 struct vxge_rx_priv
*rx_priv
;
443 struct vxge_hw_ring_rxd_info ext_info
;
444 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
445 ring
->ndev
->name
, __func__
, __LINE__
);
446 ring
->pkts_processed
= 0;
448 vxge_hw_ring_replenish(ringh
);
451 prefetch((char *)dtr
+ L1_CACHE_BYTES
);
452 rx_priv
= vxge_hw_ring_rxd_private_get(dtr
);
454 data_size
= rx_priv
->data_size
;
455 data_dma
= rx_priv
->data_dma
;
456 prefetch(rx_priv
->skb_data
);
458 vxge_debug_rx(VXGE_TRACE
,
459 "%s: %s:%d skb = 0x%p",
460 ring
->ndev
->name
, __func__
, __LINE__
, skb
);
462 vxge_hw_ring_rxd_1b_get(ringh
, dtr
, &dma_sizes
);
463 pkt_length
= dma_sizes
;
465 pkt_length
-= ETH_FCS_LEN
;
467 vxge_debug_rx(VXGE_TRACE
,
468 "%s: %s:%d Packet Length = %d",
469 ring
->ndev
->name
, __func__
, __LINE__
, pkt_length
);
471 vxge_hw_ring_rxd_1b_info_get(ringh
, dtr
, &ext_info
);
473 /* check skb validity */
476 prefetch((char *)skb
+ L1_CACHE_BYTES
);
477 if (unlikely(t_code
)) {
479 if (vxge_hw_ring_handle_tcode(ringh
, dtr
, t_code
) !=
482 ring
->stats
.rx_errors
++;
483 vxge_debug_rx(VXGE_TRACE
,
484 "%s: %s :%d Rx T_code is %d",
485 ring
->ndev
->name
, __func__
,
488 /* If the t_code is not supported and if the
489 * t_code is other than 0x5 (unparseable packet
490 * such as unknown UPV6 header), Drop it !!!
492 vxge_re_pre_post(dtr
, ring
, rx_priv
);
494 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
495 ring
->stats
.rx_dropped
++;
500 if (pkt_length
> VXGE_LL_RX_COPY_THRESHOLD
) {
502 if (vxge_rx_alloc(dtr
, ring
, data_size
) != NULL
) {
504 if (!vxge_rx_map(dtr
, ring
)) {
505 skb_put(skb
, pkt_length
);
507 pci_unmap_single(ring
->pdev
, data_dma
,
508 data_size
, PCI_DMA_FROMDEVICE
);
510 vxge_hw_ring_rxd_pre_post(ringh
, dtr
);
511 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
514 dev_kfree_skb(rx_priv
->skb
);
516 rx_priv
->data_size
= data_size
;
517 vxge_re_pre_post(dtr
, ring
, rx_priv
);
519 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
521 ring
->stats
.rx_dropped
++;
525 vxge_re_pre_post(dtr
, ring
, rx_priv
);
527 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
528 ring
->stats
.rx_dropped
++;
532 struct sk_buff
*skb_up
;
534 skb_up
= netdev_alloc_skb(dev
, pkt_length
+
535 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
536 if (skb_up
!= NULL
) {
538 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
540 pci_dma_sync_single_for_cpu(ring
->pdev
,
544 vxge_debug_mem(VXGE_TRACE
,
545 "%s: %s:%d skb_up = %p",
546 ring
->ndev
->name
, __func__
,
548 memcpy(skb_up
->data
, skb
->data
, pkt_length
);
550 vxge_re_pre_post(dtr
, ring
, rx_priv
);
552 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
554 /* will netif_rx small SKB instead */
556 skb_put(skb
, pkt_length
);
558 vxge_re_pre_post(dtr
, ring
, rx_priv
);
560 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
561 vxge_debug_rx(VXGE_ERR
,
562 "%s: vxge_rx_1b_compl: out of "
563 "memory", dev
->name
);
564 ring
->stats
.skb_alloc_fail
++;
569 if ((ext_info
.proto
& VXGE_HW_FRAME_PROTO_TCP_OR_UDP
) &&
570 !(ext_info
.proto
& VXGE_HW_FRAME_PROTO_IP_FRAG
) &&
571 ring
->rx_csum
&& /* Offload Rx side CSUM */
572 ext_info
.l3_cksum
== VXGE_HW_L3_CKSUM_OK
&&
573 ext_info
.l4_cksum
== VXGE_HW_L4_CKSUM_OK
)
574 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
576 skb
->ip_summed
= CHECKSUM_NONE
;
578 vxge_rx_complete(ring
, skb
, ext_info
.vlan
,
579 pkt_length
, &ext_info
);
582 ring
->pkts_processed
++;
586 } while (vxge_hw_ring_rxd_next_completed(ringh
, &dtr
,
587 &t_code
) == VXGE_HW_OK
);
590 vxge_hw_ring_rxd_post_post_wmb(ringh
, first_dtr
);
592 vxge_debug_entryexit(VXGE_TRACE
,
601 * If an interrupt was raised to indicate DMA complete of the Tx packet,
602 * this function is called. It identifies the last TxD whose buffer was
603 * freed and frees all skbs whose data have already DMA'ed into the NICs
607 vxge_xmit_compl(struct __vxge_hw_fifo
*fifo_hw
, void *dtr
,
608 enum vxge_hw_fifo_tcode t_code
, void *userdata
,
609 struct sk_buff
***skb_ptr
, int nr_skb
, int *more
)
611 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
612 struct sk_buff
*skb
, **done_skb
= *skb_ptr
;
615 vxge_debug_entryexit(VXGE_TRACE
,
616 "%s:%d Entered....", __func__
, __LINE__
);
622 struct vxge_tx_priv
*txd_priv
=
623 vxge_hw_fifo_txdl_private_get(dtr
);
626 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
627 frag
= &skb_shinfo(skb
)->frags
[0];
629 vxge_debug_tx(VXGE_TRACE
,
630 "%s: %s:%d fifo_hw = %p dtr = %p "
631 "tcode = 0x%x", fifo
->ndev
->name
, __func__
,
632 __LINE__
, fifo_hw
, dtr
, t_code
);
633 /* check skb validity */
635 vxge_debug_tx(VXGE_TRACE
,
636 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
637 fifo
->ndev
->name
, __func__
, __LINE__
,
638 skb
, txd_priv
, frg_cnt
);
639 if (unlikely(t_code
)) {
640 fifo
->stats
.tx_errors
++;
641 vxge_debug_tx(VXGE_ERR
,
642 "%s: tx: dtr %p completed due to "
643 "error t_code %01x", fifo
->ndev
->name
,
645 vxge_hw_fifo_handle_tcode(fifo_hw
, dtr
, t_code
);
648 /* for unfragmented skb */
649 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
650 skb_headlen(skb
), PCI_DMA_TODEVICE
);
652 for (j
= 0; j
< frg_cnt
; j
++) {
653 pci_unmap_page(fifo
->pdev
,
654 txd_priv
->dma_buffers
[i
++],
655 frag
->size
, PCI_DMA_TODEVICE
);
659 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
661 /* Updating the statistics block */
662 fifo
->stats
.tx_frms
++;
663 fifo
->stats
.tx_bytes
+= skb
->len
;
673 if (pkt_cnt
> fifo
->indicate_max_pkts
)
676 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw
,
677 &dtr
, &t_code
) == VXGE_HW_OK
);
680 vxge_wake_tx_queue(fifo
, skb
);
682 vxge_debug_entryexit(VXGE_TRACE
,
683 "%s: %s:%d Exiting...",
684 fifo
->ndev
->name
, __func__
, __LINE__
);
688 /* select a vpath to transmit the packet */
689 static u32
vxge_get_vpath_no(struct vxgedev
*vdev
, struct sk_buff
*skb
,
692 u16 queue_len
, counter
= 0;
693 if (skb
->protocol
== htons(ETH_P_IP
)) {
699 if ((ip
->frag_off
& htons(IP_OFFSET
|IP_MF
)) == 0) {
700 th
= (struct tcphdr
*)(((unsigned char *)ip
) +
703 queue_len
= vdev
->no_of_vpath
;
704 counter
= (ntohs(th
->source
) +
706 vdev
->vpath_selector
[queue_len
- 1];
707 if (counter
>= queue_len
)
708 counter
= queue_len
- 1;
710 if (ip
->protocol
== IPPROTO_UDP
) {
720 static enum vxge_hw_status
vxge_search_mac_addr_in_list(
721 struct vxge_vpath
*vpath
, u64 del_mac
)
723 struct list_head
*entry
, *next
;
724 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
725 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
)
731 static int vxge_learn_mac(struct vxgedev
*vdev
, u8
*mac_header
)
733 struct macInfo mac_info
;
734 u8
*mac_address
= NULL
;
735 u64 mac_addr
= 0, vpath_vector
= 0;
737 enum vxge_hw_status status
= VXGE_HW_OK
;
738 struct vxge_vpath
*vpath
= NULL
;
739 struct __vxge_hw_device
*hldev
;
741 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
743 mac_address
= (u8
*)&mac_addr
;
744 memcpy(mac_address
, mac_header
, ETH_ALEN
);
746 /* Is this mac address already in the list? */
747 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
748 vpath
= &vdev
->vpaths
[vpath_idx
];
749 if (vxge_search_mac_addr_in_list(vpath
, mac_addr
))
753 memset(&mac_info
, 0, sizeof(struct macInfo
));
754 memcpy(mac_info
.macaddr
, mac_header
, ETH_ALEN
);
756 /* Any vpath has room to add mac address to its da table? */
757 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
758 vpath
= &vdev
->vpaths
[vpath_idx
];
759 if (vpath
->mac_addr_cnt
< vpath
->max_mac_addr_cnt
) {
760 /* Add this mac address to this vpath */
761 mac_info
.vpath_no
= vpath_idx
;
762 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
763 status
= vxge_add_mac_addr(vdev
, &mac_info
);
764 if (status
!= VXGE_HW_OK
)
770 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_LIST
;
772 mac_info
.vpath_no
= vpath_idx
;
773 /* Is the first vpath already selected as catch-basin ? */
774 vpath
= &vdev
->vpaths
[vpath_idx
];
775 if (vpath
->mac_addr_cnt
> vpath
->max_mac_addr_cnt
) {
776 /* Add this mac address to this vpath */
777 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
782 /* Select first vpath as catch-basin */
783 vpath_vector
= vxge_mBIT(vpath
->device_id
);
784 status
= vxge_hw_mgmt_reg_write(vpath
->vdev
->devh
,
785 vxge_hw_mgmt_reg_type_mrpcim
,
788 struct vxge_hw_mrpcim_reg
,
791 if (status
!= VXGE_HW_OK
) {
792 vxge_debug_tx(VXGE_ERR
,
793 "%s: Unable to set the vpath-%d in catch-basin mode",
794 VXGE_DRIVER_NAME
, vpath
->device_id
);
798 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
806 * @skb : the socket buffer containing the Tx data.
807 * @dev : device pointer.
809 * This function is the Tx entry point of the driver. Neterion NIC supports
810 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
811 * NOTE: when device cant queue the pkt, just the trans_start variable will
815 vxge_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
817 struct vxge_fifo
*fifo
= NULL
;
820 struct vxgedev
*vdev
= NULL
;
821 enum vxge_hw_status status
;
822 int frg_cnt
, first_frg_len
;
824 int i
= 0, j
= 0, avail
;
826 struct vxge_tx_priv
*txdl_priv
= NULL
;
827 struct __vxge_hw_fifo
*fifo_hw
;
829 unsigned long flags
= 0;
831 int do_spin_tx_lock
= 1;
833 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
834 dev
->name
, __func__
, __LINE__
);
836 /* A buffer with no data will be dropped */
837 if (unlikely(skb
->len
<= 0)) {
838 vxge_debug_tx(VXGE_ERR
,
839 "%s: Buffer has no data..", dev
->name
);
844 vdev
= (struct vxgedev
*)netdev_priv(dev
);
846 if (unlikely(!is_vxge_card_up(vdev
))) {
847 vxge_debug_tx(VXGE_ERR
,
848 "%s: vdev not initialized", dev
->name
);
853 if (vdev
->config
.addr_learn_en
) {
854 vpath_no
= vxge_learn_mac(vdev
, skb
->data
+ ETH_ALEN
);
855 if (vpath_no
== -EPERM
) {
856 vxge_debug_tx(VXGE_ERR
,
857 "%s: Failed to store the mac address",
864 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
)
865 vpath_no
= skb_get_queue_mapping(skb
);
866 else if (vdev
->config
.tx_steering_type
== TX_PORT_STEERING
)
867 vpath_no
= vxge_get_vpath_no(vdev
, skb
, &do_spin_tx_lock
);
869 vxge_debug_tx(VXGE_TRACE
, "%s: vpath_no= %d", dev
->name
, vpath_no
);
871 if (vpath_no
>= vdev
->no_of_vpath
)
874 fifo
= &vdev
->vpaths
[vpath_no
].fifo
;
875 fifo_hw
= fifo
->handle
;
878 spin_lock_irqsave(&fifo
->tx_lock
, flags
);
880 if (unlikely(!spin_trylock_irqsave(&fifo
->tx_lock
, flags
)))
881 return NETDEV_TX_LOCKED
;
884 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
) {
885 if (netif_subqueue_stopped(dev
, skb
)) {
886 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
887 return NETDEV_TX_BUSY
;
889 } else if (unlikely(fifo
->queue_state
== VPATH_QUEUE_STOP
)) {
890 if (netif_queue_stopped(dev
)) {
891 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
892 return NETDEV_TX_BUSY
;
895 avail
= vxge_hw_fifo_free_txdl_count_get(fifo_hw
);
897 vxge_debug_tx(VXGE_ERR
,
898 "%s: No free TXDs available", dev
->name
);
899 fifo
->stats
.txd_not_free
++;
900 vxge_stop_tx_queue(fifo
);
904 /* Last TXD? Stop tx queue to avoid dropping packets. TX
905 * completion will resume the queue.
908 vxge_stop_tx_queue(fifo
);
910 status
= vxge_hw_fifo_txdl_reserve(fifo_hw
, &dtr
, &dtr_priv
);
911 if (unlikely(status
!= VXGE_HW_OK
)) {
912 vxge_debug_tx(VXGE_ERR
,
913 "%s: Out of descriptors .", dev
->name
);
914 fifo
->stats
.txd_out_of_desc
++;
915 vxge_stop_tx_queue(fifo
);
919 vxge_debug_tx(VXGE_TRACE
,
920 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
921 dev
->name
, __func__
, __LINE__
,
922 fifo_hw
, dtr
, dtr_priv
);
924 if (vdev
->vlgrp
&& vlan_tx_tag_present(skb
)) {
925 u16 vlan_tag
= vlan_tx_tag_get(skb
);
926 vxge_hw_fifo_txdl_vlan_set(dtr
, vlan_tag
);
929 first_frg_len
= skb_headlen(skb
);
931 dma_pointer
= pci_map_single(fifo
->pdev
, skb
->data
, first_frg_len
,
934 if (unlikely(pci_dma_mapping_error(fifo
->pdev
, dma_pointer
))) {
935 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
936 vxge_stop_tx_queue(fifo
);
937 fifo
->stats
.pci_map_fail
++;
941 txdl_priv
= vxge_hw_fifo_txdl_private_get(dtr
);
942 txdl_priv
->skb
= skb
;
943 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
945 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
946 vxge_debug_tx(VXGE_TRACE
,
947 "%s: %s:%d skb = %p txdl_priv = %p "
948 "frag_cnt = %d dma_pointer = 0x%llx", dev
->name
,
949 __func__
, __LINE__
, skb
, txdl_priv
,
950 frg_cnt
, (unsigned long long)dma_pointer
);
952 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
955 frag
= &skb_shinfo(skb
)->frags
[0];
956 for (i
= 0; i
< frg_cnt
; i
++) {
957 /* ignore 0 length fragment */
962 (u64
)pci_map_page(fifo
->pdev
, frag
->page
,
963 frag
->page_offset
, frag
->size
,
966 if (unlikely(pci_dma_mapping_error(fifo
->pdev
, dma_pointer
)))
968 vxge_debug_tx(VXGE_TRACE
,
969 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
970 dev
->name
, __func__
, __LINE__
, i
,
971 (unsigned long long)dma_pointer
);
973 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
974 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
979 offload_type
= vxge_offload_type(skb
);
981 if (offload_type
& (SKB_GSO_TCPV4
| SKB_GSO_TCPV6
)) {
983 int mss
= vxge_tcp_mss(skb
);
985 vxge_debug_tx(VXGE_TRACE
,
986 "%s: %s:%d mss = %d",
987 dev
->name
, __func__
, __LINE__
, mss
);
988 vxge_hw_fifo_txdl_mss_set(dtr
, mss
);
990 vxge_assert(skb
->len
<=
991 dev
->mtu
+ VXGE_HW_MAC_HEADER_MAX_SIZE
);
997 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
998 vxge_hw_fifo_txdl_cksum_set_bits(dtr
,
999 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN
|
1000 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN
|
1001 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN
);
1003 vxge_hw_fifo_txdl_post(fifo_hw
, dtr
);
1005 dev
->trans_start
= jiffies
; /* NETIF_F_LLTX driver :( */
1007 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
1009 VXGE_COMPLETE_VPATH_TX(fifo
);
1010 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
1011 dev
->name
, __func__
, __LINE__
);
1012 return NETDEV_TX_OK
;
1015 vxge_debug_tx(VXGE_TRACE
, "%s: pci_map_page failed", dev
->name
);
1019 frag
= &skb_shinfo(skb
)->frags
[0];
1021 pci_unmap_single(fifo
->pdev
, txdl_priv
->dma_buffers
[j
++],
1022 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1024 for (; j
< i
; j
++) {
1025 pci_unmap_page(fifo
->pdev
, txdl_priv
->dma_buffers
[j
],
1026 frag
->size
, PCI_DMA_TODEVICE
);
1030 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
1033 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
1034 VXGE_COMPLETE_VPATH_TX(fifo
);
1036 return NETDEV_TX_OK
;
1042 * Function will be called by hw function to abort all outstanding receive
1046 vxge_rx_term(void *dtrh
, enum vxge_hw_rxd_state state
, void *userdata
)
1048 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
1049 struct vxge_rx_priv
*rx_priv
=
1050 vxge_hw_ring_rxd_private_get(dtrh
);
1052 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
1053 ring
->ndev
->name
, __func__
, __LINE__
);
1054 if (state
!= VXGE_HW_RXD_STATE_POSTED
)
1057 pci_unmap_single(ring
->pdev
, rx_priv
->data_dma
,
1058 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
1060 dev_kfree_skb(rx_priv
->skb
);
1061 rx_priv
->skb_data
= NULL
;
1063 vxge_debug_entryexit(VXGE_TRACE
,
1064 "%s: %s:%d Exiting...",
1065 ring
->ndev
->name
, __func__
, __LINE__
);
1071 * Function will be called to abort all outstanding tx descriptors
1074 vxge_tx_term(void *dtrh
, enum vxge_hw_txdl_state state
, void *userdata
)
1076 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
1078 int i
= 0, j
, frg_cnt
;
1079 struct vxge_tx_priv
*txd_priv
= vxge_hw_fifo_txdl_private_get(dtrh
);
1080 struct sk_buff
*skb
= txd_priv
->skb
;
1082 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1084 if (state
!= VXGE_HW_TXDL_STATE_POSTED
)
1087 /* check skb validity */
1089 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
1090 frag
= &skb_shinfo(skb
)->frags
[0];
1092 /* for unfragmented skb */
1093 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
1094 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1096 for (j
= 0; j
< frg_cnt
; j
++) {
1097 pci_unmap_page(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
1098 frag
->size
, PCI_DMA_TODEVICE
);
1104 vxge_debug_entryexit(VXGE_TRACE
,
1105 "%s:%d Exiting...", __func__
, __LINE__
);
1109 * vxge_set_multicast
1110 * @dev: pointer to the device structure
1112 * Entry point for multicast address enable/disable
1113 * This function is a driver entry point which gets called by the kernel
1114 * whenever multicast addresses must be enabled/disabled. This also gets
1115 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1116 * determine, if multicast address must be enabled or if promiscuous mode
1117 * is to be disabled etc.
1119 static void vxge_set_multicast(struct net_device
*dev
)
1121 struct netdev_hw_addr
*ha
;
1122 struct vxgedev
*vdev
;
1123 int i
, mcast_cnt
= 0;
1124 struct __vxge_hw_device
*hldev
;
1125 enum vxge_hw_status status
= VXGE_HW_OK
;
1126 struct macInfo mac_info
;
1128 struct vxge_mac_addrs
*mac_entry
;
1129 struct list_head
*list_head
;
1130 struct list_head
*entry
, *next
;
1131 u8
*mac_address
= NULL
;
1133 vxge_debug_entryexit(VXGE_TRACE
,
1134 "%s:%d", __func__
, __LINE__
);
1136 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1137 hldev
= (struct __vxge_hw_device
*)vdev
->devh
;
1139 if (unlikely(!is_vxge_card_up(vdev
)))
1142 if ((dev
->flags
& IFF_ALLMULTI
) && (!vdev
->all_multi_flg
)) {
1143 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1144 vxge_assert(vdev
->vpaths
[i
].is_open
);
1145 status
= vxge_hw_vpath_mcast_enable(
1146 vdev
->vpaths
[i
].handle
);
1147 vdev
->all_multi_flg
= 1;
1149 } else if ((dev
->flags
& IFF_ALLMULTI
) && (vdev
->all_multi_flg
)) {
1150 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1151 vxge_assert(vdev
->vpaths
[i
].is_open
);
1152 status
= vxge_hw_vpath_mcast_disable(
1153 vdev
->vpaths
[i
].handle
);
1154 vdev
->all_multi_flg
= 1;
1158 if (status
!= VXGE_HW_OK
)
1159 vxge_debug_init(VXGE_ERR
,
1160 "failed to %s multicast, status %d",
1161 dev
->flags
& IFF_ALLMULTI
?
1162 "enable" : "disable", status
);
1164 if (!vdev
->config
.addr_learn_en
) {
1165 if (dev
->flags
& IFF_PROMISC
) {
1166 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1167 vxge_assert(vdev
->vpaths
[i
].is_open
);
1168 status
= vxge_hw_vpath_promisc_enable(
1169 vdev
->vpaths
[i
].handle
);
1172 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1173 vxge_assert(vdev
->vpaths
[i
].is_open
);
1174 status
= vxge_hw_vpath_promisc_disable(
1175 vdev
->vpaths
[i
].handle
);
1180 memset(&mac_info
, 0, sizeof(struct macInfo
));
1181 /* Update individual M_CAST address list */
1182 if ((!vdev
->all_multi_flg
) && netdev_mc_count(dev
)) {
1184 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1185 list_head
= &vdev
->vpaths
[0].mac_addr_list
;
1186 if ((netdev_mc_count(dev
) +
1187 (vdev
->vpaths
[0].mac_addr_cnt
- mcast_cnt
)) >
1188 vdev
->vpaths
[0].max_mac_addr_cnt
)
1189 goto _set_all_mcast
;
1191 /* Delete previous MC's */
1192 for (i
= 0; i
< mcast_cnt
; i
++) {
1193 if (!list_empty(list_head
))
1194 mac_entry
= (struct vxge_mac_addrs
*)
1195 list_first_entry(list_head
,
1196 struct vxge_mac_addrs
,
1199 list_for_each_safe(entry
, next
, list_head
) {
1201 mac_entry
= (struct vxge_mac_addrs
*) entry
;
1202 /* Copy the mac address to delete */
1203 mac_address
= (u8
*)&mac_entry
->macaddr
;
1204 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1206 /* Is this a multicast address */
1207 if (0x01 & mac_info
.macaddr
[0]) {
1208 for (vpath_idx
= 0; vpath_idx
<
1211 mac_info
.vpath_no
= vpath_idx
;
1212 status
= vxge_del_mac_addr(
1221 netdev_for_each_mc_addr(ha
, dev
) {
1222 memcpy(mac_info
.macaddr
, ha
->addr
, ETH_ALEN
);
1223 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1225 mac_info
.vpath_no
= vpath_idx
;
1226 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1227 status
= vxge_add_mac_addr(vdev
, &mac_info
);
1228 if (status
!= VXGE_HW_OK
) {
1229 vxge_debug_init(VXGE_ERR
,
1230 "%s:%d Setting individual"
1231 "multicast address failed",
1232 __func__
, __LINE__
);
1233 goto _set_all_mcast
;
1240 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1241 /* Delete previous MC's */
1242 for (i
= 0; i
< mcast_cnt
; i
++) {
1244 list_for_each_safe(entry
, next
, list_head
) {
1246 mac_entry
= (struct vxge_mac_addrs
*) entry
;
1247 /* Copy the mac address to delete */
1248 mac_address
= (u8
*)&mac_entry
->macaddr
;
1249 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1251 /* Is this a multicast address */
1252 if (0x01 & mac_info
.macaddr
[0])
1256 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1258 mac_info
.vpath_no
= vpath_idx
;
1259 status
= vxge_del_mac_addr(vdev
, &mac_info
);
1263 /* Enable all multicast */
1264 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1265 vxge_assert(vdev
->vpaths
[i
].is_open
);
1266 status
= vxge_hw_vpath_mcast_enable(
1267 vdev
->vpaths
[i
].handle
);
1268 if (status
!= VXGE_HW_OK
) {
1269 vxge_debug_init(VXGE_ERR
,
1270 "%s:%d Enabling all multicasts failed",
1271 __func__
, __LINE__
);
1273 vdev
->all_multi_flg
= 1;
1275 dev
->flags
|= IFF_ALLMULTI
;
1278 vxge_debug_entryexit(VXGE_TRACE
,
1279 "%s:%d Exiting...", __func__
, __LINE__
);
1284 * @dev: pointer to the device structure
1286 * Update entry "0" (default MAC addr)
1288 static int vxge_set_mac_addr(struct net_device
*dev
, void *p
)
1290 struct sockaddr
*addr
= p
;
1291 struct vxgedev
*vdev
;
1292 struct __vxge_hw_device
*hldev
;
1293 enum vxge_hw_status status
= VXGE_HW_OK
;
1294 struct macInfo mac_info_new
, mac_info_old
;
1297 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1299 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1302 if (!is_valid_ether_addr(addr
->sa_data
))
1305 memset(&mac_info_new
, 0, sizeof(struct macInfo
));
1306 memset(&mac_info_old
, 0, sizeof(struct macInfo
));
1308 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d Exiting...",
1309 __func__
, __LINE__
);
1311 /* Get the old address */
1312 memcpy(mac_info_old
.macaddr
, dev
->dev_addr
, dev
->addr_len
);
1314 /* Copy the new address */
1315 memcpy(mac_info_new
.macaddr
, addr
->sa_data
, dev
->addr_len
);
1317 /* First delete the old mac address from all the vpaths
1318 as we can't specify the index while adding new mac address */
1319 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1320 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vpath_idx
];
1321 if (!vpath
->is_open
) {
1322 /* This can happen when this interface is added/removed
1323 to the bonding interface. Delete this station address
1324 from the linked list */
1325 vxge_mac_list_del(vpath
, &mac_info_old
);
1327 /* Add this new address to the linked list
1328 for later restoring */
1329 vxge_mac_list_add(vpath
, &mac_info_new
);
1333 /* Delete the station address */
1334 mac_info_old
.vpath_no
= vpath_idx
;
1335 status
= vxge_del_mac_addr(vdev
, &mac_info_old
);
1338 if (unlikely(!is_vxge_card_up(vdev
))) {
1339 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1343 /* Set this mac address to all the vpaths */
1344 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1345 mac_info_new
.vpath_no
= vpath_idx
;
1346 mac_info_new
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1347 status
= vxge_add_mac_addr(vdev
, &mac_info_new
);
1348 if (status
!= VXGE_HW_OK
)
1352 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1358 * vxge_vpath_intr_enable
1359 * @vdev: pointer to vdev
1360 * @vp_id: vpath for which to enable the interrupts
1362 * Enables the interrupts for the vpath
1364 void vxge_vpath_intr_enable(struct vxgedev
*vdev
, int vp_id
)
1366 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1368 int tim_msix_id
[4] = {0, 1, 0, 0};
1369 int alarm_msix_id
= VXGE_ALARM_MSIX_ID
;
1371 vxge_hw_vpath_intr_enable(vpath
->handle
);
1373 if (vdev
->config
.intr_type
== INTA
)
1374 vxge_hw_vpath_inta_unmask_tx_rx(vpath
->handle
);
1376 vxge_hw_vpath_msix_set(vpath
->handle
, tim_msix_id
,
1379 msix_id
= vpath
->device_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1380 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
);
1381 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
+ 1);
1383 /* enable the alarm vector */
1384 msix_id
= (vpath
->handle
->vpath
->hldev
->first_vp_id
*
1385 VXGE_HW_VPATH_MSIX_ACTIVE
) + alarm_msix_id
;
1386 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
);
1391 * vxge_vpath_intr_disable
1392 * @vdev: pointer to vdev
1393 * @vp_id: vpath for which to disable the interrupts
1395 * Disables the interrupts for the vpath
1397 void vxge_vpath_intr_disable(struct vxgedev
*vdev
, int vp_id
)
1399 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1402 vxge_hw_vpath_intr_disable(vpath
->handle
);
1404 if (vdev
->config
.intr_type
== INTA
)
1405 vxge_hw_vpath_inta_mask_tx_rx(vpath
->handle
);
1407 msix_id
= vpath
->device_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1408 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1409 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
+ 1);
1411 /* disable the alarm vector */
1412 msix_id
= (vpath
->handle
->vpath
->hldev
->first_vp_id
*
1413 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
1414 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1420 * @vdev: pointer to vdev
1421 * @vp_id: vpath to reset
1425 static int vxge_reset_vpath(struct vxgedev
*vdev
, int vp_id
)
1427 enum vxge_hw_status status
= VXGE_HW_OK
;
1430 /* check if device is down already */
1431 if (unlikely(!is_vxge_card_up(vdev
)))
1434 /* is device reset already scheduled */
1435 if (test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1438 if (vdev
->vpaths
[vp_id
].handle
) {
1439 if (vxge_hw_vpath_reset(vdev
->vpaths
[vp_id
].handle
)
1441 if (is_vxge_card_up(vdev
) &&
1442 vxge_hw_vpath_recover_from_reset(
1443 vdev
->vpaths
[vp_id
].handle
)
1445 vxge_debug_init(VXGE_ERR
,
1446 "vxge_hw_vpath_recover_from_reset"
1447 "failed for vpath:%d", vp_id
);
1451 vxge_debug_init(VXGE_ERR
,
1452 "vxge_hw_vpath_reset failed for"
1457 return VXGE_HW_FAIL
;
1459 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[vp_id
]);
1460 vxge_restore_vpath_vid_table(&vdev
->vpaths
[vp_id
]);
1462 /* Enable all broadcast */
1463 vxge_hw_vpath_bcast_enable(vdev
->vpaths
[vp_id
].handle
);
1465 /* Enable the interrupts */
1466 vxge_vpath_intr_enable(vdev
, vp_id
);
1470 /* Enable the flow of traffic through the vpath */
1471 vxge_hw_vpath_enable(vdev
->vpaths
[vp_id
].handle
);
1474 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[vp_id
].handle
);
1475 vdev
->vpaths
[vp_id
].ring
.last_status
= VXGE_HW_OK
;
1477 /* Vpath reset done */
1478 clear_bit(vp_id
, &vdev
->vp_reset
);
1480 /* Start the vpath queue */
1481 vxge_wake_tx_queue(&vdev
->vpaths
[vp_id
].fifo
, NULL
);
1486 static int do_vxge_reset(struct vxgedev
*vdev
, int event
)
1488 enum vxge_hw_status status
;
1489 int ret
= 0, vp_id
, i
;
1491 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1493 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
)) {
1494 /* check if device is down already */
1495 if (unlikely(!is_vxge_card_up(vdev
)))
1498 /* is reset already scheduled */
1499 if (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1503 if (event
== VXGE_LL_FULL_RESET
) {
1504 /* wait for all the vpath reset to complete */
1505 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1506 while (test_bit(vp_id
, &vdev
->vp_reset
))
1510 /* if execution mode is set to debug, don't reset the adapter */
1511 if (unlikely(vdev
->exec_mode
)) {
1512 vxge_debug_init(VXGE_ERR
,
1513 "%s: execution mode is debug, returning..",
1515 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1516 vxge_stop_all_tx_queue(vdev
);
1521 if (event
== VXGE_LL_FULL_RESET
) {
1522 vxge_hw_device_intr_disable(vdev
->devh
);
1524 switch (vdev
->cric_err_event
) {
1525 case VXGE_HW_EVENT_UNKNOWN
:
1526 vxge_stop_all_tx_queue(vdev
);
1527 vxge_debug_init(VXGE_ERR
,
1528 "fatal: %s: Disabling device due to"
1533 case VXGE_HW_EVENT_RESET_START
:
1535 case VXGE_HW_EVENT_RESET_COMPLETE
:
1536 case VXGE_HW_EVENT_LINK_DOWN
:
1537 case VXGE_HW_EVENT_LINK_UP
:
1538 case VXGE_HW_EVENT_ALARM_CLEARED
:
1539 case VXGE_HW_EVENT_ECCERR
:
1540 case VXGE_HW_EVENT_MRPCIM_ECCERR
:
1543 case VXGE_HW_EVENT_FIFO_ERR
:
1544 case VXGE_HW_EVENT_VPATH_ERR
:
1546 case VXGE_HW_EVENT_CRITICAL_ERR
:
1547 vxge_stop_all_tx_queue(vdev
);
1548 vxge_debug_init(VXGE_ERR
,
1549 "fatal: %s: Disabling device due to"
1552 /* SOP or device reset required */
1553 /* This event is not currently used */
1556 case VXGE_HW_EVENT_SERR
:
1557 vxge_stop_all_tx_queue(vdev
);
1558 vxge_debug_init(VXGE_ERR
,
1559 "fatal: %s: Disabling device due to"
1564 case VXGE_HW_EVENT_SRPCIM_SERR
:
1565 case VXGE_HW_EVENT_MRPCIM_SERR
:
1568 case VXGE_HW_EVENT_SLOT_FREEZE
:
1569 vxge_stop_all_tx_queue(vdev
);
1570 vxge_debug_init(VXGE_ERR
,
1571 "fatal: %s: Disabling device due to"
1582 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
))
1583 vxge_stop_all_tx_queue(vdev
);
1585 if (event
== VXGE_LL_FULL_RESET
) {
1586 status
= vxge_reset_all_vpaths(vdev
);
1587 if (status
!= VXGE_HW_OK
) {
1588 vxge_debug_init(VXGE_ERR
,
1589 "fatal: %s: can not reset vpaths",
1596 if (event
== VXGE_LL_COMPL_RESET
) {
1597 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1598 if (vdev
->vpaths
[i
].handle
) {
1599 if (vxge_hw_vpath_recover_from_reset(
1600 vdev
->vpaths
[i
].handle
)
1602 vxge_debug_init(VXGE_ERR
,
1603 "vxge_hw_vpath_recover_"
1604 "from_reset failed for vpath: "
1610 vxge_debug_init(VXGE_ERR
,
1611 "vxge_hw_vpath_reset failed for "
1618 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
)) {
1619 /* Reprogram the DA table with populated mac addresses */
1620 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1621 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[vp_id
]);
1622 vxge_restore_vpath_vid_table(&vdev
->vpaths
[vp_id
]);
1625 /* enable vpath interrupts */
1626 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1627 vxge_vpath_intr_enable(vdev
, i
);
1629 vxge_hw_device_intr_enable(vdev
->devh
);
1633 /* Indicate card up */
1634 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1636 /* Get the traffic to flow through the vpaths */
1637 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1638 vxge_hw_vpath_enable(vdev
->vpaths
[i
].handle
);
1640 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[i
].handle
);
1643 vxge_wake_all_tx_queue(vdev
);
1647 vxge_debug_entryexit(VXGE_TRACE
,
1648 "%s:%d Exiting...", __func__
, __LINE__
);
1650 /* Indicate reset done */
1651 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
))
1652 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
1658 * @vdev: pointer to ll device
1660 * driver may reset the chip on events of serr, eccerr, etc
1662 int vxge_reset(struct vxgedev
*vdev
)
1664 do_vxge_reset(vdev
, VXGE_LL_FULL_RESET
);
1669 * vxge_poll - Receive handler when Receive Polling is used.
1670 * @dev: pointer to the device structure.
1671 * @budget: Number of packets budgeted to be processed in this iteration.
1673 * This function comes into picture only if Receive side is being handled
1674 * through polling (called NAPI in linux). It mostly does what the normal
1675 * Rx interrupt handler does in terms of descriptor and packet processing
1676 * but not in an interrupt context. Also it will process a specified number
1677 * of packets at most in one iteration. This value is passed down by the
1678 * kernel as the function argument 'budget'.
1680 static int vxge_poll_msix(struct napi_struct
*napi
, int budget
)
1682 struct vxge_ring
*ring
=
1683 container_of(napi
, struct vxge_ring
, napi
);
1684 int budget_org
= budget
;
1685 ring
->budget
= budget
;
1687 vxge_hw_vpath_poll_rx(ring
->handle
);
1689 if (ring
->pkts_processed
< budget_org
) {
1690 napi_complete(napi
);
1691 /* Re enable the Rx interrupts for the vpath */
1692 vxge_hw_channel_msix_unmask(
1693 (struct __vxge_hw_channel
*)ring
->handle
,
1694 ring
->rx_vector_no
);
1697 return ring
->pkts_processed
;
1700 static int vxge_poll_inta(struct napi_struct
*napi
, int budget
)
1702 struct vxgedev
*vdev
= container_of(napi
, struct vxgedev
, napi
);
1703 int pkts_processed
= 0;
1705 int budget_org
= budget
;
1706 struct vxge_ring
*ring
;
1708 struct __vxge_hw_device
*hldev
= (struct __vxge_hw_device
*)
1709 pci_get_drvdata(vdev
->pdev
);
1711 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1712 ring
= &vdev
->vpaths
[i
].ring
;
1713 ring
->budget
= budget
;
1714 vxge_hw_vpath_poll_rx(ring
->handle
);
1715 pkts_processed
+= ring
->pkts_processed
;
1716 budget
-= ring
->pkts_processed
;
1721 VXGE_COMPLETE_ALL_TX(vdev
);
1723 if (pkts_processed
< budget_org
) {
1724 napi_complete(napi
);
1725 /* Re enable the Rx interrupts for the ring */
1726 vxge_hw_device_unmask_all(hldev
);
1727 vxge_hw_device_flush_io(hldev
);
1730 return pkts_processed
;
1733 #ifdef CONFIG_NET_POLL_CONTROLLER
1735 * vxge_netpoll - netpoll event handler entry point
1736 * @dev : pointer to the device structure.
1738 * This function will be called by upper layer to check for events on the
1739 * interface in situations where interrupts are disabled. It is used for
1740 * specific in-kernel networking tasks, such as remote consoles and kernel
1741 * debugging over the network (example netdump in RedHat).
1743 static void vxge_netpoll(struct net_device
*dev
)
1745 struct __vxge_hw_device
*hldev
;
1746 struct vxgedev
*vdev
;
1748 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1749 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
1751 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1753 if (pci_channel_offline(vdev
->pdev
))
1756 disable_irq(dev
->irq
);
1757 vxge_hw_device_clear_tx_rx(hldev
);
1759 vxge_hw_device_clear_tx_rx(hldev
);
1760 VXGE_COMPLETE_ALL_RX(vdev
);
1761 VXGE_COMPLETE_ALL_TX(vdev
);
1763 enable_irq(dev
->irq
);
1765 vxge_debug_entryexit(VXGE_TRACE
,
1766 "%s:%d Exiting...", __func__
, __LINE__
);
1770 /* RTH configuration */
1771 static enum vxge_hw_status
vxge_rth_configure(struct vxgedev
*vdev
)
1773 enum vxge_hw_status status
= VXGE_HW_OK
;
1774 struct vxge_hw_rth_hash_types hash_types
;
1775 u8 itable
[256] = {0}; /* indirection table */
1776 u8 mtable
[256] = {0}; /* CPU to vpath mapping */
1781 * - itable with bucket numbers
1782 * - mtable with bucket-to-vpath mapping
1784 for (index
= 0; index
< (1 << vdev
->config
.rth_bkt_sz
); index
++) {
1785 itable
[index
] = index
;
1786 mtable
[index
] = index
% vdev
->no_of_vpath
;
1789 /* Fill RTH hash types */
1790 hash_types
.hash_type_tcpipv4_en
= vdev
->config
.rth_hash_type_tcpipv4
;
1791 hash_types
.hash_type_ipv4_en
= vdev
->config
.rth_hash_type_ipv4
;
1792 hash_types
.hash_type_tcpipv6_en
= vdev
->config
.rth_hash_type_tcpipv6
;
1793 hash_types
.hash_type_ipv6_en
= vdev
->config
.rth_hash_type_ipv6
;
1794 hash_types
.hash_type_tcpipv6ex_en
=
1795 vdev
->config
.rth_hash_type_tcpipv6ex
;
1796 hash_types
.hash_type_ipv6ex_en
= vdev
->config
.rth_hash_type_ipv6ex
;
1798 /* set indirection table, bucket-to-vpath mapping */
1799 status
= vxge_hw_vpath_rts_rth_itable_set(vdev
->vp_handles
,
1802 vdev
->config
.rth_bkt_sz
);
1803 if (status
!= VXGE_HW_OK
) {
1804 vxge_debug_init(VXGE_ERR
,
1805 "RTH indirection table configuration failed "
1806 "for vpath:%d", vdev
->vpaths
[0].device_id
);
1811 * Because the itable_set() method uses the active_table field
1812 * for the target virtual path the RTH config should be updated
1813 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1814 * when steering frames.
1816 for (index
= 0; index
< vdev
->no_of_vpath
; index
++) {
1817 status
= vxge_hw_vpath_rts_rth_set(
1818 vdev
->vpaths
[index
].handle
,
1819 vdev
->config
.rth_algorithm
,
1821 vdev
->config
.rth_bkt_sz
);
1823 if (status
!= VXGE_HW_OK
) {
1824 vxge_debug_init(VXGE_ERR
,
1825 "RTH configuration failed for vpath:%d",
1826 vdev
->vpaths
[index
].device_id
);
1834 int vxge_mac_list_add(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1836 struct vxge_mac_addrs
*new_mac_entry
;
1837 u8
*mac_address
= NULL
;
1839 if (vpath
->mac_addr_cnt
>= VXGE_MAX_LEARN_MAC_ADDR_CNT
)
1842 new_mac_entry
= kzalloc(sizeof(struct vxge_mac_addrs
), GFP_ATOMIC
);
1843 if (!new_mac_entry
) {
1844 vxge_debug_mem(VXGE_ERR
,
1845 "%s: memory allocation failed",
1850 list_add(&new_mac_entry
->item
, &vpath
->mac_addr_list
);
1852 /* Copy the new mac address to the list */
1853 mac_address
= (u8
*)&new_mac_entry
->macaddr
;
1854 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
1856 new_mac_entry
->state
= mac
->state
;
1857 vpath
->mac_addr_cnt
++;
1859 /* Is this a multicast address */
1860 if (0x01 & mac
->macaddr
[0])
1861 vpath
->mcast_addr_cnt
++;
1866 /* Add a mac address to DA table */
1867 enum vxge_hw_status
vxge_add_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
1869 enum vxge_hw_status status
= VXGE_HW_OK
;
1870 struct vxge_vpath
*vpath
;
1871 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode
;
1873 if (0x01 & mac
->macaddr
[0]) /* multicast address */
1874 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
;
1876 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE
;
1878 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
1879 status
= vxge_hw_vpath_mac_addr_add(vpath
->handle
, mac
->macaddr
,
1880 mac
->macmask
, duplicate_mode
);
1881 if (status
!= VXGE_HW_OK
) {
1882 vxge_debug_init(VXGE_ERR
,
1883 "DA config add entry failed for vpath:%d",
1886 if (FALSE
== vxge_mac_list_add(vpath
, mac
))
1892 int vxge_mac_list_del(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1894 struct list_head
*entry
, *next
;
1896 u8
*mac_address
= (u8
*) (&del_mac
);
1898 /* Copy the mac address to delete from the list */
1899 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
1901 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1902 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
) {
1904 kfree((struct vxge_mac_addrs
*)entry
);
1905 vpath
->mac_addr_cnt
--;
1907 /* Is this a multicast address */
1908 if (0x01 & mac
->macaddr
[0])
1909 vpath
->mcast_addr_cnt
--;
1916 /* delete a mac address from DA table */
1917 enum vxge_hw_status
vxge_del_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
1919 enum vxge_hw_status status
= VXGE_HW_OK
;
1920 struct vxge_vpath
*vpath
;
1922 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
1923 status
= vxge_hw_vpath_mac_addr_delete(vpath
->handle
, mac
->macaddr
,
1925 if (status
!= VXGE_HW_OK
) {
1926 vxge_debug_init(VXGE_ERR
,
1927 "DA config delete entry failed for vpath:%d",
1930 vxge_mac_list_del(vpath
, mac
);
1934 /* list all mac addresses from DA table */
1936 static vxge_search_mac_addr_in_da_table(struct vxge_vpath
*vpath
,
1937 struct macInfo
*mac
)
1939 enum vxge_hw_status status
= VXGE_HW_OK
;
1940 unsigned char macmask
[ETH_ALEN
];
1941 unsigned char macaddr
[ETH_ALEN
];
1943 status
= vxge_hw_vpath_mac_addr_get(vpath
->handle
,
1945 if (status
!= VXGE_HW_OK
) {
1946 vxge_debug_init(VXGE_ERR
,
1947 "DA config list entry failed for vpath:%d",
1952 while (memcmp(mac
->macaddr
, macaddr
, ETH_ALEN
)) {
1954 status
= vxge_hw_vpath_mac_addr_get_next(vpath
->handle
,
1956 if (status
!= VXGE_HW_OK
)
1963 /* Store all vlan ids from the list to the vid table */
1964 enum vxge_hw_status
vxge_restore_vpath_vid_table(struct vxge_vpath
*vpath
)
1966 enum vxge_hw_status status
= VXGE_HW_OK
;
1967 struct vxgedev
*vdev
= vpath
->vdev
;
1970 if (vdev
->vlgrp
&& vpath
->is_open
) {
1972 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
1973 if (!vlan_group_get_device(vdev
->vlgrp
, vid
))
1975 /* Add these vlan to the vid table */
1976 status
= vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
1983 /* Store all mac addresses from the list to the DA table */
1984 enum vxge_hw_status
vxge_restore_vpath_mac_addr(struct vxge_vpath
*vpath
)
1986 enum vxge_hw_status status
= VXGE_HW_OK
;
1987 struct macInfo mac_info
;
1988 u8
*mac_address
= NULL
;
1989 struct list_head
*entry
, *next
;
1991 memset(&mac_info
, 0, sizeof(struct macInfo
));
1993 if (vpath
->is_open
) {
1995 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1998 ((struct vxge_mac_addrs
*)entry
)->macaddr
;
1999 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
2000 ((struct vxge_mac_addrs
*)entry
)->state
=
2001 VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
2002 /* does this mac address already exist in da table? */
2003 status
= vxge_search_mac_addr_in_da_table(vpath
,
2005 if (status
!= VXGE_HW_OK
) {
2006 /* Add this mac address to the DA table */
2007 status
= vxge_hw_vpath_mac_addr_add(
2008 vpath
->handle
, mac_info
.macaddr
,
2010 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
);
2011 if (status
!= VXGE_HW_OK
) {
2012 vxge_debug_init(VXGE_ERR
,
2013 "DA add entry failed for vpath:%d",
2015 ((struct vxge_mac_addrs
*)entry
)->state
2016 = VXGE_LL_MAC_ADDR_IN_LIST
;
2026 enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
)
2029 enum vxge_hw_status status
= VXGE_HW_OK
;
2031 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2032 if (vdev
->vpaths
[i
].handle
) {
2033 if (vxge_hw_vpath_reset(vdev
->vpaths
[i
].handle
)
2035 if (is_vxge_card_up(vdev
) &&
2036 vxge_hw_vpath_recover_from_reset(
2037 vdev
->vpaths
[i
].handle
)
2039 vxge_debug_init(VXGE_ERR
,
2040 "vxge_hw_vpath_recover_"
2041 "from_reset failed for vpath: "
2046 vxge_debug_init(VXGE_ERR
,
2047 "vxge_hw_vpath_reset failed for "
2056 void vxge_close_vpaths(struct vxgedev
*vdev
, int index
)
2059 for (i
= index
; i
< vdev
->no_of_vpath
; i
++) {
2060 if (vdev
->vpaths
[i
].handle
&& vdev
->vpaths
[i
].is_open
) {
2061 vxge_hw_vpath_close(vdev
->vpaths
[i
].handle
);
2062 vdev
->stats
.vpaths_open
--;
2064 vdev
->vpaths
[i
].is_open
= 0;
2065 vdev
->vpaths
[i
].handle
= NULL
;
2070 int vxge_open_vpaths(struct vxgedev
*vdev
)
2072 enum vxge_hw_status status
;
2075 struct vxge_hw_vpath_attr attr
;
2077 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2078 vxge_assert(vdev
->vpaths
[i
].is_configured
);
2079 attr
.vp_id
= vdev
->vpaths
[i
].device_id
;
2080 attr
.fifo_attr
.callback
= vxge_xmit_compl
;
2081 attr
.fifo_attr
.txdl_term
= vxge_tx_term
;
2082 attr
.fifo_attr
.per_txdl_space
= sizeof(struct vxge_tx_priv
);
2083 attr
.fifo_attr
.userdata
= (void *)&vdev
->vpaths
[i
].fifo
;
2085 attr
.ring_attr
.callback
= vxge_rx_1b_compl
;
2086 attr
.ring_attr
.rxd_init
= vxge_rx_initial_replenish
;
2087 attr
.ring_attr
.rxd_term
= vxge_rx_term
;
2088 attr
.ring_attr
.per_rxd_space
= sizeof(struct vxge_rx_priv
);
2089 attr
.ring_attr
.userdata
= (void *)&vdev
->vpaths
[i
].ring
;
2091 vdev
->vpaths
[i
].ring
.ndev
= vdev
->ndev
;
2092 vdev
->vpaths
[i
].ring
.pdev
= vdev
->pdev
;
2093 status
= vxge_hw_vpath_open(vdev
->devh
, &attr
,
2094 &(vdev
->vpaths
[i
].handle
));
2095 if (status
== VXGE_HW_OK
) {
2096 vdev
->vpaths
[i
].fifo
.handle
=
2097 (struct __vxge_hw_fifo
*)attr
.fifo_attr
.userdata
;
2098 vdev
->vpaths
[i
].ring
.handle
=
2099 (struct __vxge_hw_ring
*)attr
.ring_attr
.userdata
;
2100 vdev
->vpaths
[i
].fifo
.tx_steering_type
=
2101 vdev
->config
.tx_steering_type
;
2102 vdev
->vpaths
[i
].fifo
.ndev
= vdev
->ndev
;
2103 vdev
->vpaths
[i
].fifo
.pdev
= vdev
->pdev
;
2104 vdev
->vpaths
[i
].fifo
.indicate_max_pkts
=
2105 vdev
->config
.fifo_indicate_max_pkts
;
2106 vdev
->vpaths
[i
].ring
.rx_vector_no
= 0;
2107 vdev
->vpaths
[i
].ring
.rx_csum
= vdev
->rx_csum
;
2108 vdev
->vpaths
[i
].is_open
= 1;
2109 vdev
->vp_handles
[i
] = vdev
->vpaths
[i
].handle
;
2110 vdev
->vpaths
[i
].ring
.gro_enable
=
2111 vdev
->config
.gro_enable
;
2112 vdev
->vpaths
[i
].ring
.vlan_tag_strip
=
2113 vdev
->vlan_tag_strip
;
2114 vdev
->stats
.vpaths_open
++;
2116 vdev
->stats
.vpath_open_fail
++;
2117 vxge_debug_init(VXGE_ERR
,
2118 "%s: vpath: %d failed to open "
2120 vdev
->ndev
->name
, vdev
->vpaths
[i
].device_id
,
2122 vxge_close_vpaths(vdev
, 0);
2127 ((struct __vxge_hw_vpath_handle
*)vdev
->vpaths
[i
].handle
)->
2129 vdev
->vpaths_deployed
|= vxge_mBIT(vp_id
);
2136 * @irq: the irq of the device.
2137 * @dev_id: a void pointer to the hldev structure of the Titan device
2138 * @ptregs: pointer to the registers pushed on the stack.
2140 * This function is the ISR handler of the device when napi is enabled. It
2141 * identifies the reason for the interrupt and calls the relevant service
2144 static irqreturn_t
vxge_isr_napi(int irq
, void *dev_id
)
2146 struct net_device
*dev
;
2147 struct __vxge_hw_device
*hldev
;
2149 enum vxge_hw_status status
;
2150 struct vxgedev
*vdev
= (struct vxgedev
*) dev_id
;;
2152 vxge_debug_intr(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
2155 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
2157 if (pci_channel_offline(vdev
->pdev
))
2160 if (unlikely(!is_vxge_card_up(vdev
)))
2163 status
= vxge_hw_device_begin_irq(hldev
, vdev
->exec_mode
,
2165 if (status
== VXGE_HW_OK
) {
2166 vxge_hw_device_mask_all(hldev
);
2169 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2170 vdev
->vpaths_deployed
>>
2171 (64 - VXGE_HW_MAX_VIRTUAL_PATHS
))) {
2173 vxge_hw_device_clear_tx_rx(hldev
);
2174 napi_schedule(&vdev
->napi
);
2175 vxge_debug_intr(VXGE_TRACE
,
2176 "%s:%d Exiting...", __func__
, __LINE__
);
2179 vxge_hw_device_unmask_all(hldev
);
2180 } else if (unlikely((status
== VXGE_HW_ERR_VPATH
) ||
2181 (status
== VXGE_HW_ERR_CRITICAL
) ||
2182 (status
== VXGE_HW_ERR_FIFO
))) {
2183 vxge_hw_device_mask_all(hldev
);
2184 vxge_hw_device_flush_io(hldev
);
2186 } else if (unlikely(status
== VXGE_HW_ERR_SLOT_FREEZE
))
2189 vxge_debug_intr(VXGE_TRACE
, "%s:%d Exiting...", __func__
, __LINE__
);
2193 #ifdef CONFIG_PCI_MSI
2196 vxge_tx_msix_handle(int irq
, void *dev_id
)
2198 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)dev_id
;
2200 VXGE_COMPLETE_VPATH_TX(fifo
);
2206 vxge_rx_msix_napi_handle(int irq
, void *dev_id
)
2208 struct vxge_ring
*ring
= (struct vxge_ring
*)dev_id
;
2210 /* MSIX_IDX for Rx is 1 */
2211 vxge_hw_channel_msix_mask((struct __vxge_hw_channel
*)ring
->handle
,
2212 ring
->rx_vector_no
);
2214 napi_schedule(&ring
->napi
);
2219 vxge_alarm_msix_handle(int irq
, void *dev_id
)
2222 enum vxge_hw_status status
;
2223 struct vxge_vpath
*vpath
= (struct vxge_vpath
*)dev_id
;
2224 struct vxgedev
*vdev
= vpath
->vdev
;
2225 int msix_id
= (vpath
->handle
->vpath
->vp_id
*
2226 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
2228 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2229 vxge_hw_vpath_msix_mask(vdev
->vpaths
[i
].handle
, msix_id
);
2231 status
= vxge_hw_vpath_alarm_process(vdev
->vpaths
[i
].handle
,
2233 if (status
== VXGE_HW_OK
) {
2235 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[i
].handle
,
2239 vxge_debug_intr(VXGE_ERR
,
2240 "%s: vxge_hw_vpath_alarm_process failed %x ",
2241 VXGE_DRIVER_NAME
, status
);
2246 static int vxge_alloc_msix(struct vxgedev
*vdev
)
2249 int msix_intr_vect
= 0, temp
;
2253 /* Tx/Rx MSIX Vectors count */
2254 vdev
->intr_cnt
= vdev
->no_of_vpath
* 2;
2256 /* Alarm MSIX Vectors count */
2259 vdev
->entries
= kzalloc(vdev
->intr_cnt
* sizeof(struct msix_entry
),
2261 if (!vdev
->entries
) {
2262 vxge_debug_init(VXGE_ERR
,
2263 "%s: memory allocation failed",
2266 goto alloc_entries_failed
;
2269 vdev
->vxge_entries
=
2270 kzalloc(vdev
->intr_cnt
* sizeof(struct vxge_msix_entry
),
2272 if (!vdev
->vxge_entries
) {
2273 vxge_debug_init(VXGE_ERR
, "%s: memory allocation failed",
2276 goto alloc_vxge_entries_failed
;
2279 for (i
= 0, j
= 0; i
< vdev
->no_of_vpath
; i
++) {
2281 msix_intr_vect
= i
* VXGE_HW_VPATH_MSIX_ACTIVE
;
2283 /* Initialize the fifo vector */
2284 vdev
->entries
[j
].entry
= msix_intr_vect
;
2285 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
;
2286 vdev
->vxge_entries
[j
].in_use
= 0;
2289 /* Initialize the ring vector */
2290 vdev
->entries
[j
].entry
= msix_intr_vect
+ 1;
2291 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
+ 1;
2292 vdev
->vxge_entries
[j
].in_use
= 0;
2296 /* Initialize the alarm vector */
2297 vdev
->entries
[j
].entry
= VXGE_ALARM_MSIX_ID
;
2298 vdev
->vxge_entries
[j
].entry
= VXGE_ALARM_MSIX_ID
;
2299 vdev
->vxge_entries
[j
].in_use
= 0;
2301 ret
= pci_enable_msix(vdev
->pdev
, vdev
->entries
, vdev
->intr_cnt
);
2304 vxge_debug_init(VXGE_ERR
,
2305 "%s: MSI-X enable failed for %d vectors, ret: %d",
2306 VXGE_DRIVER_NAME
, vdev
->intr_cnt
, ret
);
2307 if ((max_config_vpath
!= VXGE_USE_DEFAULT
) || (ret
< 3)) {
2309 goto enable_msix_failed
;
2312 kfree(vdev
->entries
);
2313 kfree(vdev
->vxge_entries
);
2314 vdev
->entries
= NULL
;
2315 vdev
->vxge_entries
= NULL
;
2316 /* Try with less no of vector by reducing no of vpaths count */
2318 vxge_close_vpaths(vdev
, temp
);
2319 vdev
->no_of_vpath
= temp
;
2321 } else if (ret
< 0) {
2323 goto enable_msix_failed
;
2328 kfree(vdev
->vxge_entries
);
2329 alloc_vxge_entries_failed
:
2330 kfree(vdev
->entries
);
2331 alloc_entries_failed
:
2335 static int vxge_enable_msix(struct vxgedev
*vdev
)
2339 /* 0 - Tx, 1 - Rx */
2340 int tim_msix_id
[4] = {0, 1, 0, 0};
2344 /* allocate msix vectors */
2345 ret
= vxge_alloc_msix(vdev
);
2347 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2349 /* If fifo or ring are not enabled
2350 the MSIX vector for that should be set to 0
2351 Hence initializeing this array to all 0s.
2353 vdev
->vpaths
[i
].ring
.rx_vector_no
=
2354 (vdev
->vpaths
[i
].device_id
*
2355 VXGE_HW_VPATH_MSIX_ACTIVE
) + 1;
2357 vxge_hw_vpath_msix_set(vdev
->vpaths
[i
].handle
,
2358 tim_msix_id
, VXGE_ALARM_MSIX_ID
);
2365 static void vxge_rem_msix_isr(struct vxgedev
*vdev
)
2369 for (intr_cnt
= 0; intr_cnt
< (vdev
->no_of_vpath
* 2 + 1);
2371 if (vdev
->vxge_entries
[intr_cnt
].in_use
) {
2372 synchronize_irq(vdev
->entries
[intr_cnt
].vector
);
2373 free_irq(vdev
->entries
[intr_cnt
].vector
,
2374 vdev
->vxge_entries
[intr_cnt
].arg
);
2375 vdev
->vxge_entries
[intr_cnt
].in_use
= 0;
2379 kfree(vdev
->entries
);
2380 kfree(vdev
->vxge_entries
);
2381 vdev
->entries
= NULL
;
2382 vdev
->vxge_entries
= NULL
;
2384 if (vdev
->config
.intr_type
== MSI_X
)
2385 pci_disable_msix(vdev
->pdev
);
2389 static void vxge_rem_isr(struct vxgedev
*vdev
)
2391 struct __vxge_hw_device
*hldev
;
2392 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2394 #ifdef CONFIG_PCI_MSI
2395 if (vdev
->config
.intr_type
== MSI_X
) {
2396 vxge_rem_msix_isr(vdev
);
2399 if (vdev
->config
.intr_type
== INTA
) {
2400 synchronize_irq(vdev
->pdev
->irq
);
2401 free_irq(vdev
->pdev
->irq
, vdev
);
2405 static int vxge_add_isr(struct vxgedev
*vdev
)
2408 #ifdef CONFIG_PCI_MSI
2409 int vp_idx
= 0, intr_idx
= 0, intr_cnt
= 0, msix_idx
= 0, irq_req
= 0;
2410 int pci_fun
= PCI_FUNC(vdev
->pdev
->devfn
);
2412 if (vdev
->config
.intr_type
== MSI_X
)
2413 ret
= vxge_enable_msix(vdev
);
2416 vxge_debug_init(VXGE_ERR
,
2417 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME
);
2418 vxge_debug_init(VXGE_ERR
,
2419 "%s: Defaulting to INTA", VXGE_DRIVER_NAME
);
2420 vdev
->config
.intr_type
= INTA
;
2423 if (vdev
->config
.intr_type
== MSI_X
) {
2425 intr_idx
< (vdev
->no_of_vpath
*
2426 VXGE_HW_VPATH_MSIX_ACTIVE
); intr_idx
++) {
2428 msix_idx
= intr_idx
% VXGE_HW_VPATH_MSIX_ACTIVE
;
2433 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2434 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2436 vdev
->entries
[intr_cnt
].entry
,
2439 vdev
->entries
[intr_cnt
].vector
,
2440 vxge_tx_msix_handle
, 0,
2441 vdev
->desc
[intr_cnt
],
2442 &vdev
->vpaths
[vp_idx
].fifo
);
2443 vdev
->vxge_entries
[intr_cnt
].arg
=
2444 &vdev
->vpaths
[vp_idx
].fifo
;
2448 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2449 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2451 vdev
->entries
[intr_cnt
].entry
,
2454 vdev
->entries
[intr_cnt
].vector
,
2455 vxge_rx_msix_napi_handle
,
2457 vdev
->desc
[intr_cnt
],
2458 &vdev
->vpaths
[vp_idx
].ring
);
2459 vdev
->vxge_entries
[intr_cnt
].arg
=
2460 &vdev
->vpaths
[vp_idx
].ring
;
2466 vxge_debug_init(VXGE_ERR
,
2467 "%s: MSIX - %d Registration failed",
2468 vdev
->ndev
->name
, intr_cnt
);
2469 vxge_rem_msix_isr(vdev
);
2470 vdev
->config
.intr_type
= INTA
;
2471 vxge_debug_init(VXGE_ERR
,
2472 "%s: Defaulting to INTA"
2473 , vdev
->ndev
->name
);
2478 /* We requested for this msix interrupt */
2479 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2480 msix_idx
+= vdev
->vpaths
[vp_idx
].device_id
*
2481 VXGE_HW_VPATH_MSIX_ACTIVE
;
2482 vxge_hw_vpath_msix_unmask(
2483 vdev
->vpaths
[vp_idx
].handle
,
2488 /* Point to next vpath handler */
2489 if (((intr_idx
+ 1) % VXGE_HW_VPATH_MSIX_ACTIVE
== 0) &&
2490 (vp_idx
< (vdev
->no_of_vpath
- 1)))
2494 intr_cnt
= vdev
->no_of_vpath
* 2;
2495 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2496 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2498 vdev
->entries
[intr_cnt
].entry
,
2500 /* For Alarm interrupts */
2501 ret
= request_irq(vdev
->entries
[intr_cnt
].vector
,
2502 vxge_alarm_msix_handle
, 0,
2503 vdev
->desc
[intr_cnt
],
2506 vxge_debug_init(VXGE_ERR
,
2507 "%s: MSIX - %d Registration failed",
2508 vdev
->ndev
->name
, intr_cnt
);
2509 vxge_rem_msix_isr(vdev
);
2510 vdev
->config
.intr_type
= INTA
;
2511 vxge_debug_init(VXGE_ERR
,
2512 "%s: Defaulting to INTA",
2517 msix_idx
= (vdev
->vpaths
[0].handle
->vpath
->vp_id
*
2518 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
2519 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[vp_idx
].handle
,
2521 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2522 vdev
->vxge_entries
[intr_cnt
].arg
= &vdev
->vpaths
[0];
2527 if (vdev
->config
.intr_type
== INTA
) {
2528 snprintf(vdev
->desc
[0], VXGE_INTR_STRLEN
,
2529 "%s:vxge:INTA", vdev
->ndev
->name
);
2530 vxge_hw_device_set_intr_type(vdev
->devh
,
2531 VXGE_HW_INTR_MODE_IRQLINE
);
2532 vxge_hw_vpath_tti_ci_set(vdev
->devh
,
2533 vdev
->vpaths
[0].device_id
);
2534 ret
= request_irq((int) vdev
->pdev
->irq
,
2536 IRQF_SHARED
, vdev
->desc
[0], vdev
);
2538 vxge_debug_init(VXGE_ERR
,
2539 "%s %s-%d: ISR registration failed",
2540 VXGE_DRIVER_NAME
, "IRQ", vdev
->pdev
->irq
);
2543 vxge_debug_init(VXGE_TRACE
,
2544 "new %s-%d line allocated",
2545 "IRQ", vdev
->pdev
->irq
);
2551 static void vxge_poll_vp_reset(unsigned long data
)
2553 struct vxgedev
*vdev
= (struct vxgedev
*)data
;
2556 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2557 if (test_bit(i
, &vdev
->vp_reset
)) {
2558 vxge_reset_vpath(vdev
, i
);
2562 if (j
&& (vdev
->config
.intr_type
!= MSI_X
)) {
2563 vxge_hw_device_unmask_all(vdev
->devh
);
2564 vxge_hw_device_flush_io(vdev
->devh
);
2567 mod_timer(&vdev
->vp_reset_timer
, jiffies
+ HZ
/ 2);
2570 static void vxge_poll_vp_lockup(unsigned long data
)
2572 struct vxgedev
*vdev
= (struct vxgedev
*)data
;
2574 struct vxge_ring
*ring
;
2575 enum vxge_hw_status status
= VXGE_HW_OK
;
2577 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2578 ring
= &vdev
->vpaths
[i
].ring
;
2579 /* Did this vpath received any packets */
2580 if (ring
->stats
.prev_rx_frms
== ring
->stats
.rx_frms
) {
2581 status
= vxge_hw_vpath_check_leak(ring
->handle
);
2583 /* Did it received any packets last time */
2584 if ((VXGE_HW_FAIL
== status
) &&
2585 (VXGE_HW_FAIL
== ring
->last_status
)) {
2587 /* schedule vpath reset */
2588 if (!test_and_set_bit(i
, &vdev
->vp_reset
)) {
2590 /* disable interrupts for this vpath */
2591 vxge_vpath_intr_disable(vdev
, i
);
2593 /* stop the queue for this vpath */
2594 vxge_stop_tx_queue(&vdev
->vpaths
[i
].
2600 ring
->stats
.prev_rx_frms
= ring
->stats
.rx_frms
;
2601 ring
->last_status
= status
;
2604 /* Check every 1 milli second */
2605 mod_timer(&vdev
->vp_lockup_timer
, jiffies
+ HZ
/ 1000);
2610 * @dev: pointer to the device structure.
2612 * This function is the open entry point of the driver. It mainly calls a
2613 * function to allocate Rx buffers and inserts them into the buffer
2614 * descriptors and then enables the Rx part of the NIC.
2615 * Return value: '0' on success and an appropriate (-)ve integer as
2616 * defined in errno.h file on failure.
2619 vxge_open(struct net_device
*dev
)
2621 enum vxge_hw_status status
;
2622 struct vxgedev
*vdev
;
2623 struct __vxge_hw_device
*hldev
;
2626 u64 val64
, function_mode
;
2627 vxge_debug_entryexit(VXGE_TRACE
,
2628 "%s: %s:%d", dev
->name
, __func__
, __LINE__
);
2630 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2631 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2632 function_mode
= vdev
->config
.device_hw_info
.function_mode
;
2634 /* make sure you have link off by default every time Nic is
2636 netif_carrier_off(dev
);
2639 status
= vxge_open_vpaths(vdev
);
2640 if (status
!= VXGE_HW_OK
) {
2641 vxge_debug_init(VXGE_ERR
,
2642 "%s: fatal: Vpath open failed", vdev
->ndev
->name
);
2647 vdev
->mtu
= dev
->mtu
;
2649 status
= vxge_add_isr(vdev
);
2650 if (status
!= VXGE_HW_OK
) {
2651 vxge_debug_init(VXGE_ERR
,
2652 "%s: fatal: ISR add failed", dev
->name
);
2658 if (vdev
->config
.intr_type
!= MSI_X
) {
2659 netif_napi_add(dev
, &vdev
->napi
, vxge_poll_inta
,
2660 vdev
->config
.napi_weight
);
2661 napi_enable(&vdev
->napi
);
2662 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2663 vdev
->vpaths
[i
].ring
.napi_p
= &vdev
->napi
;
2665 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2666 netif_napi_add(dev
, &vdev
->vpaths
[i
].ring
.napi
,
2667 vxge_poll_msix
, vdev
->config
.napi_weight
);
2668 napi_enable(&vdev
->vpaths
[i
].ring
.napi
);
2669 vdev
->vpaths
[i
].ring
.napi_p
=
2670 &vdev
->vpaths
[i
].ring
.napi
;
2675 if (vdev
->config
.rth_steering
) {
2676 status
= vxge_rth_configure(vdev
);
2677 if (status
!= VXGE_HW_OK
) {
2678 vxge_debug_init(VXGE_ERR
,
2679 "%s: fatal: RTH configuration failed",
2686 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2687 /* set initial mtu before enabling the device */
2688 status
= vxge_hw_vpath_mtu_set(vdev
->vpaths
[i
].handle
,
2690 if (status
!= VXGE_HW_OK
) {
2691 vxge_debug_init(VXGE_ERR
,
2692 "%s: fatal: can not set new MTU", dev
->name
);
2698 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE
, VXGE_COMPONENT_LL
, vdev
);
2699 vxge_debug_init(vdev
->level_trace
,
2700 "%s: MTU is %d", vdev
->ndev
->name
, vdev
->mtu
);
2701 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR
, VXGE_COMPONENT_LL
, vdev
);
2703 /* Reprogram the DA table with populated mac addresses */
2704 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2705 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[i
]);
2706 vxge_restore_vpath_vid_table(&vdev
->vpaths
[i
]);
2709 /* Enable vpath to sniff all unicast/multicast traffic that not
2710 * addressed to them. We allow promiscous mode for PF only
2714 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
2715 val64
|= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i
);
2717 vxge_hw_mgmt_reg_write(vdev
->devh
,
2718 vxge_hw_mgmt_reg_type_mrpcim
,
2720 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2721 rxmac_authorize_all_addr
),
2724 vxge_hw_mgmt_reg_write(vdev
->devh
,
2725 vxge_hw_mgmt_reg_type_mrpcim
,
2727 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2728 rxmac_authorize_all_vid
),
2731 vxge_set_multicast(dev
);
2733 /* Enabling Bcast and mcast for all vpath */
2734 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2735 status
= vxge_hw_vpath_bcast_enable(vdev
->vpaths
[i
].handle
);
2736 if (status
!= VXGE_HW_OK
)
2737 vxge_debug_init(VXGE_ERR
,
2738 "%s : Can not enable bcast for vpath "
2739 "id %d", dev
->name
, i
);
2740 if (vdev
->config
.addr_learn_en
) {
2742 vxge_hw_vpath_mcast_enable(vdev
->vpaths
[i
].handle
);
2743 if (status
!= VXGE_HW_OK
)
2744 vxge_debug_init(VXGE_ERR
,
2745 "%s : Can not enable mcast for vpath "
2746 "id %d", dev
->name
, i
);
2750 vxge_hw_device_setpause_data(vdev
->devh
, 0,
2751 vdev
->config
.tx_pause_enable
,
2752 vdev
->config
.rx_pause_enable
);
2754 if (vdev
->vp_reset_timer
.function
== NULL
)
2755 vxge_os_timer(vdev
->vp_reset_timer
,
2756 vxge_poll_vp_reset
, vdev
, (HZ
/2));
2758 if (vdev
->vp_lockup_timer
.function
== NULL
)
2759 vxge_os_timer(vdev
->vp_lockup_timer
,
2760 vxge_poll_vp_lockup
, vdev
, (HZ
/2));
2762 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
2766 if (vxge_hw_device_link_state_get(vdev
->devh
) == VXGE_HW_LINK_UP
) {
2767 netif_carrier_on(vdev
->ndev
);
2768 printk(KERN_NOTICE
"%s: Link Up\n", vdev
->ndev
->name
);
2769 vdev
->stats
.link_up
++;
2772 vxge_hw_device_intr_enable(vdev
->devh
);
2776 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2777 vxge_hw_vpath_enable(vdev
->vpaths
[i
].handle
);
2779 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[i
].handle
);
2782 vxge_start_all_tx_queue(vdev
);
2789 if (vdev
->config
.intr_type
!= MSI_X
)
2790 napi_disable(&vdev
->napi
);
2792 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2793 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
2797 vxge_close_vpaths(vdev
, 0);
2799 vxge_debug_entryexit(VXGE_TRACE
,
2800 "%s: %s:%d Exiting...",
2801 dev
->name
, __func__
, __LINE__
);
2805 /* Loop throught the mac address list and delete all the entries */
2806 void vxge_free_mac_add_list(struct vxge_vpath
*vpath
)
2809 struct list_head
*entry
, *next
;
2810 if (list_empty(&vpath
->mac_addr_list
))
2813 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
2815 kfree((struct vxge_mac_addrs
*)entry
);
2819 static void vxge_napi_del_all(struct vxgedev
*vdev
)
2822 if (vdev
->config
.intr_type
!= MSI_X
)
2823 netif_napi_del(&vdev
->napi
);
2825 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2826 netif_napi_del(&vdev
->vpaths
[i
].ring
.napi
);
2830 int do_vxge_close(struct net_device
*dev
, int do_io
)
2832 enum vxge_hw_status status
;
2833 struct vxgedev
*vdev
;
2834 struct __vxge_hw_device
*hldev
;
2836 u64 val64
, vpath_vector
;
2837 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
2838 dev
->name
, __func__
, __LINE__
);
2840 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2841 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2843 if (unlikely(!is_vxge_card_up(vdev
)))
2846 /* If vxge_handle_crit_err task is executing,
2847 * wait till it completes. */
2848 while (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
2851 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
2853 /* Put the vpath back in normal mode */
2854 vpath_vector
= vxge_mBIT(vdev
->vpaths
[0].device_id
);
2855 status
= vxge_hw_mgmt_reg_read(vdev
->devh
,
2856 vxge_hw_mgmt_reg_type_mrpcim
,
2859 struct vxge_hw_mrpcim_reg
,
2860 rts_mgr_cbasin_cfg
),
2863 if (status
== VXGE_HW_OK
) {
2864 val64
&= ~vpath_vector
;
2865 status
= vxge_hw_mgmt_reg_write(vdev
->devh
,
2866 vxge_hw_mgmt_reg_type_mrpcim
,
2869 struct vxge_hw_mrpcim_reg
,
2870 rts_mgr_cbasin_cfg
),
2874 /* Remove the function 0 from promiscous mode */
2875 vxge_hw_mgmt_reg_write(vdev
->devh
,
2876 vxge_hw_mgmt_reg_type_mrpcim
,
2878 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2879 rxmac_authorize_all_addr
),
2882 vxge_hw_mgmt_reg_write(vdev
->devh
,
2883 vxge_hw_mgmt_reg_type_mrpcim
,
2885 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2886 rxmac_authorize_all_vid
),
2891 del_timer_sync(&vdev
->vp_lockup_timer
);
2893 del_timer_sync(&vdev
->vp_reset_timer
);
2896 if (vdev
->config
.intr_type
!= MSI_X
)
2897 napi_disable(&vdev
->napi
);
2899 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2900 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
2903 netif_carrier_off(vdev
->ndev
);
2904 printk(KERN_NOTICE
"%s: Link Down\n", vdev
->ndev
->name
);
2905 vxge_stop_all_tx_queue(vdev
);
2907 /* Note that at this point xmit() is stopped by upper layer */
2909 vxge_hw_device_intr_disable(vdev
->devh
);
2915 vxge_napi_del_all(vdev
);
2918 vxge_reset_all_vpaths(vdev
);
2920 vxge_close_vpaths(vdev
, 0);
2922 vxge_debug_entryexit(VXGE_TRACE
,
2923 "%s: %s:%d Exiting...", dev
->name
, __func__
, __LINE__
);
2925 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
2932 * @dev: device pointer.
2934 * This is the stop entry point of the driver. It needs to undo exactly
2935 * whatever was done by the open entry point, thus it's usually referred to
2936 * as the close function.Among other things this function mainly stops the
2937 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2938 * Return value: '0' on success and an appropriate (-)ve integer as
2939 * defined in errno.h file on failure.
2942 vxge_close(struct net_device
*dev
)
2944 do_vxge_close(dev
, 1);
2950 * @dev: net device pointer.
2951 * @new_mtu :the new MTU size for the device.
2953 * A driver entry point to change MTU size for the device. Before changing
2954 * the MTU the device must be stopped.
2956 static int vxge_change_mtu(struct net_device
*dev
, int new_mtu
)
2958 struct vxgedev
*vdev
= netdev_priv(dev
);
2960 vxge_debug_entryexit(vdev
->level_trace
,
2961 "%s:%d", __func__
, __LINE__
);
2962 if ((new_mtu
< VXGE_HW_MIN_MTU
) || (new_mtu
> VXGE_HW_MAX_MTU
)) {
2963 vxge_debug_init(vdev
->level_err
,
2964 "%s: mtu size is invalid", dev
->name
);
2968 /* check if device is down already */
2969 if (unlikely(!is_vxge_card_up(vdev
))) {
2970 /* just store new value, will use later on open() */
2972 vxge_debug_init(vdev
->level_err
,
2973 "%s", "device is down on MTU change");
2977 vxge_debug_init(vdev
->level_trace
,
2978 "trying to apply new MTU %d", new_mtu
);
2980 if (vxge_close(dev
))
2984 vdev
->mtu
= new_mtu
;
2989 vxge_debug_init(vdev
->level_trace
,
2990 "%s: MTU changed to %d", vdev
->ndev
->name
, new_mtu
);
2992 vxge_debug_entryexit(vdev
->level_trace
,
2993 "%s:%d Exiting...", __func__
, __LINE__
);
3000 * @dev: pointer to the device structure
3002 * Updates the device statistics structure. This function updates the device
3003 * statistics structure in the net_device structure and returns a pointer
3006 static struct net_device_stats
*
3007 vxge_get_stats(struct net_device
*dev
)
3009 struct vxgedev
*vdev
;
3010 struct net_device_stats
*net_stats
;
3013 vdev
= netdev_priv(dev
);
3015 net_stats
= &vdev
->stats
.net_stats
;
3017 memset(net_stats
, 0, sizeof(struct net_device_stats
));
3019 for (k
= 0; k
< vdev
->no_of_vpath
; k
++) {
3020 net_stats
->rx_packets
+= vdev
->vpaths
[k
].ring
.stats
.rx_frms
;
3021 net_stats
->rx_bytes
+= vdev
->vpaths
[k
].ring
.stats
.rx_bytes
;
3022 net_stats
->rx_errors
+= vdev
->vpaths
[k
].ring
.stats
.rx_errors
;
3023 net_stats
->multicast
+= vdev
->vpaths
[k
].ring
.stats
.rx_mcast
;
3024 net_stats
->rx_dropped
+=
3025 vdev
->vpaths
[k
].ring
.stats
.rx_dropped
;
3027 net_stats
->tx_packets
+= vdev
->vpaths
[k
].fifo
.stats
.tx_frms
;
3028 net_stats
->tx_bytes
+= vdev
->vpaths
[k
].fifo
.stats
.tx_bytes
;
3029 net_stats
->tx_errors
+= vdev
->vpaths
[k
].fifo
.stats
.tx_errors
;
3037 * @dev: Device pointer.
3038 * @ifr: An IOCTL specific structure, that can contain a pointer to
3039 * a proprietary structure used to pass information to the driver.
3040 * @cmd: This is used to distinguish between the different commands that
3041 * can be passed to the IOCTL functions.
3043 * Entry point for the Ioctl.
3045 static int vxge_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3052 * @dev: pointer to net device structure
3054 * Watchdog for transmit side.
3055 * This function is triggered if the Tx Queue is stopped
3056 * for a pre-defined amount of time when the Interface is still up.
3059 vxge_tx_watchdog(struct net_device
*dev
)
3061 struct vxgedev
*vdev
;
3063 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3065 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3067 vdev
->cric_err_event
= VXGE_HW_EVENT_RESET_START
;
3070 vxge_debug_entryexit(VXGE_TRACE
,
3071 "%s:%d Exiting...", __func__
, __LINE__
);
3075 * vxge_vlan_rx_register
3076 * @dev: net device pointer.
3079 * Vlan group registration
3082 vxge_vlan_rx_register(struct net_device
*dev
, struct vlan_group
*grp
)
3084 struct vxgedev
*vdev
;
3085 struct vxge_vpath
*vpath
;
3088 enum vxge_hw_status status
;
3091 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3093 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3095 vpath
= &vdev
->vpaths
[0];
3096 if ((NULL
== grp
) && (vpath
->is_open
)) {
3097 /* Get the first vlan */
3098 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3100 while (status
== VXGE_HW_OK
) {
3102 /* Delete this vlan from the vid table */
3103 for (vp
= 0; vp
< vdev
->no_of_vpath
; vp
++) {
3104 vpath
= &vdev
->vpaths
[vp
];
3105 if (!vpath
->is_open
)
3108 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3111 /* Get the next vlan to be deleted */
3112 vpath
= &vdev
->vpaths
[0];
3113 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3119 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
3120 if (vdev
->vpaths
[i
].is_configured
)
3121 vdev
->vpaths
[i
].ring
.vlgrp
= grp
;
3124 vxge_debug_entryexit(VXGE_TRACE
,
3125 "%s:%d Exiting...", __func__
, __LINE__
);
3129 * vxge_vlan_rx_add_vid
3130 * @dev: net device pointer.
3133 * Add the vlan id to the devices vlan id table
3136 vxge_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
3138 struct vxgedev
*vdev
;
3139 struct vxge_vpath
*vpath
;
3142 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3144 /* Add these vlan to the vid table */
3145 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3146 vpath
= &vdev
->vpaths
[vp_id
];
3147 if (!vpath
->is_open
)
3149 vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
3154 * vxge_vlan_rx_add_vid
3155 * @dev: net device pointer.
3158 * Remove the vlan id from the device's vlan id table
3161 vxge_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
3163 struct vxgedev
*vdev
;
3164 struct vxge_vpath
*vpath
;
3167 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3169 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3171 vlan_group_set_device(vdev
->vlgrp
, vid
, NULL
);
3173 /* Delete this vlan from the vid table */
3174 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3175 vpath
= &vdev
->vpaths
[vp_id
];
3176 if (!vpath
->is_open
)
3178 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3180 vxge_debug_entryexit(VXGE_TRACE
,
3181 "%s:%d Exiting...", __func__
, __LINE__
);
3184 static const struct net_device_ops vxge_netdev_ops
= {
3185 .ndo_open
= vxge_open
,
3186 .ndo_stop
= vxge_close
,
3187 .ndo_get_stats
= vxge_get_stats
,
3188 .ndo_start_xmit
= vxge_xmit
,
3189 .ndo_validate_addr
= eth_validate_addr
,
3190 .ndo_set_multicast_list
= vxge_set_multicast
,
3192 .ndo_do_ioctl
= vxge_ioctl
,
3194 .ndo_set_mac_address
= vxge_set_mac_addr
,
3195 .ndo_change_mtu
= vxge_change_mtu
,
3196 .ndo_vlan_rx_register
= vxge_vlan_rx_register
,
3197 .ndo_vlan_rx_kill_vid
= vxge_vlan_rx_kill_vid
,
3198 .ndo_vlan_rx_add_vid
= vxge_vlan_rx_add_vid
,
3200 .ndo_tx_timeout
= vxge_tx_watchdog
,
3201 #ifdef CONFIG_NET_POLL_CONTROLLER
3202 .ndo_poll_controller
= vxge_netpoll
,
3206 int __devinit
vxge_device_register(struct __vxge_hw_device
*hldev
,
3207 struct vxge_config
*config
,
3208 int high_dma
, int no_of_vpath
,
3209 struct vxgedev
**vdev_out
)
3211 struct net_device
*ndev
;
3212 enum vxge_hw_status status
= VXGE_HW_OK
;
3213 struct vxgedev
*vdev
;
3214 int i
, ret
= 0, no_of_queue
= 1;
3218 if (config
->tx_steering_type
== TX_MULTIQ_STEERING
)
3219 no_of_queue
= no_of_vpath
;
3221 ndev
= alloc_etherdev_mq(sizeof(struct vxgedev
),
3225 vxge_hw_device_trace_level_get(hldev
),
3226 "%s : device allocation failed", __func__
);
3231 vxge_debug_entryexit(
3232 vxge_hw_device_trace_level_get(hldev
),
3233 "%s: %s:%d Entering...",
3234 ndev
->name
, __func__
, __LINE__
);
3236 vdev
= netdev_priv(ndev
);
3237 memset(vdev
, 0, sizeof(struct vxgedev
));
3241 vdev
->pdev
= hldev
->pdev
;
3242 memcpy(&vdev
->config
, config
, sizeof(struct vxge_config
));
3243 vdev
->rx_csum
= 1; /* Enable Rx CSUM by default. */
3245 SET_NETDEV_DEV(ndev
, &vdev
->pdev
->dev
);
3247 ndev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
|
3248 NETIF_F_HW_VLAN_FILTER
;
3249 /* Driver entry points */
3250 ndev
->irq
= vdev
->pdev
->irq
;
3251 ndev
->base_addr
= (unsigned long) hldev
->bar0
;
3253 ndev
->netdev_ops
= &vxge_netdev_ops
;
3255 ndev
->watchdog_timeo
= VXGE_LL_WATCH_DOG_TIMEOUT
;
3257 initialize_ethtool_ops(ndev
);
3259 /* Allocate memory for vpath */
3260 vdev
->vpaths
= kzalloc((sizeof(struct vxge_vpath
)) *
3261 no_of_vpath
, GFP_KERNEL
);
3262 if (!vdev
->vpaths
) {
3263 vxge_debug_init(VXGE_ERR
,
3264 "%s: vpath memory allocation failed",
3270 ndev
->features
|= NETIF_F_SG
;
3272 ndev
->features
|= NETIF_F_HW_CSUM
;
3273 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3274 "%s : checksuming enabled", __func__
);
3277 ndev
->features
|= NETIF_F_HIGHDMA
;
3278 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3279 "%s : using High DMA", __func__
);
3282 ndev
->features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
3284 if (vdev
->config
.gro_enable
)
3285 ndev
->features
|= NETIF_F_GRO
;
3287 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
)
3288 ndev
->real_num_tx_queues
= no_of_vpath
;
3291 ndev
->features
|= NETIF_F_LLTX
;
3294 for (i
= 0; i
< no_of_vpath
; i
++)
3295 spin_lock_init(&vdev
->vpaths
[i
].fifo
.tx_lock
);
3297 if (register_netdev(ndev
)) {
3298 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3299 "%s: %s : device registration failed!",
3300 ndev
->name
, __func__
);
3305 /* Set the factory defined MAC address initially */
3306 ndev
->addr_len
= ETH_ALEN
;
3308 /* Make Link state as off at this point, when the Link change
3309 * interrupt comes the state will be automatically changed to
3312 netif_carrier_off(ndev
);
3314 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3315 "%s: Ethernet device registered",
3320 /* Resetting the Device stats */
3321 status
= vxge_hw_mrpcim_stats_access(
3323 VXGE_HW_STATS_OP_CLEAR_ALL_STATS
,
3328 if (status
== VXGE_HW_ERR_PRIVILAGED_OPEARATION
)
3330 vxge_hw_device_trace_level_get(hldev
),
3331 "%s: device stats clear returns"
3332 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev
->name
);
3334 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev
),
3335 "%s: %s:%d Exiting...",
3336 ndev
->name
, __func__
, __LINE__
);
3340 kfree(vdev
->vpaths
);
3348 * vxge_device_unregister
3350 * This function will unregister and free network device
3353 vxge_device_unregister(struct __vxge_hw_device
*hldev
)
3355 struct vxgedev
*vdev
;
3356 struct net_device
*dev
;
3358 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3359 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3364 vdev
= netdev_priv(dev
);
3365 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3366 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3367 level_trace
= vdev
->level_trace
;
3369 vxge_debug_entryexit(level_trace
,
3370 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3372 memcpy(buf
, vdev
->ndev
->name
, IFNAMSIZ
);
3374 /* in 2.6 will call stop() if device is up */
3375 unregister_netdev(dev
);
3377 flush_scheduled_work();
3379 vxge_debug_init(level_trace
, "%s: ethernet device unregistered", buf
);
3380 vxge_debug_entryexit(level_trace
,
3381 "%s: %s:%d Exiting...", buf
, __func__
, __LINE__
);
3385 * vxge_callback_crit_err
3387 * This function is called by the alarm handler in interrupt context.
3388 * Driver must analyze it based on the event type.
3391 vxge_callback_crit_err(struct __vxge_hw_device
*hldev
,
3392 enum vxge_hw_event type
, u64 vp_id
)
3394 struct net_device
*dev
= hldev
->ndev
;
3395 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
3398 vxge_debug_entryexit(vdev
->level_trace
,
3399 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3401 /* Note: This event type should be used for device wide
3402 * indications only - Serious errors, Slot freeze and critical errors
3404 vdev
->cric_err_event
= type
;
3406 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++)
3407 if (vdev
->vpaths
[vpath_idx
].device_id
== vp_id
)
3410 if (!test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
)) {
3411 if (type
== VXGE_HW_EVENT_SLOT_FREEZE
) {
3412 vxge_debug_init(VXGE_ERR
,
3413 "%s: Slot is frozen", vdev
->ndev
->name
);
3414 } else if (type
== VXGE_HW_EVENT_SERR
) {
3415 vxge_debug_init(VXGE_ERR
,
3416 "%s: Encountered Serious Error",
3418 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
)
3419 vxge_debug_init(VXGE_ERR
,
3420 "%s: Encountered Critical Error",
3424 if ((type
== VXGE_HW_EVENT_SERR
) ||
3425 (type
== VXGE_HW_EVENT_SLOT_FREEZE
)) {
3426 if (unlikely(vdev
->exec_mode
))
3427 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3428 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
) {
3429 vxge_hw_device_mask_all(hldev
);
3430 if (unlikely(vdev
->exec_mode
))
3431 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3432 } else if ((type
== VXGE_HW_EVENT_FIFO_ERR
) ||
3433 (type
== VXGE_HW_EVENT_VPATH_ERR
)) {
3435 if (unlikely(vdev
->exec_mode
))
3436 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3438 /* check if this vpath is already set for reset */
3439 if (!test_and_set_bit(vpath_idx
, &vdev
->vp_reset
)) {
3441 /* disable interrupts for this vpath */
3442 vxge_vpath_intr_disable(vdev
, vpath_idx
);
3444 /* stop the queue for this vpath */
3445 vxge_stop_tx_queue(&vdev
->vpaths
[vpath_idx
].
3451 vxge_debug_entryexit(vdev
->level_trace
,
3452 "%s: %s:%d Exiting...",
3453 vdev
->ndev
->name
, __func__
, __LINE__
);
3456 static void verify_bandwidth(void)
3458 int i
, band_width
, total
= 0, equal_priority
= 0;
3460 /* 1. If user enters 0 for some fifo, give equal priority to all */
3461 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3462 if (bw_percentage
[i
] == 0) {
3468 if (!equal_priority
) {
3469 /* 2. If sum exceeds 100, give equal priority to all */
3470 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3471 if (bw_percentage
[i
] == 0xFF)
3474 total
+= bw_percentage
[i
];
3475 if (total
> VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3482 if (!equal_priority
) {
3483 /* Is all the bandwidth consumed? */
3484 if (total
< VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3485 if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
) {
3486 /* Split rest of bw equally among next VPs*/
3488 (VXGE_HW_VPATH_BANDWIDTH_MAX
- total
) /
3489 (VXGE_HW_MAX_VIRTUAL_PATHS
- i
);
3490 if (band_width
< 2) /* min of 2% */
3493 for (; i
< VXGE_HW_MAX_VIRTUAL_PATHS
;
3499 } else if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
)
3503 if (equal_priority
) {
3504 vxge_debug_init(VXGE_ERR
,
3505 "%s: Assigning equal bandwidth to all the vpaths",
3507 bw_percentage
[0] = VXGE_HW_VPATH_BANDWIDTH_MAX
/
3508 VXGE_HW_MAX_VIRTUAL_PATHS
;
3509 for (i
= 1; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3510 bw_percentage
[i
] = bw_percentage
[0];
3515 * Vpath configuration
3517 static int __devinit
vxge_config_vpaths(
3518 struct vxge_hw_device_config
*device_config
,
3519 u64 vpath_mask
, struct vxge_config
*config_param
)
3521 int i
, no_of_vpaths
= 0, default_no_vpath
= 0, temp
;
3522 u32 txdl_size
, txdl_per_memblock
;
3524 temp
= driver_config
->vpath_per_dev
;
3525 if ((driver_config
->vpath_per_dev
== VXGE_USE_DEFAULT
) &&
3526 (max_config_dev
== VXGE_MAX_CONFIG_DEV
)) {
3527 /* No more CPU. Return vpath number as zero.*/
3528 if (driver_config
->g_no_cpus
== -1)
3531 if (!driver_config
->g_no_cpus
)
3532 driver_config
->g_no_cpus
= num_online_cpus();
3534 driver_config
->vpath_per_dev
= driver_config
->g_no_cpus
>> 1;
3535 if (!driver_config
->vpath_per_dev
)
3536 driver_config
->vpath_per_dev
= 1;
3538 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3539 if (!vxge_bVALn(vpath_mask
, i
, 1))
3543 if (default_no_vpath
< driver_config
->vpath_per_dev
)
3544 driver_config
->vpath_per_dev
= default_no_vpath
;
3546 driver_config
->g_no_cpus
= driver_config
->g_no_cpus
-
3547 (driver_config
->vpath_per_dev
* 2);
3548 if (driver_config
->g_no_cpus
<= 0)
3549 driver_config
->g_no_cpus
= -1;
3552 if (driver_config
->vpath_per_dev
== 1) {
3553 vxge_debug_ll_config(VXGE_TRACE
,
3554 "%s: Disable tx and rx steering, "
3555 "as single vpath is configured", VXGE_DRIVER_NAME
);
3556 config_param
->rth_steering
= NO_STEERING
;
3557 config_param
->tx_steering_type
= NO_STEERING
;
3558 device_config
->rth_en
= 0;
3561 /* configure bandwidth */
3562 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3563 device_config
->vp_config
[i
].min_bandwidth
= bw_percentage
[i
];
3565 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3566 device_config
->vp_config
[i
].vp_id
= i
;
3567 device_config
->vp_config
[i
].mtu
= VXGE_HW_DEFAULT_MTU
;
3568 if (no_of_vpaths
< driver_config
->vpath_per_dev
) {
3569 if (!vxge_bVALn(vpath_mask
, i
, 1)) {
3570 vxge_debug_ll_config(VXGE_TRACE
,
3571 "%s: vpath: %d is not available",
3572 VXGE_DRIVER_NAME
, i
);
3575 vxge_debug_ll_config(VXGE_TRACE
,
3576 "%s: vpath: %d available",
3577 VXGE_DRIVER_NAME
, i
);
3581 vxge_debug_ll_config(VXGE_TRACE
,
3582 "%s: vpath: %d is not configured, "
3583 "max_config_vpath exceeded",
3584 VXGE_DRIVER_NAME
, i
);
3588 /* Configure Tx fifo's */
3589 device_config
->vp_config
[i
].fifo
.enable
=
3590 VXGE_HW_FIFO_ENABLE
;
3591 device_config
->vp_config
[i
].fifo
.max_frags
=
3593 device_config
->vp_config
[i
].fifo
.memblock_size
=
3594 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
;
3596 txdl_size
= device_config
->vp_config
[i
].fifo
.max_frags
*
3597 sizeof(struct vxge_hw_fifo_txd
);
3598 txdl_per_memblock
= VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
/ txdl_size
;
3600 device_config
->vp_config
[i
].fifo
.fifo_blocks
=
3601 ((VXGE_DEF_FIFO_LENGTH
- 1) / txdl_per_memblock
) + 1;
3603 device_config
->vp_config
[i
].fifo
.intr
=
3604 VXGE_HW_FIFO_QUEUE_INTR_DISABLE
;
3606 /* Configure tti properties */
3607 device_config
->vp_config
[i
].tti
.intr_enable
=
3608 VXGE_HW_TIM_INTR_ENABLE
;
3610 device_config
->vp_config
[i
].tti
.btimer_val
=
3611 (VXGE_TTI_BTIMER_VAL
* 1000) / 272;
3613 device_config
->vp_config
[i
].tti
.timer_ac_en
=
3614 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3616 /* For msi-x with napi (each vector
3617 has a handler of its own) -
3618 Set CI to OFF for all vpaths */
3619 device_config
->vp_config
[i
].tti
.timer_ci_en
=
3620 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3622 device_config
->vp_config
[i
].tti
.timer_ri_en
=
3623 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3625 device_config
->vp_config
[i
].tti
.util_sel
=
3626 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL
;
3628 device_config
->vp_config
[i
].tti
.ltimer_val
=
3629 (VXGE_TTI_LTIMER_VAL
* 1000) / 272;
3631 device_config
->vp_config
[i
].tti
.rtimer_val
=
3632 (VXGE_TTI_RTIMER_VAL
* 1000) / 272;
3634 device_config
->vp_config
[i
].tti
.urange_a
= TTI_TX_URANGE_A
;
3635 device_config
->vp_config
[i
].tti
.urange_b
= TTI_TX_URANGE_B
;
3636 device_config
->vp_config
[i
].tti
.urange_c
= TTI_TX_URANGE_C
;
3637 device_config
->vp_config
[i
].tti
.uec_a
= TTI_TX_UFC_A
;
3638 device_config
->vp_config
[i
].tti
.uec_b
= TTI_TX_UFC_B
;
3639 device_config
->vp_config
[i
].tti
.uec_c
= TTI_TX_UFC_C
;
3640 device_config
->vp_config
[i
].tti
.uec_d
= TTI_TX_UFC_D
;
3642 /* Configure Rx rings */
3643 device_config
->vp_config
[i
].ring
.enable
=
3644 VXGE_HW_RING_ENABLE
;
3646 device_config
->vp_config
[i
].ring
.ring_blocks
=
3647 VXGE_HW_DEF_RING_BLOCKS
;
3648 device_config
->vp_config
[i
].ring
.buffer_mode
=
3649 VXGE_HW_RING_RXD_BUFFER_MODE_1
;
3650 device_config
->vp_config
[i
].ring
.rxds_limit
=
3651 VXGE_HW_DEF_RING_RXDS_LIMIT
;
3652 device_config
->vp_config
[i
].ring
.scatter_mode
=
3653 VXGE_HW_RING_SCATTER_MODE_A
;
3655 /* Configure rti properties */
3656 device_config
->vp_config
[i
].rti
.intr_enable
=
3657 VXGE_HW_TIM_INTR_ENABLE
;
3659 device_config
->vp_config
[i
].rti
.btimer_val
=
3660 (VXGE_RTI_BTIMER_VAL
* 1000)/272;
3662 device_config
->vp_config
[i
].rti
.timer_ac_en
=
3663 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3665 device_config
->vp_config
[i
].rti
.timer_ci_en
=
3666 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3668 device_config
->vp_config
[i
].rti
.timer_ri_en
=
3669 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3671 device_config
->vp_config
[i
].rti
.util_sel
=
3672 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL
;
3674 device_config
->vp_config
[i
].rti
.urange_a
=
3676 device_config
->vp_config
[i
].rti
.urange_b
=
3678 device_config
->vp_config
[i
].rti
.urange_c
=
3680 device_config
->vp_config
[i
].rti
.uec_a
= RTI_RX_UFC_A
;
3681 device_config
->vp_config
[i
].rti
.uec_b
= RTI_RX_UFC_B
;
3682 device_config
->vp_config
[i
].rti
.uec_c
= RTI_RX_UFC_C
;
3683 device_config
->vp_config
[i
].rti
.uec_d
= RTI_RX_UFC_D
;
3685 device_config
->vp_config
[i
].rti
.rtimer_val
=
3686 (VXGE_RTI_RTIMER_VAL
* 1000) / 272;
3688 device_config
->vp_config
[i
].rti
.ltimer_val
=
3689 (VXGE_RTI_LTIMER_VAL
* 1000) / 272;
3691 device_config
->vp_config
[i
].rpa_strip_vlan_tag
=
3695 driver_config
->vpath_per_dev
= temp
;
3696 return no_of_vpaths
;
3699 /* initialize device configuratrions */
3700 static void __devinit
vxge_device_config_init(
3701 struct vxge_hw_device_config
*device_config
,
3704 /* Used for CQRQ/SRQ. */
3705 device_config
->dma_blockpool_initial
=
3706 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE
;
3708 device_config
->dma_blockpool_max
=
3709 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE
;
3711 if (max_mac_vpath
> VXGE_MAX_MAC_ADDR_COUNT
)
3712 max_mac_vpath
= VXGE_MAX_MAC_ADDR_COUNT
;
3714 #ifndef CONFIG_PCI_MSI
3715 vxge_debug_init(VXGE_ERR
,
3716 "%s: This Kernel does not support "
3717 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME
);
3721 /* Configure whether MSI-X or IRQL. */
3722 switch (*intr_type
) {
3724 device_config
->intr_mode
= VXGE_HW_INTR_MODE_IRQLINE
;
3728 device_config
->intr_mode
= VXGE_HW_INTR_MODE_MSIX
;
3731 /* Timer period between device poll */
3732 device_config
->device_poll_millis
= VXGE_TIMER_DELAY
;
3734 /* Configure mac based steering. */
3735 device_config
->rts_mac_en
= addr_learn_en
;
3737 /* Configure Vpaths */
3738 device_config
->rth_it_type
= VXGE_HW_RTH_IT_TYPE_MULTI_IT
;
3740 vxge_debug_ll_config(VXGE_TRACE
, "%s : Device Config Params ",
3742 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_initial : %d",
3743 device_config
->dma_blockpool_initial
);
3744 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_max : %d",
3745 device_config
->dma_blockpool_max
);
3746 vxge_debug_ll_config(VXGE_TRACE
, "intr_mode : %d",
3747 device_config
->intr_mode
);
3748 vxge_debug_ll_config(VXGE_TRACE
, "device_poll_millis : %d",
3749 device_config
->device_poll_millis
);
3750 vxge_debug_ll_config(VXGE_TRACE
, "rts_mac_en : %d",
3751 device_config
->rts_mac_en
);
3752 vxge_debug_ll_config(VXGE_TRACE
, "rth_en : %d",
3753 device_config
->rth_en
);
3754 vxge_debug_ll_config(VXGE_TRACE
, "rth_it_type : %d",
3755 device_config
->rth_it_type
);
3758 static void __devinit
vxge_print_parm(struct vxgedev
*vdev
, u64 vpath_mask
)
3762 vxge_debug_init(VXGE_TRACE
,
3763 "%s: %d Vpath(s) opened",
3764 vdev
->ndev
->name
, vdev
->no_of_vpath
);
3766 switch (vdev
->config
.intr_type
) {
3768 vxge_debug_init(VXGE_TRACE
,
3769 "%s: Interrupt type INTA", vdev
->ndev
->name
);
3773 vxge_debug_init(VXGE_TRACE
,
3774 "%s: Interrupt type MSI-X", vdev
->ndev
->name
);
3778 if (vdev
->config
.rth_steering
) {
3779 vxge_debug_init(VXGE_TRACE
,
3780 "%s: RTH steering enabled for TCP_IPV4",
3783 vxge_debug_init(VXGE_TRACE
,
3784 "%s: RTH steering disabled", vdev
->ndev
->name
);
3787 switch (vdev
->config
.tx_steering_type
) {
3789 vxge_debug_init(VXGE_TRACE
,
3790 "%s: Tx steering disabled", vdev
->ndev
->name
);
3792 case TX_PRIORITY_STEERING
:
3793 vxge_debug_init(VXGE_TRACE
,
3794 "%s: Unsupported tx steering option",
3796 vxge_debug_init(VXGE_TRACE
,
3797 "%s: Tx steering disabled", vdev
->ndev
->name
);
3798 vdev
->config
.tx_steering_type
= 0;
3800 case TX_VLAN_STEERING
:
3801 vxge_debug_init(VXGE_TRACE
,
3802 "%s: Unsupported tx steering option",
3804 vxge_debug_init(VXGE_TRACE
,
3805 "%s: Tx steering disabled", vdev
->ndev
->name
);
3806 vdev
->config
.tx_steering_type
= 0;
3808 case TX_MULTIQ_STEERING
:
3809 vxge_debug_init(VXGE_TRACE
,
3810 "%s: Tx multiqueue steering enabled",
3813 case TX_PORT_STEERING
:
3814 vxge_debug_init(VXGE_TRACE
,
3815 "%s: Tx port steering enabled",
3819 vxge_debug_init(VXGE_ERR
,
3820 "%s: Unsupported tx steering type",
3822 vxge_debug_init(VXGE_TRACE
,
3823 "%s: Tx steering disabled", vdev
->ndev
->name
);
3824 vdev
->config
.tx_steering_type
= 0;
3827 if (vdev
->config
.gro_enable
) {
3828 vxge_debug_init(VXGE_ERR
,
3829 "%s: Generic receive offload enabled",
3832 vxge_debug_init(VXGE_TRACE
,
3833 "%s: Generic receive offload disabled",
3836 if (vdev
->config
.addr_learn_en
)
3837 vxge_debug_init(VXGE_TRACE
,
3838 "%s: MAC Address learning enabled", vdev
->ndev
->name
);
3840 vxge_debug_init(VXGE_TRACE
,
3841 "%s: Rx doorbell mode enabled", vdev
->ndev
->name
);
3843 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3844 if (!vxge_bVALn(vpath_mask
, i
, 1))
3846 vxge_debug_ll_config(VXGE_TRACE
,
3847 "%s: MTU size - %d", vdev
->ndev
->name
,
3848 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3849 config
.vp_config
[i
].mtu
);
3850 vxge_debug_init(VXGE_TRACE
,
3851 "%s: VLAN tag stripping %s", vdev
->ndev
->name
,
3852 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3853 config
.vp_config
[i
].rpa_strip_vlan_tag
3854 ? "Enabled" : "Disabled");
3855 vxge_debug_init(VXGE_TRACE
,
3856 "%s: Ring blocks : %d", vdev
->ndev
->name
,
3857 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3858 config
.vp_config
[i
].ring
.ring_blocks
);
3859 vxge_debug_init(VXGE_TRACE
,
3860 "%s: Fifo blocks : %d", vdev
->ndev
->name
,
3861 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3862 config
.vp_config
[i
].fifo
.fifo_blocks
);
3863 vxge_debug_ll_config(VXGE_TRACE
,
3864 "%s: Max frags : %d", vdev
->ndev
->name
,
3865 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3866 config
.vp_config
[i
].fifo
.max_frags
);
3873 * vxge_pm_suspend - vxge power management suspend entry point
3876 static int vxge_pm_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3881 * vxge_pm_resume - vxge power management resume entry point
3884 static int vxge_pm_resume(struct pci_dev
*pdev
)
3892 * vxge_io_error_detected - called when PCI error is detected
3893 * @pdev: Pointer to PCI device
3894 * @state: The current pci connection state
3896 * This function is called after a PCI bus error affecting
3897 * this device has been detected.
3899 static pci_ers_result_t
vxge_io_error_detected(struct pci_dev
*pdev
,
3900 pci_channel_state_t state
)
3902 struct __vxge_hw_device
*hldev
=
3903 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3904 struct net_device
*netdev
= hldev
->ndev
;
3906 netif_device_detach(netdev
);
3908 if (state
== pci_channel_io_perm_failure
)
3909 return PCI_ERS_RESULT_DISCONNECT
;
3911 if (netif_running(netdev
)) {
3912 /* Bring down the card, while avoiding PCI I/O */
3913 do_vxge_close(netdev
, 0);
3916 pci_disable_device(pdev
);
3918 return PCI_ERS_RESULT_NEED_RESET
;
3922 * vxge_io_slot_reset - called after the pci bus has been reset.
3923 * @pdev: Pointer to PCI device
3925 * Restart the card from scratch, as if from a cold-boot.
3926 * At this point, the card has exprienced a hard reset,
3927 * followed by fixups by BIOS, and has its config space
3928 * set up identically to what it was at cold boot.
3930 static pci_ers_result_t
vxge_io_slot_reset(struct pci_dev
*pdev
)
3932 struct __vxge_hw_device
*hldev
=
3933 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3934 struct net_device
*netdev
= hldev
->ndev
;
3936 struct vxgedev
*vdev
= netdev_priv(netdev
);
3938 if (pci_enable_device(pdev
)) {
3939 printk(KERN_ERR
"%s: "
3940 "Cannot re-enable device after reset\n",
3942 return PCI_ERS_RESULT_DISCONNECT
;
3945 pci_set_master(pdev
);
3948 return PCI_ERS_RESULT_RECOVERED
;
3952 * vxge_io_resume - called when traffic can start flowing again.
3953 * @pdev: Pointer to PCI device
3955 * This callback is called when the error recovery driver tells
3956 * us that its OK to resume normal operation.
3958 static void vxge_io_resume(struct pci_dev
*pdev
)
3960 struct __vxge_hw_device
*hldev
=
3961 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3962 struct net_device
*netdev
= hldev
->ndev
;
3964 if (netif_running(netdev
)) {
3965 if (vxge_open(netdev
)) {
3966 printk(KERN_ERR
"%s: "
3967 "Can't bring device back up after reset\n",
3973 netif_device_attach(netdev
);
3976 static inline u32
vxge_get_num_vfs(u64 function_mode
)
3978 u32 num_functions
= 0;
3980 switch (function_mode
) {
3981 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
3982 case VXGE_HW_FUNCTION_MODE_SRIOV_8
:
3985 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
3988 case VXGE_HW_FUNCTION_MODE_SRIOV
:
3989 case VXGE_HW_FUNCTION_MODE_MRIOV
:
3990 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17
:
3993 case VXGE_HW_FUNCTION_MODE_SRIOV_4
:
3996 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2
:
3999 case VXGE_HW_FUNCTION_MODE_MRIOV_8
:
4000 num_functions
= 8; /* TODO */
4003 return num_functions
;
4008 * @pdev : structure containing the PCI related information of the device.
4009 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4011 * This function is called when a new PCI device gets detected and initializes
4014 * returns 0 on success and negative on failure.
4017 static int __devinit
4018 vxge_probe(struct pci_dev
*pdev
, const struct pci_device_id
*pre
)
4020 struct __vxge_hw_device
*hldev
;
4021 enum vxge_hw_status status
;
4025 struct vxgedev
*vdev
;
4026 struct vxge_config ll_config
;
4027 struct vxge_hw_device_config
*device_config
= NULL
;
4028 struct vxge_hw_device_attr attr
;
4029 int i
, j
, no_of_vpath
= 0, max_vpath_supported
= 0;
4031 struct vxge_mac_addrs
*entry
;
4032 static int bus
= -1, device
= -1;
4035 enum vxge_hw_status is_privileged
;
4039 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
4042 /* In SRIOV-17 mode, functions of the same adapter
4043 * can be deployed on different buses */
4044 if ((!pdev
->is_virtfn
) && ((bus
!= pdev
->bus
->number
) ||
4045 (device
!= PCI_SLOT(pdev
->devfn
))))
4048 bus
= pdev
->bus
->number
;
4049 device
= PCI_SLOT(pdev
->devfn
);
4052 if (driver_config
->config_dev_cnt
&&
4053 (driver_config
->config_dev_cnt
!=
4054 driver_config
->total_dev_cnt
))
4055 vxge_debug_init(VXGE_ERR
,
4056 "%s: Configured %d of %d devices",
4058 driver_config
->config_dev_cnt
,
4059 driver_config
->total_dev_cnt
);
4060 driver_config
->config_dev_cnt
= 0;
4061 driver_config
->total_dev_cnt
= 0;
4063 /* Now making the CPU based no of vpath calculation
4064 * applicable for individual functions as well.
4066 driver_config
->g_no_cpus
= 0;
4067 driver_config
->vpath_per_dev
= max_config_vpath
;
4069 driver_config
->total_dev_cnt
++;
4070 if (++driver_config
->config_dev_cnt
> max_config_dev
) {
4075 device_config
= kzalloc(sizeof(struct vxge_hw_device_config
),
4077 if (!device_config
) {
4079 vxge_debug_init(VXGE_ERR
,
4080 "device_config : malloc failed %s %d",
4081 __FILE__
, __LINE__
);
4085 memset(&ll_config
, 0, sizeof(struct vxge_config
));
4086 ll_config
.tx_steering_type
= TX_MULTIQ_STEERING
;
4087 ll_config
.intr_type
= MSI_X
;
4088 ll_config
.napi_weight
= NEW_NAPI_WEIGHT
;
4089 ll_config
.rth_steering
= RTH_STEERING
;
4091 /* get the default configuration parameters */
4092 vxge_hw_device_config_default_get(device_config
);
4094 /* initialize configuration parameters */
4095 vxge_device_config_init(device_config
, &ll_config
.intr_type
);
4097 ret
= pci_enable_device(pdev
);
4099 vxge_debug_init(VXGE_ERR
,
4100 "%s : can not enable PCI device", __func__
);
4104 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))) {
4105 vxge_debug_ll_config(VXGE_TRACE
,
4106 "%s : using 64bit DMA", __func__
);
4110 if (pci_set_consistent_dma_mask(pdev
,
4111 DMA_BIT_MASK(64))) {
4112 vxge_debug_init(VXGE_ERR
,
4113 "%s : unable to obtain 64bit DMA for "
4114 "consistent allocations", __func__
);
4118 } else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
4119 vxge_debug_ll_config(VXGE_TRACE
,
4120 "%s : using 32bit DMA", __func__
);
4126 if (pci_request_regions(pdev
, VXGE_DRIVER_NAME
)) {
4127 vxge_debug_init(VXGE_ERR
,
4128 "%s : request regions failed", __func__
);
4133 pci_set_master(pdev
);
4135 attr
.bar0
= pci_ioremap_bar(pdev
, 0);
4137 vxge_debug_init(VXGE_ERR
,
4138 "%s : cannot remap io memory bar0", __func__
);
4142 vxge_debug_ll_config(VXGE_TRACE
,
4143 "pci ioremap bar0: %p:0x%llx",
4145 (unsigned long long)pci_resource_start(pdev
, 0));
4147 status
= vxge_hw_device_hw_info_get(attr
.bar0
,
4148 &ll_config
.device_hw_info
);
4149 if (status
!= VXGE_HW_OK
) {
4150 vxge_debug_init(VXGE_ERR
,
4151 "%s: Reading of hardware info failed."
4152 "Please try upgrading the firmware.", VXGE_DRIVER_NAME
);
4157 if (ll_config
.device_hw_info
.fw_version
.major
!=
4158 VXGE_DRIVER_FW_VERSION_MAJOR
) {
4159 vxge_debug_init(VXGE_ERR
,
4160 "%s: Incorrect firmware version."
4161 "Please upgrade the firmware to version 1.x.x",
4167 vpath_mask
= ll_config
.device_hw_info
.vpath_mask
;
4168 if (vpath_mask
== 0) {
4169 vxge_debug_ll_config(VXGE_TRACE
,
4170 "%s: No vpaths available in device", VXGE_DRIVER_NAME
);
4175 vxge_debug_ll_config(VXGE_TRACE
,
4176 "%s:%d Vpath mask = %llx", __func__
, __LINE__
,
4177 (unsigned long long)vpath_mask
);
4179 function_mode
= ll_config
.device_hw_info
.function_mode
;
4180 host_type
= ll_config
.device_hw_info
.host_type
;
4181 is_privileged
= __vxge_hw_device_is_privilaged(host_type
,
4182 ll_config
.device_hw_info
.func_id
);
4184 /* Check how many vpaths are available */
4185 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4186 if (!((vpath_mask
) & vxge_mBIT(i
)))
4188 max_vpath_supported
++;
4192 num_vfs
= vxge_get_num_vfs(function_mode
) - 1;
4194 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4195 if (is_sriov(function_mode
) && (max_config_dev
> 1) &&
4196 (ll_config
.intr_type
!= INTA
) &&
4197 (is_privileged
== VXGE_HW_OK
)) {
4198 ret
= pci_enable_sriov(pdev
, ((max_config_dev
- 1) < num_vfs
)
4199 ? (max_config_dev
- 1) : num_vfs
);
4201 vxge_debug_ll_config(VXGE_ERR
,
4202 "Failed in enabling SRIOV mode: %d\n", ret
);
4206 * Configure vpaths and get driver configured number of vpaths
4207 * which is less than or equal to the maximum vpaths per function.
4209 no_of_vpath
= vxge_config_vpaths(device_config
, vpath_mask
, &ll_config
);
4211 vxge_debug_ll_config(VXGE_ERR
,
4212 "%s: No more vpaths to configure", VXGE_DRIVER_NAME
);
4217 /* Setting driver callbacks */
4218 attr
.uld_callbacks
.link_up
= vxge_callback_link_up
;
4219 attr
.uld_callbacks
.link_down
= vxge_callback_link_down
;
4220 attr
.uld_callbacks
.crit_err
= vxge_callback_crit_err
;
4222 status
= vxge_hw_device_initialize(&hldev
, &attr
, device_config
);
4223 if (status
!= VXGE_HW_OK
) {
4224 vxge_debug_init(VXGE_ERR
,
4225 "Failed to initialize device (%d)", status
);
4230 /* if FCS stripping is not disabled in MAC fail driver load */
4231 if (vxge_hw_vpath_strip_fcs_check(hldev
, vpath_mask
) != VXGE_HW_OK
) {
4232 vxge_debug_init(VXGE_ERR
,
4233 "%s: FCS stripping is not disabled in MAC"
4234 " failing driver load", VXGE_DRIVER_NAME
);
4239 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4241 /* set private device info */
4242 pci_set_drvdata(pdev
, hldev
);
4244 ll_config
.gro_enable
= VXGE_GRO_ALWAYS_AGGREGATE
;
4245 ll_config
.fifo_indicate_max_pkts
= VXGE_FIFO_INDICATE_MAX_PKTS
;
4246 ll_config
.addr_learn_en
= addr_learn_en
;
4247 ll_config
.rth_algorithm
= RTH_ALG_JENKINS
;
4248 ll_config
.rth_hash_type_tcpipv4
= VXGE_HW_RING_HASH_TYPE_TCP_IPV4
;
4249 ll_config
.rth_hash_type_ipv4
= VXGE_HW_RING_HASH_TYPE_NONE
;
4250 ll_config
.rth_hash_type_tcpipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4251 ll_config
.rth_hash_type_ipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4252 ll_config
.rth_hash_type_tcpipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4253 ll_config
.rth_hash_type_ipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4254 ll_config
.rth_bkt_sz
= RTH_BUCKET_SIZE
;
4255 ll_config
.tx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4256 ll_config
.rx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4258 if (vxge_device_register(hldev
, &ll_config
, high_dma
, no_of_vpath
,
4264 vxge_hw_device_debug_set(hldev
, VXGE_TRACE
, VXGE_COMPONENT_LL
);
4265 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4266 vxge_hw_device_trace_level_get(hldev
));
4268 /* set private HW device info */
4269 hldev
->ndev
= vdev
->ndev
;
4270 vdev
->mtu
= VXGE_HW_DEFAULT_MTU
;
4271 vdev
->bar0
= attr
.bar0
;
4272 vdev
->max_vpath_supported
= max_vpath_supported
;
4273 vdev
->no_of_vpath
= no_of_vpath
;
4275 /* Virtual Path count */
4276 for (i
= 0, j
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4277 if (!vxge_bVALn(vpath_mask
, i
, 1))
4279 if (j
>= vdev
->no_of_vpath
)
4282 vdev
->vpaths
[j
].is_configured
= 1;
4283 vdev
->vpaths
[j
].device_id
= i
;
4284 vdev
->vpaths
[j
].fifo
.driver_id
= j
;
4285 vdev
->vpaths
[j
].ring
.driver_id
= j
;
4286 vdev
->vpaths
[j
].vdev
= vdev
;
4287 vdev
->vpaths
[j
].max_mac_addr_cnt
= max_mac_vpath
;
4288 memcpy((u8
*)vdev
->vpaths
[j
].macaddr
,
4289 (u8
*)ll_config
.device_hw_info
.mac_addrs
[i
],
4292 /* Initialize the mac address list header */
4293 INIT_LIST_HEAD(&vdev
->vpaths
[j
].mac_addr_list
);
4295 vdev
->vpaths
[j
].mac_addr_cnt
= 0;
4296 vdev
->vpaths
[j
].mcast_addr_cnt
= 0;
4299 vdev
->exec_mode
= VXGE_EXEC_MODE_DISABLE
;
4300 vdev
->max_config_port
= max_config_port
;
4302 vdev
->vlan_tag_strip
= vlan_tag_strip
;
4304 /* map the hashing selector table to the configured vpaths */
4305 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4306 vdev
->vpath_selector
[i
] = vpath_selector
[i
];
4308 macaddr
= (u8
*)vdev
->vpaths
[0].macaddr
;
4310 ll_config
.device_hw_info
.serial_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4311 ll_config
.device_hw_info
.product_desc
[VXGE_HW_INFO_LEN
- 1] = '\0';
4312 ll_config
.device_hw_info
.part_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4314 vxge_debug_init(VXGE_TRACE
, "%s: SERIAL NUMBER: %s",
4315 vdev
->ndev
->name
, ll_config
.device_hw_info
.serial_number
);
4317 vxge_debug_init(VXGE_TRACE
, "%s: PART NUMBER: %s",
4318 vdev
->ndev
->name
, ll_config
.device_hw_info
.part_number
);
4320 vxge_debug_init(VXGE_TRACE
, "%s: Neterion %s Server Adapter",
4321 vdev
->ndev
->name
, ll_config
.device_hw_info
.product_desc
);
4323 vxge_debug_init(VXGE_TRACE
, "%s: MAC ADDR: %pM",
4324 vdev
->ndev
->name
, macaddr
);
4326 vxge_debug_init(VXGE_TRACE
, "%s: Link Width x%d",
4327 vdev
->ndev
->name
, vxge_hw_device_link_width_get(hldev
));
4329 vxge_debug_init(VXGE_TRACE
,
4330 "%s: Firmware version : %s Date : %s", vdev
->ndev
->name
,
4331 ll_config
.device_hw_info
.fw_version
.version
,
4332 ll_config
.device_hw_info
.fw_date
.date
);
4335 switch (ll_config
.device_hw_info
.function_mode
) {
4336 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
4337 vxge_debug_init(VXGE_TRACE
,
4338 "%s: Single Function Mode Enabled", vdev
->ndev
->name
);
4340 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
4341 vxge_debug_init(VXGE_TRACE
,
4342 "%s: Multi Function Mode Enabled", vdev
->ndev
->name
);
4344 case VXGE_HW_FUNCTION_MODE_SRIOV
:
4345 vxge_debug_init(VXGE_TRACE
,
4346 "%s: Single Root IOV Mode Enabled", vdev
->ndev
->name
);
4348 case VXGE_HW_FUNCTION_MODE_MRIOV
:
4349 vxge_debug_init(VXGE_TRACE
,
4350 "%s: Multi Root IOV Mode Enabled", vdev
->ndev
->name
);
4355 vxge_print_parm(vdev
, vpath_mask
);
4357 /* Store the fw version for ethttool option */
4358 strcpy(vdev
->fw_version
, ll_config
.device_hw_info
.fw_version
.version
);
4359 memcpy(vdev
->ndev
->dev_addr
, (u8
*)vdev
->vpaths
[0].macaddr
, ETH_ALEN
);
4360 memcpy(vdev
->ndev
->perm_addr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4362 /* Copy the station mac address to the list */
4363 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4364 entry
= (struct vxge_mac_addrs
*)
4365 kzalloc(sizeof(struct vxge_mac_addrs
),
4367 if (NULL
== entry
) {
4368 vxge_debug_init(VXGE_ERR
,
4369 "%s: mac_addr_list : memory allocation failed",
4374 macaddr
= (u8
*)&entry
->macaddr
;
4375 memcpy(macaddr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4376 list_add(&entry
->item
, &vdev
->vpaths
[i
].mac_addr_list
);
4377 vdev
->vpaths
[i
].mac_addr_cnt
= 1;
4380 kfree(device_config
);
4383 * INTA is shared in multi-function mode. This is unlike the INTA
4384 * implementation in MR mode, where each VH has its own INTA message.
4385 * - INTA is masked (disabled) as long as at least one function sets
4386 * its TITAN_MASK_ALL_INT.ALARM bit.
4387 * - INTA is unmasked (enabled) when all enabled functions have cleared
4388 * their own TITAN_MASK_ALL_INT.ALARM bit.
4389 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4390 * Though this driver leaves the top level interrupts unmasked while
4391 * leaving the required module interrupt bits masked on exit, there
4392 * could be a rougue driver around that does not follow this procedure
4393 * resulting in a failure to generate interrupts. The following code is
4394 * present to prevent such a failure.
4397 if (ll_config
.device_hw_info
.function_mode
==
4398 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
)
4399 if (vdev
->config
.intr_type
== INTA
)
4400 vxge_hw_device_unmask_all(hldev
);
4402 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
4403 vdev
->ndev
->name
, __func__
, __LINE__
);
4405 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4406 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4407 vxge_hw_device_trace_level_get(hldev
));
4412 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4413 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4415 vxge_device_unregister(hldev
);
4417 pci_disable_sriov(pdev
);
4418 vxge_hw_device_terminate(hldev
);
4422 pci_release_regions(pdev
);
4424 pci_disable_device(pdev
);
4426 kfree(device_config
);
4427 driver_config
->config_dev_cnt
--;
4428 pci_set_drvdata(pdev
, NULL
);
4433 * vxge_rem_nic - Free the PCI device
4434 * @pdev: structure containing the PCI related information of the device.
4435 * Description: This function is called by the Pci subsystem to release a
4436 * PCI device and free up all resource held up by the device.
4438 static void __devexit
4439 vxge_remove(struct pci_dev
*pdev
)
4441 struct __vxge_hw_device
*hldev
;
4442 struct vxgedev
*vdev
= NULL
;
4443 struct net_device
*dev
;
4445 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4446 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4450 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
4455 vdev
= netdev_priv(dev
);
4457 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4458 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4459 level_trace
= vdev
->level_trace
;
4461 vxge_debug_entryexit(level_trace
,
4462 "%s:%d", __func__
, __LINE__
);
4464 vxge_debug_init(level_trace
,
4465 "%s : removing PCI device...", __func__
);
4466 vxge_device_unregister(hldev
);
4468 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4469 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4470 vdev
->vpaths
[i
].mcast_addr_cnt
= 0;
4471 vdev
->vpaths
[i
].mac_addr_cnt
= 0;
4474 kfree(vdev
->vpaths
);
4476 iounmap(vdev
->bar0
);
4478 pci_disable_sriov(pdev
);
4480 /* we are safe to free it now */
4483 vxge_debug_init(level_trace
,
4484 "%s:%d Device unregistered", __func__
, __LINE__
);
4486 vxge_hw_device_terminate(hldev
);
4488 pci_disable_device(pdev
);
4489 pci_release_regions(pdev
);
4490 pci_set_drvdata(pdev
, NULL
);
4491 vxge_debug_entryexit(level_trace
,
4492 "%s:%d Exiting...", __func__
, __LINE__
);
4495 static struct pci_error_handlers vxge_err_handler
= {
4496 .error_detected
= vxge_io_error_detected
,
4497 .slot_reset
= vxge_io_slot_reset
,
4498 .resume
= vxge_io_resume
,
4501 static struct pci_driver vxge_driver
= {
4502 .name
= VXGE_DRIVER_NAME
,
4503 .id_table
= vxge_id_table
,
4504 .probe
= vxge_probe
,
4505 .remove
= __devexit_p(vxge_remove
),
4507 .suspend
= vxge_pm_suspend
,
4508 .resume
= vxge_pm_resume
,
4510 .err_handler
= &vxge_err_handler
,
4518 snprintf(version
, 32, "%s", DRV_VERSION
);
4520 printk(KERN_INFO
"%s: Copyright(c) 2002-2009 Neterion Inc\n",
4522 printk(KERN_INFO
"%s: Driver version: %s\n",
4523 VXGE_DRIVER_NAME
, version
);
4527 driver_config
= kzalloc(sizeof(struct vxge_drv_config
), GFP_KERNEL
);
4531 ret
= pci_register_driver(&vxge_driver
);
4533 if (driver_config
->config_dev_cnt
&&
4534 (driver_config
->config_dev_cnt
!= driver_config
->total_dev_cnt
))
4535 vxge_debug_init(VXGE_ERR
,
4536 "%s: Configured %d of %d devices",
4537 VXGE_DRIVER_NAME
, driver_config
->config_dev_cnt
,
4538 driver_config
->total_dev_cnt
);
4541 kfree(driver_config
);
4549 pci_unregister_driver(&vxge_driver
);
4550 kfree(driver_config
);
4552 module_init(vxge_starter
);
4553 module_exit(vxge_closer
);