1 /******************************************************************************
2 * This software may be used and distributed according to the terms of
3 * the GNU General Public License (GPL), incorporated herein by reference.
4 * Drivers based on or derived from this code fall under the GPL and must
5 * retain the authorship, copyright and license notice. This file is not
6 * a complete program and may only be used when the entire operating
7 * system is licensed under the GPL.
8 * See the file COPYING in this distribution for more information.
10 * vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2010 Exar Corp.
14 * The module loadable parameters that are supported by the driver and a brief
15 * explanation of all the variables:
17 * Strip VLAN Tag enable/disable. Instructs the device to remove
18 * the VLAN tag from all received tagged frames that are not
19 * replicated at the internal L2 switch.
20 * 0 - Do not strip the VLAN tag.
21 * 1 - Strip the VLAN tag.
24 * Enable learning the mac address of the guest OS interface in
25 * a virtualization environment.
30 * Maximum number of port to be supported.
34 * This configures the maximum no of VPATH configures for each
36 * MIN - 1 and MAX - 17
39 * This configures maximum no of Device function to be enabled.
40 * MIN - 1 and MAX - 17
42 ******************************************************************************/
44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/if_vlan.h>
47 #include <linux/pci.h>
48 #include <linux/slab.h>
49 #include <linux/tcp.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/firmware.h>
54 #include <linux/net_tstamp.h>
55 #include "vxge-main.h"
58 MODULE_LICENSE("Dual BSD/GPL");
59 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
60 "Virtualized Server Adapter");
62 static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
63 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
65 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
70 MODULE_DEVICE_TABLE(pci, vxge_id_table);
72 VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
73 VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
74 VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
75 VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
76 VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
77 VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
79 static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
80 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
81 static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
82 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
83 module_param_array(bw_percentage, uint, NULL, 0);
85 static struct vxge_drv_config *driver_config;
87 static enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
89 static enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev,
91 static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac);
92 static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac);
93 static enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath);
94 static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath);
96 static inline int is_vxge_card_up(struct vxgedev *vdev)
98 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
101 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
103 struct sk_buff **skb_ptr = NULL;
104 struct sk_buff **temp;
105 #define NR_SKB_COMPLETED 128
106 struct sk_buff *completed[NR_SKB_COMPLETED];
113 if (__netif_tx_trylock(fifo->txq)) {
114 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
115 NR_SKB_COMPLETED, &more);
116 __netif_tx_unlock(fifo->txq);
120 for (temp = completed; temp != skb_ptr; temp++)
121 dev_kfree_skb_irq(*temp);
125 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
129 /* Complete all transmits */
130 for (i = 0; i < vdev->no_of_vpath; i++)
131 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
134 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
137 struct vxge_ring *ring;
139 /* Complete all receives*/
140 for (i = 0; i < vdev->no_of_vpath; i++) {
141 ring = &vdev->vpaths[i].ring;
142 vxge_hw_vpath_poll_rx(ring->handle);
147 * vxge_callback_link_up
149 * This function is called during interrupt context to notify link up state
153 vxge_callback_link_up(struct __vxge_hw_device *hldev)
155 struct net_device *dev = hldev->ndev;
156 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
158 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
159 vdev->ndev->name, __func__, __LINE__);
160 netdev_notice(vdev->ndev, "Link Up\n");
161 vdev->stats.link_up++;
163 netif_carrier_on(vdev->ndev);
164 netif_tx_wake_all_queues(vdev->ndev);
166 vxge_debug_entryexit(VXGE_TRACE,
167 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
171 * vxge_callback_link_down
173 * This function is called during interrupt context to notify link down state
177 vxge_callback_link_down(struct __vxge_hw_device *hldev)
179 struct net_device *dev = hldev->ndev;
180 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
182 vxge_debug_entryexit(VXGE_TRACE,
183 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
184 netdev_notice(vdev->ndev, "Link Down\n");
186 vdev->stats.link_down++;
187 netif_carrier_off(vdev->ndev);
188 netif_tx_stop_all_queues(vdev->ndev);
190 vxge_debug_entryexit(VXGE_TRACE,
191 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
199 static struct sk_buff*
200 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
202 struct net_device *dev;
204 struct vxge_rx_priv *rx_priv;
207 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
208 ring->ndev->name, __func__, __LINE__);
210 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
212 /* try to allocate skb first. this one may fail */
213 skb = netdev_alloc_skb(dev, skb_size +
214 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
216 vxge_debug_mem(VXGE_ERR,
217 "%s: out of memory to allocate SKB", dev->name);
218 ring->stats.skb_alloc_fail++;
222 vxge_debug_mem(VXGE_TRACE,
223 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
224 __func__, __LINE__, skb);
226 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
229 rx_priv->skb_data = NULL;
230 rx_priv->data_size = skb_size;
231 vxge_debug_entryexit(VXGE_TRACE,
232 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
240 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
242 struct vxge_rx_priv *rx_priv;
245 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
246 ring->ndev->name, __func__, __LINE__);
247 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
249 rx_priv->skb_data = rx_priv->skb->data;
250 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
251 rx_priv->data_size, PCI_DMA_FROMDEVICE);
253 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
254 ring->stats.pci_map_fail++;
257 vxge_debug_mem(VXGE_TRACE,
258 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
259 ring->ndev->name, __func__, __LINE__,
260 (unsigned long long)dma_addr);
261 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
263 rx_priv->data_dma = dma_addr;
264 vxge_debug_entryexit(VXGE_TRACE,
265 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
271 * vxge_rx_initial_replenish
272 * Allocation of RxD as an initial replenish procedure.
274 static enum vxge_hw_status
275 vxge_rx_initial_replenish(void *dtrh, void *userdata)
277 struct vxge_ring *ring = (struct vxge_ring *)userdata;
278 struct vxge_rx_priv *rx_priv;
280 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
281 ring->ndev->name, __func__, __LINE__);
282 if (vxge_rx_alloc(dtrh, ring,
283 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
286 if (vxge_rx_map(dtrh, ring)) {
287 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
288 dev_kfree_skb(rx_priv->skb);
292 vxge_debug_entryexit(VXGE_TRACE,
293 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
299 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
300 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
303 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
304 ring->ndev->name, __func__, __LINE__);
305 skb_record_rx_queue(skb, ring->driver_id);
306 skb->protocol = eth_type_trans(skb, ring->ndev);
308 ring->stats.rx_frms++;
309 ring->stats.rx_bytes += pkt_length;
311 if (skb->pkt_type == PACKET_MULTICAST)
312 ring->stats.rx_mcast++;
314 vxge_debug_rx(VXGE_TRACE,
315 "%s: %s:%d skb protocol = %d",
316 ring->ndev->name, __func__, __LINE__, skb->protocol);
318 if (ring->gro_enable) {
319 if (ring->vlgrp && ext_info->vlan &&
320 (ring->vlan_tag_strip ==
321 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
322 vlan_gro_receive(ring->napi_p, ring->vlgrp,
323 ext_info->vlan, skb);
325 napi_gro_receive(ring->napi_p, skb);
327 if (ring->vlgrp && vlan &&
328 (ring->vlan_tag_strip ==
329 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
330 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
332 netif_receive_skb(skb);
334 vxge_debug_entryexit(VXGE_TRACE,
335 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
338 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
339 struct vxge_rx_priv *rx_priv)
341 pci_dma_sync_single_for_device(ring->pdev,
342 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
344 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
345 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
348 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
349 void *post_dtr, struct __vxge_hw_ring *ringh)
351 int dtr_count = *dtr_cnt;
352 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
354 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
355 *first_dtr = post_dtr;
357 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
359 *dtr_cnt = dtr_count;
365 * If the interrupt is because of a received frame or if the receive ring
366 * contains fresh as yet un-processed frames, this function is called.
368 static enum vxge_hw_status
369 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
370 u8 t_code, void *userdata)
372 struct vxge_ring *ring = (struct vxge_ring *)userdata;
373 struct net_device *dev = ring->ndev;
374 unsigned int dma_sizes;
375 void *first_dtr = NULL;
381 struct vxge_rx_priv *rx_priv;
382 struct vxge_hw_ring_rxd_info ext_info;
383 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
384 ring->ndev->name, __func__, __LINE__);
385 ring->pkts_processed = 0;
387 vxge_hw_ring_replenish(ringh);
390 prefetch((char *)dtr + L1_CACHE_BYTES);
391 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
393 data_size = rx_priv->data_size;
394 data_dma = rx_priv->data_dma;
395 prefetch(rx_priv->skb_data);
397 vxge_debug_rx(VXGE_TRACE,
398 "%s: %s:%d skb = 0x%p",
399 ring->ndev->name, __func__, __LINE__, skb);
401 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
402 pkt_length = dma_sizes;
404 pkt_length -= ETH_FCS_LEN;
406 vxge_debug_rx(VXGE_TRACE,
407 "%s: %s:%d Packet Length = %d",
408 ring->ndev->name, __func__, __LINE__, pkt_length);
410 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
412 /* check skb validity */
415 prefetch((char *)skb + L1_CACHE_BYTES);
416 if (unlikely(t_code)) {
418 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
421 ring->stats.rx_errors++;
422 vxge_debug_rx(VXGE_TRACE,
423 "%s: %s :%d Rx T_code is %d",
424 ring->ndev->name, __func__,
427 /* If the t_code is not supported and if the
428 * t_code is other than 0x5 (unparseable packet
429 * such as unknown UPV6 header), Drop it !!!
431 vxge_re_pre_post(dtr, ring, rx_priv);
433 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
434 ring->stats.rx_dropped++;
439 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
441 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
443 if (!vxge_rx_map(dtr, ring)) {
444 skb_put(skb, pkt_length);
446 pci_unmap_single(ring->pdev, data_dma,
447 data_size, PCI_DMA_FROMDEVICE);
449 vxge_hw_ring_rxd_pre_post(ringh, dtr);
450 vxge_post(&dtr_cnt, &first_dtr, dtr,
453 dev_kfree_skb(rx_priv->skb);
455 rx_priv->data_size = data_size;
456 vxge_re_pre_post(dtr, ring, rx_priv);
458 vxge_post(&dtr_cnt, &first_dtr, dtr,
460 ring->stats.rx_dropped++;
464 vxge_re_pre_post(dtr, ring, rx_priv);
466 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
467 ring->stats.rx_dropped++;
471 struct sk_buff *skb_up;
473 skb_up = netdev_alloc_skb(dev, pkt_length +
474 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
475 if (skb_up != NULL) {
477 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
479 pci_dma_sync_single_for_cpu(ring->pdev,
483 vxge_debug_mem(VXGE_TRACE,
484 "%s: %s:%d skb_up = %p",
485 ring->ndev->name, __func__,
487 memcpy(skb_up->data, skb->data, pkt_length);
489 vxge_re_pre_post(dtr, ring, rx_priv);
491 vxge_post(&dtr_cnt, &first_dtr, dtr,
493 /* will netif_rx small SKB instead */
495 skb_put(skb, pkt_length);
497 vxge_re_pre_post(dtr, ring, rx_priv);
499 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
500 vxge_debug_rx(VXGE_ERR,
501 "%s: vxge_rx_1b_compl: out of "
502 "memory", dev->name);
503 ring->stats.skb_alloc_fail++;
508 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
509 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
510 ring->rx_csum && /* Offload Rx side CSUM */
511 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
512 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
513 skb->ip_summed = CHECKSUM_UNNECESSARY;
515 skb_checksum_none_assert(skb);
519 struct skb_shared_hwtstamps *skb_hwts;
520 u32 ns = *(u32 *)(skb->head + pkt_length);
522 skb_hwts = skb_hwtstamps(skb);
523 skb_hwts->hwtstamp = ns_to_ktime(ns);
524 skb_hwts->syststamp.tv64 = 0;
527 /* rth_hash_type and rth_it_hit are non-zero regardless of
528 * whether rss is enabled. Only the rth_value is zero/non-zero
529 * if rss is disabled/enabled, so key off of that.
531 if (ext_info.rth_value)
532 skb->rxhash = ext_info.rth_value;
534 vxge_rx_complete(ring, skb, ext_info.vlan,
535 pkt_length, &ext_info);
538 ring->pkts_processed++;
542 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
543 &t_code) == VXGE_HW_OK);
546 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
548 vxge_debug_entryexit(VXGE_TRACE,
557 * If an interrupt was raised to indicate DMA complete of the Tx packet,
558 * this function is called. It identifies the last TxD whose buffer was
559 * freed and frees all skbs whose data have already DMA'ed into the NICs
562 static enum vxge_hw_status
563 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
564 enum vxge_hw_fifo_tcode t_code, void *userdata,
565 struct sk_buff ***skb_ptr, int nr_skb, int *more)
567 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
568 struct sk_buff *skb, **done_skb = *skb_ptr;
571 vxge_debug_entryexit(VXGE_TRACE,
572 "%s:%d Entered....", __func__, __LINE__);
578 struct vxge_tx_priv *txd_priv =
579 vxge_hw_fifo_txdl_private_get(dtr);
582 frg_cnt = skb_shinfo(skb)->nr_frags;
583 frag = &skb_shinfo(skb)->frags[0];
585 vxge_debug_tx(VXGE_TRACE,
586 "%s: %s:%d fifo_hw = %p dtr = %p "
587 "tcode = 0x%x", fifo->ndev->name, __func__,
588 __LINE__, fifo_hw, dtr, t_code);
589 /* check skb validity */
591 vxge_debug_tx(VXGE_TRACE,
592 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
593 fifo->ndev->name, __func__, __LINE__,
594 skb, txd_priv, frg_cnt);
595 if (unlikely(t_code)) {
596 fifo->stats.tx_errors++;
597 vxge_debug_tx(VXGE_ERR,
598 "%s: tx: dtr %p completed due to "
599 "error t_code %01x", fifo->ndev->name,
601 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
604 /* for unfragmented skb */
605 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
606 skb_headlen(skb), PCI_DMA_TODEVICE);
608 for (j = 0; j < frg_cnt; j++) {
609 pci_unmap_page(fifo->pdev,
610 txd_priv->dma_buffers[i++],
611 frag->size, PCI_DMA_TODEVICE);
615 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
617 /* Updating the statistics block */
618 fifo->stats.tx_frms++;
619 fifo->stats.tx_bytes += skb->len;
629 if (pkt_cnt > fifo->indicate_max_pkts)
632 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
633 &dtr, &t_code) == VXGE_HW_OK);
636 if (netif_tx_queue_stopped(fifo->txq))
637 netif_tx_wake_queue(fifo->txq);
639 vxge_debug_entryexit(VXGE_TRACE,
640 "%s: %s:%d Exiting...",
641 fifo->ndev->name, __func__, __LINE__);
645 /* select a vpath to transmit the packet */
646 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
648 u16 queue_len, counter = 0;
649 if (skb->protocol == htons(ETH_P_IP)) {
655 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
656 th = (struct tcphdr *)(((unsigned char *)ip) +
659 queue_len = vdev->no_of_vpath;
660 counter = (ntohs(th->source) +
662 vdev->vpath_selector[queue_len - 1];
663 if (counter >= queue_len)
664 counter = queue_len - 1;
670 static enum vxge_hw_status vxge_search_mac_addr_in_list(
671 struct vxge_vpath *vpath, u64 del_mac)
673 struct list_head *entry, *next;
674 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
675 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
681 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
683 struct macInfo mac_info;
684 u8 *mac_address = NULL;
685 u64 mac_addr = 0, vpath_vector = 0;
687 enum vxge_hw_status status = VXGE_HW_OK;
688 struct vxge_vpath *vpath = NULL;
689 struct __vxge_hw_device *hldev;
691 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
693 mac_address = (u8 *)&mac_addr;
694 memcpy(mac_address, mac_header, ETH_ALEN);
696 /* Is this mac address already in the list? */
697 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
698 vpath = &vdev->vpaths[vpath_idx];
699 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
703 memset(&mac_info, 0, sizeof(struct macInfo));
704 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
706 /* Any vpath has room to add mac address to its da table? */
707 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
708 vpath = &vdev->vpaths[vpath_idx];
709 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
710 /* Add this mac address to this vpath */
711 mac_info.vpath_no = vpath_idx;
712 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
713 status = vxge_add_mac_addr(vdev, &mac_info);
714 if (status != VXGE_HW_OK)
720 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
722 mac_info.vpath_no = vpath_idx;
723 /* Is the first vpath already selected as catch-basin ? */
724 vpath = &vdev->vpaths[vpath_idx];
725 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
726 /* Add this mac address to this vpath */
727 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
732 /* Select first vpath as catch-basin */
733 vpath_vector = vxge_mBIT(vpath->device_id);
734 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
735 vxge_hw_mgmt_reg_type_mrpcim,
738 struct vxge_hw_mrpcim_reg,
741 if (status != VXGE_HW_OK) {
742 vxge_debug_tx(VXGE_ERR,
743 "%s: Unable to set the vpath-%d in catch-basin mode",
744 VXGE_DRIVER_NAME, vpath->device_id);
748 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
756 * @skb : the socket buffer containing the Tx data.
757 * @dev : device pointer.
759 * This function is the Tx entry point of the driver. Neterion NIC supports
760 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
763 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
765 struct vxge_fifo *fifo = NULL;
768 struct vxgedev *vdev = NULL;
769 enum vxge_hw_status status;
770 int frg_cnt, first_frg_len;
772 int i = 0, j = 0, avail;
774 struct vxge_tx_priv *txdl_priv = NULL;
775 struct __vxge_hw_fifo *fifo_hw;
779 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
780 dev->name, __func__, __LINE__);
782 /* A buffer with no data will be dropped */
783 if (unlikely(skb->len <= 0)) {
784 vxge_debug_tx(VXGE_ERR,
785 "%s: Buffer has no data..", dev->name);
790 vdev = (struct vxgedev *)netdev_priv(dev);
792 if (unlikely(!is_vxge_card_up(vdev))) {
793 vxge_debug_tx(VXGE_ERR,
794 "%s: vdev not initialized", dev->name);
799 if (vdev->config.addr_learn_en) {
800 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
801 if (vpath_no == -EPERM) {
802 vxge_debug_tx(VXGE_ERR,
803 "%s: Failed to store the mac address",
810 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
811 vpath_no = skb_get_queue_mapping(skb);
812 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
813 vpath_no = vxge_get_vpath_no(vdev, skb);
815 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
817 if (vpath_no >= vdev->no_of_vpath)
820 fifo = &vdev->vpaths[vpath_no].fifo;
821 fifo_hw = fifo->handle;
823 if (netif_tx_queue_stopped(fifo->txq))
824 return NETDEV_TX_BUSY;
826 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
828 vxge_debug_tx(VXGE_ERR,
829 "%s: No free TXDs available", dev->name);
830 fifo->stats.txd_not_free++;
834 /* Last TXD? Stop tx queue to avoid dropping packets. TX
835 * completion will resume the queue.
838 netif_tx_stop_queue(fifo->txq);
840 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
841 if (unlikely(status != VXGE_HW_OK)) {
842 vxge_debug_tx(VXGE_ERR,
843 "%s: Out of descriptors .", dev->name);
844 fifo->stats.txd_out_of_desc++;
848 vxge_debug_tx(VXGE_TRACE,
849 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
850 dev->name, __func__, __LINE__,
851 fifo_hw, dtr, dtr_priv);
853 if (vlan_tx_tag_present(skb)) {
854 u16 vlan_tag = vlan_tx_tag_get(skb);
855 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
858 first_frg_len = skb_headlen(skb);
860 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
863 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
864 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
865 fifo->stats.pci_map_fail++;
869 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
870 txdl_priv->skb = skb;
871 txdl_priv->dma_buffers[j] = dma_pointer;
873 frg_cnt = skb_shinfo(skb)->nr_frags;
874 vxge_debug_tx(VXGE_TRACE,
875 "%s: %s:%d skb = %p txdl_priv = %p "
876 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
877 __func__, __LINE__, skb, txdl_priv,
878 frg_cnt, (unsigned long long)dma_pointer);
880 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
883 frag = &skb_shinfo(skb)->frags[0];
884 for (i = 0; i < frg_cnt; i++) {
885 /* ignore 0 length fragment */
889 dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
890 frag->page_offset, frag->size,
893 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
895 vxge_debug_tx(VXGE_TRACE,
896 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
897 dev->name, __func__, __LINE__, i,
898 (unsigned long long)dma_pointer);
900 txdl_priv->dma_buffers[j] = dma_pointer;
901 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
906 offload_type = vxge_offload_type(skb);
908 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
909 int mss = vxge_tcp_mss(skb);
911 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
912 dev->name, __func__, __LINE__, mss);
913 vxge_hw_fifo_txdl_mss_set(dtr, mss);
915 vxge_assert(skb->len <=
916 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
922 if (skb->ip_summed == CHECKSUM_PARTIAL)
923 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
924 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
925 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
926 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
928 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
930 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
931 dev->name, __func__, __LINE__);
935 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
938 frag = &skb_shinfo(skb)->frags[0];
940 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
941 skb_headlen(skb), PCI_DMA_TODEVICE);
944 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
945 frag->size, PCI_DMA_TODEVICE);
949 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
951 netif_tx_stop_queue(fifo->txq);
960 * Function will be called by hw function to abort all outstanding receive
964 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
966 struct vxge_ring *ring = (struct vxge_ring *)userdata;
967 struct vxge_rx_priv *rx_priv =
968 vxge_hw_ring_rxd_private_get(dtrh);
970 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
971 ring->ndev->name, __func__, __LINE__);
972 if (state != VXGE_HW_RXD_STATE_POSTED)
975 pci_unmap_single(ring->pdev, rx_priv->data_dma,
976 rx_priv->data_size, PCI_DMA_FROMDEVICE);
978 dev_kfree_skb(rx_priv->skb);
979 rx_priv->skb_data = NULL;
981 vxge_debug_entryexit(VXGE_TRACE,
982 "%s: %s:%d Exiting...",
983 ring->ndev->name, __func__, __LINE__);
989 * Function will be called to abort all outstanding tx descriptors
992 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
994 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
996 int i = 0, j, frg_cnt;
997 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
998 struct sk_buff *skb = txd_priv->skb;
1000 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1002 if (state != VXGE_HW_TXDL_STATE_POSTED)
1005 /* check skb validity */
1007 frg_cnt = skb_shinfo(skb)->nr_frags;
1008 frag = &skb_shinfo(skb)->frags[0];
1010 /* for unfragmented skb */
1011 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1012 skb_headlen(skb), PCI_DMA_TODEVICE);
1014 for (j = 0; j < frg_cnt; j++) {
1015 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1016 frag->size, PCI_DMA_TODEVICE);
1022 vxge_debug_entryexit(VXGE_TRACE,
1023 "%s:%d Exiting...", __func__, __LINE__);
1027 * vxge_set_multicast
1028 * @dev: pointer to the device structure
1030 * Entry point for multicast address enable/disable
1031 * This function is a driver entry point which gets called by the kernel
1032 * whenever multicast addresses must be enabled/disabled. This also gets
1033 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1034 * determine, if multicast address must be enabled or if promiscuous mode
1035 * is to be disabled etc.
1037 static void vxge_set_multicast(struct net_device *dev)
1039 struct netdev_hw_addr *ha;
1040 struct vxgedev *vdev;
1041 int i, mcast_cnt = 0;
1042 struct __vxge_hw_device *hldev;
1043 struct vxge_vpath *vpath;
1044 enum vxge_hw_status status = VXGE_HW_OK;
1045 struct macInfo mac_info;
1047 struct vxge_mac_addrs *mac_entry;
1048 struct list_head *list_head;
1049 struct list_head *entry, *next;
1050 u8 *mac_address = NULL;
1052 vxge_debug_entryexit(VXGE_TRACE,
1053 "%s:%d", __func__, __LINE__);
1055 vdev = (struct vxgedev *)netdev_priv(dev);
1056 hldev = (struct __vxge_hw_device *)vdev->devh;
1058 if (unlikely(!is_vxge_card_up(vdev)))
1061 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1062 for (i = 0; i < vdev->no_of_vpath; i++) {
1063 vpath = &vdev->vpaths[i];
1064 vxge_assert(vpath->is_open);
1065 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1066 if (status != VXGE_HW_OK)
1067 vxge_debug_init(VXGE_ERR, "failed to enable "
1068 "multicast, status %d", status);
1069 vdev->all_multi_flg = 1;
1071 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1072 for (i = 0; i < vdev->no_of_vpath; i++) {
1073 vpath = &vdev->vpaths[i];
1074 vxge_assert(vpath->is_open);
1075 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1076 if (status != VXGE_HW_OK)
1077 vxge_debug_init(VXGE_ERR, "failed to disable "
1078 "multicast, status %d", status);
1079 vdev->all_multi_flg = 0;
1084 if (!vdev->config.addr_learn_en) {
1085 for (i = 0; i < vdev->no_of_vpath; i++) {
1086 vpath = &vdev->vpaths[i];
1087 vxge_assert(vpath->is_open);
1089 if (dev->flags & IFF_PROMISC)
1090 status = vxge_hw_vpath_promisc_enable(
1093 status = vxge_hw_vpath_promisc_disable(
1095 if (status != VXGE_HW_OK)
1096 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1097 ", status %d", dev->flags&IFF_PROMISC ?
1098 "enable" : "disable", status);
1102 memset(&mac_info, 0, sizeof(struct macInfo));
1103 /* Update individual M_CAST address list */
1104 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
1105 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1106 list_head = &vdev->vpaths[0].mac_addr_list;
1107 if ((netdev_mc_count(dev) +
1108 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1109 vdev->vpaths[0].max_mac_addr_cnt)
1110 goto _set_all_mcast;
1112 /* Delete previous MC's */
1113 for (i = 0; i < mcast_cnt; i++) {
1114 list_for_each_safe(entry, next, list_head) {
1115 mac_entry = (struct vxge_mac_addrs *) entry;
1116 /* Copy the mac address to delete */
1117 mac_address = (u8 *)&mac_entry->macaddr;
1118 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1120 /* Is this a multicast address */
1121 if (0x01 & mac_info.macaddr[0]) {
1122 for (vpath_idx = 0; vpath_idx <
1125 mac_info.vpath_no = vpath_idx;
1126 status = vxge_del_mac_addr(
1135 netdev_for_each_mc_addr(ha, dev) {
1136 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
1137 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1139 mac_info.vpath_no = vpath_idx;
1140 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1141 status = vxge_add_mac_addr(vdev, &mac_info);
1142 if (status != VXGE_HW_OK) {
1143 vxge_debug_init(VXGE_ERR,
1144 "%s:%d Setting individual"
1145 "multicast address failed",
1146 __func__, __LINE__);
1147 goto _set_all_mcast;
1154 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1155 /* Delete previous MC's */
1156 for (i = 0; i < mcast_cnt; i++) {
1157 list_for_each_safe(entry, next, list_head) {
1158 mac_entry = (struct vxge_mac_addrs *) entry;
1159 /* Copy the mac address to delete */
1160 mac_address = (u8 *)&mac_entry->macaddr;
1161 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1163 /* Is this a multicast address */
1164 if (0x01 & mac_info.macaddr[0])
1168 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1170 mac_info.vpath_no = vpath_idx;
1171 status = vxge_del_mac_addr(vdev, &mac_info);
1175 /* Enable all multicast */
1176 for (i = 0; i < vdev->no_of_vpath; i++) {
1177 vpath = &vdev->vpaths[i];
1178 vxge_assert(vpath->is_open);
1180 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1181 if (status != VXGE_HW_OK) {
1182 vxge_debug_init(VXGE_ERR,
1183 "%s:%d Enabling all multicasts failed",
1184 __func__, __LINE__);
1186 vdev->all_multi_flg = 1;
1188 dev->flags |= IFF_ALLMULTI;
1191 vxge_debug_entryexit(VXGE_TRACE,
1192 "%s:%d Exiting...", __func__, __LINE__);
1197 * @dev: pointer to the device structure
1199 * Update entry "0" (default MAC addr)
1201 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1203 struct sockaddr *addr = p;
1204 struct vxgedev *vdev;
1205 struct __vxge_hw_device *hldev;
1206 enum vxge_hw_status status = VXGE_HW_OK;
1207 struct macInfo mac_info_new, mac_info_old;
1210 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1212 vdev = (struct vxgedev *)netdev_priv(dev);
1215 if (!is_valid_ether_addr(addr->sa_data))
1218 memset(&mac_info_new, 0, sizeof(struct macInfo));
1219 memset(&mac_info_old, 0, sizeof(struct macInfo));
1221 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1222 __func__, __LINE__);
1224 /* Get the old address */
1225 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1227 /* Copy the new address */
1228 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1230 /* First delete the old mac address from all the vpaths
1231 as we can't specify the index while adding new mac address */
1232 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1233 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1234 if (!vpath->is_open) {
1235 /* This can happen when this interface is added/removed
1236 to the bonding interface. Delete this station address
1237 from the linked list */
1238 vxge_mac_list_del(vpath, &mac_info_old);
1240 /* Add this new address to the linked list
1241 for later restoring */
1242 vxge_mac_list_add(vpath, &mac_info_new);
1246 /* Delete the station address */
1247 mac_info_old.vpath_no = vpath_idx;
1248 status = vxge_del_mac_addr(vdev, &mac_info_old);
1251 if (unlikely(!is_vxge_card_up(vdev))) {
1252 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1256 /* Set this mac address to all the vpaths */
1257 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1258 mac_info_new.vpath_no = vpath_idx;
1259 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1260 status = vxge_add_mac_addr(vdev, &mac_info_new);
1261 if (status != VXGE_HW_OK)
1265 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1271 * vxge_vpath_intr_enable
1272 * @vdev: pointer to vdev
1273 * @vp_id: vpath for which to enable the interrupts
1275 * Enables the interrupts for the vpath
1277 static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1279 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1281 int tim_msix_id[4] = {0, 1, 0, 0};
1282 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
1284 vxge_hw_vpath_intr_enable(vpath->handle);
1286 if (vdev->config.intr_type == INTA)
1287 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1289 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1292 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1293 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1294 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1296 /* enable the alarm vector */
1297 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1298 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1299 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1304 * vxge_vpath_intr_disable
1305 * @vdev: pointer to vdev
1306 * @vp_id: vpath for which to disable the interrupts
1308 * Disables the interrupts for the vpath
1310 static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1312 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1313 struct __vxge_hw_device *hldev;
1316 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1318 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1320 vxge_hw_vpath_intr_disable(vpath->handle);
1322 if (vdev->config.intr_type == INTA)
1323 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1325 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1326 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1327 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1329 /* disable the alarm vector */
1330 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1331 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
1332 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1338 * @vdev: pointer to vdev
1339 * @vp_id: vpath to reset
1343 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1345 enum vxge_hw_status status = VXGE_HW_OK;
1346 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1349 /* check if device is down already */
1350 if (unlikely(!is_vxge_card_up(vdev)))
1353 /* is device reset already scheduled */
1354 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1357 if (vpath->handle) {
1358 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1359 if (is_vxge_card_up(vdev) &&
1360 vxge_hw_vpath_recover_from_reset(vpath->handle)
1362 vxge_debug_init(VXGE_ERR,
1363 "vxge_hw_vpath_recover_from_reset"
1364 "failed for vpath:%d", vp_id);
1368 vxge_debug_init(VXGE_ERR,
1369 "vxge_hw_vpath_reset failed for"
1374 return VXGE_HW_FAIL;
1376 vxge_restore_vpath_mac_addr(vpath);
1377 vxge_restore_vpath_vid_table(vpath);
1379 /* Enable all broadcast */
1380 vxge_hw_vpath_bcast_enable(vpath->handle);
1382 /* Enable all multicast */
1383 if (vdev->all_multi_flg) {
1384 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1385 if (status != VXGE_HW_OK)
1386 vxge_debug_init(VXGE_ERR,
1387 "%s:%d Enabling multicast failed",
1388 __func__, __LINE__);
1391 /* Enable the interrupts */
1392 vxge_vpath_intr_enable(vdev, vp_id);
1396 /* Enable the flow of traffic through the vpath */
1397 vxge_hw_vpath_enable(vpath->handle);
1400 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1401 vpath->ring.last_status = VXGE_HW_OK;
1403 /* Vpath reset done */
1404 clear_bit(vp_id, &vdev->vp_reset);
1406 /* Start the vpath queue */
1407 if (netif_tx_queue_stopped(vpath->fifo.txq))
1408 netif_tx_wake_queue(vpath->fifo.txq);
1413 static int do_vxge_reset(struct vxgedev *vdev, int event)
1415 enum vxge_hw_status status;
1416 int ret = 0, vp_id, i;
1418 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1420 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1421 /* check if device is down already */
1422 if (unlikely(!is_vxge_card_up(vdev)))
1425 /* is reset already scheduled */
1426 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1430 if (event == VXGE_LL_FULL_RESET) {
1431 /* wait for all the vpath reset to complete */
1432 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1433 while (test_bit(vp_id, &vdev->vp_reset))
1437 /* if execution mode is set to debug, don't reset the adapter */
1438 if (unlikely(vdev->exec_mode)) {
1439 vxge_debug_init(VXGE_ERR,
1440 "%s: execution mode is debug, returning..",
1442 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1443 netif_tx_stop_all_queues(vdev->ndev);
1448 if (event == VXGE_LL_FULL_RESET) {
1449 vxge_hw_device_wait_receive_idle(vdev->devh);
1450 vxge_hw_device_intr_disable(vdev->devh);
1452 switch (vdev->cric_err_event) {
1453 case VXGE_HW_EVENT_UNKNOWN:
1454 netif_tx_stop_all_queues(vdev->ndev);
1455 vxge_debug_init(VXGE_ERR,
1456 "fatal: %s: Disabling device due to"
1461 case VXGE_HW_EVENT_RESET_START:
1463 case VXGE_HW_EVENT_RESET_COMPLETE:
1464 case VXGE_HW_EVENT_LINK_DOWN:
1465 case VXGE_HW_EVENT_LINK_UP:
1466 case VXGE_HW_EVENT_ALARM_CLEARED:
1467 case VXGE_HW_EVENT_ECCERR:
1468 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1471 case VXGE_HW_EVENT_FIFO_ERR:
1472 case VXGE_HW_EVENT_VPATH_ERR:
1474 case VXGE_HW_EVENT_CRITICAL_ERR:
1475 netif_tx_stop_all_queues(vdev->ndev);
1476 vxge_debug_init(VXGE_ERR,
1477 "fatal: %s: Disabling device due to"
1480 /* SOP or device reset required */
1481 /* This event is not currently used */
1484 case VXGE_HW_EVENT_SERR:
1485 netif_tx_stop_all_queues(vdev->ndev);
1486 vxge_debug_init(VXGE_ERR,
1487 "fatal: %s: Disabling device due to"
1492 case VXGE_HW_EVENT_SRPCIM_SERR:
1493 case VXGE_HW_EVENT_MRPCIM_SERR:
1496 case VXGE_HW_EVENT_SLOT_FREEZE:
1497 netif_tx_stop_all_queues(vdev->ndev);
1498 vxge_debug_init(VXGE_ERR,
1499 "fatal: %s: Disabling device due to"
1510 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1511 netif_tx_stop_all_queues(vdev->ndev);
1513 if (event == VXGE_LL_FULL_RESET) {
1514 status = vxge_reset_all_vpaths(vdev);
1515 if (status != VXGE_HW_OK) {
1516 vxge_debug_init(VXGE_ERR,
1517 "fatal: %s: can not reset vpaths",
1524 if (event == VXGE_LL_COMPL_RESET) {
1525 for (i = 0; i < vdev->no_of_vpath; i++)
1526 if (vdev->vpaths[i].handle) {
1527 if (vxge_hw_vpath_recover_from_reset(
1528 vdev->vpaths[i].handle)
1530 vxge_debug_init(VXGE_ERR,
1531 "vxge_hw_vpath_recover_"
1532 "from_reset failed for vpath: "
1538 vxge_debug_init(VXGE_ERR,
1539 "vxge_hw_vpath_reset failed for "
1546 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1547 /* Reprogram the DA table with populated mac addresses */
1548 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1549 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1550 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1553 /* enable vpath interrupts */
1554 for (i = 0; i < vdev->no_of_vpath; i++)
1555 vxge_vpath_intr_enable(vdev, i);
1557 vxge_hw_device_intr_enable(vdev->devh);
1561 /* Indicate card up */
1562 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1564 /* Get the traffic to flow through the vpaths */
1565 for (i = 0; i < vdev->no_of_vpath; i++) {
1566 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1568 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1571 netif_tx_wake_all_queues(vdev->ndev);
1575 vxge_debug_entryexit(VXGE_TRACE,
1576 "%s:%d Exiting...", __func__, __LINE__);
1578 /* Indicate reset done */
1579 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1580 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1586 * @vdev: pointer to ll device
1588 * driver may reset the chip on events of serr, eccerr, etc
1590 static int vxge_reset(struct vxgedev *vdev)
1592 return do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1596 * vxge_poll - Receive handler when Receive Polling is used.
1597 * @dev: pointer to the device structure.
1598 * @budget: Number of packets budgeted to be processed in this iteration.
1600 * This function comes into picture only if Receive side is being handled
1601 * through polling (called NAPI in linux). It mostly does what the normal
1602 * Rx interrupt handler does in terms of descriptor and packet processing
1603 * but not in an interrupt context. Also it will process a specified number
1604 * of packets at most in one iteration. This value is passed down by the
1605 * kernel as the function argument 'budget'.
1607 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1609 struct vxge_ring *ring =
1610 container_of(napi, struct vxge_ring, napi);
1611 int budget_org = budget;
1612 ring->budget = budget;
1614 vxge_hw_vpath_poll_rx(ring->handle);
1616 if (ring->pkts_processed < budget_org) {
1617 napi_complete(napi);
1618 /* Re enable the Rx interrupts for the vpath */
1619 vxge_hw_channel_msix_unmask(
1620 (struct __vxge_hw_channel *)ring->handle,
1621 ring->rx_vector_no);
1624 return ring->pkts_processed;
1627 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1629 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1630 int pkts_processed = 0;
1632 int budget_org = budget;
1633 struct vxge_ring *ring;
1635 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1636 pci_get_drvdata(vdev->pdev);
1638 for (i = 0; i < vdev->no_of_vpath; i++) {
1639 ring = &vdev->vpaths[i].ring;
1640 ring->budget = budget;
1641 vxge_hw_vpath_poll_rx(ring->handle);
1642 pkts_processed += ring->pkts_processed;
1643 budget -= ring->pkts_processed;
1648 VXGE_COMPLETE_ALL_TX(vdev);
1650 if (pkts_processed < budget_org) {
1651 napi_complete(napi);
1652 /* Re enable the Rx interrupts for the ring */
1653 vxge_hw_device_unmask_all(hldev);
1654 vxge_hw_device_flush_io(hldev);
1657 return pkts_processed;
1660 #ifdef CONFIG_NET_POLL_CONTROLLER
1662 * vxge_netpoll - netpoll event handler entry point
1663 * @dev : pointer to the device structure.
1665 * This function will be called by upper layer to check for events on the
1666 * interface in situations where interrupts are disabled. It is used for
1667 * specific in-kernel networking tasks, such as remote consoles and kernel
1668 * debugging over the network (example netdump in RedHat).
1670 static void vxge_netpoll(struct net_device *dev)
1672 struct __vxge_hw_device *hldev;
1673 struct vxgedev *vdev;
1675 vdev = (struct vxgedev *)netdev_priv(dev);
1676 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1678 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1680 if (pci_channel_offline(vdev->pdev))
1683 disable_irq(dev->irq);
1684 vxge_hw_device_clear_tx_rx(hldev);
1686 vxge_hw_device_clear_tx_rx(hldev);
1687 VXGE_COMPLETE_ALL_RX(vdev);
1688 VXGE_COMPLETE_ALL_TX(vdev);
1690 enable_irq(dev->irq);
1692 vxge_debug_entryexit(VXGE_TRACE,
1693 "%s:%d Exiting...", __func__, __LINE__);
1697 /* RTH configuration */
1698 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1700 enum vxge_hw_status status = VXGE_HW_OK;
1701 struct vxge_hw_rth_hash_types hash_types;
1702 u8 itable[256] = {0}; /* indirection table */
1703 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1708 * - itable with bucket numbers
1709 * - mtable with bucket-to-vpath mapping
1711 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1712 itable[index] = index;
1713 mtable[index] = index % vdev->no_of_vpath;
1716 /* set indirection table, bucket-to-vpath mapping */
1717 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1720 vdev->config.rth_bkt_sz);
1721 if (status != VXGE_HW_OK) {
1722 vxge_debug_init(VXGE_ERR,
1723 "RTH indirection table configuration failed "
1724 "for vpath:%d", vdev->vpaths[0].device_id);
1728 /* Fill RTH hash types */
1729 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1730 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1731 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1732 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1733 hash_types.hash_type_tcpipv6ex_en =
1734 vdev->config.rth_hash_type_tcpipv6ex;
1735 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1738 * Because the itable_set() method uses the active_table field
1739 * for the target virtual path the RTH config should be updated
1740 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1741 * when steering frames.
1743 for (index = 0; index < vdev->no_of_vpath; index++) {
1744 status = vxge_hw_vpath_rts_rth_set(
1745 vdev->vpaths[index].handle,
1746 vdev->config.rth_algorithm,
1748 vdev->config.rth_bkt_sz);
1750 if (status != VXGE_HW_OK) {
1751 vxge_debug_init(VXGE_ERR,
1752 "RTH configuration failed for vpath:%d",
1753 vdev->vpaths[index].device_id);
1761 static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1763 struct vxge_mac_addrs *new_mac_entry;
1764 u8 *mac_address = NULL;
1766 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1769 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1770 if (!new_mac_entry) {
1771 vxge_debug_mem(VXGE_ERR,
1772 "%s: memory allocation failed",
1777 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1779 /* Copy the new mac address to the list */
1780 mac_address = (u8 *)&new_mac_entry->macaddr;
1781 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1783 new_mac_entry->state = mac->state;
1784 vpath->mac_addr_cnt++;
1786 /* Is this a multicast address */
1787 if (0x01 & mac->macaddr[0])
1788 vpath->mcast_addr_cnt++;
1793 /* Add a mac address to DA table */
1794 static enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev,
1795 struct macInfo *mac)
1797 enum vxge_hw_status status = VXGE_HW_OK;
1798 struct vxge_vpath *vpath;
1799 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1801 if (0x01 & mac->macaddr[0]) /* multicast address */
1802 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1804 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1806 vpath = &vdev->vpaths[mac->vpath_no];
1807 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1808 mac->macmask, duplicate_mode);
1809 if (status != VXGE_HW_OK) {
1810 vxge_debug_init(VXGE_ERR,
1811 "DA config add entry failed for vpath:%d",
1814 if (FALSE == vxge_mac_list_add(vpath, mac))
1820 static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1822 struct list_head *entry, *next;
1824 u8 *mac_address = (u8 *) (&del_mac);
1826 /* Copy the mac address to delete from the list */
1827 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1829 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1830 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1832 kfree((struct vxge_mac_addrs *)entry);
1833 vpath->mac_addr_cnt--;
1835 /* Is this a multicast address */
1836 if (0x01 & mac->macaddr[0])
1837 vpath->mcast_addr_cnt--;
1844 /* delete a mac address from DA table */
1845 static enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev,
1846 struct macInfo *mac)
1848 enum vxge_hw_status status = VXGE_HW_OK;
1849 struct vxge_vpath *vpath;
1851 vpath = &vdev->vpaths[mac->vpath_no];
1852 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1854 if (status != VXGE_HW_OK) {
1855 vxge_debug_init(VXGE_ERR,
1856 "DA config delete entry failed for vpath:%d",
1859 vxge_mac_list_del(vpath, mac);
1863 /* list all mac addresses from DA table */
1865 static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1866 struct macInfo *mac)
1868 enum vxge_hw_status status = VXGE_HW_OK;
1869 unsigned char macmask[ETH_ALEN];
1870 unsigned char macaddr[ETH_ALEN];
1872 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1874 if (status != VXGE_HW_OK) {
1875 vxge_debug_init(VXGE_ERR,
1876 "DA config list entry failed for vpath:%d",
1881 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1883 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1885 if (status != VXGE_HW_OK)
1892 /* Store all vlan ids from the list to the vid table */
1893 static enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1895 enum vxge_hw_status status = VXGE_HW_OK;
1896 struct vxgedev *vdev = vpath->vdev;
1899 if (vdev->vlgrp && vpath->is_open) {
1901 for (vid = 0; vid < VLAN_N_VID; vid++) {
1902 if (!vlan_group_get_device(vdev->vlgrp, vid))
1904 /* Add these vlan to the vid table */
1905 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1912 /* Store all mac addresses from the list to the DA table */
1913 static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1915 enum vxge_hw_status status = VXGE_HW_OK;
1916 struct macInfo mac_info;
1917 u8 *mac_address = NULL;
1918 struct list_head *entry, *next;
1920 memset(&mac_info, 0, sizeof(struct macInfo));
1922 if (vpath->is_open) {
1924 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1927 ((struct vxge_mac_addrs *)entry)->macaddr;
1928 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1929 ((struct vxge_mac_addrs *)entry)->state =
1930 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1931 /* does this mac address already exist in da table? */
1932 status = vxge_search_mac_addr_in_da_table(vpath,
1934 if (status != VXGE_HW_OK) {
1935 /* Add this mac address to the DA table */
1936 status = vxge_hw_vpath_mac_addr_add(
1937 vpath->handle, mac_info.macaddr,
1939 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1940 if (status != VXGE_HW_OK) {
1941 vxge_debug_init(VXGE_ERR,
1942 "DA add entry failed for vpath:%d",
1944 ((struct vxge_mac_addrs *)entry)->state
1945 = VXGE_LL_MAC_ADDR_IN_LIST;
1955 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1957 enum vxge_hw_status status = VXGE_HW_OK;
1958 struct vxge_vpath *vpath;
1961 for (i = 0; i < vdev->no_of_vpath; i++) {
1962 vpath = &vdev->vpaths[i];
1963 if (vpath->handle) {
1964 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1965 if (is_vxge_card_up(vdev) &&
1966 vxge_hw_vpath_recover_from_reset(
1967 vpath->handle) != VXGE_HW_OK) {
1968 vxge_debug_init(VXGE_ERR,
1969 "vxge_hw_vpath_recover_"
1970 "from_reset failed for vpath: "
1975 vxge_debug_init(VXGE_ERR,
1976 "vxge_hw_vpath_reset failed for "
1987 static void vxge_close_vpaths(struct vxgedev *vdev, int index)
1989 struct vxge_vpath *vpath;
1992 for (i = index; i < vdev->no_of_vpath; i++) {
1993 vpath = &vdev->vpaths[i];
1995 if (vpath->handle && vpath->is_open) {
1996 vxge_hw_vpath_close(vpath->handle);
1997 vdev->stats.vpaths_open--;
2000 vpath->handle = NULL;
2005 static int vxge_open_vpaths(struct vxgedev *vdev)
2007 struct vxge_hw_vpath_attr attr;
2008 enum vxge_hw_status status;
2009 struct vxge_vpath *vpath;
2013 for (i = 0; i < vdev->no_of_vpath; i++) {
2014 vpath = &vdev->vpaths[i];
2016 vxge_assert(vpath->is_configured);
2017 attr.vp_id = vpath->device_id;
2018 attr.fifo_attr.callback = vxge_xmit_compl;
2019 attr.fifo_attr.txdl_term = vxge_tx_term;
2020 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2021 attr.fifo_attr.userdata = &vpath->fifo;
2023 attr.ring_attr.callback = vxge_rx_1b_compl;
2024 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2025 attr.ring_attr.rxd_term = vxge_rx_term;
2026 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2027 attr.ring_attr.userdata = &vpath->ring;
2029 vpath->ring.ndev = vdev->ndev;
2030 vpath->ring.pdev = vdev->pdev;
2031 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
2032 if (status == VXGE_HW_OK) {
2033 vpath->fifo.handle =
2034 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2035 vpath->ring.handle =
2036 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2037 vpath->fifo.tx_steering_type =
2038 vdev->config.tx_steering_type;
2039 vpath->fifo.ndev = vdev->ndev;
2040 vpath->fifo.pdev = vdev->pdev;
2041 if (vdev->config.tx_steering_type)
2043 netdev_get_tx_queue(vdev->ndev, i);
2046 netdev_get_tx_queue(vdev->ndev, 0);
2047 vpath->fifo.indicate_max_pkts =
2048 vdev->config.fifo_indicate_max_pkts;
2049 vpath->ring.rx_vector_no = 0;
2050 vpath->ring.rx_csum = vdev->rx_csum;
2051 vpath->ring.rx_hwts = vdev->rx_hwts;
2053 vdev->vp_handles[i] = vpath->handle;
2054 vpath->ring.gro_enable = vdev->config.gro_enable;
2055 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
2056 vdev->stats.vpaths_open++;
2058 vdev->stats.vpath_open_fail++;
2059 vxge_debug_init(VXGE_ERR,
2060 "%s: vpath: %d failed to open "
2062 vdev->ndev->name, vpath->device_id,
2064 vxge_close_vpaths(vdev, 0);
2068 vp_id = vpath->handle->vpath->vp_id;
2069 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2076 * @irq: the irq of the device.
2077 * @dev_id: a void pointer to the hldev structure of the Titan device
2078 * @ptregs: pointer to the registers pushed on the stack.
2080 * This function is the ISR handler of the device when napi is enabled. It
2081 * identifies the reason for the interrupt and calls the relevant service
2084 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2086 struct net_device *dev;
2087 struct __vxge_hw_device *hldev;
2089 enum vxge_hw_status status;
2090 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
2092 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2095 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
2097 if (pci_channel_offline(vdev->pdev))
2100 if (unlikely(!is_vxge_card_up(vdev)))
2103 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2105 if (status == VXGE_HW_OK) {
2106 vxge_hw_device_mask_all(hldev);
2109 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2110 vdev->vpaths_deployed >>
2111 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2113 vxge_hw_device_clear_tx_rx(hldev);
2114 napi_schedule(&vdev->napi);
2115 vxge_debug_intr(VXGE_TRACE,
2116 "%s:%d Exiting...", __func__, __LINE__);
2119 vxge_hw_device_unmask_all(hldev);
2120 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2121 (status == VXGE_HW_ERR_CRITICAL) ||
2122 (status == VXGE_HW_ERR_FIFO))) {
2123 vxge_hw_device_mask_all(hldev);
2124 vxge_hw_device_flush_io(hldev);
2126 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2129 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2133 #ifdef CONFIG_PCI_MSI
2136 vxge_tx_msix_handle(int irq, void *dev_id)
2138 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2140 VXGE_COMPLETE_VPATH_TX(fifo);
2146 vxge_rx_msix_napi_handle(int irq, void *dev_id)
2148 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2150 /* MSIX_IDX for Rx is 1 */
2151 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2152 ring->rx_vector_no);
2154 napi_schedule(&ring->napi);
2159 vxge_alarm_msix_handle(int irq, void *dev_id)
2162 enum vxge_hw_status status;
2163 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2164 struct vxgedev *vdev = vpath->vdev;
2165 int msix_id = (vpath->handle->vpath->vp_id *
2166 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2168 for (i = 0; i < vdev->no_of_vpath; i++) {
2169 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
2171 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2173 if (status == VXGE_HW_OK) {
2175 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2179 vxge_debug_intr(VXGE_ERR,
2180 "%s: vxge_hw_vpath_alarm_process failed %x ",
2181 VXGE_DRIVER_NAME, status);
2186 static int vxge_alloc_msix(struct vxgedev *vdev)
2189 int msix_intr_vect = 0, temp;
2193 /* Tx/Rx MSIX Vectors count */
2194 vdev->intr_cnt = vdev->no_of_vpath * 2;
2196 /* Alarm MSIX Vectors count */
2199 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2201 if (!vdev->entries) {
2202 vxge_debug_init(VXGE_ERR,
2203 "%s: memory allocation failed",
2206 goto alloc_entries_failed;
2209 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2210 sizeof(struct vxge_msix_entry),
2212 if (!vdev->vxge_entries) {
2213 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2216 goto alloc_vxge_entries_failed;
2219 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
2221 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2223 /* Initialize the fifo vector */
2224 vdev->entries[j].entry = msix_intr_vect;
2225 vdev->vxge_entries[j].entry = msix_intr_vect;
2226 vdev->vxge_entries[j].in_use = 0;
2229 /* Initialize the ring vector */
2230 vdev->entries[j].entry = msix_intr_vect + 1;
2231 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2232 vdev->vxge_entries[j].in_use = 0;
2236 /* Initialize the alarm vector */
2237 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2238 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
2239 vdev->vxge_entries[j].in_use = 0;
2241 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
2243 vxge_debug_init(VXGE_ERR,
2244 "%s: MSI-X enable failed for %d vectors, ret: %d",
2245 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
2246 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2248 goto enable_msix_failed;
2251 kfree(vdev->entries);
2252 kfree(vdev->vxge_entries);
2253 vdev->entries = NULL;
2254 vdev->vxge_entries = NULL;
2255 /* Try with less no of vector by reducing no of vpaths count */
2257 vxge_close_vpaths(vdev, temp);
2258 vdev->no_of_vpath = temp;
2260 } else if (ret < 0) {
2262 goto enable_msix_failed;
2267 kfree(vdev->vxge_entries);
2268 alloc_vxge_entries_failed:
2269 kfree(vdev->entries);
2270 alloc_entries_failed:
2274 static int vxge_enable_msix(struct vxgedev *vdev)
2278 /* 0 - Tx, 1 - Rx */
2279 int tim_msix_id[4] = {0, 1, 0, 0};
2283 /* allocate msix vectors */
2284 ret = vxge_alloc_msix(vdev);
2286 for (i = 0; i < vdev->no_of_vpath; i++) {
2287 struct vxge_vpath *vpath = &vdev->vpaths[i];
2289 /* If fifo or ring are not enabled, the MSIX vector for
2290 * it should be set to 0.
2292 vpath->ring.rx_vector_no = (vpath->device_id *
2293 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
2295 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2296 VXGE_ALARM_MSIX_ID);
2303 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2307 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
2309 if (vdev->vxge_entries[intr_cnt].in_use) {
2310 synchronize_irq(vdev->entries[intr_cnt].vector);
2311 free_irq(vdev->entries[intr_cnt].vector,
2312 vdev->vxge_entries[intr_cnt].arg);
2313 vdev->vxge_entries[intr_cnt].in_use = 0;
2317 kfree(vdev->entries);
2318 kfree(vdev->vxge_entries);
2319 vdev->entries = NULL;
2320 vdev->vxge_entries = NULL;
2322 if (vdev->config.intr_type == MSI_X)
2323 pci_disable_msix(vdev->pdev);
2327 static void vxge_rem_isr(struct vxgedev *vdev)
2329 struct __vxge_hw_device *hldev;
2330 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2332 #ifdef CONFIG_PCI_MSI
2333 if (vdev->config.intr_type == MSI_X) {
2334 vxge_rem_msix_isr(vdev);
2337 if (vdev->config.intr_type == INTA) {
2338 synchronize_irq(vdev->pdev->irq);
2339 free_irq(vdev->pdev->irq, vdev);
2343 static int vxge_add_isr(struct vxgedev *vdev)
2346 #ifdef CONFIG_PCI_MSI
2347 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2348 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2350 if (vdev->config.intr_type == MSI_X)
2351 ret = vxge_enable_msix(vdev);
2354 vxge_debug_init(VXGE_ERR,
2355 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2356 vxge_debug_init(VXGE_ERR,
2357 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2358 vdev->config.intr_type = INTA;
2361 if (vdev->config.intr_type == MSI_X) {
2363 intr_idx < (vdev->no_of_vpath *
2364 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2366 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2371 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2372 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2374 vdev->entries[intr_cnt].entry,
2377 vdev->entries[intr_cnt].vector,
2378 vxge_tx_msix_handle, 0,
2379 vdev->desc[intr_cnt],
2380 &vdev->vpaths[vp_idx].fifo);
2381 vdev->vxge_entries[intr_cnt].arg =
2382 &vdev->vpaths[vp_idx].fifo;
2386 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2387 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2389 vdev->entries[intr_cnt].entry,
2392 vdev->entries[intr_cnt].vector,
2393 vxge_rx_msix_napi_handle,
2395 vdev->desc[intr_cnt],
2396 &vdev->vpaths[vp_idx].ring);
2397 vdev->vxge_entries[intr_cnt].arg =
2398 &vdev->vpaths[vp_idx].ring;
2404 vxge_debug_init(VXGE_ERR,
2405 "%s: MSIX - %d Registration failed",
2406 vdev->ndev->name, intr_cnt);
2407 vxge_rem_msix_isr(vdev);
2408 vdev->config.intr_type = INTA;
2409 vxge_debug_init(VXGE_ERR,
2410 "%s: Defaulting to INTA"
2411 , vdev->ndev->name);
2416 /* We requested for this msix interrupt */
2417 vdev->vxge_entries[intr_cnt].in_use = 1;
2418 msix_idx += vdev->vpaths[vp_idx].device_id *
2419 VXGE_HW_VPATH_MSIX_ACTIVE;
2420 vxge_hw_vpath_msix_unmask(
2421 vdev->vpaths[vp_idx].handle,
2426 /* Point to next vpath handler */
2427 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2428 (vp_idx < (vdev->no_of_vpath - 1)))
2432 intr_cnt = vdev->no_of_vpath * 2;
2433 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2434 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2436 vdev->entries[intr_cnt].entry,
2438 /* For Alarm interrupts */
2439 ret = request_irq(vdev->entries[intr_cnt].vector,
2440 vxge_alarm_msix_handle, 0,
2441 vdev->desc[intr_cnt],
2444 vxge_debug_init(VXGE_ERR,
2445 "%s: MSIX - %d Registration failed",
2446 vdev->ndev->name, intr_cnt);
2447 vxge_rem_msix_isr(vdev);
2448 vdev->config.intr_type = INTA;
2449 vxge_debug_init(VXGE_ERR,
2450 "%s: Defaulting to INTA",
2455 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2456 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2457 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2459 vdev->vxge_entries[intr_cnt].in_use = 1;
2460 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
2465 if (vdev->config.intr_type == INTA) {
2466 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2467 "%s:vxge:INTA", vdev->ndev->name);
2468 vxge_hw_device_set_intr_type(vdev->devh,
2469 VXGE_HW_INTR_MODE_IRQLINE);
2470 vxge_hw_vpath_tti_ci_set(vdev->devh,
2471 vdev->vpaths[0].device_id);
2472 ret = request_irq((int) vdev->pdev->irq,
2474 IRQF_SHARED, vdev->desc[0], vdev);
2476 vxge_debug_init(VXGE_ERR,
2477 "%s %s-%d: ISR registration failed",
2478 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2481 vxge_debug_init(VXGE_TRACE,
2482 "new %s-%d line allocated",
2483 "IRQ", vdev->pdev->irq);
2489 static void vxge_poll_vp_reset(unsigned long data)
2491 struct vxgedev *vdev = (struct vxgedev *)data;
2494 for (i = 0; i < vdev->no_of_vpath; i++) {
2495 if (test_bit(i, &vdev->vp_reset)) {
2496 vxge_reset_vpath(vdev, i);
2500 if (j && (vdev->config.intr_type != MSI_X)) {
2501 vxge_hw_device_unmask_all(vdev->devh);
2502 vxge_hw_device_flush_io(vdev->devh);
2505 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2508 static void vxge_poll_vp_lockup(unsigned long data)
2510 struct vxgedev *vdev = (struct vxgedev *)data;
2511 enum vxge_hw_status status = VXGE_HW_OK;
2512 struct vxge_vpath *vpath;
2513 struct vxge_ring *ring;
2516 for (i = 0; i < vdev->no_of_vpath; i++) {
2517 ring = &vdev->vpaths[i].ring;
2518 /* Did this vpath received any packets */
2519 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2520 status = vxge_hw_vpath_check_leak(ring->handle);
2522 /* Did it received any packets last time */
2523 if ((VXGE_HW_FAIL == status) &&
2524 (VXGE_HW_FAIL == ring->last_status)) {
2526 /* schedule vpath reset */
2527 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2528 vpath = &vdev->vpaths[i];
2530 /* disable interrupts for this vpath */
2531 vxge_vpath_intr_disable(vdev, i);
2533 /* stop the queue for this vpath */
2534 netif_tx_stop_queue(vpath->fifo.txq);
2539 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2540 ring->last_status = status;
2543 /* Check every 1 milli second */
2544 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2549 * @dev: pointer to the device structure.
2551 * This function is the open entry point of the driver. It mainly calls a
2552 * function to allocate Rx buffers and inserts them into the buffer
2553 * descriptors and then enables the Rx part of the NIC.
2554 * Return value: '0' on success and an appropriate (-)ve integer as
2555 * defined in errno.h file on failure.
2558 vxge_open(struct net_device *dev)
2560 enum vxge_hw_status status;
2561 struct vxgedev *vdev;
2562 struct __vxge_hw_device *hldev;
2563 struct vxge_vpath *vpath;
2566 u64 val64, function_mode;
2567 vxge_debug_entryexit(VXGE_TRACE,
2568 "%s: %s:%d", dev->name, __func__, __LINE__);
2570 vdev = (struct vxgedev *)netdev_priv(dev);
2571 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2572 function_mode = vdev->config.device_hw_info.function_mode;
2574 /* make sure you have link off by default every time Nic is
2576 netif_carrier_off(dev);
2579 status = vxge_open_vpaths(vdev);
2580 if (status != VXGE_HW_OK) {
2581 vxge_debug_init(VXGE_ERR,
2582 "%s: fatal: Vpath open failed", vdev->ndev->name);
2587 vdev->mtu = dev->mtu;
2589 status = vxge_add_isr(vdev);
2590 if (status != VXGE_HW_OK) {
2591 vxge_debug_init(VXGE_ERR,
2592 "%s: fatal: ISR add failed", dev->name);
2597 if (vdev->config.intr_type != MSI_X) {
2598 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2599 vdev->config.napi_weight);
2600 napi_enable(&vdev->napi);
2601 for (i = 0; i < vdev->no_of_vpath; i++) {
2602 vpath = &vdev->vpaths[i];
2603 vpath->ring.napi_p = &vdev->napi;
2606 for (i = 0; i < vdev->no_of_vpath; i++) {
2607 vpath = &vdev->vpaths[i];
2608 netif_napi_add(dev, &vpath->ring.napi,
2609 vxge_poll_msix, vdev->config.napi_weight);
2610 napi_enable(&vpath->ring.napi);
2611 vpath->ring.napi_p = &vpath->ring.napi;
2616 if (vdev->config.rth_steering) {
2617 status = vxge_rth_configure(vdev);
2618 if (status != VXGE_HW_OK) {
2619 vxge_debug_init(VXGE_ERR,
2620 "%s: fatal: RTH configuration failed",
2626 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2627 hldev->config.rth_en ? "enabled" : "disabled");
2629 for (i = 0; i < vdev->no_of_vpath; i++) {
2630 vpath = &vdev->vpaths[i];
2632 /* set initial mtu before enabling the device */
2633 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
2634 if (status != VXGE_HW_OK) {
2635 vxge_debug_init(VXGE_ERR,
2636 "%s: fatal: can not set new MTU", dev->name);
2642 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2643 vxge_debug_init(vdev->level_trace,
2644 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2645 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2647 /* Restore the DA, VID table and also multicast and promiscuous mode
2650 if (vdev->all_multi_flg) {
2651 for (i = 0; i < vdev->no_of_vpath; i++) {
2652 vpath = &vdev->vpaths[i];
2653 vxge_restore_vpath_mac_addr(vpath);
2654 vxge_restore_vpath_vid_table(vpath);
2656 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2657 if (status != VXGE_HW_OK)
2658 vxge_debug_init(VXGE_ERR,
2659 "%s:%d Enabling multicast failed",
2660 __func__, __LINE__);
2664 /* Enable vpath to sniff all unicast/multicast traffic that not
2665 * addressed to them. We allow promiscous mode for PF only
2669 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2670 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2672 vxge_hw_mgmt_reg_write(vdev->devh,
2673 vxge_hw_mgmt_reg_type_mrpcim,
2675 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2676 rxmac_authorize_all_addr),
2679 vxge_hw_mgmt_reg_write(vdev->devh,
2680 vxge_hw_mgmt_reg_type_mrpcim,
2682 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2683 rxmac_authorize_all_vid),
2686 vxge_set_multicast(dev);
2688 /* Enabling Bcast and mcast for all vpath */
2689 for (i = 0; i < vdev->no_of_vpath; i++) {
2690 vpath = &vdev->vpaths[i];
2691 status = vxge_hw_vpath_bcast_enable(vpath->handle);
2692 if (status != VXGE_HW_OK)
2693 vxge_debug_init(VXGE_ERR,
2694 "%s : Can not enable bcast for vpath "
2695 "id %d", dev->name, i);
2696 if (vdev->config.addr_learn_en) {
2697 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2698 if (status != VXGE_HW_OK)
2699 vxge_debug_init(VXGE_ERR,
2700 "%s : Can not enable mcast for vpath "
2701 "id %d", dev->name, i);
2705 vxge_hw_device_setpause_data(vdev->devh, 0,
2706 vdev->config.tx_pause_enable,
2707 vdev->config.rx_pause_enable);
2709 if (vdev->vp_reset_timer.function == NULL)
2710 vxge_os_timer(vdev->vp_reset_timer,
2711 vxge_poll_vp_reset, vdev, (HZ/2));
2713 if (vdev->vp_lockup_timer.function == NULL)
2714 vxge_os_timer(vdev->vp_lockup_timer,
2715 vxge_poll_vp_lockup, vdev, (HZ/2));
2717 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2721 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2722 netif_carrier_on(vdev->ndev);
2723 netdev_notice(vdev->ndev, "Link Up\n");
2724 vdev->stats.link_up++;
2727 vxge_hw_device_intr_enable(vdev->devh);
2731 for (i = 0; i < vdev->no_of_vpath; i++) {
2732 vpath = &vdev->vpaths[i];
2734 vxge_hw_vpath_enable(vpath->handle);
2736 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
2739 netif_tx_start_all_queues(vdev->ndev);
2746 if (vdev->config.intr_type != MSI_X)
2747 napi_disable(&vdev->napi);
2749 for (i = 0; i < vdev->no_of_vpath; i++)
2750 napi_disable(&vdev->vpaths[i].ring.napi);
2754 vxge_close_vpaths(vdev, 0);
2756 vxge_debug_entryexit(VXGE_TRACE,
2757 "%s: %s:%d Exiting...",
2758 dev->name, __func__, __LINE__);
2762 /* Loop throught the mac address list and delete all the entries */
2763 static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2766 struct list_head *entry, *next;
2767 if (list_empty(&vpath->mac_addr_list))
2770 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2772 kfree((struct vxge_mac_addrs *)entry);
2776 static void vxge_napi_del_all(struct vxgedev *vdev)
2779 if (vdev->config.intr_type != MSI_X)
2780 netif_napi_del(&vdev->napi);
2782 for (i = 0; i < vdev->no_of_vpath; i++)
2783 netif_napi_del(&vdev->vpaths[i].ring.napi);
2787 static int do_vxge_close(struct net_device *dev, int do_io)
2789 enum vxge_hw_status status;
2790 struct vxgedev *vdev;
2791 struct __vxge_hw_device *hldev;
2793 u64 val64, vpath_vector;
2794 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2795 dev->name, __func__, __LINE__);
2797 vdev = (struct vxgedev *)netdev_priv(dev);
2798 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2800 if (unlikely(!is_vxge_card_up(vdev)))
2803 /* If vxge_handle_crit_err task is executing,
2804 * wait till it completes. */
2805 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2809 /* Put the vpath back in normal mode */
2810 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2811 status = vxge_hw_mgmt_reg_read(vdev->devh,
2812 vxge_hw_mgmt_reg_type_mrpcim,
2815 struct vxge_hw_mrpcim_reg,
2816 rts_mgr_cbasin_cfg),
2819 if (status == VXGE_HW_OK) {
2820 val64 &= ~vpath_vector;
2821 status = vxge_hw_mgmt_reg_write(vdev->devh,
2822 vxge_hw_mgmt_reg_type_mrpcim,
2825 struct vxge_hw_mrpcim_reg,
2826 rts_mgr_cbasin_cfg),
2830 /* Remove the function 0 from promiscous mode */
2831 vxge_hw_mgmt_reg_write(vdev->devh,
2832 vxge_hw_mgmt_reg_type_mrpcim,
2834 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2835 rxmac_authorize_all_addr),
2838 vxge_hw_mgmt_reg_write(vdev->devh,
2839 vxge_hw_mgmt_reg_type_mrpcim,
2841 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2842 rxmac_authorize_all_vid),
2847 del_timer_sync(&vdev->vp_lockup_timer);
2849 del_timer_sync(&vdev->vp_reset_timer);
2852 vxge_hw_device_wait_receive_idle(hldev);
2854 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2857 if (vdev->config.intr_type != MSI_X)
2858 napi_disable(&vdev->napi);
2860 for (i = 0; i < vdev->no_of_vpath; i++)
2861 napi_disable(&vdev->vpaths[i].ring.napi);
2864 netif_carrier_off(vdev->ndev);
2865 netdev_notice(vdev->ndev, "Link Down\n");
2866 netif_tx_stop_all_queues(vdev->ndev);
2868 /* Note that at this point xmit() is stopped by upper layer */
2870 vxge_hw_device_intr_disable(vdev->devh);
2874 vxge_napi_del_all(vdev);
2877 vxge_reset_all_vpaths(vdev);
2879 vxge_close_vpaths(vdev, 0);
2881 vxge_debug_entryexit(VXGE_TRACE,
2882 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2884 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2891 * @dev: device pointer.
2893 * This is the stop entry point of the driver. It needs to undo exactly
2894 * whatever was done by the open entry point, thus it's usually referred to
2895 * as the close function.Among other things this function mainly stops the
2896 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2897 * Return value: '0' on success and an appropriate (-)ve integer as
2898 * defined in errno.h file on failure.
2901 vxge_close(struct net_device *dev)
2903 do_vxge_close(dev, 1);
2909 * @dev: net device pointer.
2910 * @new_mtu :the new MTU size for the device.
2912 * A driver entry point to change MTU size for the device. Before changing
2913 * the MTU the device must be stopped.
2915 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
2917 struct vxgedev *vdev = netdev_priv(dev);
2919 vxge_debug_entryexit(vdev->level_trace,
2920 "%s:%d", __func__, __LINE__);
2921 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
2922 vxge_debug_init(vdev->level_err,
2923 "%s: mtu size is invalid", dev->name);
2927 /* check if device is down already */
2928 if (unlikely(!is_vxge_card_up(vdev))) {
2929 /* just store new value, will use later on open() */
2931 vxge_debug_init(vdev->level_err,
2932 "%s", "device is down on MTU change");
2936 vxge_debug_init(vdev->level_trace,
2937 "trying to apply new MTU %d", new_mtu);
2939 if (vxge_close(dev))
2943 vdev->mtu = new_mtu;
2948 vxge_debug_init(vdev->level_trace,
2949 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
2951 vxge_debug_entryexit(vdev->level_trace,
2952 "%s:%d Exiting...", __func__, __LINE__);
2959 * @dev: pointer to the device structure
2960 * @stats: pointer to struct rtnl_link_stats64
2963 static struct rtnl_link_stats64 *
2964 vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
2966 struct vxgedev *vdev = netdev_priv(dev);
2969 /* net_stats already zeroed by caller */
2970 for (k = 0; k < vdev->no_of_vpath; k++) {
2971 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
2972 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
2973 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
2974 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
2975 net_stats->rx_dropped +=
2976 vdev->vpaths[k].ring.stats.rx_dropped;
2978 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
2979 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
2980 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
2986 static enum vxge_hw_status vxge_timestamp_config(struct vxgedev *vdev,
2989 enum vxge_hw_status status;
2992 /* Timestamp is passed to the driver via the FCS, therefore we
2993 * must disable the FCS stripping by the adapter. Since this is
2994 * required for the driver to load (due to a hardware bug),
2995 * there is no need to do anything special here.
2998 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
2999 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3000 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
3004 status = vxge_hw_mgmt_reg_write(vdev->devh,
3005 vxge_hw_mgmt_reg_type_mrpcim,
3007 offsetof(struct vxge_hw_mrpcim_reg,
3010 vxge_hw_device_flush_io(vdev->devh);
3014 static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3016 struct hwtstamp_config config;
3017 enum vxge_hw_status status;
3020 if (copy_from_user(&config, data, sizeof(config)))
3023 /* reserved for future extensions */
3027 /* Transmit HW Timestamp not supported */
3028 switch (config.tx_type) {
3029 case HWTSTAMP_TX_OFF:
3031 case HWTSTAMP_TX_ON:
3036 switch (config.rx_filter) {
3037 case HWTSTAMP_FILTER_NONE:
3038 status = vxge_timestamp_config(vdev, 0);
3039 if (status != VXGE_HW_OK)
3043 config.rx_filter = HWTSTAMP_FILTER_NONE;
3046 case HWTSTAMP_FILTER_ALL:
3047 case HWTSTAMP_FILTER_SOME:
3048 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3049 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3050 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3051 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3052 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3053 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3054 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3055 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3056 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3057 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3058 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3059 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3060 status = vxge_timestamp_config(vdev, 1);
3061 if (status != VXGE_HW_OK)
3065 config.rx_filter = HWTSTAMP_FILTER_ALL;
3072 for (i = 0; i < vdev->no_of_vpath; i++)
3073 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3075 if (copy_to_user(data, &config, sizeof(config)))
3083 * @dev: Device pointer.
3084 * @ifr: An IOCTL specific structure, that can contain a pointer to
3085 * a proprietary structure used to pass information to the driver.
3086 * @cmd: This is used to distinguish between the different commands that
3087 * can be passed to the IOCTL functions.
3089 * Entry point for the Ioctl.
3091 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3093 struct vxgedev *vdev = netdev_priv(dev);
3098 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3111 * @dev: pointer to net device structure
3113 * Watchdog for transmit side.
3114 * This function is triggered if the Tx Queue is stopped
3115 * for a pre-defined amount of time when the Interface is still up.
3118 vxge_tx_watchdog(struct net_device *dev)
3120 struct vxgedev *vdev;
3122 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3124 vdev = (struct vxgedev *)netdev_priv(dev);
3126 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3129 vxge_debug_entryexit(VXGE_TRACE,
3130 "%s:%d Exiting...", __func__, __LINE__);
3134 * vxge_vlan_rx_register
3135 * @dev: net device pointer.
3138 * Vlan group registration
3141 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3143 struct vxgedev *vdev;
3144 struct vxge_vpath *vpath;
3147 enum vxge_hw_status status;
3150 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3152 vdev = (struct vxgedev *)netdev_priv(dev);
3154 vpath = &vdev->vpaths[0];
3155 if ((NULL == grp) && (vpath->is_open)) {
3156 /* Get the first vlan */
3157 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3159 while (status == VXGE_HW_OK) {
3161 /* Delete this vlan from the vid table */
3162 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3163 vpath = &vdev->vpaths[vp];
3164 if (!vpath->is_open)
3167 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3170 /* Get the next vlan to be deleted */
3171 vpath = &vdev->vpaths[0];
3172 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3178 for (i = 0; i < vdev->no_of_vpath; i++) {
3179 if (vdev->vpaths[i].is_configured)
3180 vdev->vpaths[i].ring.vlgrp = grp;
3183 vxge_debug_entryexit(VXGE_TRACE,
3184 "%s:%d Exiting...", __func__, __LINE__);
3188 * vxge_vlan_rx_add_vid
3189 * @dev: net device pointer.
3192 * Add the vlan id to the devices vlan id table
3195 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3197 struct vxgedev *vdev;
3198 struct vxge_vpath *vpath;
3201 vdev = (struct vxgedev *)netdev_priv(dev);
3203 /* Add these vlan to the vid table */
3204 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3205 vpath = &vdev->vpaths[vp_id];
3206 if (!vpath->is_open)
3208 vxge_hw_vpath_vid_add(vpath->handle, vid);
3213 * vxge_vlan_rx_add_vid
3214 * @dev: net device pointer.
3217 * Remove the vlan id from the device's vlan id table
3220 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3222 struct vxgedev *vdev;
3223 struct vxge_vpath *vpath;
3226 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3228 vdev = (struct vxgedev *)netdev_priv(dev);
3230 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3232 /* Delete this vlan from the vid table */
3233 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3234 vpath = &vdev->vpaths[vp_id];
3235 if (!vpath->is_open)
3237 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3239 vxge_debug_entryexit(VXGE_TRACE,
3240 "%s:%d Exiting...", __func__, __LINE__);
3243 static const struct net_device_ops vxge_netdev_ops = {
3244 .ndo_open = vxge_open,
3245 .ndo_stop = vxge_close,
3246 .ndo_get_stats64 = vxge_get_stats64,
3247 .ndo_start_xmit = vxge_xmit,
3248 .ndo_validate_addr = eth_validate_addr,
3249 .ndo_set_multicast_list = vxge_set_multicast,
3251 .ndo_do_ioctl = vxge_ioctl,
3253 .ndo_set_mac_address = vxge_set_mac_addr,
3254 .ndo_change_mtu = vxge_change_mtu,
3255 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3256 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3257 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3259 .ndo_tx_timeout = vxge_tx_watchdog,
3260 #ifdef CONFIG_NET_POLL_CONTROLLER
3261 .ndo_poll_controller = vxge_netpoll,
3265 static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3266 struct vxge_config *config,
3267 int high_dma, int no_of_vpath,
3268 struct vxgedev **vdev_out)
3270 struct net_device *ndev;
3271 enum vxge_hw_status status = VXGE_HW_OK;
3272 struct vxgedev *vdev;
3273 int ret = 0, no_of_queue = 1;
3277 if (config->tx_steering_type)
3278 no_of_queue = no_of_vpath;
3280 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3284 vxge_hw_device_trace_level_get(hldev),
3285 "%s : device allocation failed", __func__);
3290 vxge_debug_entryexit(
3291 vxge_hw_device_trace_level_get(hldev),
3292 "%s: %s:%d Entering...",
3293 ndev->name, __func__, __LINE__);
3295 vdev = netdev_priv(ndev);
3296 memset(vdev, 0, sizeof(struct vxgedev));
3300 vdev->pdev = hldev->pdev;
3301 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3302 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3305 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3307 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3308 NETIF_F_HW_VLAN_FILTER;
3309 /* Driver entry points */
3310 ndev->irq = vdev->pdev->irq;
3311 ndev->base_addr = (unsigned long) hldev->bar0;
3313 ndev->netdev_ops = &vxge_netdev_ops;
3315 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3317 vxge_initialize_ethtool_ops(ndev);
3319 if (vdev->config.rth_steering != NO_STEERING) {
3320 ndev->features |= NETIF_F_RXHASH;
3321 hldev->config.rth_en = VXGE_HW_RTH_ENABLE;
3324 /* Allocate memory for vpath */
3325 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3326 no_of_vpath, GFP_KERNEL);
3327 if (!vdev->vpaths) {
3328 vxge_debug_init(VXGE_ERR,
3329 "%s: vpath memory allocation failed",
3335 ndev->features |= NETIF_F_SG;
3337 ndev->features |= NETIF_F_HW_CSUM;
3338 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3339 "%s : checksuming enabled", __func__);
3342 ndev->features |= NETIF_F_HIGHDMA;
3343 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3344 "%s : using High DMA", __func__);
3347 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3349 if (vdev->config.gro_enable)
3350 ndev->features |= NETIF_F_GRO;
3352 if (register_netdev(ndev)) {
3353 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3354 "%s: %s : device registration failed!",
3355 ndev->name, __func__);
3360 /* Set the factory defined MAC address initially */
3361 ndev->addr_len = ETH_ALEN;
3363 /* Make Link state as off at this point, when the Link change
3364 * interrupt comes the state will be automatically changed to
3367 netif_carrier_off(ndev);
3369 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3370 "%s: Ethernet device registered",
3376 /* Resetting the Device stats */
3377 status = vxge_hw_mrpcim_stats_access(
3379 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3384 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3386 vxge_hw_device_trace_level_get(hldev),
3387 "%s: device stats clear returns"
3388 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3390 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3391 "%s: %s:%d Exiting...",
3392 ndev->name, __func__, __LINE__);
3396 kfree(vdev->vpaths);
3404 * vxge_device_unregister
3406 * This function will unregister and free network device
3409 vxge_device_unregister(struct __vxge_hw_device *hldev)
3411 struct vxgedev *vdev;
3412 struct net_device *dev;
3414 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3415 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3420 vdev = netdev_priv(dev);
3421 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3422 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3423 level_trace = vdev->level_trace;
3425 vxge_debug_entryexit(level_trace,
3426 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3428 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3430 /* in 2.6 will call stop() if device is up */
3431 unregister_netdev(dev);
3433 flush_scheduled_work();
3435 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3436 vxge_debug_entryexit(level_trace,
3437 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3441 * vxge_callback_crit_err
3443 * This function is called by the alarm handler in interrupt context.
3444 * Driver must analyze it based on the event type.
3447 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3448 enum vxge_hw_event type, u64 vp_id)
3450 struct net_device *dev = hldev->ndev;
3451 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3452 struct vxge_vpath *vpath = NULL;
3455 vxge_debug_entryexit(vdev->level_trace,
3456 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3458 /* Note: This event type should be used for device wide
3459 * indications only - Serious errors, Slot freeze and critical errors
3461 vdev->cric_err_event = type;
3463 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3464 vpath = &vdev->vpaths[vpath_idx];
3465 if (vpath->device_id == vp_id)
3469 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3470 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3471 vxge_debug_init(VXGE_ERR,
3472 "%s: Slot is frozen", vdev->ndev->name);
3473 } else if (type == VXGE_HW_EVENT_SERR) {
3474 vxge_debug_init(VXGE_ERR,
3475 "%s: Encountered Serious Error",
3477 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3478 vxge_debug_init(VXGE_ERR,
3479 "%s: Encountered Critical Error",
3483 if ((type == VXGE_HW_EVENT_SERR) ||
3484 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3485 if (unlikely(vdev->exec_mode))
3486 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3487 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3488 vxge_hw_device_mask_all(hldev);
3489 if (unlikely(vdev->exec_mode))
3490 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3491 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3492 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3494 if (unlikely(vdev->exec_mode))
3495 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3497 /* check if this vpath is already set for reset */
3498 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3500 /* disable interrupts for this vpath */
3501 vxge_vpath_intr_disable(vdev, vpath_idx);
3503 /* stop the queue for this vpath */
3504 netif_tx_stop_queue(vpath->fifo.txq);
3509 vxge_debug_entryexit(vdev->level_trace,
3510 "%s: %s:%d Exiting...",
3511 vdev->ndev->name, __func__, __LINE__);
3514 static void verify_bandwidth(void)
3516 int i, band_width, total = 0, equal_priority = 0;
3518 /* 1. If user enters 0 for some fifo, give equal priority to all */
3519 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3520 if (bw_percentage[i] == 0) {
3526 if (!equal_priority) {
3527 /* 2. If sum exceeds 100, give equal priority to all */
3528 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3529 if (bw_percentage[i] == 0xFF)
3532 total += bw_percentage[i];
3533 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3540 if (!equal_priority) {
3541 /* Is all the bandwidth consumed? */
3542 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3543 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3544 /* Split rest of bw equally among next VPs*/
3546 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3547 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3548 if (band_width < 2) /* min of 2% */
3551 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3557 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3561 if (equal_priority) {
3562 vxge_debug_init(VXGE_ERR,
3563 "%s: Assigning equal bandwidth to all the vpaths",
3565 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3566 VXGE_HW_MAX_VIRTUAL_PATHS;
3567 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3568 bw_percentage[i] = bw_percentage[0];
3573 * Vpath configuration
3575 static int __devinit vxge_config_vpaths(
3576 struct vxge_hw_device_config *device_config,
3577 u64 vpath_mask, struct vxge_config *config_param)
3579 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3580 u32 txdl_size, txdl_per_memblock;
3582 temp = driver_config->vpath_per_dev;
3583 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3584 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3585 /* No more CPU. Return vpath number as zero.*/
3586 if (driver_config->g_no_cpus == -1)
3589 if (!driver_config->g_no_cpus)
3590 driver_config->g_no_cpus = num_online_cpus();
3592 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3593 if (!driver_config->vpath_per_dev)
3594 driver_config->vpath_per_dev = 1;
3596 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3597 if (!vxge_bVALn(vpath_mask, i, 1))
3601 if (default_no_vpath < driver_config->vpath_per_dev)
3602 driver_config->vpath_per_dev = default_no_vpath;
3604 driver_config->g_no_cpus = driver_config->g_no_cpus -
3605 (driver_config->vpath_per_dev * 2);
3606 if (driver_config->g_no_cpus <= 0)
3607 driver_config->g_no_cpus = -1;
3610 if (driver_config->vpath_per_dev == 1) {
3611 vxge_debug_ll_config(VXGE_TRACE,
3612 "%s: Disable tx and rx steering, "
3613 "as single vpath is configured", VXGE_DRIVER_NAME);
3614 config_param->rth_steering = NO_STEERING;
3615 config_param->tx_steering_type = NO_STEERING;
3616 device_config->rth_en = 0;
3619 /* configure bandwidth */
3620 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3621 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3623 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3624 device_config->vp_config[i].vp_id = i;
3625 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3626 if (no_of_vpaths < driver_config->vpath_per_dev) {
3627 if (!vxge_bVALn(vpath_mask, i, 1)) {
3628 vxge_debug_ll_config(VXGE_TRACE,
3629 "%s: vpath: %d is not available",
3630 VXGE_DRIVER_NAME, i);
3633 vxge_debug_ll_config(VXGE_TRACE,
3634 "%s: vpath: %d available",
3635 VXGE_DRIVER_NAME, i);
3639 vxge_debug_ll_config(VXGE_TRACE,
3640 "%s: vpath: %d is not configured, "
3641 "max_config_vpath exceeded",
3642 VXGE_DRIVER_NAME, i);
3646 /* Configure Tx fifo's */
3647 device_config->vp_config[i].fifo.enable =
3648 VXGE_HW_FIFO_ENABLE;
3649 device_config->vp_config[i].fifo.max_frags =
3651 device_config->vp_config[i].fifo.memblock_size =
3652 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3654 txdl_size = device_config->vp_config[i].fifo.max_frags *
3655 sizeof(struct vxge_hw_fifo_txd);
3656 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3658 device_config->vp_config[i].fifo.fifo_blocks =
3659 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3661 device_config->vp_config[i].fifo.intr =
3662 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3664 /* Configure tti properties */
3665 device_config->vp_config[i].tti.intr_enable =
3666 VXGE_HW_TIM_INTR_ENABLE;
3668 device_config->vp_config[i].tti.btimer_val =
3669 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3671 device_config->vp_config[i].tti.timer_ac_en =
3672 VXGE_HW_TIM_TIMER_AC_ENABLE;
3674 /* For msi-x with napi (each vector
3675 has a handler of its own) -
3676 Set CI to OFF for all vpaths */
3677 device_config->vp_config[i].tti.timer_ci_en =
3678 VXGE_HW_TIM_TIMER_CI_DISABLE;
3680 device_config->vp_config[i].tti.timer_ri_en =
3681 VXGE_HW_TIM_TIMER_RI_DISABLE;
3683 device_config->vp_config[i].tti.util_sel =
3684 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3686 device_config->vp_config[i].tti.ltimer_val =
3687 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3689 device_config->vp_config[i].tti.rtimer_val =
3690 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3692 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3693 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3694 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3695 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3696 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3697 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3698 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3700 /* Configure Rx rings */
3701 device_config->vp_config[i].ring.enable =
3702 VXGE_HW_RING_ENABLE;
3704 device_config->vp_config[i].ring.ring_blocks =
3705 VXGE_HW_DEF_RING_BLOCKS;
3706 device_config->vp_config[i].ring.buffer_mode =
3707 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3708 device_config->vp_config[i].ring.rxds_limit =
3709 VXGE_HW_DEF_RING_RXDS_LIMIT;
3710 device_config->vp_config[i].ring.scatter_mode =
3711 VXGE_HW_RING_SCATTER_MODE_A;
3713 /* Configure rti properties */
3714 device_config->vp_config[i].rti.intr_enable =
3715 VXGE_HW_TIM_INTR_ENABLE;
3717 device_config->vp_config[i].rti.btimer_val =
3718 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3720 device_config->vp_config[i].rti.timer_ac_en =
3721 VXGE_HW_TIM_TIMER_AC_ENABLE;
3723 device_config->vp_config[i].rti.timer_ci_en =
3724 VXGE_HW_TIM_TIMER_CI_DISABLE;
3726 device_config->vp_config[i].rti.timer_ri_en =
3727 VXGE_HW_TIM_TIMER_RI_DISABLE;
3729 device_config->vp_config[i].rti.util_sel =
3730 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3732 device_config->vp_config[i].rti.urange_a =
3734 device_config->vp_config[i].rti.urange_b =
3736 device_config->vp_config[i].rti.urange_c =
3738 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3739 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3740 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3741 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3743 device_config->vp_config[i].rti.rtimer_val =
3744 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3746 device_config->vp_config[i].rti.ltimer_val =
3747 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3749 device_config->vp_config[i].rpa_strip_vlan_tag =
3753 driver_config->vpath_per_dev = temp;
3754 return no_of_vpaths;
3757 /* initialize device configuratrions */
3758 static void __devinit vxge_device_config_init(
3759 struct vxge_hw_device_config *device_config,
3762 /* Used for CQRQ/SRQ. */
3763 device_config->dma_blockpool_initial =
3764 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3766 device_config->dma_blockpool_max =
3767 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3769 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3770 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3772 #ifndef CONFIG_PCI_MSI
3773 vxge_debug_init(VXGE_ERR,
3774 "%s: This Kernel does not support "
3775 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3779 /* Configure whether MSI-X or IRQL. */
3780 switch (*intr_type) {
3782 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3786 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3789 /* Timer period between device poll */
3790 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3792 /* Configure mac based steering. */
3793 device_config->rts_mac_en = addr_learn_en;
3795 /* Configure Vpaths */
3796 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3798 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3800 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3801 device_config->dma_blockpool_initial);
3802 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3803 device_config->dma_blockpool_max);
3804 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3805 device_config->intr_mode);
3806 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3807 device_config->device_poll_millis);
3808 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3809 device_config->rts_mac_en);
3810 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3811 device_config->rth_en);
3812 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3813 device_config->rth_it_type);
3816 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3820 vxge_debug_init(VXGE_TRACE,
3821 "%s: %d Vpath(s) opened",
3822 vdev->ndev->name, vdev->no_of_vpath);
3824 switch (vdev->config.intr_type) {
3826 vxge_debug_init(VXGE_TRACE,
3827 "%s: Interrupt type INTA", vdev->ndev->name);
3831 vxge_debug_init(VXGE_TRACE,
3832 "%s: Interrupt type MSI-X", vdev->ndev->name);
3836 if (vdev->config.rth_steering) {
3837 vxge_debug_init(VXGE_TRACE,
3838 "%s: RTH steering enabled for TCP_IPV4",
3841 vxge_debug_init(VXGE_TRACE,
3842 "%s: RTH steering disabled", vdev->ndev->name);
3845 switch (vdev->config.tx_steering_type) {
3847 vxge_debug_init(VXGE_TRACE,
3848 "%s: Tx steering disabled", vdev->ndev->name);
3850 case TX_PRIORITY_STEERING:
3851 vxge_debug_init(VXGE_TRACE,
3852 "%s: Unsupported tx steering option",
3854 vxge_debug_init(VXGE_TRACE,
3855 "%s: Tx steering disabled", vdev->ndev->name);
3856 vdev->config.tx_steering_type = 0;
3858 case TX_VLAN_STEERING:
3859 vxge_debug_init(VXGE_TRACE,
3860 "%s: Unsupported tx steering option",
3862 vxge_debug_init(VXGE_TRACE,
3863 "%s: Tx steering disabled", vdev->ndev->name);
3864 vdev->config.tx_steering_type = 0;
3866 case TX_MULTIQ_STEERING:
3867 vxge_debug_init(VXGE_TRACE,
3868 "%s: Tx multiqueue steering enabled",
3871 case TX_PORT_STEERING:
3872 vxge_debug_init(VXGE_TRACE,
3873 "%s: Tx port steering enabled",
3877 vxge_debug_init(VXGE_ERR,
3878 "%s: Unsupported tx steering type",
3880 vxge_debug_init(VXGE_TRACE,
3881 "%s: Tx steering disabled", vdev->ndev->name);
3882 vdev->config.tx_steering_type = 0;
3885 if (vdev->config.gro_enable) {
3886 vxge_debug_init(VXGE_ERR,
3887 "%s: Generic receive offload enabled",
3890 vxge_debug_init(VXGE_TRACE,
3891 "%s: Generic receive offload disabled",
3894 if (vdev->config.addr_learn_en)
3895 vxge_debug_init(VXGE_TRACE,
3896 "%s: MAC Address learning enabled", vdev->ndev->name);
3898 vxge_debug_init(VXGE_TRACE,
3899 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3901 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3902 if (!vxge_bVALn(vpath_mask, i, 1))
3904 vxge_debug_ll_config(VXGE_TRACE,
3905 "%s: MTU size - %d", vdev->ndev->name,
3906 ((struct __vxge_hw_device *)(vdev->devh))->
3907 config.vp_config[i].mtu);
3908 vxge_debug_init(VXGE_TRACE,
3909 "%s: VLAN tag stripping %s", vdev->ndev->name,
3910 ((struct __vxge_hw_device *)(vdev->devh))->
3911 config.vp_config[i].rpa_strip_vlan_tag
3912 ? "Enabled" : "Disabled");
3913 vxge_debug_init(VXGE_TRACE,
3914 "%s: Ring blocks : %d", vdev->ndev->name,
3915 ((struct __vxge_hw_device *)(vdev->devh))->
3916 config.vp_config[i].ring.ring_blocks);
3917 vxge_debug_init(VXGE_TRACE,
3918 "%s: Fifo blocks : %d", vdev->ndev->name,
3919 ((struct __vxge_hw_device *)(vdev->devh))->
3920 config.vp_config[i].fifo.fifo_blocks);
3921 vxge_debug_ll_config(VXGE_TRACE,
3922 "%s: Max frags : %d", vdev->ndev->name,
3923 ((struct __vxge_hw_device *)(vdev->devh))->
3924 config.vp_config[i].fifo.max_frags);
3931 * vxge_pm_suspend - vxge power management suspend entry point
3934 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3939 * vxge_pm_resume - vxge power management resume entry point
3942 static int vxge_pm_resume(struct pci_dev *pdev)
3950 * vxge_io_error_detected - called when PCI error is detected
3951 * @pdev: Pointer to PCI device
3952 * @state: The current pci connection state
3954 * This function is called after a PCI bus error affecting
3955 * this device has been detected.
3957 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3958 pci_channel_state_t state)
3960 struct __vxge_hw_device *hldev =
3961 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3962 struct net_device *netdev = hldev->ndev;
3964 netif_device_detach(netdev);
3966 if (state == pci_channel_io_perm_failure)
3967 return PCI_ERS_RESULT_DISCONNECT;
3969 if (netif_running(netdev)) {
3970 /* Bring down the card, while avoiding PCI I/O */
3971 do_vxge_close(netdev, 0);
3974 pci_disable_device(pdev);
3976 return PCI_ERS_RESULT_NEED_RESET;
3980 * vxge_io_slot_reset - called after the pci bus has been reset.
3981 * @pdev: Pointer to PCI device
3983 * Restart the card from scratch, as if from a cold-boot.
3984 * At this point, the card has exprienced a hard reset,
3985 * followed by fixups by BIOS, and has its config space
3986 * set up identically to what it was at cold boot.
3988 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3990 struct __vxge_hw_device *hldev =
3991 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3992 struct net_device *netdev = hldev->ndev;
3994 struct vxgedev *vdev = netdev_priv(netdev);
3996 if (pci_enable_device(pdev)) {
3997 netdev_err(netdev, "Cannot re-enable device after reset\n");
3998 return PCI_ERS_RESULT_DISCONNECT;
4001 pci_set_master(pdev);
4004 return PCI_ERS_RESULT_RECOVERED;
4008 * vxge_io_resume - called when traffic can start flowing again.
4009 * @pdev: Pointer to PCI device
4011 * This callback is called when the error recovery driver tells
4012 * us that its OK to resume normal operation.
4014 static void vxge_io_resume(struct pci_dev *pdev)
4016 struct __vxge_hw_device *hldev =
4017 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4018 struct net_device *netdev = hldev->ndev;
4020 if (netif_running(netdev)) {
4021 if (vxge_open(netdev)) {
4023 "Can't bring device back up after reset\n");
4028 netif_device_attach(netdev);
4031 static inline u32 vxge_get_num_vfs(u64 function_mode)
4033 u32 num_functions = 0;
4035 switch (function_mode) {
4036 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4037 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4040 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4043 case VXGE_HW_FUNCTION_MODE_SRIOV:
4044 case VXGE_HW_FUNCTION_MODE_MRIOV:
4045 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4048 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4051 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4054 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4055 num_functions = 8; /* TODO */
4058 return num_functions;
4061 int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4063 struct __vxge_hw_device *hldev = vdev->devh;
4064 u32 maj, min, bld, cmaj, cmin, cbld;
4065 enum vxge_hw_status status;
4066 const struct firmware *fw;
4069 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4071 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4072 VXGE_DRIVER_NAME, fw_name);
4076 /* Load the new firmware onto the adapter */
4077 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4078 if (status != VXGE_HW_OK) {
4079 vxge_debug_init(VXGE_ERR,
4080 "%s: FW image download to adapter failed '%s'.",
4081 VXGE_DRIVER_NAME, fw_name);
4086 /* Read the version of the new firmware */
4087 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4088 if (status != VXGE_HW_OK) {
4089 vxge_debug_init(VXGE_ERR,
4090 "%s: Upgrade read version failed '%s'.",
4091 VXGE_DRIVER_NAME, fw_name);
4096 cmaj = vdev->config.device_hw_info.fw_version.major;
4097 cmin = vdev->config.device_hw_info.fw_version.minor;
4098 cbld = vdev->config.device_hw_info.fw_version.build;
4099 /* It's possible the version in /lib/firmware is not the latest version.
4100 * If so, we could get into a loop of trying to upgrade to the latest
4101 * and flashing the older version.
4103 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4109 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4112 /* Flash the adapter with the new firmware */
4113 status = vxge_hw_flash_fw(hldev);
4114 if (status != VXGE_HW_OK) {
4115 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4116 VXGE_DRIVER_NAME, fw_name);
4121 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4122 "hard reset before using, thus requiring a system reboot or a "
4123 "hotplug event.\n");
4129 static int vxge_probe_fw_update(struct vxgedev *vdev)
4135 maj = vdev->config.device_hw_info.fw_version.major;
4136 min = vdev->config.device_hw_info.fw_version.minor;
4137 bld = vdev->config.device_hw_info.fw_version.build;
4139 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4142 /* Ignore the build number when determining if the current firmware is
4143 * "too new" to load the driver
4145 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4146 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4147 "version, unable to load driver\n",
4152 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4153 * work with this driver.
4155 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4156 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4157 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4161 /* If file not specified, determine gPXE or not */
4162 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4164 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4165 if (vdev->devh->eprom_versions[i]) {
4171 fw_name = "vxge/X3fw-pxe.ncf";
4173 fw_name = "vxge/X3fw.ncf";
4175 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4176 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4177 * probe, so ignore them
4179 if (ret != -EINVAL && ret != -ENOENT)
4184 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4185 VXGE_FW_VER(maj, min, 0)) {
4186 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4187 " be used with this driver.\n"
4188 "Please get the latest version from "
4189 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4190 VXGE_DRIVER_NAME, maj, min, bld);
4199 * @pdev : structure containing the PCI related information of the device.
4200 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4202 * This function is called when a new PCI device gets detected and initializes
4205 * returns 0 on success and negative on failure.
4208 static int __devinit
4209 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4211 struct __vxge_hw_device *hldev;
4212 enum vxge_hw_status status;
4216 struct vxgedev *vdev;
4217 struct vxge_config *ll_config = NULL;
4218 struct vxge_hw_device_config *device_config = NULL;
4219 struct vxge_hw_device_attr attr;
4220 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4222 struct vxge_mac_addrs *entry;
4223 static int bus = -1, device = -1;
4226 enum vxge_hw_status is_privileged;
4230 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4233 /* In SRIOV-17 mode, functions of the same adapter
4234 * can be deployed on different buses */
4235 if ((!pdev->is_virtfn) && ((bus != pdev->bus->number) ||
4236 (device != PCI_SLOT(pdev->devfn))))
4239 bus = pdev->bus->number;
4240 device = PCI_SLOT(pdev->devfn);
4243 if (driver_config->config_dev_cnt &&
4244 (driver_config->config_dev_cnt !=
4245 driver_config->total_dev_cnt))
4246 vxge_debug_init(VXGE_ERR,
4247 "%s: Configured %d of %d devices",
4249 driver_config->config_dev_cnt,
4250 driver_config->total_dev_cnt);
4251 driver_config->config_dev_cnt = 0;
4252 driver_config->total_dev_cnt = 0;
4254 /* Now making the CPU based no of vpath calculation
4255 * applicable for individual functions as well.
4257 driver_config->g_no_cpus = 0;
4258 driver_config->vpath_per_dev = max_config_vpath;
4260 driver_config->total_dev_cnt++;
4261 if (++driver_config->config_dev_cnt > max_config_dev) {
4266 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4268 if (!device_config) {
4270 vxge_debug_init(VXGE_ERR,
4271 "device_config : malloc failed %s %d",
4272 __FILE__, __LINE__);
4276 ll_config = kzalloc(sizeof(*ll_config), GFP_KERNEL);
4279 vxge_debug_init(VXGE_ERR,
4280 "ll_config : malloc failed %s %d",
4281 __FILE__, __LINE__);
4284 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4285 ll_config->intr_type = MSI_X;
4286 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4287 ll_config->rth_steering = RTH_STEERING;
4289 /* get the default configuration parameters */
4290 vxge_hw_device_config_default_get(device_config);
4292 /* initialize configuration parameters */
4293 vxge_device_config_init(device_config, &ll_config->intr_type);
4295 ret = pci_enable_device(pdev);
4297 vxge_debug_init(VXGE_ERR,
4298 "%s : can not enable PCI device", __func__);
4302 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
4303 vxge_debug_ll_config(VXGE_TRACE,
4304 "%s : using 64bit DMA", __func__);
4308 if (pci_set_consistent_dma_mask(pdev,
4309 DMA_BIT_MASK(64))) {
4310 vxge_debug_init(VXGE_ERR,
4311 "%s : unable to obtain 64bit DMA for "
4312 "consistent allocations", __func__);
4316 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
4317 vxge_debug_ll_config(VXGE_TRACE,
4318 "%s : using 32bit DMA", __func__);
4324 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4325 vxge_debug_init(VXGE_ERR,
4326 "%s : request regions failed", __func__);
4331 pci_set_master(pdev);
4333 attr.bar0 = pci_ioremap_bar(pdev, 0);
4335 vxge_debug_init(VXGE_ERR,
4336 "%s : cannot remap io memory bar0", __func__);
4340 vxge_debug_ll_config(VXGE_TRACE,
4341 "pci ioremap bar0: %p:0x%llx",
4343 (unsigned long long)pci_resource_start(pdev, 0));
4345 status = vxge_hw_device_hw_info_get(attr.bar0,
4346 &ll_config->device_hw_info);
4347 if (status != VXGE_HW_OK) {
4348 vxge_debug_init(VXGE_ERR,
4349 "%s: Reading of hardware info failed."
4350 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4355 vpath_mask = ll_config->device_hw_info.vpath_mask;
4356 if (vpath_mask == 0) {
4357 vxge_debug_ll_config(VXGE_TRACE,
4358 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4363 vxge_debug_ll_config(VXGE_TRACE,
4364 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4365 (unsigned long long)vpath_mask);
4367 function_mode = ll_config->device_hw_info.function_mode;
4368 host_type = ll_config->device_hw_info.host_type;
4369 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4370 ll_config->device_hw_info.func_id);
4372 /* Check how many vpaths are available */
4373 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4374 if (!((vpath_mask) & vxge_mBIT(i)))
4376 max_vpath_supported++;
4380 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4382 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4383 if (is_sriov(function_mode) && (max_config_dev > 1) &&
4384 (ll_config->intr_type != INTA) &&
4385 (is_privileged == VXGE_HW_OK)) {
4386 ret = pci_enable_sriov(pdev, ((max_config_dev - 1) < num_vfs)
4387 ? (max_config_dev - 1) : num_vfs);
4389 vxge_debug_ll_config(VXGE_ERR,
4390 "Failed in enabling SRIOV mode: %d\n", ret);
4394 * Configure vpaths and get driver configured number of vpaths
4395 * which is less than or equal to the maximum vpaths per function.
4397 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
4399 vxge_debug_ll_config(VXGE_ERR,
4400 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4405 /* Setting driver callbacks */
4406 attr.uld_callbacks.link_up = vxge_callback_link_up;
4407 attr.uld_callbacks.link_down = vxge_callback_link_down;
4408 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4410 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4411 if (status != VXGE_HW_OK) {
4412 vxge_debug_init(VXGE_ERR,
4413 "Failed to initialize device (%d)", status);
4418 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4419 ll_config->device_hw_info.fw_version.minor,
4420 ll_config->device_hw_info.fw_version.build) >=
4421 VXGE_EPROM_FW_VER) {
4422 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4424 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4425 if (status != VXGE_HW_OK) {
4426 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4428 /* This is a non-fatal error, continue */
4431 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4432 hldev->eprom_versions[i] = img[i].version;
4433 if (!img[i].is_valid)
4435 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
4436 "%d.%d.%d.%d\n", VXGE_DRIVER_NAME, i,
4437 VXGE_EPROM_IMG_MAJOR(img[i].version),
4438 VXGE_EPROM_IMG_MINOR(img[i].version),
4439 VXGE_EPROM_IMG_FIX(img[i].version),
4440 VXGE_EPROM_IMG_BUILD(img[i].version));
4444 /* if FCS stripping is not disabled in MAC fail driver load */
4445 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4446 if (status != VXGE_HW_OK) {
4447 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4448 " failing driver load", VXGE_DRIVER_NAME);
4453 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4455 /* set private device info */
4456 pci_set_drvdata(pdev, hldev);
4458 ll_config->gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4459 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4460 ll_config->addr_learn_en = addr_learn_en;
4461 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4462 ll_config->rth_hash_type_tcpipv4 = 1;
4463 ll_config->rth_hash_type_ipv4 = 0;
4464 ll_config->rth_hash_type_tcpipv6 = 0;
4465 ll_config->rth_hash_type_ipv6 = 0;
4466 ll_config->rth_hash_type_tcpipv6ex = 0;
4467 ll_config->rth_hash_type_ipv6ex = 0;
4468 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4469 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4470 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4472 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4479 ret = vxge_probe_fw_update(vdev);
4483 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4484 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4485 vxge_hw_device_trace_level_get(hldev));
4487 /* set private HW device info */
4488 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4489 vdev->bar0 = attr.bar0;
4490 vdev->max_vpath_supported = max_vpath_supported;
4491 vdev->no_of_vpath = no_of_vpath;
4493 /* Virtual Path count */
4494 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4495 if (!vxge_bVALn(vpath_mask, i, 1))
4497 if (j >= vdev->no_of_vpath)
4500 vdev->vpaths[j].is_configured = 1;
4501 vdev->vpaths[j].device_id = i;
4502 vdev->vpaths[j].ring.driver_id = j;
4503 vdev->vpaths[j].vdev = vdev;
4504 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4505 memcpy((u8 *)vdev->vpaths[j].macaddr,
4506 ll_config->device_hw_info.mac_addrs[i],
4509 /* Initialize the mac address list header */
4510 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4512 vdev->vpaths[j].mac_addr_cnt = 0;
4513 vdev->vpaths[j].mcast_addr_cnt = 0;
4516 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4517 vdev->max_config_port = max_config_port;
4519 vdev->vlan_tag_strip = vlan_tag_strip;
4521 /* map the hashing selector table to the configured vpaths */
4522 for (i = 0; i < vdev->no_of_vpath; i++)
4523 vdev->vpath_selector[i] = vpath_selector[i];
4525 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4527 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4528 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4529 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4531 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4532 vdev->ndev->name, ll_config->device_hw_info.serial_number);
4534 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4535 vdev->ndev->name, ll_config->device_hw_info.part_number);
4537 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4538 vdev->ndev->name, ll_config->device_hw_info.product_desc);
4540 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4541 vdev->ndev->name, macaddr);
4543 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4544 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4546 vxge_debug_init(VXGE_TRACE,
4547 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4548 ll_config->device_hw_info.fw_version.version,
4549 ll_config->device_hw_info.fw_date.date);
4552 switch (ll_config->device_hw_info.function_mode) {
4553 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4554 vxge_debug_init(VXGE_TRACE,
4555 "%s: Single Function Mode Enabled", vdev->ndev->name);
4557 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4558 vxge_debug_init(VXGE_TRACE,
4559 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4561 case VXGE_HW_FUNCTION_MODE_SRIOV:
4562 vxge_debug_init(VXGE_TRACE,
4563 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4565 case VXGE_HW_FUNCTION_MODE_MRIOV:
4566 vxge_debug_init(VXGE_TRACE,
4567 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4572 vxge_print_parm(vdev, vpath_mask);
4574 /* Store the fw version for ethttool option */
4575 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
4576 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4577 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4579 /* Copy the station mac address to the list */
4580 for (i = 0; i < vdev->no_of_vpath; i++) {
4581 entry = (struct vxge_mac_addrs *)
4582 kzalloc(sizeof(struct vxge_mac_addrs),
4584 if (NULL == entry) {
4585 vxge_debug_init(VXGE_ERR,
4586 "%s: mac_addr_list : memory allocation failed",
4591 macaddr = (u8 *)&entry->macaddr;
4592 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4593 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4594 vdev->vpaths[i].mac_addr_cnt = 1;
4597 kfree(device_config);
4600 * INTA is shared in multi-function mode. This is unlike the INTA
4601 * implementation in MR mode, where each VH has its own INTA message.
4602 * - INTA is masked (disabled) as long as at least one function sets
4603 * its TITAN_MASK_ALL_INT.ALARM bit.
4604 * - INTA is unmasked (enabled) when all enabled functions have cleared
4605 * their own TITAN_MASK_ALL_INT.ALARM bit.
4606 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4607 * Though this driver leaves the top level interrupts unmasked while
4608 * leaving the required module interrupt bits masked on exit, there
4609 * could be a rougue driver around that does not follow this procedure
4610 * resulting in a failure to generate interrupts. The following code is
4611 * present to prevent such a failure.
4614 if (ll_config->device_hw_info.function_mode ==
4615 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4616 if (vdev->config.intr_type == INTA)
4617 vxge_hw_device_unmask_all(hldev);
4619 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4620 vdev->ndev->name, __func__, __LINE__);
4622 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4623 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4624 vxge_hw_device_trace_level_get(hldev));
4630 for (i = 0; i < vdev->no_of_vpath; i++)
4631 vxge_free_mac_add_list(&vdev->vpaths[i]);
4633 vxge_device_unregister(hldev);
4635 pci_disable_sriov(pdev);
4636 vxge_hw_device_terminate(hldev);
4640 pci_release_regions(pdev);
4642 pci_disable_device(pdev);
4645 kfree(device_config);
4646 driver_config->config_dev_cnt--;
4647 pci_set_drvdata(pdev, NULL);
4652 * vxge_rem_nic - Free the PCI device
4653 * @pdev: structure containing the PCI related information of the device.
4654 * Description: This function is called by the Pci subsystem to release a
4655 * PCI device and free up all resource held up by the device.
4657 static void __devexit
4658 vxge_remove(struct pci_dev *pdev)
4660 struct __vxge_hw_device *hldev;
4661 struct vxgedev *vdev = NULL;
4662 struct net_device *dev;
4664 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4665 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4669 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4674 vdev = netdev_priv(dev);
4676 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4677 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4678 level_trace = vdev->level_trace;
4680 vxge_debug_entryexit(level_trace,
4681 "%s:%d", __func__, __LINE__);
4683 vxge_debug_init(level_trace,
4684 "%s : removing PCI device...", __func__);
4685 vxge_device_unregister(hldev);
4687 for (i = 0; i < vdev->no_of_vpath; i++) {
4688 vxge_free_mac_add_list(&vdev->vpaths[i]);
4689 vdev->vpaths[i].mcast_addr_cnt = 0;
4690 vdev->vpaths[i].mac_addr_cnt = 0;
4693 kfree(vdev->vpaths);
4695 iounmap(vdev->bar0);
4697 pci_disable_sriov(pdev);
4699 /* we are safe to free it now */
4702 vxge_debug_init(level_trace,
4703 "%s:%d Device unregistered", __func__, __LINE__);
4705 vxge_hw_device_terminate(hldev);
4707 pci_disable_device(pdev);
4708 pci_release_regions(pdev);
4709 pci_set_drvdata(pdev, NULL);
4710 vxge_debug_entryexit(level_trace,
4711 "%s:%d Exiting...", __func__, __LINE__);
4714 static struct pci_error_handlers vxge_err_handler = {
4715 .error_detected = vxge_io_error_detected,
4716 .slot_reset = vxge_io_slot_reset,
4717 .resume = vxge_io_resume,
4720 static struct pci_driver vxge_driver = {
4721 .name = VXGE_DRIVER_NAME,
4722 .id_table = vxge_id_table,
4723 .probe = vxge_probe,
4724 .remove = __devexit_p(vxge_remove),
4726 .suspend = vxge_pm_suspend,
4727 .resume = vxge_pm_resume,
4729 .err_handler = &vxge_err_handler,
4737 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4738 pr_info("Driver version: %s\n", DRV_VERSION);
4742 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4746 ret = pci_register_driver(&vxge_driver);
4748 if (driver_config->config_dev_cnt &&
4749 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4750 vxge_debug_init(VXGE_ERR,
4751 "%s: Configured %d of %d devices",
4752 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4753 driver_config->total_dev_cnt);
4756 kfree(driver_config);
4764 pci_unregister_driver(&vxge_driver);
4765 kfree(driver_config);
4767 module_init(vxge_starter);
4768 module_exit(vxge_closer);