blob: ef76725454d250126b18d98998deca4b2fb7212d [file] [log] [blame]
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001/******************************************************************************
2* This software may be used and distributed according to the terms of
3* the GNU General Public License (GPL), incorporated herein by reference.
4* Drivers based on or derived from this code fall under the GPL and must
5* retain the authorship, copyright and license notice. This file is not
6* a complete program and may only be used when the entire operating
7* system is licensed under the GPL.
8* See the file COPYING in this distribution for more information.
9*
Jon Mason926bd902010-07-15 08:47:26 +000010* vxge-main.c: Driver for Exar Corp's X3100 Series 10GbE PCIe I/O
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000011* Virtualized Server Adapter.
Jon Mason926bd902010-07-15 08:47:26 +000012* Copyright(c) 2002-2010 Exar Corp.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000013*
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
Joe Perches75f5e1c2010-07-27 11:47:03 +000044#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
45
Jiri Pirko53515732011-07-20 04:54:40 +000046#include <linux/bitops.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000047#include <linux/if_vlan.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000048#include <linux/interrupt.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000049#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090050#include <linux/slab.h>
Alexander Beregalov2b05e002009-04-04 16:36:18 -070051#include <linux/tcp.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000052#include <net/ip.h>
53#include <linux/netdevice.h>
54#include <linux/etherdevice.h>
Jon Masone8ac1752010-11-11 04:25:57 +000055#include <linux/firmware.h>
Jon Masonb81b3732010-11-11 04:25:58 +000056#include <linux/net_tstamp.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040057#include <linux/prefetch.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040058#include <linux/module.h>
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000059#include "vxge-main.h"
60#include "vxge-reg.h"
61
62MODULE_LICENSE("Dual BSD/GPL");
63MODULE_DESCRIPTION("Neterion's X3100 Series 10GbE PCIe I/O"
64 "Virtualized Server Adapter");
65
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000066static DEFINE_PCI_DEVICE_TABLE(vxge_id_table) = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000067 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_WIN, PCI_ANY_ID,
68 PCI_ANY_ID},
69 {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_TITAN_UNI, PCI_ANY_ID,
70 PCI_ANY_ID},
71 {0}
72};
73
74MODULE_DEVICE_TABLE(pci, vxge_id_table);
75
76VXGE_MODULE_PARAM_INT(vlan_tag_strip, VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE);
77VXGE_MODULE_PARAM_INT(addr_learn_en, VXGE_HW_MAC_ADDR_LEARN_DEFAULT);
78VXGE_MODULE_PARAM_INT(max_config_port, VXGE_MAX_CONFIG_PORT);
79VXGE_MODULE_PARAM_INT(max_config_vpath, VXGE_USE_DEFAULT);
80VXGE_MODULE_PARAM_INT(max_mac_vpath, VXGE_MAX_MAC_ADDR_COUNT);
81VXGE_MODULE_PARAM_INT(max_config_dev, VXGE_MAX_CONFIG_DEV);
82
83static u16 vpath_selector[VXGE_HW_MAX_VIRTUAL_PATHS] =
84 {0, 1, 3, 3, 7, 7, 7, 7, 15, 15, 15, 15, 15, 15, 15, 15, 31};
85static unsigned int bw_percentage[VXGE_HW_MAX_VIRTUAL_PATHS] =
86 {[0 ...(VXGE_HW_MAX_VIRTUAL_PATHS - 1)] = 0xFF};
87module_param_array(bw_percentage, uint, NULL, 0);
88
89static struct vxge_drv_config *driver_config;
90
91static inline int is_vxge_card_up(struct vxgedev *vdev)
92{
93 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
94}
95
96static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
97{
Benjamin LaHaiseff67df52009-08-04 10:21:03 +000098 struct sk_buff **skb_ptr = NULL;
99 struct sk_buff **temp;
100#define NR_SKB_COMPLETED 128
101 struct sk_buff *completed[NR_SKB_COMPLETED];
102 int more;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000103
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000104 do {
105 more = 0;
106 skb_ptr = completed;
107
Jon Mason98f45da2010-07-15 08:47:25 +0000108 if (__netif_tx_trylock(fifo->txq)) {
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000109 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
110 NR_SKB_COMPLETED, &more);
Jon Mason98f45da2010-07-15 08:47:25 +0000111 __netif_tx_unlock(fifo->txq);
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000112 }
Jon Mason98f45da2010-07-15 08:47:25 +0000113
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000114 /* free SKBs */
115 for (temp = completed; temp != skb_ptr; temp++)
116 dev_kfree_skb_irq(*temp);
Jon Mason98f45da2010-07-15 08:47:25 +0000117 } while (more);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000118}
119
120static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
121{
122 int i;
123
124 /* Complete all transmits */
125 for (i = 0; i < vdev->no_of_vpath; i++)
126 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
127}
128
129static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
130{
131 int i;
132 struct vxge_ring *ring;
133
134 /* Complete all receives*/
135 for (i = 0; i < vdev->no_of_vpath; i++) {
136 ring = &vdev->vpaths[i].ring;
137 vxge_hw_vpath_poll_rx(ring->handle);
138 }
139}
140
141/*
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000142 * vxge_callback_link_up
143 *
144 * This function is called during interrupt context to notify link up state
145 * change.
146 */
Jon Mason528f7272010-12-10 14:02:56 +0000147static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000148{
149 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000150 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000151
152 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
153 vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000154 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000155 vdev->stats.link_up++;
156
157 netif_carrier_on(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000158 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000159
160 vxge_debug_entryexit(VXGE_TRACE,
161 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
162}
163
164/*
165 * vxge_callback_link_down
166 *
167 * This function is called during interrupt context to notify link down state
168 * change.
169 */
Jon Mason528f7272010-12-10 14:02:56 +0000170static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000171{
172 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000173 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000174
175 vxge_debug_entryexit(VXGE_TRACE,
176 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000177 netdev_notice(vdev->ndev, "Link Down\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000178
179 vdev->stats.link_down++;
180 netif_carrier_off(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000181 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000182
183 vxge_debug_entryexit(VXGE_TRACE,
184 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
185}
186
187/*
188 * vxge_rx_alloc
189 *
190 * Allocate SKB.
191 */
Jon Mason528f7272010-12-10 14:02:56 +0000192static struct sk_buff *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000193vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
194{
195 struct net_device *dev;
196 struct sk_buff *skb;
197 struct vxge_rx_priv *rx_priv;
198
199 dev = ring->ndev;
200 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
201 ring->ndev->name, __func__, __LINE__);
202
203 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
204
205 /* try to allocate skb first. this one may fail */
206 skb = netdev_alloc_skb(dev, skb_size +
207 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
208 if (skb == NULL) {
209 vxge_debug_mem(VXGE_ERR,
210 "%s: out of memory to allocate SKB", dev->name);
211 ring->stats.skb_alloc_fail++;
212 return NULL;
213 }
214
215 vxge_debug_mem(VXGE_TRACE,
216 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
217 __func__, __LINE__, skb);
218
219 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
220
221 rx_priv->skb = skb;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000222 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000223 rx_priv->data_size = skb_size;
224 vxge_debug_entryexit(VXGE_TRACE,
225 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
226
227 return skb;
228}
229
230/*
231 * vxge_rx_map
232 */
233static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
234{
235 struct vxge_rx_priv *rx_priv;
236 dma_addr_t dma_addr;
237
238 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
239 ring->ndev->name, __func__, __LINE__);
240 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
241
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000242 rx_priv->skb_data = rx_priv->skb->data;
243 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000244 rx_priv->data_size, PCI_DMA_FROMDEVICE);
245
Denis Kirjanovfa15e992010-01-10 13:40:10 -0800246 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000247 ring->stats.pci_map_fail++;
248 return -EIO;
249 }
250 vxge_debug_mem(VXGE_TRACE,
251 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
252 ring->ndev->name, __func__, __LINE__,
253 (unsigned long long)dma_addr);
254 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
255
256 rx_priv->data_dma = dma_addr;
257 vxge_debug_entryexit(VXGE_TRACE,
258 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
259
260 return 0;
261}
262
263/*
264 * vxge_rx_initial_replenish
265 * Allocation of RxD as an initial replenish procedure.
266 */
267static enum vxge_hw_status
268vxge_rx_initial_replenish(void *dtrh, void *userdata)
269{
270 struct vxge_ring *ring = (struct vxge_ring *)userdata;
271 struct vxge_rx_priv *rx_priv;
272
273 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
274 ring->ndev->name, __func__, __LINE__);
275 if (vxge_rx_alloc(dtrh, ring,
276 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
277 return VXGE_HW_FAIL;
278
279 if (vxge_rx_map(dtrh, ring)) {
280 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
281 dev_kfree_skb(rx_priv->skb);
282
283 return VXGE_HW_FAIL;
284 }
285 vxge_debug_entryexit(VXGE_TRACE,
286 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
287
288 return VXGE_HW_OK;
289}
290
291static inline void
292vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
293 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
294{
295
296 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
297 ring->ndev->name, __func__, __LINE__);
298 skb_record_rx_queue(skb, ring->driver_id);
299 skb->protocol = eth_type_trans(skb, ring->ndev);
300
stephen hemminger62ea0552011-06-20 10:35:07 +0000301 u64_stats_update_begin(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000302 ring->stats.rx_frms++;
303 ring->stats.rx_bytes += pkt_length;
304
305 if (skb->pkt_type == PACKET_MULTICAST)
306 ring->stats.rx_mcast++;
stephen hemminger62ea0552011-06-20 10:35:07 +0000307 u64_stats_update_end(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000308
309 vxge_debug_rx(VXGE_TRACE,
310 "%s: %s:%d skb protocol = %d",
311 ring->ndev->name, __func__, __LINE__, skb->protocol);
312
Jiri Pirko53515732011-07-20 04:54:40 +0000313 if (ext_info->vlan &&
314 ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
315 __vlan_hwaccel_put_tag(skb, ext_info->vlan);
316 napi_gro_receive(ring->napi_p, skb);
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000317
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000318 vxge_debug_entryexit(VXGE_TRACE,
319 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
320}
321
322static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
323 struct vxge_rx_priv *rx_priv)
324{
325 pci_dma_sync_single_for_device(ring->pdev,
326 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
327
328 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
329 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
330}
331
332static inline void vxge_post(int *dtr_cnt, void **first_dtr,
333 void *post_dtr, struct __vxge_hw_ring *ringh)
334{
335 int dtr_count = *dtr_cnt;
336 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
337 if (*first_dtr)
338 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
339 *first_dtr = post_dtr;
340 } else
341 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
342 dtr_count++;
343 *dtr_cnt = dtr_count;
344}
345
346/*
347 * vxge_rx_1b_compl
348 *
349 * If the interrupt is because of a received frame or if the receive ring
350 * contains fresh as yet un-processed frames, this function is called.
351 */
stephen hemminger42821a52010-10-21 07:50:53 +0000352static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000353vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
354 u8 t_code, void *userdata)
355{
356 struct vxge_ring *ring = (struct vxge_ring *)userdata;
Jon Masonb81b3732010-11-11 04:25:58 +0000357 struct net_device *dev = ring->ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000358 unsigned int dma_sizes;
359 void *first_dtr = NULL;
360 int dtr_cnt = 0;
361 int data_size;
362 dma_addr_t data_dma;
363 int pkt_length;
364 struct sk_buff *skb;
365 struct vxge_rx_priv *rx_priv;
366 struct vxge_hw_ring_rxd_info ext_info;
367 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
368 ring->ndev->name, __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000369
370 do {
Benjamin LaHaise3f23e432009-08-04 10:21:39 +0000371 prefetch((char *)dtr + L1_CACHE_BYTES);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000372 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
373 skb = rx_priv->skb;
374 data_size = rx_priv->data_size;
375 data_dma = rx_priv->data_dma;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000376 prefetch(rx_priv->skb_data);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000377
378 vxge_debug_rx(VXGE_TRACE,
379 "%s: %s:%d skb = 0x%p",
380 ring->ndev->name, __func__, __LINE__, skb);
381
382 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
383 pkt_length = dma_sizes;
384
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +0000385 pkt_length -= ETH_FCS_LEN;
386
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000387 vxge_debug_rx(VXGE_TRACE,
388 "%s: %s:%d Packet Length = %d",
389 ring->ndev->name, __func__, __LINE__, pkt_length);
390
391 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
392
393 /* check skb validity */
394 vxge_assert(skb);
395
396 prefetch((char *)skb + L1_CACHE_BYTES);
397 if (unlikely(t_code)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000398 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
399 VXGE_HW_OK) {
400
401 ring->stats.rx_errors++;
402 vxge_debug_rx(VXGE_TRACE,
403 "%s: %s :%d Rx T_code is %d",
404 ring->ndev->name, __func__,
405 __LINE__, t_code);
406
407 /* If the t_code is not supported and if the
408 * t_code is other than 0x5 (unparseable packet
409 * such as unknown UPV6 header), Drop it !!!
410 */
411 vxge_re_pre_post(dtr, ring, rx_priv);
412
413 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
414 ring->stats.rx_dropped++;
415 continue;
416 }
417 }
418
419 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000420 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000421 if (!vxge_rx_map(dtr, ring)) {
422 skb_put(skb, pkt_length);
423
424 pci_unmap_single(ring->pdev, data_dma,
425 data_size, PCI_DMA_FROMDEVICE);
426
427 vxge_hw_ring_rxd_pre_post(ringh, dtr);
428 vxge_post(&dtr_cnt, &first_dtr, dtr,
429 ringh);
430 } else {
431 dev_kfree_skb(rx_priv->skb);
432 rx_priv->skb = skb;
433 rx_priv->data_size = data_size;
434 vxge_re_pre_post(dtr, ring, rx_priv);
435
436 vxge_post(&dtr_cnt, &first_dtr, dtr,
437 ringh);
438 ring->stats.rx_dropped++;
439 break;
440 }
441 } else {
442 vxge_re_pre_post(dtr, ring, rx_priv);
443
444 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
445 ring->stats.rx_dropped++;
446 break;
447 }
448 } else {
449 struct sk_buff *skb_up;
450
451 skb_up = netdev_alloc_skb(dev, pkt_length +
452 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
453 if (skb_up != NULL) {
454 skb_reserve(skb_up,
455 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
456
457 pci_dma_sync_single_for_cpu(ring->pdev,
458 data_dma, data_size,
459 PCI_DMA_FROMDEVICE);
460
461 vxge_debug_mem(VXGE_TRACE,
462 "%s: %s:%d skb_up = %p",
463 ring->ndev->name, __func__,
464 __LINE__, skb);
465 memcpy(skb_up->data, skb->data, pkt_length);
466
467 vxge_re_pre_post(dtr, ring, rx_priv);
468
469 vxge_post(&dtr_cnt, &first_dtr, dtr,
470 ringh);
471 /* will netif_rx small SKB instead */
472 skb = skb_up;
473 skb_put(skb, pkt_length);
474 } else {
475 vxge_re_pre_post(dtr, ring, rx_priv);
476
477 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
478 vxge_debug_rx(VXGE_ERR,
479 "%s: vxge_rx_1b_compl: out of "
480 "memory", dev->name);
481 ring->stats.skb_alloc_fail++;
482 break;
483 }
484 }
485
486 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
487 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000488 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000489 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
490 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
491 skb->ip_summed = CHECKSUM_UNNECESSARY;
492 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700493 skb_checksum_none_assert(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000494
Jon Masonb81b3732010-11-11 04:25:58 +0000495
496 if (ring->rx_hwts) {
497 struct skb_shared_hwtstamps *skb_hwts;
498 u32 ns = *(u32 *)(skb->head + pkt_length);
499
500 skb_hwts = skb_hwtstamps(skb);
501 skb_hwts->hwtstamp = ns_to_ktime(ns);
502 skb_hwts->syststamp.tv64 = 0;
503 }
504
Jon Mason47f01db2010-11-11 04:25:53 +0000505 /* rth_hash_type and rth_it_hit are non-zero regardless of
506 * whether rss is enabled. Only the rth_value is zero/non-zero
507 * if rss is disabled/enabled, so key off of that.
508 */
509 if (ext_info.rth_value)
510 skb->rxhash = ext_info.rth_value;
511
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000512 vxge_rx_complete(ring, skb, ext_info.vlan,
513 pkt_length, &ext_info);
514
515 ring->budget--;
516 ring->pkts_processed++;
517 if (!ring->budget)
518 break;
519
520 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
521 &t_code) == VXGE_HW_OK);
522
523 if (first_dtr)
524 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
525
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000526 vxge_debug_entryexit(VXGE_TRACE,
527 "%s:%d Exiting...",
528 __func__, __LINE__);
529 return VXGE_HW_OK;
530}
531
532/*
533 * vxge_xmit_compl
534 *
535 * If an interrupt was raised to indicate DMA complete of the Tx packet,
536 * this function is called. It identifies the last TxD whose buffer was
537 * freed and frees all skbs whose data have already DMA'ed into the NICs
538 * internal memory.
539 */
stephen hemminger42821a52010-10-21 07:50:53 +0000540static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000541vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
542 enum vxge_hw_fifo_tcode t_code, void *userdata,
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000543 struct sk_buff ***skb_ptr, int nr_skb, int *more)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000544{
545 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000546 struct sk_buff *skb, **done_skb = *skb_ptr;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000547 int pkt_cnt = 0;
548
549 vxge_debug_entryexit(VXGE_TRACE,
550 "%s:%d Entered....", __func__, __LINE__);
551
552 do {
553 int frg_cnt;
554 skb_frag_t *frag;
555 int i = 0, j;
556 struct vxge_tx_priv *txd_priv =
557 vxge_hw_fifo_txdl_private_get(dtr);
558
559 skb = txd_priv->skb;
560 frg_cnt = skb_shinfo(skb)->nr_frags;
561 frag = &skb_shinfo(skb)->frags[0];
562
563 vxge_debug_tx(VXGE_TRACE,
564 "%s: %s:%d fifo_hw = %p dtr = %p "
565 "tcode = 0x%x", fifo->ndev->name, __func__,
566 __LINE__, fifo_hw, dtr, t_code);
567 /* check skb validity */
568 vxge_assert(skb);
569 vxge_debug_tx(VXGE_TRACE,
570 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
571 fifo->ndev->name, __func__, __LINE__,
572 skb, txd_priv, frg_cnt);
573 if (unlikely(t_code)) {
574 fifo->stats.tx_errors++;
575 vxge_debug_tx(VXGE_ERR,
576 "%s: tx: dtr %p completed due to "
577 "error t_code %01x", fifo->ndev->name,
578 dtr, t_code);
579 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
580 }
581
582 /* for unfragmented skb */
583 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
584 skb_headlen(skb), PCI_DMA_TODEVICE);
585
586 for (j = 0; j < frg_cnt; j++) {
587 pci_unmap_page(fifo->pdev,
588 txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000589 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000590 frag += 1;
591 }
592
593 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
594
595 /* Updating the statistics block */
stephen hemminger62ea0552011-06-20 10:35:07 +0000596 u64_stats_update_begin(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000597 fifo->stats.tx_frms++;
598 fifo->stats.tx_bytes += skb->len;
stephen hemminger62ea0552011-06-20 10:35:07 +0000599 u64_stats_update_end(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000600
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000601 *done_skb++ = skb;
602
603 if (--nr_skb <= 0) {
604 *more = 1;
605 break;
606 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000607
608 pkt_cnt++;
609 if (pkt_cnt > fifo->indicate_max_pkts)
610 break;
611
612 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
613 &dtr, &t_code) == VXGE_HW_OK);
614
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000615 *skb_ptr = done_skb;
Jon Mason98f45da2010-07-15 08:47:25 +0000616 if (netif_tx_queue_stopped(fifo->txq))
617 netif_tx_wake_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000618
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000619 vxge_debug_entryexit(VXGE_TRACE,
620 "%s: %s:%d Exiting...",
621 fifo->ndev->name, __func__, __LINE__);
622 return VXGE_HW_OK;
623}
624
Eric Dumazet28679752009-05-27 19:26:37 +0000625/* select a vpath to transmit the packet */
Jon Mason98f45da2010-07-15 08:47:25 +0000626static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000627{
628 u16 queue_len, counter = 0;
629 if (skb->protocol == htons(ETH_P_IP)) {
630 struct iphdr *ip;
631 struct tcphdr *th;
632
633 ip = ip_hdr(skb);
634
Paul Gortmaker56f8a752011-06-21 20:33:34 -0700635 if (!ip_is_fragment(ip)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000636 th = (struct tcphdr *)(((unsigned char *)ip) +
637 ip->ihl*4);
638
639 queue_len = vdev->no_of_vpath;
640 counter = (ntohs(th->source) +
641 ntohs(th->dest)) &
642 vdev->vpath_selector[queue_len - 1];
643 if (counter >= queue_len)
644 counter = queue_len - 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000645 }
646 }
647 return counter;
648}
649
650static enum vxge_hw_status vxge_search_mac_addr_in_list(
651 struct vxge_vpath *vpath, u64 del_mac)
652{
653 struct list_head *entry, *next;
654 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
655 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
656 return TRUE;
657 }
658 return FALSE;
659}
660
Jon Mason528f7272010-12-10 14:02:56 +0000661static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
662{
663 struct vxge_mac_addrs *new_mac_entry;
664 u8 *mac_address = NULL;
665
666 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
667 return TRUE;
668
669 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
670 if (!new_mac_entry) {
671 vxge_debug_mem(VXGE_ERR,
672 "%s: memory allocation failed",
673 VXGE_DRIVER_NAME);
674 return FALSE;
675 }
676
677 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
678
679 /* Copy the new mac address to the list */
680 mac_address = (u8 *)&new_mac_entry->macaddr;
681 memcpy(mac_address, mac->macaddr, ETH_ALEN);
682
683 new_mac_entry->state = mac->state;
684 vpath->mac_addr_cnt++;
685
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000686 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000687 vpath->mcast_addr_cnt++;
688
689 return TRUE;
690}
691
692/* Add a mac address to DA table */
693static enum vxge_hw_status
694vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
695{
696 enum vxge_hw_status status = VXGE_HW_OK;
697 struct vxge_vpath *vpath;
698 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
699
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000700 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000701 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
702 else
703 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
704
705 vpath = &vdev->vpaths[mac->vpath_no];
706 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
707 mac->macmask, duplicate_mode);
708 if (status != VXGE_HW_OK) {
709 vxge_debug_init(VXGE_ERR,
710 "DA config add entry failed for vpath:%d",
711 vpath->device_id);
712 } else
713 if (FALSE == vxge_mac_list_add(vpath, mac))
714 status = -EPERM;
715
716 return status;
717}
718
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000719static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
720{
721 struct macInfo mac_info;
722 u8 *mac_address = NULL;
723 u64 mac_addr = 0, vpath_vector = 0;
724 int vpath_idx = 0;
725 enum vxge_hw_status status = VXGE_HW_OK;
726 struct vxge_vpath *vpath = NULL;
727 struct __vxge_hw_device *hldev;
728
Joe Perchesd8ee7072010-11-15 10:13:58 +0000729 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000730
731 mac_address = (u8 *)&mac_addr;
732 memcpy(mac_address, mac_header, ETH_ALEN);
733
734 /* Is this mac address already in the list? */
735 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
736 vpath = &vdev->vpaths[vpath_idx];
737 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
738 return vpath_idx;
739 }
740
741 memset(&mac_info, 0, sizeof(struct macInfo));
742 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
743
744 /* Any vpath has room to add mac address to its da table? */
745 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
746 vpath = &vdev->vpaths[vpath_idx];
747 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
748 /* Add this mac address to this vpath */
749 mac_info.vpath_no = vpath_idx;
750 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
751 status = vxge_add_mac_addr(vdev, &mac_info);
752 if (status != VXGE_HW_OK)
753 return -EPERM;
754 return vpath_idx;
755 }
756 }
757
758 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
759 vpath_idx = 0;
760 mac_info.vpath_no = vpath_idx;
761 /* Is the first vpath already selected as catch-basin ? */
762 vpath = &vdev->vpaths[vpath_idx];
763 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
764 /* Add this mac address to this vpath */
765 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
766 return -EPERM;
767 return vpath_idx;
768 }
769
770 /* Select first vpath as catch-basin */
771 vpath_vector = vxge_mBIT(vpath->device_id);
772 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
773 vxge_hw_mgmt_reg_type_mrpcim,
774 0,
775 (ulong)offsetof(
776 struct vxge_hw_mrpcim_reg,
777 rts_mgr_cbasin_cfg),
778 vpath_vector);
779 if (status != VXGE_HW_OK) {
780 vxge_debug_tx(VXGE_ERR,
781 "%s: Unable to set the vpath-%d in catch-basin mode",
782 VXGE_DRIVER_NAME, vpath->device_id);
783 return -EPERM;
784 }
785
786 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
787 return -EPERM;
788
789 return vpath_idx;
790}
791
792/**
793 * vxge_xmit
794 * @skb : the socket buffer containing the Tx data.
795 * @dev : device pointer.
796 *
797 * This function is the Tx entry point of the driver. Neterion NIC supports
798 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000799*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000800static netdev_tx_t
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000801vxge_xmit(struct sk_buff *skb, struct net_device *dev)
802{
803 struct vxge_fifo *fifo = NULL;
804 void *dtr_priv;
805 void *dtr = NULL;
806 struct vxgedev *vdev = NULL;
807 enum vxge_hw_status status;
808 int frg_cnt, first_frg_len;
809 skb_frag_t *frag;
810 int i = 0, j = 0, avail;
811 u64 dma_pointer;
812 struct vxge_tx_priv *txdl_priv = NULL;
813 struct __vxge_hw_fifo *fifo_hw;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000814 int offload_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000815 int vpath_no = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000816
817 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
818 dev->name, __func__, __LINE__);
819
820 /* A buffer with no data will be dropped */
821 if (unlikely(skb->len <= 0)) {
822 vxge_debug_tx(VXGE_ERR,
823 "%s: Buffer has no data..", dev->name);
824 dev_kfree_skb(skb);
825 return NETDEV_TX_OK;
826 }
827
Joe Perches5f54ceb2010-11-15 11:12:30 +0000828 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000829
830 if (unlikely(!is_vxge_card_up(vdev))) {
831 vxge_debug_tx(VXGE_ERR,
832 "%s: vdev not initialized", dev->name);
833 dev_kfree_skb(skb);
834 return NETDEV_TX_OK;
835 }
836
837 if (vdev->config.addr_learn_en) {
838 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
839 if (vpath_no == -EPERM) {
840 vxge_debug_tx(VXGE_ERR,
841 "%s: Failed to store the mac address",
842 dev->name);
843 dev_kfree_skb(skb);
844 return NETDEV_TX_OK;
845 }
846 }
847
848 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
849 vpath_no = skb_get_queue_mapping(skb);
850 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
Jon Mason98f45da2010-07-15 08:47:25 +0000851 vpath_no = vxge_get_vpath_no(vdev, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000852
853 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
854
855 if (vpath_no >= vdev->no_of_vpath)
856 vpath_no = 0;
857
858 fifo = &vdev->vpaths[vpath_no].fifo;
859 fifo_hw = fifo->handle;
860
Jon Mason98f45da2010-07-15 08:47:25 +0000861 if (netif_tx_queue_stopped(fifo->txq))
Jon Masond03848e2010-07-15 08:47:23 +0000862 return NETDEV_TX_BUSY;
Jon Masond03848e2010-07-15 08:47:23 +0000863
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000864 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
865 if (avail == 0) {
866 vxge_debug_tx(VXGE_ERR,
867 "%s: No free TXDs available", dev->name);
868 fifo->stats.txd_not_free++;
Jon Mason98f45da2010-07-15 08:47:25 +0000869 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000870 }
871
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000872 /* Last TXD? Stop tx queue to avoid dropping packets. TX
873 * completion will resume the queue.
874 */
875 if (avail == 1)
Jon Mason98f45da2010-07-15 08:47:25 +0000876 netif_tx_stop_queue(fifo->txq);
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000877
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000878 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
879 if (unlikely(status != VXGE_HW_OK)) {
880 vxge_debug_tx(VXGE_ERR,
881 "%s: Out of descriptors .", dev->name);
882 fifo->stats.txd_out_of_desc++;
Jon Mason98f45da2010-07-15 08:47:25 +0000883 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000884 }
885
886 vxge_debug_tx(VXGE_TRACE,
887 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
888 dev->name, __func__, __LINE__,
889 fifo_hw, dtr, dtr_priv);
890
Jesse Grosseab6d182010-10-20 13:56:03 +0000891 if (vlan_tx_tag_present(skb)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000892 u16 vlan_tag = vlan_tx_tag_get(skb);
893 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
894 }
895
896 first_frg_len = skb_headlen(skb);
897
898 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
899 PCI_DMA_TODEVICE);
900
901 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
902 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000903 fifo->stats.pci_map_fail++;
Jon Mason98f45da2010-07-15 08:47:25 +0000904 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000905 }
906
907 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
908 txdl_priv->skb = skb;
909 txdl_priv->dma_buffers[j] = dma_pointer;
910
911 frg_cnt = skb_shinfo(skb)->nr_frags;
912 vxge_debug_tx(VXGE_TRACE,
913 "%s: %s:%d skb = %p txdl_priv = %p "
914 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
915 __func__, __LINE__, skb, txdl_priv,
916 frg_cnt, (unsigned long long)dma_pointer);
917
918 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
919 first_frg_len);
920
921 frag = &skb_shinfo(skb)->frags[0];
922 for (i = 0; i < frg_cnt; i++) {
923 /* ignore 0 length fragment */
Eric Dumazet9e903e02011-10-18 21:00:24 +0000924 if (!skb_frag_size(frag))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000925 continue;
926
Ian Campbell94d60a72011-10-05 17:35:34 -0400927 dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000928 0, skb_frag_size(frag),
Ian Campbell94d60a72011-10-05 17:35:34 -0400929 DMA_TO_DEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000930
Ian Campbell94d60a72011-10-05 17:35:34 -0400931 if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
Jon Mason98f45da2010-07-15 08:47:25 +0000932 goto _exit2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000933 vxge_debug_tx(VXGE_TRACE,
934 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
935 dev->name, __func__, __LINE__, i,
936 (unsigned long long)dma_pointer);
937
938 txdl_priv->dma_buffers[j] = dma_pointer;
939 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000940 skb_frag_size(frag));
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000941 frag += 1;
942 }
943
944 offload_type = vxge_offload_type(skb);
945
946 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000947 int mss = vxge_tcp_mss(skb);
948 if (mss) {
Jon Mason98f45da2010-07-15 08:47:25 +0000949 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000950 dev->name, __func__, __LINE__, mss);
951 vxge_hw_fifo_txdl_mss_set(dtr, mss);
952 } else {
953 vxge_assert(skb->len <=
954 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
955 vxge_assert(0);
956 goto _exit1;
957 }
958 }
959
960 if (skb->ip_summed == CHECKSUM_PARTIAL)
961 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
962 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
963 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
964 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
965
966 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000967
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000968 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
969 dev->name, __func__, __LINE__);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000970 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000971
Jon Mason98f45da2010-07-15 08:47:25 +0000972_exit2:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000973 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000974_exit1:
975 j = 0;
976 frag = &skb_shinfo(skb)->frags[0];
977
978 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
979 skb_headlen(skb), PCI_DMA_TODEVICE);
980
981 for (; j < i; j++) {
982 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000983 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000984 frag += 1;
985 }
986
987 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Jon Mason98f45da2010-07-15 08:47:25 +0000988_exit0:
989 netif_tx_stop_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000990 dev_kfree_skb(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000991
Patrick McHardy6ed10652009-06-23 06:03:08 +0000992 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000993}
994
995/*
996 * vxge_rx_term
997 *
998 * Function will be called by hw function to abort all outstanding receive
999 * descriptors.
1000 */
1001static void
1002vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1003{
1004 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1005 struct vxge_rx_priv *rx_priv =
1006 vxge_hw_ring_rxd_private_get(dtrh);
1007
1008 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1009 ring->ndev->name, __func__, __LINE__);
1010 if (state != VXGE_HW_RXD_STATE_POSTED)
1011 return;
1012
1013 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1014 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1015
1016 dev_kfree_skb(rx_priv->skb);
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +00001017 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001018
1019 vxge_debug_entryexit(VXGE_TRACE,
1020 "%s: %s:%d Exiting...",
1021 ring->ndev->name, __func__, __LINE__);
1022}
1023
1024/*
1025 * vxge_tx_term
1026 *
1027 * Function will be called to abort all outstanding tx descriptors
1028 */
1029static void
1030vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1031{
1032 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1033 skb_frag_t *frag;
1034 int i = 0, j, frg_cnt;
1035 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1036 struct sk_buff *skb = txd_priv->skb;
1037
1038 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1039
1040 if (state != VXGE_HW_TXDL_STATE_POSTED)
1041 return;
1042
1043 /* check skb validity */
1044 vxge_assert(skb);
1045 frg_cnt = skb_shinfo(skb)->nr_frags;
1046 frag = &skb_shinfo(skb)->frags[0];
1047
1048 /* for unfragmented skb */
1049 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1050 skb_headlen(skb), PCI_DMA_TODEVICE);
1051
1052 for (j = 0; j < frg_cnt; j++) {
1053 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +00001054 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001055 frag += 1;
1056 }
1057
1058 dev_kfree_skb(skb);
1059
1060 vxge_debug_entryexit(VXGE_TRACE,
1061 "%s:%d Exiting...", __func__, __LINE__);
1062}
1063
Jon Mason528f7272010-12-10 14:02:56 +00001064static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1065{
1066 struct list_head *entry, *next;
1067 u64 del_mac = 0;
1068 u8 *mac_address = (u8 *) (&del_mac);
1069
1070 /* Copy the mac address to delete from the list */
1071 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1072
1073 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1074 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1075 list_del(entry);
1076 kfree((struct vxge_mac_addrs *)entry);
1077 vpath->mac_addr_cnt--;
1078
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001079 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +00001080 vpath->mcast_addr_cnt--;
1081 return TRUE;
1082 }
1083 }
1084
1085 return FALSE;
1086}
1087
1088/* delete a mac address from DA table */
1089static enum vxge_hw_status
1090vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1091{
1092 enum vxge_hw_status status = VXGE_HW_OK;
1093 struct vxge_vpath *vpath;
1094
1095 vpath = &vdev->vpaths[mac->vpath_no];
1096 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1097 mac->macmask);
1098 if (status != VXGE_HW_OK) {
1099 vxge_debug_init(VXGE_ERR,
1100 "DA config delete entry failed for vpath:%d",
1101 vpath->device_id);
1102 } else
1103 vxge_mac_list_del(vpath, mac);
1104 return status;
1105}
1106
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001107/**
1108 * vxge_set_multicast
1109 * @dev: pointer to the device structure
1110 *
1111 * Entry point for multicast address enable/disable
1112 * This function is a driver entry point which gets called by the kernel
1113 * whenever multicast addresses must be enabled/disabled. This also gets
1114 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1115 * determine, if multicast address must be enabled or if promiscuous mode
1116 * is to be disabled etc.
1117 */
1118static void vxge_set_multicast(struct net_device *dev)
1119{
Jiri Pirko22bedad2010-04-01 21:22:57 +00001120 struct netdev_hw_addr *ha;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001121 struct vxgedev *vdev;
1122 int i, mcast_cnt = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00001123 struct __vxge_hw_device *hldev;
1124 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001125 enum vxge_hw_status status = VXGE_HW_OK;
1126 struct macInfo mac_info;
1127 int vpath_idx = 0;
1128 struct vxge_mac_addrs *mac_entry;
1129 struct list_head *list_head;
1130 struct list_head *entry, *next;
1131 u8 *mac_address = NULL;
1132
1133 vxge_debug_entryexit(VXGE_TRACE,
1134 "%s:%d", __func__, __LINE__);
1135
Joe Perches5f54ceb2010-11-15 11:12:30 +00001136 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001137 hldev = (struct __vxge_hw_device *)vdev->devh;
1138
1139 if (unlikely(!is_vxge_card_up(vdev)))
1140 return;
1141
1142 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1143 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001144 vpath = &vdev->vpaths[i];
1145 vxge_assert(vpath->is_open);
1146 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1147 if (status != VXGE_HW_OK)
1148 vxge_debug_init(VXGE_ERR, "failed to enable "
1149 "multicast, status %d", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001150 vdev->all_multi_flg = 1;
1151 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001152 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001153 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001154 vpath = &vdev->vpaths[i];
1155 vxge_assert(vpath->is_open);
1156 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1157 if (status != VXGE_HW_OK)
1158 vxge_debug_init(VXGE_ERR, "failed to disable "
1159 "multicast, status %d", status);
1160 vdev->all_multi_flg = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001161 }
1162 }
1163
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001164
1165 if (!vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001166 for (i = 0; i < vdev->no_of_vpath; i++) {
1167 vpath = &vdev->vpaths[i];
1168 vxge_assert(vpath->is_open);
1169
1170 if (dev->flags & IFF_PROMISC)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001171 status = vxge_hw_vpath_promisc_enable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001172 vpath->handle);
1173 else
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001174 status = vxge_hw_vpath_promisc_disable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001175 vpath->handle);
1176 if (status != VXGE_HW_OK)
1177 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1178 ", status %d", dev->flags&IFF_PROMISC ?
1179 "enable" : "disable", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001180 }
1181 }
1182
1183 memset(&mac_info, 0, sizeof(struct macInfo));
1184 /* Update individual M_CAST address list */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001185 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001186 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1187 list_head = &vdev->vpaths[0].mac_addr_list;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001188 if ((netdev_mc_count(dev) +
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001189 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1190 vdev->vpaths[0].max_mac_addr_cnt)
1191 goto _set_all_mcast;
1192
1193 /* Delete previous MC's */
1194 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001195 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001196 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001197 /* Copy the mac address to delete */
1198 mac_address = (u8 *)&mac_entry->macaddr;
1199 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1200
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001201 if (is_multicast_ether_addr(mac_info.macaddr)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001202 for (vpath_idx = 0; vpath_idx <
1203 vdev->no_of_vpath;
1204 vpath_idx++) {
1205 mac_info.vpath_no = vpath_idx;
1206 status = vxge_del_mac_addr(
1207 vdev,
1208 &mac_info);
1209 }
1210 }
1211 }
1212 }
1213
1214 /* Add new ones */
Jiri Pirko22bedad2010-04-01 21:22:57 +00001215 netdev_for_each_mc_addr(ha, dev) {
1216 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001217 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1218 vpath_idx++) {
1219 mac_info.vpath_no = vpath_idx;
1220 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1221 status = vxge_add_mac_addr(vdev, &mac_info);
1222 if (status != VXGE_HW_OK) {
1223 vxge_debug_init(VXGE_ERR,
1224 "%s:%d Setting individual"
1225 "multicast address failed",
1226 __func__, __LINE__);
1227 goto _set_all_mcast;
1228 }
1229 }
1230 }
1231
1232 return;
1233_set_all_mcast:
1234 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1235 /* Delete previous MC's */
1236 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001237 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001238 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001239 /* Copy the mac address to delete */
1240 mac_address = (u8 *)&mac_entry->macaddr;
1241 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1242
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001243 if (is_multicast_ether_addr(mac_info.macaddr))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001244 break;
1245 }
1246
1247 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1248 vpath_idx++) {
1249 mac_info.vpath_no = vpath_idx;
1250 status = vxge_del_mac_addr(vdev, &mac_info);
1251 }
1252 }
1253
1254 /* Enable all multicast */
1255 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001256 vpath = &vdev->vpaths[i];
1257 vxge_assert(vpath->is_open);
1258
1259 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001260 if (status != VXGE_HW_OK) {
1261 vxge_debug_init(VXGE_ERR,
1262 "%s:%d Enabling all multicasts failed",
1263 __func__, __LINE__);
1264 }
1265 vdev->all_multi_flg = 1;
1266 }
1267 dev->flags |= IFF_ALLMULTI;
1268 }
1269
1270 vxge_debug_entryexit(VXGE_TRACE,
1271 "%s:%d Exiting...", __func__, __LINE__);
1272}
1273
1274/**
1275 * vxge_set_mac_addr
1276 * @dev: pointer to the device structure
1277 *
1278 * Update entry "0" (default MAC addr)
1279 */
1280static int vxge_set_mac_addr(struct net_device *dev, void *p)
1281{
1282 struct sockaddr *addr = p;
1283 struct vxgedev *vdev;
Jon Mason2c913082010-11-11 04:26:03 +00001284 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001285 enum vxge_hw_status status = VXGE_HW_OK;
1286 struct macInfo mac_info_new, mac_info_old;
1287 int vpath_idx = 0;
1288
1289 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1290
Joe Perches5f54ceb2010-11-15 11:12:30 +00001291 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001292 hldev = vdev->devh;
1293
1294 if (!is_valid_ether_addr(addr->sa_data))
1295 return -EINVAL;
1296
1297 memset(&mac_info_new, 0, sizeof(struct macInfo));
1298 memset(&mac_info_old, 0, sizeof(struct macInfo));
1299
1300 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1301 __func__, __LINE__);
1302
1303 /* Get the old address */
1304 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1305
1306 /* Copy the new address */
1307 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1308
1309 /* First delete the old mac address from all the vpaths
1310 as we can't specify the index while adding new mac address */
1311 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1312 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1313 if (!vpath->is_open) {
1314 /* This can happen when this interface is added/removed
1315 to the bonding interface. Delete this station address
1316 from the linked list */
1317 vxge_mac_list_del(vpath, &mac_info_old);
1318
1319 /* Add this new address to the linked list
1320 for later restoring */
1321 vxge_mac_list_add(vpath, &mac_info_new);
1322
1323 continue;
1324 }
1325 /* Delete the station address */
1326 mac_info_old.vpath_no = vpath_idx;
1327 status = vxge_del_mac_addr(vdev, &mac_info_old);
1328 }
1329
1330 if (unlikely(!is_vxge_card_up(vdev))) {
1331 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1332 return VXGE_HW_OK;
1333 }
1334
1335 /* Set this mac address to all the vpaths */
1336 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1337 mac_info_new.vpath_no = vpath_idx;
1338 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1339 status = vxge_add_mac_addr(vdev, &mac_info_new);
1340 if (status != VXGE_HW_OK)
1341 return -EINVAL;
1342 }
1343
1344 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1345
1346 return status;
1347}
1348
1349/*
1350 * vxge_vpath_intr_enable
1351 * @vdev: pointer to vdev
1352 * @vp_id: vpath for which to enable the interrupts
1353 *
1354 * Enables the interrupts for the vpath
1355*/
stephen hemminger42821a52010-10-21 07:50:53 +00001356static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001357{
1358 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001359 int msix_id = 0;
1360 int tim_msix_id[4] = {0, 1, 0, 0};
1361 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001362
1363 vxge_hw_vpath_intr_enable(vpath->handle);
1364
1365 if (vdev->config.intr_type == INTA)
1366 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1367 else {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001368 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1369 alarm_msix_id);
1370
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001371 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001372 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1373 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1374
1375 /* enable the alarm vector */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001376 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1377 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1378 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001379 }
1380}
1381
1382/*
1383 * vxge_vpath_intr_disable
1384 * @vdev: pointer to vdev
1385 * @vp_id: vpath for which to disable the interrupts
1386 *
1387 * Disables the interrupts for the vpath
1388*/
stephen hemminger42821a52010-10-21 07:50:53 +00001389static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001390{
1391 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Jon Mason4d2a5b42010-11-11 04:25:54 +00001392 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001393 int msix_id;
1394
Joe Perchesd8ee7072010-11-15 10:13:58 +00001395 hldev = pci_get_drvdata(vdev->pdev);
Jon Mason4d2a5b42010-11-11 04:25:54 +00001396
1397 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1398
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001399 vxge_hw_vpath_intr_disable(vpath->handle);
1400
1401 if (vdev->config.intr_type == INTA)
1402 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1403 else {
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001404 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001405 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1406 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1407
1408 /* disable the alarm vector */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00001409 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1410 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001411 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1412 }
1413}
1414
Jon Mason528f7272010-12-10 14:02:56 +00001415/* list all mac addresses from DA table */
1416static enum vxge_hw_status
1417vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1418{
1419 enum vxge_hw_status status = VXGE_HW_OK;
1420 unsigned char macmask[ETH_ALEN];
1421 unsigned char macaddr[ETH_ALEN];
1422
1423 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1424 macaddr, macmask);
1425 if (status != VXGE_HW_OK) {
1426 vxge_debug_init(VXGE_ERR,
1427 "DA config list entry failed for vpath:%d",
1428 vpath->device_id);
1429 return status;
1430 }
1431
1432 while (memcmp(mac->macaddr, macaddr, ETH_ALEN)) {
1433 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1434 macaddr, macmask);
1435 if (status != VXGE_HW_OK)
1436 break;
1437 }
1438
1439 return status;
1440}
1441
1442/* Store all mac addresses from the list to the DA table */
1443static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1444{
1445 enum vxge_hw_status status = VXGE_HW_OK;
1446 struct macInfo mac_info;
1447 u8 *mac_address = NULL;
1448 struct list_head *entry, *next;
1449
1450 memset(&mac_info, 0, sizeof(struct macInfo));
1451
1452 if (vpath->is_open) {
1453 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1454 mac_address =
1455 (u8 *)&
1456 ((struct vxge_mac_addrs *)entry)->macaddr;
1457 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1458 ((struct vxge_mac_addrs *)entry)->state =
1459 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1460 /* does this mac address already exist in da table? */
1461 status = vxge_search_mac_addr_in_da_table(vpath,
1462 &mac_info);
1463 if (status != VXGE_HW_OK) {
1464 /* Add this mac address to the DA table */
1465 status = vxge_hw_vpath_mac_addr_add(
1466 vpath->handle, mac_info.macaddr,
1467 mac_info.macmask,
1468 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1469 if (status != VXGE_HW_OK) {
1470 vxge_debug_init(VXGE_ERR,
1471 "DA add entry failed for vpath:%d",
1472 vpath->device_id);
1473 ((struct vxge_mac_addrs *)entry)->state
1474 = VXGE_LL_MAC_ADDR_IN_LIST;
1475 }
1476 }
1477 }
1478 }
1479
1480 return status;
1481}
1482
1483/* Store all vlan ids from the list to the vid table */
1484static enum vxge_hw_status
1485vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1486{
1487 enum vxge_hw_status status = VXGE_HW_OK;
1488 struct vxgedev *vdev = vpath->vdev;
1489 u16 vid;
1490
Jiri Pirko53515732011-07-20 04:54:40 +00001491 if (!vpath->is_open)
1492 return status;
Jon Mason528f7272010-12-10 14:02:56 +00001493
Jiri Pirko53515732011-07-20 04:54:40 +00001494 for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
1495 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
Jon Mason528f7272010-12-10 14:02:56 +00001496
1497 return status;
1498}
1499
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001500/*
1501 * vxge_reset_vpath
1502 * @vdev: pointer to vdev
1503 * @vp_id: vpath to reset
1504 *
1505 * Resets the vpath
1506*/
1507static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1508{
1509 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001510 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001511 int ret = 0;
1512
1513 /* check if device is down already */
1514 if (unlikely(!is_vxge_card_up(vdev)))
1515 return 0;
1516
1517 /* is device reset already scheduled */
1518 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1519 return 0;
1520
Jon Mason7adf7d12010-07-15 08:47:24 +00001521 if (vpath->handle) {
1522 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001523 if (is_vxge_card_up(vdev) &&
Jon Mason7adf7d12010-07-15 08:47:24 +00001524 vxge_hw_vpath_recover_from_reset(vpath->handle)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001525 != VXGE_HW_OK) {
1526 vxge_debug_init(VXGE_ERR,
1527 "vxge_hw_vpath_recover_from_reset"
1528 "failed for vpath:%d", vp_id);
1529 return status;
1530 }
1531 } else {
1532 vxge_debug_init(VXGE_ERR,
1533 "vxge_hw_vpath_reset failed for"
1534 "vpath:%d", vp_id);
1535 return status;
1536 }
1537 } else
1538 return VXGE_HW_FAIL;
1539
Jon Mason7adf7d12010-07-15 08:47:24 +00001540 vxge_restore_vpath_mac_addr(vpath);
1541 vxge_restore_vpath_vid_table(vpath);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001542
1543 /* Enable all broadcast */
Jon Mason7adf7d12010-07-15 08:47:24 +00001544 vxge_hw_vpath_bcast_enable(vpath->handle);
1545
1546 /* Enable all multicast */
1547 if (vdev->all_multi_flg) {
1548 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1549 if (status != VXGE_HW_OK)
1550 vxge_debug_init(VXGE_ERR,
1551 "%s:%d Enabling multicast failed",
1552 __func__, __LINE__);
1553 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001554
1555 /* Enable the interrupts */
1556 vxge_vpath_intr_enable(vdev, vp_id);
1557
1558 smp_wmb();
1559
1560 /* Enable the flow of traffic through the vpath */
Jon Mason7adf7d12010-07-15 08:47:24 +00001561 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001562
1563 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00001564 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1565 vpath->ring.last_status = VXGE_HW_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001566
1567 /* Vpath reset done */
1568 clear_bit(vp_id, &vdev->vp_reset);
1569
1570 /* Start the vpath queue */
Jon Mason98f45da2010-07-15 08:47:25 +00001571 if (netif_tx_queue_stopped(vpath->fifo.txq))
1572 netif_tx_wake_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001573
1574 return ret;
1575}
1576
Jon Mason16fded72011-01-18 15:02:21 +00001577/* Configure CI */
1578static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1579{
1580 int i = 0;
1581
1582 /* Enable CI for RTI */
1583 if (vdev->config.intr_type == MSI_X) {
1584 for (i = 0; i < vdev->no_of_vpath; i++) {
1585 struct __vxge_hw_ring *hw_ring;
1586
1587 hw_ring = vdev->vpaths[i].ring.handle;
1588 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1589 }
1590 }
1591
1592 /* Enable CI for TTI */
1593 for (i = 0; i < vdev->no_of_vpath; i++) {
1594 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1595 vxge_hw_vpath_tti_ci_set(hw_fifo);
1596 /*
1597 * For Inta (with or without napi), Set CI ON for only one
1598 * vpath. (Have only one free running timer).
1599 */
1600 if ((vdev->config.intr_type == INTA) && (i == 0))
1601 break;
1602 }
1603
1604 return;
1605}
1606
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001607static int do_vxge_reset(struct vxgedev *vdev, int event)
1608{
1609 enum vxge_hw_status status;
1610 int ret = 0, vp_id, i;
1611
1612 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1613
1614 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1615 /* check if device is down already */
1616 if (unlikely(!is_vxge_card_up(vdev)))
1617 return 0;
1618
1619 /* is reset already scheduled */
1620 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1621 return 0;
1622 }
1623
1624 if (event == VXGE_LL_FULL_RESET) {
Jon Mason2e41f642010-12-10 14:02:59 +00001625 netif_carrier_off(vdev->ndev);
1626
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001627 /* wait for all the vpath reset to complete */
1628 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1629 while (test_bit(vp_id, &vdev->vp_reset))
1630 msleep(50);
1631 }
1632
Jon Mason2e41f642010-12-10 14:02:59 +00001633 netif_carrier_on(vdev->ndev);
1634
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001635 /* if execution mode is set to debug, don't reset the adapter */
1636 if (unlikely(vdev->exec_mode)) {
1637 vxge_debug_init(VXGE_ERR,
1638 "%s: execution mode is debug, returning..",
1639 vdev->ndev->name);
Jon Mason7adf7d12010-07-15 08:47:24 +00001640 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1641 netif_tx_stop_all_queues(vdev->ndev);
1642 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001643 }
1644 }
1645
1646 if (event == VXGE_LL_FULL_RESET) {
Jon Mason4d2a5b42010-11-11 04:25:54 +00001647 vxge_hw_device_wait_receive_idle(vdev->devh);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001648 vxge_hw_device_intr_disable(vdev->devh);
1649
1650 switch (vdev->cric_err_event) {
1651 case VXGE_HW_EVENT_UNKNOWN:
Jon Masond03848e2010-07-15 08:47:23 +00001652 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001653 vxge_debug_init(VXGE_ERR,
1654 "fatal: %s: Disabling device due to"
1655 "unknown error",
1656 vdev->ndev->name);
1657 ret = -EPERM;
1658 goto out;
1659 case VXGE_HW_EVENT_RESET_START:
1660 break;
1661 case VXGE_HW_EVENT_RESET_COMPLETE:
1662 case VXGE_HW_EVENT_LINK_DOWN:
1663 case VXGE_HW_EVENT_LINK_UP:
1664 case VXGE_HW_EVENT_ALARM_CLEARED:
1665 case VXGE_HW_EVENT_ECCERR:
1666 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1667 ret = -EPERM;
1668 goto out;
1669 case VXGE_HW_EVENT_FIFO_ERR:
1670 case VXGE_HW_EVENT_VPATH_ERR:
1671 break;
1672 case VXGE_HW_EVENT_CRITICAL_ERR:
Jon Masond03848e2010-07-15 08:47:23 +00001673 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001674 vxge_debug_init(VXGE_ERR,
1675 "fatal: %s: Disabling device due to"
1676 "serious error",
1677 vdev->ndev->name);
1678 /* SOP or device reset required */
1679 /* This event is not currently used */
1680 ret = -EPERM;
1681 goto out;
1682 case VXGE_HW_EVENT_SERR:
Jon Masond03848e2010-07-15 08:47:23 +00001683 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001684 vxge_debug_init(VXGE_ERR,
1685 "fatal: %s: Disabling device due to"
1686 "serious error",
1687 vdev->ndev->name);
1688 ret = -EPERM;
1689 goto out;
1690 case VXGE_HW_EVENT_SRPCIM_SERR:
1691 case VXGE_HW_EVENT_MRPCIM_SERR:
1692 ret = -EPERM;
1693 goto out;
1694 case VXGE_HW_EVENT_SLOT_FREEZE:
Jon Masond03848e2010-07-15 08:47:23 +00001695 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001696 vxge_debug_init(VXGE_ERR,
1697 "fatal: %s: Disabling device due to"
1698 "slot freeze",
1699 vdev->ndev->name);
1700 ret = -EPERM;
1701 goto out;
1702 default:
1703 break;
1704
1705 }
1706 }
1707
1708 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
Jon Masond03848e2010-07-15 08:47:23 +00001709 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001710
1711 if (event == VXGE_LL_FULL_RESET) {
1712 status = vxge_reset_all_vpaths(vdev);
1713 if (status != VXGE_HW_OK) {
1714 vxge_debug_init(VXGE_ERR,
1715 "fatal: %s: can not reset vpaths",
1716 vdev->ndev->name);
1717 ret = -EPERM;
1718 goto out;
1719 }
1720 }
1721
1722 if (event == VXGE_LL_COMPL_RESET) {
1723 for (i = 0; i < vdev->no_of_vpath; i++)
1724 if (vdev->vpaths[i].handle) {
1725 if (vxge_hw_vpath_recover_from_reset(
1726 vdev->vpaths[i].handle)
1727 != VXGE_HW_OK) {
1728 vxge_debug_init(VXGE_ERR,
1729 "vxge_hw_vpath_recover_"
1730 "from_reset failed for vpath: "
1731 "%d", i);
1732 ret = -EPERM;
1733 goto out;
1734 }
1735 } else {
1736 vxge_debug_init(VXGE_ERR,
1737 "vxge_hw_vpath_reset failed for "
1738 "vpath:%d", i);
1739 ret = -EPERM;
1740 goto out;
1741 }
1742 }
1743
1744 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1745 /* Reprogram the DA table with populated mac addresses */
1746 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1747 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1748 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1749 }
1750
1751 /* enable vpath interrupts */
1752 for (i = 0; i < vdev->no_of_vpath; i++)
1753 vxge_vpath_intr_enable(vdev, i);
1754
1755 vxge_hw_device_intr_enable(vdev->devh);
1756
1757 smp_wmb();
1758
1759 /* Indicate card up */
1760 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1761
1762 /* Get the traffic to flow through the vpaths */
1763 for (i = 0; i < vdev->no_of_vpath; i++) {
1764 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1765 smp_wmb();
1766 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1767 }
1768
Jon Masond03848e2010-07-15 08:47:23 +00001769 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001770 }
1771
Jon Mason16fded72011-01-18 15:02:21 +00001772 /* configure CI */
1773 vxge_config_ci_for_tti_rti(vdev);
1774
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001775out:
1776 vxge_debug_entryexit(VXGE_TRACE,
1777 "%s:%d Exiting...", __func__, __LINE__);
1778
1779 /* Indicate reset done */
1780 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1781 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1782 return ret;
1783}
1784
1785/*
1786 * vxge_reset
1787 * @vdev: pointer to ll device
1788 *
1789 * driver may reset the chip on events of serr, eccerr, etc
1790 */
Jon Mason2e41f642010-12-10 14:02:59 +00001791static void vxge_reset(struct work_struct *work)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001792{
Jon Mason2e41f642010-12-10 14:02:59 +00001793 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1794
1795 if (!netif_running(vdev->ndev))
1796 return;
1797
1798 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001799}
1800
1801/**
1802 * vxge_poll - Receive handler when Receive Polling is used.
1803 * @dev: pointer to the device structure.
1804 * @budget: Number of packets budgeted to be processed in this iteration.
1805 *
1806 * This function comes into picture only if Receive side is being handled
1807 * through polling (called NAPI in linux). It mostly does what the normal
1808 * Rx interrupt handler does in terms of descriptor and packet processing
1809 * but not in an interrupt context. Also it will process a specified number
1810 * of packets at most in one iteration. This value is passed down by the
1811 * kernel as the function argument 'budget'.
1812 */
1813static int vxge_poll_msix(struct napi_struct *napi, int budget)
1814{
Jon Mason16fded72011-01-18 15:02:21 +00001815 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1816 int pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001817 int budget_org = budget;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001818
Jon Mason16fded72011-01-18 15:02:21 +00001819 ring->budget = budget;
1820 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001821 vxge_hw_vpath_poll_rx(ring->handle);
Jon Mason16fded72011-01-18 15:02:21 +00001822 pkts_processed = ring->pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001823
1824 if (ring->pkts_processed < budget_org) {
1825 napi_complete(napi);
Jon Mason16fded72011-01-18 15:02:21 +00001826
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001827 /* Re enable the Rx interrupts for the vpath */
1828 vxge_hw_channel_msix_unmask(
1829 (struct __vxge_hw_channel *)ring->handle,
1830 ring->rx_vector_no);
Jon Mason16fded72011-01-18 15:02:21 +00001831 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001832 }
1833
Jon Mason16fded72011-01-18 15:02:21 +00001834 /* We are copying and returning the local variable, in case if after
1835 * clearing the msix interrupt above, if the interrupt fires right
1836 * away which can preempt this NAPI thread */
1837 return pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001838}
1839
1840static int vxge_poll_inta(struct napi_struct *napi, int budget)
1841{
1842 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1843 int pkts_processed = 0;
1844 int i;
1845 int budget_org = budget;
1846 struct vxge_ring *ring;
1847
Joe Perchesd8ee7072010-11-15 10:13:58 +00001848 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001849
1850 for (i = 0; i < vdev->no_of_vpath; i++) {
1851 ring = &vdev->vpaths[i].ring;
1852 ring->budget = budget;
Jon Mason16fded72011-01-18 15:02:21 +00001853 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001854 vxge_hw_vpath_poll_rx(ring->handle);
1855 pkts_processed += ring->pkts_processed;
1856 budget -= ring->pkts_processed;
1857 if (budget <= 0)
1858 break;
1859 }
1860
1861 VXGE_COMPLETE_ALL_TX(vdev);
1862
1863 if (pkts_processed < budget_org) {
1864 napi_complete(napi);
1865 /* Re enable the Rx interrupts for the ring */
1866 vxge_hw_device_unmask_all(hldev);
1867 vxge_hw_device_flush_io(hldev);
1868 }
1869
1870 return pkts_processed;
1871}
1872
1873#ifdef CONFIG_NET_POLL_CONTROLLER
1874/**
1875 * vxge_netpoll - netpoll event handler entry point
1876 * @dev : pointer to the device structure.
1877 * Description:
1878 * This function will be called by upper layer to check for events on the
1879 * interface in situations where interrupts are disabled. It is used for
1880 * specific in-kernel networking tasks, such as remote consoles and kernel
1881 * debugging over the network (example netdump in RedHat).
1882 */
1883static void vxge_netpoll(struct net_device *dev)
1884{
Jon Mason2c913082010-11-11 04:26:03 +00001885 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001886 struct vxgedev *vdev;
1887
Joe Perches5f54ceb2010-11-15 11:12:30 +00001888 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00001889 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001890
1891 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1892
1893 if (pci_channel_offline(vdev->pdev))
1894 return;
1895
1896 disable_irq(dev->irq);
1897 vxge_hw_device_clear_tx_rx(hldev);
1898
1899 vxge_hw_device_clear_tx_rx(hldev);
1900 VXGE_COMPLETE_ALL_RX(vdev);
1901 VXGE_COMPLETE_ALL_TX(vdev);
1902
1903 enable_irq(dev->irq);
1904
1905 vxge_debug_entryexit(VXGE_TRACE,
1906 "%s:%d Exiting...", __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001907}
1908#endif
1909
1910/* RTH configuration */
1911static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1912{
1913 enum vxge_hw_status status = VXGE_HW_OK;
1914 struct vxge_hw_rth_hash_types hash_types;
1915 u8 itable[256] = {0}; /* indirection table */
1916 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1917 int index;
1918
1919 /*
1920 * Filling
1921 * - itable with bucket numbers
1922 * - mtable with bucket-to-vpath mapping
1923 */
1924 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1925 itable[index] = index;
1926 mtable[index] = index % vdev->no_of_vpath;
1927 }
1928
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001929 /* set indirection table, bucket-to-vpath mapping */
1930 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1931 vdev->no_of_vpath,
1932 mtable, itable,
1933 vdev->config.rth_bkt_sz);
1934 if (status != VXGE_HW_OK) {
1935 vxge_debug_init(VXGE_ERR,
1936 "RTH indirection table configuration failed "
1937 "for vpath:%d", vdev->vpaths[0].device_id);
1938 return status;
1939 }
1940
Jon Mason47f01db2010-11-11 04:25:53 +00001941 /* Fill RTH hash types */
1942 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1943 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1944 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1945 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1946 hash_types.hash_type_tcpipv6ex_en =
1947 vdev->config.rth_hash_type_tcpipv6ex;
1948 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1949
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001950 /*
Jon Mason47f01db2010-11-11 04:25:53 +00001951 * Because the itable_set() method uses the active_table field
1952 * for the target virtual path the RTH config should be updated
1953 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1954 * when steering frames.
1955 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001956 for (index = 0; index < vdev->no_of_vpath; index++) {
1957 status = vxge_hw_vpath_rts_rth_set(
1958 vdev->vpaths[index].handle,
1959 vdev->config.rth_algorithm,
1960 &hash_types,
1961 vdev->config.rth_bkt_sz);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001962 if (status != VXGE_HW_OK) {
1963 vxge_debug_init(VXGE_ERR,
1964 "RTH configuration failed for vpath:%d",
1965 vdev->vpaths[index].device_id);
1966 return status;
1967 }
1968 }
1969
1970 return status;
1971}
1972
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001973/* reset vpaths */
Jon Mason4d2a5b42010-11-11 04:25:54 +00001974enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001975{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001976 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001977 struct vxge_vpath *vpath;
1978 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001979
Jon Mason7adf7d12010-07-15 08:47:24 +00001980 for (i = 0; i < vdev->no_of_vpath; i++) {
1981 vpath = &vdev->vpaths[i];
1982 if (vpath->handle) {
1983 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001984 if (is_vxge_card_up(vdev) &&
1985 vxge_hw_vpath_recover_from_reset(
Jon Mason7adf7d12010-07-15 08:47:24 +00001986 vpath->handle) != VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001987 vxge_debug_init(VXGE_ERR,
1988 "vxge_hw_vpath_recover_"
1989 "from_reset failed for vpath: "
1990 "%d", i);
1991 return status;
1992 }
1993 } else {
1994 vxge_debug_init(VXGE_ERR,
1995 "vxge_hw_vpath_reset failed for "
1996 "vpath:%d", i);
1997 return status;
1998 }
1999 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002000 }
2001
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002002 return status;
2003}
2004
2005/* close vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002006static void vxge_close_vpaths(struct vxgedev *vdev, int index)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002007{
Jon Mason7adf7d12010-07-15 08:47:24 +00002008 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002009 int i;
Jon Mason7adf7d12010-07-15 08:47:24 +00002010
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002011 for (i = index; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002012 vpath = &vdev->vpaths[i];
2013
2014 if (vpath->handle && vpath->is_open) {
2015 vxge_hw_vpath_close(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002016 vdev->stats.vpaths_open--;
2017 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002018 vpath->is_open = 0;
2019 vpath->handle = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002020 }
2021}
2022
2023/* open vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002024static int vxge_open_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002025{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002026 struct vxge_hw_vpath_attr attr;
Jon Mason7adf7d12010-07-15 08:47:24 +00002027 enum vxge_hw_status status;
2028 struct vxge_vpath *vpath;
2029 u32 vp_id = 0;
2030 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002031
2032 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002033 vpath = &vdev->vpaths[i];
Jon Mason7adf7d12010-07-15 08:47:24 +00002034 vxge_assert(vpath->is_configured);
Jon Masone7935c92010-11-11 04:26:00 +00002035
2036 if (!vdev->titan1) {
2037 struct vxge_hw_vp_config *vcfg;
2038 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2039
2040 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2041 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2042 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2043 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2044 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2045 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2046 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2047 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2048 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2049 }
2050
Jon Mason7adf7d12010-07-15 08:47:24 +00002051 attr.vp_id = vpath->device_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002052 attr.fifo_attr.callback = vxge_xmit_compl;
2053 attr.fifo_attr.txdl_term = vxge_tx_term;
2054 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002055 attr.fifo_attr.userdata = &vpath->fifo;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002056
2057 attr.ring_attr.callback = vxge_rx_1b_compl;
2058 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2059 attr.ring_attr.rxd_term = vxge_rx_term;
2060 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002061 attr.ring_attr.userdata = &vpath->ring;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002062
Jon Mason7adf7d12010-07-15 08:47:24 +00002063 vpath->ring.ndev = vdev->ndev;
2064 vpath->ring.pdev = vdev->pdev;
Jon Mason528f7272010-12-10 14:02:56 +00002065
Jon Mason7adf7d12010-07-15 08:47:24 +00002066 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002067 if (status == VXGE_HW_OK) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002068 vpath->fifo.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002069 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002070 vpath->ring.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002071 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002072 vpath->fifo.tx_steering_type =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002073 vdev->config.tx_steering_type;
Jon Mason7adf7d12010-07-15 08:47:24 +00002074 vpath->fifo.ndev = vdev->ndev;
2075 vpath->fifo.pdev = vdev->pdev;
Jon Mason98f45da2010-07-15 08:47:25 +00002076 if (vdev->config.tx_steering_type)
2077 vpath->fifo.txq =
2078 netdev_get_tx_queue(vdev->ndev, i);
2079 else
2080 vpath->fifo.txq =
2081 netdev_get_tx_queue(vdev->ndev, 0);
Jon Mason7adf7d12010-07-15 08:47:24 +00002082 vpath->fifo.indicate_max_pkts =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002083 vdev->config.fifo_indicate_max_pkts;
Jon Mason16fded72011-01-18 15:02:21 +00002084 vpath->fifo.tx_vector_no = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00002085 vpath->ring.rx_vector_no = 0;
Jon Masonb81b3732010-11-11 04:25:58 +00002086 vpath->ring.rx_hwts = vdev->rx_hwts;
Jon Mason7adf7d12010-07-15 08:47:24 +00002087 vpath->is_open = 1;
2088 vdev->vp_handles[i] = vpath->handle;
Jon Mason7adf7d12010-07-15 08:47:24 +00002089 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002090 vdev->stats.vpaths_open++;
2091 } else {
2092 vdev->stats.vpath_open_fail++;
Jon Mason528f7272010-12-10 14:02:56 +00002093 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2094 "open with status: %d",
2095 vdev->ndev->name, vpath->device_id,
2096 status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002097 vxge_close_vpaths(vdev, 0);
2098 return -EPERM;
2099 }
2100
Jon Mason7adf7d12010-07-15 08:47:24 +00002101 vp_id = vpath->handle->vpath->vp_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002102 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2103 }
Jon Mason528f7272010-12-10 14:02:56 +00002104
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002105 return VXGE_HW_OK;
2106}
2107
Jon Mason16fded72011-01-18 15:02:21 +00002108/**
2109 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2110 * if the interrupts are not within a range
2111 * @fifo: pointer to transmit fifo structure
2112 * Description: The function changes boundary timer and restriction timer
2113 * value depends on the traffic
2114 * Return Value: None
2115 */
2116static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2117{
2118 fifo->interrupt_count++;
2119 if (jiffies > fifo->jiffies + HZ / 100) {
2120 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2121
2122 fifo->jiffies = jiffies;
2123 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2124 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2125 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2126 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2127 } else if (hw_fifo->rtimer != 0) {
2128 hw_fifo->rtimer = 0;
2129 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2130 }
2131 fifo->interrupt_count = 0;
2132 }
2133}
2134
2135/**
2136 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2137 * if the interrupts are not within a range
2138 * @ring: pointer to receive ring structure
2139 * Description: The function increases of decreases the packet counts within
2140 * the ranges of traffic utilization, if the interrupts due to this ring are
2141 * not within a fixed range.
2142 * Return Value: Nothing
2143 */
2144static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2145{
2146 ring->interrupt_count++;
2147 if (jiffies > ring->jiffies + HZ / 100) {
2148 struct __vxge_hw_ring *hw_ring = ring->handle;
2149
2150 ring->jiffies = jiffies;
2151 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2152 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2153 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2154 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2155 } else if (hw_ring->rtimer != 0) {
2156 hw_ring->rtimer = 0;
2157 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2158 }
2159 ring->interrupt_count = 0;
2160 }
2161}
2162
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002163/*
2164 * vxge_isr_napi
2165 * @irq: the irq of the device.
2166 * @dev_id: a void pointer to the hldev structure of the Titan device
2167 * @ptregs: pointer to the registers pushed on the stack.
2168 *
2169 * This function is the ISR handler of the device when napi is enabled. It
2170 * identifies the reason for the interrupt and calls the relevant service
2171 * routines.
2172 */
2173static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2174{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002175 struct net_device *dev;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002176 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002177 u64 reason;
2178 enum vxge_hw_status status;
Jon Mason2c913082010-11-11 04:26:03 +00002179 struct vxgedev *vdev = (struct vxgedev *)dev_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002180
2181 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2182
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002183 dev = vdev->ndev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002184 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002185
2186 if (pci_channel_offline(vdev->pdev))
2187 return IRQ_NONE;
2188
2189 if (unlikely(!is_vxge_card_up(vdev)))
Jon Mason4d2a5b42010-11-11 04:25:54 +00002190 return IRQ_HANDLED;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002191
Jon Mason528f7272010-12-10 14:02:56 +00002192 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002193 if (status == VXGE_HW_OK) {
2194 vxge_hw_device_mask_all(hldev);
2195
2196 if (reason &
2197 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2198 vdev->vpaths_deployed >>
2199 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2200
2201 vxge_hw_device_clear_tx_rx(hldev);
2202 napi_schedule(&vdev->napi);
2203 vxge_debug_intr(VXGE_TRACE,
2204 "%s:%d Exiting...", __func__, __LINE__);
2205 return IRQ_HANDLED;
2206 } else
2207 vxge_hw_device_unmask_all(hldev);
2208 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2209 (status == VXGE_HW_ERR_CRITICAL) ||
2210 (status == VXGE_HW_ERR_FIFO))) {
2211 vxge_hw_device_mask_all(hldev);
2212 vxge_hw_device_flush_io(hldev);
2213 return IRQ_HANDLED;
2214 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2215 return IRQ_HANDLED;
2216
2217 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2218 return IRQ_NONE;
2219}
2220
2221#ifdef CONFIG_PCI_MSI
2222
Jon Mason16fded72011-01-18 15:02:21 +00002223static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002224{
2225 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2226
Jon Mason16fded72011-01-18 15:02:21 +00002227 adaptive_coalesce_tx_interrupts(fifo);
2228
2229 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2230 fifo->tx_vector_no);
2231
2232 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2233 fifo->tx_vector_no);
2234
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002235 VXGE_COMPLETE_VPATH_TX(fifo);
2236
Jon Mason16fded72011-01-18 15:02:21 +00002237 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2238 fifo->tx_vector_no);
2239
2240 mmiowb();
2241
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002242 return IRQ_HANDLED;
2243}
2244
Jon Mason16fded72011-01-18 15:02:21 +00002245static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002246{
2247 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2248
Jon Mason16fded72011-01-18 15:02:21 +00002249 adaptive_coalesce_rx_interrupts(ring);
2250
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002251 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
Jon Mason16fded72011-01-18 15:02:21 +00002252 ring->rx_vector_no);
2253
2254 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2255 ring->rx_vector_no);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002256
2257 napi_schedule(&ring->napi);
2258 return IRQ_HANDLED;
2259}
2260
2261static irqreturn_t
2262vxge_alarm_msix_handle(int irq, void *dev_id)
2263{
2264 int i;
2265 enum vxge_hw_status status;
2266 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2267 struct vxgedev *vdev = vpath->vdev;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002268 int msix_id = (vpath->handle->vpath->vp_id *
2269 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002270
2271 for (i = 0; i < vdev->no_of_vpath; i++) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002272 /* Reduce the chance of losing alarm interrupts by masking
Jon Mason16fded72011-01-18 15:02:21 +00002273 * the vector. A pending bit will be set if an alarm is
2274 * generated and on unmask the interrupt will be fired.
2275 */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002276 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
Jon Mason16fded72011-01-18 15:02:21 +00002277 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2278 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002279
2280 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2281 vdev->exec_mode);
2282 if (status == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002283 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
Jon Mason16fded72011-01-18 15:02:21 +00002284 msix_id);
2285 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002286 continue;
2287 }
2288 vxge_debug_intr(VXGE_ERR,
2289 "%s: vxge_hw_vpath_alarm_process failed %x ",
2290 VXGE_DRIVER_NAME, status);
2291 }
2292 return IRQ_HANDLED;
2293}
2294
2295static int vxge_alloc_msix(struct vxgedev *vdev)
2296{
2297 int j, i, ret = 0;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002298 int msix_intr_vect = 0, temp;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002299 vdev->intr_cnt = 0;
2300
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002301start:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002302 /* Tx/Rx MSIX Vectors count */
2303 vdev->intr_cnt = vdev->no_of_vpath * 2;
2304
2305 /* Alarm MSIX Vectors count */
2306 vdev->intr_cnt++;
2307
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002308 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2309 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002310 if (!vdev->entries) {
2311 vxge_debug_init(VXGE_ERR,
2312 "%s: memory allocation failed",
2313 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002314 ret = -ENOMEM;
2315 goto alloc_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002316 }
2317
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002318 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2319 sizeof(struct vxge_msix_entry),
2320 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002321 if (!vdev->vxge_entries) {
2322 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2323 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002324 ret = -ENOMEM;
2325 goto alloc_vxge_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002326 }
2327
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002328 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002329
2330 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2331
2332 /* Initialize the fifo vector */
2333 vdev->entries[j].entry = msix_intr_vect;
2334 vdev->vxge_entries[j].entry = msix_intr_vect;
2335 vdev->vxge_entries[j].in_use = 0;
2336 j++;
2337
2338 /* Initialize the ring vector */
2339 vdev->entries[j].entry = msix_intr_vect + 1;
2340 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2341 vdev->vxge_entries[j].in_use = 0;
2342 j++;
2343 }
2344
2345 /* Initialize the alarm vector */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002346 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2347 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002348 vdev->vxge_entries[j].in_use = 0;
2349
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002350 ret = pci_enable_msix(vdev->pdev, vdev->entries, vdev->intr_cnt);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002351 if (ret > 0) {
2352 vxge_debug_init(VXGE_ERR,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002353 "%s: MSI-X enable failed for %d vectors, ret: %d",
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002354 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002355 if ((max_config_vpath != VXGE_USE_DEFAULT) || (ret < 3)) {
2356 ret = -ENODEV;
2357 goto enable_msix_failed;
2358 }
2359
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002360 kfree(vdev->entries);
2361 kfree(vdev->vxge_entries);
2362 vdev->entries = NULL;
2363 vdev->vxge_entries = NULL;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002364 /* Try with less no of vector by reducing no of vpaths count */
2365 temp = (ret - 1)/2;
2366 vxge_close_vpaths(vdev, temp);
2367 vdev->no_of_vpath = temp;
2368 goto start;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002369 } else if (ret < 0) {
2370 ret = -ENODEV;
2371 goto enable_msix_failed;
2372 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002373 return 0;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002374
2375enable_msix_failed:
2376 kfree(vdev->vxge_entries);
2377alloc_vxge_entries_failed:
2378 kfree(vdev->entries);
2379alloc_entries_failed:
2380 return ret;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002381}
2382
2383static int vxge_enable_msix(struct vxgedev *vdev)
2384{
2385
2386 int i, ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002387 /* 0 - Tx, 1 - Rx */
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002388 int tim_msix_id[4] = {0, 1, 0, 0};
2389
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002390 vdev->intr_cnt = 0;
2391
2392 /* allocate msix vectors */
2393 ret = vxge_alloc_msix(vdev);
2394 if (!ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002395 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002396 struct vxge_vpath *vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002397
Jon Mason7adf7d12010-07-15 08:47:24 +00002398 /* If fifo or ring are not enabled, the MSIX vector for
2399 * it should be set to 0.
2400 */
2401 vpath->ring.rx_vector_no = (vpath->device_id *
2402 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002403
Jon Mason16fded72011-01-18 15:02:21 +00002404 vpath->fifo.tx_vector_no = (vpath->device_id *
2405 VXGE_HW_VPATH_MSIX_ACTIVE);
2406
Jon Mason7adf7d12010-07-15 08:47:24 +00002407 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2408 VXGE_ALARM_MSIX_ID);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002409 }
2410 }
2411
2412 return ret;
2413}
2414
2415static void vxge_rem_msix_isr(struct vxgedev *vdev)
2416{
2417 int intr_cnt;
2418
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002419 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002420 intr_cnt++) {
2421 if (vdev->vxge_entries[intr_cnt].in_use) {
2422 synchronize_irq(vdev->entries[intr_cnt].vector);
2423 free_irq(vdev->entries[intr_cnt].vector,
2424 vdev->vxge_entries[intr_cnt].arg);
2425 vdev->vxge_entries[intr_cnt].in_use = 0;
2426 }
2427 }
2428
2429 kfree(vdev->entries);
2430 kfree(vdev->vxge_entries);
2431 vdev->entries = NULL;
2432 vdev->vxge_entries = NULL;
2433
2434 if (vdev->config.intr_type == MSI_X)
2435 pci_disable_msix(vdev->pdev);
2436}
2437#endif
2438
2439static void vxge_rem_isr(struct vxgedev *vdev)
2440{
Jon Mason2c913082010-11-11 04:26:03 +00002441 struct __vxge_hw_device *hldev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002442 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002443
2444#ifdef CONFIG_PCI_MSI
2445 if (vdev->config.intr_type == MSI_X) {
2446 vxge_rem_msix_isr(vdev);
2447 } else
2448#endif
2449 if (vdev->config.intr_type == INTA) {
2450 synchronize_irq(vdev->pdev->irq);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002451 free_irq(vdev->pdev->irq, vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002452 }
2453}
2454
2455static int vxge_add_isr(struct vxgedev *vdev)
2456{
2457 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002458#ifdef CONFIG_PCI_MSI
2459 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002460 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2461
2462 if (vdev->config.intr_type == MSI_X)
2463 ret = vxge_enable_msix(vdev);
2464
2465 if (ret) {
2466 vxge_debug_init(VXGE_ERR,
2467 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002468 vxge_debug_init(VXGE_ERR,
2469 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2470 vdev->config.intr_type = INTA;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002471 }
2472
2473 if (vdev->config.intr_type == MSI_X) {
2474 for (intr_idx = 0;
2475 intr_idx < (vdev->no_of_vpath *
2476 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2477
2478 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2479 irq_req = 0;
2480
2481 switch (msix_idx) {
2482 case 0:
2483 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002484 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2485 vdev->ndev->name,
2486 vdev->entries[intr_cnt].entry,
2487 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002488 ret = request_irq(
2489 vdev->entries[intr_cnt].vector,
2490 vxge_tx_msix_handle, 0,
2491 vdev->desc[intr_cnt],
2492 &vdev->vpaths[vp_idx].fifo);
2493 vdev->vxge_entries[intr_cnt].arg =
2494 &vdev->vpaths[vp_idx].fifo;
2495 irq_req = 1;
2496 break;
2497 case 1:
2498 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002499 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2500 vdev->ndev->name,
2501 vdev->entries[intr_cnt].entry,
2502 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002503 ret = request_irq(
2504 vdev->entries[intr_cnt].vector,
2505 vxge_rx_msix_napi_handle,
2506 0,
2507 vdev->desc[intr_cnt],
2508 &vdev->vpaths[vp_idx].ring);
2509 vdev->vxge_entries[intr_cnt].arg =
2510 &vdev->vpaths[vp_idx].ring;
2511 irq_req = 1;
2512 break;
2513 }
2514
2515 if (ret) {
2516 vxge_debug_init(VXGE_ERR,
2517 "%s: MSIX - %d Registration failed",
2518 vdev->ndev->name, intr_cnt);
2519 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002520 vdev->config.intr_type = INTA;
2521 vxge_debug_init(VXGE_ERR,
2522 "%s: Defaulting to INTA"
2523 , vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002524 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002525 }
2526
2527 if (irq_req) {
2528 /* We requested for this msix interrupt */
2529 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002530 msix_idx += vdev->vpaths[vp_idx].device_id *
2531 VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002532 vxge_hw_vpath_msix_unmask(
2533 vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002534 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002535 intr_cnt++;
2536 }
2537
2538 /* Point to next vpath handler */
Joe Perches8e95a202009-12-03 07:58:21 +00002539 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2540 (vp_idx < (vdev->no_of_vpath - 1)))
2541 vp_idx++;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002542 }
2543
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002544 intr_cnt = vdev->no_of_vpath * 2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002545 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002546 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2547 vdev->ndev->name,
2548 vdev->entries[intr_cnt].entry,
2549 pci_fun);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002550 /* For Alarm interrupts */
2551 ret = request_irq(vdev->entries[intr_cnt].vector,
2552 vxge_alarm_msix_handle, 0,
2553 vdev->desc[intr_cnt],
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002554 &vdev->vpaths[0]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002555 if (ret) {
2556 vxge_debug_init(VXGE_ERR,
2557 "%s: MSIX - %d Registration failed",
2558 vdev->ndev->name, intr_cnt);
2559 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002560 vdev->config.intr_type = INTA;
2561 vxge_debug_init(VXGE_ERR,
2562 "%s: Defaulting to INTA",
2563 vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002564 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002565 }
2566
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002567 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2568 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002569 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002570 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002571 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002572 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002573 }
2574INTA_MODE:
2575#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002576
2577 if (vdev->config.intr_type == INTA) {
Sreenivasa Honnurb59c9452010-03-28 22:11:41 +00002578 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2579 "%s:vxge:INTA", vdev->ndev->name);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002580 vxge_hw_device_set_intr_type(vdev->devh,
2581 VXGE_HW_INTR_MODE_IRQLINE);
Jon Mason16fded72011-01-18 15:02:21 +00002582
2583 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2584
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002585 ret = request_irq((int) vdev->pdev->irq,
2586 vxge_isr_napi,
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002587 IRQF_SHARED, vdev->desc[0], vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002588 if (ret) {
2589 vxge_debug_init(VXGE_ERR,
2590 "%s %s-%d: ISR registration failed",
2591 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2592 return -ENODEV;
2593 }
2594 vxge_debug_init(VXGE_TRACE,
2595 "new %s-%d line allocated",
2596 "IRQ", vdev->pdev->irq);
2597 }
2598
2599 return VXGE_HW_OK;
2600}
2601
2602static void vxge_poll_vp_reset(unsigned long data)
2603{
2604 struct vxgedev *vdev = (struct vxgedev *)data;
2605 int i, j = 0;
2606
2607 for (i = 0; i < vdev->no_of_vpath; i++) {
2608 if (test_bit(i, &vdev->vp_reset)) {
2609 vxge_reset_vpath(vdev, i);
2610 j++;
2611 }
2612 }
2613 if (j && (vdev->config.intr_type != MSI_X)) {
2614 vxge_hw_device_unmask_all(vdev->devh);
2615 vxge_hw_device_flush_io(vdev->devh);
2616 }
2617
2618 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2619}
2620
2621static void vxge_poll_vp_lockup(unsigned long data)
2622{
2623 struct vxgedev *vdev = (struct vxgedev *)data;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002624 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00002625 struct vxge_vpath *vpath;
2626 struct vxge_ring *ring;
2627 int i;
stephen hemminger62ea0552011-06-20 10:35:07 +00002628 unsigned long rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002629
2630 for (i = 0; i < vdev->no_of_vpath; i++) {
2631 ring = &vdev->vpaths[i].ring;
stephen hemminger62ea0552011-06-20 10:35:07 +00002632
2633 /* Truncated to machine word size number of frames */
2634 rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
2635
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002636 /* Did this vpath received any packets */
stephen hemminger62ea0552011-06-20 10:35:07 +00002637 if (ring->stats.prev_rx_frms == rx_frms) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002638 status = vxge_hw_vpath_check_leak(ring->handle);
2639
2640 /* Did it received any packets last time */
2641 if ((VXGE_HW_FAIL == status) &&
2642 (VXGE_HW_FAIL == ring->last_status)) {
2643
2644 /* schedule vpath reset */
2645 if (!test_and_set_bit(i, &vdev->vp_reset)) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002646 vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002647
2648 /* disable interrupts for this vpath */
2649 vxge_vpath_intr_disable(vdev, i);
2650
2651 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00002652 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002653 continue;
2654 }
2655 }
2656 }
stephen hemminger62ea0552011-06-20 10:35:07 +00002657 ring->stats.prev_rx_frms = rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002658 ring->last_status = status;
2659 }
2660
2661 /* Check every 1 milli second */
2662 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2663}
2664
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002665static netdev_features_t vxge_fix_features(struct net_device *dev,
2666 netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002667{
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002668 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002669
2670 /* Enabling RTH requires some of the logic in vxge_device_register and a
2671 * vpath reset. Due to these restrictions, only allow modification
2672 * while the interface is down.
2673 */
2674 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2675 features ^= NETIF_F_RXHASH;
2676
2677 return features;
2678}
2679
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002680static int vxge_set_features(struct net_device *dev, netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002681{
2682 struct vxgedev *vdev = netdev_priv(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002683 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002684
2685 if (!(changed & NETIF_F_RXHASH))
2686 return 0;
2687
2688 /* !netif_running() ensured by vxge_fix_features() */
2689
2690 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2691 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2692 dev->features = features ^ NETIF_F_RXHASH;
2693 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2694 return -EIO;
2695 }
2696
2697 return 0;
2698}
2699
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002700/**
2701 * vxge_open
2702 * @dev: pointer to the device structure.
2703 *
2704 * This function is the open entry point of the driver. It mainly calls a
2705 * function to allocate Rx buffers and inserts them into the buffer
2706 * descriptors and then enables the Rx part of the NIC.
2707 * Return value: '0' on success and an appropriate (-)ve integer as
2708 * defined in errno.h file on failure.
2709 */
Jon Mason528f7272010-12-10 14:02:56 +00002710static int vxge_open(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002711{
2712 enum vxge_hw_status status;
2713 struct vxgedev *vdev;
2714 struct __vxge_hw_device *hldev;
Jon Mason7adf7d12010-07-15 08:47:24 +00002715 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002716 int ret = 0;
2717 int i;
2718 u64 val64, function_mode;
Jon Mason528f7272010-12-10 14:02:56 +00002719
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002720 vxge_debug_entryexit(VXGE_TRACE,
2721 "%s: %s:%d", dev->name, __func__, __LINE__);
2722
Joe Perches5f54ceb2010-11-15 11:12:30 +00002723 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002724 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002725 function_mode = vdev->config.device_hw_info.function_mode;
2726
2727 /* make sure you have link off by default every time Nic is
2728 * initialized */
2729 netif_carrier_off(dev);
2730
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002731 /* Open VPATHs */
2732 status = vxge_open_vpaths(vdev);
2733 if (status != VXGE_HW_OK) {
2734 vxge_debug_init(VXGE_ERR,
2735 "%s: fatal: Vpath open failed", vdev->ndev->name);
2736 ret = -EPERM;
2737 goto out0;
2738 }
2739
2740 vdev->mtu = dev->mtu;
2741
2742 status = vxge_add_isr(vdev);
2743 if (status != VXGE_HW_OK) {
2744 vxge_debug_init(VXGE_ERR,
2745 "%s: fatal: ISR add failed", dev->name);
2746 ret = -EPERM;
2747 goto out1;
2748 }
2749
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002750 if (vdev->config.intr_type != MSI_X) {
2751 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2752 vdev->config.napi_weight);
2753 napi_enable(&vdev->napi);
Jon Mason7adf7d12010-07-15 08:47:24 +00002754 for (i = 0; i < vdev->no_of_vpath; i++) {
2755 vpath = &vdev->vpaths[i];
2756 vpath->ring.napi_p = &vdev->napi;
2757 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002758 } else {
2759 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002760 vpath = &vdev->vpaths[i];
2761 netif_napi_add(dev, &vpath->ring.napi,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002762 vxge_poll_msix, vdev->config.napi_weight);
Jon Mason7adf7d12010-07-15 08:47:24 +00002763 napi_enable(&vpath->ring.napi);
2764 vpath->ring.napi_p = &vpath->ring.napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002765 }
2766 }
2767
2768 /* configure RTH */
2769 if (vdev->config.rth_steering) {
2770 status = vxge_rth_configure(vdev);
2771 if (status != VXGE_HW_OK) {
2772 vxge_debug_init(VXGE_ERR,
2773 "%s: fatal: RTH configuration failed",
2774 dev->name);
2775 ret = -EPERM;
2776 goto out2;
2777 }
2778 }
Jon Mason47f01db2010-11-11 04:25:53 +00002779 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2780 hldev->config.rth_en ? "enabled" : "disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002781
2782 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002783 vpath = &vdev->vpaths[i];
2784
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002785 /* set initial mtu before enabling the device */
Jon Mason7adf7d12010-07-15 08:47:24 +00002786 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002787 if (status != VXGE_HW_OK) {
2788 vxge_debug_init(VXGE_ERR,
2789 "%s: fatal: can not set new MTU", dev->name);
2790 ret = -EPERM;
2791 goto out2;
2792 }
2793 }
2794
2795 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2796 vxge_debug_init(vdev->level_trace,
2797 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2798 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2799
Jon Mason7adf7d12010-07-15 08:47:24 +00002800 /* Restore the DA, VID table and also multicast and promiscuous mode
2801 * states
2802 */
2803 if (vdev->all_multi_flg) {
2804 for (i = 0; i < vdev->no_of_vpath; i++) {
2805 vpath = &vdev->vpaths[i];
2806 vxge_restore_vpath_mac_addr(vpath);
2807 vxge_restore_vpath_vid_table(vpath);
2808
2809 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2810 if (status != VXGE_HW_OK)
2811 vxge_debug_init(VXGE_ERR,
2812 "%s:%d Enabling multicast failed",
2813 __func__, __LINE__);
2814 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002815 }
2816
2817 /* Enable vpath to sniff all unicast/multicast traffic that not
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002818 * addressed to them. We allow promiscuous mode for PF only
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002819 */
2820
2821 val64 = 0;
2822 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2823 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
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_addr),
2830 val64);
2831
2832 vxge_hw_mgmt_reg_write(vdev->devh,
2833 vxge_hw_mgmt_reg_type_mrpcim,
2834 0,
2835 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2836 rxmac_authorize_all_vid),
2837 val64);
2838
2839 vxge_set_multicast(dev);
2840
2841 /* Enabling Bcast and mcast for all vpath */
2842 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002843 vpath = &vdev->vpaths[i];
2844 status = vxge_hw_vpath_bcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002845 if (status != VXGE_HW_OK)
2846 vxge_debug_init(VXGE_ERR,
2847 "%s : Can not enable bcast for vpath "
2848 "id %d", dev->name, i);
2849 if (vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002850 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002851 if (status != VXGE_HW_OK)
2852 vxge_debug_init(VXGE_ERR,
2853 "%s : Can not enable mcast for vpath "
2854 "id %d", dev->name, i);
2855 }
2856 }
2857
2858 vxge_hw_device_setpause_data(vdev->devh, 0,
2859 vdev->config.tx_pause_enable,
2860 vdev->config.rx_pause_enable);
2861
2862 if (vdev->vp_reset_timer.function == NULL)
2863 vxge_os_timer(vdev->vp_reset_timer,
2864 vxge_poll_vp_reset, vdev, (HZ/2));
2865
Jon Masone7935c92010-11-11 04:26:00 +00002866 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2867 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
2868 vxge_os_timer(vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
2869 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002870
2871 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2872
2873 smp_wmb();
2874
2875 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2876 netif_carrier_on(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00002877 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002878 vdev->stats.link_up++;
2879 }
2880
2881 vxge_hw_device_intr_enable(vdev->devh);
2882
2883 smp_wmb();
2884
2885 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002886 vpath = &vdev->vpaths[i];
2887
2888 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002889 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00002890 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002891 }
2892
Jon Masond03848e2010-07-15 08:47:23 +00002893 netif_tx_start_all_queues(vdev->ndev);
Jon Mason16fded72011-01-18 15:02:21 +00002894
2895 /* configure CI */
2896 vxge_config_ci_for_tti_rti(vdev);
2897
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002898 goto out0;
2899
2900out2:
2901 vxge_rem_isr(vdev);
2902
2903 /* Disable napi */
2904 if (vdev->config.intr_type != MSI_X)
2905 napi_disable(&vdev->napi);
2906 else {
2907 for (i = 0; i < vdev->no_of_vpath; i++)
2908 napi_disable(&vdev->vpaths[i].ring.napi);
2909 }
2910
2911out1:
2912 vxge_close_vpaths(vdev, 0);
2913out0:
2914 vxge_debug_entryexit(VXGE_TRACE,
2915 "%s: %s:%d Exiting...",
2916 dev->name, __func__, __LINE__);
2917 return ret;
2918}
2919
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002920/* Loop through the mac address list and delete all the entries */
stephen hemminger42821a52010-10-21 07:50:53 +00002921static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002922{
2923
2924 struct list_head *entry, *next;
2925 if (list_empty(&vpath->mac_addr_list))
2926 return;
2927
2928 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2929 list_del(entry);
2930 kfree((struct vxge_mac_addrs *)entry);
2931 }
2932}
2933
2934static void vxge_napi_del_all(struct vxgedev *vdev)
2935{
2936 int i;
2937 if (vdev->config.intr_type != MSI_X)
2938 netif_napi_del(&vdev->napi);
2939 else {
2940 for (i = 0; i < vdev->no_of_vpath; i++)
2941 netif_napi_del(&vdev->vpaths[i].ring.napi);
2942 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002943}
2944
stephen hemminger42821a52010-10-21 07:50:53 +00002945static int do_vxge_close(struct net_device *dev, int do_io)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002946{
2947 enum vxge_hw_status status;
2948 struct vxgedev *vdev;
2949 struct __vxge_hw_device *hldev;
2950 int i;
2951 u64 val64, vpath_vector;
2952 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2953 dev->name, __func__, __LINE__);
2954
Joe Perches5f54ceb2010-11-15 11:12:30 +00002955 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002956 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002957
Sreenivasa Honnurbd9ee682009-07-01 21:14:03 +00002958 if (unlikely(!is_vxge_card_up(vdev)))
2959 return 0;
2960
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002961 /* If vxge_handle_crit_err task is executing,
2962 * wait till it completes. */
2963 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2964 msleep(50);
2965
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002966 if (do_io) {
2967 /* Put the vpath back in normal mode */
2968 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2969 status = vxge_hw_mgmt_reg_read(vdev->devh,
2970 vxge_hw_mgmt_reg_type_mrpcim,
2971 0,
2972 (ulong)offsetof(
2973 struct vxge_hw_mrpcim_reg,
2974 rts_mgr_cbasin_cfg),
2975 &val64);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002976 if (status == VXGE_HW_OK) {
2977 val64 &= ~vpath_vector;
2978 status = vxge_hw_mgmt_reg_write(vdev->devh,
2979 vxge_hw_mgmt_reg_type_mrpcim,
2980 0,
2981 (ulong)offsetof(
2982 struct vxge_hw_mrpcim_reg,
2983 rts_mgr_cbasin_cfg),
2984 val64);
2985 }
2986
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002987 /* Remove the function 0 from promiscuous mode */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002988 vxge_hw_mgmt_reg_write(vdev->devh,
2989 vxge_hw_mgmt_reg_type_mrpcim,
2990 0,
2991 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2992 rxmac_authorize_all_addr),
2993 0);
2994
2995 vxge_hw_mgmt_reg_write(vdev->devh,
2996 vxge_hw_mgmt_reg_type_mrpcim,
2997 0,
2998 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2999 rxmac_authorize_all_vid),
3000 0);
3001
3002 smp_wmb();
3003 }
Jon Masone7935c92010-11-11 04:26:00 +00003004
3005 if (vdev->titan1)
3006 del_timer_sync(&vdev->vp_lockup_timer);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003007
3008 del_timer_sync(&vdev->vp_reset_timer);
3009
Jon Mason4d2a5b42010-11-11 04:25:54 +00003010 if (do_io)
3011 vxge_hw_device_wait_receive_idle(hldev);
3012
3013 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3014
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003015 /* Disable napi */
3016 if (vdev->config.intr_type != MSI_X)
3017 napi_disable(&vdev->napi);
3018 else {
3019 for (i = 0; i < vdev->no_of_vpath; i++)
3020 napi_disable(&vdev->vpaths[i].ring.napi);
3021 }
3022
3023 netif_carrier_off(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00003024 netdev_notice(vdev->ndev, "Link Down\n");
Jon Masond03848e2010-07-15 08:47:23 +00003025 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003026
3027 /* Note that at this point xmit() is stopped by upper layer */
3028 if (do_io)
3029 vxge_hw_device_intr_disable(vdev->devh);
3030
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003031 vxge_rem_isr(vdev);
3032
3033 vxge_napi_del_all(vdev);
3034
3035 if (do_io)
3036 vxge_reset_all_vpaths(vdev);
3037
3038 vxge_close_vpaths(vdev, 0);
3039
3040 vxge_debug_entryexit(VXGE_TRACE,
3041 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3042
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003043 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3044
3045 return 0;
3046}
3047
3048/**
3049 * vxge_close
3050 * @dev: device pointer.
3051 *
3052 * This is the stop entry point of the driver. It needs to undo exactly
3053 * whatever was done by the open entry point, thus it's usually referred to
3054 * as the close function.Among other things this function mainly stops the
3055 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3056 * Return value: '0' on success and an appropriate (-)ve integer as
3057 * defined in errno.h file on failure.
3058 */
Jon Mason528f7272010-12-10 14:02:56 +00003059static int vxge_close(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003060{
3061 do_vxge_close(dev, 1);
3062 return 0;
3063}
3064
3065/**
3066 * vxge_change_mtu
3067 * @dev: net device pointer.
3068 * @new_mtu :the new MTU size for the device.
3069 *
3070 * A driver entry point to change MTU size for the device. Before changing
3071 * the MTU the device must be stopped.
3072 */
3073static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3074{
3075 struct vxgedev *vdev = netdev_priv(dev);
3076
3077 vxge_debug_entryexit(vdev->level_trace,
3078 "%s:%d", __func__, __LINE__);
3079 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3080 vxge_debug_init(vdev->level_err,
3081 "%s: mtu size is invalid", dev->name);
3082 return -EPERM;
3083 }
3084
3085 /* check if device is down already */
3086 if (unlikely(!is_vxge_card_up(vdev))) {
3087 /* just store new value, will use later on open() */
3088 dev->mtu = new_mtu;
3089 vxge_debug_init(vdev->level_err,
3090 "%s", "device is down on MTU change");
3091 return 0;
3092 }
3093
3094 vxge_debug_init(vdev->level_trace,
3095 "trying to apply new MTU %d", new_mtu);
3096
3097 if (vxge_close(dev))
3098 return -EIO;
3099
3100 dev->mtu = new_mtu;
3101 vdev->mtu = new_mtu;
3102
3103 if (vxge_open(dev))
3104 return -EIO;
3105
3106 vxge_debug_init(vdev->level_trace,
3107 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3108
3109 vxge_debug_entryexit(vdev->level_trace,
3110 "%s:%d Exiting...", __func__, __LINE__);
3111
3112 return 0;
3113}
3114
3115/**
Eric Dumazetdd57f972010-08-18 03:42:54 +00003116 * vxge_get_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003117 * @dev: pointer to the device structure
Eric Dumazetdd57f972010-08-18 03:42:54 +00003118 * @stats: pointer to struct rtnl_link_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003119 *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003120 */
Eric Dumazetdd57f972010-08-18 03:42:54 +00003121static struct rtnl_link_stats64 *
3122vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003123{
Eric Dumazetdd57f972010-08-18 03:42:54 +00003124 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003125 int k;
3126
Eric Dumazetdd57f972010-08-18 03:42:54 +00003127 /* net_stats already zeroed by caller */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003128 for (k = 0; k < vdev->no_of_vpath; k++) {
stephen hemminger62ea0552011-06-20 10:35:07 +00003129 struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
3130 struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
3131 unsigned int start;
3132 u64 packets, bytes, multicast;
3133
3134 do {
3135 start = u64_stats_fetch_begin(&rxstats->syncp);
3136
3137 packets = rxstats->rx_frms;
3138 multicast = rxstats->rx_mcast;
3139 bytes = rxstats->rx_bytes;
3140 } while (u64_stats_fetch_retry(&rxstats->syncp, start));
3141
3142 net_stats->rx_packets += packets;
3143 net_stats->rx_bytes += bytes;
3144 net_stats->multicast += multicast;
3145
3146 net_stats->rx_errors += rxstats->rx_errors;
3147 net_stats->rx_dropped += rxstats->rx_dropped;
3148
3149 do {
3150 start = u64_stats_fetch_begin(&txstats->syncp);
3151
3152 packets = txstats->tx_frms;
3153 bytes = txstats->tx_bytes;
3154 } while (u64_stats_fetch_retry(&txstats->syncp, start));
3155
3156 net_stats->tx_packets += packets;
3157 net_stats->tx_bytes += bytes;
3158 net_stats->tx_errors += txstats->tx_errors;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003159 }
3160
3161 return net_stats;
3162}
3163
Jon Masoncd883a72011-04-08 11:11:21 +00003164static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
Jon Masonb81b3732010-11-11 04:25:58 +00003165{
3166 enum vxge_hw_status status;
3167 u64 val64;
3168
3169 /* Timestamp is passed to the driver via the FCS, therefore we
3170 * must disable the FCS stripping by the adapter. Since this is
3171 * required for the driver to load (due to a hardware bug),
3172 * there is no need to do anything special here.
3173 */
Jon Masoncd883a72011-04-08 11:11:21 +00003174 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3175 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3176 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
Jon Masonb81b3732010-11-11 04:25:58 +00003177
Jon Masoncd883a72011-04-08 11:11:21 +00003178 status = vxge_hw_mgmt_reg_write(devh,
Jon Masonb81b3732010-11-11 04:25:58 +00003179 vxge_hw_mgmt_reg_type_mrpcim,
3180 0,
3181 offsetof(struct vxge_hw_mrpcim_reg,
3182 xmac_timestamp),
3183 val64);
Jon Masoncd883a72011-04-08 11:11:21 +00003184 vxge_hw_device_flush_io(devh);
3185 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
Jon Masonb81b3732010-11-11 04:25:58 +00003186 return status;
3187}
3188
3189static int vxge_hwtstamp_ioctl(struct vxgedev *vdev, void __user *data)
3190{
3191 struct hwtstamp_config config;
Jon Masonb81b3732010-11-11 04:25:58 +00003192 int i;
3193
3194 if (copy_from_user(&config, data, sizeof(config)))
3195 return -EFAULT;
3196
3197 /* reserved for future extensions */
3198 if (config.flags)
3199 return -EINVAL;
3200
3201 /* Transmit HW Timestamp not supported */
3202 switch (config.tx_type) {
3203 case HWTSTAMP_TX_OFF:
3204 break;
3205 case HWTSTAMP_TX_ON:
3206 default:
3207 return -ERANGE;
3208 }
3209
3210 switch (config.rx_filter) {
3211 case HWTSTAMP_FILTER_NONE:
Jon Masonb81b3732010-11-11 04:25:58 +00003212 vdev->rx_hwts = 0;
3213 config.rx_filter = HWTSTAMP_FILTER_NONE;
3214 break;
3215
3216 case HWTSTAMP_FILTER_ALL:
3217 case HWTSTAMP_FILTER_SOME:
3218 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3219 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3220 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3221 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3222 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3223 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3224 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3225 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3226 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3227 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3228 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3229 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Jon Masoncd883a72011-04-08 11:11:21 +00003230 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
Jon Masonb81b3732010-11-11 04:25:58 +00003231 return -EFAULT;
3232
3233 vdev->rx_hwts = 1;
3234 config.rx_filter = HWTSTAMP_FILTER_ALL;
3235 break;
3236
3237 default:
3238 return -ERANGE;
3239 }
3240
3241 for (i = 0; i < vdev->no_of_vpath; i++)
3242 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3243
3244 if (copy_to_user(data, &config, sizeof(config)))
3245 return -EFAULT;
3246
3247 return 0;
3248}
3249
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003250/**
3251 * vxge_ioctl
3252 * @dev: Device pointer.
3253 * @ifr: An IOCTL specific structure, that can contain a pointer to
3254 * a proprietary structure used to pass information to the driver.
3255 * @cmd: This is used to distinguish between the different commands that
3256 * can be passed to the IOCTL functions.
3257 *
3258 * Entry point for the Ioctl.
3259 */
3260static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3261{
Jon Masonb81b3732010-11-11 04:25:58 +00003262 struct vxgedev *vdev = netdev_priv(dev);
3263 int ret;
3264
3265 switch (cmd) {
3266 case SIOCSHWTSTAMP:
3267 ret = vxge_hwtstamp_ioctl(vdev, rq->ifr_data);
3268 if (ret)
3269 return ret;
3270 break;
3271 default:
3272 return -EOPNOTSUPP;
3273 }
3274
3275 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003276}
3277
3278/**
3279 * vxge_tx_watchdog
3280 * @dev: pointer to net device structure
3281 *
3282 * Watchdog for transmit side.
3283 * This function is triggered if the Tx Queue is stopped
3284 * for a pre-defined amount of time when the Interface is still up.
3285 */
Jon Mason2e41f642010-12-10 14:02:59 +00003286static void vxge_tx_watchdog(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003287{
3288 struct vxgedev *vdev;
3289
3290 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3291
Joe Perches5f54ceb2010-11-15 11:12:30 +00003292 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003293
3294 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3295
Jon Mason2e41f642010-12-10 14:02:59 +00003296 schedule_work(&vdev->reset_task);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003297 vxge_debug_entryexit(VXGE_TRACE,
3298 "%s:%d Exiting...", __func__, __LINE__);
3299}
3300
3301/**
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003302 * vxge_vlan_rx_add_vid
3303 * @dev: net device pointer.
3304 * @vid: vid
3305 *
3306 * Add the vlan id to the devices vlan id table
3307 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003308static int
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003309vxge_vlan_rx_add_vid(struct net_device *dev, unsigned short vid)
3310{
Jiri Pirko53515732011-07-20 04:54:40 +00003311 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003312 struct vxge_vpath *vpath;
3313 int vp_id;
3314
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003315 /* Add these vlan to the vid table */
3316 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3317 vpath = &vdev->vpaths[vp_id];
3318 if (!vpath->is_open)
3319 continue;
3320 vxge_hw_vpath_vid_add(vpath->handle, vid);
3321 }
Jiri Pirko53515732011-07-20 04:54:40 +00003322 set_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003323 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003324}
3325
3326/**
3327 * vxge_vlan_rx_add_vid
3328 * @dev: net device pointer.
3329 * @vid: vid
3330 *
3331 * Remove the vlan id from the device's vlan id table
3332 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003333static int
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003334vxge_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
3335{
Jiri Pirko53515732011-07-20 04:54:40 +00003336 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003337 struct vxge_vpath *vpath;
3338 int vp_id;
3339
3340 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3341
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003342 /* Delete this vlan from the vid table */
3343 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3344 vpath = &vdev->vpaths[vp_id];
3345 if (!vpath->is_open)
3346 continue;
3347 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3348 }
3349 vxge_debug_entryexit(VXGE_TRACE,
3350 "%s:%d Exiting...", __func__, __LINE__);
Jiri Pirko53515732011-07-20 04:54:40 +00003351 clear_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003352 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003353}
3354
3355static const struct net_device_ops vxge_netdev_ops = {
3356 .ndo_open = vxge_open,
3357 .ndo_stop = vxge_close,
Eric Dumazetdd57f972010-08-18 03:42:54 +00003358 .ndo_get_stats64 = vxge_get_stats64,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003359 .ndo_start_xmit = vxge_xmit,
3360 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003361 .ndo_set_rx_mode = vxge_set_multicast,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003362 .ndo_do_ioctl = vxge_ioctl,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003363 .ndo_set_mac_address = vxge_set_mac_addr,
3364 .ndo_change_mtu = vxge_change_mtu,
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003365 .ndo_fix_features = vxge_fix_features,
3366 .ndo_set_features = vxge_set_features,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003367 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3368 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003369 .ndo_tx_timeout = vxge_tx_watchdog,
3370#ifdef CONFIG_NET_POLL_CONTROLLER
3371 .ndo_poll_controller = vxge_netpoll,
3372#endif
3373};
3374
stephen hemminger42821a52010-10-21 07:50:53 +00003375static int __devinit vxge_device_register(struct __vxge_hw_device *hldev,
3376 struct vxge_config *config,
3377 int high_dma, int no_of_vpath,
3378 struct vxgedev **vdev_out)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003379{
3380 struct net_device *ndev;
3381 enum vxge_hw_status status = VXGE_HW_OK;
3382 struct vxgedev *vdev;
Jon Mason98f45da2010-07-15 08:47:25 +00003383 int ret = 0, no_of_queue = 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003384 u64 stat;
3385
3386 *vdev_out = NULL;
Jon Masond03848e2010-07-15 08:47:23 +00003387 if (config->tx_steering_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003388 no_of_queue = no_of_vpath;
3389
3390 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3391 no_of_queue);
3392 if (ndev == NULL) {
3393 vxge_debug_init(
3394 vxge_hw_device_trace_level_get(hldev),
3395 "%s : device allocation failed", __func__);
3396 ret = -ENODEV;
3397 goto _out0;
3398 }
3399
3400 vxge_debug_entryexit(
3401 vxge_hw_device_trace_level_get(hldev),
3402 "%s: %s:%d Entering...",
3403 ndev->name, __func__, __LINE__);
3404
3405 vdev = netdev_priv(ndev);
3406 memset(vdev, 0, sizeof(struct vxgedev));
3407
3408 vdev->ndev = ndev;
3409 vdev->devh = hldev;
3410 vdev->pdev = hldev->pdev;
3411 memcpy(&vdev->config, config, sizeof(struct vxge_config));
Jon Masonb81b3732010-11-11 04:25:58 +00003412 vdev->rx_hwts = 0;
Sergei Shtylyovff938e42011-02-28 11:57:33 -08003413 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
Jon Masone7935c92010-11-11 04:26:00 +00003414
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003415 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3416
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003417 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3418 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3419 NETIF_F_TSO | NETIF_F_TSO6 |
3420 NETIF_F_HW_VLAN_TX;
3421 if (vdev->config.rth_steering != NO_STEERING)
3422 ndev->hw_features |= NETIF_F_RXHASH;
3423
3424 ndev->features |= ndev->hw_features |
3425 NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER;
3426
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003427 /* Driver entry points */
3428 ndev->irq = vdev->pdev->irq;
3429 ndev->base_addr = (unsigned long) hldev->bar0;
3430
3431 ndev->netdev_ops = &vxge_netdev_ops;
3432
3433 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
Jon Mason2e41f642010-12-10 14:02:59 +00003434 INIT_WORK(&vdev->reset_task, vxge_reset);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003435
stephen hemminger42821a52010-10-21 07:50:53 +00003436 vxge_initialize_ethtool_ops(ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003437
3438 /* Allocate memory for vpath */
3439 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3440 no_of_vpath, GFP_KERNEL);
3441 if (!vdev->vpaths) {
3442 vxge_debug_init(VXGE_ERR,
3443 "%s: vpath memory allocation failed",
3444 vdev->ndev->name);
Jon Mason6cca2002011-01-18 15:02:19 +00003445 ret = -ENOMEM;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003446 goto _out1;
3447 }
3448
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003449 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3450 "%s : checksuming enabled", __func__);
3451
3452 if (high_dma) {
3453 ndev->features |= NETIF_F_HIGHDMA;
3454 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3455 "%s : using High DMA", __func__);
3456 }
3457
Jon Mason6cca2002011-01-18 15:02:19 +00003458 ret = register_netdev(ndev);
3459 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003460 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3461 "%s: %s : device registration failed!",
3462 ndev->name, __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003463 goto _out2;
3464 }
3465
3466 /* Set the factory defined MAC address initially */
3467 ndev->addr_len = ETH_ALEN;
3468
3469 /* Make Link state as off at this point, when the Link change
3470 * interrupt comes the state will be automatically changed to
3471 * the right state.
3472 */
3473 netif_carrier_off(ndev);
3474
3475 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3476 "%s: Ethernet device registered",
3477 ndev->name);
3478
Jon Masone8ac1752010-11-11 04:25:57 +00003479 hldev->ndev = ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003480 *vdev_out = vdev;
3481
3482 /* Resetting the Device stats */
3483 status = vxge_hw_mrpcim_stats_access(
3484 hldev,
3485 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3486 0,
3487 0,
3488 &stat);
3489
3490 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3491 vxge_debug_init(
3492 vxge_hw_device_trace_level_get(hldev),
3493 "%s: device stats clear returns"
3494 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3495
3496 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3497 "%s: %s:%d Exiting...",
3498 ndev->name, __func__, __LINE__);
3499
3500 return ret;
3501_out2:
3502 kfree(vdev->vpaths);
3503_out1:
3504 free_netdev(ndev);
3505_out0:
3506 return ret;
3507}
3508
3509/*
3510 * vxge_device_unregister
3511 *
3512 * This function will unregister and free network device
3513 */
Jon Mason2c913082010-11-11 04:26:03 +00003514static void vxge_device_unregister(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003515{
3516 struct vxgedev *vdev;
3517 struct net_device *dev;
3518 char buf[IFNAMSIZ];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003519
3520 dev = hldev->ndev;
3521 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003522
Jon Mason2c913082010-11-11 04:26:03 +00003523 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3524 __func__, __LINE__);
3525
Jon Masonead5d232010-11-29 18:02:46 +00003526 strncpy(buf, dev->name, IFNAMSIZ);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003527
Tejun Heoba27d852010-12-15 04:03:29 +00003528 flush_work_sync(&vdev->reset_task);
3529
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003530 /* in 2.6 will call stop() if device is up */
3531 unregister_netdev(dev);
3532
Jon Mason6cca2002011-01-18 15:02:19 +00003533 kfree(vdev->vpaths);
3534
3535 /* we are safe to free it now */
3536 free_netdev(dev);
3537
Jon Mason2c913082010-11-11 04:26:03 +00003538 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3539 buf);
3540 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3541 __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003542}
3543
3544/*
3545 * vxge_callback_crit_err
3546 *
3547 * This function is called by the alarm handler in interrupt context.
3548 * Driver must analyze it based on the event type.
3549 */
3550static void
3551vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3552 enum vxge_hw_event type, u64 vp_id)
3553{
3554 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +00003555 struct vxgedev *vdev = netdev_priv(dev);
Jon Mason98f45da2010-07-15 08:47:25 +00003556 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003557 int vpath_idx;
3558
3559 vxge_debug_entryexit(vdev->level_trace,
3560 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3561
3562 /* Note: This event type should be used for device wide
3563 * indications only - Serious errors, Slot freeze and critical errors
3564 */
3565 vdev->cric_err_event = type;
3566
Jon Mason98f45da2010-07-15 08:47:25 +00003567 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3568 vpath = &vdev->vpaths[vpath_idx];
3569 if (vpath->device_id == vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003570 break;
Jon Mason98f45da2010-07-15 08:47:25 +00003571 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003572
3573 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3574 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3575 vxge_debug_init(VXGE_ERR,
3576 "%s: Slot is frozen", vdev->ndev->name);
3577 } else if (type == VXGE_HW_EVENT_SERR) {
3578 vxge_debug_init(VXGE_ERR,
3579 "%s: Encountered Serious Error",
3580 vdev->ndev->name);
3581 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3582 vxge_debug_init(VXGE_ERR,
3583 "%s: Encountered Critical Error",
3584 vdev->ndev->name);
3585 }
3586
3587 if ((type == VXGE_HW_EVENT_SERR) ||
3588 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3589 if (unlikely(vdev->exec_mode))
3590 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3591 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3592 vxge_hw_device_mask_all(hldev);
3593 if (unlikely(vdev->exec_mode))
3594 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3595 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3596 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3597
3598 if (unlikely(vdev->exec_mode))
3599 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3600 else {
3601 /* check if this vpath is already set for reset */
3602 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3603
3604 /* disable interrupts for this vpath */
3605 vxge_vpath_intr_disable(vdev, vpath_idx);
3606
3607 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00003608 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003609 }
3610 }
3611 }
3612
3613 vxge_debug_entryexit(vdev->level_trace,
3614 "%s: %s:%d Exiting...",
3615 vdev->ndev->name, __func__, __LINE__);
3616}
3617
3618static void verify_bandwidth(void)
3619{
3620 int i, band_width, total = 0, equal_priority = 0;
3621
3622 /* 1. If user enters 0 for some fifo, give equal priority to all */
3623 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3624 if (bw_percentage[i] == 0) {
3625 equal_priority = 1;
3626 break;
3627 }
3628 }
3629
3630 if (!equal_priority) {
3631 /* 2. If sum exceeds 100, give equal priority to all */
3632 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3633 if (bw_percentage[i] == 0xFF)
3634 break;
3635
3636 total += bw_percentage[i];
3637 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3638 equal_priority = 1;
3639 break;
3640 }
3641 }
3642 }
3643
3644 if (!equal_priority) {
3645 /* Is all the bandwidth consumed? */
3646 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3647 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3648 /* Split rest of bw equally among next VPs*/
3649 band_width =
3650 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3651 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3652 if (band_width < 2) /* min of 2% */
3653 equal_priority = 1;
3654 else {
3655 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3656 i++)
3657 bw_percentage[i] =
3658 band_width;
3659 }
3660 }
3661 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3662 equal_priority = 1;
3663 }
3664
3665 if (equal_priority) {
3666 vxge_debug_init(VXGE_ERR,
3667 "%s: Assigning equal bandwidth to all the vpaths",
3668 VXGE_DRIVER_NAME);
3669 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3670 VXGE_HW_MAX_VIRTUAL_PATHS;
3671 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3672 bw_percentage[i] = bw_percentage[0];
3673 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003674}
3675
3676/*
3677 * Vpath configuration
3678 */
3679static int __devinit vxge_config_vpaths(
3680 struct vxge_hw_device_config *device_config,
3681 u64 vpath_mask, struct vxge_config *config_param)
3682{
3683 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3684 u32 txdl_size, txdl_per_memblock;
3685
3686 temp = driver_config->vpath_per_dev;
3687 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3688 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3689 /* No more CPU. Return vpath number as zero.*/
3690 if (driver_config->g_no_cpus == -1)
3691 return 0;
3692
3693 if (!driver_config->g_no_cpus)
3694 driver_config->g_no_cpus = num_online_cpus();
3695
3696 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3697 if (!driver_config->vpath_per_dev)
3698 driver_config->vpath_per_dev = 1;
3699
3700 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3701 if (!vxge_bVALn(vpath_mask, i, 1))
3702 continue;
3703 else
3704 default_no_vpath++;
3705 if (default_no_vpath < driver_config->vpath_per_dev)
3706 driver_config->vpath_per_dev = default_no_vpath;
3707
3708 driver_config->g_no_cpus = driver_config->g_no_cpus -
3709 (driver_config->vpath_per_dev * 2);
3710 if (driver_config->g_no_cpus <= 0)
3711 driver_config->g_no_cpus = -1;
3712 }
3713
3714 if (driver_config->vpath_per_dev == 1) {
3715 vxge_debug_ll_config(VXGE_TRACE,
3716 "%s: Disable tx and rx steering, "
3717 "as single vpath is configured", VXGE_DRIVER_NAME);
3718 config_param->rth_steering = NO_STEERING;
3719 config_param->tx_steering_type = NO_STEERING;
3720 device_config->rth_en = 0;
3721 }
3722
3723 /* configure bandwidth */
3724 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3725 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3726
3727 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3728 device_config->vp_config[i].vp_id = i;
3729 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3730 if (no_of_vpaths < driver_config->vpath_per_dev) {
3731 if (!vxge_bVALn(vpath_mask, i, 1)) {
3732 vxge_debug_ll_config(VXGE_TRACE,
3733 "%s: vpath: %d is not available",
3734 VXGE_DRIVER_NAME, i);
3735 continue;
3736 } else {
3737 vxge_debug_ll_config(VXGE_TRACE,
3738 "%s: vpath: %d available",
3739 VXGE_DRIVER_NAME, i);
3740 no_of_vpaths++;
3741 }
3742 } else {
3743 vxge_debug_ll_config(VXGE_TRACE,
3744 "%s: vpath: %d is not configured, "
3745 "max_config_vpath exceeded",
3746 VXGE_DRIVER_NAME, i);
3747 break;
3748 }
3749
3750 /* Configure Tx fifo's */
3751 device_config->vp_config[i].fifo.enable =
3752 VXGE_HW_FIFO_ENABLE;
3753 device_config->vp_config[i].fifo.max_frags =
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003754 MAX_SKB_FRAGS + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003755 device_config->vp_config[i].fifo.memblock_size =
3756 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3757
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003758 txdl_size = device_config->vp_config[i].fifo.max_frags *
3759 sizeof(struct vxge_hw_fifo_txd);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003760 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3761
3762 device_config->vp_config[i].fifo.fifo_blocks =
3763 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3764
3765 device_config->vp_config[i].fifo.intr =
3766 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3767
3768 /* Configure tti properties */
3769 device_config->vp_config[i].tti.intr_enable =
3770 VXGE_HW_TIM_INTR_ENABLE;
3771
3772 device_config->vp_config[i].tti.btimer_val =
3773 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3774
3775 device_config->vp_config[i].tti.timer_ac_en =
3776 VXGE_HW_TIM_TIMER_AC_ENABLE;
3777
Jon Mason528f7272010-12-10 14:02:56 +00003778 /* For msi-x with napi (each vector has a handler of its own) -
3779 * Set CI to OFF for all vpaths
3780 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003781 device_config->vp_config[i].tti.timer_ci_en =
3782 VXGE_HW_TIM_TIMER_CI_DISABLE;
3783
3784 device_config->vp_config[i].tti.timer_ri_en =
3785 VXGE_HW_TIM_TIMER_RI_DISABLE;
3786
3787 device_config->vp_config[i].tti.util_sel =
3788 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3789
3790 device_config->vp_config[i].tti.ltimer_val =
3791 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3792
3793 device_config->vp_config[i].tti.rtimer_val =
3794 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3795
3796 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3797 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3798 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3799 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3800 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3801 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3802 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3803
3804 /* Configure Rx rings */
3805 device_config->vp_config[i].ring.enable =
3806 VXGE_HW_RING_ENABLE;
3807
3808 device_config->vp_config[i].ring.ring_blocks =
3809 VXGE_HW_DEF_RING_BLOCKS;
Jon Mason528f7272010-12-10 14:02:56 +00003810
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003811 device_config->vp_config[i].ring.buffer_mode =
3812 VXGE_HW_RING_RXD_BUFFER_MODE_1;
Jon Mason528f7272010-12-10 14:02:56 +00003813
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003814 device_config->vp_config[i].ring.rxds_limit =
3815 VXGE_HW_DEF_RING_RXDS_LIMIT;
Jon Mason528f7272010-12-10 14:02:56 +00003816
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003817 device_config->vp_config[i].ring.scatter_mode =
3818 VXGE_HW_RING_SCATTER_MODE_A;
3819
3820 /* Configure rti properties */
3821 device_config->vp_config[i].rti.intr_enable =
3822 VXGE_HW_TIM_INTR_ENABLE;
3823
3824 device_config->vp_config[i].rti.btimer_val =
3825 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3826
3827 device_config->vp_config[i].rti.timer_ac_en =
3828 VXGE_HW_TIM_TIMER_AC_ENABLE;
3829
3830 device_config->vp_config[i].rti.timer_ci_en =
3831 VXGE_HW_TIM_TIMER_CI_DISABLE;
3832
3833 device_config->vp_config[i].rti.timer_ri_en =
3834 VXGE_HW_TIM_TIMER_RI_DISABLE;
3835
3836 device_config->vp_config[i].rti.util_sel =
3837 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3838
3839 device_config->vp_config[i].rti.urange_a =
3840 RTI_RX_URANGE_A;
3841 device_config->vp_config[i].rti.urange_b =
3842 RTI_RX_URANGE_B;
3843 device_config->vp_config[i].rti.urange_c =
3844 RTI_RX_URANGE_C;
3845 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3846 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3847 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3848 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3849
3850 device_config->vp_config[i].rti.rtimer_val =
3851 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3852
3853 device_config->vp_config[i].rti.ltimer_val =
3854 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3855
3856 device_config->vp_config[i].rpa_strip_vlan_tag =
3857 vlan_tag_strip;
3858 }
3859
3860 driver_config->vpath_per_dev = temp;
3861 return no_of_vpaths;
3862}
3863
3864/* initialize device configuratrions */
3865static void __devinit vxge_device_config_init(
3866 struct vxge_hw_device_config *device_config,
3867 int *intr_type)
3868{
3869 /* Used for CQRQ/SRQ. */
3870 device_config->dma_blockpool_initial =
3871 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3872
3873 device_config->dma_blockpool_max =
3874 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3875
3876 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3877 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3878
3879#ifndef CONFIG_PCI_MSI
3880 vxge_debug_init(VXGE_ERR,
3881 "%s: This Kernel does not support "
3882 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3883 *intr_type = INTA;
3884#endif
3885
3886 /* Configure whether MSI-X or IRQL. */
3887 switch (*intr_type) {
3888 case INTA:
3889 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3890 break;
3891
3892 case MSI_X:
Jon Mason16fded72011-01-18 15:02:21 +00003893 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003894 break;
3895 }
Jon Mason528f7272010-12-10 14:02:56 +00003896
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003897 /* Timer period between device poll */
3898 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3899
3900 /* Configure mac based steering. */
3901 device_config->rts_mac_en = addr_learn_en;
3902
3903 /* Configure Vpaths */
3904 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3905
3906 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3907 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003908 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3909 device_config->intr_mode);
3910 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3911 device_config->device_poll_millis);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003912 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3913 device_config->rth_en);
3914 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3915 device_config->rth_it_type);
3916}
3917
3918static void __devinit vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
3919{
3920 int i;
3921
3922 vxge_debug_init(VXGE_TRACE,
3923 "%s: %d Vpath(s) opened",
3924 vdev->ndev->name, vdev->no_of_vpath);
3925
3926 switch (vdev->config.intr_type) {
3927 case INTA:
3928 vxge_debug_init(VXGE_TRACE,
3929 "%s: Interrupt type INTA", vdev->ndev->name);
3930 break;
3931
3932 case MSI_X:
3933 vxge_debug_init(VXGE_TRACE,
3934 "%s: Interrupt type MSI-X", vdev->ndev->name);
3935 break;
3936 }
3937
3938 if (vdev->config.rth_steering) {
3939 vxge_debug_init(VXGE_TRACE,
3940 "%s: RTH steering enabled for TCP_IPV4",
3941 vdev->ndev->name);
3942 } else {
3943 vxge_debug_init(VXGE_TRACE,
3944 "%s: RTH steering disabled", vdev->ndev->name);
3945 }
3946
3947 switch (vdev->config.tx_steering_type) {
3948 case NO_STEERING:
3949 vxge_debug_init(VXGE_TRACE,
3950 "%s: Tx steering disabled", vdev->ndev->name);
3951 break;
3952 case TX_PRIORITY_STEERING:
3953 vxge_debug_init(VXGE_TRACE,
3954 "%s: Unsupported tx steering option",
3955 vdev->ndev->name);
3956 vxge_debug_init(VXGE_TRACE,
3957 "%s: Tx steering disabled", vdev->ndev->name);
3958 vdev->config.tx_steering_type = 0;
3959 break;
3960 case TX_VLAN_STEERING:
3961 vxge_debug_init(VXGE_TRACE,
3962 "%s: Unsupported tx steering option",
3963 vdev->ndev->name);
3964 vxge_debug_init(VXGE_TRACE,
3965 "%s: Tx steering disabled", vdev->ndev->name);
3966 vdev->config.tx_steering_type = 0;
3967 break;
3968 case TX_MULTIQ_STEERING:
3969 vxge_debug_init(VXGE_TRACE,
3970 "%s: Tx multiqueue steering enabled",
3971 vdev->ndev->name);
3972 break;
3973 case TX_PORT_STEERING:
3974 vxge_debug_init(VXGE_TRACE,
3975 "%s: Tx port steering enabled",
3976 vdev->ndev->name);
3977 break;
3978 default:
3979 vxge_debug_init(VXGE_ERR,
3980 "%s: Unsupported tx steering type",
3981 vdev->ndev->name);
3982 vxge_debug_init(VXGE_TRACE,
3983 "%s: Tx steering disabled", vdev->ndev->name);
3984 vdev->config.tx_steering_type = 0;
3985 }
3986
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003987 if (vdev->config.addr_learn_en)
3988 vxge_debug_init(VXGE_TRACE,
3989 "%s: MAC Address learning enabled", vdev->ndev->name);
3990
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003991 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3992 if (!vxge_bVALn(vpath_mask, i, 1))
3993 continue;
3994 vxge_debug_ll_config(VXGE_TRACE,
3995 "%s: MTU size - %d", vdev->ndev->name,
3996 ((struct __vxge_hw_device *)(vdev->devh))->
3997 config.vp_config[i].mtu);
3998 vxge_debug_init(VXGE_TRACE,
3999 "%s: VLAN tag stripping %s", vdev->ndev->name,
4000 ((struct __vxge_hw_device *)(vdev->devh))->
4001 config.vp_config[i].rpa_strip_vlan_tag
4002 ? "Enabled" : "Disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004003 vxge_debug_ll_config(VXGE_TRACE,
4004 "%s: Max frags : %d", vdev->ndev->name,
4005 ((struct __vxge_hw_device *)(vdev->devh))->
4006 config.vp_config[i].fifo.max_frags);
4007 break;
4008 }
4009}
4010
4011#ifdef CONFIG_PM
4012/**
4013 * vxge_pm_suspend - vxge power management suspend entry point
4014 *
4015 */
4016static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4017{
4018 return -ENOSYS;
4019}
4020/**
4021 * vxge_pm_resume - vxge power management resume entry point
4022 *
4023 */
4024static int vxge_pm_resume(struct pci_dev *pdev)
4025{
4026 return -ENOSYS;
4027}
4028
4029#endif
4030
4031/**
4032 * vxge_io_error_detected - called when PCI error is detected
4033 * @pdev: Pointer to PCI device
4034 * @state: The current pci connection state
4035 *
4036 * This function is called after a PCI bus error affecting
4037 * this device has been detected.
4038 */
4039static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4040 pci_channel_state_t state)
4041{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004042 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004043 struct net_device *netdev = hldev->ndev;
4044
4045 netif_device_detach(netdev);
4046
Dean Nelsone33b9922009-07-31 09:14:03 +00004047 if (state == pci_channel_io_perm_failure)
4048 return PCI_ERS_RESULT_DISCONNECT;
4049
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004050 if (netif_running(netdev)) {
4051 /* Bring down the card, while avoiding PCI I/O */
4052 do_vxge_close(netdev, 0);
4053 }
4054
4055 pci_disable_device(pdev);
4056
4057 return PCI_ERS_RESULT_NEED_RESET;
4058}
4059
4060/**
4061 * vxge_io_slot_reset - called after the pci bus has been reset.
4062 * @pdev: Pointer to PCI device
4063 *
4064 * Restart the card from scratch, as if from a cold-boot.
4065 * At this point, the card has exprienced a hard reset,
4066 * followed by fixups by BIOS, and has its config space
4067 * set up identically to what it was at cold boot.
4068 */
4069static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4070{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004071 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004072 struct net_device *netdev = hldev->ndev;
4073
4074 struct vxgedev *vdev = netdev_priv(netdev);
4075
4076 if (pci_enable_device(pdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004077 netdev_err(netdev, "Cannot re-enable device after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004078 return PCI_ERS_RESULT_DISCONNECT;
4079 }
4080
4081 pci_set_master(pdev);
Jon Mason528f7272010-12-10 14:02:56 +00004082 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004083
4084 return PCI_ERS_RESULT_RECOVERED;
4085}
4086
4087/**
4088 * vxge_io_resume - called when traffic can start flowing again.
4089 * @pdev: Pointer to PCI device
4090 *
4091 * This callback is called when the error recovery driver tells
4092 * us that its OK to resume normal operation.
4093 */
4094static void vxge_io_resume(struct pci_dev *pdev)
4095{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004096 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004097 struct net_device *netdev = hldev->ndev;
4098
4099 if (netif_running(netdev)) {
4100 if (vxge_open(netdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004101 netdev_err(netdev,
4102 "Can't bring device back up after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004103 return;
4104 }
4105 }
4106
4107 netif_device_attach(netdev);
4108}
4109
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004110static inline u32 vxge_get_num_vfs(u64 function_mode)
4111{
4112 u32 num_functions = 0;
4113
4114 switch (function_mode) {
4115 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4116 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4117 num_functions = 8;
4118 break;
4119 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4120 num_functions = 1;
4121 break;
4122 case VXGE_HW_FUNCTION_MODE_SRIOV:
4123 case VXGE_HW_FUNCTION_MODE_MRIOV:
4124 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4125 num_functions = 17;
4126 break;
4127 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4128 num_functions = 4;
4129 break;
4130 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4131 num_functions = 2;
4132 break;
4133 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4134 num_functions = 8; /* TODO */
4135 break;
4136 }
4137 return num_functions;
4138}
4139
Jon Masone8ac1752010-11-11 04:25:57 +00004140int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4141{
4142 struct __vxge_hw_device *hldev = vdev->devh;
4143 u32 maj, min, bld, cmaj, cmin, cbld;
4144 enum vxge_hw_status status;
4145 const struct firmware *fw;
4146 int ret;
4147
4148 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4149 if (ret) {
4150 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4151 VXGE_DRIVER_NAME, fw_name);
4152 goto out;
4153 }
4154
4155 /* Load the new firmware onto the adapter */
4156 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4157 if (status != VXGE_HW_OK) {
4158 vxge_debug_init(VXGE_ERR,
4159 "%s: FW image download to adapter failed '%s'.",
4160 VXGE_DRIVER_NAME, fw_name);
4161 ret = -EIO;
4162 goto out;
4163 }
4164
4165 /* Read the version of the new firmware */
4166 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4167 if (status != VXGE_HW_OK) {
4168 vxge_debug_init(VXGE_ERR,
4169 "%s: Upgrade read version failed '%s'.",
4170 VXGE_DRIVER_NAME, fw_name);
4171 ret = -EIO;
4172 goto out;
4173 }
4174
4175 cmaj = vdev->config.device_hw_info.fw_version.major;
4176 cmin = vdev->config.device_hw_info.fw_version.minor;
4177 cbld = vdev->config.device_hw_info.fw_version.build;
4178 /* It's possible the version in /lib/firmware is not the latest version.
4179 * If so, we could get into a loop of trying to upgrade to the latest
4180 * and flashing the older version.
4181 */
4182 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4183 !override) {
4184 ret = -EINVAL;
4185 goto out;
4186 }
4187
4188 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4189 maj, min, bld);
4190
4191 /* Flash the adapter with the new firmware */
4192 status = vxge_hw_flash_fw(hldev);
4193 if (status != VXGE_HW_OK) {
4194 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4195 VXGE_DRIVER_NAME, fw_name);
4196 ret = -EIO;
4197 goto out;
4198 }
4199
4200 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4201 "hard reset before using, thus requiring a system reboot or a "
4202 "hotplug event.\n");
4203
4204out:
Jesper Juhle84f8852011-01-13 10:25:20 +00004205 release_firmware(fw);
Jon Masone8ac1752010-11-11 04:25:57 +00004206 return ret;
4207}
4208
4209static int vxge_probe_fw_update(struct vxgedev *vdev)
4210{
4211 u32 maj, min, bld;
4212 int ret, gpxe = 0;
4213 char *fw_name;
4214
4215 maj = vdev->config.device_hw_info.fw_version.major;
4216 min = vdev->config.device_hw_info.fw_version.minor;
4217 bld = vdev->config.device_hw_info.fw_version.build;
4218
4219 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4220 return 0;
4221
4222 /* Ignore the build number when determining if the current firmware is
4223 * "too new" to load the driver
4224 */
4225 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4226 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4227 "version, unable to load driver\n",
4228 VXGE_DRIVER_NAME);
4229 return -EINVAL;
4230 }
4231
4232 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4233 * work with this driver.
4234 */
4235 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4236 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4237 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4238 return -EINVAL;
4239 }
4240
4241 /* If file not specified, determine gPXE or not */
4242 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4243 int i;
4244 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4245 if (vdev->devh->eprom_versions[i]) {
4246 gpxe = 1;
4247 break;
4248 }
4249 }
4250 if (gpxe)
4251 fw_name = "vxge/X3fw-pxe.ncf";
4252 else
4253 fw_name = "vxge/X3fw.ncf";
4254
4255 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4256 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4257 * probe, so ignore them
4258 */
4259 if (ret != -EINVAL && ret != -ENOENT)
4260 return -EIO;
4261 else
4262 ret = 0;
4263
4264 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4265 VXGE_FW_VER(maj, min, 0)) {
4266 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
4267 " be used with this driver.\n"
4268 "Please get the latest version from "
4269 "ftp://ftp.s2io.com/pub/X3100-Drivers/FIRMWARE",
4270 VXGE_DRIVER_NAME, maj, min, bld);
4271 return -EINVAL;
4272 }
4273
4274 return ret;
4275}
4276
Jon Masonc92bf702010-12-10 14:02:57 +00004277static int __devinit is_sriov_initialized(struct pci_dev *pdev)
4278{
4279 int pos;
4280 u16 ctrl;
4281
4282 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4283 if (pos) {
4284 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4285 if (ctrl & PCI_SRIOV_CTRL_VFE)
4286 return 1;
4287 }
4288 return 0;
4289}
4290
stephen hemminger956a2062011-09-16 11:10:01 +00004291static const struct vxge_hw_uld_cbs vxge_callbacks = {
4292 .link_up = vxge_callback_link_up,
4293 .link_down = vxge_callback_link_down,
4294 .crit_err = vxge_callback_crit_err,
4295};
4296
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004297/**
4298 * vxge_probe
4299 * @pdev : structure containing the PCI related information of the device.
4300 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4301 * Description:
4302 * This function is called when a new PCI device gets detected and initializes
4303 * it.
4304 * Return value:
4305 * returns 0 on success and negative on failure.
4306 *
4307 */
4308static int __devinit
4309vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4310{
Jon Mason2c913082010-11-11 04:26:03 +00004311 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004312 enum vxge_hw_status status;
4313 int ret;
4314 int high_dma = 0;
4315 u64 vpath_mask = 0;
4316 struct vxgedev *vdev;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004317 struct vxge_config *ll_config = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004318 struct vxge_hw_device_config *device_config = NULL;
4319 struct vxge_hw_device_attr attr;
4320 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4321 u8 *macaddr;
4322 struct vxge_mac_addrs *entry;
4323 static int bus = -1, device = -1;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004324 u32 host_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004325 u8 new_device = 0;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004326 enum vxge_hw_status is_privileged;
4327 u32 function_mode;
4328 u32 num_vfs = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004329
4330 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4331 attr.pdev = pdev;
4332
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004333 /* In SRIOV-17 mode, functions of the same adapter
Jon Mason528f7272010-12-10 14:02:56 +00004334 * can be deployed on different buses
4335 */
4336 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4337 !pdev->is_virtfn)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004338 new_device = 1;
4339
4340 bus = pdev->bus->number;
4341 device = PCI_SLOT(pdev->devfn);
4342
4343 if (new_device) {
4344 if (driver_config->config_dev_cnt &&
4345 (driver_config->config_dev_cnt !=
4346 driver_config->total_dev_cnt))
4347 vxge_debug_init(VXGE_ERR,
4348 "%s: Configured %d of %d devices",
4349 VXGE_DRIVER_NAME,
4350 driver_config->config_dev_cnt,
4351 driver_config->total_dev_cnt);
4352 driver_config->config_dev_cnt = 0;
4353 driver_config->total_dev_cnt = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004354 }
Jon Mason528f7272010-12-10 14:02:56 +00004355
Sreenivasa Honnur90023972010-04-08 01:48:30 -07004356 /* Now making the CPU based no of vpath calculation
4357 * applicable for individual functions as well.
4358 */
4359 driver_config->g_no_cpus = 0;
Sreenivasa Honnur657205b2009-10-05 01:52:54 +00004360 driver_config->vpath_per_dev = max_config_vpath;
4361
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004362 driver_config->total_dev_cnt++;
4363 if (++driver_config->config_dev_cnt > max_config_dev) {
4364 ret = 0;
4365 goto _exit0;
4366 }
4367
4368 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4369 GFP_KERNEL);
4370 if (!device_config) {
4371 ret = -ENOMEM;
4372 vxge_debug_init(VXGE_ERR,
4373 "device_config : malloc failed %s %d",
4374 __FILE__, __LINE__);
4375 goto _exit0;
4376 }
4377
Jon Mason528f7272010-12-10 14:02:56 +00004378 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004379 if (!ll_config) {
4380 ret = -ENOMEM;
4381 vxge_debug_init(VXGE_ERR,
Jon Mason528f7272010-12-10 14:02:56 +00004382 "device_config : malloc failed %s %d",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004383 __FILE__, __LINE__);
4384 goto _exit0;
4385 }
4386 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4387 ll_config->intr_type = MSI_X;
4388 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4389 ll_config->rth_steering = RTH_STEERING;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004390
4391 /* get the default configuration parameters */
4392 vxge_hw_device_config_default_get(device_config);
4393
4394 /* initialize configuration parameters */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004395 vxge_device_config_init(device_config, &ll_config->intr_type);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004396
4397 ret = pci_enable_device(pdev);
4398 if (ret) {
4399 vxge_debug_init(VXGE_ERR,
4400 "%s : can not enable PCI device", __func__);
4401 goto _exit0;
4402 }
4403
Denis Kirjanovb3837cec2009-12-25 18:48:33 -08004404 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004405 vxge_debug_ll_config(VXGE_TRACE,
4406 "%s : using 64bit DMA", __func__);
4407
4408 high_dma = 1;
4409
4410 if (pci_set_consistent_dma_mask(pdev,
Denis Kirjanovb3837cec2009-12-25 18:48:33 -08004411 DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004412 vxge_debug_init(VXGE_ERR,
4413 "%s : unable to obtain 64bit DMA for "
4414 "consistent allocations", __func__);
4415 ret = -ENOMEM;
4416 goto _exit1;
4417 }
Denis Kirjanovb3837cec2009-12-25 18:48:33 -08004418 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004419 vxge_debug_ll_config(VXGE_TRACE,
4420 "%s : using 32bit DMA", __func__);
4421 } else {
4422 ret = -ENOMEM;
4423 goto _exit1;
4424 }
4425
Jon Mason6cca2002011-01-18 15:02:19 +00004426 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4427 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004428 vxge_debug_init(VXGE_ERR,
4429 "%s : request regions failed", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004430 goto _exit1;
4431 }
4432
4433 pci_set_master(pdev);
4434
4435 attr.bar0 = pci_ioremap_bar(pdev, 0);
4436 if (!attr.bar0) {
4437 vxge_debug_init(VXGE_ERR,
4438 "%s : cannot remap io memory bar0", __func__);
4439 ret = -ENODEV;
4440 goto _exit2;
4441 }
4442 vxge_debug_ll_config(VXGE_TRACE,
4443 "pci ioremap bar0: %p:0x%llx",
4444 attr.bar0,
4445 (unsigned long long)pci_resource_start(pdev, 0));
4446
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004447 status = vxge_hw_device_hw_info_get(attr.bar0,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004448 &ll_config->device_hw_info);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004449 if (status != VXGE_HW_OK) {
4450 vxge_debug_init(VXGE_ERR,
4451 "%s: Reading of hardware info failed."
4452 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4453 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004454 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004455 }
4456
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004457 vpath_mask = ll_config->device_hw_info.vpath_mask;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004458 if (vpath_mask == 0) {
4459 vxge_debug_ll_config(VXGE_TRACE,
4460 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4461 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004462 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004463 }
4464
4465 vxge_debug_ll_config(VXGE_TRACE,
4466 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4467 (unsigned long long)vpath_mask);
4468
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004469 function_mode = ll_config->device_hw_info.function_mode;
4470 host_type = ll_config->device_hw_info.host_type;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004471 is_privileged = __vxge_hw_device_is_privilaged(host_type,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004472 ll_config->device_hw_info.func_id);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004473
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004474 /* Check how many vpaths are available */
4475 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4476 if (!((vpath_mask) & vxge_mBIT(i)))
4477 continue;
4478 max_vpath_supported++;
4479 }
4480
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004481 if (new_device)
4482 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4483
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004484 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
Jon Masonc92bf702010-12-10 14:02:57 +00004485 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4486 (ll_config->intr_type != INTA)) {
4487 ret = pci_enable_sriov(pdev, num_vfs);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004488 if (ret)
4489 vxge_debug_ll_config(VXGE_ERR,
4490 "Failed in enabling SRIOV mode: %d\n", ret);
Jon Masonc92bf702010-12-10 14:02:57 +00004491 /* No need to fail out, as an error here is non-fatal */
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004492 }
4493
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004494 /*
4495 * Configure vpaths and get driver configured number of vpaths
4496 * which is less than or equal to the maximum vpaths per function.
4497 */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004498 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004499 if (!no_of_vpath) {
4500 vxge_debug_ll_config(VXGE_ERR,
4501 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4502 ret = 0;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004503 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004504 }
4505
4506 /* Setting driver callbacks */
stephen hemminger956a2062011-09-16 11:10:01 +00004507 attr.uld_callbacks = &vxge_callbacks;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004508
4509 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4510 if (status != VXGE_HW_OK) {
4511 vxge_debug_init(VXGE_ERR,
4512 "Failed to initialize device (%d)", status);
4513 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004514 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004515 }
4516
Jon Masone8ac1752010-11-11 04:25:57 +00004517 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4518 ll_config->device_hw_info.fw_version.minor,
4519 ll_config->device_hw_info.fw_version.build) >=
4520 VXGE_EPROM_FW_VER) {
4521 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4522
4523 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4524 if (status != VXGE_HW_OK) {
4525 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4526 VXGE_DRIVER_NAME);
4527 /* This is a non-fatal error, continue */
4528 }
4529
4530 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4531 hldev->eprom_versions[i] = img[i].version;
4532 if (!img[i].is_valid)
4533 break;
4534 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
Jon Mason1d15f812011-01-18 15:02:20 +00004535 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
Jon Masone8ac1752010-11-11 04:25:57 +00004536 VXGE_EPROM_IMG_MAJOR(img[i].version),
4537 VXGE_EPROM_IMG_MINOR(img[i].version),
4538 VXGE_EPROM_IMG_FIX(img[i].version),
4539 VXGE_EPROM_IMG_BUILD(img[i].version));
4540 }
4541 }
4542
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004543 /* if FCS stripping is not disabled in MAC fail driver load */
Jon Masonb81b3732010-11-11 04:25:58 +00004544 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4545 if (status != VXGE_HW_OK) {
4546 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4547 " failing driver load", VXGE_DRIVER_NAME);
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004548 ret = -EINVAL;
4549 goto _exit4;
4550 }
4551
Jon Masoncd883a72011-04-08 11:11:21 +00004552 /* Always enable HWTS. This will always cause the FCS to be invalid,
4553 * due to the fact that HWTS is using the FCS as the location of the
4554 * timestamp. The HW FCS checking will still correctly determine if
4555 * there is a valid checksum, and the FCS is being removed by the driver
4556 * anyway. So no fucntionality is being lost. Since it is always
4557 * enabled, we now simply use the ioctl call to set whether or not the
4558 * driver should be paying attention to the HWTS.
4559 */
4560 if (is_privileged == VXGE_HW_OK) {
4561 status = vxge_timestamp_config(hldev);
4562 if (status != VXGE_HW_OK) {
4563 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4564 VXGE_DRIVER_NAME);
4565 ret = -EFAULT;
4566 goto _exit4;
4567 }
4568 }
4569
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004570 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4571
4572 /* set private device info */
4573 pci_set_drvdata(pdev, hldev);
4574
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004575 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4576 ll_config->addr_learn_en = addr_learn_en;
4577 ll_config->rth_algorithm = RTH_ALG_JENKINS;
Jon Mason47f01db2010-11-11 04:25:53 +00004578 ll_config->rth_hash_type_tcpipv4 = 1;
4579 ll_config->rth_hash_type_ipv4 = 0;
4580 ll_config->rth_hash_type_tcpipv6 = 0;
4581 ll_config->rth_hash_type_ipv6 = 0;
4582 ll_config->rth_hash_type_tcpipv6ex = 0;
4583 ll_config->rth_hash_type_ipv6ex = 0;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004584 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4585 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4586 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004587
Jon Masone8ac1752010-11-11 04:25:57 +00004588 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4589 &vdev);
4590 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004591 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004592 goto _exit4;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004593 }
4594
Jon Masone8ac1752010-11-11 04:25:57 +00004595 ret = vxge_probe_fw_update(vdev);
4596 if (ret)
4597 goto _exit5;
4598
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004599 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4600 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4601 vxge_hw_device_trace_level_get(hldev));
4602
4603 /* set private HW device info */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004604 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4605 vdev->bar0 = attr.bar0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004606 vdev->max_vpath_supported = max_vpath_supported;
4607 vdev->no_of_vpath = no_of_vpath;
4608
4609 /* Virtual Path count */
4610 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4611 if (!vxge_bVALn(vpath_mask, i, 1))
4612 continue;
4613 if (j >= vdev->no_of_vpath)
4614 break;
4615
4616 vdev->vpaths[j].is_configured = 1;
4617 vdev->vpaths[j].device_id = i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004618 vdev->vpaths[j].ring.driver_id = j;
4619 vdev->vpaths[j].vdev = vdev;
4620 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4621 memcpy((u8 *)vdev->vpaths[j].macaddr,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004622 ll_config->device_hw_info.mac_addrs[i],
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004623 ETH_ALEN);
4624
4625 /* Initialize the mac address list header */
4626 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4627
4628 vdev->vpaths[j].mac_addr_cnt = 0;
4629 vdev->vpaths[j].mcast_addr_cnt = 0;
4630 j++;
4631 }
4632 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4633 vdev->max_config_port = max_config_port;
4634
4635 vdev->vlan_tag_strip = vlan_tag_strip;
4636
4637 /* map the hashing selector table to the configured vpaths */
4638 for (i = 0; i < vdev->no_of_vpath; i++)
4639 vdev->vpath_selector[i] = vpath_selector[i];
4640
4641 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4642
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004643 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4644 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4645 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004646
4647 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004648 vdev->ndev->name, ll_config->device_hw_info.serial_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004649
4650 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004651 vdev->ndev->name, ll_config->device_hw_info.part_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004652
4653 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004654 vdev->ndev->name, ll_config->device_hw_info.product_desc);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004655
hartleysbf54e732010-01-05 06:59:23 +00004656 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4657 vdev->ndev->name, macaddr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004658
4659 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4660 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4661
4662 vxge_debug_init(VXGE_TRACE,
4663 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004664 ll_config->device_hw_info.fw_version.version,
4665 ll_config->device_hw_info.fw_date.date);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004666
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004667 if (new_device) {
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004668 switch (ll_config->device_hw_info.function_mode) {
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004669 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4670 vxge_debug_init(VXGE_TRACE,
4671 "%s: Single Function Mode Enabled", vdev->ndev->name);
4672 break;
4673 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4674 vxge_debug_init(VXGE_TRACE,
4675 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4676 break;
4677 case VXGE_HW_FUNCTION_MODE_SRIOV:
4678 vxge_debug_init(VXGE_TRACE,
4679 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4680 break;
4681 case VXGE_HW_FUNCTION_MODE_MRIOV:
4682 vxge_debug_init(VXGE_TRACE,
4683 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4684 break;
4685 }
4686 }
4687
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004688 vxge_print_parm(vdev, vpath_mask);
4689
4690 /* Store the fw version for ethttool option */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004691 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004692 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
4693 memcpy(vdev->ndev->perm_addr, vdev->ndev->dev_addr, ETH_ALEN);
4694
4695 /* Copy the station mac address to the list */
4696 for (i = 0; i < vdev->no_of_vpath; i++) {
Joe Perchese80be0b2010-11-27 23:05:45 +00004697 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004698 if (NULL == entry) {
4699 vxge_debug_init(VXGE_ERR,
4700 "%s: mac_addr_list : memory allocation failed",
4701 vdev->ndev->name);
4702 ret = -EPERM;
Jon Masone8ac1752010-11-11 04:25:57 +00004703 goto _exit6;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004704 }
4705 macaddr = (u8 *)&entry->macaddr;
4706 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4707 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4708 vdev->vpaths[i].mac_addr_cnt = 1;
4709 }
4710
Sreenivasa Honnur914d0d72009-07-01 21:13:12 +00004711 kfree(device_config);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004712
4713 /*
4714 * INTA is shared in multi-function mode. This is unlike the INTA
4715 * implementation in MR mode, where each VH has its own INTA message.
4716 * - INTA is masked (disabled) as long as at least one function sets
4717 * its TITAN_MASK_ALL_INT.ALARM bit.
4718 * - INTA is unmasked (enabled) when all enabled functions have cleared
4719 * their own TITAN_MASK_ALL_INT.ALARM bit.
4720 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4721 * Though this driver leaves the top level interrupts unmasked while
4722 * leaving the required module interrupt bits masked on exit, there
4723 * could be a rougue driver around that does not follow this procedure
4724 * resulting in a failure to generate interrupts. The following code is
4725 * present to prevent such a failure.
4726 */
4727
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004728 if (ll_config->device_hw_info.function_mode ==
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004729 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4730 if (vdev->config.intr_type == INTA)
4731 vxge_hw_device_unmask_all(hldev);
4732
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004733 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4734 vdev->ndev->name, __func__, __LINE__);
4735
4736 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4737 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4738 vxge_hw_device_trace_level_get(hldev));
4739
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004740 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004741 return 0;
4742
Jon Masone8ac1752010-11-11 04:25:57 +00004743_exit6:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004744 for (i = 0; i < vdev->no_of_vpath; i++)
4745 vxge_free_mac_add_list(&vdev->vpaths[i]);
Jon Masone8ac1752010-11-11 04:25:57 +00004746_exit5:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004747 vxge_device_unregister(hldev);
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004748_exit4:
Jon Mason6cca2002011-01-18 15:02:19 +00004749 pci_set_drvdata(pdev, NULL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004750 vxge_hw_device_terminate(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004751 pci_disable_sriov(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004752_exit3:
4753 iounmap(attr.bar0);
4754_exit2:
Jon Masondc66daa2010-12-10 14:02:58 +00004755 pci_release_region(pdev, 0);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004756_exit1:
4757 pci_disable_device(pdev);
4758_exit0:
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004759 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004760 kfree(device_config);
4761 driver_config->config_dev_cnt--;
Jon Mason6cca2002011-01-18 15:02:19 +00004762 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004763 return ret;
4764}
4765
4766/**
4767 * vxge_rem_nic - Free the PCI device
4768 * @pdev: structure containing the PCI related information of the device.
4769 * Description: This function is called by the Pci subsystem to release a
4770 * PCI device and free up all resource held up by the device.
4771 */
Jon Mason2c913082010-11-11 04:26:03 +00004772static void __devexit vxge_remove(struct pci_dev *pdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004773{
Jon Mason2c913082010-11-11 04:26:03 +00004774 struct __vxge_hw_device *hldev;
Jon Mason6cca2002011-01-18 15:02:19 +00004775 struct vxgedev *vdev;
4776 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004777
Joe Perchesd8ee7072010-11-15 10:13:58 +00004778 hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004779 if (hldev == NULL)
4780 return;
Jon Mason2c913082010-11-11 04:26:03 +00004781
Jon Mason6cca2002011-01-18 15:02:19 +00004782 vdev = netdev_priv(hldev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004783
Jon Mason2c913082010-11-11 04:26:03 +00004784 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004785 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4786 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004787
Jon Mason6cca2002011-01-18 15:02:19 +00004788 for (i = 0; i < vdev->no_of_vpath; i++)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004789 vxge_free_mac_add_list(&vdev->vpaths[i]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004790
Jon Mason6cca2002011-01-18 15:02:19 +00004791 vxge_device_unregister(hldev);
4792 pci_set_drvdata(pdev, NULL);
4793 /* Do not call pci_disable_sriov here, as it will break child devices */
4794 vxge_hw_device_terminate(hldev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004795 iounmap(vdev->bar0);
Jon Mason6cca2002011-01-18 15:02:19 +00004796 pci_release_region(pdev, 0);
4797 pci_disable_device(pdev);
4798 driver_config->config_dev_cnt--;
4799 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004800
Jon Mason2c913082010-11-11 04:26:03 +00004801 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4802 __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004803 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4804 __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004805}
4806
4807static struct pci_error_handlers vxge_err_handler = {
4808 .error_detected = vxge_io_error_detected,
4809 .slot_reset = vxge_io_slot_reset,
4810 .resume = vxge_io_resume,
4811};
4812
4813static struct pci_driver vxge_driver = {
4814 .name = VXGE_DRIVER_NAME,
4815 .id_table = vxge_id_table,
4816 .probe = vxge_probe,
4817 .remove = __devexit_p(vxge_remove),
4818#ifdef CONFIG_PM
4819 .suspend = vxge_pm_suspend,
4820 .resume = vxge_pm_resume,
4821#endif
4822 .err_handler = &vxge_err_handler,
4823};
4824
4825static int __init
4826vxge_starter(void)
4827{
4828 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004829
Joe Perches75f5e1c2010-07-27 11:47:03 +00004830 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4831 pr_info("Driver version: %s\n", DRV_VERSION);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004832
4833 verify_bandwidth();
4834
4835 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4836 if (!driver_config)
4837 return -ENOMEM;
4838
4839 ret = pci_register_driver(&vxge_driver);
Jon Mason528f7272010-12-10 14:02:56 +00004840 if (ret) {
4841 kfree(driver_config);
4842 goto err;
4843 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004844
4845 if (driver_config->config_dev_cnt &&
4846 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4847 vxge_debug_init(VXGE_ERR,
4848 "%s: Configured %d of %d devices",
4849 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4850 driver_config->total_dev_cnt);
Jon Mason528f7272010-12-10 14:02:56 +00004851err:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004852 return ret;
4853}
4854
4855static void __exit
4856vxge_closer(void)
4857{
4858 pci_unregister_driver(&vxge_driver);
4859 kfree(driver_config);
4860}
4861module_init(vxge_starter);
4862module_exit(vxge_closer);