blob: 413e362e3275c5ff1f5ee2d8fae09a651a855239 [file] [log] [blame]
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001/*
2 * Copyright 2008 Cisco Systems, Inc. All rights reserved.
3 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
4 *
5 * This program is free software; you may redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
10 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
11 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
12 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
13 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
14 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
15 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
16 * SOFTWARE.
17 *
18 */
19
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/string.h>
23#include <linux/errno.h>
24#include <linux/types.h>
25#include <linux/init.h>
26#include <linux/workqueue.h>
27#include <linux/pci.h>
28#include <linux/netdevice.h>
29#include <linux/etherdevice.h>
30#include <linux/if_ether.h>
31#include <linux/if_vlan.h>
Scott Feldmanf8bd9092010-05-17 22:50:19 -070032#include <linux/if_link.h>
Scott Feldman01f2e4e2008-09-15 09:17:11 -070033#include <linux/ethtool.h>
34#include <linux/in.h>
35#include <linux/ip.h>
36#include <linux/ipv6.h>
37#include <linux/tcp.h>
Kamalesh Babulalb7c6bfb2008-10-13 18:41:01 -070038#include <net/ip6_checksum.h>
Scott Feldman01f2e4e2008-09-15 09:17:11 -070039
40#include "cq_enet_desc.h"
41#include "vnic_dev.h"
42#include "vnic_intr.h"
43#include "vnic_stats.h"
Scott Feldmanf8bd9092010-05-17 22:50:19 -070044#include "vnic_vic.h"
Scott Feldman01f2e4e2008-09-15 09:17:11 -070045#include "enic_res.h"
46#include "enic.h"
47
48#define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ)
Scott Feldmanea0d7d92009-09-03 17:02:03 +000049#define WQ_ENET_MAX_DESC_LEN (1 << WQ_ENET_LEN_BITS)
50#define MAX_TSO (1 << 16)
51#define ENIC_DESC_MAX_SPLITS (MAX_TSO / WQ_ENET_MAX_DESC_LEN + 1)
52
53#define PCI_DEVICE_ID_CISCO_VIC_ENET 0x0043 /* ethernet vnic */
Scott Feldmanf8bd9092010-05-17 22:50:19 -070054#define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044 /* enet dynamic vnic */
Scott Feldman01f2e4e2008-09-15 09:17:11 -070055
56/* Supported devices */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000057static DEFINE_PCI_DEVICE_TABLE(enic_id_table) = {
Scott Feldmanea0d7d92009-09-03 17:02:03 +000058 { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) },
Scott Feldmanf8bd9092010-05-17 22:50:19 -070059 { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_DYN) },
Scott Feldman01f2e4e2008-09-15 09:17:11 -070060 { 0, } /* end of table */
61};
62
63MODULE_DESCRIPTION(DRV_DESCRIPTION);
64MODULE_AUTHOR("Scott Feldman <scofeldm@cisco.com>");
65MODULE_LICENSE("GPL");
66MODULE_VERSION(DRV_VERSION);
67MODULE_DEVICE_TABLE(pci, enic_id_table);
68
69struct enic_stat {
70 char name[ETH_GSTRING_LEN];
71 unsigned int offset;
72};
73
74#define ENIC_TX_STAT(stat) \
75 { .name = #stat, .offset = offsetof(struct vnic_tx_stats, stat) / 8 }
76#define ENIC_RX_STAT(stat) \
77 { .name = #stat, .offset = offsetof(struct vnic_rx_stats, stat) / 8 }
78
79static const struct enic_stat enic_tx_stats[] = {
80 ENIC_TX_STAT(tx_frames_ok),
81 ENIC_TX_STAT(tx_unicast_frames_ok),
82 ENIC_TX_STAT(tx_multicast_frames_ok),
83 ENIC_TX_STAT(tx_broadcast_frames_ok),
84 ENIC_TX_STAT(tx_bytes_ok),
85 ENIC_TX_STAT(tx_unicast_bytes_ok),
86 ENIC_TX_STAT(tx_multicast_bytes_ok),
87 ENIC_TX_STAT(tx_broadcast_bytes_ok),
88 ENIC_TX_STAT(tx_drops),
89 ENIC_TX_STAT(tx_errors),
90 ENIC_TX_STAT(tx_tso),
91};
92
93static const struct enic_stat enic_rx_stats[] = {
94 ENIC_RX_STAT(rx_frames_ok),
95 ENIC_RX_STAT(rx_frames_total),
96 ENIC_RX_STAT(rx_unicast_frames_ok),
97 ENIC_RX_STAT(rx_multicast_frames_ok),
98 ENIC_RX_STAT(rx_broadcast_frames_ok),
99 ENIC_RX_STAT(rx_bytes_ok),
100 ENIC_RX_STAT(rx_unicast_bytes_ok),
101 ENIC_RX_STAT(rx_multicast_bytes_ok),
102 ENIC_RX_STAT(rx_broadcast_bytes_ok),
103 ENIC_RX_STAT(rx_drop),
104 ENIC_RX_STAT(rx_no_bufs),
105 ENIC_RX_STAT(rx_errors),
106 ENIC_RX_STAT(rx_rss),
107 ENIC_RX_STAT(rx_crc_errors),
108 ENIC_RX_STAT(rx_frames_64),
109 ENIC_RX_STAT(rx_frames_127),
110 ENIC_RX_STAT(rx_frames_255),
111 ENIC_RX_STAT(rx_frames_511),
112 ENIC_RX_STAT(rx_frames_1023),
113 ENIC_RX_STAT(rx_frames_1518),
114 ENIC_RX_STAT(rx_frames_to_max),
115};
116
117static const unsigned int enic_n_tx_stats = ARRAY_SIZE(enic_tx_stats);
118static const unsigned int enic_n_rx_stats = ARRAY_SIZE(enic_rx_stats);
119
Scott Feldmanf8bd9092010-05-17 22:50:19 -0700120static int enic_is_dynamic(struct enic *enic)
121{
122 return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_DYN;
123}
124
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700125static int enic_get_settings(struct net_device *netdev,
126 struct ethtool_cmd *ecmd)
127{
128 struct enic *enic = netdev_priv(netdev);
129
130 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
131 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
132 ecmd->port = PORT_FIBRE;
133 ecmd->transceiver = XCVR_EXTERNAL;
134
135 if (netif_carrier_ok(netdev)) {
136 ecmd->speed = vnic_dev_port_speed(enic->vdev);
137 ecmd->duplex = DUPLEX_FULL;
138 } else {
139 ecmd->speed = -1;
140 ecmd->duplex = -1;
141 }
142
143 ecmd->autoneg = AUTONEG_DISABLE;
144
145 return 0;
146}
147
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000148static int enic_dev_fw_info(struct enic *enic,
149 struct vnic_devcmd_fw_info **fw_info)
150{
151 int err;
152
153 spin_lock(&enic->devcmd_lock);
154 err = vnic_dev_fw_info(enic->vdev, fw_info);
155 spin_unlock(&enic->devcmd_lock);
156
157 return err;
158}
159
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700160static void enic_get_drvinfo(struct net_device *netdev,
161 struct ethtool_drvinfo *drvinfo)
162{
163 struct enic *enic = netdev_priv(netdev);
164 struct vnic_devcmd_fw_info *fw_info;
165
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000166 enic_dev_fw_info(enic, &fw_info);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700167
168 strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
169 strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
170 strncpy(drvinfo->fw_version, fw_info->fw_version,
171 sizeof(drvinfo->fw_version));
172 strncpy(drvinfo->bus_info, pci_name(enic->pdev),
173 sizeof(drvinfo->bus_info));
174}
175
176static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
177{
178 unsigned int i;
179
180 switch (stringset) {
181 case ETH_SS_STATS:
182 for (i = 0; i < enic_n_tx_stats; i++) {
183 memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
184 data += ETH_GSTRING_LEN;
185 }
186 for (i = 0; i < enic_n_rx_stats; i++) {
187 memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
188 data += ETH_GSTRING_LEN;
189 }
190 break;
191 }
192}
193
Scott Feldman25f0a062008-09-24 11:23:32 -0700194static int enic_get_sset_count(struct net_device *netdev, int sset)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700195{
Scott Feldman25f0a062008-09-24 11:23:32 -0700196 switch (sset) {
197 case ETH_SS_STATS:
198 return enic_n_tx_stats + enic_n_rx_stats;
199 default:
200 return -EOPNOTSUPP;
201 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700202}
203
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000204static int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
205{
206 int err;
207
208 spin_lock(&enic->devcmd_lock);
209 err = vnic_dev_stats_dump(enic->vdev, vstats);
210 spin_unlock(&enic->devcmd_lock);
211
212 return err;
213}
214
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700215static void enic_get_ethtool_stats(struct net_device *netdev,
216 struct ethtool_stats *stats, u64 *data)
217{
218 struct enic *enic = netdev_priv(netdev);
219 struct vnic_stats *vstats;
220 unsigned int i;
221
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000222 enic_dev_stats_dump(enic, &vstats);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700223
224 for (i = 0; i < enic_n_tx_stats; i++)
225 *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
226 for (i = 0; i < enic_n_rx_stats; i++)
227 *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
228}
229
230static u32 enic_get_rx_csum(struct net_device *netdev)
231{
232 struct enic *enic = netdev_priv(netdev);
233 return enic->csum_rx_enabled;
234}
235
236static int enic_set_rx_csum(struct net_device *netdev, u32 data)
237{
238 struct enic *enic = netdev_priv(netdev);
239
Scott Feldman25f0a062008-09-24 11:23:32 -0700240 if (data && !ENIC_SETTING(enic, RXCSUM))
241 return -EINVAL;
242
243 enic->csum_rx_enabled = !!data;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700244
245 return 0;
246}
247
248static int enic_set_tx_csum(struct net_device *netdev, u32 data)
249{
250 struct enic *enic = netdev_priv(netdev);
251
Scott Feldman25f0a062008-09-24 11:23:32 -0700252 if (data && !ENIC_SETTING(enic, TXCSUM))
253 return -EINVAL;
254
255 if (data)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700256 netdev->features |= NETIF_F_HW_CSUM;
257 else
258 netdev->features &= ~NETIF_F_HW_CSUM;
259
260 return 0;
261}
262
263static int enic_set_tso(struct net_device *netdev, u32 data)
264{
265 struct enic *enic = netdev_priv(netdev);
266
Scott Feldman25f0a062008-09-24 11:23:32 -0700267 if (data && !ENIC_SETTING(enic, TSO))
268 return -EINVAL;
269
270 if (data)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700271 netdev->features |=
272 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN;
273 else
274 netdev->features &=
275 ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN);
276
277 return 0;
278}
279
280static u32 enic_get_msglevel(struct net_device *netdev)
281{
282 struct enic *enic = netdev_priv(netdev);
283 return enic->msg_enable;
284}
285
286static void enic_set_msglevel(struct net_device *netdev, u32 value)
287{
288 struct enic *enic = netdev_priv(netdev);
289 enic->msg_enable = value;
290}
291
Scott Feldman7c844592009-12-23 13:27:54 +0000292static int enic_get_coalesce(struct net_device *netdev,
293 struct ethtool_coalesce *ecmd)
294{
295 struct enic *enic = netdev_priv(netdev);
296
297 ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
298 ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
299
300 return 0;
301}
302
303static int enic_set_coalesce(struct net_device *netdev,
304 struct ethtool_coalesce *ecmd)
305{
306 struct enic *enic = netdev_priv(netdev);
307 u32 tx_coalesce_usecs;
308 u32 rx_coalesce_usecs;
309
310 tx_coalesce_usecs = min_t(u32,
311 INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
312 ecmd->tx_coalesce_usecs);
313 rx_coalesce_usecs = min_t(u32,
314 INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
315 ecmd->rx_coalesce_usecs);
316
317 switch (vnic_dev_get_intr_mode(enic->vdev)) {
318 case VNIC_DEV_INTR_MODE_INTX:
319 if (tx_coalesce_usecs != rx_coalesce_usecs)
320 return -EINVAL;
321
322 vnic_intr_coalescing_timer_set(&enic->intr[ENIC_INTX_WQ_RQ],
323 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
324 break;
325 case VNIC_DEV_INTR_MODE_MSI:
326 if (tx_coalesce_usecs != rx_coalesce_usecs)
327 return -EINVAL;
328
329 vnic_intr_coalescing_timer_set(&enic->intr[0],
330 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
331 break;
332 case VNIC_DEV_INTR_MODE_MSIX:
333 vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_WQ],
334 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
335 vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_RQ],
336 INTR_COALESCE_USEC_TO_HW(rx_coalesce_usecs));
337 break;
338 default:
339 break;
340 }
341
342 enic->tx_coalesce_usecs = tx_coalesce_usecs;
343 enic->rx_coalesce_usecs = rx_coalesce_usecs;
344
345 return 0;
346}
347
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700348static const struct ethtool_ops enic_ethtool_ops = {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700349 .get_settings = enic_get_settings,
350 .get_drvinfo = enic_get_drvinfo,
351 .get_msglevel = enic_get_msglevel,
352 .set_msglevel = enic_set_msglevel,
353 .get_link = ethtool_op_get_link,
354 .get_strings = enic_get_strings,
Scott Feldman25f0a062008-09-24 11:23:32 -0700355 .get_sset_count = enic_get_sset_count,
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700356 .get_ethtool_stats = enic_get_ethtool_stats,
357 .get_rx_csum = enic_get_rx_csum,
358 .set_rx_csum = enic_set_rx_csum,
359 .get_tx_csum = ethtool_op_get_tx_csum,
360 .set_tx_csum = enic_set_tx_csum,
361 .get_sg = ethtool_op_get_sg,
362 .set_sg = ethtool_op_set_sg,
363 .get_tso = ethtool_op_get_tso,
364 .set_tso = enic_set_tso,
Scott Feldman7c844592009-12-23 13:27:54 +0000365 .get_coalesce = enic_get_coalesce,
366 .set_coalesce = enic_set_coalesce,
Scott Feldman86ca9db2008-11-21 21:26:55 -0800367 .get_flags = ethtool_op_get_flags,
368 .set_flags = ethtool_op_set_flags,
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700369};
370
371static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
372{
373 struct enic *enic = vnic_dev_priv(wq->vdev);
374
375 if (buf->sop)
376 pci_unmap_single(enic->pdev, buf->dma_addr,
377 buf->len, PCI_DMA_TODEVICE);
378 else
379 pci_unmap_page(enic->pdev, buf->dma_addr,
380 buf->len, PCI_DMA_TODEVICE);
381
382 if (buf->os_buf)
383 dev_kfree_skb_any(buf->os_buf);
384}
385
386static void enic_wq_free_buf(struct vnic_wq *wq,
387 struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
388{
389 enic_free_wq_buf(wq, buf);
390}
391
392static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
393 u8 type, u16 q_number, u16 completed_index, void *opaque)
394{
395 struct enic *enic = vnic_dev_priv(vdev);
396
397 spin_lock(&enic->wq_lock[q_number]);
398
399 vnic_wq_service(&enic->wq[q_number], cq_desc,
400 completed_index, enic_wq_free_buf,
401 opaque);
402
403 if (netif_queue_stopped(enic->netdev) &&
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000404 vnic_wq_desc_avail(&enic->wq[q_number]) >=
405 (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS))
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700406 netif_wake_queue(enic->netdev);
407
408 spin_unlock(&enic->wq_lock[q_number]);
409
410 return 0;
411}
412
413static void enic_log_q_error(struct enic *enic)
414{
415 unsigned int i;
416 u32 error_status;
417
418 for (i = 0; i < enic->wq_count; i++) {
419 error_status = vnic_wq_error_status(&enic->wq[i]);
420 if (error_status)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000421 netdev_err(enic->netdev, "WQ[%d] error_status %d\n",
422 i, error_status);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700423 }
424
425 for (i = 0; i < enic->rq_count; i++) {
426 error_status = vnic_rq_error_status(&enic->rq[i]);
427 if (error_status)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000428 netdev_err(enic->netdev, "RQ[%d] error_status %d\n",
429 i, error_status);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700430 }
431}
432
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000433static void enic_msglvl_check(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700434{
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000435 u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700436
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000437 if (msg_enable != enic->msg_enable) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000438 netdev_info(enic->netdev, "msg lvl changed from 0x%x to 0x%x\n",
439 enic->msg_enable, msg_enable);
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000440 enic->msg_enable = msg_enable;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700441 }
442}
443
444static void enic_mtu_check(struct enic *enic)
445{
446 u32 mtu = vnic_dev_mtu(enic->vdev);
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000447 struct net_device *netdev = enic->netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700448
Scott Feldman491598a2009-09-03 17:02:40 +0000449 if (mtu && mtu != enic->port_mtu) {
Scott Feldman7c844592009-12-23 13:27:54 +0000450 enic->port_mtu = mtu;
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000451 if (mtu < netdev->mtu)
452 netdev_warn(netdev,
453 "interface MTU (%d) set higher "
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700454 "than switch port MTU (%d)\n",
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000455 netdev->mtu, mtu);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700456 }
457}
458
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000459static void enic_link_check(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700460{
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000461 int link_status = vnic_dev_link_status(enic->vdev);
462 int carrier_ok = netif_carrier_ok(enic->netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700463
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000464 if (link_status && !carrier_ok) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000465 netdev_info(enic->netdev, "Link UP\n");
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000466 netif_carrier_on(enic->netdev);
467 } else if (!link_status && carrier_ok) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000468 netdev_info(enic->netdev, "Link DOWN\n");
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000469 netif_carrier_off(enic->netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700470 }
471}
472
473static void enic_notify_check(struct enic *enic)
474{
475 enic_msglvl_check(enic);
476 enic_mtu_check(enic);
477 enic_link_check(enic);
478}
479
480#define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
481
482static irqreturn_t enic_isr_legacy(int irq, void *data)
483{
484 struct net_device *netdev = data;
485 struct enic *enic = netdev_priv(netdev);
486 u32 pba;
487
488 vnic_intr_mask(&enic->intr[ENIC_INTX_WQ_RQ]);
489
490 pba = vnic_intr_legacy_pba(enic->legacy_pba);
491 if (!pba) {
492 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
493 return IRQ_NONE; /* not our interrupt */
494 }
495
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800496 if (ENIC_TEST_INTR(pba, ENIC_INTX_NOTIFY)) {
497 vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_NOTIFY]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700498 enic_notify_check(enic);
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800499 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700500
501 if (ENIC_TEST_INTR(pba, ENIC_INTX_ERR)) {
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800502 vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_ERR]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700503 enic_log_q_error(enic);
504 /* schedule recovery from WQ/RQ error */
505 schedule_work(&enic->reset);
506 return IRQ_HANDLED;
507 }
508
509 if (ENIC_TEST_INTR(pba, ENIC_INTX_WQ_RQ)) {
Ben Hutchings288379f2009-01-19 16:43:59 -0800510 if (napi_schedule_prep(&enic->napi))
511 __napi_schedule(&enic->napi);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700512 } else {
513 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
514 }
515
516 return IRQ_HANDLED;
517}
518
519static irqreturn_t enic_isr_msi(int irq, void *data)
520{
521 struct enic *enic = data;
522
523 /* With MSI, there is no sharing of interrupts, so this is
524 * our interrupt and there is no need to ack it. The device
525 * is not providing per-vector masking, so the OS will not
526 * write to PCI config space to mask/unmask the interrupt.
527 * We're using mask_on_assertion for MSI, so the device
528 * automatically masks the interrupt when the interrupt is
529 * generated. Later, when exiting polling, the interrupt
530 * will be unmasked (see enic_poll).
531 *
532 * Also, the device uses the same PCIe Traffic Class (TC)
533 * for Memory Write data and MSI, so there are no ordering
534 * issues; the MSI will always arrive at the Root Complex
535 * _after_ corresponding Memory Writes (i.e. descriptor
536 * writes).
537 */
538
Ben Hutchings288379f2009-01-19 16:43:59 -0800539 napi_schedule(&enic->napi);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700540
541 return IRQ_HANDLED;
542}
543
544static irqreturn_t enic_isr_msix_rq(int irq, void *data)
545{
546 struct enic *enic = data;
547
548 /* schedule NAPI polling for RQ cleanup */
Ben Hutchings288379f2009-01-19 16:43:59 -0800549 napi_schedule(&enic->napi);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700550
551 return IRQ_HANDLED;
552}
553
554static irqreturn_t enic_isr_msix_wq(int irq, void *data)
555{
556 struct enic *enic = data;
557 unsigned int wq_work_to_do = -1; /* no limit */
558 unsigned int wq_work_done;
559
560 wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
561 wq_work_to_do, enic_wq_service, NULL);
562
563 vnic_intr_return_credits(&enic->intr[ENIC_MSIX_WQ],
564 wq_work_done,
565 1 /* unmask intr */,
566 1 /* reset intr timer */);
567
568 return IRQ_HANDLED;
569}
570
571static irqreturn_t enic_isr_msix_err(int irq, void *data)
572{
573 struct enic *enic = data;
574
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800575 vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_ERR]);
576
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700577 enic_log_q_error(enic);
578
579 /* schedule recovery from WQ/RQ error */
580 schedule_work(&enic->reset);
581
582 return IRQ_HANDLED;
583}
584
585static irqreturn_t enic_isr_msix_notify(int irq, void *data)
586{
587 struct enic *enic = data;
588
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800589 vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_NOTIFY]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700590 enic_notify_check(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700591
592 return IRQ_HANDLED;
593}
594
595static inline void enic_queue_wq_skb_cont(struct enic *enic,
596 struct vnic_wq *wq, struct sk_buff *skb,
597 unsigned int len_left)
598{
599 skb_frag_t *frag;
600
601 /* Queue additional data fragments */
602 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
603 len_left -= frag->size;
604 enic_queue_wq_desc_cont(wq, skb,
605 pci_map_page(enic->pdev, frag->page,
606 frag->page_offset, frag->size,
607 PCI_DMA_TODEVICE),
608 frag->size,
609 (len_left == 0)); /* EOP? */
610 }
611}
612
613static inline void enic_queue_wq_skb_vlan(struct enic *enic,
614 struct vnic_wq *wq, struct sk_buff *skb,
615 int vlan_tag_insert, unsigned int vlan_tag)
616{
617 unsigned int head_len = skb_headlen(skb);
618 unsigned int len_left = skb->len - head_len;
619 int eop = (len_left == 0);
620
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000621 /* Queue the main skb fragment. The fragments are no larger
622 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
623 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
624 * per fragment is queued.
625 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700626 enic_queue_wq_desc(wq, skb,
627 pci_map_single(enic->pdev, skb->data,
628 head_len, PCI_DMA_TODEVICE),
629 head_len,
630 vlan_tag_insert, vlan_tag,
631 eop);
632
633 if (!eop)
634 enic_queue_wq_skb_cont(enic, wq, skb, len_left);
635}
636
637static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
638 struct vnic_wq *wq, struct sk_buff *skb,
639 int vlan_tag_insert, unsigned int vlan_tag)
640{
641 unsigned int head_len = skb_headlen(skb);
642 unsigned int len_left = skb->len - head_len;
643 unsigned int hdr_len = skb_transport_offset(skb);
644 unsigned int csum_offset = hdr_len + skb->csum_offset;
645 int eop = (len_left == 0);
646
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000647 /* Queue the main skb fragment. The fragments are no larger
648 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
649 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
650 * per fragment is queued.
651 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700652 enic_queue_wq_desc_csum_l4(wq, skb,
653 pci_map_single(enic->pdev, skb->data,
654 head_len, PCI_DMA_TODEVICE),
655 head_len,
656 csum_offset,
657 hdr_len,
658 vlan_tag_insert, vlan_tag,
659 eop);
660
661 if (!eop)
662 enic_queue_wq_skb_cont(enic, wq, skb, len_left);
663}
664
665static inline void enic_queue_wq_skb_tso(struct enic *enic,
666 struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
667 int vlan_tag_insert, unsigned int vlan_tag)
668{
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000669 unsigned int frag_len_left = skb_headlen(skb);
670 unsigned int len_left = skb->len - frag_len_left;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700671 unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
672 int eop = (len_left == 0);
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000673 unsigned int len;
674 dma_addr_t dma_addr;
675 unsigned int offset = 0;
676 skb_frag_t *frag;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700677
678 /* Preload TCP csum field with IP pseudo hdr calculated
679 * with IP length set to zero. HW will later add in length
680 * to each TCP segment resulting from the TSO.
681 */
682
Harvey Harrison09640e632009-02-01 00:45:17 -0800683 if (skb->protocol == cpu_to_be16(ETH_P_IP)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700684 ip_hdr(skb)->check = 0;
685 tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
686 ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
Harvey Harrison09640e632009-02-01 00:45:17 -0800687 } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700688 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
689 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
690 }
691
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000692 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
693 * for the main skb fragment
694 */
695 while (frag_len_left) {
696 len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN);
697 dma_addr = pci_map_single(enic->pdev, skb->data + offset,
698 len, PCI_DMA_TODEVICE);
699 enic_queue_wq_desc_tso(wq, skb,
700 dma_addr,
701 len,
702 mss, hdr_len,
703 vlan_tag_insert, vlan_tag,
704 eop && (len == frag_len_left));
705 frag_len_left -= len;
706 offset += len;
707 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700708
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000709 if (eop)
710 return;
711
712 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
713 * for additional data fragments
714 */
715 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
716 len_left -= frag->size;
717 frag_len_left = frag->size;
718 offset = frag->page_offset;
719
720 while (frag_len_left) {
721 len = min(frag_len_left,
722 (unsigned int)WQ_ENET_MAX_DESC_LEN);
723 dma_addr = pci_map_page(enic->pdev, frag->page,
724 offset, len,
725 PCI_DMA_TODEVICE);
726 enic_queue_wq_desc_cont(wq, skb,
727 dma_addr,
728 len,
729 (len_left == 0) &&
730 (len == frag_len_left)); /* EOP? */
731 frag_len_left -= len;
732 offset += len;
733 }
734 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700735}
736
737static inline void enic_queue_wq_skb(struct enic *enic,
738 struct vnic_wq *wq, struct sk_buff *skb)
739{
740 unsigned int mss = skb_shinfo(skb)->gso_size;
741 unsigned int vlan_tag = 0;
742 int vlan_tag_insert = 0;
743
744 if (enic->vlan_group && vlan_tx_tag_present(skb)) {
745 /* VLAN tag from trunking driver */
746 vlan_tag_insert = 1;
747 vlan_tag = vlan_tx_tag_get(skb);
748 }
749
750 if (mss)
751 enic_queue_wq_skb_tso(enic, wq, skb, mss,
752 vlan_tag_insert, vlan_tag);
753 else if (skb->ip_summed == CHECKSUM_PARTIAL)
754 enic_queue_wq_skb_csum_l4(enic, wq, skb,
755 vlan_tag_insert, vlan_tag);
756 else
757 enic_queue_wq_skb_vlan(enic, wq, skb,
758 vlan_tag_insert, vlan_tag);
759}
760
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800761/* netif_tx_lock held, process context with BHs disabled, or BH */
Stephen Hemminger613573252009-08-31 19:50:58 +0000762static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb,
Scott Feldmand87fd252009-12-23 13:27:59 +0000763 struct net_device *netdev)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700764{
765 struct enic *enic = netdev_priv(netdev);
766 struct vnic_wq *wq = &enic->wq[0];
767 unsigned long flags;
768
769 if (skb->len <= 0) {
770 dev_kfree_skb(skb);
771 return NETDEV_TX_OK;
772 }
773
774 /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
775 * which is very likely. In the off chance it's going to take
776 * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
777 */
778
779 if (skb_shinfo(skb)->gso_size == 0 &&
780 skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
781 skb_linearize(skb)) {
782 dev_kfree_skb(skb);
783 return NETDEV_TX_OK;
784 }
785
786 spin_lock_irqsave(&enic->wq_lock[0], flags);
787
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000788 if (vnic_wq_desc_avail(wq) <
789 skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700790 netif_stop_queue(netdev);
791 /* This is a hard error, log it */
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000792 netdev_err(netdev, "BUG! Tx ring full when queue awake!\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700793 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
794 return NETDEV_TX_BUSY;
795 }
796
797 enic_queue_wq_skb(enic, wq, skb);
798
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000799 if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700800 netif_stop_queue(netdev);
801
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700802 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
803
804 return NETDEV_TX_OK;
805}
806
807/* dev_base_lock rwlock held, nominally process context */
808static struct net_device_stats *enic_get_stats(struct net_device *netdev)
809{
810 struct enic *enic = netdev_priv(netdev);
Scott Feldman25f0a062008-09-24 11:23:32 -0700811 struct net_device_stats *net_stats = &netdev->stats;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700812 struct vnic_stats *stats;
813
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000814 enic_dev_stats_dump(enic, &stats);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700815
Scott Feldman25f0a062008-09-24 11:23:32 -0700816 net_stats->tx_packets = stats->tx.tx_frames_ok;
817 net_stats->tx_bytes = stats->tx.tx_bytes_ok;
818 net_stats->tx_errors = stats->tx.tx_errors;
819 net_stats->tx_dropped = stats->tx.tx_drops;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700820
Scott Feldman25f0a062008-09-24 11:23:32 -0700821 net_stats->rx_packets = stats->rx.rx_frames_ok;
822 net_stats->rx_bytes = stats->rx.rx_bytes_ok;
823 net_stats->rx_errors = stats->rx.rx_errors;
824 net_stats->multicast = stats->rx.rx_multicast_frames_ok;
Scott Feldman350991e2009-09-03 17:02:19 +0000825 net_stats->rx_over_errors = enic->rq_truncated_pkts;
Scott Feldmanbd9fb1a2009-02-09 23:24:08 -0800826 net_stats->rx_crc_errors = enic->rq_bad_fcs;
Scott Feldman350991e2009-09-03 17:02:19 +0000827 net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700828
Scott Feldman25f0a062008-09-24 11:23:32 -0700829 return net_stats;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700830}
831
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +0000832static void enic_reset_multicast_list(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700833{
834 enic->mc_count = 0;
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +0000835 enic->flags = 0;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700836}
837
838static int enic_set_mac_addr(struct net_device *netdev, char *addr)
839{
Scott Feldmanf8bd9092010-05-17 22:50:19 -0700840 struct enic *enic = netdev_priv(netdev);
841
842 if (enic_is_dynamic(enic)) {
843 if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr))
844 return -EADDRNOTAVAIL;
845 } else {
846 if (!is_valid_ether_addr(addr))
847 return -EADDRNOTAVAIL;
848 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700849
850 memcpy(netdev->dev_addr, addr, netdev->addr_len);
851
852 return 0;
853}
854
Scott Feldmanf8bd9092010-05-17 22:50:19 -0700855static int enic_dev_add_station_addr(struct enic *enic)
856{
857 int err = 0;
858
859 if (is_valid_ether_addr(enic->netdev->dev_addr)) {
860 spin_lock(&enic->devcmd_lock);
861 err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
862 spin_unlock(&enic->devcmd_lock);
863 }
864
865 return err;
866}
867
868static int enic_dev_del_station_addr(struct enic *enic)
869{
870 int err = 0;
871
872 if (is_valid_ether_addr(enic->netdev->dev_addr)) {
873 spin_lock(&enic->devcmd_lock);
874 err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
875 spin_unlock(&enic->devcmd_lock);
876 }
877
878 return err;
879}
880
881static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
882{
883 struct enic *enic = netdev_priv(netdev);
884 struct sockaddr *saddr = p;
885 char *addr = saddr->sa_data;
886 int err;
887
888 if (netif_running(enic->netdev)) {
889 err = enic_dev_del_station_addr(enic);
890 if (err)
891 return err;
892 }
893
894 err = enic_set_mac_addr(netdev, addr);
895 if (err)
896 return err;
897
898 if (netif_running(enic->netdev)) {
899 err = enic_dev_add_station_addr(enic);
900 if (err)
901 return err;
902 }
903
904 return err;
905}
906
907static int enic_set_mac_address(struct net_device *netdev, void *p)
908{
909 return -EOPNOTSUPP;
910}
911
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000912static int enic_dev_packet_filter(struct enic *enic, int directed,
913 int multicast, int broadcast, int promisc, int allmulti)
914{
915 int err;
916
917 spin_lock(&enic->devcmd_lock);
918 err = vnic_dev_packet_filter(enic->vdev, directed,
919 multicast, broadcast, promisc, allmulti);
920 spin_unlock(&enic->devcmd_lock);
921
922 return err;
923}
924
925static int enic_dev_add_multicast_addr(struct enic *enic, u8 *addr)
926{
927 int err;
928
929 spin_lock(&enic->devcmd_lock);
930 err = vnic_dev_add_addr(enic->vdev, addr);
931 spin_unlock(&enic->devcmd_lock);
932
933 return err;
934}
935
936static int enic_dev_del_multicast_addr(struct enic *enic, u8 *addr)
937{
938 int err;
939
940 spin_lock(&enic->devcmd_lock);
941 err = vnic_dev_del_addr(enic->vdev, addr);
942 spin_unlock(&enic->devcmd_lock);
943
944 return err;
945}
946
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700947/* netif_tx_lock held, BHs disabled */
948static void enic_set_multicast_list(struct net_device *netdev)
949{
950 struct enic *enic = netdev_priv(netdev);
Jiri Pirko22bedad32010-04-01 21:22:57 +0000951 struct netdev_hw_addr *ha;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700952 int directed = 1;
953 int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
954 int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
955 int promisc = (netdev->flags & IFF_PROMISC) ? 1 : 0;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +0000956 unsigned int mc_count = netdev_mc_count(netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700957 int allmulti = (netdev->flags & IFF_ALLMULTI) ||
Vasanthy Kolluri641cb852010-03-18 16:20:04 +0000958 mc_count > ENIC_MULTICAST_PERFECT_FILTERS;
Scott Feldman9959a182009-12-23 13:27:43 +0000959 unsigned int flags = netdev->flags | (allmulti ? IFF_ALLMULTI : 0);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700960 u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700961 unsigned int i, j;
962
963 if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
964 mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
965
Scott Feldman9959a182009-12-23 13:27:43 +0000966 if (enic->flags != flags) {
967 enic->flags = flags;
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000968 enic_dev_packet_filter(enic, directed,
Scott Feldman9959a182009-12-23 13:27:43 +0000969 multicast, broadcast, promisc, allmulti);
970 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700971
972 /* Is there an easier way? Trying to minimize to
973 * calls to add/del multicast addrs. We keep the
974 * addrs from the last call in enic->mc_addr and
975 * look for changes to add/del.
976 */
977
Jiri Pirko48e2f182010-02-22 09:22:26 +0000978 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000979 netdev_for_each_mc_addr(ha, netdev) {
Jiri Pirko48e2f182010-02-22 09:22:26 +0000980 if (i == mc_count)
981 break;
Jiri Pirko22bedad32010-04-01 21:22:57 +0000982 memcpy(mc_addr[i++], ha->addr, ETH_ALEN);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700983 }
984
985 for (i = 0; i < enic->mc_count; i++) {
986 for (j = 0; j < mc_count; j++)
987 if (compare_ether_addr(enic->mc_addr[i],
988 mc_addr[j]) == 0)
989 break;
990 if (j == mc_count)
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000991 enic_dev_del_multicast_addr(enic, enic->mc_addr[i]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700992 }
993
994 for (i = 0; i < mc_count; i++) {
995 for (j = 0; j < enic->mc_count; j++)
996 if (compare_ether_addr(mc_addr[i],
997 enic->mc_addr[j]) == 0)
998 break;
999 if (j == enic->mc_count)
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001000 enic_dev_add_multicast_addr(enic, mc_addr[i]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001001 }
1002
1003 /* Save the list to compare against next time
1004 */
1005
1006 for (i = 0; i < mc_count; i++)
1007 memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
1008
1009 enic->mc_count = mc_count;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001010}
1011
1012/* rtnl lock is held */
1013static void enic_vlan_rx_register(struct net_device *netdev,
1014 struct vlan_group *vlan_group)
1015{
1016 struct enic *enic = netdev_priv(netdev);
1017 enic->vlan_group = vlan_group;
1018}
1019
1020/* rtnl lock is held */
1021static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1022{
1023 struct enic *enic = netdev_priv(netdev);
1024
1025 spin_lock(&enic->devcmd_lock);
1026 enic_add_vlan(enic, vid);
1027 spin_unlock(&enic->devcmd_lock);
1028}
1029
1030/* rtnl lock is held */
1031static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1032{
1033 struct enic *enic = netdev_priv(netdev);
1034
1035 spin_lock(&enic->devcmd_lock);
1036 enic_del_vlan(enic, vid);
1037 spin_unlock(&enic->devcmd_lock);
1038}
1039
1040/* netif_tx_lock held, BHs disabled */
1041static void enic_tx_timeout(struct net_device *netdev)
1042{
1043 struct enic *enic = netdev_priv(netdev);
1044 schedule_work(&enic->reset);
1045}
1046
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001047static int enic_vnic_dev_deinit(struct enic *enic)
1048{
1049 int err;
1050
1051 spin_lock(&enic->devcmd_lock);
1052 err = vnic_dev_deinit(enic->vdev);
1053 spin_unlock(&enic->devcmd_lock);
1054
1055 return err;
1056}
1057
1058static int enic_dev_init_prov(struct enic *enic, struct vic_provinfo *vp)
1059{
1060 int err;
1061
1062 spin_lock(&enic->devcmd_lock);
1063 err = vnic_dev_init_prov(enic->vdev,
1064 (u8 *)vp, vic_provinfo_size(vp));
1065 spin_unlock(&enic->devcmd_lock);
1066
1067 return err;
1068}
1069
1070static int enic_dev_init_done(struct enic *enic, int *done, int *error)
1071{
1072 int err;
1073
1074 spin_lock(&enic->devcmd_lock);
1075 err = vnic_dev_init_done(enic->vdev, done, error);
1076 spin_unlock(&enic->devcmd_lock);
1077
1078 return err;
1079}
1080
Scott Feldman08f382e2010-06-01 08:59:33 +00001081static int enic_set_port_profile(struct enic *enic, u8 *mac)
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001082{
1083 struct vic_provinfo *vp;
1084 u8 oui[3] = VIC_PROVINFO_CISCO_OUI;
Scott Feldman6fc7f572010-05-22 17:29:52 +00001085 u8 *uuid;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001086 char uuid_str[38];
Scott Feldman6fc7f572010-05-22 17:29:52 +00001087 static char *uuid_fmt = "%02X%02X%02X%02X-%02X%02X-%02X%02X-"
1088 "%02X%02X-%02X%02X%02X%02X%0X%02X";
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001089 int err;
1090
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001091 err = enic_vnic_dev_deinit(enic);
1092 if (err)
Scott Feldman08f382e2010-06-01 08:59:33 +00001093 return err;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001094
Scott Feldman08f382e2010-06-01 08:59:33 +00001095 switch (enic->pp.request) {
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001096
Scott Feldman08f382e2010-06-01 08:59:33 +00001097 case PORT_REQUEST_ASSOCIATE:
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001098
Scott Feldman08f382e2010-06-01 08:59:33 +00001099 if (!(enic->pp.set & ENIC_SET_NAME) || !strlen(enic->pp.name))
1100 return -EINVAL;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001101
Scott Feldman08f382e2010-06-01 08:59:33 +00001102 if (!is_valid_ether_addr(mac))
1103 return -EADDRNOTAVAIL;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001104
Scott Feldman08f382e2010-06-01 08:59:33 +00001105 vp = vic_provinfo_alloc(GFP_KERNEL, oui,
1106 VIC_PROVINFO_LINUX_TYPE);
1107 if (!vp)
1108 return -ENOMEM;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001109
Scott Feldman08f382e2010-06-01 08:59:33 +00001110 vic_provinfo_add_tlv(vp,
1111 VIC_LINUX_PROV_TLV_PORT_PROFILE_NAME_STR,
1112 strlen(enic->pp.name) + 1, enic->pp.name);
1113
1114 vic_provinfo_add_tlv(vp,
1115 VIC_LINUX_PROV_TLV_CLIENT_MAC_ADDR,
1116 ETH_ALEN, mac);
1117
1118 if (enic->pp.set & ENIC_SET_INSTANCE) {
1119 uuid = enic->pp.instance_uuid;
1120 sprintf(uuid_str, uuid_fmt,
1121 uuid[0], uuid[1], uuid[2], uuid[3],
1122 uuid[4], uuid[5], uuid[6], uuid[7],
1123 uuid[8], uuid[9], uuid[10], uuid[11],
1124 uuid[12], uuid[13], uuid[14], uuid[15]);
1125 vic_provinfo_add_tlv(vp,
1126 VIC_LINUX_PROV_TLV_CLIENT_UUID_STR,
1127 sizeof(uuid_str), uuid_str);
1128 }
1129
1130 if (enic->pp.set & ENIC_SET_HOST) {
1131 uuid = enic->pp.host_uuid;
1132 sprintf(uuid_str, uuid_fmt,
1133 uuid[0], uuid[1], uuid[2], uuid[3],
1134 uuid[4], uuid[5], uuid[6], uuid[7],
1135 uuid[8], uuid[9], uuid[10], uuid[11],
1136 uuid[12], uuid[13], uuid[14], uuid[15]);
1137 vic_provinfo_add_tlv(vp,
1138 VIC_LINUX_PROV_TLV_HOST_UUID_STR,
1139 sizeof(uuid_str), uuid_str);
1140 }
1141
1142 err = enic_dev_init_prov(enic, vp);
1143 vic_provinfo_free(vp);
1144 if (err)
1145 return err;
1146 break;
1147
1148 case PORT_REQUEST_DISASSOCIATE:
1149 break;
1150
1151 default:
1152 return -EINVAL;
1153 }
1154
1155 enic->pp.set |= ENIC_SET_APPLIED;
1156 return 0;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001157}
1158
1159static int enic_set_vf_port(struct net_device *netdev, int vf,
1160 struct nlattr *port[])
1161{
1162 struct enic *enic = netdev_priv(netdev);
Scott Feldman08f382e2010-06-01 08:59:33 +00001163
1164 memset(&enic->pp, 0, sizeof(enic->pp));
1165
1166 if (port[IFLA_PORT_REQUEST]) {
1167 enic->pp.set |= ENIC_SET_REQUEST;
1168 enic->pp.request = nla_get_u8(port[IFLA_PORT_REQUEST]);
1169 }
1170
1171 if (port[IFLA_PORT_PROFILE]) {
1172 enic->pp.set |= ENIC_SET_NAME;
1173 memcpy(enic->pp.name, nla_data(port[IFLA_PORT_PROFILE]),
1174 PORT_PROFILE_MAX);
1175 }
1176
1177 if (port[IFLA_PORT_INSTANCE_UUID]) {
1178 enic->pp.set |= ENIC_SET_INSTANCE;
1179 memcpy(enic->pp.instance_uuid,
1180 nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX);
1181 }
1182
1183 if (port[IFLA_PORT_HOST_UUID]) {
1184 enic->pp.set |= ENIC_SET_HOST;
1185 memcpy(enic->pp.host_uuid,
1186 nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX);
1187 }
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001188
1189 /* don't support VFs, yet */
1190 if (vf != PORT_SELF_VF)
1191 return -EOPNOTSUPP;
1192
Scott Feldman08f382e2010-06-01 08:59:33 +00001193 if (!(enic->pp.set & ENIC_SET_REQUEST))
1194 return -EOPNOTSUPP;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001195
Scott Feldman08f382e2010-06-01 08:59:33 +00001196 if (enic->pp.request == PORT_REQUEST_ASSOCIATE) {
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001197
Scott Feldman418c4372010-05-22 17:29:58 +00001198 /* If the interface mac addr hasn't been assigned,
1199 * assign a random mac addr before setting port-
1200 * profile.
1201 */
1202
1203 if (is_zero_ether_addr(netdev->dev_addr))
1204 random_ether_addr(netdev->dev_addr);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001205 }
1206
Scott Feldman08f382e2010-06-01 08:59:33 +00001207 return enic_set_port_profile(enic, netdev->dev_addr);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001208}
1209
1210static int enic_get_vf_port(struct net_device *netdev, int vf,
1211 struct sk_buff *skb)
1212{
1213 struct enic *enic = netdev_priv(netdev);
1214 int err, error, done;
1215 u16 response = PORT_PROFILE_RESPONSE_SUCCESS;
1216
Scott Feldman08f382e2010-06-01 08:59:33 +00001217 if (!(enic->pp.set & ENIC_SET_APPLIED))
1218 return -ENODATA;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001219
1220 err = enic_dev_init_done(enic, &done, &error);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001221 if (err)
Scott Feldman08f382e2010-06-01 08:59:33 +00001222 error = err;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001223
1224 switch (error) {
1225 case ERR_SUCCESS:
1226 if (!done)
1227 response = PORT_PROFILE_RESPONSE_INPROGRESS;
1228 break;
1229 case ERR_EINVAL:
1230 response = PORT_PROFILE_RESPONSE_INVALID;
1231 break;
1232 case ERR_EBADSTATE:
1233 response = PORT_PROFILE_RESPONSE_BADSTATE;
1234 break;
1235 case ERR_ENOMEM:
1236 response = PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES;
1237 break;
1238 default:
1239 response = PORT_PROFILE_RESPONSE_ERROR;
1240 break;
1241 }
1242
1243 NLA_PUT_U16(skb, IFLA_PORT_REQUEST, enic->pp.request);
1244 NLA_PUT_U16(skb, IFLA_PORT_RESPONSE, response);
Scott Feldman08f382e2010-06-01 08:59:33 +00001245 if (enic->pp.set & ENIC_SET_NAME)
1246 NLA_PUT(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX,
1247 enic->pp.name);
1248 if (enic->pp.set & ENIC_SET_INSTANCE)
1249 NLA_PUT(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX,
1250 enic->pp.instance_uuid);
1251 if (enic->pp.set & ENIC_SET_HOST)
1252 NLA_PUT(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX,
1253 enic->pp.host_uuid);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001254
1255 return 0;
1256
1257nla_put_failure:
1258 return -EMSGSIZE;
1259}
1260
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001261static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
1262{
1263 struct enic *enic = vnic_dev_priv(rq->vdev);
1264
1265 if (!buf->os_buf)
1266 return;
1267
1268 pci_unmap_single(enic->pdev, buf->dma_addr,
1269 buf->len, PCI_DMA_FROMDEVICE);
1270 dev_kfree_skb_any(buf->os_buf);
1271}
1272
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001273static int enic_rq_alloc_buf(struct vnic_rq *rq)
1274{
1275 struct enic *enic = vnic_dev_priv(rq->vdev);
Scott Feldmand19e22d2009-09-03 17:02:08 +00001276 struct net_device *netdev = enic->netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001277 struct sk_buff *skb;
Scott Feldmand19e22d2009-09-03 17:02:08 +00001278 unsigned int len = netdev->mtu + ETH_HLEN;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001279 unsigned int os_buf_index = 0;
1280 dma_addr_t dma_addr;
1281
Eric Dumazet89d71a62009-10-13 05:34:20 +00001282 skb = netdev_alloc_skb_ip_align(netdev, len);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001283 if (!skb)
1284 return -ENOMEM;
1285
1286 dma_addr = pci_map_single(enic->pdev, skb->data,
1287 len, PCI_DMA_FROMDEVICE);
1288
1289 enic_queue_rq_desc(rq, skb, os_buf_index,
1290 dma_addr, len);
1291
1292 return 0;
1293}
1294
Scott Feldman4badc382009-09-03 17:01:58 +00001295static int enic_rq_alloc_buf_a1(struct vnic_rq *rq)
1296{
1297 struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
1298
1299 if (vnic_rq_posting_soon(rq)) {
1300
1301 /* SW workaround for A0 HW erratum: if we're just about
1302 * to write posted_index, insert a dummy desc
1303 * of type resvd
1304 */
1305
1306 rq_enet_desc_enc(desc, 0, RQ_ENET_TYPE_RESV2, 0);
1307 vnic_rq_post(rq, 0, 0, 0, 0);
1308 } else {
1309 return enic_rq_alloc_buf(rq);
1310 }
1311
1312 return 0;
1313}
1314
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001315static int enic_dev_hw_version(struct enic *enic,
1316 enum vnic_dev_hw_version *hw_ver)
1317{
1318 int err;
1319
1320 spin_lock(&enic->devcmd_lock);
1321 err = vnic_dev_hw_version(enic->vdev, hw_ver);
1322 spin_unlock(&enic->devcmd_lock);
1323
1324 return err;
1325}
1326
Scott Feldman4badc382009-09-03 17:01:58 +00001327static int enic_set_rq_alloc_buf(struct enic *enic)
1328{
1329 enum vnic_dev_hw_version hw_ver;
1330 int err;
1331
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001332 err = enic_dev_hw_version(enic, &hw_ver);
Scott Feldman4badc382009-09-03 17:01:58 +00001333 if (err)
1334 return err;
1335
1336 switch (hw_ver) {
1337 case VNIC_DEV_HW_VER_A1:
1338 enic->rq_alloc_buf = enic_rq_alloc_buf_a1;
1339 break;
1340 case VNIC_DEV_HW_VER_A2:
1341 case VNIC_DEV_HW_VER_UNKNOWN:
1342 enic->rq_alloc_buf = enic_rq_alloc_buf;
1343 break;
1344 default:
1345 return -ENODEV;
1346 }
1347
1348 return 0;
1349}
1350
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001351static void enic_rq_indicate_buf(struct vnic_rq *rq,
1352 struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
1353 int skipped, void *opaque)
1354{
1355 struct enic *enic = vnic_dev_priv(rq->vdev);
Scott Feldman86ca9db2008-11-21 21:26:55 -08001356 struct net_device *netdev = enic->netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001357 struct sk_buff *skb;
1358
1359 u8 type, color, eop, sop, ingress_port, vlan_stripped;
1360 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
1361 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
1362 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
1363 u8 packet_error;
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001364 u16 q_number, completed_index, bytes_written, vlan_tci, checksum;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001365 u32 rss_hash;
1366
1367 if (skipped)
1368 return;
1369
1370 skb = buf->os_buf;
1371 prefetch(skb->data - NET_IP_ALIGN);
1372 pci_unmap_single(enic->pdev, buf->dma_addr,
1373 buf->len, PCI_DMA_FROMDEVICE);
1374
1375 cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
1376 &type, &color, &q_number, &completed_index,
1377 &ingress_port, &fcoe, &eop, &sop, &rss_type,
1378 &csum_not_calc, &rss_hash, &bytes_written,
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001379 &packet_error, &vlan_stripped, &vlan_tci, &checksum,
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001380 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
1381 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
1382 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
1383 &fcs_ok);
1384
1385 if (packet_error) {
1386
Scott Feldman350991e2009-09-03 17:02:19 +00001387 if (!fcs_ok) {
1388 if (bytes_written > 0)
1389 enic->rq_bad_fcs++;
1390 else if (bytes_written == 0)
1391 enic->rq_truncated_pkts++;
1392 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001393
1394 dev_kfree_skb_any(skb);
1395
1396 return;
1397 }
1398
1399 if (eop && bytes_written > 0) {
1400
1401 /* Good receive
1402 */
1403
1404 skb_put(skb, bytes_written);
Scott Feldman86ca9db2008-11-21 21:26:55 -08001405 skb->protocol = eth_type_trans(skb, netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001406
1407 if (enic->csum_rx_enabled && !csum_not_calc) {
1408 skb->csum = htons(checksum);
1409 skb->ip_summed = CHECKSUM_COMPLETE;
1410 }
1411
Scott Feldman86ca9db2008-11-21 21:26:55 -08001412 skb->dev = netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001413
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001414 if (enic->vlan_group && vlan_stripped &&
1415 (vlan_tci & CQ_ENET_RQ_DESC_VLAN_TCI_VLAN_MASK)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001416
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001417 if (netdev->features & NETIF_F_GRO)
1418 vlan_gro_receive(&enic->napi, enic->vlan_group,
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001419 vlan_tci, skb);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001420 else
1421 vlan_hwaccel_receive_skb(skb,
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001422 enic->vlan_group, vlan_tci);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001423
1424 } else {
1425
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001426 if (netdev->features & NETIF_F_GRO)
1427 napi_gro_receive(&enic->napi, skb);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001428 else
1429 netif_receive_skb(skb);
1430
1431 }
1432
1433 } else {
1434
1435 /* Buffer overflow
1436 */
1437
1438 dev_kfree_skb_any(skb);
1439 }
1440}
1441
1442static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
1443 u8 type, u16 q_number, u16 completed_index, void *opaque)
1444{
1445 struct enic *enic = vnic_dev_priv(vdev);
1446
1447 vnic_rq_service(&enic->rq[q_number], cq_desc,
1448 completed_index, VNIC_RQ_RETURN_DESC,
1449 enic_rq_indicate_buf, opaque);
1450
1451 return 0;
1452}
1453
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001454static int enic_poll(struct napi_struct *napi, int budget)
1455{
1456 struct enic *enic = container_of(napi, struct enic, napi);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001457 unsigned int rq_work_to_do = budget;
1458 unsigned int wq_work_to_do = -1; /* no limit */
1459 unsigned int work_done, rq_work_done, wq_work_done;
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001460 int err;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001461
1462 /* Service RQ (first) and WQ
1463 */
1464
1465 rq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
1466 rq_work_to_do, enic_rq_service, NULL);
1467
1468 wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
1469 wq_work_to_do, enic_wq_service, NULL);
1470
1471 /* Accumulate intr event credits for this polling
1472 * cycle. An intr event is the completion of a
1473 * a WQ or RQ packet.
1474 */
1475
1476 work_done = rq_work_done + wq_work_done;
1477
1478 if (work_done > 0)
1479 vnic_intr_return_credits(&enic->intr[ENIC_INTX_WQ_RQ],
1480 work_done,
1481 0 /* don't unmask intr */,
1482 0 /* don't reset intr timer */);
1483
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001484 err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001485
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001486 /* Buffer allocation failed. Stay in polling
1487 * mode so we can try to fill the ring again.
1488 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001489
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001490 if (err)
1491 rq_work_done = rq_work_to_do;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001492
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001493 if (rq_work_done < rq_work_to_do) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001494
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001495 /* Some work done, but not enough to stay in polling,
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001496 * exit polling
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001497 */
1498
Ben Hutchings288379f2009-01-19 16:43:59 -08001499 napi_complete(napi);
Scott Feldmaned8af6b2009-02-09 23:23:50 -08001500 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001501 }
1502
1503 return rq_work_done;
1504}
1505
1506static int enic_poll_msix(struct napi_struct *napi, int budget)
1507{
1508 struct enic *enic = container_of(napi, struct enic, napi);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001509 unsigned int work_to_do = budget;
1510 unsigned int work_done;
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001511 int err;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001512
1513 /* Service RQ
1514 */
1515
1516 work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
1517 work_to_do, enic_rq_service, NULL);
1518
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001519 /* Return intr event credits for this polling
1520 * cycle. An intr event is the completion of a
1521 * RQ packet.
1522 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001523
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001524 if (work_done > 0)
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001525 vnic_intr_return_credits(&enic->intr[ENIC_MSIX_RQ],
1526 work_done,
1527 0 /* don't unmask intr */,
1528 0 /* don't reset intr timer */);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001529
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001530 err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
1531
1532 /* Buffer allocation failed. Stay in polling mode
1533 * so we can try to fill the ring again.
1534 */
1535
1536 if (err)
1537 work_done = work_to_do;
1538
1539 if (work_done < work_to_do) {
1540
1541 /* Some work done, but not enough to stay in polling,
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001542 * exit polling
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001543 */
1544
Ben Hutchings288379f2009-01-19 16:43:59 -08001545 napi_complete(napi);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001546 vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
1547 }
1548
1549 return work_done;
1550}
1551
1552static void enic_notify_timer(unsigned long data)
1553{
1554 struct enic *enic = (struct enic *)data;
1555
1556 enic_notify_check(enic);
1557
Scott Feldman25f0a062008-09-24 11:23:32 -07001558 mod_timer(&enic->notify_timer,
1559 round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001560}
1561
1562static void enic_free_intr(struct enic *enic)
1563{
1564 struct net_device *netdev = enic->netdev;
1565 unsigned int i;
1566
1567 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1568 case VNIC_DEV_INTR_MODE_INTX:
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001569 free_irq(enic->pdev->irq, netdev);
1570 break;
Scott Feldman8f4d2482008-09-24 11:23:42 -07001571 case VNIC_DEV_INTR_MODE_MSI:
1572 free_irq(enic->pdev->irq, enic);
1573 break;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001574 case VNIC_DEV_INTR_MODE_MSIX:
1575 for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
1576 if (enic->msix[i].requested)
1577 free_irq(enic->msix_entry[i].vector,
1578 enic->msix[i].devid);
1579 break;
1580 default:
1581 break;
1582 }
1583}
1584
1585static int enic_request_intr(struct enic *enic)
1586{
1587 struct net_device *netdev = enic->netdev;
1588 unsigned int i;
1589 int err = 0;
1590
1591 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1592
1593 case VNIC_DEV_INTR_MODE_INTX:
1594
1595 err = request_irq(enic->pdev->irq, enic_isr_legacy,
1596 IRQF_SHARED, netdev->name, netdev);
1597 break;
1598
1599 case VNIC_DEV_INTR_MODE_MSI:
1600
1601 err = request_irq(enic->pdev->irq, enic_isr_msi,
1602 0, netdev->name, enic);
1603 break;
1604
1605 case VNIC_DEV_INTR_MODE_MSIX:
1606
1607 sprintf(enic->msix[ENIC_MSIX_RQ].devname,
Scott Feldman8f4d2482008-09-24 11:23:42 -07001608 "%.11s-rx-0", netdev->name);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001609 enic->msix[ENIC_MSIX_RQ].isr = enic_isr_msix_rq;
1610 enic->msix[ENIC_MSIX_RQ].devid = enic;
1611
1612 sprintf(enic->msix[ENIC_MSIX_WQ].devname,
Scott Feldman8f4d2482008-09-24 11:23:42 -07001613 "%.11s-tx-0", netdev->name);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001614 enic->msix[ENIC_MSIX_WQ].isr = enic_isr_msix_wq;
1615 enic->msix[ENIC_MSIX_WQ].devid = enic;
1616
1617 sprintf(enic->msix[ENIC_MSIX_ERR].devname,
1618 "%.11s-err", netdev->name);
1619 enic->msix[ENIC_MSIX_ERR].isr = enic_isr_msix_err;
1620 enic->msix[ENIC_MSIX_ERR].devid = enic;
1621
1622 sprintf(enic->msix[ENIC_MSIX_NOTIFY].devname,
1623 "%.11s-notify", netdev->name);
1624 enic->msix[ENIC_MSIX_NOTIFY].isr = enic_isr_msix_notify;
1625 enic->msix[ENIC_MSIX_NOTIFY].devid = enic;
1626
1627 for (i = 0; i < ARRAY_SIZE(enic->msix); i++) {
1628 err = request_irq(enic->msix_entry[i].vector,
1629 enic->msix[i].isr, 0,
1630 enic->msix[i].devname,
1631 enic->msix[i].devid);
1632 if (err) {
1633 enic_free_intr(enic);
1634 break;
1635 }
1636 enic->msix[i].requested = 1;
1637 }
1638
1639 break;
1640
1641 default:
1642 break;
1643 }
1644
1645 return err;
1646}
1647
Scott Feldmanb3d18d12009-12-23 13:27:30 +00001648static void enic_synchronize_irqs(struct enic *enic)
1649{
1650 unsigned int i;
1651
1652 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1653 case VNIC_DEV_INTR_MODE_INTX:
1654 case VNIC_DEV_INTR_MODE_MSI:
1655 synchronize_irq(enic->pdev->irq);
1656 break;
1657 case VNIC_DEV_INTR_MODE_MSIX:
1658 for (i = 0; i < enic->intr_count; i++)
1659 synchronize_irq(enic->msix_entry[i].vector);
1660 break;
1661 default:
1662 break;
1663 }
1664}
1665
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001666static int enic_dev_notify_set(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001667{
1668 int err;
1669
Scott Feldman56ac88b2009-09-03 17:02:14 +00001670 spin_lock(&enic->devcmd_lock);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001671 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1672 case VNIC_DEV_INTR_MODE_INTX:
1673 err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY);
1674 break;
1675 case VNIC_DEV_INTR_MODE_MSIX:
1676 err = vnic_dev_notify_set(enic->vdev, ENIC_MSIX_NOTIFY);
1677 break;
1678 default:
1679 err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
1680 break;
1681 }
Scott Feldman56ac88b2009-09-03 17:02:14 +00001682 spin_unlock(&enic->devcmd_lock);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001683
1684 return err;
1685}
1686
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001687static int enic_dev_notify_unset(struct enic *enic)
1688{
1689 int err;
1690
1691 spin_lock(&enic->devcmd_lock);
1692 err = vnic_dev_notify_unset(enic->vdev);
1693 spin_unlock(&enic->devcmd_lock);
1694
1695 return err;
1696}
1697
1698static int enic_dev_enable(struct enic *enic)
1699{
1700 int err;
1701
1702 spin_lock(&enic->devcmd_lock);
1703 err = vnic_dev_enable(enic->vdev);
1704 spin_unlock(&enic->devcmd_lock);
1705
1706 return err;
1707}
1708
1709static int enic_dev_disable(struct enic *enic)
1710{
1711 int err;
1712
1713 spin_lock(&enic->devcmd_lock);
1714 err = vnic_dev_disable(enic->vdev);
1715 spin_unlock(&enic->devcmd_lock);
1716
1717 return err;
1718}
1719
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001720static void enic_notify_timer_start(struct enic *enic)
1721{
1722 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1723 case VNIC_DEV_INTR_MODE_MSI:
1724 mod_timer(&enic->notify_timer, jiffies);
1725 break;
1726 default:
1727 /* Using intr for notification for INTx/MSI-X */
1728 break;
1729 };
1730}
1731
1732/* rtnl lock is held, process context */
1733static int enic_open(struct net_device *netdev)
1734{
1735 struct enic *enic = netdev_priv(netdev);
1736 unsigned int i;
1737 int err;
1738
Scott Feldman4b75a442008-09-24 11:23:53 -07001739 err = enic_request_intr(enic);
1740 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001741 netdev_err(netdev, "Unable to request irq.\n");
Scott Feldman4b75a442008-09-24 11:23:53 -07001742 return err;
1743 }
1744
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001745 err = enic_dev_notify_set(enic);
Scott Feldman4b75a442008-09-24 11:23:53 -07001746 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001747 netdev_err(netdev,
1748 "Failed to alloc notify buffer, aborting.\n");
Scott Feldman4b75a442008-09-24 11:23:53 -07001749 goto err_out_free_intr;
1750 }
1751
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001752 for (i = 0; i < enic->rq_count; i++) {
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001753 vnic_rq_fill(&enic->rq[i], enic->rq_alloc_buf);
1754 /* Need at least one buffer on ring to get going */
1755 if (vnic_rq_desc_used(&enic->rq[i]) == 0) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001756 netdev_err(netdev, "Unable to alloc receive buffers\n");
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001757 err = -ENOMEM;
Scott Feldman4b75a442008-09-24 11:23:53 -07001758 goto err_out_notify_unset;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001759 }
1760 }
1761
1762 for (i = 0; i < enic->wq_count; i++)
1763 vnic_wq_enable(&enic->wq[i]);
1764 for (i = 0; i < enic->rq_count; i++)
1765 vnic_rq_enable(&enic->rq[i]);
1766
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001767 enic_dev_add_station_addr(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001768 enic_set_multicast_list(netdev);
1769
1770 netif_wake_queue(netdev);
1771 napi_enable(&enic->napi);
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001772 enic_dev_enable(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001773
1774 for (i = 0; i < enic->intr_count; i++)
1775 vnic_intr_unmask(&enic->intr[i]);
1776
1777 enic_notify_timer_start(enic);
1778
1779 return 0;
Scott Feldman4b75a442008-09-24 11:23:53 -07001780
1781err_out_notify_unset:
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001782 enic_dev_notify_unset(enic);
Scott Feldman4b75a442008-09-24 11:23:53 -07001783err_out_free_intr:
1784 enic_free_intr(enic);
1785
1786 return err;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001787}
1788
1789/* rtnl lock is held, process context */
1790static int enic_stop(struct net_device *netdev)
1791{
1792 struct enic *enic = netdev_priv(netdev);
1793 unsigned int i;
1794 int err;
1795
Scott Feldmanb3d18d12009-12-23 13:27:30 +00001796 for (i = 0; i < enic->intr_count; i++)
1797 vnic_intr_mask(&enic->intr[i]);
1798
1799 enic_synchronize_irqs(enic);
1800
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001801 del_timer_sync(&enic->notify_timer);
1802
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001803 enic_dev_disable(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001804 napi_disable(&enic->napi);
Scott Feldmanb3d18d12009-12-23 13:27:30 +00001805 netif_carrier_off(netdev);
1806 netif_tx_disable(netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001807
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001808 enic_dev_del_station_addr(enic);
1809
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001810 for (i = 0; i < enic->wq_count; i++) {
1811 err = vnic_wq_disable(&enic->wq[i]);
1812 if (err)
1813 return err;
1814 }
1815 for (i = 0; i < enic->rq_count; i++) {
1816 err = vnic_rq_disable(&enic->rq[i]);
1817 if (err)
1818 return err;
1819 }
1820
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001821 enic_dev_notify_unset(enic);
Scott Feldman4b75a442008-09-24 11:23:53 -07001822 enic_free_intr(enic);
1823
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001824 for (i = 0; i < enic->wq_count; i++)
1825 vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
1826 for (i = 0; i < enic->rq_count; i++)
1827 vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
1828 for (i = 0; i < enic->cq_count; i++)
1829 vnic_cq_clean(&enic->cq[i]);
1830 for (i = 0; i < enic->intr_count; i++)
1831 vnic_intr_clean(&enic->intr[i]);
1832
1833 return 0;
1834}
1835
1836static int enic_change_mtu(struct net_device *netdev, int new_mtu)
1837{
1838 struct enic *enic = netdev_priv(netdev);
1839 int running = netif_running(netdev);
1840
Scott Feldman25f0a062008-09-24 11:23:32 -07001841 if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
1842 return -EINVAL;
1843
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001844 if (running)
1845 enic_stop(netdev);
1846
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001847 netdev->mtu = new_mtu;
1848
1849 if (netdev->mtu > enic->port_mtu)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001850 netdev_warn(netdev,
1851 "interface MTU (%d) set higher than port MTU (%d)\n",
1852 netdev->mtu, enic->port_mtu);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001853
1854 if (running)
1855 enic_open(netdev);
1856
1857 return 0;
1858}
1859
1860#ifdef CONFIG_NET_POLL_CONTROLLER
1861static void enic_poll_controller(struct net_device *netdev)
1862{
1863 struct enic *enic = netdev_priv(netdev);
1864 struct vnic_dev *vdev = enic->vdev;
1865
1866 switch (vnic_dev_get_intr_mode(vdev)) {
1867 case VNIC_DEV_INTR_MODE_MSIX:
1868 enic_isr_msix_rq(enic->pdev->irq, enic);
1869 enic_isr_msix_wq(enic->pdev->irq, enic);
1870 break;
1871 case VNIC_DEV_INTR_MODE_MSI:
1872 enic_isr_msi(enic->pdev->irq, enic);
1873 break;
1874 case VNIC_DEV_INTR_MODE_INTX:
1875 enic_isr_legacy(enic->pdev->irq, netdev);
1876 break;
1877 default:
1878 break;
1879 }
1880}
1881#endif
1882
1883static int enic_dev_wait(struct vnic_dev *vdev,
1884 int (*start)(struct vnic_dev *, int),
1885 int (*finished)(struct vnic_dev *, int *),
1886 int arg)
1887{
1888 unsigned long time;
1889 int done;
1890 int err;
1891
1892 BUG_ON(in_interrupt());
1893
1894 err = start(vdev, arg);
1895 if (err)
1896 return err;
1897
1898 /* Wait for func to complete...2 seconds max
1899 */
1900
1901 time = jiffies + (HZ * 2);
1902 do {
1903
1904 err = finished(vdev, &done);
1905 if (err)
1906 return err;
1907
1908 if (done)
1909 return 0;
1910
1911 schedule_timeout_uninterruptible(HZ / 10);
1912
1913 } while (time_after(time, jiffies));
1914
1915 return -ETIMEDOUT;
1916}
1917
1918static int enic_dev_open(struct enic *enic)
1919{
1920 int err;
1921
1922 err = enic_dev_wait(enic->vdev, vnic_dev_open,
1923 vnic_dev_open_done, 0);
1924 if (err)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001925 dev_err(enic_get_dev(enic), "vNIC device open failed, err %d\n",
1926 err);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001927
1928 return err;
1929}
1930
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +00001931static int enic_dev_hang_reset(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001932{
1933 int err;
1934
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +00001935 err = enic_dev_wait(enic->vdev, vnic_dev_hang_reset,
1936 vnic_dev_hang_reset_done, 0);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001937 if (err)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001938 netdev_err(enic->netdev, "vNIC hang reset failed, err %d\n",
1939 err);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001940
1941 return err;
1942}
1943
Scott Feldman68f71702009-02-09 23:24:24 -08001944static int enic_set_niccfg(struct enic *enic)
1945{
1946 const u8 rss_default_cpu = 0;
1947 const u8 rss_hash_type = 0;
1948 const u8 rss_hash_bits = 0;
1949 const u8 rss_base_cpu = 0;
1950 const u8 rss_enable = 0;
1951 const u8 tso_ipid_split_en = 0;
1952 const u8 ig_vlan_strip_en = 1;
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001953 int err;
Scott Feldman68f71702009-02-09 23:24:24 -08001954
1955 /* Enable VLAN tag stripping. RSS not enabled (yet).
Scott Feldman6ba9cdc2009-09-03 17:02:24 +00001956 */
Scott Feldman68f71702009-02-09 23:24:24 -08001957
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001958 spin_lock(&enic->devcmd_lock);
1959 err = enic_set_nic_cfg(enic,
Scott Feldman68f71702009-02-09 23:24:24 -08001960 rss_default_cpu, rss_hash_type,
1961 rss_hash_bits, rss_base_cpu,
1962 rss_enable, tso_ipid_split_en,
1963 ig_vlan_strip_en);
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001964 spin_unlock(&enic->devcmd_lock);
1965
1966 return err;
1967}
1968
1969static int enic_dev_hang_notify(struct enic *enic)
1970{
1971 int err;
1972
1973 spin_lock(&enic->devcmd_lock);
1974 err = vnic_dev_hang_notify(enic->vdev);
1975 spin_unlock(&enic->devcmd_lock);
1976
1977 return err;
Scott Feldman68f71702009-02-09 23:24:24 -08001978}
1979
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001980int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
1981{
1982 int err;
1983
1984 spin_lock(&enic->devcmd_lock);
1985 err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
1986 IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
1987 spin_unlock(&enic->devcmd_lock);
1988
1989 return err;
1990}
1991
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001992static void enic_reset(struct work_struct *work)
1993{
1994 struct enic *enic = container_of(work, struct enic, reset);
1995
1996 if (!netif_running(enic->netdev))
1997 return;
1998
1999 rtnl_lock();
2000
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002001 enic_dev_hang_notify(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002002 enic_stop(enic->netdev);
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +00002003 enic_dev_hang_reset(enic);
2004 enic_reset_multicast_list(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002005 enic_init_vnic_resources(enic);
Scott Feldman68f71702009-02-09 23:24:24 -08002006 enic_set_niccfg(enic);
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00002007 enic_dev_set_ig_vlan_rewrite_mode(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002008 enic_open(enic->netdev);
2009
2010 rtnl_unlock();
2011}
2012
2013static int enic_set_intr_mode(struct enic *enic)
2014{
Scott Feldman6ba9cdc2009-09-03 17:02:24 +00002015 unsigned int n = 1;
2016 unsigned int m = 1;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002017 unsigned int i;
2018
2019 /* Set interrupt mode (INTx, MSI, MSI-X) depending
2020 * system capabilities.
2021 *
2022 * Try MSI-X first
2023 *
2024 * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
2025 * (the second to last INTR is used for WQ/RQ errors)
2026 * (the last INTR is used for notifications)
2027 */
2028
2029 BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
2030 for (i = 0; i < n + m + 2; i++)
2031 enic->msix_entry[i].entry = i;
2032
2033 if (enic->config.intr_mode < 1 &&
2034 enic->rq_count >= n &&
2035 enic->wq_count >= m &&
2036 enic->cq_count >= n + m &&
2037 enic->intr_count >= n + m + 2 &&
2038 !pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
2039
2040 enic->rq_count = n;
2041 enic->wq_count = m;
2042 enic->cq_count = n + m;
2043 enic->intr_count = n + m + 2;
2044
2045 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX);
2046
2047 return 0;
2048 }
2049
2050 /* Next try MSI
2051 *
2052 * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
2053 */
2054
2055 if (enic->config.intr_mode < 2 &&
2056 enic->rq_count >= 1 &&
2057 enic->wq_count >= 1 &&
2058 enic->cq_count >= 2 &&
2059 enic->intr_count >= 1 &&
2060 !pci_enable_msi(enic->pdev)) {
2061
2062 enic->rq_count = 1;
2063 enic->wq_count = 1;
2064 enic->cq_count = 2;
2065 enic->intr_count = 1;
2066
2067 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
2068
2069 return 0;
2070 }
2071
2072 /* Next try INTx
2073 *
2074 * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
2075 * (the first INTR is used for WQ/RQ)
2076 * (the second INTR is used for WQ/RQ errors)
2077 * (the last INTR is used for notifications)
2078 */
2079
2080 if (enic->config.intr_mode < 3 &&
2081 enic->rq_count >= 1 &&
2082 enic->wq_count >= 1 &&
2083 enic->cq_count >= 2 &&
2084 enic->intr_count >= 3) {
2085
2086 enic->rq_count = 1;
2087 enic->wq_count = 1;
2088 enic->cq_count = 2;
2089 enic->intr_count = 3;
2090
2091 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
2092
2093 return 0;
2094 }
2095
2096 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2097
2098 return -EINVAL;
2099}
2100
2101static void enic_clear_intr_mode(struct enic *enic)
2102{
2103 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2104 case VNIC_DEV_INTR_MODE_MSIX:
2105 pci_disable_msix(enic->pdev);
2106 break;
2107 case VNIC_DEV_INTR_MODE_MSI:
2108 pci_disable_msi(enic->pdev);
2109 break;
2110 default:
2111 break;
2112 }
2113
2114 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2115}
2116
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002117static const struct net_device_ops enic_netdev_dynamic_ops = {
2118 .ndo_open = enic_open,
2119 .ndo_stop = enic_stop,
2120 .ndo_start_xmit = enic_hard_start_xmit,
2121 .ndo_get_stats = enic_get_stats,
2122 .ndo_validate_addr = eth_validate_addr,
2123 .ndo_set_multicast_list = enic_set_multicast_list,
2124 .ndo_set_mac_address = enic_set_mac_address_dynamic,
2125 .ndo_change_mtu = enic_change_mtu,
2126 .ndo_vlan_rx_register = enic_vlan_rx_register,
2127 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2128 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2129 .ndo_tx_timeout = enic_tx_timeout,
2130 .ndo_set_vf_port = enic_set_vf_port,
2131 .ndo_get_vf_port = enic_get_vf_port,
2132#ifdef CONFIG_NET_POLL_CONTROLLER
2133 .ndo_poll_controller = enic_poll_controller,
2134#endif
2135};
2136
Stephen Hemmingerafe29f72008-11-19 22:23:26 -08002137static const struct net_device_ops enic_netdev_ops = {
2138 .ndo_open = enic_open,
2139 .ndo_stop = enic_stop,
Stephen Hemminger00829822008-11-20 20:14:53 -08002140 .ndo_start_xmit = enic_hard_start_xmit,
Stephen Hemmingerafe29f72008-11-19 22:23:26 -08002141 .ndo_get_stats = enic_get_stats,
2142 .ndo_validate_addr = eth_validate_addr,
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002143 .ndo_set_mac_address = enic_set_mac_address,
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002144 .ndo_set_multicast_list = enic_set_multicast_list,
Stephen Hemmingerafe29f72008-11-19 22:23:26 -08002145 .ndo_change_mtu = enic_change_mtu,
2146 .ndo_vlan_rx_register = enic_vlan_rx_register,
2147 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2148 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2149 .ndo_tx_timeout = enic_tx_timeout,
2150#ifdef CONFIG_NET_POLL_CONTROLLER
2151 .ndo_poll_controller = enic_poll_controller,
2152#endif
2153};
2154
Scott Feldman6fdfa972009-09-03 17:02:45 +00002155void enic_dev_deinit(struct enic *enic)
2156{
2157 netif_napi_del(&enic->napi);
2158 enic_free_vnic_resources(enic);
2159 enic_clear_intr_mode(enic);
2160}
2161
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002162static int enic_dev_stats_clear(struct enic *enic)
2163{
2164 int err;
2165
2166 spin_lock(&enic->devcmd_lock);
2167 err = vnic_dev_stats_clear(enic->vdev);
2168 spin_unlock(&enic->devcmd_lock);
2169
2170 return err;
2171}
2172
Scott Feldman6fdfa972009-09-03 17:02:45 +00002173int enic_dev_init(struct enic *enic)
2174{
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002175 struct device *dev = enic_get_dev(enic);
Scott Feldman6fdfa972009-09-03 17:02:45 +00002176 struct net_device *netdev = enic->netdev;
2177 int err;
2178
2179 /* Get vNIC configuration
2180 */
2181
2182 err = enic_get_vnic_config(enic);
2183 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002184 dev_err(dev, "Get vNIC configuration failed, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002185 return err;
2186 }
2187
2188 /* Get available resource counts
2189 */
2190
2191 enic_get_res_counts(enic);
2192
2193 /* Set interrupt mode based on resource counts and system
2194 * capabilities
2195 */
2196
2197 err = enic_set_intr_mode(enic);
2198 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002199 dev_err(dev, "Failed to set intr mode based on resource "
2200 "counts and system capabilities, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002201 return err;
2202 }
2203
2204 /* Allocate and configure vNIC resources
2205 */
2206
2207 err = enic_alloc_vnic_resources(enic);
2208 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002209 dev_err(dev, "Failed to alloc vNIC resources, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002210 goto err_out_free_vnic_resources;
2211 }
2212
2213 enic_init_vnic_resources(enic);
2214
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002215 /* Clear LIF stats
2216 */
2217 enic_dev_stats_clear(enic);
2218
Scott Feldman6fdfa972009-09-03 17:02:45 +00002219 err = enic_set_rq_alloc_buf(enic);
2220 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002221 dev_err(dev, "Failed to set RQ buffer allocator, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002222 goto err_out_free_vnic_resources;
2223 }
2224
2225 err = enic_set_niccfg(enic);
2226 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002227 dev_err(dev, "Failed to config nic, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002228 goto err_out_free_vnic_resources;
2229 }
2230
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00002231 err = enic_dev_set_ig_vlan_rewrite_mode(enic);
2232 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002233 netdev_err(netdev,
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00002234 "Failed to set ingress vlan rewrite mode, aborting.\n");
2235 goto err_out_free_vnic_resources;
2236 }
2237
Scott Feldman6fdfa972009-09-03 17:02:45 +00002238 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2239 default:
2240 netif_napi_add(netdev, &enic->napi, enic_poll, 64);
2241 break;
2242 case VNIC_DEV_INTR_MODE_MSIX:
2243 netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64);
2244 break;
2245 }
2246
2247 return 0;
2248
2249err_out_free_vnic_resources:
2250 enic_clear_intr_mode(enic);
2251 enic_free_vnic_resources(enic);
2252
2253 return err;
2254}
2255
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002256static void enic_iounmap(struct enic *enic)
2257{
2258 unsigned int i;
2259
2260 for (i = 0; i < ARRAY_SIZE(enic->bar); i++)
2261 if (enic->bar[i].vaddr)
2262 iounmap(enic->bar[i].vaddr);
2263}
2264
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002265static int __devinit enic_probe(struct pci_dev *pdev,
2266 const struct pci_device_id *ent)
2267{
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002268 struct device *dev = &pdev->dev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002269 struct net_device *netdev;
2270 struct enic *enic;
2271 int using_dac = 0;
2272 unsigned int i;
2273 int err;
2274
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002275 /* Allocate net device structure and initialize. Private
2276 * instance data is initialized to zero.
2277 */
2278
2279 netdev = alloc_etherdev(sizeof(struct enic));
2280 if (!netdev) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002281 pr_err("Etherdev alloc failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002282 return -ENOMEM;
2283 }
2284
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002285 pci_set_drvdata(pdev, netdev);
2286
2287 SET_NETDEV_DEV(netdev, &pdev->dev);
2288
2289 enic = netdev_priv(netdev);
2290 enic->netdev = netdev;
2291 enic->pdev = pdev;
2292
2293 /* Setup PCI resources
2294 */
2295
2296 err = pci_enable_device(pdev);
2297 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002298 dev_err(dev, "Cannot enable PCI device, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002299 goto err_out_free_netdev;
2300 }
2301
2302 err = pci_request_regions(pdev, DRV_NAME);
2303 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002304 dev_err(dev, "Cannot request PCI regions, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002305 goto err_out_disable_device;
2306 }
2307
2308 pci_set_master(pdev);
2309
2310 /* Query PCI controller on system for DMA addressing
2311 * limitation for the device. Try 40-bit first, and
2312 * fail to 32-bit.
2313 */
2314
Yang Hongyang50cf1562009-04-06 19:01:14 -07002315 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002316 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07002317 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002318 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002319 dev_err(dev, "No usable DMA configuration, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002320 goto err_out_release_regions;
2321 }
Yang Hongyang284901a2009-04-06 19:01:15 -07002322 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002323 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002324 dev_err(dev, "Unable to obtain %u-bit DMA "
2325 "for consistent allocations, aborting\n", 32);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002326 goto err_out_release_regions;
2327 }
2328 } else {
Yang Hongyang50cf1562009-04-06 19:01:14 -07002329 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002330 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002331 dev_err(dev, "Unable to obtain %u-bit DMA "
2332 "for consistent allocations, aborting\n", 40);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002333 goto err_out_release_regions;
2334 }
2335 using_dac = 1;
2336 }
2337
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002338 /* Map vNIC resources from BAR0-5
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002339 */
2340
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002341 for (i = 0; i < ARRAY_SIZE(enic->bar); i++) {
2342 if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM))
2343 continue;
2344 enic->bar[i].len = pci_resource_len(pdev, i);
2345 enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len);
2346 if (!enic->bar[i].vaddr) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002347 dev_err(dev, "Cannot memory-map BAR %d, aborting\n", i);
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002348 err = -ENODEV;
2349 goto err_out_iounmap;
2350 }
2351 enic->bar[i].bus_addr = pci_resource_start(pdev, i);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002352 }
2353
2354 /* Register vNIC device
2355 */
2356
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002357 enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar,
2358 ARRAY_SIZE(enic->bar));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002359 if (!enic->vdev) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002360 dev_err(dev, "vNIC registration failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002361 err = -ENODEV;
2362 goto err_out_iounmap;
2363 }
2364
2365 /* Issue device open to get device in known state
2366 */
2367
2368 err = enic_dev_open(enic);
2369 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002370 dev_err(dev, "vNIC dev open failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002371 goto err_out_vnic_unregister;
2372 }
2373
2374 /* Issue device init to initialize the vnic-to-switch link.
2375 * We'll start with carrier off and wait for link UP
2376 * notification later to turn on carrier. We don't need
2377 * to wait here for the vnic-to-switch link initialization
2378 * to complete; link UP notification is the indication that
2379 * the process is complete.
2380 */
2381
2382 netif_carrier_off(netdev);
2383
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002384 /* Do not call dev_init for a dynamic vnic.
2385 * For a dynamic vnic, init_prov_info will be
2386 * called later by an upper layer.
2387 */
2388
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002389 if (!enic_is_dynamic(enic)) {
2390 err = vnic_dev_init(enic->vdev, 0);
2391 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002392 dev_err(dev, "vNIC dev init failed, aborting\n");
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002393 goto err_out_dev_close;
2394 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002395 }
2396
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002397 /* Setup devcmd lock
2398 */
2399
2400 spin_lock_init(&enic->devcmd_lock);
2401
Scott Feldman6fdfa972009-09-03 17:02:45 +00002402 err = enic_dev_init(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002403 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002404 dev_err(dev, "Device initialization failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002405 goto err_out_dev_close;
2406 }
2407
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002408 /* Setup notification timer, HW reset task, and wq locks
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002409 */
2410
2411 init_timer(&enic->notify_timer);
2412 enic->notify_timer.function = enic_notify_timer;
2413 enic->notify_timer.data = (unsigned long)enic;
2414
2415 INIT_WORK(&enic->reset, enic_reset);
2416
2417 for (i = 0; i < enic->wq_count; i++)
2418 spin_lock_init(&enic->wq_lock[i]);
2419
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002420 /* Register net device
2421 */
2422
2423 enic->port_mtu = enic->config.mtu;
2424 (void)enic_change_mtu(netdev, enic->port_mtu);
2425
2426 err = enic_set_mac_addr(netdev, enic->mac_addr);
2427 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002428 dev_err(dev, "Invalid MAC address, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002429 goto err_out_dev_deinit;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002430 }
2431
Scott Feldman7c844592009-12-23 13:27:54 +00002432 enic->tx_coalesce_usecs = enic->config.intr_timer_usec;
2433 enic->rx_coalesce_usecs = enic->tx_coalesce_usecs;
2434
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002435 if (enic_is_dynamic(enic))
2436 netdev->netdev_ops = &enic_netdev_dynamic_ops;
2437 else
2438 netdev->netdev_ops = &enic_netdev_ops;
2439
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002440 netdev->watchdog_timeo = 2 * HZ;
2441 netdev->ethtool_ops = &enic_ethtool_ops;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002442
Vasanthy Kolluri73c1ea92010-03-18 16:19:54 +00002443 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002444 if (ENIC_SETTING(enic, TXCSUM))
2445 netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
2446 if (ENIC_SETTING(enic, TSO))
2447 netdev->features |= NETIF_F_TSO |
2448 NETIF_F_TSO6 | NETIF_F_TSO_ECN;
Scott Feldman86ca9db2008-11-21 21:26:55 -08002449 if (ENIC_SETTING(enic, LRO))
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00002450 netdev->features |= NETIF_F_GRO;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002451 if (using_dac)
2452 netdev->features |= NETIF_F_HIGHDMA;
2453
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002454 enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM);
2455
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002456 err = register_netdev(netdev);
2457 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002458 dev_err(dev, "Cannot register net device, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002459 goto err_out_dev_deinit;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002460 }
2461
2462 return 0;
2463
Scott Feldman6fdfa972009-09-03 17:02:45 +00002464err_out_dev_deinit:
2465 enic_dev_deinit(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002466err_out_dev_close:
2467 vnic_dev_close(enic->vdev);
2468err_out_vnic_unregister:
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002469 vnic_dev_unregister(enic->vdev);
2470err_out_iounmap:
2471 enic_iounmap(enic);
2472err_out_release_regions:
2473 pci_release_regions(pdev);
2474err_out_disable_device:
2475 pci_disable_device(pdev);
2476err_out_free_netdev:
2477 pci_set_drvdata(pdev, NULL);
2478 free_netdev(netdev);
2479
2480 return err;
2481}
2482
2483static void __devexit enic_remove(struct pci_dev *pdev)
2484{
2485 struct net_device *netdev = pci_get_drvdata(pdev);
2486
2487 if (netdev) {
2488 struct enic *enic = netdev_priv(netdev);
2489
2490 flush_scheduled_work();
2491 unregister_netdev(netdev);
Scott Feldman6fdfa972009-09-03 17:02:45 +00002492 enic_dev_deinit(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002493 vnic_dev_close(enic->vdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002494 vnic_dev_unregister(enic->vdev);
2495 enic_iounmap(enic);
2496 pci_release_regions(pdev);
2497 pci_disable_device(pdev);
2498 pci_set_drvdata(pdev, NULL);
2499 free_netdev(netdev);
2500 }
2501}
2502
2503static struct pci_driver enic_driver = {
2504 .name = DRV_NAME,
2505 .id_table = enic_id_table,
2506 .probe = enic_probe,
2507 .remove = __devexit_p(enic_remove),
2508};
2509
2510static int __init enic_init_module(void)
2511{
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002512 pr_info("%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002513
2514 return pci_register_driver(&enic_driver);
2515}
2516
2517static void __exit enic_cleanup_module(void)
2518{
2519 pci_unregister_driver(&enic_driver);
2520}
2521
2522module_init(enic_init_module);
2523module_exit(enic_cleanup_module);