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 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
899 if (unlikely(status != VXGE_HW_OK)) {
900 vxge_debug_tx(VXGE_ERR,
901 "%s: Out of descriptors .", dev->name);
902 fifo->stats.txd_out_of_desc++;
903 vxge_stop_tx_queue(fifo);
907 vxge_debug_tx(VXGE_TRACE,
908 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
909 dev->name, __func__, __LINE__,
910 fifo_hw, dtr, dtr_priv);
912 if (vdev->vlgrp && vlan_tx_tag_present(skb)) {
913 u16 vlan_tag = vlan_tx_tag_get(skb);
914 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
917 first_frg_len = skb_headlen(skb);
919 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
922 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
923 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
924 vxge_stop_tx_queue(fifo);
925 fifo->stats.pci_map_fail++;
929 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
930 txdl_priv->skb = skb;
931 txdl_priv->dma_buffers[j] = dma_pointer;
933 frg_cnt = skb_shinfo(skb)->nr_frags;
934 vxge_debug_tx(VXGE_TRACE,
935 "%s: %s:%d skb = %p txdl_priv = %p "
936 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
937 __func__, __LINE__, skb, txdl_priv,
938 frg_cnt, (unsigned long long)dma_pointer);
940 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
943 frag = &skb_shinfo(skb)->frags[0];
944 for (i = 0; i < frg_cnt; i++) {
945 /* ignore 0 length fragment */
950 (u64)pci_map_page(fifo->pdev, frag->page,
951 frag->page_offset, frag->size,
954 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
956 vxge_debug_tx(VXGE_TRACE,
957 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
958 dev->name, __func__, __LINE__, i,
959 (unsigned long long)dma_pointer);
961 txdl_priv->dma_buffers[j] = dma_pointer;
962 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
967 offload_type = vxge_offload_type(skb);
969 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
971 int mss = vxge_tcp_mss(skb);
973 vxge_debug_tx(VXGE_TRACE,
974 "%s: %s:%d mss = %d",
975 dev->name, __func__, __LINE__, mss);
976 vxge_hw_fifo_txdl_mss_set(dtr, mss);
978 vxge_assert(skb->len <=
979 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
985 if (skb->ip_summed == CHECKSUM_PARTIAL)
986 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
987 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
988 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
989 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
991 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
993 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
995 spin_unlock_irqrestore(&fifo->tx_lock, flags);
997 VXGE_COMPLETE_VPATH_TX(fifo);
998 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
999 dev->name, __func__, __LINE__);
1000 return NETDEV_TX_OK;
1003 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
1007 frag = &skb_shinfo(skb)->frags[0];
1009 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
1010 skb_headlen(skb), PCI_DMA_TODEVICE);
1012 for (; j < i; j++) {
1013 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
1014 frag->size, PCI_DMA_TODEVICE);
1018 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
1021 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1022 VXGE_COMPLETE_VPATH_TX(fifo);
1024 return NETDEV_TX_OK;
1030 * Function will be called by hw function to abort all outstanding receive
1034 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1036 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1037 struct vxge_rx_priv *rx_priv =
1038 vxge_hw_ring_rxd_private_get(dtrh);
1040 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1041 ring->ndev->name, __func__, __LINE__);
1042 if (state != VXGE_HW_RXD_STATE_POSTED)
1045 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1046 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1048 dev_kfree_skb(rx_priv->skb);
1050 vxge_debug_entryexit(VXGE_TRACE,
1051 "%s: %s:%d Exiting...",
1052 ring->ndev->name, __func__, __LINE__);
1058 * Function will be called to abort all outstanding tx descriptors
1061 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1063 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1065 int i = 0, j, frg_cnt;
1066 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1067 struct sk_buff *skb = txd_priv->skb;
1069 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1071 if (state != VXGE_HW_TXDL_STATE_POSTED)
1074 /* check skb validity */
1076 frg_cnt = skb_shinfo(skb)->nr_frags;
1077 frag = &skb_shinfo(skb)->frags[0];
1079 /* for unfragmented skb */
1080 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1081 skb_headlen(skb), PCI_DMA_TODEVICE);
1083 for (j = 0; j < frg_cnt; j++) {
1084 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1085 frag->size, PCI_DMA_TODEVICE);
1091 vxge_debug_entryexit(VXGE_TRACE,
1092 "%s:%d Exiting...", __func__, __LINE__);
1096 * vxge_set_multicast
1097 * @dev: pointer to the device structure
1099 * Entry point for multicast address enable/disable
1100 * This function is a driver entry point which gets called by the kernel
1101 * whenever multicast addresses must be enabled/disabled. This also gets
1102 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1103 * determine, if multicast address must be enabled or if promiscuous mode
1104 * is to be disabled etc.
1106 static void vxge_set_multicast(struct net_device *dev)
1108 struct dev_mc_list *mclist;
1109 struct vxgedev *vdev;
1110 int i, mcast_cnt = 0;
1111 struct __vxge_hw_device *hldev;
1112 enum vxge_hw_status status = VXGE_HW_OK;
1113 struct macInfo mac_info;
1115 struct vxge_mac_addrs *mac_entry;
1116 struct list_head *list_head;
1117 struct list_head *entry, *next;
1118 u8 *mac_address = NULL;
1120 vxge_debug_entryexit(VXGE_TRACE,
1121 "%s:%d", __func__, __LINE__);
1123 vdev = (struct vxgedev *)netdev_priv(dev);
1124 hldev = (struct __vxge_hw_device *)vdev->devh;
1126 if (unlikely(!is_vxge_card_up(vdev)))
1129 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1130 for (i = 0; i < vdev->no_of_vpath; i++) {
1131 vxge_assert(vdev->vpaths[i].is_open);
1132 status = vxge_hw_vpath_mcast_enable(
1133 vdev->vpaths[i].handle);
1134 vdev->all_multi_flg = 1;
1136 } else if ((dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1137 for (i = 0; i < vdev->no_of_vpath; i++) {
1138 vxge_assert(vdev->vpaths[i].is_open);
1139 status = vxge_hw_vpath_mcast_disable(
1140 vdev->vpaths[i].handle);
1141 vdev->all_multi_flg = 1;
1145 if (status != VXGE_HW_OK)
1146 vxge_debug_init(VXGE_ERR,
1147 "failed to %s multicast, status %d",
1148 dev->flags & IFF_ALLMULTI ?
1149 "enable" : "disable", status);
1151 if (!vdev->config.addr_learn_en) {
1152 if (dev->flags & IFF_PROMISC) {
1153 for (i = 0; i < vdev->no_of_vpath; i++) {
1154 vxge_assert(vdev->vpaths[i].is_open);
1155 status = vxge_hw_vpath_promisc_enable(
1156 vdev->vpaths[i].handle);
1159 for (i = 0; i < vdev->no_of_vpath; i++) {
1160 vxge_assert(vdev->vpaths[i].is_open);
1161 status = vxge_hw_vpath_promisc_disable(
1162 vdev->vpaths[i].handle);
1167 memset(&mac_info, 0, sizeof(struct macInfo));
1168 /* Update individual M_CAST address list */
1169 if ((!vdev->all_multi_flg) && dev->mc_count) {
1171 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1172 list_head = &vdev->vpaths[0].mac_addr_list;
1173 if ((dev->mc_count +
1174 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1175 vdev->vpaths[0].max_mac_addr_cnt)
1176 goto _set_all_mcast;
1178 /* Delete previous MC's */
1179 for (i = 0; i < mcast_cnt; i++) {
1180 if (!list_empty(list_head))
1181 mac_entry = (struct vxge_mac_addrs *)
1182 list_first_entry(list_head,
1183 struct vxge_mac_addrs,
1186 list_for_each_safe(entry, next, list_head) {
1188 mac_entry = (struct vxge_mac_addrs *) entry;
1189 /* Copy the mac address to delete */
1190 mac_address = (u8 *)&mac_entry->macaddr;
1191 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1193 /* Is this a multicast address */
1194 if (0x01 & mac_info.macaddr[0]) {
1195 for (vpath_idx = 0; vpath_idx <
1198 mac_info.vpath_no = vpath_idx;
1199 status = vxge_del_mac_addr(
1208 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
1209 i++, mclist = mclist->next) {
1211 memcpy(mac_info.macaddr, mclist->dmi_addr, ETH_ALEN);
1212 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1214 mac_info.vpath_no = vpath_idx;
1215 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1216 status = vxge_add_mac_addr(vdev, &mac_info);
1217 if (status != VXGE_HW_OK) {
1218 vxge_debug_init(VXGE_ERR,
1219 "%s:%d Setting individual"
1220 "multicast address failed",
1221 __func__, __LINE__);
1222 goto _set_all_mcast;
1229 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1230 /* Delete previous MC's */
1231 for (i = 0; i < mcast_cnt; i++) {
1233 list_for_each_safe(entry, next, list_head) {
1235 mac_entry = (struct vxge_mac_addrs *) entry;
1236 /* Copy the mac address to delete */
1237 mac_address = (u8 *)&mac_entry->macaddr;
1238 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1240 /* Is this a multicast address */
1241 if (0x01 & mac_info.macaddr[0])
1245 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1247 mac_info.vpath_no = vpath_idx;
1248 status = vxge_del_mac_addr(vdev, &mac_info);
1252 /* Enable all multicast */
1253 for (i = 0; i < vdev->no_of_vpath; i++) {
1254 vxge_assert(vdev->vpaths[i].is_open);
1255 status = vxge_hw_vpath_mcast_enable(
1256 vdev->vpaths[i].handle);
1257 if (status != VXGE_HW_OK) {
1258 vxge_debug_init(VXGE_ERR,
1259 "%s:%d Enabling all multicasts failed",
1260 __func__, __LINE__);
1262 vdev->all_multi_flg = 1;
1264 dev->flags |= IFF_ALLMULTI;
1267 vxge_debug_entryexit(VXGE_TRACE,
1268 "%s:%d Exiting...", __func__, __LINE__);
1273 * @dev: pointer to the device structure
1275 * Update entry "0" (default MAC addr)
1277 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1279 struct sockaddr *addr = p;
1280 struct vxgedev *vdev;
1281 struct __vxge_hw_device *hldev;
1282 enum vxge_hw_status status = VXGE_HW_OK;
1283 struct macInfo mac_info_new, mac_info_old;
1286 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1288 vdev = (struct vxgedev *)netdev_priv(dev);
1291 if (!is_valid_ether_addr(addr->sa_data))
1294 memset(&mac_info_new, 0, sizeof(struct macInfo));
1295 memset(&mac_info_old, 0, sizeof(struct macInfo));
1297 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1298 __func__, __LINE__);
1300 /* Get the old address */
1301 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1303 /* Copy the new address */
1304 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1306 /* First delete the old mac address from all the vpaths
1307 as we can't specify the index while adding new mac address */
1308 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1309 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1310 if (!vpath->is_open) {
1311 /* This can happen when this interface is added/removed
1312 to the bonding interface. Delete this station address
1313 from the linked list */
1314 vxge_mac_list_del(vpath, &mac_info_old);
1316 /* Add this new address to the linked list
1317 for later restoring */
1318 vxge_mac_list_add(vpath, &mac_info_new);
1322 /* Delete the station address */
1323 mac_info_old.vpath_no = vpath_idx;
1324 status = vxge_del_mac_addr(vdev, &mac_info_old);
1327 if (unlikely(!is_vxge_card_up(vdev))) {
1328 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1332 /* Set this mac address to all the vpaths */
1333 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1334 mac_info_new.vpath_no = vpath_idx;
1335 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1336 status = vxge_add_mac_addr(vdev, &mac_info_new);
1337 if (status != VXGE_HW_OK)
1341 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1347 * vxge_vpath_intr_enable
1348 * @vdev: pointer to vdev
1349 * @vp_id: vpath for which to enable the interrupts
1351 * Enables the interrupts for the vpath
1353 void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1355 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1356 int msix_id, alarm_msix_id;
1357 int tim_msix_id[4] = {[0 ...3] = 0};
1359 vxge_hw_vpath_intr_enable(vpath->handle);
1361 if (vdev->config.intr_type == INTA)
1362 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1364 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1366 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1368 tim_msix_id[0] = msix_id;
1369 tim_msix_id[1] = msix_id + 1;
1370 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1373 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1374 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1376 /* enable the alarm vector */
1377 vxge_hw_vpath_msix_unmask(vpath->handle, alarm_msix_id);
1382 * vxge_vpath_intr_disable
1383 * @vdev: pointer to vdev
1384 * @vp_id: vpath for which to disable the interrupts
1386 * Disables the interrupts for the vpath
1388 void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1390 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1393 vxge_hw_vpath_intr_disable(vpath->handle);
1395 if (vdev->config.intr_type == INTA)
1396 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1398 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1399 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1400 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1402 /* disable the alarm vector */
1403 msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1404 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1410 * @vdev: pointer to vdev
1411 * @vp_id: vpath to reset
1415 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1417 enum vxge_hw_status status = VXGE_HW_OK;
1420 /* check if device is down already */
1421 if (unlikely(!is_vxge_card_up(vdev)))
1424 /* is device reset already scheduled */
1425 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1428 if (vdev->vpaths[vp_id].handle) {
1429 if (vxge_hw_vpath_reset(vdev->vpaths[vp_id].handle)
1431 if (is_vxge_card_up(vdev) &&
1432 vxge_hw_vpath_recover_from_reset(
1433 vdev->vpaths[vp_id].handle)
1435 vxge_debug_init(VXGE_ERR,
1436 "vxge_hw_vpath_recover_from_reset"
1437 "failed for vpath:%d", vp_id);
1441 vxge_debug_init(VXGE_ERR,
1442 "vxge_hw_vpath_reset failed for"
1447 return VXGE_HW_FAIL;
1449 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1450 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1452 /* Enable all broadcast */
1453 vxge_hw_vpath_bcast_enable(vdev->vpaths[vp_id].handle);
1455 /* Enable the interrupts */
1456 vxge_vpath_intr_enable(vdev, vp_id);
1460 /* Enable the flow of traffic through the vpath */
1461 vxge_hw_vpath_enable(vdev->vpaths[vp_id].handle);
1464 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[vp_id].handle);
1465 vdev->vpaths[vp_id].ring.last_status = VXGE_HW_OK;
1467 /* Vpath reset done */
1468 clear_bit(vp_id, &vdev->vp_reset);
1470 /* Start the vpath queue */
1471 vxge_wake_tx_queue(&vdev->vpaths[vp_id].fifo, NULL);
1476 static int do_vxge_reset(struct vxgedev *vdev, int event)
1478 enum vxge_hw_status status;
1479 int ret = 0, vp_id, i;
1481 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1483 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1484 /* check if device is down already */
1485 if (unlikely(!is_vxge_card_up(vdev)))
1488 /* is reset already scheduled */
1489 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1493 if (event == VXGE_LL_FULL_RESET) {
1494 /* wait for all the vpath reset to complete */
1495 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1496 while (test_bit(vp_id, &vdev->vp_reset))
1500 /* if execution mode is set to debug, don't reset the adapter */
1501 if (unlikely(vdev->exec_mode)) {
1502 vxge_debug_init(VXGE_ERR,
1503 "%s: execution mode is debug, returning..",
1505 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1506 vxge_stop_all_tx_queue(vdev);
1511 if (event == VXGE_LL_FULL_RESET) {
1512 vxge_hw_device_intr_disable(vdev->devh);
1514 switch (vdev->cric_err_event) {
1515 case VXGE_HW_EVENT_UNKNOWN:
1516 vxge_stop_all_tx_queue(vdev);
1517 vxge_debug_init(VXGE_ERR,
1518 "fatal: %s: Disabling device due to"
1523 case VXGE_HW_EVENT_RESET_START:
1525 case VXGE_HW_EVENT_RESET_COMPLETE:
1526 case VXGE_HW_EVENT_LINK_DOWN:
1527 case VXGE_HW_EVENT_LINK_UP:
1528 case VXGE_HW_EVENT_ALARM_CLEARED:
1529 case VXGE_HW_EVENT_ECCERR:
1530 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1533 case VXGE_HW_EVENT_FIFO_ERR:
1534 case VXGE_HW_EVENT_VPATH_ERR:
1536 case VXGE_HW_EVENT_CRITICAL_ERR:
1537 vxge_stop_all_tx_queue(vdev);
1538 vxge_debug_init(VXGE_ERR,
1539 "fatal: %s: Disabling device due to"
1542 /* SOP or device reset required */
1543 /* This event is not currently used */
1546 case VXGE_HW_EVENT_SERR:
1547 vxge_stop_all_tx_queue(vdev);
1548 vxge_debug_init(VXGE_ERR,
1549 "fatal: %s: Disabling device due to"
1554 case VXGE_HW_EVENT_SRPCIM_SERR:
1555 case VXGE_HW_EVENT_MRPCIM_SERR:
1558 case VXGE_HW_EVENT_SLOT_FREEZE:
1559 vxge_stop_all_tx_queue(vdev);
1560 vxge_debug_init(VXGE_ERR,
1561 "fatal: %s: Disabling device due to"
1572 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1573 vxge_stop_all_tx_queue(vdev);
1575 if (event == VXGE_LL_FULL_RESET) {
1576 status = vxge_reset_all_vpaths(vdev);
1577 if (status != VXGE_HW_OK) {
1578 vxge_debug_init(VXGE_ERR,
1579 "fatal: %s: can not reset vpaths",
1586 if (event == VXGE_LL_COMPL_RESET) {
1587 for (i = 0; i < vdev->no_of_vpath; i++)
1588 if (vdev->vpaths[i].handle) {
1589 if (vxge_hw_vpath_recover_from_reset(
1590 vdev->vpaths[i].handle)
1592 vxge_debug_init(VXGE_ERR,
1593 "vxge_hw_vpath_recover_"
1594 "from_reset failed for vpath: "
1600 vxge_debug_init(VXGE_ERR,
1601 "vxge_hw_vpath_reset failed for "
1608 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1609 /* Reprogram the DA table with populated mac addresses */
1610 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1611 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1612 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1615 /* enable vpath interrupts */
1616 for (i = 0; i < vdev->no_of_vpath; i++)
1617 vxge_vpath_intr_enable(vdev, i);
1619 vxge_hw_device_intr_enable(vdev->devh);
1623 /* Indicate card up */
1624 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1626 /* Get the traffic to flow through the vpaths */
1627 for (i = 0; i < vdev->no_of_vpath; i++) {
1628 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1630 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1633 vxge_wake_all_tx_queue(vdev);
1637 vxge_debug_entryexit(VXGE_TRACE,
1638 "%s:%d Exiting...", __func__, __LINE__);
1640 /* Indicate reset done */
1641 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1642 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1648 * @vdev: pointer to ll device
1650 * driver may reset the chip on events of serr, eccerr, etc
1652 int vxge_reset(struct vxgedev *vdev)
1654 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1659 * vxge_poll - Receive handler when Receive Polling is used.
1660 * @dev: pointer to the device structure.
1661 * @budget: Number of packets budgeted to be processed in this iteration.
1663 * This function comes into picture only if Receive side is being handled
1664 * through polling (called NAPI in linux). It mostly does what the normal
1665 * Rx interrupt handler does in terms of descriptor and packet processing
1666 * but not in an interrupt context. Also it will process a specified number
1667 * of packets at most in one iteration. This value is passed down by the
1668 * kernel as the function argument 'budget'.
1670 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1672 struct vxge_ring *ring =
1673 container_of(napi, struct vxge_ring, napi);
1674 int budget_org = budget;
1675 ring->budget = budget;
1677 vxge_hw_vpath_poll_rx(ring->handle);
1679 if (ring->pkts_processed < budget_org) {
1680 napi_complete(napi);
1681 /* Re enable the Rx interrupts for the vpath */
1682 vxge_hw_channel_msix_unmask(
1683 (struct __vxge_hw_channel *)ring->handle,
1684 ring->rx_vector_no);
1687 return ring->pkts_processed;
1690 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1692 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1693 int pkts_processed = 0;
1695 int budget_org = budget;
1696 struct vxge_ring *ring;
1698 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1699 pci_get_drvdata(vdev->pdev);
1701 for (i = 0; i < vdev->no_of_vpath; i++) {
1702 ring = &vdev->vpaths[i].ring;
1703 ring->budget = budget;
1704 vxge_hw_vpath_poll_rx(ring->handle);
1705 pkts_processed += ring->pkts_processed;
1706 budget -= ring->pkts_processed;
1711 VXGE_COMPLETE_ALL_TX(vdev);
1713 if (pkts_processed < budget_org) {
1714 napi_complete(napi);
1715 /* Re enable the Rx interrupts for the ring */
1716 vxge_hw_device_unmask_all(hldev);
1717 vxge_hw_device_flush_io(hldev);
1720 return pkts_processed;
1723 #ifdef CONFIG_NET_POLL_CONTROLLER
1725 * vxge_netpoll - netpoll event handler entry point
1726 * @dev : pointer to the device structure.
1728 * This function will be called by upper layer to check for events on the
1729 * interface in situations where interrupts are disabled. It is used for
1730 * specific in-kernel networking tasks, such as remote consoles and kernel
1731 * debugging over the network (example netdump in RedHat).
1733 static void vxge_netpoll(struct net_device *dev)
1735 struct __vxge_hw_device *hldev;
1736 struct vxgedev *vdev;
1738 vdev = (struct vxgedev *)netdev_priv(dev);
1739 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1741 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1743 if (pci_channel_offline(vdev->pdev))
1746 disable_irq(dev->irq);
1747 vxge_hw_device_clear_tx_rx(hldev);
1749 vxge_hw_device_clear_tx_rx(hldev);
1750 VXGE_COMPLETE_ALL_RX(vdev);
1751 VXGE_COMPLETE_ALL_TX(vdev);
1753 enable_irq(dev->irq);
1755 vxge_debug_entryexit(VXGE_TRACE,
1756 "%s:%d Exiting...", __func__, __LINE__);
1761 /* RTH configuration */
1762 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1764 enum vxge_hw_status status = VXGE_HW_OK;
1765 struct vxge_hw_rth_hash_types hash_types;
1766 u8 itable[256] = {0}; /* indirection table */
1767 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1772 * - itable with bucket numbers
1773 * - mtable with bucket-to-vpath mapping
1775 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1776 itable[index] = index;
1777 mtable[index] = index % vdev->no_of_vpath;
1780 /* Fill RTH hash types */
1781 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1782 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1783 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1784 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1785 hash_types.hash_type_tcpipv6ex_en =
1786 vdev->config.rth_hash_type_tcpipv6ex;
1787 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1789 /* set indirection table, bucket-to-vpath mapping */
1790 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1793 vdev->config.rth_bkt_sz);
1794 if (status != VXGE_HW_OK) {
1795 vxge_debug_init(VXGE_ERR,
1796 "RTH indirection table configuration failed "
1797 "for vpath:%d", vdev->vpaths[0].device_id);
1802 * Because the itable_set() method uses the active_table field
1803 * for the target virtual path the RTH config should be updated
1804 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1805 * when steering frames.
1807 for (index = 0; index < vdev->no_of_vpath; index++) {
1808 status = vxge_hw_vpath_rts_rth_set(
1809 vdev->vpaths[index].handle,
1810 vdev->config.rth_algorithm,
1812 vdev->config.rth_bkt_sz);
1814 if (status != VXGE_HW_OK) {
1815 vxge_debug_init(VXGE_ERR,
1816 "RTH configuration failed for vpath:%d",
1817 vdev->vpaths[index].device_id);
1825 int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1827 struct vxge_mac_addrs *new_mac_entry;
1828 u8 *mac_address = NULL;
1830 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1833 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1834 if (!new_mac_entry) {
1835 vxge_debug_mem(VXGE_ERR,
1836 "%s: memory allocation failed",
1841 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1843 /* Copy the new mac address to the list */
1844 mac_address = (u8 *)&new_mac_entry->macaddr;
1845 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1847 new_mac_entry->state = mac->state;
1848 vpath->mac_addr_cnt++;
1850 /* Is this a multicast address */
1851 if (0x01 & mac->macaddr[0])
1852 vpath->mcast_addr_cnt++;
1857 /* Add a mac address to DA table */
1858 enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1860 enum vxge_hw_status status = VXGE_HW_OK;
1861 struct vxge_vpath *vpath;
1862 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1864 if (0x01 & mac->macaddr[0]) /* multicast address */
1865 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1867 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1869 vpath = &vdev->vpaths[mac->vpath_no];
1870 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1871 mac->macmask, duplicate_mode);
1872 if (status != VXGE_HW_OK) {
1873 vxge_debug_init(VXGE_ERR,
1874 "DA config add entry failed for vpath:%d",
1877 if (FALSE == vxge_mac_list_add(vpath, mac))
1883 int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1885 struct list_head *entry, *next;
1887 u8 *mac_address = (u8 *) (&del_mac);
1889 /* Copy the mac address to delete from the list */
1890 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1892 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1893 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1895 kfree((struct vxge_mac_addrs *)entry);
1896 vpath->mac_addr_cnt--;
1898 /* Is this a multicast address */
1899 if (0x01 & mac->macaddr[0])
1900 vpath->mcast_addr_cnt--;
1907 /* delete a mac address from DA table */
1908 enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1910 enum vxge_hw_status status = VXGE_HW_OK;
1911 struct vxge_vpath *vpath;
1913 vpath = &vdev->vpaths[mac->vpath_no];
1914 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1916 if (status != VXGE_HW_OK) {
1917 vxge_debug_init(VXGE_ERR,
1918 "DA config delete entry failed for vpath:%d",
1921 vxge_mac_list_del(vpath, mac);
1925 /* list all mac addresses from DA table */
1927 static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1928 struct macInfo *mac)
1930 enum vxge_hw_status status = VXGE_HW_OK;
1931 unsigned char macmask[ETH_ALEN];
1932 unsigned char macaddr[ETH_ALEN];
1934 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1936 if (status != VXGE_HW_OK) {
1937 vxge_debug_init(VXGE_ERR,
1938 "DA config list entry failed for vpath:%d",
1943 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1945 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1947 if (status != VXGE_HW_OK)
1954 /* Store all vlan ids from the list to the vid table */
1955 enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1957 enum vxge_hw_status status = VXGE_HW_OK;
1958 struct vxgedev *vdev = vpath->vdev;
1961 if (vdev->vlgrp && vpath->is_open) {
1963 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1964 if (!vlan_group_get_device(vdev->vlgrp, vid))
1966 /* Add these vlan to the vid table */
1967 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1974 /* Store all mac addresses from the list to the DA table */
1975 enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1977 enum vxge_hw_status status = VXGE_HW_OK;
1978 struct macInfo mac_info;
1979 u8 *mac_address = NULL;
1980 struct list_head *entry, *next;
1982 memset(&mac_info, 0, sizeof(struct macInfo));
1984 if (vpath->is_open) {
1986 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1989 ((struct vxge_mac_addrs *)entry)->macaddr;
1990 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1991 ((struct vxge_mac_addrs *)entry)->state =
1992 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1993 /* does this mac address already exist in da table? */
1994 status = vxge_search_mac_addr_in_da_table(vpath,
1996 if (status != VXGE_HW_OK) {
1997 /* Add this mac address to the DA table */
1998 status = vxge_hw_vpath_mac_addr_add(
1999 vpath->handle, mac_info.macaddr,
2001 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
2002 if (status != VXGE_HW_OK) {
2003 vxge_debug_init(VXGE_ERR,
2004 "DA add entry failed for vpath:%d",
2006 ((struct vxge_mac_addrs *)entry)->state
2007 = VXGE_LL_MAC_ADDR_IN_LIST;
2017 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
2020 enum vxge_hw_status status = VXGE_HW_OK;
2022 for (i = 0; i < vdev->no_of_vpath; i++)
2023 if (vdev->vpaths[i].handle) {
2024 if (vxge_hw_vpath_reset(vdev->vpaths[i].handle)
2026 if (is_vxge_card_up(vdev) &&
2027 vxge_hw_vpath_recover_from_reset(
2028 vdev->vpaths[i].handle)
2030 vxge_debug_init(VXGE_ERR,
2031 "vxge_hw_vpath_recover_"
2032 "from_reset failed for vpath: "
2037 vxge_debug_init(VXGE_ERR,
2038 "vxge_hw_vpath_reset failed for "
2047 void vxge_close_vpaths(struct vxgedev *vdev, int index)
2050 for (i = index; i < vdev->no_of_vpath; i++) {
2051 if (vdev->vpaths[i].handle && vdev->vpaths[i].is_open) {
2052 vxge_hw_vpath_close(vdev->vpaths[i].handle);
2053 vdev->stats.vpaths_open--;
2055 vdev->vpaths[i].is_open = 0;
2056 vdev->vpaths[i].handle = NULL;
2061 int vxge_open_vpaths(struct vxgedev *vdev)
2063 enum vxge_hw_status status;
2066 struct vxge_hw_vpath_attr attr;
2068 for (i = 0; i < vdev->no_of_vpath; i++) {
2069 vxge_assert(vdev->vpaths[i].is_configured);
2070 attr.vp_id = vdev->vpaths[i].device_id;
2071 attr.fifo_attr.callback = vxge_xmit_compl;
2072 attr.fifo_attr.txdl_term = vxge_tx_term;
2073 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2074 attr.fifo_attr.userdata = (void *)&vdev->vpaths[i].fifo;
2076 attr.ring_attr.callback = vxge_rx_1b_compl;
2077 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2078 attr.ring_attr.rxd_term = vxge_rx_term;
2079 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2080 attr.ring_attr.userdata = (void *)&vdev->vpaths[i].ring;
2082 vdev->vpaths[i].ring.ndev = vdev->ndev;
2083 vdev->vpaths[i].ring.pdev = vdev->pdev;
2084 status = vxge_hw_vpath_open(vdev->devh, &attr,
2085 &(vdev->vpaths[i].handle));
2086 if (status == VXGE_HW_OK) {
2087 vdev->vpaths[i].fifo.handle =
2088 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2089 vdev->vpaths[i].ring.handle =
2090 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2091 vdev->vpaths[i].fifo.tx_steering_type =
2092 vdev->config.tx_steering_type;
2093 vdev->vpaths[i].fifo.ndev = vdev->ndev;
2094 vdev->vpaths[i].fifo.pdev = vdev->pdev;
2095 vdev->vpaths[i].fifo.indicate_max_pkts =
2096 vdev->config.fifo_indicate_max_pkts;
2097 vdev->vpaths[i].ring.rx_vector_no = 0;
2098 vdev->vpaths[i].ring.rx_csum = vdev->rx_csum;
2099 vdev->vpaths[i].is_open = 1;
2100 vdev->vp_handles[i] = vdev->vpaths[i].handle;
2101 vdev->vpaths[i].ring.gro_enable =
2102 vdev->config.gro_enable;
2103 vdev->vpaths[i].ring.vlan_tag_strip =
2104 vdev->vlan_tag_strip;
2105 vdev->stats.vpaths_open++;
2107 vdev->stats.vpath_open_fail++;
2108 vxge_debug_init(VXGE_ERR,
2109 "%s: vpath: %d failed to open "
2111 vdev->ndev->name, vdev->vpaths[i].device_id,
2113 vxge_close_vpaths(vdev, 0);
2118 ((struct __vxge_hw_vpath_handle *)vdev->vpaths[i].handle)->
2120 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2127 * @irq: the irq of the device.
2128 * @dev_id: a void pointer to the hldev structure of the Titan device
2129 * @ptregs: pointer to the registers pushed on the stack.
2131 * This function is the ISR handler of the device when napi is enabled. It
2132 * identifies the reason for the interrupt and calls the relevant service
2135 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2137 struct net_device *dev;
2138 struct __vxge_hw_device *hldev;
2140 enum vxge_hw_status status;
2141 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
2143 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2146 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
2148 if (pci_channel_offline(vdev->pdev))
2151 if (unlikely(!is_vxge_card_up(vdev)))
2154 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2156 if (status == VXGE_HW_OK) {
2157 vxge_hw_device_mask_all(hldev);
2160 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2161 vdev->vpaths_deployed >>
2162 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2164 vxge_hw_device_clear_tx_rx(hldev);
2165 napi_schedule(&vdev->napi);
2166 vxge_debug_intr(VXGE_TRACE,
2167 "%s:%d Exiting...", __func__, __LINE__);
2170 vxge_hw_device_unmask_all(hldev);
2171 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2172 (status == VXGE_HW_ERR_CRITICAL) ||
2173 (status == VXGE_HW_ERR_FIFO))) {
2174 vxge_hw_device_mask_all(hldev);
2175 vxge_hw_device_flush_io(hldev);
2177 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2180 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2184 #ifdef CONFIG_PCI_MSI
2187 vxge_tx_msix_handle(int irq, void *dev_id)
2189 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2191 VXGE_COMPLETE_VPATH_TX(fifo);
2197 vxge_rx_msix_napi_handle(int irq, void *dev_id)
2199 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2201 /* MSIX_IDX for Rx is 1 */
2202 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2203 ring->rx_vector_no);
2205 napi_schedule(&ring->napi);
2210 vxge_alarm_msix_handle(int irq, void *dev_id)
2213 enum vxge_hw_status status;
2214 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2215 struct vxgedev *vdev = vpath->vdev;
2217 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2219 for (i = 0; i < vdev->no_of_vpath; i++) {
2220 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle,
2223 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2225 if (status == VXGE_HW_OK) {
2227 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2231 vxge_debug_intr(VXGE_ERR,
2232 "%s: vxge_hw_vpath_alarm_process failed %x ",
2233 VXGE_DRIVER_NAME, status);
2238 static int vxge_alloc_msix(struct vxgedev *vdev)
2242 int alarm_msix_id = 0, msix_intr_vect = 0;
2245 /* Tx/Rx MSIX Vectors count */
2246 vdev->intr_cnt = vdev->no_of_vpath * 2;
2248 /* Alarm MSIX Vectors count */
2251 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2252 vdev->entries = kzalloc(intr_cnt * sizeof(struct msix_entry),
2254 if (!vdev->entries) {
2255 vxge_debug_init(VXGE_ERR,
2256 "%s: memory allocation failed",
2261 vdev->vxge_entries = kzalloc(intr_cnt * sizeof(struct vxge_msix_entry),
2263 if (!vdev->vxge_entries) {
2264 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2266 kfree(vdev->entries);
2270 /* Last vector in the list is used for alarm */
2271 alarm_msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2272 for (i = 0, j = 0; i < vdev->max_vpath_supported; i++) {
2274 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2276 /* Initialize the fifo vector */
2277 vdev->entries[j].entry = msix_intr_vect;
2278 vdev->vxge_entries[j].entry = msix_intr_vect;
2279 vdev->vxge_entries[j].in_use = 0;
2282 /* Initialize the ring vector */
2283 vdev->entries[j].entry = msix_intr_vect + 1;
2284 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2285 vdev->vxge_entries[j].in_use = 0;
2289 /* Initialize the alarm vector */
2290 vdev->entries[j].entry = alarm_msix_id;
2291 vdev->vxge_entries[j].entry = alarm_msix_id;
2292 vdev->vxge_entries[j].in_use = 0;
2294 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2295 /* if driver request exceeeds available irq's, request with a small
2299 vxge_debug_init(VXGE_ERR,
2300 "%s: MSI-X enable failed for %d vectors, available: %d",
2301 VXGE_DRIVER_NAME, intr_cnt, ret);
2302 vdev->max_vpath_supported = vdev->no_of_vpath;
2303 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2305 /* Reset the alarm vector setting */
2306 vdev->entries[j].entry = 0;
2307 vdev->vxge_entries[j].entry = 0;
2309 /* Initialize the alarm vector with new setting */
2310 vdev->entries[intr_cnt - 1].entry = alarm_msix_id;
2311 vdev->vxge_entries[intr_cnt - 1].entry = alarm_msix_id;
2312 vdev->vxge_entries[intr_cnt - 1].in_use = 0;
2314 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2316 vxge_debug_init(VXGE_ERR,
2317 "%s: MSI-X enabled for %d vectors",
2318 VXGE_DRIVER_NAME, intr_cnt);
2322 vxge_debug_init(VXGE_ERR,
2323 "%s: MSI-X enable failed for %d vectors, ret: %d",
2324 VXGE_DRIVER_NAME, intr_cnt, ret);
2325 kfree(vdev->entries);
2326 kfree(vdev->vxge_entries);
2327 vdev->entries = NULL;
2328 vdev->vxge_entries = NULL;
2334 static int vxge_enable_msix(struct vxgedev *vdev)
2338 enum vxge_hw_status status;
2339 /* 0 - Tx, 1 - Rx */
2341 int alarm_msix_id = 0, msix_intr_vect = 0;;
2344 /* allocate msix vectors */
2345 ret = vxge_alloc_msix(vdev);
2347 /* Last vector in the list is used for alarm */
2349 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2350 for (i = 0; i < vdev->no_of_vpath; i++) {
2352 /* If fifo or ring are not enabled
2353 the MSIX vector for that should be set to 0
2354 Hence initializeing this array to all 0s.
2356 memset(tim_msix_id, 0, sizeof(tim_msix_id));
2357 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2358 tim_msix_id[0] = msix_intr_vect;
2360 tim_msix_id[1] = msix_intr_vect + 1;
2361 vdev->vpaths[i].ring.rx_vector_no = tim_msix_id[1];
2363 status = vxge_hw_vpath_msix_set(
2364 vdev->vpaths[i].handle,
2365 tim_msix_id, alarm_msix_id);
2366 if (status != VXGE_HW_OK) {
2367 vxge_debug_init(VXGE_ERR,
2368 "vxge_hw_vpath_msix_set "
2369 "failed with status : %x", status);
2370 kfree(vdev->entries);
2371 kfree(vdev->vxge_entries);
2372 pci_disable_msix(vdev->pdev);
2381 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2385 for (intr_cnt = 0; intr_cnt < (vdev->max_vpath_supported * 2 + 1);
2387 if (vdev->vxge_entries[intr_cnt].in_use) {
2388 synchronize_irq(vdev->entries[intr_cnt].vector);
2389 free_irq(vdev->entries[intr_cnt].vector,
2390 vdev->vxge_entries[intr_cnt].arg);
2391 vdev->vxge_entries[intr_cnt].in_use = 0;
2395 kfree(vdev->entries);
2396 kfree(vdev->vxge_entries);
2397 vdev->entries = NULL;
2398 vdev->vxge_entries = NULL;
2400 if (vdev->config.intr_type == MSI_X)
2401 pci_disable_msix(vdev->pdev);
2405 static void vxge_rem_isr(struct vxgedev *vdev)
2407 struct __vxge_hw_device *hldev;
2408 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2410 #ifdef CONFIG_PCI_MSI
2411 if (vdev->config.intr_type == MSI_X) {
2412 vxge_rem_msix_isr(vdev);
2415 if (vdev->config.intr_type == INTA) {
2416 synchronize_irq(vdev->pdev->irq);
2417 free_irq(vdev->pdev->irq, vdev);
2421 static int vxge_add_isr(struct vxgedev *vdev)
2424 #ifdef CONFIG_PCI_MSI
2425 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2426 u64 function_mode = vdev->config.device_hw_info.function_mode;
2427 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2429 if (vdev->config.intr_type == MSI_X)
2430 ret = vxge_enable_msix(vdev);
2433 vxge_debug_init(VXGE_ERR,
2434 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2435 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2436 test_and_set_bit(__VXGE_STATE_CARD_UP,
2437 &driver_config->inta_dev_open))
2438 return VXGE_HW_FAIL;
2440 vxge_debug_init(VXGE_ERR,
2441 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2442 vdev->config.intr_type = INTA;
2443 vxge_hw_device_set_intr_type(vdev->devh,
2444 VXGE_HW_INTR_MODE_IRQLINE);
2445 vxge_close_vpaths(vdev, 1);
2446 vdev->no_of_vpath = 1;
2447 vdev->stats.vpaths_open = 1;
2451 if (vdev->config.intr_type == MSI_X) {
2453 intr_idx < (vdev->no_of_vpath *
2454 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2456 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2461 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2462 "%s:vxge fn: %d vpath: %d Tx MSI-X: %d",
2463 vdev->ndev->name, pci_fun, vp_idx,
2464 vdev->entries[intr_cnt].entry);
2466 vdev->entries[intr_cnt].vector,
2467 vxge_tx_msix_handle, 0,
2468 vdev->desc[intr_cnt],
2469 &vdev->vpaths[vp_idx].fifo);
2470 vdev->vxge_entries[intr_cnt].arg =
2471 &vdev->vpaths[vp_idx].fifo;
2475 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2476 "%s:vxge fn: %d vpath: %d Rx MSI-X: %d",
2477 vdev->ndev->name, pci_fun, vp_idx,
2478 vdev->entries[intr_cnt].entry);
2480 vdev->entries[intr_cnt].vector,
2481 vxge_rx_msix_napi_handle,
2483 vdev->desc[intr_cnt],
2484 &vdev->vpaths[vp_idx].ring);
2485 vdev->vxge_entries[intr_cnt].arg =
2486 &vdev->vpaths[vp_idx].ring;
2492 vxge_debug_init(VXGE_ERR,
2493 "%s: MSIX - %d Registration failed",
2494 vdev->ndev->name, intr_cnt);
2495 vxge_rem_msix_isr(vdev);
2496 if ((function_mode ==
2497 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2498 test_and_set_bit(__VXGE_STATE_CARD_UP,
2499 &driver_config->inta_dev_open))
2500 return VXGE_HW_FAIL;
2502 vxge_hw_device_set_intr_type(
2504 VXGE_HW_INTR_MODE_IRQLINE);
2505 vdev->config.intr_type = INTA;
2506 vxge_debug_init(VXGE_ERR,
2507 "%s: Defaulting to INTA"
2508 , vdev->ndev->name);
2509 vxge_close_vpaths(vdev, 1);
2510 vdev->no_of_vpath = 1;
2511 vdev->stats.vpaths_open = 1;
2517 /* We requested for this msix interrupt */
2518 vdev->vxge_entries[intr_cnt].in_use = 1;
2519 vxge_hw_vpath_msix_unmask(
2520 vdev->vpaths[vp_idx].handle,
2525 /* Point to next vpath handler */
2526 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0)
2527 && (vp_idx < (vdev->no_of_vpath - 1)))
2531 intr_cnt = vdev->max_vpath_supported * 2;
2532 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2533 "%s:vxge Alarm fn: %d MSI-X: %d",
2534 vdev->ndev->name, pci_fun,
2535 vdev->entries[intr_cnt].entry);
2536 /* For Alarm interrupts */
2537 ret = request_irq(vdev->entries[intr_cnt].vector,
2538 vxge_alarm_msix_handle, 0,
2539 vdev->desc[intr_cnt],
2540 &vdev->vpaths[vp_idx]);
2542 vxge_debug_init(VXGE_ERR,
2543 "%s: MSIX - %d Registration failed",
2544 vdev->ndev->name, intr_cnt);
2545 vxge_rem_msix_isr(vdev);
2546 if ((function_mode ==
2547 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2548 test_and_set_bit(__VXGE_STATE_CARD_UP,
2549 &driver_config->inta_dev_open))
2550 return VXGE_HW_FAIL;
2552 vxge_hw_device_set_intr_type(vdev->devh,
2553 VXGE_HW_INTR_MODE_IRQLINE);
2554 vdev->config.intr_type = INTA;
2555 vxge_debug_init(VXGE_ERR,
2556 "%s: Defaulting to INTA",
2558 vxge_close_vpaths(vdev, 1);
2559 vdev->no_of_vpath = 1;
2560 vdev->stats.vpaths_open = 1;
2565 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2567 vdev->vxge_entries[intr_cnt].in_use = 1;
2568 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[vp_idx];
2572 snprintf(vdev->desc[0], VXGE_INTR_STRLEN, "%s:vxge", vdev->ndev->name);
2574 if (vdev->config.intr_type == INTA) {
2575 ret = request_irq((int) vdev->pdev->irq,
2577 IRQF_SHARED, vdev->desc[0], vdev);
2579 vxge_debug_init(VXGE_ERR,
2580 "%s %s-%d: ISR registration failed",
2581 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2584 vxge_debug_init(VXGE_TRACE,
2585 "new %s-%d line allocated",
2586 "IRQ", vdev->pdev->irq);
2592 static void vxge_poll_vp_reset(unsigned long data)
2594 struct vxgedev *vdev = (struct vxgedev *)data;
2597 for (i = 0; i < vdev->no_of_vpath; i++) {
2598 if (test_bit(i, &vdev->vp_reset)) {
2599 vxge_reset_vpath(vdev, i);
2603 if (j && (vdev->config.intr_type != MSI_X)) {
2604 vxge_hw_device_unmask_all(vdev->devh);
2605 vxge_hw_device_flush_io(vdev->devh);
2608 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2611 static void vxge_poll_vp_lockup(unsigned long data)
2613 struct vxgedev *vdev = (struct vxgedev *)data;
2615 struct vxge_ring *ring;
2616 enum vxge_hw_status status = VXGE_HW_OK;
2618 for (i = 0; i < vdev->no_of_vpath; i++) {
2619 ring = &vdev->vpaths[i].ring;
2620 /* Did this vpath received any packets */
2621 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2622 status = vxge_hw_vpath_check_leak(ring->handle);
2624 /* Did it received any packets last time */
2625 if ((VXGE_HW_FAIL == status) &&
2626 (VXGE_HW_FAIL == ring->last_status)) {
2628 /* schedule vpath reset */
2629 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2631 /* disable interrupts for this vpath */
2632 vxge_vpath_intr_disable(vdev, i);
2634 /* stop the queue for this vpath */
2635 vxge_stop_tx_queue(&vdev->vpaths[i].
2641 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2642 ring->last_status = status;
2645 /* Check every 1 milli second */
2646 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2651 * @dev: pointer to the device structure.
2653 * This function is the open entry point of the driver. It mainly calls a
2654 * function to allocate Rx buffers and inserts them into the buffer
2655 * descriptors and then enables the Rx part of the NIC.
2656 * Return value: '0' on success and an appropriate (-)ve integer as
2657 * defined in errno.h file on failure.
2660 vxge_open(struct net_device *dev)
2662 enum vxge_hw_status status;
2663 struct vxgedev *vdev;
2664 struct __vxge_hw_device *hldev;
2667 u64 val64, function_mode;
2668 vxge_debug_entryexit(VXGE_TRACE,
2669 "%s: %s:%d", dev->name, __func__, __LINE__);
2671 vdev = (struct vxgedev *)netdev_priv(dev);
2672 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2673 function_mode = vdev->config.device_hw_info.function_mode;
2675 /* make sure you have link off by default every time Nic is
2677 netif_carrier_off(dev);
2679 /* Check for another device already opn with INTA */
2680 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2681 test_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open)) {
2687 status = vxge_open_vpaths(vdev);
2688 if (status != VXGE_HW_OK) {
2689 vxge_debug_init(VXGE_ERR,
2690 "%s: fatal: Vpath open failed", vdev->ndev->name);
2695 vdev->mtu = dev->mtu;
2697 status = vxge_add_isr(vdev);
2698 if (status != VXGE_HW_OK) {
2699 vxge_debug_init(VXGE_ERR,
2700 "%s: fatal: ISR add failed", dev->name);
2706 if (vdev->config.intr_type != MSI_X) {
2707 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2708 vdev->config.napi_weight);
2709 napi_enable(&vdev->napi);
2710 for (i = 0; i < vdev->no_of_vpath; i++)
2711 vdev->vpaths[i].ring.napi_p = &vdev->napi;
2713 for (i = 0; i < vdev->no_of_vpath; i++) {
2714 netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
2715 vxge_poll_msix, vdev->config.napi_weight);
2716 napi_enable(&vdev->vpaths[i].ring.napi);
2717 vdev->vpaths[i].ring.napi_p =
2718 &vdev->vpaths[i].ring.napi;
2723 if (vdev->config.rth_steering) {
2724 status = vxge_rth_configure(vdev);
2725 if (status != VXGE_HW_OK) {
2726 vxge_debug_init(VXGE_ERR,
2727 "%s: fatal: RTH configuration failed",
2734 for (i = 0; i < vdev->no_of_vpath; i++) {
2735 /* set initial mtu before enabling the device */
2736 status = vxge_hw_vpath_mtu_set(vdev->vpaths[i].handle,
2738 if (status != VXGE_HW_OK) {
2739 vxge_debug_init(VXGE_ERR,
2740 "%s: fatal: can not set new MTU", dev->name);
2746 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2747 vxge_debug_init(vdev->level_trace,
2748 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2749 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2751 /* Reprogram the DA table with populated mac addresses */
2752 for (i = 0; i < vdev->no_of_vpath; i++) {
2753 vxge_restore_vpath_mac_addr(&vdev->vpaths[i]);
2754 vxge_restore_vpath_vid_table(&vdev->vpaths[i]);
2757 /* Enable vpath to sniff all unicast/multicast traffic that not
2758 * addressed to them. We allow promiscous mode for PF only
2762 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2763 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2765 vxge_hw_mgmt_reg_write(vdev->devh,
2766 vxge_hw_mgmt_reg_type_mrpcim,
2768 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2769 rxmac_authorize_all_addr),
2772 vxge_hw_mgmt_reg_write(vdev->devh,
2773 vxge_hw_mgmt_reg_type_mrpcim,
2775 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2776 rxmac_authorize_all_vid),
2779 vxge_set_multicast(dev);
2781 /* Enabling Bcast and mcast for all vpath */
2782 for (i = 0; i < vdev->no_of_vpath; i++) {
2783 status = vxge_hw_vpath_bcast_enable(vdev->vpaths[i].handle);
2784 if (status != VXGE_HW_OK)
2785 vxge_debug_init(VXGE_ERR,
2786 "%s : Can not enable bcast for vpath "
2787 "id %d", dev->name, i);
2788 if (vdev->config.addr_learn_en) {
2790 vxge_hw_vpath_mcast_enable(vdev->vpaths[i].handle);
2791 if (status != VXGE_HW_OK)
2792 vxge_debug_init(VXGE_ERR,
2793 "%s : Can not enable mcast for vpath "
2794 "id %d", dev->name, i);
2798 vxge_hw_device_setpause_data(vdev->devh, 0,
2799 vdev->config.tx_pause_enable,
2800 vdev->config.rx_pause_enable);
2802 if (vdev->vp_reset_timer.function == NULL)
2803 vxge_os_timer(vdev->vp_reset_timer,
2804 vxge_poll_vp_reset, vdev, (HZ/2));
2806 if (vdev->vp_lockup_timer.function == NULL)
2807 vxge_os_timer(vdev->vp_lockup_timer,
2808 vxge_poll_vp_lockup, vdev, (HZ/2));
2810 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2814 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2815 netif_carrier_on(vdev->ndev);
2816 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
2817 vdev->stats.link_up++;
2820 vxge_hw_device_intr_enable(vdev->devh);
2824 for (i = 0; i < vdev->no_of_vpath; i++) {
2825 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
2827 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
2830 vxge_start_all_tx_queue(vdev);
2837 if (vdev->config.intr_type != MSI_X)
2838 napi_disable(&vdev->napi);
2840 for (i = 0; i < vdev->no_of_vpath; i++)
2841 napi_disable(&vdev->vpaths[i].ring.napi);
2845 vxge_close_vpaths(vdev, 0);
2847 vxge_debug_entryexit(VXGE_TRACE,
2848 "%s: %s:%d Exiting...",
2849 dev->name, __func__, __LINE__);
2853 /* Loop throught the mac address list and delete all the entries */
2854 void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2857 struct list_head *entry, *next;
2858 if (list_empty(&vpath->mac_addr_list))
2861 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2863 kfree((struct vxge_mac_addrs *)entry);
2867 static void vxge_napi_del_all(struct vxgedev *vdev)
2870 if (vdev->config.intr_type != MSI_X)
2871 netif_napi_del(&vdev->napi);
2873 for (i = 0; i < vdev->no_of_vpath; i++)
2874 netif_napi_del(&vdev->vpaths[i].ring.napi);
2879 int do_vxge_close(struct net_device *dev, int do_io)
2881 enum vxge_hw_status status;
2882 struct vxgedev *vdev;
2883 struct __vxge_hw_device *hldev;
2885 u64 val64, vpath_vector;
2886 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2887 dev->name, __func__, __LINE__);
2889 vdev = (struct vxgedev *)netdev_priv(dev);
2890 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2892 if (unlikely(!is_vxge_card_up(vdev)))
2895 /* If vxge_handle_crit_err task is executing,
2896 * wait till it completes. */
2897 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2900 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2902 /* Put the vpath back in normal mode */
2903 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2904 status = vxge_hw_mgmt_reg_read(vdev->devh,
2905 vxge_hw_mgmt_reg_type_mrpcim,
2908 struct vxge_hw_mrpcim_reg,
2909 rts_mgr_cbasin_cfg),
2912 if (status == VXGE_HW_OK) {
2913 val64 &= ~vpath_vector;
2914 status = vxge_hw_mgmt_reg_write(vdev->devh,
2915 vxge_hw_mgmt_reg_type_mrpcim,
2918 struct vxge_hw_mrpcim_reg,
2919 rts_mgr_cbasin_cfg),
2923 /* Remove the function 0 from promiscous mode */
2924 vxge_hw_mgmt_reg_write(vdev->devh,
2925 vxge_hw_mgmt_reg_type_mrpcim,
2927 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2928 rxmac_authorize_all_addr),
2931 vxge_hw_mgmt_reg_write(vdev->devh,
2932 vxge_hw_mgmt_reg_type_mrpcim,
2934 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2935 rxmac_authorize_all_vid),
2940 del_timer_sync(&vdev->vp_lockup_timer);
2942 del_timer_sync(&vdev->vp_reset_timer);
2945 if (vdev->config.intr_type != MSI_X)
2946 napi_disable(&vdev->napi);
2948 for (i = 0; i < vdev->no_of_vpath; i++)
2949 napi_disable(&vdev->vpaths[i].ring.napi);
2952 netif_carrier_off(vdev->ndev);
2953 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
2954 vxge_stop_all_tx_queue(vdev);
2956 /* Note that at this point xmit() is stopped by upper layer */
2958 vxge_hw_device_intr_disable(vdev->devh);
2964 vxge_napi_del_all(vdev);
2967 vxge_reset_all_vpaths(vdev);
2969 vxge_close_vpaths(vdev, 0);
2971 vxge_debug_entryexit(VXGE_TRACE,
2972 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2974 clear_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open);
2975 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2982 * @dev: device pointer.
2984 * This is the stop entry point of the driver. It needs to undo exactly
2985 * whatever was done by the open entry point, thus it's usually referred to
2986 * as the close function.Among other things this function mainly stops the
2987 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2988 * Return value: '0' on success and an appropriate (-)ve integer as
2989 * defined in errno.h file on failure.
2992 vxge_close(struct net_device *dev)
2994 do_vxge_close(dev, 1);
3000 * @dev: net device pointer.
3001 * @new_mtu :the new MTU size for the device.
3003 * A driver entry point to change MTU size for the device. Before changing
3004 * the MTU the device must be stopped.
3006 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3008 struct vxgedev *vdev = netdev_priv(dev);
3010 vxge_debug_entryexit(vdev->level_trace,
3011 "%s:%d", __func__, __LINE__);
3012 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3013 vxge_debug_init(vdev->level_err,
3014 "%s: mtu size is invalid", dev->name);
3018 /* check if device is down already */
3019 if (unlikely(!is_vxge_card_up(vdev))) {
3020 /* just store new value, will use later on open() */
3022 vxge_debug_init(vdev->level_err,
3023 "%s", "device is down on MTU change");
3027 vxge_debug_init(vdev->level_trace,
3028 "trying to apply new MTU %d", new_mtu);
3030 if (vxge_close(dev))
3034 vdev->mtu = new_mtu;
3039 vxge_debug_init(vdev->level_trace,
3040 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3042 vxge_debug_entryexit(vdev->level_trace,
3043 "%s:%d Exiting...", __func__, __LINE__);
3050 * @dev: pointer to the device structure
3052 * Updates the device statistics structure. This function updates the device
3053 * statistics structure in the net_device structure and returns a pointer
3056 static struct net_device_stats *
3057 vxge_get_stats(struct net_device *dev)
3059 struct vxgedev *vdev;
3060 struct net_device_stats *net_stats;
3063 vdev = netdev_priv(dev);
3065 net_stats = &vdev->stats.net_stats;
3067 memset(net_stats, 0, sizeof(struct net_device_stats));
3069 for (k = 0; k < vdev->no_of_vpath; k++) {
3070 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3071 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3072 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3073 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3074 net_stats->rx_dropped +=
3075 vdev->vpaths[k].ring.stats.rx_dropped;
3077 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3078 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3079 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3087 * @dev: Device pointer.
3088 * @ifr: An IOCTL specific structure, that can contain a pointer to
3089 * a proprietary structure used to pass information to the driver.
3090 * @cmd: This is used to distinguish between the different commands that
3091 * can be passed to the IOCTL functions.
3093 * Entry point for the Ioctl.
3095 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3102 * @dev: pointer to net device structure
3104 * Watchdog for transmit side.
3105 * This function is triggered if the Tx Queue is stopped
3106 * for a pre-defined amount of time when the Interface is still up.
3109 vxge_tx_watchdog(struct net_device *dev)
3111 struct vxgedev *vdev;
3113 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3115 vdev = (struct vxgedev *)netdev_priv(dev);
3117 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3120 vxge_debug_entryexit(VXGE_TRACE,
3121 "%s:%d Exiting...", __func__, __LINE__);
3125 * vxge_vlan_rx_register
3126 * @dev: net device pointer.
3129 * Vlan group registration
3132 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3134 struct vxgedev *vdev;
3135 struct vxge_vpath *vpath;
3138 enum vxge_hw_status status;
3141 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3143 vdev = (struct vxgedev *)netdev_priv(dev);
3145 vpath = &vdev->vpaths[0];
3146 if ((NULL == grp) && (vpath->is_open)) {
3147 /* Get the first vlan */
3148 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3150 while (status == VXGE_HW_OK) {
3152 /* Delete this vlan from the vid table */
3153 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3154 vpath = &vdev->vpaths[vp];
3155 if (!vpath->is_open)
3158 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3161 /* Get the next vlan to be deleted */
3162 vpath = &vdev->vpaths[0];
3163 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3169 for (i = 0; i < vdev->no_of_vpath; i++) {
3170 if (vdev->vpaths[i].is_configured)
3171 vdev->vpaths[i].ring.vlgrp = grp;
3174 vxge_debug_entryexit(VXGE_TRACE,
3175 "%s:%d Exiting...", __func__, __LINE__);
3179 * vxge_vlan_rx_add_vid
3180 * @dev: net device pointer.
3183 * Add the vlan id to the devices vlan id table
3186 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3188 struct vxgedev *vdev;
3189 struct vxge_vpath *vpath;
3192 vdev = (struct vxgedev *)netdev_priv(dev);
3194 /* Add these vlan to the vid table */
3195 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3196 vpath = &vdev->vpaths[vp_id];
3197 if (!vpath->is_open)
3199 vxge_hw_vpath_vid_add(vpath->handle, vid);
3204 * vxge_vlan_rx_add_vid
3205 * @dev: net device pointer.
3208 * Remove the vlan id from the device's vlan id table
3211 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3213 struct vxgedev *vdev;
3214 struct vxge_vpath *vpath;
3217 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3219 vdev = (struct vxgedev *)netdev_priv(dev);
3221 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3223 /* Delete this vlan from the vid table */
3224 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3225 vpath = &vdev->vpaths[vp_id];
3226 if (!vpath->is_open)
3228 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3230 vxge_debug_entryexit(VXGE_TRACE,
3231 "%s:%d Exiting...", __func__, __LINE__);
3234 static const struct net_device_ops vxge_netdev_ops = {
3235 .ndo_open = vxge_open,
3236 .ndo_stop = vxge_close,
3237 .ndo_get_stats = vxge_get_stats,
3238 .ndo_start_xmit = vxge_xmit,
3239 .ndo_validate_addr = eth_validate_addr,
3240 .ndo_set_multicast_list = vxge_set_multicast,
3242 .ndo_do_ioctl = vxge_ioctl,
3244 .ndo_set_mac_address = vxge_set_mac_addr,
3245 .ndo_change_mtu = vxge_change_mtu,
3246 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3247 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3248 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3250 .ndo_tx_timeout = vxge_tx_watchdog,
3251 #ifdef CONFIG_NET_POLL_CONTROLLER
3252 .ndo_poll_controller = vxge_netpoll,
3256 int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3257 struct vxge_config *config,
3258 int high_dma, int no_of_vpath,
3259 struct vxgedev **vdev_out)
3261 struct net_device *ndev;
3262 enum vxge_hw_status status = VXGE_HW_OK;
3263 struct vxgedev *vdev;
3264 int i, ret = 0, no_of_queue = 1;
3268 if (config->tx_steering_type == TX_MULTIQ_STEERING)
3269 no_of_queue = no_of_vpath;
3271 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3275 vxge_hw_device_trace_level_get(hldev),
3276 "%s : device allocation failed", __func__);
3281 vxge_debug_entryexit(
3282 vxge_hw_device_trace_level_get(hldev),
3283 "%s: %s:%d Entering...",
3284 ndev->name, __func__, __LINE__);
3286 vdev = netdev_priv(ndev);
3287 memset(vdev, 0, sizeof(struct vxgedev));
3291 vdev->pdev = hldev->pdev;
3292 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3293 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3295 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3297 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3298 NETIF_F_HW_VLAN_FILTER;
3299 /* Driver entry points */
3300 ndev->irq = vdev->pdev->irq;
3301 ndev->base_addr = (unsigned long) hldev->bar0;
3303 ndev->netdev_ops = &vxge_netdev_ops;
3305 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3307 initialize_ethtool_ops(ndev);
3309 /* Allocate memory for vpath */
3310 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3311 no_of_vpath, GFP_KERNEL);
3312 if (!vdev->vpaths) {
3313 vxge_debug_init(VXGE_ERR,
3314 "%s: vpath memory allocation failed",
3320 ndev->features |= NETIF_F_SG;
3322 ndev->features |= NETIF_F_HW_CSUM;
3323 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3324 "%s : checksuming enabled", __func__);
3327 ndev->features |= NETIF_F_HIGHDMA;
3328 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3329 "%s : using High DMA", __func__);
3332 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3334 if (vdev->config.gro_enable)
3335 ndev->features |= NETIF_F_GRO;
3337 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
3338 ndev->real_num_tx_queues = no_of_vpath;
3341 ndev->features |= NETIF_F_LLTX;
3344 for (i = 0; i < no_of_vpath; i++)
3345 spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
3347 if (register_netdev(ndev)) {
3348 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3349 "%s: %s : device registration failed!",
3350 ndev->name, __func__);
3355 /* Set the factory defined MAC address initially */
3356 ndev->addr_len = ETH_ALEN;
3358 /* Make Link state as off at this point, when the Link change
3359 * interrupt comes the state will be automatically changed to
3362 netif_carrier_off(ndev);
3364 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3365 "%s: Ethernet device registered",
3370 /* Resetting the Device stats */
3371 status = vxge_hw_mrpcim_stats_access(
3373 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3378 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3380 vxge_hw_device_trace_level_get(hldev),
3381 "%s: device stats clear returns"
3382 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3384 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3385 "%s: %s:%d Exiting...",
3386 ndev->name, __func__, __LINE__);
3390 kfree(vdev->vpaths);
3398 * vxge_device_unregister
3400 * This function will unregister and free network device
3403 vxge_device_unregister(struct __vxge_hw_device *hldev)
3405 struct vxgedev *vdev;
3406 struct net_device *dev;
3408 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3409 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3414 vdev = netdev_priv(dev);
3415 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3416 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3417 level_trace = vdev->level_trace;
3419 vxge_debug_entryexit(level_trace,
3420 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3422 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3424 /* in 2.6 will call stop() if device is up */
3425 unregister_netdev(dev);
3427 flush_scheduled_work();
3429 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3430 vxge_debug_entryexit(level_trace,
3431 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3435 * vxge_callback_crit_err
3437 * This function is called by the alarm handler in interrupt context.
3438 * Driver must analyze it based on the event type.
3441 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3442 enum vxge_hw_event type, u64 vp_id)
3444 struct net_device *dev = hldev->ndev;
3445 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3448 vxge_debug_entryexit(vdev->level_trace,
3449 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3451 /* Note: This event type should be used for device wide
3452 * indications only - Serious errors, Slot freeze and critical errors
3454 vdev->cric_err_event = type;
3456 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
3457 if (vdev->vpaths[vpath_idx].device_id == vp_id)
3460 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3461 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3462 vxge_debug_init(VXGE_ERR,
3463 "%s: Slot is frozen", vdev->ndev->name);
3464 } else if (type == VXGE_HW_EVENT_SERR) {
3465 vxge_debug_init(VXGE_ERR,
3466 "%s: Encountered Serious Error",
3468 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3469 vxge_debug_init(VXGE_ERR,
3470 "%s: Encountered Critical Error",
3474 if ((type == VXGE_HW_EVENT_SERR) ||
3475 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3476 if (unlikely(vdev->exec_mode))
3477 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3478 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3479 vxge_hw_device_mask_all(hldev);
3480 if (unlikely(vdev->exec_mode))
3481 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3482 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3483 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3485 if (unlikely(vdev->exec_mode))
3486 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3488 /* check if this vpath is already set for reset */
3489 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3491 /* disable interrupts for this vpath */
3492 vxge_vpath_intr_disable(vdev, vpath_idx);
3494 /* stop the queue for this vpath */
3495 vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
3501 vxge_debug_entryexit(vdev->level_trace,
3502 "%s: %s:%d Exiting...",
3503 vdev->ndev->name, __func__, __LINE__);
3506 static void verify_bandwidth(void)
3508 int i, band_width, total = 0, equal_priority = 0;
3510 /* 1. If user enters 0 for some fifo, give equal priority to all */
3511 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3512 if (bw_percentage[i] == 0) {
3518 if (!equal_priority) {
3519 /* 2. If sum exceeds 100, give equal priority to all */
3520 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3521 if (bw_percentage[i] == 0xFF)
3524 total += bw_percentage[i];
3525 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3532 if (!equal_priority) {
3533 /* Is all the bandwidth consumed? */
3534 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3535 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3536 /* Split rest of bw equally among next VPs*/
3538 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3539 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3540 if (band_width < 2) /* min of 2% */
3543 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3549 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3553 if (equal_priority) {
3554 vxge_debug_init(VXGE_ERR,
3555 "%s: Assigning equal bandwidth to all the vpaths",
3557 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3558 VXGE_HW_MAX_VIRTUAL_PATHS;
3559 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3560 bw_percentage[i] = bw_percentage[0];
3567 * Vpath configuration
3569 static int __devinit vxge_config_vpaths(
3570 struct vxge_hw_device_config *device_config,
3571 u64 vpath_mask, struct vxge_config *config_param)
3573 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3574 u32 txdl_size, txdl_per_memblock;
3576 temp = driver_config->vpath_per_dev;
3577 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3578 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3579 /* No more CPU. Return vpath number as zero.*/
3580 if (driver_config->g_no_cpus == -1)
3583 if (!driver_config->g_no_cpus)
3584 driver_config->g_no_cpus = num_online_cpus();
3586 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3587 if (!driver_config->vpath_per_dev)
3588 driver_config->vpath_per_dev = 1;
3590 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3591 if (!vxge_bVALn(vpath_mask, i, 1))
3595 if (default_no_vpath < driver_config->vpath_per_dev)
3596 driver_config->vpath_per_dev = default_no_vpath;
3598 driver_config->g_no_cpus = driver_config->g_no_cpus -
3599 (driver_config->vpath_per_dev * 2);
3600 if (driver_config->g_no_cpus <= 0)
3601 driver_config->g_no_cpus = -1;
3604 if (driver_config->vpath_per_dev == 1) {
3605 vxge_debug_ll_config(VXGE_TRACE,
3606 "%s: Disable tx and rx steering, "
3607 "as single vpath is configured", VXGE_DRIVER_NAME);
3608 config_param->rth_steering = NO_STEERING;
3609 config_param->tx_steering_type = NO_STEERING;
3610 device_config->rth_en = 0;
3613 /* configure bandwidth */
3614 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3615 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3617 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3618 device_config->vp_config[i].vp_id = i;
3619 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3620 if (no_of_vpaths < driver_config->vpath_per_dev) {
3621 if (!vxge_bVALn(vpath_mask, i, 1)) {
3622 vxge_debug_ll_config(VXGE_TRACE,
3623 "%s: vpath: %d is not available",
3624 VXGE_DRIVER_NAME, i);
3627 vxge_debug_ll_config(VXGE_TRACE,
3628 "%s: vpath: %d available",
3629 VXGE_DRIVER_NAME, i);
3633 vxge_debug_ll_config(VXGE_TRACE,
3634 "%s: vpath: %d is not configured, "
3635 "max_config_vpath exceeded",
3636 VXGE_DRIVER_NAME, i);
3640 /* Configure Tx fifo's */
3641 device_config->vp_config[i].fifo.enable =
3642 VXGE_HW_FIFO_ENABLE;
3643 device_config->vp_config[i].fifo.max_frags =
3645 device_config->vp_config[i].fifo.memblock_size =
3646 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3648 txdl_size = MAX_SKB_FRAGS * sizeof(struct vxge_hw_fifo_txd);
3649 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3651 device_config->vp_config[i].fifo.fifo_blocks =
3652 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3654 device_config->vp_config[i].fifo.intr =
3655 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3657 /* Configure tti properties */
3658 device_config->vp_config[i].tti.intr_enable =
3659 VXGE_HW_TIM_INTR_ENABLE;
3661 device_config->vp_config[i].tti.btimer_val =
3662 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3664 device_config->vp_config[i].tti.timer_ac_en =
3665 VXGE_HW_TIM_TIMER_AC_ENABLE;
3667 /* For msi-x with napi (each vector
3668 has a handler of its own) -
3669 Set CI to OFF for all vpaths */
3670 device_config->vp_config[i].tti.timer_ci_en =
3671 VXGE_HW_TIM_TIMER_CI_DISABLE;
3673 device_config->vp_config[i].tti.timer_ri_en =
3674 VXGE_HW_TIM_TIMER_RI_DISABLE;
3676 device_config->vp_config[i].tti.util_sel =
3677 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3679 device_config->vp_config[i].tti.ltimer_val =
3680 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3682 device_config->vp_config[i].tti.rtimer_val =
3683 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3685 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3686 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3687 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3688 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3689 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3690 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3691 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3693 /* Configure Rx rings */
3694 device_config->vp_config[i].ring.enable =
3695 VXGE_HW_RING_ENABLE;
3697 device_config->vp_config[i].ring.ring_blocks =
3698 VXGE_HW_DEF_RING_BLOCKS;
3699 device_config->vp_config[i].ring.buffer_mode =
3700 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3701 device_config->vp_config[i].ring.rxds_limit =
3702 VXGE_HW_DEF_RING_RXDS_LIMIT;
3703 device_config->vp_config[i].ring.scatter_mode =
3704 VXGE_HW_RING_SCATTER_MODE_A;
3706 /* Configure rti properties */
3707 device_config->vp_config[i].rti.intr_enable =
3708 VXGE_HW_TIM_INTR_ENABLE;
3710 device_config->vp_config[i].rti.btimer_val =
3711 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3713 device_config->vp_config[i].rti.timer_ac_en =
3714 VXGE_HW_TIM_TIMER_AC_ENABLE;
3716 device_config->vp_config[i].rti.timer_ci_en =
3717 VXGE_HW_TIM_TIMER_CI_DISABLE;
3719 device_config->vp_config[i].rti.timer_ri_en =
3720 VXGE_HW_TIM_TIMER_RI_DISABLE;
3722 device_config->vp_config[i].rti.util_sel =
3723 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3725 device_config->vp_config[i].rti.urange_a =
3727 device_config->vp_config[i].rti.urange_b =
3729 device_config->vp_config[i].rti.urange_c =
3731 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3732 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3733 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3734 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3736 device_config->vp_config[i].rti.rtimer_val =
3737 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3739 device_config->vp_config[i].rti.ltimer_val =
3740 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3742 device_config->vp_config[i].rpa_strip_vlan_tag =
3746 driver_config->vpath_per_dev = temp;
3747 return no_of_vpaths;
3750 /* initialize device configuratrions */
3751 static void __devinit vxge_device_config_init(
3752 struct vxge_hw_device_config *device_config,
3755 /* Used for CQRQ/SRQ. */
3756 device_config->dma_blockpool_initial =
3757 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3759 device_config->dma_blockpool_max =
3760 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3762 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3763 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3765 #ifndef CONFIG_PCI_MSI
3766 vxge_debug_init(VXGE_ERR,
3767 "%s: This Kernel does not support "
3768 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3772 /* Configure whether MSI-X or IRQL. */
3773 switch (*intr_type) {
3775 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3779 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3782 /* Timer period between device poll */
3783 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3785 /* Configure mac based steering. */
3786 device_config->rts_mac_en = addr_learn_en;
3788 /* Configure Vpaths */
3789 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3791 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3793 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3794 device_config->dma_blockpool_initial);
3795 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3796 device_config->dma_blockpool_max);
3797 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3798 device_config->intr_mode);
3799 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3800 device_config->device_poll_millis);
3801 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3802 device_config->rts_mac_en);
3803 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3804 device_config->rth_en);
3805 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3806 device_config->rth_it_type);
3809 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3813 vxge_debug_init(VXGE_TRACE,
3814 "%s: %d Vpath(s) opened",
3815 vdev->ndev->name, vdev->no_of_vpath);
3817 switch (vdev->config.intr_type) {
3819 vxge_debug_init(VXGE_TRACE,
3820 "%s: Interrupt type INTA", vdev->ndev->name);
3824 vxge_debug_init(VXGE_TRACE,
3825 "%s: Interrupt type MSI-X", vdev->ndev->name);
3829 if (vdev->config.rth_steering) {
3830 vxge_debug_init(VXGE_TRACE,
3831 "%s: RTH steering enabled for TCP_IPV4",
3834 vxge_debug_init(VXGE_TRACE,
3835 "%s: RTH steering disabled", vdev->ndev->name);
3838 switch (vdev->config.tx_steering_type) {
3840 vxge_debug_init(VXGE_TRACE,
3841 "%s: Tx steering disabled", vdev->ndev->name);
3843 case TX_PRIORITY_STEERING:
3844 vxge_debug_init(VXGE_TRACE,
3845 "%s: Unsupported tx steering option",
3847 vxge_debug_init(VXGE_TRACE,
3848 "%s: Tx steering disabled", vdev->ndev->name);
3849 vdev->config.tx_steering_type = 0;
3851 case TX_VLAN_STEERING:
3852 vxge_debug_init(VXGE_TRACE,
3853 "%s: Unsupported tx steering option",
3855 vxge_debug_init(VXGE_TRACE,
3856 "%s: Tx steering disabled", vdev->ndev->name);
3857 vdev->config.tx_steering_type = 0;
3859 case TX_MULTIQ_STEERING:
3860 vxge_debug_init(VXGE_TRACE,
3861 "%s: Tx multiqueue steering enabled",
3864 case TX_PORT_STEERING:
3865 vxge_debug_init(VXGE_TRACE,
3866 "%s: Tx port steering enabled",
3870 vxge_debug_init(VXGE_ERR,
3871 "%s: Unsupported tx steering type",
3873 vxge_debug_init(VXGE_TRACE,
3874 "%s: Tx steering disabled", vdev->ndev->name);
3875 vdev->config.tx_steering_type = 0;
3878 if (vdev->config.gro_enable) {
3879 vxge_debug_init(VXGE_ERR,
3880 "%s: Generic receive offload enabled",
3883 vxge_debug_init(VXGE_TRACE,
3884 "%s: Generic receive offload disabled",
3887 if (vdev->config.addr_learn_en)
3888 vxge_debug_init(VXGE_TRACE,
3889 "%s: MAC Address learning enabled", vdev->ndev->name);
3891 vxge_debug_init(VXGE_TRACE,
3892 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3894 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3895 if (!vxge_bVALn(vpath_mask, i, 1))
3897 vxge_debug_ll_config(VXGE_TRACE,
3898 "%s: MTU size - %d", vdev->ndev->name,
3899 ((struct __vxge_hw_device *)(vdev->devh))->
3900 config.vp_config[i].mtu);
3901 vxge_debug_init(VXGE_TRACE,
3902 "%s: VLAN tag stripping %s", vdev->ndev->name,
3903 ((struct __vxge_hw_device *)(vdev->devh))->
3904 config.vp_config[i].rpa_strip_vlan_tag
3905 ? "Enabled" : "Disabled");
3906 vxge_debug_init(VXGE_TRACE,
3907 "%s: Ring blocks : %d", vdev->ndev->name,
3908 ((struct __vxge_hw_device *)(vdev->devh))->
3909 config.vp_config[i].ring.ring_blocks);
3910 vxge_debug_init(VXGE_TRACE,
3911 "%s: Fifo blocks : %d", vdev->ndev->name,
3912 ((struct __vxge_hw_device *)(vdev->devh))->
3913 config.vp_config[i].fifo.fifo_blocks);
3914 vxge_debug_ll_config(VXGE_TRACE,
3915 "%s: Max frags : %d", vdev->ndev->name,
3916 ((struct __vxge_hw_device *)(vdev->devh))->
3917 config.vp_config[i].fifo.max_frags);
3924 * vxge_pm_suspend - vxge power management suspend entry point
3927 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3932 * vxge_pm_resume - vxge power management resume entry point
3935 static int vxge_pm_resume(struct pci_dev *pdev)
3943 * vxge_io_error_detected - called when PCI error is detected
3944 * @pdev: Pointer to PCI device
3945 * @state: The current pci connection state
3947 * This function is called after a PCI bus error affecting
3948 * this device has been detected.
3950 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3951 pci_channel_state_t state)
3953 struct __vxge_hw_device *hldev =
3954 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3955 struct net_device *netdev = hldev->ndev;
3957 netif_device_detach(netdev);
3959 if (netif_running(netdev)) {
3960 /* Bring down the card, while avoiding PCI I/O */
3961 do_vxge_close(netdev, 0);
3964 pci_disable_device(pdev);
3966 return PCI_ERS_RESULT_NEED_RESET;
3970 * vxge_io_slot_reset - called after the pci bus has been reset.
3971 * @pdev: Pointer to PCI device
3973 * Restart the card from scratch, as if from a cold-boot.
3974 * At this point, the card has exprienced a hard reset,
3975 * followed by fixups by BIOS, and has its config space
3976 * set up identically to what it was at cold boot.
3978 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3980 struct __vxge_hw_device *hldev =
3981 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3982 struct net_device *netdev = hldev->ndev;
3984 struct vxgedev *vdev = netdev_priv(netdev);
3986 if (pci_enable_device(pdev)) {
3987 printk(KERN_ERR "%s: "
3988 "Cannot re-enable device after reset\n",
3990 return PCI_ERS_RESULT_DISCONNECT;
3993 pci_set_master(pdev);
3996 return PCI_ERS_RESULT_RECOVERED;
4000 * vxge_io_resume - called when traffic can start flowing again.
4001 * @pdev: Pointer to PCI device
4003 * This callback is called when the error recovery driver tells
4004 * us that its OK to resume normal operation.
4006 static void vxge_io_resume(struct pci_dev *pdev)
4008 struct __vxge_hw_device *hldev =
4009 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4010 struct net_device *netdev = hldev->ndev;
4012 if (netif_running(netdev)) {
4013 if (vxge_open(netdev)) {
4014 printk(KERN_ERR "%s: "
4015 "Can't bring device back up after reset\n",
4021 netif_device_attach(netdev);
4026 * @pdev : structure containing the PCI related information of the device.
4027 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4029 * This function is called when a new PCI device gets detected and initializes
4032 * returns 0 on success and negative on failure.
4035 static int __devinit
4036 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4038 struct __vxge_hw_device *hldev;
4039 enum vxge_hw_status status;
4043 struct vxgedev *vdev;
4044 struct vxge_config ll_config;
4045 struct vxge_hw_device_config *device_config = NULL;
4046 struct vxge_hw_device_attr attr;
4047 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4049 struct vxge_mac_addrs *entry;
4050 static int bus = -1, device = -1;
4053 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4056 if (bus != pdev->bus->number)
4058 if (device != PCI_SLOT(pdev->devfn))
4061 bus = pdev->bus->number;
4062 device = PCI_SLOT(pdev->devfn);
4065 if (driver_config->config_dev_cnt &&
4066 (driver_config->config_dev_cnt !=
4067 driver_config->total_dev_cnt))
4068 vxge_debug_init(VXGE_ERR,
4069 "%s: Configured %d of %d devices",
4071 driver_config->config_dev_cnt,
4072 driver_config->total_dev_cnt);
4073 driver_config->config_dev_cnt = 0;
4074 driver_config->total_dev_cnt = 0;
4075 driver_config->g_no_cpus = 0;
4076 driver_config->vpath_per_dev = max_config_vpath;
4079 driver_config->total_dev_cnt++;
4080 if (++driver_config->config_dev_cnt > max_config_dev) {
4085 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4087 if (!device_config) {
4089 vxge_debug_init(VXGE_ERR,
4090 "device_config : malloc failed %s %d",
4091 __FILE__, __LINE__);
4095 memset(&ll_config, 0, sizeof(struct vxge_config));
4096 ll_config.tx_steering_type = TX_MULTIQ_STEERING;
4097 ll_config.intr_type = MSI_X;
4098 ll_config.napi_weight = NEW_NAPI_WEIGHT;
4099 ll_config.rth_steering = RTH_STEERING;
4101 /* get the default configuration parameters */
4102 vxge_hw_device_config_default_get(device_config);
4104 /* initialize configuration parameters */
4105 vxge_device_config_init(device_config, &ll_config.intr_type);
4107 ret = pci_enable_device(pdev);
4109 vxge_debug_init(VXGE_ERR,
4110 "%s : can not enable PCI device", __func__);
4114 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
4115 vxge_debug_ll_config(VXGE_TRACE,
4116 "%s : using 64bit DMA", __func__);
4120 if (pci_set_consistent_dma_mask(pdev,
4121 0xffffffffffffffffULL)) {
4122 vxge_debug_init(VXGE_ERR,
4123 "%s : unable to obtain 64bit DMA for "
4124 "consistent allocations", __func__);
4128 } else if (!pci_set_dma_mask(pdev, 0xffffffffUL)) {
4129 vxge_debug_ll_config(VXGE_TRACE,
4130 "%s : using 32bit DMA", __func__);
4136 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4137 vxge_debug_init(VXGE_ERR,
4138 "%s : request regions failed", __func__);
4143 pci_set_master(pdev);
4145 attr.bar0 = pci_ioremap_bar(pdev, 0);
4147 vxge_debug_init(VXGE_ERR,
4148 "%s : cannot remap io memory bar0", __func__);
4152 vxge_debug_ll_config(VXGE_TRACE,
4153 "pci ioremap bar0: %p:0x%llx",
4155 (unsigned long long)pci_resource_start(pdev, 0));
4157 status = vxge_hw_device_hw_info_get(attr.bar0,
4158 &ll_config.device_hw_info);
4159 if (status != VXGE_HW_OK) {
4160 vxge_debug_init(VXGE_ERR,
4161 "%s: Reading of hardware info failed."
4162 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4167 if (ll_config.device_hw_info.fw_version.major !=
4168 VXGE_DRIVER_FW_VERSION_MAJOR) {
4169 vxge_debug_init(VXGE_ERR,
4170 "%s: Incorrect firmware version."
4171 "Please upgrade the firmware to version 1.x.x",
4177 vpath_mask = ll_config.device_hw_info.vpath_mask;
4178 if (vpath_mask == 0) {
4179 vxge_debug_ll_config(VXGE_TRACE,
4180 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4185 vxge_debug_ll_config(VXGE_TRACE,
4186 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4187 (unsigned long long)vpath_mask);
4189 /* Check how many vpaths are available */
4190 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4191 if (!((vpath_mask) & vxge_mBIT(i)))
4193 max_vpath_supported++;
4196 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4197 if ((VXGE_HW_FUNCTION_MODE_SRIOV ==
4198 ll_config.device_hw_info.function_mode) &&
4199 (max_config_dev > 1) && (pdev->is_physfn)) {
4200 ret = pci_enable_sriov(pdev, max_config_dev - 1);
4202 vxge_debug_ll_config(VXGE_ERR,
4203 "Failed to enable SRIOV: %d \n", ret);
4207 * Configure vpaths and get driver configured number of vpaths
4208 * which is less than or equal to the maximum vpaths per function.
4210 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, &ll_config);
4212 vxge_debug_ll_config(VXGE_ERR,
4213 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4218 /* Setting driver callbacks */
4219 attr.uld_callbacks.link_up = vxge_callback_link_up;
4220 attr.uld_callbacks.link_down = vxge_callback_link_down;
4221 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4223 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4224 if (status != VXGE_HW_OK) {
4225 vxge_debug_init(VXGE_ERR,
4226 "Failed to initialize device (%d)", status);
4231 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4233 /* set private device info */
4234 pci_set_drvdata(pdev, hldev);
4236 ll_config.gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4237 ll_config.fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4238 ll_config.addr_learn_en = addr_learn_en;
4239 ll_config.rth_algorithm = RTH_ALG_JENKINS;
4240 ll_config.rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
4241 ll_config.rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
4242 ll_config.rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4243 ll_config.rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4244 ll_config.rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4245 ll_config.rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4246 ll_config.rth_bkt_sz = RTH_BUCKET_SIZE;
4247 ll_config.tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4248 ll_config.rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4250 if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath,
4256 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4257 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4258 vxge_hw_device_trace_level_get(hldev));
4260 /* set private HW device info */
4261 hldev->ndev = vdev->ndev;
4262 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4263 vdev->bar0 = attr.bar0;
4264 vdev->max_vpath_supported = max_vpath_supported;
4265 vdev->no_of_vpath = no_of_vpath;
4267 /* Virtual Path count */
4268 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4269 if (!vxge_bVALn(vpath_mask, i, 1))
4271 if (j >= vdev->no_of_vpath)
4274 vdev->vpaths[j].is_configured = 1;
4275 vdev->vpaths[j].device_id = i;
4276 vdev->vpaths[j].fifo.driver_id = j;
4277 vdev->vpaths[j].ring.driver_id = j;
4278 vdev->vpaths[j].vdev = vdev;
4279 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4280 memcpy((u8 *)vdev->vpaths[j].macaddr,
4281 (u8 *)ll_config.device_hw_info.mac_addrs[i],
4284 /* Initialize the mac address list header */
4285 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4287 vdev->vpaths[j].mac_addr_cnt = 0;
4288 vdev->vpaths[j].mcast_addr_cnt = 0;
4291 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4292 vdev->max_config_port = max_config_port;
4294 vdev->vlan_tag_strip = vlan_tag_strip;
4296 /* map the hashing selector table to the configured vpaths */
4297 for (i = 0; i < vdev->no_of_vpath; i++)
4298 vdev->vpath_selector[i] = vpath_selector[i];
4300 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4302 ll_config.device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4303 ll_config.device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4304 ll_config.device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4306 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4307 vdev->ndev->name, ll_config.device_hw_info.serial_number);
4309 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4310 vdev->ndev->name, ll_config.device_hw_info.part_number);
4312 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4313 vdev->ndev->name, ll_config.device_hw_info.product_desc);
4315 vxge_debug_init(VXGE_TRACE,
4316 "%s: MAC ADDR: %02X:%02X:%02X:%02X:%02X:%02X",
4317 vdev->ndev->name, macaddr[0], macaddr[1], macaddr[2],
4318 macaddr[3], macaddr[4], macaddr[5]);
4320 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4321 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4323 vxge_debug_init(VXGE_TRACE,
4324 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4325 ll_config.device_hw_info.fw_version.version,
4326 ll_config.device_hw_info.fw_date.date);
4328 vxge_print_parm(vdev, vpath_mask);
4330 /* Store the fw version for ethttool option */
4331 strcpy(vdev->fw_version, ll_config.device_hw_info.fw_version.version);
4332 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4333 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4335 /* Copy the station mac address to the list */
4336 for (i = 0; i < vdev->no_of_vpath; i++) {
4337 entry = (struct vxge_mac_addrs *)
4338 kzalloc(sizeof(struct vxge_mac_addrs),
4340 if (NULL == entry) {
4341 vxge_debug_init(VXGE_ERR,
4342 "%s: mac_addr_list : memory allocation failed",
4347 macaddr = (u8 *)&entry->macaddr;
4348 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4349 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4350 vdev->vpaths[i].mac_addr_cnt = 1;
4353 kfree(device_config);
4354 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4355 vdev->ndev->name, __func__, __LINE__);
4357 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4358 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4359 vxge_hw_device_trace_level_get(hldev));
4364 for (i = 0; i < vdev->no_of_vpath; i++)
4365 vxge_free_mac_add_list(&vdev->vpaths[i]);
4367 vxge_device_unregister(hldev);
4369 pci_disable_sriov(pdev);
4370 vxge_hw_device_terminate(hldev);
4374 pci_release_regions(pdev);
4376 pci_disable_device(pdev);
4378 kfree(device_config);
4379 driver_config->config_dev_cnt--;
4380 pci_set_drvdata(pdev, NULL);
4385 * vxge_rem_nic - Free the PCI device
4386 * @pdev: structure containing the PCI related information of the device.
4387 * Description: This function is called by the Pci subsystem to release a
4388 * PCI device and free up all resource held up by the device.
4390 static void __devexit
4391 vxge_remove(struct pci_dev *pdev)
4393 struct __vxge_hw_device *hldev;
4394 struct vxgedev *vdev = NULL;
4395 struct net_device *dev;
4397 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4398 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4402 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4407 vdev = netdev_priv(dev);
4409 #if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4410 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4411 level_trace = vdev->level_trace;
4413 vxge_debug_entryexit(level_trace,
4414 "%s:%d", __func__, __LINE__);
4416 vxge_debug_init(level_trace,
4417 "%s : removing PCI device...", __func__);
4418 vxge_device_unregister(hldev);
4420 for (i = 0; i < vdev->no_of_vpath; i++) {
4421 vxge_free_mac_add_list(&vdev->vpaths[i]);
4422 vdev->vpaths[i].mcast_addr_cnt = 0;
4423 vdev->vpaths[i].mac_addr_cnt = 0;
4426 kfree(vdev->vpaths);
4428 iounmap(vdev->bar0);
4430 pci_disable_sriov(pdev);
4432 /* we are safe to free it now */
4435 vxge_debug_init(level_trace,
4436 "%s:%d Device unregistered", __func__, __LINE__);
4438 vxge_hw_device_terminate(hldev);
4440 pci_disable_device(pdev);
4441 pci_release_regions(pdev);
4442 pci_set_drvdata(pdev, NULL);
4443 vxge_debug_entryexit(level_trace,
4444 "%s:%d Exiting...", __func__, __LINE__);
4447 static struct pci_error_handlers vxge_err_handler = {
4448 .error_detected = vxge_io_error_detected,
4449 .slot_reset = vxge_io_slot_reset,
4450 .resume = vxge_io_resume,
4453 static struct pci_driver vxge_driver = {
4454 .name = VXGE_DRIVER_NAME,
4455 .id_table = vxge_id_table,
4456 .probe = vxge_probe,
4457 .remove = __devexit_p(vxge_remove),
4459 .suspend = vxge_pm_suspend,
4460 .resume = vxge_pm_resume,
4462 .err_handler = &vxge_err_handler,
4470 snprintf(version, 32, "%s", DRV_VERSION);
4472 printk(KERN_CRIT "%s: Copyright(c) 2002-2009 Neterion Inc\n",
4474 printk(KERN_CRIT "%s: Driver version: %s\n",
4475 VXGE_DRIVER_NAME, version);
4479 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4483 ret = pci_register_driver(&vxge_driver);
4485 if (driver_config->config_dev_cnt &&
4486 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4487 vxge_debug_init(VXGE_ERR,
4488 "%s: Configured %d of %d devices",
4489 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4490 driver_config->total_dev_cnt);
4493 kfree(driver_config);
4501 pci_unregister_driver(&vxge_driver);
4502 kfree(driver_config);
4504 module_init(vxge_starter);
4505 module_exit(vxge_closer);