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 Neterion Inc's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2009 Neterion Inc.
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 #include <linux/if_vlan.h>
45 #include <linux/pci.h>
46 #include <linux/slab.h>
47 #include <linux/tcp.h>
49 #include <linux/netdevice.h>
50 #include <linux/etherdevice.h>
51 #include "vxge-main.h"
54 MODULE_LICENSE("Dual BSD/GPL");
55 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
56 "Virtualized Server Adapter");
58 static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
59 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
61 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
66 MODULE_DEVICE_TABLE(pci, vxge_id_table);
68 VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
69 VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
70 VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
71 VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
72 VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
73 VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
75 static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
76 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
77 static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
78 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
79 module_param_array(bw_percentage, uint, NULL, 0);
81 static struct vxge_drv_config *driver_config;
83 static inline int is_vxge_card_up(struct vxgedev *vdev)
85 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
88 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
90 unsigned long flags = 0;
91 struct sk_buff **skb_ptr = NULL;
92 struct sk_buff **temp;
93 #define NR_SKB_COMPLETED 128
94 struct sk_buff *completed[NR_SKB_COMPLETED];
101 if (spin_trylock_irqsave(&fifo->tx_lock, flags)) {
102 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
103 NR_SKB_COMPLETED, &more);
104 spin_unlock_irqrestore(&fifo->tx_lock, flags);
107 for (temp = completed; temp != skb_ptr; temp++)
108 dev_kfree_skb_irq(*temp);
112 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
116 /* Complete all transmits */
117 for (i = 0; i < vdev->no_of_vpath; i++)
118 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
121 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
124 struct vxge_ring *ring;
126 /* Complete all receives*/
127 for (i = 0; i < vdev->no_of_vpath; i++) {
128 ring = &vdev->vpaths[i].ring;
129 vxge_hw_vpath_poll_rx(ring->handle);
134 * MultiQ manipulation helper functions
136 static inline int vxge_netif_queue_stopped(struct vxge_fifo *fifo)
138 struct net_device *dev = fifo->ndev;
139 struct netdev_queue *txq = NULL;
140 int vpath_no = fifo->driver_id;
143 if (fifo->tx_steering_type)
144 txq = netdev_get_tx_queue(dev, vpath_no);
146 txq = netdev_get_tx_queue(dev, 0);
148 ret = netif_tx_queue_stopped(txq);
152 void vxge_stop_tx_queue(struct vxge_fifo *fifo)
154 struct net_device *dev = fifo->ndev;
155 struct netdev_queue *txq = NULL;
157 if (fifo->tx_steering_type)
158 txq = netdev_get_tx_queue(dev, fifo->driver_id);
160 txq = netdev_get_tx_queue(dev, 0);
162 netif_tx_stop_queue(txq);
165 void vxge_wake_tx_queue(struct vxge_fifo *fifo)
167 struct net_device *dev = fifo->ndev;
168 struct netdev_queue *txq = NULL;
169 int vpath_no = fifo->driver_id;
171 if (fifo->tx_steering_type)
172 txq = netdev_get_tx_queue(dev, vpath_no);
174 txq = netdev_get_tx_queue(dev, 0);
176 if (netif_tx_queue_stopped(txq))
177 netif_tx_wake_queue(txq);
181 * vxge_callback_link_up
183 * This function is called during interrupt context to notify link up state
187 vxge_callback_link_up(struct __vxge_hw_device *hldev)
189 struct net_device *dev = hldev->ndev;
190 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
192 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
193 vdev->ndev->name, __func__, __LINE__);
194 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
195 vdev->stats.link_up++;
197 netif_carrier_on(vdev->ndev);
198 netif_tx_wake_all_queues(vdev->ndev);
200 vxge_debug_entryexit(VXGE_TRACE,
201 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
205 * vxge_callback_link_down
207 * This function is called during interrupt context to notify link down state
211 vxge_callback_link_down(struct __vxge_hw_device *hldev)
213 struct net_device *dev = hldev->ndev;
214 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
216 vxge_debug_entryexit(VXGE_TRACE,
217 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
218 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
220 vdev->stats.link_down++;
221 netif_carrier_off(vdev->ndev);
222 netif_tx_stop_all_queues(vdev->ndev);
224 vxge_debug_entryexit(VXGE_TRACE,
225 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
233 static struct sk_buff*
234 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
236 struct net_device *dev;
238 struct vxge_rx_priv *rx_priv;
241 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
242 ring->ndev->name, __func__, __LINE__);
244 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
246 /* try to allocate skb first. this one may fail */
247 skb = netdev_alloc_skb(dev, skb_size +
248 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
250 vxge_debug_mem(VXGE_ERR,
251 "%s: out of memory to allocate SKB", dev->name);
252 ring->stats.skb_alloc_fail++;
256 vxge_debug_mem(VXGE_TRACE,
257 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
258 __func__, __LINE__, skb);
260 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
263 rx_priv->skb_data = NULL;
264 rx_priv->data_size = skb_size;
265 vxge_debug_entryexit(VXGE_TRACE,
266 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
274 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
276 struct vxge_rx_priv *rx_priv;
279 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
280 ring->ndev->name, __func__, __LINE__);
281 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
283 rx_priv->skb_data = rx_priv->skb->data;
284 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
285 rx_priv->data_size, PCI_DMA_FROMDEVICE);
287 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
288 ring->stats.pci_map_fail++;
291 vxge_debug_mem(VXGE_TRACE,
292 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
293 ring->ndev->name, __func__, __LINE__,
294 (unsigned long long)dma_addr);
295 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
297 rx_priv->data_dma = dma_addr;
298 vxge_debug_entryexit(VXGE_TRACE,
299 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
305 * vxge_rx_initial_replenish
306 * Allocation of RxD as an initial replenish procedure.
308 static enum vxge_hw_status
309 vxge_rx_initial_replenish(void *dtrh, void *userdata)
311 struct vxge_ring *ring = (struct vxge_ring *)userdata;
312 struct vxge_rx_priv *rx_priv;
314 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
315 ring->ndev->name, __func__, __LINE__);
316 if (vxge_rx_alloc(dtrh, ring,
317 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
320 if (vxge_rx_map(dtrh, ring)) {
321 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
322 dev_kfree_skb(rx_priv->skb);
326 vxge_debug_entryexit(VXGE_TRACE,
327 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
333 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
334 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
337 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
338 ring->ndev->name, __func__, __LINE__);
339 skb_record_rx_queue(skb, ring->driver_id);
340 skb->protocol = eth_type_trans(skb, ring->ndev);
342 ring->stats.rx_frms++;
343 ring->stats.rx_bytes += pkt_length;
345 if (skb->pkt_type == PACKET_MULTICAST)
346 ring->stats.rx_mcast++;
348 vxge_debug_rx(VXGE_TRACE,
349 "%s: %s:%d skb protocol = %d",
350 ring->ndev->name, __func__, __LINE__, skb->protocol);
352 if (ring->gro_enable) {
353 if (ring->vlgrp && ext_info->vlan &&
354 (ring->vlan_tag_strip ==
355 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
356 vlan_gro_receive(ring->napi_p, ring->vlgrp,
357 ext_info->vlan, skb);
359 napi_gro_receive(ring->napi_p, skb);
361 if (ring->vlgrp && vlan &&
362 (ring->vlan_tag_strip ==
363 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
364 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
366 netif_receive_skb(skb);
368 vxge_debug_entryexit(VXGE_TRACE,
369 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
372 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
373 struct vxge_rx_priv *rx_priv)
375 pci_dma_sync_single_for_device(ring->pdev,
376 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
378 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
379 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
382 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
383 void *post_dtr, struct __vxge_hw_ring *ringh)
385 int dtr_count = *dtr_cnt;
386 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
388 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
389 *first_dtr = post_dtr;
391 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
393 *dtr_cnt = dtr_count;
399 * If the interrupt is because of a received frame or if the receive ring
400 * contains fresh as yet un-processed frames, this function is called.
403 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
404 u8 t_code, void *userdata)
406 struct vxge_ring *ring = (struct vxge_ring *)userdata;
407 struct net_device *dev = ring->ndev;
408 unsigned int dma_sizes;
409 void *first_dtr = NULL;
415 struct vxge_rx_priv *rx_priv;
416 struct vxge_hw_ring_rxd_info ext_info;
417 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
418 ring->ndev->name, __func__, __LINE__);
419 ring->pkts_processed = 0;
421 vxge_hw_ring_replenish(ringh);
424 prefetch((char *)dtr + L1_CACHE_BYTES);
425 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
427 data_size = rx_priv->data_size;
428 data_dma = rx_priv->data_dma;
429 prefetch(rx_priv->skb_data);
431 vxge_debug_rx(VXGE_TRACE,
432 "%s: %s:%d skb = 0x%p",
433 ring->ndev->name, __func__, __LINE__, skb);
435 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
436 pkt_length = dma_sizes;
438 pkt_length -= ETH_FCS_LEN;
440 vxge_debug_rx(VXGE_TRACE,
441 "%s: %s:%d Packet Length = %d",
442 ring->ndev->name, __func__, __LINE__, pkt_length);
444 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
446 /* check skb validity */
449 prefetch((char *)skb + L1_CACHE_BYTES);
450 if (unlikely(t_code)) {
452 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
455 ring->stats.rx_errors++;
456 vxge_debug_rx(VXGE_TRACE,
457 "%s: %s :%d Rx T_code is %d",
458 ring->ndev->name, __func__,
461 /* If the t_code is not supported and if the
462 * t_code is other than 0x5 (unparseable packet
463 * such as unknown UPV6 header), Drop it !!!
465 vxge_re_pre_post(dtr, ring, rx_priv);
467 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
468 ring->stats.rx_dropped++;
473 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
475 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
477 if (!vxge_rx_map(dtr, ring)) {
478 skb_put(skb, pkt_length);
480 pci_unmap_single(ring->pdev, data_dma,
481 data_size, PCI_DMA_FROMDEVICE);
483 vxge_hw_ring_rxd_pre_post(ringh, dtr);
484 vxge_post(&dtr_cnt, &first_dtr, dtr,
487 dev_kfree_skb(rx_priv->skb);
489 rx_priv->data_size = data_size;
490 vxge_re_pre_post(dtr, ring, rx_priv);
492 vxge_post(&dtr_cnt, &first_dtr, dtr,
494 ring->stats.rx_dropped++;
498 vxge_re_pre_post(dtr, ring, rx_priv);
500 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
501 ring->stats.rx_dropped++;
505 struct sk_buff *skb_up;
507 skb_up = netdev_alloc_skb(dev, pkt_length +
508 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
509 if (skb_up != NULL) {
511 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
513 pci_dma_sync_single_for_cpu(ring->pdev,
517 vxge_debug_mem(VXGE_TRACE,
518 "%s: %s:%d skb_up = %p",
519 ring->ndev->name, __func__,
521 memcpy(skb_up->data, skb->data, pkt_length);
523 vxge_re_pre_post(dtr, ring, rx_priv);
525 vxge_post(&dtr_cnt, &first_dtr, dtr,
527 /* will netif_rx small SKB instead */
529 skb_put(skb, pkt_length);
531 vxge_re_pre_post(dtr, ring, rx_priv);
533 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
534 vxge_debug_rx(VXGE_ERR,
535 "%s: vxge_rx_1b_compl: out of "
536 "memory", dev->name);
537 ring->stats.skb_alloc_fail++;
542 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
543 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
544 ring->rx_csum && /* Offload Rx side CSUM */
545 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
546 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
547 skb->ip_summed = CHECKSUM_UNNECESSARY;
549 skb->ip_summed = CHECKSUM_NONE;
551 vxge_rx_complete(ring, skb, ext_info.vlan,
552 pkt_length, &ext_info);
555 ring->pkts_processed++;
559 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
560 &t_code) == VXGE_HW_OK);
563 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
565 vxge_debug_entryexit(VXGE_TRACE,
574 * If an interrupt was raised to indicate DMA complete of the Tx packet,
575 * this function is called. It identifies the last TxD whose buffer was
576 * freed and frees all skbs whose data have already DMA'ed into the NICs
580 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
581 enum vxge_hw_fifo_tcode t_code, void *userdata,
582 struct sk_buff ***skb_ptr, int nr_skb, int *more)
584 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
585 struct sk_buff *skb, **done_skb = *skb_ptr;
588 vxge_debug_entryexit(VXGE_TRACE,
589 "%s:%d Entered....", __func__, __LINE__);
595 struct vxge_tx_priv *txd_priv =
596 vxge_hw_fifo_txdl_private_get(dtr);
599 frg_cnt = skb_shinfo(skb)->nr_frags;
600 frag = &skb_shinfo(skb)->frags[0];
602 vxge_debug_tx(VXGE_TRACE,
603 "%s: %s:%d fifo_hw = %p dtr = %p "
604 "tcode = 0x%x", fifo->ndev->name, __func__,
605 __LINE__, fifo_hw, dtr, t_code);
606 /* check skb validity */
608 vxge_debug_tx(VXGE_TRACE,
609 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
610 fifo->ndev->name, __func__, __LINE__,
611 skb, txd_priv, frg_cnt);
612 if (unlikely(t_code)) {
613 fifo->stats.tx_errors++;
614 vxge_debug_tx(VXGE_ERR,
615 "%s: tx: dtr %p completed due to "
616 "error t_code %01x", fifo->ndev->name,
618 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
621 /* for unfragmented skb */
622 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
623 skb_headlen(skb), PCI_DMA_TODEVICE);
625 for (j = 0; j < frg_cnt; j++) {
626 pci_unmap_page(fifo->pdev,
627 txd_priv->dma_buffers[i++],
628 frag->size, PCI_DMA_TODEVICE);
632 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
634 /* Updating the statistics block */
635 fifo->stats.tx_frms++;
636 fifo->stats.tx_bytes += skb->len;
646 if (pkt_cnt > fifo->indicate_max_pkts)
649 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
650 &dtr, &t_code) == VXGE_HW_OK);
653 vxge_wake_tx_queue(fifo);
655 vxge_debug_entryexit(VXGE_TRACE,
656 "%s: %s:%d Exiting...",
657 fifo->ndev->name, __func__, __LINE__);
661 /* select a vpath to transmit the packet */
662 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb,
665 u16 queue_len, counter = 0;
666 if (skb->protocol == htons(ETH_P_IP)) {
672 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
673 th = (struct tcphdr *)(((unsigned char *)ip) +
676 queue_len = vdev->no_of_vpath;
677 counter = (ntohs(th->source) +
679 vdev->vpath_selector[queue_len - 1];
680 if (counter >= queue_len)
681 counter = queue_len - 1;
683 if (ip->protocol == IPPROTO_UDP) {
693 static enum vxge_hw_status vxge_search_mac_addr_in_list(
694 struct vxge_vpath *vpath, u64 del_mac)
696 struct list_head *entry, *next;
697 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
698 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
704 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
706 struct macInfo mac_info;
707 u8 *mac_address = NULL;
708 u64 mac_addr = 0, vpath_vector = 0;
710 enum vxge_hw_status status = VXGE_HW_OK;
711 struct vxge_vpath *vpath = NULL;
712 struct __vxge_hw_device *hldev;
714 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
716 mac_address = (u8 *)&mac_addr;
717 memcpy(mac_address, mac_header, ETH_ALEN);
719 /* Is this mac address already in the list? */
720 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
721 vpath = &vdev->vpaths[vpath_idx];
722 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
726 memset(&mac_info, 0, sizeof(struct macInfo));
727 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
729 /* Any vpath has room to add mac address to its da table? */
730 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
731 vpath = &vdev->vpaths[vpath_idx];
732 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
733 /* Add this mac address to this vpath */
734 mac_info.vpath_no = vpath_idx;
735 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
736 status = vxge_add_mac_addr(vdev, &mac_info);
737 if (status != VXGE_HW_OK)
743 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
745 mac_info.vpath_no = vpath_idx;
746 /* Is the first vpath already selected as catch-basin ? */
747 vpath = &vdev->vpaths[vpath_idx];
748 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
749 /* Add this mac address to this vpath */
750 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
755 /* Select first vpath as catch-basin */
756 vpath_vector = vxge_mBIT(vpath->device_id);
757 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
758 vxge_hw_mgmt_reg_type_mrpcim,
761 struct vxge_hw_mrpcim_reg,
764 if (status != VXGE_HW_OK) {
765 vxge_debug_tx(VXGE_ERR,
766 "%s: Unable to set the vpath-%d in catch-basin mode",
767 VXGE_DRIVER_NAME, vpath->device_id);
771 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
779 * @skb : the socket buffer containing the Tx data.
780 * @dev : device pointer.
782 * This function is the Tx entry point of the driver. Neterion NIC supports
783 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
784 * NOTE: when device cant queue the pkt, just the trans_start variable will
788 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
790 struct vxge_fifo *fifo = NULL;
793 struct vxgedev *vdev = NULL;
794 enum vxge_hw_status status;
795 int frg_cnt, first_frg_len;
797 int i = 0, j = 0, avail;
799 struct vxge_tx_priv *txdl_priv = NULL;
800 struct __vxge_hw_fifo *fifo_hw;
802 unsigned long flags = 0;
804 int do_spin_tx_lock = 1;
806 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
807 dev->name, __func__, __LINE__);
809 /* A buffer with no data will be dropped */
810 if (unlikely(skb->len <= 0)) {
811 vxge_debug_tx(VXGE_ERR,
812 "%s: Buffer has no data..", dev->name);
817 vdev = (struct vxgedev *)netdev_priv(dev);
819 if (unlikely(!is_vxge_card_up(vdev))) {
820 vxge_debug_tx(VXGE_ERR,
821 "%s: vdev not initialized", dev->name);
826 if (vdev->config.addr_learn_en) {
827 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
828 if (vpath_no == -EPERM) {
829 vxge_debug_tx(VXGE_ERR,
830 "%s: Failed to store the mac address",
837 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
838 vpath_no = skb_get_queue_mapping(skb);
839 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
840 vpath_no = vxge_get_vpath_no(vdev, skb, &do_spin_tx_lock);
842 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
844 if (vpath_no >= vdev->no_of_vpath)
847 fifo = &vdev->vpaths[vpath_no].fifo;
848 fifo_hw = fifo->handle;
851 spin_lock_irqsave(&fifo->tx_lock, flags);
853 if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
854 return NETDEV_TX_LOCKED;
857 if (vxge_netif_queue_stopped(fifo)) {
858 spin_unlock_irqrestore(&fifo->tx_lock, flags);
859 return NETDEV_TX_BUSY;
862 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
864 vxge_debug_tx(VXGE_ERR,
865 "%s: No free TXDs available", dev->name);
866 fifo->stats.txd_not_free++;
867 vxge_stop_tx_queue(fifo);
871 /* Last TXD? Stop tx queue to avoid dropping packets. TX
872 * completion will resume the queue.
875 vxge_stop_tx_queue(fifo);
877 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
878 if (unlikely(status != VXGE_HW_OK)) {
879 vxge_debug_tx(VXGE_ERR,
880 "%s: Out of descriptors .", dev->name);
881 fifo->stats.txd_out_of_desc++;
882 vxge_stop_tx_queue(fifo);
886 vxge_debug_tx(VXGE_TRACE,
887 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
888 dev->name, __func__, __LINE__,
889 fifo_hw, dtr, dtr_priv);
891 if (vdev->vlgrp && vlan_tx_tag_present(skb)) {
892 u16 vlan_tag = vlan_tx_tag_get(skb);
893 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
896 first_frg_len = skb_headlen(skb);
898 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
901 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
902 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
903 vxge_stop_tx_queue(fifo);
904 fifo->stats.pci_map_fail++;
908 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
909 txdl_priv->skb = skb;
910 txdl_priv->dma_buffers[j] = dma_pointer;
912 frg_cnt = skb_shinfo(skb)->nr_frags;
913 vxge_debug_tx(VXGE_TRACE,
914 "%s: %s:%d skb = %p txdl_priv = %p "
915 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
916 __func__, __LINE__, skb, txdl_priv,
917 frg_cnt, (unsigned long long)dma_pointer);
919 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
922 frag = &skb_shinfo(skb)->frags[0];
923 for (i = 0; i < frg_cnt; i++) {
924 /* ignore 0 length fragment */
929 (u64)pci_map_page(fifo->pdev, frag->page,
930 frag->page_offset, frag->size,
933 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
935 vxge_debug_tx(VXGE_TRACE,
936 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
937 dev->name, __func__, __LINE__, i,
938 (unsigned long long)dma_pointer);
940 txdl_priv->dma_buffers[j] = dma_pointer;
941 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
946 offload_type = vxge_offload_type(skb);
948 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
950 int mss = vxge_tcp_mss(skb);
952 vxge_debug_tx(VXGE_TRACE,
953 "%s: %s:%d mss = %d",
954 dev->name, __func__, __LINE__, mss);
955 vxge_hw_fifo_txdl_mss_set(dtr, mss);
957 vxge_assert(skb->len <=
958 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
964 if (skb->ip_summed == CHECKSUM_PARTIAL)
965 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
966 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
967 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
968 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
970 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
972 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
974 spin_unlock_irqrestore(&fifo->tx_lock, flags);
976 VXGE_COMPLETE_VPATH_TX(fifo);
977 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
978 dev->name, __func__, __LINE__);
982 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
986 frag = &skb_shinfo(skb)->frags[0];
988 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
989 skb_headlen(skb), PCI_DMA_TODEVICE);
992 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
993 frag->size, PCI_DMA_TODEVICE);
997 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
1000 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1001 VXGE_COMPLETE_VPATH_TX(fifo);
1003 return NETDEV_TX_OK;
1009 * Function will be called by hw function to abort all outstanding receive
1013 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1015 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1016 struct vxge_rx_priv *rx_priv =
1017 vxge_hw_ring_rxd_private_get(dtrh);
1019 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1020 ring->ndev->name, __func__, __LINE__);
1021 if (state != VXGE_HW_RXD_STATE_POSTED)
1024 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1025 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1027 dev_kfree_skb(rx_priv->skb);
1028 rx_priv->skb_data = NULL;
1030 vxge_debug_entryexit(VXGE_TRACE,
1031 "%s: %s:%d Exiting...",
1032 ring->ndev->name, __func__, __LINE__);
1038 * Function will be called to abort all outstanding tx descriptors
1041 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1043 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1045 int i = 0, j, frg_cnt;
1046 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1047 struct sk_buff *skb = txd_priv->skb;
1049 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1051 if (state != VXGE_HW_TXDL_STATE_POSTED)
1054 /* check skb validity */
1056 frg_cnt = skb_shinfo(skb)->nr_frags;
1057 frag = &skb_shinfo(skb)->frags[0];
1059 /* for unfragmented skb */
1060 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1061 skb_headlen(skb), PCI_DMA_TODEVICE);
1063 for (j = 0; j < frg_cnt; j++) {
1064 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1065 frag->size, PCI_DMA_TODEVICE);
1071 vxge_debug_entryexit(VXGE_TRACE,
1072 "%s:%d Exiting...", __func__, __LINE__);
1076 * vxge_set_multicast
1077 * @dev: pointer to the device structure
1079 * Entry point for multicast address enable/disable
1080 * This function is a driver entry point which gets called by the kernel
1081 * whenever multicast addresses must be enabled/disabled. This also gets
1082 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1083 * determine, if multicast address must be enabled or if promiscuous mode
1084 * is to be disabled etc.
1086 static void vxge_set_multicast(struct net_device *dev)
1088 struct netdev_hw_addr *ha;
1089 struct vxgedev *vdev;
1090 int i, mcast_cnt = 0;
1091 struct __vxge_hw_device *hldev;
1092 enum vxge_hw_status status = VXGE_HW_OK;
1093 struct macInfo mac_info;
1095 struct vxge_mac_addrs *mac_entry;
1096 struct list_head *list_head;
1097 struct list_head *entry, *next;
1098 u8 *mac_address = NULL;
1100 vxge_debug_entryexit(VXGE_TRACE,
1101 "%s:%d", __func__, __LINE__);
1103 vdev = (struct vxgedev *)netdev_priv(dev);
1104 hldev = (struct __vxge_hw_device *)vdev->devh;
1106 if (unlikely(!is_vxge_card_up(vdev)))
1109 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1110 for (i = 0; i < vdev->no_of_vpath; i++) {
1111 vxge_assert(vdev->vpaths[i].is_open);
1112 status = vxge_hw_vpath_mcast_enable(
1113 vdev->vpaths[i].handle);
1114 vdev->all_multi_flg = 1;
1116 } else if ((dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1117 for (i = 0; i < vdev->no_of_vpath; i++) {
1118 vxge_assert(vdev->vpaths[i].is_open);
1119 status = vxge_hw_vpath_mcast_disable(
1120 vdev->vpaths[i].handle);
1121 vdev->all_multi_flg = 1;
1125 if (status != VXGE_HW_OK)
1126 vxge_debug_init(VXGE_ERR,
1127 "failed to %s multicast, status %d",
1128 dev->flags & IFF_ALLMULTI ?
1129 "enable" : "disable", status);
1131 if (!vdev->config.addr_learn_en) {
1132 if (dev->flags & IFF_PROMISC) {
1133 for (i = 0; i < vdev->no_of_vpath; i++) {
1134 vxge_assert(vdev->vpaths[i].is_open);
1135 status = vxge_hw_vpath_promisc_enable(
1136 vdev->vpaths[i].handle);
1139 for (i = 0; i < vdev->no_of_vpath; i++) {
1140 vxge_assert(vdev->vpaths[i].is_open);
1141 status = vxge_hw_vpath_promisc_disable(
1142 vdev->vpaths[i].handle);
1147 memset(&mac_info, 0, sizeof(struct macInfo));
1148 /* Update individual M_CAST address list */
1149 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
1151 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1152 list_head = &vdev->vpaths[0].mac_addr_list;
1153 if ((netdev_mc_count(dev) +
1154 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1155 vdev->vpaths[0].max_mac_addr_cnt)
1156 goto _set_all_mcast;
1158 /* Delete previous MC's */
1159 for (i = 0; i < mcast_cnt; i++) {
1160 if (!list_empty(list_head))
1161 mac_entry = (struct vxge_mac_addrs *)
1162 list_first_entry(list_head,
1163 struct vxge_mac_addrs,
1166 list_for_each_safe(entry, next, list_head) {
1168 mac_entry = (struct vxge_mac_addrs *) entry;
1169 /* Copy the mac address to delete */
1170 mac_address = (u8 *)&mac_entry->macaddr;
1171 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1173 /* Is this a multicast address */
1174 if (0x01 & mac_info.macaddr[0]) {
1175 for (vpath_idx = 0; vpath_idx <
1178 mac_info.vpath_no = vpath_idx;
1179 status = vxge_del_mac_addr(
1188 netdev_for_each_mc_addr(ha, dev) {
1189 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
1190 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1192 mac_info.vpath_no = vpath_idx;
1193 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1194 status = vxge_add_mac_addr(vdev, &mac_info);
1195 if (status != VXGE_HW_OK) {
1196 vxge_debug_init(VXGE_ERR,
1197 "%s:%d Setting individual"
1198 "multicast address failed",
1199 __func__, __LINE__);
1200 goto _set_all_mcast;
1207 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1208 /* Delete previous MC's */
1209 for (i = 0; i < mcast_cnt; i++) {
1211 list_for_each_safe(entry, next, list_head) {
1213 mac_entry = (struct vxge_mac_addrs *) entry;
1214 /* Copy the mac address to delete */
1215 mac_address = (u8 *)&mac_entry->macaddr;
1216 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1218 /* Is this a multicast address */
1219 if (0x01 & mac_info.macaddr[0])
1223 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1225 mac_info.vpath_no = vpath_idx;
1226 status = vxge_del_mac_addr(vdev, &mac_info);
1230 /* Enable all multicast */
1231 for (i = 0; i < vdev->no_of_vpath; i++) {
1232 vxge_assert(vdev->vpaths[i].is_open);
1233 status = vxge_hw_vpath_mcast_enable(
1234 vdev->vpaths[i].handle);
1235 if (status != VXGE_HW_OK) {
1236 vxge_debug_init(VXGE_ERR,
1237 "%s:%d Enabling all multicasts failed",
1238 __func__, __LINE__);
1240 vdev->all_multi_flg = 1;
1242 dev->flags |= IFF_ALLMULTI;
1245 vxge_debug_entryexit(VXGE_TRACE,
1246 "%s:%d Exiting...", __func__, __LINE__);
1251 * @dev: pointer to the device structure
1253 * Update entry "0" (default MAC addr)
1255 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1257 struct sockaddr *addr = p;
1258 struct vxgedev *vdev;
1259 struct __vxge_hw_device *hldev;
1260 enum vxge_hw_status status = VXGE_HW_OK;
1261 struct macInfo mac_info_new, mac_info_old;
1264 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1266 vdev = (struct vxgedev *)netdev_priv(dev);
1269 if (!is_valid_ether_addr(addr->sa_data))
1272 memset(&mac_info_new, 0, sizeof(struct macInfo));
1273 memset(&mac_info_old, 0, sizeof(struct macInfo));
1275 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1276 __func__, __LINE__);
1278 /* Get the old address */
1279 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1281 /* Copy the new address */
1282 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1284 /* First delete the old mac address from all the vpaths
1285 as we can't specify the index while adding new mac address */
1286 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1287 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1288 if (!vpath->is_open) {
1289 /* This can happen when this interface is added/removed
1290 to the bonding interface. Delete this station address
1291 from the linked list */
1292 vxge_mac_list_del(vpath, &mac_info_old);
1294 /* Add this new address to the linked list
1295 for later restoring */
1296 vxge_mac_list_add(vpath, &mac_info_new);
1300 /* Delete the station address */
1301 mac_info_old.vpath_no = vpath_idx;
1302 status = vxge_del_mac_addr(vdev, &mac_info_old);
1305 if (unlikely(!is_vxge_card_up(vdev))) {
1306 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1310 /* Set this mac address to all the vpaths */
1311 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1312 mac_info_new.vpath_no = vpath_idx;
1313 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1314 status = vxge_add_mac_addr(vdev, &mac_info_new);
1315 if (status != VXGE_HW_OK)
1319 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1325 * vxge_vpath_intr_enable
1326 * @vdev: pointer to vdev
1327 * @vp_id: vpath for which to enable the interrupts
1329 * Enables the interrupts for the vpath
1331 void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1333 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1335 int tim_msix_id[4] = {0, 1, 0, 0};
1336 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
1338 vxge_hw_vpath_intr_enable(vpath->handle);
1340 if (vdev->config.intr_type == INTA)
1341 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1343 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1346 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1347 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1348 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1350 /* enable the alarm vector */
1351 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1352 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1353 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1358 * vxge_vpath_intr_disable
1359 * @vdev: pointer to vdev
1360 * @vp_id: vpath for which to disable the interrupts
1362 * Disables the interrupts for the vpath
1364 void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1366 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1369 vxge_hw_vpath_intr_disable(vpath->handle);
1371 if (vdev->config.intr_type == INTA)
1372 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1374 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1375 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1376 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1378 /* disable the alarm vector */
1379 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1380 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
1381 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1387 * @vdev: pointer to vdev
1388 * @vp_id: vpath to reset
1392 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1394 enum vxge_hw_status status = VXGE_HW_OK;
1397 /* check if device is down already */
1398 if (unlikely(!is_vxge_card_up(vdev)))
1401 /* is device reset already scheduled */
1402 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1405 if (vdev->vpaths[vp_id].handle) {
1406 if (vxge_hw_vpath_reset(vdev->vpaths[vp_id].handle)
1408 if (is_vxge_card_up(vdev) &&
1409 vxge_hw_vpath_recover_from_reset(
1410 vdev->vpaths[vp_id].handle)
1412 vxge_debug_init(VXGE_ERR,
1413 "vxge_hw_vpath_recover_from_reset"
1414 "failed for vpath:%d", vp_id);
1418 vxge_debug_init(VXGE_ERR,
1419 "vxge_hw_vpath_reset failed for"
1424 return VXGE_HW_FAIL;
1426 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1427 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1429 /* Enable all broadcast */
1430 vxge_hw_vpath_bcast_enable(vdev->vpaths[vp_id].handle);
1432 /* Enable the interrupts */
1433 vxge_vpath_intr_enable(vdev, vp_id);
1437 /* Enable the flow of traffic through the vpath */
1438 vxge_hw_vpath_enable(vdev->vpaths[vp_id].handle);
1441 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[vp_id].handle);
1442 vdev->vpaths[vp_id].ring.last_status = VXGE_HW_OK;
1444 /* Vpath reset done */
1445 clear_bit(vp_id, &vdev->vp_reset);
1447 /* Start the vpath queue */
1448 vxge_wake_tx_queue(&vdev->vpaths[vp_id].fifo);
1453 static int do_vxge_reset(struct vxgedev *vdev, int event)
1455 enum vxge_hw_status status;
1456 int ret = 0, vp_id, i;
1458 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1460 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1461 /* check if device is down already */
1462 if (unlikely(!is_vxge_card_up(vdev)))
1465 /* is reset already scheduled */
1466 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1470 if (event == VXGE_LL_FULL_RESET) {
1471 /* wait for all the vpath reset to complete */
1472 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1473 while (test_bit(vp_id, &vdev->vp_reset))
1477 /* if execution mode is set to debug, don't reset the adapter */
1478 if (unlikely(vdev->exec_mode)) {
1479 vxge_debug_init(VXGE_ERR,
1480 "%s: execution mode is debug, returning..",
1482 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1483 netif_tx_stop_all_queues(vdev->ndev);
1488 if (event == VXGE_LL_FULL_RESET) {
1489 vxge_hw_device_intr_disable(vdev->devh);
1491 switch (vdev->cric_err_event) {
1492 case VXGE_HW_EVENT_UNKNOWN:
1493 netif_tx_stop_all_queues(vdev->ndev);
1494 vxge_debug_init(VXGE_ERR,
1495 "fatal: %s: Disabling device due to"
1500 case VXGE_HW_EVENT_RESET_START:
1502 case VXGE_HW_EVENT_RESET_COMPLETE:
1503 case VXGE_HW_EVENT_LINK_DOWN:
1504 case VXGE_HW_EVENT_LINK_UP:
1505 case VXGE_HW_EVENT_ALARM_CLEARED:
1506 case VXGE_HW_EVENT_ECCERR:
1507 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1510 case VXGE_HW_EVENT_FIFO_ERR:
1511 case VXGE_HW_EVENT_VPATH_ERR:
1513 case VXGE_HW_EVENT_CRITICAL_ERR:
1514 netif_tx_stop_all_queues(vdev->ndev);
1515 vxge_debug_init(VXGE_ERR,
1516 "fatal: %s: Disabling device due to"
1519 /* SOP or device reset required */
1520 /* This event is not currently used */
1523 case VXGE_HW_EVENT_SERR:
1524 netif_tx_stop_all_queues(vdev->ndev);
1525 vxge_debug_init(VXGE_ERR,
1526 "fatal: %s: Disabling device due to"
1531 case VXGE_HW_EVENT_SRPCIM_SERR:
1532 case VXGE_HW_EVENT_MRPCIM_SERR:
1535 case VXGE_HW_EVENT_SLOT_FREEZE:
1536 netif_tx_stop_all_queues(vdev->ndev);
1537 vxge_debug_init(VXGE_ERR,
1538 "fatal: %s: Disabling device due to"
1549 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1550 netif_tx_stop_all_queues(vdev->ndev);
1552 if (event == VXGE_LL_FULL_RESET) {
1553 status = vxge_reset_all_vpaths(vdev);
1554 if (status != VXGE_HW_OK) {
1555 vxge_debug_init(VXGE_ERR,
1556 "fatal: %s: can not reset vpaths",
1563 if (event == VXGE_LL_COMPL_RESET) {
1564 for (i = 0; i < vdev->no_of_vpath; i++)
1565 if (vdev->vpaths[i].handle) {
1566 if (vxge_hw_vpath_recover_from_reset(
1567 vdev->vpaths[i].handle)
1569 vxge_debug_init(VXGE_ERR,
1570 "vxge_hw_vpath_recover_"
1571 "from_reset failed for vpath: "
1577 vxge_debug_init(VXGE_ERR,
1578 "vxge_hw_vpath_reset failed for "
1585 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1586 /* Reprogram the DA table with populated mac addresses */
1587 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1588 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1589 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1592 /* enable vpath interrupts */
1593 for (i = 0; i < vdev->no_of_vpath; i++)
1594 vxge_vpath_intr_enable(vdev, i);
1596 vxge_hw_device_intr_enable(vdev->devh);
1600 /* Indicate card up */
1601 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1603 /* Get the traffic to flow through the vpaths */
1604 for (i = 0; i < vdev->no_of_vpath; i++) {
1605 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1607 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1610 netif_tx_wake_all_queues(vdev->ndev);
1614 vxge_debug_entryexit(VXGE_TRACE,
1615 "%s:%d Exiting...", __func__, __LINE__);
1617 /* Indicate reset done */
1618 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1619 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1625 * @vdev: pointer to ll device
1627 * driver may reset the chip on events of serr, eccerr, etc
1629 int vxge_reset(struct vxgedev *vdev)
1631 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1636 * vxge_poll - Receive handler when Receive Polling is used.
1637 * @dev: pointer to the device structure.
1638 * @budget: Number of packets budgeted to be processed in this iteration.
1640 * This function comes into picture only if Receive side is being handled
1641 * through polling (called NAPI in linux). It mostly does what the normal
1642 * Rx interrupt handler does in terms of descriptor and packet processing
1643 * but not in an interrupt context. Also it will process a specified number
1644 * of packets at most in one iteration. This value is passed down by the
1645 * kernel as the function argument 'budget'.
1647 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1649 struct vxge_ring *ring =
1650 container_of(napi, struct vxge_ring, napi);
1651 int budget_org = budget;
1652 ring->budget = budget;
1654 vxge_hw_vpath_poll_rx(ring->handle);
1656 if (ring->pkts_processed < budget_org) {
1657 napi_complete(napi);
1658 /* Re enable the Rx interrupts for the vpath */
1659 vxge_hw_channel_msix_unmask(
1660 (struct __vxge_hw_channel *)ring->handle,
1661 ring->rx_vector_no);
1664 return ring->pkts_processed;
1667 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1669 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1670 int pkts_processed = 0;
1672 int budget_org = budget;
1673 struct vxge_ring *ring;
1675 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1676 pci_get_drvdata(vdev->pdev);
1678 for (i = 0; i < vdev->no_of_vpath; i++) {
1679 ring = &vdev->vpaths[i].ring;
1680 ring->budget = budget;
1681 vxge_hw_vpath_poll_rx(ring->handle);
1682 pkts_processed += ring->pkts_processed;
1683 budget -= ring->pkts_processed;
1688 VXGE_COMPLETE_ALL_TX(vdev);
1690 if (pkts_processed < budget_org) {
1691 napi_complete(napi);
1692 /* Re enable the Rx interrupts for the ring */
1693 vxge_hw_device_unmask_all(hldev);
1694 vxge_hw_device_flush_io(hldev);
1697 return pkts_processed;
1700 #ifdef CONFIG_NET_POLL_CONTROLLER
1702 * vxge_netpoll - netpoll event handler entry point
1703 * @dev : pointer to the device structure.
1705 * This function will be called by upper layer to check for events on the
1706 * interface in situations where interrupts are disabled. It is used for
1707 * specific in-kernel networking tasks, such as remote consoles and kernel
1708 * debugging over the network (example netdump in RedHat).
1710 static void vxge_netpoll(struct net_device *dev)
1712 struct __vxge_hw_device *hldev;
1713 struct vxgedev *vdev;
1715 vdev = (struct vxgedev *)netdev_priv(dev);
1716 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1718 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1720 if (pci_channel_offline(vdev->pdev))
1723 disable_irq(dev->irq);
1724 vxge_hw_device_clear_tx_rx(hldev);
1726 vxge_hw_device_clear_tx_rx(hldev);
1727 VXGE_COMPLETE_ALL_RX(vdev);
1728 VXGE_COMPLETE_ALL_TX(vdev);
1730 enable_irq(dev->irq);
1732 vxge_debug_entryexit(VXGE_TRACE,
1733 "%s:%d Exiting...", __func__, __LINE__);
1737 /* RTH configuration */
1738 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1740 enum vxge_hw_status status = VXGE_HW_OK;
1741 struct vxge_hw_rth_hash_types hash_types;
1742 u8 itable[256] = {0}; /* indirection table */
1743 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1748 * - itable with bucket numbers
1749 * - mtable with bucket-to-vpath mapping
1751 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1752 itable[index] = index;
1753 mtable[index] = index % vdev->no_of_vpath;
1756 /* Fill RTH hash types */
1757 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1758 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1759 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1760 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1761 hash_types.hash_type_tcpipv6ex_en =
1762 vdev->config.rth_hash_type_tcpipv6ex;
1763 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1765 /* set indirection table, bucket-to-vpath mapping */
1766 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1769 vdev->config.rth_bkt_sz);
1770 if (status != VXGE_HW_OK) {
1771 vxge_debug_init(VXGE_ERR,
1772 "RTH indirection table configuration failed "
1773 "for vpath:%d", vdev->vpaths[0].device_id);
1778 * Because the itable_set() method uses the active_table field
1779 * for the target virtual path the RTH config should be updated
1780 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1781 * when steering frames.
1783 for (index = 0; index < vdev->no_of_vpath; index++) {
1784 status = vxge_hw_vpath_rts_rth_set(
1785 vdev->vpaths[index].handle,
1786 vdev->config.rth_algorithm,
1788 vdev->config.rth_bkt_sz);
1790 if (status != VXGE_HW_OK) {
1791 vxge_debug_init(VXGE_ERR,
1792 "RTH configuration failed for vpath:%d",
1793 vdev->vpaths[index].device_id);
1801 int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1803 struct vxge_mac_addrs *new_mac_entry;
1804 u8 *mac_address = NULL;
1806 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1809 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1810 if (!new_mac_entry) {
1811 vxge_debug_mem(VXGE_ERR,
1812 "%s: memory allocation failed",
1817 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1819 /* Copy the new mac address to the list */
1820 mac_address = (u8 *)&new_mac_entry->macaddr;
1821 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1823 new_mac_entry->state = mac->state;
1824 vpath->mac_addr_cnt++;
1826 /* Is this a multicast address */
1827 if (0x01 & mac->macaddr[0])
1828 vpath->mcast_addr_cnt++;
1833 /* Add a mac address to DA table */
1834 enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1836 enum vxge_hw_status status = VXGE_HW_OK;
1837 struct vxge_vpath *vpath;
1838 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1840 if (0x01 & mac->macaddr[0]) /* multicast address */
1841 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1843 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1845 vpath = &vdev->vpaths[mac->vpath_no];
1846 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1847 mac->macmask, duplicate_mode);
1848 if (status != VXGE_HW_OK) {
1849 vxge_debug_init(VXGE_ERR,
1850 "DA config add entry failed for vpath:%d",
1853 if (FALSE == vxge_mac_list_add(vpath, mac))
1859 int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1861 struct list_head *entry, *next;
1863 u8 *mac_address = (u8 *) (&del_mac);
1865 /* Copy the mac address to delete from the list */
1866 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1868 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1869 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1871 kfree((struct vxge_mac_addrs *)entry);
1872 vpath->mac_addr_cnt--;
1874 /* Is this a multicast address */
1875 if (0x01 & mac->macaddr[0])
1876 vpath->mcast_addr_cnt--;
1883 /* delete a mac address from DA table */
1884 enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1886 enum vxge_hw_status status = VXGE_HW_OK;
1887 struct vxge_vpath *vpath;
1889 vpath = &vdev->vpaths[mac->vpath_no];
1890 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1892 if (status != VXGE_HW_OK) {
1893 vxge_debug_init(VXGE_ERR,
1894 "DA config delete entry failed for vpath:%d",
1897 vxge_mac_list_del(vpath, mac);
1901 /* list all mac addresses from DA table */
1903 static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1904 struct macInfo *mac)
1906 enum vxge_hw_status status = VXGE_HW_OK;
1907 unsigned char macmask[ETH_ALEN];
1908 unsigned char macaddr[ETH_ALEN];
1910 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1912 if (status != VXGE_HW_OK) {
1913 vxge_debug_init(VXGE_ERR,
1914 "DA config list entry failed for vpath:%d",
1919 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1921 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1923 if (status != VXGE_HW_OK)
1930 /* Store all vlan ids from the list to the vid table */
1931 enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1933 enum vxge_hw_status status = VXGE_HW_OK;
1934 struct vxgedev *vdev = vpath->vdev;
1937 if (vdev->vlgrp && vpath->is_open) {
1939 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1940 if (!vlan_group_get_device(vdev->vlgrp, vid))
1942 /* Add these vlan to the vid table */
1943 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1950 /* Store all mac addresses from the list to the DA table */
1951 enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1953 enum vxge_hw_status status = VXGE_HW_OK;
1954 struct macInfo mac_info;
1955 u8 *mac_address = NULL;
1956 struct list_head *entry, *next;
1958 memset(&mac_info, 0, sizeof(struct macInfo));
1960 if (vpath->is_open) {
1962 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1965 ((struct vxge_mac_addrs *)entry)->macaddr;
1966 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1967 ((struct vxge_mac_addrs *)entry)->state =
1968 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1969 /* does this mac address already exist in da table? */
1970 status = vxge_search_mac_addr_in_da_table(vpath,
1972 if (status != VXGE_HW_OK) {
1973 /* Add this mac address to the DA table */
1974 status = vxge_hw_vpath_mac_addr_add(
1975 vpath->handle, mac_info.macaddr,
1977 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1978 if (status != VXGE_HW_OK) {
1979 vxge_debug_init(VXGE_ERR,
1980 "DA add entry failed for vpath:%d",
1982 ((struct vxge_mac_addrs *)entry)->state
1983 = VXGE_LL_MAC_ADDR_IN_LIST;
1993 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1996 enum vxge_hw_status status = VXGE_HW_OK;
1998 for (i = 0; i < vdev->no_of_vpath; i++)
1999 if (vdev->vpaths[i].handle) {
2000 if (vxge_hw_vpath_reset(vdev->vpaths[i].handle)
2002 if (is_vxge_card_up(vdev) &&
2003 vxge_hw_vpath_recover_from_reset(
2004 vdev->vpaths[i].handle)
2006 vxge_debug_init(VXGE_ERR,
2007 "vxge_hw_vpath_recover_"
2008 "from_reset failed for vpath: "
2013 vxge_debug_init(VXGE_ERR,
2014 "vxge_hw_vpath_reset failed for "
2023 void vxge_close_vpaths(struct vxgedev *vdev, int index)
2026 for (i = index; i < vdev->no_of_vpath; i++) {
2027 if (vdev->vpaths[i].handle && vdev->vpaths[i].is_open) {
2028 vxge_hw_vpath_close(vdev->vpaths[i].handle);
2029 vdev->stats.vpaths_open--;
2031 vdev->vpaths[i].is_open = 0;
2032 vdev->vpaths[i].handle = NULL;
2037 int vxge_open_vpaths(struct vxgedev *vdev)
2039 enum vxge_hw_status status;
2042 struct vxge_hw_vpath_attr attr;
2044 for (i = 0; i < vdev->no_of_vpath; i++) {
2045 vxge_assert(vdev->vpaths[i].is_configured);
2046 attr.vp_id = vdev->vpaths[i].device_id;
2047 attr.fifo_attr.callback = vxge_xmit_compl;
2048 attr.fifo_attr.txdl_term = vxge_tx_term;
2049 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2050 attr.fifo_attr.userdata = (void *)&vdev->vpaths[i].fifo;
2052 attr.ring_attr.callback = vxge_rx_1b_compl;
2053 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2054 attr.ring_attr.rxd_term = vxge_rx_term;
2055 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2056 attr.ring_attr.userdata = (void *)&vdev->vpaths[i].ring;
2058 vdev->vpaths[i].ring.ndev = vdev->ndev;
2059 vdev->vpaths[i].ring.pdev = vdev->pdev;
2060 status = vxge_hw_vpath_open(vdev->devh, &attr,
2061 &(vdev->vpaths[i].handle));
2062 if (status == VXGE_HW_OK) {
2063 vdev->vpaths[i].fifo.handle =
2064 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2065 vdev->vpaths[i].ring.handle =
2066 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2067 vdev->vpaths[i].fifo.tx_steering_type =
2068 vdev->config.tx_steering_type;
2069 vdev->vpaths[i].fifo.ndev = vdev->ndev;
2070 vdev->vpaths[i].fifo.pdev = vdev->pdev;
2071 vdev->vpaths[i].fifo.indicate_max_pkts =
2072 vdev->config.fifo_indicate_max_pkts;
2073 vdev->vpaths[i].ring.rx_vector_no = 0;
2074 vdev->vpaths[i].ring.rx_csum = vdev->rx_csum;
2075 vdev->vpaths[i].is_open = 1;
2076 vdev->vp_handles[i] = vdev->vpaths[i].handle;
2077 vdev->vpaths[i].ring.gro_enable =
2078 vdev->config.gro_enable;
2079 vdev->vpaths[i].ring.vlan_tag_strip =
2080 vdev->vlan_tag_strip;
2081 vdev->stats.vpaths_open++;
2083 vdev->stats.vpath_open_fail++;
2084 vxge_debug_init(VXGE_ERR,
2085 "%s: vpath: %d failed to open "
2087 vdev->ndev->name, vdev->vpaths[i].device_id,
2089 vxge_close_vpaths(vdev, 0);
2094 ((struct __vxge_hw_vpath_handle *)vdev->vpaths[i].handle)->
2096 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2103 * @irq: the irq of the device.
2104 * @dev_id: a void pointer to the hldev structure of the Titan device
2105 * @ptregs: pointer to the registers pushed on the stack.
2107 * This function is the ISR handler of the device when napi is enabled. It
2108 * identifies the reason for the interrupt and calls the relevant service
2111 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2113 struct net_device *dev;
2114 struct __vxge_hw_device *hldev;
2116 enum vxge_hw_status status;
2117 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
2119 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2122 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
2124 if (pci_channel_offline(vdev->pdev))
2127 if (unlikely(!is_vxge_card_up(vdev)))
2130 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2132 if (status == VXGE_HW_OK) {
2133 vxge_hw_device_mask_all(hldev);
2136 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2137 vdev->vpaths_deployed >>
2138 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2140 vxge_hw_device_clear_tx_rx(hldev);
2141 napi_schedule(&vdev->napi);
2142 vxge_debug_intr(VXGE_TRACE,
2143 "%s:%d Exiting...", __func__, __LINE__);
2146 vxge_hw_device_unmask_all(hldev);
2147 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2148 (status == VXGE_HW_ERR_CRITICAL) ||
2149 (status == VXGE_HW_ERR_FIFO))) {
2150 vxge_hw_device_mask_all(hldev);
2151 vxge_hw_device_flush_io(hldev);
2153 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2156 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2160 #ifdef CONFIG_PCI_MSI
2163 vxge_tx_msix_handle(int irq, void *dev_id)
2165 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2167 VXGE_COMPLETE_VPATH_TX(fifo);
2173 vxge_rx_msix_napi_handle(int irq, void *dev_id)
2175 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2177 /* MSIX_IDX for Rx is 1 */
2178 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2179 ring->rx_vector_no);
2181 napi_schedule(&ring->napi);
2186 vxge_alarm_msix_handle(int irq, void *dev_id)
2189 enum vxge_hw_status status;
2190 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2191 struct vxgedev *vdev = vpath->vdev;
2192 int msix_id = (vpath->handle->vpath->vp_id *
2193 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2195 for (i = 0; i < vdev->no_of_vpath; i++) {
2196 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
2198 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2200 if (status == VXGE_HW_OK) {
2202 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2206 vxge_debug_intr(VXGE_ERR,
2207 "%s: vxge_hw_vpath_alarm_process failed %x ",
2208 VXGE_DRIVER_NAME, status);
2213 static int vxge_alloc_msix(struct vxgedev *vdev)
2216 int msix_intr_vect = 0, temp;
2220 /* Tx/Rx MSIX Vectors count */
2221 vdev->intr_cnt = vdev->no_of_vpath * 2;
2223 /* Alarm MSIX Vectors count */
2226 vdev->entries = kzalloc(vdev->intr_cnt * sizeof(struct msix_entry),
2228 if (!vdev->entries) {
2229 vxge_debug_init(VXGE_ERR,
2230 "%s: memory allocation failed",
2233 goto alloc_entries_failed;
2236 vdev->vxge_entries =
2237 kzalloc(vdev->intr_cnt * sizeof(struct vxge_msix_entry),
2239 if (!vdev->vxge_entries) {
2240 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2243 goto alloc_vxge_entries_failed;
2246 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
2248 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2250 /* Initialize the fifo vector */
2251 vdev->entries[j].entry = msix_intr_vect;
2252 vdev->vxge_entries[j].entry = msix_intr_vect;
2253 vdev->vxge_entries[j].in_use = 0;
2256 /* Initialize the ring vector */
2257 vdev->entries[j].entry = msix_intr_vect + 1;
2258 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2259 vdev->vxge_entries[j].in_use = 0;
2263 /* Initialize the alarm vector */
2264 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2265 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
2266 vdev->vxge_entries[j].in_use = 0;
2268 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
2271 vxge_debug_init(VXGE_ERR,
2272 "%s: MSI-X enable failed for %d vectors, ret: %d",
2273 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
2274 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2276 goto enable_msix_failed;
2279 kfree(vdev->entries);
2280 kfree(vdev->vxge_entries);
2281 vdev->entries = NULL;
2282 vdev->vxge_entries = NULL;
2283 /* Try with less no of vector by reducing no of vpaths count */
2285 vxge_close_vpaths(vdev, temp);
2286 vdev->no_of_vpath = temp;
2288 } else if (ret < 0) {
2290 goto enable_msix_failed;
2295 kfree(vdev->vxge_entries);
2296 alloc_vxge_entries_failed:
2297 kfree(vdev->entries);
2298 alloc_entries_failed:
2302 static int vxge_enable_msix(struct vxgedev *vdev)
2306 /* 0 - Tx, 1 - Rx */
2307 int tim_msix_id[4] = {0, 1, 0, 0};
2311 /* allocate msix vectors */
2312 ret = vxge_alloc_msix(vdev);
2314 for (i = 0; i < vdev->no_of_vpath; i++) {
2316 /* If fifo or ring are not enabled
2317 the MSIX vector for that should be set to 0
2318 Hence initializeing this array to all 0s.
2320 vdev->vpaths[i].ring.rx_vector_no =
2321 (vdev->vpaths[i].device_id *
2322 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
2324 vxge_hw_vpath_msix_set(vdev->vpaths[i].handle,
2325 tim_msix_id, VXGE_ALARM_MSIX_ID);
2332 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2336 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
2338 if (vdev->vxge_entries[intr_cnt].in_use) {
2339 synchronize_irq(vdev->entries[intr_cnt].vector);
2340 free_irq(vdev->entries[intr_cnt].vector,
2341 vdev->vxge_entries[intr_cnt].arg);
2342 vdev->vxge_entries[intr_cnt].in_use = 0;
2346 kfree(vdev->entries);
2347 kfree(vdev->vxge_entries);
2348 vdev->entries = NULL;
2349 vdev->vxge_entries = NULL;
2351 if (vdev->config.intr_type == MSI_X)
2352 pci_disable_msix(vdev->pdev);
2356 static void vxge_rem_isr(struct vxgedev *vdev)
2358 struct __vxge_hw_device *hldev;
2359 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2361 #ifdef CONFIG_PCI_MSI
2362 if (vdev->config.intr_type == MSI_X) {
2363 vxge_rem_msix_isr(vdev);
2366 if (vdev->config.intr_type == INTA) {
2367 synchronize_irq(vdev->pdev->irq);
2368 free_irq(vdev->pdev->irq, vdev);
2372 static int vxge_add_isr(struct vxgedev *vdev)
2375 #ifdef CONFIG_PCI_MSI
2376 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2377 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2379 if (vdev->config.intr_type == MSI_X)
2380 ret = vxge_enable_msix(vdev);
2383 vxge_debug_init(VXGE_ERR,
2384 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2385 vxge_debug_init(VXGE_ERR,
2386 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2387 vdev->config.intr_type = INTA;
2390 if (vdev->config.intr_type == MSI_X) {
2392 intr_idx < (vdev->no_of_vpath *
2393 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2395 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2400 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2401 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2403 vdev->entries[intr_cnt].entry,
2406 vdev->entries[intr_cnt].vector,
2407 vxge_tx_msix_handle, 0,
2408 vdev->desc[intr_cnt],
2409 &vdev->vpaths[vp_idx].fifo);
2410 vdev->vxge_entries[intr_cnt].arg =
2411 &vdev->vpaths[vp_idx].fifo;
2415 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2416 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2418 vdev->entries[intr_cnt].entry,
2421 vdev->entries[intr_cnt].vector,
2422 vxge_rx_msix_napi_handle,
2424 vdev->desc[intr_cnt],
2425 &vdev->vpaths[vp_idx].ring);
2426 vdev->vxge_entries[intr_cnt].arg =
2427 &vdev->vpaths[vp_idx].ring;
2433 vxge_debug_init(VXGE_ERR,
2434 "%s: MSIX - %d Registration failed",
2435 vdev->ndev->name, intr_cnt);
2436 vxge_rem_msix_isr(vdev);
2437 vdev->config.intr_type = INTA;
2438 vxge_debug_init(VXGE_ERR,
2439 "%s: Defaulting to INTA"
2440 , vdev->ndev->name);
2445 /* We requested for this msix interrupt */
2446 vdev->vxge_entries[intr_cnt].in_use = 1;
2447 msix_idx += vdev->vpaths[vp_idx].device_id *
2448 VXGE_HW_VPATH_MSIX_ACTIVE;
2449 vxge_hw_vpath_msix_unmask(
2450 vdev->vpaths[vp_idx].handle,
2455 /* Point to next vpath handler */
2456 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2457 (vp_idx < (vdev->no_of_vpath - 1)))
2461 intr_cnt = vdev->no_of_vpath * 2;
2462 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2463 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2465 vdev->entries[intr_cnt].entry,
2467 /* For Alarm interrupts */
2468 ret = request_irq(vdev->entries[intr_cnt].vector,
2469 vxge_alarm_msix_handle, 0,
2470 vdev->desc[intr_cnt],
2473 vxge_debug_init(VXGE_ERR,
2474 "%s: MSIX - %d Registration failed",
2475 vdev->ndev->name, intr_cnt);
2476 vxge_rem_msix_isr(vdev);
2477 vdev->config.intr_type = INTA;
2478 vxge_debug_init(VXGE_ERR,
2479 "%s: Defaulting to INTA",
2484 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2485 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2486 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2488 vdev->vxge_entries[intr_cnt].in_use = 1;
2489 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
2494 if (vdev->config.intr_type == INTA) {
2495 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2496 "%s:vxge:INTA", vdev->ndev->name);
2497 vxge_hw_device_set_intr_type(vdev->devh,
2498 VXGE_HW_INTR_MODE_IRQLINE);
2499 vxge_hw_vpath_tti_ci_set(vdev->devh,
2500 vdev->vpaths[0].device_id);
2501 ret = request_irq((int) vdev->pdev->irq,
2503 IRQF_SHARED, vdev->desc[0], vdev);
2505 vxge_debug_init(VXGE_ERR,
2506 "%s %s-%d: ISR registration failed",
2507 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2510 vxge_debug_init(VXGE_TRACE,
2511 "new %s-%d line allocated",
2512 "IRQ", vdev->pdev->irq);
2518 static void vxge_poll_vp_reset(unsigned long data)
2520 struct vxgedev *vdev = (struct vxgedev *)data;
2523 for (i = 0; i < vdev->no_of_vpath; i++) {
2524 if (test_bit(i, &vdev->vp_reset)) {
2525 vxge_reset_vpath(vdev, i);
2529 if (j && (vdev->config.intr_type != MSI_X)) {
2530 vxge_hw_device_unmask_all(vdev->devh);
2531 vxge_hw_device_flush_io(vdev->devh);
2534 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2537 static void vxge_poll_vp_lockup(unsigned long data)
2539 struct vxgedev *vdev = (struct vxgedev *)data;
2541 struct vxge_ring *ring;
2542 enum vxge_hw_status status = VXGE_HW_OK;
2544 for (i = 0; i < vdev->no_of_vpath; i++) {
2545 ring = &vdev->vpaths[i].ring;
2546 /* Did this vpath received any packets */
2547 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2548 status = vxge_hw_vpath_check_leak(ring->handle);
2550 /* Did it received any packets last time */
2551 if ((VXGE_HW_FAIL == status) &&
2552 (VXGE_HW_FAIL == ring->last_status)) {
2554 /* schedule vpath reset */
2555 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2557 /* disable interrupts for this vpath */
2558 vxge_vpath_intr_disable(vdev, i);
2560 /* stop the queue for this vpath */
2561 vxge_stop_tx_queue(&vdev->vpaths[i].
2567 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2568 ring->last_status = status;
2571 /* Check every 1 milli second */
2572 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2577 * @dev: pointer to the device structure.
2579 * This function is the open entry point of the driver. It mainly calls a
2580 * function to allocate Rx buffers and inserts them into the buffer
2581 * descriptors and then enables the Rx part of the NIC.
2582 * Return value: '0' on success and an appropriate (-)ve integer as
2583 * defined in errno.h file on failure.
2586 vxge_open(struct net_device *dev)
2588 enum vxge_hw_status status;
2589 struct vxgedev *vdev;
2590 struct __vxge_hw_device *hldev;
2593 u64 val64, function_mode;
2594 vxge_debug_entryexit(VXGE_TRACE,
2595 "%s: %s:%d", dev->name, __func__, __LINE__);
2597 vdev = (struct vxgedev *)netdev_priv(dev);
2598 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2599 function_mode = vdev->config.device_hw_info.function_mode;
2601 /* make sure you have link off by default every time Nic is
2603 netif_carrier_off(dev);
2606 status = vxge_open_vpaths(vdev);
2607 if (status != VXGE_HW_OK) {
2608 vxge_debug_init(VXGE_ERR,
2609 "%s: fatal: Vpath open failed", vdev->ndev->name);
2614 vdev->mtu = dev->mtu;
2616 status = vxge_add_isr(vdev);
2617 if (status != VXGE_HW_OK) {
2618 vxge_debug_init(VXGE_ERR,
2619 "%s: fatal: ISR add failed", dev->name);
2625 if (vdev->config.intr_type != MSI_X) {
2626 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2627 vdev->config.napi_weight);
2628 napi_enable(&vdev->napi);
2629 for (i = 0; i < vdev->no_of_vpath; i++)
2630 vdev->vpaths[i].ring.napi_p = &vdev->napi;
2632 for (i = 0; i < vdev->no_of_vpath; i++) {
2633 netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
2634 vxge_poll_msix, vdev->config.napi_weight);
2635 napi_enable(&vdev->vpaths[i].ring.napi);
2636 vdev->vpaths[i].ring.napi_p =
2637 &vdev->vpaths[i].ring.napi;
2642 if (vdev->config.rth_steering) {
2643 status = vxge_rth_configure(vdev);
2644 if (status != VXGE_HW_OK) {
2645 vxge_debug_init(VXGE_ERR,
2646 "%s: fatal: RTH configuration failed",
2653 for (i = 0; i < vdev->no_of_vpath; i++) {
2654 /* set initial mtu before enabling the device */
2655 status = vxge_hw_vpath_mtu_set(vdev->vpaths[i].handle,
2657 if (status != VXGE_HW_OK) {
2658 vxge_debug_init(VXGE_ERR,
2659 "%s: fatal: can not set new MTU", dev->name);
2665 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2666 vxge_debug_init(vdev->level_trace,
2667 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2668 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2670 /* Reprogram the DA table with populated mac addresses */
2671 for (i = 0; i < vdev->no_of_vpath; i++) {
2672 vxge_restore_vpath_mac_addr(&vdev->vpaths[i]);
2673 vxge_restore_vpath_vid_table(&vdev->vpaths[i]);
2676 /* Enable vpath to sniff all unicast/multicast traffic that not
2677 * addressed to them. We allow promiscous mode for PF only
2681 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2682 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2684 vxge_hw_mgmt_reg_write(vdev->devh,
2685 vxge_hw_mgmt_reg_type_mrpcim,
2687 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2688 rxmac_authorize_all_addr),
2691 vxge_hw_mgmt_reg_write(vdev->devh,
2692 vxge_hw_mgmt_reg_type_mrpcim,
2694 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2695 rxmac_authorize_all_vid),
2698 vxge_set_multicast(dev);
2700 /* Enabling Bcast and mcast for all vpath */
2701 for (i = 0; i < vdev->no_of_vpath; i++) {
2702 status = vxge_hw_vpath_bcast_enable(vdev->vpaths[i].handle);
2703 if (status != VXGE_HW_OK)
2704 vxge_debug_init(VXGE_ERR,
2705 "%s : Can not enable bcast for vpath "
2706 "id %d", dev->name, i);
2707 if (vdev->config.addr_learn_en) {
2709 vxge_hw_vpath_mcast_enable(vdev->vpaths[i].handle);
2710 if (status != VXGE_HW_OK)
2711 vxge_debug_init(VXGE_ERR,
2712 "%s : Can not enable mcast for vpath "
2713 "id %d", dev->name, i);
2717 vxge_hw_device_setpause_data(vdev->devh, 0,
2718 vdev->config.tx_pause_enable,
2719 vdev->config.rx_pause_enable);
2721 if (vdev->vp_reset_timer.function == NULL)
2722 vxge_os_timer(vdev->vp_reset_timer,
2723 vxge_poll_vp_reset, vdev, (HZ/2));
2725 if (vdev->vp_lockup_timer.function == NULL)
2726 vxge_os_timer(vdev->vp_lockup_timer,
2727 vxge_poll_vp_lockup, vdev, (HZ/2));
2729 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2733 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2734 netif_carrier_on(vdev->ndev);
2735 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
2736 vdev->stats.link_up++;
2739 vxge_hw_device_intr_enable(vdev->devh);
2743 for (i = 0; i < vdev->no_of_vpath; i++) {
2744 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
2746 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
2749 netif_tx_start_all_queues(vdev->ndev);
2756 if (vdev->config.intr_type != MSI_X)
2757 napi_disable(&vdev->napi);
2759 for (i = 0; i < vdev->no_of_vpath; i++)
2760 napi_disable(&vdev->vpaths[i].ring.napi);
2764 vxge_close_vpaths(vdev, 0);
2766 vxge_debug_entryexit(VXGE_TRACE,
2767 "%s: %s:%d Exiting...",
2768 dev->name, __func__, __LINE__);
2772 /* Loop throught the mac address list and delete all the entries */
2773 void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2776 struct list_head *entry, *next;
2777 if (list_empty(&vpath->mac_addr_list))
2780 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2782 kfree((struct vxge_mac_addrs *)entry);
2786 static void vxge_napi_del_all(struct vxgedev *vdev)
2789 if (vdev->config.intr_type != MSI_X)
2790 netif_napi_del(&vdev->napi);
2792 for (i = 0; i < vdev->no_of_vpath; i++)
2793 netif_napi_del(&vdev->vpaths[i].ring.napi);
2797 int do_vxge_close(struct net_device *dev, int do_io)
2799 enum vxge_hw_status status;
2800 struct vxgedev *vdev;
2801 struct __vxge_hw_device *hldev;
2803 u64 val64, vpath_vector;
2804 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2805 dev->name, __func__, __LINE__);
2807 vdev = (struct vxgedev *)netdev_priv(dev);
2808 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2810 if (unlikely(!is_vxge_card_up(vdev)))
2813 /* If vxge_handle_crit_err task is executing,
2814 * wait till it completes. */
2815 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2818 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2820 /* Put the vpath back in normal mode */
2821 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2822 status = vxge_hw_mgmt_reg_read(vdev->devh,
2823 vxge_hw_mgmt_reg_type_mrpcim,
2826 struct vxge_hw_mrpcim_reg,
2827 rts_mgr_cbasin_cfg),
2830 if (status == VXGE_HW_OK) {
2831 val64 &= ~vpath_vector;
2832 status = vxge_hw_mgmt_reg_write(vdev->devh,
2833 vxge_hw_mgmt_reg_type_mrpcim,
2836 struct vxge_hw_mrpcim_reg,
2837 rts_mgr_cbasin_cfg),
2841 /* Remove the function 0 from promiscous mode */
2842 vxge_hw_mgmt_reg_write(vdev->devh,
2843 vxge_hw_mgmt_reg_type_mrpcim,
2845 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2846 rxmac_authorize_all_addr),
2849 vxge_hw_mgmt_reg_write(vdev->devh,
2850 vxge_hw_mgmt_reg_type_mrpcim,
2852 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2853 rxmac_authorize_all_vid),
2858 del_timer_sync(&vdev->vp_lockup_timer);
2860 del_timer_sync(&vdev->vp_reset_timer);
2863 if (vdev->config.intr_type != MSI_X)
2864 napi_disable(&vdev->napi);
2866 for (i = 0; i < vdev->no_of_vpath; i++)
2867 napi_disable(&vdev->vpaths[i].ring.napi);
2870 netif_carrier_off(vdev->ndev);
2871 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
2872 netif_tx_stop_all_queues(vdev->ndev);
2874 /* Note that at this point xmit() is stopped by upper layer */
2876 vxge_hw_device_intr_disable(vdev->devh);
2882 vxge_napi_del_all(vdev);
2885 vxge_reset_all_vpaths(vdev);
2887 vxge_close_vpaths(vdev, 0);
2889 vxge_debug_entryexit(VXGE_TRACE,
2890 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2892 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2899 * @dev: device pointer.
2901 * This is the stop entry point of the driver. It needs to undo exactly
2902 * whatever was done by the open entry point, thus it's usually referred to
2903 * as the close function.Among other things this function mainly stops the
2904 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2905 * Return value: '0' on success and an appropriate (-)ve integer as
2906 * defined in errno.h file on failure.
2909 vxge_close(struct net_device *dev)
2911 do_vxge_close(dev, 1);
2917 * @dev: net device pointer.
2918 * @new_mtu :the new MTU size for the device.
2920 * A driver entry point to change MTU size for the device. Before changing
2921 * the MTU the device must be stopped.
2923 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
2925 struct vxgedev *vdev = netdev_priv(dev);
2927 vxge_debug_entryexit(vdev->level_trace,
2928 "%s:%d", __func__, __LINE__);
2929 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
2930 vxge_debug_init(vdev->level_err,
2931 "%s: mtu size is invalid", dev->name);
2935 /* check if device is down already */
2936 if (unlikely(!is_vxge_card_up(vdev))) {
2937 /* just store new value, will use later on open() */
2939 vxge_debug_init(vdev->level_err,
2940 "%s", "device is down on MTU change");
2944 vxge_debug_init(vdev->level_trace,
2945 "trying to apply new MTU %d", new_mtu);
2947 if (vxge_close(dev))
2951 vdev->mtu = new_mtu;
2956 vxge_debug_init(vdev->level_trace,
2957 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
2959 vxge_debug_entryexit(vdev->level_trace,
2960 "%s:%d Exiting...", __func__, __LINE__);
2967 * @dev: pointer to the device structure
2969 * Updates the device statistics structure. This function updates the device
2970 * statistics structure in the net_device structure and returns a pointer
2973 static struct net_device_stats *
2974 vxge_get_stats(struct net_device *dev)
2976 struct vxgedev *vdev;
2977 struct net_device_stats *net_stats;
2980 vdev = netdev_priv(dev);
2982 net_stats = &vdev->stats.net_stats;
2984 memset(net_stats, 0, sizeof(struct net_device_stats));
2986 for (k = 0; k < vdev->no_of_vpath; k++) {
2987 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
2988 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
2989 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
2990 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
2991 net_stats->rx_dropped +=
2992 vdev->vpaths[k].ring.stats.rx_dropped;
2994 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
2995 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
2996 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3004 * @dev: Device pointer.
3005 * @ifr: An IOCTL specific structure, that can contain a pointer to
3006 * a proprietary structure used to pass information to the driver.
3007 * @cmd: This is used to distinguish between the different commands that
3008 * can be passed to the IOCTL functions.
3010 * Entry point for the Ioctl.
3012 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3019 * @dev: pointer to net device structure
3021 * Watchdog for transmit side.
3022 * This function is triggered if the Tx Queue is stopped
3023 * for a pre-defined amount of time when the Interface is still up.
3026 vxge_tx_watchdog(struct net_device *dev)
3028 struct vxgedev *vdev;
3030 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3032 vdev = (struct vxgedev *)netdev_priv(dev);
3034 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3037 vxge_debug_entryexit(VXGE_TRACE,
3038 "%s:%d Exiting...", __func__, __LINE__);
3042 * vxge_vlan_rx_register
3043 * @dev: net device pointer.
3046 * Vlan group registration
3049 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3051 struct vxgedev *vdev;
3052 struct vxge_vpath *vpath;
3055 enum vxge_hw_status status;
3058 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3060 vdev = (struct vxgedev *)netdev_priv(dev);
3062 vpath = &vdev->vpaths[0];
3063 if ((NULL == grp) && (vpath->is_open)) {
3064 /* Get the first vlan */
3065 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3067 while (status == VXGE_HW_OK) {
3069 /* Delete this vlan from the vid table */
3070 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3071 vpath = &vdev->vpaths[vp];
3072 if (!vpath->is_open)
3075 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3078 /* Get the next vlan to be deleted */
3079 vpath = &vdev->vpaths[0];
3080 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3086 for (i = 0; i < vdev->no_of_vpath; i++) {
3087 if (vdev->vpaths[i].is_configured)
3088 vdev->vpaths[i].ring.vlgrp = grp;
3091 vxge_debug_entryexit(VXGE_TRACE,
3092 "%s:%d Exiting...", __func__, __LINE__);
3096 * vxge_vlan_rx_add_vid
3097 * @dev: net device pointer.
3100 * Add the vlan id to the devices vlan id table
3103 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3105 struct vxgedev *vdev;
3106 struct vxge_vpath *vpath;
3109 vdev = (struct vxgedev *)netdev_priv(dev);
3111 /* Add these vlan to the vid table */
3112 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3113 vpath = &vdev->vpaths[vp_id];
3114 if (!vpath->is_open)
3116 vxge_hw_vpath_vid_add(vpath->handle, vid);
3121 * vxge_vlan_rx_add_vid
3122 * @dev: net device pointer.
3125 * Remove the vlan id from the device's vlan id table
3128 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3130 struct vxgedev *vdev;
3131 struct vxge_vpath *vpath;
3134 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3136 vdev = (struct vxgedev *)netdev_priv(dev);
3138 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3140 /* Delete this vlan from the vid table */
3141 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3142 vpath = &vdev->vpaths[vp_id];
3143 if (!vpath->is_open)
3145 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3147 vxge_debug_entryexit(VXGE_TRACE,
3148 "%s:%d Exiting...", __func__, __LINE__);
3151 static const struct net_device_ops vxge_netdev_ops = {
3152 .ndo_open = vxge_open,
3153 .ndo_stop = vxge_close,
3154 .ndo_get_stats = vxge_get_stats,
3155 .ndo_start_xmit = vxge_xmit,
3156 .ndo_validate_addr = eth_validate_addr,
3157 .ndo_set_multicast_list = vxge_set_multicast,
3159 .ndo_do_ioctl = vxge_ioctl,
3161 .ndo_set_mac_address = vxge_set_mac_addr,
3162 .ndo_change_mtu = vxge_change_mtu,
3163 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3164 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3165 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3167 .ndo_tx_timeout = vxge_tx_watchdog,
3168 #ifdef CONFIG_NET_POLL_CONTROLLER
3169 .ndo_poll_controller = vxge_netpoll,
3173 int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3174 struct vxge_config *config,
3175 int high_dma, int no_of_vpath,
3176 struct vxgedev **vdev_out)
3178 struct net_device *ndev;
3179 enum vxge_hw_status status = VXGE_HW_OK;
3180 struct vxgedev *vdev;
3181 int i, ret = 0, no_of_queue = 1;
3185 if (config->tx_steering_type)
3186 no_of_queue = no_of_vpath;
3188 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3192 vxge_hw_device_trace_level_get(hldev),
3193 "%s : device allocation failed", __func__);
3198 vxge_debug_entryexit(
3199 vxge_hw_device_trace_level_get(hldev),
3200 "%s: %s:%d Entering...",
3201 ndev->name, __func__, __LINE__);
3203 vdev = netdev_priv(ndev);
3204 memset(vdev, 0, sizeof(struct vxgedev));
3208 vdev->pdev = hldev->pdev;
3209 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3210 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3212 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3214 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3215 NETIF_F_HW_VLAN_FILTER;
3216 /* Driver entry points */
3217 ndev->irq = vdev->pdev->irq;
3218 ndev->base_addr = (unsigned long) hldev->bar0;
3220 ndev->netdev_ops = &vxge_netdev_ops;
3222 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3224 initialize_ethtool_ops(ndev);
3226 /* Allocate memory for vpath */
3227 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3228 no_of_vpath, GFP_KERNEL);
3229 if (!vdev->vpaths) {
3230 vxge_debug_init(VXGE_ERR,
3231 "%s: vpath memory allocation failed",
3237 ndev->features |= NETIF_F_SG;
3239 ndev->features |= NETIF_F_HW_CSUM;
3240 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3241 "%s : checksuming enabled", __func__);
3244 ndev->features |= NETIF_F_HIGHDMA;
3245 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3246 "%s : using High DMA", __func__);
3249 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3251 if (vdev->config.gro_enable)
3252 ndev->features |= NETIF_F_GRO;
3255 ndev->features |= NETIF_F_LLTX;
3258 for (i = 0; i < no_of_vpath; i++)
3259 spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
3261 if (register_netdev(ndev)) {
3262 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3263 "%s: %s : device registration failed!",
3264 ndev->name, __func__);
3269 /* Set the factory defined MAC address initially */
3270 ndev->addr_len = ETH_ALEN;
3272 /* Make Link state as off at this point, when the Link change
3273 * interrupt comes the state will be automatically changed to
3276 netif_carrier_off(ndev);
3278 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3279 "%s: Ethernet device registered",
3284 /* Resetting the Device stats */
3285 status = vxge_hw_mrpcim_stats_access(
3287 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3292 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3294 vxge_hw_device_trace_level_get(hldev),
3295 "%s: device stats clear returns"
3296 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3298 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3299 "%s: %s:%d Exiting...",
3300 ndev->name, __func__, __LINE__);
3304 kfree(vdev->vpaths);
3312 * vxge_device_unregister
3314 * This function will unregister and free network device
3317 vxge_device_unregister(struct __vxge_hw_device *hldev)
3319 struct vxgedev *vdev;
3320 struct net_device *dev;
3322 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3323 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3328 vdev = netdev_priv(dev);
3329 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3330 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3331 level_trace = vdev->level_trace;
3333 vxge_debug_entryexit(level_trace,
3334 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3336 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3338 /* in 2.6 will call stop() if device is up */
3339 unregister_netdev(dev);
3341 flush_scheduled_work();
3343 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3344 vxge_debug_entryexit(level_trace,
3345 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3349 * vxge_callback_crit_err
3351 * This function is called by the alarm handler in interrupt context.
3352 * Driver must analyze it based on the event type.
3355 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3356 enum vxge_hw_event type, u64 vp_id)
3358 struct net_device *dev = hldev->ndev;
3359 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3362 vxge_debug_entryexit(vdev->level_trace,
3363 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3365 /* Note: This event type should be used for device wide
3366 * indications only - Serious errors, Slot freeze and critical errors
3368 vdev->cric_err_event = type;
3370 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
3371 if (vdev->vpaths[vpath_idx].device_id == vp_id)
3374 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3375 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3376 vxge_debug_init(VXGE_ERR,
3377 "%s: Slot is frozen", vdev->ndev->name);
3378 } else if (type == VXGE_HW_EVENT_SERR) {
3379 vxge_debug_init(VXGE_ERR,
3380 "%s: Encountered Serious Error",
3382 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3383 vxge_debug_init(VXGE_ERR,
3384 "%s: Encountered Critical Error",
3388 if ((type == VXGE_HW_EVENT_SERR) ||
3389 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3390 if (unlikely(vdev->exec_mode))
3391 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3392 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3393 vxge_hw_device_mask_all(hldev);
3394 if (unlikely(vdev->exec_mode))
3395 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3396 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3397 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3399 if (unlikely(vdev->exec_mode))
3400 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3402 /* check if this vpath is already set for reset */
3403 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3405 /* disable interrupts for this vpath */
3406 vxge_vpath_intr_disable(vdev, vpath_idx);
3408 /* stop the queue for this vpath */
3409 vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
3415 vxge_debug_entryexit(vdev->level_trace,
3416 "%s: %s:%d Exiting...",
3417 vdev->ndev->name, __func__, __LINE__);
3420 static void verify_bandwidth(void)
3422 int i, band_width, total = 0, equal_priority = 0;
3424 /* 1. If user enters 0 for some fifo, give equal priority to all */
3425 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3426 if (bw_percentage[i] == 0) {
3432 if (!equal_priority) {
3433 /* 2. If sum exceeds 100, give equal priority to all */
3434 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3435 if (bw_percentage[i] == 0xFF)
3438 total += bw_percentage[i];
3439 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3446 if (!equal_priority) {
3447 /* Is all the bandwidth consumed? */
3448 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3449 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3450 /* Split rest of bw equally among next VPs*/
3452 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3453 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3454 if (band_width < 2) /* min of 2% */
3457 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3463 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3467 if (equal_priority) {
3468 vxge_debug_init(VXGE_ERR,
3469 "%s: Assigning equal bandwidth to all the vpaths",
3471 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3472 VXGE_HW_MAX_VIRTUAL_PATHS;
3473 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3474 bw_percentage[i] = bw_percentage[0];
3479 * Vpath configuration
3481 static int __devinit vxge_config_vpaths(
3482 struct vxge_hw_device_config *device_config,
3483 u64 vpath_mask, struct vxge_config *config_param)
3485 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3486 u32 txdl_size, txdl_per_memblock;
3488 temp = driver_config->vpath_per_dev;
3489 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3490 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3491 /* No more CPU. Return vpath number as zero.*/
3492 if (driver_config->g_no_cpus == -1)
3495 if (!driver_config->g_no_cpus)
3496 driver_config->g_no_cpus = num_online_cpus();
3498 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3499 if (!driver_config->vpath_per_dev)
3500 driver_config->vpath_per_dev = 1;
3502 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3503 if (!vxge_bVALn(vpath_mask, i, 1))
3507 if (default_no_vpath < driver_config->vpath_per_dev)
3508 driver_config->vpath_per_dev = default_no_vpath;
3510 driver_config->g_no_cpus = driver_config->g_no_cpus -
3511 (driver_config->vpath_per_dev * 2);
3512 if (driver_config->g_no_cpus <= 0)
3513 driver_config->g_no_cpus = -1;
3516 if (driver_config->vpath_per_dev == 1) {
3517 vxge_debug_ll_config(VXGE_TRACE,
3518 "%s: Disable tx and rx steering, "
3519 "as single vpath is configured", VXGE_DRIVER_NAME);
3520 config_param->rth_steering = NO_STEERING;
3521 config_param->tx_steering_type = NO_STEERING;
3522 device_config->rth_en = 0;
3525 /* configure bandwidth */
3526 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3527 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3529 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3530 device_config->vp_config[i].vp_id = i;
3531 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3532 if (no_of_vpaths < driver_config->vpath_per_dev) {
3533 if (!vxge_bVALn(vpath_mask, i, 1)) {
3534 vxge_debug_ll_config(VXGE_TRACE,
3535 "%s: vpath: %d is not available",
3536 VXGE_DRIVER_NAME, i);
3539 vxge_debug_ll_config(VXGE_TRACE,
3540 "%s: vpath: %d available",
3541 VXGE_DRIVER_NAME, i);
3545 vxge_debug_ll_config(VXGE_TRACE,
3546 "%s: vpath: %d is not configured, "
3547 "max_config_vpath exceeded",
3548 VXGE_DRIVER_NAME, i);
3552 /* Configure Tx fifo's */
3553 device_config->vp_config[i].fifo.enable =
3554 VXGE_HW_FIFO_ENABLE;
3555 device_config->vp_config[i].fifo.max_frags =
3557 device_config->vp_config[i].fifo.memblock_size =
3558 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3560 txdl_size = device_config->vp_config[i].fifo.max_frags *
3561 sizeof(struct vxge_hw_fifo_txd);
3562 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3564 device_config->vp_config[i].fifo.fifo_blocks =
3565 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3567 device_config->vp_config[i].fifo.intr =
3568 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3570 /* Configure tti properties */
3571 device_config->vp_config[i].tti.intr_enable =
3572 VXGE_HW_TIM_INTR_ENABLE;
3574 device_config->vp_config[i].tti.btimer_val =
3575 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3577 device_config->vp_config[i].tti.timer_ac_en =
3578 VXGE_HW_TIM_TIMER_AC_ENABLE;
3580 /* For msi-x with napi (each vector
3581 has a handler of its own) -
3582 Set CI to OFF for all vpaths */
3583 device_config->vp_config[i].tti.timer_ci_en =
3584 VXGE_HW_TIM_TIMER_CI_DISABLE;
3586 device_config->vp_config[i].tti.timer_ri_en =
3587 VXGE_HW_TIM_TIMER_RI_DISABLE;
3589 device_config->vp_config[i].tti.util_sel =
3590 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3592 device_config->vp_config[i].tti.ltimer_val =
3593 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3595 device_config->vp_config[i].tti.rtimer_val =
3596 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3598 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3599 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3600 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3601 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3602 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3603 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3604 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3606 /* Configure Rx rings */
3607 device_config->vp_config[i].ring.enable =
3608 VXGE_HW_RING_ENABLE;
3610 device_config->vp_config[i].ring.ring_blocks =
3611 VXGE_HW_DEF_RING_BLOCKS;
3612 device_config->vp_config[i].ring.buffer_mode =
3613 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3614 device_config->vp_config[i].ring.rxds_limit =
3615 VXGE_HW_DEF_RING_RXDS_LIMIT;
3616 device_config->vp_config[i].ring.scatter_mode =
3617 VXGE_HW_RING_SCATTER_MODE_A;
3619 /* Configure rti properties */
3620 device_config->vp_config[i].rti.intr_enable =
3621 VXGE_HW_TIM_INTR_ENABLE;
3623 device_config->vp_config[i].rti.btimer_val =
3624 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3626 device_config->vp_config[i].rti.timer_ac_en =
3627 VXGE_HW_TIM_TIMER_AC_ENABLE;
3629 device_config->vp_config[i].rti.timer_ci_en =
3630 VXGE_HW_TIM_TIMER_CI_DISABLE;
3632 device_config->vp_config[i].rti.timer_ri_en =
3633 VXGE_HW_TIM_TIMER_RI_DISABLE;
3635 device_config->vp_config[i].rti.util_sel =
3636 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3638 device_config->vp_config[i].rti.urange_a =
3640 device_config->vp_config[i].rti.urange_b =
3642 device_config->vp_config[i].rti.urange_c =
3644 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3645 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3646 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3647 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3649 device_config->vp_config[i].rti.rtimer_val =
3650 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3652 device_config->vp_config[i].rti.ltimer_val =
3653 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3655 device_config->vp_config[i].rpa_strip_vlan_tag =
3659 driver_config->vpath_per_dev = temp;
3660 return no_of_vpaths;
3663 /* initialize device configuratrions */
3664 static void __devinit vxge_device_config_init(
3665 struct vxge_hw_device_config *device_config,
3668 /* Used for CQRQ/SRQ. */
3669 device_config->dma_blockpool_initial =
3670 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3672 device_config->dma_blockpool_max =
3673 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3675 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3676 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3678 #ifndef CONFIG_PCI_MSI
3679 vxge_debug_init(VXGE_ERR,
3680 "%s: This Kernel does not support "
3681 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3685 /* Configure whether MSI-X or IRQL. */
3686 switch (*intr_type) {
3688 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3692 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3695 /* Timer period between device poll */
3696 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3698 /* Configure mac based steering. */
3699 device_config->rts_mac_en = addr_learn_en;
3701 /* Configure Vpaths */
3702 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3704 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3706 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3707 device_config->dma_blockpool_initial);
3708 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3709 device_config->dma_blockpool_max);
3710 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3711 device_config->intr_mode);
3712 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3713 device_config->device_poll_millis);
3714 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3715 device_config->rts_mac_en);
3716 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3717 device_config->rth_en);
3718 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3719 device_config->rth_it_type);
3722 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3726 vxge_debug_init(VXGE_TRACE,
3727 "%s: %d Vpath(s) opened",
3728 vdev->ndev->name, vdev->no_of_vpath);
3730 switch (vdev->config.intr_type) {
3732 vxge_debug_init(VXGE_TRACE,
3733 "%s: Interrupt type INTA", vdev->ndev->name);
3737 vxge_debug_init(VXGE_TRACE,
3738 "%s: Interrupt type MSI-X", vdev->ndev->name);
3742 if (vdev->config.rth_steering) {
3743 vxge_debug_init(VXGE_TRACE,
3744 "%s: RTH steering enabled for TCP_IPV4",
3747 vxge_debug_init(VXGE_TRACE,
3748 "%s: RTH steering disabled", vdev->ndev->name);
3751 switch (vdev->config.tx_steering_type) {
3753 vxge_debug_init(VXGE_TRACE,
3754 "%s: Tx steering disabled", vdev->ndev->name);
3756 case TX_PRIORITY_STEERING:
3757 vxge_debug_init(VXGE_TRACE,
3758 "%s: Unsupported tx steering option",
3760 vxge_debug_init(VXGE_TRACE,
3761 "%s: Tx steering disabled", vdev->ndev->name);
3762 vdev->config.tx_steering_type = 0;
3764 case TX_VLAN_STEERING:
3765 vxge_debug_init(VXGE_TRACE,
3766 "%s: Unsupported tx steering option",
3768 vxge_debug_init(VXGE_TRACE,
3769 "%s: Tx steering disabled", vdev->ndev->name);
3770 vdev->config.tx_steering_type = 0;
3772 case TX_MULTIQ_STEERING:
3773 vxge_debug_init(VXGE_TRACE,
3774 "%s: Tx multiqueue steering enabled",
3777 case TX_PORT_STEERING:
3778 vxge_debug_init(VXGE_TRACE,
3779 "%s: Tx port steering enabled",
3783 vxge_debug_init(VXGE_ERR,
3784 "%s: Unsupported tx steering type",
3786 vxge_debug_init(VXGE_TRACE,
3787 "%s: Tx steering disabled", vdev->ndev->name);
3788 vdev->config.tx_steering_type = 0;
3791 if (vdev->config.gro_enable) {
3792 vxge_debug_init(VXGE_ERR,
3793 "%s: Generic receive offload enabled",
3796 vxge_debug_init(VXGE_TRACE,
3797 "%s: Generic receive offload disabled",
3800 if (vdev->config.addr_learn_en)
3801 vxge_debug_init(VXGE_TRACE,
3802 "%s: MAC Address learning enabled", vdev->ndev->name);
3804 vxge_debug_init(VXGE_TRACE,
3805 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3807 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3808 if (!vxge_bVALn(vpath_mask, i, 1))
3810 vxge_debug_ll_config(VXGE_TRACE,
3811 "%s: MTU size - %d", vdev->ndev->name,
3812 ((struct __vxge_hw_device *)(vdev->devh))->
3813 config.vp_config[i].mtu);
3814 vxge_debug_init(VXGE_TRACE,
3815 "%s: VLAN tag stripping %s", vdev->ndev->name,
3816 ((struct __vxge_hw_device *)(vdev->devh))->
3817 config.vp_config[i].rpa_strip_vlan_tag
3818 ? "Enabled" : "Disabled");
3819 vxge_debug_init(VXGE_TRACE,
3820 "%s: Ring blocks : %d", vdev->ndev->name,
3821 ((struct __vxge_hw_device *)(vdev->devh))->
3822 config.vp_config[i].ring.ring_blocks);
3823 vxge_debug_init(VXGE_TRACE,
3824 "%s: Fifo blocks : %d", vdev->ndev->name,
3825 ((struct __vxge_hw_device *)(vdev->devh))->
3826 config.vp_config[i].fifo.fifo_blocks);
3827 vxge_debug_ll_config(VXGE_TRACE,
3828 "%s: Max frags : %d", vdev->ndev->name,
3829 ((struct __vxge_hw_device *)(vdev->devh))->
3830 config.vp_config[i].fifo.max_frags);
3837 * vxge_pm_suspend - vxge power management suspend entry point
3840 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3845 * vxge_pm_resume - vxge power management resume entry point
3848 static int vxge_pm_resume(struct pci_dev *pdev)
3856 * vxge_io_error_detected - called when PCI error is detected
3857 * @pdev: Pointer to PCI device
3858 * @state: The current pci connection state
3860 * This function is called after a PCI bus error affecting
3861 * this device has been detected.
3863 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3864 pci_channel_state_t state)
3866 struct __vxge_hw_device *hldev =
3867 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3868 struct net_device *netdev = hldev->ndev;
3870 netif_device_detach(netdev);
3872 if (state == pci_channel_io_perm_failure)
3873 return PCI_ERS_RESULT_DISCONNECT;
3875 if (netif_running(netdev)) {
3876 /* Bring down the card, while avoiding PCI I/O */
3877 do_vxge_close(netdev, 0);
3880 pci_disable_device(pdev);
3882 return PCI_ERS_RESULT_NEED_RESET;
3886 * vxge_io_slot_reset - called after the pci bus has been reset.
3887 * @pdev: Pointer to PCI device
3889 * Restart the card from scratch, as if from a cold-boot.
3890 * At this point, the card has exprienced a hard reset,
3891 * followed by fixups by BIOS, and has its config space
3892 * set up identically to what it was at cold boot.
3894 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3896 struct __vxge_hw_device *hldev =
3897 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3898 struct net_device *netdev = hldev->ndev;
3900 struct vxgedev *vdev = netdev_priv(netdev);
3902 if (pci_enable_device(pdev)) {
3903 printk(KERN_ERR "%s: "
3904 "Cannot re-enable device after reset\n",
3906 return PCI_ERS_RESULT_DISCONNECT;
3909 pci_set_master(pdev);
3912 return PCI_ERS_RESULT_RECOVERED;
3916 * vxge_io_resume - called when traffic can start flowing again.
3917 * @pdev: Pointer to PCI device
3919 * This callback is called when the error recovery driver tells
3920 * us that its OK to resume normal operation.
3922 static void vxge_io_resume(struct pci_dev *pdev)
3924 struct __vxge_hw_device *hldev =
3925 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3926 struct net_device *netdev = hldev->ndev;
3928 if (netif_running(netdev)) {
3929 if (vxge_open(netdev)) {
3930 printk(KERN_ERR "%s: "
3931 "Can't bring device back up after reset\n",
3937 netif_device_attach(netdev);
3940 static inline u32 vxge_get_num_vfs(u64 function_mode)
3942 u32 num_functions = 0;
3944 switch (function_mode) {
3945 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
3946 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
3949 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
3952 case VXGE_HW_FUNCTION_MODE_SRIOV:
3953 case VXGE_HW_FUNCTION_MODE_MRIOV:
3954 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
3957 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
3960 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
3963 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
3964 num_functions = 8; /* TODO */
3967 return num_functions;
3972 * @pdev : structure containing the PCI related information of the device.
3973 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
3975 * This function is called when a new PCI device gets detected and initializes
3978 * returns 0 on success and negative on failure.
3981 static int __devinit
3982 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
3984 struct __vxge_hw_device *hldev;
3985 enum vxge_hw_status status;
3989 struct vxgedev *vdev;
3990 struct vxge_config *ll_config = NULL;
3991 struct vxge_hw_device_config *device_config = NULL;
3992 struct vxge_hw_device_attr attr;
3993 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
3995 struct vxge_mac_addrs *entry;
3996 static int bus = -1, device = -1;
3999 enum vxge_hw_status is_privileged;
4003 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4006 /* In SRIOV-17 mode, functions of the same adapter
4007 * can be deployed on different buses */
4008 if ((!pdev->is_virtfn) && ((bus != pdev->bus->number) ||
4009 (device != PCI_SLOT(pdev->devfn))))
4012 bus = pdev->bus->number;
4013 device = PCI_SLOT(pdev->devfn);
4016 if (driver_config->config_dev_cnt &&
4017 (driver_config->config_dev_cnt !=
4018 driver_config->total_dev_cnt))
4019 vxge_debug_init(VXGE_ERR,
4020 "%s: Configured %d of %d devices",
4022 driver_config->config_dev_cnt,
4023 driver_config->total_dev_cnt);
4024 driver_config->config_dev_cnt = 0;
4025 driver_config->total_dev_cnt = 0;
4027 /* Now making the CPU based no of vpath calculation
4028 * applicable for individual functions as well.
4030 driver_config->g_no_cpus = 0;
4031 driver_config->vpath_per_dev = max_config_vpath;
4033 driver_config->total_dev_cnt++;
4034 if (++driver_config->config_dev_cnt > max_config_dev) {
4039 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4041 if (!device_config) {
4043 vxge_debug_init(VXGE_ERR,
4044 "device_config : malloc failed %s %d",
4045 __FILE__, __LINE__);
4049 ll_config = kzalloc(sizeof(*ll_config), GFP_KERNEL);
4052 vxge_debug_init(VXGE_ERR,
4053 "ll_config : malloc failed %s %d",
4054 __FILE__, __LINE__);
4057 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4058 ll_config->intr_type = MSI_X;
4059 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4060 ll_config->rth_steering = RTH_STEERING;
4062 /* get the default configuration parameters */
4063 vxge_hw_device_config_default_get(device_config);
4065 /* initialize configuration parameters */
4066 vxge_device_config_init(device_config, &ll_config->intr_type);
4068 ret = pci_enable_device(pdev);
4070 vxge_debug_init(VXGE_ERR,
4071 "%s : can not enable PCI device", __func__);
4075 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
4076 vxge_debug_ll_config(VXGE_TRACE,
4077 "%s : using 64bit DMA", __func__);
4081 if (pci_set_consistent_dma_mask(pdev,
4082 DMA_BIT_MASK(64))) {
4083 vxge_debug_init(VXGE_ERR,
4084 "%s : unable to obtain 64bit DMA for "
4085 "consistent allocations", __func__);
4089 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
4090 vxge_debug_ll_config(VXGE_TRACE,
4091 "%s : using 32bit DMA", __func__);
4097 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4098 vxge_debug_init(VXGE_ERR,
4099 "%s : request regions failed", __func__);
4104 pci_set_master(pdev);
4106 attr.bar0 = pci_ioremap_bar(pdev, 0);
4108 vxge_debug_init(VXGE_ERR,
4109 "%s : cannot remap io memory bar0", __func__);
4113 vxge_debug_ll_config(VXGE_TRACE,
4114 "pci ioremap bar0: %p:0x%llx",
4116 (unsigned long long)pci_resource_start(pdev, 0));
4118 status = vxge_hw_device_hw_info_get(attr.bar0,
4119 &ll_config->device_hw_info);
4120 if (status != VXGE_HW_OK) {
4121 vxge_debug_init(VXGE_ERR,
4122 "%s: Reading of hardware info failed."
4123 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4128 if (ll_config->device_hw_info.fw_version.major !=
4129 VXGE_DRIVER_FW_VERSION_MAJOR) {
4130 vxge_debug_init(VXGE_ERR,
4131 "%s: Incorrect firmware version."
4132 "Please upgrade the firmware to version 1.x.x",
4138 vpath_mask = ll_config->device_hw_info.vpath_mask;
4139 if (vpath_mask == 0) {
4140 vxge_debug_ll_config(VXGE_TRACE,
4141 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4146 vxge_debug_ll_config(VXGE_TRACE,
4147 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4148 (unsigned long long)vpath_mask);
4150 function_mode = ll_config->device_hw_info.function_mode;
4151 host_type = ll_config->device_hw_info.host_type;
4152 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4153 ll_config->device_hw_info.func_id);
4155 /* Check how many vpaths are available */
4156 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4157 if (!((vpath_mask) & vxge_mBIT(i)))
4159 max_vpath_supported++;
4163 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4165 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4166 if (is_sriov(function_mode) && (max_config_dev > 1) &&
4167 (ll_config->intr_type != INTA) &&
4168 (is_privileged == VXGE_HW_OK)) {
4169 ret = pci_enable_sriov(pdev, ((max_config_dev - 1) < num_vfs)
4170 ? (max_config_dev - 1) : num_vfs);
4172 vxge_debug_ll_config(VXGE_ERR,
4173 "Failed in enabling SRIOV mode: %d\n", ret);
4177 * Configure vpaths and get driver configured number of vpaths
4178 * which is less than or equal to the maximum vpaths per function.
4180 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
4182 vxge_debug_ll_config(VXGE_ERR,
4183 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4188 /* Setting driver callbacks */
4189 attr.uld_callbacks.link_up = vxge_callback_link_up;
4190 attr.uld_callbacks.link_down = vxge_callback_link_down;
4191 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4193 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4194 if (status != VXGE_HW_OK) {
4195 vxge_debug_init(VXGE_ERR,
4196 "Failed to initialize device (%d)", status);
4201 /* if FCS stripping is not disabled in MAC fail driver load */
4202 if (vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask) != VXGE_HW_OK) {
4203 vxge_debug_init(VXGE_ERR,
4204 "%s: FCS stripping is not disabled in MAC"
4205 " failing driver load", VXGE_DRIVER_NAME);
4210 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4212 /* set private device info */
4213 pci_set_drvdata(pdev, hldev);
4215 ll_config->gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4216 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4217 ll_config->addr_learn_en = addr_learn_en;
4218 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4219 ll_config->rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
4220 ll_config->rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
4221 ll_config->rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4222 ll_config->rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4223 ll_config->rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4224 ll_config->rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4225 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4226 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4227 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4229 if (vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4235 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4236 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4237 vxge_hw_device_trace_level_get(hldev));
4239 /* set private HW device info */
4240 hldev->ndev = vdev->ndev;
4241 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4242 vdev->bar0 = attr.bar0;
4243 vdev->max_vpath_supported = max_vpath_supported;
4244 vdev->no_of_vpath = no_of_vpath;
4246 /* Virtual Path count */
4247 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4248 if (!vxge_bVALn(vpath_mask, i, 1))
4250 if (j >= vdev->no_of_vpath)
4253 vdev->vpaths[j].is_configured = 1;
4254 vdev->vpaths[j].device_id = i;
4255 vdev->vpaths[j].fifo.driver_id = j;
4256 vdev->vpaths[j].ring.driver_id = j;
4257 vdev->vpaths[j].vdev = vdev;
4258 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4259 memcpy((u8 *)vdev->vpaths[j].macaddr,
4260 ll_config->device_hw_info.mac_addrs[i],
4263 /* Initialize the mac address list header */
4264 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4266 vdev->vpaths[j].mac_addr_cnt = 0;
4267 vdev->vpaths[j].mcast_addr_cnt = 0;
4270 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4271 vdev->max_config_port = max_config_port;
4273 vdev->vlan_tag_strip = vlan_tag_strip;
4275 /* map the hashing selector table to the configured vpaths */
4276 for (i = 0; i < vdev->no_of_vpath; i++)
4277 vdev->vpath_selector[i] = vpath_selector[i];
4279 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4281 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4282 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4283 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4285 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4286 vdev->ndev->name, ll_config->device_hw_info.serial_number);
4288 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4289 vdev->ndev->name, ll_config->device_hw_info.part_number);
4291 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4292 vdev->ndev->name, ll_config->device_hw_info.product_desc);
4294 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4295 vdev->ndev->name, macaddr);
4297 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4298 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4300 vxge_debug_init(VXGE_TRACE,
4301 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4302 ll_config->device_hw_info.fw_version.version,
4303 ll_config->device_hw_info.fw_date.date);
4306 switch (ll_config->device_hw_info.function_mode) {
4307 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4308 vxge_debug_init(VXGE_TRACE,
4309 "%s: Single Function Mode Enabled", vdev->ndev->name);
4311 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4312 vxge_debug_init(VXGE_TRACE,
4313 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4315 case VXGE_HW_FUNCTION_MODE_SRIOV:
4316 vxge_debug_init(VXGE_TRACE,
4317 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4319 case VXGE_HW_FUNCTION_MODE_MRIOV:
4320 vxge_debug_init(VXGE_TRACE,
4321 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4326 vxge_print_parm(vdev, vpath_mask);
4328 /* Store the fw version for ethttool option */
4329 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
4330 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4331 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4333 /* Copy the station mac address to the list */
4334 for (i = 0; i < vdev->no_of_vpath; i++) {
4335 entry = (struct vxge_mac_addrs *)
4336 kzalloc(sizeof(struct vxge_mac_addrs),
4338 if (NULL == entry) {
4339 vxge_debug_init(VXGE_ERR,
4340 "%s: mac_addr_list : memory allocation failed",
4345 macaddr = (u8 *)&entry->macaddr;
4346 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4347 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4348 vdev->vpaths[i].mac_addr_cnt = 1;
4351 kfree(device_config);
4354 * INTA is shared in multi-function mode. This is unlike the INTA
4355 * implementation in MR mode, where each VH has its own INTA message.
4356 * - INTA is masked (disabled) as long as at least one function sets
4357 * its TITAN_MASK_ALL_INT.ALARM bit.
4358 * - INTA is unmasked (enabled) when all enabled functions have cleared
4359 * their own TITAN_MASK_ALL_INT.ALARM bit.
4360 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4361 * Though this driver leaves the top level interrupts unmasked while
4362 * leaving the required module interrupt bits masked on exit, there
4363 * could be a rougue driver around that does not follow this procedure
4364 * resulting in a failure to generate interrupts. The following code is
4365 * present to prevent such a failure.
4368 if (ll_config->device_hw_info.function_mode ==
4369 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4370 if (vdev->config.intr_type == INTA)
4371 vxge_hw_device_unmask_all(hldev);
4373 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4374 vdev->ndev->name, __func__, __LINE__);
4376 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4377 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4378 vxge_hw_device_trace_level_get(hldev));
4384 for (i = 0; i < vdev->no_of_vpath; i++)
4385 vxge_free_mac_add_list(&vdev->vpaths[i]);
4387 vxge_device_unregister(hldev);
4389 pci_disable_sriov(pdev);
4390 vxge_hw_device_terminate(hldev);
4394 pci_release_regions(pdev);
4396 pci_disable_device(pdev);
4399 kfree(device_config);
4400 driver_config->config_dev_cnt--;
4401 pci_set_drvdata(pdev, NULL);
4406 * vxge_rem_nic - Free the PCI device
4407 * @pdev: structure containing the PCI related information of the device.
4408 * Description: This function is called by the Pci subsystem to release a
4409 * PCI device and free up all resource held up by the device.
4411 static void __devexit
4412 vxge_remove(struct pci_dev *pdev)
4414 struct __vxge_hw_device *hldev;
4415 struct vxgedev *vdev = NULL;
4416 struct net_device *dev;
4418 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4419 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4423 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4428 vdev = netdev_priv(dev);
4430 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4431 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4432 level_trace = vdev->level_trace;
4434 vxge_debug_entryexit(level_trace,
4435 "%s:%d", __func__, __LINE__);
4437 vxge_debug_init(level_trace,
4438 "%s : removing PCI device...", __func__);
4439 vxge_device_unregister(hldev);
4441 for (i = 0; i < vdev->no_of_vpath; i++) {
4442 vxge_free_mac_add_list(&vdev->vpaths[i]);
4443 vdev->vpaths[i].mcast_addr_cnt = 0;
4444 vdev->vpaths[i].mac_addr_cnt = 0;
4447 kfree(vdev->vpaths);
4449 iounmap(vdev->bar0);
4451 pci_disable_sriov(pdev);
4453 /* we are safe to free it now */
4456 vxge_debug_init(level_trace,
4457 "%s:%d Device unregistered", __func__, __LINE__);
4459 vxge_hw_device_terminate(hldev);
4461 pci_disable_device(pdev);
4462 pci_release_regions(pdev);
4463 pci_set_drvdata(pdev, NULL);
4464 vxge_debug_entryexit(level_trace,
4465 "%s:%d Exiting...", __func__, __LINE__);
4468 static struct pci_error_handlers vxge_err_handler = {
4469 .error_detected = vxge_io_error_detected,
4470 .slot_reset = vxge_io_slot_reset,
4471 .resume = vxge_io_resume,
4474 static struct pci_driver vxge_driver = {
4475 .name = VXGE_DRIVER_NAME,
4476 .id_table = vxge_id_table,
4477 .probe = vxge_probe,
4478 .remove = __devexit_p(vxge_remove),
4480 .suspend = vxge_pm_suspend,
4481 .resume = vxge_pm_resume,
4483 .err_handler = &vxge_err_handler,
4491 snprintf(version, 32, "%s", DRV_VERSION);
4493 printk(KERN_INFO "%s: Copyright(c) 2002-2009 Neterion Inc\n",
4495 printk(KERN_INFO "%s: Driver version: %s\n",
4496 VXGE_DRIVER_NAME, version);
4500 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4504 ret = pci_register_driver(&vxge_driver);
4506 if (driver_config->config_dev_cnt &&
4507 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4508 vxge_debug_init(VXGE_ERR,
4509 "%s: Configured %d of %d devices",
4510 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4511 driver_config->total_dev_cnt);
4514 kfree(driver_config);
4522 pci_unregister_driver(&vxge_driver);
4523 kfree(driver_config);
4525 module_init(vxge_starter);
4526 module_exit(vxge_closer);