blob: c5bb1ace4a746f6a96887392a5a2da018d3a63a6 [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;
stephen hemmingere40c10f2014-01-15 08:28:54 -080090static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +000091
92static inline int is_vxge_card_up(struct vxgedev *vdev)
93{
94 return test_bit(__VXGE_STATE_CARD_UP, &vdev->state);
95}
96
97static inline void VXGE_COMPLETE_VPATH_TX(struct vxge_fifo *fifo)
98{
Benjamin LaHaiseff67df52009-08-04 10:21:03 +000099 struct sk_buff **skb_ptr = NULL;
100 struct sk_buff **temp;
101#define NR_SKB_COMPLETED 128
102 struct sk_buff *completed[NR_SKB_COMPLETED];
103 int more;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000104
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000105 do {
106 more = 0;
107 skb_ptr = completed;
108
Jon Mason98f45da2010-07-15 08:47:25 +0000109 if (__netif_tx_trylock(fifo->txq)) {
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000110 vxge_hw_vpath_poll_tx(fifo->handle, &skb_ptr,
111 NR_SKB_COMPLETED, &more);
Jon Mason98f45da2010-07-15 08:47:25 +0000112 __netif_tx_unlock(fifo->txq);
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000113 }
Jon Mason98f45da2010-07-15 08:47:25 +0000114
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000115 /* free SKBs */
116 for (temp = completed; temp != skb_ptr; temp++)
117 dev_kfree_skb_irq(*temp);
Jon Mason98f45da2010-07-15 08:47:25 +0000118 } while (more);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000119}
120
121static inline void VXGE_COMPLETE_ALL_TX(struct vxgedev *vdev)
122{
123 int i;
124
125 /* Complete all transmits */
126 for (i = 0; i < vdev->no_of_vpath; i++)
127 VXGE_COMPLETE_VPATH_TX(&vdev->vpaths[i].fifo);
128}
129
130static inline void VXGE_COMPLETE_ALL_RX(struct vxgedev *vdev)
131{
132 int i;
133 struct vxge_ring *ring;
134
135 /* Complete all receives*/
136 for (i = 0; i < vdev->no_of_vpath; i++) {
137 ring = &vdev->vpaths[i].ring;
138 vxge_hw_vpath_poll_rx(ring->handle);
139 }
140}
141
142/*
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000143 * vxge_callback_link_up
144 *
145 * This function is called during interrupt context to notify link up state
146 * change.
147 */
Jon Mason528f7272010-12-10 14:02:56 +0000148static void vxge_callback_link_up(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000149{
150 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000151 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000152
153 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
154 vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000155 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000156 vdev->stats.link_up++;
157
158 netif_carrier_on(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000159 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000160
161 vxge_debug_entryexit(VXGE_TRACE,
162 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
163}
164
165/*
166 * vxge_callback_link_down
167 *
168 * This function is called during interrupt context to notify link down state
169 * change.
170 */
Jon Mason528f7272010-12-10 14:02:56 +0000171static void vxge_callback_link_down(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000172{
173 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +0000174 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000175
176 vxge_debug_entryexit(VXGE_TRACE,
177 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
Joe Perches75f5e1c2010-07-27 11:47:03 +0000178 netdev_notice(vdev->ndev, "Link Down\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000179
180 vdev->stats.link_down++;
181 netif_carrier_off(vdev->ndev);
Jon Masond03848e2010-07-15 08:47:23 +0000182 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000183
184 vxge_debug_entryexit(VXGE_TRACE,
185 "%s: %s:%d Exiting...", vdev->ndev->name, __func__, __LINE__);
186}
187
188/*
189 * vxge_rx_alloc
190 *
191 * Allocate SKB.
192 */
Jon Mason528f7272010-12-10 14:02:56 +0000193static struct sk_buff *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000194vxge_rx_alloc(void *dtrh, struct vxge_ring *ring, const int skb_size)
195{
196 struct net_device *dev;
197 struct sk_buff *skb;
198 struct vxge_rx_priv *rx_priv;
199
200 dev = ring->ndev;
201 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
202 ring->ndev->name, __func__, __LINE__);
203
204 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
205
206 /* try to allocate skb first. this one may fail */
207 skb = netdev_alloc_skb(dev, skb_size +
208 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
209 if (skb == NULL) {
210 vxge_debug_mem(VXGE_ERR,
211 "%s: out of memory to allocate SKB", dev->name);
212 ring->stats.skb_alloc_fail++;
213 return NULL;
214 }
215
216 vxge_debug_mem(VXGE_TRACE,
217 "%s: %s:%d Skb : 0x%p", ring->ndev->name,
218 __func__, __LINE__, skb);
219
220 skb_reserve(skb, VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
221
222 rx_priv->skb = skb;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000223 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000224 rx_priv->data_size = skb_size;
225 vxge_debug_entryexit(VXGE_TRACE,
226 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
227
228 return skb;
229}
230
231/*
232 * vxge_rx_map
233 */
234static int vxge_rx_map(void *dtrh, struct vxge_ring *ring)
235{
236 struct vxge_rx_priv *rx_priv;
237 dma_addr_t dma_addr;
238
239 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
240 ring->ndev->name, __func__, __LINE__);
241 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
242
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000243 rx_priv->skb_data = rx_priv->skb->data;
244 dma_addr = pci_map_single(ring->pdev, rx_priv->skb_data,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000245 rx_priv->data_size, PCI_DMA_FROMDEVICE);
246
Denis Kirjanovfa15e992010-01-10 13:40:10 -0800247 if (unlikely(pci_dma_mapping_error(ring->pdev, dma_addr))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000248 ring->stats.pci_map_fail++;
249 return -EIO;
250 }
251 vxge_debug_mem(VXGE_TRACE,
252 "%s: %s:%d 1 buffer mode dma_addr = 0x%llx",
253 ring->ndev->name, __func__, __LINE__,
254 (unsigned long long)dma_addr);
255 vxge_hw_ring_rxd_1b_set(dtrh, dma_addr, rx_priv->data_size);
256
257 rx_priv->data_dma = dma_addr;
258 vxge_debug_entryexit(VXGE_TRACE,
259 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
260
261 return 0;
262}
263
264/*
265 * vxge_rx_initial_replenish
266 * Allocation of RxD as an initial replenish procedure.
267 */
268static enum vxge_hw_status
269vxge_rx_initial_replenish(void *dtrh, void *userdata)
270{
271 struct vxge_ring *ring = (struct vxge_ring *)userdata;
272 struct vxge_rx_priv *rx_priv;
273
274 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
275 ring->ndev->name, __func__, __LINE__);
276 if (vxge_rx_alloc(dtrh, ring,
277 VXGE_LL_MAX_FRAME_SIZE(ring->ndev)) == NULL)
278 return VXGE_HW_FAIL;
279
280 if (vxge_rx_map(dtrh, ring)) {
281 rx_priv = vxge_hw_ring_rxd_private_get(dtrh);
282 dev_kfree_skb(rx_priv->skb);
283
284 return VXGE_HW_FAIL;
285 }
286 vxge_debug_entryexit(VXGE_TRACE,
287 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
288
289 return VXGE_HW_OK;
290}
291
292static inline void
293vxge_rx_complete(struct vxge_ring *ring, struct sk_buff *skb, u16 vlan,
294 int pkt_length, struct vxge_hw_ring_rxd_info *ext_info)
295{
296
297 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
298 ring->ndev->name, __func__, __LINE__);
299 skb_record_rx_queue(skb, ring->driver_id);
300 skb->protocol = eth_type_trans(skb, ring->ndev);
301
stephen hemminger62ea0552011-06-20 10:35:07 +0000302 u64_stats_update_begin(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000303 ring->stats.rx_frms++;
304 ring->stats.rx_bytes += pkt_length;
305
306 if (skb->pkt_type == PACKET_MULTICAST)
307 ring->stats.rx_mcast++;
stephen hemminger62ea0552011-06-20 10:35:07 +0000308 u64_stats_update_end(&ring->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000309
310 vxge_debug_rx(VXGE_TRACE,
311 "%s: %s:%d skb protocol = %d",
312 ring->ndev->name, __func__, __LINE__, skb->protocol);
313
Jiri Pirko53515732011-07-20 04:54:40 +0000314 if (ext_info->vlan &&
315 ring->vlan_tag_strip == VXGE_HW_VPATH_RPA_STRIP_VLAN_TAG_ENABLE)
Patrick McHardy86a9bad2013-04-19 02:04:30 +0000316 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), ext_info->vlan);
Jiri Pirko53515732011-07-20 04:54:40 +0000317 napi_gro_receive(ring->napi_p, skb);
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000318
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000319 vxge_debug_entryexit(VXGE_TRACE,
320 "%s: %s:%d Exiting...", ring->ndev->name, __func__, __LINE__);
321}
322
323static inline void vxge_re_pre_post(void *dtr, struct vxge_ring *ring,
324 struct vxge_rx_priv *rx_priv)
325{
326 pci_dma_sync_single_for_device(ring->pdev,
327 rx_priv->data_dma, rx_priv->data_size, PCI_DMA_FROMDEVICE);
328
329 vxge_hw_ring_rxd_1b_set(dtr, rx_priv->data_dma, rx_priv->data_size);
330 vxge_hw_ring_rxd_pre_post(ring->handle, dtr);
331}
332
333static inline void vxge_post(int *dtr_cnt, void **first_dtr,
334 void *post_dtr, struct __vxge_hw_ring *ringh)
335{
336 int dtr_count = *dtr_cnt;
337 if ((*dtr_cnt % VXGE_HW_RXSYNC_FREQ_CNT) == 0) {
338 if (*first_dtr)
339 vxge_hw_ring_rxd_post_post_wmb(ringh, *first_dtr);
340 *first_dtr = post_dtr;
341 } else
342 vxge_hw_ring_rxd_post_post(ringh, post_dtr);
343 dtr_count++;
344 *dtr_cnt = dtr_count;
345}
346
347/*
348 * vxge_rx_1b_compl
349 *
350 * If the interrupt is because of a received frame or if the receive ring
351 * contains fresh as yet un-processed frames, this function is called.
352 */
stephen hemminger42821a52010-10-21 07:50:53 +0000353static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000354vxge_rx_1b_compl(struct __vxge_hw_ring *ringh, void *dtr,
355 u8 t_code, void *userdata)
356{
357 struct vxge_ring *ring = (struct vxge_ring *)userdata;
Jon Masonb81b3732010-11-11 04:25:58 +0000358 struct net_device *dev = ring->ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000359 unsigned int dma_sizes;
360 void *first_dtr = NULL;
361 int dtr_cnt = 0;
362 int data_size;
363 dma_addr_t data_dma;
364 int pkt_length;
365 struct sk_buff *skb;
366 struct vxge_rx_priv *rx_priv;
367 struct vxge_hw_ring_rxd_info ext_info;
368 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
369 ring->ndev->name, __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000370
371 do {
Benjamin LaHaise3f23e432009-08-04 10:21:39 +0000372 prefetch((char *)dtr + L1_CACHE_BYTES);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000373 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
374 skb = rx_priv->skb;
375 data_size = rx_priv->data_size;
376 data_dma = rx_priv->data_dma;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000377 prefetch(rx_priv->skb_data);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000378
379 vxge_debug_rx(VXGE_TRACE,
380 "%s: %s:%d skb = 0x%p",
381 ring->ndev->name, __func__, __LINE__, skb);
382
383 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
384 pkt_length = dma_sizes;
385
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +0000386 pkt_length -= ETH_FCS_LEN;
387
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000388 vxge_debug_rx(VXGE_TRACE,
389 "%s: %s:%d Packet Length = %d",
390 ring->ndev->name, __func__, __LINE__, pkt_length);
391
392 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
393
394 /* check skb validity */
395 vxge_assert(skb);
396
397 prefetch((char *)skb + L1_CACHE_BYTES);
398 if (unlikely(t_code)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000399 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
400 VXGE_HW_OK) {
401
402 ring->stats.rx_errors++;
403 vxge_debug_rx(VXGE_TRACE,
404 "%s: %s :%d Rx T_code is %d",
405 ring->ndev->name, __func__,
406 __LINE__, t_code);
407
408 /* If the t_code is not supported and if the
409 * t_code is other than 0x5 (unparseable packet
410 * such as unknown UPV6 header), Drop it !!!
411 */
412 vxge_re_pre_post(dtr, ring, rx_priv);
413
414 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
415 ring->stats.rx_dropped++;
416 continue;
417 }
418 }
419
420 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000421 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000422 if (!vxge_rx_map(dtr, ring)) {
423 skb_put(skb, pkt_length);
424
425 pci_unmap_single(ring->pdev, data_dma,
426 data_size, PCI_DMA_FROMDEVICE);
427
428 vxge_hw_ring_rxd_pre_post(ringh, dtr);
429 vxge_post(&dtr_cnt, &first_dtr, dtr,
430 ringh);
431 } else {
432 dev_kfree_skb(rx_priv->skb);
433 rx_priv->skb = skb;
434 rx_priv->data_size = data_size;
435 vxge_re_pre_post(dtr, ring, rx_priv);
436
437 vxge_post(&dtr_cnt, &first_dtr, dtr,
438 ringh);
439 ring->stats.rx_dropped++;
440 break;
441 }
442 } else {
443 vxge_re_pre_post(dtr, ring, rx_priv);
444
445 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
446 ring->stats.rx_dropped++;
447 break;
448 }
449 } else {
450 struct sk_buff *skb_up;
451
452 skb_up = netdev_alloc_skb(dev, pkt_length +
453 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
454 if (skb_up != NULL) {
455 skb_reserve(skb_up,
456 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
457
458 pci_dma_sync_single_for_cpu(ring->pdev,
459 data_dma, data_size,
460 PCI_DMA_FROMDEVICE);
461
462 vxge_debug_mem(VXGE_TRACE,
463 "%s: %s:%d skb_up = %p",
464 ring->ndev->name, __func__,
465 __LINE__, skb);
466 memcpy(skb_up->data, skb->data, pkt_length);
467
468 vxge_re_pre_post(dtr, ring, rx_priv);
469
470 vxge_post(&dtr_cnt, &first_dtr, dtr,
471 ringh);
472 /* will netif_rx small SKB instead */
473 skb = skb_up;
474 skb_put(skb, pkt_length);
475 } else {
476 vxge_re_pre_post(dtr, ring, rx_priv);
477
478 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
479 vxge_debug_rx(VXGE_ERR,
480 "%s: vxge_rx_1b_compl: out of "
481 "memory", dev->name);
482 ring->stats.skb_alloc_fail++;
483 break;
484 }
485 }
486
487 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
488 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000489 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000490 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
491 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
492 skb->ip_summed = CHECKSUM_UNNECESSARY;
493 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700494 skb_checksum_none_assert(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000495
Jon Masonb81b3732010-11-11 04:25:58 +0000496
497 if (ring->rx_hwts) {
498 struct skb_shared_hwtstamps *skb_hwts;
499 u32 ns = *(u32 *)(skb->head + pkt_length);
500
501 skb_hwts = skb_hwtstamps(skb);
502 skb_hwts->hwtstamp = ns_to_ktime(ns);
503 skb_hwts->syststamp.tv64 = 0;
504 }
505
Jon Mason47f01db2010-11-11 04:25:53 +0000506 /* rth_hash_type and rth_it_hit are non-zero regardless of
507 * whether rss is enabled. Only the rth_value is zero/non-zero
508 * if rss is disabled/enabled, so key off of that.
509 */
510 if (ext_info.rth_value)
Tom Herbertc4be4162013-12-17 23:31:36 -0800511 skb_set_hash(skb, ext_info.rth_value,
512 PKT_HASH_TYPE_L3);
Jon Mason47f01db2010-11-11 04:25:53 +0000513
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000514 vxge_rx_complete(ring, skb, ext_info.vlan,
515 pkt_length, &ext_info);
516
517 ring->budget--;
518 ring->pkts_processed++;
519 if (!ring->budget)
520 break;
521
522 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
523 &t_code) == VXGE_HW_OK);
524
525 if (first_dtr)
526 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
527
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000528 vxge_debug_entryexit(VXGE_TRACE,
529 "%s:%d Exiting...",
530 __func__, __LINE__);
531 return VXGE_HW_OK;
532}
533
534/*
535 * vxge_xmit_compl
536 *
537 * If an interrupt was raised to indicate DMA complete of the Tx packet,
538 * this function is called. It identifies the last TxD whose buffer was
539 * freed and frees all skbs whose data have already DMA'ed into the NICs
540 * internal memory.
541 */
stephen hemminger42821a52010-10-21 07:50:53 +0000542static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000543vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
544 enum vxge_hw_fifo_tcode t_code, void *userdata,
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000545 struct sk_buff ***skb_ptr, int nr_skb, int *more)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000546{
547 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000548 struct sk_buff *skb, **done_skb = *skb_ptr;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000549 int pkt_cnt = 0;
550
551 vxge_debug_entryexit(VXGE_TRACE,
552 "%s:%d Entered....", __func__, __LINE__);
553
554 do {
555 int frg_cnt;
556 skb_frag_t *frag;
557 int i = 0, j;
558 struct vxge_tx_priv *txd_priv =
559 vxge_hw_fifo_txdl_private_get(dtr);
560
561 skb = txd_priv->skb;
562 frg_cnt = skb_shinfo(skb)->nr_frags;
563 frag = &skb_shinfo(skb)->frags[0];
564
565 vxge_debug_tx(VXGE_TRACE,
566 "%s: %s:%d fifo_hw = %p dtr = %p "
567 "tcode = 0x%x", fifo->ndev->name, __func__,
568 __LINE__, fifo_hw, dtr, t_code);
569 /* check skb validity */
570 vxge_assert(skb);
571 vxge_debug_tx(VXGE_TRACE,
572 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
573 fifo->ndev->name, __func__, __LINE__,
574 skb, txd_priv, frg_cnt);
575 if (unlikely(t_code)) {
576 fifo->stats.tx_errors++;
577 vxge_debug_tx(VXGE_ERR,
578 "%s: tx: dtr %p completed due to "
579 "error t_code %01x", fifo->ndev->name,
580 dtr, t_code);
581 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
582 }
583
584 /* for unfragmented skb */
585 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
586 skb_headlen(skb), PCI_DMA_TODEVICE);
587
588 for (j = 0; j < frg_cnt; j++) {
589 pci_unmap_page(fifo->pdev,
590 txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000591 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000592 frag += 1;
593 }
594
595 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
596
597 /* Updating the statistics block */
stephen hemminger62ea0552011-06-20 10:35:07 +0000598 u64_stats_update_begin(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000599 fifo->stats.tx_frms++;
600 fifo->stats.tx_bytes += skb->len;
stephen hemminger62ea0552011-06-20 10:35:07 +0000601 u64_stats_update_end(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000602
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000603 *done_skb++ = skb;
604
605 if (--nr_skb <= 0) {
606 *more = 1;
607 break;
608 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000609
610 pkt_cnt++;
611 if (pkt_cnt > fifo->indicate_max_pkts)
612 break;
613
614 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
615 &dtr, &t_code) == VXGE_HW_OK);
616
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000617 *skb_ptr = done_skb;
Jon Mason98f45da2010-07-15 08:47:25 +0000618 if (netif_tx_queue_stopped(fifo->txq))
619 netif_tx_wake_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000620
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000621 vxge_debug_entryexit(VXGE_TRACE,
622 "%s: %s:%d Exiting...",
623 fifo->ndev->name, __func__, __LINE__);
624 return VXGE_HW_OK;
625}
626
Eric Dumazet28679752009-05-27 19:26:37 +0000627/* select a vpath to transmit the packet */
Jon Mason98f45da2010-07-15 08:47:25 +0000628static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000629{
630 u16 queue_len, counter = 0;
631 if (skb->protocol == htons(ETH_P_IP)) {
632 struct iphdr *ip;
633 struct tcphdr *th;
634
635 ip = ip_hdr(skb);
636
Paul Gortmaker56f8a752011-06-21 20:33:34 -0700637 if (!ip_is_fragment(ip)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000638 th = (struct tcphdr *)(((unsigned char *)ip) +
639 ip->ihl*4);
640
641 queue_len = vdev->no_of_vpath;
642 counter = (ntohs(th->source) +
643 ntohs(th->dest)) &
644 vdev->vpath_selector[queue_len - 1];
645 if (counter >= queue_len)
646 counter = queue_len - 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000647 }
648 }
649 return counter;
650}
651
652static enum vxge_hw_status vxge_search_mac_addr_in_list(
653 struct vxge_vpath *vpath, u64 del_mac)
654{
655 struct list_head *entry, *next;
656 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
657 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
658 return TRUE;
659 }
660 return FALSE;
661}
662
Jon Mason528f7272010-12-10 14:02:56 +0000663static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
664{
665 struct vxge_mac_addrs *new_mac_entry;
666 u8 *mac_address = NULL;
667
668 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
669 return TRUE;
670
671 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
672 if (!new_mac_entry) {
673 vxge_debug_mem(VXGE_ERR,
674 "%s: memory allocation failed",
675 VXGE_DRIVER_NAME);
676 return FALSE;
677 }
678
679 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
680
681 /* Copy the new mac address to the list */
682 mac_address = (u8 *)&new_mac_entry->macaddr;
683 memcpy(mac_address, mac->macaddr, ETH_ALEN);
684
685 new_mac_entry->state = mac->state;
686 vpath->mac_addr_cnt++;
687
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000688 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000689 vpath->mcast_addr_cnt++;
690
691 return TRUE;
692}
693
694/* Add a mac address to DA table */
695static enum vxge_hw_status
696vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
697{
698 enum vxge_hw_status status = VXGE_HW_OK;
699 struct vxge_vpath *vpath;
700 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
701
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000702 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000703 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
704 else
705 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
706
707 vpath = &vdev->vpaths[mac->vpath_no];
708 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
709 mac->macmask, duplicate_mode);
710 if (status != VXGE_HW_OK) {
711 vxge_debug_init(VXGE_ERR,
712 "DA config add entry failed for vpath:%d",
713 vpath->device_id);
714 } else
715 if (FALSE == vxge_mac_list_add(vpath, mac))
716 status = -EPERM;
717
718 return status;
719}
720
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000721static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
722{
723 struct macInfo mac_info;
724 u8 *mac_address = NULL;
725 u64 mac_addr = 0, vpath_vector = 0;
726 int vpath_idx = 0;
727 enum vxge_hw_status status = VXGE_HW_OK;
728 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000729
730 mac_address = (u8 *)&mac_addr;
731 memcpy(mac_address, mac_header, ETH_ALEN);
732
733 /* Is this mac address already in the list? */
734 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
735 vpath = &vdev->vpaths[vpath_idx];
736 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
737 return vpath_idx;
738 }
739
740 memset(&mac_info, 0, sizeof(struct macInfo));
741 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
742
743 /* Any vpath has room to add mac address to its da table? */
744 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
745 vpath = &vdev->vpaths[vpath_idx];
746 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
747 /* Add this mac address to this vpath */
748 mac_info.vpath_no = vpath_idx;
749 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
750 status = vxge_add_mac_addr(vdev, &mac_info);
751 if (status != VXGE_HW_OK)
752 return -EPERM;
753 return vpath_idx;
754 }
755 }
756
757 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
758 vpath_idx = 0;
759 mac_info.vpath_no = vpath_idx;
760 /* Is the first vpath already selected as catch-basin ? */
761 vpath = &vdev->vpaths[vpath_idx];
762 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
763 /* Add this mac address to this vpath */
764 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
765 return -EPERM;
766 return vpath_idx;
767 }
768
769 /* Select first vpath as catch-basin */
770 vpath_vector = vxge_mBIT(vpath->device_id);
771 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
772 vxge_hw_mgmt_reg_type_mrpcim,
773 0,
774 (ulong)offsetof(
775 struct vxge_hw_mrpcim_reg,
776 rts_mgr_cbasin_cfg),
777 vpath_vector);
778 if (status != VXGE_HW_OK) {
779 vxge_debug_tx(VXGE_ERR,
780 "%s: Unable to set the vpath-%d in catch-basin mode",
781 VXGE_DRIVER_NAME, vpath->device_id);
782 return -EPERM;
783 }
784
785 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
786 return -EPERM;
787
788 return vpath_idx;
789}
790
791/**
792 * vxge_xmit
793 * @skb : the socket buffer containing the Tx data.
794 * @dev : device pointer.
795 *
796 * This function is the Tx entry point of the driver. Neterion NIC supports
797 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000798*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000799static netdev_tx_t
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000800vxge_xmit(struct sk_buff *skb, struct net_device *dev)
801{
802 struct vxge_fifo *fifo = NULL;
803 void *dtr_priv;
804 void *dtr = NULL;
805 struct vxgedev *vdev = NULL;
806 enum vxge_hw_status status;
807 int frg_cnt, first_frg_len;
808 skb_frag_t *frag;
809 int i = 0, j = 0, avail;
810 u64 dma_pointer;
811 struct vxge_tx_priv *txdl_priv = NULL;
812 struct __vxge_hw_fifo *fifo_hw;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000813 int offload_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000814 int vpath_no = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000815
816 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
817 dev->name, __func__, __LINE__);
818
819 /* A buffer with no data will be dropped */
820 if (unlikely(skb->len <= 0)) {
821 vxge_debug_tx(VXGE_ERR,
822 "%s: Buffer has no data..", dev->name);
823 dev_kfree_skb(skb);
824 return NETDEV_TX_OK;
825 }
826
Joe Perches5f54ceb2010-11-15 11:12:30 +0000827 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000828
829 if (unlikely(!is_vxge_card_up(vdev))) {
830 vxge_debug_tx(VXGE_ERR,
831 "%s: vdev not initialized", dev->name);
832 dev_kfree_skb(skb);
833 return NETDEV_TX_OK;
834 }
835
836 if (vdev->config.addr_learn_en) {
837 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
838 if (vpath_no == -EPERM) {
839 vxge_debug_tx(VXGE_ERR,
840 "%s: Failed to store the mac address",
841 dev->name);
842 dev_kfree_skb(skb);
843 return NETDEV_TX_OK;
844 }
845 }
846
847 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
848 vpath_no = skb_get_queue_mapping(skb);
849 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
Jon Mason98f45da2010-07-15 08:47:25 +0000850 vpath_no = vxge_get_vpath_no(vdev, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000851
852 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
853
854 if (vpath_no >= vdev->no_of_vpath)
855 vpath_no = 0;
856
857 fifo = &vdev->vpaths[vpath_no].fifo;
858 fifo_hw = fifo->handle;
859
Jon Mason98f45da2010-07-15 08:47:25 +0000860 if (netif_tx_queue_stopped(fifo->txq))
Jon Masond03848e2010-07-15 08:47:23 +0000861 return NETDEV_TX_BUSY;
Jon Masond03848e2010-07-15 08:47:23 +0000862
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000863 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
864 if (avail == 0) {
865 vxge_debug_tx(VXGE_ERR,
866 "%s: No free TXDs available", dev->name);
867 fifo->stats.txd_not_free++;
Jon Mason98f45da2010-07-15 08:47:25 +0000868 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000869 }
870
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000871 /* Last TXD? Stop tx queue to avoid dropping packets. TX
872 * completion will resume the queue.
873 */
874 if (avail == 1)
Jon Mason98f45da2010-07-15 08:47:25 +0000875 netif_tx_stop_queue(fifo->txq);
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000876
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000877 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
878 if (unlikely(status != VXGE_HW_OK)) {
879 vxge_debug_tx(VXGE_ERR,
880 "%s: Out of descriptors .", dev->name);
881 fifo->stats.txd_out_of_desc++;
Jon Mason98f45da2010-07-15 08:47:25 +0000882 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000883 }
884
885 vxge_debug_tx(VXGE_TRACE,
886 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
887 dev->name, __func__, __LINE__,
888 fifo_hw, dtr, dtr_priv);
889
Jesse Grosseab6d182010-10-20 13:56:03 +0000890 if (vlan_tx_tag_present(skb)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000891 u16 vlan_tag = vlan_tx_tag_get(skb);
892 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
893 }
894
895 first_frg_len = skb_headlen(skb);
896
897 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
898 PCI_DMA_TODEVICE);
899
900 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
901 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000902 fifo->stats.pci_map_fail++;
Jon Mason98f45da2010-07-15 08:47:25 +0000903 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000904 }
905
906 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
907 txdl_priv->skb = skb;
908 txdl_priv->dma_buffers[j] = dma_pointer;
909
910 frg_cnt = skb_shinfo(skb)->nr_frags;
911 vxge_debug_tx(VXGE_TRACE,
912 "%s: %s:%d skb = %p txdl_priv = %p "
913 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
914 __func__, __LINE__, skb, txdl_priv,
915 frg_cnt, (unsigned long long)dma_pointer);
916
917 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
918 first_frg_len);
919
920 frag = &skb_shinfo(skb)->frags[0];
921 for (i = 0; i < frg_cnt; i++) {
922 /* ignore 0 length fragment */
Eric Dumazet9e903e02011-10-18 21:00:24 +0000923 if (!skb_frag_size(frag))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000924 continue;
925
Ian Campbell94d60a72011-10-05 17:35:34 -0400926 dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000927 0, skb_frag_size(frag),
Ian Campbell94d60a72011-10-05 17:35:34 -0400928 DMA_TO_DEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000929
Ian Campbell94d60a72011-10-05 17:35:34 -0400930 if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
Jon Mason98f45da2010-07-15 08:47:25 +0000931 goto _exit2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000932 vxge_debug_tx(VXGE_TRACE,
933 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
934 dev->name, __func__, __LINE__, i,
935 (unsigned long long)dma_pointer);
936
937 txdl_priv->dma_buffers[j] = dma_pointer;
938 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000939 skb_frag_size(frag));
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000940 frag += 1;
941 }
942
943 offload_type = vxge_offload_type(skb);
944
945 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000946 int mss = vxge_tcp_mss(skb);
947 if (mss) {
Jon Mason98f45da2010-07-15 08:47:25 +0000948 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000949 dev->name, __func__, __LINE__, mss);
950 vxge_hw_fifo_txdl_mss_set(dtr, mss);
951 } else {
952 vxge_assert(skb->len <=
953 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
954 vxge_assert(0);
955 goto _exit1;
956 }
957 }
958
959 if (skb->ip_summed == CHECKSUM_PARTIAL)
960 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
961 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
962 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
963 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
964
965 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000966
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000967 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
968 dev->name, __func__, __LINE__);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000969 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000970
Jon Mason98f45da2010-07-15 08:47:25 +0000971_exit2:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000972 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000973_exit1:
974 j = 0;
975 frag = &skb_shinfo(skb)->frags[0];
976
977 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
978 skb_headlen(skb), PCI_DMA_TODEVICE);
979
980 for (; j < i; j++) {
981 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000982 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000983 frag += 1;
984 }
985
986 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Jon Mason98f45da2010-07-15 08:47:25 +0000987_exit0:
988 netif_tx_stop_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000989 dev_kfree_skb(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000990
Patrick McHardy6ed10652009-06-23 06:03:08 +0000991 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000992}
993
994/*
995 * vxge_rx_term
996 *
997 * Function will be called by hw function to abort all outstanding receive
998 * descriptors.
999 */
1000static void
1001vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1002{
1003 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1004 struct vxge_rx_priv *rx_priv =
1005 vxge_hw_ring_rxd_private_get(dtrh);
1006
1007 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1008 ring->ndev->name, __func__, __LINE__);
1009 if (state != VXGE_HW_RXD_STATE_POSTED)
1010 return;
1011
1012 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1013 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1014
1015 dev_kfree_skb(rx_priv->skb);
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +00001016 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001017
1018 vxge_debug_entryexit(VXGE_TRACE,
1019 "%s: %s:%d Exiting...",
1020 ring->ndev->name, __func__, __LINE__);
1021}
1022
1023/*
1024 * vxge_tx_term
1025 *
1026 * Function will be called to abort all outstanding tx descriptors
1027 */
1028static void
1029vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1030{
1031 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1032 skb_frag_t *frag;
1033 int i = 0, j, frg_cnt;
1034 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1035 struct sk_buff *skb = txd_priv->skb;
1036
1037 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1038
1039 if (state != VXGE_HW_TXDL_STATE_POSTED)
1040 return;
1041
1042 /* check skb validity */
1043 vxge_assert(skb);
1044 frg_cnt = skb_shinfo(skb)->nr_frags;
1045 frag = &skb_shinfo(skb)->frags[0];
1046
1047 /* for unfragmented skb */
1048 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1049 skb_headlen(skb), PCI_DMA_TODEVICE);
1050
1051 for (j = 0; j < frg_cnt; j++) {
1052 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +00001053 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001054 frag += 1;
1055 }
1056
1057 dev_kfree_skb(skb);
1058
1059 vxge_debug_entryexit(VXGE_TRACE,
1060 "%s:%d Exiting...", __func__, __LINE__);
1061}
1062
Jon Mason528f7272010-12-10 14:02:56 +00001063static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1064{
1065 struct list_head *entry, *next;
1066 u64 del_mac = 0;
1067 u8 *mac_address = (u8 *) (&del_mac);
1068
1069 /* Copy the mac address to delete from the list */
1070 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1071
1072 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1073 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1074 list_del(entry);
1075 kfree((struct vxge_mac_addrs *)entry);
1076 vpath->mac_addr_cnt--;
1077
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001078 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +00001079 vpath->mcast_addr_cnt--;
1080 return TRUE;
1081 }
1082 }
1083
1084 return FALSE;
1085}
1086
1087/* delete a mac address from DA table */
1088static enum vxge_hw_status
1089vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1090{
1091 enum vxge_hw_status status = VXGE_HW_OK;
1092 struct vxge_vpath *vpath;
1093
1094 vpath = &vdev->vpaths[mac->vpath_no];
1095 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1096 mac->macmask);
1097 if (status != VXGE_HW_OK) {
1098 vxge_debug_init(VXGE_ERR,
1099 "DA config delete entry failed for vpath:%d",
1100 vpath->device_id);
1101 } else
1102 vxge_mac_list_del(vpath, mac);
1103 return status;
1104}
1105
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001106/**
1107 * vxge_set_multicast
1108 * @dev: pointer to the device structure
1109 *
1110 * Entry point for multicast address enable/disable
1111 * This function is a driver entry point which gets called by the kernel
1112 * whenever multicast addresses must be enabled/disabled. This also gets
1113 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1114 * determine, if multicast address must be enabled or if promiscuous mode
1115 * is to be disabled etc.
1116 */
1117static void vxge_set_multicast(struct net_device *dev)
1118{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001119 struct netdev_hw_addr *ha;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001120 struct vxgedev *vdev;
1121 int i, mcast_cnt = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00001122 struct __vxge_hw_device *hldev;
1123 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001124 enum vxge_hw_status status = VXGE_HW_OK;
1125 struct macInfo mac_info;
1126 int vpath_idx = 0;
1127 struct vxge_mac_addrs *mac_entry;
1128 struct list_head *list_head;
1129 struct list_head *entry, *next;
1130 u8 *mac_address = NULL;
1131
1132 vxge_debug_entryexit(VXGE_TRACE,
1133 "%s:%d", __func__, __LINE__);
1134
Joe Perches5f54ceb2010-11-15 11:12:30 +00001135 vdev = netdev_priv(dev);
Joe Perches64699332012-06-04 12:44:16 +00001136 hldev = vdev->devh;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001137
1138 if (unlikely(!is_vxge_card_up(vdev)))
1139 return;
1140
1141 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1142 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001143 vpath = &vdev->vpaths[i];
1144 vxge_assert(vpath->is_open);
1145 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1146 if (status != VXGE_HW_OK)
1147 vxge_debug_init(VXGE_ERR, "failed to enable "
1148 "multicast, status %d", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001149 vdev->all_multi_flg = 1;
1150 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001151 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001152 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001153 vpath = &vdev->vpaths[i];
1154 vxge_assert(vpath->is_open);
1155 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1156 if (status != VXGE_HW_OK)
1157 vxge_debug_init(VXGE_ERR, "failed to disable "
1158 "multicast, status %d", status);
1159 vdev->all_multi_flg = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001160 }
1161 }
1162
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001163
1164 if (!vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001165 for (i = 0; i < vdev->no_of_vpath; i++) {
1166 vpath = &vdev->vpaths[i];
1167 vxge_assert(vpath->is_open);
1168
1169 if (dev->flags & IFF_PROMISC)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001170 status = vxge_hw_vpath_promisc_enable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001171 vpath->handle);
1172 else
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001173 status = vxge_hw_vpath_promisc_disable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001174 vpath->handle);
1175 if (status != VXGE_HW_OK)
1176 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1177 ", status %d", dev->flags&IFF_PROMISC ?
1178 "enable" : "disable", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001179 }
1180 }
1181
1182 memset(&mac_info, 0, sizeof(struct macInfo));
1183 /* Update individual M_CAST address list */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001184 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001185 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1186 list_head = &vdev->vpaths[0].mac_addr_list;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001187 if ((netdev_mc_count(dev) +
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001188 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1189 vdev->vpaths[0].max_mac_addr_cnt)
1190 goto _set_all_mcast;
1191
1192 /* Delete previous MC's */
1193 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001194 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001195 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001196 /* Copy the mac address to delete */
1197 mac_address = (u8 *)&mac_entry->macaddr;
1198 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1199
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001200 if (is_multicast_ether_addr(mac_info.macaddr)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001201 for (vpath_idx = 0; vpath_idx <
1202 vdev->no_of_vpath;
1203 vpath_idx++) {
1204 mac_info.vpath_no = vpath_idx;
1205 status = vxge_del_mac_addr(
1206 vdev,
1207 &mac_info);
1208 }
1209 }
1210 }
1211 }
1212
1213 /* Add new ones */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001214 netdev_for_each_mc_addr(ha, dev) {
1215 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001216 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1217 vpath_idx++) {
1218 mac_info.vpath_no = vpath_idx;
1219 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1220 status = vxge_add_mac_addr(vdev, &mac_info);
1221 if (status != VXGE_HW_OK) {
1222 vxge_debug_init(VXGE_ERR,
1223 "%s:%d Setting individual"
1224 "multicast address failed",
1225 __func__, __LINE__);
1226 goto _set_all_mcast;
1227 }
1228 }
1229 }
1230
1231 return;
1232_set_all_mcast:
1233 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1234 /* Delete previous MC's */
1235 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001236 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001237 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001238 /* Copy the mac address to delete */
1239 mac_address = (u8 *)&mac_entry->macaddr;
1240 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1241
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001242 if (is_multicast_ether_addr(mac_info.macaddr))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001243 break;
1244 }
1245
1246 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1247 vpath_idx++) {
1248 mac_info.vpath_no = vpath_idx;
1249 status = vxge_del_mac_addr(vdev, &mac_info);
1250 }
1251 }
1252
1253 /* Enable all multicast */
1254 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001255 vpath = &vdev->vpaths[i];
1256 vxge_assert(vpath->is_open);
1257
1258 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001259 if (status != VXGE_HW_OK) {
1260 vxge_debug_init(VXGE_ERR,
1261 "%s:%d Enabling all multicasts failed",
1262 __func__, __LINE__);
1263 }
1264 vdev->all_multi_flg = 1;
1265 }
1266 dev->flags |= IFF_ALLMULTI;
1267 }
1268
1269 vxge_debug_entryexit(VXGE_TRACE,
1270 "%s:%d Exiting...", __func__, __LINE__);
1271}
1272
1273/**
1274 * vxge_set_mac_addr
1275 * @dev: pointer to the device structure
1276 *
1277 * Update entry "0" (default MAC addr)
1278 */
1279static int vxge_set_mac_addr(struct net_device *dev, void *p)
1280{
1281 struct sockaddr *addr = p;
1282 struct vxgedev *vdev;
Jon Mason2c913082010-11-11 04:26:03 +00001283 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001284 enum vxge_hw_status status = VXGE_HW_OK;
1285 struct macInfo mac_info_new, mac_info_old;
1286 int vpath_idx = 0;
1287
1288 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1289
Joe Perches5f54ceb2010-11-15 11:12:30 +00001290 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001291 hldev = vdev->devh;
1292
1293 if (!is_valid_ether_addr(addr->sa_data))
1294 return -EINVAL;
1295
1296 memset(&mac_info_new, 0, sizeof(struct macInfo));
1297 memset(&mac_info_old, 0, sizeof(struct macInfo));
1298
1299 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1300 __func__, __LINE__);
1301
1302 /* Get the old address */
1303 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1304
1305 /* Copy the new address */
1306 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1307
1308 /* First delete the old mac address from all the vpaths
1309 as we can't specify the index while adding new mac address */
1310 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1311 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1312 if (!vpath->is_open) {
1313 /* This can happen when this interface is added/removed
1314 to the bonding interface. Delete this station address
1315 from the linked list */
1316 vxge_mac_list_del(vpath, &mac_info_old);
1317
1318 /* Add this new address to the linked list
1319 for later restoring */
1320 vxge_mac_list_add(vpath, &mac_info_new);
1321
1322 continue;
1323 }
1324 /* Delete the station address */
1325 mac_info_old.vpath_no = vpath_idx;
1326 status = vxge_del_mac_addr(vdev, &mac_info_old);
1327 }
1328
1329 if (unlikely(!is_vxge_card_up(vdev))) {
1330 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1331 return VXGE_HW_OK;
1332 }
1333
1334 /* Set this mac address to all the vpaths */
1335 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1336 mac_info_new.vpath_no = vpath_idx;
1337 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1338 status = vxge_add_mac_addr(vdev, &mac_info_new);
1339 if (status != VXGE_HW_OK)
1340 return -EINVAL;
1341 }
1342
1343 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1344
1345 return status;
1346}
1347
1348/*
1349 * vxge_vpath_intr_enable
1350 * @vdev: pointer to vdev
1351 * @vp_id: vpath for which to enable the interrupts
1352 *
1353 * Enables the interrupts for the vpath
1354*/
stephen hemminger42821a52010-10-21 07:50:53 +00001355static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001356{
1357 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001358 int msix_id = 0;
1359 int tim_msix_id[4] = {0, 1, 0, 0};
1360 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001361
1362 vxge_hw_vpath_intr_enable(vpath->handle);
1363
1364 if (vdev->config.intr_type == INTA)
1365 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1366 else {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001367 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1368 alarm_msix_id);
1369
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001370 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001371 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1372 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1373
1374 /* enable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001375 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1376 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1377 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001378 }
1379}
1380
1381/*
1382 * vxge_vpath_intr_disable
1383 * @vdev: pointer to vdev
1384 * @vp_id: vpath for which to disable the interrupts
1385 *
1386 * Disables the interrupts for the vpath
1387*/
stephen hemminger42821a52010-10-21 07:50:53 +00001388static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001389{
1390 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Jon Mason4d2a5b42010-11-11 04:25:54 +00001391 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001392 int msix_id;
1393
Joe Perchesd8ee7072010-11-15 10:13:58 +00001394 hldev = pci_get_drvdata(vdev->pdev);
Jon Mason4d2a5b42010-11-11 04:25:54 +00001395
1396 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1397
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001398 vxge_hw_vpath_intr_disable(vpath->handle);
1399
1400 if (vdev->config.intr_type == INTA)
1401 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1402 else {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001403 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001404 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1405 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1406
1407 /* disable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001408 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1409 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001410 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1411 }
1412}
1413
Jon Mason528f7272010-12-10 14:02:56 +00001414/* list all mac addresses from DA table */
1415static enum vxge_hw_status
1416vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1417{
1418 enum vxge_hw_status status = VXGE_HW_OK;
1419 unsigned char macmask[ETH_ALEN];
1420 unsigned char macaddr[ETH_ALEN];
1421
1422 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1423 macaddr, macmask);
1424 if (status != VXGE_HW_OK) {
1425 vxge_debug_init(VXGE_ERR,
1426 "DA config list entry failed for vpath:%d",
1427 vpath->device_id);
1428 return status;
1429 }
1430
dingtianhongf75d1912013-12-30 15:41:02 +08001431 while (!ether_addr_equal(mac->macaddr, macaddr)) {
Jon Mason528f7272010-12-10 14:02:56 +00001432 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1433 macaddr, macmask);
1434 if (status != VXGE_HW_OK)
1435 break;
1436 }
1437
1438 return status;
1439}
1440
1441/* Store all mac addresses from the list to the DA table */
1442static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1443{
1444 enum vxge_hw_status status = VXGE_HW_OK;
1445 struct macInfo mac_info;
1446 u8 *mac_address = NULL;
1447 struct list_head *entry, *next;
1448
1449 memset(&mac_info, 0, sizeof(struct macInfo));
1450
1451 if (vpath->is_open) {
1452 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1453 mac_address =
1454 (u8 *)&
1455 ((struct vxge_mac_addrs *)entry)->macaddr;
1456 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1457 ((struct vxge_mac_addrs *)entry)->state =
1458 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1459 /* does this mac address already exist in da table? */
1460 status = vxge_search_mac_addr_in_da_table(vpath,
1461 &mac_info);
1462 if (status != VXGE_HW_OK) {
1463 /* Add this mac address to the DA table */
1464 status = vxge_hw_vpath_mac_addr_add(
1465 vpath->handle, mac_info.macaddr,
1466 mac_info.macmask,
1467 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1468 if (status != VXGE_HW_OK) {
1469 vxge_debug_init(VXGE_ERR,
1470 "DA add entry failed for vpath:%d",
1471 vpath->device_id);
1472 ((struct vxge_mac_addrs *)entry)->state
1473 = VXGE_LL_MAC_ADDR_IN_LIST;
1474 }
1475 }
1476 }
1477 }
1478
1479 return status;
1480}
1481
1482/* Store all vlan ids from the list to the vid table */
1483static enum vxge_hw_status
1484vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1485{
1486 enum vxge_hw_status status = VXGE_HW_OK;
1487 struct vxgedev *vdev = vpath->vdev;
1488 u16 vid;
1489
Jiri Pirko53515732011-07-20 04:54:40 +00001490 if (!vpath->is_open)
1491 return status;
Jon Mason528f7272010-12-10 14:02:56 +00001492
Jiri Pirko53515732011-07-20 04:54:40 +00001493 for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
1494 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
Jon Mason528f7272010-12-10 14:02:56 +00001495
1496 return status;
1497}
1498
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001499/*
1500 * vxge_reset_vpath
1501 * @vdev: pointer to vdev
1502 * @vp_id: vpath to reset
1503 *
1504 * Resets the vpath
1505*/
1506static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1507{
1508 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001509 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001510 int ret = 0;
1511
1512 /* check if device is down already */
1513 if (unlikely(!is_vxge_card_up(vdev)))
1514 return 0;
1515
1516 /* is device reset already scheduled */
1517 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1518 return 0;
1519
Jon Mason7adf7d12010-07-15 08:47:24 +00001520 if (vpath->handle) {
1521 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001522 if (is_vxge_card_up(vdev) &&
Jon Mason7adf7d12010-07-15 08:47:24 +00001523 vxge_hw_vpath_recover_from_reset(vpath->handle)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001524 != VXGE_HW_OK) {
1525 vxge_debug_init(VXGE_ERR,
1526 "vxge_hw_vpath_recover_from_reset"
1527 "failed for vpath:%d", vp_id);
1528 return status;
1529 }
1530 } else {
1531 vxge_debug_init(VXGE_ERR,
1532 "vxge_hw_vpath_reset failed for"
1533 "vpath:%d", vp_id);
1534 return status;
1535 }
1536 } else
1537 return VXGE_HW_FAIL;
1538
Jon Mason7adf7d12010-07-15 08:47:24 +00001539 vxge_restore_vpath_mac_addr(vpath);
1540 vxge_restore_vpath_vid_table(vpath);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001541
1542 /* Enable all broadcast */
Jon Mason7adf7d12010-07-15 08:47:24 +00001543 vxge_hw_vpath_bcast_enable(vpath->handle);
1544
1545 /* Enable all multicast */
1546 if (vdev->all_multi_flg) {
1547 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1548 if (status != VXGE_HW_OK)
1549 vxge_debug_init(VXGE_ERR,
1550 "%s:%d Enabling multicast failed",
1551 __func__, __LINE__);
1552 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001553
1554 /* Enable the interrupts */
1555 vxge_vpath_intr_enable(vdev, vp_id);
1556
1557 smp_wmb();
1558
1559 /* Enable the flow of traffic through the vpath */
Jon Mason7adf7d12010-07-15 08:47:24 +00001560 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001561
1562 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00001563 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1564 vpath->ring.last_status = VXGE_HW_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001565
1566 /* Vpath reset done */
1567 clear_bit(vp_id, &vdev->vp_reset);
1568
1569 /* Start the vpath queue */
Jon Mason98f45da2010-07-15 08:47:25 +00001570 if (netif_tx_queue_stopped(vpath->fifo.txq))
1571 netif_tx_wake_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001572
1573 return ret;
1574}
1575
Jon Mason16fded72011-01-18 15:02:21 +00001576/* Configure CI */
1577static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1578{
1579 int i = 0;
1580
1581 /* Enable CI for RTI */
1582 if (vdev->config.intr_type == MSI_X) {
1583 for (i = 0; i < vdev->no_of_vpath; i++) {
1584 struct __vxge_hw_ring *hw_ring;
1585
1586 hw_ring = vdev->vpaths[i].ring.handle;
1587 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1588 }
1589 }
1590
1591 /* Enable CI for TTI */
1592 for (i = 0; i < vdev->no_of_vpath; i++) {
1593 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1594 vxge_hw_vpath_tti_ci_set(hw_fifo);
1595 /*
1596 * For Inta (with or without napi), Set CI ON for only one
1597 * vpath. (Have only one free running timer).
1598 */
1599 if ((vdev->config.intr_type == INTA) && (i == 0))
1600 break;
1601 }
1602
1603 return;
1604}
1605
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001606static int do_vxge_reset(struct vxgedev *vdev, int event)
1607{
1608 enum vxge_hw_status status;
1609 int ret = 0, vp_id, i;
1610
1611 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1612
1613 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1614 /* check if device is down already */
1615 if (unlikely(!is_vxge_card_up(vdev)))
1616 return 0;
1617
1618 /* is reset already scheduled */
1619 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1620 return 0;
1621 }
1622
1623 if (event == VXGE_LL_FULL_RESET) {
Jon Mason2e41f642010-12-10 14:02:59 +00001624 netif_carrier_off(vdev->ndev);
1625
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001626 /* wait for all the vpath reset to complete */
1627 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1628 while (test_bit(vp_id, &vdev->vp_reset))
1629 msleep(50);
1630 }
1631
Jon Mason2e41f642010-12-10 14:02:59 +00001632 netif_carrier_on(vdev->ndev);
1633
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001634 /* if execution mode is set to debug, don't reset the adapter */
1635 if (unlikely(vdev->exec_mode)) {
1636 vxge_debug_init(VXGE_ERR,
1637 "%s: execution mode is debug, returning..",
1638 vdev->ndev->name);
Jon Mason7adf7d12010-07-15 08:47:24 +00001639 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1640 netif_tx_stop_all_queues(vdev->ndev);
1641 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001642 }
1643 }
1644
1645 if (event == VXGE_LL_FULL_RESET) {
Jon Mason4d2a5b42010-11-11 04:25:54 +00001646 vxge_hw_device_wait_receive_idle(vdev->devh);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001647 vxge_hw_device_intr_disable(vdev->devh);
1648
1649 switch (vdev->cric_err_event) {
1650 case VXGE_HW_EVENT_UNKNOWN:
Jon Masond03848e2010-07-15 08:47:23 +00001651 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001652 vxge_debug_init(VXGE_ERR,
1653 "fatal: %s: Disabling device due to"
1654 "unknown error",
1655 vdev->ndev->name);
1656 ret = -EPERM;
1657 goto out;
1658 case VXGE_HW_EVENT_RESET_START:
1659 break;
1660 case VXGE_HW_EVENT_RESET_COMPLETE:
1661 case VXGE_HW_EVENT_LINK_DOWN:
1662 case VXGE_HW_EVENT_LINK_UP:
1663 case VXGE_HW_EVENT_ALARM_CLEARED:
1664 case VXGE_HW_EVENT_ECCERR:
1665 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1666 ret = -EPERM;
1667 goto out;
1668 case VXGE_HW_EVENT_FIFO_ERR:
1669 case VXGE_HW_EVENT_VPATH_ERR:
1670 break;
1671 case VXGE_HW_EVENT_CRITICAL_ERR:
Jon Masond03848e2010-07-15 08:47:23 +00001672 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001673 vxge_debug_init(VXGE_ERR,
1674 "fatal: %s: Disabling device due to"
1675 "serious error",
1676 vdev->ndev->name);
1677 /* SOP or device reset required */
1678 /* This event is not currently used */
1679 ret = -EPERM;
1680 goto out;
1681 case VXGE_HW_EVENT_SERR:
Jon Masond03848e2010-07-15 08:47:23 +00001682 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001683 vxge_debug_init(VXGE_ERR,
1684 "fatal: %s: Disabling device due to"
1685 "serious error",
1686 vdev->ndev->name);
1687 ret = -EPERM;
1688 goto out;
1689 case VXGE_HW_EVENT_SRPCIM_SERR:
1690 case VXGE_HW_EVENT_MRPCIM_SERR:
1691 ret = -EPERM;
1692 goto out;
1693 case VXGE_HW_EVENT_SLOT_FREEZE:
Jon Masond03848e2010-07-15 08:47:23 +00001694 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001695 vxge_debug_init(VXGE_ERR,
1696 "fatal: %s: Disabling device due to"
1697 "slot freeze",
1698 vdev->ndev->name);
1699 ret = -EPERM;
1700 goto out;
1701 default:
1702 break;
1703
1704 }
1705 }
1706
1707 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
Jon Masond03848e2010-07-15 08:47:23 +00001708 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001709
1710 if (event == VXGE_LL_FULL_RESET) {
1711 status = vxge_reset_all_vpaths(vdev);
1712 if (status != VXGE_HW_OK) {
1713 vxge_debug_init(VXGE_ERR,
1714 "fatal: %s: can not reset vpaths",
1715 vdev->ndev->name);
1716 ret = -EPERM;
1717 goto out;
1718 }
1719 }
1720
1721 if (event == VXGE_LL_COMPL_RESET) {
1722 for (i = 0; i < vdev->no_of_vpath; i++)
1723 if (vdev->vpaths[i].handle) {
1724 if (vxge_hw_vpath_recover_from_reset(
1725 vdev->vpaths[i].handle)
1726 != VXGE_HW_OK) {
1727 vxge_debug_init(VXGE_ERR,
1728 "vxge_hw_vpath_recover_"
1729 "from_reset failed for vpath: "
1730 "%d", i);
1731 ret = -EPERM;
1732 goto out;
1733 }
1734 } else {
1735 vxge_debug_init(VXGE_ERR,
1736 "vxge_hw_vpath_reset failed for "
1737 "vpath:%d", i);
1738 ret = -EPERM;
1739 goto out;
1740 }
1741 }
1742
1743 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1744 /* Reprogram the DA table with populated mac addresses */
1745 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1746 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1747 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1748 }
1749
1750 /* enable vpath interrupts */
1751 for (i = 0; i < vdev->no_of_vpath; i++)
1752 vxge_vpath_intr_enable(vdev, i);
1753
1754 vxge_hw_device_intr_enable(vdev->devh);
1755
1756 smp_wmb();
1757
1758 /* Indicate card up */
1759 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1760
1761 /* Get the traffic to flow through the vpaths */
1762 for (i = 0; i < vdev->no_of_vpath; i++) {
1763 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1764 smp_wmb();
1765 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1766 }
1767
Jon Masond03848e2010-07-15 08:47:23 +00001768 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001769 }
1770
Jon Mason16fded72011-01-18 15:02:21 +00001771 /* configure CI */
1772 vxge_config_ci_for_tti_rti(vdev);
1773
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001774out:
1775 vxge_debug_entryexit(VXGE_TRACE,
1776 "%s:%d Exiting...", __func__, __LINE__);
1777
1778 /* Indicate reset done */
1779 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1780 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1781 return ret;
1782}
1783
1784/*
1785 * vxge_reset
1786 * @vdev: pointer to ll device
1787 *
1788 * driver may reset the chip on events of serr, eccerr, etc
1789 */
Jon Mason2e41f642010-12-10 14:02:59 +00001790static void vxge_reset(struct work_struct *work)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001791{
Jon Mason2e41f642010-12-10 14:02:59 +00001792 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1793
1794 if (!netif_running(vdev->ndev))
1795 return;
1796
1797 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001798}
1799
1800/**
1801 * vxge_poll - Receive handler when Receive Polling is used.
1802 * @dev: pointer to the device structure.
1803 * @budget: Number of packets budgeted to be processed in this iteration.
1804 *
1805 * This function comes into picture only if Receive side is being handled
1806 * through polling (called NAPI in linux). It mostly does what the normal
1807 * Rx interrupt handler does in terms of descriptor and packet processing
1808 * but not in an interrupt context. Also it will process a specified number
1809 * of packets at most in one iteration. This value is passed down by the
1810 * kernel as the function argument 'budget'.
1811 */
1812static int vxge_poll_msix(struct napi_struct *napi, int budget)
1813{
Jon Mason16fded72011-01-18 15:02:21 +00001814 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1815 int pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001816 int budget_org = budget;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001817
Jon Mason16fded72011-01-18 15:02:21 +00001818 ring->budget = budget;
1819 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001820 vxge_hw_vpath_poll_rx(ring->handle);
Jon Mason16fded72011-01-18 15:02:21 +00001821 pkts_processed = ring->pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001822
1823 if (ring->pkts_processed < budget_org) {
1824 napi_complete(napi);
Jon Mason16fded72011-01-18 15:02:21 +00001825
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001826 /* Re enable the Rx interrupts for the vpath */
1827 vxge_hw_channel_msix_unmask(
1828 (struct __vxge_hw_channel *)ring->handle,
1829 ring->rx_vector_no);
Jon Mason16fded72011-01-18 15:02:21 +00001830 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001831 }
1832
Jon Mason16fded72011-01-18 15:02:21 +00001833 /* We are copying and returning the local variable, in case if after
1834 * clearing the msix interrupt above, if the interrupt fires right
1835 * away which can preempt this NAPI thread */
1836 return pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001837}
1838
1839static int vxge_poll_inta(struct napi_struct *napi, int budget)
1840{
1841 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1842 int pkts_processed = 0;
1843 int i;
1844 int budget_org = budget;
1845 struct vxge_ring *ring;
1846
Joe Perchesd8ee7072010-11-15 10:13:58 +00001847 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001848
1849 for (i = 0; i < vdev->no_of_vpath; i++) {
1850 ring = &vdev->vpaths[i].ring;
1851 ring->budget = budget;
Jon Mason16fded72011-01-18 15:02:21 +00001852 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001853 vxge_hw_vpath_poll_rx(ring->handle);
1854 pkts_processed += ring->pkts_processed;
1855 budget -= ring->pkts_processed;
1856 if (budget <= 0)
1857 break;
1858 }
1859
1860 VXGE_COMPLETE_ALL_TX(vdev);
1861
1862 if (pkts_processed < budget_org) {
1863 napi_complete(napi);
1864 /* Re enable the Rx interrupts for the ring */
1865 vxge_hw_device_unmask_all(hldev);
1866 vxge_hw_device_flush_io(hldev);
1867 }
1868
1869 return pkts_processed;
1870}
1871
1872#ifdef CONFIG_NET_POLL_CONTROLLER
1873/**
1874 * vxge_netpoll - netpoll event handler entry point
1875 * @dev : pointer to the device structure.
1876 * Description:
1877 * This function will be called by upper layer to check for events on the
1878 * interface in situations where interrupts are disabled. It is used for
1879 * specific in-kernel networking tasks, such as remote consoles and kernel
1880 * debugging over the network (example netdump in RedHat).
1881 */
1882static void vxge_netpoll(struct net_device *dev)
1883{
Francois Romieu32e819e2012-03-09 19:37:55 +01001884 struct vxgedev *vdev = netdev_priv(dev);
1885 struct pci_dev *pdev = vdev->pdev;
1886 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
1887 const int irq = pdev->irq;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001888
1889 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1890
Francois Romieu32e819e2012-03-09 19:37:55 +01001891 if (pci_channel_offline(pdev))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001892 return;
1893
Francois Romieu32e819e2012-03-09 19:37:55 +01001894 disable_irq(irq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001895 vxge_hw_device_clear_tx_rx(hldev);
1896
1897 vxge_hw_device_clear_tx_rx(hldev);
1898 VXGE_COMPLETE_ALL_RX(vdev);
1899 VXGE_COMPLETE_ALL_TX(vdev);
1900
Francois Romieu32e819e2012-03-09 19:37:55 +01001901 enable_irq(irq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001902
1903 vxge_debug_entryexit(VXGE_TRACE,
1904 "%s:%d Exiting...", __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001905}
1906#endif
1907
1908/* RTH configuration */
1909static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1910{
1911 enum vxge_hw_status status = VXGE_HW_OK;
1912 struct vxge_hw_rth_hash_types hash_types;
1913 u8 itable[256] = {0}; /* indirection table */
1914 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1915 int index;
1916
1917 /*
1918 * Filling
1919 * - itable with bucket numbers
1920 * - mtable with bucket-to-vpath mapping
1921 */
1922 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1923 itable[index] = index;
1924 mtable[index] = index % vdev->no_of_vpath;
1925 }
1926
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001927 /* set indirection table, bucket-to-vpath mapping */
1928 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1929 vdev->no_of_vpath,
1930 mtable, itable,
1931 vdev->config.rth_bkt_sz);
1932 if (status != VXGE_HW_OK) {
1933 vxge_debug_init(VXGE_ERR,
1934 "RTH indirection table configuration failed "
1935 "for vpath:%d", vdev->vpaths[0].device_id);
1936 return status;
1937 }
1938
Jon Mason47f01db2010-11-11 04:25:53 +00001939 /* Fill RTH hash types */
1940 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1941 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1942 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1943 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1944 hash_types.hash_type_tcpipv6ex_en =
1945 vdev->config.rth_hash_type_tcpipv6ex;
1946 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1947
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001948 /*
Jon Mason47f01db2010-11-11 04:25:53 +00001949 * Because the itable_set() method uses the active_table field
1950 * for the target virtual path the RTH config should be updated
1951 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1952 * when steering frames.
1953 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001954 for (index = 0; index < vdev->no_of_vpath; index++) {
1955 status = vxge_hw_vpath_rts_rth_set(
1956 vdev->vpaths[index].handle,
1957 vdev->config.rth_algorithm,
1958 &hash_types,
1959 vdev->config.rth_bkt_sz);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001960 if (status != VXGE_HW_OK) {
1961 vxge_debug_init(VXGE_ERR,
1962 "RTH configuration failed for vpath:%d",
1963 vdev->vpaths[index].device_id);
1964 return status;
1965 }
1966 }
1967
1968 return status;
1969}
1970
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001971/* reset vpaths */
stephen hemmingere40c10f2014-01-15 08:28:54 -08001972static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001973{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001974 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001975 struct vxge_vpath *vpath;
1976 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001977
Jon Mason7adf7d12010-07-15 08:47:24 +00001978 for (i = 0; i < vdev->no_of_vpath; i++) {
1979 vpath = &vdev->vpaths[i];
1980 if (vpath->handle) {
1981 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001982 if (is_vxge_card_up(vdev) &&
1983 vxge_hw_vpath_recover_from_reset(
Jon Mason7adf7d12010-07-15 08:47:24 +00001984 vpath->handle) != VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001985 vxge_debug_init(VXGE_ERR,
1986 "vxge_hw_vpath_recover_"
1987 "from_reset failed for vpath: "
1988 "%d", i);
1989 return status;
1990 }
1991 } else {
1992 vxge_debug_init(VXGE_ERR,
1993 "vxge_hw_vpath_reset failed for "
1994 "vpath:%d", i);
1995 return status;
1996 }
1997 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001998 }
1999
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002000 return status;
2001}
2002
2003/* close vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002004static void vxge_close_vpaths(struct vxgedev *vdev, int index)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002005{
Jon Mason7adf7d12010-07-15 08:47:24 +00002006 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002007 int i;
Jon Mason7adf7d12010-07-15 08:47:24 +00002008
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002009 for (i = index; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002010 vpath = &vdev->vpaths[i];
2011
2012 if (vpath->handle && vpath->is_open) {
2013 vxge_hw_vpath_close(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002014 vdev->stats.vpaths_open--;
2015 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002016 vpath->is_open = 0;
2017 vpath->handle = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002018 }
2019}
2020
2021/* open vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002022static int vxge_open_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002023{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002024 struct vxge_hw_vpath_attr attr;
Jon Mason7adf7d12010-07-15 08:47:24 +00002025 enum vxge_hw_status status;
2026 struct vxge_vpath *vpath;
2027 u32 vp_id = 0;
2028 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002029
2030 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002031 vpath = &vdev->vpaths[i];
Jon Mason7adf7d12010-07-15 08:47:24 +00002032 vxge_assert(vpath->is_configured);
Jon Masone7935c92010-11-11 04:26:00 +00002033
2034 if (!vdev->titan1) {
2035 struct vxge_hw_vp_config *vcfg;
2036 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2037
2038 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2039 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2040 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2041 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2042 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2043 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2044 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2045 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2046 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2047 }
2048
Jon Mason7adf7d12010-07-15 08:47:24 +00002049 attr.vp_id = vpath->device_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002050 attr.fifo_attr.callback = vxge_xmit_compl;
2051 attr.fifo_attr.txdl_term = vxge_tx_term;
2052 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002053 attr.fifo_attr.userdata = &vpath->fifo;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002054
2055 attr.ring_attr.callback = vxge_rx_1b_compl;
2056 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2057 attr.ring_attr.rxd_term = vxge_rx_term;
2058 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002059 attr.ring_attr.userdata = &vpath->ring;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002060
Jon Mason7adf7d12010-07-15 08:47:24 +00002061 vpath->ring.ndev = vdev->ndev;
2062 vpath->ring.pdev = vdev->pdev;
Jon Mason528f7272010-12-10 14:02:56 +00002063
Jon Mason7adf7d12010-07-15 08:47:24 +00002064 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002065 if (status == VXGE_HW_OK) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002066 vpath->fifo.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002067 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002068 vpath->ring.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002069 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002070 vpath->fifo.tx_steering_type =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002071 vdev->config.tx_steering_type;
Jon Mason7adf7d12010-07-15 08:47:24 +00002072 vpath->fifo.ndev = vdev->ndev;
2073 vpath->fifo.pdev = vdev->pdev;
John Stultz827da442013-10-07 15:51:58 -07002074
2075 u64_stats_init(&vpath->fifo.stats.syncp);
2076 u64_stats_init(&vpath->ring.stats.syncp);
2077
Jon Mason98f45da2010-07-15 08:47:25 +00002078 if (vdev->config.tx_steering_type)
2079 vpath->fifo.txq =
2080 netdev_get_tx_queue(vdev->ndev, i);
2081 else
2082 vpath->fifo.txq =
2083 netdev_get_tx_queue(vdev->ndev, 0);
Jon Mason7adf7d12010-07-15 08:47:24 +00002084 vpath->fifo.indicate_max_pkts =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002085 vdev->config.fifo_indicate_max_pkts;
Jon Mason16fded72011-01-18 15:02:21 +00002086 vpath->fifo.tx_vector_no = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00002087 vpath->ring.rx_vector_no = 0;
Jon Masonb81b3732010-11-11 04:25:58 +00002088 vpath->ring.rx_hwts = vdev->rx_hwts;
Jon Mason7adf7d12010-07-15 08:47:24 +00002089 vpath->is_open = 1;
2090 vdev->vp_handles[i] = vpath->handle;
Jon Mason7adf7d12010-07-15 08:47:24 +00002091 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002092 vdev->stats.vpaths_open++;
2093 } else {
2094 vdev->stats.vpath_open_fail++;
Jon Mason528f7272010-12-10 14:02:56 +00002095 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2096 "open with status: %d",
2097 vdev->ndev->name, vpath->device_id,
2098 status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002099 vxge_close_vpaths(vdev, 0);
2100 return -EPERM;
2101 }
2102
Jon Mason7adf7d12010-07-15 08:47:24 +00002103 vp_id = vpath->handle->vpath->vp_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002104 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2105 }
Jon Mason528f7272010-12-10 14:02:56 +00002106
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002107 return VXGE_HW_OK;
2108}
2109
Jon Mason16fded72011-01-18 15:02:21 +00002110/**
2111 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2112 * if the interrupts are not within a range
2113 * @fifo: pointer to transmit fifo structure
2114 * Description: The function changes boundary timer and restriction timer
2115 * value depends on the traffic
2116 * Return Value: None
2117 */
2118static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2119{
2120 fifo->interrupt_count++;
2121 if (jiffies > fifo->jiffies + HZ / 100) {
2122 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2123
2124 fifo->jiffies = jiffies;
2125 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2126 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2127 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2128 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2129 } else if (hw_fifo->rtimer != 0) {
2130 hw_fifo->rtimer = 0;
2131 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2132 }
2133 fifo->interrupt_count = 0;
2134 }
2135}
2136
2137/**
2138 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2139 * if the interrupts are not within a range
2140 * @ring: pointer to receive ring structure
2141 * Description: The function increases of decreases the packet counts within
2142 * the ranges of traffic utilization, if the interrupts due to this ring are
2143 * not within a fixed range.
2144 * Return Value: Nothing
2145 */
2146static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2147{
2148 ring->interrupt_count++;
2149 if (jiffies > ring->jiffies + HZ / 100) {
2150 struct __vxge_hw_ring *hw_ring = ring->handle;
2151
2152 ring->jiffies = jiffies;
2153 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2154 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2155 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2156 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2157 } else if (hw_ring->rtimer != 0) {
2158 hw_ring->rtimer = 0;
2159 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2160 }
2161 ring->interrupt_count = 0;
2162 }
2163}
2164
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002165/*
2166 * vxge_isr_napi
2167 * @irq: the irq of the device.
2168 * @dev_id: a void pointer to the hldev structure of the Titan device
2169 * @ptregs: pointer to the registers pushed on the stack.
2170 *
2171 * This function is the ISR handler of the device when napi is enabled. It
2172 * identifies the reason for the interrupt and calls the relevant service
2173 * routines.
2174 */
2175static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2176{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002177 struct net_device *dev;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002178 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002179 u64 reason;
2180 enum vxge_hw_status status;
Jon Mason2c913082010-11-11 04:26:03 +00002181 struct vxgedev *vdev = (struct vxgedev *)dev_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002182
2183 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2184
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002185 dev = vdev->ndev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002186 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002187
2188 if (pci_channel_offline(vdev->pdev))
2189 return IRQ_NONE;
2190
2191 if (unlikely(!is_vxge_card_up(vdev)))
Jon Mason4d2a5b42010-11-11 04:25:54 +00002192 return IRQ_HANDLED;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002193
Jon Mason528f7272010-12-10 14:02:56 +00002194 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002195 if (status == VXGE_HW_OK) {
2196 vxge_hw_device_mask_all(hldev);
2197
2198 if (reason &
2199 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2200 vdev->vpaths_deployed >>
2201 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2202
2203 vxge_hw_device_clear_tx_rx(hldev);
2204 napi_schedule(&vdev->napi);
2205 vxge_debug_intr(VXGE_TRACE,
2206 "%s:%d Exiting...", __func__, __LINE__);
2207 return IRQ_HANDLED;
2208 } else
2209 vxge_hw_device_unmask_all(hldev);
2210 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2211 (status == VXGE_HW_ERR_CRITICAL) ||
2212 (status == VXGE_HW_ERR_FIFO))) {
2213 vxge_hw_device_mask_all(hldev);
2214 vxge_hw_device_flush_io(hldev);
2215 return IRQ_HANDLED;
2216 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2217 return IRQ_HANDLED;
2218
2219 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2220 return IRQ_NONE;
2221}
2222
2223#ifdef CONFIG_PCI_MSI
2224
Jon Mason16fded72011-01-18 15:02:21 +00002225static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002226{
2227 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2228
Jon Mason16fded72011-01-18 15:02:21 +00002229 adaptive_coalesce_tx_interrupts(fifo);
2230
2231 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2232 fifo->tx_vector_no);
2233
2234 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2235 fifo->tx_vector_no);
2236
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002237 VXGE_COMPLETE_VPATH_TX(fifo);
2238
Jon Mason16fded72011-01-18 15:02:21 +00002239 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2240 fifo->tx_vector_no);
2241
2242 mmiowb();
2243
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002244 return IRQ_HANDLED;
2245}
2246
Jon Mason16fded72011-01-18 15:02:21 +00002247static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002248{
2249 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2250
Jon Mason16fded72011-01-18 15:02:21 +00002251 adaptive_coalesce_rx_interrupts(ring);
2252
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002253 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
Jon Mason16fded72011-01-18 15:02:21 +00002254 ring->rx_vector_no);
2255
2256 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2257 ring->rx_vector_no);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002258
2259 napi_schedule(&ring->napi);
2260 return IRQ_HANDLED;
2261}
2262
2263static irqreturn_t
2264vxge_alarm_msix_handle(int irq, void *dev_id)
2265{
2266 int i;
2267 enum vxge_hw_status status;
2268 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2269 struct vxgedev *vdev = vpath->vdev;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002270 int msix_id = (vpath->handle->vpath->vp_id *
2271 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002272
2273 for (i = 0; i < vdev->no_of_vpath; i++) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002274 /* Reduce the chance of losing alarm interrupts by masking
Jon Mason16fded72011-01-18 15:02:21 +00002275 * the vector. A pending bit will be set if an alarm is
2276 * generated and on unmask the interrupt will be fired.
2277 */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002278 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
Jon Mason16fded72011-01-18 15:02:21 +00002279 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2280 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002281
2282 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2283 vdev->exec_mode);
2284 if (status == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002285 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
Jon Mason16fded72011-01-18 15:02:21 +00002286 msix_id);
2287 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002288 continue;
2289 }
2290 vxge_debug_intr(VXGE_ERR,
2291 "%s: vxge_hw_vpath_alarm_process failed %x ",
2292 VXGE_DRIVER_NAME, status);
2293 }
2294 return IRQ_HANDLED;
2295}
2296
2297static int vxge_alloc_msix(struct vxgedev *vdev)
2298{
2299 int j, i, ret = 0;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002300 int msix_intr_vect = 0, temp;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002301 vdev->intr_cnt = 0;
2302
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002303start:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002304 /* Tx/Rx MSIX Vectors count */
2305 vdev->intr_cnt = vdev->no_of_vpath * 2;
2306
2307 /* Alarm MSIX Vectors count */
2308 vdev->intr_cnt++;
2309
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002310 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2311 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002312 if (!vdev->entries) {
2313 vxge_debug_init(VXGE_ERR,
2314 "%s: memory allocation failed",
2315 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002316 ret = -ENOMEM;
2317 goto alloc_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002318 }
2319
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002320 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2321 sizeof(struct vxge_msix_entry),
2322 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002323 if (!vdev->vxge_entries) {
2324 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2325 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002326 ret = -ENOMEM;
2327 goto alloc_vxge_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002328 }
2329
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002330 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002331
2332 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2333
2334 /* Initialize the fifo vector */
2335 vdev->entries[j].entry = msix_intr_vect;
2336 vdev->vxge_entries[j].entry = msix_intr_vect;
2337 vdev->vxge_entries[j].in_use = 0;
2338 j++;
2339
2340 /* Initialize the ring vector */
2341 vdev->entries[j].entry = msix_intr_vect + 1;
2342 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2343 vdev->vxge_entries[j].in_use = 0;
2344 j++;
2345 }
2346
2347 /* Initialize the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002348 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2349 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002350 vdev->vxge_entries[j].in_use = 0;
2351
Alexander Gordeev9644cdc2014-02-18 11:11:51 +01002352 ret = pci_enable_msix_range(vdev->pdev,
2353 vdev->entries, 3, vdev->intr_cnt);
2354 if (ret < 0) {
2355 ret = -ENODEV;
2356 goto enable_msix_failed;
2357 } else if (ret < vdev->intr_cnt) {
2358 pci_disable_msix(vdev->pdev);
2359
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002360 vxge_debug_init(VXGE_ERR,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002361 "%s: MSI-X enable failed for %d vectors, ret: %d",
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002362 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
Alexander Gordeev9644cdc2014-02-18 11:11:51 +01002363 if (max_config_vpath != VXGE_USE_DEFAULT) {
Michal Schmidtcc413d92010-06-24 04:13:44 +00002364 ret = -ENODEV;
2365 goto enable_msix_failed;
2366 }
2367
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002368 kfree(vdev->entries);
2369 kfree(vdev->vxge_entries);
2370 vdev->entries = NULL;
2371 vdev->vxge_entries = NULL;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002372 /* Try with less no of vector by reducing no of vpaths count */
2373 temp = (ret - 1)/2;
2374 vxge_close_vpaths(vdev, temp);
2375 vdev->no_of_vpath = temp;
2376 goto start;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002377 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002378 return 0;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002379
2380enable_msix_failed:
2381 kfree(vdev->vxge_entries);
2382alloc_vxge_entries_failed:
2383 kfree(vdev->entries);
2384alloc_entries_failed:
2385 return ret;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002386}
2387
2388static int vxge_enable_msix(struct vxgedev *vdev)
2389{
2390
2391 int i, ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002392 /* 0 - Tx, 1 - Rx */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002393 int tim_msix_id[4] = {0, 1, 0, 0};
2394
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002395 vdev->intr_cnt = 0;
2396
2397 /* allocate msix vectors */
2398 ret = vxge_alloc_msix(vdev);
2399 if (!ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002400 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002401 struct vxge_vpath *vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002402
Jon Mason7adf7d12010-07-15 08:47:24 +00002403 /* If fifo or ring are not enabled, the MSIX vector for
2404 * it should be set to 0.
2405 */
2406 vpath->ring.rx_vector_no = (vpath->device_id *
2407 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002408
Jon Mason16fded72011-01-18 15:02:21 +00002409 vpath->fifo.tx_vector_no = (vpath->device_id *
2410 VXGE_HW_VPATH_MSIX_ACTIVE);
2411
Jon Mason7adf7d12010-07-15 08:47:24 +00002412 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2413 VXGE_ALARM_MSIX_ID);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002414 }
2415 }
2416
2417 return ret;
2418}
2419
2420static void vxge_rem_msix_isr(struct vxgedev *vdev)
2421{
2422 int intr_cnt;
2423
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002424 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002425 intr_cnt++) {
2426 if (vdev->vxge_entries[intr_cnt].in_use) {
2427 synchronize_irq(vdev->entries[intr_cnt].vector);
2428 free_irq(vdev->entries[intr_cnt].vector,
2429 vdev->vxge_entries[intr_cnt].arg);
2430 vdev->vxge_entries[intr_cnt].in_use = 0;
2431 }
2432 }
2433
2434 kfree(vdev->entries);
2435 kfree(vdev->vxge_entries);
2436 vdev->entries = NULL;
2437 vdev->vxge_entries = NULL;
2438
2439 if (vdev->config.intr_type == MSI_X)
2440 pci_disable_msix(vdev->pdev);
2441}
2442#endif
2443
2444static void vxge_rem_isr(struct vxgedev *vdev)
2445{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002446#ifdef CONFIG_PCI_MSI
2447 if (vdev->config.intr_type == MSI_X) {
2448 vxge_rem_msix_isr(vdev);
2449 } else
2450#endif
2451 if (vdev->config.intr_type == INTA) {
2452 synchronize_irq(vdev->pdev->irq);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002453 free_irq(vdev->pdev->irq, vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002454 }
2455}
2456
2457static int vxge_add_isr(struct vxgedev *vdev)
2458{
2459 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002460#ifdef CONFIG_PCI_MSI
2461 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002462 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2463
2464 if (vdev->config.intr_type == MSI_X)
2465 ret = vxge_enable_msix(vdev);
2466
2467 if (ret) {
2468 vxge_debug_init(VXGE_ERR,
2469 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002470 vxge_debug_init(VXGE_ERR,
2471 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2472 vdev->config.intr_type = INTA;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002473 }
2474
2475 if (vdev->config.intr_type == MSI_X) {
2476 for (intr_idx = 0;
2477 intr_idx < (vdev->no_of_vpath *
2478 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2479
2480 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2481 irq_req = 0;
2482
2483 switch (msix_idx) {
2484 case 0:
2485 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002486 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2487 vdev->ndev->name,
2488 vdev->entries[intr_cnt].entry,
2489 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002490 ret = request_irq(
2491 vdev->entries[intr_cnt].vector,
2492 vxge_tx_msix_handle, 0,
2493 vdev->desc[intr_cnt],
2494 &vdev->vpaths[vp_idx].fifo);
2495 vdev->vxge_entries[intr_cnt].arg =
2496 &vdev->vpaths[vp_idx].fifo;
2497 irq_req = 1;
2498 break;
2499 case 1:
2500 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002501 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2502 vdev->ndev->name,
2503 vdev->entries[intr_cnt].entry,
2504 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002505 ret = request_irq(
2506 vdev->entries[intr_cnt].vector,
2507 vxge_rx_msix_napi_handle,
2508 0,
2509 vdev->desc[intr_cnt],
2510 &vdev->vpaths[vp_idx].ring);
2511 vdev->vxge_entries[intr_cnt].arg =
2512 &vdev->vpaths[vp_idx].ring;
2513 irq_req = 1;
2514 break;
2515 }
2516
2517 if (ret) {
2518 vxge_debug_init(VXGE_ERR,
2519 "%s: MSIX - %d Registration failed",
2520 vdev->ndev->name, intr_cnt);
2521 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002522 vdev->config.intr_type = INTA;
2523 vxge_debug_init(VXGE_ERR,
2524 "%s: Defaulting to INTA"
2525 , vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002526 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002527 }
2528
2529 if (irq_req) {
2530 /* We requested for this msix interrupt */
2531 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002532 msix_idx += vdev->vpaths[vp_idx].device_id *
2533 VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002534 vxge_hw_vpath_msix_unmask(
2535 vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002536 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002537 intr_cnt++;
2538 }
2539
2540 /* Point to next vpath handler */
Joe Perches8e95a202009-12-03 07:58:21 +00002541 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2542 (vp_idx < (vdev->no_of_vpath - 1)))
2543 vp_idx++;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002544 }
2545
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002546 intr_cnt = vdev->no_of_vpath * 2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002547 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002548 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2549 vdev->ndev->name,
2550 vdev->entries[intr_cnt].entry,
2551 pci_fun);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002552 /* For Alarm interrupts */
2553 ret = request_irq(vdev->entries[intr_cnt].vector,
2554 vxge_alarm_msix_handle, 0,
2555 vdev->desc[intr_cnt],
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002556 &vdev->vpaths[0]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002557 if (ret) {
2558 vxge_debug_init(VXGE_ERR,
2559 "%s: MSIX - %d Registration failed",
2560 vdev->ndev->name, intr_cnt);
2561 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002562 vdev->config.intr_type = INTA;
2563 vxge_debug_init(VXGE_ERR,
2564 "%s: Defaulting to INTA",
2565 vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002566 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002567 }
2568
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002569 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2570 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002571 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002572 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002573 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002574 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002575 }
2576INTA_MODE:
2577#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002578
2579 if (vdev->config.intr_type == INTA) {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002580 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2581 "%s:vxge:INTA", vdev->ndev->name);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002582 vxge_hw_device_set_intr_type(vdev->devh,
2583 VXGE_HW_INTR_MODE_IRQLINE);
Jon Mason16fded72011-01-18 15:02:21 +00002584
2585 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2586
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002587 ret = request_irq((int) vdev->pdev->irq,
2588 vxge_isr_napi,
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002589 IRQF_SHARED, vdev->desc[0], vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002590 if (ret) {
2591 vxge_debug_init(VXGE_ERR,
2592 "%s %s-%d: ISR registration failed",
2593 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2594 return -ENODEV;
2595 }
2596 vxge_debug_init(VXGE_TRACE,
2597 "new %s-%d line allocated",
2598 "IRQ", vdev->pdev->irq);
2599 }
2600
2601 return VXGE_HW_OK;
2602}
2603
2604static void vxge_poll_vp_reset(unsigned long data)
2605{
2606 struct vxgedev *vdev = (struct vxgedev *)data;
2607 int i, j = 0;
2608
2609 for (i = 0; i < vdev->no_of_vpath; i++) {
2610 if (test_bit(i, &vdev->vp_reset)) {
2611 vxge_reset_vpath(vdev, i);
2612 j++;
2613 }
2614 }
2615 if (j && (vdev->config.intr_type != MSI_X)) {
2616 vxge_hw_device_unmask_all(vdev->devh);
2617 vxge_hw_device_flush_io(vdev->devh);
2618 }
2619
2620 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2621}
2622
2623static void vxge_poll_vp_lockup(unsigned long data)
2624{
2625 struct vxgedev *vdev = (struct vxgedev *)data;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002626 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00002627 struct vxge_vpath *vpath;
2628 struct vxge_ring *ring;
2629 int i;
stephen hemminger62ea0552011-06-20 10:35:07 +00002630 unsigned long rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002631
2632 for (i = 0; i < vdev->no_of_vpath; i++) {
2633 ring = &vdev->vpaths[i].ring;
stephen hemminger62ea0552011-06-20 10:35:07 +00002634
2635 /* Truncated to machine word size number of frames */
2636 rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
2637
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002638 /* Did this vpath received any packets */
stephen hemminger62ea0552011-06-20 10:35:07 +00002639 if (ring->stats.prev_rx_frms == rx_frms) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002640 status = vxge_hw_vpath_check_leak(ring->handle);
2641
2642 /* Did it received any packets last time */
2643 if ((VXGE_HW_FAIL == status) &&
2644 (VXGE_HW_FAIL == ring->last_status)) {
2645
2646 /* schedule vpath reset */
2647 if (!test_and_set_bit(i, &vdev->vp_reset)) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002648 vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002649
2650 /* disable interrupts for this vpath */
2651 vxge_vpath_intr_disable(vdev, i);
2652
2653 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00002654 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002655 continue;
2656 }
2657 }
2658 }
stephen hemminger62ea0552011-06-20 10:35:07 +00002659 ring->stats.prev_rx_frms = rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002660 ring->last_status = status;
2661 }
2662
2663 /* Check every 1 milli second */
2664 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2665}
2666
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002667static netdev_features_t vxge_fix_features(struct net_device *dev,
2668 netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002669{
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002670 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002671
2672 /* Enabling RTH requires some of the logic in vxge_device_register and a
2673 * vpath reset. Due to these restrictions, only allow modification
2674 * while the interface is down.
2675 */
2676 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2677 features ^= NETIF_F_RXHASH;
2678
2679 return features;
2680}
2681
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002682static int vxge_set_features(struct net_device *dev, netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002683{
2684 struct vxgedev *vdev = netdev_priv(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002685 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002686
2687 if (!(changed & NETIF_F_RXHASH))
2688 return 0;
2689
2690 /* !netif_running() ensured by vxge_fix_features() */
2691
2692 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2693 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2694 dev->features = features ^ NETIF_F_RXHASH;
2695 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2696 return -EIO;
2697 }
2698
2699 return 0;
2700}
2701
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002702/**
2703 * vxge_open
2704 * @dev: pointer to the device structure.
2705 *
2706 * This function is the open entry point of the driver. It mainly calls a
2707 * function to allocate Rx buffers and inserts them into the buffer
2708 * descriptors and then enables the Rx part of the NIC.
2709 * Return value: '0' on success and an appropriate (-)ve integer as
2710 * defined in errno.h file on failure.
2711 */
Jon Mason528f7272010-12-10 14:02:56 +00002712static int vxge_open(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002713{
2714 enum vxge_hw_status status;
2715 struct vxgedev *vdev;
2716 struct __vxge_hw_device *hldev;
Jon Mason7adf7d12010-07-15 08:47:24 +00002717 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002718 int ret = 0;
2719 int i;
2720 u64 val64, function_mode;
Jon Mason528f7272010-12-10 14:02:56 +00002721
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002722 vxge_debug_entryexit(VXGE_TRACE,
2723 "%s: %s:%d", dev->name, __func__, __LINE__);
2724
Joe Perches5f54ceb2010-11-15 11:12:30 +00002725 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002726 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002727 function_mode = vdev->config.device_hw_info.function_mode;
2728
2729 /* make sure you have link off by default every time Nic is
2730 * initialized */
2731 netif_carrier_off(dev);
2732
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002733 /* Open VPATHs */
2734 status = vxge_open_vpaths(vdev);
2735 if (status != VXGE_HW_OK) {
2736 vxge_debug_init(VXGE_ERR,
2737 "%s: fatal: Vpath open failed", vdev->ndev->name);
2738 ret = -EPERM;
2739 goto out0;
2740 }
2741
2742 vdev->mtu = dev->mtu;
2743
2744 status = vxge_add_isr(vdev);
2745 if (status != VXGE_HW_OK) {
2746 vxge_debug_init(VXGE_ERR,
2747 "%s: fatal: ISR add failed", dev->name);
2748 ret = -EPERM;
2749 goto out1;
2750 }
2751
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002752 if (vdev->config.intr_type != MSI_X) {
2753 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2754 vdev->config.napi_weight);
2755 napi_enable(&vdev->napi);
Jon Mason7adf7d12010-07-15 08:47:24 +00002756 for (i = 0; i < vdev->no_of_vpath; i++) {
2757 vpath = &vdev->vpaths[i];
2758 vpath->ring.napi_p = &vdev->napi;
2759 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002760 } else {
2761 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002762 vpath = &vdev->vpaths[i];
2763 netif_napi_add(dev, &vpath->ring.napi,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002764 vxge_poll_msix, vdev->config.napi_weight);
Jon Mason7adf7d12010-07-15 08:47:24 +00002765 napi_enable(&vpath->ring.napi);
2766 vpath->ring.napi_p = &vpath->ring.napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002767 }
2768 }
2769
2770 /* configure RTH */
2771 if (vdev->config.rth_steering) {
2772 status = vxge_rth_configure(vdev);
2773 if (status != VXGE_HW_OK) {
2774 vxge_debug_init(VXGE_ERR,
2775 "%s: fatal: RTH configuration failed",
2776 dev->name);
2777 ret = -EPERM;
2778 goto out2;
2779 }
2780 }
Jon Mason47f01db2010-11-11 04:25:53 +00002781 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2782 hldev->config.rth_en ? "enabled" : "disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002783
2784 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002785 vpath = &vdev->vpaths[i];
2786
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002787 /* set initial mtu before enabling the device */
Jon Mason7adf7d12010-07-15 08:47:24 +00002788 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002789 if (status != VXGE_HW_OK) {
2790 vxge_debug_init(VXGE_ERR,
2791 "%s: fatal: can not set new MTU", dev->name);
2792 ret = -EPERM;
2793 goto out2;
2794 }
2795 }
2796
2797 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2798 vxge_debug_init(vdev->level_trace,
2799 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2800 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2801
Jon Mason7adf7d12010-07-15 08:47:24 +00002802 /* Restore the DA, VID table and also multicast and promiscuous mode
2803 * states
2804 */
2805 if (vdev->all_multi_flg) {
2806 for (i = 0; i < vdev->no_of_vpath; i++) {
2807 vpath = &vdev->vpaths[i];
2808 vxge_restore_vpath_mac_addr(vpath);
2809 vxge_restore_vpath_vid_table(vpath);
2810
2811 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2812 if (status != VXGE_HW_OK)
2813 vxge_debug_init(VXGE_ERR,
2814 "%s:%d Enabling multicast failed",
2815 __func__, __LINE__);
2816 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002817 }
2818
2819 /* Enable vpath to sniff all unicast/multicast traffic that not
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002820 * addressed to them. We allow promiscuous mode for PF only
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002821 */
2822
2823 val64 = 0;
2824 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2825 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2826
2827 vxge_hw_mgmt_reg_write(vdev->devh,
2828 vxge_hw_mgmt_reg_type_mrpcim,
2829 0,
2830 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2831 rxmac_authorize_all_addr),
2832 val64);
2833
2834 vxge_hw_mgmt_reg_write(vdev->devh,
2835 vxge_hw_mgmt_reg_type_mrpcim,
2836 0,
2837 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2838 rxmac_authorize_all_vid),
2839 val64);
2840
2841 vxge_set_multicast(dev);
2842
2843 /* Enabling Bcast and mcast for all vpath */
2844 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002845 vpath = &vdev->vpaths[i];
2846 status = vxge_hw_vpath_bcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002847 if (status != VXGE_HW_OK)
2848 vxge_debug_init(VXGE_ERR,
2849 "%s : Can not enable bcast for vpath "
2850 "id %d", dev->name, i);
2851 if (vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002852 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002853 if (status != VXGE_HW_OK)
2854 vxge_debug_init(VXGE_ERR,
2855 "%s : Can not enable mcast for vpath "
2856 "id %d", dev->name, i);
2857 }
2858 }
2859
2860 vxge_hw_device_setpause_data(vdev->devh, 0,
2861 vdev->config.tx_pause_enable,
2862 vdev->config.rx_pause_enable);
2863
2864 if (vdev->vp_reset_timer.function == NULL)
Joe Perches044a3812012-04-03 12:14:31 +00002865 vxge_os_timer(&vdev->vp_reset_timer, vxge_poll_vp_reset, vdev,
2866 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002867
Jon Masone7935c92010-11-11 04:26:00 +00002868 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2869 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
Joe Perches044a3812012-04-03 12:14:31 +00002870 vxge_os_timer(&vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
Jon Masone7935c92010-11-11 04:26:00 +00002871 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002872
2873 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2874
2875 smp_wmb();
2876
2877 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2878 netif_carrier_on(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00002879 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002880 vdev->stats.link_up++;
2881 }
2882
2883 vxge_hw_device_intr_enable(vdev->devh);
2884
2885 smp_wmb();
2886
2887 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002888 vpath = &vdev->vpaths[i];
2889
2890 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002891 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00002892 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002893 }
2894
Jon Masond03848e2010-07-15 08:47:23 +00002895 netif_tx_start_all_queues(vdev->ndev);
Jon Mason16fded72011-01-18 15:02:21 +00002896
2897 /* configure CI */
2898 vxge_config_ci_for_tti_rti(vdev);
2899
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002900 goto out0;
2901
2902out2:
2903 vxge_rem_isr(vdev);
2904
2905 /* Disable napi */
2906 if (vdev->config.intr_type != MSI_X)
2907 napi_disable(&vdev->napi);
2908 else {
2909 for (i = 0; i < vdev->no_of_vpath; i++)
2910 napi_disable(&vdev->vpaths[i].ring.napi);
2911 }
2912
2913out1:
2914 vxge_close_vpaths(vdev, 0);
2915out0:
2916 vxge_debug_entryexit(VXGE_TRACE,
2917 "%s: %s:%d Exiting...",
2918 dev->name, __func__, __LINE__);
2919 return ret;
2920}
2921
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002922/* Loop through the mac address list and delete all the entries */
stephen hemminger42821a52010-10-21 07:50:53 +00002923static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002924{
2925
2926 struct list_head *entry, *next;
2927 if (list_empty(&vpath->mac_addr_list))
2928 return;
2929
2930 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2931 list_del(entry);
2932 kfree((struct vxge_mac_addrs *)entry);
2933 }
2934}
2935
2936static void vxge_napi_del_all(struct vxgedev *vdev)
2937{
2938 int i;
2939 if (vdev->config.intr_type != MSI_X)
2940 netif_napi_del(&vdev->napi);
2941 else {
2942 for (i = 0; i < vdev->no_of_vpath; i++)
2943 netif_napi_del(&vdev->vpaths[i].ring.napi);
2944 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002945}
2946
stephen hemminger42821a52010-10-21 07:50:53 +00002947static int do_vxge_close(struct net_device *dev, int do_io)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002948{
2949 enum vxge_hw_status status;
2950 struct vxgedev *vdev;
2951 struct __vxge_hw_device *hldev;
2952 int i;
2953 u64 val64, vpath_vector;
2954 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2955 dev->name, __func__, __LINE__);
2956
Joe Perches5f54ceb2010-11-15 11:12:30 +00002957 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002958 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002959
Sreenivasa Honnurbd9ee682009-07-01 21:14:03 +00002960 if (unlikely(!is_vxge_card_up(vdev)))
2961 return 0;
2962
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002963 /* If vxge_handle_crit_err task is executing,
2964 * wait till it completes. */
2965 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2966 msleep(50);
2967
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002968 if (do_io) {
2969 /* Put the vpath back in normal mode */
2970 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2971 status = vxge_hw_mgmt_reg_read(vdev->devh,
2972 vxge_hw_mgmt_reg_type_mrpcim,
2973 0,
2974 (ulong)offsetof(
2975 struct vxge_hw_mrpcim_reg,
2976 rts_mgr_cbasin_cfg),
2977 &val64);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002978 if (status == VXGE_HW_OK) {
2979 val64 &= ~vpath_vector;
2980 status = vxge_hw_mgmt_reg_write(vdev->devh,
2981 vxge_hw_mgmt_reg_type_mrpcim,
2982 0,
2983 (ulong)offsetof(
2984 struct vxge_hw_mrpcim_reg,
2985 rts_mgr_cbasin_cfg),
2986 val64);
2987 }
2988
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002989 /* Remove the function 0 from promiscuous mode */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002990 vxge_hw_mgmt_reg_write(vdev->devh,
2991 vxge_hw_mgmt_reg_type_mrpcim,
2992 0,
2993 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2994 rxmac_authorize_all_addr),
2995 0);
2996
2997 vxge_hw_mgmt_reg_write(vdev->devh,
2998 vxge_hw_mgmt_reg_type_mrpcim,
2999 0,
3000 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
3001 rxmac_authorize_all_vid),
3002 0);
3003
3004 smp_wmb();
3005 }
Jon Masone7935c92010-11-11 04:26:00 +00003006
3007 if (vdev->titan1)
3008 del_timer_sync(&vdev->vp_lockup_timer);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003009
3010 del_timer_sync(&vdev->vp_reset_timer);
3011
Jon Mason4d2a5b42010-11-11 04:25:54 +00003012 if (do_io)
3013 vxge_hw_device_wait_receive_idle(hldev);
3014
3015 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3016
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003017 /* Disable napi */
3018 if (vdev->config.intr_type != MSI_X)
3019 napi_disable(&vdev->napi);
3020 else {
3021 for (i = 0; i < vdev->no_of_vpath; i++)
3022 napi_disable(&vdev->vpaths[i].ring.napi);
3023 }
3024
3025 netif_carrier_off(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00003026 netdev_notice(vdev->ndev, "Link Down\n");
Jon Masond03848e2010-07-15 08:47:23 +00003027 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003028
3029 /* Note that at this point xmit() is stopped by upper layer */
3030 if (do_io)
3031 vxge_hw_device_intr_disable(vdev->devh);
3032
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003033 vxge_rem_isr(vdev);
3034
3035 vxge_napi_del_all(vdev);
3036
3037 if (do_io)
3038 vxge_reset_all_vpaths(vdev);
3039
3040 vxge_close_vpaths(vdev, 0);
3041
3042 vxge_debug_entryexit(VXGE_TRACE,
3043 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3044
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003045 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3046
3047 return 0;
3048}
3049
3050/**
3051 * vxge_close
3052 * @dev: device pointer.
3053 *
3054 * This is the stop entry point of the driver. It needs to undo exactly
3055 * whatever was done by the open entry point, thus it's usually referred to
3056 * as the close function.Among other things this function mainly stops the
3057 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3058 * Return value: '0' on success and an appropriate (-)ve integer as
3059 * defined in errno.h file on failure.
3060 */
Jon Mason528f7272010-12-10 14:02:56 +00003061static int vxge_close(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003062{
3063 do_vxge_close(dev, 1);
3064 return 0;
3065}
3066
3067/**
3068 * vxge_change_mtu
3069 * @dev: net device pointer.
3070 * @new_mtu :the new MTU size for the device.
3071 *
3072 * A driver entry point to change MTU size for the device. Before changing
3073 * the MTU the device must be stopped.
3074 */
3075static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3076{
3077 struct vxgedev *vdev = netdev_priv(dev);
3078
3079 vxge_debug_entryexit(vdev->level_trace,
3080 "%s:%d", __func__, __LINE__);
3081 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3082 vxge_debug_init(vdev->level_err,
3083 "%s: mtu size is invalid", dev->name);
3084 return -EPERM;
3085 }
3086
3087 /* check if device is down already */
3088 if (unlikely(!is_vxge_card_up(vdev))) {
3089 /* just store new value, will use later on open() */
3090 dev->mtu = new_mtu;
3091 vxge_debug_init(vdev->level_err,
3092 "%s", "device is down on MTU change");
3093 return 0;
3094 }
3095
3096 vxge_debug_init(vdev->level_trace,
3097 "trying to apply new MTU %d", new_mtu);
3098
3099 if (vxge_close(dev))
3100 return -EIO;
3101
3102 dev->mtu = new_mtu;
3103 vdev->mtu = new_mtu;
3104
3105 if (vxge_open(dev))
3106 return -EIO;
3107
3108 vxge_debug_init(vdev->level_trace,
3109 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3110
3111 vxge_debug_entryexit(vdev->level_trace,
3112 "%s:%d Exiting...", __func__, __LINE__);
3113
3114 return 0;
3115}
3116
3117/**
Eric Dumazetdd57f972010-08-18 03:42:54 +00003118 * vxge_get_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003119 * @dev: pointer to the device structure
Eric Dumazetdd57f972010-08-18 03:42:54 +00003120 * @stats: pointer to struct rtnl_link_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003121 *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003122 */
Eric Dumazetdd57f972010-08-18 03:42:54 +00003123static struct rtnl_link_stats64 *
3124vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003125{
Eric Dumazetdd57f972010-08-18 03:42:54 +00003126 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003127 int k;
3128
Eric Dumazetdd57f972010-08-18 03:42:54 +00003129 /* net_stats already zeroed by caller */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003130 for (k = 0; k < vdev->no_of_vpath; k++) {
stephen hemminger62ea0552011-06-20 10:35:07 +00003131 struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
3132 struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
3133 unsigned int start;
3134 u64 packets, bytes, multicast;
3135
3136 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07003137 start = u64_stats_fetch_begin_irq(&rxstats->syncp);
stephen hemminger62ea0552011-06-20 10:35:07 +00003138
3139 packets = rxstats->rx_frms;
3140 multicast = rxstats->rx_mcast;
3141 bytes = rxstats->rx_bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07003142 } while (u64_stats_fetch_retry_irq(&rxstats->syncp, start));
stephen hemminger62ea0552011-06-20 10:35:07 +00003143
3144 net_stats->rx_packets += packets;
3145 net_stats->rx_bytes += bytes;
3146 net_stats->multicast += multicast;
3147
3148 net_stats->rx_errors += rxstats->rx_errors;
3149 net_stats->rx_dropped += rxstats->rx_dropped;
3150
3151 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07003152 start = u64_stats_fetch_begin_irq(&txstats->syncp);
stephen hemminger62ea0552011-06-20 10:35:07 +00003153
3154 packets = txstats->tx_frms;
3155 bytes = txstats->tx_bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07003156 } while (u64_stats_fetch_retry_irq(&txstats->syncp, start));
stephen hemminger62ea0552011-06-20 10:35:07 +00003157
3158 net_stats->tx_packets += packets;
3159 net_stats->tx_bytes += bytes;
3160 net_stats->tx_errors += txstats->tx_errors;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003161 }
3162
3163 return net_stats;
3164}
3165
Jon Masoncd883a72011-04-08 11:11:21 +00003166static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
Jon Masonb81b3732010-11-11 04:25:58 +00003167{
3168 enum vxge_hw_status status;
3169 u64 val64;
3170
3171 /* Timestamp is passed to the driver via the FCS, therefore we
3172 * must disable the FCS stripping by the adapter. Since this is
3173 * required for the driver to load (due to a hardware bug),
3174 * there is no need to do anything special here.
3175 */
Jon Masoncd883a72011-04-08 11:11:21 +00003176 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3177 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3178 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
Jon Masonb81b3732010-11-11 04:25:58 +00003179
Jon Masoncd883a72011-04-08 11:11:21 +00003180 status = vxge_hw_mgmt_reg_write(devh,
Jon Masonb81b3732010-11-11 04:25:58 +00003181 vxge_hw_mgmt_reg_type_mrpcim,
3182 0,
3183 offsetof(struct vxge_hw_mrpcim_reg,
3184 xmac_timestamp),
3185 val64);
Jon Masoncd883a72011-04-08 11:11:21 +00003186 vxge_hw_device_flush_io(devh);
3187 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
Jon Masonb81b3732010-11-11 04:25:58 +00003188 return status;
3189}
3190
Ben Hutchings450e55e2013-11-18 23:16:23 +00003191static int vxge_hwtstamp_set(struct vxgedev *vdev, void __user *data)
Jon Masonb81b3732010-11-11 04:25:58 +00003192{
3193 struct hwtstamp_config config;
Jon Masonb81b3732010-11-11 04:25:58 +00003194 int i;
3195
3196 if (copy_from_user(&config, data, sizeof(config)))
3197 return -EFAULT;
3198
3199 /* reserved for future extensions */
3200 if (config.flags)
3201 return -EINVAL;
3202
3203 /* Transmit HW Timestamp not supported */
3204 switch (config.tx_type) {
3205 case HWTSTAMP_TX_OFF:
3206 break;
3207 case HWTSTAMP_TX_ON:
3208 default:
3209 return -ERANGE;
3210 }
3211
3212 switch (config.rx_filter) {
3213 case HWTSTAMP_FILTER_NONE:
Jon Masonb81b3732010-11-11 04:25:58 +00003214 vdev->rx_hwts = 0;
3215 config.rx_filter = HWTSTAMP_FILTER_NONE;
3216 break;
3217
3218 case HWTSTAMP_FILTER_ALL:
3219 case HWTSTAMP_FILTER_SOME:
3220 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3221 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3222 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3223 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3224 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3225 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3226 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3227 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3228 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3229 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3230 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3231 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Jon Masoncd883a72011-04-08 11:11:21 +00003232 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
Jon Masonb81b3732010-11-11 04:25:58 +00003233 return -EFAULT;
3234
3235 vdev->rx_hwts = 1;
3236 config.rx_filter = HWTSTAMP_FILTER_ALL;
3237 break;
3238
3239 default:
3240 return -ERANGE;
3241 }
3242
3243 for (i = 0; i < vdev->no_of_vpath; i++)
3244 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3245
3246 if (copy_to_user(data, &config, sizeof(config)))
3247 return -EFAULT;
3248
3249 return 0;
3250}
3251
Ben Hutchings450e55e2013-11-18 23:16:23 +00003252static int vxge_hwtstamp_get(struct vxgedev *vdev, void __user *data)
3253{
3254 struct hwtstamp_config config;
3255
3256 config.flags = 0;
3257 config.tx_type = HWTSTAMP_TX_OFF;
3258 config.rx_filter = (vdev->rx_hwts ?
3259 HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
3260
3261 if (copy_to_user(data, &config, sizeof(config)))
3262 return -EFAULT;
3263
3264 return 0;
3265}
3266
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003267/**
3268 * vxge_ioctl
3269 * @dev: Device pointer.
3270 * @ifr: An IOCTL specific structure, that can contain a pointer to
3271 * a proprietary structure used to pass information to the driver.
3272 * @cmd: This is used to distinguish between the different commands that
3273 * can be passed to the IOCTL functions.
3274 *
3275 * Entry point for the Ioctl.
3276 */
3277static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3278{
Jon Masonb81b3732010-11-11 04:25:58 +00003279 struct vxgedev *vdev = netdev_priv(dev);
Jon Masonb81b3732010-11-11 04:25:58 +00003280
3281 switch (cmd) {
3282 case SIOCSHWTSTAMP:
Ben Hutchings450e55e2013-11-18 23:16:23 +00003283 return vxge_hwtstamp_set(vdev, rq->ifr_data);
3284 case SIOCGHWTSTAMP:
3285 return vxge_hwtstamp_get(vdev, rq->ifr_data);
Jon Masonb81b3732010-11-11 04:25:58 +00003286 default:
3287 return -EOPNOTSUPP;
3288 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003289}
3290
3291/**
3292 * vxge_tx_watchdog
3293 * @dev: pointer to net device structure
3294 *
3295 * Watchdog for transmit side.
3296 * This function is triggered if the Tx Queue is stopped
3297 * for a pre-defined amount of time when the Interface is still up.
3298 */
Jon Mason2e41f642010-12-10 14:02:59 +00003299static void vxge_tx_watchdog(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003300{
3301 struct vxgedev *vdev;
3302
3303 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3304
Joe Perches5f54ceb2010-11-15 11:12:30 +00003305 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003306
3307 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3308
Jon Mason2e41f642010-12-10 14:02:59 +00003309 schedule_work(&vdev->reset_task);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003310 vxge_debug_entryexit(VXGE_TRACE,
3311 "%s:%d Exiting...", __func__, __LINE__);
3312}
3313
3314/**
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003315 * vxge_vlan_rx_add_vid
3316 * @dev: net device pointer.
Patrick McHardy80d5c362013-04-19 02:04:28 +00003317 * @proto: vlan protocol
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003318 * @vid: vid
3319 *
3320 * Add the vlan id to the devices vlan id table
3321 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003322static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00003323vxge_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003324{
Jiri Pirko53515732011-07-20 04:54:40 +00003325 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003326 struct vxge_vpath *vpath;
3327 int vp_id;
3328
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003329 /* Add these vlan to the vid table */
3330 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3331 vpath = &vdev->vpaths[vp_id];
3332 if (!vpath->is_open)
3333 continue;
3334 vxge_hw_vpath_vid_add(vpath->handle, vid);
3335 }
Jiri Pirko53515732011-07-20 04:54:40 +00003336 set_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003337 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003338}
3339
3340/**
Patrick McHardy80d5c362013-04-19 02:04:28 +00003341 * vxge_vlan_rx_kill_vid
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003342 * @dev: net device pointer.
Patrick McHardy80d5c362013-04-19 02:04:28 +00003343 * @proto: vlan protocol
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003344 * @vid: vid
3345 *
3346 * Remove the vlan id from the device's vlan id table
3347 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003348static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00003349vxge_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003350{
Jiri Pirko53515732011-07-20 04:54:40 +00003351 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003352 struct vxge_vpath *vpath;
3353 int vp_id;
3354
3355 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3356
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003357 /* Delete this vlan from the vid table */
3358 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3359 vpath = &vdev->vpaths[vp_id];
3360 if (!vpath->is_open)
3361 continue;
3362 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3363 }
3364 vxge_debug_entryexit(VXGE_TRACE,
3365 "%s:%d Exiting...", __func__, __LINE__);
Jiri Pirko53515732011-07-20 04:54:40 +00003366 clear_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003367 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003368}
3369
3370static const struct net_device_ops vxge_netdev_ops = {
3371 .ndo_open = vxge_open,
3372 .ndo_stop = vxge_close,
Eric Dumazetdd57f972010-08-18 03:42:54 +00003373 .ndo_get_stats64 = vxge_get_stats64,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003374 .ndo_start_xmit = vxge_xmit,
3375 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003376 .ndo_set_rx_mode = vxge_set_multicast,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003377 .ndo_do_ioctl = vxge_ioctl,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003378 .ndo_set_mac_address = vxge_set_mac_addr,
3379 .ndo_change_mtu = vxge_change_mtu,
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003380 .ndo_fix_features = vxge_fix_features,
3381 .ndo_set_features = vxge_set_features,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003382 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3383 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003384 .ndo_tx_timeout = vxge_tx_watchdog,
3385#ifdef CONFIG_NET_POLL_CONTROLLER
3386 .ndo_poll_controller = vxge_netpoll,
3387#endif
3388};
3389
Bill Pemberton3a036ce2012-12-03 09:23:18 -05003390static int vxge_device_register(struct __vxge_hw_device *hldev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003391 struct vxge_config *config, int high_dma,
3392 int no_of_vpath, struct vxgedev **vdev_out)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003393{
3394 struct net_device *ndev;
3395 enum vxge_hw_status status = VXGE_HW_OK;
3396 struct vxgedev *vdev;
Jon Mason98f45da2010-07-15 08:47:25 +00003397 int ret = 0, no_of_queue = 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003398 u64 stat;
3399
3400 *vdev_out = NULL;
Jon Masond03848e2010-07-15 08:47:23 +00003401 if (config->tx_steering_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003402 no_of_queue = no_of_vpath;
3403
3404 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3405 no_of_queue);
3406 if (ndev == NULL) {
3407 vxge_debug_init(
3408 vxge_hw_device_trace_level_get(hldev),
3409 "%s : device allocation failed", __func__);
3410 ret = -ENODEV;
3411 goto _out0;
3412 }
3413
3414 vxge_debug_entryexit(
3415 vxge_hw_device_trace_level_get(hldev),
3416 "%s: %s:%d Entering...",
3417 ndev->name, __func__, __LINE__);
3418
3419 vdev = netdev_priv(ndev);
3420 memset(vdev, 0, sizeof(struct vxgedev));
3421
3422 vdev->ndev = ndev;
3423 vdev->devh = hldev;
3424 vdev->pdev = hldev->pdev;
3425 memcpy(&vdev->config, config, sizeof(struct vxge_config));
Jon Masonb81b3732010-11-11 04:25:58 +00003426 vdev->rx_hwts = 0;
Sergei Shtylyovff938e42011-02-28 11:57:33 -08003427 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
Jon Masone7935c92010-11-11 04:26:00 +00003428
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003429 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3430
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003431 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3432 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3433 NETIF_F_TSO | NETIF_F_TSO6 |
Patrick McHardyf6469682013-04-19 02:04:27 +00003434 NETIF_F_HW_VLAN_CTAG_TX;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003435 if (vdev->config.rth_steering != NO_STEERING)
3436 ndev->hw_features |= NETIF_F_RXHASH;
3437
3438 ndev->features |= ndev->hw_features |
Patrick McHardyf6469682013-04-19 02:04:27 +00003439 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003440
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003441
3442 ndev->netdev_ops = &vxge_netdev_ops;
3443
3444 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
Jon Mason2e41f642010-12-10 14:02:59 +00003445 INIT_WORK(&vdev->reset_task, vxge_reset);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003446
stephen hemminger42821a52010-10-21 07:50:53 +00003447 vxge_initialize_ethtool_ops(ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003448
3449 /* Allocate memory for vpath */
3450 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3451 no_of_vpath, GFP_KERNEL);
3452 if (!vdev->vpaths) {
3453 vxge_debug_init(VXGE_ERR,
3454 "%s: vpath memory allocation failed",
3455 vdev->ndev->name);
Jon Mason6cca2002011-01-18 15:02:19 +00003456 ret = -ENOMEM;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003457 goto _out1;
3458 }
3459
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003460 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
Masanari Iida278cee02013-06-01 01:30:56 +09003461 "%s : checksumming enabled", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003462
3463 if (high_dma) {
3464 ndev->features |= NETIF_F_HIGHDMA;
3465 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3466 "%s : using High DMA", __func__);
3467 }
3468
Jon Mason6cca2002011-01-18 15:02:19 +00003469 ret = register_netdev(ndev);
3470 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003471 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3472 "%s: %s : device registration failed!",
3473 ndev->name, __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003474 goto _out2;
3475 }
3476
3477 /* Set the factory defined MAC address initially */
3478 ndev->addr_len = ETH_ALEN;
3479
3480 /* Make Link state as off at this point, when the Link change
3481 * interrupt comes the state will be automatically changed to
3482 * the right state.
3483 */
3484 netif_carrier_off(ndev);
3485
3486 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3487 "%s: Ethernet device registered",
3488 ndev->name);
3489
Jon Masone8ac1752010-11-11 04:25:57 +00003490 hldev->ndev = ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003491 *vdev_out = vdev;
3492
3493 /* Resetting the Device stats */
3494 status = vxge_hw_mrpcim_stats_access(
3495 hldev,
3496 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3497 0,
3498 0,
3499 &stat);
3500
3501 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3502 vxge_debug_init(
3503 vxge_hw_device_trace_level_get(hldev),
3504 "%s: device stats clear returns"
3505 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3506
3507 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3508 "%s: %s:%d Exiting...",
3509 ndev->name, __func__, __LINE__);
3510
3511 return ret;
3512_out2:
3513 kfree(vdev->vpaths);
3514_out1:
3515 free_netdev(ndev);
3516_out0:
3517 return ret;
3518}
3519
3520/*
3521 * vxge_device_unregister
3522 *
3523 * This function will unregister and free network device
3524 */
Jon Mason2c913082010-11-11 04:26:03 +00003525static void vxge_device_unregister(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003526{
3527 struct vxgedev *vdev;
3528 struct net_device *dev;
3529 char buf[IFNAMSIZ];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003530
3531 dev = hldev->ndev;
3532 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003533
Jon Mason2c913082010-11-11 04:26:03 +00003534 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3535 __func__, __LINE__);
3536
Jon Masonead5d232010-11-29 18:02:46 +00003537 strncpy(buf, dev->name, IFNAMSIZ);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003538
Tejun Heo43829732012-08-20 14:51:24 -07003539 flush_work(&vdev->reset_task);
Tejun Heoba27d852010-12-15 04:03:29 +00003540
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003541 /* in 2.6 will call stop() if device is up */
3542 unregister_netdev(dev);
3543
Jon Mason6cca2002011-01-18 15:02:19 +00003544 kfree(vdev->vpaths);
3545
3546 /* we are safe to free it now */
3547 free_netdev(dev);
3548
Jon Mason2c913082010-11-11 04:26:03 +00003549 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3550 buf);
3551 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3552 __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003553}
3554
3555/*
3556 * vxge_callback_crit_err
3557 *
3558 * This function is called by the alarm handler in interrupt context.
3559 * Driver must analyze it based on the event type.
3560 */
3561static void
3562vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3563 enum vxge_hw_event type, u64 vp_id)
3564{
3565 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +00003566 struct vxgedev *vdev = netdev_priv(dev);
Jon Mason98f45da2010-07-15 08:47:25 +00003567 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003568 int vpath_idx;
3569
3570 vxge_debug_entryexit(vdev->level_trace,
3571 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3572
3573 /* Note: This event type should be used for device wide
3574 * indications only - Serious errors, Slot freeze and critical errors
3575 */
3576 vdev->cric_err_event = type;
3577
Jon Mason98f45da2010-07-15 08:47:25 +00003578 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3579 vpath = &vdev->vpaths[vpath_idx];
3580 if (vpath->device_id == vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003581 break;
Jon Mason98f45da2010-07-15 08:47:25 +00003582 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003583
3584 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3585 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3586 vxge_debug_init(VXGE_ERR,
3587 "%s: Slot is frozen", vdev->ndev->name);
3588 } else if (type == VXGE_HW_EVENT_SERR) {
3589 vxge_debug_init(VXGE_ERR,
3590 "%s: Encountered Serious Error",
3591 vdev->ndev->name);
3592 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3593 vxge_debug_init(VXGE_ERR,
3594 "%s: Encountered Critical Error",
3595 vdev->ndev->name);
3596 }
3597
3598 if ((type == VXGE_HW_EVENT_SERR) ||
3599 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3600 if (unlikely(vdev->exec_mode))
3601 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3602 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3603 vxge_hw_device_mask_all(hldev);
3604 if (unlikely(vdev->exec_mode))
3605 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3606 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3607 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3608
3609 if (unlikely(vdev->exec_mode))
3610 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3611 else {
3612 /* check if this vpath is already set for reset */
3613 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3614
3615 /* disable interrupts for this vpath */
3616 vxge_vpath_intr_disable(vdev, vpath_idx);
3617
3618 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00003619 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003620 }
3621 }
3622 }
3623
3624 vxge_debug_entryexit(vdev->level_trace,
3625 "%s: %s:%d Exiting...",
3626 vdev->ndev->name, __func__, __LINE__);
3627}
3628
3629static void verify_bandwidth(void)
3630{
3631 int i, band_width, total = 0, equal_priority = 0;
3632
3633 /* 1. If user enters 0 for some fifo, give equal priority to all */
3634 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3635 if (bw_percentage[i] == 0) {
3636 equal_priority = 1;
3637 break;
3638 }
3639 }
3640
3641 if (!equal_priority) {
3642 /* 2. If sum exceeds 100, give equal priority to all */
3643 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3644 if (bw_percentage[i] == 0xFF)
3645 break;
3646
3647 total += bw_percentage[i];
3648 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3649 equal_priority = 1;
3650 break;
3651 }
3652 }
3653 }
3654
3655 if (!equal_priority) {
3656 /* Is all the bandwidth consumed? */
3657 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3658 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3659 /* Split rest of bw equally among next VPs*/
3660 band_width =
3661 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3662 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3663 if (band_width < 2) /* min of 2% */
3664 equal_priority = 1;
3665 else {
3666 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3667 i++)
3668 bw_percentage[i] =
3669 band_width;
3670 }
3671 }
3672 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3673 equal_priority = 1;
3674 }
3675
3676 if (equal_priority) {
3677 vxge_debug_init(VXGE_ERR,
3678 "%s: Assigning equal bandwidth to all the vpaths",
3679 VXGE_DRIVER_NAME);
3680 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3681 VXGE_HW_MAX_VIRTUAL_PATHS;
3682 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3683 bw_percentage[i] = bw_percentage[0];
3684 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003685}
3686
3687/*
3688 * Vpath configuration
3689 */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003690static int vxge_config_vpaths(struct vxge_hw_device_config *device_config,
3691 u64 vpath_mask, struct vxge_config *config_param)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003692{
3693 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3694 u32 txdl_size, txdl_per_memblock;
3695
3696 temp = driver_config->vpath_per_dev;
3697 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3698 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3699 /* No more CPU. Return vpath number as zero.*/
3700 if (driver_config->g_no_cpus == -1)
3701 return 0;
3702
3703 if (!driver_config->g_no_cpus)
Yuval Mintz9cbb5762012-07-01 03:18:52 +00003704 driver_config->g_no_cpus =
3705 netif_get_num_default_rss_queues();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003706
3707 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3708 if (!driver_config->vpath_per_dev)
3709 driver_config->vpath_per_dev = 1;
3710
3711 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3712 if (!vxge_bVALn(vpath_mask, i, 1))
3713 continue;
3714 else
3715 default_no_vpath++;
3716 if (default_no_vpath < driver_config->vpath_per_dev)
3717 driver_config->vpath_per_dev = default_no_vpath;
3718
3719 driver_config->g_no_cpus = driver_config->g_no_cpus -
3720 (driver_config->vpath_per_dev * 2);
3721 if (driver_config->g_no_cpus <= 0)
3722 driver_config->g_no_cpus = -1;
3723 }
3724
3725 if (driver_config->vpath_per_dev == 1) {
3726 vxge_debug_ll_config(VXGE_TRACE,
3727 "%s: Disable tx and rx steering, "
3728 "as single vpath is configured", VXGE_DRIVER_NAME);
3729 config_param->rth_steering = NO_STEERING;
3730 config_param->tx_steering_type = NO_STEERING;
3731 device_config->rth_en = 0;
3732 }
3733
3734 /* configure bandwidth */
3735 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3736 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3737
3738 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3739 device_config->vp_config[i].vp_id = i;
3740 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3741 if (no_of_vpaths < driver_config->vpath_per_dev) {
3742 if (!vxge_bVALn(vpath_mask, i, 1)) {
3743 vxge_debug_ll_config(VXGE_TRACE,
3744 "%s: vpath: %d is not available",
3745 VXGE_DRIVER_NAME, i);
3746 continue;
3747 } else {
3748 vxge_debug_ll_config(VXGE_TRACE,
3749 "%s: vpath: %d available",
3750 VXGE_DRIVER_NAME, i);
3751 no_of_vpaths++;
3752 }
3753 } else {
3754 vxge_debug_ll_config(VXGE_TRACE,
3755 "%s: vpath: %d is not configured, "
3756 "max_config_vpath exceeded",
3757 VXGE_DRIVER_NAME, i);
3758 break;
3759 }
3760
3761 /* Configure Tx fifo's */
3762 device_config->vp_config[i].fifo.enable =
3763 VXGE_HW_FIFO_ENABLE;
3764 device_config->vp_config[i].fifo.max_frags =
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003765 MAX_SKB_FRAGS + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003766 device_config->vp_config[i].fifo.memblock_size =
3767 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3768
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003769 txdl_size = device_config->vp_config[i].fifo.max_frags *
3770 sizeof(struct vxge_hw_fifo_txd);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003771 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3772
3773 device_config->vp_config[i].fifo.fifo_blocks =
3774 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3775
3776 device_config->vp_config[i].fifo.intr =
3777 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3778
3779 /* Configure tti properties */
3780 device_config->vp_config[i].tti.intr_enable =
3781 VXGE_HW_TIM_INTR_ENABLE;
3782
3783 device_config->vp_config[i].tti.btimer_val =
3784 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3785
3786 device_config->vp_config[i].tti.timer_ac_en =
3787 VXGE_HW_TIM_TIMER_AC_ENABLE;
3788
Jon Mason528f7272010-12-10 14:02:56 +00003789 /* For msi-x with napi (each vector has a handler of its own) -
3790 * Set CI to OFF for all vpaths
3791 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003792 device_config->vp_config[i].tti.timer_ci_en =
3793 VXGE_HW_TIM_TIMER_CI_DISABLE;
3794
3795 device_config->vp_config[i].tti.timer_ri_en =
3796 VXGE_HW_TIM_TIMER_RI_DISABLE;
3797
3798 device_config->vp_config[i].tti.util_sel =
3799 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3800
3801 device_config->vp_config[i].tti.ltimer_val =
3802 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3803
3804 device_config->vp_config[i].tti.rtimer_val =
3805 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3806
3807 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3808 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3809 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3810 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3811 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3812 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3813 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3814
3815 /* Configure Rx rings */
3816 device_config->vp_config[i].ring.enable =
3817 VXGE_HW_RING_ENABLE;
3818
3819 device_config->vp_config[i].ring.ring_blocks =
3820 VXGE_HW_DEF_RING_BLOCKS;
Jon Mason528f7272010-12-10 14:02:56 +00003821
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003822 device_config->vp_config[i].ring.buffer_mode =
3823 VXGE_HW_RING_RXD_BUFFER_MODE_1;
Jon Mason528f7272010-12-10 14:02:56 +00003824
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003825 device_config->vp_config[i].ring.rxds_limit =
3826 VXGE_HW_DEF_RING_RXDS_LIMIT;
Jon Mason528f7272010-12-10 14:02:56 +00003827
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003828 device_config->vp_config[i].ring.scatter_mode =
3829 VXGE_HW_RING_SCATTER_MODE_A;
3830
3831 /* Configure rti properties */
3832 device_config->vp_config[i].rti.intr_enable =
3833 VXGE_HW_TIM_INTR_ENABLE;
3834
3835 device_config->vp_config[i].rti.btimer_val =
3836 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3837
3838 device_config->vp_config[i].rti.timer_ac_en =
3839 VXGE_HW_TIM_TIMER_AC_ENABLE;
3840
3841 device_config->vp_config[i].rti.timer_ci_en =
3842 VXGE_HW_TIM_TIMER_CI_DISABLE;
3843
3844 device_config->vp_config[i].rti.timer_ri_en =
3845 VXGE_HW_TIM_TIMER_RI_DISABLE;
3846
3847 device_config->vp_config[i].rti.util_sel =
3848 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3849
3850 device_config->vp_config[i].rti.urange_a =
3851 RTI_RX_URANGE_A;
3852 device_config->vp_config[i].rti.urange_b =
3853 RTI_RX_URANGE_B;
3854 device_config->vp_config[i].rti.urange_c =
3855 RTI_RX_URANGE_C;
3856 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3857 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3858 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3859 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3860
3861 device_config->vp_config[i].rti.rtimer_val =
3862 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3863
3864 device_config->vp_config[i].rti.ltimer_val =
3865 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3866
3867 device_config->vp_config[i].rpa_strip_vlan_tag =
3868 vlan_tag_strip;
3869 }
3870
3871 driver_config->vpath_per_dev = temp;
3872 return no_of_vpaths;
3873}
3874
3875/* initialize device configuratrions */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003876static void vxge_device_config_init(struct vxge_hw_device_config *device_config,
3877 int *intr_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003878{
3879 /* Used for CQRQ/SRQ. */
3880 device_config->dma_blockpool_initial =
3881 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3882
3883 device_config->dma_blockpool_max =
3884 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3885
3886 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3887 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3888
3889#ifndef CONFIG_PCI_MSI
3890 vxge_debug_init(VXGE_ERR,
3891 "%s: This Kernel does not support "
3892 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3893 *intr_type = INTA;
3894#endif
3895
3896 /* Configure whether MSI-X or IRQL. */
3897 switch (*intr_type) {
3898 case INTA:
3899 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3900 break;
3901
3902 case MSI_X:
Jon Mason16fded72011-01-18 15:02:21 +00003903 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003904 break;
3905 }
Jon Mason528f7272010-12-10 14:02:56 +00003906
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003907 /* Timer period between device poll */
3908 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3909
3910 /* Configure mac based steering. */
3911 device_config->rts_mac_en = addr_learn_en;
3912
3913 /* Configure Vpaths */
3914 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3915
3916 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3917 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003918 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3919 device_config->intr_mode);
3920 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3921 device_config->device_poll_millis);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003922 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3923 device_config->rth_en);
3924 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3925 device_config->rth_it_type);
3926}
3927
Bill Pemberton3a036ce2012-12-03 09:23:18 -05003928static void vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003929{
3930 int i;
3931
3932 vxge_debug_init(VXGE_TRACE,
3933 "%s: %d Vpath(s) opened",
3934 vdev->ndev->name, vdev->no_of_vpath);
3935
3936 switch (vdev->config.intr_type) {
3937 case INTA:
3938 vxge_debug_init(VXGE_TRACE,
3939 "%s: Interrupt type INTA", vdev->ndev->name);
3940 break;
3941
3942 case MSI_X:
3943 vxge_debug_init(VXGE_TRACE,
3944 "%s: Interrupt type MSI-X", vdev->ndev->name);
3945 break;
3946 }
3947
3948 if (vdev->config.rth_steering) {
3949 vxge_debug_init(VXGE_TRACE,
3950 "%s: RTH steering enabled for TCP_IPV4",
3951 vdev->ndev->name);
3952 } else {
3953 vxge_debug_init(VXGE_TRACE,
3954 "%s: RTH steering disabled", vdev->ndev->name);
3955 }
3956
3957 switch (vdev->config.tx_steering_type) {
3958 case NO_STEERING:
3959 vxge_debug_init(VXGE_TRACE,
3960 "%s: Tx steering disabled", vdev->ndev->name);
3961 break;
3962 case TX_PRIORITY_STEERING:
3963 vxge_debug_init(VXGE_TRACE,
3964 "%s: Unsupported tx steering option",
3965 vdev->ndev->name);
3966 vxge_debug_init(VXGE_TRACE,
3967 "%s: Tx steering disabled", vdev->ndev->name);
3968 vdev->config.tx_steering_type = 0;
3969 break;
3970 case TX_VLAN_STEERING:
3971 vxge_debug_init(VXGE_TRACE,
3972 "%s: Unsupported tx steering option",
3973 vdev->ndev->name);
3974 vxge_debug_init(VXGE_TRACE,
3975 "%s: Tx steering disabled", vdev->ndev->name);
3976 vdev->config.tx_steering_type = 0;
3977 break;
3978 case TX_MULTIQ_STEERING:
3979 vxge_debug_init(VXGE_TRACE,
3980 "%s: Tx multiqueue steering enabled",
3981 vdev->ndev->name);
3982 break;
3983 case TX_PORT_STEERING:
3984 vxge_debug_init(VXGE_TRACE,
3985 "%s: Tx port steering enabled",
3986 vdev->ndev->name);
3987 break;
3988 default:
3989 vxge_debug_init(VXGE_ERR,
3990 "%s: Unsupported tx steering type",
3991 vdev->ndev->name);
3992 vxge_debug_init(VXGE_TRACE,
3993 "%s: Tx steering disabled", vdev->ndev->name);
3994 vdev->config.tx_steering_type = 0;
3995 }
3996
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003997 if (vdev->config.addr_learn_en)
3998 vxge_debug_init(VXGE_TRACE,
3999 "%s: MAC Address learning enabled", vdev->ndev->name);
4000
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004001 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4002 if (!vxge_bVALn(vpath_mask, i, 1))
4003 continue;
4004 vxge_debug_ll_config(VXGE_TRACE,
4005 "%s: MTU size - %d", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004006 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004007 config.vp_config[i].mtu);
4008 vxge_debug_init(VXGE_TRACE,
4009 "%s: VLAN tag stripping %s", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004010 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004011 config.vp_config[i].rpa_strip_vlan_tag
4012 ? "Enabled" : "Disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004013 vxge_debug_ll_config(VXGE_TRACE,
4014 "%s: Max frags : %d", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004015 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004016 config.vp_config[i].fifo.max_frags);
4017 break;
4018 }
4019}
4020
4021#ifdef CONFIG_PM
4022/**
4023 * vxge_pm_suspend - vxge power management suspend entry point
4024 *
4025 */
4026static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4027{
4028 return -ENOSYS;
4029}
4030/**
4031 * vxge_pm_resume - vxge power management resume entry point
4032 *
4033 */
4034static int vxge_pm_resume(struct pci_dev *pdev)
4035{
4036 return -ENOSYS;
4037}
4038
4039#endif
4040
4041/**
4042 * vxge_io_error_detected - called when PCI error is detected
4043 * @pdev: Pointer to PCI device
4044 * @state: The current pci connection state
4045 *
4046 * This function is called after a PCI bus error affecting
4047 * this device has been detected.
4048 */
4049static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4050 pci_channel_state_t state)
4051{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004052 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004053 struct net_device *netdev = hldev->ndev;
4054
4055 netif_device_detach(netdev);
4056
Dean Nelsone33b9922009-07-31 09:14:03 +00004057 if (state == pci_channel_io_perm_failure)
4058 return PCI_ERS_RESULT_DISCONNECT;
4059
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004060 if (netif_running(netdev)) {
4061 /* Bring down the card, while avoiding PCI I/O */
4062 do_vxge_close(netdev, 0);
4063 }
4064
4065 pci_disable_device(pdev);
4066
4067 return PCI_ERS_RESULT_NEED_RESET;
4068}
4069
4070/**
4071 * vxge_io_slot_reset - called after the pci bus has been reset.
4072 * @pdev: Pointer to PCI device
4073 *
4074 * Restart the card from scratch, as if from a cold-boot.
4075 * At this point, the card has exprienced a hard reset,
4076 * followed by fixups by BIOS, and has its config space
4077 * set up identically to what it was at cold boot.
4078 */
4079static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4080{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004081 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004082 struct net_device *netdev = hldev->ndev;
4083
4084 struct vxgedev *vdev = netdev_priv(netdev);
4085
4086 if (pci_enable_device(pdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004087 netdev_err(netdev, "Cannot re-enable device after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004088 return PCI_ERS_RESULT_DISCONNECT;
4089 }
4090
4091 pci_set_master(pdev);
Jon Mason528f7272010-12-10 14:02:56 +00004092 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004093
4094 return PCI_ERS_RESULT_RECOVERED;
4095}
4096
4097/**
4098 * vxge_io_resume - called when traffic can start flowing again.
4099 * @pdev: Pointer to PCI device
4100 *
4101 * This callback is called when the error recovery driver tells
4102 * us that its OK to resume normal operation.
4103 */
4104static void vxge_io_resume(struct pci_dev *pdev)
4105{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004106 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004107 struct net_device *netdev = hldev->ndev;
4108
4109 if (netif_running(netdev)) {
4110 if (vxge_open(netdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004111 netdev_err(netdev,
4112 "Can't bring device back up after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004113 return;
4114 }
4115 }
4116
4117 netif_device_attach(netdev);
4118}
4119
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004120static inline u32 vxge_get_num_vfs(u64 function_mode)
4121{
4122 u32 num_functions = 0;
4123
4124 switch (function_mode) {
4125 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4126 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4127 num_functions = 8;
4128 break;
4129 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4130 num_functions = 1;
4131 break;
4132 case VXGE_HW_FUNCTION_MODE_SRIOV:
4133 case VXGE_HW_FUNCTION_MODE_MRIOV:
4134 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4135 num_functions = 17;
4136 break;
4137 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4138 num_functions = 4;
4139 break;
4140 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4141 num_functions = 2;
4142 break;
4143 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4144 num_functions = 8; /* TODO */
4145 break;
4146 }
4147 return num_functions;
4148}
4149
Jon Masone8ac1752010-11-11 04:25:57 +00004150int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4151{
4152 struct __vxge_hw_device *hldev = vdev->devh;
4153 u32 maj, min, bld, cmaj, cmin, cbld;
4154 enum vxge_hw_status status;
4155 const struct firmware *fw;
4156 int ret;
4157
4158 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4159 if (ret) {
4160 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4161 VXGE_DRIVER_NAME, fw_name);
4162 goto out;
4163 }
4164
4165 /* Load the new firmware onto the adapter */
4166 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4167 if (status != VXGE_HW_OK) {
4168 vxge_debug_init(VXGE_ERR,
4169 "%s: FW image download to adapter failed '%s'.",
4170 VXGE_DRIVER_NAME, fw_name);
4171 ret = -EIO;
4172 goto out;
4173 }
4174
4175 /* Read the version of the new firmware */
4176 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4177 if (status != VXGE_HW_OK) {
4178 vxge_debug_init(VXGE_ERR,
4179 "%s: Upgrade read version failed '%s'.",
4180 VXGE_DRIVER_NAME, fw_name);
4181 ret = -EIO;
4182 goto out;
4183 }
4184
4185 cmaj = vdev->config.device_hw_info.fw_version.major;
4186 cmin = vdev->config.device_hw_info.fw_version.minor;
4187 cbld = vdev->config.device_hw_info.fw_version.build;
4188 /* It's possible the version in /lib/firmware is not the latest version.
4189 * If so, we could get into a loop of trying to upgrade to the latest
4190 * and flashing the older version.
4191 */
4192 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4193 !override) {
4194 ret = -EINVAL;
4195 goto out;
4196 }
4197
4198 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4199 maj, min, bld);
4200
4201 /* Flash the adapter with the new firmware */
4202 status = vxge_hw_flash_fw(hldev);
4203 if (status != VXGE_HW_OK) {
4204 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4205 VXGE_DRIVER_NAME, fw_name);
4206 ret = -EIO;
4207 goto out;
4208 }
4209
4210 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4211 "hard reset before using, thus requiring a system reboot or a "
4212 "hotplug event.\n");
4213
4214out:
Jesper Juhle84f8852011-01-13 10:25:20 +00004215 release_firmware(fw);
Jon Masone8ac1752010-11-11 04:25:57 +00004216 return ret;
4217}
4218
4219static int vxge_probe_fw_update(struct vxgedev *vdev)
4220{
4221 u32 maj, min, bld;
4222 int ret, gpxe = 0;
4223 char *fw_name;
4224
4225 maj = vdev->config.device_hw_info.fw_version.major;
4226 min = vdev->config.device_hw_info.fw_version.minor;
4227 bld = vdev->config.device_hw_info.fw_version.build;
4228
4229 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4230 return 0;
4231
4232 /* Ignore the build number when determining if the current firmware is
4233 * "too new" to load the driver
4234 */
4235 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4236 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4237 "version, unable to load driver\n",
4238 VXGE_DRIVER_NAME);
4239 return -EINVAL;
4240 }
4241
4242 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4243 * work with this driver.
4244 */
4245 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4246 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4247 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4248 return -EINVAL;
4249 }
4250
4251 /* If file not specified, determine gPXE or not */
4252 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4253 int i;
4254 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4255 if (vdev->devh->eprom_versions[i]) {
4256 gpxe = 1;
4257 break;
4258 }
4259 }
4260 if (gpxe)
4261 fw_name = "vxge/X3fw-pxe.ncf";
4262 else
4263 fw_name = "vxge/X3fw.ncf";
4264
4265 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4266 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4267 * probe, so ignore them
4268 */
4269 if (ret != -EINVAL && ret != -ENOENT)
4270 return -EIO;
4271 else
4272 ret = 0;
4273
4274 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4275 VXGE_FW_VER(maj, min, 0)) {
4276 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
Jon Masonc0589fa2012-07-09 14:07:57 +00004277 " be used with this driver.",
Jon Masone8ac1752010-11-11 04:25:57 +00004278 VXGE_DRIVER_NAME, maj, min, bld);
4279 return -EINVAL;
4280 }
4281
4282 return ret;
4283}
4284
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004285static int is_sriov_initialized(struct pci_dev *pdev)
Jon Masonc92bf702010-12-10 14:02:57 +00004286{
4287 int pos;
4288 u16 ctrl;
4289
4290 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4291 if (pos) {
4292 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4293 if (ctrl & PCI_SRIOV_CTRL_VFE)
4294 return 1;
4295 }
4296 return 0;
4297}
4298
stephen hemminger956a2062011-09-16 11:10:01 +00004299static const struct vxge_hw_uld_cbs vxge_callbacks = {
4300 .link_up = vxge_callback_link_up,
4301 .link_down = vxge_callback_link_down,
4302 .crit_err = vxge_callback_crit_err,
4303};
4304
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004305/**
4306 * vxge_probe
4307 * @pdev : structure containing the PCI related information of the device.
4308 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4309 * Description:
4310 * This function is called when a new PCI device gets detected and initializes
4311 * it.
4312 * Return value:
4313 * returns 0 on success and negative on failure.
4314 *
4315 */
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004316static int
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004317vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4318{
Jon Mason2c913082010-11-11 04:26:03 +00004319 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004320 enum vxge_hw_status status;
4321 int ret;
4322 int high_dma = 0;
4323 u64 vpath_mask = 0;
4324 struct vxgedev *vdev;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004325 struct vxge_config *ll_config = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004326 struct vxge_hw_device_config *device_config = NULL;
4327 struct vxge_hw_device_attr attr;
4328 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4329 u8 *macaddr;
4330 struct vxge_mac_addrs *entry;
4331 static int bus = -1, device = -1;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004332 u32 host_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004333 u8 new_device = 0;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004334 enum vxge_hw_status is_privileged;
4335 u32 function_mode;
4336 u32 num_vfs = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004337
4338 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4339 attr.pdev = pdev;
4340
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004341 /* In SRIOV-17 mode, functions of the same adapter
Jon Mason528f7272010-12-10 14:02:56 +00004342 * can be deployed on different buses
4343 */
4344 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4345 !pdev->is_virtfn)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004346 new_device = 1;
4347
4348 bus = pdev->bus->number;
4349 device = PCI_SLOT(pdev->devfn);
4350
4351 if (new_device) {
4352 if (driver_config->config_dev_cnt &&
4353 (driver_config->config_dev_cnt !=
4354 driver_config->total_dev_cnt))
4355 vxge_debug_init(VXGE_ERR,
4356 "%s: Configured %d of %d devices",
4357 VXGE_DRIVER_NAME,
4358 driver_config->config_dev_cnt,
4359 driver_config->total_dev_cnt);
4360 driver_config->config_dev_cnt = 0;
4361 driver_config->total_dev_cnt = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004362 }
Jon Mason528f7272010-12-10 14:02:56 +00004363
Sreenivasa Honnur90023972010-04-08 01:48:30 -07004364 /* Now making the CPU based no of vpath calculation
4365 * applicable for individual functions as well.
4366 */
4367 driver_config->g_no_cpus = 0;
Sreenivasa Honnur657205b2009-10-05 01:52:54 +00004368 driver_config->vpath_per_dev = max_config_vpath;
4369
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004370 driver_config->total_dev_cnt++;
4371 if (++driver_config->config_dev_cnt > max_config_dev) {
4372 ret = 0;
4373 goto _exit0;
4374 }
4375
4376 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4377 GFP_KERNEL);
4378 if (!device_config) {
4379 ret = -ENOMEM;
4380 vxge_debug_init(VXGE_ERR,
4381 "device_config : malloc failed %s %d",
4382 __FILE__, __LINE__);
4383 goto _exit0;
4384 }
4385
Jon Mason528f7272010-12-10 14:02:56 +00004386 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004387 if (!ll_config) {
4388 ret = -ENOMEM;
4389 vxge_debug_init(VXGE_ERR,
Jon Mason528f7272010-12-10 14:02:56 +00004390 "device_config : malloc failed %s %d",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004391 __FILE__, __LINE__);
4392 goto _exit0;
4393 }
4394 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4395 ll_config->intr_type = MSI_X;
4396 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4397 ll_config->rth_steering = RTH_STEERING;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004398
4399 /* get the default configuration parameters */
4400 vxge_hw_device_config_default_get(device_config);
4401
4402 /* initialize configuration parameters */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004403 vxge_device_config_init(device_config, &ll_config->intr_type);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004404
4405 ret = pci_enable_device(pdev);
4406 if (ret) {
4407 vxge_debug_init(VXGE_ERR,
4408 "%s : can not enable PCI device", __func__);
4409 goto _exit0;
4410 }
4411
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004412 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004413 vxge_debug_ll_config(VXGE_TRACE,
4414 "%s : using 64bit DMA", __func__);
4415
4416 high_dma = 1;
4417
4418 if (pci_set_consistent_dma_mask(pdev,
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004419 DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004420 vxge_debug_init(VXGE_ERR,
4421 "%s : unable to obtain 64bit DMA for "
4422 "consistent allocations", __func__);
4423 ret = -ENOMEM;
4424 goto _exit1;
4425 }
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004426 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004427 vxge_debug_ll_config(VXGE_TRACE,
4428 "%s : using 32bit DMA", __func__);
4429 } else {
4430 ret = -ENOMEM;
4431 goto _exit1;
4432 }
4433
Jon Mason6cca2002011-01-18 15:02:19 +00004434 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4435 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004436 vxge_debug_init(VXGE_ERR,
4437 "%s : request regions failed", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004438 goto _exit1;
4439 }
4440
4441 pci_set_master(pdev);
4442
4443 attr.bar0 = pci_ioremap_bar(pdev, 0);
4444 if (!attr.bar0) {
4445 vxge_debug_init(VXGE_ERR,
4446 "%s : cannot remap io memory bar0", __func__);
4447 ret = -ENODEV;
4448 goto _exit2;
4449 }
4450 vxge_debug_ll_config(VXGE_TRACE,
4451 "pci ioremap bar0: %p:0x%llx",
4452 attr.bar0,
4453 (unsigned long long)pci_resource_start(pdev, 0));
4454
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004455 status = vxge_hw_device_hw_info_get(attr.bar0,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004456 &ll_config->device_hw_info);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004457 if (status != VXGE_HW_OK) {
4458 vxge_debug_init(VXGE_ERR,
4459 "%s: Reading of hardware info failed."
4460 "Please try upgrading the firmware.", 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
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004465 vpath_mask = ll_config->device_hw_info.vpath_mask;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004466 if (vpath_mask == 0) {
4467 vxge_debug_ll_config(VXGE_TRACE,
4468 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4469 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004470 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004471 }
4472
4473 vxge_debug_ll_config(VXGE_TRACE,
4474 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4475 (unsigned long long)vpath_mask);
4476
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004477 function_mode = ll_config->device_hw_info.function_mode;
4478 host_type = ll_config->device_hw_info.host_type;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004479 is_privileged = __vxge_hw_device_is_privilaged(host_type,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004480 ll_config->device_hw_info.func_id);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004481
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004482 /* Check how many vpaths are available */
4483 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4484 if (!((vpath_mask) & vxge_mBIT(i)))
4485 continue;
4486 max_vpath_supported++;
4487 }
4488
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004489 if (new_device)
4490 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4491
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004492 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
Jon Masonc92bf702010-12-10 14:02:57 +00004493 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4494 (ll_config->intr_type != INTA)) {
4495 ret = pci_enable_sriov(pdev, num_vfs);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004496 if (ret)
4497 vxge_debug_ll_config(VXGE_ERR,
4498 "Failed in enabling SRIOV mode: %d\n", ret);
Jon Masonc92bf702010-12-10 14:02:57 +00004499 /* No need to fail out, as an error here is non-fatal */
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004500 }
4501
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004502 /*
4503 * Configure vpaths and get driver configured number of vpaths
4504 * which is less than or equal to the maximum vpaths per function.
4505 */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004506 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004507 if (!no_of_vpath) {
4508 vxge_debug_ll_config(VXGE_ERR,
4509 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4510 ret = 0;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004511 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004512 }
4513
4514 /* Setting driver callbacks */
stephen hemminger956a2062011-09-16 11:10:01 +00004515 attr.uld_callbacks = &vxge_callbacks;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004516
4517 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4518 if (status != VXGE_HW_OK) {
4519 vxge_debug_init(VXGE_ERR,
4520 "Failed to initialize device (%d)", status);
4521 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004522 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004523 }
4524
Jon Masone8ac1752010-11-11 04:25:57 +00004525 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4526 ll_config->device_hw_info.fw_version.minor,
4527 ll_config->device_hw_info.fw_version.build) >=
4528 VXGE_EPROM_FW_VER) {
4529 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4530
4531 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4532 if (status != VXGE_HW_OK) {
4533 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4534 VXGE_DRIVER_NAME);
4535 /* This is a non-fatal error, continue */
4536 }
4537
4538 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4539 hldev->eprom_versions[i] = img[i].version;
4540 if (!img[i].is_valid)
4541 break;
4542 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
Jon Mason1d15f812011-01-18 15:02:20 +00004543 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
Jon Masone8ac1752010-11-11 04:25:57 +00004544 VXGE_EPROM_IMG_MAJOR(img[i].version),
4545 VXGE_EPROM_IMG_MINOR(img[i].version),
4546 VXGE_EPROM_IMG_FIX(img[i].version),
4547 VXGE_EPROM_IMG_BUILD(img[i].version));
4548 }
4549 }
4550
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004551 /* if FCS stripping is not disabled in MAC fail driver load */
Jon Masonb81b3732010-11-11 04:25:58 +00004552 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4553 if (status != VXGE_HW_OK) {
4554 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4555 " failing driver load", VXGE_DRIVER_NAME);
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004556 ret = -EINVAL;
4557 goto _exit4;
4558 }
4559
Jon Masoncd883a72011-04-08 11:11:21 +00004560 /* Always enable HWTS. This will always cause the FCS to be invalid,
4561 * due to the fact that HWTS is using the FCS as the location of the
4562 * timestamp. The HW FCS checking will still correctly determine if
4563 * there is a valid checksum, and the FCS is being removed by the driver
4564 * anyway. So no fucntionality is being lost. Since it is always
4565 * enabled, we now simply use the ioctl call to set whether or not the
4566 * driver should be paying attention to the HWTS.
4567 */
4568 if (is_privileged == VXGE_HW_OK) {
4569 status = vxge_timestamp_config(hldev);
4570 if (status != VXGE_HW_OK) {
4571 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4572 VXGE_DRIVER_NAME);
4573 ret = -EFAULT;
4574 goto _exit4;
4575 }
4576 }
4577
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004578 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4579
4580 /* set private device info */
4581 pci_set_drvdata(pdev, hldev);
4582
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004583 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4584 ll_config->addr_learn_en = addr_learn_en;
4585 ll_config->rth_algorithm = RTH_ALG_JENKINS;
Jon Mason47f01db2010-11-11 04:25:53 +00004586 ll_config->rth_hash_type_tcpipv4 = 1;
4587 ll_config->rth_hash_type_ipv4 = 0;
4588 ll_config->rth_hash_type_tcpipv6 = 0;
4589 ll_config->rth_hash_type_ipv6 = 0;
4590 ll_config->rth_hash_type_tcpipv6ex = 0;
4591 ll_config->rth_hash_type_ipv6ex = 0;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004592 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4593 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4594 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004595
Jon Masone8ac1752010-11-11 04:25:57 +00004596 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4597 &vdev);
4598 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004599 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004600 goto _exit4;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004601 }
4602
Jon Masone8ac1752010-11-11 04:25:57 +00004603 ret = vxge_probe_fw_update(vdev);
4604 if (ret)
4605 goto _exit5;
4606
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004607 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4608 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4609 vxge_hw_device_trace_level_get(hldev));
4610
4611 /* set private HW device info */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004612 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4613 vdev->bar0 = attr.bar0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004614 vdev->max_vpath_supported = max_vpath_supported;
4615 vdev->no_of_vpath = no_of_vpath;
4616
4617 /* Virtual Path count */
4618 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4619 if (!vxge_bVALn(vpath_mask, i, 1))
4620 continue;
4621 if (j >= vdev->no_of_vpath)
4622 break;
4623
4624 vdev->vpaths[j].is_configured = 1;
4625 vdev->vpaths[j].device_id = i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004626 vdev->vpaths[j].ring.driver_id = j;
4627 vdev->vpaths[j].vdev = vdev;
4628 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4629 memcpy((u8 *)vdev->vpaths[j].macaddr,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004630 ll_config->device_hw_info.mac_addrs[i],
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004631 ETH_ALEN);
4632
4633 /* Initialize the mac address list header */
4634 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4635
4636 vdev->vpaths[j].mac_addr_cnt = 0;
4637 vdev->vpaths[j].mcast_addr_cnt = 0;
4638 j++;
4639 }
4640 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4641 vdev->max_config_port = max_config_port;
4642
4643 vdev->vlan_tag_strip = vlan_tag_strip;
4644
4645 /* map the hashing selector table to the configured vpaths */
4646 for (i = 0; i < vdev->no_of_vpath; i++)
4647 vdev->vpath_selector[i] = vpath_selector[i];
4648
4649 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4650
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004651 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4652 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4653 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004654
4655 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004656 vdev->ndev->name, ll_config->device_hw_info.serial_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004657
4658 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004659 vdev->ndev->name, ll_config->device_hw_info.part_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004660
4661 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004662 vdev->ndev->name, ll_config->device_hw_info.product_desc);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004663
hartleysbf54e732010-01-05 06:59:23 +00004664 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4665 vdev->ndev->name, macaddr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004666
4667 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4668 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4669
4670 vxge_debug_init(VXGE_TRACE,
4671 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004672 ll_config->device_hw_info.fw_version.version,
4673 ll_config->device_hw_info.fw_date.date);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004674
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004675 if (new_device) {
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004676 switch (ll_config->device_hw_info.function_mode) {
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004677 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4678 vxge_debug_init(VXGE_TRACE,
4679 "%s: Single Function Mode Enabled", vdev->ndev->name);
4680 break;
4681 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4682 vxge_debug_init(VXGE_TRACE,
4683 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4684 break;
4685 case VXGE_HW_FUNCTION_MODE_SRIOV:
4686 vxge_debug_init(VXGE_TRACE,
4687 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4688 break;
4689 case VXGE_HW_FUNCTION_MODE_MRIOV:
4690 vxge_debug_init(VXGE_TRACE,
4691 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4692 break;
4693 }
4694 }
4695
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004696 vxge_print_parm(vdev, vpath_mask);
4697
4698 /* Store the fw version for ethttool option */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004699 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004700 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004701
4702 /* Copy the station mac address to the list */
4703 for (i = 0; i < vdev->no_of_vpath; i++) {
Joe Perchese80be0b2010-11-27 23:05:45 +00004704 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004705 if (NULL == entry) {
4706 vxge_debug_init(VXGE_ERR,
4707 "%s: mac_addr_list : memory allocation failed",
4708 vdev->ndev->name);
4709 ret = -EPERM;
Jon Masone8ac1752010-11-11 04:25:57 +00004710 goto _exit6;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004711 }
4712 macaddr = (u8 *)&entry->macaddr;
4713 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4714 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4715 vdev->vpaths[i].mac_addr_cnt = 1;
4716 }
4717
Sreenivasa Honnur914d0d72009-07-01 21:13:12 +00004718 kfree(device_config);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004719
4720 /*
4721 * INTA is shared in multi-function mode. This is unlike the INTA
4722 * implementation in MR mode, where each VH has its own INTA message.
4723 * - INTA is masked (disabled) as long as at least one function sets
4724 * its TITAN_MASK_ALL_INT.ALARM bit.
4725 * - INTA is unmasked (enabled) when all enabled functions have cleared
4726 * their own TITAN_MASK_ALL_INT.ALARM bit.
4727 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4728 * Though this driver leaves the top level interrupts unmasked while
4729 * leaving the required module interrupt bits masked on exit, there
4730 * could be a rougue driver around that does not follow this procedure
4731 * resulting in a failure to generate interrupts. The following code is
4732 * present to prevent such a failure.
4733 */
4734
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004735 if (ll_config->device_hw_info.function_mode ==
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004736 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4737 if (vdev->config.intr_type == INTA)
4738 vxge_hw_device_unmask_all(hldev);
4739
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004740 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4741 vdev->ndev->name, __func__, __LINE__);
4742
4743 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4744 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4745 vxge_hw_device_trace_level_get(hldev));
4746
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004747 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004748 return 0;
4749
Jon Masone8ac1752010-11-11 04:25:57 +00004750_exit6:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004751 for (i = 0; i < vdev->no_of_vpath; i++)
4752 vxge_free_mac_add_list(&vdev->vpaths[i]);
Jon Masone8ac1752010-11-11 04:25:57 +00004753_exit5:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004754 vxge_device_unregister(hldev);
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004755_exit4:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004756 vxge_hw_device_terminate(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004757 pci_disable_sriov(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004758_exit3:
4759 iounmap(attr.bar0);
4760_exit2:
Jon Masondc66daa2010-12-10 14:02:58 +00004761 pci_release_region(pdev, 0);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004762_exit1:
4763 pci_disable_device(pdev);
4764_exit0:
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004765 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004766 kfree(device_config);
4767 driver_config->config_dev_cnt--;
Jon Mason6cca2002011-01-18 15:02:19 +00004768 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004769 return ret;
4770}
4771
4772/**
4773 * vxge_rem_nic - Free the PCI device
4774 * @pdev: structure containing the PCI related information of the device.
4775 * Description: This function is called by the Pci subsystem to release a
4776 * PCI device and free up all resource held up by the device.
4777 */
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004778static void vxge_remove(struct pci_dev *pdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004779{
Jon Mason2c913082010-11-11 04:26:03 +00004780 struct __vxge_hw_device *hldev;
Jon Mason6cca2002011-01-18 15:02:19 +00004781 struct vxgedev *vdev;
4782 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004783
Joe Perchesd8ee7072010-11-15 10:13:58 +00004784 hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004785 if (hldev == NULL)
4786 return;
Jon Mason2c913082010-11-11 04:26:03 +00004787
Jon Mason6cca2002011-01-18 15:02:19 +00004788 vdev = netdev_priv(hldev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004789
Jon Mason2c913082010-11-11 04:26:03 +00004790 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004791 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4792 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004793
Jon Mason6cca2002011-01-18 15:02:19 +00004794 for (i = 0; i < vdev->no_of_vpath; i++)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004795 vxge_free_mac_add_list(&vdev->vpaths[i]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004796
Jon Mason6cca2002011-01-18 15:02:19 +00004797 vxge_device_unregister(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004798 /* Do not call pci_disable_sriov here, as it will break child devices */
4799 vxge_hw_device_terminate(hldev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004800 iounmap(vdev->bar0);
Jon Mason6cca2002011-01-18 15:02:19 +00004801 pci_release_region(pdev, 0);
4802 pci_disable_device(pdev);
4803 driver_config->config_dev_cnt--;
4804 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004805
Jon Mason2c913082010-11-11 04:26:03 +00004806 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4807 __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004808 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4809 __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004810}
4811
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07004812static const struct pci_error_handlers vxge_err_handler = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004813 .error_detected = vxge_io_error_detected,
4814 .slot_reset = vxge_io_slot_reset,
4815 .resume = vxge_io_resume,
4816};
4817
4818static struct pci_driver vxge_driver = {
4819 .name = VXGE_DRIVER_NAME,
4820 .id_table = vxge_id_table,
4821 .probe = vxge_probe,
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004822 .remove = vxge_remove,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004823#ifdef CONFIG_PM
4824 .suspend = vxge_pm_suspend,
4825 .resume = vxge_pm_resume,
4826#endif
4827 .err_handler = &vxge_err_handler,
4828};
4829
4830static int __init
4831vxge_starter(void)
4832{
4833 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004834
Joe Perches75f5e1c2010-07-27 11:47:03 +00004835 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4836 pr_info("Driver version: %s\n", DRV_VERSION);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004837
4838 verify_bandwidth();
4839
4840 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4841 if (!driver_config)
4842 return -ENOMEM;
4843
4844 ret = pci_register_driver(&vxge_driver);
Jon Mason528f7272010-12-10 14:02:56 +00004845 if (ret) {
4846 kfree(driver_config);
4847 goto err;
4848 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004849
4850 if (driver_config->config_dev_cnt &&
4851 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4852 vxge_debug_init(VXGE_ERR,
4853 "%s: Configured %d of %d devices",
4854 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4855 driver_config->total_dev_cnt);
Jon Mason528f7272010-12-10 14:02:56 +00004856err:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004857 return ret;
4858}
4859
4860static void __exit
4861vxge_closer(void)
4862{
4863 pci_unregister_driver(&vxge_driver);
4864 kfree(driver_config);
4865}
4866module_init(vxge_starter);
4867module_exit(vxge_closer);