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