Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
8ceee660 | 2 | /**************************************************************************** |
f7a6d2c4 | 3 | * Driver for Solarflare network controllers and boards |
8ceee660 | 4 | * Copyright 2005-2006 Fen Systems Ltd. |
f7a6d2c4 | 5 | * Copyright 2005-2013 Solarflare Communications Inc. |
8ceee660 BH |
6 | */ |
7 | ||
b6459415 | 8 | #include <linux/filter.h> |
8ceee660 BH |
9 | #include <linux/module.h> |
10 | #include <linux/pci.h> | |
11 | #include <linux/netdevice.h> | |
12 | #include <linux/etherdevice.h> | |
13 | #include <linux/delay.h> | |
14 | #include <linux/notifier.h> | |
15 | #include <linux/ip.h> | |
16 | #include <linux/tcp.h> | |
17 | #include <linux/in.h> | |
8ceee660 | 18 | #include <linux/ethtool.h> |
aa6ef27e | 19 | #include <linux/topology.h> |
5a0e3ad6 | 20 | #include <linux/gfp.h> |
b28405b0 | 21 | #include <linux/interrupt.h> |
8ceee660 | 22 | #include "net_driver.h" |
e5fbd977 JC |
23 | #include <net/gre.h> |
24 | #include <net/udp_tunnel.h> | |
8ceee660 | 25 | #include "efx.h" |
e1253f39 AM |
26 | #include "efx_common.h" |
27 | #include "efx_channels.h" | |
51b35a45 | 28 | #include "ef100.h" |
e1253f39 AM |
29 | #include "rx_common.h" |
30 | #include "tx_common.h" | |
744093c9 | 31 | #include "nic.h" |
71827443 | 32 | #include "io.h" |
dd40781e | 33 | #include "selftest.h" |
7fa8d547 | 34 | #include "sriov.h" |
8ceee660 | 35 | |
c77289b4 | 36 | #include "mcdi_port_common.h" |
e5fbd977 | 37 | #include "mcdi_pcol.h" |
fd371e32 | 38 | #include "workarounds.h" |
8880f4ec | 39 | |
8ceee660 BH |
40 | /************************************************************************** |
41 | * | |
42 | * Configurable values | |
43 | * | |
44 | *************************************************************************/ | |
45 | ||
e4ff3232 EC |
46 | module_param_named(interrupt_mode, efx_interrupt_mode, uint, 0444); |
47 | MODULE_PARM_DESC(interrupt_mode, | |
48 | "Interrupt mode (0=>MSIX 1=>MSI 2=>legacy)"); | |
49 | ||
67e6398e EC |
50 | module_param(rss_cpus, uint, 0444); |
51 | MODULE_PARM_DESC(rss_cpus, "Number of CPUs to use for Receive-Side Scaling"); | |
52 | ||
8ceee660 BH |
53 | /* |
54 | * Use separate channels for TX and RX events | |
55 | * | |
28b581ab NT |
56 | * Set this to 1 to use separate channels for TX and RX. It allows us |
57 | * to control interrupt affinity separately for TX and RX. | |
8ceee660 | 58 | * |
28b581ab | 59 | * This is only used in MSI-X interrupt mode |
8ceee660 | 60 | */ |
b0fbdae1 SS |
61 | bool efx_separate_tx_channels; |
62 | module_param(efx_separate_tx_channels, bool, 0444); | |
63 | MODULE_PARM_DESC(efx_separate_tx_channels, | |
28b581ab | 64 | "Use separate channels for TX and RX"); |
8ceee660 | 65 | |
8ceee660 BH |
66 | /* Initial interrupt moderation settings. They can be modified after |
67 | * module load with ethtool. | |
68 | * | |
69 | * The default for RX should strike a balance between increasing the | |
70 | * round-trip latency and reducing overhead. | |
71 | */ | |
72 | static unsigned int rx_irq_mod_usec = 60; | |
73 | ||
74 | /* Initial interrupt moderation settings. They can be modified after | |
75 | * module load with ethtool. | |
76 | * | |
77 | * This default is chosen to ensure that a 10G link does not go idle | |
78 | * while a TX queue is stopped after it has become full. A queue is | |
79 | * restarted when it drops below half full. The time this takes (assuming | |
80 | * worst case 3 descriptors per packet and 1024 descriptors) is | |
81 | * 512 / 3 * 1.2 = 205 usec. | |
82 | */ | |
83 | static unsigned int tx_irq_mod_usec = 150; | |
84 | ||
b9cc977d BH |
85 | static bool phy_flash_cfg; |
86 | module_param(phy_flash_cfg, bool, 0644); | |
84ae48fe BH |
87 | MODULE_PARM_DESC(phy_flash_cfg, "Set PHYs into reflash mode initially"); |
88 | ||
62776d03 BH |
89 | static unsigned debug = (NETIF_MSG_DRV | NETIF_MSG_PROBE | |
90 | NETIF_MSG_LINK | NETIF_MSG_IFDOWN | | |
91 | NETIF_MSG_IFUP | NETIF_MSG_RX_ERR | | |
92 | NETIF_MSG_TX_ERR | NETIF_MSG_HW); | |
93 | module_param(debug, uint, 0); | |
94 | MODULE_PARM_DESC(debug, "Bitmapped debugging message enable value"); | |
95 | ||
8ceee660 BH |
96 | /************************************************************************** |
97 | * | |
98 | * Utility functions and prototypes | |
99 | * | |
100 | *************************************************************************/ | |
4642610c | 101 | |
8ceee660 | 102 | static void efx_remove_port(struct efx_nic *efx); |
e45a4fed CM |
103 | static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog); |
104 | static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp); | |
dfe44c1f CM |
105 | static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs, |
106 | u32 flags); | |
8ceee660 | 107 | |
8ceee660 BH |
108 | /************************************************************************** |
109 | * | |
110 | * Port handling | |
111 | * | |
112 | **************************************************************************/ | |
113 | ||
115122af BH |
114 | static void efx_fini_port(struct efx_nic *efx); |
115 | ||
8ceee660 BH |
116 | static int efx_probe_port(struct efx_nic *efx) |
117 | { | |
118 | int rc; | |
119 | ||
62776d03 | 120 | netif_dbg(efx, probe, efx->net_dev, "create port\n"); |
8ceee660 | 121 | |
ff3b00a0 SH |
122 | if (phy_flash_cfg) |
123 | efx->phy_mode = PHY_MODE_SPECIAL; | |
124 | ||
ef2b90ee BH |
125 | /* Connect up MAC/PHY operations table */ |
126 | rc = efx->type->probe_port(efx); | |
8ceee660 | 127 | if (rc) |
e42de262 | 128 | return rc; |
8ceee660 | 129 | |
e332bcb3 | 130 | /* Initialise MAC address to permanent address */ |
f3956ebb | 131 | eth_hw_addr_set(efx->net_dev, efx->net_dev->perm_addr); |
8ceee660 BH |
132 | |
133 | return 0; | |
8ceee660 BH |
134 | } |
135 | ||
136 | static int efx_init_port(struct efx_nic *efx) | |
137 | { | |
138 | int rc; | |
139 | ||
62776d03 | 140 | netif_dbg(efx, drv, efx->net_dev, "init port\n"); |
8ceee660 | 141 | |
1dfc5cea BH |
142 | mutex_lock(&efx->mac_lock); |
143 | ||
dc8cfa55 | 144 | efx->port_initialized = true; |
1dfc5cea | 145 | |
d3245b28 | 146 | /* Ensure the PHY advertises the correct flow control settings */ |
c77289b4 | 147 | rc = efx_mcdi_port_reconfigure(efx); |
267d9d73 | 148 | if (rc && rc != -EPERM) |
c77289b4 | 149 | goto fail; |
d3245b28 | 150 | |
1dfc5cea | 151 | mutex_unlock(&efx->mac_lock); |
8ceee660 | 152 | return 0; |
177dfcd8 | 153 | |
c77289b4 | 154 | fail: |
1dfc5cea | 155 | mutex_unlock(&efx->mac_lock); |
177dfcd8 | 156 | return rc; |
8ceee660 BH |
157 | } |
158 | ||
8ceee660 BH |
159 | static void efx_fini_port(struct efx_nic *efx) |
160 | { | |
62776d03 | 161 | netif_dbg(efx, drv, efx->net_dev, "shut down port\n"); |
8ceee660 BH |
162 | |
163 | if (!efx->port_initialized) | |
164 | return; | |
165 | ||
dc8cfa55 | 166 | efx->port_initialized = false; |
8ceee660 | 167 | |
eb50c0d6 | 168 | efx->link_state.up = false; |
8ceee660 BH |
169 | efx_link_status_changed(efx); |
170 | } | |
171 | ||
172 | static void efx_remove_port(struct efx_nic *efx) | |
173 | { | |
62776d03 | 174 | netif_dbg(efx, drv, efx->net_dev, "destroying port\n"); |
8ceee660 | 175 | |
ef2b90ee | 176 | efx->type->remove_port(efx); |
8ceee660 BH |
177 | } |
178 | ||
179 | /************************************************************************** | |
180 | * | |
181 | * NIC handling | |
182 | * | |
183 | **************************************************************************/ | |
184 | ||
0bcf4a64 BH |
185 | static LIST_HEAD(efx_primary_list); |
186 | static LIST_HEAD(efx_unassociated_list); | |
187 | ||
188 | static bool efx_same_controller(struct efx_nic *left, struct efx_nic *right) | |
189 | { | |
190 | return left->type == right->type && | |
191 | left->vpd_sn && right->vpd_sn && | |
192 | !strcmp(left->vpd_sn, right->vpd_sn); | |
193 | } | |
194 | ||
195 | static void efx_associate(struct efx_nic *efx) | |
196 | { | |
197 | struct efx_nic *other, *next; | |
198 | ||
199 | if (efx->primary == efx) { | |
200 | /* Adding primary function; look for secondaries */ | |
201 | ||
202 | netif_dbg(efx, probe, efx->net_dev, "adding to primary list\n"); | |
203 | list_add_tail(&efx->node, &efx_primary_list); | |
204 | ||
205 | list_for_each_entry_safe(other, next, &efx_unassociated_list, | |
206 | node) { | |
207 | if (efx_same_controller(efx, other)) { | |
208 | list_del(&other->node); | |
209 | netif_dbg(other, probe, other->net_dev, | |
210 | "moving to secondary list of %s %s\n", | |
211 | pci_name(efx->pci_dev), | |
212 | efx->net_dev->name); | |
213 | list_add_tail(&other->node, | |
214 | &efx->secondary_list); | |
215 | other->primary = efx; | |
216 | } | |
217 | } | |
218 | } else { | |
219 | /* Adding secondary function; look for primary */ | |
220 | ||
221 | list_for_each_entry(other, &efx_primary_list, node) { | |
222 | if (efx_same_controller(efx, other)) { | |
223 | netif_dbg(efx, probe, efx->net_dev, | |
224 | "adding to secondary list of %s %s\n", | |
225 | pci_name(other->pci_dev), | |
226 | other->net_dev->name); | |
227 | list_add_tail(&efx->node, | |
228 | &other->secondary_list); | |
229 | efx->primary = other; | |
230 | return; | |
231 | } | |
232 | } | |
233 | ||
234 | netif_dbg(efx, probe, efx->net_dev, | |
235 | "adding to unassociated list\n"); | |
236 | list_add_tail(&efx->node, &efx_unassociated_list); | |
237 | } | |
238 | } | |
239 | ||
240 | static void efx_dissociate(struct efx_nic *efx) | |
241 | { | |
242 | struct efx_nic *other, *next; | |
243 | ||
244 | list_del(&efx->node); | |
245 | efx->primary = NULL; | |
246 | ||
247 | list_for_each_entry_safe(other, next, &efx->secondary_list, node) { | |
248 | list_del(&other->node); | |
249 | netif_dbg(other, probe, other->net_dev, | |
250 | "moving to unassociated list\n"); | |
251 | list_add_tail(&other->node, &efx_unassociated_list); | |
252 | other->primary = NULL; | |
253 | } | |
254 | } | |
255 | ||
8ceee660 BH |
256 | static int efx_probe_nic(struct efx_nic *efx) |
257 | { | |
258 | int rc; | |
259 | ||
62776d03 | 260 | netif_dbg(efx, probe, efx->net_dev, "creating NIC\n"); |
8ceee660 BH |
261 | |
262 | /* Carry out hardware-type specific initialisation */ | |
ef2b90ee | 263 | rc = efx->type->probe(efx); |
8ceee660 BH |
264 | if (rc) |
265 | return rc; | |
266 | ||
b0fbdae1 SS |
267 | do { |
268 | if (!efx->max_channels || !efx->max_tx_channels) { | |
269 | netif_err(efx, drv, efx->net_dev, | |
270 | "Insufficient resources to allocate" | |
271 | " any channels\n"); | |
272 | rc = -ENOSPC; | |
273 | goto fail1; | |
274 | } | |
8ceee660 | 275 | |
b0fbdae1 SS |
276 | /* Determine the number of channels and queues by trying |
277 | * to hook in MSI-X interrupts. | |
278 | */ | |
279 | rc = efx_probe_interrupts(efx); | |
280 | if (rc) | |
281 | goto fail1; | |
52ad762b | 282 | |
3990a8ff CM |
283 | rc = efx_set_channels(efx); |
284 | if (rc) | |
285 | goto fail1; | |
b0fbdae1 SS |
286 | |
287 | /* dimension_resources can fail with EAGAIN */ | |
288 | rc = efx->type->dimension_resources(efx); | |
289 | if (rc != 0 && rc != -EAGAIN) | |
290 | goto fail2; | |
291 | ||
292 | if (rc == -EAGAIN) | |
293 | /* try again with new max_channels */ | |
294 | efx_remove_interrupts(efx); | |
295 | ||
296 | } while (rc == -EAGAIN); | |
28e47c49 | 297 | |
5d3a6fca | 298 | if (efx->n_channels > 1) |
42356d9a EC |
299 | netdev_rss_key_fill(efx->rss_context.rx_hash_key, |
300 | sizeof(efx->rss_context.rx_hash_key)); | |
301 | efx_set_default_rx_indir_table(efx, &efx->rss_context); | |
5d3a6fca | 302 | |
8ceee660 | 303 | /* Initialise the interrupt moderation settings */ |
539de7c5 | 304 | efx->irq_mod_step_us = DIV_ROUND_UP(efx->timer_quantum_ns, 1000); |
9e393b30 BH |
305 | efx_init_irq_moderation(efx, tx_irq_mod_usec, rx_irq_mod_usec, true, |
306 | true); | |
8ceee660 BH |
307 | |
308 | return 0; | |
64d8ad6d | 309 | |
c15eed22 BH |
310 | fail2: |
311 | efx_remove_interrupts(efx); | |
312 | fail1: | |
64d8ad6d BH |
313 | efx->type->remove(efx); |
314 | return rc; | |
8ceee660 BH |
315 | } |
316 | ||
317 | static void efx_remove_nic(struct efx_nic *efx) | |
318 | { | |
62776d03 | 319 | netif_dbg(efx, drv, efx->net_dev, "destroying NIC\n"); |
8ceee660 BH |
320 | |
321 | efx_remove_interrupts(efx); | |
ef2b90ee | 322 | efx->type->remove(efx); |
8ceee660 BH |
323 | } |
324 | ||
325 | /************************************************************************** | |
326 | * | |
327 | * NIC startup/shutdown | |
328 | * | |
329 | *************************************************************************/ | |
330 | ||
331 | static int efx_probe_all(struct efx_nic *efx) | |
332 | { | |
8ceee660 BH |
333 | int rc; |
334 | ||
8ceee660 BH |
335 | rc = efx_probe_nic(efx); |
336 | if (rc) { | |
62776d03 | 337 | netif_err(efx, probe, efx->net_dev, "failed to create NIC\n"); |
8ceee660 BH |
338 | goto fail1; |
339 | } | |
340 | ||
8ceee660 BH |
341 | rc = efx_probe_port(efx); |
342 | if (rc) { | |
62776d03 | 343 | netif_err(efx, probe, efx->net_dev, "failed to create port\n"); |
8ceee660 BH |
344 | goto fail2; |
345 | } | |
346 | ||
7e6d06f0 BH |
347 | BUILD_BUG_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_RXQ_MIN_ENT); |
348 | if (WARN_ON(EFX_DEFAULT_DMAQ_SIZE < EFX_TXQ_MIN_ENT(efx))) { | |
349 | rc = -EINVAL; | |
350 | goto fail3; | |
351 | } | |
8ceee660 | 352 | |
6d8aaaf6 DP |
353 | #ifdef CONFIG_SFC_SRIOV |
354 | rc = efx->type->vswitching_probe(efx); | |
355 | if (rc) /* not fatal; the PF will still work fine */ | |
356 | netif_warn(efx, probe, efx->net_dev, | |
357 | "failed to setup vswitching rc=%d;" | |
358 | " VFs may not function\n", rc); | |
359 | #endif | |
360 | ||
64eebcfd BH |
361 | rc = efx_probe_filters(efx); |
362 | if (rc) { | |
363 | netif_err(efx, probe, efx->net_dev, | |
364 | "failed to create filter tables\n"); | |
6d8aaaf6 | 365 | goto fail4; |
64eebcfd BH |
366 | } |
367 | ||
7f967c01 BH |
368 | rc = efx_probe_channels(efx); |
369 | if (rc) | |
6d8aaaf6 | 370 | goto fail5; |
7f967c01 | 371 | |
813cf9d1 JC |
372 | efx->state = STATE_NET_DOWN; |
373 | ||
8ceee660 BH |
374 | return 0; |
375 | ||
6d8aaaf6 | 376 | fail5: |
7f967c01 | 377 | efx_remove_filters(efx); |
6d8aaaf6 DP |
378 | fail4: |
379 | #ifdef CONFIG_SFC_SRIOV | |
380 | efx->type->vswitching_remove(efx); | |
381 | #endif | |
8ceee660 | 382 | fail3: |
8ceee660 BH |
383 | efx_remove_port(efx); |
384 | fail2: | |
385 | efx_remove_nic(efx); | |
386 | fail1: | |
387 | return rc; | |
388 | } | |
389 | ||
8ceee660 BH |
390 | static void efx_remove_all(struct efx_nic *efx) |
391 | { | |
e45a4fed CM |
392 | rtnl_lock(); |
393 | efx_xdp_setup_prog(efx, NULL); | |
394 | rtnl_unlock(); | |
395 | ||
4642610c | 396 | efx_remove_channels(efx); |
7f967c01 | 397 | efx_remove_filters(efx); |
6d8aaaf6 DP |
398 | #ifdef CONFIG_SFC_SRIOV |
399 | efx->type->vswitching_remove(efx); | |
400 | #endif | |
8ceee660 BH |
401 | efx_remove_port(efx); |
402 | efx_remove_nic(efx); | |
403 | } | |
404 | ||
8ceee660 BH |
405 | /************************************************************************** |
406 | * | |
407 | * Interrupt moderation | |
408 | * | |
409 | **************************************************************************/ | |
539de7c5 | 410 | unsigned int efx_usecs_to_ticks(struct efx_nic *efx, unsigned int usecs) |
0d86ebd8 | 411 | { |
b548f976 BH |
412 | if (usecs == 0) |
413 | return 0; | |
539de7c5 | 414 | if (usecs * 1000 < efx->timer_quantum_ns) |
0d86ebd8 | 415 | return 1; /* never round down to 0 */ |
539de7c5 BK |
416 | return usecs * 1000 / efx->timer_quantum_ns; |
417 | } | |
418 | ||
419 | unsigned int efx_ticks_to_usecs(struct efx_nic *efx, unsigned int ticks) | |
420 | { | |
421 | /* We must round up when converting ticks to microseconds | |
422 | * because we round down when converting the other way. | |
423 | */ | |
424 | return DIV_ROUND_UP(ticks * efx->timer_quantum_ns, 1000); | |
0d86ebd8 BH |
425 | } |
426 | ||
8ceee660 | 427 | /* Set interrupt moderation parameters */ |
9e393b30 BH |
428 | int efx_init_irq_moderation(struct efx_nic *efx, unsigned int tx_usecs, |
429 | unsigned int rx_usecs, bool rx_adaptive, | |
430 | bool rx_may_override_tx) | |
8ceee660 | 431 | { |
f7d12cdc | 432 | struct efx_channel *channel; |
d95e329a BK |
433 | unsigned int timer_max_us; |
434 | ||
8ceee660 BH |
435 | EFX_ASSERT_RESET_SERIALISED(efx); |
436 | ||
d95e329a BK |
437 | timer_max_us = efx->timer_max_ns / 1000; |
438 | ||
439 | if (tx_usecs > timer_max_us || rx_usecs > timer_max_us) | |
9e393b30 BH |
440 | return -EINVAL; |
441 | ||
539de7c5 | 442 | if (tx_usecs != rx_usecs && efx->tx_channel_offset == 0 && |
9e393b30 BH |
443 | !rx_may_override_tx) { |
444 | netif_err(efx, drv, efx->net_dev, "Channels are shared. " | |
445 | "RX and TX IRQ moderation must be equal\n"); | |
446 | return -EINVAL; | |
447 | } | |
448 | ||
6fb70fd1 | 449 | efx->irq_rx_adaptive = rx_adaptive; |
539de7c5 | 450 | efx->irq_rx_moderation_us = rx_usecs; |
f7d12cdc | 451 | efx_for_each_channel(channel, efx) { |
525da907 | 452 | if (efx_channel_has_rx_queue(channel)) |
539de7c5 | 453 | channel->irq_moderation_us = rx_usecs; |
525da907 | 454 | else if (efx_channel_has_tx_queues(channel)) |
539de7c5 | 455 | channel->irq_moderation_us = tx_usecs; |
3990a8ff CM |
456 | else if (efx_channel_is_xdp_tx(channel)) |
457 | channel->irq_moderation_us = tx_usecs; | |
f7d12cdc | 458 | } |
9e393b30 BH |
459 | |
460 | return 0; | |
8ceee660 BH |
461 | } |
462 | ||
a0c4faf5 BH |
463 | void efx_get_irq_moderation(struct efx_nic *efx, unsigned int *tx_usecs, |
464 | unsigned int *rx_usecs, bool *rx_adaptive) | |
465 | { | |
466 | *rx_adaptive = efx->irq_rx_adaptive; | |
539de7c5 | 467 | *rx_usecs = efx->irq_rx_moderation_us; |
a0c4faf5 BH |
468 | |
469 | /* If channels are shared between RX and TX, so is IRQ | |
470 | * moderation. Otherwise, IRQ moderation is the same for all | |
471 | * TX channels and is not adaptive. | |
472 | */ | |
539de7c5 | 473 | if (efx->tx_channel_offset == 0) { |
a0c4faf5 | 474 | *tx_usecs = *rx_usecs; |
539de7c5 BK |
475 | } else { |
476 | struct efx_channel *tx_channel; | |
477 | ||
478 | tx_channel = efx->channel[efx->tx_channel_offset]; | |
479 | *tx_usecs = tx_channel->irq_moderation_us; | |
480 | } | |
a0c4faf5 BH |
481 | } |
482 | ||
8ceee660 BH |
483 | /************************************************************************** |
484 | * | |
485 | * ioctls | |
486 | * | |
487 | *************************************************************************/ | |
488 | ||
489 | /* Net device ioctl | |
490 | * Context: process, rtnl_lock() held. | |
491 | */ | |
492 | static int efx_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd) | |
493 | { | |
8cb03f4e | 494 | struct efx_nic *efx = efx_netdev_priv(net_dev); |
68e7f45e | 495 | struct mii_ioctl_data *data = if_mii(ifr); |
8ceee660 | 496 | |
7c236c43 | 497 | if (cmd == SIOCSHWTSTAMP) |
433dc9b3 BH |
498 | return efx_ptp_set_ts_config(efx, ifr); |
499 | if (cmd == SIOCGHWTSTAMP) | |
500 | return efx_ptp_get_ts_config(efx, ifr); | |
7c236c43 | 501 | |
68e7f45e BH |
502 | /* Convert phy_id from older PRTAD/DEVAD format */ |
503 | if ((cmd == SIOCGMIIREG || cmd == SIOCSMIIREG) && | |
504 | (data->phy_id & 0xfc00) == 0x0400) | |
505 | data->phy_id ^= MDIO_PHY_ID_C45 | 0x0400; | |
506 | ||
507 | return mdio_mii_ioctl(&efx->mdio, data, cmd); | |
8ceee660 BH |
508 | } |
509 | ||
8ceee660 BH |
510 | /************************************************************************** |
511 | * | |
512 | * Kernel net device interface | |
513 | * | |
514 | *************************************************************************/ | |
515 | ||
516 | /* Context: process, rtnl_lock() held. */ | |
e340be92 | 517 | int efx_net_open(struct net_device *net_dev) |
8ceee660 | 518 | { |
8cb03f4e | 519 | struct efx_nic *efx = efx_netdev_priv(net_dev); |
8b7325b4 BH |
520 | int rc; |
521 | ||
62776d03 BH |
522 | netif_dbg(efx, ifup, efx->net_dev, "opening device on CPU %d\n", |
523 | raw_smp_processor_id()); | |
8ceee660 | 524 | |
8b7325b4 BH |
525 | rc = efx_check_disabled(efx); |
526 | if (rc) | |
527 | return rc; | |
f8b87c17 BH |
528 | if (efx->phy_mode & PHY_MODE_SPECIAL) |
529 | return -EBUSY; | |
8880f4ec BH |
530 | if (efx_mcdi_poll_reboot(efx) && efx_reset(efx, RESET_TYPE_ALL)) |
531 | return -EIO; | |
f8b87c17 | 532 | |
78c1f0a0 SH |
533 | /* Notify the kernel of the link state polled during driver load, |
534 | * before the monitor starts running */ | |
535 | efx_link_status_changed(efx); | |
536 | ||
8ceee660 | 537 | efx_start_all(efx); |
9c568fd8 PD |
538 | if (efx->state == STATE_DISABLED || efx->reset_pending) |
539 | netif_device_detach(efx->net_dev); | |
813cf9d1 JC |
540 | else |
541 | efx->state = STATE_NET_UP; | |
542 | ||
8ceee660 BH |
543 | return 0; |
544 | } | |
545 | ||
546 | /* Context: process, rtnl_lock() held. | |
547 | * Note that the kernel will ignore our return code; this method | |
548 | * should really be a void. | |
549 | */ | |
e340be92 | 550 | int efx_net_stop(struct net_device *net_dev) |
8ceee660 | 551 | { |
8cb03f4e | 552 | struct efx_nic *efx = efx_netdev_priv(net_dev); |
8ceee660 | 553 | |
62776d03 BH |
554 | netif_dbg(efx, ifdown, efx->net_dev, "closing on CPU %d\n", |
555 | raw_smp_processor_id()); | |
8ceee660 | 556 | |
8b7325b4 BH |
557 | /* Stop the device and flush all the channels */ |
558 | efx_stop_all(efx); | |
8ceee660 BH |
559 | |
560 | return 0; | |
561 | } | |
562 | ||
4a53ea8a AR |
563 | static int efx_vlan_rx_add_vid(struct net_device *net_dev, __be16 proto, u16 vid) |
564 | { | |
8cb03f4e | 565 | struct efx_nic *efx = efx_netdev_priv(net_dev); |
4a53ea8a AR |
566 | |
567 | if (efx->type->vlan_rx_add_vid) | |
568 | return efx->type->vlan_rx_add_vid(efx, proto, vid); | |
569 | else | |
570 | return -EOPNOTSUPP; | |
571 | } | |
572 | ||
573 | static int efx_vlan_rx_kill_vid(struct net_device *net_dev, __be16 proto, u16 vid) | |
574 | { | |
8cb03f4e | 575 | struct efx_nic *efx = efx_netdev_priv(net_dev); |
4a53ea8a AR |
576 | |
577 | if (efx->type->vlan_rx_kill_vid) | |
578 | return efx->type->vlan_rx_kill_vid(efx, proto, vid); | |
579 | else | |
580 | return -EOPNOTSUPP; | |
581 | } | |
582 | ||
7fa8d547 | 583 | static const struct net_device_ops efx_netdev_ops = { |
c3ecb9f3 SH |
584 | .ndo_open = efx_net_open, |
585 | .ndo_stop = efx_net_stop, | |
4472702e | 586 | .ndo_get_stats64 = efx_net_stats, |
c3ecb9f3 SH |
587 | .ndo_tx_timeout = efx_watchdog, |
588 | .ndo_start_xmit = efx_hard_start_xmit, | |
589 | .ndo_validate_addr = eth_validate_addr, | |
a7605370 | 590 | .ndo_eth_ioctl = efx_ioctl, |
c3ecb9f3 SH |
591 | .ndo_change_mtu = efx_change_mtu, |
592 | .ndo_set_mac_address = efx_set_mac_address, | |
0fca8c97 | 593 | .ndo_set_rx_mode = efx_set_rx_mode, |
abfe9039 | 594 | .ndo_set_features = efx_set_features, |
24b2c375 | 595 | .ndo_features_check = efx_features_check, |
4a53ea8a AR |
596 | .ndo_vlan_rx_add_vid = efx_vlan_rx_add_vid, |
597 | .ndo_vlan_rx_kill_vid = efx_vlan_rx_kill_vid, | |
cd2d5b52 | 598 | #ifdef CONFIG_SFC_SRIOV |
7fa8d547 SS |
599 | .ndo_set_vf_mac = efx_sriov_set_vf_mac, |
600 | .ndo_set_vf_vlan = efx_sriov_set_vf_vlan, | |
601 | .ndo_set_vf_spoofchk = efx_sriov_set_vf_spoofchk, | |
602 | .ndo_get_vf_config = efx_sriov_get_vf_config, | |
4392dc69 | 603 | .ndo_set_vf_link_state = efx_sriov_set_vf_link_state, |
cd2d5b52 | 604 | #endif |
08a7b29b | 605 | .ndo_get_phys_port_id = efx_get_phys_port_id, |
ac019f08 | 606 | .ndo_get_phys_port_name = efx_get_phys_port_name, |
94b274bf | 607 | .ndo_setup_tc = efx_setup_tc, |
64d8ad6d BH |
608 | #ifdef CONFIG_RFS_ACCEL |
609 | .ndo_rx_flow_steer = efx_filter_rfs, | |
610 | #endif | |
dfe44c1f | 611 | .ndo_xdp_xmit = efx_xdp_xmit, |
e45a4fed | 612 | .ndo_bpf = efx_xdp |
c3ecb9f3 SH |
613 | }; |
614 | ||
e45a4fed CM |
615 | static int efx_xdp_setup_prog(struct efx_nic *efx, struct bpf_prog *prog) |
616 | { | |
617 | struct bpf_prog *old_prog; | |
618 | ||
619 | if (efx->xdp_rxq_info_failed) { | |
620 | netif_err(efx, drv, efx->net_dev, | |
621 | "Unable to bind XDP program due to previous failure of rxq_info\n"); | |
622 | return -EINVAL; | |
623 | } | |
624 | ||
625 | if (prog && efx->net_dev->mtu > efx_xdp_max_mtu(efx)) { | |
626 | netif_err(efx, drv, efx->net_dev, | |
627 | "Unable to configure XDP with MTU of %d (max: %d)\n", | |
628 | efx->net_dev->mtu, efx_xdp_max_mtu(efx)); | |
629 | return -EINVAL; | |
630 | } | |
631 | ||
632 | old_prog = rtnl_dereference(efx->xdp_prog); | |
633 | rcu_assign_pointer(efx->xdp_prog, prog); | |
634 | /* Release the reference that was originally passed by the caller. */ | |
635 | if (old_prog) | |
636 | bpf_prog_put(old_prog); | |
637 | ||
638 | return 0; | |
639 | } | |
640 | ||
641 | /* Context: process, rtnl_lock() held. */ | |
642 | static int efx_xdp(struct net_device *dev, struct netdev_bpf *xdp) | |
643 | { | |
8cb03f4e | 644 | struct efx_nic *efx = efx_netdev_priv(dev); |
e45a4fed CM |
645 | |
646 | switch (xdp->command) { | |
647 | case XDP_SETUP_PROG: | |
648 | return efx_xdp_setup_prog(efx, xdp->prog); | |
e45a4fed CM |
649 | default: |
650 | return -EINVAL; | |
651 | } | |
652 | } | |
653 | ||
dfe44c1f CM |
654 | static int efx_xdp_xmit(struct net_device *dev, int n, struct xdp_frame **xdpfs, |
655 | u32 flags) | |
656 | { | |
8cb03f4e | 657 | struct efx_nic *efx = efx_netdev_priv(dev); |
dfe44c1f CM |
658 | |
659 | if (!netif_running(dev)) | |
660 | return -EINVAL; | |
661 | ||
662 | return efx_xdp_tx_buffers(efx, n, xdpfs, flags & XDP_XMIT_FLUSH); | |
663 | } | |
664 | ||
7dde596e BH |
665 | static void efx_update_name(struct efx_nic *efx) |
666 | { | |
667 | strcpy(efx->name, efx->net_dev->name); | |
668 | efx_mtd_rename(efx); | |
669 | efx_set_channel_names(efx); | |
670 | } | |
671 | ||
8ceee660 BH |
672 | static int efx_netdev_event(struct notifier_block *this, |
673 | unsigned long event, void *ptr) | |
674 | { | |
351638e7 | 675 | struct net_device *net_dev = netdev_notifier_info_to_dev(ptr); |
8ceee660 | 676 | |
7fa8d547 | 677 | if ((net_dev->netdev_ops == &efx_netdev_ops) && |
7dde596e | 678 | event == NETDEV_CHANGENAME) |
8cb03f4e | 679 | efx_update_name(efx_netdev_priv(net_dev)); |
8ceee660 BH |
680 | |
681 | return NOTIFY_DONE; | |
682 | } | |
683 | ||
684 | static struct notifier_block efx_netdev_notifier = { | |
685 | .notifier_call = efx_netdev_event, | |
686 | }; | |
687 | ||
3880fc37 Y |
688 | static ssize_t phy_type_show(struct device *dev, |
689 | struct device_attribute *attr, char *buf) | |
06d5e193 | 690 | { |
3e03a8ba | 691 | struct efx_nic *efx = dev_get_drvdata(dev); |
06d5e193 BH |
692 | return sprintf(buf, "%d\n", efx->phy_type); |
693 | } | |
3880fc37 | 694 | static DEVICE_ATTR_RO(phy_type); |
06d5e193 | 695 | |
8ceee660 BH |
696 | static int efx_register_netdev(struct efx_nic *efx) |
697 | { | |
698 | struct net_device *net_dev = efx->net_dev; | |
c04bfc6b | 699 | struct efx_channel *channel; |
8ceee660 BH |
700 | int rc; |
701 | ||
702 | net_dev->watchdog_timeo = 5 * HZ; | |
703 | net_dev->irq = efx->pci_dev->irq; | |
7fa8d547 SS |
704 | net_dev->netdev_ops = &efx_netdev_ops; |
705 | if (efx_nic_rev(efx) >= EFX_REV_HUNT_A0) | |
8127d661 | 706 | net_dev->priv_flags |= IFF_UNICAST_FLT; |
7ad24ea4 | 707 | net_dev->ethtool_ops = &efx_ethtool_ops; |
ee8b7a11 | 708 | netif_set_tso_max_segs(net_dev, EFX_TSO_MAX_SEGS); |
cd94e519 BK |
709 | net_dev->min_mtu = EFX_MIN_MTU; |
710 | net_dev->max_mtu = EFX_MAX_MTU; | |
8ceee660 | 711 | |
7dde596e | 712 | rtnl_lock(); |
aed0628d | 713 | |
7153f623 BH |
714 | /* Enable resets to be scheduled and check whether any were |
715 | * already requested. If so, the NIC is probably hosed so we | |
716 | * abort. | |
717 | */ | |
7153f623 | 718 | if (efx->reset_pending) { |
fa44821a | 719 | pci_err(efx->pci_dev, "aborting probe due to scheduled reset\n"); |
7153f623 BH |
720 | rc = -EIO; |
721 | goto fail_locked; | |
722 | } | |
723 | ||
aed0628d BH |
724 | rc = dev_alloc_name(net_dev, net_dev->name); |
725 | if (rc < 0) | |
726 | goto fail_locked; | |
7dde596e | 727 | efx_update_name(efx); |
aed0628d | 728 | |
8f8b3d51 BH |
729 | /* Always start with carrier off; PHY events will detect the link */ |
730 | netif_carrier_off(net_dev); | |
731 | ||
aed0628d BH |
732 | rc = register_netdevice(net_dev); |
733 | if (rc) | |
734 | goto fail_locked; | |
735 | ||
c04bfc6b BH |
736 | efx_for_each_channel(channel, efx) { |
737 | struct efx_tx_queue *tx_queue; | |
60031fcc BH |
738 | efx_for_each_channel_tx_queue(tx_queue, channel) |
739 | efx_init_tx_queue_core_txq(tx_queue); | |
c04bfc6b BH |
740 | } |
741 | ||
0bcf4a64 BH |
742 | efx_associate(efx); |
743 | ||
813cf9d1 JC |
744 | efx->state = STATE_NET_DOWN; |
745 | ||
7dde596e | 746 | rtnl_unlock(); |
8ceee660 | 747 | |
06d5e193 BH |
748 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
749 | if (rc) { | |
62776d03 BH |
750 | netif_err(efx, drv, efx->net_dev, |
751 | "failed to init net dev attributes\n"); | |
06d5e193 BH |
752 | goto fail_registered; |
753 | } | |
b69f7a3e AM |
754 | |
755 | efx_init_mcdi_logging(efx); | |
06d5e193 | 756 | |
8ceee660 | 757 | return 0; |
06d5e193 | 758 | |
7153f623 BH |
759 | fail_registered: |
760 | rtnl_lock(); | |
0bcf4a64 | 761 | efx_dissociate(efx); |
7153f623 | 762 | unregister_netdevice(net_dev); |
aed0628d | 763 | fail_locked: |
7153f623 | 764 | efx->state = STATE_UNINIT; |
aed0628d | 765 | rtnl_unlock(); |
62776d03 | 766 | netif_err(efx, drv, efx->net_dev, "could not register net dev\n"); |
aed0628d | 767 | return rc; |
8ceee660 BH |
768 | } |
769 | ||
770 | static void efx_unregister_netdev(struct efx_nic *efx) | |
771 | { | |
8ceee660 BH |
772 | if (!efx->net_dev) |
773 | return; | |
774 | ||
8cb03f4e | 775 | if (WARN_ON(efx_netdev_priv(efx->net_dev) != efx)) |
b3fd0a86 | 776 | return; |
8ceee660 | 777 | |
e7fef9b4 | 778 | if (efx_dev_registered(efx)) { |
f029c781 | 779 | strscpy(efx->name, pci_name(efx->pci_dev), sizeof(efx->name)); |
b69f7a3e | 780 | efx_fini_mcdi_logging(efx); |
e7fef9b4 EC |
781 | device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_type); |
782 | unregister_netdev(efx->net_dev); | |
783 | } | |
8ceee660 BH |
784 | } |
785 | ||
8ceee660 BH |
786 | /************************************************************************** |
787 | * | |
788 | * List of NICs we support | |
789 | * | |
790 | **************************************************************************/ | |
791 | ||
792 | /* PCI device ID table */ | |
9baa3c34 | 793 | static const struct pci_device_id efx_pci_table[] = { |
8127d661 BH |
794 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0903), /* SFC9120 PF */ |
795 | .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, | |
6f7f8aa6 SS |
796 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1903), /* SFC9120 VF */ |
797 | .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, | |
3b06a00e MW |
798 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0923), /* SFC9140 PF */ |
799 | .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, | |
dd248f1b BK |
800 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1923), /* SFC9140 VF */ |
801 | .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, | |
802 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0a03), /* SFC9220 PF */ | |
803 | .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, | |
804 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1a03), /* SFC9220 VF */ | |
805 | .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, | |
aae5a316 EC |
806 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x0b03), /* SFC9250 PF */ |
807 | .driver_data = (unsigned long) &efx_hunt_a0_nic_type}, | |
808 | {PCI_DEVICE(PCI_VENDOR_ID_SOLARFLARE, 0x1b03), /* SFC9250 VF */ | |
809 | .driver_data = (unsigned long) &efx_hunt_a0_vf_nic_type}, | |
8ceee660 BH |
810 | {0} /* end of list */ |
811 | }; | |
812 | ||
8ceee660 BH |
813 | /************************************************************************** |
814 | * | |
815 | * Data housekeeping | |
816 | * | |
817 | **************************************************************************/ | |
818 | ||
e4d112e4 EC |
819 | void efx_update_sw_stats(struct efx_nic *efx, u64 *stats) |
820 | { | |
821 | u64 n_rx_nodesc_trunc = 0; | |
822 | struct efx_channel *channel; | |
823 | ||
824 | efx_for_each_channel(channel, efx) | |
825 | n_rx_nodesc_trunc += channel->n_rx_nodesc_trunc; | |
826 | stats[GENERIC_STAT_rx_nodesc_trunc] = n_rx_nodesc_trunc; | |
827 | stats[GENERIC_STAT_rx_noskb_drops] = atomic_read(&efx->n_rx_noskb_drops); | |
828 | } | |
829 | ||
8ceee660 BH |
830 | /************************************************************************** |
831 | * | |
832 | * PCI interface | |
833 | * | |
834 | **************************************************************************/ | |
835 | ||
836 | /* Main body of final NIC shutdown code | |
837 | * This is called only at module unload (or hotplug removal). | |
838 | */ | |
839 | static void efx_pci_remove_main(struct efx_nic *efx) | |
840 | { | |
7153f623 BH |
841 | /* Flush reset_work. It can no longer be scheduled since we |
842 | * are not READY. | |
843 | */ | |
813cf9d1 | 844 | WARN_ON(efx_net_active(efx->state)); |
82c64484 | 845 | efx_flush_reset_workqueue(efx); |
7153f623 | 846 | |
d8291187 | 847 | efx_disable_interrupts(efx); |
a83762d9 | 848 | efx_clear_interrupt_affinity(efx); |
152b6a62 | 849 | efx_nic_fini_interrupt(efx); |
8ceee660 | 850 | efx_fini_port(efx); |
ef2b90ee | 851 | efx->type->fini(efx); |
8ceee660 BH |
852 | efx_fini_napi(efx); |
853 | efx_remove_all(efx); | |
854 | } | |
855 | ||
856 | /* Final NIC shutdown | |
2a3fc311 DP |
857 | * This is called only at module unload (or hotplug removal). A PF can call |
858 | * this on its VFs to ensure they are unbound first. | |
8ceee660 BH |
859 | */ |
860 | static void efx_pci_remove(struct pci_dev *pci_dev) | |
861 | { | |
7e773594 | 862 | struct efx_probe_data *probe_data; |
8ceee660 BH |
863 | struct efx_nic *efx; |
864 | ||
865 | efx = pci_get_drvdata(pci_dev); | |
866 | if (!efx) | |
867 | return; | |
868 | ||
869 | /* Mark the NIC as fini, then stop the interface */ | |
870 | rtnl_lock(); | |
0bcf4a64 | 871 | efx_dissociate(efx); |
8ceee660 | 872 | dev_close(efx->net_dev); |
d8291187 | 873 | efx_disable_interrupts(efx); |
ea6bb99e | 874 | efx->state = STATE_UNINIT; |
8ceee660 BH |
875 | rtnl_unlock(); |
876 | ||
7fa8d547 SS |
877 | if (efx->type->sriov_fini) |
878 | efx->type->sriov_fini(efx); | |
879 | ||
8ceee660 BH |
880 | efx_unregister_netdev(efx); |
881 | ||
7dde596e BH |
882 | efx_mtd_remove(efx); |
883 | ||
8ceee660 BH |
884 | efx_pci_remove_main(efx); |
885 | ||
66a65128 | 886 | efx_fini_io(efx); |
98ff4c7c | 887 | pci_dbg(efx->pci_dev, "shutdown successful\n"); |
8ceee660 | 888 | |
8ceee660 BH |
889 | efx_fini_struct(efx); |
890 | free_netdev(efx->net_dev); | |
7e773594 JC |
891 | probe_data = container_of(efx, struct efx_probe_data, efx); |
892 | kfree(probe_data); | |
8ceee660 BH |
893 | }; |
894 | ||
460eeaa0 BH |
895 | /* NIC VPD information |
896 | * Called during probe to display the part number of the | |
5119e20f | 897 | * installed NIC. |
460eeaa0 | 898 | */ |
ef215e64 | 899 | static void efx_probe_vpd_strings(struct efx_nic *efx) |
460eeaa0 BH |
900 | { |
901 | struct pci_dev *dev = efx->pci_dev; | |
37838aa4 | 902 | unsigned int vpd_size, kw_len; |
5119e20f | 903 | u8 *vpd_data; |
37838aa4 | 904 | int start; |
460eeaa0 | 905 | |
5119e20f HK |
906 | vpd_data = pci_vpd_alloc(dev, &vpd_size); |
907 | if (IS_ERR(vpd_data)) { | |
908 | pci_warn(dev, "Unable to read VPD\n"); | |
460eeaa0 BH |
909 | return; |
910 | } | |
911 | ||
37838aa4 HK |
912 | start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, |
913 | PCI_VPD_RO_KEYWORD_PARTNO, &kw_len); | |
914 | if (start < 0) | |
915 | pci_err(dev, "Part number not found or incomplete\n"); | |
916 | else | |
917 | pci_info(dev, "Part Number : %.*s\n", kw_len, vpd_data + start); | |
ef215e64 | 918 | |
37838aa4 HK |
919 | start = pci_vpd_find_ro_info_keyword(vpd_data, vpd_size, |
920 | PCI_VPD_RO_KEYWORD_SERIALNO, &kw_len); | |
921 | if (start < 0) | |
922 | pci_err(dev, "Serial number not found or incomplete\n"); | |
923 | else | |
924 | efx->vpd_sn = kmemdup_nul(vpd_data + start, kw_len, GFP_KERNEL); | |
ef215e64 | 925 | |
5119e20f | 926 | kfree(vpd_data); |
460eeaa0 BH |
927 | } |
928 | ||
929 | ||
8ceee660 BH |
930 | /* Main body of NIC initialisation |
931 | * This is called at module load (or hotplug insertion, theoretically). | |
932 | */ | |
933 | static int efx_pci_probe_main(struct efx_nic *efx) | |
934 | { | |
935 | int rc; | |
936 | ||
937 | /* Do start-of-day initialisation */ | |
938 | rc = efx_probe_all(efx); | |
939 | if (rc) | |
940 | goto fail1; | |
941 | ||
e8f14992 | 942 | efx_init_napi(efx); |
8ceee660 | 943 | |
193f2003 | 944 | down_write(&efx->filter_sem); |
ef2b90ee | 945 | rc = efx->type->init(efx); |
193f2003 | 946 | up_write(&efx->filter_sem); |
8ceee660 | 947 | if (rc) { |
fa44821a | 948 | pci_err(efx->pci_dev, "failed to initialise NIC\n"); |
278c0621 | 949 | goto fail3; |
8ceee660 BH |
950 | } |
951 | ||
952 | rc = efx_init_port(efx); | |
953 | if (rc) { | |
62776d03 BH |
954 | netif_err(efx, probe, efx->net_dev, |
955 | "failed to initialise port\n"); | |
278c0621 | 956 | goto fail4; |
8ceee660 BH |
957 | } |
958 | ||
152b6a62 | 959 | rc = efx_nic_init_interrupt(efx); |
8ceee660 | 960 | if (rc) |
278c0621 | 961 | goto fail5; |
a83762d9 BK |
962 | |
963 | efx_set_interrupt_affinity(efx); | |
261e4d96 JC |
964 | rc = efx_enable_interrupts(efx); |
965 | if (rc) | |
966 | goto fail6; | |
8ceee660 BH |
967 | |
968 | return 0; | |
969 | ||
261e4d96 | 970 | fail6: |
a83762d9 | 971 | efx_clear_interrupt_affinity(efx); |
261e4d96 | 972 | efx_nic_fini_interrupt(efx); |
278c0621 | 973 | fail5: |
8ceee660 | 974 | efx_fini_port(efx); |
8ceee660 | 975 | fail4: |
ef2b90ee | 976 | efx->type->fini(efx); |
8ceee660 BH |
977 | fail3: |
978 | efx_fini_napi(efx); | |
8ceee660 BH |
979 | efx_remove_all(efx); |
980 | fail1: | |
981 | return rc; | |
982 | } | |
983 | ||
8a531400 JC |
984 | static int efx_pci_probe_post_io(struct efx_nic *efx) |
985 | { | |
986 | struct net_device *net_dev = efx->net_dev; | |
987 | int rc = efx_pci_probe_main(efx); | |
988 | ||
989 | if (rc) | |
990 | return rc; | |
991 | ||
992 | if (efx->type->sriov_init) { | |
993 | rc = efx->type->sriov_init(efx); | |
994 | if (rc) | |
fa44821a HK |
995 | pci_err(efx->pci_dev, "SR-IOV can't be enabled rc %d\n", |
996 | rc); | |
8a531400 JC |
997 | } |
998 | ||
999 | /* Determine netdevice features */ | |
ca4a80e4 ÍH |
1000 | net_dev->features |= efx->type->offload_features; |
1001 | ||
1002 | /* Add TSO features */ | |
1003 | if (efx->type->tso_versions && efx->type->tso_versions(efx)) | |
1004 | net_dev->features |= NETIF_F_TSO | NETIF_F_TSO6; | |
1005 | ||
8a531400 JC |
1006 | /* Mask for features that also apply to VLAN devices */ |
1007 | net_dev->vlan_features |= (NETIF_F_HW_CSUM | NETIF_F_SG | | |
1008 | NETIF_F_HIGHDMA | NETIF_F_ALL_TSO | | |
1009 | NETIF_F_RXCSUM); | |
1010 | ||
ca4a80e4 | 1011 | /* Determine user configurable features */ |
6978729f EC |
1012 | net_dev->hw_features |= net_dev->features & ~efx->fixed_features; |
1013 | ||
1014 | /* Disable receiving frames with bad FCS, by default. */ | |
1015 | net_dev->features &= ~NETIF_F_RXALL; | |
8a531400 JC |
1016 | |
1017 | /* Disable VLAN filtering by default. It may be enforced if | |
1018 | * the feature is fixed (i.e. VLAN filters are required to | |
1019 | * receive VLAN tagged packets due to vPort restrictions). | |
1020 | */ | |
1021 | net_dev->features &= ~NETIF_F_HW_VLAN_CTAG_FILTER; | |
1022 | net_dev->features |= efx->fixed_features; | |
1023 | ||
9b0651e4 LB |
1024 | net_dev->xdp_features = NETDEV_XDP_ACT_BASIC | |
1025 | NETDEV_XDP_ACT_REDIRECT | | |
1026 | NETDEV_XDP_ACT_NDO_XMIT; | |
1027 | ||
8a531400 JC |
1028 | rc = efx_register_netdev(efx); |
1029 | if (!rc) | |
1030 | return 0; | |
1031 | ||
1032 | efx_pci_remove_main(efx); | |
1033 | return rc; | |
1034 | } | |
1035 | ||
8ceee660 BH |
1036 | /* NIC initialisation |
1037 | * | |
1038 | * This is called at module load (or hotplug insertion, | |
73ba7b68 | 1039 | * theoretically). It sets up PCI mappings, resets the NIC, |
8ceee660 BH |
1040 | * sets up and registers the network devices with the kernel and hooks |
1041 | * the interrupt service routine. It does not prepare the device for | |
1042 | * transmission; this is left to the first time one of the network | |
1043 | * interfaces is brought up (i.e. efx_net_open). | |
1044 | */ | |
87d1fc11 | 1045 | static int efx_pci_probe(struct pci_dev *pci_dev, |
1dd06ae8 | 1046 | const struct pci_device_id *entry) |
8ceee660 | 1047 | { |
7e773594 | 1048 | struct efx_probe_data *probe_data, **probe_ptr; |
8ceee660 BH |
1049 | struct net_device *net_dev; |
1050 | struct efx_nic *efx; | |
fadac6aa | 1051 | int rc; |
8ceee660 | 1052 | |
7e773594 JC |
1053 | /* Allocate probe data and struct efx_nic */ |
1054 | probe_data = kzalloc(sizeof(*probe_data), GFP_KERNEL); | |
1055 | if (!probe_data) | |
1056 | return -ENOMEM; | |
1057 | probe_data->pci_dev = pci_dev; | |
1058 | efx = &probe_data->efx; | |
1059 | ||
1060 | /* Allocate and initialise a struct net_device */ | |
1061 | net_dev = alloc_etherdev_mq(sizeof(probe_data), EFX_MAX_CORE_TX_QUEUES); | |
6c412da5 CJ |
1062 | if (!net_dev) { |
1063 | rc = -ENOMEM; | |
1064 | goto fail0; | |
1065 | } | |
7e773594 JC |
1066 | probe_ptr = netdev_priv(net_dev); |
1067 | *probe_ptr = probe_data; | |
1068 | efx->net_dev = net_dev; | |
adeb15aa | 1069 | efx->type = (const struct efx_nic_type *) entry->driver_data; |
ebfcd0fd | 1070 | efx->fixed_features |= NETIF_F_HIGHDMA; |
eb7cfd8c | 1071 | |
8ceee660 | 1072 | pci_set_drvdata(pci_dev, efx); |
62776d03 | 1073 | SET_NETDEV_DEV(net_dev, &pci_dev->dev); |
62ac3ce5 | 1074 | rc = efx_init_struct(efx, pci_dev); |
8ceee660 BH |
1075 | if (rc) |
1076 | goto fail1; | |
62ac3ce5 | 1077 | efx->mdio.dev = net_dev; |
8ceee660 | 1078 | |
fa44821a | 1079 | pci_info(pci_dev, "Solarflare NIC detected\n"); |
8ceee660 | 1080 | |
6f7f8aa6 SS |
1081 | if (!efx->type->is_vf) |
1082 | efx_probe_vpd_strings(efx); | |
460eeaa0 | 1083 | |
8ceee660 | 1084 | /* Set up basic I/O (BAR mappings etc) */ |
b1940451 AM |
1085 | rc = efx_init_io(efx, efx->type->mem_bar(efx), efx->type->max_dma_mask, |
1086 | efx->type->mem_map_size(efx)); | |
8ceee660 BH |
1087 | if (rc) |
1088 | goto fail2; | |
1089 | ||
8a531400 JC |
1090 | rc = efx_pci_probe_post_io(efx); |
1091 | if (rc) { | |
1092 | /* On failure, retry once immediately. | |
1093 | * If we aborted probe due to a scheduled reset, dismiss it. | |
1094 | */ | |
1095 | efx->reset_pending = 0; | |
1096 | rc = efx_pci_probe_post_io(efx); | |
1097 | if (rc) { | |
1098 | /* On another failure, retry once more | |
1099 | * after a 50-305ms delay. | |
1100 | */ | |
1101 | unsigned char r; | |
1102 | ||
1103 | get_random_bytes(&r, 1); | |
1104 | msleep((unsigned int)r + 50); | |
1105 | efx->reset_pending = 0; | |
1106 | rc = efx_pci_probe_post_io(efx); | |
1107 | } | |
1108 | } | |
fadac6aa BH |
1109 | if (rc) |
1110 | goto fail3; | |
8ceee660 | 1111 | |
62776d03 | 1112 | netif_dbg(efx, probe, efx->net_dev, "initialisation successful\n"); |
a5211bb5 | 1113 | |
7c43161c | 1114 | /* Try to create MTDs, but allow this to fail */ |
a5211bb5 | 1115 | rtnl_lock(); |
7c43161c | 1116 | rc = efx_mtd_probe(efx); |
a5211bb5 | 1117 | rtnl_unlock(); |
09a04204 | 1118 | if (rc && rc != -EPERM) |
7c43161c BH |
1119 | netif_warn(efx, probe, efx->net_dev, |
1120 | "failed to create MTDs (%d)\n", rc); | |
1121 | ||
e5fbd977 JC |
1122 | if (efx->type->udp_tnl_push_ports) |
1123 | efx->type->udp_tnl_push_ports(efx); | |
1124 | ||
8ceee660 BH |
1125 | return 0; |
1126 | ||
8ceee660 | 1127 | fail3: |
66a65128 | 1128 | efx_fini_io(efx); |
8ceee660 BH |
1129 | fail2: |
1130 | efx_fini_struct(efx); | |
1131 | fail1: | |
5e2a911c | 1132 | WARN_ON(rc > 0); |
62776d03 | 1133 | netif_dbg(efx, drv, efx->net_dev, "initialisation failed. rc=%d\n", rc); |
8ceee660 | 1134 | free_netdev(net_dev); |
6c412da5 CJ |
1135 | fail0: |
1136 | kfree(probe_data); | |
8ceee660 BH |
1137 | return rc; |
1138 | } | |
1139 | ||
834e23dd SS |
1140 | /* efx_pci_sriov_configure returns the actual number of Virtual Functions |
1141 | * enabled on success | |
1142 | */ | |
1143 | #ifdef CONFIG_SFC_SRIOV | |
1144 | static int efx_pci_sriov_configure(struct pci_dev *dev, int num_vfs) | |
1145 | { | |
1146 | int rc; | |
1147 | struct efx_nic *efx = pci_get_drvdata(dev); | |
1148 | ||
1149 | if (efx->type->sriov_configure) { | |
1150 | rc = efx->type->sriov_configure(efx, num_vfs); | |
1151 | if (rc) | |
1152 | return rc; | |
1153 | else | |
1154 | return num_vfs; | |
1155 | } else | |
1156 | return -EOPNOTSUPP; | |
1157 | } | |
1158 | #endif | |
1159 | ||
89c758fa BH |
1160 | static int efx_pm_freeze(struct device *dev) |
1161 | { | |
3e03a8ba | 1162 | struct efx_nic *efx = dev_get_drvdata(dev); |
89c758fa | 1163 | |
61da026d BH |
1164 | rtnl_lock(); |
1165 | ||
813cf9d1 | 1166 | if (efx_net_active(efx->state)) { |
c2f3b8e3 | 1167 | efx_device_detach_sync(efx); |
89c758fa | 1168 | |
6032fb56 | 1169 | efx_stop_all(efx); |
d8291187 | 1170 | efx_disable_interrupts(efx); |
813cf9d1 JC |
1171 | |
1172 | efx->state = efx_freeze(efx->state); | |
6032fb56 | 1173 | } |
89c758fa | 1174 | |
61da026d BH |
1175 | rtnl_unlock(); |
1176 | ||
89c758fa BH |
1177 | return 0; |
1178 | } | |
1179 | ||
41e3b072 PJV |
1180 | static void efx_pci_shutdown(struct pci_dev *pci_dev) |
1181 | { | |
1182 | struct efx_nic *efx = pci_get_drvdata(pci_dev); | |
1183 | ||
1184 | if (!efx) | |
1185 | return; | |
1186 | ||
1187 | efx_pm_freeze(&pci_dev->dev); | |
1188 | pci_disable_device(pci_dev); | |
1189 | } | |
1190 | ||
89c758fa BH |
1191 | static int efx_pm_thaw(struct device *dev) |
1192 | { | |
261e4d96 | 1193 | int rc; |
3e03a8ba | 1194 | struct efx_nic *efx = dev_get_drvdata(dev); |
89c758fa | 1195 | |
61da026d BH |
1196 | rtnl_lock(); |
1197 | ||
813cf9d1 | 1198 | if (efx_frozen(efx->state)) { |
261e4d96 JC |
1199 | rc = efx_enable_interrupts(efx); |
1200 | if (rc) | |
1201 | goto fail; | |
89c758fa | 1202 | |
6032fb56 | 1203 | mutex_lock(&efx->mac_lock); |
c77289b4 | 1204 | efx_mcdi_port_reconfigure(efx); |
6032fb56 | 1205 | mutex_unlock(&efx->mac_lock); |
89c758fa | 1206 | |
6032fb56 | 1207 | efx_start_all(efx); |
89c758fa | 1208 | |
9c568fd8 | 1209 | efx_device_attach_if_not_resetting(efx); |
89c758fa | 1210 | |
813cf9d1 | 1211 | efx->state = efx_thaw(efx->state); |
89c758fa | 1212 | |
6032fb56 BH |
1213 | efx->type->resume_wol(efx); |
1214 | } | |
89c758fa | 1215 | |
61da026d BH |
1216 | rtnl_unlock(); |
1217 | ||
319ba649 | 1218 | /* Reschedule any quenched resets scheduled during efx_pm_freeze() */ |
82c64484 | 1219 | efx_queue_reset_work(efx); |
319ba649 | 1220 | |
89c758fa | 1221 | return 0; |
261e4d96 JC |
1222 | |
1223 | fail: | |
1224 | rtnl_unlock(); | |
1225 | ||
1226 | return rc; | |
89c758fa BH |
1227 | } |
1228 | ||
1229 | static int efx_pm_poweroff(struct device *dev) | |
1230 | { | |
1231 | struct pci_dev *pci_dev = to_pci_dev(dev); | |
1232 | struct efx_nic *efx = pci_get_drvdata(pci_dev); | |
1233 | ||
1234 | efx->type->fini(efx); | |
1235 | ||
a7d529ae | 1236 | efx->reset_pending = 0; |
89c758fa BH |
1237 | |
1238 | pci_save_state(pci_dev); | |
1239 | return pci_set_power_state(pci_dev, PCI_D3hot); | |
1240 | } | |
1241 | ||
1242 | /* Used for both resume and restore */ | |
1243 | static int efx_pm_resume(struct device *dev) | |
1244 | { | |
1245 | struct pci_dev *pci_dev = to_pci_dev(dev); | |
1246 | struct efx_nic *efx = pci_get_drvdata(pci_dev); | |
1247 | int rc; | |
1248 | ||
1249 | rc = pci_set_power_state(pci_dev, PCI_D0); | |
1250 | if (rc) | |
1251 | return rc; | |
1252 | pci_restore_state(pci_dev); | |
1253 | rc = pci_enable_device(pci_dev); | |
1254 | if (rc) | |
1255 | return rc; | |
1256 | pci_set_master(efx->pci_dev); | |
1257 | rc = efx->type->reset(efx, RESET_TYPE_ALL); | |
1258 | if (rc) | |
1259 | return rc; | |
193f2003 | 1260 | down_write(&efx->filter_sem); |
89c758fa | 1261 | rc = efx->type->init(efx); |
193f2003 | 1262 | up_write(&efx->filter_sem); |
89c758fa BH |
1263 | if (rc) |
1264 | return rc; | |
261e4d96 JC |
1265 | rc = efx_pm_thaw(dev); |
1266 | return rc; | |
89c758fa BH |
1267 | } |
1268 | ||
1269 | static int efx_pm_suspend(struct device *dev) | |
1270 | { | |
1271 | int rc; | |
1272 | ||
1273 | efx_pm_freeze(dev); | |
1274 | rc = efx_pm_poweroff(dev); | |
1275 | if (rc) | |
1276 | efx_pm_resume(dev); | |
1277 | return rc; | |
1278 | } | |
1279 | ||
18e83e4c | 1280 | static const struct dev_pm_ops efx_pm_ops = { |
89c758fa BH |
1281 | .suspend = efx_pm_suspend, |
1282 | .resume = efx_pm_resume, | |
1283 | .freeze = efx_pm_freeze, | |
1284 | .thaw = efx_pm_thaw, | |
1285 | .poweroff = efx_pm_poweroff, | |
1286 | .restore = efx_pm_resume, | |
1287 | }; | |
1288 | ||
8ceee660 | 1289 | static struct pci_driver efx_pci_driver = { |
c5d5f5fd | 1290 | .name = KBUILD_MODNAME, |
8ceee660 BH |
1291 | .id_table = efx_pci_table, |
1292 | .probe = efx_pci_probe, | |
1293 | .remove = efx_pci_remove, | |
89c758fa | 1294 | .driver.pm = &efx_pm_ops, |
41e3b072 | 1295 | .shutdown = efx_pci_shutdown, |
626950db | 1296 | .err_handler = &efx_err_handlers, |
834e23dd SS |
1297 | #ifdef CONFIG_SFC_SRIOV |
1298 | .sriov_configure = efx_pci_sriov_configure, | |
1299 | #endif | |
8ceee660 BH |
1300 | }; |
1301 | ||
1302 | /************************************************************************** | |
1303 | * | |
1304 | * Kernel module interface | |
1305 | * | |
1306 | *************************************************************************/ | |
1307 | ||
8ceee660 BH |
1308 | static int __init efx_init_module(void) |
1309 | { | |
1310 | int rc; | |
1311 | ||
60bd2a2d | 1312 | printk(KERN_INFO "Solarflare NET driver\n"); |
8ceee660 BH |
1313 | |
1314 | rc = register_netdevice_notifier(&efx_netdev_notifier); | |
1315 | if (rc) | |
1316 | goto err_notifier; | |
1317 | ||
82c64484 AM |
1318 | rc = efx_create_reset_workqueue(); |
1319 | if (rc) | |
1ab00629 | 1320 | goto err_reset; |
8ceee660 BH |
1321 | |
1322 | rc = pci_register_driver(&efx_pci_driver); | |
1323 | if (rc < 0) | |
1324 | goto err_pci; | |
1325 | ||
51b35a45 EC |
1326 | rc = pci_register_driver(&ef100_pci_driver); |
1327 | if (rc < 0) | |
1328 | goto err_pci_ef100; | |
1329 | ||
8ceee660 BH |
1330 | return 0; |
1331 | ||
51b35a45 EC |
1332 | err_pci_ef100: |
1333 | pci_unregister_driver(&efx_pci_driver); | |
8ceee660 | 1334 | err_pci: |
82c64484 | 1335 | efx_destroy_reset_workqueue(); |
1ab00629 | 1336 | err_reset: |
8ceee660 BH |
1337 | unregister_netdevice_notifier(&efx_netdev_notifier); |
1338 | err_notifier: | |
1339 | return rc; | |
1340 | } | |
1341 | ||
1342 | static void __exit efx_exit_module(void) | |
1343 | { | |
1344 | printk(KERN_INFO "Solarflare NET driver unloading\n"); | |
1345 | ||
51b35a45 | 1346 | pci_unregister_driver(&ef100_pci_driver); |
8ceee660 | 1347 | pci_unregister_driver(&efx_pci_driver); |
82c64484 | 1348 | efx_destroy_reset_workqueue(); |
8ceee660 BH |
1349 | unregister_netdevice_notifier(&efx_netdev_notifier); |
1350 | ||
1351 | } | |
1352 | ||
1353 | module_init(efx_init_module); | |
1354 | module_exit(efx_exit_module); | |
1355 | ||
906bb26c BH |
1356 | MODULE_AUTHOR("Solarflare Communications and " |
1357 | "Michael Brown <mbrown@fensystems.co.uk>"); | |
6a350fdb | 1358 | MODULE_DESCRIPTION("Solarflare network driver"); |
8ceee660 BH |
1359 | MODULE_LICENSE("GPL"); |
1360 | MODULE_DEVICE_TABLE(pci, efx_pci_table); |