1 /******************************************************************************
2 * This software may be used and distributed according to the terms of
3 * the GNU General Public License (GPL), incorporated herein by reference.
4 * Drivers based on or derived from this code fall under the GPL and must
5 * retain the authorship, copyright and license notice. This file is not
6 * a complete program and may only be used when the entire operating
7 * system is licensed under the GPL.
8 * See the file COPYING in this distribution for more information.
10 * vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2010 Exar Corp.
14 * The module loadable parameters that are supported by the driver and a brief
15 * explanation of all the variables:
17 * Strip VLAN Tag enable/disable. Instructs the device to remove
18 * the VLAN tag from all received tagged frames that are not
19 * replicated at the internal L2 switch.
20 * 0 - Do not strip the VLAN tag.
21 * 1 - Strip the VLAN tag.
24 * Enable learning the mac address of the guest OS interface in
25 * a virtualization environment.
30 * Maximum number of port to be supported.
34 * This configures the maximum no of VPATH configures for each
36 * MIN - 1 and MAX - 17
39 * This configures maximum no of Device function to be enabled.
40 * MIN - 1 and MAX - 17
42 ******************************************************************************/
44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/if_vlan.h>
47 #include <linux/interrupt.h>
48 #include <linux/pci.h>
49 #include <linux/slab.h>
50 #include <linux/tcp.h>
52 #include <linux/netdevice.h>
53 #include <linux/etherdevice.h>
54 #include <linux/firmware.h>
55 #include <linux/net_tstamp.h>
56 #include <linux/prefetch.h>
57 #include "vxge-main.h"
60 MODULE_LICENSE("Dual BSD/GPL");
61 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
62 "Virtualized Server Adapter");
64 static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
65 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
67 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
72 MODULE_DEVICE_TABLE(pci, vxge_id_table);
74 VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
75 VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
76 VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
77 VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
78 VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
79 VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
81 static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
82 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
83 static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
84 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
85 module_param_array(bw_percentage, uint, NULL, 0);
87 static struct vxge_drv_config *driver_config;
89 static inline int is_vxge_card_up(struct vxgedev *vdev)
91 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
94 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
96 struct sk_buff **skb_ptr = NULL;
97 struct sk_buff **temp;
98 #define NR_SKB_COMPLETED 128
99 struct sk_buff *completed[NR_SKB_COMPLETED];
106 if (__netif_tx_trylock(fifo->txq)) {
107 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
108 NR_SKB_COMPLETED, &more);
109 __netif_tx_unlock(fifo->txq);
113 for (temp = completed; temp != skb_ptr; temp++)
114 dev_kfree_skb_irq(*temp);
118 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
122 /* Complete all transmits */
123 for (i = 0; i < vdev->no_of_vpath; i++)
124 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
127 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
130 struct vxge_ring *ring;
132 /* Complete all receives*/
133 for (i = 0; i < vdev->no_of_vpath; i++) {
134 ring = &vdev->vpaths[i].ring;
135 vxge_hw_vpath_poll_rx(ring->handle);
140 * vxge_callback_link_up
142 * This function is called during interrupt context to notify link up state
145 static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
147 struct net_device *dev = hldev->ndev;
148 struct vxgedev *vdev = netdev_priv(dev);
150 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
151 vdev->ndev->name, __func__, __LINE__);
152 netdev_notice(vdev->ndev, "Link Up\n");
153 vdev->stats.link_up++;
155 netif_carrier_on(vdev->ndev);
156 netif_tx_wake_all_queues(vdev->ndev);
158 vxge_debug_entryexit(VXGE_TRACE,
159 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
163 * vxge_callback_link_down
165 * This function is called during interrupt context to notify link down state
168 static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
170 struct net_device *dev = hldev->ndev;
171 struct vxgedev *vdev = netdev_priv(dev);
173 vxge_debug_entryexit(VXGE_TRACE,
174 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
175 netdev_notice(vdev->ndev, "Link Down\n");
177 vdev->stats.link_down++;
178 netif_carrier_off(vdev->ndev);
179 netif_tx_stop_all_queues(vdev->ndev);
181 vxge_debug_entryexit(VXGE_TRACE,
182 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
190 static struct sk_buff *
191 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
193 struct net_device *dev;
195 struct vxge_rx_priv *rx_priv;
198 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
199 ring->ndev->name, __func__, __LINE__);
201 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
203 /* try to allocate skb first. this one may fail */
204 skb = netdev_alloc_skb(dev, skb_size +
205 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
207 vxge_debug_mem(VXGE_ERR,
208 "%s: out of memory to allocate SKB", dev->name);
209 ring->stats.skb_alloc_fail++;
213 vxge_debug_mem(VXGE_TRACE,
214 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
215 __func__, __LINE__, skb);
217 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
220 rx_priv->skb_data = NULL;
221 rx_priv->data_size = skb_size;
222 vxge_debug_entryexit(VXGE_TRACE,
223 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
231 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
233 struct vxge_rx_priv *rx_priv;
236 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
237 ring->ndev->name, __func__, __LINE__);
238 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
240 rx_priv->skb_data = rx_priv->skb->data;
241 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
242 rx_priv->data_size, PCI_DMA_FROMDEVICE);
244 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
245 ring->stats.pci_map_fail++;
248 vxge_debug_mem(VXGE_TRACE,
249 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
250 ring->ndev->name, __func__, __LINE__,
251 (unsigned long long)dma_addr);
252 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
254 rx_priv->data_dma = dma_addr;
255 vxge_debug_entryexit(VXGE_TRACE,
256 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
262 * vxge_rx_initial_replenish
263 * Allocation of RxD as an initial replenish procedure.
265 static enum vxge_hw_status
266 vxge_rx_initial_replenish(void *dtrh, void *userdata)
268 struct vxge_ring *ring = (struct vxge_ring *)userdata;
269 struct vxge_rx_priv *rx_priv;
271 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
272 ring->ndev->name, __func__, __LINE__);
273 if (vxge_rx_alloc(dtrh, ring,
274 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
277 if (vxge_rx_map(dtrh, ring)) {
278 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
279 dev_kfree_skb(rx_priv->skb);
283 vxge_debug_entryexit(VXGE_TRACE,
284 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
290 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
291 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
294 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
295 ring->ndev->name, __func__, __LINE__);
296 skb_record_rx_queue(skb, ring->driver_id);
297 skb->protocol = eth_type_trans(skb, ring->ndev);
299 u64_stats_update_begin(&ring->stats.syncp);
300 ring->stats.rx_frms++;
301 ring->stats.rx_bytes += pkt_length;
303 if (skb->pkt_type == PACKET_MULTICAST)
304 ring->stats.rx_mcast++;
305 u64_stats_update_end(&ring->stats.syncp);
307 vxge_debug_rx(VXGE_TRACE,
308 "%s: %s:%d skb protocol = %d",
309 ring->ndev->name, __func__, __LINE__, skb->protocol);
311 if (ring->vlgrp && ext_info->vlan &&
312 (ring->vlan_tag_strip ==
313 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
314 vlan_gro_receive(ring->napi_p, ring->vlgrp,
315 ext_info->vlan, skb);
317 napi_gro_receive(ring->napi_p, skb);
319 vxge_debug_entryexit(VXGE_TRACE,
320 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
323 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
324 struct vxge_rx_priv *rx_priv)
326 pci_dma_sync_single_for_device(ring->pdev,
327 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
329 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
330 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
333 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
334 void *post_dtr, struct __vxge_hw_ring *ringh)
336 int dtr_count = *dtr_cnt;
337 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
339 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
340 *first_dtr = post_dtr;
342 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
344 *dtr_cnt = dtr_count;
350 * If the interrupt is because of a received frame or if the receive ring
351 * contains fresh as yet un-processed frames, this function is called.
353 static enum vxge_hw_status
354 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
355 u8 t_code, void *userdata)
357 struct vxge_ring *ring = (struct vxge_ring *)userdata;
358 struct net_device *dev = ring->ndev;
359 unsigned int dma_sizes;
360 void *first_dtr = NULL;
366 struct vxge_rx_priv *rx_priv;
367 struct vxge_hw_ring_rxd_info ext_info;
368 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
369 ring->ndev->name, __func__, __LINE__);
372 prefetch((char *)dtr + L1_CACHE_BYTES);
373 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
375 data_size = rx_priv->data_size;
376 data_dma = rx_priv->data_dma;
377 prefetch(rx_priv->skb_data);
379 vxge_debug_rx(VXGE_TRACE,
380 "%s: %s:%d skb = 0x%p",
381 ring->ndev->name, __func__, __LINE__, skb);
383 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
384 pkt_length = dma_sizes;
386 pkt_length -= ETH_FCS_LEN;
388 vxge_debug_rx(VXGE_TRACE,
389 "%s: %s:%d Packet Length = %d",
390 ring->ndev->name, __func__, __LINE__, pkt_length);
392 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
394 /* check skb validity */
397 prefetch((char *)skb + L1_CACHE_BYTES);
398 if (unlikely(t_code)) {
399 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
402 ring->stats.rx_errors++;
403 vxge_debug_rx(VXGE_TRACE,
404 "%s: %s :%d Rx T_code is %d",
405 ring->ndev->name, __func__,
408 /* If the t_code is not supported and if the
409 * t_code is other than 0x5 (unparseable packet
410 * such as unknown UPV6 header), Drop it !!!
412 vxge_re_pre_post(dtr, ring, rx_priv);
414 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
415 ring->stats.rx_dropped++;
420 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
421 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
422 if (!vxge_rx_map(dtr, ring)) {
423 skb_put(skb, pkt_length);
425 pci_unmap_single(ring->pdev, data_dma,
426 data_size, PCI_DMA_FROMDEVICE);
428 vxge_hw_ring_rxd_pre_post(ringh, dtr);
429 vxge_post(&dtr_cnt, &first_dtr, dtr,
432 dev_kfree_skb(rx_priv->skb);
434 rx_priv->data_size = data_size;
435 vxge_re_pre_post(dtr, ring, rx_priv);
437 vxge_post(&dtr_cnt, &first_dtr, dtr,
439 ring->stats.rx_dropped++;
443 vxge_re_pre_post(dtr, ring, rx_priv);
445 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
446 ring->stats.rx_dropped++;
450 struct sk_buff *skb_up;
452 skb_up = netdev_alloc_skb(dev, pkt_length +
453 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
454 if (skb_up != NULL) {
456 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
458 pci_dma_sync_single_for_cpu(ring->pdev,
462 vxge_debug_mem(VXGE_TRACE,
463 "%s: %s:%d skb_up = %p",
464 ring->ndev->name, __func__,
466 memcpy(skb_up->data, skb->data, pkt_length);
468 vxge_re_pre_post(dtr, ring, rx_priv);
470 vxge_post(&dtr_cnt, &first_dtr, dtr,
472 /* will netif_rx small SKB instead */
474 skb_put(skb, pkt_length);
476 vxge_re_pre_post(dtr, ring, rx_priv);
478 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
479 vxge_debug_rx(VXGE_ERR,
480 "%s: vxge_rx_1b_compl: out of "
481 "memory", dev->name);
482 ring->stats.skb_alloc_fail++;
487 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
488 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
489 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
490 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
491 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
492 skb->ip_summed = CHECKSUM_UNNECESSARY;
494 skb_checksum_none_assert(skb);
498 struct skb_shared_hwtstamps *skb_hwts;
499 u32 ns = *(u32 *)(skb->head + pkt_length);
501 skb_hwts = skb_hwtstamps(skb);
502 skb_hwts->hwtstamp = ns_to_ktime(ns);
503 skb_hwts->syststamp.tv64 = 0;
506 /* rth_hash_type and rth_it_hit are non-zero regardless of
507 * whether rss is enabled. Only the rth_value is zero/non-zero
508 * if rss is disabled/enabled, so key off of that.
510 if (ext_info.rth_value)
511 skb->rxhash = ext_info.rth_value;
513 vxge_rx_complete(ring, skb, ext_info.vlan,
514 pkt_length, &ext_info);
517 ring->pkts_processed++;
521 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
522 &t_code) == VXGE_HW_OK);
525 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
527 vxge_debug_entryexit(VXGE_TRACE,
536 * If an interrupt was raised to indicate DMA complete of the Tx packet,
537 * this function is called. It identifies the last TxD whose buffer was
538 * freed and frees all skbs whose data have already DMA'ed into the NICs
541 static enum vxge_hw_status
542 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
543 enum vxge_hw_fifo_tcode t_code, void *userdata,
544 struct sk_buff ***skb_ptr, int nr_skb, int *more)
546 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
547 struct sk_buff *skb, **done_skb = *skb_ptr;
550 vxge_debug_entryexit(VXGE_TRACE,
551 "%s:%d Entered....", __func__, __LINE__);
557 struct vxge_tx_priv *txd_priv =
558 vxge_hw_fifo_txdl_private_get(dtr);
561 frg_cnt = skb_shinfo(skb)->nr_frags;
562 frag = &skb_shinfo(skb)->frags[0];
564 vxge_debug_tx(VXGE_TRACE,
565 "%s: %s:%d fifo_hw = %p dtr = %p "
566 "tcode = 0x%x", fifo->ndev->name, __func__,
567 __LINE__, fifo_hw, dtr, t_code);
568 /* check skb validity */
570 vxge_debug_tx(VXGE_TRACE,
571 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
572 fifo->ndev->name, __func__, __LINE__,
573 skb, txd_priv, frg_cnt);
574 if (unlikely(t_code)) {
575 fifo->stats.tx_errors++;
576 vxge_debug_tx(VXGE_ERR,
577 "%s: tx: dtr %p completed due to "
578 "error t_code %01x", fifo->ndev->name,
580 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
583 /* for unfragmented skb */
584 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
585 skb_headlen(skb), PCI_DMA_TODEVICE);
587 for (j = 0; j < frg_cnt; j++) {
588 pci_unmap_page(fifo->pdev,
589 txd_priv->dma_buffers[i++],
590 frag->size, PCI_DMA_TODEVICE);
594 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
596 /* Updating the statistics block */
597 u64_stats_update_begin(&fifo->stats.syncp);
598 fifo->stats.tx_frms++;
599 fifo->stats.tx_bytes += skb->len;
600 u64_stats_update_end(&fifo->stats.syncp);
610 if (pkt_cnt > fifo->indicate_max_pkts)
613 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
614 &dtr, &t_code) == VXGE_HW_OK);
617 if (netif_tx_queue_stopped(fifo->txq))
618 netif_tx_wake_queue(fifo->txq);
620 vxge_debug_entryexit(VXGE_TRACE,
621 "%s: %s:%d Exiting...",
622 fifo->ndev->name, __func__, __LINE__);
626 /* select a vpath to transmit the packet */
627 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
629 u16 queue_len, counter = 0;
630 if (skb->protocol == htons(ETH_P_IP)) {
636 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
637 th = (struct tcphdr *)(((unsigned char *)ip) +
640 queue_len = vdev->no_of_vpath;
641 counter = (ntohs(th->source) +
643 vdev->vpath_selector[queue_len - 1];
644 if (counter >= queue_len)
645 counter = queue_len - 1;
651 static enum vxge_hw_status vxge_search_mac_addr_in_list(
652 struct vxge_vpath *vpath, u64 del_mac)
654 struct list_head *entry, *next;
655 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
656 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
662 static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
664 struct vxge_mac_addrs *new_mac_entry;
665 u8 *mac_address = NULL;
667 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
670 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
671 if (!new_mac_entry) {
672 vxge_debug_mem(VXGE_ERR,
673 "%s: memory allocation failed",
678 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
680 /* Copy the new mac address to the list */
681 mac_address = (u8 *)&new_mac_entry->macaddr;
682 memcpy(mac_address, mac->macaddr, ETH_ALEN);
684 new_mac_entry->state = mac->state;
685 vpath->mac_addr_cnt++;
687 /* Is this a multicast address */
688 if (0x01 & mac->macaddr[0])
689 vpath->mcast_addr_cnt++;
694 /* Add a mac address to DA table */
695 static enum vxge_hw_status
696 vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
698 enum vxge_hw_status status = VXGE_HW_OK;
699 struct vxge_vpath *vpath;
700 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
702 if (0x01 & mac->macaddr[0]) /* multicast address */
703 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
705 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
707 vpath = &vdev->vpaths[mac->vpath_no];
708 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
709 mac->macmask, duplicate_mode);
710 if (status != VXGE_HW_OK) {
711 vxge_debug_init(VXGE_ERR,
712 "DA config add entry failed for vpath:%d",
715 if (FALSE == vxge_mac_list_add(vpath, mac))
721 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
723 struct macInfo mac_info;
724 u8 *mac_address = NULL;
725 u64 mac_addr = 0, vpath_vector = 0;
727 enum vxge_hw_status status = VXGE_HW_OK;
728 struct vxge_vpath *vpath = NULL;
729 struct __vxge_hw_device *hldev;
731 hldev = pci_get_drvdata(vdev->pdev);
733 mac_address = (u8 *)&mac_addr;
734 memcpy(mac_address, mac_header, ETH_ALEN);
736 /* Is this mac address already in the list? */
737 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
738 vpath = &vdev->vpaths[vpath_idx];
739 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
743 memset(&mac_info, 0, sizeof(struct macInfo));
744 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
746 /* Any vpath has room to add mac address to its da table? */
747 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
748 vpath = &vdev->vpaths[vpath_idx];
749 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
750 /* Add this mac address to this vpath */
751 mac_info.vpath_no = vpath_idx;
752 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
753 status = vxge_add_mac_addr(vdev, &mac_info);
754 if (status != VXGE_HW_OK)
760 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
762 mac_info.vpath_no = vpath_idx;
763 /* Is the first vpath already selected as catch-basin ? */
764 vpath = &vdev->vpaths[vpath_idx];
765 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
766 /* Add this mac address to this vpath */
767 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
772 /* Select first vpath as catch-basin */
773 vpath_vector = vxge_mBIT(vpath->device_id);
774 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
775 vxge_hw_mgmt_reg_type_mrpcim,
778 struct vxge_hw_mrpcim_reg,
781 if (status != VXGE_HW_OK) {
782 vxge_debug_tx(VXGE_ERR,
783 "%s: Unable to set the vpath-%d in catch-basin mode",
784 VXGE_DRIVER_NAME, vpath->device_id);
788 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
796 * @skb : the socket buffer containing the Tx data.
797 * @dev : device pointer.
799 * This function is the Tx entry point of the driver. Neterion NIC supports
800 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
803 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
805 struct vxge_fifo *fifo = NULL;
808 struct vxgedev *vdev = NULL;
809 enum vxge_hw_status status;
810 int frg_cnt, first_frg_len;
812 int i = 0, j = 0, avail;
814 struct vxge_tx_priv *txdl_priv = NULL;
815 struct __vxge_hw_fifo *fifo_hw;
819 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
820 dev->name, __func__, __LINE__);
822 /* A buffer with no data will be dropped */
823 if (unlikely(skb->len <= 0)) {
824 vxge_debug_tx(VXGE_ERR,
825 "%s: Buffer has no data..", dev->name);
830 vdev = netdev_priv(dev);
832 if (unlikely(!is_vxge_card_up(vdev))) {
833 vxge_debug_tx(VXGE_ERR,
834 "%s: vdev not initialized", dev->name);
839 if (vdev->config.addr_learn_en) {
840 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
841 if (vpath_no == -EPERM) {
842 vxge_debug_tx(VXGE_ERR,
843 "%s: Failed to store the mac address",
850 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
851 vpath_no = skb_get_queue_mapping(skb);
852 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
853 vpath_no = vxge_get_vpath_no(vdev, skb);
855 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
857 if (vpath_no >= vdev->no_of_vpath)
860 fifo = &vdev->vpaths[vpath_no].fifo;
861 fifo_hw = fifo->handle;
863 if (netif_tx_queue_stopped(fifo->txq))
864 return NETDEV_TX_BUSY;
866 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
868 vxge_debug_tx(VXGE_ERR,
869 "%s: No free TXDs available", dev->name);
870 fifo->stats.txd_not_free++;
874 /* Last TXD? Stop tx queue to avoid dropping packets. TX
875 * completion will resume the queue.
878 netif_tx_stop_queue(fifo->txq);
880 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
881 if (unlikely(status != VXGE_HW_OK)) {
882 vxge_debug_tx(VXGE_ERR,
883 "%s: Out of descriptors .", dev->name);
884 fifo->stats.txd_out_of_desc++;
888 vxge_debug_tx(VXGE_TRACE,
889 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
890 dev->name, __func__, __LINE__,
891 fifo_hw, dtr, dtr_priv);
893 if (vlan_tx_tag_present(skb)) {
894 u16 vlan_tag = vlan_tx_tag_get(skb);
895 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
898 first_frg_len = skb_headlen(skb);
900 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
903 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
904 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
905 fifo->stats.pci_map_fail++;
909 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
910 txdl_priv->skb = skb;
911 txdl_priv->dma_buffers[j] = dma_pointer;
913 frg_cnt = skb_shinfo(skb)->nr_frags;
914 vxge_debug_tx(VXGE_TRACE,
915 "%s: %s:%d skb = %p txdl_priv = %p "
916 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
917 __func__, __LINE__, skb, txdl_priv,
918 frg_cnt, (unsigned long long)dma_pointer);
920 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
923 frag = &skb_shinfo(skb)->frags[0];
924 for (i = 0; i < frg_cnt; i++) {
925 /* ignore 0 length fragment */
929 dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
930 frag->page_offset, frag->size,
933 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
935 vxge_debug_tx(VXGE_TRACE,
936 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
937 dev->name, __func__, __LINE__, i,
938 (unsigned long long)dma_pointer);
940 txdl_priv->dma_buffers[j] = dma_pointer;
941 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
946 offload_type = vxge_offload_type(skb);
948 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
949 int mss = vxge_tcp_mss(skb);
951 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
952 dev->name, __func__, __LINE__, mss);
953 vxge_hw_fifo_txdl_mss_set(dtr, mss);
955 vxge_assert(skb->len <=
956 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
962 if (skb->ip_summed == CHECKSUM_PARTIAL)
963 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
964 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
965 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
966 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
968 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
970 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
971 dev->name, __func__, __LINE__);
975 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
978 frag = &skb_shinfo(skb)->frags[0];
980 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
981 skb_headlen(skb), PCI_DMA_TODEVICE);
984 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
985 frag->size, PCI_DMA_TODEVICE);
989 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
991 netif_tx_stop_queue(fifo->txq);
1000 * Function will be called by hw function to abort all outstanding receive
1004 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1006 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1007 struct vxge_rx_priv *rx_priv =
1008 vxge_hw_ring_rxd_private_get(dtrh);
1010 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1011 ring->ndev->name, __func__, __LINE__);
1012 if (state != VXGE_HW_RXD_STATE_POSTED)
1015 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1016 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1018 dev_kfree_skb(rx_priv->skb);
1019 rx_priv->skb_data = NULL;
1021 vxge_debug_entryexit(VXGE_TRACE,
1022 "%s: %s:%d Exiting...",
1023 ring->ndev->name, __func__, __LINE__);
1029 * Function will be called to abort all outstanding tx descriptors
1032 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1034 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1036 int i = 0, j, frg_cnt;
1037 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1038 struct sk_buff *skb = txd_priv->skb;
1040 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1042 if (state != VXGE_HW_TXDL_STATE_POSTED)
1045 /* check skb validity */
1047 frg_cnt = skb_shinfo(skb)->nr_frags;
1048 frag = &skb_shinfo(skb)->frags[0];
1050 /* for unfragmented skb */
1051 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1052 skb_headlen(skb), PCI_DMA_TODEVICE);
1054 for (j = 0; j < frg_cnt; j++) {
1055 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1056 frag->size, PCI_DMA_TODEVICE);
1062 vxge_debug_entryexit(VXGE_TRACE,
1063 "%s:%d Exiting...", __func__, __LINE__);
1066 static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1068 struct list_head *entry, *next;
1070 u8 *mac_address = (u8 *) (&del_mac);
1072 /* Copy the mac address to delete from the list */
1073 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1075 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1076 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1078 kfree((struct vxge_mac_addrs *)entry);
1079 vpath->mac_addr_cnt--;
1081 /* Is this a multicast address */
1082 if (0x01 & mac->macaddr[0])
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_hw_device *hldev;
1127 struct vxge_vpath *vpath;
1128 enum vxge_hw_status status = VXGE_HW_OK;
1129 struct macInfo mac_info;
1131 struct vxge_mac_addrs *mac_entry;
1132 struct list_head *list_head;
1133 struct list_head *entry, *next;
1134 u8 *mac_address = NULL;
1136 vxge_debug_entryexit(VXGE_TRACE,
1137 "%s:%d", __func__, __LINE__);
1139 vdev = netdev_priv(dev);
1140 hldev = (struct __vxge_hw_device *)vdev->devh;
1142 if (unlikely(!is_vxge_card_up(vdev)))
1145 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1146 for (i = 0; i < vdev->no_of_vpath; i++) {
1147 vpath = &vdev->vpaths[i];
1148 vxge_assert(vpath->is_open);
1149 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1150 if (status != VXGE_HW_OK)
1151 vxge_debug_init(VXGE_ERR, "failed to enable "
1152 "multicast, status %d", status);
1153 vdev->all_multi_flg = 1;
1155 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1156 for (i = 0; i < vdev->no_of_vpath; i++) {
1157 vpath = &vdev->vpaths[i];
1158 vxge_assert(vpath->is_open);
1159 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1160 if (status != VXGE_HW_OK)
1161 vxge_debug_init(VXGE_ERR, "failed to disable "
1162 "multicast, status %d", status);
1163 vdev->all_multi_flg = 0;
1168 if (!vdev->config.addr_learn_en) {
1169 for (i = 0; i < vdev->no_of_vpath; i++) {
1170 vpath = &vdev->vpaths[i];
1171 vxge_assert(vpath->is_open);
1173 if (dev->flags & IFF_PROMISC)
1174 status = vxge_hw_vpath_promisc_enable(
1177 status = vxge_hw_vpath_promisc_disable(
1179 if (status != VXGE_HW_OK)
1180 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1181 ", status %d", dev->flags&IFF_PROMISC ?
1182 "enable" : "disable", status);
1186 memset(&mac_info, 0, sizeof(struct macInfo));
1187 /* Update individual M_CAST address list */
1188 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
1189 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1190 list_head = &vdev->vpaths[0].mac_addr_list;
1191 if ((netdev_mc_count(dev) +
1192 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1193 vdev->vpaths[0].max_mac_addr_cnt)
1194 goto _set_all_mcast;
1196 /* Delete previous MC's */
1197 for (i = 0; i < mcast_cnt; i++) {
1198 list_for_each_safe(entry, next, list_head) {
1199 mac_entry = (struct vxge_mac_addrs *)entry;
1200 /* Copy the mac address to delete */
1201 mac_address = (u8 *)&mac_entry->macaddr;
1202 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1204 /* Is this a multicast address */
1205 if (0x01 & mac_info.macaddr[0]) {
1206 for (vpath_idx = 0; vpath_idx <
1209 mac_info.vpath_no = vpath_idx;
1210 status = vxge_del_mac_addr(
1219 netdev_for_each_mc_addr(ha, dev) {
1220 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
1221 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1223 mac_info.vpath_no = vpath_idx;
1224 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1225 status = vxge_add_mac_addr(vdev, &mac_info);
1226 if (status != VXGE_HW_OK) {
1227 vxge_debug_init(VXGE_ERR,
1228 "%s:%d Setting individual"
1229 "multicast address failed",
1230 __func__, __LINE__);
1231 goto _set_all_mcast;
1238 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1239 /* Delete previous MC's */
1240 for (i = 0; i < mcast_cnt; i++) {
1241 list_for_each_safe(entry, next, list_head) {
1242 mac_entry = (struct vxge_mac_addrs *)entry;
1243 /* Copy the mac address to delete */
1244 mac_address = (u8 *)&mac_entry->macaddr;
1245 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1247 /* Is this a multicast address */
1248 if (0x01 & mac_info.macaddr[0])
1252 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1254 mac_info.vpath_no = vpath_idx;
1255 status = vxge_del_mac_addr(vdev, &mac_info);
1259 /* Enable all multicast */
1260 for (i = 0; i < vdev->no_of_vpath; i++) {
1261 vpath = &vdev->vpaths[i];
1262 vxge_assert(vpath->is_open);
1264 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1265 if (status != VXGE_HW_OK) {
1266 vxge_debug_init(VXGE_ERR,
1267 "%s:%d Enabling all multicasts failed",
1268 __func__, __LINE__);
1270 vdev->all_multi_flg = 1;
1272 dev->flags |= IFF_ALLMULTI;
1275 vxge_debug_entryexit(VXGE_TRACE,
1276 "%s:%d Exiting...", __func__, __LINE__);
1281 * @dev: pointer to the device structure
1283 * Update entry "0" (default MAC addr)
1285 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1287 struct sockaddr *addr = p;
1288 struct vxgedev *vdev;
1289 struct __vxge_hw_device *hldev;
1290 enum vxge_hw_status status = VXGE_HW_OK;
1291 struct macInfo mac_info_new, mac_info_old;
1294 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1296 vdev = netdev_priv(dev);
1299 if (!is_valid_ether_addr(addr->sa_data))
1302 memset(&mac_info_new, 0, sizeof(struct macInfo));
1303 memset(&mac_info_old, 0, sizeof(struct macInfo));
1305 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1306 __func__, __LINE__);
1308 /* Get the old address */
1309 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1311 /* Copy the new address */
1312 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1314 /* First delete the old mac address from all the vpaths
1315 as we can't specify the index while adding new mac address */
1316 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1317 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1318 if (!vpath->is_open) {
1319 /* This can happen when this interface is added/removed
1320 to the bonding interface. Delete this station address
1321 from the linked list */
1322 vxge_mac_list_del(vpath, &mac_info_old);
1324 /* Add this new address to the linked list
1325 for later restoring */
1326 vxge_mac_list_add(vpath, &mac_info_new);
1330 /* Delete the station address */
1331 mac_info_old.vpath_no = vpath_idx;
1332 status = vxge_del_mac_addr(vdev, &mac_info_old);
1335 if (unlikely(!is_vxge_card_up(vdev))) {
1336 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1340 /* Set this mac address to all the vpaths */
1341 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1342 mac_info_new.vpath_no = vpath_idx;
1343 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1344 status = vxge_add_mac_addr(vdev, &mac_info_new);
1345 if (status != VXGE_HW_OK)
1349 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1355 * vxge_vpath_intr_enable
1356 * @vdev: pointer to vdev
1357 * @vp_id: vpath for which to enable the interrupts
1359 * Enables the interrupts for the vpath
1361 static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1363 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1365 int tim_msix_id[4] = {0, 1, 0, 0};
1366 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
1368 vxge_hw_vpath_intr_enable(vpath->handle);
1370 if (vdev->config.intr_type == INTA)
1371 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1373 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1376 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1377 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1378 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1380 /* enable the alarm vector */
1381 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1382 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1383 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1388 * vxge_vpath_intr_disable
1389 * @vdev: pointer to vdev
1390 * @vp_id: vpath for which to disable the interrupts
1392 * Disables the interrupts for the vpath
1394 static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1396 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1397 struct __vxge_hw_device *hldev;
1400 hldev = pci_get_drvdata(vdev->pdev);
1402 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1404 vxge_hw_vpath_intr_disable(vpath->handle);
1406 if (vdev->config.intr_type == INTA)
1407 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1409 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1410 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1411 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1413 /* disable the alarm vector */
1414 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1415 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
1416 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1420 /* list all mac addresses from DA table */
1421 static enum vxge_hw_status
1422 vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1424 enum vxge_hw_status status = VXGE_HW_OK;
1425 unsigned char macmask[ETH_ALEN];
1426 unsigned char macaddr[ETH_ALEN];
1428 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1430 if (status != VXGE_HW_OK) {
1431 vxge_debug_init(VXGE_ERR,
1432 "DA config list entry failed for vpath:%d",
1437 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1438 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1440 if (status != VXGE_HW_OK)
1447 /* Store all mac addresses from the list to the DA table */
1448 static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1450 enum vxge_hw_status status = VXGE_HW_OK;
1451 struct macInfo mac_info;
1452 u8 *mac_address = NULL;
1453 struct list_head *entry, *next;
1455 memset(&mac_info, 0, sizeof(struct macInfo));
1457 if (vpath->is_open) {
1458 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1461 ((struct vxge_mac_addrs *)entry)->macaddr;
1462 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1463 ((struct vxge_mac_addrs *)entry)->state =
1464 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1465 /* does this mac address already exist in da table? */
1466 status = vxge_search_mac_addr_in_da_table(vpath,
1468 if (status != VXGE_HW_OK) {
1469 /* Add this mac address to the DA table */
1470 status = vxge_hw_vpath_mac_addr_add(
1471 vpath->handle, mac_info.macaddr,
1473 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1474 if (status != VXGE_HW_OK) {
1475 vxge_debug_init(VXGE_ERR,
1476 "DA add entry failed for vpath:%d",
1478 ((struct vxge_mac_addrs *)entry)->state
1479 = VXGE_LL_MAC_ADDR_IN_LIST;
1488 /* Store all vlan ids from the list to the vid table */
1489 static enum vxge_hw_status
1490 vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1492 enum vxge_hw_status status = VXGE_HW_OK;
1493 struct vxgedev *vdev = vpath->vdev;
1496 if (vdev->vlgrp && vpath->is_open) {
1498 for (vid = 0; vid < VLAN_N_VID; vid++) {
1499 if (!vlan_group_get_device(vdev->vlgrp, vid))
1501 /* Add these vlan to the vid table */
1502 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1511 * @vdev: pointer to vdev
1512 * @vp_id: vpath to reset
1516 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1518 enum vxge_hw_status status = VXGE_HW_OK;
1519 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1522 /* check if device is down already */
1523 if (unlikely(!is_vxge_card_up(vdev)))
1526 /* is device reset already scheduled */
1527 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1530 if (vpath->handle) {
1531 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1532 if (is_vxge_card_up(vdev) &&
1533 vxge_hw_vpath_recover_from_reset(vpath->handle)
1535 vxge_debug_init(VXGE_ERR,
1536 "vxge_hw_vpath_recover_from_reset"
1537 "failed for vpath:%d", vp_id);
1541 vxge_debug_init(VXGE_ERR,
1542 "vxge_hw_vpath_reset failed for"
1547 return VXGE_HW_FAIL;
1549 vxge_restore_vpath_mac_addr(vpath);
1550 vxge_restore_vpath_vid_table(vpath);
1552 /* Enable all broadcast */
1553 vxge_hw_vpath_bcast_enable(vpath->handle);
1555 /* Enable all multicast */
1556 if (vdev->all_multi_flg) {
1557 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1558 if (status != VXGE_HW_OK)
1559 vxge_debug_init(VXGE_ERR,
1560 "%s:%d Enabling multicast failed",
1561 __func__, __LINE__);
1564 /* Enable the interrupts */
1565 vxge_vpath_intr_enable(vdev, vp_id);
1569 /* Enable the flow of traffic through the vpath */
1570 vxge_hw_vpath_enable(vpath->handle);
1573 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1574 vpath->ring.last_status = VXGE_HW_OK;
1576 /* Vpath reset done */
1577 clear_bit(vp_id, &vdev->vp_reset);
1579 /* Start the vpath queue */
1580 if (netif_tx_queue_stopped(vpath->fifo.txq))
1581 netif_tx_wake_queue(vpath->fifo.txq);
1587 static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1591 /* Enable CI for RTI */
1592 if (vdev->config.intr_type == MSI_X) {
1593 for (i = 0; i < vdev->no_of_vpath; i++) {
1594 struct __vxge_hw_ring *hw_ring;
1596 hw_ring = vdev->vpaths[i].ring.handle;
1597 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1601 /* Enable CI for TTI */
1602 for (i = 0; i < vdev->no_of_vpath; i++) {
1603 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1604 vxge_hw_vpath_tti_ci_set(hw_fifo);
1606 * For Inta (with or without napi), Set CI ON for only one
1607 * vpath. (Have only one free running timer).
1609 if ((vdev->config.intr_type == INTA) && (i == 0))
1616 static int do_vxge_reset(struct vxgedev *vdev, int event)
1618 enum vxge_hw_status status;
1619 int ret = 0, vp_id, i;
1621 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1623 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1624 /* check if device is down already */
1625 if (unlikely(!is_vxge_card_up(vdev)))
1628 /* is reset already scheduled */
1629 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1633 if (event == VXGE_LL_FULL_RESET) {
1634 netif_carrier_off(vdev->ndev);
1636 /* wait for all the vpath reset to complete */
1637 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1638 while (test_bit(vp_id, &vdev->vp_reset))
1642 netif_carrier_on(vdev->ndev);
1644 /* if execution mode is set to debug, don't reset the adapter */
1645 if (unlikely(vdev->exec_mode)) {
1646 vxge_debug_init(VXGE_ERR,
1647 "%s: execution mode is debug, returning..",
1649 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1650 netif_tx_stop_all_queues(vdev->ndev);
1655 if (event == VXGE_LL_FULL_RESET) {
1656 vxge_hw_device_wait_receive_idle(vdev->devh);
1657 vxge_hw_device_intr_disable(vdev->devh);
1659 switch (vdev->cric_err_event) {
1660 case VXGE_HW_EVENT_UNKNOWN:
1661 netif_tx_stop_all_queues(vdev->ndev);
1662 vxge_debug_init(VXGE_ERR,
1663 "fatal: %s: Disabling device due to"
1668 case VXGE_HW_EVENT_RESET_START:
1670 case VXGE_HW_EVENT_RESET_COMPLETE:
1671 case VXGE_HW_EVENT_LINK_DOWN:
1672 case VXGE_HW_EVENT_LINK_UP:
1673 case VXGE_HW_EVENT_ALARM_CLEARED:
1674 case VXGE_HW_EVENT_ECCERR:
1675 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1678 case VXGE_HW_EVENT_FIFO_ERR:
1679 case VXGE_HW_EVENT_VPATH_ERR:
1681 case VXGE_HW_EVENT_CRITICAL_ERR:
1682 netif_tx_stop_all_queues(vdev->ndev);
1683 vxge_debug_init(VXGE_ERR,
1684 "fatal: %s: Disabling device due to"
1687 /* SOP or device reset required */
1688 /* This event is not currently used */
1691 case VXGE_HW_EVENT_SERR:
1692 netif_tx_stop_all_queues(vdev->ndev);
1693 vxge_debug_init(VXGE_ERR,
1694 "fatal: %s: Disabling device due to"
1699 case VXGE_HW_EVENT_SRPCIM_SERR:
1700 case VXGE_HW_EVENT_MRPCIM_SERR:
1703 case VXGE_HW_EVENT_SLOT_FREEZE:
1704 netif_tx_stop_all_queues(vdev->ndev);
1705 vxge_debug_init(VXGE_ERR,
1706 "fatal: %s: Disabling device due to"
1717 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1718 netif_tx_stop_all_queues(vdev->ndev);
1720 if (event == VXGE_LL_FULL_RESET) {
1721 status = vxge_reset_all_vpaths(vdev);
1722 if (status != VXGE_HW_OK) {
1723 vxge_debug_init(VXGE_ERR,
1724 "fatal: %s: can not reset vpaths",
1731 if (event == VXGE_LL_COMPL_RESET) {
1732 for (i = 0; i < vdev->no_of_vpath; i++)
1733 if (vdev->vpaths[i].handle) {
1734 if (vxge_hw_vpath_recover_from_reset(
1735 vdev->vpaths[i].handle)
1737 vxge_debug_init(VXGE_ERR,
1738 "vxge_hw_vpath_recover_"
1739 "from_reset failed for vpath: "
1745 vxge_debug_init(VXGE_ERR,
1746 "vxge_hw_vpath_reset failed for "
1753 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1754 /* Reprogram the DA table with populated mac addresses */
1755 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1756 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1757 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1760 /* enable vpath interrupts */
1761 for (i = 0; i < vdev->no_of_vpath; i++)
1762 vxge_vpath_intr_enable(vdev, i);
1764 vxge_hw_device_intr_enable(vdev->devh);
1768 /* Indicate card up */
1769 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1771 /* Get the traffic to flow through the vpaths */
1772 for (i = 0; i < vdev->no_of_vpath; i++) {
1773 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1775 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1778 netif_tx_wake_all_queues(vdev->ndev);
1782 vxge_config_ci_for_tti_rti(vdev);
1785 vxge_debug_entryexit(VXGE_TRACE,
1786 "%s:%d Exiting...", __func__, __LINE__);
1788 /* Indicate reset done */
1789 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1790 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1796 * @vdev: pointer to ll device
1798 * driver may reset the chip on events of serr, eccerr, etc
1800 static void vxge_reset(struct work_struct *work)
1802 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1804 if (!netif_running(vdev->ndev))
1807 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1811 * vxge_poll - Receive handler when Receive Polling is used.
1812 * @dev: pointer to the device structure.
1813 * @budget: Number of packets budgeted to be processed in this iteration.
1815 * This function comes into picture only if Receive side is being handled
1816 * through polling (called NAPI in linux). It mostly does what the normal
1817 * Rx interrupt handler does in terms of descriptor and packet processing
1818 * but not in an interrupt context. Also it will process a specified number
1819 * of packets at most in one iteration. This value is passed down by the
1820 * kernel as the function argument 'budget'.
1822 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1824 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1826 int budget_org = budget;
1828 ring->budget = budget;
1829 ring->pkts_processed = 0;
1830 vxge_hw_vpath_poll_rx(ring->handle);
1831 pkts_processed = ring->pkts_processed;
1833 if (ring->pkts_processed < budget_org) {
1834 napi_complete(napi);
1836 /* Re enable the Rx interrupts for the vpath */
1837 vxge_hw_channel_msix_unmask(
1838 (struct __vxge_hw_channel *)ring->handle,
1839 ring->rx_vector_no);
1843 /* We are copying and returning the local variable, in case if after
1844 * clearing the msix interrupt above, if the interrupt fires right
1845 * away which can preempt this NAPI thread */
1846 return pkts_processed;
1849 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1851 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1852 int pkts_processed = 0;
1854 int budget_org = budget;
1855 struct vxge_ring *ring;
1857 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
1859 for (i = 0; i < vdev->no_of_vpath; i++) {
1860 ring = &vdev->vpaths[i].ring;
1861 ring->budget = budget;
1862 ring->pkts_processed = 0;
1863 vxge_hw_vpath_poll_rx(ring->handle);
1864 pkts_processed += ring->pkts_processed;
1865 budget -= ring->pkts_processed;
1870 VXGE_COMPLETE_ALL_TX(vdev);
1872 if (pkts_processed < budget_org) {
1873 napi_complete(napi);
1874 /* Re enable the Rx interrupts for the ring */
1875 vxge_hw_device_unmask_all(hldev);
1876 vxge_hw_device_flush_io(hldev);
1879 return pkts_processed;
1882 #ifdef CONFIG_NET_POLL_CONTROLLER
1884 * vxge_netpoll - netpoll event handler entry point
1885 * @dev : pointer to the device structure.
1887 * This function will be called by upper layer to check for events on the
1888 * interface in situations where interrupts are disabled. It is used for
1889 * specific in-kernel networking tasks, such as remote consoles and kernel
1890 * debugging over the network (example netdump in RedHat).
1892 static void vxge_netpoll(struct net_device *dev)
1894 struct __vxge_hw_device *hldev;
1895 struct vxgedev *vdev;
1897 vdev = netdev_priv(dev);
1898 hldev = pci_get_drvdata(vdev->pdev);
1900 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1902 if (pci_channel_offline(vdev->pdev))
1905 disable_irq(dev->irq);
1906 vxge_hw_device_clear_tx_rx(hldev);
1908 vxge_hw_device_clear_tx_rx(hldev);
1909 VXGE_COMPLETE_ALL_RX(vdev);
1910 VXGE_COMPLETE_ALL_TX(vdev);
1912 enable_irq(dev->irq);
1914 vxge_debug_entryexit(VXGE_TRACE,
1915 "%s:%d Exiting...", __func__, __LINE__);
1919 /* RTH configuration */
1920 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1922 enum vxge_hw_status status = VXGE_HW_OK;
1923 struct vxge_hw_rth_hash_types hash_types;
1924 u8 itable[256] = {0}; /* indirection table */
1925 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1930 * - itable with bucket numbers
1931 * - mtable with bucket-to-vpath mapping
1933 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1934 itable[index] = index;
1935 mtable[index] = index % vdev->no_of_vpath;
1938 /* set indirection table, bucket-to-vpath mapping */
1939 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1942 vdev->config.rth_bkt_sz);
1943 if (status != VXGE_HW_OK) {
1944 vxge_debug_init(VXGE_ERR,
1945 "RTH indirection table configuration failed "
1946 "for vpath:%d", vdev->vpaths[0].device_id);
1950 /* Fill RTH hash types */
1951 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1952 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1953 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1954 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1955 hash_types.hash_type_tcpipv6ex_en =
1956 vdev->config.rth_hash_type_tcpipv6ex;
1957 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1960 * Because the itable_set() method uses the active_table field
1961 * for the target virtual path the RTH config should be updated
1962 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1963 * when steering frames.
1965 for (index = 0; index < vdev->no_of_vpath; index++) {
1966 status = vxge_hw_vpath_rts_rth_set(
1967 vdev->vpaths[index].handle,
1968 vdev->config.rth_algorithm,
1970 vdev->config.rth_bkt_sz);
1971 if (status != VXGE_HW_OK) {
1972 vxge_debug_init(VXGE_ERR,
1973 "RTH configuration failed for vpath:%d",
1974 vdev->vpaths[index].device_id);
1983 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1985 enum vxge_hw_status status = VXGE_HW_OK;
1986 struct vxge_vpath *vpath;
1989 for (i = 0; i < vdev->no_of_vpath; i++) {
1990 vpath = &vdev->vpaths[i];
1991 if (vpath->handle) {
1992 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1993 if (is_vxge_card_up(vdev) &&
1994 vxge_hw_vpath_recover_from_reset(
1995 vpath->handle) != VXGE_HW_OK) {
1996 vxge_debug_init(VXGE_ERR,
1997 "vxge_hw_vpath_recover_"
1998 "from_reset failed for vpath: "
2003 vxge_debug_init(VXGE_ERR,
2004 "vxge_hw_vpath_reset failed for "
2015 static void vxge_close_vpaths(struct vxgedev *vdev, int index)
2017 struct vxge_vpath *vpath;
2020 for (i = index; i < vdev->no_of_vpath; i++) {
2021 vpath = &vdev->vpaths[i];
2023 if (vpath->handle && vpath->is_open) {
2024 vxge_hw_vpath_close(vpath->handle);
2025 vdev->stats.vpaths_open--;
2028 vpath->handle = NULL;
2033 static int vxge_open_vpaths(struct vxgedev *vdev)
2035 struct vxge_hw_vpath_attr attr;
2036 enum vxge_hw_status status;
2037 struct vxge_vpath *vpath;
2041 for (i = 0; i < vdev->no_of_vpath; i++) {
2042 vpath = &vdev->vpaths[i];
2043 vxge_assert(vpath->is_configured);
2045 if (!vdev->titan1) {
2046 struct vxge_hw_vp_config *vcfg;
2047 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2049 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2050 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2051 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2052 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2053 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2054 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2055 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2056 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2057 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2060 attr.vp_id = vpath->device_id;
2061 attr.fifo_attr.callback = vxge_xmit_compl;
2062 attr.fifo_attr.txdl_term = vxge_tx_term;
2063 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2064 attr.fifo_attr.userdata = &vpath->fifo;
2066 attr.ring_attr.callback = vxge_rx_1b_compl;
2067 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2068 attr.ring_attr.rxd_term = vxge_rx_term;
2069 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2070 attr.ring_attr.userdata = &vpath->ring;
2072 vpath->ring.ndev = vdev->ndev;
2073 vpath->ring.pdev = vdev->pdev;
2075 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
2076 if (status == VXGE_HW_OK) {
2077 vpath->fifo.handle =
2078 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2079 vpath->ring.handle =
2080 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2081 vpath->fifo.tx_steering_type =
2082 vdev->config.tx_steering_type;
2083 vpath->fifo.ndev = vdev->ndev;
2084 vpath->fifo.pdev = vdev->pdev;
2085 if (vdev->config.tx_steering_type)
2087 netdev_get_tx_queue(vdev->ndev, i);
2090 netdev_get_tx_queue(vdev->ndev, 0);
2091 vpath->fifo.indicate_max_pkts =
2092 vdev->config.fifo_indicate_max_pkts;
2093 vpath->fifo.tx_vector_no = 0;
2094 vpath->ring.rx_vector_no = 0;
2095 vpath->ring.rx_hwts = vdev->rx_hwts;
2097 vdev->vp_handles[i] = vpath->handle;
2098 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
2099 vdev->stats.vpaths_open++;
2101 vdev->stats.vpath_open_fail++;
2102 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2103 "open with status: %d",
2104 vdev->ndev->name, vpath->device_id,
2106 vxge_close_vpaths(vdev, 0);
2110 vp_id = vpath->handle->vpath->vp_id;
2111 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2118 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2119 * if the interrupts are not within a range
2120 * @fifo: pointer to transmit fifo structure
2121 * Description: The function changes boundary timer and restriction timer
2122 * value depends on the traffic
2123 * Return Value: None
2125 static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2127 fifo->interrupt_count++;
2128 if (jiffies > fifo->jiffies + HZ / 100) {
2129 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2131 fifo->jiffies = jiffies;
2132 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2133 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2134 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2135 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2136 } else if (hw_fifo->rtimer != 0) {
2137 hw_fifo->rtimer = 0;
2138 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2140 fifo->interrupt_count = 0;
2145 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2146 * if the interrupts are not within a range
2147 * @ring: pointer to receive ring structure
2148 * Description: The function increases of decreases the packet counts within
2149 * the ranges of traffic utilization, if the interrupts due to this ring are
2150 * not within a fixed range.
2151 * Return Value: Nothing
2153 static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2155 ring->interrupt_count++;
2156 if (jiffies > ring->jiffies + HZ / 100) {
2157 struct __vxge_hw_ring *hw_ring = ring->handle;
2159 ring->jiffies = jiffies;
2160 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2161 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2162 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2163 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2164 } else if (hw_ring->rtimer != 0) {
2165 hw_ring->rtimer = 0;
2166 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2168 ring->interrupt_count = 0;
2174 * @irq: the irq of the device.
2175 * @dev_id: a void pointer to the hldev structure of the Titan device
2176 * @ptregs: pointer to the registers pushed on the stack.
2178 * This function is the ISR handler of the device when napi is enabled. It
2179 * identifies the reason for the interrupt and calls the relevant service
2182 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2184 struct net_device *dev;
2185 struct __vxge_hw_device *hldev;
2187 enum vxge_hw_status status;
2188 struct vxgedev *vdev = (struct vxgedev *)dev_id;
2190 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2193 hldev = pci_get_drvdata(vdev->pdev);
2195 if (pci_channel_offline(vdev->pdev))
2198 if (unlikely(!is_vxge_card_up(vdev)))
2201 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
2202 if (status == VXGE_HW_OK) {
2203 vxge_hw_device_mask_all(hldev);
2206 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2207 vdev->vpaths_deployed >>
2208 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2210 vxge_hw_device_clear_tx_rx(hldev);
2211 napi_schedule(&vdev->napi);
2212 vxge_debug_intr(VXGE_TRACE,
2213 "%s:%d Exiting...", __func__, __LINE__);
2216 vxge_hw_device_unmask_all(hldev);
2217 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2218 (status == VXGE_HW_ERR_CRITICAL) ||
2219 (status == VXGE_HW_ERR_FIFO))) {
2220 vxge_hw_device_mask_all(hldev);
2221 vxge_hw_device_flush_io(hldev);
2223 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2226 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2230 #ifdef CONFIG_PCI_MSI
2232 static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
2234 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2236 adaptive_coalesce_tx_interrupts(fifo);
2238 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2239 fifo->tx_vector_no);
2241 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2242 fifo->tx_vector_no);
2244 VXGE_COMPLETE_VPATH_TX(fifo);
2246 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2247 fifo->tx_vector_no);
2254 static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
2256 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2258 adaptive_coalesce_rx_interrupts(ring);
2260 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2261 ring->rx_vector_no);
2263 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2264 ring->rx_vector_no);
2266 napi_schedule(&ring->napi);
2271 vxge_alarm_msix_handle(int irq, void *dev_id)
2274 enum vxge_hw_status status;
2275 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2276 struct vxgedev *vdev = vpath->vdev;
2277 int msix_id = (vpath->handle->vpath->vp_id *
2278 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2280 for (i = 0; i < vdev->no_of_vpath; i++) {
2281 /* Reduce the chance of losing alarm interrupts by masking
2282 * the vector. A pending bit will be set if an alarm is
2283 * generated and on unmask the interrupt will be fired.
2285 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
2286 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2289 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2291 if (status == VXGE_HW_OK) {
2292 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2297 vxge_debug_intr(VXGE_ERR,
2298 "%s: vxge_hw_vpath_alarm_process failed %x ",
2299 VXGE_DRIVER_NAME, status);
2304 static int vxge_alloc_msix(struct vxgedev *vdev)
2307 int msix_intr_vect = 0, temp;
2311 /* Tx/Rx MSIX Vectors count */
2312 vdev->intr_cnt = vdev->no_of_vpath * 2;
2314 /* Alarm MSIX Vectors count */
2317 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2319 if (!vdev->entries) {
2320 vxge_debug_init(VXGE_ERR,
2321 "%s: memory allocation failed",
2324 goto alloc_entries_failed;
2327 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2328 sizeof(struct vxge_msix_entry),
2330 if (!vdev->vxge_entries) {
2331 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2334 goto alloc_vxge_entries_failed;
2337 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
2339 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2341 /* Initialize the fifo vector */
2342 vdev->entries[j].entry = msix_intr_vect;
2343 vdev->vxge_entries[j].entry = msix_intr_vect;
2344 vdev->vxge_entries[j].in_use = 0;
2347 /* Initialize the ring vector */
2348 vdev->entries[j].entry = msix_intr_vect + 1;
2349 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2350 vdev->vxge_entries[j].in_use = 0;
2354 /* Initialize the alarm vector */
2355 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2356 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
2357 vdev->vxge_entries[j].in_use = 0;
2359 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
2361 vxge_debug_init(VXGE_ERR,
2362 "%s: MSI-X enable failed for %d vectors, ret: %d",
2363 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
2364 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2366 goto enable_msix_failed;
2369 kfree(vdev->entries);
2370 kfree(vdev->vxge_entries);
2371 vdev->entries = NULL;
2372 vdev->vxge_entries = NULL;
2373 /* Try with less no of vector by reducing no of vpaths count */
2375 vxge_close_vpaths(vdev, temp);
2376 vdev->no_of_vpath = temp;
2378 } else if (ret < 0) {
2380 goto enable_msix_failed;
2385 kfree(vdev->vxge_entries);
2386 alloc_vxge_entries_failed:
2387 kfree(vdev->entries);
2388 alloc_entries_failed:
2392 static int vxge_enable_msix(struct vxgedev *vdev)
2396 /* 0 - Tx, 1 - Rx */
2397 int tim_msix_id[4] = {0, 1, 0, 0};
2401 /* allocate msix vectors */
2402 ret = vxge_alloc_msix(vdev);
2404 for (i = 0; i < vdev->no_of_vpath; i++) {
2405 struct vxge_vpath *vpath = &vdev->vpaths[i];
2407 /* If fifo or ring are not enabled, the MSIX vector for
2408 * it should be set to 0.
2410 vpath->ring.rx_vector_no = (vpath->device_id *
2411 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
2413 vpath->fifo.tx_vector_no = (vpath->device_id *
2414 VXGE_HW_VPATH_MSIX_ACTIVE);
2416 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2417 VXGE_ALARM_MSIX_ID);
2424 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2428 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
2430 if (vdev->vxge_entries[intr_cnt].in_use) {
2431 synchronize_irq(vdev->entries[intr_cnt].vector);
2432 free_irq(vdev->entries[intr_cnt].vector,
2433 vdev->vxge_entries[intr_cnt].arg);
2434 vdev->vxge_entries[intr_cnt].in_use = 0;
2438 kfree(vdev->entries);
2439 kfree(vdev->vxge_entries);
2440 vdev->entries = NULL;
2441 vdev->vxge_entries = NULL;
2443 if (vdev->config.intr_type == MSI_X)
2444 pci_disable_msix(vdev->pdev);
2448 static void vxge_rem_isr(struct vxgedev *vdev)
2450 struct __vxge_hw_device *hldev;
2451 hldev = pci_get_drvdata(vdev->pdev);
2453 #ifdef CONFIG_PCI_MSI
2454 if (vdev->config.intr_type == MSI_X) {
2455 vxge_rem_msix_isr(vdev);
2458 if (vdev->config.intr_type == INTA) {
2459 synchronize_irq(vdev->pdev->irq);
2460 free_irq(vdev->pdev->irq, vdev);
2464 static int vxge_add_isr(struct vxgedev *vdev)
2467 #ifdef CONFIG_PCI_MSI
2468 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2469 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2471 if (vdev->config.intr_type == MSI_X)
2472 ret = vxge_enable_msix(vdev);
2475 vxge_debug_init(VXGE_ERR,
2476 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2477 vxge_debug_init(VXGE_ERR,
2478 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2479 vdev->config.intr_type = INTA;
2482 if (vdev->config.intr_type == MSI_X) {
2484 intr_idx < (vdev->no_of_vpath *
2485 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2487 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2492 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2493 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2495 vdev->entries[intr_cnt].entry,
2498 vdev->entries[intr_cnt].vector,
2499 vxge_tx_msix_handle, 0,
2500 vdev->desc[intr_cnt],
2501 &vdev->vpaths[vp_idx].fifo);
2502 vdev->vxge_entries[intr_cnt].arg =
2503 &vdev->vpaths[vp_idx].fifo;
2507 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2508 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2510 vdev->entries[intr_cnt].entry,
2513 vdev->entries[intr_cnt].vector,
2514 vxge_rx_msix_napi_handle,
2516 vdev->desc[intr_cnt],
2517 &vdev->vpaths[vp_idx].ring);
2518 vdev->vxge_entries[intr_cnt].arg =
2519 &vdev->vpaths[vp_idx].ring;
2525 vxge_debug_init(VXGE_ERR,
2526 "%s: MSIX - %d Registration failed",
2527 vdev->ndev->name, intr_cnt);
2528 vxge_rem_msix_isr(vdev);
2529 vdev->config.intr_type = INTA;
2530 vxge_debug_init(VXGE_ERR,
2531 "%s: Defaulting to INTA"
2532 , vdev->ndev->name);
2537 /* We requested for this msix interrupt */
2538 vdev->vxge_entries[intr_cnt].in_use = 1;
2539 msix_idx += vdev->vpaths[vp_idx].device_id *
2540 VXGE_HW_VPATH_MSIX_ACTIVE;
2541 vxge_hw_vpath_msix_unmask(
2542 vdev->vpaths[vp_idx].handle,
2547 /* Point to next vpath handler */
2548 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2549 (vp_idx < (vdev->no_of_vpath - 1)))
2553 intr_cnt = vdev->no_of_vpath * 2;
2554 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2555 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2557 vdev->entries[intr_cnt].entry,
2559 /* For Alarm interrupts */
2560 ret = request_irq(vdev->entries[intr_cnt].vector,
2561 vxge_alarm_msix_handle, 0,
2562 vdev->desc[intr_cnt],
2565 vxge_debug_init(VXGE_ERR,
2566 "%s: MSIX - %d Registration failed",
2567 vdev->ndev->name, intr_cnt);
2568 vxge_rem_msix_isr(vdev);
2569 vdev->config.intr_type = INTA;
2570 vxge_debug_init(VXGE_ERR,
2571 "%s: Defaulting to INTA",
2576 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2577 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2578 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2580 vdev->vxge_entries[intr_cnt].in_use = 1;
2581 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
2586 if (vdev->config.intr_type == INTA) {
2587 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2588 "%s:vxge:INTA", vdev->ndev->name);
2589 vxge_hw_device_set_intr_type(vdev->devh,
2590 VXGE_HW_INTR_MODE_IRQLINE);
2592 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2594 ret = request_irq((int) vdev->pdev->irq,
2596 IRQF_SHARED, vdev->desc[0], vdev);
2598 vxge_debug_init(VXGE_ERR,
2599 "%s %s-%d: ISR registration failed",
2600 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2603 vxge_debug_init(VXGE_TRACE,
2604 "new %s-%d line allocated",
2605 "IRQ", vdev->pdev->irq);
2611 static void vxge_poll_vp_reset(unsigned long data)
2613 struct vxgedev *vdev = (struct vxgedev *)data;
2616 for (i = 0; i < vdev->no_of_vpath; i++) {
2617 if (test_bit(i, &vdev->vp_reset)) {
2618 vxge_reset_vpath(vdev, i);
2622 if (j && (vdev->config.intr_type != MSI_X)) {
2623 vxge_hw_device_unmask_all(vdev->devh);
2624 vxge_hw_device_flush_io(vdev->devh);
2627 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2630 static void vxge_poll_vp_lockup(unsigned long data)
2632 struct vxgedev *vdev = (struct vxgedev *)data;
2633 enum vxge_hw_status status = VXGE_HW_OK;
2634 struct vxge_vpath *vpath;
2635 struct vxge_ring *ring;
2637 unsigned long rx_frms;
2639 for (i = 0; i < vdev->no_of_vpath; i++) {
2640 ring = &vdev->vpaths[i].ring;
2642 /* Truncated to machine word size number of frames */
2643 rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
2645 /* Did this vpath received any packets */
2646 if (ring->stats.prev_rx_frms == rx_frms) {
2647 status = vxge_hw_vpath_check_leak(ring->handle);
2649 /* Did it received any packets last time */
2650 if ((VXGE_HW_FAIL == status) &&
2651 (VXGE_HW_FAIL == ring->last_status)) {
2653 /* schedule vpath reset */
2654 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2655 vpath = &vdev->vpaths[i];
2657 /* disable interrupts for this vpath */
2658 vxge_vpath_intr_disable(vdev, i);
2660 /* stop the queue for this vpath */
2661 netif_tx_stop_queue(vpath->fifo.txq);
2666 ring->stats.prev_rx_frms = rx_frms;
2667 ring->last_status = status;
2670 /* Check every 1 milli second */
2671 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2674 static u32 vxge_fix_features(struct net_device *dev, u32 features)
2676 u32 changed = dev->features ^ features;
2678 /* Enabling RTH requires some of the logic in vxge_device_register and a
2679 * vpath reset. Due to these restrictions, only allow modification
2680 * while the interface is down.
2682 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2683 features ^= NETIF_F_RXHASH;
2688 static int vxge_set_features(struct net_device *dev, u32 features)
2690 struct vxgedev *vdev = netdev_priv(dev);
2691 u32 changed = dev->features ^ features;
2693 if (!(changed & NETIF_F_RXHASH))
2696 /* !netif_running() ensured by vxge_fix_features() */
2698 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2699 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2700 dev->features = features ^ NETIF_F_RXHASH;
2701 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2710 * @dev: pointer to the device structure.
2712 * This function is the open entry point of the driver. It mainly calls a
2713 * function to allocate Rx buffers and inserts them into the buffer
2714 * descriptors and then enables the Rx part of the NIC.
2715 * Return value: '0' on success and an appropriate (-)ve integer as
2716 * defined in errno.h file on failure.
2718 static int vxge_open(struct net_device *dev)
2720 enum vxge_hw_status status;
2721 struct vxgedev *vdev;
2722 struct __vxge_hw_device *hldev;
2723 struct vxge_vpath *vpath;
2726 u64 val64, function_mode;
2728 vxge_debug_entryexit(VXGE_TRACE,
2729 "%s: %s:%d", dev->name, __func__, __LINE__);
2731 vdev = netdev_priv(dev);
2732 hldev = pci_get_drvdata(vdev->pdev);
2733 function_mode = vdev->config.device_hw_info.function_mode;
2735 /* make sure you have link off by default every time Nic is
2737 netif_carrier_off(dev);
2740 status = vxge_open_vpaths(vdev);
2741 if (status != VXGE_HW_OK) {
2742 vxge_debug_init(VXGE_ERR,
2743 "%s: fatal: Vpath open failed", vdev->ndev->name);
2748 vdev->mtu = dev->mtu;
2750 status = vxge_add_isr(vdev);
2751 if (status != VXGE_HW_OK) {
2752 vxge_debug_init(VXGE_ERR,
2753 "%s: fatal: ISR add failed", dev->name);
2758 if (vdev->config.intr_type != MSI_X) {
2759 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2760 vdev->config.napi_weight);
2761 napi_enable(&vdev->napi);
2762 for (i = 0; i < vdev->no_of_vpath; i++) {
2763 vpath = &vdev->vpaths[i];
2764 vpath->ring.napi_p = &vdev->napi;
2767 for (i = 0; i < vdev->no_of_vpath; i++) {
2768 vpath = &vdev->vpaths[i];
2769 netif_napi_add(dev, &vpath->ring.napi,
2770 vxge_poll_msix, vdev->config.napi_weight);
2771 napi_enable(&vpath->ring.napi);
2772 vpath->ring.napi_p = &vpath->ring.napi;
2777 if (vdev->config.rth_steering) {
2778 status = vxge_rth_configure(vdev);
2779 if (status != VXGE_HW_OK) {
2780 vxge_debug_init(VXGE_ERR,
2781 "%s: fatal: RTH configuration failed",
2787 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2788 hldev->config.rth_en ? "enabled" : "disabled");
2790 for (i = 0; i < vdev->no_of_vpath; i++) {
2791 vpath = &vdev->vpaths[i];
2793 /* set initial mtu before enabling the device */
2794 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
2795 if (status != VXGE_HW_OK) {
2796 vxge_debug_init(VXGE_ERR,
2797 "%s: fatal: can not set new MTU", dev->name);
2803 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2804 vxge_debug_init(vdev->level_trace,
2805 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2806 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2808 /* Restore the DA, VID table and also multicast and promiscuous mode
2811 if (vdev->all_multi_flg) {
2812 for (i = 0; i < vdev->no_of_vpath; i++) {
2813 vpath = &vdev->vpaths[i];
2814 vxge_restore_vpath_mac_addr(vpath);
2815 vxge_restore_vpath_vid_table(vpath);
2817 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2818 if (status != VXGE_HW_OK)
2819 vxge_debug_init(VXGE_ERR,
2820 "%s:%d Enabling multicast failed",
2821 __func__, __LINE__);
2825 /* Enable vpath to sniff all unicast/multicast traffic that not
2826 * addressed to them. We allow promiscuous mode for PF only
2830 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2831 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2833 vxge_hw_mgmt_reg_write(vdev->devh,
2834 vxge_hw_mgmt_reg_type_mrpcim,
2836 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2837 rxmac_authorize_all_addr),
2840 vxge_hw_mgmt_reg_write(vdev->devh,
2841 vxge_hw_mgmt_reg_type_mrpcim,
2843 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2844 rxmac_authorize_all_vid),
2847 vxge_set_multicast(dev);
2849 /* Enabling Bcast and mcast for all vpath */
2850 for (i = 0; i < vdev->no_of_vpath; i++) {
2851 vpath = &vdev->vpaths[i];
2852 status = vxge_hw_vpath_bcast_enable(vpath->handle);
2853 if (status != VXGE_HW_OK)
2854 vxge_debug_init(VXGE_ERR,
2855 "%s : Can not enable bcast for vpath "
2856 "id %d", dev->name, i);
2857 if (vdev->config.addr_learn_en) {
2858 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2859 if (status != VXGE_HW_OK)
2860 vxge_debug_init(VXGE_ERR,
2861 "%s : Can not enable mcast for vpath "
2862 "id %d", dev->name, i);
2866 vxge_hw_device_setpause_data(vdev->devh, 0,
2867 vdev->config.tx_pause_enable,
2868 vdev->config.rx_pause_enable);
2870 if (vdev->vp_reset_timer.function == NULL)
2871 vxge_os_timer(vdev->vp_reset_timer,
2872 vxge_poll_vp_reset, vdev, (HZ/2));
2874 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2875 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2876 vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
2879 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2883 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2884 netif_carrier_on(vdev->ndev);
2885 netdev_notice(vdev->ndev, "Link Up\n");
2886 vdev->stats.link_up++;
2889 vxge_hw_device_intr_enable(vdev->devh);
2893 for (i = 0; i < vdev->no_of_vpath; i++) {
2894 vpath = &vdev->vpaths[i];
2896 vxge_hw_vpath_enable(vpath->handle);
2898 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
2901 netif_tx_start_all_queues(vdev->ndev);
2904 vxge_config_ci_for_tti_rti(vdev);
2912 if (vdev->config.intr_type != MSI_X)
2913 napi_disable(&vdev->napi);
2915 for (i = 0; i < vdev->no_of_vpath; i++)
2916 napi_disable(&vdev->vpaths[i].ring.napi);
2920 vxge_close_vpaths(vdev, 0);
2922 vxge_debug_entryexit(VXGE_TRACE,
2923 "%s: %s:%d Exiting...",
2924 dev->name, __func__, __LINE__);
2928 /* Loop through the mac address list and delete all the entries */
2929 static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2932 struct list_head *entry, *next;
2933 if (list_empty(&vpath->mac_addr_list))
2936 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2938 kfree((struct vxge_mac_addrs *)entry);
2942 static void vxge_napi_del_all(struct vxgedev *vdev)
2945 if (vdev->config.intr_type != MSI_X)
2946 netif_napi_del(&vdev->napi);
2948 for (i = 0; i < vdev->no_of_vpath; i++)
2949 netif_napi_del(&vdev->vpaths[i].ring.napi);
2953 static int do_vxge_close(struct net_device *dev, int do_io)
2955 enum vxge_hw_status status;
2956 struct vxgedev *vdev;
2957 struct __vxge_hw_device *hldev;
2959 u64 val64, vpath_vector;
2960 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2961 dev->name, __func__, __LINE__);
2963 vdev = netdev_priv(dev);
2964 hldev = pci_get_drvdata(vdev->pdev);
2966 if (unlikely(!is_vxge_card_up(vdev)))
2969 /* If vxge_handle_crit_err task is executing,
2970 * wait till it completes. */
2971 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2975 /* Put the vpath back in normal mode */
2976 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2977 status = vxge_hw_mgmt_reg_read(vdev->devh,
2978 vxge_hw_mgmt_reg_type_mrpcim,
2981 struct vxge_hw_mrpcim_reg,
2982 rts_mgr_cbasin_cfg),
2984 if (status == VXGE_HW_OK) {
2985 val64 &= ~vpath_vector;
2986 status = vxge_hw_mgmt_reg_write(vdev->devh,
2987 vxge_hw_mgmt_reg_type_mrpcim,
2990 struct vxge_hw_mrpcim_reg,
2991 rts_mgr_cbasin_cfg),
2995 /* Remove the function 0 from promiscuous mode */
2996 vxge_hw_mgmt_reg_write(vdev->devh,
2997 vxge_hw_mgmt_reg_type_mrpcim,
2999 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
3000 rxmac_authorize_all_addr),
3003 vxge_hw_mgmt_reg_write(vdev->devh,
3004 vxge_hw_mgmt_reg_type_mrpcim,
3006 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
3007 rxmac_authorize_all_vid),
3014 del_timer_sync(&vdev->vp_lockup_timer);
3016 del_timer_sync(&vdev->vp_reset_timer);
3019 vxge_hw_device_wait_receive_idle(hldev);
3021 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3024 if (vdev->config.intr_type != MSI_X)
3025 napi_disable(&vdev->napi);
3027 for (i = 0; i < vdev->no_of_vpath; i++)
3028 napi_disable(&vdev->vpaths[i].ring.napi);
3031 netif_carrier_off(vdev->ndev);
3032 netdev_notice(vdev->ndev, "Link Down\n");
3033 netif_tx_stop_all_queues(vdev->ndev);
3035 /* Note that at this point xmit() is stopped by upper layer */
3037 vxge_hw_device_intr_disable(vdev->devh);
3041 vxge_napi_del_all(vdev);
3044 vxge_reset_all_vpaths(vdev);
3046 vxge_close_vpaths(vdev, 0);
3048 vxge_debug_entryexit(VXGE_TRACE,
3049 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3051 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3058 * @dev: device pointer.
3060 * This is the stop entry point of the driver. It needs to undo exactly
3061 * whatever was done by the open entry point, thus it's usually referred to
3062 * as the close function.Among other things this function mainly stops the
3063 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3064 * Return value: '0' on success and an appropriate (-)ve integer as
3065 * defined in errno.h file on failure.
3067 static int vxge_close(struct net_device *dev)
3069 do_vxge_close(dev, 1);
3075 * @dev: net device pointer.
3076 * @new_mtu :the new MTU size for the device.
3078 * A driver entry point to change MTU size for the device. Before changing
3079 * the MTU the device must be stopped.
3081 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3083 struct vxgedev *vdev = netdev_priv(dev);
3085 vxge_debug_entryexit(vdev->level_trace,
3086 "%s:%d", __func__, __LINE__);
3087 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3088 vxge_debug_init(vdev->level_err,
3089 "%s: mtu size is invalid", dev->name);
3093 /* check if device is down already */
3094 if (unlikely(!is_vxge_card_up(vdev))) {
3095 /* just store new value, will use later on open() */
3097 vxge_debug_init(vdev->level_err,
3098 "%s", "device is down on MTU change");
3102 vxge_debug_init(vdev->level_trace,
3103 "trying to apply new MTU %d", new_mtu);
3105 if (vxge_close(dev))
3109 vdev->mtu = new_mtu;
3114 vxge_debug_init(vdev->level_trace,
3115 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3117 vxge_debug_entryexit(vdev->level_trace,
3118 "%s:%d Exiting...", __func__, __LINE__);
3125 * @dev: pointer to the device structure
3126 * @stats: pointer to struct rtnl_link_stats64
3129 static struct rtnl_link_stats64 *
3130 vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
3132 struct vxgedev *vdev = netdev_priv(dev);
3135 /* net_stats already zeroed by caller */
3136 for (k = 0; k < vdev->no_of_vpath; k++) {
3137 struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
3138 struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
3140 u64 packets, bytes, multicast;
3143 start = u64_stats_fetch_begin(&rxstats->syncp);
3145 packets = rxstats->rx_frms;
3146 multicast = rxstats->rx_mcast;
3147 bytes = rxstats->rx_bytes;
3148 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
3150 net_stats->rx_packets += packets;
3151 net_stats->rx_bytes += bytes;
3152 net_stats->multicast += multicast;
3154 net_stats->rx_errors += rxstats->rx_errors;
3155 net_stats->rx_dropped += rxstats->rx_dropped;
3158 start = u64_stats_fetch_begin(&txstats->syncp);
3160 packets = txstats->tx_frms;
3161 bytes = txstats->tx_bytes;
3162 } while (u64_stats_fetch_retry(&txstats->syncp, start));
3164 net_stats->tx_packets += packets;
3165 net_stats->tx_bytes += bytes;
3166 net_stats->tx_errors += txstats->tx_errors;
3172 static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
3174 enum vxge_hw_status status;
3177 /* Timestamp is passed to the driver via the FCS, therefore we
3178 * must disable the FCS stripping by the adapter. Since this is
3179 * required for the driver to load (due to a hardware bug),
3180 * there is no need to do anything special here.
3182 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3183 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3184 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
3186 status = vxge_hw_mgmt_reg_write(devh,
3187 vxge_hw_mgmt_reg_type_mrpcim,
3189 offsetof(struct vxge_hw_mrpcim_reg,
3192 vxge_hw_device_flush_io(devh);
3193 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
3197 static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3199 struct hwtstamp_config config;
3202 if (copy_from_user(&config, data, sizeof(config)))
3205 /* reserved for future extensions */
3209 /* Transmit HW Timestamp not supported */
3210 switch (config.tx_type) {
3211 case HWTSTAMP_TX_OFF:
3213 case HWTSTAMP_TX_ON:
3218 switch (config.rx_filter) {
3219 case HWTSTAMP_FILTER_NONE:
3221 config.rx_filter = HWTSTAMP_FILTER_NONE;
3224 case HWTSTAMP_FILTER_ALL:
3225 case HWTSTAMP_FILTER_SOME:
3226 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3227 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3228 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3229 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3230 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3231 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3232 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3233 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3234 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3235 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3236 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3237 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3238 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
3242 config.rx_filter = HWTSTAMP_FILTER_ALL;
3249 for (i = 0; i < vdev->no_of_vpath; i++)
3250 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3252 if (copy_to_user(data, &config, sizeof(config)))
3260 * @dev: Device pointer.
3261 * @ifr: An IOCTL specific structure, that can contain a pointer to
3262 * a proprietary structure used to pass information to the driver.
3263 * @cmd: This is used to distinguish between the different commands that
3264 * can be passed to the IOCTL functions.
3266 * Entry point for the Ioctl.
3268 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3270 struct vxgedev *vdev = netdev_priv(dev);
3275 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3288 * @dev: pointer to net device structure
3290 * Watchdog for transmit side.
3291 * This function is triggered if the Tx Queue is stopped
3292 * for a pre-defined amount of time when the Interface is still up.
3294 static void vxge_tx_watchdog(struct net_device *dev)
3296 struct vxgedev *vdev;
3298 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3300 vdev = netdev_priv(dev);
3302 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3304 schedule_work(&vdev->reset_task);
3305 vxge_debug_entryexit(VXGE_TRACE,
3306 "%s:%d Exiting...", __func__, __LINE__);
3310 * vxge_vlan_rx_register
3311 * @dev: net device pointer.
3314 * Vlan group registration
3317 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3319 struct vxgedev *vdev;
3320 struct vxge_vpath *vpath;
3323 enum vxge_hw_status status;
3326 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3328 vdev = netdev_priv(dev);
3330 vpath = &vdev->vpaths[0];
3331 if ((NULL == grp) && (vpath->is_open)) {
3332 /* Get the first vlan */
3333 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3335 while (status == VXGE_HW_OK) {
3337 /* Delete this vlan from the vid table */
3338 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3339 vpath = &vdev->vpaths[vp];
3340 if (!vpath->is_open)
3343 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3346 /* Get the next vlan to be deleted */
3347 vpath = &vdev->vpaths[0];
3348 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3354 for (i = 0; i < vdev->no_of_vpath; i++) {
3355 if (vdev->vpaths[i].is_configured)
3356 vdev->vpaths[i].ring.vlgrp = grp;
3359 vxge_debug_entryexit(VXGE_TRACE,
3360 "%s:%d Exiting...", __func__, __LINE__);
3364 * vxge_vlan_rx_add_vid
3365 * @dev: net device pointer.
3368 * Add the vlan id to the devices vlan id table
3371 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3373 struct vxgedev *vdev;
3374 struct vxge_vpath *vpath;
3377 vdev = netdev_priv(dev);
3379 /* Add these vlan to the vid table */
3380 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3381 vpath = &vdev->vpaths[vp_id];
3382 if (!vpath->is_open)
3384 vxge_hw_vpath_vid_add(vpath->handle, vid);
3389 * vxge_vlan_rx_add_vid
3390 * @dev: net device pointer.
3393 * Remove the vlan id from the device's vlan id table
3396 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3398 struct vxgedev *vdev;
3399 struct vxge_vpath *vpath;
3402 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3404 vdev = netdev_priv(dev);
3406 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3408 /* Delete this vlan from the vid table */
3409 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3410 vpath = &vdev->vpaths[vp_id];
3411 if (!vpath->is_open)
3413 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3415 vxge_debug_entryexit(VXGE_TRACE,
3416 "%s:%d Exiting...", __func__, __LINE__);
3419 static const struct net_device_ops vxge_netdev_ops = {
3420 .ndo_open = vxge_open,
3421 .ndo_stop = vxge_close,
3422 .ndo_get_stats64 = vxge_get_stats64,
3423 .ndo_start_xmit = vxge_xmit,
3424 .ndo_validate_addr = eth_validate_addr,
3425 .ndo_set_multicast_list = vxge_set_multicast,
3426 .ndo_do_ioctl = vxge_ioctl,
3427 .ndo_set_mac_address = vxge_set_mac_addr,
3428 .ndo_change_mtu = vxge_change_mtu,
3429 .ndo_fix_features = vxge_fix_features,
3430 .ndo_set_features = vxge_set_features,
3431 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3432 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3433 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3434 .ndo_tx_timeout = vxge_tx_watchdog,
3435 #ifdef CONFIG_NET_POLL_CONTROLLER
3436 .ndo_poll_controller = vxge_netpoll,
3440 static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3441 struct vxge_config *config,
3442 int high_dma, int no_of_vpath,
3443 struct vxgedev **vdev_out)
3445 struct net_device *ndev;
3446 enum vxge_hw_status status = VXGE_HW_OK;
3447 struct vxgedev *vdev;
3448 int ret = 0, no_of_queue = 1;
3452 if (config->tx_steering_type)
3453 no_of_queue = no_of_vpath;
3455 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3459 vxge_hw_device_trace_level_get(hldev),
3460 "%s : device allocation failed", __func__);
3465 vxge_debug_entryexit(
3466 vxge_hw_device_trace_level_get(hldev),
3467 "%s: %s:%d Entering...",
3468 ndev->name, __func__, __LINE__);
3470 vdev = netdev_priv(ndev);
3471 memset(vdev, 0, sizeof(struct vxgedev));
3475 vdev->pdev = hldev->pdev;
3476 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3478 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
3480 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3482 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3483 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3484 NETIF_F_TSO | NETIF_F_TSO6 |
3486 if (vdev->config.rth_steering != NO_STEERING)
3487 ndev->hw_features |= NETIF_F_RXHASH;
3489 ndev->features |= ndev->hw_features |
3490 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
3492 /* Driver entry points */
3493 ndev->irq = vdev->pdev->irq;
3494 ndev->base_addr = (unsigned long) hldev->bar0;
3496 ndev->netdev_ops = &vxge_netdev_ops;
3498 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3499 INIT_WORK(&vdev->reset_task, vxge_reset);
3501 vxge_initialize_ethtool_ops(ndev);
3503 /* Allocate memory for vpath */
3504 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3505 no_of_vpath, GFP_KERNEL);
3506 if (!vdev->vpaths) {
3507 vxge_debug_init(VXGE_ERR,
3508 "%s: vpath memory allocation failed",
3514 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3515 "%s : checksuming enabled", __func__);
3518 ndev->features |= NETIF_F_HIGHDMA;
3519 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3520 "%s : using High DMA", __func__);
3523 ret = register_netdev(ndev);
3525 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3526 "%s: %s : device registration failed!",
3527 ndev->name, __func__);
3531 /* Set the factory defined MAC address initially */
3532 ndev->addr_len = ETH_ALEN;
3534 /* Make Link state as off at this point, when the Link change
3535 * interrupt comes the state will be automatically changed to
3538 netif_carrier_off(ndev);
3540 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3541 "%s: Ethernet device registered",
3547 /* Resetting the Device stats */
3548 status = vxge_hw_mrpcim_stats_access(
3550 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3555 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3557 vxge_hw_device_trace_level_get(hldev),
3558 "%s: device stats clear returns"
3559 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3561 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3562 "%s: %s:%d Exiting...",
3563 ndev->name, __func__, __LINE__);
3567 kfree(vdev->vpaths);
3575 * vxge_device_unregister
3577 * This function will unregister and free network device
3579 static void vxge_device_unregister(struct __vxge_hw_device *hldev)
3581 struct vxgedev *vdev;
3582 struct net_device *dev;
3586 vdev = netdev_priv(dev);
3588 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3589 __func__, __LINE__);
3591 strncpy(buf, dev->name, IFNAMSIZ);
3593 flush_work_sync(&vdev->reset_task);
3595 /* in 2.6 will call stop() if device is up */
3596 unregister_netdev(dev);
3598 kfree(vdev->vpaths);
3600 /* we are safe to free it now */
3603 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3605 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3606 __func__, __LINE__);
3610 * vxge_callback_crit_err
3612 * This function is called by the alarm handler in interrupt context.
3613 * Driver must analyze it based on the event type.
3616 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3617 enum vxge_hw_event type, u64 vp_id)
3619 struct net_device *dev = hldev->ndev;
3620 struct vxgedev *vdev = netdev_priv(dev);
3621 struct vxge_vpath *vpath = NULL;
3624 vxge_debug_entryexit(vdev->level_trace,
3625 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3627 /* Note: This event type should be used for device wide
3628 * indications only - Serious errors, Slot freeze and critical errors
3630 vdev->cric_err_event = type;
3632 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3633 vpath = &vdev->vpaths[vpath_idx];
3634 if (vpath->device_id == vp_id)
3638 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3639 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3640 vxge_debug_init(VXGE_ERR,
3641 "%s: Slot is frozen", vdev->ndev->name);
3642 } else if (type == VXGE_HW_EVENT_SERR) {
3643 vxge_debug_init(VXGE_ERR,
3644 "%s: Encountered Serious Error",
3646 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3647 vxge_debug_init(VXGE_ERR,
3648 "%s: Encountered Critical Error",
3652 if ((type == VXGE_HW_EVENT_SERR) ||
3653 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3654 if (unlikely(vdev->exec_mode))
3655 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3656 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3657 vxge_hw_device_mask_all(hldev);
3658 if (unlikely(vdev->exec_mode))
3659 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3660 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3661 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3663 if (unlikely(vdev->exec_mode))
3664 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3666 /* check if this vpath is already set for reset */
3667 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3669 /* disable interrupts for this vpath */
3670 vxge_vpath_intr_disable(vdev, vpath_idx);
3672 /* stop the queue for this vpath */
3673 netif_tx_stop_queue(vpath->fifo.txq);
3678 vxge_debug_entryexit(vdev->level_trace,
3679 "%s: %s:%d Exiting...",
3680 vdev->ndev->name, __func__, __LINE__);
3683 static void verify_bandwidth(void)
3685 int i, band_width, total = 0, equal_priority = 0;
3687 /* 1. If user enters 0 for some fifo, give equal priority to all */
3688 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3689 if (bw_percentage[i] == 0) {
3695 if (!equal_priority) {
3696 /* 2. If sum exceeds 100, give equal priority to all */
3697 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3698 if (bw_percentage[i] == 0xFF)
3701 total += bw_percentage[i];
3702 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3709 if (!equal_priority) {
3710 /* Is all the bandwidth consumed? */
3711 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3712 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3713 /* Split rest of bw equally among next VPs*/
3715 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3716 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3717 if (band_width < 2) /* min of 2% */
3720 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3726 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3730 if (equal_priority) {
3731 vxge_debug_init(VXGE_ERR,
3732 "%s: Assigning equal bandwidth to all the vpaths",
3734 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3735 VXGE_HW_MAX_VIRTUAL_PATHS;
3736 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3737 bw_percentage[i] = bw_percentage[0];
3742 * Vpath configuration
3744 static int __devinit vxge_config_vpaths(
3745 struct vxge_hw_device_config *device_config,
3746 u64 vpath_mask, struct vxge_config *config_param)
3748 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3749 u32 txdl_size, txdl_per_memblock;
3751 temp = driver_config->vpath_per_dev;
3752 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3753 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3754 /* No more CPU. Return vpath number as zero.*/
3755 if (driver_config->g_no_cpus == -1)
3758 if (!driver_config->g_no_cpus)
3759 driver_config->g_no_cpus = num_online_cpus();
3761 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3762 if (!driver_config->vpath_per_dev)
3763 driver_config->vpath_per_dev = 1;
3765 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3766 if (!vxge_bVALn(vpath_mask, i, 1))
3770 if (default_no_vpath < driver_config->vpath_per_dev)
3771 driver_config->vpath_per_dev = default_no_vpath;
3773 driver_config->g_no_cpus = driver_config->g_no_cpus -
3774 (driver_config->vpath_per_dev * 2);
3775 if (driver_config->g_no_cpus <= 0)
3776 driver_config->g_no_cpus = -1;
3779 if (driver_config->vpath_per_dev == 1) {
3780 vxge_debug_ll_config(VXGE_TRACE,
3781 "%s: Disable tx and rx steering, "
3782 "as single vpath is configured", VXGE_DRIVER_NAME);
3783 config_param->rth_steering = NO_STEERING;
3784 config_param->tx_steering_type = NO_STEERING;
3785 device_config->rth_en = 0;
3788 /* configure bandwidth */
3789 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3790 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3792 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3793 device_config->vp_config[i].vp_id = i;
3794 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3795 if (no_of_vpaths < driver_config->vpath_per_dev) {
3796 if (!vxge_bVALn(vpath_mask, i, 1)) {
3797 vxge_debug_ll_config(VXGE_TRACE,
3798 "%s: vpath: %d is not available",
3799 VXGE_DRIVER_NAME, i);
3802 vxge_debug_ll_config(VXGE_TRACE,
3803 "%s: vpath: %d available",
3804 VXGE_DRIVER_NAME, i);
3808 vxge_debug_ll_config(VXGE_TRACE,
3809 "%s: vpath: %d is not configured, "
3810 "max_config_vpath exceeded",
3811 VXGE_DRIVER_NAME, i);
3815 /* Configure Tx fifo's */
3816 device_config->vp_config[i].fifo.enable =
3817 VXGE_HW_FIFO_ENABLE;
3818 device_config->vp_config[i].fifo.max_frags =
3820 device_config->vp_config[i].fifo.memblock_size =
3821 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3823 txdl_size = device_config->vp_config[i].fifo.max_frags *
3824 sizeof(struct vxge_hw_fifo_txd);
3825 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3827 device_config->vp_config[i].fifo.fifo_blocks =
3828 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3830 device_config->vp_config[i].fifo.intr =
3831 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3833 /* Configure tti properties */
3834 device_config->vp_config[i].tti.intr_enable =
3835 VXGE_HW_TIM_INTR_ENABLE;
3837 device_config->vp_config[i].tti.btimer_val =
3838 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3840 device_config->vp_config[i].tti.timer_ac_en =
3841 VXGE_HW_TIM_TIMER_AC_ENABLE;
3843 /* For msi-x with napi (each vector has a handler of its own) -
3844 * Set CI to OFF for all vpaths
3846 device_config->vp_config[i].tti.timer_ci_en =
3847 VXGE_HW_TIM_TIMER_CI_DISABLE;
3849 device_config->vp_config[i].tti.timer_ri_en =
3850 VXGE_HW_TIM_TIMER_RI_DISABLE;
3852 device_config->vp_config[i].tti.util_sel =
3853 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3855 device_config->vp_config[i].tti.ltimer_val =
3856 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3858 device_config->vp_config[i].tti.rtimer_val =
3859 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3861 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3862 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3863 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3864 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3865 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3866 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3867 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3869 /* Configure Rx rings */
3870 device_config->vp_config[i].ring.enable =
3871 VXGE_HW_RING_ENABLE;
3873 device_config->vp_config[i].ring.ring_blocks =
3874 VXGE_HW_DEF_RING_BLOCKS;
3876 device_config->vp_config[i].ring.buffer_mode =
3877 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3879 device_config->vp_config[i].ring.rxds_limit =
3880 VXGE_HW_DEF_RING_RXDS_LIMIT;
3882 device_config->vp_config[i].ring.scatter_mode =
3883 VXGE_HW_RING_SCATTER_MODE_A;
3885 /* Configure rti properties */
3886 device_config->vp_config[i].rti.intr_enable =
3887 VXGE_HW_TIM_INTR_ENABLE;
3889 device_config->vp_config[i].rti.btimer_val =
3890 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3892 device_config->vp_config[i].rti.timer_ac_en =
3893 VXGE_HW_TIM_TIMER_AC_ENABLE;
3895 device_config->vp_config[i].rti.timer_ci_en =
3896 VXGE_HW_TIM_TIMER_CI_DISABLE;
3898 device_config->vp_config[i].rti.timer_ri_en =
3899 VXGE_HW_TIM_TIMER_RI_DISABLE;
3901 device_config->vp_config[i].rti.util_sel =
3902 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3904 device_config->vp_config[i].rti.urange_a =
3906 device_config->vp_config[i].rti.urange_b =
3908 device_config->vp_config[i].rti.urange_c =
3910 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3911 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3912 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3913 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3915 device_config->vp_config[i].rti.rtimer_val =
3916 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3918 device_config->vp_config[i].rti.ltimer_val =
3919 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3921 device_config->vp_config[i].rpa_strip_vlan_tag =
3925 driver_config->vpath_per_dev = temp;
3926 return no_of_vpaths;
3929 /* initialize device configuratrions */
3930 static void __devinit vxge_device_config_init(
3931 struct vxge_hw_device_config *device_config,
3934 /* Used for CQRQ/SRQ. */
3935 device_config->dma_blockpool_initial =
3936 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3938 device_config->dma_blockpool_max =
3939 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3941 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3942 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3944 #ifndef CONFIG_PCI_MSI
3945 vxge_debug_init(VXGE_ERR,
3946 "%s: This Kernel does not support "
3947 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3951 /* Configure whether MSI-X or IRQL. */
3952 switch (*intr_type) {
3954 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3958 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
3962 /* Timer period between device poll */
3963 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3965 /* Configure mac based steering. */
3966 device_config->rts_mac_en = addr_learn_en;
3968 /* Configure Vpaths */
3969 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3971 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3973 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3974 device_config->intr_mode);
3975 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3976 device_config->device_poll_millis);
3977 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3978 device_config->rth_en);
3979 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3980 device_config->rth_it_type);
3983 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3987 vxge_debug_init(VXGE_TRACE,
3988 "%s: %d Vpath(s) opened",
3989 vdev->ndev->name, vdev->no_of_vpath);
3991 switch (vdev->config.intr_type) {
3993 vxge_debug_init(VXGE_TRACE,
3994 "%s: Interrupt type INTA", vdev->ndev->name);
3998 vxge_debug_init(VXGE_TRACE,
3999 "%s: Interrupt type MSI-X", vdev->ndev->name);
4003 if (vdev->config.rth_steering) {
4004 vxge_debug_init(VXGE_TRACE,
4005 "%s: RTH steering enabled for TCP_IPV4",
4008 vxge_debug_init(VXGE_TRACE,
4009 "%s: RTH steering disabled", vdev->ndev->name);
4012 switch (vdev->config.tx_steering_type) {
4014 vxge_debug_init(VXGE_TRACE,
4015 "%s: Tx steering disabled", vdev->ndev->name);
4017 case TX_PRIORITY_STEERING:
4018 vxge_debug_init(VXGE_TRACE,
4019 "%s: Unsupported tx steering option",
4021 vxge_debug_init(VXGE_TRACE,
4022 "%s: Tx steering disabled", vdev->ndev->name);
4023 vdev->config.tx_steering_type = 0;
4025 case TX_VLAN_STEERING:
4026 vxge_debug_init(VXGE_TRACE,
4027 "%s: Unsupported tx steering option",
4029 vxge_debug_init(VXGE_TRACE,
4030 "%s: Tx steering disabled", vdev->ndev->name);
4031 vdev->config.tx_steering_type = 0;
4033 case TX_MULTIQ_STEERING:
4034 vxge_debug_init(VXGE_TRACE,
4035 "%s: Tx multiqueue steering enabled",
4038 case TX_PORT_STEERING:
4039 vxge_debug_init(VXGE_TRACE,
4040 "%s: Tx port steering enabled",
4044 vxge_debug_init(VXGE_ERR,
4045 "%s: Unsupported tx steering type",
4047 vxge_debug_init(VXGE_TRACE,
4048 "%s: Tx steering disabled", vdev->ndev->name);
4049 vdev->config.tx_steering_type = 0;
4052 if (vdev->config.addr_learn_en)
4053 vxge_debug_init(VXGE_TRACE,
4054 "%s: MAC Address learning enabled", vdev->ndev->name);
4056 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4057 if (!vxge_bVALn(vpath_mask, i, 1))
4059 vxge_debug_ll_config(VXGE_TRACE,
4060 "%s: MTU size - %d", vdev->ndev->name,
4061 ((struct __vxge_hw_device *)(vdev->devh))->
4062 config.vp_config[i].mtu);
4063 vxge_debug_init(VXGE_TRACE,
4064 "%s: VLAN tag stripping %s", vdev->ndev->name,
4065 ((struct __vxge_hw_device *)(vdev->devh))->
4066 config.vp_config[i].rpa_strip_vlan_tag
4067 ? "Enabled" : "Disabled");
4068 vxge_debug_ll_config(VXGE_TRACE,
4069 "%s: Max frags : %d", vdev->ndev->name,
4070 ((struct __vxge_hw_device *)(vdev->devh))->
4071 config.vp_config[i].fifo.max_frags);
4078 * vxge_pm_suspend - vxge power management suspend entry point
4081 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4086 * vxge_pm_resume - vxge power management resume entry point
4089 static int vxge_pm_resume(struct pci_dev *pdev)
4097 * vxge_io_error_detected - called when PCI error is detected
4098 * @pdev: Pointer to PCI device
4099 * @state: The current pci connection state
4101 * This function is called after a PCI bus error affecting
4102 * this device has been detected.
4104 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4105 pci_channel_state_t state)
4107 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4108 struct net_device *netdev = hldev->ndev;
4110 netif_device_detach(netdev);
4112 if (state == pci_channel_io_perm_failure)
4113 return PCI_ERS_RESULT_DISCONNECT;
4115 if (netif_running(netdev)) {
4116 /* Bring down the card, while avoiding PCI I/O */
4117 do_vxge_close(netdev, 0);
4120 pci_disable_device(pdev);
4122 return PCI_ERS_RESULT_NEED_RESET;
4126 * vxge_io_slot_reset - called after the pci bus has been reset.
4127 * @pdev: Pointer to PCI device
4129 * Restart the card from scratch, as if from a cold-boot.
4130 * At this point, the card has exprienced a hard reset,
4131 * followed by fixups by BIOS, and has its config space
4132 * set up identically to what it was at cold boot.
4134 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4136 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4137 struct net_device *netdev = hldev->ndev;
4139 struct vxgedev *vdev = netdev_priv(netdev);
4141 if (pci_enable_device(pdev)) {
4142 netdev_err(netdev, "Cannot re-enable device after reset\n");
4143 return PCI_ERS_RESULT_DISCONNECT;
4146 pci_set_master(pdev);
4147 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
4149 return PCI_ERS_RESULT_RECOVERED;
4153 * vxge_io_resume - called when traffic can start flowing again.
4154 * @pdev: Pointer to PCI device
4156 * This callback is called when the error recovery driver tells
4157 * us that its OK to resume normal operation.
4159 static void vxge_io_resume(struct pci_dev *pdev)
4161 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4162 struct net_device *netdev = hldev->ndev;
4164 if (netif_running(netdev)) {
4165 if (vxge_open(netdev)) {
4167 "Can't bring device back up after reset\n");
4172 netif_device_attach(netdev);
4175 static inline u32 vxge_get_num_vfs(u64 function_mode)
4177 u32 num_functions = 0;
4179 switch (function_mode) {
4180 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4181 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4184 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4187 case VXGE_HW_FUNCTION_MODE_SRIOV:
4188 case VXGE_HW_FUNCTION_MODE_MRIOV:
4189 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4192 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4195 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4198 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4199 num_functions = 8; /* TODO */
4202 return num_functions;
4205 int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4207 struct __vxge_hw_device *hldev = vdev->devh;
4208 u32 maj, min, bld, cmaj, cmin, cbld;
4209 enum vxge_hw_status status;
4210 const struct firmware *fw;
4213 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4215 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4216 VXGE_DRIVER_NAME, fw_name);
4220 /* Load the new firmware onto the adapter */
4221 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4222 if (status != VXGE_HW_OK) {
4223 vxge_debug_init(VXGE_ERR,
4224 "%s: FW image download to adapter failed '%s'.",
4225 VXGE_DRIVER_NAME, fw_name);
4230 /* Read the version of the new firmware */
4231 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4232 if (status != VXGE_HW_OK) {
4233 vxge_debug_init(VXGE_ERR,
4234 "%s: Upgrade read version failed '%s'.",
4235 VXGE_DRIVER_NAME, fw_name);
4240 cmaj = vdev->config.device_hw_info.fw_version.major;
4241 cmin = vdev->config.device_hw_info.fw_version.minor;
4242 cbld = vdev->config.device_hw_info.fw_version.build;
4243 /* It's possible the version in /lib/firmware is not the latest version.
4244 * If so, we could get into a loop of trying to upgrade to the latest
4245 * and flashing the older version.
4247 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4253 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4256 /* Flash the adapter with the new firmware */
4257 status = vxge_hw_flash_fw(hldev);
4258 if (status != VXGE_HW_OK) {
4259 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4260 VXGE_DRIVER_NAME, fw_name);
4265 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4266 "hard reset before using, thus requiring a system reboot or a "
4267 "hotplug event.\n");
4270 release_firmware(fw);
4274 static int vxge_probe_fw_update(struct vxgedev *vdev)
4280 maj = vdev->config.device_hw_info.fw_version.major;
4281 min = vdev->config.device_hw_info.fw_version.minor;
4282 bld = vdev->config.device_hw_info.fw_version.build;
4284 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4287 /* Ignore the build number when determining if the current firmware is
4288 * "too new" to load the driver
4290 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4291 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4292 "version, unable to load driver\n",
4297 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4298 * work with this driver.
4300 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4301 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4302 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4306 /* If file not specified, determine gPXE or not */
4307 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4309 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4310 if (vdev->devh->eprom_versions[i]) {
4316 fw_name = "vxge/X3fw-pxe.ncf";
4318 fw_name = "vxge/X3fw.ncf";
4320 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4321 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4322 * probe, so ignore them
4324 if (ret != -EINVAL && ret != -ENOENT)
4329 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4330 VXGE_FW_VER(maj, min, 0)) {
4331 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4332 " be used with this driver.\n"
4333 "Please get the latest version from "
4334 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4335 VXGE_DRIVER_NAME, maj, min, bld);
4342 static int __devinit is_sriov_initialized(struct pci_dev *pdev)
4347 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4349 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4350 if (ctrl & PCI_SRIOV_CTRL_VFE)
4358 * @pdev : structure containing the PCI related information of the device.
4359 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4361 * This function is called when a new PCI device gets detected and initializes
4364 * returns 0 on success and negative on failure.
4367 static int __devinit
4368 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4370 struct __vxge_hw_device *hldev;
4371 enum vxge_hw_status status;
4375 struct vxgedev *vdev;
4376 struct vxge_config *ll_config = NULL;
4377 struct vxge_hw_device_config *device_config = NULL;
4378 struct vxge_hw_device_attr attr;
4379 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4381 struct vxge_mac_addrs *entry;
4382 static int bus = -1, device = -1;
4385 enum vxge_hw_status is_privileged;
4389 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4392 /* In SRIOV-17 mode, functions of the same adapter
4393 * can be deployed on different buses
4395 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4399 bus = pdev->bus->number;
4400 device = PCI_SLOT(pdev->devfn);
4403 if (driver_config->config_dev_cnt &&
4404 (driver_config->config_dev_cnt !=
4405 driver_config->total_dev_cnt))
4406 vxge_debug_init(VXGE_ERR,
4407 "%s: Configured %d of %d devices",
4409 driver_config->config_dev_cnt,
4410 driver_config->total_dev_cnt);
4411 driver_config->config_dev_cnt = 0;
4412 driver_config->total_dev_cnt = 0;
4415 /* Now making the CPU based no of vpath calculation
4416 * applicable for individual functions as well.
4418 driver_config->g_no_cpus = 0;
4419 driver_config->vpath_per_dev = max_config_vpath;
4421 driver_config->total_dev_cnt++;
4422 if (++driver_config->config_dev_cnt > max_config_dev) {
4427 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4429 if (!device_config) {
4431 vxge_debug_init(VXGE_ERR,
4432 "device_config : malloc failed %s %d",
4433 __FILE__, __LINE__);
4437 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
4440 vxge_debug_init(VXGE_ERR,
4441 "device_config : malloc failed %s %d",
4442 __FILE__, __LINE__);
4445 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4446 ll_config->intr_type = MSI_X;
4447 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4448 ll_config->rth_steering = RTH_STEERING;
4450 /* get the default configuration parameters */
4451 vxge_hw_device_config_default_get(device_config);
4453 /* initialize configuration parameters */
4454 vxge_device_config_init(device_config, &ll_config->intr_type);
4456 ret = pci_enable_device(pdev);
4458 vxge_debug_init(VXGE_ERR,
4459 "%s : can not enable PCI device", __func__);
4463 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
4464 vxge_debug_ll_config(VXGE_TRACE,
4465 "%s : using 64bit DMA", __func__);
4469 if (pci_set_consistent_dma_mask(pdev,
4470 DMA_BIT_MASK(64))) {
4471 vxge_debug_init(VXGE_ERR,
4472 "%s : unable to obtain 64bit DMA for "
4473 "consistent allocations", __func__);
4477 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
4478 vxge_debug_ll_config(VXGE_TRACE,
4479 "%s : using 32bit DMA", __func__);
4485 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4487 vxge_debug_init(VXGE_ERR,
4488 "%s : request regions failed", __func__);
4492 pci_set_master(pdev);
4494 attr.bar0 = pci_ioremap_bar(pdev, 0);
4496 vxge_debug_init(VXGE_ERR,
4497 "%s : cannot remap io memory bar0", __func__);
4501 vxge_debug_ll_config(VXGE_TRACE,
4502 "pci ioremap bar0: %p:0x%llx",
4504 (unsigned long long)pci_resource_start(pdev, 0));
4506 status = vxge_hw_device_hw_info_get(attr.bar0,
4507 &ll_config->device_hw_info);
4508 if (status != VXGE_HW_OK) {
4509 vxge_debug_init(VXGE_ERR,
4510 "%s: Reading of hardware info failed."
4511 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4516 vpath_mask = ll_config->device_hw_info.vpath_mask;
4517 if (vpath_mask == 0) {
4518 vxge_debug_ll_config(VXGE_TRACE,
4519 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4524 vxge_debug_ll_config(VXGE_TRACE,
4525 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4526 (unsigned long long)vpath_mask);
4528 function_mode = ll_config->device_hw_info.function_mode;
4529 host_type = ll_config->device_hw_info.host_type;
4530 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4531 ll_config->device_hw_info.func_id);
4533 /* Check how many vpaths are available */
4534 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4535 if (!((vpath_mask) & vxge_mBIT(i)))
4537 max_vpath_supported++;
4541 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4543 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4544 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4545 (ll_config->intr_type != INTA)) {
4546 ret = pci_enable_sriov(pdev, num_vfs);
4548 vxge_debug_ll_config(VXGE_ERR,
4549 "Failed in enabling SRIOV mode: %d\n", ret);
4550 /* No need to fail out, as an error here is non-fatal */
4554 * Configure vpaths and get driver configured number of vpaths
4555 * which is less than or equal to the maximum vpaths per function.
4557 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
4559 vxge_debug_ll_config(VXGE_ERR,
4560 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4565 /* Setting driver callbacks */
4566 attr.uld_callbacks.link_up = vxge_callback_link_up;
4567 attr.uld_callbacks.link_down = vxge_callback_link_down;
4568 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4570 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4571 if (status != VXGE_HW_OK) {
4572 vxge_debug_init(VXGE_ERR,
4573 "Failed to initialize device (%d)", status);
4578 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4579 ll_config->device_hw_info.fw_version.minor,
4580 ll_config->device_hw_info.fw_version.build) >=
4581 VXGE_EPROM_FW_VER) {
4582 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4584 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4585 if (status != VXGE_HW_OK) {
4586 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4588 /* This is a non-fatal error, continue */
4591 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4592 hldev->eprom_versions[i] = img[i].version;
4593 if (!img[i].is_valid)
4595 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
4596 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
4597 VXGE_EPROM_IMG_MAJOR(img[i].version),
4598 VXGE_EPROM_IMG_MINOR(img[i].version),
4599 VXGE_EPROM_IMG_FIX(img[i].version),
4600 VXGE_EPROM_IMG_BUILD(img[i].version));
4604 /* if FCS stripping is not disabled in MAC fail driver load */
4605 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4606 if (status != VXGE_HW_OK) {
4607 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4608 " failing driver load", VXGE_DRIVER_NAME);
4613 /* Always enable HWTS. This will always cause the FCS to be invalid,
4614 * due to the fact that HWTS is using the FCS as the location of the
4615 * timestamp. The HW FCS checking will still correctly determine if
4616 * there is a valid checksum, and the FCS is being removed by the driver
4617 * anyway. So no fucntionality is being lost. Since it is always
4618 * enabled, we now simply use the ioctl call to set whether or not the
4619 * driver should be paying attention to the HWTS.
4621 if (is_privileged == VXGE_HW_OK) {
4622 status = vxge_timestamp_config(hldev);
4623 if (status != VXGE_HW_OK) {
4624 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4631 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4633 /* set private device info */
4634 pci_set_drvdata(pdev, hldev);
4636 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4637 ll_config->addr_learn_en = addr_learn_en;
4638 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4639 ll_config->rth_hash_type_tcpipv4 = 1;
4640 ll_config->rth_hash_type_ipv4 = 0;
4641 ll_config->rth_hash_type_tcpipv6 = 0;
4642 ll_config->rth_hash_type_ipv6 = 0;
4643 ll_config->rth_hash_type_tcpipv6ex = 0;
4644 ll_config->rth_hash_type_ipv6ex = 0;
4645 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4646 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4647 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4649 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4656 ret = vxge_probe_fw_update(vdev);
4660 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4661 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4662 vxge_hw_device_trace_level_get(hldev));
4664 /* set private HW device info */
4665 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4666 vdev->bar0 = attr.bar0;
4667 vdev->max_vpath_supported = max_vpath_supported;
4668 vdev->no_of_vpath = no_of_vpath;
4670 /* Virtual Path count */
4671 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4672 if (!vxge_bVALn(vpath_mask, i, 1))
4674 if (j >= vdev->no_of_vpath)
4677 vdev->vpaths[j].is_configured = 1;
4678 vdev->vpaths[j].device_id = i;
4679 vdev->vpaths[j].ring.driver_id = j;
4680 vdev->vpaths[j].vdev = vdev;
4681 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4682 memcpy((u8 *)vdev->vpaths[j].macaddr,
4683 ll_config->device_hw_info.mac_addrs[i],
4686 /* Initialize the mac address list header */
4687 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4689 vdev->vpaths[j].mac_addr_cnt = 0;
4690 vdev->vpaths[j].mcast_addr_cnt = 0;
4693 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4694 vdev->max_config_port = max_config_port;
4696 vdev->vlan_tag_strip = vlan_tag_strip;
4698 /* map the hashing selector table to the configured vpaths */
4699 for (i = 0; i < vdev->no_of_vpath; i++)
4700 vdev->vpath_selector[i] = vpath_selector[i];
4702 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4704 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4705 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4706 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4708 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4709 vdev->ndev->name, ll_config->device_hw_info.serial_number);
4711 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4712 vdev->ndev->name, ll_config->device_hw_info.part_number);
4714 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4715 vdev->ndev->name, ll_config->device_hw_info.product_desc);
4717 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4718 vdev->ndev->name, macaddr);
4720 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4721 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4723 vxge_debug_init(VXGE_TRACE,
4724 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4725 ll_config->device_hw_info.fw_version.version,
4726 ll_config->device_hw_info.fw_date.date);
4729 switch (ll_config->device_hw_info.function_mode) {
4730 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4731 vxge_debug_init(VXGE_TRACE,
4732 "%s: Single Function Mode Enabled", vdev->ndev->name);
4734 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4735 vxge_debug_init(VXGE_TRACE,
4736 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4738 case VXGE_HW_FUNCTION_MODE_SRIOV:
4739 vxge_debug_init(VXGE_TRACE,
4740 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4742 case VXGE_HW_FUNCTION_MODE_MRIOV:
4743 vxge_debug_init(VXGE_TRACE,
4744 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4749 vxge_print_parm(vdev, vpath_mask);
4751 /* Store the fw version for ethttool option */
4752 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
4753 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4754 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4756 /* Copy the station mac address to the list */
4757 for (i = 0; i < vdev->no_of_vpath; i++) {
4758 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
4759 if (NULL == entry) {
4760 vxge_debug_init(VXGE_ERR,
4761 "%s: mac_addr_list : memory allocation failed",
4766 macaddr = (u8 *)&entry->macaddr;
4767 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4768 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4769 vdev->vpaths[i].mac_addr_cnt = 1;
4772 kfree(device_config);
4775 * INTA is shared in multi-function mode. This is unlike the INTA
4776 * implementation in MR mode, where each VH has its own INTA message.
4777 * - INTA is masked (disabled) as long as at least one function sets
4778 * its TITAN_MASK_ALL_INT.ALARM bit.
4779 * - INTA is unmasked (enabled) when all enabled functions have cleared
4780 * their own TITAN_MASK_ALL_INT.ALARM bit.
4781 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4782 * Though this driver leaves the top level interrupts unmasked while
4783 * leaving the required module interrupt bits masked on exit, there
4784 * could be a rougue driver around that does not follow this procedure
4785 * resulting in a failure to generate interrupts. The following code is
4786 * present to prevent such a failure.
4789 if (ll_config->device_hw_info.function_mode ==
4790 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4791 if (vdev->config.intr_type == INTA)
4792 vxge_hw_device_unmask_all(hldev);
4794 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4795 vdev->ndev->name, __func__, __LINE__);
4797 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4798 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4799 vxge_hw_device_trace_level_get(hldev));
4805 for (i = 0; i < vdev->no_of_vpath; i++)
4806 vxge_free_mac_add_list(&vdev->vpaths[i]);
4808 vxge_device_unregister(hldev);
4810 pci_set_drvdata(pdev, NULL);
4811 vxge_hw_device_terminate(hldev);
4812 pci_disable_sriov(pdev);
4816 pci_release_region(pdev, 0);
4818 pci_disable_device(pdev);
4821 kfree(device_config);
4822 driver_config->config_dev_cnt--;
4823 driver_config->total_dev_cnt--;
4828 * vxge_rem_nic - Free the PCI device
4829 * @pdev: structure containing the PCI related information of the device.
4830 * Description: This function is called by the Pci subsystem to release a
4831 * PCI device and free up all resource held up by the device.
4833 static void __devexit vxge_remove(struct pci_dev *pdev)
4835 struct __vxge_hw_device *hldev;
4836 struct vxgedev *vdev;
4839 hldev = pci_get_drvdata(pdev);
4843 vdev = netdev_priv(hldev->ndev);
4845 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
4846 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4849 for (i = 0; i < vdev->no_of_vpath; i++)
4850 vxge_free_mac_add_list(&vdev->vpaths[i]);
4852 vxge_device_unregister(hldev);
4853 pci_set_drvdata(pdev, NULL);
4854 /* Do not call pci_disable_sriov here, as it will break child devices */
4855 vxge_hw_device_terminate(hldev);
4856 iounmap(vdev->bar0);
4857 pci_release_region(pdev, 0);
4858 pci_disable_device(pdev);
4859 driver_config->config_dev_cnt--;
4860 driver_config->total_dev_cnt--;
4862 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4863 __func__, __LINE__);
4864 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4868 static struct pci_error_handlers vxge_err_handler = {
4869 .error_detected = vxge_io_error_detected,
4870 .slot_reset = vxge_io_slot_reset,
4871 .resume = vxge_io_resume,
4874 static struct pci_driver vxge_driver = {
4875 .name = VXGE_DRIVER_NAME,
4876 .id_table = vxge_id_table,
4877 .probe = vxge_probe,
4878 .remove = __devexit_p(vxge_remove),
4880 .suspend = vxge_pm_suspend,
4881 .resume = vxge_pm_resume,
4883 .err_handler = &vxge_err_handler,
4891 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4892 pr_info("Driver version: %s\n", DRV_VERSION);
4896 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4900 ret = pci_register_driver(&vxge_driver);
4902 kfree(driver_config);
4906 if (driver_config->config_dev_cnt &&
4907 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4908 vxge_debug_init(VXGE_ERR,
4909 "%s: Configured %d of %d devices",
4910 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4911 driver_config->total_dev_cnt);
4919 pci_unregister_driver(&vxge_driver);
4920 kfree(driver_config);
4922 module_init(vxge_starter);
4923 module_exit(vxge_closer);