]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/net/vxge/vxge-main.c
vxge: prefetch RxD descriptors
[net-next-2.6.git] / drivers / net / vxge / vxge-main.c
CommitLineData
703da5a1
RV
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.
9*
10* vxge-main.c: Driver for Neterion Inc's X3100 Series 10GbE PCIe I/O
11* Virtualized Server Adapter.
12* Copyright(c) 2002-2009 Neterion Inc.
13*
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.
22*
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
28*
29* max_config_port:
30* Maximum number of port to be supported.
31* MIN -1 and MAX - 2
32*
33* max_config_vpath:
34* This configures the maximum no of VPATH configures for each
35* device function.
36* MIN - 1 and MAX - 17
37*
38* max_config_dev:
39* This configures maximum no of Device function to be enabled.
40* MIN - 1 and MAX - 17
41*
42******************************************************************************/
43
44#include <linux/if_vlan.h>
45#include <linux/pci.h>
2b05e002 46#include <linux/tcp.h>
703da5a1
RV
47#include <net/ip.h>
48#include <linux/netdevice.h>
49#include <linux/etherdevice.h>
50#include "vxge-main.h"
51#include "vxge-reg.h"
52
53MODULE_LICENSE("Dual BSD/GPL");
54MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
55 "Virtualized Server Adapter");
56
57static struct pci_device_id vxge_id_table[] __devinitdata = {
58 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
59 PCI_ANY_ID},
60 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
61 PCI_ANY_ID},
62 {0}
63};
64
65MODULE_DEVICE_TABLE(pci, vxge_id_table);
66
67VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
68VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
69VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
70VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
71VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
72VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
73
74static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
75 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
76static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
77 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
78module_param_array(bw_percentage, uint, NULL, 0);
79
80static struct vxge_drv_config *driver_config;
81
82static inline int is_vxge_card_up(struct vxgedev *vdev)
83{
84 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
85}
86
87static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
88{
89 unsigned long flags = 0;
ff67df55
BL
90 struct sk_buff **skb_ptr = NULL;
91 struct sk_buff **temp;
92#define NR_SKB_COMPLETED 128
93 struct sk_buff *completed[NR_SKB_COMPLETED];
94 int more;
703da5a1 95
ff67df55
BL
96 do {
97 more = 0;
98 skb_ptr = completed;
99
100 if (spin_trylock_irqsave(&fifo->tx_lock, flags)) {
101 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
102 NR_SKB_COMPLETED, &more);
103 spin_unlock_irqrestore(&fifo->tx_lock, flags);
104 }
105 /* free SKBs */
106 for (temp = completed; temp != skb_ptr; temp++)
107 dev_kfree_skb_irq(*temp);
108 } while (more) ;
703da5a1
RV
109}
110
111static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
112{
113 int i;
114
115 /* Complete all transmits */
116 for (i = 0; i < vdev->no_of_vpath; i++)
117 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
118}
119
120static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
121{
122 int i;
123 struct vxge_ring *ring;
124
125 /* Complete all receives*/
126 for (i = 0; i < vdev->no_of_vpath; i++) {
127 ring = &vdev->vpaths[i].ring;
128 vxge_hw_vpath_poll_rx(ring->handle);
129 }
130}
131
132/*
133 * MultiQ manipulation helper functions
134 */
135void vxge_stop_all_tx_queue(struct vxgedev *vdev)
136{
137 int i;
138 struct net_device *dev = vdev->ndev;
139
140 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
141 for (i = 0; i < vdev->no_of_vpath; i++)
142 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_STOP;
143 }
144 netif_tx_stop_all_queues(dev);
145}
146
147void vxge_stop_tx_queue(struct vxge_fifo *fifo)
148{
149 struct net_device *dev = fifo->ndev;
150
151 struct netdev_queue *txq = NULL;
152 if (fifo->tx_steering_type == TX_MULTIQ_STEERING)
153 txq = netdev_get_tx_queue(dev, fifo->driver_id);
154 else {
155 txq = netdev_get_tx_queue(dev, 0);
156 fifo->queue_state = VPATH_QUEUE_STOP;
157 }
158
159 netif_tx_stop_queue(txq);
160}
161
162void vxge_start_all_tx_queue(struct vxgedev *vdev)
163{
164 int i;
165 struct net_device *dev = vdev->ndev;
166
167 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
168 for (i = 0; i < vdev->no_of_vpath; i++)
169 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
170 }
171 netif_tx_start_all_queues(dev);
172}
173
174static void vxge_wake_all_tx_queue(struct vxgedev *vdev)
175{
176 int i;
177 struct net_device *dev = vdev->ndev;
178
179 if (vdev->config.tx_steering_type != TX_MULTIQ_STEERING) {
180 for (i = 0; i < vdev->no_of_vpath; i++)
181 vdev->vpaths[i].fifo.queue_state = VPATH_QUEUE_START;
182 }
183 netif_tx_wake_all_queues(dev);
184}
185
186void vxge_wake_tx_queue(struct vxge_fifo *fifo, struct sk_buff *skb)
187{
188 struct net_device *dev = fifo->ndev;
189
190 int vpath_no = fifo->driver_id;
191 struct netdev_queue *txq = NULL;
192 if (fifo->tx_steering_type == TX_MULTIQ_STEERING) {
193 txq = netdev_get_tx_queue(dev, vpath_no);
194 if (netif_tx_queue_stopped(txq))
195 netif_tx_wake_queue(txq);
196 } else {
197 txq = netdev_get_tx_queue(dev, 0);
198 if (fifo->queue_state == VPATH_QUEUE_STOP)
199 if (netif_tx_queue_stopped(txq)) {
200 fifo->queue_state = VPATH_QUEUE_START;
201 netif_tx_wake_queue(txq);
202 }
203 }
204}
205
206/*
207 * vxge_callback_link_up
208 *
209 * This function is called during interrupt context to notify link up state
210 * change.
211 */
212void
213vxge_callback_link_up(struct __vxge_hw_device *hldev)
214{
215 struct net_device *dev = hldev->ndev;
216 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
217
218 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
219 vdev->ndev->name, __func__, __LINE__);
220 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
221 vdev->stats.link_up++;
222
223 netif_carrier_on(vdev->ndev);
224 vxge_wake_all_tx_queue(vdev);
225
226 vxge_debug_entryexit(VXGE_TRACE,
227 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
228}
229
230/*
231 * vxge_callback_link_down
232 *
233 * This function is called during interrupt context to notify link down state
234 * change.
235 */
236void
237vxge_callback_link_down(struct __vxge_hw_device *hldev)
238{
239 struct net_device *dev = hldev->ndev;
240 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
241
242 vxge_debug_entryexit(VXGE_TRACE,
243 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
244 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
245
246 vdev->stats.link_down++;
247 netif_carrier_off(vdev->ndev);
248 vxge_stop_all_tx_queue(vdev);
249
250 vxge_debug_entryexit(VXGE_TRACE,
251 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
252}
253
254/*
255 * vxge_rx_alloc
256 *
257 * Allocate SKB.
258 */
259static struct sk_buff*
260vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
261{
262 struct net_device *dev;
263 struct sk_buff *skb;
264 struct vxge_rx_priv *rx_priv;
265
266 dev = ring->ndev;
267 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
268 ring->ndev->name, __func__, __LINE__);
269
270 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
271
272 /* try to allocate skb first. this one may fail */
273 skb = netdev_alloc_skb(dev, skb_size +
274 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
275 if (skb == NULL) {
276 vxge_debug_mem(VXGE_ERR,
277 "%s: out of memory to allocate SKB", dev->name);
278 ring->stats.skb_alloc_fail++;
279 return NULL;
280 }
281
282 vxge_debug_mem(VXGE_TRACE,
283 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
284 __func__, __LINE__, skb);
285
286 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
287
288 rx_priv->skb = skb;
289 rx_priv->data_size = skb_size;
290 vxge_debug_entryexit(VXGE_TRACE,
291 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
292
293 return skb;
294}
295
296/*
297 * vxge_rx_map
298 */
299static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
300{
301 struct vxge_rx_priv *rx_priv;
302 dma_addr_t dma_addr;
303
304 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
305 ring->ndev->name, __func__, __LINE__);
306 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
307
308 dma_addr = pci_map_single(ring->pdev, rx_priv->skb->data,
309 rx_priv->data_size, PCI_DMA_FROMDEVICE);
310
311 if (dma_addr == 0) {
312 ring->stats.pci_map_fail++;
313 return -EIO;
314 }
315 vxge_debug_mem(VXGE_TRACE,
316 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
317 ring->ndev->name, __func__, __LINE__,
318 (unsigned long long)dma_addr);
319 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
320
321 rx_priv->data_dma = dma_addr;
322 vxge_debug_entryexit(VXGE_TRACE,
323 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
324
325 return 0;
326}
327
328/*
329 * vxge_rx_initial_replenish
330 * Allocation of RxD as an initial replenish procedure.
331 */
332static enum vxge_hw_status
333vxge_rx_initial_replenish(void *dtrh, void *userdata)
334{
335 struct vxge_ring *ring = (struct vxge_ring *)userdata;
336 struct vxge_rx_priv *rx_priv;
337
338 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
339 ring->ndev->name, __func__, __LINE__);
340 if (vxge_rx_alloc(dtrh, ring,
341 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
342 return VXGE_HW_FAIL;
343
344 if (vxge_rx_map(dtrh, ring)) {
345 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
346 dev_kfree_skb(rx_priv->skb);
347
348 return VXGE_HW_FAIL;
349 }
350 vxge_debug_entryexit(VXGE_TRACE,
351 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
352
353 return VXGE_HW_OK;
354}
355
356static inline void
357vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
358 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
359{
360
361 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
362 ring->ndev->name, __func__, __LINE__);
363 skb_record_rx_queue(skb, ring->driver_id);
364 skb->protocol = eth_type_trans(skb, ring->ndev);
365
366 ring->stats.rx_frms++;
367 ring->stats.rx_bytes += pkt_length;
368
369 if (skb->pkt_type == PACKET_MULTICAST)
370 ring->stats.rx_mcast++;
371
372 vxge_debug_rx(VXGE_TRACE,
373 "%s: %s:%d skb protocol = %d",
374 ring->ndev->name, __func__, __LINE__, skb->protocol);
375
376 if (ring->gro_enable) {
377 if (ring->vlgrp && ext_info->vlan &&
378 (ring->vlan_tag_strip ==
379 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
a5d165b5 380 vlan_gro_receive(ring->napi_p, ring->vlgrp,
703da5a1
RV
381 ext_info->vlan, skb);
382 else
a5d165b5 383 napi_gro_receive(ring->napi_p, skb);
703da5a1
RV
384 } else {
385 if (ring->vlgrp && vlan &&
386 (ring->vlan_tag_strip ==
387 VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE))
388 vlan_hwaccel_receive_skb(skb, ring->vlgrp, vlan);
389 else
390 netif_receive_skb(skb);
391 }
392 vxge_debug_entryexit(VXGE_TRACE,
393 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
394}
395
396static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
397 struct vxge_rx_priv *rx_priv)
398{
399 pci_dma_sync_single_for_device(ring->pdev,
400 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
401
402 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
403 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
404}
405
406static inline void vxge_post(int *dtr_cnt, void **first_dtr,
407 void *post_dtr, struct __vxge_hw_ring *ringh)
408{
409 int dtr_count = *dtr_cnt;
410 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
411 if (*first_dtr)
412 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
413 *first_dtr = post_dtr;
414 } else
415 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
416 dtr_count++;
417 *dtr_cnt = dtr_count;
418}
419
420/*
421 * vxge_rx_1b_compl
422 *
423 * If the interrupt is because of a received frame or if the receive ring
424 * contains fresh as yet un-processed frames, this function is called.
425 */
426enum vxge_hw_status
427vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
428 u8 t_code, void *userdata)
429{
430 struct vxge_ring *ring = (struct vxge_ring *)userdata;
431 struct net_device *dev = ring->ndev;
432 unsigned int dma_sizes;
433 void *first_dtr = NULL;
434 int dtr_cnt = 0;
435 int data_size;
436 dma_addr_t data_dma;
437 int pkt_length;
438 struct sk_buff *skb;
439 struct vxge_rx_priv *rx_priv;
440 struct vxge_hw_ring_rxd_info ext_info;
441 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
442 ring->ndev->name, __func__, __LINE__);
443 ring->pkts_processed = 0;
444
445 vxge_hw_ring_replenish(ringh, 0);
446
447 do {
3f23e436 448 prefetch((char *)dtr + L1_CACHE_BYTES);
703da5a1
RV
449 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
450 skb = rx_priv->skb;
451 data_size = rx_priv->data_size;
452 data_dma = rx_priv->data_dma;
453
454 vxge_debug_rx(VXGE_TRACE,
455 "%s: %s:%d skb = 0x%p",
456 ring->ndev->name, __func__, __LINE__, skb);
457
458 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
459 pkt_length = dma_sizes;
460
22fa125e
SH
461 pkt_length -= ETH_FCS_LEN;
462
703da5a1
RV
463 vxge_debug_rx(VXGE_TRACE,
464 "%s: %s:%d Packet Length = %d",
465 ring->ndev->name, __func__, __LINE__, pkt_length);
466
467 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
468
469 /* check skb validity */
470 vxge_assert(skb);
471
472 prefetch((char *)skb + L1_CACHE_BYTES);
473 if (unlikely(t_code)) {
474
475 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
476 VXGE_HW_OK) {
477
478 ring->stats.rx_errors++;
479 vxge_debug_rx(VXGE_TRACE,
480 "%s: %s :%d Rx T_code is %d",
481 ring->ndev->name, __func__,
482 __LINE__, t_code);
483
484 /* If the t_code is not supported and if the
485 * t_code is other than 0x5 (unparseable packet
486 * such as unknown UPV6 header), Drop it !!!
487 */
488 vxge_re_pre_post(dtr, ring, rx_priv);
489
490 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
491 ring->stats.rx_dropped++;
492 continue;
493 }
494 }
495
496 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
497
498 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
499
500 if (!vxge_rx_map(dtr, ring)) {
501 skb_put(skb, pkt_length);
502
503 pci_unmap_single(ring->pdev, data_dma,
504 data_size, PCI_DMA_FROMDEVICE);
505
506 vxge_hw_ring_rxd_pre_post(ringh, dtr);
507 vxge_post(&dtr_cnt, &first_dtr, dtr,
508 ringh);
509 } else {
510 dev_kfree_skb(rx_priv->skb);
511 rx_priv->skb = skb;
512 rx_priv->data_size = data_size;
513 vxge_re_pre_post(dtr, ring, rx_priv);
514
515 vxge_post(&dtr_cnt, &first_dtr, dtr,
516 ringh);
517 ring->stats.rx_dropped++;
518 break;
519 }
520 } else {
521 vxge_re_pre_post(dtr, ring, rx_priv);
522
523 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
524 ring->stats.rx_dropped++;
525 break;
526 }
527 } else {
528 struct sk_buff *skb_up;
529
530 skb_up = netdev_alloc_skb(dev, pkt_length +
531 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
532 if (skb_up != NULL) {
533 skb_reserve(skb_up,
534 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
535
536 pci_dma_sync_single_for_cpu(ring->pdev,
537 data_dma, data_size,
538 PCI_DMA_FROMDEVICE);
539
540 vxge_debug_mem(VXGE_TRACE,
541 "%s: %s:%d skb_up = %p",
542 ring->ndev->name, __func__,
543 __LINE__, skb);
544 memcpy(skb_up->data, skb->data, pkt_length);
545
546 vxge_re_pre_post(dtr, ring, rx_priv);
547
548 vxge_post(&dtr_cnt, &first_dtr, dtr,
549 ringh);
550 /* will netif_rx small SKB instead */
551 skb = skb_up;
552 skb_put(skb, pkt_length);
553 } else {
554 vxge_re_pre_post(dtr, ring, rx_priv);
555
556 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
557 vxge_debug_rx(VXGE_ERR,
558 "%s: vxge_rx_1b_compl: out of "
559 "memory", dev->name);
560 ring->stats.skb_alloc_fail++;
561 break;
562 }
563 }
564
565 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
566 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
567 ring->rx_csum && /* Offload Rx side CSUM */
568 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
569 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
570 skb->ip_summed = CHECKSUM_UNNECESSARY;
571 else
572 skb->ip_summed = CHECKSUM_NONE;
573
574 vxge_rx_complete(ring, skb, ext_info.vlan,
575 pkt_length, &ext_info);
576
577 ring->budget--;
578 ring->pkts_processed++;
579 if (!ring->budget)
580 break;
581
582 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
583 &t_code) == VXGE_HW_OK);
584
585 if (first_dtr)
586 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
587
588 dev->last_rx = jiffies;
589
590 vxge_debug_entryexit(VXGE_TRACE,
591 "%s:%d Exiting...",
592 __func__, __LINE__);
593 return VXGE_HW_OK;
594}
595
596/*
597 * vxge_xmit_compl
598 *
599 * If an interrupt was raised to indicate DMA complete of the Tx packet,
600 * this function is called. It identifies the last TxD whose buffer was
601 * freed and frees all skbs whose data have already DMA'ed into the NICs
602 * internal memory.
603 */
604enum vxge_hw_status
605vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
606 enum vxge_hw_fifo_tcode t_code, void *userdata,
ff67df55 607 struct sk_buff ***skb_ptr, int nr_skb, int *more)
703da5a1
RV
608{
609 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
ff67df55 610 struct sk_buff *skb, **done_skb = *skb_ptr;
703da5a1
RV
611 int pkt_cnt = 0;
612
613 vxge_debug_entryexit(VXGE_TRACE,
614 "%s:%d Entered....", __func__, __LINE__);
615
616 do {
617 int frg_cnt;
618 skb_frag_t *frag;
619 int i = 0, j;
620 struct vxge_tx_priv *txd_priv =
621 vxge_hw_fifo_txdl_private_get(dtr);
622
623 skb = txd_priv->skb;
624 frg_cnt = skb_shinfo(skb)->nr_frags;
625 frag = &skb_shinfo(skb)->frags[0];
626
627 vxge_debug_tx(VXGE_TRACE,
628 "%s: %s:%d fifo_hw = %p dtr = %p "
629 "tcode = 0x%x", fifo->ndev->name, __func__,
630 __LINE__, fifo_hw, dtr, t_code);
631 /* check skb validity */
632 vxge_assert(skb);
633 vxge_debug_tx(VXGE_TRACE,
634 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
635 fifo->ndev->name, __func__, __LINE__,
636 skb, txd_priv, frg_cnt);
637 if (unlikely(t_code)) {
638 fifo->stats.tx_errors++;
639 vxge_debug_tx(VXGE_ERR,
640 "%s: tx: dtr %p completed due to "
641 "error t_code %01x", fifo->ndev->name,
642 dtr, t_code);
643 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
644 }
645
646 /* for unfragmented skb */
647 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
648 skb_headlen(skb), PCI_DMA_TODEVICE);
649
650 for (j = 0; j < frg_cnt; j++) {
651 pci_unmap_page(fifo->pdev,
652 txd_priv->dma_buffers[i++],
653 frag->size, PCI_DMA_TODEVICE);
654 frag += 1;
655 }
656
657 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
658
659 /* Updating the statistics block */
660 fifo->stats.tx_frms++;
661 fifo->stats.tx_bytes += skb->len;
662
ff67df55
BL
663 *done_skb++ = skb;
664
665 if (--nr_skb <= 0) {
666 *more = 1;
667 break;
668 }
703da5a1
RV
669
670 pkt_cnt++;
671 if (pkt_cnt > fifo->indicate_max_pkts)
672 break;
673
674 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
675 &dtr, &t_code) == VXGE_HW_OK);
676
ff67df55 677 *skb_ptr = done_skb;
703da5a1
RV
678 vxge_wake_tx_queue(fifo, skb);
679
703da5a1
RV
680 vxge_debug_entryexit(VXGE_TRACE,
681 "%s: %s:%d Exiting...",
682 fifo->ndev->name, __func__, __LINE__);
683 return VXGE_HW_OK;
684}
685
28679751 686/* select a vpath to transmit the packet */
703da5a1
RV
687static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb,
688 int *do_lock)
689{
690 u16 queue_len, counter = 0;
691 if (skb->protocol == htons(ETH_P_IP)) {
692 struct iphdr *ip;
693 struct tcphdr *th;
694
695 ip = ip_hdr(skb);
696
697 if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
698 th = (struct tcphdr *)(((unsigned char *)ip) +
699 ip->ihl*4);
700
701 queue_len = vdev->no_of_vpath;
702 counter = (ntohs(th->source) +
703 ntohs(th->dest)) &
704 vdev->vpath_selector[queue_len - 1];
705 if (counter >= queue_len)
706 counter = queue_len - 1;
707
708 if (ip->protocol == IPPROTO_UDP) {
709#ifdef NETIF_F_LLTX
710 *do_lock = 0;
711#endif
712 }
713 }
714 }
715 return counter;
716}
717
718static enum vxge_hw_status vxge_search_mac_addr_in_list(
719 struct vxge_vpath *vpath, u64 del_mac)
720{
721 struct list_head *entry, *next;
722 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
723 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
724 return TRUE;
725 }
726 return FALSE;
727}
728
729static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
730{
731 struct macInfo mac_info;
732 u8 *mac_address = NULL;
733 u64 mac_addr = 0, vpath_vector = 0;
734 int vpath_idx = 0;
735 enum vxge_hw_status status = VXGE_HW_OK;
736 struct vxge_vpath *vpath = NULL;
737 struct __vxge_hw_device *hldev;
738
739 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
740
741 mac_address = (u8 *)&mac_addr;
742 memcpy(mac_address, mac_header, ETH_ALEN);
743
744 /* Is this mac address already in the list? */
745 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
746 vpath = &vdev->vpaths[vpath_idx];
747 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
748 return vpath_idx;
749 }
750
751 memset(&mac_info, 0, sizeof(struct macInfo));
752 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
753
754 /* Any vpath has room to add mac address to its da table? */
755 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
756 vpath = &vdev->vpaths[vpath_idx];
757 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
758 /* Add this mac address to this vpath */
759 mac_info.vpath_no = vpath_idx;
760 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
761 status = vxge_add_mac_addr(vdev, &mac_info);
762 if (status != VXGE_HW_OK)
763 return -EPERM;
764 return vpath_idx;
765 }
766 }
767
768 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
769 vpath_idx = 0;
770 mac_info.vpath_no = vpath_idx;
771 /* Is the first vpath already selected as catch-basin ? */
772 vpath = &vdev->vpaths[vpath_idx];
773 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
774 /* Add this mac address to this vpath */
775 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
776 return -EPERM;
777 return vpath_idx;
778 }
779
780 /* Select first vpath as catch-basin */
781 vpath_vector = vxge_mBIT(vpath->device_id);
782 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
783 vxge_hw_mgmt_reg_type_mrpcim,
784 0,
785 (ulong)offsetof(
786 struct vxge_hw_mrpcim_reg,
787 rts_mgr_cbasin_cfg),
788 vpath_vector);
789 if (status != VXGE_HW_OK) {
790 vxge_debug_tx(VXGE_ERR,
791 "%s: Unable to set the vpath-%d in catch-basin mode",
792 VXGE_DRIVER_NAME, vpath->device_id);
793 return -EPERM;
794 }
795
796 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
797 return -EPERM;
798
799 return vpath_idx;
800}
801
802/**
803 * vxge_xmit
804 * @skb : the socket buffer containing the Tx data.
805 * @dev : device pointer.
806 *
807 * This function is the Tx entry point of the driver. Neterion NIC supports
808 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
809 * NOTE: when device cant queue the pkt, just the trans_start variable will
810 * not be upadted.
811*/
812static int
813vxge_xmit(struct sk_buff *skb, struct net_device *dev)
814{
815 struct vxge_fifo *fifo = NULL;
816 void *dtr_priv;
817 void *dtr = NULL;
818 struct vxgedev *vdev = NULL;
819 enum vxge_hw_status status;
820 int frg_cnt, first_frg_len;
821 skb_frag_t *frag;
822 int i = 0, j = 0, avail;
823 u64 dma_pointer;
824 struct vxge_tx_priv *txdl_priv = NULL;
825 struct __vxge_hw_fifo *fifo_hw;
703da5a1
RV
826 int offload_type;
827 unsigned long flags = 0;
828 int vpath_no = 0;
829 int do_spin_tx_lock = 1;
830
831 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
832 dev->name, __func__, __LINE__);
833
834 /* A buffer with no data will be dropped */
835 if (unlikely(skb->len <= 0)) {
836 vxge_debug_tx(VXGE_ERR,
837 "%s: Buffer has no data..", dev->name);
838 dev_kfree_skb(skb);
839 return NETDEV_TX_OK;
840 }
841
842 vdev = (struct vxgedev *)netdev_priv(dev);
843
844 if (unlikely(!is_vxge_card_up(vdev))) {
845 vxge_debug_tx(VXGE_ERR,
846 "%s: vdev not initialized", dev->name);
847 dev_kfree_skb(skb);
848 return NETDEV_TX_OK;
849 }
850
851 if (vdev->config.addr_learn_en) {
852 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
853 if (vpath_no == -EPERM) {
854 vxge_debug_tx(VXGE_ERR,
855 "%s: Failed to store the mac address",
856 dev->name);
857 dev_kfree_skb(skb);
858 return NETDEV_TX_OK;
859 }
860 }
861
862 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
863 vpath_no = skb_get_queue_mapping(skb);
864 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
865 vpath_no = vxge_get_vpath_no(vdev, skb, &do_spin_tx_lock);
866
867 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
868
869 if (vpath_no >= vdev->no_of_vpath)
870 vpath_no = 0;
871
872 fifo = &vdev->vpaths[vpath_no].fifo;
873 fifo_hw = fifo->handle;
874
875 if (do_spin_tx_lock)
876 spin_lock_irqsave(&fifo->tx_lock, flags);
877 else {
878 if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
879 return NETDEV_TX_LOCKED;
880 }
881
882 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING) {
883 if (netif_subqueue_stopped(dev, skb)) {
884 spin_unlock_irqrestore(&fifo->tx_lock, flags);
885 return NETDEV_TX_BUSY;
886 }
887 } else if (unlikely(fifo->queue_state == VPATH_QUEUE_STOP)) {
888 if (netif_queue_stopped(dev)) {
889 spin_unlock_irqrestore(&fifo->tx_lock, flags);
890 return NETDEV_TX_BUSY;
891 }
892 }
893 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
894 if (avail == 0) {
895 vxge_debug_tx(VXGE_ERR,
896 "%s: No free TXDs available", dev->name);
897 fifo->stats.txd_not_free++;
898 vxge_stop_tx_queue(fifo);
899 goto _exit2;
900 }
901
4403b371
BL
902 /* Last TXD? Stop tx queue to avoid dropping packets. TX
903 * completion will resume the queue.
904 */
905 if (avail == 1)
906 vxge_stop_tx_queue(fifo);
907
703da5a1
RV
908 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
909 if (unlikely(status != VXGE_HW_OK)) {
910 vxge_debug_tx(VXGE_ERR,
911 "%s: Out of descriptors .", dev->name);
912 fifo->stats.txd_out_of_desc++;
913 vxge_stop_tx_queue(fifo);
914 goto _exit2;
915 }
916
917 vxge_debug_tx(VXGE_TRACE,
918 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
919 dev->name, __func__, __LINE__,
920 fifo_hw, dtr, dtr_priv);
921
922 if (vdev->vlgrp && vlan_tx_tag_present(skb)) {
923 u16 vlan_tag = vlan_tx_tag_get(skb);
924 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
925 }
926
927 first_frg_len = skb_headlen(skb);
928
929 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
930 PCI_DMA_TODEVICE);
931
932 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
933 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
934 vxge_stop_tx_queue(fifo);
935 fifo->stats.pci_map_fail++;
936 goto _exit2;
937 }
938
939 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
940 txdl_priv->skb = skb;
941 txdl_priv->dma_buffers[j] = dma_pointer;
942
943 frg_cnt = skb_shinfo(skb)->nr_frags;
944 vxge_debug_tx(VXGE_TRACE,
945 "%s: %s:%d skb = %p txdl_priv = %p "
946 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
947 __func__, __LINE__, skb, txdl_priv,
948 frg_cnt, (unsigned long long)dma_pointer);
949
950 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
951 first_frg_len);
952
953 frag = &skb_shinfo(skb)->frags[0];
954 for (i = 0; i < frg_cnt; i++) {
955 /* ignore 0 length fragment */
956 if (!frag->size)
957 continue;
958
959 dma_pointer =
960 (u64)pci_map_page(fifo->pdev, frag->page,
961 frag->page_offset, frag->size,
962 PCI_DMA_TODEVICE);
963
964 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer)))
965 goto _exit0;
966 vxge_debug_tx(VXGE_TRACE,
967 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
968 dev->name, __func__, __LINE__, i,
969 (unsigned long long)dma_pointer);
970
971 txdl_priv->dma_buffers[j] = dma_pointer;
972 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
973 frag->size);
974 frag += 1;
975 }
976
977 offload_type = vxge_offload_type(skb);
978
979 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
980
981 int mss = vxge_tcp_mss(skb);
982 if (mss) {
703da5a1
RV
983 vxge_debug_tx(VXGE_TRACE,
984 "%s: %s:%d mss = %d",
985 dev->name, __func__, __LINE__, mss);
986 vxge_hw_fifo_txdl_mss_set(dtr, mss);
987 } else {
988 vxge_assert(skb->len <=
989 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
990 vxge_assert(0);
991 goto _exit1;
992 }
993 }
994
995 if (skb->ip_summed == CHECKSUM_PARTIAL)
996 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
997 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
998 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
999 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
1000
1001 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
28679751
ED
1002#ifdef NETIF_F_LLTX
1003 dev->trans_start = jiffies; /* NETIF_F_LLTX driver :( */
1004#endif
703da5a1
RV
1005 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1006
1007 VXGE_COMPLETE_VPATH_TX(fifo);
1008 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
1009 dev->name, __func__, __LINE__);
6ed10654 1010 return NETDEV_TX_OK;
703da5a1
RV
1011
1012_exit0:
1013 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
1014
1015_exit1:
1016 j = 0;
1017 frag = &skb_shinfo(skb)->frags[0];
1018
1019 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
1020 skb_headlen(skb), PCI_DMA_TODEVICE);
1021
1022 for (; j < i; j++) {
1023 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
1024 frag->size, PCI_DMA_TODEVICE);
1025 frag += 1;
1026 }
1027
1028 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
1029_exit2:
1030 dev_kfree_skb(skb);
1031 spin_unlock_irqrestore(&fifo->tx_lock, flags);
1032 VXGE_COMPLETE_VPATH_TX(fifo);
1033
6ed10654 1034 return NETDEV_TX_OK;
703da5a1
RV
1035}
1036
1037/*
1038 * vxge_rx_term
1039 *
1040 * Function will be called by hw function to abort all outstanding receive
1041 * descriptors.
1042 */
1043static void
1044vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1045{
1046 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1047 struct vxge_rx_priv *rx_priv =
1048 vxge_hw_ring_rxd_private_get(dtrh);
1049
1050 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1051 ring->ndev->name, __func__, __LINE__);
1052 if (state != VXGE_HW_RXD_STATE_POSTED)
1053 return;
1054
1055 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1056 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1057
1058 dev_kfree_skb(rx_priv->skb);
1059
1060 vxge_debug_entryexit(VXGE_TRACE,
1061 "%s: %s:%d Exiting...",
1062 ring->ndev->name, __func__, __LINE__);
1063}
1064
1065/*
1066 * vxge_tx_term
1067 *
1068 * Function will be called to abort all outstanding tx descriptors
1069 */
1070static void
1071vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1072{
1073 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1074 skb_frag_t *frag;
1075 int i = 0, j, frg_cnt;
1076 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1077 struct sk_buff *skb = txd_priv->skb;
1078
1079 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1080
1081 if (state != VXGE_HW_TXDL_STATE_POSTED)
1082 return;
1083
1084 /* check skb validity */
1085 vxge_assert(skb);
1086 frg_cnt = skb_shinfo(skb)->nr_frags;
1087 frag = &skb_shinfo(skb)->frags[0];
1088
1089 /* for unfragmented skb */
1090 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1091 skb_headlen(skb), PCI_DMA_TODEVICE);
1092
1093 for (j = 0; j < frg_cnt; j++) {
1094 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
1095 frag->size, PCI_DMA_TODEVICE);
1096 frag += 1;
1097 }
1098
1099 dev_kfree_skb(skb);
1100
1101 vxge_debug_entryexit(VXGE_TRACE,
1102 "%s:%d Exiting...", __func__, __LINE__);
1103}
1104
1105/**
1106 * vxge_set_multicast
1107 * @dev: pointer to the device structure
1108 *
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.
1115 */
1116static void vxge_set_multicast(struct net_device *dev)
1117{
1118 struct dev_mc_list *mclist;
1119 struct vxgedev *vdev;
1120 int i, mcast_cnt = 0;
1121 struct __vxge_hw_device *hldev;
1122 enum vxge_hw_status status = VXGE_HW_OK;
1123 struct macInfo mac_info;
1124 int vpath_idx = 0;
1125 struct vxge_mac_addrs *mac_entry;
1126 struct list_head *list_head;
1127 struct list_head *entry, *next;
1128 u8 *mac_address = NULL;
1129
1130 vxge_debug_entryexit(VXGE_TRACE,
1131 "%s:%d", __func__, __LINE__);
1132
1133 vdev = (struct vxgedev *)netdev_priv(dev);
1134 hldev = (struct __vxge_hw_device *)vdev->devh;
1135
1136 if (unlikely(!is_vxge_card_up(vdev)))
1137 return;
1138
1139 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1140 for (i = 0; i < vdev->no_of_vpath; i++) {
1141 vxge_assert(vdev->vpaths[i].is_open);
1142 status = vxge_hw_vpath_mcast_enable(
1143 vdev->vpaths[i].handle);
1144 vdev->all_multi_flg = 1;
1145 }
1146 } else if ((dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
1147 for (i = 0; i < vdev->no_of_vpath; i++) {
1148 vxge_assert(vdev->vpaths[i].is_open);
1149 status = vxge_hw_vpath_mcast_disable(
1150 vdev->vpaths[i].handle);
1151 vdev->all_multi_flg = 1;
1152 }
1153 }
1154
1155 if (status != VXGE_HW_OK)
1156 vxge_debug_init(VXGE_ERR,
1157 "failed to %s multicast, status %d",
1158 dev->flags & IFF_ALLMULTI ?
1159 "enable" : "disable", status);
1160
1161 if (!vdev->config.addr_learn_en) {
1162 if (dev->flags & IFF_PROMISC) {
1163 for (i = 0; i < vdev->no_of_vpath; i++) {
1164 vxge_assert(vdev->vpaths[i].is_open);
1165 status = vxge_hw_vpath_promisc_enable(
1166 vdev->vpaths[i].handle);
1167 }
1168 } else {
1169 for (i = 0; i < vdev->no_of_vpath; i++) {
1170 vxge_assert(vdev->vpaths[i].is_open);
1171 status = vxge_hw_vpath_promisc_disable(
1172 vdev->vpaths[i].handle);
1173 }
1174 }
1175 }
1176
1177 memset(&mac_info, 0, sizeof(struct macInfo));
1178 /* Update individual M_CAST address list */
1179 if ((!vdev->all_multi_flg) && dev->mc_count) {
1180
1181 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1182 list_head = &vdev->vpaths[0].mac_addr_list;
1183 if ((dev->mc_count +
1184 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1185 vdev->vpaths[0].max_mac_addr_cnt)
1186 goto _set_all_mcast;
1187
1188 /* Delete previous MC's */
1189 for (i = 0; i < mcast_cnt; i++) {
1190 if (!list_empty(list_head))
1191 mac_entry = (struct vxge_mac_addrs *)
1192 list_first_entry(list_head,
1193 struct vxge_mac_addrs,
1194 item);
1195
1196 list_for_each_safe(entry, next, list_head) {
1197
1198 mac_entry = (struct vxge_mac_addrs *) entry;
1199 /* Copy the mac address to delete */
1200 mac_address = (u8 *)&mac_entry->macaddr;
1201 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1202
1203 /* Is this a multicast address */
1204 if (0x01 & mac_info.macaddr[0]) {
1205 for (vpath_idx = 0; vpath_idx <
1206 vdev->no_of_vpath;
1207 vpath_idx++) {
1208 mac_info.vpath_no = vpath_idx;
1209 status = vxge_del_mac_addr(
1210 vdev,
1211 &mac_info);
1212 }
1213 }
1214 }
1215 }
1216
1217 /* Add new ones */
1218 for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
1219 i++, mclist = mclist->next) {
1220
1221 memcpy(mac_info.macaddr, mclist->dmi_addr, ETH_ALEN);
1222 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1223 vpath_idx++) {
1224 mac_info.vpath_no = vpath_idx;
1225 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1226 status = vxge_add_mac_addr(vdev, &mac_info);
1227 if (status != VXGE_HW_OK) {
1228 vxge_debug_init(VXGE_ERR,
1229 "%s:%d Setting individual"
1230 "multicast address failed",
1231 __func__, __LINE__);
1232 goto _set_all_mcast;
1233 }
1234 }
1235 }
1236
1237 return;
1238_set_all_mcast:
1239 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1240 /* Delete previous MC's */
1241 for (i = 0; i < mcast_cnt; i++) {
1242
1243 list_for_each_safe(entry, next, list_head) {
1244
1245 mac_entry = (struct vxge_mac_addrs *) entry;
1246 /* Copy the mac address to delete */
1247 mac_address = (u8 *)&mac_entry->macaddr;
1248 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1249
1250 /* Is this a multicast address */
1251 if (0x01 & mac_info.macaddr[0])
1252 break;
1253 }
1254
1255 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1256 vpath_idx++) {
1257 mac_info.vpath_no = vpath_idx;
1258 status = vxge_del_mac_addr(vdev, &mac_info);
1259 }
1260 }
1261
1262 /* Enable all multicast */
1263 for (i = 0; i < vdev->no_of_vpath; i++) {
1264 vxge_assert(vdev->vpaths[i].is_open);
1265 status = vxge_hw_vpath_mcast_enable(
1266 vdev->vpaths[i].handle);
1267 if (status != VXGE_HW_OK) {
1268 vxge_debug_init(VXGE_ERR,
1269 "%s:%d Enabling all multicasts failed",
1270 __func__, __LINE__);
1271 }
1272 vdev->all_multi_flg = 1;
1273 }
1274 dev->flags |= IFF_ALLMULTI;
1275 }
1276
1277 vxge_debug_entryexit(VXGE_TRACE,
1278 "%s:%d Exiting...", __func__, __LINE__);
1279}
1280
1281/**
1282 * vxge_set_mac_addr
1283 * @dev: pointer to the device structure
1284 *
1285 * Update entry "0" (default MAC addr)
1286 */
1287static int vxge_set_mac_addr(struct net_device *dev, void *p)
1288{
1289 struct sockaddr *addr = p;
1290 struct vxgedev *vdev;
1291 struct __vxge_hw_device *hldev;
1292 enum vxge_hw_status status = VXGE_HW_OK;
1293 struct macInfo mac_info_new, mac_info_old;
1294 int vpath_idx = 0;
1295
1296 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1297
1298 vdev = (struct vxgedev *)netdev_priv(dev);
1299 hldev = vdev->devh;
1300
1301 if (!is_valid_ether_addr(addr->sa_data))
1302 return -EINVAL;
1303
1304 memset(&mac_info_new, 0, sizeof(struct macInfo));
1305 memset(&mac_info_old, 0, sizeof(struct macInfo));
1306
1307 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1308 __func__, __LINE__);
1309
1310 /* Get the old address */
1311 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1312
1313 /* Copy the new address */
1314 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1315
1316 /* First delete the old mac address from all the vpaths
1317 as we can't specify the index while adding new mac address */
1318 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1319 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1320 if (!vpath->is_open) {
1321 /* This can happen when this interface is added/removed
1322 to the bonding interface. Delete this station address
1323 from the linked list */
1324 vxge_mac_list_del(vpath, &mac_info_old);
1325
1326 /* Add this new address to the linked list
1327 for later restoring */
1328 vxge_mac_list_add(vpath, &mac_info_new);
1329
1330 continue;
1331 }
1332 /* Delete the station address */
1333 mac_info_old.vpath_no = vpath_idx;
1334 status = vxge_del_mac_addr(vdev, &mac_info_old);
1335 }
1336
1337 if (unlikely(!is_vxge_card_up(vdev))) {
1338 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1339 return VXGE_HW_OK;
1340 }
1341
1342 /* Set this mac address to all the vpaths */
1343 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1344 mac_info_new.vpath_no = vpath_idx;
1345 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1346 status = vxge_add_mac_addr(vdev, &mac_info_new);
1347 if (status != VXGE_HW_OK)
1348 return -EINVAL;
1349 }
1350
1351 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1352
1353 return status;
1354}
1355
1356/*
1357 * vxge_vpath_intr_enable
1358 * @vdev: pointer to vdev
1359 * @vp_id: vpath for which to enable the interrupts
1360 *
1361 * Enables the interrupts for the vpath
1362*/
1363void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
1364{
1365 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1366 int msix_id, alarm_msix_id;
1367 int tim_msix_id[4] = {[0 ...3] = 0};
1368
1369 vxge_hw_vpath_intr_enable(vpath->handle);
1370
1371 if (vdev->config.intr_type == INTA)
1372 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1373 else {
1374 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1375 alarm_msix_id =
1376 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1377
1378 tim_msix_id[0] = msix_id;
1379 tim_msix_id[1] = msix_id + 1;
1380 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1381 alarm_msix_id);
1382
1383 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1384 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1385
1386 /* enable the alarm vector */
1387 vxge_hw_vpath_msix_unmask(vpath->handle, alarm_msix_id);
1388 }
1389}
1390
1391/*
1392 * vxge_vpath_intr_disable
1393 * @vdev: pointer to vdev
1394 * @vp_id: vpath for which to disable the interrupts
1395 *
1396 * Disables the interrupts for the vpath
1397*/
1398void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
1399{
1400 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
1401 int msix_id;
1402
1403 vxge_hw_vpath_intr_disable(vpath->handle);
1404
1405 if (vdev->config.intr_type == INTA)
1406 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1407 else {
1408 msix_id = vp_id * VXGE_HW_VPATH_MSIX_ACTIVE;
1409 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1410 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1411
1412 /* disable the alarm vector */
1413 msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
1414 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1415 }
1416}
1417
1418/*
1419 * vxge_reset_vpath
1420 * @vdev: pointer to vdev
1421 * @vp_id: vpath to reset
1422 *
1423 * Resets the vpath
1424*/
1425static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1426{
1427 enum vxge_hw_status status = VXGE_HW_OK;
1428 int ret = 0;
1429
1430 /* check if device is down already */
1431 if (unlikely(!is_vxge_card_up(vdev)))
1432 return 0;
1433
1434 /* is device reset already scheduled */
1435 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1436 return 0;
1437
1438 if (vdev->vpaths[vp_id].handle) {
1439 if (vxge_hw_vpath_reset(vdev->vpaths[vp_id].handle)
1440 == VXGE_HW_OK) {
1441 if (is_vxge_card_up(vdev) &&
1442 vxge_hw_vpath_recover_from_reset(
1443 vdev->vpaths[vp_id].handle)
1444 != VXGE_HW_OK) {
1445 vxge_debug_init(VXGE_ERR,
1446 "vxge_hw_vpath_recover_from_reset"
1447 "failed for vpath:%d", vp_id);
1448 return status;
1449 }
1450 } else {
1451 vxge_debug_init(VXGE_ERR,
1452 "vxge_hw_vpath_reset failed for"
1453 "vpath:%d", vp_id);
1454 return status;
1455 }
1456 } else
1457 return VXGE_HW_FAIL;
1458
1459 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1460 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1461
1462 /* Enable all broadcast */
1463 vxge_hw_vpath_bcast_enable(vdev->vpaths[vp_id].handle);
1464
1465 /* Enable the interrupts */
1466 vxge_vpath_intr_enable(vdev, vp_id);
1467
1468 smp_wmb();
1469
1470 /* Enable the flow of traffic through the vpath */
1471 vxge_hw_vpath_enable(vdev->vpaths[vp_id].handle);
1472
1473 smp_wmb();
1474 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[vp_id].handle);
1475 vdev->vpaths[vp_id].ring.last_status = VXGE_HW_OK;
1476
1477 /* Vpath reset done */
1478 clear_bit(vp_id, &vdev->vp_reset);
1479
1480 /* Start the vpath queue */
1481 vxge_wake_tx_queue(&vdev->vpaths[vp_id].fifo, NULL);
1482
1483 return ret;
1484}
1485
1486static int do_vxge_reset(struct vxgedev *vdev, int event)
1487{
1488 enum vxge_hw_status status;
1489 int ret = 0, vp_id, i;
1490
1491 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1492
1493 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1494 /* check if device is down already */
1495 if (unlikely(!is_vxge_card_up(vdev)))
1496 return 0;
1497
1498 /* is reset already scheduled */
1499 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1500 return 0;
1501 }
1502
1503 if (event == VXGE_LL_FULL_RESET) {
1504 /* wait for all the vpath reset to complete */
1505 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1506 while (test_bit(vp_id, &vdev->vp_reset))
1507 msleep(50);
1508 }
1509
1510 /* if execution mode is set to debug, don't reset the adapter */
1511 if (unlikely(vdev->exec_mode)) {
1512 vxge_debug_init(VXGE_ERR,
1513 "%s: execution mode is debug, returning..",
1514 vdev->ndev->name);
1515 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1516 vxge_stop_all_tx_queue(vdev);
1517 return 0;
1518 }
1519 }
1520
1521 if (event == VXGE_LL_FULL_RESET) {
1522 vxge_hw_device_intr_disable(vdev->devh);
1523
1524 switch (vdev->cric_err_event) {
1525 case VXGE_HW_EVENT_UNKNOWN:
1526 vxge_stop_all_tx_queue(vdev);
1527 vxge_debug_init(VXGE_ERR,
1528 "fatal: %s: Disabling device due to"
1529 "unknown error",
1530 vdev->ndev->name);
1531 ret = -EPERM;
1532 goto out;
1533 case VXGE_HW_EVENT_RESET_START:
1534 break;
1535 case VXGE_HW_EVENT_RESET_COMPLETE:
1536 case VXGE_HW_EVENT_LINK_DOWN:
1537 case VXGE_HW_EVENT_LINK_UP:
1538 case VXGE_HW_EVENT_ALARM_CLEARED:
1539 case VXGE_HW_EVENT_ECCERR:
1540 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1541 ret = -EPERM;
1542 goto out;
1543 case VXGE_HW_EVENT_FIFO_ERR:
1544 case VXGE_HW_EVENT_VPATH_ERR:
1545 break;
1546 case VXGE_HW_EVENT_CRITICAL_ERR:
1547 vxge_stop_all_tx_queue(vdev);
1548 vxge_debug_init(VXGE_ERR,
1549 "fatal: %s: Disabling device due to"
1550 "serious error",
1551 vdev->ndev->name);
1552 /* SOP or device reset required */
1553 /* This event is not currently used */
1554 ret = -EPERM;
1555 goto out;
1556 case VXGE_HW_EVENT_SERR:
1557 vxge_stop_all_tx_queue(vdev);
1558 vxge_debug_init(VXGE_ERR,
1559 "fatal: %s: Disabling device due to"
1560 "serious error",
1561 vdev->ndev->name);
1562 ret = -EPERM;
1563 goto out;
1564 case VXGE_HW_EVENT_SRPCIM_SERR:
1565 case VXGE_HW_EVENT_MRPCIM_SERR:
1566 ret = -EPERM;
1567 goto out;
1568 case VXGE_HW_EVENT_SLOT_FREEZE:
1569 vxge_stop_all_tx_queue(vdev);
1570 vxge_debug_init(VXGE_ERR,
1571 "fatal: %s: Disabling device due to"
1572 "slot freeze",
1573 vdev->ndev->name);
1574 ret = -EPERM;
1575 goto out;
1576 default:
1577 break;
1578
1579 }
1580 }
1581
1582 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
1583 vxge_stop_all_tx_queue(vdev);
1584
1585 if (event == VXGE_LL_FULL_RESET) {
1586 status = vxge_reset_all_vpaths(vdev);
1587 if (status != VXGE_HW_OK) {
1588 vxge_debug_init(VXGE_ERR,
1589 "fatal: %s: can not reset vpaths",
1590 vdev->ndev->name);
1591 ret = -EPERM;
1592 goto out;
1593 }
1594 }
1595
1596 if (event == VXGE_LL_COMPL_RESET) {
1597 for (i = 0; i < vdev->no_of_vpath; i++)
1598 if (vdev->vpaths[i].handle) {
1599 if (vxge_hw_vpath_recover_from_reset(
1600 vdev->vpaths[i].handle)
1601 != VXGE_HW_OK) {
1602 vxge_debug_init(VXGE_ERR,
1603 "vxge_hw_vpath_recover_"
1604 "from_reset failed for vpath: "
1605 "%d", i);
1606 ret = -EPERM;
1607 goto out;
1608 }
1609 } else {
1610 vxge_debug_init(VXGE_ERR,
1611 "vxge_hw_vpath_reset failed for "
1612 "vpath:%d", i);
1613 ret = -EPERM;
1614 goto out;
1615 }
1616 }
1617
1618 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1619 /* Reprogram the DA table with populated mac addresses */
1620 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1621 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1622 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1623 }
1624
1625 /* enable vpath interrupts */
1626 for (i = 0; i < vdev->no_of_vpath; i++)
1627 vxge_vpath_intr_enable(vdev, i);
1628
1629 vxge_hw_device_intr_enable(vdev->devh);
1630
1631 smp_wmb();
1632
1633 /* Indicate card up */
1634 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1635
1636 /* Get the traffic to flow through the vpaths */
1637 for (i = 0; i < vdev->no_of_vpath; i++) {
1638 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1639 smp_wmb();
1640 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1641 }
1642
1643 vxge_wake_all_tx_queue(vdev);
1644 }
1645
1646out:
1647 vxge_debug_entryexit(VXGE_TRACE,
1648 "%s:%d Exiting...", __func__, __LINE__);
1649
1650 /* Indicate reset done */
1651 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1652 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1653 return ret;
1654}
1655
1656/*
1657 * vxge_reset
1658 * @vdev: pointer to ll device
1659 *
1660 * driver may reset the chip on events of serr, eccerr, etc
1661 */
1662int vxge_reset(struct vxgedev *vdev)
1663{
1664 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
1665 return 0;
1666}
1667
1668/**
1669 * vxge_poll - Receive handler when Receive Polling is used.
1670 * @dev: pointer to the device structure.
1671 * @budget: Number of packets budgeted to be processed in this iteration.
1672 *
1673 * This function comes into picture only if Receive side is being handled
1674 * through polling (called NAPI in linux). It mostly does what the normal
1675 * Rx interrupt handler does in terms of descriptor and packet processing
1676 * but not in an interrupt context. Also it will process a specified number
1677 * of packets at most in one iteration. This value is passed down by the
1678 * kernel as the function argument 'budget'.
1679 */
1680static int vxge_poll_msix(struct napi_struct *napi, int budget)
1681{
1682 struct vxge_ring *ring =
1683 container_of(napi, struct vxge_ring, napi);
1684 int budget_org = budget;
1685 ring->budget = budget;
1686
1687 vxge_hw_vpath_poll_rx(ring->handle);
1688
1689 if (ring->pkts_processed < budget_org) {
1690 napi_complete(napi);
1691 /* Re enable the Rx interrupts for the vpath */
1692 vxge_hw_channel_msix_unmask(
1693 (struct __vxge_hw_channel *)ring->handle,
1694 ring->rx_vector_no);
1695 }
1696
1697 return ring->pkts_processed;
1698}
1699
1700static int vxge_poll_inta(struct napi_struct *napi, int budget)
1701{
1702 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1703 int pkts_processed = 0;
1704 int i;
1705 int budget_org = budget;
1706 struct vxge_ring *ring;
1707
1708 struct __vxge_hw_device *hldev = (struct __vxge_hw_device *)
1709 pci_get_drvdata(vdev->pdev);
1710
1711 for (i = 0; i < vdev->no_of_vpath; i++) {
1712 ring = &vdev->vpaths[i].ring;
1713 ring->budget = budget;
1714 vxge_hw_vpath_poll_rx(ring->handle);
1715 pkts_processed += ring->pkts_processed;
1716 budget -= ring->pkts_processed;
1717 if (budget <= 0)
1718 break;
1719 }
1720
1721 VXGE_COMPLETE_ALL_TX(vdev);
1722
1723 if (pkts_processed < budget_org) {
1724 napi_complete(napi);
1725 /* Re enable the Rx interrupts for the ring */
1726 vxge_hw_device_unmask_all(hldev);
1727 vxge_hw_device_flush_io(hldev);
1728 }
1729
1730 return pkts_processed;
1731}
1732
1733#ifdef CONFIG_NET_POLL_CONTROLLER
1734/**
1735 * vxge_netpoll - netpoll event handler entry point
1736 * @dev : pointer to the device structure.
1737 * Description:
1738 * This function will be called by upper layer to check for events on the
1739 * interface in situations where interrupts are disabled. It is used for
1740 * specific in-kernel networking tasks, such as remote consoles and kernel
1741 * debugging over the network (example netdump in RedHat).
1742 */
1743static void vxge_netpoll(struct net_device *dev)
1744{
1745 struct __vxge_hw_device *hldev;
1746 struct vxgedev *vdev;
1747
1748 vdev = (struct vxgedev *)netdev_priv(dev);
1749 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
1750
1751 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1752
1753 if (pci_channel_offline(vdev->pdev))
1754 return;
1755
1756 disable_irq(dev->irq);
1757 vxge_hw_device_clear_tx_rx(hldev);
1758
1759 vxge_hw_device_clear_tx_rx(hldev);
1760 VXGE_COMPLETE_ALL_RX(vdev);
1761 VXGE_COMPLETE_ALL_TX(vdev);
1762
1763 enable_irq(dev->irq);
1764
1765 vxge_debug_entryexit(VXGE_TRACE,
1766 "%s:%d Exiting...", __func__, __LINE__);
1767 return;
1768}
1769#endif
1770
1771/* RTH configuration */
1772static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1773{
1774 enum vxge_hw_status status = VXGE_HW_OK;
1775 struct vxge_hw_rth_hash_types hash_types;
1776 u8 itable[256] = {0}; /* indirection table */
1777 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1778 int index;
1779
1780 /*
1781 * Filling
1782 * - itable with bucket numbers
1783 * - mtable with bucket-to-vpath mapping
1784 */
1785 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1786 itable[index] = index;
1787 mtable[index] = index % vdev->no_of_vpath;
1788 }
1789
1790 /* Fill RTH hash types */
1791 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1792 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1793 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1794 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1795 hash_types.hash_type_tcpipv6ex_en =
1796 vdev->config.rth_hash_type_tcpipv6ex;
1797 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1798
1799 /* set indirection table, bucket-to-vpath mapping */
1800 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1801 vdev->no_of_vpath,
1802 mtable, itable,
1803 vdev->config.rth_bkt_sz);
1804 if (status != VXGE_HW_OK) {
1805 vxge_debug_init(VXGE_ERR,
1806 "RTH indirection table configuration failed "
1807 "for vpath:%d", vdev->vpaths[0].device_id);
1808 return status;
1809 }
1810
1811 /*
1812 * Because the itable_set() method uses the active_table field
1813 * for the target virtual path the RTH config should be updated
1814 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1815 * when steering frames.
1816 */
1817 for (index = 0; index < vdev->no_of_vpath; index++) {
1818 status = vxge_hw_vpath_rts_rth_set(
1819 vdev->vpaths[index].handle,
1820 vdev->config.rth_algorithm,
1821 &hash_types,
1822 vdev->config.rth_bkt_sz);
1823
1824 if (status != VXGE_HW_OK) {
1825 vxge_debug_init(VXGE_ERR,
1826 "RTH configuration failed for vpath:%d",
1827 vdev->vpaths[index].device_id);
1828 return status;
1829 }
1830 }
1831
1832 return status;
1833}
1834
1835int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
1836{
1837 struct vxge_mac_addrs *new_mac_entry;
1838 u8 *mac_address = NULL;
1839
1840 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
1841 return TRUE;
1842
1843 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
1844 if (!new_mac_entry) {
1845 vxge_debug_mem(VXGE_ERR,
1846 "%s: memory allocation failed",
1847 VXGE_DRIVER_NAME);
1848 return FALSE;
1849 }
1850
1851 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
1852
1853 /* Copy the new mac address to the list */
1854 mac_address = (u8 *)&new_mac_entry->macaddr;
1855 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1856
1857 new_mac_entry->state = mac->state;
1858 vpath->mac_addr_cnt++;
1859
1860 /* Is this a multicast address */
1861 if (0x01 & mac->macaddr[0])
1862 vpath->mcast_addr_cnt++;
1863
1864 return TRUE;
1865}
1866
1867/* Add a mac address to DA table */
1868enum vxge_hw_status vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1869{
1870 enum vxge_hw_status status = VXGE_HW_OK;
1871 struct vxge_vpath *vpath;
1872 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
1873
1874 if (0x01 & mac->macaddr[0]) /* multicast address */
1875 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
1876 else
1877 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
1878
1879 vpath = &vdev->vpaths[mac->vpath_no];
1880 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
1881 mac->macmask, duplicate_mode);
1882 if (status != VXGE_HW_OK) {
1883 vxge_debug_init(VXGE_ERR,
1884 "DA config add entry failed for vpath:%d",
1885 vpath->device_id);
1886 } else
1887 if (FALSE == vxge_mac_list_add(vpath, mac))
1888 status = -EPERM;
1889
1890 return status;
1891}
1892
1893int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1894{
1895 struct list_head *entry, *next;
1896 u64 del_mac = 0;
1897 u8 *mac_address = (u8 *) (&del_mac);
1898
1899 /* Copy the mac address to delete from the list */
1900 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1901
1902 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1903 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1904 list_del(entry);
1905 kfree((struct vxge_mac_addrs *)entry);
1906 vpath->mac_addr_cnt--;
1907
1908 /* Is this a multicast address */
1909 if (0x01 & mac->macaddr[0])
1910 vpath->mcast_addr_cnt--;
1911 return TRUE;
1912 }
1913 }
1914
1915 return FALSE;
1916}
1917/* delete a mac address from DA table */
1918enum vxge_hw_status vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1919{
1920 enum vxge_hw_status status = VXGE_HW_OK;
1921 struct vxge_vpath *vpath;
1922
1923 vpath = &vdev->vpaths[mac->vpath_no];
1924 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1925 mac->macmask);
1926 if (status != VXGE_HW_OK) {
1927 vxge_debug_init(VXGE_ERR,
1928 "DA config delete entry failed for vpath:%d",
1929 vpath->device_id);
1930 } else
1931 vxge_mac_list_del(vpath, mac);
1932 return status;
1933}
1934
1935/* list all mac addresses from DA table */
1936enum vxge_hw_status
1937static vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath,
1938 struct macInfo *mac)
1939{
1940 enum vxge_hw_status status = VXGE_HW_OK;
1941 unsigned char macmask[ETH_ALEN];
1942 unsigned char macaddr[ETH_ALEN];
1943
1944 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1945 macaddr, macmask);
1946 if (status != VXGE_HW_OK) {
1947 vxge_debug_init(VXGE_ERR,
1948 "DA config list entry failed for vpath:%d",
1949 vpath->device_id);
1950 return status;
1951 }
1952
1953 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1954
1955 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1956 macaddr, macmask);
1957 if (status != VXGE_HW_OK)
1958 break;
1959 }
1960
1961 return status;
1962}
1963
1964/* Store all vlan ids from the list to the vid table */
1965enum vxge_hw_status vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1966{
1967 enum vxge_hw_status status = VXGE_HW_OK;
1968 struct vxgedev *vdev = vpath->vdev;
1969 u16 vid;
1970
1971 if (vdev->vlgrp && vpath->is_open) {
1972
1973 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
1974 if (!vlan_group_get_device(vdev->vlgrp, vid))
1975 continue;
1976 /* Add these vlan to the vid table */
1977 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
1978 }
1979 }
1980
1981 return status;
1982}
1983
1984/* Store all mac addresses from the list to the DA table */
1985enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1986{
1987 enum vxge_hw_status status = VXGE_HW_OK;
1988 struct macInfo mac_info;
1989 u8 *mac_address = NULL;
1990 struct list_head *entry, *next;
1991
1992 memset(&mac_info, 0, sizeof(struct macInfo));
1993
1994 if (vpath->is_open) {
1995
1996 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1997 mac_address =
1998 (u8 *)&
1999 ((struct vxge_mac_addrs *)entry)->macaddr;
2000 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
2001 ((struct vxge_mac_addrs *)entry)->state =
2002 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
2003 /* does this mac address already exist in da table? */
2004 status = vxge_search_mac_addr_in_da_table(vpath,
2005 &mac_info);
2006 if (status != VXGE_HW_OK) {
2007 /* Add this mac address to the DA table */
2008 status = vxge_hw_vpath_mac_addr_add(
2009 vpath->handle, mac_info.macaddr,
2010 mac_info.macmask,
2011 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
2012 if (status != VXGE_HW_OK) {
2013 vxge_debug_init(VXGE_ERR,
2014 "DA add entry failed for vpath:%d",
2015 vpath->device_id);
2016 ((struct vxge_mac_addrs *)entry)->state
2017 = VXGE_LL_MAC_ADDR_IN_LIST;
2018 }
2019 }
2020 }
2021 }
2022
2023 return status;
2024}
2025
2026/* reset vpaths */
2027enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
2028{
2029 int i;
2030 enum vxge_hw_status status = VXGE_HW_OK;
2031
2032 for (i = 0; i < vdev->no_of_vpath; i++)
2033 if (vdev->vpaths[i].handle) {
2034 if (vxge_hw_vpath_reset(vdev->vpaths[i].handle)
2035 == VXGE_HW_OK) {
2036 if (is_vxge_card_up(vdev) &&
2037 vxge_hw_vpath_recover_from_reset(
2038 vdev->vpaths[i].handle)
2039 != VXGE_HW_OK) {
2040 vxge_debug_init(VXGE_ERR,
2041 "vxge_hw_vpath_recover_"
2042 "from_reset failed for vpath: "
2043 "%d", i);
2044 return status;
2045 }
2046 } else {
2047 vxge_debug_init(VXGE_ERR,
2048 "vxge_hw_vpath_reset failed for "
2049 "vpath:%d", i);
2050 return status;
2051 }
2052 }
2053 return status;
2054}
2055
2056/* close vpaths */
2057void vxge_close_vpaths(struct vxgedev *vdev, int index)
2058{
2059 int i;
2060 for (i = index; i < vdev->no_of_vpath; i++) {
2061 if (vdev->vpaths[i].handle && vdev->vpaths[i].is_open) {
2062 vxge_hw_vpath_close(vdev->vpaths[i].handle);
2063 vdev->stats.vpaths_open--;
2064 }
2065 vdev->vpaths[i].is_open = 0;
2066 vdev->vpaths[i].handle = NULL;
2067 }
2068}
2069
2070/* open vpaths */
2071int vxge_open_vpaths(struct vxgedev *vdev)
2072{
2073 enum vxge_hw_status status;
2074 int i;
2075 u32 vp_id = 0;
2076 struct vxge_hw_vpath_attr attr;
2077
2078 for (i = 0; i < vdev->no_of_vpath; i++) {
2079 vxge_assert(vdev->vpaths[i].is_configured);
2080 attr.vp_id = vdev->vpaths[i].device_id;
2081 attr.fifo_attr.callback = vxge_xmit_compl;
2082 attr.fifo_attr.txdl_term = vxge_tx_term;
2083 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
2084 attr.fifo_attr.userdata = (void *)&vdev->vpaths[i].fifo;
2085
2086 attr.ring_attr.callback = vxge_rx_1b_compl;
2087 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2088 attr.ring_attr.rxd_term = vxge_rx_term;
2089 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
2090 attr.ring_attr.userdata = (void *)&vdev->vpaths[i].ring;
2091
2092 vdev->vpaths[i].ring.ndev = vdev->ndev;
2093 vdev->vpaths[i].ring.pdev = vdev->pdev;
2094 status = vxge_hw_vpath_open(vdev->devh, &attr,
2095 &(vdev->vpaths[i].handle));
2096 if (status == VXGE_HW_OK) {
2097 vdev->vpaths[i].fifo.handle =
2098 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
2099 vdev->vpaths[i].ring.handle =
2100 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
2101 vdev->vpaths[i].fifo.tx_steering_type =
2102 vdev->config.tx_steering_type;
2103 vdev->vpaths[i].fifo.ndev = vdev->ndev;
2104 vdev->vpaths[i].fifo.pdev = vdev->pdev;
2105 vdev->vpaths[i].fifo.indicate_max_pkts =
2106 vdev->config.fifo_indicate_max_pkts;
2107 vdev->vpaths[i].ring.rx_vector_no = 0;
2108 vdev->vpaths[i].ring.rx_csum = vdev->rx_csum;
2109 vdev->vpaths[i].is_open = 1;
2110 vdev->vp_handles[i] = vdev->vpaths[i].handle;
2111 vdev->vpaths[i].ring.gro_enable =
2112 vdev->config.gro_enable;
2113 vdev->vpaths[i].ring.vlan_tag_strip =
2114 vdev->vlan_tag_strip;
2115 vdev->stats.vpaths_open++;
2116 } else {
2117 vdev->stats.vpath_open_fail++;
2118 vxge_debug_init(VXGE_ERR,
2119 "%s: vpath: %d failed to open "
2120 "with status: %d",
2121 vdev->ndev->name, vdev->vpaths[i].device_id,
2122 status);
2123 vxge_close_vpaths(vdev, 0);
2124 return -EPERM;
2125 }
2126
2127 vp_id =
2128 ((struct __vxge_hw_vpath_handle *)vdev->vpaths[i].handle)->
2129 vpath->vp_id;
2130 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2131 }
2132 return VXGE_HW_OK;
2133}
2134
2135/*
2136 * vxge_isr_napi
2137 * @irq: the irq of the device.
2138 * @dev_id: a void pointer to the hldev structure of the Titan device
2139 * @ptregs: pointer to the registers pushed on the stack.
2140 *
2141 * This function is the ISR handler of the device when napi is enabled. It
2142 * identifies the reason for the interrupt and calls the relevant service
2143 * routines.
2144 */
2145static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2146{
703da5a1 2147 struct net_device *dev;
a5d165b5 2148 struct __vxge_hw_device *hldev;
703da5a1
RV
2149 u64 reason;
2150 enum vxge_hw_status status;
a5d165b5 2151 struct vxgedev *vdev = (struct vxgedev *) dev_id;;
703da5a1
RV
2152
2153 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2154
a5d165b5
SH
2155 dev = vdev->ndev;
2156 hldev = (struct __vxge_hw_device *)pci_get_drvdata(vdev->pdev);
703da5a1
RV
2157
2158 if (pci_channel_offline(vdev->pdev))
2159 return IRQ_NONE;
2160
2161 if (unlikely(!is_vxge_card_up(vdev)))
2162 return IRQ_NONE;
2163
2164 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode,
2165 &reason);
2166 if (status == VXGE_HW_OK) {
2167 vxge_hw_device_mask_all(hldev);
2168
2169 if (reason &
2170 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2171 vdev->vpaths_deployed >>
2172 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2173
2174 vxge_hw_device_clear_tx_rx(hldev);
2175 napi_schedule(&vdev->napi);
2176 vxge_debug_intr(VXGE_TRACE,
2177 "%s:%d Exiting...", __func__, __LINE__);
2178 return IRQ_HANDLED;
2179 } else
2180 vxge_hw_device_unmask_all(hldev);
2181 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2182 (status == VXGE_HW_ERR_CRITICAL) ||
2183 (status == VXGE_HW_ERR_FIFO))) {
2184 vxge_hw_device_mask_all(hldev);
2185 vxge_hw_device_flush_io(hldev);
2186 return IRQ_HANDLED;
2187 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2188 return IRQ_HANDLED;
2189
2190 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2191 return IRQ_NONE;
2192}
2193
2194#ifdef CONFIG_PCI_MSI
2195
2196static irqreturn_t
2197vxge_tx_msix_handle(int irq, void *dev_id)
2198{
2199 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2200
2201 VXGE_COMPLETE_VPATH_TX(fifo);
2202
2203 return IRQ_HANDLED;
2204}
2205
2206static irqreturn_t
2207vxge_rx_msix_napi_handle(int irq, void *dev_id)
2208{
2209 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2210
2211 /* MSIX_IDX for Rx is 1 */
2212 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
2213 ring->rx_vector_no);
2214
2215 napi_schedule(&ring->napi);
2216 return IRQ_HANDLED;
2217}
2218
2219static irqreturn_t
2220vxge_alarm_msix_handle(int irq, void *dev_id)
2221{
2222 int i;
2223 enum vxge_hw_status status;
2224 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2225 struct vxgedev *vdev = vpath->vdev;
2226 int alarm_msix_id =
2227 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2228
2229 for (i = 0; i < vdev->no_of_vpath; i++) {
2230 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle,
2231 alarm_msix_id);
2232
2233 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2234 vdev->exec_mode);
2235 if (status == VXGE_HW_OK) {
2236
2237 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
2238 alarm_msix_id);
2239 continue;
2240 }
2241 vxge_debug_intr(VXGE_ERR,
2242 "%s: vxge_hw_vpath_alarm_process failed %x ",
2243 VXGE_DRIVER_NAME, status);
2244 }
2245 return IRQ_HANDLED;
2246}
2247
2248static int vxge_alloc_msix(struct vxgedev *vdev)
2249{
2250 int j, i, ret = 0;
2251 int intr_cnt = 0;
2252 int alarm_msix_id = 0, msix_intr_vect = 0;
2253 vdev->intr_cnt = 0;
2254
2255 /* Tx/Rx MSIX Vectors count */
2256 vdev->intr_cnt = vdev->no_of_vpath * 2;
2257
2258 /* Alarm MSIX Vectors count */
2259 vdev->intr_cnt++;
2260
2261 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2262 vdev->entries = kzalloc(intr_cnt * sizeof(struct msix_entry),
2263 GFP_KERNEL);
2264 if (!vdev->entries) {
2265 vxge_debug_init(VXGE_ERR,
2266 "%s: memory allocation failed",
2267 VXGE_DRIVER_NAME);
2268 return -ENOMEM;
2269 }
2270
2271 vdev->vxge_entries = kzalloc(intr_cnt * sizeof(struct vxge_msix_entry),
2272 GFP_KERNEL);
2273 if (!vdev->vxge_entries) {
2274 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2275 VXGE_DRIVER_NAME);
2276 kfree(vdev->entries);
2277 return -ENOMEM;
2278 }
2279
2280 /* Last vector in the list is used for alarm */
2281 alarm_msix_id = VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2282 for (i = 0, j = 0; i < vdev->max_vpath_supported; i++) {
2283
2284 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2285
2286 /* Initialize the fifo vector */
2287 vdev->entries[j].entry = msix_intr_vect;
2288 vdev->vxge_entries[j].entry = msix_intr_vect;
2289 vdev->vxge_entries[j].in_use = 0;
2290 j++;
2291
2292 /* Initialize the ring vector */
2293 vdev->entries[j].entry = msix_intr_vect + 1;
2294 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2295 vdev->vxge_entries[j].in_use = 0;
2296 j++;
2297 }
2298
2299 /* Initialize the alarm vector */
2300 vdev->entries[j].entry = alarm_msix_id;
2301 vdev->vxge_entries[j].entry = alarm_msix_id;
2302 vdev->vxge_entries[j].in_use = 0;
2303
2304 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2305 /* if driver request exceeeds available irq's, request with a small
2306 * number.
2307 */
2308 if (ret > 0) {
2309 vxge_debug_init(VXGE_ERR,
2310 "%s: MSI-X enable failed for %d vectors, available: %d",
2311 VXGE_DRIVER_NAME, intr_cnt, ret);
2312 vdev->max_vpath_supported = vdev->no_of_vpath;
2313 intr_cnt = (vdev->max_vpath_supported * 2) + 1;
2314
2315 /* Reset the alarm vector setting */
2316 vdev->entries[j].entry = 0;
2317 vdev->vxge_entries[j].entry = 0;
2318
2319 /* Initialize the alarm vector with new setting */
2320 vdev->entries[intr_cnt - 1].entry = alarm_msix_id;
2321 vdev->vxge_entries[intr_cnt - 1].entry = alarm_msix_id;
2322 vdev->vxge_entries[intr_cnt - 1].in_use = 0;
2323
2324 ret = pci_enable_msix(vdev->pdev, vdev->entries, intr_cnt);
2325 if (!ret)
2326 vxge_debug_init(VXGE_ERR,
2327 "%s: MSI-X enabled for %d vectors",
2328 VXGE_DRIVER_NAME, intr_cnt);
2329 }
2330
2331 if (ret) {
2332 vxge_debug_init(VXGE_ERR,
2333 "%s: MSI-X enable failed for %d vectors, ret: %d",
2334 VXGE_DRIVER_NAME, intr_cnt, ret);
2335 kfree(vdev->entries);
2336 kfree(vdev->vxge_entries);
2337 vdev->entries = NULL;
2338 vdev->vxge_entries = NULL;
2339 return -ENODEV;
2340 }
2341 return 0;
2342}
2343
2344static int vxge_enable_msix(struct vxgedev *vdev)
2345{
2346
2347 int i, ret = 0;
2348 enum vxge_hw_status status;
2349 /* 0 - Tx, 1 - Rx */
2350 int tim_msix_id[4];
2351 int alarm_msix_id = 0, msix_intr_vect = 0;;
2352 vdev->intr_cnt = 0;
2353
2354 /* allocate msix vectors */
2355 ret = vxge_alloc_msix(vdev);
2356 if (!ret) {
2357 /* Last vector in the list is used for alarm */
2358 alarm_msix_id =
2359 VXGE_HW_VPATH_MSIX_ACTIVE * vdev->no_of_vpath - 2;
2360 for (i = 0; i < vdev->no_of_vpath; i++) {
2361
2362 /* If fifo or ring are not enabled
2363 the MSIX vector for that should be set to 0
2364 Hence initializeing this array to all 0s.
2365 */
2366 memset(tim_msix_id, 0, sizeof(tim_msix_id));
2367 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2368 tim_msix_id[0] = msix_intr_vect;
2369
2370 tim_msix_id[1] = msix_intr_vect + 1;
2371 vdev->vpaths[i].ring.rx_vector_no = tim_msix_id[1];
2372
2373 status = vxge_hw_vpath_msix_set(
2374 vdev->vpaths[i].handle,
2375 tim_msix_id, alarm_msix_id);
2376 if (status != VXGE_HW_OK) {
2377 vxge_debug_init(VXGE_ERR,
2378 "vxge_hw_vpath_msix_set "
2379 "failed with status : %x", status);
2380 kfree(vdev->entries);
2381 kfree(vdev->vxge_entries);
2382 pci_disable_msix(vdev->pdev);
2383 return -ENODEV;
2384 }
2385 }
2386 }
2387
2388 return ret;
2389}
2390
2391static void vxge_rem_msix_isr(struct vxgedev *vdev)
2392{
2393 int intr_cnt;
2394
2395 for (intr_cnt = 0; intr_cnt < (vdev->max_vpath_supported * 2 + 1);
2396 intr_cnt++) {
2397 if (vdev->vxge_entries[intr_cnt].in_use) {
2398 synchronize_irq(vdev->entries[intr_cnt].vector);
2399 free_irq(vdev->entries[intr_cnt].vector,
2400 vdev->vxge_entries[intr_cnt].arg);
2401 vdev->vxge_entries[intr_cnt].in_use = 0;
2402 }
2403 }
2404
2405 kfree(vdev->entries);
2406 kfree(vdev->vxge_entries);
2407 vdev->entries = NULL;
2408 vdev->vxge_entries = NULL;
2409
2410 if (vdev->config.intr_type == MSI_X)
2411 pci_disable_msix(vdev->pdev);
2412}
2413#endif
2414
2415static void vxge_rem_isr(struct vxgedev *vdev)
2416{
2417 struct __vxge_hw_device *hldev;
2418 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2419
2420#ifdef CONFIG_PCI_MSI
2421 if (vdev->config.intr_type == MSI_X) {
2422 vxge_rem_msix_isr(vdev);
2423 } else
2424#endif
2425 if (vdev->config.intr_type == INTA) {
2426 synchronize_irq(vdev->pdev->irq);
a5d165b5 2427 free_irq(vdev->pdev->irq, vdev);
703da5a1
RV
2428 }
2429}
2430
2431static int vxge_add_isr(struct vxgedev *vdev)
2432{
2433 int ret = 0;
703da5a1
RV
2434#ifdef CONFIG_PCI_MSI
2435 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
2436 u64 function_mode = vdev->config.device_hw_info.function_mode;
2437 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2438
2439 if (vdev->config.intr_type == MSI_X)
2440 ret = vxge_enable_msix(vdev);
2441
2442 if (ret) {
2443 vxge_debug_init(VXGE_ERR,
2444 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
2445 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2446 test_and_set_bit(__VXGE_STATE_CARD_UP,
2447 &driver_config->inta_dev_open))
2448 return VXGE_HW_FAIL;
2449 else {
2450 vxge_debug_init(VXGE_ERR,
2451 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2452 vdev->config.intr_type = INTA;
2453 vxge_hw_device_set_intr_type(vdev->devh,
2454 VXGE_HW_INTR_MODE_IRQLINE);
2455 vxge_close_vpaths(vdev, 1);
2456 vdev->no_of_vpath = 1;
2457 vdev->stats.vpaths_open = 1;
2458 }
2459 }
2460
2461 if (vdev->config.intr_type == MSI_X) {
2462 for (intr_idx = 0;
2463 intr_idx < (vdev->no_of_vpath *
2464 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2465
2466 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2467 irq_req = 0;
2468
2469 switch (msix_idx) {
2470 case 0:
2471 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2472 "%s:vxge fn: %d vpath: %d Tx MSI-X: %d",
2473 vdev->ndev->name, pci_fun, vp_idx,
2474 vdev->entries[intr_cnt].entry);
2475 ret = request_irq(
2476 vdev->entries[intr_cnt].vector,
2477 vxge_tx_msix_handle, 0,
2478 vdev->desc[intr_cnt],
2479 &vdev->vpaths[vp_idx].fifo);
2480 vdev->vxge_entries[intr_cnt].arg =
2481 &vdev->vpaths[vp_idx].fifo;
2482 irq_req = 1;
2483 break;
2484 case 1:
2485 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2486 "%s:vxge fn: %d vpath: %d Rx MSI-X: %d",
2487 vdev->ndev->name, pci_fun, vp_idx,
2488 vdev->entries[intr_cnt].entry);
2489 ret = request_irq(
2490 vdev->entries[intr_cnt].vector,
2491 vxge_rx_msix_napi_handle,
2492 0,
2493 vdev->desc[intr_cnt],
2494 &vdev->vpaths[vp_idx].ring);
2495 vdev->vxge_entries[intr_cnt].arg =
2496 &vdev->vpaths[vp_idx].ring;
2497 irq_req = 1;
2498 break;
2499 }
2500
2501 if (ret) {
2502 vxge_debug_init(VXGE_ERR,
2503 "%s: MSIX - %d Registration failed",
2504 vdev->ndev->name, intr_cnt);
2505 vxge_rem_msix_isr(vdev);
2506 if ((function_mode ==
2507 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2508 test_and_set_bit(__VXGE_STATE_CARD_UP,
2509 &driver_config->inta_dev_open))
2510 return VXGE_HW_FAIL;
2511 else {
2512 vxge_hw_device_set_intr_type(
2513 vdev->devh,
2514 VXGE_HW_INTR_MODE_IRQLINE);
2515 vdev->config.intr_type = INTA;
2516 vxge_debug_init(VXGE_ERR,
2517 "%s: Defaulting to INTA"
2518 , vdev->ndev->name);
2519 vxge_close_vpaths(vdev, 1);
2520 vdev->no_of_vpath = 1;
2521 vdev->stats.vpaths_open = 1;
2522 goto INTA_MODE;
2523 }
2524 }
2525
2526 if (irq_req) {
2527 /* We requested for this msix interrupt */
2528 vdev->vxge_entries[intr_cnt].in_use = 1;
2529 vxge_hw_vpath_msix_unmask(
2530 vdev->vpaths[vp_idx].handle,
2531 intr_idx);
2532 intr_cnt++;
2533 }
2534
2535 /* Point to next vpath handler */
2536 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0)
2537 && (vp_idx < (vdev->no_of_vpath - 1)))
2538 vp_idx++;
2539 }
2540
2541 intr_cnt = vdev->max_vpath_supported * 2;
2542 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
2543 "%s:vxge Alarm fn: %d MSI-X: %d",
2544 vdev->ndev->name, pci_fun,
2545 vdev->entries[intr_cnt].entry);
2546 /* For Alarm interrupts */
2547 ret = request_irq(vdev->entries[intr_cnt].vector,
2548 vxge_alarm_msix_handle, 0,
2549 vdev->desc[intr_cnt],
2550 &vdev->vpaths[vp_idx]);
2551 if (ret) {
2552 vxge_debug_init(VXGE_ERR,
2553 "%s: MSIX - %d Registration failed",
2554 vdev->ndev->name, intr_cnt);
2555 vxge_rem_msix_isr(vdev);
2556 if ((function_mode ==
2557 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2558 test_and_set_bit(__VXGE_STATE_CARD_UP,
2559 &driver_config->inta_dev_open))
2560 return VXGE_HW_FAIL;
2561 else {
2562 vxge_hw_device_set_intr_type(vdev->devh,
2563 VXGE_HW_INTR_MODE_IRQLINE);
2564 vdev->config.intr_type = INTA;
2565 vxge_debug_init(VXGE_ERR,
2566 "%s: Defaulting to INTA",
2567 vdev->ndev->name);
2568 vxge_close_vpaths(vdev, 1);
2569 vdev->no_of_vpath = 1;
2570 vdev->stats.vpaths_open = 1;
2571 goto INTA_MODE;
2572 }
2573 }
2574
2575 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
2576 intr_idx - 2);
2577 vdev->vxge_entries[intr_cnt].in_use = 1;
2578 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[vp_idx];
2579 }
2580INTA_MODE:
2581#endif
2582 snprintf(vdev->desc[0], VXGE_INTR_STRLEN, "%s:vxge", vdev->ndev->name);
2583
2584 if (vdev->config.intr_type == INTA) {
2585 ret = request_irq((int) vdev->pdev->irq,
2586 vxge_isr_napi,
a5d165b5 2587 IRQF_SHARED, vdev->desc[0], vdev);
703da5a1
RV
2588 if (ret) {
2589 vxge_debug_init(VXGE_ERR,
2590 "%s %s-%d: ISR registration failed",
2591 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2592 return -ENODEV;
2593 }
2594 vxge_debug_init(VXGE_TRACE,
2595 "new %s-%d line allocated",
2596 "IRQ", vdev->pdev->irq);
2597 }
2598
2599 return VXGE_HW_OK;
2600}
2601
2602static void vxge_poll_vp_reset(unsigned long data)
2603{
2604 struct vxgedev *vdev = (struct vxgedev *)data;
2605 int i, j = 0;
2606
2607 for (i = 0; i < vdev->no_of_vpath; i++) {
2608 if (test_bit(i, &vdev->vp_reset)) {
2609 vxge_reset_vpath(vdev, i);
2610 j++;
2611 }
2612 }
2613 if (j && (vdev->config.intr_type != MSI_X)) {
2614 vxge_hw_device_unmask_all(vdev->devh);
2615 vxge_hw_device_flush_io(vdev->devh);
2616 }
2617
2618 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2619}
2620
2621static void vxge_poll_vp_lockup(unsigned long data)
2622{
2623 struct vxgedev *vdev = (struct vxgedev *)data;
2624 int i;
2625 struct vxge_ring *ring;
2626 enum vxge_hw_status status = VXGE_HW_OK;
2627
2628 for (i = 0; i < vdev->no_of_vpath; i++) {
2629 ring = &vdev->vpaths[i].ring;
2630 /* Did this vpath received any packets */
2631 if (ring->stats.prev_rx_frms == ring->stats.rx_frms) {
2632 status = vxge_hw_vpath_check_leak(ring->handle);
2633
2634 /* Did it received any packets last time */
2635 if ((VXGE_HW_FAIL == status) &&
2636 (VXGE_HW_FAIL == ring->last_status)) {
2637
2638 /* schedule vpath reset */
2639 if (!test_and_set_bit(i, &vdev->vp_reset)) {
2640
2641 /* disable interrupts for this vpath */
2642 vxge_vpath_intr_disable(vdev, i);
2643
2644 /* stop the queue for this vpath */
2645 vxge_stop_tx_queue(&vdev->vpaths[i].
2646 fifo);
2647 continue;
2648 }
2649 }
2650 }
2651 ring->stats.prev_rx_frms = ring->stats.rx_frms;
2652 ring->last_status = status;
2653 }
2654
2655 /* Check every 1 milli second */
2656 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2657}
2658
2659/**
2660 * vxge_open
2661 * @dev: pointer to the device structure.
2662 *
2663 * This function is the open entry point of the driver. It mainly calls a
2664 * function to allocate Rx buffers and inserts them into the buffer
2665 * descriptors and then enables the Rx part of the NIC.
2666 * Return value: '0' on success and an appropriate (-)ve integer as
2667 * defined in errno.h file on failure.
2668 */
2669int
2670vxge_open(struct net_device *dev)
2671{
2672 enum vxge_hw_status status;
2673 struct vxgedev *vdev;
2674 struct __vxge_hw_device *hldev;
2675 int ret = 0;
2676 int i;
2677 u64 val64, function_mode;
2678 vxge_debug_entryexit(VXGE_TRACE,
2679 "%s: %s:%d", dev->name, __func__, __LINE__);
2680
2681 vdev = (struct vxgedev *)netdev_priv(dev);
2682 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2683 function_mode = vdev->config.device_hw_info.function_mode;
2684
2685 /* make sure you have link off by default every time Nic is
2686 * initialized */
2687 netif_carrier_off(dev);
2688
2689 /* Check for another device already opn with INTA */
2690 if ((function_mode == VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION) &&
2691 test_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open)) {
2692 ret = -EPERM;
2693 goto out0;
2694 }
2695
2696 /* Open VPATHs */
2697 status = vxge_open_vpaths(vdev);
2698 if (status != VXGE_HW_OK) {
2699 vxge_debug_init(VXGE_ERR,
2700 "%s: fatal: Vpath open failed", vdev->ndev->name);
2701 ret = -EPERM;
2702 goto out0;
2703 }
2704
2705 vdev->mtu = dev->mtu;
2706
2707 status = vxge_add_isr(vdev);
2708 if (status != VXGE_HW_OK) {
2709 vxge_debug_init(VXGE_ERR,
2710 "%s: fatal: ISR add failed", dev->name);
2711 ret = -EPERM;
2712 goto out1;
2713 }
2714
2715
2716 if (vdev->config.intr_type != MSI_X) {
2717 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2718 vdev->config.napi_weight);
2719 napi_enable(&vdev->napi);
a5d165b5
SH
2720 for (i = 0; i < vdev->no_of_vpath; i++)
2721 vdev->vpaths[i].ring.napi_p = &vdev->napi;
703da5a1
RV
2722 } else {
2723 for (i = 0; i < vdev->no_of_vpath; i++) {
2724 netif_napi_add(dev, &vdev->vpaths[i].ring.napi,
2725 vxge_poll_msix, vdev->config.napi_weight);
2726 napi_enable(&vdev->vpaths[i].ring.napi);
a5d165b5
SH
2727 vdev->vpaths[i].ring.napi_p =
2728 &vdev->vpaths[i].ring.napi;
703da5a1
RV
2729 }
2730 }
2731
2732 /* configure RTH */
2733 if (vdev->config.rth_steering) {
2734 status = vxge_rth_configure(vdev);
2735 if (status != VXGE_HW_OK) {
2736 vxge_debug_init(VXGE_ERR,
2737 "%s: fatal: RTH configuration failed",
2738 dev->name);
2739 ret = -EPERM;
2740 goto out2;
2741 }
2742 }
2743
2744 for (i = 0; i < vdev->no_of_vpath; i++) {
2745 /* set initial mtu before enabling the device */
2746 status = vxge_hw_vpath_mtu_set(vdev->vpaths[i].handle,
2747 vdev->mtu);
2748 if (status != VXGE_HW_OK) {
2749 vxge_debug_init(VXGE_ERR,
2750 "%s: fatal: can not set new MTU", dev->name);
2751 ret = -EPERM;
2752 goto out2;
2753 }
2754 }
2755
2756 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2757 vxge_debug_init(vdev->level_trace,
2758 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2759 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2760
2761 /* Reprogram the DA table with populated mac addresses */
2762 for (i = 0; i < vdev->no_of_vpath; i++) {
2763 vxge_restore_vpath_mac_addr(&vdev->vpaths[i]);
2764 vxge_restore_vpath_vid_table(&vdev->vpaths[i]);
2765 }
2766
2767 /* Enable vpath to sniff all unicast/multicast traffic that not
2768 * addressed to them. We allow promiscous mode for PF only
2769 */
2770
2771 val64 = 0;
2772 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2773 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2774
2775 vxge_hw_mgmt_reg_write(vdev->devh,
2776 vxge_hw_mgmt_reg_type_mrpcim,
2777 0,
2778 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2779 rxmac_authorize_all_addr),
2780 val64);
2781
2782 vxge_hw_mgmt_reg_write(vdev->devh,
2783 vxge_hw_mgmt_reg_type_mrpcim,
2784 0,
2785 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2786 rxmac_authorize_all_vid),
2787 val64);
2788
2789 vxge_set_multicast(dev);
2790
2791 /* Enabling Bcast and mcast for all vpath */
2792 for (i = 0; i < vdev->no_of_vpath; i++) {
2793 status = vxge_hw_vpath_bcast_enable(vdev->vpaths[i].handle);
2794 if (status != VXGE_HW_OK)
2795 vxge_debug_init(VXGE_ERR,
2796 "%s : Can not enable bcast for vpath "
2797 "id %d", dev->name, i);
2798 if (vdev->config.addr_learn_en) {
2799 status =
2800 vxge_hw_vpath_mcast_enable(vdev->vpaths[i].handle);
2801 if (status != VXGE_HW_OK)
2802 vxge_debug_init(VXGE_ERR,
2803 "%s : Can not enable mcast for vpath "
2804 "id %d", dev->name, i);
2805 }
2806 }
2807
2808 vxge_hw_device_setpause_data(vdev->devh, 0,
2809 vdev->config.tx_pause_enable,
2810 vdev->config.rx_pause_enable);
2811
2812 if (vdev->vp_reset_timer.function == NULL)
2813 vxge_os_timer(vdev->vp_reset_timer,
2814 vxge_poll_vp_reset, vdev, (HZ/2));
2815
2816 if (vdev->vp_lockup_timer.function == NULL)
2817 vxge_os_timer(vdev->vp_lockup_timer,
2818 vxge_poll_vp_lockup, vdev, (HZ/2));
2819
2820 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2821
2822 smp_wmb();
2823
2824 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2825 netif_carrier_on(vdev->ndev);
2826 printk(KERN_NOTICE "%s: Link Up\n", vdev->ndev->name);
2827 vdev->stats.link_up++;
2828 }
2829
2830 vxge_hw_device_intr_enable(vdev->devh);
2831
2832 smp_wmb();
2833
2834 for (i = 0; i < vdev->no_of_vpath; i++) {
2835 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
2836 smp_wmb();
2837 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
2838 }
2839
2840 vxge_start_all_tx_queue(vdev);
2841 goto out0;
2842
2843out2:
2844 vxge_rem_isr(vdev);
2845
2846 /* Disable napi */
2847 if (vdev->config.intr_type != MSI_X)
2848 napi_disable(&vdev->napi);
2849 else {
2850 for (i = 0; i < vdev->no_of_vpath; i++)
2851 napi_disable(&vdev->vpaths[i].ring.napi);
2852 }
2853
2854out1:
2855 vxge_close_vpaths(vdev, 0);
2856out0:
2857 vxge_debug_entryexit(VXGE_TRACE,
2858 "%s: %s:%d Exiting...",
2859 dev->name, __func__, __LINE__);
2860 return ret;
2861}
2862
2863/* Loop throught the mac address list and delete all the entries */
2864void vxge_free_mac_add_list(struct vxge_vpath *vpath)
2865{
2866
2867 struct list_head *entry, *next;
2868 if (list_empty(&vpath->mac_addr_list))
2869 return;
2870
2871 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2872 list_del(entry);
2873 kfree((struct vxge_mac_addrs *)entry);
2874 }
2875}
2876
2877static void vxge_napi_del_all(struct vxgedev *vdev)
2878{
2879 int i;
2880 if (vdev->config.intr_type != MSI_X)
2881 netif_napi_del(&vdev->napi);
2882 else {
2883 for (i = 0; i < vdev->no_of_vpath; i++)
2884 netif_napi_del(&vdev->vpaths[i].ring.napi);
2885 }
2886 return;
2887}
2888
2889int do_vxge_close(struct net_device *dev, int do_io)
2890{
2891 enum vxge_hw_status status;
2892 struct vxgedev *vdev;
2893 struct __vxge_hw_device *hldev;
2894 int i;
2895 u64 val64, vpath_vector;
2896 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2897 dev->name, __func__, __LINE__);
2898
2899 vdev = (struct vxgedev *)netdev_priv(dev);
2900 hldev = (struct __vxge_hw_device *) pci_get_drvdata(vdev->pdev);
2901
bd9ee680
SH
2902 if (unlikely(!is_vxge_card_up(vdev)))
2903 return 0;
2904
703da5a1
RV
2905 /* If vxge_handle_crit_err task is executing,
2906 * wait till it completes. */
2907 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2908 msleep(50);
2909
2910 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2911 if (do_io) {
2912 /* Put the vpath back in normal mode */
2913 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2914 status = vxge_hw_mgmt_reg_read(vdev->devh,
2915 vxge_hw_mgmt_reg_type_mrpcim,
2916 0,
2917 (ulong)offsetof(
2918 struct vxge_hw_mrpcim_reg,
2919 rts_mgr_cbasin_cfg),
2920 &val64);
2921
2922 if (status == VXGE_HW_OK) {
2923 val64 &= ~vpath_vector;
2924 status = vxge_hw_mgmt_reg_write(vdev->devh,
2925 vxge_hw_mgmt_reg_type_mrpcim,
2926 0,
2927 (ulong)offsetof(
2928 struct vxge_hw_mrpcim_reg,
2929 rts_mgr_cbasin_cfg),
2930 val64);
2931 }
2932
2933 /* Remove the function 0 from promiscous mode */
2934 vxge_hw_mgmt_reg_write(vdev->devh,
2935 vxge_hw_mgmt_reg_type_mrpcim,
2936 0,
2937 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2938 rxmac_authorize_all_addr),
2939 0);
2940
2941 vxge_hw_mgmt_reg_write(vdev->devh,
2942 vxge_hw_mgmt_reg_type_mrpcim,
2943 0,
2944 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2945 rxmac_authorize_all_vid),
2946 0);
2947
2948 smp_wmb();
2949 }
2950 del_timer_sync(&vdev->vp_lockup_timer);
2951
2952 del_timer_sync(&vdev->vp_reset_timer);
2953
2954 /* Disable napi */
2955 if (vdev->config.intr_type != MSI_X)
2956 napi_disable(&vdev->napi);
2957 else {
2958 for (i = 0; i < vdev->no_of_vpath; i++)
2959 napi_disable(&vdev->vpaths[i].ring.napi);
2960 }
2961
2962 netif_carrier_off(vdev->ndev);
2963 printk(KERN_NOTICE "%s: Link Down\n", vdev->ndev->name);
2964 vxge_stop_all_tx_queue(vdev);
2965
2966 /* Note that at this point xmit() is stopped by upper layer */
2967 if (do_io)
2968 vxge_hw_device_intr_disable(vdev->devh);
2969
2970 mdelay(1000);
2971
2972 vxge_rem_isr(vdev);
2973
2974 vxge_napi_del_all(vdev);
2975
2976 if (do_io)
2977 vxge_reset_all_vpaths(vdev);
2978
2979 vxge_close_vpaths(vdev, 0);
2980
2981 vxge_debug_entryexit(VXGE_TRACE,
2982 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
2983
2984 clear_bit(__VXGE_STATE_CARD_UP, &driver_config->inta_dev_open);
2985 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
2986
2987 return 0;
2988}
2989
2990/**
2991 * vxge_close
2992 * @dev: device pointer.
2993 *
2994 * This is the stop entry point of the driver. It needs to undo exactly
2995 * whatever was done by the open entry point, thus it's usually referred to
2996 * as the close function.Among other things this function mainly stops the
2997 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
2998 * Return value: '0' on success and an appropriate (-)ve integer as
2999 * defined in errno.h file on failure.
3000 */
3001int
3002vxge_close(struct net_device *dev)
3003{
3004 do_vxge_close(dev, 1);
3005 return 0;
3006}
3007
3008/**
3009 * vxge_change_mtu
3010 * @dev: net device pointer.
3011 * @new_mtu :the new MTU size for the device.
3012 *
3013 * A driver entry point to change MTU size for the device. Before changing
3014 * the MTU the device must be stopped.
3015 */
3016static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3017{
3018 struct vxgedev *vdev = netdev_priv(dev);
3019
3020 vxge_debug_entryexit(vdev->level_trace,
3021 "%s:%d", __func__, __LINE__);
3022 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3023 vxge_debug_init(vdev->level_err,
3024 "%s: mtu size is invalid", dev->name);
3025 return -EPERM;
3026 }
3027
3028 /* check if device is down already */
3029 if (unlikely(!is_vxge_card_up(vdev))) {
3030 /* just store new value, will use later on open() */
3031 dev->mtu = new_mtu;
3032 vxge_debug_init(vdev->level_err,
3033 "%s", "device is down on MTU change");
3034 return 0;
3035 }
3036
3037 vxge_debug_init(vdev->level_trace,
3038 "trying to apply new MTU %d", new_mtu);
3039
3040 if (vxge_close(dev))
3041 return -EIO;
3042
3043 dev->mtu = new_mtu;
3044 vdev->mtu = new_mtu;
3045
3046 if (vxge_open(dev))
3047 return -EIO;
3048
3049 vxge_debug_init(vdev->level_trace,
3050 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3051
3052 vxge_debug_entryexit(vdev->level_trace,
3053 "%s:%d Exiting...", __func__, __LINE__);
3054
3055 return 0;
3056}
3057
3058/**
3059 * vxge_get_stats
3060 * @dev: pointer to the device structure
3061 *
3062 * Updates the device statistics structure. This function updates the device
3063 * statistics structure in the net_device structure and returns a pointer
3064 * to the same.
3065 */
3066static struct net_device_stats *
3067vxge_get_stats(struct net_device *dev)
3068{
3069 struct vxgedev *vdev;
3070 struct net_device_stats *net_stats;
3071 int k;
3072
3073 vdev = netdev_priv(dev);
3074
3075 net_stats = &vdev->stats.net_stats;
3076
3077 memset(net_stats, 0, sizeof(struct net_device_stats));
3078
3079 for (k = 0; k < vdev->no_of_vpath; k++) {
3080 net_stats->rx_packets += vdev->vpaths[k].ring.stats.rx_frms;
3081 net_stats->rx_bytes += vdev->vpaths[k].ring.stats.rx_bytes;
3082 net_stats->rx_errors += vdev->vpaths[k].ring.stats.rx_errors;
3083 net_stats->multicast += vdev->vpaths[k].ring.stats.rx_mcast;
3084 net_stats->rx_dropped +=
3085 vdev->vpaths[k].ring.stats.rx_dropped;
3086
3087 net_stats->tx_packets += vdev->vpaths[k].fifo.stats.tx_frms;
3088 net_stats->tx_bytes += vdev->vpaths[k].fifo.stats.tx_bytes;
3089 net_stats->tx_errors += vdev->vpaths[k].fifo.stats.tx_errors;
3090 }
3091
3092 return net_stats;
3093}
3094
3095/**
3096 * vxge_ioctl
3097 * @dev: Device pointer.
3098 * @ifr: An IOCTL specific structure, that can contain a pointer to
3099 * a proprietary structure used to pass information to the driver.
3100 * @cmd: This is used to distinguish between the different commands that
3101 * can be passed to the IOCTL functions.
3102 *
3103 * Entry point for the Ioctl.
3104 */
3105static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3106{
3107 return -EOPNOTSUPP;
3108}
3109
3110/**
3111 * vxge_tx_watchdog
3112 * @dev: pointer to net device structure
3113 *
3114 * Watchdog for transmit side.
3115 * This function is triggered if the Tx Queue is stopped
3116 * for a pre-defined amount of time when the Interface is still up.
3117 */
3118static void
3119vxge_tx_watchdog(struct net_device *dev)
3120{
3121 struct vxgedev *vdev;
3122
3123 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3124
3125 vdev = (struct vxgedev *)netdev_priv(dev);
3126
3127 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3128
3129 vxge_reset(vdev);
3130 vxge_debug_entryexit(VXGE_TRACE,
3131 "%s:%d Exiting...", __func__, __LINE__);
3132}
3133
3134/**
3135 * vxge_vlan_rx_register
3136 * @dev: net device pointer.
3137 * @grp: vlan group
3138 *
3139 * Vlan group registration
3140 */
3141static void
3142vxge_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
3143{
3144 struct vxgedev *vdev;
3145 struct vxge_vpath *vpath;
3146 int vp;
3147 u64 vid;
3148 enum vxge_hw_status status;
3149 int i;
3150
3151 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3152
3153 vdev = (struct vxgedev *)netdev_priv(dev);
3154
3155 vpath = &vdev->vpaths[0];
3156 if ((NULL == grp) && (vpath->is_open)) {
3157 /* Get the first vlan */
3158 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3159
3160 while (status == VXGE_HW_OK) {
3161
3162 /* Delete this vlan from the vid table */
3163 for (vp = 0; vp < vdev->no_of_vpath; vp++) {
3164 vpath = &vdev->vpaths[vp];
3165 if (!vpath->is_open)
3166 continue;
3167
3168 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3169 }
3170
3171 /* Get the next vlan to be deleted */
3172 vpath = &vdev->vpaths[0];
3173 status = vxge_hw_vpath_vid_get(vpath->handle, &vid);
3174 }
3175 }
3176
3177 vdev->vlgrp = grp;
3178
3179 for (i = 0; i < vdev->no_of_vpath; i++) {
3180 if (vdev->vpaths[i].is_configured)
3181 vdev->vpaths[i].ring.vlgrp = grp;
3182 }
3183
3184 vxge_debug_entryexit(VXGE_TRACE,
3185 "%s:%d Exiting...", __func__, __LINE__);
3186}
3187
3188/**
3189 * vxge_vlan_rx_add_vid
3190 * @dev: net device pointer.
3191 * @vid: vid
3192 *
3193 * Add the vlan id to the devices vlan id table
3194 */
3195static void
3196vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3197{
3198 struct vxgedev *vdev;
3199 struct vxge_vpath *vpath;
3200 int vp_id;
3201
3202 vdev = (struct vxgedev *)netdev_priv(dev);
3203
3204 /* Add these vlan to the vid table */
3205 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3206 vpath = &vdev->vpaths[vp_id];
3207 if (!vpath->is_open)
3208 continue;
3209 vxge_hw_vpath_vid_add(vpath->handle, vid);
3210 }
3211}
3212
3213/**
3214 * vxge_vlan_rx_add_vid
3215 * @dev: net device pointer.
3216 * @vid: vid
3217 *
3218 * Remove the vlan id from the device's vlan id table
3219 */
3220static void
3221vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3222{
3223 struct vxgedev *vdev;
3224 struct vxge_vpath *vpath;
3225 int vp_id;
3226
3227 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3228
3229 vdev = (struct vxgedev *)netdev_priv(dev);
3230
3231 vlan_group_set_device(vdev->vlgrp, vid, NULL);
3232
3233 /* Delete this vlan from the vid table */
3234 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3235 vpath = &vdev->vpaths[vp_id];
3236 if (!vpath->is_open)
3237 continue;
3238 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3239 }
3240 vxge_debug_entryexit(VXGE_TRACE,
3241 "%s:%d Exiting...", __func__, __LINE__);
3242}
3243
3244static const struct net_device_ops vxge_netdev_ops = {
3245 .ndo_open = vxge_open,
3246 .ndo_stop = vxge_close,
3247 .ndo_get_stats = vxge_get_stats,
3248 .ndo_start_xmit = vxge_xmit,
3249 .ndo_validate_addr = eth_validate_addr,
3250 .ndo_set_multicast_list = vxge_set_multicast,
3251
3252 .ndo_do_ioctl = vxge_ioctl,
3253
3254 .ndo_set_mac_address = vxge_set_mac_addr,
3255 .ndo_change_mtu = vxge_change_mtu,
3256 .ndo_vlan_rx_register = vxge_vlan_rx_register,
3257 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3258 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
3259
3260 .ndo_tx_timeout = vxge_tx_watchdog,
3261#ifdef CONFIG_NET_POLL_CONTROLLER
3262 .ndo_poll_controller = vxge_netpoll,
3263#endif
3264};
3265
3266int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3267 struct vxge_config *config,
3268 int high_dma, int no_of_vpath,
3269 struct vxgedev **vdev_out)
3270{
3271 struct net_device *ndev;
3272 enum vxge_hw_status status = VXGE_HW_OK;
3273 struct vxgedev *vdev;
3274 int i, ret = 0, no_of_queue = 1;
3275 u64 stat;
3276
3277 *vdev_out = NULL;
3278 if (config->tx_steering_type == TX_MULTIQ_STEERING)
3279 no_of_queue = no_of_vpath;
3280
3281 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3282 no_of_queue);
3283 if (ndev == NULL) {
3284 vxge_debug_init(
3285 vxge_hw_device_trace_level_get(hldev),
3286 "%s : device allocation failed", __func__);
3287 ret = -ENODEV;
3288 goto _out0;
3289 }
3290
3291 vxge_debug_entryexit(
3292 vxge_hw_device_trace_level_get(hldev),
3293 "%s: %s:%d Entering...",
3294 ndev->name, __func__, __LINE__);
3295
3296 vdev = netdev_priv(ndev);
3297 memset(vdev, 0, sizeof(struct vxgedev));
3298
3299 vdev->ndev = ndev;
3300 vdev->devh = hldev;
3301 vdev->pdev = hldev->pdev;
3302 memcpy(&vdev->config, config, sizeof(struct vxge_config));
3303 vdev->rx_csum = 1; /* Enable Rx CSUM by default. */
3304
3305 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3306
3307 ndev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX |
3308 NETIF_F_HW_VLAN_FILTER;
3309 /* Driver entry points */
3310 ndev->irq = vdev->pdev->irq;
3311 ndev->base_addr = (unsigned long) hldev->bar0;
3312
3313 ndev->netdev_ops = &vxge_netdev_ops;
3314
3315 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
3316
3317 initialize_ethtool_ops(ndev);
3318
3319 /* Allocate memory for vpath */
3320 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3321 no_of_vpath, GFP_KERNEL);
3322 if (!vdev->vpaths) {
3323 vxge_debug_init(VXGE_ERR,
3324 "%s: vpath memory allocation failed",
3325 vdev->ndev->name);
3326 ret = -ENODEV;
3327 goto _out1;
3328 }
3329
3330 ndev->features |= NETIF_F_SG;
3331
3332 ndev->features |= NETIF_F_HW_CSUM;
3333 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3334 "%s : checksuming enabled", __func__);
3335
3336 if (high_dma) {
3337 ndev->features |= NETIF_F_HIGHDMA;
3338 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3339 "%s : using High DMA", __func__);
3340 }
3341
3342 ndev->features |= NETIF_F_TSO | NETIF_F_TSO6;
3343
3344 if (vdev->config.gro_enable)
3345 ndev->features |= NETIF_F_GRO;
3346
3347 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
3348 ndev->real_num_tx_queues = no_of_vpath;
3349
3350#ifdef NETIF_F_LLTX
3351 ndev->features |= NETIF_F_LLTX;
3352#endif
3353
3354 for (i = 0; i < no_of_vpath; i++)
3355 spin_lock_init(&vdev->vpaths[i].fifo.tx_lock);
3356
3357 if (register_netdev(ndev)) {
3358 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3359 "%s: %s : device registration failed!",
3360 ndev->name, __func__);
3361 ret = -ENODEV;
3362 goto _out2;
3363 }
3364
3365 /* Set the factory defined MAC address initially */
3366 ndev->addr_len = ETH_ALEN;
3367
3368 /* Make Link state as off at this point, when the Link change
3369 * interrupt comes the state will be automatically changed to
3370 * the right state.
3371 */
3372 netif_carrier_off(ndev);
3373
3374 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3375 "%s: Ethernet device registered",
3376 ndev->name);
3377
3378 *vdev_out = vdev;
3379
3380 /* Resetting the Device stats */
3381 status = vxge_hw_mrpcim_stats_access(
3382 hldev,
3383 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3384 0,
3385 0,
3386 &stat);
3387
3388 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3389 vxge_debug_init(
3390 vxge_hw_device_trace_level_get(hldev),
3391 "%s: device stats clear returns"
3392 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3393
3394 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3395 "%s: %s:%d Exiting...",
3396 ndev->name, __func__, __LINE__);
3397
3398 return ret;
3399_out2:
3400 kfree(vdev->vpaths);
3401_out1:
3402 free_netdev(ndev);
3403_out0:
3404 return ret;
3405}
3406
3407/*
3408 * vxge_device_unregister
3409 *
3410 * This function will unregister and free network device
3411 */
3412void
3413vxge_device_unregister(struct __vxge_hw_device *hldev)
3414{
3415 struct vxgedev *vdev;
3416 struct net_device *dev;
3417 char buf[IFNAMSIZ];
3418#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3419 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3420 u32 level_trace;
3421#endif
3422
3423 dev = hldev->ndev;
3424 vdev = netdev_priv(dev);
3425#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
3426 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
3427 level_trace = vdev->level_trace;
3428#endif
3429 vxge_debug_entryexit(level_trace,
3430 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3431
3432 memcpy(buf, vdev->ndev->name, IFNAMSIZ);
3433
3434 /* in 2.6 will call stop() if device is up */
3435 unregister_netdev(dev);
3436
3437 flush_scheduled_work();
3438
3439 vxge_debug_init(level_trace, "%s: ethernet device unregistered", buf);
3440 vxge_debug_entryexit(level_trace,
3441 "%s: %s:%d Exiting...", buf, __func__, __LINE__);
3442}
3443
3444/*
3445 * vxge_callback_crit_err
3446 *
3447 * This function is called by the alarm handler in interrupt context.
3448 * Driver must analyze it based on the event type.
3449 */
3450static void
3451vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3452 enum vxge_hw_event type, u64 vp_id)
3453{
3454 struct net_device *dev = hldev->ndev;
3455 struct vxgedev *vdev = (struct vxgedev *)netdev_priv(dev);
3456 int vpath_idx;
3457
3458 vxge_debug_entryexit(vdev->level_trace,
3459 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3460
3461 /* Note: This event type should be used for device wide
3462 * indications only - Serious errors, Slot freeze and critical errors
3463 */
3464 vdev->cric_err_event = type;
3465
3466 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++)
3467 if (vdev->vpaths[vpath_idx].device_id == vp_id)
3468 break;
3469
3470 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3471 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3472 vxge_debug_init(VXGE_ERR,
3473 "%s: Slot is frozen", vdev->ndev->name);
3474 } else if (type == VXGE_HW_EVENT_SERR) {
3475 vxge_debug_init(VXGE_ERR,
3476 "%s: Encountered Serious Error",
3477 vdev->ndev->name);
3478 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3479 vxge_debug_init(VXGE_ERR,
3480 "%s: Encountered Critical Error",
3481 vdev->ndev->name);
3482 }
3483
3484 if ((type == VXGE_HW_EVENT_SERR) ||
3485 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3486 if (unlikely(vdev->exec_mode))
3487 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3488 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3489 vxge_hw_device_mask_all(hldev);
3490 if (unlikely(vdev->exec_mode))
3491 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3492 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3493 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3494
3495 if (unlikely(vdev->exec_mode))
3496 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3497 else {
3498 /* check if this vpath is already set for reset */
3499 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3500
3501 /* disable interrupts for this vpath */
3502 vxge_vpath_intr_disable(vdev, vpath_idx);
3503
3504 /* stop the queue for this vpath */
3505 vxge_stop_tx_queue(&vdev->vpaths[vpath_idx].
3506 fifo);
3507 }
3508 }
3509 }
3510
3511 vxge_debug_entryexit(vdev->level_trace,
3512 "%s: %s:%d Exiting...",
3513 vdev->ndev->name, __func__, __LINE__);
3514}
3515
3516static void verify_bandwidth(void)
3517{
3518 int i, band_width, total = 0, equal_priority = 0;
3519
3520 /* 1. If user enters 0 for some fifo, give equal priority to all */
3521 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3522 if (bw_percentage[i] == 0) {
3523 equal_priority = 1;
3524 break;
3525 }
3526 }
3527
3528 if (!equal_priority) {
3529 /* 2. If sum exceeds 100, give equal priority to all */
3530 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3531 if (bw_percentage[i] == 0xFF)
3532 break;
3533
3534 total += bw_percentage[i];
3535 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3536 equal_priority = 1;
3537 break;
3538 }
3539 }
3540 }
3541
3542 if (!equal_priority) {
3543 /* Is all the bandwidth consumed? */
3544 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3545 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3546 /* Split rest of bw equally among next VPs*/
3547 band_width =
3548 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3549 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3550 if (band_width < 2) /* min of 2% */
3551 equal_priority = 1;
3552 else {
3553 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3554 i++)
3555 bw_percentage[i] =
3556 band_width;
3557 }
3558 }
3559 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3560 equal_priority = 1;
3561 }
3562
3563 if (equal_priority) {
3564 vxge_debug_init(VXGE_ERR,
3565 "%s: Assigning equal bandwidth to all the vpaths",
3566 VXGE_DRIVER_NAME);
3567 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3568 VXGE_HW_MAX_VIRTUAL_PATHS;
3569 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3570 bw_percentage[i] = bw_percentage[0];
3571 }
3572
3573 return;
3574}
3575
3576/*
3577 * Vpath configuration
3578 */
3579static int __devinit vxge_config_vpaths(
3580 struct vxge_hw_device_config *device_config,
3581 u64 vpath_mask, struct vxge_config *config_param)
3582{
3583 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3584 u32 txdl_size, txdl_per_memblock;
3585
3586 temp = driver_config->vpath_per_dev;
3587 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3588 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3589 /* No more CPU. Return vpath number as zero.*/
3590 if (driver_config->g_no_cpus == -1)
3591 return 0;
3592
3593 if (!driver_config->g_no_cpus)
3594 driver_config->g_no_cpus = num_online_cpus();
3595
3596 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3597 if (!driver_config->vpath_per_dev)
3598 driver_config->vpath_per_dev = 1;
3599
3600 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3601 if (!vxge_bVALn(vpath_mask, i, 1))
3602 continue;
3603 else
3604 default_no_vpath++;
3605 if (default_no_vpath < driver_config->vpath_per_dev)
3606 driver_config->vpath_per_dev = default_no_vpath;
3607
3608 driver_config->g_no_cpus = driver_config->g_no_cpus -
3609 (driver_config->vpath_per_dev * 2);
3610 if (driver_config->g_no_cpus <= 0)
3611 driver_config->g_no_cpus = -1;
3612 }
3613
3614 if (driver_config->vpath_per_dev == 1) {
3615 vxge_debug_ll_config(VXGE_TRACE,
3616 "%s: Disable tx and rx steering, "
3617 "as single vpath is configured", VXGE_DRIVER_NAME);
3618 config_param->rth_steering = NO_STEERING;
3619 config_param->tx_steering_type = NO_STEERING;
3620 device_config->rth_en = 0;
3621 }
3622
3623 /* configure bandwidth */
3624 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3625 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3626
3627 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3628 device_config->vp_config[i].vp_id = i;
3629 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3630 if (no_of_vpaths < driver_config->vpath_per_dev) {
3631 if (!vxge_bVALn(vpath_mask, i, 1)) {
3632 vxge_debug_ll_config(VXGE_TRACE,
3633 "%s: vpath: %d is not available",
3634 VXGE_DRIVER_NAME, i);
3635 continue;
3636 } else {
3637 vxge_debug_ll_config(VXGE_TRACE,
3638 "%s: vpath: %d available",
3639 VXGE_DRIVER_NAME, i);
3640 no_of_vpaths++;
3641 }
3642 } else {
3643 vxge_debug_ll_config(VXGE_TRACE,
3644 "%s: vpath: %d is not configured, "
3645 "max_config_vpath exceeded",
3646 VXGE_DRIVER_NAME, i);
3647 break;
3648 }
3649
3650 /* Configure Tx fifo's */
3651 device_config->vp_config[i].fifo.enable =
3652 VXGE_HW_FIFO_ENABLE;
3653 device_config->vp_config[i].fifo.max_frags =
3654 MAX_SKB_FRAGS;
3655 device_config->vp_config[i].fifo.memblock_size =
3656 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3657
3658 txdl_size = MAX_SKB_FRAGS * sizeof(struct vxge_hw_fifo_txd);
3659 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3660
3661 device_config->vp_config[i].fifo.fifo_blocks =
3662 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3663
3664 device_config->vp_config[i].fifo.intr =
3665 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3666
3667 /* Configure tti properties */
3668 device_config->vp_config[i].tti.intr_enable =
3669 VXGE_HW_TIM_INTR_ENABLE;
3670
3671 device_config->vp_config[i].tti.btimer_val =
3672 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3673
3674 device_config->vp_config[i].tti.timer_ac_en =
3675 VXGE_HW_TIM_TIMER_AC_ENABLE;
3676
3677 /* For msi-x with napi (each vector
3678 has a handler of its own) -
3679 Set CI to OFF for all vpaths */
3680 device_config->vp_config[i].tti.timer_ci_en =
3681 VXGE_HW_TIM_TIMER_CI_DISABLE;
3682
3683 device_config->vp_config[i].tti.timer_ri_en =
3684 VXGE_HW_TIM_TIMER_RI_DISABLE;
3685
3686 device_config->vp_config[i].tti.util_sel =
3687 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3688
3689 device_config->vp_config[i].tti.ltimer_val =
3690 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3691
3692 device_config->vp_config[i].tti.rtimer_val =
3693 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3694
3695 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3696 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3697 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3698 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3699 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3700 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3701 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3702
3703 /* Configure Rx rings */
3704 device_config->vp_config[i].ring.enable =
3705 VXGE_HW_RING_ENABLE;
3706
3707 device_config->vp_config[i].ring.ring_blocks =
3708 VXGE_HW_DEF_RING_BLOCKS;
3709 device_config->vp_config[i].ring.buffer_mode =
3710 VXGE_HW_RING_RXD_BUFFER_MODE_1;
3711 device_config->vp_config[i].ring.rxds_limit =
3712 VXGE_HW_DEF_RING_RXDS_LIMIT;
3713 device_config->vp_config[i].ring.scatter_mode =
3714 VXGE_HW_RING_SCATTER_MODE_A;
3715
3716 /* Configure rti properties */
3717 device_config->vp_config[i].rti.intr_enable =
3718 VXGE_HW_TIM_INTR_ENABLE;
3719
3720 device_config->vp_config[i].rti.btimer_val =
3721 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3722
3723 device_config->vp_config[i].rti.timer_ac_en =
3724 VXGE_HW_TIM_TIMER_AC_ENABLE;
3725
3726 device_config->vp_config[i].rti.timer_ci_en =
3727 VXGE_HW_TIM_TIMER_CI_DISABLE;
3728
3729 device_config->vp_config[i].rti.timer_ri_en =
3730 VXGE_HW_TIM_TIMER_RI_DISABLE;
3731
3732 device_config->vp_config[i].rti.util_sel =
3733 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3734
3735 device_config->vp_config[i].rti.urange_a =
3736 RTI_RX_URANGE_A;
3737 device_config->vp_config[i].rti.urange_b =
3738 RTI_RX_URANGE_B;
3739 device_config->vp_config[i].rti.urange_c =
3740 RTI_RX_URANGE_C;
3741 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3742 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3743 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3744 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3745
3746 device_config->vp_config[i].rti.rtimer_val =
3747 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3748
3749 device_config->vp_config[i].rti.ltimer_val =
3750 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3751
3752 device_config->vp_config[i].rpa_strip_vlan_tag =
3753 vlan_tag_strip;
3754 }
3755
3756 driver_config->vpath_per_dev = temp;
3757 return no_of_vpaths;
3758}
3759
3760/* initialize device configuratrions */
3761static void __devinit vxge_device_config_init(
3762 struct vxge_hw_device_config *device_config,
3763 int *intr_type)
3764{
3765 /* Used for CQRQ/SRQ. */
3766 device_config->dma_blockpool_initial =
3767 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3768
3769 device_config->dma_blockpool_max =
3770 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3771
3772 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3773 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3774
3775#ifndef CONFIG_PCI_MSI
3776 vxge_debug_init(VXGE_ERR,
3777 "%s: This Kernel does not support "
3778 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3779 *intr_type = INTA;
3780#endif
3781
3782 /* Configure whether MSI-X or IRQL. */
3783 switch (*intr_type) {
3784 case INTA:
3785 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3786 break;
3787
3788 case MSI_X:
3789 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX;
3790 break;
3791 }
3792 /* Timer period between device poll */
3793 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3794
3795 /* Configure mac based steering. */
3796 device_config->rts_mac_en = addr_learn_en;
3797
3798 /* Configure Vpaths */
3799 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3800
3801 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3802 __func__);
3803 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_initial : %d",
3804 device_config->dma_blockpool_initial);
3805 vxge_debug_ll_config(VXGE_TRACE, "dma_blockpool_max : %d",
3806 device_config->dma_blockpool_max);
3807 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3808 device_config->intr_mode);
3809 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3810 device_config->device_poll_millis);
3811 vxge_debug_ll_config(VXGE_TRACE, "rts_mac_en : %d",
3812 device_config->rts_mac_en);
3813 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3814 device_config->rth_en);
3815 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3816 device_config->rth_it_type);
3817}
3818
3819static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3820{
3821 int i;
3822
3823 vxge_debug_init(VXGE_TRACE,
3824 "%s: %d Vpath(s) opened",
3825 vdev->ndev->name, vdev->no_of_vpath);
3826
3827 switch (vdev->config.intr_type) {
3828 case INTA:
3829 vxge_debug_init(VXGE_TRACE,
3830 "%s: Interrupt type INTA", vdev->ndev->name);
3831 break;
3832
3833 case MSI_X:
3834 vxge_debug_init(VXGE_TRACE,
3835 "%s: Interrupt type MSI-X", vdev->ndev->name);
3836 break;
3837 }
3838
3839 if (vdev->config.rth_steering) {
3840 vxge_debug_init(VXGE_TRACE,
3841 "%s: RTH steering enabled for TCP_IPV4",
3842 vdev->ndev->name);
3843 } else {
3844 vxge_debug_init(VXGE_TRACE,
3845 "%s: RTH steering disabled", vdev->ndev->name);
3846 }
3847
3848 switch (vdev->config.tx_steering_type) {
3849 case NO_STEERING:
3850 vxge_debug_init(VXGE_TRACE,
3851 "%s: Tx steering disabled", vdev->ndev->name);
3852 break;
3853 case TX_PRIORITY_STEERING:
3854 vxge_debug_init(VXGE_TRACE,
3855 "%s: Unsupported tx steering option",
3856 vdev->ndev->name);
3857 vxge_debug_init(VXGE_TRACE,
3858 "%s: Tx steering disabled", vdev->ndev->name);
3859 vdev->config.tx_steering_type = 0;
3860 break;
3861 case TX_VLAN_STEERING:
3862 vxge_debug_init(VXGE_TRACE,
3863 "%s: Unsupported tx steering option",
3864 vdev->ndev->name);
3865 vxge_debug_init(VXGE_TRACE,
3866 "%s: Tx steering disabled", vdev->ndev->name);
3867 vdev->config.tx_steering_type = 0;
3868 break;
3869 case TX_MULTIQ_STEERING:
3870 vxge_debug_init(VXGE_TRACE,
3871 "%s: Tx multiqueue steering enabled",
3872 vdev->ndev->name);
3873 break;
3874 case TX_PORT_STEERING:
3875 vxge_debug_init(VXGE_TRACE,
3876 "%s: Tx port steering enabled",
3877 vdev->ndev->name);
3878 break;
3879 default:
3880 vxge_debug_init(VXGE_ERR,
3881 "%s: Unsupported tx steering type",
3882 vdev->ndev->name);
3883 vxge_debug_init(VXGE_TRACE,
3884 "%s: Tx steering disabled", vdev->ndev->name);
3885 vdev->config.tx_steering_type = 0;
3886 }
3887
3888 if (vdev->config.gro_enable) {
3889 vxge_debug_init(VXGE_ERR,
3890 "%s: Generic receive offload enabled",
3891 vdev->ndev->name);
3892 } else
3893 vxge_debug_init(VXGE_TRACE,
3894 "%s: Generic receive offload disabled",
3895 vdev->ndev->name);
3896
3897 if (vdev->config.addr_learn_en)
3898 vxge_debug_init(VXGE_TRACE,
3899 "%s: MAC Address learning enabled", vdev->ndev->name);
3900
3901 vxge_debug_init(VXGE_TRACE,
3902 "%s: Rx doorbell mode enabled", vdev->ndev->name);
3903
3904 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3905 if (!vxge_bVALn(vpath_mask, i, 1))
3906 continue;
3907 vxge_debug_ll_config(VXGE_TRACE,
3908 "%s: MTU size - %d", vdev->ndev->name,
3909 ((struct __vxge_hw_device *)(vdev->devh))->
3910 config.vp_config[i].mtu);
3911 vxge_debug_init(VXGE_TRACE,
3912 "%s: VLAN tag stripping %s", vdev->ndev->name,
3913 ((struct __vxge_hw_device *)(vdev->devh))->
3914 config.vp_config[i].rpa_strip_vlan_tag
3915 ? "Enabled" : "Disabled");
3916 vxge_debug_init(VXGE_TRACE,
3917 "%s: Ring blocks : %d", vdev->ndev->name,
3918 ((struct __vxge_hw_device *)(vdev->devh))->
3919 config.vp_config[i].ring.ring_blocks);
3920 vxge_debug_init(VXGE_TRACE,
3921 "%s: Fifo blocks : %d", vdev->ndev->name,
3922 ((struct __vxge_hw_device *)(vdev->devh))->
3923 config.vp_config[i].fifo.fifo_blocks);
3924 vxge_debug_ll_config(VXGE_TRACE,
3925 "%s: Max frags : %d", vdev->ndev->name,
3926 ((struct __vxge_hw_device *)(vdev->devh))->
3927 config.vp_config[i].fifo.max_frags);
3928 break;
3929 }
3930}
3931
3932#ifdef CONFIG_PM
3933/**
3934 * vxge_pm_suspend - vxge power management suspend entry point
3935 *
3936 */
3937static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
3938{
3939 return -ENOSYS;
3940}
3941/**
3942 * vxge_pm_resume - vxge power management resume entry point
3943 *
3944 */
3945static int vxge_pm_resume(struct pci_dev *pdev)
3946{
3947 return -ENOSYS;
3948}
3949
3950#endif
3951
3952/**
3953 * vxge_io_error_detected - called when PCI error is detected
3954 * @pdev: Pointer to PCI device
3955 * @state: The current pci connection state
3956 *
3957 * This function is called after a PCI bus error affecting
3958 * this device has been detected.
3959 */
3960static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
3961 pci_channel_state_t state)
3962{
3963 struct __vxge_hw_device *hldev =
3964 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3965 struct net_device *netdev = hldev->ndev;
3966
3967 netif_device_detach(netdev);
3968
e33b992d
DN
3969 if (state == pci_channel_io_perm_failure)
3970 return PCI_ERS_RESULT_DISCONNECT;
3971
703da5a1
RV
3972 if (netif_running(netdev)) {
3973 /* Bring down the card, while avoiding PCI I/O */
3974 do_vxge_close(netdev, 0);
3975 }
3976
3977 pci_disable_device(pdev);
3978
3979 return PCI_ERS_RESULT_NEED_RESET;
3980}
3981
3982/**
3983 * vxge_io_slot_reset - called after the pci bus has been reset.
3984 * @pdev: Pointer to PCI device
3985 *
3986 * Restart the card from scratch, as if from a cold-boot.
3987 * At this point, the card has exprienced a hard reset,
3988 * followed by fixups by BIOS, and has its config space
3989 * set up identically to what it was at cold boot.
3990 */
3991static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
3992{
3993 struct __vxge_hw_device *hldev =
3994 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
3995 struct net_device *netdev = hldev->ndev;
3996
3997 struct vxgedev *vdev = netdev_priv(netdev);
3998
3999 if (pci_enable_device(pdev)) {
4000 printk(KERN_ERR "%s: "
4001 "Cannot re-enable device after reset\n",
4002 VXGE_DRIVER_NAME);
4003 return PCI_ERS_RESULT_DISCONNECT;
4004 }
4005
4006 pci_set_master(pdev);
4007 vxge_reset(vdev);
4008
4009 return PCI_ERS_RESULT_RECOVERED;
4010}
4011
4012/**
4013 * vxge_io_resume - called when traffic can start flowing again.
4014 * @pdev: Pointer to PCI device
4015 *
4016 * This callback is called when the error recovery driver tells
4017 * us that its OK to resume normal operation.
4018 */
4019static void vxge_io_resume(struct pci_dev *pdev)
4020{
4021 struct __vxge_hw_device *hldev =
4022 (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4023 struct net_device *netdev = hldev->ndev;
4024
4025 if (netif_running(netdev)) {
4026 if (vxge_open(netdev)) {
4027 printk(KERN_ERR "%s: "
4028 "Can't bring device back up after reset\n",
4029 VXGE_DRIVER_NAME);
4030 return;
4031 }
4032 }
4033
4034 netif_device_attach(netdev);
4035}
4036
4037/**
4038 * vxge_probe
4039 * @pdev : structure containing the PCI related information of the device.
4040 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4041 * Description:
4042 * This function is called when a new PCI device gets detected and initializes
4043 * it.
4044 * Return value:
4045 * returns 0 on success and negative on failure.
4046 *
4047 */
4048static int __devinit
4049vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4050{
4051 struct __vxge_hw_device *hldev;
4052 enum vxge_hw_status status;
4053 int ret;
4054 int high_dma = 0;
4055 u64 vpath_mask = 0;
4056 struct vxgedev *vdev;
4057 struct vxge_config ll_config;
4058 struct vxge_hw_device_config *device_config = NULL;
4059 struct vxge_hw_device_attr attr;
4060 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4061 u8 *macaddr;
4062 struct vxge_mac_addrs *entry;
4063 static int bus = -1, device = -1;
4064 u8 new_device = 0;
4065
4066 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4067 attr.pdev = pdev;
4068
4069 if (bus != pdev->bus->number)
4070 new_device = 1;
4071 if (device != PCI_SLOT(pdev->devfn))
4072 new_device = 1;
4073
4074 bus = pdev->bus->number;
4075 device = PCI_SLOT(pdev->devfn);
4076
4077 if (new_device) {
4078 if (driver_config->config_dev_cnt &&
4079 (driver_config->config_dev_cnt !=
4080 driver_config->total_dev_cnt))
4081 vxge_debug_init(VXGE_ERR,
4082 "%s: Configured %d of %d devices",
4083 VXGE_DRIVER_NAME,
4084 driver_config->config_dev_cnt,
4085 driver_config->total_dev_cnt);
4086 driver_config->config_dev_cnt = 0;
4087 driver_config->total_dev_cnt = 0;
4088 driver_config->g_no_cpus = 0;
4089 driver_config->vpath_per_dev = max_config_vpath;
4090 }
4091
4092 driver_config->total_dev_cnt++;
4093 if (++driver_config->config_dev_cnt > max_config_dev) {
4094 ret = 0;
4095 goto _exit0;
4096 }
4097
4098 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4099 GFP_KERNEL);
4100 if (!device_config) {
4101 ret = -ENOMEM;
4102 vxge_debug_init(VXGE_ERR,
4103 "device_config : malloc failed %s %d",
4104 __FILE__, __LINE__);
4105 goto _exit0;
4106 }
4107
4108 memset(&ll_config, 0, sizeof(struct vxge_config));
4109 ll_config.tx_steering_type = TX_MULTIQ_STEERING;
4110 ll_config.intr_type = MSI_X;
4111 ll_config.napi_weight = NEW_NAPI_WEIGHT;
4112 ll_config.rth_steering = RTH_STEERING;
4113
4114 /* get the default configuration parameters */
4115 vxge_hw_device_config_default_get(device_config);
4116
4117 /* initialize configuration parameters */
4118 vxge_device_config_init(device_config, &ll_config.intr_type);
4119
4120 ret = pci_enable_device(pdev);
4121 if (ret) {
4122 vxge_debug_init(VXGE_ERR,
4123 "%s : can not enable PCI device", __func__);
4124 goto _exit0;
4125 }
4126
4127 if (!pci_set_dma_mask(pdev, 0xffffffffffffffffULL)) {
4128 vxge_debug_ll_config(VXGE_TRACE,
4129 "%s : using 64bit DMA", __func__);
4130
4131 high_dma = 1;
4132
4133 if (pci_set_consistent_dma_mask(pdev,
4134 0xffffffffffffffffULL)) {
4135 vxge_debug_init(VXGE_ERR,
4136 "%s : unable to obtain 64bit DMA for "
4137 "consistent allocations", __func__);
4138 ret = -ENOMEM;
4139 goto _exit1;
4140 }
4141 } else if (!pci_set_dma_mask(pdev, 0xffffffffUL)) {
4142 vxge_debug_ll_config(VXGE_TRACE,
4143 "%s : using 32bit DMA", __func__);
4144 } else {
4145 ret = -ENOMEM;
4146 goto _exit1;
4147 }
4148
4149 if (pci_request_regions(pdev, VXGE_DRIVER_NAME)) {
4150 vxge_debug_init(VXGE_ERR,
4151 "%s : request regions failed", __func__);
4152 ret = -ENODEV;
4153 goto _exit1;
4154 }
4155
4156 pci_set_master(pdev);
4157
4158 attr.bar0 = pci_ioremap_bar(pdev, 0);
4159 if (!attr.bar0) {
4160 vxge_debug_init(VXGE_ERR,
4161 "%s : cannot remap io memory bar0", __func__);
4162 ret = -ENODEV;
4163 goto _exit2;
4164 }
4165 vxge_debug_ll_config(VXGE_TRACE,
4166 "pci ioremap bar0: %p:0x%llx",
4167 attr.bar0,
4168 (unsigned long long)pci_resource_start(pdev, 0));
4169
703da5a1
RV
4170 status = vxge_hw_device_hw_info_get(attr.bar0,
4171 &ll_config.device_hw_info);
4172 if (status != VXGE_HW_OK) {
4173 vxge_debug_init(VXGE_ERR,
4174 "%s: Reading of hardware info failed."
4175 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4176 ret = -EINVAL;
7975d1ee 4177 goto _exit3;
703da5a1
RV
4178 }
4179
4180 if (ll_config.device_hw_info.fw_version.major !=
22fa125e 4181 VXGE_DRIVER_FW_VERSION_MAJOR) {
703da5a1 4182 vxge_debug_init(VXGE_ERR,
22fa125e
SH
4183 "%s: Incorrect firmware version."
4184 "Please upgrade the firmware to version 1.x.x",
4185 VXGE_DRIVER_NAME);
703da5a1 4186 ret = -EINVAL;
7975d1ee 4187 goto _exit3;
703da5a1
RV
4188 }
4189
4190 vpath_mask = ll_config.device_hw_info.vpath_mask;
4191 if (vpath_mask == 0) {
4192 vxge_debug_ll_config(VXGE_TRACE,
4193 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4194 ret = -EINVAL;
7975d1ee 4195 goto _exit3;
703da5a1
RV
4196 }
4197
4198 vxge_debug_ll_config(VXGE_TRACE,
4199 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4200 (unsigned long long)vpath_mask);
4201
4202 /* Check how many vpaths are available */
4203 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4204 if (!((vpath_mask) & vxge_mBIT(i)))
4205 continue;
4206 max_vpath_supported++;
4207 }
4208
5dbc9011
SS
4209 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
4210 if ((VXGE_HW_FUNCTION_MODE_SRIOV ==
4211 ll_config.device_hw_info.function_mode) &&
4212 (max_config_dev > 1) && (pdev->is_physfn)) {
4213 ret = pci_enable_sriov(pdev, max_config_dev - 1);
4214 if (ret)
4215 vxge_debug_ll_config(VXGE_ERR,
4216 "Failed to enable SRIOV: %d \n", ret);
4217 }
4218
703da5a1
RV
4219 /*
4220 * Configure vpaths and get driver configured number of vpaths
4221 * which is less than or equal to the maximum vpaths per function.
4222 */
4223 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, &ll_config);
4224 if (!no_of_vpath) {
4225 vxge_debug_ll_config(VXGE_ERR,
4226 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4227 ret = 0;
7975d1ee 4228 goto _exit3;
703da5a1
RV
4229 }
4230
4231 /* Setting driver callbacks */
4232 attr.uld_callbacks.link_up = vxge_callback_link_up;
4233 attr.uld_callbacks.link_down = vxge_callback_link_down;
4234 attr.uld_callbacks.crit_err = vxge_callback_crit_err;
4235
4236 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4237 if (status != VXGE_HW_OK) {
4238 vxge_debug_init(VXGE_ERR,
4239 "Failed to initialize device (%d)", status);
4240 ret = -EINVAL;
7975d1ee 4241 goto _exit3;
703da5a1
RV
4242 }
4243
4244 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4245
4246 /* set private device info */
4247 pci_set_drvdata(pdev, hldev);
4248
4249 ll_config.gro_enable = VXGE_GRO_ALWAYS_AGGREGATE;
4250 ll_config.fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4251 ll_config.addr_learn_en = addr_learn_en;
4252 ll_config.rth_algorithm = RTH_ALG_JENKINS;
4253 ll_config.rth_hash_type_tcpipv4 = VXGE_HW_RING_HASH_TYPE_TCP_IPV4;
4254 ll_config.rth_hash_type_ipv4 = VXGE_HW_RING_HASH_TYPE_NONE;
4255 ll_config.rth_hash_type_tcpipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4256 ll_config.rth_hash_type_ipv6 = VXGE_HW_RING_HASH_TYPE_NONE;
4257 ll_config.rth_hash_type_tcpipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4258 ll_config.rth_hash_type_ipv6ex = VXGE_HW_RING_HASH_TYPE_NONE;
4259 ll_config.rth_bkt_sz = RTH_BUCKET_SIZE;
4260 ll_config.tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4261 ll_config.rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4262
4263 if (vxge_device_register(hldev, &ll_config, high_dma, no_of_vpath,
4264 &vdev)) {
4265 ret = -EINVAL;
7975d1ee 4266 goto _exit4;
703da5a1
RV
4267 }
4268
4269 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4270 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4271 vxge_hw_device_trace_level_get(hldev));
4272
4273 /* set private HW device info */
4274 hldev->ndev = vdev->ndev;
4275 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4276 vdev->bar0 = attr.bar0;
703da5a1
RV
4277 vdev->max_vpath_supported = max_vpath_supported;
4278 vdev->no_of_vpath = no_of_vpath;
4279
4280 /* Virtual Path count */
4281 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4282 if (!vxge_bVALn(vpath_mask, i, 1))
4283 continue;
4284 if (j >= vdev->no_of_vpath)
4285 break;
4286
4287 vdev->vpaths[j].is_configured = 1;
4288 vdev->vpaths[j].device_id = i;
4289 vdev->vpaths[j].fifo.driver_id = j;
4290 vdev->vpaths[j].ring.driver_id = j;
4291 vdev->vpaths[j].vdev = vdev;
4292 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4293 memcpy((u8 *)vdev->vpaths[j].macaddr,
4294 (u8 *)ll_config.device_hw_info.mac_addrs[i],
4295 ETH_ALEN);
4296
4297 /* Initialize the mac address list header */
4298 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4299
4300 vdev->vpaths[j].mac_addr_cnt = 0;
4301 vdev->vpaths[j].mcast_addr_cnt = 0;
4302 j++;
4303 }
4304 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4305 vdev->max_config_port = max_config_port;
4306
4307 vdev->vlan_tag_strip = vlan_tag_strip;
4308
4309 /* map the hashing selector table to the configured vpaths */
4310 for (i = 0; i < vdev->no_of_vpath; i++)
4311 vdev->vpath_selector[i] = vpath_selector[i];
4312
4313 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4314
4315 ll_config.device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4316 ll_config.device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4317 ll_config.device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
4318
4319 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
4320 vdev->ndev->name, ll_config.device_hw_info.serial_number);
4321
4322 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
4323 vdev->ndev->name, ll_config.device_hw_info.part_number);
4324
4325 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
4326 vdev->ndev->name, ll_config.device_hw_info.product_desc);
4327
4328 vxge_debug_init(VXGE_TRACE,
4329 "%s: MAC ADDR: %02X:%02X:%02X:%02X:%02X:%02X",
4330 vdev->ndev->name, macaddr[0], macaddr[1], macaddr[2],
4331 macaddr[3], macaddr[4], macaddr[5]);
4332
4333 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4334 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4335
4336 vxge_debug_init(VXGE_TRACE,
4337 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
4338 ll_config.device_hw_info.fw_version.version,
4339 ll_config.device_hw_info.fw_date.date);
4340
0a25bdc6
SH
4341 if (new_device) {
4342 switch (ll_config.device_hw_info.function_mode) {
4343 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4344 vxge_debug_init(VXGE_TRACE,
4345 "%s: Single Function Mode Enabled", vdev->ndev->name);
4346 break;
4347 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4348 vxge_debug_init(VXGE_TRACE,
4349 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4350 break;
4351 case VXGE_HW_FUNCTION_MODE_SRIOV:
4352 vxge_debug_init(VXGE_TRACE,
4353 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4354 break;
4355 case VXGE_HW_FUNCTION_MODE_MRIOV:
4356 vxge_debug_init(VXGE_TRACE,
4357 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4358 break;
4359 }
4360 }
4361
703da5a1
RV
4362 vxge_print_parm(vdev, vpath_mask);
4363
4364 /* Store the fw version for ethttool option */
4365 strcpy(vdev->fw_version, ll_config.device_hw_info.fw_version.version);
4366 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4367 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4368
4369 /* Copy the station mac address to the list */
4370 for (i = 0; i < vdev->no_of_vpath; i++) {
4371 entry = (struct vxge_mac_addrs *)
4372 kzalloc(sizeof(struct vxge_mac_addrs),
4373 GFP_KERNEL);
4374 if (NULL == entry) {
4375 vxge_debug_init(VXGE_ERR,
4376 "%s: mac_addr_list : memory allocation failed",
4377 vdev->ndev->name);
4378 ret = -EPERM;
7975d1ee 4379 goto _exit5;
703da5a1
RV
4380 }
4381 macaddr = (u8 *)&entry->macaddr;
4382 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4383 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4384 vdev->vpaths[i].mac_addr_cnt = 1;
4385 }
4386
914d0d71 4387 kfree(device_config);
703da5a1
RV
4388 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4389 vdev->ndev->name, __func__, __LINE__);
4390
4391 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4392 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4393 vxge_hw_device_trace_level_get(hldev));
4394
4395 return 0;
4396
7975d1ee 4397_exit5:
703da5a1
RV
4398 for (i = 0; i < vdev->no_of_vpath; i++)
4399 vxge_free_mac_add_list(&vdev->vpaths[i]);
4400
4401 vxge_device_unregister(hldev);
7975d1ee 4402_exit4:
5dbc9011 4403 pci_disable_sriov(pdev);
703da5a1 4404 vxge_hw_device_terminate(hldev);
703da5a1
RV
4405_exit3:
4406 iounmap(attr.bar0);
4407_exit2:
4408 pci_release_regions(pdev);
4409_exit1:
4410 pci_disable_device(pdev);
4411_exit0:
4412 kfree(device_config);
4413 driver_config->config_dev_cnt--;
4414 pci_set_drvdata(pdev, NULL);
4415 return ret;
4416}
4417
4418/**
4419 * vxge_rem_nic - Free the PCI device
4420 * @pdev: structure containing the PCI related information of the device.
4421 * Description: This function is called by the Pci subsystem to release a
4422 * PCI device and free up all resource held up by the device.
4423 */
4424static void __devexit
4425vxge_remove(struct pci_dev *pdev)
4426{
4427 struct __vxge_hw_device *hldev;
4428 struct vxgedev *vdev = NULL;
4429 struct net_device *dev;
4430 int i = 0;
4431#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4432 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4433 u32 level_trace;
4434#endif
4435
4436 hldev = (struct __vxge_hw_device *) pci_get_drvdata(pdev);
4437
4438 if (hldev == NULL)
4439 return;
4440 dev = hldev->ndev;
4441 vdev = netdev_priv(dev);
4442
4443#if ((VXGE_DEBUG_INIT & VXGE_DEBUG_MASK) || \
4444 (VXGE_DEBUG_ENTRYEXIT & VXGE_DEBUG_MASK))
4445 level_trace = vdev->level_trace;
4446#endif
4447 vxge_debug_entryexit(level_trace,
4448 "%s:%d", __func__, __LINE__);
4449
4450 vxge_debug_init(level_trace,
4451 "%s : removing PCI device...", __func__);
4452 vxge_device_unregister(hldev);
4453
4454 for (i = 0; i < vdev->no_of_vpath; i++) {
4455 vxge_free_mac_add_list(&vdev->vpaths[i]);
4456 vdev->vpaths[i].mcast_addr_cnt = 0;
4457 vdev->vpaths[i].mac_addr_cnt = 0;
4458 }
4459
4460 kfree(vdev->vpaths);
4461
4462 iounmap(vdev->bar0);
703da5a1 4463
5dbc9011
SS
4464 pci_disable_sriov(pdev);
4465
703da5a1
RV
4466 /* we are safe to free it now */
4467 free_netdev(dev);
4468
4469 vxge_debug_init(level_trace,
4470 "%s:%d Device unregistered", __func__, __LINE__);
4471
4472 vxge_hw_device_terminate(hldev);
4473
4474 pci_disable_device(pdev);
4475 pci_release_regions(pdev);
4476 pci_set_drvdata(pdev, NULL);
4477 vxge_debug_entryexit(level_trace,
4478 "%s:%d Exiting...", __func__, __LINE__);
4479}
4480
4481static struct pci_error_handlers vxge_err_handler = {
4482 .error_detected = vxge_io_error_detected,
4483 .slot_reset = vxge_io_slot_reset,
4484 .resume = vxge_io_resume,
4485};
4486
4487static struct pci_driver vxge_driver = {
4488 .name = VXGE_DRIVER_NAME,
4489 .id_table = vxge_id_table,
4490 .probe = vxge_probe,
4491 .remove = __devexit_p(vxge_remove),
4492#ifdef CONFIG_PM
4493 .suspend = vxge_pm_suspend,
4494 .resume = vxge_pm_resume,
4495#endif
4496 .err_handler = &vxge_err_handler,
4497};
4498
4499static int __init
4500vxge_starter(void)
4501{
4502 int ret = 0;
4503 char version[32];
4504 snprintf(version, 32, "%s", DRV_VERSION);
4505
4506 printk(KERN_CRIT "%s: Copyright(c) 2002-2009 Neterion Inc\n",
4507 VXGE_DRIVER_NAME);
4508 printk(KERN_CRIT "%s: Driver version: %s\n",
4509 VXGE_DRIVER_NAME, version);
4510
4511 verify_bandwidth();
4512
4513 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4514 if (!driver_config)
4515 return -ENOMEM;
4516
4517 ret = pci_register_driver(&vxge_driver);
4518
4519 if (driver_config->config_dev_cnt &&
4520 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4521 vxge_debug_init(VXGE_ERR,
4522 "%s: Configured %d of %d devices",
4523 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4524 driver_config->total_dev_cnt);
4525
4526 if (ret)
4527 kfree(driver_config);
4528
4529 return ret;
4530}
4531
4532static void __exit
4533vxge_closer(void)
4534{
4535 pci_unregister_driver(&vxge_driver);
4536 kfree(driver_config);
4537}
4538module_init(vxge_starter);
4539module_exit(vxge_closer);