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>
47 #include <linux/netdevice.h>
48 #include <linux/etherdevice.h>
49 #include "vxge-main.h"
52 MODULE_LICENSE("Dual BSD/GPL");
53 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
54 "Virtualized Server Adapter");
56 static struct pci_device_id vxge_id_table
[] __devinitdata
= {
57 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_WIN
, PCI_ANY_ID
,
59 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_UNI
, PCI_ANY_ID
,
64 MODULE_DEVICE_TABLE(pci
, vxge_id_table
);
66 VXGE_MODULE_PARAM_INT(vlan_tag_strip
, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
);
67 VXGE_MODULE_PARAM_INT(addr_learn_en
, VXGE_HW_MAC_ADDR_LEARN_DEFAULT
);
68 VXGE_MODULE_PARAM_INT(max_config_port
, VXGE_MAX_CONFIG_PORT
);
69 VXGE_MODULE_PARAM_INT(max_config_vpath
, VXGE_USE_DEFAULT
);
70 VXGE_MODULE_PARAM_INT(max_mac_vpath
, VXGE_MAX_MAC_ADDR_COUNT
);
71 VXGE_MODULE_PARAM_INT(max_config_dev
, VXGE_MAX_CONFIG_DEV
);
73 static u16 vpath_selector
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
74 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
75 static unsigned int bw_percentage
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
76 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS
- 1)] = 0xFF};
77 module_param_array(bw_percentage
, uint
, NULL
, 0);
79 static struct vxge_drv_config
*driver_config
;
81 static inline int is_vxge_card_up(struct vxgedev
*vdev
)
83 return test_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
86 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo
*fifo
)
88 unsigned long flags
= 0;
89 struct sk_buff
*skb_ptr
= NULL
;
90 struct sk_buff
**temp
, *head
, *skb
;
92 if (spin_trylock_irqsave(&fifo
->tx_lock
, flags
)) {
93 vxge_hw_vpath_poll_tx(fifo
->handle
, (void **)&skb_ptr
);
94 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
100 temp
= (struct sk_buff
**)&skb
->cb
;
103 dev_kfree_skb_irq(skb
);
107 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev
*vdev
)
111 /* Complete all transmits */
112 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
113 VXGE_COMPLETE_VPATH_TX(&vdev
->vpaths
[i
].fifo
);
116 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev
*vdev
)
119 struct vxge_ring
*ring
;
121 /* Complete all receives*/
122 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
123 ring
= &vdev
->vpaths
[i
].ring
;
124 vxge_hw_vpath_poll_rx(ring
->handle
);
129 * MultiQ manipulation helper functions
131 void vxge_stop_all_tx_queue(struct vxgedev
*vdev
)
134 struct net_device
*dev
= vdev
->ndev
;
136 if (vdev
->config
.tx_steering_type
!= TX_MULTIQ_STEERING
) {
137 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
138 vdev
->vpaths
[i
].fifo
.queue_state
= VPATH_QUEUE_STOP
;
140 netif_tx_stop_all_queues(dev
);
143 void vxge_stop_tx_queue(struct vxge_fifo
*fifo
)
145 struct net_device
*dev
= fifo
->ndev
;
147 struct netdev_queue
*txq
= NULL
;
148 if (fifo
->tx_steering_type
== TX_MULTIQ_STEERING
)
149 txq
= netdev_get_tx_queue(dev
, fifo
->driver_id
);
151 txq
= netdev_get_tx_queue(dev
, 0);
152 fifo
->queue_state
= VPATH_QUEUE_STOP
;
155 netif_tx_stop_queue(txq
);
158 void vxge_start_all_tx_queue(struct vxgedev
*vdev
)
161 struct net_device
*dev
= vdev
->ndev
;
163 if (vdev
->config
.tx_steering_type
!= TX_MULTIQ_STEERING
) {
164 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
165 vdev
->vpaths
[i
].fifo
.queue_state
= VPATH_QUEUE_START
;
167 netif_tx_start_all_queues(dev
);
170 static void vxge_wake_all_tx_queue(struct vxgedev
*vdev
)
173 struct net_device
*dev
= vdev
->ndev
;
175 if (vdev
->config
.tx_steering_type
!= TX_MULTIQ_STEERING
) {
176 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
177 vdev
->vpaths
[i
].fifo
.queue_state
= VPATH_QUEUE_START
;
179 netif_tx_wake_all_queues(dev
);
182 void vxge_wake_tx_queue(struct vxge_fifo
*fifo
, struct sk_buff
*skb
)
184 struct net_device
*dev
= fifo
->ndev
;
186 int vpath_no
= fifo
->driver_id
;
187 struct netdev_queue
*txq
= NULL
;
188 if (fifo
->tx_steering_type
== TX_MULTIQ_STEERING
) {
189 txq
= netdev_get_tx_queue(dev
, vpath_no
);
190 if (netif_tx_queue_stopped(txq
))
191 netif_tx_wake_queue(txq
);
193 txq
= netdev_get_tx_queue(dev
, 0);
194 if (fifo
->queue_state
== VPATH_QUEUE_STOP
)
195 if (netif_tx_queue_stopped(txq
)) {
196 fifo
->queue_state
= VPATH_QUEUE_START
;
197 netif_tx_wake_queue(txq
);
203 * vxge_callback_link_up
205 * This function is called during interrupt context to notify link up state
209 vxge_callback_link_up(struct __vxge_hw_device
*hldev
)
211 struct net_device
*dev
= hldev
->ndev
;
212 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
214 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
215 vdev
->ndev
->name
, __func__
, __LINE__
);
216 printk(KERN_NOTICE
"%s: Link Up\n", vdev
->ndev
->name
);
217 vdev
->stats
.link_up
++;
219 netif_carrier_on(vdev
->ndev
);
220 vxge_wake_all_tx_queue(vdev
);
222 vxge_debug_entryexit(VXGE_TRACE
,
223 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
227 * vxge_callback_link_down
229 * This function is called during interrupt context to notify link down state
233 vxge_callback_link_down(struct __vxge_hw_device
*hldev
)
235 struct net_device
*dev
= hldev
->ndev
;
236 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
238 vxge_debug_entryexit(VXGE_TRACE
,
239 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
240 printk(KERN_NOTICE
"%s: Link Down\n", vdev
->ndev
->name
);
242 vdev
->stats
.link_down
++;
243 netif_carrier_off(vdev
->ndev
);
244 vxge_stop_all_tx_queue(vdev
);
246 vxge_debug_entryexit(VXGE_TRACE
,
247 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
255 static struct sk_buff
*
256 vxge_rx_alloc(void *dtrh
, struct vxge_ring
*ring
, const int skb_size
)
258 struct net_device
*dev
;
260 struct vxge_rx_priv
*rx_priv
;
263 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
264 ring
->ndev
->name
, __func__
, __LINE__
);
266 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
268 /* try to allocate skb first. this one may fail */
269 skb
= netdev_alloc_skb(dev
, skb_size
+
270 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
272 vxge_debug_mem(VXGE_ERR
,
273 "%s: out of memory to allocate SKB", dev
->name
);
274 ring
->stats
.skb_alloc_fail
++;
278 vxge_debug_mem(VXGE_TRACE
,
279 "%s: %s:%d Skb : 0x%p", ring
->ndev
->name
,
280 __func__
, __LINE__
, skb
);
282 skb_reserve(skb
, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
285 rx_priv
->data_size
= skb_size
;
286 vxge_debug_entryexit(VXGE_TRACE
,
287 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
295 static int vxge_rx_map(void *dtrh
, struct vxge_ring
*ring
)
297 struct vxge_rx_priv
*rx_priv
;
300 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
301 ring
->ndev
->name
, __func__
, __LINE__
);
302 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
304 dma_addr
= pci_map_single(ring
->pdev
, rx_priv
->skb
->data
,
305 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
308 ring
->stats
.pci_map_fail
++;
311 vxge_debug_mem(VXGE_TRACE
,
312 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
313 ring
->ndev
->name
, __func__
, __LINE__
,
314 (unsigned long long)dma_addr
);
315 vxge_hw_ring_rxd_1b_set(dtrh
, dma_addr
, rx_priv
->data_size
);
317 rx_priv
->data_dma
= dma_addr
;
318 vxge_debug_entryexit(VXGE_TRACE
,
319 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
325 * vxge_rx_initial_replenish
326 * Allocation of RxD as an initial replenish procedure.
328 static enum vxge_hw_status
329 vxge_rx_initial_replenish(void *dtrh
, void *userdata
)
331 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
332 struct vxge_rx_priv
*rx_priv
;
334 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
335 ring
->ndev
->name
, __func__
, __LINE__
);
336 if (vxge_rx_alloc(dtrh
, ring
,
337 VXGE_LL_MAX_FRAME_SIZE(ring
->ndev
)) == NULL
)
340 if (vxge_rx_map(dtrh
, ring
)) {
341 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
342 dev_kfree_skb(rx_priv
->skb
);
346 vxge_debug_entryexit(VXGE_TRACE
,
347 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
353 vxge_rx_complete(struct vxge_ring
*ring
, struct sk_buff
*skb
, u16 vlan
,
354 int pkt_length
, struct vxge_hw_ring_rxd_info
*ext_info
)
357 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
358 ring
->ndev
->name
, __func__
, __LINE__
);
359 skb_record_rx_queue(skb
, ring
->driver_id
);
360 skb
->protocol
= eth_type_trans(skb
, ring
->ndev
);
362 ring
->stats
.rx_frms
++;
363 ring
->stats
.rx_bytes
+= pkt_length
;
365 if (skb
->pkt_type
== PACKET_MULTICAST
)
366 ring
->stats
.rx_mcast
++;
368 vxge_debug_rx(VXGE_TRACE
,
369 "%s: %s:%d skb protocol = %d",
370 ring
->ndev
->name
, __func__
, __LINE__
, skb
->protocol
);
372 if (ring
->gro_enable
) {
373 if (ring
->vlgrp
&& ext_info
->vlan
&&
374 (ring
->vlan_tag_strip
==
375 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
))
376 vlan_gro_receive(&ring
->napi
, ring
->vlgrp
,
377 ext_info
->vlan
, skb
);
379 napi_gro_receive(&ring
->napi
, skb
);
381 if (ring
->vlgrp
&& vlan
&&
382 (ring
->vlan_tag_strip
==
383 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
))
384 vlan_hwaccel_receive_skb(skb
, ring
->vlgrp
, vlan
);
386 netif_receive_skb(skb
);
388 vxge_debug_entryexit(VXGE_TRACE
,
389 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
392 static inline void vxge_re_pre_post(void *dtr
, struct vxge_ring
*ring
,
393 struct vxge_rx_priv
*rx_priv
)
395 pci_dma_sync_single_for_device(ring
->pdev
,
396 rx_priv
->data_dma
, rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
398 vxge_hw_ring_rxd_1b_set(dtr
, rx_priv
->data_dma
, rx_priv
->data_size
);
399 vxge_hw_ring_rxd_pre_post(ring
->handle
, dtr
);
402 static inline void vxge_post(int *dtr_cnt
, void **first_dtr
,
403 void *post_dtr
, struct __vxge_hw_ring
*ringh
)
405 int dtr_count
= *dtr_cnt
;
406 if ((*dtr_cnt
% VXGE_HW_RXSYNC_FREQ_CNT
) == 0) {
408 vxge_hw_ring_rxd_post_post_wmb(ringh
, *first_dtr
);
409 *first_dtr
= post_dtr
;
411 vxge_hw_ring_rxd_post_post(ringh
, post_dtr
);
413 *dtr_cnt
= dtr_count
;
419 * If the interrupt is because of a received frame or if the receive ring
420 * contains fresh as yet un-processed frames, this function is called.
423 vxge_rx_1b_compl(struct __vxge_hw_ring
*ringh
, void *dtr
,
424 u8 t_code
, void *userdata
)
426 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
427 struct net_device
*dev
= ring
->ndev
;
428 unsigned int dma_sizes
;
429 void *first_dtr
= NULL
;
435 struct vxge_rx_priv
*rx_priv
;
436 struct vxge_hw_ring_rxd_info ext_info
;
437 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
438 ring
->ndev
->name
, __func__
, __LINE__
);
439 ring
->pkts_processed
= 0;
441 vxge_hw_ring_replenish(ringh
, 0);
444 rx_priv
= vxge_hw_ring_rxd_private_get(dtr
);
446 data_size
= rx_priv
->data_size
;
447 data_dma
= rx_priv
->data_dma
;
449 vxge_debug_rx(VXGE_TRACE
,
450 "%s: %s:%d skb = 0x%p",
451 ring
->ndev
->name
, __func__
, __LINE__
, skb
);
453 vxge_hw_ring_rxd_1b_get(ringh
, dtr
, &dma_sizes
);
454 pkt_length
= dma_sizes
;
456 vxge_debug_rx(VXGE_TRACE
,
457 "%s: %s:%d Packet Length = %d",
458 ring
->ndev
->name
, __func__
, __LINE__
, pkt_length
);
460 vxge_hw_ring_rxd_1b_info_get(ringh
, dtr
, &ext_info
);
462 /* check skb validity */
465 prefetch((char *)skb
+ L1_CACHE_BYTES
);
466 if (unlikely(t_code
)) {
468 if (vxge_hw_ring_handle_tcode(ringh
, dtr
, t_code
) !=
471 ring
->stats
.rx_errors
++;
472 vxge_debug_rx(VXGE_TRACE
,
473 "%s: %s :%d Rx T_code is %d",
474 ring
->ndev
->name
, __func__
,
477 /* If the t_code is not supported and if the
478 * t_code is other than 0x5 (unparseable packet
479 * such as unknown UPV6 header), Drop it !!!
481 vxge_re_pre_post(dtr
, ring
, rx_priv
);
483 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
484 ring
->stats
.rx_dropped
++;
489 if (pkt_length
> VXGE_LL_RX_COPY_THRESHOLD
) {
491 if (vxge_rx_alloc(dtr
, ring
, data_size
) != NULL
) {
493 if (!vxge_rx_map(dtr
, ring
)) {
494 skb_put(skb
, pkt_length
);
496 pci_unmap_single(ring
->pdev
, data_dma
,
497 data_size
, PCI_DMA_FROMDEVICE
);
499 vxge_hw_ring_rxd_pre_post(ringh
, dtr
);
500 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
503 dev_kfree_skb(rx_priv
->skb
);
505 rx_priv
->data_size
= data_size
;
506 vxge_re_pre_post(dtr
, ring
, rx_priv
);
508 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
510 ring
->stats
.rx_dropped
++;
514 vxge_re_pre_post(dtr
, ring
, rx_priv
);
516 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
517 ring
->stats
.rx_dropped
++;
521 struct sk_buff
*skb_up
;
523 skb_up
= netdev_alloc_skb(dev
, pkt_length
+
524 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
525 if (skb_up
!= NULL
) {
527 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
529 pci_dma_sync_single_for_cpu(ring
->pdev
,
533 vxge_debug_mem(VXGE_TRACE
,
534 "%s: %s:%d skb_up = %p",
535 ring
->ndev
->name
, __func__
,
537 memcpy(skb_up
->data
, skb
->data
, pkt_length
);
539 vxge_re_pre_post(dtr
, ring
, rx_priv
);
541 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
543 /* will netif_rx small SKB instead */
545 skb_put(skb
, pkt_length
);
547 vxge_re_pre_post(dtr
, ring
, rx_priv
);
549 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
550 vxge_debug_rx(VXGE_ERR
,
551 "%s: vxge_rx_1b_compl: out of "
552 "memory", dev
->name
);
553 ring
->stats
.skb_alloc_fail
++;
558 if ((ext_info
.proto
& VXGE_HW_FRAME_PROTO_TCP_OR_UDP
) &&
559 !(ext_info
.proto
& VXGE_HW_FRAME_PROTO_IP_FRAG
) &&
560 ring
->rx_csum
&& /* Offload Rx side CSUM */
561 ext_info
.l3_cksum
== VXGE_HW_L3_CKSUM_OK
&&
562 ext_info
.l4_cksum
== VXGE_HW_L4_CKSUM_OK
)
563 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
565 skb
->ip_summed
= CHECKSUM_NONE
;
567 vxge_rx_complete(ring
, skb
, ext_info
.vlan
,
568 pkt_length
, &ext_info
);
571 ring
->pkts_processed
++;
575 } while (vxge_hw_ring_rxd_next_completed(ringh
, &dtr
,
576 &t_code
) == VXGE_HW_OK
);
579 vxge_hw_ring_rxd_post_post_wmb(ringh
, first_dtr
);
581 dev
->last_rx
= jiffies
;
583 vxge_debug_entryexit(VXGE_TRACE
,
592 * If an interrupt was raised to indicate DMA complete of the Tx packet,
593 * this function is called. It identifies the last TxD whose buffer was
594 * freed and frees all skbs whose data have already DMA'ed into the NICs
598 vxge_xmit_compl(struct __vxge_hw_fifo
*fifo_hw
, void *dtr
,
599 enum vxge_hw_fifo_tcode t_code
, void *userdata
,
602 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
603 struct sk_buff
*skb
, *head
= NULL
;
604 struct sk_buff
**temp
;
607 vxge_debug_entryexit(VXGE_TRACE
,
608 "%s:%d Entered....", __func__
, __LINE__
);
614 struct vxge_tx_priv
*txd_priv
=
615 vxge_hw_fifo_txdl_private_get(dtr
);
618 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
619 frag
= &skb_shinfo(skb
)->frags
[0];
621 vxge_debug_tx(VXGE_TRACE
,
622 "%s: %s:%d fifo_hw = %p dtr = %p "
623 "tcode = 0x%x", fifo
->ndev
->name
, __func__
,
624 __LINE__
, fifo_hw
, dtr
, t_code
);
625 /* check skb validity */
627 vxge_debug_tx(VXGE_TRACE
,
628 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
629 fifo
->ndev
->name
, __func__
, __LINE__
,
630 skb
, txd_priv
, frg_cnt
);
631 if (unlikely(t_code
)) {
632 fifo
->stats
.tx_errors
++;
633 vxge_debug_tx(VXGE_ERR
,
634 "%s: tx: dtr %p completed due to "
635 "error t_code %01x", fifo
->ndev
->name
,
637 vxge_hw_fifo_handle_tcode(fifo_hw
, dtr
, t_code
);
640 /* for unfragmented skb */
641 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
642 skb_headlen(skb
), PCI_DMA_TODEVICE
);
644 for (j
= 0; j
< frg_cnt
; j
++) {
645 pci_unmap_page(fifo
->pdev
,
646 txd_priv
->dma_buffers
[i
++],
647 frag
->size
, PCI_DMA_TODEVICE
);
651 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
653 /* Updating the statistics block */
654 fifo
->stats
.tx_frms
++;
655 fifo
->stats
.tx_bytes
+= skb
->len
;
657 temp
= (struct sk_buff
**)&skb
->cb
;
662 if (pkt_cnt
> fifo
->indicate_max_pkts
)
665 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw
,
666 &dtr
, &t_code
) == VXGE_HW_OK
);
668 vxge_wake_tx_queue(fifo
, skb
);
671 *skb_ptr
= (void *) head
;
673 vxge_debug_entryexit(VXGE_TRACE
,
674 "%s: %s:%d Exiting...",
675 fifo
->ndev
->name
, __func__
, __LINE__
);
679 /* select a vpath to trasmit the packet */
680 static u32
vxge_get_vpath_no(struct vxgedev
*vdev
, struct sk_buff
*skb
,
683 u16 queue_len
, counter
= 0;
684 if (skb
->protocol
== htons(ETH_P_IP
)) {
690 if ((ip
->frag_off
& htons(IP_OFFSET
|IP_MF
)) == 0) {
691 th
= (struct tcphdr
*)(((unsigned char *)ip
) +
694 queue_len
= vdev
->no_of_vpath
;
695 counter
= (ntohs(th
->source
) +
697 vdev
->vpath_selector
[queue_len
- 1];
698 if (counter
>= queue_len
)
699 counter
= queue_len
- 1;
701 if (ip
->protocol
== IPPROTO_UDP
) {
711 static enum vxge_hw_status
vxge_search_mac_addr_in_list(
712 struct vxge_vpath
*vpath
, u64 del_mac
)
714 struct list_head
*entry
, *next
;
715 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
716 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
)
722 static int vxge_learn_mac(struct vxgedev
*vdev
, u8
*mac_header
)
724 struct macInfo mac_info
;
725 u8
*mac_address
= NULL
;
726 u64 mac_addr
= 0, vpath_vector
= 0;
728 enum vxge_hw_status status
= VXGE_HW_OK
;
729 struct vxge_vpath
*vpath
= NULL
;
730 struct __vxge_hw_device
*hldev
;
732 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
734 mac_address
= (u8
*)&mac_addr
;
735 memcpy(mac_address
, mac_header
, ETH_ALEN
);
737 /* Is this mac address already in the list? */
738 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
739 vpath
= &vdev
->vpaths
[vpath_idx
];
740 if (vxge_search_mac_addr_in_list(vpath
, mac_addr
))
744 memset(&mac_info
, 0, sizeof(struct macInfo
));
745 memcpy(mac_info
.macaddr
, mac_header
, ETH_ALEN
);
747 /* Any vpath has room to add mac address to its da table? */
748 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
749 vpath
= &vdev
->vpaths
[vpath_idx
];
750 if (vpath
->mac_addr_cnt
< vpath
->max_mac_addr_cnt
) {
751 /* Add this mac address to this vpath */
752 mac_info
.vpath_no
= vpath_idx
;
753 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
754 status
= vxge_add_mac_addr(vdev
, &mac_info
);
755 if (status
!= VXGE_HW_OK
)
761 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_LIST
;
763 mac_info
.vpath_no
= vpath_idx
;
764 /* Is the first vpath already selected as catch-basin ? */
765 vpath
= &vdev
->vpaths
[vpath_idx
];
766 if (vpath
->mac_addr_cnt
> vpath
->max_mac_addr_cnt
) {
767 /* Add this mac address to this vpath */
768 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
773 /* Select first vpath as catch-basin */
774 vpath_vector
= vxge_mBIT(vpath
->device_id
);
775 status
= vxge_hw_mgmt_reg_write(vpath
->vdev
->devh
,
776 vxge_hw_mgmt_reg_type_mrpcim
,
779 struct vxge_hw_mrpcim_reg
,
782 if (status
!= VXGE_HW_OK
) {
783 vxge_debug_tx(VXGE_ERR
,
784 "%s: Unable to set the vpath-%d in catch-basin mode",
785 VXGE_DRIVER_NAME
, vpath
->device_id
);
789 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
797 * @skb : the socket buffer containing the Tx data.
798 * @dev : device pointer.
800 * This function is the Tx entry point of the driver. Neterion NIC supports
801 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
802 * NOTE: when device cant queue the pkt, just the trans_start variable will
806 vxge_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
808 struct vxge_fifo
*fifo
= NULL
;
811 struct vxgedev
*vdev
= NULL
;
812 enum vxge_hw_status status
;
813 int frg_cnt
, first_frg_len
;
815 int i
= 0, j
= 0, avail
;
817 struct vxge_tx_priv
*txdl_priv
= NULL
;
818 struct __vxge_hw_fifo
*fifo_hw
;
821 unsigned long flags
= 0;
823 int do_spin_tx_lock
= 1;
825 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
826 dev
->name
, __func__
, __LINE__
);
828 /* A buffer with no data will be dropped */
829 if (unlikely(skb
->len
<= 0)) {
830 vxge_debug_tx(VXGE_ERR
,
831 "%s: Buffer has no data..", dev
->name
);
836 vdev
= (struct vxgedev
*)netdev_priv(dev
);
838 if (unlikely(!is_vxge_card_up(vdev
))) {
839 vxge_debug_tx(VXGE_ERR
,
840 "%s: vdev not initialized", dev
->name
);
845 if (vdev
->config
.addr_learn_en
) {
846 vpath_no
= vxge_learn_mac(vdev
, skb
->data
+ ETH_ALEN
);
847 if (vpath_no
== -EPERM
) {
848 vxge_debug_tx(VXGE_ERR
,
849 "%s: Failed to store the mac address",
856 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
)
857 vpath_no
= skb_get_queue_mapping(skb
);
858 else if (vdev
->config
.tx_steering_type
== TX_PORT_STEERING
)
859 vpath_no
= vxge_get_vpath_no(vdev
, skb
, &do_spin_tx_lock
);
861 vxge_debug_tx(VXGE_TRACE
, "%s: vpath_no= %d", dev
->name
, vpath_no
);
863 if (vpath_no
>= vdev
->no_of_vpath
)
866 fifo
= &vdev
->vpaths
[vpath_no
].fifo
;
867 fifo_hw
= fifo
->handle
;
870 spin_lock_irqsave(&fifo
->tx_lock
, flags
);
872 if (unlikely(!spin_trylock_irqsave(&fifo
->tx_lock
, flags
)))
873 return NETDEV_TX_LOCKED
;
876 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
) {
877 if (netif_subqueue_stopped(dev
, skb
)) {
878 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
879 return NETDEV_TX_BUSY
;
881 } else if (unlikely(fifo
->queue_state
== VPATH_QUEUE_STOP
)) {
882 if (netif_queue_stopped(dev
)) {
883 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
884 return NETDEV_TX_BUSY
;
887 avail
= vxge_hw_fifo_free_txdl_count_get(fifo_hw
);
889 vxge_debug_tx(VXGE_ERR
,
890 "%s: No free TXDs available", dev
->name
);
891 fifo
->stats
.txd_not_free
++;
892 vxge_stop_tx_queue(fifo
);
896 status
= vxge_hw_fifo_txdl_reserve(fifo_hw
, &dtr
, &dtr_priv
);
897 if (unlikely(status
!= VXGE_HW_OK
)) {
898 vxge_debug_tx(VXGE_ERR
,
899 "%s: Out of descriptors .", dev
->name
);
900 fifo
->stats
.txd_out_of_desc
++;
901 vxge_stop_tx_queue(fifo
);
905 vxge_debug_tx(VXGE_TRACE
,
906 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
907 dev
->name
, __func__
, __LINE__
,
908 fifo_hw
, dtr
, dtr_priv
);
910 if (vdev
->vlgrp
&& vlan_tx_tag_present(skb
)) {
911 u16 vlan_tag
= vlan_tx_tag_get(skb
);
912 vxge_hw_fifo_txdl_vlan_set(dtr
, vlan_tag
);
915 first_frg_len
= skb_headlen(skb
);
917 dma_pointer
= pci_map_single(fifo
->pdev
, skb
->data
, first_frg_len
,
920 if (unlikely(pci_dma_mapping_error(fifo
->pdev
, dma_pointer
))) {
921 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
922 vxge_stop_tx_queue(fifo
);
923 fifo
->stats
.pci_map_fail
++;
927 txdl_priv
= vxge_hw_fifo_txdl_private_get(dtr
);
928 txdl_priv
->skb
= skb
;
929 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
931 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
932 vxge_debug_tx(VXGE_TRACE
,
933 "%s: %s:%d skb = %p txdl_priv = %p "
934 "frag_cnt = %d dma_pointer = 0x%llx", dev
->name
,
935 __func__
, __LINE__
, skb
, txdl_priv
,
936 frg_cnt
, (unsigned long long)dma_pointer
);
938 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
941 frag
= &skb_shinfo(skb
)->frags
[0];
942 for (i
= 0; i
< frg_cnt
; i
++) {
943 /* ignore 0 length fragment */
948 (u64
)pci_map_page(fifo
->pdev
, frag
->page
,
949 frag
->page_offset
, frag
->size
,
952 if (unlikely(pci_dma_mapping_error(fifo
->pdev
, dma_pointer
)))
954 vxge_debug_tx(VXGE_TRACE
,
955 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
956 dev
->name
, __func__
, __LINE__
, i
,
957 (unsigned long long)dma_pointer
);
959 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
960 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
965 offload_type
= vxge_offload_type(skb
);
967 if (offload_type
& (SKB_GSO_TCPV4
| SKB_GSO_TCPV6
)) {
969 int mss
= vxge_tcp_mss(skb
);
971 max_mss
= dev
->mtu
+ ETH_HLEN
-
972 VXGE_HW_TCPIP_HEADER_MAX_SIZE
;
975 vxge_debug_tx(VXGE_TRACE
,
976 "%s: %s:%d mss = %d",
977 dev
->name
, __func__
, __LINE__
, mss
);
978 vxge_hw_fifo_txdl_mss_set(dtr
, mss
);
980 vxge_assert(skb
->len
<=
981 dev
->mtu
+ VXGE_HW_MAC_HEADER_MAX_SIZE
);
987 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
988 vxge_hw_fifo_txdl_cksum_set_bits(dtr
,
989 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN
|
990 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN
|
991 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN
);
993 vxge_hw_fifo_txdl_post(fifo_hw
, dtr
);
994 dev
->trans_start
= jiffies
;
995 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
997 VXGE_COMPLETE_VPATH_TX(fifo
);
998 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
999 dev
->name
, __func__
, __LINE__
);
1003 vxge_debug_tx(VXGE_TRACE
, "%s: pci_map_page failed", dev
->name
);
1007 frag
= &skb_shinfo(skb
)->frags
[0];
1009 pci_unmap_single(fifo
->pdev
, txdl_priv
->dma_buffers
[j
++],
1010 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1012 for (; j
< i
; j
++) {
1013 pci_unmap_page(fifo
->pdev
, txdl_priv
->dma_buffers
[j
],
1014 frag
->size
, PCI_DMA_TODEVICE
);
1018 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
1021 spin_unlock_irqrestore(&fifo
->tx_lock
, flags
);
1022 VXGE_COMPLETE_VPATH_TX(fifo
);
1030 * Function will be called by hw function to abort all outstanding receive
1034 vxge_rx_term(void *dtrh
, enum vxge_hw_rxd_state state
, void *userdata
)
1036 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
1037 struct vxge_rx_priv
*rx_priv
=
1038 vxge_hw_ring_rxd_private_get(dtrh
);
1040 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
1041 ring
->ndev
->name
, __func__
, __LINE__
);
1042 if (state
!= VXGE_HW_RXD_STATE_POSTED
)
1045 pci_unmap_single(ring
->pdev
, rx_priv
->data_dma
,
1046 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
1048 dev_kfree_skb(rx_priv
->skb
);
1050 vxge_debug_entryexit(VXGE_TRACE
,
1051 "%s: %s:%d Exiting...",
1052 ring
->ndev
->name
, __func__
, __LINE__
);
1058 * Function will be called to abort all outstanding tx descriptors
1061 vxge_tx_term(void *dtrh
, enum vxge_hw_txdl_state state
, void *userdata
)
1063 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
1065 int i
= 0, j
, frg_cnt
;
1066 struct vxge_tx_priv
*txd_priv
= vxge_hw_fifo_txdl_private_get(dtrh
);
1067 struct sk_buff
*skb
= txd_priv
->skb
;
1069 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1071 if (state
!= VXGE_HW_TXDL_STATE_POSTED
)
1074 /* check skb validity */
1076 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
1077 frag
= &skb_shinfo(skb
)->frags
[0];
1079 /* for unfragmented skb */
1080 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
1081 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1083 for (j
= 0; j
< frg_cnt
; j
++) {
1084 pci_unmap_page(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
1085 frag
->size
, PCI_DMA_TODEVICE
);
1091 vxge_debug_entryexit(VXGE_TRACE
,
1092 "%s:%d Exiting...", __func__
, __LINE__
);
1096 * vxge_set_multicast
1097 * @dev: pointer to the device structure
1099 * Entry point for multicast address enable/disable
1100 * This function is a driver entry point which gets called by the kernel
1101 * whenever multicast addresses must be enabled/disabled. This also gets
1102 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1103 * determine, if multicast address must be enabled or if promiscuous mode
1104 * is to be disabled etc.
1106 static void vxge_set_multicast(struct net_device
*dev
)
1108 struct dev_mc_list
*mclist
;
1109 struct vxgedev
*vdev
;
1110 int i
, mcast_cnt
= 0;
1111 struct __vxge_hw_device
*hldev
;
1112 enum vxge_hw_status status
= VXGE_HW_OK
;
1113 struct macInfo mac_info
;
1115 struct vxge_mac_addrs
*mac_entry
;
1116 struct list_head
*list_head
;
1117 struct list_head
*entry
, *next
;
1118 u8
*mac_address
= NULL
;
1120 vxge_debug_entryexit(VXGE_TRACE
,
1121 "%s:%d", __func__
, __LINE__
);
1123 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1124 hldev
= (struct __vxge_hw_device
*)vdev
->devh
;
1126 if (unlikely(!is_vxge_card_up(vdev
)))
1129 if ((dev
->flags
& IFF_ALLMULTI
) && (!vdev
->all_multi_flg
)) {
1130 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1131 vxge_assert(vdev
->vpaths
[i
].is_open
);
1132 status
= vxge_hw_vpath_mcast_enable(
1133 vdev
->vpaths
[i
].handle
);
1134 vdev
->all_multi_flg
= 1;
1136 } else if ((dev
->flags
& IFF_ALLMULTI
) && (vdev
->all_multi_flg
)) {
1137 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1138 vxge_assert(vdev
->vpaths
[i
].is_open
);
1139 status
= vxge_hw_vpath_mcast_disable(
1140 vdev
->vpaths
[i
].handle
);
1141 vdev
->all_multi_flg
= 1;
1145 if (status
!= VXGE_HW_OK
)
1146 vxge_debug_init(VXGE_ERR
,
1147 "failed to %s multicast, status %d",
1148 dev
->flags
& IFF_ALLMULTI
?
1149 "enable" : "disable", status
);
1151 if (!vdev
->config
.addr_learn_en
) {
1152 if (dev
->flags
& IFF_PROMISC
) {
1153 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1154 vxge_assert(vdev
->vpaths
[i
].is_open
);
1155 status
= vxge_hw_vpath_promisc_enable(
1156 vdev
->vpaths
[i
].handle
);
1159 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1160 vxge_assert(vdev
->vpaths
[i
].is_open
);
1161 status
= vxge_hw_vpath_promisc_disable(
1162 vdev
->vpaths
[i
].handle
);
1167 memset(&mac_info
, 0, sizeof(struct macInfo
));
1168 /* Update individual M_CAST address list */
1169 if ((!vdev
->all_multi_flg
) && dev
->mc_count
) {
1171 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1172 list_head
= &vdev
->vpaths
[0].mac_addr_list
;
1173 if ((dev
->mc_count
+
1174 (vdev
->vpaths
[0].mac_addr_cnt
- mcast_cnt
)) >
1175 vdev
->vpaths
[0].max_mac_addr_cnt
)
1176 goto _set_all_mcast
;
1178 /* Delete previous MC's */
1179 for (i
= 0; i
< mcast_cnt
; i
++) {
1180 if (!list_empty(list_head
))
1181 mac_entry
= (struct vxge_mac_addrs
*)
1182 list_first_entry(list_head
,
1183 struct vxge_mac_addrs
,
1186 list_for_each_safe(entry
, next
, list_head
) {
1188 mac_entry
= (struct vxge_mac_addrs
*) entry
;
1189 /* Copy the mac address to delete */
1190 mac_address
= (u8
*)&mac_entry
->macaddr
;
1191 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1193 /* Is this a multicast address */
1194 if (0x01 & mac_info
.macaddr
[0]) {
1195 for (vpath_idx
= 0; vpath_idx
<
1198 mac_info
.vpath_no
= vpath_idx
;
1199 status
= vxge_del_mac_addr(
1208 for (i
= 0, mclist
= dev
->mc_list
; i
< dev
->mc_count
;
1209 i
++, mclist
= mclist
->next
) {
1211 memcpy(mac_info
.macaddr
, mclist
->dmi_addr
, ETH_ALEN
);
1212 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1214 mac_info
.vpath_no
= vpath_idx
;
1215 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1216 status
= vxge_add_mac_addr(vdev
, &mac_info
);
1217 if (status
!= VXGE_HW_OK
) {
1218 vxge_debug_init(VXGE_ERR
,
1219 "%s:%d Setting individual"
1220 "multicast address failed",
1221 __func__
, __LINE__
);
1222 goto _set_all_mcast
;
1229 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1230 /* Delete previous MC's */
1231 for (i
= 0; i
< mcast_cnt
; i
++) {
1233 list_for_each_safe(entry
, next
, list_head
) {
1235 mac_entry
= (struct vxge_mac_addrs
*) entry
;
1236 /* Copy the mac address to delete */
1237 mac_address
= (u8
*)&mac_entry
->macaddr
;
1238 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1240 /* Is this a multicast address */
1241 if (0x01 & mac_info
.macaddr
[0])
1245 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1247 mac_info
.vpath_no
= vpath_idx
;
1248 status
= vxge_del_mac_addr(vdev
, &mac_info
);
1252 /* Enable all multicast */
1253 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1254 vxge_assert(vdev
->vpaths
[i
].is_open
);
1255 status
= vxge_hw_vpath_mcast_enable(
1256 vdev
->vpaths
[i
].handle
);
1257 if (status
!= VXGE_HW_OK
) {
1258 vxge_debug_init(VXGE_ERR
,
1259 "%s:%d Enabling all multicasts failed",
1260 __func__
, __LINE__
);
1262 vdev
->all_multi_flg
= 1;
1264 dev
->flags
|= IFF_ALLMULTI
;
1267 vxge_debug_entryexit(VXGE_TRACE
,
1268 "%s:%d Exiting...", __func__
, __LINE__
);
1273 * @dev: pointer to the device structure
1275 * Update entry "0" (default MAC addr)
1277 static int vxge_set_mac_addr(struct net_device
*dev
, void *p
)
1279 struct sockaddr
*addr
= p
;
1280 struct vxgedev
*vdev
;
1281 struct __vxge_hw_device
*hldev
;
1282 enum vxge_hw_status status
= VXGE_HW_OK
;
1283 struct macInfo mac_info_new
, mac_info_old
;
1286 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1288 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1291 if (!is_valid_ether_addr(addr
->sa_data
))
1294 memset(&mac_info_new
, 0, sizeof(struct macInfo
));
1295 memset(&mac_info_old
, 0, sizeof(struct macInfo
));
1297 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d Exiting...",
1298 __func__
, __LINE__
);
1300 /* Get the old address */
1301 memcpy(mac_info_old
.macaddr
, dev
->dev_addr
, dev
->addr_len
);
1303 /* Copy the new address */
1304 memcpy(mac_info_new
.macaddr
, addr
->sa_data
, dev
->addr_len
);
1306 /* First delete the old mac address from all the vpaths
1307 as we can't specify the index while adding new mac address */
1308 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1309 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vpath_idx
];
1310 if (!vpath
->is_open
) {
1311 /* This can happen when this interface is added/removed
1312 to the bonding interface. Delete this station address
1313 from the linked list */
1314 vxge_mac_list_del(vpath
, &mac_info_old
);
1316 /* Add this new address to the linked list
1317 for later restoring */
1318 vxge_mac_list_add(vpath
, &mac_info_new
);
1322 /* Delete the station address */
1323 mac_info_old
.vpath_no
= vpath_idx
;
1324 status
= vxge_del_mac_addr(vdev
, &mac_info_old
);
1327 if (unlikely(!is_vxge_card_up(vdev
))) {
1328 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1332 /* Set this mac address to all the vpaths */
1333 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1334 mac_info_new
.vpath_no
= vpath_idx
;
1335 mac_info_new
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1336 status
= vxge_add_mac_addr(vdev
, &mac_info_new
);
1337 if (status
!= VXGE_HW_OK
)
1341 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1347 * vxge_vpath_intr_enable
1348 * @vdev: pointer to vdev
1349 * @vp_id: vpath for which to enable the interrupts
1351 * Enables the interrupts for the vpath
1353 void vxge_vpath_intr_enable(struct vxgedev
*vdev
, int vp_id
)
1355 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1356 int msix_id
, alarm_msix_id
;
1357 int tim_msix_id
[4] = {[0 ...3] = 0};
1359 vxge_hw_vpath_intr_enable(vpath
->handle
);
1361 if (vdev
->config
.intr_type
== INTA
)
1362 vxge_hw_vpath_inta_unmask_tx_rx(vpath
->handle
);
1364 msix_id
= vp_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1366 VXGE_HW_VPATH_MSIX_ACTIVE
* vdev
->no_of_vpath
- 2;
1368 tim_msix_id
[0] = msix_id
;
1369 tim_msix_id
[1] = msix_id
+ 1;
1370 vxge_hw_vpath_msix_set(vpath
->handle
, tim_msix_id
,
1373 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
);
1374 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
+ 1);
1376 /* enable the alarm vector */
1377 vxge_hw_vpath_msix_unmask(vpath
->handle
, alarm_msix_id
);
1382 * vxge_vpath_intr_disable
1383 * @vdev: pointer to vdev
1384 * @vp_id: vpath for which to disable the interrupts
1386 * Disables the interrupts for the vpath
1388 void vxge_vpath_intr_disable(struct vxgedev
*vdev
, int vp_id
)
1390 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1393 vxge_hw_vpath_intr_disable(vpath
->handle
);
1395 if (vdev
->config
.intr_type
== INTA
)
1396 vxge_hw_vpath_inta_mask_tx_rx(vpath
->handle
);
1398 msix_id
= vp_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1399 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1400 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
+ 1);
1402 /* disable the alarm vector */
1403 msix_id
= VXGE_HW_VPATH_MSIX_ACTIVE
* vdev
->no_of_vpath
- 2;
1404 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1410 * @vdev: pointer to vdev
1411 * @vp_id: vpath to reset
1415 static int vxge_reset_vpath(struct vxgedev
*vdev
, int vp_id
)
1417 enum vxge_hw_status status
= VXGE_HW_OK
;
1420 /* check if device is down already */
1421 if (unlikely(!is_vxge_card_up(vdev
)))
1424 /* is device reset already scheduled */
1425 if (test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1428 if (vdev
->vpaths
[vp_id
].handle
) {
1429 if (vxge_hw_vpath_reset(vdev
->vpaths
[vp_id
].handle
)
1431 if (is_vxge_card_up(vdev
) &&
1432 vxge_hw_vpath_recover_from_reset(
1433 vdev
->vpaths
[vp_id
].handle
)
1435 vxge_debug_init(VXGE_ERR
,
1436 "vxge_hw_vpath_recover_from_reset"
1437 "failed for vpath:%d", vp_id
);
1441 vxge_debug_init(VXGE_ERR
,
1442 "vxge_hw_vpath_reset failed for"
1447 return VXGE_HW_FAIL
;
1449 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[vp_id
]);
1450 vxge_restore_vpath_vid_table(&vdev
->vpaths
[vp_id
]);
1452 /* Enable all broadcast */
1453 vxge_hw_vpath_bcast_enable(vdev
->vpaths
[vp_id
].handle
);
1455 /* Enable the interrupts */
1456 vxge_vpath_intr_enable(vdev
, vp_id
);
1460 /* Enable the flow of traffic through the vpath */
1461 vxge_hw_vpath_enable(vdev
->vpaths
[vp_id
].handle
);
1464 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[vp_id
].handle
);
1465 vdev
->vpaths
[vp_id
].ring
.last_status
= VXGE_HW_OK
;
1467 /* Vpath reset done */
1468 clear_bit(vp_id
, &vdev
->vp_reset
);
1470 /* Start the vpath queue */
1471 vxge_wake_tx_queue(&vdev
->vpaths
[vp_id
].fifo
, NULL
);
1476 static int do_vxge_reset(struct vxgedev
*vdev
, int event
)
1478 enum vxge_hw_status status
;
1479 int ret
= 0, vp_id
, i
;
1481 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1483 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
)) {
1484 /* check if device is down already */
1485 if (unlikely(!is_vxge_card_up(vdev
)))
1488 /* is reset already scheduled */
1489 if (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1493 if (event
== VXGE_LL_FULL_RESET
) {
1494 /* wait for all the vpath reset to complete */
1495 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1496 while (test_bit(vp_id
, &vdev
->vp_reset
))
1500 /* if execution mode is set to debug, don't reset the adapter */
1501 if (unlikely(vdev
->exec_mode
)) {
1502 vxge_debug_init(VXGE_ERR
,
1503 "%s: execution mode is debug, returning..",
1505 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1506 vxge_stop_all_tx_queue(vdev
);
1511 if (event
== VXGE_LL_FULL_RESET
) {
1512 vxge_hw_device_intr_disable(vdev
->devh
);
1514 switch (vdev
->cric_err_event
) {
1515 case VXGE_HW_EVENT_UNKNOWN
:
1516 vxge_stop_all_tx_queue(vdev
);
1517 vxge_debug_init(VXGE_ERR
,
1518 "fatal: %s: Disabling device due to"
1523 case VXGE_HW_EVENT_RESET_START
:
1525 case VXGE_HW_EVENT_RESET_COMPLETE
:
1526 case VXGE_HW_EVENT_LINK_DOWN
:
1527 case VXGE_HW_EVENT_LINK_UP
:
1528 case VXGE_HW_EVENT_ALARM_CLEARED
:
1529 case VXGE_HW_EVENT_ECCERR
:
1530 case VXGE_HW_EVENT_MRPCIM_ECCERR
:
1533 case VXGE_HW_EVENT_FIFO_ERR
:
1534 case VXGE_HW_EVENT_VPATH_ERR
:
1536 case VXGE_HW_EVENT_CRITICAL_ERR
:
1537 vxge_stop_all_tx_queue(vdev
);
1538 vxge_debug_init(VXGE_ERR
,
1539 "fatal: %s: Disabling device due to"
1542 /* SOP or device reset required */
1543 /* This event is not currently used */
1546 case VXGE_HW_EVENT_SERR
:
1547 vxge_stop_all_tx_queue(vdev
);
1548 vxge_debug_init(VXGE_ERR
,
1549 "fatal: %s: Disabling device due to"
1554 case VXGE_HW_EVENT_SRPCIM_SERR
:
1555 case VXGE_HW_EVENT_MRPCIM_SERR
:
1558 case VXGE_HW_EVENT_SLOT_FREEZE
:
1559 vxge_stop_all_tx_queue(vdev
);
1560 vxge_debug_init(VXGE_ERR
,
1561 "fatal: %s: Disabling device due to"
1572 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
))
1573 vxge_stop_all_tx_queue(vdev
);
1575 if (event
== VXGE_LL_FULL_RESET
) {
1576 status
= vxge_reset_all_vpaths(vdev
);
1577 if (status
!= VXGE_HW_OK
) {
1578 vxge_debug_init(VXGE_ERR
,
1579 "fatal: %s: can not reset vpaths",
1586 if (event
== VXGE_LL_COMPL_RESET
) {
1587 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1588 if (vdev
->vpaths
[i
].handle
) {
1589 if (vxge_hw_vpath_recover_from_reset(
1590 vdev
->vpaths
[i
].handle
)
1592 vxge_debug_init(VXGE_ERR
,
1593 "vxge_hw_vpath_recover_"
1594 "from_reset failed for vpath: "
1600 vxge_debug_init(VXGE_ERR
,
1601 "vxge_hw_vpath_reset failed for "
1608 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
)) {
1609 /* Reprogram the DA table with populated mac addresses */
1610 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1611 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[vp_id
]);
1612 vxge_restore_vpath_vid_table(&vdev
->vpaths
[vp_id
]);
1615 /* enable vpath interrupts */
1616 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1617 vxge_vpath_intr_enable(vdev
, i
);
1619 vxge_hw_device_intr_enable(vdev
->devh
);
1623 /* Indicate card up */
1624 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1626 /* Get the traffic to flow through the vpaths */
1627 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1628 vxge_hw_vpath_enable(vdev
->vpaths
[i
].handle
);
1630 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[i
].handle
);
1633 vxge_wake_all_tx_queue(vdev
);
1637 vxge_debug_entryexit(VXGE_TRACE
,
1638 "%s:%d Exiting...", __func__
, __LINE__
);
1640 /* Indicate reset done */
1641 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
))
1642 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
1648 * @vdev: pointer to ll device
1650 * driver may reset the chip on events of serr, eccerr, etc
1652 int vxge_reset(struct vxgedev
*vdev
)
1654 do_vxge_reset(vdev
, VXGE_LL_FULL_RESET
);
1659 * vxge_poll - Receive handler when Receive Polling is used.
1660 * @dev: pointer to the device structure.
1661 * @budget: Number of packets budgeted to be processed in this iteration.
1663 * This function comes into picture only if Receive side is being handled
1664 * through polling (called NAPI in linux). It mostly does what the normal
1665 * Rx interrupt handler does in terms of descriptor and packet processing
1666 * but not in an interrupt context. Also it will process a specified number
1667 * of packets at most in one iteration. This value is passed down by the
1668 * kernel as the function argument 'budget'.
1670 static int vxge_poll_msix(struct napi_struct
*napi
, int budget
)
1672 struct vxge_ring
*ring
=
1673 container_of(napi
, struct vxge_ring
, napi
);
1674 int budget_org
= budget
;
1675 ring
->budget
= budget
;
1677 vxge_hw_vpath_poll_rx(ring
->handle
);
1679 if (ring
->pkts_processed
< budget_org
) {
1680 napi_complete(napi
);
1681 /* Re enable the Rx interrupts for the vpath */
1682 vxge_hw_channel_msix_unmask(
1683 (struct __vxge_hw_channel
*)ring
->handle
,
1684 ring
->rx_vector_no
);
1687 return ring
->pkts_processed
;
1690 static int vxge_poll_inta(struct napi_struct
*napi
, int budget
)
1692 struct vxgedev
*vdev
= container_of(napi
, struct vxgedev
, napi
);
1693 int pkts_processed
= 0;
1695 int budget_org
= budget
;
1696 struct vxge_ring
*ring
;
1698 struct __vxge_hw_device
*hldev
= (struct __vxge_hw_device
*)
1699 pci_get_drvdata(vdev
->pdev
);
1701 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1702 ring
= &vdev
->vpaths
[i
].ring
;
1703 ring
->budget
= budget
;
1704 vxge_hw_vpath_poll_rx(ring
->handle
);
1705 pkts_processed
+= ring
->pkts_processed
;
1706 budget
-= ring
->pkts_processed
;
1711 VXGE_COMPLETE_ALL_TX(vdev
);
1713 if (pkts_processed
< budget_org
) {
1714 napi_complete(napi
);
1715 /* Re enable the Rx interrupts for the ring */
1716 vxge_hw_device_unmask_all(hldev
);
1717 vxge_hw_device_flush_io(hldev
);
1720 return pkts_processed
;
1723 #ifdef CONFIG_NET_POLL_CONTROLLER
1725 * vxge_netpoll - netpoll event handler entry point
1726 * @dev : pointer to the device structure.
1728 * This function will be called by upper layer to check for events on the
1729 * interface in situations where interrupts are disabled. It is used for
1730 * specific in-kernel networking tasks, such as remote consoles and kernel
1731 * debugging over the network (example netdump in RedHat).
1733 static void vxge_netpoll(struct net_device
*dev
)
1735 struct __vxge_hw_device
*hldev
;
1736 struct vxgedev
*vdev
;
1738 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1739 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
1741 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1743 if (pci_channel_offline(vdev
->pdev
))
1746 disable_irq(dev
->irq
);
1747 vxge_hw_device_clear_tx_rx(hldev
);
1749 vxge_hw_device_clear_tx_rx(hldev
);
1750 VXGE_COMPLETE_ALL_RX(vdev
);
1751 VXGE_COMPLETE_ALL_TX(vdev
);
1753 enable_irq(dev
->irq
);
1755 vxge_debug_entryexit(VXGE_TRACE
,
1756 "%s:%d Exiting...", __func__
, __LINE__
);
1761 /* RTH configuration */
1762 static enum vxge_hw_status
vxge_rth_configure(struct vxgedev
*vdev
)
1764 enum vxge_hw_status status
= VXGE_HW_OK
;
1765 struct vxge_hw_rth_hash_types hash_types
;
1766 u8 itable
[256] = {0}; /* indirection table */
1767 u8 mtable
[256] = {0}; /* CPU to vpath mapping */
1772 * - itable with bucket numbers
1773 * - mtable with bucket-to-vpath mapping
1775 for (index
= 0; index
< (1 << vdev
->config
.rth_bkt_sz
); index
++) {
1776 itable
[index
] = index
;
1777 mtable
[index
] = index
% vdev
->no_of_vpath
;
1780 /* Fill RTH hash types */
1781 hash_types
.hash_type_tcpipv4_en
= vdev
->config
.rth_hash_type_tcpipv4
;
1782 hash_types
.hash_type_ipv4_en
= vdev
->config
.rth_hash_type_ipv4
;
1783 hash_types
.hash_type_tcpipv6_en
= vdev
->config
.rth_hash_type_tcpipv6
;
1784 hash_types
.hash_type_ipv6_en
= vdev
->config
.rth_hash_type_ipv6
;
1785 hash_types
.hash_type_tcpipv6ex_en
=
1786 vdev
->config
.rth_hash_type_tcpipv6ex
;
1787 hash_types
.hash_type_ipv6ex_en
= vdev
->config
.rth_hash_type_ipv6ex
;
1789 /* set indirection table, bucket-to-vpath mapping */
1790 status
= vxge_hw_vpath_rts_rth_itable_set(vdev
->vp_handles
,
1793 vdev
->config
.rth_bkt_sz
);
1794 if (status
!= VXGE_HW_OK
) {
1795 vxge_debug_init(VXGE_ERR
,
1796 "RTH indirection table configuration failed "
1797 "for vpath:%d", vdev
->vpaths
[0].device_id
);
1802 * Because the itable_set() method uses the active_table field
1803 * for the target virtual path the RTH config should be updated
1804 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1805 * when steering frames.
1807 for (index
= 0; index
< vdev
->no_of_vpath
; index
++) {
1808 status
= vxge_hw_vpath_rts_rth_set(
1809 vdev
->vpaths
[index
].handle
,
1810 vdev
->config
.rth_algorithm
,
1812 vdev
->config
.rth_bkt_sz
);
1814 if (status
!= VXGE_HW_OK
) {
1815 vxge_debug_init(VXGE_ERR
,
1816 "RTH configuration failed for vpath:%d",
1817 vdev
->vpaths
[index
].device_id
);
1825 int vxge_mac_list_add(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1827 struct vxge_mac_addrs
*new_mac_entry
;
1828 u8
*mac_address
= NULL
;
1830 if (vpath
->mac_addr_cnt
>= VXGE_MAX_LEARN_MAC_ADDR_CNT
)
1833 new_mac_entry
= kzalloc(sizeof(struct vxge_mac_addrs
), GFP_ATOMIC
);
1834 if (!new_mac_entry
) {
1835 vxge_debug_mem(VXGE_ERR
,
1836 "%s: memory allocation failed",
1841 list_add(&new_mac_entry
->item
, &vpath
->mac_addr_list
);
1843 /* Copy the new mac address to the list */
1844 mac_address
= (u8
*)&new_mac_entry
->macaddr
;
1845 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
1847 new_mac_entry
->state
= mac
->state
;
1848 vpath
->mac_addr_cnt
++;
1850 /* Is this a multicast address */
1851 if (0x01 & mac
->macaddr
[0])
1852 vpath
->mcast_addr_cnt
++;
1857 /* Add a mac address to DA table */
1858 enum vxge_hw_status
vxge_add_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
1860 enum vxge_hw_status status
= VXGE_HW_OK
;
1861 struct vxge_vpath
*vpath
;
1862 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode
;
1864 if (0x01 & mac
->macaddr
[0]) /* multicast address */
1865 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
;
1867 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE
;
1869 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
1870 status
= vxge_hw_vpath_mac_addr_add(vpath
->handle
, mac
->macaddr
,
1871 mac
->macmask
, duplicate_mode
);
1872 if (status
!= VXGE_HW_OK
) {
1873 vxge_debug_init(VXGE_ERR
,
1874 "DA config add entry failed for vpath:%d",
1877 if (FALSE
== vxge_mac_list_add(vpath
, mac
))
1883 int vxge_mac_list_del(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1885 struct list_head
*entry
, *next
;
1887 u8
*mac_address
= (u8
*) (&del_mac
);
1889 /* Copy the mac address to delete from the list */
1890 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
1892 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1893 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
) {
1895 kfree((struct vxge_mac_addrs
*)entry
);
1896 vpath
->mac_addr_cnt
--;
1898 /* Is this a multicast address */
1899 if (0x01 & mac
->macaddr
[0])
1900 vpath
->mcast_addr_cnt
--;
1907 /* delete a mac address from DA table */
1908 enum vxge_hw_status
vxge_del_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
1910 enum vxge_hw_status status
= VXGE_HW_OK
;
1911 struct vxge_vpath
*vpath
;
1913 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
1914 status
= vxge_hw_vpath_mac_addr_delete(vpath
->handle
, mac
->macaddr
,
1916 if (status
!= VXGE_HW_OK
) {
1917 vxge_debug_init(VXGE_ERR
,
1918 "DA config delete entry failed for vpath:%d",
1921 vxge_mac_list_del(vpath
, mac
);
1925 /* list all mac addresses from DA table */
1927 static vxge_search_mac_addr_in_da_table(struct vxge_vpath
*vpath
,
1928 struct macInfo
*mac
)
1930 enum vxge_hw_status status
= VXGE_HW_OK
;
1931 unsigned char macmask
[ETH_ALEN
];
1932 unsigned char macaddr
[ETH_ALEN
];
1934 status
= vxge_hw_vpath_mac_addr_get(vpath
->handle
,
1936 if (status
!= VXGE_HW_OK
) {
1937 vxge_debug_init(VXGE_ERR
,
1938 "DA config list entry failed for vpath:%d",
1943 while (memcmp(mac
->macaddr
, macaddr
, ETH_ALEN
)) {
1945 status
= vxge_hw_vpath_mac_addr_get_next(vpath
->handle
,
1947 if (status
!= VXGE_HW_OK
)
1954 /* Store all vlan ids from the list to the vid table */
1955 enum vxge_hw_status
vxge_restore_vpath_vid_table(struct vxge_vpath
*vpath
)
1957 enum vxge_hw_status status
= VXGE_HW_OK
;
1958 struct vxgedev
*vdev
= vpath
->vdev
;
1961 if (vdev
->vlgrp
&& vpath
->is_open
) {
1963 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
1964 if (!vlan_group_get_device(vdev
->vlgrp
, vid
))
1966 /* Add these vlan to the vid table */
1967 status
= vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
1974 /* Store all mac addresses from the list to the DA table */
1975 enum vxge_hw_status
vxge_restore_vpath_mac_addr(struct vxge_vpath
*vpath
)
1977 enum vxge_hw_status status
= VXGE_HW_OK
;
1978 struct macInfo mac_info
;
1979 u8
*mac_address
= NULL
;
1980 struct list_head
*entry
, *next
;
1982 memset(&mac_info
, 0, sizeof(struct macInfo
));
1984 if (vpath
->is_open
) {
1986 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1989 ((struct vxge_mac_addrs
*)entry
)->macaddr
;
1990 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1991 ((struct vxge_mac_addrs
*)entry
)->state
=
1992 VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1993 /* does this mac address already exist in da table? */
1994 status
= vxge_search_mac_addr_in_da_table(vpath
,
1996 if (status
!= VXGE_HW_OK
) {
1997 /* Add this mac address to the DA table */
1998 status
= vxge_hw_vpath_mac_addr_add(
1999 vpath
->handle
, mac_info
.macaddr
,
2001 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
);
2002 if (status
!= VXGE_HW_OK
) {
2003 vxge_debug_init(VXGE_ERR
,
2004 "DA add entry failed for vpath:%d",
2006 ((struct vxge_mac_addrs
*)entry
)->state
2007 = VXGE_LL_MAC_ADDR_IN_LIST
;
2017 enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
)
2020 enum vxge_hw_status status
= VXGE_HW_OK
;
2022 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2023 if (vdev
->vpaths
[i
].handle
) {
2024 if (vxge_hw_vpath_reset(vdev
->vpaths
[i
].handle
)
2026 if (is_vxge_card_up(vdev
) &&
2027 vxge_hw_vpath_recover_from_reset(
2028 vdev
->vpaths
[i
].handle
)
2030 vxge_debug_init(VXGE_ERR
,
2031 "vxge_hw_vpath_recover_"
2032 "from_reset failed for vpath: "
2037 vxge_debug_init(VXGE_ERR
,
2038 "vxge_hw_vpath_reset failed for "
2047 void vxge_close_vpaths(struct vxgedev
*vdev
, int index
)
2050 for (i
= index
; i
< vdev
->no_of_vpath
; i
++) {
2051 if (vdev
->vpaths
[i
].handle
&& vdev
->vpaths
[i
].is_open
) {
2052 vxge_hw_vpath_close(vdev
->vpaths
[i
].handle
);
2053 vdev
->stats
.vpaths_open
--;
2055 vdev
->vpaths
[i
].is_open
= 0;
2056 vdev
->vpaths
[i
].handle
= NULL
;
2061 int vxge_open_vpaths(struct vxgedev
*vdev
)
2063 enum vxge_hw_status status
;
2066 struct vxge_hw_vpath_attr attr
;
2068 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2069 vxge_assert(vdev
->vpaths
[i
].is_configured
);
2070 attr
.vp_id
= vdev
->vpaths
[i
].device_id
;
2071 attr
.fifo_attr
.callback
= vxge_xmit_compl
;
2072 attr
.fifo_attr
.txdl_term
= vxge_tx_term
;
2073 attr
.fifo_attr
.per_txdl_space
= sizeof(struct vxge_tx_priv
);
2074 attr
.fifo_attr
.userdata
= (void *)&vdev
->vpaths
[i
].fifo
;
2076 attr
.ring_attr
.callback
= vxge_rx_1b_compl
;
2077 attr
.ring_attr
.rxd_init
= vxge_rx_initial_replenish
;
2078 attr
.ring_attr
.rxd_term
= vxge_rx_term
;
2079 attr
.ring_attr
.per_rxd_space
= sizeof(struct vxge_rx_priv
);
2080 attr
.ring_attr
.userdata
= (void *)&vdev
->vpaths
[i
].ring
;
2082 vdev
->vpaths
[i
].ring
.ndev
= vdev
->ndev
;
2083 vdev
->vpaths
[i
].ring
.pdev
= vdev
->pdev
;
2084 status
= vxge_hw_vpath_open(vdev
->devh
, &attr
,
2085 &(vdev
->vpaths
[i
].handle
));
2086 if (status
== VXGE_HW_OK
) {
2087 vdev
->vpaths
[i
].fifo
.handle
=
2088 (struct __vxge_hw_fifo
*)attr
.fifo_attr
.userdata
;
2089 vdev
->vpaths
[i
].ring
.handle
=
2090 (struct __vxge_hw_ring
*)attr
.ring_attr
.userdata
;
2091 vdev
->vpaths
[i
].fifo
.tx_steering_type
=
2092 vdev
->config
.tx_steering_type
;
2093 vdev
->vpaths
[i
].fifo
.ndev
= vdev
->ndev
;
2094 vdev
->vpaths
[i
].fifo
.pdev
= vdev
->pdev
;
2095 vdev
->vpaths
[i
].fifo
.indicate_max_pkts
=
2096 vdev
->config
.fifo_indicate_max_pkts
;
2097 vdev
->vpaths
[i
].ring
.rx_vector_no
= 0;
2098 vdev
->vpaths
[i
].ring
.rx_csum
= vdev
->rx_csum
;
2099 vdev
->vpaths
[i
].is_open
= 1;
2100 vdev
->vp_handles
[i
] = vdev
->vpaths
[i
].handle
;
2101 vdev
->vpaths
[i
].ring
.gro_enable
=
2102 vdev
->config
.gro_enable
;
2103 vdev
->vpaths
[i
].ring
.vlan_tag_strip
=
2104 vdev
->vlan_tag_strip
;
2105 vdev
->stats
.vpaths_open
++;
2107 vdev
->stats
.vpath_open_fail
++;
2108 vxge_debug_init(VXGE_ERR
,
2109 "%s: vpath: %d failed to open "
2111 vdev
->ndev
->name
, vdev
->vpaths
[i
].device_id
,
2113 vxge_close_vpaths(vdev
, 0);
2118 ((struct __vxge_hw_vpath_handle
*)vdev
->vpaths
[i
].handle
)->
2120 vdev
->vpaths_deployed
|= vxge_mBIT(vp_id
);
2127 * @irq: the irq of the device.
2128 * @dev_id: a void pointer to the hldev structure of the Titan device
2129 * @ptregs: pointer to the registers pushed on the stack.
2131 * This function is the ISR handler of the device when napi is enabled. It
2132 * identifies the reason for the interrupt and calls the relevant service
2135 static irqreturn_t
vxge_isr_napi(int irq
, void *dev_id
)
2137 struct __vxge_hw_device
*hldev
= (struct __vxge_hw_device
*)dev_id
;
2138 struct vxgedev
*vdev
;
2139 struct net_device
*dev
;
2141 enum vxge_hw_status status
;
2143 vxge_debug_intr(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
2146 vdev
= netdev_priv(dev
);
2148 if (pci_channel_offline(vdev
->pdev
))
2151 if (unlikely(!is_vxge_card_up(vdev
)))
2154 status
= vxge_hw_device_begin_irq(hldev
, vdev
->exec_mode
,
2156 if (status
== VXGE_HW_OK
) {
2157 vxge_hw_device_mask_all(hldev
);
2160 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2161 vdev
->vpaths_deployed
>>
2162 (64 - VXGE_HW_MAX_VIRTUAL_PATHS
))) {
2164 vxge_hw_device_clear_tx_rx(hldev
);
2165 napi_schedule(&vdev
->napi
);
2166 vxge_debug_intr(VXGE_TRACE
,
2167 "%s:%d Exiting...", __func__
, __LINE__
);
2170 vxge_hw_device_unmask_all(hldev
);
2171 } else if (unlikely((status
== VXGE_HW_ERR_VPATH
) ||
2172 (status
== VXGE_HW_ERR_CRITICAL
) ||
2173 (status
== VXGE_HW_ERR_FIFO
))) {
2174 vxge_hw_device_mask_all(hldev
);
2175 vxge_hw_device_flush_io(hldev
);
2177 } else if (unlikely(status
== VXGE_HW_ERR_SLOT_FREEZE
))
2180 vxge_debug_intr(VXGE_TRACE
, "%s:%d Exiting...", __func__
, __LINE__
);
2184 #ifdef CONFIG_PCI_MSI
2187 vxge_tx_msix_handle(int irq
, void *dev_id
)
2189 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)dev_id
;
2191 VXGE_COMPLETE_VPATH_TX(fifo
);
2197 vxge_rx_msix_napi_handle(int irq
, void *dev_id
)
2199 struct vxge_ring
*ring
= (struct vxge_ring
*)dev_id
;
2201 /* MSIX_IDX for Rx is 1 */
2202 vxge_hw_channel_msix_mask((struct __vxge_hw_channel
*)ring
->handle
,
2203 ring
->rx_vector_no
);
2205 napi_schedule(&ring
->napi
);
2210 vxge_alarm_msix_handle(int irq
, void *dev_id
)
2213 enum vxge_hw_status status
;
2214 struct vxge_vpath
*vpath
= (struct vxge_vpath
*)dev_id
;
2215 struct vxgedev
*vdev
= vpath
->vdev
;
2217 VXGE_HW_VPATH_MSIX_ACTIVE
* vdev
->no_of_vpath
- 2;
2219 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2220 vxge_hw_vpath_msix_mask(vdev
->vpaths
[i
].handle
,
2223 status
= vxge_hw_vpath_alarm_process(vdev
->vpaths
[i
].handle
,
2225 if (status
== VXGE_HW_OK
) {
2227 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[i
].handle
,
2231 vxge_debug_intr(VXGE_ERR
,
2232 "%s: vxge_hw_vpath_alarm_process failed %x ",
2233 VXGE_DRIVER_NAME
, status
);
2238 static int vxge_alloc_msix(struct vxgedev
*vdev
)
2242 int alarm_msix_id
= 0, msix_intr_vect
= 0;
2245 /* Tx/Rx MSIX Vectors count */
2246 vdev
->intr_cnt
= vdev
->no_of_vpath
* 2;
2248 /* Alarm MSIX Vectors count */
2251 intr_cnt
= (vdev
->max_vpath_supported
* 2) + 1;
2252 vdev
->entries
= kzalloc(intr_cnt
* sizeof(struct msix_entry
),
2254 if (!vdev
->entries
) {
2255 vxge_debug_init(VXGE_ERR
,
2256 "%s: memory allocation failed",
2261 vdev
->vxge_entries
= kzalloc(intr_cnt
* sizeof(struct vxge_msix_entry
),
2263 if (!vdev
->vxge_entries
) {
2264 vxge_debug_init(VXGE_ERR
, "%s: memory allocation failed",
2266 kfree(vdev
->entries
);
2270 /* Last vector in the list is used for alarm */
2271 alarm_msix_id
= VXGE_HW_VPATH_MSIX_ACTIVE
* vdev
->no_of_vpath
- 2;
2272 for (i
= 0, j
= 0; i
< vdev
->max_vpath_supported
; i
++) {
2274 msix_intr_vect
= i
* VXGE_HW_VPATH_MSIX_ACTIVE
;
2276 /* Initialize the fifo vector */
2277 vdev
->entries
[j
].entry
= msix_intr_vect
;
2278 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
;
2279 vdev
->vxge_entries
[j
].in_use
= 0;
2282 /* Initialize the ring vector */
2283 vdev
->entries
[j
].entry
= msix_intr_vect
+ 1;
2284 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
+ 1;
2285 vdev
->vxge_entries
[j
].in_use
= 0;
2289 /* Initialize the alarm vector */
2290 vdev
->entries
[j
].entry
= alarm_msix_id
;
2291 vdev
->vxge_entries
[j
].entry
= alarm_msix_id
;
2292 vdev
->vxge_entries
[j
].in_use
= 0;
2294 ret
= pci_enable_msix(vdev
->pdev
, vdev
->entries
, intr_cnt
);
2295 /* if driver request exceeeds available irq's, request with a small
2299 vxge_debug_init(VXGE_ERR
,
2300 "%s: MSI-X enable failed for %d vectors, available: %d",
2301 VXGE_DRIVER_NAME
, intr_cnt
, ret
);
2302 vdev
->max_vpath_supported
= vdev
->no_of_vpath
;
2303 intr_cnt
= (vdev
->max_vpath_supported
* 2) + 1;
2305 /* Reset the alarm vector setting */
2306 vdev
->entries
[j
].entry
= 0;
2307 vdev
->vxge_entries
[j
].entry
= 0;
2309 /* Initialize the alarm vector with new setting */
2310 vdev
->entries
[intr_cnt
- 1].entry
= alarm_msix_id
;
2311 vdev
->vxge_entries
[intr_cnt
- 1].entry
= alarm_msix_id
;
2312 vdev
->vxge_entries
[intr_cnt
- 1].in_use
= 0;
2314 ret
= pci_enable_msix(vdev
->pdev
, vdev
->entries
, intr_cnt
);
2316 vxge_debug_init(VXGE_ERR
,
2317 "%s: MSI-X enabled for %d vectors",
2318 VXGE_DRIVER_NAME
, intr_cnt
);
2322 vxge_debug_init(VXGE_ERR
,
2323 "%s: MSI-X enable failed for %d vectors, ret: %d",
2324 VXGE_DRIVER_NAME
, intr_cnt
, ret
);
2325 kfree(vdev
->entries
);
2326 kfree(vdev
->vxge_entries
);
2327 vdev
->entries
= NULL
;
2328 vdev
->vxge_entries
= NULL
;
2334 static int vxge_enable_msix(struct vxgedev
*vdev
)
2338 enum vxge_hw_status status
;
2339 /* 0 - Tx, 1 - Rx */
2341 int alarm_msix_id
= 0, msix_intr_vect
= 0;;
2344 /* allocate msix vectors */
2345 ret
= vxge_alloc_msix(vdev
);
2347 /* Last vector in the list is used for alarm */
2349 VXGE_HW_VPATH_MSIX_ACTIVE
* vdev
->no_of_vpath
- 2;
2350 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2352 /* If fifo or ring are not enabled
2353 the MSIX vector for that should be set to 0
2354 Hence initializeing this array to all 0s.
2356 memset(tim_msix_id
, 0, sizeof(tim_msix_id
));
2357 msix_intr_vect
= i
* VXGE_HW_VPATH_MSIX_ACTIVE
;
2358 tim_msix_id
[0] = msix_intr_vect
;
2360 tim_msix_id
[1] = msix_intr_vect
+ 1;
2361 vdev
->vpaths
[i
].ring
.rx_vector_no
= tim_msix_id
[1];
2363 status
= vxge_hw_vpath_msix_set(
2364 vdev
->vpaths
[i
].handle
,
2365 tim_msix_id
, alarm_msix_id
);
2366 if (status
!= VXGE_HW_OK
) {
2367 vxge_debug_init(VXGE_ERR
,
2368 "vxge_hw_vpath_msix_set "
2369 "failed with status : %x", status
);
2370 kfree(vdev
->entries
);
2371 kfree(vdev
->vxge_entries
);
2372 pci_disable_msix(vdev
->pdev
);
2381 static void vxge_rem_msix_isr(struct vxgedev
*vdev
)
2385 for (intr_cnt
= 0; intr_cnt
< (vdev
->max_vpath_supported
* 2 + 1);
2387 if (vdev
->vxge_entries
[intr_cnt
].in_use
) {
2388 synchronize_irq(vdev
->entries
[intr_cnt
].vector
);
2389 free_irq(vdev
->entries
[intr_cnt
].vector
,
2390 vdev
->vxge_entries
[intr_cnt
].arg
);
2391 vdev
->vxge_entries
[intr_cnt
].in_use
= 0;
2395 kfree(vdev
->entries
);
2396 kfree(vdev
->vxge_entries
);
2397 vdev
->entries
= NULL
;
2398 vdev
->vxge_entries
= NULL
;
2400 if (vdev
->config
.intr_type
== MSI_X
)
2401 pci_disable_msix(vdev
->pdev
);
2405 static void vxge_rem_isr(struct vxgedev
*vdev
)
2407 struct __vxge_hw_device
*hldev
;
2408 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2410 #ifdef CONFIG_PCI_MSI
2411 if (vdev
->config
.intr_type
== MSI_X
) {
2412 vxge_rem_msix_isr(vdev
);
2415 if (vdev
->config
.intr_type
== INTA
) {
2416 synchronize_irq(vdev
->pdev
->irq
);
2417 free_irq(vdev
->pdev
->irq
, hldev
);
2421 static int vxge_add_isr(struct vxgedev
*vdev
)
2424 struct __vxge_hw_device
*hldev
=
2425 (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2426 #ifdef CONFIG_PCI_MSI
2427 int vp_idx
= 0, intr_idx
= 0, intr_cnt
= 0, msix_idx
= 0, irq_req
= 0;
2428 u64 function_mode
= vdev
->config
.device_hw_info
.function_mode
;
2429 int pci_fun
= PCI_FUNC(vdev
->pdev
->devfn
);
2431 if (vdev
->config
.intr_type
== MSI_X
)
2432 ret
= vxge_enable_msix(vdev
);
2435 vxge_debug_init(VXGE_ERR
,
2436 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME
);
2437 if ((function_mode
== VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
) &&
2438 test_and_set_bit(__VXGE_STATE_CARD_UP
,
2439 &driver_config
->inta_dev_open
))
2440 return VXGE_HW_FAIL
;
2442 vxge_debug_init(VXGE_ERR
,
2443 "%s: Defaulting to INTA", VXGE_DRIVER_NAME
);
2444 vdev
->config
.intr_type
= INTA
;
2445 vxge_hw_device_set_intr_type(vdev
->devh
,
2446 VXGE_HW_INTR_MODE_IRQLINE
);
2447 vxge_close_vpaths(vdev
, 1);
2448 vdev
->no_of_vpath
= 1;
2449 vdev
->stats
.vpaths_open
= 1;
2453 if (vdev
->config
.intr_type
== MSI_X
) {
2455 intr_idx
< (vdev
->no_of_vpath
*
2456 VXGE_HW_VPATH_MSIX_ACTIVE
); intr_idx
++) {
2458 msix_idx
= intr_idx
% VXGE_HW_VPATH_MSIX_ACTIVE
;
2463 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2464 "%s:vxge fn: %d vpath: %d Tx MSI-X: %d",
2465 vdev
->ndev
->name
, pci_fun
, vp_idx
,
2466 vdev
->entries
[intr_cnt
].entry
);
2468 vdev
->entries
[intr_cnt
].vector
,
2469 vxge_tx_msix_handle
, 0,
2470 vdev
->desc
[intr_cnt
],
2471 &vdev
->vpaths
[vp_idx
].fifo
);
2472 vdev
->vxge_entries
[intr_cnt
].arg
=
2473 &vdev
->vpaths
[vp_idx
].fifo
;
2477 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2478 "%s:vxge fn: %d vpath: %d Rx MSI-X: %d",
2479 vdev
->ndev
->name
, pci_fun
, vp_idx
,
2480 vdev
->entries
[intr_cnt
].entry
);
2482 vdev
->entries
[intr_cnt
].vector
,
2483 vxge_rx_msix_napi_handle
,
2485 vdev
->desc
[intr_cnt
],
2486 &vdev
->vpaths
[vp_idx
].ring
);
2487 vdev
->vxge_entries
[intr_cnt
].arg
=
2488 &vdev
->vpaths
[vp_idx
].ring
;
2494 vxge_debug_init(VXGE_ERR
,
2495 "%s: MSIX - %d Registration failed",
2496 vdev
->ndev
->name
, intr_cnt
);
2497 vxge_rem_msix_isr(vdev
);
2498 if ((function_mode
==
2499 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
) &&
2500 test_and_set_bit(__VXGE_STATE_CARD_UP
,
2501 &driver_config
->inta_dev_open
))
2502 return VXGE_HW_FAIL
;
2504 vxge_hw_device_set_intr_type(
2506 VXGE_HW_INTR_MODE_IRQLINE
);
2507 vdev
->config
.intr_type
= INTA
;
2508 vxge_debug_init(VXGE_ERR
,
2509 "%s: Defaulting to INTA"
2510 , vdev
->ndev
->name
);
2511 vxge_close_vpaths(vdev
, 1);
2512 vdev
->no_of_vpath
= 1;
2513 vdev
->stats
.vpaths_open
= 1;
2519 /* We requested for this msix interrupt */
2520 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2521 vxge_hw_vpath_msix_unmask(
2522 vdev
->vpaths
[vp_idx
].handle
,
2527 /* Point to next vpath handler */
2528 if (((intr_idx
+ 1) % VXGE_HW_VPATH_MSIX_ACTIVE
== 0)
2529 && (vp_idx
< (vdev
->no_of_vpath
- 1)))
2533 intr_cnt
= vdev
->max_vpath_supported
* 2;
2534 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2535 "%s:vxge Alarm fn: %d MSI-X: %d",
2536 vdev
->ndev
->name
, pci_fun
,
2537 vdev
->entries
[intr_cnt
].entry
);
2538 /* For Alarm interrupts */
2539 ret
= request_irq(vdev
->entries
[intr_cnt
].vector
,
2540 vxge_alarm_msix_handle
, 0,
2541 vdev
->desc
[intr_cnt
],
2542 &vdev
->vpaths
[vp_idx
]);
2544 vxge_debug_init(VXGE_ERR
,
2545 "%s: MSIX - %d Registration failed",
2546 vdev
->ndev
->name
, intr_cnt
);
2547 vxge_rem_msix_isr(vdev
);
2548 if ((function_mode
==
2549 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
) &&
2550 test_and_set_bit(__VXGE_STATE_CARD_UP
,
2551 &driver_config
->inta_dev_open
))
2552 return VXGE_HW_FAIL
;
2554 vxge_hw_device_set_intr_type(vdev
->devh
,
2555 VXGE_HW_INTR_MODE_IRQLINE
);
2556 vdev
->config
.intr_type
= INTA
;
2557 vxge_debug_init(VXGE_ERR
,
2558 "%s: Defaulting to INTA",
2560 vxge_close_vpaths(vdev
, 1);
2561 vdev
->no_of_vpath
= 1;
2562 vdev
->stats
.vpaths_open
= 1;
2567 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[vp_idx
].handle
,
2569 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2570 vdev
->vxge_entries
[intr_cnt
].arg
= &vdev
->vpaths
[vp_idx
];
2574 snprintf(vdev
->desc
[0], VXGE_INTR_STRLEN
, "%s:vxge", vdev
->ndev
->name
);
2576 if (vdev
->config
.intr_type
== INTA
) {
2577 ret
= request_irq((int) vdev
->pdev
->irq
,
2579 IRQF_SHARED
, vdev
->desc
[0], hldev
);
2581 vxge_debug_init(VXGE_ERR
,
2582 "%s %s-%d: ISR registration failed",
2583 VXGE_DRIVER_NAME
, "IRQ", vdev
->pdev
->irq
);
2586 vxge_debug_init(VXGE_TRACE
,
2587 "new %s-%d line allocated",
2588 "IRQ", vdev
->pdev
->irq
);
2594 static void vxge_poll_vp_reset(unsigned long data
)
2596 struct vxgedev
*vdev
= (struct vxgedev
*)data
;
2599 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2600 if (test_bit(i
, &vdev
->vp_reset
)) {
2601 vxge_reset_vpath(vdev
, i
);
2605 if (j
&& (vdev
->config
.intr_type
!= MSI_X
)) {
2606 vxge_hw_device_unmask_all(vdev
->devh
);
2607 vxge_hw_device_flush_io(vdev
->devh
);
2610 mod_timer(&vdev
->vp_reset_timer
, jiffies
+ HZ
/ 2);
2613 static void vxge_poll_vp_lockup(unsigned long data
)
2615 struct vxgedev
*vdev
= (struct vxgedev
*)data
;
2617 struct vxge_ring
*ring
;
2618 enum vxge_hw_status status
= VXGE_HW_OK
;
2620 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2621 ring
= &vdev
->vpaths
[i
].ring
;
2622 /* Did this vpath received any packets */
2623 if (ring
->stats
.prev_rx_frms
== ring
->stats
.rx_frms
) {
2624 status
= vxge_hw_vpath_check_leak(ring
->handle
);
2626 /* Did it received any packets last time */
2627 if ((VXGE_HW_FAIL
== status
) &&
2628 (VXGE_HW_FAIL
== ring
->last_status
)) {
2630 /* schedule vpath reset */
2631 if (!test_and_set_bit(i
, &vdev
->vp_reset
)) {
2633 /* disable interrupts for this vpath */
2634 vxge_vpath_intr_disable(vdev
, i
);
2636 /* stop the queue for this vpath */
2637 vxge_stop_tx_queue(&vdev
->vpaths
[i
].
2643 ring
->stats
.prev_rx_frms
= ring
->stats
.rx_frms
;
2644 ring
->last_status
= status
;
2647 /* Check every 1 milli second */
2648 mod_timer(&vdev
->vp_lockup_timer
, jiffies
+ HZ
/ 1000);
2653 * @dev: pointer to the device structure.
2655 * This function is the open entry point of the driver. It mainly calls a
2656 * function to allocate Rx buffers and inserts them into the buffer
2657 * descriptors and then enables the Rx part of the NIC.
2658 * Return value: '0' on success and an appropriate (-)ve integer as
2659 * defined in errno.h file on failure.
2662 vxge_open(struct net_device
*dev
)
2664 enum vxge_hw_status status
;
2665 struct vxgedev
*vdev
;
2666 struct __vxge_hw_device
*hldev
;
2669 u64 val64
, function_mode
;
2670 vxge_debug_entryexit(VXGE_TRACE
,
2671 "%s: %s:%d", dev
->name
, __func__
, __LINE__
);
2673 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2674 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2675 function_mode
= vdev
->config
.device_hw_info
.function_mode
;
2677 /* make sure you have link off by default every time Nic is
2679 netif_carrier_off(dev
);
2681 /* Check for another device already opn with INTA */
2682 if ((function_mode
== VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
) &&
2683 test_bit(__VXGE_STATE_CARD_UP
, &driver_config
->inta_dev_open
)) {
2689 status
= vxge_open_vpaths(vdev
);
2690 if (status
!= VXGE_HW_OK
) {
2691 vxge_debug_init(VXGE_ERR
,
2692 "%s: fatal: Vpath open failed", vdev
->ndev
->name
);
2697 vdev
->mtu
= dev
->mtu
;
2699 status
= vxge_add_isr(vdev
);
2700 if (status
!= VXGE_HW_OK
) {
2701 vxge_debug_init(VXGE_ERR
,
2702 "%s: fatal: ISR add failed", dev
->name
);
2708 if (vdev
->config
.intr_type
!= MSI_X
) {
2709 netif_napi_add(dev
, &vdev
->napi
, vxge_poll_inta
,
2710 vdev
->config
.napi_weight
);
2711 napi_enable(&vdev
->napi
);
2713 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2714 netif_napi_add(dev
, &vdev
->vpaths
[i
].ring
.napi
,
2715 vxge_poll_msix
, vdev
->config
.napi_weight
);
2716 napi_enable(&vdev
->vpaths
[i
].ring
.napi
);
2721 if (vdev
->config
.rth_steering
) {
2722 status
= vxge_rth_configure(vdev
);
2723 if (status
!= VXGE_HW_OK
) {
2724 vxge_debug_init(VXGE_ERR
,
2725 "%s: fatal: RTH configuration failed",
2732 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2733 /* set initial mtu before enabling the device */
2734 status
= vxge_hw_vpath_mtu_set(vdev
->vpaths
[i
].handle
,
2736 if (status
!= VXGE_HW_OK
) {
2737 vxge_debug_init(VXGE_ERR
,
2738 "%s: fatal: can not set new MTU", dev
->name
);
2744 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE
, VXGE_COMPONENT_LL
, vdev
);
2745 vxge_debug_init(vdev
->level_trace
,
2746 "%s: MTU is %d", vdev
->ndev
->name
, vdev
->mtu
);
2747 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR
, VXGE_COMPONENT_LL
, vdev
);
2749 /* Reprogram the DA table with populated mac addresses */
2750 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2751 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[i
]);
2752 vxge_restore_vpath_vid_table(&vdev
->vpaths
[i
]);
2755 /* Enable vpath to sniff all unicast/multicast traffic that not
2756 * addressed to them. We allow promiscous mode for PF only
2760 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
2761 val64
|= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i
);
2763 vxge_hw_mgmt_reg_write(vdev
->devh
,
2764 vxge_hw_mgmt_reg_type_mrpcim
,
2766 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2767 rxmac_authorize_all_addr
),
2770 vxge_hw_mgmt_reg_write(vdev
->devh
,
2771 vxge_hw_mgmt_reg_type_mrpcim
,
2773 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2774 rxmac_authorize_all_vid
),
2777 vxge_set_multicast(dev
);
2779 /* Enabling Bcast and mcast for all vpath */
2780 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2781 status
= vxge_hw_vpath_bcast_enable(vdev
->vpaths
[i
].handle
);
2782 if (status
!= VXGE_HW_OK
)
2783 vxge_debug_init(VXGE_ERR
,
2784 "%s : Can not enable bcast for vpath "
2785 "id %d", dev
->name
, i
);
2786 if (vdev
->config
.addr_learn_en
) {
2788 vxge_hw_vpath_mcast_enable(vdev
->vpaths
[i
].handle
);
2789 if (status
!= VXGE_HW_OK
)
2790 vxge_debug_init(VXGE_ERR
,
2791 "%s : Can not enable mcast for vpath "
2792 "id %d", dev
->name
, i
);
2796 vxge_hw_device_setpause_data(vdev
->devh
, 0,
2797 vdev
->config
.tx_pause_enable
,
2798 vdev
->config
.rx_pause_enable
);
2800 if (vdev
->vp_reset_timer
.function
== NULL
)
2801 vxge_os_timer(vdev
->vp_reset_timer
,
2802 vxge_poll_vp_reset
, vdev
, (HZ
/2));
2804 if (vdev
->vp_lockup_timer
.function
== NULL
)
2805 vxge_os_timer(vdev
->vp_lockup_timer
,
2806 vxge_poll_vp_lockup
, vdev
, (HZ
/2));
2808 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
2812 if (vxge_hw_device_link_state_get(vdev
->devh
) == VXGE_HW_LINK_UP
) {
2813 netif_carrier_on(vdev
->ndev
);
2814 printk(KERN_NOTICE
"%s: Link Up\n", vdev
->ndev
->name
);
2815 vdev
->stats
.link_up
++;
2818 vxge_hw_device_intr_enable(vdev
->devh
);
2822 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2823 vxge_hw_vpath_enable(vdev
->vpaths
[i
].handle
);
2825 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[i
].handle
);
2828 vxge_start_all_tx_queue(vdev
);
2835 if (vdev
->config
.intr_type
!= MSI_X
)
2836 napi_disable(&vdev
->napi
);
2838 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2839 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
2843 vxge_close_vpaths(vdev
, 0);
2845 vxge_debug_entryexit(VXGE_TRACE
,
2846 "%s: %s:%d Exiting...",
2847 dev
->name
, __func__
, __LINE__
);
2851 /* Loop throught the mac address list and delete all the entries */
2852 void vxge_free_mac_add_list(struct vxge_vpath
*vpath
)
2855 struct list_head
*entry
, *next
;
2856 if (list_empty(&vpath
->mac_addr_list
))
2859 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
2861 kfree((struct vxge_mac_addrs
*)entry
);
2865 static void vxge_napi_del_all(struct vxgedev
*vdev
)
2868 if (vdev
->config
.intr_type
!= MSI_X
)
2869 netif_napi_del(&vdev
->napi
);
2871 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2872 netif_napi_del(&vdev
->vpaths
[i
].ring
.napi
);
2877 int do_vxge_close(struct net_device
*dev
, int do_io
)
2879 enum vxge_hw_status status
;
2880 struct vxgedev
*vdev
;
2881 struct __vxge_hw_device
*hldev
;
2883 u64 val64
, vpath_vector
;
2884 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
2885 dev
->name
, __func__
, __LINE__
);
2887 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2888 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2890 /* If vxge_handle_crit_err task is executing,
2891 * wait till it completes. */
2892 while (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
2895 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
2897 /* Put the vpath back in normal mode */
2898 vpath_vector
= vxge_mBIT(vdev
->vpaths
[0].device_id
);
2899 status
= vxge_hw_mgmt_reg_read(vdev
->devh
,
2900 vxge_hw_mgmt_reg_type_mrpcim
,
2903 struct vxge_hw_mrpcim_reg
,
2904 rts_mgr_cbasin_cfg
),
2907 if (status
== VXGE_HW_OK
) {
2908 val64
&= ~vpath_vector
;
2909 status
= vxge_hw_mgmt_reg_write(vdev
->devh
,
2910 vxge_hw_mgmt_reg_type_mrpcim
,
2913 struct vxge_hw_mrpcim_reg
,
2914 rts_mgr_cbasin_cfg
),
2918 /* Remove the function 0 from promiscous mode */
2919 vxge_hw_mgmt_reg_write(vdev
->devh
,
2920 vxge_hw_mgmt_reg_type_mrpcim
,
2922 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2923 rxmac_authorize_all_addr
),
2926 vxge_hw_mgmt_reg_write(vdev
->devh
,
2927 vxge_hw_mgmt_reg_type_mrpcim
,
2929 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2930 rxmac_authorize_all_vid
),
2935 del_timer_sync(&vdev
->vp_lockup_timer
);
2937 del_timer_sync(&vdev
->vp_reset_timer
);
2940 if (vdev
->config
.intr_type
!= MSI_X
)
2941 napi_disable(&vdev
->napi
);
2943 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2944 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
2947 netif_carrier_off(vdev
->ndev
);
2948 printk(KERN_NOTICE
"%s: Link Down\n", vdev
->ndev
->name
);
2949 vxge_stop_all_tx_queue(vdev
);
2951 /* Note that at this point xmit() is stopped by upper layer */
2953 vxge_hw_device_intr_disable(vdev
->devh
);
2959 vxge_napi_del_all(vdev
);
2962 vxge_reset_all_vpaths(vdev
);
2964 vxge_close_vpaths(vdev
, 0);
2966 vxge_debug_entryexit(VXGE_TRACE
,
2967 "%s: %s:%d Exiting...", dev
->name
, __func__
, __LINE__
);
2969 clear_bit(__VXGE_STATE_CARD_UP
, &driver_config
->inta_dev_open
);
2970 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
2977 * @dev: device pointer.
2979 * This is the stop entry point of the driver. It needs to undo exactly
2980 * whatever was done by the open entry point, thus it's usually referred to
2981 * as the close function.Among other things this function mainly stops the
2982 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2983 * Return value: '0' on success and an appropriate (-)ve integer as
2984 * defined in errno.h file on failure.
2987 vxge_close(struct net_device
*dev
)
2989 do_vxge_close(dev
, 1);
2995 * @dev: net device pointer.
2996 * @new_mtu :the new MTU size for the device.
2998 * A driver entry point to change MTU size for the device. Before changing
2999 * the MTU the device must be stopped.
3001 static int vxge_change_mtu(struct net_device
*dev
, int new_mtu
)
3003 struct vxgedev
*vdev
= netdev_priv(dev
);
3005 vxge_debug_entryexit(vdev
->level_trace
,
3006 "%s:%d", __func__
, __LINE__
);
3007 if ((new_mtu
< VXGE_HW_MIN_MTU
) || (new_mtu
> VXGE_HW_MAX_MTU
)) {
3008 vxge_debug_init(vdev
->level_err
,
3009 "%s: mtu size is invalid", dev
->name
);
3013 /* check if device is down already */
3014 if (unlikely(!is_vxge_card_up(vdev
))) {
3015 /* just store new value, will use later on open() */
3017 vxge_debug_init(vdev
->level_err
,
3018 "%s", "device is down on MTU change");
3022 vxge_debug_init(vdev
->level_trace
,
3023 "trying to apply new MTU %d", new_mtu
);
3025 if (vxge_close(dev
))
3029 vdev
->mtu
= new_mtu
;
3034 vxge_debug_init(vdev
->level_trace
,
3035 "%s: MTU changed to %d", vdev
->ndev
->name
, new_mtu
);
3037 vxge_debug_entryexit(vdev
->level_trace
,
3038 "%s:%d Exiting...", __func__
, __LINE__
);
3045 * @dev: pointer to the device structure
3047 * Updates the device statistics structure. This function updates the device
3048 * statistics structure in the net_device structure and returns a pointer
3051 static struct net_device_stats
*
3052 vxge_get_stats(struct net_device
*dev
)
3054 struct vxgedev
*vdev
;
3055 struct net_device_stats
*net_stats
;
3058 vdev
= netdev_priv(dev
);
3060 net_stats
= &vdev
->stats
.net_stats
;
3062 memset(net_stats
, 0, sizeof(struct net_device_stats
));
3064 for (k
= 0; k
< vdev
->no_of_vpath
; k
++) {
3065 net_stats
->rx_packets
+= vdev
->vpaths
[k
].ring
.stats
.rx_frms
;
3066 net_stats
->rx_bytes
+= vdev
->vpaths
[k
].ring
.stats
.rx_bytes
;
3067 net_stats
->rx_errors
+= vdev
->vpaths
[k
].ring
.stats
.rx_errors
;
3068 net_stats
->multicast
+= vdev
->vpaths
[k
].ring
.stats
.rx_mcast
;
3069 net_stats
->rx_dropped
+=
3070 vdev
->vpaths
[k
].ring
.stats
.rx_dropped
;
3072 net_stats
->tx_packets
+= vdev
->vpaths
[k
].fifo
.stats
.tx_frms
;
3073 net_stats
->tx_bytes
+= vdev
->vpaths
[k
].fifo
.stats
.tx_bytes
;
3074 net_stats
->tx_errors
+= vdev
->vpaths
[k
].fifo
.stats
.tx_errors
;
3082 * @dev: Device pointer.
3083 * @ifr: An IOCTL specific structure, that can contain a pointer to
3084 * a proprietary structure used to pass information to the driver.
3085 * @cmd: This is used to distinguish between the different commands that
3086 * can be passed to the IOCTL functions.
3088 * Entry point for the Ioctl.
3090 static int vxge_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3097 * @dev: pointer to net device structure
3099 * Watchdog for transmit side.
3100 * This function is triggered if the Tx Queue is stopped
3101 * for a pre-defined amount of time when the Interface is still up.
3104 vxge_tx_watchdog(struct net_device
*dev
)
3106 struct vxgedev
*vdev
;
3108 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3110 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3112 vdev
->cric_err_event
= VXGE_HW_EVENT_RESET_START
;
3115 vxge_debug_entryexit(VXGE_TRACE
,
3116 "%s:%d Exiting...", __func__
, __LINE__
);
3120 * vxge_vlan_rx_register
3121 * @dev: net device pointer.
3124 * Vlan group registration
3127 vxge_vlan_rx_register(struct net_device
*dev
, struct vlan_group
*grp
)
3129 struct vxgedev
*vdev
;
3130 struct vxge_vpath
*vpath
;
3133 enum vxge_hw_status status
;
3136 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3138 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3140 vpath
= &vdev
->vpaths
[0];
3141 if ((NULL
== grp
) && (vpath
->is_open
)) {
3142 /* Get the first vlan */
3143 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3145 while (status
== VXGE_HW_OK
) {
3147 /* Delete this vlan from the vid table */
3148 for (vp
= 0; vp
< vdev
->no_of_vpath
; vp
++) {
3149 vpath
= &vdev
->vpaths
[vp
];
3150 if (!vpath
->is_open
)
3153 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3156 /* Get the next vlan to be deleted */
3157 vpath
= &vdev
->vpaths
[0];
3158 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3164 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
3165 if (vdev
->vpaths
[i
].is_configured
)
3166 vdev
->vpaths
[i
].ring
.vlgrp
= grp
;
3169 vxge_debug_entryexit(VXGE_TRACE
,
3170 "%s:%d Exiting...", __func__
, __LINE__
);
3174 * vxge_vlan_rx_add_vid
3175 * @dev: net device pointer.
3178 * Add the vlan id to the devices vlan id table
3181 vxge_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
3183 struct vxgedev
*vdev
;
3184 struct vxge_vpath
*vpath
;
3187 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3189 /* Add these vlan to the vid table */
3190 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3191 vpath
= &vdev
->vpaths
[vp_id
];
3192 if (!vpath
->is_open
)
3194 vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
3199 * vxge_vlan_rx_add_vid
3200 * @dev: net device pointer.
3203 * Remove the vlan id from the device's vlan id table
3206 vxge_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
3208 struct vxgedev
*vdev
;
3209 struct vxge_vpath
*vpath
;
3212 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3214 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3216 vlan_group_set_device(vdev
->vlgrp
, vid
, NULL
);
3218 /* Delete this vlan from the vid table */
3219 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3220 vpath
= &vdev
->vpaths
[vp_id
];
3221 if (!vpath
->is_open
)
3223 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3225 vxge_debug_entryexit(VXGE_TRACE
,
3226 "%s:%d Exiting...", __func__
, __LINE__
);
3229 static const struct net_device_ops vxge_netdev_ops
= {
3230 .ndo_open
= vxge_open
,
3231 .ndo_stop
= vxge_close
,
3232 .ndo_get_stats
= vxge_get_stats
,
3233 .ndo_start_xmit
= vxge_xmit
,
3234 .ndo_validate_addr
= eth_validate_addr
,
3235 .ndo_set_multicast_list
= vxge_set_multicast
,
3237 .ndo_do_ioctl
= vxge_ioctl
,
3239 .ndo_set_mac_address
= vxge_set_mac_addr
,
3240 .ndo_change_mtu
= vxge_change_mtu
,
3241 .ndo_vlan_rx_register
= vxge_vlan_rx_register
,
3242 .ndo_vlan_rx_kill_vid
= vxge_vlan_rx_kill_vid
,
3243 .ndo_vlan_rx_add_vid
= vxge_vlan_rx_add_vid
,
3245 .ndo_tx_timeout
= vxge_tx_watchdog
,
3246 #ifdef CONFIG_NET_POLL_CONTROLLER
3247 .ndo_poll_controller
= vxge_netpoll
,
3251 int __devinit
vxge_device_register(struct __vxge_hw_device
*hldev
,
3252 struct vxge_config
*config
,
3253 int high_dma
, int no_of_vpath
,
3254 struct vxgedev
**vdev_out
)
3256 struct net_device
*ndev
;
3257 enum vxge_hw_status status
= VXGE_HW_OK
;
3258 struct vxgedev
*vdev
;
3259 int i
, ret
= 0, no_of_queue
= 1;
3263 if (config
->tx_steering_type
== TX_MULTIQ_STEERING
)
3264 no_of_queue
= no_of_vpath
;
3266 ndev
= alloc_etherdev_mq(sizeof(struct vxgedev
),
3270 vxge_hw_device_trace_level_get(hldev
),
3271 "%s : device allocation failed", __func__
);
3276 vxge_debug_entryexit(
3277 vxge_hw_device_trace_level_get(hldev
),
3278 "%s: %s:%d Entering...",
3279 ndev
->name
, __func__
, __LINE__
);
3281 vdev
= netdev_priv(ndev
);
3282 memset(vdev
, 0, sizeof(struct vxgedev
));
3286 vdev
->pdev
= hldev
->pdev
;
3287 memcpy(&vdev
->config
, config
, sizeof(struct vxge_config
));
3288 vdev
->rx_csum
= 1; /* Enable Rx CSUM by default. */
3290 SET_NETDEV_DEV(ndev
, &vdev
->pdev
->dev
);
3292 ndev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
|
3293 NETIF_F_HW_VLAN_FILTER
;
3294 /* Driver entry points */
3295 ndev
->irq
= vdev
->pdev
->irq
;
3296 ndev
->base_addr
= (unsigned long) hldev
->bar0
;
3298 ndev
->netdev_ops
= &vxge_netdev_ops
;
3300 ndev
->watchdog_timeo
= VXGE_LL_WATCH_DOG_TIMEOUT
;
3302 initialize_ethtool_ops(ndev
);
3304 /* Allocate memory for vpath */
3305 vdev
->vpaths
= kzalloc((sizeof(struct vxge_vpath
)) *
3306 no_of_vpath
, GFP_KERNEL
);
3307 if (!vdev
->vpaths
) {
3308 vxge_debug_init(VXGE_ERR
,
3309 "%s: vpath memory allocation failed",
3315 ndev
->features
|= NETIF_F_SG
;
3317 ndev
->features
|= NETIF_F_HW_CSUM
;
3318 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3319 "%s : checksuming enabled", __func__
);
3322 ndev
->features
|= NETIF_F_HIGHDMA
;
3323 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3324 "%s : using High DMA", __func__
);
3327 ndev
->features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
3329 if (vdev
->config
.gro_enable
)
3330 ndev
->features
|= NETIF_F_GRO
;
3332 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
)
3333 ndev
->real_num_tx_queues
= no_of_vpath
;
3336 ndev
->features
|= NETIF_F_LLTX
;
3339 for (i
= 0; i
< no_of_vpath
; i
++)
3340 spin_lock_init(&vdev
->vpaths
[i
].fifo
.tx_lock
);
3342 if (register_netdev(ndev
)) {
3343 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3344 "%s: %s : device registration failed!",
3345 ndev
->name
, __func__
);
3350 /* Set the factory defined MAC address initially */
3351 ndev
->addr_len
= ETH_ALEN
;
3353 /* Make Link state as off at this point, when the Link change
3354 * interrupt comes the state will be automatically changed to
3357 netif_carrier_off(ndev
);
3359 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3360 "%s: Ethernet device registered",
3365 /* Resetting the Device stats */
3366 status
= vxge_hw_mrpcim_stats_access(
3368 VXGE_HW_STATS_OP_CLEAR_ALL_STATS
,
3373 if (status
== VXGE_HW_ERR_PRIVILAGED_OPEARATION
)
3375 vxge_hw_device_trace_level_get(hldev
),
3376 "%s: device stats clear returns"
3377 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev
->name
);
3379 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev
),
3380 "%s: %s:%d Exiting...",
3381 ndev
->name
, __func__
, __LINE__
);
3385 kfree(vdev
->vpaths
);
3393 * vxge_device_unregister
3395 * This function will unregister and free network device
3398 vxge_device_unregister(struct __vxge_hw_device
*hldev
)
3400 struct vxgedev
*vdev
;
3401 struct net_device
*dev
;
3403 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3404 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3409 vdev
= netdev_priv(dev
);
3410 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3411 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3412 level_trace
= vdev
->level_trace
;
3414 vxge_debug_entryexit(level_trace
,
3415 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3417 memcpy(buf
, vdev
->ndev
->name
, IFNAMSIZ
);
3419 /* in 2.6 will call stop() if device is up */
3420 unregister_netdev(dev
);
3422 flush_scheduled_work();
3424 vxge_debug_init(level_trace
, "%s: ethernet device unregistered", buf
);
3425 vxge_debug_entryexit(level_trace
,
3426 "%s: %s:%d Exiting...", buf
, __func__
, __LINE__
);
3430 * vxge_callback_crit_err
3432 * This function is called by the alarm handler in interrupt context.
3433 * Driver must analyze it based on the event type.
3436 vxge_callback_crit_err(struct __vxge_hw_device
*hldev
,
3437 enum vxge_hw_event type
, u64 vp_id
)
3439 struct net_device
*dev
= hldev
->ndev
;
3440 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
3443 vxge_debug_entryexit(vdev
->level_trace
,
3444 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3446 /* Note: This event type should be used for device wide
3447 * indications only - Serious errors, Slot freeze and critical errors
3449 vdev
->cric_err_event
= type
;
3451 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++)
3452 if (vdev
->vpaths
[vpath_idx
].device_id
== vp_id
)
3455 if (!test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
)) {
3456 if (type
== VXGE_HW_EVENT_SLOT_FREEZE
) {
3457 vxge_debug_init(VXGE_ERR
,
3458 "%s: Slot is frozen", vdev
->ndev
->name
);
3459 } else if (type
== VXGE_HW_EVENT_SERR
) {
3460 vxge_debug_init(VXGE_ERR
,
3461 "%s: Encountered Serious Error",
3463 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
)
3464 vxge_debug_init(VXGE_ERR
,
3465 "%s: Encountered Critical Error",
3469 if ((type
== VXGE_HW_EVENT_SERR
) ||
3470 (type
== VXGE_HW_EVENT_SLOT_FREEZE
)) {
3471 if (unlikely(vdev
->exec_mode
))
3472 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3473 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
) {
3474 vxge_hw_device_mask_all(hldev
);
3475 if (unlikely(vdev
->exec_mode
))
3476 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3477 } else if ((type
== VXGE_HW_EVENT_FIFO_ERR
) ||
3478 (type
== VXGE_HW_EVENT_VPATH_ERR
)) {
3480 if (unlikely(vdev
->exec_mode
))
3481 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3483 /* check if this vpath is already set for reset */
3484 if (!test_and_set_bit(vpath_idx
, &vdev
->vp_reset
)) {
3486 /* disable interrupts for this vpath */
3487 vxge_vpath_intr_disable(vdev
, vpath_idx
);
3489 /* stop the queue for this vpath */
3490 vxge_stop_tx_queue(&vdev
->vpaths
[vpath_idx
].
3496 vxge_debug_entryexit(vdev
->level_trace
,
3497 "%s: %s:%d Exiting...",
3498 vdev
->ndev
->name
, __func__
, __LINE__
);
3501 static void verify_bandwidth(void)
3503 int i
, band_width
, total
= 0, equal_priority
= 0;
3505 /* 1. If user enters 0 for some fifo, give equal priority to all */
3506 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3507 if (bw_percentage
[i
] == 0) {
3513 if (!equal_priority
) {
3514 /* 2. If sum exceeds 100, give equal priority to all */
3515 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3516 if (bw_percentage
[i
] == 0xFF)
3519 total
+= bw_percentage
[i
];
3520 if (total
> VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3527 if (!equal_priority
) {
3528 /* Is all the bandwidth consumed? */
3529 if (total
< VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3530 if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
) {
3531 /* Split rest of bw equally among next VPs*/
3533 (VXGE_HW_VPATH_BANDWIDTH_MAX
- total
) /
3534 (VXGE_HW_MAX_VIRTUAL_PATHS
- i
);
3535 if (band_width
< 2) /* min of 2% */
3538 for (; i
< VXGE_HW_MAX_VIRTUAL_PATHS
;
3544 } else if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
)
3548 if (equal_priority
) {
3549 vxge_debug_init(VXGE_ERR
,
3550 "%s: Assigning equal bandwidth to all the vpaths",
3552 bw_percentage
[0] = VXGE_HW_VPATH_BANDWIDTH_MAX
/
3553 VXGE_HW_MAX_VIRTUAL_PATHS
;
3554 for (i
= 1; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3555 bw_percentage
[i
] = bw_percentage
[0];
3562 * Vpath configuration
3564 static int __devinit
vxge_config_vpaths(
3565 struct vxge_hw_device_config
*device_config
,
3566 u64 vpath_mask
, struct vxge_config
*config_param
)
3568 int i
, no_of_vpaths
= 0, default_no_vpath
= 0, temp
;
3569 u32 txdl_size
, txdl_per_memblock
;
3571 temp
= driver_config
->vpath_per_dev
;
3572 if ((driver_config
->vpath_per_dev
== VXGE_USE_DEFAULT
) &&
3573 (max_config_dev
== VXGE_MAX_CONFIG_DEV
)) {
3574 /* No more CPU. Return vpath number as zero.*/
3575 if (driver_config
->g_no_cpus
== -1)
3578 if (!driver_config
->g_no_cpus
)
3579 driver_config
->g_no_cpus
= num_online_cpus();
3581 driver_config
->vpath_per_dev
= driver_config
->g_no_cpus
>> 1;
3582 if (!driver_config
->vpath_per_dev
)
3583 driver_config
->vpath_per_dev
= 1;
3585 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3586 if (!vxge_bVALn(vpath_mask
, i
, 1))
3590 if (default_no_vpath
< driver_config
->vpath_per_dev
)
3591 driver_config
->vpath_per_dev
= default_no_vpath
;
3593 driver_config
->g_no_cpus
= driver_config
->g_no_cpus
-
3594 (driver_config
->vpath_per_dev
* 2);
3595 if (driver_config
->g_no_cpus
<= 0)
3596 driver_config
->g_no_cpus
= -1;
3599 if (driver_config
->vpath_per_dev
== 1) {
3600 vxge_debug_ll_config(VXGE_TRACE
,
3601 "%s: Disable tx and rx steering, "
3602 "as single vpath is configured", VXGE_DRIVER_NAME
);
3603 config_param
->rth_steering
= NO_STEERING
;
3604 config_param
->tx_steering_type
= NO_STEERING
;
3605 device_config
->rth_en
= 0;
3608 /* configure bandwidth */
3609 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3610 device_config
->vp_config
[i
].min_bandwidth
= bw_percentage
[i
];
3612 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3613 device_config
->vp_config
[i
].vp_id
= i
;
3614 device_config
->vp_config
[i
].mtu
= VXGE_HW_DEFAULT_MTU
;
3615 if (no_of_vpaths
< driver_config
->vpath_per_dev
) {
3616 if (!vxge_bVALn(vpath_mask
, i
, 1)) {
3617 vxge_debug_ll_config(VXGE_TRACE
,
3618 "%s: vpath: %d is not available",
3619 VXGE_DRIVER_NAME
, i
);
3622 vxge_debug_ll_config(VXGE_TRACE
,
3623 "%s: vpath: %d available",
3624 VXGE_DRIVER_NAME
, i
);
3628 vxge_debug_ll_config(VXGE_TRACE
,
3629 "%s: vpath: %d is not configured, "
3630 "max_config_vpath exceeded",
3631 VXGE_DRIVER_NAME
, i
);
3635 /* Configure Tx fifo's */
3636 device_config
->vp_config
[i
].fifo
.enable
=
3637 VXGE_HW_FIFO_ENABLE
;
3638 device_config
->vp_config
[i
].fifo
.max_frags
=
3640 device_config
->vp_config
[i
].fifo
.memblock_size
=
3641 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
;
3643 txdl_size
= MAX_SKB_FRAGS
* sizeof(struct vxge_hw_fifo_txd
);
3644 txdl_per_memblock
= VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
/ txdl_size
;
3646 device_config
->vp_config
[i
].fifo
.fifo_blocks
=
3647 ((VXGE_DEF_FIFO_LENGTH
- 1) / txdl_per_memblock
) + 1;
3649 device_config
->vp_config
[i
].fifo
.intr
=
3650 VXGE_HW_FIFO_QUEUE_INTR_DISABLE
;
3652 /* Configure tti properties */
3653 device_config
->vp_config
[i
].tti
.intr_enable
=
3654 VXGE_HW_TIM_INTR_ENABLE
;
3656 device_config
->vp_config
[i
].tti
.btimer_val
=
3657 (VXGE_TTI_BTIMER_VAL
* 1000) / 272;
3659 device_config
->vp_config
[i
].tti
.timer_ac_en
=
3660 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3662 /* For msi-x with napi (each vector
3663 has a handler of its own) -
3664 Set CI to OFF for all vpaths */
3665 device_config
->vp_config
[i
].tti
.timer_ci_en
=
3666 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3668 device_config
->vp_config
[i
].tti
.timer_ri_en
=
3669 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3671 device_config
->vp_config
[i
].tti
.util_sel
=
3672 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL
;
3674 device_config
->vp_config
[i
].tti
.ltimer_val
=
3675 (VXGE_TTI_LTIMER_VAL
* 1000) / 272;
3677 device_config
->vp_config
[i
].tti
.rtimer_val
=
3678 (VXGE_TTI_RTIMER_VAL
* 1000) / 272;
3680 device_config
->vp_config
[i
].tti
.urange_a
= TTI_TX_URANGE_A
;
3681 device_config
->vp_config
[i
].tti
.urange_b
= TTI_TX_URANGE_B
;
3682 device_config
->vp_config
[i
].tti
.urange_c
= TTI_TX_URANGE_C
;
3683 device_config
->vp_config
[i
].tti
.uec_a
= TTI_TX_UFC_A
;
3684 device_config
->vp_config
[i
].tti
.uec_b
= TTI_TX_UFC_B
;
3685 device_config
->vp_config
[i
].tti
.uec_c
= TTI_TX_UFC_C
;
3686 device_config
->vp_config
[i
].tti
.uec_d
= TTI_TX_UFC_D
;
3688 /* Configure Rx rings */
3689 device_config
->vp_config
[i
].ring
.enable
=
3690 VXGE_HW_RING_ENABLE
;
3692 device_config
->vp_config
[i
].ring
.ring_blocks
=
3693 VXGE_HW_DEF_RING_BLOCKS
;
3694 device_config
->vp_config
[i
].ring
.buffer_mode
=
3695 VXGE_HW_RING_RXD_BUFFER_MODE_1
;
3696 device_config
->vp_config
[i
].ring
.rxds_limit
=
3697 VXGE_HW_DEF_RING_RXDS_LIMIT
;
3698 device_config
->vp_config
[i
].ring
.scatter_mode
=
3699 VXGE_HW_RING_SCATTER_MODE_A
;
3701 /* Configure rti properties */
3702 device_config
->vp_config
[i
].rti
.intr_enable
=
3703 VXGE_HW_TIM_INTR_ENABLE
;
3705 device_config
->vp_config
[i
].rti
.btimer_val
=
3706 (VXGE_RTI_BTIMER_VAL
* 1000)/272;
3708 device_config
->vp_config
[i
].rti
.timer_ac_en
=
3709 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3711 device_config
->vp_config
[i
].rti
.timer_ci_en
=
3712 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3714 device_config
->vp_config
[i
].rti
.timer_ri_en
=
3715 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3717 device_config
->vp_config
[i
].rti
.util_sel
=
3718 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL
;
3720 device_config
->vp_config
[i
].rti
.urange_a
=
3722 device_config
->vp_config
[i
].rti
.urange_b
=
3724 device_config
->vp_config
[i
].rti
.urange_c
=
3726 device_config
->vp_config
[i
].rti
.uec_a
= RTI_RX_UFC_A
;
3727 device_config
->vp_config
[i
].rti
.uec_b
= RTI_RX_UFC_B
;
3728 device_config
->vp_config
[i
].rti
.uec_c
= RTI_RX_UFC_C
;
3729 device_config
->vp_config
[i
].rti
.uec_d
= RTI_RX_UFC_D
;
3731 device_config
->vp_config
[i
].rti
.rtimer_val
=
3732 (VXGE_RTI_RTIMER_VAL
* 1000) / 272;
3734 device_config
->vp_config
[i
].rti
.ltimer_val
=
3735 (VXGE_RTI_LTIMER_VAL
* 1000) / 272;
3737 device_config
->vp_config
[i
].rpa_strip_vlan_tag
=
3741 driver_config
->vpath_per_dev
= temp
;
3742 return no_of_vpaths
;
3745 /* initialize device configuratrions */
3746 static void __devinit
vxge_device_config_init(
3747 struct vxge_hw_device_config
*device_config
,
3750 /* Used for CQRQ/SRQ. */
3751 device_config
->dma_blockpool_initial
=
3752 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE
;
3754 device_config
->dma_blockpool_max
=
3755 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE
;
3757 if (max_mac_vpath
> VXGE_MAX_MAC_ADDR_COUNT
)
3758 max_mac_vpath
= VXGE_MAX_MAC_ADDR_COUNT
;
3760 #ifndef CONFIG_PCI_MSI
3761 vxge_debug_init(VXGE_ERR
,
3762 "%s: This Kernel does not support "
3763 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME
);
3767 /* Configure whether MSI-X or IRQL. */
3768 switch (*intr_type
) {
3770 device_config
->intr_mode
= VXGE_HW_INTR_MODE_IRQLINE
;
3774 device_config
->intr_mode
= VXGE_HW_INTR_MODE_MSIX
;
3777 /* Timer period between device poll */
3778 device_config
->device_poll_millis
= VXGE_TIMER_DELAY
;
3780 /* Configure mac based steering. */
3781 device_config
->rts_mac_en
= addr_learn_en
;
3783 /* Configure Vpaths */
3784 device_config
->rth_it_type
= VXGE_HW_RTH_IT_TYPE_MULTI_IT
;
3786 vxge_debug_ll_config(VXGE_TRACE
, "%s : Device Config Params ",
3788 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_initial : %d",
3789 device_config
->dma_blockpool_initial
);
3790 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_max : %d",
3791 device_config
->dma_blockpool_max
);
3792 vxge_debug_ll_config(VXGE_TRACE
, "intr_mode : %d",
3793 device_config
->intr_mode
);
3794 vxge_debug_ll_config(VXGE_TRACE
, "device_poll_millis : %d",
3795 device_config
->device_poll_millis
);
3796 vxge_debug_ll_config(VXGE_TRACE
, "rts_mac_en : %d",
3797 device_config
->rts_mac_en
);
3798 vxge_debug_ll_config(VXGE_TRACE
, "rth_en : %d",
3799 device_config
->rth_en
);
3800 vxge_debug_ll_config(VXGE_TRACE
, "rth_it_type : %d",
3801 device_config
->rth_it_type
);
3804 static void __devinit
vxge_print_parm(struct vxgedev
*vdev
, u64 vpath_mask
)
3808 vxge_debug_init(VXGE_TRACE
,
3809 "%s: %d Vpath(s) opened",
3810 vdev
->ndev
->name
, vdev
->no_of_vpath
);
3812 switch (vdev
->config
.intr_type
) {
3814 vxge_debug_init(VXGE_TRACE
,
3815 "%s: Interrupt type INTA", vdev
->ndev
->name
);
3819 vxge_debug_init(VXGE_TRACE
,
3820 "%s: Interrupt type MSI-X", vdev
->ndev
->name
);
3824 if (vdev
->config
.rth_steering
) {
3825 vxge_debug_init(VXGE_TRACE
,
3826 "%s: RTH steering enabled for TCP_IPV4",
3829 vxge_debug_init(VXGE_TRACE
,
3830 "%s: RTH steering disabled", vdev
->ndev
->name
);
3833 switch (vdev
->config
.tx_steering_type
) {
3835 vxge_debug_init(VXGE_TRACE
,
3836 "%s: Tx steering disabled", vdev
->ndev
->name
);
3838 case TX_PRIORITY_STEERING
:
3839 vxge_debug_init(VXGE_TRACE
,
3840 "%s: Unsupported tx steering option",
3842 vxge_debug_init(VXGE_TRACE
,
3843 "%s: Tx steering disabled", vdev
->ndev
->name
);
3844 vdev
->config
.tx_steering_type
= 0;
3846 case TX_VLAN_STEERING
:
3847 vxge_debug_init(VXGE_TRACE
,
3848 "%s: Unsupported tx steering option",
3850 vxge_debug_init(VXGE_TRACE
,
3851 "%s: Tx steering disabled", vdev
->ndev
->name
);
3852 vdev
->config
.tx_steering_type
= 0;
3854 case TX_MULTIQ_STEERING
:
3855 vxge_debug_init(VXGE_TRACE
,
3856 "%s: Tx multiqueue steering enabled",
3859 case TX_PORT_STEERING
:
3860 vxge_debug_init(VXGE_TRACE
,
3861 "%s: Tx port steering enabled",
3865 vxge_debug_init(VXGE_ERR
,
3866 "%s: Unsupported tx steering type",
3868 vxge_debug_init(VXGE_TRACE
,
3869 "%s: Tx steering disabled", vdev
->ndev
->name
);
3870 vdev
->config
.tx_steering_type
= 0;
3873 if (vdev
->config
.gro_enable
) {
3874 vxge_debug_init(VXGE_ERR
,
3875 "%s: Generic receive offload enabled",
3878 vxge_debug_init(VXGE_TRACE
,
3879 "%s: Generic receive offload disabled",
3882 if (vdev
->config
.addr_learn_en
)
3883 vxge_debug_init(VXGE_TRACE
,
3884 "%s: MAC Address learning enabled", vdev
->ndev
->name
);
3886 vxge_debug_init(VXGE_TRACE
,
3887 "%s: Rx doorbell mode enabled", vdev
->ndev
->name
);
3889 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3890 if (!vxge_bVALn(vpath_mask
, i
, 1))
3892 vxge_debug_ll_config(VXGE_TRACE
,
3893 "%s: MTU size - %d", vdev
->ndev
->name
,
3894 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3895 config
.vp_config
[i
].mtu
);
3896 vxge_debug_init(VXGE_TRACE
,
3897 "%s: VLAN tag stripping %s", vdev
->ndev
->name
,
3898 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3899 config
.vp_config
[i
].rpa_strip_vlan_tag
3900 ? "Enabled" : "Disabled");
3901 vxge_debug_init(VXGE_TRACE
,
3902 "%s: Ring blocks : %d", vdev
->ndev
->name
,
3903 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3904 config
.vp_config
[i
].ring
.ring_blocks
);
3905 vxge_debug_init(VXGE_TRACE
,
3906 "%s: Fifo blocks : %d", vdev
->ndev
->name
,
3907 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3908 config
.vp_config
[i
].fifo
.fifo_blocks
);
3909 vxge_debug_ll_config(VXGE_TRACE
,
3910 "%s: Max frags : %d", vdev
->ndev
->name
,
3911 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3912 config
.vp_config
[i
].fifo
.max_frags
);
3919 * vxge_pm_suspend - vxge power management suspend entry point
3922 static int vxge_pm_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3927 * vxge_pm_resume - vxge power management resume entry point
3930 static int vxge_pm_resume(struct pci_dev
*pdev
)
3938 * vxge_io_error_detected - called when PCI error is detected
3939 * @pdev: Pointer to PCI device
3940 * @state: The current pci connection state
3942 * This function is called after a PCI bus error affecting
3943 * this device has been detected.
3945 static pci_ers_result_t
vxge_io_error_detected(struct pci_dev
*pdev
,
3946 pci_channel_state_t state
)
3948 struct __vxge_hw_device
*hldev
=
3949 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3950 struct net_device
*netdev
= hldev
->ndev
;
3952 netif_device_detach(netdev
);
3954 if (netif_running(netdev
)) {
3955 /* Bring down the card, while avoiding PCI I/O */
3956 do_vxge_close(netdev
, 0);
3959 pci_disable_device(pdev
);
3961 return PCI_ERS_RESULT_NEED_RESET
;
3965 * vxge_io_slot_reset - called after the pci bus has been reset.
3966 * @pdev: Pointer to PCI device
3968 * Restart the card from scratch, as if from a cold-boot.
3969 * At this point, the card has exprienced a hard reset,
3970 * followed by fixups by BIOS, and has its config space
3971 * set up identically to what it was at cold boot.
3973 static pci_ers_result_t
vxge_io_slot_reset(struct pci_dev
*pdev
)
3975 struct __vxge_hw_device
*hldev
=
3976 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3977 struct net_device
*netdev
= hldev
->ndev
;
3979 struct vxgedev
*vdev
= netdev_priv(netdev
);
3981 if (pci_enable_device(pdev
)) {
3982 printk(KERN_ERR
"%s: "
3983 "Cannot re-enable device after reset\n",
3985 return PCI_ERS_RESULT_DISCONNECT
;
3988 pci_set_master(pdev
);
3991 return PCI_ERS_RESULT_RECOVERED
;
3995 * vxge_io_resume - called when traffic can start flowing again.
3996 * @pdev: Pointer to PCI device
3998 * This callback is called when the error recovery driver tells
3999 * us that its OK to resume normal operation.
4001 static void vxge_io_resume(struct pci_dev
*pdev
)
4003 struct __vxge_hw_device
*hldev
=
4004 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
4005 struct net_device
*netdev
= hldev
->ndev
;
4007 if (netif_running(netdev
)) {
4008 if (vxge_open(netdev
)) {
4009 printk(KERN_ERR
"%s: "
4010 "Can't bring device back up after reset\n",
4016 netif_device_attach(netdev
);
4021 * @pdev : structure containing the PCI related information of the device.
4022 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4024 * This function is called when a new PCI device gets detected and initializes
4027 * returns 0 on success and negative on failure.
4030 static int __devinit
4031 vxge_probe(struct pci_dev
*pdev
, const struct pci_device_id
*pre
)
4033 struct __vxge_hw_device
*hldev
;
4034 enum vxge_hw_status status
;
4038 struct vxgedev
*vdev
;
4039 struct vxge_config ll_config
;
4040 struct vxge_hw_device_config
*device_config
= NULL
;
4041 struct vxge_hw_device_attr attr
;
4042 int i
, j
, no_of_vpath
= 0, max_vpath_supported
= 0;
4044 struct vxge_mac_addrs
*entry
;
4045 static int bus
= -1, device
= -1;
4048 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
4051 if (bus
!= pdev
->bus
->number
)
4053 if (device
!= PCI_SLOT(pdev
->devfn
))
4056 bus
= pdev
->bus
->number
;
4057 device
= PCI_SLOT(pdev
->devfn
);
4060 if (driver_config
->config_dev_cnt
&&
4061 (driver_config
->config_dev_cnt
!=
4062 driver_config
->total_dev_cnt
))
4063 vxge_debug_init(VXGE_ERR
,
4064 "%s: Configured %d of %d devices",
4066 driver_config
->config_dev_cnt
,
4067 driver_config
->total_dev_cnt
);
4068 driver_config
->config_dev_cnt
= 0;
4069 driver_config
->total_dev_cnt
= 0;
4070 driver_config
->g_no_cpus
= 0;
4071 driver_config
->vpath_per_dev
= max_config_vpath
;
4074 driver_config
->total_dev_cnt
++;
4075 if (++driver_config
->config_dev_cnt
> max_config_dev
) {
4080 device_config
= kzalloc(sizeof(struct vxge_hw_device_config
),
4082 if (!device_config
) {
4084 vxge_debug_init(VXGE_ERR
,
4085 "device_config : malloc failed %s %d",
4086 __FILE__
, __LINE__
);
4090 memset(&ll_config
, 0, sizeof(struct vxge_config
));
4091 ll_config
.tx_steering_type
= TX_MULTIQ_STEERING
;
4092 ll_config
.intr_type
= MSI_X
;
4093 ll_config
.napi_weight
= NEW_NAPI_WEIGHT
;
4094 ll_config
.rth_steering
= RTH_STEERING
;
4096 /* get the default configuration parameters */
4097 vxge_hw_device_config_default_get(device_config
);
4099 /* initialize configuration parameters */
4100 vxge_device_config_init(device_config
, &ll_config
.intr_type
);
4102 ret
= pci_enable_device(pdev
);
4104 vxge_debug_init(VXGE_ERR
,
4105 "%s : can not enable PCI device", __func__
);
4109 if (!pci_set_dma_mask(pdev
, 0xffffffffffffffffULL
)) {
4110 vxge_debug_ll_config(VXGE_TRACE
,
4111 "%s : using 64bit DMA", __func__
);
4115 if (pci_set_consistent_dma_mask(pdev
,
4116 0xffffffffffffffffULL
)) {
4117 vxge_debug_init(VXGE_ERR
,
4118 "%s : unable to obtain 64bit DMA for "
4119 "consistent allocations", __func__
);
4123 } else if (!pci_set_dma_mask(pdev
, 0xffffffffUL
)) {
4124 vxge_debug_ll_config(VXGE_TRACE
,
4125 "%s : using 32bit DMA", __func__
);
4131 if (pci_request_regions(pdev
, VXGE_DRIVER_NAME
)) {
4132 vxge_debug_init(VXGE_ERR
,
4133 "%s : request regions failed", __func__
);
4138 pci_set_master(pdev
);
4140 attr
.bar0
= pci_ioremap_bar(pdev
, 0);
4142 vxge_debug_init(VXGE_ERR
,
4143 "%s : cannot remap io memory bar0", __func__
);
4147 vxge_debug_ll_config(VXGE_TRACE
,
4148 "pci ioremap bar0: %p:0x%llx",
4150 (unsigned long long)pci_resource_start(pdev
, 0));
4152 attr
.bar1
= pci_ioremap_bar(pdev
, 2);
4154 vxge_debug_init(VXGE_ERR
,
4155 "%s : cannot remap io memory bar2", __func__
);
4159 vxge_debug_ll_config(VXGE_TRACE
,
4160 "pci ioremap bar1: %p:0x%llx",
4162 (unsigned long long)pci_resource_start(pdev
, 2));
4164 status
= vxge_hw_device_hw_info_get(attr
.bar0
,
4165 &ll_config
.device_hw_info
);
4166 if (status
!= VXGE_HW_OK
) {
4167 vxge_debug_init(VXGE_ERR
,
4168 "%s: Reading of hardware info failed."
4169 "Please try upgrading the firmware.", VXGE_DRIVER_NAME
);
4174 if (ll_config
.device_hw_info
.fw_version
.major
!=
4175 VXGE_DRIVER_VERSION_MAJOR
) {
4176 vxge_debug_init(VXGE_ERR
,
4177 "FW Ver.(maj): %d not driver's expected version: %d",
4178 ll_config
.device_hw_info
.fw_version
.major
,
4179 VXGE_DRIVER_VERSION_MAJOR
);
4184 vpath_mask
= ll_config
.device_hw_info
.vpath_mask
;
4185 if (vpath_mask
== 0) {
4186 vxge_debug_ll_config(VXGE_TRACE
,
4187 "%s: No vpaths available in device", VXGE_DRIVER_NAME
);
4192 vxge_debug_ll_config(VXGE_TRACE
,
4193 "%s:%d Vpath mask = %llx", __func__
, __LINE__
,
4194 (unsigned long long)vpath_mask
);
4196 /* Check how many vpaths are available */
4197 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4198 if (!((vpath_mask
) & vxge_mBIT(i
)))
4200 max_vpath_supported
++;
4204 * Configure vpaths and get driver configured number of vpaths
4205 * which is less than or equal to the maximum vpaths per function.
4207 no_of_vpath
= vxge_config_vpaths(device_config
, vpath_mask
, &ll_config
);
4209 vxge_debug_ll_config(VXGE_ERR
,
4210 "%s: No more vpaths to configure", VXGE_DRIVER_NAME
);
4215 /* Setting driver callbacks */
4216 attr
.uld_callbacks
.link_up
= vxge_callback_link_up
;
4217 attr
.uld_callbacks
.link_down
= vxge_callback_link_down
;
4218 attr
.uld_callbacks
.crit_err
= vxge_callback_crit_err
;
4220 status
= vxge_hw_device_initialize(&hldev
, &attr
, device_config
);
4221 if (status
!= VXGE_HW_OK
) {
4222 vxge_debug_init(VXGE_ERR
,
4223 "Failed to initialize device (%d)", status
);
4228 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4230 /* set private device info */
4231 pci_set_drvdata(pdev
, hldev
);
4233 ll_config
.gro_enable
= VXGE_GRO_ALWAYS_AGGREGATE
;
4234 ll_config
.fifo_indicate_max_pkts
= VXGE_FIFO_INDICATE_MAX_PKTS
;
4235 ll_config
.addr_learn_en
= addr_learn_en
;
4236 ll_config
.rth_algorithm
= RTH_ALG_JENKINS
;
4237 ll_config
.rth_hash_type_tcpipv4
= VXGE_HW_RING_HASH_TYPE_TCP_IPV4
;
4238 ll_config
.rth_hash_type_ipv4
= VXGE_HW_RING_HASH_TYPE_NONE
;
4239 ll_config
.rth_hash_type_tcpipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4240 ll_config
.rth_hash_type_ipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4241 ll_config
.rth_hash_type_tcpipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4242 ll_config
.rth_hash_type_ipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4243 ll_config
.rth_bkt_sz
= RTH_BUCKET_SIZE
;
4244 ll_config
.tx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4245 ll_config
.rx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4247 if (vxge_device_register(hldev
, &ll_config
, high_dma
, no_of_vpath
,
4253 vxge_hw_device_debug_set(hldev
, VXGE_TRACE
, VXGE_COMPONENT_LL
);
4254 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4255 vxge_hw_device_trace_level_get(hldev
));
4257 /* set private HW device info */
4258 hldev
->ndev
= vdev
->ndev
;
4259 vdev
->mtu
= VXGE_HW_DEFAULT_MTU
;
4260 vdev
->bar0
= attr
.bar0
;
4261 vdev
->bar1
= attr
.bar1
;
4262 vdev
->max_vpath_supported
= max_vpath_supported
;
4263 vdev
->no_of_vpath
= no_of_vpath
;
4265 /* Virtual Path count */
4266 for (i
= 0, j
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4267 if (!vxge_bVALn(vpath_mask
, i
, 1))
4269 if (j
>= vdev
->no_of_vpath
)
4272 vdev
->vpaths
[j
].is_configured
= 1;
4273 vdev
->vpaths
[j
].device_id
= i
;
4274 vdev
->vpaths
[j
].fifo
.driver_id
= j
;
4275 vdev
->vpaths
[j
].ring
.driver_id
= j
;
4276 vdev
->vpaths
[j
].vdev
= vdev
;
4277 vdev
->vpaths
[j
].max_mac_addr_cnt
= max_mac_vpath
;
4278 memcpy((u8
*)vdev
->vpaths
[j
].macaddr
,
4279 (u8
*)ll_config
.device_hw_info
.mac_addrs
[i
],
4282 /* Initialize the mac address list header */
4283 INIT_LIST_HEAD(&vdev
->vpaths
[j
].mac_addr_list
);
4285 vdev
->vpaths
[j
].mac_addr_cnt
= 0;
4286 vdev
->vpaths
[j
].mcast_addr_cnt
= 0;
4289 vdev
->exec_mode
= VXGE_EXEC_MODE_DISABLE
;
4290 vdev
->max_config_port
= max_config_port
;
4292 vdev
->vlan_tag_strip
= vlan_tag_strip
;
4294 /* map the hashing selector table to the configured vpaths */
4295 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4296 vdev
->vpath_selector
[i
] = vpath_selector
[i
];
4298 macaddr
= (u8
*)vdev
->vpaths
[0].macaddr
;
4300 ll_config
.device_hw_info
.serial_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4301 ll_config
.device_hw_info
.product_desc
[VXGE_HW_INFO_LEN
- 1] = '\0';
4302 ll_config
.device_hw_info
.part_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4304 vxge_debug_init(VXGE_TRACE
, "%s: SERIAL NUMBER: %s",
4305 vdev
->ndev
->name
, ll_config
.device_hw_info
.serial_number
);
4307 vxge_debug_init(VXGE_TRACE
, "%s: PART NUMBER: %s",
4308 vdev
->ndev
->name
, ll_config
.device_hw_info
.part_number
);
4310 vxge_debug_init(VXGE_TRACE
, "%s: Neterion %s Server Adapter",
4311 vdev
->ndev
->name
, ll_config
.device_hw_info
.product_desc
);
4313 vxge_debug_init(VXGE_TRACE
,
4314 "%s: MAC ADDR: %02X:%02X:%02X:%02X:%02X:%02X",
4315 vdev
->ndev
->name
, macaddr
[0], macaddr
[1], macaddr
[2],
4316 macaddr
[3], macaddr
[4], macaddr
[5]);
4318 vxge_debug_init(VXGE_TRACE
, "%s: Link Width x%d",
4319 vdev
->ndev
->name
, vxge_hw_device_link_width_get(hldev
));
4321 vxge_debug_init(VXGE_TRACE
,
4322 "%s: Firmware version : %s Date : %s", vdev
->ndev
->name
,
4323 ll_config
.device_hw_info
.fw_version
.version
,
4324 ll_config
.device_hw_info
.fw_date
.date
);
4326 vxge_print_parm(vdev
, vpath_mask
);
4328 /* Store the fw version for ethttool option */
4329 strcpy(vdev
->fw_version
, ll_config
.device_hw_info
.fw_version
.version
);
4330 memcpy(vdev
->ndev
->dev_addr
, (u8
*)vdev
->vpaths
[0].macaddr
, ETH_ALEN
);
4331 memcpy(vdev
->ndev
->perm_addr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4333 /* Copy the station mac address to the list */
4334 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4335 entry
= (struct vxge_mac_addrs
*)
4336 kzalloc(sizeof(struct vxge_mac_addrs
),
4338 if (NULL
== entry
) {
4339 vxge_debug_init(VXGE_ERR
,
4340 "%s: mac_addr_list : memory allocation failed",
4345 macaddr
= (u8
*)&entry
->macaddr
;
4346 memcpy(macaddr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4347 list_add(&entry
->item
, &vdev
->vpaths
[i
].mac_addr_list
);
4348 vdev
->vpaths
[i
].mac_addr_cnt
= 1;
4351 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
4352 vdev
->ndev
->name
, __func__
, __LINE__
);
4354 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4355 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4356 vxge_hw_device_trace_level_get(hldev
));
4361 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4362 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4364 vxge_device_unregister(hldev
);
4366 vxge_hw_device_terminate(hldev
);
4372 pci_release_regions(pdev
);
4374 pci_disable_device(pdev
);
4376 kfree(device_config
);
4377 driver_config
->config_dev_cnt
--;
4378 pci_set_drvdata(pdev
, NULL
);
4383 * vxge_rem_nic - Free the PCI device
4384 * @pdev: structure containing the PCI related information of the device.
4385 * Description: This function is called by the Pci subsystem to release a
4386 * PCI device and free up all resource held up by the device.
4388 static void __devexit
4389 vxge_remove(struct pci_dev
*pdev
)
4391 struct __vxge_hw_device
*hldev
;
4392 struct vxgedev
*vdev
= NULL
;
4393 struct net_device
*dev
;
4395 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4396 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4400 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
4405 vdev
= netdev_priv(dev
);
4407 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4408 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4409 level_trace
= vdev
->level_trace
;
4411 vxge_debug_entryexit(level_trace
,
4412 "%s:%d", __func__
, __LINE__
);
4414 vxge_debug_init(level_trace
,
4415 "%s : removing PCI device...", __func__
);
4416 vxge_device_unregister(hldev
);
4418 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4419 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4420 vdev
->vpaths
[i
].mcast_addr_cnt
= 0;
4421 vdev
->vpaths
[i
].mac_addr_cnt
= 0;
4424 kfree(vdev
->vpaths
);
4426 iounmap(vdev
->bar0
);
4427 iounmap(vdev
->bar1
);
4429 /* we are safe to free it now */
4432 vxge_debug_init(level_trace
,
4433 "%s:%d Device unregistered", __func__
, __LINE__
);
4435 vxge_hw_device_terminate(hldev
);
4437 pci_disable_device(pdev
);
4438 pci_release_regions(pdev
);
4439 pci_set_drvdata(pdev
, NULL
);
4440 vxge_debug_entryexit(level_trace
,
4441 "%s:%d Exiting...", __func__
, __LINE__
);
4444 static struct pci_error_handlers vxge_err_handler
= {
4445 .error_detected
= vxge_io_error_detected
,
4446 .slot_reset
= vxge_io_slot_reset
,
4447 .resume
= vxge_io_resume
,
4450 static struct pci_driver vxge_driver
= {
4451 .name
= VXGE_DRIVER_NAME
,
4452 .id_table
= vxge_id_table
,
4453 .probe
= vxge_probe
,
4454 .remove
= __devexit_p(vxge_remove
),
4456 .suspend
= vxge_pm_suspend
,
4457 .resume
= vxge_pm_resume
,
4459 .err_handler
= &vxge_err_handler
,
4467 snprintf(version
, 32, "%s", DRV_VERSION
);
4469 printk(KERN_CRIT
"%s: Copyright(c) 2002-2009 Neterion Inc\n",
4471 printk(KERN_CRIT
"%s: Driver version: %s\n",
4472 VXGE_DRIVER_NAME
, version
);
4476 driver_config
= kzalloc(sizeof(struct vxge_drv_config
), GFP_KERNEL
);
4480 ret
= pci_register_driver(&vxge_driver
);
4482 if (driver_config
->config_dev_cnt
&&
4483 (driver_config
->config_dev_cnt
!= driver_config
->total_dev_cnt
))
4484 vxge_debug_init(VXGE_ERR
,
4485 "%s: Configured %d of %d devices",
4486 VXGE_DRIVER_NAME
, driver_config
->config_dev_cnt
,
4487 driver_config
->total_dev_cnt
);
4490 kfree(driver_config
);
4498 pci_unregister_driver(&vxge_driver
);
4499 kfree(driver_config
);
4501 module_init(vxge_starter
);
4502 module_exit(vxge_closer
);