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/bitops.h>
47 #include <linux/if_vlan.h>
48 #include <linux/interrupt.h>
49 #include <linux/pci.h>
50 #include <linux/slab.h>
51 #include <linux/tcp.h>
53 #include <linux/netdevice.h>
54 #include <linux/etherdevice.h>
55 #include <linux/firmware.h>
56 #include <linux/net_tstamp.h>
57 #include <linux/prefetch.h>
58 #include <linux/module.h>
59 #include "vxge-main.h"
62 MODULE_LICENSE("Dual BSD/GPL");
63 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
64 "Virtualized Server Adapter");
66 static const struct pci_device_id vxge_id_table
[] = {
67 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_WIN
, PCI_ANY_ID
,
69 {PCI_VENDOR_ID_S2IO
, PCI_DEVICE_ID_TITAN_UNI
, PCI_ANY_ID
,
74 MODULE_DEVICE_TABLE(pci
, vxge_id_table
);
76 VXGE_MODULE_PARAM_INT(vlan_tag_strip
, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
);
77 VXGE_MODULE_PARAM_INT(addr_learn_en
, VXGE_HW_MAC_ADDR_LEARN_DEFAULT
);
78 VXGE_MODULE_PARAM_INT(max_config_port
, VXGE_MAX_CONFIG_PORT
);
79 VXGE_MODULE_PARAM_INT(max_config_vpath
, VXGE_USE_DEFAULT
);
80 VXGE_MODULE_PARAM_INT(max_mac_vpath
, VXGE_MAX_MAC_ADDR_COUNT
);
81 VXGE_MODULE_PARAM_INT(max_config_dev
, VXGE_MAX_CONFIG_DEV
);
83 static u16 vpath_selector
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
84 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
85 static unsigned int bw_percentage
[VXGE_HW_MAX_VIRTUAL_PATHS
] =
86 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS
- 1)] = 0xFF};
87 module_param_array(bw_percentage
, uint
, NULL
, 0);
89 static struct vxge_drv_config
*driver_config
;
90 static enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
);
92 static inline int is_vxge_card_up(struct vxgedev
*vdev
)
94 return test_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
97 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo
*fifo
)
99 struct sk_buff
**skb_ptr
= NULL
;
100 struct sk_buff
**temp
;
101 #define NR_SKB_COMPLETED 128
102 struct sk_buff
*completed
[NR_SKB_COMPLETED
];
109 if (__netif_tx_trylock(fifo
->txq
)) {
110 vxge_hw_vpath_poll_tx(fifo
->handle
, &skb_ptr
,
111 NR_SKB_COMPLETED
, &more
);
112 __netif_tx_unlock(fifo
->txq
);
116 for (temp
= completed
; temp
!= skb_ptr
; temp
++)
117 dev_kfree_skb_irq(*temp
);
121 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev
*vdev
)
125 /* Complete all transmits */
126 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
127 VXGE_COMPLETE_VPATH_TX(&vdev
->vpaths
[i
].fifo
);
130 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev
*vdev
)
133 struct vxge_ring
*ring
;
135 /* Complete all receives*/
136 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
137 ring
= &vdev
->vpaths
[i
].ring
;
138 vxge_hw_vpath_poll_rx(ring
->handle
);
143 * vxge_callback_link_up
145 * This function is called during interrupt context to notify link up state
148 static void vxge_callback_link_up(struct __vxge_hw_device
*hldev
)
150 struct net_device
*dev
= hldev
->ndev
;
151 struct vxgedev
*vdev
= netdev_priv(dev
);
153 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
154 vdev
->ndev
->name
, __func__
, __LINE__
);
155 netdev_notice(vdev
->ndev
, "Link Up\n");
156 vdev
->stats
.link_up
++;
158 netif_carrier_on(vdev
->ndev
);
159 netif_tx_wake_all_queues(vdev
->ndev
);
161 vxge_debug_entryexit(VXGE_TRACE
,
162 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
166 * vxge_callback_link_down
168 * This function is called during interrupt context to notify link down state
171 static void vxge_callback_link_down(struct __vxge_hw_device
*hldev
)
173 struct net_device
*dev
= hldev
->ndev
;
174 struct vxgedev
*vdev
= netdev_priv(dev
);
176 vxge_debug_entryexit(VXGE_TRACE
,
177 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
178 netdev_notice(vdev
->ndev
, "Link Down\n");
180 vdev
->stats
.link_down
++;
181 netif_carrier_off(vdev
->ndev
);
182 netif_tx_stop_all_queues(vdev
->ndev
);
184 vxge_debug_entryexit(VXGE_TRACE
,
185 "%s: %s:%d Exiting...", vdev
->ndev
->name
, __func__
, __LINE__
);
193 static struct sk_buff
*
194 vxge_rx_alloc(void *dtrh
, struct vxge_ring
*ring
, const int skb_size
)
196 struct net_device
*dev
;
198 struct vxge_rx_priv
*rx_priv
;
201 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
202 ring
->ndev
->name
, __func__
, __LINE__
);
204 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
206 /* try to allocate skb first. this one may fail */
207 skb
= netdev_alloc_skb(dev
, skb_size
+
208 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
210 vxge_debug_mem(VXGE_ERR
,
211 "%s: out of memory to allocate SKB", dev
->name
);
212 ring
->stats
.skb_alloc_fail
++;
216 vxge_debug_mem(VXGE_TRACE
,
217 "%s: %s:%d Skb : 0x%p", ring
->ndev
->name
,
218 __func__
, __LINE__
, skb
);
220 skb_reserve(skb
, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
223 rx_priv
->skb_data
= NULL
;
224 rx_priv
->data_size
= skb_size
;
225 vxge_debug_entryexit(VXGE_TRACE
,
226 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
234 static int vxge_rx_map(void *dtrh
, struct vxge_ring
*ring
)
236 struct vxge_rx_priv
*rx_priv
;
239 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
240 ring
->ndev
->name
, __func__
, __LINE__
);
241 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
243 rx_priv
->skb_data
= rx_priv
->skb
->data
;
244 dma_addr
= pci_map_single(ring
->pdev
, rx_priv
->skb_data
,
245 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
247 if (unlikely(pci_dma_mapping_error(ring
->pdev
, dma_addr
))) {
248 ring
->stats
.pci_map_fail
++;
251 vxge_debug_mem(VXGE_TRACE
,
252 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
253 ring
->ndev
->name
, __func__
, __LINE__
,
254 (unsigned long long)dma_addr
);
255 vxge_hw_ring_rxd_1b_set(dtrh
, dma_addr
, rx_priv
->data_size
);
257 rx_priv
->data_dma
= dma_addr
;
258 vxge_debug_entryexit(VXGE_TRACE
,
259 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
265 * vxge_rx_initial_replenish
266 * Allocation of RxD as an initial replenish procedure.
268 static enum vxge_hw_status
269 vxge_rx_initial_replenish(void *dtrh
, void *userdata
)
271 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
272 struct vxge_rx_priv
*rx_priv
;
274 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
275 ring
->ndev
->name
, __func__
, __LINE__
);
276 if (vxge_rx_alloc(dtrh
, ring
,
277 VXGE_LL_MAX_FRAME_SIZE(ring
->ndev
)) == NULL
)
280 if (vxge_rx_map(dtrh
, ring
)) {
281 rx_priv
= vxge_hw_ring_rxd_private_get(dtrh
);
282 dev_kfree_skb(rx_priv
->skb
);
286 vxge_debug_entryexit(VXGE_TRACE
,
287 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
293 vxge_rx_complete(struct vxge_ring
*ring
, struct sk_buff
*skb
, u16 vlan
,
294 int pkt_length
, struct vxge_hw_ring_rxd_info
*ext_info
)
297 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
298 ring
->ndev
->name
, __func__
, __LINE__
);
299 skb_record_rx_queue(skb
, ring
->driver_id
);
300 skb
->protocol
= eth_type_trans(skb
, ring
->ndev
);
302 u64_stats_update_begin(&ring
->stats
.syncp
);
303 ring
->stats
.rx_frms
++;
304 ring
->stats
.rx_bytes
+= pkt_length
;
306 if (skb
->pkt_type
== PACKET_MULTICAST
)
307 ring
->stats
.rx_mcast
++;
308 u64_stats_update_end(&ring
->stats
.syncp
);
310 vxge_debug_rx(VXGE_TRACE
,
311 "%s: %s:%d skb protocol = %d",
312 ring
->ndev
->name
, __func__
, __LINE__
, skb
->protocol
);
314 if (ext_info
->vlan
&&
315 ring
->vlan_tag_strip
== VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE
)
316 __vlan_hwaccel_put_tag(skb
, htons(ETH_P_8021Q
), ext_info
->vlan
);
317 napi_gro_receive(ring
->napi_p
, skb
);
319 vxge_debug_entryexit(VXGE_TRACE
,
320 "%s: %s:%d Exiting...", ring
->ndev
->name
, __func__
, __LINE__
);
323 static inline void vxge_re_pre_post(void *dtr
, struct vxge_ring
*ring
,
324 struct vxge_rx_priv
*rx_priv
)
326 pci_dma_sync_single_for_device(ring
->pdev
,
327 rx_priv
->data_dma
, rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
329 vxge_hw_ring_rxd_1b_set(dtr
, rx_priv
->data_dma
, rx_priv
->data_size
);
330 vxge_hw_ring_rxd_pre_post(ring
->handle
, dtr
);
333 static inline void vxge_post(int *dtr_cnt
, void **first_dtr
,
334 void *post_dtr
, struct __vxge_hw_ring
*ringh
)
336 int dtr_count
= *dtr_cnt
;
337 if ((*dtr_cnt
% VXGE_HW_RXSYNC_FREQ_CNT
) == 0) {
339 vxge_hw_ring_rxd_post_post_wmb(ringh
, *first_dtr
);
340 *first_dtr
= post_dtr
;
342 vxge_hw_ring_rxd_post_post(ringh
, post_dtr
);
344 *dtr_cnt
= dtr_count
;
350 * If the interrupt is because of a received frame or if the receive ring
351 * contains fresh as yet un-processed frames, this function is called.
353 static enum vxge_hw_status
354 vxge_rx_1b_compl(struct __vxge_hw_ring
*ringh
, void *dtr
,
355 u8 t_code
, void *userdata
)
357 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
358 struct net_device
*dev
= ring
->ndev
;
359 unsigned int dma_sizes
;
360 void *first_dtr
= NULL
;
366 struct vxge_rx_priv
*rx_priv
;
367 struct vxge_hw_ring_rxd_info ext_info
;
368 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
369 ring
->ndev
->name
, __func__
, __LINE__
);
371 if (ring
->budget
<= 0)
375 prefetch((char *)dtr
+ L1_CACHE_BYTES
);
376 rx_priv
= vxge_hw_ring_rxd_private_get(dtr
);
378 data_size
= rx_priv
->data_size
;
379 data_dma
= rx_priv
->data_dma
;
380 prefetch(rx_priv
->skb_data
);
382 vxge_debug_rx(VXGE_TRACE
,
383 "%s: %s:%d skb = 0x%p",
384 ring
->ndev
->name
, __func__
, __LINE__
, skb
);
386 vxge_hw_ring_rxd_1b_get(ringh
, dtr
, &dma_sizes
);
387 pkt_length
= dma_sizes
;
389 pkt_length
-= ETH_FCS_LEN
;
391 vxge_debug_rx(VXGE_TRACE
,
392 "%s: %s:%d Packet Length = %d",
393 ring
->ndev
->name
, __func__
, __LINE__
, pkt_length
);
395 vxge_hw_ring_rxd_1b_info_get(ringh
, dtr
, &ext_info
);
397 /* check skb validity */
400 prefetch((char *)skb
+ L1_CACHE_BYTES
);
401 if (unlikely(t_code
)) {
402 if (vxge_hw_ring_handle_tcode(ringh
, dtr
, t_code
) !=
405 ring
->stats
.rx_errors
++;
406 vxge_debug_rx(VXGE_TRACE
,
407 "%s: %s :%d Rx T_code is %d",
408 ring
->ndev
->name
, __func__
,
411 /* If the t_code is not supported and if the
412 * t_code is other than 0x5 (unparseable packet
413 * such as unknown UPV6 header), Drop it !!!
415 vxge_re_pre_post(dtr
, ring
, rx_priv
);
417 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
418 ring
->stats
.rx_dropped
++;
423 if (pkt_length
> VXGE_LL_RX_COPY_THRESHOLD
) {
424 if (vxge_rx_alloc(dtr
, ring
, data_size
) != NULL
) {
425 if (!vxge_rx_map(dtr
, ring
)) {
426 skb_put(skb
, pkt_length
);
428 pci_unmap_single(ring
->pdev
, data_dma
,
429 data_size
, PCI_DMA_FROMDEVICE
);
431 vxge_hw_ring_rxd_pre_post(ringh
, dtr
);
432 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
435 dev_kfree_skb(rx_priv
->skb
);
437 rx_priv
->data_size
= data_size
;
438 vxge_re_pre_post(dtr
, ring
, rx_priv
);
440 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
442 ring
->stats
.rx_dropped
++;
446 vxge_re_pre_post(dtr
, ring
, rx_priv
);
448 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
449 ring
->stats
.rx_dropped
++;
453 struct sk_buff
*skb_up
;
455 skb_up
= netdev_alloc_skb(dev
, pkt_length
+
456 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
457 if (skb_up
!= NULL
) {
459 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN
);
461 pci_dma_sync_single_for_cpu(ring
->pdev
,
465 vxge_debug_mem(VXGE_TRACE
,
466 "%s: %s:%d skb_up = %p",
467 ring
->ndev
->name
, __func__
,
469 memcpy(skb_up
->data
, skb
->data
, pkt_length
);
471 vxge_re_pre_post(dtr
, ring
, rx_priv
);
473 vxge_post(&dtr_cnt
, &first_dtr
, dtr
,
475 /* will netif_rx small SKB instead */
477 skb_put(skb
, pkt_length
);
479 vxge_re_pre_post(dtr
, ring
, rx_priv
);
481 vxge_post(&dtr_cnt
, &first_dtr
, dtr
, ringh
);
482 vxge_debug_rx(VXGE_ERR
,
483 "%s: vxge_rx_1b_compl: out of "
484 "memory", dev
->name
);
485 ring
->stats
.skb_alloc_fail
++;
490 if ((ext_info
.proto
& VXGE_HW_FRAME_PROTO_TCP_OR_UDP
) &&
491 !(ext_info
.proto
& VXGE_HW_FRAME_PROTO_IP_FRAG
) &&
492 (dev
->features
& NETIF_F_RXCSUM
) && /* Offload Rx side CSUM */
493 ext_info
.l3_cksum
== VXGE_HW_L3_CKSUM_OK
&&
494 ext_info
.l4_cksum
== VXGE_HW_L4_CKSUM_OK
)
495 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
497 skb_checksum_none_assert(skb
);
501 struct skb_shared_hwtstamps
*skb_hwts
;
502 u32 ns
= *(u32
*)(skb
->head
+ pkt_length
);
504 skb_hwts
= skb_hwtstamps(skb
);
505 skb_hwts
->hwtstamp
= ns_to_ktime(ns
);
508 /* rth_hash_type and rth_it_hit are non-zero regardless of
509 * whether rss is enabled. Only the rth_value is zero/non-zero
510 * if rss is disabled/enabled, so key off of that.
512 if (ext_info
.rth_value
)
513 skb_set_hash(skb
, ext_info
.rth_value
,
516 vxge_rx_complete(ring
, skb
, ext_info
.vlan
,
517 pkt_length
, &ext_info
);
520 ring
->pkts_processed
++;
524 } while (vxge_hw_ring_rxd_next_completed(ringh
, &dtr
,
525 &t_code
) == VXGE_HW_OK
);
528 vxge_hw_ring_rxd_post_post_wmb(ringh
, first_dtr
);
531 vxge_debug_entryexit(VXGE_TRACE
,
540 * If an interrupt was raised to indicate DMA complete of the Tx packet,
541 * this function is called. It identifies the last TxD whose buffer was
542 * freed and frees all skbs whose data have already DMA'ed into the NICs
545 static enum vxge_hw_status
546 vxge_xmit_compl(struct __vxge_hw_fifo
*fifo_hw
, void *dtr
,
547 enum vxge_hw_fifo_tcode t_code
, void *userdata
,
548 struct sk_buff
***skb_ptr
, int nr_skb
, int *more
)
550 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
551 struct sk_buff
*skb
, **done_skb
= *skb_ptr
;
554 vxge_debug_entryexit(VXGE_TRACE
,
555 "%s:%d Entered....", __func__
, __LINE__
);
561 struct vxge_tx_priv
*txd_priv
=
562 vxge_hw_fifo_txdl_private_get(dtr
);
565 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
566 frag
= &skb_shinfo(skb
)->frags
[0];
568 vxge_debug_tx(VXGE_TRACE
,
569 "%s: %s:%d fifo_hw = %p dtr = %p "
570 "tcode = 0x%x", fifo
->ndev
->name
, __func__
,
571 __LINE__
, fifo_hw
, dtr
, t_code
);
572 /* check skb validity */
574 vxge_debug_tx(VXGE_TRACE
,
575 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
576 fifo
->ndev
->name
, __func__
, __LINE__
,
577 skb
, txd_priv
, frg_cnt
);
578 if (unlikely(t_code
)) {
579 fifo
->stats
.tx_errors
++;
580 vxge_debug_tx(VXGE_ERR
,
581 "%s: tx: dtr %p completed due to "
582 "error t_code %01x", fifo
->ndev
->name
,
584 vxge_hw_fifo_handle_tcode(fifo_hw
, dtr
, t_code
);
587 /* for unfragmented skb */
588 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
589 skb_headlen(skb
), PCI_DMA_TODEVICE
);
591 for (j
= 0; j
< frg_cnt
; j
++) {
592 pci_unmap_page(fifo
->pdev
,
593 txd_priv
->dma_buffers
[i
++],
594 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
598 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
600 /* Updating the statistics block */
601 u64_stats_update_begin(&fifo
->stats
.syncp
);
602 fifo
->stats
.tx_frms
++;
603 fifo
->stats
.tx_bytes
+= skb
->len
;
604 u64_stats_update_end(&fifo
->stats
.syncp
);
614 if (pkt_cnt
> fifo
->indicate_max_pkts
)
617 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw
,
618 &dtr
, &t_code
) == VXGE_HW_OK
);
621 if (netif_tx_queue_stopped(fifo
->txq
))
622 netif_tx_wake_queue(fifo
->txq
);
624 vxge_debug_entryexit(VXGE_TRACE
,
625 "%s: %s:%d Exiting...",
626 fifo
->ndev
->name
, __func__
, __LINE__
);
630 /* select a vpath to transmit the packet */
631 static u32
vxge_get_vpath_no(struct vxgedev
*vdev
, struct sk_buff
*skb
)
633 u16 queue_len
, counter
= 0;
634 if (skb
->protocol
== htons(ETH_P_IP
)) {
640 if (!ip_is_fragment(ip
)) {
641 th
= (struct tcphdr
*)(((unsigned char *)ip
) +
644 queue_len
= vdev
->no_of_vpath
;
645 counter
= (ntohs(th
->source
) +
647 vdev
->vpath_selector
[queue_len
- 1];
648 if (counter
>= queue_len
)
649 counter
= queue_len
- 1;
655 static enum vxge_hw_status
vxge_search_mac_addr_in_list(
656 struct vxge_vpath
*vpath
, u64 del_mac
)
658 struct list_head
*entry
, *next
;
659 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
660 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
)
666 static int vxge_mac_list_add(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
668 struct vxge_mac_addrs
*new_mac_entry
;
669 u8
*mac_address
= NULL
;
671 if (vpath
->mac_addr_cnt
>= VXGE_MAX_LEARN_MAC_ADDR_CNT
)
674 new_mac_entry
= kzalloc(sizeof(struct vxge_mac_addrs
), GFP_ATOMIC
);
675 if (!new_mac_entry
) {
676 vxge_debug_mem(VXGE_ERR
,
677 "%s: memory allocation failed",
682 list_add(&new_mac_entry
->item
, &vpath
->mac_addr_list
);
684 /* Copy the new mac address to the list */
685 mac_address
= (u8
*)&new_mac_entry
->macaddr
;
686 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
688 new_mac_entry
->state
= mac
->state
;
689 vpath
->mac_addr_cnt
++;
691 if (is_multicast_ether_addr(mac
->macaddr
))
692 vpath
->mcast_addr_cnt
++;
697 /* Add a mac address to DA table */
698 static enum vxge_hw_status
699 vxge_add_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
701 enum vxge_hw_status status
= VXGE_HW_OK
;
702 struct vxge_vpath
*vpath
;
703 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode
;
705 if (is_multicast_ether_addr(mac
->macaddr
))
706 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
;
708 duplicate_mode
= VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE
;
710 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
711 status
= vxge_hw_vpath_mac_addr_add(vpath
->handle
, mac
->macaddr
,
712 mac
->macmask
, duplicate_mode
);
713 if (status
!= VXGE_HW_OK
) {
714 vxge_debug_init(VXGE_ERR
,
715 "DA config add entry failed for vpath:%d",
718 if (FALSE
== vxge_mac_list_add(vpath
, mac
))
724 static int vxge_learn_mac(struct vxgedev
*vdev
, u8
*mac_header
)
726 struct macInfo mac_info
;
727 u8
*mac_address
= NULL
;
728 u64 mac_addr
= 0, vpath_vector
= 0;
730 enum vxge_hw_status status
= VXGE_HW_OK
;
731 struct vxge_vpath
*vpath
= NULL
;
733 mac_address
= (u8
*)&mac_addr
;
734 memcpy(mac_address
, mac_header
, ETH_ALEN
);
736 /* Is this mac address already in the list? */
737 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
738 vpath
= &vdev
->vpaths
[vpath_idx
];
739 if (vxge_search_mac_addr_in_list(vpath
, mac_addr
))
743 memset(&mac_info
, 0, sizeof(struct macInfo
));
744 memcpy(mac_info
.macaddr
, mac_header
, ETH_ALEN
);
746 /* Any vpath has room to add mac address to its da table? */
747 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
748 vpath
= &vdev
->vpaths
[vpath_idx
];
749 if (vpath
->mac_addr_cnt
< vpath
->max_mac_addr_cnt
) {
750 /* Add this mac address to this vpath */
751 mac_info
.vpath_no
= vpath_idx
;
752 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
753 status
= vxge_add_mac_addr(vdev
, &mac_info
);
754 if (status
!= VXGE_HW_OK
)
760 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_LIST
;
762 mac_info
.vpath_no
= vpath_idx
;
763 /* Is the first vpath already selected as catch-basin ? */
764 vpath
= &vdev
->vpaths
[vpath_idx
];
765 if (vpath
->mac_addr_cnt
> vpath
->max_mac_addr_cnt
) {
766 /* Add this mac address to this vpath */
767 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
772 /* Select first vpath as catch-basin */
773 vpath_vector
= vxge_mBIT(vpath
->device_id
);
774 status
= vxge_hw_mgmt_reg_write(vpath
->vdev
->devh
,
775 vxge_hw_mgmt_reg_type_mrpcim
,
778 struct vxge_hw_mrpcim_reg
,
781 if (status
!= VXGE_HW_OK
) {
782 vxge_debug_tx(VXGE_ERR
,
783 "%s: Unable to set the vpath-%d in catch-basin mode",
784 VXGE_DRIVER_NAME
, vpath
->device_id
);
788 if (FALSE
== vxge_mac_list_add(vpath
, &mac_info
))
796 * @skb : the socket buffer containing the Tx data.
797 * @dev : device pointer.
799 * This function is the Tx entry point of the driver. Neterion NIC supports
800 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
803 vxge_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
805 struct vxge_fifo
*fifo
= NULL
;
808 struct vxgedev
*vdev
= NULL
;
809 enum vxge_hw_status status
;
810 int frg_cnt
, first_frg_len
;
812 int i
= 0, j
= 0, avail
;
814 struct vxge_tx_priv
*txdl_priv
= NULL
;
815 struct __vxge_hw_fifo
*fifo_hw
;
819 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
820 dev
->name
, __func__
, __LINE__
);
822 /* A buffer with no data will be dropped */
823 if (unlikely(skb
->len
<= 0)) {
824 vxge_debug_tx(VXGE_ERR
,
825 "%s: Buffer has no data..", dev
->name
);
826 dev_kfree_skb_any(skb
);
830 vdev
= netdev_priv(dev
);
832 if (unlikely(!is_vxge_card_up(vdev
))) {
833 vxge_debug_tx(VXGE_ERR
,
834 "%s: vdev not initialized", dev
->name
);
835 dev_kfree_skb_any(skb
);
839 if (vdev
->config
.addr_learn_en
) {
840 vpath_no
= vxge_learn_mac(vdev
, skb
->data
+ ETH_ALEN
);
841 if (vpath_no
== -EPERM
) {
842 vxge_debug_tx(VXGE_ERR
,
843 "%s: Failed to store the mac address",
845 dev_kfree_skb_any(skb
);
850 if (vdev
->config
.tx_steering_type
== TX_MULTIQ_STEERING
)
851 vpath_no
= skb_get_queue_mapping(skb
);
852 else if (vdev
->config
.tx_steering_type
== TX_PORT_STEERING
)
853 vpath_no
= vxge_get_vpath_no(vdev
, skb
);
855 vxge_debug_tx(VXGE_TRACE
, "%s: vpath_no= %d", dev
->name
, vpath_no
);
857 if (vpath_no
>= vdev
->no_of_vpath
)
860 fifo
= &vdev
->vpaths
[vpath_no
].fifo
;
861 fifo_hw
= fifo
->handle
;
863 if (netif_tx_queue_stopped(fifo
->txq
))
864 return NETDEV_TX_BUSY
;
866 avail
= vxge_hw_fifo_free_txdl_count_get(fifo_hw
);
868 vxge_debug_tx(VXGE_ERR
,
869 "%s: No free TXDs available", dev
->name
);
870 fifo
->stats
.txd_not_free
++;
874 /* Last TXD? Stop tx queue to avoid dropping packets. TX
875 * completion will resume the queue.
878 netif_tx_stop_queue(fifo
->txq
);
880 status
= vxge_hw_fifo_txdl_reserve(fifo_hw
, &dtr
, &dtr_priv
);
881 if (unlikely(status
!= VXGE_HW_OK
)) {
882 vxge_debug_tx(VXGE_ERR
,
883 "%s: Out of descriptors .", dev
->name
);
884 fifo
->stats
.txd_out_of_desc
++;
888 vxge_debug_tx(VXGE_TRACE
,
889 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
890 dev
->name
, __func__
, __LINE__
,
891 fifo_hw
, dtr
, dtr_priv
);
893 if (skb_vlan_tag_present(skb
)) {
894 u16 vlan_tag
= skb_vlan_tag_get(skb
);
895 vxge_hw_fifo_txdl_vlan_set(dtr
, vlan_tag
);
898 first_frg_len
= skb_headlen(skb
);
900 dma_pointer
= pci_map_single(fifo
->pdev
, skb
->data
, first_frg_len
,
903 if (unlikely(pci_dma_mapping_error(fifo
->pdev
, dma_pointer
))) {
904 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
905 fifo
->stats
.pci_map_fail
++;
909 txdl_priv
= vxge_hw_fifo_txdl_private_get(dtr
);
910 txdl_priv
->skb
= skb
;
911 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
913 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
914 vxge_debug_tx(VXGE_TRACE
,
915 "%s: %s:%d skb = %p txdl_priv = %p "
916 "frag_cnt = %d dma_pointer = 0x%llx", dev
->name
,
917 __func__
, __LINE__
, skb
, txdl_priv
,
918 frg_cnt
, (unsigned long long)dma_pointer
);
920 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
923 frag
= &skb_shinfo(skb
)->frags
[0];
924 for (i
= 0; i
< frg_cnt
; i
++) {
925 /* ignore 0 length fragment */
926 if (!skb_frag_size(frag
))
929 dma_pointer
= (u64
)skb_frag_dma_map(&fifo
->pdev
->dev
, frag
,
930 0, skb_frag_size(frag
),
933 if (unlikely(dma_mapping_error(&fifo
->pdev
->dev
, dma_pointer
)))
935 vxge_debug_tx(VXGE_TRACE
,
936 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
937 dev
->name
, __func__
, __LINE__
, i
,
938 (unsigned long long)dma_pointer
);
940 txdl_priv
->dma_buffers
[j
] = dma_pointer
;
941 vxge_hw_fifo_txdl_buffer_set(fifo_hw
, dtr
, j
++, dma_pointer
,
942 skb_frag_size(frag
));
946 offload_type
= vxge_offload_type(skb
);
948 if (offload_type
& (SKB_GSO_TCPV4
| SKB_GSO_TCPV6
)) {
949 int mss
= vxge_tcp_mss(skb
);
951 vxge_debug_tx(VXGE_TRACE
, "%s: %s:%d mss = %d",
952 dev
->name
, __func__
, __LINE__
, mss
);
953 vxge_hw_fifo_txdl_mss_set(dtr
, mss
);
955 vxge_assert(skb
->len
<=
956 dev
->mtu
+ VXGE_HW_MAC_HEADER_MAX_SIZE
);
962 if (skb
->ip_summed
== CHECKSUM_PARTIAL
)
963 vxge_hw_fifo_txdl_cksum_set_bits(dtr
,
964 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN
|
965 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN
|
966 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN
);
968 vxge_hw_fifo_txdl_post(fifo_hw
, dtr
);
970 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
971 dev
->name
, __func__
, __LINE__
);
975 vxge_debug_tx(VXGE_TRACE
, "%s: pci_map_page failed", dev
->name
);
978 frag
= &skb_shinfo(skb
)->frags
[0];
980 pci_unmap_single(fifo
->pdev
, txdl_priv
->dma_buffers
[j
++],
981 skb_headlen(skb
), PCI_DMA_TODEVICE
);
984 pci_unmap_page(fifo
->pdev
, txdl_priv
->dma_buffers
[j
],
985 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
989 vxge_hw_fifo_txdl_free(fifo_hw
, dtr
);
991 netif_tx_stop_queue(fifo
->txq
);
992 dev_kfree_skb_any(skb
);
1000 * Function will be called by hw function to abort all outstanding receive
1004 vxge_rx_term(void *dtrh
, enum vxge_hw_rxd_state state
, void *userdata
)
1006 struct vxge_ring
*ring
= (struct vxge_ring
*)userdata
;
1007 struct vxge_rx_priv
*rx_priv
=
1008 vxge_hw_ring_rxd_private_get(dtrh
);
1010 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
1011 ring
->ndev
->name
, __func__
, __LINE__
);
1012 if (state
!= VXGE_HW_RXD_STATE_POSTED
)
1015 pci_unmap_single(ring
->pdev
, rx_priv
->data_dma
,
1016 rx_priv
->data_size
, PCI_DMA_FROMDEVICE
);
1018 dev_kfree_skb(rx_priv
->skb
);
1019 rx_priv
->skb_data
= NULL
;
1021 vxge_debug_entryexit(VXGE_TRACE
,
1022 "%s: %s:%d Exiting...",
1023 ring
->ndev
->name
, __func__
, __LINE__
);
1029 * Function will be called to abort all outstanding tx descriptors
1032 vxge_tx_term(void *dtrh
, enum vxge_hw_txdl_state state
, void *userdata
)
1034 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)userdata
;
1036 int i
= 0, j
, frg_cnt
;
1037 struct vxge_tx_priv
*txd_priv
= vxge_hw_fifo_txdl_private_get(dtrh
);
1038 struct sk_buff
*skb
= txd_priv
->skb
;
1040 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1042 if (state
!= VXGE_HW_TXDL_STATE_POSTED
)
1045 /* check skb validity */
1047 frg_cnt
= skb_shinfo(skb
)->nr_frags
;
1048 frag
= &skb_shinfo(skb
)->frags
[0];
1050 /* for unfragmented skb */
1051 pci_unmap_single(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
1052 skb_headlen(skb
), PCI_DMA_TODEVICE
);
1054 for (j
= 0; j
< frg_cnt
; j
++) {
1055 pci_unmap_page(fifo
->pdev
, txd_priv
->dma_buffers
[i
++],
1056 skb_frag_size(frag
), PCI_DMA_TODEVICE
);
1062 vxge_debug_entryexit(VXGE_TRACE
,
1063 "%s:%d Exiting...", __func__
, __LINE__
);
1066 static int vxge_mac_list_del(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1068 struct list_head
*entry
, *next
;
1070 u8
*mac_address
= (u8
*) (&del_mac
);
1072 /* Copy the mac address to delete from the list */
1073 memcpy(mac_address
, mac
->macaddr
, ETH_ALEN
);
1075 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1076 if (((struct vxge_mac_addrs
*)entry
)->macaddr
== del_mac
) {
1078 kfree((struct vxge_mac_addrs
*)entry
);
1079 vpath
->mac_addr_cnt
--;
1081 if (is_multicast_ether_addr(mac
->macaddr
))
1082 vpath
->mcast_addr_cnt
--;
1090 /* delete a mac address from DA table */
1091 static enum vxge_hw_status
1092 vxge_del_mac_addr(struct vxgedev
*vdev
, struct macInfo
*mac
)
1094 enum vxge_hw_status status
= VXGE_HW_OK
;
1095 struct vxge_vpath
*vpath
;
1097 vpath
= &vdev
->vpaths
[mac
->vpath_no
];
1098 status
= vxge_hw_vpath_mac_addr_delete(vpath
->handle
, mac
->macaddr
,
1100 if (status
!= VXGE_HW_OK
) {
1101 vxge_debug_init(VXGE_ERR
,
1102 "DA config delete entry failed for vpath:%d",
1105 vxge_mac_list_del(vpath
, mac
);
1110 * vxge_set_multicast
1111 * @dev: pointer to the device structure
1113 * Entry point for multicast address enable/disable
1114 * This function is a driver entry point which gets called by the kernel
1115 * whenever multicast addresses must be enabled/disabled. This also gets
1116 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1117 * determine, if multicast address must be enabled or if promiscuous mode
1118 * is to be disabled etc.
1120 static void vxge_set_multicast(struct net_device
*dev
)
1122 struct netdev_hw_addr
*ha
;
1123 struct vxgedev
*vdev
;
1124 int i
, mcast_cnt
= 0;
1125 struct vxge_vpath
*vpath
;
1126 enum vxge_hw_status status
= VXGE_HW_OK
;
1127 struct macInfo mac_info
;
1129 struct vxge_mac_addrs
*mac_entry
;
1130 struct list_head
*list_head
;
1131 struct list_head
*entry
, *next
;
1132 u8
*mac_address
= NULL
;
1134 vxge_debug_entryexit(VXGE_TRACE
,
1135 "%s:%d", __func__
, __LINE__
);
1137 vdev
= netdev_priv(dev
);
1139 if (unlikely(!is_vxge_card_up(vdev
)))
1142 if ((dev
->flags
& IFF_ALLMULTI
) && (!vdev
->all_multi_flg
)) {
1143 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1144 vpath
= &vdev
->vpaths
[i
];
1145 vxge_assert(vpath
->is_open
);
1146 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
1147 if (status
!= VXGE_HW_OK
)
1148 vxge_debug_init(VXGE_ERR
, "failed to enable "
1149 "multicast, status %d", status
);
1150 vdev
->all_multi_flg
= 1;
1152 } else if (!(dev
->flags
& IFF_ALLMULTI
) && (vdev
->all_multi_flg
)) {
1153 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1154 vpath
= &vdev
->vpaths
[i
];
1155 vxge_assert(vpath
->is_open
);
1156 status
= vxge_hw_vpath_mcast_disable(vpath
->handle
);
1157 if (status
!= VXGE_HW_OK
)
1158 vxge_debug_init(VXGE_ERR
, "failed to disable "
1159 "multicast, status %d", status
);
1160 vdev
->all_multi_flg
= 0;
1165 if (!vdev
->config
.addr_learn_en
) {
1166 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1167 vpath
= &vdev
->vpaths
[i
];
1168 vxge_assert(vpath
->is_open
);
1170 if (dev
->flags
& IFF_PROMISC
)
1171 status
= vxge_hw_vpath_promisc_enable(
1174 status
= vxge_hw_vpath_promisc_disable(
1176 if (status
!= VXGE_HW_OK
)
1177 vxge_debug_init(VXGE_ERR
, "failed to %s promisc"
1178 ", status %d", dev
->flags
&IFF_PROMISC
?
1179 "enable" : "disable", status
);
1183 memset(&mac_info
, 0, sizeof(struct macInfo
));
1184 /* Update individual M_CAST address list */
1185 if ((!vdev
->all_multi_flg
) && netdev_mc_count(dev
)) {
1186 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1187 list_head
= &vdev
->vpaths
[0].mac_addr_list
;
1188 if ((netdev_mc_count(dev
) +
1189 (vdev
->vpaths
[0].mac_addr_cnt
- mcast_cnt
)) >
1190 vdev
->vpaths
[0].max_mac_addr_cnt
)
1191 goto _set_all_mcast
;
1193 /* Delete previous MC's */
1194 for (i
= 0; i
< mcast_cnt
; i
++) {
1195 list_for_each_safe(entry
, next
, list_head
) {
1196 mac_entry
= (struct vxge_mac_addrs
*)entry
;
1197 /* Copy the mac address to delete */
1198 mac_address
= (u8
*)&mac_entry
->macaddr
;
1199 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1201 if (is_multicast_ether_addr(mac_info
.macaddr
)) {
1202 for (vpath_idx
= 0; vpath_idx
<
1205 mac_info
.vpath_no
= vpath_idx
;
1206 status
= vxge_del_mac_addr(
1215 netdev_for_each_mc_addr(ha
, dev
) {
1216 memcpy(mac_info
.macaddr
, ha
->addr
, ETH_ALEN
);
1217 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1219 mac_info
.vpath_no
= vpath_idx
;
1220 mac_info
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1221 status
= vxge_add_mac_addr(vdev
, &mac_info
);
1222 if (status
!= VXGE_HW_OK
) {
1223 vxge_debug_init(VXGE_ERR
,
1224 "%s:%d Setting individual"
1225 "multicast address failed",
1226 __func__
, __LINE__
);
1227 goto _set_all_mcast
;
1234 mcast_cnt
= vdev
->vpaths
[0].mcast_addr_cnt
;
1235 /* Delete previous MC's */
1236 for (i
= 0; i
< mcast_cnt
; i
++) {
1237 list_for_each_safe(entry
, next
, list_head
) {
1238 mac_entry
= (struct vxge_mac_addrs
*)entry
;
1239 /* Copy the mac address to delete */
1240 mac_address
= (u8
*)&mac_entry
->macaddr
;
1241 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1243 if (is_multicast_ether_addr(mac_info
.macaddr
))
1247 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
;
1249 mac_info
.vpath_no
= vpath_idx
;
1250 status
= vxge_del_mac_addr(vdev
, &mac_info
);
1254 /* Enable all multicast */
1255 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1256 vpath
= &vdev
->vpaths
[i
];
1257 vxge_assert(vpath
->is_open
);
1259 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
1260 if (status
!= VXGE_HW_OK
) {
1261 vxge_debug_init(VXGE_ERR
,
1262 "%s:%d Enabling all multicasts failed",
1263 __func__
, __LINE__
);
1265 vdev
->all_multi_flg
= 1;
1267 dev
->flags
|= IFF_ALLMULTI
;
1270 vxge_debug_entryexit(VXGE_TRACE
,
1271 "%s:%d Exiting...", __func__
, __LINE__
);
1276 * @dev: pointer to the device structure
1278 * Update entry "0" (default MAC addr)
1280 static int vxge_set_mac_addr(struct net_device
*dev
, void *p
)
1282 struct sockaddr
*addr
= p
;
1283 struct vxgedev
*vdev
;
1284 enum vxge_hw_status status
= VXGE_HW_OK
;
1285 struct macInfo mac_info_new
, mac_info_old
;
1288 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1290 vdev
= netdev_priv(dev
);
1292 if (!is_valid_ether_addr(addr
->sa_data
))
1295 memset(&mac_info_new
, 0, sizeof(struct macInfo
));
1296 memset(&mac_info_old
, 0, sizeof(struct macInfo
));
1298 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d Exiting...",
1299 __func__
, __LINE__
);
1301 /* Get the old address */
1302 memcpy(mac_info_old
.macaddr
, dev
->dev_addr
, dev
->addr_len
);
1304 /* Copy the new address */
1305 memcpy(mac_info_new
.macaddr
, addr
->sa_data
, dev
->addr_len
);
1307 /* First delete the old mac address from all the vpaths
1308 as we can't specify the index while adding new mac address */
1309 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1310 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vpath_idx
];
1311 if (!vpath
->is_open
) {
1312 /* This can happen when this interface is added/removed
1313 to the bonding interface. Delete this station address
1314 from the linked list */
1315 vxge_mac_list_del(vpath
, &mac_info_old
);
1317 /* Add this new address to the linked list
1318 for later restoring */
1319 vxge_mac_list_add(vpath
, &mac_info_new
);
1323 /* Delete the station address */
1324 mac_info_old
.vpath_no
= vpath_idx
;
1325 status
= vxge_del_mac_addr(vdev
, &mac_info_old
);
1328 if (unlikely(!is_vxge_card_up(vdev
))) {
1329 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1333 /* Set this mac address to all the vpaths */
1334 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
1335 mac_info_new
.vpath_no
= vpath_idx
;
1336 mac_info_new
.state
= VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1337 status
= vxge_add_mac_addr(vdev
, &mac_info_new
);
1338 if (status
!= VXGE_HW_OK
)
1342 memcpy(dev
->dev_addr
, addr
->sa_data
, dev
->addr_len
);
1348 * vxge_vpath_intr_enable
1349 * @vdev: pointer to vdev
1350 * @vp_id: vpath for which to enable the interrupts
1352 * Enables the interrupts for the vpath
1354 static void vxge_vpath_intr_enable(struct vxgedev
*vdev
, int vp_id
)
1356 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1358 int tim_msix_id
[4] = {0, 1, 0, 0};
1359 int alarm_msix_id
= VXGE_ALARM_MSIX_ID
;
1361 vxge_hw_vpath_intr_enable(vpath
->handle
);
1363 if (vdev
->config
.intr_type
== INTA
)
1364 vxge_hw_vpath_inta_unmask_tx_rx(vpath
->handle
);
1366 vxge_hw_vpath_msix_set(vpath
->handle
, tim_msix_id
,
1369 msix_id
= vpath
->device_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1370 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
);
1371 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
+ 1);
1373 /* enable the alarm vector */
1374 msix_id
= (vpath
->handle
->vpath
->hldev
->first_vp_id
*
1375 VXGE_HW_VPATH_MSIX_ACTIVE
) + alarm_msix_id
;
1376 vxge_hw_vpath_msix_unmask(vpath
->handle
, msix_id
);
1381 * vxge_vpath_intr_disable
1382 * @vdev: pointer to vdev
1383 * @vp_id: vpath for which to disable the interrupts
1385 * Disables the interrupts for the vpath
1387 static void vxge_vpath_intr_disable(struct vxgedev
*vdev
, int vp_id
)
1389 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1390 struct __vxge_hw_device
*hldev
;
1393 hldev
= pci_get_drvdata(vdev
->pdev
);
1395 vxge_hw_vpath_wait_receive_idle(hldev
, vpath
->device_id
);
1397 vxge_hw_vpath_intr_disable(vpath
->handle
);
1399 if (vdev
->config
.intr_type
== INTA
)
1400 vxge_hw_vpath_inta_mask_tx_rx(vpath
->handle
);
1402 msix_id
= vpath
->device_id
* VXGE_HW_VPATH_MSIX_ACTIVE
;
1403 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1404 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
+ 1);
1406 /* disable the alarm vector */
1407 msix_id
= (vpath
->handle
->vpath
->hldev
->first_vp_id
*
1408 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
1409 vxge_hw_vpath_msix_mask(vpath
->handle
, msix_id
);
1413 /* list all mac addresses from DA table */
1414 static enum vxge_hw_status
1415 vxge_search_mac_addr_in_da_table(struct vxge_vpath
*vpath
, struct macInfo
*mac
)
1417 enum vxge_hw_status status
= VXGE_HW_OK
;
1418 unsigned char macmask
[ETH_ALEN
];
1419 unsigned char macaddr
[ETH_ALEN
];
1421 status
= vxge_hw_vpath_mac_addr_get(vpath
->handle
,
1423 if (status
!= VXGE_HW_OK
) {
1424 vxge_debug_init(VXGE_ERR
,
1425 "DA config list entry failed for vpath:%d",
1430 while (!ether_addr_equal(mac
->macaddr
, macaddr
)) {
1431 status
= vxge_hw_vpath_mac_addr_get_next(vpath
->handle
,
1433 if (status
!= VXGE_HW_OK
)
1440 /* Store all mac addresses from the list to the DA table */
1441 static enum vxge_hw_status
vxge_restore_vpath_mac_addr(struct vxge_vpath
*vpath
)
1443 enum vxge_hw_status status
= VXGE_HW_OK
;
1444 struct macInfo mac_info
;
1445 u8
*mac_address
= NULL
;
1446 struct list_head
*entry
, *next
;
1448 memset(&mac_info
, 0, sizeof(struct macInfo
));
1450 if (vpath
->is_open
) {
1451 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
1454 ((struct vxge_mac_addrs
*)entry
)->macaddr
;
1455 memcpy(mac_info
.macaddr
, mac_address
, ETH_ALEN
);
1456 ((struct vxge_mac_addrs
*)entry
)->state
=
1457 VXGE_LL_MAC_ADDR_IN_DA_TABLE
;
1458 /* does this mac address already exist in da table? */
1459 status
= vxge_search_mac_addr_in_da_table(vpath
,
1461 if (status
!= VXGE_HW_OK
) {
1462 /* Add this mac address to the DA table */
1463 status
= vxge_hw_vpath_mac_addr_add(
1464 vpath
->handle
, mac_info
.macaddr
,
1466 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE
);
1467 if (status
!= VXGE_HW_OK
) {
1468 vxge_debug_init(VXGE_ERR
,
1469 "DA add entry failed for vpath:%d",
1471 ((struct vxge_mac_addrs
*)entry
)->state
1472 = VXGE_LL_MAC_ADDR_IN_LIST
;
1481 /* Store all vlan ids from the list to the vid table */
1482 static enum vxge_hw_status
1483 vxge_restore_vpath_vid_table(struct vxge_vpath
*vpath
)
1485 enum vxge_hw_status status
= VXGE_HW_OK
;
1486 struct vxgedev
*vdev
= vpath
->vdev
;
1489 if (!vpath
->is_open
)
1492 for_each_set_bit(vid
, vdev
->active_vlans
, VLAN_N_VID
)
1493 status
= vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
1500 * @vdev: pointer to vdev
1501 * @vp_id: vpath to reset
1505 static int vxge_reset_vpath(struct vxgedev
*vdev
, int vp_id
)
1507 enum vxge_hw_status status
= VXGE_HW_OK
;
1508 struct vxge_vpath
*vpath
= &vdev
->vpaths
[vp_id
];
1511 /* check if device is down already */
1512 if (unlikely(!is_vxge_card_up(vdev
)))
1515 /* is device reset already scheduled */
1516 if (test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1519 if (vpath
->handle
) {
1520 if (vxge_hw_vpath_reset(vpath
->handle
) == VXGE_HW_OK
) {
1521 if (is_vxge_card_up(vdev
) &&
1522 vxge_hw_vpath_recover_from_reset(vpath
->handle
)
1524 vxge_debug_init(VXGE_ERR
,
1525 "vxge_hw_vpath_recover_from_reset"
1526 "failed for vpath:%d", vp_id
);
1530 vxge_debug_init(VXGE_ERR
,
1531 "vxge_hw_vpath_reset failed for"
1536 return VXGE_HW_FAIL
;
1538 vxge_restore_vpath_mac_addr(vpath
);
1539 vxge_restore_vpath_vid_table(vpath
);
1541 /* Enable all broadcast */
1542 vxge_hw_vpath_bcast_enable(vpath
->handle
);
1544 /* Enable all multicast */
1545 if (vdev
->all_multi_flg
) {
1546 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
1547 if (status
!= VXGE_HW_OK
)
1548 vxge_debug_init(VXGE_ERR
,
1549 "%s:%d Enabling multicast failed",
1550 __func__
, __LINE__
);
1553 /* Enable the interrupts */
1554 vxge_vpath_intr_enable(vdev
, vp_id
);
1558 /* Enable the flow of traffic through the vpath */
1559 vxge_hw_vpath_enable(vpath
->handle
);
1562 vxge_hw_vpath_rx_doorbell_init(vpath
->handle
);
1563 vpath
->ring
.last_status
= VXGE_HW_OK
;
1565 /* Vpath reset done */
1566 clear_bit(vp_id
, &vdev
->vp_reset
);
1568 /* Start the vpath queue */
1569 if (netif_tx_queue_stopped(vpath
->fifo
.txq
))
1570 netif_tx_wake_queue(vpath
->fifo
.txq
);
1576 static void vxge_config_ci_for_tti_rti(struct vxgedev
*vdev
)
1580 /* Enable CI for RTI */
1581 if (vdev
->config
.intr_type
== MSI_X
) {
1582 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1583 struct __vxge_hw_ring
*hw_ring
;
1585 hw_ring
= vdev
->vpaths
[i
].ring
.handle
;
1586 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring
);
1590 /* Enable CI for TTI */
1591 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1592 struct __vxge_hw_fifo
*hw_fifo
= vdev
->vpaths
[i
].fifo
.handle
;
1593 vxge_hw_vpath_tti_ci_set(hw_fifo
);
1595 * For Inta (with or without napi), Set CI ON for only one
1596 * vpath. (Have only one free running timer).
1598 if ((vdev
->config
.intr_type
== INTA
) && (i
== 0))
1605 static int do_vxge_reset(struct vxgedev
*vdev
, int event
)
1607 enum vxge_hw_status status
;
1608 int ret
= 0, vp_id
, i
;
1610 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1612 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
)) {
1613 /* check if device is down already */
1614 if (unlikely(!is_vxge_card_up(vdev
)))
1617 /* is reset already scheduled */
1618 if (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
1622 if (event
== VXGE_LL_FULL_RESET
) {
1623 netif_carrier_off(vdev
->ndev
);
1625 /* wait for all the vpath reset to complete */
1626 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1627 while (test_bit(vp_id
, &vdev
->vp_reset
))
1631 netif_carrier_on(vdev
->ndev
);
1633 /* if execution mode is set to debug, don't reset the adapter */
1634 if (unlikely(vdev
->exec_mode
)) {
1635 vxge_debug_init(VXGE_ERR
,
1636 "%s: execution mode is debug, returning..",
1638 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1639 netif_tx_stop_all_queues(vdev
->ndev
);
1644 if (event
== VXGE_LL_FULL_RESET
) {
1645 vxge_hw_device_wait_receive_idle(vdev
->devh
);
1646 vxge_hw_device_intr_disable(vdev
->devh
);
1648 switch (vdev
->cric_err_event
) {
1649 case VXGE_HW_EVENT_UNKNOWN
:
1650 netif_tx_stop_all_queues(vdev
->ndev
);
1651 vxge_debug_init(VXGE_ERR
,
1652 "fatal: %s: Disabling device due to"
1657 case VXGE_HW_EVENT_RESET_START
:
1659 case VXGE_HW_EVENT_RESET_COMPLETE
:
1660 case VXGE_HW_EVENT_LINK_DOWN
:
1661 case VXGE_HW_EVENT_LINK_UP
:
1662 case VXGE_HW_EVENT_ALARM_CLEARED
:
1663 case VXGE_HW_EVENT_ECCERR
:
1664 case VXGE_HW_EVENT_MRPCIM_ECCERR
:
1667 case VXGE_HW_EVENT_FIFO_ERR
:
1668 case VXGE_HW_EVENT_VPATH_ERR
:
1670 case VXGE_HW_EVENT_CRITICAL_ERR
:
1671 netif_tx_stop_all_queues(vdev
->ndev
);
1672 vxge_debug_init(VXGE_ERR
,
1673 "fatal: %s: Disabling device due to"
1676 /* SOP or device reset required */
1677 /* This event is not currently used */
1680 case VXGE_HW_EVENT_SERR
:
1681 netif_tx_stop_all_queues(vdev
->ndev
);
1682 vxge_debug_init(VXGE_ERR
,
1683 "fatal: %s: Disabling device due to"
1688 case VXGE_HW_EVENT_SRPCIM_SERR
:
1689 case VXGE_HW_EVENT_MRPCIM_SERR
:
1692 case VXGE_HW_EVENT_SLOT_FREEZE
:
1693 netif_tx_stop_all_queues(vdev
->ndev
);
1694 vxge_debug_init(VXGE_ERR
,
1695 "fatal: %s: Disabling device due to"
1706 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_START_RESET
))
1707 netif_tx_stop_all_queues(vdev
->ndev
);
1709 if (event
== VXGE_LL_FULL_RESET
) {
1710 status
= vxge_reset_all_vpaths(vdev
);
1711 if (status
!= VXGE_HW_OK
) {
1712 vxge_debug_init(VXGE_ERR
,
1713 "fatal: %s: can not reset vpaths",
1720 if (event
== VXGE_LL_COMPL_RESET
) {
1721 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1722 if (vdev
->vpaths
[i
].handle
) {
1723 if (vxge_hw_vpath_recover_from_reset(
1724 vdev
->vpaths
[i
].handle
)
1726 vxge_debug_init(VXGE_ERR
,
1727 "vxge_hw_vpath_recover_"
1728 "from_reset failed for vpath: "
1734 vxge_debug_init(VXGE_ERR
,
1735 "vxge_hw_vpath_reset failed for "
1742 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
)) {
1743 /* Reprogram the DA table with populated mac addresses */
1744 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
1745 vxge_restore_vpath_mac_addr(&vdev
->vpaths
[vp_id
]);
1746 vxge_restore_vpath_vid_table(&vdev
->vpaths
[vp_id
]);
1749 /* enable vpath interrupts */
1750 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
1751 vxge_vpath_intr_enable(vdev
, i
);
1753 vxge_hw_device_intr_enable(vdev
->devh
);
1757 /* Indicate card up */
1758 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
1760 /* Get the traffic to flow through the vpaths */
1761 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1762 vxge_hw_vpath_enable(vdev
->vpaths
[i
].handle
);
1764 vxge_hw_vpath_rx_doorbell_init(vdev
->vpaths
[i
].handle
);
1767 netif_tx_wake_all_queues(vdev
->ndev
);
1771 vxge_config_ci_for_tti_rti(vdev
);
1774 vxge_debug_entryexit(VXGE_TRACE
,
1775 "%s:%d Exiting...", __func__
, __LINE__
);
1777 /* Indicate reset done */
1778 if ((event
== VXGE_LL_FULL_RESET
) || (event
== VXGE_LL_COMPL_RESET
))
1779 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
1785 * @vdev: pointer to ll device
1787 * driver may reset the chip on events of serr, eccerr, etc
1789 static void vxge_reset(struct work_struct
*work
)
1791 struct vxgedev
*vdev
= container_of(work
, struct vxgedev
, reset_task
);
1793 if (!netif_running(vdev
->ndev
))
1796 do_vxge_reset(vdev
, VXGE_LL_FULL_RESET
);
1800 * vxge_poll - Receive handler when Receive Polling is used.
1801 * @dev: pointer to the device structure.
1802 * @budget: Number of packets budgeted to be processed in this iteration.
1804 * This function comes into picture only if Receive side is being handled
1805 * through polling (called NAPI in linux). It mostly does what the normal
1806 * Rx interrupt handler does in terms of descriptor and packet processing
1807 * but not in an interrupt context. Also it will process a specified number
1808 * of packets at most in one iteration. This value is passed down by the
1809 * kernel as the function argument 'budget'.
1811 static int vxge_poll_msix(struct napi_struct
*napi
, int budget
)
1813 struct vxge_ring
*ring
= container_of(napi
, struct vxge_ring
, napi
);
1815 int budget_org
= budget
;
1817 ring
->budget
= budget
;
1818 ring
->pkts_processed
= 0;
1819 vxge_hw_vpath_poll_rx(ring
->handle
);
1820 pkts_processed
= ring
->pkts_processed
;
1822 if (pkts_processed
< budget_org
) {
1823 napi_complete_done(napi
, pkts_processed
);
1825 /* Re enable the Rx interrupts for the vpath */
1826 vxge_hw_channel_msix_unmask(
1827 (struct __vxge_hw_channel
*)ring
->handle
,
1828 ring
->rx_vector_no
);
1832 /* We are copying and returning the local variable, in case if after
1833 * clearing the msix interrupt above, if the interrupt fires right
1834 * away which can preempt this NAPI thread */
1835 return pkts_processed
;
1838 static int vxge_poll_inta(struct napi_struct
*napi
, int budget
)
1840 struct vxgedev
*vdev
= container_of(napi
, struct vxgedev
, napi
);
1841 int pkts_processed
= 0;
1843 int budget_org
= budget
;
1844 struct vxge_ring
*ring
;
1846 struct __vxge_hw_device
*hldev
= pci_get_drvdata(vdev
->pdev
);
1848 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1849 ring
= &vdev
->vpaths
[i
].ring
;
1850 ring
->budget
= budget
;
1851 ring
->pkts_processed
= 0;
1852 vxge_hw_vpath_poll_rx(ring
->handle
);
1853 pkts_processed
+= ring
->pkts_processed
;
1854 budget
-= ring
->pkts_processed
;
1859 VXGE_COMPLETE_ALL_TX(vdev
);
1861 if (pkts_processed
< budget_org
) {
1862 napi_complete_done(napi
, pkts_processed
);
1863 /* Re enable the Rx interrupts for the ring */
1864 vxge_hw_device_unmask_all(hldev
);
1865 vxge_hw_device_flush_io(hldev
);
1868 return pkts_processed
;
1871 #ifdef CONFIG_NET_POLL_CONTROLLER
1873 * vxge_netpoll - netpoll event handler entry point
1874 * @dev : pointer to the device structure.
1876 * This function will be called by upper layer to check for events on the
1877 * interface in situations where interrupts are disabled. It is used for
1878 * specific in-kernel networking tasks, such as remote consoles and kernel
1879 * debugging over the network (example netdump in RedHat).
1881 static void vxge_netpoll(struct net_device
*dev
)
1883 struct vxgedev
*vdev
= netdev_priv(dev
);
1884 struct pci_dev
*pdev
= vdev
->pdev
;
1885 struct __vxge_hw_device
*hldev
= pci_get_drvdata(pdev
);
1886 const int irq
= pdev
->irq
;
1888 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
1890 if (pci_channel_offline(pdev
))
1894 vxge_hw_device_clear_tx_rx(hldev
);
1896 vxge_hw_device_clear_tx_rx(hldev
);
1897 VXGE_COMPLETE_ALL_RX(vdev
);
1898 VXGE_COMPLETE_ALL_TX(vdev
);
1902 vxge_debug_entryexit(VXGE_TRACE
,
1903 "%s:%d Exiting...", __func__
, __LINE__
);
1907 /* RTH configuration */
1908 static enum vxge_hw_status
vxge_rth_configure(struct vxgedev
*vdev
)
1910 enum vxge_hw_status status
= VXGE_HW_OK
;
1911 struct vxge_hw_rth_hash_types hash_types
;
1912 u8 itable
[256] = {0}; /* indirection table */
1913 u8 mtable
[256] = {0}; /* CPU to vpath mapping */
1918 * - itable with bucket numbers
1919 * - mtable with bucket-to-vpath mapping
1921 for (index
= 0; index
< (1 << vdev
->config
.rth_bkt_sz
); index
++) {
1922 itable
[index
] = index
;
1923 mtable
[index
] = index
% vdev
->no_of_vpath
;
1926 /* set indirection table, bucket-to-vpath mapping */
1927 status
= vxge_hw_vpath_rts_rth_itable_set(vdev
->vp_handles
,
1930 vdev
->config
.rth_bkt_sz
);
1931 if (status
!= VXGE_HW_OK
) {
1932 vxge_debug_init(VXGE_ERR
,
1933 "RTH indirection table configuration failed "
1934 "for vpath:%d", vdev
->vpaths
[0].device_id
);
1938 /* Fill RTH hash types */
1939 hash_types
.hash_type_tcpipv4_en
= vdev
->config
.rth_hash_type_tcpipv4
;
1940 hash_types
.hash_type_ipv4_en
= vdev
->config
.rth_hash_type_ipv4
;
1941 hash_types
.hash_type_tcpipv6_en
= vdev
->config
.rth_hash_type_tcpipv6
;
1942 hash_types
.hash_type_ipv6_en
= vdev
->config
.rth_hash_type_ipv6
;
1943 hash_types
.hash_type_tcpipv6ex_en
=
1944 vdev
->config
.rth_hash_type_tcpipv6ex
;
1945 hash_types
.hash_type_ipv6ex_en
= vdev
->config
.rth_hash_type_ipv6ex
;
1948 * Because the itable_set() method uses the active_table field
1949 * for the target virtual path the RTH config should be updated
1950 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1951 * when steering frames.
1953 for (index
= 0; index
< vdev
->no_of_vpath
; index
++) {
1954 status
= vxge_hw_vpath_rts_rth_set(
1955 vdev
->vpaths
[index
].handle
,
1956 vdev
->config
.rth_algorithm
,
1958 vdev
->config
.rth_bkt_sz
);
1959 if (status
!= VXGE_HW_OK
) {
1960 vxge_debug_init(VXGE_ERR
,
1961 "RTH configuration failed for vpath:%d",
1962 vdev
->vpaths
[index
].device_id
);
1971 static enum vxge_hw_status
vxge_reset_all_vpaths(struct vxgedev
*vdev
)
1973 enum vxge_hw_status status
= VXGE_HW_OK
;
1974 struct vxge_vpath
*vpath
;
1977 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
1978 vpath
= &vdev
->vpaths
[i
];
1979 if (vpath
->handle
) {
1980 if (vxge_hw_vpath_reset(vpath
->handle
) == VXGE_HW_OK
) {
1981 if (is_vxge_card_up(vdev
) &&
1982 vxge_hw_vpath_recover_from_reset(
1983 vpath
->handle
) != VXGE_HW_OK
) {
1984 vxge_debug_init(VXGE_ERR
,
1985 "vxge_hw_vpath_recover_"
1986 "from_reset failed for vpath: "
1991 vxge_debug_init(VXGE_ERR
,
1992 "vxge_hw_vpath_reset failed for "
2003 static void vxge_close_vpaths(struct vxgedev
*vdev
, int index
)
2005 struct vxge_vpath
*vpath
;
2008 for (i
= index
; i
< vdev
->no_of_vpath
; i
++) {
2009 vpath
= &vdev
->vpaths
[i
];
2011 if (vpath
->handle
&& vpath
->is_open
) {
2012 vxge_hw_vpath_close(vpath
->handle
);
2013 vdev
->stats
.vpaths_open
--;
2016 vpath
->handle
= NULL
;
2021 static int vxge_open_vpaths(struct vxgedev
*vdev
)
2023 struct vxge_hw_vpath_attr attr
;
2024 enum vxge_hw_status status
;
2025 struct vxge_vpath
*vpath
;
2029 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2030 vpath
= &vdev
->vpaths
[i
];
2031 vxge_assert(vpath
->is_configured
);
2033 if (!vdev
->titan1
) {
2034 struct vxge_hw_vp_config
*vcfg
;
2035 vcfg
= &vdev
->devh
->config
.vp_config
[vpath
->device_id
];
2037 vcfg
->rti
.urange_a
= RTI_T1A_RX_URANGE_A
;
2038 vcfg
->rti
.urange_b
= RTI_T1A_RX_URANGE_B
;
2039 vcfg
->rti
.urange_c
= RTI_T1A_RX_URANGE_C
;
2040 vcfg
->tti
.uec_a
= TTI_T1A_TX_UFC_A
;
2041 vcfg
->tti
.uec_b
= TTI_T1A_TX_UFC_B
;
2042 vcfg
->tti
.uec_c
= TTI_T1A_TX_UFC_C(vdev
->mtu
);
2043 vcfg
->tti
.uec_d
= TTI_T1A_TX_UFC_D(vdev
->mtu
);
2044 vcfg
->tti
.ltimer_val
= VXGE_T1A_TTI_LTIMER_VAL
;
2045 vcfg
->tti
.rtimer_val
= VXGE_T1A_TTI_RTIMER_VAL
;
2048 attr
.vp_id
= vpath
->device_id
;
2049 attr
.fifo_attr
.callback
= vxge_xmit_compl
;
2050 attr
.fifo_attr
.txdl_term
= vxge_tx_term
;
2051 attr
.fifo_attr
.per_txdl_space
= sizeof(struct vxge_tx_priv
);
2052 attr
.fifo_attr
.userdata
= &vpath
->fifo
;
2054 attr
.ring_attr
.callback
= vxge_rx_1b_compl
;
2055 attr
.ring_attr
.rxd_init
= vxge_rx_initial_replenish
;
2056 attr
.ring_attr
.rxd_term
= vxge_rx_term
;
2057 attr
.ring_attr
.per_rxd_space
= sizeof(struct vxge_rx_priv
);
2058 attr
.ring_attr
.userdata
= &vpath
->ring
;
2060 vpath
->ring
.ndev
= vdev
->ndev
;
2061 vpath
->ring
.pdev
= vdev
->pdev
;
2063 status
= vxge_hw_vpath_open(vdev
->devh
, &attr
, &vpath
->handle
);
2064 if (status
== VXGE_HW_OK
) {
2065 vpath
->fifo
.handle
=
2066 (struct __vxge_hw_fifo
*)attr
.fifo_attr
.userdata
;
2067 vpath
->ring
.handle
=
2068 (struct __vxge_hw_ring
*)attr
.ring_attr
.userdata
;
2069 vpath
->fifo
.tx_steering_type
=
2070 vdev
->config
.tx_steering_type
;
2071 vpath
->fifo
.ndev
= vdev
->ndev
;
2072 vpath
->fifo
.pdev
= vdev
->pdev
;
2074 u64_stats_init(&vpath
->fifo
.stats
.syncp
);
2075 u64_stats_init(&vpath
->ring
.stats
.syncp
);
2077 if (vdev
->config
.tx_steering_type
)
2079 netdev_get_tx_queue(vdev
->ndev
, i
);
2082 netdev_get_tx_queue(vdev
->ndev
, 0);
2083 vpath
->fifo
.indicate_max_pkts
=
2084 vdev
->config
.fifo_indicate_max_pkts
;
2085 vpath
->fifo
.tx_vector_no
= 0;
2086 vpath
->ring
.rx_vector_no
= 0;
2087 vpath
->ring
.rx_hwts
= vdev
->rx_hwts
;
2089 vdev
->vp_handles
[i
] = vpath
->handle
;
2090 vpath
->ring
.vlan_tag_strip
= vdev
->vlan_tag_strip
;
2091 vdev
->stats
.vpaths_open
++;
2093 vdev
->stats
.vpath_open_fail
++;
2094 vxge_debug_init(VXGE_ERR
, "%s: vpath: %d failed to "
2095 "open with status: %d",
2096 vdev
->ndev
->name
, vpath
->device_id
,
2098 vxge_close_vpaths(vdev
, 0);
2102 vp_id
= vpath
->handle
->vpath
->vp_id
;
2103 vdev
->vpaths_deployed
|= vxge_mBIT(vp_id
);
2110 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2111 * if the interrupts are not within a range
2112 * @fifo: pointer to transmit fifo structure
2113 * Description: The function changes boundary timer and restriction timer
2114 * value depends on the traffic
2115 * Return Value: None
2117 static void adaptive_coalesce_tx_interrupts(struct vxge_fifo
*fifo
)
2119 fifo
->interrupt_count
++;
2120 if (time_before(fifo
->jiffies
+ HZ
/ 100, jiffies
)) {
2121 struct __vxge_hw_fifo
*hw_fifo
= fifo
->handle
;
2123 fifo
->jiffies
= jiffies
;
2124 if (fifo
->interrupt_count
> VXGE_T1A_MAX_TX_INTERRUPT_COUNT
&&
2125 hw_fifo
->rtimer
!= VXGE_TTI_RTIMER_ADAPT_VAL
) {
2126 hw_fifo
->rtimer
= VXGE_TTI_RTIMER_ADAPT_VAL
;
2127 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo
);
2128 } else if (hw_fifo
->rtimer
!= 0) {
2129 hw_fifo
->rtimer
= 0;
2130 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo
);
2132 fifo
->interrupt_count
= 0;
2137 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2138 * if the interrupts are not within a range
2139 * @ring: pointer to receive ring structure
2140 * Description: The function increases of decreases the packet counts within
2141 * the ranges of traffic utilization, if the interrupts due to this ring are
2142 * not within a fixed range.
2143 * Return Value: Nothing
2145 static void adaptive_coalesce_rx_interrupts(struct vxge_ring
*ring
)
2147 ring
->interrupt_count
++;
2148 if (time_before(ring
->jiffies
+ HZ
/ 100, jiffies
)) {
2149 struct __vxge_hw_ring
*hw_ring
= ring
->handle
;
2151 ring
->jiffies
= jiffies
;
2152 if (ring
->interrupt_count
> VXGE_T1A_MAX_INTERRUPT_COUNT
&&
2153 hw_ring
->rtimer
!= VXGE_RTI_RTIMER_ADAPT_VAL
) {
2154 hw_ring
->rtimer
= VXGE_RTI_RTIMER_ADAPT_VAL
;
2155 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring
);
2156 } else if (hw_ring
->rtimer
!= 0) {
2157 hw_ring
->rtimer
= 0;
2158 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring
);
2160 ring
->interrupt_count
= 0;
2166 * @irq: the irq of the device.
2167 * @dev_id: a void pointer to the hldev structure of the Titan device
2168 * @ptregs: pointer to the registers pushed on the stack.
2170 * This function is the ISR handler of the device when napi is enabled. It
2171 * identifies the reason for the interrupt and calls the relevant service
2174 static irqreturn_t
vxge_isr_napi(int irq
, void *dev_id
)
2176 struct __vxge_hw_device
*hldev
;
2178 enum vxge_hw_status status
;
2179 struct vxgedev
*vdev
= (struct vxgedev
*)dev_id
;
2181 vxge_debug_intr(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
2183 hldev
= pci_get_drvdata(vdev
->pdev
);
2185 if (pci_channel_offline(vdev
->pdev
))
2188 if (unlikely(!is_vxge_card_up(vdev
)))
2191 status
= vxge_hw_device_begin_irq(hldev
, vdev
->exec_mode
, &reason
);
2192 if (status
== VXGE_HW_OK
) {
2193 vxge_hw_device_mask_all(hldev
);
2196 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2197 vdev
->vpaths_deployed
>>
2198 (64 - VXGE_HW_MAX_VIRTUAL_PATHS
))) {
2200 vxge_hw_device_clear_tx_rx(hldev
);
2201 napi_schedule(&vdev
->napi
);
2202 vxge_debug_intr(VXGE_TRACE
,
2203 "%s:%d Exiting...", __func__
, __LINE__
);
2206 vxge_hw_device_unmask_all(hldev
);
2207 } else if (unlikely((status
== VXGE_HW_ERR_VPATH
) ||
2208 (status
== VXGE_HW_ERR_CRITICAL
) ||
2209 (status
== VXGE_HW_ERR_FIFO
))) {
2210 vxge_hw_device_mask_all(hldev
);
2211 vxge_hw_device_flush_io(hldev
);
2213 } else if (unlikely(status
== VXGE_HW_ERR_SLOT_FREEZE
))
2216 vxge_debug_intr(VXGE_TRACE
, "%s:%d Exiting...", __func__
, __LINE__
);
2220 static irqreturn_t
vxge_tx_msix_handle(int irq
, void *dev_id
)
2222 struct vxge_fifo
*fifo
= (struct vxge_fifo
*)dev_id
;
2224 adaptive_coalesce_tx_interrupts(fifo
);
2226 vxge_hw_channel_msix_mask((struct __vxge_hw_channel
*)fifo
->handle
,
2227 fifo
->tx_vector_no
);
2229 vxge_hw_channel_msix_clear((struct __vxge_hw_channel
*)fifo
->handle
,
2230 fifo
->tx_vector_no
);
2232 VXGE_COMPLETE_VPATH_TX(fifo
);
2234 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel
*)fifo
->handle
,
2235 fifo
->tx_vector_no
);
2242 static irqreturn_t
vxge_rx_msix_napi_handle(int irq
, void *dev_id
)
2244 struct vxge_ring
*ring
= (struct vxge_ring
*)dev_id
;
2246 adaptive_coalesce_rx_interrupts(ring
);
2248 vxge_hw_channel_msix_mask((struct __vxge_hw_channel
*)ring
->handle
,
2249 ring
->rx_vector_no
);
2251 vxge_hw_channel_msix_clear((struct __vxge_hw_channel
*)ring
->handle
,
2252 ring
->rx_vector_no
);
2254 napi_schedule(&ring
->napi
);
2259 vxge_alarm_msix_handle(int irq
, void *dev_id
)
2262 enum vxge_hw_status status
;
2263 struct vxge_vpath
*vpath
= (struct vxge_vpath
*)dev_id
;
2264 struct vxgedev
*vdev
= vpath
->vdev
;
2265 int msix_id
= (vpath
->handle
->vpath
->vp_id
*
2266 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
2268 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2269 /* Reduce the chance of losing alarm interrupts by masking
2270 * the vector. A pending bit will be set if an alarm is
2271 * generated and on unmask the interrupt will be fired.
2273 vxge_hw_vpath_msix_mask(vdev
->vpaths
[i
].handle
, msix_id
);
2274 vxge_hw_vpath_msix_clear(vdev
->vpaths
[i
].handle
, msix_id
);
2277 status
= vxge_hw_vpath_alarm_process(vdev
->vpaths
[i
].handle
,
2279 if (status
== VXGE_HW_OK
) {
2280 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[i
].handle
,
2285 vxge_debug_intr(VXGE_ERR
,
2286 "%s: vxge_hw_vpath_alarm_process failed %x ",
2287 VXGE_DRIVER_NAME
, status
);
2292 static int vxge_alloc_msix(struct vxgedev
*vdev
)
2295 int msix_intr_vect
= 0, temp
;
2299 /* Tx/Rx MSIX Vectors count */
2300 vdev
->intr_cnt
= vdev
->no_of_vpath
* 2;
2302 /* Alarm MSIX Vectors count */
2305 vdev
->entries
= kcalloc(vdev
->intr_cnt
, sizeof(struct msix_entry
),
2307 if (!vdev
->entries
) {
2308 vxge_debug_init(VXGE_ERR
,
2309 "%s: memory allocation failed",
2312 goto alloc_entries_failed
;
2315 vdev
->vxge_entries
= kcalloc(vdev
->intr_cnt
,
2316 sizeof(struct vxge_msix_entry
),
2318 if (!vdev
->vxge_entries
) {
2319 vxge_debug_init(VXGE_ERR
, "%s: memory allocation failed",
2322 goto alloc_vxge_entries_failed
;
2325 for (i
= 0, j
= 0; i
< vdev
->no_of_vpath
; i
++) {
2327 msix_intr_vect
= i
* VXGE_HW_VPATH_MSIX_ACTIVE
;
2329 /* Initialize the fifo vector */
2330 vdev
->entries
[j
].entry
= msix_intr_vect
;
2331 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
;
2332 vdev
->vxge_entries
[j
].in_use
= 0;
2335 /* Initialize the ring vector */
2336 vdev
->entries
[j
].entry
= msix_intr_vect
+ 1;
2337 vdev
->vxge_entries
[j
].entry
= msix_intr_vect
+ 1;
2338 vdev
->vxge_entries
[j
].in_use
= 0;
2342 /* Initialize the alarm vector */
2343 vdev
->entries
[j
].entry
= VXGE_ALARM_MSIX_ID
;
2344 vdev
->vxge_entries
[j
].entry
= VXGE_ALARM_MSIX_ID
;
2345 vdev
->vxge_entries
[j
].in_use
= 0;
2347 ret
= pci_enable_msix_range(vdev
->pdev
,
2348 vdev
->entries
, 3, vdev
->intr_cnt
);
2351 goto enable_msix_failed
;
2352 } else if (ret
< vdev
->intr_cnt
) {
2353 pci_disable_msix(vdev
->pdev
);
2355 vxge_debug_init(VXGE_ERR
,
2356 "%s: MSI-X enable failed for %d vectors, ret: %d",
2357 VXGE_DRIVER_NAME
, vdev
->intr_cnt
, ret
);
2358 if (max_config_vpath
!= VXGE_USE_DEFAULT
) {
2360 goto enable_msix_failed
;
2363 kfree(vdev
->entries
);
2364 kfree(vdev
->vxge_entries
);
2365 vdev
->entries
= NULL
;
2366 vdev
->vxge_entries
= NULL
;
2367 /* Try with less no of vector by reducing no of vpaths count */
2369 vxge_close_vpaths(vdev
, temp
);
2370 vdev
->no_of_vpath
= temp
;
2376 kfree(vdev
->vxge_entries
);
2377 alloc_vxge_entries_failed
:
2378 kfree(vdev
->entries
);
2379 alloc_entries_failed
:
2383 static int vxge_enable_msix(struct vxgedev
*vdev
)
2387 /* 0 - Tx, 1 - Rx */
2388 int tim_msix_id
[4] = {0, 1, 0, 0};
2392 /* allocate msix vectors */
2393 ret
= vxge_alloc_msix(vdev
);
2395 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2396 struct vxge_vpath
*vpath
= &vdev
->vpaths
[i
];
2398 /* If fifo or ring are not enabled, the MSIX vector for
2399 * it should be set to 0.
2401 vpath
->ring
.rx_vector_no
= (vpath
->device_id
*
2402 VXGE_HW_VPATH_MSIX_ACTIVE
) + 1;
2404 vpath
->fifo
.tx_vector_no
= (vpath
->device_id
*
2405 VXGE_HW_VPATH_MSIX_ACTIVE
);
2407 vxge_hw_vpath_msix_set(vpath
->handle
, tim_msix_id
,
2408 VXGE_ALARM_MSIX_ID
);
2415 static void vxge_rem_msix_isr(struct vxgedev
*vdev
)
2419 for (intr_cnt
= 0; intr_cnt
< (vdev
->no_of_vpath
* 2 + 1);
2421 if (vdev
->vxge_entries
[intr_cnt
].in_use
) {
2422 synchronize_irq(vdev
->entries
[intr_cnt
].vector
);
2423 free_irq(vdev
->entries
[intr_cnt
].vector
,
2424 vdev
->vxge_entries
[intr_cnt
].arg
);
2425 vdev
->vxge_entries
[intr_cnt
].in_use
= 0;
2429 kfree(vdev
->entries
);
2430 kfree(vdev
->vxge_entries
);
2431 vdev
->entries
= NULL
;
2432 vdev
->vxge_entries
= NULL
;
2434 if (vdev
->config
.intr_type
== MSI_X
)
2435 pci_disable_msix(vdev
->pdev
);
2438 static void vxge_rem_isr(struct vxgedev
*vdev
)
2440 if (IS_ENABLED(CONFIG_PCI_MSI
) &&
2441 vdev
->config
.intr_type
== MSI_X
) {
2442 vxge_rem_msix_isr(vdev
);
2443 } else if (vdev
->config
.intr_type
== INTA
) {
2444 synchronize_irq(vdev
->pdev
->irq
);
2445 free_irq(vdev
->pdev
->irq
, vdev
);
2449 static int vxge_add_isr(struct vxgedev
*vdev
)
2452 int vp_idx
= 0, intr_idx
= 0, intr_cnt
= 0, msix_idx
= 0, irq_req
= 0;
2453 int pci_fun
= PCI_FUNC(vdev
->pdev
->devfn
);
2455 if (IS_ENABLED(CONFIG_PCI_MSI
) && vdev
->config
.intr_type
== MSI_X
)
2456 ret
= vxge_enable_msix(vdev
);
2459 vxge_debug_init(VXGE_ERR
,
2460 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME
);
2461 vxge_debug_init(VXGE_ERR
,
2462 "%s: Defaulting to INTA", VXGE_DRIVER_NAME
);
2463 vdev
->config
.intr_type
= INTA
;
2466 if (IS_ENABLED(CONFIG_PCI_MSI
) && vdev
->config
.intr_type
== MSI_X
) {
2468 intr_idx
< (vdev
->no_of_vpath
*
2469 VXGE_HW_VPATH_MSIX_ACTIVE
); intr_idx
++) {
2471 msix_idx
= intr_idx
% VXGE_HW_VPATH_MSIX_ACTIVE
;
2476 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2477 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2479 vdev
->entries
[intr_cnt
].entry
,
2482 vdev
->entries
[intr_cnt
].vector
,
2483 vxge_tx_msix_handle
, 0,
2484 vdev
->desc
[intr_cnt
],
2485 &vdev
->vpaths
[vp_idx
].fifo
);
2486 vdev
->vxge_entries
[intr_cnt
].arg
=
2487 &vdev
->vpaths
[vp_idx
].fifo
;
2491 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2492 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2494 vdev
->entries
[intr_cnt
].entry
,
2497 vdev
->entries
[intr_cnt
].vector
,
2498 vxge_rx_msix_napi_handle
, 0,
2499 vdev
->desc
[intr_cnt
],
2500 &vdev
->vpaths
[vp_idx
].ring
);
2501 vdev
->vxge_entries
[intr_cnt
].arg
=
2502 &vdev
->vpaths
[vp_idx
].ring
;
2508 vxge_debug_init(VXGE_ERR
,
2509 "%s: MSIX - %d Registration failed",
2510 vdev
->ndev
->name
, intr_cnt
);
2511 vxge_rem_msix_isr(vdev
);
2512 vdev
->config
.intr_type
= INTA
;
2513 vxge_debug_init(VXGE_ERR
,
2514 "%s: Defaulting to INTA",
2520 /* We requested for this msix interrupt */
2521 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2522 msix_idx
+= vdev
->vpaths
[vp_idx
].device_id
*
2523 VXGE_HW_VPATH_MSIX_ACTIVE
;
2524 vxge_hw_vpath_msix_unmask(
2525 vdev
->vpaths
[vp_idx
].handle
,
2530 /* Point to next vpath handler */
2531 if (((intr_idx
+ 1) % VXGE_HW_VPATH_MSIX_ACTIVE
== 0) &&
2532 (vp_idx
< (vdev
->no_of_vpath
- 1)))
2536 intr_cnt
= vdev
->no_of_vpath
* 2;
2537 snprintf(vdev
->desc
[intr_cnt
], VXGE_INTR_STRLEN
,
2538 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2540 vdev
->entries
[intr_cnt
].entry
,
2542 /* For Alarm interrupts */
2543 ret
= request_irq(vdev
->entries
[intr_cnt
].vector
,
2544 vxge_alarm_msix_handle
, 0,
2545 vdev
->desc
[intr_cnt
],
2548 vxge_debug_init(VXGE_ERR
,
2549 "%s: MSIX - %d Registration failed",
2550 vdev
->ndev
->name
, intr_cnt
);
2551 vxge_rem_msix_isr(vdev
);
2552 vdev
->config
.intr_type
= INTA
;
2553 vxge_debug_init(VXGE_ERR
,
2554 "%s: Defaulting to INTA",
2559 msix_idx
= (vdev
->vpaths
[0].handle
->vpath
->vp_id
*
2560 VXGE_HW_VPATH_MSIX_ACTIVE
) + VXGE_ALARM_MSIX_ID
;
2561 vxge_hw_vpath_msix_unmask(vdev
->vpaths
[vp_idx
].handle
,
2563 vdev
->vxge_entries
[intr_cnt
].in_use
= 1;
2564 vdev
->vxge_entries
[intr_cnt
].arg
= &vdev
->vpaths
[0];
2568 if (vdev
->config
.intr_type
== INTA
) {
2569 snprintf(vdev
->desc
[0], VXGE_INTR_STRLEN
,
2570 "%s:vxge:INTA", vdev
->ndev
->name
);
2571 vxge_hw_device_set_intr_type(vdev
->devh
,
2572 VXGE_HW_INTR_MODE_IRQLINE
);
2574 vxge_hw_vpath_tti_ci_set(vdev
->vpaths
[0].fifo
.handle
);
2576 ret
= request_irq((int) vdev
->pdev
->irq
,
2578 IRQF_SHARED
, vdev
->desc
[0], vdev
);
2580 vxge_debug_init(VXGE_ERR
,
2581 "%s %s-%d: ISR registration failed",
2582 VXGE_DRIVER_NAME
, "IRQ", vdev
->pdev
->irq
);
2585 vxge_debug_init(VXGE_TRACE
,
2586 "new %s-%d line allocated",
2587 "IRQ", vdev
->pdev
->irq
);
2593 static void vxge_poll_vp_reset(struct timer_list
*t
)
2595 struct vxgedev
*vdev
= from_timer(vdev
, t
, vp_reset_timer
);
2598 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2599 if (test_bit(i
, &vdev
->vp_reset
)) {
2600 vxge_reset_vpath(vdev
, i
);
2604 if (j
&& (vdev
->config
.intr_type
!= MSI_X
)) {
2605 vxge_hw_device_unmask_all(vdev
->devh
);
2606 vxge_hw_device_flush_io(vdev
->devh
);
2609 mod_timer(&vdev
->vp_reset_timer
, jiffies
+ HZ
/ 2);
2612 static void vxge_poll_vp_lockup(struct timer_list
*t
)
2614 struct vxgedev
*vdev
= from_timer(vdev
, t
, vp_lockup_timer
);
2615 enum vxge_hw_status status
= VXGE_HW_OK
;
2616 struct vxge_vpath
*vpath
;
2617 struct vxge_ring
*ring
;
2619 unsigned long rx_frms
;
2621 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2622 ring
= &vdev
->vpaths
[i
].ring
;
2624 /* Truncated to machine word size number of frames */
2625 rx_frms
= READ_ONCE(ring
->stats
.rx_frms
);
2627 /* Did this vpath received any packets */
2628 if (ring
->stats
.prev_rx_frms
== rx_frms
) {
2629 status
= vxge_hw_vpath_check_leak(ring
->handle
);
2631 /* Did it received any packets last time */
2632 if ((VXGE_HW_FAIL
== status
) &&
2633 (VXGE_HW_FAIL
== ring
->last_status
)) {
2635 /* schedule vpath reset */
2636 if (!test_and_set_bit(i
, &vdev
->vp_reset
)) {
2637 vpath
= &vdev
->vpaths
[i
];
2639 /* disable interrupts for this vpath */
2640 vxge_vpath_intr_disable(vdev
, i
);
2642 /* stop the queue for this vpath */
2643 netif_tx_stop_queue(vpath
->fifo
.txq
);
2648 ring
->stats
.prev_rx_frms
= rx_frms
;
2649 ring
->last_status
= status
;
2652 /* Check every 1 milli second */
2653 mod_timer(&vdev
->vp_lockup_timer
, jiffies
+ HZ
/ 1000);
2656 static netdev_features_t
vxge_fix_features(struct net_device
*dev
,
2657 netdev_features_t features
)
2659 netdev_features_t changed
= dev
->features
^ features
;
2661 /* Enabling RTH requires some of the logic in vxge_device_register and a
2662 * vpath reset. Due to these restrictions, only allow modification
2663 * while the interface is down.
2665 if ((changed
& NETIF_F_RXHASH
) && netif_running(dev
))
2666 features
^= NETIF_F_RXHASH
;
2671 static int vxge_set_features(struct net_device
*dev
, netdev_features_t features
)
2673 struct vxgedev
*vdev
= netdev_priv(dev
);
2674 netdev_features_t changed
= dev
->features
^ features
;
2676 if (!(changed
& NETIF_F_RXHASH
))
2679 /* !netif_running() ensured by vxge_fix_features() */
2681 vdev
->devh
->config
.rth_en
= !!(features
& NETIF_F_RXHASH
);
2682 if (vxge_reset_all_vpaths(vdev
) != VXGE_HW_OK
) {
2683 dev
->features
= features
^ NETIF_F_RXHASH
;
2684 vdev
->devh
->config
.rth_en
= !!(dev
->features
& NETIF_F_RXHASH
);
2693 * @dev: pointer to the device structure.
2695 * This function is the open entry point of the driver. It mainly calls a
2696 * function to allocate Rx buffers and inserts them into the buffer
2697 * descriptors and then enables the Rx part of the NIC.
2698 * Return value: '0' on success and an appropriate (-)ve integer as
2699 * defined in errno.h file on failure.
2701 static int vxge_open(struct net_device
*dev
)
2703 enum vxge_hw_status status
;
2704 struct vxgedev
*vdev
;
2705 struct __vxge_hw_device
*hldev
;
2706 struct vxge_vpath
*vpath
;
2711 vxge_debug_entryexit(VXGE_TRACE
,
2712 "%s: %s:%d", dev
->name
, __func__
, __LINE__
);
2714 vdev
= netdev_priv(dev
);
2715 hldev
= pci_get_drvdata(vdev
->pdev
);
2717 /* make sure you have link off by default every time Nic is
2719 netif_carrier_off(dev
);
2722 status
= vxge_open_vpaths(vdev
);
2723 if (status
!= VXGE_HW_OK
) {
2724 vxge_debug_init(VXGE_ERR
,
2725 "%s: fatal: Vpath open failed", vdev
->ndev
->name
);
2730 vdev
->mtu
= dev
->mtu
;
2732 status
= vxge_add_isr(vdev
);
2733 if (status
!= VXGE_HW_OK
) {
2734 vxge_debug_init(VXGE_ERR
,
2735 "%s: fatal: ISR add failed", dev
->name
);
2740 if (vdev
->config
.intr_type
!= MSI_X
) {
2741 netif_napi_add(dev
, &vdev
->napi
, vxge_poll_inta
,
2742 vdev
->config
.napi_weight
);
2743 napi_enable(&vdev
->napi
);
2744 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2745 vpath
= &vdev
->vpaths
[i
];
2746 vpath
->ring
.napi_p
= &vdev
->napi
;
2749 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2750 vpath
= &vdev
->vpaths
[i
];
2751 netif_napi_add(dev
, &vpath
->ring
.napi
,
2752 vxge_poll_msix
, vdev
->config
.napi_weight
);
2753 napi_enable(&vpath
->ring
.napi
);
2754 vpath
->ring
.napi_p
= &vpath
->ring
.napi
;
2759 if (vdev
->config
.rth_steering
) {
2760 status
= vxge_rth_configure(vdev
);
2761 if (status
!= VXGE_HW_OK
) {
2762 vxge_debug_init(VXGE_ERR
,
2763 "%s: fatal: RTH configuration failed",
2769 printk(KERN_INFO
"%s: Receive Hashing Offload %s\n", dev
->name
,
2770 hldev
->config
.rth_en
? "enabled" : "disabled");
2772 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2773 vpath
= &vdev
->vpaths
[i
];
2775 /* set initial mtu before enabling the device */
2776 status
= vxge_hw_vpath_mtu_set(vpath
->handle
, vdev
->mtu
);
2777 if (status
!= VXGE_HW_OK
) {
2778 vxge_debug_init(VXGE_ERR
,
2779 "%s: fatal: can not set new MTU", dev
->name
);
2785 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE
, VXGE_COMPONENT_LL
, vdev
);
2786 vxge_debug_init(vdev
->level_trace
,
2787 "%s: MTU is %d", vdev
->ndev
->name
, vdev
->mtu
);
2788 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR
, VXGE_COMPONENT_LL
, vdev
);
2790 /* Restore the DA, VID table and also multicast and promiscuous mode
2793 if (vdev
->all_multi_flg
) {
2794 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2795 vpath
= &vdev
->vpaths
[i
];
2796 vxge_restore_vpath_mac_addr(vpath
);
2797 vxge_restore_vpath_vid_table(vpath
);
2799 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
2800 if (status
!= VXGE_HW_OK
)
2801 vxge_debug_init(VXGE_ERR
,
2802 "%s:%d Enabling multicast failed",
2803 __func__
, __LINE__
);
2807 /* Enable vpath to sniff all unicast/multicast traffic that not
2808 * addressed to them. We allow promiscuous mode for PF only
2812 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
2813 val64
|= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i
);
2815 vxge_hw_mgmt_reg_write(vdev
->devh
,
2816 vxge_hw_mgmt_reg_type_mrpcim
,
2818 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2819 rxmac_authorize_all_addr
),
2822 vxge_hw_mgmt_reg_write(vdev
->devh
,
2823 vxge_hw_mgmt_reg_type_mrpcim
,
2825 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2826 rxmac_authorize_all_vid
),
2829 vxge_set_multicast(dev
);
2831 /* Enabling Bcast and mcast for all vpath */
2832 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2833 vpath
= &vdev
->vpaths
[i
];
2834 status
= vxge_hw_vpath_bcast_enable(vpath
->handle
);
2835 if (status
!= VXGE_HW_OK
)
2836 vxge_debug_init(VXGE_ERR
,
2837 "%s : Can not enable bcast for vpath "
2838 "id %d", dev
->name
, i
);
2839 if (vdev
->config
.addr_learn_en
) {
2840 status
= vxge_hw_vpath_mcast_enable(vpath
->handle
);
2841 if (status
!= VXGE_HW_OK
)
2842 vxge_debug_init(VXGE_ERR
,
2843 "%s : Can not enable mcast for vpath "
2844 "id %d", dev
->name
, i
);
2848 vxge_hw_device_setpause_data(vdev
->devh
, 0,
2849 vdev
->config
.tx_pause_enable
,
2850 vdev
->config
.rx_pause_enable
);
2852 if (vdev
->vp_reset_timer
.function
== NULL
)
2853 vxge_os_timer(&vdev
->vp_reset_timer
, vxge_poll_vp_reset
,
2856 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2857 if (vdev
->titan1
&& vdev
->vp_lockup_timer
.function
== NULL
)
2858 vxge_os_timer(&vdev
->vp_lockup_timer
, vxge_poll_vp_lockup
,
2861 set_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
2865 if (vxge_hw_device_link_state_get(vdev
->devh
) == VXGE_HW_LINK_UP
) {
2866 netif_carrier_on(vdev
->ndev
);
2867 netdev_notice(vdev
->ndev
, "Link Up\n");
2868 vdev
->stats
.link_up
++;
2871 vxge_hw_device_intr_enable(vdev
->devh
);
2875 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
2876 vpath
= &vdev
->vpaths
[i
];
2878 vxge_hw_vpath_enable(vpath
->handle
);
2880 vxge_hw_vpath_rx_doorbell_init(vpath
->handle
);
2883 netif_tx_start_all_queues(vdev
->ndev
);
2886 vxge_config_ci_for_tti_rti(vdev
);
2894 if (vdev
->config
.intr_type
!= MSI_X
)
2895 napi_disable(&vdev
->napi
);
2897 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2898 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
2902 vxge_close_vpaths(vdev
, 0);
2904 vxge_debug_entryexit(VXGE_TRACE
,
2905 "%s: %s:%d Exiting...",
2906 dev
->name
, __func__
, __LINE__
);
2910 /* Loop through the mac address list and delete all the entries */
2911 static void vxge_free_mac_add_list(struct vxge_vpath
*vpath
)
2914 struct list_head
*entry
, *next
;
2915 if (list_empty(&vpath
->mac_addr_list
))
2918 list_for_each_safe(entry
, next
, &vpath
->mac_addr_list
) {
2920 kfree((struct vxge_mac_addrs
*)entry
);
2924 static void vxge_napi_del_all(struct vxgedev
*vdev
)
2927 if (vdev
->config
.intr_type
!= MSI_X
)
2928 netif_napi_del(&vdev
->napi
);
2930 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
2931 netif_napi_del(&vdev
->vpaths
[i
].ring
.napi
);
2935 static int do_vxge_close(struct net_device
*dev
, int do_io
)
2937 enum vxge_hw_status status
;
2938 struct vxgedev
*vdev
;
2939 struct __vxge_hw_device
*hldev
;
2941 u64 val64
, vpath_vector
;
2942 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d",
2943 dev
->name
, __func__
, __LINE__
);
2945 vdev
= netdev_priv(dev
);
2946 hldev
= pci_get_drvdata(vdev
->pdev
);
2948 if (unlikely(!is_vxge_card_up(vdev
)))
2951 /* If vxge_handle_crit_err task is executing,
2952 * wait till it completes. */
2953 while (test_and_set_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
))
2957 /* Put the vpath back in normal mode */
2958 vpath_vector
= vxge_mBIT(vdev
->vpaths
[0].device_id
);
2959 status
= vxge_hw_mgmt_reg_read(vdev
->devh
,
2960 vxge_hw_mgmt_reg_type_mrpcim
,
2963 struct vxge_hw_mrpcim_reg
,
2964 rts_mgr_cbasin_cfg
),
2966 if (status
== VXGE_HW_OK
) {
2967 val64
&= ~vpath_vector
;
2968 status
= vxge_hw_mgmt_reg_write(vdev
->devh
,
2969 vxge_hw_mgmt_reg_type_mrpcim
,
2972 struct vxge_hw_mrpcim_reg
,
2973 rts_mgr_cbasin_cfg
),
2977 /* Remove the function 0 from promiscuous mode */
2978 vxge_hw_mgmt_reg_write(vdev
->devh
,
2979 vxge_hw_mgmt_reg_type_mrpcim
,
2981 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2982 rxmac_authorize_all_addr
),
2985 vxge_hw_mgmt_reg_write(vdev
->devh
,
2986 vxge_hw_mgmt_reg_type_mrpcim
,
2988 (ulong
)offsetof(struct vxge_hw_mrpcim_reg
,
2989 rxmac_authorize_all_vid
),
2996 del_timer_sync(&vdev
->vp_lockup_timer
);
2998 del_timer_sync(&vdev
->vp_reset_timer
);
3001 vxge_hw_device_wait_receive_idle(hldev
);
3003 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3006 if (vdev
->config
.intr_type
!= MSI_X
)
3007 napi_disable(&vdev
->napi
);
3009 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
3010 napi_disable(&vdev
->vpaths
[i
].ring
.napi
);
3013 netif_carrier_off(vdev
->ndev
);
3014 netdev_notice(vdev
->ndev
, "Link Down\n");
3015 netif_tx_stop_all_queues(vdev
->ndev
);
3017 /* Note that at this point xmit() is stopped by upper layer */
3019 vxge_hw_device_intr_disable(vdev
->devh
);
3023 vxge_napi_del_all(vdev
);
3026 vxge_reset_all_vpaths(vdev
);
3028 vxge_close_vpaths(vdev
, 0);
3030 vxge_debug_entryexit(VXGE_TRACE
,
3031 "%s: %s:%d Exiting...", dev
->name
, __func__
, __LINE__
);
3033 clear_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
);
3040 * @dev: device pointer.
3042 * This is the stop entry point of the driver. It needs to undo exactly
3043 * whatever was done by the open entry point, thus it's usually referred to
3044 * as the close function.Among other things this function mainly stops the
3045 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3046 * Return value: '0' on success and an appropriate (-)ve integer as
3047 * defined in errno.h file on failure.
3049 static int vxge_close(struct net_device
*dev
)
3051 do_vxge_close(dev
, 1);
3057 * @dev: net device pointer.
3058 * @new_mtu :the new MTU size for the device.
3060 * A driver entry point to change MTU size for the device. Before changing
3061 * the MTU the device must be stopped.
3063 static int vxge_change_mtu(struct net_device
*dev
, int new_mtu
)
3065 struct vxgedev
*vdev
= netdev_priv(dev
);
3067 vxge_debug_entryexit(vdev
->level_trace
,
3068 "%s:%d", __func__
, __LINE__
);
3070 /* check if device is down already */
3071 if (unlikely(!is_vxge_card_up(vdev
))) {
3072 /* just store new value, will use later on open() */
3074 vxge_debug_init(vdev
->level_err
,
3075 "%s", "device is down on MTU change");
3079 vxge_debug_init(vdev
->level_trace
,
3080 "trying to apply new MTU %d", new_mtu
);
3082 if (vxge_close(dev
))
3086 vdev
->mtu
= new_mtu
;
3091 vxge_debug_init(vdev
->level_trace
,
3092 "%s: MTU changed to %d", vdev
->ndev
->name
, new_mtu
);
3094 vxge_debug_entryexit(vdev
->level_trace
,
3095 "%s:%d Exiting...", __func__
, __LINE__
);
3102 * @dev: pointer to the device structure
3103 * @stats: pointer to struct rtnl_link_stats64
3107 vxge_get_stats64(struct net_device
*dev
, struct rtnl_link_stats64
*net_stats
)
3109 struct vxgedev
*vdev
= netdev_priv(dev
);
3112 /* net_stats already zeroed by caller */
3113 for (k
= 0; k
< vdev
->no_of_vpath
; k
++) {
3114 struct vxge_ring_stats
*rxstats
= &vdev
->vpaths
[k
].ring
.stats
;
3115 struct vxge_fifo_stats
*txstats
= &vdev
->vpaths
[k
].fifo
.stats
;
3117 u64 packets
, bytes
, multicast
;
3120 start
= u64_stats_fetch_begin_irq(&rxstats
->syncp
);
3122 packets
= rxstats
->rx_frms
;
3123 multicast
= rxstats
->rx_mcast
;
3124 bytes
= rxstats
->rx_bytes
;
3125 } while (u64_stats_fetch_retry_irq(&rxstats
->syncp
, start
));
3127 net_stats
->rx_packets
+= packets
;
3128 net_stats
->rx_bytes
+= bytes
;
3129 net_stats
->multicast
+= multicast
;
3131 net_stats
->rx_errors
+= rxstats
->rx_errors
;
3132 net_stats
->rx_dropped
+= rxstats
->rx_dropped
;
3135 start
= u64_stats_fetch_begin_irq(&txstats
->syncp
);
3137 packets
= txstats
->tx_frms
;
3138 bytes
= txstats
->tx_bytes
;
3139 } while (u64_stats_fetch_retry_irq(&txstats
->syncp
, start
));
3141 net_stats
->tx_packets
+= packets
;
3142 net_stats
->tx_bytes
+= bytes
;
3143 net_stats
->tx_errors
+= txstats
->tx_errors
;
3147 static enum vxge_hw_status
vxge_timestamp_config(struct __vxge_hw_device
*devh
)
3149 enum vxge_hw_status status
;
3152 /* Timestamp is passed to the driver via the FCS, therefore we
3153 * must disable the FCS stripping by the adapter. Since this is
3154 * required for the driver to load (due to a hardware bug),
3155 * there is no need to do anything special here.
3157 val64
= VXGE_HW_XMAC_TIMESTAMP_EN
|
3158 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3159 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
3161 status
= vxge_hw_mgmt_reg_write(devh
,
3162 vxge_hw_mgmt_reg_type_mrpcim
,
3164 offsetof(struct vxge_hw_mrpcim_reg
,
3167 vxge_hw_device_flush_io(devh
);
3168 devh
->config
.hwts_en
= VXGE_HW_HWTS_ENABLE
;
3172 static int vxge_hwtstamp_set(struct vxgedev
*vdev
, void __user
*data
)
3174 struct hwtstamp_config config
;
3177 if (copy_from_user(&config
, data
, sizeof(config
)))
3180 /* reserved for future extensions */
3184 /* Transmit HW Timestamp not supported */
3185 switch (config
.tx_type
) {
3186 case HWTSTAMP_TX_OFF
:
3188 case HWTSTAMP_TX_ON
:
3193 switch (config
.rx_filter
) {
3194 case HWTSTAMP_FILTER_NONE
:
3196 config
.rx_filter
= HWTSTAMP_FILTER_NONE
;
3199 case HWTSTAMP_FILTER_ALL
:
3200 case HWTSTAMP_FILTER_SOME
:
3201 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT
:
3202 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC
:
3203 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
:
3204 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT
:
3205 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC
:
3206 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
:
3207 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT
:
3208 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC
:
3209 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
:
3210 case HWTSTAMP_FILTER_PTP_V2_EVENT
:
3211 case HWTSTAMP_FILTER_PTP_V2_SYNC
:
3212 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
:
3213 case HWTSTAMP_FILTER_NTP_ALL
:
3214 if (vdev
->devh
->config
.hwts_en
!= VXGE_HW_HWTS_ENABLE
)
3218 config
.rx_filter
= HWTSTAMP_FILTER_ALL
;
3225 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
3226 vdev
->vpaths
[i
].ring
.rx_hwts
= vdev
->rx_hwts
;
3228 if (copy_to_user(data
, &config
, sizeof(config
)))
3234 static int vxge_hwtstamp_get(struct vxgedev
*vdev
, void __user
*data
)
3236 struct hwtstamp_config config
;
3239 config
.tx_type
= HWTSTAMP_TX_OFF
;
3240 config
.rx_filter
= (vdev
->rx_hwts
?
3241 HWTSTAMP_FILTER_ALL
: HWTSTAMP_FILTER_NONE
);
3243 if (copy_to_user(data
, &config
, sizeof(config
)))
3251 * @dev: Device pointer.
3252 * @ifr: An IOCTL specific structure, that can contain a pointer to
3253 * a proprietary structure used to pass information to the driver.
3254 * @cmd: This is used to distinguish between the different commands that
3255 * can be passed to the IOCTL functions.
3257 * Entry point for the Ioctl.
3259 static int vxge_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
3261 struct vxgedev
*vdev
= netdev_priv(dev
);
3265 return vxge_hwtstamp_set(vdev
, rq
->ifr_data
);
3267 return vxge_hwtstamp_get(vdev
, rq
->ifr_data
);
3275 * @dev: pointer to net device structure
3277 * Watchdog for transmit side.
3278 * This function is triggered if the Tx Queue is stopped
3279 * for a pre-defined amount of time when the Interface is still up.
3281 static void vxge_tx_watchdog(struct net_device
*dev
)
3283 struct vxgedev
*vdev
;
3285 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3287 vdev
= netdev_priv(dev
);
3289 vdev
->cric_err_event
= VXGE_HW_EVENT_RESET_START
;
3291 schedule_work(&vdev
->reset_task
);
3292 vxge_debug_entryexit(VXGE_TRACE
,
3293 "%s:%d Exiting...", __func__
, __LINE__
);
3297 * vxge_vlan_rx_add_vid
3298 * @dev: net device pointer.
3299 * @proto: vlan protocol
3302 * Add the vlan id to the devices vlan id table
3305 vxge_vlan_rx_add_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
3307 struct vxgedev
*vdev
= netdev_priv(dev
);
3308 struct vxge_vpath
*vpath
;
3311 /* Add these vlan to the vid table */
3312 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3313 vpath
= &vdev
->vpaths
[vp_id
];
3314 if (!vpath
->is_open
)
3316 vxge_hw_vpath_vid_add(vpath
->handle
, vid
);
3318 set_bit(vid
, vdev
->active_vlans
);
3323 * vxge_vlan_rx_kill_vid
3324 * @dev: net device pointer.
3325 * @proto: vlan protocol
3328 * Remove the vlan id from the device's vlan id table
3331 vxge_vlan_rx_kill_vid(struct net_device
*dev
, __be16 proto
, u16 vid
)
3333 struct vxgedev
*vdev
= netdev_priv(dev
);
3334 struct vxge_vpath
*vpath
;
3337 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
3339 /* Delete this vlan from the vid table */
3340 for (vp_id
= 0; vp_id
< vdev
->no_of_vpath
; vp_id
++) {
3341 vpath
= &vdev
->vpaths
[vp_id
];
3342 if (!vpath
->is_open
)
3344 vxge_hw_vpath_vid_delete(vpath
->handle
, vid
);
3346 vxge_debug_entryexit(VXGE_TRACE
,
3347 "%s:%d Exiting...", __func__
, __LINE__
);
3348 clear_bit(vid
, vdev
->active_vlans
);
3352 static const struct net_device_ops vxge_netdev_ops
= {
3353 .ndo_open
= vxge_open
,
3354 .ndo_stop
= vxge_close
,
3355 .ndo_get_stats64
= vxge_get_stats64
,
3356 .ndo_start_xmit
= vxge_xmit
,
3357 .ndo_validate_addr
= eth_validate_addr
,
3358 .ndo_set_rx_mode
= vxge_set_multicast
,
3359 .ndo_do_ioctl
= vxge_ioctl
,
3360 .ndo_set_mac_address
= vxge_set_mac_addr
,
3361 .ndo_change_mtu
= vxge_change_mtu
,
3362 .ndo_fix_features
= vxge_fix_features
,
3363 .ndo_set_features
= vxge_set_features
,
3364 .ndo_vlan_rx_kill_vid
= vxge_vlan_rx_kill_vid
,
3365 .ndo_vlan_rx_add_vid
= vxge_vlan_rx_add_vid
,
3366 .ndo_tx_timeout
= vxge_tx_watchdog
,
3367 #ifdef CONFIG_NET_POLL_CONTROLLER
3368 .ndo_poll_controller
= vxge_netpoll
,
3372 static int vxge_device_register(struct __vxge_hw_device
*hldev
,
3373 struct vxge_config
*config
, int high_dma
,
3374 int no_of_vpath
, struct vxgedev
**vdev_out
)
3376 struct net_device
*ndev
;
3377 enum vxge_hw_status status
= VXGE_HW_OK
;
3378 struct vxgedev
*vdev
;
3379 int ret
= 0, no_of_queue
= 1;
3383 if (config
->tx_steering_type
)
3384 no_of_queue
= no_of_vpath
;
3386 ndev
= alloc_etherdev_mq(sizeof(struct vxgedev
),
3390 vxge_hw_device_trace_level_get(hldev
),
3391 "%s : device allocation failed", __func__
);
3396 vxge_debug_entryexit(
3397 vxge_hw_device_trace_level_get(hldev
),
3398 "%s: %s:%d Entering...",
3399 ndev
->name
, __func__
, __LINE__
);
3401 vdev
= netdev_priv(ndev
);
3402 memset(vdev
, 0, sizeof(struct vxgedev
));
3406 vdev
->pdev
= hldev
->pdev
;
3407 memcpy(&vdev
->config
, config
, sizeof(struct vxge_config
));
3409 vdev
->titan1
= (vdev
->pdev
->revision
== VXGE_HW_TITAN1_PCI_REVISION
);
3411 SET_NETDEV_DEV(ndev
, &vdev
->pdev
->dev
);
3413 ndev
->hw_features
= NETIF_F_RXCSUM
| NETIF_F_SG
|
3414 NETIF_F_IP_CSUM
| NETIF_F_IPV6_CSUM
|
3415 NETIF_F_TSO
| NETIF_F_TSO6
|
3416 NETIF_F_HW_VLAN_CTAG_TX
;
3417 if (vdev
->config
.rth_steering
!= NO_STEERING
)
3418 ndev
->hw_features
|= NETIF_F_RXHASH
;
3420 ndev
->features
|= ndev
->hw_features
|
3421 NETIF_F_HW_VLAN_CTAG_RX
| NETIF_F_HW_VLAN_CTAG_FILTER
;
3424 ndev
->netdev_ops
= &vxge_netdev_ops
;
3426 ndev
->watchdog_timeo
= VXGE_LL_WATCH_DOG_TIMEOUT
;
3427 INIT_WORK(&vdev
->reset_task
, vxge_reset
);
3429 vxge_initialize_ethtool_ops(ndev
);
3431 /* Allocate memory for vpath */
3432 vdev
->vpaths
= kzalloc((sizeof(struct vxge_vpath
)) *
3433 no_of_vpath
, GFP_KERNEL
);
3434 if (!vdev
->vpaths
) {
3435 vxge_debug_init(VXGE_ERR
,
3436 "%s: vpath memory allocation failed",
3442 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3443 "%s : checksumming enabled", __func__
);
3446 ndev
->features
|= NETIF_F_HIGHDMA
;
3447 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3448 "%s : using High DMA", __func__
);
3451 /* MTU range: 68 - 9600 */
3452 ndev
->min_mtu
= VXGE_HW_MIN_MTU
;
3453 ndev
->max_mtu
= VXGE_HW_MAX_MTU
;
3455 ret
= register_netdev(ndev
);
3457 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3458 "%s: %s : device registration failed!",
3459 ndev
->name
, __func__
);
3463 /* Set the factory defined MAC address initially */
3464 ndev
->addr_len
= ETH_ALEN
;
3466 /* Make Link state as off at this point, when the Link change
3467 * interrupt comes the state will be automatically changed to
3470 netif_carrier_off(ndev
);
3472 vxge_debug_init(vxge_hw_device_trace_level_get(hldev
),
3473 "%s: Ethernet device registered",
3479 /* Resetting the Device stats */
3480 status
= vxge_hw_mrpcim_stats_access(
3482 VXGE_HW_STATS_OP_CLEAR_ALL_STATS
,
3487 if (status
== VXGE_HW_ERR_PRIVILAGED_OPEARATION
)
3489 vxge_hw_device_trace_level_get(hldev
),
3490 "%s: device stats clear returns"
3491 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev
->name
);
3493 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev
),
3494 "%s: %s:%d Exiting...",
3495 ndev
->name
, __func__
, __LINE__
);
3499 kfree(vdev
->vpaths
);
3507 * vxge_device_unregister
3509 * This function will unregister and free network device
3511 static void vxge_device_unregister(struct __vxge_hw_device
*hldev
)
3513 struct vxgedev
*vdev
;
3514 struct net_device
*dev
;
3518 vdev
= netdev_priv(dev
);
3520 vxge_debug_entryexit(vdev
->level_trace
, "%s: %s:%d", vdev
->ndev
->name
,
3521 __func__
, __LINE__
);
3523 strlcpy(buf
, dev
->name
, IFNAMSIZ
);
3525 flush_work(&vdev
->reset_task
);
3527 /* in 2.6 will call stop() if device is up */
3528 unregister_netdev(dev
);
3530 kfree(vdev
->vpaths
);
3532 /* we are safe to free it now */
3535 vxge_debug_init(vdev
->level_trace
, "%s: ethernet device unregistered",
3537 vxge_debug_entryexit(vdev
->level_trace
, "%s: %s:%d Exiting...", buf
,
3538 __func__
, __LINE__
);
3542 * vxge_callback_crit_err
3544 * This function is called by the alarm handler in interrupt context.
3545 * Driver must analyze it based on the event type.
3548 vxge_callback_crit_err(struct __vxge_hw_device
*hldev
,
3549 enum vxge_hw_event type
, u64 vp_id
)
3551 struct net_device
*dev
= hldev
->ndev
;
3552 struct vxgedev
*vdev
= netdev_priv(dev
);
3553 struct vxge_vpath
*vpath
= NULL
;
3556 vxge_debug_entryexit(vdev
->level_trace
,
3557 "%s: %s:%d", vdev
->ndev
->name
, __func__
, __LINE__
);
3559 /* Note: This event type should be used for device wide
3560 * indications only - Serious errors, Slot freeze and critical errors
3562 vdev
->cric_err_event
= type
;
3564 for (vpath_idx
= 0; vpath_idx
< vdev
->no_of_vpath
; vpath_idx
++) {
3565 vpath
= &vdev
->vpaths
[vpath_idx
];
3566 if (vpath
->device_id
== vp_id
)
3570 if (!test_bit(__VXGE_STATE_RESET_CARD
, &vdev
->state
)) {
3571 if (type
== VXGE_HW_EVENT_SLOT_FREEZE
) {
3572 vxge_debug_init(VXGE_ERR
,
3573 "%s: Slot is frozen", vdev
->ndev
->name
);
3574 } else if (type
== VXGE_HW_EVENT_SERR
) {
3575 vxge_debug_init(VXGE_ERR
,
3576 "%s: Encountered Serious Error",
3578 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
)
3579 vxge_debug_init(VXGE_ERR
,
3580 "%s: Encountered Critical Error",
3584 if ((type
== VXGE_HW_EVENT_SERR
) ||
3585 (type
== VXGE_HW_EVENT_SLOT_FREEZE
)) {
3586 if (unlikely(vdev
->exec_mode
))
3587 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3588 } else if (type
== VXGE_HW_EVENT_CRITICAL_ERR
) {
3589 vxge_hw_device_mask_all(hldev
);
3590 if (unlikely(vdev
->exec_mode
))
3591 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3592 } else if ((type
== VXGE_HW_EVENT_FIFO_ERR
) ||
3593 (type
== VXGE_HW_EVENT_VPATH_ERR
)) {
3595 if (unlikely(vdev
->exec_mode
))
3596 clear_bit(__VXGE_STATE_CARD_UP
, &vdev
->state
);
3598 /* check if this vpath is already set for reset */
3599 if (!test_and_set_bit(vpath_idx
, &vdev
->vp_reset
)) {
3601 /* disable interrupts for this vpath */
3602 vxge_vpath_intr_disable(vdev
, vpath_idx
);
3604 /* stop the queue for this vpath */
3605 netif_tx_stop_queue(vpath
->fifo
.txq
);
3610 vxge_debug_entryexit(vdev
->level_trace
,
3611 "%s: %s:%d Exiting...",
3612 vdev
->ndev
->name
, __func__
, __LINE__
);
3615 static void verify_bandwidth(void)
3617 int i
, band_width
, total
= 0, equal_priority
= 0;
3619 /* 1. If user enters 0 for some fifo, give equal priority to all */
3620 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3621 if (bw_percentage
[i
] == 0) {
3627 if (!equal_priority
) {
3628 /* 2. If sum exceeds 100, give equal priority to all */
3629 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3630 if (bw_percentage
[i
] == 0xFF)
3633 total
+= bw_percentage
[i
];
3634 if (total
> VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3641 if (!equal_priority
) {
3642 /* Is all the bandwidth consumed? */
3643 if (total
< VXGE_HW_VPATH_BANDWIDTH_MAX
) {
3644 if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
) {
3645 /* Split rest of bw equally among next VPs*/
3647 (VXGE_HW_VPATH_BANDWIDTH_MAX
- total
) /
3648 (VXGE_HW_MAX_VIRTUAL_PATHS
- i
);
3649 if (band_width
< 2) /* min of 2% */
3652 for (; i
< VXGE_HW_MAX_VIRTUAL_PATHS
;
3658 } else if (i
< VXGE_HW_MAX_VIRTUAL_PATHS
)
3662 if (equal_priority
) {
3663 vxge_debug_init(VXGE_ERR
,
3664 "%s: Assigning equal bandwidth to all the vpaths",
3666 bw_percentage
[0] = VXGE_HW_VPATH_BANDWIDTH_MAX
/
3667 VXGE_HW_MAX_VIRTUAL_PATHS
;
3668 for (i
= 1; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3669 bw_percentage
[i
] = bw_percentage
[0];
3674 * Vpath configuration
3676 static int vxge_config_vpaths(struct vxge_hw_device_config
*device_config
,
3677 u64 vpath_mask
, struct vxge_config
*config_param
)
3679 int i
, no_of_vpaths
= 0, default_no_vpath
= 0, temp
;
3680 u32 txdl_size
, txdl_per_memblock
;
3682 temp
= driver_config
->vpath_per_dev
;
3683 if ((driver_config
->vpath_per_dev
== VXGE_USE_DEFAULT
) &&
3684 (max_config_dev
== VXGE_MAX_CONFIG_DEV
)) {
3685 /* No more CPU. Return vpath number as zero.*/
3686 if (driver_config
->g_no_cpus
== -1)
3689 if (!driver_config
->g_no_cpus
)
3690 driver_config
->g_no_cpus
=
3691 netif_get_num_default_rss_queues();
3693 driver_config
->vpath_per_dev
= driver_config
->g_no_cpus
>> 1;
3694 if (!driver_config
->vpath_per_dev
)
3695 driver_config
->vpath_per_dev
= 1;
3697 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3698 if (!vxge_bVALn(vpath_mask
, i
, 1))
3702 if (default_no_vpath
< driver_config
->vpath_per_dev
)
3703 driver_config
->vpath_per_dev
= default_no_vpath
;
3705 driver_config
->g_no_cpus
= driver_config
->g_no_cpus
-
3706 (driver_config
->vpath_per_dev
* 2);
3707 if (driver_config
->g_no_cpus
<= 0)
3708 driver_config
->g_no_cpus
= -1;
3711 if (driver_config
->vpath_per_dev
== 1) {
3712 vxge_debug_ll_config(VXGE_TRACE
,
3713 "%s: Disable tx and rx steering, "
3714 "as single vpath is configured", VXGE_DRIVER_NAME
);
3715 config_param
->rth_steering
= NO_STEERING
;
3716 config_param
->tx_steering_type
= NO_STEERING
;
3717 device_config
->rth_en
= 0;
3720 /* configure bandwidth */
3721 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++)
3722 device_config
->vp_config
[i
].min_bandwidth
= bw_percentage
[i
];
3724 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3725 device_config
->vp_config
[i
].vp_id
= i
;
3726 device_config
->vp_config
[i
].mtu
= VXGE_HW_DEFAULT_MTU
;
3727 if (no_of_vpaths
< driver_config
->vpath_per_dev
) {
3728 if (!vxge_bVALn(vpath_mask
, i
, 1)) {
3729 vxge_debug_ll_config(VXGE_TRACE
,
3730 "%s: vpath: %d is not available",
3731 VXGE_DRIVER_NAME
, i
);
3734 vxge_debug_ll_config(VXGE_TRACE
,
3735 "%s: vpath: %d available",
3736 VXGE_DRIVER_NAME
, i
);
3740 vxge_debug_ll_config(VXGE_TRACE
,
3741 "%s: vpath: %d is not configured, "
3742 "max_config_vpath exceeded",
3743 VXGE_DRIVER_NAME
, i
);
3747 /* Configure Tx fifo's */
3748 device_config
->vp_config
[i
].fifo
.enable
=
3749 VXGE_HW_FIFO_ENABLE
;
3750 device_config
->vp_config
[i
].fifo
.max_frags
=
3752 device_config
->vp_config
[i
].fifo
.memblock_size
=
3753 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
;
3755 txdl_size
= device_config
->vp_config
[i
].fifo
.max_frags
*
3756 sizeof(struct vxge_hw_fifo_txd
);
3757 txdl_per_memblock
= VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE
/ txdl_size
;
3759 device_config
->vp_config
[i
].fifo
.fifo_blocks
=
3760 ((VXGE_DEF_FIFO_LENGTH
- 1) / txdl_per_memblock
) + 1;
3762 device_config
->vp_config
[i
].fifo
.intr
=
3763 VXGE_HW_FIFO_QUEUE_INTR_DISABLE
;
3765 /* Configure tti properties */
3766 device_config
->vp_config
[i
].tti
.intr_enable
=
3767 VXGE_HW_TIM_INTR_ENABLE
;
3769 device_config
->vp_config
[i
].tti
.btimer_val
=
3770 (VXGE_TTI_BTIMER_VAL
* 1000) / 272;
3772 device_config
->vp_config
[i
].tti
.timer_ac_en
=
3773 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3775 /* For msi-x with napi (each vector has a handler of its own) -
3776 * Set CI to OFF for all vpaths
3778 device_config
->vp_config
[i
].tti
.timer_ci_en
=
3779 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3781 device_config
->vp_config
[i
].tti
.timer_ri_en
=
3782 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3784 device_config
->vp_config
[i
].tti
.util_sel
=
3785 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL
;
3787 device_config
->vp_config
[i
].tti
.ltimer_val
=
3788 (VXGE_TTI_LTIMER_VAL
* 1000) / 272;
3790 device_config
->vp_config
[i
].tti
.rtimer_val
=
3791 (VXGE_TTI_RTIMER_VAL
* 1000) / 272;
3793 device_config
->vp_config
[i
].tti
.urange_a
= TTI_TX_URANGE_A
;
3794 device_config
->vp_config
[i
].tti
.urange_b
= TTI_TX_URANGE_B
;
3795 device_config
->vp_config
[i
].tti
.urange_c
= TTI_TX_URANGE_C
;
3796 device_config
->vp_config
[i
].tti
.uec_a
= TTI_TX_UFC_A
;
3797 device_config
->vp_config
[i
].tti
.uec_b
= TTI_TX_UFC_B
;
3798 device_config
->vp_config
[i
].tti
.uec_c
= TTI_TX_UFC_C
;
3799 device_config
->vp_config
[i
].tti
.uec_d
= TTI_TX_UFC_D
;
3801 /* Configure Rx rings */
3802 device_config
->vp_config
[i
].ring
.enable
=
3803 VXGE_HW_RING_ENABLE
;
3805 device_config
->vp_config
[i
].ring
.ring_blocks
=
3806 VXGE_HW_DEF_RING_BLOCKS
;
3808 device_config
->vp_config
[i
].ring
.buffer_mode
=
3809 VXGE_HW_RING_RXD_BUFFER_MODE_1
;
3811 device_config
->vp_config
[i
].ring
.rxds_limit
=
3812 VXGE_HW_DEF_RING_RXDS_LIMIT
;
3814 device_config
->vp_config
[i
].ring
.scatter_mode
=
3815 VXGE_HW_RING_SCATTER_MODE_A
;
3817 /* Configure rti properties */
3818 device_config
->vp_config
[i
].rti
.intr_enable
=
3819 VXGE_HW_TIM_INTR_ENABLE
;
3821 device_config
->vp_config
[i
].rti
.btimer_val
=
3822 (VXGE_RTI_BTIMER_VAL
* 1000)/272;
3824 device_config
->vp_config
[i
].rti
.timer_ac_en
=
3825 VXGE_HW_TIM_TIMER_AC_ENABLE
;
3827 device_config
->vp_config
[i
].rti
.timer_ci_en
=
3828 VXGE_HW_TIM_TIMER_CI_DISABLE
;
3830 device_config
->vp_config
[i
].rti
.timer_ri_en
=
3831 VXGE_HW_TIM_TIMER_RI_DISABLE
;
3833 device_config
->vp_config
[i
].rti
.util_sel
=
3834 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL
;
3836 device_config
->vp_config
[i
].rti
.urange_a
=
3838 device_config
->vp_config
[i
].rti
.urange_b
=
3840 device_config
->vp_config
[i
].rti
.urange_c
=
3842 device_config
->vp_config
[i
].rti
.uec_a
= RTI_RX_UFC_A
;
3843 device_config
->vp_config
[i
].rti
.uec_b
= RTI_RX_UFC_B
;
3844 device_config
->vp_config
[i
].rti
.uec_c
= RTI_RX_UFC_C
;
3845 device_config
->vp_config
[i
].rti
.uec_d
= RTI_RX_UFC_D
;
3847 device_config
->vp_config
[i
].rti
.rtimer_val
=
3848 (VXGE_RTI_RTIMER_VAL
* 1000) / 272;
3850 device_config
->vp_config
[i
].rti
.ltimer_val
=
3851 (VXGE_RTI_LTIMER_VAL
* 1000) / 272;
3853 device_config
->vp_config
[i
].rpa_strip_vlan_tag
=
3857 driver_config
->vpath_per_dev
= temp
;
3858 return no_of_vpaths
;
3861 /* initialize device configuratrions */
3862 static void vxge_device_config_init(struct vxge_hw_device_config
*device_config
,
3865 /* Used for CQRQ/SRQ. */
3866 device_config
->dma_blockpool_initial
=
3867 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE
;
3869 device_config
->dma_blockpool_max
=
3870 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE
;
3872 if (max_mac_vpath
> VXGE_MAX_MAC_ADDR_COUNT
)
3873 max_mac_vpath
= VXGE_MAX_MAC_ADDR_COUNT
;
3875 if (!IS_ENABLED(CONFIG_PCI_MSI
)) {
3876 vxge_debug_init(VXGE_ERR
,
3877 "%s: This Kernel does not support "
3878 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME
);
3882 /* Configure whether MSI-X or IRQL. */
3883 switch (*intr_type
) {
3885 device_config
->intr_mode
= VXGE_HW_INTR_MODE_IRQLINE
;
3889 device_config
->intr_mode
= VXGE_HW_INTR_MODE_MSIX_ONE_SHOT
;
3893 /* Timer period between device poll */
3894 device_config
->device_poll_millis
= VXGE_TIMER_DELAY
;
3896 /* Configure mac based steering. */
3897 device_config
->rts_mac_en
= addr_learn_en
;
3899 /* Configure Vpaths */
3900 device_config
->rth_it_type
= VXGE_HW_RTH_IT_TYPE_MULTI_IT
;
3902 vxge_debug_ll_config(VXGE_TRACE
, "%s : Device Config Params ",
3904 vxge_debug_ll_config(VXGE_TRACE
, "intr_mode : %d",
3905 device_config
->intr_mode
);
3906 vxge_debug_ll_config(VXGE_TRACE
, "device_poll_millis : %d",
3907 device_config
->device_poll_millis
);
3908 vxge_debug_ll_config(VXGE_TRACE
, "rth_en : %d",
3909 device_config
->rth_en
);
3910 vxge_debug_ll_config(VXGE_TRACE
, "rth_it_type : %d",
3911 device_config
->rth_it_type
);
3914 static void vxge_print_parm(struct vxgedev
*vdev
, u64 vpath_mask
)
3918 vxge_debug_init(VXGE_TRACE
,
3919 "%s: %d Vpath(s) opened",
3920 vdev
->ndev
->name
, vdev
->no_of_vpath
);
3922 switch (vdev
->config
.intr_type
) {
3924 vxge_debug_init(VXGE_TRACE
,
3925 "%s: Interrupt type INTA", vdev
->ndev
->name
);
3929 vxge_debug_init(VXGE_TRACE
,
3930 "%s: Interrupt type MSI-X", vdev
->ndev
->name
);
3934 if (vdev
->config
.rth_steering
) {
3935 vxge_debug_init(VXGE_TRACE
,
3936 "%s: RTH steering enabled for TCP_IPV4",
3939 vxge_debug_init(VXGE_TRACE
,
3940 "%s: RTH steering disabled", vdev
->ndev
->name
);
3943 switch (vdev
->config
.tx_steering_type
) {
3945 vxge_debug_init(VXGE_TRACE
,
3946 "%s: Tx steering disabled", vdev
->ndev
->name
);
3948 case TX_PRIORITY_STEERING
:
3949 vxge_debug_init(VXGE_TRACE
,
3950 "%s: Unsupported tx steering option",
3952 vxge_debug_init(VXGE_TRACE
,
3953 "%s: Tx steering disabled", vdev
->ndev
->name
);
3954 vdev
->config
.tx_steering_type
= 0;
3956 case TX_VLAN_STEERING
:
3957 vxge_debug_init(VXGE_TRACE
,
3958 "%s: Unsupported tx steering option",
3960 vxge_debug_init(VXGE_TRACE
,
3961 "%s: Tx steering disabled", vdev
->ndev
->name
);
3962 vdev
->config
.tx_steering_type
= 0;
3964 case TX_MULTIQ_STEERING
:
3965 vxge_debug_init(VXGE_TRACE
,
3966 "%s: Tx multiqueue steering enabled",
3969 case TX_PORT_STEERING
:
3970 vxge_debug_init(VXGE_TRACE
,
3971 "%s: Tx port steering enabled",
3975 vxge_debug_init(VXGE_ERR
,
3976 "%s: Unsupported tx steering type",
3978 vxge_debug_init(VXGE_TRACE
,
3979 "%s: Tx steering disabled", vdev
->ndev
->name
);
3980 vdev
->config
.tx_steering_type
= 0;
3983 if (vdev
->config
.addr_learn_en
)
3984 vxge_debug_init(VXGE_TRACE
,
3985 "%s: MAC Address learning enabled", vdev
->ndev
->name
);
3987 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
3988 if (!vxge_bVALn(vpath_mask
, i
, 1))
3990 vxge_debug_ll_config(VXGE_TRACE
,
3991 "%s: MTU size - %d", vdev
->ndev
->name
,
3993 config
.vp_config
[i
].mtu
);
3994 vxge_debug_init(VXGE_TRACE
,
3995 "%s: VLAN tag stripping %s", vdev
->ndev
->name
,
3997 config
.vp_config
[i
].rpa_strip_vlan_tag
3998 ? "Enabled" : "Disabled");
3999 vxge_debug_ll_config(VXGE_TRACE
,
4000 "%s: Max frags : %d", vdev
->ndev
->name
,
4002 config
.vp_config
[i
].fifo
.max_frags
);
4009 * vxge_pm_suspend - vxge power management suspend entry point
4012 static int vxge_pm_suspend(struct pci_dev
*pdev
, pm_message_t state
)
4017 * vxge_pm_resume - vxge power management resume entry point
4020 static int vxge_pm_resume(struct pci_dev
*pdev
)
4028 * vxge_io_error_detected - called when PCI error is detected
4029 * @pdev: Pointer to PCI device
4030 * @state: The current pci connection state
4032 * This function is called after a PCI bus error affecting
4033 * this device has been detected.
4035 static pci_ers_result_t
vxge_io_error_detected(struct pci_dev
*pdev
,
4036 pci_channel_state_t state
)
4038 struct __vxge_hw_device
*hldev
= pci_get_drvdata(pdev
);
4039 struct net_device
*netdev
= hldev
->ndev
;
4041 netif_device_detach(netdev
);
4043 if (state
== pci_channel_io_perm_failure
)
4044 return PCI_ERS_RESULT_DISCONNECT
;
4046 if (netif_running(netdev
)) {
4047 /* Bring down the card, while avoiding PCI I/O */
4048 do_vxge_close(netdev
, 0);
4051 pci_disable_device(pdev
);
4053 return PCI_ERS_RESULT_NEED_RESET
;
4057 * vxge_io_slot_reset - called after the pci bus has been reset.
4058 * @pdev: Pointer to PCI device
4060 * Restart the card from scratch, as if from a cold-boot.
4061 * At this point, the card has exprienced a hard reset,
4062 * followed by fixups by BIOS, and has its config space
4063 * set up identically to what it was at cold boot.
4065 static pci_ers_result_t
vxge_io_slot_reset(struct pci_dev
*pdev
)
4067 struct __vxge_hw_device
*hldev
= pci_get_drvdata(pdev
);
4068 struct net_device
*netdev
= hldev
->ndev
;
4070 struct vxgedev
*vdev
= netdev_priv(netdev
);
4072 if (pci_enable_device(pdev
)) {
4073 netdev_err(netdev
, "Cannot re-enable device after reset\n");
4074 return PCI_ERS_RESULT_DISCONNECT
;
4077 pci_set_master(pdev
);
4078 do_vxge_reset(vdev
, VXGE_LL_FULL_RESET
);
4080 return PCI_ERS_RESULT_RECOVERED
;
4084 * vxge_io_resume - called when traffic can start flowing again.
4085 * @pdev: Pointer to PCI device
4087 * This callback is called when the error recovery driver tells
4088 * us that its OK to resume normal operation.
4090 static void vxge_io_resume(struct pci_dev
*pdev
)
4092 struct __vxge_hw_device
*hldev
= pci_get_drvdata(pdev
);
4093 struct net_device
*netdev
= hldev
->ndev
;
4095 if (netif_running(netdev
)) {
4096 if (vxge_open(netdev
)) {
4098 "Can't bring device back up after reset\n");
4103 netif_device_attach(netdev
);
4106 static inline u32
vxge_get_num_vfs(u64 function_mode
)
4108 u32 num_functions
= 0;
4110 switch (function_mode
) {
4111 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
4112 case VXGE_HW_FUNCTION_MODE_SRIOV_8
:
4115 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
4118 case VXGE_HW_FUNCTION_MODE_SRIOV
:
4119 case VXGE_HW_FUNCTION_MODE_MRIOV
:
4120 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17
:
4123 case VXGE_HW_FUNCTION_MODE_SRIOV_4
:
4126 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2
:
4129 case VXGE_HW_FUNCTION_MODE_MRIOV_8
:
4130 num_functions
= 8; /* TODO */
4133 return num_functions
;
4136 int vxge_fw_upgrade(struct vxgedev
*vdev
, char *fw_name
, int override
)
4138 struct __vxge_hw_device
*hldev
= vdev
->devh
;
4139 u32 maj
, min
, bld
, cmaj
, cmin
, cbld
;
4140 enum vxge_hw_status status
;
4141 const struct firmware
*fw
;
4144 ret
= request_firmware(&fw
, fw_name
, &vdev
->pdev
->dev
);
4146 vxge_debug_init(VXGE_ERR
, "%s: Firmware file '%s' not found",
4147 VXGE_DRIVER_NAME
, fw_name
);
4151 /* Load the new firmware onto the adapter */
4152 status
= vxge_update_fw_image(hldev
, fw
->data
, fw
->size
);
4153 if (status
!= VXGE_HW_OK
) {
4154 vxge_debug_init(VXGE_ERR
,
4155 "%s: FW image download to adapter failed '%s'.",
4156 VXGE_DRIVER_NAME
, fw_name
);
4161 /* Read the version of the new firmware */
4162 status
= vxge_hw_upgrade_read_version(hldev
, &maj
, &min
, &bld
);
4163 if (status
!= VXGE_HW_OK
) {
4164 vxge_debug_init(VXGE_ERR
,
4165 "%s: Upgrade read version failed '%s'.",
4166 VXGE_DRIVER_NAME
, fw_name
);
4171 cmaj
= vdev
->config
.device_hw_info
.fw_version
.major
;
4172 cmin
= vdev
->config
.device_hw_info
.fw_version
.minor
;
4173 cbld
= vdev
->config
.device_hw_info
.fw_version
.build
;
4174 /* It's possible the version in /lib/firmware is not the latest version.
4175 * If so, we could get into a loop of trying to upgrade to the latest
4176 * and flashing the older version.
4178 if (VXGE_FW_VER(maj
, min
, bld
) == VXGE_FW_VER(cmaj
, cmin
, cbld
) &&
4184 printk(KERN_NOTICE
"Upgrade to firmware version %d.%d.%d commencing\n",
4187 /* Flash the adapter with the new firmware */
4188 status
= vxge_hw_flash_fw(hldev
);
4189 if (status
!= VXGE_HW_OK
) {
4190 vxge_debug_init(VXGE_ERR
, "%s: Upgrade commit failed '%s'.",
4191 VXGE_DRIVER_NAME
, fw_name
);
4196 printk(KERN_NOTICE
"Upgrade of firmware successful! Adapter must be "
4197 "hard reset before using, thus requiring a system reboot or a "
4198 "hotplug event.\n");
4201 release_firmware(fw
);
4205 static int vxge_probe_fw_update(struct vxgedev
*vdev
)
4211 maj
= vdev
->config
.device_hw_info
.fw_version
.major
;
4212 min
= vdev
->config
.device_hw_info
.fw_version
.minor
;
4213 bld
= vdev
->config
.device_hw_info
.fw_version
.build
;
4215 if (VXGE_FW_VER(maj
, min
, bld
) == VXGE_CERT_FW_VER
)
4218 /* Ignore the build number when determining if the current firmware is
4219 * "too new" to load the driver
4221 if (VXGE_FW_VER(maj
, min
, 0) > VXGE_CERT_FW_VER
) {
4222 vxge_debug_init(VXGE_ERR
, "%s: Firmware newer than last known "
4223 "version, unable to load driver\n",
4228 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4229 * work with this driver.
4231 if (VXGE_FW_VER(maj
, min
, bld
) <= VXGE_FW_DEAD_VER
) {
4232 vxge_debug_init(VXGE_ERR
, "%s: Firmware %d.%d.%d cannot be "
4233 "upgraded\n", VXGE_DRIVER_NAME
, maj
, min
, bld
);
4237 /* If file not specified, determine gPXE or not */
4238 if (VXGE_FW_VER(maj
, min
, bld
) >= VXGE_EPROM_FW_VER
) {
4240 for (i
= 0; i
< VXGE_HW_MAX_ROM_IMAGES
; i
++)
4241 if (vdev
->devh
->eprom_versions
[i
]) {
4247 fw_name
= "vxge/X3fw-pxe.ncf";
4249 fw_name
= "vxge/X3fw.ncf";
4251 ret
= vxge_fw_upgrade(vdev
, fw_name
, 0);
4252 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4253 * probe, so ignore them
4255 if (ret
!= -EINVAL
&& ret
!= -ENOENT
)
4260 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR
, VXGE_CERT_FW_VER_MINOR
, 0) >
4261 VXGE_FW_VER(maj
, min
, 0)) {
4262 vxge_debug_init(VXGE_ERR
, "%s: Firmware %d.%d.%d is too old to"
4263 " be used with this driver.",
4264 VXGE_DRIVER_NAME
, maj
, min
, bld
);
4271 static int is_sriov_initialized(struct pci_dev
*pdev
)
4276 pos
= pci_find_ext_capability(pdev
, PCI_EXT_CAP_ID_SRIOV
);
4278 pci_read_config_word(pdev
, pos
+ PCI_SRIOV_CTRL
, &ctrl
);
4279 if (ctrl
& PCI_SRIOV_CTRL_VFE
)
4285 static const struct vxge_hw_uld_cbs vxge_callbacks
= {
4286 .link_up
= vxge_callback_link_up
,
4287 .link_down
= vxge_callback_link_down
,
4288 .crit_err
= vxge_callback_crit_err
,
4293 * @pdev : structure containing the PCI related information of the device.
4294 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4296 * This function is called when a new PCI device gets detected and initializes
4299 * returns 0 on success and negative on failure.
4303 vxge_probe(struct pci_dev
*pdev
, const struct pci_device_id
*pre
)
4305 struct __vxge_hw_device
*hldev
;
4306 enum vxge_hw_status status
;
4310 struct vxgedev
*vdev
;
4311 struct vxge_config
*ll_config
= NULL
;
4312 struct vxge_hw_device_config
*device_config
= NULL
;
4313 struct vxge_hw_device_attr attr
;
4314 int i
, j
, no_of_vpath
= 0, max_vpath_supported
= 0;
4316 struct vxge_mac_addrs
*entry
;
4317 static int bus
= -1, device
= -1;
4320 enum vxge_hw_status is_privileged
;
4324 vxge_debug_entryexit(VXGE_TRACE
, "%s:%d", __func__
, __LINE__
);
4327 /* In SRIOV-17 mode, functions of the same adapter
4328 * can be deployed on different buses
4330 if (((bus
!= pdev
->bus
->number
) || (device
!= PCI_SLOT(pdev
->devfn
))) &&
4334 bus
= pdev
->bus
->number
;
4335 device
= PCI_SLOT(pdev
->devfn
);
4338 if (driver_config
->config_dev_cnt
&&
4339 (driver_config
->config_dev_cnt
!=
4340 driver_config
->total_dev_cnt
))
4341 vxge_debug_init(VXGE_ERR
,
4342 "%s: Configured %d of %d devices",
4344 driver_config
->config_dev_cnt
,
4345 driver_config
->total_dev_cnt
);
4346 driver_config
->config_dev_cnt
= 0;
4347 driver_config
->total_dev_cnt
= 0;
4350 /* Now making the CPU based no of vpath calculation
4351 * applicable for individual functions as well.
4353 driver_config
->g_no_cpus
= 0;
4354 driver_config
->vpath_per_dev
= max_config_vpath
;
4356 driver_config
->total_dev_cnt
++;
4357 if (++driver_config
->config_dev_cnt
> max_config_dev
) {
4362 device_config
= kzalloc(sizeof(struct vxge_hw_device_config
),
4364 if (!device_config
) {
4366 vxge_debug_init(VXGE_ERR
,
4367 "device_config : malloc failed %s %d",
4368 __FILE__
, __LINE__
);
4372 ll_config
= kzalloc(sizeof(struct vxge_config
), GFP_KERNEL
);
4375 vxge_debug_init(VXGE_ERR
,
4376 "device_config : malloc failed %s %d",
4377 __FILE__
, __LINE__
);
4380 ll_config
->tx_steering_type
= TX_MULTIQ_STEERING
;
4381 ll_config
->intr_type
= MSI_X
;
4382 ll_config
->napi_weight
= NEW_NAPI_WEIGHT
;
4383 ll_config
->rth_steering
= RTH_STEERING
;
4385 /* get the default configuration parameters */
4386 vxge_hw_device_config_default_get(device_config
);
4388 /* initialize configuration parameters */
4389 vxge_device_config_init(device_config
, &ll_config
->intr_type
);
4391 ret
= pci_enable_device(pdev
);
4393 vxge_debug_init(VXGE_ERR
,
4394 "%s : can not enable PCI device", __func__
);
4398 if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(64))) {
4399 vxge_debug_ll_config(VXGE_TRACE
,
4400 "%s : using 64bit DMA", __func__
);
4404 if (pci_set_consistent_dma_mask(pdev
,
4405 DMA_BIT_MASK(64))) {
4406 vxge_debug_init(VXGE_ERR
,
4407 "%s : unable to obtain 64bit DMA for "
4408 "consistent allocations", __func__
);
4412 } else if (!pci_set_dma_mask(pdev
, DMA_BIT_MASK(32))) {
4413 vxge_debug_ll_config(VXGE_TRACE
,
4414 "%s : using 32bit DMA", __func__
);
4420 ret
= pci_request_region(pdev
, 0, VXGE_DRIVER_NAME
);
4422 vxge_debug_init(VXGE_ERR
,
4423 "%s : request regions failed", __func__
);
4427 pci_set_master(pdev
);
4429 attr
.bar0
= pci_ioremap_bar(pdev
, 0);
4431 vxge_debug_init(VXGE_ERR
,
4432 "%s : cannot remap io memory bar0", __func__
);
4436 vxge_debug_ll_config(VXGE_TRACE
,
4437 "pci ioremap bar0: %p:0x%llx",
4439 (unsigned long long)pci_resource_start(pdev
, 0));
4441 status
= vxge_hw_device_hw_info_get(attr
.bar0
,
4442 &ll_config
->device_hw_info
);
4443 if (status
!= VXGE_HW_OK
) {
4444 vxge_debug_init(VXGE_ERR
,
4445 "%s: Reading of hardware info failed."
4446 "Please try upgrading the firmware.", VXGE_DRIVER_NAME
);
4451 vpath_mask
= ll_config
->device_hw_info
.vpath_mask
;
4452 if (vpath_mask
== 0) {
4453 vxge_debug_ll_config(VXGE_TRACE
,
4454 "%s: No vpaths available in device", VXGE_DRIVER_NAME
);
4459 vxge_debug_ll_config(VXGE_TRACE
,
4460 "%s:%d Vpath mask = %llx", __func__
, __LINE__
,
4461 (unsigned long long)vpath_mask
);
4463 function_mode
= ll_config
->device_hw_info
.function_mode
;
4464 host_type
= ll_config
->device_hw_info
.host_type
;
4465 is_privileged
= __vxge_hw_device_is_privilaged(host_type
,
4466 ll_config
->device_hw_info
.func_id
);
4468 /* Check how many vpaths are available */
4469 for (i
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4470 if (!((vpath_mask
) & vxge_mBIT(i
)))
4472 max_vpath_supported
++;
4476 num_vfs
= vxge_get_num_vfs(function_mode
) - 1;
4478 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4479 if (is_sriov(function_mode
) && !is_sriov_initialized(pdev
) &&
4480 (ll_config
->intr_type
!= INTA
)) {
4481 ret
= pci_enable_sriov(pdev
, num_vfs
);
4483 vxge_debug_ll_config(VXGE_ERR
,
4484 "Failed in enabling SRIOV mode: %d\n", ret
);
4485 /* No need to fail out, as an error here is non-fatal */
4489 * Configure vpaths and get driver configured number of vpaths
4490 * which is less than or equal to the maximum vpaths per function.
4492 no_of_vpath
= vxge_config_vpaths(device_config
, vpath_mask
, ll_config
);
4494 vxge_debug_ll_config(VXGE_ERR
,
4495 "%s: No more vpaths to configure", VXGE_DRIVER_NAME
);
4500 /* Setting driver callbacks */
4501 attr
.uld_callbacks
= &vxge_callbacks
;
4503 status
= vxge_hw_device_initialize(&hldev
, &attr
, device_config
);
4504 if (status
!= VXGE_HW_OK
) {
4505 vxge_debug_init(VXGE_ERR
,
4506 "Failed to initialize device (%d)", status
);
4511 if (VXGE_FW_VER(ll_config
->device_hw_info
.fw_version
.major
,
4512 ll_config
->device_hw_info
.fw_version
.minor
,
4513 ll_config
->device_hw_info
.fw_version
.build
) >=
4514 VXGE_EPROM_FW_VER
) {
4515 struct eprom_image img
[VXGE_HW_MAX_ROM_IMAGES
];
4517 status
= vxge_hw_vpath_eprom_img_ver_get(hldev
, img
);
4518 if (status
!= VXGE_HW_OK
) {
4519 vxge_debug_init(VXGE_ERR
, "%s: Reading of EPROM failed",
4521 /* This is a non-fatal error, continue */
4524 for (i
= 0; i
< VXGE_HW_MAX_ROM_IMAGES
; i
++) {
4525 hldev
->eprom_versions
[i
] = img
[i
].version
;
4526 if (!img
[i
].is_valid
)
4528 vxge_debug_init(VXGE_TRACE
, "%s: EPROM %d, version "
4529 "%d.%d.%d.%d", VXGE_DRIVER_NAME
, i
,
4530 VXGE_EPROM_IMG_MAJOR(img
[i
].version
),
4531 VXGE_EPROM_IMG_MINOR(img
[i
].version
),
4532 VXGE_EPROM_IMG_FIX(img
[i
].version
),
4533 VXGE_EPROM_IMG_BUILD(img
[i
].version
));
4537 /* if FCS stripping is not disabled in MAC fail driver load */
4538 status
= vxge_hw_vpath_strip_fcs_check(hldev
, vpath_mask
);
4539 if (status
!= VXGE_HW_OK
) {
4540 vxge_debug_init(VXGE_ERR
, "%s: FCS stripping is enabled in MAC"
4541 " failing driver load", VXGE_DRIVER_NAME
);
4546 /* Always enable HWTS. This will always cause the FCS to be invalid,
4547 * due to the fact that HWTS is using the FCS as the location of the
4548 * timestamp. The HW FCS checking will still correctly determine if
4549 * there is a valid checksum, and the FCS is being removed by the driver
4550 * anyway. So no fucntionality is being lost. Since it is always
4551 * enabled, we now simply use the ioctl call to set whether or not the
4552 * driver should be paying attention to the HWTS.
4554 if (is_privileged
== VXGE_HW_OK
) {
4555 status
= vxge_timestamp_config(hldev
);
4556 if (status
!= VXGE_HW_OK
) {
4557 vxge_debug_init(VXGE_ERR
, "%s: HWTS enable failed",
4564 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4566 /* set private device info */
4567 pci_set_drvdata(pdev
, hldev
);
4569 ll_config
->fifo_indicate_max_pkts
= VXGE_FIFO_INDICATE_MAX_PKTS
;
4570 ll_config
->addr_learn_en
= addr_learn_en
;
4571 ll_config
->rth_algorithm
= RTH_ALG_JENKINS
;
4572 ll_config
->rth_hash_type_tcpipv4
= 1;
4573 ll_config
->rth_hash_type_ipv4
= 0;
4574 ll_config
->rth_hash_type_tcpipv6
= 0;
4575 ll_config
->rth_hash_type_ipv6
= 0;
4576 ll_config
->rth_hash_type_tcpipv6ex
= 0;
4577 ll_config
->rth_hash_type_ipv6ex
= 0;
4578 ll_config
->rth_bkt_sz
= RTH_BUCKET_SIZE
;
4579 ll_config
->tx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4580 ll_config
->rx_pause_enable
= VXGE_PAUSE_CTRL_ENABLE
;
4582 ret
= vxge_device_register(hldev
, ll_config
, high_dma
, no_of_vpath
,
4589 ret
= vxge_probe_fw_update(vdev
);
4593 vxge_hw_device_debug_set(hldev
, VXGE_TRACE
, VXGE_COMPONENT_LL
);
4594 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4595 vxge_hw_device_trace_level_get(hldev
));
4597 /* set private HW device info */
4598 vdev
->mtu
= VXGE_HW_DEFAULT_MTU
;
4599 vdev
->bar0
= attr
.bar0
;
4600 vdev
->max_vpath_supported
= max_vpath_supported
;
4601 vdev
->no_of_vpath
= no_of_vpath
;
4603 /* Virtual Path count */
4604 for (i
= 0, j
= 0; i
< VXGE_HW_MAX_VIRTUAL_PATHS
; i
++) {
4605 if (!vxge_bVALn(vpath_mask
, i
, 1))
4607 if (j
>= vdev
->no_of_vpath
)
4610 vdev
->vpaths
[j
].is_configured
= 1;
4611 vdev
->vpaths
[j
].device_id
= i
;
4612 vdev
->vpaths
[j
].ring
.driver_id
= j
;
4613 vdev
->vpaths
[j
].vdev
= vdev
;
4614 vdev
->vpaths
[j
].max_mac_addr_cnt
= max_mac_vpath
;
4615 memcpy((u8
*)vdev
->vpaths
[j
].macaddr
,
4616 ll_config
->device_hw_info
.mac_addrs
[i
],
4619 /* Initialize the mac address list header */
4620 INIT_LIST_HEAD(&vdev
->vpaths
[j
].mac_addr_list
);
4622 vdev
->vpaths
[j
].mac_addr_cnt
= 0;
4623 vdev
->vpaths
[j
].mcast_addr_cnt
= 0;
4626 vdev
->exec_mode
= VXGE_EXEC_MODE_DISABLE
;
4627 vdev
->max_config_port
= max_config_port
;
4629 vdev
->vlan_tag_strip
= vlan_tag_strip
;
4631 /* map the hashing selector table to the configured vpaths */
4632 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4633 vdev
->vpath_selector
[i
] = vpath_selector
[i
];
4635 macaddr
= (u8
*)vdev
->vpaths
[0].macaddr
;
4637 ll_config
->device_hw_info
.serial_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4638 ll_config
->device_hw_info
.product_desc
[VXGE_HW_INFO_LEN
- 1] = '\0';
4639 ll_config
->device_hw_info
.part_number
[VXGE_HW_INFO_LEN
- 1] = '\0';
4641 vxge_debug_init(VXGE_TRACE
, "%s: SERIAL NUMBER: %s",
4642 vdev
->ndev
->name
, ll_config
->device_hw_info
.serial_number
);
4644 vxge_debug_init(VXGE_TRACE
, "%s: PART NUMBER: %s",
4645 vdev
->ndev
->name
, ll_config
->device_hw_info
.part_number
);
4647 vxge_debug_init(VXGE_TRACE
, "%s: Neterion %s Server Adapter",
4648 vdev
->ndev
->name
, ll_config
->device_hw_info
.product_desc
);
4650 vxge_debug_init(VXGE_TRACE
, "%s: MAC ADDR: %pM",
4651 vdev
->ndev
->name
, macaddr
);
4653 vxge_debug_init(VXGE_TRACE
, "%s: Link Width x%d",
4654 vdev
->ndev
->name
, vxge_hw_device_link_width_get(hldev
));
4656 vxge_debug_init(VXGE_TRACE
,
4657 "%s: Firmware version : %s Date : %s", vdev
->ndev
->name
,
4658 ll_config
->device_hw_info
.fw_version
.version
,
4659 ll_config
->device_hw_info
.fw_date
.date
);
4662 switch (ll_config
->device_hw_info
.function_mode
) {
4663 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION
:
4664 vxge_debug_init(VXGE_TRACE
,
4665 "%s: Single Function Mode Enabled", vdev
->ndev
->name
);
4667 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
:
4668 vxge_debug_init(VXGE_TRACE
,
4669 "%s: Multi Function Mode Enabled", vdev
->ndev
->name
);
4671 case VXGE_HW_FUNCTION_MODE_SRIOV
:
4672 vxge_debug_init(VXGE_TRACE
,
4673 "%s: Single Root IOV Mode Enabled", vdev
->ndev
->name
);
4675 case VXGE_HW_FUNCTION_MODE_MRIOV
:
4676 vxge_debug_init(VXGE_TRACE
,
4677 "%s: Multi Root IOV Mode Enabled", vdev
->ndev
->name
);
4682 vxge_print_parm(vdev
, vpath_mask
);
4684 /* Store the fw version for ethttool option */
4685 strcpy(vdev
->fw_version
, ll_config
->device_hw_info
.fw_version
.version
);
4686 memcpy(vdev
->ndev
->dev_addr
, (u8
*)vdev
->vpaths
[0].macaddr
, ETH_ALEN
);
4688 /* Copy the station mac address to the list */
4689 for (i
= 0; i
< vdev
->no_of_vpath
; i
++) {
4690 entry
= kzalloc(sizeof(struct vxge_mac_addrs
), GFP_KERNEL
);
4691 if (NULL
== entry
) {
4692 vxge_debug_init(VXGE_ERR
,
4693 "%s: mac_addr_list : memory allocation failed",
4698 macaddr
= (u8
*)&entry
->macaddr
;
4699 memcpy(macaddr
, vdev
->ndev
->dev_addr
, ETH_ALEN
);
4700 list_add(&entry
->item
, &vdev
->vpaths
[i
].mac_addr_list
);
4701 vdev
->vpaths
[i
].mac_addr_cnt
= 1;
4704 kfree(device_config
);
4707 * INTA is shared in multi-function mode. This is unlike the INTA
4708 * implementation in MR mode, where each VH has its own INTA message.
4709 * - INTA is masked (disabled) as long as at least one function sets
4710 * its TITAN_MASK_ALL_INT.ALARM bit.
4711 * - INTA is unmasked (enabled) when all enabled functions have cleared
4712 * their own TITAN_MASK_ALL_INT.ALARM bit.
4713 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4714 * Though this driver leaves the top level interrupts unmasked while
4715 * leaving the required module interrupt bits masked on exit, there
4716 * could be a rougue driver around that does not follow this procedure
4717 * resulting in a failure to generate interrupts. The following code is
4718 * present to prevent such a failure.
4721 if (ll_config
->device_hw_info
.function_mode
==
4722 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION
)
4723 if (vdev
->config
.intr_type
== INTA
)
4724 vxge_hw_device_unmask_all(hldev
);
4726 vxge_debug_entryexit(VXGE_TRACE
, "%s: %s:%d Exiting...",
4727 vdev
->ndev
->name
, __func__
, __LINE__
);
4729 vxge_hw_device_debug_set(hldev
, VXGE_ERR
, VXGE_COMPONENT_LL
);
4730 VXGE_COPY_DEBUG_INFO_TO_LL(vdev
, vxge_hw_device_error_level_get(hldev
),
4731 vxge_hw_device_trace_level_get(hldev
));
4737 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4738 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4740 vxge_device_unregister(hldev
);
4742 vxge_hw_device_terminate(hldev
);
4743 pci_disable_sriov(pdev
);
4747 pci_release_region(pdev
, 0);
4749 pci_disable_device(pdev
);
4752 kfree(device_config
);
4753 driver_config
->config_dev_cnt
--;
4754 driver_config
->total_dev_cnt
--;
4759 * vxge_rem_nic - Free the PCI device
4760 * @pdev: structure containing the PCI related information of the device.
4761 * Description: This function is called by the Pci subsystem to release a
4762 * PCI device and free up all resource held up by the device.
4764 static void vxge_remove(struct pci_dev
*pdev
)
4766 struct __vxge_hw_device
*hldev
;
4767 struct vxgedev
*vdev
;
4770 hldev
= pci_get_drvdata(pdev
);
4774 vdev
= netdev_priv(hldev
->ndev
);
4776 vxge_debug_entryexit(vdev
->level_trace
, "%s:%d", __func__
, __LINE__
);
4777 vxge_debug_init(vdev
->level_trace
, "%s : removing PCI device...",
4780 for (i
= 0; i
< vdev
->no_of_vpath
; i
++)
4781 vxge_free_mac_add_list(&vdev
->vpaths
[i
]);
4783 vxge_device_unregister(hldev
);
4784 /* Do not call pci_disable_sriov here, as it will break child devices */
4785 vxge_hw_device_terminate(hldev
);
4786 iounmap(vdev
->bar0
);
4787 pci_release_region(pdev
, 0);
4788 pci_disable_device(pdev
);
4789 driver_config
->config_dev_cnt
--;
4790 driver_config
->total_dev_cnt
--;
4792 vxge_debug_init(vdev
->level_trace
, "%s:%d Device unregistered",
4793 __func__
, __LINE__
);
4794 vxge_debug_entryexit(vdev
->level_trace
, "%s:%d Exiting...", __func__
,
4798 static const struct pci_error_handlers vxge_err_handler
= {
4799 .error_detected
= vxge_io_error_detected
,
4800 .slot_reset
= vxge_io_slot_reset
,
4801 .resume
= vxge_io_resume
,
4804 static struct pci_driver vxge_driver
= {
4805 .name
= VXGE_DRIVER_NAME
,
4806 .id_table
= vxge_id_table
,
4807 .probe
= vxge_probe
,
4808 .remove
= vxge_remove
,
4810 .suspend
= vxge_pm_suspend
,
4811 .resume
= vxge_pm_resume
,
4813 .err_handler
= &vxge_err_handler
,
4821 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4822 pr_info("Driver version: %s\n", DRV_VERSION
);
4826 driver_config
= kzalloc(sizeof(struct vxge_drv_config
), GFP_KERNEL
);
4830 ret
= pci_register_driver(&vxge_driver
);
4832 kfree(driver_config
);
4836 if (driver_config
->config_dev_cnt
&&
4837 (driver_config
->config_dev_cnt
!= driver_config
->total_dev_cnt
))
4838 vxge_debug_init(VXGE_ERR
,
4839 "%s: Configured %d of %d devices",
4840 VXGE_DRIVER_NAME
, driver_config
->config_dev_cnt
,
4841 driver_config
->total_dev_cnt
);
4849 pci_unregister_driver(&vxge_driver
);
4850 kfree(driver_config
);
4852 module_init(vxge_starter
);
4853 module_exit(vxge_closer
);