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 Exar Corp's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2010 Exar Corp.
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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/if_vlan.h>
47 #include <linux/pci.h>
48 #include <linux/slab.h>
49 #include <linux/tcp.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include "vxge-main.h"
56 MODULE_LICENSE("Dual BSD/GPL");
57 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
58 "Virtualized Server Adapter");
60 static DEFINE_PCI_DEVICE_TABLE(vxge_id_table
) = {
61 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_WIN
, PCI_ANY_ID
,
63 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_UNI
, PCI_ANY_ID
,
68 MODULE_DEVICE_TABLE(pci
, vxge_id_table
);
70 VXGE_MODULE_PARAM_INT(vlan_tag_strip
, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
);
71 VXGE_MODULE_PARAM_INT(addr_learn_en
, VXGE_HW_MAC_ADDR_LEARN_DEFAULT
);
72 VXGE_MODULE_PARAM_INT(max_config_port
, VXGE_MAX_CONFIG_PORT
);
73 VXGE_MODULE_PARAM_INT(max_config_vpath
, VXGE_USE_DEFAULT
);
74 VXGE_MODULE_PARAM_INT(max_mac_vpath
, VXGE_MAX_MAC_ADDR_COUNT
);
75 VXGE_MODULE_PARAM_INT(max_config_dev
, VXGE_MAX_CONFIG_DEV
);
77 static u16 vpath_selector
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
78 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
79 static unsigned int bw_percentage
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
80 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS
- 1)] = 0xFF};
81 module_param_array(bw_percentage
, uint
, NULL
, 0);
83 static struct vxge_drv_config
*driver_config
;
85 static inline int is_vxge_card_up(struct vxgedev
*vdev
)
87 return test_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
90 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo
*fifo
)
92 struct sk_buff
**skb_ptr
= NULL
;
93 struct sk_buff
**temp
;
94 #define NR_SKB_COMPLETED 128
95 struct sk_buff
*completed
[NR_SKB_COMPLETED
];
102 if (__netif_tx_trylock(fifo
->txq
)) {
103 vxge_hw_vpath_poll_tx(fifo
->handle
, &skb_ptr
,
104 NR_SKB_COMPLETED
, &more
);
105 __netif_tx_unlock(fifo
->txq
);
109 for (temp
= completed
; temp
!= skb_ptr
; temp
++)
110 dev_kfree_skb_irq(*temp
);
114 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev
*vdev
)
118 /* Complete all transmits */
119 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
120 VXGE_COMPLETE_VPATH_TX(&vdev
->vpaths
[i
].fifo
);
123 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev
*vdev
)
126 struct vxge_ring
*ring
;
128 /* Complete all receives*/
129 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
130 ring
= &vdev
->vpaths
[i
].ring
;
131 vxge_hw_vpath_poll_rx(ring
->handle
);
136 * vxge_callback_link_up
138 * This function is called during interrupt context to notify link up state
142 vxge_callback_link_up(struct __vxge_hw_device
*hldev
)
144 struct net_device
*dev
= hldev
->ndev
;
145 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
147 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
148 vdev
->ndev
->name
, __func__
, __LINE__
);
149 netdev_notice(vdev
->ndev
, "Link Up\n");
150 vdev
->stats
.link_up
++;
152 netif_carrier_on(vdev
->ndev
);
153 netif_tx_wake_all_queues(vdev
->ndev
);
155 vxge_debug_entryexit(VXGE_TRACE
,
156 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
160 * vxge_callback_link_down
162 * This function is called during interrupt context to notify link down state
166 vxge_callback_link_down(struct __vxge_hw_device
*hldev
)
168 struct net_device
*dev
= hldev
->ndev
;
169 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
171 vxge_debug_entryexit(VXGE_TRACE
,
172 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
173 netdev_notice(vdev
->ndev
, "Link Down\n");
175 vdev
->stats
.link_down
++;
176 netif_carrier_off(vdev
->ndev
);
177 netif_tx_stop_all_queues(vdev
->ndev
);
179 vxge_debug_entryexit(VXGE_TRACE
,
180 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
188 static struct sk_buff
*
189 vxge_rx_alloc(void *dtrh
, struct vxge_ring
*ring
, const int skb_size
)
191 struct net_device
*dev
;
193 struct vxge_rx_priv
*rx_priv
;
196 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
197 ring
->ndev
->name
, __func__
, __LINE__
);
199 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
201 /* try to allocate skb first. this one may fail */
202 skb
= netdev_alloc_skb(dev
, skb_size
+
203 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
205 vxge_debug_mem(VXGE_ERR
,
206 "%s: out of memory to allocate SKB", dev
->name
);
207 ring
->stats
.skb_alloc_fail
++;
211 vxge_debug_mem(VXGE_TRACE
,
212 "%s: %s:%d Skb : 0x%p", ring
->ndev
->name
,
213 __func__
, __LINE__
, skb
);
215 skb_reserve(skb
, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
218 rx_priv
->skb_data
= NULL
;
219 rx_priv
->data_size
= skb_size
;
220 vxge_debug_entryexit(VXGE_TRACE
,
221 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
229 static int vxge_rx_map(void *dtrh
, struct vxge_ring
*ring
)
231 struct vxge_rx_priv
*rx_priv
;
234 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
235 ring
->ndev
->name
, __func__
, __LINE__
);
236 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
238 rx_priv
->skb_data
= rx_priv
->skb
->data
;
239 dma_addr
= pci_map_single(ring
->pdev
, rx_priv
->skb_data
,
240 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
242 if (unlikely(pci_dma_mapping_error(ring
->pdev
, dma_addr
))) {
243 ring
->stats
.pci_map_fail
++;
246 vxge_debug_mem(VXGE_TRACE
,
247 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
248 ring
->ndev
->name
, __func__
, __LINE__
,
249 (unsigned long long)dma_addr
);
250 vxge_hw_ring_rxd_1b_set(dtrh
, dma_addr
, rx_priv
->data_size
);
252 rx_priv
->data_dma
= dma_addr
;
253 vxge_debug_entryexit(VXGE_TRACE
,
254 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
260 * vxge_rx_initial_replenish
261 * Allocation of RxD as an initial replenish procedure.
263 static enum vxge_hw_status
264 vxge_rx_initial_replenish(void *dtrh
, void *userdata
)
266 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
267 struct vxge_rx_priv
*rx_priv
;
269 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
270 ring
->ndev
->name
, __func__
, __LINE__
);
271 if (vxge_rx_alloc(dtrh
, ring
,
272 VXGE_LL_MAX_FRAME_SIZE(ring
->ndev
)) == NULL
)
275 if (vxge_rx_map(dtrh
, ring
)) {
276 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
277 dev_kfree_skb(rx_priv
->skb
);
281 vxge_debug_entryexit(VXGE_TRACE
,
282 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
288 vxge_rx_complete(struct vxge_ring
*ring
, struct sk_buff
*skb
, u16 vlan
,
289 int pkt_length
, struct vxge_hw_ring_rxd_info
*ext_info
)
292 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
293 ring
->ndev
->name
, __func__
, __LINE__
);
294 skb_record_rx_queue(skb
, ring
->driver_id
);
295 skb
->protocol
= eth_type_trans(skb
, ring
->ndev
);
297 ring
->stats
.rx_frms
++;
298 ring
->stats
.rx_bytes
+= pkt_length
;
300 if (skb
->pkt_type
== PACKET_MULTICAST
)
301 ring
->stats
.rx_mcast
++;
303 vxge_debug_rx(VXGE_TRACE
,
304 "%s: %s:%d skb protocol = %d",
305 ring
->ndev
->name
, __func__
, __LINE__
, skb
->protocol
);
307 if (ring
->gro_enable
) {
308 if (ring
->vlgrp
&& ext_info
->vlan
&&
309 (ring
->vlan_tag_strip
==
310 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
))
311 vlan_gro_receive(ring
->napi_p
, ring
->vlgrp
,
312 ext_info
->vlan
, skb
);
314 napi_gro_receive(ring
->napi_p
, skb
);
316 if (ring
->vlgrp
&& vlan
&&
317 (ring
->vlan_tag_strip
==
318 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
))
319 vlan_hwaccel_receive_skb(skb
, ring
->vlgrp
, vlan
);
321 netif_receive_skb(skb
);
323 vxge_debug_entryexit(VXGE_TRACE
,
324 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
327 static inline void vxge_re_pre_post(void *dtr
, struct vxge_ring
*ring
,
328 struct vxge_rx_priv
*rx_priv
)
330 pci_dma_sync_single_for_device(ring
->pdev
,
331 rx_priv
->data_dma
, rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
333 vxge_hw_ring_rxd_1b_set(dtr
, rx_priv
->data_dma
, rx_priv
->data_size
);
334 vxge_hw_ring_rxd_pre_post(ring
->handle
, dtr
);
337 static inline void vxge_post(int *dtr_cnt
, void **first_dtr
,
338 void *post_dtr
, struct __vxge_hw_ring
*ringh
)
340 int dtr_count
= *dtr_cnt
;
341 if ((*dtr_cnt
% VXGE_HW_RXSYNC_FREQ_CNT
) == 0) {
343 vxge_hw_ring_rxd_post_post_wmb(ringh
, *first_dtr
);
344 *first_dtr
= post_dtr
;
346 vxge_hw_ring_rxd_post_post(ringh
, post_dtr
);
348 *dtr_cnt
= dtr_count
;
354 * If the interrupt is because of a received frame or if the receive ring
355 * contains fresh as yet un-processed frames, this function is called.
358 vxge_rx_1b_compl(struct __vxge_hw_ring
*ringh
, void *dtr
,
359 u8 t_code
, void *userdata
)
361 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
362 struct net_device
*dev
= ring
->ndev
;
363 unsigned int dma_sizes
;
364 void *first_dtr
= NULL
;
370 struct vxge_rx_priv
*rx_priv
;
371 struct vxge_hw_ring_rxd_info ext_info
;
372 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
373 ring
->ndev
->name
, __func__
, __LINE__
);
374 ring
->pkts_processed
= 0;
376 vxge_hw_ring_replenish(ringh
);
379 prefetch((char *)dtr
+ L1_CACHE_BYTES
);
380 rx_priv
= vxge_hw_ring_rxd_private_get(dtr
);
382 data_size
= rx_priv
->data_size
;
383 data_dma
= rx_priv
->data_dma
;
384 prefetch(rx_priv
->skb_data
);
386 vxge_debug_rx(VXGE_TRACE
,
387 "%s: %s:%d skb = 0x%p",
388 ring
->ndev
->name
, __func__
, __LINE__
, skb
);
390 vxge_hw_ring_rxd_1b_get(ringh
, dtr
, &dma_sizes
);
391 pkt_length
= dma_sizes
;
393 pkt_length
-= ETH_FCS_LEN
;
395 vxge_debug_rx(VXGE_TRACE
,
396 "%s: %s:%d Packet Length = %d",
397 ring
->ndev
->name
, __func__
, __LINE__
, pkt_length
);
399 vxge_hw_ring_rxd_1b_info_get(ringh
, dtr
, &ext_info
);
401 /* check skb validity */
404 prefetch((char *)skb
+ L1_CACHE_BYTES
);
405 if (unlikely(t_code
)) {
407 if (vxge_hw_ring_handle_tcode(ringh
, dtr
, t_code
) !=
410 ring
->stats
.rx_errors
++;
411 vxge_debug_rx(VXGE_TRACE
,
412 "%s: %s :%d Rx T_code is %d",
413 ring
->ndev
->name
, __func__
,
416 /* If the t_code is not supported and if the
417 * t_code is other than 0x5 (unparseable packet
418 * such as unknown UPV6 header), Drop it !!!
420 vxge_re_pre_post(dtr
, ring
, rx_priv
);
422 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
423 ring
->stats
.rx_dropped
++;
428 if (pkt_length
> VXGE_LL_RX_COPY_THRESHOLD
) {
430 if (vxge_rx_alloc(dtr
, ring
, data_size
) != NULL
) {
432 if (!vxge_rx_map(dtr
, ring
)) {
433 skb_put(skb
, pkt_length
);
435 pci_unmap_single(ring
->pdev
, data_dma
,
436 data_size
, PCI_DMA_FROMDEVICE
);
438 vxge_hw_ring_rxd_pre_post(ringh
, dtr
);
439 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
442 dev_kfree_skb(rx_priv
->skb
);
444 rx_priv
->data_size
= data_size
;
445 vxge_re_pre_post(dtr
, ring
, rx_priv
);
447 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
449 ring
->stats
.rx_dropped
++;
453 vxge_re_pre_post(dtr
, ring
, rx_priv
);
455 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
456 ring
->stats
.rx_dropped
++;
460 struct sk_buff
*skb_up
;
462 skb_up
= netdev_alloc_skb(dev
, pkt_length
+
463 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
464 if (skb_up
!= NULL
) {
466 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
468 pci_dma_sync_single_for_cpu(ring
->pdev
,
472 vxge_debug_mem(VXGE_TRACE
,
473 "%s: %s:%d skb_up = %p",
474 ring
->ndev
->name
, __func__
,
476 memcpy(skb_up
->data
, skb
->data
, pkt_length
);
478 vxge_re_pre_post(dtr
, ring
, rx_priv
);
480 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
482 /* will netif_rx small SKB instead */
484 skb_put(skb
, pkt_length
);
486 vxge_re_pre_post(dtr
, ring
, rx_priv
);
488 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
489 vxge_debug_rx(VXGE_ERR
,
490 "%s: vxge_rx_1b_compl: out of "
491 "memory", dev
->name
);
492 ring
->stats
.skb_alloc_fail
++;
497 if ((ext_info
.proto
& VXGE_HW_FRAME_PROTO_TCP_OR_UDP
) &&
498 !(ext_info
.proto
& VXGE_HW_FRAME_PROTO_IP_FRAG
) &&
499 ring
->rx_csum
&& /* Offload Rx side CSUM */
500 ext_info
.l3_cksum
== VXGE_HW_L3_CKSUM_OK
&&
501 ext_info
.l4_cksum
== VXGE_HW_L4_CKSUM_OK
)
502 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
504 skb
->ip_summed
= CHECKSUM_NONE
;
506 vxge_rx_complete(ring
, skb
, ext_info
.vlan
,
507 pkt_length
, &ext_info
);
510 ring
->pkts_processed
++;
514 } while (vxge_hw_ring_rxd_next_completed(ringh
, &dtr
,
515 &t_code
) == VXGE_HW_OK
);
518 vxge_hw_ring_rxd_post_post_wmb(ringh
, first_dtr
);
520 vxge_debug_entryexit(VXGE_TRACE
,
529 * If an interrupt was raised to indicate DMA complete of the Tx packet,
530 * this function is called. It identifies the last TxD whose buffer was
531 * freed and frees all skbs whose data have already DMA'ed into the NICs
535 vxge_xmit_compl(struct __vxge_hw_fifo
*fifo_hw
, void *dtr
,
536 enum vxge_hw_fifo_tcode t_code
, void *userdata
,
537 struct sk_buff
***skb_ptr
, int nr_skb
, int *more
)
539 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
540 struct sk_buff
*skb
, **done_skb
= *skb_ptr
;
543 vxge_debug_entryexit(VXGE_TRACE
,
544 "%s:%d Entered....", __func__
, __LINE__
);
550 struct vxge_tx_priv
*txd_priv
=
551 vxge_hw_fifo_txdl_private_get(dtr
);
554 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
555 frag
= &skb_shinfo(skb
)->frags
[0];
557 vxge_debug_tx(VXGE_TRACE
,
558 "%s: %s:%d fifo_hw = %p dtr = %p "
559 "tcode = 0x%x", fifo
->ndev
->name
, __func__
,
560 __LINE__
, fifo_hw
, dtr
, t_code
);
561 /* check skb validity */
563 vxge_debug_tx(VXGE_TRACE
,
564 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
565 fifo
->ndev
->name
, __func__
, __LINE__
,
566 skb
, txd_priv
, frg_cnt
);
567 if (unlikely(t_code
)) {
568 fifo
->stats
.tx_errors
++;
569 vxge_debug_tx(VXGE_ERR
,
570 "%s: tx: dtr %p completed due to "
571 "error t_code %01x", fifo
->ndev
->name
,
573 vxge_hw_fifo_handle_tcode(fifo_hw
, dtr
, t_code
);
576 /* for unfragmented skb */
577 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
578 skb_headlen(skb
), PCI_DMA_TODEVICE
);
580 for (j
= 0; j
< frg_cnt
; j
++) {
581 pci_unmap_page(fifo
->pdev
,
582 txd_priv
->dma_buffers
[i
++],
583 frag
->size
, PCI_DMA_TODEVICE
);
587 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
589 /* Updating the statistics block */
590 fifo
->stats
.tx_frms
++;
591 fifo
->stats
.tx_bytes
+= skb
->len
;
601 if (pkt_cnt
> fifo
->indicate_max_pkts
)
604 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw
,
605 &dtr
, &t_code
) == VXGE_HW_OK
);
608 if (netif_tx_queue_stopped(fifo
->txq
))
609 netif_tx_wake_queue(fifo
->txq
);
611 vxge_debug_entryexit(VXGE_TRACE
,
612 "%s: %s:%d Exiting...",
613 fifo
->ndev
->name
, __func__
, __LINE__
);
617 /* select a vpath to transmit the packet */
618 static u32
vxge_get_vpath_no(struct vxgedev
*vdev
, struct sk_buff
*skb
)
620 u16 queue_len
, counter
= 0;
621 if (skb
->protocol
== htons(ETH_P_IP
)) {
627 if ((ip
->frag_off
& htons(IP_OFFSET
|IP_MF
)) == 0) {
628 th
= (struct tcphdr
*)(((unsigned char *)ip
) +
631 queue_len
= vdev
->no_of_vpath
;
632 counter
= (ntohs(th
->source
) +
634 vdev
->vpath_selector
[queue_len
- 1];
635 if (counter
>= queue_len
)
636 counter
= queue_len
- 1;
642 static enum vxge_hw_status
vxge_search_mac_addr_in_list(
643 struct vxge_vpath
*vpath
, u64 del_mac
)
645 struct list_head
*entry
, *next
;
646 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
647 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
)
653 static int vxge_learn_mac(struct vxgedev
*vdev
, u8
*mac_header
)
655 struct macInfo mac_info
;
656 u8
*mac_address
= NULL
;
657 u64 mac_addr
= 0, vpath_vector
= 0;
659 enum vxge_hw_status status
= VXGE_HW_OK
;
660 struct vxge_vpath
*vpath
= NULL
;
661 struct __vxge_hw_device
*hldev
;
663 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
665 mac_address
= (u8
*)&mac_addr
;
666 memcpy(mac_address
, mac_header
, ETH_ALEN
);
668 /* Is this mac address already in the list? */
669 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
670 vpath
= &vdev
->vpaths
[vpath_idx
];
671 if (vxge_search_mac_addr_in_list(vpath
, mac_addr
))
675 memset(&mac_info
, 0, sizeof(struct macInfo
));
676 memcpy(mac_info
.macaddr
, mac_header
, ETH_ALEN
);
678 /* Any vpath has room to add mac address to its da table? */
679 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
680 vpath
= &vdev
->vpaths
[vpath_idx
];
681 if (vpath
->mac_addr_cnt
< vpath
->max_mac_addr_cnt
) {
682 /* Add this mac address to this vpath */
683 mac_info
.vpath_no
= vpath_idx
;
684 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
685 status
= vxge_add_mac_addr(vdev
, &mac_info
);
686 if (status
!= VXGE_HW_OK
)
692 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_LIST
;
694 mac_info
.vpath_no
= vpath_idx
;
695 /* Is the first vpath already selected as catch-basin ? */
696 vpath
= &vdev
->vpaths
[vpath_idx
];
697 if (vpath
->mac_addr_cnt
> vpath
->max_mac_addr_cnt
) {
698 /* Add this mac address to this vpath */
699 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
704 /* Select first vpath as catch-basin */
705 vpath_vector
= vxge_mBIT(vpath
->device_id
);
706 status
= vxge_hw_mgmt_reg_write(vpath
->vdev
->devh
,
707 vxge_hw_mgmt_reg_type_mrpcim
,
710 struct vxge_hw_mrpcim_reg
,
713 if (status
!= VXGE_HW_OK
) {
714 vxge_debug_tx(VXGE_ERR
,
715 "%s: Unable to set the vpath-%d in catch-basin mode",
716 VXGE_DRIVER_NAME
, vpath
->device_id
);
720 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
728 * @skb : the socket buffer containing the Tx data.
729 * @dev : device pointer.
731 * This function is the Tx entry point of the driver. Neterion NIC supports
732 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
735 vxge_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
737 struct vxge_fifo
*fifo
= NULL
;
740 struct vxgedev
*vdev
= NULL
;
741 enum vxge_hw_status status
;
742 int frg_cnt
, first_frg_len
;
744 int i
= 0, j
= 0, avail
;
746 struct vxge_tx_priv
*txdl_priv
= NULL
;
747 struct __vxge_hw_fifo
*fifo_hw
;
751 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
752 dev
->name
, __func__
, __LINE__
);
754 /* A buffer with no data will be dropped */
755 if (unlikely(skb
->len
<= 0)) {
756 vxge_debug_tx(VXGE_ERR
,
757 "%s: Buffer has no data..", dev
->name
);
762 vdev
= (struct vxgedev
*)netdev_priv(dev
);
764 if (unlikely(!is_vxge_card_up(vdev
))) {
765 vxge_debug_tx(VXGE_ERR
,
766 "%s: vdev not initialized", dev
->name
);
771 if (vdev
->config
.addr_learn_en
) {
772 vpath_no
= vxge_learn_mac(vdev
, skb
->data
+ ETH_ALEN
);
773 if (vpath_no
== -EPERM
) {
774 vxge_debug_tx(VXGE_ERR
,
775 "%s: Failed to store the mac address",
782 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
)
783 vpath_no
= skb_get_queue_mapping(skb
);
784 else if (vdev
->config
.tx_steering_type
== TX_PORT_STEERING
)
785 vpath_no
= vxge_get_vpath_no(vdev
, skb
);
787 vxge_debug_tx(VXGE_TRACE
, "%s: vpath_no= %d", dev
->name
, vpath_no
);
789 if (vpath_no
>= vdev
->no_of_vpath
)
792 fifo
= &vdev
->vpaths
[vpath_no
].fifo
;
793 fifo_hw
= fifo
->handle
;
795 if (netif_tx_queue_stopped(fifo
->txq
))
796 return NETDEV_TX_BUSY
;
798 avail
= vxge_hw_fifo_free_txdl_count_get(fifo_hw
);
800 vxge_debug_tx(VXGE_ERR
,
801 "%s: No free TXDs available", dev
->name
);
802 fifo
->stats
.txd_not_free
++;
806 /* Last TXD? Stop tx queue to avoid dropping packets. TX
807 * completion will resume the queue.
810 netif_tx_stop_queue(fifo
->txq
);
812 status
= vxge_hw_fifo_txdl_reserve(fifo_hw
, &dtr
, &dtr_priv
);
813 if (unlikely(status
!= VXGE_HW_OK
)) {
814 vxge_debug_tx(VXGE_ERR
,
815 "%s: Out of descriptors .", dev
->name
);
816 fifo
->stats
.txd_out_of_desc
++;
820 vxge_debug_tx(VXGE_TRACE
,
821 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
822 dev
->name
, __func__
, __LINE__
,
823 fifo_hw
, dtr
, dtr_priv
);
825 if (vdev
->vlgrp
&& vlan_tx_tag_present(skb
)) {
826 u16 vlan_tag
= vlan_tx_tag_get(skb
);
827 vxge_hw_fifo_txdl_vlan_set(dtr
, vlan_tag
);
830 first_frg_len
= skb_headlen(skb
);
832 dma_pointer
= pci_map_single(fifo
->pdev
, skb
->data
, first_frg_len
,
835 if (unlikely(pci_dma_mapping_error(fifo
->pdev
, dma_pointer
))) {
836 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
837 fifo
->stats
.pci_map_fail
++;
841 txdl_priv
= vxge_hw_fifo_txdl_private_get(dtr
);
842 txdl_priv
->skb
= skb
;
843 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
845 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
846 vxge_debug_tx(VXGE_TRACE
,
847 "%s: %s:%d skb = %p txdl_priv = %p "
848 "frag_cnt = %d dma_pointer = 0x%llx", dev
->name
,
849 __func__
, __LINE__
, skb
, txdl_priv
,
850 frg_cnt
, (unsigned long long)dma_pointer
);
852 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
855 frag
= &skb_shinfo(skb
)->frags
[0];
856 for (i
= 0; i
< frg_cnt
; i
++) {
857 /* ignore 0 length fragment */
861 dma_pointer
= (u64
) pci_map_page(fifo
->pdev
, frag
->page
,
862 frag
->page_offset
, frag
->size
,
865 if (unlikely(pci_dma_mapping_error(fifo
->pdev
, dma_pointer
)))
867 vxge_debug_tx(VXGE_TRACE
,
868 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
869 dev
->name
, __func__
, __LINE__
, i
,
870 (unsigned long long)dma_pointer
);
872 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
873 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
878 offload_type
= vxge_offload_type(skb
);
880 if (offload_type
& (SKB_GSO_TCPV4
| SKB_GSO_TCPV6
)) {
881 int mss
= vxge_tcp_mss(skb
);
883 vxge_debug_tx(VXGE_TRACE
, "%s: %s:%d mss = %d",
884 dev
->name
, __func__
, __LINE__
, mss
);
885 vxge_hw_fifo_txdl_mss_set(dtr
, mss
);
887 vxge_assert(skb
->len
<=
888 dev
->mtu
+ VXGE_HW_MAC_HEADER_MAX_SIZE
);
894 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
895 vxge_hw_fifo_txdl_cksum_set_bits(dtr
,
896 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN
|
897 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN
|
898 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN
);
900 vxge_hw_fifo_txdl_post(fifo_hw
, dtr
);
902 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
903 dev
->name
, __func__
, __LINE__
);
907 vxge_debug_tx(VXGE_TRACE
, "%s: pci_map_page failed", dev
->name
);
910 frag
= &skb_shinfo(skb
)->frags
[0];
912 pci_unmap_single(fifo
->pdev
, txdl_priv
->dma_buffers
[j
++],
913 skb_headlen(skb
), PCI_DMA_TODEVICE
);
916 pci_unmap_page(fifo
->pdev
, txdl_priv
->dma_buffers
[j
],
917 frag
->size
, PCI_DMA_TODEVICE
);
921 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
923 netif_tx_stop_queue(fifo
->txq
);
932 * Function will be called by hw function to abort all outstanding receive
936 vxge_rx_term(void *dtrh
, enum vxge_hw_rxd_state state
, void *userdata
)
938 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
939 struct vxge_rx_priv
*rx_priv
=
940 vxge_hw_ring_rxd_private_get(dtrh
);
942 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
943 ring
->ndev
->name
, __func__
, __LINE__
);
944 if (state
!= VXGE_HW_RXD_STATE_POSTED
)
947 pci_unmap_single(ring
->pdev
, rx_priv
->data_dma
,
948 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
950 dev_kfree_skb(rx_priv
->skb
);
951 rx_priv
->skb_data
= NULL
;
953 vxge_debug_entryexit(VXGE_TRACE
,
954 "%s: %s:%d Exiting...",
955 ring
->ndev
->name
, __func__
, __LINE__
);
961 * Function will be called to abort all outstanding tx descriptors
964 vxge_tx_term(void *dtrh
, enum vxge_hw_txdl_state state
, void *userdata
)
966 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
968 int i
= 0, j
, frg_cnt
;
969 struct vxge_tx_priv
*txd_priv
= vxge_hw_fifo_txdl_private_get(dtrh
);
970 struct sk_buff
*skb
= txd_priv
->skb
;
972 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
974 if (state
!= VXGE_HW_TXDL_STATE_POSTED
)
977 /* check skb validity */
979 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
980 frag
= &skb_shinfo(skb
)->frags
[0];
982 /* for unfragmented skb */
983 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
984 skb_headlen(skb
), PCI_DMA_TODEVICE
);
986 for (j
= 0; j
< frg_cnt
; j
++) {
987 pci_unmap_page(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
988 frag
->size
, PCI_DMA_TODEVICE
);
994 vxge_debug_entryexit(VXGE_TRACE
,
995 "%s:%d Exiting...", __func__
, __LINE__
);
1000 * @dev: pointer to the device structure
1002 * Entry point for multicast address enable/disable
1003 * This function is a driver entry point which gets called by the kernel
1004 * whenever multicast addresses must be enabled/disabled. This also gets
1005 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1006 * determine, if multicast address must be enabled or if promiscuous mode
1007 * is to be disabled etc.
1009 static void vxge_set_multicast(struct net_device
*dev
)
1011 struct netdev_hw_addr
*ha
;
1012 struct vxgedev
*vdev
;
1013 int i
, mcast_cnt
= 0;
1014 struct __vxge_hw_device
*hldev
;
1015 struct vxge_vpath
*vpath
;
1016 enum vxge_hw_status status
= VXGE_HW_OK
;
1017 struct macInfo mac_info
;
1019 struct vxge_mac_addrs
*mac_entry
;
1020 struct list_head
*list_head
;
1021 struct list_head
*entry
, *next
;
1022 u8
*mac_address
= NULL
;
1024 vxge_debug_entryexit(VXGE_TRACE
,
1025 "%s:%d", __func__
, __LINE__
);
1027 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1028 hldev
= (struct __vxge_hw_device
*)vdev
->devh
;
1030 if (unlikely(!is_vxge_card_up(vdev
)))
1033 if ((dev
->flags
& IFF_ALLMULTI
) && (!vdev
->all_multi_flg
)) {
1034 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1035 vpath
= &vdev
->vpaths
[i
];
1036 vxge_assert(vpath
->is_open
);
1037 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
1038 if (status
!= VXGE_HW_OK
)
1039 vxge_debug_init(VXGE_ERR
, "failed to enable "
1040 "multicast, status %d", status
);
1041 vdev
->all_multi_flg
= 1;
1043 } else if (!(dev
->flags
& IFF_ALLMULTI
) && (vdev
->all_multi_flg
)) {
1044 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1045 vpath
= &vdev
->vpaths
[i
];
1046 vxge_assert(vpath
->is_open
);
1047 status
= vxge_hw_vpath_mcast_disable(vpath
->handle
);
1048 if (status
!= VXGE_HW_OK
)
1049 vxge_debug_init(VXGE_ERR
, "failed to disable "
1050 "multicast, status %d", status
);
1051 vdev
->all_multi_flg
= 0;
1056 if (!vdev
->config
.addr_learn_en
) {
1057 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1058 vpath
= &vdev
->vpaths
[i
];
1059 vxge_assert(vpath
->is_open
);
1061 if (dev
->flags
& IFF_PROMISC
)
1062 status
= vxge_hw_vpath_promisc_enable(
1065 status
= vxge_hw_vpath_promisc_disable(
1067 if (status
!= VXGE_HW_OK
)
1068 vxge_debug_init(VXGE_ERR
, "failed to %s promisc"
1069 ", status %d", dev
->flags
&IFF_PROMISC
?
1070 "enable" : "disable", status
);
1074 memset(&mac_info
, 0, sizeof(struct macInfo
));
1075 /* Update individual M_CAST address list */
1076 if ((!vdev
->all_multi_flg
) && netdev_mc_count(dev
)) {
1077 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1078 list_head
= &vdev
->vpaths
[0].mac_addr_list
;
1079 if ((netdev_mc_count(dev
) +
1080 (vdev
->vpaths
[0].mac_addr_cnt
- mcast_cnt
)) >
1081 vdev
->vpaths
[0].max_mac_addr_cnt
)
1082 goto _set_all_mcast
;
1084 /* Delete previous MC's */
1085 for (i
= 0; i
< mcast_cnt
; i
++) {
1086 list_for_each_safe(entry
, next
, list_head
) {
1087 mac_entry
= (struct vxge_mac_addrs
*) entry
;
1088 /* Copy the mac address to delete */
1089 mac_address
= (u8
*)&mac_entry
->macaddr
;
1090 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1092 /* Is this a multicast address */
1093 if (0x01 & mac_info
.macaddr
[0]) {
1094 for (vpath_idx
= 0; vpath_idx
<
1097 mac_info
.vpath_no
= vpath_idx
;
1098 status
= vxge_del_mac_addr(
1107 netdev_for_each_mc_addr(ha
, dev
) {
1108 memcpy(mac_info
.macaddr
, ha
->addr
, ETH_ALEN
);
1109 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1111 mac_info
.vpath_no
= vpath_idx
;
1112 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1113 status
= vxge_add_mac_addr(vdev
, &mac_info
);
1114 if (status
!= VXGE_HW_OK
) {
1115 vxge_debug_init(VXGE_ERR
,
1116 "%s:%d Setting individual"
1117 "multicast address failed",
1118 __func__
, __LINE__
);
1119 goto _set_all_mcast
;
1126 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1127 /* Delete previous MC's */
1128 for (i
= 0; i
< mcast_cnt
; i
++) {
1129 list_for_each_safe(entry
, next
, list_head
) {
1130 mac_entry
= (struct vxge_mac_addrs
*) entry
;
1131 /* Copy the mac address to delete */
1132 mac_address
= (u8
*)&mac_entry
->macaddr
;
1133 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1135 /* Is this a multicast address */
1136 if (0x01 & mac_info
.macaddr
[0])
1140 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1142 mac_info
.vpath_no
= vpath_idx
;
1143 status
= vxge_del_mac_addr(vdev
, &mac_info
);
1147 /* Enable all multicast */
1148 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1149 vpath
= &vdev
->vpaths
[i
];
1150 vxge_assert(vpath
->is_open
);
1152 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
1153 if (status
!= VXGE_HW_OK
) {
1154 vxge_debug_init(VXGE_ERR
,
1155 "%s:%d Enabling all multicasts failed",
1156 __func__
, __LINE__
);
1158 vdev
->all_multi_flg
= 1;
1160 dev
->flags
|= IFF_ALLMULTI
;
1163 vxge_debug_entryexit(VXGE_TRACE
,
1164 "%s:%d Exiting...", __func__
, __LINE__
);
1169 * @dev: pointer to the device structure
1171 * Update entry "0" (default MAC addr)
1173 static int vxge_set_mac_addr(struct net_device
*dev
, void *p
)
1175 struct sockaddr
*addr
= p
;
1176 struct vxgedev
*vdev
;
1177 struct __vxge_hw_device
*hldev
;
1178 enum vxge_hw_status status
= VXGE_HW_OK
;
1179 struct macInfo mac_info_new
, mac_info_old
;
1182 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1184 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1187 if (!is_valid_ether_addr(addr
->sa_data
))
1190 memset(&mac_info_new
, 0, sizeof(struct macInfo
));
1191 memset(&mac_info_old
, 0, sizeof(struct macInfo
));
1193 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d Exiting...",
1194 __func__
, __LINE__
);
1196 /* Get the old address */
1197 memcpy(mac_info_old
.macaddr
, dev
->dev_addr
, dev
->addr_len
);
1199 /* Copy the new address */
1200 memcpy(mac_info_new
.macaddr
, addr
->sa_data
, dev
->addr_len
);
1202 /* First delete the old mac address from all the vpaths
1203 as we can't specify the index while adding new mac address */
1204 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1205 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vpath_idx
];
1206 if (!vpath
->is_open
) {
1207 /* This can happen when this interface is added/removed
1208 to the bonding interface. Delete this station address
1209 from the linked list */
1210 vxge_mac_list_del(vpath
, &mac_info_old
);
1212 /* Add this new address to the linked list
1213 for later restoring */
1214 vxge_mac_list_add(vpath
, &mac_info_new
);
1218 /* Delete the station address */
1219 mac_info_old
.vpath_no
= vpath_idx
;
1220 status
= vxge_del_mac_addr(vdev
, &mac_info_old
);
1223 if (unlikely(!is_vxge_card_up(vdev
))) {
1224 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1228 /* Set this mac address to all the vpaths */
1229 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1230 mac_info_new
.vpath_no
= vpath_idx
;
1231 mac_info_new
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1232 status
= vxge_add_mac_addr(vdev
, &mac_info_new
);
1233 if (status
!= VXGE_HW_OK
)
1237 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1243 * vxge_vpath_intr_enable
1244 * @vdev: pointer to vdev
1245 * @vp_id: vpath for which to enable the interrupts
1247 * Enables the interrupts for the vpath
1249 void vxge_vpath_intr_enable(struct vxgedev
*vdev
, int vp_id
)
1251 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1253 int tim_msix_id
[4] = {0, 1, 0, 0};
1254 int alarm_msix_id
= VXGE_ALARM_MSIX_ID
;
1256 vxge_hw_vpath_intr_enable(vpath
->handle
);
1258 if (vdev
->config
.intr_type
== INTA
)
1259 vxge_hw_vpath_inta_unmask_tx_rx(vpath
->handle
);
1261 vxge_hw_vpath_msix_set(vpath
->handle
, tim_msix_id
,
1264 msix_id
= vpath
->device_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1265 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
);
1266 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
+ 1);
1268 /* enable the alarm vector */
1269 msix_id
= (vpath
->handle
->vpath
->hldev
->first_vp_id
*
1270 VXGE_HW_VPATH_MSIX_ACTIVE
) + alarm_msix_id
;
1271 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
);
1276 * vxge_vpath_intr_disable
1277 * @vdev: pointer to vdev
1278 * @vp_id: vpath for which to disable the interrupts
1280 * Disables the interrupts for the vpath
1282 void vxge_vpath_intr_disable(struct vxgedev
*vdev
, int vp_id
)
1284 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1287 vxge_hw_vpath_intr_disable(vpath
->handle
);
1289 if (vdev
->config
.intr_type
== INTA
)
1290 vxge_hw_vpath_inta_mask_tx_rx(vpath
->handle
);
1292 msix_id
= vpath
->device_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1293 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1294 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
+ 1);
1296 /* disable the alarm vector */
1297 msix_id
= (vpath
->handle
->vpath
->hldev
->first_vp_id
*
1298 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
1299 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1305 * @vdev: pointer to vdev
1306 * @vp_id: vpath to reset
1310 static int vxge_reset_vpath(struct vxgedev
*vdev
, int vp_id
)
1312 enum vxge_hw_status status
= VXGE_HW_OK
;
1313 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1316 /* check if device is down already */
1317 if (unlikely(!is_vxge_card_up(vdev
)))
1320 /* is device reset already scheduled */
1321 if (test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1324 if (vpath
->handle
) {
1325 if (vxge_hw_vpath_reset(vpath
->handle
) == VXGE_HW_OK
) {
1326 if (is_vxge_card_up(vdev
) &&
1327 vxge_hw_vpath_recover_from_reset(vpath
->handle
)
1329 vxge_debug_init(VXGE_ERR
,
1330 "vxge_hw_vpath_recover_from_reset"
1331 "failed for vpath:%d", vp_id
);
1335 vxge_debug_init(VXGE_ERR
,
1336 "vxge_hw_vpath_reset failed for"
1341 return VXGE_HW_FAIL
;
1343 vxge_restore_vpath_mac_addr(vpath
);
1344 vxge_restore_vpath_vid_table(vpath
);
1346 /* Enable all broadcast */
1347 vxge_hw_vpath_bcast_enable(vpath
->handle
);
1349 /* Enable all multicast */
1350 if (vdev
->all_multi_flg
) {
1351 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
1352 if (status
!= VXGE_HW_OK
)
1353 vxge_debug_init(VXGE_ERR
,
1354 "%s:%d Enabling multicast failed",
1355 __func__
, __LINE__
);
1358 /* Enable the interrupts */
1359 vxge_vpath_intr_enable(vdev
, vp_id
);
1363 /* Enable the flow of traffic through the vpath */
1364 vxge_hw_vpath_enable(vpath
->handle
);
1367 vxge_hw_vpath_rx_doorbell_init(vpath
->handle
);
1368 vpath
->ring
.last_status
= VXGE_HW_OK
;
1370 /* Vpath reset done */
1371 clear_bit(vp_id
, &vdev
->vp_reset
);
1373 /* Start the vpath queue */
1374 if (netif_tx_queue_stopped(vpath
->fifo
.txq
))
1375 netif_tx_wake_queue(vpath
->fifo
.txq
);
1380 static int do_vxge_reset(struct vxgedev
*vdev
, int event
)
1382 enum vxge_hw_status status
;
1383 int ret
= 0, vp_id
, i
;
1385 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1387 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
)) {
1388 /* check if device is down already */
1389 if (unlikely(!is_vxge_card_up(vdev
)))
1392 /* is reset already scheduled */
1393 if (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1397 if (event
== VXGE_LL_FULL_RESET
) {
1398 /* wait for all the vpath reset to complete */
1399 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1400 while (test_bit(vp_id
, &vdev
->vp_reset
))
1404 /* if execution mode is set to debug, don't reset the adapter */
1405 if (unlikely(vdev
->exec_mode
)) {
1406 vxge_debug_init(VXGE_ERR
,
1407 "%s: execution mode is debug, returning..",
1409 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1410 netif_tx_stop_all_queues(vdev
->ndev
);
1415 if (event
== VXGE_LL_FULL_RESET
) {
1416 vxge_hw_device_intr_disable(vdev
->devh
);
1418 switch (vdev
->cric_err_event
) {
1419 case VXGE_HW_EVENT_UNKNOWN
:
1420 netif_tx_stop_all_queues(vdev
->ndev
);
1421 vxge_debug_init(VXGE_ERR
,
1422 "fatal: %s: Disabling device due to"
1427 case VXGE_HW_EVENT_RESET_START
:
1429 case VXGE_HW_EVENT_RESET_COMPLETE
:
1430 case VXGE_HW_EVENT_LINK_DOWN
:
1431 case VXGE_HW_EVENT_LINK_UP
:
1432 case VXGE_HW_EVENT_ALARM_CLEARED
:
1433 case VXGE_HW_EVENT_ECCERR
:
1434 case VXGE_HW_EVENT_MRPCIM_ECCERR
:
1437 case VXGE_HW_EVENT_FIFO_ERR
:
1438 case VXGE_HW_EVENT_VPATH_ERR
:
1440 case VXGE_HW_EVENT_CRITICAL_ERR
:
1441 netif_tx_stop_all_queues(vdev
->ndev
);
1442 vxge_debug_init(VXGE_ERR
,
1443 "fatal: %s: Disabling device due to"
1446 /* SOP or device reset required */
1447 /* This event is not currently used */
1450 case VXGE_HW_EVENT_SERR
:
1451 netif_tx_stop_all_queues(vdev
->ndev
);
1452 vxge_debug_init(VXGE_ERR
,
1453 "fatal: %s: Disabling device due to"
1458 case VXGE_HW_EVENT_SRPCIM_SERR
:
1459 case VXGE_HW_EVENT_MRPCIM_SERR
:
1462 case VXGE_HW_EVENT_SLOT_FREEZE
:
1463 netif_tx_stop_all_queues(vdev
->ndev
);
1464 vxge_debug_init(VXGE_ERR
,
1465 "fatal: %s: Disabling device due to"
1476 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
))
1477 netif_tx_stop_all_queues(vdev
->ndev
);
1479 if (event
== VXGE_LL_FULL_RESET
) {
1480 status
= vxge_reset_all_vpaths(vdev
);
1481 if (status
!= VXGE_HW_OK
) {
1482 vxge_debug_init(VXGE_ERR
,
1483 "fatal: %s: can not reset vpaths",
1490 if (event
== VXGE_LL_COMPL_RESET
) {
1491 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1492 if (vdev
->vpaths
[i
].handle
) {
1493 if (vxge_hw_vpath_recover_from_reset(
1494 vdev
->vpaths
[i
].handle
)
1496 vxge_debug_init(VXGE_ERR
,
1497 "vxge_hw_vpath_recover_"
1498 "from_reset failed for vpath: "
1504 vxge_debug_init(VXGE_ERR
,
1505 "vxge_hw_vpath_reset failed for "
1512 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
)) {
1513 /* Reprogram the DA table with populated mac addresses */
1514 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1515 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[vp_id
]);
1516 vxge_restore_vpath_vid_table(&vdev
->vpaths
[vp_id
]);
1519 /* enable vpath interrupts */
1520 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1521 vxge_vpath_intr_enable(vdev
, i
);
1523 vxge_hw_device_intr_enable(vdev
->devh
);
1527 /* Indicate card up */
1528 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1530 /* Get the traffic to flow through the vpaths */
1531 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1532 vxge_hw_vpath_enable(vdev
->vpaths
[i
].handle
);
1534 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[i
].handle
);
1537 netif_tx_wake_all_queues(vdev
->ndev
);
1541 vxge_debug_entryexit(VXGE_TRACE
,
1542 "%s:%d Exiting...", __func__
, __LINE__
);
1544 /* Indicate reset done */
1545 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
))
1546 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
1552 * @vdev: pointer to ll device
1554 * driver may reset the chip on events of serr, eccerr, etc
1556 int vxge_reset(struct vxgedev
*vdev
)
1558 return do_vxge_reset(vdev
, VXGE_LL_FULL_RESET
);
1562 * vxge_poll - Receive handler when Receive Polling is used.
1563 * @dev: pointer to the device structure.
1564 * @budget: Number of packets budgeted to be processed in this iteration.
1566 * This function comes into picture only if Receive side is being handled
1567 * through polling (called NAPI in linux). It mostly does what the normal
1568 * Rx interrupt handler does in terms of descriptor and packet processing
1569 * but not in an interrupt context. Also it will process a specified number
1570 * of packets at most in one iteration. This value is passed down by the
1571 * kernel as the function argument 'budget'.
1573 static int vxge_poll_msix(struct napi_struct
*napi
, int budget
)
1575 struct vxge_ring
*ring
=
1576 container_of(napi
, struct vxge_ring
, napi
);
1577 int budget_org
= budget
;
1578 ring
->budget
= budget
;
1580 vxge_hw_vpath_poll_rx(ring
->handle
);
1582 if (ring
->pkts_processed
< budget_org
) {
1583 napi_complete(napi
);
1584 /* Re enable the Rx interrupts for the vpath */
1585 vxge_hw_channel_msix_unmask(
1586 (struct __vxge_hw_channel
*)ring
->handle
,
1587 ring
->rx_vector_no
);
1590 return ring
->pkts_processed
;
1593 static int vxge_poll_inta(struct napi_struct
*napi
, int budget
)
1595 struct vxgedev
*vdev
= container_of(napi
, struct vxgedev
, napi
);
1596 int pkts_processed
= 0;
1598 int budget_org
= budget
;
1599 struct vxge_ring
*ring
;
1601 struct __vxge_hw_device
*hldev
= (struct __vxge_hw_device
*)
1602 pci_get_drvdata(vdev
->pdev
);
1604 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1605 ring
= &vdev
->vpaths
[i
].ring
;
1606 ring
->budget
= budget
;
1607 vxge_hw_vpath_poll_rx(ring
->handle
);
1608 pkts_processed
+= ring
->pkts_processed
;
1609 budget
-= ring
->pkts_processed
;
1614 VXGE_COMPLETE_ALL_TX(vdev
);
1616 if (pkts_processed
< budget_org
) {
1617 napi_complete(napi
);
1618 /* Re enable the Rx interrupts for the ring */
1619 vxge_hw_device_unmask_all(hldev
);
1620 vxge_hw_device_flush_io(hldev
);
1623 return pkts_processed
;
1626 #ifdef CONFIG_NET_POLL_CONTROLLER
1628 * vxge_netpoll - netpoll event handler entry point
1629 * @dev : pointer to the device structure.
1631 * This function will be called by upper layer to check for events on the
1632 * interface in situations where interrupts are disabled. It is used for
1633 * specific in-kernel networking tasks, such as remote consoles and kernel
1634 * debugging over the network (example netdump in RedHat).
1636 static void vxge_netpoll(struct net_device
*dev
)
1638 struct __vxge_hw_device
*hldev
;
1639 struct vxgedev
*vdev
;
1641 vdev
= (struct vxgedev
*)netdev_priv(dev
);
1642 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
1644 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1646 if (pci_channel_offline(vdev
->pdev
))
1649 disable_irq(dev
->irq
);
1650 vxge_hw_device_clear_tx_rx(hldev
);
1652 vxge_hw_device_clear_tx_rx(hldev
);
1653 VXGE_COMPLETE_ALL_RX(vdev
);
1654 VXGE_COMPLETE_ALL_TX(vdev
);
1656 enable_irq(dev
->irq
);
1658 vxge_debug_entryexit(VXGE_TRACE
,
1659 "%s:%d Exiting...", __func__
, __LINE__
);
1663 /* RTH configuration */
1664 static enum vxge_hw_status
vxge_rth_configure(struct vxgedev
*vdev
)
1666 enum vxge_hw_status status
= VXGE_HW_OK
;
1667 struct vxge_hw_rth_hash_types hash_types
;
1668 u8 itable
[256] = {0}; /* indirection table */
1669 u8 mtable
[256] = {0}; /* CPU to vpath mapping */
1674 * - itable with bucket numbers
1675 * - mtable with bucket-to-vpath mapping
1677 for (index
= 0; index
< (1 << vdev
->config
.rth_bkt_sz
); index
++) {
1678 itable
[index
] = index
;
1679 mtable
[index
] = index
% vdev
->no_of_vpath
;
1682 /* Fill RTH hash types */
1683 hash_types
.hash_type_tcpipv4_en
= vdev
->config
.rth_hash_type_tcpipv4
;
1684 hash_types
.hash_type_ipv4_en
= vdev
->config
.rth_hash_type_ipv4
;
1685 hash_types
.hash_type_tcpipv6_en
= vdev
->config
.rth_hash_type_tcpipv6
;
1686 hash_types
.hash_type_ipv6_en
= vdev
->config
.rth_hash_type_ipv6
;
1687 hash_types
.hash_type_tcpipv6ex_en
=
1688 vdev
->config
.rth_hash_type_tcpipv6ex
;
1689 hash_types
.hash_type_ipv6ex_en
= vdev
->config
.rth_hash_type_ipv6ex
;
1691 /* set indirection table, bucket-to-vpath mapping */
1692 status
= vxge_hw_vpath_rts_rth_itable_set(vdev
->vp_handles
,
1695 vdev
->config
.rth_bkt_sz
);
1696 if (status
!= VXGE_HW_OK
) {
1697 vxge_debug_init(VXGE_ERR
,
1698 "RTH indirection table configuration failed "
1699 "for vpath:%d", vdev
->vpaths
[0].device_id
);
1704 * Because the itable_set() method uses the active_table field
1705 * for the target virtual path the RTH config should be updated
1706 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1707 * when steering frames.
1709 for (index
= 0; index
< vdev
->no_of_vpath
; index
++) {
1710 status
= vxge_hw_vpath_rts_rth_set(
1711 vdev
->vpaths
[index
].handle
,
1712 vdev
->config
.rth_algorithm
,
1714 vdev
->config
.rth_bkt_sz
);
1716 if (status
!= VXGE_HW_OK
) {
1717 vxge_debug_init(VXGE_ERR
,
1718 "RTH configuration failed for vpath:%d",
1719 vdev
->vpaths
[index
].device_id
);
1727 int vxge_mac_list_add(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1729 struct vxge_mac_addrs
*new_mac_entry
;
1730 u8
*mac_address
= NULL
;
1732 if (vpath
->mac_addr_cnt
>= VXGE_MAX_LEARN_MAC_ADDR_CNT
)
1735 new_mac_entry
= kzalloc(sizeof(struct vxge_mac_addrs
), GFP_ATOMIC
);
1736 if (!new_mac_entry
) {
1737 vxge_debug_mem(VXGE_ERR
,
1738 "%s: memory allocation failed",
1743 list_add(&new_mac_entry
->item
, &vpath
->mac_addr_list
);
1745 /* Copy the new mac address to the list */
1746 mac_address
= (u8
*)&new_mac_entry
->macaddr
;
1747 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
1749 new_mac_entry
->state
= mac
->state
;
1750 vpath
->mac_addr_cnt
++;
1752 /* Is this a multicast address */
1753 if (0x01 & mac
->macaddr
[0])
1754 vpath
->mcast_addr_cnt
++;
1759 /* Add a mac address to DA table */
1760 enum vxge_hw_status
vxge_add_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
1762 enum vxge_hw_status status
= VXGE_HW_OK
;
1763 struct vxge_vpath
*vpath
;
1764 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode
;
1766 if (0x01 & mac
->macaddr
[0]) /* multicast address */
1767 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
;
1769 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE
;
1771 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
1772 status
= vxge_hw_vpath_mac_addr_add(vpath
->handle
, mac
->macaddr
,
1773 mac
->macmask
, duplicate_mode
);
1774 if (status
!= VXGE_HW_OK
) {
1775 vxge_debug_init(VXGE_ERR
,
1776 "DA config add entry failed for vpath:%d",
1779 if (FALSE
== vxge_mac_list_add(vpath
, mac
))
1785 int vxge_mac_list_del(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1787 struct list_head
*entry
, *next
;
1789 u8
*mac_address
= (u8
*) (&del_mac
);
1791 /* Copy the mac address to delete from the list */
1792 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
1794 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1795 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
) {
1797 kfree((struct vxge_mac_addrs
*)entry
);
1798 vpath
->mac_addr_cnt
--;
1800 /* Is this a multicast address */
1801 if (0x01 & mac
->macaddr
[0])
1802 vpath
->mcast_addr_cnt
--;
1809 /* delete a mac address from DA table */
1810 enum vxge_hw_status
vxge_del_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
1812 enum vxge_hw_status status
= VXGE_HW_OK
;
1813 struct vxge_vpath
*vpath
;
1815 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
1816 status
= vxge_hw_vpath_mac_addr_delete(vpath
->handle
, mac
->macaddr
,
1818 if (status
!= VXGE_HW_OK
) {
1819 vxge_debug_init(VXGE_ERR
,
1820 "DA config delete entry failed for vpath:%d",
1823 vxge_mac_list_del(vpath
, mac
);
1827 /* list all mac addresses from DA table */
1829 static vxge_search_mac_addr_in_da_table(struct vxge_vpath
*vpath
,
1830 struct macInfo
*mac
)
1832 enum vxge_hw_status status
= VXGE_HW_OK
;
1833 unsigned char macmask
[ETH_ALEN
];
1834 unsigned char macaddr
[ETH_ALEN
];
1836 status
= vxge_hw_vpath_mac_addr_get(vpath
->handle
,
1838 if (status
!= VXGE_HW_OK
) {
1839 vxge_debug_init(VXGE_ERR
,
1840 "DA config list entry failed for vpath:%d",
1845 while (memcmp(mac
->macaddr
, macaddr
, ETH_ALEN
)) {
1847 status
= vxge_hw_vpath_mac_addr_get_next(vpath
->handle
,
1849 if (status
!= VXGE_HW_OK
)
1856 /* Store all vlan ids from the list to the vid table */
1857 enum vxge_hw_status
vxge_restore_vpath_vid_table(struct vxge_vpath
*vpath
)
1859 enum vxge_hw_status status
= VXGE_HW_OK
;
1860 struct vxgedev
*vdev
= vpath
->vdev
;
1863 if (vdev
->vlgrp
&& vpath
->is_open
) {
1865 for (vid
= 0; vid
< VLAN_GROUP_ARRAY_LEN
; vid
++) {
1866 if (!vlan_group_get_device(vdev
->vlgrp
, vid
))
1868 /* Add these vlan to the vid table */
1869 status
= vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
1876 /* Store all mac addresses from the list to the DA table */
1877 enum vxge_hw_status
vxge_restore_vpath_mac_addr(struct vxge_vpath
*vpath
)
1879 enum vxge_hw_status status
= VXGE_HW_OK
;
1880 struct macInfo mac_info
;
1881 u8
*mac_address
= NULL
;
1882 struct list_head
*entry
, *next
;
1884 memset(&mac_info
, 0, sizeof(struct macInfo
));
1886 if (vpath
->is_open
) {
1888 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1891 ((struct vxge_mac_addrs
*)entry
)->macaddr
;
1892 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1893 ((struct vxge_mac_addrs
*)entry
)->state
=
1894 VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1895 /* does this mac address already exist in da table? */
1896 status
= vxge_search_mac_addr_in_da_table(vpath
,
1898 if (status
!= VXGE_HW_OK
) {
1899 /* Add this mac address to the DA table */
1900 status
= vxge_hw_vpath_mac_addr_add(
1901 vpath
->handle
, mac_info
.macaddr
,
1903 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
);
1904 if (status
!= VXGE_HW_OK
) {
1905 vxge_debug_init(VXGE_ERR
,
1906 "DA add entry failed for vpath:%d",
1908 ((struct vxge_mac_addrs
*)entry
)->state
1909 = VXGE_LL_MAC_ADDR_IN_LIST
;
1919 enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
)
1921 enum vxge_hw_status status
= VXGE_HW_OK
;
1922 struct vxge_vpath
*vpath
;
1925 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1926 vpath
= &vdev
->vpaths
[i
];
1927 if (vpath
->handle
) {
1928 if (vxge_hw_vpath_reset(vpath
->handle
) == VXGE_HW_OK
) {
1929 if (is_vxge_card_up(vdev
) &&
1930 vxge_hw_vpath_recover_from_reset(
1931 vpath
->handle
) != VXGE_HW_OK
) {
1932 vxge_debug_init(VXGE_ERR
,
1933 "vxge_hw_vpath_recover_"
1934 "from_reset failed for vpath: "
1939 vxge_debug_init(VXGE_ERR
,
1940 "vxge_hw_vpath_reset failed for "
1951 void vxge_close_vpaths(struct vxgedev
*vdev
, int index
)
1953 struct vxge_vpath
*vpath
;
1956 for (i
= index
; i
< vdev
->no_of_vpath
; i
++) {
1957 vpath
= &vdev
->vpaths
[i
];
1959 if (vpath
->handle
&& vpath
->is_open
) {
1960 vxge_hw_vpath_close(vpath
->handle
);
1961 vdev
->stats
.vpaths_open
--;
1964 vpath
->handle
= NULL
;
1969 int vxge_open_vpaths(struct vxgedev
*vdev
)
1971 struct vxge_hw_vpath_attr attr
;
1972 enum vxge_hw_status status
;
1973 struct vxge_vpath
*vpath
;
1977 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1978 vpath
= &vdev
->vpaths
[i
];
1980 vxge_assert(vpath
->is_configured
);
1981 attr
.vp_id
= vpath
->device_id
;
1982 attr
.fifo_attr
.callback
= vxge_xmit_compl
;
1983 attr
.fifo_attr
.txdl_term
= vxge_tx_term
;
1984 attr
.fifo_attr
.per_txdl_space
= sizeof(struct vxge_tx_priv
);
1985 attr
.fifo_attr
.userdata
= &vpath
->fifo
;
1987 attr
.ring_attr
.callback
= vxge_rx_1b_compl
;
1988 attr
.ring_attr
.rxd_init
= vxge_rx_initial_replenish
;
1989 attr
.ring_attr
.rxd_term
= vxge_rx_term
;
1990 attr
.ring_attr
.per_rxd_space
= sizeof(struct vxge_rx_priv
);
1991 attr
.ring_attr
.userdata
= &vpath
->ring
;
1993 vpath
->ring
.ndev
= vdev
->ndev
;
1994 vpath
->ring
.pdev
= vdev
->pdev
;
1995 status
= vxge_hw_vpath_open(vdev
->devh
, &attr
, &vpath
->handle
);
1996 if (status
== VXGE_HW_OK
) {
1997 vpath
->fifo
.handle
=
1998 (struct __vxge_hw_fifo
*)attr
.fifo_attr
.userdata
;
1999 vpath
->ring
.handle
=
2000 (struct __vxge_hw_ring
*)attr
.ring_attr
.userdata
;
2001 vpath
->fifo
.tx_steering_type
=
2002 vdev
->config
.tx_steering_type
;
2003 vpath
->fifo
.ndev
= vdev
->ndev
;
2004 vpath
->fifo
.pdev
= vdev
->pdev
;
2005 if (vdev
->config
.tx_steering_type
)
2007 netdev_get_tx_queue(vdev
->ndev
, i
);
2010 netdev_get_tx_queue(vdev
->ndev
, 0);
2011 vpath
->fifo
.indicate_max_pkts
=
2012 vdev
->config
.fifo_indicate_max_pkts
;
2013 vpath
->ring
.rx_vector_no
= 0;
2014 vpath
->ring
.rx_csum
= vdev
->rx_csum
;
2016 vdev
->vp_handles
[i
] = vpath
->handle
;
2017 vpath
->ring
.gro_enable
= vdev
->config
.gro_enable
;
2018 vpath
->ring
.vlan_tag_strip
= vdev
->vlan_tag_strip
;
2019 vdev
->stats
.vpaths_open
++;
2021 vdev
->stats
.vpath_open_fail
++;
2022 vxge_debug_init(VXGE_ERR
,
2023 "%s: vpath: %d failed to open "
2025 vdev
->ndev
->name
, vpath
->device_id
,
2027 vxge_close_vpaths(vdev
, 0);
2031 vp_id
= vpath
->handle
->vpath
->vp_id
;
2032 vdev
->vpaths_deployed
|= vxge_mBIT(vp_id
);
2039 * @irq: the irq of the device.
2040 * @dev_id: a void pointer to the hldev structure of the Titan device
2041 * @ptregs: pointer to the registers pushed on the stack.
2043 * This function is the ISR handler of the device when napi is enabled. It
2044 * identifies the reason for the interrupt and calls the relevant service
2047 static irqreturn_t
vxge_isr_napi(int irq
, void *dev_id
)
2049 struct net_device
*dev
;
2050 struct __vxge_hw_device
*hldev
;
2052 enum vxge_hw_status status
;
2053 struct vxgedev
*vdev
= (struct vxgedev
*) dev_id
;;
2055 vxge_debug_intr(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
2058 hldev
= (struct __vxge_hw_device
*)pci_get_drvdata(vdev
->pdev
);
2060 if (pci_channel_offline(vdev
->pdev
))
2063 if (unlikely(!is_vxge_card_up(vdev
)))
2066 status
= vxge_hw_device_begin_irq(hldev
, vdev
->exec_mode
,
2068 if (status
== VXGE_HW_OK
) {
2069 vxge_hw_device_mask_all(hldev
);
2072 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2073 vdev
->vpaths_deployed
>>
2074 (64 - VXGE_HW_MAX_VIRTUAL_PATHS
))) {
2076 vxge_hw_device_clear_tx_rx(hldev
);
2077 napi_schedule(&vdev
->napi
);
2078 vxge_debug_intr(VXGE_TRACE
,
2079 "%s:%d Exiting...", __func__
, __LINE__
);
2082 vxge_hw_device_unmask_all(hldev
);
2083 } else if (unlikely((status
== VXGE_HW_ERR_VPATH
) ||
2084 (status
== VXGE_HW_ERR_CRITICAL
) ||
2085 (status
== VXGE_HW_ERR_FIFO
))) {
2086 vxge_hw_device_mask_all(hldev
);
2087 vxge_hw_device_flush_io(hldev
);
2089 } else if (unlikely(status
== VXGE_HW_ERR_SLOT_FREEZE
))
2092 vxge_debug_intr(VXGE_TRACE
, "%s:%d Exiting...", __func__
, __LINE__
);
2096 #ifdef CONFIG_PCI_MSI
2099 vxge_tx_msix_handle(int irq
, void *dev_id
)
2101 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)dev_id
;
2103 VXGE_COMPLETE_VPATH_TX(fifo
);
2109 vxge_rx_msix_napi_handle(int irq
, void *dev_id
)
2111 struct vxge_ring
*ring
= (struct vxge_ring
*)dev_id
;
2113 /* MSIX_IDX for Rx is 1 */
2114 vxge_hw_channel_msix_mask((struct __vxge_hw_channel
*)ring
->handle
,
2115 ring
->rx_vector_no
);
2117 napi_schedule(&ring
->napi
);
2122 vxge_alarm_msix_handle(int irq
, void *dev_id
)
2125 enum vxge_hw_status status
;
2126 struct vxge_vpath
*vpath
= (struct vxge_vpath
*)dev_id
;
2127 struct vxgedev
*vdev
= vpath
->vdev
;
2128 int msix_id
= (vpath
->handle
->vpath
->vp_id
*
2129 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
2131 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2132 vxge_hw_vpath_msix_mask(vdev
->vpaths
[i
].handle
, msix_id
);
2134 status
= vxge_hw_vpath_alarm_process(vdev
->vpaths
[i
].handle
,
2136 if (status
== VXGE_HW_OK
) {
2138 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[i
].handle
,
2142 vxge_debug_intr(VXGE_ERR
,
2143 "%s: vxge_hw_vpath_alarm_process failed %x ",
2144 VXGE_DRIVER_NAME
, status
);
2149 static int vxge_alloc_msix(struct vxgedev
*vdev
)
2152 int msix_intr_vect
= 0, temp
;
2156 /* Tx/Rx MSIX Vectors count */
2157 vdev
->intr_cnt
= vdev
->no_of_vpath
* 2;
2159 /* Alarm MSIX Vectors count */
2162 vdev
->entries
= kzalloc(vdev
->intr_cnt
* sizeof(struct msix_entry
),
2164 if (!vdev
->entries
) {
2165 vxge_debug_init(VXGE_ERR
,
2166 "%s: memory allocation failed",
2169 goto alloc_entries_failed
;
2172 vdev
->vxge_entries
=
2173 kzalloc(vdev
->intr_cnt
* sizeof(struct vxge_msix_entry
),
2175 if (!vdev
->vxge_entries
) {
2176 vxge_debug_init(VXGE_ERR
, "%s: memory allocation failed",
2179 goto alloc_vxge_entries_failed
;
2182 for (i
= 0, j
= 0; i
< vdev
->no_of_vpath
; i
++) {
2184 msix_intr_vect
= i
* VXGE_HW_VPATH_MSIX_ACTIVE
;
2186 /* Initialize the fifo vector */
2187 vdev
->entries
[j
].entry
= msix_intr_vect
;
2188 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
;
2189 vdev
->vxge_entries
[j
].in_use
= 0;
2192 /* Initialize the ring vector */
2193 vdev
->entries
[j
].entry
= msix_intr_vect
+ 1;
2194 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
+ 1;
2195 vdev
->vxge_entries
[j
].in_use
= 0;
2199 /* Initialize the alarm vector */
2200 vdev
->entries
[j
].entry
= VXGE_ALARM_MSIX_ID
;
2201 vdev
->vxge_entries
[j
].entry
= VXGE_ALARM_MSIX_ID
;
2202 vdev
->vxge_entries
[j
].in_use
= 0;
2204 ret
= pci_enable_msix(vdev
->pdev
, vdev
->entries
, vdev
->intr_cnt
);
2206 vxge_debug_init(VXGE_ERR
,
2207 "%s: MSI-X enable failed for %d vectors, ret: %d",
2208 VXGE_DRIVER_NAME
, vdev
->intr_cnt
, ret
);
2209 if ((max_config_vpath
!= VXGE_USE_DEFAULT
) || (ret
< 3)) {
2211 goto enable_msix_failed
;
2214 kfree(vdev
->entries
);
2215 kfree(vdev
->vxge_entries
);
2216 vdev
->entries
= NULL
;
2217 vdev
->vxge_entries
= NULL
;
2218 /* Try with less no of vector by reducing no of vpaths count */
2220 vxge_close_vpaths(vdev
, temp
);
2221 vdev
->no_of_vpath
= temp
;
2223 } else if (ret
< 0) {
2225 goto enable_msix_failed
;
2230 kfree(vdev
->vxge_entries
);
2231 alloc_vxge_entries_failed
:
2232 kfree(vdev
->entries
);
2233 alloc_entries_failed
:
2237 static int vxge_enable_msix(struct vxgedev
*vdev
)
2241 /* 0 - Tx, 1 - Rx */
2242 int tim_msix_id
[4] = {0, 1, 0, 0};
2246 /* allocate msix vectors */
2247 ret
= vxge_alloc_msix(vdev
);
2249 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2250 struct vxge_vpath
*vpath
= &vdev
->vpaths
[i
];
2252 /* If fifo or ring are not enabled, the MSIX vector for
2253 * it should be set to 0.
2255 vpath
->ring
.rx_vector_no
= (vpath
->device_id
*
2256 VXGE_HW_VPATH_MSIX_ACTIVE
) + 1;
2258 vxge_hw_vpath_msix_set(vpath
->handle
, tim_msix_id
,
2259 VXGE_ALARM_MSIX_ID
);
2266 static void vxge_rem_msix_isr(struct vxgedev
*vdev
)
2270 for (intr_cnt
= 0; intr_cnt
< (vdev
->no_of_vpath
* 2 + 1);
2272 if (vdev
->vxge_entries
[intr_cnt
].in_use
) {
2273 synchronize_irq(vdev
->entries
[intr_cnt
].vector
);
2274 free_irq(vdev
->entries
[intr_cnt
].vector
,
2275 vdev
->vxge_entries
[intr_cnt
].arg
);
2276 vdev
->vxge_entries
[intr_cnt
].in_use
= 0;
2280 kfree(vdev
->entries
);
2281 kfree(vdev
->vxge_entries
);
2282 vdev
->entries
= NULL
;
2283 vdev
->vxge_entries
= NULL
;
2285 if (vdev
->config
.intr_type
== MSI_X
)
2286 pci_disable_msix(vdev
->pdev
);
2290 static void vxge_rem_isr(struct vxgedev
*vdev
)
2292 struct __vxge_hw_device
*hldev
;
2293 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2295 #ifdef CONFIG_PCI_MSI
2296 if (vdev
->config
.intr_type
== MSI_X
) {
2297 vxge_rem_msix_isr(vdev
);
2300 if (vdev
->config
.intr_type
== INTA
) {
2301 synchronize_irq(vdev
->pdev
->irq
);
2302 free_irq(vdev
->pdev
->irq
, vdev
);
2306 static int vxge_add_isr(struct vxgedev
*vdev
)
2309 #ifdef CONFIG_PCI_MSI
2310 int vp_idx
= 0, intr_idx
= 0, intr_cnt
= 0, msix_idx
= 0, irq_req
= 0;
2311 int pci_fun
= PCI_FUNC(vdev
->pdev
->devfn
);
2313 if (vdev
->config
.intr_type
== MSI_X
)
2314 ret
= vxge_enable_msix(vdev
);
2317 vxge_debug_init(VXGE_ERR
,
2318 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME
);
2319 vxge_debug_init(VXGE_ERR
,
2320 "%s: Defaulting to INTA", VXGE_DRIVER_NAME
);
2321 vdev
->config
.intr_type
= INTA
;
2324 if (vdev
->config
.intr_type
== MSI_X
) {
2326 intr_idx
< (vdev
->no_of_vpath
*
2327 VXGE_HW_VPATH_MSIX_ACTIVE
); intr_idx
++) {
2329 msix_idx
= intr_idx
% VXGE_HW_VPATH_MSIX_ACTIVE
;
2334 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2335 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2337 vdev
->entries
[intr_cnt
].entry
,
2340 vdev
->entries
[intr_cnt
].vector
,
2341 vxge_tx_msix_handle
, 0,
2342 vdev
->desc
[intr_cnt
],
2343 &vdev
->vpaths
[vp_idx
].fifo
);
2344 vdev
->vxge_entries
[intr_cnt
].arg
=
2345 &vdev
->vpaths
[vp_idx
].fifo
;
2349 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2350 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2352 vdev
->entries
[intr_cnt
].entry
,
2355 vdev
->entries
[intr_cnt
].vector
,
2356 vxge_rx_msix_napi_handle
,
2358 vdev
->desc
[intr_cnt
],
2359 &vdev
->vpaths
[vp_idx
].ring
);
2360 vdev
->vxge_entries
[intr_cnt
].arg
=
2361 &vdev
->vpaths
[vp_idx
].ring
;
2367 vxge_debug_init(VXGE_ERR
,
2368 "%s: MSIX - %d Registration failed",
2369 vdev
->ndev
->name
, intr_cnt
);
2370 vxge_rem_msix_isr(vdev
);
2371 vdev
->config
.intr_type
= INTA
;
2372 vxge_debug_init(VXGE_ERR
,
2373 "%s: Defaulting to INTA"
2374 , vdev
->ndev
->name
);
2379 /* We requested for this msix interrupt */
2380 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2381 msix_idx
+= vdev
->vpaths
[vp_idx
].device_id
*
2382 VXGE_HW_VPATH_MSIX_ACTIVE
;
2383 vxge_hw_vpath_msix_unmask(
2384 vdev
->vpaths
[vp_idx
].handle
,
2389 /* Point to next vpath handler */
2390 if (((intr_idx
+ 1) % VXGE_HW_VPATH_MSIX_ACTIVE
== 0) &&
2391 (vp_idx
< (vdev
->no_of_vpath
- 1)))
2395 intr_cnt
= vdev
->no_of_vpath
* 2;
2396 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2397 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2399 vdev
->entries
[intr_cnt
].entry
,
2401 /* For Alarm interrupts */
2402 ret
= request_irq(vdev
->entries
[intr_cnt
].vector
,
2403 vxge_alarm_msix_handle
, 0,
2404 vdev
->desc
[intr_cnt
],
2407 vxge_debug_init(VXGE_ERR
,
2408 "%s: MSIX - %d Registration failed",
2409 vdev
->ndev
->name
, intr_cnt
);
2410 vxge_rem_msix_isr(vdev
);
2411 vdev
->config
.intr_type
= INTA
;
2412 vxge_debug_init(VXGE_ERR
,
2413 "%s: Defaulting to INTA",
2418 msix_idx
= (vdev
->vpaths
[0].handle
->vpath
->vp_id
*
2419 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
2420 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[vp_idx
].handle
,
2422 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2423 vdev
->vxge_entries
[intr_cnt
].arg
= &vdev
->vpaths
[0];
2428 if (vdev
->config
.intr_type
== INTA
) {
2429 snprintf(vdev
->desc
[0], VXGE_INTR_STRLEN
,
2430 "%s:vxge:INTA", vdev
->ndev
->name
);
2431 vxge_hw_device_set_intr_type(vdev
->devh
,
2432 VXGE_HW_INTR_MODE_IRQLINE
);
2433 vxge_hw_vpath_tti_ci_set(vdev
->devh
,
2434 vdev
->vpaths
[0].device_id
);
2435 ret
= request_irq((int) vdev
->pdev
->irq
,
2437 IRQF_SHARED
, vdev
->desc
[0], vdev
);
2439 vxge_debug_init(VXGE_ERR
,
2440 "%s %s-%d: ISR registration failed",
2441 VXGE_DRIVER_NAME
, "IRQ", vdev
->pdev
->irq
);
2444 vxge_debug_init(VXGE_TRACE
,
2445 "new %s-%d line allocated",
2446 "IRQ", vdev
->pdev
->irq
);
2452 static void vxge_poll_vp_reset(unsigned long data
)
2454 struct vxgedev
*vdev
= (struct vxgedev
*)data
;
2457 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2458 if (test_bit(i
, &vdev
->vp_reset
)) {
2459 vxge_reset_vpath(vdev
, i
);
2463 if (j
&& (vdev
->config
.intr_type
!= MSI_X
)) {
2464 vxge_hw_device_unmask_all(vdev
->devh
);
2465 vxge_hw_device_flush_io(vdev
->devh
);
2468 mod_timer(&vdev
->vp_reset_timer
, jiffies
+ HZ
/ 2);
2471 static void vxge_poll_vp_lockup(unsigned long data
)
2473 struct vxgedev
*vdev
= (struct vxgedev
*)data
;
2474 enum vxge_hw_status status
= VXGE_HW_OK
;
2475 struct vxge_vpath
*vpath
;
2476 struct vxge_ring
*ring
;
2479 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2480 ring
= &vdev
->vpaths
[i
].ring
;
2481 /* Did this vpath received any packets */
2482 if (ring
->stats
.prev_rx_frms
== ring
->stats
.rx_frms
) {
2483 status
= vxge_hw_vpath_check_leak(ring
->handle
);
2485 /* Did it received any packets last time */
2486 if ((VXGE_HW_FAIL
== status
) &&
2487 (VXGE_HW_FAIL
== ring
->last_status
)) {
2489 /* schedule vpath reset */
2490 if (!test_and_set_bit(i
, &vdev
->vp_reset
)) {
2491 vpath
= &vdev
->vpaths
[i
];
2493 /* disable interrupts for this vpath */
2494 vxge_vpath_intr_disable(vdev
, i
);
2496 /* stop the queue for this vpath */
2497 netif_tx_stop_queue(vpath
->fifo
.txq
);
2502 ring
->stats
.prev_rx_frms
= ring
->stats
.rx_frms
;
2503 ring
->last_status
= status
;
2506 /* Check every 1 milli second */
2507 mod_timer(&vdev
->vp_lockup_timer
, jiffies
+ HZ
/ 1000);
2512 * @dev: pointer to the device structure.
2514 * This function is the open entry point of the driver. It mainly calls a
2515 * function to allocate Rx buffers and inserts them into the buffer
2516 * descriptors and then enables the Rx part of the NIC.
2517 * Return value: '0' on success and an appropriate (-)ve integer as
2518 * defined in errno.h file on failure.
2521 vxge_open(struct net_device
*dev
)
2523 enum vxge_hw_status status
;
2524 struct vxgedev
*vdev
;
2525 struct __vxge_hw_device
*hldev
;
2526 struct vxge_vpath
*vpath
;
2529 u64 val64
, function_mode
;
2530 vxge_debug_entryexit(VXGE_TRACE
,
2531 "%s: %s:%d", dev
->name
, __func__
, __LINE__
);
2533 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2534 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2535 function_mode
= vdev
->config
.device_hw_info
.function_mode
;
2537 /* make sure you have link off by default every time Nic is
2539 netif_carrier_off(dev
);
2542 status
= vxge_open_vpaths(vdev
);
2543 if (status
!= VXGE_HW_OK
) {
2544 vxge_debug_init(VXGE_ERR
,
2545 "%s: fatal: Vpath open failed", vdev
->ndev
->name
);
2550 vdev
->mtu
= dev
->mtu
;
2552 status
= vxge_add_isr(vdev
);
2553 if (status
!= VXGE_HW_OK
) {
2554 vxge_debug_init(VXGE_ERR
,
2555 "%s: fatal: ISR add failed", dev
->name
);
2560 if (vdev
->config
.intr_type
!= MSI_X
) {
2561 netif_napi_add(dev
, &vdev
->napi
, vxge_poll_inta
,
2562 vdev
->config
.napi_weight
);
2563 napi_enable(&vdev
->napi
);
2564 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2565 vpath
= &vdev
->vpaths
[i
];
2566 vpath
->ring
.napi_p
= &vdev
->napi
;
2569 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2570 vpath
= &vdev
->vpaths
[i
];
2571 netif_napi_add(dev
, &vpath
->ring
.napi
,
2572 vxge_poll_msix
, vdev
->config
.napi_weight
);
2573 napi_enable(&vpath
->ring
.napi
);
2574 vpath
->ring
.napi_p
= &vpath
->ring
.napi
;
2579 if (vdev
->config
.rth_steering
) {
2580 status
= vxge_rth_configure(vdev
);
2581 if (status
!= VXGE_HW_OK
) {
2582 vxge_debug_init(VXGE_ERR
,
2583 "%s: fatal: RTH configuration failed",
2590 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2591 vpath
= &vdev
->vpaths
[i
];
2593 /* set initial mtu before enabling the device */
2594 status
= vxge_hw_vpath_mtu_set(vpath
->handle
, vdev
->mtu
);
2595 if (status
!= VXGE_HW_OK
) {
2596 vxge_debug_init(VXGE_ERR
,
2597 "%s: fatal: can not set new MTU", dev
->name
);
2603 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE
, VXGE_COMPONENT_LL
, vdev
);
2604 vxge_debug_init(vdev
->level_trace
,
2605 "%s: MTU is %d", vdev
->ndev
->name
, vdev
->mtu
);
2606 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR
, VXGE_COMPONENT_LL
, vdev
);
2608 /* Restore the DA, VID table and also multicast and promiscuous mode
2611 if (vdev
->all_multi_flg
) {
2612 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2613 vpath
= &vdev
->vpaths
[i
];
2614 vxge_restore_vpath_mac_addr(vpath
);
2615 vxge_restore_vpath_vid_table(vpath
);
2617 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
2618 if (status
!= VXGE_HW_OK
)
2619 vxge_debug_init(VXGE_ERR
,
2620 "%s:%d Enabling multicast failed",
2621 __func__
, __LINE__
);
2625 /* Enable vpath to sniff all unicast/multicast traffic that not
2626 * addressed to them. We allow promiscous mode for PF only
2630 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
2631 val64
|= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i
);
2633 vxge_hw_mgmt_reg_write(vdev
->devh
,
2634 vxge_hw_mgmt_reg_type_mrpcim
,
2636 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2637 rxmac_authorize_all_addr
),
2640 vxge_hw_mgmt_reg_write(vdev
->devh
,
2641 vxge_hw_mgmt_reg_type_mrpcim
,
2643 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2644 rxmac_authorize_all_vid
),
2647 vxge_set_multicast(dev
);
2649 /* Enabling Bcast and mcast for all vpath */
2650 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2651 vpath
= &vdev
->vpaths
[i
];
2652 status
= vxge_hw_vpath_bcast_enable(vpath
->handle
);
2653 if (status
!= VXGE_HW_OK
)
2654 vxge_debug_init(VXGE_ERR
,
2655 "%s : Can not enable bcast for vpath "
2656 "id %d", dev
->name
, i
);
2657 if (vdev
->config
.addr_learn_en
) {
2658 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
2659 if (status
!= VXGE_HW_OK
)
2660 vxge_debug_init(VXGE_ERR
,
2661 "%s : Can not enable mcast for vpath "
2662 "id %d", dev
->name
, i
);
2666 vxge_hw_device_setpause_data(vdev
->devh
, 0,
2667 vdev
->config
.tx_pause_enable
,
2668 vdev
->config
.rx_pause_enable
);
2670 if (vdev
->vp_reset_timer
.function
== NULL
)
2671 vxge_os_timer(vdev
->vp_reset_timer
,
2672 vxge_poll_vp_reset
, vdev
, (HZ
/2));
2674 if (vdev
->vp_lockup_timer
.function
== NULL
)
2675 vxge_os_timer(vdev
->vp_lockup_timer
,
2676 vxge_poll_vp_lockup
, vdev
, (HZ
/2));
2678 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
2682 if (vxge_hw_device_link_state_get(vdev
->devh
) == VXGE_HW_LINK_UP
) {
2683 netif_carrier_on(vdev
->ndev
);
2684 netdev_notice(vdev
->ndev
, "Link Up\n");
2685 vdev
->stats
.link_up
++;
2688 vxge_hw_device_intr_enable(vdev
->devh
);
2692 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2693 vpath
= &vdev
->vpaths
[i
];
2695 vxge_hw_vpath_enable(vpath
->handle
);
2697 vxge_hw_vpath_rx_doorbell_init(vpath
->handle
);
2700 netif_tx_start_all_queues(vdev
->ndev
);
2707 if (vdev
->config
.intr_type
!= MSI_X
)
2708 napi_disable(&vdev
->napi
);
2710 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2711 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
2715 vxge_close_vpaths(vdev
, 0);
2717 vxge_debug_entryexit(VXGE_TRACE
,
2718 "%s: %s:%d Exiting...",
2719 dev
->name
, __func__
, __LINE__
);
2723 /* Loop throught the mac address list and delete all the entries */
2724 void vxge_free_mac_add_list(struct vxge_vpath
*vpath
)
2727 struct list_head
*entry
, *next
;
2728 if (list_empty(&vpath
->mac_addr_list
))
2731 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
2733 kfree((struct vxge_mac_addrs
*)entry
);
2737 static void vxge_napi_del_all(struct vxgedev
*vdev
)
2740 if (vdev
->config
.intr_type
!= MSI_X
)
2741 netif_napi_del(&vdev
->napi
);
2743 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2744 netif_napi_del(&vdev
->vpaths
[i
].ring
.napi
);
2748 int do_vxge_close(struct net_device
*dev
, int do_io
)
2750 enum vxge_hw_status status
;
2751 struct vxgedev
*vdev
;
2752 struct __vxge_hw_device
*hldev
;
2754 u64 val64
, vpath_vector
;
2755 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
2756 dev
->name
, __func__
, __LINE__
);
2758 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2759 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(vdev
->pdev
);
2761 if (unlikely(!is_vxge_card_up(vdev
)))
2764 /* If vxge_handle_crit_err task is executing,
2765 * wait till it completes. */
2766 while (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
2769 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
2771 /* Put the vpath back in normal mode */
2772 vpath_vector
= vxge_mBIT(vdev
->vpaths
[0].device_id
);
2773 status
= vxge_hw_mgmt_reg_read(vdev
->devh
,
2774 vxge_hw_mgmt_reg_type_mrpcim
,
2777 struct vxge_hw_mrpcim_reg
,
2778 rts_mgr_cbasin_cfg
),
2781 if (status
== VXGE_HW_OK
) {
2782 val64
&= ~vpath_vector
;
2783 status
= vxge_hw_mgmt_reg_write(vdev
->devh
,
2784 vxge_hw_mgmt_reg_type_mrpcim
,
2787 struct vxge_hw_mrpcim_reg
,
2788 rts_mgr_cbasin_cfg
),
2792 /* Remove the function 0 from promiscous mode */
2793 vxge_hw_mgmt_reg_write(vdev
->devh
,
2794 vxge_hw_mgmt_reg_type_mrpcim
,
2796 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2797 rxmac_authorize_all_addr
),
2800 vxge_hw_mgmt_reg_write(vdev
->devh
,
2801 vxge_hw_mgmt_reg_type_mrpcim
,
2803 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2804 rxmac_authorize_all_vid
),
2809 del_timer_sync(&vdev
->vp_lockup_timer
);
2811 del_timer_sync(&vdev
->vp_reset_timer
);
2814 if (vdev
->config
.intr_type
!= MSI_X
)
2815 napi_disable(&vdev
->napi
);
2817 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2818 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
2821 netif_carrier_off(vdev
->ndev
);
2822 netdev_notice(vdev
->ndev
, "Link Down\n");
2823 netif_tx_stop_all_queues(vdev
->ndev
);
2825 /* Note that at this point xmit() is stopped by upper layer */
2827 vxge_hw_device_intr_disable(vdev
->devh
);
2833 vxge_napi_del_all(vdev
);
2836 vxge_reset_all_vpaths(vdev
);
2838 vxge_close_vpaths(vdev
, 0);
2840 vxge_debug_entryexit(VXGE_TRACE
,
2841 "%s: %s:%d Exiting...", dev
->name
, __func__
, __LINE__
);
2843 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
2850 * @dev: device pointer.
2852 * This is the stop entry point of the driver. It needs to undo exactly
2853 * whatever was done by the open entry point, thus it's usually referred to
2854 * as the close function.Among other things this function mainly stops the
2855 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2856 * Return value: '0' on success and an appropriate (-)ve integer as
2857 * defined in errno.h file on failure.
2860 vxge_close(struct net_device
*dev
)
2862 do_vxge_close(dev
, 1);
2868 * @dev: net device pointer.
2869 * @new_mtu :the new MTU size for the device.
2871 * A driver entry point to change MTU size for the device. Before changing
2872 * the MTU the device must be stopped.
2874 static int vxge_change_mtu(struct net_device
*dev
, int new_mtu
)
2876 struct vxgedev
*vdev
= netdev_priv(dev
);
2878 vxge_debug_entryexit(vdev
->level_trace
,
2879 "%s:%d", __func__
, __LINE__
);
2880 if ((new_mtu
< VXGE_HW_MIN_MTU
) || (new_mtu
> VXGE_HW_MAX_MTU
)) {
2881 vxge_debug_init(vdev
->level_err
,
2882 "%s: mtu size is invalid", dev
->name
);
2886 /* check if device is down already */
2887 if (unlikely(!is_vxge_card_up(vdev
))) {
2888 /* just store new value, will use later on open() */
2890 vxge_debug_init(vdev
->level_err
,
2891 "%s", "device is down on MTU change");
2895 vxge_debug_init(vdev
->level_trace
,
2896 "trying to apply new MTU %d", new_mtu
);
2898 if (vxge_close(dev
))
2902 vdev
->mtu
= new_mtu
;
2907 vxge_debug_init(vdev
->level_trace
,
2908 "%s: MTU changed to %d", vdev
->ndev
->name
, new_mtu
);
2910 vxge_debug_entryexit(vdev
->level_trace
,
2911 "%s:%d Exiting...", __func__
, __LINE__
);
2918 * @dev: pointer to the device structure
2920 * Updates the device statistics structure. This function updates the device
2921 * statistics structure in the net_device structure and returns a pointer
2924 static struct net_device_stats
*
2925 vxge_get_stats(struct net_device
*dev
)
2927 struct vxgedev
*vdev
;
2928 struct net_device_stats
*net_stats
;
2931 vdev
= netdev_priv(dev
);
2933 net_stats
= &vdev
->stats
.net_stats
;
2935 memset(net_stats
, 0, sizeof(struct net_device_stats
));
2937 for (k
= 0; k
< vdev
->no_of_vpath
; k
++) {
2938 net_stats
->rx_packets
+= vdev
->vpaths
[k
].ring
.stats
.rx_frms
;
2939 net_stats
->rx_bytes
+= vdev
->vpaths
[k
].ring
.stats
.rx_bytes
;
2940 net_stats
->rx_errors
+= vdev
->vpaths
[k
].ring
.stats
.rx_errors
;
2941 net_stats
->multicast
+= vdev
->vpaths
[k
].ring
.stats
.rx_mcast
;
2942 net_stats
->rx_dropped
+=
2943 vdev
->vpaths
[k
].ring
.stats
.rx_dropped
;
2945 net_stats
->tx_packets
+= vdev
->vpaths
[k
].fifo
.stats
.tx_frms
;
2946 net_stats
->tx_bytes
+= vdev
->vpaths
[k
].fifo
.stats
.tx_bytes
;
2947 net_stats
->tx_errors
+= vdev
->vpaths
[k
].fifo
.stats
.tx_errors
;
2955 * @dev: Device pointer.
2956 * @ifr: An IOCTL specific structure, that can contain a pointer to
2957 * a proprietary structure used to pass information to the driver.
2958 * @cmd: This is used to distinguish between the different commands that
2959 * can be passed to the IOCTL functions.
2961 * Entry point for the Ioctl.
2963 static int vxge_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2970 * @dev: pointer to net device structure
2972 * Watchdog for transmit side.
2973 * This function is triggered if the Tx Queue is stopped
2974 * for a pre-defined amount of time when the Interface is still up.
2977 vxge_tx_watchdog(struct net_device
*dev
)
2979 struct vxgedev
*vdev
;
2981 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
2983 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2985 vdev
->cric_err_event
= VXGE_HW_EVENT_RESET_START
;
2988 vxge_debug_entryexit(VXGE_TRACE
,
2989 "%s:%d Exiting...", __func__
, __LINE__
);
2993 * vxge_vlan_rx_register
2994 * @dev: net device pointer.
2997 * Vlan group registration
3000 vxge_vlan_rx_register(struct net_device
*dev
, struct vlan_group
*grp
)
3002 struct vxgedev
*vdev
;
3003 struct vxge_vpath
*vpath
;
3006 enum vxge_hw_status status
;
3009 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3011 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3013 vpath
= &vdev
->vpaths
[0];
3014 if ((NULL
== grp
) && (vpath
->is_open
)) {
3015 /* Get the first vlan */
3016 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3018 while (status
== VXGE_HW_OK
) {
3020 /* Delete this vlan from the vid table */
3021 for (vp
= 0; vp
< vdev
->no_of_vpath
; vp
++) {
3022 vpath
= &vdev
->vpaths
[vp
];
3023 if (!vpath
->is_open
)
3026 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3029 /* Get the next vlan to be deleted */
3030 vpath
= &vdev
->vpaths
[0];
3031 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3037 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
3038 if (vdev
->vpaths
[i
].is_configured
)
3039 vdev
->vpaths
[i
].ring
.vlgrp
= grp
;
3042 vxge_debug_entryexit(VXGE_TRACE
,
3043 "%s:%d Exiting...", __func__
, __LINE__
);
3047 * vxge_vlan_rx_add_vid
3048 * @dev: net device pointer.
3051 * Add the vlan id to the devices vlan id table
3054 vxge_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
3056 struct vxgedev
*vdev
;
3057 struct vxge_vpath
*vpath
;
3060 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3062 /* Add these vlan to the vid table */
3063 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3064 vpath
= &vdev
->vpaths
[vp_id
];
3065 if (!vpath
->is_open
)
3067 vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
3072 * vxge_vlan_rx_add_vid
3073 * @dev: net device pointer.
3076 * Remove the vlan id from the device's vlan id table
3079 vxge_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
3081 struct vxgedev
*vdev
;
3082 struct vxge_vpath
*vpath
;
3085 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3087 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3089 vlan_group_set_device(vdev
->vlgrp
, vid
, NULL
);
3091 /* Delete this vlan from the vid table */
3092 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3093 vpath
= &vdev
->vpaths
[vp_id
];
3094 if (!vpath
->is_open
)
3096 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3098 vxge_debug_entryexit(VXGE_TRACE
,
3099 "%s:%d Exiting...", __func__
, __LINE__
);
3102 static const struct net_device_ops vxge_netdev_ops
= {
3103 .ndo_open
= vxge_open
,
3104 .ndo_stop
= vxge_close
,
3105 .ndo_get_stats
= vxge_get_stats
,
3106 .ndo_start_xmit
= vxge_xmit
,
3107 .ndo_validate_addr
= eth_validate_addr
,
3108 .ndo_set_multicast_list
= vxge_set_multicast
,
3110 .ndo_do_ioctl
= vxge_ioctl
,
3112 .ndo_set_mac_address
= vxge_set_mac_addr
,
3113 .ndo_change_mtu
= vxge_change_mtu
,
3114 .ndo_vlan_rx_register
= vxge_vlan_rx_register
,
3115 .ndo_vlan_rx_kill_vid
= vxge_vlan_rx_kill_vid
,
3116 .ndo_vlan_rx_add_vid
= vxge_vlan_rx_add_vid
,
3118 .ndo_tx_timeout
= vxge_tx_watchdog
,
3119 #ifdef CONFIG_NET_POLL_CONTROLLER
3120 .ndo_poll_controller
= vxge_netpoll
,
3124 int __devinit
vxge_device_register(struct __vxge_hw_device
*hldev
,
3125 struct vxge_config
*config
,
3126 int high_dma
, int no_of_vpath
,
3127 struct vxgedev
**vdev_out
)
3129 struct net_device
*ndev
;
3130 enum vxge_hw_status status
= VXGE_HW_OK
;
3131 struct vxgedev
*vdev
;
3132 int ret
= 0, no_of_queue
= 1;
3136 if (config
->tx_steering_type
)
3137 no_of_queue
= no_of_vpath
;
3139 ndev
= alloc_etherdev_mq(sizeof(struct vxgedev
),
3143 vxge_hw_device_trace_level_get(hldev
),
3144 "%s : device allocation failed", __func__
);
3149 vxge_debug_entryexit(
3150 vxge_hw_device_trace_level_get(hldev
),
3151 "%s: %s:%d Entering...",
3152 ndev
->name
, __func__
, __LINE__
);
3154 vdev
= netdev_priv(ndev
);
3155 memset(vdev
, 0, sizeof(struct vxgedev
));
3159 vdev
->pdev
= hldev
->pdev
;
3160 memcpy(&vdev
->config
, config
, sizeof(struct vxge_config
));
3161 vdev
->rx_csum
= 1; /* Enable Rx CSUM by default. */
3163 SET_NETDEV_DEV(ndev
, &vdev
->pdev
->dev
);
3165 ndev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
|
3166 NETIF_F_HW_VLAN_FILTER
;
3167 /* Driver entry points */
3168 ndev
->irq
= vdev
->pdev
->irq
;
3169 ndev
->base_addr
= (unsigned long) hldev
->bar0
;
3171 ndev
->netdev_ops
= &vxge_netdev_ops
;
3173 ndev
->watchdog_timeo
= VXGE_LL_WATCH_DOG_TIMEOUT
;
3175 initialize_ethtool_ops(ndev
);
3177 /* Allocate memory for vpath */
3178 vdev
->vpaths
= kzalloc((sizeof(struct vxge_vpath
)) *
3179 no_of_vpath
, GFP_KERNEL
);
3180 if (!vdev
->vpaths
) {
3181 vxge_debug_init(VXGE_ERR
,
3182 "%s: vpath memory allocation failed",
3188 ndev
->features
|= NETIF_F_SG
;
3190 ndev
->features
|= NETIF_F_HW_CSUM
;
3191 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3192 "%s : checksuming enabled", __func__
);
3195 ndev
->features
|= NETIF_F_HIGHDMA
;
3196 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3197 "%s : using High DMA", __func__
);
3200 ndev
->features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
3202 if (vdev
->config
.gro_enable
)
3203 ndev
->features
|= NETIF_F_GRO
;
3205 if (register_netdev(ndev
)) {
3206 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3207 "%s: %s : device registration failed!",
3208 ndev
->name
, __func__
);
3213 /* Set the factory defined MAC address initially */
3214 ndev
->addr_len
= ETH_ALEN
;
3216 /* Make Link state as off at this point, when the Link change
3217 * interrupt comes the state will be automatically changed to
3220 netif_carrier_off(ndev
);
3222 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3223 "%s: Ethernet device registered",
3228 /* Resetting the Device stats */
3229 status
= vxge_hw_mrpcim_stats_access(
3231 VXGE_HW_STATS_OP_CLEAR_ALL_STATS
,
3236 if (status
== VXGE_HW_ERR_PRIVILAGED_OPEARATION
)
3238 vxge_hw_device_trace_level_get(hldev
),
3239 "%s: device stats clear returns"
3240 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev
->name
);
3242 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev
),
3243 "%s: %s:%d Exiting...",
3244 ndev
->name
, __func__
, __LINE__
);
3248 kfree(vdev
->vpaths
);
3256 * vxge_device_unregister
3258 * This function will unregister and free network device
3261 vxge_device_unregister(struct __vxge_hw_device
*hldev
)
3263 struct vxgedev
*vdev
;
3264 struct net_device
*dev
;
3266 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3267 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3272 vdev
= netdev_priv(dev
);
3273 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3274 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3275 level_trace
= vdev
->level_trace
;
3277 vxge_debug_entryexit(level_trace
,
3278 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3280 memcpy(buf
, vdev
->ndev
->name
, IFNAMSIZ
);
3282 /* in 2.6 will call stop() if device is up */
3283 unregister_netdev(dev
);
3285 flush_scheduled_work();
3287 vxge_debug_init(level_trace
, "%s: ethernet device unregistered", buf
);
3288 vxge_debug_entryexit(level_trace
,
3289 "%s: %s:%d Exiting...", buf
, __func__
, __LINE__
);
3293 * vxge_callback_crit_err
3295 * This function is called by the alarm handler in interrupt context.
3296 * Driver must analyze it based on the event type.
3299 vxge_callback_crit_err(struct __vxge_hw_device
*hldev
,
3300 enum vxge_hw_event type
, u64 vp_id
)
3302 struct net_device
*dev
= hldev
->ndev
;
3303 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
3304 struct vxge_vpath
*vpath
= NULL
;
3307 vxge_debug_entryexit(vdev
->level_trace
,
3308 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3310 /* Note: This event type should be used for device wide
3311 * indications only - Serious errors, Slot freeze and critical errors
3313 vdev
->cric_err_event
= type
;
3315 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
3316 vpath
= &vdev
->vpaths
[vpath_idx
];
3317 if (vpath
->device_id
== vp_id
)
3321 if (!test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
)) {
3322 if (type
== VXGE_HW_EVENT_SLOT_FREEZE
) {
3323 vxge_debug_init(VXGE_ERR
,
3324 "%s: Slot is frozen", vdev
->ndev
->name
);
3325 } else if (type
== VXGE_HW_EVENT_SERR
) {
3326 vxge_debug_init(VXGE_ERR
,
3327 "%s: Encountered Serious Error",
3329 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
)
3330 vxge_debug_init(VXGE_ERR
,
3331 "%s: Encountered Critical Error",
3335 if ((type
== VXGE_HW_EVENT_SERR
) ||
3336 (type
== VXGE_HW_EVENT_SLOT_FREEZE
)) {
3337 if (unlikely(vdev
->exec_mode
))
3338 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3339 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
) {
3340 vxge_hw_device_mask_all(hldev
);
3341 if (unlikely(vdev
->exec_mode
))
3342 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3343 } else if ((type
== VXGE_HW_EVENT_FIFO_ERR
) ||
3344 (type
== VXGE_HW_EVENT_VPATH_ERR
)) {
3346 if (unlikely(vdev
->exec_mode
))
3347 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3349 /* check if this vpath is already set for reset */
3350 if (!test_and_set_bit(vpath_idx
, &vdev
->vp_reset
)) {
3352 /* disable interrupts for this vpath */
3353 vxge_vpath_intr_disable(vdev
, vpath_idx
);
3355 /* stop the queue for this vpath */
3356 netif_tx_stop_queue(vpath
->fifo
.txq
);
3361 vxge_debug_entryexit(vdev
->level_trace
,
3362 "%s: %s:%d Exiting...",
3363 vdev
->ndev
->name
, __func__
, __LINE__
);
3366 static void verify_bandwidth(void)
3368 int i
, band_width
, total
= 0, equal_priority
= 0;
3370 /* 1. If user enters 0 for some fifo, give equal priority to all */
3371 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3372 if (bw_percentage
[i
] == 0) {
3378 if (!equal_priority
) {
3379 /* 2. If sum exceeds 100, give equal priority to all */
3380 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3381 if (bw_percentage
[i
] == 0xFF)
3384 total
+= bw_percentage
[i
];
3385 if (total
> VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3392 if (!equal_priority
) {
3393 /* Is all the bandwidth consumed? */
3394 if (total
< VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3395 if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
) {
3396 /* Split rest of bw equally among next VPs*/
3398 (VXGE_HW_VPATH_BANDWIDTH_MAX
- total
) /
3399 (VXGE_HW_MAX_VIRTUAL_PATHS
- i
);
3400 if (band_width
< 2) /* min of 2% */
3403 for (; i
< VXGE_HW_MAX_VIRTUAL_PATHS
;
3409 } else if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
)
3413 if (equal_priority
) {
3414 vxge_debug_init(VXGE_ERR
,
3415 "%s: Assigning equal bandwidth to all the vpaths",
3417 bw_percentage
[0] = VXGE_HW_VPATH_BANDWIDTH_MAX
/
3418 VXGE_HW_MAX_VIRTUAL_PATHS
;
3419 for (i
= 1; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3420 bw_percentage
[i
] = bw_percentage
[0];
3425 * Vpath configuration
3427 static int __devinit
vxge_config_vpaths(
3428 struct vxge_hw_device_config
*device_config
,
3429 u64 vpath_mask
, struct vxge_config
*config_param
)
3431 int i
, no_of_vpaths
= 0, default_no_vpath
= 0, temp
;
3432 u32 txdl_size
, txdl_per_memblock
;
3434 temp
= driver_config
->vpath_per_dev
;
3435 if ((driver_config
->vpath_per_dev
== VXGE_USE_DEFAULT
) &&
3436 (max_config_dev
== VXGE_MAX_CONFIG_DEV
)) {
3437 /* No more CPU. Return vpath number as zero.*/
3438 if (driver_config
->g_no_cpus
== -1)
3441 if (!driver_config
->g_no_cpus
)
3442 driver_config
->g_no_cpus
= num_online_cpus();
3444 driver_config
->vpath_per_dev
= driver_config
->g_no_cpus
>> 1;
3445 if (!driver_config
->vpath_per_dev
)
3446 driver_config
->vpath_per_dev
= 1;
3448 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3449 if (!vxge_bVALn(vpath_mask
, i
, 1))
3453 if (default_no_vpath
< driver_config
->vpath_per_dev
)
3454 driver_config
->vpath_per_dev
= default_no_vpath
;
3456 driver_config
->g_no_cpus
= driver_config
->g_no_cpus
-
3457 (driver_config
->vpath_per_dev
* 2);
3458 if (driver_config
->g_no_cpus
<= 0)
3459 driver_config
->g_no_cpus
= -1;
3462 if (driver_config
->vpath_per_dev
== 1) {
3463 vxge_debug_ll_config(VXGE_TRACE
,
3464 "%s: Disable tx and rx steering, "
3465 "as single vpath is configured", VXGE_DRIVER_NAME
);
3466 config_param
->rth_steering
= NO_STEERING
;
3467 config_param
->tx_steering_type
= NO_STEERING
;
3468 device_config
->rth_en
= 0;
3471 /* configure bandwidth */
3472 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3473 device_config
->vp_config
[i
].min_bandwidth
= bw_percentage
[i
];
3475 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3476 device_config
->vp_config
[i
].vp_id
= i
;
3477 device_config
->vp_config
[i
].mtu
= VXGE_HW_DEFAULT_MTU
;
3478 if (no_of_vpaths
< driver_config
->vpath_per_dev
) {
3479 if (!vxge_bVALn(vpath_mask
, i
, 1)) {
3480 vxge_debug_ll_config(VXGE_TRACE
,
3481 "%s: vpath: %d is not available",
3482 VXGE_DRIVER_NAME
, i
);
3485 vxge_debug_ll_config(VXGE_TRACE
,
3486 "%s: vpath: %d available",
3487 VXGE_DRIVER_NAME
, i
);
3491 vxge_debug_ll_config(VXGE_TRACE
,
3492 "%s: vpath: %d is not configured, "
3493 "max_config_vpath exceeded",
3494 VXGE_DRIVER_NAME
, i
);
3498 /* Configure Tx fifo's */
3499 device_config
->vp_config
[i
].fifo
.enable
=
3500 VXGE_HW_FIFO_ENABLE
;
3501 device_config
->vp_config
[i
].fifo
.max_frags
=
3503 device_config
->vp_config
[i
].fifo
.memblock_size
=
3504 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
;
3506 txdl_size
= device_config
->vp_config
[i
].fifo
.max_frags
*
3507 sizeof(struct vxge_hw_fifo_txd
);
3508 txdl_per_memblock
= VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
/ txdl_size
;
3510 device_config
->vp_config
[i
].fifo
.fifo_blocks
=
3511 ((VXGE_DEF_FIFO_LENGTH
- 1) / txdl_per_memblock
) + 1;
3513 device_config
->vp_config
[i
].fifo
.intr
=
3514 VXGE_HW_FIFO_QUEUE_INTR_DISABLE
;
3516 /* Configure tti properties */
3517 device_config
->vp_config
[i
].tti
.intr_enable
=
3518 VXGE_HW_TIM_INTR_ENABLE
;
3520 device_config
->vp_config
[i
].tti
.btimer_val
=
3521 (VXGE_TTI_BTIMER_VAL
* 1000) / 272;
3523 device_config
->vp_config
[i
].tti
.timer_ac_en
=
3524 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3526 /* For msi-x with napi (each vector
3527 has a handler of its own) -
3528 Set CI to OFF for all vpaths */
3529 device_config
->vp_config
[i
].tti
.timer_ci_en
=
3530 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3532 device_config
->vp_config
[i
].tti
.timer_ri_en
=
3533 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3535 device_config
->vp_config
[i
].tti
.util_sel
=
3536 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL
;
3538 device_config
->vp_config
[i
].tti
.ltimer_val
=
3539 (VXGE_TTI_LTIMER_VAL
* 1000) / 272;
3541 device_config
->vp_config
[i
].tti
.rtimer_val
=
3542 (VXGE_TTI_RTIMER_VAL
* 1000) / 272;
3544 device_config
->vp_config
[i
].tti
.urange_a
= TTI_TX_URANGE_A
;
3545 device_config
->vp_config
[i
].tti
.urange_b
= TTI_TX_URANGE_B
;
3546 device_config
->vp_config
[i
].tti
.urange_c
= TTI_TX_URANGE_C
;
3547 device_config
->vp_config
[i
].tti
.uec_a
= TTI_TX_UFC_A
;
3548 device_config
->vp_config
[i
].tti
.uec_b
= TTI_TX_UFC_B
;
3549 device_config
->vp_config
[i
].tti
.uec_c
= TTI_TX_UFC_C
;
3550 device_config
->vp_config
[i
].tti
.uec_d
= TTI_TX_UFC_D
;
3552 /* Configure Rx rings */
3553 device_config
->vp_config
[i
].ring
.enable
=
3554 VXGE_HW_RING_ENABLE
;
3556 device_config
->vp_config
[i
].ring
.ring_blocks
=
3557 VXGE_HW_DEF_RING_BLOCKS
;
3558 device_config
->vp_config
[i
].ring
.buffer_mode
=
3559 VXGE_HW_RING_RXD_BUFFER_MODE_1
;
3560 device_config
->vp_config
[i
].ring
.rxds_limit
=
3561 VXGE_HW_DEF_RING_RXDS_LIMIT
;
3562 device_config
->vp_config
[i
].ring
.scatter_mode
=
3563 VXGE_HW_RING_SCATTER_MODE_A
;
3565 /* Configure rti properties */
3566 device_config
->vp_config
[i
].rti
.intr_enable
=
3567 VXGE_HW_TIM_INTR_ENABLE
;
3569 device_config
->vp_config
[i
].rti
.btimer_val
=
3570 (VXGE_RTI_BTIMER_VAL
* 1000)/272;
3572 device_config
->vp_config
[i
].rti
.timer_ac_en
=
3573 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3575 device_config
->vp_config
[i
].rti
.timer_ci_en
=
3576 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3578 device_config
->vp_config
[i
].rti
.timer_ri_en
=
3579 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3581 device_config
->vp_config
[i
].rti
.util_sel
=
3582 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL
;
3584 device_config
->vp_config
[i
].rti
.urange_a
=
3586 device_config
->vp_config
[i
].rti
.urange_b
=
3588 device_config
->vp_config
[i
].rti
.urange_c
=
3590 device_config
->vp_config
[i
].rti
.uec_a
= RTI_RX_UFC_A
;
3591 device_config
->vp_config
[i
].rti
.uec_b
= RTI_RX_UFC_B
;
3592 device_config
->vp_config
[i
].rti
.uec_c
= RTI_RX_UFC_C
;
3593 device_config
->vp_config
[i
].rti
.uec_d
= RTI_RX_UFC_D
;
3595 device_config
->vp_config
[i
].rti
.rtimer_val
=
3596 (VXGE_RTI_RTIMER_VAL
* 1000) / 272;
3598 device_config
->vp_config
[i
].rti
.ltimer_val
=
3599 (VXGE_RTI_LTIMER_VAL
* 1000) / 272;
3601 device_config
->vp_config
[i
].rpa_strip_vlan_tag
=
3605 driver_config
->vpath_per_dev
= temp
;
3606 return no_of_vpaths
;
3609 /* initialize device configuratrions */
3610 static void __devinit
vxge_device_config_init(
3611 struct vxge_hw_device_config
*device_config
,
3614 /* Used for CQRQ/SRQ. */
3615 device_config
->dma_blockpool_initial
=
3616 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE
;
3618 device_config
->dma_blockpool_max
=
3619 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE
;
3621 if (max_mac_vpath
> VXGE_MAX_MAC_ADDR_COUNT
)
3622 max_mac_vpath
= VXGE_MAX_MAC_ADDR_COUNT
;
3624 #ifndef CONFIG_PCI_MSI
3625 vxge_debug_init(VXGE_ERR
,
3626 "%s: This Kernel does not support "
3627 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME
);
3631 /* Configure whether MSI-X or IRQL. */
3632 switch (*intr_type
) {
3634 device_config
->intr_mode
= VXGE_HW_INTR_MODE_IRQLINE
;
3638 device_config
->intr_mode
= VXGE_HW_INTR_MODE_MSIX
;
3641 /* Timer period between device poll */
3642 device_config
->device_poll_millis
= VXGE_TIMER_DELAY
;
3644 /* Configure mac based steering. */
3645 device_config
->rts_mac_en
= addr_learn_en
;
3647 /* Configure Vpaths */
3648 device_config
->rth_it_type
= VXGE_HW_RTH_IT_TYPE_MULTI_IT
;
3650 vxge_debug_ll_config(VXGE_TRACE
, "%s : Device Config Params ",
3652 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_initial : %d",
3653 device_config
->dma_blockpool_initial
);
3654 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_max : %d",
3655 device_config
->dma_blockpool_max
);
3656 vxge_debug_ll_config(VXGE_TRACE
, "intr_mode : %d",
3657 device_config
->intr_mode
);
3658 vxge_debug_ll_config(VXGE_TRACE
, "device_poll_millis : %d",
3659 device_config
->device_poll_millis
);
3660 vxge_debug_ll_config(VXGE_TRACE
, "rts_mac_en : %d",
3661 device_config
->rts_mac_en
);
3662 vxge_debug_ll_config(VXGE_TRACE
, "rth_en : %d",
3663 device_config
->rth_en
);
3664 vxge_debug_ll_config(VXGE_TRACE
, "rth_it_type : %d",
3665 device_config
->rth_it_type
);
3668 static void __devinit
vxge_print_parm(struct vxgedev
*vdev
, u64 vpath_mask
)
3672 vxge_debug_init(VXGE_TRACE
,
3673 "%s: %d Vpath(s) opened",
3674 vdev
->ndev
->name
, vdev
->no_of_vpath
);
3676 switch (vdev
->config
.intr_type
) {
3678 vxge_debug_init(VXGE_TRACE
,
3679 "%s: Interrupt type INTA", vdev
->ndev
->name
);
3683 vxge_debug_init(VXGE_TRACE
,
3684 "%s: Interrupt type MSI-X", vdev
->ndev
->name
);
3688 if (vdev
->config
.rth_steering
) {
3689 vxge_debug_init(VXGE_TRACE
,
3690 "%s: RTH steering enabled for TCP_IPV4",
3693 vxge_debug_init(VXGE_TRACE
,
3694 "%s: RTH steering disabled", vdev
->ndev
->name
);
3697 switch (vdev
->config
.tx_steering_type
) {
3699 vxge_debug_init(VXGE_TRACE
,
3700 "%s: Tx steering disabled", vdev
->ndev
->name
);
3702 case TX_PRIORITY_STEERING
:
3703 vxge_debug_init(VXGE_TRACE
,
3704 "%s: Unsupported tx steering option",
3706 vxge_debug_init(VXGE_TRACE
,
3707 "%s: Tx steering disabled", vdev
->ndev
->name
);
3708 vdev
->config
.tx_steering_type
= 0;
3710 case TX_VLAN_STEERING
:
3711 vxge_debug_init(VXGE_TRACE
,
3712 "%s: Unsupported tx steering option",
3714 vxge_debug_init(VXGE_TRACE
,
3715 "%s: Tx steering disabled", vdev
->ndev
->name
);
3716 vdev
->config
.tx_steering_type
= 0;
3718 case TX_MULTIQ_STEERING
:
3719 vxge_debug_init(VXGE_TRACE
,
3720 "%s: Tx multiqueue steering enabled",
3723 case TX_PORT_STEERING
:
3724 vxge_debug_init(VXGE_TRACE
,
3725 "%s: Tx port steering enabled",
3729 vxge_debug_init(VXGE_ERR
,
3730 "%s: Unsupported tx steering type",
3732 vxge_debug_init(VXGE_TRACE
,
3733 "%s: Tx steering disabled", vdev
->ndev
->name
);
3734 vdev
->config
.tx_steering_type
= 0;
3737 if (vdev
->config
.gro_enable
) {
3738 vxge_debug_init(VXGE_ERR
,
3739 "%s: Generic receive offload enabled",
3742 vxge_debug_init(VXGE_TRACE
,
3743 "%s: Generic receive offload disabled",
3746 if (vdev
->config
.addr_learn_en
)
3747 vxge_debug_init(VXGE_TRACE
,
3748 "%s: MAC Address learning enabled", vdev
->ndev
->name
);
3750 vxge_debug_init(VXGE_TRACE
,
3751 "%s: Rx doorbell mode enabled", vdev
->ndev
->name
);
3753 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3754 if (!vxge_bVALn(vpath_mask
, i
, 1))
3756 vxge_debug_ll_config(VXGE_TRACE
,
3757 "%s: MTU size - %d", vdev
->ndev
->name
,
3758 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3759 config
.vp_config
[i
].mtu
);
3760 vxge_debug_init(VXGE_TRACE
,
3761 "%s: VLAN tag stripping %s", vdev
->ndev
->name
,
3762 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3763 config
.vp_config
[i
].rpa_strip_vlan_tag
3764 ? "Enabled" : "Disabled");
3765 vxge_debug_init(VXGE_TRACE
,
3766 "%s: Ring blocks : %d", vdev
->ndev
->name
,
3767 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3768 config
.vp_config
[i
].ring
.ring_blocks
);
3769 vxge_debug_init(VXGE_TRACE
,
3770 "%s: Fifo blocks : %d", vdev
->ndev
->name
,
3771 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3772 config
.vp_config
[i
].fifo
.fifo_blocks
);
3773 vxge_debug_ll_config(VXGE_TRACE
,
3774 "%s: Max frags : %d", vdev
->ndev
->name
,
3775 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3776 config
.vp_config
[i
].fifo
.max_frags
);
3783 * vxge_pm_suspend - vxge power management suspend entry point
3786 static int vxge_pm_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3791 * vxge_pm_resume - vxge power management resume entry point
3794 static int vxge_pm_resume(struct pci_dev
*pdev
)
3802 * vxge_io_error_detected - called when PCI error is detected
3803 * @pdev: Pointer to PCI device
3804 * @state: The current pci connection state
3806 * This function is called after a PCI bus error affecting
3807 * this device has been detected.
3809 static pci_ers_result_t
vxge_io_error_detected(struct pci_dev
*pdev
,
3810 pci_channel_state_t state
)
3812 struct __vxge_hw_device
*hldev
=
3813 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3814 struct net_device
*netdev
= hldev
->ndev
;
3816 netif_device_detach(netdev
);
3818 if (state
== pci_channel_io_perm_failure
)
3819 return PCI_ERS_RESULT_DISCONNECT
;
3821 if (netif_running(netdev
)) {
3822 /* Bring down the card, while avoiding PCI I/O */
3823 do_vxge_close(netdev
, 0);
3826 pci_disable_device(pdev
);
3828 return PCI_ERS_RESULT_NEED_RESET
;
3832 * vxge_io_slot_reset - called after the pci bus has been reset.
3833 * @pdev: Pointer to PCI device
3835 * Restart the card from scratch, as if from a cold-boot.
3836 * At this point, the card has exprienced a hard reset,
3837 * followed by fixups by BIOS, and has its config space
3838 * set up identically to what it was at cold boot.
3840 static pci_ers_result_t
vxge_io_slot_reset(struct pci_dev
*pdev
)
3842 struct __vxge_hw_device
*hldev
=
3843 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3844 struct net_device
*netdev
= hldev
->ndev
;
3846 struct vxgedev
*vdev
= netdev_priv(netdev
);
3848 if (pci_enable_device(pdev
)) {
3849 netdev_err(netdev
, "Cannot re-enable device after reset\n");
3850 return PCI_ERS_RESULT_DISCONNECT
;
3853 pci_set_master(pdev
);
3856 return PCI_ERS_RESULT_RECOVERED
;
3860 * vxge_io_resume - called when traffic can start flowing again.
3861 * @pdev: Pointer to PCI device
3863 * This callback is called when the error recovery driver tells
3864 * us that its OK to resume normal operation.
3866 static void vxge_io_resume(struct pci_dev
*pdev
)
3868 struct __vxge_hw_device
*hldev
=
3869 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3870 struct net_device
*netdev
= hldev
->ndev
;
3872 if (netif_running(netdev
)) {
3873 if (vxge_open(netdev
)) {
3875 "Can't bring device back up after reset\n");
3880 netif_device_attach(netdev
);
3883 static inline u32
vxge_get_num_vfs(u64 function_mode
)
3885 u32 num_functions
= 0;
3887 switch (function_mode
) {
3888 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
3889 case VXGE_HW_FUNCTION_MODE_SRIOV_8
:
3892 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
3895 case VXGE_HW_FUNCTION_MODE_SRIOV
:
3896 case VXGE_HW_FUNCTION_MODE_MRIOV
:
3897 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17
:
3900 case VXGE_HW_FUNCTION_MODE_SRIOV_4
:
3903 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2
:
3906 case VXGE_HW_FUNCTION_MODE_MRIOV_8
:
3907 num_functions
= 8; /* TODO */
3910 return num_functions
;
3915 * @pdev : structure containing the PCI related information of the device.
3916 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
3918 * This function is called when a new PCI device gets detected and initializes
3921 * returns 0 on success and negative on failure.
3924 static int __devinit
3925 vxge_probe(struct pci_dev
*pdev
, const struct pci_device_id
*pre
)
3927 struct __vxge_hw_device
*hldev
;
3928 enum vxge_hw_status status
;
3932 struct vxgedev
*vdev
;
3933 struct vxge_config
*ll_config
= NULL
;
3934 struct vxge_hw_device_config
*device_config
= NULL
;
3935 struct vxge_hw_device_attr attr
;
3936 int i
, j
, no_of_vpath
= 0, max_vpath_supported
= 0;
3938 struct vxge_mac_addrs
*entry
;
3939 static int bus
= -1, device
= -1;
3942 enum vxge_hw_status is_privileged
;
3946 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3949 /* In SRIOV-17 mode, functions of the same adapter
3950 * can be deployed on different buses */
3951 if ((!pdev
->is_virtfn
) && ((bus
!= pdev
->bus
->number
) ||
3952 (device
!= PCI_SLOT(pdev
->devfn
))))
3955 bus
= pdev
->bus
->number
;
3956 device
= PCI_SLOT(pdev
->devfn
);
3959 if (driver_config
->config_dev_cnt
&&
3960 (driver_config
->config_dev_cnt
!=
3961 driver_config
->total_dev_cnt
))
3962 vxge_debug_init(VXGE_ERR
,
3963 "%s: Configured %d of %d devices",
3965 driver_config
->config_dev_cnt
,
3966 driver_config
->total_dev_cnt
);
3967 driver_config
->config_dev_cnt
= 0;
3968 driver_config
->total_dev_cnt
= 0;
3970 /* Now making the CPU based no of vpath calculation
3971 * applicable for individual functions as well.
3973 driver_config
->g_no_cpus
= 0;
3974 driver_config
->vpath_per_dev
= max_config_vpath
;
3976 driver_config
->total_dev_cnt
++;
3977 if (++driver_config
->config_dev_cnt
> max_config_dev
) {
3982 device_config
= kzalloc(sizeof(struct vxge_hw_device_config
),
3984 if (!device_config
) {
3986 vxge_debug_init(VXGE_ERR
,
3987 "device_config : malloc failed %s %d",
3988 __FILE__
, __LINE__
);
3992 ll_config
= kzalloc(sizeof(*ll_config
), GFP_KERNEL
);
3995 vxge_debug_init(VXGE_ERR
,
3996 "ll_config : malloc failed %s %d",
3997 __FILE__
, __LINE__
);
4000 ll_config
->tx_steering_type
= TX_MULTIQ_STEERING
;
4001 ll_config
->intr_type
= MSI_X
;
4002 ll_config
->napi_weight
= NEW_NAPI_WEIGHT
;
4003 ll_config
->rth_steering
= RTH_STEERING
;
4005 /* get the default configuration parameters */
4006 vxge_hw_device_config_default_get(device_config
);
4008 /* initialize configuration parameters */
4009 vxge_device_config_init(device_config
, &ll_config
->intr_type
);
4011 ret
= pci_enable_device(pdev
);
4013 vxge_debug_init(VXGE_ERR
,
4014 "%s : can not enable PCI device", __func__
);
4018 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))) {
4019 vxge_debug_ll_config(VXGE_TRACE
,
4020 "%s : using 64bit DMA", __func__
);
4024 if (pci_set_consistent_dma_mask(pdev
,
4025 DMA_BIT_MASK(64))) {
4026 vxge_debug_init(VXGE_ERR
,
4027 "%s : unable to obtain 64bit DMA for "
4028 "consistent allocations", __func__
);
4032 } else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
4033 vxge_debug_ll_config(VXGE_TRACE
,
4034 "%s : using 32bit DMA", __func__
);
4040 if (pci_request_regions(pdev
, VXGE_DRIVER_NAME
)) {
4041 vxge_debug_init(VXGE_ERR
,
4042 "%s : request regions failed", __func__
);
4047 pci_set_master(pdev
);
4049 attr
.bar0
= pci_ioremap_bar(pdev
, 0);
4051 vxge_debug_init(VXGE_ERR
,
4052 "%s : cannot remap io memory bar0", __func__
);
4056 vxge_debug_ll_config(VXGE_TRACE
,
4057 "pci ioremap bar0: %p:0x%llx",
4059 (unsigned long long)pci_resource_start(pdev
, 0));
4061 status
= vxge_hw_device_hw_info_get(attr
.bar0
,
4062 &ll_config
->device_hw_info
);
4063 if (status
!= VXGE_HW_OK
) {
4064 vxge_debug_init(VXGE_ERR
,
4065 "%s: Reading of hardware info failed."
4066 "Please try upgrading the firmware.", VXGE_DRIVER_NAME
);
4071 if (ll_config
->device_hw_info
.fw_version
.major
!=
4072 VXGE_DRIVER_FW_VERSION_MAJOR
) {
4073 vxge_debug_init(VXGE_ERR
,
4074 "%s: Incorrect firmware version."
4075 "Please upgrade the firmware to version 1.x.x",
4081 vpath_mask
= ll_config
->device_hw_info
.vpath_mask
;
4082 if (vpath_mask
== 0) {
4083 vxge_debug_ll_config(VXGE_TRACE
,
4084 "%s: No vpaths available in device", VXGE_DRIVER_NAME
);
4089 vxge_debug_ll_config(VXGE_TRACE
,
4090 "%s:%d Vpath mask = %llx", __func__
, __LINE__
,
4091 (unsigned long long)vpath_mask
);
4093 function_mode
= ll_config
->device_hw_info
.function_mode
;
4094 host_type
= ll_config
->device_hw_info
.host_type
;
4095 is_privileged
= __vxge_hw_device_is_privilaged(host_type
,
4096 ll_config
->device_hw_info
.func_id
);
4098 /* Check how many vpaths are available */
4099 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4100 if (!((vpath_mask
) & vxge_mBIT(i
)))
4102 max_vpath_supported
++;
4106 num_vfs
= vxge_get_num_vfs(function_mode
) - 1;
4108 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4109 if (is_sriov(function_mode
) && (max_config_dev
> 1) &&
4110 (ll_config
->intr_type
!= INTA
) &&
4111 (is_privileged
== VXGE_HW_OK
)) {
4112 ret
= pci_enable_sriov(pdev
, ((max_config_dev
- 1) < num_vfs
)
4113 ? (max_config_dev
- 1) : num_vfs
);
4115 vxge_debug_ll_config(VXGE_ERR
,
4116 "Failed in enabling SRIOV mode: %d\n", ret
);
4120 * Configure vpaths and get driver configured number of vpaths
4121 * which is less than or equal to the maximum vpaths per function.
4123 no_of_vpath
= vxge_config_vpaths(device_config
, vpath_mask
, ll_config
);
4125 vxge_debug_ll_config(VXGE_ERR
,
4126 "%s: No more vpaths to configure", VXGE_DRIVER_NAME
);
4131 /* Setting driver callbacks */
4132 attr
.uld_callbacks
.link_up
= vxge_callback_link_up
;
4133 attr
.uld_callbacks
.link_down
= vxge_callback_link_down
;
4134 attr
.uld_callbacks
.crit_err
= vxge_callback_crit_err
;
4136 status
= vxge_hw_device_initialize(&hldev
, &attr
, device_config
);
4137 if (status
!= VXGE_HW_OK
) {
4138 vxge_debug_init(VXGE_ERR
,
4139 "Failed to initialize device (%d)", status
);
4144 /* if FCS stripping is not disabled in MAC fail driver load */
4145 if (vxge_hw_vpath_strip_fcs_check(hldev
, vpath_mask
) != VXGE_HW_OK
) {
4146 vxge_debug_init(VXGE_ERR
,
4147 "%s: FCS stripping is not disabled in MAC"
4148 " failing driver load", VXGE_DRIVER_NAME
);
4153 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4155 /* set private device info */
4156 pci_set_drvdata(pdev
, hldev
);
4158 ll_config
->gro_enable
= VXGE_GRO_ALWAYS_AGGREGATE
;
4159 ll_config
->fifo_indicate_max_pkts
= VXGE_FIFO_INDICATE_MAX_PKTS
;
4160 ll_config
->addr_learn_en
= addr_learn_en
;
4161 ll_config
->rth_algorithm
= RTH_ALG_JENKINS
;
4162 ll_config
->rth_hash_type_tcpipv4
= VXGE_HW_RING_HASH_TYPE_TCP_IPV4
;
4163 ll_config
->rth_hash_type_ipv4
= VXGE_HW_RING_HASH_TYPE_NONE
;
4164 ll_config
->rth_hash_type_tcpipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4165 ll_config
->rth_hash_type_ipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4166 ll_config
->rth_hash_type_tcpipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4167 ll_config
->rth_hash_type_ipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4168 ll_config
->rth_bkt_sz
= RTH_BUCKET_SIZE
;
4169 ll_config
->tx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4170 ll_config
->rx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4172 if (vxge_device_register(hldev
, ll_config
, high_dma
, no_of_vpath
,
4178 vxge_hw_device_debug_set(hldev
, VXGE_TRACE
, VXGE_COMPONENT_LL
);
4179 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4180 vxge_hw_device_trace_level_get(hldev
));
4182 /* set private HW device info */
4183 hldev
->ndev
= vdev
->ndev
;
4184 vdev
->mtu
= VXGE_HW_DEFAULT_MTU
;
4185 vdev
->bar0
= attr
.bar0
;
4186 vdev
->max_vpath_supported
= max_vpath_supported
;
4187 vdev
->no_of_vpath
= no_of_vpath
;
4189 /* Virtual Path count */
4190 for (i
= 0, j
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4191 if (!vxge_bVALn(vpath_mask
, i
, 1))
4193 if (j
>= vdev
->no_of_vpath
)
4196 vdev
->vpaths
[j
].is_configured
= 1;
4197 vdev
->vpaths
[j
].device_id
= i
;
4198 vdev
->vpaths
[j
].ring
.driver_id
= j
;
4199 vdev
->vpaths
[j
].vdev
= vdev
;
4200 vdev
->vpaths
[j
].max_mac_addr_cnt
= max_mac_vpath
;
4201 memcpy((u8
*)vdev
->vpaths
[j
].macaddr
,
4202 ll_config
->device_hw_info
.mac_addrs
[i
],
4205 /* Initialize the mac address list header */
4206 INIT_LIST_HEAD(&vdev
->vpaths
[j
].mac_addr_list
);
4208 vdev
->vpaths
[j
].mac_addr_cnt
= 0;
4209 vdev
->vpaths
[j
].mcast_addr_cnt
= 0;
4212 vdev
->exec_mode
= VXGE_EXEC_MODE_DISABLE
;
4213 vdev
->max_config_port
= max_config_port
;
4215 vdev
->vlan_tag_strip
= vlan_tag_strip
;
4217 /* map the hashing selector table to the configured vpaths */
4218 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4219 vdev
->vpath_selector
[i
] = vpath_selector
[i
];
4221 macaddr
= (u8
*)vdev
->vpaths
[0].macaddr
;
4223 ll_config
->device_hw_info
.serial_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4224 ll_config
->device_hw_info
.product_desc
[VXGE_HW_INFO_LEN
- 1] = '\0';
4225 ll_config
->device_hw_info
.part_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4227 vxge_debug_init(VXGE_TRACE
, "%s: SERIAL NUMBER: %s",
4228 vdev
->ndev
->name
, ll_config
->device_hw_info
.serial_number
);
4230 vxge_debug_init(VXGE_TRACE
, "%s: PART NUMBER: %s",
4231 vdev
->ndev
->name
, ll_config
->device_hw_info
.part_number
);
4233 vxge_debug_init(VXGE_TRACE
, "%s: Neterion %s Server Adapter",
4234 vdev
->ndev
->name
, ll_config
->device_hw_info
.product_desc
);
4236 vxge_debug_init(VXGE_TRACE
, "%s: MAC ADDR: %pM",
4237 vdev
->ndev
->name
, macaddr
);
4239 vxge_debug_init(VXGE_TRACE
, "%s: Link Width x%d",
4240 vdev
->ndev
->name
, vxge_hw_device_link_width_get(hldev
));
4242 vxge_debug_init(VXGE_TRACE
,
4243 "%s: Firmware version : %s Date : %s", vdev
->ndev
->name
,
4244 ll_config
->device_hw_info
.fw_version
.version
,
4245 ll_config
->device_hw_info
.fw_date
.date
);
4248 switch (ll_config
->device_hw_info
.function_mode
) {
4249 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
4250 vxge_debug_init(VXGE_TRACE
,
4251 "%s: Single Function Mode Enabled", vdev
->ndev
->name
);
4253 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
4254 vxge_debug_init(VXGE_TRACE
,
4255 "%s: Multi Function Mode Enabled", vdev
->ndev
->name
);
4257 case VXGE_HW_FUNCTION_MODE_SRIOV
:
4258 vxge_debug_init(VXGE_TRACE
,
4259 "%s: Single Root IOV Mode Enabled", vdev
->ndev
->name
);
4261 case VXGE_HW_FUNCTION_MODE_MRIOV
:
4262 vxge_debug_init(VXGE_TRACE
,
4263 "%s: Multi Root IOV Mode Enabled", vdev
->ndev
->name
);
4268 vxge_print_parm(vdev
, vpath_mask
);
4270 /* Store the fw version for ethttool option */
4271 strcpy(vdev
->fw_version
, ll_config
->device_hw_info
.fw_version
.version
);
4272 memcpy(vdev
->ndev
->dev_addr
, (u8
*)vdev
->vpaths
[0].macaddr
, ETH_ALEN
);
4273 memcpy(vdev
->ndev
->perm_addr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4275 /* Copy the station mac address to the list */
4276 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4277 entry
= (struct vxge_mac_addrs
*)
4278 kzalloc(sizeof(struct vxge_mac_addrs
),
4280 if (NULL
== entry
) {
4281 vxge_debug_init(VXGE_ERR
,
4282 "%s: mac_addr_list : memory allocation failed",
4287 macaddr
= (u8
*)&entry
->macaddr
;
4288 memcpy(macaddr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4289 list_add(&entry
->item
, &vdev
->vpaths
[i
].mac_addr_list
);
4290 vdev
->vpaths
[i
].mac_addr_cnt
= 1;
4293 kfree(device_config
);
4296 * INTA is shared in multi-function mode. This is unlike the INTA
4297 * implementation in MR mode, where each VH has its own INTA message.
4298 * - INTA is masked (disabled) as long as at least one function sets
4299 * its TITAN_MASK_ALL_INT.ALARM bit.
4300 * - INTA is unmasked (enabled) when all enabled functions have cleared
4301 * their own TITAN_MASK_ALL_INT.ALARM bit.
4302 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4303 * Though this driver leaves the top level interrupts unmasked while
4304 * leaving the required module interrupt bits masked on exit, there
4305 * could be a rougue driver around that does not follow this procedure
4306 * resulting in a failure to generate interrupts. The following code is
4307 * present to prevent such a failure.
4310 if (ll_config
->device_hw_info
.function_mode
==
4311 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
)
4312 if (vdev
->config
.intr_type
== INTA
)
4313 vxge_hw_device_unmask_all(hldev
);
4315 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
4316 vdev
->ndev
->name
, __func__
, __LINE__
);
4318 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4319 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4320 vxge_hw_device_trace_level_get(hldev
));
4326 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4327 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4329 vxge_device_unregister(hldev
);
4331 pci_disable_sriov(pdev
);
4332 vxge_hw_device_terminate(hldev
);
4336 pci_release_regions(pdev
);
4338 pci_disable_device(pdev
);
4341 kfree(device_config
);
4342 driver_config
->config_dev_cnt
--;
4343 pci_set_drvdata(pdev
, NULL
);
4348 * vxge_rem_nic - Free the PCI device
4349 * @pdev: structure containing the PCI related information of the device.
4350 * Description: This function is called by the Pci subsystem to release a
4351 * PCI device and free up all resource held up by the device.
4353 static void __devexit
4354 vxge_remove(struct pci_dev
*pdev
)
4356 struct __vxge_hw_device
*hldev
;
4357 struct vxgedev
*vdev
= NULL
;
4358 struct net_device
*dev
;
4360 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4361 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4365 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
4370 vdev
= netdev_priv(dev
);
4372 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4373 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4374 level_trace
= vdev
->level_trace
;
4376 vxge_debug_entryexit(level_trace
,
4377 "%s:%d", __func__
, __LINE__
);
4379 vxge_debug_init(level_trace
,
4380 "%s : removing PCI device...", __func__
);
4381 vxge_device_unregister(hldev
);
4383 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4384 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4385 vdev
->vpaths
[i
].mcast_addr_cnt
= 0;
4386 vdev
->vpaths
[i
].mac_addr_cnt
= 0;
4389 kfree(vdev
->vpaths
);
4391 iounmap(vdev
->bar0
);
4393 pci_disable_sriov(pdev
);
4395 /* we are safe to free it now */
4398 vxge_debug_init(level_trace
,
4399 "%s:%d Device unregistered", __func__
, __LINE__
);
4401 vxge_hw_device_terminate(hldev
);
4403 pci_disable_device(pdev
);
4404 pci_release_regions(pdev
);
4405 pci_set_drvdata(pdev
, NULL
);
4406 vxge_debug_entryexit(level_trace
,
4407 "%s:%d Exiting...", __func__
, __LINE__
);
4410 static struct pci_error_handlers vxge_err_handler
= {
4411 .error_detected
= vxge_io_error_detected
,
4412 .slot_reset
= vxge_io_slot_reset
,
4413 .resume
= vxge_io_resume
,
4416 static struct pci_driver vxge_driver
= {
4417 .name
= VXGE_DRIVER_NAME
,
4418 .id_table
= vxge_id_table
,
4419 .probe
= vxge_probe
,
4420 .remove
= __devexit_p(vxge_remove
),
4422 .suspend
= vxge_pm_suspend
,
4423 .resume
= vxge_pm_resume
,
4425 .err_handler
= &vxge_err_handler
,
4433 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4434 pr_info("Driver version: %s\n", DRV_VERSION
);
4438 driver_config
= kzalloc(sizeof(struct vxge_drv_config
), GFP_KERNEL
);
4442 ret
= pci_register_driver(&vxge_driver
);
4444 if (driver_config
->config_dev_cnt
&&
4445 (driver_config
->config_dev_cnt
!= driver_config
->total_dev_cnt
))
4446 vxge_debug_init(VXGE_ERR
,
4447 "%s: Configured %d of %d devices",
4448 VXGE_DRIVER_NAME
, driver_config
->config_dev_cnt
,
4449 driver_config
->total_dev_cnt
);
4452 kfree(driver_config
);
4460 pci_unregister_driver(&vxge_driver
);
4461 kfree(driver_config
);
4463 module_init(vxge_starter
);
4464 module_exit(vxge_closer
);