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_checksum_none_assert(skb
);
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 (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_N_VID
; 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
= kcalloc(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
= kcalloc(vdev
->intr_cnt
,
2173 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
2919 * @stats: pointer to struct rtnl_link_stats64
2922 static struct rtnl_link_stats64
*
2923 vxge_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*net_stats
)
2925 struct vxgedev
*vdev
= netdev_priv(dev
);
2928 /* net_stats already zeroed by caller */
2929 for (k
= 0; k
< vdev
->no_of_vpath
; k
++) {
2930 net_stats
->rx_packets
+= vdev
->vpaths
[k
].ring
.stats
.rx_frms
;
2931 net_stats
->rx_bytes
+= vdev
->vpaths
[k
].ring
.stats
.rx_bytes
;
2932 net_stats
->rx_errors
+= vdev
->vpaths
[k
].ring
.stats
.rx_errors
;
2933 net_stats
->multicast
+= vdev
->vpaths
[k
].ring
.stats
.rx_mcast
;
2934 net_stats
->rx_dropped
+=
2935 vdev
->vpaths
[k
].ring
.stats
.rx_dropped
;
2937 net_stats
->tx_packets
+= vdev
->vpaths
[k
].fifo
.stats
.tx_frms
;
2938 net_stats
->tx_bytes
+= vdev
->vpaths
[k
].fifo
.stats
.tx_bytes
;
2939 net_stats
->tx_errors
+= vdev
->vpaths
[k
].fifo
.stats
.tx_errors
;
2947 * @dev: Device pointer.
2948 * @ifr: An IOCTL specific structure, that can contain a pointer to
2949 * a proprietary structure used to pass information to the driver.
2950 * @cmd: This is used to distinguish between the different commands that
2951 * can be passed to the IOCTL functions.
2953 * Entry point for the Ioctl.
2955 static int vxge_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
2962 * @dev: pointer to net device structure
2964 * Watchdog for transmit side.
2965 * This function is triggered if the Tx Queue is stopped
2966 * for a pre-defined amount of time when the Interface is still up.
2969 vxge_tx_watchdog(struct net_device
*dev
)
2971 struct vxgedev
*vdev
;
2973 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
2975 vdev
= (struct vxgedev
*)netdev_priv(dev
);
2977 vdev
->cric_err_event
= VXGE_HW_EVENT_RESET_START
;
2980 vxge_debug_entryexit(VXGE_TRACE
,
2981 "%s:%d Exiting...", __func__
, __LINE__
);
2985 * vxge_vlan_rx_register
2986 * @dev: net device pointer.
2989 * Vlan group registration
2992 vxge_vlan_rx_register(struct net_device
*dev
, struct vlan_group
*grp
)
2994 struct vxgedev
*vdev
;
2995 struct vxge_vpath
*vpath
;
2998 enum vxge_hw_status status
;
3001 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3003 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3005 vpath
= &vdev
->vpaths
[0];
3006 if ((NULL
== grp
) && (vpath
->is_open
)) {
3007 /* Get the first vlan */
3008 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3010 while (status
== VXGE_HW_OK
) {
3012 /* Delete this vlan from the vid table */
3013 for (vp
= 0; vp
< vdev
->no_of_vpath
; vp
++) {
3014 vpath
= &vdev
->vpaths
[vp
];
3015 if (!vpath
->is_open
)
3018 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3021 /* Get the next vlan to be deleted */
3022 vpath
= &vdev
->vpaths
[0];
3023 status
= vxge_hw_vpath_vid_get(vpath
->handle
, &vid
);
3029 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
3030 if (vdev
->vpaths
[i
].is_configured
)
3031 vdev
->vpaths
[i
].ring
.vlgrp
= grp
;
3034 vxge_debug_entryexit(VXGE_TRACE
,
3035 "%s:%d Exiting...", __func__
, __LINE__
);
3039 * vxge_vlan_rx_add_vid
3040 * @dev: net device pointer.
3043 * Add the vlan id to the devices vlan id table
3046 vxge_vlan_rx_add_vid(struct net_device
*dev
, unsigned short vid
)
3048 struct vxgedev
*vdev
;
3049 struct vxge_vpath
*vpath
;
3052 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3054 /* Add these vlan to the vid table */
3055 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3056 vpath
= &vdev
->vpaths
[vp_id
];
3057 if (!vpath
->is_open
)
3059 vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
3064 * vxge_vlan_rx_add_vid
3065 * @dev: net device pointer.
3068 * Remove the vlan id from the device's vlan id table
3071 vxge_vlan_rx_kill_vid(struct net_device
*dev
, unsigned short vid
)
3073 struct vxgedev
*vdev
;
3074 struct vxge_vpath
*vpath
;
3077 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3079 vdev
= (struct vxgedev
*)netdev_priv(dev
);
3081 vlan_group_set_device(vdev
->vlgrp
, vid
, NULL
);
3083 /* Delete this vlan from the vid table */
3084 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3085 vpath
= &vdev
->vpaths
[vp_id
];
3086 if (!vpath
->is_open
)
3088 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3090 vxge_debug_entryexit(VXGE_TRACE
,
3091 "%s:%d Exiting...", __func__
, __LINE__
);
3094 static const struct net_device_ops vxge_netdev_ops
= {
3095 .ndo_open
= vxge_open
,
3096 .ndo_stop
= vxge_close
,
3097 .ndo_get_stats64
= vxge_get_stats64
,
3098 .ndo_start_xmit
= vxge_xmit
,
3099 .ndo_validate_addr
= eth_validate_addr
,
3100 .ndo_set_multicast_list
= vxge_set_multicast
,
3102 .ndo_do_ioctl
= vxge_ioctl
,
3104 .ndo_set_mac_address
= vxge_set_mac_addr
,
3105 .ndo_change_mtu
= vxge_change_mtu
,
3106 .ndo_vlan_rx_register
= vxge_vlan_rx_register
,
3107 .ndo_vlan_rx_kill_vid
= vxge_vlan_rx_kill_vid
,
3108 .ndo_vlan_rx_add_vid
= vxge_vlan_rx_add_vid
,
3110 .ndo_tx_timeout
= vxge_tx_watchdog
,
3111 #ifdef CONFIG_NET_POLL_CONTROLLER
3112 .ndo_poll_controller
= vxge_netpoll
,
3116 int __devinit
vxge_device_register(struct __vxge_hw_device
*hldev
,
3117 struct vxge_config
*config
,
3118 int high_dma
, int no_of_vpath
,
3119 struct vxgedev
**vdev_out
)
3121 struct net_device
*ndev
;
3122 enum vxge_hw_status status
= VXGE_HW_OK
;
3123 struct vxgedev
*vdev
;
3124 int ret
= 0, no_of_queue
= 1;
3128 if (config
->tx_steering_type
)
3129 no_of_queue
= no_of_vpath
;
3131 ndev
= alloc_etherdev_mq(sizeof(struct vxgedev
),
3135 vxge_hw_device_trace_level_get(hldev
),
3136 "%s : device allocation failed", __func__
);
3141 vxge_debug_entryexit(
3142 vxge_hw_device_trace_level_get(hldev
),
3143 "%s: %s:%d Entering...",
3144 ndev
->name
, __func__
, __LINE__
);
3146 vdev
= netdev_priv(ndev
);
3147 memset(vdev
, 0, sizeof(struct vxgedev
));
3151 vdev
->pdev
= hldev
->pdev
;
3152 memcpy(&vdev
->config
, config
, sizeof(struct vxge_config
));
3153 vdev
->rx_csum
= 1; /* Enable Rx CSUM by default. */
3155 SET_NETDEV_DEV(ndev
, &vdev
->pdev
->dev
);
3157 ndev
->features
|= NETIF_F_HW_VLAN_TX
| NETIF_F_HW_VLAN_RX
|
3158 NETIF_F_HW_VLAN_FILTER
;
3159 /* Driver entry points */
3160 ndev
->irq
= vdev
->pdev
->irq
;
3161 ndev
->base_addr
= (unsigned long) hldev
->bar0
;
3163 ndev
->netdev_ops
= &vxge_netdev_ops
;
3165 ndev
->watchdog_timeo
= VXGE_LL_WATCH_DOG_TIMEOUT
;
3167 initialize_ethtool_ops(ndev
);
3169 /* Allocate memory for vpath */
3170 vdev
->vpaths
= kzalloc((sizeof(struct vxge_vpath
)) *
3171 no_of_vpath
, GFP_KERNEL
);
3172 if (!vdev
->vpaths
) {
3173 vxge_debug_init(VXGE_ERR
,
3174 "%s: vpath memory allocation failed",
3180 ndev
->features
|= NETIF_F_SG
;
3182 ndev
->features
|= NETIF_F_HW_CSUM
;
3183 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3184 "%s : checksuming enabled", __func__
);
3187 ndev
->features
|= NETIF_F_HIGHDMA
;
3188 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3189 "%s : using High DMA", __func__
);
3192 ndev
->features
|= NETIF_F_TSO
| NETIF_F_TSO6
;
3194 if (vdev
->config
.gro_enable
)
3195 ndev
->features
|= NETIF_F_GRO
;
3197 if (register_netdev(ndev
)) {
3198 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3199 "%s: %s : device registration failed!",
3200 ndev
->name
, __func__
);
3205 /* Set the factory defined MAC address initially */
3206 ndev
->addr_len
= ETH_ALEN
;
3208 /* Make Link state as off at this point, when the Link change
3209 * interrupt comes the state will be automatically changed to
3212 netif_carrier_off(ndev
);
3214 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3215 "%s: Ethernet device registered",
3220 /* Resetting the Device stats */
3221 status
= vxge_hw_mrpcim_stats_access(
3223 VXGE_HW_STATS_OP_CLEAR_ALL_STATS
,
3228 if (status
== VXGE_HW_ERR_PRIVILAGED_OPEARATION
)
3230 vxge_hw_device_trace_level_get(hldev
),
3231 "%s: device stats clear returns"
3232 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev
->name
);
3234 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev
),
3235 "%s: %s:%d Exiting...",
3236 ndev
->name
, __func__
, __LINE__
);
3240 kfree(vdev
->vpaths
);
3248 * vxge_device_unregister
3250 * This function will unregister and free network device
3253 vxge_device_unregister(struct __vxge_hw_device
*hldev
)
3255 struct vxgedev
*vdev
;
3256 struct net_device
*dev
;
3258 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3259 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3264 vdev
= netdev_priv(dev
);
3265 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3266 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3267 level_trace
= vdev
->level_trace
;
3269 vxge_debug_entryexit(level_trace
,
3270 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3272 memcpy(buf
, vdev
->ndev
->name
, IFNAMSIZ
);
3274 /* in 2.6 will call stop() if device is up */
3275 unregister_netdev(dev
);
3277 flush_scheduled_work();
3279 vxge_debug_init(level_trace
, "%s: ethernet device unregistered", buf
);
3280 vxge_debug_entryexit(level_trace
,
3281 "%s: %s:%d Exiting...", buf
, __func__
, __LINE__
);
3285 * vxge_callback_crit_err
3287 * This function is called by the alarm handler in interrupt context.
3288 * Driver must analyze it based on the event type.
3291 vxge_callback_crit_err(struct __vxge_hw_device
*hldev
,
3292 enum vxge_hw_event type
, u64 vp_id
)
3294 struct net_device
*dev
= hldev
->ndev
;
3295 struct vxgedev
*vdev
= (struct vxgedev
*)netdev_priv(dev
);
3296 struct vxge_vpath
*vpath
= NULL
;
3299 vxge_debug_entryexit(vdev
->level_trace
,
3300 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3302 /* Note: This event type should be used for device wide
3303 * indications only - Serious errors, Slot freeze and critical errors
3305 vdev
->cric_err_event
= type
;
3307 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
3308 vpath
= &vdev
->vpaths
[vpath_idx
];
3309 if (vpath
->device_id
== vp_id
)
3313 if (!test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
)) {
3314 if (type
== VXGE_HW_EVENT_SLOT_FREEZE
) {
3315 vxge_debug_init(VXGE_ERR
,
3316 "%s: Slot is frozen", vdev
->ndev
->name
);
3317 } else if (type
== VXGE_HW_EVENT_SERR
) {
3318 vxge_debug_init(VXGE_ERR
,
3319 "%s: Encountered Serious Error",
3321 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
)
3322 vxge_debug_init(VXGE_ERR
,
3323 "%s: Encountered Critical Error",
3327 if ((type
== VXGE_HW_EVENT_SERR
) ||
3328 (type
== VXGE_HW_EVENT_SLOT_FREEZE
)) {
3329 if (unlikely(vdev
->exec_mode
))
3330 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3331 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
) {
3332 vxge_hw_device_mask_all(hldev
);
3333 if (unlikely(vdev
->exec_mode
))
3334 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3335 } else if ((type
== VXGE_HW_EVENT_FIFO_ERR
) ||
3336 (type
== VXGE_HW_EVENT_VPATH_ERR
)) {
3338 if (unlikely(vdev
->exec_mode
))
3339 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3341 /* check if this vpath is already set for reset */
3342 if (!test_and_set_bit(vpath_idx
, &vdev
->vp_reset
)) {
3344 /* disable interrupts for this vpath */
3345 vxge_vpath_intr_disable(vdev
, vpath_idx
);
3347 /* stop the queue for this vpath */
3348 netif_tx_stop_queue(vpath
->fifo
.txq
);
3353 vxge_debug_entryexit(vdev
->level_trace
,
3354 "%s: %s:%d Exiting...",
3355 vdev
->ndev
->name
, __func__
, __LINE__
);
3358 static void verify_bandwidth(void)
3360 int i
, band_width
, total
= 0, equal_priority
= 0;
3362 /* 1. If user enters 0 for some fifo, give equal priority to all */
3363 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3364 if (bw_percentage
[i
] == 0) {
3370 if (!equal_priority
) {
3371 /* 2. If sum exceeds 100, give equal priority to all */
3372 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3373 if (bw_percentage
[i
] == 0xFF)
3376 total
+= bw_percentage
[i
];
3377 if (total
> VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3384 if (!equal_priority
) {
3385 /* Is all the bandwidth consumed? */
3386 if (total
< VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3387 if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
) {
3388 /* Split rest of bw equally among next VPs*/
3390 (VXGE_HW_VPATH_BANDWIDTH_MAX
- total
) /
3391 (VXGE_HW_MAX_VIRTUAL_PATHS
- i
);
3392 if (band_width
< 2) /* min of 2% */
3395 for (; i
< VXGE_HW_MAX_VIRTUAL_PATHS
;
3401 } else if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
)
3405 if (equal_priority
) {
3406 vxge_debug_init(VXGE_ERR
,
3407 "%s: Assigning equal bandwidth to all the vpaths",
3409 bw_percentage
[0] = VXGE_HW_VPATH_BANDWIDTH_MAX
/
3410 VXGE_HW_MAX_VIRTUAL_PATHS
;
3411 for (i
= 1; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3412 bw_percentage
[i
] = bw_percentage
[0];
3417 * Vpath configuration
3419 static int __devinit
vxge_config_vpaths(
3420 struct vxge_hw_device_config
*device_config
,
3421 u64 vpath_mask
, struct vxge_config
*config_param
)
3423 int i
, no_of_vpaths
= 0, default_no_vpath
= 0, temp
;
3424 u32 txdl_size
, txdl_per_memblock
;
3426 temp
= driver_config
->vpath_per_dev
;
3427 if ((driver_config
->vpath_per_dev
== VXGE_USE_DEFAULT
) &&
3428 (max_config_dev
== VXGE_MAX_CONFIG_DEV
)) {
3429 /* No more CPU. Return vpath number as zero.*/
3430 if (driver_config
->g_no_cpus
== -1)
3433 if (!driver_config
->g_no_cpus
)
3434 driver_config
->g_no_cpus
= num_online_cpus();
3436 driver_config
->vpath_per_dev
= driver_config
->g_no_cpus
>> 1;
3437 if (!driver_config
->vpath_per_dev
)
3438 driver_config
->vpath_per_dev
= 1;
3440 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3441 if (!vxge_bVALn(vpath_mask
, i
, 1))
3445 if (default_no_vpath
< driver_config
->vpath_per_dev
)
3446 driver_config
->vpath_per_dev
= default_no_vpath
;
3448 driver_config
->g_no_cpus
= driver_config
->g_no_cpus
-
3449 (driver_config
->vpath_per_dev
* 2);
3450 if (driver_config
->g_no_cpus
<= 0)
3451 driver_config
->g_no_cpus
= -1;
3454 if (driver_config
->vpath_per_dev
== 1) {
3455 vxge_debug_ll_config(VXGE_TRACE
,
3456 "%s: Disable tx and rx steering, "
3457 "as single vpath is configured", VXGE_DRIVER_NAME
);
3458 config_param
->rth_steering
= NO_STEERING
;
3459 config_param
->tx_steering_type
= NO_STEERING
;
3460 device_config
->rth_en
= 0;
3463 /* configure bandwidth */
3464 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3465 device_config
->vp_config
[i
].min_bandwidth
= bw_percentage
[i
];
3467 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3468 device_config
->vp_config
[i
].vp_id
= i
;
3469 device_config
->vp_config
[i
].mtu
= VXGE_HW_DEFAULT_MTU
;
3470 if (no_of_vpaths
< driver_config
->vpath_per_dev
) {
3471 if (!vxge_bVALn(vpath_mask
, i
, 1)) {
3472 vxge_debug_ll_config(VXGE_TRACE
,
3473 "%s: vpath: %d is not available",
3474 VXGE_DRIVER_NAME
, i
);
3477 vxge_debug_ll_config(VXGE_TRACE
,
3478 "%s: vpath: %d available",
3479 VXGE_DRIVER_NAME
, i
);
3483 vxge_debug_ll_config(VXGE_TRACE
,
3484 "%s: vpath: %d is not configured, "
3485 "max_config_vpath exceeded",
3486 VXGE_DRIVER_NAME
, i
);
3490 /* Configure Tx fifo's */
3491 device_config
->vp_config
[i
].fifo
.enable
=
3492 VXGE_HW_FIFO_ENABLE
;
3493 device_config
->vp_config
[i
].fifo
.max_frags
=
3495 device_config
->vp_config
[i
].fifo
.memblock_size
=
3496 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
;
3498 txdl_size
= device_config
->vp_config
[i
].fifo
.max_frags
*
3499 sizeof(struct vxge_hw_fifo_txd
);
3500 txdl_per_memblock
= VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
/ txdl_size
;
3502 device_config
->vp_config
[i
].fifo
.fifo_blocks
=
3503 ((VXGE_DEF_FIFO_LENGTH
- 1) / txdl_per_memblock
) + 1;
3505 device_config
->vp_config
[i
].fifo
.intr
=
3506 VXGE_HW_FIFO_QUEUE_INTR_DISABLE
;
3508 /* Configure tti properties */
3509 device_config
->vp_config
[i
].tti
.intr_enable
=
3510 VXGE_HW_TIM_INTR_ENABLE
;
3512 device_config
->vp_config
[i
].tti
.btimer_val
=
3513 (VXGE_TTI_BTIMER_VAL
* 1000) / 272;
3515 device_config
->vp_config
[i
].tti
.timer_ac_en
=
3516 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3518 /* For msi-x with napi (each vector
3519 has a handler of its own) -
3520 Set CI to OFF for all vpaths */
3521 device_config
->vp_config
[i
].tti
.timer_ci_en
=
3522 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3524 device_config
->vp_config
[i
].tti
.timer_ri_en
=
3525 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3527 device_config
->vp_config
[i
].tti
.util_sel
=
3528 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL
;
3530 device_config
->vp_config
[i
].tti
.ltimer_val
=
3531 (VXGE_TTI_LTIMER_VAL
* 1000) / 272;
3533 device_config
->vp_config
[i
].tti
.rtimer_val
=
3534 (VXGE_TTI_RTIMER_VAL
* 1000) / 272;
3536 device_config
->vp_config
[i
].tti
.urange_a
= TTI_TX_URANGE_A
;
3537 device_config
->vp_config
[i
].tti
.urange_b
= TTI_TX_URANGE_B
;
3538 device_config
->vp_config
[i
].tti
.urange_c
= TTI_TX_URANGE_C
;
3539 device_config
->vp_config
[i
].tti
.uec_a
= TTI_TX_UFC_A
;
3540 device_config
->vp_config
[i
].tti
.uec_b
= TTI_TX_UFC_B
;
3541 device_config
->vp_config
[i
].tti
.uec_c
= TTI_TX_UFC_C
;
3542 device_config
->vp_config
[i
].tti
.uec_d
= TTI_TX_UFC_D
;
3544 /* Configure Rx rings */
3545 device_config
->vp_config
[i
].ring
.enable
=
3546 VXGE_HW_RING_ENABLE
;
3548 device_config
->vp_config
[i
].ring
.ring_blocks
=
3549 VXGE_HW_DEF_RING_BLOCKS
;
3550 device_config
->vp_config
[i
].ring
.buffer_mode
=
3551 VXGE_HW_RING_RXD_BUFFER_MODE_1
;
3552 device_config
->vp_config
[i
].ring
.rxds_limit
=
3553 VXGE_HW_DEF_RING_RXDS_LIMIT
;
3554 device_config
->vp_config
[i
].ring
.scatter_mode
=
3555 VXGE_HW_RING_SCATTER_MODE_A
;
3557 /* Configure rti properties */
3558 device_config
->vp_config
[i
].rti
.intr_enable
=
3559 VXGE_HW_TIM_INTR_ENABLE
;
3561 device_config
->vp_config
[i
].rti
.btimer_val
=
3562 (VXGE_RTI_BTIMER_VAL
* 1000)/272;
3564 device_config
->vp_config
[i
].rti
.timer_ac_en
=
3565 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3567 device_config
->vp_config
[i
].rti
.timer_ci_en
=
3568 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3570 device_config
->vp_config
[i
].rti
.timer_ri_en
=
3571 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3573 device_config
->vp_config
[i
].rti
.util_sel
=
3574 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL
;
3576 device_config
->vp_config
[i
].rti
.urange_a
=
3578 device_config
->vp_config
[i
].rti
.urange_b
=
3580 device_config
->vp_config
[i
].rti
.urange_c
=
3582 device_config
->vp_config
[i
].rti
.uec_a
= RTI_RX_UFC_A
;
3583 device_config
->vp_config
[i
].rti
.uec_b
= RTI_RX_UFC_B
;
3584 device_config
->vp_config
[i
].rti
.uec_c
= RTI_RX_UFC_C
;
3585 device_config
->vp_config
[i
].rti
.uec_d
= RTI_RX_UFC_D
;
3587 device_config
->vp_config
[i
].rti
.rtimer_val
=
3588 (VXGE_RTI_RTIMER_VAL
* 1000) / 272;
3590 device_config
->vp_config
[i
].rti
.ltimer_val
=
3591 (VXGE_RTI_LTIMER_VAL
* 1000) / 272;
3593 device_config
->vp_config
[i
].rpa_strip_vlan_tag
=
3597 driver_config
->vpath_per_dev
= temp
;
3598 return no_of_vpaths
;
3601 /* initialize device configuratrions */
3602 static void __devinit
vxge_device_config_init(
3603 struct vxge_hw_device_config
*device_config
,
3606 /* Used for CQRQ/SRQ. */
3607 device_config
->dma_blockpool_initial
=
3608 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE
;
3610 device_config
->dma_blockpool_max
=
3611 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE
;
3613 if (max_mac_vpath
> VXGE_MAX_MAC_ADDR_COUNT
)
3614 max_mac_vpath
= VXGE_MAX_MAC_ADDR_COUNT
;
3616 #ifndef CONFIG_PCI_MSI
3617 vxge_debug_init(VXGE_ERR
,
3618 "%s: This Kernel does not support "
3619 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME
);
3623 /* Configure whether MSI-X or IRQL. */
3624 switch (*intr_type
) {
3626 device_config
->intr_mode
= VXGE_HW_INTR_MODE_IRQLINE
;
3630 device_config
->intr_mode
= VXGE_HW_INTR_MODE_MSIX
;
3633 /* Timer period between device poll */
3634 device_config
->device_poll_millis
= VXGE_TIMER_DELAY
;
3636 /* Configure mac based steering. */
3637 device_config
->rts_mac_en
= addr_learn_en
;
3639 /* Configure Vpaths */
3640 device_config
->rth_it_type
= VXGE_HW_RTH_IT_TYPE_MULTI_IT
;
3642 vxge_debug_ll_config(VXGE_TRACE
, "%s : Device Config Params ",
3644 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_initial : %d",
3645 device_config
->dma_blockpool_initial
);
3646 vxge_debug_ll_config(VXGE_TRACE
, "dma_blockpool_max : %d",
3647 device_config
->dma_blockpool_max
);
3648 vxge_debug_ll_config(VXGE_TRACE
, "intr_mode : %d",
3649 device_config
->intr_mode
);
3650 vxge_debug_ll_config(VXGE_TRACE
, "device_poll_millis : %d",
3651 device_config
->device_poll_millis
);
3652 vxge_debug_ll_config(VXGE_TRACE
, "rts_mac_en : %d",
3653 device_config
->rts_mac_en
);
3654 vxge_debug_ll_config(VXGE_TRACE
, "rth_en : %d",
3655 device_config
->rth_en
);
3656 vxge_debug_ll_config(VXGE_TRACE
, "rth_it_type : %d",
3657 device_config
->rth_it_type
);
3660 static void __devinit
vxge_print_parm(struct vxgedev
*vdev
, u64 vpath_mask
)
3664 vxge_debug_init(VXGE_TRACE
,
3665 "%s: %d Vpath(s) opened",
3666 vdev
->ndev
->name
, vdev
->no_of_vpath
);
3668 switch (vdev
->config
.intr_type
) {
3670 vxge_debug_init(VXGE_TRACE
,
3671 "%s: Interrupt type INTA", vdev
->ndev
->name
);
3675 vxge_debug_init(VXGE_TRACE
,
3676 "%s: Interrupt type MSI-X", vdev
->ndev
->name
);
3680 if (vdev
->config
.rth_steering
) {
3681 vxge_debug_init(VXGE_TRACE
,
3682 "%s: RTH steering enabled for TCP_IPV4",
3685 vxge_debug_init(VXGE_TRACE
,
3686 "%s: RTH steering disabled", vdev
->ndev
->name
);
3689 switch (vdev
->config
.tx_steering_type
) {
3691 vxge_debug_init(VXGE_TRACE
,
3692 "%s: Tx steering disabled", vdev
->ndev
->name
);
3694 case TX_PRIORITY_STEERING
:
3695 vxge_debug_init(VXGE_TRACE
,
3696 "%s: Unsupported tx steering option",
3698 vxge_debug_init(VXGE_TRACE
,
3699 "%s: Tx steering disabled", vdev
->ndev
->name
);
3700 vdev
->config
.tx_steering_type
= 0;
3702 case TX_VLAN_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_MULTIQ_STEERING
:
3711 vxge_debug_init(VXGE_TRACE
,
3712 "%s: Tx multiqueue steering enabled",
3715 case TX_PORT_STEERING
:
3716 vxge_debug_init(VXGE_TRACE
,
3717 "%s: Tx port steering enabled",
3721 vxge_debug_init(VXGE_ERR
,
3722 "%s: Unsupported tx steering type",
3724 vxge_debug_init(VXGE_TRACE
,
3725 "%s: Tx steering disabled", vdev
->ndev
->name
);
3726 vdev
->config
.tx_steering_type
= 0;
3729 if (vdev
->config
.gro_enable
) {
3730 vxge_debug_init(VXGE_ERR
,
3731 "%s: Generic receive offload enabled",
3734 vxge_debug_init(VXGE_TRACE
,
3735 "%s: Generic receive offload disabled",
3738 if (vdev
->config
.addr_learn_en
)
3739 vxge_debug_init(VXGE_TRACE
,
3740 "%s: MAC Address learning enabled", vdev
->ndev
->name
);
3742 vxge_debug_init(VXGE_TRACE
,
3743 "%s: Rx doorbell mode enabled", vdev
->ndev
->name
);
3745 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3746 if (!vxge_bVALn(vpath_mask
, i
, 1))
3748 vxge_debug_ll_config(VXGE_TRACE
,
3749 "%s: MTU size - %d", vdev
->ndev
->name
,
3750 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3751 config
.vp_config
[i
].mtu
);
3752 vxge_debug_init(VXGE_TRACE
,
3753 "%s: VLAN tag stripping %s", vdev
->ndev
->name
,
3754 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3755 config
.vp_config
[i
].rpa_strip_vlan_tag
3756 ? "Enabled" : "Disabled");
3757 vxge_debug_init(VXGE_TRACE
,
3758 "%s: Ring blocks : %d", vdev
->ndev
->name
,
3759 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3760 config
.vp_config
[i
].ring
.ring_blocks
);
3761 vxge_debug_init(VXGE_TRACE
,
3762 "%s: Fifo blocks : %d", vdev
->ndev
->name
,
3763 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3764 config
.vp_config
[i
].fifo
.fifo_blocks
);
3765 vxge_debug_ll_config(VXGE_TRACE
,
3766 "%s: Max frags : %d", vdev
->ndev
->name
,
3767 ((struct __vxge_hw_device
*)(vdev
->devh
))->
3768 config
.vp_config
[i
].fifo
.max_frags
);
3775 * vxge_pm_suspend - vxge power management suspend entry point
3778 static int vxge_pm_suspend(struct pci_dev
*pdev
, pm_message_t state
)
3783 * vxge_pm_resume - vxge power management resume entry point
3786 static int vxge_pm_resume(struct pci_dev
*pdev
)
3794 * vxge_io_error_detected - called when PCI error is detected
3795 * @pdev: Pointer to PCI device
3796 * @state: The current pci connection state
3798 * This function is called after a PCI bus error affecting
3799 * this device has been detected.
3801 static pci_ers_result_t
vxge_io_error_detected(struct pci_dev
*pdev
,
3802 pci_channel_state_t state
)
3804 struct __vxge_hw_device
*hldev
=
3805 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3806 struct net_device
*netdev
= hldev
->ndev
;
3808 netif_device_detach(netdev
);
3810 if (state
== pci_channel_io_perm_failure
)
3811 return PCI_ERS_RESULT_DISCONNECT
;
3813 if (netif_running(netdev
)) {
3814 /* Bring down the card, while avoiding PCI I/O */
3815 do_vxge_close(netdev
, 0);
3818 pci_disable_device(pdev
);
3820 return PCI_ERS_RESULT_NEED_RESET
;
3824 * vxge_io_slot_reset - called after the pci bus has been reset.
3825 * @pdev: Pointer to PCI device
3827 * Restart the card from scratch, as if from a cold-boot.
3828 * At this point, the card has exprienced a hard reset,
3829 * followed by fixups by BIOS, and has its config space
3830 * set up identically to what it was at cold boot.
3832 static pci_ers_result_t
vxge_io_slot_reset(struct pci_dev
*pdev
)
3834 struct __vxge_hw_device
*hldev
=
3835 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3836 struct net_device
*netdev
= hldev
->ndev
;
3838 struct vxgedev
*vdev
= netdev_priv(netdev
);
3840 if (pci_enable_device(pdev
)) {
3841 netdev_err(netdev
, "Cannot re-enable device after reset\n");
3842 return PCI_ERS_RESULT_DISCONNECT
;
3845 pci_set_master(pdev
);
3848 return PCI_ERS_RESULT_RECOVERED
;
3852 * vxge_io_resume - called when traffic can start flowing again.
3853 * @pdev: Pointer to PCI device
3855 * This callback is called when the error recovery driver tells
3856 * us that its OK to resume normal operation.
3858 static void vxge_io_resume(struct pci_dev
*pdev
)
3860 struct __vxge_hw_device
*hldev
=
3861 (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
3862 struct net_device
*netdev
= hldev
->ndev
;
3864 if (netif_running(netdev
)) {
3865 if (vxge_open(netdev
)) {
3867 "Can't bring device back up after reset\n");
3872 netif_device_attach(netdev
);
3875 static inline u32
vxge_get_num_vfs(u64 function_mode
)
3877 u32 num_functions
= 0;
3879 switch (function_mode
) {
3880 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
3881 case VXGE_HW_FUNCTION_MODE_SRIOV_8
:
3884 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
3887 case VXGE_HW_FUNCTION_MODE_SRIOV
:
3888 case VXGE_HW_FUNCTION_MODE_MRIOV
:
3889 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17
:
3892 case VXGE_HW_FUNCTION_MODE_SRIOV_4
:
3895 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2
:
3898 case VXGE_HW_FUNCTION_MODE_MRIOV_8
:
3899 num_functions
= 8; /* TODO */
3902 return num_functions
;
3907 * @pdev : structure containing the PCI related information of the device.
3908 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
3910 * This function is called when a new PCI device gets detected and initializes
3913 * returns 0 on success and negative on failure.
3916 static int __devinit
3917 vxge_probe(struct pci_dev
*pdev
, const struct pci_device_id
*pre
)
3919 struct __vxge_hw_device
*hldev
;
3920 enum vxge_hw_status status
;
3924 struct vxgedev
*vdev
;
3925 struct vxge_config
*ll_config
= NULL
;
3926 struct vxge_hw_device_config
*device_config
= NULL
;
3927 struct vxge_hw_device_attr attr
;
3928 int i
, j
, no_of_vpath
= 0, max_vpath_supported
= 0;
3930 struct vxge_mac_addrs
*entry
;
3931 static int bus
= -1, device
= -1;
3934 enum vxge_hw_status is_privileged
;
3938 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3941 /* In SRIOV-17 mode, functions of the same adapter
3942 * can be deployed on different buses */
3943 if ((!pdev
->is_virtfn
) && ((bus
!= pdev
->bus
->number
) ||
3944 (device
!= PCI_SLOT(pdev
->devfn
))))
3947 bus
= pdev
->bus
->number
;
3948 device
= PCI_SLOT(pdev
->devfn
);
3951 if (driver_config
->config_dev_cnt
&&
3952 (driver_config
->config_dev_cnt
!=
3953 driver_config
->total_dev_cnt
))
3954 vxge_debug_init(VXGE_ERR
,
3955 "%s: Configured %d of %d devices",
3957 driver_config
->config_dev_cnt
,
3958 driver_config
->total_dev_cnt
);
3959 driver_config
->config_dev_cnt
= 0;
3960 driver_config
->total_dev_cnt
= 0;
3962 /* Now making the CPU based no of vpath calculation
3963 * applicable for individual functions as well.
3965 driver_config
->g_no_cpus
= 0;
3966 driver_config
->vpath_per_dev
= max_config_vpath
;
3968 driver_config
->total_dev_cnt
++;
3969 if (++driver_config
->config_dev_cnt
> max_config_dev
) {
3974 device_config
= kzalloc(sizeof(struct vxge_hw_device_config
),
3976 if (!device_config
) {
3978 vxge_debug_init(VXGE_ERR
,
3979 "device_config : malloc failed %s %d",
3980 __FILE__
, __LINE__
);
3984 ll_config
= kzalloc(sizeof(*ll_config
), GFP_KERNEL
);
3987 vxge_debug_init(VXGE_ERR
,
3988 "ll_config : malloc failed %s %d",
3989 __FILE__
, __LINE__
);
3992 ll_config
->tx_steering_type
= TX_MULTIQ_STEERING
;
3993 ll_config
->intr_type
= MSI_X
;
3994 ll_config
->napi_weight
= NEW_NAPI_WEIGHT
;
3995 ll_config
->rth_steering
= RTH_STEERING
;
3997 /* get the default configuration parameters */
3998 vxge_hw_device_config_default_get(device_config
);
4000 /* initialize configuration parameters */
4001 vxge_device_config_init(device_config
, &ll_config
->intr_type
);
4003 ret
= pci_enable_device(pdev
);
4005 vxge_debug_init(VXGE_ERR
,
4006 "%s : can not enable PCI device", __func__
);
4010 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))) {
4011 vxge_debug_ll_config(VXGE_TRACE
,
4012 "%s : using 64bit DMA", __func__
);
4016 if (pci_set_consistent_dma_mask(pdev
,
4017 DMA_BIT_MASK(64))) {
4018 vxge_debug_init(VXGE_ERR
,
4019 "%s : unable to obtain 64bit DMA for "
4020 "consistent allocations", __func__
);
4024 } else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
4025 vxge_debug_ll_config(VXGE_TRACE
,
4026 "%s : using 32bit DMA", __func__
);
4032 if (pci_request_regions(pdev
, VXGE_DRIVER_NAME
)) {
4033 vxge_debug_init(VXGE_ERR
,
4034 "%s : request regions failed", __func__
);
4039 pci_set_master(pdev
);
4041 attr
.bar0
= pci_ioremap_bar(pdev
, 0);
4043 vxge_debug_init(VXGE_ERR
,
4044 "%s : cannot remap io memory bar0", __func__
);
4048 vxge_debug_ll_config(VXGE_TRACE
,
4049 "pci ioremap bar0: %p:0x%llx",
4051 (unsigned long long)pci_resource_start(pdev
, 0));
4053 status
= vxge_hw_device_hw_info_get(attr
.bar0
,
4054 &ll_config
->device_hw_info
);
4055 if (status
!= VXGE_HW_OK
) {
4056 vxge_debug_init(VXGE_ERR
,
4057 "%s: Reading of hardware info failed."
4058 "Please try upgrading the firmware.", VXGE_DRIVER_NAME
);
4063 if (ll_config
->device_hw_info
.fw_version
.major
!=
4064 VXGE_DRIVER_FW_VERSION_MAJOR
) {
4065 vxge_debug_init(VXGE_ERR
,
4066 "%s: Incorrect firmware version."
4067 "Please upgrade the firmware to version 1.x.x",
4073 vpath_mask
= ll_config
->device_hw_info
.vpath_mask
;
4074 if (vpath_mask
== 0) {
4075 vxge_debug_ll_config(VXGE_TRACE
,
4076 "%s: No vpaths available in device", VXGE_DRIVER_NAME
);
4081 vxge_debug_ll_config(VXGE_TRACE
,
4082 "%s:%d Vpath mask = %llx", __func__
, __LINE__
,
4083 (unsigned long long)vpath_mask
);
4085 function_mode
= ll_config
->device_hw_info
.function_mode
;
4086 host_type
= ll_config
->device_hw_info
.host_type
;
4087 is_privileged
= __vxge_hw_device_is_privilaged(host_type
,
4088 ll_config
->device_hw_info
.func_id
);
4090 /* Check how many vpaths are available */
4091 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4092 if (!((vpath_mask
) & vxge_mBIT(i
)))
4094 max_vpath_supported
++;
4098 num_vfs
= vxge_get_num_vfs(function_mode
) - 1;
4100 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4101 if (is_sriov(function_mode
) && (max_config_dev
> 1) &&
4102 (ll_config
->intr_type
!= INTA
) &&
4103 (is_privileged
== VXGE_HW_OK
)) {
4104 ret
= pci_enable_sriov(pdev
, ((max_config_dev
- 1) < num_vfs
)
4105 ? (max_config_dev
- 1) : num_vfs
);
4107 vxge_debug_ll_config(VXGE_ERR
,
4108 "Failed in enabling SRIOV mode: %d\n", ret
);
4112 * Configure vpaths and get driver configured number of vpaths
4113 * which is less than or equal to the maximum vpaths per function.
4115 no_of_vpath
= vxge_config_vpaths(device_config
, vpath_mask
, ll_config
);
4117 vxge_debug_ll_config(VXGE_ERR
,
4118 "%s: No more vpaths to configure", VXGE_DRIVER_NAME
);
4123 /* Setting driver callbacks */
4124 attr
.uld_callbacks
.link_up
= vxge_callback_link_up
;
4125 attr
.uld_callbacks
.link_down
= vxge_callback_link_down
;
4126 attr
.uld_callbacks
.crit_err
= vxge_callback_crit_err
;
4128 status
= vxge_hw_device_initialize(&hldev
, &attr
, device_config
);
4129 if (status
!= VXGE_HW_OK
) {
4130 vxge_debug_init(VXGE_ERR
,
4131 "Failed to initialize device (%d)", status
);
4136 /* if FCS stripping is not disabled in MAC fail driver load */
4137 if (vxge_hw_vpath_strip_fcs_check(hldev
, vpath_mask
) != VXGE_HW_OK
) {
4138 vxge_debug_init(VXGE_ERR
,
4139 "%s: FCS stripping is not disabled in MAC"
4140 " failing driver load", VXGE_DRIVER_NAME
);
4145 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4147 /* set private device info */
4148 pci_set_drvdata(pdev
, hldev
);
4150 ll_config
->gro_enable
= VXGE_GRO_ALWAYS_AGGREGATE
;
4151 ll_config
->fifo_indicate_max_pkts
= VXGE_FIFO_INDICATE_MAX_PKTS
;
4152 ll_config
->addr_learn_en
= addr_learn_en
;
4153 ll_config
->rth_algorithm
= RTH_ALG_JENKINS
;
4154 ll_config
->rth_hash_type_tcpipv4
= VXGE_HW_RING_HASH_TYPE_TCP_IPV4
;
4155 ll_config
->rth_hash_type_ipv4
= VXGE_HW_RING_HASH_TYPE_NONE
;
4156 ll_config
->rth_hash_type_tcpipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4157 ll_config
->rth_hash_type_ipv6
= VXGE_HW_RING_HASH_TYPE_NONE
;
4158 ll_config
->rth_hash_type_tcpipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4159 ll_config
->rth_hash_type_ipv6ex
= VXGE_HW_RING_HASH_TYPE_NONE
;
4160 ll_config
->rth_bkt_sz
= RTH_BUCKET_SIZE
;
4161 ll_config
->tx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4162 ll_config
->rx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4164 if (vxge_device_register(hldev
, ll_config
, high_dma
, no_of_vpath
,
4170 vxge_hw_device_debug_set(hldev
, VXGE_TRACE
, VXGE_COMPONENT_LL
);
4171 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4172 vxge_hw_device_trace_level_get(hldev
));
4174 /* set private HW device info */
4175 hldev
->ndev
= vdev
->ndev
;
4176 vdev
->mtu
= VXGE_HW_DEFAULT_MTU
;
4177 vdev
->bar0
= attr
.bar0
;
4178 vdev
->max_vpath_supported
= max_vpath_supported
;
4179 vdev
->no_of_vpath
= no_of_vpath
;
4181 /* Virtual Path count */
4182 for (i
= 0, j
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4183 if (!vxge_bVALn(vpath_mask
, i
, 1))
4185 if (j
>= vdev
->no_of_vpath
)
4188 vdev
->vpaths
[j
].is_configured
= 1;
4189 vdev
->vpaths
[j
].device_id
= i
;
4190 vdev
->vpaths
[j
].ring
.driver_id
= j
;
4191 vdev
->vpaths
[j
].vdev
= vdev
;
4192 vdev
->vpaths
[j
].max_mac_addr_cnt
= max_mac_vpath
;
4193 memcpy((u8
*)vdev
->vpaths
[j
].macaddr
,
4194 ll_config
->device_hw_info
.mac_addrs
[i
],
4197 /* Initialize the mac address list header */
4198 INIT_LIST_HEAD(&vdev
->vpaths
[j
].mac_addr_list
);
4200 vdev
->vpaths
[j
].mac_addr_cnt
= 0;
4201 vdev
->vpaths
[j
].mcast_addr_cnt
= 0;
4204 vdev
->exec_mode
= VXGE_EXEC_MODE_DISABLE
;
4205 vdev
->max_config_port
= max_config_port
;
4207 vdev
->vlan_tag_strip
= vlan_tag_strip
;
4209 /* map the hashing selector table to the configured vpaths */
4210 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4211 vdev
->vpath_selector
[i
] = vpath_selector
[i
];
4213 macaddr
= (u8
*)vdev
->vpaths
[0].macaddr
;
4215 ll_config
->device_hw_info
.serial_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4216 ll_config
->device_hw_info
.product_desc
[VXGE_HW_INFO_LEN
- 1] = '\0';
4217 ll_config
->device_hw_info
.part_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4219 vxge_debug_init(VXGE_TRACE
, "%s: SERIAL NUMBER: %s",
4220 vdev
->ndev
->name
, ll_config
->device_hw_info
.serial_number
);
4222 vxge_debug_init(VXGE_TRACE
, "%s: PART NUMBER: %s",
4223 vdev
->ndev
->name
, ll_config
->device_hw_info
.part_number
);
4225 vxge_debug_init(VXGE_TRACE
, "%s: Neterion %s Server Adapter",
4226 vdev
->ndev
->name
, ll_config
->device_hw_info
.product_desc
);
4228 vxge_debug_init(VXGE_TRACE
, "%s: MAC ADDR: %pM",
4229 vdev
->ndev
->name
, macaddr
);
4231 vxge_debug_init(VXGE_TRACE
, "%s: Link Width x%d",
4232 vdev
->ndev
->name
, vxge_hw_device_link_width_get(hldev
));
4234 vxge_debug_init(VXGE_TRACE
,
4235 "%s: Firmware version : %s Date : %s", vdev
->ndev
->name
,
4236 ll_config
->device_hw_info
.fw_version
.version
,
4237 ll_config
->device_hw_info
.fw_date
.date
);
4240 switch (ll_config
->device_hw_info
.function_mode
) {
4241 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
4242 vxge_debug_init(VXGE_TRACE
,
4243 "%s: Single Function Mode Enabled", vdev
->ndev
->name
);
4245 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
4246 vxge_debug_init(VXGE_TRACE
,
4247 "%s: Multi Function Mode Enabled", vdev
->ndev
->name
);
4249 case VXGE_HW_FUNCTION_MODE_SRIOV
:
4250 vxge_debug_init(VXGE_TRACE
,
4251 "%s: Single Root IOV Mode Enabled", vdev
->ndev
->name
);
4253 case VXGE_HW_FUNCTION_MODE_MRIOV
:
4254 vxge_debug_init(VXGE_TRACE
,
4255 "%s: Multi Root IOV Mode Enabled", vdev
->ndev
->name
);
4260 vxge_print_parm(vdev
, vpath_mask
);
4262 /* Store the fw version for ethttool option */
4263 strcpy(vdev
->fw_version
, ll_config
->device_hw_info
.fw_version
.version
);
4264 memcpy(vdev
->ndev
->dev_addr
, (u8
*)vdev
->vpaths
[0].macaddr
, ETH_ALEN
);
4265 memcpy(vdev
->ndev
->perm_addr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4267 /* Copy the station mac address to the list */
4268 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4269 entry
= (struct vxge_mac_addrs
*)
4270 kzalloc(sizeof(struct vxge_mac_addrs
),
4272 if (NULL
== entry
) {
4273 vxge_debug_init(VXGE_ERR
,
4274 "%s: mac_addr_list : memory allocation failed",
4279 macaddr
= (u8
*)&entry
->macaddr
;
4280 memcpy(macaddr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4281 list_add(&entry
->item
, &vdev
->vpaths
[i
].mac_addr_list
);
4282 vdev
->vpaths
[i
].mac_addr_cnt
= 1;
4285 kfree(device_config
);
4288 * INTA is shared in multi-function mode. This is unlike the INTA
4289 * implementation in MR mode, where each VH has its own INTA message.
4290 * - INTA is masked (disabled) as long as at least one function sets
4291 * its TITAN_MASK_ALL_INT.ALARM bit.
4292 * - INTA is unmasked (enabled) when all enabled functions have cleared
4293 * their own TITAN_MASK_ALL_INT.ALARM bit.
4294 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4295 * Though this driver leaves the top level interrupts unmasked while
4296 * leaving the required module interrupt bits masked on exit, there
4297 * could be a rougue driver around that does not follow this procedure
4298 * resulting in a failure to generate interrupts. The following code is
4299 * present to prevent such a failure.
4302 if (ll_config
->device_hw_info
.function_mode
==
4303 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
)
4304 if (vdev
->config
.intr_type
== INTA
)
4305 vxge_hw_device_unmask_all(hldev
);
4307 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
4308 vdev
->ndev
->name
, __func__
, __LINE__
);
4310 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4311 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4312 vxge_hw_device_trace_level_get(hldev
));
4318 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4319 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4321 vxge_device_unregister(hldev
);
4323 pci_disable_sriov(pdev
);
4324 vxge_hw_device_terminate(hldev
);
4328 pci_release_regions(pdev
);
4330 pci_disable_device(pdev
);
4333 kfree(device_config
);
4334 driver_config
->config_dev_cnt
--;
4335 pci_set_drvdata(pdev
, NULL
);
4340 * vxge_rem_nic - Free the PCI device
4341 * @pdev: structure containing the PCI related information of the device.
4342 * Description: This function is called by the Pci subsystem to release a
4343 * PCI device and free up all resource held up by the device.
4345 static void __devexit
4346 vxge_remove(struct pci_dev
*pdev
)
4348 struct __vxge_hw_device
*hldev
;
4349 struct vxgedev
*vdev
= NULL
;
4350 struct net_device
*dev
;
4352 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4353 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4357 hldev
= (struct __vxge_hw_device
*) pci_get_drvdata(pdev
);
4362 vdev
= netdev_priv(dev
);
4364 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4365 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4366 level_trace
= vdev
->level_trace
;
4368 vxge_debug_entryexit(level_trace
,
4369 "%s:%d", __func__
, __LINE__
);
4371 vxge_debug_init(level_trace
,
4372 "%s : removing PCI device...", __func__
);
4373 vxge_device_unregister(hldev
);
4375 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4376 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4377 vdev
->vpaths
[i
].mcast_addr_cnt
= 0;
4378 vdev
->vpaths
[i
].mac_addr_cnt
= 0;
4381 kfree(vdev
->vpaths
);
4383 iounmap(vdev
->bar0
);
4385 pci_disable_sriov(pdev
);
4387 /* we are safe to free it now */
4390 vxge_debug_init(level_trace
,
4391 "%s:%d Device unregistered", __func__
, __LINE__
);
4393 vxge_hw_device_terminate(hldev
);
4395 pci_disable_device(pdev
);
4396 pci_release_regions(pdev
);
4397 pci_set_drvdata(pdev
, NULL
);
4398 vxge_debug_entryexit(level_trace
,
4399 "%s:%d Exiting...", __func__
, __LINE__
);
4402 static struct pci_error_handlers vxge_err_handler
= {
4403 .error_detected
= vxge_io_error_detected
,
4404 .slot_reset
= vxge_io_slot_reset
,
4405 .resume
= vxge_io_resume
,
4408 static struct pci_driver vxge_driver
= {
4409 .name
= VXGE_DRIVER_NAME
,
4410 .id_table
= vxge_id_table
,
4411 .probe
= vxge_probe
,
4412 .remove
= __devexit_p(vxge_remove
),
4414 .suspend
= vxge_pm_suspend
,
4415 .resume
= vxge_pm_resume
,
4417 .err_handler
= &vxge_err_handler
,
4425 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4426 pr_info("Driver version: %s\n", DRV_VERSION
);
4430 driver_config
= kzalloc(sizeof(struct vxge_drv_config
), GFP_KERNEL
);
4434 ret
= pci_register_driver(&vxge_driver
);
4436 if (driver_config
->config_dev_cnt
&&
4437 (driver_config
->config_dev_cnt
!= driver_config
->total_dev_cnt
))
4438 vxge_debug_init(VXGE_ERR
,
4439 "%s: Configured %d of %d devices",
4440 VXGE_DRIVER_NAME
, driver_config
->config_dev_cnt
,
4441 driver_config
->total_dev_cnt
);
4444 kfree(driver_config
);
4452 pci_unregister_driver(&vxge_driver
);
4453 kfree(driver_config
);
4455 module_init(vxge_starter
);
4456 module_exit(vxge_closer
);