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/tcp.h>
48 #include <linux/netdevice.h>
49 #include <linux/etherdevice.h>
50 #include "vxge-main.h"
53 MODULE_LICENSE("Dual BSD/GPL");
54 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
55 "Virtualized Server Adapter");
57 static struct pci_device_id vxge_id_table[] __devinitdata = {
58 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
60 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
65 MODULE_DEVICE_TABLE(pci, vxge_id_table);
67 VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
68 VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
69 VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
70 VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
71 VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
72 VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
74 static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
75 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
76 static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
77 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
78 module_param_array(bw_percentage, uint, NULL, 0);
80 static struct vxge_drv_config *driver_config;
82 static inline int is_vxge_card_up(struct vxgedev *vdev)
84 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
87 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
89 unsigned long flags = 0;
90 struct sk_buff *skb_ptr = NULL;
91 struct sk_buff **temp, *head, *skb;
93 if (spin_trylock_irqsave(&fifo->tx_lock, flags)) {
94 vxge_hw_vpath_poll_tx(fifo->handle, (void **)&skb_ptr);
95 spin_unlock_irqrestore(&fifo->tx_lock, flags);
101 temp = (struct sk_buff **)&skb->cb;
104 dev_kfree_skb_irq(skb);
108 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
112 /* Complete all transmits */
113 for (i = 0; i < vdev->no_of_vpath; i++)
114 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
117 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
120 struct vxge_ring *ring;
122 /* Complete all receives*/
123 for (i = 0; i < vdev->no_of_vpath; i++) {
124 ring = &vdev->vpaths[i].ring;
125 vxge_hw_vpath_poll_rx(ring->handle);
130 * MultiQ manipulation helper functions
132 void vxge_stop_all_tx_queue(struct vxgedev *vdev)
135 struct net_device *dev = vdev->ndev;
137 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
138 for (i = 0; i < vdev->no_of_vpath; i++)
139 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_STOP;
141 netif_tx_stop_all_queues(dev);
144 void vxge_stop_tx_queue(struct vxge_fifo *fifo)
146 struct net_device *dev = fifo->ndev;
148 struct netdev_queue *txq = NULL;
149 if (fifo->tx_steering_type == TX_MULTIQ_STEERING)
150 txq = netdev_get_tx_queue(dev, fifo->driver_id);
152 txq = netdev_get_tx_queue(dev, 0);
153 fifo->queue_state = VPATH_QUEUE_STOP;
156 netif_tx_stop_queue(txq);
159 void vxge_start_all_tx_queue(struct vxgedev *vdev)
162 struct net_device *dev = vdev->ndev;
164 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
165 for (i = 0; i < vdev->no_of_vpath; i++)
166 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
168 netif_tx_start_all_queues(dev);
171 static void vxge_wake_all_tx_queue(struct vxgedev *vdev)
174 struct net_device *dev = vdev->ndev;
176 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
177 for (i = 0; i < vdev->no_of_vpath; i++)
178 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
180 netif_tx_wake_all_queues(dev);
183 void vxge_wake_tx_queue(struct vxge_fifo *fifo, struct sk_buff *skb)
185 struct net_device *dev = fifo->ndev;
187 int vpath_no = fifo->driver_id;
188 struct netdev_queue *txq = NULL;
189 if (fifo->tx_steering_type == TX_MULTIQ_STEERING) {
190 txq = netdev_get_tx_queue(dev, vpath_no);
191 if (netif_tx_queue_stopped(txq))
192 netif_tx_wake_queue(txq);
194 txq = netdev_get_tx_queue(dev, 0);
195 if (fifo->queue_state == VPATH_QUEUE_STOP)
196 if (netif_tx_queue_stopped(txq)) {
197 fifo->queue_state = VPATH_QUEUE_START;
198 netif_tx_wake_queue(txq);
204 * vxge_callback_link_up
206 * This function is called during interrupt context to notify link up state
210 vxge_callback_link_up(struct __vxge_hw_device *hldev)
212 struct net_device *dev = hldev->ndev;
213 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
215 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
216 vdev->ndev->name, __func__, __LINE__);
217 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
218 vdev->stats.link_up++;
220 netif_carrier_on(vdev->ndev);
221 vxge_wake_all_tx_queue(vdev);
223 vxge_debug_entryexit(VXGE_TRACE,
224 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
228 * vxge_callback_link_down
230 * This function is called during interrupt context to notify link down state
234 vxge_callback_link_down(struct __vxge_hw_device *hldev)
236 struct net_device *dev = hldev->ndev;
237 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
239 vxge_debug_entryexit(VXGE_TRACE,
240 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
241 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
243 vdev->stats.link_down++;
244 netif_carrier_off(vdev->ndev);
245 vxge_stop_all_tx_queue(vdev);
247 vxge_debug_entryexit(VXGE_TRACE,
248 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
256 static struct sk_buff*
257 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
259 struct net_device *dev;
261 struct vxge_rx_priv *rx_priv;
264 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
265 ring->ndev->name, __func__, __LINE__);
267 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
269 /* try to allocate skb first. this one may fail */
270 skb = netdev_alloc_skb(dev, skb_size +
271 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
273 vxge_debug_mem(VXGE_ERR,
274 "%s: out of memory to allocate SKB", dev->name);
275 ring->stats.skb_alloc_fail++;
279 vxge_debug_mem(VXGE_TRACE,
280 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
281 __func__, __LINE__, skb);
283 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
286 rx_priv->data_size = skb_size;
287 vxge_debug_entryexit(VXGE_TRACE,
288 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
296 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
298 struct vxge_rx_priv *rx_priv;
301 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
302 ring->ndev->name, __func__, __LINE__);
303 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
305 dma_addr = pci_map_single(ring->pdev, rx_priv->skb->data,
306 rx_priv->data_size, PCI_DMA_FROMDEVICE);
309 ring->stats.pci_map_fail++;
312 vxge_debug_mem(VXGE_TRACE,
313 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
314 ring->ndev->name, __func__, __LINE__,
315 (unsigned long long)dma_addr);
316 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
318 rx_priv->data_dma = dma_addr;
319 vxge_debug_entryexit(VXGE_TRACE,
320 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
326 * vxge_rx_initial_replenish
327 * Allocation of RxD as an initial replenish procedure.
329 static enum vxge_hw_status
330 vxge_rx_initial_replenish(void *dtrh, void *userdata)
332 struct vxge_ring *ring = (struct vxge_ring *)userdata;
333 struct vxge_rx_priv *rx_priv;
335 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
336 ring->ndev->name, __func__, __LINE__);
337 if (vxge_rx_alloc(dtrh, ring,
338 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
341 if (vxge_rx_map(dtrh, ring)) {
342 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
343 dev_kfree_skb(rx_priv->skb);
347 vxge_debug_entryexit(VXGE_TRACE,
348 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
354 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
355 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
358 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
359 ring->ndev->name, __func__, __LINE__);
360 skb_record_rx_queue(skb, ring->driver_id);
361 skb->protocol = eth_type_trans(skb, ring->ndev);
363 ring->stats.rx_frms++;
364 ring->stats.rx_bytes += pkt_length;
366 if (skb->pkt_type == PACKET_MULTICAST)
367 ring->stats.rx_mcast++;
369 vxge_debug_rx(VXGE_TRACE,
370 "%s: %s:%d skb protocol = %d",
371 ring->ndev->name, __func__, __LINE__, skb->protocol);
373 if (ring->gro_enable) {
374 if (ring->vlgrp && ext_info->vlan &&
375 (ring->vlan_tag_strip ==
376 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
377 vlan_gro_receive(ring->napi_p, ring->vlgrp,
378 ext_info->vlan, skb);
380 napi_gro_receive(ring->napi_p, skb);
382 if (ring->vlgrp && vlan &&
383 (ring->vlan_tag_strip ==
384 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
385 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
387 netif_receive_skb(skb);
389 vxge_debug_entryexit(VXGE_TRACE,
390 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
393 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
394 struct vxge_rx_priv *rx_priv)
396 pci_dma_sync_single_for_device(ring->pdev,
397 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
399 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
400 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
403 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
404 void *post_dtr, struct __vxge_hw_ring *ringh)
406 int dtr_count = *dtr_cnt;
407 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
409 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
410 *first_dtr = post_dtr;
412 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
414 *dtr_cnt = dtr_count;
420 * If the interrupt is because of a received frame or if the receive ring
421 * contains fresh as yet un-processed frames, this function is called.
424 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
425 u8 t_code, void *userdata)
427 struct vxge_ring *ring = (struct vxge_ring *)userdata;
428 struct net_device *dev = ring->ndev;
429 unsigned int dma_sizes;
430 void *first_dtr = NULL;
436 struct vxge_rx_priv *rx_priv;
437 struct vxge_hw_ring_rxd_info ext_info;
438 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
439 ring->ndev->name, __func__, __LINE__);
440 ring->pkts_processed = 0;
442 vxge_hw_ring_replenish(ringh, 0);
445 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
447 data_size = rx_priv->data_size;
448 data_dma = rx_priv->data_dma;
450 vxge_debug_rx(VXGE_TRACE,
451 "%s: %s:%d skb = 0x%p",
452 ring->ndev->name, __func__, __LINE__, skb);
454 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
455 pkt_length = dma_sizes;
457 pkt_length -= ETH_FCS_LEN;
459 vxge_debug_rx(VXGE_TRACE,
460 "%s: %s:%d Packet Length = %d",
461 ring->ndev->name, __func__, __LINE__, pkt_length);
463 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
465 /* check skb validity */
468 prefetch((char *)skb + L1_CACHE_BYTES);
469 if (unlikely(t_code)) {
471 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
474 ring->stats.rx_errors++;
475 vxge_debug_rx(VXGE_TRACE,
476 "%s: %s :%d Rx T_code is %d",
477 ring->ndev->name, __func__,
480 /* If the t_code is not supported and if the
481 * t_code is other than 0x5 (unparseable packet
482 * such as unknown UPV6 header), Drop it !!!
484 vxge_re_pre_post(dtr, ring, rx_priv);
486 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
487 ring->stats.rx_dropped++;
492 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
494 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
496 if (!vxge_rx_map(dtr, ring)) {
497 skb_put(skb, pkt_length);
499 pci_unmap_single(ring->pdev, data_dma,
500 data_size, PCI_DMA_FROMDEVICE);
502 vxge_hw_ring_rxd_pre_post(ringh, dtr);
503 vxge_post(&dtr_cnt, &first_dtr, dtr,
506 dev_kfree_skb(rx_priv->skb);
508 rx_priv->data_size = data_size;
509 vxge_re_pre_post(dtr, ring, rx_priv);
511 vxge_post(&dtr_cnt, &first_dtr, dtr,
513 ring->stats.rx_dropped++;
517 vxge_re_pre_post(dtr, ring, rx_priv);
519 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
520 ring->stats.rx_dropped++;
524 struct sk_buff *skb_up;
526 skb_up = netdev_alloc_skb(dev, pkt_length +
527 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
528 if (skb_up != NULL) {
530 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
532 pci_dma_sync_single_for_cpu(ring->pdev,
536 vxge_debug_mem(VXGE_TRACE,
537 "%s: %s:%d skb_up = %p",
538 ring->ndev->name, __func__,
540 memcpy(skb_up->data, skb->data, pkt_length);
542 vxge_re_pre_post(dtr, ring, rx_priv);
544 vxge_post(&dtr_cnt, &first_dtr, dtr,
546 /* will netif_rx small SKB instead */
548 skb_put(skb, pkt_length);
550 vxge_re_pre_post(dtr, ring, rx_priv);
552 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
553 vxge_debug_rx(VXGE_ERR,
554 "%s: vxge_rx_1b_compl: out of "
555 "memory", dev->name);
556 ring->stats.skb_alloc_fail++;
561 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
562 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
563 ring->rx_csum && /* Offload Rx side CSUM */
564 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
565 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
566 skb->ip_summed = CHECKSUM_UNNECESSARY;
568 skb->ip_summed = CHECKSUM_NONE;
570 vxge_rx_complete(ring, skb, ext_info.vlan,
571 pkt_length, &ext_info);
574 ring->pkts_processed++;
578 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
579 &t_code) == VXGE_HW_OK);
582 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
584 dev->last_rx = jiffies;
586 vxge_debug_entryexit(VXGE_TRACE,
595 * If an interrupt was raised to indicate DMA complete of the Tx packet,
596 * this function is called. It identifies the last TxD whose buffer was
597 * freed and frees all skbs whose data have already DMA'ed into the NICs
601 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
602 enum vxge_hw_fifo_tcode t_code, void *userdata,
605 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
606 struct sk_buff *skb, *head = NULL;
607 struct sk_buff **temp;
610 vxge_debug_entryexit(VXGE_TRACE,
611 "%s:%d Entered....", __func__, __LINE__);
617 struct vxge_tx_priv *txd_priv =
618 vxge_hw_fifo_txdl_private_get(dtr);
621 frg_cnt = skb_shinfo(skb)->nr_frags;
622 frag = &skb_shinfo(skb)->frags[0];
624 vxge_debug_tx(VXGE_TRACE,
625 "%s: %s:%d fifo_hw = %p dtr = %p "
626 "tcode = 0x%x", fifo->ndev->name, __func__,
627 __LINE__, fifo_hw, dtr, t_code);
628 /* check skb validity */
630 vxge_debug_tx(VXGE_TRACE,
631 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
632 fifo->ndev->name, __func__, __LINE__,
633 skb, txd_priv, frg_cnt);
634 if (unlikely(t_code)) {
635 fifo->stats.tx_errors++;
636 vxge_debug_tx(VXGE_ERR,
637 "%s: tx: dtr %p completed due to "
638 "error t_code %01x", fifo->ndev->name,
640 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
643 /* for unfragmented skb */
644 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
645 skb_headlen(skb), PCI_DMA_TODEVICE);
647 for (j = 0; j < frg_cnt; j++) {
648 pci_unmap_page(fifo->pdev,
649 txd_priv->dma_buffers[i++],
650 frag->size, PCI_DMA_TODEVICE);
654 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
656 /* Updating the statistics block */
657 fifo->stats.tx_frms++;
658 fifo->stats.tx_bytes += skb->len;
660 temp = (struct sk_buff **)&skb->cb;
665 if (pkt_cnt > fifo->indicate_max_pkts)
668 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
669 &dtr, &t_code) == VXGE_HW_OK);
671 vxge_wake_tx_queue(fifo, skb);
674 *skb_ptr = (void *) head;
676 vxge_debug_entryexit(VXGE_TRACE,
677 "%s: %s:%d Exiting...",
678 fifo->ndev->name, __func__, __LINE__);
682 /* select a vpath to transmit the packet */
683 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb,
686 u16 queue_len, counter = 0;
687 if (skb->protocol == htons(ETH_P_IP)) {
693 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
694 th = (struct tcphdr *)(((unsigned char *)ip) +
697 queue_len = vdev->no_of_vpath;
698 counter = (ntohs(th->source) +
700 vdev->vpath_selector[queue_len - 1];
701 if (counter >= queue_len)
702 counter = queue_len - 1;
704 if (ip->protocol == IPPROTO_UDP) {
714 static enum vxge_hw_status vxge_search_mac_addr_in_list(
715 struct vxge_vpath *vpath, u64 del_mac)
717 struct list_head *entry, *next;
718 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
719 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
725 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
727 struct macInfo mac_info;
728 u8 *mac_address = NULL;
729 u64 mac_addr = 0, vpath_vector = 0;
731 enum vxge_hw_status status = VXGE_HW_OK;
732 struct vxge_vpath *vpath = NULL;
733 struct __vxge_hw_device *hldev;
735 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
737 mac_address = (u8 *)&mac_addr;
738 memcpy(mac_address, mac_header, ETH_ALEN);
740 /* Is this mac address already in the list? */
741 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
742 vpath = &vdev->vpaths[vpath_idx];
743 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
747 memset(&mac_info, 0, sizeof(struct macInfo));
748 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
750 /* Any vpath has room to add mac address to its da table? */
751 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
752 vpath = &vdev->vpaths[vpath_idx];
753 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
754 /* Add this mac address to this vpath */
755 mac_info.vpath_no = vpath_idx;
756 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
757 status = vxge_add_mac_addr(vdev, &mac_info);
758 if (status != VXGE_HW_OK)
764 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
766 mac_info.vpath_no = vpath_idx;
767 /* Is the first vpath already selected as catch-basin ? */
768 vpath = &vdev->vpaths[vpath_idx];
769 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
770 /* Add this mac address to this vpath */
771 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
776 /* Select first vpath as catch-basin */
777 vpath_vector = vxge_mBIT(vpath->device_id);
778 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
779 vxge_hw_mgmt_reg_type_mrpcim,
782 struct vxge_hw_mrpcim_reg,
785 if (status != VXGE_HW_OK) {
786 vxge_debug_tx(VXGE_ERR,
787 "%s: Unable to set the vpath-%d in catch-basin mode",
788 VXGE_DRIVER_NAME, vpath->device_id);
792 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
800 * @skb : the socket buffer containing the Tx data.
801 * @dev : device pointer.
803 * This function is the Tx entry point of the driver. Neterion NIC supports
804 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
805 * NOTE: when device cant queue the pkt, just the trans_start variable will
809 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
811 struct vxge_fifo *fifo = NULL;
814 struct vxgedev *vdev = NULL;
815 enum vxge_hw_status status;
816 int frg_cnt, first_frg_len;
818 int i = 0, j = 0, avail;
820 struct vxge_tx_priv *txdl_priv = NULL;
821 struct __vxge_hw_fifo *fifo_hw;
823 unsigned long flags = 0;
825 int do_spin_tx_lock = 1;
827 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
828 dev->name, __func__, __LINE__);
830 /* A buffer with no data will be dropped */
831 if (unlikely(skb->len <= 0)) {
832 vxge_debug_tx(VXGE_ERR,
833 "%s: Buffer has no data..", dev->name);
838 vdev = (struct vxgedev *)netdev_priv(dev);
840 if (unlikely(!is_vxge_card_up(vdev))) {
841 vxge_debug_tx(VXGE_ERR,
842 "%s: vdev not initialized", dev->name);
847 if (vdev->config.addr_learn_en) {
848 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
849 if (vpath_no == -EPERM) {
850 vxge_debug_tx(VXGE_ERR,
851 "%s: Failed to store the mac address",
858 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
859 vpath_no = skb_get_queue_mapping(skb);
860 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
861 vpath_no = vxge_get_vpath_no(vdev, skb, &do_spin_tx_lock);
863 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
865 if (vpath_no >= vdev->no_of_vpath)
868 fifo = &vdev->vpaths[vpath_no].fifo;
869 fifo_hw = fifo->handle;
872 spin_lock_irqsave(&fifo->tx_lock, flags);
874 if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
875 return NETDEV_TX_LOCKED;
878 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING) {
879 if (netif_subqueue_stopped(dev, skb)) {
880 spin_unlock_irqrestore(&fifo->tx_lock, flags);
881 return NETDEV_TX_BUSY;
883 } else if (unlikely(fifo->queue_state == VPATH_QUEUE_STOP)) {
884 if (netif_queue_stopped(dev)) {
885 spin_unlock_irqrestore(&fifo->tx_lock, flags);
886 return NETDEV_TX_BUSY;
889 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
891 vxge_debug_tx(VXGE_ERR,
892 "%s: No free TXDs available", dev->name);
893 fifo->stats.txd_not_free++;
894 vxge_stop_tx_queue(fifo);
898 /* Last TXD? Stop tx queue to avoid dropping packets. TX
899 * completion will resume the queue.
902 vxge_stop_tx_queue(fifo);
904 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
905 if (unlikely(status != VXGE_HW_OK)) {
906 vxge_debug_tx(VXGE_ERR,
907 "%s: Out of descriptors .", dev->name);
908 fifo->stats.txd_out_of_desc++;
909 vxge_stop_tx_queue(fifo);
913 vxge_debug_tx(VXGE_TRACE,
914 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
915 dev->name, __func__, __LINE__,
916 fifo_hw, dtr, dtr_priv);
918 if (vdev->vlgrp && vlan_tx_tag_present(skb)) {
919 u16 vlan_tag = vlan_tx_tag_get(skb);
920 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
923 first_frg_len = skb_headlen(skb);
925 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
928 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
929 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
930 vxge_stop_tx_queue(fifo);
931 fifo->stats.pci_map_fail++;
935 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
936 txdl_priv->skb = skb;
937 txdl_priv->dma_buffers[j] = dma_pointer;
939 frg_cnt = skb_shinfo(skb)->nr_frags;
940 vxge_debug_tx(VXGE_TRACE,
941 "%s: %s:%d skb = %p txdl_priv = %p "
942 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
943 __func__, __LINE__, skb, txdl_priv,
944 frg_cnt, (unsigned long long)dma_pointer);
946 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
949 frag = &skb_shinfo(skb)->frags[0];
950 for (i = 0; i < frg_cnt; i++) {
951 /* ignore 0 length fragment */
956 (u64)pci_map_page(fifo->pdev, frag->page,
957 frag->page_offset, frag->size,
960 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
962 vxge_debug_tx(VXGE_TRACE,
963 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
964 dev->name, __func__, __LINE__, i,
965 (unsigned long long)dma_pointer);
967 txdl_priv->dma_buffers[j] = dma_pointer;
968 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
973 offload_type = vxge_offload_type(skb);
975 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
977 int mss = vxge_tcp_mss(skb);
979 vxge_debug_tx(VXGE_TRACE,
980 "%s: %s:%d mss = %d",
981 dev->name, __func__, __LINE__, mss);
982 vxge_hw_fifo_txdl_mss_set(dtr, mss);
984 vxge_assert(skb->len <=
985 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
991 if (skb->ip_summed == CHECKSUM_PARTIAL)
992 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
993 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
994 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
995 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
997 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
999 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
1001 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1003 VXGE_COMPLETE_VPATH_TX(fifo);
1004 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
1005 dev->name, __func__, __LINE__);
1006 return NETDEV_TX_OK;
1009 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
1013 frag = &skb_shinfo(skb)->frags[0];
1015 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
1016 skb_headlen(skb), PCI_DMA_TODEVICE);
1018 for (; j < i; j++) {
1019 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
1020 frag->size, PCI_DMA_TODEVICE);
1024 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
1027 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1028 VXGE_COMPLETE_VPATH_TX(fifo);
1030 return NETDEV_TX_OK;
1036 * Function will be called by hw function to abort all outstanding receive
1040 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1042 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1043 struct vxge_rx_priv *rx_priv =
1044 vxge_hw_ring_rxd_private_get(dtrh);
1046 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1047 ring->ndev->name, __func__, __LINE__);
1048 if (state != VXGE_HW_RXD_STATE_POSTED)
1051 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1052 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1054 dev_kfree_skb(rx_priv->skb);
1056 vxge_debug_entryexit(VXGE_TRACE,
1057 "%s: %s:%d Exiting...",
1058 ring->ndev->name, __func__, __LINE__);
1064 * Function will be called to abort all outstanding tx descriptors
1067 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1069 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1071 int i = 0, j, frg_cnt;
1072 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1073 struct sk_buff *skb = txd_priv->skb;
1075 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1077 if (state != VXGE_HW_TXDL_STATE_POSTED)
1080 /* check skb validity */
1082 frg_cnt = skb_shinfo(skb)->nr_frags;
1083 frag = &skb_shinfo(skb)->frags[0];
1085 /* for unfragmented skb */
1086 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1087 skb_headlen(skb), PCI_DMA_TODEVICE);
1089 for (j = 0; j < frg_cnt; j++) {
1090 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1091 frag->size, PCI_DMA_TODEVICE);
1097 vxge_debug_entryexit(VXGE_TRACE,
1098 "%s:%d Exiting...", __func__, __LINE__);
1102 * vxge_set_multicast
1103 * @dev: pointer to the device structure
1105 * Entry point for multicast address enable/disable
1106 * This function is a driver entry point which gets called by the kernel
1107 * whenever multicast addresses must be enabled/disabled. This also gets
1108 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1109 * determine, if multicast address must be enabled or if promiscuous mode
1110 * is to be disabled etc.
1112 static void vxge_set_multicast(struct net_device *dev)
1114 struct dev_mc_list *mclist;
1115 struct vxgedev *vdev;
1116 int i, mcast_cnt = 0;
1117 struct __vxge_hw_device *hldev;
1118 enum vxge_hw_status status = VXGE_HW_OK;
1119 struct macInfo mac_info;
1121 struct vxge_mac_addrs *mac_entry;
1122 struct list_head *list_head;
1123 struct list_head *entry, *next;
1124 u8 *mac_address = NULL;
1126 vxge_debug_entryexit(VXGE_TRACE,
1127 "%s:%d", __func__, __LINE__);
1129 vdev = (struct vxgedev *)netdev_priv(dev);
1130 hldev = (struct __vxge_hw_device *)vdev->devh;
1132 if (unlikely(!is_vxge_card_up(vdev)))
1135 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1136 for (i = 0; i < vdev->no_of_vpath; i++) {
1137 vxge_assert(vdev->vpaths[i].is_open);
1138 status = vxge_hw_vpath_mcast_enable(
1139 vdev->vpaths[i].handle);
1140 vdev->all_multi_flg = 1;
1142 } else if ((dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1143 for (i = 0; i < vdev->no_of_vpath; i++) {
1144 vxge_assert(vdev->vpaths[i].is_open);
1145 status = vxge_hw_vpath_mcast_disable(
1146 vdev->vpaths[i].handle);
1147 vdev->all_multi_flg = 1;
1151 if (status != VXGE_HW_OK)
1152 vxge_debug_init(VXGE_ERR,
1153 "failed to %s multicast, status %d",
1154 dev->flags & IFF_ALLMULTI ?
1155 "enable" : "disable", status);
1157 if (!vdev->config.addr_learn_en) {
1158 if (dev->flags & IFF_PROMISC) {
1159 for (i = 0; i < vdev->no_of_vpath; i++) {
1160 vxge_assert(vdev->vpaths[i].is_open);
1161 status = vxge_hw_vpath_promisc_enable(
1162 vdev->vpaths[i].handle);
1165 for (i = 0; i < vdev->no_of_vpath; i++) {
1166 vxge_assert(vdev->vpaths[i].is_open);
1167 status = vxge_hw_vpath_promisc_disable(
1168 vdev->vpaths[i].handle);
1173 memset(&mac_info, 0, sizeof(struct macInfo));
1174 /* Update individual M_CAST address list */
1175 if ((!vdev->all_multi_flg) && dev->mc_count) {
1177 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1178 list_head = &vdev->vpaths[0].mac_addr_list;
1179 if ((dev->mc_count +
1180 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1181 vdev->vpaths[0].max_mac_addr_cnt)
1182 goto _set_all_mcast;
1184 /* Delete previous MC's */
1185 for (i = 0; i < mcast_cnt; i++) {
1186 if (!list_empty(list_head))
1187 mac_entry = (struct vxge_mac_addrs *)
1188 list_first_entry(list_head,
1189 struct vxge_mac_addrs,
1192 list_for_each_safe(entry, next, list_head) {
1194 mac_entry = (struct vxge_mac_addrs *) entry;
1195 /* Copy the mac address to delete */
1196 mac_address = (u8 *)&mac_entry->macaddr;
1197 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1199 /* Is this a multicast address */
1200 if (0x01 & mac_info.macaddr[0]) {
1201 for (vpath_idx = 0; vpath_idx <
1204 mac_info.vpath_no = vpath_idx;
1205 status = vxge_del_mac_addr(
1214 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
1215 i++, mclist = mclist->next) {
1217 memcpy(mac_info.macaddr, mclist->dmi_addr, ETH_ALEN);
1218 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1220 mac_info.vpath_no = vpath_idx;
1221 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1222 status = vxge_add_mac_addr(vdev, &mac_info);
1223 if (status != VXGE_HW_OK) {
1224 vxge_debug_init(VXGE_ERR,
1225 "%s:%d Setting individual"
1226 "multicast address failed",
1227 __func__, __LINE__);
1228 goto _set_all_mcast;
1235 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1236 /* Delete previous MC's */
1237 for (i = 0; i < mcast_cnt; i++) {
1239 list_for_each_safe(entry, next, list_head) {
1241 mac_entry = (struct vxge_mac_addrs *) entry;
1242 /* Copy the mac address to delete */
1243 mac_address = (u8 *)&mac_entry->macaddr;
1244 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1246 /* Is this a multicast address */
1247 if (0x01 & mac_info.macaddr[0])
1251 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1253 mac_info.vpath_no = vpath_idx;
1254 status = vxge_del_mac_addr(vdev, &mac_info);
1258 /* Enable all multicast */
1259 for (i = 0; i < vdev->no_of_vpath; i++) {
1260 vxge_assert(vdev->vpaths[i].is_open);
1261 status = vxge_hw_vpath_mcast_enable(
1262 vdev->vpaths[i].handle);
1263 if (status != VXGE_HW_OK) {
1264 vxge_debug_init(VXGE_ERR,
1265 "%s:%d Enabling all multicasts failed",
1266 __func__, __LINE__);
1268 vdev->all_multi_flg = 1;
1270 dev->flags |= IFF_ALLMULTI;
1273 vxge_debug_entryexit(VXGE_TRACE,
1274 "%s:%d Exiting...", __func__, __LINE__);
1279 * @dev: pointer to the device structure
1281 * Update entry "0" (default MAC addr)
1283 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1285 struct sockaddr *addr = p;
1286 struct vxgedev *vdev;
1287 struct __vxge_hw_device *hldev;
1288 enum vxge_hw_status status = VXGE_HW_OK;
1289 struct macInfo mac_info_new, mac_info_old;
1292 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1294 vdev = (struct vxgedev *)netdev_priv(dev);
1297 if (!is_valid_ether_addr(addr->sa_data))
1300 memset(&mac_info_new, 0, sizeof(struct macInfo));
1301 memset(&mac_info_old, 0, sizeof(struct macInfo));
1303 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1304 __func__, __LINE__);
1306 /* Get the old address */
1307 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1309 /* Copy the new address */
1310 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1312 /* First delete the old mac address from all the vpaths
1313 as we can't specify the index while adding new mac address */
1314 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1315 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1316 if (!vpath->is_open) {
1317 /* This can happen when this interface is added/removed
1318 to the bonding interface. Delete this station address
1319 from the linked list */
1320 vxge_mac_list_del(vpath, &mac_info_old);
1322 /* Add this new address to the linked list
1323 for later restoring */
1324 vxge_mac_list_add(vpath, &mac_info_new);
1328 /* Delete the station address */
1329 mac_info_old.vpath_no = vpath_idx;
1330 status = vxge_del_mac_addr(vdev, &mac_info_old);
1333 if (unlikely(!is_vxge_card_up(vdev))) {
1334 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1338 /* Set this mac address to all the vpaths */
1339 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1340 mac_info_new.vpath_no = vpath_idx;
1341 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1342 status = vxge_add_mac_addr(vdev, &mac_info_new);
1343 if (status != VXGE_HW_OK)
1347 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1353 * vxge_vpath_intr_enable
1354 * @vdev: pointer to vdev
1355 * @vp_id: vpath for which to enable the interrupts
1357 * Enables the interrupts for the vpath
1359 void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1361 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1362 int msix_id, alarm_msix_id;
1363 int tim_msix_id[4] = {[0 ...3] = 0};
1365 vxge_hw_vpath_intr_enable(vpath->handle);
1367 if (vdev->config.intr_type == INTA)
1368 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1370 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1372 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1374 tim_msix_id[0] = msix_id;
1375 tim_msix_id[1] = msix_id + 1;
1376 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1379 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1380 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1382 /* enable the alarm vector */
1383 vxge_hw_vpath_msix_unmask(vpath->handle, alarm_msix_id);
1388 * vxge_vpath_intr_disable
1389 * @vdev: pointer to vdev
1390 * @vp_id: vpath for which to disable the interrupts
1392 * Disables the interrupts for the vpath
1394 void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1396 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1399 vxge_hw_vpath_intr_disable(vpath->handle);
1401 if (vdev->config.intr_type == INTA)
1402 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1404 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1405 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1406 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1408 /* disable the alarm vector */
1409 msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1410 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1416 * @vdev: pointer to vdev
1417 * @vp_id: vpath to reset
1421 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1423 enum vxge_hw_status status = VXGE_HW_OK;
1426 /* check if device is down already */
1427 if (unlikely(!is_vxge_card_up(vdev)))
1430 /* is device reset already scheduled */
1431 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1434 if (vdev->vpaths[vp_id].handle) {
1435 if (vxge_hw_vpath_reset(vdev->vpaths[vp_id].handle)
1437 if (is_vxge_card_up(vdev) &&
1438 vxge_hw_vpath_recover_from_reset(
1439 vdev->vpaths[vp_id].handle)
1441 vxge_debug_init(VXGE_ERR,
1442 "vxge_hw_vpath_recover_from_reset"
1443 "failed for vpath:%d", vp_id);
1447 vxge_debug_init(VXGE_ERR,
1448 "vxge_hw_vpath_reset failed for"
1453 return VXGE_HW_FAIL;
1455 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1456 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1458 /* Enable all broadcast */
1459 vxge_hw_vpath_bcast_enable(vdev->vpaths[vp_id].handle);
1461 /* Enable the interrupts */
1462 vxge_vpath_intr_enable(vdev, vp_id);
1466 /* Enable the flow of traffic through the vpath */
1467 vxge_hw_vpath_enable(vdev->vpaths[vp_id].handle);
1470 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[vp_id].handle);
1471 vdev->vpaths[vp_id].ring.last_status = VXGE_HW_OK;
1473 /* Vpath reset done */
1474 clear_bit(vp_id, &vdev->vp_reset);
1476 /* Start the vpath queue */
1477 vxge_wake_tx_queue(&vdev->vpaths[vp_id].fifo, NULL);
1482 static int do_vxge_reset(struct vxgedev *vdev, int event)
1484 enum vxge_hw_status status;
1485 int ret = 0, vp_id, i;
1487 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1489 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1490 /* check if device is down already */
1491 if (unlikely(!is_vxge_card_up(vdev)))
1494 /* is reset already scheduled */
1495 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1499 if (event == VXGE_LL_FULL_RESET) {
1500 /* wait for all the vpath reset to complete */
1501 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1502 while (test_bit(vp_id, &vdev->vp_reset))
1506 /* if execution mode is set to debug, don't reset the adapter */
1507 if (unlikely(vdev->exec_mode)) {
1508 vxge_debug_init(VXGE_ERR,
1509 "%s: execution mode is debug, returning..",
1511 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1512 vxge_stop_all_tx_queue(vdev);
1517 if (event == VXGE_LL_FULL_RESET) {
1518 vxge_hw_device_intr_disable(vdev->devh);
1520 switch (vdev->cric_err_event) {
1521 case VXGE_HW_EVENT_UNKNOWN:
1522 vxge_stop_all_tx_queue(vdev);
1523 vxge_debug_init(VXGE_ERR,
1524 "fatal: %s: Disabling device due to"
1529 case VXGE_HW_EVENT_RESET_START:
1531 case VXGE_HW_EVENT_RESET_COMPLETE:
1532 case VXGE_HW_EVENT_LINK_DOWN:
1533 case VXGE_HW_EVENT_LINK_UP:
1534 case VXGE_HW_EVENT_ALARM_CLEARED:
1535 case VXGE_HW_EVENT_ECCERR:
1536 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1539 case VXGE_HW_EVENT_FIFO_ERR:
1540 case VXGE_HW_EVENT_VPATH_ERR:
1542 case VXGE_HW_EVENT_CRITICAL_ERR:
1543 vxge_stop_all_tx_queue(vdev);
1544 vxge_debug_init(VXGE_ERR,
1545 "fatal: %s: Disabling device due to"
1548 /* SOP or device reset required */
1549 /* This event is not currently used */
1552 case VXGE_HW_EVENT_SERR:
1553 vxge_stop_all_tx_queue(vdev);
1554 vxge_debug_init(VXGE_ERR,
1555 "fatal: %s: Disabling device due to"
1560 case VXGE_HW_EVENT_SRPCIM_SERR:
1561 case VXGE_HW_EVENT_MRPCIM_SERR:
1564 case VXGE_HW_EVENT_SLOT_FREEZE:
1565 vxge_stop_all_tx_queue(vdev);
1566 vxge_debug_init(VXGE_ERR,
1567 "fatal: %s: Disabling device due to"
1578 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1579 vxge_stop_all_tx_queue(vdev);
1581 if (event == VXGE_LL_FULL_RESET) {
1582 status = vxge_reset_all_vpaths(vdev);
1583 if (status != VXGE_HW_OK) {
1584 vxge_debug_init(VXGE_ERR,
1585 "fatal: %s: can not reset vpaths",
1592 if (event == VXGE_LL_COMPL_RESET) {
1593 for (i = 0; i < vdev->no_of_vpath; i++)
1594 if (vdev->vpaths[i].handle) {
1595 if (vxge_hw_vpath_recover_from_reset(
1596 vdev->vpaths[i].handle)
1598 vxge_debug_init(VXGE_ERR,
1599 "vxge_hw_vpath_recover_"
1600 "from_reset failed for vpath: "
1606 vxge_debug_init(VXGE_ERR,
1607 "vxge_hw_vpath_reset failed for "
1614 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1615 /* Reprogram the DA table with populated mac addresses */
1616 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1617 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1618 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1621 /* enable vpath interrupts */
1622 for (i = 0; i < vdev->no_of_vpath; i++)
1623 vxge_vpath_intr_enable(vdev, i);
1625 vxge_hw_device_intr_enable(vdev->devh);
1629 /* Indicate card up */
1630 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1632 /* Get the traffic to flow through the vpaths */
1633 for (i = 0; i < vdev->no_of_vpath; i++) {
1634 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1636 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1639 vxge_wake_all_tx_queue(vdev);
1643 vxge_debug_entryexit(VXGE_TRACE,
1644 "%s:%d Exiting...", __func__, __LINE__);
1646 /* Indicate reset done */
1647 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1648 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1654 * @vdev: pointer to ll device
1656 * driver may reset the chip on events of serr, eccerr, etc
1658 int vxge_reset(struct vxgedev *vdev)
1660 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1665 * vxge_poll - Receive handler when Receive Polling is used.
1666 * @dev: pointer to the device structure.
1667 * @budget: Number of packets budgeted to be processed in this iteration.
1669 * This function comes into picture only if Receive side is being handled
1670 * through polling (called NAPI in linux). It mostly does what the normal
1671 * Rx interrupt handler does in terms of descriptor and packet processing
1672 * but not in an interrupt context. Also it will process a specified number
1673 * of packets at most in one iteration. This value is passed down by the
1674 * kernel as the function argument 'budget'.
1676 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1678 struct vxge_ring *ring =
1679 container_of(napi, struct vxge_ring, napi);
1680 int budget_org = budget;
1681 ring->budget = budget;
1683 vxge_hw_vpath_poll_rx(ring->handle);
1685 if (ring->pkts_processed < budget_org) {
1686 napi_complete(napi);
1687 /* Re enable the Rx interrupts for the vpath */
1688 vxge_hw_channel_msix_unmask(
1689 (struct __vxge_hw_channel *)ring->handle,
1690 ring->rx_vector_no);
1693 return ring->pkts_processed;
1696 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1698 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1699 int pkts_processed = 0;
1701 int budget_org = budget;
1702 struct vxge_ring *ring;
1704 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1705 pci_get_drvdata(vdev->pdev);
1707 for (i = 0; i < vdev->no_of_vpath; i++) {
1708 ring = &vdev->vpaths[i].ring;
1709 ring->budget = budget;
1710 vxge_hw_vpath_poll_rx(ring->handle);
1711 pkts_processed += ring->pkts_processed;
1712 budget -= ring->pkts_processed;
1717 VXGE_COMPLETE_ALL_TX(vdev);
1719 if (pkts_processed < budget_org) {
1720 napi_complete(napi);
1721 /* Re enable the Rx interrupts for the ring */
1722 vxge_hw_device_unmask_all(hldev);
1723 vxge_hw_device_flush_io(hldev);
1726 return pkts_processed;
1729 #ifdef CONFIG_NET_POLL_CONTROLLER
1731 * vxge_netpoll - netpoll event handler entry point
1732 * @dev : pointer to the device structure.
1734 * This function will be called by upper layer to check for events on the
1735 * interface in situations where interrupts are disabled. It is used for
1736 * specific in-kernel networking tasks, such as remote consoles and kernel
1737 * debugging over the network (example netdump in RedHat).
1739 static void vxge_netpoll(struct net_device *dev)
1741 struct __vxge_hw_device *hldev;
1742 struct vxgedev *vdev;
1744 vdev = (struct vxgedev *)netdev_priv(dev);
1745 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1747 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1749 if (pci_channel_offline(vdev->pdev))
1752 disable_irq(dev->irq);
1753 vxge_hw_device_clear_tx_rx(hldev);
1755 vxge_hw_device_clear_tx_rx(hldev);
1756 VXGE_COMPLETE_ALL_RX(vdev);
1757 VXGE_COMPLETE_ALL_TX(vdev);
1759 enable_irq(dev->irq);
1761 vxge_debug_entryexit(VXGE_TRACE,
1762 "%s:%d Exiting...", __func__, __LINE__);
1767 /* RTH configuration */
1768 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1770 enum vxge_hw_status status = VXGE_HW_OK;
1771 struct vxge_hw_rth_hash_types hash_types;
1772 u8 itable[256] = {0}; /* indirection table */
1773 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1778 * - itable with bucket numbers
1779 * - mtable with bucket-to-vpath mapping
1781 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1782 itable[index] = index;
1783 mtable[index] = index % vdev->no_of_vpath;
1786 /* Fill RTH hash types */
1787 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1788 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1789 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1790 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1791 hash_types.hash_type_tcpipv6ex_en =
1792 vdev->config.rth_hash_type_tcpipv6ex;
1793 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1795 /* set indirection table, bucket-to-vpath mapping */
1796 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1799 vdev->config.rth_bkt_sz);
1800 if (status != VXGE_HW_OK) {
1801 vxge_debug_init(VXGE_ERR,
1802 "RTH indirection table configuration failed "
1803 "for vpath:%d", vdev->vpaths[0].device_id);
1808 * Because the itable_set() method uses the active_table field
1809 * for the target virtual path the RTH config should be updated
1810 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1811 * when steering frames.
1813 for (index = 0; index < vdev->no_of_vpath; index++) {
1814 status = vxge_hw_vpath_rts_rth_set(
1815 vdev->vpaths[index].handle,
1816 vdev->config.rth_algorithm,
1818 vdev->config.rth_bkt_sz);
1820 if (status != VXGE_HW_OK) {
1821 vxge_debug_init(VXGE_ERR,
1822 "RTH configuration failed for vpath:%d",
1823 vdev->vpaths[index].device_id);
1831 int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1833 struct vxge_mac_addrs *new_mac_entry;
1834 u8 *mac_address = NULL;
1836 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1839 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1840 if (!new_mac_entry) {
1841 vxge_debug_mem(VXGE_ERR,
1842 "%s: memory allocation failed",
1847 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1849 /* Copy the new mac address to the list */
1850 mac_address = (u8 *)&new_mac_entry->macaddr;
1851 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1853 new_mac_entry->state = mac->state;
1854 vpath->mac_addr_cnt++;
1856 /* Is this a multicast address */
1857 if (0x01 & mac->macaddr[0])
1858 vpath->mcast_addr_cnt++;
1863 /* Add a mac address to DA table */
1864 enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1866 enum vxge_hw_status status = VXGE_HW_OK;
1867 struct vxge_vpath *vpath;
1868 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1870 if (0x01 & mac->macaddr[0]) /* multicast address */
1871 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1873 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1875 vpath = &vdev->vpaths[mac->vpath_no];
1876 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1877 mac->macmask, duplicate_mode);
1878 if (status != VXGE_HW_OK) {
1879 vxge_debug_init(VXGE_ERR,
1880 "DA config add entry failed for vpath:%d",
1883 if (FALSE == vxge_mac_list_add(vpath, mac))
1889 int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1891 struct list_head *entry, *next;
1893 u8 *mac_address = (u8 *) (&del_mac);
1895 /* Copy the mac address to delete from the list */
1896 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1898 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1899 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1901 kfree((struct vxge_mac_addrs *)entry);
1902 vpath->mac_addr_cnt--;
1904 /* Is this a multicast address */
1905 if (0x01 & mac->macaddr[0])
1906 vpath->mcast_addr_cnt--;
1913 /* delete a mac address from DA table */
1914 enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1916 enum vxge_hw_status status = VXGE_HW_OK;
1917 struct vxge_vpath *vpath;
1919 vpath = &vdev->vpaths[mac->vpath_no];
1920 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1922 if (status != VXGE_HW_OK) {
1923 vxge_debug_init(VXGE_ERR,
1924 "DA config delete entry failed for vpath:%d",
1927 vxge_mac_list_del(vpath, mac);
1931 /* list all mac addresses from DA table */
1933 static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1934 struct macInfo *mac)
1936 enum vxge_hw_status status = VXGE_HW_OK;
1937 unsigned char macmask[ETH_ALEN];
1938 unsigned char macaddr[ETH_ALEN];
1940 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1942 if (status != VXGE_HW_OK) {
1943 vxge_debug_init(VXGE_ERR,
1944 "DA config list entry failed for vpath:%d",
1949 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1951 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1953 if (status != VXGE_HW_OK)
1960 /* Store all vlan ids from the list to the vid table */
1961 enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1963 enum vxge_hw_status status = VXGE_HW_OK;
1964 struct vxgedev *vdev = vpath->vdev;
1967 if (vdev->vlgrp && vpath->is_open) {
1969 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1970 if (!vlan_group_get_device(vdev->vlgrp, vid))
1972 /* Add these vlan to the vid table */
1973 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1980 /* Store all mac addresses from the list to the DA table */
1981 enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1983 enum vxge_hw_status status = VXGE_HW_OK;
1984 struct macInfo mac_info;
1985 u8 *mac_address = NULL;
1986 struct list_head *entry, *next;
1988 memset(&mac_info, 0, sizeof(struct macInfo));
1990 if (vpath->is_open) {
1992 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1995 ((struct vxge_mac_addrs *)entry)->macaddr;
1996 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1997 ((struct vxge_mac_addrs *)entry)->state =
1998 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1999 /* does this mac address already exist in da table? */
2000 status = vxge_search_mac_addr_in_da_table(vpath,
2002 if (status != VXGE_HW_OK) {
2003 /* Add this mac address to the DA table */
2004 status = vxge_hw_vpath_mac_addr_add(
2005 vpath->handle, mac_info.macaddr,
2007 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
2008 if (status != VXGE_HW_OK) {
2009 vxge_debug_init(VXGE_ERR,
2010 "DA add entry failed for vpath:%d",
2012 ((struct vxge_mac_addrs *)entry)->state
2013 = VXGE_LL_MAC_ADDR_IN_LIST;
2023 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
2026 enum vxge_hw_status status = VXGE_HW_OK;
2028 for (i = 0; i < vdev->no_of_vpath; i++)
2029 if (vdev->vpaths[i].handle) {
2030 if (vxge_hw_vpath_reset(vdev->vpaths[i].handle)
2032 if (is_vxge_card_up(vdev) &&
2033 vxge_hw_vpath_recover_from_reset(
2034 vdev->vpaths[i].handle)
2036 vxge_debug_init(VXGE_ERR,
2037 "vxge_hw_vpath_recover_"
2038 "from_reset failed for vpath: "
2043 vxge_debug_init(VXGE_ERR,
2044 "vxge_hw_vpath_reset failed for "
2053 void vxge_close_vpaths(struct vxgedev *vdev, int index)
2056 for (i = index; i < vdev->no_of_vpath; i++) {
2057 if (vdev->vpaths[i].handle && vdev->vpaths[i].is_open) {
2058 vxge_hw_vpath_close(vdev->vpaths[i].handle);
2059 vdev->stats.vpaths_open--;
2061 vdev->vpaths[i].is_open = 0;
2062 vdev->vpaths[i].handle = NULL;
2067 int vxge_open_vpaths(struct vxgedev *vdev)
2069 enum vxge_hw_status status;
2072 struct vxge_hw_vpath_attr attr;
2074 for (i = 0; i < vdev->no_of_vpath; i++) {
2075 vxge_assert(vdev->vpaths[i].is_configured);
2076 attr.vp_id = vdev->vpaths[i].device_id;
2077 attr.fifo_attr.callback = vxge_xmit_compl;
2078 attr.fifo_attr.txdl_term = vxge_tx_term;
2079 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2080 attr.fifo_attr.userdata = (void *)&vdev->vpaths[i].fifo;
2082 attr.ring_attr.callback = vxge_rx_1b_compl;
2083 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2084 attr.ring_attr.rxd_term = vxge_rx_term;
2085 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2086 attr.ring_attr.userdata = (void *)&vdev->vpaths[i].ring;
2088 vdev->vpaths[i].ring.ndev = vdev->ndev;
2089 vdev->vpaths[i].ring.pdev = vdev->pdev;
2090 status = vxge_hw_vpath_open(vdev->devh, &attr,
2091 &(vdev->vpaths[i].handle));
2092 if (status == VXGE_HW_OK) {
2093 vdev->vpaths[i].fifo.handle =
2094 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2095 vdev->vpaths[i].ring.handle =
2096 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2097 vdev->vpaths[i].fifo.tx_steering_type =
2098 vdev->config.tx_steering_type;
2099 vdev->vpaths[i].fifo.ndev = vdev->ndev;
2100 vdev->vpaths[i].fifo.pdev = vdev->pdev;
2101 vdev->vpaths[i].fifo.indicate_max_pkts =
2102 vdev->config.fifo_indicate_max_pkts;
2103 vdev->vpaths[i].ring.rx_vector_no = 0;
2104 vdev->vpaths[i].ring.rx_csum = vdev->rx_csum;
2105 vdev->vpaths[i].is_open = 1;
2106 vdev->vp_handles[i] = vdev->vpaths[i].handle;
2107 vdev->vpaths[i].ring.gro_enable =
2108 vdev->config.gro_enable;
2109 vdev->vpaths[i].ring.vlan_tag_strip =
2110 vdev->vlan_tag_strip;
2111 vdev->stats.vpaths_open++;
2113 vdev->stats.vpath_open_fail++;
2114 vxge_debug_init(VXGE_ERR,
2115 "%s: vpath: %d failed to open "
2117 vdev->ndev->name, vdev->vpaths[i].device_id,
2119 vxge_close_vpaths(vdev, 0);
2124 ((struct __vxge_hw_vpath_handle *)vdev->vpaths[i].handle)->
2126 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2133 * @irq: the irq of the device.
2134 * @dev_id: a void pointer to the hldev structure of the Titan device
2135 * @ptregs: pointer to the registers pushed on the stack.
2137 * This function is the ISR handler of the device when napi is enabled. It
2138 * identifies the reason for the interrupt and calls the relevant service
2141 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2143 struct net_device *dev;
2144 struct __vxge_hw_device *hldev;
2146 enum vxge_hw_status status;
2147 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
2149 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2152 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
2154 if (pci_channel_offline(vdev->pdev))
2157 if (unlikely(!is_vxge_card_up(vdev)))
2160 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2162 if (status == VXGE_HW_OK) {
2163 vxge_hw_device_mask_all(hldev);
2166 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2167 vdev->vpaths_deployed >>
2168 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2170 vxge_hw_device_clear_tx_rx(hldev);
2171 napi_schedule(&vdev->napi);
2172 vxge_debug_intr(VXGE_TRACE,
2173 "%s:%d Exiting...", __func__, __LINE__);
2176 vxge_hw_device_unmask_all(hldev);
2177 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2178 (status == VXGE_HW_ERR_CRITICAL) ||
2179 (status == VXGE_HW_ERR_FIFO))) {
2180 vxge_hw_device_mask_all(hldev);
2181 vxge_hw_device_flush_io(hldev);
2183 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2186 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2190 #ifdef CONFIG_PCI_MSI
2193 vxge_tx_msix_handle(int irq, void *dev_id)
2195 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2197 VXGE_COMPLETE_VPATH_TX(fifo);
2203 vxge_rx_msix_napi_handle(int irq, void *dev_id)
2205 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2207 /* MSIX_IDX for Rx is 1 */
2208 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2209 ring->rx_vector_no);
2211 napi_schedule(&ring->napi);
2216 vxge_alarm_msix_handle(int irq, void *dev_id)
2219 enum vxge_hw_status status;
2220 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2221 struct vxgedev *vdev = vpath->vdev;
2223 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2225 for (i = 0; i < vdev->no_of_vpath; i++) {
2226 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle,
2229 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2231 if (status == VXGE_HW_OK) {
2233 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2237 vxge_debug_intr(VXGE_ERR,
2238 "%s: vxge_hw_vpath_alarm_process failed %x ",
2239 VXGE_DRIVER_NAME, status);
2244 static int vxge_alloc_msix(struct vxgedev *vdev)
2248 int alarm_msix_id = 0, msix_intr_vect = 0;
2251 /* Tx/Rx MSIX Vectors count */
2252 vdev->intr_cnt = vdev->no_of_vpath * 2;
2254 /* Alarm MSIX Vectors count */
2257 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2258 vdev->entries = kzalloc(intr_cnt * sizeof(struct msix_entry),
2260 if (!vdev->entries) {
2261 vxge_debug_init(VXGE_ERR,
2262 "%s: memory allocation failed",
2267 vdev->vxge_entries = kzalloc(intr_cnt * sizeof(struct vxge_msix_entry),
2269 if (!vdev->vxge_entries) {
2270 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2272 kfree(vdev->entries);
2276 /* Last vector in the list is used for alarm */
2277 alarm_msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2278 for (i = 0, j = 0; i < vdev->max_vpath_supported; i++) {
2280 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2282 /* Initialize the fifo vector */
2283 vdev->entries[j].entry = msix_intr_vect;
2284 vdev->vxge_entries[j].entry = msix_intr_vect;
2285 vdev->vxge_entries[j].in_use = 0;
2288 /* Initialize the ring vector */
2289 vdev->entries[j].entry = msix_intr_vect + 1;
2290 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2291 vdev->vxge_entries[j].in_use = 0;
2295 /* Initialize the alarm vector */
2296 vdev->entries[j].entry = alarm_msix_id;
2297 vdev->vxge_entries[j].entry = alarm_msix_id;
2298 vdev->vxge_entries[j].in_use = 0;
2300 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2301 /* if driver request exceeeds available irq's, request with a small
2305 vxge_debug_init(VXGE_ERR,
2306 "%s: MSI-X enable failed for %d vectors, available: %d",
2307 VXGE_DRIVER_NAME, intr_cnt, ret);
2308 vdev->max_vpath_supported = vdev->no_of_vpath;
2309 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2311 /* Reset the alarm vector setting */
2312 vdev->entries[j].entry = 0;
2313 vdev->vxge_entries[j].entry = 0;
2315 /* Initialize the alarm vector with new setting */
2316 vdev->entries[intr_cnt - 1].entry = alarm_msix_id;
2317 vdev->vxge_entries[intr_cnt - 1].entry = alarm_msix_id;
2318 vdev->vxge_entries[intr_cnt - 1].in_use = 0;
2320 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2322 vxge_debug_init(VXGE_ERR,
2323 "%s: MSI-X enabled for %d vectors",
2324 VXGE_DRIVER_NAME, intr_cnt);
2328 vxge_debug_init(VXGE_ERR,
2329 "%s: MSI-X enable failed for %d vectors, ret: %d",
2330 VXGE_DRIVER_NAME, intr_cnt, ret);
2331 kfree(vdev->entries);
2332 kfree(vdev->vxge_entries);
2333 vdev->entries = NULL;
2334 vdev->vxge_entries = NULL;
2340 static int vxge_enable_msix(struct vxgedev *vdev)
2344 enum vxge_hw_status status;
2345 /* 0 - Tx, 1 - Rx */
2347 int alarm_msix_id = 0, msix_intr_vect = 0;;
2350 /* allocate msix vectors */
2351 ret = vxge_alloc_msix(vdev);
2353 /* Last vector in the list is used for alarm */
2355 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2356 for (i = 0; i < vdev->no_of_vpath; i++) {
2358 /* If fifo or ring are not enabled
2359 the MSIX vector for that should be set to 0
2360 Hence initializeing this array to all 0s.
2362 memset(tim_msix_id, 0, sizeof(tim_msix_id));
2363 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2364 tim_msix_id[0] = msix_intr_vect;
2366 tim_msix_id[1] = msix_intr_vect + 1;
2367 vdev->vpaths[i].ring.rx_vector_no = tim_msix_id[1];
2369 status = vxge_hw_vpath_msix_set(
2370 vdev->vpaths[i].handle,
2371 tim_msix_id, alarm_msix_id);
2372 if (status != VXGE_HW_OK) {
2373 vxge_debug_init(VXGE_ERR,
2374 "vxge_hw_vpath_msix_set "
2375 "failed with status : %x", status);
2376 kfree(vdev->entries);
2377 kfree(vdev->vxge_entries);
2378 pci_disable_msix(vdev->pdev);
2387 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2391 for (intr_cnt = 0; intr_cnt < (vdev->max_vpath_supported * 2 + 1);
2393 if (vdev->vxge_entries[intr_cnt].in_use) {
2394 synchronize_irq(vdev->entries[intr_cnt].vector);
2395 free_irq(vdev->entries[intr_cnt].vector,
2396 vdev->vxge_entries[intr_cnt].arg);
2397 vdev->vxge_entries[intr_cnt].in_use = 0;
2401 kfree(vdev->entries);
2402 kfree(vdev->vxge_entries);
2403 vdev->entries = NULL;
2404 vdev->vxge_entries = NULL;
2406 if (vdev->config.intr_type == MSI_X)
2407 pci_disable_msix(vdev->pdev);
2411 static void vxge_rem_isr(struct vxgedev *vdev)
2413 struct __vxge_hw_device *hldev;
2414 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2416 #ifdef CONFIG_PCI_MSI
2417 if (vdev->config.intr_type == MSI_X) {
2418 vxge_rem_msix_isr(vdev);
2421 if (vdev->config.intr_type == INTA) {
2422 synchronize_irq(vdev->pdev->irq);
2423 free_irq(vdev->pdev->irq, vdev);
2427 static int vxge_add_isr(struct vxgedev *vdev)
2430 #ifdef CONFIG_PCI_MSI
2431 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2432 u64 function_mode = vdev->config.device_hw_info.function_mode;
2433 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2435 if (vdev->config.intr_type == MSI_X)
2436 ret = vxge_enable_msix(vdev);
2439 vxge_debug_init(VXGE_ERR,
2440 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2441 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2442 test_and_set_bit(__VXGE_STATE_CARD_UP,
2443 &driver_config->inta_dev_open))
2444 return VXGE_HW_FAIL;
2446 vxge_debug_init(VXGE_ERR,
2447 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2448 vdev->config.intr_type = INTA;
2449 vxge_hw_device_set_intr_type(vdev->devh,
2450 VXGE_HW_INTR_MODE_IRQLINE);
2451 vxge_close_vpaths(vdev, 1);
2452 vdev->no_of_vpath = 1;
2453 vdev->stats.vpaths_open = 1;
2457 if (vdev->config.intr_type == MSI_X) {
2459 intr_idx < (vdev->no_of_vpath *
2460 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2462 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2467 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2468 "%s:vxge fn: %d vpath: %d Tx MSI-X: %d",
2469 vdev->ndev->name, pci_fun, vp_idx,
2470 vdev->entries[intr_cnt].entry);
2472 vdev->entries[intr_cnt].vector,
2473 vxge_tx_msix_handle, 0,
2474 vdev->desc[intr_cnt],
2475 &vdev->vpaths[vp_idx].fifo);
2476 vdev->vxge_entries[intr_cnt].arg =
2477 &vdev->vpaths[vp_idx].fifo;
2481 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2482 "%s:vxge fn: %d vpath: %d Rx MSI-X: %d",
2483 vdev->ndev->name, pci_fun, vp_idx,
2484 vdev->entries[intr_cnt].entry);
2486 vdev->entries[intr_cnt].vector,
2487 vxge_rx_msix_napi_handle,
2489 vdev->desc[intr_cnt],
2490 &vdev->vpaths[vp_idx].ring);
2491 vdev->vxge_entries[intr_cnt].arg =
2492 &vdev->vpaths[vp_idx].ring;
2498 vxge_debug_init(VXGE_ERR,
2499 "%s: MSIX - %d Registration failed",
2500 vdev->ndev->name, intr_cnt);
2501 vxge_rem_msix_isr(vdev);
2502 if ((function_mode ==
2503 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2504 test_and_set_bit(__VXGE_STATE_CARD_UP,
2505 &driver_config->inta_dev_open))
2506 return VXGE_HW_FAIL;
2508 vxge_hw_device_set_intr_type(
2510 VXGE_HW_INTR_MODE_IRQLINE);
2511 vdev->config.intr_type = INTA;
2512 vxge_debug_init(VXGE_ERR,
2513 "%s: Defaulting to INTA"
2514 , vdev->ndev->name);
2515 vxge_close_vpaths(vdev, 1);
2516 vdev->no_of_vpath = 1;
2517 vdev->stats.vpaths_open = 1;
2523 /* We requested for this msix interrupt */
2524 vdev->vxge_entries[intr_cnt].in_use = 1;
2525 vxge_hw_vpath_msix_unmask(
2526 vdev->vpaths[vp_idx].handle,
2531 /* Point to next vpath handler */
2532 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0)
2533 && (vp_idx < (vdev->no_of_vpath - 1)))
2537 intr_cnt = vdev->max_vpath_supported * 2;
2538 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2539 "%s:vxge Alarm fn: %d MSI-X: %d",
2540 vdev->ndev->name, pci_fun,
2541 vdev->entries[intr_cnt].entry);
2542 /* For Alarm interrupts */
2543 ret = request_irq(vdev->entries[intr_cnt].vector,
2544 vxge_alarm_msix_handle, 0,
2545 vdev->desc[intr_cnt],
2546 &vdev->vpaths[vp_idx]);
2548 vxge_debug_init(VXGE_ERR,
2549 "%s: MSIX - %d Registration failed",
2550 vdev->ndev->name, intr_cnt);
2551 vxge_rem_msix_isr(vdev);
2552 if ((function_mode ==
2553 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2554 test_and_set_bit(__VXGE_STATE_CARD_UP,
2555 &driver_config->inta_dev_open))
2556 return VXGE_HW_FAIL;
2558 vxge_hw_device_set_intr_type(vdev->devh,
2559 VXGE_HW_INTR_MODE_IRQLINE);
2560 vdev->config.intr_type = INTA;
2561 vxge_debug_init(VXGE_ERR,
2562 "%s: Defaulting to INTA",
2564 vxge_close_vpaths(vdev, 1);
2565 vdev->no_of_vpath = 1;
2566 vdev->stats.vpaths_open = 1;
2571 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2573 vdev->vxge_entries[intr_cnt].in_use = 1;
2574 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[vp_idx];
2578 snprintf(vdev->desc[0], VXGE_INTR_STRLEN, "%s:vxge", vdev->ndev->name);
2580 if (vdev->config.intr_type == INTA) {
2581 ret = request_irq((int) vdev->pdev->irq,
2583 IRQF_SHARED, vdev->desc[0], vdev);
2585 vxge_debug_init(VXGE_ERR,
2586 "%s %s-%d: ISR registration failed",
2587 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2590 vxge_debug_init(VXGE_TRACE,
2591 "new %s-%d line allocated",
2592 "IRQ", vdev->pdev->irq);
2598 static void vxge_poll_vp_reset(unsigned long data)
2600 struct vxgedev *vdev = (struct vxgedev *)data;
2603 for (i = 0; i < vdev->no_of_vpath; i++) {
2604 if (test_bit(i, &vdev->vp_reset)) {
2605 vxge_reset_vpath(vdev, i);
2609 if (j && (vdev->config.intr_type != MSI_X)) {
2610 vxge_hw_device_unmask_all(vdev->devh);
2611 vxge_hw_device_flush_io(vdev->devh);
2614 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2617 static void vxge_poll_vp_lockup(unsigned long data)
2619 struct vxgedev *vdev = (struct vxgedev *)data;
2621 struct vxge_ring *ring;
2622 enum vxge_hw_status status = VXGE_HW_OK;
2624 for (i = 0; i < vdev->no_of_vpath; i++) {
2625 ring = &vdev->vpaths[i].ring;
2626 /* Did this vpath received any packets */
2627 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2628 status = vxge_hw_vpath_check_leak(ring->handle);
2630 /* Did it received any packets last time */
2631 if ((VXGE_HW_FAIL == status) &&
2632 (VXGE_HW_FAIL == ring->last_status)) {
2634 /* schedule vpath reset */
2635 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2637 /* disable interrupts for this vpath */
2638 vxge_vpath_intr_disable(vdev, i);
2640 /* stop the queue for this vpath */
2641 vxge_stop_tx_queue(&vdev->vpaths[i].
2647 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2648 ring->last_status = status;
2651 /* Check every 1 milli second */
2652 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2657 * @dev: pointer to the device structure.
2659 * This function is the open entry point of the driver. It mainly calls a
2660 * function to allocate Rx buffers and inserts them into the buffer
2661 * descriptors and then enables the Rx part of the NIC.
2662 * Return value: '0' on success and an appropriate (-)ve integer as
2663 * defined in errno.h file on failure.
2666 vxge_open(struct net_device *dev)
2668 enum vxge_hw_status status;
2669 struct vxgedev *vdev;
2670 struct __vxge_hw_device *hldev;
2673 u64 val64, function_mode;
2674 vxge_debug_entryexit(VXGE_TRACE,
2675 "%s: %s:%d", dev->name, __func__, __LINE__);
2677 vdev = (struct vxgedev *)netdev_priv(dev);
2678 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2679 function_mode = vdev->config.device_hw_info.function_mode;
2681 /* make sure you have link off by default every time Nic is
2683 netif_carrier_off(dev);
2685 /* Check for another device already opn with INTA */
2686 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2687 test_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open)) {
2693 status = vxge_open_vpaths(vdev);
2694 if (status != VXGE_HW_OK) {
2695 vxge_debug_init(VXGE_ERR,
2696 "%s: fatal: Vpath open failed", vdev->ndev->name);
2701 vdev->mtu = dev->mtu;
2703 status = vxge_add_isr(vdev);
2704 if (status != VXGE_HW_OK) {
2705 vxge_debug_init(VXGE_ERR,
2706 "%s: fatal: ISR add failed", dev->name);
2712 if (vdev->config.intr_type != MSI_X) {
2713 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2714 vdev->config.napi_weight);
2715 napi_enable(&vdev->napi);
2716 for (i = 0; i < vdev->no_of_vpath; i++)
2717 vdev->vpaths[i].ring.napi_p = &vdev->napi;
2719 for (i = 0; i < vdev->no_of_vpath; i++) {
2720 netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
2721 vxge_poll_msix, vdev->config.napi_weight);
2722 napi_enable(&vdev->vpaths[i].ring.napi);
2723 vdev->vpaths[i].ring.napi_p =
2724 &vdev->vpaths[i].ring.napi;
2729 if (vdev->config.rth_steering) {
2730 status = vxge_rth_configure(vdev);
2731 if (status != VXGE_HW_OK) {
2732 vxge_debug_init(VXGE_ERR,
2733 "%s: fatal: RTH configuration failed",
2740 for (i = 0; i < vdev->no_of_vpath; i++) {
2741 /* set initial mtu before enabling the device */
2742 status = vxge_hw_vpath_mtu_set(vdev->vpaths[i].handle,
2744 if (status != VXGE_HW_OK) {
2745 vxge_debug_init(VXGE_ERR,
2746 "%s: fatal: can not set new MTU", dev->name);
2752 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2753 vxge_debug_init(vdev->level_trace,
2754 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2755 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2757 /* Reprogram the DA table with populated mac addresses */
2758 for (i = 0; i < vdev->no_of_vpath; i++) {
2759 vxge_restore_vpath_mac_addr(&vdev->vpaths[i]);
2760 vxge_restore_vpath_vid_table(&vdev->vpaths[i]);
2763 /* Enable vpath to sniff all unicast/multicast traffic that not
2764 * addressed to them. We allow promiscous mode for PF only
2768 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2769 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2771 vxge_hw_mgmt_reg_write(vdev->devh,
2772 vxge_hw_mgmt_reg_type_mrpcim,
2774 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2775 rxmac_authorize_all_addr),
2778 vxge_hw_mgmt_reg_write(vdev->devh,
2779 vxge_hw_mgmt_reg_type_mrpcim,
2781 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2782 rxmac_authorize_all_vid),
2785 vxge_set_multicast(dev);
2787 /* Enabling Bcast and mcast for all vpath */
2788 for (i = 0; i < vdev->no_of_vpath; i++) {
2789 status = vxge_hw_vpath_bcast_enable(vdev->vpaths[i].handle);
2790 if (status != VXGE_HW_OK)
2791 vxge_debug_init(VXGE_ERR,
2792 "%s : Can not enable bcast for vpath "
2793 "id %d", dev->name, i);
2794 if (vdev->config.addr_learn_en) {
2796 vxge_hw_vpath_mcast_enable(vdev->vpaths[i].handle);
2797 if (status != VXGE_HW_OK)
2798 vxge_debug_init(VXGE_ERR,
2799 "%s : Can not enable mcast for vpath "
2800 "id %d", dev->name, i);
2804 vxge_hw_device_setpause_data(vdev->devh, 0,
2805 vdev->config.tx_pause_enable,
2806 vdev->config.rx_pause_enable);
2808 if (vdev->vp_reset_timer.function == NULL)
2809 vxge_os_timer(vdev->vp_reset_timer,
2810 vxge_poll_vp_reset, vdev, (HZ/2));
2812 if (vdev->vp_lockup_timer.function == NULL)
2813 vxge_os_timer(vdev->vp_lockup_timer,
2814 vxge_poll_vp_lockup, vdev, (HZ/2));
2816 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2820 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2821 netif_carrier_on(vdev->ndev);
2822 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
2823 vdev->stats.link_up++;
2826 vxge_hw_device_intr_enable(vdev->devh);
2830 for (i = 0; i < vdev->no_of_vpath; i++) {
2831 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
2833 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
2836 vxge_start_all_tx_queue(vdev);
2843 if (vdev->config.intr_type != MSI_X)
2844 napi_disable(&vdev->napi);
2846 for (i = 0; i < vdev->no_of_vpath; i++)
2847 napi_disable(&vdev->vpaths[i].ring.napi);
2851 vxge_close_vpaths(vdev, 0);
2853 vxge_debug_entryexit(VXGE_TRACE,
2854 "%s: %s:%d Exiting...",
2855 dev->name, __func__, __LINE__);
2859 /* Loop throught the mac address list and delete all the entries */
2860 void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2863 struct list_head *entry, *next;
2864 if (list_empty(&vpath->mac_addr_list))
2867 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2869 kfree((struct vxge_mac_addrs *)entry);
2873 static void vxge_napi_del_all(struct vxgedev *vdev)
2876 if (vdev->config.intr_type != MSI_X)
2877 netif_napi_del(&vdev->napi);
2879 for (i = 0; i < vdev->no_of_vpath; i++)
2880 netif_napi_del(&vdev->vpaths[i].ring.napi);
2885 int do_vxge_close(struct net_device *dev, int do_io)
2887 enum vxge_hw_status status;
2888 struct vxgedev *vdev;
2889 struct __vxge_hw_device *hldev;
2891 u64 val64, vpath_vector;
2892 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2893 dev->name, __func__, __LINE__);
2895 vdev = (struct vxgedev *)netdev_priv(dev);
2896 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2898 if (unlikely(!is_vxge_card_up(vdev)))
2901 /* If vxge_handle_crit_err task is executing,
2902 * wait till it completes. */
2903 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2906 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2908 /* Put the vpath back in normal mode */
2909 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2910 status = vxge_hw_mgmt_reg_read(vdev->devh,
2911 vxge_hw_mgmt_reg_type_mrpcim,
2914 struct vxge_hw_mrpcim_reg,
2915 rts_mgr_cbasin_cfg),
2918 if (status == VXGE_HW_OK) {
2919 val64 &= ~vpath_vector;
2920 status = vxge_hw_mgmt_reg_write(vdev->devh,
2921 vxge_hw_mgmt_reg_type_mrpcim,
2924 struct vxge_hw_mrpcim_reg,
2925 rts_mgr_cbasin_cfg),
2929 /* Remove the function 0 from promiscous mode */
2930 vxge_hw_mgmt_reg_write(vdev->devh,
2931 vxge_hw_mgmt_reg_type_mrpcim,
2933 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2934 rxmac_authorize_all_addr),
2937 vxge_hw_mgmt_reg_write(vdev->devh,
2938 vxge_hw_mgmt_reg_type_mrpcim,
2940 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2941 rxmac_authorize_all_vid),
2946 del_timer_sync(&vdev->vp_lockup_timer);
2948 del_timer_sync(&vdev->vp_reset_timer);
2951 if (vdev->config.intr_type != MSI_X)
2952 napi_disable(&vdev->napi);
2954 for (i = 0; i < vdev->no_of_vpath; i++)
2955 napi_disable(&vdev->vpaths[i].ring.napi);
2958 netif_carrier_off(vdev->ndev);
2959 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
2960 vxge_stop_all_tx_queue(vdev);
2962 /* Note that at this point xmit() is stopped by upper layer */
2964 vxge_hw_device_intr_disable(vdev->devh);
2970 vxge_napi_del_all(vdev);
2973 vxge_reset_all_vpaths(vdev);
2975 vxge_close_vpaths(vdev, 0);
2977 vxge_debug_entryexit(VXGE_TRACE,
2978 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2980 clear_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open);
2981 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2988 * @dev: device pointer.
2990 * This is the stop entry point of the driver. It needs to undo exactly
2991 * whatever was done by the open entry point, thus it's usually referred to
2992 * as the close function.Among other things this function mainly stops the
2993 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2994 * Return value: '0' on success and an appropriate (-)ve integer as
2995 * defined in errno.h file on failure.
2998 vxge_close(struct net_device *dev)
3000 do_vxge_close(dev, 1);
3006 * @dev: net device pointer.
3007 * @new_mtu :the new MTU size for the device.
3009 * A driver entry point to change MTU size for the device. Before changing
3010 * the MTU the device must be stopped.
3012 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3014 struct vxgedev *vdev = netdev_priv(dev);
3016 vxge_debug_entryexit(vdev->level_trace,
3017 "%s:%d", __func__, __LINE__);
3018 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3019 vxge_debug_init(vdev->level_err,
3020 "%s: mtu size is invalid", dev->name);
3024 /* check if device is down already */
3025 if (unlikely(!is_vxge_card_up(vdev))) {
3026 /* just store new value, will use later on open() */
3028 vxge_debug_init(vdev->level_err,
3029 "%s", "device is down on MTU change");
3033 vxge_debug_init(vdev->level_trace,
3034 "trying to apply new MTU %d", new_mtu);
3036 if (vxge_close(dev))
3040 vdev->mtu = new_mtu;
3045 vxge_debug_init(vdev->level_trace,
3046 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3048 vxge_debug_entryexit(vdev->level_trace,
3049 "%s:%d Exiting...", __func__, __LINE__);
3056 * @dev: pointer to the device structure
3058 * Updates the device statistics structure. This function updates the device
3059 * statistics structure in the net_device structure and returns a pointer
3062 static struct net_device_stats *
3063 vxge_get_stats(struct net_device *dev)
3065 struct vxgedev *vdev;
3066 struct net_device_stats *net_stats;
3069 vdev = netdev_priv(dev);
3071 net_stats = &vdev->stats.net_stats;
3073 memset(net_stats, 0, sizeof(struct net_device_stats));
3075 for (k = 0; k < vdev->no_of_vpath; k++) {
3076 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3077 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3078 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3079 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3080 net_stats->rx_dropped +=
3081 vdev->vpaths[k].ring.stats.rx_dropped;
3083 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3084 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3085 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3093 * @dev: Device pointer.
3094 * @ifr: An IOCTL specific structure, that can contain a pointer to
3095 * a proprietary structure used to pass information to the driver.
3096 * @cmd: This is used to distinguish between the different commands that
3097 * can be passed to the IOCTL functions.
3099 * Entry point for the Ioctl.
3101 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3108 * @dev: pointer to net device structure
3110 * Watchdog for transmit side.
3111 * This function is triggered if the Tx Queue is stopped
3112 * for a pre-defined amount of time when the Interface is still up.
3115 vxge_tx_watchdog(struct net_device *dev)
3117 struct vxgedev *vdev;
3119 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3121 vdev = (struct vxgedev *)netdev_priv(dev);
3123 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3126 vxge_debug_entryexit(VXGE_TRACE,
3127 "%s:%d Exiting...", __func__, __LINE__);
3131 * vxge_vlan_rx_register
3132 * @dev: net device pointer.
3135 * Vlan group registration
3138 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3140 struct vxgedev *vdev;
3141 struct vxge_vpath *vpath;
3144 enum vxge_hw_status status;
3147 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3149 vdev = (struct vxgedev *)netdev_priv(dev);
3151 vpath = &vdev->vpaths[0];
3152 if ((NULL == grp) && (vpath->is_open)) {
3153 /* Get the first vlan */
3154 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3156 while (status == VXGE_HW_OK) {
3158 /* Delete this vlan from the vid table */
3159 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3160 vpath = &vdev->vpaths[vp];
3161 if (!vpath->is_open)
3164 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3167 /* Get the next vlan to be deleted */
3168 vpath = &vdev->vpaths[0];
3169 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3175 for (i = 0; i < vdev->no_of_vpath; i++) {
3176 if (vdev->vpaths[i].is_configured)
3177 vdev->vpaths[i].ring.vlgrp = grp;
3180 vxge_debug_entryexit(VXGE_TRACE,
3181 "%s:%d Exiting...", __func__, __LINE__);
3185 * vxge_vlan_rx_add_vid
3186 * @dev: net device pointer.
3189 * Add the vlan id to the devices vlan id table
3192 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3194 struct vxgedev *vdev;
3195 struct vxge_vpath *vpath;
3198 vdev = (struct vxgedev *)netdev_priv(dev);
3200 /* Add these vlan to the vid table */
3201 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3202 vpath = &vdev->vpaths[vp_id];
3203 if (!vpath->is_open)
3205 vxge_hw_vpath_vid_add(vpath->handle, vid);
3210 * vxge_vlan_rx_add_vid
3211 * @dev: net device pointer.
3214 * Remove the vlan id from the device's vlan id table
3217 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3219 struct vxgedev *vdev;
3220 struct vxge_vpath *vpath;
3223 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3225 vdev = (struct vxgedev *)netdev_priv(dev);
3227 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3229 /* Delete this vlan from the vid table */
3230 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3231 vpath = &vdev->vpaths[vp_id];
3232 if (!vpath->is_open)
3234 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3236 vxge_debug_entryexit(VXGE_TRACE,
3237 "%s:%d Exiting...", __func__, __LINE__);
3240 static const struct net_device_ops vxge_netdev_ops = {
3241 .ndo_open = vxge_open,
3242 .ndo_stop = vxge_close,
3243 .ndo_get_stats = vxge_get_stats,
3244 .ndo_start_xmit = vxge_xmit,
3245 .ndo_validate_addr = eth_validate_addr,
3246 .ndo_set_multicast_list = vxge_set_multicast,
3248 .ndo_do_ioctl = vxge_ioctl,
3250 .ndo_set_mac_address = vxge_set_mac_addr,
3251 .ndo_change_mtu = vxge_change_mtu,
3252 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3253 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3254 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3256 .ndo_tx_timeout = vxge_tx_watchdog,
3257 #ifdef CONFIG_NET_POLL_CONTROLLER
3258 .ndo_poll_controller = vxge_netpoll,
3262 int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3263 struct vxge_config *config,
3264 int high_dma, int no_of_vpath,
3265 struct vxgedev **vdev_out)
3267 struct net_device *ndev;
3268 enum vxge_hw_status status = VXGE_HW_OK;
3269 struct vxgedev *vdev;
3270 int i, ret = 0, no_of_queue = 1;
3274 if (config->tx_steering_type == TX_MULTIQ_STEERING)
3275 no_of_queue = no_of_vpath;
3277 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3281 vxge_hw_device_trace_level_get(hldev),
3282 "%s : device allocation failed", __func__);
3287 vxge_debug_entryexit(
3288 vxge_hw_device_trace_level_get(hldev),
3289 "%s: %s:%d Entering...",
3290 ndev->name, __func__, __LINE__);
3292 vdev = netdev_priv(ndev);
3293 memset(vdev, 0, sizeof(struct vxgedev));
3297 vdev->pdev = hldev->pdev;
3298 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3299 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3301 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3303 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3304 NETIF_F_HW_VLAN_FILTER;
3305 /* Driver entry points */
3306 ndev->irq = vdev->pdev->irq;
3307 ndev->base_addr = (unsigned long) hldev->bar0;
3309 ndev->netdev_ops = &vxge_netdev_ops;
3311 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3313 initialize_ethtool_ops(ndev);
3315 /* Allocate memory for vpath */
3316 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3317 no_of_vpath, GFP_KERNEL);
3318 if (!vdev->vpaths) {
3319 vxge_debug_init(VXGE_ERR,
3320 "%s: vpath memory allocation failed",
3326 ndev->features |= NETIF_F_SG;
3328 ndev->features |= NETIF_F_HW_CSUM;
3329 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3330 "%s : checksuming enabled", __func__);
3333 ndev->features |= NETIF_F_HIGHDMA;
3334 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3335 "%s : using High DMA", __func__);
3338 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3340 if (vdev->config.gro_enable)
3341 ndev->features |= NETIF_F_GRO;
3343 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
3344 ndev->real_num_tx_queues = no_of_vpath;
3347 ndev->features |= NETIF_F_LLTX;
3350 for (i = 0; i < no_of_vpath; i++)
3351 spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
3353 if (register_netdev(ndev)) {
3354 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3355 "%s: %s : device registration failed!",
3356 ndev->name, __func__);
3361 /* Set the factory defined MAC address initially */
3362 ndev->addr_len = ETH_ALEN;
3364 /* Make Link state as off at this point, when the Link change
3365 * interrupt comes the state will be automatically changed to
3368 netif_carrier_off(ndev);
3370 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3371 "%s: Ethernet device registered",
3376 /* Resetting the Device stats */
3377 status = vxge_hw_mrpcim_stats_access(
3379 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3384 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3386 vxge_hw_device_trace_level_get(hldev),
3387 "%s: device stats clear returns"
3388 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3390 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3391 "%s: %s:%d Exiting...",
3392 ndev->name, __func__, __LINE__);
3396 kfree(vdev->vpaths);
3404 * vxge_device_unregister
3406 * This function will unregister and free network device
3409 vxge_device_unregister(struct __vxge_hw_device *hldev)
3411 struct vxgedev *vdev;
3412 struct net_device *dev;
3414 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3415 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3420 vdev = netdev_priv(dev);
3421 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3422 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3423 level_trace = vdev->level_trace;
3425 vxge_debug_entryexit(level_trace,
3426 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3428 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3430 /* in 2.6 will call stop() if device is up */
3431 unregister_netdev(dev);
3433 flush_scheduled_work();
3435 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3436 vxge_debug_entryexit(level_trace,
3437 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3441 * vxge_callback_crit_err
3443 * This function is called by the alarm handler in interrupt context.
3444 * Driver must analyze it based on the event type.
3447 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3448 enum vxge_hw_event type, u64 vp_id)
3450 struct net_device *dev = hldev->ndev;
3451 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3454 vxge_debug_entryexit(vdev->level_trace,
3455 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3457 /* Note: This event type should be used for device wide
3458 * indications only - Serious errors, Slot freeze and critical errors
3460 vdev->cric_err_event = type;
3462 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
3463 if (vdev->vpaths[vpath_idx].device_id == vp_id)
3466 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3467 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3468 vxge_debug_init(VXGE_ERR,
3469 "%s: Slot is frozen", vdev->ndev->name);
3470 } else if (type == VXGE_HW_EVENT_SERR) {
3471 vxge_debug_init(VXGE_ERR,
3472 "%s: Encountered Serious Error",
3474 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3475 vxge_debug_init(VXGE_ERR,
3476 "%s: Encountered Critical Error",
3480 if ((type == VXGE_HW_EVENT_SERR) ||
3481 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3482 if (unlikely(vdev->exec_mode))
3483 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3484 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3485 vxge_hw_device_mask_all(hldev);
3486 if (unlikely(vdev->exec_mode))
3487 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3488 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3489 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3491 if (unlikely(vdev->exec_mode))
3492 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3494 /* check if this vpath is already set for reset */
3495 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3497 /* disable interrupts for this vpath */
3498 vxge_vpath_intr_disable(vdev, vpath_idx);
3500 /* stop the queue for this vpath */
3501 vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
3507 vxge_debug_entryexit(vdev->level_trace,
3508 "%s: %s:%d Exiting...",
3509 vdev->ndev->name, __func__, __LINE__);
3512 static void verify_bandwidth(void)
3514 int i, band_width, total = 0, equal_priority = 0;
3516 /* 1. If user enters 0 for some fifo, give equal priority to all */
3517 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3518 if (bw_percentage[i] == 0) {
3524 if (!equal_priority) {
3525 /* 2. If sum exceeds 100, give equal priority to all */
3526 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3527 if (bw_percentage[i] == 0xFF)
3530 total += bw_percentage[i];
3531 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3538 if (!equal_priority) {
3539 /* Is all the bandwidth consumed? */
3540 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3541 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3542 /* Split rest of bw equally among next VPs*/
3544 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3545 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3546 if (band_width < 2) /* min of 2% */
3549 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3555 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3559 if (equal_priority) {
3560 vxge_debug_init(VXGE_ERR,
3561 "%s: Assigning equal bandwidth to all the vpaths",
3563 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3564 VXGE_HW_MAX_VIRTUAL_PATHS;
3565 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3566 bw_percentage[i] = bw_percentage[0];
3573 * Vpath configuration
3575 static int __devinit vxge_config_vpaths(
3576 struct vxge_hw_device_config *device_config,
3577 u64 vpath_mask, struct vxge_config *config_param)
3579 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3580 u32 txdl_size, txdl_per_memblock;
3582 temp = driver_config->vpath_per_dev;
3583 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3584 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3585 /* No more CPU. Return vpath number as zero.*/
3586 if (driver_config->g_no_cpus == -1)
3589 if (!driver_config->g_no_cpus)
3590 driver_config->g_no_cpus = num_online_cpus();
3592 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3593 if (!driver_config->vpath_per_dev)
3594 driver_config->vpath_per_dev = 1;
3596 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3597 if (!vxge_bVALn(vpath_mask, i, 1))
3601 if (default_no_vpath < driver_config->vpath_per_dev)
3602 driver_config->vpath_per_dev = default_no_vpath;
3604 driver_config->g_no_cpus = driver_config->g_no_cpus -
3605 (driver_config->vpath_per_dev * 2);
3606 if (driver_config->g_no_cpus <= 0)
3607 driver_config->g_no_cpus = -1;
3610 if (driver_config->vpath_per_dev == 1) {
3611 vxge_debug_ll_config(VXGE_TRACE,
3612 "%s: Disable tx and rx steering, "
3613 "as single vpath is configured", VXGE_DRIVER_NAME);
3614 config_param->rth_steering = NO_STEERING;
3615 config_param->tx_steering_type = NO_STEERING;
3616 device_config->rth_en = 0;
3619 /* configure bandwidth */
3620 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3621 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3623 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3624 device_config->vp_config[i].vp_id = i;
3625 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3626 if (no_of_vpaths < driver_config->vpath_per_dev) {
3627 if (!vxge_bVALn(vpath_mask, i, 1)) {
3628 vxge_debug_ll_config(VXGE_TRACE,
3629 "%s: vpath: %d is not available",
3630 VXGE_DRIVER_NAME, i);
3633 vxge_debug_ll_config(VXGE_TRACE,
3634 "%s: vpath: %d available",
3635 VXGE_DRIVER_NAME, i);
3639 vxge_debug_ll_config(VXGE_TRACE,
3640 "%s: vpath: %d is not configured, "
3641 "max_config_vpath exceeded",
3642 VXGE_DRIVER_NAME, i);
3646 /* Configure Tx fifo's */
3647 device_config->vp_config[i].fifo.enable =
3648 VXGE_HW_FIFO_ENABLE;
3649 device_config->vp_config[i].fifo.max_frags =
3651 device_config->vp_config[i].fifo.memblock_size =
3652 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3654 txdl_size = MAX_SKB_FRAGS * sizeof(struct vxge_hw_fifo_txd);
3655 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3657 device_config->vp_config[i].fifo.fifo_blocks =
3658 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3660 device_config->vp_config[i].fifo.intr =
3661 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3663 /* Configure tti properties */
3664 device_config->vp_config[i].tti.intr_enable =
3665 VXGE_HW_TIM_INTR_ENABLE;
3667 device_config->vp_config[i].tti.btimer_val =
3668 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3670 device_config->vp_config[i].tti.timer_ac_en =
3671 VXGE_HW_TIM_TIMER_AC_ENABLE;
3673 /* For msi-x with napi (each vector
3674 has a handler of its own) -
3675 Set CI to OFF for all vpaths */
3676 device_config->vp_config[i].tti.timer_ci_en =
3677 VXGE_HW_TIM_TIMER_CI_DISABLE;
3679 device_config->vp_config[i].tti.timer_ri_en =
3680 VXGE_HW_TIM_TIMER_RI_DISABLE;
3682 device_config->vp_config[i].tti.util_sel =
3683 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3685 device_config->vp_config[i].tti.ltimer_val =
3686 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3688 device_config->vp_config[i].tti.rtimer_val =
3689 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3691 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3692 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3693 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3694 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3695 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3696 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3697 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3699 /* Configure Rx rings */
3700 device_config->vp_config[i].ring.enable =
3701 VXGE_HW_RING_ENABLE;
3703 device_config->vp_config[i].ring.ring_blocks =
3704 VXGE_HW_DEF_RING_BLOCKS;
3705 device_config->vp_config[i].ring.buffer_mode =
3706 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3707 device_config->vp_config[i].ring.rxds_limit =
3708 VXGE_HW_DEF_RING_RXDS_LIMIT;
3709 device_config->vp_config[i].ring.scatter_mode =
3710 VXGE_HW_RING_SCATTER_MODE_A;
3712 /* Configure rti properties */
3713 device_config->vp_config[i].rti.intr_enable =
3714 VXGE_HW_TIM_INTR_ENABLE;
3716 device_config->vp_config[i].rti.btimer_val =
3717 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3719 device_config->vp_config[i].rti.timer_ac_en =
3720 VXGE_HW_TIM_TIMER_AC_ENABLE;
3722 device_config->vp_config[i].rti.timer_ci_en =
3723 VXGE_HW_TIM_TIMER_CI_DISABLE;
3725 device_config->vp_config[i].rti.timer_ri_en =
3726 VXGE_HW_TIM_TIMER_RI_DISABLE;
3728 device_config->vp_config[i].rti.util_sel =
3729 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3731 device_config->vp_config[i].rti.urange_a =
3733 device_config->vp_config[i].rti.urange_b =
3735 device_config->vp_config[i].rti.urange_c =
3737 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3738 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3739 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3740 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3742 device_config->vp_config[i].rti.rtimer_val =
3743 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3745 device_config->vp_config[i].rti.ltimer_val =
3746 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3748 device_config->vp_config[i].rpa_strip_vlan_tag =
3752 driver_config->vpath_per_dev = temp;
3753 return no_of_vpaths;
3756 /* initialize device configuratrions */
3757 static void __devinit vxge_device_config_init(
3758 struct vxge_hw_device_config *device_config,
3761 /* Used for CQRQ/SRQ. */
3762 device_config->dma_blockpool_initial =
3763 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3765 device_config->dma_blockpool_max =
3766 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3768 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3769 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3771 #ifndef CONFIG_PCI_MSI
3772 vxge_debug_init(VXGE_ERR,
3773 "%s: This Kernel does not support "
3774 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3778 /* Configure whether MSI-X or IRQL. */
3779 switch (*intr_type) {
3781 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3785 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3788 /* Timer period between device poll */
3789 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3791 /* Configure mac based steering. */
3792 device_config->rts_mac_en = addr_learn_en;
3794 /* Configure Vpaths */
3795 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3797 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3799 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3800 device_config->dma_blockpool_initial);
3801 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3802 device_config->dma_blockpool_max);
3803 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3804 device_config->intr_mode);
3805 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3806 device_config->device_poll_millis);
3807 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3808 device_config->rts_mac_en);
3809 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3810 device_config->rth_en);
3811 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3812 device_config->rth_it_type);
3815 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3819 vxge_debug_init(VXGE_TRACE,
3820 "%s: %d Vpath(s) opened",
3821 vdev->ndev->name, vdev->no_of_vpath);
3823 switch (vdev->config.intr_type) {
3825 vxge_debug_init(VXGE_TRACE,
3826 "%s: Interrupt type INTA", vdev->ndev->name);
3830 vxge_debug_init(VXGE_TRACE,
3831 "%s: Interrupt type MSI-X", vdev->ndev->name);
3835 if (vdev->config.rth_steering) {
3836 vxge_debug_init(VXGE_TRACE,
3837 "%s: RTH steering enabled for TCP_IPV4",
3840 vxge_debug_init(VXGE_TRACE,
3841 "%s: RTH steering disabled", vdev->ndev->name);
3844 switch (vdev->config.tx_steering_type) {
3846 vxge_debug_init(VXGE_TRACE,
3847 "%s: Tx steering disabled", vdev->ndev->name);
3849 case TX_PRIORITY_STEERING:
3850 vxge_debug_init(VXGE_TRACE,
3851 "%s: Unsupported tx steering option",
3853 vxge_debug_init(VXGE_TRACE,
3854 "%s: Tx steering disabled", vdev->ndev->name);
3855 vdev->config.tx_steering_type = 0;
3857 case TX_VLAN_STEERING:
3858 vxge_debug_init(VXGE_TRACE,
3859 "%s: Unsupported tx steering option",
3861 vxge_debug_init(VXGE_TRACE,
3862 "%s: Tx steering disabled", vdev->ndev->name);
3863 vdev->config.tx_steering_type = 0;
3865 case TX_MULTIQ_STEERING:
3866 vxge_debug_init(VXGE_TRACE,
3867 "%s: Tx multiqueue steering enabled",
3870 case TX_PORT_STEERING:
3871 vxge_debug_init(VXGE_TRACE,
3872 "%s: Tx port steering enabled",
3876 vxge_debug_init(VXGE_ERR,
3877 "%s: Unsupported tx steering type",
3879 vxge_debug_init(VXGE_TRACE,
3880 "%s: Tx steering disabled", vdev->ndev->name);
3881 vdev->config.tx_steering_type = 0;
3884 if (vdev->config.gro_enable) {
3885 vxge_debug_init(VXGE_ERR,
3886 "%s: Generic receive offload enabled",
3889 vxge_debug_init(VXGE_TRACE,
3890 "%s: Generic receive offload disabled",
3893 if (vdev->config.addr_learn_en)
3894 vxge_debug_init(VXGE_TRACE,
3895 "%s: MAC Address learning enabled", vdev->ndev->name);
3897 vxge_debug_init(VXGE_TRACE,
3898 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3900 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3901 if (!vxge_bVALn(vpath_mask, i, 1))
3903 vxge_debug_ll_config(VXGE_TRACE,
3904 "%s: MTU size - %d", vdev->ndev->name,
3905 ((struct __vxge_hw_device *)(vdev->devh))->
3906 config.vp_config[i].mtu);
3907 vxge_debug_init(VXGE_TRACE,
3908 "%s: VLAN tag stripping %s", vdev->ndev->name,
3909 ((struct __vxge_hw_device *)(vdev->devh))->
3910 config.vp_config[i].rpa_strip_vlan_tag
3911 ? "Enabled" : "Disabled");
3912 vxge_debug_init(VXGE_TRACE,
3913 "%s: Ring blocks : %d", vdev->ndev->name,
3914 ((struct __vxge_hw_device *)(vdev->devh))->
3915 config.vp_config[i].ring.ring_blocks);
3916 vxge_debug_init(VXGE_TRACE,
3917 "%s: Fifo blocks : %d", vdev->ndev->name,
3918 ((struct __vxge_hw_device *)(vdev->devh))->
3919 config.vp_config[i].fifo.fifo_blocks);
3920 vxge_debug_ll_config(VXGE_TRACE,
3921 "%s: Max frags : %d", vdev->ndev->name,
3922 ((struct __vxge_hw_device *)(vdev->devh))->
3923 config.vp_config[i].fifo.max_frags);
3930 * vxge_pm_suspend - vxge power management suspend entry point
3933 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3938 * vxge_pm_resume - vxge power management resume entry point
3941 static int vxge_pm_resume(struct pci_dev *pdev)
3949 * vxge_io_error_detected - called when PCI error is detected
3950 * @pdev: Pointer to PCI device
3951 * @state: The current pci connection state
3953 * This function is called after a PCI bus error affecting
3954 * this device has been detected.
3956 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3957 pci_channel_state_t state)
3959 struct __vxge_hw_device *hldev =
3960 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3961 struct net_device *netdev = hldev->ndev;
3963 netif_device_detach(netdev);
3965 if (state == pci_channel_io_perm_failure)
3966 return PCI_ERS_RESULT_DISCONNECT;
3968 if (netif_running(netdev)) {
3969 /* Bring down the card, while avoiding PCI I/O */
3970 do_vxge_close(netdev, 0);
3973 pci_disable_device(pdev);
3975 return PCI_ERS_RESULT_NEED_RESET;
3979 * vxge_io_slot_reset - called after the pci bus has been reset.
3980 * @pdev: Pointer to PCI device
3982 * Restart the card from scratch, as if from a cold-boot.
3983 * At this point, the card has exprienced a hard reset,
3984 * followed by fixups by BIOS, and has its config space
3985 * set up identically to what it was at cold boot.
3987 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3989 struct __vxge_hw_device *hldev =
3990 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3991 struct net_device *netdev = hldev->ndev;
3993 struct vxgedev *vdev = netdev_priv(netdev);
3995 if (pci_enable_device(pdev)) {
3996 printk(KERN_ERR "%s: "
3997 "Cannot re-enable device after reset\n",
3999 return PCI_ERS_RESULT_DISCONNECT;
4002 pci_set_master(pdev);
4005 return PCI_ERS_RESULT_RECOVERED;
4009 * vxge_io_resume - called when traffic can start flowing again.
4010 * @pdev: Pointer to PCI device
4012 * This callback is called when the error recovery driver tells
4013 * us that its OK to resume normal operation.
4015 static void vxge_io_resume(struct pci_dev *pdev)
4017 struct __vxge_hw_device *hldev =
4018 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4019 struct net_device *netdev = hldev->ndev;
4021 if (netif_running(netdev)) {
4022 if (vxge_open(netdev)) {
4023 printk(KERN_ERR "%s: "
4024 "Can't bring device back up after reset\n",
4030 netif_device_attach(netdev);
4035 * @pdev : structure containing the PCI related information of the device.
4036 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4038 * This function is called when a new PCI device gets detected and initializes
4041 * returns 0 on success and negative on failure.
4044 static int __devinit
4045 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4047 struct __vxge_hw_device *hldev;
4048 enum vxge_hw_status status;
4052 struct vxgedev *vdev;
4053 struct vxge_config ll_config;
4054 struct vxge_hw_device_config *device_config = NULL;
4055 struct vxge_hw_device_attr attr;
4056 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4058 struct vxge_mac_addrs *entry;
4059 static int bus = -1, device = -1;
4062 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4065 if (bus != pdev->bus->number)
4067 if (device != PCI_SLOT(pdev->devfn))
4070 bus = pdev->bus->number;
4071 device = PCI_SLOT(pdev->devfn);
4074 if (driver_config->config_dev_cnt &&
4075 (driver_config->config_dev_cnt !=
4076 driver_config->total_dev_cnt))
4077 vxge_debug_init(VXGE_ERR,
4078 "%s: Configured %d of %d devices",
4080 driver_config->config_dev_cnt,
4081 driver_config->total_dev_cnt);
4082 driver_config->config_dev_cnt = 0;
4083 driver_config->total_dev_cnt = 0;
4084 driver_config->g_no_cpus = 0;
4085 driver_config->vpath_per_dev = max_config_vpath;
4088 driver_config->total_dev_cnt++;
4089 if (++driver_config->config_dev_cnt > max_config_dev) {
4094 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4096 if (!device_config) {
4098 vxge_debug_init(VXGE_ERR,
4099 "device_config : malloc failed %s %d",
4100 __FILE__, __LINE__);
4104 memset(&ll_config, 0, sizeof(struct vxge_config));
4105 ll_config.tx_steering_type = TX_MULTIQ_STEERING;
4106 ll_config.intr_type = MSI_X;
4107 ll_config.napi_weight = NEW_NAPI_WEIGHT;
4108 ll_config.rth_steering = RTH_STEERING;
4110 /* get the default configuration parameters */
4111 vxge_hw_device_config_default_get(device_config);
4113 /* initialize configuration parameters */
4114 vxge_device_config_init(device_config, &ll_config.intr_type);
4116 ret = pci_enable_device(pdev);
4118 vxge_debug_init(VXGE_ERR,
4119 "%s : can not enable PCI device", __func__);
4123 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
4124 vxge_debug_ll_config(VXGE_TRACE,
4125 "%s : using 64bit DMA", __func__);
4129 if (pci_set_consistent_dma_mask(pdev,
4130 0xffffffffffffffffULL)) {
4131 vxge_debug_init(VXGE_ERR,
4132 "%s : unable to obtain 64bit DMA for "
4133 "consistent allocations", __func__);
4137 } else if (!pci_set_dma_mask(pdev, 0xffffffffUL)) {
4138 vxge_debug_ll_config(VXGE_TRACE,
4139 "%s : using 32bit DMA", __func__);
4145 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4146 vxge_debug_init(VXGE_ERR,
4147 "%s : request regions failed", __func__);
4152 pci_set_master(pdev);
4154 attr.bar0 = pci_ioremap_bar(pdev, 0);
4156 vxge_debug_init(VXGE_ERR,
4157 "%s : cannot remap io memory bar0", __func__);
4161 vxge_debug_ll_config(VXGE_TRACE,
4162 "pci ioremap bar0: %p:0x%llx",
4164 (unsigned long long)pci_resource_start(pdev, 0));
4166 status = vxge_hw_device_hw_info_get(attr.bar0,
4167 &ll_config.device_hw_info);
4168 if (status != VXGE_HW_OK) {
4169 vxge_debug_init(VXGE_ERR,
4170 "%s: Reading of hardware info failed."
4171 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4176 if (ll_config.device_hw_info.fw_version.major !=
4177 VXGE_DRIVER_FW_VERSION_MAJOR) {
4178 vxge_debug_init(VXGE_ERR,
4179 "%s: Incorrect firmware version."
4180 "Please upgrade the firmware to version 1.x.x",
4186 vpath_mask = ll_config.device_hw_info.vpath_mask;
4187 if (vpath_mask == 0) {
4188 vxge_debug_ll_config(VXGE_TRACE,
4189 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4194 vxge_debug_ll_config(VXGE_TRACE,
4195 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4196 (unsigned long long)vpath_mask);
4198 /* Check how many vpaths are available */
4199 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4200 if (!((vpath_mask) & vxge_mBIT(i)))
4202 max_vpath_supported++;
4205 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4206 if ((VXGE_HW_FUNCTION_MODE_SRIOV ==
4207 ll_config.device_hw_info.function_mode) &&
4208 (max_config_dev > 1) && (pdev->is_physfn)) {
4209 ret = pci_enable_sriov(pdev, max_config_dev - 1);
4211 vxge_debug_ll_config(VXGE_ERR,
4212 "Failed to enable SRIOV: %d \n", ret);
4216 * Configure vpaths and get driver configured number of vpaths
4217 * which is less than or equal to the maximum vpaths per function.
4219 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, &ll_config);
4221 vxge_debug_ll_config(VXGE_ERR,
4222 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4227 /* Setting driver callbacks */
4228 attr.uld_callbacks.link_up = vxge_callback_link_up;
4229 attr.uld_callbacks.link_down = vxge_callback_link_down;
4230 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4232 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4233 if (status != VXGE_HW_OK) {
4234 vxge_debug_init(VXGE_ERR,
4235 "Failed to initialize device (%d)", status);
4240 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4242 /* set private device info */
4243 pci_set_drvdata(pdev, hldev);
4245 ll_config.gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4246 ll_config.fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4247 ll_config.addr_learn_en = addr_learn_en;
4248 ll_config.rth_algorithm = RTH_ALG_JENKINS;
4249 ll_config.rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
4250 ll_config.rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
4251 ll_config.rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4252 ll_config.rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4253 ll_config.rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4254 ll_config.rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4255 ll_config.rth_bkt_sz = RTH_BUCKET_SIZE;
4256 ll_config.tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4257 ll_config.rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4259 if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath,
4265 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4266 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4267 vxge_hw_device_trace_level_get(hldev));
4269 /* set private HW device info */
4270 hldev->ndev = vdev->ndev;
4271 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4272 vdev->bar0 = attr.bar0;
4273 vdev->max_vpath_supported = max_vpath_supported;
4274 vdev->no_of_vpath = no_of_vpath;
4276 /* Virtual Path count */
4277 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4278 if (!vxge_bVALn(vpath_mask, i, 1))
4280 if (j >= vdev->no_of_vpath)
4283 vdev->vpaths[j].is_configured = 1;
4284 vdev->vpaths[j].device_id = i;
4285 vdev->vpaths[j].fifo.driver_id = j;
4286 vdev->vpaths[j].ring.driver_id = j;
4287 vdev->vpaths[j].vdev = vdev;
4288 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4289 memcpy((u8 *)vdev->vpaths[j].macaddr,
4290 (u8 *)ll_config.device_hw_info.mac_addrs[i],
4293 /* Initialize the mac address list header */
4294 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4296 vdev->vpaths[j].mac_addr_cnt = 0;
4297 vdev->vpaths[j].mcast_addr_cnt = 0;
4300 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4301 vdev->max_config_port = max_config_port;
4303 vdev->vlan_tag_strip = vlan_tag_strip;
4305 /* map the hashing selector table to the configured vpaths */
4306 for (i = 0; i < vdev->no_of_vpath; i++)
4307 vdev->vpath_selector[i] = vpath_selector[i];
4309 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4311 ll_config.device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4312 ll_config.device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4313 ll_config.device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4315 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4316 vdev->ndev->name, ll_config.device_hw_info.serial_number);
4318 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4319 vdev->ndev->name, ll_config.device_hw_info.part_number);
4321 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4322 vdev->ndev->name, ll_config.device_hw_info.product_desc);
4324 vxge_debug_init(VXGE_TRACE,
4325 "%s: MAC ADDR: %02X:%02X:%02X:%02X:%02X:%02X",
4326 vdev->ndev->name, macaddr[0], macaddr[1], macaddr[2],
4327 macaddr[3], macaddr[4], macaddr[5]);
4329 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4330 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4332 vxge_debug_init(VXGE_TRACE,
4333 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4334 ll_config.device_hw_info.fw_version.version,
4335 ll_config.device_hw_info.fw_date.date);
4338 switch (ll_config.device_hw_info.function_mode) {
4339 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4340 vxge_debug_init(VXGE_TRACE,
4341 "%s: Single Function Mode Enabled", vdev->ndev->name);
4343 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4344 vxge_debug_init(VXGE_TRACE,
4345 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4347 case VXGE_HW_FUNCTION_MODE_SRIOV:
4348 vxge_debug_init(VXGE_TRACE,
4349 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4351 case VXGE_HW_FUNCTION_MODE_MRIOV:
4352 vxge_debug_init(VXGE_TRACE,
4353 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4358 vxge_print_parm(vdev, vpath_mask);
4360 /* Store the fw version for ethttool option */
4361 strcpy(vdev->fw_version, ll_config.device_hw_info.fw_version.version);
4362 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4363 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4365 /* Copy the station mac address to the list */
4366 for (i = 0; i < vdev->no_of_vpath; i++) {
4367 entry = (struct vxge_mac_addrs *)
4368 kzalloc(sizeof(struct vxge_mac_addrs),
4370 if (NULL == entry) {
4371 vxge_debug_init(VXGE_ERR,
4372 "%s: mac_addr_list : memory allocation failed",
4377 macaddr = (u8 *)&entry->macaddr;
4378 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4379 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4380 vdev->vpaths[i].mac_addr_cnt = 1;
4383 kfree(device_config);
4384 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4385 vdev->ndev->name, __func__, __LINE__);
4387 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4388 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4389 vxge_hw_device_trace_level_get(hldev));
4394 for (i = 0; i < vdev->no_of_vpath; i++)
4395 vxge_free_mac_add_list(&vdev->vpaths[i]);
4397 vxge_device_unregister(hldev);
4399 pci_disable_sriov(pdev);
4400 vxge_hw_device_terminate(hldev);
4404 pci_release_regions(pdev);
4406 pci_disable_device(pdev);
4408 kfree(device_config);
4409 driver_config->config_dev_cnt--;
4410 pci_set_drvdata(pdev, NULL);
4415 * vxge_rem_nic - Free the PCI device
4416 * @pdev: structure containing the PCI related information of the device.
4417 * Description: This function is called by the Pci subsystem to release a
4418 * PCI device and free up all resource held up by the device.
4420 static void __devexit
4421 vxge_remove(struct pci_dev *pdev)
4423 struct __vxge_hw_device *hldev;
4424 struct vxgedev *vdev = NULL;
4425 struct net_device *dev;
4427 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4428 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4432 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4437 vdev = netdev_priv(dev);
4439 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4440 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4441 level_trace = vdev->level_trace;
4443 vxge_debug_entryexit(level_trace,
4444 "%s:%d", __func__, __LINE__);
4446 vxge_debug_init(level_trace,
4447 "%s : removing PCI device...", __func__);
4448 vxge_device_unregister(hldev);
4450 for (i = 0; i < vdev->no_of_vpath; i++) {
4451 vxge_free_mac_add_list(&vdev->vpaths[i]);
4452 vdev->vpaths[i].mcast_addr_cnt = 0;
4453 vdev->vpaths[i].mac_addr_cnt = 0;
4456 kfree(vdev->vpaths);
4458 iounmap(vdev->bar0);
4460 pci_disable_sriov(pdev);
4462 /* we are safe to free it now */
4465 vxge_debug_init(level_trace,
4466 "%s:%d Device unregistered", __func__, __LINE__);
4468 vxge_hw_device_terminate(hldev);
4470 pci_disable_device(pdev);
4471 pci_release_regions(pdev);
4472 pci_set_drvdata(pdev, NULL);
4473 vxge_debug_entryexit(level_trace,
4474 "%s:%d Exiting...", __func__, __LINE__);
4477 static struct pci_error_handlers vxge_err_handler = {
4478 .error_detected = vxge_io_error_detected,
4479 .slot_reset = vxge_io_slot_reset,
4480 .resume = vxge_io_resume,
4483 static struct pci_driver vxge_driver = {
4484 .name = VXGE_DRIVER_NAME,
4485 .id_table = vxge_id_table,
4486 .probe = vxge_probe,
4487 .remove = __devexit_p(vxge_remove),
4489 .suspend = vxge_pm_suspend,
4490 .resume = vxge_pm_resume,
4492 .err_handler = &vxge_err_handler,
4500 snprintf(version, 32, "%s", DRV_VERSION);
4502 printk(KERN_CRIT "%s: Copyright(c) 2002-2009 Neterion Inc\n",
4504 printk(KERN_CRIT "%s: Driver version: %s\n",
4505 VXGE_DRIVER_NAME, version);
4509 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4513 ret = pci_register_driver(&vxge_driver);
4515 if (driver_config->config_dev_cnt &&
4516 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4517 vxge_debug_init(VXGE_ERR,
4518 "%s: Configured %d of %d devices",
4519 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4520 driver_config->total_dev_cnt);
4523 kfree(driver_config);
4531 pci_unregister_driver(&vxge_driver);
4532 kfree(driver_config);
4534 module_init(vxge_starter);
4535 module_exit(vxge_closer);