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