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