ARM: 7409/1: Do not call flush_cache_user_range with mmap_sem held
[linux/fpc-iii.git] / drivers / net / vxge / vxge-main.c
blob8ab870a2ad0239105f579558bb5c077ffb7dea6a
1 /******************************************************************************
2 * This software may be used and distributed according to the terms of
3 * the GNU General Public License (GPL), incorporated herein by reference.
4 * Drivers based on or derived from this code fall under the GPL and must
5 * retain the authorship, copyright and license notice. This file is not
6 * a complete program and may only be used when the entire operating
7 * system is licensed under the GPL.
8 * See the file COPYING in this distribution for more information.
10 * vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
11 * Virtualized Server Adapter.
12 * Copyright(c) 2002-2010 Exar Corp.
14 * The module loadable parameters that are supported by the driver and a brief
15 * explanation of all the variables:
16 * vlan_tag_strip:
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.
23 * addr_learn_en:
24 * Enable learning the mac address of the guest OS interface in
25 * a virtualization environment.
26 * 0 - DISABLE
27 * 1 - ENABLE
29 * max_config_port:
30 * Maximum number of port to be supported.
31 * MIN -1 and MAX - 2
33 * max_config_vpath:
34 * This configures the maximum no of VPATH configures for each
35 * device function.
36 * MIN - 1 and MAX - 17
38 * max_config_dev:
39 * This configures maximum no of Device function to be enabled.
40 * MIN - 1 and MAX - 17
42 ******************************************************************************/
44 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
46 #include <linux/if_vlan.h>
47 #include <linux/pci.h>
48 #include <linux/slab.h>
49 #include <linux/tcp.h>
50 #include <net/ip.h>
51 #include <linux/netdevice.h>
52 #include <linux/etherdevice.h>
53 #include <linux/firmware.h>
54 #include <linux/net_tstamp.h>
55 #include <linux/prefetch.h>
56 #include "vxge-main.h"
57 #include "vxge-reg.h"
59 MODULE_LICENSE("Dual BSD/GPL");
60 MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
61 "Virtualized Server Adapter");
63 static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
64 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
65 PCI_ANY_ID},
66 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
67 PCI_ANY_ID},
68 {0}
71 MODULE_DEVICE_TABLE(pci, vxge_id_table);
73 VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
74 VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
75 VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
76 VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
77 VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
78 VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
80 static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
81 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
82 static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
83 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
84 module_param_array(bw_percentage, uint, NULL, 0);
86 static struct vxge_drv_config *driver_config;
88 static inline int is_vxge_card_up(struct vxgedev *vdev)
90 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
93 static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
95 struct sk_buff **skb_ptr = NULL;
96 struct sk_buff **temp;
97 #define NR_SKB_COMPLETED 128
98 struct sk_buff *completed[NR_SKB_COMPLETED];
99 int more;
101 do {
102 more = 0;
103 skb_ptr = completed;
105 if (__netif_tx_trylock(fifo->txq)) {
106 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
107 NR_SKB_COMPLETED, &more);
108 __netif_tx_unlock(fifo->txq);
111 /* free SKBs */
112 for (temp = completed; temp != skb_ptr; temp++)
113 dev_kfree_skb_irq(*temp);
114 } while (more);
117 static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
119 int i;
121 /* Complete all transmits */
122 for (i = 0; i < vdev->no_of_vpath; i++)
123 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
126 static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
128 int i;
129 struct vxge_ring *ring;
131 /* Complete all receives*/
132 for (i = 0; i < vdev->no_of_vpath; i++) {
133 ring = &vdev->vpaths[i].ring;
134 vxge_hw_vpath_poll_rx(ring->handle);
139 * vxge_callback_link_up
141 * This function is called during interrupt context to notify link up state
142 * change.
144 static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
146 struct net_device *dev = hldev->ndev;
147 struct vxgedev *vdev = netdev_priv(dev);
149 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
150 vdev->ndev->name, __func__, __LINE__);
151 netdev_notice(vdev->ndev, "Link Up\n");
152 vdev->stats.link_up++;
154 netif_carrier_on(vdev->ndev);
155 netif_tx_wake_all_queues(vdev->ndev);
157 vxge_debug_entryexit(VXGE_TRACE,
158 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
162 * vxge_callback_link_down
164 * This function is called during interrupt context to notify link down state
165 * change.
167 static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
169 struct net_device *dev = hldev->ndev;
170 struct vxgedev *vdev = netdev_priv(dev);
172 vxge_debug_entryexit(VXGE_TRACE,
173 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
174 netdev_notice(vdev->ndev, "Link Down\n");
176 vdev->stats.link_down++;
177 netif_carrier_off(vdev->ndev);
178 netif_tx_stop_all_queues(vdev->ndev);
180 vxge_debug_entryexit(VXGE_TRACE,
181 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
185 * vxge_rx_alloc
187 * Allocate SKB.
189 static struct sk_buff *
190 vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
192 struct net_device *dev;
193 struct sk_buff *skb;
194 struct vxge_rx_priv *rx_priv;
196 dev = ring->ndev;
197 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
198 ring->ndev->name, __func__, __LINE__);
200 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
202 /* try to allocate skb first. this one may fail */
203 skb = netdev_alloc_skb(dev, skb_size +
204 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
205 if (skb == NULL) {
206 vxge_debug_mem(VXGE_ERR,
207 "%s: out of memory to allocate SKB", dev->name);
208 ring->stats.skb_alloc_fail++;
209 return NULL;
212 vxge_debug_mem(VXGE_TRACE,
213 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
214 __func__, __LINE__, skb);
216 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
218 rx_priv->skb = skb;
219 rx_priv->skb_data = NULL;
220 rx_priv->data_size = skb_size;
221 vxge_debug_entryexit(VXGE_TRACE,
222 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
224 return skb;
228 * vxge_rx_map
230 static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
232 struct vxge_rx_priv *rx_priv;
233 dma_addr_t dma_addr;
235 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
236 ring->ndev->name, __func__, __LINE__);
237 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
239 rx_priv->skb_data = rx_priv->skb->data;
240 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
241 rx_priv->data_size, PCI_DMA_FROMDEVICE);
243 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
244 ring->stats.pci_map_fail++;
245 return -EIO;
247 vxge_debug_mem(VXGE_TRACE,
248 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
249 ring->ndev->name, __func__, __LINE__,
250 (unsigned long long)dma_addr);
251 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
253 rx_priv->data_dma = dma_addr;
254 vxge_debug_entryexit(VXGE_TRACE,
255 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
257 return 0;
261 * vxge_rx_initial_replenish
262 * Allocation of RxD as an initial replenish procedure.
264 static enum vxge_hw_status
265 vxge_rx_initial_replenish(void *dtrh, void *userdata)
267 struct vxge_ring *ring = (struct vxge_ring *)userdata;
268 struct vxge_rx_priv *rx_priv;
270 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
271 ring->ndev->name, __func__, __LINE__);
272 if (vxge_rx_alloc(dtrh, ring,
273 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
274 return VXGE_HW_FAIL;
276 if (vxge_rx_map(dtrh, ring)) {
277 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
278 dev_kfree_skb(rx_priv->skb);
280 return VXGE_HW_FAIL;
282 vxge_debug_entryexit(VXGE_TRACE,
283 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
285 return VXGE_HW_OK;
288 static inline void
289 vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
290 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
293 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
294 ring->ndev->name, __func__, __LINE__);
295 skb_record_rx_queue(skb, ring->driver_id);
296 skb->protocol = eth_type_trans(skb, ring->ndev);
298 ring->stats.rx_frms++;
299 ring->stats.rx_bytes += pkt_length;
301 if (skb->pkt_type == PACKET_MULTICAST)
302 ring->stats.rx_mcast++;
304 vxge_debug_rx(VXGE_TRACE,
305 "%s: %s:%d skb protocol = %d",
306 ring->ndev->name, __func__, __LINE__, skb->protocol);
308 if (ring->vlgrp && ext_info->vlan &&
309 (ring->vlan_tag_strip ==
310 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
311 vlan_gro_receive(ring->napi_p, ring->vlgrp,
312 ext_info->vlan, skb);
313 else
314 napi_gro_receive(ring->napi_p, skb);
316 vxge_debug_entryexit(VXGE_TRACE,
317 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
320 static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
321 struct vxge_rx_priv *rx_priv)
323 pci_dma_sync_single_for_device(ring->pdev,
324 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
326 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
327 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
330 static inline void vxge_post(int *dtr_cnt, void **first_dtr,
331 void *post_dtr, struct __vxge_hw_ring *ringh)
333 int dtr_count = *dtr_cnt;
334 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
335 if (*first_dtr)
336 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
337 *first_dtr = post_dtr;
338 } else
339 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
340 dtr_count++;
341 *dtr_cnt = dtr_count;
345 * vxge_rx_1b_compl
347 * If the interrupt is because of a received frame or if the receive ring
348 * contains fresh as yet un-processed frames, this function is called.
350 static enum vxge_hw_status
351 vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
352 u8 t_code, void *userdata)
354 struct vxge_ring *ring = (struct vxge_ring *)userdata;
355 struct net_device *dev = ring->ndev;
356 unsigned int dma_sizes;
357 void *first_dtr = NULL;
358 int dtr_cnt = 0;
359 int data_size;
360 dma_addr_t data_dma;
361 int pkt_length;
362 struct sk_buff *skb;
363 struct vxge_rx_priv *rx_priv;
364 struct vxge_hw_ring_rxd_info ext_info;
365 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
366 ring->ndev->name, __func__, __LINE__);
368 do {
369 prefetch((char *)dtr + L1_CACHE_BYTES);
370 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
371 skb = rx_priv->skb;
372 data_size = rx_priv->data_size;
373 data_dma = rx_priv->data_dma;
374 prefetch(rx_priv->skb_data);
376 vxge_debug_rx(VXGE_TRACE,
377 "%s: %s:%d skb = 0x%p",
378 ring->ndev->name, __func__, __LINE__, skb);
380 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
381 pkt_length = dma_sizes;
383 pkt_length -= ETH_FCS_LEN;
385 vxge_debug_rx(VXGE_TRACE,
386 "%s: %s:%d Packet Length = %d",
387 ring->ndev->name, __func__, __LINE__, pkt_length);
389 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
391 /* check skb validity */
392 vxge_assert(skb);
394 prefetch((char *)skb + L1_CACHE_BYTES);
395 if (unlikely(t_code)) {
396 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
397 VXGE_HW_OK) {
399 ring->stats.rx_errors++;
400 vxge_debug_rx(VXGE_TRACE,
401 "%s: %s :%d Rx T_code is %d",
402 ring->ndev->name, __func__,
403 __LINE__, t_code);
405 /* If the t_code is not supported and if the
406 * t_code is other than 0x5 (unparseable packet
407 * such as unknown UPV6 header), Drop it !!!
409 vxge_re_pre_post(dtr, ring, rx_priv);
411 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
412 ring->stats.rx_dropped++;
413 continue;
417 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
418 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
419 if (!vxge_rx_map(dtr, ring)) {
420 skb_put(skb, pkt_length);
422 pci_unmap_single(ring->pdev, data_dma,
423 data_size, PCI_DMA_FROMDEVICE);
425 vxge_hw_ring_rxd_pre_post(ringh, dtr);
426 vxge_post(&dtr_cnt, &first_dtr, dtr,
427 ringh);
428 } else {
429 dev_kfree_skb(rx_priv->skb);
430 rx_priv->skb = skb;
431 rx_priv->data_size = data_size;
432 vxge_re_pre_post(dtr, ring, rx_priv);
434 vxge_post(&dtr_cnt, &first_dtr, dtr,
435 ringh);
436 ring->stats.rx_dropped++;
437 break;
439 } else {
440 vxge_re_pre_post(dtr, ring, rx_priv);
442 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
443 ring->stats.rx_dropped++;
444 break;
446 } else {
447 struct sk_buff *skb_up;
449 skb_up = netdev_alloc_skb(dev, pkt_length +
450 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
451 if (skb_up != NULL) {
452 skb_reserve(skb_up,
453 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
455 pci_dma_sync_single_for_cpu(ring->pdev,
456 data_dma, data_size,
457 PCI_DMA_FROMDEVICE);
459 vxge_debug_mem(VXGE_TRACE,
460 "%s: %s:%d skb_up = %p",
461 ring->ndev->name, __func__,
462 __LINE__, skb);
463 memcpy(skb_up->data, skb->data, pkt_length);
465 vxge_re_pre_post(dtr, ring, rx_priv);
467 vxge_post(&dtr_cnt, &first_dtr, dtr,
468 ringh);
469 /* will netif_rx small SKB instead */
470 skb = skb_up;
471 skb_put(skb, pkt_length);
472 } else {
473 vxge_re_pre_post(dtr, ring, rx_priv);
475 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
476 vxge_debug_rx(VXGE_ERR,
477 "%s: vxge_rx_1b_compl: out of "
478 "memory", dev->name);
479 ring->stats.skb_alloc_fail++;
480 break;
484 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
485 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
486 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
487 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
488 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
489 skb->ip_summed = CHECKSUM_UNNECESSARY;
490 else
491 skb_checksum_none_assert(skb);
494 if (ring->rx_hwts) {
495 struct skb_shared_hwtstamps *skb_hwts;
496 u32 ns = *(u32 *)(skb->head + pkt_length);
498 skb_hwts = skb_hwtstamps(skb);
499 skb_hwts->hwtstamp = ns_to_ktime(ns);
500 skb_hwts->syststamp.tv64 = 0;
503 /* rth_hash_type and rth_it_hit are non-zero regardless of
504 * whether rss is enabled. Only the rth_value is zero/non-zero
505 * if rss is disabled/enabled, so key off of that.
507 if (ext_info.rth_value)
508 skb->rxhash = ext_info.rth_value;
510 vxge_rx_complete(ring, skb, ext_info.vlan,
511 pkt_length, &ext_info);
513 ring->budget--;
514 ring->pkts_processed++;
515 if (!ring->budget)
516 break;
518 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
519 &t_code) == VXGE_HW_OK);
521 if (first_dtr)
522 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
524 vxge_debug_entryexit(VXGE_TRACE,
525 "%s:%d Exiting...",
526 __func__, __LINE__);
527 return VXGE_HW_OK;
531 * vxge_xmit_compl
533 * If an interrupt was raised to indicate DMA complete of the Tx packet,
534 * this function is called. It identifies the last TxD whose buffer was
535 * freed and frees all skbs whose data have already DMA'ed into the NICs
536 * internal memory.
538 static enum vxge_hw_status
539 vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
540 enum vxge_hw_fifo_tcode t_code, void *userdata,
541 struct sk_buff ***skb_ptr, int nr_skb, int *more)
543 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
544 struct sk_buff *skb, **done_skb = *skb_ptr;
545 int pkt_cnt = 0;
547 vxge_debug_entryexit(VXGE_TRACE,
548 "%s:%d Entered....", __func__, __LINE__);
550 do {
551 int frg_cnt;
552 skb_frag_t *frag;
553 int i = 0, j;
554 struct vxge_tx_priv *txd_priv =
555 vxge_hw_fifo_txdl_private_get(dtr);
557 skb = txd_priv->skb;
558 frg_cnt = skb_shinfo(skb)->nr_frags;
559 frag = &skb_shinfo(skb)->frags[0];
561 vxge_debug_tx(VXGE_TRACE,
562 "%s: %s:%d fifo_hw = %p dtr = %p "
563 "tcode = 0x%x", fifo->ndev->name, __func__,
564 __LINE__, fifo_hw, dtr, t_code);
565 /* check skb validity */
566 vxge_assert(skb);
567 vxge_debug_tx(VXGE_TRACE,
568 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
569 fifo->ndev->name, __func__, __LINE__,
570 skb, txd_priv, frg_cnt);
571 if (unlikely(t_code)) {
572 fifo->stats.tx_errors++;
573 vxge_debug_tx(VXGE_ERR,
574 "%s: tx: dtr %p completed due to "
575 "error t_code %01x", fifo->ndev->name,
576 dtr, t_code);
577 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
580 /* for unfragmented skb */
581 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
582 skb_headlen(skb), PCI_DMA_TODEVICE);
584 for (j = 0; j < frg_cnt; j++) {
585 pci_unmap_page(fifo->pdev,
586 txd_priv->dma_buffers[i++],
587 frag->size, PCI_DMA_TODEVICE);
588 frag += 1;
591 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
593 /* Updating the statistics block */
594 fifo->stats.tx_frms++;
595 fifo->stats.tx_bytes += skb->len;
597 *done_skb++ = skb;
599 if (--nr_skb <= 0) {
600 *more = 1;
601 break;
604 pkt_cnt++;
605 if (pkt_cnt > fifo->indicate_max_pkts)
606 break;
608 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
609 &dtr, &t_code) == VXGE_HW_OK);
611 *skb_ptr = done_skb;
612 if (netif_tx_queue_stopped(fifo->txq))
613 netif_tx_wake_queue(fifo->txq);
615 vxge_debug_entryexit(VXGE_TRACE,
616 "%s: %s:%d Exiting...",
617 fifo->ndev->name, __func__, __LINE__);
618 return VXGE_HW_OK;
621 /* select a vpath to transmit the packet */
622 static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
624 u16 queue_len, counter = 0;
625 if (skb->protocol == htons(ETH_P_IP)) {
626 struct iphdr *ip;
627 struct tcphdr *th;
629 ip = ip_hdr(skb);
631 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
632 th = (struct tcphdr *)(((unsigned char *)ip) +
633 ip->ihl*4);
635 queue_len = vdev->no_of_vpath;
636 counter = (ntohs(th->source) +
637 ntohs(th->dest)) &
638 vdev->vpath_selector[queue_len - 1];
639 if (counter >= queue_len)
640 counter = queue_len - 1;
643 return counter;
646 static enum vxge_hw_status vxge_search_mac_addr_in_list(
647 struct vxge_vpath *vpath, u64 del_mac)
649 struct list_head *entry, *next;
650 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
651 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
652 return TRUE;
654 return FALSE;
657 static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
659 struct vxge_mac_addrs *new_mac_entry;
660 u8 *mac_address = NULL;
662 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
663 return TRUE;
665 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
666 if (!new_mac_entry) {
667 vxge_debug_mem(VXGE_ERR,
668 "%s: memory allocation failed",
669 VXGE_DRIVER_NAME);
670 return FALSE;
673 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
675 /* Copy the new mac address to the list */
676 mac_address = (u8 *)&new_mac_entry->macaddr;
677 memcpy(mac_address, mac->macaddr, ETH_ALEN);
679 new_mac_entry->state = mac->state;
680 vpath->mac_addr_cnt++;
682 /* Is this a multicast address */
683 if (0x01 & mac->macaddr[0])
684 vpath->mcast_addr_cnt++;
686 return TRUE;
689 /* Add a mac address to DA table */
690 static enum vxge_hw_status
691 vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
693 enum vxge_hw_status status = VXGE_HW_OK;
694 struct vxge_vpath *vpath;
695 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
697 if (0x01 & mac->macaddr[0]) /* multicast address */
698 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
699 else
700 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
702 vpath = &vdev->vpaths[mac->vpath_no];
703 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
704 mac->macmask, duplicate_mode);
705 if (status != VXGE_HW_OK) {
706 vxge_debug_init(VXGE_ERR,
707 "DA config add entry failed for vpath:%d",
708 vpath->device_id);
709 } else
710 if (FALSE == vxge_mac_list_add(vpath, mac))
711 status = -EPERM;
713 return status;
716 static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
718 struct macInfo mac_info;
719 u8 *mac_address = NULL;
720 u64 mac_addr = 0, vpath_vector = 0;
721 int vpath_idx = 0;
722 enum vxge_hw_status status = VXGE_HW_OK;
723 struct vxge_vpath *vpath = NULL;
724 struct __vxge_hw_device *hldev;
726 hldev = pci_get_drvdata(vdev->pdev);
728 mac_address = (u8 *)&mac_addr;
729 memcpy(mac_address, mac_header, ETH_ALEN);
731 /* Is this mac address already in the list? */
732 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
733 vpath = &vdev->vpaths[vpath_idx];
734 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
735 return vpath_idx;
738 memset(&mac_info, 0, sizeof(struct macInfo));
739 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
741 /* Any vpath has room to add mac address to its da table? */
742 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
743 vpath = &vdev->vpaths[vpath_idx];
744 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
745 /* Add this mac address to this vpath */
746 mac_info.vpath_no = vpath_idx;
747 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
748 status = vxge_add_mac_addr(vdev, &mac_info);
749 if (status != VXGE_HW_OK)
750 return -EPERM;
751 return vpath_idx;
755 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
756 vpath_idx = 0;
757 mac_info.vpath_no = vpath_idx;
758 /* Is the first vpath already selected as catch-basin ? */
759 vpath = &vdev->vpaths[vpath_idx];
760 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
761 /* Add this mac address to this vpath */
762 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
763 return -EPERM;
764 return vpath_idx;
767 /* Select first vpath as catch-basin */
768 vpath_vector = vxge_mBIT(vpath->device_id);
769 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
770 vxge_hw_mgmt_reg_type_mrpcim,
772 (ulong)offsetof(
773 struct vxge_hw_mrpcim_reg,
774 rts_mgr_cbasin_cfg),
775 vpath_vector);
776 if (status != VXGE_HW_OK) {
777 vxge_debug_tx(VXGE_ERR,
778 "%s: Unable to set the vpath-%d in catch-basin mode",
779 VXGE_DRIVER_NAME, vpath->device_id);
780 return -EPERM;
783 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
784 return -EPERM;
786 return vpath_idx;
790 * vxge_xmit
791 * @skb : the socket buffer containing the Tx data.
792 * @dev : device pointer.
794 * This function is the Tx entry point of the driver. Neterion NIC supports
795 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
797 static netdev_tx_t
798 vxge_xmit(struct sk_buff *skb, struct net_device *dev)
800 struct vxge_fifo *fifo = NULL;
801 void *dtr_priv;
802 void *dtr = NULL;
803 struct vxgedev *vdev = NULL;
804 enum vxge_hw_status status;
805 int frg_cnt, first_frg_len;
806 skb_frag_t *frag;
807 int i = 0, j = 0, avail;
808 u64 dma_pointer;
809 struct vxge_tx_priv *txdl_priv = NULL;
810 struct __vxge_hw_fifo *fifo_hw;
811 int offload_type;
812 int vpath_no = 0;
814 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
815 dev->name, __func__, __LINE__);
817 /* A buffer with no data will be dropped */
818 if (unlikely(skb->len <= 0)) {
819 vxge_debug_tx(VXGE_ERR,
820 "%s: Buffer has no data..", dev->name);
821 dev_kfree_skb(skb);
822 return NETDEV_TX_OK;
825 vdev = netdev_priv(dev);
827 if (unlikely(!is_vxge_card_up(vdev))) {
828 vxge_debug_tx(VXGE_ERR,
829 "%s: vdev not initialized", dev->name);
830 dev_kfree_skb(skb);
831 return NETDEV_TX_OK;
834 if (vdev->config.addr_learn_en) {
835 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
836 if (vpath_no == -EPERM) {
837 vxge_debug_tx(VXGE_ERR,
838 "%s: Failed to store the mac address",
839 dev->name);
840 dev_kfree_skb(skb);
841 return NETDEV_TX_OK;
845 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
846 vpath_no = skb_get_queue_mapping(skb);
847 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
848 vpath_no = vxge_get_vpath_no(vdev, skb);
850 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
852 if (vpath_no >= vdev->no_of_vpath)
853 vpath_no = 0;
855 fifo = &vdev->vpaths[vpath_no].fifo;
856 fifo_hw = fifo->handle;
858 if (netif_tx_queue_stopped(fifo->txq))
859 return NETDEV_TX_BUSY;
861 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
862 if (avail == 0) {
863 vxge_debug_tx(VXGE_ERR,
864 "%s: No free TXDs available", dev->name);
865 fifo->stats.txd_not_free++;
866 goto _exit0;
869 /* Last TXD? Stop tx queue to avoid dropping packets. TX
870 * completion will resume the queue.
872 if (avail == 1)
873 netif_tx_stop_queue(fifo->txq);
875 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
876 if (unlikely(status != VXGE_HW_OK)) {
877 vxge_debug_tx(VXGE_ERR,
878 "%s: Out of descriptors .", dev->name);
879 fifo->stats.txd_out_of_desc++;
880 goto _exit0;
883 vxge_debug_tx(VXGE_TRACE,
884 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
885 dev->name, __func__, __LINE__,
886 fifo_hw, dtr, dtr_priv);
888 if (vlan_tx_tag_present(skb)) {
889 u16 vlan_tag = vlan_tx_tag_get(skb);
890 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
893 first_frg_len = skb_headlen(skb);
895 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
896 PCI_DMA_TODEVICE);
898 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
899 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
900 fifo->stats.pci_map_fail++;
901 goto _exit0;
904 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
905 txdl_priv->skb = skb;
906 txdl_priv->dma_buffers[j] = dma_pointer;
908 frg_cnt = skb_shinfo(skb)->nr_frags;
909 vxge_debug_tx(VXGE_TRACE,
910 "%s: %s:%d skb = %p txdl_priv = %p "
911 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
912 __func__, __LINE__, skb, txdl_priv,
913 frg_cnt, (unsigned long long)dma_pointer);
915 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
916 first_frg_len);
918 frag = &skb_shinfo(skb)->frags[0];
919 for (i = 0; i < frg_cnt; i++) {
920 /* ignore 0 length fragment */
921 if (!frag->size)
922 continue;
924 dma_pointer = (u64) pci_map_page(fifo->pdev, frag->page,
925 frag->page_offset, frag->size,
926 PCI_DMA_TODEVICE);
928 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
929 goto _exit2;
930 vxge_debug_tx(VXGE_TRACE,
931 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
932 dev->name, __func__, __LINE__, i,
933 (unsigned long long)dma_pointer);
935 txdl_priv->dma_buffers[j] = dma_pointer;
936 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
937 frag->size);
938 frag += 1;
941 offload_type = vxge_offload_type(skb);
943 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
944 int mss = vxge_tcp_mss(skb);
945 if (mss) {
946 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
947 dev->name, __func__, __LINE__, mss);
948 vxge_hw_fifo_txdl_mss_set(dtr, mss);
949 } else {
950 vxge_assert(skb->len <=
951 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
952 vxge_assert(0);
953 goto _exit1;
957 if (skb->ip_summed == CHECKSUM_PARTIAL)
958 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
959 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
960 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
961 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
963 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
965 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
966 dev->name, __func__, __LINE__);
967 return NETDEV_TX_OK;
969 _exit2:
970 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
971 _exit1:
972 j = 0;
973 frag = &skb_shinfo(skb)->frags[0];
975 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
976 skb_headlen(skb), PCI_DMA_TODEVICE);
978 for (; j < i; j++) {
979 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
980 frag->size, PCI_DMA_TODEVICE);
981 frag += 1;
984 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
985 _exit0:
986 netif_tx_stop_queue(fifo->txq);
987 dev_kfree_skb(skb);
989 return NETDEV_TX_OK;
993 * vxge_rx_term
995 * Function will be called by hw function to abort all outstanding receive
996 * descriptors.
998 static void
999 vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1001 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1002 struct vxge_rx_priv *rx_priv =
1003 vxge_hw_ring_rxd_private_get(dtrh);
1005 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1006 ring->ndev->name, __func__, __LINE__);
1007 if (state != VXGE_HW_RXD_STATE_POSTED)
1008 return;
1010 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1011 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1013 dev_kfree_skb(rx_priv->skb);
1014 rx_priv->skb_data = NULL;
1016 vxge_debug_entryexit(VXGE_TRACE,
1017 "%s: %s:%d Exiting...",
1018 ring->ndev->name, __func__, __LINE__);
1022 * vxge_tx_term
1024 * Function will be called to abort all outstanding tx descriptors
1026 static void
1027 vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1029 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1030 skb_frag_t *frag;
1031 int i = 0, j, frg_cnt;
1032 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1033 struct sk_buff *skb = txd_priv->skb;
1035 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1037 if (state != VXGE_HW_TXDL_STATE_POSTED)
1038 return;
1040 /* check skb validity */
1041 vxge_assert(skb);
1042 frg_cnt = skb_shinfo(skb)->nr_frags;
1043 frag = &skb_shinfo(skb)->frags[0];
1045 /* for unfragmented skb */
1046 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1047 skb_headlen(skb), PCI_DMA_TODEVICE);
1049 for (j = 0; j < frg_cnt; j++) {
1050 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1051 frag->size, PCI_DMA_TODEVICE);
1052 frag += 1;
1055 dev_kfree_skb(skb);
1057 vxge_debug_entryexit(VXGE_TRACE,
1058 "%s:%d Exiting...", __func__, __LINE__);
1061 static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1063 struct list_head *entry, *next;
1064 u64 del_mac = 0;
1065 u8 *mac_address = (u8 *) (&del_mac);
1067 /* Copy the mac address to delete from the list */
1068 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1070 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1071 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1072 list_del(entry);
1073 kfree((struct vxge_mac_addrs *)entry);
1074 vpath->mac_addr_cnt--;
1076 /* Is this a multicast address */
1077 if (0x01 & mac->macaddr[0])
1078 vpath->mcast_addr_cnt--;
1079 return TRUE;
1083 return FALSE;
1086 /* delete a mac address from DA table */
1087 static enum vxge_hw_status
1088 vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1090 enum vxge_hw_status status = VXGE_HW_OK;
1091 struct vxge_vpath *vpath;
1093 vpath = &vdev->vpaths[mac->vpath_no];
1094 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1095 mac->macmask);
1096 if (status != VXGE_HW_OK) {
1097 vxge_debug_init(VXGE_ERR,
1098 "DA config delete entry failed for vpath:%d",
1099 vpath->device_id);
1100 } else
1101 vxge_mac_list_del(vpath, mac);
1102 return status;
1106 * vxge_set_multicast
1107 * @dev: pointer to the device structure
1109 * Entry point for multicast address enable/disable
1110 * This function is a driver entry point which gets called by the kernel
1111 * whenever multicast addresses must be enabled/disabled. This also gets
1112 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1113 * determine, if multicast address must be enabled or if promiscuous mode
1114 * is to be disabled etc.
1116 static void vxge_set_multicast(struct net_device *dev)
1118 struct netdev_hw_addr *ha;
1119 struct vxgedev *vdev;
1120 int i, mcast_cnt = 0;
1121 struct __vxge_hw_device *hldev;
1122 struct vxge_vpath *vpath;
1123 enum vxge_hw_status status = VXGE_HW_OK;
1124 struct macInfo mac_info;
1125 int vpath_idx = 0;
1126 struct vxge_mac_addrs *mac_entry;
1127 struct list_head *list_head;
1128 struct list_head *entry, *next;
1129 u8 *mac_address = NULL;
1131 vxge_debug_entryexit(VXGE_TRACE,
1132 "%s:%d", __func__, __LINE__);
1134 vdev = netdev_priv(dev);
1135 hldev = (struct __vxge_hw_device *)vdev->devh;
1137 if (unlikely(!is_vxge_card_up(vdev)))
1138 return;
1140 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1141 for (i = 0; i < vdev->no_of_vpath; i++) {
1142 vpath = &vdev->vpaths[i];
1143 vxge_assert(vpath->is_open);
1144 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1145 if (status != VXGE_HW_OK)
1146 vxge_debug_init(VXGE_ERR, "failed to enable "
1147 "multicast, status %d", status);
1148 vdev->all_multi_flg = 1;
1150 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1151 for (i = 0; i < vdev->no_of_vpath; i++) {
1152 vpath = &vdev->vpaths[i];
1153 vxge_assert(vpath->is_open);
1154 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1155 if (status != VXGE_HW_OK)
1156 vxge_debug_init(VXGE_ERR, "failed to disable "
1157 "multicast, status %d", status);
1158 vdev->all_multi_flg = 0;
1163 if (!vdev->config.addr_learn_en) {
1164 for (i = 0; i < vdev->no_of_vpath; i++) {
1165 vpath = &vdev->vpaths[i];
1166 vxge_assert(vpath->is_open);
1168 if (dev->flags & IFF_PROMISC)
1169 status = vxge_hw_vpath_promisc_enable(
1170 vpath->handle);
1171 else
1172 status = vxge_hw_vpath_promisc_disable(
1173 vpath->handle);
1174 if (status != VXGE_HW_OK)
1175 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1176 ", status %d", dev->flags&IFF_PROMISC ?
1177 "enable" : "disable", status);
1181 memset(&mac_info, 0, sizeof(struct macInfo));
1182 /* Update individual M_CAST address list */
1183 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
1184 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1185 list_head = &vdev->vpaths[0].mac_addr_list;
1186 if ((netdev_mc_count(dev) +
1187 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1188 vdev->vpaths[0].max_mac_addr_cnt)
1189 goto _set_all_mcast;
1191 /* Delete previous MC's */
1192 for (i = 0; i < mcast_cnt; i++) {
1193 list_for_each_safe(entry, next, list_head) {
1194 mac_entry = (struct vxge_mac_addrs *)entry;
1195 /* Copy the mac address to delete */
1196 mac_address = (u8 *)&mac_entry->macaddr;
1197 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1199 /* Is this a multicast address */
1200 if (0x01 & mac_info.macaddr[0]) {
1201 for (vpath_idx = 0; vpath_idx <
1202 vdev->no_of_vpath;
1203 vpath_idx++) {
1204 mac_info.vpath_no = vpath_idx;
1205 status = vxge_del_mac_addr(
1206 vdev,
1207 &mac_info);
1213 /* Add new ones */
1214 netdev_for_each_mc_addr(ha, dev) {
1215 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
1216 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1217 vpath_idx++) {
1218 mac_info.vpath_no = vpath_idx;
1219 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1220 status = vxge_add_mac_addr(vdev, &mac_info);
1221 if (status != VXGE_HW_OK) {
1222 vxge_debug_init(VXGE_ERR,
1223 "%s:%d Setting individual"
1224 "multicast address failed",
1225 __func__, __LINE__);
1226 goto _set_all_mcast;
1231 return;
1232 _set_all_mcast:
1233 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1234 /* Delete previous MC's */
1235 for (i = 0; i < mcast_cnt; i++) {
1236 list_for_each_safe(entry, next, list_head) {
1237 mac_entry = (struct vxge_mac_addrs *)entry;
1238 /* Copy the mac address to delete */
1239 mac_address = (u8 *)&mac_entry->macaddr;
1240 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1242 /* Is this a multicast address */
1243 if (0x01 & mac_info.macaddr[0])
1244 break;
1247 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1248 vpath_idx++) {
1249 mac_info.vpath_no = vpath_idx;
1250 status = vxge_del_mac_addr(vdev, &mac_info);
1254 /* Enable all multicast */
1255 for (i = 0; i < vdev->no_of_vpath; i++) {
1256 vpath = &vdev->vpaths[i];
1257 vxge_assert(vpath->is_open);
1259 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1260 if (status != VXGE_HW_OK) {
1261 vxge_debug_init(VXGE_ERR,
1262 "%s:%d Enabling all multicasts failed",
1263 __func__, __LINE__);
1265 vdev->all_multi_flg = 1;
1267 dev->flags |= IFF_ALLMULTI;
1270 vxge_debug_entryexit(VXGE_TRACE,
1271 "%s:%d Exiting...", __func__, __LINE__);
1275 * vxge_set_mac_addr
1276 * @dev: pointer to the device structure
1278 * Update entry "0" (default MAC addr)
1280 static int vxge_set_mac_addr(struct net_device *dev, void *p)
1282 struct sockaddr *addr = p;
1283 struct vxgedev *vdev;
1284 struct __vxge_hw_device *hldev;
1285 enum vxge_hw_status status = VXGE_HW_OK;
1286 struct macInfo mac_info_new, mac_info_old;
1287 int vpath_idx = 0;
1289 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1291 vdev = netdev_priv(dev);
1292 hldev = vdev->devh;
1294 if (!is_valid_ether_addr(addr->sa_data))
1295 return -EINVAL;
1297 memset(&mac_info_new, 0, sizeof(struct macInfo));
1298 memset(&mac_info_old, 0, sizeof(struct macInfo));
1300 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1301 __func__, __LINE__);
1303 /* Get the old address */
1304 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1306 /* Copy the new address */
1307 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1309 /* First delete the old mac address from all the vpaths
1310 as we can't specify the index while adding new mac address */
1311 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1312 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1313 if (!vpath->is_open) {
1314 /* This can happen when this interface is added/removed
1315 to the bonding interface. Delete this station address
1316 from the linked list */
1317 vxge_mac_list_del(vpath, &mac_info_old);
1319 /* Add this new address to the linked list
1320 for later restoring */
1321 vxge_mac_list_add(vpath, &mac_info_new);
1323 continue;
1325 /* Delete the station address */
1326 mac_info_old.vpath_no = vpath_idx;
1327 status = vxge_del_mac_addr(vdev, &mac_info_old);
1330 if (unlikely(!is_vxge_card_up(vdev))) {
1331 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1332 return VXGE_HW_OK;
1335 /* Set this mac address to all the vpaths */
1336 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1337 mac_info_new.vpath_no = vpath_idx;
1338 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1339 status = vxge_add_mac_addr(vdev, &mac_info_new);
1340 if (status != VXGE_HW_OK)
1341 return -EINVAL;
1344 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1346 return status;
1350 * vxge_vpath_intr_enable
1351 * @vdev: pointer to vdev
1352 * @vp_id: vpath for which to enable the interrupts
1354 * Enables the interrupts for the vpath
1356 static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1358 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1359 int msix_id = 0;
1360 int tim_msix_id[4] = {0, 1, 0, 0};
1361 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
1363 vxge_hw_vpath_intr_enable(vpath->handle);
1365 if (vdev->config.intr_type == INTA)
1366 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1367 else {
1368 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1369 alarm_msix_id);
1371 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1372 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1373 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1375 /* enable the alarm vector */
1376 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1377 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1378 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1383 * vxge_vpath_intr_disable
1384 * @vdev: pointer to vdev
1385 * @vp_id: vpath for which to disable the interrupts
1387 * Disables the interrupts for the vpath
1389 static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1391 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1392 struct __vxge_hw_device *hldev;
1393 int msix_id;
1395 hldev = pci_get_drvdata(vdev->pdev);
1397 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1399 vxge_hw_vpath_intr_disable(vpath->handle);
1401 if (vdev->config.intr_type == INTA)
1402 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1403 else {
1404 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1405 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1406 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1408 /* disable the alarm vector */
1409 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1410 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
1411 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1415 /* list all mac addresses from DA table */
1416 static enum vxge_hw_status
1417 vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1419 enum vxge_hw_status status = VXGE_HW_OK;
1420 unsigned char macmask[ETH_ALEN];
1421 unsigned char macaddr[ETH_ALEN];
1423 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1424 macaddr, macmask);
1425 if (status != VXGE_HW_OK) {
1426 vxge_debug_init(VXGE_ERR,
1427 "DA config list entry failed for vpath:%d",
1428 vpath->device_id);
1429 return status;
1432 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1433 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1434 macaddr, macmask);
1435 if (status != VXGE_HW_OK)
1436 break;
1439 return status;
1442 /* Store all mac addresses from the list to the DA table */
1443 static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1445 enum vxge_hw_status status = VXGE_HW_OK;
1446 struct macInfo mac_info;
1447 u8 *mac_address = NULL;
1448 struct list_head *entry, *next;
1450 memset(&mac_info, 0, sizeof(struct macInfo));
1452 if (vpath->is_open) {
1453 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1454 mac_address =
1455 (u8 *)&
1456 ((struct vxge_mac_addrs *)entry)->macaddr;
1457 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1458 ((struct vxge_mac_addrs *)entry)->state =
1459 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1460 /* does this mac address already exist in da table? */
1461 status = vxge_search_mac_addr_in_da_table(vpath,
1462 &mac_info);
1463 if (status != VXGE_HW_OK) {
1464 /* Add this mac address to the DA table */
1465 status = vxge_hw_vpath_mac_addr_add(
1466 vpath->handle, mac_info.macaddr,
1467 mac_info.macmask,
1468 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1469 if (status != VXGE_HW_OK) {
1470 vxge_debug_init(VXGE_ERR,
1471 "DA add entry failed for vpath:%d",
1472 vpath->device_id);
1473 ((struct vxge_mac_addrs *)entry)->state
1474 = VXGE_LL_MAC_ADDR_IN_LIST;
1480 return status;
1483 /* Store all vlan ids from the list to the vid table */
1484 static enum vxge_hw_status
1485 vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1487 enum vxge_hw_status status = VXGE_HW_OK;
1488 struct vxgedev *vdev = vpath->vdev;
1489 u16 vid;
1491 if (vdev->vlgrp && vpath->is_open) {
1493 for (vid = 0; vid < VLAN_N_VID; vid++) {
1494 if (!vlan_group_get_device(vdev->vlgrp, vid))
1495 continue;
1496 /* Add these vlan to the vid table */
1497 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1501 return status;
1505 * vxge_reset_vpath
1506 * @vdev: pointer to vdev
1507 * @vp_id: vpath to reset
1509 * Resets the vpath
1511 static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1513 enum vxge_hw_status status = VXGE_HW_OK;
1514 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1515 int ret = 0;
1517 /* check if device is down already */
1518 if (unlikely(!is_vxge_card_up(vdev)))
1519 return 0;
1521 /* is device reset already scheduled */
1522 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1523 return 0;
1525 if (vpath->handle) {
1526 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1527 if (is_vxge_card_up(vdev) &&
1528 vxge_hw_vpath_recover_from_reset(vpath->handle)
1529 != VXGE_HW_OK) {
1530 vxge_debug_init(VXGE_ERR,
1531 "vxge_hw_vpath_recover_from_reset"
1532 "failed for vpath:%d", vp_id);
1533 return status;
1535 } else {
1536 vxge_debug_init(VXGE_ERR,
1537 "vxge_hw_vpath_reset failed for"
1538 "vpath:%d", vp_id);
1539 return status;
1541 } else
1542 return VXGE_HW_FAIL;
1544 vxge_restore_vpath_mac_addr(vpath);
1545 vxge_restore_vpath_vid_table(vpath);
1547 /* Enable all broadcast */
1548 vxge_hw_vpath_bcast_enable(vpath->handle);
1550 /* Enable all multicast */
1551 if (vdev->all_multi_flg) {
1552 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1553 if (status != VXGE_HW_OK)
1554 vxge_debug_init(VXGE_ERR,
1555 "%s:%d Enabling multicast failed",
1556 __func__, __LINE__);
1559 /* Enable the interrupts */
1560 vxge_vpath_intr_enable(vdev, vp_id);
1562 smp_wmb();
1564 /* Enable the flow of traffic through the vpath */
1565 vxge_hw_vpath_enable(vpath->handle);
1567 smp_wmb();
1568 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1569 vpath->ring.last_status = VXGE_HW_OK;
1571 /* Vpath reset done */
1572 clear_bit(vp_id, &vdev->vp_reset);
1574 /* Start the vpath queue */
1575 if (netif_tx_queue_stopped(vpath->fifo.txq))
1576 netif_tx_wake_queue(vpath->fifo.txq);
1578 return ret;
1581 /* Configure CI */
1582 static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1584 int i = 0;
1586 /* Enable CI for RTI */
1587 if (vdev->config.intr_type == MSI_X) {
1588 for (i = 0; i < vdev->no_of_vpath; i++) {
1589 struct __vxge_hw_ring *hw_ring;
1591 hw_ring = vdev->vpaths[i].ring.handle;
1592 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1596 /* Enable CI for TTI */
1597 for (i = 0; i < vdev->no_of_vpath; i++) {
1598 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1599 vxge_hw_vpath_tti_ci_set(hw_fifo);
1601 * For Inta (with or without napi), Set CI ON for only one
1602 * vpath. (Have only one free running timer).
1604 if ((vdev->config.intr_type == INTA) && (i == 0))
1605 break;
1608 return;
1611 static int do_vxge_reset(struct vxgedev *vdev, int event)
1613 enum vxge_hw_status status;
1614 int ret = 0, vp_id, i;
1616 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1618 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1619 /* check if device is down already */
1620 if (unlikely(!is_vxge_card_up(vdev)))
1621 return 0;
1623 /* is reset already scheduled */
1624 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1625 return 0;
1628 if (event == VXGE_LL_FULL_RESET) {
1629 netif_carrier_off(vdev->ndev);
1631 /* wait for all the vpath reset to complete */
1632 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1633 while (test_bit(vp_id, &vdev->vp_reset))
1634 msleep(50);
1637 netif_carrier_on(vdev->ndev);
1639 /* if execution mode is set to debug, don't reset the adapter */
1640 if (unlikely(vdev->exec_mode)) {
1641 vxge_debug_init(VXGE_ERR,
1642 "%s: execution mode is debug, returning..",
1643 vdev->ndev->name);
1644 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1645 netif_tx_stop_all_queues(vdev->ndev);
1646 return 0;
1650 if (event == VXGE_LL_FULL_RESET) {
1651 vxge_hw_device_wait_receive_idle(vdev->devh);
1652 vxge_hw_device_intr_disable(vdev->devh);
1654 switch (vdev->cric_err_event) {
1655 case VXGE_HW_EVENT_UNKNOWN:
1656 netif_tx_stop_all_queues(vdev->ndev);
1657 vxge_debug_init(VXGE_ERR,
1658 "fatal: %s: Disabling device due to"
1659 "unknown error",
1660 vdev->ndev->name);
1661 ret = -EPERM;
1662 goto out;
1663 case VXGE_HW_EVENT_RESET_START:
1664 break;
1665 case VXGE_HW_EVENT_RESET_COMPLETE:
1666 case VXGE_HW_EVENT_LINK_DOWN:
1667 case VXGE_HW_EVENT_LINK_UP:
1668 case VXGE_HW_EVENT_ALARM_CLEARED:
1669 case VXGE_HW_EVENT_ECCERR:
1670 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1671 ret = -EPERM;
1672 goto out;
1673 case VXGE_HW_EVENT_FIFO_ERR:
1674 case VXGE_HW_EVENT_VPATH_ERR:
1675 break;
1676 case VXGE_HW_EVENT_CRITICAL_ERR:
1677 netif_tx_stop_all_queues(vdev->ndev);
1678 vxge_debug_init(VXGE_ERR,
1679 "fatal: %s: Disabling device due to"
1680 "serious error",
1681 vdev->ndev->name);
1682 /* SOP or device reset required */
1683 /* This event is not currently used */
1684 ret = -EPERM;
1685 goto out;
1686 case VXGE_HW_EVENT_SERR:
1687 netif_tx_stop_all_queues(vdev->ndev);
1688 vxge_debug_init(VXGE_ERR,
1689 "fatal: %s: Disabling device due to"
1690 "serious error",
1691 vdev->ndev->name);
1692 ret = -EPERM;
1693 goto out;
1694 case VXGE_HW_EVENT_SRPCIM_SERR:
1695 case VXGE_HW_EVENT_MRPCIM_SERR:
1696 ret = -EPERM;
1697 goto out;
1698 case VXGE_HW_EVENT_SLOT_FREEZE:
1699 netif_tx_stop_all_queues(vdev->ndev);
1700 vxge_debug_init(VXGE_ERR,
1701 "fatal: %s: Disabling device due to"
1702 "slot freeze",
1703 vdev->ndev->name);
1704 ret = -EPERM;
1705 goto out;
1706 default:
1707 break;
1712 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1713 netif_tx_stop_all_queues(vdev->ndev);
1715 if (event == VXGE_LL_FULL_RESET) {
1716 status = vxge_reset_all_vpaths(vdev);
1717 if (status != VXGE_HW_OK) {
1718 vxge_debug_init(VXGE_ERR,
1719 "fatal: %s: can not reset vpaths",
1720 vdev->ndev->name);
1721 ret = -EPERM;
1722 goto out;
1726 if (event == VXGE_LL_COMPL_RESET) {
1727 for (i = 0; i < vdev->no_of_vpath; i++)
1728 if (vdev->vpaths[i].handle) {
1729 if (vxge_hw_vpath_recover_from_reset(
1730 vdev->vpaths[i].handle)
1731 != VXGE_HW_OK) {
1732 vxge_debug_init(VXGE_ERR,
1733 "vxge_hw_vpath_recover_"
1734 "from_reset failed for vpath: "
1735 "%d", i);
1736 ret = -EPERM;
1737 goto out;
1739 } else {
1740 vxge_debug_init(VXGE_ERR,
1741 "vxge_hw_vpath_reset failed for "
1742 "vpath:%d", i);
1743 ret = -EPERM;
1744 goto out;
1748 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1749 /* Reprogram the DA table with populated mac addresses */
1750 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1751 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1752 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1755 /* enable vpath interrupts */
1756 for (i = 0; i < vdev->no_of_vpath; i++)
1757 vxge_vpath_intr_enable(vdev, i);
1759 vxge_hw_device_intr_enable(vdev->devh);
1761 smp_wmb();
1763 /* Indicate card up */
1764 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1766 /* Get the traffic to flow through the vpaths */
1767 for (i = 0; i < vdev->no_of_vpath; i++) {
1768 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1769 smp_wmb();
1770 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1773 netif_tx_wake_all_queues(vdev->ndev);
1776 /* configure CI */
1777 vxge_config_ci_for_tti_rti(vdev);
1779 out:
1780 vxge_debug_entryexit(VXGE_TRACE,
1781 "%s:%d Exiting...", __func__, __LINE__);
1783 /* Indicate reset done */
1784 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1785 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1786 return ret;
1790 * vxge_reset
1791 * @vdev: pointer to ll device
1793 * driver may reset the chip on events of serr, eccerr, etc
1795 static void vxge_reset(struct work_struct *work)
1797 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1799 if (!netif_running(vdev->ndev))
1800 return;
1802 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1806 * vxge_poll - Receive handler when Receive Polling is used.
1807 * @dev: pointer to the device structure.
1808 * @budget: Number of packets budgeted to be processed in this iteration.
1810 * This function comes into picture only if Receive side is being handled
1811 * through polling (called NAPI in linux). It mostly does what the normal
1812 * Rx interrupt handler does in terms of descriptor and packet processing
1813 * but not in an interrupt context. Also it will process a specified number
1814 * of packets at most in one iteration. This value is passed down by the
1815 * kernel as the function argument 'budget'.
1817 static int vxge_poll_msix(struct napi_struct *napi, int budget)
1819 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1820 int pkts_processed;
1821 int budget_org = budget;
1823 ring->budget = budget;
1824 ring->pkts_processed = 0;
1825 vxge_hw_vpath_poll_rx(ring->handle);
1826 pkts_processed = ring->pkts_processed;
1828 if (ring->pkts_processed < budget_org) {
1829 napi_complete(napi);
1831 /* Re enable the Rx interrupts for the vpath */
1832 vxge_hw_channel_msix_unmask(
1833 (struct __vxge_hw_channel *)ring->handle,
1834 ring->rx_vector_no);
1835 mmiowb();
1838 /* We are copying and returning the local variable, in case if after
1839 * clearing the msix interrupt above, if the interrupt fires right
1840 * away which can preempt this NAPI thread */
1841 return pkts_processed;
1844 static int vxge_poll_inta(struct napi_struct *napi, int budget)
1846 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1847 int pkts_processed = 0;
1848 int i;
1849 int budget_org = budget;
1850 struct vxge_ring *ring;
1852 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
1854 for (i = 0; i < vdev->no_of_vpath; i++) {
1855 ring = &vdev->vpaths[i].ring;
1856 ring->budget = budget;
1857 ring->pkts_processed = 0;
1858 vxge_hw_vpath_poll_rx(ring->handle);
1859 pkts_processed += ring->pkts_processed;
1860 budget -= ring->pkts_processed;
1861 if (budget <= 0)
1862 break;
1865 VXGE_COMPLETE_ALL_TX(vdev);
1867 if (pkts_processed < budget_org) {
1868 napi_complete(napi);
1869 /* Re enable the Rx interrupts for the ring */
1870 vxge_hw_device_unmask_all(hldev);
1871 vxge_hw_device_flush_io(hldev);
1874 return pkts_processed;
1877 #ifdef CONFIG_NET_POLL_CONTROLLER
1879 * vxge_netpoll - netpoll event handler entry point
1880 * @dev : pointer to the device structure.
1881 * Description:
1882 * This function will be called by upper layer to check for events on the
1883 * interface in situations where interrupts are disabled. It is used for
1884 * specific in-kernel networking tasks, such as remote consoles and kernel
1885 * debugging over the network (example netdump in RedHat).
1887 static void vxge_netpoll(struct net_device *dev)
1889 struct __vxge_hw_device *hldev;
1890 struct vxgedev *vdev;
1892 vdev = netdev_priv(dev);
1893 hldev = pci_get_drvdata(vdev->pdev);
1895 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1897 if (pci_channel_offline(vdev->pdev))
1898 return;
1900 disable_irq(dev->irq);
1901 vxge_hw_device_clear_tx_rx(hldev);
1903 vxge_hw_device_clear_tx_rx(hldev);
1904 VXGE_COMPLETE_ALL_RX(vdev);
1905 VXGE_COMPLETE_ALL_TX(vdev);
1907 enable_irq(dev->irq);
1909 vxge_debug_entryexit(VXGE_TRACE,
1910 "%s:%d Exiting...", __func__, __LINE__);
1912 #endif
1914 /* RTH configuration */
1915 static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1917 enum vxge_hw_status status = VXGE_HW_OK;
1918 struct vxge_hw_rth_hash_types hash_types;
1919 u8 itable[256] = {0}; /* indirection table */
1920 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1921 int index;
1924 * Filling
1925 * - itable with bucket numbers
1926 * - mtable with bucket-to-vpath mapping
1928 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1929 itable[index] = index;
1930 mtable[index] = index % vdev->no_of_vpath;
1933 /* set indirection table, bucket-to-vpath mapping */
1934 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1935 vdev->no_of_vpath,
1936 mtable, itable,
1937 vdev->config.rth_bkt_sz);
1938 if (status != VXGE_HW_OK) {
1939 vxge_debug_init(VXGE_ERR,
1940 "RTH indirection table configuration failed "
1941 "for vpath:%d", vdev->vpaths[0].device_id);
1942 return status;
1945 /* Fill RTH hash types */
1946 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1947 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1948 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1949 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1950 hash_types.hash_type_tcpipv6ex_en =
1951 vdev->config.rth_hash_type_tcpipv6ex;
1952 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1955 * Because the itable_set() method uses the active_table field
1956 * for the target virtual path the RTH config should be updated
1957 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1958 * when steering frames.
1960 for (index = 0; index < vdev->no_of_vpath; index++) {
1961 status = vxge_hw_vpath_rts_rth_set(
1962 vdev->vpaths[index].handle,
1963 vdev->config.rth_algorithm,
1964 &hash_types,
1965 vdev->config.rth_bkt_sz);
1966 if (status != VXGE_HW_OK) {
1967 vxge_debug_init(VXGE_ERR,
1968 "RTH configuration failed for vpath:%d",
1969 vdev->vpaths[index].device_id);
1970 return status;
1974 return status;
1977 /* reset vpaths */
1978 enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
1980 enum vxge_hw_status status = VXGE_HW_OK;
1981 struct vxge_vpath *vpath;
1982 int i;
1984 for (i = 0; i < vdev->no_of_vpath; i++) {
1985 vpath = &vdev->vpaths[i];
1986 if (vpath->handle) {
1987 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
1988 if (is_vxge_card_up(vdev) &&
1989 vxge_hw_vpath_recover_from_reset(
1990 vpath->handle) != VXGE_HW_OK) {
1991 vxge_debug_init(VXGE_ERR,
1992 "vxge_hw_vpath_recover_"
1993 "from_reset failed for vpath: "
1994 "%d", i);
1995 return status;
1997 } else {
1998 vxge_debug_init(VXGE_ERR,
1999 "vxge_hw_vpath_reset failed for "
2000 "vpath:%d", i);
2001 return status;
2006 return status;
2009 /* close vpaths */
2010 static void vxge_close_vpaths(struct vxgedev *vdev, int index)
2012 struct vxge_vpath *vpath;
2013 int i;
2015 for (i = index; i < vdev->no_of_vpath; i++) {
2016 vpath = &vdev->vpaths[i];
2018 if (vpath->handle && vpath->is_open) {
2019 vxge_hw_vpath_close(vpath->handle);
2020 vdev->stats.vpaths_open--;
2022 vpath->is_open = 0;
2023 vpath->handle = NULL;
2027 /* open vpaths */
2028 static int vxge_open_vpaths(struct vxgedev *vdev)
2030 struct vxge_hw_vpath_attr attr;
2031 enum vxge_hw_status status;
2032 struct vxge_vpath *vpath;
2033 u32 vp_id = 0;
2034 int i;
2036 for (i = 0; i < vdev->no_of_vpath; i++) {
2037 vpath = &vdev->vpaths[i];
2038 vxge_assert(vpath->is_configured);
2040 if (!vdev->titan1) {
2041 struct vxge_hw_vp_config *vcfg;
2042 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2044 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2045 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2046 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2047 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2048 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2049 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2050 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2051 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2052 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2055 attr.vp_id = vpath->device_id;
2056 attr.fifo_attr.callback = vxge_xmit_compl;
2057 attr.fifo_attr.txdl_term = vxge_tx_term;
2058 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2059 attr.fifo_attr.userdata = &vpath->fifo;
2061 attr.ring_attr.callback = vxge_rx_1b_compl;
2062 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2063 attr.ring_attr.rxd_term = vxge_rx_term;
2064 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2065 attr.ring_attr.userdata = &vpath->ring;
2067 vpath->ring.ndev = vdev->ndev;
2068 vpath->ring.pdev = vdev->pdev;
2070 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
2071 if (status == VXGE_HW_OK) {
2072 vpath->fifo.handle =
2073 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2074 vpath->ring.handle =
2075 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2076 vpath->fifo.tx_steering_type =
2077 vdev->config.tx_steering_type;
2078 vpath->fifo.ndev = vdev->ndev;
2079 vpath->fifo.pdev = vdev->pdev;
2080 if (vdev->config.tx_steering_type)
2081 vpath->fifo.txq =
2082 netdev_get_tx_queue(vdev->ndev, i);
2083 else
2084 vpath->fifo.txq =
2085 netdev_get_tx_queue(vdev->ndev, 0);
2086 vpath->fifo.indicate_max_pkts =
2087 vdev->config.fifo_indicate_max_pkts;
2088 vpath->fifo.tx_vector_no = 0;
2089 vpath->ring.rx_vector_no = 0;
2090 vpath->ring.rx_hwts = vdev->rx_hwts;
2091 vpath->is_open = 1;
2092 vdev->vp_handles[i] = vpath->handle;
2093 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
2094 vdev->stats.vpaths_open++;
2095 } else {
2096 vdev->stats.vpath_open_fail++;
2097 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2098 "open with status: %d",
2099 vdev->ndev->name, vpath->device_id,
2100 status);
2101 vxge_close_vpaths(vdev, 0);
2102 return -EPERM;
2105 vp_id = vpath->handle->vpath->vp_id;
2106 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2109 return VXGE_HW_OK;
2113 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2114 * if the interrupts are not within a range
2115 * @fifo: pointer to transmit fifo structure
2116 * Description: The function changes boundary timer and restriction timer
2117 * value depends on the traffic
2118 * Return Value: None
2120 static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2122 fifo->interrupt_count++;
2123 if (jiffies > fifo->jiffies + HZ / 100) {
2124 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2126 fifo->jiffies = jiffies;
2127 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2128 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2129 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2130 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2131 } else if (hw_fifo->rtimer != 0) {
2132 hw_fifo->rtimer = 0;
2133 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2135 fifo->interrupt_count = 0;
2140 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2141 * if the interrupts are not within a range
2142 * @ring: pointer to receive ring structure
2143 * Description: The function increases of decreases the packet counts within
2144 * the ranges of traffic utilization, if the interrupts due to this ring are
2145 * not within a fixed range.
2146 * Return Value: Nothing
2148 static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2150 ring->interrupt_count++;
2151 if (jiffies > ring->jiffies + HZ / 100) {
2152 struct __vxge_hw_ring *hw_ring = ring->handle;
2154 ring->jiffies = jiffies;
2155 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2156 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2157 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2158 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2159 } else if (hw_ring->rtimer != 0) {
2160 hw_ring->rtimer = 0;
2161 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2163 ring->interrupt_count = 0;
2168 * vxge_isr_napi
2169 * @irq: the irq of the device.
2170 * @dev_id: a void pointer to the hldev structure of the Titan device
2171 * @ptregs: pointer to the registers pushed on the stack.
2173 * This function is the ISR handler of the device when napi is enabled. It
2174 * identifies the reason for the interrupt and calls the relevant service
2175 * routines.
2177 static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2179 struct net_device *dev;
2180 struct __vxge_hw_device *hldev;
2181 u64 reason;
2182 enum vxge_hw_status status;
2183 struct vxgedev *vdev = (struct vxgedev *)dev_id;
2185 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2187 dev = vdev->ndev;
2188 hldev = pci_get_drvdata(vdev->pdev);
2190 if (pci_channel_offline(vdev->pdev))
2191 return IRQ_NONE;
2193 if (unlikely(!is_vxge_card_up(vdev)))
2194 return IRQ_HANDLED;
2196 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
2197 if (status == VXGE_HW_OK) {
2198 vxge_hw_device_mask_all(hldev);
2200 if (reason &
2201 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2202 vdev->vpaths_deployed >>
2203 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2205 vxge_hw_device_clear_tx_rx(hldev);
2206 napi_schedule(&vdev->napi);
2207 vxge_debug_intr(VXGE_TRACE,
2208 "%s:%d Exiting...", __func__, __LINE__);
2209 return IRQ_HANDLED;
2210 } else
2211 vxge_hw_device_unmask_all(hldev);
2212 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2213 (status == VXGE_HW_ERR_CRITICAL) ||
2214 (status == VXGE_HW_ERR_FIFO))) {
2215 vxge_hw_device_mask_all(hldev);
2216 vxge_hw_device_flush_io(hldev);
2217 return IRQ_HANDLED;
2218 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2219 return IRQ_HANDLED;
2221 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2222 return IRQ_NONE;
2225 #ifdef CONFIG_PCI_MSI
2227 static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
2229 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2231 adaptive_coalesce_tx_interrupts(fifo);
2233 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2234 fifo->tx_vector_no);
2236 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2237 fifo->tx_vector_no);
2239 VXGE_COMPLETE_VPATH_TX(fifo);
2241 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2242 fifo->tx_vector_no);
2244 mmiowb();
2246 return IRQ_HANDLED;
2249 static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
2251 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2253 adaptive_coalesce_rx_interrupts(ring);
2255 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2256 ring->rx_vector_no);
2258 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2259 ring->rx_vector_no);
2261 napi_schedule(&ring->napi);
2262 return IRQ_HANDLED;
2265 static irqreturn_t
2266 vxge_alarm_msix_handle(int irq, void *dev_id)
2268 int i;
2269 enum vxge_hw_status status;
2270 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2271 struct vxgedev *vdev = vpath->vdev;
2272 int msix_id = (vpath->handle->vpath->vp_id *
2273 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2275 for (i = 0; i < vdev->no_of_vpath; i++) {
2276 /* Reduce the chance of losing alarm interrupts by masking
2277 * the vector. A pending bit will be set if an alarm is
2278 * generated and on unmask the interrupt will be fired.
2280 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
2281 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2282 mmiowb();
2284 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2285 vdev->exec_mode);
2286 if (status == VXGE_HW_OK) {
2287 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2288 msix_id);
2289 mmiowb();
2290 continue;
2292 vxge_debug_intr(VXGE_ERR,
2293 "%s: vxge_hw_vpath_alarm_process failed %x ",
2294 VXGE_DRIVER_NAME, status);
2296 return IRQ_HANDLED;
2299 static int vxge_alloc_msix(struct vxgedev *vdev)
2301 int j, i, ret = 0;
2302 int msix_intr_vect = 0, temp;
2303 vdev->intr_cnt = 0;
2305 start:
2306 /* Tx/Rx MSIX Vectors count */
2307 vdev->intr_cnt = vdev->no_of_vpath * 2;
2309 /* Alarm MSIX Vectors count */
2310 vdev->intr_cnt++;
2312 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2313 GFP_KERNEL);
2314 if (!vdev->entries) {
2315 vxge_debug_init(VXGE_ERR,
2316 "%s: memory allocation failed",
2317 VXGE_DRIVER_NAME);
2318 ret = -ENOMEM;
2319 goto alloc_entries_failed;
2322 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2323 sizeof(struct vxge_msix_entry),
2324 GFP_KERNEL);
2325 if (!vdev->vxge_entries) {
2326 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2327 VXGE_DRIVER_NAME);
2328 ret = -ENOMEM;
2329 goto alloc_vxge_entries_failed;
2332 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
2334 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2336 /* Initialize the fifo vector */
2337 vdev->entries[j].entry = msix_intr_vect;
2338 vdev->vxge_entries[j].entry = msix_intr_vect;
2339 vdev->vxge_entries[j].in_use = 0;
2340 j++;
2342 /* Initialize the ring vector */
2343 vdev->entries[j].entry = msix_intr_vect + 1;
2344 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2345 vdev->vxge_entries[j].in_use = 0;
2346 j++;
2349 /* Initialize the alarm vector */
2350 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2351 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
2352 vdev->vxge_entries[j].in_use = 0;
2354 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
2355 if (ret > 0) {
2356 vxge_debug_init(VXGE_ERR,
2357 "%s: MSI-X enable failed for %d vectors, ret: %d",
2358 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
2359 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2360 ret = -ENODEV;
2361 goto enable_msix_failed;
2364 kfree(vdev->entries);
2365 kfree(vdev->vxge_entries);
2366 vdev->entries = NULL;
2367 vdev->vxge_entries = NULL;
2368 /* Try with less no of vector by reducing no of vpaths count */
2369 temp = (ret - 1)/2;
2370 vxge_close_vpaths(vdev, temp);
2371 vdev->no_of_vpath = temp;
2372 goto start;
2373 } else if (ret < 0) {
2374 ret = -ENODEV;
2375 goto enable_msix_failed;
2377 return 0;
2379 enable_msix_failed:
2380 kfree(vdev->vxge_entries);
2381 alloc_vxge_entries_failed:
2382 kfree(vdev->entries);
2383 alloc_entries_failed:
2384 return ret;
2387 static int vxge_enable_msix(struct vxgedev *vdev)
2390 int i, ret = 0;
2391 /* 0 - Tx, 1 - Rx */
2392 int tim_msix_id[4] = {0, 1, 0, 0};
2394 vdev->intr_cnt = 0;
2396 /* allocate msix vectors */
2397 ret = vxge_alloc_msix(vdev);
2398 if (!ret) {
2399 for (i = 0; i < vdev->no_of_vpath; i++) {
2400 struct vxge_vpath *vpath = &vdev->vpaths[i];
2402 /* If fifo or ring are not enabled, the MSIX vector for
2403 * it should be set to 0.
2405 vpath->ring.rx_vector_no = (vpath->device_id *
2406 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
2408 vpath->fifo.tx_vector_no = (vpath->device_id *
2409 VXGE_HW_VPATH_MSIX_ACTIVE);
2411 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2412 VXGE_ALARM_MSIX_ID);
2416 return ret;
2419 static void vxge_rem_msix_isr(struct vxgedev *vdev)
2421 int intr_cnt;
2423 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
2424 intr_cnt++) {
2425 if (vdev->vxge_entries[intr_cnt].in_use) {
2426 synchronize_irq(vdev->entries[intr_cnt].vector);
2427 free_irq(vdev->entries[intr_cnt].vector,
2428 vdev->vxge_entries[intr_cnt].arg);
2429 vdev->vxge_entries[intr_cnt].in_use = 0;
2433 kfree(vdev->entries);
2434 kfree(vdev->vxge_entries);
2435 vdev->entries = NULL;
2436 vdev->vxge_entries = NULL;
2438 if (vdev->config.intr_type == MSI_X)
2439 pci_disable_msix(vdev->pdev);
2441 #endif
2443 static void vxge_rem_isr(struct vxgedev *vdev)
2445 struct __vxge_hw_device *hldev;
2446 hldev = pci_get_drvdata(vdev->pdev);
2448 #ifdef CONFIG_PCI_MSI
2449 if (vdev->config.intr_type == MSI_X) {
2450 vxge_rem_msix_isr(vdev);
2451 } else
2452 #endif
2453 if (vdev->config.intr_type == INTA) {
2454 synchronize_irq(vdev->pdev->irq);
2455 free_irq(vdev->pdev->irq, vdev);
2459 static int vxge_add_isr(struct vxgedev *vdev)
2461 int ret = 0;
2462 #ifdef CONFIG_PCI_MSI
2463 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2464 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2466 if (vdev->config.intr_type == MSI_X)
2467 ret = vxge_enable_msix(vdev);
2469 if (ret) {
2470 vxge_debug_init(VXGE_ERR,
2471 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2472 vxge_debug_init(VXGE_ERR,
2473 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2474 vdev->config.intr_type = INTA;
2477 if (vdev->config.intr_type == MSI_X) {
2478 for (intr_idx = 0;
2479 intr_idx < (vdev->no_of_vpath *
2480 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2482 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2483 irq_req = 0;
2485 switch (msix_idx) {
2486 case 0:
2487 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2488 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2489 vdev->ndev->name,
2490 vdev->entries[intr_cnt].entry,
2491 pci_fun, vp_idx);
2492 ret = request_irq(
2493 vdev->entries[intr_cnt].vector,
2494 vxge_tx_msix_handle, 0,
2495 vdev->desc[intr_cnt],
2496 &vdev->vpaths[vp_idx].fifo);
2497 vdev->vxge_entries[intr_cnt].arg =
2498 &vdev->vpaths[vp_idx].fifo;
2499 irq_req = 1;
2500 break;
2501 case 1:
2502 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2503 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2504 vdev->ndev->name,
2505 vdev->entries[intr_cnt].entry,
2506 pci_fun, vp_idx);
2507 ret = request_irq(
2508 vdev->entries[intr_cnt].vector,
2509 vxge_rx_msix_napi_handle,
2511 vdev->desc[intr_cnt],
2512 &vdev->vpaths[vp_idx].ring);
2513 vdev->vxge_entries[intr_cnt].arg =
2514 &vdev->vpaths[vp_idx].ring;
2515 irq_req = 1;
2516 break;
2519 if (ret) {
2520 vxge_debug_init(VXGE_ERR,
2521 "%s: MSIX - %d Registration failed",
2522 vdev->ndev->name, intr_cnt);
2523 vxge_rem_msix_isr(vdev);
2524 vdev->config.intr_type = INTA;
2525 vxge_debug_init(VXGE_ERR,
2526 "%s: Defaulting to INTA"
2527 , vdev->ndev->name);
2528 goto INTA_MODE;
2531 if (irq_req) {
2532 /* We requested for this msix interrupt */
2533 vdev->vxge_entries[intr_cnt].in_use = 1;
2534 msix_idx += vdev->vpaths[vp_idx].device_id *
2535 VXGE_HW_VPATH_MSIX_ACTIVE;
2536 vxge_hw_vpath_msix_unmask(
2537 vdev->vpaths[vp_idx].handle,
2538 msix_idx);
2539 intr_cnt++;
2542 /* Point to next vpath handler */
2543 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2544 (vp_idx < (vdev->no_of_vpath - 1)))
2545 vp_idx++;
2548 intr_cnt = vdev->no_of_vpath * 2;
2549 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2550 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2551 vdev->ndev->name,
2552 vdev->entries[intr_cnt].entry,
2553 pci_fun);
2554 /* For Alarm interrupts */
2555 ret = request_irq(vdev->entries[intr_cnt].vector,
2556 vxge_alarm_msix_handle, 0,
2557 vdev->desc[intr_cnt],
2558 &vdev->vpaths[0]);
2559 if (ret) {
2560 vxge_debug_init(VXGE_ERR,
2561 "%s: MSIX - %d Registration failed",
2562 vdev->ndev->name, intr_cnt);
2563 vxge_rem_msix_isr(vdev);
2564 vdev->config.intr_type = INTA;
2565 vxge_debug_init(VXGE_ERR,
2566 "%s: Defaulting to INTA",
2567 vdev->ndev->name);
2568 goto INTA_MODE;
2571 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2572 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
2573 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2574 msix_idx);
2575 vdev->vxge_entries[intr_cnt].in_use = 1;
2576 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
2578 INTA_MODE:
2579 #endif
2581 if (vdev->config.intr_type == INTA) {
2582 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2583 "%s:vxge:INTA", vdev->ndev->name);
2584 vxge_hw_device_set_intr_type(vdev->devh,
2585 VXGE_HW_INTR_MODE_IRQLINE);
2587 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2589 ret = request_irq((int) vdev->pdev->irq,
2590 vxge_isr_napi,
2591 IRQF_SHARED, vdev->desc[0], vdev);
2592 if (ret) {
2593 vxge_debug_init(VXGE_ERR,
2594 "%s %s-%d: ISR registration failed",
2595 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2596 return -ENODEV;
2598 vxge_debug_init(VXGE_TRACE,
2599 "new %s-%d line allocated",
2600 "IRQ", vdev->pdev->irq);
2603 return VXGE_HW_OK;
2606 static void vxge_poll_vp_reset(unsigned long data)
2608 struct vxgedev *vdev = (struct vxgedev *)data;
2609 int i, j = 0;
2611 for (i = 0; i < vdev->no_of_vpath; i++) {
2612 if (test_bit(i, &vdev->vp_reset)) {
2613 vxge_reset_vpath(vdev, i);
2614 j++;
2617 if (j && (vdev->config.intr_type != MSI_X)) {
2618 vxge_hw_device_unmask_all(vdev->devh);
2619 vxge_hw_device_flush_io(vdev->devh);
2622 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2625 static void vxge_poll_vp_lockup(unsigned long data)
2627 struct vxgedev *vdev = (struct vxgedev *)data;
2628 enum vxge_hw_status status = VXGE_HW_OK;
2629 struct vxge_vpath *vpath;
2630 struct vxge_ring *ring;
2631 int i;
2633 for (i = 0; i < vdev->no_of_vpath; i++) {
2634 ring = &vdev->vpaths[i].ring;
2635 /* Did this vpath received any packets */
2636 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2637 status = vxge_hw_vpath_check_leak(ring->handle);
2639 /* Did it received any packets last time */
2640 if ((VXGE_HW_FAIL == status) &&
2641 (VXGE_HW_FAIL == ring->last_status)) {
2643 /* schedule vpath reset */
2644 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2645 vpath = &vdev->vpaths[i];
2647 /* disable interrupts for this vpath */
2648 vxge_vpath_intr_disable(vdev, i);
2650 /* stop the queue for this vpath */
2651 netif_tx_stop_queue(vpath->fifo.txq);
2652 continue;
2656 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2657 ring->last_status = status;
2660 /* Check every 1 milli second */
2661 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2664 static u32 vxge_fix_features(struct net_device *dev, u32 features)
2666 u32 changed = dev->features ^ features;
2668 /* Enabling RTH requires some of the logic in vxge_device_register and a
2669 * vpath reset. Due to these restrictions, only allow modification
2670 * while the interface is down.
2672 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2673 features ^= NETIF_F_RXHASH;
2675 return features;
2678 static int vxge_set_features(struct net_device *dev, u32 features)
2680 struct vxgedev *vdev = netdev_priv(dev);
2681 u32 changed = dev->features ^ features;
2683 if (!(changed & NETIF_F_RXHASH))
2684 return 0;
2686 /* !netif_running() ensured by vxge_fix_features() */
2688 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2689 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2690 dev->features = features ^ NETIF_F_RXHASH;
2691 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2692 return -EIO;
2695 return 0;
2699 * vxge_open
2700 * @dev: pointer to the device structure.
2702 * This function is the open entry point of the driver. It mainly calls a
2703 * function to allocate Rx buffers and inserts them into the buffer
2704 * descriptors and then enables the Rx part of the NIC.
2705 * Return value: '0' on success and an appropriate (-)ve integer as
2706 * defined in errno.h file on failure.
2708 static int vxge_open(struct net_device *dev)
2710 enum vxge_hw_status status;
2711 struct vxgedev *vdev;
2712 struct __vxge_hw_device *hldev;
2713 struct vxge_vpath *vpath;
2714 int ret = 0;
2715 int i;
2716 u64 val64, function_mode;
2718 vxge_debug_entryexit(VXGE_TRACE,
2719 "%s: %s:%d", dev->name, __func__, __LINE__);
2721 vdev = netdev_priv(dev);
2722 hldev = pci_get_drvdata(vdev->pdev);
2723 function_mode = vdev->config.device_hw_info.function_mode;
2725 /* make sure you have link off by default every time Nic is
2726 * initialized */
2727 netif_carrier_off(dev);
2729 /* Open VPATHs */
2730 status = vxge_open_vpaths(vdev);
2731 if (status != VXGE_HW_OK) {
2732 vxge_debug_init(VXGE_ERR,
2733 "%s: fatal: Vpath open failed", vdev->ndev->name);
2734 ret = -EPERM;
2735 goto out0;
2738 vdev->mtu = dev->mtu;
2740 status = vxge_add_isr(vdev);
2741 if (status != VXGE_HW_OK) {
2742 vxge_debug_init(VXGE_ERR,
2743 "%s: fatal: ISR add failed", dev->name);
2744 ret = -EPERM;
2745 goto out1;
2748 if (vdev->config.intr_type != MSI_X) {
2749 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2750 vdev->config.napi_weight);
2751 napi_enable(&vdev->napi);
2752 for (i = 0; i < vdev->no_of_vpath; i++) {
2753 vpath = &vdev->vpaths[i];
2754 vpath->ring.napi_p = &vdev->napi;
2756 } else {
2757 for (i = 0; i < vdev->no_of_vpath; i++) {
2758 vpath = &vdev->vpaths[i];
2759 netif_napi_add(dev, &vpath->ring.napi,
2760 vxge_poll_msix, vdev->config.napi_weight);
2761 napi_enable(&vpath->ring.napi);
2762 vpath->ring.napi_p = &vpath->ring.napi;
2766 /* configure RTH */
2767 if (vdev->config.rth_steering) {
2768 status = vxge_rth_configure(vdev);
2769 if (status != VXGE_HW_OK) {
2770 vxge_debug_init(VXGE_ERR,
2771 "%s: fatal: RTH configuration failed",
2772 dev->name);
2773 ret = -EPERM;
2774 goto out2;
2777 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2778 hldev->config.rth_en ? "enabled" : "disabled");
2780 for (i = 0; i < vdev->no_of_vpath; i++) {
2781 vpath = &vdev->vpaths[i];
2783 /* set initial mtu before enabling the device */
2784 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
2785 if (status != VXGE_HW_OK) {
2786 vxge_debug_init(VXGE_ERR,
2787 "%s: fatal: can not set new MTU", dev->name);
2788 ret = -EPERM;
2789 goto out2;
2793 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2794 vxge_debug_init(vdev->level_trace,
2795 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2796 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2798 /* Restore the DA, VID table and also multicast and promiscuous mode
2799 * states
2801 if (vdev->all_multi_flg) {
2802 for (i = 0; i < vdev->no_of_vpath; i++) {
2803 vpath = &vdev->vpaths[i];
2804 vxge_restore_vpath_mac_addr(vpath);
2805 vxge_restore_vpath_vid_table(vpath);
2807 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2808 if (status != VXGE_HW_OK)
2809 vxge_debug_init(VXGE_ERR,
2810 "%s:%d Enabling multicast failed",
2811 __func__, __LINE__);
2815 /* Enable vpath to sniff all unicast/multicast traffic that not
2816 * addressed to them. We allow promiscuous mode for PF only
2819 val64 = 0;
2820 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2821 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2823 vxge_hw_mgmt_reg_write(vdev->devh,
2824 vxge_hw_mgmt_reg_type_mrpcim,
2826 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2827 rxmac_authorize_all_addr),
2828 val64);
2830 vxge_hw_mgmt_reg_write(vdev->devh,
2831 vxge_hw_mgmt_reg_type_mrpcim,
2833 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2834 rxmac_authorize_all_vid),
2835 val64);
2837 vxge_set_multicast(dev);
2839 /* Enabling Bcast and mcast for all vpath */
2840 for (i = 0; i < vdev->no_of_vpath; i++) {
2841 vpath = &vdev->vpaths[i];
2842 status = vxge_hw_vpath_bcast_enable(vpath->handle);
2843 if (status != VXGE_HW_OK)
2844 vxge_debug_init(VXGE_ERR,
2845 "%s : Can not enable bcast for vpath "
2846 "id %d", dev->name, i);
2847 if (vdev->config.addr_learn_en) {
2848 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2849 if (status != VXGE_HW_OK)
2850 vxge_debug_init(VXGE_ERR,
2851 "%s : Can not enable mcast for vpath "
2852 "id %d", dev->name, i);
2856 vxge_hw_device_setpause_data(vdev->devh, 0,
2857 vdev->config.tx_pause_enable,
2858 vdev->config.rx_pause_enable);
2860 if (vdev->vp_reset_timer.function == NULL)
2861 vxge_os_timer(vdev->vp_reset_timer,
2862 vxge_poll_vp_reset, vdev, (HZ/2));
2864 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2865 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2866 vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
2867 HZ / 2);
2869 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2871 smp_wmb();
2873 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2874 netif_carrier_on(vdev->ndev);
2875 netdev_notice(vdev->ndev, "Link Up\n");
2876 vdev->stats.link_up++;
2879 vxge_hw_device_intr_enable(vdev->devh);
2881 smp_wmb();
2883 for (i = 0; i < vdev->no_of_vpath; i++) {
2884 vpath = &vdev->vpaths[i];
2886 vxge_hw_vpath_enable(vpath->handle);
2887 smp_wmb();
2888 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
2891 netif_tx_start_all_queues(vdev->ndev);
2893 /* configure CI */
2894 vxge_config_ci_for_tti_rti(vdev);
2896 goto out0;
2898 out2:
2899 vxge_rem_isr(vdev);
2901 /* Disable napi */
2902 if (vdev->config.intr_type != MSI_X)
2903 napi_disable(&vdev->napi);
2904 else {
2905 for (i = 0; i < vdev->no_of_vpath; i++)
2906 napi_disable(&vdev->vpaths[i].ring.napi);
2909 out1:
2910 vxge_close_vpaths(vdev, 0);
2911 out0:
2912 vxge_debug_entryexit(VXGE_TRACE,
2913 "%s: %s:%d Exiting...",
2914 dev->name, __func__, __LINE__);
2915 return ret;
2918 /* Loop through the mac address list and delete all the entries */
2919 static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2922 struct list_head *entry, *next;
2923 if (list_empty(&vpath->mac_addr_list))
2924 return;
2926 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2927 list_del(entry);
2928 kfree((struct vxge_mac_addrs *)entry);
2932 static void vxge_napi_del_all(struct vxgedev *vdev)
2934 int i;
2935 if (vdev->config.intr_type != MSI_X)
2936 netif_napi_del(&vdev->napi);
2937 else {
2938 for (i = 0; i < vdev->no_of_vpath; i++)
2939 netif_napi_del(&vdev->vpaths[i].ring.napi);
2943 static int do_vxge_close(struct net_device *dev, int do_io)
2945 enum vxge_hw_status status;
2946 struct vxgedev *vdev;
2947 struct __vxge_hw_device *hldev;
2948 int i;
2949 u64 val64, vpath_vector;
2950 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2951 dev->name, __func__, __LINE__);
2953 vdev = netdev_priv(dev);
2954 hldev = pci_get_drvdata(vdev->pdev);
2956 if (unlikely(!is_vxge_card_up(vdev)))
2957 return 0;
2959 /* If vxge_handle_crit_err task is executing,
2960 * wait till it completes. */
2961 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2962 msleep(50);
2964 if (do_io) {
2965 /* Put the vpath back in normal mode */
2966 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2967 status = vxge_hw_mgmt_reg_read(vdev->devh,
2968 vxge_hw_mgmt_reg_type_mrpcim,
2970 (ulong)offsetof(
2971 struct vxge_hw_mrpcim_reg,
2972 rts_mgr_cbasin_cfg),
2973 &val64);
2974 if (status == VXGE_HW_OK) {
2975 val64 &= ~vpath_vector;
2976 status = vxge_hw_mgmt_reg_write(vdev->devh,
2977 vxge_hw_mgmt_reg_type_mrpcim,
2979 (ulong)offsetof(
2980 struct vxge_hw_mrpcim_reg,
2981 rts_mgr_cbasin_cfg),
2982 val64);
2985 /* Remove the function 0 from promiscuous mode */
2986 vxge_hw_mgmt_reg_write(vdev->devh,
2987 vxge_hw_mgmt_reg_type_mrpcim,
2989 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2990 rxmac_authorize_all_addr),
2993 vxge_hw_mgmt_reg_write(vdev->devh,
2994 vxge_hw_mgmt_reg_type_mrpcim,
2996 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2997 rxmac_authorize_all_vid),
3000 smp_wmb();
3003 if (vdev->titan1)
3004 del_timer_sync(&vdev->vp_lockup_timer);
3006 del_timer_sync(&vdev->vp_reset_timer);
3008 if (do_io)
3009 vxge_hw_device_wait_receive_idle(hldev);
3011 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3013 /* Disable napi */
3014 if (vdev->config.intr_type != MSI_X)
3015 napi_disable(&vdev->napi);
3016 else {
3017 for (i = 0; i < vdev->no_of_vpath; i++)
3018 napi_disable(&vdev->vpaths[i].ring.napi);
3021 netif_carrier_off(vdev->ndev);
3022 netdev_notice(vdev->ndev, "Link Down\n");
3023 netif_tx_stop_all_queues(vdev->ndev);
3025 /* Note that at this point xmit() is stopped by upper layer */
3026 if (do_io)
3027 vxge_hw_device_intr_disable(vdev->devh);
3029 vxge_rem_isr(vdev);
3031 vxge_napi_del_all(vdev);
3033 if (do_io)
3034 vxge_reset_all_vpaths(vdev);
3036 vxge_close_vpaths(vdev, 0);
3038 vxge_debug_entryexit(VXGE_TRACE,
3039 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3041 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3043 return 0;
3047 * vxge_close
3048 * @dev: device pointer.
3050 * This is the stop entry point of the driver. It needs to undo exactly
3051 * whatever was done by the open entry point, thus it's usually referred to
3052 * as the close function.Among other things this function mainly stops the
3053 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3054 * Return value: '0' on success and an appropriate (-)ve integer as
3055 * defined in errno.h file on failure.
3057 static int vxge_close(struct net_device *dev)
3059 do_vxge_close(dev, 1);
3060 return 0;
3064 * vxge_change_mtu
3065 * @dev: net device pointer.
3066 * @new_mtu :the new MTU size for the device.
3068 * A driver entry point to change MTU size for the device. Before changing
3069 * the MTU the device must be stopped.
3071 static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3073 struct vxgedev *vdev = netdev_priv(dev);
3075 vxge_debug_entryexit(vdev->level_trace,
3076 "%s:%d", __func__, __LINE__);
3077 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3078 vxge_debug_init(vdev->level_err,
3079 "%s: mtu size is invalid", dev->name);
3080 return -EPERM;
3083 /* check if device is down already */
3084 if (unlikely(!is_vxge_card_up(vdev))) {
3085 /* just store new value, will use later on open() */
3086 dev->mtu = new_mtu;
3087 vxge_debug_init(vdev->level_err,
3088 "%s", "device is down on MTU change");
3089 return 0;
3092 vxge_debug_init(vdev->level_trace,
3093 "trying to apply new MTU %d", new_mtu);
3095 if (vxge_close(dev))
3096 return -EIO;
3098 dev->mtu = new_mtu;
3099 vdev->mtu = new_mtu;
3101 if (vxge_open(dev))
3102 return -EIO;
3104 vxge_debug_init(vdev->level_trace,
3105 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3107 vxge_debug_entryexit(vdev->level_trace,
3108 "%s:%d Exiting...", __func__, __LINE__);
3110 return 0;
3114 * vxge_get_stats64
3115 * @dev: pointer to the device structure
3116 * @stats: pointer to struct rtnl_link_stats64
3119 static struct rtnl_link_stats64 *
3120 vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
3122 struct vxgedev *vdev = netdev_priv(dev);
3123 int k;
3125 /* net_stats already zeroed by caller */
3126 for (k = 0; k < vdev->no_of_vpath; k++) {
3127 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3128 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3129 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3130 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3131 net_stats->rx_dropped += vdev->vpaths[k].ring.stats.rx_dropped;
3132 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3133 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3134 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3137 return net_stats;
3140 static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
3142 enum vxge_hw_status status;
3143 u64 val64;
3145 /* Timestamp is passed to the driver via the FCS, therefore we
3146 * must disable the FCS stripping by the adapter. Since this is
3147 * required for the driver to load (due to a hardware bug),
3148 * there is no need to do anything special here.
3150 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3151 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3152 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
3154 status = vxge_hw_mgmt_reg_write(devh,
3155 vxge_hw_mgmt_reg_type_mrpcim,
3157 offsetof(struct vxge_hw_mrpcim_reg,
3158 xmac_timestamp),
3159 val64);
3160 vxge_hw_device_flush_io(devh);
3161 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
3162 return status;
3165 static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3167 struct hwtstamp_config config;
3168 int i;
3170 if (copy_from_user(&config, data, sizeof(config)))
3171 return -EFAULT;
3173 /* reserved for future extensions */
3174 if (config.flags)
3175 return -EINVAL;
3177 /* Transmit HW Timestamp not supported */
3178 switch (config.tx_type) {
3179 case HWTSTAMP_TX_OFF:
3180 break;
3181 case HWTSTAMP_TX_ON:
3182 default:
3183 return -ERANGE;
3186 switch (config.rx_filter) {
3187 case HWTSTAMP_FILTER_NONE:
3188 vdev->rx_hwts = 0;
3189 config.rx_filter = HWTSTAMP_FILTER_NONE;
3190 break;
3192 case HWTSTAMP_FILTER_ALL:
3193 case HWTSTAMP_FILTER_SOME:
3194 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3195 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3196 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3197 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3198 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3199 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3200 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3201 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3202 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3203 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3204 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3205 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
3206 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
3207 return -EFAULT;
3209 vdev->rx_hwts = 1;
3210 config.rx_filter = HWTSTAMP_FILTER_ALL;
3211 break;
3213 default:
3214 return -ERANGE;
3217 for (i = 0; i < vdev->no_of_vpath; i++)
3218 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3220 if (copy_to_user(data, &config, sizeof(config)))
3221 return -EFAULT;
3223 return 0;
3227 * vxge_ioctl
3228 * @dev: Device pointer.
3229 * @ifr: An IOCTL specific structure, that can contain a pointer to
3230 * a proprietary structure used to pass information to the driver.
3231 * @cmd: This is used to distinguish between the different commands that
3232 * can be passed to the IOCTL functions.
3234 * Entry point for the Ioctl.
3236 static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3238 struct vxgedev *vdev = netdev_priv(dev);
3239 int ret;
3241 switch (cmd) {
3242 case SIOCSHWTSTAMP:
3243 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3244 if (ret)
3245 return ret;
3246 break;
3247 default:
3248 return -EOPNOTSUPP;
3251 return 0;
3255 * vxge_tx_watchdog
3256 * @dev: pointer to net device structure
3258 * Watchdog for transmit side.
3259 * This function is triggered if the Tx Queue is stopped
3260 * for a pre-defined amount of time when the Interface is still up.
3262 static void vxge_tx_watchdog(struct net_device *dev)
3264 struct vxgedev *vdev;
3266 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3268 vdev = netdev_priv(dev);
3270 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3272 schedule_work(&vdev->reset_task);
3273 vxge_debug_entryexit(VXGE_TRACE,
3274 "%s:%d Exiting...", __func__, __LINE__);
3278 * vxge_vlan_rx_register
3279 * @dev: net device pointer.
3280 * @grp: vlan group
3282 * Vlan group registration
3284 static void
3285 vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3287 struct vxgedev *vdev;
3288 struct vxge_vpath *vpath;
3289 int vp;
3290 u64 vid;
3291 enum vxge_hw_status status;
3292 int i;
3294 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3296 vdev = netdev_priv(dev);
3298 vpath = &vdev->vpaths[0];
3299 if ((NULL == grp) && (vpath->is_open)) {
3300 /* Get the first vlan */
3301 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3303 while (status == VXGE_HW_OK) {
3305 /* Delete this vlan from the vid table */
3306 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3307 vpath = &vdev->vpaths[vp];
3308 if (!vpath->is_open)
3309 continue;
3311 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3314 /* Get the next vlan to be deleted */
3315 vpath = &vdev->vpaths[0];
3316 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3320 vdev->vlgrp = grp;
3322 for (i = 0; i < vdev->no_of_vpath; i++) {
3323 if (vdev->vpaths[i].is_configured)
3324 vdev->vpaths[i].ring.vlgrp = grp;
3327 vxge_debug_entryexit(VXGE_TRACE,
3328 "%s:%d Exiting...", __func__, __LINE__);
3332 * vxge_vlan_rx_add_vid
3333 * @dev: net device pointer.
3334 * @vid: vid
3336 * Add the vlan id to the devices vlan id table
3338 static void
3339 vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3341 struct vxgedev *vdev;
3342 struct vxge_vpath *vpath;
3343 int vp_id;
3345 vdev = netdev_priv(dev);
3347 /* Add these vlan to the vid table */
3348 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3349 vpath = &vdev->vpaths[vp_id];
3350 if (!vpath->is_open)
3351 continue;
3352 vxge_hw_vpath_vid_add(vpath->handle, vid);
3357 * vxge_vlan_rx_add_vid
3358 * @dev: net device pointer.
3359 * @vid: vid
3361 * Remove the vlan id from the device's vlan id table
3363 static void
3364 vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3366 struct vxgedev *vdev;
3367 struct vxge_vpath *vpath;
3368 int vp_id;
3370 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3372 vdev = netdev_priv(dev);
3374 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3376 /* Delete this vlan from the vid table */
3377 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3378 vpath = &vdev->vpaths[vp_id];
3379 if (!vpath->is_open)
3380 continue;
3381 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3383 vxge_debug_entryexit(VXGE_TRACE,
3384 "%s:%d Exiting...", __func__, __LINE__);
3387 static const struct net_device_ops vxge_netdev_ops = {
3388 .ndo_open = vxge_open,
3389 .ndo_stop = vxge_close,
3390 .ndo_get_stats64 = vxge_get_stats64,
3391 .ndo_start_xmit = vxge_xmit,
3392 .ndo_validate_addr = eth_validate_addr,
3393 .ndo_set_multicast_list = vxge_set_multicast,
3394 .ndo_do_ioctl = vxge_ioctl,
3395 .ndo_set_mac_address = vxge_set_mac_addr,
3396 .ndo_change_mtu = vxge_change_mtu,
3397 .ndo_fix_features = vxge_fix_features,
3398 .ndo_set_features = vxge_set_features,
3399 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3400 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3401 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3402 .ndo_tx_timeout = vxge_tx_watchdog,
3403 #ifdef CONFIG_NET_POLL_CONTROLLER
3404 .ndo_poll_controller = vxge_netpoll,
3405 #endif
3408 static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3409 struct vxge_config *config,
3410 int high_dma, int no_of_vpath,
3411 struct vxgedev **vdev_out)
3413 struct net_device *ndev;
3414 enum vxge_hw_status status = VXGE_HW_OK;
3415 struct vxgedev *vdev;
3416 int ret = 0, no_of_queue = 1;
3417 u64 stat;
3419 *vdev_out = NULL;
3420 if (config->tx_steering_type)
3421 no_of_queue = no_of_vpath;
3423 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3424 no_of_queue);
3425 if (ndev == NULL) {
3426 vxge_debug_init(
3427 vxge_hw_device_trace_level_get(hldev),
3428 "%s : device allocation failed", __func__);
3429 ret = -ENODEV;
3430 goto _out0;
3433 vxge_debug_entryexit(
3434 vxge_hw_device_trace_level_get(hldev),
3435 "%s: %s:%d Entering...",
3436 ndev->name, __func__, __LINE__);
3438 vdev = netdev_priv(ndev);
3439 memset(vdev, 0, sizeof(struct vxgedev));
3441 vdev->ndev = ndev;
3442 vdev->devh = hldev;
3443 vdev->pdev = hldev->pdev;
3444 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3445 vdev->rx_hwts = 0;
3446 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
3448 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3450 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3451 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3452 NETIF_F_TSO | NETIF_F_TSO6 |
3453 NETIF_F_HW_VLAN_TX;
3454 if (vdev->config.rth_steering != NO_STEERING)
3455 ndev->hw_features |= NETIF_F_RXHASH;
3457 ndev->features |= ndev->hw_features |
3458 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
3460 /* Driver entry points */
3461 ndev->irq = vdev->pdev->irq;
3462 ndev->base_addr = (unsigned long) hldev->bar0;
3464 ndev->netdev_ops = &vxge_netdev_ops;
3466 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3467 INIT_WORK(&vdev->reset_task, vxge_reset);
3469 vxge_initialize_ethtool_ops(ndev);
3471 /* Allocate memory for vpath */
3472 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3473 no_of_vpath, GFP_KERNEL);
3474 if (!vdev->vpaths) {
3475 vxge_debug_init(VXGE_ERR,
3476 "%s: vpath memory allocation failed",
3477 vdev->ndev->name);
3478 ret = -ENOMEM;
3479 goto _out1;
3482 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3483 "%s : checksuming enabled", __func__);
3485 if (high_dma) {
3486 ndev->features |= NETIF_F_HIGHDMA;
3487 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3488 "%s : using High DMA", __func__);
3491 ret = register_netdev(ndev);
3492 if (ret) {
3493 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3494 "%s: %s : device registration failed!",
3495 ndev->name, __func__);
3496 goto _out2;
3499 /* Set the factory defined MAC address initially */
3500 ndev->addr_len = ETH_ALEN;
3502 /* Make Link state as off at this point, when the Link change
3503 * interrupt comes the state will be automatically changed to
3504 * the right state.
3506 netif_carrier_off(ndev);
3508 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3509 "%s: Ethernet device registered",
3510 ndev->name);
3512 hldev->ndev = ndev;
3513 *vdev_out = vdev;
3515 /* Resetting the Device stats */
3516 status = vxge_hw_mrpcim_stats_access(
3517 hldev,
3518 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3521 &stat);
3523 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3524 vxge_debug_init(
3525 vxge_hw_device_trace_level_get(hldev),
3526 "%s: device stats clear returns"
3527 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3529 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3530 "%s: %s:%d Exiting...",
3531 ndev->name, __func__, __LINE__);
3533 return ret;
3534 _out2:
3535 kfree(vdev->vpaths);
3536 _out1:
3537 free_netdev(ndev);
3538 _out0:
3539 return ret;
3543 * vxge_device_unregister
3545 * This function will unregister and free network device
3547 static void vxge_device_unregister(struct __vxge_hw_device *hldev)
3549 struct vxgedev *vdev;
3550 struct net_device *dev;
3551 char buf[IFNAMSIZ];
3553 dev = hldev->ndev;
3554 vdev = netdev_priv(dev);
3556 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3557 __func__, __LINE__);
3559 strncpy(buf, dev->name, IFNAMSIZ);
3561 flush_work_sync(&vdev->reset_task);
3563 /* in 2.6 will call stop() if device is up */
3564 unregister_netdev(dev);
3566 kfree(vdev->vpaths);
3568 /* we are safe to free it now */
3569 free_netdev(dev);
3571 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3572 buf);
3573 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3574 __func__, __LINE__);
3578 * vxge_callback_crit_err
3580 * This function is called by the alarm handler in interrupt context.
3581 * Driver must analyze it based on the event type.
3583 static void
3584 vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3585 enum vxge_hw_event type, u64 vp_id)
3587 struct net_device *dev = hldev->ndev;
3588 struct vxgedev *vdev = netdev_priv(dev);
3589 struct vxge_vpath *vpath = NULL;
3590 int vpath_idx;
3592 vxge_debug_entryexit(vdev->level_trace,
3593 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3595 /* Note: This event type should be used for device wide
3596 * indications only - Serious errors, Slot freeze and critical errors
3598 vdev->cric_err_event = type;
3600 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3601 vpath = &vdev->vpaths[vpath_idx];
3602 if (vpath->device_id == vp_id)
3603 break;
3606 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3607 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3608 vxge_debug_init(VXGE_ERR,
3609 "%s: Slot is frozen", vdev->ndev->name);
3610 } else if (type == VXGE_HW_EVENT_SERR) {
3611 vxge_debug_init(VXGE_ERR,
3612 "%s: Encountered Serious Error",
3613 vdev->ndev->name);
3614 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3615 vxge_debug_init(VXGE_ERR,
3616 "%s: Encountered Critical Error",
3617 vdev->ndev->name);
3620 if ((type == VXGE_HW_EVENT_SERR) ||
3621 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3622 if (unlikely(vdev->exec_mode))
3623 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3624 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3625 vxge_hw_device_mask_all(hldev);
3626 if (unlikely(vdev->exec_mode))
3627 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3628 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3629 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3631 if (unlikely(vdev->exec_mode))
3632 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3633 else {
3634 /* check if this vpath is already set for reset */
3635 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3637 /* disable interrupts for this vpath */
3638 vxge_vpath_intr_disable(vdev, vpath_idx);
3640 /* stop the queue for this vpath */
3641 netif_tx_stop_queue(vpath->fifo.txq);
3646 vxge_debug_entryexit(vdev->level_trace,
3647 "%s: %s:%d Exiting...",
3648 vdev->ndev->name, __func__, __LINE__);
3651 static void verify_bandwidth(void)
3653 int i, band_width, total = 0, equal_priority = 0;
3655 /* 1. If user enters 0 for some fifo, give equal priority to all */
3656 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3657 if (bw_percentage[i] == 0) {
3658 equal_priority = 1;
3659 break;
3663 if (!equal_priority) {
3664 /* 2. If sum exceeds 100, give equal priority to all */
3665 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3666 if (bw_percentage[i] == 0xFF)
3667 break;
3669 total += bw_percentage[i];
3670 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3671 equal_priority = 1;
3672 break;
3677 if (!equal_priority) {
3678 /* Is all the bandwidth consumed? */
3679 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3680 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3681 /* Split rest of bw equally among next VPs*/
3682 band_width =
3683 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3684 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3685 if (band_width < 2) /* min of 2% */
3686 equal_priority = 1;
3687 else {
3688 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3689 i++)
3690 bw_percentage[i] =
3691 band_width;
3694 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3695 equal_priority = 1;
3698 if (equal_priority) {
3699 vxge_debug_init(VXGE_ERR,
3700 "%s: Assigning equal bandwidth to all the vpaths",
3701 VXGE_DRIVER_NAME);
3702 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3703 VXGE_HW_MAX_VIRTUAL_PATHS;
3704 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3705 bw_percentage[i] = bw_percentage[0];
3710 * Vpath configuration
3712 static int __devinit vxge_config_vpaths(
3713 struct vxge_hw_device_config *device_config,
3714 u64 vpath_mask, struct vxge_config *config_param)
3716 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3717 u32 txdl_size, txdl_per_memblock;
3719 temp = driver_config->vpath_per_dev;
3720 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3721 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3722 /* No more CPU. Return vpath number as zero.*/
3723 if (driver_config->g_no_cpus == -1)
3724 return 0;
3726 if (!driver_config->g_no_cpus)
3727 driver_config->g_no_cpus = num_online_cpus();
3729 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3730 if (!driver_config->vpath_per_dev)
3731 driver_config->vpath_per_dev = 1;
3733 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3734 if (!vxge_bVALn(vpath_mask, i, 1))
3735 continue;
3736 else
3737 default_no_vpath++;
3738 if (default_no_vpath < driver_config->vpath_per_dev)
3739 driver_config->vpath_per_dev = default_no_vpath;
3741 driver_config->g_no_cpus = driver_config->g_no_cpus -
3742 (driver_config->vpath_per_dev * 2);
3743 if (driver_config->g_no_cpus <= 0)
3744 driver_config->g_no_cpus = -1;
3747 if (driver_config->vpath_per_dev == 1) {
3748 vxge_debug_ll_config(VXGE_TRACE,
3749 "%s: Disable tx and rx steering, "
3750 "as single vpath is configured", VXGE_DRIVER_NAME);
3751 config_param->rth_steering = NO_STEERING;
3752 config_param->tx_steering_type = NO_STEERING;
3753 device_config->rth_en = 0;
3756 /* configure bandwidth */
3757 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3758 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3760 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3761 device_config->vp_config[i].vp_id = i;
3762 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3763 if (no_of_vpaths < driver_config->vpath_per_dev) {
3764 if (!vxge_bVALn(vpath_mask, i, 1)) {
3765 vxge_debug_ll_config(VXGE_TRACE,
3766 "%s: vpath: %d is not available",
3767 VXGE_DRIVER_NAME, i);
3768 continue;
3769 } else {
3770 vxge_debug_ll_config(VXGE_TRACE,
3771 "%s: vpath: %d available",
3772 VXGE_DRIVER_NAME, i);
3773 no_of_vpaths++;
3775 } else {
3776 vxge_debug_ll_config(VXGE_TRACE,
3777 "%s: vpath: %d is not configured, "
3778 "max_config_vpath exceeded",
3779 VXGE_DRIVER_NAME, i);
3780 break;
3783 /* Configure Tx fifo's */
3784 device_config->vp_config[i].fifo.enable =
3785 VXGE_HW_FIFO_ENABLE;
3786 device_config->vp_config[i].fifo.max_frags =
3787 MAX_SKB_FRAGS + 1;
3788 device_config->vp_config[i].fifo.memblock_size =
3789 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3791 txdl_size = device_config->vp_config[i].fifo.max_frags *
3792 sizeof(struct vxge_hw_fifo_txd);
3793 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3795 device_config->vp_config[i].fifo.fifo_blocks =
3796 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3798 device_config->vp_config[i].fifo.intr =
3799 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3801 /* Configure tti properties */
3802 device_config->vp_config[i].tti.intr_enable =
3803 VXGE_HW_TIM_INTR_ENABLE;
3805 device_config->vp_config[i].tti.btimer_val =
3806 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3808 device_config->vp_config[i].tti.timer_ac_en =
3809 VXGE_HW_TIM_TIMER_AC_ENABLE;
3811 /* For msi-x with napi (each vector has a handler of its own) -
3812 * Set CI to OFF for all vpaths
3814 device_config->vp_config[i].tti.timer_ci_en =
3815 VXGE_HW_TIM_TIMER_CI_DISABLE;
3817 device_config->vp_config[i].tti.timer_ri_en =
3818 VXGE_HW_TIM_TIMER_RI_DISABLE;
3820 device_config->vp_config[i].tti.util_sel =
3821 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3823 device_config->vp_config[i].tti.ltimer_val =
3824 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3826 device_config->vp_config[i].tti.rtimer_val =
3827 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3829 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3830 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3831 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3832 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3833 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3834 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3835 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3837 /* Configure Rx rings */
3838 device_config->vp_config[i].ring.enable =
3839 VXGE_HW_RING_ENABLE;
3841 device_config->vp_config[i].ring.ring_blocks =
3842 VXGE_HW_DEF_RING_BLOCKS;
3844 device_config->vp_config[i].ring.buffer_mode =
3845 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3847 device_config->vp_config[i].ring.rxds_limit =
3848 VXGE_HW_DEF_RING_RXDS_LIMIT;
3850 device_config->vp_config[i].ring.scatter_mode =
3851 VXGE_HW_RING_SCATTER_MODE_A;
3853 /* Configure rti properties */
3854 device_config->vp_config[i].rti.intr_enable =
3855 VXGE_HW_TIM_INTR_ENABLE;
3857 device_config->vp_config[i].rti.btimer_val =
3858 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3860 device_config->vp_config[i].rti.timer_ac_en =
3861 VXGE_HW_TIM_TIMER_AC_ENABLE;
3863 device_config->vp_config[i].rti.timer_ci_en =
3864 VXGE_HW_TIM_TIMER_CI_DISABLE;
3866 device_config->vp_config[i].rti.timer_ri_en =
3867 VXGE_HW_TIM_TIMER_RI_DISABLE;
3869 device_config->vp_config[i].rti.util_sel =
3870 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3872 device_config->vp_config[i].rti.urange_a =
3873 RTI_RX_URANGE_A;
3874 device_config->vp_config[i].rti.urange_b =
3875 RTI_RX_URANGE_B;
3876 device_config->vp_config[i].rti.urange_c =
3877 RTI_RX_URANGE_C;
3878 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3879 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3880 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3881 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3883 device_config->vp_config[i].rti.rtimer_val =
3884 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3886 device_config->vp_config[i].rti.ltimer_val =
3887 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3889 device_config->vp_config[i].rpa_strip_vlan_tag =
3890 vlan_tag_strip;
3893 driver_config->vpath_per_dev = temp;
3894 return no_of_vpaths;
3897 /* initialize device configuratrions */
3898 static void __devinit vxge_device_config_init(
3899 struct vxge_hw_device_config *device_config,
3900 int *intr_type)
3902 /* Used for CQRQ/SRQ. */
3903 device_config->dma_blockpool_initial =
3904 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3906 device_config->dma_blockpool_max =
3907 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3909 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3910 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3912 #ifndef CONFIG_PCI_MSI
3913 vxge_debug_init(VXGE_ERR,
3914 "%s: This Kernel does not support "
3915 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3916 *intr_type = INTA;
3917 #endif
3919 /* Configure whether MSI-X or IRQL. */
3920 switch (*intr_type) {
3921 case INTA:
3922 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3923 break;
3925 case MSI_X:
3926 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
3927 break;
3930 /* Timer period between device poll */
3931 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3933 /* Configure mac based steering. */
3934 device_config->rts_mac_en = addr_learn_en;
3936 /* Configure Vpaths */
3937 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3939 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3940 __func__);
3941 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3942 device_config->intr_mode);
3943 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3944 device_config->device_poll_millis);
3945 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3946 device_config->rth_en);
3947 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3948 device_config->rth_it_type);
3951 static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3953 int i;
3955 vxge_debug_init(VXGE_TRACE,
3956 "%s: %d Vpath(s) opened",
3957 vdev->ndev->name, vdev->no_of_vpath);
3959 switch (vdev->config.intr_type) {
3960 case INTA:
3961 vxge_debug_init(VXGE_TRACE,
3962 "%s: Interrupt type INTA", vdev->ndev->name);
3963 break;
3965 case MSI_X:
3966 vxge_debug_init(VXGE_TRACE,
3967 "%s: Interrupt type MSI-X", vdev->ndev->name);
3968 break;
3971 if (vdev->config.rth_steering) {
3972 vxge_debug_init(VXGE_TRACE,
3973 "%s: RTH steering enabled for TCP_IPV4",
3974 vdev->ndev->name);
3975 } else {
3976 vxge_debug_init(VXGE_TRACE,
3977 "%s: RTH steering disabled", vdev->ndev->name);
3980 switch (vdev->config.tx_steering_type) {
3981 case NO_STEERING:
3982 vxge_debug_init(VXGE_TRACE,
3983 "%s: Tx steering disabled", vdev->ndev->name);
3984 break;
3985 case TX_PRIORITY_STEERING:
3986 vxge_debug_init(VXGE_TRACE,
3987 "%s: Unsupported tx steering option",
3988 vdev->ndev->name);
3989 vxge_debug_init(VXGE_TRACE,
3990 "%s: Tx steering disabled", vdev->ndev->name);
3991 vdev->config.tx_steering_type = 0;
3992 break;
3993 case TX_VLAN_STEERING:
3994 vxge_debug_init(VXGE_TRACE,
3995 "%s: Unsupported tx steering option",
3996 vdev->ndev->name);
3997 vxge_debug_init(VXGE_TRACE,
3998 "%s: Tx steering disabled", vdev->ndev->name);
3999 vdev->config.tx_steering_type = 0;
4000 break;
4001 case TX_MULTIQ_STEERING:
4002 vxge_debug_init(VXGE_TRACE,
4003 "%s: Tx multiqueue steering enabled",
4004 vdev->ndev->name);
4005 break;
4006 case TX_PORT_STEERING:
4007 vxge_debug_init(VXGE_TRACE,
4008 "%s: Tx port steering enabled",
4009 vdev->ndev->name);
4010 break;
4011 default:
4012 vxge_debug_init(VXGE_ERR,
4013 "%s: Unsupported tx steering type",
4014 vdev->ndev->name);
4015 vxge_debug_init(VXGE_TRACE,
4016 "%s: Tx steering disabled", vdev->ndev->name);
4017 vdev->config.tx_steering_type = 0;
4020 if (vdev->config.addr_learn_en)
4021 vxge_debug_init(VXGE_TRACE,
4022 "%s: MAC Address learning enabled", vdev->ndev->name);
4024 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4025 if (!vxge_bVALn(vpath_mask, i, 1))
4026 continue;
4027 vxge_debug_ll_config(VXGE_TRACE,
4028 "%s: MTU size - %d", vdev->ndev->name,
4029 ((struct __vxge_hw_device *)(vdev->devh))->
4030 config.vp_config[i].mtu);
4031 vxge_debug_init(VXGE_TRACE,
4032 "%s: VLAN tag stripping %s", vdev->ndev->name,
4033 ((struct __vxge_hw_device *)(vdev->devh))->
4034 config.vp_config[i].rpa_strip_vlan_tag
4035 ? "Enabled" : "Disabled");
4036 vxge_debug_ll_config(VXGE_TRACE,
4037 "%s: Max frags : %d", vdev->ndev->name,
4038 ((struct __vxge_hw_device *)(vdev->devh))->
4039 config.vp_config[i].fifo.max_frags);
4040 break;
4044 #ifdef CONFIG_PM
4046 * vxge_pm_suspend - vxge power management suspend entry point
4049 static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4051 return -ENOSYS;
4054 * vxge_pm_resume - vxge power management resume entry point
4057 static int vxge_pm_resume(struct pci_dev *pdev)
4059 return -ENOSYS;
4062 #endif
4065 * vxge_io_error_detected - called when PCI error is detected
4066 * @pdev: Pointer to PCI device
4067 * @state: The current pci connection state
4069 * This function is called after a PCI bus error affecting
4070 * this device has been detected.
4072 static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4073 pci_channel_state_t state)
4075 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4076 struct net_device *netdev = hldev->ndev;
4078 netif_device_detach(netdev);
4080 if (state == pci_channel_io_perm_failure)
4081 return PCI_ERS_RESULT_DISCONNECT;
4083 if (netif_running(netdev)) {
4084 /* Bring down the card, while avoiding PCI I/O */
4085 do_vxge_close(netdev, 0);
4088 pci_disable_device(pdev);
4090 return PCI_ERS_RESULT_NEED_RESET;
4094 * vxge_io_slot_reset - called after the pci bus has been reset.
4095 * @pdev: Pointer to PCI device
4097 * Restart the card from scratch, as if from a cold-boot.
4098 * At this point, the card has exprienced a hard reset,
4099 * followed by fixups by BIOS, and has its config space
4100 * set up identically to what it was at cold boot.
4102 static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4104 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4105 struct net_device *netdev = hldev->ndev;
4107 struct vxgedev *vdev = netdev_priv(netdev);
4109 if (pci_enable_device(pdev)) {
4110 netdev_err(netdev, "Cannot re-enable device after reset\n");
4111 return PCI_ERS_RESULT_DISCONNECT;
4114 pci_set_master(pdev);
4115 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
4117 return PCI_ERS_RESULT_RECOVERED;
4121 * vxge_io_resume - called when traffic can start flowing again.
4122 * @pdev: Pointer to PCI device
4124 * This callback is called when the error recovery driver tells
4125 * us that its OK to resume normal operation.
4127 static void vxge_io_resume(struct pci_dev *pdev)
4129 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
4130 struct net_device *netdev = hldev->ndev;
4132 if (netif_running(netdev)) {
4133 if (vxge_open(netdev)) {
4134 netdev_err(netdev,
4135 "Can't bring device back up after reset\n");
4136 return;
4140 netif_device_attach(netdev);
4143 static inline u32 vxge_get_num_vfs(u64 function_mode)
4145 u32 num_functions = 0;
4147 switch (function_mode) {
4148 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4149 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4150 num_functions = 8;
4151 break;
4152 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4153 num_functions = 1;
4154 break;
4155 case VXGE_HW_FUNCTION_MODE_SRIOV:
4156 case VXGE_HW_FUNCTION_MODE_MRIOV:
4157 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4158 num_functions = 17;
4159 break;
4160 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4161 num_functions = 4;
4162 break;
4163 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4164 num_functions = 2;
4165 break;
4166 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4167 num_functions = 8; /* TODO */
4168 break;
4170 return num_functions;
4173 int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4175 struct __vxge_hw_device *hldev = vdev->devh;
4176 u32 maj, min, bld, cmaj, cmin, cbld;
4177 enum vxge_hw_status status;
4178 const struct firmware *fw;
4179 int ret;
4181 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4182 if (ret) {
4183 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4184 VXGE_DRIVER_NAME, fw_name);
4185 goto out;
4188 /* Load the new firmware onto the adapter */
4189 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4190 if (status != VXGE_HW_OK) {
4191 vxge_debug_init(VXGE_ERR,
4192 "%s: FW image download to adapter failed '%s'.",
4193 VXGE_DRIVER_NAME, fw_name);
4194 ret = -EIO;
4195 goto out;
4198 /* Read the version of the new firmware */
4199 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4200 if (status != VXGE_HW_OK) {
4201 vxge_debug_init(VXGE_ERR,
4202 "%s: Upgrade read version failed '%s'.",
4203 VXGE_DRIVER_NAME, fw_name);
4204 ret = -EIO;
4205 goto out;
4208 cmaj = vdev->config.device_hw_info.fw_version.major;
4209 cmin = vdev->config.device_hw_info.fw_version.minor;
4210 cbld = vdev->config.device_hw_info.fw_version.build;
4211 /* It's possible the version in /lib/firmware is not the latest version.
4212 * If so, we could get into a loop of trying to upgrade to the latest
4213 * and flashing the older version.
4215 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4216 !override) {
4217 ret = -EINVAL;
4218 goto out;
4221 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4222 maj, min, bld);
4224 /* Flash the adapter with the new firmware */
4225 status = vxge_hw_flash_fw(hldev);
4226 if (status != VXGE_HW_OK) {
4227 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4228 VXGE_DRIVER_NAME, fw_name);
4229 ret = -EIO;
4230 goto out;
4233 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4234 "hard reset before using, thus requiring a system reboot or a "
4235 "hotplug event.\n");
4237 out:
4238 release_firmware(fw);
4239 return ret;
4242 static int vxge_probe_fw_update(struct vxgedev *vdev)
4244 u32 maj, min, bld;
4245 int ret, gpxe = 0;
4246 char *fw_name;
4248 maj = vdev->config.device_hw_info.fw_version.major;
4249 min = vdev->config.device_hw_info.fw_version.minor;
4250 bld = vdev->config.device_hw_info.fw_version.build;
4252 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4253 return 0;
4255 /* Ignore the build number when determining if the current firmware is
4256 * "too new" to load the driver
4258 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4259 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4260 "version, unable to load driver\n",
4261 VXGE_DRIVER_NAME);
4262 return -EINVAL;
4265 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4266 * work with this driver.
4268 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4269 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4270 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4271 return -EINVAL;
4274 /* If file not specified, determine gPXE or not */
4275 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4276 int i;
4277 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4278 if (vdev->devh->eprom_versions[i]) {
4279 gpxe = 1;
4280 break;
4283 if (gpxe)
4284 fw_name = "vxge/X3fw-pxe.ncf";
4285 else
4286 fw_name = "vxge/X3fw.ncf";
4288 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4289 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4290 * probe, so ignore them
4292 if (ret != -EINVAL && ret != -ENOENT)
4293 return -EIO;
4294 else
4295 ret = 0;
4297 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4298 VXGE_FW_VER(maj, min, 0)) {
4299 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4300 " be used with this driver.\n"
4301 "Please get the latest version from "
4302 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4303 VXGE_DRIVER_NAME, maj, min, bld);
4304 return -EINVAL;
4307 return ret;
4310 static int __devinit is_sriov_initialized(struct pci_dev *pdev)
4312 int pos;
4313 u16 ctrl;
4315 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4316 if (pos) {
4317 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4318 if (ctrl & PCI_SRIOV_CTRL_VFE)
4319 return 1;
4321 return 0;
4325 * vxge_probe
4326 * @pdev : structure containing the PCI related information of the device.
4327 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4328 * Description:
4329 * This function is called when a new PCI device gets detected and initializes
4330 * it.
4331 * Return value:
4332 * returns 0 on success and negative on failure.
4335 static int __devinit
4336 vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4338 struct __vxge_hw_device *hldev;
4339 enum vxge_hw_status status;
4340 int ret;
4341 int high_dma = 0;
4342 u64 vpath_mask = 0;
4343 struct vxgedev *vdev;
4344 struct vxge_config *ll_config = NULL;
4345 struct vxge_hw_device_config *device_config = NULL;
4346 struct vxge_hw_device_attr attr;
4347 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4348 u8 *macaddr;
4349 struct vxge_mac_addrs *entry;
4350 static int bus = -1, device = -1;
4351 u32 host_type;
4352 u8 new_device = 0;
4353 enum vxge_hw_status is_privileged;
4354 u32 function_mode;
4355 u32 num_vfs = 0;
4357 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4358 attr.pdev = pdev;
4360 /* In SRIOV-17 mode, functions of the same adapter
4361 * can be deployed on different buses
4363 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4364 !pdev->is_virtfn)
4365 new_device = 1;
4367 bus = pdev->bus->number;
4368 device = PCI_SLOT(pdev->devfn);
4370 if (new_device) {
4371 if (driver_config->config_dev_cnt &&
4372 (driver_config->config_dev_cnt !=
4373 driver_config->total_dev_cnt))
4374 vxge_debug_init(VXGE_ERR,
4375 "%s: Configured %d of %d devices",
4376 VXGE_DRIVER_NAME,
4377 driver_config->config_dev_cnt,
4378 driver_config->total_dev_cnt);
4379 driver_config->config_dev_cnt = 0;
4380 driver_config->total_dev_cnt = 0;
4383 /* Now making the CPU based no of vpath calculation
4384 * applicable for individual functions as well.
4386 driver_config->g_no_cpus = 0;
4387 driver_config->vpath_per_dev = max_config_vpath;
4389 driver_config->total_dev_cnt++;
4390 if (++driver_config->config_dev_cnt > max_config_dev) {
4391 ret = 0;
4392 goto _exit0;
4395 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4396 GFP_KERNEL);
4397 if (!device_config) {
4398 ret = -ENOMEM;
4399 vxge_debug_init(VXGE_ERR,
4400 "device_config : malloc failed %s %d",
4401 __FILE__, __LINE__);
4402 goto _exit0;
4405 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
4406 if (!ll_config) {
4407 ret = -ENOMEM;
4408 vxge_debug_init(VXGE_ERR,
4409 "device_config : malloc failed %s %d",
4410 __FILE__, __LINE__);
4411 goto _exit0;
4413 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4414 ll_config->intr_type = MSI_X;
4415 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4416 ll_config->rth_steering = RTH_STEERING;
4418 /* get the default configuration parameters */
4419 vxge_hw_device_config_default_get(device_config);
4421 /* initialize configuration parameters */
4422 vxge_device_config_init(device_config, &ll_config->intr_type);
4424 ret = pci_enable_device(pdev);
4425 if (ret) {
4426 vxge_debug_init(VXGE_ERR,
4427 "%s : can not enable PCI device", __func__);
4428 goto _exit0;
4431 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
4432 vxge_debug_ll_config(VXGE_TRACE,
4433 "%s : using 64bit DMA", __func__);
4435 high_dma = 1;
4437 if (pci_set_consistent_dma_mask(pdev,
4438 DMA_BIT_MASK(64))) {
4439 vxge_debug_init(VXGE_ERR,
4440 "%s : unable to obtain 64bit DMA for "
4441 "consistent allocations", __func__);
4442 ret = -ENOMEM;
4443 goto _exit1;
4445 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
4446 vxge_debug_ll_config(VXGE_TRACE,
4447 "%s : using 32bit DMA", __func__);
4448 } else {
4449 ret = -ENOMEM;
4450 goto _exit1;
4453 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4454 if (ret) {
4455 vxge_debug_init(VXGE_ERR,
4456 "%s : request regions failed", __func__);
4457 goto _exit1;
4460 pci_set_master(pdev);
4462 attr.bar0 = pci_ioremap_bar(pdev, 0);
4463 if (!attr.bar0) {
4464 vxge_debug_init(VXGE_ERR,
4465 "%s : cannot remap io memory bar0", __func__);
4466 ret = -ENODEV;
4467 goto _exit2;
4469 vxge_debug_ll_config(VXGE_TRACE,
4470 "pci ioremap bar0: %p:0x%llx",
4471 attr.bar0,
4472 (unsigned long long)pci_resource_start(pdev, 0));
4474 status = vxge_hw_device_hw_info_get(attr.bar0,
4475 &ll_config->device_hw_info);
4476 if (status != VXGE_HW_OK) {
4477 vxge_debug_init(VXGE_ERR,
4478 "%s: Reading of hardware info failed."
4479 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4480 ret = -EINVAL;
4481 goto _exit3;
4484 vpath_mask = ll_config->device_hw_info.vpath_mask;
4485 if (vpath_mask == 0) {
4486 vxge_debug_ll_config(VXGE_TRACE,
4487 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4488 ret = -EINVAL;
4489 goto _exit3;
4492 vxge_debug_ll_config(VXGE_TRACE,
4493 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4494 (unsigned long long)vpath_mask);
4496 function_mode = ll_config->device_hw_info.function_mode;
4497 host_type = ll_config->device_hw_info.host_type;
4498 is_privileged = __vxge_hw_device_is_privilaged(host_type,
4499 ll_config->device_hw_info.func_id);
4501 /* Check how many vpaths are available */
4502 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4503 if (!((vpath_mask) & vxge_mBIT(i)))
4504 continue;
4505 max_vpath_supported++;
4508 if (new_device)
4509 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4511 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4512 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4513 (ll_config->intr_type != INTA)) {
4514 ret = pci_enable_sriov(pdev, num_vfs);
4515 if (ret)
4516 vxge_debug_ll_config(VXGE_ERR,
4517 "Failed in enabling SRIOV mode: %d\n", ret);
4518 /* No need to fail out, as an error here is non-fatal */
4522 * Configure vpaths and get driver configured number of vpaths
4523 * which is less than or equal to the maximum vpaths per function.
4525 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
4526 if (!no_of_vpath) {
4527 vxge_debug_ll_config(VXGE_ERR,
4528 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4529 ret = 0;
4530 goto _exit3;
4533 /* Setting driver callbacks */
4534 attr.uld_callbacks.link_up = vxge_callback_link_up;
4535 attr.uld_callbacks.link_down = vxge_callback_link_down;
4536 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4538 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4539 if (status != VXGE_HW_OK) {
4540 vxge_debug_init(VXGE_ERR,
4541 "Failed to initialize device (%d)", status);
4542 ret = -EINVAL;
4543 goto _exit3;
4546 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4547 ll_config->device_hw_info.fw_version.minor,
4548 ll_config->device_hw_info.fw_version.build) >=
4549 VXGE_EPROM_FW_VER) {
4550 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4552 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4553 if (status != VXGE_HW_OK) {
4554 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4555 VXGE_DRIVER_NAME);
4556 /* This is a non-fatal error, continue */
4559 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4560 hldev->eprom_versions[i] = img[i].version;
4561 if (!img[i].is_valid)
4562 break;
4563 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
4564 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
4565 VXGE_EPROM_IMG_MAJOR(img[i].version),
4566 VXGE_EPROM_IMG_MINOR(img[i].version),
4567 VXGE_EPROM_IMG_FIX(img[i].version),
4568 VXGE_EPROM_IMG_BUILD(img[i].version));
4572 /* if FCS stripping is not disabled in MAC fail driver load */
4573 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4574 if (status != VXGE_HW_OK) {
4575 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4576 " failing driver load", VXGE_DRIVER_NAME);
4577 ret = -EINVAL;
4578 goto _exit4;
4581 /* Always enable HWTS. This will always cause the FCS to be invalid,
4582 * due to the fact that HWTS is using the FCS as the location of the
4583 * timestamp. The HW FCS checking will still correctly determine if
4584 * there is a valid checksum, and the FCS is being removed by the driver
4585 * anyway. So no fucntionality is being lost. Since it is always
4586 * enabled, we now simply use the ioctl call to set whether or not the
4587 * driver should be paying attention to the HWTS.
4589 if (is_privileged == VXGE_HW_OK) {
4590 status = vxge_timestamp_config(hldev);
4591 if (status != VXGE_HW_OK) {
4592 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4593 VXGE_DRIVER_NAME);
4594 ret = -EFAULT;
4595 goto _exit4;
4599 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4601 /* set private device info */
4602 pci_set_drvdata(pdev, hldev);
4604 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4605 ll_config->addr_learn_en = addr_learn_en;
4606 ll_config->rth_algorithm = RTH_ALG_JENKINS;
4607 ll_config->rth_hash_type_tcpipv4 = 1;
4608 ll_config->rth_hash_type_ipv4 = 0;
4609 ll_config->rth_hash_type_tcpipv6 = 0;
4610 ll_config->rth_hash_type_ipv6 = 0;
4611 ll_config->rth_hash_type_tcpipv6ex = 0;
4612 ll_config->rth_hash_type_ipv6ex = 0;
4613 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4614 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4615 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4617 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4618 &vdev);
4619 if (ret) {
4620 ret = -EINVAL;
4621 goto _exit4;
4624 ret = vxge_probe_fw_update(vdev);
4625 if (ret)
4626 goto _exit5;
4628 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4629 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4630 vxge_hw_device_trace_level_get(hldev));
4632 /* set private HW device info */
4633 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4634 vdev->bar0 = attr.bar0;
4635 vdev->max_vpath_supported = max_vpath_supported;
4636 vdev->no_of_vpath = no_of_vpath;
4638 /* Virtual Path count */
4639 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4640 if (!vxge_bVALn(vpath_mask, i, 1))
4641 continue;
4642 if (j >= vdev->no_of_vpath)
4643 break;
4645 vdev->vpaths[j].is_configured = 1;
4646 vdev->vpaths[j].device_id = i;
4647 vdev->vpaths[j].ring.driver_id = j;
4648 vdev->vpaths[j].vdev = vdev;
4649 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4650 memcpy((u8 *)vdev->vpaths[j].macaddr,
4651 ll_config->device_hw_info.mac_addrs[i],
4652 ETH_ALEN);
4654 /* Initialize the mac address list header */
4655 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4657 vdev->vpaths[j].mac_addr_cnt = 0;
4658 vdev->vpaths[j].mcast_addr_cnt = 0;
4659 j++;
4661 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4662 vdev->max_config_port = max_config_port;
4664 vdev->vlan_tag_strip = vlan_tag_strip;
4666 /* map the hashing selector table to the configured vpaths */
4667 for (i = 0; i < vdev->no_of_vpath; i++)
4668 vdev->vpath_selector[i] = vpath_selector[i];
4670 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4672 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4673 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4674 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4676 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4677 vdev->ndev->name, ll_config->device_hw_info.serial_number);
4679 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4680 vdev->ndev->name, ll_config->device_hw_info.part_number);
4682 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4683 vdev->ndev->name, ll_config->device_hw_info.product_desc);
4685 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4686 vdev->ndev->name, macaddr);
4688 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4689 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4691 vxge_debug_init(VXGE_TRACE,
4692 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4693 ll_config->device_hw_info.fw_version.version,
4694 ll_config->device_hw_info.fw_date.date);
4696 if (new_device) {
4697 switch (ll_config->device_hw_info.function_mode) {
4698 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4699 vxge_debug_init(VXGE_TRACE,
4700 "%s: Single Function Mode Enabled", vdev->ndev->name);
4701 break;
4702 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4703 vxge_debug_init(VXGE_TRACE,
4704 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4705 break;
4706 case VXGE_HW_FUNCTION_MODE_SRIOV:
4707 vxge_debug_init(VXGE_TRACE,
4708 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4709 break;
4710 case VXGE_HW_FUNCTION_MODE_MRIOV:
4711 vxge_debug_init(VXGE_TRACE,
4712 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4713 break;
4717 vxge_print_parm(vdev, vpath_mask);
4719 /* Store the fw version for ethttool option */
4720 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
4721 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4722 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4724 /* Copy the station mac address to the list */
4725 for (i = 0; i < vdev->no_of_vpath; i++) {
4726 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
4727 if (NULL == entry) {
4728 vxge_debug_init(VXGE_ERR,
4729 "%s: mac_addr_list : memory allocation failed",
4730 vdev->ndev->name);
4731 ret = -EPERM;
4732 goto _exit6;
4734 macaddr = (u8 *)&entry->macaddr;
4735 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4736 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4737 vdev->vpaths[i].mac_addr_cnt = 1;
4740 kfree(device_config);
4743 * INTA is shared in multi-function mode. This is unlike the INTA
4744 * implementation in MR mode, where each VH has its own INTA message.
4745 * - INTA is masked (disabled) as long as at least one function sets
4746 * its TITAN_MASK_ALL_INT.ALARM bit.
4747 * - INTA is unmasked (enabled) when all enabled functions have cleared
4748 * their own TITAN_MASK_ALL_INT.ALARM bit.
4749 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4750 * Though this driver leaves the top level interrupts unmasked while
4751 * leaving the required module interrupt bits masked on exit, there
4752 * could be a rougue driver around that does not follow this procedure
4753 * resulting in a failure to generate interrupts. The following code is
4754 * present to prevent such a failure.
4757 if (ll_config->device_hw_info.function_mode ==
4758 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4759 if (vdev->config.intr_type == INTA)
4760 vxge_hw_device_unmask_all(hldev);
4762 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4763 vdev->ndev->name, __func__, __LINE__);
4765 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4766 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4767 vxge_hw_device_trace_level_get(hldev));
4769 kfree(ll_config);
4770 return 0;
4772 _exit6:
4773 for (i = 0; i < vdev->no_of_vpath; i++)
4774 vxge_free_mac_add_list(&vdev->vpaths[i]);
4775 _exit5:
4776 vxge_device_unregister(hldev);
4777 _exit4:
4778 pci_set_drvdata(pdev, NULL);
4779 vxge_hw_device_terminate(hldev);
4780 pci_disable_sriov(pdev);
4781 _exit3:
4782 iounmap(attr.bar0);
4783 _exit2:
4784 pci_release_region(pdev, 0);
4785 _exit1:
4786 pci_disable_device(pdev);
4787 _exit0:
4788 kfree(ll_config);
4789 kfree(device_config);
4790 driver_config->config_dev_cnt--;
4791 driver_config->total_dev_cnt--;
4792 return ret;
4796 * vxge_rem_nic - Free the PCI device
4797 * @pdev: structure containing the PCI related information of the device.
4798 * Description: This function is called by the Pci subsystem to release a
4799 * PCI device and free up all resource held up by the device.
4801 static void __devexit vxge_remove(struct pci_dev *pdev)
4803 struct __vxge_hw_device *hldev;
4804 struct vxgedev *vdev;
4805 int i;
4807 hldev = pci_get_drvdata(pdev);
4808 if (hldev == NULL)
4809 return;
4811 vdev = netdev_priv(hldev->ndev);
4813 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
4814 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4815 __func__);
4817 for (i = 0; i < vdev->no_of_vpath; i++)
4818 vxge_free_mac_add_list(&vdev->vpaths[i]);
4820 vxge_device_unregister(hldev);
4821 pci_set_drvdata(pdev, NULL);
4822 /* Do not call pci_disable_sriov here, as it will break child devices */
4823 vxge_hw_device_terminate(hldev);
4824 iounmap(vdev->bar0);
4825 pci_release_region(pdev, 0);
4826 pci_disable_device(pdev);
4827 driver_config->config_dev_cnt--;
4828 driver_config->total_dev_cnt--;
4830 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4831 __func__, __LINE__);
4832 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4833 __LINE__);
4836 static struct pci_error_handlers vxge_err_handler = {
4837 .error_detected = vxge_io_error_detected,
4838 .slot_reset = vxge_io_slot_reset,
4839 .resume = vxge_io_resume,
4842 static struct pci_driver vxge_driver = {
4843 .name = VXGE_DRIVER_NAME,
4844 .id_table = vxge_id_table,
4845 .probe = vxge_probe,
4846 .remove = __devexit_p(vxge_remove),
4847 #ifdef CONFIG_PM
4848 .suspend = vxge_pm_suspend,
4849 .resume = vxge_pm_resume,
4850 #endif
4851 .err_handler = &vxge_err_handler,
4854 static int __init
4855 vxge_starter(void)
4857 int ret = 0;
4859 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4860 pr_info("Driver version: %s\n", DRV_VERSION);
4862 verify_bandwidth();
4864 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4865 if (!driver_config)
4866 return -ENOMEM;
4868 ret = pci_register_driver(&vxge_driver);
4869 if (ret) {
4870 kfree(driver_config);
4871 goto err;
4874 if (driver_config->config_dev_cnt &&
4875 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4876 vxge_debug_init(VXGE_ERR,
4877 "%s: Configured %d of %d devices",
4878 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4879 driver_config->total_dev_cnt);
4880 err:
4881 return ret;
4884 static void __exit
4885 vxge_closer(void)
4887 pci_unregister_driver(&vxge_driver);
4888 kfree(driver_config);
4890 module_init(vxge_starter);
4891 module_exit(vxge_closer);