Commit | Line | Data |
---|---|---|
8127d661 BH |
1 | /**************************************************************************** |
2 | * Driver for Solarflare network controllers and boards | |
3 | * Copyright 2012-2013 Solarflare Communications Inc. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License version 2 as published | |
7 | * by the Free Software Foundation, incorporated herein by reference. | |
8 | */ | |
9 | ||
10 | #include "net_driver.h" | |
11 | #include "ef10_regs.h" | |
12 | #include "io.h" | |
13 | #include "mcdi.h" | |
14 | #include "mcdi_pcol.h" | |
15 | #include "nic.h" | |
16 | #include "workarounds.h" | |
74cd60a4 | 17 | #include "selftest.h" |
7fa8d547 | 18 | #include "ef10_sriov.h" |
8127d661 BH |
19 | #include <linux/in.h> |
20 | #include <linux/jhash.h> | |
21 | #include <linux/wait.h> | |
22 | #include <linux/workqueue.h> | |
23 | ||
24 | /* Hardware control for EF10 architecture including 'Huntington'. */ | |
25 | ||
26 | #define EFX_EF10_DRVGEN_EV 7 | |
27 | enum { | |
28 | EFX_EF10_TEST = 1, | |
29 | EFX_EF10_REFILL, | |
30 | }; | |
31 | ||
32 | /* The reserved RSS context value */ | |
33 | #define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff | |
267c0157 JC |
34 | /* The maximum size of a shared RSS context */ |
35 | /* TODO: this should really be from the mcdi protocol export */ | |
36 | #define EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE 64UL | |
8127d661 BH |
37 | |
38 | /* The filter table(s) are managed by firmware and we have write-only | |
39 | * access. When removing filters we must identify them to the | |
40 | * firmware by a 64-bit handle, but this is too wide for Linux kernel | |
41 | * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to | |
42 | * be able to tell in advance whether a requested insertion will | |
43 | * replace an existing filter. Therefore we maintain a software hash | |
44 | * table, which should be at least as large as the hardware hash | |
45 | * table. | |
46 | * | |
47 | * Huntington has a single 8K filter table shared between all filter | |
48 | * types and both ports. | |
49 | */ | |
50 | #define HUNT_FILTER_TBL_ROWS 8192 | |
51 | ||
52 | struct efx_ef10_filter_table { | |
53 | /* The RX match field masks supported by this fw & hw, in order of priority */ | |
54 | enum efx_filter_match_flags rx_match_flags[ | |
55 | MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM]; | |
56 | unsigned int rx_match_count; | |
57 | ||
58 | struct { | |
59 | unsigned long spec; /* pointer to spec plus flag bits */ | |
b59e6ef8 BH |
60 | /* BUSY flag indicates that an update is in progress. AUTO_OLD is |
61 | * used to mark and sweep MAC filters for the device address lists. | |
8127d661 BH |
62 | */ |
63 | #define EFX_EF10_FILTER_FLAG_BUSY 1UL | |
b59e6ef8 | 64 | #define EFX_EF10_FILTER_FLAG_AUTO_OLD 2UL |
8127d661 BH |
65 | #define EFX_EF10_FILTER_FLAGS 3UL |
66 | u64 handle; /* firmware handle */ | |
67 | } *entry; | |
68 | wait_queue_head_t waitq; | |
69 | /* Shadow of net_device address lists, guarded by mac_lock */ | |
b59e6ef8 BH |
70 | #define EFX_EF10_FILTER_DEV_UC_MAX 32 |
71 | #define EFX_EF10_FILTER_DEV_MC_MAX 256 | |
8127d661 BH |
72 | struct { |
73 | u8 addr[ETH_ALEN]; | |
74 | u16 id; | |
b59e6ef8 BH |
75 | } dev_uc_list[EFX_EF10_FILTER_DEV_UC_MAX], |
76 | dev_mc_list[EFX_EF10_FILTER_DEV_MC_MAX]; | |
77 | int dev_uc_count; /* negative for PROMISC */ | |
78 | int dev_mc_count; /* negative for PROMISC/ALLMULTI */ | |
8127d661 BH |
79 | }; |
80 | ||
81 | /* An arbitrary search limit for the software hash table */ | |
82 | #define EFX_EF10_FILTER_SEARCH_LIMIT 200 | |
83 | ||
8127d661 BH |
84 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx); |
85 | static void efx_ef10_filter_table_remove(struct efx_nic *efx); | |
86 | ||
87 | static int efx_ef10_get_warm_boot_count(struct efx_nic *efx) | |
88 | { | |
89 | efx_dword_t reg; | |
90 | ||
91 | efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS); | |
92 | return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ? | |
93 | EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO; | |
94 | } | |
95 | ||
96 | static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx) | |
97 | { | |
02246a7f SS |
98 | int bar; |
99 | ||
100 | bar = efx->type->mem_bar; | |
101 | return resource_size(&efx->pci_dev->resource[bar]); | |
8127d661 BH |
102 | } |
103 | ||
1cd9ecbb DP |
104 | static int efx_ef10_get_pf_index(struct efx_nic *efx) |
105 | { | |
106 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); | |
107 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
108 | size_t outlen; | |
109 | int rc; | |
110 | ||
111 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf, | |
112 | sizeof(outbuf), &outlen); | |
113 | if (rc) | |
114 | return rc; | |
115 | if (outlen < sizeof(outbuf)) | |
116 | return -EIO; | |
117 | ||
118 | nic_data->pf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_PF); | |
119 | return 0; | |
120 | } | |
121 | ||
88a37de6 SS |
122 | #ifdef CONFIG_SFC_SRIOV |
123 | static int efx_ef10_get_vf_index(struct efx_nic *efx) | |
124 | { | |
125 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_FUNCTION_INFO_OUT_LEN); | |
126 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
127 | size_t outlen; | |
128 | int rc; | |
129 | ||
130 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_FUNCTION_INFO, NULL, 0, outbuf, | |
131 | sizeof(outbuf), &outlen); | |
132 | if (rc) | |
133 | return rc; | |
134 | if (outlen < sizeof(outbuf)) | |
135 | return -EIO; | |
136 | ||
137 | nic_data->vf_index = MCDI_DWORD(outbuf, GET_FUNCTION_INFO_OUT_VF); | |
138 | return 0; | |
139 | } | |
140 | #endif | |
141 | ||
e5a2538a | 142 | static int efx_ef10_init_datapath_caps(struct efx_nic *efx) |
8127d661 BH |
143 | { |
144 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN); | |
145 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
146 | size_t outlen; | |
147 | int rc; | |
148 | ||
149 | BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0); | |
150 | ||
151 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0, | |
152 | outbuf, sizeof(outbuf), &outlen); | |
153 | if (rc) | |
154 | return rc; | |
e5a2538a BH |
155 | if (outlen < sizeof(outbuf)) { |
156 | netif_err(efx, drv, efx->net_dev, | |
157 | "unable to read datapath firmware capabilities\n"); | |
158 | return -EIO; | |
159 | } | |
160 | ||
161 | nic_data->datapath_caps = | |
162 | MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1); | |
8127d661 | 163 | |
8d9f9dd4 DP |
164 | /* record the DPCPU firmware IDs to determine VEB vswitching support. |
165 | */ | |
166 | nic_data->rx_dpcpu_fw_id = | |
167 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_RX_DPCPU_FW_ID); | |
168 | nic_data->tx_dpcpu_fw_id = | |
169 | MCDI_WORD(outbuf, GET_CAPABILITIES_OUT_TX_DPCPU_FW_ID); | |
170 | ||
e5a2538a BH |
171 | if (!(nic_data->datapath_caps & |
172 | (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) { | |
173 | netif_err(efx, drv, efx->net_dev, | |
174 | "current firmware does not support TSO\n"); | |
175 | return -ENODEV; | |
176 | } | |
177 | ||
178 | if (!(nic_data->datapath_caps & | |
179 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) { | |
180 | netif_err(efx, probe, efx->net_dev, | |
181 | "current firmware does not support an RX prefix\n"); | |
182 | return -ENODEV; | |
8127d661 BH |
183 | } |
184 | ||
185 | return 0; | |
186 | } | |
187 | ||
188 | static int efx_ef10_get_sysclk_freq(struct efx_nic *efx) | |
189 | { | |
190 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN); | |
191 | int rc; | |
192 | ||
193 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0, | |
194 | outbuf, sizeof(outbuf), NULL); | |
195 | if (rc) | |
196 | return rc; | |
197 | rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ); | |
198 | return rc > 0 ? rc : -ERANGE; | |
199 | } | |
200 | ||
0d5e0fbb | 201 | static int efx_ef10_get_mac_address_pf(struct efx_nic *efx, u8 *mac_address) |
8127d661 BH |
202 | { |
203 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN); | |
204 | size_t outlen; | |
205 | int rc; | |
206 | ||
207 | BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0); | |
208 | ||
209 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0, | |
210 | outbuf, sizeof(outbuf), &outlen); | |
211 | if (rc) | |
212 | return rc; | |
213 | if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) | |
214 | return -EIO; | |
215 | ||
cd84ff4d EC |
216 | ether_addr_copy(mac_address, |
217 | MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE)); | |
8127d661 BH |
218 | return 0; |
219 | } | |
220 | ||
0d5e0fbb DP |
221 | static int efx_ef10_get_mac_address_vf(struct efx_nic *efx, u8 *mac_address) |
222 | { | |
223 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_IN_LEN); | |
224 | MCDI_DECLARE_BUF(outbuf, MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMAX); | |
225 | size_t outlen; | |
226 | int num_addrs, rc; | |
227 | ||
228 | MCDI_SET_DWORD(inbuf, VPORT_GET_MAC_ADDRESSES_IN_VPORT_ID, | |
229 | EVB_PORT_ID_ASSIGNED); | |
230 | rc = efx_mcdi_rpc(efx, MC_CMD_VPORT_GET_MAC_ADDRESSES, inbuf, | |
231 | sizeof(inbuf), outbuf, sizeof(outbuf), &outlen); | |
232 | ||
233 | if (rc) | |
234 | return rc; | |
235 | if (outlen < MC_CMD_VPORT_GET_MAC_ADDRESSES_OUT_LENMIN) | |
236 | return -EIO; | |
237 | ||
238 | num_addrs = MCDI_DWORD(outbuf, | |
239 | VPORT_GET_MAC_ADDRESSES_OUT_MACADDR_COUNT); | |
240 | ||
241 | WARN_ON(num_addrs != 1); | |
242 | ||
243 | ether_addr_copy(mac_address, | |
244 | MCDI_PTR(outbuf, VPORT_GET_MAC_ADDRESSES_OUT_MACADDR)); | |
245 | ||
246 | return 0; | |
247 | } | |
248 | ||
0f5c0845 SS |
249 | static ssize_t efx_ef10_show_link_control_flag(struct device *dev, |
250 | struct device_attribute *attr, | |
251 | char *buf) | |
252 | { | |
253 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); | |
254 | ||
255 | return sprintf(buf, "%d\n", | |
256 | ((efx->mcdi->fn_flags) & | |
257 | (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL)) | |
258 | ? 1 : 0); | |
259 | } | |
260 | ||
261 | static ssize_t efx_ef10_show_primary_flag(struct device *dev, | |
262 | struct device_attribute *attr, | |
263 | char *buf) | |
264 | { | |
265 | struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev)); | |
266 | ||
267 | return sprintf(buf, "%d\n", | |
268 | ((efx->mcdi->fn_flags) & | |
269 | (1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_PRIMARY)) | |
270 | ? 1 : 0); | |
271 | } | |
272 | ||
273 | static DEVICE_ATTR(link_control_flag, 0444, efx_ef10_show_link_control_flag, | |
274 | NULL); | |
275 | static DEVICE_ATTR(primary_flag, 0444, efx_ef10_show_primary_flag, NULL); | |
276 | ||
8127d661 BH |
277 | static int efx_ef10_probe(struct efx_nic *efx) |
278 | { | |
279 | struct efx_ef10_nic_data *nic_data; | |
8be41320 | 280 | struct net_device *net_dev = efx->net_dev; |
8127d661 BH |
281 | int i, rc; |
282 | ||
aa3930ee BH |
283 | /* We can have one VI for each 8K region. However, until we |
284 | * use TX option descriptors we need two TX queues per channel. | |
8127d661 BH |
285 | */ |
286 | efx->max_channels = | |
287 | min_t(unsigned int, | |
288 | EFX_MAX_CHANNELS, | |
02246a7f | 289 | efx_ef10_mem_map_size(efx) / |
8127d661 | 290 | (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES)); |
9fd3d3a4 EC |
291 | if (WARN_ON(efx->max_channels == 0)) |
292 | return -EIO; | |
8127d661 BH |
293 | |
294 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); | |
295 | if (!nic_data) | |
296 | return -ENOMEM; | |
297 | efx->nic_data = nic_data; | |
298 | ||
75aba2a5 EC |
299 | /* we assume later that we can copy from this buffer in dwords */ |
300 | BUILD_BUG_ON(MCDI_CTL_SDU_LEN_MAX_V2 % 4); | |
301 | ||
8127d661 BH |
302 | rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, |
303 | 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL); | |
304 | if (rc) | |
305 | goto fail1; | |
306 | ||
307 | /* Get the MC's warm boot count. In case it's rebooting right | |
308 | * now, be prepared to retry. | |
309 | */ | |
310 | i = 0; | |
311 | for (;;) { | |
312 | rc = efx_ef10_get_warm_boot_count(efx); | |
313 | if (rc >= 0) | |
314 | break; | |
315 | if (++i == 5) | |
316 | goto fail2; | |
317 | ssleep(1); | |
318 | } | |
319 | nic_data->warm_boot_count = rc; | |
320 | ||
321 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
322 | ||
45b2449e DP |
323 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; |
324 | ||
8127d661 BH |
325 | /* In case we're recovering from a crash (kexec), we want to |
326 | * cancel any outstanding request by the previous user of this | |
327 | * function. We send a special message using the least | |
328 | * significant bits of the 'high' (doorbell) register. | |
329 | */ | |
330 | _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD); | |
331 | ||
332 | rc = efx_mcdi_init(efx); | |
333 | if (rc) | |
334 | goto fail2; | |
335 | ||
336 | /* Reset (most) configuration for this function */ | |
337 | rc = efx_mcdi_reset(efx, RESET_TYPE_ALL); | |
338 | if (rc) | |
339 | goto fail3; | |
340 | ||
341 | /* Enable event logging */ | |
342 | rc = efx_mcdi_log_ctrl(efx, true, false, 0); | |
343 | if (rc) | |
344 | goto fail3; | |
345 | ||
0f5c0845 SS |
346 | rc = device_create_file(&efx->pci_dev->dev, |
347 | &dev_attr_link_control_flag); | |
1cd9ecbb DP |
348 | if (rc) |
349 | goto fail3; | |
350 | ||
0f5c0845 SS |
351 | rc = device_create_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
352 | if (rc) | |
353 | goto fail4; | |
354 | ||
355 | rc = efx_ef10_get_pf_index(efx); | |
356 | if (rc) | |
357 | goto fail5; | |
358 | ||
e5a2538a | 359 | rc = efx_ef10_init_datapath_caps(efx); |
8127d661 | 360 | if (rc < 0) |
0f5c0845 | 361 | goto fail5; |
8127d661 BH |
362 | |
363 | efx->rx_packet_len_offset = | |
364 | ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE; | |
365 | ||
8127d661 BH |
366 | rc = efx_mcdi_port_get_number(efx); |
367 | if (rc < 0) | |
0f5c0845 | 368 | goto fail5; |
8127d661 | 369 | efx->port_num = rc; |
8be41320 | 370 | net_dev->dev_port = rc; |
8127d661 | 371 | |
0d5e0fbb | 372 | rc = efx->type->get_mac_address(efx, efx->net_dev->perm_addr); |
8127d661 | 373 | if (rc) |
0f5c0845 | 374 | goto fail5; |
8127d661 BH |
375 | |
376 | rc = efx_ef10_get_sysclk_freq(efx); | |
377 | if (rc < 0) | |
0f5c0845 | 378 | goto fail5; |
8127d661 BH |
379 | efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */ |
380 | ||
267d9d73 EC |
381 | /* Check whether firmware supports bug 35388 workaround. |
382 | * First try to enable it, then if we get EPERM, just | |
383 | * ask if it's already enabled | |
384 | */ | |
8127d661 | 385 | rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true); |
c9012e00 | 386 | if (rc == 0) { |
8127d661 | 387 | nic_data->workaround_35388 = true; |
c9012e00 | 388 | } else if (rc == -EPERM) { |
267d9d73 EC |
389 | unsigned int enabled; |
390 | ||
391 | rc = efx_mcdi_get_workarounds(efx, NULL, &enabled); | |
392 | if (rc) | |
393 | goto fail3; | |
394 | nic_data->workaround_35388 = enabled & | |
395 | MC_CMD_GET_WORKAROUNDS_OUT_BUG35388; | |
c9012e00 | 396 | } else if (rc != -ENOSYS && rc != -ENOENT) { |
0f5c0845 | 397 | goto fail5; |
c9012e00 | 398 | } |
8127d661 BH |
399 | netif_dbg(efx, probe, efx->net_dev, |
400 | "workaround for bug 35388 is %sabled\n", | |
401 | nic_data->workaround_35388 ? "en" : "dis"); | |
402 | ||
403 | rc = efx_mcdi_mon_probe(efx); | |
267d9d73 | 404 | if (rc && rc != -EPERM) |
0f5c0845 | 405 | goto fail5; |
8127d661 | 406 | |
9aecda95 BH |
407 | efx_ptp_probe(efx, NULL); |
408 | ||
1d051e00 SS |
409 | #ifdef CONFIG_SFC_SRIOV |
410 | if ((efx->pci_dev->physfn) && (!efx->pci_dev->is_physfn)) { | |
411 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; | |
412 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); | |
413 | ||
414 | efx_pf->type->get_mac_address(efx_pf, nic_data->port_id); | |
415 | } else | |
416 | #endif | |
417 | ether_addr_copy(nic_data->port_id, efx->net_dev->perm_addr); | |
418 | ||
8127d661 BH |
419 | return 0; |
420 | ||
0f5c0845 SS |
421 | fail5: |
422 | device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag); | |
423 | fail4: | |
424 | device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag); | |
8127d661 BH |
425 | fail3: |
426 | efx_mcdi_fini(efx); | |
427 | fail2: | |
428 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); | |
429 | fail1: | |
430 | kfree(nic_data); | |
431 | efx->nic_data = NULL; | |
432 | return rc; | |
433 | } | |
434 | ||
435 | static int efx_ef10_free_vis(struct efx_nic *efx) | |
436 | { | |
aa09a3da | 437 | MCDI_DECLARE_BUF_ERR(outbuf); |
1e0b8120 EC |
438 | size_t outlen; |
439 | int rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FREE_VIS, NULL, 0, | |
440 | outbuf, sizeof(outbuf), &outlen); | |
8127d661 BH |
441 | |
442 | /* -EALREADY means nothing to free, so ignore */ | |
443 | if (rc == -EALREADY) | |
444 | rc = 0; | |
1e0b8120 EC |
445 | if (rc) |
446 | efx_mcdi_display_error(efx, MC_CMD_FREE_VIS, 0, outbuf, outlen, | |
447 | rc); | |
8127d661 BH |
448 | return rc; |
449 | } | |
450 | ||
183233be BH |
451 | #ifdef EFX_USE_PIO |
452 | ||
453 | static void efx_ef10_free_piobufs(struct efx_nic *efx) | |
454 | { | |
455 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
456 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FREE_PIOBUF_IN_LEN); | |
457 | unsigned int i; | |
458 | int rc; | |
459 | ||
460 | BUILD_BUG_ON(MC_CMD_FREE_PIOBUF_OUT_LEN != 0); | |
461 | ||
462 | for (i = 0; i < nic_data->n_piobufs; i++) { | |
463 | MCDI_SET_DWORD(inbuf, FREE_PIOBUF_IN_PIOBUF_HANDLE, | |
464 | nic_data->piobuf_handle[i]); | |
465 | rc = efx_mcdi_rpc(efx, MC_CMD_FREE_PIOBUF, inbuf, sizeof(inbuf), | |
466 | NULL, 0, NULL); | |
467 | WARN_ON(rc); | |
468 | } | |
469 | ||
470 | nic_data->n_piobufs = 0; | |
471 | } | |
472 | ||
473 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) | |
474 | { | |
475 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
476 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_PIOBUF_OUT_LEN); | |
477 | unsigned int i; | |
478 | size_t outlen; | |
479 | int rc = 0; | |
480 | ||
481 | BUILD_BUG_ON(MC_CMD_ALLOC_PIOBUF_IN_LEN != 0); | |
482 | ||
483 | for (i = 0; i < n; i++) { | |
484 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_PIOBUF, NULL, 0, | |
485 | outbuf, sizeof(outbuf), &outlen); | |
486 | if (rc) | |
487 | break; | |
488 | if (outlen < MC_CMD_ALLOC_PIOBUF_OUT_LEN) { | |
489 | rc = -EIO; | |
490 | break; | |
491 | } | |
492 | nic_data->piobuf_handle[i] = | |
493 | MCDI_DWORD(outbuf, ALLOC_PIOBUF_OUT_PIOBUF_HANDLE); | |
494 | netif_dbg(efx, probe, efx->net_dev, | |
495 | "allocated PIO buffer %u handle %x\n", i, | |
496 | nic_data->piobuf_handle[i]); | |
497 | } | |
498 | ||
499 | nic_data->n_piobufs = i; | |
500 | if (rc) | |
501 | efx_ef10_free_piobufs(efx); | |
502 | return rc; | |
503 | } | |
504 | ||
505 | static int efx_ef10_link_piobufs(struct efx_nic *efx) | |
506 | { | |
507 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
aa09a3da JC |
508 | _MCDI_DECLARE_BUF(inbuf, |
509 | max(MC_CMD_LINK_PIOBUF_IN_LEN, | |
510 | MC_CMD_UNLINK_PIOBUF_IN_LEN)); | |
183233be BH |
511 | struct efx_channel *channel; |
512 | struct efx_tx_queue *tx_queue; | |
513 | unsigned int offset, index; | |
514 | int rc; | |
515 | ||
516 | BUILD_BUG_ON(MC_CMD_LINK_PIOBUF_OUT_LEN != 0); | |
517 | BUILD_BUG_ON(MC_CMD_UNLINK_PIOBUF_OUT_LEN != 0); | |
518 | ||
aa09a3da JC |
519 | memset(inbuf, 0, sizeof(inbuf)); |
520 | ||
183233be BH |
521 | /* Link a buffer to each VI in the write-combining mapping */ |
522 | for (index = 0; index < nic_data->n_piobufs; ++index) { | |
523 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_PIOBUF_HANDLE, | |
524 | nic_data->piobuf_handle[index]); | |
525 | MCDI_SET_DWORD(inbuf, LINK_PIOBUF_IN_TXQ_INSTANCE, | |
526 | nic_data->pio_write_vi_base + index); | |
527 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, | |
528 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, | |
529 | NULL, 0, NULL); | |
530 | if (rc) { | |
531 | netif_err(efx, drv, efx->net_dev, | |
532 | "failed to link VI %u to PIO buffer %u (%d)\n", | |
533 | nic_data->pio_write_vi_base + index, index, | |
534 | rc); | |
535 | goto fail; | |
536 | } | |
537 | netif_dbg(efx, probe, efx->net_dev, | |
538 | "linked VI %u to PIO buffer %u\n", | |
539 | nic_data->pio_write_vi_base + index, index); | |
540 | } | |
541 | ||
542 | /* Link a buffer to each TX queue */ | |
543 | efx_for_each_channel(channel, efx) { | |
544 | efx_for_each_channel_tx_queue(tx_queue, channel) { | |
545 | /* We assign the PIO buffers to queues in | |
546 | * reverse order to allow for the following | |
547 | * special case. | |
548 | */ | |
549 | offset = ((efx->tx_channel_offset + efx->n_tx_channels - | |
550 | tx_queue->channel->channel - 1) * | |
551 | efx_piobuf_size); | |
552 | index = offset / ER_DZ_TX_PIOBUF_SIZE; | |
553 | offset = offset % ER_DZ_TX_PIOBUF_SIZE; | |
554 | ||
555 | /* When the host page size is 4K, the first | |
556 | * host page in the WC mapping may be within | |
557 | * the same VI page as the last TX queue. We | |
558 | * can only link one buffer to each VI. | |
559 | */ | |
560 | if (tx_queue->queue == nic_data->pio_write_vi_base) { | |
561 | BUG_ON(index != 0); | |
562 | rc = 0; | |
563 | } else { | |
564 | MCDI_SET_DWORD(inbuf, | |
565 | LINK_PIOBUF_IN_PIOBUF_HANDLE, | |
566 | nic_data->piobuf_handle[index]); | |
567 | MCDI_SET_DWORD(inbuf, | |
568 | LINK_PIOBUF_IN_TXQ_INSTANCE, | |
569 | tx_queue->queue); | |
570 | rc = efx_mcdi_rpc(efx, MC_CMD_LINK_PIOBUF, | |
571 | inbuf, MC_CMD_LINK_PIOBUF_IN_LEN, | |
572 | NULL, 0, NULL); | |
573 | } | |
574 | ||
575 | if (rc) { | |
576 | /* This is non-fatal; the TX path just | |
577 | * won't use PIO for this queue | |
578 | */ | |
579 | netif_err(efx, drv, efx->net_dev, | |
580 | "failed to link VI %u to PIO buffer %u (%d)\n", | |
581 | tx_queue->queue, index, rc); | |
582 | tx_queue->piobuf = NULL; | |
583 | } else { | |
584 | tx_queue->piobuf = | |
585 | nic_data->pio_write_base + | |
586 | index * EFX_VI_PAGE_SIZE + offset; | |
587 | tx_queue->piobuf_offset = offset; | |
588 | netif_dbg(efx, probe, efx->net_dev, | |
589 | "linked VI %u to PIO buffer %u offset %x addr %p\n", | |
590 | tx_queue->queue, index, | |
591 | tx_queue->piobuf_offset, | |
592 | tx_queue->piobuf); | |
593 | } | |
594 | } | |
595 | } | |
596 | ||
597 | return 0; | |
598 | ||
599 | fail: | |
600 | while (index--) { | |
601 | MCDI_SET_DWORD(inbuf, UNLINK_PIOBUF_IN_TXQ_INSTANCE, | |
602 | nic_data->pio_write_vi_base + index); | |
603 | efx_mcdi_rpc(efx, MC_CMD_UNLINK_PIOBUF, | |
604 | inbuf, MC_CMD_UNLINK_PIOBUF_IN_LEN, | |
605 | NULL, 0, NULL); | |
606 | } | |
607 | return rc; | |
608 | } | |
609 | ||
610 | #else /* !EFX_USE_PIO */ | |
611 | ||
612 | static int efx_ef10_alloc_piobufs(struct efx_nic *efx, unsigned int n) | |
613 | { | |
614 | return n == 0 ? 0 : -ENOBUFS; | |
615 | } | |
616 | ||
617 | static int efx_ef10_link_piobufs(struct efx_nic *efx) | |
618 | { | |
619 | return 0; | |
620 | } | |
621 | ||
622 | static void efx_ef10_free_piobufs(struct efx_nic *efx) | |
623 | { | |
624 | } | |
625 | ||
626 | #endif /* EFX_USE_PIO */ | |
627 | ||
8127d661 BH |
628 | static void efx_ef10_remove(struct efx_nic *efx) |
629 | { | |
630 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
631 | int rc; | |
632 | ||
f1122a34 SS |
633 | #ifdef CONFIG_SFC_SRIOV |
634 | struct efx_ef10_nic_data *nic_data_pf; | |
635 | struct pci_dev *pci_dev_pf; | |
636 | struct efx_nic *efx_pf; | |
637 | struct ef10_vf *vf; | |
638 | ||
639 | if (efx->pci_dev->is_virtfn) { | |
640 | pci_dev_pf = efx->pci_dev->physfn; | |
641 | if (pci_dev_pf) { | |
642 | efx_pf = pci_get_drvdata(pci_dev_pf); | |
643 | nic_data_pf = efx_pf->nic_data; | |
644 | vf = nic_data_pf->vf + nic_data->vf_index; | |
645 | vf->efx = NULL; | |
646 | } else | |
647 | netif_info(efx, drv, efx->net_dev, | |
648 | "Could not get the PF id from VF\n"); | |
649 | } | |
650 | #endif | |
651 | ||
9aecda95 BH |
652 | efx_ptp_remove(efx); |
653 | ||
8127d661 BH |
654 | efx_mcdi_mon_remove(efx); |
655 | ||
8127d661 BH |
656 | efx_ef10_rx_free_indir_table(efx); |
657 | ||
183233be BH |
658 | if (nic_data->wc_membase) |
659 | iounmap(nic_data->wc_membase); | |
660 | ||
8127d661 BH |
661 | rc = efx_ef10_free_vis(efx); |
662 | WARN_ON(rc != 0); | |
663 | ||
183233be BH |
664 | if (!nic_data->must_restore_piobufs) |
665 | efx_ef10_free_piobufs(efx); | |
666 | ||
0f5c0845 SS |
667 | device_remove_file(&efx->pci_dev->dev, &dev_attr_primary_flag); |
668 | device_remove_file(&efx->pci_dev->dev, &dev_attr_link_control_flag); | |
669 | ||
8127d661 BH |
670 | efx_mcdi_fini(efx); |
671 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); | |
672 | kfree(nic_data); | |
673 | } | |
674 | ||
88a37de6 SS |
675 | static int efx_ef10_probe_pf(struct efx_nic *efx) |
676 | { | |
677 | return efx_ef10_probe(efx); | |
678 | } | |
679 | ||
680 | #ifdef CONFIG_SFC_SRIOV | |
681 | static int efx_ef10_probe_vf(struct efx_nic *efx) | |
682 | { | |
683 | int rc; | |
684 | ||
685 | rc = efx_ef10_probe(efx); | |
686 | if (rc) | |
687 | return rc; | |
688 | ||
689 | rc = efx_ef10_get_vf_index(efx); | |
690 | if (rc) | |
691 | goto fail; | |
692 | ||
f1122a34 SS |
693 | if (efx->pci_dev->is_virtfn) { |
694 | if (efx->pci_dev->physfn) { | |
695 | struct efx_nic *efx_pf = | |
696 | pci_get_drvdata(efx->pci_dev->physfn); | |
697 | struct efx_ef10_nic_data *nic_data_p = efx_pf->nic_data; | |
698 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
699 | ||
700 | nic_data_p->vf[nic_data->vf_index].efx = efx; | |
701 | } else | |
702 | netif_info(efx, drv, efx->net_dev, | |
703 | "Could not get the PF id from VF\n"); | |
704 | } | |
705 | ||
88a37de6 SS |
706 | return 0; |
707 | ||
708 | fail: | |
709 | efx_ef10_remove(efx); | |
710 | return rc; | |
711 | } | |
712 | #else | |
713 | static int efx_ef10_probe_vf(struct efx_nic *efx __attribute__ ((unused))) | |
714 | { | |
715 | return 0; | |
716 | } | |
717 | #endif | |
718 | ||
8127d661 BH |
719 | static int efx_ef10_alloc_vis(struct efx_nic *efx, |
720 | unsigned int min_vis, unsigned int max_vis) | |
721 | { | |
722 | MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN); | |
723 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN); | |
724 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
725 | size_t outlen; | |
726 | int rc; | |
727 | ||
728 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis); | |
729 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis); | |
730 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf), | |
731 | outbuf, sizeof(outbuf), &outlen); | |
732 | if (rc != 0) | |
733 | return rc; | |
734 | ||
735 | if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN) | |
736 | return -EIO; | |
737 | ||
738 | netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n", | |
739 | MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE)); | |
740 | ||
741 | nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE); | |
742 | nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT); | |
743 | return 0; | |
744 | } | |
745 | ||
183233be BH |
746 | /* Note that the failure path of this function does not free |
747 | * resources, as this will be done by efx_ef10_remove(). | |
748 | */ | |
8127d661 BH |
749 | static int efx_ef10_dimension_resources(struct efx_nic *efx) |
750 | { | |
183233be BH |
751 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
752 | unsigned int uc_mem_map_size, wc_mem_map_size; | |
753 | unsigned int min_vis, pio_write_vi_base, max_vis; | |
754 | void __iomem *membase; | |
755 | int rc; | |
756 | ||
757 | min_vis = max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES); | |
8127d661 | 758 | |
183233be BH |
759 | #ifdef EFX_USE_PIO |
760 | /* Try to allocate PIO buffers if wanted and if the full | |
761 | * number of PIO buffers would be sufficient to allocate one | |
762 | * copy-buffer per TX channel. Failure is non-fatal, as there | |
763 | * are only a small number of PIO buffers shared between all | |
764 | * functions of the controller. | |
765 | */ | |
766 | if (efx_piobuf_size != 0 && | |
767 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size * EF10_TX_PIOBUF_COUNT >= | |
768 | efx->n_tx_channels) { | |
769 | unsigned int n_piobufs = | |
770 | DIV_ROUND_UP(efx->n_tx_channels, | |
771 | ER_DZ_TX_PIOBUF_SIZE / efx_piobuf_size); | |
772 | ||
773 | rc = efx_ef10_alloc_piobufs(efx, n_piobufs); | |
774 | if (rc) | |
775 | netif_err(efx, probe, efx->net_dev, | |
776 | "failed to allocate PIO buffers (%d)\n", rc); | |
777 | else | |
778 | netif_dbg(efx, probe, efx->net_dev, | |
779 | "allocated %u PIO buffers\n", n_piobufs); | |
780 | } | |
781 | #else | |
782 | nic_data->n_piobufs = 0; | |
783 | #endif | |
784 | ||
785 | /* PIO buffers should be mapped with write-combining enabled, | |
786 | * and we want to make single UC and WC mappings rather than | |
787 | * several of each (in fact that's the only option if host | |
788 | * page size is >4K). So we may allocate some extra VIs just | |
789 | * for writing PIO buffers through. | |
52ad762b DP |
790 | * |
791 | * The UC mapping contains (min_vis - 1) complete VIs and the | |
792 | * first half of the next VI. Then the WC mapping begins with | |
793 | * the second half of this last VI. | |
183233be BH |
794 | */ |
795 | uc_mem_map_size = PAGE_ALIGN((min_vis - 1) * EFX_VI_PAGE_SIZE + | |
796 | ER_DZ_TX_PIOBUF); | |
797 | if (nic_data->n_piobufs) { | |
52ad762b DP |
798 | /* pio_write_vi_base rounds down to give the number of complete |
799 | * VIs inside the UC mapping. | |
800 | */ | |
183233be BH |
801 | pio_write_vi_base = uc_mem_map_size / EFX_VI_PAGE_SIZE; |
802 | wc_mem_map_size = (PAGE_ALIGN((pio_write_vi_base + | |
803 | nic_data->n_piobufs) * | |
804 | EFX_VI_PAGE_SIZE) - | |
805 | uc_mem_map_size); | |
806 | max_vis = pio_write_vi_base + nic_data->n_piobufs; | |
807 | } else { | |
808 | pio_write_vi_base = 0; | |
809 | wc_mem_map_size = 0; | |
810 | max_vis = min_vis; | |
811 | } | |
812 | ||
813 | /* In case the last attached driver failed to free VIs, do it now */ | |
814 | rc = efx_ef10_free_vis(efx); | |
815 | if (rc != 0) | |
816 | return rc; | |
817 | ||
818 | rc = efx_ef10_alloc_vis(efx, min_vis, max_vis); | |
819 | if (rc != 0) | |
820 | return rc; | |
821 | ||
822 | /* If we didn't get enough VIs to map all the PIO buffers, free the | |
823 | * PIO buffers | |
824 | */ | |
825 | if (nic_data->n_piobufs && | |
826 | nic_data->n_allocated_vis < | |
827 | pio_write_vi_base + nic_data->n_piobufs) { | |
828 | netif_dbg(efx, probe, efx->net_dev, | |
829 | "%u VIs are not sufficient to map %u PIO buffers\n", | |
830 | nic_data->n_allocated_vis, nic_data->n_piobufs); | |
831 | efx_ef10_free_piobufs(efx); | |
832 | } | |
833 | ||
834 | /* Shrink the original UC mapping of the memory BAR */ | |
835 | membase = ioremap_nocache(efx->membase_phys, uc_mem_map_size); | |
836 | if (!membase) { | |
837 | netif_err(efx, probe, efx->net_dev, | |
838 | "could not shrink memory BAR to %x\n", | |
839 | uc_mem_map_size); | |
840 | return -ENOMEM; | |
841 | } | |
842 | iounmap(efx->membase); | |
843 | efx->membase = membase; | |
844 | ||
845 | /* Set up the WC mapping if needed */ | |
846 | if (wc_mem_map_size) { | |
847 | nic_data->wc_membase = ioremap_wc(efx->membase_phys + | |
848 | uc_mem_map_size, | |
849 | wc_mem_map_size); | |
850 | if (!nic_data->wc_membase) { | |
851 | netif_err(efx, probe, efx->net_dev, | |
852 | "could not allocate WC mapping of size %x\n", | |
853 | wc_mem_map_size); | |
854 | return -ENOMEM; | |
855 | } | |
856 | nic_data->pio_write_vi_base = pio_write_vi_base; | |
857 | nic_data->pio_write_base = | |
858 | nic_data->wc_membase + | |
859 | (pio_write_vi_base * EFX_VI_PAGE_SIZE + ER_DZ_TX_PIOBUF - | |
860 | uc_mem_map_size); | |
861 | ||
862 | rc = efx_ef10_link_piobufs(efx); | |
863 | if (rc) | |
864 | efx_ef10_free_piobufs(efx); | |
865 | } | |
866 | ||
867 | netif_dbg(efx, probe, efx->net_dev, | |
868 | "memory BAR at %pa (virtual %p+%x UC, %p+%x WC)\n", | |
869 | &efx->membase_phys, efx->membase, uc_mem_map_size, | |
870 | nic_data->wc_membase, wc_mem_map_size); | |
871 | ||
872 | return 0; | |
8127d661 BH |
873 | } |
874 | ||
875 | static int efx_ef10_init_nic(struct efx_nic *efx) | |
876 | { | |
877 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
878 | int rc; | |
879 | ||
a915ccc9 BH |
880 | if (nic_data->must_check_datapath_caps) { |
881 | rc = efx_ef10_init_datapath_caps(efx); | |
882 | if (rc) | |
883 | return rc; | |
884 | nic_data->must_check_datapath_caps = false; | |
885 | } | |
886 | ||
8127d661 BH |
887 | if (nic_data->must_realloc_vis) { |
888 | /* We cannot let the number of VIs change now */ | |
889 | rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis, | |
890 | nic_data->n_allocated_vis); | |
891 | if (rc) | |
892 | return rc; | |
893 | nic_data->must_realloc_vis = false; | |
894 | } | |
895 | ||
183233be BH |
896 | if (nic_data->must_restore_piobufs && nic_data->n_piobufs) { |
897 | rc = efx_ef10_alloc_piobufs(efx, nic_data->n_piobufs); | |
898 | if (rc == 0) { | |
899 | rc = efx_ef10_link_piobufs(efx); | |
900 | if (rc) | |
901 | efx_ef10_free_piobufs(efx); | |
902 | } | |
903 | ||
904 | /* Log an error on failure, but this is non-fatal */ | |
905 | if (rc) | |
906 | netif_err(efx, drv, efx->net_dev, | |
907 | "failed to restore PIO buffers (%d)\n", rc); | |
908 | nic_data->must_restore_piobufs = false; | |
909 | } | |
910 | ||
267c0157 JC |
911 | /* don't fail init if RSS setup doesn't work */ |
912 | efx->type->rx_push_rss_config(efx, false, efx->rx_indir_table); | |
913 | ||
8127d661 BH |
914 | return 0; |
915 | } | |
916 | ||
3e336261 JC |
917 | static void efx_ef10_reset_mc_allocations(struct efx_nic *efx) |
918 | { | |
919 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
920 | ||
921 | /* All our allocations have been reset */ | |
922 | nic_data->must_realloc_vis = true; | |
923 | nic_data->must_restore_filters = true; | |
924 | nic_data->must_restore_piobufs = true; | |
925 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
926 | } | |
927 | ||
087e9025 JC |
928 | static enum reset_type efx_ef10_map_reset_reason(enum reset_type reason) |
929 | { | |
930 | if (reason == RESET_TYPE_MC_FAILURE) | |
931 | return RESET_TYPE_DATAPATH; | |
932 | ||
933 | return efx_mcdi_map_reset_reason(reason); | |
934 | } | |
935 | ||
8127d661 BH |
936 | static int efx_ef10_map_reset_flags(u32 *flags) |
937 | { | |
938 | enum { | |
939 | EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) << | |
940 | ETH_RESET_SHARED_SHIFT), | |
941 | EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER | | |
942 | ETH_RESET_OFFLOAD | ETH_RESET_MAC | | |
943 | ETH_RESET_PHY | ETH_RESET_MGMT) << | |
944 | ETH_RESET_SHARED_SHIFT) | |
945 | }; | |
946 | ||
947 | /* We assume for now that our PCI function is permitted to | |
948 | * reset everything. | |
949 | */ | |
950 | ||
951 | if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) { | |
952 | *flags &= ~EF10_RESET_MC; | |
953 | return RESET_TYPE_WORLD; | |
954 | } | |
955 | ||
956 | if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) { | |
957 | *flags &= ~EF10_RESET_PORT; | |
958 | return RESET_TYPE_ALL; | |
959 | } | |
960 | ||
961 | /* no invisible reset implemented */ | |
962 | ||
963 | return -EINVAL; | |
964 | } | |
965 | ||
3e336261 JC |
966 | static int efx_ef10_reset(struct efx_nic *efx, enum reset_type reset_type) |
967 | { | |
968 | int rc = efx_mcdi_reset(efx, reset_type); | |
969 | ||
970 | /* If it was a port reset, trigger reallocation of MC resources. | |
971 | * Note that on an MC reset nothing needs to be done now because we'll | |
972 | * detect the MC reset later and handle it then. | |
e283546c EC |
973 | * For an FLR, we never get an MC reset event, but the MC has reset all |
974 | * resources assigned to us, so we have to trigger reallocation now. | |
3e336261 | 975 | */ |
e283546c EC |
976 | if ((reset_type == RESET_TYPE_ALL || |
977 | reset_type == RESET_TYPE_MCDI_TIMEOUT) && !rc) | |
3e336261 JC |
978 | efx_ef10_reset_mc_allocations(efx); |
979 | return rc; | |
980 | } | |
981 | ||
8127d661 BH |
982 | #define EF10_DMA_STAT(ext_name, mcdi_name) \ |
983 | [EF10_STAT_ ## ext_name] = \ | |
984 | { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name } | |
985 | #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \ | |
986 | [EF10_STAT_ ## int_name] = \ | |
987 | { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name } | |
988 | #define EF10_OTHER_STAT(ext_name) \ | |
989 | [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 } | |
e4d112e4 EC |
990 | #define GENERIC_SW_STAT(ext_name) \ |
991 | [GENERIC_STAT_ ## ext_name] = { #ext_name, 0, 0 } | |
8127d661 BH |
992 | |
993 | static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = { | |
e80ca013 DP |
994 | EF10_DMA_STAT(port_tx_bytes, TX_BYTES), |
995 | EF10_DMA_STAT(port_tx_packets, TX_PKTS), | |
996 | EF10_DMA_STAT(port_tx_pause, TX_PAUSE_PKTS), | |
997 | EF10_DMA_STAT(port_tx_control, TX_CONTROL_PKTS), | |
998 | EF10_DMA_STAT(port_tx_unicast, TX_UNICAST_PKTS), | |
999 | EF10_DMA_STAT(port_tx_multicast, TX_MULTICAST_PKTS), | |
1000 | EF10_DMA_STAT(port_tx_broadcast, TX_BROADCAST_PKTS), | |
1001 | EF10_DMA_STAT(port_tx_lt64, TX_LT64_PKTS), | |
1002 | EF10_DMA_STAT(port_tx_64, TX_64_PKTS), | |
1003 | EF10_DMA_STAT(port_tx_65_to_127, TX_65_TO_127_PKTS), | |
1004 | EF10_DMA_STAT(port_tx_128_to_255, TX_128_TO_255_PKTS), | |
1005 | EF10_DMA_STAT(port_tx_256_to_511, TX_256_TO_511_PKTS), | |
1006 | EF10_DMA_STAT(port_tx_512_to_1023, TX_512_TO_1023_PKTS), | |
1007 | EF10_DMA_STAT(port_tx_1024_to_15xx, TX_1024_TO_15XX_PKTS), | |
1008 | EF10_DMA_STAT(port_tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS), | |
1009 | EF10_DMA_STAT(port_rx_bytes, RX_BYTES), | |
1010 | EF10_DMA_INVIS_STAT(port_rx_bytes_minus_good_bytes, RX_BAD_BYTES), | |
1011 | EF10_OTHER_STAT(port_rx_good_bytes), | |
1012 | EF10_OTHER_STAT(port_rx_bad_bytes), | |
1013 | EF10_DMA_STAT(port_rx_packets, RX_PKTS), | |
1014 | EF10_DMA_STAT(port_rx_good, RX_GOOD_PKTS), | |
1015 | EF10_DMA_STAT(port_rx_bad, RX_BAD_FCS_PKTS), | |
1016 | EF10_DMA_STAT(port_rx_pause, RX_PAUSE_PKTS), | |
1017 | EF10_DMA_STAT(port_rx_control, RX_CONTROL_PKTS), | |
1018 | EF10_DMA_STAT(port_rx_unicast, RX_UNICAST_PKTS), | |
1019 | EF10_DMA_STAT(port_rx_multicast, RX_MULTICAST_PKTS), | |
1020 | EF10_DMA_STAT(port_rx_broadcast, RX_BROADCAST_PKTS), | |
1021 | EF10_DMA_STAT(port_rx_lt64, RX_UNDERSIZE_PKTS), | |
1022 | EF10_DMA_STAT(port_rx_64, RX_64_PKTS), | |
1023 | EF10_DMA_STAT(port_rx_65_to_127, RX_65_TO_127_PKTS), | |
1024 | EF10_DMA_STAT(port_rx_128_to_255, RX_128_TO_255_PKTS), | |
1025 | EF10_DMA_STAT(port_rx_256_to_511, RX_256_TO_511_PKTS), | |
1026 | EF10_DMA_STAT(port_rx_512_to_1023, RX_512_TO_1023_PKTS), | |
1027 | EF10_DMA_STAT(port_rx_1024_to_15xx, RX_1024_TO_15XX_PKTS), | |
1028 | EF10_DMA_STAT(port_rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS), | |
1029 | EF10_DMA_STAT(port_rx_gtjumbo, RX_GTJUMBO_PKTS), | |
1030 | EF10_DMA_STAT(port_rx_bad_gtjumbo, RX_JABBER_PKTS), | |
1031 | EF10_DMA_STAT(port_rx_overflow, RX_OVERFLOW_PKTS), | |
1032 | EF10_DMA_STAT(port_rx_align_error, RX_ALIGN_ERROR_PKTS), | |
1033 | EF10_DMA_STAT(port_rx_length_error, RX_LENGTH_ERROR_PKTS), | |
1034 | EF10_DMA_STAT(port_rx_nodesc_drops, RX_NODESC_DROPS), | |
e4d112e4 EC |
1035 | GENERIC_SW_STAT(rx_nodesc_trunc), |
1036 | GENERIC_SW_STAT(rx_noskb_drops), | |
e80ca013 DP |
1037 | EF10_DMA_STAT(port_rx_pm_trunc_bb_overflow, PM_TRUNC_BB_OVERFLOW), |
1038 | EF10_DMA_STAT(port_rx_pm_discard_bb_overflow, PM_DISCARD_BB_OVERFLOW), | |
1039 | EF10_DMA_STAT(port_rx_pm_trunc_vfifo_full, PM_TRUNC_VFIFO_FULL), | |
1040 | EF10_DMA_STAT(port_rx_pm_discard_vfifo_full, PM_DISCARD_VFIFO_FULL), | |
1041 | EF10_DMA_STAT(port_rx_pm_trunc_qbb, PM_TRUNC_QBB), | |
1042 | EF10_DMA_STAT(port_rx_pm_discard_qbb, PM_DISCARD_QBB), | |
1043 | EF10_DMA_STAT(port_rx_pm_discard_mapping, PM_DISCARD_MAPPING), | |
1044 | EF10_DMA_STAT(port_rx_dp_q_disabled_packets, RXDP_Q_DISABLED_PKTS), | |
1045 | EF10_DMA_STAT(port_rx_dp_di_dropped_packets, RXDP_DI_DROPPED_PKTS), | |
1046 | EF10_DMA_STAT(port_rx_dp_streaming_packets, RXDP_STREAMING_PKTS), | |
1047 | EF10_DMA_STAT(port_rx_dp_hlb_fetch, RXDP_HLB_FETCH_CONDITIONS), | |
1048 | EF10_DMA_STAT(port_rx_dp_hlb_wait, RXDP_HLB_WAIT_CONDITIONS), | |
3c36a2ad DP |
1049 | EF10_DMA_STAT(rx_unicast, VADAPTER_RX_UNICAST_PACKETS), |
1050 | EF10_DMA_STAT(rx_unicast_bytes, VADAPTER_RX_UNICAST_BYTES), | |
1051 | EF10_DMA_STAT(rx_multicast, VADAPTER_RX_MULTICAST_PACKETS), | |
1052 | EF10_DMA_STAT(rx_multicast_bytes, VADAPTER_RX_MULTICAST_BYTES), | |
1053 | EF10_DMA_STAT(rx_broadcast, VADAPTER_RX_BROADCAST_PACKETS), | |
1054 | EF10_DMA_STAT(rx_broadcast_bytes, VADAPTER_RX_BROADCAST_BYTES), | |
1055 | EF10_DMA_STAT(rx_bad, VADAPTER_RX_BAD_PACKETS), | |
1056 | EF10_DMA_STAT(rx_bad_bytes, VADAPTER_RX_BAD_BYTES), | |
1057 | EF10_DMA_STAT(rx_overflow, VADAPTER_RX_OVERFLOW), | |
1058 | EF10_DMA_STAT(tx_unicast, VADAPTER_TX_UNICAST_PACKETS), | |
1059 | EF10_DMA_STAT(tx_unicast_bytes, VADAPTER_TX_UNICAST_BYTES), | |
1060 | EF10_DMA_STAT(tx_multicast, VADAPTER_TX_MULTICAST_PACKETS), | |
1061 | EF10_DMA_STAT(tx_multicast_bytes, VADAPTER_TX_MULTICAST_BYTES), | |
1062 | EF10_DMA_STAT(tx_broadcast, VADAPTER_TX_BROADCAST_PACKETS), | |
1063 | EF10_DMA_STAT(tx_broadcast_bytes, VADAPTER_TX_BROADCAST_BYTES), | |
1064 | EF10_DMA_STAT(tx_bad, VADAPTER_TX_BAD_PACKETS), | |
1065 | EF10_DMA_STAT(tx_bad_bytes, VADAPTER_TX_BAD_BYTES), | |
1066 | EF10_DMA_STAT(tx_overflow, VADAPTER_TX_OVERFLOW), | |
8127d661 BH |
1067 | }; |
1068 | ||
e80ca013 DP |
1069 | #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_port_tx_bytes) | \ |
1070 | (1ULL << EF10_STAT_port_tx_packets) | \ | |
1071 | (1ULL << EF10_STAT_port_tx_pause) | \ | |
1072 | (1ULL << EF10_STAT_port_tx_unicast) | \ | |
1073 | (1ULL << EF10_STAT_port_tx_multicast) | \ | |
1074 | (1ULL << EF10_STAT_port_tx_broadcast) | \ | |
1075 | (1ULL << EF10_STAT_port_rx_bytes) | \ | |
1076 | (1ULL << \ | |
1077 | EF10_STAT_port_rx_bytes_minus_good_bytes) | \ | |
1078 | (1ULL << EF10_STAT_port_rx_good_bytes) | \ | |
1079 | (1ULL << EF10_STAT_port_rx_bad_bytes) | \ | |
1080 | (1ULL << EF10_STAT_port_rx_packets) | \ | |
1081 | (1ULL << EF10_STAT_port_rx_good) | \ | |
1082 | (1ULL << EF10_STAT_port_rx_bad) | \ | |
1083 | (1ULL << EF10_STAT_port_rx_pause) | \ | |
1084 | (1ULL << EF10_STAT_port_rx_control) | \ | |
1085 | (1ULL << EF10_STAT_port_rx_unicast) | \ | |
1086 | (1ULL << EF10_STAT_port_rx_multicast) | \ | |
1087 | (1ULL << EF10_STAT_port_rx_broadcast) | \ | |
1088 | (1ULL << EF10_STAT_port_rx_lt64) | \ | |
1089 | (1ULL << EF10_STAT_port_rx_64) | \ | |
1090 | (1ULL << EF10_STAT_port_rx_65_to_127) | \ | |
1091 | (1ULL << EF10_STAT_port_rx_128_to_255) | \ | |
1092 | (1ULL << EF10_STAT_port_rx_256_to_511) | \ | |
1093 | (1ULL << EF10_STAT_port_rx_512_to_1023) |\ | |
1094 | (1ULL << EF10_STAT_port_rx_1024_to_15xx) |\ | |
1095 | (1ULL << EF10_STAT_port_rx_15xx_to_jumbo) |\ | |
1096 | (1ULL << EF10_STAT_port_rx_gtjumbo) | \ | |
1097 | (1ULL << EF10_STAT_port_rx_bad_gtjumbo) |\ | |
1098 | (1ULL << EF10_STAT_port_rx_overflow) | \ | |
1099 | (1ULL << EF10_STAT_port_rx_nodesc_drops) |\ | |
e4d112e4 EC |
1100 | (1ULL << GENERIC_STAT_rx_nodesc_trunc) | \ |
1101 | (1ULL << GENERIC_STAT_rx_noskb_drops)) | |
8127d661 BH |
1102 | |
1103 | /* These statistics are only provided by the 10G MAC. For a 10G/40G | |
1104 | * switchable port we do not expose these because they might not | |
1105 | * include all the packets they should. | |
1106 | */ | |
e80ca013 DP |
1107 | #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_port_tx_control) | \ |
1108 | (1ULL << EF10_STAT_port_tx_lt64) | \ | |
1109 | (1ULL << EF10_STAT_port_tx_64) | \ | |
1110 | (1ULL << EF10_STAT_port_tx_65_to_127) |\ | |
1111 | (1ULL << EF10_STAT_port_tx_128_to_255) |\ | |
1112 | (1ULL << EF10_STAT_port_tx_256_to_511) |\ | |
1113 | (1ULL << EF10_STAT_port_tx_512_to_1023) |\ | |
1114 | (1ULL << EF10_STAT_port_tx_1024_to_15xx) |\ | |
1115 | (1ULL << EF10_STAT_port_tx_15xx_to_jumbo)) | |
8127d661 BH |
1116 | |
1117 | /* These statistics are only provided by the 40G MAC. For a 10G/40G | |
1118 | * switchable port we do expose these because the errors will otherwise | |
1119 | * be silent. | |
1120 | */ | |
e80ca013 DP |
1121 | #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_port_rx_align_error) |\ |
1122 | (1ULL << EF10_STAT_port_rx_length_error)) | |
8127d661 | 1123 | |
568d7a00 EC |
1124 | /* These statistics are only provided if the firmware supports the |
1125 | * capability PM_AND_RXDP_COUNTERS. | |
1126 | */ | |
1127 | #define HUNT_PM_AND_RXDP_STAT_MASK ( \ | |
e80ca013 DP |
1128 | (1ULL << EF10_STAT_port_rx_pm_trunc_bb_overflow) | \ |
1129 | (1ULL << EF10_STAT_port_rx_pm_discard_bb_overflow) | \ | |
1130 | (1ULL << EF10_STAT_port_rx_pm_trunc_vfifo_full) | \ | |
1131 | (1ULL << EF10_STAT_port_rx_pm_discard_vfifo_full) | \ | |
1132 | (1ULL << EF10_STAT_port_rx_pm_trunc_qbb) | \ | |
1133 | (1ULL << EF10_STAT_port_rx_pm_discard_qbb) | \ | |
1134 | (1ULL << EF10_STAT_port_rx_pm_discard_mapping) | \ | |
1135 | (1ULL << EF10_STAT_port_rx_dp_q_disabled_packets) | \ | |
1136 | (1ULL << EF10_STAT_port_rx_dp_di_dropped_packets) | \ | |
1137 | (1ULL << EF10_STAT_port_rx_dp_streaming_packets) | \ | |
1138 | (1ULL << EF10_STAT_port_rx_dp_hlb_fetch) | \ | |
1139 | (1ULL << EF10_STAT_port_rx_dp_hlb_wait)) | |
568d7a00 | 1140 | |
4bae913b | 1141 | static u64 efx_ef10_raw_stat_mask(struct efx_nic *efx) |
8127d661 | 1142 | { |
4bae913b | 1143 | u64 raw_mask = HUNT_COMMON_STAT_MASK; |
8127d661 | 1144 | u32 port_caps = efx_mcdi_phy_get_caps(efx); |
568d7a00 | 1145 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
8127d661 | 1146 | |
3c36a2ad DP |
1147 | if (!(efx->mcdi->fn_flags & |
1148 | 1 << MC_CMD_DRV_ATTACH_EXT_OUT_FLAG_LINKCTRL)) | |
1149 | return 0; | |
1150 | ||
8127d661 | 1151 | if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) |
4bae913b | 1152 | raw_mask |= HUNT_40G_EXTRA_STAT_MASK; |
8127d661 | 1153 | else |
4bae913b | 1154 | raw_mask |= HUNT_10G_ONLY_STAT_MASK; |
568d7a00 EC |
1155 | |
1156 | if (nic_data->datapath_caps & | |
1157 | (1 << MC_CMD_GET_CAPABILITIES_OUT_PM_AND_RXDP_COUNTERS_LBN)) | |
1158 | raw_mask |= HUNT_PM_AND_RXDP_STAT_MASK; | |
1159 | ||
4bae913b EC |
1160 | return raw_mask; |
1161 | } | |
1162 | ||
1163 | static void efx_ef10_get_stat_mask(struct efx_nic *efx, unsigned long *mask) | |
1164 | { | |
d94619cd | 1165 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
3c36a2ad DP |
1166 | u64 raw_mask[2]; |
1167 | ||
1168 | raw_mask[0] = efx_ef10_raw_stat_mask(efx); | |
1169 | ||
d94619cd DP |
1170 | /* Only show vadaptor stats when EVB capability is present */ |
1171 | if (nic_data->datapath_caps & | |
1172 | (1 << MC_CMD_GET_CAPABILITIES_OUT_EVB_LBN)) { | |
1173 | raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1); | |
1174 | raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1; | |
1175 | } else { | |
1176 | raw_mask[1] = 0; | |
1177 | } | |
4bae913b EC |
1178 | |
1179 | #if BITS_PER_LONG == 64 | |
3c36a2ad DP |
1180 | mask[0] = raw_mask[0]; |
1181 | mask[1] = raw_mask[1]; | |
4bae913b | 1182 | #else |
3c36a2ad DP |
1183 | mask[0] = raw_mask[0] & 0xffffffff; |
1184 | mask[1] = raw_mask[0] >> 32; | |
1185 | mask[2] = raw_mask[1] & 0xffffffff; | |
1186 | mask[3] = raw_mask[1] >> 32; | |
4bae913b | 1187 | #endif |
8127d661 BH |
1188 | } |
1189 | ||
1190 | static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) | |
1191 | { | |
4bae913b EC |
1192 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
1193 | ||
1194 | efx_ef10_get_stat_mask(efx, mask); | |
8127d661 | 1195 | return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, |
4bae913b | 1196 | mask, names); |
8127d661 BH |
1197 | } |
1198 | ||
d7788196 DP |
1199 | static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats, |
1200 | struct rtnl_link_stats64 *core_stats) | |
1201 | { | |
1202 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); | |
1203 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1204 | u64 *stats = nic_data->stats; | |
1205 | size_t stats_count = 0, index; | |
1206 | ||
1207 | efx_ef10_get_stat_mask(efx, mask); | |
1208 | ||
1209 | if (full_stats) { | |
1210 | for_each_set_bit(index, mask, EF10_STAT_COUNT) { | |
1211 | if (efx_ef10_stat_desc[index].name) { | |
1212 | *full_stats++ = stats[index]; | |
1213 | ++stats_count; | |
1214 | } | |
1215 | } | |
1216 | } | |
1217 | ||
1218 | if (core_stats) { | |
0fc95fca DP |
1219 | core_stats->rx_packets = stats[EF10_STAT_rx_unicast] + |
1220 | stats[EF10_STAT_rx_multicast] + | |
1221 | stats[EF10_STAT_rx_broadcast]; | |
1222 | core_stats->tx_packets = stats[EF10_STAT_tx_unicast] + | |
1223 | stats[EF10_STAT_tx_multicast] + | |
1224 | stats[EF10_STAT_tx_broadcast]; | |
1225 | core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] + | |
1226 | stats[EF10_STAT_rx_multicast_bytes] + | |
1227 | stats[EF10_STAT_rx_broadcast_bytes]; | |
1228 | core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] + | |
1229 | stats[EF10_STAT_tx_multicast_bytes] + | |
1230 | stats[EF10_STAT_tx_broadcast_bytes]; | |
1231 | core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] + | |
d7788196 | 1232 | stats[GENERIC_STAT_rx_noskb_drops]; |
0fc95fca DP |
1233 | core_stats->multicast = stats[EF10_STAT_rx_multicast]; |
1234 | core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad]; | |
1235 | core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow]; | |
1236 | core_stats->rx_errors = core_stats->rx_crc_errors; | |
1237 | core_stats->tx_errors = stats[EF10_STAT_tx_bad]; | |
d7788196 DP |
1238 | } |
1239 | ||
1240 | return stats_count; | |
1241 | } | |
1242 | ||
1243 | static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx) | |
8127d661 BH |
1244 | { |
1245 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
4bae913b | 1246 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
8127d661 BH |
1247 | __le64 generation_start, generation_end; |
1248 | u64 *stats = nic_data->stats; | |
1249 | __le64 *dma_stats; | |
1250 | ||
4bae913b EC |
1251 | efx_ef10_get_stat_mask(efx, mask); |
1252 | ||
8127d661 BH |
1253 | dma_stats = efx->stats_buffer.addr; |
1254 | nic_data = efx->nic_data; | |
1255 | ||
1256 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; | |
1257 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) | |
1258 | return 0; | |
1259 | rmb(); | |
4bae913b | 1260 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
8127d661 | 1261 | stats, efx->stats_buffer.addr, false); |
d546a893 | 1262 | rmb(); |
8127d661 BH |
1263 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
1264 | if (generation_end != generation_start) | |
1265 | return -EAGAIN; | |
1266 | ||
1267 | /* Update derived statistics */ | |
e80ca013 DP |
1268 | efx_nic_fix_nodesc_drop_stat(efx, |
1269 | &stats[EF10_STAT_port_rx_nodesc_drops]); | |
1270 | stats[EF10_STAT_port_rx_good_bytes] = | |
1271 | stats[EF10_STAT_port_rx_bytes] - | |
1272 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]; | |
1273 | efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes], | |
1274 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]); | |
e4d112e4 | 1275 | efx_update_sw_stats(efx, stats); |
8127d661 BH |
1276 | return 0; |
1277 | } | |
1278 | ||
1279 | ||
d7788196 DP |
1280 | static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats, |
1281 | struct rtnl_link_stats64 *core_stats) | |
8127d661 | 1282 | { |
8127d661 BH |
1283 | int retry; |
1284 | ||
1285 | /* If we're unlucky enough to read statistics during the DMA, wait | |
1286 | * up to 10ms for it to finish (typically takes <500us) | |
1287 | */ | |
1288 | for (retry = 0; retry < 100; ++retry) { | |
d7788196 | 1289 | if (efx_ef10_try_update_nic_stats_pf(efx) == 0) |
8127d661 BH |
1290 | break; |
1291 | udelay(100); | |
1292 | } | |
1293 | ||
d7788196 DP |
1294 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); |
1295 | } | |
8127d661 | 1296 | |
d7788196 DP |
1297 | static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx) |
1298 | { | |
1299 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN); | |
1300 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1301 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); | |
1302 | __le64 generation_start, generation_end; | |
1303 | u64 *stats = nic_data->stats; | |
1304 | u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64); | |
1305 | struct efx_buffer stats_buf; | |
1306 | __le64 *dma_stats; | |
1307 | int rc; | |
1308 | ||
f00bf230 DP |
1309 | spin_unlock_bh(&efx->stats_lock); |
1310 | ||
1311 | if (in_interrupt()) { | |
1312 | /* If in atomic context, cannot update stats. Just update the | |
1313 | * software stats and return so the caller can continue. | |
1314 | */ | |
1315 | spin_lock_bh(&efx->stats_lock); | |
1316 | efx_update_sw_stats(efx, stats); | |
1317 | return 0; | |
1318 | } | |
1319 | ||
d7788196 DP |
1320 | efx_ef10_get_stat_mask(efx, mask); |
1321 | ||
1322 | rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC); | |
f00bf230 DP |
1323 | if (rc) { |
1324 | spin_lock_bh(&efx->stats_lock); | |
d7788196 | 1325 | return rc; |
f00bf230 | 1326 | } |
d7788196 DP |
1327 | |
1328 | dma_stats = stats_buf.addr; | |
1329 | dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID; | |
1330 | ||
1331 | MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr); | |
1332 | MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD, | |
0fc95fca | 1333 | MAC_STATS_IN_DMA, 1); |
d7788196 DP |
1334 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len); |
1335 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED); | |
1336 | ||
6dd4859b DP |
1337 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf), |
1338 | NULL, 0, NULL); | |
d7788196 | 1339 | spin_lock_bh(&efx->stats_lock); |
6dd4859b DP |
1340 | if (rc) { |
1341 | /* Expect ENOENT if DMA queues have not been set up */ | |
1342 | if (rc != -ENOENT || atomic_read(&efx->active_queues)) | |
1343 | efx_mcdi_display_error(efx, MC_CMD_MAC_STATS, | |
1344 | sizeof(inbuf), NULL, 0, rc); | |
d7788196 | 1345 | goto out; |
6dd4859b | 1346 | } |
d7788196 DP |
1347 | |
1348 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; | |
0fc95fca DP |
1349 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) { |
1350 | WARN_ON_ONCE(1); | |
d7788196 | 1351 | goto out; |
0fc95fca | 1352 | } |
d7788196 DP |
1353 | rmb(); |
1354 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, | |
1355 | stats, stats_buf.addr, false); | |
1356 | rmb(); | |
1357 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; | |
1358 | if (generation_end != generation_start) { | |
1359 | rc = -EAGAIN; | |
1360 | goto out; | |
8127d661 BH |
1361 | } |
1362 | ||
d7788196 DP |
1363 | efx_update_sw_stats(efx, stats); |
1364 | out: | |
1365 | efx_nic_free_buffer(efx, &stats_buf); | |
1366 | return rc; | |
1367 | } | |
1368 | ||
1369 | static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats, | |
1370 | struct rtnl_link_stats64 *core_stats) | |
1371 | { | |
1372 | if (efx_ef10_try_update_nic_stats_vf(efx)) | |
1373 | return 0; | |
1374 | ||
1375 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); | |
8127d661 BH |
1376 | } |
1377 | ||
1378 | static void efx_ef10_push_irq_moderation(struct efx_channel *channel) | |
1379 | { | |
1380 | struct efx_nic *efx = channel->efx; | |
1381 | unsigned int mode, value; | |
1382 | efx_dword_t timer_cmd; | |
1383 | ||
1384 | if (channel->irq_moderation) { | |
1385 | mode = 3; | |
1386 | value = channel->irq_moderation - 1; | |
1387 | } else { | |
1388 | mode = 0; | |
1389 | value = 0; | |
1390 | } | |
1391 | ||
1392 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
1393 | EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS, | |
1394 | EFE_DD_EVQ_IND_TIMER_FLAGS, | |
1395 | ERF_DD_EVQ_IND_TIMER_MODE, mode, | |
1396 | ERF_DD_EVQ_IND_TIMER_VAL, value); | |
1397 | efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT, | |
1398 | channel->channel); | |
1399 | } else { | |
1400 | EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode, | |
1401 | ERF_DZ_TC_TIMER_VAL, value); | |
1402 | efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR, | |
1403 | channel->channel); | |
1404 | } | |
1405 | } | |
1406 | ||
02246a7f SS |
1407 | static void efx_ef10_get_wol_vf(struct efx_nic *efx, |
1408 | struct ethtool_wolinfo *wol) {} | |
1409 | ||
1410 | static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type) | |
1411 | { | |
1412 | return -EOPNOTSUPP; | |
1413 | } | |
1414 | ||
8127d661 BH |
1415 | static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
1416 | { | |
1417 | wol->supported = 0; | |
1418 | wol->wolopts = 0; | |
1419 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
1420 | } | |
1421 | ||
1422 | static int efx_ef10_set_wol(struct efx_nic *efx, u32 type) | |
1423 | { | |
1424 | if (type != 0) | |
1425 | return -EINVAL; | |
1426 | return 0; | |
1427 | } | |
1428 | ||
1429 | static void efx_ef10_mcdi_request(struct efx_nic *efx, | |
1430 | const efx_dword_t *hdr, size_t hdr_len, | |
1431 | const efx_dword_t *sdu, size_t sdu_len) | |
1432 | { | |
1433 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1434 | u8 *pdu = nic_data->mcdi_buf.addr; | |
1435 | ||
1436 | memcpy(pdu, hdr, hdr_len); | |
1437 | memcpy(pdu + hdr_len, sdu, sdu_len); | |
1438 | wmb(); | |
1439 | ||
1440 | /* The hardware provides 'low' and 'high' (doorbell) registers | |
1441 | * for passing the 64-bit address of an MCDI request to | |
1442 | * firmware. However the dwords are swapped by firmware. The | |
1443 | * least significant bits of the doorbell are then 0 for all | |
1444 | * MCDI requests due to alignment. | |
1445 | */ | |
1446 | _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32), | |
1447 | ER_DZ_MC_DB_LWRD); | |
1448 | _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr), | |
1449 | ER_DZ_MC_DB_HWRD); | |
1450 | } | |
1451 | ||
1452 | static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx) | |
1453 | { | |
1454 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1455 | const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr; | |
1456 | ||
1457 | rmb(); | |
1458 | return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE); | |
1459 | } | |
1460 | ||
1461 | static void | |
1462 | efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf, | |
1463 | size_t offset, size_t outlen) | |
1464 | { | |
1465 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1466 | const u8 *pdu = nic_data->mcdi_buf.addr; | |
1467 | ||
1468 | memcpy(outbuf, pdu + offset, outlen); | |
1469 | } | |
1470 | ||
1471 | static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx) | |
1472 | { | |
1473 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1474 | int rc; | |
1475 | ||
1476 | rc = efx_ef10_get_warm_boot_count(efx); | |
1477 | if (rc < 0) { | |
1478 | /* The firmware is presumably in the process of | |
1479 | * rebooting. However, we are supposed to report each | |
1480 | * reboot just once, so we must only do that once we | |
1481 | * can read and store the updated warm boot count. | |
1482 | */ | |
1483 | return 0; | |
1484 | } | |
1485 | ||
1486 | if (rc == nic_data->warm_boot_count) | |
1487 | return 0; | |
1488 | ||
1489 | nic_data->warm_boot_count = rc; | |
1490 | ||
1491 | /* All our allocations have been reset */ | |
3e336261 | 1492 | efx_ef10_reset_mc_allocations(efx); |
8127d661 | 1493 | |
6d8aaaf6 DP |
1494 | /* Driver-created vswitches and vports must be re-created */ |
1495 | nic_data->must_probe_vswitching = true; | |
1496 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; | |
1497 | ||
a915ccc9 BH |
1498 | /* The datapath firmware might have been changed */ |
1499 | nic_data->must_check_datapath_caps = true; | |
1500 | ||
869070c5 BH |
1501 | /* MAC statistics have been cleared on the NIC; clear the local |
1502 | * statistic that we update with efx_update_diff_stat(). | |
1503 | */ | |
e80ca013 | 1504 | nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0; |
869070c5 | 1505 | |
8127d661 BH |
1506 | return -EIO; |
1507 | } | |
1508 | ||
1509 | /* Handle an MSI interrupt | |
1510 | * | |
1511 | * Handle an MSI hardware interrupt. This routine schedules event | |
1512 | * queue processing. No interrupt acknowledgement cycle is necessary. | |
1513 | * Also, we never need to check that the interrupt is for us, since | |
1514 | * MSI interrupts cannot be shared. | |
1515 | */ | |
1516 | static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id) | |
1517 | { | |
1518 | struct efx_msi_context *context = dev_id; | |
1519 | struct efx_nic *efx = context->efx; | |
1520 | ||
1521 | netif_vdbg(efx, intr, efx->net_dev, | |
1522 | "IRQ %d on CPU %d\n", irq, raw_smp_processor_id()); | |
1523 | ||
1524 | if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) { | |
1525 | /* Note test interrupts */ | |
1526 | if (context->index == efx->irq_level) | |
1527 | efx->last_irq_cpu = raw_smp_processor_id(); | |
1528 | ||
1529 | /* Schedule processing of the channel */ | |
1530 | efx_schedule_channel_irq(efx->channel[context->index]); | |
1531 | } | |
1532 | ||
1533 | return IRQ_HANDLED; | |
1534 | } | |
1535 | ||
1536 | static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id) | |
1537 | { | |
1538 | struct efx_nic *efx = dev_id; | |
1539 | bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled); | |
1540 | struct efx_channel *channel; | |
1541 | efx_dword_t reg; | |
1542 | u32 queues; | |
1543 | ||
1544 | /* Read the ISR which also ACKs the interrupts */ | |
1545 | efx_readd(efx, ®, ER_DZ_BIU_INT_ISR); | |
1546 | queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG); | |
1547 | ||
1548 | if (queues == 0) | |
1549 | return IRQ_NONE; | |
1550 | ||
1551 | if (likely(soft_enabled)) { | |
1552 | /* Note test interrupts */ | |
1553 | if (queues & (1U << efx->irq_level)) | |
1554 | efx->last_irq_cpu = raw_smp_processor_id(); | |
1555 | ||
1556 | efx_for_each_channel(channel, efx) { | |
1557 | if (queues & 1) | |
1558 | efx_schedule_channel_irq(channel); | |
1559 | queues >>= 1; | |
1560 | } | |
1561 | } | |
1562 | ||
1563 | netif_vdbg(efx, intr, efx->net_dev, | |
1564 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", | |
1565 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); | |
1566 | ||
1567 | return IRQ_HANDLED; | |
1568 | } | |
1569 | ||
1570 | static void efx_ef10_irq_test_generate(struct efx_nic *efx) | |
1571 | { | |
1572 | MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN); | |
1573 | ||
1574 | BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0); | |
1575 | ||
1576 | MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level); | |
1577 | (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT, | |
1578 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
1579 | } | |
1580 | ||
1581 | static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue) | |
1582 | { | |
1583 | return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf, | |
1584 | (tx_queue->ptr_mask + 1) * | |
1585 | sizeof(efx_qword_t), | |
1586 | GFP_KERNEL); | |
1587 | } | |
1588 | ||
1589 | /* This writes to the TX_DESC_WPTR and also pushes data */ | |
1590 | static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue, | |
1591 | const efx_qword_t *txd) | |
1592 | { | |
1593 | unsigned int write_ptr; | |
1594 | efx_oword_t reg; | |
1595 | ||
1596 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1597 | EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr); | |
1598 | reg.qword[0] = *txd; | |
1599 | efx_writeo_page(tx_queue->efx, ®, | |
1600 | ER_DZ_TX_DESC_UPD, tx_queue->queue); | |
1601 | } | |
1602 | ||
1603 | static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) | |
1604 | { | |
1605 | MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
1606 | EFX_BUF_SIZE)); | |
8127d661 BH |
1607 | bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; |
1608 | size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE; | |
1609 | struct efx_channel *channel = tx_queue->channel; | |
1610 | struct efx_nic *efx = tx_queue->efx; | |
45b2449e | 1611 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
aa09a3da | 1612 | size_t inlen; |
8127d661 BH |
1613 | dma_addr_t dma_addr; |
1614 | efx_qword_t *txd; | |
1615 | int rc; | |
1616 | int i; | |
aa09a3da | 1617 | BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0); |
8127d661 BH |
1618 | |
1619 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); | |
1620 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); | |
1621 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); | |
1622 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); | |
1623 | MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS, | |
1624 | INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, | |
1625 | INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); | |
1626 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); | |
45b2449e | 1627 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
1628 | |
1629 | dma_addr = tx_queue->txd.buf.dma_addr; | |
1630 | ||
1631 | netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n", | |
1632 | tx_queue->queue, entries, (u64)dma_addr); | |
1633 | ||
1634 | for (i = 0; i < entries; ++i) { | |
1635 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr); | |
1636 | dma_addr += EFX_BUF_SIZE; | |
1637 | } | |
1638 | ||
1639 | inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); | |
1640 | ||
1641 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen, | |
aa09a3da | 1642 | NULL, 0, NULL); |
8127d661 BH |
1643 | if (rc) |
1644 | goto fail; | |
1645 | ||
1646 | /* A previous user of this TX queue might have set us up the | |
1647 | * bomb by writing a descriptor to the TX push collector but | |
1648 | * not the doorbell. (Each collector belongs to a port, not a | |
1649 | * queue or function, so cannot easily be reset.) We must | |
1650 | * attempt to push a no-op descriptor in its place. | |
1651 | */ | |
1652 | tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION; | |
1653 | tx_queue->insert_count = 1; | |
1654 | txd = efx_tx_desc(tx_queue, 0); | |
1655 | EFX_POPULATE_QWORD_4(*txd, | |
1656 | ESF_DZ_TX_DESC_IS_OPT, true, | |
1657 | ESF_DZ_TX_OPTION_TYPE, | |
1658 | ESE_DZ_TX_OPTION_DESC_CRC_CSUM, | |
1659 | ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload, | |
1660 | ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); | |
1661 | tx_queue->write_count = 1; | |
1662 | wmb(); | |
1663 | efx_ef10_push_tx_desc(tx_queue, txd); | |
1664 | ||
1665 | return; | |
1666 | ||
1667 | fail: | |
48ce5634 BH |
1668 | netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n", |
1669 | tx_queue->queue); | |
8127d661 BH |
1670 | } |
1671 | ||
1672 | static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue) | |
1673 | { | |
1674 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN); | |
aa09a3da | 1675 | MCDI_DECLARE_BUF_ERR(outbuf); |
8127d661 BH |
1676 | struct efx_nic *efx = tx_queue->efx; |
1677 | size_t outlen; | |
1678 | int rc; | |
1679 | ||
1680 | MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE, | |
1681 | tx_queue->queue); | |
1682 | ||
1e0b8120 | 1683 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf), |
8127d661 BH |
1684 | outbuf, sizeof(outbuf), &outlen); |
1685 | ||
1686 | if (rc && rc != -EALREADY) | |
1687 | goto fail; | |
1688 | ||
1689 | return; | |
1690 | ||
1691 | fail: | |
1e0b8120 EC |
1692 | efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN, |
1693 | outbuf, outlen, rc); | |
8127d661 BH |
1694 | } |
1695 | ||
1696 | static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue) | |
1697 | { | |
1698 | efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf); | |
1699 | } | |
1700 | ||
1701 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ | |
1702 | static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue) | |
1703 | { | |
1704 | unsigned int write_ptr; | |
1705 | efx_dword_t reg; | |
1706 | ||
1707 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1708 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); | |
1709 | efx_writed_page(tx_queue->efx, ®, | |
1710 | ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); | |
1711 | } | |
1712 | ||
1713 | static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) | |
1714 | { | |
1715 | unsigned int old_write_count = tx_queue->write_count; | |
1716 | struct efx_tx_buffer *buffer; | |
1717 | unsigned int write_ptr; | |
1718 | efx_qword_t *txd; | |
1719 | ||
1720 | BUG_ON(tx_queue->write_count == tx_queue->insert_count); | |
1721 | ||
1722 | do { | |
1723 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1724 | buffer = &tx_queue->buffer[write_ptr]; | |
1725 | txd = efx_tx_desc(tx_queue, write_ptr); | |
1726 | ++tx_queue->write_count; | |
1727 | ||
1728 | /* Create TX descriptor ring entry */ | |
1729 | if (buffer->flags & EFX_TX_BUF_OPTION) { | |
1730 | *txd = buffer->option; | |
1731 | } else { | |
1732 | BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); | |
1733 | EFX_POPULATE_QWORD_3( | |
1734 | *txd, | |
1735 | ESF_DZ_TX_KER_CONT, | |
1736 | buffer->flags & EFX_TX_BUF_CONT, | |
1737 | ESF_DZ_TX_KER_BYTE_CNT, buffer->len, | |
1738 | ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr); | |
1739 | } | |
1740 | } while (tx_queue->write_count != tx_queue->insert_count); | |
1741 | ||
1742 | wmb(); /* Ensure descriptors are written before they are fetched */ | |
1743 | ||
1744 | if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { | |
1745 | txd = efx_tx_desc(tx_queue, | |
1746 | old_write_count & tx_queue->ptr_mask); | |
1747 | efx_ef10_push_tx_desc(tx_queue, txd); | |
1748 | ++tx_queue->pushes; | |
1749 | } else { | |
1750 | efx_ef10_notify_tx_desc(tx_queue); | |
1751 | } | |
1752 | } | |
1753 | ||
267c0157 JC |
1754 | static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context, |
1755 | bool exclusive, unsigned *context_size) | |
8127d661 BH |
1756 | { |
1757 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); | |
1758 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN); | |
45b2449e | 1759 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
8127d661 BH |
1760 | size_t outlen; |
1761 | int rc; | |
267c0157 JC |
1762 | u32 alloc_type = exclusive ? |
1763 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE : | |
1764 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED; | |
1765 | unsigned rss_spread = exclusive ? | |
1766 | efx->rss_spread : | |
1767 | min(rounddown_pow_of_two(efx->rss_spread), | |
1768 | EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE); | |
1769 | ||
1770 | if (!exclusive && rss_spread == 1) { | |
1771 | *context = EFX_EF10_RSS_CONTEXT_INVALID; | |
1772 | if (context_size) | |
1773 | *context_size = 1; | |
1774 | return 0; | |
1775 | } | |
8127d661 BH |
1776 | |
1777 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID, | |
45b2449e | 1778 | nic_data->vport_id); |
267c0157 JC |
1779 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type); |
1780 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread); | |
8127d661 BH |
1781 | |
1782 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf), | |
1783 | outbuf, sizeof(outbuf), &outlen); | |
1784 | if (rc != 0) | |
1785 | return rc; | |
1786 | ||
1787 | if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) | |
1788 | return -EIO; | |
1789 | ||
1790 | *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID); | |
1791 | ||
267c0157 JC |
1792 | if (context_size) |
1793 | *context_size = rss_spread; | |
1794 | ||
8127d661 BH |
1795 | return 0; |
1796 | } | |
1797 | ||
1798 | static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context) | |
1799 | { | |
1800 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN); | |
1801 | int rc; | |
1802 | ||
1803 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, | |
1804 | context); | |
1805 | ||
1806 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf), | |
1807 | NULL, 0, NULL); | |
1808 | WARN_ON(rc != 0); | |
1809 | } | |
1810 | ||
267c0157 JC |
1811 | static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context, |
1812 | const u32 *rx_indir_table) | |
8127d661 BH |
1813 | { |
1814 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN); | |
1815 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN); | |
1816 | int i, rc; | |
1817 | ||
1818 | MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID, | |
1819 | context); | |
1820 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != | |
1821 | MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN); | |
1822 | ||
1823 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i) | |
1824 | MCDI_PTR(tablebuf, | |
1825 | RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] = | |
267c0157 | 1826 | (u8) rx_indir_table[i]; |
8127d661 BH |
1827 | |
1828 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf, | |
1829 | sizeof(tablebuf), NULL, 0, NULL); | |
1830 | if (rc != 0) | |
1831 | return rc; | |
1832 | ||
1833 | MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID, | |
1834 | context); | |
1835 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != | |
1836 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); | |
1837 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) | |
1838 | MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = | |
1839 | efx->rx_hash_key[i]; | |
1840 | ||
1841 | return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf, | |
1842 | sizeof(keybuf), NULL, 0, NULL); | |
1843 | } | |
1844 | ||
1845 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx) | |
1846 | { | |
1847 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1848 | ||
1849 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) | |
1850 | efx_ef10_free_rss_context(efx, nic_data->rx_rss_context); | |
1851 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
1852 | } | |
1853 | ||
267c0157 JC |
1854 | static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx, |
1855 | unsigned *context_size) | |
8127d661 | 1856 | { |
267c0157 | 1857 | u32 new_rx_rss_context; |
8127d661 | 1858 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
267c0157 JC |
1859 | int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, |
1860 | false, context_size); | |
1861 | ||
1862 | if (rc != 0) | |
1863 | return rc; | |
8127d661 | 1864 | |
267c0157 JC |
1865 | nic_data->rx_rss_context = new_rx_rss_context; |
1866 | nic_data->rx_rss_context_exclusive = false; | |
1867 | efx_set_default_rx_indir_table(efx); | |
1868 | return 0; | |
1869 | } | |
8127d661 | 1870 | |
267c0157 JC |
1871 | static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx, |
1872 | const u32 *rx_indir_table) | |
1873 | { | |
1874 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1875 | int rc; | |
1876 | u32 new_rx_rss_context; | |
1877 | ||
1878 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID || | |
1879 | !nic_data->rx_rss_context_exclusive) { | |
1880 | rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, | |
1881 | true, NULL); | |
1882 | if (rc == -EOPNOTSUPP) | |
1883 | return rc; | |
1884 | else if (rc != 0) | |
1885 | goto fail1; | |
1886 | } else { | |
1887 | new_rx_rss_context = nic_data->rx_rss_context; | |
8127d661 BH |
1888 | } |
1889 | ||
267c0157 JC |
1890 | rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context, |
1891 | rx_indir_table); | |
8127d661 | 1892 | if (rc != 0) |
267c0157 | 1893 | goto fail2; |
8127d661 | 1894 | |
267c0157 JC |
1895 | if (nic_data->rx_rss_context != new_rx_rss_context) |
1896 | efx_ef10_rx_free_indir_table(efx); | |
1897 | nic_data->rx_rss_context = new_rx_rss_context; | |
1898 | nic_data->rx_rss_context_exclusive = true; | |
1899 | if (rx_indir_table != efx->rx_indir_table) | |
1900 | memcpy(efx->rx_indir_table, rx_indir_table, | |
1901 | sizeof(efx->rx_indir_table)); | |
1902 | return 0; | |
8127d661 | 1903 | |
267c0157 JC |
1904 | fail2: |
1905 | if (new_rx_rss_context != nic_data->rx_rss_context) | |
1906 | efx_ef10_free_rss_context(efx, new_rx_rss_context); | |
1907 | fail1: | |
8127d661 | 1908 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
267c0157 JC |
1909 | return rc; |
1910 | } | |
1911 | ||
1912 | static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user, | |
1913 | const u32 *rx_indir_table) | |
1914 | { | |
1915 | int rc; | |
1916 | ||
1917 | if (efx->rss_spread == 1) | |
1918 | return 0; | |
1919 | ||
1920 | rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table); | |
1921 | ||
1922 | if (rc == -ENOBUFS && !user) { | |
1923 | unsigned context_size; | |
1924 | bool mismatch = false; | |
1925 | size_t i; | |
1926 | ||
1927 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch; | |
1928 | i++) | |
1929 | mismatch = rx_indir_table[i] != | |
1930 | ethtool_rxfh_indir_default(i, efx->rss_spread); | |
1931 | ||
1932 | rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size); | |
1933 | if (rc == 0) { | |
1934 | if (context_size != efx->rss_spread) | |
1935 | netif_warn(efx, probe, efx->net_dev, | |
1936 | "Could not allocate an exclusive RSS" | |
1937 | " context; allocated a shared one of" | |
1938 | " different size." | |
1939 | " Wanted %u, got %u.\n", | |
1940 | efx->rss_spread, context_size); | |
1941 | else if (mismatch) | |
1942 | netif_warn(efx, probe, efx->net_dev, | |
1943 | "Could not allocate an exclusive RSS" | |
1944 | " context; allocated a shared one but" | |
1945 | " could not apply custom" | |
1946 | " indirection.\n"); | |
1947 | else | |
1948 | netif_info(efx, probe, efx->net_dev, | |
1949 | "Could not allocate an exclusive RSS" | |
1950 | " context; allocated a shared one.\n"); | |
1951 | } | |
1952 | } | |
1953 | return rc; | |
1954 | } | |
1955 | ||
1956 | static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user, | |
1957 | const u32 *rx_indir_table | |
1958 | __attribute__ ((unused))) | |
1959 | { | |
1960 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1961 | ||
1962 | if (user) | |
1963 | return -EOPNOTSUPP; | |
1964 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) | |
1965 | return 0; | |
1966 | return efx_ef10_rx_push_shared_rss_config(efx, NULL); | |
8127d661 BH |
1967 | } |
1968 | ||
1969 | static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue) | |
1970 | { | |
1971 | return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf, | |
1972 | (rx_queue->ptr_mask + 1) * | |
1973 | sizeof(efx_qword_t), | |
1974 | GFP_KERNEL); | |
1975 | } | |
1976 | ||
1977 | static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue) | |
1978 | { | |
1979 | MCDI_DECLARE_BUF(inbuf, | |
1980 | MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
1981 | EFX_BUF_SIZE)); | |
8127d661 BH |
1982 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
1983 | size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE; | |
1984 | struct efx_nic *efx = rx_queue->efx; | |
45b2449e | 1985 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
aa09a3da | 1986 | size_t inlen; |
8127d661 BH |
1987 | dma_addr_t dma_addr; |
1988 | int rc; | |
1989 | int i; | |
aa09a3da | 1990 | BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0); |
8127d661 BH |
1991 | |
1992 | rx_queue->scatter_n = 0; | |
1993 | rx_queue->scatter_len = 0; | |
1994 | ||
1995 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1); | |
1996 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel); | |
1997 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue)); | |
1998 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE, | |
1999 | efx_rx_queue_index(rx_queue)); | |
bd9a265d JC |
2000 | MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS, |
2001 | INIT_RXQ_IN_FLAG_PREFIX, 1, | |
2002 | INIT_RXQ_IN_FLAG_TIMESTAMP, 1); | |
8127d661 | 2003 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0); |
45b2449e | 2004 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
2005 | |
2006 | dma_addr = rx_queue->rxd.buf.dma_addr; | |
2007 | ||
2008 | netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n", | |
2009 | efx_rx_queue_index(rx_queue), entries, (u64)dma_addr); | |
2010 | ||
2011 | for (i = 0; i < entries; ++i) { | |
2012 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr); | |
2013 | dma_addr += EFX_BUF_SIZE; | |
2014 | } | |
2015 | ||
2016 | inlen = MC_CMD_INIT_RXQ_IN_LEN(entries); | |
2017 | ||
2018 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen, | |
aa09a3da | 2019 | NULL, 0, NULL); |
48ce5634 BH |
2020 | if (rc) |
2021 | netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n", | |
2022 | efx_rx_queue_index(rx_queue)); | |
8127d661 BH |
2023 | } |
2024 | ||
2025 | static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue) | |
2026 | { | |
2027 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN); | |
aa09a3da | 2028 | MCDI_DECLARE_BUF_ERR(outbuf); |
8127d661 BH |
2029 | struct efx_nic *efx = rx_queue->efx; |
2030 | size_t outlen; | |
2031 | int rc; | |
2032 | ||
2033 | MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE, | |
2034 | efx_rx_queue_index(rx_queue)); | |
2035 | ||
1e0b8120 | 2036 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf), |
8127d661 BH |
2037 | outbuf, sizeof(outbuf), &outlen); |
2038 | ||
2039 | if (rc && rc != -EALREADY) | |
2040 | goto fail; | |
2041 | ||
2042 | return; | |
2043 | ||
2044 | fail: | |
1e0b8120 EC |
2045 | efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN, |
2046 | outbuf, outlen, rc); | |
8127d661 BH |
2047 | } |
2048 | ||
2049 | static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue) | |
2050 | { | |
2051 | efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf); | |
2052 | } | |
2053 | ||
2054 | /* This creates an entry in the RX descriptor queue */ | |
2055 | static inline void | |
2056 | efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) | |
2057 | { | |
2058 | struct efx_rx_buffer *rx_buf; | |
2059 | efx_qword_t *rxd; | |
2060 | ||
2061 | rxd = efx_rx_desc(rx_queue, index); | |
2062 | rx_buf = efx_rx_buffer(rx_queue, index); | |
2063 | EFX_POPULATE_QWORD_2(*rxd, | |
2064 | ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len, | |
2065 | ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); | |
2066 | } | |
2067 | ||
2068 | static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue) | |
2069 | { | |
2070 | struct efx_nic *efx = rx_queue->efx; | |
2071 | unsigned int write_count; | |
2072 | efx_dword_t reg; | |
2073 | ||
2074 | /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */ | |
2075 | write_count = rx_queue->added_count & ~7; | |
2076 | if (rx_queue->notified_count == write_count) | |
2077 | return; | |
2078 | ||
2079 | do | |
2080 | efx_ef10_build_rx_desc( | |
2081 | rx_queue, | |
2082 | rx_queue->notified_count & rx_queue->ptr_mask); | |
2083 | while (++rx_queue->notified_count != write_count); | |
2084 | ||
2085 | wmb(); | |
2086 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR, | |
2087 | write_count & rx_queue->ptr_mask); | |
2088 | efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD, | |
2089 | efx_rx_queue_index(rx_queue)); | |
2090 | } | |
2091 | ||
2092 | static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete; | |
2093 | ||
2094 | static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue) | |
2095 | { | |
2096 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | |
2097 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
2098 | efx_qword_t event; | |
2099 | ||
2100 | EFX_POPULATE_QWORD_2(event, | |
2101 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
2102 | ESF_DZ_EV_DATA, EFX_EF10_REFILL); | |
2103 | ||
2104 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
2105 | ||
2106 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
2107 | * already swapped the data to little-endian order. | |
2108 | */ | |
2109 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
2110 | sizeof(efx_qword_t)); | |
2111 | ||
2112 | efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT, | |
2113 | inbuf, sizeof(inbuf), 0, | |
2114 | efx_ef10_rx_defer_refill_complete, 0); | |
2115 | } | |
2116 | ||
2117 | static void | |
2118 | efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie, | |
2119 | int rc, efx_dword_t *outbuf, | |
2120 | size_t outlen_actual) | |
2121 | { | |
2122 | /* nothing to do */ | |
2123 | } | |
2124 | ||
2125 | static int efx_ef10_ev_probe(struct efx_channel *channel) | |
2126 | { | |
2127 | return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf, | |
2128 | (channel->eventq_mask + 1) * | |
2129 | sizeof(efx_qword_t), | |
2130 | GFP_KERNEL); | |
2131 | } | |
2132 | ||
2133 | static int efx_ef10_ev_init(struct efx_channel *channel) | |
2134 | { | |
2135 | MCDI_DECLARE_BUF(inbuf, | |
2136 | MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 / | |
2137 | EFX_BUF_SIZE)); | |
2138 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN); | |
2139 | size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE; | |
2140 | struct efx_nic *efx = channel->efx; | |
2141 | struct efx_ef10_nic_data *nic_data; | |
2142 | bool supports_rx_merge; | |
2143 | size_t inlen, outlen; | |
2144 | dma_addr_t dma_addr; | |
2145 | int rc; | |
2146 | int i; | |
2147 | ||
2148 | nic_data = efx->nic_data; | |
2149 | supports_rx_merge = | |
2150 | !!(nic_data->datapath_caps & | |
2151 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN); | |
2152 | ||
2153 | /* Fill event queue with all ones (i.e. empty events) */ | |
2154 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); | |
2155 | ||
2156 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1); | |
2157 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel); | |
2158 | /* INIT_EVQ expects index in vector table, not absolute */ | |
2159 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel); | |
2160 | MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS, | |
2161 | INIT_EVQ_IN_FLAG_INTERRUPTING, 1, | |
2162 | INIT_EVQ_IN_FLAG_RX_MERGE, 1, | |
2163 | INIT_EVQ_IN_FLAG_TX_MERGE, 1, | |
2164 | INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge); | |
2165 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE, | |
2166 | MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); | |
2167 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0); | |
2168 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0); | |
2169 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE, | |
2170 | MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); | |
2171 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0); | |
2172 | ||
2173 | dma_addr = channel->eventq.buf.dma_addr; | |
2174 | for (i = 0; i < entries; ++i) { | |
2175 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr); | |
2176 | dma_addr += EFX_BUF_SIZE; | |
2177 | } | |
2178 | ||
2179 | inlen = MC_CMD_INIT_EVQ_IN_LEN(entries); | |
2180 | ||
2181 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen, | |
2182 | outbuf, sizeof(outbuf), &outlen); | |
8127d661 | 2183 | /* IRQ return is ignored */ |
8127d661 BH |
2184 | return rc; |
2185 | } | |
2186 | ||
2187 | static void efx_ef10_ev_fini(struct efx_channel *channel) | |
2188 | { | |
2189 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN); | |
aa09a3da | 2190 | MCDI_DECLARE_BUF_ERR(outbuf); |
8127d661 BH |
2191 | struct efx_nic *efx = channel->efx; |
2192 | size_t outlen; | |
2193 | int rc; | |
2194 | ||
2195 | MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel); | |
2196 | ||
1e0b8120 | 2197 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf), |
8127d661 BH |
2198 | outbuf, sizeof(outbuf), &outlen); |
2199 | ||
2200 | if (rc && rc != -EALREADY) | |
2201 | goto fail; | |
2202 | ||
2203 | return; | |
2204 | ||
2205 | fail: | |
1e0b8120 EC |
2206 | efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN, |
2207 | outbuf, outlen, rc); | |
8127d661 BH |
2208 | } |
2209 | ||
2210 | static void efx_ef10_ev_remove(struct efx_channel *channel) | |
2211 | { | |
2212 | efx_nic_free_buffer(channel->efx, &channel->eventq.buf); | |
2213 | } | |
2214 | ||
2215 | static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue, | |
2216 | unsigned int rx_queue_label) | |
2217 | { | |
2218 | struct efx_nic *efx = rx_queue->efx; | |
2219 | ||
2220 | netif_info(efx, hw, efx->net_dev, | |
2221 | "rx event arrived on queue %d labeled as queue %u\n", | |
2222 | efx_rx_queue_index(rx_queue), rx_queue_label); | |
2223 | ||
2224 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
2225 | } | |
2226 | ||
2227 | static void | |
2228 | efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue, | |
2229 | unsigned int actual, unsigned int expected) | |
2230 | { | |
2231 | unsigned int dropped = (actual - expected) & rx_queue->ptr_mask; | |
2232 | struct efx_nic *efx = rx_queue->efx; | |
2233 | ||
2234 | netif_info(efx, hw, efx->net_dev, | |
2235 | "dropped %d events (index=%d expected=%d)\n", | |
2236 | dropped, actual, expected); | |
2237 | ||
2238 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
2239 | } | |
2240 | ||
2241 | /* partially received RX was aborted. clean up. */ | |
2242 | static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue) | |
2243 | { | |
2244 | unsigned int rx_desc_ptr; | |
2245 | ||
8127d661 BH |
2246 | netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev, |
2247 | "scattered RX aborted (dropping %u buffers)\n", | |
2248 | rx_queue->scatter_n); | |
2249 | ||
2250 | rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask; | |
2251 | ||
2252 | efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n, | |
2253 | 0, EFX_RX_PKT_DISCARD); | |
2254 | ||
2255 | rx_queue->removed_count += rx_queue->scatter_n; | |
2256 | rx_queue->scatter_n = 0; | |
2257 | rx_queue->scatter_len = 0; | |
2258 | ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc; | |
2259 | } | |
2260 | ||
2261 | static int efx_ef10_handle_rx_event(struct efx_channel *channel, | |
2262 | const efx_qword_t *event) | |
2263 | { | |
2264 | unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class; | |
2265 | unsigned int n_descs, n_packets, i; | |
2266 | struct efx_nic *efx = channel->efx; | |
2267 | struct efx_rx_queue *rx_queue; | |
2268 | bool rx_cont; | |
2269 | u16 flags = 0; | |
2270 | ||
2271 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
2272 | return 0; | |
2273 | ||
2274 | /* Basic packet information */ | |
2275 | rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES); | |
2276 | next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS); | |
2277 | rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL); | |
2278 | rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS); | |
2279 | rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT); | |
2280 | ||
48ce5634 BH |
2281 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT)) |
2282 | netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event=" | |
2283 | EFX_QWORD_FMT "\n", | |
2284 | EFX_QWORD_VAL(*event)); | |
8127d661 BH |
2285 | |
2286 | rx_queue = efx_channel_get_rx_queue(channel); | |
2287 | ||
2288 | if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue))) | |
2289 | efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label); | |
2290 | ||
2291 | n_descs = ((next_ptr_lbits - rx_queue->removed_count) & | |
2292 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
2293 | ||
2294 | if (n_descs != rx_queue->scatter_n + 1) { | |
92a04168 BH |
2295 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
2296 | ||
8127d661 BH |
2297 | /* detect rx abort */ |
2298 | if (unlikely(n_descs == rx_queue->scatter_n)) { | |
48ce5634 BH |
2299 | if (rx_queue->scatter_n == 0 || rx_bytes != 0) |
2300 | netdev_WARN(efx->net_dev, | |
2301 | "invalid RX abort: scatter_n=%u event=" | |
2302 | EFX_QWORD_FMT "\n", | |
2303 | rx_queue->scatter_n, | |
2304 | EFX_QWORD_VAL(*event)); | |
8127d661 BH |
2305 | efx_ef10_handle_rx_abort(rx_queue); |
2306 | return 0; | |
2307 | } | |
2308 | ||
92a04168 BH |
2309 | /* Check that RX completion merging is valid, i.e. |
2310 | * the current firmware supports it and this is a | |
2311 | * non-scattered packet. | |
2312 | */ | |
2313 | if (!(nic_data->datapath_caps & | |
2314 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) || | |
2315 | rx_queue->scatter_n != 0 || rx_cont) { | |
8127d661 BH |
2316 | efx_ef10_handle_rx_bad_lbits( |
2317 | rx_queue, next_ptr_lbits, | |
2318 | (rx_queue->removed_count + | |
2319 | rx_queue->scatter_n + 1) & | |
2320 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
2321 | return 0; | |
2322 | } | |
2323 | ||
2324 | /* Merged completion for multiple non-scattered packets */ | |
2325 | rx_queue->scatter_n = 1; | |
2326 | rx_queue->scatter_len = 0; | |
2327 | n_packets = n_descs; | |
2328 | ++channel->n_rx_merge_events; | |
2329 | channel->n_rx_merge_packets += n_packets; | |
2330 | flags |= EFX_RX_PKT_PREFIX_LEN; | |
2331 | } else { | |
2332 | ++rx_queue->scatter_n; | |
2333 | rx_queue->scatter_len += rx_bytes; | |
2334 | if (rx_cont) | |
2335 | return 0; | |
2336 | n_packets = 1; | |
2337 | } | |
2338 | ||
2339 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR))) | |
2340 | flags |= EFX_RX_PKT_DISCARD; | |
2341 | ||
2342 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) { | |
2343 | channel->n_rx_ip_hdr_chksum_err += n_packets; | |
2344 | } else if (unlikely(EFX_QWORD_FIELD(*event, | |
2345 | ESF_DZ_RX_TCPUDP_CKSUM_ERR))) { | |
2346 | channel->n_rx_tcp_udp_chksum_err += n_packets; | |
2347 | } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP || | |
2348 | rx_l4_class == ESE_DZ_L4_CLASS_UDP) { | |
2349 | flags |= EFX_RX_PKT_CSUMMED; | |
2350 | } | |
2351 | ||
2352 | if (rx_l4_class == ESE_DZ_L4_CLASS_TCP) | |
2353 | flags |= EFX_RX_PKT_TCP; | |
2354 | ||
2355 | channel->irq_mod_score += 2 * n_packets; | |
2356 | ||
2357 | /* Handle received packet(s) */ | |
2358 | for (i = 0; i < n_packets; i++) { | |
2359 | efx_rx_packet(rx_queue, | |
2360 | rx_queue->removed_count & rx_queue->ptr_mask, | |
2361 | rx_queue->scatter_n, rx_queue->scatter_len, | |
2362 | flags); | |
2363 | rx_queue->removed_count += rx_queue->scatter_n; | |
2364 | } | |
2365 | ||
2366 | rx_queue->scatter_n = 0; | |
2367 | rx_queue->scatter_len = 0; | |
2368 | ||
2369 | return n_packets; | |
2370 | } | |
2371 | ||
2372 | static int | |
2373 | efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) | |
2374 | { | |
2375 | struct efx_nic *efx = channel->efx; | |
2376 | struct efx_tx_queue *tx_queue; | |
2377 | unsigned int tx_ev_desc_ptr; | |
2378 | unsigned int tx_ev_q_label; | |
2379 | int tx_descs = 0; | |
2380 | ||
2381 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
2382 | return 0; | |
2383 | ||
2384 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT))) | |
2385 | return 0; | |
2386 | ||
2387 | /* Transmit completion */ | |
2388 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX); | |
2389 | tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL); | |
2390 | tx_queue = efx_channel_get_tx_queue(channel, | |
2391 | tx_ev_q_label % EFX_TXQ_TYPES); | |
2392 | tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) & | |
2393 | tx_queue->ptr_mask); | |
2394 | efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask); | |
2395 | ||
2396 | return tx_descs; | |
2397 | } | |
2398 | ||
2399 | static void | |
2400 | efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) | |
2401 | { | |
2402 | struct efx_nic *efx = channel->efx; | |
2403 | int subcode; | |
2404 | ||
2405 | subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE); | |
2406 | ||
2407 | switch (subcode) { | |
2408 | case ESE_DZ_DRV_TIMER_EV: | |
2409 | case ESE_DZ_DRV_WAKE_UP_EV: | |
2410 | break; | |
2411 | case ESE_DZ_DRV_START_UP_EV: | |
2412 | /* event queue init complete. ok. */ | |
2413 | break; | |
2414 | default: | |
2415 | netif_err(efx, hw, efx->net_dev, | |
2416 | "channel %d unknown driver event type %d" | |
2417 | " (data " EFX_QWORD_FMT ")\n", | |
2418 | channel->channel, subcode, | |
2419 | EFX_QWORD_VAL(*event)); | |
2420 | ||
2421 | } | |
2422 | } | |
2423 | ||
2424 | static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel, | |
2425 | efx_qword_t *event) | |
2426 | { | |
2427 | struct efx_nic *efx = channel->efx; | |
2428 | u32 subcode; | |
2429 | ||
2430 | subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0); | |
2431 | ||
2432 | switch (subcode) { | |
2433 | case EFX_EF10_TEST: | |
2434 | channel->event_test_cpu = raw_smp_processor_id(); | |
2435 | break; | |
2436 | case EFX_EF10_REFILL: | |
2437 | /* The queue must be empty, so we won't receive any rx | |
2438 | * events, so efx_process_channel() won't refill the | |
2439 | * queue. Refill it here | |
2440 | */ | |
cce28794 | 2441 | efx_fast_push_rx_descriptors(&channel->rx_queue, true); |
8127d661 BH |
2442 | break; |
2443 | default: | |
2444 | netif_err(efx, hw, efx->net_dev, | |
2445 | "channel %d unknown driver event type %u" | |
2446 | " (data " EFX_QWORD_FMT ")\n", | |
2447 | channel->channel, (unsigned) subcode, | |
2448 | EFX_QWORD_VAL(*event)); | |
2449 | } | |
2450 | } | |
2451 | ||
2452 | static int efx_ef10_ev_process(struct efx_channel *channel, int quota) | |
2453 | { | |
2454 | struct efx_nic *efx = channel->efx; | |
2455 | efx_qword_t event, *p_event; | |
2456 | unsigned int read_ptr; | |
2457 | int ev_code; | |
2458 | int tx_descs = 0; | |
2459 | int spent = 0; | |
2460 | ||
75363a46 EB |
2461 | if (quota <= 0) |
2462 | return spent; | |
2463 | ||
8127d661 BH |
2464 | read_ptr = channel->eventq_read_ptr; |
2465 | ||
2466 | for (;;) { | |
2467 | p_event = efx_event(channel, read_ptr); | |
2468 | event = *p_event; | |
2469 | ||
2470 | if (!efx_event_present(&event)) | |
2471 | break; | |
2472 | ||
2473 | EFX_SET_QWORD(*p_event); | |
2474 | ||
2475 | ++read_ptr; | |
2476 | ||
2477 | ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE); | |
2478 | ||
2479 | netif_vdbg(efx, drv, efx->net_dev, | |
2480 | "processing event on %d " EFX_QWORD_FMT "\n", | |
2481 | channel->channel, EFX_QWORD_VAL(event)); | |
2482 | ||
2483 | switch (ev_code) { | |
2484 | case ESE_DZ_EV_CODE_MCDI_EV: | |
2485 | efx_mcdi_process_event(channel, &event); | |
2486 | break; | |
2487 | case ESE_DZ_EV_CODE_RX_EV: | |
2488 | spent += efx_ef10_handle_rx_event(channel, &event); | |
2489 | if (spent >= quota) { | |
2490 | /* XXX can we split a merged event to | |
2491 | * avoid going over-quota? | |
2492 | */ | |
2493 | spent = quota; | |
2494 | goto out; | |
2495 | } | |
2496 | break; | |
2497 | case ESE_DZ_EV_CODE_TX_EV: | |
2498 | tx_descs += efx_ef10_handle_tx_event(channel, &event); | |
2499 | if (tx_descs > efx->txq_entries) { | |
2500 | spent = quota; | |
2501 | goto out; | |
2502 | } else if (++spent == quota) { | |
2503 | goto out; | |
2504 | } | |
2505 | break; | |
2506 | case ESE_DZ_EV_CODE_DRIVER_EV: | |
2507 | efx_ef10_handle_driver_event(channel, &event); | |
2508 | if (++spent == quota) | |
2509 | goto out; | |
2510 | break; | |
2511 | case EFX_EF10_DRVGEN_EV: | |
2512 | efx_ef10_handle_driver_generated_event(channel, &event); | |
2513 | break; | |
2514 | default: | |
2515 | netif_err(efx, hw, efx->net_dev, | |
2516 | "channel %d unknown event type %d" | |
2517 | " (data " EFX_QWORD_FMT ")\n", | |
2518 | channel->channel, ev_code, | |
2519 | EFX_QWORD_VAL(event)); | |
2520 | } | |
2521 | } | |
2522 | ||
2523 | out: | |
2524 | channel->eventq_read_ptr = read_ptr; | |
2525 | return spent; | |
2526 | } | |
2527 | ||
2528 | static void efx_ef10_ev_read_ack(struct efx_channel *channel) | |
2529 | { | |
2530 | struct efx_nic *efx = channel->efx; | |
2531 | efx_dword_t rptr; | |
2532 | ||
2533 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
2534 | BUILD_BUG_ON(EFX_MIN_EVQ_SIZE < | |
2535 | (1 << ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
2536 | BUILD_BUG_ON(EFX_MAX_EVQ_SIZE > | |
2537 | (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
2538 | ||
2539 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
2540 | EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH, | |
2541 | ERF_DD_EVQ_IND_RPTR, | |
2542 | (channel->eventq_read_ptr & | |
2543 | channel->eventq_mask) >> | |
2544 | ERF_DD_EVQ_IND_RPTR_WIDTH); | |
2545 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
2546 | channel->channel); | |
2547 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
2548 | EFE_DD_EVQ_IND_RPTR_FLAGS_LOW, | |
2549 | ERF_DD_EVQ_IND_RPTR, | |
2550 | channel->eventq_read_ptr & | |
2551 | ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1)); | |
2552 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
2553 | channel->channel); | |
2554 | } else { | |
2555 | EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR, | |
2556 | channel->eventq_read_ptr & | |
2557 | channel->eventq_mask); | |
2558 | efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel); | |
2559 | } | |
2560 | } | |
2561 | ||
2562 | static void efx_ef10_ev_test_generate(struct efx_channel *channel) | |
2563 | { | |
2564 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
2565 | struct efx_nic *efx = channel->efx; | |
2566 | efx_qword_t event; | |
2567 | int rc; | |
2568 | ||
2569 | EFX_POPULATE_QWORD_2(event, | |
2570 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
2571 | ESF_DZ_EV_DATA, EFX_EF10_TEST); | |
2572 | ||
2573 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
2574 | ||
2575 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
2576 | * already swapped the data to little-endian order. | |
2577 | */ | |
2578 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
2579 | sizeof(efx_qword_t)); | |
2580 | ||
2581 | rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf), | |
2582 | NULL, 0, NULL); | |
2583 | if (rc != 0) | |
2584 | goto fail; | |
2585 | ||
2586 | return; | |
2587 | ||
2588 | fail: | |
2589 | WARN_ON(true); | |
2590 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
2591 | } | |
2592 | ||
2593 | void efx_ef10_handle_drain_event(struct efx_nic *efx) | |
2594 | { | |
2595 | if (atomic_dec_and_test(&efx->active_queues)) | |
2596 | wake_up(&efx->flush_wq); | |
2597 | ||
2598 | WARN_ON(atomic_read(&efx->active_queues) < 0); | |
2599 | } | |
2600 | ||
2601 | static int efx_ef10_fini_dmaq(struct efx_nic *efx) | |
2602 | { | |
2603 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
2604 | struct efx_channel *channel; | |
2605 | struct efx_tx_queue *tx_queue; | |
2606 | struct efx_rx_queue *rx_queue; | |
2607 | int pending; | |
2608 | ||
2609 | /* If the MC has just rebooted, the TX/RX queues will have already been | |
2610 | * torn down, but efx->active_queues needs to be set to zero. | |
2611 | */ | |
2612 | if (nic_data->must_realloc_vis) { | |
2613 | atomic_set(&efx->active_queues, 0); | |
2614 | return 0; | |
2615 | } | |
2616 | ||
2617 | /* Do not attempt to write to the NIC during EEH recovery */ | |
2618 | if (efx->state != STATE_RECOVERY) { | |
2619 | efx_for_each_channel(channel, efx) { | |
2620 | efx_for_each_channel_rx_queue(rx_queue, channel) | |
2621 | efx_ef10_rx_fini(rx_queue); | |
2622 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
2623 | efx_ef10_tx_fini(tx_queue); | |
2624 | } | |
2625 | ||
2626 | wait_event_timeout(efx->flush_wq, | |
2627 | atomic_read(&efx->active_queues) == 0, | |
2628 | msecs_to_jiffies(EFX_MAX_FLUSH_TIME)); | |
2629 | pending = atomic_read(&efx->active_queues); | |
2630 | if (pending) { | |
2631 | netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n", | |
2632 | pending); | |
2633 | return -ETIMEDOUT; | |
2634 | } | |
2635 | } | |
2636 | ||
2637 | return 0; | |
2638 | } | |
2639 | ||
e283546c EC |
2640 | static void efx_ef10_prepare_flr(struct efx_nic *efx) |
2641 | { | |
2642 | atomic_set(&efx->active_queues, 0); | |
2643 | } | |
2644 | ||
8127d661 BH |
2645 | static bool efx_ef10_filter_equal(const struct efx_filter_spec *left, |
2646 | const struct efx_filter_spec *right) | |
2647 | { | |
2648 | if ((left->match_flags ^ right->match_flags) | | |
2649 | ((left->flags ^ right->flags) & | |
2650 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX))) | |
2651 | return false; | |
2652 | ||
2653 | return memcmp(&left->outer_vid, &right->outer_vid, | |
2654 | sizeof(struct efx_filter_spec) - | |
2655 | offsetof(struct efx_filter_spec, outer_vid)) == 0; | |
2656 | } | |
2657 | ||
2658 | static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec) | |
2659 | { | |
2660 | BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3); | |
2661 | return jhash2((const u32 *)&spec->outer_vid, | |
2662 | (sizeof(struct efx_filter_spec) - | |
2663 | offsetof(struct efx_filter_spec, outer_vid)) / 4, | |
2664 | 0); | |
2665 | /* XXX should we randomise the initval? */ | |
2666 | } | |
2667 | ||
2668 | /* Decide whether a filter should be exclusive or else should allow | |
2669 | * delivery to additional recipients. Currently we decide that | |
2670 | * filters for specific local unicast MAC and IP addresses are | |
2671 | * exclusive. | |
2672 | */ | |
2673 | static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec) | |
2674 | { | |
2675 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC && | |
2676 | !is_multicast_ether_addr(spec->loc_mac)) | |
2677 | return true; | |
2678 | ||
2679 | if ((spec->match_flags & | |
2680 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) == | |
2681 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) { | |
2682 | if (spec->ether_type == htons(ETH_P_IP) && | |
2683 | !ipv4_is_multicast(spec->loc_host[0])) | |
2684 | return true; | |
2685 | if (spec->ether_type == htons(ETH_P_IPV6) && | |
2686 | ((const u8 *)spec->loc_host)[0] != 0xff) | |
2687 | return true; | |
2688 | } | |
2689 | ||
2690 | return false; | |
2691 | } | |
2692 | ||
2693 | static struct efx_filter_spec * | |
2694 | efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table, | |
2695 | unsigned int filter_idx) | |
2696 | { | |
2697 | return (struct efx_filter_spec *)(table->entry[filter_idx].spec & | |
2698 | ~EFX_EF10_FILTER_FLAGS); | |
2699 | } | |
2700 | ||
2701 | static unsigned int | |
2702 | efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table, | |
2703 | unsigned int filter_idx) | |
2704 | { | |
2705 | return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS; | |
2706 | } | |
2707 | ||
2708 | static void | |
2709 | efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table, | |
2710 | unsigned int filter_idx, | |
2711 | const struct efx_filter_spec *spec, | |
2712 | unsigned int flags) | |
2713 | { | |
2714 | table->entry[filter_idx].spec = (unsigned long)spec | flags; | |
2715 | } | |
2716 | ||
2717 | static void efx_ef10_filter_push_prep(struct efx_nic *efx, | |
2718 | const struct efx_filter_spec *spec, | |
2719 | efx_dword_t *inbuf, u64 handle, | |
2720 | bool replacing) | |
2721 | { | |
2722 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
2723 | ||
2724 | memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN); | |
2725 | ||
2726 | if (replacing) { | |
2727 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2728 | MC_CMD_FILTER_OP_IN_OP_REPLACE); | |
2729 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle); | |
2730 | } else { | |
2731 | u32 match_fields = 0; | |
2732 | ||
2733 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2734 | efx_ef10_filter_is_exclusive(spec) ? | |
2735 | MC_CMD_FILTER_OP_IN_OP_INSERT : | |
2736 | MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE); | |
2737 | ||
2738 | /* Convert match flags and values. Unlike almost | |
2739 | * everything else in MCDI, these fields are in | |
2740 | * network byte order. | |
2741 | */ | |
2742 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) | |
2743 | match_fields |= | |
2744 | is_multicast_ether_addr(spec->loc_mac) ? | |
2745 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN : | |
2746 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN; | |
2747 | #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \ | |
2748 | if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \ | |
2749 | match_fields |= \ | |
2750 | 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
2751 | mcdi_field ## _LBN; \ | |
2752 | BUILD_BUG_ON( \ | |
2753 | MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \ | |
2754 | sizeof(spec->gen_field)); \ | |
2755 | memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \ | |
2756 | &spec->gen_field, sizeof(spec->gen_field)); \ | |
2757 | } | |
2758 | COPY_FIELD(REM_HOST, rem_host, SRC_IP); | |
2759 | COPY_FIELD(LOC_HOST, loc_host, DST_IP); | |
2760 | COPY_FIELD(REM_MAC, rem_mac, SRC_MAC); | |
2761 | COPY_FIELD(REM_PORT, rem_port, SRC_PORT); | |
2762 | COPY_FIELD(LOC_MAC, loc_mac, DST_MAC); | |
2763 | COPY_FIELD(LOC_PORT, loc_port, DST_PORT); | |
2764 | COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE); | |
2765 | COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN); | |
2766 | COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN); | |
2767 | COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO); | |
2768 | #undef COPY_FIELD | |
2769 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS, | |
2770 | match_fields); | |
2771 | } | |
2772 | ||
45b2449e | 2773 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
2774 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST, |
2775 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? | |
2776 | MC_CMD_FILTER_OP_IN_RX_DEST_DROP : | |
2777 | MC_CMD_FILTER_OP_IN_RX_DEST_HOST); | |
e3d36293 | 2778 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0); |
8127d661 BH |
2779 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST, |
2780 | MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT); | |
a0bc3487 BH |
2781 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE, |
2782 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? | |
2783 | 0 : spec->dmaq_id); | |
8127d661 BH |
2784 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE, |
2785 | (spec->flags & EFX_FILTER_FLAG_RX_RSS) ? | |
2786 | MC_CMD_FILTER_OP_IN_RX_MODE_RSS : | |
2787 | MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE); | |
2788 | if (spec->flags & EFX_FILTER_FLAG_RX_RSS) | |
2789 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, | |
2790 | spec->rss_context != | |
2791 | EFX_FILTER_RSS_CONTEXT_DEFAULT ? | |
2792 | spec->rss_context : nic_data->rx_rss_context); | |
2793 | } | |
2794 | ||
2795 | static int efx_ef10_filter_push(struct efx_nic *efx, | |
2796 | const struct efx_filter_spec *spec, | |
2797 | u64 *handle, bool replacing) | |
2798 | { | |
2799 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2800 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN); | |
2801 | int rc; | |
2802 | ||
2803 | efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing); | |
2804 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
2805 | outbuf, sizeof(outbuf), NULL); | |
2806 | if (rc == 0) | |
2807 | *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
065e64c4 BH |
2808 | if (rc == -ENOSPC) |
2809 | rc = -EBUSY; /* to match efx_farch_filter_insert() */ | |
8127d661 BH |
2810 | return rc; |
2811 | } | |
2812 | ||
2813 | static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table, | |
2814 | enum efx_filter_match_flags match_flags) | |
2815 | { | |
2816 | unsigned int match_pri; | |
2817 | ||
2818 | for (match_pri = 0; | |
2819 | match_pri < table->rx_match_count; | |
2820 | match_pri++) | |
2821 | if (table->rx_match_flags[match_pri] == match_flags) | |
2822 | return match_pri; | |
2823 | ||
2824 | return -EPROTONOSUPPORT; | |
2825 | } | |
2826 | ||
2827 | static s32 efx_ef10_filter_insert(struct efx_nic *efx, | |
2828 | struct efx_filter_spec *spec, | |
2829 | bool replace_equal) | |
2830 | { | |
2831 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2832 | DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
2833 | struct efx_filter_spec *saved_spec; | |
2834 | unsigned int match_pri, hash; | |
2835 | unsigned int priv_flags; | |
2836 | bool replacing = false; | |
2837 | int ins_index = -1; | |
2838 | DEFINE_WAIT(wait); | |
2839 | bool is_mc_recip; | |
2840 | s32 rc; | |
2841 | ||
2842 | /* For now, only support RX filters */ | |
2843 | if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != | |
2844 | EFX_FILTER_FLAG_RX) | |
2845 | return -EINVAL; | |
2846 | ||
2847 | rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags); | |
2848 | if (rc < 0) | |
2849 | return rc; | |
2850 | match_pri = rc; | |
2851 | ||
2852 | hash = efx_ef10_filter_hash(spec); | |
2853 | is_mc_recip = efx_filter_is_mc_recipient(spec); | |
2854 | if (is_mc_recip) | |
2855 | bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
2856 | ||
2857 | /* Find any existing filters with the same match tuple or | |
2858 | * else a free slot to insert at. If any of them are busy, | |
2859 | * we have to wait and retry. | |
2860 | */ | |
2861 | for (;;) { | |
2862 | unsigned int depth = 1; | |
2863 | unsigned int i; | |
2864 | ||
2865 | spin_lock_bh(&efx->filter_lock); | |
2866 | ||
2867 | for (;;) { | |
2868 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2869 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2870 | ||
2871 | if (!saved_spec) { | |
2872 | if (ins_index < 0) | |
2873 | ins_index = i; | |
2874 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
2875 | if (table->entry[i].spec & | |
2876 | EFX_EF10_FILTER_FLAG_BUSY) | |
2877 | break; | |
2878 | if (spec->priority < saved_spec->priority && | |
7665d1ab | 2879 | spec->priority != EFX_FILTER_PRI_AUTO) { |
8127d661 BH |
2880 | rc = -EPERM; |
2881 | goto out_unlock; | |
2882 | } | |
2883 | if (!is_mc_recip) { | |
2884 | /* This is the only one */ | |
2885 | if (spec->priority == | |
2886 | saved_spec->priority && | |
2887 | !replace_equal) { | |
2888 | rc = -EEXIST; | |
2889 | goto out_unlock; | |
2890 | } | |
2891 | ins_index = i; | |
2892 | goto found; | |
2893 | } else if (spec->priority > | |
2894 | saved_spec->priority || | |
2895 | (spec->priority == | |
2896 | saved_spec->priority && | |
2897 | replace_equal)) { | |
2898 | if (ins_index < 0) | |
2899 | ins_index = i; | |
2900 | else | |
2901 | __set_bit(depth, mc_rem_map); | |
2902 | } | |
2903 | } | |
2904 | ||
2905 | /* Once we reach the maximum search depth, use | |
2906 | * the first suitable slot or return -EBUSY if | |
2907 | * there was none | |
2908 | */ | |
2909 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
2910 | if (ins_index < 0) { | |
2911 | rc = -EBUSY; | |
2912 | goto out_unlock; | |
2913 | } | |
2914 | goto found; | |
2915 | } | |
2916 | ||
2917 | ++depth; | |
2918 | } | |
2919 | ||
2920 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
2921 | spin_unlock_bh(&efx->filter_lock); | |
2922 | schedule(); | |
2923 | } | |
2924 | ||
2925 | found: | |
2926 | /* Create a software table entry if necessary, and mark it | |
2927 | * busy. We might yet fail to insert, but any attempt to | |
2928 | * insert a conflicting filter while we're waiting for the | |
2929 | * firmware must find the busy entry. | |
2930 | */ | |
2931 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2932 | if (saved_spec) { | |
7665d1ab BH |
2933 | if (spec->priority == EFX_FILTER_PRI_AUTO && |
2934 | saved_spec->priority >= EFX_FILTER_PRI_AUTO) { | |
8127d661 | 2935 | /* Just make sure it won't be removed */ |
7665d1ab BH |
2936 | if (saved_spec->priority > EFX_FILTER_PRI_AUTO) |
2937 | saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO; | |
8127d661 | 2938 | table->entry[ins_index].spec &= |
b59e6ef8 | 2939 | ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
8127d661 BH |
2940 | rc = ins_index; |
2941 | goto out_unlock; | |
2942 | } | |
2943 | replacing = true; | |
2944 | priv_flags = efx_ef10_filter_entry_flags(table, ins_index); | |
2945 | } else { | |
2946 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
2947 | if (!saved_spec) { | |
2948 | rc = -ENOMEM; | |
2949 | goto out_unlock; | |
2950 | } | |
2951 | *saved_spec = *spec; | |
2952 | priv_flags = 0; | |
2953 | } | |
2954 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
2955 | priv_flags | EFX_EF10_FILTER_FLAG_BUSY); | |
2956 | ||
2957 | /* Mark lower-priority multicast recipients busy prior to removal */ | |
2958 | if (is_mc_recip) { | |
2959 | unsigned int depth, i; | |
2960 | ||
2961 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
2962 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2963 | if (test_bit(depth, mc_rem_map)) | |
2964 | table->entry[i].spec |= | |
2965 | EFX_EF10_FILTER_FLAG_BUSY; | |
2966 | } | |
2967 | } | |
2968 | ||
2969 | spin_unlock_bh(&efx->filter_lock); | |
2970 | ||
2971 | rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, | |
2972 | replacing); | |
2973 | ||
2974 | /* Finalise the software table entry */ | |
2975 | spin_lock_bh(&efx->filter_lock); | |
2976 | if (rc == 0) { | |
2977 | if (replacing) { | |
2978 | /* Update the fields that may differ */ | |
7665d1ab BH |
2979 | if (saved_spec->priority == EFX_FILTER_PRI_AUTO) |
2980 | saved_spec->flags |= | |
2981 | EFX_FILTER_FLAG_RX_OVER_AUTO; | |
8127d661 | 2982 | saved_spec->priority = spec->priority; |
7665d1ab | 2983 | saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO; |
8127d661 BH |
2984 | saved_spec->flags |= spec->flags; |
2985 | saved_spec->rss_context = spec->rss_context; | |
2986 | saved_spec->dmaq_id = spec->dmaq_id; | |
2987 | } | |
2988 | } else if (!replacing) { | |
2989 | kfree(saved_spec); | |
2990 | saved_spec = NULL; | |
2991 | } | |
2992 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); | |
2993 | ||
2994 | /* Remove and finalise entries for lower-priority multicast | |
2995 | * recipients | |
2996 | */ | |
2997 | if (is_mc_recip) { | |
2998 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2999 | unsigned int depth, i; | |
3000 | ||
3001 | memset(inbuf, 0, sizeof(inbuf)); | |
3002 | ||
3003 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
3004 | if (!test_bit(depth, mc_rem_map)) | |
3005 | continue; | |
3006 | ||
3007 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
3008 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
3009 | priv_flags = efx_ef10_filter_entry_flags(table, i); | |
3010 | ||
3011 | if (rc == 0) { | |
3012 | spin_unlock_bh(&efx->filter_lock); | |
3013 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3014 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
3015 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3016 | table->entry[i].handle); | |
3017 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
3018 | inbuf, sizeof(inbuf), | |
3019 | NULL, 0, NULL); | |
3020 | spin_lock_bh(&efx->filter_lock); | |
3021 | } | |
3022 | ||
3023 | if (rc == 0) { | |
3024 | kfree(saved_spec); | |
3025 | saved_spec = NULL; | |
3026 | priv_flags = 0; | |
3027 | } else { | |
3028 | priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
3029 | } | |
3030 | efx_ef10_filter_set_entry(table, i, saved_spec, | |
3031 | priv_flags); | |
3032 | } | |
3033 | } | |
3034 | ||
3035 | /* If successful, return the inserted filter ID */ | |
3036 | if (rc == 0) | |
3037 | rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index; | |
3038 | ||
3039 | wake_up_all(&table->waitq); | |
3040 | out_unlock: | |
3041 | spin_unlock_bh(&efx->filter_lock); | |
3042 | finish_wait(&table->waitq, &wait); | |
3043 | return rc; | |
3044 | } | |
3045 | ||
9fd8095d | 3046 | static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx) |
8127d661 BH |
3047 | { |
3048 | /* no need to do anything here on EF10 */ | |
3049 | } | |
3050 | ||
3051 | /* Remove a filter. | |
b59e6ef8 BH |
3052 | * If !by_index, remove by ID |
3053 | * If by_index, remove by index | |
8127d661 BH |
3054 | * Filter ID may come from userland and must be range-checked. |
3055 | */ | |
3056 | static int efx_ef10_filter_remove_internal(struct efx_nic *efx, | |
fbd79120 | 3057 | unsigned int priority_mask, |
b59e6ef8 | 3058 | u32 filter_id, bool by_index) |
8127d661 BH |
3059 | { |
3060 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
3061 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3062 | MCDI_DECLARE_BUF(inbuf, | |
3063 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
3064 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
3065 | struct efx_filter_spec *spec; | |
3066 | DEFINE_WAIT(wait); | |
3067 | int rc; | |
3068 | ||
3069 | /* Find the software table entry and mark it busy. Don't | |
3070 | * remove it yet; any attempt to update while we're waiting | |
3071 | * for the firmware must find the busy entry. | |
3072 | */ | |
3073 | for (;;) { | |
3074 | spin_lock_bh(&efx->filter_lock); | |
3075 | if (!(table->entry[filter_idx].spec & | |
3076 | EFX_EF10_FILTER_FLAG_BUSY)) | |
3077 | break; | |
3078 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
3079 | spin_unlock_bh(&efx->filter_lock); | |
3080 | schedule(); | |
3081 | } | |
7665d1ab | 3082 | |
8127d661 | 3083 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
7665d1ab | 3084 | if (!spec || |
b59e6ef8 | 3085 | (!by_index && |
8127d661 BH |
3086 | efx_ef10_filter_rx_match_pri(table, spec->match_flags) != |
3087 | filter_id / HUNT_FILTER_TBL_ROWS)) { | |
3088 | rc = -ENOENT; | |
3089 | goto out_unlock; | |
3090 | } | |
7665d1ab BH |
3091 | |
3092 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO && | |
fbd79120 | 3093 | priority_mask == (1U << EFX_FILTER_PRI_AUTO)) { |
7665d1ab BH |
3094 | /* Just remove flags */ |
3095 | spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO; | |
b59e6ef8 | 3096 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
7665d1ab BH |
3097 | rc = 0; |
3098 | goto out_unlock; | |
3099 | } | |
3100 | ||
fbd79120 | 3101 | if (!(priority_mask & (1U << spec->priority))) { |
7665d1ab BH |
3102 | rc = -ENOENT; |
3103 | goto out_unlock; | |
3104 | } | |
3105 | ||
8127d661 BH |
3106 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
3107 | spin_unlock_bh(&efx->filter_lock); | |
3108 | ||
7665d1ab | 3109 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { |
b59e6ef8 | 3110 | /* Reset to an automatic filter */ |
8127d661 BH |
3111 | |
3112 | struct efx_filter_spec new_spec = *spec; | |
3113 | ||
7665d1ab | 3114 | new_spec.priority = EFX_FILTER_PRI_AUTO; |
8127d661 | 3115 | new_spec.flags = (EFX_FILTER_FLAG_RX | |
7665d1ab | 3116 | EFX_FILTER_FLAG_RX_RSS); |
8127d661 BH |
3117 | new_spec.dmaq_id = 0; |
3118 | new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT; | |
3119 | rc = efx_ef10_filter_push(efx, &new_spec, | |
3120 | &table->entry[filter_idx].handle, | |
3121 | true); | |
3122 | ||
3123 | spin_lock_bh(&efx->filter_lock); | |
3124 | if (rc == 0) | |
3125 | *spec = new_spec; | |
3126 | } else { | |
3127 | /* Really remove the filter */ | |
3128 | ||
3129 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3130 | efx_ef10_filter_is_exclusive(spec) ? | |
3131 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
3132 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
3133 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3134 | table->entry[filter_idx].handle); | |
3135 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
3136 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
3137 | ||
3138 | spin_lock_bh(&efx->filter_lock); | |
3139 | if (rc == 0) { | |
3140 | kfree(spec); | |
3141 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3142 | } | |
3143 | } | |
7665d1ab | 3144 | |
8127d661 BH |
3145 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
3146 | wake_up_all(&table->waitq); | |
3147 | out_unlock: | |
3148 | spin_unlock_bh(&efx->filter_lock); | |
3149 | finish_wait(&table->waitq, &wait); | |
3150 | return rc; | |
3151 | } | |
3152 | ||
3153 | static int efx_ef10_filter_remove_safe(struct efx_nic *efx, | |
3154 | enum efx_filter_priority priority, | |
3155 | u32 filter_id) | |
3156 | { | |
fbd79120 BH |
3157 | return efx_ef10_filter_remove_internal(efx, 1U << priority, |
3158 | filter_id, false); | |
8127d661 BH |
3159 | } |
3160 | ||
3161 | static int efx_ef10_filter_get_safe(struct efx_nic *efx, | |
3162 | enum efx_filter_priority priority, | |
3163 | u32 filter_id, struct efx_filter_spec *spec) | |
3164 | { | |
3165 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
3166 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3167 | const struct efx_filter_spec *saved_spec; | |
3168 | int rc; | |
3169 | ||
3170 | spin_lock_bh(&efx->filter_lock); | |
3171 | saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3172 | if (saved_spec && saved_spec->priority == priority && | |
3173 | efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) == | |
3174 | filter_id / HUNT_FILTER_TBL_ROWS) { | |
3175 | *spec = *saved_spec; | |
3176 | rc = 0; | |
3177 | } else { | |
3178 | rc = -ENOENT; | |
3179 | } | |
3180 | spin_unlock_bh(&efx->filter_lock); | |
3181 | return rc; | |
3182 | } | |
3183 | ||
fbd79120 | 3184 | static int efx_ef10_filter_clear_rx(struct efx_nic *efx, |
8127d661 BH |
3185 | enum efx_filter_priority priority) |
3186 | { | |
fbd79120 BH |
3187 | unsigned int priority_mask; |
3188 | unsigned int i; | |
3189 | int rc; | |
3190 | ||
3191 | priority_mask = (((1U << (priority + 1)) - 1) & | |
3192 | ~(1U << EFX_FILTER_PRI_AUTO)); | |
3193 | ||
3194 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { | |
3195 | rc = efx_ef10_filter_remove_internal(efx, priority_mask, | |
3196 | i, true); | |
3197 | if (rc && rc != -ENOENT) | |
3198 | return rc; | |
3199 | } | |
3200 | ||
3201 | return 0; | |
8127d661 BH |
3202 | } |
3203 | ||
3204 | static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, | |
3205 | enum efx_filter_priority priority) | |
3206 | { | |
3207 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3208 | unsigned int filter_idx; | |
3209 | s32 count = 0; | |
3210 | ||
3211 | spin_lock_bh(&efx->filter_lock); | |
3212 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3213 | if (table->entry[filter_idx].spec && | |
3214 | efx_ef10_filter_entry_spec(table, filter_idx)->priority == | |
3215 | priority) | |
3216 | ++count; | |
3217 | } | |
3218 | spin_unlock_bh(&efx->filter_lock); | |
3219 | return count; | |
3220 | } | |
3221 | ||
3222 | static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx) | |
3223 | { | |
3224 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3225 | ||
3226 | return table->rx_match_count * HUNT_FILTER_TBL_ROWS; | |
3227 | } | |
3228 | ||
3229 | static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx, | |
3230 | enum efx_filter_priority priority, | |
3231 | u32 *buf, u32 size) | |
3232 | { | |
3233 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3234 | struct efx_filter_spec *spec; | |
3235 | unsigned int filter_idx; | |
3236 | s32 count = 0; | |
3237 | ||
3238 | spin_lock_bh(&efx->filter_lock); | |
3239 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3240 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3241 | if (spec && spec->priority == priority) { | |
3242 | if (count == size) { | |
3243 | count = -EMSGSIZE; | |
3244 | break; | |
3245 | } | |
3246 | buf[count++] = (efx_ef10_filter_rx_match_pri( | |
3247 | table, spec->match_flags) * | |
3248 | HUNT_FILTER_TBL_ROWS + | |
3249 | filter_idx); | |
3250 | } | |
3251 | } | |
3252 | spin_unlock_bh(&efx->filter_lock); | |
3253 | return count; | |
3254 | } | |
3255 | ||
3256 | #ifdef CONFIG_RFS_ACCEL | |
3257 | ||
3258 | static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete; | |
3259 | ||
3260 | static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx, | |
3261 | struct efx_filter_spec *spec) | |
3262 | { | |
3263 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3264 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
3265 | struct efx_filter_spec *saved_spec; | |
3266 | unsigned int hash, i, depth = 1; | |
3267 | bool replacing = false; | |
3268 | int ins_index = -1; | |
3269 | u64 cookie; | |
3270 | s32 rc; | |
3271 | ||
3272 | /* Must be an RX filter without RSS and not for a multicast | |
3273 | * destination address (RFS only works for connected sockets). | |
3274 | * These restrictions allow us to pass only a tiny amount of | |
3275 | * data through to the completion function. | |
3276 | */ | |
3277 | EFX_WARN_ON_PARANOID(spec->flags != | |
3278 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER)); | |
3279 | EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT); | |
3280 | EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec)); | |
3281 | ||
3282 | hash = efx_ef10_filter_hash(spec); | |
3283 | ||
3284 | spin_lock_bh(&efx->filter_lock); | |
3285 | ||
3286 | /* Find any existing filter with the same match tuple or else | |
3287 | * a free slot to insert at. If an existing filter is busy, | |
3288 | * we have to give up. | |
3289 | */ | |
3290 | for (;;) { | |
3291 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
3292 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
3293 | ||
3294 | if (!saved_spec) { | |
3295 | if (ins_index < 0) | |
3296 | ins_index = i; | |
3297 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
3298 | if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) { | |
3299 | rc = -EBUSY; | |
3300 | goto fail_unlock; | |
3301 | } | |
8127d661 BH |
3302 | if (spec->priority < saved_spec->priority) { |
3303 | rc = -EPERM; | |
3304 | goto fail_unlock; | |
3305 | } | |
3306 | ins_index = i; | |
3307 | break; | |
3308 | } | |
3309 | ||
3310 | /* Once we reach the maximum search depth, use the | |
3311 | * first suitable slot or return -EBUSY if there was | |
3312 | * none | |
3313 | */ | |
3314 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
3315 | if (ins_index < 0) { | |
3316 | rc = -EBUSY; | |
3317 | goto fail_unlock; | |
3318 | } | |
3319 | break; | |
3320 | } | |
3321 | ||
3322 | ++depth; | |
3323 | } | |
3324 | ||
3325 | /* Create a software table entry if necessary, and mark it | |
3326 | * busy. We might yet fail to insert, but any attempt to | |
3327 | * insert a conflicting filter while we're waiting for the | |
3328 | * firmware must find the busy entry. | |
3329 | */ | |
3330 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
3331 | if (saved_spec) { | |
3332 | replacing = true; | |
3333 | } else { | |
3334 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
3335 | if (!saved_spec) { | |
3336 | rc = -ENOMEM; | |
3337 | goto fail_unlock; | |
3338 | } | |
3339 | *saved_spec = *spec; | |
3340 | } | |
3341 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
3342 | EFX_EF10_FILTER_FLAG_BUSY); | |
3343 | ||
3344 | spin_unlock_bh(&efx->filter_lock); | |
3345 | ||
3346 | /* Pack up the variables needed on completion */ | |
3347 | cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id; | |
3348 | ||
3349 | efx_ef10_filter_push_prep(efx, spec, inbuf, | |
3350 | table->entry[ins_index].handle, replacing); | |
3351 | efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
3352 | MC_CMD_FILTER_OP_OUT_LEN, | |
3353 | efx_ef10_filter_rfs_insert_complete, cookie); | |
3354 | ||
3355 | return ins_index; | |
3356 | ||
3357 | fail_unlock: | |
3358 | spin_unlock_bh(&efx->filter_lock); | |
3359 | return rc; | |
3360 | } | |
3361 | ||
3362 | static void | |
3363 | efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie, | |
3364 | int rc, efx_dword_t *outbuf, | |
3365 | size_t outlen_actual) | |
3366 | { | |
3367 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3368 | unsigned int ins_index, dmaq_id; | |
3369 | struct efx_filter_spec *spec; | |
3370 | bool replacing; | |
3371 | ||
3372 | /* Unpack the cookie */ | |
3373 | replacing = cookie >> 31; | |
3374 | ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1); | |
3375 | dmaq_id = cookie & 0xffff; | |
3376 | ||
3377 | spin_lock_bh(&efx->filter_lock); | |
3378 | spec = efx_ef10_filter_entry_spec(table, ins_index); | |
3379 | if (rc == 0) { | |
3380 | table->entry[ins_index].handle = | |
3381 | MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
3382 | if (replacing) | |
3383 | spec->dmaq_id = dmaq_id; | |
3384 | } else if (!replacing) { | |
3385 | kfree(spec); | |
3386 | spec = NULL; | |
3387 | } | |
3388 | efx_ef10_filter_set_entry(table, ins_index, spec, 0); | |
3389 | spin_unlock_bh(&efx->filter_lock); | |
3390 | ||
3391 | wake_up_all(&table->waitq); | |
3392 | } | |
3393 | ||
3394 | static void | |
3395 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
3396 | unsigned long filter_idx, | |
3397 | int rc, efx_dword_t *outbuf, | |
3398 | size_t outlen_actual); | |
3399 | ||
3400 | static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, | |
3401 | unsigned int filter_idx) | |
3402 | { | |
3403 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3404 | struct efx_filter_spec *spec = | |
3405 | efx_ef10_filter_entry_spec(table, filter_idx); | |
3406 | MCDI_DECLARE_BUF(inbuf, | |
3407 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
3408 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
3409 | ||
3410 | if (!spec || | |
3411 | (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) || | |
3412 | spec->priority != EFX_FILTER_PRI_HINT || | |
3413 | !rps_may_expire_flow(efx->net_dev, spec->dmaq_id, | |
3414 | flow_id, filter_idx)) | |
3415 | return false; | |
3416 | ||
3417 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3418 | MC_CMD_FILTER_OP_IN_OP_REMOVE); | |
3419 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3420 | table->entry[filter_idx].handle); | |
3421 | if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0, | |
3422 | efx_ef10_filter_rfs_expire_complete, filter_idx)) | |
3423 | return false; | |
3424 | ||
3425 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
3426 | return true; | |
3427 | } | |
3428 | ||
3429 | static void | |
3430 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
3431 | unsigned long filter_idx, | |
3432 | int rc, efx_dword_t *outbuf, | |
3433 | size_t outlen_actual) | |
3434 | { | |
3435 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3436 | struct efx_filter_spec *spec = | |
3437 | efx_ef10_filter_entry_spec(table, filter_idx); | |
3438 | ||
3439 | spin_lock_bh(&efx->filter_lock); | |
3440 | if (rc == 0) { | |
3441 | kfree(spec); | |
3442 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3443 | } | |
3444 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
3445 | wake_up_all(&table->waitq); | |
3446 | spin_unlock_bh(&efx->filter_lock); | |
3447 | } | |
3448 | ||
3449 | #endif /* CONFIG_RFS_ACCEL */ | |
3450 | ||
3451 | static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags) | |
3452 | { | |
3453 | int match_flags = 0; | |
3454 | ||
3455 | #define MAP_FLAG(gen_flag, mcdi_field) { \ | |
3456 | u32 old_mcdi_flags = mcdi_flags; \ | |
3457 | mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
3458 | mcdi_field ## _LBN); \ | |
3459 | if (mcdi_flags != old_mcdi_flags) \ | |
3460 | match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \ | |
3461 | } | |
3462 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST); | |
3463 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST); | |
3464 | MAP_FLAG(REM_HOST, SRC_IP); | |
3465 | MAP_FLAG(LOC_HOST, DST_IP); | |
3466 | MAP_FLAG(REM_MAC, SRC_MAC); | |
3467 | MAP_FLAG(REM_PORT, SRC_PORT); | |
3468 | MAP_FLAG(LOC_MAC, DST_MAC); | |
3469 | MAP_FLAG(LOC_PORT, DST_PORT); | |
3470 | MAP_FLAG(ETHER_TYPE, ETHER_TYPE); | |
3471 | MAP_FLAG(INNER_VID, INNER_VLAN); | |
3472 | MAP_FLAG(OUTER_VID, OUTER_VLAN); | |
3473 | MAP_FLAG(IP_PROTO, IP_PROTO); | |
3474 | #undef MAP_FLAG | |
3475 | ||
3476 | /* Did we map them all? */ | |
3477 | if (mcdi_flags) | |
3478 | return -EINVAL; | |
3479 | ||
3480 | return match_flags; | |
3481 | } | |
3482 | ||
3483 | static int efx_ef10_filter_table_probe(struct efx_nic *efx) | |
3484 | { | |
3485 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN); | |
3486 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX); | |
3487 | unsigned int pd_match_pri, pd_match_count; | |
3488 | struct efx_ef10_filter_table *table; | |
3489 | size_t outlen; | |
3490 | int rc; | |
3491 | ||
3492 | table = kzalloc(sizeof(*table), GFP_KERNEL); | |
3493 | if (!table) | |
3494 | return -ENOMEM; | |
3495 | ||
3496 | /* Find out which RX filter types are supported, and their priorities */ | |
3497 | MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP, | |
3498 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES); | |
3499 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO, | |
3500 | inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), | |
3501 | &outlen); | |
3502 | if (rc) | |
3503 | goto fail; | |
3504 | pd_match_count = MCDI_VAR_ARRAY_LEN( | |
3505 | outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES); | |
3506 | table->rx_match_count = 0; | |
3507 | ||
3508 | for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) { | |
3509 | u32 mcdi_flags = | |
3510 | MCDI_ARRAY_DWORD( | |
3511 | outbuf, | |
3512 | GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES, | |
3513 | pd_match_pri); | |
3514 | rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags); | |
3515 | if (rc < 0) { | |
3516 | netif_dbg(efx, probe, efx->net_dev, | |
3517 | "%s: fw flags %#x pri %u not supported in driver\n", | |
3518 | __func__, mcdi_flags, pd_match_pri); | |
3519 | } else { | |
3520 | netif_dbg(efx, probe, efx->net_dev, | |
3521 | "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", | |
3522 | __func__, mcdi_flags, pd_match_pri, | |
3523 | rc, table->rx_match_count); | |
3524 | table->rx_match_flags[table->rx_match_count++] = rc; | |
3525 | } | |
3526 | } | |
3527 | ||
3528 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); | |
3529 | if (!table->entry) { | |
3530 | rc = -ENOMEM; | |
3531 | goto fail; | |
3532 | } | |
3533 | ||
3534 | efx->filter_state = table; | |
3535 | init_waitqueue_head(&table->waitq); | |
3536 | return 0; | |
3537 | ||
3538 | fail: | |
3539 | kfree(table); | |
3540 | return rc; | |
3541 | } | |
3542 | ||
0d322413 EC |
3543 | /* Caller must hold efx->filter_sem for read if race against |
3544 | * efx_ef10_filter_table_remove() is possible | |
3545 | */ | |
8127d661 BH |
3546 | static void efx_ef10_filter_table_restore(struct efx_nic *efx) |
3547 | { | |
3548 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3549 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
3550 | struct efx_filter_spec *spec; | |
3551 | unsigned int filter_idx; | |
3552 | bool failed = false; | |
3553 | int rc; | |
3554 | ||
0d322413 EC |
3555 | WARN_ON(!rwsem_is_locked(&efx->filter_sem)); |
3556 | ||
8127d661 BH |
3557 | if (!nic_data->must_restore_filters) |
3558 | return; | |
3559 | ||
0d322413 EC |
3560 | if (!table) |
3561 | return; | |
3562 | ||
8127d661 BH |
3563 | spin_lock_bh(&efx->filter_lock); |
3564 | ||
3565 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3566 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3567 | if (!spec) | |
3568 | continue; | |
3569 | ||
3570 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
3571 | spin_unlock_bh(&efx->filter_lock); | |
3572 | ||
3573 | rc = efx_ef10_filter_push(efx, spec, | |
3574 | &table->entry[filter_idx].handle, | |
3575 | false); | |
3576 | if (rc) | |
3577 | failed = true; | |
3578 | ||
3579 | spin_lock_bh(&efx->filter_lock); | |
3580 | if (rc) { | |
3581 | kfree(spec); | |
3582 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3583 | } else { | |
3584 | table->entry[filter_idx].spec &= | |
3585 | ~EFX_EF10_FILTER_FLAG_BUSY; | |
3586 | } | |
3587 | } | |
3588 | ||
3589 | spin_unlock_bh(&efx->filter_lock); | |
3590 | ||
3591 | if (failed) | |
3592 | netif_err(efx, hw, efx->net_dev, | |
3593 | "unable to restore all filters\n"); | |
3594 | else | |
3595 | nic_data->must_restore_filters = false; | |
3596 | } | |
3597 | ||
0d322413 | 3598 | /* Caller must hold efx->filter_sem for write */ |
8127d661 BH |
3599 | static void efx_ef10_filter_table_remove(struct efx_nic *efx) |
3600 | { | |
3601 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3602 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
3603 | struct efx_filter_spec *spec; | |
3604 | unsigned int filter_idx; | |
3605 | int rc; | |
3606 | ||
0d322413 EC |
3607 | efx->filter_state = NULL; |
3608 | if (!table) | |
3609 | return; | |
3610 | ||
8127d661 BH |
3611 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
3612 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3613 | if (!spec) | |
3614 | continue; | |
3615 | ||
3616 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3617 | efx_ef10_filter_is_exclusive(spec) ? | |
3618 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
3619 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
3620 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3621 | table->entry[filter_idx].handle); | |
3622 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
3623 | NULL, 0, NULL); | |
48ce5634 BH |
3624 | if (rc) |
3625 | netdev_WARN(efx->net_dev, | |
3626 | "filter_idx=%#x handle=%#llx\n", | |
3627 | filter_idx, | |
3628 | table->entry[filter_idx].handle); | |
8127d661 BH |
3629 | kfree(spec); |
3630 | } | |
3631 | ||
3632 | vfree(table->entry); | |
3633 | kfree(table); | |
3634 | } | |
3635 | ||
0d322413 EC |
3636 | /* Caller must hold efx->filter_sem for read if race against |
3637 | * efx_ef10_filter_table_remove() is possible | |
3638 | */ | |
8127d661 BH |
3639 | static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx) |
3640 | { | |
3641 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3642 | struct net_device *net_dev = efx->net_dev; | |
3643 | struct efx_filter_spec spec; | |
3644 | bool remove_failed = false; | |
3645 | struct netdev_hw_addr *uc; | |
3646 | struct netdev_hw_addr *mc; | |
3647 | unsigned int filter_idx; | |
3648 | int i, n, rc; | |
3649 | ||
3650 | if (!efx_dev_registered(efx)) | |
3651 | return; | |
3652 | ||
0d322413 EC |
3653 | if (!table) |
3654 | return; | |
3655 | ||
8127d661 BH |
3656 | /* Mark old filters that may need to be removed */ |
3657 | spin_lock_bh(&efx->filter_lock); | |
b59e6ef8 | 3658 | n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count; |
8127d661 | 3659 | for (i = 0; i < n; i++) { |
b59e6ef8 BH |
3660 | filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS; |
3661 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; | |
8127d661 | 3662 | } |
b59e6ef8 | 3663 | n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count; |
8127d661 | 3664 | for (i = 0; i < n; i++) { |
b59e6ef8 BH |
3665 | filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS; |
3666 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; | |
8127d661 BH |
3667 | } |
3668 | spin_unlock_bh(&efx->filter_lock); | |
3669 | ||
3670 | /* Copy/convert the address lists; add the primary station | |
3671 | * address and broadcast address | |
3672 | */ | |
3673 | netif_addr_lock_bh(net_dev); | |
3674 | if (net_dev->flags & IFF_PROMISC || | |
b59e6ef8 BH |
3675 | netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) { |
3676 | table->dev_uc_count = -1; | |
8127d661 | 3677 | } else { |
b59e6ef8 | 3678 | table->dev_uc_count = 1 + netdev_uc_count(net_dev); |
cd84ff4d | 3679 | ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr); |
8127d661 BH |
3680 | i = 1; |
3681 | netdev_for_each_uc_addr(uc, net_dev) { | |
cd84ff4d | 3682 | ether_addr_copy(table->dev_uc_list[i].addr, uc->addr); |
8127d661 BH |
3683 | i++; |
3684 | } | |
3685 | } | |
3686 | if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) || | |
b59e6ef8 BH |
3687 | netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) { |
3688 | table->dev_mc_count = -1; | |
8127d661 | 3689 | } else { |
b59e6ef8 BH |
3690 | table->dev_mc_count = 1 + netdev_mc_count(net_dev); |
3691 | eth_broadcast_addr(table->dev_mc_list[0].addr); | |
8127d661 BH |
3692 | i = 1; |
3693 | netdev_for_each_mc_addr(mc, net_dev) { | |
cd84ff4d | 3694 | ether_addr_copy(table->dev_mc_list[i].addr, mc->addr); |
8127d661 BH |
3695 | i++; |
3696 | } | |
3697 | } | |
3698 | netif_addr_unlock_bh(net_dev); | |
3699 | ||
3700 | /* Insert/renew unicast filters */ | |
b59e6ef8 BH |
3701 | if (table->dev_uc_count >= 0) { |
3702 | for (i = 0; i < table->dev_uc_count; i++) { | |
7665d1ab BH |
3703 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3704 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3705 | 0); |
3706 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
b59e6ef8 | 3707 | table->dev_uc_list[i].addr); |
8127d661 BH |
3708 | rc = efx_ef10_filter_insert(efx, &spec, true); |
3709 | if (rc < 0) { | |
3710 | /* Fall back to unicast-promisc */ | |
3711 | while (i--) | |
3712 | efx_ef10_filter_remove_safe( | |
7665d1ab | 3713 | efx, EFX_FILTER_PRI_AUTO, |
b59e6ef8 BH |
3714 | table->dev_uc_list[i].id); |
3715 | table->dev_uc_count = -1; | |
8127d661 BH |
3716 | break; |
3717 | } | |
b59e6ef8 | 3718 | table->dev_uc_list[i].id = rc; |
8127d661 BH |
3719 | } |
3720 | } | |
b59e6ef8 | 3721 | if (table->dev_uc_count < 0) { |
7665d1ab BH |
3722 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3723 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3724 | 0); |
3725 | efx_filter_set_uc_def(&spec); | |
3726 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
3727 | if (rc < 0) { | |
3728 | WARN_ON(1); | |
b59e6ef8 | 3729 | table->dev_uc_count = 0; |
8127d661 | 3730 | } else { |
b59e6ef8 | 3731 | table->dev_uc_list[0].id = rc; |
8127d661 BH |
3732 | } |
3733 | } | |
3734 | ||
3735 | /* Insert/renew multicast filters */ | |
b59e6ef8 BH |
3736 | if (table->dev_mc_count >= 0) { |
3737 | for (i = 0; i < table->dev_mc_count; i++) { | |
7665d1ab BH |
3738 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3739 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3740 | 0); |
3741 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
b59e6ef8 | 3742 | table->dev_mc_list[i].addr); |
8127d661 BH |
3743 | rc = efx_ef10_filter_insert(efx, &spec, true); |
3744 | if (rc < 0) { | |
3745 | /* Fall back to multicast-promisc */ | |
3746 | while (i--) | |
3747 | efx_ef10_filter_remove_safe( | |
7665d1ab | 3748 | efx, EFX_FILTER_PRI_AUTO, |
b59e6ef8 BH |
3749 | table->dev_mc_list[i].id); |
3750 | table->dev_mc_count = -1; | |
8127d661 BH |
3751 | break; |
3752 | } | |
b59e6ef8 | 3753 | table->dev_mc_list[i].id = rc; |
8127d661 BH |
3754 | } |
3755 | } | |
b59e6ef8 | 3756 | if (table->dev_mc_count < 0) { |
7665d1ab BH |
3757 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3758 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3759 | 0); |
3760 | efx_filter_set_mc_def(&spec); | |
3761 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
3762 | if (rc < 0) { | |
3763 | WARN_ON(1); | |
b59e6ef8 | 3764 | table->dev_mc_count = 0; |
8127d661 | 3765 | } else { |
b59e6ef8 | 3766 | table->dev_mc_list[0].id = rc; |
8127d661 BH |
3767 | } |
3768 | } | |
3769 | ||
3770 | /* Remove filters that weren't renewed. Since nothing else | |
b59e6ef8 | 3771 | * changes the AUTO_OLD flag or removes these filters, we |
8127d661 BH |
3772 | * don't need to hold the filter_lock while scanning for |
3773 | * these filters. | |
3774 | */ | |
3775 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { | |
3776 | if (ACCESS_ONCE(table->entry[i].spec) & | |
b59e6ef8 | 3777 | EFX_EF10_FILTER_FLAG_AUTO_OLD) { |
7665d1ab | 3778 | if (efx_ef10_filter_remove_internal( |
fbd79120 BH |
3779 | efx, 1U << EFX_FILTER_PRI_AUTO, |
3780 | i, true) < 0) | |
8127d661 BH |
3781 | remove_failed = true; |
3782 | } | |
3783 | } | |
3784 | WARN_ON(remove_failed); | |
3785 | } | |
3786 | ||
910c8789 SS |
3787 | static int efx_ef10_set_mac_address(struct efx_nic *efx) |
3788 | { | |
3789 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN); | |
3790 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
3791 | bool was_enabled = efx->port_enabled; | |
3792 | int rc; | |
3793 | ||
3794 | efx_device_detach_sync(efx); | |
3795 | efx_net_stop(efx->net_dev); | |
3796 | down_write(&efx->filter_sem); | |
3797 | efx_ef10_filter_table_remove(efx); | |
3798 | ||
3799 | ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR), | |
3800 | efx->net_dev->dev_addr); | |
3801 | MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID, | |
3802 | nic_data->vport_id); | |
3803 | rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf, | |
3804 | sizeof(inbuf), NULL, 0, NULL); | |
3805 | ||
3806 | efx_ef10_filter_table_probe(efx); | |
3807 | up_write(&efx->filter_sem); | |
3808 | if (was_enabled) | |
3809 | efx_net_open(efx->net_dev); | |
3810 | netif_device_attach(efx->net_dev); | |
3811 | ||
3812 | #if !defined(CONFIG_SFC_SRIOV) | |
3813 | if (rc == -EPERM) | |
3814 | netif_err(efx, drv, efx->net_dev, | |
3815 | "Cannot change MAC address; use sfboot to enable mac-spoofing" | |
3816 | " on this interface\n"); | |
3817 | #else | |
3818 | if (rc == -EPERM) { | |
3819 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; | |
3820 | ||
3821 | /* Switch to PF and change MAC address on vport */ | |
3822 | if (efx->pci_dev->is_virtfn && pci_dev_pf) { | |
3823 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); | |
3824 | ||
3825 | if (!efx_ef10_sriov_set_vf_mac(efx_pf, | |
3826 | nic_data->vf_index, | |
3827 | efx->net_dev->dev_addr)) | |
3828 | return 0; | |
3829 | } | |
3830 | netif_err(efx, drv, efx->net_dev, | |
3831 | "Cannot change MAC address; use sfboot to enable mac-spoofing" | |
3832 | " on this interface\n"); | |
3833 | } else if (efx->pci_dev->is_virtfn) { | |
3834 | /* Successfully changed by VF (with MAC spoofing), so update the | |
3835 | * parent PF if possible. | |
3836 | */ | |
3837 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; | |
3838 | ||
3839 | if (pci_dev_pf) { | |
3840 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); | |
3841 | struct efx_ef10_nic_data *nic_data = efx_pf->nic_data; | |
3842 | unsigned int i; | |
3843 | ||
3844 | for (i = 0; i < efx_pf->vf_count; ++i) { | |
3845 | struct ef10_vf *vf = nic_data->vf + i; | |
3846 | ||
3847 | if (vf->efx == efx) { | |
3848 | ether_addr_copy(vf->mac, | |
3849 | efx->net_dev->dev_addr); | |
3850 | return 0; | |
3851 | } | |
3852 | } | |
3853 | } | |
3854 | } | |
3855 | #endif | |
3856 | return rc; | |
3857 | } | |
3858 | ||
8127d661 BH |
3859 | static int efx_ef10_mac_reconfigure(struct efx_nic *efx) |
3860 | { | |
3861 | efx_ef10_filter_sync_rx_mode(efx); | |
3862 | ||
3863 | return efx_mcdi_set_mac(efx); | |
3864 | } | |
3865 | ||
862f894c SS |
3866 | static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx) |
3867 | { | |
3868 | efx_ef10_filter_sync_rx_mode(efx); | |
3869 | ||
3870 | return 0; | |
3871 | } | |
3872 | ||
74cd60a4 JC |
3873 | static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type) |
3874 | { | |
3875 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); | |
3876 | ||
3877 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type); | |
3878 | return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf), | |
3879 | NULL, 0, NULL); | |
3880 | } | |
3881 | ||
3882 | /* MC BISTs follow a different poll mechanism to phy BISTs. | |
3883 | * The BIST is done in the poll handler on the MC, and the MCDI command | |
3884 | * will block until the BIST is done. | |
3885 | */ | |
3886 | static int efx_ef10_poll_bist(struct efx_nic *efx) | |
3887 | { | |
3888 | int rc; | |
3889 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN); | |
3890 | size_t outlen; | |
3891 | u32 result; | |
3892 | ||
3893 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, | |
3894 | outbuf, sizeof(outbuf), &outlen); | |
3895 | if (rc != 0) | |
3896 | return rc; | |
3897 | ||
3898 | if (outlen < MC_CMD_POLL_BIST_OUT_LEN) | |
3899 | return -EIO; | |
3900 | ||
3901 | result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); | |
3902 | switch (result) { | |
3903 | case MC_CMD_POLL_BIST_PASSED: | |
3904 | netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n"); | |
3905 | return 0; | |
3906 | case MC_CMD_POLL_BIST_TIMEOUT: | |
3907 | netif_err(efx, hw, efx->net_dev, "BIST timed out\n"); | |
3908 | return -EIO; | |
3909 | case MC_CMD_POLL_BIST_FAILED: | |
3910 | netif_err(efx, hw, efx->net_dev, "BIST failed.\n"); | |
3911 | return -EIO; | |
3912 | default: | |
3913 | netif_err(efx, hw, efx->net_dev, | |
3914 | "BIST returned unknown result %u", result); | |
3915 | return -EIO; | |
3916 | } | |
3917 | } | |
3918 | ||
3919 | static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type) | |
3920 | { | |
3921 | int rc; | |
3922 | ||
3923 | netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type); | |
3924 | ||
3925 | rc = efx_ef10_start_bist(efx, bist_type); | |
3926 | if (rc != 0) | |
3927 | return rc; | |
3928 | ||
3929 | return efx_ef10_poll_bist(efx); | |
3930 | } | |
3931 | ||
3932 | static int | |
3933 | efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) | |
3934 | { | |
3935 | int rc, rc2; | |
3936 | ||
3937 | efx_reset_down(efx, RESET_TYPE_WORLD); | |
3938 | ||
3939 | rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST, | |
3940 | NULL, 0, NULL, 0, NULL); | |
3941 | if (rc != 0) | |
3942 | goto out; | |
3943 | ||
3944 | tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1; | |
3945 | tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1; | |
3946 | ||
3947 | rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD); | |
3948 | ||
3949 | out: | |
3950 | rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0); | |
3951 | return rc ? rc : rc2; | |
3952 | } | |
3953 | ||
8127d661 BH |
3954 | #ifdef CONFIG_SFC_MTD |
3955 | ||
3956 | struct efx_ef10_nvram_type_info { | |
3957 | u16 type, type_mask; | |
3958 | u8 port; | |
3959 | const char *name; | |
3960 | }; | |
3961 | ||
3962 | static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { | |
3963 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" }, | |
3964 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" }, | |
3965 | { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" }, | |
3966 | { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" }, | |
3967 | { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" }, | |
3968 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" }, | |
3969 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" }, | |
3970 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" }, | |
3971 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" }, | |
a84f3bf9 | 3972 | { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" }, |
8127d661 BH |
3973 | { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, |
3974 | }; | |
3975 | ||
3976 | static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, | |
3977 | struct efx_mcdi_mtd_partition *part, | |
3978 | unsigned int type) | |
3979 | { | |
3980 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); | |
3981 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); | |
3982 | const struct efx_ef10_nvram_type_info *info; | |
3983 | size_t size, erase_size, outlen; | |
3984 | bool protected; | |
3985 | int rc; | |
3986 | ||
3987 | for (info = efx_ef10_nvram_types; ; info++) { | |
3988 | if (info == | |
3989 | efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) | |
3990 | return -ENODEV; | |
3991 | if ((type & ~info->type_mask) == info->type) | |
3992 | break; | |
3993 | } | |
3994 | if (info->port != efx_port_num(efx)) | |
3995 | return -ENODEV; | |
3996 | ||
3997 | rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected); | |
3998 | if (rc) | |
3999 | return rc; | |
4000 | if (protected) | |
4001 | return -ENODEV; /* hide it */ | |
4002 | ||
4003 | part->nvram_type = type; | |
4004 | ||
4005 | MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); | |
4006 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf), | |
4007 | outbuf, sizeof(outbuf), &outlen); | |
4008 | if (rc) | |
4009 | return rc; | |
4010 | if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) | |
4011 | return -EIO; | |
4012 | if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) & | |
4013 | (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) | |
4014 | part->fw_subtype = MCDI_DWORD(outbuf, | |
4015 | NVRAM_METADATA_OUT_SUBTYPE); | |
4016 | ||
4017 | part->common.dev_type_name = "EF10 NVRAM manager"; | |
4018 | part->common.type_name = info->name; | |
4019 | ||
4020 | part->common.mtd.type = MTD_NORFLASH; | |
4021 | part->common.mtd.flags = MTD_CAP_NORFLASH; | |
4022 | part->common.mtd.size = size; | |
4023 | part->common.mtd.erasesize = erase_size; | |
4024 | ||
4025 | return 0; | |
4026 | } | |
4027 | ||
4028 | static int efx_ef10_mtd_probe(struct efx_nic *efx) | |
4029 | { | |
4030 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); | |
4031 | struct efx_mcdi_mtd_partition *parts; | |
4032 | size_t outlen, n_parts_total, i, n_parts; | |
4033 | unsigned int type; | |
4034 | int rc; | |
4035 | ||
4036 | ASSERT_RTNL(); | |
4037 | ||
4038 | BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0); | |
4039 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0, | |
4040 | outbuf, sizeof(outbuf), &outlen); | |
4041 | if (rc) | |
4042 | return rc; | |
4043 | if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN) | |
4044 | return -EIO; | |
4045 | ||
4046 | n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS); | |
4047 | if (n_parts_total > | |
4048 | MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID)) | |
4049 | return -EIO; | |
4050 | ||
4051 | parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL); | |
4052 | if (!parts) | |
4053 | return -ENOMEM; | |
4054 | ||
4055 | n_parts = 0; | |
4056 | for (i = 0; i < n_parts_total; i++) { | |
4057 | type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, | |
4058 | i); | |
4059 | rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); | |
4060 | if (rc == 0) | |
4061 | n_parts++; | |
4062 | else if (rc != -ENODEV) | |
4063 | goto fail; | |
4064 | } | |
4065 | ||
4066 | rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); | |
4067 | fail: | |
4068 | if (rc) | |
4069 | kfree(parts); | |
4070 | return rc; | |
4071 | } | |
4072 | ||
4073 | #endif /* CONFIG_SFC_MTD */ | |
4074 | ||
4075 | static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time) | |
4076 | { | |
4077 | _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD); | |
4078 | } | |
4079 | ||
02246a7f SS |
4080 | static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx, |
4081 | u32 host_time) {} | |
4082 | ||
bd9a265d JC |
4083 | static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel, |
4084 | bool temp) | |
4085 | { | |
4086 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN); | |
4087 | int rc; | |
4088 | ||
4089 | if (channel->sync_events_state == SYNC_EVENTS_REQUESTED || | |
4090 | channel->sync_events_state == SYNC_EVENTS_VALID || | |
4091 | (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED)) | |
4092 | return 0; | |
4093 | channel->sync_events_state = SYNC_EVENTS_REQUESTED; | |
4094 | ||
4095 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE); | |
4096 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); | |
4097 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE, | |
4098 | channel->channel); | |
4099 | ||
4100 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, | |
4101 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
4102 | ||
4103 | if (rc != 0) | |
4104 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : | |
4105 | SYNC_EVENTS_DISABLED; | |
4106 | ||
4107 | return rc; | |
4108 | } | |
4109 | ||
4110 | static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel, | |
4111 | bool temp) | |
4112 | { | |
4113 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN); | |
4114 | int rc; | |
4115 | ||
4116 | if (channel->sync_events_state == SYNC_EVENTS_DISABLED || | |
4117 | (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT)) | |
4118 | return 0; | |
4119 | if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) { | |
4120 | channel->sync_events_state = SYNC_EVENTS_DISABLED; | |
4121 | return 0; | |
4122 | } | |
4123 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : | |
4124 | SYNC_EVENTS_DISABLED; | |
4125 | ||
4126 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE); | |
4127 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); | |
4128 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL, | |
4129 | MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE); | |
4130 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE, | |
4131 | channel->channel); | |
4132 | ||
4133 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, | |
4134 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
4135 | ||
4136 | return rc; | |
4137 | } | |
4138 | ||
4139 | static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en, | |
4140 | bool temp) | |
4141 | { | |
4142 | int (*set)(struct efx_channel *channel, bool temp); | |
4143 | struct efx_channel *channel; | |
4144 | ||
4145 | set = en ? | |
4146 | efx_ef10_rx_enable_timestamping : | |
4147 | efx_ef10_rx_disable_timestamping; | |
4148 | ||
4149 | efx_for_each_channel(channel, efx) { | |
4150 | int rc = set(channel, temp); | |
4151 | if (en && rc != 0) { | |
4152 | efx_ef10_ptp_set_ts_sync_events(efx, false, temp); | |
4153 | return rc; | |
4154 | } | |
4155 | } | |
4156 | ||
4157 | return 0; | |
4158 | } | |
4159 | ||
02246a7f SS |
4160 | static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx, |
4161 | struct hwtstamp_config *init) | |
4162 | { | |
4163 | return -EOPNOTSUPP; | |
4164 | } | |
4165 | ||
bd9a265d JC |
4166 | static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx, |
4167 | struct hwtstamp_config *init) | |
4168 | { | |
4169 | int rc; | |
4170 | ||
4171 | switch (init->rx_filter) { | |
4172 | case HWTSTAMP_FILTER_NONE: | |
4173 | efx_ef10_ptp_set_ts_sync_events(efx, false, false); | |
4174 | /* if TX timestamping is still requested then leave PTP on */ | |
4175 | return efx_ptp_change_mode(efx, | |
4176 | init->tx_type != HWTSTAMP_TX_OFF, 0); | |
4177 | case HWTSTAMP_FILTER_ALL: | |
4178 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: | |
4179 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: | |
4180 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: | |
4181 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: | |
4182 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: | |
4183 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: | |
4184 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: | |
4185 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: | |
4186 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: | |
4187 | case HWTSTAMP_FILTER_PTP_V2_EVENT: | |
4188 | case HWTSTAMP_FILTER_PTP_V2_SYNC: | |
4189 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: | |
4190 | init->rx_filter = HWTSTAMP_FILTER_ALL; | |
4191 | rc = efx_ptp_change_mode(efx, true, 0); | |
4192 | if (!rc) | |
4193 | rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false); | |
4194 | if (rc) | |
4195 | efx_ptp_change_mode(efx, false, 0); | |
4196 | return rc; | |
4197 | default: | |
4198 | return -ERANGE; | |
4199 | } | |
4200 | } | |
4201 | ||
02246a7f | 4202 | const struct efx_nic_type efx_hunt_a0_vf_nic_type = { |
6f7f8aa6 | 4203 | .is_vf = true, |
02246a7f SS |
4204 | .mem_bar = EFX_MEM_VF_BAR, |
4205 | .mem_map_size = efx_ef10_mem_map_size, | |
4206 | .probe = efx_ef10_probe_vf, | |
4207 | .remove = efx_ef10_remove, | |
4208 | .dimension_resources = efx_ef10_dimension_resources, | |
4209 | .init = efx_ef10_init_nic, | |
4210 | .fini = efx_port_dummy_op_void, | |
087e9025 | 4211 | .map_reset_reason = efx_ef10_map_reset_reason, |
02246a7f SS |
4212 | .map_reset_flags = efx_ef10_map_reset_flags, |
4213 | .reset = efx_ef10_reset, | |
4214 | .probe_port = efx_mcdi_port_probe, | |
4215 | .remove_port = efx_mcdi_port_remove, | |
4216 | .fini_dmaq = efx_ef10_fini_dmaq, | |
4217 | .prepare_flr = efx_ef10_prepare_flr, | |
4218 | .finish_flr = efx_port_dummy_op_void, | |
4219 | .describe_stats = efx_ef10_describe_stats, | |
d7788196 | 4220 | .update_stats = efx_ef10_update_stats_vf, |
02246a7f SS |
4221 | .start_stats = efx_port_dummy_op_void, |
4222 | .pull_stats = efx_port_dummy_op_void, | |
4223 | .stop_stats = efx_port_dummy_op_void, | |
4224 | .set_id_led = efx_mcdi_set_id_led, | |
4225 | .push_irq_moderation = efx_ef10_push_irq_moderation, | |
862f894c | 4226 | .reconfigure_mac = efx_ef10_mac_reconfigure_vf, |
02246a7f SS |
4227 | .check_mac_fault = efx_mcdi_mac_check_fault, |
4228 | .reconfigure_port = efx_mcdi_port_reconfigure, | |
4229 | .get_wol = efx_ef10_get_wol_vf, | |
4230 | .set_wol = efx_ef10_set_wol_vf, | |
4231 | .resume_wol = efx_port_dummy_op_void, | |
4232 | .mcdi_request = efx_ef10_mcdi_request, | |
4233 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, | |
4234 | .mcdi_read_response = efx_ef10_mcdi_read_response, | |
4235 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, | |
4236 | .irq_enable_master = efx_port_dummy_op_void, | |
4237 | .irq_test_generate = efx_ef10_irq_test_generate, | |
4238 | .irq_disable_non_ev = efx_port_dummy_op_void, | |
4239 | .irq_handle_msi = efx_ef10_msi_interrupt, | |
4240 | .irq_handle_legacy = efx_ef10_legacy_interrupt, | |
4241 | .tx_probe = efx_ef10_tx_probe, | |
4242 | .tx_init = efx_ef10_tx_init, | |
4243 | .tx_remove = efx_ef10_tx_remove, | |
4244 | .tx_write = efx_ef10_tx_write, | |
267c0157 | 4245 | .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config, |
02246a7f SS |
4246 | .rx_probe = efx_ef10_rx_probe, |
4247 | .rx_init = efx_ef10_rx_init, | |
4248 | .rx_remove = efx_ef10_rx_remove, | |
4249 | .rx_write = efx_ef10_rx_write, | |
4250 | .rx_defer_refill = efx_ef10_rx_defer_refill, | |
4251 | .ev_probe = efx_ef10_ev_probe, | |
4252 | .ev_init = efx_ef10_ev_init, | |
4253 | .ev_fini = efx_ef10_ev_fini, | |
4254 | .ev_remove = efx_ef10_ev_remove, | |
4255 | .ev_process = efx_ef10_ev_process, | |
4256 | .ev_read_ack = efx_ef10_ev_read_ack, | |
4257 | .ev_test_generate = efx_ef10_ev_test_generate, | |
4258 | .filter_table_probe = efx_ef10_filter_table_probe, | |
4259 | .filter_table_restore = efx_ef10_filter_table_restore, | |
4260 | .filter_table_remove = efx_ef10_filter_table_remove, | |
4261 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, | |
4262 | .filter_insert = efx_ef10_filter_insert, | |
4263 | .filter_remove_safe = efx_ef10_filter_remove_safe, | |
4264 | .filter_get_safe = efx_ef10_filter_get_safe, | |
4265 | .filter_clear_rx = efx_ef10_filter_clear_rx, | |
4266 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, | |
4267 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, | |
4268 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, | |
4269 | #ifdef CONFIG_RFS_ACCEL | |
4270 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, | |
4271 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, | |
4272 | #endif | |
4273 | #ifdef CONFIG_SFC_MTD | |
4274 | .mtd_probe = efx_port_dummy_op_int, | |
4275 | #endif | |
4276 | .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf, | |
4277 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf, | |
4278 | #ifdef CONFIG_SFC_SRIOV | |
7b8c7b54 SS |
4279 | .vswitching_probe = efx_ef10_vswitching_probe_vf, |
4280 | .vswitching_restore = efx_ef10_vswitching_restore_vf, | |
4281 | .vswitching_remove = efx_ef10_vswitching_remove_vf, | |
1d051e00 | 4282 | .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id, |
02246a7f | 4283 | #endif |
0d5e0fbb | 4284 | .get_mac_address = efx_ef10_get_mac_address_vf, |
910c8789 | 4285 | .set_mac_address = efx_ef10_set_mac_address, |
0d5e0fbb | 4286 | |
02246a7f SS |
4287 | .revision = EFX_REV_HUNT_A0, |
4288 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), | |
4289 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, | |
4290 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, | |
4291 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, | |
4292 | .can_rx_scatter = true, | |
4293 | .always_rx_scatter = true, | |
4294 | .max_interrupt_mode = EFX_INT_MODE_MSIX, | |
4295 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, | |
4296 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
4297 | NETIF_F_RXHASH | NETIF_F_NTUPLE), | |
4298 | .mcdi_max_ver = 2, | |
4299 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, | |
4300 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | | |
4301 | 1 << HWTSTAMP_FILTER_ALL, | |
4302 | }; | |
4303 | ||
8127d661 | 4304 | const struct efx_nic_type efx_hunt_a0_nic_type = { |
6f7f8aa6 | 4305 | .is_vf = false, |
02246a7f | 4306 | .mem_bar = EFX_MEM_BAR, |
8127d661 | 4307 | .mem_map_size = efx_ef10_mem_map_size, |
02246a7f | 4308 | .probe = efx_ef10_probe_pf, |
8127d661 BH |
4309 | .remove = efx_ef10_remove, |
4310 | .dimension_resources = efx_ef10_dimension_resources, | |
4311 | .init = efx_ef10_init_nic, | |
4312 | .fini = efx_port_dummy_op_void, | |
087e9025 | 4313 | .map_reset_reason = efx_ef10_map_reset_reason, |
8127d661 | 4314 | .map_reset_flags = efx_ef10_map_reset_flags, |
3e336261 | 4315 | .reset = efx_ef10_reset, |
8127d661 BH |
4316 | .probe_port = efx_mcdi_port_probe, |
4317 | .remove_port = efx_mcdi_port_remove, | |
4318 | .fini_dmaq = efx_ef10_fini_dmaq, | |
e283546c EC |
4319 | .prepare_flr = efx_ef10_prepare_flr, |
4320 | .finish_flr = efx_port_dummy_op_void, | |
8127d661 | 4321 | .describe_stats = efx_ef10_describe_stats, |
d7788196 | 4322 | .update_stats = efx_ef10_update_stats_pf, |
8127d661 | 4323 | .start_stats = efx_mcdi_mac_start_stats, |
f8f3b5ae | 4324 | .pull_stats = efx_mcdi_mac_pull_stats, |
8127d661 BH |
4325 | .stop_stats = efx_mcdi_mac_stop_stats, |
4326 | .set_id_led = efx_mcdi_set_id_led, | |
4327 | .push_irq_moderation = efx_ef10_push_irq_moderation, | |
4328 | .reconfigure_mac = efx_ef10_mac_reconfigure, | |
4329 | .check_mac_fault = efx_mcdi_mac_check_fault, | |
4330 | .reconfigure_port = efx_mcdi_port_reconfigure, | |
4331 | .get_wol = efx_ef10_get_wol, | |
4332 | .set_wol = efx_ef10_set_wol, | |
4333 | .resume_wol = efx_port_dummy_op_void, | |
74cd60a4 | 4334 | .test_chip = efx_ef10_test_chip, |
8127d661 BH |
4335 | .test_nvram = efx_mcdi_nvram_test_all, |
4336 | .mcdi_request = efx_ef10_mcdi_request, | |
4337 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, | |
4338 | .mcdi_read_response = efx_ef10_mcdi_read_response, | |
4339 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, | |
4340 | .irq_enable_master = efx_port_dummy_op_void, | |
4341 | .irq_test_generate = efx_ef10_irq_test_generate, | |
4342 | .irq_disable_non_ev = efx_port_dummy_op_void, | |
4343 | .irq_handle_msi = efx_ef10_msi_interrupt, | |
4344 | .irq_handle_legacy = efx_ef10_legacy_interrupt, | |
4345 | .tx_probe = efx_ef10_tx_probe, | |
4346 | .tx_init = efx_ef10_tx_init, | |
4347 | .tx_remove = efx_ef10_tx_remove, | |
4348 | .tx_write = efx_ef10_tx_write, | |
267c0157 | 4349 | .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config, |
8127d661 BH |
4350 | .rx_probe = efx_ef10_rx_probe, |
4351 | .rx_init = efx_ef10_rx_init, | |
4352 | .rx_remove = efx_ef10_rx_remove, | |
4353 | .rx_write = efx_ef10_rx_write, | |
4354 | .rx_defer_refill = efx_ef10_rx_defer_refill, | |
4355 | .ev_probe = efx_ef10_ev_probe, | |
4356 | .ev_init = efx_ef10_ev_init, | |
4357 | .ev_fini = efx_ef10_ev_fini, | |
4358 | .ev_remove = efx_ef10_ev_remove, | |
4359 | .ev_process = efx_ef10_ev_process, | |
4360 | .ev_read_ack = efx_ef10_ev_read_ack, | |
4361 | .ev_test_generate = efx_ef10_ev_test_generate, | |
4362 | .filter_table_probe = efx_ef10_filter_table_probe, | |
4363 | .filter_table_restore = efx_ef10_filter_table_restore, | |
4364 | .filter_table_remove = efx_ef10_filter_table_remove, | |
4365 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, | |
4366 | .filter_insert = efx_ef10_filter_insert, | |
4367 | .filter_remove_safe = efx_ef10_filter_remove_safe, | |
4368 | .filter_get_safe = efx_ef10_filter_get_safe, | |
4369 | .filter_clear_rx = efx_ef10_filter_clear_rx, | |
4370 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, | |
4371 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, | |
4372 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, | |
4373 | #ifdef CONFIG_RFS_ACCEL | |
4374 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, | |
4375 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, | |
4376 | #endif | |
4377 | #ifdef CONFIG_SFC_MTD | |
4378 | .mtd_probe = efx_ef10_mtd_probe, | |
4379 | .mtd_rename = efx_mcdi_mtd_rename, | |
4380 | .mtd_read = efx_mcdi_mtd_read, | |
4381 | .mtd_erase = efx_mcdi_mtd_erase, | |
4382 | .mtd_write = efx_mcdi_mtd_write, | |
4383 | .mtd_sync = efx_mcdi_mtd_sync, | |
4384 | #endif | |
4385 | .ptp_write_host_time = efx_ef10_ptp_write_host_time, | |
bd9a265d JC |
4386 | .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events, |
4387 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config, | |
7fa8d547 | 4388 | #ifdef CONFIG_SFC_SRIOV |
834e23dd | 4389 | .sriov_configure = efx_ef10_sriov_configure, |
d98a4ffe SS |
4390 | .sriov_init = efx_ef10_sriov_init, |
4391 | .sriov_fini = efx_ef10_sriov_fini, | |
d98a4ffe SS |
4392 | .sriov_wanted = efx_ef10_sriov_wanted, |
4393 | .sriov_reset = efx_ef10_sriov_reset, | |
7fa8d547 SS |
4394 | .sriov_flr = efx_ef10_sriov_flr, |
4395 | .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac, | |
4396 | .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan, | |
4397 | .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk, | |
4398 | .sriov_get_vf_config = efx_ef10_sriov_get_vf_config, | |
4392dc69 | 4399 | .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state, |
7b8c7b54 SS |
4400 | .vswitching_probe = efx_ef10_vswitching_probe_pf, |
4401 | .vswitching_restore = efx_ef10_vswitching_restore_pf, | |
4402 | .vswitching_remove = efx_ef10_vswitching_remove_pf, | |
7fa8d547 | 4403 | #endif |
0d5e0fbb | 4404 | .get_mac_address = efx_ef10_get_mac_address_pf, |
910c8789 | 4405 | .set_mac_address = efx_ef10_set_mac_address, |
8127d661 BH |
4406 | |
4407 | .revision = EFX_REV_HUNT_A0, | |
4408 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), | |
4409 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, | |
4410 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, | |
bd9a265d | 4411 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
8127d661 BH |
4412 | .can_rx_scatter = true, |
4413 | .always_rx_scatter = true, | |
4414 | .max_interrupt_mode = EFX_INT_MODE_MSIX, | |
4415 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, | |
4416 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
4417 | NETIF_F_RXHASH | NETIF_F_NTUPLE), | |
4418 | .mcdi_max_ver = 2, | |
4419 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, | |
bd9a265d JC |
4420 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
4421 | 1 << HWTSTAMP_FILTER_ALL, | |
8127d661 | 4422 | }; |