blob: d107bcbb8543035110a98a82a21a7e72c8ec1303 [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
Eric W. Biedermanc7b82cc2014-03-14 18:10:50 -0700371 if (ring->budget <= 0)
372 goto out;
373
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000374 do {
Benjamin LaHaise3f23e432009-08-04 10:21:39 +0000375 prefetch((char *)dtr + L1_CACHE_BYTES);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000376 rx_priv = vxge_hw_ring_rxd_private_get(dtr);
377 skb = rx_priv->skb;
378 data_size = rx_priv->data_size;
379 data_dma = rx_priv->data_dma;
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +0000380 prefetch(rx_priv->skb_data);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000381
382 vxge_debug_rx(VXGE_TRACE,
383 "%s: %s:%d skb = 0x%p",
384 ring->ndev->name, __func__, __LINE__, skb);
385
386 vxge_hw_ring_rxd_1b_get(ringh, dtr, &dma_sizes);
387 pkt_length = dma_sizes;
388
Sreenivasa Honnur22fa1252009-07-01 21:17:24 +0000389 pkt_length -= ETH_FCS_LEN;
390
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000391 vxge_debug_rx(VXGE_TRACE,
392 "%s: %s:%d Packet Length = %d",
393 ring->ndev->name, __func__, __LINE__, pkt_length);
394
395 vxge_hw_ring_rxd_1b_info_get(ringh, dtr, &ext_info);
396
397 /* check skb validity */
398 vxge_assert(skb);
399
400 prefetch((char *)skb + L1_CACHE_BYTES);
401 if (unlikely(t_code)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000402 if (vxge_hw_ring_handle_tcode(ringh, dtr, t_code) !=
403 VXGE_HW_OK) {
404
405 ring->stats.rx_errors++;
406 vxge_debug_rx(VXGE_TRACE,
407 "%s: %s :%d Rx T_code is %d",
408 ring->ndev->name, __func__,
409 __LINE__, t_code);
410
411 /* If the t_code is not supported and if the
412 * t_code is other than 0x5 (unparseable packet
413 * such as unknown UPV6 header), Drop it !!!
414 */
415 vxge_re_pre_post(dtr, ring, rx_priv);
416
417 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
418 ring->stats.rx_dropped++;
419 continue;
420 }
421 }
422
423 if (pkt_length > VXGE_LL_RX_COPY_THRESHOLD) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000424 if (vxge_rx_alloc(dtr, ring, data_size) != NULL) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000425 if (!vxge_rx_map(dtr, ring)) {
426 skb_put(skb, pkt_length);
427
428 pci_unmap_single(ring->pdev, data_dma,
429 data_size, PCI_DMA_FROMDEVICE);
430
431 vxge_hw_ring_rxd_pre_post(ringh, dtr);
432 vxge_post(&dtr_cnt, &first_dtr, dtr,
433 ringh);
434 } else {
435 dev_kfree_skb(rx_priv->skb);
436 rx_priv->skb = skb;
437 rx_priv->data_size = data_size;
438 vxge_re_pre_post(dtr, ring, rx_priv);
439
440 vxge_post(&dtr_cnt, &first_dtr, dtr,
441 ringh);
442 ring->stats.rx_dropped++;
443 break;
444 }
445 } else {
446 vxge_re_pre_post(dtr, ring, rx_priv);
447
448 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
449 ring->stats.rx_dropped++;
450 break;
451 }
452 } else {
453 struct sk_buff *skb_up;
454
455 skb_up = netdev_alloc_skb(dev, pkt_length +
456 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
457 if (skb_up != NULL) {
458 skb_reserve(skb_up,
459 VXGE_HW_HEADER_ETHERNET_II_802_3_ALIGN);
460
461 pci_dma_sync_single_for_cpu(ring->pdev,
462 data_dma, data_size,
463 PCI_DMA_FROMDEVICE);
464
465 vxge_debug_mem(VXGE_TRACE,
466 "%s: %s:%d skb_up = %p",
467 ring->ndev->name, __func__,
468 __LINE__, skb);
469 memcpy(skb_up->data, skb->data, pkt_length);
470
471 vxge_re_pre_post(dtr, ring, rx_priv);
472
473 vxge_post(&dtr_cnt, &first_dtr, dtr,
474 ringh);
475 /* will netif_rx small SKB instead */
476 skb = skb_up;
477 skb_put(skb, pkt_length);
478 } else {
479 vxge_re_pre_post(dtr, ring, rx_priv);
480
481 vxge_post(&dtr_cnt, &first_dtr, dtr, ringh);
482 vxge_debug_rx(VXGE_ERR,
483 "%s: vxge_rx_1b_compl: out of "
484 "memory", dev->name);
485 ring->stats.skb_alloc_fail++;
486 break;
487 }
488 }
489
490 if ((ext_info.proto & VXGE_HW_FRAME_PROTO_TCP_OR_UDP) &&
491 !(ext_info.proto & VXGE_HW_FRAME_PROTO_IP_FRAG) &&
Michał Mirosławfeb990d2011-04-18 13:31:21 +0000492 (dev->features & NETIF_F_RXCSUM) && /* Offload Rx side CSUM */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000493 ext_info.l3_cksum == VXGE_HW_L3_CKSUM_OK &&
494 ext_info.l4_cksum == VXGE_HW_L4_CKSUM_OK)
495 skb->ip_summed = CHECKSUM_UNNECESSARY;
496 else
Eric Dumazetbc8acf22010-09-02 13:07:41 -0700497 skb_checksum_none_assert(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000498
Jon Masonb81b3732010-11-11 04:25:58 +0000499
500 if (ring->rx_hwts) {
501 struct skb_shared_hwtstamps *skb_hwts;
502 u32 ns = *(u32 *)(skb->head + pkt_length);
503
504 skb_hwts = skb_hwtstamps(skb);
505 skb_hwts->hwtstamp = ns_to_ktime(ns);
506 skb_hwts->syststamp.tv64 = 0;
507 }
508
Jon Mason47f01db2010-11-11 04:25:53 +0000509 /* rth_hash_type and rth_it_hit are non-zero regardless of
510 * whether rss is enabled. Only the rth_value is zero/non-zero
511 * if rss is disabled/enabled, so key off of that.
512 */
513 if (ext_info.rth_value)
Tom Herbertc4be4162013-12-17 23:31:36 -0800514 skb_set_hash(skb, ext_info.rth_value,
515 PKT_HASH_TYPE_L3);
Jon Mason47f01db2010-11-11 04:25:53 +0000516
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000517 vxge_rx_complete(ring, skb, ext_info.vlan,
518 pkt_length, &ext_info);
519
520 ring->budget--;
521 ring->pkts_processed++;
522 if (!ring->budget)
523 break;
524
525 } while (vxge_hw_ring_rxd_next_completed(ringh, &dtr,
526 &t_code) == VXGE_HW_OK);
527
528 if (first_dtr)
529 vxge_hw_ring_rxd_post_post_wmb(ringh, first_dtr);
530
Eric W. Biedermanc7b82cc2014-03-14 18:10:50 -0700531out:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000532 vxge_debug_entryexit(VXGE_TRACE,
533 "%s:%d Exiting...",
534 __func__, __LINE__);
535 return VXGE_HW_OK;
536}
537
538/*
539 * vxge_xmit_compl
540 *
541 * If an interrupt was raised to indicate DMA complete of the Tx packet,
542 * this function is called. It identifies the last TxD whose buffer was
543 * freed and frees all skbs whose data have already DMA'ed into the NICs
544 * internal memory.
545 */
stephen hemminger42821a52010-10-21 07:50:53 +0000546static enum vxge_hw_status
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000547vxge_xmit_compl(struct __vxge_hw_fifo *fifo_hw, void *dtr,
548 enum vxge_hw_fifo_tcode t_code, void *userdata,
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000549 struct sk_buff ***skb_ptr, int nr_skb, int *more)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000550{
551 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000552 struct sk_buff *skb, **done_skb = *skb_ptr;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000553 int pkt_cnt = 0;
554
555 vxge_debug_entryexit(VXGE_TRACE,
556 "%s:%d Entered....", __func__, __LINE__);
557
558 do {
559 int frg_cnt;
560 skb_frag_t *frag;
561 int i = 0, j;
562 struct vxge_tx_priv *txd_priv =
563 vxge_hw_fifo_txdl_private_get(dtr);
564
565 skb = txd_priv->skb;
566 frg_cnt = skb_shinfo(skb)->nr_frags;
567 frag = &skb_shinfo(skb)->frags[0];
568
569 vxge_debug_tx(VXGE_TRACE,
570 "%s: %s:%d fifo_hw = %p dtr = %p "
571 "tcode = 0x%x", fifo->ndev->name, __func__,
572 __LINE__, fifo_hw, dtr, t_code);
573 /* check skb validity */
574 vxge_assert(skb);
575 vxge_debug_tx(VXGE_TRACE,
576 "%s: %s:%d skb = %p itxd_priv = %p frg_cnt = %d",
577 fifo->ndev->name, __func__, __LINE__,
578 skb, txd_priv, frg_cnt);
579 if (unlikely(t_code)) {
580 fifo->stats.tx_errors++;
581 vxge_debug_tx(VXGE_ERR,
582 "%s: tx: dtr %p completed due to "
583 "error t_code %01x", fifo->ndev->name,
584 dtr, t_code);
585 vxge_hw_fifo_handle_tcode(fifo_hw, dtr, t_code);
586 }
587
588 /* for unfragmented skb */
589 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
590 skb_headlen(skb), PCI_DMA_TODEVICE);
591
592 for (j = 0; j < frg_cnt; j++) {
593 pci_unmap_page(fifo->pdev,
594 txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000595 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000596 frag += 1;
597 }
598
599 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
600
601 /* Updating the statistics block */
stephen hemminger62ea0552011-06-20 10:35:07 +0000602 u64_stats_update_begin(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000603 fifo->stats.tx_frms++;
604 fifo->stats.tx_bytes += skb->len;
stephen hemminger62ea0552011-06-20 10:35:07 +0000605 u64_stats_update_end(&fifo->stats.syncp);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000606
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000607 *done_skb++ = skb;
608
609 if (--nr_skb <= 0) {
610 *more = 1;
611 break;
612 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000613
614 pkt_cnt++;
615 if (pkt_cnt > fifo->indicate_max_pkts)
616 break;
617
618 } while (vxge_hw_fifo_txdl_next_completed(fifo_hw,
619 &dtr, &t_code) == VXGE_HW_OK);
620
Benjamin LaHaiseff67df52009-08-04 10:21:03 +0000621 *skb_ptr = done_skb;
Jon Mason98f45da2010-07-15 08:47:25 +0000622 if (netif_tx_queue_stopped(fifo->txq))
623 netif_tx_wake_queue(fifo->txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000624
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000625 vxge_debug_entryexit(VXGE_TRACE,
626 "%s: %s:%d Exiting...",
627 fifo->ndev->name, __func__, __LINE__);
628 return VXGE_HW_OK;
629}
630
Eric Dumazet28679752009-05-27 19:26:37 +0000631/* select a vpath to transmit the packet */
Jon Mason98f45da2010-07-15 08:47:25 +0000632static u32 vxge_get_vpath_no(struct vxgedev *vdev, struct sk_buff *skb)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000633{
634 u16 queue_len, counter = 0;
635 if (skb->protocol == htons(ETH_P_IP)) {
636 struct iphdr *ip;
637 struct tcphdr *th;
638
639 ip = ip_hdr(skb);
640
Paul Gortmaker56f8a752011-06-21 20:33:34 -0700641 if (!ip_is_fragment(ip)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000642 th = (struct tcphdr *)(((unsigned char *)ip) +
643 ip->ihl*4);
644
645 queue_len = vdev->no_of_vpath;
646 counter = (ntohs(th->source) +
647 ntohs(th->dest)) &
648 vdev->vpath_selector[queue_len - 1];
649 if (counter >= queue_len)
650 counter = queue_len - 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000651 }
652 }
653 return counter;
654}
655
656static enum vxge_hw_status vxge_search_mac_addr_in_list(
657 struct vxge_vpath *vpath, u64 del_mac)
658{
659 struct list_head *entry, *next;
660 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
661 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac)
662 return TRUE;
663 }
664 return FALSE;
665}
666
Jon Mason528f7272010-12-10 14:02:56 +0000667static int vxge_mac_list_add(struct vxge_vpath *vpath, struct macInfo *mac)
668{
669 struct vxge_mac_addrs *new_mac_entry;
670 u8 *mac_address = NULL;
671
672 if (vpath->mac_addr_cnt >= VXGE_MAX_LEARN_MAC_ADDR_CNT)
673 return TRUE;
674
675 new_mac_entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_ATOMIC);
676 if (!new_mac_entry) {
677 vxge_debug_mem(VXGE_ERR,
678 "%s: memory allocation failed",
679 VXGE_DRIVER_NAME);
680 return FALSE;
681 }
682
683 list_add(&new_mac_entry->item, &vpath->mac_addr_list);
684
685 /* Copy the new mac address to the list */
686 mac_address = (u8 *)&new_mac_entry->macaddr;
687 memcpy(mac_address, mac->macaddr, ETH_ALEN);
688
689 new_mac_entry->state = mac->state;
690 vpath->mac_addr_cnt++;
691
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000692 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000693 vpath->mcast_addr_cnt++;
694
695 return TRUE;
696}
697
698/* Add a mac address to DA table */
699static enum vxge_hw_status
700vxge_add_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
701{
702 enum vxge_hw_status status = VXGE_HW_OK;
703 struct vxge_vpath *vpath;
704 enum vxge_hw_vpath_mac_addr_add_mode duplicate_mode;
705
Tobias Klauserf8d4aa22011-07-03 23:58:04 +0000706 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +0000707 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE;
708 else
709 duplicate_mode = VXGE_HW_VPATH_MAC_ADDR_REPLACE_DUPLICATE;
710
711 vpath = &vdev->vpaths[mac->vpath_no];
712 status = vxge_hw_vpath_mac_addr_add(vpath->handle, mac->macaddr,
713 mac->macmask, duplicate_mode);
714 if (status != VXGE_HW_OK) {
715 vxge_debug_init(VXGE_ERR,
716 "DA config add entry failed for vpath:%d",
717 vpath->device_id);
718 } else
719 if (FALSE == vxge_mac_list_add(vpath, mac))
720 status = -EPERM;
721
722 return status;
723}
724
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000725static int vxge_learn_mac(struct vxgedev *vdev, u8 *mac_header)
726{
727 struct macInfo mac_info;
728 u8 *mac_address = NULL;
729 u64 mac_addr = 0, vpath_vector = 0;
730 int vpath_idx = 0;
731 enum vxge_hw_status status = VXGE_HW_OK;
732 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000733
734 mac_address = (u8 *)&mac_addr;
735 memcpy(mac_address, mac_header, ETH_ALEN);
736
737 /* Is this mac address already in the list? */
738 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
739 vpath = &vdev->vpaths[vpath_idx];
740 if (vxge_search_mac_addr_in_list(vpath, mac_addr))
741 return vpath_idx;
742 }
743
744 memset(&mac_info, 0, sizeof(struct macInfo));
745 memcpy(mac_info.macaddr, mac_header, ETH_ALEN);
746
747 /* Any vpath has room to add mac address to its da table? */
748 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
749 vpath = &vdev->vpaths[vpath_idx];
750 if (vpath->mac_addr_cnt < vpath->max_mac_addr_cnt) {
751 /* Add this mac address to this vpath */
752 mac_info.vpath_no = vpath_idx;
753 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
754 status = vxge_add_mac_addr(vdev, &mac_info);
755 if (status != VXGE_HW_OK)
756 return -EPERM;
757 return vpath_idx;
758 }
759 }
760
761 mac_info.state = VXGE_LL_MAC_ADDR_IN_LIST;
762 vpath_idx = 0;
763 mac_info.vpath_no = vpath_idx;
764 /* Is the first vpath already selected as catch-basin ? */
765 vpath = &vdev->vpaths[vpath_idx];
766 if (vpath->mac_addr_cnt > vpath->max_mac_addr_cnt) {
767 /* Add this mac address to this vpath */
768 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
769 return -EPERM;
770 return vpath_idx;
771 }
772
773 /* Select first vpath as catch-basin */
774 vpath_vector = vxge_mBIT(vpath->device_id);
775 status = vxge_hw_mgmt_reg_write(vpath->vdev->devh,
776 vxge_hw_mgmt_reg_type_mrpcim,
777 0,
778 (ulong)offsetof(
779 struct vxge_hw_mrpcim_reg,
780 rts_mgr_cbasin_cfg),
781 vpath_vector);
782 if (status != VXGE_HW_OK) {
783 vxge_debug_tx(VXGE_ERR,
784 "%s: Unable to set the vpath-%d in catch-basin mode",
785 VXGE_DRIVER_NAME, vpath->device_id);
786 return -EPERM;
787 }
788
789 if (FALSE == vxge_mac_list_add(vpath, &mac_info))
790 return -EPERM;
791
792 return vpath_idx;
793}
794
795/**
796 * vxge_xmit
797 * @skb : the socket buffer containing the Tx data.
798 * @dev : device pointer.
799 *
800 * This function is the Tx entry point of the driver. Neterion NIC supports
801 * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000802*/
Stephen Hemminger613573252009-08-31 19:50:58 +0000803static netdev_tx_t
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000804vxge_xmit(struct sk_buff *skb, struct net_device *dev)
805{
806 struct vxge_fifo *fifo = NULL;
807 void *dtr_priv;
808 void *dtr = NULL;
809 struct vxgedev *vdev = NULL;
810 enum vxge_hw_status status;
811 int frg_cnt, first_frg_len;
812 skb_frag_t *frag;
813 int i = 0, j = 0, avail;
814 u64 dma_pointer;
815 struct vxge_tx_priv *txdl_priv = NULL;
816 struct __vxge_hw_fifo *fifo_hw;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000817 int offload_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000818 int vpath_no = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000819
820 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
821 dev->name, __func__, __LINE__);
822
823 /* A buffer with no data will be dropped */
824 if (unlikely(skb->len <= 0)) {
825 vxge_debug_tx(VXGE_ERR,
826 "%s: Buffer has no data..", dev->name);
Eric W. Biederman6956d732014-03-15 17:51:57 -0700827 dev_kfree_skb_any(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000828 return NETDEV_TX_OK;
829 }
830
Joe Perches5f54ceb2010-11-15 11:12:30 +0000831 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000832
833 if (unlikely(!is_vxge_card_up(vdev))) {
834 vxge_debug_tx(VXGE_ERR,
835 "%s: vdev not initialized", dev->name);
Eric W. Biederman6956d732014-03-15 17:51:57 -0700836 dev_kfree_skb_any(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000837 return NETDEV_TX_OK;
838 }
839
840 if (vdev->config.addr_learn_en) {
841 vpath_no = vxge_learn_mac(vdev, skb->data + ETH_ALEN);
842 if (vpath_no == -EPERM) {
843 vxge_debug_tx(VXGE_ERR,
844 "%s: Failed to store the mac address",
845 dev->name);
Eric W. Biederman6956d732014-03-15 17:51:57 -0700846 dev_kfree_skb_any(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000847 return NETDEV_TX_OK;
848 }
849 }
850
851 if (vdev->config.tx_steering_type == TX_MULTIQ_STEERING)
852 vpath_no = skb_get_queue_mapping(skb);
853 else if (vdev->config.tx_steering_type == TX_PORT_STEERING)
Jon Mason98f45da2010-07-15 08:47:25 +0000854 vpath_no = vxge_get_vpath_no(vdev, skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000855
856 vxge_debug_tx(VXGE_TRACE, "%s: vpath_no= %d", dev->name, vpath_no);
857
858 if (vpath_no >= vdev->no_of_vpath)
859 vpath_no = 0;
860
861 fifo = &vdev->vpaths[vpath_no].fifo;
862 fifo_hw = fifo->handle;
863
Jon Mason98f45da2010-07-15 08:47:25 +0000864 if (netif_tx_queue_stopped(fifo->txq))
Jon Masond03848e2010-07-15 08:47:23 +0000865 return NETDEV_TX_BUSY;
Jon Masond03848e2010-07-15 08:47:23 +0000866
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000867 avail = vxge_hw_fifo_free_txdl_count_get(fifo_hw);
868 if (avail == 0) {
869 vxge_debug_tx(VXGE_ERR,
870 "%s: No free TXDs available", dev->name);
871 fifo->stats.txd_not_free++;
Jon Mason98f45da2010-07-15 08:47:25 +0000872 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000873 }
874
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000875 /* Last TXD? Stop tx queue to avoid dropping packets. TX
876 * completion will resume the queue.
877 */
878 if (avail == 1)
Jon Mason98f45da2010-07-15 08:47:25 +0000879 netif_tx_stop_queue(fifo->txq);
Benjamin LaHaise4403b372009-08-04 10:20:44 +0000880
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000881 status = vxge_hw_fifo_txdl_reserve(fifo_hw, &dtr, &dtr_priv);
882 if (unlikely(status != VXGE_HW_OK)) {
883 vxge_debug_tx(VXGE_ERR,
884 "%s: Out of descriptors .", dev->name);
885 fifo->stats.txd_out_of_desc++;
Jon Mason98f45da2010-07-15 08:47:25 +0000886 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000887 }
888
889 vxge_debug_tx(VXGE_TRACE,
890 "%s: %s:%d fifo_hw = %p dtr = %p dtr_priv = %p",
891 dev->name, __func__, __LINE__,
892 fifo_hw, dtr, dtr_priv);
893
Jesse Grosseab6d182010-10-20 13:56:03 +0000894 if (vlan_tx_tag_present(skb)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000895 u16 vlan_tag = vlan_tx_tag_get(skb);
896 vxge_hw_fifo_txdl_vlan_set(dtr, vlan_tag);
897 }
898
899 first_frg_len = skb_headlen(skb);
900
901 dma_pointer = pci_map_single(fifo->pdev, skb->data, first_frg_len,
902 PCI_DMA_TODEVICE);
903
904 if (unlikely(pci_dma_mapping_error(fifo->pdev, dma_pointer))) {
905 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000906 fifo->stats.pci_map_fail++;
Jon Mason98f45da2010-07-15 08:47:25 +0000907 goto _exit0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000908 }
909
910 txdl_priv = vxge_hw_fifo_txdl_private_get(dtr);
911 txdl_priv->skb = skb;
912 txdl_priv->dma_buffers[j] = dma_pointer;
913
914 frg_cnt = skb_shinfo(skb)->nr_frags;
915 vxge_debug_tx(VXGE_TRACE,
916 "%s: %s:%d skb = %p txdl_priv = %p "
917 "frag_cnt = %d dma_pointer = 0x%llx", dev->name,
918 __func__, __LINE__, skb, txdl_priv,
919 frg_cnt, (unsigned long long)dma_pointer);
920
921 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
922 first_frg_len);
923
924 frag = &skb_shinfo(skb)->frags[0];
925 for (i = 0; i < frg_cnt; i++) {
926 /* ignore 0 length fragment */
Eric Dumazet9e903e02011-10-18 21:00:24 +0000927 if (!skb_frag_size(frag))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000928 continue;
929
Ian Campbell94d60a72011-10-05 17:35:34 -0400930 dma_pointer = (u64)skb_frag_dma_map(&fifo->pdev->dev, frag,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000931 0, skb_frag_size(frag),
Ian Campbell94d60a72011-10-05 17:35:34 -0400932 DMA_TO_DEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000933
Ian Campbell94d60a72011-10-05 17:35:34 -0400934 if (unlikely(dma_mapping_error(&fifo->pdev->dev, dma_pointer)))
Jon Mason98f45da2010-07-15 08:47:25 +0000935 goto _exit2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000936 vxge_debug_tx(VXGE_TRACE,
937 "%s: %s:%d frag = %d dma_pointer = 0x%llx",
938 dev->name, __func__, __LINE__, i,
939 (unsigned long long)dma_pointer);
940
941 txdl_priv->dma_buffers[j] = dma_pointer;
942 vxge_hw_fifo_txdl_buffer_set(fifo_hw, dtr, j++, dma_pointer,
Eric Dumazet9e903e02011-10-18 21:00:24 +0000943 skb_frag_size(frag));
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000944 frag += 1;
945 }
946
947 offload_type = vxge_offload_type(skb);
948
949 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000950 int mss = vxge_tcp_mss(skb);
951 if (mss) {
Jon Mason98f45da2010-07-15 08:47:25 +0000952 vxge_debug_tx(VXGE_TRACE, "%s: %s:%d mss = %d",
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000953 dev->name, __func__, __LINE__, mss);
954 vxge_hw_fifo_txdl_mss_set(dtr, mss);
955 } else {
956 vxge_assert(skb->len <=
957 dev->mtu + VXGE_HW_MAC_HEADER_MAX_SIZE);
958 vxge_assert(0);
959 goto _exit1;
960 }
961 }
962
963 if (skb->ip_summed == CHECKSUM_PARTIAL)
964 vxge_hw_fifo_txdl_cksum_set_bits(dtr,
965 VXGE_HW_FIFO_TXD_TX_CKO_IPV4_EN |
966 VXGE_HW_FIFO_TXD_TX_CKO_TCP_EN |
967 VXGE_HW_FIFO_TXD_TX_CKO_UDP_EN);
968
969 vxge_hw_fifo_txdl_post(fifo_hw, dtr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000970
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000971 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
972 dev->name, __func__, __LINE__);
Patrick McHardy6ed10652009-06-23 06:03:08 +0000973 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000974
Jon Mason98f45da2010-07-15 08:47:25 +0000975_exit2:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000976 vxge_debug_tx(VXGE_TRACE, "%s: pci_map_page failed", dev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000977_exit1:
978 j = 0;
979 frag = &skb_shinfo(skb)->frags[0];
980
981 pci_unmap_single(fifo->pdev, txdl_priv->dma_buffers[j++],
982 skb_headlen(skb), PCI_DMA_TODEVICE);
983
984 for (; j < i; j++) {
985 pci_unmap_page(fifo->pdev, txdl_priv->dma_buffers[j],
Eric Dumazet9e903e02011-10-18 21:00:24 +0000986 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000987 frag += 1;
988 }
989
990 vxge_hw_fifo_txdl_free(fifo_hw, dtr);
Jon Mason98f45da2010-07-15 08:47:25 +0000991_exit0:
992 netif_tx_stop_queue(fifo->txq);
Eric W. Biederman6956d732014-03-15 17:51:57 -0700993 dev_kfree_skb_any(skb);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000994
Patrick McHardy6ed10652009-06-23 06:03:08 +0000995 return NETDEV_TX_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +0000996}
997
998/*
999 * vxge_rx_term
1000 *
1001 * Function will be called by hw function to abort all outstanding receive
1002 * descriptors.
1003 */
1004static void
1005vxge_rx_term(void *dtrh, enum vxge_hw_rxd_state state, void *userdata)
1006{
1007 struct vxge_ring *ring = (struct vxge_ring *)userdata;
1008 struct vxge_rx_priv *rx_priv =
1009 vxge_hw_ring_rxd_private_get(dtrh);
1010
1011 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
1012 ring->ndev->name, __func__, __LINE__);
1013 if (state != VXGE_HW_RXD_STATE_POSTED)
1014 return;
1015
1016 pci_unmap_single(ring->pdev, rx_priv->data_dma,
1017 rx_priv->data_size, PCI_DMA_FROMDEVICE);
1018
1019 dev_kfree_skb(rx_priv->skb);
Benjamin LaHaiseea11bbe2009-08-04 10:21:57 +00001020 rx_priv->skb_data = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001021
1022 vxge_debug_entryexit(VXGE_TRACE,
1023 "%s: %s:%d Exiting...",
1024 ring->ndev->name, __func__, __LINE__);
1025}
1026
1027/*
1028 * vxge_tx_term
1029 *
1030 * Function will be called to abort all outstanding tx descriptors
1031 */
1032static void
1033vxge_tx_term(void *dtrh, enum vxge_hw_txdl_state state, void *userdata)
1034{
1035 struct vxge_fifo *fifo = (struct vxge_fifo *)userdata;
1036 skb_frag_t *frag;
1037 int i = 0, j, frg_cnt;
1038 struct vxge_tx_priv *txd_priv = vxge_hw_fifo_txdl_private_get(dtrh);
1039 struct sk_buff *skb = txd_priv->skb;
1040
1041 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1042
1043 if (state != VXGE_HW_TXDL_STATE_POSTED)
1044 return;
1045
1046 /* check skb validity */
1047 vxge_assert(skb);
1048 frg_cnt = skb_shinfo(skb)->nr_frags;
1049 frag = &skb_shinfo(skb)->frags[0];
1050
1051 /* for unfragmented skb */
1052 pci_unmap_single(fifo->pdev, txd_priv->dma_buffers[i++],
1053 skb_headlen(skb), PCI_DMA_TODEVICE);
1054
1055 for (j = 0; j < frg_cnt; j++) {
1056 pci_unmap_page(fifo->pdev, txd_priv->dma_buffers[i++],
Eric Dumazet9e903e02011-10-18 21:00:24 +00001057 skb_frag_size(frag), PCI_DMA_TODEVICE);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001058 frag += 1;
1059 }
1060
1061 dev_kfree_skb(skb);
1062
1063 vxge_debug_entryexit(VXGE_TRACE,
1064 "%s:%d Exiting...", __func__, __LINE__);
1065}
1066
Jon Mason528f7272010-12-10 14:02:56 +00001067static int vxge_mac_list_del(struct vxge_vpath *vpath, struct macInfo *mac)
1068{
1069 struct list_head *entry, *next;
1070 u64 del_mac = 0;
1071 u8 *mac_address = (u8 *) (&del_mac);
1072
1073 /* Copy the mac address to delete from the list */
1074 memcpy(mac_address, mac->macaddr, ETH_ALEN);
1075
1076 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1077 if (((struct vxge_mac_addrs *)entry)->macaddr == del_mac) {
1078 list_del(entry);
1079 kfree((struct vxge_mac_addrs *)entry);
1080 vpath->mac_addr_cnt--;
1081
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001082 if (is_multicast_ether_addr(mac->macaddr))
Jon Mason528f7272010-12-10 14:02:56 +00001083 vpath->mcast_addr_cnt--;
1084 return TRUE;
1085 }
1086 }
1087
1088 return FALSE;
1089}
1090
1091/* delete a mac address from DA table */
1092static enum vxge_hw_status
1093vxge_del_mac_addr(struct vxgedev *vdev, struct macInfo *mac)
1094{
1095 enum vxge_hw_status status = VXGE_HW_OK;
1096 struct vxge_vpath *vpath;
1097
1098 vpath = &vdev->vpaths[mac->vpath_no];
1099 status = vxge_hw_vpath_mac_addr_delete(vpath->handle, mac->macaddr,
1100 mac->macmask);
1101 if (status != VXGE_HW_OK) {
1102 vxge_debug_init(VXGE_ERR,
1103 "DA config delete entry failed for vpath:%d",
1104 vpath->device_id);
1105 } else
1106 vxge_mac_list_del(vpath, mac);
1107 return status;
1108}
1109
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001110/**
1111 * vxge_set_multicast
1112 * @dev: pointer to the device structure
1113 *
1114 * Entry point for multicast address enable/disable
1115 * This function is a driver entry point which gets called by the kernel
1116 * whenever multicast addresses must be enabled/disabled. This also gets
1117 * called to set/reset promiscuous mode. Depending on the deivce flag, we
1118 * determine, if multicast address must be enabled or if promiscuous mode
1119 * is to be disabled etc.
1120 */
1121static void vxge_set_multicast(struct net_device *dev)
1122{
Jiri Pirko22bedad32010-04-01 21:22:57 +00001123 struct netdev_hw_addr *ha;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001124 struct vxgedev *vdev;
1125 int i, mcast_cnt = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00001126 struct __vxge_hw_device *hldev;
1127 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001128 enum vxge_hw_status status = VXGE_HW_OK;
1129 struct macInfo mac_info;
1130 int vpath_idx = 0;
1131 struct vxge_mac_addrs *mac_entry;
1132 struct list_head *list_head;
1133 struct list_head *entry, *next;
1134 u8 *mac_address = NULL;
1135
1136 vxge_debug_entryexit(VXGE_TRACE,
1137 "%s:%d", __func__, __LINE__);
1138
Joe Perches5f54ceb2010-11-15 11:12:30 +00001139 vdev = netdev_priv(dev);
Joe Perches64699332012-06-04 12:44:16 +00001140 hldev = vdev->devh;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001141
1142 if (unlikely(!is_vxge_card_up(vdev)))
1143 return;
1144
1145 if ((dev->flags & IFF_ALLMULTI) && (!vdev->all_multi_flg)) {
1146 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001147 vpath = &vdev->vpaths[i];
1148 vxge_assert(vpath->is_open);
1149 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1150 if (status != VXGE_HW_OK)
1151 vxge_debug_init(VXGE_ERR, "failed to enable "
1152 "multicast, status %d", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001153 vdev->all_multi_flg = 1;
1154 }
Jon Mason7adf7d12010-07-15 08:47:24 +00001155 } else if (!(dev->flags & IFF_ALLMULTI) && (vdev->all_multi_flg)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001156 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001157 vpath = &vdev->vpaths[i];
1158 vxge_assert(vpath->is_open);
1159 status = vxge_hw_vpath_mcast_disable(vpath->handle);
1160 if (status != VXGE_HW_OK)
1161 vxge_debug_init(VXGE_ERR, "failed to disable "
1162 "multicast, status %d", status);
1163 vdev->all_multi_flg = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001164 }
1165 }
1166
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001167
1168 if (!vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001169 for (i = 0; i < vdev->no_of_vpath; i++) {
1170 vpath = &vdev->vpaths[i];
1171 vxge_assert(vpath->is_open);
1172
1173 if (dev->flags & IFF_PROMISC)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001174 status = vxge_hw_vpath_promisc_enable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001175 vpath->handle);
1176 else
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001177 status = vxge_hw_vpath_promisc_disable(
Jon Mason7adf7d12010-07-15 08:47:24 +00001178 vpath->handle);
1179 if (status != VXGE_HW_OK)
1180 vxge_debug_init(VXGE_ERR, "failed to %s promisc"
1181 ", status %d", dev->flags&IFF_PROMISC ?
1182 "enable" : "disable", status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001183 }
1184 }
1185
1186 memset(&mac_info, 0, sizeof(struct macInfo));
1187 /* Update individual M_CAST address list */
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001188 if ((!vdev->all_multi_flg) && netdev_mc_count(dev)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001189 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1190 list_head = &vdev->vpaths[0].mac_addr_list;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001191 if ((netdev_mc_count(dev) +
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001192 (vdev->vpaths[0].mac_addr_cnt - mcast_cnt)) >
1193 vdev->vpaths[0].max_mac_addr_cnt)
1194 goto _set_all_mcast;
1195
1196 /* Delete previous MC's */
1197 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001198 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001199 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001200 /* Copy the mac address to delete */
1201 mac_address = (u8 *)&mac_entry->macaddr;
1202 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1203
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001204 if (is_multicast_ether_addr(mac_info.macaddr)) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001205 for (vpath_idx = 0; vpath_idx <
1206 vdev->no_of_vpath;
1207 vpath_idx++) {
1208 mac_info.vpath_no = vpath_idx;
1209 status = vxge_del_mac_addr(
1210 vdev,
1211 &mac_info);
1212 }
1213 }
1214 }
1215 }
1216
1217 /* Add new ones */
Jiri Pirko22bedad32010-04-01 21:22:57 +00001218 netdev_for_each_mc_addr(ha, dev) {
1219 memcpy(mac_info.macaddr, ha->addr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001220 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1221 vpath_idx++) {
1222 mac_info.vpath_no = vpath_idx;
1223 mac_info.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1224 status = vxge_add_mac_addr(vdev, &mac_info);
1225 if (status != VXGE_HW_OK) {
1226 vxge_debug_init(VXGE_ERR,
1227 "%s:%d Setting individual"
1228 "multicast address failed",
1229 __func__, __LINE__);
1230 goto _set_all_mcast;
1231 }
1232 }
1233 }
1234
1235 return;
1236_set_all_mcast:
1237 mcast_cnt = vdev->vpaths[0].mcast_addr_cnt;
1238 /* Delete previous MC's */
1239 for (i = 0; i < mcast_cnt; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001240 list_for_each_safe(entry, next, list_head) {
Jon Mason2c913082010-11-11 04:26:03 +00001241 mac_entry = (struct vxge_mac_addrs *)entry;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001242 /* Copy the mac address to delete */
1243 mac_address = (u8 *)&mac_entry->macaddr;
1244 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1245
Tobias Klauserf8d4aa22011-07-03 23:58:04 +00001246 if (is_multicast_ether_addr(mac_info.macaddr))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001247 break;
1248 }
1249
1250 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath;
1251 vpath_idx++) {
1252 mac_info.vpath_no = vpath_idx;
1253 status = vxge_del_mac_addr(vdev, &mac_info);
1254 }
1255 }
1256
1257 /* Enable all multicast */
1258 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00001259 vpath = &vdev->vpaths[i];
1260 vxge_assert(vpath->is_open);
1261
1262 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001263 if (status != VXGE_HW_OK) {
1264 vxge_debug_init(VXGE_ERR,
1265 "%s:%d Enabling all multicasts failed",
1266 __func__, __LINE__);
1267 }
1268 vdev->all_multi_flg = 1;
1269 }
1270 dev->flags |= IFF_ALLMULTI;
1271 }
1272
1273 vxge_debug_entryexit(VXGE_TRACE,
1274 "%s:%d Exiting...", __func__, __LINE__);
1275}
1276
1277/**
1278 * vxge_set_mac_addr
1279 * @dev: pointer to the device structure
1280 *
1281 * Update entry "0" (default MAC addr)
1282 */
1283static int vxge_set_mac_addr(struct net_device *dev, void *p)
1284{
1285 struct sockaddr *addr = p;
1286 struct vxgedev *vdev;
Jon Mason2c913082010-11-11 04:26:03 +00001287 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001288 enum vxge_hw_status status = VXGE_HW_OK;
1289 struct macInfo mac_info_new, mac_info_old;
1290 int vpath_idx = 0;
1291
1292 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1293
Joe Perches5f54ceb2010-11-15 11:12:30 +00001294 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001295 hldev = vdev->devh;
1296
1297 if (!is_valid_ether_addr(addr->sa_data))
1298 return -EINVAL;
1299
1300 memset(&mac_info_new, 0, sizeof(struct macInfo));
1301 memset(&mac_info_old, 0, sizeof(struct macInfo));
1302
1303 vxge_debug_entryexit(VXGE_TRACE, "%s:%d Exiting...",
1304 __func__, __LINE__);
1305
1306 /* Get the old address */
1307 memcpy(mac_info_old.macaddr, dev->dev_addr, dev->addr_len);
1308
1309 /* Copy the new address */
1310 memcpy(mac_info_new.macaddr, addr->sa_data, dev->addr_len);
1311
1312 /* First delete the old mac address from all the vpaths
1313 as we can't specify the index while adding new mac address */
1314 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1315 struct vxge_vpath *vpath = &vdev->vpaths[vpath_idx];
1316 if (!vpath->is_open) {
1317 /* This can happen when this interface is added/removed
1318 to the bonding interface. Delete this station address
1319 from the linked list */
1320 vxge_mac_list_del(vpath, &mac_info_old);
1321
1322 /* Add this new address to the linked list
1323 for later restoring */
1324 vxge_mac_list_add(vpath, &mac_info_new);
1325
1326 continue;
1327 }
1328 /* Delete the station address */
1329 mac_info_old.vpath_no = vpath_idx;
1330 status = vxge_del_mac_addr(vdev, &mac_info_old);
1331 }
1332
1333 if (unlikely(!is_vxge_card_up(vdev))) {
1334 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1335 return VXGE_HW_OK;
1336 }
1337
1338 /* Set this mac address to all the vpaths */
1339 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
1340 mac_info_new.vpath_no = vpath_idx;
1341 mac_info_new.state = VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1342 status = vxge_add_mac_addr(vdev, &mac_info_new);
1343 if (status != VXGE_HW_OK)
1344 return -EINVAL;
1345 }
1346
1347 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
1348
1349 return status;
1350}
1351
1352/*
1353 * vxge_vpath_intr_enable
1354 * @vdev: pointer to vdev
1355 * @vp_id: vpath for which to enable the interrupts
1356 *
1357 * Enables the interrupts for the vpath
1358*/
stephen hemminger42821a52010-10-21 07:50:53 +00001359static void vxge_vpath_intr_enable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001360{
1361 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001362 int msix_id = 0;
1363 int tim_msix_id[4] = {0, 1, 0, 0};
1364 int alarm_msix_id = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001365
1366 vxge_hw_vpath_intr_enable(vpath->handle);
1367
1368 if (vdev->config.intr_type == INTA)
1369 vxge_hw_vpath_inta_unmask_tx_rx(vpath->handle);
1370 else {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001371 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
1372 alarm_msix_id);
1373
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001374 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001375 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
1376 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id + 1);
1377
1378 /* enable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001379 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1380 VXGE_HW_VPATH_MSIX_ACTIVE) + alarm_msix_id;
1381 vxge_hw_vpath_msix_unmask(vpath->handle, msix_id);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001382 }
1383}
1384
1385/*
1386 * vxge_vpath_intr_disable
1387 * @vdev: pointer to vdev
1388 * @vp_id: vpath for which to disable the interrupts
1389 *
1390 * Disables the interrupts for the vpath
1391*/
stephen hemminger42821a52010-10-21 07:50:53 +00001392static void vxge_vpath_intr_disable(struct vxgedev *vdev, int vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001393{
1394 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Jon Mason4d2a5b42010-11-11 04:25:54 +00001395 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001396 int msix_id;
1397
Joe Perchesd8ee7072010-11-15 10:13:58 +00001398 hldev = pci_get_drvdata(vdev->pdev);
Jon Mason4d2a5b42010-11-11 04:25:54 +00001399
1400 vxge_hw_vpath_wait_receive_idle(hldev, vpath->device_id);
1401
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001402 vxge_hw_vpath_intr_disable(vpath->handle);
1403
1404 if (vdev->config.intr_type == INTA)
1405 vxge_hw_vpath_inta_mask_tx_rx(vpath->handle);
1406 else {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001407 msix_id = vpath->device_id * VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001408 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1409 vxge_hw_vpath_msix_mask(vpath->handle, msix_id + 1);
1410
1411 /* disable the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00001412 msix_id = (vpath->handle->vpath->hldev->first_vp_id *
1413 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001414 vxge_hw_vpath_msix_mask(vpath->handle, msix_id);
1415 }
1416}
1417
Jon Mason528f7272010-12-10 14:02:56 +00001418/* list all mac addresses from DA table */
1419static enum vxge_hw_status
1420vxge_search_mac_addr_in_da_table(struct vxge_vpath *vpath, struct macInfo *mac)
1421{
1422 enum vxge_hw_status status = VXGE_HW_OK;
1423 unsigned char macmask[ETH_ALEN];
1424 unsigned char macaddr[ETH_ALEN];
1425
1426 status = vxge_hw_vpath_mac_addr_get(vpath->handle,
1427 macaddr, macmask);
1428 if (status != VXGE_HW_OK) {
1429 vxge_debug_init(VXGE_ERR,
1430 "DA config list entry failed for vpath:%d",
1431 vpath->device_id);
1432 return status;
1433 }
1434
dingtianhongf75d1912013-12-30 15:41:02 +08001435 while (!ether_addr_equal(mac->macaddr, macaddr)) {
Jon Mason528f7272010-12-10 14:02:56 +00001436 status = vxge_hw_vpath_mac_addr_get_next(vpath->handle,
1437 macaddr, macmask);
1438 if (status != VXGE_HW_OK)
1439 break;
1440 }
1441
1442 return status;
1443}
1444
1445/* Store all mac addresses from the list to the DA table */
1446static enum vxge_hw_status vxge_restore_vpath_mac_addr(struct vxge_vpath *vpath)
1447{
1448 enum vxge_hw_status status = VXGE_HW_OK;
1449 struct macInfo mac_info;
1450 u8 *mac_address = NULL;
1451 struct list_head *entry, *next;
1452
1453 memset(&mac_info, 0, sizeof(struct macInfo));
1454
1455 if (vpath->is_open) {
1456 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
1457 mac_address =
1458 (u8 *)&
1459 ((struct vxge_mac_addrs *)entry)->macaddr;
1460 memcpy(mac_info.macaddr, mac_address, ETH_ALEN);
1461 ((struct vxge_mac_addrs *)entry)->state =
1462 VXGE_LL_MAC_ADDR_IN_DA_TABLE;
1463 /* does this mac address already exist in da table? */
1464 status = vxge_search_mac_addr_in_da_table(vpath,
1465 &mac_info);
1466 if (status != VXGE_HW_OK) {
1467 /* Add this mac address to the DA table */
1468 status = vxge_hw_vpath_mac_addr_add(
1469 vpath->handle, mac_info.macaddr,
1470 mac_info.macmask,
1471 VXGE_HW_VPATH_MAC_ADDR_ADD_DUPLICATE);
1472 if (status != VXGE_HW_OK) {
1473 vxge_debug_init(VXGE_ERR,
1474 "DA add entry failed for vpath:%d",
1475 vpath->device_id);
1476 ((struct vxge_mac_addrs *)entry)->state
1477 = VXGE_LL_MAC_ADDR_IN_LIST;
1478 }
1479 }
1480 }
1481 }
1482
1483 return status;
1484}
1485
1486/* Store all vlan ids from the list to the vid table */
1487static enum vxge_hw_status
1488vxge_restore_vpath_vid_table(struct vxge_vpath *vpath)
1489{
1490 enum vxge_hw_status status = VXGE_HW_OK;
1491 struct vxgedev *vdev = vpath->vdev;
1492 u16 vid;
1493
Jiri Pirko53515732011-07-20 04:54:40 +00001494 if (!vpath->is_open)
1495 return status;
Jon Mason528f7272010-12-10 14:02:56 +00001496
Jiri Pirko53515732011-07-20 04:54:40 +00001497 for_each_set_bit(vid, vdev->active_vlans, VLAN_N_VID)
1498 status = vxge_hw_vpath_vid_add(vpath->handle, vid);
Jon Mason528f7272010-12-10 14:02:56 +00001499
1500 return status;
1501}
1502
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001503/*
1504 * vxge_reset_vpath
1505 * @vdev: pointer to vdev
1506 * @vp_id: vpath to reset
1507 *
1508 * Resets the vpath
1509*/
1510static int vxge_reset_vpath(struct vxgedev *vdev, int vp_id)
1511{
1512 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001513 struct vxge_vpath *vpath = &vdev->vpaths[vp_id];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001514 int ret = 0;
1515
1516 /* check if device is down already */
1517 if (unlikely(!is_vxge_card_up(vdev)))
1518 return 0;
1519
1520 /* is device reset already scheduled */
1521 if (test_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1522 return 0;
1523
Jon Mason7adf7d12010-07-15 08:47:24 +00001524 if (vpath->handle) {
1525 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001526 if (is_vxge_card_up(vdev) &&
Jon Mason7adf7d12010-07-15 08:47:24 +00001527 vxge_hw_vpath_recover_from_reset(vpath->handle)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001528 != VXGE_HW_OK) {
1529 vxge_debug_init(VXGE_ERR,
1530 "vxge_hw_vpath_recover_from_reset"
1531 "failed for vpath:%d", vp_id);
1532 return status;
1533 }
1534 } else {
1535 vxge_debug_init(VXGE_ERR,
1536 "vxge_hw_vpath_reset failed for"
1537 "vpath:%d", vp_id);
1538 return status;
1539 }
1540 } else
1541 return VXGE_HW_FAIL;
1542
Jon Mason7adf7d12010-07-15 08:47:24 +00001543 vxge_restore_vpath_mac_addr(vpath);
1544 vxge_restore_vpath_vid_table(vpath);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001545
1546 /* Enable all broadcast */
Jon Mason7adf7d12010-07-15 08:47:24 +00001547 vxge_hw_vpath_bcast_enable(vpath->handle);
1548
1549 /* Enable all multicast */
1550 if (vdev->all_multi_flg) {
1551 status = vxge_hw_vpath_mcast_enable(vpath->handle);
1552 if (status != VXGE_HW_OK)
1553 vxge_debug_init(VXGE_ERR,
1554 "%s:%d Enabling multicast failed",
1555 __func__, __LINE__);
1556 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001557
1558 /* Enable the interrupts */
1559 vxge_vpath_intr_enable(vdev, vp_id);
1560
1561 smp_wmb();
1562
1563 /* Enable the flow of traffic through the vpath */
Jon Mason7adf7d12010-07-15 08:47:24 +00001564 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001565
1566 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00001567 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
1568 vpath->ring.last_status = VXGE_HW_OK;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001569
1570 /* Vpath reset done */
1571 clear_bit(vp_id, &vdev->vp_reset);
1572
1573 /* Start the vpath queue */
Jon Mason98f45da2010-07-15 08:47:25 +00001574 if (netif_tx_queue_stopped(vpath->fifo.txq))
1575 netif_tx_wake_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001576
1577 return ret;
1578}
1579
Jon Mason16fded72011-01-18 15:02:21 +00001580/* Configure CI */
1581static void vxge_config_ci_for_tti_rti(struct vxgedev *vdev)
1582{
1583 int i = 0;
1584
1585 /* Enable CI for RTI */
1586 if (vdev->config.intr_type == MSI_X) {
1587 for (i = 0; i < vdev->no_of_vpath; i++) {
1588 struct __vxge_hw_ring *hw_ring;
1589
1590 hw_ring = vdev->vpaths[i].ring.handle;
1591 vxge_hw_vpath_dynamic_rti_ci_set(hw_ring);
1592 }
1593 }
1594
1595 /* Enable CI for TTI */
1596 for (i = 0; i < vdev->no_of_vpath; i++) {
1597 struct __vxge_hw_fifo *hw_fifo = vdev->vpaths[i].fifo.handle;
1598 vxge_hw_vpath_tti_ci_set(hw_fifo);
1599 /*
1600 * For Inta (with or without napi), Set CI ON for only one
1601 * vpath. (Have only one free running timer).
1602 */
1603 if ((vdev->config.intr_type == INTA) && (i == 0))
1604 break;
1605 }
1606
1607 return;
1608}
1609
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001610static int do_vxge_reset(struct vxgedev *vdev, int event)
1611{
1612 enum vxge_hw_status status;
1613 int ret = 0, vp_id, i;
1614
1615 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1616
1617 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET)) {
1618 /* check if device is down already */
1619 if (unlikely(!is_vxge_card_up(vdev)))
1620 return 0;
1621
1622 /* is reset already scheduled */
1623 if (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
1624 return 0;
1625 }
1626
1627 if (event == VXGE_LL_FULL_RESET) {
Jon Mason2e41f642010-12-10 14:02:59 +00001628 netif_carrier_off(vdev->ndev);
1629
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001630 /* wait for all the vpath reset to complete */
1631 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1632 while (test_bit(vp_id, &vdev->vp_reset))
1633 msleep(50);
1634 }
1635
Jon Mason2e41f642010-12-10 14:02:59 +00001636 netif_carrier_on(vdev->ndev);
1637
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001638 /* if execution mode is set to debug, don't reset the adapter */
1639 if (unlikely(vdev->exec_mode)) {
1640 vxge_debug_init(VXGE_ERR,
1641 "%s: execution mode is debug, returning..",
1642 vdev->ndev->name);
Jon Mason7adf7d12010-07-15 08:47:24 +00001643 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1644 netif_tx_stop_all_queues(vdev->ndev);
1645 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001646 }
1647 }
1648
1649 if (event == VXGE_LL_FULL_RESET) {
Jon Mason4d2a5b42010-11-11 04:25:54 +00001650 vxge_hw_device_wait_receive_idle(vdev->devh);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001651 vxge_hw_device_intr_disable(vdev->devh);
1652
1653 switch (vdev->cric_err_event) {
1654 case VXGE_HW_EVENT_UNKNOWN:
Jon Masond03848e2010-07-15 08:47:23 +00001655 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001656 vxge_debug_init(VXGE_ERR,
1657 "fatal: %s: Disabling device due to"
1658 "unknown error",
1659 vdev->ndev->name);
1660 ret = -EPERM;
1661 goto out;
1662 case VXGE_HW_EVENT_RESET_START:
1663 break;
1664 case VXGE_HW_EVENT_RESET_COMPLETE:
1665 case VXGE_HW_EVENT_LINK_DOWN:
1666 case VXGE_HW_EVENT_LINK_UP:
1667 case VXGE_HW_EVENT_ALARM_CLEARED:
1668 case VXGE_HW_EVENT_ECCERR:
1669 case VXGE_HW_EVENT_MRPCIM_ECCERR:
1670 ret = -EPERM;
1671 goto out;
1672 case VXGE_HW_EVENT_FIFO_ERR:
1673 case VXGE_HW_EVENT_VPATH_ERR:
1674 break;
1675 case VXGE_HW_EVENT_CRITICAL_ERR:
Jon Masond03848e2010-07-15 08:47:23 +00001676 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001677 vxge_debug_init(VXGE_ERR,
1678 "fatal: %s: Disabling device due to"
1679 "serious error",
1680 vdev->ndev->name);
1681 /* SOP or device reset required */
1682 /* This event is not currently used */
1683 ret = -EPERM;
1684 goto out;
1685 case VXGE_HW_EVENT_SERR:
Jon Masond03848e2010-07-15 08:47:23 +00001686 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001687 vxge_debug_init(VXGE_ERR,
1688 "fatal: %s: Disabling device due to"
1689 "serious error",
1690 vdev->ndev->name);
1691 ret = -EPERM;
1692 goto out;
1693 case VXGE_HW_EVENT_SRPCIM_SERR:
1694 case VXGE_HW_EVENT_MRPCIM_SERR:
1695 ret = -EPERM;
1696 goto out;
1697 case VXGE_HW_EVENT_SLOT_FREEZE:
Jon Masond03848e2010-07-15 08:47:23 +00001698 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001699 vxge_debug_init(VXGE_ERR,
1700 "fatal: %s: Disabling device due to"
1701 "slot freeze",
1702 vdev->ndev->name);
1703 ret = -EPERM;
1704 goto out;
1705 default:
1706 break;
1707
1708 }
1709 }
1710
1711 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_START_RESET))
Jon Masond03848e2010-07-15 08:47:23 +00001712 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001713
1714 if (event == VXGE_LL_FULL_RESET) {
1715 status = vxge_reset_all_vpaths(vdev);
1716 if (status != VXGE_HW_OK) {
1717 vxge_debug_init(VXGE_ERR,
1718 "fatal: %s: can not reset vpaths",
1719 vdev->ndev->name);
1720 ret = -EPERM;
1721 goto out;
1722 }
1723 }
1724
1725 if (event == VXGE_LL_COMPL_RESET) {
1726 for (i = 0; i < vdev->no_of_vpath; i++)
1727 if (vdev->vpaths[i].handle) {
1728 if (vxge_hw_vpath_recover_from_reset(
1729 vdev->vpaths[i].handle)
1730 != VXGE_HW_OK) {
1731 vxge_debug_init(VXGE_ERR,
1732 "vxge_hw_vpath_recover_"
1733 "from_reset failed for vpath: "
1734 "%d", i);
1735 ret = -EPERM;
1736 goto out;
1737 }
1738 } else {
1739 vxge_debug_init(VXGE_ERR,
1740 "vxge_hw_vpath_reset failed for "
1741 "vpath:%d", i);
1742 ret = -EPERM;
1743 goto out;
1744 }
1745 }
1746
1747 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET)) {
1748 /* Reprogram the DA table with populated mac addresses */
1749 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
1750 vxge_restore_vpath_mac_addr(&vdev->vpaths[vp_id]);
1751 vxge_restore_vpath_vid_table(&vdev->vpaths[vp_id]);
1752 }
1753
1754 /* enable vpath interrupts */
1755 for (i = 0; i < vdev->no_of_vpath; i++)
1756 vxge_vpath_intr_enable(vdev, i);
1757
1758 vxge_hw_device_intr_enable(vdev->devh);
1759
1760 smp_wmb();
1761
1762 /* Indicate card up */
1763 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
1764
1765 /* Get the traffic to flow through the vpaths */
1766 for (i = 0; i < vdev->no_of_vpath; i++) {
1767 vxge_hw_vpath_enable(vdev->vpaths[i].handle);
1768 smp_wmb();
1769 vxge_hw_vpath_rx_doorbell_init(vdev->vpaths[i].handle);
1770 }
1771
Jon Masond03848e2010-07-15 08:47:23 +00001772 netif_tx_wake_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001773 }
1774
Jon Mason16fded72011-01-18 15:02:21 +00001775 /* configure CI */
1776 vxge_config_ci_for_tti_rti(vdev);
1777
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001778out:
1779 vxge_debug_entryexit(VXGE_TRACE,
1780 "%s:%d Exiting...", __func__, __LINE__);
1781
1782 /* Indicate reset done */
1783 if ((event == VXGE_LL_FULL_RESET) || (event == VXGE_LL_COMPL_RESET))
1784 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
1785 return ret;
1786}
1787
1788/*
1789 * vxge_reset
1790 * @vdev: pointer to ll device
1791 *
1792 * driver may reset the chip on events of serr, eccerr, etc
1793 */
Jon Mason2e41f642010-12-10 14:02:59 +00001794static void vxge_reset(struct work_struct *work)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001795{
Jon Mason2e41f642010-12-10 14:02:59 +00001796 struct vxgedev *vdev = container_of(work, struct vxgedev, reset_task);
1797
1798 if (!netif_running(vdev->ndev))
1799 return;
1800
1801 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001802}
1803
1804/**
1805 * vxge_poll - Receive handler when Receive Polling is used.
1806 * @dev: pointer to the device structure.
1807 * @budget: Number of packets budgeted to be processed in this iteration.
1808 *
1809 * This function comes into picture only if Receive side is being handled
1810 * through polling (called NAPI in linux). It mostly does what the normal
1811 * Rx interrupt handler does in terms of descriptor and packet processing
1812 * but not in an interrupt context. Also it will process a specified number
1813 * of packets at most in one iteration. This value is passed down by the
1814 * kernel as the function argument 'budget'.
1815 */
1816static int vxge_poll_msix(struct napi_struct *napi, int budget)
1817{
Jon Mason16fded72011-01-18 15:02:21 +00001818 struct vxge_ring *ring = container_of(napi, struct vxge_ring, napi);
1819 int pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001820 int budget_org = budget;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001821
Jon Mason16fded72011-01-18 15:02:21 +00001822 ring->budget = budget;
1823 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001824 vxge_hw_vpath_poll_rx(ring->handle);
Jon Mason16fded72011-01-18 15:02:21 +00001825 pkts_processed = ring->pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001826
1827 if (ring->pkts_processed < budget_org) {
1828 napi_complete(napi);
Jon Mason16fded72011-01-18 15:02:21 +00001829
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001830 /* Re enable the Rx interrupts for the vpath */
1831 vxge_hw_channel_msix_unmask(
1832 (struct __vxge_hw_channel *)ring->handle,
1833 ring->rx_vector_no);
Jon Mason16fded72011-01-18 15:02:21 +00001834 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001835 }
1836
Jon Mason16fded72011-01-18 15:02:21 +00001837 /* We are copying and returning the local variable, in case if after
1838 * clearing the msix interrupt above, if the interrupt fires right
1839 * away which can preempt this NAPI thread */
1840 return pkts_processed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001841}
1842
1843static int vxge_poll_inta(struct napi_struct *napi, int budget)
1844{
1845 struct vxgedev *vdev = container_of(napi, struct vxgedev, napi);
1846 int pkts_processed = 0;
1847 int i;
1848 int budget_org = budget;
1849 struct vxge_ring *ring;
1850
Joe Perchesd8ee7072010-11-15 10:13:58 +00001851 struct __vxge_hw_device *hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001852
1853 for (i = 0; i < vdev->no_of_vpath; i++) {
1854 ring = &vdev->vpaths[i].ring;
1855 ring->budget = budget;
Jon Mason16fded72011-01-18 15:02:21 +00001856 ring->pkts_processed = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001857 vxge_hw_vpath_poll_rx(ring->handle);
1858 pkts_processed += ring->pkts_processed;
1859 budget -= ring->pkts_processed;
1860 if (budget <= 0)
1861 break;
1862 }
1863
1864 VXGE_COMPLETE_ALL_TX(vdev);
1865
1866 if (pkts_processed < budget_org) {
1867 napi_complete(napi);
1868 /* Re enable the Rx interrupts for the ring */
1869 vxge_hw_device_unmask_all(hldev);
1870 vxge_hw_device_flush_io(hldev);
1871 }
1872
1873 return pkts_processed;
1874}
1875
1876#ifdef CONFIG_NET_POLL_CONTROLLER
1877/**
1878 * vxge_netpoll - netpoll event handler entry point
1879 * @dev : pointer to the device structure.
1880 * Description:
1881 * This function will be called by upper layer to check for events on the
1882 * interface in situations where interrupts are disabled. It is used for
1883 * specific in-kernel networking tasks, such as remote consoles and kernel
1884 * debugging over the network (example netdump in RedHat).
1885 */
1886static void vxge_netpoll(struct net_device *dev)
1887{
Francois Romieu32e819e2012-03-09 19:37:55 +01001888 struct vxgedev *vdev = netdev_priv(dev);
1889 struct pci_dev *pdev = vdev->pdev;
1890 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
1891 const int irq = pdev->irq;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001892
1893 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
1894
Francois Romieu32e819e2012-03-09 19:37:55 +01001895 if (pci_channel_offline(pdev))
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001896 return;
1897
Francois Romieu32e819e2012-03-09 19:37:55 +01001898 disable_irq(irq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001899 vxge_hw_device_clear_tx_rx(hldev);
1900
1901 vxge_hw_device_clear_tx_rx(hldev);
1902 VXGE_COMPLETE_ALL_RX(vdev);
1903 VXGE_COMPLETE_ALL_TX(vdev);
1904
Francois Romieu32e819e2012-03-09 19:37:55 +01001905 enable_irq(irq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001906
1907 vxge_debug_entryexit(VXGE_TRACE,
1908 "%s:%d Exiting...", __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001909}
1910#endif
1911
1912/* RTH configuration */
1913static enum vxge_hw_status vxge_rth_configure(struct vxgedev *vdev)
1914{
1915 enum vxge_hw_status status = VXGE_HW_OK;
1916 struct vxge_hw_rth_hash_types hash_types;
1917 u8 itable[256] = {0}; /* indirection table */
1918 u8 mtable[256] = {0}; /* CPU to vpath mapping */
1919 int index;
1920
1921 /*
1922 * Filling
1923 * - itable with bucket numbers
1924 * - mtable with bucket-to-vpath mapping
1925 */
1926 for (index = 0; index < (1 << vdev->config.rth_bkt_sz); index++) {
1927 itable[index] = index;
1928 mtable[index] = index % vdev->no_of_vpath;
1929 }
1930
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001931 /* set indirection table, bucket-to-vpath mapping */
1932 status = vxge_hw_vpath_rts_rth_itable_set(vdev->vp_handles,
1933 vdev->no_of_vpath,
1934 mtable, itable,
1935 vdev->config.rth_bkt_sz);
1936 if (status != VXGE_HW_OK) {
1937 vxge_debug_init(VXGE_ERR,
1938 "RTH indirection table configuration failed "
1939 "for vpath:%d", vdev->vpaths[0].device_id);
1940 return status;
1941 }
1942
Jon Mason47f01db2010-11-11 04:25:53 +00001943 /* Fill RTH hash types */
1944 hash_types.hash_type_tcpipv4_en = vdev->config.rth_hash_type_tcpipv4;
1945 hash_types.hash_type_ipv4_en = vdev->config.rth_hash_type_ipv4;
1946 hash_types.hash_type_tcpipv6_en = vdev->config.rth_hash_type_tcpipv6;
1947 hash_types.hash_type_ipv6_en = vdev->config.rth_hash_type_ipv6;
1948 hash_types.hash_type_tcpipv6ex_en =
1949 vdev->config.rth_hash_type_tcpipv6ex;
1950 hash_types.hash_type_ipv6ex_en = vdev->config.rth_hash_type_ipv6ex;
1951
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001952 /*
Jon Mason47f01db2010-11-11 04:25:53 +00001953 * Because the itable_set() method uses the active_table field
1954 * for the target virtual path the RTH config should be updated
1955 * for all VPATHs. The h/w only uses the lowest numbered VPATH
1956 * when steering frames.
1957 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001958 for (index = 0; index < vdev->no_of_vpath; index++) {
1959 status = vxge_hw_vpath_rts_rth_set(
1960 vdev->vpaths[index].handle,
1961 vdev->config.rth_algorithm,
1962 &hash_types,
1963 vdev->config.rth_bkt_sz);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001964 if (status != VXGE_HW_OK) {
1965 vxge_debug_init(VXGE_ERR,
1966 "RTH configuration failed for vpath:%d",
1967 vdev->vpaths[index].device_id);
1968 return status;
1969 }
1970 }
1971
1972 return status;
1973}
1974
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001975/* reset vpaths */
stephen hemmingere40c10f2014-01-15 08:28:54 -08001976static enum vxge_hw_status vxge_reset_all_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001977{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001978 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00001979 struct vxge_vpath *vpath;
1980 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001981
Jon Mason7adf7d12010-07-15 08:47:24 +00001982 for (i = 0; i < vdev->no_of_vpath; i++) {
1983 vpath = &vdev->vpaths[i];
1984 if (vpath->handle) {
1985 if (vxge_hw_vpath_reset(vpath->handle) == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001986 if (is_vxge_card_up(vdev) &&
1987 vxge_hw_vpath_recover_from_reset(
Jon Mason7adf7d12010-07-15 08:47:24 +00001988 vpath->handle) != VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00001989 vxge_debug_init(VXGE_ERR,
1990 "vxge_hw_vpath_recover_"
1991 "from_reset failed for vpath: "
1992 "%d", i);
1993 return status;
1994 }
1995 } else {
1996 vxge_debug_init(VXGE_ERR,
1997 "vxge_hw_vpath_reset failed for "
1998 "vpath:%d", i);
1999 return status;
2000 }
2001 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002002 }
2003
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002004 return status;
2005}
2006
2007/* close vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002008static void vxge_close_vpaths(struct vxgedev *vdev, int index)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002009{
Jon Mason7adf7d12010-07-15 08:47:24 +00002010 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002011 int i;
Jon Mason7adf7d12010-07-15 08:47:24 +00002012
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002013 for (i = index; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002014 vpath = &vdev->vpaths[i];
2015
2016 if (vpath->handle && vpath->is_open) {
2017 vxge_hw_vpath_close(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002018 vdev->stats.vpaths_open--;
2019 }
Jon Mason7adf7d12010-07-15 08:47:24 +00002020 vpath->is_open = 0;
2021 vpath->handle = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002022 }
2023}
2024
2025/* open vpaths */
stephen hemminger42821a52010-10-21 07:50:53 +00002026static int vxge_open_vpaths(struct vxgedev *vdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002027{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002028 struct vxge_hw_vpath_attr attr;
Jon Mason7adf7d12010-07-15 08:47:24 +00002029 enum vxge_hw_status status;
2030 struct vxge_vpath *vpath;
2031 u32 vp_id = 0;
2032 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002033
2034 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002035 vpath = &vdev->vpaths[i];
Jon Mason7adf7d12010-07-15 08:47:24 +00002036 vxge_assert(vpath->is_configured);
Jon Masone7935c92010-11-11 04:26:00 +00002037
2038 if (!vdev->titan1) {
2039 struct vxge_hw_vp_config *vcfg;
2040 vcfg = &vdev->devh->config.vp_config[vpath->device_id];
2041
2042 vcfg->rti.urange_a = RTI_T1A_RX_URANGE_A;
2043 vcfg->rti.urange_b = RTI_T1A_RX_URANGE_B;
2044 vcfg->rti.urange_c = RTI_T1A_RX_URANGE_C;
2045 vcfg->tti.uec_a = TTI_T1A_TX_UFC_A;
2046 vcfg->tti.uec_b = TTI_T1A_TX_UFC_B;
2047 vcfg->tti.uec_c = TTI_T1A_TX_UFC_C(vdev->mtu);
2048 vcfg->tti.uec_d = TTI_T1A_TX_UFC_D(vdev->mtu);
2049 vcfg->tti.ltimer_val = VXGE_T1A_TTI_LTIMER_VAL;
2050 vcfg->tti.rtimer_val = VXGE_T1A_TTI_RTIMER_VAL;
2051 }
2052
Jon Mason7adf7d12010-07-15 08:47:24 +00002053 attr.vp_id = vpath->device_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002054 attr.fifo_attr.callback = vxge_xmit_compl;
2055 attr.fifo_attr.txdl_term = vxge_tx_term;
2056 attr.fifo_attr.per_txdl_space = sizeof(struct vxge_tx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002057 attr.fifo_attr.userdata = &vpath->fifo;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002058
2059 attr.ring_attr.callback = vxge_rx_1b_compl;
2060 attr.ring_attr.rxd_init = vxge_rx_initial_replenish;
2061 attr.ring_attr.rxd_term = vxge_rx_term;
2062 attr.ring_attr.per_rxd_space = sizeof(struct vxge_rx_priv);
Jon Mason7adf7d12010-07-15 08:47:24 +00002063 attr.ring_attr.userdata = &vpath->ring;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002064
Jon Mason7adf7d12010-07-15 08:47:24 +00002065 vpath->ring.ndev = vdev->ndev;
2066 vpath->ring.pdev = vdev->pdev;
Jon Mason528f7272010-12-10 14:02:56 +00002067
Jon Mason7adf7d12010-07-15 08:47:24 +00002068 status = vxge_hw_vpath_open(vdev->devh, &attr, &vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002069 if (status == VXGE_HW_OK) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002070 vpath->fifo.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002071 (struct __vxge_hw_fifo *)attr.fifo_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002072 vpath->ring.handle =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002073 (struct __vxge_hw_ring *)attr.ring_attr.userdata;
Jon Mason7adf7d12010-07-15 08:47:24 +00002074 vpath->fifo.tx_steering_type =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002075 vdev->config.tx_steering_type;
Jon Mason7adf7d12010-07-15 08:47:24 +00002076 vpath->fifo.ndev = vdev->ndev;
2077 vpath->fifo.pdev = vdev->pdev;
John Stultz827da442013-10-07 15:51:58 -07002078
2079 u64_stats_init(&vpath->fifo.stats.syncp);
2080 u64_stats_init(&vpath->ring.stats.syncp);
2081
Jon Mason98f45da2010-07-15 08:47:25 +00002082 if (vdev->config.tx_steering_type)
2083 vpath->fifo.txq =
2084 netdev_get_tx_queue(vdev->ndev, i);
2085 else
2086 vpath->fifo.txq =
2087 netdev_get_tx_queue(vdev->ndev, 0);
Jon Mason7adf7d12010-07-15 08:47:24 +00002088 vpath->fifo.indicate_max_pkts =
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002089 vdev->config.fifo_indicate_max_pkts;
Jon Mason16fded72011-01-18 15:02:21 +00002090 vpath->fifo.tx_vector_no = 0;
Jon Mason7adf7d12010-07-15 08:47:24 +00002091 vpath->ring.rx_vector_no = 0;
Jon Masonb81b3732010-11-11 04:25:58 +00002092 vpath->ring.rx_hwts = vdev->rx_hwts;
Jon Mason7adf7d12010-07-15 08:47:24 +00002093 vpath->is_open = 1;
2094 vdev->vp_handles[i] = vpath->handle;
Jon Mason7adf7d12010-07-15 08:47:24 +00002095 vpath->ring.vlan_tag_strip = vdev->vlan_tag_strip;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002096 vdev->stats.vpaths_open++;
2097 } else {
2098 vdev->stats.vpath_open_fail++;
Jon Mason528f7272010-12-10 14:02:56 +00002099 vxge_debug_init(VXGE_ERR, "%s: vpath: %d failed to "
2100 "open with status: %d",
2101 vdev->ndev->name, vpath->device_id,
2102 status);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002103 vxge_close_vpaths(vdev, 0);
2104 return -EPERM;
2105 }
2106
Jon Mason7adf7d12010-07-15 08:47:24 +00002107 vp_id = vpath->handle->vpath->vp_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002108 vdev->vpaths_deployed |= vxge_mBIT(vp_id);
2109 }
Jon Mason528f7272010-12-10 14:02:56 +00002110
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002111 return VXGE_HW_OK;
2112}
2113
Jon Mason16fded72011-01-18 15:02:21 +00002114/**
2115 * adaptive_coalesce_tx_interrupts - Changes the interrupt coalescing
2116 * if the interrupts are not within a range
2117 * @fifo: pointer to transmit fifo structure
2118 * Description: The function changes boundary timer and restriction timer
2119 * value depends on the traffic
2120 * Return Value: None
2121 */
2122static void adaptive_coalesce_tx_interrupts(struct vxge_fifo *fifo)
2123{
2124 fifo->interrupt_count++;
2125 if (jiffies > fifo->jiffies + HZ / 100) {
2126 struct __vxge_hw_fifo *hw_fifo = fifo->handle;
2127
2128 fifo->jiffies = jiffies;
2129 if (fifo->interrupt_count > VXGE_T1A_MAX_TX_INTERRUPT_COUNT &&
2130 hw_fifo->rtimer != VXGE_TTI_RTIMER_ADAPT_VAL) {
2131 hw_fifo->rtimer = VXGE_TTI_RTIMER_ADAPT_VAL;
2132 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2133 } else if (hw_fifo->rtimer != 0) {
2134 hw_fifo->rtimer = 0;
2135 vxge_hw_vpath_dynamic_tti_rtimer_set(hw_fifo);
2136 }
2137 fifo->interrupt_count = 0;
2138 }
2139}
2140
2141/**
2142 * adaptive_coalesce_rx_interrupts - Changes the interrupt coalescing
2143 * if the interrupts are not within a range
2144 * @ring: pointer to receive ring structure
2145 * Description: The function increases of decreases the packet counts within
2146 * the ranges of traffic utilization, if the interrupts due to this ring are
2147 * not within a fixed range.
2148 * Return Value: Nothing
2149 */
2150static void adaptive_coalesce_rx_interrupts(struct vxge_ring *ring)
2151{
2152 ring->interrupt_count++;
2153 if (jiffies > ring->jiffies + HZ / 100) {
2154 struct __vxge_hw_ring *hw_ring = ring->handle;
2155
2156 ring->jiffies = jiffies;
2157 if (ring->interrupt_count > VXGE_T1A_MAX_INTERRUPT_COUNT &&
2158 hw_ring->rtimer != VXGE_RTI_RTIMER_ADAPT_VAL) {
2159 hw_ring->rtimer = VXGE_RTI_RTIMER_ADAPT_VAL;
2160 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2161 } else if (hw_ring->rtimer != 0) {
2162 hw_ring->rtimer = 0;
2163 vxge_hw_vpath_dynamic_rti_rtimer_set(hw_ring);
2164 }
2165 ring->interrupt_count = 0;
2166 }
2167}
2168
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002169/*
2170 * vxge_isr_napi
2171 * @irq: the irq of the device.
2172 * @dev_id: a void pointer to the hldev structure of the Titan device
2173 * @ptregs: pointer to the registers pushed on the stack.
2174 *
2175 * This function is the ISR handler of the device when napi is enabled. It
2176 * identifies the reason for the interrupt and calls the relevant service
2177 * routines.
2178 */
2179static irqreturn_t vxge_isr_napi(int irq, void *dev_id)
2180{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002181 struct net_device *dev;
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002182 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002183 u64 reason;
2184 enum vxge_hw_status status;
Jon Mason2c913082010-11-11 04:26:03 +00002185 struct vxgedev *vdev = (struct vxgedev *)dev_id;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002186
2187 vxge_debug_intr(VXGE_TRACE, "%s:%d", __func__, __LINE__);
2188
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002189 dev = vdev->ndev;
Joe Perchesd8ee7072010-11-15 10:13:58 +00002190 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002191
2192 if (pci_channel_offline(vdev->pdev))
2193 return IRQ_NONE;
2194
2195 if (unlikely(!is_vxge_card_up(vdev)))
Jon Mason4d2a5b42010-11-11 04:25:54 +00002196 return IRQ_HANDLED;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002197
Jon Mason528f7272010-12-10 14:02:56 +00002198 status = vxge_hw_device_begin_irq(hldev, vdev->exec_mode, &reason);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002199 if (status == VXGE_HW_OK) {
2200 vxge_hw_device_mask_all(hldev);
2201
2202 if (reason &
2203 VXGE_HW_TITAN_GENERAL_INT_STATUS_VPATH_TRAFFIC_INT(
2204 vdev->vpaths_deployed >>
2205 (64 - VXGE_HW_MAX_VIRTUAL_PATHS))) {
2206
2207 vxge_hw_device_clear_tx_rx(hldev);
2208 napi_schedule(&vdev->napi);
2209 vxge_debug_intr(VXGE_TRACE,
2210 "%s:%d Exiting...", __func__, __LINE__);
2211 return IRQ_HANDLED;
2212 } else
2213 vxge_hw_device_unmask_all(hldev);
2214 } else if (unlikely((status == VXGE_HW_ERR_VPATH) ||
2215 (status == VXGE_HW_ERR_CRITICAL) ||
2216 (status == VXGE_HW_ERR_FIFO))) {
2217 vxge_hw_device_mask_all(hldev);
2218 vxge_hw_device_flush_io(hldev);
2219 return IRQ_HANDLED;
2220 } else if (unlikely(status == VXGE_HW_ERR_SLOT_FREEZE))
2221 return IRQ_HANDLED;
2222
2223 vxge_debug_intr(VXGE_TRACE, "%s:%d Exiting...", __func__, __LINE__);
2224 return IRQ_NONE;
2225}
2226
2227#ifdef CONFIG_PCI_MSI
2228
Jon Mason16fded72011-01-18 15:02:21 +00002229static irqreturn_t vxge_tx_msix_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002230{
2231 struct vxge_fifo *fifo = (struct vxge_fifo *)dev_id;
2232
Jon Mason16fded72011-01-18 15:02:21 +00002233 adaptive_coalesce_tx_interrupts(fifo);
2234
2235 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)fifo->handle,
2236 fifo->tx_vector_no);
2237
2238 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)fifo->handle,
2239 fifo->tx_vector_no);
2240
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002241 VXGE_COMPLETE_VPATH_TX(fifo);
2242
Jon Mason16fded72011-01-18 15:02:21 +00002243 vxge_hw_channel_msix_unmask((struct __vxge_hw_channel *)fifo->handle,
2244 fifo->tx_vector_no);
2245
2246 mmiowb();
2247
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002248 return IRQ_HANDLED;
2249}
2250
Jon Mason16fded72011-01-18 15:02:21 +00002251static irqreturn_t vxge_rx_msix_napi_handle(int irq, void *dev_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002252{
2253 struct vxge_ring *ring = (struct vxge_ring *)dev_id;
2254
Jon Mason16fded72011-01-18 15:02:21 +00002255 adaptive_coalesce_rx_interrupts(ring);
2256
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002257 vxge_hw_channel_msix_mask((struct __vxge_hw_channel *)ring->handle,
Jon Mason16fded72011-01-18 15:02:21 +00002258 ring->rx_vector_no);
2259
2260 vxge_hw_channel_msix_clear((struct __vxge_hw_channel *)ring->handle,
2261 ring->rx_vector_no);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002262
2263 napi_schedule(&ring->napi);
2264 return IRQ_HANDLED;
2265}
2266
2267static irqreturn_t
2268vxge_alarm_msix_handle(int irq, void *dev_id)
2269{
2270 int i;
2271 enum vxge_hw_status status;
2272 struct vxge_vpath *vpath = (struct vxge_vpath *)dev_id;
2273 struct vxgedev *vdev = vpath->vdev;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002274 int msix_id = (vpath->handle->vpath->vp_id *
2275 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002276
2277 for (i = 0; i < vdev->no_of_vpath; i++) {
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002278 /* Reduce the chance of losing alarm interrupts by masking
Jon Mason16fded72011-01-18 15:02:21 +00002279 * the vector. A pending bit will be set if an alarm is
2280 * generated and on unmask the interrupt will be fired.
2281 */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002282 vxge_hw_vpath_msix_mask(vdev->vpaths[i].handle, msix_id);
Jon Mason16fded72011-01-18 15:02:21 +00002283 vxge_hw_vpath_msix_clear(vdev->vpaths[i].handle, msix_id);
2284 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002285
2286 status = vxge_hw_vpath_alarm_process(vdev->vpaths[i].handle,
2287 vdev->exec_mode);
2288 if (status == VXGE_HW_OK) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002289 vxge_hw_vpath_msix_unmask(vdev->vpaths[i].handle,
Jon Mason16fded72011-01-18 15:02:21 +00002290 msix_id);
2291 mmiowb();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002292 continue;
2293 }
2294 vxge_debug_intr(VXGE_ERR,
2295 "%s: vxge_hw_vpath_alarm_process failed %x ",
2296 VXGE_DRIVER_NAME, status);
2297 }
2298 return IRQ_HANDLED;
2299}
2300
2301static int vxge_alloc_msix(struct vxgedev *vdev)
2302{
2303 int j, i, ret = 0;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002304 int msix_intr_vect = 0, temp;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002305 vdev->intr_cnt = 0;
2306
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002307start:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002308 /* Tx/Rx MSIX Vectors count */
2309 vdev->intr_cnt = vdev->no_of_vpath * 2;
2310
2311 /* Alarm MSIX Vectors count */
2312 vdev->intr_cnt++;
2313
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002314 vdev->entries = kcalloc(vdev->intr_cnt, sizeof(struct msix_entry),
2315 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002316 if (!vdev->entries) {
2317 vxge_debug_init(VXGE_ERR,
2318 "%s: memory allocation failed",
2319 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002320 ret = -ENOMEM;
2321 goto alloc_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002322 }
2323
Joe Perchesbaeb2ff2010-08-11 07:02:48 +00002324 vdev->vxge_entries = kcalloc(vdev->intr_cnt,
2325 sizeof(struct vxge_msix_entry),
2326 GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002327 if (!vdev->vxge_entries) {
2328 vxge_debug_init(VXGE_ERR, "%s: memory allocation failed",
2329 VXGE_DRIVER_NAME);
Michal Schmidtcc413d92010-06-24 04:13:44 +00002330 ret = -ENOMEM;
2331 goto alloc_vxge_entries_failed;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002332 }
2333
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002334 for (i = 0, j = 0; i < vdev->no_of_vpath; i++) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002335
2336 msix_intr_vect = i * VXGE_HW_VPATH_MSIX_ACTIVE;
2337
2338 /* Initialize the fifo vector */
2339 vdev->entries[j].entry = msix_intr_vect;
2340 vdev->vxge_entries[j].entry = msix_intr_vect;
2341 vdev->vxge_entries[j].in_use = 0;
2342 j++;
2343
2344 /* Initialize the ring vector */
2345 vdev->entries[j].entry = msix_intr_vect + 1;
2346 vdev->vxge_entries[j].entry = msix_intr_vect + 1;
2347 vdev->vxge_entries[j].in_use = 0;
2348 j++;
2349 }
2350
2351 /* Initialize the alarm vector */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002352 vdev->entries[j].entry = VXGE_ALARM_MSIX_ID;
2353 vdev->vxge_entries[j].entry = VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002354 vdev->vxge_entries[j].in_use = 0;
2355
Alexander Gordeev9644cdc2014-02-18 11:11:51 +01002356 ret = pci_enable_msix_range(vdev->pdev,
2357 vdev->entries, 3, vdev->intr_cnt);
2358 if (ret < 0) {
2359 ret = -ENODEV;
2360 goto enable_msix_failed;
2361 } else if (ret < vdev->intr_cnt) {
2362 pci_disable_msix(vdev->pdev);
2363
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002364 vxge_debug_init(VXGE_ERR,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002365 "%s: MSI-X enable failed for %d vectors, ret: %d",
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002366 VXGE_DRIVER_NAME, vdev->intr_cnt, ret);
Alexander Gordeev9644cdc2014-02-18 11:11:51 +01002367 if (max_config_vpath != VXGE_USE_DEFAULT) {
Michal Schmidtcc413d92010-06-24 04:13:44 +00002368 ret = -ENODEV;
2369 goto enable_msix_failed;
2370 }
2371
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002372 kfree(vdev->entries);
2373 kfree(vdev->vxge_entries);
2374 vdev->entries = NULL;
2375 vdev->vxge_entries = NULL;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002376 /* Try with less no of vector by reducing no of vpaths count */
2377 temp = (ret - 1)/2;
2378 vxge_close_vpaths(vdev, temp);
2379 vdev->no_of_vpath = temp;
2380 goto start;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002381 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002382 return 0;
Michal Schmidtcc413d92010-06-24 04:13:44 +00002383
2384enable_msix_failed:
2385 kfree(vdev->vxge_entries);
2386alloc_vxge_entries_failed:
2387 kfree(vdev->entries);
2388alloc_entries_failed:
2389 return ret;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002390}
2391
2392static int vxge_enable_msix(struct vxgedev *vdev)
2393{
2394
2395 int i, ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002396 /* 0 - Tx, 1 - Rx */
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002397 int tim_msix_id[4] = {0, 1, 0, 0};
2398
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002399 vdev->intr_cnt = 0;
2400
2401 /* allocate msix vectors */
2402 ret = vxge_alloc_msix(vdev);
2403 if (!ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002404 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002405 struct vxge_vpath *vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002406
Jon Mason7adf7d12010-07-15 08:47:24 +00002407 /* If fifo or ring are not enabled, the MSIX vector for
2408 * it should be set to 0.
2409 */
2410 vpath->ring.rx_vector_no = (vpath->device_id *
2411 VXGE_HW_VPATH_MSIX_ACTIVE) + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002412
Jon Mason16fded72011-01-18 15:02:21 +00002413 vpath->fifo.tx_vector_no = (vpath->device_id *
2414 VXGE_HW_VPATH_MSIX_ACTIVE);
2415
Jon Mason7adf7d12010-07-15 08:47:24 +00002416 vxge_hw_vpath_msix_set(vpath->handle, tim_msix_id,
2417 VXGE_ALARM_MSIX_ID);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002418 }
2419 }
2420
2421 return ret;
2422}
2423
2424static void vxge_rem_msix_isr(struct vxgedev *vdev)
2425{
2426 int intr_cnt;
2427
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002428 for (intr_cnt = 0; intr_cnt < (vdev->no_of_vpath * 2 + 1);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002429 intr_cnt++) {
2430 if (vdev->vxge_entries[intr_cnt].in_use) {
2431 synchronize_irq(vdev->entries[intr_cnt].vector);
2432 free_irq(vdev->entries[intr_cnt].vector,
2433 vdev->vxge_entries[intr_cnt].arg);
2434 vdev->vxge_entries[intr_cnt].in_use = 0;
2435 }
2436 }
2437
2438 kfree(vdev->entries);
2439 kfree(vdev->vxge_entries);
2440 vdev->entries = NULL;
2441 vdev->vxge_entries = NULL;
2442
2443 if (vdev->config.intr_type == MSI_X)
2444 pci_disable_msix(vdev->pdev);
2445}
2446#endif
2447
2448static void vxge_rem_isr(struct vxgedev *vdev)
2449{
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002450#ifdef CONFIG_PCI_MSI
2451 if (vdev->config.intr_type == MSI_X) {
2452 vxge_rem_msix_isr(vdev);
2453 } else
2454#endif
2455 if (vdev->config.intr_type == INTA) {
2456 synchronize_irq(vdev->pdev->irq);
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002457 free_irq(vdev->pdev->irq, vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002458 }
2459}
2460
2461static int vxge_add_isr(struct vxgedev *vdev)
2462{
2463 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002464#ifdef CONFIG_PCI_MSI
2465 int vp_idx = 0, intr_idx = 0, intr_cnt = 0, msix_idx = 0, irq_req = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002466 int pci_fun = PCI_FUNC(vdev->pdev->devfn);
2467
2468 if (vdev->config.intr_type == MSI_X)
2469 ret = vxge_enable_msix(vdev);
2470
2471 if (ret) {
2472 vxge_debug_init(VXGE_ERR,
2473 "%s: Enabling MSI-X Failed", VXGE_DRIVER_NAME);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002474 vxge_debug_init(VXGE_ERR,
2475 "%s: Defaulting to INTA", VXGE_DRIVER_NAME);
2476 vdev->config.intr_type = INTA;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002477 }
2478
2479 if (vdev->config.intr_type == MSI_X) {
2480 for (intr_idx = 0;
2481 intr_idx < (vdev->no_of_vpath *
2482 VXGE_HW_VPATH_MSIX_ACTIVE); intr_idx++) {
2483
2484 msix_idx = intr_idx % VXGE_HW_VPATH_MSIX_ACTIVE;
2485 irq_req = 0;
2486
2487 switch (msix_idx) {
2488 case 0:
2489 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002490 "%s:vxge:MSI-X %d - Tx - fn:%d vpath:%d",
2491 vdev->ndev->name,
2492 vdev->entries[intr_cnt].entry,
2493 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002494 ret = request_irq(
2495 vdev->entries[intr_cnt].vector,
2496 vxge_tx_msix_handle, 0,
2497 vdev->desc[intr_cnt],
2498 &vdev->vpaths[vp_idx].fifo);
2499 vdev->vxge_entries[intr_cnt].arg =
2500 &vdev->vpaths[vp_idx].fifo;
2501 irq_req = 1;
2502 break;
2503 case 1:
2504 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002505 "%s:vxge:MSI-X %d - Rx - fn:%d vpath:%d",
2506 vdev->ndev->name,
2507 vdev->entries[intr_cnt].entry,
2508 pci_fun, vp_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002509 ret = request_irq(
2510 vdev->entries[intr_cnt].vector,
2511 vxge_rx_msix_napi_handle,
2512 0,
2513 vdev->desc[intr_cnt],
2514 &vdev->vpaths[vp_idx].ring);
2515 vdev->vxge_entries[intr_cnt].arg =
2516 &vdev->vpaths[vp_idx].ring;
2517 irq_req = 1;
2518 break;
2519 }
2520
2521 if (ret) {
2522 vxge_debug_init(VXGE_ERR,
2523 "%s: MSIX - %d Registration failed",
2524 vdev->ndev->name, intr_cnt);
2525 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002526 vdev->config.intr_type = INTA;
2527 vxge_debug_init(VXGE_ERR,
2528 "%s: Defaulting to INTA"
2529 , vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002530 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002531 }
2532
2533 if (irq_req) {
2534 /* We requested for this msix interrupt */
2535 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002536 msix_idx += vdev->vpaths[vp_idx].device_id *
2537 VXGE_HW_VPATH_MSIX_ACTIVE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002538 vxge_hw_vpath_msix_unmask(
2539 vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002540 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002541 intr_cnt++;
2542 }
2543
2544 /* Point to next vpath handler */
Joe Perches8e95a202009-12-03 07:58:21 +00002545 if (((intr_idx + 1) % VXGE_HW_VPATH_MSIX_ACTIVE == 0) &&
2546 (vp_idx < (vdev->no_of_vpath - 1)))
2547 vp_idx++;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002548 }
2549
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002550 intr_cnt = vdev->no_of_vpath * 2;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002551 snprintf(vdev->desc[intr_cnt], VXGE_INTR_STRLEN,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002552 "%s:vxge:MSI-X %d - Alarm - fn:%d",
2553 vdev->ndev->name,
2554 vdev->entries[intr_cnt].entry,
2555 pci_fun);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002556 /* For Alarm interrupts */
2557 ret = request_irq(vdev->entries[intr_cnt].vector,
2558 vxge_alarm_msix_handle, 0,
2559 vdev->desc[intr_cnt],
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002560 &vdev->vpaths[0]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002561 if (ret) {
2562 vxge_debug_init(VXGE_ERR,
2563 "%s: MSIX - %d Registration failed",
2564 vdev->ndev->name, intr_cnt);
2565 vxge_rem_msix_isr(vdev);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002566 vdev->config.intr_type = INTA;
2567 vxge_debug_init(VXGE_ERR,
2568 "%s: Defaulting to INTA",
2569 vdev->ndev->name);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002570 goto INTA_MODE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002571 }
2572
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002573 msix_idx = (vdev->vpaths[0].handle->vpath->vp_id *
2574 VXGE_HW_VPATH_MSIX_ACTIVE) + VXGE_ALARM_MSIX_ID;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002575 vxge_hw_vpath_msix_unmask(vdev->vpaths[vp_idx].handle,
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002576 msix_idx);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002577 vdev->vxge_entries[intr_cnt].in_use = 1;
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002578 vdev->vxge_entries[intr_cnt].arg = &vdev->vpaths[0];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002579 }
2580INTA_MODE:
2581#endif
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002582
2583 if (vdev->config.intr_type == INTA) {
Sreenivasa Honnurb59c94572010-03-28 22:11:41 +00002584 snprintf(vdev->desc[0], VXGE_INTR_STRLEN,
2585 "%s:vxge:INTA", vdev->ndev->name);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00002586 vxge_hw_device_set_intr_type(vdev->devh,
2587 VXGE_HW_INTR_MODE_IRQLINE);
Jon Mason16fded72011-01-18 15:02:21 +00002588
2589 vxge_hw_vpath_tti_ci_set(vdev->vpaths[0].fifo.handle);
2590
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002591 ret = request_irq((int) vdev->pdev->irq,
2592 vxge_isr_napi,
Sreenivasa Honnura5d165b2009-07-01 21:16:37 +00002593 IRQF_SHARED, vdev->desc[0], vdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002594 if (ret) {
2595 vxge_debug_init(VXGE_ERR,
2596 "%s %s-%d: ISR registration failed",
2597 VXGE_DRIVER_NAME, "IRQ", vdev->pdev->irq);
2598 return -ENODEV;
2599 }
2600 vxge_debug_init(VXGE_TRACE,
2601 "new %s-%d line allocated",
2602 "IRQ", vdev->pdev->irq);
2603 }
2604
2605 return VXGE_HW_OK;
2606}
2607
2608static void vxge_poll_vp_reset(unsigned long data)
2609{
2610 struct vxgedev *vdev = (struct vxgedev *)data;
2611 int i, j = 0;
2612
2613 for (i = 0; i < vdev->no_of_vpath; i++) {
2614 if (test_bit(i, &vdev->vp_reset)) {
2615 vxge_reset_vpath(vdev, i);
2616 j++;
2617 }
2618 }
2619 if (j && (vdev->config.intr_type != MSI_X)) {
2620 vxge_hw_device_unmask_all(vdev->devh);
2621 vxge_hw_device_flush_io(vdev->devh);
2622 }
2623
2624 mod_timer(&vdev->vp_reset_timer, jiffies + HZ / 2);
2625}
2626
2627static void vxge_poll_vp_lockup(unsigned long data)
2628{
2629 struct vxgedev *vdev = (struct vxgedev *)data;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002630 enum vxge_hw_status status = VXGE_HW_OK;
Jon Mason7adf7d12010-07-15 08:47:24 +00002631 struct vxge_vpath *vpath;
2632 struct vxge_ring *ring;
2633 int i;
stephen hemminger62ea0552011-06-20 10:35:07 +00002634 unsigned long rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002635
2636 for (i = 0; i < vdev->no_of_vpath; i++) {
2637 ring = &vdev->vpaths[i].ring;
stephen hemminger62ea0552011-06-20 10:35:07 +00002638
2639 /* Truncated to machine word size number of frames */
2640 rx_frms = ACCESS_ONCE(ring->stats.rx_frms);
2641
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002642 /* Did this vpath received any packets */
stephen hemminger62ea0552011-06-20 10:35:07 +00002643 if (ring->stats.prev_rx_frms == rx_frms) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002644 status = vxge_hw_vpath_check_leak(ring->handle);
2645
2646 /* Did it received any packets last time */
2647 if ((VXGE_HW_FAIL == status) &&
2648 (VXGE_HW_FAIL == ring->last_status)) {
2649
2650 /* schedule vpath reset */
2651 if (!test_and_set_bit(i, &vdev->vp_reset)) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002652 vpath = &vdev->vpaths[i];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002653
2654 /* disable interrupts for this vpath */
2655 vxge_vpath_intr_disable(vdev, i);
2656
2657 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00002658 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002659 continue;
2660 }
2661 }
2662 }
stephen hemminger62ea0552011-06-20 10:35:07 +00002663 ring->stats.prev_rx_frms = rx_frms;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002664 ring->last_status = status;
2665 }
2666
2667 /* Check every 1 milli second */
2668 mod_timer(&vdev->vp_lockup_timer, jiffies + HZ / 1000);
2669}
2670
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002671static netdev_features_t vxge_fix_features(struct net_device *dev,
2672 netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002673{
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002674 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002675
2676 /* Enabling RTH requires some of the logic in vxge_device_register and a
2677 * vpath reset. Due to these restrictions, only allow modification
2678 * while the interface is down.
2679 */
2680 if ((changed & NETIF_F_RXHASH) && netif_running(dev))
2681 features ^= NETIF_F_RXHASH;
2682
2683 return features;
2684}
2685
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002686static int vxge_set_features(struct net_device *dev, netdev_features_t features)
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002687{
2688 struct vxgedev *vdev = netdev_priv(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00002689 netdev_features_t changed = dev->features ^ features;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00002690
2691 if (!(changed & NETIF_F_RXHASH))
2692 return 0;
2693
2694 /* !netif_running() ensured by vxge_fix_features() */
2695
2696 vdev->devh->config.rth_en = !!(features & NETIF_F_RXHASH);
2697 if (vxge_reset_all_vpaths(vdev) != VXGE_HW_OK) {
2698 dev->features = features ^ NETIF_F_RXHASH;
2699 vdev->devh->config.rth_en = !!(dev->features & NETIF_F_RXHASH);
2700 return -EIO;
2701 }
2702
2703 return 0;
2704}
2705
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002706/**
2707 * vxge_open
2708 * @dev: pointer to the device structure.
2709 *
2710 * This function is the open entry point of the driver. It mainly calls a
2711 * function to allocate Rx buffers and inserts them into the buffer
2712 * descriptors and then enables the Rx part of the NIC.
2713 * Return value: '0' on success and an appropriate (-)ve integer as
2714 * defined in errno.h file on failure.
2715 */
Jon Mason528f7272010-12-10 14:02:56 +00002716static int vxge_open(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002717{
2718 enum vxge_hw_status status;
2719 struct vxgedev *vdev;
2720 struct __vxge_hw_device *hldev;
Jon Mason7adf7d12010-07-15 08:47:24 +00002721 struct vxge_vpath *vpath;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002722 int ret = 0;
2723 int i;
2724 u64 val64, function_mode;
Jon Mason528f7272010-12-10 14:02:56 +00002725
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002726 vxge_debug_entryexit(VXGE_TRACE,
2727 "%s: %s:%d", dev->name, __func__, __LINE__);
2728
Joe Perches5f54ceb2010-11-15 11:12:30 +00002729 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002730 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002731 function_mode = vdev->config.device_hw_info.function_mode;
2732
2733 /* make sure you have link off by default every time Nic is
2734 * initialized */
2735 netif_carrier_off(dev);
2736
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002737 /* Open VPATHs */
2738 status = vxge_open_vpaths(vdev);
2739 if (status != VXGE_HW_OK) {
2740 vxge_debug_init(VXGE_ERR,
2741 "%s: fatal: Vpath open failed", vdev->ndev->name);
2742 ret = -EPERM;
2743 goto out0;
2744 }
2745
2746 vdev->mtu = dev->mtu;
2747
2748 status = vxge_add_isr(vdev);
2749 if (status != VXGE_HW_OK) {
2750 vxge_debug_init(VXGE_ERR,
2751 "%s: fatal: ISR add failed", dev->name);
2752 ret = -EPERM;
2753 goto out1;
2754 }
2755
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002756 if (vdev->config.intr_type != MSI_X) {
2757 netif_napi_add(dev, &vdev->napi, vxge_poll_inta,
2758 vdev->config.napi_weight);
2759 napi_enable(&vdev->napi);
Jon Mason7adf7d12010-07-15 08:47:24 +00002760 for (i = 0; i < vdev->no_of_vpath; i++) {
2761 vpath = &vdev->vpaths[i];
2762 vpath->ring.napi_p = &vdev->napi;
2763 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002764 } else {
2765 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002766 vpath = &vdev->vpaths[i];
2767 netif_napi_add(dev, &vpath->ring.napi,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002768 vxge_poll_msix, vdev->config.napi_weight);
Jon Mason7adf7d12010-07-15 08:47:24 +00002769 napi_enable(&vpath->ring.napi);
2770 vpath->ring.napi_p = &vpath->ring.napi;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002771 }
2772 }
2773
2774 /* configure RTH */
2775 if (vdev->config.rth_steering) {
2776 status = vxge_rth_configure(vdev);
2777 if (status != VXGE_HW_OK) {
2778 vxge_debug_init(VXGE_ERR,
2779 "%s: fatal: RTH configuration failed",
2780 dev->name);
2781 ret = -EPERM;
2782 goto out2;
2783 }
2784 }
Jon Mason47f01db2010-11-11 04:25:53 +00002785 printk(KERN_INFO "%s: Receive Hashing Offload %s\n", dev->name,
2786 hldev->config.rth_en ? "enabled" : "disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002787
2788 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002789 vpath = &vdev->vpaths[i];
2790
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002791 /* set initial mtu before enabling the device */
Jon Mason7adf7d12010-07-15 08:47:24 +00002792 status = vxge_hw_vpath_mtu_set(vpath->handle, vdev->mtu);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002793 if (status != VXGE_HW_OK) {
2794 vxge_debug_init(VXGE_ERR,
2795 "%s: fatal: can not set new MTU", dev->name);
2796 ret = -EPERM;
2797 goto out2;
2798 }
2799 }
2800
2801 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_TRACE, VXGE_COMPONENT_LL, vdev);
2802 vxge_debug_init(vdev->level_trace,
2803 "%s: MTU is %d", vdev->ndev->name, vdev->mtu);
2804 VXGE_DEVICE_DEBUG_LEVEL_SET(VXGE_ERR, VXGE_COMPONENT_LL, vdev);
2805
Jon Mason7adf7d12010-07-15 08:47:24 +00002806 /* Restore the DA, VID table and also multicast and promiscuous mode
2807 * states
2808 */
2809 if (vdev->all_multi_flg) {
2810 for (i = 0; i < vdev->no_of_vpath; i++) {
2811 vpath = &vdev->vpaths[i];
2812 vxge_restore_vpath_mac_addr(vpath);
2813 vxge_restore_vpath_vid_table(vpath);
2814
2815 status = vxge_hw_vpath_mcast_enable(vpath->handle);
2816 if (status != VXGE_HW_OK)
2817 vxge_debug_init(VXGE_ERR,
2818 "%s:%d Enabling multicast failed",
2819 __func__, __LINE__);
2820 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002821 }
2822
2823 /* Enable vpath to sniff all unicast/multicast traffic that not
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002824 * addressed to them. We allow promiscuous mode for PF only
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002825 */
2826
2827 val64 = 0;
2828 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
2829 val64 |= VXGE_HW_RXMAC_AUTHORIZE_ALL_ADDR_VP(i);
2830
2831 vxge_hw_mgmt_reg_write(vdev->devh,
2832 vxge_hw_mgmt_reg_type_mrpcim,
2833 0,
2834 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2835 rxmac_authorize_all_addr),
2836 val64);
2837
2838 vxge_hw_mgmt_reg_write(vdev->devh,
2839 vxge_hw_mgmt_reg_type_mrpcim,
2840 0,
2841 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2842 rxmac_authorize_all_vid),
2843 val64);
2844
2845 vxge_set_multicast(dev);
2846
2847 /* Enabling Bcast and mcast for all vpath */
2848 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002849 vpath = &vdev->vpaths[i];
2850 status = vxge_hw_vpath_bcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002851 if (status != VXGE_HW_OK)
2852 vxge_debug_init(VXGE_ERR,
2853 "%s : Can not enable bcast for vpath "
2854 "id %d", dev->name, i);
2855 if (vdev->config.addr_learn_en) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002856 status = vxge_hw_vpath_mcast_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002857 if (status != VXGE_HW_OK)
2858 vxge_debug_init(VXGE_ERR,
2859 "%s : Can not enable mcast for vpath "
2860 "id %d", dev->name, i);
2861 }
2862 }
2863
2864 vxge_hw_device_setpause_data(vdev->devh, 0,
2865 vdev->config.tx_pause_enable,
2866 vdev->config.rx_pause_enable);
2867
2868 if (vdev->vp_reset_timer.function == NULL)
Joe Perches044a3812012-04-03 12:14:31 +00002869 vxge_os_timer(&vdev->vp_reset_timer, vxge_poll_vp_reset, vdev,
2870 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002871
Jon Masone7935c92010-11-11 04:26:00 +00002872 /* There is no need to check for RxD leak and RxD lookup on Titan1A */
2873 if (vdev->titan1 && vdev->vp_lockup_timer.function == NULL)
Joe Perches044a3812012-04-03 12:14:31 +00002874 vxge_os_timer(&vdev->vp_lockup_timer, vxge_poll_vp_lockup, vdev,
Jon Masone7935c92010-11-11 04:26:00 +00002875 HZ / 2);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002876
2877 set_bit(__VXGE_STATE_CARD_UP, &vdev->state);
2878
2879 smp_wmb();
2880
2881 if (vxge_hw_device_link_state_get(vdev->devh) == VXGE_HW_LINK_UP) {
2882 netif_carrier_on(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00002883 netdev_notice(vdev->ndev, "Link Up\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002884 vdev->stats.link_up++;
2885 }
2886
2887 vxge_hw_device_intr_enable(vdev->devh);
2888
2889 smp_wmb();
2890
2891 for (i = 0; i < vdev->no_of_vpath; i++) {
Jon Mason7adf7d12010-07-15 08:47:24 +00002892 vpath = &vdev->vpaths[i];
2893
2894 vxge_hw_vpath_enable(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002895 smp_wmb();
Jon Mason7adf7d12010-07-15 08:47:24 +00002896 vxge_hw_vpath_rx_doorbell_init(vpath->handle);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002897 }
2898
Jon Masond03848e2010-07-15 08:47:23 +00002899 netif_tx_start_all_queues(vdev->ndev);
Jon Mason16fded72011-01-18 15:02:21 +00002900
2901 /* configure CI */
2902 vxge_config_ci_for_tti_rti(vdev);
2903
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002904 goto out0;
2905
2906out2:
2907 vxge_rem_isr(vdev);
2908
2909 /* Disable napi */
2910 if (vdev->config.intr_type != MSI_X)
2911 napi_disable(&vdev->napi);
2912 else {
2913 for (i = 0; i < vdev->no_of_vpath; i++)
2914 napi_disable(&vdev->vpaths[i].ring.napi);
2915 }
2916
2917out1:
2918 vxge_close_vpaths(vdev, 0);
2919out0:
2920 vxge_debug_entryexit(VXGE_TRACE,
2921 "%s: %s:%d Exiting...",
2922 dev->name, __func__, __LINE__);
2923 return ret;
2924}
2925
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002926/* Loop through the mac address list and delete all the entries */
stephen hemminger42821a52010-10-21 07:50:53 +00002927static void vxge_free_mac_add_list(struct vxge_vpath *vpath)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002928{
2929
2930 struct list_head *entry, *next;
2931 if (list_empty(&vpath->mac_addr_list))
2932 return;
2933
2934 list_for_each_safe(entry, next, &vpath->mac_addr_list) {
2935 list_del(entry);
2936 kfree((struct vxge_mac_addrs *)entry);
2937 }
2938}
2939
2940static void vxge_napi_del_all(struct vxgedev *vdev)
2941{
2942 int i;
2943 if (vdev->config.intr_type != MSI_X)
2944 netif_napi_del(&vdev->napi);
2945 else {
2946 for (i = 0; i < vdev->no_of_vpath; i++)
2947 netif_napi_del(&vdev->vpaths[i].ring.napi);
2948 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002949}
2950
stephen hemminger42821a52010-10-21 07:50:53 +00002951static int do_vxge_close(struct net_device *dev, int do_io)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002952{
2953 enum vxge_hw_status status;
2954 struct vxgedev *vdev;
2955 struct __vxge_hw_device *hldev;
2956 int i;
2957 u64 val64, vpath_vector;
2958 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d",
2959 dev->name, __func__, __LINE__);
2960
Joe Perches5f54ceb2010-11-15 11:12:30 +00002961 vdev = netdev_priv(dev);
Joe Perchesd8ee7072010-11-15 10:13:58 +00002962 hldev = pci_get_drvdata(vdev->pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002963
Sreenivasa Honnurbd9ee682009-07-01 21:14:03 +00002964 if (unlikely(!is_vxge_card_up(vdev)))
2965 return 0;
2966
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002967 /* If vxge_handle_crit_err task is executing,
2968 * wait till it completes. */
2969 while (test_and_set_bit(__VXGE_STATE_RESET_CARD, &vdev->state))
2970 msleep(50);
2971
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002972 if (do_io) {
2973 /* Put the vpath back in normal mode */
2974 vpath_vector = vxge_mBIT(vdev->vpaths[0].device_id);
2975 status = vxge_hw_mgmt_reg_read(vdev->devh,
2976 vxge_hw_mgmt_reg_type_mrpcim,
2977 0,
2978 (ulong)offsetof(
2979 struct vxge_hw_mrpcim_reg,
2980 rts_mgr_cbasin_cfg),
2981 &val64);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002982 if (status == VXGE_HW_OK) {
2983 val64 &= ~vpath_vector;
2984 status = vxge_hw_mgmt_reg_write(vdev->devh,
2985 vxge_hw_mgmt_reg_type_mrpcim,
2986 0,
2987 (ulong)offsetof(
2988 struct vxge_hw_mrpcim_reg,
2989 rts_mgr_cbasin_cfg),
2990 val64);
2991 }
2992
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002993 /* Remove the function 0 from promiscuous mode */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00002994 vxge_hw_mgmt_reg_write(vdev->devh,
2995 vxge_hw_mgmt_reg_type_mrpcim,
2996 0,
2997 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
2998 rxmac_authorize_all_addr),
2999 0);
3000
3001 vxge_hw_mgmt_reg_write(vdev->devh,
3002 vxge_hw_mgmt_reg_type_mrpcim,
3003 0,
3004 (ulong)offsetof(struct vxge_hw_mrpcim_reg,
3005 rxmac_authorize_all_vid),
3006 0);
3007
3008 smp_wmb();
3009 }
Jon Masone7935c92010-11-11 04:26:00 +00003010
3011 if (vdev->titan1)
3012 del_timer_sync(&vdev->vp_lockup_timer);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003013
3014 del_timer_sync(&vdev->vp_reset_timer);
3015
Jon Mason4d2a5b42010-11-11 04:25:54 +00003016 if (do_io)
3017 vxge_hw_device_wait_receive_idle(hldev);
3018
3019 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3020
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003021 /* Disable napi */
3022 if (vdev->config.intr_type != MSI_X)
3023 napi_disable(&vdev->napi);
3024 else {
3025 for (i = 0; i < vdev->no_of_vpath; i++)
3026 napi_disable(&vdev->vpaths[i].ring.napi);
3027 }
3028
3029 netif_carrier_off(vdev->ndev);
Joe Perches75f5e1c2010-07-27 11:47:03 +00003030 netdev_notice(vdev->ndev, "Link Down\n");
Jon Masond03848e2010-07-15 08:47:23 +00003031 netif_tx_stop_all_queues(vdev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003032
3033 /* Note that at this point xmit() is stopped by upper layer */
3034 if (do_io)
3035 vxge_hw_device_intr_disable(vdev->devh);
3036
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003037 vxge_rem_isr(vdev);
3038
3039 vxge_napi_del_all(vdev);
3040
3041 if (do_io)
3042 vxge_reset_all_vpaths(vdev);
3043
3044 vxge_close_vpaths(vdev, 0);
3045
3046 vxge_debug_entryexit(VXGE_TRACE,
3047 "%s: %s:%d Exiting...", dev->name, __func__, __LINE__);
3048
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003049 clear_bit(__VXGE_STATE_RESET_CARD, &vdev->state);
3050
3051 return 0;
3052}
3053
3054/**
3055 * vxge_close
3056 * @dev: device pointer.
3057 *
3058 * This is the stop entry point of the driver. It needs to undo exactly
3059 * whatever was done by the open entry point, thus it's usually referred to
3060 * as the close function.Among other things this function mainly stops the
3061 * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
3062 * Return value: '0' on success and an appropriate (-)ve integer as
3063 * defined in errno.h file on failure.
3064 */
Jon Mason528f7272010-12-10 14:02:56 +00003065static int vxge_close(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003066{
3067 do_vxge_close(dev, 1);
3068 return 0;
3069}
3070
3071/**
3072 * vxge_change_mtu
3073 * @dev: net device pointer.
3074 * @new_mtu :the new MTU size for the device.
3075 *
3076 * A driver entry point to change MTU size for the device. Before changing
3077 * the MTU the device must be stopped.
3078 */
3079static int vxge_change_mtu(struct net_device *dev, int new_mtu)
3080{
3081 struct vxgedev *vdev = netdev_priv(dev);
3082
3083 vxge_debug_entryexit(vdev->level_trace,
3084 "%s:%d", __func__, __LINE__);
3085 if ((new_mtu < VXGE_HW_MIN_MTU) || (new_mtu > VXGE_HW_MAX_MTU)) {
3086 vxge_debug_init(vdev->level_err,
3087 "%s: mtu size is invalid", dev->name);
3088 return -EPERM;
3089 }
3090
3091 /* check if device is down already */
3092 if (unlikely(!is_vxge_card_up(vdev))) {
3093 /* just store new value, will use later on open() */
3094 dev->mtu = new_mtu;
3095 vxge_debug_init(vdev->level_err,
3096 "%s", "device is down on MTU change");
3097 return 0;
3098 }
3099
3100 vxge_debug_init(vdev->level_trace,
3101 "trying to apply new MTU %d", new_mtu);
3102
3103 if (vxge_close(dev))
3104 return -EIO;
3105
3106 dev->mtu = new_mtu;
3107 vdev->mtu = new_mtu;
3108
3109 if (vxge_open(dev))
3110 return -EIO;
3111
3112 vxge_debug_init(vdev->level_trace,
3113 "%s: MTU changed to %d", vdev->ndev->name, new_mtu);
3114
3115 vxge_debug_entryexit(vdev->level_trace,
3116 "%s:%d Exiting...", __func__, __LINE__);
3117
3118 return 0;
3119}
3120
3121/**
Eric Dumazetdd57f972010-08-18 03:42:54 +00003122 * vxge_get_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003123 * @dev: pointer to the device structure
Eric Dumazetdd57f972010-08-18 03:42:54 +00003124 * @stats: pointer to struct rtnl_link_stats64
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003125 *
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003126 */
Eric Dumazetdd57f972010-08-18 03:42:54 +00003127static struct rtnl_link_stats64 *
3128vxge_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *net_stats)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003129{
Eric Dumazetdd57f972010-08-18 03:42:54 +00003130 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003131 int k;
3132
Eric Dumazetdd57f972010-08-18 03:42:54 +00003133 /* net_stats already zeroed by caller */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003134 for (k = 0; k < vdev->no_of_vpath; k++) {
stephen hemminger62ea0552011-06-20 10:35:07 +00003135 struct vxge_ring_stats *rxstats = &vdev->vpaths[k].ring.stats;
3136 struct vxge_fifo_stats *txstats = &vdev->vpaths[k].fifo.stats;
3137 unsigned int start;
3138 u64 packets, bytes, multicast;
3139
3140 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07003141 start = u64_stats_fetch_begin_irq(&rxstats->syncp);
stephen hemminger62ea0552011-06-20 10:35:07 +00003142
3143 packets = rxstats->rx_frms;
3144 multicast = rxstats->rx_mcast;
3145 bytes = rxstats->rx_bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07003146 } while (u64_stats_fetch_retry_irq(&rxstats->syncp, start));
stephen hemminger62ea0552011-06-20 10:35:07 +00003147
3148 net_stats->rx_packets += packets;
3149 net_stats->rx_bytes += bytes;
3150 net_stats->multicast += multicast;
3151
3152 net_stats->rx_errors += rxstats->rx_errors;
3153 net_stats->rx_dropped += rxstats->rx_dropped;
3154
3155 do {
Eric W. Biederman57a77442014-03-13 21:26:42 -07003156 start = u64_stats_fetch_begin_irq(&txstats->syncp);
stephen hemminger62ea0552011-06-20 10:35:07 +00003157
3158 packets = txstats->tx_frms;
3159 bytes = txstats->tx_bytes;
Eric W. Biederman57a77442014-03-13 21:26:42 -07003160 } while (u64_stats_fetch_retry_irq(&txstats->syncp, start));
stephen hemminger62ea0552011-06-20 10:35:07 +00003161
3162 net_stats->tx_packets += packets;
3163 net_stats->tx_bytes += bytes;
3164 net_stats->tx_errors += txstats->tx_errors;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003165 }
3166
3167 return net_stats;
3168}
3169
Jon Masoncd883a72011-04-08 11:11:21 +00003170static enum vxge_hw_status vxge_timestamp_config(struct __vxge_hw_device *devh)
Jon Masonb81b3732010-11-11 04:25:58 +00003171{
3172 enum vxge_hw_status status;
3173 u64 val64;
3174
3175 /* Timestamp is passed to the driver via the FCS, therefore we
3176 * must disable the FCS stripping by the adapter. Since this is
3177 * required for the driver to load (due to a hardware bug),
3178 * there is no need to do anything special here.
3179 */
Jon Masoncd883a72011-04-08 11:11:21 +00003180 val64 = VXGE_HW_XMAC_TIMESTAMP_EN |
3181 VXGE_HW_XMAC_TIMESTAMP_USE_LINK_ID(0) |
3182 VXGE_HW_XMAC_TIMESTAMP_INTERVAL(0);
Jon Masonb81b3732010-11-11 04:25:58 +00003183
Jon Masoncd883a72011-04-08 11:11:21 +00003184 status = vxge_hw_mgmt_reg_write(devh,
Jon Masonb81b3732010-11-11 04:25:58 +00003185 vxge_hw_mgmt_reg_type_mrpcim,
3186 0,
3187 offsetof(struct vxge_hw_mrpcim_reg,
3188 xmac_timestamp),
3189 val64);
Jon Masoncd883a72011-04-08 11:11:21 +00003190 vxge_hw_device_flush_io(devh);
3191 devh->config.hwts_en = VXGE_HW_HWTS_ENABLE;
Jon Masonb81b3732010-11-11 04:25:58 +00003192 return status;
3193}
3194
Ben Hutchings450e55e2013-11-18 23:16:23 +00003195static int vxge_hwtstamp_set(struct vxgedev *vdev, void __user *data)
Jon Masonb81b3732010-11-11 04:25:58 +00003196{
3197 struct hwtstamp_config config;
Jon Masonb81b3732010-11-11 04:25:58 +00003198 int i;
3199
3200 if (copy_from_user(&config, data, sizeof(config)))
3201 return -EFAULT;
3202
3203 /* reserved for future extensions */
3204 if (config.flags)
3205 return -EINVAL;
3206
3207 /* Transmit HW Timestamp not supported */
3208 switch (config.tx_type) {
3209 case HWTSTAMP_TX_OFF:
3210 break;
3211 case HWTSTAMP_TX_ON:
3212 default:
3213 return -ERANGE;
3214 }
3215
3216 switch (config.rx_filter) {
3217 case HWTSTAMP_FILTER_NONE:
Jon Masonb81b3732010-11-11 04:25:58 +00003218 vdev->rx_hwts = 0;
3219 config.rx_filter = HWTSTAMP_FILTER_NONE;
3220 break;
3221
3222 case HWTSTAMP_FILTER_ALL:
3223 case HWTSTAMP_FILTER_SOME:
3224 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
3225 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
3226 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
3227 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
3228 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
3229 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
3230 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
3231 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
3232 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
3233 case HWTSTAMP_FILTER_PTP_V2_EVENT:
3234 case HWTSTAMP_FILTER_PTP_V2_SYNC:
3235 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Jon Masoncd883a72011-04-08 11:11:21 +00003236 if (vdev->devh->config.hwts_en != VXGE_HW_HWTS_ENABLE)
Jon Masonb81b3732010-11-11 04:25:58 +00003237 return -EFAULT;
3238
3239 vdev->rx_hwts = 1;
3240 config.rx_filter = HWTSTAMP_FILTER_ALL;
3241 break;
3242
3243 default:
3244 return -ERANGE;
3245 }
3246
3247 for (i = 0; i < vdev->no_of_vpath; i++)
3248 vdev->vpaths[i].ring.rx_hwts = vdev->rx_hwts;
3249
3250 if (copy_to_user(data, &config, sizeof(config)))
3251 return -EFAULT;
3252
3253 return 0;
3254}
3255
Ben Hutchings450e55e2013-11-18 23:16:23 +00003256static int vxge_hwtstamp_get(struct vxgedev *vdev, void __user *data)
3257{
3258 struct hwtstamp_config config;
3259
3260 config.flags = 0;
3261 config.tx_type = HWTSTAMP_TX_OFF;
3262 config.rx_filter = (vdev->rx_hwts ?
3263 HWTSTAMP_FILTER_ALL : HWTSTAMP_FILTER_NONE);
3264
3265 if (copy_to_user(data, &config, sizeof(config)))
3266 return -EFAULT;
3267
3268 return 0;
3269}
3270
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003271/**
3272 * vxge_ioctl
3273 * @dev: Device pointer.
3274 * @ifr: An IOCTL specific structure, that can contain a pointer to
3275 * a proprietary structure used to pass information to the driver.
3276 * @cmd: This is used to distinguish between the different commands that
3277 * can be passed to the IOCTL functions.
3278 *
3279 * Entry point for the Ioctl.
3280 */
3281static int vxge_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3282{
Jon Masonb81b3732010-11-11 04:25:58 +00003283 struct vxgedev *vdev = netdev_priv(dev);
Jon Masonb81b3732010-11-11 04:25:58 +00003284
3285 switch (cmd) {
3286 case SIOCSHWTSTAMP:
Ben Hutchings450e55e2013-11-18 23:16:23 +00003287 return vxge_hwtstamp_set(vdev, rq->ifr_data);
3288 case SIOCGHWTSTAMP:
3289 return vxge_hwtstamp_get(vdev, rq->ifr_data);
Jon Masonb81b3732010-11-11 04:25:58 +00003290 default:
3291 return -EOPNOTSUPP;
3292 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003293}
3294
3295/**
3296 * vxge_tx_watchdog
3297 * @dev: pointer to net device structure
3298 *
3299 * Watchdog for transmit side.
3300 * This function is triggered if the Tx Queue is stopped
3301 * for a pre-defined amount of time when the Interface is still up.
3302 */
Jon Mason2e41f642010-12-10 14:02:59 +00003303static void vxge_tx_watchdog(struct net_device *dev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003304{
3305 struct vxgedev *vdev;
3306
3307 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3308
Joe Perches5f54ceb2010-11-15 11:12:30 +00003309 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003310
3311 vdev->cric_err_event = VXGE_HW_EVENT_RESET_START;
3312
Jon Mason2e41f642010-12-10 14:02:59 +00003313 schedule_work(&vdev->reset_task);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003314 vxge_debug_entryexit(VXGE_TRACE,
3315 "%s:%d Exiting...", __func__, __LINE__);
3316}
3317
3318/**
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003319 * vxge_vlan_rx_add_vid
3320 * @dev: net device pointer.
Patrick McHardy80d5c362013-04-19 02:04:28 +00003321 * @proto: vlan protocol
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003322 * @vid: vid
3323 *
3324 * Add the vlan id to the devices vlan id table
3325 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003326static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00003327vxge_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003328{
Jiri Pirko53515732011-07-20 04:54:40 +00003329 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003330 struct vxge_vpath *vpath;
3331 int vp_id;
3332
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003333 /* Add these vlan to the vid table */
3334 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3335 vpath = &vdev->vpaths[vp_id];
3336 if (!vpath->is_open)
3337 continue;
3338 vxge_hw_vpath_vid_add(vpath->handle, vid);
3339 }
Jiri Pirko53515732011-07-20 04:54:40 +00003340 set_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003341 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003342}
3343
3344/**
Patrick McHardy80d5c362013-04-19 02:04:28 +00003345 * vxge_vlan_rx_kill_vid
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003346 * @dev: net device pointer.
Patrick McHardy80d5c362013-04-19 02:04:28 +00003347 * @proto: vlan protocol
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003348 * @vid: vid
3349 *
3350 * Remove the vlan id from the device's vlan id table
3351 */
Jiri Pirko8e586132011-12-08 19:52:37 -05003352static int
Patrick McHardy80d5c362013-04-19 02:04:28 +00003353vxge_vlan_rx_kill_vid(struct net_device *dev, __be16 proto, u16 vid)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003354{
Jiri Pirko53515732011-07-20 04:54:40 +00003355 struct vxgedev *vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003356 struct vxge_vpath *vpath;
3357 int vp_id;
3358
3359 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
3360
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003361 /* Delete this vlan from the vid table */
3362 for (vp_id = 0; vp_id < vdev->no_of_vpath; vp_id++) {
3363 vpath = &vdev->vpaths[vp_id];
3364 if (!vpath->is_open)
3365 continue;
3366 vxge_hw_vpath_vid_delete(vpath->handle, vid);
3367 }
3368 vxge_debug_entryexit(VXGE_TRACE,
3369 "%s:%d Exiting...", __func__, __LINE__);
Jiri Pirko53515732011-07-20 04:54:40 +00003370 clear_bit(vid, vdev->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003371 return 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003372}
3373
3374static const struct net_device_ops vxge_netdev_ops = {
3375 .ndo_open = vxge_open,
3376 .ndo_stop = vxge_close,
Eric Dumazetdd57f972010-08-18 03:42:54 +00003377 .ndo_get_stats64 = vxge_get_stats64,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003378 .ndo_start_xmit = vxge_xmit,
3379 .ndo_validate_addr = eth_validate_addr,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00003380 .ndo_set_rx_mode = vxge_set_multicast,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003381 .ndo_do_ioctl = vxge_ioctl,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003382 .ndo_set_mac_address = vxge_set_mac_addr,
3383 .ndo_change_mtu = vxge_change_mtu,
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003384 .ndo_fix_features = vxge_fix_features,
3385 .ndo_set_features = vxge_set_features,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003386 .ndo_vlan_rx_kill_vid = vxge_vlan_rx_kill_vid,
3387 .ndo_vlan_rx_add_vid = vxge_vlan_rx_add_vid,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003388 .ndo_tx_timeout = vxge_tx_watchdog,
3389#ifdef CONFIG_NET_POLL_CONTROLLER
3390 .ndo_poll_controller = vxge_netpoll,
3391#endif
3392};
3393
Bill Pemberton3a036ce2012-12-03 09:23:18 -05003394static int vxge_device_register(struct __vxge_hw_device *hldev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003395 struct vxge_config *config, int high_dma,
3396 int no_of_vpath, struct vxgedev **vdev_out)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003397{
3398 struct net_device *ndev;
3399 enum vxge_hw_status status = VXGE_HW_OK;
3400 struct vxgedev *vdev;
Jon Mason98f45da2010-07-15 08:47:25 +00003401 int ret = 0, no_of_queue = 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003402 u64 stat;
3403
3404 *vdev_out = NULL;
Jon Masond03848e2010-07-15 08:47:23 +00003405 if (config->tx_steering_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003406 no_of_queue = no_of_vpath;
3407
3408 ndev = alloc_etherdev_mq(sizeof(struct vxgedev),
3409 no_of_queue);
3410 if (ndev == NULL) {
3411 vxge_debug_init(
3412 vxge_hw_device_trace_level_get(hldev),
3413 "%s : device allocation failed", __func__);
3414 ret = -ENODEV;
3415 goto _out0;
3416 }
3417
3418 vxge_debug_entryexit(
3419 vxge_hw_device_trace_level_get(hldev),
3420 "%s: %s:%d Entering...",
3421 ndev->name, __func__, __LINE__);
3422
3423 vdev = netdev_priv(ndev);
3424 memset(vdev, 0, sizeof(struct vxgedev));
3425
3426 vdev->ndev = ndev;
3427 vdev->devh = hldev;
3428 vdev->pdev = hldev->pdev;
3429 memcpy(&vdev->config, config, sizeof(struct vxge_config));
Jon Masonb81b3732010-11-11 04:25:58 +00003430 vdev->rx_hwts = 0;
Sergei Shtylyovff938e42011-02-28 11:57:33 -08003431 vdev->titan1 = (vdev->pdev->revision == VXGE_HW_TITAN1_PCI_REVISION);
Jon Masone7935c92010-11-11 04:26:00 +00003432
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003433 SET_NETDEV_DEV(ndev, &vdev->pdev->dev);
3434
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003435 ndev->hw_features = NETIF_F_RXCSUM | NETIF_F_SG |
3436 NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
3437 NETIF_F_TSO | NETIF_F_TSO6 |
Patrick McHardyf6469682013-04-19 02:04:27 +00003438 NETIF_F_HW_VLAN_CTAG_TX;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003439 if (vdev->config.rth_steering != NO_STEERING)
3440 ndev->hw_features |= NETIF_F_RXHASH;
3441
3442 ndev->features |= ndev->hw_features |
Patrick McHardyf6469682013-04-19 02:04:27 +00003443 NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_FILTER;
Michał Mirosławfeb990d2011-04-18 13:31:21 +00003444
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003445
3446 ndev->netdev_ops = &vxge_netdev_ops;
3447
3448 ndev->watchdog_timeo = VXGE_LL_WATCH_DOG_TIMEOUT;
Jon Mason2e41f642010-12-10 14:02:59 +00003449 INIT_WORK(&vdev->reset_task, vxge_reset);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003450
stephen hemminger42821a52010-10-21 07:50:53 +00003451 vxge_initialize_ethtool_ops(ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003452
3453 /* Allocate memory for vpath */
3454 vdev->vpaths = kzalloc((sizeof(struct vxge_vpath)) *
3455 no_of_vpath, GFP_KERNEL);
3456 if (!vdev->vpaths) {
3457 vxge_debug_init(VXGE_ERR,
3458 "%s: vpath memory allocation failed",
3459 vdev->ndev->name);
Jon Mason6cca2002011-01-18 15:02:19 +00003460 ret = -ENOMEM;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003461 goto _out1;
3462 }
3463
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003464 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
Masanari Iida278cee02013-06-01 01:30:56 +09003465 "%s : checksumming enabled", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003466
3467 if (high_dma) {
3468 ndev->features |= NETIF_F_HIGHDMA;
3469 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3470 "%s : using High DMA", __func__);
3471 }
3472
Jon Mason6cca2002011-01-18 15:02:19 +00003473 ret = register_netdev(ndev);
3474 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003475 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3476 "%s: %s : device registration failed!",
3477 ndev->name, __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003478 goto _out2;
3479 }
3480
3481 /* Set the factory defined MAC address initially */
3482 ndev->addr_len = ETH_ALEN;
3483
3484 /* Make Link state as off at this point, when the Link change
3485 * interrupt comes the state will be automatically changed to
3486 * the right state.
3487 */
3488 netif_carrier_off(ndev);
3489
3490 vxge_debug_init(vxge_hw_device_trace_level_get(hldev),
3491 "%s: Ethernet device registered",
3492 ndev->name);
3493
Jon Masone8ac1752010-11-11 04:25:57 +00003494 hldev->ndev = ndev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003495 *vdev_out = vdev;
3496
3497 /* Resetting the Device stats */
3498 status = vxge_hw_mrpcim_stats_access(
3499 hldev,
3500 VXGE_HW_STATS_OP_CLEAR_ALL_STATS,
3501 0,
3502 0,
3503 &stat);
3504
3505 if (status == VXGE_HW_ERR_PRIVILAGED_OPEARATION)
3506 vxge_debug_init(
3507 vxge_hw_device_trace_level_get(hldev),
3508 "%s: device stats clear returns"
3509 "VXGE_HW_ERR_PRIVILAGED_OPEARATION", ndev->name);
3510
3511 vxge_debug_entryexit(vxge_hw_device_trace_level_get(hldev),
3512 "%s: %s:%d Exiting...",
3513 ndev->name, __func__, __LINE__);
3514
3515 return ret;
3516_out2:
3517 kfree(vdev->vpaths);
3518_out1:
3519 free_netdev(ndev);
3520_out0:
3521 return ret;
3522}
3523
3524/*
3525 * vxge_device_unregister
3526 *
3527 * This function will unregister and free network device
3528 */
Jon Mason2c913082010-11-11 04:26:03 +00003529static void vxge_device_unregister(struct __vxge_hw_device *hldev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003530{
3531 struct vxgedev *vdev;
3532 struct net_device *dev;
3533 char buf[IFNAMSIZ];
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003534
3535 dev = hldev->ndev;
3536 vdev = netdev_priv(dev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003537
Jon Mason2c913082010-11-11 04:26:03 +00003538 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d", vdev->ndev->name,
3539 __func__, __LINE__);
3540
Jon Masonead5d232010-11-29 18:02:46 +00003541 strncpy(buf, dev->name, IFNAMSIZ);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003542
Tejun Heo43829732012-08-20 14:51:24 -07003543 flush_work(&vdev->reset_task);
Tejun Heoba27d852010-12-15 04:03:29 +00003544
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003545 /* in 2.6 will call stop() if device is up */
3546 unregister_netdev(dev);
3547
Jon Mason6cca2002011-01-18 15:02:19 +00003548 kfree(vdev->vpaths);
3549
3550 /* we are safe to free it now */
3551 free_netdev(dev);
3552
Jon Mason2c913082010-11-11 04:26:03 +00003553 vxge_debug_init(vdev->level_trace, "%s: ethernet device unregistered",
3554 buf);
3555 vxge_debug_entryexit(vdev->level_trace, "%s: %s:%d Exiting...", buf,
3556 __func__, __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003557}
3558
3559/*
3560 * vxge_callback_crit_err
3561 *
3562 * This function is called by the alarm handler in interrupt context.
3563 * Driver must analyze it based on the event type.
3564 */
3565static void
3566vxge_callback_crit_err(struct __vxge_hw_device *hldev,
3567 enum vxge_hw_event type, u64 vp_id)
3568{
3569 struct net_device *dev = hldev->ndev;
Joe Perches5f54ceb2010-11-15 11:12:30 +00003570 struct vxgedev *vdev = netdev_priv(dev);
Jon Mason98f45da2010-07-15 08:47:25 +00003571 struct vxge_vpath *vpath = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003572 int vpath_idx;
3573
3574 vxge_debug_entryexit(vdev->level_trace,
3575 "%s: %s:%d", vdev->ndev->name, __func__, __LINE__);
3576
3577 /* Note: This event type should be used for device wide
3578 * indications only - Serious errors, Slot freeze and critical errors
3579 */
3580 vdev->cric_err_event = type;
3581
Jon Mason98f45da2010-07-15 08:47:25 +00003582 for (vpath_idx = 0; vpath_idx < vdev->no_of_vpath; vpath_idx++) {
3583 vpath = &vdev->vpaths[vpath_idx];
3584 if (vpath->device_id == vp_id)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003585 break;
Jon Mason98f45da2010-07-15 08:47:25 +00003586 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003587
3588 if (!test_bit(__VXGE_STATE_RESET_CARD, &vdev->state)) {
3589 if (type == VXGE_HW_EVENT_SLOT_FREEZE) {
3590 vxge_debug_init(VXGE_ERR,
3591 "%s: Slot is frozen", vdev->ndev->name);
3592 } else if (type == VXGE_HW_EVENT_SERR) {
3593 vxge_debug_init(VXGE_ERR,
3594 "%s: Encountered Serious Error",
3595 vdev->ndev->name);
3596 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR)
3597 vxge_debug_init(VXGE_ERR,
3598 "%s: Encountered Critical Error",
3599 vdev->ndev->name);
3600 }
3601
3602 if ((type == VXGE_HW_EVENT_SERR) ||
3603 (type == VXGE_HW_EVENT_SLOT_FREEZE)) {
3604 if (unlikely(vdev->exec_mode))
3605 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3606 } else if (type == VXGE_HW_EVENT_CRITICAL_ERR) {
3607 vxge_hw_device_mask_all(hldev);
3608 if (unlikely(vdev->exec_mode))
3609 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3610 } else if ((type == VXGE_HW_EVENT_FIFO_ERR) ||
3611 (type == VXGE_HW_EVENT_VPATH_ERR)) {
3612
3613 if (unlikely(vdev->exec_mode))
3614 clear_bit(__VXGE_STATE_CARD_UP, &vdev->state);
3615 else {
3616 /* check if this vpath is already set for reset */
3617 if (!test_and_set_bit(vpath_idx, &vdev->vp_reset)) {
3618
3619 /* disable interrupts for this vpath */
3620 vxge_vpath_intr_disable(vdev, vpath_idx);
3621
3622 /* stop the queue for this vpath */
Jon Mason98f45da2010-07-15 08:47:25 +00003623 netif_tx_stop_queue(vpath->fifo.txq);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003624 }
3625 }
3626 }
3627
3628 vxge_debug_entryexit(vdev->level_trace,
3629 "%s: %s:%d Exiting...",
3630 vdev->ndev->name, __func__, __LINE__);
3631}
3632
3633static void verify_bandwidth(void)
3634{
3635 int i, band_width, total = 0, equal_priority = 0;
3636
3637 /* 1. If user enters 0 for some fifo, give equal priority to all */
3638 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3639 if (bw_percentage[i] == 0) {
3640 equal_priority = 1;
3641 break;
3642 }
3643 }
3644
3645 if (!equal_priority) {
3646 /* 2. If sum exceeds 100, give equal priority to all */
3647 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3648 if (bw_percentage[i] == 0xFF)
3649 break;
3650
3651 total += bw_percentage[i];
3652 if (total > VXGE_HW_VPATH_BANDWIDTH_MAX) {
3653 equal_priority = 1;
3654 break;
3655 }
3656 }
3657 }
3658
3659 if (!equal_priority) {
3660 /* Is all the bandwidth consumed? */
3661 if (total < VXGE_HW_VPATH_BANDWIDTH_MAX) {
3662 if (i < VXGE_HW_MAX_VIRTUAL_PATHS) {
3663 /* Split rest of bw equally among next VPs*/
3664 band_width =
3665 (VXGE_HW_VPATH_BANDWIDTH_MAX - total) /
3666 (VXGE_HW_MAX_VIRTUAL_PATHS - i);
3667 if (band_width < 2) /* min of 2% */
3668 equal_priority = 1;
3669 else {
3670 for (; i < VXGE_HW_MAX_VIRTUAL_PATHS;
3671 i++)
3672 bw_percentage[i] =
3673 band_width;
3674 }
3675 }
3676 } else if (i < VXGE_HW_MAX_VIRTUAL_PATHS)
3677 equal_priority = 1;
3678 }
3679
3680 if (equal_priority) {
3681 vxge_debug_init(VXGE_ERR,
3682 "%s: Assigning equal bandwidth to all the vpaths",
3683 VXGE_DRIVER_NAME);
3684 bw_percentage[0] = VXGE_HW_VPATH_BANDWIDTH_MAX /
3685 VXGE_HW_MAX_VIRTUAL_PATHS;
3686 for (i = 1; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3687 bw_percentage[i] = bw_percentage[0];
3688 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003689}
3690
3691/*
3692 * Vpath configuration
3693 */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003694static int vxge_config_vpaths(struct vxge_hw_device_config *device_config,
3695 u64 vpath_mask, struct vxge_config *config_param)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003696{
3697 int i, no_of_vpaths = 0, default_no_vpath = 0, temp;
3698 u32 txdl_size, txdl_per_memblock;
3699
3700 temp = driver_config->vpath_per_dev;
3701 if ((driver_config->vpath_per_dev == VXGE_USE_DEFAULT) &&
3702 (max_config_dev == VXGE_MAX_CONFIG_DEV)) {
3703 /* No more CPU. Return vpath number as zero.*/
3704 if (driver_config->g_no_cpus == -1)
3705 return 0;
3706
3707 if (!driver_config->g_no_cpus)
Yuval Mintz9cbb5762012-07-01 03:18:52 +00003708 driver_config->g_no_cpus =
3709 netif_get_num_default_rss_queues();
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003710
3711 driver_config->vpath_per_dev = driver_config->g_no_cpus >> 1;
3712 if (!driver_config->vpath_per_dev)
3713 driver_config->vpath_per_dev = 1;
3714
3715 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3716 if (!vxge_bVALn(vpath_mask, i, 1))
3717 continue;
3718 else
3719 default_no_vpath++;
3720 if (default_no_vpath < driver_config->vpath_per_dev)
3721 driver_config->vpath_per_dev = default_no_vpath;
3722
3723 driver_config->g_no_cpus = driver_config->g_no_cpus -
3724 (driver_config->vpath_per_dev * 2);
3725 if (driver_config->g_no_cpus <= 0)
3726 driver_config->g_no_cpus = -1;
3727 }
3728
3729 if (driver_config->vpath_per_dev == 1) {
3730 vxge_debug_ll_config(VXGE_TRACE,
3731 "%s: Disable tx and rx steering, "
3732 "as single vpath is configured", VXGE_DRIVER_NAME);
3733 config_param->rth_steering = NO_STEERING;
3734 config_param->tx_steering_type = NO_STEERING;
3735 device_config->rth_en = 0;
3736 }
3737
3738 /* configure bandwidth */
3739 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++)
3740 device_config->vp_config[i].min_bandwidth = bw_percentage[i];
3741
3742 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
3743 device_config->vp_config[i].vp_id = i;
3744 device_config->vp_config[i].mtu = VXGE_HW_DEFAULT_MTU;
3745 if (no_of_vpaths < driver_config->vpath_per_dev) {
3746 if (!vxge_bVALn(vpath_mask, i, 1)) {
3747 vxge_debug_ll_config(VXGE_TRACE,
3748 "%s: vpath: %d is not available",
3749 VXGE_DRIVER_NAME, i);
3750 continue;
3751 } else {
3752 vxge_debug_ll_config(VXGE_TRACE,
3753 "%s: vpath: %d available",
3754 VXGE_DRIVER_NAME, i);
3755 no_of_vpaths++;
3756 }
3757 } else {
3758 vxge_debug_ll_config(VXGE_TRACE,
3759 "%s: vpath: %d is not configured, "
3760 "max_config_vpath exceeded",
3761 VXGE_DRIVER_NAME, i);
3762 break;
3763 }
3764
3765 /* Configure Tx fifo's */
3766 device_config->vp_config[i].fifo.enable =
3767 VXGE_HW_FIFO_ENABLE;
3768 device_config->vp_config[i].fifo.max_frags =
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003769 MAX_SKB_FRAGS + 1;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003770 device_config->vp_config[i].fifo.memblock_size =
3771 VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE;
3772
Sreenivasa Honnur5beefb42009-10-28 02:46:54 -07003773 txdl_size = device_config->vp_config[i].fifo.max_frags *
3774 sizeof(struct vxge_hw_fifo_txd);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003775 txdl_per_memblock = VXGE_HW_MIN_FIFO_MEMBLOCK_SIZE / txdl_size;
3776
3777 device_config->vp_config[i].fifo.fifo_blocks =
3778 ((VXGE_DEF_FIFO_LENGTH - 1) / txdl_per_memblock) + 1;
3779
3780 device_config->vp_config[i].fifo.intr =
3781 VXGE_HW_FIFO_QUEUE_INTR_DISABLE;
3782
3783 /* Configure tti properties */
3784 device_config->vp_config[i].tti.intr_enable =
3785 VXGE_HW_TIM_INTR_ENABLE;
3786
3787 device_config->vp_config[i].tti.btimer_val =
3788 (VXGE_TTI_BTIMER_VAL * 1000) / 272;
3789
3790 device_config->vp_config[i].tti.timer_ac_en =
3791 VXGE_HW_TIM_TIMER_AC_ENABLE;
3792
Jon Mason528f7272010-12-10 14:02:56 +00003793 /* For msi-x with napi (each vector has a handler of its own) -
3794 * Set CI to OFF for all vpaths
3795 */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003796 device_config->vp_config[i].tti.timer_ci_en =
3797 VXGE_HW_TIM_TIMER_CI_DISABLE;
3798
3799 device_config->vp_config[i].tti.timer_ri_en =
3800 VXGE_HW_TIM_TIMER_RI_DISABLE;
3801
3802 device_config->vp_config[i].tti.util_sel =
3803 VXGE_HW_TIM_UTIL_SEL_LEGACY_TX_NET_UTIL;
3804
3805 device_config->vp_config[i].tti.ltimer_val =
3806 (VXGE_TTI_LTIMER_VAL * 1000) / 272;
3807
3808 device_config->vp_config[i].tti.rtimer_val =
3809 (VXGE_TTI_RTIMER_VAL * 1000) / 272;
3810
3811 device_config->vp_config[i].tti.urange_a = TTI_TX_URANGE_A;
3812 device_config->vp_config[i].tti.urange_b = TTI_TX_URANGE_B;
3813 device_config->vp_config[i].tti.urange_c = TTI_TX_URANGE_C;
3814 device_config->vp_config[i].tti.uec_a = TTI_TX_UFC_A;
3815 device_config->vp_config[i].tti.uec_b = TTI_TX_UFC_B;
3816 device_config->vp_config[i].tti.uec_c = TTI_TX_UFC_C;
3817 device_config->vp_config[i].tti.uec_d = TTI_TX_UFC_D;
3818
3819 /* Configure Rx rings */
3820 device_config->vp_config[i].ring.enable =
3821 VXGE_HW_RING_ENABLE;
3822
3823 device_config->vp_config[i].ring.ring_blocks =
3824 VXGE_HW_DEF_RING_BLOCKS;
Jon Mason528f7272010-12-10 14:02:56 +00003825
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003826 device_config->vp_config[i].ring.buffer_mode =
3827 VXGE_HW_RING_RXD_BUFFER_MODE_1;
Jon Mason528f7272010-12-10 14:02:56 +00003828
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003829 device_config->vp_config[i].ring.rxds_limit =
3830 VXGE_HW_DEF_RING_RXDS_LIMIT;
Jon Mason528f7272010-12-10 14:02:56 +00003831
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003832 device_config->vp_config[i].ring.scatter_mode =
3833 VXGE_HW_RING_SCATTER_MODE_A;
3834
3835 /* Configure rti properties */
3836 device_config->vp_config[i].rti.intr_enable =
3837 VXGE_HW_TIM_INTR_ENABLE;
3838
3839 device_config->vp_config[i].rti.btimer_val =
3840 (VXGE_RTI_BTIMER_VAL * 1000)/272;
3841
3842 device_config->vp_config[i].rti.timer_ac_en =
3843 VXGE_HW_TIM_TIMER_AC_ENABLE;
3844
3845 device_config->vp_config[i].rti.timer_ci_en =
3846 VXGE_HW_TIM_TIMER_CI_DISABLE;
3847
3848 device_config->vp_config[i].rti.timer_ri_en =
3849 VXGE_HW_TIM_TIMER_RI_DISABLE;
3850
3851 device_config->vp_config[i].rti.util_sel =
3852 VXGE_HW_TIM_UTIL_SEL_LEGACY_RX_NET_UTIL;
3853
3854 device_config->vp_config[i].rti.urange_a =
3855 RTI_RX_URANGE_A;
3856 device_config->vp_config[i].rti.urange_b =
3857 RTI_RX_URANGE_B;
3858 device_config->vp_config[i].rti.urange_c =
3859 RTI_RX_URANGE_C;
3860 device_config->vp_config[i].rti.uec_a = RTI_RX_UFC_A;
3861 device_config->vp_config[i].rti.uec_b = RTI_RX_UFC_B;
3862 device_config->vp_config[i].rti.uec_c = RTI_RX_UFC_C;
3863 device_config->vp_config[i].rti.uec_d = RTI_RX_UFC_D;
3864
3865 device_config->vp_config[i].rti.rtimer_val =
3866 (VXGE_RTI_RTIMER_VAL * 1000) / 272;
3867
3868 device_config->vp_config[i].rti.ltimer_val =
3869 (VXGE_RTI_LTIMER_VAL * 1000) / 272;
3870
3871 device_config->vp_config[i].rpa_strip_vlan_tag =
3872 vlan_tag_strip;
3873 }
3874
3875 driver_config->vpath_per_dev = temp;
3876 return no_of_vpaths;
3877}
3878
3879/* initialize device configuratrions */
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +00003880static void vxge_device_config_init(struct vxge_hw_device_config *device_config,
3881 int *intr_type)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003882{
3883 /* Used for CQRQ/SRQ. */
3884 device_config->dma_blockpool_initial =
3885 VXGE_HW_INITIAL_DMA_BLOCK_POOL_SIZE;
3886
3887 device_config->dma_blockpool_max =
3888 VXGE_HW_MAX_DMA_BLOCK_POOL_SIZE;
3889
3890 if (max_mac_vpath > VXGE_MAX_MAC_ADDR_COUNT)
3891 max_mac_vpath = VXGE_MAX_MAC_ADDR_COUNT;
3892
3893#ifndef CONFIG_PCI_MSI
3894 vxge_debug_init(VXGE_ERR,
3895 "%s: This Kernel does not support "
3896 "MSI-X. Defaulting to INTA", VXGE_DRIVER_NAME);
3897 *intr_type = INTA;
3898#endif
3899
3900 /* Configure whether MSI-X or IRQL. */
3901 switch (*intr_type) {
3902 case INTA:
3903 device_config->intr_mode = VXGE_HW_INTR_MODE_IRQLINE;
3904 break;
3905
3906 case MSI_X:
Jon Mason16fded72011-01-18 15:02:21 +00003907 device_config->intr_mode = VXGE_HW_INTR_MODE_MSIX_ONE_SHOT;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003908 break;
3909 }
Jon Mason528f7272010-12-10 14:02:56 +00003910
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003911 /* Timer period between device poll */
3912 device_config->device_poll_millis = VXGE_TIMER_DELAY;
3913
3914 /* Configure mac based steering. */
3915 device_config->rts_mac_en = addr_learn_en;
3916
3917 /* Configure Vpaths */
3918 device_config->rth_it_type = VXGE_HW_RTH_IT_TYPE_MULTI_IT;
3919
3920 vxge_debug_ll_config(VXGE_TRACE, "%s : Device Config Params ",
3921 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003922 vxge_debug_ll_config(VXGE_TRACE, "intr_mode : %d",
3923 device_config->intr_mode);
3924 vxge_debug_ll_config(VXGE_TRACE, "device_poll_millis : %d",
3925 device_config->device_poll_millis);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003926 vxge_debug_ll_config(VXGE_TRACE, "rth_en : %d",
3927 device_config->rth_en);
3928 vxge_debug_ll_config(VXGE_TRACE, "rth_it_type : %d",
3929 device_config->rth_it_type);
3930}
3931
Bill Pemberton3a036ce2012-12-03 09:23:18 -05003932static void vxge_print_parm(struct vxgedev *vdev, u64 vpath_mask)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00003933{
3934 int i;
3935
3936 vxge_debug_init(VXGE_TRACE,
3937 "%s: %d Vpath(s) opened",
3938 vdev->ndev->name, vdev->no_of_vpath);
3939
3940 switch (vdev->config.intr_type) {
3941 case INTA:
3942 vxge_debug_init(VXGE_TRACE,
3943 "%s: Interrupt type INTA", vdev->ndev->name);
3944 break;
3945
3946 case MSI_X:
3947 vxge_debug_init(VXGE_TRACE,
3948 "%s: Interrupt type MSI-X", vdev->ndev->name);
3949 break;
3950 }
3951
3952 if (vdev->config.rth_steering) {
3953 vxge_debug_init(VXGE_TRACE,
3954 "%s: RTH steering enabled for TCP_IPV4",
3955 vdev->ndev->name);
3956 } else {
3957 vxge_debug_init(VXGE_TRACE,
3958 "%s: RTH steering disabled", vdev->ndev->name);
3959 }
3960
3961 switch (vdev->config.tx_steering_type) {
3962 case NO_STEERING:
3963 vxge_debug_init(VXGE_TRACE,
3964 "%s: Tx steering disabled", vdev->ndev->name);
3965 break;
3966 case TX_PRIORITY_STEERING:
3967 vxge_debug_init(VXGE_TRACE,
3968 "%s: Unsupported tx steering option",
3969 vdev->ndev->name);
3970 vxge_debug_init(VXGE_TRACE,
3971 "%s: Tx steering disabled", vdev->ndev->name);
3972 vdev->config.tx_steering_type = 0;
3973 break;
3974 case TX_VLAN_STEERING:
3975 vxge_debug_init(VXGE_TRACE,
3976 "%s: Unsupported tx steering option",
3977 vdev->ndev->name);
3978 vxge_debug_init(VXGE_TRACE,
3979 "%s: Tx steering disabled", vdev->ndev->name);
3980 vdev->config.tx_steering_type = 0;
3981 break;
3982 case TX_MULTIQ_STEERING:
3983 vxge_debug_init(VXGE_TRACE,
3984 "%s: Tx multiqueue steering enabled",
3985 vdev->ndev->name);
3986 break;
3987 case TX_PORT_STEERING:
3988 vxge_debug_init(VXGE_TRACE,
3989 "%s: Tx port steering enabled",
3990 vdev->ndev->name);
3991 break;
3992 default:
3993 vxge_debug_init(VXGE_ERR,
3994 "%s: Unsupported tx steering type",
3995 vdev->ndev->name);
3996 vxge_debug_init(VXGE_TRACE,
3997 "%s: Tx steering disabled", vdev->ndev->name);
3998 vdev->config.tx_steering_type = 0;
3999 }
4000
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004001 if (vdev->config.addr_learn_en)
4002 vxge_debug_init(VXGE_TRACE,
4003 "%s: MAC Address learning enabled", vdev->ndev->name);
4004
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004005 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4006 if (!vxge_bVALn(vpath_mask, i, 1))
4007 continue;
4008 vxge_debug_ll_config(VXGE_TRACE,
4009 "%s: MTU size - %d", 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].mtu);
4012 vxge_debug_init(VXGE_TRACE,
4013 "%s: VLAN tag stripping %s", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004014 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004015 config.vp_config[i].rpa_strip_vlan_tag
4016 ? "Enabled" : "Disabled");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004017 vxge_debug_ll_config(VXGE_TRACE,
4018 "%s: Max frags : %d", vdev->ndev->name,
Joe Perches64699332012-06-04 12:44:16 +00004019 ((vdev->devh))->
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004020 config.vp_config[i].fifo.max_frags);
4021 break;
4022 }
4023}
4024
4025#ifdef CONFIG_PM
4026/**
4027 * vxge_pm_suspend - vxge power management suspend entry point
4028 *
4029 */
4030static int vxge_pm_suspend(struct pci_dev *pdev, pm_message_t state)
4031{
4032 return -ENOSYS;
4033}
4034/**
4035 * vxge_pm_resume - vxge power management resume entry point
4036 *
4037 */
4038static int vxge_pm_resume(struct pci_dev *pdev)
4039{
4040 return -ENOSYS;
4041}
4042
4043#endif
4044
4045/**
4046 * vxge_io_error_detected - called when PCI error is detected
4047 * @pdev: Pointer to PCI device
4048 * @state: The current pci connection state
4049 *
4050 * This function is called after a PCI bus error affecting
4051 * this device has been detected.
4052 */
4053static pci_ers_result_t vxge_io_error_detected(struct pci_dev *pdev,
4054 pci_channel_state_t state)
4055{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004056 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004057 struct net_device *netdev = hldev->ndev;
4058
4059 netif_device_detach(netdev);
4060
Dean Nelsone33b9922009-07-31 09:14:03 +00004061 if (state == pci_channel_io_perm_failure)
4062 return PCI_ERS_RESULT_DISCONNECT;
4063
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004064 if (netif_running(netdev)) {
4065 /* Bring down the card, while avoiding PCI I/O */
4066 do_vxge_close(netdev, 0);
4067 }
4068
4069 pci_disable_device(pdev);
4070
4071 return PCI_ERS_RESULT_NEED_RESET;
4072}
4073
4074/**
4075 * vxge_io_slot_reset - called after the pci bus has been reset.
4076 * @pdev: Pointer to PCI device
4077 *
4078 * Restart the card from scratch, as if from a cold-boot.
4079 * At this point, the card has exprienced a hard reset,
4080 * followed by fixups by BIOS, and has its config space
4081 * set up identically to what it was at cold boot.
4082 */
4083static pci_ers_result_t vxge_io_slot_reset(struct pci_dev *pdev)
4084{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004085 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004086 struct net_device *netdev = hldev->ndev;
4087
4088 struct vxgedev *vdev = netdev_priv(netdev);
4089
4090 if (pci_enable_device(pdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004091 netdev_err(netdev, "Cannot re-enable device after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004092 return PCI_ERS_RESULT_DISCONNECT;
4093 }
4094
4095 pci_set_master(pdev);
Jon Mason528f7272010-12-10 14:02:56 +00004096 do_vxge_reset(vdev, VXGE_LL_FULL_RESET);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004097
4098 return PCI_ERS_RESULT_RECOVERED;
4099}
4100
4101/**
4102 * vxge_io_resume - called when traffic can start flowing again.
4103 * @pdev: Pointer to PCI device
4104 *
4105 * This callback is called when the error recovery driver tells
4106 * us that its OK to resume normal operation.
4107 */
4108static void vxge_io_resume(struct pci_dev *pdev)
4109{
Joe Perchesd8ee7072010-11-15 10:13:58 +00004110 struct __vxge_hw_device *hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004111 struct net_device *netdev = hldev->ndev;
4112
4113 if (netif_running(netdev)) {
4114 if (vxge_open(netdev)) {
Joe Perches75f5e1c2010-07-27 11:47:03 +00004115 netdev_err(netdev,
4116 "Can't bring device back up after reset\n");
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004117 return;
4118 }
4119 }
4120
4121 netif_device_attach(netdev);
4122}
4123
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004124static inline u32 vxge_get_num_vfs(u64 function_mode)
4125{
4126 u32 num_functions = 0;
4127
4128 switch (function_mode) {
4129 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4130 case VXGE_HW_FUNCTION_MODE_SRIOV_8:
4131 num_functions = 8;
4132 break;
4133 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4134 num_functions = 1;
4135 break;
4136 case VXGE_HW_FUNCTION_MODE_SRIOV:
4137 case VXGE_HW_FUNCTION_MODE_MRIOV:
4138 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_17:
4139 num_functions = 17;
4140 break;
4141 case VXGE_HW_FUNCTION_MODE_SRIOV_4:
4142 num_functions = 4;
4143 break;
4144 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION_2:
4145 num_functions = 2;
4146 break;
4147 case VXGE_HW_FUNCTION_MODE_MRIOV_8:
4148 num_functions = 8; /* TODO */
4149 break;
4150 }
4151 return num_functions;
4152}
4153
Jon Masone8ac1752010-11-11 04:25:57 +00004154int vxge_fw_upgrade(struct vxgedev *vdev, char *fw_name, int override)
4155{
4156 struct __vxge_hw_device *hldev = vdev->devh;
4157 u32 maj, min, bld, cmaj, cmin, cbld;
4158 enum vxge_hw_status status;
4159 const struct firmware *fw;
4160 int ret;
4161
4162 ret = request_firmware(&fw, fw_name, &vdev->pdev->dev);
4163 if (ret) {
4164 vxge_debug_init(VXGE_ERR, "%s: Firmware file '%s' not found",
4165 VXGE_DRIVER_NAME, fw_name);
4166 goto out;
4167 }
4168
4169 /* Load the new firmware onto the adapter */
4170 status = vxge_update_fw_image(hldev, fw->data, fw->size);
4171 if (status != VXGE_HW_OK) {
4172 vxge_debug_init(VXGE_ERR,
4173 "%s: FW image download to adapter failed '%s'.",
4174 VXGE_DRIVER_NAME, fw_name);
4175 ret = -EIO;
4176 goto out;
4177 }
4178
4179 /* Read the version of the new firmware */
4180 status = vxge_hw_upgrade_read_version(hldev, &maj, &min, &bld);
4181 if (status != VXGE_HW_OK) {
4182 vxge_debug_init(VXGE_ERR,
4183 "%s: Upgrade read version failed '%s'.",
4184 VXGE_DRIVER_NAME, fw_name);
4185 ret = -EIO;
4186 goto out;
4187 }
4188
4189 cmaj = vdev->config.device_hw_info.fw_version.major;
4190 cmin = vdev->config.device_hw_info.fw_version.minor;
4191 cbld = vdev->config.device_hw_info.fw_version.build;
4192 /* It's possible the version in /lib/firmware is not the latest version.
4193 * If so, we could get into a loop of trying to upgrade to the latest
4194 * and flashing the older version.
4195 */
4196 if (VXGE_FW_VER(maj, min, bld) == VXGE_FW_VER(cmaj, cmin, cbld) &&
4197 !override) {
4198 ret = -EINVAL;
4199 goto out;
4200 }
4201
4202 printk(KERN_NOTICE "Upgrade to firmware version %d.%d.%d commencing\n",
4203 maj, min, bld);
4204
4205 /* Flash the adapter with the new firmware */
4206 status = vxge_hw_flash_fw(hldev);
4207 if (status != VXGE_HW_OK) {
4208 vxge_debug_init(VXGE_ERR, "%s: Upgrade commit failed '%s'.",
4209 VXGE_DRIVER_NAME, fw_name);
4210 ret = -EIO;
4211 goto out;
4212 }
4213
4214 printk(KERN_NOTICE "Upgrade of firmware successful! Adapter must be "
4215 "hard reset before using, thus requiring a system reboot or a "
4216 "hotplug event.\n");
4217
4218out:
Jesper Juhle84f8852011-01-13 10:25:20 +00004219 release_firmware(fw);
Jon Masone8ac1752010-11-11 04:25:57 +00004220 return ret;
4221}
4222
4223static int vxge_probe_fw_update(struct vxgedev *vdev)
4224{
4225 u32 maj, min, bld;
4226 int ret, gpxe = 0;
4227 char *fw_name;
4228
4229 maj = vdev->config.device_hw_info.fw_version.major;
4230 min = vdev->config.device_hw_info.fw_version.minor;
4231 bld = vdev->config.device_hw_info.fw_version.build;
4232
4233 if (VXGE_FW_VER(maj, min, bld) == VXGE_CERT_FW_VER)
4234 return 0;
4235
4236 /* Ignore the build number when determining if the current firmware is
4237 * "too new" to load the driver
4238 */
4239 if (VXGE_FW_VER(maj, min, 0) > VXGE_CERT_FW_VER) {
4240 vxge_debug_init(VXGE_ERR, "%s: Firmware newer than last known "
4241 "version, unable to load driver\n",
4242 VXGE_DRIVER_NAME);
4243 return -EINVAL;
4244 }
4245
4246 /* Firmware 1.4.4 and older cannot be upgraded, and is too ancient to
4247 * work with this driver.
4248 */
4249 if (VXGE_FW_VER(maj, min, bld) <= VXGE_FW_DEAD_VER) {
4250 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d cannot be "
4251 "upgraded\n", VXGE_DRIVER_NAME, maj, min, bld);
4252 return -EINVAL;
4253 }
4254
4255 /* If file not specified, determine gPXE or not */
4256 if (VXGE_FW_VER(maj, min, bld) >= VXGE_EPROM_FW_VER) {
4257 int i;
4258 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++)
4259 if (vdev->devh->eprom_versions[i]) {
4260 gpxe = 1;
4261 break;
4262 }
4263 }
4264 if (gpxe)
4265 fw_name = "vxge/X3fw-pxe.ncf";
4266 else
4267 fw_name = "vxge/X3fw.ncf";
4268
4269 ret = vxge_fw_upgrade(vdev, fw_name, 0);
4270 /* -EINVAL and -ENOENT are not fatal errors for flashing firmware on
4271 * probe, so ignore them
4272 */
4273 if (ret != -EINVAL && ret != -ENOENT)
4274 return -EIO;
4275 else
4276 ret = 0;
4277
4278 if (VXGE_FW_VER(VXGE_CERT_FW_VER_MAJOR, VXGE_CERT_FW_VER_MINOR, 0) >
4279 VXGE_FW_VER(maj, min, 0)) {
4280 vxge_debug_init(VXGE_ERR, "%s: Firmware %d.%d.%d is too old to"
Jon Masonc0589fa2012-07-09 14:07:57 +00004281 " be used with this driver.",
Jon Masone8ac1752010-11-11 04:25:57 +00004282 VXGE_DRIVER_NAME, maj, min, bld);
4283 return -EINVAL;
4284 }
4285
4286 return ret;
4287}
4288
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004289static int is_sriov_initialized(struct pci_dev *pdev)
Jon Masonc92bf702010-12-10 14:02:57 +00004290{
4291 int pos;
4292 u16 ctrl;
4293
4294 pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV);
4295 if (pos) {
4296 pci_read_config_word(pdev, pos + PCI_SRIOV_CTRL, &ctrl);
4297 if (ctrl & PCI_SRIOV_CTRL_VFE)
4298 return 1;
4299 }
4300 return 0;
4301}
4302
stephen hemminger956a2062011-09-16 11:10:01 +00004303static const struct vxge_hw_uld_cbs vxge_callbacks = {
4304 .link_up = vxge_callback_link_up,
4305 .link_down = vxge_callback_link_down,
4306 .crit_err = vxge_callback_crit_err,
4307};
4308
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004309/**
4310 * vxge_probe
4311 * @pdev : structure containing the PCI related information of the device.
4312 * @pre: List of PCI devices supported by the driver listed in vxge_id_table.
4313 * Description:
4314 * This function is called when a new PCI device gets detected and initializes
4315 * it.
4316 * Return value:
4317 * returns 0 on success and negative on failure.
4318 *
4319 */
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004320static int
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004321vxge_probe(struct pci_dev *pdev, const struct pci_device_id *pre)
4322{
Jon Mason2c913082010-11-11 04:26:03 +00004323 struct __vxge_hw_device *hldev;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004324 enum vxge_hw_status status;
4325 int ret;
4326 int high_dma = 0;
4327 u64 vpath_mask = 0;
4328 struct vxgedev *vdev;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004329 struct vxge_config *ll_config = NULL;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004330 struct vxge_hw_device_config *device_config = NULL;
4331 struct vxge_hw_device_attr attr;
4332 int i, j, no_of_vpath = 0, max_vpath_supported = 0;
4333 u8 *macaddr;
4334 struct vxge_mac_addrs *entry;
4335 static int bus = -1, device = -1;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004336 u32 host_type;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004337 u8 new_device = 0;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004338 enum vxge_hw_status is_privileged;
4339 u32 function_mode;
4340 u32 num_vfs = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004341
4342 vxge_debug_entryexit(VXGE_TRACE, "%s:%d", __func__, __LINE__);
4343 attr.pdev = pdev;
4344
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004345 /* In SRIOV-17 mode, functions of the same adapter
Jon Mason528f7272010-12-10 14:02:56 +00004346 * can be deployed on different buses
4347 */
4348 if (((bus != pdev->bus->number) || (device != PCI_SLOT(pdev->devfn))) &&
4349 !pdev->is_virtfn)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004350 new_device = 1;
4351
4352 bus = pdev->bus->number;
4353 device = PCI_SLOT(pdev->devfn);
4354
4355 if (new_device) {
4356 if (driver_config->config_dev_cnt &&
4357 (driver_config->config_dev_cnt !=
4358 driver_config->total_dev_cnt))
4359 vxge_debug_init(VXGE_ERR,
4360 "%s: Configured %d of %d devices",
4361 VXGE_DRIVER_NAME,
4362 driver_config->config_dev_cnt,
4363 driver_config->total_dev_cnt);
4364 driver_config->config_dev_cnt = 0;
4365 driver_config->total_dev_cnt = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004366 }
Jon Mason528f7272010-12-10 14:02:56 +00004367
Sreenivasa Honnur90023972010-04-08 01:48:30 -07004368 /* Now making the CPU based no of vpath calculation
4369 * applicable for individual functions as well.
4370 */
4371 driver_config->g_no_cpus = 0;
Sreenivasa Honnur657205b2009-10-05 01:52:54 +00004372 driver_config->vpath_per_dev = max_config_vpath;
4373
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004374 driver_config->total_dev_cnt++;
4375 if (++driver_config->config_dev_cnt > max_config_dev) {
4376 ret = 0;
4377 goto _exit0;
4378 }
4379
4380 device_config = kzalloc(sizeof(struct vxge_hw_device_config),
4381 GFP_KERNEL);
4382 if (!device_config) {
4383 ret = -ENOMEM;
4384 vxge_debug_init(VXGE_ERR,
4385 "device_config : malloc failed %s %d",
4386 __FILE__, __LINE__);
4387 goto _exit0;
4388 }
4389
Jon Mason528f7272010-12-10 14:02:56 +00004390 ll_config = kzalloc(sizeof(struct vxge_config), GFP_KERNEL);
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004391 if (!ll_config) {
4392 ret = -ENOMEM;
4393 vxge_debug_init(VXGE_ERR,
Jon Mason528f7272010-12-10 14:02:56 +00004394 "device_config : malloc failed %s %d",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004395 __FILE__, __LINE__);
4396 goto _exit0;
4397 }
4398 ll_config->tx_steering_type = TX_MULTIQ_STEERING;
4399 ll_config->intr_type = MSI_X;
4400 ll_config->napi_weight = NEW_NAPI_WEIGHT;
4401 ll_config->rth_steering = RTH_STEERING;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004402
4403 /* get the default configuration parameters */
4404 vxge_hw_device_config_default_get(device_config);
4405
4406 /* initialize configuration parameters */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004407 vxge_device_config_init(device_config, &ll_config->intr_type);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004408
4409 ret = pci_enable_device(pdev);
4410 if (ret) {
4411 vxge_debug_init(VXGE_ERR,
4412 "%s : can not enable PCI device", __func__);
4413 goto _exit0;
4414 }
4415
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004416 if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004417 vxge_debug_ll_config(VXGE_TRACE,
4418 "%s : using 64bit DMA", __func__);
4419
4420 high_dma = 1;
4421
4422 if (pci_set_consistent_dma_mask(pdev,
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004423 DMA_BIT_MASK(64))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004424 vxge_debug_init(VXGE_ERR,
4425 "%s : unable to obtain 64bit DMA for "
4426 "consistent allocations", __func__);
4427 ret = -ENOMEM;
4428 goto _exit1;
4429 }
Denis Kirjanovb3837ce2009-12-25 18:48:33 -08004430 } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004431 vxge_debug_ll_config(VXGE_TRACE,
4432 "%s : using 32bit DMA", __func__);
4433 } else {
4434 ret = -ENOMEM;
4435 goto _exit1;
4436 }
4437
Jon Mason6cca2002011-01-18 15:02:19 +00004438 ret = pci_request_region(pdev, 0, VXGE_DRIVER_NAME);
4439 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004440 vxge_debug_init(VXGE_ERR,
4441 "%s : request regions failed", __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004442 goto _exit1;
4443 }
4444
4445 pci_set_master(pdev);
4446
4447 attr.bar0 = pci_ioremap_bar(pdev, 0);
4448 if (!attr.bar0) {
4449 vxge_debug_init(VXGE_ERR,
4450 "%s : cannot remap io memory bar0", __func__);
4451 ret = -ENODEV;
4452 goto _exit2;
4453 }
4454 vxge_debug_ll_config(VXGE_TRACE,
4455 "pci ioremap bar0: %p:0x%llx",
4456 attr.bar0,
4457 (unsigned long long)pci_resource_start(pdev, 0));
4458
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004459 status = vxge_hw_device_hw_info_get(attr.bar0,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004460 &ll_config->device_hw_info);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004461 if (status != VXGE_HW_OK) {
4462 vxge_debug_init(VXGE_ERR,
4463 "%s: Reading of hardware info failed."
4464 "Please try upgrading the firmware.", VXGE_DRIVER_NAME);
4465 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004466 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004467 }
4468
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004469 vpath_mask = ll_config->device_hw_info.vpath_mask;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004470 if (vpath_mask == 0) {
4471 vxge_debug_ll_config(VXGE_TRACE,
4472 "%s: No vpaths available in device", VXGE_DRIVER_NAME);
4473 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004474 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004475 }
4476
4477 vxge_debug_ll_config(VXGE_TRACE,
4478 "%s:%d Vpath mask = %llx", __func__, __LINE__,
4479 (unsigned long long)vpath_mask);
4480
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004481 function_mode = ll_config->device_hw_info.function_mode;
4482 host_type = ll_config->device_hw_info.host_type;
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004483 is_privileged = __vxge_hw_device_is_privilaged(host_type,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004484 ll_config->device_hw_info.func_id);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004485
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004486 /* Check how many vpaths are available */
4487 for (i = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4488 if (!((vpath_mask) & vxge_mBIT(i)))
4489 continue;
4490 max_vpath_supported++;
4491 }
4492
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004493 if (new_device)
4494 num_vfs = vxge_get_num_vfs(function_mode) - 1;
4495
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004496 /* Enable SRIOV mode, if firmware has SRIOV support and if it is a PF */
Jon Masonc92bf702010-12-10 14:02:57 +00004497 if (is_sriov(function_mode) && !is_sriov_initialized(pdev) &&
4498 (ll_config->intr_type != INTA)) {
4499 ret = pci_enable_sriov(pdev, num_vfs);
Sreenivasa Honnurcb27ec62010-04-08 01:48:57 -07004500 if (ret)
4501 vxge_debug_ll_config(VXGE_ERR,
4502 "Failed in enabling SRIOV mode: %d\n", ret);
Jon Masonc92bf702010-12-10 14:02:57 +00004503 /* No need to fail out, as an error here is non-fatal */
Sivakumar Subramani5dbc9012009-06-16 18:48:55 +00004504 }
4505
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004506 /*
4507 * Configure vpaths and get driver configured number of vpaths
4508 * which is less than or equal to the maximum vpaths per function.
4509 */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004510 no_of_vpath = vxge_config_vpaths(device_config, vpath_mask, ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004511 if (!no_of_vpath) {
4512 vxge_debug_ll_config(VXGE_ERR,
4513 "%s: No more vpaths to configure", VXGE_DRIVER_NAME);
4514 ret = 0;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004515 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004516 }
4517
4518 /* Setting driver callbacks */
stephen hemminger956a2062011-09-16 11:10:01 +00004519 attr.uld_callbacks = &vxge_callbacks;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004520
4521 status = vxge_hw_device_initialize(&hldev, &attr, device_config);
4522 if (status != VXGE_HW_OK) {
4523 vxge_debug_init(VXGE_ERR,
4524 "Failed to initialize device (%d)", status);
4525 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004526 goto _exit3;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004527 }
4528
Jon Masone8ac1752010-11-11 04:25:57 +00004529 if (VXGE_FW_VER(ll_config->device_hw_info.fw_version.major,
4530 ll_config->device_hw_info.fw_version.minor,
4531 ll_config->device_hw_info.fw_version.build) >=
4532 VXGE_EPROM_FW_VER) {
4533 struct eprom_image img[VXGE_HW_MAX_ROM_IMAGES];
4534
4535 status = vxge_hw_vpath_eprom_img_ver_get(hldev, img);
4536 if (status != VXGE_HW_OK) {
4537 vxge_debug_init(VXGE_ERR, "%s: Reading of EPROM failed",
4538 VXGE_DRIVER_NAME);
4539 /* This is a non-fatal error, continue */
4540 }
4541
4542 for (i = 0; i < VXGE_HW_MAX_ROM_IMAGES; i++) {
4543 hldev->eprom_versions[i] = img[i].version;
4544 if (!img[i].is_valid)
4545 break;
4546 vxge_debug_init(VXGE_TRACE, "%s: EPROM %d, version "
Jon Mason1d15f812011-01-18 15:02:20 +00004547 "%d.%d.%d.%d", VXGE_DRIVER_NAME, i,
Jon Masone8ac1752010-11-11 04:25:57 +00004548 VXGE_EPROM_IMG_MAJOR(img[i].version),
4549 VXGE_EPROM_IMG_MINOR(img[i].version),
4550 VXGE_EPROM_IMG_FIX(img[i].version),
4551 VXGE_EPROM_IMG_BUILD(img[i].version));
4552 }
4553 }
4554
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004555 /* if FCS stripping is not disabled in MAC fail driver load */
Jon Masonb81b3732010-11-11 04:25:58 +00004556 status = vxge_hw_vpath_strip_fcs_check(hldev, vpath_mask);
4557 if (status != VXGE_HW_OK) {
4558 vxge_debug_init(VXGE_ERR, "%s: FCS stripping is enabled in MAC"
4559 " failing driver load", VXGE_DRIVER_NAME);
Sreenivasa Honnurfa41fd12009-10-05 01:56:35 +00004560 ret = -EINVAL;
4561 goto _exit4;
4562 }
4563
Jon Masoncd883a72011-04-08 11:11:21 +00004564 /* Always enable HWTS. This will always cause the FCS to be invalid,
4565 * due to the fact that HWTS is using the FCS as the location of the
4566 * timestamp. The HW FCS checking will still correctly determine if
4567 * there is a valid checksum, and the FCS is being removed by the driver
4568 * anyway. So no fucntionality is being lost. Since it is always
4569 * enabled, we now simply use the ioctl call to set whether or not the
4570 * driver should be paying attention to the HWTS.
4571 */
4572 if (is_privileged == VXGE_HW_OK) {
4573 status = vxge_timestamp_config(hldev);
4574 if (status != VXGE_HW_OK) {
4575 vxge_debug_init(VXGE_ERR, "%s: HWTS enable failed",
4576 VXGE_DRIVER_NAME);
4577 ret = -EFAULT;
4578 goto _exit4;
4579 }
4580 }
4581
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004582 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4583
4584 /* set private device info */
4585 pci_set_drvdata(pdev, hldev);
4586
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004587 ll_config->fifo_indicate_max_pkts = VXGE_FIFO_INDICATE_MAX_PKTS;
4588 ll_config->addr_learn_en = addr_learn_en;
4589 ll_config->rth_algorithm = RTH_ALG_JENKINS;
Jon Mason47f01db2010-11-11 04:25:53 +00004590 ll_config->rth_hash_type_tcpipv4 = 1;
4591 ll_config->rth_hash_type_ipv4 = 0;
4592 ll_config->rth_hash_type_tcpipv6 = 0;
4593 ll_config->rth_hash_type_ipv6 = 0;
4594 ll_config->rth_hash_type_tcpipv6ex = 0;
4595 ll_config->rth_hash_type_ipv6ex = 0;
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004596 ll_config->rth_bkt_sz = RTH_BUCKET_SIZE;
4597 ll_config->tx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
4598 ll_config->rx_pause_enable = VXGE_PAUSE_CTRL_ENABLE;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004599
Jon Masone8ac1752010-11-11 04:25:57 +00004600 ret = vxge_device_register(hldev, ll_config, high_dma, no_of_vpath,
4601 &vdev);
4602 if (ret) {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004603 ret = -EINVAL;
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004604 goto _exit4;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004605 }
4606
Jon Masone8ac1752010-11-11 04:25:57 +00004607 ret = vxge_probe_fw_update(vdev);
4608 if (ret)
4609 goto _exit5;
4610
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004611 vxge_hw_device_debug_set(hldev, VXGE_TRACE, VXGE_COMPONENT_LL);
4612 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4613 vxge_hw_device_trace_level_get(hldev));
4614
4615 /* set private HW device info */
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004616 vdev->mtu = VXGE_HW_DEFAULT_MTU;
4617 vdev->bar0 = attr.bar0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004618 vdev->max_vpath_supported = max_vpath_supported;
4619 vdev->no_of_vpath = no_of_vpath;
4620
4621 /* Virtual Path count */
4622 for (i = 0, j = 0; i < VXGE_HW_MAX_VIRTUAL_PATHS; i++) {
4623 if (!vxge_bVALn(vpath_mask, i, 1))
4624 continue;
4625 if (j >= vdev->no_of_vpath)
4626 break;
4627
4628 vdev->vpaths[j].is_configured = 1;
4629 vdev->vpaths[j].device_id = i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004630 vdev->vpaths[j].ring.driver_id = j;
4631 vdev->vpaths[j].vdev = vdev;
4632 vdev->vpaths[j].max_mac_addr_cnt = max_mac_vpath;
4633 memcpy((u8 *)vdev->vpaths[j].macaddr,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004634 ll_config->device_hw_info.mac_addrs[i],
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004635 ETH_ALEN);
4636
4637 /* Initialize the mac address list header */
4638 INIT_LIST_HEAD(&vdev->vpaths[j].mac_addr_list);
4639
4640 vdev->vpaths[j].mac_addr_cnt = 0;
4641 vdev->vpaths[j].mcast_addr_cnt = 0;
4642 j++;
4643 }
4644 vdev->exec_mode = VXGE_EXEC_MODE_DISABLE;
4645 vdev->max_config_port = max_config_port;
4646
4647 vdev->vlan_tag_strip = vlan_tag_strip;
4648
4649 /* map the hashing selector table to the configured vpaths */
4650 for (i = 0; i < vdev->no_of_vpath; i++)
4651 vdev->vpath_selector[i] = vpath_selector[i];
4652
4653 macaddr = (u8 *)vdev->vpaths[0].macaddr;
4654
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004655 ll_config->device_hw_info.serial_number[VXGE_HW_INFO_LEN - 1] = '\0';
4656 ll_config->device_hw_info.product_desc[VXGE_HW_INFO_LEN - 1] = '\0';
4657 ll_config->device_hw_info.part_number[VXGE_HW_INFO_LEN - 1] = '\0';
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004658
4659 vxge_debug_init(VXGE_TRACE, "%s: SERIAL NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004660 vdev->ndev->name, ll_config->device_hw_info.serial_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004661
4662 vxge_debug_init(VXGE_TRACE, "%s: PART NUMBER: %s",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004663 vdev->ndev->name, ll_config->device_hw_info.part_number);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004664
4665 vxge_debug_init(VXGE_TRACE, "%s: Neterion %s Server Adapter",
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004666 vdev->ndev->name, ll_config->device_hw_info.product_desc);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004667
hartleysbf54e732010-01-05 06:59:23 +00004668 vxge_debug_init(VXGE_TRACE, "%s: MAC ADDR: %pM",
4669 vdev->ndev->name, macaddr);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004670
4671 vxge_debug_init(VXGE_TRACE, "%s: Link Width x%d",
4672 vdev->ndev->name, vxge_hw_device_link_width_get(hldev));
4673
4674 vxge_debug_init(VXGE_TRACE,
4675 "%s: Firmware version : %s Date : %s", vdev->ndev->name,
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004676 ll_config->device_hw_info.fw_version.version,
4677 ll_config->device_hw_info.fw_date.date);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004678
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004679 if (new_device) {
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004680 switch (ll_config->device_hw_info.function_mode) {
Sreenivasa Honnur0a25bdc2009-07-01 21:18:06 +00004681 case VXGE_HW_FUNCTION_MODE_SINGLE_FUNCTION:
4682 vxge_debug_init(VXGE_TRACE,
4683 "%s: Single Function Mode Enabled", vdev->ndev->name);
4684 break;
4685 case VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION:
4686 vxge_debug_init(VXGE_TRACE,
4687 "%s: Multi Function Mode Enabled", vdev->ndev->name);
4688 break;
4689 case VXGE_HW_FUNCTION_MODE_SRIOV:
4690 vxge_debug_init(VXGE_TRACE,
4691 "%s: Single Root IOV Mode Enabled", vdev->ndev->name);
4692 break;
4693 case VXGE_HW_FUNCTION_MODE_MRIOV:
4694 vxge_debug_init(VXGE_TRACE,
4695 "%s: Multi Root IOV Mode Enabled", vdev->ndev->name);
4696 break;
4697 }
4698 }
4699
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004700 vxge_print_parm(vdev, vpath_mask);
4701
4702 /* Store the fw version for ethttool option */
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004703 strcpy(vdev->fw_version, ll_config->device_hw_info.fw_version.version);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004704 memcpy(vdev->ndev->dev_addr, (u8 *)vdev->vpaths[0].macaddr, ETH_ALEN);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004705
4706 /* Copy the station mac address to the list */
4707 for (i = 0; i < vdev->no_of_vpath; i++) {
Joe Perchese80be0b2010-11-27 23:05:45 +00004708 entry = kzalloc(sizeof(struct vxge_mac_addrs), GFP_KERNEL);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004709 if (NULL == entry) {
4710 vxge_debug_init(VXGE_ERR,
4711 "%s: mac_addr_list : memory allocation failed",
4712 vdev->ndev->name);
4713 ret = -EPERM;
Jon Masone8ac1752010-11-11 04:25:57 +00004714 goto _exit6;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004715 }
4716 macaddr = (u8 *)&entry->macaddr;
4717 memcpy(macaddr, vdev->ndev->dev_addr, ETH_ALEN);
4718 list_add(&entry->item, &vdev->vpaths[i].mac_addr_list);
4719 vdev->vpaths[i].mac_addr_cnt = 1;
4720 }
4721
Sreenivasa Honnur914d0d72009-07-01 21:13:12 +00004722 kfree(device_config);
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004723
4724 /*
4725 * INTA is shared in multi-function mode. This is unlike the INTA
4726 * implementation in MR mode, where each VH has its own INTA message.
4727 * - INTA is masked (disabled) as long as at least one function sets
4728 * its TITAN_MASK_ALL_INT.ALARM bit.
4729 * - INTA is unmasked (enabled) when all enabled functions have cleared
4730 * their own TITAN_MASK_ALL_INT.ALARM bit.
4731 * The TITAN_MASK_ALL_INT ALARM & TRAFFIC bits are cleared on power up.
4732 * Though this driver leaves the top level interrupts unmasked while
4733 * leaving the required module interrupt bits masked on exit, there
4734 * could be a rougue driver around that does not follow this procedure
4735 * resulting in a failure to generate interrupts. The following code is
4736 * present to prevent such a failure.
4737 */
4738
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004739 if (ll_config->device_hw_info.function_mode ==
Sreenivasa Honnureb5f10c2009-10-05 01:57:29 +00004740 VXGE_HW_FUNCTION_MODE_MULTI_FUNCTION)
4741 if (vdev->config.intr_type == INTA)
4742 vxge_hw_device_unmask_all(hldev);
4743
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004744 vxge_debug_entryexit(VXGE_TRACE, "%s: %s:%d Exiting...",
4745 vdev->ndev->name, __func__, __LINE__);
4746
4747 vxge_hw_device_debug_set(hldev, VXGE_ERR, VXGE_COMPONENT_LL);
4748 VXGE_COPY_DEBUG_INFO_TO_LL(vdev, vxge_hw_device_error_level_get(hldev),
4749 vxge_hw_device_trace_level_get(hldev));
4750
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004751 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004752 return 0;
4753
Jon Masone8ac1752010-11-11 04:25:57 +00004754_exit6:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004755 for (i = 0; i < vdev->no_of_vpath; i++)
4756 vxge_free_mac_add_list(&vdev->vpaths[i]);
Jon Masone8ac1752010-11-11 04:25:57 +00004757_exit5:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004758 vxge_device_unregister(hldev);
Sreenivasa Honnur7975d1e2009-07-01 21:12:23 +00004759_exit4:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004760 vxge_hw_device_terminate(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004761 pci_disable_sriov(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004762_exit3:
4763 iounmap(attr.bar0);
4764_exit2:
Jon Masondc66daa2010-12-10 14:02:58 +00004765 pci_release_region(pdev, 0);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004766_exit1:
4767 pci_disable_device(pdev);
4768_exit0:
Prarit Bhargava7dad1712010-06-02 05:51:19 -07004769 kfree(ll_config);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004770 kfree(device_config);
4771 driver_config->config_dev_cnt--;
Jon Mason6cca2002011-01-18 15:02:19 +00004772 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004773 return ret;
4774}
4775
4776/**
4777 * vxge_rem_nic - Free the PCI device
4778 * @pdev: structure containing the PCI related information of the device.
4779 * Description: This function is called by the Pci subsystem to release a
4780 * PCI device and free up all resource held up by the device.
4781 */
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004782static void vxge_remove(struct pci_dev *pdev)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004783{
Jon Mason2c913082010-11-11 04:26:03 +00004784 struct __vxge_hw_device *hldev;
Jon Mason6cca2002011-01-18 15:02:19 +00004785 struct vxgedev *vdev;
4786 int i;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004787
Joe Perchesd8ee7072010-11-15 10:13:58 +00004788 hldev = pci_get_drvdata(pdev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004789 if (hldev == NULL)
4790 return;
Jon Mason2c913082010-11-11 04:26:03 +00004791
Jon Mason6cca2002011-01-18 15:02:19 +00004792 vdev = netdev_priv(hldev->ndev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004793
Jon Mason2c913082010-11-11 04:26:03 +00004794 vxge_debug_entryexit(vdev->level_trace, "%s:%d", __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004795 vxge_debug_init(vdev->level_trace, "%s : removing PCI device...",
4796 __func__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004797
Jon Mason6cca2002011-01-18 15:02:19 +00004798 for (i = 0; i < vdev->no_of_vpath; i++)
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004799 vxge_free_mac_add_list(&vdev->vpaths[i]);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004800
Jon Mason6cca2002011-01-18 15:02:19 +00004801 vxge_device_unregister(hldev);
Jon Mason6cca2002011-01-18 15:02:19 +00004802 /* Do not call pci_disable_sriov here, as it will break child devices */
4803 vxge_hw_device_terminate(hldev);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004804 iounmap(vdev->bar0);
Jon Mason6cca2002011-01-18 15:02:19 +00004805 pci_release_region(pdev, 0);
4806 pci_disable_device(pdev);
4807 driver_config->config_dev_cnt--;
4808 driver_config->total_dev_cnt--;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004809
Jon Mason2c913082010-11-11 04:26:03 +00004810 vxge_debug_init(vdev->level_trace, "%s:%d Device unregistered",
4811 __func__, __LINE__);
Jon Mason2c913082010-11-11 04:26:03 +00004812 vxge_debug_entryexit(vdev->level_trace, "%s:%d Exiting...", __func__,
4813 __LINE__);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004814}
4815
Stephen Hemminger3646f0e2012-09-07 09:33:15 -07004816static const struct pci_error_handlers vxge_err_handler = {
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004817 .error_detected = vxge_io_error_detected,
4818 .slot_reset = vxge_io_slot_reset,
4819 .resume = vxge_io_resume,
4820};
4821
4822static struct pci_driver vxge_driver = {
4823 .name = VXGE_DRIVER_NAME,
4824 .id_table = vxge_id_table,
4825 .probe = vxge_probe,
Bill Pemberton3a036ce2012-12-03 09:23:18 -05004826 .remove = vxge_remove,
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004827#ifdef CONFIG_PM
4828 .suspend = vxge_pm_suspend,
4829 .resume = vxge_pm_resume,
4830#endif
4831 .err_handler = &vxge_err_handler,
4832};
4833
4834static int __init
4835vxge_starter(void)
4836{
4837 int ret = 0;
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004838
Joe Perches75f5e1c2010-07-27 11:47:03 +00004839 pr_info("Copyright(c) 2002-2010 Exar Corp.\n");
4840 pr_info("Driver version: %s\n", DRV_VERSION);
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004841
4842 verify_bandwidth();
4843
4844 driver_config = kzalloc(sizeof(struct vxge_drv_config), GFP_KERNEL);
4845 if (!driver_config)
4846 return -ENOMEM;
4847
4848 ret = pci_register_driver(&vxge_driver);
Jon Mason528f7272010-12-10 14:02:56 +00004849 if (ret) {
4850 kfree(driver_config);
4851 goto err;
4852 }
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004853
4854 if (driver_config->config_dev_cnt &&
4855 (driver_config->config_dev_cnt != driver_config->total_dev_cnt))
4856 vxge_debug_init(VXGE_ERR,
4857 "%s: Configured %d of %d devices",
4858 VXGE_DRIVER_NAME, driver_config->config_dev_cnt,
4859 driver_config->total_dev_cnt);
Jon Mason528f7272010-12-10 14:02:56 +00004860err:
Ramkrishna Vepa703da5a2009-04-01 18:15:13 +00004861 return ret;
4862}
4863
4864static void __exit
4865vxge_closer(void)
4866{
4867 pci_unregister_driver(&vxge_driver);
4868 kfree(driver_config);
4869}
4870module_init(vxge_starter);
4871module_exit(vxge_closer);