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 inline int is_vxge_card_up(struct vxgedev *vdev)
89 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
92 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
94 struct sk_buff **skb_ptr = NULL;
95 struct sk_buff **temp;
96 #define NR_SKB_COMPLETED 128
97 struct sk_buff *completed[NR_SKB_COMPLETED];
104 if (__netif_tx_trylock(fifo->txq)) {
105 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
106 NR_SKB_COMPLETED, &more);
107 __netif_tx_unlock(fifo->txq);
111 for (temp = completed; temp != skb_ptr; temp++)
112 dev_kfree_skb_irq(*temp);
116 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
120 /* Complete all transmits */
121 for (i = 0; i < vdev->no_of_vpath; i++)
122 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
125 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
128 struct vxge_ring *ring;
130 /* Complete all receives*/
131 for (i = 0; i < vdev->no_of_vpath; i++) {
132 ring = &vdev->vpaths[i].ring;
133 vxge_hw_vpath_poll_rx(ring->handle);
138 * vxge_callback_link_up
140 * This function is called during interrupt context to notify link up state
143 static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
145 struct net_device *dev = hldev->ndev;
146 struct vxgedev *vdev = netdev_priv(dev);
148 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
149 vdev->ndev->name, __func__, __LINE__);
150 netdev_notice(vdev->ndev, "Link Up\n");
151 vdev->stats.link_up++;
153 netif_carrier_on(vdev->ndev);
154 netif_tx_wake_all_queues(vdev->ndev);
156 vxge_debug_entryexit(VXGE_TRACE,
157 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
161 * vxge_callback_link_down
163 * This function is called during interrupt context to notify link down state
166 static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
168 struct net_device *dev = hldev->ndev;
169 struct vxgedev *vdev = netdev_priv(dev);
171 vxge_debug_entryexit(VXGE_TRACE,
172 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
173 netdev_notice(vdev->ndev, "Link Down\n");
175 vdev->stats.link_down++;
176 netif_carrier_off(vdev->ndev);
177 netif_tx_stop_all_queues(vdev->ndev);
179 vxge_debug_entryexit(VXGE_TRACE,
180 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
188 static struct sk_buff *
189 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
191 struct net_device *dev;
193 struct vxge_rx_priv *rx_priv;
196 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
197 ring->ndev->name, __func__, __LINE__);
199 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
201 /* try to allocate skb first. this one may fail */
202 skb = netdev_alloc_skb(dev, skb_size +
203 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
205 vxge_debug_mem(VXGE_ERR,
206 "%s: out of memory to allocate SKB", dev->name);
207 ring->stats.skb_alloc_fail++;
211 vxge_debug_mem(VXGE_TRACE,
212 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
213 __func__, __LINE__, skb);
215 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
218 rx_priv->skb_data = NULL;
219 rx_priv->data_size = skb_size;
220 vxge_debug_entryexit(VXGE_TRACE,
221 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
229 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
231 struct vxge_rx_priv *rx_priv;
234 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
235 ring->ndev->name, __func__, __LINE__);
236 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
238 rx_priv->skb_data = rx_priv->skb->data;
239 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
240 rx_priv->data_size, PCI_DMA_FROMDEVICE);
242 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
243 ring->stats.pci_map_fail++;
246 vxge_debug_mem(VXGE_TRACE,
247 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
248 ring->ndev->name, __func__, __LINE__,
249 (unsigned long long)dma_addr);
250 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
252 rx_priv->data_dma = dma_addr;
253 vxge_debug_entryexit(VXGE_TRACE,
254 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
260 * vxge_rx_initial_replenish
261 * Allocation of RxD as an initial replenish procedure.
263 static enum vxge_hw_status
264 vxge_rx_initial_replenish(void *dtrh, void *userdata)
266 struct vxge_ring *ring = (struct vxge_ring *)userdata;
267 struct vxge_rx_priv *rx_priv;
269 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
270 ring->ndev->name, __func__, __LINE__);
271 if (vxge_rx_alloc(dtrh, ring,
272 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
275 if (vxge_rx_map(dtrh, ring)) {
276 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
277 dev_kfree_skb(rx_priv->skb);
281 vxge_debug_entryexit(VXGE_TRACE,
282 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
288 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
289 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
292 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
293 ring->ndev->name, __func__, __LINE__);
294 skb_record_rx_queue(skb, ring->driver_id);
295 skb->protocol = eth_type_trans(skb, ring->ndev);
297 ring->stats.rx_frms++;
298 ring->stats.rx_bytes += pkt_length;
300 if (skb->pkt_type == PACKET_MULTICAST)
301 ring->stats.rx_mcast++;
303 vxge_debug_rx(VXGE_TRACE,
304 "%s: %s:%d skb protocol = %d",
305 ring->ndev->name, __func__, __LINE__, skb->protocol);
307 if (ring->gro_enable) {
308 if (ring->vlgrp && ext_info->vlan &&
309 (ring->vlan_tag_strip ==
310 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
311 vlan_gro_receive(ring->napi_p, ring->vlgrp,
312 ext_info->vlan, skb);
314 napi_gro_receive(ring->napi_p, skb);
316 if (ring->vlgrp && vlan &&
317 (ring->vlan_tag_strip ==
318 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
319 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
321 netif_receive_skb(skb);
323 vxge_debug_entryexit(VXGE_TRACE,
324 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
327 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
328 struct vxge_rx_priv *rx_priv)
330 pci_dma_sync_single_for_device(ring->pdev,
331 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
333 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
334 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
337 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
338 void *post_dtr, struct __vxge_hw_ring *ringh)
340 int dtr_count = *dtr_cnt;
341 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
343 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
344 *first_dtr = post_dtr;
346 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
348 *dtr_cnt = dtr_count;
354 * If the interrupt is because of a received frame or if the receive ring
355 * contains fresh as yet un-processed frames, this function is called.
357 static enum vxge_hw_status
358 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
359 u8 t_code, void *userdata)
361 struct vxge_ring *ring = (struct vxge_ring *)userdata;
362 struct net_device *dev = ring->ndev;
363 unsigned int dma_sizes;
364 void *first_dtr = NULL;
370 struct vxge_rx_priv *rx_priv;
371 struct vxge_hw_ring_rxd_info ext_info;
372 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
373 ring->ndev->name, __func__, __LINE__);
374 ring->pkts_processed = 0;
376 vxge_hw_ring_replenish(ringh);
379 prefetch((char *)dtr + L1_CACHE_BYTES);
380 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
382 data_size = rx_priv->data_size;
383 data_dma = rx_priv->data_dma;
384 prefetch(rx_priv->skb_data);
386 vxge_debug_rx(VXGE_TRACE,
387 "%s: %s:%d skb = 0x%p",
388 ring->ndev->name, __func__, __LINE__, skb);
390 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
391 pkt_length = dma_sizes;
393 pkt_length -= ETH_FCS_LEN;
395 vxge_debug_rx(VXGE_TRACE,
396 "%s: %s:%d Packet Length = %d",
397 ring->ndev->name, __func__, __LINE__, pkt_length);
399 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
401 /* check skb validity */
404 prefetch((char *)skb + L1_CACHE_BYTES);
405 if (unlikely(t_code)) {
406 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
409 ring->stats.rx_errors++;
410 vxge_debug_rx(VXGE_TRACE,
411 "%s: %s :%d Rx T_code is %d",
412 ring->ndev->name, __func__,
415 /* If the t_code is not supported and if the
416 * t_code is other than 0x5 (unparseable packet
417 * such as unknown UPV6 header), Drop it !!!
419 vxge_re_pre_post(dtr, ring, rx_priv);
421 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
422 ring->stats.rx_dropped++;
427 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
428 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
429 if (!vxge_rx_map(dtr, ring)) {
430 skb_put(skb, pkt_length);
432 pci_unmap_single(ring->pdev, data_dma,
433 data_size, PCI_DMA_FROMDEVICE);
435 vxge_hw_ring_rxd_pre_post(ringh, dtr);
436 vxge_post(&dtr_cnt, &first_dtr, dtr,
439 dev_kfree_skb(rx_priv->skb);
441 rx_priv->data_size = data_size;
442 vxge_re_pre_post(dtr, ring, rx_priv);
444 vxge_post(&dtr_cnt, &first_dtr, dtr,
446 ring->stats.rx_dropped++;
450 vxge_re_pre_post(dtr, ring, rx_priv);
452 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
453 ring->stats.rx_dropped++;
457 struct sk_buff *skb_up;
459 skb_up = netdev_alloc_skb(dev, pkt_length +
460 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
461 if (skb_up != NULL) {
463 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
465 pci_dma_sync_single_for_cpu(ring->pdev,
469 vxge_debug_mem(VXGE_TRACE,
470 "%s: %s:%d skb_up = %p",
471 ring->ndev->name, __func__,
473 memcpy(skb_up->data, skb->data, pkt_length);
475 vxge_re_pre_post(dtr, ring, rx_priv);
477 vxge_post(&dtr_cnt, &first_dtr, dtr,
479 /* will netif_rx small SKB instead */
481 skb_put(skb, pkt_length);
483 vxge_re_pre_post(dtr, ring, rx_priv);
485 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
486 vxge_debug_rx(VXGE_ERR,
487 "%s: vxge_rx_1b_compl: out of "
488 "memory", dev->name);
489 ring->stats.skb_alloc_fail++;
494 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
495 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
496 ring->rx_csum && /* Offload Rx side CSUM */
497 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
498 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
499 skb->ip_summed = CHECKSUM_UNNECESSARY;
501 skb_checksum_none_assert(skb);
505 struct skb_shared_hwtstamps *skb_hwts;
506 u32 ns = *(u32 *)(skb->head + pkt_length);
508 skb_hwts = skb_hwtstamps(skb);
509 skb_hwts->hwtstamp = ns_to_ktime(ns);
510 skb_hwts->syststamp.tv64 = 0;
513 /* rth_hash_type and rth_it_hit are non-zero regardless of
514 * whether rss is enabled. Only the rth_value is zero/non-zero
515 * if rss is disabled/enabled, so key off of that.
517 if (ext_info.rth_value)
518 skb->rxhash = ext_info.rth_value;
520 vxge_rx_complete(ring, skb, ext_info.vlan,
521 pkt_length, &ext_info);
524 ring->pkts_processed++;
528 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
529 &t_code) == VXGE_HW_OK);
532 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
534 vxge_debug_entryexit(VXGE_TRACE,
543 * If an interrupt was raised to indicate DMA complete of the Tx packet,
544 * this function is called. It identifies the last TxD whose buffer was
545 * freed and frees all skbs whose data have already DMA'ed into the NICs
548 static enum vxge_hw_status
549 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
550 enum vxge_hw_fifo_tcode t_code, void *userdata,
551 struct sk_buff ***skb_ptr, int nr_skb, int *more)
553 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
554 struct sk_buff *skb, **done_skb = *skb_ptr;
557 vxge_debug_entryexit(VXGE_TRACE,
558 "%s:%d Entered....", __func__, __LINE__);
564 struct vxge_tx_priv *txd_priv =
565 vxge_hw_fifo_txdl_private_get(dtr);
568 frg_cnt = skb_shinfo(skb)->nr_frags;
569 frag = &skb_shinfo(skb)->frags[0];
571 vxge_debug_tx(VXGE_TRACE,
572 "%s: %s:%d fifo_hw = %p dtr = %p "
573 "tcode = 0x%x", fifo->ndev->name, __func__,
574 __LINE__, fifo_hw, dtr, t_code);
575 /* check skb validity */
577 vxge_debug_tx(VXGE_TRACE,
578 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
579 fifo->ndev->name, __func__, __LINE__,
580 skb, txd_priv, frg_cnt);
581 if (unlikely(t_code)) {
582 fifo->stats.tx_errors++;
583 vxge_debug_tx(VXGE_ERR,
584 "%s: tx: dtr %p completed due to "
585 "error t_code %01x", fifo->ndev->name,
587 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
590 /* for unfragmented skb */
591 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
592 skb_headlen(skb), PCI_DMA_TODEVICE);
594 for (j = 0; j < frg_cnt; j++) {
595 pci_unmap_page(fifo->pdev,
596 txd_priv->dma_buffers[i++],
597 frag->size, PCI_DMA_TODEVICE);
601 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
603 /* Updating the statistics block */
604 fifo->stats.tx_frms++;
605 fifo->stats.tx_bytes += skb->len;
615 if (pkt_cnt > fifo->indicate_max_pkts)
618 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
619 &dtr, &t_code) == VXGE_HW_OK);
622 if (netif_tx_queue_stopped(fifo->txq))
623 netif_tx_wake_queue(fifo->txq);
625 vxge_debug_entryexit(VXGE_TRACE,
626 "%s: %s:%d Exiting...",
627 fifo->ndev->name, __func__, __LINE__);
631 /* select a vpath to transmit the packet */
632 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
634 u16 queue_len, counter = 0;
635 if (skb->protocol == htons(ETH_P_IP)) {
641 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
642 th = (struct tcphdr *)(((unsigned char *)ip) +
645 queue_len = vdev->no_of_vpath;
646 counter = (ntohs(th->source) +
648 vdev->vpath_selector[queue_len - 1];
649 if (counter >= queue_len)
650 counter = queue_len - 1;
656 static enum vxge_hw_status vxge_search_mac_addr_in_list(
657 struct vxge_vpath *vpath, u64 del_mac)
659 struct list_head *entry, *next;
660 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
661 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
667 static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
669 struct vxge_mac_addrs *new_mac_entry;
670 u8 *mac_address = NULL;
672 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
675 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
676 if (!new_mac_entry) {
677 vxge_debug_mem(VXGE_ERR,
678 "%s: memory allocation failed",
683 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
685 /* Copy the new mac address to the list */
686 mac_address = (u8 *)&new_mac_entry->macaddr;
687 memcpy(mac_address, mac->macaddr, ETH_ALEN);
689 new_mac_entry->state = mac->state;
690 vpath->mac_addr_cnt++;
692 /* Is this a multicast address */
693 if (0x01 & mac->macaddr[0])
694 vpath->mcast_addr_cnt++;
699 /* Add a mac address to DA table */
700 static enum vxge_hw_status
701 vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
703 enum vxge_hw_status status = VXGE_HW_OK;
704 struct vxge_vpath *vpath;
705 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
707 if (0x01 & mac->macaddr[0]) /* multicast address */
708 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
710 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
712 vpath = &vdev->vpaths[mac->vpath_no];
713 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
714 mac->macmask, duplicate_mode);
715 if (status != VXGE_HW_OK) {
716 vxge_debug_init(VXGE_ERR,
717 "DA config add entry failed for vpath:%d",
720 if (FALSE == vxge_mac_list_add(vpath, mac))
726 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
728 struct macInfo mac_info;
729 u8 *mac_address = NULL;
730 u64 mac_addr = 0, vpath_vector = 0;
732 enum vxge_hw_status status = VXGE_HW_OK;
733 struct vxge_vpath *vpath = NULL;
734 struct __vxge_hw_device *hldev;
736 hldev = pci_get_drvdata(vdev->pdev);
738 mac_address = (u8 *)&mac_addr;
739 memcpy(mac_address, mac_header, ETH_ALEN);
741 /* Is this mac address already in the list? */
742 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
743 vpath = &vdev->vpaths[vpath_idx];
744 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
748 memset(&mac_info, 0, sizeof(struct macInfo));
749 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
751 /* Any vpath has room to add mac address to its da table? */
752 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
753 vpath = &vdev->vpaths[vpath_idx];
754 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
755 /* Add this mac address to this vpath */
756 mac_info.vpath_no = vpath_idx;
757 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
758 status = vxge_add_mac_addr(vdev, &mac_info);
759 if (status != VXGE_HW_OK)
765 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
767 mac_info.vpath_no = vpath_idx;
768 /* Is the first vpath already selected as catch-basin ? */
769 vpath = &vdev->vpaths[vpath_idx];
770 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
771 /* Add this mac address to this vpath */
772 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
777 /* Select first vpath as catch-basin */
778 vpath_vector = vxge_mBIT(vpath->device_id);
779 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
780 vxge_hw_mgmt_reg_type_mrpcim,
783 struct vxge_hw_mrpcim_reg,
786 if (status != VXGE_HW_OK) {
787 vxge_debug_tx(VXGE_ERR,
788 "%s: Unable to set the vpath-%d in catch-basin mode",
789 VXGE_DRIVER_NAME, vpath->device_id);
793 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
801 * @skb : the socket buffer containing the Tx data.
802 * @dev : device pointer.
804 * This function is the Tx entry point of the driver. Neterion NIC supports
805 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
808 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
810 struct vxge_fifo *fifo = NULL;
813 struct vxgedev *vdev = NULL;
814 enum vxge_hw_status status;
815 int frg_cnt, first_frg_len;
817 int i = 0, j = 0, avail;
819 struct vxge_tx_priv *txdl_priv = NULL;
820 struct __vxge_hw_fifo *fifo_hw;
824 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
825 dev->name, __func__, __LINE__);
827 /* A buffer with no data will be dropped */
828 if (unlikely(skb->len <= 0)) {
829 vxge_debug_tx(VXGE_ERR,
830 "%s: Buffer has no data..", dev->name);
835 vdev = netdev_priv(dev);
837 if (unlikely(!is_vxge_card_up(vdev))) {
838 vxge_debug_tx(VXGE_ERR,
839 "%s: vdev not initialized", dev->name);
844 if (vdev->config.addr_learn_en) {
845 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
846 if (vpath_no == -EPERM) {
847 vxge_debug_tx(VXGE_ERR,
848 "%s: Failed to store the mac address",
855 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
856 vpath_no = skb_get_queue_mapping(skb);
857 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
858 vpath_no = vxge_get_vpath_no(vdev, skb);
860 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
862 if (vpath_no >= vdev->no_of_vpath)
865 fifo = &vdev->vpaths[vpath_no].fifo;
866 fifo_hw = fifo->handle;
868 if (netif_tx_queue_stopped(fifo->txq))
869 return NETDEV_TX_BUSY;
871 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
873 vxge_debug_tx(VXGE_ERR,
874 "%s: No free TXDs available", dev->name);
875 fifo->stats.txd_not_free++;
879 /* Last TXD? Stop tx queue to avoid dropping packets. TX
880 * completion will resume the queue.
883 netif_tx_stop_queue(fifo->txq);
885 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
886 if (unlikely(status != VXGE_HW_OK)) {
887 vxge_debug_tx(VXGE_ERR,
888 "%s: Out of descriptors .", dev->name);
889 fifo->stats.txd_out_of_desc++;
893 vxge_debug_tx(VXGE_TRACE,
894 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
895 dev->name, __func__, __LINE__,
896 fifo_hw, dtr, dtr_priv);
898 if (vlan_tx_tag_present(skb)) {
899 u16 vlan_tag = vlan_tx_tag_get(skb);
900 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
903 first_frg_len = skb_headlen(skb);
905 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
908 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
909 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
910 fifo->stats.pci_map_fail++;
914 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
915 txdl_priv->skb = skb;
916 txdl_priv->dma_buffers[j] = dma_pointer;
918 frg_cnt = skb_shinfo(skb)->nr_frags;
919 vxge_debug_tx(VXGE_TRACE,
920 "%s: %s:%d skb = %p txdl_priv = %p "
921 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
922 __func__, __LINE__, skb, txdl_priv,
923 frg_cnt, (unsigned long long)dma_pointer);
925 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
928 frag = &skb_shinfo(skb)->frags[0];
929 for (i = 0; i < frg_cnt; i++) {
930 /* ignore 0 length fragment */
934 dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
935 frag->page_offset, frag->size,
938 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
940 vxge_debug_tx(VXGE_TRACE,
941 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
942 dev->name, __func__, __LINE__, i,
943 (unsigned long long)dma_pointer);
945 txdl_priv->dma_buffers[j] = dma_pointer;
946 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
951 offload_type = vxge_offload_type(skb);
953 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
954 int mss = vxge_tcp_mss(skb);
956 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
957 dev->name, __func__, __LINE__, mss);
958 vxge_hw_fifo_txdl_mss_set(dtr, mss);
960 vxge_assert(skb->len <=
961 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
967 if (skb->ip_summed == CHECKSUM_PARTIAL)
968 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
969 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
970 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
971 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
973 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
975 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
976 dev->name, __func__, __LINE__);
980 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
983 frag = &skb_shinfo(skb)->frags[0];
985 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
986 skb_headlen(skb), PCI_DMA_TODEVICE);
989 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
990 frag->size, PCI_DMA_TODEVICE);
994 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
996 netif_tx_stop_queue(fifo->txq);
1005 * Function will be called by hw function to abort all outstanding receive
1009 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1011 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1012 struct vxge_rx_priv *rx_priv =
1013 vxge_hw_ring_rxd_private_get(dtrh);
1015 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1016 ring->ndev->name, __func__, __LINE__);
1017 if (state != VXGE_HW_RXD_STATE_POSTED)
1020 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1021 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1023 dev_kfree_skb(rx_priv->skb);
1024 rx_priv->skb_data = NULL;
1026 vxge_debug_entryexit(VXGE_TRACE,
1027 "%s: %s:%d Exiting...",
1028 ring->ndev->name, __func__, __LINE__);
1034 * Function will be called to abort all outstanding tx descriptors
1037 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1039 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1041 int i = 0, j, frg_cnt;
1042 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1043 struct sk_buff *skb = txd_priv->skb;
1045 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1047 if (state != VXGE_HW_TXDL_STATE_POSTED)
1050 /* check skb validity */
1052 frg_cnt = skb_shinfo(skb)->nr_frags;
1053 frag = &skb_shinfo(skb)->frags[0];
1055 /* for unfragmented skb */
1056 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1057 skb_headlen(skb), PCI_DMA_TODEVICE);
1059 for (j = 0; j < frg_cnt; j++) {
1060 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1061 frag->size, PCI_DMA_TODEVICE);
1067 vxge_debug_entryexit(VXGE_TRACE,
1068 "%s:%d Exiting...", __func__, __LINE__);
1071 static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1073 struct list_head *entry, *next;
1075 u8 *mac_address = (u8 *) (&del_mac);
1077 /* Copy the mac address to delete from the list */
1078 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1080 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1081 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1083 kfree((struct vxge_mac_addrs *)entry);
1084 vpath->mac_addr_cnt--;
1086 /* Is this a multicast address */
1087 if (0x01 & mac->macaddr[0])
1088 vpath->mcast_addr_cnt--;
1096 /* delete a mac address from DA table */
1097 static enum vxge_hw_status
1098 vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1100 enum vxge_hw_status status = VXGE_HW_OK;
1101 struct vxge_vpath *vpath;
1103 vpath = &vdev->vpaths[mac->vpath_no];
1104 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1106 if (status != VXGE_HW_OK) {
1107 vxge_debug_init(VXGE_ERR,
1108 "DA config delete entry failed for vpath:%d",
1111 vxge_mac_list_del(vpath, mac);
1116 * vxge_set_multicast
1117 * @dev: pointer to the device structure
1119 * Entry point for multicast address enable/disable
1120 * This function is a driver entry point which gets called by the kernel
1121 * whenever multicast addresses must be enabled/disabled. This also gets
1122 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1123 * determine, if multicast address must be enabled or if promiscuous mode
1124 * is to be disabled etc.
1126 static void vxge_set_multicast(struct net_device *dev)
1128 struct netdev_hw_addr *ha;
1129 struct vxgedev *vdev;
1130 int i, mcast_cnt = 0;
1131 struct __vxge_hw_device *hldev;
1132 struct vxge_vpath *vpath;
1133 enum vxge_hw_status status = VXGE_HW_OK;
1134 struct macInfo mac_info;
1136 struct vxge_mac_addrs *mac_entry;
1137 struct list_head *list_head;
1138 struct list_head *entry, *next;
1139 u8 *mac_address = NULL;
1141 vxge_debug_entryexit(VXGE_TRACE,
1142 "%s:%d", __func__, __LINE__);
1144 vdev = netdev_priv(dev);
1145 hldev = (struct __vxge_hw_device *)vdev->devh;
1147 if (unlikely(!is_vxge_card_up(vdev)))
1150 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1151 for (i = 0; i < vdev->no_of_vpath; i++) {
1152 vpath = &vdev->vpaths[i];
1153 vxge_assert(vpath->is_open);
1154 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1155 if (status != VXGE_HW_OK)
1156 vxge_debug_init(VXGE_ERR, "failed to enable "
1157 "multicast, status %d", status);
1158 vdev->all_multi_flg = 1;
1160 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1161 for (i = 0; i < vdev->no_of_vpath; i++) {
1162 vpath = &vdev->vpaths[i];
1163 vxge_assert(vpath->is_open);
1164 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1165 if (status != VXGE_HW_OK)
1166 vxge_debug_init(VXGE_ERR, "failed to disable "
1167 "multicast, status %d", status);
1168 vdev->all_multi_flg = 0;
1173 if (!vdev->config.addr_learn_en) {
1174 for (i = 0; i < vdev->no_of_vpath; i++) {
1175 vpath = &vdev->vpaths[i];
1176 vxge_assert(vpath->is_open);
1178 if (dev->flags & IFF_PROMISC)
1179 status = vxge_hw_vpath_promisc_enable(
1182 status = vxge_hw_vpath_promisc_disable(
1184 if (status != VXGE_HW_OK)
1185 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1186 ", status %d", dev->flags&IFF_PROMISC ?
1187 "enable" : "disable", status);
1191 memset(&mac_info, 0, sizeof(struct macInfo));
1192 /* Update individual M_CAST address list */
1193 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
1194 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1195 list_head = &vdev->vpaths[0].mac_addr_list;
1196 if ((netdev_mc_count(dev) +
1197 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1198 vdev->vpaths[0].max_mac_addr_cnt)
1199 goto _set_all_mcast;
1201 /* Delete previous MC's */
1202 for (i = 0; i < mcast_cnt; i++) {
1203 list_for_each_safe(entry, next, list_head) {
1204 mac_entry = (struct vxge_mac_addrs *)entry;
1205 /* Copy the mac address to delete */
1206 mac_address = (u8 *)&mac_entry->macaddr;
1207 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1209 /* Is this a multicast address */
1210 if (0x01 & mac_info.macaddr[0]) {
1211 for (vpath_idx = 0; vpath_idx <
1214 mac_info.vpath_no = vpath_idx;
1215 status = vxge_del_mac_addr(
1224 netdev_for_each_mc_addr(ha, dev) {
1225 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
1226 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1228 mac_info.vpath_no = vpath_idx;
1229 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1230 status = vxge_add_mac_addr(vdev, &mac_info);
1231 if (status != VXGE_HW_OK) {
1232 vxge_debug_init(VXGE_ERR,
1233 "%s:%d Setting individual"
1234 "multicast address failed",
1235 __func__, __LINE__);
1236 goto _set_all_mcast;
1243 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1244 /* Delete previous MC's */
1245 for (i = 0; i < mcast_cnt; i++) {
1246 list_for_each_safe(entry, next, list_head) {
1247 mac_entry = (struct vxge_mac_addrs *)entry;
1248 /* Copy the mac address to delete */
1249 mac_address = (u8 *)&mac_entry->macaddr;
1250 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1252 /* Is this a multicast address */
1253 if (0x01 & mac_info.macaddr[0])
1257 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1259 mac_info.vpath_no = vpath_idx;
1260 status = vxge_del_mac_addr(vdev, &mac_info);
1264 /* Enable all multicast */
1265 for (i = 0; i < vdev->no_of_vpath; i++) {
1266 vpath = &vdev->vpaths[i];
1267 vxge_assert(vpath->is_open);
1269 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1270 if (status != VXGE_HW_OK) {
1271 vxge_debug_init(VXGE_ERR,
1272 "%s:%d Enabling all multicasts failed",
1273 __func__, __LINE__);
1275 vdev->all_multi_flg = 1;
1277 dev->flags |= IFF_ALLMULTI;
1280 vxge_debug_entryexit(VXGE_TRACE,
1281 "%s:%d Exiting...", __func__, __LINE__);
1286 * @dev: pointer to the device structure
1288 * Update entry "0" (default MAC addr)
1290 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1292 struct sockaddr *addr = p;
1293 struct vxgedev *vdev;
1294 struct __vxge_hw_device *hldev;
1295 enum vxge_hw_status status = VXGE_HW_OK;
1296 struct macInfo mac_info_new, mac_info_old;
1299 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1301 vdev = netdev_priv(dev);
1304 if (!is_valid_ether_addr(addr->sa_data))
1307 memset(&mac_info_new, 0, sizeof(struct macInfo));
1308 memset(&mac_info_old, 0, sizeof(struct macInfo));
1310 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1311 __func__, __LINE__);
1313 /* Get the old address */
1314 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1316 /* Copy the new address */
1317 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1319 /* First delete the old mac address from all the vpaths
1320 as we can't specify the index while adding new mac address */
1321 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1322 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1323 if (!vpath->is_open) {
1324 /* This can happen when this interface is added/removed
1325 to the bonding interface. Delete this station address
1326 from the linked list */
1327 vxge_mac_list_del(vpath, &mac_info_old);
1329 /* Add this new address to the linked list
1330 for later restoring */
1331 vxge_mac_list_add(vpath, &mac_info_new);
1335 /* Delete the station address */
1336 mac_info_old.vpath_no = vpath_idx;
1337 status = vxge_del_mac_addr(vdev, &mac_info_old);
1340 if (unlikely(!is_vxge_card_up(vdev))) {
1341 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1345 /* Set this mac address to all the vpaths */
1346 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1347 mac_info_new.vpath_no = vpath_idx;
1348 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1349 status = vxge_add_mac_addr(vdev, &mac_info_new);
1350 if (status != VXGE_HW_OK)
1354 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1360 * vxge_vpath_intr_enable
1361 * @vdev: pointer to vdev
1362 * @vp_id: vpath for which to enable the interrupts
1364 * Enables the interrupts for the vpath
1366 static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1368 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1370 int tim_msix_id[4] = {0, 1, 0, 0};
1371 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
1373 vxge_hw_vpath_intr_enable(vpath->handle);
1375 if (vdev->config.intr_type == INTA)
1376 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1378 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1381 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1382 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1383 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1385 /* enable the alarm vector */
1386 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1387 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1388 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1393 * vxge_vpath_intr_disable
1394 * @vdev: pointer to vdev
1395 * @vp_id: vpath for which to disable the interrupts
1397 * Disables the interrupts for the vpath
1399 static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1401 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1402 struct __vxge_hw_device *hldev;
1405 hldev = pci_get_drvdata(vdev->pdev);
1407 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1409 vxge_hw_vpath_intr_disable(vpath->handle);
1411 if (vdev->config.intr_type == INTA)
1412 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1414 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1415 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1416 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1418 /* disable the alarm vector */
1419 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1420 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
1421 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1425 /* list all mac addresses from DA table */
1426 static enum vxge_hw_status
1427 vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1429 enum vxge_hw_status status = VXGE_HW_OK;
1430 unsigned char macmask[ETH_ALEN];
1431 unsigned char macaddr[ETH_ALEN];
1433 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1435 if (status != VXGE_HW_OK) {
1436 vxge_debug_init(VXGE_ERR,
1437 "DA config list entry failed for vpath:%d",
1442 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1443 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1445 if (status != VXGE_HW_OK)
1452 /* Store all mac addresses from the list to the DA table */
1453 static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1455 enum vxge_hw_status status = VXGE_HW_OK;
1456 struct macInfo mac_info;
1457 u8 *mac_address = NULL;
1458 struct list_head *entry, *next;
1460 memset(&mac_info, 0, sizeof(struct macInfo));
1462 if (vpath->is_open) {
1463 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1466 ((struct vxge_mac_addrs *)entry)->macaddr;
1467 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1468 ((struct vxge_mac_addrs *)entry)->state =
1469 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1470 /* does this mac address already exist in da table? */
1471 status = vxge_search_mac_addr_in_da_table(vpath,
1473 if (status != VXGE_HW_OK) {
1474 /* Add this mac address to the DA table */
1475 status = vxge_hw_vpath_mac_addr_add(
1476 vpath->handle, mac_info.macaddr,
1478 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1479 if (status != VXGE_HW_OK) {
1480 vxge_debug_init(VXGE_ERR,
1481 "DA add entry failed for vpath:%d",
1483 ((struct vxge_mac_addrs *)entry)->state
1484 = VXGE_LL_MAC_ADDR_IN_LIST;
1493 /* Store all vlan ids from the list to the vid table */
1494 static enum vxge_hw_status
1495 vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1497 enum vxge_hw_status status = VXGE_HW_OK;
1498 struct vxgedev *vdev = vpath->vdev;
1501 if (vdev->vlgrp && vpath->is_open) {
1503 for (vid = 0; vid < VLAN_N_VID; vid++) {
1504 if (!vlan_group_get_device(vdev->vlgrp, vid))
1506 /* Add these vlan to the vid table */
1507 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1516 * @vdev: pointer to vdev
1517 * @vp_id: vpath to reset
1521 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1523 enum vxge_hw_status status = VXGE_HW_OK;
1524 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1527 /* check if device is down already */
1528 if (unlikely(!is_vxge_card_up(vdev)))
1531 /* is device reset already scheduled */
1532 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1535 if (vpath->handle) {
1536 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1537 if (is_vxge_card_up(vdev) &&
1538 vxge_hw_vpath_recover_from_reset(vpath->handle)
1540 vxge_debug_init(VXGE_ERR,
1541 "vxge_hw_vpath_recover_from_reset"
1542 "failed for vpath:%d", vp_id);
1546 vxge_debug_init(VXGE_ERR,
1547 "vxge_hw_vpath_reset failed for"
1552 return VXGE_HW_FAIL;
1554 vxge_restore_vpath_mac_addr(vpath);
1555 vxge_restore_vpath_vid_table(vpath);
1557 /* Enable all broadcast */
1558 vxge_hw_vpath_bcast_enable(vpath->handle);
1560 /* Enable all multicast */
1561 if (vdev->all_multi_flg) {
1562 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1563 if (status != VXGE_HW_OK)
1564 vxge_debug_init(VXGE_ERR,
1565 "%s:%d Enabling multicast failed",
1566 __func__, __LINE__);
1569 /* Enable the interrupts */
1570 vxge_vpath_intr_enable(vdev, vp_id);
1574 /* Enable the flow of traffic through the vpath */
1575 vxge_hw_vpath_enable(vpath->handle);
1578 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1579 vpath->ring.last_status = VXGE_HW_OK;
1581 /* Vpath reset done */
1582 clear_bit(vp_id, &vdev->vp_reset);
1584 /* Start the vpath queue */
1585 if (netif_tx_queue_stopped(vpath->fifo.txq))
1586 netif_tx_wake_queue(vpath->fifo.txq);
1591 static int do_vxge_reset(struct vxgedev *vdev, int event)
1593 enum vxge_hw_status status;
1594 int ret = 0, vp_id, i;
1596 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1598 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1599 /* check if device is down already */
1600 if (unlikely(!is_vxge_card_up(vdev)))
1603 /* is reset already scheduled */
1604 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1608 if (event == VXGE_LL_FULL_RESET) {
1609 /* wait for all the vpath reset to complete */
1610 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1611 while (test_bit(vp_id, &vdev->vp_reset))
1615 /* if execution mode is set to debug, don't reset the adapter */
1616 if (unlikely(vdev->exec_mode)) {
1617 vxge_debug_init(VXGE_ERR,
1618 "%s: execution mode is debug, returning..",
1620 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1621 netif_tx_stop_all_queues(vdev->ndev);
1626 if (event == VXGE_LL_FULL_RESET) {
1627 vxge_hw_device_wait_receive_idle(vdev->devh);
1628 vxge_hw_device_intr_disable(vdev->devh);
1630 switch (vdev->cric_err_event) {
1631 case VXGE_HW_EVENT_UNKNOWN:
1632 netif_tx_stop_all_queues(vdev->ndev);
1633 vxge_debug_init(VXGE_ERR,
1634 "fatal: %s: Disabling device due to"
1639 case VXGE_HW_EVENT_RESET_START:
1641 case VXGE_HW_EVENT_RESET_COMPLETE:
1642 case VXGE_HW_EVENT_LINK_DOWN:
1643 case VXGE_HW_EVENT_LINK_UP:
1644 case VXGE_HW_EVENT_ALARM_CLEARED:
1645 case VXGE_HW_EVENT_ECCERR:
1646 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1649 case VXGE_HW_EVENT_FIFO_ERR:
1650 case VXGE_HW_EVENT_VPATH_ERR:
1652 case VXGE_HW_EVENT_CRITICAL_ERR:
1653 netif_tx_stop_all_queues(vdev->ndev);
1654 vxge_debug_init(VXGE_ERR,
1655 "fatal: %s: Disabling device due to"
1658 /* SOP or device reset required */
1659 /* This event is not currently used */
1662 case VXGE_HW_EVENT_SERR:
1663 netif_tx_stop_all_queues(vdev->ndev);
1664 vxge_debug_init(VXGE_ERR,
1665 "fatal: %s: Disabling device due to"
1670 case VXGE_HW_EVENT_SRPCIM_SERR:
1671 case VXGE_HW_EVENT_MRPCIM_SERR:
1674 case VXGE_HW_EVENT_SLOT_FREEZE:
1675 netif_tx_stop_all_queues(vdev->ndev);
1676 vxge_debug_init(VXGE_ERR,
1677 "fatal: %s: Disabling device due to"
1688 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1689 netif_tx_stop_all_queues(vdev->ndev);
1691 if (event == VXGE_LL_FULL_RESET) {
1692 status = vxge_reset_all_vpaths(vdev);
1693 if (status != VXGE_HW_OK) {
1694 vxge_debug_init(VXGE_ERR,
1695 "fatal: %s: can not reset vpaths",
1702 if (event == VXGE_LL_COMPL_RESET) {
1703 for (i = 0; i < vdev->no_of_vpath; i++)
1704 if (vdev->vpaths[i].handle) {
1705 if (vxge_hw_vpath_recover_from_reset(
1706 vdev->vpaths[i].handle)
1708 vxge_debug_init(VXGE_ERR,
1709 "vxge_hw_vpath_recover_"
1710 "from_reset failed for vpath: "
1716 vxge_debug_init(VXGE_ERR,
1717 "vxge_hw_vpath_reset failed for "
1724 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1725 /* Reprogram the DA table with populated mac addresses */
1726 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1727 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1728 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1731 /* enable vpath interrupts */
1732 for (i = 0; i < vdev->no_of_vpath; i++)
1733 vxge_vpath_intr_enable(vdev, i);
1735 vxge_hw_device_intr_enable(vdev->devh);
1739 /* Indicate card up */
1740 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1742 /* Get the traffic to flow through the vpaths */
1743 for (i = 0; i < vdev->no_of_vpath; i++) {
1744 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1746 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1749 netif_tx_wake_all_queues(vdev->ndev);
1753 vxge_debug_entryexit(VXGE_TRACE,
1754 "%s:%d Exiting...", __func__, __LINE__);
1756 /* Indicate reset done */
1757 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1758 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1764 * @vdev: pointer to ll device
1766 * driver may reset the chip on events of serr, eccerr, etc
1768 static int vxge_reset(struct vxgedev *vdev)
1770 return do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1774 * vxge_poll - Receive handler when Receive Polling is used.
1775 * @dev: pointer to the device structure.
1776 * @budget: Number of packets budgeted to be processed in this iteration.
1778 * This function comes into picture only if Receive side is being handled
1779 * through polling (called NAPI in linux). It mostly does what the normal
1780 * Rx interrupt handler does in terms of descriptor and packet processing
1781 * but not in an interrupt context. Also it will process a specified number
1782 * of packets at most in one iteration. This value is passed down by the
1783 * kernel as the function argument 'budget'.
1785 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1787 struct vxge_ring *ring =
1788 container_of(napi, struct vxge_ring, napi);
1789 int budget_org = budget;
1790 ring->budget = budget;
1792 vxge_hw_vpath_poll_rx(ring->handle);
1794 if (ring->pkts_processed < budget_org) {
1795 napi_complete(napi);
1796 /* Re enable the Rx interrupts for the vpath */
1797 vxge_hw_channel_msix_unmask(
1798 (struct __vxge_hw_channel *)ring->handle,
1799 ring->rx_vector_no);
1802 return ring->pkts_processed;
1805 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1807 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1808 int pkts_processed = 0;
1810 int budget_org = budget;
1811 struct vxge_ring *ring;
1813 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
1815 for (i = 0; i < vdev->no_of_vpath; i++) {
1816 ring = &vdev->vpaths[i].ring;
1817 ring->budget = budget;
1818 vxge_hw_vpath_poll_rx(ring->handle);
1819 pkts_processed += ring->pkts_processed;
1820 budget -= ring->pkts_processed;
1825 VXGE_COMPLETE_ALL_TX(vdev);
1827 if (pkts_processed < budget_org) {
1828 napi_complete(napi);
1829 /* Re enable the Rx interrupts for the ring */
1830 vxge_hw_device_unmask_all(hldev);
1831 vxge_hw_device_flush_io(hldev);
1834 return pkts_processed;
1837 #ifdef CONFIG_NET_POLL_CONTROLLER
1839 * vxge_netpoll - netpoll event handler entry point
1840 * @dev : pointer to the device structure.
1842 * This function will be called by upper layer to check for events on the
1843 * interface in situations where interrupts are disabled. It is used for
1844 * specific in-kernel networking tasks, such as remote consoles and kernel
1845 * debugging over the network (example netdump in RedHat).
1847 static void vxge_netpoll(struct net_device *dev)
1849 struct __vxge_hw_device *hldev;
1850 struct vxgedev *vdev;
1852 vdev = netdev_priv(dev);
1853 hldev = pci_get_drvdata(vdev->pdev);
1855 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1857 if (pci_channel_offline(vdev->pdev))
1860 disable_irq(dev->irq);
1861 vxge_hw_device_clear_tx_rx(hldev);
1863 vxge_hw_device_clear_tx_rx(hldev);
1864 VXGE_COMPLETE_ALL_RX(vdev);
1865 VXGE_COMPLETE_ALL_TX(vdev);
1867 enable_irq(dev->irq);
1869 vxge_debug_entryexit(VXGE_TRACE,
1870 "%s:%d Exiting...", __func__, __LINE__);
1874 /* RTH configuration */
1875 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1877 enum vxge_hw_status status = VXGE_HW_OK;
1878 struct vxge_hw_rth_hash_types hash_types;
1879 u8 itable[256] = {0}; /* indirection table */
1880 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1885 * - itable with bucket numbers
1886 * - mtable with bucket-to-vpath mapping
1888 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1889 itable[index] = index;
1890 mtable[index] = index % vdev->no_of_vpath;
1893 /* set indirection table, bucket-to-vpath mapping */
1894 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1897 vdev->config.rth_bkt_sz);
1898 if (status != VXGE_HW_OK) {
1899 vxge_debug_init(VXGE_ERR,
1900 "RTH indirection table configuration failed "
1901 "for vpath:%d", vdev->vpaths[0].device_id);
1905 /* Fill RTH hash types */
1906 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1907 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1908 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1909 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1910 hash_types.hash_type_tcpipv6ex_en =
1911 vdev->config.rth_hash_type_tcpipv6ex;
1912 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1915 * Because the itable_set() method uses the active_table field
1916 * for the target virtual path the RTH config should be updated
1917 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1918 * when steering frames.
1920 for (index = 0; index < vdev->no_of_vpath; index++) {
1921 status = vxge_hw_vpath_rts_rth_set(
1922 vdev->vpaths[index].handle,
1923 vdev->config.rth_algorithm,
1925 vdev->config.rth_bkt_sz);
1926 if (status != VXGE_HW_OK) {
1927 vxge_debug_init(VXGE_ERR,
1928 "RTH configuration failed for vpath:%d",
1929 vdev->vpaths[index].device_id);
1938 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1940 enum vxge_hw_status status = VXGE_HW_OK;
1941 struct vxge_vpath *vpath;
1944 for (i = 0; i < vdev->no_of_vpath; i++) {
1945 vpath = &vdev->vpaths[i];
1946 if (vpath->handle) {
1947 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1948 if (is_vxge_card_up(vdev) &&
1949 vxge_hw_vpath_recover_from_reset(
1950 vpath->handle) != VXGE_HW_OK) {
1951 vxge_debug_init(VXGE_ERR,
1952 "vxge_hw_vpath_recover_"
1953 "from_reset failed for vpath: "
1958 vxge_debug_init(VXGE_ERR,
1959 "vxge_hw_vpath_reset failed for "
1970 static void vxge_close_vpaths(struct vxgedev *vdev, int index)
1972 struct vxge_vpath *vpath;
1975 for (i = index; i < vdev->no_of_vpath; i++) {
1976 vpath = &vdev->vpaths[i];
1978 if (vpath->handle && vpath->is_open) {
1979 vxge_hw_vpath_close(vpath->handle);
1980 vdev->stats.vpaths_open--;
1983 vpath->handle = NULL;
1988 static int vxge_open_vpaths(struct vxgedev *vdev)
1990 struct vxge_hw_vpath_attr attr;
1991 enum vxge_hw_status status;
1992 struct vxge_vpath *vpath;
1996 for (i = 0; i < vdev->no_of_vpath; i++) {
1997 vpath = &vdev->vpaths[i];
1998 vxge_assert(vpath->is_configured);
2000 if (!vdev->titan1) {
2001 struct vxge_hw_vp_config *vcfg;
2002 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2004 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2005 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2006 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2007 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2008 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2009 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2010 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2011 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2012 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2015 attr.vp_id = vpath->device_id;
2016 attr.fifo_attr.callback = vxge_xmit_compl;
2017 attr.fifo_attr.txdl_term = vxge_tx_term;
2018 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2019 attr.fifo_attr.userdata = &vpath->fifo;
2021 attr.ring_attr.callback = vxge_rx_1b_compl;
2022 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2023 attr.ring_attr.rxd_term = vxge_rx_term;
2024 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2025 attr.ring_attr.userdata = &vpath->ring;
2027 vpath->ring.ndev = vdev->ndev;
2028 vpath->ring.pdev = vdev->pdev;
2030 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
2031 if (status == VXGE_HW_OK) {
2032 vpath->fifo.handle =
2033 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2034 vpath->ring.handle =
2035 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2036 vpath->fifo.tx_steering_type =
2037 vdev->config.tx_steering_type;
2038 vpath->fifo.ndev = vdev->ndev;
2039 vpath->fifo.pdev = vdev->pdev;
2040 if (vdev->config.tx_steering_type)
2042 netdev_get_tx_queue(vdev->ndev, i);
2045 netdev_get_tx_queue(vdev->ndev, 0);
2046 vpath->fifo.indicate_max_pkts =
2047 vdev->config.fifo_indicate_max_pkts;
2048 vpath->ring.rx_vector_no = 0;
2049 vpath->ring.rx_csum = vdev->rx_csum;
2050 vpath->ring.rx_hwts = vdev->rx_hwts;
2052 vdev->vp_handles[i] = vpath->handle;
2053 vpath->ring.gro_enable = vdev->config.gro_enable;
2054 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
2055 vdev->stats.vpaths_open++;
2057 vdev->stats.vpath_open_fail++;
2058 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2059 "open with status: %d",
2060 vdev->ndev->name, vpath->device_id,
2062 vxge_close_vpaths(vdev, 0);
2066 vp_id = vpath->handle->vpath->vp_id;
2067 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2075 * @irq: the irq of the device.
2076 * @dev_id: a void pointer to the hldev structure of the Titan device
2077 * @ptregs: pointer to the registers pushed on the stack.
2079 * This function is the ISR handler of the device when napi is enabled. It
2080 * identifies the reason for the interrupt and calls the relevant service
2083 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2085 struct net_device *dev;
2086 struct __vxge_hw_device *hldev;
2088 enum vxge_hw_status status;
2089 struct vxgedev *vdev = (struct vxgedev *)dev_id;
2091 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2094 hldev = pci_get_drvdata(vdev->pdev);
2096 if (pci_channel_offline(vdev->pdev))
2099 if (unlikely(!is_vxge_card_up(vdev)))
2102 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
2103 if (status == VXGE_HW_OK) {
2104 vxge_hw_device_mask_all(hldev);
2107 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2108 vdev->vpaths_deployed >>
2109 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2111 vxge_hw_device_clear_tx_rx(hldev);
2112 napi_schedule(&vdev->napi);
2113 vxge_debug_intr(VXGE_TRACE,
2114 "%s:%d Exiting...", __func__, __LINE__);
2117 vxge_hw_device_unmask_all(hldev);
2118 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2119 (status == VXGE_HW_ERR_CRITICAL) ||
2120 (status == VXGE_HW_ERR_FIFO))) {
2121 vxge_hw_device_mask_all(hldev);
2122 vxge_hw_device_flush_io(hldev);
2124 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2127 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2131 #ifdef CONFIG_PCI_MSI
2134 vxge_tx_msix_handle(int irq, void *dev_id)
2136 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2138 VXGE_COMPLETE_VPATH_TX(fifo);
2144 vxge_rx_msix_napi_handle(int irq, void *dev_id)
2146 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2148 /* MSIX_IDX for Rx is 1 */
2149 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2150 ring->rx_vector_no);
2152 napi_schedule(&ring->napi);
2157 vxge_alarm_msix_handle(int irq, void *dev_id)
2160 enum vxge_hw_status status;
2161 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2162 struct vxgedev *vdev = vpath->vdev;
2163 int msix_id = (vpath->handle->vpath->vp_id *
2164 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2166 for (i = 0; i < vdev->no_of_vpath; i++) {
2167 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
2169 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2171 if (status == VXGE_HW_OK) {
2173 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2177 vxge_debug_intr(VXGE_ERR,
2178 "%s: vxge_hw_vpath_alarm_process failed %x ",
2179 VXGE_DRIVER_NAME, status);
2184 static int vxge_alloc_msix(struct vxgedev *vdev)
2187 int msix_intr_vect = 0, temp;
2191 /* Tx/Rx MSIX Vectors count */
2192 vdev->intr_cnt = vdev->no_of_vpath * 2;
2194 /* Alarm MSIX Vectors count */
2197 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2199 if (!vdev->entries) {
2200 vxge_debug_init(VXGE_ERR,
2201 "%s: memory allocation failed",
2204 goto alloc_entries_failed;
2207 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2208 sizeof(struct vxge_msix_entry),
2210 if (!vdev->vxge_entries) {
2211 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2214 goto alloc_vxge_entries_failed;
2217 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
2219 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2221 /* Initialize the fifo vector */
2222 vdev->entries[j].entry = msix_intr_vect;
2223 vdev->vxge_entries[j].entry = msix_intr_vect;
2224 vdev->vxge_entries[j].in_use = 0;
2227 /* Initialize the ring vector */
2228 vdev->entries[j].entry = msix_intr_vect + 1;
2229 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2230 vdev->vxge_entries[j].in_use = 0;
2234 /* Initialize the alarm vector */
2235 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2236 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
2237 vdev->vxge_entries[j].in_use = 0;
2239 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
2241 vxge_debug_init(VXGE_ERR,
2242 "%s: MSI-X enable failed for %d vectors, ret: %d",
2243 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
2244 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2246 goto enable_msix_failed;
2249 kfree(vdev->entries);
2250 kfree(vdev->vxge_entries);
2251 vdev->entries = NULL;
2252 vdev->vxge_entries = NULL;
2253 /* Try with less no of vector by reducing no of vpaths count */
2255 vxge_close_vpaths(vdev, temp);
2256 vdev->no_of_vpath = temp;
2258 } else if (ret < 0) {
2260 goto enable_msix_failed;
2265 kfree(vdev->vxge_entries);
2266 alloc_vxge_entries_failed:
2267 kfree(vdev->entries);
2268 alloc_entries_failed:
2272 static int vxge_enable_msix(struct vxgedev *vdev)
2276 /* 0 - Tx, 1 - Rx */
2277 int tim_msix_id[4] = {0, 1, 0, 0};
2281 /* allocate msix vectors */
2282 ret = vxge_alloc_msix(vdev);
2284 for (i = 0; i < vdev->no_of_vpath; i++) {
2285 struct vxge_vpath *vpath = &vdev->vpaths[i];
2287 /* If fifo or ring are not enabled, the MSIX vector for
2288 * it should be set to 0.
2290 vpath->ring.rx_vector_no = (vpath->device_id *
2291 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
2293 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2294 VXGE_ALARM_MSIX_ID);
2301 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2305 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
2307 if (vdev->vxge_entries[intr_cnt].in_use) {
2308 synchronize_irq(vdev->entries[intr_cnt].vector);
2309 free_irq(vdev->entries[intr_cnt].vector,
2310 vdev->vxge_entries[intr_cnt].arg);
2311 vdev->vxge_entries[intr_cnt].in_use = 0;
2315 kfree(vdev->entries);
2316 kfree(vdev->vxge_entries);
2317 vdev->entries = NULL;
2318 vdev->vxge_entries = NULL;
2320 if (vdev->config.intr_type == MSI_X)
2321 pci_disable_msix(vdev->pdev);
2325 static void vxge_rem_isr(struct vxgedev *vdev)
2327 struct __vxge_hw_device *hldev;
2328 hldev = pci_get_drvdata(vdev->pdev);
2330 #ifdef CONFIG_PCI_MSI
2331 if (vdev->config.intr_type == MSI_X) {
2332 vxge_rem_msix_isr(vdev);
2335 if (vdev->config.intr_type == INTA) {
2336 synchronize_irq(vdev->pdev->irq);
2337 free_irq(vdev->pdev->irq, vdev);
2341 static int vxge_add_isr(struct vxgedev *vdev)
2344 #ifdef CONFIG_PCI_MSI
2345 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2346 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2348 if (vdev->config.intr_type == MSI_X)
2349 ret = vxge_enable_msix(vdev);
2352 vxge_debug_init(VXGE_ERR,
2353 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2354 vxge_debug_init(VXGE_ERR,
2355 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2356 vdev->config.intr_type = INTA;
2359 if (vdev->config.intr_type == MSI_X) {
2361 intr_idx < (vdev->no_of_vpath *
2362 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2364 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2369 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2370 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2372 vdev->entries[intr_cnt].entry,
2375 vdev->entries[intr_cnt].vector,
2376 vxge_tx_msix_handle, 0,
2377 vdev->desc[intr_cnt],
2378 &vdev->vpaths[vp_idx].fifo);
2379 vdev->vxge_entries[intr_cnt].arg =
2380 &vdev->vpaths[vp_idx].fifo;
2384 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2385 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2387 vdev->entries[intr_cnt].entry,
2390 vdev->entries[intr_cnt].vector,
2391 vxge_rx_msix_napi_handle,
2393 vdev->desc[intr_cnt],
2394 &vdev->vpaths[vp_idx].ring);
2395 vdev->vxge_entries[intr_cnt].arg =
2396 &vdev->vpaths[vp_idx].ring;
2402 vxge_debug_init(VXGE_ERR,
2403 "%s: MSIX - %d Registration failed",
2404 vdev->ndev->name, intr_cnt);
2405 vxge_rem_msix_isr(vdev);
2406 vdev->config.intr_type = INTA;
2407 vxge_debug_init(VXGE_ERR,
2408 "%s: Defaulting to INTA"
2409 , vdev->ndev->name);
2414 /* We requested for this msix interrupt */
2415 vdev->vxge_entries[intr_cnt].in_use = 1;
2416 msix_idx += vdev->vpaths[vp_idx].device_id *
2417 VXGE_HW_VPATH_MSIX_ACTIVE;
2418 vxge_hw_vpath_msix_unmask(
2419 vdev->vpaths[vp_idx].handle,
2424 /* Point to next vpath handler */
2425 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2426 (vp_idx < (vdev->no_of_vpath - 1)))
2430 intr_cnt = vdev->no_of_vpath * 2;
2431 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2432 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2434 vdev->entries[intr_cnt].entry,
2436 /* For Alarm interrupts */
2437 ret = request_irq(vdev->entries[intr_cnt].vector,
2438 vxge_alarm_msix_handle, 0,
2439 vdev->desc[intr_cnt],
2442 vxge_debug_init(VXGE_ERR,
2443 "%s: MSIX - %d Registration failed",
2444 vdev->ndev->name, intr_cnt);
2445 vxge_rem_msix_isr(vdev);
2446 vdev->config.intr_type = INTA;
2447 vxge_debug_init(VXGE_ERR,
2448 "%s: Defaulting to INTA",
2453 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2454 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2455 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2457 vdev->vxge_entries[intr_cnt].in_use = 1;
2458 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
2463 if (vdev->config.intr_type == INTA) {
2464 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2465 "%s:vxge:INTA", vdev->ndev->name);
2466 vxge_hw_device_set_intr_type(vdev->devh,
2467 VXGE_HW_INTR_MODE_IRQLINE);
2468 vxge_hw_vpath_tti_ci_set(vdev->devh,
2469 vdev->vpaths[0].device_id);
2470 ret = request_irq((int) vdev->pdev->irq,
2472 IRQF_SHARED, vdev->desc[0], vdev);
2474 vxge_debug_init(VXGE_ERR,
2475 "%s %s-%d: ISR registration failed",
2476 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2479 vxge_debug_init(VXGE_TRACE,
2480 "new %s-%d line allocated",
2481 "IRQ", vdev->pdev->irq);
2487 static void vxge_poll_vp_reset(unsigned long data)
2489 struct vxgedev *vdev = (struct vxgedev *)data;
2492 for (i = 0; i < vdev->no_of_vpath; i++) {
2493 if (test_bit(i, &vdev->vp_reset)) {
2494 vxge_reset_vpath(vdev, i);
2498 if (j && (vdev->config.intr_type != MSI_X)) {
2499 vxge_hw_device_unmask_all(vdev->devh);
2500 vxge_hw_device_flush_io(vdev->devh);
2503 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2506 static void vxge_poll_vp_lockup(unsigned long data)
2508 struct vxgedev *vdev = (struct vxgedev *)data;
2509 enum vxge_hw_status status = VXGE_HW_OK;
2510 struct vxge_vpath *vpath;
2511 struct vxge_ring *ring;
2514 for (i = 0; i < vdev->no_of_vpath; i++) {
2515 ring = &vdev->vpaths[i].ring;
2516 /* Did this vpath received any packets */
2517 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2518 status = vxge_hw_vpath_check_leak(ring->handle);
2520 /* Did it received any packets last time */
2521 if ((VXGE_HW_FAIL == status) &&
2522 (VXGE_HW_FAIL == ring->last_status)) {
2524 /* schedule vpath reset */
2525 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2526 vpath = &vdev->vpaths[i];
2528 /* disable interrupts for this vpath */
2529 vxge_vpath_intr_disable(vdev, i);
2531 /* stop the queue for this vpath */
2532 netif_tx_stop_queue(vpath->fifo.txq);
2537 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2538 ring->last_status = status;
2541 /* Check every 1 milli second */
2542 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2547 * @dev: pointer to the device structure.
2549 * This function is the open entry point of the driver. It mainly calls a
2550 * function to allocate Rx buffers and inserts them into the buffer
2551 * descriptors and then enables the Rx part of the NIC.
2552 * Return value: '0' on success and an appropriate (-)ve integer as
2553 * defined in errno.h file on failure.
2555 static int vxge_open(struct net_device *dev)
2557 enum vxge_hw_status status;
2558 struct vxgedev *vdev;
2559 struct __vxge_hw_device *hldev;
2560 struct vxge_vpath *vpath;
2563 u64 val64, function_mode;
2565 vxge_debug_entryexit(VXGE_TRACE,
2566 "%s: %s:%d", dev->name, __func__, __LINE__);
2568 vdev = netdev_priv(dev);
2569 hldev = pci_get_drvdata(vdev->pdev);
2570 function_mode = vdev->config.device_hw_info.function_mode;
2572 /* make sure you have link off by default every time Nic is
2574 netif_carrier_off(dev);
2577 status = vxge_open_vpaths(vdev);
2578 if (status != VXGE_HW_OK) {
2579 vxge_debug_init(VXGE_ERR,
2580 "%s: fatal: Vpath open failed", vdev->ndev->name);
2585 vdev->mtu = dev->mtu;
2587 status = vxge_add_isr(vdev);
2588 if (status != VXGE_HW_OK) {
2589 vxge_debug_init(VXGE_ERR,
2590 "%s: fatal: ISR add failed", dev->name);
2595 if (vdev->config.intr_type != MSI_X) {
2596 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2597 vdev->config.napi_weight);
2598 napi_enable(&vdev->napi);
2599 for (i = 0; i < vdev->no_of_vpath; i++) {
2600 vpath = &vdev->vpaths[i];
2601 vpath->ring.napi_p = &vdev->napi;
2604 for (i = 0; i < vdev->no_of_vpath; i++) {
2605 vpath = &vdev->vpaths[i];
2606 netif_napi_add(dev, &vpath->ring.napi,
2607 vxge_poll_msix, vdev->config.napi_weight);
2608 napi_enable(&vpath->ring.napi);
2609 vpath->ring.napi_p = &vpath->ring.napi;
2614 if (vdev->config.rth_steering) {
2615 status = vxge_rth_configure(vdev);
2616 if (status != VXGE_HW_OK) {
2617 vxge_debug_init(VXGE_ERR,
2618 "%s: fatal: RTH configuration failed",
2624 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2625 hldev->config.rth_en ? "enabled" : "disabled");
2627 for (i = 0; i < vdev->no_of_vpath; i++) {
2628 vpath = &vdev->vpaths[i];
2630 /* set initial mtu before enabling the device */
2631 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
2632 if (status != VXGE_HW_OK) {
2633 vxge_debug_init(VXGE_ERR,
2634 "%s: fatal: can not set new MTU", dev->name);
2640 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2641 vxge_debug_init(vdev->level_trace,
2642 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2643 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2645 /* Restore the DA, VID table and also multicast and promiscuous mode
2648 if (vdev->all_multi_flg) {
2649 for (i = 0; i < vdev->no_of_vpath; i++) {
2650 vpath = &vdev->vpaths[i];
2651 vxge_restore_vpath_mac_addr(vpath);
2652 vxge_restore_vpath_vid_table(vpath);
2654 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2655 if (status != VXGE_HW_OK)
2656 vxge_debug_init(VXGE_ERR,
2657 "%s:%d Enabling multicast failed",
2658 __func__, __LINE__);
2662 /* Enable vpath to sniff all unicast/multicast traffic that not
2663 * addressed to them. We allow promiscous mode for PF only
2667 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2668 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2670 vxge_hw_mgmt_reg_write(vdev->devh,
2671 vxge_hw_mgmt_reg_type_mrpcim,
2673 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2674 rxmac_authorize_all_addr),
2677 vxge_hw_mgmt_reg_write(vdev->devh,
2678 vxge_hw_mgmt_reg_type_mrpcim,
2680 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2681 rxmac_authorize_all_vid),
2684 vxge_set_multicast(dev);
2686 /* Enabling Bcast and mcast for all vpath */
2687 for (i = 0; i < vdev->no_of_vpath; i++) {
2688 vpath = &vdev->vpaths[i];
2689 status = vxge_hw_vpath_bcast_enable(vpath->handle);
2690 if (status != VXGE_HW_OK)
2691 vxge_debug_init(VXGE_ERR,
2692 "%s : Can not enable bcast for vpath "
2693 "id %d", dev->name, i);
2694 if (vdev->config.addr_learn_en) {
2695 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2696 if (status != VXGE_HW_OK)
2697 vxge_debug_init(VXGE_ERR,
2698 "%s : Can not enable mcast for vpath "
2699 "id %d", dev->name, i);
2703 vxge_hw_device_setpause_data(vdev->devh, 0,
2704 vdev->config.tx_pause_enable,
2705 vdev->config.rx_pause_enable);
2707 if (vdev->vp_reset_timer.function == NULL)
2708 vxge_os_timer(vdev->vp_reset_timer,
2709 vxge_poll_vp_reset, vdev, (HZ/2));
2711 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2712 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2713 vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
2716 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2720 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2721 netif_carrier_on(vdev->ndev);
2722 netdev_notice(vdev->ndev, "Link Up\n");
2723 vdev->stats.link_up++;
2726 vxge_hw_device_intr_enable(vdev->devh);
2730 for (i = 0; i < vdev->no_of_vpath; i++) {
2731 vpath = &vdev->vpaths[i];
2733 vxge_hw_vpath_enable(vpath->handle);
2735 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
2738 netif_tx_start_all_queues(vdev->ndev);
2745 if (vdev->config.intr_type != MSI_X)
2746 napi_disable(&vdev->napi);
2748 for (i = 0; i < vdev->no_of_vpath; i++)
2749 napi_disable(&vdev->vpaths[i].ring.napi);
2753 vxge_close_vpaths(vdev, 0);
2755 vxge_debug_entryexit(VXGE_TRACE,
2756 "%s: %s:%d Exiting...",
2757 dev->name, __func__, __LINE__);
2761 /* Loop throught the mac address list and delete all the entries */
2762 static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2765 struct list_head *entry, *next;
2766 if (list_empty(&vpath->mac_addr_list))
2769 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2771 kfree((struct vxge_mac_addrs *)entry);
2775 static void vxge_napi_del_all(struct vxgedev *vdev)
2778 if (vdev->config.intr_type != MSI_X)
2779 netif_napi_del(&vdev->napi);
2781 for (i = 0; i < vdev->no_of_vpath; i++)
2782 netif_napi_del(&vdev->vpaths[i].ring.napi);
2786 static int do_vxge_close(struct net_device *dev, int do_io)
2788 enum vxge_hw_status status;
2789 struct vxgedev *vdev;
2790 struct __vxge_hw_device *hldev;
2792 u64 val64, vpath_vector;
2793 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2794 dev->name, __func__, __LINE__);
2796 vdev = netdev_priv(dev);
2797 hldev = pci_get_drvdata(vdev->pdev);
2799 if (unlikely(!is_vxge_card_up(vdev)))
2802 /* If vxge_handle_crit_err task is executing,
2803 * wait till it completes. */
2804 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2808 /* Put the vpath back in normal mode */
2809 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2810 status = vxge_hw_mgmt_reg_read(vdev->devh,
2811 vxge_hw_mgmt_reg_type_mrpcim,
2814 struct vxge_hw_mrpcim_reg,
2815 rts_mgr_cbasin_cfg),
2817 if (status == VXGE_HW_OK) {
2818 val64 &= ~vpath_vector;
2819 status = vxge_hw_mgmt_reg_write(vdev->devh,
2820 vxge_hw_mgmt_reg_type_mrpcim,
2823 struct vxge_hw_mrpcim_reg,
2824 rts_mgr_cbasin_cfg),
2828 /* Remove the function 0 from promiscous mode */
2829 vxge_hw_mgmt_reg_write(vdev->devh,
2830 vxge_hw_mgmt_reg_type_mrpcim,
2832 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2833 rxmac_authorize_all_addr),
2836 vxge_hw_mgmt_reg_write(vdev->devh,
2837 vxge_hw_mgmt_reg_type_mrpcim,
2839 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2840 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.
2900 static int vxge_close(struct net_device *dev)
2902 do_vxge_close(dev, 1);
2908 * @dev: net device pointer.
2909 * @new_mtu :the new MTU size for the device.
2911 * A driver entry point to change MTU size for the device. Before changing
2912 * the MTU the device must be stopped.
2914 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
2916 struct vxgedev *vdev = netdev_priv(dev);
2918 vxge_debug_entryexit(vdev->level_trace,
2919 "%s:%d", __func__, __LINE__);
2920 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
2921 vxge_debug_init(vdev->level_err,
2922 "%s: mtu size is invalid", dev->name);
2926 /* check if device is down already */
2927 if (unlikely(!is_vxge_card_up(vdev))) {
2928 /* just store new value, will use later on open() */
2930 vxge_debug_init(vdev->level_err,
2931 "%s", "device is down on MTU change");
2935 vxge_debug_init(vdev->level_trace,
2936 "trying to apply new MTU %d", new_mtu);
2938 if (vxge_close(dev))
2942 vdev->mtu = new_mtu;
2947 vxge_debug_init(vdev->level_trace,
2948 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
2950 vxge_debug_entryexit(vdev->level_trace,
2951 "%s:%d Exiting...", __func__, __LINE__);
2958 * @dev: pointer to the device structure
2959 * @stats: pointer to struct rtnl_link_stats64
2962 static struct rtnl_link_stats64 *
2963 vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
2965 struct vxgedev *vdev = netdev_priv(dev);
2968 /* net_stats already zeroed by caller */
2969 for (k = 0; k < vdev->no_of_vpath; k++) {
2970 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
2971 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
2972 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
2973 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
2974 net_stats->rx_dropped += vdev->vpaths[k].ring.stats.rx_dropped;
2975 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
2976 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
2977 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
2983 static enum vxge_hw_status vxge_timestamp_config(struct vxgedev *vdev,
2986 enum vxge_hw_status status;
2989 /* Timestamp is passed to the driver via the FCS, therefore we
2990 * must disable the FCS stripping by the adapter. Since this is
2991 * required for the driver to load (due to a hardware bug),
2992 * there is no need to do anything special here.
2995 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
2996 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
2997 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
3001 status = vxge_hw_mgmt_reg_write(vdev->devh,
3002 vxge_hw_mgmt_reg_type_mrpcim,
3004 offsetof(struct vxge_hw_mrpcim_reg,
3007 vxge_hw_device_flush_io(vdev->devh);
3011 static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3013 struct hwtstamp_config config;
3014 enum vxge_hw_status status;
3017 if (copy_from_user(&config, data, sizeof(config)))
3020 /* reserved for future extensions */
3024 /* Transmit HW Timestamp not supported */
3025 switch (config.tx_type) {
3026 case HWTSTAMP_TX_OFF:
3028 case HWTSTAMP_TX_ON:
3033 switch (config.rx_filter) {
3034 case HWTSTAMP_FILTER_NONE:
3035 status = vxge_timestamp_config(vdev, 0);
3036 if (status != VXGE_HW_OK)
3040 config.rx_filter = HWTSTAMP_FILTER_NONE;
3043 case HWTSTAMP_FILTER_ALL:
3044 case HWTSTAMP_FILTER_SOME:
3045 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3046 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3047 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3048 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3049 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3050 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3051 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3052 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3053 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3054 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3055 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3056 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3057 status = vxge_timestamp_config(vdev, 1);
3058 if (status != VXGE_HW_OK)
3062 config.rx_filter = HWTSTAMP_FILTER_ALL;
3069 for (i = 0; i < vdev->no_of_vpath; i++)
3070 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3072 if (copy_to_user(data, &config, sizeof(config)))
3080 * @dev: Device pointer.
3081 * @ifr: An IOCTL specific structure, that can contain a pointer to
3082 * a proprietary structure used to pass information to the driver.
3083 * @cmd: This is used to distinguish between the different commands that
3084 * can be passed to the IOCTL functions.
3086 * Entry point for the Ioctl.
3088 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3090 struct vxgedev *vdev = netdev_priv(dev);
3095 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3108 * @dev: pointer to net device structure
3110 * Watchdog for transmit side.
3111 * This function is triggered if the Tx Queue is stopped
3112 * for a pre-defined amount of time when the Interface is still up.
3115 vxge_tx_watchdog(struct net_device *dev)
3117 struct vxgedev *vdev;
3119 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3121 vdev = netdev_priv(dev);
3123 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3126 vxge_debug_entryexit(VXGE_TRACE,
3127 "%s:%d Exiting...", __func__, __LINE__);
3131 * vxge_vlan_rx_register
3132 * @dev: net device pointer.
3135 * Vlan group registration
3138 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3140 struct vxgedev *vdev;
3141 struct vxge_vpath *vpath;
3144 enum vxge_hw_status status;
3147 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3149 vdev = netdev_priv(dev);
3151 vpath = &vdev->vpaths[0];
3152 if ((NULL == grp) && (vpath->is_open)) {
3153 /* Get the first vlan */
3154 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3156 while (status == VXGE_HW_OK) {
3158 /* Delete this vlan from the vid table */
3159 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3160 vpath = &vdev->vpaths[vp];
3161 if (!vpath->is_open)
3164 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3167 /* Get the next vlan to be deleted */
3168 vpath = &vdev->vpaths[0];
3169 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3175 for (i = 0; i < vdev->no_of_vpath; i++) {
3176 if (vdev->vpaths[i].is_configured)
3177 vdev->vpaths[i].ring.vlgrp = grp;
3180 vxge_debug_entryexit(VXGE_TRACE,
3181 "%s:%d Exiting...", __func__, __LINE__);
3185 * vxge_vlan_rx_add_vid
3186 * @dev: net device pointer.
3189 * Add the vlan id to the devices vlan id table
3192 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3194 struct vxgedev *vdev;
3195 struct vxge_vpath *vpath;
3198 vdev = netdev_priv(dev);
3200 /* Add these vlan to the vid table */
3201 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3202 vpath = &vdev->vpaths[vp_id];
3203 if (!vpath->is_open)
3205 vxge_hw_vpath_vid_add(vpath->handle, vid);
3210 * vxge_vlan_rx_add_vid
3211 * @dev: net device pointer.
3214 * Remove the vlan id from the device's vlan id table
3217 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3219 struct vxgedev *vdev;
3220 struct vxge_vpath *vpath;
3223 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3225 vdev = netdev_priv(dev);
3227 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3229 /* Delete this vlan from the vid table */
3230 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3231 vpath = &vdev->vpaths[vp_id];
3232 if (!vpath->is_open)
3234 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3236 vxge_debug_entryexit(VXGE_TRACE,
3237 "%s:%d Exiting...", __func__, __LINE__);
3240 static const struct net_device_ops vxge_netdev_ops = {
3241 .ndo_open = vxge_open,
3242 .ndo_stop = vxge_close,
3243 .ndo_get_stats64 = vxge_get_stats64,
3244 .ndo_start_xmit = vxge_xmit,
3245 .ndo_validate_addr = eth_validate_addr,
3246 .ndo_set_multicast_list = vxge_set_multicast,
3247 .ndo_do_ioctl = vxge_ioctl,
3248 .ndo_set_mac_address = vxge_set_mac_addr,
3249 .ndo_change_mtu = vxge_change_mtu,
3250 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3251 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3252 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3253 .ndo_tx_timeout = vxge_tx_watchdog,
3254 #ifdef CONFIG_NET_POLL_CONTROLLER
3255 .ndo_poll_controller = vxge_netpoll,
3259 static int __devinit vxge_device_revision(struct vxgedev *vdev)
3264 ret = pci_read_config_byte(vdev->pdev, PCI_REVISION_ID, &revision);
3268 vdev->titan1 = (revision == VXGE_HW_TITAN1_PCI_REVISION);
3272 static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3273 struct vxge_config *config,
3274 int high_dma, int no_of_vpath,
3275 struct vxgedev **vdev_out)
3277 struct net_device *ndev;
3278 enum vxge_hw_status status = VXGE_HW_OK;
3279 struct vxgedev *vdev;
3280 int ret = 0, no_of_queue = 1;
3284 if (config->tx_steering_type)
3285 no_of_queue = no_of_vpath;
3287 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3291 vxge_hw_device_trace_level_get(hldev),
3292 "%s : device allocation failed", __func__);
3297 vxge_debug_entryexit(
3298 vxge_hw_device_trace_level_get(hldev),
3299 "%s: %s:%d Entering...",
3300 ndev->name, __func__, __LINE__);
3302 vdev = netdev_priv(ndev);
3303 memset(vdev, 0, sizeof(struct vxgedev));
3307 vdev->pdev = hldev->pdev;
3308 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3309 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3312 ret = vxge_device_revision(vdev);
3316 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3318 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3319 NETIF_F_HW_VLAN_FILTER;
3320 /* Driver entry points */
3321 ndev->irq = vdev->pdev->irq;
3322 ndev->base_addr = (unsigned long) hldev->bar0;
3324 ndev->netdev_ops = &vxge_netdev_ops;
3326 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3328 vxge_initialize_ethtool_ops(ndev);
3330 if (vdev->config.rth_steering != NO_STEERING) {
3331 ndev->features |= NETIF_F_RXHASH;
3332 hldev->config.rth_en = VXGE_HW_RTH_ENABLE;
3335 /* Allocate memory for vpath */
3336 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3337 no_of_vpath, GFP_KERNEL);
3338 if (!vdev->vpaths) {
3339 vxge_debug_init(VXGE_ERR,
3340 "%s: vpath memory allocation failed",
3346 ndev->features |= NETIF_F_SG;
3348 ndev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
3349 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3350 "%s : checksuming enabled", __func__);
3353 ndev->features |= NETIF_F_HIGHDMA;
3354 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3355 "%s : using High DMA", __func__);
3358 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3360 if (vdev->config.gro_enable)
3361 ndev->features |= NETIF_F_GRO;
3363 if (register_netdev(ndev)) {
3364 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3365 "%s: %s : device registration failed!",
3366 ndev->name, __func__);
3371 /* Set the factory defined MAC address initially */
3372 ndev->addr_len = ETH_ALEN;
3374 /* Make Link state as off at this point, when the Link change
3375 * interrupt comes the state will be automatically changed to
3378 netif_carrier_off(ndev);
3380 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3381 "%s: Ethernet device registered",
3387 /* Resetting the Device stats */
3388 status = vxge_hw_mrpcim_stats_access(
3390 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3395 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3397 vxge_hw_device_trace_level_get(hldev),
3398 "%s: device stats clear returns"
3399 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3401 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3402 "%s: %s:%d Exiting...",
3403 ndev->name, __func__, __LINE__);
3407 kfree(vdev->vpaths);
3415 * vxge_device_unregister
3417 * This function will unregister and free network device
3419 static void vxge_device_unregister(struct __vxge_hw_device *hldev)
3421 struct vxgedev *vdev;
3422 struct net_device *dev;
3426 vdev = netdev_priv(dev);
3428 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3429 __func__, __LINE__);
3431 strncpy(buf, dev->name, IFNAMSIZ);
3433 /* in 2.6 will call stop() if device is up */
3434 unregister_netdev(dev);
3436 flush_scheduled_work();
3438 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3440 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3441 __func__, __LINE__);
3445 * vxge_callback_crit_err
3447 * This function is called by the alarm handler in interrupt context.
3448 * Driver must analyze it based on the event type.
3451 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3452 enum vxge_hw_event type, u64 vp_id)
3454 struct net_device *dev = hldev->ndev;
3455 struct vxgedev *vdev = netdev_priv(dev);
3456 struct vxge_vpath *vpath = NULL;
3459 vxge_debug_entryexit(vdev->level_trace,
3460 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3462 /* Note: This event type should be used for device wide
3463 * indications only - Serious errors, Slot freeze and critical errors
3465 vdev->cric_err_event = type;
3467 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3468 vpath = &vdev->vpaths[vpath_idx];
3469 if (vpath->device_id == vp_id)
3473 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3474 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3475 vxge_debug_init(VXGE_ERR,
3476 "%s: Slot is frozen", vdev->ndev->name);
3477 } else if (type == VXGE_HW_EVENT_SERR) {
3478 vxge_debug_init(VXGE_ERR,
3479 "%s: Encountered Serious Error",
3481 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3482 vxge_debug_init(VXGE_ERR,
3483 "%s: Encountered Critical Error",
3487 if ((type == VXGE_HW_EVENT_SERR) ||
3488 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3489 if (unlikely(vdev->exec_mode))
3490 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3491 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3492 vxge_hw_device_mask_all(hldev);
3493 if (unlikely(vdev->exec_mode))
3494 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3495 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3496 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3498 if (unlikely(vdev->exec_mode))
3499 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3501 /* check if this vpath is already set for reset */
3502 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3504 /* disable interrupts for this vpath */
3505 vxge_vpath_intr_disable(vdev, vpath_idx);
3507 /* stop the queue for this vpath */
3508 netif_tx_stop_queue(vpath->fifo.txq);
3513 vxge_debug_entryexit(vdev->level_trace,
3514 "%s: %s:%d Exiting...",
3515 vdev->ndev->name, __func__, __LINE__);
3518 static void verify_bandwidth(void)
3520 int i, band_width, total = 0, equal_priority = 0;
3522 /* 1. If user enters 0 for some fifo, give equal priority to all */
3523 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3524 if (bw_percentage[i] == 0) {
3530 if (!equal_priority) {
3531 /* 2. If sum exceeds 100, give equal priority to all */
3532 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3533 if (bw_percentage[i] == 0xFF)
3536 total += bw_percentage[i];
3537 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3544 if (!equal_priority) {
3545 /* Is all the bandwidth consumed? */
3546 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3547 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3548 /* Split rest of bw equally among next VPs*/
3550 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3551 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3552 if (band_width < 2) /* min of 2% */
3555 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3561 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3565 if (equal_priority) {
3566 vxge_debug_init(VXGE_ERR,
3567 "%s: Assigning equal bandwidth to all the vpaths",
3569 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3570 VXGE_HW_MAX_VIRTUAL_PATHS;
3571 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3572 bw_percentage[i] = bw_percentage[0];
3577 * Vpath configuration
3579 static int __devinit vxge_config_vpaths(
3580 struct vxge_hw_device_config *device_config,
3581 u64 vpath_mask, struct vxge_config *config_param)
3583 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3584 u32 txdl_size, txdl_per_memblock;
3586 temp = driver_config->vpath_per_dev;
3587 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3588 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3589 /* No more CPU. Return vpath number as zero.*/
3590 if (driver_config->g_no_cpus == -1)
3593 if (!driver_config->g_no_cpus)
3594 driver_config->g_no_cpus = num_online_cpus();
3596 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3597 if (!driver_config->vpath_per_dev)
3598 driver_config->vpath_per_dev = 1;
3600 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3601 if (!vxge_bVALn(vpath_mask, i, 1))
3605 if (default_no_vpath < driver_config->vpath_per_dev)
3606 driver_config->vpath_per_dev = default_no_vpath;
3608 driver_config->g_no_cpus = driver_config->g_no_cpus -
3609 (driver_config->vpath_per_dev * 2);
3610 if (driver_config->g_no_cpus <= 0)
3611 driver_config->g_no_cpus = -1;
3614 if (driver_config->vpath_per_dev == 1) {
3615 vxge_debug_ll_config(VXGE_TRACE,
3616 "%s: Disable tx and rx steering, "
3617 "as single vpath is configured", VXGE_DRIVER_NAME);
3618 config_param->rth_steering = NO_STEERING;
3619 config_param->tx_steering_type = NO_STEERING;
3620 device_config->rth_en = 0;
3623 /* configure bandwidth */
3624 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3625 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3627 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3628 device_config->vp_config[i].vp_id = i;
3629 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3630 if (no_of_vpaths < driver_config->vpath_per_dev) {
3631 if (!vxge_bVALn(vpath_mask, i, 1)) {
3632 vxge_debug_ll_config(VXGE_TRACE,
3633 "%s: vpath: %d is not available",
3634 VXGE_DRIVER_NAME, i);
3637 vxge_debug_ll_config(VXGE_TRACE,
3638 "%s: vpath: %d available",
3639 VXGE_DRIVER_NAME, i);
3643 vxge_debug_ll_config(VXGE_TRACE,
3644 "%s: vpath: %d is not configured, "
3645 "max_config_vpath exceeded",
3646 VXGE_DRIVER_NAME, i);
3650 /* Configure Tx fifo's */
3651 device_config->vp_config[i].fifo.enable =
3652 VXGE_HW_FIFO_ENABLE;
3653 device_config->vp_config[i].fifo.max_frags =
3655 device_config->vp_config[i].fifo.memblock_size =
3656 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3658 txdl_size = device_config->vp_config[i].fifo.max_frags *
3659 sizeof(struct vxge_hw_fifo_txd);
3660 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3662 device_config->vp_config[i].fifo.fifo_blocks =
3663 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3665 device_config->vp_config[i].fifo.intr =
3666 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3668 /* Configure tti properties */
3669 device_config->vp_config[i].tti.intr_enable =
3670 VXGE_HW_TIM_INTR_ENABLE;
3672 device_config->vp_config[i].tti.btimer_val =
3673 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3675 device_config->vp_config[i].tti.timer_ac_en =
3676 VXGE_HW_TIM_TIMER_AC_ENABLE;
3678 /* For msi-x with napi (each vector has a handler of its own) -
3679 * Set CI to OFF for all vpaths
3681 device_config->vp_config[i].tti.timer_ci_en =
3682 VXGE_HW_TIM_TIMER_CI_DISABLE;
3684 device_config->vp_config[i].tti.timer_ri_en =
3685 VXGE_HW_TIM_TIMER_RI_DISABLE;
3687 device_config->vp_config[i].tti.util_sel =
3688 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3690 device_config->vp_config[i].tti.ltimer_val =
3691 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3693 device_config->vp_config[i].tti.rtimer_val =
3694 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3696 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3697 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3698 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3699 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3700 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3701 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3702 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3704 /* Configure Rx rings */
3705 device_config->vp_config[i].ring.enable =
3706 VXGE_HW_RING_ENABLE;
3708 device_config->vp_config[i].ring.ring_blocks =
3709 VXGE_HW_DEF_RING_BLOCKS;
3711 device_config->vp_config[i].ring.buffer_mode =
3712 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3714 device_config->vp_config[i].ring.rxds_limit =
3715 VXGE_HW_DEF_RING_RXDS_LIMIT;
3717 device_config->vp_config[i].ring.scatter_mode =
3718 VXGE_HW_RING_SCATTER_MODE_A;
3720 /* Configure rti properties */
3721 device_config->vp_config[i].rti.intr_enable =
3722 VXGE_HW_TIM_INTR_ENABLE;
3724 device_config->vp_config[i].rti.btimer_val =
3725 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3727 device_config->vp_config[i].rti.timer_ac_en =
3728 VXGE_HW_TIM_TIMER_AC_ENABLE;
3730 device_config->vp_config[i].rti.timer_ci_en =
3731 VXGE_HW_TIM_TIMER_CI_DISABLE;
3733 device_config->vp_config[i].rti.timer_ri_en =
3734 VXGE_HW_TIM_TIMER_RI_DISABLE;
3736 device_config->vp_config[i].rti.util_sel =
3737 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3739 device_config->vp_config[i].rti.urange_a =
3741 device_config->vp_config[i].rti.urange_b =
3743 device_config->vp_config[i].rti.urange_c =
3745 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3746 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3747 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3748 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3750 device_config->vp_config[i].rti.rtimer_val =
3751 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3753 device_config->vp_config[i].rti.ltimer_val =
3754 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3756 device_config->vp_config[i].rpa_strip_vlan_tag =
3760 driver_config->vpath_per_dev = temp;
3761 return no_of_vpaths;
3764 /* initialize device configuratrions */
3765 static void __devinit vxge_device_config_init(
3766 struct vxge_hw_device_config *device_config,
3769 /* Used for CQRQ/SRQ. */
3770 device_config->dma_blockpool_initial =
3771 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3773 device_config->dma_blockpool_max =
3774 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3776 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3777 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3779 #ifndef CONFIG_PCI_MSI
3780 vxge_debug_init(VXGE_ERR,
3781 "%s: This Kernel does not support "
3782 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3786 /* Configure whether MSI-X or IRQL. */
3787 switch (*intr_type) {
3789 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3793 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3797 /* Timer period between device poll */
3798 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3800 /* Configure mac based steering. */
3801 device_config->rts_mac_en = addr_learn_en;
3803 /* Configure Vpaths */
3804 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3806 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3808 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3809 device_config->intr_mode);
3810 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3811 device_config->device_poll_millis);
3812 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3813 device_config->rth_en);
3814 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3815 device_config->rth_it_type);
3818 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3822 vxge_debug_init(VXGE_TRACE,
3823 "%s: %d Vpath(s) opened",
3824 vdev->ndev->name, vdev->no_of_vpath);
3826 switch (vdev->config.intr_type) {
3828 vxge_debug_init(VXGE_TRACE,
3829 "%s: Interrupt type INTA", vdev->ndev->name);
3833 vxge_debug_init(VXGE_TRACE,
3834 "%s: Interrupt type MSI-X", vdev->ndev->name);
3838 if (vdev->config.rth_steering) {
3839 vxge_debug_init(VXGE_TRACE,
3840 "%s: RTH steering enabled for TCP_IPV4",
3843 vxge_debug_init(VXGE_TRACE,
3844 "%s: RTH steering disabled", vdev->ndev->name);
3847 switch (vdev->config.tx_steering_type) {
3849 vxge_debug_init(VXGE_TRACE,
3850 "%s: Tx steering disabled", vdev->ndev->name);
3852 case TX_PRIORITY_STEERING:
3853 vxge_debug_init(VXGE_TRACE,
3854 "%s: Unsupported tx steering option",
3856 vxge_debug_init(VXGE_TRACE,
3857 "%s: Tx steering disabled", vdev->ndev->name);
3858 vdev->config.tx_steering_type = 0;
3860 case TX_VLAN_STEERING:
3861 vxge_debug_init(VXGE_TRACE,
3862 "%s: Unsupported tx steering option",
3864 vxge_debug_init(VXGE_TRACE,
3865 "%s: Tx steering disabled", vdev->ndev->name);
3866 vdev->config.tx_steering_type = 0;
3868 case TX_MULTIQ_STEERING:
3869 vxge_debug_init(VXGE_TRACE,
3870 "%s: Tx multiqueue steering enabled",
3873 case TX_PORT_STEERING:
3874 vxge_debug_init(VXGE_TRACE,
3875 "%s: Tx port steering enabled",
3879 vxge_debug_init(VXGE_ERR,
3880 "%s: Unsupported tx steering type",
3882 vxge_debug_init(VXGE_TRACE,
3883 "%s: Tx steering disabled", vdev->ndev->name);
3884 vdev->config.tx_steering_type = 0;
3887 if (vdev->config.gro_enable) {
3888 vxge_debug_init(VXGE_ERR,
3889 "%s: Generic receive offload enabled",
3892 vxge_debug_init(VXGE_TRACE,
3893 "%s: Generic receive offload disabled",
3896 if (vdev->config.addr_learn_en)
3897 vxge_debug_init(VXGE_TRACE,
3898 "%s: MAC Address learning enabled", vdev->ndev->name);
3900 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3901 if (!vxge_bVALn(vpath_mask, i, 1))
3903 vxge_debug_ll_config(VXGE_TRACE,
3904 "%s: MTU size - %d", vdev->ndev->name,
3905 ((struct __vxge_hw_device *)(vdev->devh))->
3906 config.vp_config[i].mtu);
3907 vxge_debug_init(VXGE_TRACE,
3908 "%s: VLAN tag stripping %s", vdev->ndev->name,
3909 ((struct __vxge_hw_device *)(vdev->devh))->
3910 config.vp_config[i].rpa_strip_vlan_tag
3911 ? "Enabled" : "Disabled");
3912 vxge_debug_ll_config(VXGE_TRACE,
3913 "%s: Max frags : %d", vdev->ndev->name,
3914 ((struct __vxge_hw_device *)(vdev->devh))->
3915 config.vp_config[i].fifo.max_frags);
3922 * vxge_pm_suspend - vxge power management suspend entry point
3925 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3930 * vxge_pm_resume - vxge power management resume entry point
3933 static int vxge_pm_resume(struct pci_dev *pdev)
3941 * vxge_io_error_detected - called when PCI error is detected
3942 * @pdev: Pointer to PCI device
3943 * @state: The current pci connection state
3945 * This function is called after a PCI bus error affecting
3946 * this device has been detected.
3948 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3949 pci_channel_state_t state)
3951 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
3952 struct net_device *netdev = hldev->ndev;
3954 netif_device_detach(netdev);
3956 if (state == pci_channel_io_perm_failure)
3957 return PCI_ERS_RESULT_DISCONNECT;
3959 if (netif_running(netdev)) {
3960 /* Bring down the card, while avoiding PCI I/O */
3961 do_vxge_close(netdev, 0);
3964 pci_disable_device(pdev);
3966 return PCI_ERS_RESULT_NEED_RESET;
3970 * vxge_io_slot_reset - called after the pci bus has been reset.
3971 * @pdev: Pointer to PCI device
3973 * Restart the card from scratch, as if from a cold-boot.
3974 * At this point, the card has exprienced a hard reset,
3975 * followed by fixups by BIOS, and has its config space
3976 * set up identically to what it was at cold boot.
3978 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3980 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
3981 struct net_device *netdev = hldev->ndev;
3983 struct vxgedev *vdev = netdev_priv(netdev);
3985 if (pci_enable_device(pdev)) {
3986 netdev_err(netdev, "Cannot re-enable device after reset\n");
3987 return PCI_ERS_RESULT_DISCONNECT;
3990 pci_set_master(pdev);
3991 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
3993 return PCI_ERS_RESULT_RECOVERED;
3997 * vxge_io_resume - called when traffic can start flowing again.
3998 * @pdev: Pointer to PCI device
4000 * This callback is called when the error recovery driver tells
4001 * us that its OK to resume normal operation.
4003 static void vxge_io_resume(struct pci_dev *pdev)
4005 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4006 struct net_device *netdev = hldev->ndev;
4008 if (netif_running(netdev)) {
4009 if (vxge_open(netdev)) {
4011 "Can't bring device back up after reset\n");
4016 netif_device_attach(netdev);
4019 static inline u32 vxge_get_num_vfs(u64 function_mode)
4021 u32 num_functions = 0;
4023 switch (function_mode) {
4024 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4025 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4028 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4031 case VXGE_HW_FUNCTION_MODE_SRIOV:
4032 case VXGE_HW_FUNCTION_MODE_MRIOV:
4033 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4036 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4039 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4042 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4043 num_functions = 8; /* TODO */
4046 return num_functions;
4049 int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4051 struct __vxge_hw_device *hldev = vdev->devh;
4052 u32 maj, min, bld, cmaj, cmin, cbld;
4053 enum vxge_hw_status status;
4054 const struct firmware *fw;
4057 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4059 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4060 VXGE_DRIVER_NAME, fw_name);
4064 /* Load the new firmware onto the adapter */
4065 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4066 if (status != VXGE_HW_OK) {
4067 vxge_debug_init(VXGE_ERR,
4068 "%s: FW image download to adapter failed '%s'.",
4069 VXGE_DRIVER_NAME, fw_name);
4074 /* Read the version of the new firmware */
4075 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4076 if (status != VXGE_HW_OK) {
4077 vxge_debug_init(VXGE_ERR,
4078 "%s: Upgrade read version failed '%s'.",
4079 VXGE_DRIVER_NAME, fw_name);
4084 cmaj = vdev->config.device_hw_info.fw_version.major;
4085 cmin = vdev->config.device_hw_info.fw_version.minor;
4086 cbld = vdev->config.device_hw_info.fw_version.build;
4087 /* It's possible the version in /lib/firmware is not the latest version.
4088 * If so, we could get into a loop of trying to upgrade to the latest
4089 * and flashing the older version.
4091 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4097 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4100 /* Flash the adapter with the new firmware */
4101 status = vxge_hw_flash_fw(hldev);
4102 if (status != VXGE_HW_OK) {
4103 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4104 VXGE_DRIVER_NAME, fw_name);
4109 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4110 "hard reset before using, thus requiring a system reboot or a "
4111 "hotplug event.\n");
4117 static int vxge_probe_fw_update(struct vxgedev *vdev)
4123 maj = vdev->config.device_hw_info.fw_version.major;
4124 min = vdev->config.device_hw_info.fw_version.minor;
4125 bld = vdev->config.device_hw_info.fw_version.build;
4127 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4130 /* Ignore the build number when determining if the current firmware is
4131 * "too new" to load the driver
4133 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4134 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4135 "version, unable to load driver\n",
4140 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4141 * work with this driver.
4143 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4144 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4145 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4149 /* If file not specified, determine gPXE or not */
4150 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4152 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4153 if (vdev->devh->eprom_versions[i]) {
4159 fw_name = "vxge/X3fw-pxe.ncf";
4161 fw_name = "vxge/X3fw.ncf";
4163 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4164 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4165 * probe, so ignore them
4167 if (ret != -EINVAL && ret != -ENOENT)
4172 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4173 VXGE_FW_VER(maj, min, 0)) {
4174 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4175 " be used with this driver.\n"
4176 "Please get the latest version from "
4177 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4178 VXGE_DRIVER_NAME, maj, min, bld);
4185 static int __devinit is_sriov_initialized(struct pci_dev *pdev)
4190 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4192 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4193 if (ctrl & PCI_SRIOV_CTRL_VFE)
4201 * @pdev : structure containing the PCI related information of the device.
4202 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4204 * This function is called when a new PCI device gets detected and initializes
4207 * returns 0 on success and negative on failure.
4210 static int __devinit
4211 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4213 struct __vxge_hw_device *hldev;
4214 enum vxge_hw_status status;
4218 struct vxgedev *vdev;
4219 struct vxge_config *ll_config = NULL;
4220 struct vxge_hw_device_config *device_config = NULL;
4221 struct vxge_hw_device_attr attr;
4222 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4224 struct vxge_mac_addrs *entry;
4225 static int bus = -1, device = -1;
4228 enum vxge_hw_status is_privileged;
4232 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4235 /* In SRIOV-17 mode, functions of the same adapter
4236 * can be deployed on different buses
4238 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4242 bus = pdev->bus->number;
4243 device = PCI_SLOT(pdev->devfn);
4246 if (driver_config->config_dev_cnt &&
4247 (driver_config->config_dev_cnt !=
4248 driver_config->total_dev_cnt))
4249 vxge_debug_init(VXGE_ERR,
4250 "%s: Configured %d of %d devices",
4252 driver_config->config_dev_cnt,
4253 driver_config->total_dev_cnt);
4254 driver_config->config_dev_cnt = 0;
4255 driver_config->total_dev_cnt = 0;
4258 /* Now making the CPU based no of vpath calculation
4259 * applicable for individual functions as well.
4261 driver_config->g_no_cpus = 0;
4262 driver_config->vpath_per_dev = max_config_vpath;
4264 driver_config->total_dev_cnt++;
4265 if (++driver_config->config_dev_cnt > max_config_dev) {
4270 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4272 if (!device_config) {
4274 vxge_debug_init(VXGE_ERR,
4275 "device_config : malloc failed %s %d",
4276 __FILE__, __LINE__);
4280 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
4283 vxge_debug_init(VXGE_ERR,
4284 "device_config : malloc failed %s %d",
4285 __FILE__, __LINE__);
4288 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4289 ll_config->intr_type = MSI_X;
4290 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4291 ll_config->rth_steering = RTH_STEERING;
4293 /* get the default configuration parameters */
4294 vxge_hw_device_config_default_get(device_config);
4296 /* initialize configuration parameters */
4297 vxge_device_config_init(device_config, &ll_config->intr_type);
4299 ret = pci_enable_device(pdev);
4301 vxge_debug_init(VXGE_ERR,
4302 "%s : can not enable PCI device", __func__);
4306 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
4307 vxge_debug_ll_config(VXGE_TRACE,
4308 "%s : using 64bit DMA", __func__);
4312 if (pci_set_consistent_dma_mask(pdev,
4313 DMA_BIT_MASK(64))) {
4314 vxge_debug_init(VXGE_ERR,
4315 "%s : unable to obtain 64bit DMA for "
4316 "consistent allocations", __func__);
4320 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
4321 vxge_debug_ll_config(VXGE_TRACE,
4322 "%s : using 32bit DMA", __func__);
4328 if (pci_request_region(pdev, 0, VXGE_DRIVER_NAME)) {
4329 vxge_debug_init(VXGE_ERR,
4330 "%s : request regions failed", __func__);
4335 pci_set_master(pdev);
4337 attr.bar0 = pci_ioremap_bar(pdev, 0);
4339 vxge_debug_init(VXGE_ERR,
4340 "%s : cannot remap io memory bar0", __func__);
4344 vxge_debug_ll_config(VXGE_TRACE,
4345 "pci ioremap bar0: %p:0x%llx",
4347 (unsigned long long)pci_resource_start(pdev, 0));
4349 status = vxge_hw_device_hw_info_get(attr.bar0,
4350 &ll_config->device_hw_info);
4351 if (status != VXGE_HW_OK) {
4352 vxge_debug_init(VXGE_ERR,
4353 "%s: Reading of hardware info failed."
4354 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4359 vpath_mask = ll_config->device_hw_info.vpath_mask;
4360 if (vpath_mask == 0) {
4361 vxge_debug_ll_config(VXGE_TRACE,
4362 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4367 vxge_debug_ll_config(VXGE_TRACE,
4368 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4369 (unsigned long long)vpath_mask);
4371 function_mode = ll_config->device_hw_info.function_mode;
4372 host_type = ll_config->device_hw_info.host_type;
4373 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4374 ll_config->device_hw_info.func_id);
4376 /* Check how many vpaths are available */
4377 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4378 if (!((vpath_mask) & vxge_mBIT(i)))
4380 max_vpath_supported++;
4384 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4386 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4387 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4388 (ll_config->intr_type != INTA)) {
4389 ret = pci_enable_sriov(pdev, num_vfs);
4391 vxge_debug_ll_config(VXGE_ERR,
4392 "Failed in enabling SRIOV mode: %d\n", ret);
4393 /* No need to fail out, as an error here is non-fatal */
4397 * Configure vpaths and get driver configured number of vpaths
4398 * which is less than or equal to the maximum vpaths per function.
4400 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
4402 vxge_debug_ll_config(VXGE_ERR,
4403 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4408 /* Setting driver callbacks */
4409 attr.uld_callbacks.link_up = vxge_callback_link_up;
4410 attr.uld_callbacks.link_down = vxge_callback_link_down;
4411 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4413 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4414 if (status != VXGE_HW_OK) {
4415 vxge_debug_init(VXGE_ERR,
4416 "Failed to initialize device (%d)", status);
4421 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4422 ll_config->device_hw_info.fw_version.minor,
4423 ll_config->device_hw_info.fw_version.build) >=
4424 VXGE_EPROM_FW_VER) {
4425 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4427 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4428 if (status != VXGE_HW_OK) {
4429 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4431 /* This is a non-fatal error, continue */
4434 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4435 hldev->eprom_versions[i] = img[i].version;
4436 if (!img[i].is_valid)
4438 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
4439 "%d.%d.%d.%d\n", VXGE_DRIVER_NAME, i,
4440 VXGE_EPROM_IMG_MAJOR(img[i].version),
4441 VXGE_EPROM_IMG_MINOR(img[i].version),
4442 VXGE_EPROM_IMG_FIX(img[i].version),
4443 VXGE_EPROM_IMG_BUILD(img[i].version));
4447 /* if FCS stripping is not disabled in MAC fail driver load */
4448 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4449 if (status != VXGE_HW_OK) {
4450 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4451 " failing driver load", VXGE_DRIVER_NAME);
4456 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4458 /* set private device info */
4459 pci_set_drvdata(pdev, hldev);
4461 ll_config->gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4462 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4463 ll_config->addr_learn_en = addr_learn_en;
4464 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4465 ll_config->rth_hash_type_tcpipv4 = 1;
4466 ll_config->rth_hash_type_ipv4 = 0;
4467 ll_config->rth_hash_type_tcpipv6 = 0;
4468 ll_config->rth_hash_type_ipv6 = 0;
4469 ll_config->rth_hash_type_tcpipv6ex = 0;
4470 ll_config->rth_hash_type_ipv6ex = 0;
4471 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4472 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4473 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4475 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4482 ret = vxge_probe_fw_update(vdev);
4486 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4487 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4488 vxge_hw_device_trace_level_get(hldev));
4490 /* set private HW device info */
4491 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4492 vdev->bar0 = attr.bar0;
4493 vdev->max_vpath_supported = max_vpath_supported;
4494 vdev->no_of_vpath = no_of_vpath;
4496 /* Virtual Path count */
4497 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4498 if (!vxge_bVALn(vpath_mask, i, 1))
4500 if (j >= vdev->no_of_vpath)
4503 vdev->vpaths[j].is_configured = 1;
4504 vdev->vpaths[j].device_id = i;
4505 vdev->vpaths[j].ring.driver_id = j;
4506 vdev->vpaths[j].vdev = vdev;
4507 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4508 memcpy((u8 *)vdev->vpaths[j].macaddr,
4509 ll_config->device_hw_info.mac_addrs[i],
4512 /* Initialize the mac address list header */
4513 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4515 vdev->vpaths[j].mac_addr_cnt = 0;
4516 vdev->vpaths[j].mcast_addr_cnt = 0;
4519 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4520 vdev->max_config_port = max_config_port;
4522 vdev->vlan_tag_strip = vlan_tag_strip;
4524 /* map the hashing selector table to the configured vpaths */
4525 for (i = 0; i < vdev->no_of_vpath; i++)
4526 vdev->vpath_selector[i] = vpath_selector[i];
4528 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4530 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4531 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4532 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4534 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4535 vdev->ndev->name, ll_config->device_hw_info.serial_number);
4537 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4538 vdev->ndev->name, ll_config->device_hw_info.part_number);
4540 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4541 vdev->ndev->name, ll_config->device_hw_info.product_desc);
4543 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4544 vdev->ndev->name, macaddr);
4546 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4547 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4549 vxge_debug_init(VXGE_TRACE,
4550 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4551 ll_config->device_hw_info.fw_version.version,
4552 ll_config->device_hw_info.fw_date.date);
4555 switch (ll_config->device_hw_info.function_mode) {
4556 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4557 vxge_debug_init(VXGE_TRACE,
4558 "%s: Single Function Mode Enabled", vdev->ndev->name);
4560 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4561 vxge_debug_init(VXGE_TRACE,
4562 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4564 case VXGE_HW_FUNCTION_MODE_SRIOV:
4565 vxge_debug_init(VXGE_TRACE,
4566 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4568 case VXGE_HW_FUNCTION_MODE_MRIOV:
4569 vxge_debug_init(VXGE_TRACE,
4570 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4575 vxge_print_parm(vdev, vpath_mask);
4577 /* Store the fw version for ethttool option */
4578 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
4579 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4580 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4582 /* Copy the station mac address to the list */
4583 for (i = 0; i < vdev->no_of_vpath; i++) {
4584 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
4585 if (NULL == entry) {
4586 vxge_debug_init(VXGE_ERR,
4587 "%s: mac_addr_list : memory allocation failed",
4592 macaddr = (u8 *)&entry->macaddr;
4593 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4594 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4595 vdev->vpaths[i].mac_addr_cnt = 1;
4598 kfree(device_config);
4601 * INTA is shared in multi-function mode. This is unlike the INTA
4602 * implementation in MR mode, where each VH has its own INTA message.
4603 * - INTA is masked (disabled) as long as at least one function sets
4604 * its TITAN_MASK_ALL_INT.ALARM bit.
4605 * - INTA is unmasked (enabled) when all enabled functions have cleared
4606 * their own TITAN_MASK_ALL_INT.ALARM bit.
4607 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4608 * Though this driver leaves the top level interrupts unmasked while
4609 * leaving the required module interrupt bits masked on exit, there
4610 * could be a rougue driver around that does not follow this procedure
4611 * resulting in a failure to generate interrupts. The following code is
4612 * present to prevent such a failure.
4615 if (ll_config->device_hw_info.function_mode ==
4616 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4617 if (vdev->config.intr_type == INTA)
4618 vxge_hw_device_unmask_all(hldev);
4620 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4621 vdev->ndev->name, __func__, __LINE__);
4623 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4624 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4625 vxge_hw_device_trace_level_get(hldev));
4631 for (i = 0; i < vdev->no_of_vpath; i++)
4632 vxge_free_mac_add_list(&vdev->vpaths[i]);
4634 vxge_device_unregister(hldev);
4636 pci_disable_sriov(pdev);
4637 vxge_hw_device_terminate(hldev);
4641 pci_release_region(pdev, 0);
4643 pci_disable_device(pdev);
4646 kfree(device_config);
4647 driver_config->config_dev_cnt--;
4648 pci_set_drvdata(pdev, NULL);
4653 * vxge_rem_nic - Free the PCI device
4654 * @pdev: structure containing the PCI related information of the device.
4655 * Description: This function is called by the Pci subsystem to release a
4656 * PCI device and free up all resource held up by the device.
4658 static void __devexit vxge_remove(struct pci_dev *pdev)
4660 struct __vxge_hw_device *hldev;
4661 struct vxgedev *vdev = NULL;
4662 struct net_device *dev;
4665 hldev = pci_get_drvdata(pdev);
4671 vdev = netdev_priv(dev);
4673 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
4675 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4677 vxge_device_unregister(hldev);
4679 for (i = 0; i < vdev->no_of_vpath; i++) {
4680 vxge_free_mac_add_list(&vdev->vpaths[i]);
4681 vdev->vpaths[i].mcast_addr_cnt = 0;
4682 vdev->vpaths[i].mac_addr_cnt = 0;
4685 kfree(vdev->vpaths);
4687 iounmap(vdev->bar0);
4689 /* we are safe to free it now */
4692 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4693 __func__, __LINE__);
4695 vxge_hw_device_terminate(hldev);
4697 pci_disable_device(pdev);
4698 pci_release_region(pdev, 0);
4699 pci_set_drvdata(pdev, NULL);
4700 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4704 static struct pci_error_handlers vxge_err_handler = {
4705 .error_detected = vxge_io_error_detected,
4706 .slot_reset = vxge_io_slot_reset,
4707 .resume = vxge_io_resume,
4710 static struct pci_driver vxge_driver = {
4711 .name = VXGE_DRIVER_NAME,
4712 .id_table = vxge_id_table,
4713 .probe = vxge_probe,
4714 .remove = __devexit_p(vxge_remove),
4716 .suspend = vxge_pm_suspend,
4717 .resume = vxge_pm_resume,
4719 .err_handler = &vxge_err_handler,
4727 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4728 pr_info("Driver version: %s\n", DRV_VERSION);
4732 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4736 ret = pci_register_driver(&vxge_driver);
4738 kfree(driver_config);
4742 if (driver_config->config_dev_cnt &&
4743 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4744 vxge_debug_init(VXGE_ERR,
4745 "%s: Configured %d of %d devices",
4746 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4747 driver_config->total_dev_cnt);
4755 pci_unregister_driver(&vxge_driver);
4756 kfree(driver_config);
4758 module_init(vxge_starter);
4759 module_exit(vxge_closer);