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