blob: 21be989e6a14249d15086f0526c88e6f5fd214b3 [file] [log] [blame]
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001/*
Vasanthy Kolluri29046f92010-06-24 10:52:26 +00002 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
Scott Feldman01f2e4e2008-09-15 09:17:11 -07003 * 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>
32#include <linux/ethtool.h>
33#include <linux/in.h>
34#include <linux/ip.h>
35#include <linux/ipv6.h>
36#include <linux/tcp.h>
Vasanthy Kolluri29046f92010-06-24 10:52:26 +000037#include <linux/rtnetlink.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
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000125static inline unsigned int enic_cq_rq(struct enic *enic, unsigned int rq)
126{
127 return rq;
128}
129
130static inline unsigned int enic_cq_wq(struct enic *enic, unsigned int wq)
131{
132 return enic->rq_count + wq;
133}
134
135static inline unsigned int enic_legacy_io_intr(void)
136{
137 return 0;
138}
139
140static inline unsigned int enic_legacy_err_intr(void)
141{
142 return 1;
143}
144
145static inline unsigned int enic_legacy_notify_intr(void)
146{
147 return 2;
148}
149
150static inline unsigned int enic_msix_rq_intr(struct enic *enic, unsigned int rq)
151{
152 return rq;
153}
154
155static inline unsigned int enic_msix_wq_intr(struct enic *enic, unsigned int wq)
156{
157 return enic->rq_count + wq;
158}
159
160static inline unsigned int enic_msix_err_intr(struct enic *enic)
161{
162 return enic->rq_count + enic->wq_count;
163}
164
165static inline unsigned int enic_msix_notify_intr(struct enic *enic)
166{
167 return enic->rq_count + enic->wq_count + 1;
168}
169
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700170static int enic_get_settings(struct net_device *netdev,
171 struct ethtool_cmd *ecmd)
172{
173 struct enic *enic = netdev_priv(netdev);
174
175 ecmd->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
176 ecmd->advertising = (ADVERTISED_10000baseT_Full | ADVERTISED_FIBRE);
177 ecmd->port = PORT_FIBRE;
178 ecmd->transceiver = XCVR_EXTERNAL;
179
180 if (netif_carrier_ok(netdev)) {
181 ecmd->speed = vnic_dev_port_speed(enic->vdev);
182 ecmd->duplex = DUPLEX_FULL;
183 } else {
184 ecmd->speed = -1;
185 ecmd->duplex = -1;
186 }
187
188 ecmd->autoneg = AUTONEG_DISABLE;
189
190 return 0;
191}
192
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000193static int enic_dev_fw_info(struct enic *enic,
194 struct vnic_devcmd_fw_info **fw_info)
195{
196 int err;
197
198 spin_lock(&enic->devcmd_lock);
199 err = vnic_dev_fw_info(enic->vdev, fw_info);
200 spin_unlock(&enic->devcmd_lock);
201
202 return err;
203}
204
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700205static void enic_get_drvinfo(struct net_device *netdev,
206 struct ethtool_drvinfo *drvinfo)
207{
208 struct enic *enic = netdev_priv(netdev);
209 struct vnic_devcmd_fw_info *fw_info;
210
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000211 enic_dev_fw_info(enic, &fw_info);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700212
213 strncpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
214 strncpy(drvinfo->version, DRV_VERSION, sizeof(drvinfo->version));
215 strncpy(drvinfo->fw_version, fw_info->fw_version,
216 sizeof(drvinfo->fw_version));
217 strncpy(drvinfo->bus_info, pci_name(enic->pdev),
218 sizeof(drvinfo->bus_info));
219}
220
221static void enic_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
222{
223 unsigned int i;
224
225 switch (stringset) {
226 case ETH_SS_STATS:
227 for (i = 0; i < enic_n_tx_stats; i++) {
228 memcpy(data, enic_tx_stats[i].name, ETH_GSTRING_LEN);
229 data += ETH_GSTRING_LEN;
230 }
231 for (i = 0; i < enic_n_rx_stats; i++) {
232 memcpy(data, enic_rx_stats[i].name, ETH_GSTRING_LEN);
233 data += ETH_GSTRING_LEN;
234 }
235 break;
236 }
237}
238
Scott Feldman25f0a062008-09-24 11:23:32 -0700239static int enic_get_sset_count(struct net_device *netdev, int sset)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700240{
Scott Feldman25f0a062008-09-24 11:23:32 -0700241 switch (sset) {
242 case ETH_SS_STATS:
243 return enic_n_tx_stats + enic_n_rx_stats;
244 default:
245 return -EOPNOTSUPP;
246 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700247}
248
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000249static int enic_dev_stats_dump(struct enic *enic, struct vnic_stats **vstats)
250{
251 int err;
252
253 spin_lock(&enic->devcmd_lock);
254 err = vnic_dev_stats_dump(enic->vdev, vstats);
255 spin_unlock(&enic->devcmd_lock);
256
257 return err;
258}
259
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700260static void enic_get_ethtool_stats(struct net_device *netdev,
261 struct ethtool_stats *stats, u64 *data)
262{
263 struct enic *enic = netdev_priv(netdev);
264 struct vnic_stats *vstats;
265 unsigned int i;
266
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000267 enic_dev_stats_dump(enic, &vstats);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700268
269 for (i = 0; i < enic_n_tx_stats; i++)
270 *(data++) = ((u64 *)&vstats->tx)[enic_tx_stats[i].offset];
271 for (i = 0; i < enic_n_rx_stats; i++)
272 *(data++) = ((u64 *)&vstats->rx)[enic_rx_stats[i].offset];
273}
274
275static u32 enic_get_rx_csum(struct net_device *netdev)
276{
277 struct enic *enic = netdev_priv(netdev);
278 return enic->csum_rx_enabled;
279}
280
281static int enic_set_rx_csum(struct net_device *netdev, u32 data)
282{
283 struct enic *enic = netdev_priv(netdev);
284
Scott Feldman25f0a062008-09-24 11:23:32 -0700285 if (data && !ENIC_SETTING(enic, RXCSUM))
286 return -EINVAL;
287
288 enic->csum_rx_enabled = !!data;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700289
290 return 0;
291}
292
293static int enic_set_tx_csum(struct net_device *netdev, u32 data)
294{
295 struct enic *enic = netdev_priv(netdev);
296
Scott Feldman25f0a062008-09-24 11:23:32 -0700297 if (data && !ENIC_SETTING(enic, TXCSUM))
298 return -EINVAL;
299
300 if (data)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700301 netdev->features |= NETIF_F_HW_CSUM;
302 else
303 netdev->features &= ~NETIF_F_HW_CSUM;
304
305 return 0;
306}
307
308static int enic_set_tso(struct net_device *netdev, u32 data)
309{
310 struct enic *enic = netdev_priv(netdev);
311
Scott Feldman25f0a062008-09-24 11:23:32 -0700312 if (data && !ENIC_SETTING(enic, TSO))
313 return -EINVAL;
314
315 if (data)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700316 netdev->features |=
317 NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN;
318 else
319 netdev->features &=
320 ~(NETIF_F_TSO | NETIF_F_TSO6 | NETIF_F_TSO_ECN);
321
322 return 0;
323}
324
325static u32 enic_get_msglevel(struct net_device *netdev)
326{
327 struct enic *enic = netdev_priv(netdev);
328 return enic->msg_enable;
329}
330
331static void enic_set_msglevel(struct net_device *netdev, u32 value)
332{
333 struct enic *enic = netdev_priv(netdev);
334 enic->msg_enable = value;
335}
336
Scott Feldman7c844592009-12-23 13:27:54 +0000337static int enic_get_coalesce(struct net_device *netdev,
338 struct ethtool_coalesce *ecmd)
339{
340 struct enic *enic = netdev_priv(netdev);
341
342 ecmd->tx_coalesce_usecs = enic->tx_coalesce_usecs;
343 ecmd->rx_coalesce_usecs = enic->rx_coalesce_usecs;
344
345 return 0;
346}
347
348static int enic_set_coalesce(struct net_device *netdev,
349 struct ethtool_coalesce *ecmd)
350{
351 struct enic *enic = netdev_priv(netdev);
352 u32 tx_coalesce_usecs;
353 u32 rx_coalesce_usecs;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000354 unsigned int i, intr;
Scott Feldman7c844592009-12-23 13:27:54 +0000355
356 tx_coalesce_usecs = min_t(u32,
357 INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
358 ecmd->tx_coalesce_usecs);
359 rx_coalesce_usecs = min_t(u32,
360 INTR_COALESCE_HW_TO_USEC(VNIC_INTR_TIMER_MAX),
361 ecmd->rx_coalesce_usecs);
362
363 switch (vnic_dev_get_intr_mode(enic->vdev)) {
364 case VNIC_DEV_INTR_MODE_INTX:
365 if (tx_coalesce_usecs != rx_coalesce_usecs)
366 return -EINVAL;
367
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000368 intr = enic_legacy_io_intr();
369 vnic_intr_coalescing_timer_set(&enic->intr[intr],
Scott Feldman7c844592009-12-23 13:27:54 +0000370 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
371 break;
372 case VNIC_DEV_INTR_MODE_MSI:
373 if (tx_coalesce_usecs != rx_coalesce_usecs)
374 return -EINVAL;
375
376 vnic_intr_coalescing_timer_set(&enic->intr[0],
377 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
378 break;
379 case VNIC_DEV_INTR_MODE_MSIX:
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000380 for (i = 0; i < enic->wq_count; i++) {
381 intr = enic_msix_wq_intr(enic, i);
382 vnic_intr_coalescing_timer_set(&enic->intr[intr],
383 INTR_COALESCE_USEC_TO_HW(tx_coalesce_usecs));
384 }
385
386 for (i = 0; i < enic->rq_count; i++) {
387 intr = enic_msix_rq_intr(enic, i);
388 vnic_intr_coalescing_timer_set(&enic->intr[intr],
389 INTR_COALESCE_USEC_TO_HW(rx_coalesce_usecs));
390 }
391
Scott Feldman7c844592009-12-23 13:27:54 +0000392 break;
393 default:
394 break;
395 }
396
397 enic->tx_coalesce_usecs = tx_coalesce_usecs;
398 enic->rx_coalesce_usecs = rx_coalesce_usecs;
399
400 return 0;
401}
402
Stephen Hemminger0fc0b732009-09-02 01:03:33 -0700403static const struct ethtool_ops enic_ethtool_ops = {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700404 .get_settings = enic_get_settings,
405 .get_drvinfo = enic_get_drvinfo,
406 .get_msglevel = enic_get_msglevel,
407 .set_msglevel = enic_set_msglevel,
408 .get_link = ethtool_op_get_link,
409 .get_strings = enic_get_strings,
Scott Feldman25f0a062008-09-24 11:23:32 -0700410 .get_sset_count = enic_get_sset_count,
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700411 .get_ethtool_stats = enic_get_ethtool_stats,
412 .get_rx_csum = enic_get_rx_csum,
413 .set_rx_csum = enic_set_rx_csum,
414 .get_tx_csum = ethtool_op_get_tx_csum,
415 .set_tx_csum = enic_set_tx_csum,
416 .get_sg = ethtool_op_get_sg,
417 .set_sg = ethtool_op_set_sg,
418 .get_tso = ethtool_op_get_tso,
419 .set_tso = enic_set_tso,
Scott Feldman7c844592009-12-23 13:27:54 +0000420 .get_coalesce = enic_get_coalesce,
421 .set_coalesce = enic_set_coalesce,
Scott Feldman86ca9db2008-11-21 21:26:55 -0800422 .get_flags = ethtool_op_get_flags,
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700423};
424
425static void enic_free_wq_buf(struct vnic_wq *wq, struct vnic_wq_buf *buf)
426{
427 struct enic *enic = vnic_dev_priv(wq->vdev);
428
429 if (buf->sop)
430 pci_unmap_single(enic->pdev, buf->dma_addr,
431 buf->len, PCI_DMA_TODEVICE);
432 else
433 pci_unmap_page(enic->pdev, buf->dma_addr,
434 buf->len, PCI_DMA_TODEVICE);
435
436 if (buf->os_buf)
437 dev_kfree_skb_any(buf->os_buf);
438}
439
440static void enic_wq_free_buf(struct vnic_wq *wq,
441 struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque)
442{
443 enic_free_wq_buf(wq, buf);
444}
445
446static int enic_wq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
447 u8 type, u16 q_number, u16 completed_index, void *opaque)
448{
449 struct enic *enic = vnic_dev_priv(vdev);
450
451 spin_lock(&enic->wq_lock[q_number]);
452
453 vnic_wq_service(&enic->wq[q_number], cq_desc,
454 completed_index, enic_wq_free_buf,
455 opaque);
456
457 if (netif_queue_stopped(enic->netdev) &&
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000458 vnic_wq_desc_avail(&enic->wq[q_number]) >=
459 (MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS))
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700460 netif_wake_queue(enic->netdev);
461
462 spin_unlock(&enic->wq_lock[q_number]);
463
464 return 0;
465}
466
467static void enic_log_q_error(struct enic *enic)
468{
469 unsigned int i;
470 u32 error_status;
471
472 for (i = 0; i < enic->wq_count; i++) {
473 error_status = vnic_wq_error_status(&enic->wq[i]);
474 if (error_status)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000475 netdev_err(enic->netdev, "WQ[%d] error_status %d\n",
476 i, error_status);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700477 }
478
479 for (i = 0; i < enic->rq_count; i++) {
480 error_status = vnic_rq_error_status(&enic->rq[i]);
481 if (error_status)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000482 netdev_err(enic->netdev, "RQ[%d] error_status %d\n",
483 i, error_status);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700484 }
485}
486
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000487static void enic_msglvl_check(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700488{
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000489 u32 msg_enable = vnic_dev_msg_lvl(enic->vdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700490
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000491 if (msg_enable != enic->msg_enable) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000492 netdev_info(enic->netdev, "msg lvl changed from 0x%x to 0x%x\n",
493 enic->msg_enable, msg_enable);
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000494 enic->msg_enable = msg_enable;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700495 }
496}
497
498static void enic_mtu_check(struct enic *enic)
499{
500 u32 mtu = vnic_dev_mtu(enic->vdev);
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000501 struct net_device *netdev = enic->netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700502
Scott Feldman491598a2009-09-03 17:02:40 +0000503 if (mtu && mtu != enic->port_mtu) {
Scott Feldman7c844592009-12-23 13:27:54 +0000504 enic->port_mtu = mtu;
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000505 if (mtu < netdev->mtu)
506 netdev_warn(netdev,
507 "interface MTU (%d) set higher "
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700508 "than switch port MTU (%d)\n",
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000509 netdev->mtu, mtu);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700510 }
511}
512
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000513static void enic_link_check(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700514{
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000515 int link_status = vnic_dev_link_status(enic->vdev);
516 int carrier_ok = netif_carrier_ok(enic->netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700517
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000518 if (link_status && !carrier_ok) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000519 netdev_info(enic->netdev, "Link UP\n");
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000520 netif_carrier_on(enic->netdev);
521 } else if (!link_status && carrier_ok) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000522 netdev_info(enic->netdev, "Link DOWN\n");
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000523 netif_carrier_off(enic->netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700524 }
525}
526
527static void enic_notify_check(struct enic *enic)
528{
529 enic_msglvl_check(enic);
530 enic_mtu_check(enic);
531 enic_link_check(enic);
532}
533
534#define ENIC_TEST_INTR(pba, i) (pba & (1 << i))
535
536static irqreturn_t enic_isr_legacy(int irq, void *data)
537{
538 struct net_device *netdev = data;
539 struct enic *enic = netdev_priv(netdev);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000540 unsigned int io_intr = enic_legacy_io_intr();
541 unsigned int err_intr = enic_legacy_err_intr();
542 unsigned int notify_intr = enic_legacy_notify_intr();
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700543 u32 pba;
544
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000545 vnic_intr_mask(&enic->intr[io_intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700546
547 pba = vnic_intr_legacy_pba(enic->legacy_pba);
548 if (!pba) {
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000549 vnic_intr_unmask(&enic->intr[io_intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700550 return IRQ_NONE; /* not our interrupt */
551 }
552
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000553 if (ENIC_TEST_INTR(pba, notify_intr)) {
554 vnic_intr_return_all_credits(&enic->intr[notify_intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700555 enic_notify_check(enic);
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800556 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700557
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000558 if (ENIC_TEST_INTR(pba, err_intr)) {
559 vnic_intr_return_all_credits(&enic->intr[err_intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700560 enic_log_q_error(enic);
561 /* schedule recovery from WQ/RQ error */
562 schedule_work(&enic->reset);
563 return IRQ_HANDLED;
564 }
565
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000566 if (ENIC_TEST_INTR(pba, io_intr)) {
567 if (napi_schedule_prep(&enic->napi[0]))
568 __napi_schedule(&enic->napi[0]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700569 } else {
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000570 vnic_intr_unmask(&enic->intr[io_intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700571 }
572
573 return IRQ_HANDLED;
574}
575
576static irqreturn_t enic_isr_msi(int irq, void *data)
577{
578 struct enic *enic = data;
579
580 /* With MSI, there is no sharing of interrupts, so this is
581 * our interrupt and there is no need to ack it. The device
582 * is not providing per-vector masking, so the OS will not
583 * write to PCI config space to mask/unmask the interrupt.
584 * We're using mask_on_assertion for MSI, so the device
585 * automatically masks the interrupt when the interrupt is
586 * generated. Later, when exiting polling, the interrupt
587 * will be unmasked (see enic_poll).
588 *
589 * Also, the device uses the same PCIe Traffic Class (TC)
590 * for Memory Write data and MSI, so there are no ordering
591 * issues; the MSI will always arrive at the Root Complex
592 * _after_ corresponding Memory Writes (i.e. descriptor
593 * writes).
594 */
595
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000596 napi_schedule(&enic->napi[0]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700597
598 return IRQ_HANDLED;
599}
600
601static irqreturn_t enic_isr_msix_rq(int irq, void *data)
602{
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000603 struct napi_struct *napi = data;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700604
605 /* schedule NAPI polling for RQ cleanup */
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000606 napi_schedule(napi);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700607
608 return IRQ_HANDLED;
609}
610
611static irqreturn_t enic_isr_msix_wq(int irq, void *data)
612{
613 struct enic *enic = data;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000614 unsigned int cq = enic_cq_wq(enic, 0);
615 unsigned int intr = enic_msix_wq_intr(enic, 0);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700616 unsigned int wq_work_to_do = -1; /* no limit */
617 unsigned int wq_work_done;
618
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000619 wq_work_done = vnic_cq_service(&enic->cq[cq],
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700620 wq_work_to_do, enic_wq_service, NULL);
621
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000622 vnic_intr_return_credits(&enic->intr[intr],
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700623 wq_work_done,
624 1 /* unmask intr */,
625 1 /* reset intr timer */);
626
627 return IRQ_HANDLED;
628}
629
630static irqreturn_t enic_isr_msix_err(int irq, void *data)
631{
632 struct enic *enic = data;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000633 unsigned int intr = enic_msix_err_intr(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700634
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000635 vnic_intr_return_all_credits(&enic->intr[intr]);
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800636
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700637 enic_log_q_error(enic);
638
639 /* schedule recovery from WQ/RQ error */
640 schedule_work(&enic->reset);
641
642 return IRQ_HANDLED;
643}
644
645static irqreturn_t enic_isr_msix_notify(int irq, void *data)
646{
647 struct enic *enic = data;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000648 unsigned int intr = enic_msix_notify_intr(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700649
Vasanthy Kolluri717258b2010-10-20 10:16:59 +0000650 vnic_intr_return_all_credits(&enic->intr[intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700651 enic_notify_check(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700652
653 return IRQ_HANDLED;
654}
655
656static inline void enic_queue_wq_skb_cont(struct enic *enic,
657 struct vnic_wq *wq, struct sk_buff *skb,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000658 unsigned int len_left, int loopback)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700659{
660 skb_frag_t *frag;
661
662 /* Queue additional data fragments */
663 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
664 len_left -= frag->size;
665 enic_queue_wq_desc_cont(wq, skb,
666 pci_map_page(enic->pdev, frag->page,
667 frag->page_offset, frag->size,
668 PCI_DMA_TODEVICE),
669 frag->size,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000670 (len_left == 0), /* EOP? */
671 loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700672 }
673}
674
675static inline void enic_queue_wq_skb_vlan(struct enic *enic,
676 struct vnic_wq *wq, struct sk_buff *skb,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000677 int vlan_tag_insert, unsigned int vlan_tag, int loopback)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700678{
679 unsigned int head_len = skb_headlen(skb);
680 unsigned int len_left = skb->len - head_len;
681 int eop = (len_left == 0);
682
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000683 /* Queue the main skb fragment. The fragments are no larger
684 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
685 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
686 * per fragment is queued.
687 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700688 enic_queue_wq_desc(wq, skb,
689 pci_map_single(enic->pdev, skb->data,
690 head_len, PCI_DMA_TODEVICE),
691 head_len,
692 vlan_tag_insert, vlan_tag,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000693 eop, loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700694
695 if (!eop)
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000696 enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700697}
698
699static inline void enic_queue_wq_skb_csum_l4(struct enic *enic,
700 struct vnic_wq *wq, struct sk_buff *skb,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000701 int vlan_tag_insert, unsigned int vlan_tag, int loopback)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700702{
703 unsigned int head_len = skb_headlen(skb);
704 unsigned int len_left = skb->len - head_len;
705 unsigned int hdr_len = skb_transport_offset(skb);
706 unsigned int csum_offset = hdr_len + skb->csum_offset;
707 int eop = (len_left == 0);
708
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000709 /* Queue the main skb fragment. The fragments are no larger
710 * than max MTU(9000)+ETH_HDR_LEN(14) bytes, which is less
711 * than WQ_ENET_MAX_DESC_LEN length. So only one descriptor
712 * per fragment is queued.
713 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700714 enic_queue_wq_desc_csum_l4(wq, skb,
715 pci_map_single(enic->pdev, skb->data,
716 head_len, PCI_DMA_TODEVICE),
717 head_len,
718 csum_offset,
719 hdr_len,
720 vlan_tag_insert, vlan_tag,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000721 eop, loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700722
723 if (!eop)
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000724 enic_queue_wq_skb_cont(enic, wq, skb, len_left, loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700725}
726
727static inline void enic_queue_wq_skb_tso(struct enic *enic,
728 struct vnic_wq *wq, struct sk_buff *skb, unsigned int mss,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000729 int vlan_tag_insert, unsigned int vlan_tag, int loopback)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700730{
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000731 unsigned int frag_len_left = skb_headlen(skb);
732 unsigned int len_left = skb->len - frag_len_left;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700733 unsigned int hdr_len = skb_transport_offset(skb) + tcp_hdrlen(skb);
734 int eop = (len_left == 0);
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000735 unsigned int len;
736 dma_addr_t dma_addr;
737 unsigned int offset = 0;
738 skb_frag_t *frag;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700739
740 /* Preload TCP csum field with IP pseudo hdr calculated
741 * with IP length set to zero. HW will later add in length
742 * to each TCP segment resulting from the TSO.
743 */
744
Harvey Harrison09640e62009-02-01 00:45:17 -0800745 if (skb->protocol == cpu_to_be16(ETH_P_IP)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700746 ip_hdr(skb)->check = 0;
747 tcp_hdr(skb)->check = ~csum_tcpudp_magic(ip_hdr(skb)->saddr,
748 ip_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
Harvey Harrison09640e62009-02-01 00:45:17 -0800749 } else if (skb->protocol == cpu_to_be16(ETH_P_IPV6)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700750 tcp_hdr(skb)->check = ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
751 &ipv6_hdr(skb)->daddr, 0, IPPROTO_TCP, 0);
752 }
753
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000754 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
755 * for the main skb fragment
756 */
757 while (frag_len_left) {
758 len = min(frag_len_left, (unsigned int)WQ_ENET_MAX_DESC_LEN);
759 dma_addr = pci_map_single(enic->pdev, skb->data + offset,
760 len, PCI_DMA_TODEVICE);
761 enic_queue_wq_desc_tso(wq, skb,
762 dma_addr,
763 len,
764 mss, hdr_len,
765 vlan_tag_insert, vlan_tag,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000766 eop && (len == frag_len_left), loopback);
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000767 frag_len_left -= len;
768 offset += len;
769 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700770
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000771 if (eop)
772 return;
773
774 /* Queue WQ_ENET_MAX_DESC_LEN length descriptors
775 * for additional data fragments
776 */
777 for (frag = skb_shinfo(skb)->frags; len_left; frag++) {
778 len_left -= frag->size;
779 frag_len_left = frag->size;
780 offset = frag->page_offset;
781
782 while (frag_len_left) {
783 len = min(frag_len_left,
784 (unsigned int)WQ_ENET_MAX_DESC_LEN);
785 dma_addr = pci_map_page(enic->pdev, frag->page,
786 offset, len,
787 PCI_DMA_TODEVICE);
788 enic_queue_wq_desc_cont(wq, skb,
789 dma_addr,
790 len,
791 (len_left == 0) &&
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000792 (len == frag_len_left), /* EOP? */
793 loopback);
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000794 frag_len_left -= len;
795 offset += len;
796 }
797 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700798}
799
800static inline void enic_queue_wq_skb(struct enic *enic,
801 struct vnic_wq *wq, struct sk_buff *skb)
802{
803 unsigned int mss = skb_shinfo(skb)->gso_size;
804 unsigned int vlan_tag = 0;
805 int vlan_tag_insert = 0;
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000806 int loopback = 0;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700807
Jesse Grosseab6d182010-10-20 13:56:03 +0000808 if (vlan_tx_tag_present(skb)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700809 /* VLAN tag from trunking driver */
810 vlan_tag_insert = 1;
811 vlan_tag = vlan_tx_tag_get(skb);
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000812 } else if (enic->loop_enable) {
813 vlan_tag = enic->loop_tag;
814 loopback = 1;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700815 }
816
817 if (mss)
818 enic_queue_wq_skb_tso(enic, wq, skb, mss,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000819 vlan_tag_insert, vlan_tag, loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700820 else if (skb->ip_summed == CHECKSUM_PARTIAL)
821 enic_queue_wq_skb_csum_l4(enic, wq, skb,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000822 vlan_tag_insert, vlan_tag, loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700823 else
824 enic_queue_wq_skb_vlan(enic, wq, skb,
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +0000825 vlan_tag_insert, vlan_tag, loopback);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700826}
827
Scott Feldmaned8af6b2009-02-09 23:23:50 -0800828/* netif_tx_lock held, process context with BHs disabled, or BH */
Stephen Hemminger613573252009-08-31 19:50:58 +0000829static netdev_tx_t enic_hard_start_xmit(struct sk_buff *skb,
Scott Feldmand87fd252009-12-23 13:27:59 +0000830 struct net_device *netdev)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700831{
832 struct enic *enic = netdev_priv(netdev);
833 struct vnic_wq *wq = &enic->wq[0];
834 unsigned long flags;
835
836 if (skb->len <= 0) {
837 dev_kfree_skb(skb);
838 return NETDEV_TX_OK;
839 }
840
841 /* Non-TSO sends must fit within ENIC_NON_TSO_MAX_DESC descs,
842 * which is very likely. In the off chance it's going to take
843 * more than * ENIC_NON_TSO_MAX_DESC, linearize the skb.
844 */
845
846 if (skb_shinfo(skb)->gso_size == 0 &&
847 skb_shinfo(skb)->nr_frags + 1 > ENIC_NON_TSO_MAX_DESC &&
848 skb_linearize(skb)) {
849 dev_kfree_skb(skb);
850 return NETDEV_TX_OK;
851 }
852
853 spin_lock_irqsave(&enic->wq_lock[0], flags);
854
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000855 if (vnic_wq_desc_avail(wq) <
856 skb_shinfo(skb)->nr_frags + ENIC_DESC_MAX_SPLITS) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700857 netif_stop_queue(netdev);
858 /* This is a hard error, log it */
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +0000859 netdev_err(netdev, "BUG! Tx ring full when queue awake!\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700860 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
861 return NETDEV_TX_BUSY;
862 }
863
864 enic_queue_wq_skb(enic, wq, skb);
865
Scott Feldmanea0d7d92009-09-03 17:02:03 +0000866 if (vnic_wq_desc_avail(wq) < MAX_SKB_FRAGS + ENIC_DESC_MAX_SPLITS)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700867 netif_stop_queue(netdev);
868
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700869 spin_unlock_irqrestore(&enic->wq_lock[0], flags);
870
871 return NETDEV_TX_OK;
872}
873
874/* dev_base_lock rwlock held, nominally process context */
875static struct net_device_stats *enic_get_stats(struct net_device *netdev)
876{
877 struct enic *enic = netdev_priv(netdev);
Scott Feldman25f0a062008-09-24 11:23:32 -0700878 struct net_device_stats *net_stats = &netdev->stats;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700879 struct vnic_stats *stats;
880
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000881 enic_dev_stats_dump(enic, &stats);
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700882
Scott Feldman25f0a062008-09-24 11:23:32 -0700883 net_stats->tx_packets = stats->tx.tx_frames_ok;
884 net_stats->tx_bytes = stats->tx.tx_bytes_ok;
885 net_stats->tx_errors = stats->tx.tx_errors;
886 net_stats->tx_dropped = stats->tx.tx_drops;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700887
Scott Feldman25f0a062008-09-24 11:23:32 -0700888 net_stats->rx_packets = stats->rx.rx_frames_ok;
889 net_stats->rx_bytes = stats->rx.rx_bytes_ok;
890 net_stats->rx_errors = stats->rx.rx_errors;
891 net_stats->multicast = stats->rx.rx_multicast_frames_ok;
Scott Feldman350991e2009-09-03 17:02:19 +0000892 net_stats->rx_over_errors = enic->rq_truncated_pkts;
Scott Feldmanbd9fb1a2009-02-09 23:24:08 -0800893 net_stats->rx_crc_errors = enic->rq_bad_fcs;
Scott Feldman350991e2009-09-03 17:02:19 +0000894 net_stats->rx_dropped = stats->rx.rx_no_bufs + stats->rx.rx_drop;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700895
Scott Feldman25f0a062008-09-24 11:23:32 -0700896 return net_stats;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700897}
898
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +0000899static void enic_reset_multicast_list(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700900{
901 enic->mc_count = 0;
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +0000902 enic->flags = 0;
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700903}
904
905static int enic_set_mac_addr(struct net_device *netdev, char *addr)
906{
Scott Feldmanf8bd9092010-05-17 22:50:19 -0700907 struct enic *enic = netdev_priv(netdev);
908
909 if (enic_is_dynamic(enic)) {
910 if (!is_valid_ether_addr(addr) && !is_zero_ether_addr(addr))
911 return -EADDRNOTAVAIL;
912 } else {
913 if (!is_valid_ether_addr(addr))
914 return -EADDRNOTAVAIL;
915 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -0700916
917 memcpy(netdev->dev_addr, addr, netdev->addr_len);
918
919 return 0;
920}
921
Scott Feldmanf8bd9092010-05-17 22:50:19 -0700922static int enic_dev_add_station_addr(struct enic *enic)
923{
924 int err = 0;
925
926 if (is_valid_ether_addr(enic->netdev->dev_addr)) {
927 spin_lock(&enic->devcmd_lock);
928 err = vnic_dev_add_addr(enic->vdev, enic->netdev->dev_addr);
929 spin_unlock(&enic->devcmd_lock);
930 }
931
932 return err;
933}
934
935static int enic_dev_del_station_addr(struct enic *enic)
936{
937 int err = 0;
938
939 if (is_valid_ether_addr(enic->netdev->dev_addr)) {
940 spin_lock(&enic->devcmd_lock);
941 err = vnic_dev_del_addr(enic->vdev, enic->netdev->dev_addr);
942 spin_unlock(&enic->devcmd_lock);
943 }
944
945 return err;
946}
947
948static int enic_set_mac_address_dynamic(struct net_device *netdev, void *p)
949{
950 struct enic *enic = netdev_priv(netdev);
951 struct sockaddr *saddr = p;
952 char *addr = saddr->sa_data;
953 int err;
954
955 if (netif_running(enic->netdev)) {
956 err = enic_dev_del_station_addr(enic);
957 if (err)
958 return err;
959 }
960
961 err = enic_set_mac_addr(netdev, addr);
962 if (err)
963 return err;
964
965 if (netif_running(enic->netdev)) {
966 err = enic_dev_add_station_addr(enic);
967 if (err)
968 return err;
969 }
970
971 return err;
972}
973
974static int enic_set_mac_address(struct net_device *netdev, void *p)
975{
Roopa Prabhu294dab22010-08-10 18:54:55 +0000976 struct sockaddr *saddr = p;
Vasanthy Kolluric76fd322010-10-20 10:17:04 +0000977 char *addr = saddr->sa_data;
978 struct enic *enic = netdev_priv(netdev);
979 int err;
Roopa Prabhu294dab22010-08-10 18:54:55 +0000980
Vasanthy Kolluric76fd322010-10-20 10:17:04 +0000981 err = enic_dev_del_station_addr(enic);
982 if (err)
983 return err;
984
985 err = enic_set_mac_addr(netdev, addr);
986 if (err)
987 return err;
988
989 return enic_dev_add_station_addr(enic);
Scott Feldmanf8bd9092010-05-17 22:50:19 -0700990}
991
Vasanthy Kolluri383ab922010-06-24 10:50:12 +0000992static int enic_dev_packet_filter(struct enic *enic, int directed,
993 int multicast, int broadcast, int promisc, int allmulti)
994{
995 int err;
996
997 spin_lock(&enic->devcmd_lock);
998 err = vnic_dev_packet_filter(enic->vdev, directed,
999 multicast, broadcast, promisc, allmulti);
1000 spin_unlock(&enic->devcmd_lock);
1001
1002 return err;
1003}
1004
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001005static int enic_dev_add_addr(struct enic *enic, u8 *addr)
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001006{
1007 int err;
1008
1009 spin_lock(&enic->devcmd_lock);
1010 err = vnic_dev_add_addr(enic->vdev, addr);
1011 spin_unlock(&enic->devcmd_lock);
1012
1013 return err;
1014}
1015
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001016static int enic_dev_del_addr(struct enic *enic, u8 *addr)
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001017{
1018 int err;
1019
1020 spin_lock(&enic->devcmd_lock);
1021 err = vnic_dev_del_addr(enic->vdev, addr);
1022 spin_unlock(&enic->devcmd_lock);
1023
1024 return err;
1025}
1026
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001027static void enic_add_multicast_addr_list(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001028{
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001029 struct net_device *netdev = enic->netdev;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001030 struct netdev_hw_addr *ha;
Jiri Pirko4cd24ea2010-02-08 04:30:35 +00001031 unsigned int mc_count = netdev_mc_count(netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001032 u8 mc_addr[ENIC_MULTICAST_PERFECT_FILTERS][ETH_ALEN];
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001033 unsigned int i, j;
1034
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001035 if (mc_count > ENIC_MULTICAST_PERFECT_FILTERS) {
1036 netdev_warn(netdev, "Registering only %d out of %d "
1037 "multicast addresses\n",
1038 ENIC_MULTICAST_PERFECT_FILTERS, mc_count);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001039 mc_count = ENIC_MULTICAST_PERFECT_FILTERS;
Scott Feldman9959a182009-12-23 13:27:43 +00001040 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001041
1042 /* Is there an easier way? Trying to minimize to
1043 * calls to add/del multicast addrs. We keep the
1044 * addrs from the last call in enic->mc_addr and
1045 * look for changes to add/del.
1046 */
1047
Jiri Pirko48e2f182010-02-22 09:22:26 +00001048 i = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001049 netdev_for_each_mc_addr(ha, netdev) {
Jiri Pirko48e2f182010-02-22 09:22:26 +00001050 if (i == mc_count)
1051 break;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001052 memcpy(mc_addr[i++], ha->addr, ETH_ALEN);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001053 }
1054
1055 for (i = 0; i < enic->mc_count; i++) {
1056 for (j = 0; j < mc_count; j++)
1057 if (compare_ether_addr(enic->mc_addr[i],
1058 mc_addr[j]) == 0)
1059 break;
1060 if (j == mc_count)
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001061 enic_dev_del_addr(enic, enic->mc_addr[i]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001062 }
1063
1064 for (i = 0; i < mc_count; i++) {
1065 for (j = 0; j < enic->mc_count; j++)
1066 if (compare_ether_addr(mc_addr[i],
1067 enic->mc_addr[j]) == 0)
1068 break;
1069 if (j == enic->mc_count)
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001070 enic_dev_add_addr(enic, mc_addr[i]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001071 }
1072
1073 /* Save the list to compare against next time
1074 */
1075
1076 for (i = 0; i < mc_count; i++)
1077 memcpy(enic->mc_addr[i], mc_addr[i], ETH_ALEN);
1078
1079 enic->mc_count = mc_count;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001080}
1081
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001082static void enic_add_unicast_addr_list(struct enic *enic)
1083{
1084 struct net_device *netdev = enic->netdev;
1085 struct netdev_hw_addr *ha;
1086 unsigned int uc_count = netdev_uc_count(netdev);
1087 u8 uc_addr[ENIC_UNICAST_PERFECT_FILTERS][ETH_ALEN];
1088 unsigned int i, j;
1089
1090 if (uc_count > ENIC_UNICAST_PERFECT_FILTERS) {
1091 netdev_warn(netdev, "Registering only %d out of %d "
1092 "unicast addresses\n",
1093 ENIC_UNICAST_PERFECT_FILTERS, uc_count);
1094 uc_count = ENIC_UNICAST_PERFECT_FILTERS;
1095 }
1096
1097 /* Is there an easier way? Trying to minimize to
1098 * calls to add/del unicast addrs. We keep the
1099 * addrs from the last call in enic->uc_addr and
1100 * look for changes to add/del.
1101 */
1102
1103 i = 0;
1104 netdev_for_each_uc_addr(ha, netdev) {
1105 if (i == uc_count)
1106 break;
1107 memcpy(uc_addr[i++], ha->addr, ETH_ALEN);
1108 }
1109
1110 for (i = 0; i < enic->uc_count; i++) {
1111 for (j = 0; j < uc_count; j++)
1112 if (compare_ether_addr(enic->uc_addr[i],
1113 uc_addr[j]) == 0)
1114 break;
1115 if (j == uc_count)
1116 enic_dev_del_addr(enic, enic->uc_addr[i]);
1117 }
1118
1119 for (i = 0; i < uc_count; i++) {
1120 for (j = 0; j < enic->uc_count; j++)
1121 if (compare_ether_addr(uc_addr[i],
1122 enic->uc_addr[j]) == 0)
1123 break;
1124 if (j == enic->uc_count)
1125 enic_dev_add_addr(enic, uc_addr[i]);
1126 }
1127
1128 /* Save the list to compare against next time
1129 */
1130
1131 for (i = 0; i < uc_count; i++)
1132 memcpy(enic->uc_addr[i], uc_addr[i], ETH_ALEN);
1133
1134 enic->uc_count = uc_count;
1135}
1136
1137/* netif_tx_lock held, BHs disabled */
1138static void enic_set_rx_mode(struct net_device *netdev)
1139{
1140 struct enic *enic = netdev_priv(netdev);
1141 int directed = 1;
1142 int multicast = (netdev->flags & IFF_MULTICAST) ? 1 : 0;
1143 int broadcast = (netdev->flags & IFF_BROADCAST) ? 1 : 0;
1144 int promisc = (netdev->flags & IFF_PROMISC) ||
1145 netdev_uc_count(netdev) > ENIC_UNICAST_PERFECT_FILTERS;
1146 int allmulti = (netdev->flags & IFF_ALLMULTI) ||
1147 netdev_mc_count(netdev) > ENIC_MULTICAST_PERFECT_FILTERS;
1148 unsigned int flags = netdev->flags |
1149 (allmulti ? IFF_ALLMULTI : 0) |
1150 (promisc ? IFF_PROMISC : 0);
1151
1152 if (enic->flags != flags) {
1153 enic->flags = flags;
1154 enic_dev_packet_filter(enic, directed,
1155 multicast, broadcast, promisc, allmulti);
1156 }
1157
1158 if (!promisc) {
1159 enic_add_unicast_addr_list(enic);
1160 if (!allmulti)
1161 enic_add_multicast_addr_list(enic);
1162 }
1163}
1164
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001165/* rtnl lock is held */
1166static void enic_vlan_rx_register(struct net_device *netdev,
1167 struct vlan_group *vlan_group)
1168{
1169 struct enic *enic = netdev_priv(netdev);
1170 enic->vlan_group = vlan_group;
1171}
1172
1173/* rtnl lock is held */
1174static void enic_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
1175{
1176 struct enic *enic = netdev_priv(netdev);
1177
1178 spin_lock(&enic->devcmd_lock);
1179 enic_add_vlan(enic, vid);
1180 spin_unlock(&enic->devcmd_lock);
1181}
1182
1183/* rtnl lock is held */
1184static void enic_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
1185{
1186 struct enic *enic = netdev_priv(netdev);
1187
1188 spin_lock(&enic->devcmd_lock);
1189 enic_del_vlan(enic, vid);
1190 spin_unlock(&enic->devcmd_lock);
1191}
1192
1193/* netif_tx_lock held, BHs disabled */
1194static void enic_tx_timeout(struct net_device *netdev)
1195{
1196 struct enic *enic = netdev_priv(netdev);
1197 schedule_work(&enic->reset);
1198}
1199
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001200static int enic_vnic_dev_deinit(struct enic *enic)
1201{
1202 int err;
1203
1204 spin_lock(&enic->devcmd_lock);
1205 err = vnic_dev_deinit(enic->vdev);
1206 spin_unlock(&enic->devcmd_lock);
1207
1208 return err;
1209}
1210
1211static int enic_dev_init_prov(struct enic *enic, struct vic_provinfo *vp)
1212{
1213 int err;
1214
1215 spin_lock(&enic->devcmd_lock);
1216 err = vnic_dev_init_prov(enic->vdev,
1217 (u8 *)vp, vic_provinfo_size(vp));
1218 spin_unlock(&enic->devcmd_lock);
1219
1220 return err;
1221}
1222
1223static int enic_dev_init_done(struct enic *enic, int *done, int *error)
1224{
1225 int err;
1226
1227 spin_lock(&enic->devcmd_lock);
1228 err = vnic_dev_init_done(enic->vdev, done, error);
1229 spin_unlock(&enic->devcmd_lock);
1230
1231 return err;
1232}
1233
Roopa Prabhu0b1c00f2010-12-08 13:53:58 +00001234static int enic_set_vf_mac(struct net_device *netdev, int vf, u8 *mac)
1235{
1236 struct enic *enic = netdev_priv(netdev);
1237
1238 if (vf != PORT_SELF_VF)
1239 return -EOPNOTSUPP;
1240
1241 /* Ignore the vf argument for now. We can assume the request
1242 * is coming on a vf.
1243 */
1244 if (is_valid_ether_addr(mac)) {
1245 memcpy(enic->pp.vf_mac, mac, ETH_ALEN);
1246 return 0;
1247 } else
1248 return -EINVAL;
1249}
1250
Scott Feldman08f382e2010-06-01 08:59:33 +00001251static int enic_set_port_profile(struct enic *enic, u8 *mac)
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001252{
1253 struct vic_provinfo *vp;
1254 u8 oui[3] = VIC_PROVINFO_CISCO_OUI;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001255 char uuid_str[38];
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001256 int err;
1257
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001258 err = enic_vnic_dev_deinit(enic);
1259 if (err)
Scott Feldman08f382e2010-06-01 08:59:33 +00001260 return err;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001261
Scott Feldman08f382e2010-06-01 08:59:33 +00001262 switch (enic->pp.request) {
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001263
Scott Feldman08f382e2010-06-01 08:59:33 +00001264 case PORT_REQUEST_ASSOCIATE:
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001265
Scott Feldman08f382e2010-06-01 08:59:33 +00001266 if (!(enic->pp.set & ENIC_SET_NAME) || !strlen(enic->pp.name))
1267 return -EINVAL;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001268
Scott Feldman08f382e2010-06-01 08:59:33 +00001269 if (!is_valid_ether_addr(mac))
1270 return -EADDRNOTAVAIL;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001271
Scott Feldman08f382e2010-06-01 08:59:33 +00001272 vp = vic_provinfo_alloc(GFP_KERNEL, oui,
1273 VIC_PROVINFO_LINUX_TYPE);
1274 if (!vp)
1275 return -ENOMEM;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001276
Scott Feldman08f382e2010-06-01 08:59:33 +00001277 vic_provinfo_add_tlv(vp,
1278 VIC_LINUX_PROV_TLV_PORT_PROFILE_NAME_STR,
1279 strlen(enic->pp.name) + 1, enic->pp.name);
1280
Roopa Prabhu29639052010-12-08 13:54:03 +00001281 if (!is_zero_ether_addr(enic->pp.mac_addr))
1282 vic_provinfo_add_tlv(vp,
1283 VIC_LINUX_PROV_TLV_CLIENT_MAC_ADDR,
1284 ETH_ALEN, enic->pp.mac_addr);
1285 else
1286 vic_provinfo_add_tlv(vp,
1287 VIC_LINUX_PROV_TLV_CLIENT_MAC_ADDR,
1288 ETH_ALEN, mac);
Scott Feldman08f382e2010-06-01 08:59:33 +00001289
1290 if (enic->pp.set & ENIC_SET_INSTANCE) {
Joe Perchesc33788b2010-08-03 09:32:24 +00001291 sprintf(uuid_str, "%pUB", enic->pp.instance_uuid);
Scott Feldman08f382e2010-06-01 08:59:33 +00001292 vic_provinfo_add_tlv(vp,
1293 VIC_LINUX_PROV_TLV_CLIENT_UUID_STR,
1294 sizeof(uuid_str), uuid_str);
1295 }
1296
1297 if (enic->pp.set & ENIC_SET_HOST) {
Joe Perchesc33788b2010-08-03 09:32:24 +00001298 sprintf(uuid_str, "%pUB", enic->pp.host_uuid);
Scott Feldman08f382e2010-06-01 08:59:33 +00001299 vic_provinfo_add_tlv(vp,
1300 VIC_LINUX_PROV_TLV_HOST_UUID_STR,
1301 sizeof(uuid_str), uuid_str);
1302 }
1303
1304 err = enic_dev_init_prov(enic, vp);
1305 vic_provinfo_free(vp);
1306 if (err)
1307 return err;
Roopa Prabhu29639052010-12-08 13:54:03 +00001308
1309 enic->pp.set |= ENIC_SET_APPLIED;
Scott Feldman08f382e2010-06-01 08:59:33 +00001310 break;
1311
1312 case PORT_REQUEST_DISASSOCIATE:
Roopa Prabhu29639052010-12-08 13:54:03 +00001313 enic->pp.set &= ~ENIC_SET_APPLIED;
Scott Feldman08f382e2010-06-01 08:59:33 +00001314 break;
1315
1316 default:
1317 return -EINVAL;
1318 }
1319
Scott Feldman08f382e2010-06-01 08:59:33 +00001320 return 0;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001321}
1322
1323static int enic_set_vf_port(struct net_device *netdev, int vf,
1324 struct nlattr *port[])
1325{
1326 struct enic *enic = netdev_priv(netdev);
Roopa Prabhu29639052010-12-08 13:54:03 +00001327 struct enic_port_profile new_pp;
1328 int err = 0;
Scott Feldman08f382e2010-06-01 08:59:33 +00001329
Roopa Prabhu29639052010-12-08 13:54:03 +00001330 memset(&new_pp, 0, sizeof(new_pp));
Scott Feldman08f382e2010-06-01 08:59:33 +00001331
1332 if (port[IFLA_PORT_REQUEST]) {
Roopa Prabhu29639052010-12-08 13:54:03 +00001333 new_pp.set |= ENIC_SET_REQUEST;
1334 new_pp.request = nla_get_u8(port[IFLA_PORT_REQUEST]);
Scott Feldman08f382e2010-06-01 08:59:33 +00001335 }
1336
1337 if (port[IFLA_PORT_PROFILE]) {
Roopa Prabhu29639052010-12-08 13:54:03 +00001338 new_pp.set |= ENIC_SET_NAME;
1339 memcpy(new_pp.name, nla_data(port[IFLA_PORT_PROFILE]),
Scott Feldman08f382e2010-06-01 08:59:33 +00001340 PORT_PROFILE_MAX);
1341 }
1342
1343 if (port[IFLA_PORT_INSTANCE_UUID]) {
Roopa Prabhu29639052010-12-08 13:54:03 +00001344 new_pp.set |= ENIC_SET_INSTANCE;
1345 memcpy(new_pp.instance_uuid,
Scott Feldman08f382e2010-06-01 08:59:33 +00001346 nla_data(port[IFLA_PORT_INSTANCE_UUID]), PORT_UUID_MAX);
1347 }
1348
1349 if (port[IFLA_PORT_HOST_UUID]) {
Roopa Prabhu29639052010-12-08 13:54:03 +00001350 new_pp.set |= ENIC_SET_HOST;
1351 memcpy(new_pp.host_uuid,
Scott Feldman08f382e2010-06-01 08:59:33 +00001352 nla_data(port[IFLA_PORT_HOST_UUID]), PORT_UUID_MAX);
1353 }
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001354
1355 /* don't support VFs, yet */
1356 if (vf != PORT_SELF_VF)
1357 return -EOPNOTSUPP;
1358
Roopa Prabhu29639052010-12-08 13:54:03 +00001359 if (!(new_pp.set & ENIC_SET_REQUEST))
Scott Feldman08f382e2010-06-01 08:59:33 +00001360 return -EOPNOTSUPP;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001361
Roopa Prabhu29639052010-12-08 13:54:03 +00001362 if (new_pp.request == PORT_REQUEST_ASSOCIATE) {
1363 /* Special case handling */
1364 if (!is_zero_ether_addr(enic->pp.vf_mac))
1365 memcpy(new_pp.mac_addr, enic->pp.vf_mac, ETH_ALEN);
Scott Feldman418c4372010-05-22 17:29:58 +00001366
1367 if (is_zero_ether_addr(netdev->dev_addr))
1368 random_ether_addr(netdev->dev_addr);
Roopa Prabhu29639052010-12-08 13:54:03 +00001369 } else if (new_pp.request == PORT_REQUEST_DISASSOCIATE) {
1370 if (!is_zero_ether_addr(enic->pp.mac_addr))
1371 enic_dev_del_addr(enic, enic->pp.mac_addr);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001372 }
1373
Roopa Prabhu29639052010-12-08 13:54:03 +00001374 memcpy(&enic->pp, &new_pp, sizeof(struct enic_port_profile));
1375
1376 err = enic_set_port_profile(enic, netdev->dev_addr);
1377 if (err)
1378 goto set_port_profile_cleanup;
1379
1380 if (!is_zero_ether_addr(enic->pp.mac_addr))
1381 enic_dev_add_addr(enic, enic->pp.mac_addr);
1382
1383set_port_profile_cleanup:
1384 memset(enic->pp.vf_mac, 0, ETH_ALEN);
1385
1386 if (err || enic->pp.request == PORT_REQUEST_DISASSOCIATE) {
1387 memset(netdev->dev_addr, 0, ETH_ALEN);
1388 memset(enic->pp.mac_addr, 0, ETH_ALEN);
1389 }
1390
1391 return err;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001392}
1393
1394static int enic_get_vf_port(struct net_device *netdev, int vf,
1395 struct sk_buff *skb)
1396{
1397 struct enic *enic = netdev_priv(netdev);
1398 int err, error, done;
1399 u16 response = PORT_PROFILE_RESPONSE_SUCCESS;
1400
Scott Feldman08f382e2010-06-01 08:59:33 +00001401 if (!(enic->pp.set & ENIC_SET_APPLIED))
1402 return -ENODATA;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001403
1404 err = enic_dev_init_done(enic, &done, &error);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001405 if (err)
Scott Feldman08f382e2010-06-01 08:59:33 +00001406 error = err;
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001407
1408 switch (error) {
1409 case ERR_SUCCESS:
1410 if (!done)
1411 response = PORT_PROFILE_RESPONSE_INPROGRESS;
1412 break;
1413 case ERR_EINVAL:
1414 response = PORT_PROFILE_RESPONSE_INVALID;
1415 break;
1416 case ERR_EBADSTATE:
1417 response = PORT_PROFILE_RESPONSE_BADSTATE;
1418 break;
1419 case ERR_ENOMEM:
1420 response = PORT_PROFILE_RESPONSE_INSUFFICIENT_RESOURCES;
1421 break;
1422 default:
1423 response = PORT_PROFILE_RESPONSE_ERROR;
1424 break;
1425 }
1426
1427 NLA_PUT_U16(skb, IFLA_PORT_REQUEST, enic->pp.request);
1428 NLA_PUT_U16(skb, IFLA_PORT_RESPONSE, response);
Scott Feldman08f382e2010-06-01 08:59:33 +00001429 if (enic->pp.set & ENIC_SET_NAME)
1430 NLA_PUT(skb, IFLA_PORT_PROFILE, PORT_PROFILE_MAX,
1431 enic->pp.name);
1432 if (enic->pp.set & ENIC_SET_INSTANCE)
1433 NLA_PUT(skb, IFLA_PORT_INSTANCE_UUID, PORT_UUID_MAX,
1434 enic->pp.instance_uuid);
1435 if (enic->pp.set & ENIC_SET_HOST)
1436 NLA_PUT(skb, IFLA_PORT_HOST_UUID, PORT_UUID_MAX,
1437 enic->pp.host_uuid);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07001438
1439 return 0;
1440
1441nla_put_failure:
1442 return -EMSGSIZE;
1443}
1444
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001445static void enic_free_rq_buf(struct vnic_rq *rq, struct vnic_rq_buf *buf)
1446{
1447 struct enic *enic = vnic_dev_priv(rq->vdev);
1448
1449 if (!buf->os_buf)
1450 return;
1451
1452 pci_unmap_single(enic->pdev, buf->dma_addr,
1453 buf->len, PCI_DMA_FROMDEVICE);
1454 dev_kfree_skb_any(buf->os_buf);
1455}
1456
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001457static int enic_rq_alloc_buf(struct vnic_rq *rq)
1458{
1459 struct enic *enic = vnic_dev_priv(rq->vdev);
Scott Feldmand19e22d2009-09-03 17:02:08 +00001460 struct net_device *netdev = enic->netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001461 struct sk_buff *skb;
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +00001462 unsigned int len = netdev->mtu + VLAN_ETH_HLEN;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001463 unsigned int os_buf_index = 0;
1464 dma_addr_t dma_addr;
1465
Eric Dumazet89d71a62009-10-13 05:34:20 +00001466 skb = netdev_alloc_skb_ip_align(netdev, len);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001467 if (!skb)
1468 return -ENOMEM;
1469
1470 dma_addr = pci_map_single(enic->pdev, skb->data,
1471 len, PCI_DMA_FROMDEVICE);
1472
1473 enic_queue_rq_desc(rq, skb, os_buf_index,
1474 dma_addr, len);
1475
1476 return 0;
1477}
1478
Scott Feldman4badc382009-09-03 17:01:58 +00001479static int enic_rq_alloc_buf_a1(struct vnic_rq *rq)
1480{
1481 struct rq_enet_desc *desc = vnic_rq_next_desc(rq);
1482
1483 if (vnic_rq_posting_soon(rq)) {
1484
1485 /* SW workaround for A0 HW erratum: if we're just about
1486 * to write posted_index, insert a dummy desc
1487 * of type resvd
1488 */
1489
1490 rq_enet_desc_enc(desc, 0, RQ_ENET_TYPE_RESV2, 0);
1491 vnic_rq_post(rq, 0, 0, 0, 0);
1492 } else {
1493 return enic_rq_alloc_buf(rq);
1494 }
1495
1496 return 0;
1497}
1498
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001499static int enic_dev_hw_version(struct enic *enic,
1500 enum vnic_dev_hw_version *hw_ver)
1501{
1502 int err;
1503
1504 spin_lock(&enic->devcmd_lock);
1505 err = vnic_dev_hw_version(enic->vdev, hw_ver);
1506 spin_unlock(&enic->devcmd_lock);
1507
1508 return err;
1509}
1510
Scott Feldman4badc382009-09-03 17:01:58 +00001511static int enic_set_rq_alloc_buf(struct enic *enic)
1512{
1513 enum vnic_dev_hw_version hw_ver;
1514 int err;
1515
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001516 err = enic_dev_hw_version(enic, &hw_ver);
Scott Feldman4badc382009-09-03 17:01:58 +00001517 if (err)
1518 return err;
1519
1520 switch (hw_ver) {
1521 case VNIC_DEV_HW_VER_A1:
1522 enic->rq_alloc_buf = enic_rq_alloc_buf_a1;
1523 break;
1524 case VNIC_DEV_HW_VER_A2:
1525 case VNIC_DEV_HW_VER_UNKNOWN:
1526 enic->rq_alloc_buf = enic_rq_alloc_buf;
1527 break;
1528 default:
1529 return -ENODEV;
1530 }
1531
1532 return 0;
1533}
1534
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001535static void enic_rq_indicate_buf(struct vnic_rq *rq,
1536 struct cq_desc *cq_desc, struct vnic_rq_buf *buf,
1537 int skipped, void *opaque)
1538{
1539 struct enic *enic = vnic_dev_priv(rq->vdev);
Scott Feldman86ca9db2008-11-21 21:26:55 -08001540 struct net_device *netdev = enic->netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001541 struct sk_buff *skb;
1542
1543 u8 type, color, eop, sop, ingress_port, vlan_stripped;
1544 u8 fcoe, fcoe_sof, fcoe_fc_crc_ok, fcoe_enc_error, fcoe_eof;
1545 u8 tcp_udp_csum_ok, udp, tcp, ipv4_csum_ok;
1546 u8 ipv6, ipv4, ipv4_fragment, fcs_ok, rss_type, csum_not_calc;
1547 u8 packet_error;
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001548 u16 q_number, completed_index, bytes_written, vlan_tci, checksum;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001549 u32 rss_hash;
1550
1551 if (skipped)
1552 return;
1553
1554 skb = buf->os_buf;
1555 prefetch(skb->data - NET_IP_ALIGN);
1556 pci_unmap_single(enic->pdev, buf->dma_addr,
1557 buf->len, PCI_DMA_FROMDEVICE);
1558
1559 cq_enet_rq_desc_dec((struct cq_enet_rq_desc *)cq_desc,
1560 &type, &color, &q_number, &completed_index,
1561 &ingress_port, &fcoe, &eop, &sop, &rss_type,
1562 &csum_not_calc, &rss_hash, &bytes_written,
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001563 &packet_error, &vlan_stripped, &vlan_tci, &checksum,
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001564 &fcoe_sof, &fcoe_fc_crc_ok, &fcoe_enc_error,
1565 &fcoe_eof, &tcp_udp_csum_ok, &udp, &tcp,
1566 &ipv4_csum_ok, &ipv6, &ipv4, &ipv4_fragment,
1567 &fcs_ok);
1568
1569 if (packet_error) {
1570
Scott Feldman350991e2009-09-03 17:02:19 +00001571 if (!fcs_ok) {
1572 if (bytes_written > 0)
1573 enic->rq_bad_fcs++;
1574 else if (bytes_written == 0)
1575 enic->rq_truncated_pkts++;
1576 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001577
1578 dev_kfree_skb_any(skb);
1579
1580 return;
1581 }
1582
1583 if (eop && bytes_written > 0) {
1584
1585 /* Good receive
1586 */
1587
1588 skb_put(skb, bytes_written);
Scott Feldman86ca9db2008-11-21 21:26:55 -08001589 skb->protocol = eth_type_trans(skb, netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001590
1591 if (enic->csum_rx_enabled && !csum_not_calc) {
1592 skb->csum = htons(checksum);
1593 skb->ip_summed = CHECKSUM_COMPLETE;
1594 }
1595
Scott Feldman86ca9db2008-11-21 21:26:55 -08001596 skb->dev = netdev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001597
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001598 if (enic->vlan_group && vlan_stripped &&
1599 (vlan_tci & CQ_ENET_RQ_DESC_VLAN_TCI_VLAN_MASK)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001600
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001601 if (netdev->features & NETIF_F_GRO)
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001602 vlan_gro_receive(&enic->napi[q_number],
1603 enic->vlan_group, vlan_tci, skb);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001604 else
1605 vlan_hwaccel_receive_skb(skb,
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00001606 enic->vlan_group, vlan_tci);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001607
1608 } else {
1609
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001610 if (netdev->features & NETIF_F_GRO)
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001611 napi_gro_receive(&enic->napi[q_number], skb);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001612 else
1613 netif_receive_skb(skb);
1614
1615 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001616 } else {
1617
1618 /* Buffer overflow
1619 */
1620
1621 dev_kfree_skb_any(skb);
1622 }
1623}
1624
1625static int enic_rq_service(struct vnic_dev *vdev, struct cq_desc *cq_desc,
1626 u8 type, u16 q_number, u16 completed_index, void *opaque)
1627{
1628 struct enic *enic = vnic_dev_priv(vdev);
1629
1630 vnic_rq_service(&enic->rq[q_number], cq_desc,
1631 completed_index, VNIC_RQ_RETURN_DESC,
1632 enic_rq_indicate_buf, opaque);
1633
1634 return 0;
1635}
1636
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001637static int enic_poll(struct napi_struct *napi, int budget)
1638{
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001639 struct net_device *netdev = napi->dev;
1640 struct enic *enic = netdev_priv(netdev);
1641 unsigned int cq_rq = enic_cq_rq(enic, 0);
1642 unsigned int cq_wq = enic_cq_wq(enic, 0);
1643 unsigned int intr = enic_legacy_io_intr();
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001644 unsigned int rq_work_to_do = budget;
1645 unsigned int wq_work_to_do = -1; /* no limit */
1646 unsigned int work_done, rq_work_done, wq_work_done;
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001647 int err;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001648
1649 /* Service RQ (first) and WQ
1650 */
1651
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001652 rq_work_done = vnic_cq_service(&enic->cq[cq_rq],
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001653 rq_work_to_do, enic_rq_service, NULL);
1654
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001655 wq_work_done = vnic_cq_service(&enic->cq[cq_wq],
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001656 wq_work_to_do, enic_wq_service, NULL);
1657
1658 /* Accumulate intr event credits for this polling
1659 * cycle. An intr event is the completion of a
1660 * a WQ or RQ packet.
1661 */
1662
1663 work_done = rq_work_done + wq_work_done;
1664
1665 if (work_done > 0)
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001666 vnic_intr_return_credits(&enic->intr[intr],
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001667 work_done,
1668 0 /* don't unmask intr */,
1669 0 /* don't reset intr timer */);
1670
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001671 err = vnic_rq_fill(&enic->rq[0], enic->rq_alloc_buf);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001672
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001673 /* Buffer allocation failed. Stay in polling
1674 * mode so we can try to fill the ring again.
1675 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001676
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001677 if (err)
1678 rq_work_done = rq_work_to_do;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001679
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001680 if (rq_work_done < rq_work_to_do) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001681
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001682 /* Some work done, but not enough to stay in polling,
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001683 * exit polling
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001684 */
1685
Ben Hutchings288379f2009-01-19 16:43:59 -08001686 napi_complete(napi);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001687 vnic_intr_unmask(&enic->intr[intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001688 }
1689
1690 return rq_work_done;
1691}
1692
1693static int enic_poll_msix(struct napi_struct *napi, int budget)
1694{
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001695 struct net_device *netdev = napi->dev;
1696 struct enic *enic = netdev_priv(netdev);
1697 unsigned int rq = (napi - &enic->napi[0]);
1698 unsigned int cq = enic_cq_rq(enic, rq);
1699 unsigned int intr = enic_msix_rq_intr(enic, rq);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001700 unsigned int work_to_do = budget;
1701 unsigned int work_done;
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001702 int err;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001703
1704 /* Service RQ
1705 */
1706
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001707 work_done = vnic_cq_service(&enic->cq[cq],
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001708 work_to_do, enic_rq_service, NULL);
1709
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001710 /* Return intr event credits for this polling
1711 * cycle. An intr event is the completion of a
1712 * RQ packet.
1713 */
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001714
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001715 if (work_done > 0)
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001716 vnic_intr_return_credits(&enic->intr[intr],
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001717 work_done,
1718 0 /* don't unmask intr */,
1719 0 /* don't reset intr timer */);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001720
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001721 err = vnic_rq_fill(&enic->rq[rq], enic->rq_alloc_buf);
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001722
1723 /* Buffer allocation failed. Stay in polling mode
1724 * so we can try to fill the ring again.
1725 */
1726
1727 if (err)
1728 work_done = work_to_do;
1729
1730 if (work_done < work_to_do) {
1731
1732 /* Some work done, but not enough to stay in polling,
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00001733 * exit polling
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001734 */
1735
Ben Hutchings288379f2009-01-19 16:43:59 -08001736 napi_complete(napi);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001737 vnic_intr_unmask(&enic->intr[intr]);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001738 }
1739
1740 return work_done;
1741}
1742
1743static void enic_notify_timer(unsigned long data)
1744{
1745 struct enic *enic = (struct enic *)data;
1746
1747 enic_notify_check(enic);
1748
Scott Feldman25f0a062008-09-24 11:23:32 -07001749 mod_timer(&enic->notify_timer,
1750 round_jiffies(jiffies + ENIC_NOTIFY_TIMER_PERIOD));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001751}
1752
1753static void enic_free_intr(struct enic *enic)
1754{
1755 struct net_device *netdev = enic->netdev;
1756 unsigned int i;
1757
1758 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1759 case VNIC_DEV_INTR_MODE_INTX:
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001760 free_irq(enic->pdev->irq, netdev);
1761 break;
Scott Feldman8f4d2482008-09-24 11:23:42 -07001762 case VNIC_DEV_INTR_MODE_MSI:
1763 free_irq(enic->pdev->irq, enic);
1764 break;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001765 case VNIC_DEV_INTR_MODE_MSIX:
1766 for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
1767 if (enic->msix[i].requested)
1768 free_irq(enic->msix_entry[i].vector,
1769 enic->msix[i].devid);
1770 break;
1771 default:
1772 break;
1773 }
1774}
1775
1776static int enic_request_intr(struct enic *enic)
1777{
1778 struct net_device *netdev = enic->netdev;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001779 unsigned int i, intr;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001780 int err = 0;
1781
1782 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1783
1784 case VNIC_DEV_INTR_MODE_INTX:
1785
1786 err = request_irq(enic->pdev->irq, enic_isr_legacy,
1787 IRQF_SHARED, netdev->name, netdev);
1788 break;
1789
1790 case VNIC_DEV_INTR_MODE_MSI:
1791
1792 err = request_irq(enic->pdev->irq, enic_isr_msi,
1793 0, netdev->name, enic);
1794 break;
1795
1796 case VNIC_DEV_INTR_MODE_MSIX:
1797
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001798 for (i = 0; i < enic->rq_count; i++) {
1799 intr = enic_msix_rq_intr(enic, i);
1800 sprintf(enic->msix[intr].devname,
1801 "%.11s-rx-%d", netdev->name, i);
1802 enic->msix[intr].isr = enic_isr_msix_rq;
1803 enic->msix[intr].devid = &enic->napi[i];
1804 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001805
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001806 for (i = 0; i < enic->wq_count; i++) {
1807 intr = enic_msix_wq_intr(enic, i);
1808 sprintf(enic->msix[intr].devname,
1809 "%.11s-tx-%d", netdev->name, i);
1810 enic->msix[intr].isr = enic_isr_msix_wq;
1811 enic->msix[intr].devid = enic;
1812 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001813
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001814 intr = enic_msix_err_intr(enic);
1815 sprintf(enic->msix[intr].devname,
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001816 "%.11s-err", netdev->name);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001817 enic->msix[intr].isr = enic_isr_msix_err;
1818 enic->msix[intr].devid = enic;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001819
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001820 intr = enic_msix_notify_intr(enic);
1821 sprintf(enic->msix[intr].devname,
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001822 "%.11s-notify", netdev->name);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001823 enic->msix[intr].isr = enic_isr_msix_notify;
1824 enic->msix[intr].devid = enic;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001825
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001826 for (i = 0; i < ARRAY_SIZE(enic->msix); i++)
1827 enic->msix[i].requested = 0;
1828
1829 for (i = 0; i < enic->intr_count; i++) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001830 err = request_irq(enic->msix_entry[i].vector,
1831 enic->msix[i].isr, 0,
1832 enic->msix[i].devname,
1833 enic->msix[i].devid);
1834 if (err) {
1835 enic_free_intr(enic);
1836 break;
1837 }
1838 enic->msix[i].requested = 1;
1839 }
1840
1841 break;
1842
1843 default:
1844 break;
1845 }
1846
1847 return err;
1848}
1849
Scott Feldmanb3d18d12009-12-23 13:27:30 +00001850static void enic_synchronize_irqs(struct enic *enic)
1851{
1852 unsigned int i;
1853
1854 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1855 case VNIC_DEV_INTR_MODE_INTX:
1856 case VNIC_DEV_INTR_MODE_MSI:
1857 synchronize_irq(enic->pdev->irq);
1858 break;
1859 case VNIC_DEV_INTR_MODE_MSIX:
1860 for (i = 0; i < enic->intr_count; i++)
1861 synchronize_irq(enic->msix_entry[i].vector);
1862 break;
1863 default:
1864 break;
1865 }
1866}
1867
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001868static int enic_dev_notify_set(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001869{
1870 int err;
1871
Scott Feldman56ac88b2009-09-03 17:02:14 +00001872 spin_lock(&enic->devcmd_lock);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001873 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1874 case VNIC_DEV_INTR_MODE_INTX:
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001875 err = vnic_dev_notify_set(enic->vdev,
1876 enic_legacy_notify_intr());
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001877 break;
1878 case VNIC_DEV_INTR_MODE_MSIX:
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001879 err = vnic_dev_notify_set(enic->vdev,
1880 enic_msix_notify_intr(enic));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001881 break;
1882 default:
1883 err = vnic_dev_notify_set(enic->vdev, -1 /* no intr */);
1884 break;
1885 }
Scott Feldman56ac88b2009-09-03 17:02:14 +00001886 spin_unlock(&enic->devcmd_lock);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001887
1888 return err;
1889}
1890
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001891static int enic_dev_notify_unset(struct enic *enic)
1892{
1893 int err;
1894
1895 spin_lock(&enic->devcmd_lock);
1896 err = vnic_dev_notify_unset(enic->vdev);
1897 spin_unlock(&enic->devcmd_lock);
1898
1899 return err;
1900}
1901
1902static int enic_dev_enable(struct enic *enic)
1903{
1904 int err;
1905
1906 spin_lock(&enic->devcmd_lock);
Vasanthy Kolluri2db77e02010-10-20 10:17:09 +00001907 err = vnic_dev_enable_wait(enic->vdev);
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001908 spin_unlock(&enic->devcmd_lock);
1909
1910 return err;
1911}
1912
1913static int enic_dev_disable(struct enic *enic)
1914{
1915 int err;
1916
1917 spin_lock(&enic->devcmd_lock);
1918 err = vnic_dev_disable(enic->vdev);
1919 spin_unlock(&enic->devcmd_lock);
1920
1921 return err;
1922}
1923
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001924static void enic_notify_timer_start(struct enic *enic)
1925{
1926 switch (vnic_dev_get_intr_mode(enic->vdev)) {
1927 case VNIC_DEV_INTR_MODE_MSI:
1928 mod_timer(&enic->notify_timer, jiffies);
1929 break;
1930 default:
1931 /* Using intr for notification for INTx/MSI-X */
1932 break;
1933 };
1934}
1935
1936/* rtnl lock is held, process context */
1937static int enic_open(struct net_device *netdev)
1938{
1939 struct enic *enic = netdev_priv(netdev);
1940 unsigned int i;
1941 int err;
1942
Scott Feldman4b75a442008-09-24 11:23:53 -07001943 err = enic_request_intr(enic);
1944 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001945 netdev_err(netdev, "Unable to request irq.\n");
Scott Feldman4b75a442008-09-24 11:23:53 -07001946 return err;
1947 }
1948
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001949 err = enic_dev_notify_set(enic);
Scott Feldman4b75a442008-09-24 11:23:53 -07001950 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001951 netdev_err(netdev,
1952 "Failed to alloc notify buffer, aborting.\n");
Scott Feldman4b75a442008-09-24 11:23:53 -07001953 goto err_out_free_intr;
1954 }
1955
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001956 for (i = 0; i < enic->rq_count; i++) {
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001957 vnic_rq_fill(&enic->rq[i], enic->rq_alloc_buf);
1958 /* Need at least one buffer on ring to get going */
1959 if (vnic_rq_desc_used(&enic->rq[i]) == 0) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00001960 netdev_err(netdev, "Unable to alloc receive buffers\n");
Scott Feldman2d6ddce2009-12-23 13:27:38 +00001961 err = -ENOMEM;
Scott Feldman4b75a442008-09-24 11:23:53 -07001962 goto err_out_notify_unset;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001963 }
1964 }
1965
1966 for (i = 0; i < enic->wq_count; i++)
1967 vnic_wq_enable(&enic->wq[i]);
1968 for (i = 0; i < enic->rq_count; i++)
1969 vnic_rq_enable(&enic->rq[i]);
1970
Roopa Prabhu29639052010-12-08 13:54:03 +00001971 if (enic_is_dynamic(enic) && !is_zero_ether_addr(enic->pp.mac_addr))
1972 enic_dev_add_addr(enic, enic->pp.mac_addr);
1973 else
1974 enic_dev_add_station_addr(enic);
Roopa Prabhu319d7e82010-12-08 13:19:58 +00001975 enic_set_rx_mode(netdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001976
1977 netif_wake_queue(netdev);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00001978
1979 for (i = 0; i < enic->rq_count; i++)
1980 napi_enable(&enic->napi[i]);
1981
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001982 enic_dev_enable(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001983
1984 for (i = 0; i < enic->intr_count; i++)
1985 vnic_intr_unmask(&enic->intr[i]);
1986
1987 enic_notify_timer_start(enic);
1988
1989 return 0;
Scott Feldman4b75a442008-09-24 11:23:53 -07001990
1991err_out_notify_unset:
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00001992 enic_dev_notify_unset(enic);
Scott Feldman4b75a442008-09-24 11:23:53 -07001993err_out_free_intr:
1994 enic_free_intr(enic);
1995
1996 return err;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07001997}
1998
1999/* rtnl lock is held, process context */
2000static int enic_stop(struct net_device *netdev)
2001{
2002 struct enic *enic = netdev_priv(netdev);
2003 unsigned int i;
2004 int err;
2005
Vasanthy Kolluri29046f92010-06-24 10:52:26 +00002006 for (i = 0; i < enic->intr_count; i++) {
Scott Feldmanb3d18d12009-12-23 13:27:30 +00002007 vnic_intr_mask(&enic->intr[i]);
Vasanthy Kolluri29046f92010-06-24 10:52:26 +00002008 (void)vnic_intr_masked(&enic->intr[i]); /* flush write */
2009 }
Scott Feldmanb3d18d12009-12-23 13:27:30 +00002010
2011 enic_synchronize_irqs(enic);
2012
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002013 del_timer_sync(&enic->notify_timer);
2014
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002015 enic_dev_disable(enic);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002016
2017 for (i = 0; i < enic->rq_count; i++)
2018 napi_disable(&enic->napi[i]);
2019
Scott Feldmanb3d18d12009-12-23 13:27:30 +00002020 netif_carrier_off(netdev);
2021 netif_tx_disable(netdev);
Roopa Prabhu29639052010-12-08 13:54:03 +00002022 if (enic_is_dynamic(enic) && !is_zero_ether_addr(enic->pp.mac_addr))
2023 enic_dev_del_addr(enic, enic->pp.mac_addr);
2024 else
2025 enic_dev_del_station_addr(enic);
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002026
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002027 for (i = 0; i < enic->wq_count; i++) {
2028 err = vnic_wq_disable(&enic->wq[i]);
2029 if (err)
2030 return err;
2031 }
2032 for (i = 0; i < enic->rq_count; i++) {
2033 err = vnic_rq_disable(&enic->rq[i]);
2034 if (err)
2035 return err;
2036 }
2037
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002038 enic_dev_notify_unset(enic);
Scott Feldman4b75a442008-09-24 11:23:53 -07002039 enic_free_intr(enic);
2040
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002041 for (i = 0; i < enic->wq_count; i++)
2042 vnic_wq_clean(&enic->wq[i], enic_free_wq_buf);
2043 for (i = 0; i < enic->rq_count; i++)
2044 vnic_rq_clean(&enic->rq[i], enic_free_rq_buf);
2045 for (i = 0; i < enic->cq_count; i++)
2046 vnic_cq_clean(&enic->cq[i]);
2047 for (i = 0; i < enic->intr_count; i++)
2048 vnic_intr_clean(&enic->intr[i]);
2049
2050 return 0;
2051}
2052
2053static int enic_change_mtu(struct net_device *netdev, int new_mtu)
2054{
2055 struct enic *enic = netdev_priv(netdev);
2056 int running = netif_running(netdev);
2057
Scott Feldman25f0a062008-09-24 11:23:32 -07002058 if (new_mtu < ENIC_MIN_MTU || new_mtu > ENIC_MAX_MTU)
2059 return -EINVAL;
2060
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002061 if (running)
2062 enic_stop(netdev);
2063
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002064 netdev->mtu = new_mtu;
2065
2066 if (netdev->mtu > enic->port_mtu)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002067 netdev_warn(netdev,
2068 "interface MTU (%d) set higher than port MTU (%d)\n",
2069 netdev->mtu, enic->port_mtu);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002070
2071 if (running)
2072 enic_open(netdev);
2073
2074 return 0;
2075}
2076
2077#ifdef CONFIG_NET_POLL_CONTROLLER
2078static void enic_poll_controller(struct net_device *netdev)
2079{
2080 struct enic *enic = netdev_priv(netdev);
2081 struct vnic_dev *vdev = enic->vdev;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002082 unsigned int i, intr;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002083
2084 switch (vnic_dev_get_intr_mode(vdev)) {
2085 case VNIC_DEV_INTR_MODE_MSIX:
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002086 for (i = 0; i < enic->rq_count; i++) {
2087 intr = enic_msix_rq_intr(enic, i);
2088 enic_isr_msix_rq(enic->msix_entry[intr].vector, enic);
2089 }
2090 intr = enic_msix_wq_intr(enic, i);
2091 enic_isr_msix_wq(enic->msix_entry[intr].vector, enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002092 break;
2093 case VNIC_DEV_INTR_MODE_MSI:
2094 enic_isr_msi(enic->pdev->irq, enic);
2095 break;
2096 case VNIC_DEV_INTR_MODE_INTX:
2097 enic_isr_legacy(enic->pdev->irq, netdev);
2098 break;
2099 default:
2100 break;
2101 }
2102}
2103#endif
2104
2105static int enic_dev_wait(struct vnic_dev *vdev,
2106 int (*start)(struct vnic_dev *, int),
2107 int (*finished)(struct vnic_dev *, int *),
2108 int arg)
2109{
2110 unsigned long time;
2111 int done;
2112 int err;
2113
2114 BUG_ON(in_interrupt());
2115
2116 err = start(vdev, arg);
2117 if (err)
2118 return err;
2119
2120 /* Wait for func to complete...2 seconds max
2121 */
2122
2123 time = jiffies + (HZ * 2);
2124 do {
2125
2126 err = finished(vdev, &done);
2127 if (err)
2128 return err;
2129
2130 if (done)
2131 return 0;
2132
2133 schedule_timeout_uninterruptible(HZ / 10);
2134
2135 } while (time_after(time, jiffies));
2136
2137 return -ETIMEDOUT;
2138}
2139
2140static int enic_dev_open(struct enic *enic)
2141{
2142 int err;
2143
2144 err = enic_dev_wait(enic->vdev, vnic_dev_open,
2145 vnic_dev_open_done, 0);
2146 if (err)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002147 dev_err(enic_get_dev(enic), "vNIC device open failed, err %d\n",
2148 err);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002149
2150 return err;
2151}
2152
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +00002153static int enic_dev_hang_reset(struct enic *enic)
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002154{
2155 int err;
2156
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +00002157 err = enic_dev_wait(enic->vdev, vnic_dev_hang_reset,
2158 vnic_dev_hang_reset_done, 0);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002159 if (err)
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002160 netdev_err(enic->netdev, "vNIC hang reset failed, err %d\n",
2161 err);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002162
2163 return err;
2164}
2165
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002166static int enic_set_rsskey(struct enic *enic)
Scott Feldman68f71702009-02-09 23:24:24 -08002167{
Vasanthy Kolluri1f4f0672010-11-15 08:09:55 +00002168 dma_addr_t rss_key_buf_pa;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002169 union vnic_rss_key *rss_key_buf_va = NULL;
2170 union vnic_rss_key rss_key = {
2171 .key[0].b = {85, 67, 83, 97, 119, 101, 115, 111, 109, 101},
2172 .key[1].b = {80, 65, 76, 79, 117, 110, 105, 113, 117, 101},
2173 .key[2].b = {76, 73, 78, 85, 88, 114, 111, 99, 107, 115},
2174 .key[3].b = {69, 78, 73, 67, 105, 115, 99, 111, 111, 108},
2175 };
2176 int err;
2177
2178 rss_key_buf_va = pci_alloc_consistent(enic->pdev,
2179 sizeof(union vnic_rss_key), &rss_key_buf_pa);
2180 if (!rss_key_buf_va)
2181 return -ENOMEM;
2182
2183 memcpy(rss_key_buf_va, &rss_key, sizeof(union vnic_rss_key));
2184
2185 spin_lock(&enic->devcmd_lock);
2186 err = enic_set_rss_key(enic,
2187 rss_key_buf_pa,
2188 sizeof(union vnic_rss_key));
2189 spin_unlock(&enic->devcmd_lock);
2190
2191 pci_free_consistent(enic->pdev, sizeof(union vnic_rss_key),
2192 rss_key_buf_va, rss_key_buf_pa);
2193
2194 return err;
2195}
2196
2197static int enic_set_rsscpu(struct enic *enic, u8 rss_hash_bits)
2198{
Vasanthy Kolluri1f4f0672010-11-15 08:09:55 +00002199 dma_addr_t rss_cpu_buf_pa;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002200 union vnic_rss_cpu *rss_cpu_buf_va = NULL;
2201 unsigned int i;
2202 int err;
2203
2204 rss_cpu_buf_va = pci_alloc_consistent(enic->pdev,
2205 sizeof(union vnic_rss_cpu), &rss_cpu_buf_pa);
2206 if (!rss_cpu_buf_va)
2207 return -ENOMEM;
2208
2209 for (i = 0; i < (1 << rss_hash_bits); i++)
2210 (*rss_cpu_buf_va).cpu[i/4].b[i%4] = i % enic->rq_count;
2211
2212 spin_lock(&enic->devcmd_lock);
2213 err = enic_set_rss_cpu(enic,
2214 rss_cpu_buf_pa,
2215 sizeof(union vnic_rss_cpu));
2216 spin_unlock(&enic->devcmd_lock);
2217
2218 pci_free_consistent(enic->pdev, sizeof(union vnic_rss_cpu),
2219 rss_cpu_buf_va, rss_cpu_buf_pa);
2220
2221 return err;
2222}
2223
2224static int enic_set_niccfg(struct enic *enic, u8 rss_default_cpu,
2225 u8 rss_hash_type, u8 rss_hash_bits, u8 rss_base_cpu, u8 rss_enable)
2226{
Scott Feldman68f71702009-02-09 23:24:24 -08002227 const u8 tso_ipid_split_en = 0;
2228 const u8 ig_vlan_strip_en = 1;
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002229 int err;
Scott Feldman68f71702009-02-09 23:24:24 -08002230
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002231 /* Enable VLAN tag stripping.
2232 */
Scott Feldman68f71702009-02-09 23:24:24 -08002233
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002234 spin_lock(&enic->devcmd_lock);
2235 err = enic_set_nic_cfg(enic,
Scott Feldman68f71702009-02-09 23:24:24 -08002236 rss_default_cpu, rss_hash_type,
2237 rss_hash_bits, rss_base_cpu,
2238 rss_enable, tso_ipid_split_en,
2239 ig_vlan_strip_en);
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002240 spin_unlock(&enic->devcmd_lock);
2241
2242 return err;
2243}
2244
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002245static int enic_set_rss_nic_cfg(struct enic *enic)
2246{
2247 struct device *dev = enic_get_dev(enic);
2248 const u8 rss_default_cpu = 0;
2249 const u8 rss_hash_type = NIC_CFG_RSS_HASH_TYPE_IPV4 |
2250 NIC_CFG_RSS_HASH_TYPE_TCP_IPV4 |
2251 NIC_CFG_RSS_HASH_TYPE_IPV6 |
2252 NIC_CFG_RSS_HASH_TYPE_TCP_IPV6;
2253 const u8 rss_hash_bits = 7;
2254 const u8 rss_base_cpu = 0;
2255 u8 rss_enable = ENIC_SETTING(enic, RSS) && (enic->rq_count > 1);
2256
2257 if (rss_enable) {
2258 if (!enic_set_rsskey(enic)) {
2259 if (enic_set_rsscpu(enic, rss_hash_bits)) {
2260 rss_enable = 0;
2261 dev_warn(dev, "RSS disabled, "
2262 "Failed to set RSS cpu indirection table.");
2263 }
2264 } else {
2265 rss_enable = 0;
2266 dev_warn(dev, "RSS disabled, Failed to set RSS key.\n");
2267 }
2268 }
2269
2270 return enic_set_niccfg(enic, rss_default_cpu, rss_hash_type,
2271 rss_hash_bits, rss_base_cpu, rss_enable);
2272}
2273
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002274static int enic_dev_hang_notify(struct enic *enic)
2275{
2276 int err;
2277
2278 spin_lock(&enic->devcmd_lock);
2279 err = vnic_dev_hang_notify(enic->vdev);
2280 spin_unlock(&enic->devcmd_lock);
2281
2282 return err;
Scott Feldman68f71702009-02-09 23:24:24 -08002283}
2284
Vasanthy Kolluri2fdba382010-09-30 13:35:45 +00002285static int enic_dev_set_ig_vlan_rewrite_mode(struct enic *enic)
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00002286{
2287 int err;
2288
2289 spin_lock(&enic->devcmd_lock);
2290 err = vnic_dev_set_ig_vlan_rewrite_mode(enic->vdev,
2291 IG_VLAN_REWRITE_MODE_PRIORITY_TAG_DEFAULT_VLAN);
2292 spin_unlock(&enic->devcmd_lock);
2293
2294 return err;
2295}
2296
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002297static void enic_reset(struct work_struct *work)
2298{
2299 struct enic *enic = container_of(work, struct enic, reset);
2300
2301 if (!netif_running(enic->netdev))
2302 return;
2303
2304 rtnl_lock();
2305
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002306 enic_dev_hang_notify(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002307 enic_stop(enic->netdev);
Vasanthy Kolluri99ef5632010-06-24 10:50:00 +00002308 enic_dev_hang_reset(enic);
2309 enic_reset_multicast_list(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002310 enic_init_vnic_resources(enic);
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002311 enic_set_rss_nic_cfg(enic);
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00002312 enic_dev_set_ig_vlan_rewrite_mode(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002313 enic_open(enic->netdev);
2314
2315 rtnl_unlock();
2316}
2317
2318static int enic_set_intr_mode(struct enic *enic)
2319{
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002320 unsigned int n = min_t(unsigned int, enic->rq_count, ENIC_RQ_MAX);
Scott Feldman6ba9cdc2009-09-03 17:02:24 +00002321 unsigned int m = 1;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002322 unsigned int i;
2323
2324 /* Set interrupt mode (INTx, MSI, MSI-X) depending
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002325 * on system capabilities.
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002326 *
2327 * Try MSI-X first
2328 *
2329 * We need n RQs, m WQs, n+m CQs, and n+m+2 INTRs
2330 * (the second to last INTR is used for WQ/RQ errors)
2331 * (the last INTR is used for notifications)
2332 */
2333
2334 BUG_ON(ARRAY_SIZE(enic->msix_entry) < n + m + 2);
2335 for (i = 0; i < n + m + 2; i++)
2336 enic->msix_entry[i].entry = i;
2337
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002338 /* Use multiple RQs if RSS is enabled
2339 */
2340
2341 if (ENIC_SETTING(enic, RSS) &&
2342 enic->config.intr_mode < 1 &&
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002343 enic->rq_count >= n &&
2344 enic->wq_count >= m &&
2345 enic->cq_count >= n + m &&
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002346 enic->intr_count >= n + m + 2) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002347
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002348 if (!pci_enable_msix(enic->pdev, enic->msix_entry, n + m + 2)) {
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002349
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002350 enic->rq_count = n;
2351 enic->wq_count = m;
2352 enic->cq_count = n + m;
2353 enic->intr_count = n + m + 2;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002354
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002355 vnic_dev_set_intr_mode(enic->vdev,
2356 VNIC_DEV_INTR_MODE_MSIX);
2357
2358 return 0;
2359 }
2360 }
2361
2362 if (enic->config.intr_mode < 1 &&
2363 enic->rq_count >= 1 &&
2364 enic->wq_count >= m &&
2365 enic->cq_count >= 1 + m &&
2366 enic->intr_count >= 1 + m + 2) {
2367 if (!pci_enable_msix(enic->pdev, enic->msix_entry, 1 + m + 2)) {
2368
2369 enic->rq_count = 1;
2370 enic->wq_count = m;
2371 enic->cq_count = 1 + m;
2372 enic->intr_count = 1 + m + 2;
2373
2374 vnic_dev_set_intr_mode(enic->vdev,
2375 VNIC_DEV_INTR_MODE_MSIX);
2376
2377 return 0;
2378 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002379 }
2380
2381 /* Next try MSI
2382 *
2383 * We need 1 RQ, 1 WQ, 2 CQs, and 1 INTR
2384 */
2385
2386 if (enic->config.intr_mode < 2 &&
2387 enic->rq_count >= 1 &&
2388 enic->wq_count >= 1 &&
2389 enic->cq_count >= 2 &&
2390 enic->intr_count >= 1 &&
2391 !pci_enable_msi(enic->pdev)) {
2392
2393 enic->rq_count = 1;
2394 enic->wq_count = 1;
2395 enic->cq_count = 2;
2396 enic->intr_count = 1;
2397
2398 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_MSI);
2399
2400 return 0;
2401 }
2402
2403 /* Next try INTx
2404 *
2405 * We need 1 RQ, 1 WQ, 2 CQs, and 3 INTRs
2406 * (the first INTR is used for WQ/RQ)
2407 * (the second INTR is used for WQ/RQ errors)
2408 * (the last INTR is used for notifications)
2409 */
2410
2411 if (enic->config.intr_mode < 3 &&
2412 enic->rq_count >= 1 &&
2413 enic->wq_count >= 1 &&
2414 enic->cq_count >= 2 &&
2415 enic->intr_count >= 3) {
2416
2417 enic->rq_count = 1;
2418 enic->wq_count = 1;
2419 enic->cq_count = 2;
2420 enic->intr_count = 3;
2421
2422 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_INTX);
2423
2424 return 0;
2425 }
2426
2427 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2428
2429 return -EINVAL;
2430}
2431
2432static void enic_clear_intr_mode(struct enic *enic)
2433{
2434 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2435 case VNIC_DEV_INTR_MODE_MSIX:
2436 pci_disable_msix(enic->pdev);
2437 break;
2438 case VNIC_DEV_INTR_MODE_MSI:
2439 pci_disable_msi(enic->pdev);
2440 break;
2441 default:
2442 break;
2443 }
2444
2445 vnic_dev_set_intr_mode(enic->vdev, VNIC_DEV_INTR_MODE_UNKNOWN);
2446}
2447
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002448static const struct net_device_ops enic_netdev_dynamic_ops = {
2449 .ndo_open = enic_open,
2450 .ndo_stop = enic_stop,
2451 .ndo_start_xmit = enic_hard_start_xmit,
2452 .ndo_get_stats = enic_get_stats,
2453 .ndo_validate_addr = eth_validate_addr,
Roopa Prabhu319d7e82010-12-08 13:19:58 +00002454 .ndo_set_rx_mode = enic_set_rx_mode,
2455 .ndo_set_multicast_list = enic_set_rx_mode,
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002456 .ndo_set_mac_address = enic_set_mac_address_dynamic,
2457 .ndo_change_mtu = enic_change_mtu,
2458 .ndo_vlan_rx_register = enic_vlan_rx_register,
2459 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2460 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2461 .ndo_tx_timeout = enic_tx_timeout,
2462 .ndo_set_vf_port = enic_set_vf_port,
2463 .ndo_get_vf_port = enic_get_vf_port,
Roopa Prabhu0b1c00f2010-12-08 13:53:58 +00002464#ifdef IFLA_VF_MAX
2465 .ndo_set_vf_mac = enic_set_vf_mac,
2466#endif
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002467#ifdef CONFIG_NET_POLL_CONTROLLER
2468 .ndo_poll_controller = enic_poll_controller,
2469#endif
2470};
2471
Stephen Hemmingerafe29f72008-11-19 22:23:26 -08002472static const struct net_device_ops enic_netdev_ops = {
2473 .ndo_open = enic_open,
2474 .ndo_stop = enic_stop,
Stephen Hemminger00829822008-11-20 20:14:53 -08002475 .ndo_start_xmit = enic_hard_start_xmit,
Stephen Hemmingerafe29f72008-11-19 22:23:26 -08002476 .ndo_get_stats = enic_get_stats,
2477 .ndo_validate_addr = eth_validate_addr,
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002478 .ndo_set_mac_address = enic_set_mac_address,
Roopa Prabhu319d7e82010-12-08 13:19:58 +00002479 .ndo_set_rx_mode = enic_set_rx_mode,
2480 .ndo_set_multicast_list = enic_set_rx_mode,
Stephen Hemmingerafe29f72008-11-19 22:23:26 -08002481 .ndo_change_mtu = enic_change_mtu,
2482 .ndo_vlan_rx_register = enic_vlan_rx_register,
2483 .ndo_vlan_rx_add_vid = enic_vlan_rx_add_vid,
2484 .ndo_vlan_rx_kill_vid = enic_vlan_rx_kill_vid,
2485 .ndo_tx_timeout = enic_tx_timeout,
2486#ifdef CONFIG_NET_POLL_CONTROLLER
2487 .ndo_poll_controller = enic_poll_controller,
2488#endif
2489};
2490
Vasanthy Kolluri2fdba382010-09-30 13:35:45 +00002491static void enic_dev_deinit(struct enic *enic)
Scott Feldman6fdfa972009-09-03 17:02:45 +00002492{
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002493 unsigned int i;
2494
2495 for (i = 0; i < enic->rq_count; i++)
2496 netif_napi_del(&enic->napi[i]);
2497
Scott Feldman6fdfa972009-09-03 17:02:45 +00002498 enic_free_vnic_resources(enic);
2499 enic_clear_intr_mode(enic);
2500}
2501
Vasanthy Kolluri2fdba382010-09-30 13:35:45 +00002502static int enic_dev_init(struct enic *enic)
Scott Feldman6fdfa972009-09-03 17:02:45 +00002503{
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002504 struct device *dev = enic_get_dev(enic);
Scott Feldman6fdfa972009-09-03 17:02:45 +00002505 struct net_device *netdev = enic->netdev;
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002506 unsigned int i;
Scott Feldman6fdfa972009-09-03 17:02:45 +00002507 int err;
2508
2509 /* Get vNIC configuration
2510 */
2511
2512 err = enic_get_vnic_config(enic);
2513 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002514 dev_err(dev, "Get vNIC configuration failed, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002515 return err;
2516 }
2517
2518 /* Get available resource counts
2519 */
2520
2521 enic_get_res_counts(enic);
2522
2523 /* Set interrupt mode based on resource counts and system
2524 * capabilities
2525 */
2526
2527 err = enic_set_intr_mode(enic);
2528 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002529 dev_err(dev, "Failed to set intr mode based on resource "
2530 "counts and system capabilities, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002531 return err;
2532 }
2533
2534 /* Allocate and configure vNIC resources
2535 */
2536
2537 err = enic_alloc_vnic_resources(enic);
2538 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002539 dev_err(dev, "Failed to alloc vNIC resources, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002540 goto err_out_free_vnic_resources;
2541 }
2542
2543 enic_init_vnic_resources(enic);
2544
2545 err = enic_set_rq_alloc_buf(enic);
2546 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002547 dev_err(dev, "Failed to set RQ buffer allocator, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002548 goto err_out_free_vnic_resources;
2549 }
2550
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002551 err = enic_set_rss_nic_cfg(enic);
Scott Feldman6fdfa972009-09-03 17:02:45 +00002552 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002553 dev_err(dev, "Failed to config nic, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002554 goto err_out_free_vnic_resources;
2555 }
2556
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00002557 err = enic_dev_set_ig_vlan_rewrite_mode(enic);
2558 if (err) {
Vasanthy Kolluri53c90532010-10-20 10:17:19 +00002559 dev_err(dev,
Vasanthy Kollurif8cac142010-06-24 10:49:51 +00002560 "Failed to set ingress vlan rewrite mode, aborting.\n");
2561 goto err_out_free_vnic_resources;
2562 }
2563
Scott Feldman6fdfa972009-09-03 17:02:45 +00002564 switch (vnic_dev_get_intr_mode(enic->vdev)) {
2565 default:
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002566 netif_napi_add(netdev, &enic->napi[0], enic_poll, 64);
Scott Feldman6fdfa972009-09-03 17:02:45 +00002567 break;
2568 case VNIC_DEV_INTR_MODE_MSIX:
Vasanthy Kolluri717258b2010-10-20 10:16:59 +00002569 for (i = 0; i < enic->rq_count; i++)
2570 netif_napi_add(netdev, &enic->napi[i],
2571 enic_poll_msix, 64);
Scott Feldman6fdfa972009-09-03 17:02:45 +00002572 break;
2573 }
2574
2575 return 0;
2576
2577err_out_free_vnic_resources:
2578 enic_clear_intr_mode(enic);
2579 enic_free_vnic_resources(enic);
2580
2581 return err;
2582}
2583
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002584static void enic_iounmap(struct enic *enic)
2585{
2586 unsigned int i;
2587
2588 for (i = 0; i < ARRAY_SIZE(enic->bar); i++)
2589 if (enic->bar[i].vaddr)
2590 iounmap(enic->bar[i].vaddr);
2591}
2592
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002593static int __devinit enic_probe(struct pci_dev *pdev,
2594 const struct pci_device_id *ent)
2595{
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002596 struct device *dev = &pdev->dev;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002597 struct net_device *netdev;
2598 struct enic *enic;
2599 int using_dac = 0;
2600 unsigned int i;
2601 int err;
2602
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002603 /* Allocate net device structure and initialize. Private
2604 * instance data is initialized to zero.
2605 */
2606
2607 netdev = alloc_etherdev(sizeof(struct enic));
2608 if (!netdev) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002609 pr_err("Etherdev alloc failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002610 return -ENOMEM;
2611 }
2612
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002613 pci_set_drvdata(pdev, netdev);
2614
2615 SET_NETDEV_DEV(netdev, &pdev->dev);
2616
2617 enic = netdev_priv(netdev);
2618 enic->netdev = netdev;
2619 enic->pdev = pdev;
2620
2621 /* Setup PCI resources
2622 */
2623
Vasanthy Kolluri29046f92010-06-24 10:52:26 +00002624 err = pci_enable_device_mem(pdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002625 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002626 dev_err(dev, "Cannot enable PCI device, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002627 goto err_out_free_netdev;
2628 }
2629
2630 err = pci_request_regions(pdev, DRV_NAME);
2631 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002632 dev_err(dev, "Cannot request PCI regions, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002633 goto err_out_disable_device;
2634 }
2635
2636 pci_set_master(pdev);
2637
2638 /* Query PCI controller on system for DMA addressing
2639 * limitation for the device. Try 40-bit first, and
2640 * fail to 32-bit.
2641 */
2642
Yang Hongyang50cf1562009-04-06 19:01:14 -07002643 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(40));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002644 if (err) {
Yang Hongyang284901a2009-04-06 19:01:15 -07002645 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002646 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002647 dev_err(dev, "No usable DMA configuration, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002648 goto err_out_release_regions;
2649 }
Yang Hongyang284901a2009-04-06 19:01:15 -07002650 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002651 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002652 dev_err(dev, "Unable to obtain %u-bit DMA "
2653 "for consistent allocations, aborting\n", 32);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002654 goto err_out_release_regions;
2655 }
2656 } else {
Yang Hongyang50cf1562009-04-06 19:01:14 -07002657 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(40));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002658 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002659 dev_err(dev, "Unable to obtain %u-bit DMA "
2660 "for consistent allocations, aborting\n", 40);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002661 goto err_out_release_regions;
2662 }
2663 using_dac = 1;
2664 }
2665
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002666 /* Map vNIC resources from BAR0-5
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002667 */
2668
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002669 for (i = 0; i < ARRAY_SIZE(enic->bar); i++) {
2670 if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM))
2671 continue;
2672 enic->bar[i].len = pci_resource_len(pdev, i);
2673 enic->bar[i].vaddr = pci_iomap(pdev, i, enic->bar[i].len);
2674 if (!enic->bar[i].vaddr) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002675 dev_err(dev, "Cannot memory-map BAR %d, aborting\n", i);
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002676 err = -ENODEV;
2677 goto err_out_iounmap;
2678 }
2679 enic->bar[i].bus_addr = pci_resource_start(pdev, i);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002680 }
2681
2682 /* Register vNIC device
2683 */
2684
Scott Feldman27e6c7d2009-09-03 17:01:53 +00002685 enic->vdev = vnic_dev_register(NULL, enic, pdev, enic->bar,
2686 ARRAY_SIZE(enic->bar));
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002687 if (!enic->vdev) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002688 dev_err(dev, "vNIC registration failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002689 err = -ENODEV;
2690 goto err_out_iounmap;
2691 }
2692
2693 /* Issue device open to get device in known state
2694 */
2695
2696 err = enic_dev_open(enic);
2697 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002698 dev_err(dev, "vNIC dev open failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002699 goto err_out_vnic_unregister;
2700 }
2701
2702 /* Issue device init to initialize the vnic-to-switch link.
2703 * We'll start with carrier off and wait for link UP
2704 * notification later to turn on carrier. We don't need
2705 * to wait here for the vnic-to-switch link initialization
2706 * to complete; link UP notification is the indication that
2707 * the process is complete.
2708 */
2709
2710 netif_carrier_off(netdev);
2711
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002712 /* Do not call dev_init for a dynamic vnic.
2713 * For a dynamic vnic, init_prov_info will be
2714 * called later by an upper layer.
2715 */
2716
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002717 if (!enic_is_dynamic(enic)) {
2718 err = vnic_dev_init(enic->vdev, 0);
2719 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002720 dev_err(dev, "vNIC dev init failed, aborting\n");
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002721 goto err_out_dev_close;
2722 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002723 }
2724
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002725 /* Setup devcmd lock
2726 */
2727
2728 spin_lock_init(&enic->devcmd_lock);
2729
Scott Feldman6fdfa972009-09-03 17:02:45 +00002730 err = enic_dev_init(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002731 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002732 dev_err(dev, "Device initialization failed, aborting\n");
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002733 goto err_out_dev_close;
2734 }
2735
Vasanthy Kolluri383ab922010-06-24 10:50:12 +00002736 /* Setup notification timer, HW reset task, and wq locks
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002737 */
2738
2739 init_timer(&enic->notify_timer);
2740 enic->notify_timer.function = enic_notify_timer;
2741 enic->notify_timer.data = (unsigned long)enic;
2742
2743 INIT_WORK(&enic->reset, enic_reset);
2744
2745 for (i = 0; i < enic->wq_count; i++)
2746 spin_lock_init(&enic->wq_lock[i]);
2747
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002748 /* Register net device
2749 */
2750
2751 enic->port_mtu = enic->config.mtu;
2752 (void)enic_change_mtu(netdev, enic->port_mtu);
2753
2754 err = enic_set_mac_addr(netdev, enic->mac_addr);
2755 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002756 dev_err(dev, "Invalid MAC address, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002757 goto err_out_dev_deinit;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002758 }
2759
Scott Feldman7c844592009-12-23 13:27:54 +00002760 enic->tx_coalesce_usecs = enic->config.intr_timer_usec;
2761 enic->rx_coalesce_usecs = enic->tx_coalesce_usecs;
2762
Scott Feldmanf8bd9092010-05-17 22:50:19 -07002763 if (enic_is_dynamic(enic))
2764 netdev->netdev_ops = &enic_netdev_dynamic_ops;
2765 else
2766 netdev->netdev_ops = &enic_netdev_ops;
2767
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002768 netdev->watchdog_timeo = 2 * HZ;
2769 netdev->ethtool_ops = &enic_ethtool_ops;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002770
Vasanthy Kolluri73c1ea92010-03-18 16:19:54 +00002771 netdev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
Vasanthy Kolluri1825aca2010-06-24 10:51:59 +00002772 if (ENIC_SETTING(enic, LOOP)) {
2773 netdev->features &= ~NETIF_F_HW_VLAN_TX;
2774 enic->loop_enable = 1;
2775 enic->loop_tag = enic->config.loop_tag;
2776 dev_info(dev, "loopback tag=0x%04x\n", enic->loop_tag);
2777 }
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002778 if (ENIC_SETTING(enic, TXCSUM))
2779 netdev->features |= NETIF_F_SG | NETIF_F_HW_CSUM;
2780 if (ENIC_SETTING(enic, TSO))
2781 netdev->features |= NETIF_F_TSO |
2782 NETIF_F_TSO6 | NETIF_F_TSO_ECN;
Scott Feldman86ca9db2008-11-21 21:26:55 -08002783 if (ENIC_SETTING(enic, LRO))
Vasanthy Kolluri88132f52010-06-24 10:49:25 +00002784 netdev->features |= NETIF_F_GRO;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002785 if (using_dac)
2786 netdev->features |= NETIF_F_HIGHDMA;
2787
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002788 enic->csum_rx_enabled = ENIC_SETTING(enic, RXCSUM);
2789
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002790 err = register_netdev(netdev);
2791 if (err) {
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002792 dev_err(dev, "Cannot register net device, aborting\n");
Scott Feldman6fdfa972009-09-03 17:02:45 +00002793 goto err_out_dev_deinit;
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002794 }
2795
2796 return 0;
2797
Scott Feldman6fdfa972009-09-03 17:02:45 +00002798err_out_dev_deinit:
2799 enic_dev_deinit(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002800err_out_dev_close:
2801 vnic_dev_close(enic->vdev);
2802err_out_vnic_unregister:
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002803 vnic_dev_unregister(enic->vdev);
2804err_out_iounmap:
2805 enic_iounmap(enic);
2806err_out_release_regions:
2807 pci_release_regions(pdev);
2808err_out_disable_device:
2809 pci_disable_device(pdev);
2810err_out_free_netdev:
2811 pci_set_drvdata(pdev, NULL);
2812 free_netdev(netdev);
2813
2814 return err;
2815}
2816
2817static void __devexit enic_remove(struct pci_dev *pdev)
2818{
2819 struct net_device *netdev = pci_get_drvdata(pdev);
2820
2821 if (netdev) {
2822 struct enic *enic = netdev_priv(netdev);
2823
2824 flush_scheduled_work();
2825 unregister_netdev(netdev);
Scott Feldman6fdfa972009-09-03 17:02:45 +00002826 enic_dev_deinit(enic);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002827 vnic_dev_close(enic->vdev);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002828 vnic_dev_unregister(enic->vdev);
2829 enic_iounmap(enic);
2830 pci_release_regions(pdev);
2831 pci_disable_device(pdev);
2832 pci_set_drvdata(pdev, NULL);
2833 free_netdev(netdev);
2834 }
2835}
2836
2837static struct pci_driver enic_driver = {
2838 .name = DRV_NAME,
2839 .id_table = enic_id_table,
2840 .probe = enic_probe,
2841 .remove = __devexit_p(enic_remove),
2842};
2843
2844static int __init enic_init_module(void)
2845{
Vasanthy Kolluria7a79de2010-06-24 10:50:56 +00002846 pr_info("%s, ver %s\n", DRV_DESCRIPTION, DRV_VERSION);
Scott Feldman01f2e4e2008-09-15 09:17:11 -07002847
2848 return pci_register_driver(&enic_driver);
2849}
2850
2851static void __exit enic_cleanup_module(void)
2852{
2853 pci_unregister_driver(&enic_driver);
2854}
2855
2856module_init(enic_init_module);
2857module_exit(enic_cleanup_module);