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