]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/net/enic/enic_main.c
enic: bug fix: sprintf UUID to string as u8[] rather than u16[] array
[mirror_ubuntu-focal-kernel.git] / drivers / net / enic / enic_main.c
CommitLineData
01f2e4ea
SF
1/*
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>
f8bd9091 32#include <linux/if_link.h>
01f2e4ea
SF
33#include <linux/ethtool.h>
34#include <linux/in.h>
35#include <linux/ip.h>
36#include <linux/ipv6.h>
37#include <linux/tcp.h>
b7c6bfb7 38#include <net/ip6_checksum.h>
01f2e4ea
SF
39
40#include "cq_enet_desc.h"
41#include "vnic_dev.h"
42#include "vnic_intr.h"
43#include "vnic_stats.h"
f8bd9091 44#include "vnic_vic.h"
01f2e4ea
SF
45#include "enic_res.h"
46#include "enic.h"
47
48#define ENIC_NOTIFY_TIMER_PERIOD (2 * HZ)
ea0d7d91
SF
49#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 */
f8bd9091 54#define PCI_DEVICE_ID_CISCO_VIC_ENET_DYN 0x0044 /* enet dynamic vnic */
01f2e4ea
SF
55
56/* Supported devices */
a3aa1884 57static DEFINE_PCI_DEVICE_TABLE(enic_id_table) = {
ea0d7d91 58 { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET) },
f8bd9091 59 { PCI_VDEVICE(CISCO, PCI_DEVICE_ID_CISCO_VIC_ENET_DYN) },
01f2e4ea
SF
60 { 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
f8bd9091
SF
120static int enic_is_dynamic(struct enic *enic)
121{
122 return enic->pdev->device == PCI_DEVICE_ID_CISCO_VIC_ENET_DYN;
123}
124
01f2e4ea
SF
125static 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
148static void enic_get_drvinfo(struct net_device *netdev,
149 struct ethtool_drvinfo *drvinfo)
150{
151 struct enic *enic = netdev_priv(netdev);
152 struct vnic_devcmd_fw_info *fw_info;
153
154 spin_lock(&enic->devcmd_lock);
155 vnic_dev_fw_info(enic->vdev, &fw_info);
156 spin_unlock(&enic->devcmd_lock);
157
158 strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
159 strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
160 strncpy(drvinfo->fw_version, fw_info->fw_version,
161 sizeof(drvinfo->fw_version));
162 strncpy(drvinfo->bus_info, pci_name(enic->pdev),
163 sizeof(drvinfo->bus_info));
164}
165
166static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
167{
168 unsigned int i;
169
170 switch (stringset) {
171 case ETH_SS_STATS:
172 for (i = 0; i < enic_n_tx_stats; i++) {
173 memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
174 data += ETH_GSTRING_LEN;
175 }
176 for (i = 0; i < enic_n_rx_stats; i++) {
177 memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
178 data += ETH_GSTRING_LEN;
179 }
180 break;
181 }
182}
183
25f0a061 184static int enic_get_sset_count(struct net_device *netdev, int sset)
01f2e4ea 185{
25f0a061
SF
186 switch (sset) {
187 case ETH_SS_STATS:
188 return enic_n_tx_stats + enic_n_rx_stats;
189 default:
190 return -EOPNOTSUPP;
191 }
01f2e4ea
SF
192}
193
194static void enic_get_ethtool_stats(struct net_device *netdev,
195 struct ethtool_stats *stats, u64 *data)
196{
197 struct enic *enic = netdev_priv(netdev);
198 struct vnic_stats *vstats;
199 unsigned int i;
200
201 spin_lock(&enic->devcmd_lock);
202 vnic_dev_stats_dump(enic->vdev, &vstats);
203 spin_unlock(&enic->devcmd_lock);
204
205 for (i = 0; i < enic_n_tx_stats; i++)
206 *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
207 for (i = 0; i < enic_n_rx_stats; i++)
208 *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
209}
210
211static u32 enic_get_rx_csum(struct net_device *netdev)
212{
213 struct enic *enic = netdev_priv(netdev);
214 return enic->csum_rx_enabled;
215}
216
217static int enic_set_rx_csum(struct net_device *netdev, u32 data)
218{
219 struct enic *enic = netdev_priv(netdev);
220
25f0a061
SF
221 if (data && !ENIC_SETTING(enic, RXCSUM))
222 return -EINVAL;
223
224 enic->csum_rx_enabled = !!data;
01f2e4ea
SF
225
226 return 0;
227}
228
229static int enic_set_tx_csum(struct net_device *netdev, u32 data)
230{
231 struct enic *enic = netdev_priv(netdev);
232
25f0a061
SF
233 if (data && !ENIC_SETTING(enic, TXCSUM))
234 return -EINVAL;
235
236 if (data)
01f2e4ea
SF
237 netdev->features |= NETIF_F_HW_CSUM;
238 else
239 netdev->features &= ~NETIF_F_HW_CSUM;
240
241 return 0;
242}
243
244static int enic_set_tso(struct net_device *netdev, u32 data)
245{
246 struct enic *enic = netdev_priv(netdev);
247
25f0a061
SF
248 if (data && !ENIC_SETTING(enic, TSO))
249 return -EINVAL;
250
251 if (data)
01f2e4ea
SF
252 netdev->features |=
253 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN;
254 else
255 netdev->features &=
256 ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN);
257
258 return 0;
259}
260
261static u32 enic_get_msglevel(struct net_device *netdev)
262{
263 struct enic *enic = netdev_priv(netdev);
264 return enic->msg_enable;
265}
266
267static void enic_set_msglevel(struct net_device *netdev, u32 value)
268{
269 struct enic *enic = netdev_priv(netdev);
270 enic->msg_enable = value;
271}
272
7c844599
SF
273static int enic_get_coalesce(struct net_device *netdev,
274 struct ethtool_coalesce *ecmd)
275{
276 struct enic *enic = netdev_priv(netdev);
277
278 ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
279 ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
280
281 return 0;
282}
283
284static int enic_set_coalesce(struct net_device *netdev,
285 struct ethtool_coalesce *ecmd)
286{
287 struct enic *enic = netdev_priv(netdev);
288 u32 tx_coalesce_usecs;
289 u32 rx_coalesce_usecs;
290
291 tx_coalesce_usecs = min_t(u32,
292 INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
293 ecmd->tx_coalesce_usecs);
294 rx_coalesce_usecs = min_t(u32,
295 INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
296 ecmd->rx_coalesce_usecs);
297
298 switch (vnic_dev_get_intr_mode(enic->vdev)) {
299 case VNIC_DEV_INTR_MODE_INTX:
300 if (tx_coalesce_usecs != rx_coalesce_usecs)
301 return -EINVAL;
302
303 vnic_intr_coalescing_timer_set(&enic->intr[ENIC_INTX_WQ_RQ],
304 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
305 break;
306 case VNIC_DEV_INTR_MODE_MSI:
307 if (tx_coalesce_usecs != rx_coalesce_usecs)
308 return -EINVAL;
309
310 vnic_intr_coalescing_timer_set(&enic->intr[0],
311 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
312 break;
313 case VNIC_DEV_INTR_MODE_MSIX:
314 vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_WQ],
315 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
316 vnic_intr_coalescing_timer_set(&enic->intr[ENIC_MSIX_RQ],
317 INTR_COALESCE_USEC_TO_HW(rx_coalesce_usecs));
318 break;
319 default:
320 break;
321 }
322
323 enic->tx_coalesce_usecs = tx_coalesce_usecs;
324 enic->rx_coalesce_usecs = rx_coalesce_usecs;
325
326 return 0;
327}
328
0fc0b732 329static const struct ethtool_ops enic_ethtool_ops = {
01f2e4ea
SF
330 .get_settings = enic_get_settings,
331 .get_drvinfo = enic_get_drvinfo,
332 .get_msglevel = enic_get_msglevel,
333 .set_msglevel = enic_set_msglevel,
334 .get_link = ethtool_op_get_link,
335 .get_strings = enic_get_strings,
25f0a061 336 .get_sset_count = enic_get_sset_count,
01f2e4ea
SF
337 .get_ethtool_stats = enic_get_ethtool_stats,
338 .get_rx_csum = enic_get_rx_csum,
339 .set_rx_csum = enic_set_rx_csum,
340 .get_tx_csum = ethtool_op_get_tx_csum,
341 .set_tx_csum = enic_set_tx_csum,
342 .get_sg = ethtool_op_get_sg,
343 .set_sg = ethtool_op_set_sg,
344 .get_tso = ethtool_op_get_tso,
345 .set_tso = enic_set_tso,
7c844599
SF
346 .get_coalesce = enic_get_coalesce,
347 .set_coalesce = enic_set_coalesce,
86ca9db7
SF
348 .get_flags = ethtool_op_get_flags,
349 .set_flags = ethtool_op_set_flags,
01f2e4ea
SF
350};
351
352static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
353{
354 struct enic *enic = vnic_dev_priv(wq->vdev);
355
356 if (buf->sop)
357 pci_unmap_single(enic->pdev, buf->dma_addr,
358 buf->len, PCI_DMA_TODEVICE);
359 else
360 pci_unmap_page(enic->pdev, buf->dma_addr,
361 buf->len, PCI_DMA_TODEVICE);
362
363 if (buf->os_buf)
364 dev_kfree_skb_any(buf->os_buf);
365}
366
367static void enic_wq_free_buf(struct vnic_wq *wq,
368 struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
369{
370 enic_free_wq_buf(wq, buf);
371}
372
373static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
374 u8 type, u16 q_number, u16 completed_index, void *opaque)
375{
376 struct enic *enic = vnic_dev_priv(vdev);
377
378 spin_lock(&enic->wq_lock[q_number]);
379
380 vnic_wq_service(&enic->wq[q_number], cq_desc,
381 completed_index, enic_wq_free_buf,
382 opaque);
383
384 if (netif_queue_stopped(enic->netdev) &&
ea0d7d91
SF
385 vnic_wq_desc_avail(&enic->wq[q_number]) >=
386 (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS))
01f2e4ea
SF
387 netif_wake_queue(enic->netdev);
388
389 spin_unlock(&enic->wq_lock[q_number]);
390
391 return 0;
392}
393
394static void enic_log_q_error(struct enic *enic)
395{
396 unsigned int i;
397 u32 error_status;
398
399 for (i = 0; i < enic->wq_count; i++) {
400 error_status = vnic_wq_error_status(&enic->wq[i]);
401 if (error_status)
402 printk(KERN_ERR PFX "%s: WQ[%d] error_status %d\n",
403 enic->netdev->name, i, error_status);
404 }
405
406 for (i = 0; i < enic->rq_count; i++) {
407 error_status = vnic_rq_error_status(&enic->rq[i]);
408 if (error_status)
409 printk(KERN_ERR PFX "%s: RQ[%d] error_status %d\n",
410 enic->netdev->name, i, error_status);
411 }
412}
413
414static void enic_link_check(struct enic *enic)
415{
416 int link_status = vnic_dev_link_status(enic->vdev);
417 int carrier_ok = netif_carrier_ok(enic->netdev);
418
419 if (link_status && !carrier_ok) {
420 printk(KERN_INFO PFX "%s: Link UP\n", enic->netdev->name);
421 netif_carrier_on(enic->netdev);
422 } else if (!link_status && carrier_ok) {
423 printk(KERN_INFO PFX "%s: Link DOWN\n", enic->netdev->name);
424 netif_carrier_off(enic->netdev);
425 }
426}
427
428static void enic_mtu_check(struct enic *enic)
429{
430 u32 mtu = vnic_dev_mtu(enic->vdev);
431
491598a4 432 if (mtu && mtu != enic->port_mtu) {
7c844599 433 enic->port_mtu = mtu;
01f2e4ea
SF
434 if (mtu < enic->netdev->mtu)
435 printk(KERN_WARNING PFX
436 "%s: interface MTU (%d) set higher "
437 "than switch port MTU (%d)\n",
438 enic->netdev->name, enic->netdev->mtu, mtu);
01f2e4ea
SF
439 }
440}
441
442static void enic_msglvl_check(struct enic *enic)
443{
444 u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
445
446 if (msg_enable != enic->msg_enable) {
447 printk(KERN_INFO PFX "%s: msg lvl changed from 0x%x to 0x%x\n",
448 enic->netdev->name, enic->msg_enable, msg_enable);
449 enic->msg_enable = msg_enable;
450 }
451}
452
453static void enic_notify_check(struct enic *enic)
454{
455 enic_msglvl_check(enic);
456 enic_mtu_check(enic);
457 enic_link_check(enic);
458}
459
460#define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
461
462static irqreturn_t enic_isr_legacy(int irq, void *data)
463{
464 struct net_device *netdev = data;
465 struct enic *enic = netdev_priv(netdev);
466 u32 pba;
467
468 vnic_intr_mask(&enic->intr[ENIC_INTX_WQ_RQ]);
469
470 pba = vnic_intr_legacy_pba(enic->legacy_pba);
471 if (!pba) {
472 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
473 return IRQ_NONE; /* not our interrupt */
474 }
475
ed8af6b2
SF
476 if (ENIC_TEST_INTR(pba, ENIC_INTX_NOTIFY)) {
477 vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_NOTIFY]);
01f2e4ea 478 enic_notify_check(enic);
ed8af6b2 479 }
01f2e4ea
SF
480
481 if (ENIC_TEST_INTR(pba, ENIC_INTX_ERR)) {
ed8af6b2 482 vnic_intr_return_all_credits(&enic->intr[ENIC_INTX_ERR]);
01f2e4ea
SF
483 enic_log_q_error(enic);
484 /* schedule recovery from WQ/RQ error */
485 schedule_work(&enic->reset);
486 return IRQ_HANDLED;
487 }
488
489 if (ENIC_TEST_INTR(pba, ENIC_INTX_WQ_RQ)) {
288379f0
BH
490 if (napi_schedule_prep(&enic->napi))
491 __napi_schedule(&enic->napi);
01f2e4ea
SF
492 } else {
493 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
494 }
495
496 return IRQ_HANDLED;
497}
498
499static irqreturn_t enic_isr_msi(int irq, void *data)
500{
501 struct enic *enic = data;
502
503 /* With MSI, there is no sharing of interrupts, so this is
504 * our interrupt and there is no need to ack it. The device
505 * is not providing per-vector masking, so the OS will not
506 * write to PCI config space to mask/unmask the interrupt.
507 * We're using mask_on_assertion for MSI, so the device
508 * automatically masks the interrupt when the interrupt is
509 * generated. Later, when exiting polling, the interrupt
510 * will be unmasked (see enic_poll).
511 *
512 * Also, the device uses the same PCIe Traffic Class (TC)
513 * for Memory Write data and MSI, so there are no ordering
514 * issues; the MSI will always arrive at the Root Complex
515 * _after_ corresponding Memory Writes (i.e. descriptor
516 * writes).
517 */
518
288379f0 519 napi_schedule(&enic->napi);
01f2e4ea
SF
520
521 return IRQ_HANDLED;
522}
523
524static irqreturn_t enic_isr_msix_rq(int irq, void *data)
525{
526 struct enic *enic = data;
527
528 /* schedule NAPI polling for RQ cleanup */
288379f0 529 napi_schedule(&enic->napi);
01f2e4ea
SF
530
531 return IRQ_HANDLED;
532}
533
534static irqreturn_t enic_isr_msix_wq(int irq, void *data)
535{
536 struct enic *enic = data;
537 unsigned int wq_work_to_do = -1; /* no limit */
538 unsigned int wq_work_done;
539
540 wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
541 wq_work_to_do, enic_wq_service, NULL);
542
543 vnic_intr_return_credits(&enic->intr[ENIC_MSIX_WQ],
544 wq_work_done,
545 1 /* unmask intr */,
546 1 /* reset intr timer */);
547
548 return IRQ_HANDLED;
549}
550
551static irqreturn_t enic_isr_msix_err(int irq, void *data)
552{
553 struct enic *enic = data;
554
ed8af6b2
SF
555 vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_ERR]);
556
01f2e4ea
SF
557 enic_log_q_error(enic);
558
559 /* schedule recovery from WQ/RQ error */
560 schedule_work(&enic->reset);
561
562 return IRQ_HANDLED;
563}
564
565static irqreturn_t enic_isr_msix_notify(int irq, void *data)
566{
567 struct enic *enic = data;
568
ed8af6b2 569 vnic_intr_return_all_credits(&enic->intr[ENIC_MSIX_NOTIFY]);
01f2e4ea 570 enic_notify_check(enic);
01f2e4ea
SF
571
572 return IRQ_HANDLED;
573}
574
575static inline void enic_queue_wq_skb_cont(struct enic *enic,
576 struct vnic_wq *wq, struct sk_buff *skb,
577 unsigned int len_left)
578{
579 skb_frag_t *frag;
580
581 /* Queue additional data fragments */
582 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
583 len_left -= frag->size;
584 enic_queue_wq_desc_cont(wq, skb,
585 pci_map_page(enic->pdev, frag->page,
586 frag->page_offset, frag->size,
587 PCI_DMA_TODEVICE),
588 frag->size,
589 (len_left == 0)); /* EOP? */
590 }
591}
592
593static inline void enic_queue_wq_skb_vlan(struct enic *enic,
594 struct vnic_wq *wq, struct sk_buff *skb,
595 int vlan_tag_insert, unsigned int vlan_tag)
596{
597 unsigned int head_len = skb_headlen(skb);
598 unsigned int len_left = skb->len - head_len;
599 int eop = (len_left == 0);
600
ea0d7d91
SF
601 /* Queue the main skb fragment. The fragments are no larger
602 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
603 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
604 * per fragment is queued.
605 */
01f2e4ea
SF
606 enic_queue_wq_desc(wq, skb,
607 pci_map_single(enic->pdev, skb->data,
608 head_len, PCI_DMA_TODEVICE),
609 head_len,
610 vlan_tag_insert, vlan_tag,
611 eop);
612
613 if (!eop)
614 enic_queue_wq_skb_cont(enic, wq, skb, len_left);
615}
616
617static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
618 struct vnic_wq *wq, struct sk_buff *skb,
619 int vlan_tag_insert, unsigned int vlan_tag)
620{
621 unsigned int head_len = skb_headlen(skb);
622 unsigned int len_left = skb->len - head_len;
623 unsigned int hdr_len = skb_transport_offset(skb);
624 unsigned int csum_offset = hdr_len + skb->csum_offset;
625 int eop = (len_left == 0);
626
ea0d7d91
SF
627 /* Queue the main skb fragment. The fragments are no larger
628 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
629 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
630 * per fragment is queued.
631 */
01f2e4ea
SF
632 enic_queue_wq_desc_csum_l4(wq, skb,
633 pci_map_single(enic->pdev, skb->data,
634 head_len, PCI_DMA_TODEVICE),
635 head_len,
636 csum_offset,
637 hdr_len,
638 vlan_tag_insert, vlan_tag,
639 eop);
640
641 if (!eop)
642 enic_queue_wq_skb_cont(enic, wq, skb, len_left);
643}
644
645static inline void enic_queue_wq_skb_tso(struct enic *enic,
646 struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
647 int vlan_tag_insert, unsigned int vlan_tag)
648{
ea0d7d91
SF
649 unsigned int frag_len_left = skb_headlen(skb);
650 unsigned int len_left = skb->len - frag_len_left;
01f2e4ea
SF
651 unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
652 int eop = (len_left == 0);
ea0d7d91
SF
653 unsigned int len;
654 dma_addr_t dma_addr;
655 unsigned int offset = 0;
656 skb_frag_t *frag;
01f2e4ea
SF
657
658 /* Preload TCP csum field with IP pseudo hdr calculated
659 * with IP length set to zero. HW will later add in length
660 * to each TCP segment resulting from the TSO.
661 */
662
09640e63 663 if (skb->protocol == cpu_to_be16(ETH_P_IP)) {
01f2e4ea
SF
664 ip_hdr(skb)->check = 0;
665 tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
666 ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
09640e63 667 } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
01f2e4ea
SF
668 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
669 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
670 }
671
ea0d7d91
SF
672 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
673 * for the main skb fragment
674 */
675 while (frag_len_left) {
676 len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN);
677 dma_addr = pci_map_single(enic->pdev, skb->data + offset,
678 len, PCI_DMA_TODEVICE);
679 enic_queue_wq_desc_tso(wq, skb,
680 dma_addr,
681 len,
682 mss, hdr_len,
683 vlan_tag_insert, vlan_tag,
684 eop && (len == frag_len_left));
685 frag_len_left -= len;
686 offset += len;
687 }
01f2e4ea 688
ea0d7d91
SF
689 if (eop)
690 return;
691
692 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
693 * for additional data fragments
694 */
695 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
696 len_left -= frag->size;
697 frag_len_left = frag->size;
698 offset = frag->page_offset;
699
700 while (frag_len_left) {
701 len = min(frag_len_left,
702 (unsigned int)WQ_ENET_MAX_DESC_LEN);
703 dma_addr = pci_map_page(enic->pdev, frag->page,
704 offset, len,
705 PCI_DMA_TODEVICE);
706 enic_queue_wq_desc_cont(wq, skb,
707 dma_addr,
708 len,
709 (len_left == 0) &&
710 (len == frag_len_left)); /* EOP? */
711 frag_len_left -= len;
712 offset += len;
713 }
714 }
01f2e4ea
SF
715}
716
717static inline void enic_queue_wq_skb(struct enic *enic,
718 struct vnic_wq *wq, struct sk_buff *skb)
719{
720 unsigned int mss = skb_shinfo(skb)->gso_size;
721 unsigned int vlan_tag = 0;
722 int vlan_tag_insert = 0;
723
724 if (enic->vlan_group && vlan_tx_tag_present(skb)) {
725 /* VLAN tag from trunking driver */
726 vlan_tag_insert = 1;
727 vlan_tag = vlan_tx_tag_get(skb);
728 }
729
730 if (mss)
731 enic_queue_wq_skb_tso(enic, wq, skb, mss,
732 vlan_tag_insert, vlan_tag);
733 else if (skb->ip_summed == CHECKSUM_PARTIAL)
734 enic_queue_wq_skb_csum_l4(enic, wq, skb,
735 vlan_tag_insert, vlan_tag);
736 else
737 enic_queue_wq_skb_vlan(enic, wq, skb,
738 vlan_tag_insert, vlan_tag);
739}
740
ed8af6b2 741/* netif_tx_lock held, process context with BHs disabled, or BH */
61357325 742static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb,
d87fd25d 743 struct net_device *netdev)
01f2e4ea
SF
744{
745 struct enic *enic = netdev_priv(netdev);
746 struct vnic_wq *wq = &enic->wq[0];
747 unsigned long flags;
748
749 if (skb->len <= 0) {
750 dev_kfree_skb(skb);
751 return NETDEV_TX_OK;
752 }
753
754 /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
755 * which is very likely. In the off chance it's going to take
756 * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
757 */
758
759 if (skb_shinfo(skb)->gso_size == 0 &&
760 skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
761 skb_linearize(skb)) {
762 dev_kfree_skb(skb);
763 return NETDEV_TX_OK;
764 }
765
766 spin_lock_irqsave(&enic->wq_lock[0], flags);
767
ea0d7d91
SF
768 if (vnic_wq_desc_avail(wq) <
769 skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) {
01f2e4ea
SF
770 netif_stop_queue(netdev);
771 /* This is a hard error, log it */
772 printk(KERN_ERR PFX "%s: BUG! Tx ring full when "
773 "queue awake!\n", netdev->name);
774 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
775 return NETDEV_TX_BUSY;
776 }
777
778 enic_queue_wq_skb(enic, wq, skb);
779
ea0d7d91 780 if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)
01f2e4ea
SF
781 netif_stop_queue(netdev);
782
01f2e4ea
SF
783 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
784
785 return NETDEV_TX_OK;
786}
787
788/* dev_base_lock rwlock held, nominally process context */
789static struct net_device_stats *enic_get_stats(struct net_device *netdev)
790{
791 struct enic *enic = netdev_priv(netdev);
25f0a061 792 struct net_device_stats *net_stats = &netdev->stats;
01f2e4ea
SF
793 struct vnic_stats *stats;
794
795 spin_lock(&enic->devcmd_lock);
796 vnic_dev_stats_dump(enic->vdev, &stats);
797 spin_unlock(&enic->devcmd_lock);
798
25f0a061
SF
799 net_stats->tx_packets = stats->tx.tx_frames_ok;
800 net_stats->tx_bytes = stats->tx.tx_bytes_ok;
801 net_stats->tx_errors = stats->tx.tx_errors;
802 net_stats->tx_dropped = stats->tx.tx_drops;
01f2e4ea 803
25f0a061
SF
804 net_stats->rx_packets = stats->rx.rx_frames_ok;
805 net_stats->rx_bytes = stats->rx.rx_bytes_ok;
806 net_stats->rx_errors = stats->rx.rx_errors;
807 net_stats->multicast = stats->rx.rx_multicast_frames_ok;
350991e1 808 net_stats->rx_over_errors = enic->rq_truncated_pkts;
bd9fb1a4 809 net_stats->rx_crc_errors = enic->rq_bad_fcs;
350991e1 810 net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop;
01f2e4ea 811
25f0a061 812 return net_stats;
01f2e4ea
SF
813}
814
815static void enic_reset_mcaddrs(struct enic *enic)
816{
817 enic->mc_count = 0;
818}
819
820static int enic_set_mac_addr(struct net_device *netdev, char *addr)
821{
f8bd9091
SF
822 struct enic *enic = netdev_priv(netdev);
823
824 if (enic_is_dynamic(enic)) {
825 if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr))
826 return -EADDRNOTAVAIL;
827 } else {
828 if (!is_valid_ether_addr(addr))
829 return -EADDRNOTAVAIL;
830 }
01f2e4ea
SF
831
832 memcpy(netdev->dev_addr, addr, netdev->addr_len);
833
834 return 0;
835}
836
f8bd9091
SF
837static int enic_dev_add_station_addr(struct enic *enic)
838{
839 int err = 0;
840
841 if (is_valid_ether_addr(enic->netdev->dev_addr)) {
842 spin_lock(&enic->devcmd_lock);
843 err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
844 spin_unlock(&enic->devcmd_lock);
845 }
846
847 return err;
848}
849
850static int enic_dev_del_station_addr(struct enic *enic)
851{
852 int err = 0;
853
854 if (is_valid_ether_addr(enic->netdev->dev_addr)) {
855 spin_lock(&enic->devcmd_lock);
856 err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
857 spin_unlock(&enic->devcmd_lock);
858 }
859
860 return err;
861}
862
863static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
864{
865 struct enic *enic = netdev_priv(netdev);
866 struct sockaddr *saddr = p;
867 char *addr = saddr->sa_data;
868 int err;
869
870 if (netif_running(enic->netdev)) {
871 err = enic_dev_del_station_addr(enic);
872 if (err)
873 return err;
874 }
875
876 err = enic_set_mac_addr(netdev, addr);
877 if (err)
878 return err;
879
880 if (netif_running(enic->netdev)) {
881 err = enic_dev_add_station_addr(enic);
882 if (err)
883 return err;
884 }
885
886 return err;
887}
888
889static int enic_set_mac_address(struct net_device *netdev, void *p)
890{
891 return -EOPNOTSUPP;
892}
893
01f2e4ea
SF
894/* netif_tx_lock held, BHs disabled */
895static void enic_set_multicast_list(struct net_device *netdev)
896{
897 struct enic *enic = netdev_priv(netdev);
22bedad3 898 struct netdev_hw_addr *ha;
01f2e4ea
SF
899 int directed = 1;
900 int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
901 int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
902 int promisc = (netdev->flags & IFF_PROMISC) ? 1 : 0;
4cd24eaf 903 unsigned int mc_count = netdev_mc_count(netdev);
01f2e4ea 904 int allmulti = (netdev->flags & IFF_ALLMULTI) ||
641cb85e 905 mc_count > ENIC_MULTICAST_PERFECT_FILTERS;
9959a185 906 unsigned int flags = netdev->flags | (allmulti ? IFF_ALLMULTI : 0);
01f2e4ea 907 u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
01f2e4ea
SF
908 unsigned int i, j;
909
910 if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS)
911 mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
912
913 spin_lock(&enic->devcmd_lock);
914
9959a185
SF
915 if (enic->flags != flags) {
916 enic->flags = flags;
917 vnic_dev_packet_filter(enic->vdev, directed,
918 multicast, broadcast, promisc, allmulti);
919 }
01f2e4ea
SF
920
921 /* Is there an easier way? Trying to minimize to
922 * calls to add/del multicast addrs. We keep the
923 * addrs from the last call in enic->mc_addr and
924 * look for changes to add/del.
925 */
926
48e2f183 927 i = 0;
22bedad3 928 netdev_for_each_mc_addr(ha, netdev) {
48e2f183
JP
929 if (i == mc_count)
930 break;
22bedad3 931 memcpy(mc_addr[i++], ha->addr, ETH_ALEN);
01f2e4ea
SF
932 }
933
934 for (i = 0; i < enic->mc_count; i++) {
935 for (j = 0; j < mc_count; j++)
936 if (compare_ether_addr(enic->mc_addr[i],
937 mc_addr[j]) == 0)
938 break;
939 if (j == mc_count)
940 enic_del_multicast_addr(enic, enic->mc_addr[i]);
941 }
942
943 for (i = 0; i < mc_count; i++) {
944 for (j = 0; j < enic->mc_count; j++)
945 if (compare_ether_addr(mc_addr[i],
946 enic->mc_addr[j]) == 0)
947 break;
948 if (j == enic->mc_count)
949 enic_add_multicast_addr(enic, mc_addr[i]);
950 }
951
952 /* Save the list to compare against next time
953 */
954
955 for (i = 0; i < mc_count; i++)
956 memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
957
958 enic->mc_count = mc_count;
959
960 spin_unlock(&enic->devcmd_lock);
961}
962
963/* rtnl lock is held */
964static void enic_vlan_rx_register(struct net_device *netdev,
965 struct vlan_group *vlan_group)
966{
967 struct enic *enic = netdev_priv(netdev);
968 enic->vlan_group = vlan_group;
969}
970
971/* rtnl lock is held */
972static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
973{
974 struct enic *enic = netdev_priv(netdev);
975
976 spin_lock(&enic->devcmd_lock);
977 enic_add_vlan(enic, vid);
978 spin_unlock(&enic->devcmd_lock);
979}
980
981/* rtnl lock is held */
982static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
983{
984 struct enic *enic = netdev_priv(netdev);
985
986 spin_lock(&enic->devcmd_lock);
987 enic_del_vlan(enic, vid);
988 spin_unlock(&enic->devcmd_lock);
989}
990
991/* netif_tx_lock held, BHs disabled */
992static void enic_tx_timeout(struct net_device *netdev)
993{
994 struct enic *enic = netdev_priv(netdev);
995 schedule_work(&enic->reset);
996}
997
f8bd9091
SF
998static int enic_vnic_dev_deinit(struct enic *enic)
999{
1000 int err;
1001
1002 spin_lock(&enic->devcmd_lock);
1003 err = vnic_dev_deinit(enic->vdev);
1004 spin_unlock(&enic->devcmd_lock);
1005
1006 return err;
1007}
1008
1009static int enic_dev_init_prov(struct enic *enic, struct vic_provinfo *vp)
1010{
1011 int err;
1012
1013 spin_lock(&enic->devcmd_lock);
1014 err = vnic_dev_init_prov(enic->vdev,
1015 (u8 *)vp, vic_provinfo_size(vp));
1016 spin_unlock(&enic->devcmd_lock);
1017
1018 return err;
1019}
1020
1021static int enic_dev_init_done(struct enic *enic, int *done, int *error)
1022{
1023 int err;
1024
1025 spin_lock(&enic->devcmd_lock);
1026 err = vnic_dev_init_done(enic->vdev, done, error);
1027 spin_unlock(&enic->devcmd_lock);
1028
1029 return err;
1030}
1031
1032static int enic_set_port_profile(struct enic *enic, u8 request, u8 *mac,
1033 char *name, u8 *instance_uuid, u8 *host_uuid)
1034{
1035 struct vic_provinfo *vp;
1036 u8 oui[3] = VIC_PROVINFO_CISCO_OUI;
6fc7f573 1037 u8 *uuid;
f8bd9091 1038 char uuid_str[38];
6fc7f573
SF
1039 static char *uuid_fmt = "%02X%02X%02X%02X-%02X%02X-%02X%02X-"
1040 "%02X%02X-%02X%02X%02X%02X%0X%02X";
f8bd9091
SF
1041 int err;
1042
1043 if (!name)
1044 return -EINVAL;
1045
1046 if (!is_valid_ether_addr(mac))
1047 return -EADDRNOTAVAIL;
1048
1049 vp = vic_provinfo_alloc(GFP_KERNEL, oui, VIC_PROVINFO_LINUX_TYPE);
1050 if (!vp)
1051 return -ENOMEM;
1052
1053 vic_provinfo_add_tlv(vp,
1054 VIC_LINUX_PROV_TLV_PORT_PROFILE_NAME_STR,
1055 strlen(name) + 1, name);
1056
1057 vic_provinfo_add_tlv(vp,
1058 VIC_LINUX_PROV_TLV_CLIENT_MAC_ADDR,
1059 ETH_ALEN, mac);
1060
1061 if (instance_uuid) {
6fc7f573 1062 uuid = instance_uuid;
f8bd9091 1063 sprintf(uuid_str, uuid_fmt,
6fc7f573
SF
1064 uuid[0], uuid[1], uuid[2], uuid[3],
1065 uuid[4], uuid[5], uuid[6], uuid[7],
1066 uuid[8], uuid[9], uuid[10], uuid[11],
1067 uuid[12], uuid[13], uuid[14], uuid[15]);
f8bd9091
SF
1068 vic_provinfo_add_tlv(vp,
1069 VIC_LINUX_PROV_TLV_CLIENT_UUID_STR,
1070 sizeof(uuid_str), uuid_str);
1071 }
1072
1073 if (host_uuid) {
6fc7f573 1074 uuid = host_uuid;
f8bd9091 1075 sprintf(uuid_str, uuid_fmt,
6fc7f573
SF
1076 uuid[0], uuid[1], uuid[2], uuid[3],
1077 uuid[4], uuid[5], uuid[6], uuid[7],
1078 uuid[8], uuid[9], uuid[10], uuid[11],
1079 uuid[12], uuid[13], uuid[14], uuid[15]);
f8bd9091
SF
1080 vic_provinfo_add_tlv(vp,
1081 VIC_LINUX_PROV_TLV_HOST_UUID_STR,
1082 sizeof(uuid_str), uuid_str);
1083 }
1084
1085 err = enic_vnic_dev_deinit(enic);
1086 if (err)
1087 goto err_out;
1088
1089 memset(&enic->pp, 0, sizeof(enic->pp));
1090
1091 err = enic_dev_init_prov(enic, vp);
1092 if (err)
1093 goto err_out;
1094
1095 enic->pp.request = request;
1096 memcpy(enic->pp.name, name, PORT_PROFILE_MAX);
1097 if (instance_uuid)
1098 memcpy(enic->pp.instance_uuid,
1099 instance_uuid, PORT_UUID_MAX);
1100 if (host_uuid)
1101 memcpy(enic->pp.host_uuid,
1102 host_uuid, PORT_UUID_MAX);
1103
1104err_out:
1105 vic_provinfo_free(vp);
1106
1107 return err;
1108}
1109
1110static int enic_unset_port_profile(struct enic *enic)
1111{
1112 memset(&enic->pp, 0, sizeof(enic->pp));
1113 return enic_vnic_dev_deinit(enic);
1114}
1115
1116static int enic_set_vf_port(struct net_device *netdev, int vf,
1117 struct nlattr *port[])
1118{
1119 struct enic *enic = netdev_priv(netdev);
1120 char *name = NULL;
1121 u8 *instance_uuid = NULL;
1122 u8 *host_uuid = NULL;
1123 u8 request = PORT_REQUEST_DISASSOCIATE;
1124
1125 /* don't support VFs, yet */
1126 if (vf != PORT_SELF_VF)
1127 return -EOPNOTSUPP;
1128
1129 if (port[IFLA_PORT_REQUEST])
1130 request = nla_get_u8(port[IFLA_PORT_REQUEST]);
1131
1132 switch (request) {
1133 case PORT_REQUEST_ASSOCIATE:
1134
1135 if (port[IFLA_PORT_PROFILE])
1136 name = nla_data(port[IFLA_PORT_PROFILE]);
1137
1138 if (port[IFLA_PORT_INSTANCE_UUID])
1139 instance_uuid =
1140 nla_data(port[IFLA_PORT_INSTANCE_UUID]);
1141
1142 if (port[IFLA_PORT_HOST_UUID])
1143 host_uuid = nla_data(port[IFLA_PORT_HOST_UUID]);
1144
1145 return enic_set_port_profile(enic, request,
1146 netdev->dev_addr, name,
1147 instance_uuid, host_uuid);
1148
1149 case PORT_REQUEST_DISASSOCIATE:
1150
1151 return enic_unset_port_profile(enic);
1152
1153 default:
1154 break;
1155 }
1156
1157 return -EOPNOTSUPP;
1158}
1159
1160static int enic_get_vf_port(struct net_device *netdev, int vf,
1161 struct sk_buff *skb)
1162{
1163 struct enic *enic = netdev_priv(netdev);
1164 int err, error, done;
1165 u16 response = PORT_PROFILE_RESPONSE_SUCCESS;
1166
1167 /* don't support VFs, yet */
1168 if (vf != PORT_SELF_VF)
1169 return -EOPNOTSUPP;
1170
1171 err = enic_dev_init_done(enic, &done, &error);
1172
1173 if (err)
1174 return err;
1175
1176 switch (error) {
1177 case ERR_SUCCESS:
1178 if (!done)
1179 response = PORT_PROFILE_RESPONSE_INPROGRESS;
1180 break;
1181 case ERR_EINVAL:
1182 response = PORT_PROFILE_RESPONSE_INVALID;
1183 break;
1184 case ERR_EBADSTATE:
1185 response = PORT_PROFILE_RESPONSE_BADSTATE;
1186 break;
1187 case ERR_ENOMEM:
1188 response = PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES;
1189 break;
1190 default:
1191 response = PORT_PROFILE_RESPONSE_ERROR;
1192 break;
1193 }
1194
1195 NLA_PUT_U16(skb, IFLA_PORT_REQUEST, enic->pp.request);
1196 NLA_PUT_U16(skb, IFLA_PORT_RESPONSE, response);
1197 NLA_PUT(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX,
1198 enic->pp.name);
1199 NLA_PUT(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX,
1200 enic->pp.instance_uuid);
1201 NLA_PUT(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX,
1202 enic->pp.host_uuid);
1203
1204 return 0;
1205
1206nla_put_failure:
1207 return -EMSGSIZE;
1208}
1209
01f2e4ea
SF
1210static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
1211{
1212 struct enic *enic = vnic_dev_priv(rq->vdev);
1213
1214 if (!buf->os_buf)
1215 return;
1216
1217 pci_unmap_single(enic->pdev, buf->dma_addr,
1218 buf->len, PCI_DMA_FROMDEVICE);
1219 dev_kfree_skb_any(buf->os_buf);
1220}
1221
01f2e4ea
SF
1222static int enic_rq_alloc_buf(struct vnic_rq *rq)
1223{
1224 struct enic *enic = vnic_dev_priv(rq->vdev);
d19e22dc 1225 struct net_device *netdev = enic->netdev;
01f2e4ea 1226 struct sk_buff *skb;
d19e22dc 1227 unsigned int len = netdev->mtu + ETH_HLEN;
01f2e4ea
SF
1228 unsigned int os_buf_index = 0;
1229 dma_addr_t dma_addr;
1230
89d71a66 1231 skb = netdev_alloc_skb_ip_align(netdev, len);
01f2e4ea
SF
1232 if (!skb)
1233 return -ENOMEM;
1234
1235 dma_addr = pci_map_single(enic->pdev, skb->data,
1236 len, PCI_DMA_FROMDEVICE);
1237
1238 enic_queue_rq_desc(rq, skb, os_buf_index,
1239 dma_addr, len);
1240
1241 return 0;
1242}
1243
4badc385
SF
1244static int enic_rq_alloc_buf_a1(struct vnic_rq *rq)
1245{
1246 struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
1247
1248 if (vnic_rq_posting_soon(rq)) {
1249
1250 /* SW workaround for A0 HW erratum: if we're just about
1251 * to write posted_index, insert a dummy desc
1252 * of type resvd
1253 */
1254
1255 rq_enet_desc_enc(desc, 0, RQ_ENET_TYPE_RESV2, 0);
1256 vnic_rq_post(rq, 0, 0, 0, 0);
1257 } else {
1258 return enic_rq_alloc_buf(rq);
1259 }
1260
1261 return 0;
1262}
1263
1264static int enic_set_rq_alloc_buf(struct enic *enic)
1265{
1266 enum vnic_dev_hw_version hw_ver;
1267 int err;
1268
1269 err = vnic_dev_hw_version(enic->vdev, &hw_ver);
1270 if (err)
1271 return err;
1272
1273 switch (hw_ver) {
1274 case VNIC_DEV_HW_VER_A1:
1275 enic->rq_alloc_buf = enic_rq_alloc_buf_a1;
1276 break;
1277 case VNIC_DEV_HW_VER_A2:
1278 case VNIC_DEV_HW_VER_UNKNOWN:
1279 enic->rq_alloc_buf = enic_rq_alloc_buf;
1280 break;
1281 default:
1282 return -ENODEV;
1283 }
1284
1285 return 0;
1286}
1287
01f2e4ea
SF
1288static int enic_get_skb_header(struct sk_buff *skb, void **iphdr,
1289 void **tcph, u64 *hdr_flags, void *priv)
1290{
1291 struct cq_enet_rq_desc *cq_desc = priv;
1292 unsigned int ip_len;
1293 struct iphdr *iph;
1294
1295 u8 type, color, eop, sop, ingress_port, vlan_stripped;
1296 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
1297 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
1298 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
1299 u8 packet_error;
1300 u16 q_number, completed_index, bytes_written, vlan, checksum;
1301 u32 rss_hash;
1302
1303 cq_enet_rq_desc_dec(cq_desc,
1304 &type, &color, &q_number, &completed_index,
1305 &ingress_port, &fcoe, &eop, &sop, &rss_type,
1306 &csum_not_calc, &rss_hash, &bytes_written,
1307 &packet_error, &vlan_stripped, &vlan, &checksum,
1308 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
1309 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
1310 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
1311 &fcs_ok);
1312
1313 if (!(ipv4 && tcp && !ipv4_fragment))
1314 return -1;
1315
1316 skb_reset_network_header(skb);
1317 iph = ip_hdr(skb);
1318
1319 ip_len = ip_hdrlen(skb);
1320 skb_set_transport_header(skb, ip_len);
1321
1322 /* check if ip header and tcp header are complete */
1323 if (ntohs(iph->tot_len) < ip_len + tcp_hdrlen(skb))
1324 return -1;
1325
1326 *hdr_flags = LRO_IPV4 | LRO_TCP;
1327 *tcph = tcp_hdr(skb);
1328 *iphdr = iph;
1329
1330 return 0;
1331}
1332
1333static void enic_rq_indicate_buf(struct vnic_rq *rq,
1334 struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
1335 int skipped, void *opaque)
1336{
1337 struct enic *enic = vnic_dev_priv(rq->vdev);
86ca9db7 1338 struct net_device *netdev = enic->netdev;
01f2e4ea
SF
1339 struct sk_buff *skb;
1340
1341 u8 type, color, eop, sop, ingress_port, vlan_stripped;
1342 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
1343 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
1344 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
1345 u8 packet_error;
1346 u16 q_number, completed_index, bytes_written, vlan, checksum;
1347 u32 rss_hash;
1348
1349 if (skipped)
1350 return;
1351
1352 skb = buf->os_buf;
1353 prefetch(skb->data - NET_IP_ALIGN);
1354 pci_unmap_single(enic->pdev, buf->dma_addr,
1355 buf->len, PCI_DMA_FROMDEVICE);
1356
1357 cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
1358 &type, &color, &q_number, &completed_index,
1359 &ingress_port, &fcoe, &eop, &sop, &rss_type,
1360 &csum_not_calc, &rss_hash, &bytes_written,
1361 &packet_error, &vlan_stripped, &vlan, &checksum,
1362 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
1363 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
1364 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
1365 &fcs_ok);
1366
1367 if (packet_error) {
1368
350991e1
SF
1369 if (!fcs_ok) {
1370 if (bytes_written > 0)
1371 enic->rq_bad_fcs++;
1372 else if (bytes_written == 0)
1373 enic->rq_truncated_pkts++;
1374 }
01f2e4ea
SF
1375
1376 dev_kfree_skb_any(skb);
1377
1378 return;
1379 }
1380
1381 if (eop && bytes_written > 0) {
1382
1383 /* Good receive
1384 */
1385
1386 skb_put(skb, bytes_written);
86ca9db7 1387 skb->protocol = eth_type_trans(skb, netdev);
01f2e4ea
SF
1388
1389 if (enic->csum_rx_enabled && !csum_not_calc) {
1390 skb->csum = htons(checksum);
1391 skb->ip_summed = CHECKSUM_COMPLETE;
1392 }
1393
86ca9db7 1394 skb->dev = netdev;
01f2e4ea
SF
1395
1396 if (enic->vlan_group && vlan_stripped) {
1397
86ca9db7 1398 if ((netdev->features & NETIF_F_LRO) && ipv4)
01f2e4ea
SF
1399 lro_vlan_hwaccel_receive_skb(&enic->lro_mgr,
1400 skb, enic->vlan_group,
1401 vlan, cq_desc);
1402 else
1403 vlan_hwaccel_receive_skb(skb,
1404 enic->vlan_group, vlan);
1405
1406 } else {
1407
86ca9db7 1408 if ((netdev->features & NETIF_F_LRO) && ipv4)
01f2e4ea
SF
1409 lro_receive_skb(&enic->lro_mgr, skb, cq_desc);
1410 else
1411 netif_receive_skb(skb);
1412
1413 }
1414
1415 } else {
1416
1417 /* Buffer overflow
1418 */
1419
1420 dev_kfree_skb_any(skb);
1421 }
1422}
1423
1424static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
1425 u8 type, u16 q_number, u16 completed_index, void *opaque)
1426{
1427 struct enic *enic = vnic_dev_priv(vdev);
1428
1429 vnic_rq_service(&enic->rq[q_number], cq_desc,
1430 completed_index, VNIC_RQ_RETURN_DESC,
1431 enic_rq_indicate_buf, opaque);
1432
1433 return 0;
1434}
1435
01f2e4ea
SF
1436static int enic_poll(struct napi_struct *napi, int budget)
1437{
1438 struct enic *enic = container_of(napi, struct enic, napi);
1439 struct net_device *netdev = enic->netdev;
1440 unsigned int rq_work_to_do = budget;
1441 unsigned int wq_work_to_do = -1; /* no limit */
1442 unsigned int work_done, rq_work_done, wq_work_done;
2d6ddced 1443 int err;
01f2e4ea
SF
1444
1445 /* Service RQ (first) and WQ
1446 */
1447
1448 rq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
1449 rq_work_to_do, enic_rq_service, NULL);
1450
1451 wq_work_done = vnic_cq_service(&enic->cq[ENIC_CQ_WQ],
1452 wq_work_to_do, enic_wq_service, NULL);
1453
1454 /* Accumulate intr event credits for this polling
1455 * cycle. An intr event is the completion of a
1456 * a WQ or RQ packet.
1457 */
1458
1459 work_done = rq_work_done + wq_work_done;
1460
1461 if (work_done > 0)
1462 vnic_intr_return_credits(&enic->intr[ENIC_INTX_WQ_RQ],
1463 work_done,
1464 0 /* don't unmask intr */,
1465 0 /* don't reset intr timer */);
1466
2d6ddced 1467 err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
01f2e4ea 1468
2d6ddced
SF
1469 /* Buffer allocation failed. Stay in polling
1470 * mode so we can try to fill the ring again.
1471 */
01f2e4ea 1472
2d6ddced
SF
1473 if (err)
1474 rq_work_done = rq_work_to_do;
01f2e4ea 1475
2d6ddced 1476 if (rq_work_done < rq_work_to_do) {
01f2e4ea 1477
2d6ddced
SF
1478 /* Some work done, but not enough to stay in polling,
1479 * flush all LROs and exit polling
01f2e4ea
SF
1480 */
1481
86ca9db7 1482 if (netdev->features & NETIF_F_LRO)
01f2e4ea
SF
1483 lro_flush_all(&enic->lro_mgr);
1484
288379f0 1485 napi_complete(napi);
ed8af6b2 1486 vnic_intr_unmask(&enic->intr[ENIC_INTX_WQ_RQ]);
01f2e4ea
SF
1487 }
1488
1489 return rq_work_done;
1490}
1491
1492static int enic_poll_msix(struct napi_struct *napi, int budget)
1493{
1494 struct enic *enic = container_of(napi, struct enic, napi);
1495 struct net_device *netdev = enic->netdev;
1496 unsigned int work_to_do = budget;
1497 unsigned int work_done;
2d6ddced 1498 int err;
01f2e4ea
SF
1499
1500 /* Service RQ
1501 */
1502
1503 work_done = vnic_cq_service(&enic->cq[ENIC_CQ_RQ],
1504 work_to_do, enic_rq_service, NULL);
1505
2d6ddced
SF
1506 /* Return intr event credits for this polling
1507 * cycle. An intr event is the completion of a
1508 * RQ packet.
1509 */
01f2e4ea 1510
2d6ddced 1511 if (work_done > 0)
01f2e4ea
SF
1512 vnic_intr_return_credits(&enic->intr[ENIC_MSIX_RQ],
1513 work_done,
1514 0 /* don't unmask intr */,
1515 0 /* don't reset intr timer */);
01f2e4ea 1516
2d6ddced
SF
1517 err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
1518
1519 /* Buffer allocation failed. Stay in polling mode
1520 * so we can try to fill the ring again.
1521 */
1522
1523 if (err)
1524 work_done = work_to_do;
1525
1526 if (work_done < work_to_do) {
1527
1528 /* Some work done, but not enough to stay in polling,
1529 * flush all LROs and exit polling
01f2e4ea
SF
1530 */
1531
86ca9db7 1532 if (netdev->features & NETIF_F_LRO)
01f2e4ea
SF
1533 lro_flush_all(&enic->lro_mgr);
1534
288379f0 1535 napi_complete(napi);
01f2e4ea
SF
1536 vnic_intr_unmask(&enic->intr[ENIC_MSIX_RQ]);
1537 }
1538
1539 return work_done;
1540}
1541
1542static void enic_notify_timer(unsigned long data)
1543{
1544 struct enic *enic = (struct enic *)data;
1545
1546 enic_notify_check(enic);
1547
25f0a061
SF
1548 mod_timer(&enic->notify_timer,
1549 round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
01f2e4ea
SF
1550}
1551
1552static void enic_free_intr(struct enic *enic)
1553{
1554 struct net_device *netdev = enic->netdev;
1555 unsigned int i;
1556
1557 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1558 case VNIC_DEV_INTR_MODE_INTX:
01f2e4ea
SF
1559 free_irq(enic->pdev->irq, netdev);
1560 break;
8f4d248c
SF
1561 case VNIC_DEV_INTR_MODE_MSI:
1562 free_irq(enic->pdev->irq, enic);
1563 break;
01f2e4ea
SF
1564 case VNIC_DEV_INTR_MODE_MSIX:
1565 for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
1566 if (enic->msix[i].requested)
1567 free_irq(enic->msix_entry[i].vector,
1568 enic->msix[i].devid);
1569 break;
1570 default:
1571 break;
1572 }
1573}
1574
1575static int enic_request_intr(struct enic *enic)
1576{
1577 struct net_device *netdev = enic->netdev;
1578 unsigned int i;
1579 int err = 0;
1580
1581 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1582
1583 case VNIC_DEV_INTR_MODE_INTX:
1584
1585 err = request_irq(enic->pdev->irq, enic_isr_legacy,
1586 IRQF_SHARED, netdev->name, netdev);
1587 break;
1588
1589 case VNIC_DEV_INTR_MODE_MSI:
1590
1591 err = request_irq(enic->pdev->irq, enic_isr_msi,
1592 0, netdev->name, enic);
1593 break;
1594
1595 case VNIC_DEV_INTR_MODE_MSIX:
1596
1597 sprintf(enic->msix[ENIC_MSIX_RQ].devname,
8f4d248c 1598 "%.11s-rx-0", netdev->name);
01f2e4ea
SF
1599 enic->msix[ENIC_MSIX_RQ].isr = enic_isr_msix_rq;
1600 enic->msix[ENIC_MSIX_RQ].devid = enic;
1601
1602 sprintf(enic->msix[ENIC_MSIX_WQ].devname,
8f4d248c 1603 "%.11s-tx-0", netdev->name);
01f2e4ea
SF
1604 enic->msix[ENIC_MSIX_WQ].isr = enic_isr_msix_wq;
1605 enic->msix[ENIC_MSIX_WQ].devid = enic;
1606
1607 sprintf(enic->msix[ENIC_MSIX_ERR].devname,
1608 "%.11s-err", netdev->name);
1609 enic->msix[ENIC_MSIX_ERR].isr = enic_isr_msix_err;
1610 enic->msix[ENIC_MSIX_ERR].devid = enic;
1611
1612 sprintf(enic->msix[ENIC_MSIX_NOTIFY].devname,
1613 "%.11s-notify", netdev->name);
1614 enic->msix[ENIC_MSIX_NOTIFY].isr = enic_isr_msix_notify;
1615 enic->msix[ENIC_MSIX_NOTIFY].devid = enic;
1616
1617 for (i = 0; i < ARRAY_SIZE(enic->msix); i++) {
1618 err = request_irq(enic->msix_entry[i].vector,
1619 enic->msix[i].isr, 0,
1620 enic->msix[i].devname,
1621 enic->msix[i].devid);
1622 if (err) {
1623 enic_free_intr(enic);
1624 break;
1625 }
1626 enic->msix[i].requested = 1;
1627 }
1628
1629 break;
1630
1631 default:
1632 break;
1633 }
1634
1635 return err;
1636}
1637
b3d18d19
SF
1638static void enic_synchronize_irqs(struct enic *enic)
1639{
1640 unsigned int i;
1641
1642 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1643 case VNIC_DEV_INTR_MODE_INTX:
1644 case VNIC_DEV_INTR_MODE_MSI:
1645 synchronize_irq(enic->pdev->irq);
1646 break;
1647 case VNIC_DEV_INTR_MODE_MSIX:
1648 for (i = 0; i < enic->intr_count; i++)
1649 synchronize_irq(enic->msix_entry[i].vector);
1650 break;
1651 default:
1652 break;
1653 }
1654}
1655
01f2e4ea
SF
1656static int enic_notify_set(struct enic *enic)
1657{
1658 int err;
1659
56ac88b3 1660 spin_lock(&enic->devcmd_lock);
01f2e4ea
SF
1661 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1662 case VNIC_DEV_INTR_MODE_INTX:
1663 err = vnic_dev_notify_set(enic->vdev, ENIC_INTX_NOTIFY);
1664 break;
1665 case VNIC_DEV_INTR_MODE_MSIX:
1666 err = vnic_dev_notify_set(enic->vdev, ENIC_MSIX_NOTIFY);
1667 break;
1668 default:
1669 err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
1670 break;
1671 }
56ac88b3 1672 spin_unlock(&enic->devcmd_lock);
01f2e4ea
SF
1673
1674 return err;
1675}
1676
1677static void enic_notify_timer_start(struct enic *enic)
1678{
1679 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1680 case VNIC_DEV_INTR_MODE_MSI:
1681 mod_timer(&enic->notify_timer, jiffies);
1682 break;
1683 default:
1684 /* Using intr for notification for INTx/MSI-X */
1685 break;
1686 };
1687}
1688
1689/* rtnl lock is held, process context */
1690static int enic_open(struct net_device *netdev)
1691{
1692 struct enic *enic = netdev_priv(netdev);
1693 unsigned int i;
1694 int err;
1695
4b75a442
SF
1696 err = enic_request_intr(enic);
1697 if (err) {
1698 printk(KERN_ERR PFX "%s: Unable to request irq.\n",
1699 netdev->name);
1700 return err;
1701 }
1702
1703 err = enic_notify_set(enic);
1704 if (err) {
1705 printk(KERN_ERR PFX
1706 "%s: Failed to alloc notify buffer, aborting.\n",
1707 netdev->name);
1708 goto err_out_free_intr;
1709 }
1710
01f2e4ea 1711 for (i = 0; i < enic->rq_count; i++) {
2d6ddced
SF
1712 vnic_rq_fill(&enic->rq[i], enic->rq_alloc_buf);
1713 /* Need at least one buffer on ring to get going */
1714 if (vnic_rq_desc_used(&enic->rq[i]) == 0) {
01f2e4ea
SF
1715 printk(KERN_ERR PFX
1716 "%s: Unable to alloc receive buffers.\n",
1717 netdev->name);
2d6ddced 1718 err = -ENOMEM;
4b75a442 1719 goto err_out_notify_unset;
01f2e4ea
SF
1720 }
1721 }
1722
1723 for (i = 0; i < enic->wq_count; i++)
1724 vnic_wq_enable(&enic->wq[i]);
1725 for (i = 0; i < enic->rq_count; i++)
1726 vnic_rq_enable(&enic->rq[i]);
1727
f8bd9091 1728 enic_dev_add_station_addr(enic);
01f2e4ea
SF
1729 enic_set_multicast_list(netdev);
1730
1731 netif_wake_queue(netdev);
1732 napi_enable(&enic->napi);
56ac88b3 1733 spin_lock(&enic->devcmd_lock);
01f2e4ea 1734 vnic_dev_enable(enic->vdev);
56ac88b3 1735 spin_unlock(&enic->devcmd_lock);
01f2e4ea
SF
1736
1737 for (i = 0; i < enic->intr_count; i++)
1738 vnic_intr_unmask(&enic->intr[i]);
1739
1740 enic_notify_timer_start(enic);
1741
1742 return 0;
4b75a442
SF
1743
1744err_out_notify_unset:
56ac88b3 1745 spin_lock(&enic->devcmd_lock);
4b75a442 1746 vnic_dev_notify_unset(enic->vdev);
56ac88b3 1747 spin_unlock(&enic->devcmd_lock);
4b75a442
SF
1748err_out_free_intr:
1749 enic_free_intr(enic);
1750
1751 return err;
01f2e4ea
SF
1752}
1753
1754/* rtnl lock is held, process context */
1755static int enic_stop(struct net_device *netdev)
1756{
1757 struct enic *enic = netdev_priv(netdev);
1758 unsigned int i;
1759 int err;
1760
b3d18d19
SF
1761 for (i = 0; i < enic->intr_count; i++)
1762 vnic_intr_mask(&enic->intr[i]);
1763
1764 enic_synchronize_irqs(enic);
1765
01f2e4ea
SF
1766 del_timer_sync(&enic->notify_timer);
1767
56ac88b3 1768 spin_lock(&enic->devcmd_lock);
01f2e4ea 1769 vnic_dev_disable(enic->vdev);
56ac88b3 1770 spin_unlock(&enic->devcmd_lock);
01f2e4ea 1771 napi_disable(&enic->napi);
b3d18d19
SF
1772 netif_carrier_off(netdev);
1773 netif_tx_disable(netdev);
01f2e4ea 1774
f8bd9091
SF
1775 enic_dev_del_station_addr(enic);
1776
01f2e4ea
SF
1777 for (i = 0; i < enic->wq_count; i++) {
1778 err = vnic_wq_disable(&enic->wq[i]);
1779 if (err)
1780 return err;
1781 }
1782 for (i = 0; i < enic->rq_count; i++) {
1783 err = vnic_rq_disable(&enic->rq[i]);
1784 if (err)
1785 return err;
1786 }
1787
56ac88b3 1788 spin_lock(&enic->devcmd_lock);
4b75a442 1789 vnic_dev_notify_unset(enic->vdev);
56ac88b3 1790 spin_unlock(&enic->devcmd_lock);
4b75a442
SF
1791 enic_free_intr(enic);
1792
01f2e4ea
SF
1793 for (i = 0; i < enic->wq_count; i++)
1794 vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
1795 for (i = 0; i < enic->rq_count; i++)
1796 vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
1797 for (i = 0; i < enic->cq_count; i++)
1798 vnic_cq_clean(&enic->cq[i]);
1799 for (i = 0; i < enic->intr_count; i++)
1800 vnic_intr_clean(&enic->intr[i]);
1801
1802 return 0;
1803}
1804
1805static int enic_change_mtu(struct net_device *netdev, int new_mtu)
1806{
1807 struct enic *enic = netdev_priv(netdev);
1808 int running = netif_running(netdev);
1809
25f0a061
SF
1810 if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
1811 return -EINVAL;
1812
01f2e4ea
SF
1813 if (running)
1814 enic_stop(netdev);
1815
01f2e4ea
SF
1816 netdev->mtu = new_mtu;
1817
1818 if (netdev->mtu > enic->port_mtu)
1819 printk(KERN_WARNING PFX
1820 "%s: interface MTU (%d) set higher "
1821 "than port MTU (%d)\n",
1822 netdev->name, netdev->mtu, enic->port_mtu);
1823
1824 if (running)
1825 enic_open(netdev);
1826
1827 return 0;
1828}
1829
1830#ifdef CONFIG_NET_POLL_CONTROLLER
1831static void enic_poll_controller(struct net_device *netdev)
1832{
1833 struct enic *enic = netdev_priv(netdev);
1834 struct vnic_dev *vdev = enic->vdev;
1835
1836 switch (vnic_dev_get_intr_mode(vdev)) {
1837 case VNIC_DEV_INTR_MODE_MSIX:
1838 enic_isr_msix_rq(enic->pdev->irq, enic);
1839 enic_isr_msix_wq(enic->pdev->irq, enic);
1840 break;
1841 case VNIC_DEV_INTR_MODE_MSI:
1842 enic_isr_msi(enic->pdev->irq, enic);
1843 break;
1844 case VNIC_DEV_INTR_MODE_INTX:
1845 enic_isr_legacy(enic->pdev->irq, netdev);
1846 break;
1847 default:
1848 break;
1849 }
1850}
1851#endif
1852
1853static int enic_dev_wait(struct vnic_dev *vdev,
1854 int (*start)(struct vnic_dev *, int),
1855 int (*finished)(struct vnic_dev *, int *),
1856 int arg)
1857{
1858 unsigned long time;
1859 int done;
1860 int err;
1861
1862 BUG_ON(in_interrupt());
1863
1864 err = start(vdev, arg);
1865 if (err)
1866 return err;
1867
1868 /* Wait for func to complete...2 seconds max
1869 */
1870
1871 time = jiffies + (HZ * 2);
1872 do {
1873
1874 err = finished(vdev, &done);
1875 if (err)
1876 return err;
1877
1878 if (done)
1879 return 0;
1880
1881 schedule_timeout_uninterruptible(HZ / 10);
1882
1883 } while (time_after(time, jiffies));
1884
1885 return -ETIMEDOUT;
1886}
1887
1888static int enic_dev_open(struct enic *enic)
1889{
1890 int err;
1891
1892 err = enic_dev_wait(enic->vdev, vnic_dev_open,
1893 vnic_dev_open_done, 0);
1894 if (err)
1895 printk(KERN_ERR PFX
1896 "vNIC device open failed, err %d.\n", err);
1897
1898 return err;
1899}
1900
1901static int enic_dev_soft_reset(struct enic *enic)
1902{
1903 int err;
1904
1905 err = enic_dev_wait(enic->vdev, vnic_dev_soft_reset,
1906 vnic_dev_soft_reset_done, 0);
1907 if (err)
1908 printk(KERN_ERR PFX
1909 "vNIC soft reset failed, err %d.\n", err);
1910
1911 return err;
1912}
1913
68f71708
SF
1914static int enic_set_niccfg(struct enic *enic)
1915{
1916 const u8 rss_default_cpu = 0;
1917 const u8 rss_hash_type = 0;
1918 const u8 rss_hash_bits = 0;
1919 const u8 rss_base_cpu = 0;
1920 const u8 rss_enable = 0;
1921 const u8 tso_ipid_split_en = 0;
1922 const u8 ig_vlan_strip_en = 1;
1923
1924 /* Enable VLAN tag stripping. RSS not enabled (yet).
6ba9cdc0 1925 */
68f71708
SF
1926
1927 return enic_set_nic_cfg(enic,
1928 rss_default_cpu, rss_hash_type,
1929 rss_hash_bits, rss_base_cpu,
1930 rss_enable, tso_ipid_split_en,
1931 ig_vlan_strip_en);
1932}
1933
01f2e4ea
SF
1934static void enic_reset(struct work_struct *work)
1935{
1936 struct enic *enic = container_of(work, struct enic, reset);
1937
1938 if (!netif_running(enic->netdev))
1939 return;
1940
1941 rtnl_lock();
1942
1943 spin_lock(&enic->devcmd_lock);
1944 vnic_dev_hang_notify(enic->vdev);
1945 spin_unlock(&enic->devcmd_lock);
1946
1947 enic_stop(enic->netdev);
1948 enic_dev_soft_reset(enic);
68f71708 1949 vnic_dev_init(enic->vdev, 0);
01f2e4ea
SF
1950 enic_reset_mcaddrs(enic);
1951 enic_init_vnic_resources(enic);
68f71708 1952 enic_set_niccfg(enic);
01f2e4ea
SF
1953 enic_open(enic->netdev);
1954
1955 rtnl_unlock();
1956}
1957
1958static int enic_set_intr_mode(struct enic *enic)
1959{
6ba9cdc0
SF
1960 unsigned int n = 1;
1961 unsigned int m = 1;
01f2e4ea
SF
1962 unsigned int i;
1963
1964 /* Set interrupt mode (INTx, MSI, MSI-X) depending
1965 * system capabilities.
1966 *
1967 * Try MSI-X first
1968 *
1969 * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
1970 * (the second to last INTR is used for WQ/RQ errors)
1971 * (the last INTR is used for notifications)
1972 */
1973
1974 BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
1975 for (i = 0; i < n + m + 2; i++)
1976 enic->msix_entry[i].entry = i;
1977
1978 if (enic->config.intr_mode < 1 &&
1979 enic->rq_count >= n &&
1980 enic->wq_count >= m &&
1981 enic->cq_count >= n + m &&
1982 enic->intr_count >= n + m + 2 &&
1983 !pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
1984
1985 enic->rq_count = n;
1986 enic->wq_count = m;
1987 enic->cq_count = n + m;
1988 enic->intr_count = n + m + 2;
1989
1990 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSIX);
1991
1992 return 0;
1993 }
1994
1995 /* Next try MSI
1996 *
1997 * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
1998 */
1999
2000 if (enic->config.intr_mode < 2 &&
2001 enic->rq_count >= 1 &&
2002 enic->wq_count >= 1 &&
2003 enic->cq_count >= 2 &&
2004 enic->intr_count >= 1 &&
2005 !pci_enable_msi(enic->pdev)) {
2006
2007 enic->rq_count = 1;
2008 enic->wq_count = 1;
2009 enic->cq_count = 2;
2010 enic->intr_count = 1;
2011
2012 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
2013
2014 return 0;
2015 }
2016
2017 /* Next try INTx
2018 *
2019 * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
2020 * (the first INTR is used for WQ/RQ)
2021 * (the second INTR is used for WQ/RQ errors)
2022 * (the last INTR is used for notifications)
2023 */
2024
2025 if (enic->config.intr_mode < 3 &&
2026 enic->rq_count >= 1 &&
2027 enic->wq_count >= 1 &&
2028 enic->cq_count >= 2 &&
2029 enic->intr_count >= 3) {
2030
2031 enic->rq_count = 1;
2032 enic->wq_count = 1;
2033 enic->cq_count = 2;
2034 enic->intr_count = 3;
2035
2036 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
2037
2038 return 0;
2039 }
2040
2041 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2042
2043 return -EINVAL;
2044}
2045
2046static void enic_clear_intr_mode(struct enic *enic)
2047{
2048 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2049 case VNIC_DEV_INTR_MODE_MSIX:
2050 pci_disable_msix(enic->pdev);
2051 break;
2052 case VNIC_DEV_INTR_MODE_MSI:
2053 pci_disable_msi(enic->pdev);
2054 break;
2055 default:
2056 break;
2057 }
2058
2059 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2060}
2061
f8bd9091
SF
2062static const struct net_device_ops enic_netdev_dynamic_ops = {
2063 .ndo_open = enic_open,
2064 .ndo_stop = enic_stop,
2065 .ndo_start_xmit = enic_hard_start_xmit,
2066 .ndo_get_stats = enic_get_stats,
2067 .ndo_validate_addr = eth_validate_addr,
2068 .ndo_set_multicast_list = enic_set_multicast_list,
2069 .ndo_set_mac_address = enic_set_mac_address_dynamic,
2070 .ndo_change_mtu = enic_change_mtu,
2071 .ndo_vlan_rx_register = enic_vlan_rx_register,
2072 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2073 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2074 .ndo_tx_timeout = enic_tx_timeout,
2075 .ndo_set_vf_port = enic_set_vf_port,
2076 .ndo_get_vf_port = enic_get_vf_port,
2077#ifdef CONFIG_NET_POLL_CONTROLLER
2078 .ndo_poll_controller = enic_poll_controller,
2079#endif
2080};
2081
afe29f7a
SH
2082static const struct net_device_ops enic_netdev_ops = {
2083 .ndo_open = enic_open,
2084 .ndo_stop = enic_stop,
00829823 2085 .ndo_start_xmit = enic_hard_start_xmit,
afe29f7a
SH
2086 .ndo_get_stats = enic_get_stats,
2087 .ndo_validate_addr = eth_validate_addr,
2088 .ndo_set_multicast_list = enic_set_multicast_list,
f8bd9091 2089 .ndo_set_mac_address = enic_set_mac_address,
afe29f7a
SH
2090 .ndo_change_mtu = enic_change_mtu,
2091 .ndo_vlan_rx_register = enic_vlan_rx_register,
2092 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2093 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2094 .ndo_tx_timeout = enic_tx_timeout,
2095#ifdef CONFIG_NET_POLL_CONTROLLER
2096 .ndo_poll_controller = enic_poll_controller,
2097#endif
2098};
2099
6fdfa970
SF
2100void enic_dev_deinit(struct enic *enic)
2101{
2102 netif_napi_del(&enic->napi);
2103 enic_free_vnic_resources(enic);
2104 enic_clear_intr_mode(enic);
2105}
2106
2107int enic_dev_init(struct enic *enic)
2108{
2109 struct net_device *netdev = enic->netdev;
2110 int err;
2111
2112 /* Get vNIC configuration
2113 */
2114
2115 err = enic_get_vnic_config(enic);
2116 if (err) {
2117 printk(KERN_ERR PFX
2118 "Get vNIC configuration failed, aborting.\n");
2119 return err;
2120 }
2121
2122 /* Get available resource counts
2123 */
2124
2125 enic_get_res_counts(enic);
2126
2127 /* Set interrupt mode based on resource counts and system
2128 * capabilities
2129 */
2130
2131 err = enic_set_intr_mode(enic);
2132 if (err) {
2133 printk(KERN_ERR PFX
d87fd25d
SF
2134 "Failed to set intr mode based on resource "
2135 "counts and system capabilities, aborting.\n");
6fdfa970
SF
2136 return err;
2137 }
2138
2139 /* Allocate and configure vNIC resources
2140 */
2141
2142 err = enic_alloc_vnic_resources(enic);
2143 if (err) {
2144 printk(KERN_ERR PFX
2145 "Failed to alloc vNIC resources, aborting.\n");
2146 goto err_out_free_vnic_resources;
2147 }
2148
2149 enic_init_vnic_resources(enic);
2150
2151 err = enic_set_rq_alloc_buf(enic);
2152 if (err) {
2153 printk(KERN_ERR PFX
2154 "Failed to set RQ buffer allocator, aborting.\n");
2155 goto err_out_free_vnic_resources;
2156 }
2157
2158 err = enic_set_niccfg(enic);
2159 if (err) {
2160 printk(KERN_ERR PFX
2161 "Failed to config nic, aborting.\n");
2162 goto err_out_free_vnic_resources;
2163 }
2164
2165 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2166 default:
2167 netif_napi_add(netdev, &enic->napi, enic_poll, 64);
2168 break;
2169 case VNIC_DEV_INTR_MODE_MSIX:
2170 netif_napi_add(netdev, &enic->napi, enic_poll_msix, 64);
2171 break;
2172 }
2173
2174 return 0;
2175
2176err_out_free_vnic_resources:
2177 enic_clear_intr_mode(enic);
2178 enic_free_vnic_resources(enic);
2179
2180 return err;
2181}
2182
27e6c7d3
SF
2183static void enic_iounmap(struct enic *enic)
2184{
2185 unsigned int i;
2186
2187 for (i = 0; i < ARRAY_SIZE(enic->bar); i++)
2188 if (enic->bar[i].vaddr)
2189 iounmap(enic->bar[i].vaddr);
2190}
2191
01f2e4ea
SF
2192static int __devinit enic_probe(struct pci_dev *pdev,
2193 const struct pci_device_id *ent)
2194{
2195 struct net_device *netdev;
2196 struct enic *enic;
2197 int using_dac = 0;
2198 unsigned int i;
2199 int err;
2200
01f2e4ea
SF
2201 /* Allocate net device structure and initialize. Private
2202 * instance data is initialized to zero.
2203 */
2204
2205 netdev = alloc_etherdev(sizeof(struct enic));
2206 if (!netdev) {
2207 printk(KERN_ERR PFX "Etherdev alloc failed, aborting.\n");
2208 return -ENOMEM;
2209 }
2210
01f2e4ea
SF
2211 pci_set_drvdata(pdev, netdev);
2212
2213 SET_NETDEV_DEV(netdev, &pdev->dev);
2214
2215 enic = netdev_priv(netdev);
2216 enic->netdev = netdev;
2217 enic->pdev = pdev;
2218
2219 /* Setup PCI resources
2220 */
2221
2222 err = pci_enable_device(pdev);
2223 if (err) {
2224 printk(KERN_ERR PFX
4b75a442 2225 "Cannot enable PCI device, aborting.\n");
01f2e4ea
SF
2226 goto err_out_free_netdev;
2227 }
2228
2229 err = pci_request_regions(pdev, DRV_NAME);
2230 if (err) {
2231 printk(KERN_ERR PFX
4b75a442 2232 "Cannot request PCI regions, aborting.\n");
01f2e4ea
SF
2233 goto err_out_disable_device;
2234 }
2235
2236 pci_set_master(pdev);
2237
2238 /* Query PCI controller on system for DMA addressing
2239 * limitation for the device. Try 40-bit first, and
2240 * fail to 32-bit.
2241 */
2242
50cf156a 2243 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
01f2e4ea 2244 if (err) {
284901a9 2245 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
01f2e4ea
SF
2246 if (err) {
2247 printk(KERN_ERR PFX
4b75a442 2248 "No usable DMA configuration, aborting.\n");
01f2e4ea
SF
2249 goto err_out_release_regions;
2250 }
284901a9 2251 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
01f2e4ea
SF
2252 if (err) {
2253 printk(KERN_ERR PFX
4b75a442
SF
2254 "Unable to obtain 32-bit DMA "
2255 "for consistent allocations, aborting.\n");
01f2e4ea
SF
2256 goto err_out_release_regions;
2257 }
2258 } else {
50cf156a 2259 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
01f2e4ea
SF
2260 if (err) {
2261 printk(KERN_ERR PFX
4b75a442
SF
2262 "Unable to obtain 40-bit DMA "
2263 "for consistent allocations, aborting.\n");
01f2e4ea
SF
2264 goto err_out_release_regions;
2265 }
2266 using_dac = 1;
2267 }
2268
27e6c7d3 2269 /* Map vNIC resources from BAR0-5
01f2e4ea
SF
2270 */
2271
27e6c7d3
SF
2272 for (i = 0; i < ARRAY_SIZE(enic->bar); i++) {
2273 if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM))
2274 continue;
2275 enic->bar[i].len = pci_resource_len(pdev, i);
2276 enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len);
2277 if (!enic->bar[i].vaddr) {
2278 printk(KERN_ERR PFX
2279 "Cannot memory-map BAR %d, aborting.\n", i);
2280 err = -ENODEV;
2281 goto err_out_iounmap;
2282 }
2283 enic->bar[i].bus_addr = pci_resource_start(pdev, i);
01f2e4ea
SF
2284 }
2285
2286 /* Register vNIC device
2287 */
2288
27e6c7d3
SF
2289 enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar,
2290 ARRAY_SIZE(enic->bar));
01f2e4ea
SF
2291 if (!enic->vdev) {
2292 printk(KERN_ERR PFX
4b75a442 2293 "vNIC registration failed, aborting.\n");
01f2e4ea
SF
2294 err = -ENODEV;
2295 goto err_out_iounmap;
2296 }
2297
2298 /* Issue device open to get device in known state
2299 */
2300
2301 err = enic_dev_open(enic);
2302 if (err) {
2303 printk(KERN_ERR PFX
4b75a442 2304 "vNIC dev open failed, aborting.\n");
01f2e4ea
SF
2305 goto err_out_vnic_unregister;
2306 }
2307
2308 /* Issue device init to initialize the vnic-to-switch link.
2309 * We'll start with carrier off and wait for link UP
2310 * notification later to turn on carrier. We don't need
2311 * to wait here for the vnic-to-switch link initialization
2312 * to complete; link UP notification is the indication that
2313 * the process is complete.
2314 */
2315
2316 netif_carrier_off(netdev);
2317
f8bd9091
SF
2318 if (!enic_is_dynamic(enic)) {
2319 err = vnic_dev_init(enic->vdev, 0);
2320 if (err) {
2321 printk(KERN_ERR PFX
2322 "vNIC dev init failed, aborting.\n");
2323 goto err_out_dev_close;
2324 }
01f2e4ea
SF
2325 }
2326
6fdfa970 2327 err = enic_dev_init(enic);
01f2e4ea
SF
2328 if (err) {
2329 printk(KERN_ERR PFX
6fdfa970 2330 "Device initialization failed, aborting.\n");
01f2e4ea
SF
2331 goto err_out_dev_close;
2332 }
2333
01f2e4ea
SF
2334 /* Setup notification timer, HW reset task, and locks
2335 */
2336
2337 init_timer(&enic->notify_timer);
2338 enic->notify_timer.function = enic_notify_timer;
2339 enic->notify_timer.data = (unsigned long)enic;
2340
2341 INIT_WORK(&enic->reset, enic_reset);
2342
2343 for (i = 0; i < enic->wq_count; i++)
2344 spin_lock_init(&enic->wq_lock[i]);
2345
2346 spin_lock_init(&enic->devcmd_lock);
2347
2348 /* Register net device
2349 */
2350
2351 enic->port_mtu = enic->config.mtu;
2352 (void)enic_change_mtu(netdev, enic->port_mtu);
2353
2354 err = enic_set_mac_addr(netdev, enic->mac_addr);
2355 if (err) {
2356 printk(KERN_ERR PFX
4b75a442 2357 "Invalid MAC address, aborting.\n");
6fdfa970 2358 goto err_out_dev_deinit;
01f2e4ea
SF
2359 }
2360
7c844599
SF
2361 enic->tx_coalesce_usecs = enic->config.intr_timer_usec;
2362 enic->rx_coalesce_usecs = enic->tx_coalesce_usecs;
2363
f8bd9091
SF
2364 if (enic_is_dynamic(enic))
2365 netdev->netdev_ops = &enic_netdev_dynamic_ops;
2366 else
2367 netdev->netdev_ops = &enic_netdev_ops;
2368
01f2e4ea
SF
2369 netdev->watchdog_timeo = 2 * HZ;
2370 netdev->ethtool_ops = &enic_ethtool_ops;
01f2e4ea 2371
73c1ea9b 2372 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
01f2e4ea
SF
2373 if (ENIC_SETTING(enic, TXCSUM))
2374 netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
2375 if (ENIC_SETTING(enic, TSO))
2376 netdev->features |= NETIF_F_TSO |
2377 NETIF_F_TSO6 | NETIF_F_TSO_ECN;
86ca9db7
SF
2378 if (ENIC_SETTING(enic, LRO))
2379 netdev->features |= NETIF_F_LRO;
01f2e4ea
SF
2380 if (using_dac)
2381 netdev->features |= NETIF_F_HIGHDMA;
2382
01f2e4ea
SF
2383 enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM);
2384
86ca9db7
SF
2385 enic->lro_mgr.max_aggr = ENIC_LRO_MAX_AGGR;
2386 enic->lro_mgr.max_desc = ENIC_LRO_MAX_DESC;
2387 enic->lro_mgr.lro_arr = enic->lro_desc;
2388 enic->lro_mgr.get_skb_header = enic_get_skb_header;
2389 enic->lro_mgr.features = LRO_F_NAPI | LRO_F_EXTRACT_VLAN_ID;
2390 enic->lro_mgr.dev = netdev;
2391 enic->lro_mgr.ip_summed = CHECKSUM_COMPLETE;
2392 enic->lro_mgr.ip_summed_aggr = CHECKSUM_UNNECESSARY;
2393
01f2e4ea
SF
2394 err = register_netdev(netdev);
2395 if (err) {
2396 printk(KERN_ERR PFX
4b75a442 2397 "Cannot register net device, aborting.\n");
6fdfa970 2398 goto err_out_dev_deinit;
01f2e4ea
SF
2399 }
2400
2401 return 0;
2402
6fdfa970
SF
2403err_out_dev_deinit:
2404 enic_dev_deinit(enic);
01f2e4ea
SF
2405err_out_dev_close:
2406 vnic_dev_close(enic->vdev);
2407err_out_vnic_unregister:
01f2e4ea
SF
2408 vnic_dev_unregister(enic->vdev);
2409err_out_iounmap:
2410 enic_iounmap(enic);
2411err_out_release_regions:
2412 pci_release_regions(pdev);
2413err_out_disable_device:
2414 pci_disable_device(pdev);
2415err_out_free_netdev:
2416 pci_set_drvdata(pdev, NULL);
2417 free_netdev(netdev);
2418
2419 return err;
2420}
2421
2422static void __devexit enic_remove(struct pci_dev *pdev)
2423{
2424 struct net_device *netdev = pci_get_drvdata(pdev);
2425
2426 if (netdev) {
2427 struct enic *enic = netdev_priv(netdev);
2428
2429 flush_scheduled_work();
2430 unregister_netdev(netdev);
6fdfa970 2431 enic_dev_deinit(enic);
01f2e4ea 2432 vnic_dev_close(enic->vdev);
01f2e4ea
SF
2433 vnic_dev_unregister(enic->vdev);
2434 enic_iounmap(enic);
2435 pci_release_regions(pdev);
2436 pci_disable_device(pdev);
2437 pci_set_drvdata(pdev, NULL);
2438 free_netdev(netdev);
2439 }
2440}
2441
2442static struct pci_driver enic_driver = {
2443 .name = DRV_NAME,
2444 .id_table = enic_id_table,
2445 .probe = enic_probe,
2446 .remove = __devexit_p(enic_remove),
2447};
2448
2449static int __init enic_init_module(void)
2450{
2451 printk(KERN_INFO PFX "%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
2452
2453 return pci_register_driver(&enic_driver);
2454}
2455
2456static void __exit enic_cleanup_module(void)
2457{
2458 pci_unregister_driver(&enic_driver);
2459}
2460
2461module_init(enic_init_module);
2462module_exit(enic_cleanup_module);