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 16
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_consume_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 = dma_map_single(&ring->pdev->dev, rx_priv->skb_data,
245 rx_priv->data_size, DMA_FROM_DEVICE);
247 if (unlikely(dma_mapping_error(&ring->pdev->dev, 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 dma_sync_single_for_device(&ring->pdev->dev, rx_priv->data_dma,
327 rx_priv->data_size, DMA_FROM_DEVICE);
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 dma_unmap_single(&ring->pdev->dev,
432 vxge_hw_ring_rxd_pre_post(ringh, dtr);
433 vxge_post(&dtr_cnt, &first_dtr, dtr,
436 dev_kfree_skb(rx_priv->skb);
438 rx_priv->data_size = data_size;
439 vxge_re_pre_post(dtr, ring, rx_priv);
441 vxge_post(&dtr_cnt, &first_dtr, dtr,
443 ring->stats.rx_dropped++;
447 vxge_re_pre_post(dtr, ring, rx_priv);
449 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
450 ring->stats.rx_dropped++;
454 struct sk_buff *skb_up;
456 skb_up = netdev_alloc_skb(dev, pkt_length +
457 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
458 if (skb_up != NULL) {
460 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
462 dma_sync_single_for_cpu(&ring->pdev->dev,
466 vxge_debug_mem(VXGE_TRACE,
467 "%s: %s:%d skb_up = %p",
468 ring->ndev->name, __func__,
470 memcpy(skb_up->data, skb->data, pkt_length);
472 vxge_re_pre_post(dtr, ring, rx_priv);
474 vxge_post(&dtr_cnt, &first_dtr, dtr,
476 /* will netif_rx small SKB instead */
478 skb_put(skb, pkt_length);
480 vxge_re_pre_post(dtr, ring, rx_priv);
482 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
483 vxge_debug_rx(VXGE_ERR,
484 "%s: vxge_rx_1b_compl: out of "
485 "memory", dev->name);
486 ring->stats.skb_alloc_fail++;
491 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
492 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
493 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
494 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
495 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
496 skb->ip_summed = CHECKSUM_UNNECESSARY;
498 skb_checksum_none_assert(skb);
502 struct skb_shared_hwtstamps *skb_hwts;
503 u32 ns = *(u32 *)(skb->head + pkt_length);
505 skb_hwts = skb_hwtstamps(skb);
506 skb_hwts->hwtstamp = ns_to_ktime(ns);
509 /* rth_hash_type and rth_it_hit are non-zero regardless of
510 * whether rss is enabled. Only the rth_value is zero/non-zero
511 * if rss is disabled/enabled, so key off of that.
513 if (ext_info.rth_value)
514 skb_set_hash(skb, ext_info.rth_value,
517 vxge_rx_complete(ring, skb, ext_info.vlan,
518 pkt_length, &ext_info);
521 ring->pkts_processed++;
525 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
526 &t_code) == VXGE_HW_OK);
529 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
532 vxge_debug_entryexit(VXGE_TRACE,
541 * If an interrupt was raised to indicate DMA complete of the Tx packet,
542 * this function is called. It identifies the last TxD whose buffer was
543 * freed and frees all skbs whose data have already DMA'ed into the NICs
546 static enum vxge_hw_status
547 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
548 enum vxge_hw_fifo_tcode t_code, void *userdata,
549 struct sk_buff ***skb_ptr, int nr_skb, int *more)
551 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
552 struct sk_buff *skb, **done_skb = *skb_ptr;
555 vxge_debug_entryexit(VXGE_TRACE,
556 "%s:%d Entered....", __func__, __LINE__);
562 struct vxge_tx_priv *txd_priv =
563 vxge_hw_fifo_txdl_private_get(dtr);
566 frg_cnt = skb_shinfo(skb)->nr_frags;
567 frag = &skb_shinfo(skb)->frags[0];
569 vxge_debug_tx(VXGE_TRACE,
570 "%s: %s:%d fifo_hw = %p dtr = %p "
571 "tcode = 0x%x", fifo->ndev->name, __func__,
572 __LINE__, fifo_hw, dtr, t_code);
573 /* check skb validity */
575 vxge_debug_tx(VXGE_TRACE,
576 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
577 fifo->ndev->name, __func__, __LINE__,
578 skb, txd_priv, frg_cnt);
579 if (unlikely(t_code)) {
580 fifo->stats.tx_errors++;
581 vxge_debug_tx(VXGE_ERR,
582 "%s: tx: dtr %p completed due to "
583 "error t_code %01x", fifo->ndev->name,
585 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
588 /* for unfragmented skb */
589 dma_unmap_single(&fifo->pdev->dev, txd_priv->dma_buffers[i++],
590 skb_headlen(skb), DMA_TO_DEVICE);
592 for (j = 0; j < frg_cnt; j++) {
593 dma_unmap_page(&fifo->pdev->dev,
594 txd_priv->dma_buffers[i++],
595 skb_frag_size(frag), DMA_TO_DEVICE);
599 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
601 /* Updating the statistics block */
602 u64_stats_update_begin(&fifo->stats.syncp);
603 fifo->stats.tx_frms++;
604 fifo->stats.tx_bytes += skb->len;
605 u64_stats_update_end(&fifo->stats.syncp);
615 if (pkt_cnt > fifo->indicate_max_pkts)
618 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
619 &dtr, &t_code) == VXGE_HW_OK);
622 if (netif_tx_queue_stopped(fifo->txq))
623 netif_tx_wake_queue(fifo->txq);
625 vxge_debug_entryexit(VXGE_TRACE,
626 "%s: %s:%d Exiting...",
627 fifo->ndev->name, __func__, __LINE__);
631 /* select a vpath to transmit the packet */
632 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
634 u16 queue_len, counter = 0;
635 if (skb->protocol == htons(ETH_P_IP)) {
641 if (!ip_is_fragment(ip)) {
642 th = (struct tcphdr *)(((unsigned char *)ip) +
645 queue_len = vdev->no_of_vpath;
646 counter = (ntohs(th->source) +
648 vdev->vpath_selector[queue_len - 1];
649 if (counter >= queue_len)
650 counter = queue_len - 1;
656 static enum vxge_hw_status vxge_search_mac_addr_in_list(
657 struct vxge_vpath *vpath, u64 del_mac)
659 struct list_head *entry, *next;
660 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
661 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
667 static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
669 struct vxge_mac_addrs *new_mac_entry;
670 u8 *mac_address = NULL;
672 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
675 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
676 if (!new_mac_entry) {
677 vxge_debug_mem(VXGE_ERR,
678 "%s: memory allocation failed",
683 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
685 /* Copy the new mac address to the list */
686 mac_address = (u8 *)&new_mac_entry->macaddr;
687 memcpy(mac_address, mac->macaddr, ETH_ALEN);
689 new_mac_entry->state = mac->state;
690 vpath->mac_addr_cnt++;
692 if (is_multicast_ether_addr(mac->macaddr))
693 vpath->mcast_addr_cnt++;
698 /* Add a mac address to DA table */
699 static enum vxge_hw_status
700 vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
702 enum vxge_hw_status status = VXGE_HW_OK;
703 struct vxge_vpath *vpath;
704 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
706 if (is_multicast_ether_addr(mac->macaddr))
707 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
709 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
711 vpath = &vdev->vpaths[mac->vpath_no];
712 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
713 mac->macmask, duplicate_mode);
714 if (status != VXGE_HW_OK) {
715 vxge_debug_init(VXGE_ERR,
716 "DA config add entry failed for vpath:%d",
719 if (FALSE == vxge_mac_list_add(vpath, mac))
725 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
727 struct macInfo mac_info;
728 u8 *mac_address = NULL;
729 u64 mac_addr = 0, vpath_vector = 0;
731 enum vxge_hw_status status = VXGE_HW_OK;
732 struct vxge_vpath *vpath = NULL;
734 mac_address = (u8 *)&mac_addr;
735 memcpy(mac_address, mac_header, ETH_ALEN);
737 /* Is this mac address already in the list? */
738 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
739 vpath = &vdev->vpaths[vpath_idx];
740 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
744 memset(&mac_info, 0, sizeof(struct macInfo));
745 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
747 /* Any vpath has room to add mac address to its da table? */
748 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
749 vpath = &vdev->vpaths[vpath_idx];
750 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
751 /* Add this mac address to this vpath */
752 mac_info.vpath_no = vpath_idx;
753 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
754 status = vxge_add_mac_addr(vdev, &mac_info);
755 if (status != VXGE_HW_OK)
761 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
763 mac_info.vpath_no = vpath_idx;
764 /* Is the first vpath already selected as catch-basin ? */
765 vpath = &vdev->vpaths[vpath_idx];
766 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
767 /* Add this mac address to this vpath */
768 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
773 /* Select first vpath as catch-basin */
774 vpath_vector = vxge_mBIT(vpath->device_id);
775 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
776 vxge_hw_mgmt_reg_type_mrpcim,
779 struct vxge_hw_mrpcim_reg,
782 if (status != VXGE_HW_OK) {
783 vxge_debug_tx(VXGE_ERR,
784 "%s: Unable to set the vpath-%d in catch-basin mode",
785 VXGE_DRIVER_NAME, vpath->device_id);
789 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
797 * @skb : the socket buffer containing the Tx data.
798 * @dev : device pointer.
800 * This function is the Tx entry point of the driver. Neterion NIC supports
801 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
804 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
806 struct vxge_fifo *fifo = NULL;
809 struct vxgedev *vdev = NULL;
810 enum vxge_hw_status status;
811 int frg_cnt, first_frg_len;
813 int i = 0, j = 0, avail;
815 struct vxge_tx_priv *txdl_priv = NULL;
816 struct __vxge_hw_fifo *fifo_hw;
820 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
821 dev->name, __func__, __LINE__);
823 /* A buffer with no data will be dropped */
824 if (unlikely(skb->len <= 0)) {
825 vxge_debug_tx(VXGE_ERR,
826 "%s: Buffer has no data..", dev->name);
827 dev_kfree_skb_any(skb);
831 vdev = netdev_priv(dev);
833 if (unlikely(!is_vxge_card_up(vdev))) {
834 vxge_debug_tx(VXGE_ERR,
835 "%s: vdev not initialized", dev->name);
836 dev_kfree_skb_any(skb);
840 if (vdev->config.addr_learn_en) {
841 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
842 if (vpath_no == -EPERM) {
843 vxge_debug_tx(VXGE_ERR,
844 "%s: Failed to store the mac address",
846 dev_kfree_skb_any(skb);
851 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
852 vpath_no = skb_get_queue_mapping(skb);
853 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
854 vpath_no = vxge_get_vpath_no(vdev, skb);
856 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
858 if (vpath_no >= vdev->no_of_vpath)
861 fifo = &vdev->vpaths[vpath_no].fifo;
862 fifo_hw = fifo->handle;
864 if (netif_tx_queue_stopped(fifo->txq))
865 return NETDEV_TX_BUSY;
867 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
869 vxge_debug_tx(VXGE_ERR,
870 "%s: No free TXDs available", dev->name);
871 fifo->stats.txd_not_free++;
875 /* Last TXD? Stop tx queue to avoid dropping packets. TX
876 * completion will resume the queue.
879 netif_tx_stop_queue(fifo->txq);
881 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
882 if (unlikely(status != VXGE_HW_OK)) {
883 vxge_debug_tx(VXGE_ERR,
884 "%s: Out of descriptors .", dev->name);
885 fifo->stats.txd_out_of_desc++;
889 vxge_debug_tx(VXGE_TRACE,
890 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
891 dev->name, __func__, __LINE__,
892 fifo_hw, dtr, dtr_priv);
894 if (skb_vlan_tag_present(skb)) {
895 u16 vlan_tag = skb_vlan_tag_get(skb);
896 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
899 first_frg_len = skb_headlen(skb);
901 dma_pointer = dma_map_single(&fifo->pdev->dev, skb->data,
902 first_frg_len, DMA_TO_DEVICE);
904 if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer))) {
905 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
906 fifo->stats.pci_map_fail++;
910 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
911 txdl_priv->skb = skb;
912 txdl_priv->dma_buffers[j] = dma_pointer;
914 frg_cnt = skb_shinfo(skb)->nr_frags;
915 vxge_debug_tx(VXGE_TRACE,
916 "%s: %s:%d skb = %p txdl_priv = %p "
917 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
918 __func__, __LINE__, skb, txdl_priv,
919 frg_cnt, (unsigned long long)dma_pointer);
921 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
924 frag = &skb_shinfo(skb)->frags[0];
925 for (i = 0; i < frg_cnt; i++) {
926 /* ignore 0 length fragment */
927 if (!skb_frag_size(frag))
930 dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
931 0, skb_frag_size(frag),
934 if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
936 vxge_debug_tx(VXGE_TRACE,
937 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
938 dev->name, __func__, __LINE__, i,
939 (unsigned long long)dma_pointer);
941 txdl_priv->dma_buffers[j] = dma_pointer;
942 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
943 skb_frag_size(frag));
947 offload_type = vxge_offload_type(skb);
949 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
950 int mss = vxge_tcp_mss(skb);
952 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
953 dev->name, __func__, __LINE__, mss);
954 vxge_hw_fifo_txdl_mss_set(dtr, mss);
956 vxge_assert(skb->len <=
957 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
963 if (skb->ip_summed == CHECKSUM_PARTIAL)
964 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
965 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
966 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
967 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
969 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
971 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
972 dev->name, __func__, __LINE__);
976 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
979 frag = &skb_shinfo(skb)->frags[0];
981 dma_unmap_single(&fifo->pdev->dev, txdl_priv->dma_buffers[j++],
982 skb_headlen(skb), DMA_TO_DEVICE);
985 dma_unmap_page(&fifo->pdev->dev, txdl_priv->dma_buffers[j],
986 skb_frag_size(frag), DMA_TO_DEVICE);
990 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
992 netif_tx_stop_queue(fifo->txq);
993 dev_kfree_skb_any(skb);
1001 * Function will be called by hw function to abort all outstanding receive
1005 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1007 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1008 struct vxge_rx_priv *rx_priv =
1009 vxge_hw_ring_rxd_private_get(dtrh);
1011 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1012 ring->ndev->name, __func__, __LINE__);
1013 if (state != VXGE_HW_RXD_STATE_POSTED)
1016 dma_unmap_single(&ring->pdev->dev, rx_priv->data_dma,
1017 rx_priv->data_size, DMA_FROM_DEVICE);
1019 dev_kfree_skb(rx_priv->skb);
1020 rx_priv->skb_data = NULL;
1022 vxge_debug_entryexit(VXGE_TRACE,
1023 "%s: %s:%d Exiting...",
1024 ring->ndev->name, __func__, __LINE__);
1030 * Function will be called to abort all outstanding tx descriptors
1033 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1035 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1037 int i = 0, j, frg_cnt;
1038 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1039 struct sk_buff *skb = txd_priv->skb;
1041 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1043 if (state != VXGE_HW_TXDL_STATE_POSTED)
1046 /* check skb validity */
1048 frg_cnt = skb_shinfo(skb)->nr_frags;
1049 frag = &skb_shinfo(skb)->frags[0];
1051 /* for unfragmented skb */
1052 dma_unmap_single(&fifo->pdev->dev, txd_priv->dma_buffers[i++],
1053 skb_headlen(skb), DMA_TO_DEVICE);
1055 for (j = 0; j < frg_cnt; j++) {
1056 dma_unmap_page(&fifo->pdev->dev, txd_priv->dma_buffers[i++],
1057 skb_frag_size(frag), DMA_TO_DEVICE);
1063 vxge_debug_entryexit(VXGE_TRACE,
1064 "%s:%d Exiting...", __func__, __LINE__);
1067 static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1069 struct list_head *entry, *next;
1071 u8 *mac_address = (u8 *) (&del_mac);
1073 /* Copy the mac address to delete from the list */
1074 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1076 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1077 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1080 vpath->mac_addr_cnt--;
1082 if (is_multicast_ether_addr(mac->macaddr))
1083 vpath->mcast_addr_cnt--;
1091 /* delete a mac address from DA table */
1092 static enum vxge_hw_status
1093 vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1095 enum vxge_hw_status status = VXGE_HW_OK;
1096 struct vxge_vpath *vpath;
1098 vpath = &vdev->vpaths[mac->vpath_no];
1099 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1101 if (status != VXGE_HW_OK) {
1102 vxge_debug_init(VXGE_ERR,
1103 "DA config delete entry failed for vpath:%d",
1106 vxge_mac_list_del(vpath, mac);
1111 * vxge_set_multicast
1112 * @dev: pointer to the device structure
1114 * Entry point for multicast address enable/disable
1115 * This function is a driver entry point which gets called by the kernel
1116 * whenever multicast addresses must be enabled/disabled. This also gets
1117 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1118 * determine, if multicast address must be enabled or if promiscuous mode
1119 * is to be disabled etc.
1121 static void vxge_set_multicast(struct net_device *dev)
1123 struct netdev_hw_addr *ha;
1124 struct vxgedev *vdev;
1125 int i, mcast_cnt = 0;
1126 struct vxge_vpath *vpath;
1127 enum vxge_hw_status status = VXGE_HW_OK;
1128 struct macInfo mac_info;
1130 struct vxge_mac_addrs *mac_entry;
1131 struct list_head *list_head;
1132 struct list_head *entry, *next;
1133 u8 *mac_address = NULL;
1135 vxge_debug_entryexit(VXGE_TRACE,
1136 "%s:%d", __func__, __LINE__);
1138 vdev = netdev_priv(dev);
1140 if (unlikely(!is_vxge_card_up(vdev)))
1143 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1144 for (i = 0; i < vdev->no_of_vpath; i++) {
1145 vpath = &vdev->vpaths[i];
1146 vxge_assert(vpath->is_open);
1147 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1148 if (status != VXGE_HW_OK)
1149 vxge_debug_init(VXGE_ERR, "failed to enable "
1150 "multicast, status %d", status);
1151 vdev->all_multi_flg = 1;
1153 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1154 for (i = 0; i < vdev->no_of_vpath; i++) {
1155 vpath = &vdev->vpaths[i];
1156 vxge_assert(vpath->is_open);
1157 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1158 if (status != VXGE_HW_OK)
1159 vxge_debug_init(VXGE_ERR, "failed to disable "
1160 "multicast, status %d", status);
1161 vdev->all_multi_flg = 0;
1166 if (!vdev->config.addr_learn_en) {
1167 for (i = 0; i < vdev->no_of_vpath; i++) {
1168 vpath = &vdev->vpaths[i];
1169 vxge_assert(vpath->is_open);
1171 if (dev->flags & IFF_PROMISC)
1172 status = vxge_hw_vpath_promisc_enable(
1175 status = vxge_hw_vpath_promisc_disable(
1177 if (status != VXGE_HW_OK)
1178 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1179 ", status %d", dev->flags&IFF_PROMISC ?
1180 "enable" : "disable", status);
1184 memset(&mac_info, 0, sizeof(struct macInfo));
1185 /* Update individual M_CAST address list */
1186 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
1187 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1188 list_head = &vdev->vpaths[0].mac_addr_list;
1189 if ((netdev_mc_count(dev) +
1190 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1191 vdev->vpaths[0].max_mac_addr_cnt)
1192 goto _set_all_mcast;
1194 /* Delete previous MC's */
1195 for (i = 0; i < mcast_cnt; i++) {
1196 list_for_each_safe(entry, next, list_head) {
1197 mac_entry = (struct vxge_mac_addrs *)entry;
1198 /* Copy the mac address to delete */
1199 mac_address = (u8 *)&mac_entry->macaddr;
1200 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1202 if (is_multicast_ether_addr(mac_info.macaddr)) {
1203 for (vpath_idx = 0; vpath_idx <
1206 mac_info.vpath_no = vpath_idx;
1207 status = vxge_del_mac_addr(
1216 netdev_for_each_mc_addr(ha, dev) {
1217 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
1218 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1220 mac_info.vpath_no = vpath_idx;
1221 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1222 status = vxge_add_mac_addr(vdev, &mac_info);
1223 if (status != VXGE_HW_OK) {
1224 vxge_debug_init(VXGE_ERR,
1225 "%s:%d Setting individual"
1226 "multicast address failed",
1227 __func__, __LINE__);
1228 goto _set_all_mcast;
1235 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1236 /* Delete previous MC's */
1237 for (i = 0; i < mcast_cnt; i++) {
1238 list_for_each_safe(entry, next, list_head) {
1239 mac_entry = (struct vxge_mac_addrs *)entry;
1240 /* Copy the mac address to delete */
1241 mac_address = (u8 *)&mac_entry->macaddr;
1242 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1244 if (is_multicast_ether_addr(mac_info.macaddr))
1248 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1250 mac_info.vpath_no = vpath_idx;
1251 status = vxge_del_mac_addr(vdev, &mac_info);
1255 /* Enable all multicast */
1256 for (i = 0; i < vdev->no_of_vpath; i++) {
1257 vpath = &vdev->vpaths[i];
1258 vxge_assert(vpath->is_open);
1260 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1261 if (status != VXGE_HW_OK) {
1262 vxge_debug_init(VXGE_ERR,
1263 "%s:%d Enabling all multicasts failed",
1264 __func__, __LINE__);
1266 vdev->all_multi_flg = 1;
1268 dev->flags |= IFF_ALLMULTI;
1271 vxge_debug_entryexit(VXGE_TRACE,
1272 "%s:%d Exiting...", __func__, __LINE__);
1277 * @dev: pointer to the device structure
1280 * Update entry "0" (default MAC addr)
1282 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1284 struct sockaddr *addr = p;
1285 struct vxgedev *vdev;
1286 enum vxge_hw_status status = VXGE_HW_OK;
1287 struct macInfo mac_info_new, mac_info_old;
1290 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1292 vdev = netdev_priv(dev);
1294 if (!is_valid_ether_addr(addr->sa_data))
1297 memset(&mac_info_new, 0, sizeof(struct macInfo));
1298 memset(&mac_info_old, 0, sizeof(struct macInfo));
1300 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1301 __func__, __LINE__);
1303 /* Get the old address */
1304 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1306 /* Copy the new address */
1307 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1309 /* First delete the old mac address from all the vpaths
1310 as we can't specify the index while adding new mac address */
1311 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1312 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1313 if (!vpath->is_open) {
1314 /* This can happen when this interface is added/removed
1315 to the bonding interface. Delete this station address
1316 from the linked list */
1317 vxge_mac_list_del(vpath, &mac_info_old);
1319 /* Add this new address to the linked list
1320 for later restoring */
1321 vxge_mac_list_add(vpath, &mac_info_new);
1325 /* Delete the station address */
1326 mac_info_old.vpath_no = vpath_idx;
1327 status = vxge_del_mac_addr(vdev, &mac_info_old);
1330 if (unlikely(!is_vxge_card_up(vdev))) {
1331 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1335 /* Set this mac address to all the vpaths */
1336 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1337 mac_info_new.vpath_no = vpath_idx;
1338 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1339 status = vxge_add_mac_addr(vdev, &mac_info_new);
1340 if (status != VXGE_HW_OK)
1344 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1350 * vxge_vpath_intr_enable
1351 * @vdev: pointer to vdev
1352 * @vp_id: vpath for which to enable the interrupts
1354 * Enables the interrupts for the vpath
1356 static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1358 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1360 int tim_msix_id[4] = {0, 1, 0, 0};
1361 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
1363 vxge_hw_vpath_intr_enable(vpath->handle);
1365 if (vdev->config.intr_type == INTA)
1366 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1368 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1371 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1372 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1373 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1375 /* enable the alarm vector */
1376 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1377 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1378 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1383 * vxge_vpath_intr_disable
1384 * @vdev: pointer to vdev
1385 * @vp_id: vpath for which to disable the interrupts
1387 * Disables the interrupts for the vpath
1389 static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1391 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1392 struct __vxge_hw_device *hldev;
1395 hldev = pci_get_drvdata(vdev->pdev);
1397 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1399 vxge_hw_vpath_intr_disable(vpath->handle);
1401 if (vdev->config.intr_type == INTA)
1402 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1404 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1405 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1406 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1408 /* disable the alarm vector */
1409 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1410 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
1411 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1415 /* list all mac addresses from DA table */
1416 static enum vxge_hw_status
1417 vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1419 enum vxge_hw_status status = VXGE_HW_OK;
1420 unsigned char macmask[ETH_ALEN];
1421 unsigned char macaddr[ETH_ALEN];
1423 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1425 if (status != VXGE_HW_OK) {
1426 vxge_debug_init(VXGE_ERR,
1427 "DA config list entry failed for vpath:%d",
1432 while (!ether_addr_equal(mac->macaddr, macaddr)) {
1433 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1435 if (status != VXGE_HW_OK)
1442 /* Store all mac addresses from the list to the DA table */
1443 static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1445 enum vxge_hw_status status = VXGE_HW_OK;
1446 struct macInfo mac_info;
1447 u8 *mac_address = NULL;
1448 struct list_head *entry, *next;
1450 memset(&mac_info, 0, sizeof(struct macInfo));
1452 if (vpath->is_open) {
1453 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1456 ((struct vxge_mac_addrs *)entry)->macaddr;
1457 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1458 ((struct vxge_mac_addrs *)entry)->state =
1459 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1460 /* does this mac address already exist in da table? */
1461 status = vxge_search_mac_addr_in_da_table(vpath,
1463 if (status != VXGE_HW_OK) {
1464 /* Add this mac address to the DA table */
1465 status = vxge_hw_vpath_mac_addr_add(
1466 vpath->handle, mac_info.macaddr,
1468 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1469 if (status != VXGE_HW_OK) {
1470 vxge_debug_init(VXGE_ERR,
1471 "DA add entry failed for vpath:%d",
1473 ((struct vxge_mac_addrs *)entry)->state
1474 = VXGE_LL_MAC_ADDR_IN_LIST;
1483 /* Store all vlan ids from the list to the vid table */
1484 static enum vxge_hw_status
1485 vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1487 enum vxge_hw_status status = VXGE_HW_OK;
1488 struct vxgedev *vdev = vpath->vdev;
1491 if (!vpath->is_open)
1494 for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
1495 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1502 * @vdev: pointer to vdev
1503 * @vp_id: vpath to reset
1507 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1509 enum vxge_hw_status status = VXGE_HW_OK;
1510 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1513 /* check if device is down already */
1514 if (unlikely(!is_vxge_card_up(vdev)))
1517 /* is device reset already scheduled */
1518 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1521 if (vpath->handle) {
1522 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1523 if (is_vxge_card_up(vdev) &&
1524 vxge_hw_vpath_recover_from_reset(vpath->handle)
1526 vxge_debug_init(VXGE_ERR,
1527 "vxge_hw_vpath_recover_from_reset"
1528 "failed for vpath:%d", vp_id);
1532 vxge_debug_init(VXGE_ERR,
1533 "vxge_hw_vpath_reset failed for"
1538 return VXGE_HW_FAIL;
1540 vxge_restore_vpath_mac_addr(vpath);
1541 vxge_restore_vpath_vid_table(vpath);
1543 /* Enable all broadcast */
1544 vxge_hw_vpath_bcast_enable(vpath->handle);
1546 /* Enable all multicast */
1547 if (vdev->all_multi_flg) {
1548 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1549 if (status != VXGE_HW_OK)
1550 vxge_debug_init(VXGE_ERR,
1551 "%s:%d Enabling multicast failed",
1552 __func__, __LINE__);
1555 /* Enable the interrupts */
1556 vxge_vpath_intr_enable(vdev, vp_id);
1560 /* Enable the flow of traffic through the vpath */
1561 vxge_hw_vpath_enable(vpath->handle);
1564 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1565 vpath->ring.last_status = VXGE_HW_OK;
1567 /* Vpath reset done */
1568 clear_bit(vp_id, &vdev->vp_reset);
1570 /* Start the vpath queue */
1571 if (netif_tx_queue_stopped(vpath->fifo.txq))
1572 netif_tx_wake_queue(vpath->fifo.txq);
1578 static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1582 /* Enable CI for RTI */
1583 if (vdev->config.intr_type == MSI_X) {
1584 for (i = 0; i < vdev->no_of_vpath; i++) {
1585 struct __vxge_hw_ring *hw_ring;
1587 hw_ring = vdev->vpaths[i].ring.handle;
1588 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1592 /* Enable CI for TTI */
1593 for (i = 0; i < vdev->no_of_vpath; i++) {
1594 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1595 vxge_hw_vpath_tti_ci_set(hw_fifo);
1597 * For Inta (with or without napi), Set CI ON for only one
1598 * vpath. (Have only one free running timer).
1600 if ((vdev->config.intr_type == INTA) && (i == 0))
1607 static int do_vxge_reset(struct vxgedev *vdev, int event)
1609 enum vxge_hw_status status;
1610 int ret = 0, vp_id, i;
1612 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1614 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1615 /* check if device is down already */
1616 if (unlikely(!is_vxge_card_up(vdev)))
1619 /* is reset already scheduled */
1620 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1624 if (event == VXGE_LL_FULL_RESET) {
1625 netif_carrier_off(vdev->ndev);
1627 /* wait for all the vpath reset to complete */
1628 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1629 while (test_bit(vp_id, &vdev->vp_reset))
1633 netif_carrier_on(vdev->ndev);
1635 /* if execution mode is set to debug, don't reset the adapter */
1636 if (unlikely(vdev->exec_mode)) {
1637 vxge_debug_init(VXGE_ERR,
1638 "%s: execution mode is debug, returning..",
1640 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1641 netif_tx_stop_all_queues(vdev->ndev);
1646 if (event == VXGE_LL_FULL_RESET) {
1647 vxge_hw_device_wait_receive_idle(vdev->devh);
1648 vxge_hw_device_intr_disable(vdev->devh);
1650 switch (vdev->cric_err_event) {
1651 case VXGE_HW_EVENT_UNKNOWN:
1652 netif_tx_stop_all_queues(vdev->ndev);
1653 vxge_debug_init(VXGE_ERR,
1654 "fatal: %s: Disabling device due to"
1659 case VXGE_HW_EVENT_RESET_START:
1661 case VXGE_HW_EVENT_RESET_COMPLETE:
1662 case VXGE_HW_EVENT_LINK_DOWN:
1663 case VXGE_HW_EVENT_LINK_UP:
1664 case VXGE_HW_EVENT_ALARM_CLEARED:
1665 case VXGE_HW_EVENT_ECCERR:
1666 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1669 case VXGE_HW_EVENT_FIFO_ERR:
1670 case VXGE_HW_EVENT_VPATH_ERR:
1672 case VXGE_HW_EVENT_CRITICAL_ERR:
1673 netif_tx_stop_all_queues(vdev->ndev);
1674 vxge_debug_init(VXGE_ERR,
1675 "fatal: %s: Disabling device due to"
1678 /* SOP or device reset required */
1679 /* This event is not currently used */
1682 case VXGE_HW_EVENT_SERR:
1683 netif_tx_stop_all_queues(vdev->ndev);
1684 vxge_debug_init(VXGE_ERR,
1685 "fatal: %s: Disabling device due to"
1690 case VXGE_HW_EVENT_SRPCIM_SERR:
1691 case VXGE_HW_EVENT_MRPCIM_SERR:
1694 case VXGE_HW_EVENT_SLOT_FREEZE:
1695 netif_tx_stop_all_queues(vdev->ndev);
1696 vxge_debug_init(VXGE_ERR,
1697 "fatal: %s: Disabling device due to"
1708 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1709 netif_tx_stop_all_queues(vdev->ndev);
1711 if (event == VXGE_LL_FULL_RESET) {
1712 status = vxge_reset_all_vpaths(vdev);
1713 if (status != VXGE_HW_OK) {
1714 vxge_debug_init(VXGE_ERR,
1715 "fatal: %s: can not reset vpaths",
1722 if (event == VXGE_LL_COMPL_RESET) {
1723 for (i = 0; i < vdev->no_of_vpath; i++)
1724 if (vdev->vpaths[i].handle) {
1725 if (vxge_hw_vpath_recover_from_reset(
1726 vdev->vpaths[i].handle)
1728 vxge_debug_init(VXGE_ERR,
1729 "vxge_hw_vpath_recover_"
1730 "from_reset failed for vpath: "
1736 vxge_debug_init(VXGE_ERR,
1737 "vxge_hw_vpath_reset failed for "
1744 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1745 /* Reprogram the DA table with populated mac addresses */
1746 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1747 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1748 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1751 /* enable vpath interrupts */
1752 for (i = 0; i < vdev->no_of_vpath; i++)
1753 vxge_vpath_intr_enable(vdev, i);
1755 vxge_hw_device_intr_enable(vdev->devh);
1759 /* Indicate card up */
1760 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1762 /* Get the traffic to flow through the vpaths */
1763 for (i = 0; i < vdev->no_of_vpath; i++) {
1764 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1766 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1769 netif_tx_wake_all_queues(vdev->ndev);
1773 vxge_config_ci_for_tti_rti(vdev);
1776 vxge_debug_entryexit(VXGE_TRACE,
1777 "%s:%d Exiting...", __func__, __LINE__);
1779 /* Indicate reset done */
1780 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1781 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1787 * @vdev: pointer to ll device
1789 * driver may reset the chip on events of serr, eccerr, etc
1791 static void vxge_reset(struct work_struct *work)
1793 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1795 if (!netif_running(vdev->ndev))
1798 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1802 * vxge_poll - Receive handler when Receive Polling is used.
1803 * @napi: pointer to the napi structure.
1804 * @budget: Number of packets budgeted to be processed in this iteration.
1806 * This function comes into picture only if Receive side is being handled
1807 * through polling (called NAPI in linux). It mostly does what the normal
1808 * Rx interrupt handler does in terms of descriptor and packet processing
1809 * but not in an interrupt context. Also it will process a specified number
1810 * of packets at most in one iteration. This value is passed down by the
1811 * kernel as the function argument 'budget'.
1813 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1815 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1817 int budget_org = budget;
1819 ring->budget = budget;
1820 ring->pkts_processed = 0;
1821 vxge_hw_vpath_poll_rx(ring->handle);
1822 pkts_processed = ring->pkts_processed;
1824 if (pkts_processed < budget_org) {
1825 napi_complete_done(napi, pkts_processed);
1827 /* Re enable the Rx interrupts for the vpath */
1828 vxge_hw_channel_msix_unmask(
1829 (struct __vxge_hw_channel *)ring->handle,
1830 ring->rx_vector_no);
1833 /* We are copying and returning the local variable, in case if after
1834 * clearing the msix interrupt above, if the interrupt fires right
1835 * away which can preempt this NAPI thread */
1836 return pkts_processed;
1839 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1841 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1842 int pkts_processed = 0;
1844 int budget_org = budget;
1845 struct vxge_ring *ring;
1847 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
1849 for (i = 0; i < vdev->no_of_vpath; i++) {
1850 ring = &vdev->vpaths[i].ring;
1851 ring->budget = budget;
1852 ring->pkts_processed = 0;
1853 vxge_hw_vpath_poll_rx(ring->handle);
1854 pkts_processed += ring->pkts_processed;
1855 budget -= ring->pkts_processed;
1860 VXGE_COMPLETE_ALL_TX(vdev);
1862 if (pkts_processed < budget_org) {
1863 napi_complete_done(napi, pkts_processed);
1864 /* Re enable the Rx interrupts for the ring */
1865 vxge_hw_device_unmask_all(hldev);
1866 vxge_hw_device_flush_io(hldev);
1869 return pkts_processed;
1872 #ifdef CONFIG_NET_POLL_CONTROLLER
1874 * vxge_netpoll - netpoll event handler entry point
1875 * @dev : pointer to the device structure.
1877 * This function will be called by upper layer to check for events on the
1878 * interface in situations where interrupts are disabled. It is used for
1879 * specific in-kernel networking tasks, such as remote consoles and kernel
1880 * debugging over the network (example netdump in RedHat).
1882 static void vxge_netpoll(struct net_device *dev)
1884 struct vxgedev *vdev = netdev_priv(dev);
1885 struct pci_dev *pdev = vdev->pdev;
1886 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
1887 const int irq = pdev->irq;
1889 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1891 if (pci_channel_offline(pdev))
1895 vxge_hw_device_clear_tx_rx(hldev);
1897 vxge_hw_device_clear_tx_rx(hldev);
1898 VXGE_COMPLETE_ALL_RX(vdev);
1899 VXGE_COMPLETE_ALL_TX(vdev);
1903 vxge_debug_entryexit(VXGE_TRACE,
1904 "%s:%d Exiting...", __func__, __LINE__);
1908 /* RTH configuration */
1909 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1911 enum vxge_hw_status status = VXGE_HW_OK;
1912 struct vxge_hw_rth_hash_types hash_types;
1913 u8 itable[256] = {0}; /* indirection table */
1914 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1919 * - itable with bucket numbers
1920 * - mtable with bucket-to-vpath mapping
1922 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1923 itable[index] = index;
1924 mtable[index] = index % vdev->no_of_vpath;
1927 /* set indirection table, bucket-to-vpath mapping */
1928 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1931 vdev->config.rth_bkt_sz);
1932 if (status != VXGE_HW_OK) {
1933 vxge_debug_init(VXGE_ERR,
1934 "RTH indirection table configuration failed "
1935 "for vpath:%d", vdev->vpaths[0].device_id);
1939 /* Fill RTH hash types */
1940 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1941 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1942 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1943 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1944 hash_types.hash_type_tcpipv6ex_en =
1945 vdev->config.rth_hash_type_tcpipv6ex;
1946 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1949 * Because the itable_set() method uses the active_table field
1950 * for the target virtual path the RTH config should be updated
1951 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1952 * when steering frames.
1954 for (index = 0; index < vdev->no_of_vpath; index++) {
1955 status = vxge_hw_vpath_rts_rth_set(
1956 vdev->vpaths[index].handle,
1957 vdev->config.rth_algorithm,
1959 vdev->config.rth_bkt_sz);
1960 if (status != VXGE_HW_OK) {
1961 vxge_debug_init(VXGE_ERR,
1962 "RTH configuration failed for vpath:%d",
1963 vdev->vpaths[index].device_id);
1972 static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1974 enum vxge_hw_status status = VXGE_HW_OK;
1975 struct vxge_vpath *vpath;
1978 for (i = 0; i < vdev->no_of_vpath; i++) {
1979 vpath = &vdev->vpaths[i];
1980 if (vpath->handle) {
1981 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1982 if (is_vxge_card_up(vdev) &&
1983 vxge_hw_vpath_recover_from_reset(
1984 vpath->handle) != VXGE_HW_OK) {
1985 vxge_debug_init(VXGE_ERR,
1986 "vxge_hw_vpath_recover_"
1987 "from_reset failed for vpath: "
1992 vxge_debug_init(VXGE_ERR,
1993 "vxge_hw_vpath_reset failed for "
2004 static void vxge_close_vpaths(struct vxgedev *vdev, int index)
2006 struct vxge_vpath *vpath;
2009 for (i = index; i < vdev->no_of_vpath; i++) {
2010 vpath = &vdev->vpaths[i];
2012 if (vpath->handle && vpath->is_open) {
2013 vxge_hw_vpath_close(vpath->handle);
2014 vdev->stats.vpaths_open--;
2017 vpath->handle = NULL;
2022 static int vxge_open_vpaths(struct vxgedev *vdev)
2024 struct vxge_hw_vpath_attr attr;
2025 enum vxge_hw_status status;
2026 struct vxge_vpath *vpath;
2030 for (i = 0; i < vdev->no_of_vpath; i++) {
2031 vpath = &vdev->vpaths[i];
2032 vxge_assert(vpath->is_configured);
2034 if (!vdev->titan1) {
2035 struct vxge_hw_vp_config *vcfg;
2036 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2038 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2039 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2040 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2041 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2042 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2043 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2044 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2045 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2046 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2049 attr.vp_id = vpath->device_id;
2050 attr.fifo_attr.callback = vxge_xmit_compl;
2051 attr.fifo_attr.txdl_term = vxge_tx_term;
2052 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2053 attr.fifo_attr.userdata = &vpath->fifo;
2055 attr.ring_attr.callback = vxge_rx_1b_compl;
2056 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2057 attr.ring_attr.rxd_term = vxge_rx_term;
2058 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2059 attr.ring_attr.userdata = &vpath->ring;
2061 vpath->ring.ndev = vdev->ndev;
2062 vpath->ring.pdev = vdev->pdev;
2064 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
2065 if (status == VXGE_HW_OK) {
2066 vpath->fifo.handle =
2067 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2068 vpath->ring.handle =
2069 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2070 vpath->fifo.tx_steering_type =
2071 vdev->config.tx_steering_type;
2072 vpath->fifo.ndev = vdev->ndev;
2073 vpath->fifo.pdev = vdev->pdev;
2075 u64_stats_init(&vpath->fifo.stats.syncp);
2076 u64_stats_init(&vpath->ring.stats.syncp);
2078 if (vdev->config.tx_steering_type)
2080 netdev_get_tx_queue(vdev->ndev, i);
2083 netdev_get_tx_queue(vdev->ndev, 0);
2084 vpath->fifo.indicate_max_pkts =
2085 vdev->config.fifo_indicate_max_pkts;
2086 vpath->fifo.tx_vector_no = 0;
2087 vpath->ring.rx_vector_no = 0;
2088 vpath->ring.rx_hwts = vdev->rx_hwts;
2090 vdev->vp_handles[i] = vpath->handle;
2091 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
2092 vdev->stats.vpaths_open++;
2094 vdev->stats.vpath_open_fail++;
2095 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2096 "open with status: %d",
2097 vdev->ndev->name, vpath->device_id,
2099 vxge_close_vpaths(vdev, 0);
2103 vp_id = vpath->handle->vpath->vp_id;
2104 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2111 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2112 * if the interrupts are not within a range
2113 * @fifo: pointer to transmit fifo structure
2114 * Description: The function changes boundary timer and restriction timer
2115 * value depends on the traffic
2116 * Return Value: None
2118 static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2120 fifo->interrupt_count++;
2121 if (time_before(fifo->jiffies + HZ / 100, jiffies)) {
2122 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2124 fifo->jiffies = jiffies;
2125 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2126 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2127 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2128 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2129 } else if (hw_fifo->rtimer != 0) {
2130 hw_fifo->rtimer = 0;
2131 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2133 fifo->interrupt_count = 0;
2138 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2139 * if the interrupts are not within a range
2140 * @ring: pointer to receive ring structure
2141 * Description: The function increases of decreases the packet counts within
2142 * the ranges of traffic utilization, if the interrupts due to this ring are
2143 * not within a fixed range.
2144 * Return Value: Nothing
2146 static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2148 ring->interrupt_count++;
2149 if (time_before(ring->jiffies + HZ / 100, jiffies)) {
2150 struct __vxge_hw_ring *hw_ring = ring->handle;
2152 ring->jiffies = jiffies;
2153 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2154 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2155 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2156 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2157 } else if (hw_ring->rtimer != 0) {
2158 hw_ring->rtimer = 0;
2159 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2161 ring->interrupt_count = 0;
2167 * @irq: the irq of the device.
2168 * @dev_id: a void pointer to the hldev structure of the Titan device
2169 * @ptregs: pointer to the registers pushed on the stack.
2171 * This function is the ISR handler of the device when napi is enabled. It
2172 * identifies the reason for the interrupt and calls the relevant service
2175 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2177 struct __vxge_hw_device *hldev;
2179 enum vxge_hw_status status;
2180 struct vxgedev *vdev = (struct vxgedev *)dev_id;
2182 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2184 hldev = pci_get_drvdata(vdev->pdev);
2186 if (pci_channel_offline(vdev->pdev))
2189 if (unlikely(!is_vxge_card_up(vdev)))
2192 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
2193 if (status == VXGE_HW_OK) {
2194 vxge_hw_device_mask_all(hldev);
2197 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2198 vdev->vpaths_deployed >>
2199 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2201 vxge_hw_device_clear_tx_rx(hldev);
2202 napi_schedule(&vdev->napi);
2203 vxge_debug_intr(VXGE_TRACE,
2204 "%s:%d Exiting...", __func__, __LINE__);
2207 vxge_hw_device_unmask_all(hldev);
2208 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2209 (status == VXGE_HW_ERR_CRITICAL) ||
2210 (status == VXGE_HW_ERR_FIFO))) {
2211 vxge_hw_device_mask_all(hldev);
2212 vxge_hw_device_flush_io(hldev);
2214 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2217 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2221 static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
2223 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2225 adaptive_coalesce_tx_interrupts(fifo);
2227 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2228 fifo->tx_vector_no);
2230 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2231 fifo->tx_vector_no);
2233 VXGE_COMPLETE_VPATH_TX(fifo);
2235 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2236 fifo->tx_vector_no);
2241 static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
2243 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2245 adaptive_coalesce_rx_interrupts(ring);
2247 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2248 ring->rx_vector_no);
2250 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2251 ring->rx_vector_no);
2253 napi_schedule(&ring->napi);
2258 vxge_alarm_msix_handle(int irq, void *dev_id)
2261 enum vxge_hw_status status;
2262 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2263 struct vxgedev *vdev = vpath->vdev;
2264 int msix_id = (vpath->handle->vpath->vp_id *
2265 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2267 for (i = 0; i < vdev->no_of_vpath; i++) {
2268 /* Reduce the chance of losing alarm interrupts by masking
2269 * the vector. A pending bit will be set if an alarm is
2270 * generated and on unmask the interrupt will be fired.
2272 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
2273 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2275 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2277 if (status == VXGE_HW_OK) {
2278 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2282 vxge_debug_intr(VXGE_ERR,
2283 "%s: vxge_hw_vpath_alarm_process failed %x ",
2284 VXGE_DRIVER_NAME, status);
2289 static int vxge_alloc_msix(struct vxgedev *vdev)
2292 int msix_intr_vect = 0, temp;
2296 /* Tx/Rx MSIX Vectors count */
2297 vdev->intr_cnt = vdev->no_of_vpath * 2;
2299 /* Alarm MSIX Vectors count */
2302 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2304 if (!vdev->entries) {
2305 vxge_debug_init(VXGE_ERR,
2306 "%s: memory allocation failed",
2309 goto alloc_entries_failed;
2312 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2313 sizeof(struct vxge_msix_entry),
2315 if (!vdev->vxge_entries) {
2316 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2319 goto alloc_vxge_entries_failed;
2322 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
2324 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2326 /* Initialize the fifo vector */
2327 vdev->entries[j].entry = msix_intr_vect;
2328 vdev->vxge_entries[j].entry = msix_intr_vect;
2329 vdev->vxge_entries[j].in_use = 0;
2332 /* Initialize the ring vector */
2333 vdev->entries[j].entry = msix_intr_vect + 1;
2334 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2335 vdev->vxge_entries[j].in_use = 0;
2339 /* Initialize the alarm vector */
2340 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2341 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
2342 vdev->vxge_entries[j].in_use = 0;
2344 ret = pci_enable_msix_range(vdev->pdev,
2345 vdev->entries, 3, vdev->intr_cnt);
2348 goto enable_msix_failed;
2349 } else if (ret < vdev->intr_cnt) {
2350 pci_disable_msix(vdev->pdev);
2352 vxge_debug_init(VXGE_ERR,
2353 "%s: MSI-X enable failed for %d vectors, ret: %d",
2354 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
2355 if (max_config_vpath != VXGE_USE_DEFAULT) {
2357 goto enable_msix_failed;
2360 kfree(vdev->entries);
2361 kfree(vdev->vxge_entries);
2362 vdev->entries = NULL;
2363 vdev->vxge_entries = NULL;
2364 /* Try with less no of vector by reducing no of vpaths count */
2366 vxge_close_vpaths(vdev, temp);
2367 vdev->no_of_vpath = temp;
2373 kfree(vdev->vxge_entries);
2374 alloc_vxge_entries_failed:
2375 kfree(vdev->entries);
2376 alloc_entries_failed:
2380 static int vxge_enable_msix(struct vxgedev *vdev)
2384 /* 0 - Tx, 1 - Rx */
2385 int tim_msix_id[4] = {0, 1, 0, 0};
2389 /* allocate msix vectors */
2390 ret = vxge_alloc_msix(vdev);
2392 for (i = 0; i < vdev->no_of_vpath; i++) {
2393 struct vxge_vpath *vpath = &vdev->vpaths[i];
2395 /* If fifo or ring are not enabled, the MSIX vector for
2396 * it should be set to 0.
2398 vpath->ring.rx_vector_no = (vpath->device_id *
2399 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
2401 vpath->fifo.tx_vector_no = (vpath->device_id *
2402 VXGE_HW_VPATH_MSIX_ACTIVE);
2404 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2405 VXGE_ALARM_MSIX_ID);
2412 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2416 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
2418 if (vdev->vxge_entries[intr_cnt].in_use) {
2419 synchronize_irq(vdev->entries[intr_cnt].vector);
2420 free_irq(vdev->entries[intr_cnt].vector,
2421 vdev->vxge_entries[intr_cnt].arg);
2422 vdev->vxge_entries[intr_cnt].in_use = 0;
2426 kfree(vdev->entries);
2427 kfree(vdev->vxge_entries);
2428 vdev->entries = NULL;
2429 vdev->vxge_entries = NULL;
2431 if (vdev->config.intr_type == MSI_X)
2432 pci_disable_msix(vdev->pdev);
2435 static void vxge_rem_isr(struct vxgedev *vdev)
2437 if (IS_ENABLED(CONFIG_PCI_MSI) &&
2438 vdev->config.intr_type == MSI_X) {
2439 vxge_rem_msix_isr(vdev);
2440 } else if (vdev->config.intr_type == INTA) {
2441 synchronize_irq(vdev->pdev->irq);
2442 free_irq(vdev->pdev->irq, vdev);
2446 static int vxge_add_isr(struct vxgedev *vdev)
2449 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2450 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2452 if (IS_ENABLED(CONFIG_PCI_MSI) && vdev->config.intr_type == MSI_X)
2453 ret = vxge_enable_msix(vdev);
2456 vxge_debug_init(VXGE_ERR,
2457 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2458 vxge_debug_init(VXGE_ERR,
2459 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2460 vdev->config.intr_type = INTA;
2463 if (IS_ENABLED(CONFIG_PCI_MSI) && vdev->config.intr_type == MSI_X) {
2465 intr_idx < (vdev->no_of_vpath *
2466 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2468 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2473 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2474 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2476 vdev->entries[intr_cnt].entry,
2479 vdev->entries[intr_cnt].vector,
2480 vxge_tx_msix_handle, 0,
2481 vdev->desc[intr_cnt],
2482 &vdev->vpaths[vp_idx].fifo);
2483 vdev->vxge_entries[intr_cnt].arg =
2484 &vdev->vpaths[vp_idx].fifo;
2488 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2489 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2491 vdev->entries[intr_cnt].entry,
2494 vdev->entries[intr_cnt].vector,
2495 vxge_rx_msix_napi_handle, 0,
2496 vdev->desc[intr_cnt],
2497 &vdev->vpaths[vp_idx].ring);
2498 vdev->vxge_entries[intr_cnt].arg =
2499 &vdev->vpaths[vp_idx].ring;
2505 vxge_debug_init(VXGE_ERR,
2506 "%s: MSIX - %d Registration failed",
2507 vdev->ndev->name, intr_cnt);
2508 vxge_rem_msix_isr(vdev);
2509 vdev->config.intr_type = INTA;
2510 vxge_debug_init(VXGE_ERR,
2511 "%s: Defaulting to INTA",
2517 /* We requested for this msix interrupt */
2518 vdev->vxge_entries[intr_cnt].in_use = 1;
2519 msix_idx += vdev->vpaths[vp_idx].device_id *
2520 VXGE_HW_VPATH_MSIX_ACTIVE;
2521 vxge_hw_vpath_msix_unmask(
2522 vdev->vpaths[vp_idx].handle,
2527 /* Point to next vpath handler */
2528 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2529 (vp_idx < (vdev->no_of_vpath - 1)))
2533 intr_cnt = vdev->no_of_vpath * 2;
2534 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2535 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2537 vdev->entries[intr_cnt].entry,
2539 /* For Alarm interrupts */
2540 ret = request_irq(vdev->entries[intr_cnt].vector,
2541 vxge_alarm_msix_handle, 0,
2542 vdev->desc[intr_cnt],
2545 vxge_debug_init(VXGE_ERR,
2546 "%s: MSIX - %d Registration failed",
2547 vdev->ndev->name, intr_cnt);
2548 vxge_rem_msix_isr(vdev);
2549 vdev->config.intr_type = INTA;
2550 vxge_debug_init(VXGE_ERR,
2551 "%s: Defaulting to INTA",
2556 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2557 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2558 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2560 vdev->vxge_entries[intr_cnt].in_use = 1;
2561 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
2565 if (vdev->config.intr_type == INTA) {
2566 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2567 "%s:vxge:INTA", vdev->ndev->name);
2568 vxge_hw_device_set_intr_type(vdev->devh,
2569 VXGE_HW_INTR_MODE_IRQLINE);
2571 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2573 ret = request_irq((int) vdev->pdev->irq,
2575 IRQF_SHARED, vdev->desc[0], vdev);
2577 vxge_debug_init(VXGE_ERR,
2578 "%s %s-%d: ISR registration failed",
2579 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2582 vxge_debug_init(VXGE_TRACE,
2583 "new %s-%d line allocated",
2584 "IRQ", vdev->pdev->irq);
2590 static void vxge_poll_vp_reset(struct timer_list *t)
2592 struct vxgedev *vdev = from_timer(vdev, t, vp_reset_timer);
2595 for (i = 0; i < vdev->no_of_vpath; i++) {
2596 if (test_bit(i, &vdev->vp_reset)) {
2597 vxge_reset_vpath(vdev, i);
2601 if (j && (vdev->config.intr_type != MSI_X)) {
2602 vxge_hw_device_unmask_all(vdev->devh);
2603 vxge_hw_device_flush_io(vdev->devh);
2606 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2609 static void vxge_poll_vp_lockup(struct timer_list *t)
2611 struct vxgedev *vdev = from_timer(vdev, t, vp_lockup_timer);
2612 enum vxge_hw_status status = VXGE_HW_OK;
2613 struct vxge_vpath *vpath;
2614 struct vxge_ring *ring;
2616 unsigned long rx_frms;
2618 for (i = 0; i < vdev->no_of_vpath; i++) {
2619 ring = &vdev->vpaths[i].ring;
2621 /* Truncated to machine word size number of frames */
2622 rx_frms = READ_ONCE(ring->stats.rx_frms);
2624 /* Did this vpath received any packets */
2625 if (ring->stats.prev_rx_frms == rx_frms) {
2626 status = vxge_hw_vpath_check_leak(ring->handle);
2628 /* Did it received any packets last time */
2629 if ((VXGE_HW_FAIL == status) &&
2630 (VXGE_HW_FAIL == ring->last_status)) {
2632 /* schedule vpath reset */
2633 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2634 vpath = &vdev->vpaths[i];
2636 /* disable interrupts for this vpath */
2637 vxge_vpath_intr_disable(vdev, i);
2639 /* stop the queue for this vpath */
2640 netif_tx_stop_queue(vpath->fifo.txq);
2645 ring->stats.prev_rx_frms = rx_frms;
2646 ring->last_status = status;
2649 /* Check every 1 milli second */
2650 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2653 static netdev_features_t vxge_fix_features(struct net_device *dev,
2654 netdev_features_t features)
2656 netdev_features_t changed = dev->features ^ features;
2658 /* Enabling RTH requires some of the logic in vxge_device_register and a
2659 * vpath reset. Due to these restrictions, only allow modification
2660 * while the interface is down.
2662 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2663 features ^= NETIF_F_RXHASH;
2668 static int vxge_set_features(struct net_device *dev, netdev_features_t features)
2670 struct vxgedev *vdev = netdev_priv(dev);
2671 netdev_features_t changed = dev->features ^ features;
2673 if (!(changed & NETIF_F_RXHASH))
2676 /* !netif_running() ensured by vxge_fix_features() */
2678 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2679 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2680 dev->features = features ^ NETIF_F_RXHASH;
2681 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2690 * @dev: pointer to the device structure.
2692 * This function is the open entry point of the driver. It mainly calls a
2693 * function to allocate Rx buffers and inserts them into the buffer
2694 * descriptors and then enables the Rx part of the NIC.
2695 * Return value: '0' on success and an appropriate (-)ve integer as
2696 * defined in errno.h file on failure.
2698 static int vxge_open(struct net_device *dev)
2700 enum vxge_hw_status status;
2701 struct vxgedev *vdev;
2702 struct __vxge_hw_device *hldev;
2703 struct vxge_vpath *vpath;
2708 vxge_debug_entryexit(VXGE_TRACE,
2709 "%s: %s:%d", dev->name, __func__, __LINE__);
2711 vdev = netdev_priv(dev);
2712 hldev = pci_get_drvdata(vdev->pdev);
2714 /* make sure you have link off by default every time Nic is
2716 netif_carrier_off(dev);
2719 status = vxge_open_vpaths(vdev);
2720 if (status != VXGE_HW_OK) {
2721 vxge_debug_init(VXGE_ERR,
2722 "%s: fatal: Vpath open failed", vdev->ndev->name);
2727 vdev->mtu = dev->mtu;
2729 status = vxge_add_isr(vdev);
2730 if (status != VXGE_HW_OK) {
2731 vxge_debug_init(VXGE_ERR,
2732 "%s: fatal: ISR add failed", dev->name);
2737 if (vdev->config.intr_type != MSI_X) {
2738 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2739 vdev->config.napi_weight);
2740 napi_enable(&vdev->napi);
2741 for (i = 0; i < vdev->no_of_vpath; i++) {
2742 vpath = &vdev->vpaths[i];
2743 vpath->ring.napi_p = &vdev->napi;
2746 for (i = 0; i < vdev->no_of_vpath; i++) {
2747 vpath = &vdev->vpaths[i];
2748 netif_napi_add(dev, &vpath->ring.napi,
2749 vxge_poll_msix, vdev->config.napi_weight);
2750 napi_enable(&vpath->ring.napi);
2751 vpath->ring.napi_p = &vpath->ring.napi;
2756 if (vdev->config.rth_steering) {
2757 status = vxge_rth_configure(vdev);
2758 if (status != VXGE_HW_OK) {
2759 vxge_debug_init(VXGE_ERR,
2760 "%s: fatal: RTH configuration failed",
2766 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2767 hldev->config.rth_en ? "enabled" : "disabled");
2769 for (i = 0; i < vdev->no_of_vpath; i++) {
2770 vpath = &vdev->vpaths[i];
2772 /* set initial mtu before enabling the device */
2773 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
2774 if (status != VXGE_HW_OK) {
2775 vxge_debug_init(VXGE_ERR,
2776 "%s: fatal: can not set new MTU", dev->name);
2782 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2783 vxge_debug_init(vdev->level_trace,
2784 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2785 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2787 /* Restore the DA, VID table and also multicast and promiscuous mode
2790 if (vdev->all_multi_flg) {
2791 for (i = 0; i < vdev->no_of_vpath; i++) {
2792 vpath = &vdev->vpaths[i];
2793 vxge_restore_vpath_mac_addr(vpath);
2794 vxge_restore_vpath_vid_table(vpath);
2796 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2797 if (status != VXGE_HW_OK)
2798 vxge_debug_init(VXGE_ERR,
2799 "%s:%d Enabling multicast failed",
2800 __func__, __LINE__);
2804 /* Enable vpath to sniff all unicast/multicast traffic that not
2805 * addressed to them. We allow promiscuous mode for PF only
2809 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2810 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2812 vxge_hw_mgmt_reg_write(vdev->devh,
2813 vxge_hw_mgmt_reg_type_mrpcim,
2815 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2816 rxmac_authorize_all_addr),
2819 vxge_hw_mgmt_reg_write(vdev->devh,
2820 vxge_hw_mgmt_reg_type_mrpcim,
2822 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2823 rxmac_authorize_all_vid),
2826 vxge_set_multicast(dev);
2828 /* Enabling Bcast and mcast for all vpath */
2829 for (i = 0; i < vdev->no_of_vpath; i++) {
2830 vpath = &vdev->vpaths[i];
2831 status = vxge_hw_vpath_bcast_enable(vpath->handle);
2832 if (status != VXGE_HW_OK)
2833 vxge_debug_init(VXGE_ERR,
2834 "%s : Can not enable bcast for vpath "
2835 "id %d", dev->name, i);
2836 if (vdev->config.addr_learn_en) {
2837 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2838 if (status != VXGE_HW_OK)
2839 vxge_debug_init(VXGE_ERR,
2840 "%s : Can not enable mcast for vpath "
2841 "id %d", dev->name, i);
2845 vxge_hw_device_setpause_data(vdev->devh, 0,
2846 vdev->config.tx_pause_enable,
2847 vdev->config.rx_pause_enable);
2849 if (vdev->vp_reset_timer.function == NULL)
2850 vxge_os_timer(&vdev->vp_reset_timer, vxge_poll_vp_reset,
2853 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2854 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2855 vxge_os_timer(&vdev->vp_lockup_timer, vxge_poll_vp_lockup,
2858 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2862 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2863 netif_carrier_on(vdev->ndev);
2864 netdev_notice(vdev->ndev, "Link Up\n");
2865 vdev->stats.link_up++;
2868 vxge_hw_device_intr_enable(vdev->devh);
2872 for (i = 0; i < vdev->no_of_vpath; i++) {
2873 vpath = &vdev->vpaths[i];
2875 vxge_hw_vpath_enable(vpath->handle);
2877 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
2880 netif_tx_start_all_queues(vdev->ndev);
2883 vxge_config_ci_for_tti_rti(vdev);
2891 if (vdev->config.intr_type != MSI_X)
2892 napi_disable(&vdev->napi);
2894 for (i = 0; i < vdev->no_of_vpath; i++)
2895 napi_disable(&vdev->vpaths[i].ring.napi);
2899 vxge_close_vpaths(vdev, 0);
2901 vxge_debug_entryexit(VXGE_TRACE,
2902 "%s: %s:%d Exiting...",
2903 dev->name, __func__, __LINE__);
2907 /* Loop through the mac address list and delete all the entries */
2908 static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2911 struct list_head *entry, *next;
2912 if (list_empty(&vpath->mac_addr_list))
2915 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2921 static void vxge_napi_del_all(struct vxgedev *vdev)
2924 if (vdev->config.intr_type != MSI_X)
2925 netif_napi_del(&vdev->napi);
2927 for (i = 0; i < vdev->no_of_vpath; i++)
2928 netif_napi_del(&vdev->vpaths[i].ring.napi);
2932 static int do_vxge_close(struct net_device *dev, int do_io)
2934 enum vxge_hw_status status;
2935 struct vxgedev *vdev;
2936 struct __vxge_hw_device *hldev;
2938 u64 val64, vpath_vector;
2939 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2940 dev->name, __func__, __LINE__);
2942 vdev = netdev_priv(dev);
2943 hldev = pci_get_drvdata(vdev->pdev);
2945 if (unlikely(!is_vxge_card_up(vdev)))
2948 /* If vxge_handle_crit_err task is executing,
2949 * wait till it completes. */
2950 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2954 /* Put the vpath back in normal mode */
2955 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2956 status = vxge_hw_mgmt_reg_read(vdev->devh,
2957 vxge_hw_mgmt_reg_type_mrpcim,
2960 struct vxge_hw_mrpcim_reg,
2961 rts_mgr_cbasin_cfg),
2963 if (status == VXGE_HW_OK) {
2964 val64 &= ~vpath_vector;
2965 status = vxge_hw_mgmt_reg_write(vdev->devh,
2966 vxge_hw_mgmt_reg_type_mrpcim,
2969 struct vxge_hw_mrpcim_reg,
2970 rts_mgr_cbasin_cfg),
2974 /* Remove the function 0 from promiscuous mode */
2975 vxge_hw_mgmt_reg_write(vdev->devh,
2976 vxge_hw_mgmt_reg_type_mrpcim,
2978 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2979 rxmac_authorize_all_addr),
2982 vxge_hw_mgmt_reg_write(vdev->devh,
2983 vxge_hw_mgmt_reg_type_mrpcim,
2985 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2986 rxmac_authorize_all_vid),
2993 del_timer_sync(&vdev->vp_lockup_timer);
2995 del_timer_sync(&vdev->vp_reset_timer);
2998 vxge_hw_device_wait_receive_idle(hldev);
3000 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3003 if (vdev->config.intr_type != MSI_X)
3004 napi_disable(&vdev->napi);
3006 for (i = 0; i < vdev->no_of_vpath; i++)
3007 napi_disable(&vdev->vpaths[i].ring.napi);
3010 netif_carrier_off(vdev->ndev);
3011 netdev_notice(vdev->ndev, "Link Down\n");
3012 netif_tx_stop_all_queues(vdev->ndev);
3014 /* Note that at this point xmit() is stopped by upper layer */
3016 vxge_hw_device_intr_disable(vdev->devh);
3020 vxge_napi_del_all(vdev);
3023 vxge_reset_all_vpaths(vdev);
3025 vxge_close_vpaths(vdev, 0);
3027 vxge_debug_entryexit(VXGE_TRACE,
3028 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3030 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3037 * @dev: device pointer.
3039 * This is the stop entry point of the driver. It needs to undo exactly
3040 * whatever was done by the open entry point, thus it's usually referred to
3041 * as the close function.Among other things this function mainly stops the
3042 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3043 * Return value: '0' on success and an appropriate (-)ve integer as
3044 * defined in errno.h file on failure.
3046 static int vxge_close(struct net_device *dev)
3048 do_vxge_close(dev, 1);
3054 * @dev: net device pointer.
3055 * @new_mtu :the new MTU size for the device.
3057 * A driver entry point to change MTU size for the device. Before changing
3058 * the MTU the device must be stopped.
3060 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3062 struct vxgedev *vdev = netdev_priv(dev);
3064 vxge_debug_entryexit(vdev->level_trace,
3065 "%s:%d", __func__, __LINE__);
3067 /* check if device is down already */
3068 if (unlikely(!is_vxge_card_up(vdev))) {
3069 /* just store new value, will use later on open() */
3071 vxge_debug_init(vdev->level_err,
3072 "%s", "device is down on MTU change");
3076 vxge_debug_init(vdev->level_trace,
3077 "trying to apply new MTU %d", new_mtu);
3079 if (vxge_close(dev))
3083 vdev->mtu = new_mtu;
3088 vxge_debug_init(vdev->level_trace,
3089 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3091 vxge_debug_entryexit(vdev->level_trace,
3092 "%s:%d Exiting...", __func__, __LINE__);
3099 * @dev: pointer to the device structure
3100 * @net_stats: pointer to struct rtnl_link_stats64
3104 vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
3106 struct vxgedev *vdev = netdev_priv(dev);
3109 /* net_stats already zeroed by caller */
3110 for (k = 0; k < vdev->no_of_vpath; k++) {
3111 struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
3112 struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
3114 u64 packets, bytes, multicast;
3117 start = u64_stats_fetch_begin_irq(&rxstats->syncp);
3119 packets = rxstats->rx_frms;
3120 multicast = rxstats->rx_mcast;
3121 bytes = rxstats->rx_bytes;
3122 } while (u64_stats_fetch_retry_irq(&rxstats->syncp, start));
3124 net_stats->rx_packets += packets;
3125 net_stats->rx_bytes += bytes;
3126 net_stats->multicast += multicast;
3128 net_stats->rx_errors += rxstats->rx_errors;
3129 net_stats->rx_dropped += rxstats->rx_dropped;
3132 start = u64_stats_fetch_begin_irq(&txstats->syncp);
3134 packets = txstats->tx_frms;
3135 bytes = txstats->tx_bytes;
3136 } while (u64_stats_fetch_retry_irq(&txstats->syncp, start));
3138 net_stats->tx_packets += packets;
3139 net_stats->tx_bytes += bytes;
3140 net_stats->tx_errors += txstats->tx_errors;
3144 static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
3146 enum vxge_hw_status status;
3149 /* Timestamp is passed to the driver via the FCS, therefore we
3150 * must disable the FCS stripping by the adapter. Since this is
3151 * required for the driver to load (due to a hardware bug),
3152 * there is no need to do anything special here.
3154 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3155 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3156 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
3158 status = vxge_hw_mgmt_reg_write(devh,
3159 vxge_hw_mgmt_reg_type_mrpcim,
3161 offsetof(struct vxge_hw_mrpcim_reg,
3164 vxge_hw_device_flush_io(devh);
3165 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
3169 static int vxge_hwtstamp_set(struct vxgedev *vdev, void __user *data)
3171 struct hwtstamp_config config;
3174 if (copy_from_user(&config, data, sizeof(config)))
3177 /* reserved for future extensions */
3181 /* Transmit HW Timestamp not supported */
3182 switch (config.tx_type) {
3183 case HWTSTAMP_TX_OFF:
3185 case HWTSTAMP_TX_ON:
3190 switch (config.rx_filter) {
3191 case HWTSTAMP_FILTER_NONE:
3193 config.rx_filter = HWTSTAMP_FILTER_NONE;
3196 case HWTSTAMP_FILTER_ALL:
3197 case HWTSTAMP_FILTER_SOME:
3198 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3199 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3200 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3201 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3202 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3203 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3204 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3205 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3206 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3207 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3208 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3209 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3210 case HWTSTAMP_FILTER_NTP_ALL:
3211 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
3215 config.rx_filter = HWTSTAMP_FILTER_ALL;
3222 for (i = 0; i < vdev->no_of_vpath; i++)
3223 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3225 if (copy_to_user(data, &config, sizeof(config)))
3231 static int vxge_hwtstamp_get(struct vxgedev *vdev, void __user *data)
3233 struct hwtstamp_config config;
3236 config.tx_type = HWTSTAMP_TX_OFF;
3237 config.rx_filter = (vdev->rx_hwts ?
3238 HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
3240 if (copy_to_user(data, &config, sizeof(config)))
3248 * @dev: Device pointer.
3249 * @rq: An IOCTL specific structure, that can contain a pointer to
3250 * a proprietary structure used to pass information to the driver.
3251 * @cmd: This is used to distinguish between the different commands that
3252 * can be passed to the IOCTL functions.
3254 * Entry point for the Ioctl.
3256 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3258 struct vxgedev *vdev = netdev_priv(dev);
3262 return vxge_hwtstamp_set(vdev, rq->ifr_data);
3264 return vxge_hwtstamp_get(vdev, rq->ifr_data);
3272 * @dev: pointer to net device structure
3273 * @txqueue: index of the hanging queue
3275 * Watchdog for transmit side.
3276 * This function is triggered if the Tx Queue is stopped
3277 * for a pre-defined amount of time when the Interface is still up.
3279 static void vxge_tx_watchdog(struct net_device *dev, unsigned int txqueue)
3281 struct vxgedev *vdev;
3283 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3285 vdev = netdev_priv(dev);
3287 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3289 schedule_work(&vdev->reset_task);
3290 vxge_debug_entryexit(VXGE_TRACE,
3291 "%s:%d Exiting...", __func__, __LINE__);
3295 * vxge_vlan_rx_add_vid
3296 * @dev: net device pointer.
3297 * @proto: vlan protocol
3300 * Add the vlan id to the devices vlan id table
3303 vxge_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
3305 struct vxgedev *vdev = netdev_priv(dev);
3306 struct vxge_vpath *vpath;
3309 /* Add these vlan to the vid table */
3310 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3311 vpath = &vdev->vpaths[vp_id];
3312 if (!vpath->is_open)
3314 vxge_hw_vpath_vid_add(vpath->handle, vid);
3316 set_bit(vid, vdev->active_vlans);
3321 * vxge_vlan_rx_kill_vid
3322 * @dev: net device pointer.
3323 * @proto: vlan protocol
3326 * Remove the vlan id from the device's vlan id table
3329 vxge_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
3331 struct vxgedev *vdev = netdev_priv(dev);
3332 struct vxge_vpath *vpath;
3335 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3337 /* Delete this vlan from the vid table */
3338 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3339 vpath = &vdev->vpaths[vp_id];
3340 if (!vpath->is_open)
3342 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3344 vxge_debug_entryexit(VXGE_TRACE,
3345 "%s:%d Exiting...", __func__, __LINE__);
3346 clear_bit(vid, vdev->active_vlans);
3350 static const struct net_device_ops vxge_netdev_ops = {
3351 .ndo_open = vxge_open,
3352 .ndo_stop = vxge_close,
3353 .ndo_get_stats64 = vxge_get_stats64,
3354 .ndo_start_xmit = vxge_xmit,
3355 .ndo_validate_addr = eth_validate_addr,
3356 .ndo_set_rx_mode = vxge_set_multicast,
3357 .ndo_do_ioctl = vxge_ioctl,
3358 .ndo_set_mac_address = vxge_set_mac_addr,
3359 .ndo_change_mtu = vxge_change_mtu,
3360 .ndo_fix_features = vxge_fix_features,
3361 .ndo_set_features = vxge_set_features,
3362 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3363 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3364 .ndo_tx_timeout = vxge_tx_watchdog,
3365 #ifdef CONFIG_NET_POLL_CONTROLLER
3366 .ndo_poll_controller = vxge_netpoll,
3370 static int vxge_device_register(struct __vxge_hw_device *hldev,
3371 struct vxge_config *config, int high_dma,
3372 int no_of_vpath, struct vxgedev **vdev_out)
3374 struct net_device *ndev;
3375 enum vxge_hw_status status = VXGE_HW_OK;
3376 struct vxgedev *vdev;
3377 int ret = 0, no_of_queue = 1;
3381 if (config->tx_steering_type)
3382 no_of_queue = no_of_vpath;
3384 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3388 vxge_hw_device_trace_level_get(hldev),
3389 "%s : device allocation failed", __func__);
3394 vxge_debug_entryexit(
3395 vxge_hw_device_trace_level_get(hldev),
3396 "%s: %s:%d Entering...",
3397 ndev->name, __func__, __LINE__);
3399 vdev = netdev_priv(ndev);
3400 memset(vdev, 0, sizeof(struct vxgedev));
3404 vdev->pdev = hldev->pdev;
3405 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3407 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
3409 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3411 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3412 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3413 NETIF_F_TSO | NETIF_F_TSO6 |
3414 NETIF_F_HW_VLAN_CTAG_TX;
3415 if (vdev->config.rth_steering != NO_STEERING)
3416 ndev->hw_features |= NETIF_F_RXHASH;
3418 ndev->features |= ndev->hw_features |
3419 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
3422 ndev->netdev_ops = &vxge_netdev_ops;
3424 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3425 INIT_WORK(&vdev->reset_task, vxge_reset);
3427 vxge_initialize_ethtool_ops(ndev);
3429 /* Allocate memory for vpath */
3430 vdev->vpaths = kcalloc(no_of_vpath, sizeof(struct vxge_vpath),
3432 if (!vdev->vpaths) {
3433 vxge_debug_init(VXGE_ERR,
3434 "%s: vpath memory allocation failed",
3440 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3441 "%s : checksumming enabled", __func__);
3444 ndev->features |= NETIF_F_HIGHDMA;
3445 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3446 "%s : using High DMA", __func__);
3449 /* MTU range: 68 - 9600 */
3450 ndev->min_mtu = VXGE_HW_MIN_MTU;
3451 ndev->max_mtu = VXGE_HW_MAX_MTU;
3453 ret = register_netdev(ndev);
3455 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3456 "%s: %s : device registration failed!",
3457 ndev->name, __func__);
3461 /* Set the factory defined MAC address initially */
3462 ndev->addr_len = ETH_ALEN;
3464 /* Make Link state as off at this point, when the Link change
3465 * interrupt comes the state will be automatically changed to
3468 netif_carrier_off(ndev);
3470 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3471 "%s: Ethernet device registered",
3477 /* Resetting the Device stats */
3478 status = vxge_hw_mrpcim_stats_access(
3480 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3485 if (status == VXGE_HW_ERR_PRIVILEGED_OPERATION)
3487 vxge_hw_device_trace_level_get(hldev),
3488 "%s: device stats clear returns"
3489 "VXGE_HW_ERR_PRIVILEGED_OPERATION", ndev->name);
3491 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3492 "%s: %s:%d Exiting...",
3493 ndev->name, __func__, __LINE__);
3497 kfree(vdev->vpaths);
3505 * vxge_device_unregister
3507 * This function will unregister and free network device
3509 static void vxge_device_unregister(struct __vxge_hw_device *hldev)
3511 struct vxgedev *vdev;
3512 struct net_device *dev;
3516 vdev = netdev_priv(dev);
3518 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3519 __func__, __LINE__);
3521 strlcpy(buf, dev->name, IFNAMSIZ);
3523 flush_work(&vdev->reset_task);
3525 /* in 2.6 will call stop() if device is up */
3526 unregister_netdev(dev);
3528 kfree(vdev->vpaths);
3530 /* we are safe to free it now */
3533 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3535 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3536 __func__, __LINE__);
3540 * vxge_callback_crit_err
3542 * This function is called by the alarm handler in interrupt context.
3543 * Driver must analyze it based on the event type.
3546 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3547 enum vxge_hw_event type, u64 vp_id)
3549 struct net_device *dev = hldev->ndev;
3550 struct vxgedev *vdev = netdev_priv(dev);
3551 struct vxge_vpath *vpath = NULL;
3554 vxge_debug_entryexit(vdev->level_trace,
3555 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3557 /* Note: This event type should be used for device wide
3558 * indications only - Serious errors, Slot freeze and critical errors
3560 vdev->cric_err_event = type;
3562 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3563 vpath = &vdev->vpaths[vpath_idx];
3564 if (vpath->device_id == vp_id)
3568 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3569 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3570 vxge_debug_init(VXGE_ERR,
3571 "%s: Slot is frozen", vdev->ndev->name);
3572 } else if (type == VXGE_HW_EVENT_SERR) {
3573 vxge_debug_init(VXGE_ERR,
3574 "%s: Encountered Serious Error",
3576 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3577 vxge_debug_init(VXGE_ERR,
3578 "%s: Encountered Critical Error",
3582 if ((type == VXGE_HW_EVENT_SERR) ||
3583 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3584 if (unlikely(vdev->exec_mode))
3585 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3586 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3587 vxge_hw_device_mask_all(hldev);
3588 if (unlikely(vdev->exec_mode))
3589 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3590 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3591 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3593 if (unlikely(vdev->exec_mode))
3594 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3596 /* check if this vpath is already set for reset */
3597 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3599 /* disable interrupts for this vpath */
3600 vxge_vpath_intr_disable(vdev, vpath_idx);
3602 /* stop the queue for this vpath */
3603 netif_tx_stop_queue(vpath->fifo.txq);
3608 vxge_debug_entryexit(vdev->level_trace,
3609 "%s: %s:%d Exiting...",
3610 vdev->ndev->name, __func__, __LINE__);
3613 static void verify_bandwidth(void)
3615 int i, band_width, total = 0, equal_priority = 0;
3617 /* 1. If user enters 0 for some fifo, give equal priority to all */
3618 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3619 if (bw_percentage[i] == 0) {
3625 if (!equal_priority) {
3626 /* 2. If sum exceeds 100, give equal priority to all */
3627 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3628 if (bw_percentage[i] == 0xFF)
3631 total += bw_percentage[i];
3632 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3639 if (!equal_priority) {
3640 /* Is all the bandwidth consumed? */
3641 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3642 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3643 /* Split rest of bw equally among next VPs*/
3645 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3646 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3647 if (band_width < 2) /* min of 2% */
3650 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3656 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3660 if (equal_priority) {
3661 vxge_debug_init(VXGE_ERR,
3662 "%s: Assigning equal bandwidth to all the vpaths",
3664 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3665 VXGE_HW_MAX_VIRTUAL_PATHS;
3666 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3667 bw_percentage[i] = bw_percentage[0];
3672 * Vpath configuration
3674 static int vxge_config_vpaths(struct vxge_hw_device_config *device_config,
3675 u64 vpath_mask, struct vxge_config *config_param)
3677 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3678 u32 txdl_size, txdl_per_memblock;
3680 temp = driver_config->vpath_per_dev;
3681 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3682 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3683 /* No more CPU. Return vpath number as zero.*/
3684 if (driver_config->g_no_cpus == -1)
3687 if (!driver_config->g_no_cpus)
3688 driver_config->g_no_cpus =
3689 netif_get_num_default_rss_queues();
3691 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3692 if (!driver_config->vpath_per_dev)
3693 driver_config->vpath_per_dev = 1;
3695 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3696 if (!vxge_bVALn(vpath_mask, i, 1))
3700 if (default_no_vpath < driver_config->vpath_per_dev)
3701 driver_config->vpath_per_dev = default_no_vpath;
3703 driver_config->g_no_cpus = driver_config->g_no_cpus -
3704 (driver_config->vpath_per_dev * 2);
3705 if (driver_config->g_no_cpus <= 0)
3706 driver_config->g_no_cpus = -1;
3709 if (driver_config->vpath_per_dev == 1) {
3710 vxge_debug_ll_config(VXGE_TRACE,
3711 "%s: Disable tx and rx steering, "
3712 "as single vpath is configured", VXGE_DRIVER_NAME);
3713 config_param->rth_steering = NO_STEERING;
3714 config_param->tx_steering_type = NO_STEERING;
3715 device_config->rth_en = 0;
3718 /* configure bandwidth */
3719 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3720 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3722 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3723 device_config->vp_config[i].vp_id = i;
3724 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3725 if (no_of_vpaths < driver_config->vpath_per_dev) {
3726 if (!vxge_bVALn(vpath_mask, i, 1)) {
3727 vxge_debug_ll_config(VXGE_TRACE,
3728 "%s: vpath: %d is not available",
3729 VXGE_DRIVER_NAME, i);
3732 vxge_debug_ll_config(VXGE_TRACE,
3733 "%s: vpath: %d available",
3734 VXGE_DRIVER_NAME, i);
3738 vxge_debug_ll_config(VXGE_TRACE,
3739 "%s: vpath: %d is not configured, "
3740 "max_config_vpath exceeded",
3741 VXGE_DRIVER_NAME, i);
3745 /* Configure Tx fifo's */
3746 device_config->vp_config[i].fifo.enable =
3747 VXGE_HW_FIFO_ENABLE;
3748 device_config->vp_config[i].fifo.max_frags =
3750 device_config->vp_config[i].fifo.memblock_size =
3751 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3753 txdl_size = device_config->vp_config[i].fifo.max_frags *
3754 sizeof(struct vxge_hw_fifo_txd);
3755 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3757 device_config->vp_config[i].fifo.fifo_blocks =
3758 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3760 device_config->vp_config[i].fifo.intr =
3761 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3763 /* Configure tti properties */
3764 device_config->vp_config[i].tti.intr_enable =
3765 VXGE_HW_TIM_INTR_ENABLE;
3767 device_config->vp_config[i].tti.btimer_val =
3768 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3770 device_config->vp_config[i].tti.timer_ac_en =
3771 VXGE_HW_TIM_TIMER_AC_ENABLE;
3773 /* For msi-x with napi (each vector has a handler of its own) -
3774 * Set CI to OFF for all vpaths
3776 device_config->vp_config[i].tti.timer_ci_en =
3777 VXGE_HW_TIM_TIMER_CI_DISABLE;
3779 device_config->vp_config[i].tti.timer_ri_en =
3780 VXGE_HW_TIM_TIMER_RI_DISABLE;
3782 device_config->vp_config[i].tti.util_sel =
3783 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3785 device_config->vp_config[i].tti.ltimer_val =
3786 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3788 device_config->vp_config[i].tti.rtimer_val =
3789 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3791 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3792 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3793 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3794 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3795 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3796 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3797 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3799 /* Configure Rx rings */
3800 device_config->vp_config[i].ring.enable =
3801 VXGE_HW_RING_ENABLE;
3803 device_config->vp_config[i].ring.ring_blocks =
3804 VXGE_HW_DEF_RING_BLOCKS;
3806 device_config->vp_config[i].ring.buffer_mode =
3807 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3809 device_config->vp_config[i].ring.rxds_limit =
3810 VXGE_HW_DEF_RING_RXDS_LIMIT;
3812 device_config->vp_config[i].ring.scatter_mode =
3813 VXGE_HW_RING_SCATTER_MODE_A;
3815 /* Configure rti properties */
3816 device_config->vp_config[i].rti.intr_enable =
3817 VXGE_HW_TIM_INTR_ENABLE;
3819 device_config->vp_config[i].rti.btimer_val =
3820 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3822 device_config->vp_config[i].rti.timer_ac_en =
3823 VXGE_HW_TIM_TIMER_AC_ENABLE;
3825 device_config->vp_config[i].rti.timer_ci_en =
3826 VXGE_HW_TIM_TIMER_CI_DISABLE;
3828 device_config->vp_config[i].rti.timer_ri_en =
3829 VXGE_HW_TIM_TIMER_RI_DISABLE;
3831 device_config->vp_config[i].rti.util_sel =
3832 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3834 device_config->vp_config[i].rti.urange_a =
3836 device_config->vp_config[i].rti.urange_b =
3838 device_config->vp_config[i].rti.urange_c =
3840 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3841 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3842 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3843 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3845 device_config->vp_config[i].rti.rtimer_val =
3846 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3848 device_config->vp_config[i].rti.ltimer_val =
3849 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3851 device_config->vp_config[i].rpa_strip_vlan_tag =
3855 driver_config->vpath_per_dev = temp;
3856 return no_of_vpaths;
3859 /* initialize device configuratrions */
3860 static void vxge_device_config_init(struct vxge_hw_device_config *device_config,
3863 /* Used for CQRQ/SRQ. */
3864 device_config->dma_blockpool_initial =
3865 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3867 device_config->dma_blockpool_max =
3868 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3870 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3871 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3873 if (!IS_ENABLED(CONFIG_PCI_MSI)) {
3874 vxge_debug_init(VXGE_ERR,
3875 "%s: This Kernel does not support "
3876 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3880 /* Configure whether MSI-X or IRQL. */
3881 switch (*intr_type) {
3883 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3887 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
3891 /* Timer period between device poll */
3892 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3894 /* Configure mac based steering. */
3895 device_config->rts_mac_en = addr_learn_en;
3897 /* Configure Vpaths */
3898 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3900 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3902 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3903 device_config->intr_mode);
3904 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3905 device_config->device_poll_millis);
3906 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3907 device_config->rth_en);
3908 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3909 device_config->rth_it_type);
3912 static void vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3916 vxge_debug_init(VXGE_TRACE,
3917 "%s: %d Vpath(s) opened",
3918 vdev->ndev->name, vdev->no_of_vpath);
3920 switch (vdev->config.intr_type) {
3922 vxge_debug_init(VXGE_TRACE,
3923 "%s: Interrupt type INTA", vdev->ndev->name);
3927 vxge_debug_init(VXGE_TRACE,
3928 "%s: Interrupt type MSI-X", vdev->ndev->name);
3932 if (vdev->config.rth_steering) {
3933 vxge_debug_init(VXGE_TRACE,
3934 "%s: RTH steering enabled for TCP_IPV4",
3937 vxge_debug_init(VXGE_TRACE,
3938 "%s: RTH steering disabled", vdev->ndev->name);
3941 switch (vdev->config.tx_steering_type) {
3943 vxge_debug_init(VXGE_TRACE,
3944 "%s: Tx steering disabled", vdev->ndev->name);
3946 case TX_PRIORITY_STEERING:
3947 vxge_debug_init(VXGE_TRACE,
3948 "%s: Unsupported tx steering option",
3950 vxge_debug_init(VXGE_TRACE,
3951 "%s: Tx steering disabled", vdev->ndev->name);
3952 vdev->config.tx_steering_type = 0;
3954 case TX_VLAN_STEERING:
3955 vxge_debug_init(VXGE_TRACE,
3956 "%s: Unsupported tx steering option",
3958 vxge_debug_init(VXGE_TRACE,
3959 "%s: Tx steering disabled", vdev->ndev->name);
3960 vdev->config.tx_steering_type = 0;
3962 case TX_MULTIQ_STEERING:
3963 vxge_debug_init(VXGE_TRACE,
3964 "%s: Tx multiqueue steering enabled",
3967 case TX_PORT_STEERING:
3968 vxge_debug_init(VXGE_TRACE,
3969 "%s: Tx port steering enabled",
3973 vxge_debug_init(VXGE_ERR,
3974 "%s: Unsupported tx steering type",
3976 vxge_debug_init(VXGE_TRACE,
3977 "%s: Tx steering disabled", vdev->ndev->name);
3978 vdev->config.tx_steering_type = 0;
3981 if (vdev->config.addr_learn_en)
3982 vxge_debug_init(VXGE_TRACE,
3983 "%s: MAC Address learning enabled", vdev->ndev->name);
3985 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3986 if (!vxge_bVALn(vpath_mask, i, 1))
3988 vxge_debug_ll_config(VXGE_TRACE,
3989 "%s: MTU size - %d", vdev->ndev->name,
3991 config.vp_config[i].mtu);
3992 vxge_debug_init(VXGE_TRACE,
3993 "%s: VLAN tag stripping %s", vdev->ndev->name,
3995 config.vp_config[i].rpa_strip_vlan_tag
3996 ? "Enabled" : "Disabled");
3997 vxge_debug_ll_config(VXGE_TRACE,
3998 "%s: Max frags : %d", vdev->ndev->name,
4000 config.vp_config[i].fifo.max_frags);
4006 * vxge_pm_suspend - vxge power management suspend entry point
4007 * @dev_d: device pointer
4010 static int __maybe_unused vxge_pm_suspend(struct device *dev_d)
4015 * vxge_pm_resume - vxge power management resume entry point
4016 * @dev_d: device pointer
4019 static int __maybe_unused vxge_pm_resume(struct device *dev_d)
4025 * vxge_io_error_detected - called when PCI error is detected
4026 * @pdev: Pointer to PCI device
4027 * @state: The current pci connection state
4029 * This function is called after a PCI bus error affecting
4030 * this device has been detected.
4032 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4033 pci_channel_state_t state)
4035 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4036 struct net_device *netdev = hldev->ndev;
4038 netif_device_detach(netdev);
4040 if (state == pci_channel_io_perm_failure)
4041 return PCI_ERS_RESULT_DISCONNECT;
4043 if (netif_running(netdev)) {
4044 /* Bring down the card, while avoiding PCI I/O */
4045 do_vxge_close(netdev, 0);
4048 pci_disable_device(pdev);
4050 return PCI_ERS_RESULT_NEED_RESET;
4054 * vxge_io_slot_reset - called after the pci bus has been reset.
4055 * @pdev: Pointer to PCI device
4057 * Restart the card from scratch, as if from a cold-boot.
4058 * At this point, the card has exprienced a hard reset,
4059 * followed by fixups by BIOS, and has its config space
4060 * set up identically to what it was at cold boot.
4062 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4064 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4065 struct net_device *netdev = hldev->ndev;
4067 struct vxgedev *vdev = netdev_priv(netdev);
4069 if (pci_enable_device(pdev)) {
4070 netdev_err(netdev, "Cannot re-enable device after reset\n");
4071 return PCI_ERS_RESULT_DISCONNECT;
4074 pci_set_master(pdev);
4075 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
4077 return PCI_ERS_RESULT_RECOVERED;
4081 * vxge_io_resume - called when traffic can start flowing again.
4082 * @pdev: Pointer to PCI device
4084 * This callback is called when the error recovery driver tells
4085 * us that its OK to resume normal operation.
4087 static void vxge_io_resume(struct pci_dev *pdev)
4089 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4090 struct net_device *netdev = hldev->ndev;
4092 if (netif_running(netdev)) {
4093 if (vxge_open(netdev)) {
4095 "Can't bring device back up after reset\n");
4100 netif_device_attach(netdev);
4103 static inline u32 vxge_get_num_vfs(u64 function_mode)
4105 u32 num_functions = 0;
4107 switch (function_mode) {
4108 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4109 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4112 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4115 case VXGE_HW_FUNCTION_MODE_SRIOV:
4116 case VXGE_HW_FUNCTION_MODE_MRIOV:
4117 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4120 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4123 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4126 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4127 num_functions = 8; /* TODO */
4130 return num_functions;
4133 int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4135 struct __vxge_hw_device *hldev = vdev->devh;
4136 u32 maj, min, bld, cmaj, cmin, cbld;
4137 enum vxge_hw_status status;
4138 const struct firmware *fw;
4141 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4143 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4144 VXGE_DRIVER_NAME, fw_name);
4148 /* Load the new firmware onto the adapter */
4149 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4150 if (status != VXGE_HW_OK) {
4151 vxge_debug_init(VXGE_ERR,
4152 "%s: FW image download to adapter failed '%s'.",
4153 VXGE_DRIVER_NAME, fw_name);
4158 /* Read the version of the new firmware */
4159 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4160 if (status != VXGE_HW_OK) {
4161 vxge_debug_init(VXGE_ERR,
4162 "%s: Upgrade read version failed '%s'.",
4163 VXGE_DRIVER_NAME, fw_name);
4168 cmaj = vdev->config.device_hw_info.fw_version.major;
4169 cmin = vdev->config.device_hw_info.fw_version.minor;
4170 cbld = vdev->config.device_hw_info.fw_version.build;
4171 /* It's possible the version in /lib/firmware is not the latest version.
4172 * If so, we could get into a loop of trying to upgrade to the latest
4173 * and flashing the older version.
4175 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4181 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4184 /* Flash the adapter with the new firmware */
4185 status = vxge_hw_flash_fw(hldev);
4186 if (status != VXGE_HW_OK) {
4187 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4188 VXGE_DRIVER_NAME, fw_name);
4193 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4194 "hard reset before using, thus requiring a system reboot or a "
4195 "hotplug event.\n");
4198 release_firmware(fw);
4202 static int vxge_probe_fw_update(struct vxgedev *vdev)
4208 maj = vdev->config.device_hw_info.fw_version.major;
4209 min = vdev->config.device_hw_info.fw_version.minor;
4210 bld = vdev->config.device_hw_info.fw_version.build;
4212 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4215 /* Ignore the build number when determining if the current firmware is
4216 * "too new" to load the driver
4218 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4219 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4220 "version, unable to load driver\n",
4225 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4226 * work with this driver.
4228 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4229 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4230 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4234 /* If file not specified, determine gPXE or not */
4235 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4237 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4238 if (vdev->devh->eprom_versions[i]) {
4244 fw_name = "vxge/X3fw-pxe.ncf";
4246 fw_name = "vxge/X3fw.ncf";
4248 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4249 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4250 * probe, so ignore them
4252 if (ret != -EINVAL && ret != -ENOENT)
4257 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4258 VXGE_FW_VER(maj, min, 0)) {
4259 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4260 " be used with this driver.",
4261 VXGE_DRIVER_NAME, maj, min, bld);
4268 static int is_sriov_initialized(struct pci_dev *pdev)
4273 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4275 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4276 if (ctrl & PCI_SRIOV_CTRL_VFE)
4282 static const struct vxge_hw_uld_cbs vxge_callbacks = {
4283 .link_up = vxge_callback_link_up,
4284 .link_down = vxge_callback_link_down,
4285 .crit_err = vxge_callback_crit_err,
4290 * @pdev : structure containing the PCI related information of the device.
4291 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4293 * This function is called when a new PCI device gets detected and initializes
4296 * returns 0 on success and negative on failure.
4300 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4302 struct __vxge_hw_device *hldev;
4303 enum vxge_hw_status status;
4307 struct vxgedev *vdev;
4308 struct vxge_config *ll_config = NULL;
4309 struct vxge_hw_device_config *device_config = NULL;
4310 struct vxge_hw_device_attr attr;
4311 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4313 struct vxge_mac_addrs *entry;
4314 static int bus = -1, device = -1;
4317 enum vxge_hw_status is_privileged;
4321 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4324 /* In SRIOV-17 mode, functions of the same adapter
4325 * can be deployed on different buses
4327 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4331 bus = pdev->bus->number;
4332 device = PCI_SLOT(pdev->devfn);
4335 if (driver_config->config_dev_cnt &&
4336 (driver_config->config_dev_cnt !=
4337 driver_config->total_dev_cnt))
4338 vxge_debug_init(VXGE_ERR,
4339 "%s: Configured %d of %d devices",
4341 driver_config->config_dev_cnt,
4342 driver_config->total_dev_cnt);
4343 driver_config->config_dev_cnt = 0;
4344 driver_config->total_dev_cnt = 0;
4347 /* Now making the CPU based no of vpath calculation
4348 * applicable for individual functions as well.
4350 driver_config->g_no_cpus = 0;
4351 driver_config->vpath_per_dev = max_config_vpath;
4353 driver_config->total_dev_cnt++;
4354 if (++driver_config->config_dev_cnt > max_config_dev) {
4359 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4361 if (!device_config) {
4363 vxge_debug_init(VXGE_ERR,
4364 "device_config : malloc failed %s %d",
4365 __FILE__, __LINE__);
4369 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
4372 vxge_debug_init(VXGE_ERR,
4373 "device_config : malloc failed %s %d",
4374 __FILE__, __LINE__);
4377 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4378 ll_config->intr_type = MSI_X;
4379 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4380 ll_config->rth_steering = RTH_STEERING;
4382 /* get the default configuration parameters */
4383 vxge_hw_device_config_default_get(device_config);
4385 /* initialize configuration parameters */
4386 vxge_device_config_init(device_config, &ll_config->intr_type);
4388 ret = pci_enable_device(pdev);
4390 vxge_debug_init(VXGE_ERR,
4391 "%s : can not enable PCI device", __func__);
4395 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64))) {
4396 vxge_debug_ll_config(VXGE_TRACE,
4397 "%s : using 64bit DMA", __func__);
4401 if (dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
4402 vxge_debug_init(VXGE_ERR,
4403 "%s : unable to obtain 64bit DMA for "
4404 "consistent allocations", __func__);
4408 } else if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
4409 vxge_debug_ll_config(VXGE_TRACE,
4410 "%s : using 32bit DMA", __func__);
4416 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4418 vxge_debug_init(VXGE_ERR,
4419 "%s : request regions failed", __func__);
4423 pci_set_master(pdev);
4425 attr.bar0 = pci_ioremap_bar(pdev, 0);
4427 vxge_debug_init(VXGE_ERR,
4428 "%s : cannot remap io memory bar0", __func__);
4432 vxge_debug_ll_config(VXGE_TRACE,
4433 "pci ioremap bar0: %p:0x%llx",
4435 (unsigned long long)pci_resource_start(pdev, 0));
4437 status = vxge_hw_device_hw_info_get(attr.bar0,
4438 &ll_config->device_hw_info);
4439 if (status != VXGE_HW_OK) {
4440 vxge_debug_init(VXGE_ERR,
4441 "%s: Reading of hardware info failed."
4442 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4447 vpath_mask = ll_config->device_hw_info.vpath_mask;
4448 if (vpath_mask == 0) {
4449 vxge_debug_ll_config(VXGE_TRACE,
4450 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4455 vxge_debug_ll_config(VXGE_TRACE,
4456 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4457 (unsigned long long)vpath_mask);
4459 function_mode = ll_config->device_hw_info.function_mode;
4460 host_type = ll_config->device_hw_info.host_type;
4461 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4462 ll_config->device_hw_info.func_id);
4464 /* Check how many vpaths are available */
4465 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4466 if (!((vpath_mask) & vxge_mBIT(i)))
4468 max_vpath_supported++;
4472 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4474 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4475 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4476 (ll_config->intr_type != INTA)) {
4477 ret = pci_enable_sriov(pdev, num_vfs);
4479 vxge_debug_ll_config(VXGE_ERR,
4480 "Failed in enabling SRIOV mode: %d\n", ret);
4481 /* No need to fail out, as an error here is non-fatal */
4485 * Configure vpaths and get driver configured number of vpaths
4486 * which is less than or equal to the maximum vpaths per function.
4488 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
4490 vxge_debug_ll_config(VXGE_ERR,
4491 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4496 /* Setting driver callbacks */
4497 attr.uld_callbacks = &vxge_callbacks;
4499 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4500 if (status != VXGE_HW_OK) {
4501 vxge_debug_init(VXGE_ERR,
4502 "Failed to initialize device (%d)", status);
4507 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4508 ll_config->device_hw_info.fw_version.minor,
4509 ll_config->device_hw_info.fw_version.build) >=
4510 VXGE_EPROM_FW_VER) {
4511 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4513 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4514 if (status != VXGE_HW_OK) {
4515 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4517 /* This is a non-fatal error, continue */
4520 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4521 hldev->eprom_versions[i] = img[i].version;
4522 if (!img[i].is_valid)
4524 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
4525 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
4526 VXGE_EPROM_IMG_MAJOR(img[i].version),
4527 VXGE_EPROM_IMG_MINOR(img[i].version),
4528 VXGE_EPROM_IMG_FIX(img[i].version),
4529 VXGE_EPROM_IMG_BUILD(img[i].version));
4533 /* if FCS stripping is not disabled in MAC fail driver load */
4534 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4535 if (status != VXGE_HW_OK) {
4536 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4537 " failing driver load", VXGE_DRIVER_NAME);
4542 /* Always enable HWTS. This will always cause the FCS to be invalid,
4543 * due to the fact that HWTS is using the FCS as the location of the
4544 * timestamp. The HW FCS checking will still correctly determine if
4545 * there is a valid checksum, and the FCS is being removed by the driver
4546 * anyway. So no functionality is being lost. Since it is always
4547 * enabled, we now simply use the ioctl call to set whether or not the
4548 * driver should be paying attention to the HWTS.
4550 if (is_privileged == VXGE_HW_OK) {
4551 status = vxge_timestamp_config(hldev);
4552 if (status != VXGE_HW_OK) {
4553 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4560 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4562 /* set private device info */
4563 pci_set_drvdata(pdev, hldev);
4565 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4566 ll_config->addr_learn_en = addr_learn_en;
4567 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4568 ll_config->rth_hash_type_tcpipv4 = 1;
4569 ll_config->rth_hash_type_ipv4 = 0;
4570 ll_config->rth_hash_type_tcpipv6 = 0;
4571 ll_config->rth_hash_type_ipv6 = 0;
4572 ll_config->rth_hash_type_tcpipv6ex = 0;
4573 ll_config->rth_hash_type_ipv6ex = 0;
4574 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4575 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4576 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4578 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4585 ret = vxge_probe_fw_update(vdev);
4589 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4590 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4591 vxge_hw_device_trace_level_get(hldev));
4593 /* set private HW device info */
4594 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4595 vdev->bar0 = attr.bar0;
4596 vdev->max_vpath_supported = max_vpath_supported;
4597 vdev->no_of_vpath = no_of_vpath;
4599 /* Virtual Path count */
4600 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4601 if (!vxge_bVALn(vpath_mask, i, 1))
4603 if (j >= vdev->no_of_vpath)
4606 vdev->vpaths[j].is_configured = 1;
4607 vdev->vpaths[j].device_id = i;
4608 vdev->vpaths[j].ring.driver_id = j;
4609 vdev->vpaths[j].vdev = vdev;
4610 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4611 memcpy((u8 *)vdev->vpaths[j].macaddr,
4612 ll_config->device_hw_info.mac_addrs[i],
4615 /* Initialize the mac address list header */
4616 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4618 vdev->vpaths[j].mac_addr_cnt = 0;
4619 vdev->vpaths[j].mcast_addr_cnt = 0;
4622 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4623 vdev->max_config_port = max_config_port;
4625 vdev->vlan_tag_strip = vlan_tag_strip;
4627 /* map the hashing selector table to the configured vpaths */
4628 for (i = 0; i < vdev->no_of_vpath; i++)
4629 vdev->vpath_selector[i] = vpath_selector[i];
4631 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4633 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4634 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4635 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4637 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4638 vdev->ndev->name, ll_config->device_hw_info.serial_number);
4640 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4641 vdev->ndev->name, ll_config->device_hw_info.part_number);
4643 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4644 vdev->ndev->name, ll_config->device_hw_info.product_desc);
4646 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4647 vdev->ndev->name, macaddr);
4649 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4650 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4652 vxge_debug_init(VXGE_TRACE,
4653 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4654 ll_config->device_hw_info.fw_version.version,
4655 ll_config->device_hw_info.fw_date.date);
4658 switch (ll_config->device_hw_info.function_mode) {
4659 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4660 vxge_debug_init(VXGE_TRACE,
4661 "%s: Single Function Mode Enabled", vdev->ndev->name);
4663 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4664 vxge_debug_init(VXGE_TRACE,
4665 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4667 case VXGE_HW_FUNCTION_MODE_SRIOV:
4668 vxge_debug_init(VXGE_TRACE,
4669 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4671 case VXGE_HW_FUNCTION_MODE_MRIOV:
4672 vxge_debug_init(VXGE_TRACE,
4673 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4678 vxge_print_parm(vdev, vpath_mask);
4680 /* Store the fw version for ethttool option */
4681 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
4682 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4684 /* Copy the station mac address to the list */
4685 for (i = 0; i < vdev->no_of_vpath; i++) {
4686 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
4687 if (NULL == entry) {
4688 vxge_debug_init(VXGE_ERR,
4689 "%s: mac_addr_list : memory allocation failed",
4694 macaddr = (u8 *)&entry->macaddr;
4695 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4696 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4697 vdev->vpaths[i].mac_addr_cnt = 1;
4700 kfree(device_config);
4703 * INTA is shared in multi-function mode. This is unlike the INTA
4704 * implementation in MR mode, where each VH has its own INTA message.
4705 * - INTA is masked (disabled) as long as at least one function sets
4706 * its TITAN_MASK_ALL_INT.ALARM bit.
4707 * - INTA is unmasked (enabled) when all enabled functions have cleared
4708 * their own TITAN_MASK_ALL_INT.ALARM bit.
4709 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4710 * Though this driver leaves the top level interrupts unmasked while
4711 * leaving the required module interrupt bits masked on exit, there
4712 * could be a rougue driver around that does not follow this procedure
4713 * resulting in a failure to generate interrupts. The following code is
4714 * present to prevent such a failure.
4717 if (ll_config->device_hw_info.function_mode ==
4718 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4719 if (vdev->config.intr_type == INTA)
4720 vxge_hw_device_unmask_all(hldev);
4722 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4723 vdev->ndev->name, __func__, __LINE__);
4725 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4726 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4727 vxge_hw_device_trace_level_get(hldev));
4733 for (i = 0; i < vdev->no_of_vpath; i++)
4734 vxge_free_mac_add_list(&vdev->vpaths[i]);
4736 vxge_device_unregister(hldev);
4738 vxge_hw_device_terminate(hldev);
4739 pci_disable_sriov(pdev);
4743 pci_release_region(pdev, 0);
4745 pci_disable_device(pdev);
4748 kfree(device_config);
4749 driver_config->config_dev_cnt--;
4750 driver_config->total_dev_cnt--;
4755 * vxge_rem_nic - Free the PCI device
4756 * @pdev: structure containing the PCI related information of the device.
4757 * Description: This function is called by the Pci subsystem to release a
4758 * PCI device and free up all resource held up by the device.
4760 static void vxge_remove(struct pci_dev *pdev)
4762 struct __vxge_hw_device *hldev;
4763 struct vxgedev *vdev;
4766 hldev = pci_get_drvdata(pdev);
4770 vdev = netdev_priv(hldev->ndev);
4772 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
4773 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4776 for (i = 0; i < vdev->no_of_vpath; i++)
4777 vxge_free_mac_add_list(&vdev->vpaths[i]);
4779 vxge_device_unregister(hldev);
4780 /* Do not call pci_disable_sriov here, as it will break child devices */
4781 vxge_hw_device_terminate(hldev);
4782 iounmap(vdev->bar0);
4783 pci_release_region(pdev, 0);
4784 pci_disable_device(pdev);
4785 driver_config->config_dev_cnt--;
4786 driver_config->total_dev_cnt--;
4788 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4789 __func__, __LINE__);
4790 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4794 static const struct pci_error_handlers vxge_err_handler = {
4795 .error_detected = vxge_io_error_detected,
4796 .slot_reset = vxge_io_slot_reset,
4797 .resume = vxge_io_resume,
4800 static SIMPLE_DEV_PM_OPS(vxge_pm_ops, vxge_pm_suspend, vxge_pm_resume);
4802 static struct pci_driver vxge_driver = {
4803 .name = VXGE_DRIVER_NAME,
4804 .id_table = vxge_id_table,
4805 .probe = vxge_probe,
4806 .remove = vxge_remove,
4807 .driver.pm = &vxge_pm_ops,
4808 .err_handler = &vxge_err_handler,
4816 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4817 pr_info("Driver version: %s\n", DRV_VERSION);
4821 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4825 ret = pci_register_driver(&vxge_driver);
4827 kfree(driver_config);
4831 if (driver_config->config_dev_cnt &&
4832 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4833 vxge_debug_init(VXGE_ERR,
4834 "%s: Configured %d of %d devices",
4835 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4836 driver_config->total_dev_cnt);
4844 pci_unregister_driver(&vxge_driver);
4845 kfree(driver_config);
4847 module_init(vxge_starter);
4848 module_exit(vxge_closer);