]>
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 | { | |
3c36a2ad DP |
1165 | u64 raw_mask[2]; |
1166 | ||
1167 | raw_mask[0] = efx_ef10_raw_stat_mask(efx); | |
1168 | ||
1169 | /* All functions see the vadaptor stats */ | |
1170 | raw_mask[0] |= ~((1ULL << EF10_STAT_rx_unicast) - 1); | |
1171 | raw_mask[1] = (1ULL << (EF10_STAT_COUNT - 63)) - 1; | |
4bae913b EC |
1172 | |
1173 | #if BITS_PER_LONG == 64 | |
3c36a2ad DP |
1174 | mask[0] = raw_mask[0]; |
1175 | mask[1] = raw_mask[1]; | |
4bae913b | 1176 | #else |
3c36a2ad DP |
1177 | mask[0] = raw_mask[0] & 0xffffffff; |
1178 | mask[1] = raw_mask[0] >> 32; | |
1179 | mask[2] = raw_mask[1] & 0xffffffff; | |
1180 | mask[3] = raw_mask[1] >> 32; | |
4bae913b | 1181 | #endif |
8127d661 BH |
1182 | } |
1183 | ||
1184 | static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) | |
1185 | { | |
4bae913b EC |
1186 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
1187 | ||
1188 | efx_ef10_get_stat_mask(efx, mask); | |
8127d661 | 1189 | return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, |
4bae913b | 1190 | mask, names); |
8127d661 BH |
1191 | } |
1192 | ||
d7788196 DP |
1193 | static size_t efx_ef10_update_stats_common(struct efx_nic *efx, u64 *full_stats, |
1194 | struct rtnl_link_stats64 *core_stats) | |
1195 | { | |
1196 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); | |
1197 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1198 | u64 *stats = nic_data->stats; | |
1199 | size_t stats_count = 0, index; | |
1200 | ||
1201 | efx_ef10_get_stat_mask(efx, mask); | |
1202 | ||
1203 | if (full_stats) { | |
1204 | for_each_set_bit(index, mask, EF10_STAT_COUNT) { | |
1205 | if (efx_ef10_stat_desc[index].name) { | |
1206 | *full_stats++ = stats[index]; | |
1207 | ++stats_count; | |
1208 | } | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | if (core_stats) { | |
0fc95fca DP |
1213 | core_stats->rx_packets = stats[EF10_STAT_rx_unicast] + |
1214 | stats[EF10_STAT_rx_multicast] + | |
1215 | stats[EF10_STAT_rx_broadcast]; | |
1216 | core_stats->tx_packets = stats[EF10_STAT_tx_unicast] + | |
1217 | stats[EF10_STAT_tx_multicast] + | |
1218 | stats[EF10_STAT_tx_broadcast]; | |
1219 | core_stats->rx_bytes = stats[EF10_STAT_rx_unicast_bytes] + | |
1220 | stats[EF10_STAT_rx_multicast_bytes] + | |
1221 | stats[EF10_STAT_rx_broadcast_bytes]; | |
1222 | core_stats->tx_bytes = stats[EF10_STAT_tx_unicast_bytes] + | |
1223 | stats[EF10_STAT_tx_multicast_bytes] + | |
1224 | stats[EF10_STAT_tx_broadcast_bytes]; | |
1225 | core_stats->rx_dropped = stats[GENERIC_STAT_rx_nodesc_trunc] + | |
d7788196 | 1226 | stats[GENERIC_STAT_rx_noskb_drops]; |
0fc95fca DP |
1227 | core_stats->multicast = stats[EF10_STAT_rx_multicast]; |
1228 | core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad]; | |
1229 | core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow]; | |
1230 | core_stats->rx_errors = core_stats->rx_crc_errors; | |
1231 | core_stats->tx_errors = stats[EF10_STAT_tx_bad]; | |
d7788196 DP |
1232 | } |
1233 | ||
1234 | return stats_count; | |
1235 | } | |
1236 | ||
1237 | static int efx_ef10_try_update_nic_stats_pf(struct efx_nic *efx) | |
8127d661 BH |
1238 | { |
1239 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
4bae913b | 1240 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); |
8127d661 BH |
1241 | __le64 generation_start, generation_end; |
1242 | u64 *stats = nic_data->stats; | |
1243 | __le64 *dma_stats; | |
1244 | ||
4bae913b EC |
1245 | efx_ef10_get_stat_mask(efx, mask); |
1246 | ||
8127d661 BH |
1247 | dma_stats = efx->stats_buffer.addr; |
1248 | nic_data = efx->nic_data; | |
1249 | ||
1250 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; | |
1251 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) | |
1252 | return 0; | |
1253 | rmb(); | |
4bae913b | 1254 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, |
8127d661 | 1255 | stats, efx->stats_buffer.addr, false); |
d546a893 | 1256 | rmb(); |
8127d661 BH |
1257 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; |
1258 | if (generation_end != generation_start) | |
1259 | return -EAGAIN; | |
1260 | ||
1261 | /* Update derived statistics */ | |
e80ca013 DP |
1262 | efx_nic_fix_nodesc_drop_stat(efx, |
1263 | &stats[EF10_STAT_port_rx_nodesc_drops]); | |
1264 | stats[EF10_STAT_port_rx_good_bytes] = | |
1265 | stats[EF10_STAT_port_rx_bytes] - | |
1266 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]; | |
1267 | efx_update_diff_stat(&stats[EF10_STAT_port_rx_bad_bytes], | |
1268 | stats[EF10_STAT_port_rx_bytes_minus_good_bytes]); | |
e4d112e4 | 1269 | efx_update_sw_stats(efx, stats); |
8127d661 BH |
1270 | return 0; |
1271 | } | |
1272 | ||
1273 | ||
d7788196 DP |
1274 | static size_t efx_ef10_update_stats_pf(struct efx_nic *efx, u64 *full_stats, |
1275 | struct rtnl_link_stats64 *core_stats) | |
8127d661 | 1276 | { |
8127d661 BH |
1277 | int retry; |
1278 | ||
1279 | /* If we're unlucky enough to read statistics during the DMA, wait | |
1280 | * up to 10ms for it to finish (typically takes <500us) | |
1281 | */ | |
1282 | for (retry = 0; retry < 100; ++retry) { | |
d7788196 | 1283 | if (efx_ef10_try_update_nic_stats_pf(efx) == 0) |
8127d661 BH |
1284 | break; |
1285 | udelay(100); | |
1286 | } | |
1287 | ||
d7788196 DP |
1288 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); |
1289 | } | |
8127d661 | 1290 | |
d7788196 DP |
1291 | static int efx_ef10_try_update_nic_stats_vf(struct efx_nic *efx) |
1292 | { | |
1293 | MCDI_DECLARE_BUF(inbuf, MC_CMD_MAC_STATS_IN_LEN); | |
1294 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1295 | DECLARE_BITMAP(mask, EF10_STAT_COUNT); | |
1296 | __le64 generation_start, generation_end; | |
1297 | u64 *stats = nic_data->stats; | |
1298 | u32 dma_len = MC_CMD_MAC_NSTATS * sizeof(u64); | |
1299 | struct efx_buffer stats_buf; | |
1300 | __le64 *dma_stats; | |
1301 | int rc; | |
1302 | ||
1303 | efx_ef10_get_stat_mask(efx, mask); | |
1304 | ||
1305 | rc = efx_nic_alloc_buffer(efx, &stats_buf, dma_len, GFP_ATOMIC); | |
1306 | if (rc) | |
1307 | return rc; | |
1308 | ||
1309 | dma_stats = stats_buf.addr; | |
1310 | dma_stats[MC_CMD_MAC_GENERATION_END] = EFX_MC_STATS_GENERATION_INVALID; | |
1311 | ||
1312 | MCDI_SET_QWORD(inbuf, MAC_STATS_IN_DMA_ADDR, stats_buf.dma_addr); | |
1313 | MCDI_POPULATE_DWORD_1(inbuf, MAC_STATS_IN_CMD, | |
0fc95fca | 1314 | MAC_STATS_IN_DMA, 1); |
d7788196 DP |
1315 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_DMA_LEN, dma_len); |
1316 | MCDI_SET_DWORD(inbuf, MAC_STATS_IN_PORT_ID, EVB_PORT_ID_ASSIGNED); | |
1317 | ||
1318 | spin_unlock_bh(&efx->stats_lock); | |
1319 | rc = efx_mcdi_rpc(efx, MC_CMD_MAC_STATS, inbuf, sizeof(inbuf), NULL, | |
1320 | 0, NULL); | |
1321 | spin_lock_bh(&efx->stats_lock); | |
1322 | if (rc) | |
1323 | goto out; | |
1324 | ||
1325 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; | |
0fc95fca DP |
1326 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) { |
1327 | WARN_ON_ONCE(1); | |
d7788196 | 1328 | goto out; |
0fc95fca | 1329 | } |
d7788196 DP |
1330 | rmb(); |
1331 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, mask, | |
1332 | stats, stats_buf.addr, false); | |
1333 | rmb(); | |
1334 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; | |
1335 | if (generation_end != generation_start) { | |
1336 | rc = -EAGAIN; | |
1337 | goto out; | |
8127d661 BH |
1338 | } |
1339 | ||
d7788196 DP |
1340 | efx_update_sw_stats(efx, stats); |
1341 | out: | |
1342 | efx_nic_free_buffer(efx, &stats_buf); | |
1343 | return rc; | |
1344 | } | |
1345 | ||
1346 | static size_t efx_ef10_update_stats_vf(struct efx_nic *efx, u64 *full_stats, | |
1347 | struct rtnl_link_stats64 *core_stats) | |
1348 | { | |
1349 | if (efx_ef10_try_update_nic_stats_vf(efx)) | |
1350 | return 0; | |
1351 | ||
1352 | return efx_ef10_update_stats_common(efx, full_stats, core_stats); | |
8127d661 BH |
1353 | } |
1354 | ||
1355 | static void efx_ef10_push_irq_moderation(struct efx_channel *channel) | |
1356 | { | |
1357 | struct efx_nic *efx = channel->efx; | |
1358 | unsigned int mode, value; | |
1359 | efx_dword_t timer_cmd; | |
1360 | ||
1361 | if (channel->irq_moderation) { | |
1362 | mode = 3; | |
1363 | value = channel->irq_moderation - 1; | |
1364 | } else { | |
1365 | mode = 0; | |
1366 | value = 0; | |
1367 | } | |
1368 | ||
1369 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
1370 | EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS, | |
1371 | EFE_DD_EVQ_IND_TIMER_FLAGS, | |
1372 | ERF_DD_EVQ_IND_TIMER_MODE, mode, | |
1373 | ERF_DD_EVQ_IND_TIMER_VAL, value); | |
1374 | efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT, | |
1375 | channel->channel); | |
1376 | } else { | |
1377 | EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode, | |
1378 | ERF_DZ_TC_TIMER_VAL, value); | |
1379 | efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR, | |
1380 | channel->channel); | |
1381 | } | |
1382 | } | |
1383 | ||
02246a7f SS |
1384 | static void efx_ef10_get_wol_vf(struct efx_nic *efx, |
1385 | struct ethtool_wolinfo *wol) {} | |
1386 | ||
1387 | static int efx_ef10_set_wol_vf(struct efx_nic *efx, u32 type) | |
1388 | { | |
1389 | return -EOPNOTSUPP; | |
1390 | } | |
1391 | ||
8127d661 BH |
1392 | static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) |
1393 | { | |
1394 | wol->supported = 0; | |
1395 | wol->wolopts = 0; | |
1396 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
1397 | } | |
1398 | ||
1399 | static int efx_ef10_set_wol(struct efx_nic *efx, u32 type) | |
1400 | { | |
1401 | if (type != 0) | |
1402 | return -EINVAL; | |
1403 | return 0; | |
1404 | } | |
1405 | ||
1406 | static void efx_ef10_mcdi_request(struct efx_nic *efx, | |
1407 | const efx_dword_t *hdr, size_t hdr_len, | |
1408 | const efx_dword_t *sdu, size_t sdu_len) | |
1409 | { | |
1410 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1411 | u8 *pdu = nic_data->mcdi_buf.addr; | |
1412 | ||
1413 | memcpy(pdu, hdr, hdr_len); | |
1414 | memcpy(pdu + hdr_len, sdu, sdu_len); | |
1415 | wmb(); | |
1416 | ||
1417 | /* The hardware provides 'low' and 'high' (doorbell) registers | |
1418 | * for passing the 64-bit address of an MCDI request to | |
1419 | * firmware. However the dwords are swapped by firmware. The | |
1420 | * least significant bits of the doorbell are then 0 for all | |
1421 | * MCDI requests due to alignment. | |
1422 | */ | |
1423 | _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32), | |
1424 | ER_DZ_MC_DB_LWRD); | |
1425 | _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr), | |
1426 | ER_DZ_MC_DB_HWRD); | |
1427 | } | |
1428 | ||
1429 | static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx) | |
1430 | { | |
1431 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1432 | const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr; | |
1433 | ||
1434 | rmb(); | |
1435 | return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE); | |
1436 | } | |
1437 | ||
1438 | static void | |
1439 | efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf, | |
1440 | size_t offset, size_t outlen) | |
1441 | { | |
1442 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1443 | const u8 *pdu = nic_data->mcdi_buf.addr; | |
1444 | ||
1445 | memcpy(outbuf, pdu + offset, outlen); | |
1446 | } | |
1447 | ||
1448 | static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx) | |
1449 | { | |
1450 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1451 | int rc; | |
1452 | ||
1453 | rc = efx_ef10_get_warm_boot_count(efx); | |
1454 | if (rc < 0) { | |
1455 | /* The firmware is presumably in the process of | |
1456 | * rebooting. However, we are supposed to report each | |
1457 | * reboot just once, so we must only do that once we | |
1458 | * can read and store the updated warm boot count. | |
1459 | */ | |
1460 | return 0; | |
1461 | } | |
1462 | ||
1463 | if (rc == nic_data->warm_boot_count) | |
1464 | return 0; | |
1465 | ||
1466 | nic_data->warm_boot_count = rc; | |
1467 | ||
1468 | /* All our allocations have been reset */ | |
3e336261 | 1469 | efx_ef10_reset_mc_allocations(efx); |
8127d661 | 1470 | |
6d8aaaf6 DP |
1471 | /* Driver-created vswitches and vports must be re-created */ |
1472 | nic_data->must_probe_vswitching = true; | |
1473 | nic_data->vport_id = EVB_PORT_ID_ASSIGNED; | |
1474 | ||
a915ccc9 BH |
1475 | /* The datapath firmware might have been changed */ |
1476 | nic_data->must_check_datapath_caps = true; | |
1477 | ||
869070c5 BH |
1478 | /* MAC statistics have been cleared on the NIC; clear the local |
1479 | * statistic that we update with efx_update_diff_stat(). | |
1480 | */ | |
e80ca013 | 1481 | nic_data->stats[EF10_STAT_port_rx_bad_bytes] = 0; |
869070c5 | 1482 | |
8127d661 BH |
1483 | return -EIO; |
1484 | } | |
1485 | ||
1486 | /* Handle an MSI interrupt | |
1487 | * | |
1488 | * Handle an MSI hardware interrupt. This routine schedules event | |
1489 | * queue processing. No interrupt acknowledgement cycle is necessary. | |
1490 | * Also, we never need to check that the interrupt is for us, since | |
1491 | * MSI interrupts cannot be shared. | |
1492 | */ | |
1493 | static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id) | |
1494 | { | |
1495 | struct efx_msi_context *context = dev_id; | |
1496 | struct efx_nic *efx = context->efx; | |
1497 | ||
1498 | netif_vdbg(efx, intr, efx->net_dev, | |
1499 | "IRQ %d on CPU %d\n", irq, raw_smp_processor_id()); | |
1500 | ||
1501 | if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) { | |
1502 | /* Note test interrupts */ | |
1503 | if (context->index == efx->irq_level) | |
1504 | efx->last_irq_cpu = raw_smp_processor_id(); | |
1505 | ||
1506 | /* Schedule processing of the channel */ | |
1507 | efx_schedule_channel_irq(efx->channel[context->index]); | |
1508 | } | |
1509 | ||
1510 | return IRQ_HANDLED; | |
1511 | } | |
1512 | ||
1513 | static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id) | |
1514 | { | |
1515 | struct efx_nic *efx = dev_id; | |
1516 | bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled); | |
1517 | struct efx_channel *channel; | |
1518 | efx_dword_t reg; | |
1519 | u32 queues; | |
1520 | ||
1521 | /* Read the ISR which also ACKs the interrupts */ | |
1522 | efx_readd(efx, ®, ER_DZ_BIU_INT_ISR); | |
1523 | queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG); | |
1524 | ||
1525 | if (queues == 0) | |
1526 | return IRQ_NONE; | |
1527 | ||
1528 | if (likely(soft_enabled)) { | |
1529 | /* Note test interrupts */ | |
1530 | if (queues & (1U << efx->irq_level)) | |
1531 | efx->last_irq_cpu = raw_smp_processor_id(); | |
1532 | ||
1533 | efx_for_each_channel(channel, efx) { | |
1534 | if (queues & 1) | |
1535 | efx_schedule_channel_irq(channel); | |
1536 | queues >>= 1; | |
1537 | } | |
1538 | } | |
1539 | ||
1540 | netif_vdbg(efx, intr, efx->net_dev, | |
1541 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", | |
1542 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); | |
1543 | ||
1544 | return IRQ_HANDLED; | |
1545 | } | |
1546 | ||
1547 | static void efx_ef10_irq_test_generate(struct efx_nic *efx) | |
1548 | { | |
1549 | MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN); | |
1550 | ||
1551 | BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0); | |
1552 | ||
1553 | MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level); | |
1554 | (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT, | |
1555 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
1556 | } | |
1557 | ||
1558 | static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue) | |
1559 | { | |
1560 | return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf, | |
1561 | (tx_queue->ptr_mask + 1) * | |
1562 | sizeof(efx_qword_t), | |
1563 | GFP_KERNEL); | |
1564 | } | |
1565 | ||
1566 | /* This writes to the TX_DESC_WPTR and also pushes data */ | |
1567 | static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue, | |
1568 | const efx_qword_t *txd) | |
1569 | { | |
1570 | unsigned int write_ptr; | |
1571 | efx_oword_t reg; | |
1572 | ||
1573 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1574 | EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr); | |
1575 | reg.qword[0] = *txd; | |
1576 | efx_writeo_page(tx_queue->efx, ®, | |
1577 | ER_DZ_TX_DESC_UPD, tx_queue->queue); | |
1578 | } | |
1579 | ||
1580 | static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) | |
1581 | { | |
1582 | MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
1583 | EFX_BUF_SIZE)); | |
8127d661 BH |
1584 | bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; |
1585 | size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE; | |
1586 | struct efx_channel *channel = tx_queue->channel; | |
1587 | struct efx_nic *efx = tx_queue->efx; | |
45b2449e | 1588 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
aa09a3da | 1589 | size_t inlen; |
8127d661 BH |
1590 | dma_addr_t dma_addr; |
1591 | efx_qword_t *txd; | |
1592 | int rc; | |
1593 | int i; | |
aa09a3da | 1594 | BUILD_BUG_ON(MC_CMD_INIT_TXQ_OUT_LEN != 0); |
8127d661 BH |
1595 | |
1596 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); | |
1597 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); | |
1598 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); | |
1599 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); | |
1600 | MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS, | |
1601 | INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, | |
1602 | INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); | |
1603 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); | |
45b2449e | 1604 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
1605 | |
1606 | dma_addr = tx_queue->txd.buf.dma_addr; | |
1607 | ||
1608 | netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n", | |
1609 | tx_queue->queue, entries, (u64)dma_addr); | |
1610 | ||
1611 | for (i = 0; i < entries; ++i) { | |
1612 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr); | |
1613 | dma_addr += EFX_BUF_SIZE; | |
1614 | } | |
1615 | ||
1616 | inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); | |
1617 | ||
1618 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen, | |
aa09a3da | 1619 | NULL, 0, NULL); |
8127d661 BH |
1620 | if (rc) |
1621 | goto fail; | |
1622 | ||
1623 | /* A previous user of this TX queue might have set us up the | |
1624 | * bomb by writing a descriptor to the TX push collector but | |
1625 | * not the doorbell. (Each collector belongs to a port, not a | |
1626 | * queue or function, so cannot easily be reset.) We must | |
1627 | * attempt to push a no-op descriptor in its place. | |
1628 | */ | |
1629 | tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION; | |
1630 | tx_queue->insert_count = 1; | |
1631 | txd = efx_tx_desc(tx_queue, 0); | |
1632 | EFX_POPULATE_QWORD_4(*txd, | |
1633 | ESF_DZ_TX_DESC_IS_OPT, true, | |
1634 | ESF_DZ_TX_OPTION_TYPE, | |
1635 | ESE_DZ_TX_OPTION_DESC_CRC_CSUM, | |
1636 | ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload, | |
1637 | ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); | |
1638 | tx_queue->write_count = 1; | |
1639 | wmb(); | |
1640 | efx_ef10_push_tx_desc(tx_queue, txd); | |
1641 | ||
1642 | return; | |
1643 | ||
1644 | fail: | |
48ce5634 BH |
1645 | netdev_WARN(efx->net_dev, "failed to initialise TXQ %d\n", |
1646 | tx_queue->queue); | |
8127d661 BH |
1647 | } |
1648 | ||
1649 | static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue) | |
1650 | { | |
1651 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN); | |
aa09a3da | 1652 | MCDI_DECLARE_BUF_ERR(outbuf); |
8127d661 BH |
1653 | struct efx_nic *efx = tx_queue->efx; |
1654 | size_t outlen; | |
1655 | int rc; | |
1656 | ||
1657 | MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE, | |
1658 | tx_queue->queue); | |
1659 | ||
1e0b8120 | 1660 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf), |
8127d661 BH |
1661 | outbuf, sizeof(outbuf), &outlen); |
1662 | ||
1663 | if (rc && rc != -EALREADY) | |
1664 | goto fail; | |
1665 | ||
1666 | return; | |
1667 | ||
1668 | fail: | |
1e0b8120 EC |
1669 | efx_mcdi_display_error(efx, MC_CMD_FINI_TXQ, MC_CMD_FINI_TXQ_IN_LEN, |
1670 | outbuf, outlen, rc); | |
8127d661 BH |
1671 | } |
1672 | ||
1673 | static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue) | |
1674 | { | |
1675 | efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf); | |
1676 | } | |
1677 | ||
1678 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ | |
1679 | static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue) | |
1680 | { | |
1681 | unsigned int write_ptr; | |
1682 | efx_dword_t reg; | |
1683 | ||
1684 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1685 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); | |
1686 | efx_writed_page(tx_queue->efx, ®, | |
1687 | ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); | |
1688 | } | |
1689 | ||
1690 | static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) | |
1691 | { | |
1692 | unsigned int old_write_count = tx_queue->write_count; | |
1693 | struct efx_tx_buffer *buffer; | |
1694 | unsigned int write_ptr; | |
1695 | efx_qword_t *txd; | |
1696 | ||
1697 | BUG_ON(tx_queue->write_count == tx_queue->insert_count); | |
1698 | ||
1699 | do { | |
1700 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
1701 | buffer = &tx_queue->buffer[write_ptr]; | |
1702 | txd = efx_tx_desc(tx_queue, write_ptr); | |
1703 | ++tx_queue->write_count; | |
1704 | ||
1705 | /* Create TX descriptor ring entry */ | |
1706 | if (buffer->flags & EFX_TX_BUF_OPTION) { | |
1707 | *txd = buffer->option; | |
1708 | } else { | |
1709 | BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); | |
1710 | EFX_POPULATE_QWORD_3( | |
1711 | *txd, | |
1712 | ESF_DZ_TX_KER_CONT, | |
1713 | buffer->flags & EFX_TX_BUF_CONT, | |
1714 | ESF_DZ_TX_KER_BYTE_CNT, buffer->len, | |
1715 | ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr); | |
1716 | } | |
1717 | } while (tx_queue->write_count != tx_queue->insert_count); | |
1718 | ||
1719 | wmb(); /* Ensure descriptors are written before they are fetched */ | |
1720 | ||
1721 | if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { | |
1722 | txd = efx_tx_desc(tx_queue, | |
1723 | old_write_count & tx_queue->ptr_mask); | |
1724 | efx_ef10_push_tx_desc(tx_queue, txd); | |
1725 | ++tx_queue->pushes; | |
1726 | } else { | |
1727 | efx_ef10_notify_tx_desc(tx_queue); | |
1728 | } | |
1729 | } | |
1730 | ||
267c0157 JC |
1731 | static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context, |
1732 | bool exclusive, unsigned *context_size) | |
8127d661 BH |
1733 | { |
1734 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); | |
1735 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN); | |
45b2449e | 1736 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
8127d661 BH |
1737 | size_t outlen; |
1738 | int rc; | |
267c0157 JC |
1739 | u32 alloc_type = exclusive ? |
1740 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE : | |
1741 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_SHARED; | |
1742 | unsigned rss_spread = exclusive ? | |
1743 | efx->rss_spread : | |
1744 | min(rounddown_pow_of_two(efx->rss_spread), | |
1745 | EFX_EF10_MAX_SHARED_RSS_CONTEXT_SIZE); | |
1746 | ||
1747 | if (!exclusive && rss_spread == 1) { | |
1748 | *context = EFX_EF10_RSS_CONTEXT_INVALID; | |
1749 | if (context_size) | |
1750 | *context_size = 1; | |
1751 | return 0; | |
1752 | } | |
8127d661 BH |
1753 | |
1754 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID, | |
45b2449e | 1755 | nic_data->vport_id); |
267c0157 JC |
1756 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, alloc_type); |
1757 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, rss_spread); | |
8127d661 BH |
1758 | |
1759 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf), | |
1760 | outbuf, sizeof(outbuf), &outlen); | |
1761 | if (rc != 0) | |
1762 | return rc; | |
1763 | ||
1764 | if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) | |
1765 | return -EIO; | |
1766 | ||
1767 | *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID); | |
1768 | ||
267c0157 JC |
1769 | if (context_size) |
1770 | *context_size = rss_spread; | |
1771 | ||
8127d661 BH |
1772 | return 0; |
1773 | } | |
1774 | ||
1775 | static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context) | |
1776 | { | |
1777 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN); | |
1778 | int rc; | |
1779 | ||
1780 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, | |
1781 | context); | |
1782 | ||
1783 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf), | |
1784 | NULL, 0, NULL); | |
1785 | WARN_ON(rc != 0); | |
1786 | } | |
1787 | ||
267c0157 JC |
1788 | static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context, |
1789 | const u32 *rx_indir_table) | |
8127d661 BH |
1790 | { |
1791 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN); | |
1792 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN); | |
1793 | int i, rc; | |
1794 | ||
1795 | MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID, | |
1796 | context); | |
1797 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != | |
1798 | MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN); | |
1799 | ||
1800 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i) | |
1801 | MCDI_PTR(tablebuf, | |
1802 | RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] = | |
267c0157 | 1803 | (u8) rx_indir_table[i]; |
8127d661 BH |
1804 | |
1805 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf, | |
1806 | sizeof(tablebuf), NULL, 0, NULL); | |
1807 | if (rc != 0) | |
1808 | return rc; | |
1809 | ||
1810 | MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID, | |
1811 | context); | |
1812 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != | |
1813 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); | |
1814 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) | |
1815 | MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = | |
1816 | efx->rx_hash_key[i]; | |
1817 | ||
1818 | return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf, | |
1819 | sizeof(keybuf), NULL, 0, NULL); | |
1820 | } | |
1821 | ||
1822 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx) | |
1823 | { | |
1824 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1825 | ||
1826 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) | |
1827 | efx_ef10_free_rss_context(efx, nic_data->rx_rss_context); | |
1828 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
1829 | } | |
1830 | ||
267c0157 JC |
1831 | static int efx_ef10_rx_push_shared_rss_config(struct efx_nic *efx, |
1832 | unsigned *context_size) | |
8127d661 | 1833 | { |
267c0157 | 1834 | u32 new_rx_rss_context; |
8127d661 | 1835 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
267c0157 JC |
1836 | int rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, |
1837 | false, context_size); | |
1838 | ||
1839 | if (rc != 0) | |
1840 | return rc; | |
8127d661 | 1841 | |
267c0157 JC |
1842 | nic_data->rx_rss_context = new_rx_rss_context; |
1843 | nic_data->rx_rss_context_exclusive = false; | |
1844 | efx_set_default_rx_indir_table(efx); | |
1845 | return 0; | |
1846 | } | |
8127d661 | 1847 | |
267c0157 JC |
1848 | static int efx_ef10_rx_push_exclusive_rss_config(struct efx_nic *efx, |
1849 | const u32 *rx_indir_table) | |
1850 | { | |
1851 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1852 | int rc; | |
1853 | u32 new_rx_rss_context; | |
1854 | ||
1855 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID || | |
1856 | !nic_data->rx_rss_context_exclusive) { | |
1857 | rc = efx_ef10_alloc_rss_context(efx, &new_rx_rss_context, | |
1858 | true, NULL); | |
1859 | if (rc == -EOPNOTSUPP) | |
1860 | return rc; | |
1861 | else if (rc != 0) | |
1862 | goto fail1; | |
1863 | } else { | |
1864 | new_rx_rss_context = nic_data->rx_rss_context; | |
8127d661 BH |
1865 | } |
1866 | ||
267c0157 JC |
1867 | rc = efx_ef10_populate_rss_table(efx, new_rx_rss_context, |
1868 | rx_indir_table); | |
8127d661 | 1869 | if (rc != 0) |
267c0157 | 1870 | goto fail2; |
8127d661 | 1871 | |
267c0157 JC |
1872 | if (nic_data->rx_rss_context != new_rx_rss_context) |
1873 | efx_ef10_rx_free_indir_table(efx); | |
1874 | nic_data->rx_rss_context = new_rx_rss_context; | |
1875 | nic_data->rx_rss_context_exclusive = true; | |
1876 | if (rx_indir_table != efx->rx_indir_table) | |
1877 | memcpy(efx->rx_indir_table, rx_indir_table, | |
1878 | sizeof(efx->rx_indir_table)); | |
1879 | return 0; | |
8127d661 | 1880 | |
267c0157 JC |
1881 | fail2: |
1882 | if (new_rx_rss_context != nic_data->rx_rss_context) | |
1883 | efx_ef10_free_rss_context(efx, new_rx_rss_context); | |
1884 | fail1: | |
8127d661 | 1885 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); |
267c0157 JC |
1886 | return rc; |
1887 | } | |
1888 | ||
1889 | static int efx_ef10_pf_rx_push_rss_config(struct efx_nic *efx, bool user, | |
1890 | const u32 *rx_indir_table) | |
1891 | { | |
1892 | int rc; | |
1893 | ||
1894 | if (efx->rss_spread == 1) | |
1895 | return 0; | |
1896 | ||
1897 | rc = efx_ef10_rx_push_exclusive_rss_config(efx, rx_indir_table); | |
1898 | ||
1899 | if (rc == -ENOBUFS && !user) { | |
1900 | unsigned context_size; | |
1901 | bool mismatch = false; | |
1902 | size_t i; | |
1903 | ||
1904 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table) && !mismatch; | |
1905 | i++) | |
1906 | mismatch = rx_indir_table[i] != | |
1907 | ethtool_rxfh_indir_default(i, efx->rss_spread); | |
1908 | ||
1909 | rc = efx_ef10_rx_push_shared_rss_config(efx, &context_size); | |
1910 | if (rc == 0) { | |
1911 | if (context_size != efx->rss_spread) | |
1912 | netif_warn(efx, probe, efx->net_dev, | |
1913 | "Could not allocate an exclusive RSS" | |
1914 | " context; allocated a shared one of" | |
1915 | " different size." | |
1916 | " Wanted %u, got %u.\n", | |
1917 | efx->rss_spread, context_size); | |
1918 | else if (mismatch) | |
1919 | netif_warn(efx, probe, efx->net_dev, | |
1920 | "Could not allocate an exclusive RSS" | |
1921 | " context; allocated a shared one but" | |
1922 | " could not apply custom" | |
1923 | " indirection.\n"); | |
1924 | else | |
1925 | netif_info(efx, probe, efx->net_dev, | |
1926 | "Could not allocate an exclusive RSS" | |
1927 | " context; allocated a shared one.\n"); | |
1928 | } | |
1929 | } | |
1930 | return rc; | |
1931 | } | |
1932 | ||
1933 | static int efx_ef10_vf_rx_push_rss_config(struct efx_nic *efx, bool user, | |
1934 | const u32 *rx_indir_table | |
1935 | __attribute__ ((unused))) | |
1936 | { | |
1937 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1938 | ||
1939 | if (user) | |
1940 | return -EOPNOTSUPP; | |
1941 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) | |
1942 | return 0; | |
1943 | return efx_ef10_rx_push_shared_rss_config(efx, NULL); | |
8127d661 BH |
1944 | } |
1945 | ||
1946 | static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue) | |
1947 | { | |
1948 | return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf, | |
1949 | (rx_queue->ptr_mask + 1) * | |
1950 | sizeof(efx_qword_t), | |
1951 | GFP_KERNEL); | |
1952 | } | |
1953 | ||
1954 | static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue) | |
1955 | { | |
1956 | MCDI_DECLARE_BUF(inbuf, | |
1957 | MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
1958 | EFX_BUF_SIZE)); | |
8127d661 BH |
1959 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); |
1960 | size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE; | |
1961 | struct efx_nic *efx = rx_queue->efx; | |
45b2449e | 1962 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
aa09a3da | 1963 | size_t inlen; |
8127d661 BH |
1964 | dma_addr_t dma_addr; |
1965 | int rc; | |
1966 | int i; | |
aa09a3da | 1967 | BUILD_BUG_ON(MC_CMD_INIT_RXQ_OUT_LEN != 0); |
8127d661 BH |
1968 | |
1969 | rx_queue->scatter_n = 0; | |
1970 | rx_queue->scatter_len = 0; | |
1971 | ||
1972 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1); | |
1973 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel); | |
1974 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue)); | |
1975 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE, | |
1976 | efx_rx_queue_index(rx_queue)); | |
bd9a265d JC |
1977 | MCDI_POPULATE_DWORD_2(inbuf, INIT_RXQ_IN_FLAGS, |
1978 | INIT_RXQ_IN_FLAG_PREFIX, 1, | |
1979 | INIT_RXQ_IN_FLAG_TIMESTAMP, 1); | |
8127d661 | 1980 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0); |
45b2449e | 1981 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
1982 | |
1983 | dma_addr = rx_queue->rxd.buf.dma_addr; | |
1984 | ||
1985 | netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n", | |
1986 | efx_rx_queue_index(rx_queue), entries, (u64)dma_addr); | |
1987 | ||
1988 | for (i = 0; i < entries; ++i) { | |
1989 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr); | |
1990 | dma_addr += EFX_BUF_SIZE; | |
1991 | } | |
1992 | ||
1993 | inlen = MC_CMD_INIT_RXQ_IN_LEN(entries); | |
1994 | ||
1995 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen, | |
aa09a3da | 1996 | NULL, 0, NULL); |
48ce5634 BH |
1997 | if (rc) |
1998 | netdev_WARN(efx->net_dev, "failed to initialise RXQ %d\n", | |
1999 | efx_rx_queue_index(rx_queue)); | |
8127d661 BH |
2000 | } |
2001 | ||
2002 | static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue) | |
2003 | { | |
2004 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN); | |
aa09a3da | 2005 | MCDI_DECLARE_BUF_ERR(outbuf); |
8127d661 BH |
2006 | struct efx_nic *efx = rx_queue->efx; |
2007 | size_t outlen; | |
2008 | int rc; | |
2009 | ||
2010 | MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE, | |
2011 | efx_rx_queue_index(rx_queue)); | |
2012 | ||
1e0b8120 | 2013 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf), |
8127d661 BH |
2014 | outbuf, sizeof(outbuf), &outlen); |
2015 | ||
2016 | if (rc && rc != -EALREADY) | |
2017 | goto fail; | |
2018 | ||
2019 | return; | |
2020 | ||
2021 | fail: | |
1e0b8120 EC |
2022 | efx_mcdi_display_error(efx, MC_CMD_FINI_RXQ, MC_CMD_FINI_RXQ_IN_LEN, |
2023 | outbuf, outlen, rc); | |
8127d661 BH |
2024 | } |
2025 | ||
2026 | static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue) | |
2027 | { | |
2028 | efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf); | |
2029 | } | |
2030 | ||
2031 | /* This creates an entry in the RX descriptor queue */ | |
2032 | static inline void | |
2033 | efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) | |
2034 | { | |
2035 | struct efx_rx_buffer *rx_buf; | |
2036 | efx_qword_t *rxd; | |
2037 | ||
2038 | rxd = efx_rx_desc(rx_queue, index); | |
2039 | rx_buf = efx_rx_buffer(rx_queue, index); | |
2040 | EFX_POPULATE_QWORD_2(*rxd, | |
2041 | ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len, | |
2042 | ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); | |
2043 | } | |
2044 | ||
2045 | static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue) | |
2046 | { | |
2047 | struct efx_nic *efx = rx_queue->efx; | |
2048 | unsigned int write_count; | |
2049 | efx_dword_t reg; | |
2050 | ||
2051 | /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */ | |
2052 | write_count = rx_queue->added_count & ~7; | |
2053 | if (rx_queue->notified_count == write_count) | |
2054 | return; | |
2055 | ||
2056 | do | |
2057 | efx_ef10_build_rx_desc( | |
2058 | rx_queue, | |
2059 | rx_queue->notified_count & rx_queue->ptr_mask); | |
2060 | while (++rx_queue->notified_count != write_count); | |
2061 | ||
2062 | wmb(); | |
2063 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR, | |
2064 | write_count & rx_queue->ptr_mask); | |
2065 | efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD, | |
2066 | efx_rx_queue_index(rx_queue)); | |
2067 | } | |
2068 | ||
2069 | static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete; | |
2070 | ||
2071 | static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue) | |
2072 | { | |
2073 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | |
2074 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
2075 | efx_qword_t event; | |
2076 | ||
2077 | EFX_POPULATE_QWORD_2(event, | |
2078 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
2079 | ESF_DZ_EV_DATA, EFX_EF10_REFILL); | |
2080 | ||
2081 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
2082 | ||
2083 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
2084 | * already swapped the data to little-endian order. | |
2085 | */ | |
2086 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
2087 | sizeof(efx_qword_t)); | |
2088 | ||
2089 | efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT, | |
2090 | inbuf, sizeof(inbuf), 0, | |
2091 | efx_ef10_rx_defer_refill_complete, 0); | |
2092 | } | |
2093 | ||
2094 | static void | |
2095 | efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie, | |
2096 | int rc, efx_dword_t *outbuf, | |
2097 | size_t outlen_actual) | |
2098 | { | |
2099 | /* nothing to do */ | |
2100 | } | |
2101 | ||
2102 | static int efx_ef10_ev_probe(struct efx_channel *channel) | |
2103 | { | |
2104 | return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf, | |
2105 | (channel->eventq_mask + 1) * | |
2106 | sizeof(efx_qword_t), | |
2107 | GFP_KERNEL); | |
2108 | } | |
2109 | ||
2110 | static int efx_ef10_ev_init(struct efx_channel *channel) | |
2111 | { | |
2112 | MCDI_DECLARE_BUF(inbuf, | |
2113 | MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 / | |
2114 | EFX_BUF_SIZE)); | |
2115 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN); | |
2116 | size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE; | |
2117 | struct efx_nic *efx = channel->efx; | |
2118 | struct efx_ef10_nic_data *nic_data; | |
2119 | bool supports_rx_merge; | |
2120 | size_t inlen, outlen; | |
2121 | dma_addr_t dma_addr; | |
2122 | int rc; | |
2123 | int i; | |
2124 | ||
2125 | nic_data = efx->nic_data; | |
2126 | supports_rx_merge = | |
2127 | !!(nic_data->datapath_caps & | |
2128 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN); | |
2129 | ||
2130 | /* Fill event queue with all ones (i.e. empty events) */ | |
2131 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); | |
2132 | ||
2133 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1); | |
2134 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel); | |
2135 | /* INIT_EVQ expects index in vector table, not absolute */ | |
2136 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel); | |
2137 | MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS, | |
2138 | INIT_EVQ_IN_FLAG_INTERRUPTING, 1, | |
2139 | INIT_EVQ_IN_FLAG_RX_MERGE, 1, | |
2140 | INIT_EVQ_IN_FLAG_TX_MERGE, 1, | |
2141 | INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge); | |
2142 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE, | |
2143 | MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); | |
2144 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0); | |
2145 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0); | |
2146 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE, | |
2147 | MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); | |
2148 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0); | |
2149 | ||
2150 | dma_addr = channel->eventq.buf.dma_addr; | |
2151 | for (i = 0; i < entries; ++i) { | |
2152 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr); | |
2153 | dma_addr += EFX_BUF_SIZE; | |
2154 | } | |
2155 | ||
2156 | inlen = MC_CMD_INIT_EVQ_IN_LEN(entries); | |
2157 | ||
2158 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen, | |
2159 | outbuf, sizeof(outbuf), &outlen); | |
8127d661 | 2160 | /* IRQ return is ignored */ |
8127d661 BH |
2161 | return rc; |
2162 | } | |
2163 | ||
2164 | static void efx_ef10_ev_fini(struct efx_channel *channel) | |
2165 | { | |
2166 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN); | |
aa09a3da | 2167 | MCDI_DECLARE_BUF_ERR(outbuf); |
8127d661 BH |
2168 | struct efx_nic *efx = channel->efx; |
2169 | size_t outlen; | |
2170 | int rc; | |
2171 | ||
2172 | MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel); | |
2173 | ||
1e0b8120 | 2174 | rc = efx_mcdi_rpc_quiet(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf), |
8127d661 BH |
2175 | outbuf, sizeof(outbuf), &outlen); |
2176 | ||
2177 | if (rc && rc != -EALREADY) | |
2178 | goto fail; | |
2179 | ||
2180 | return; | |
2181 | ||
2182 | fail: | |
1e0b8120 EC |
2183 | efx_mcdi_display_error(efx, MC_CMD_FINI_EVQ, MC_CMD_FINI_EVQ_IN_LEN, |
2184 | outbuf, outlen, rc); | |
8127d661 BH |
2185 | } |
2186 | ||
2187 | static void efx_ef10_ev_remove(struct efx_channel *channel) | |
2188 | { | |
2189 | efx_nic_free_buffer(channel->efx, &channel->eventq.buf); | |
2190 | } | |
2191 | ||
2192 | static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue, | |
2193 | unsigned int rx_queue_label) | |
2194 | { | |
2195 | struct efx_nic *efx = rx_queue->efx; | |
2196 | ||
2197 | netif_info(efx, hw, efx->net_dev, | |
2198 | "rx event arrived on queue %d labeled as queue %u\n", | |
2199 | efx_rx_queue_index(rx_queue), rx_queue_label); | |
2200 | ||
2201 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
2202 | } | |
2203 | ||
2204 | static void | |
2205 | efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue, | |
2206 | unsigned int actual, unsigned int expected) | |
2207 | { | |
2208 | unsigned int dropped = (actual - expected) & rx_queue->ptr_mask; | |
2209 | struct efx_nic *efx = rx_queue->efx; | |
2210 | ||
2211 | netif_info(efx, hw, efx->net_dev, | |
2212 | "dropped %d events (index=%d expected=%d)\n", | |
2213 | dropped, actual, expected); | |
2214 | ||
2215 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
2216 | } | |
2217 | ||
2218 | /* partially received RX was aborted. clean up. */ | |
2219 | static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue) | |
2220 | { | |
2221 | unsigned int rx_desc_ptr; | |
2222 | ||
8127d661 BH |
2223 | netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev, |
2224 | "scattered RX aborted (dropping %u buffers)\n", | |
2225 | rx_queue->scatter_n); | |
2226 | ||
2227 | rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask; | |
2228 | ||
2229 | efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n, | |
2230 | 0, EFX_RX_PKT_DISCARD); | |
2231 | ||
2232 | rx_queue->removed_count += rx_queue->scatter_n; | |
2233 | rx_queue->scatter_n = 0; | |
2234 | rx_queue->scatter_len = 0; | |
2235 | ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc; | |
2236 | } | |
2237 | ||
2238 | static int efx_ef10_handle_rx_event(struct efx_channel *channel, | |
2239 | const efx_qword_t *event) | |
2240 | { | |
2241 | unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class; | |
2242 | unsigned int n_descs, n_packets, i; | |
2243 | struct efx_nic *efx = channel->efx; | |
2244 | struct efx_rx_queue *rx_queue; | |
2245 | bool rx_cont; | |
2246 | u16 flags = 0; | |
2247 | ||
2248 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
2249 | return 0; | |
2250 | ||
2251 | /* Basic packet information */ | |
2252 | rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES); | |
2253 | next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS); | |
2254 | rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL); | |
2255 | rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS); | |
2256 | rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT); | |
2257 | ||
48ce5634 BH |
2258 | if (EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT)) |
2259 | netdev_WARN(efx->net_dev, "saw RX_DROP_EVENT: event=" | |
2260 | EFX_QWORD_FMT "\n", | |
2261 | EFX_QWORD_VAL(*event)); | |
8127d661 BH |
2262 | |
2263 | rx_queue = efx_channel_get_rx_queue(channel); | |
2264 | ||
2265 | if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue))) | |
2266 | efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label); | |
2267 | ||
2268 | n_descs = ((next_ptr_lbits - rx_queue->removed_count) & | |
2269 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
2270 | ||
2271 | if (n_descs != rx_queue->scatter_n + 1) { | |
92a04168 BH |
2272 | struct efx_ef10_nic_data *nic_data = efx->nic_data; |
2273 | ||
8127d661 BH |
2274 | /* detect rx abort */ |
2275 | if (unlikely(n_descs == rx_queue->scatter_n)) { | |
48ce5634 BH |
2276 | if (rx_queue->scatter_n == 0 || rx_bytes != 0) |
2277 | netdev_WARN(efx->net_dev, | |
2278 | "invalid RX abort: scatter_n=%u event=" | |
2279 | EFX_QWORD_FMT "\n", | |
2280 | rx_queue->scatter_n, | |
2281 | EFX_QWORD_VAL(*event)); | |
8127d661 BH |
2282 | efx_ef10_handle_rx_abort(rx_queue); |
2283 | return 0; | |
2284 | } | |
2285 | ||
92a04168 BH |
2286 | /* Check that RX completion merging is valid, i.e. |
2287 | * the current firmware supports it and this is a | |
2288 | * non-scattered packet. | |
2289 | */ | |
2290 | if (!(nic_data->datapath_caps & | |
2291 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN)) || | |
2292 | rx_queue->scatter_n != 0 || rx_cont) { | |
8127d661 BH |
2293 | efx_ef10_handle_rx_bad_lbits( |
2294 | rx_queue, next_ptr_lbits, | |
2295 | (rx_queue->removed_count + | |
2296 | rx_queue->scatter_n + 1) & | |
2297 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
2298 | return 0; | |
2299 | } | |
2300 | ||
2301 | /* Merged completion for multiple non-scattered packets */ | |
2302 | rx_queue->scatter_n = 1; | |
2303 | rx_queue->scatter_len = 0; | |
2304 | n_packets = n_descs; | |
2305 | ++channel->n_rx_merge_events; | |
2306 | channel->n_rx_merge_packets += n_packets; | |
2307 | flags |= EFX_RX_PKT_PREFIX_LEN; | |
2308 | } else { | |
2309 | ++rx_queue->scatter_n; | |
2310 | rx_queue->scatter_len += rx_bytes; | |
2311 | if (rx_cont) | |
2312 | return 0; | |
2313 | n_packets = 1; | |
2314 | } | |
2315 | ||
2316 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR))) | |
2317 | flags |= EFX_RX_PKT_DISCARD; | |
2318 | ||
2319 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) { | |
2320 | channel->n_rx_ip_hdr_chksum_err += n_packets; | |
2321 | } else if (unlikely(EFX_QWORD_FIELD(*event, | |
2322 | ESF_DZ_RX_TCPUDP_CKSUM_ERR))) { | |
2323 | channel->n_rx_tcp_udp_chksum_err += n_packets; | |
2324 | } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP || | |
2325 | rx_l4_class == ESE_DZ_L4_CLASS_UDP) { | |
2326 | flags |= EFX_RX_PKT_CSUMMED; | |
2327 | } | |
2328 | ||
2329 | if (rx_l4_class == ESE_DZ_L4_CLASS_TCP) | |
2330 | flags |= EFX_RX_PKT_TCP; | |
2331 | ||
2332 | channel->irq_mod_score += 2 * n_packets; | |
2333 | ||
2334 | /* Handle received packet(s) */ | |
2335 | for (i = 0; i < n_packets; i++) { | |
2336 | efx_rx_packet(rx_queue, | |
2337 | rx_queue->removed_count & rx_queue->ptr_mask, | |
2338 | rx_queue->scatter_n, rx_queue->scatter_len, | |
2339 | flags); | |
2340 | rx_queue->removed_count += rx_queue->scatter_n; | |
2341 | } | |
2342 | ||
2343 | rx_queue->scatter_n = 0; | |
2344 | rx_queue->scatter_len = 0; | |
2345 | ||
2346 | return n_packets; | |
2347 | } | |
2348 | ||
2349 | static int | |
2350 | efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) | |
2351 | { | |
2352 | struct efx_nic *efx = channel->efx; | |
2353 | struct efx_tx_queue *tx_queue; | |
2354 | unsigned int tx_ev_desc_ptr; | |
2355 | unsigned int tx_ev_q_label; | |
2356 | int tx_descs = 0; | |
2357 | ||
2358 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
2359 | return 0; | |
2360 | ||
2361 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT))) | |
2362 | return 0; | |
2363 | ||
2364 | /* Transmit completion */ | |
2365 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX); | |
2366 | tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL); | |
2367 | tx_queue = efx_channel_get_tx_queue(channel, | |
2368 | tx_ev_q_label % EFX_TXQ_TYPES); | |
2369 | tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) & | |
2370 | tx_queue->ptr_mask); | |
2371 | efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask); | |
2372 | ||
2373 | return tx_descs; | |
2374 | } | |
2375 | ||
2376 | static void | |
2377 | efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) | |
2378 | { | |
2379 | struct efx_nic *efx = channel->efx; | |
2380 | int subcode; | |
2381 | ||
2382 | subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE); | |
2383 | ||
2384 | switch (subcode) { | |
2385 | case ESE_DZ_DRV_TIMER_EV: | |
2386 | case ESE_DZ_DRV_WAKE_UP_EV: | |
2387 | break; | |
2388 | case ESE_DZ_DRV_START_UP_EV: | |
2389 | /* event queue init complete. ok. */ | |
2390 | break; | |
2391 | default: | |
2392 | netif_err(efx, hw, efx->net_dev, | |
2393 | "channel %d unknown driver event type %d" | |
2394 | " (data " EFX_QWORD_FMT ")\n", | |
2395 | channel->channel, subcode, | |
2396 | EFX_QWORD_VAL(*event)); | |
2397 | ||
2398 | } | |
2399 | } | |
2400 | ||
2401 | static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel, | |
2402 | efx_qword_t *event) | |
2403 | { | |
2404 | struct efx_nic *efx = channel->efx; | |
2405 | u32 subcode; | |
2406 | ||
2407 | subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0); | |
2408 | ||
2409 | switch (subcode) { | |
2410 | case EFX_EF10_TEST: | |
2411 | channel->event_test_cpu = raw_smp_processor_id(); | |
2412 | break; | |
2413 | case EFX_EF10_REFILL: | |
2414 | /* The queue must be empty, so we won't receive any rx | |
2415 | * events, so efx_process_channel() won't refill the | |
2416 | * queue. Refill it here | |
2417 | */ | |
cce28794 | 2418 | efx_fast_push_rx_descriptors(&channel->rx_queue, true); |
8127d661 BH |
2419 | break; |
2420 | default: | |
2421 | netif_err(efx, hw, efx->net_dev, | |
2422 | "channel %d unknown driver event type %u" | |
2423 | " (data " EFX_QWORD_FMT ")\n", | |
2424 | channel->channel, (unsigned) subcode, | |
2425 | EFX_QWORD_VAL(*event)); | |
2426 | } | |
2427 | } | |
2428 | ||
2429 | static int efx_ef10_ev_process(struct efx_channel *channel, int quota) | |
2430 | { | |
2431 | struct efx_nic *efx = channel->efx; | |
2432 | efx_qword_t event, *p_event; | |
2433 | unsigned int read_ptr; | |
2434 | int ev_code; | |
2435 | int tx_descs = 0; | |
2436 | int spent = 0; | |
2437 | ||
75363a46 EB |
2438 | if (quota <= 0) |
2439 | return spent; | |
2440 | ||
8127d661 BH |
2441 | read_ptr = channel->eventq_read_ptr; |
2442 | ||
2443 | for (;;) { | |
2444 | p_event = efx_event(channel, read_ptr); | |
2445 | event = *p_event; | |
2446 | ||
2447 | if (!efx_event_present(&event)) | |
2448 | break; | |
2449 | ||
2450 | EFX_SET_QWORD(*p_event); | |
2451 | ||
2452 | ++read_ptr; | |
2453 | ||
2454 | ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE); | |
2455 | ||
2456 | netif_vdbg(efx, drv, efx->net_dev, | |
2457 | "processing event on %d " EFX_QWORD_FMT "\n", | |
2458 | channel->channel, EFX_QWORD_VAL(event)); | |
2459 | ||
2460 | switch (ev_code) { | |
2461 | case ESE_DZ_EV_CODE_MCDI_EV: | |
2462 | efx_mcdi_process_event(channel, &event); | |
2463 | break; | |
2464 | case ESE_DZ_EV_CODE_RX_EV: | |
2465 | spent += efx_ef10_handle_rx_event(channel, &event); | |
2466 | if (spent >= quota) { | |
2467 | /* XXX can we split a merged event to | |
2468 | * avoid going over-quota? | |
2469 | */ | |
2470 | spent = quota; | |
2471 | goto out; | |
2472 | } | |
2473 | break; | |
2474 | case ESE_DZ_EV_CODE_TX_EV: | |
2475 | tx_descs += efx_ef10_handle_tx_event(channel, &event); | |
2476 | if (tx_descs > efx->txq_entries) { | |
2477 | spent = quota; | |
2478 | goto out; | |
2479 | } else if (++spent == quota) { | |
2480 | goto out; | |
2481 | } | |
2482 | break; | |
2483 | case ESE_DZ_EV_CODE_DRIVER_EV: | |
2484 | efx_ef10_handle_driver_event(channel, &event); | |
2485 | if (++spent == quota) | |
2486 | goto out; | |
2487 | break; | |
2488 | case EFX_EF10_DRVGEN_EV: | |
2489 | efx_ef10_handle_driver_generated_event(channel, &event); | |
2490 | break; | |
2491 | default: | |
2492 | netif_err(efx, hw, efx->net_dev, | |
2493 | "channel %d unknown event type %d" | |
2494 | " (data " EFX_QWORD_FMT ")\n", | |
2495 | channel->channel, ev_code, | |
2496 | EFX_QWORD_VAL(event)); | |
2497 | } | |
2498 | } | |
2499 | ||
2500 | out: | |
2501 | channel->eventq_read_ptr = read_ptr; | |
2502 | return spent; | |
2503 | } | |
2504 | ||
2505 | static void efx_ef10_ev_read_ack(struct efx_channel *channel) | |
2506 | { | |
2507 | struct efx_nic *efx = channel->efx; | |
2508 | efx_dword_t rptr; | |
2509 | ||
2510 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
2511 | BUILD_BUG_ON(EFX_MIN_EVQ_SIZE < | |
2512 | (1 << ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
2513 | BUILD_BUG_ON(EFX_MAX_EVQ_SIZE > | |
2514 | (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
2515 | ||
2516 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
2517 | EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH, | |
2518 | ERF_DD_EVQ_IND_RPTR, | |
2519 | (channel->eventq_read_ptr & | |
2520 | channel->eventq_mask) >> | |
2521 | ERF_DD_EVQ_IND_RPTR_WIDTH); | |
2522 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
2523 | channel->channel); | |
2524 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
2525 | EFE_DD_EVQ_IND_RPTR_FLAGS_LOW, | |
2526 | ERF_DD_EVQ_IND_RPTR, | |
2527 | channel->eventq_read_ptr & | |
2528 | ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1)); | |
2529 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
2530 | channel->channel); | |
2531 | } else { | |
2532 | EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR, | |
2533 | channel->eventq_read_ptr & | |
2534 | channel->eventq_mask); | |
2535 | efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel); | |
2536 | } | |
2537 | } | |
2538 | ||
2539 | static void efx_ef10_ev_test_generate(struct efx_channel *channel) | |
2540 | { | |
2541 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
2542 | struct efx_nic *efx = channel->efx; | |
2543 | efx_qword_t event; | |
2544 | int rc; | |
2545 | ||
2546 | EFX_POPULATE_QWORD_2(event, | |
2547 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
2548 | ESF_DZ_EV_DATA, EFX_EF10_TEST); | |
2549 | ||
2550 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
2551 | ||
2552 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
2553 | * already swapped the data to little-endian order. | |
2554 | */ | |
2555 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
2556 | sizeof(efx_qword_t)); | |
2557 | ||
2558 | rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf), | |
2559 | NULL, 0, NULL); | |
2560 | if (rc != 0) | |
2561 | goto fail; | |
2562 | ||
2563 | return; | |
2564 | ||
2565 | fail: | |
2566 | WARN_ON(true); | |
2567 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
2568 | } | |
2569 | ||
2570 | void efx_ef10_handle_drain_event(struct efx_nic *efx) | |
2571 | { | |
2572 | if (atomic_dec_and_test(&efx->active_queues)) | |
2573 | wake_up(&efx->flush_wq); | |
2574 | ||
2575 | WARN_ON(atomic_read(&efx->active_queues) < 0); | |
2576 | } | |
2577 | ||
2578 | static int efx_ef10_fini_dmaq(struct efx_nic *efx) | |
2579 | { | |
2580 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
2581 | struct efx_channel *channel; | |
2582 | struct efx_tx_queue *tx_queue; | |
2583 | struct efx_rx_queue *rx_queue; | |
2584 | int pending; | |
2585 | ||
2586 | /* If the MC has just rebooted, the TX/RX queues will have already been | |
2587 | * torn down, but efx->active_queues needs to be set to zero. | |
2588 | */ | |
2589 | if (nic_data->must_realloc_vis) { | |
2590 | atomic_set(&efx->active_queues, 0); | |
2591 | return 0; | |
2592 | } | |
2593 | ||
2594 | /* Do not attempt to write to the NIC during EEH recovery */ | |
2595 | if (efx->state != STATE_RECOVERY) { | |
2596 | efx_for_each_channel(channel, efx) { | |
2597 | efx_for_each_channel_rx_queue(rx_queue, channel) | |
2598 | efx_ef10_rx_fini(rx_queue); | |
2599 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
2600 | efx_ef10_tx_fini(tx_queue); | |
2601 | } | |
2602 | ||
2603 | wait_event_timeout(efx->flush_wq, | |
2604 | atomic_read(&efx->active_queues) == 0, | |
2605 | msecs_to_jiffies(EFX_MAX_FLUSH_TIME)); | |
2606 | pending = atomic_read(&efx->active_queues); | |
2607 | if (pending) { | |
2608 | netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n", | |
2609 | pending); | |
2610 | return -ETIMEDOUT; | |
2611 | } | |
2612 | } | |
2613 | ||
2614 | return 0; | |
2615 | } | |
2616 | ||
e283546c EC |
2617 | static void efx_ef10_prepare_flr(struct efx_nic *efx) |
2618 | { | |
2619 | atomic_set(&efx->active_queues, 0); | |
2620 | } | |
2621 | ||
8127d661 BH |
2622 | static bool efx_ef10_filter_equal(const struct efx_filter_spec *left, |
2623 | const struct efx_filter_spec *right) | |
2624 | { | |
2625 | if ((left->match_flags ^ right->match_flags) | | |
2626 | ((left->flags ^ right->flags) & | |
2627 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX))) | |
2628 | return false; | |
2629 | ||
2630 | return memcmp(&left->outer_vid, &right->outer_vid, | |
2631 | sizeof(struct efx_filter_spec) - | |
2632 | offsetof(struct efx_filter_spec, outer_vid)) == 0; | |
2633 | } | |
2634 | ||
2635 | static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec) | |
2636 | { | |
2637 | BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3); | |
2638 | return jhash2((const u32 *)&spec->outer_vid, | |
2639 | (sizeof(struct efx_filter_spec) - | |
2640 | offsetof(struct efx_filter_spec, outer_vid)) / 4, | |
2641 | 0); | |
2642 | /* XXX should we randomise the initval? */ | |
2643 | } | |
2644 | ||
2645 | /* Decide whether a filter should be exclusive or else should allow | |
2646 | * delivery to additional recipients. Currently we decide that | |
2647 | * filters for specific local unicast MAC and IP addresses are | |
2648 | * exclusive. | |
2649 | */ | |
2650 | static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec) | |
2651 | { | |
2652 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC && | |
2653 | !is_multicast_ether_addr(spec->loc_mac)) | |
2654 | return true; | |
2655 | ||
2656 | if ((spec->match_flags & | |
2657 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) == | |
2658 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) { | |
2659 | if (spec->ether_type == htons(ETH_P_IP) && | |
2660 | !ipv4_is_multicast(spec->loc_host[0])) | |
2661 | return true; | |
2662 | if (spec->ether_type == htons(ETH_P_IPV6) && | |
2663 | ((const u8 *)spec->loc_host)[0] != 0xff) | |
2664 | return true; | |
2665 | } | |
2666 | ||
2667 | return false; | |
2668 | } | |
2669 | ||
2670 | static struct efx_filter_spec * | |
2671 | efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table, | |
2672 | unsigned int filter_idx) | |
2673 | { | |
2674 | return (struct efx_filter_spec *)(table->entry[filter_idx].spec & | |
2675 | ~EFX_EF10_FILTER_FLAGS); | |
2676 | } | |
2677 | ||
2678 | static unsigned int | |
2679 | efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table, | |
2680 | unsigned int filter_idx) | |
2681 | { | |
2682 | return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS; | |
2683 | } | |
2684 | ||
2685 | static void | |
2686 | efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table, | |
2687 | unsigned int filter_idx, | |
2688 | const struct efx_filter_spec *spec, | |
2689 | unsigned int flags) | |
2690 | { | |
2691 | table->entry[filter_idx].spec = (unsigned long)spec | flags; | |
2692 | } | |
2693 | ||
2694 | static void efx_ef10_filter_push_prep(struct efx_nic *efx, | |
2695 | const struct efx_filter_spec *spec, | |
2696 | efx_dword_t *inbuf, u64 handle, | |
2697 | bool replacing) | |
2698 | { | |
2699 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
2700 | ||
2701 | memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN); | |
2702 | ||
2703 | if (replacing) { | |
2704 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2705 | MC_CMD_FILTER_OP_IN_OP_REPLACE); | |
2706 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle); | |
2707 | } else { | |
2708 | u32 match_fields = 0; | |
2709 | ||
2710 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2711 | efx_ef10_filter_is_exclusive(spec) ? | |
2712 | MC_CMD_FILTER_OP_IN_OP_INSERT : | |
2713 | MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE); | |
2714 | ||
2715 | /* Convert match flags and values. Unlike almost | |
2716 | * everything else in MCDI, these fields are in | |
2717 | * network byte order. | |
2718 | */ | |
2719 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) | |
2720 | match_fields |= | |
2721 | is_multicast_ether_addr(spec->loc_mac) ? | |
2722 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN : | |
2723 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN; | |
2724 | #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \ | |
2725 | if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \ | |
2726 | match_fields |= \ | |
2727 | 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
2728 | mcdi_field ## _LBN; \ | |
2729 | BUILD_BUG_ON( \ | |
2730 | MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \ | |
2731 | sizeof(spec->gen_field)); \ | |
2732 | memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \ | |
2733 | &spec->gen_field, sizeof(spec->gen_field)); \ | |
2734 | } | |
2735 | COPY_FIELD(REM_HOST, rem_host, SRC_IP); | |
2736 | COPY_FIELD(LOC_HOST, loc_host, DST_IP); | |
2737 | COPY_FIELD(REM_MAC, rem_mac, SRC_MAC); | |
2738 | COPY_FIELD(REM_PORT, rem_port, SRC_PORT); | |
2739 | COPY_FIELD(LOC_MAC, loc_mac, DST_MAC); | |
2740 | COPY_FIELD(LOC_PORT, loc_port, DST_PORT); | |
2741 | COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE); | |
2742 | COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN); | |
2743 | COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN); | |
2744 | COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO); | |
2745 | #undef COPY_FIELD | |
2746 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS, | |
2747 | match_fields); | |
2748 | } | |
2749 | ||
45b2449e | 2750 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, nic_data->vport_id); |
8127d661 BH |
2751 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST, |
2752 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? | |
2753 | MC_CMD_FILTER_OP_IN_RX_DEST_DROP : | |
2754 | MC_CMD_FILTER_OP_IN_RX_DEST_HOST); | |
e3d36293 | 2755 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DOMAIN, 0); |
8127d661 BH |
2756 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST, |
2757 | MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT); | |
a0bc3487 BH |
2758 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE, |
2759 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? | |
2760 | 0 : spec->dmaq_id); | |
8127d661 BH |
2761 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE, |
2762 | (spec->flags & EFX_FILTER_FLAG_RX_RSS) ? | |
2763 | MC_CMD_FILTER_OP_IN_RX_MODE_RSS : | |
2764 | MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE); | |
2765 | if (spec->flags & EFX_FILTER_FLAG_RX_RSS) | |
2766 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, | |
2767 | spec->rss_context != | |
2768 | EFX_FILTER_RSS_CONTEXT_DEFAULT ? | |
2769 | spec->rss_context : nic_data->rx_rss_context); | |
2770 | } | |
2771 | ||
2772 | static int efx_ef10_filter_push(struct efx_nic *efx, | |
2773 | const struct efx_filter_spec *spec, | |
2774 | u64 *handle, bool replacing) | |
2775 | { | |
2776 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2777 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN); | |
2778 | int rc; | |
2779 | ||
2780 | efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing); | |
2781 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
2782 | outbuf, sizeof(outbuf), NULL); | |
2783 | if (rc == 0) | |
2784 | *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
065e64c4 BH |
2785 | if (rc == -ENOSPC) |
2786 | rc = -EBUSY; /* to match efx_farch_filter_insert() */ | |
8127d661 BH |
2787 | return rc; |
2788 | } | |
2789 | ||
2790 | static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table, | |
2791 | enum efx_filter_match_flags match_flags) | |
2792 | { | |
2793 | unsigned int match_pri; | |
2794 | ||
2795 | for (match_pri = 0; | |
2796 | match_pri < table->rx_match_count; | |
2797 | match_pri++) | |
2798 | if (table->rx_match_flags[match_pri] == match_flags) | |
2799 | return match_pri; | |
2800 | ||
2801 | return -EPROTONOSUPPORT; | |
2802 | } | |
2803 | ||
2804 | static s32 efx_ef10_filter_insert(struct efx_nic *efx, | |
2805 | struct efx_filter_spec *spec, | |
2806 | bool replace_equal) | |
2807 | { | |
2808 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2809 | DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
2810 | struct efx_filter_spec *saved_spec; | |
2811 | unsigned int match_pri, hash; | |
2812 | unsigned int priv_flags; | |
2813 | bool replacing = false; | |
2814 | int ins_index = -1; | |
2815 | DEFINE_WAIT(wait); | |
2816 | bool is_mc_recip; | |
2817 | s32 rc; | |
2818 | ||
2819 | /* For now, only support RX filters */ | |
2820 | if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != | |
2821 | EFX_FILTER_FLAG_RX) | |
2822 | return -EINVAL; | |
2823 | ||
2824 | rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags); | |
2825 | if (rc < 0) | |
2826 | return rc; | |
2827 | match_pri = rc; | |
2828 | ||
2829 | hash = efx_ef10_filter_hash(spec); | |
2830 | is_mc_recip = efx_filter_is_mc_recipient(spec); | |
2831 | if (is_mc_recip) | |
2832 | bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
2833 | ||
2834 | /* Find any existing filters with the same match tuple or | |
2835 | * else a free slot to insert at. If any of them are busy, | |
2836 | * we have to wait and retry. | |
2837 | */ | |
2838 | for (;;) { | |
2839 | unsigned int depth = 1; | |
2840 | unsigned int i; | |
2841 | ||
2842 | spin_lock_bh(&efx->filter_lock); | |
2843 | ||
2844 | for (;;) { | |
2845 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2846 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2847 | ||
2848 | if (!saved_spec) { | |
2849 | if (ins_index < 0) | |
2850 | ins_index = i; | |
2851 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
2852 | if (table->entry[i].spec & | |
2853 | EFX_EF10_FILTER_FLAG_BUSY) | |
2854 | break; | |
2855 | if (spec->priority < saved_spec->priority && | |
7665d1ab | 2856 | spec->priority != EFX_FILTER_PRI_AUTO) { |
8127d661 BH |
2857 | rc = -EPERM; |
2858 | goto out_unlock; | |
2859 | } | |
2860 | if (!is_mc_recip) { | |
2861 | /* This is the only one */ | |
2862 | if (spec->priority == | |
2863 | saved_spec->priority && | |
2864 | !replace_equal) { | |
2865 | rc = -EEXIST; | |
2866 | goto out_unlock; | |
2867 | } | |
2868 | ins_index = i; | |
2869 | goto found; | |
2870 | } else if (spec->priority > | |
2871 | saved_spec->priority || | |
2872 | (spec->priority == | |
2873 | saved_spec->priority && | |
2874 | replace_equal)) { | |
2875 | if (ins_index < 0) | |
2876 | ins_index = i; | |
2877 | else | |
2878 | __set_bit(depth, mc_rem_map); | |
2879 | } | |
2880 | } | |
2881 | ||
2882 | /* Once we reach the maximum search depth, use | |
2883 | * the first suitable slot or return -EBUSY if | |
2884 | * there was none | |
2885 | */ | |
2886 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
2887 | if (ins_index < 0) { | |
2888 | rc = -EBUSY; | |
2889 | goto out_unlock; | |
2890 | } | |
2891 | goto found; | |
2892 | } | |
2893 | ||
2894 | ++depth; | |
2895 | } | |
2896 | ||
2897 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
2898 | spin_unlock_bh(&efx->filter_lock); | |
2899 | schedule(); | |
2900 | } | |
2901 | ||
2902 | found: | |
2903 | /* Create a software table entry if necessary, and mark it | |
2904 | * busy. We might yet fail to insert, but any attempt to | |
2905 | * insert a conflicting filter while we're waiting for the | |
2906 | * firmware must find the busy entry. | |
2907 | */ | |
2908 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2909 | if (saved_spec) { | |
7665d1ab BH |
2910 | if (spec->priority == EFX_FILTER_PRI_AUTO && |
2911 | saved_spec->priority >= EFX_FILTER_PRI_AUTO) { | |
8127d661 | 2912 | /* Just make sure it won't be removed */ |
7665d1ab BH |
2913 | if (saved_spec->priority > EFX_FILTER_PRI_AUTO) |
2914 | saved_spec->flags |= EFX_FILTER_FLAG_RX_OVER_AUTO; | |
8127d661 | 2915 | table->entry[ins_index].spec &= |
b59e6ef8 | 2916 | ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
8127d661 BH |
2917 | rc = ins_index; |
2918 | goto out_unlock; | |
2919 | } | |
2920 | replacing = true; | |
2921 | priv_flags = efx_ef10_filter_entry_flags(table, ins_index); | |
2922 | } else { | |
2923 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
2924 | if (!saved_spec) { | |
2925 | rc = -ENOMEM; | |
2926 | goto out_unlock; | |
2927 | } | |
2928 | *saved_spec = *spec; | |
2929 | priv_flags = 0; | |
2930 | } | |
2931 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
2932 | priv_flags | EFX_EF10_FILTER_FLAG_BUSY); | |
2933 | ||
2934 | /* Mark lower-priority multicast recipients busy prior to removal */ | |
2935 | if (is_mc_recip) { | |
2936 | unsigned int depth, i; | |
2937 | ||
2938 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
2939 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2940 | if (test_bit(depth, mc_rem_map)) | |
2941 | table->entry[i].spec |= | |
2942 | EFX_EF10_FILTER_FLAG_BUSY; | |
2943 | } | |
2944 | } | |
2945 | ||
2946 | spin_unlock_bh(&efx->filter_lock); | |
2947 | ||
2948 | rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, | |
2949 | replacing); | |
2950 | ||
2951 | /* Finalise the software table entry */ | |
2952 | spin_lock_bh(&efx->filter_lock); | |
2953 | if (rc == 0) { | |
2954 | if (replacing) { | |
2955 | /* Update the fields that may differ */ | |
7665d1ab BH |
2956 | if (saved_spec->priority == EFX_FILTER_PRI_AUTO) |
2957 | saved_spec->flags |= | |
2958 | EFX_FILTER_FLAG_RX_OVER_AUTO; | |
8127d661 | 2959 | saved_spec->priority = spec->priority; |
7665d1ab | 2960 | saved_spec->flags &= EFX_FILTER_FLAG_RX_OVER_AUTO; |
8127d661 BH |
2961 | saved_spec->flags |= spec->flags; |
2962 | saved_spec->rss_context = spec->rss_context; | |
2963 | saved_spec->dmaq_id = spec->dmaq_id; | |
2964 | } | |
2965 | } else if (!replacing) { | |
2966 | kfree(saved_spec); | |
2967 | saved_spec = NULL; | |
2968 | } | |
2969 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); | |
2970 | ||
2971 | /* Remove and finalise entries for lower-priority multicast | |
2972 | * recipients | |
2973 | */ | |
2974 | if (is_mc_recip) { | |
2975 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2976 | unsigned int depth, i; | |
2977 | ||
2978 | memset(inbuf, 0, sizeof(inbuf)); | |
2979 | ||
2980 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
2981 | if (!test_bit(depth, mc_rem_map)) | |
2982 | continue; | |
2983 | ||
2984 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2985 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2986 | priv_flags = efx_ef10_filter_entry_flags(table, i); | |
2987 | ||
2988 | if (rc == 0) { | |
2989 | spin_unlock_bh(&efx->filter_lock); | |
2990 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2991 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
2992 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
2993 | table->entry[i].handle); | |
2994 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
2995 | inbuf, sizeof(inbuf), | |
2996 | NULL, 0, NULL); | |
2997 | spin_lock_bh(&efx->filter_lock); | |
2998 | } | |
2999 | ||
3000 | if (rc == 0) { | |
3001 | kfree(saved_spec); | |
3002 | saved_spec = NULL; | |
3003 | priv_flags = 0; | |
3004 | } else { | |
3005 | priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
3006 | } | |
3007 | efx_ef10_filter_set_entry(table, i, saved_spec, | |
3008 | priv_flags); | |
3009 | } | |
3010 | } | |
3011 | ||
3012 | /* If successful, return the inserted filter ID */ | |
3013 | if (rc == 0) | |
3014 | rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index; | |
3015 | ||
3016 | wake_up_all(&table->waitq); | |
3017 | out_unlock: | |
3018 | spin_unlock_bh(&efx->filter_lock); | |
3019 | finish_wait(&table->waitq, &wait); | |
3020 | return rc; | |
3021 | } | |
3022 | ||
9fd8095d | 3023 | static void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx) |
8127d661 BH |
3024 | { |
3025 | /* no need to do anything here on EF10 */ | |
3026 | } | |
3027 | ||
3028 | /* Remove a filter. | |
b59e6ef8 BH |
3029 | * If !by_index, remove by ID |
3030 | * If by_index, remove by index | |
8127d661 BH |
3031 | * Filter ID may come from userland and must be range-checked. |
3032 | */ | |
3033 | static int efx_ef10_filter_remove_internal(struct efx_nic *efx, | |
fbd79120 | 3034 | unsigned int priority_mask, |
b59e6ef8 | 3035 | u32 filter_id, bool by_index) |
8127d661 BH |
3036 | { |
3037 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
3038 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3039 | MCDI_DECLARE_BUF(inbuf, | |
3040 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
3041 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
3042 | struct efx_filter_spec *spec; | |
3043 | DEFINE_WAIT(wait); | |
3044 | int rc; | |
3045 | ||
3046 | /* Find the software table entry and mark it busy. Don't | |
3047 | * remove it yet; any attempt to update while we're waiting | |
3048 | * for the firmware must find the busy entry. | |
3049 | */ | |
3050 | for (;;) { | |
3051 | spin_lock_bh(&efx->filter_lock); | |
3052 | if (!(table->entry[filter_idx].spec & | |
3053 | EFX_EF10_FILTER_FLAG_BUSY)) | |
3054 | break; | |
3055 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
3056 | spin_unlock_bh(&efx->filter_lock); | |
3057 | schedule(); | |
3058 | } | |
7665d1ab | 3059 | |
8127d661 | 3060 | spec = efx_ef10_filter_entry_spec(table, filter_idx); |
7665d1ab | 3061 | if (!spec || |
b59e6ef8 | 3062 | (!by_index && |
8127d661 BH |
3063 | efx_ef10_filter_rx_match_pri(table, spec->match_flags) != |
3064 | filter_id / HUNT_FILTER_TBL_ROWS)) { | |
3065 | rc = -ENOENT; | |
3066 | goto out_unlock; | |
3067 | } | |
7665d1ab BH |
3068 | |
3069 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO && | |
fbd79120 | 3070 | priority_mask == (1U << EFX_FILTER_PRI_AUTO)) { |
7665d1ab BH |
3071 | /* Just remove flags */ |
3072 | spec->flags &= ~EFX_FILTER_FLAG_RX_OVER_AUTO; | |
b59e6ef8 | 3073 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_AUTO_OLD; |
7665d1ab BH |
3074 | rc = 0; |
3075 | goto out_unlock; | |
3076 | } | |
3077 | ||
fbd79120 | 3078 | if (!(priority_mask & (1U << spec->priority))) { |
7665d1ab BH |
3079 | rc = -ENOENT; |
3080 | goto out_unlock; | |
3081 | } | |
3082 | ||
8127d661 BH |
3083 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; |
3084 | spin_unlock_bh(&efx->filter_lock); | |
3085 | ||
7665d1ab | 3086 | if (spec->flags & EFX_FILTER_FLAG_RX_OVER_AUTO) { |
b59e6ef8 | 3087 | /* Reset to an automatic filter */ |
8127d661 BH |
3088 | |
3089 | struct efx_filter_spec new_spec = *spec; | |
3090 | ||
7665d1ab | 3091 | new_spec.priority = EFX_FILTER_PRI_AUTO; |
8127d661 | 3092 | new_spec.flags = (EFX_FILTER_FLAG_RX | |
7665d1ab | 3093 | EFX_FILTER_FLAG_RX_RSS); |
8127d661 BH |
3094 | new_spec.dmaq_id = 0; |
3095 | new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT; | |
3096 | rc = efx_ef10_filter_push(efx, &new_spec, | |
3097 | &table->entry[filter_idx].handle, | |
3098 | true); | |
3099 | ||
3100 | spin_lock_bh(&efx->filter_lock); | |
3101 | if (rc == 0) | |
3102 | *spec = new_spec; | |
3103 | } else { | |
3104 | /* Really remove the filter */ | |
3105 | ||
3106 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3107 | efx_ef10_filter_is_exclusive(spec) ? | |
3108 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
3109 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
3110 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3111 | table->entry[filter_idx].handle); | |
3112 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
3113 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
3114 | ||
3115 | spin_lock_bh(&efx->filter_lock); | |
3116 | if (rc == 0) { | |
3117 | kfree(spec); | |
3118 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3119 | } | |
3120 | } | |
7665d1ab | 3121 | |
8127d661 BH |
3122 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; |
3123 | wake_up_all(&table->waitq); | |
3124 | out_unlock: | |
3125 | spin_unlock_bh(&efx->filter_lock); | |
3126 | finish_wait(&table->waitq, &wait); | |
3127 | return rc; | |
3128 | } | |
3129 | ||
3130 | static int efx_ef10_filter_remove_safe(struct efx_nic *efx, | |
3131 | enum efx_filter_priority priority, | |
3132 | u32 filter_id) | |
3133 | { | |
fbd79120 BH |
3134 | return efx_ef10_filter_remove_internal(efx, 1U << priority, |
3135 | filter_id, false); | |
8127d661 BH |
3136 | } |
3137 | ||
3138 | static int efx_ef10_filter_get_safe(struct efx_nic *efx, | |
3139 | enum efx_filter_priority priority, | |
3140 | u32 filter_id, struct efx_filter_spec *spec) | |
3141 | { | |
3142 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
3143 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3144 | const struct efx_filter_spec *saved_spec; | |
3145 | int rc; | |
3146 | ||
3147 | spin_lock_bh(&efx->filter_lock); | |
3148 | saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3149 | if (saved_spec && saved_spec->priority == priority && | |
3150 | efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) == | |
3151 | filter_id / HUNT_FILTER_TBL_ROWS) { | |
3152 | *spec = *saved_spec; | |
3153 | rc = 0; | |
3154 | } else { | |
3155 | rc = -ENOENT; | |
3156 | } | |
3157 | spin_unlock_bh(&efx->filter_lock); | |
3158 | return rc; | |
3159 | } | |
3160 | ||
fbd79120 | 3161 | static int efx_ef10_filter_clear_rx(struct efx_nic *efx, |
8127d661 BH |
3162 | enum efx_filter_priority priority) |
3163 | { | |
fbd79120 BH |
3164 | unsigned int priority_mask; |
3165 | unsigned int i; | |
3166 | int rc; | |
3167 | ||
3168 | priority_mask = (((1U << (priority + 1)) - 1) & | |
3169 | ~(1U << EFX_FILTER_PRI_AUTO)); | |
3170 | ||
3171 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { | |
3172 | rc = efx_ef10_filter_remove_internal(efx, priority_mask, | |
3173 | i, true); | |
3174 | if (rc && rc != -ENOENT) | |
3175 | return rc; | |
3176 | } | |
3177 | ||
3178 | return 0; | |
8127d661 BH |
3179 | } |
3180 | ||
3181 | static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, | |
3182 | enum efx_filter_priority priority) | |
3183 | { | |
3184 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3185 | unsigned int filter_idx; | |
3186 | s32 count = 0; | |
3187 | ||
3188 | spin_lock_bh(&efx->filter_lock); | |
3189 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3190 | if (table->entry[filter_idx].spec && | |
3191 | efx_ef10_filter_entry_spec(table, filter_idx)->priority == | |
3192 | priority) | |
3193 | ++count; | |
3194 | } | |
3195 | spin_unlock_bh(&efx->filter_lock); | |
3196 | return count; | |
3197 | } | |
3198 | ||
3199 | static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx) | |
3200 | { | |
3201 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3202 | ||
3203 | return table->rx_match_count * HUNT_FILTER_TBL_ROWS; | |
3204 | } | |
3205 | ||
3206 | static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx, | |
3207 | enum efx_filter_priority priority, | |
3208 | u32 *buf, u32 size) | |
3209 | { | |
3210 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3211 | struct efx_filter_spec *spec; | |
3212 | unsigned int filter_idx; | |
3213 | s32 count = 0; | |
3214 | ||
3215 | spin_lock_bh(&efx->filter_lock); | |
3216 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3217 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3218 | if (spec && spec->priority == priority) { | |
3219 | if (count == size) { | |
3220 | count = -EMSGSIZE; | |
3221 | break; | |
3222 | } | |
3223 | buf[count++] = (efx_ef10_filter_rx_match_pri( | |
3224 | table, spec->match_flags) * | |
3225 | HUNT_FILTER_TBL_ROWS + | |
3226 | filter_idx); | |
3227 | } | |
3228 | } | |
3229 | spin_unlock_bh(&efx->filter_lock); | |
3230 | return count; | |
3231 | } | |
3232 | ||
3233 | #ifdef CONFIG_RFS_ACCEL | |
3234 | ||
3235 | static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete; | |
3236 | ||
3237 | static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx, | |
3238 | struct efx_filter_spec *spec) | |
3239 | { | |
3240 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3241 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
3242 | struct efx_filter_spec *saved_spec; | |
3243 | unsigned int hash, i, depth = 1; | |
3244 | bool replacing = false; | |
3245 | int ins_index = -1; | |
3246 | u64 cookie; | |
3247 | s32 rc; | |
3248 | ||
3249 | /* Must be an RX filter without RSS and not for a multicast | |
3250 | * destination address (RFS only works for connected sockets). | |
3251 | * These restrictions allow us to pass only a tiny amount of | |
3252 | * data through to the completion function. | |
3253 | */ | |
3254 | EFX_WARN_ON_PARANOID(spec->flags != | |
3255 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER)); | |
3256 | EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT); | |
3257 | EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec)); | |
3258 | ||
3259 | hash = efx_ef10_filter_hash(spec); | |
3260 | ||
3261 | spin_lock_bh(&efx->filter_lock); | |
3262 | ||
3263 | /* Find any existing filter with the same match tuple or else | |
3264 | * a free slot to insert at. If an existing filter is busy, | |
3265 | * we have to give up. | |
3266 | */ | |
3267 | for (;;) { | |
3268 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
3269 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
3270 | ||
3271 | if (!saved_spec) { | |
3272 | if (ins_index < 0) | |
3273 | ins_index = i; | |
3274 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
3275 | if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) { | |
3276 | rc = -EBUSY; | |
3277 | goto fail_unlock; | |
3278 | } | |
8127d661 BH |
3279 | if (spec->priority < saved_spec->priority) { |
3280 | rc = -EPERM; | |
3281 | goto fail_unlock; | |
3282 | } | |
3283 | ins_index = i; | |
3284 | break; | |
3285 | } | |
3286 | ||
3287 | /* Once we reach the maximum search depth, use the | |
3288 | * first suitable slot or return -EBUSY if there was | |
3289 | * none | |
3290 | */ | |
3291 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
3292 | if (ins_index < 0) { | |
3293 | rc = -EBUSY; | |
3294 | goto fail_unlock; | |
3295 | } | |
3296 | break; | |
3297 | } | |
3298 | ||
3299 | ++depth; | |
3300 | } | |
3301 | ||
3302 | /* Create a software table entry if necessary, and mark it | |
3303 | * busy. We might yet fail to insert, but any attempt to | |
3304 | * insert a conflicting filter while we're waiting for the | |
3305 | * firmware must find the busy entry. | |
3306 | */ | |
3307 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
3308 | if (saved_spec) { | |
3309 | replacing = true; | |
3310 | } else { | |
3311 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
3312 | if (!saved_spec) { | |
3313 | rc = -ENOMEM; | |
3314 | goto fail_unlock; | |
3315 | } | |
3316 | *saved_spec = *spec; | |
3317 | } | |
3318 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
3319 | EFX_EF10_FILTER_FLAG_BUSY); | |
3320 | ||
3321 | spin_unlock_bh(&efx->filter_lock); | |
3322 | ||
3323 | /* Pack up the variables needed on completion */ | |
3324 | cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id; | |
3325 | ||
3326 | efx_ef10_filter_push_prep(efx, spec, inbuf, | |
3327 | table->entry[ins_index].handle, replacing); | |
3328 | efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
3329 | MC_CMD_FILTER_OP_OUT_LEN, | |
3330 | efx_ef10_filter_rfs_insert_complete, cookie); | |
3331 | ||
3332 | return ins_index; | |
3333 | ||
3334 | fail_unlock: | |
3335 | spin_unlock_bh(&efx->filter_lock); | |
3336 | return rc; | |
3337 | } | |
3338 | ||
3339 | static void | |
3340 | efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie, | |
3341 | int rc, efx_dword_t *outbuf, | |
3342 | size_t outlen_actual) | |
3343 | { | |
3344 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3345 | unsigned int ins_index, dmaq_id; | |
3346 | struct efx_filter_spec *spec; | |
3347 | bool replacing; | |
3348 | ||
3349 | /* Unpack the cookie */ | |
3350 | replacing = cookie >> 31; | |
3351 | ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1); | |
3352 | dmaq_id = cookie & 0xffff; | |
3353 | ||
3354 | spin_lock_bh(&efx->filter_lock); | |
3355 | spec = efx_ef10_filter_entry_spec(table, ins_index); | |
3356 | if (rc == 0) { | |
3357 | table->entry[ins_index].handle = | |
3358 | MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
3359 | if (replacing) | |
3360 | spec->dmaq_id = dmaq_id; | |
3361 | } else if (!replacing) { | |
3362 | kfree(spec); | |
3363 | spec = NULL; | |
3364 | } | |
3365 | efx_ef10_filter_set_entry(table, ins_index, spec, 0); | |
3366 | spin_unlock_bh(&efx->filter_lock); | |
3367 | ||
3368 | wake_up_all(&table->waitq); | |
3369 | } | |
3370 | ||
3371 | static void | |
3372 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
3373 | unsigned long filter_idx, | |
3374 | int rc, efx_dword_t *outbuf, | |
3375 | size_t outlen_actual); | |
3376 | ||
3377 | static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, | |
3378 | unsigned int filter_idx) | |
3379 | { | |
3380 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3381 | struct efx_filter_spec *spec = | |
3382 | efx_ef10_filter_entry_spec(table, filter_idx); | |
3383 | MCDI_DECLARE_BUF(inbuf, | |
3384 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
3385 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
3386 | ||
3387 | if (!spec || | |
3388 | (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) || | |
3389 | spec->priority != EFX_FILTER_PRI_HINT || | |
3390 | !rps_may_expire_flow(efx->net_dev, spec->dmaq_id, | |
3391 | flow_id, filter_idx)) | |
3392 | return false; | |
3393 | ||
3394 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3395 | MC_CMD_FILTER_OP_IN_OP_REMOVE); | |
3396 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3397 | table->entry[filter_idx].handle); | |
3398 | if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0, | |
3399 | efx_ef10_filter_rfs_expire_complete, filter_idx)) | |
3400 | return false; | |
3401 | ||
3402 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
3403 | return true; | |
3404 | } | |
3405 | ||
3406 | static void | |
3407 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
3408 | unsigned long filter_idx, | |
3409 | int rc, efx_dword_t *outbuf, | |
3410 | size_t outlen_actual) | |
3411 | { | |
3412 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3413 | struct efx_filter_spec *spec = | |
3414 | efx_ef10_filter_entry_spec(table, filter_idx); | |
3415 | ||
3416 | spin_lock_bh(&efx->filter_lock); | |
3417 | if (rc == 0) { | |
3418 | kfree(spec); | |
3419 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3420 | } | |
3421 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
3422 | wake_up_all(&table->waitq); | |
3423 | spin_unlock_bh(&efx->filter_lock); | |
3424 | } | |
3425 | ||
3426 | #endif /* CONFIG_RFS_ACCEL */ | |
3427 | ||
3428 | static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags) | |
3429 | { | |
3430 | int match_flags = 0; | |
3431 | ||
3432 | #define MAP_FLAG(gen_flag, mcdi_field) { \ | |
3433 | u32 old_mcdi_flags = mcdi_flags; \ | |
3434 | mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
3435 | mcdi_field ## _LBN); \ | |
3436 | if (mcdi_flags != old_mcdi_flags) \ | |
3437 | match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \ | |
3438 | } | |
3439 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST); | |
3440 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST); | |
3441 | MAP_FLAG(REM_HOST, SRC_IP); | |
3442 | MAP_FLAG(LOC_HOST, DST_IP); | |
3443 | MAP_FLAG(REM_MAC, SRC_MAC); | |
3444 | MAP_FLAG(REM_PORT, SRC_PORT); | |
3445 | MAP_FLAG(LOC_MAC, DST_MAC); | |
3446 | MAP_FLAG(LOC_PORT, DST_PORT); | |
3447 | MAP_FLAG(ETHER_TYPE, ETHER_TYPE); | |
3448 | MAP_FLAG(INNER_VID, INNER_VLAN); | |
3449 | MAP_FLAG(OUTER_VID, OUTER_VLAN); | |
3450 | MAP_FLAG(IP_PROTO, IP_PROTO); | |
3451 | #undef MAP_FLAG | |
3452 | ||
3453 | /* Did we map them all? */ | |
3454 | if (mcdi_flags) | |
3455 | return -EINVAL; | |
3456 | ||
3457 | return match_flags; | |
3458 | } | |
3459 | ||
3460 | static int efx_ef10_filter_table_probe(struct efx_nic *efx) | |
3461 | { | |
3462 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN); | |
3463 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX); | |
3464 | unsigned int pd_match_pri, pd_match_count; | |
3465 | struct efx_ef10_filter_table *table; | |
3466 | size_t outlen; | |
3467 | int rc; | |
3468 | ||
3469 | table = kzalloc(sizeof(*table), GFP_KERNEL); | |
3470 | if (!table) | |
3471 | return -ENOMEM; | |
3472 | ||
3473 | /* Find out which RX filter types are supported, and their priorities */ | |
3474 | MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP, | |
3475 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES); | |
3476 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO, | |
3477 | inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), | |
3478 | &outlen); | |
3479 | if (rc) | |
3480 | goto fail; | |
3481 | pd_match_count = MCDI_VAR_ARRAY_LEN( | |
3482 | outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES); | |
3483 | table->rx_match_count = 0; | |
3484 | ||
3485 | for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) { | |
3486 | u32 mcdi_flags = | |
3487 | MCDI_ARRAY_DWORD( | |
3488 | outbuf, | |
3489 | GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES, | |
3490 | pd_match_pri); | |
3491 | rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags); | |
3492 | if (rc < 0) { | |
3493 | netif_dbg(efx, probe, efx->net_dev, | |
3494 | "%s: fw flags %#x pri %u not supported in driver\n", | |
3495 | __func__, mcdi_flags, pd_match_pri); | |
3496 | } else { | |
3497 | netif_dbg(efx, probe, efx->net_dev, | |
3498 | "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", | |
3499 | __func__, mcdi_flags, pd_match_pri, | |
3500 | rc, table->rx_match_count); | |
3501 | table->rx_match_flags[table->rx_match_count++] = rc; | |
3502 | } | |
3503 | } | |
3504 | ||
3505 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); | |
3506 | if (!table->entry) { | |
3507 | rc = -ENOMEM; | |
3508 | goto fail; | |
3509 | } | |
3510 | ||
3511 | efx->filter_state = table; | |
3512 | init_waitqueue_head(&table->waitq); | |
3513 | return 0; | |
3514 | ||
3515 | fail: | |
3516 | kfree(table); | |
3517 | return rc; | |
3518 | } | |
3519 | ||
0d322413 EC |
3520 | /* Caller must hold efx->filter_sem for read if race against |
3521 | * efx_ef10_filter_table_remove() is possible | |
3522 | */ | |
8127d661 BH |
3523 | static void efx_ef10_filter_table_restore(struct efx_nic *efx) |
3524 | { | |
3525 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3526 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
3527 | struct efx_filter_spec *spec; | |
3528 | unsigned int filter_idx; | |
3529 | bool failed = false; | |
3530 | int rc; | |
3531 | ||
0d322413 EC |
3532 | WARN_ON(!rwsem_is_locked(&efx->filter_sem)); |
3533 | ||
8127d661 BH |
3534 | if (!nic_data->must_restore_filters) |
3535 | return; | |
3536 | ||
0d322413 EC |
3537 | if (!table) |
3538 | return; | |
3539 | ||
8127d661 BH |
3540 | spin_lock_bh(&efx->filter_lock); |
3541 | ||
3542 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
3543 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3544 | if (!spec) | |
3545 | continue; | |
3546 | ||
3547 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
3548 | spin_unlock_bh(&efx->filter_lock); | |
3549 | ||
3550 | rc = efx_ef10_filter_push(efx, spec, | |
3551 | &table->entry[filter_idx].handle, | |
3552 | false); | |
3553 | if (rc) | |
3554 | failed = true; | |
3555 | ||
3556 | spin_lock_bh(&efx->filter_lock); | |
3557 | if (rc) { | |
3558 | kfree(spec); | |
3559 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
3560 | } else { | |
3561 | table->entry[filter_idx].spec &= | |
3562 | ~EFX_EF10_FILTER_FLAG_BUSY; | |
3563 | } | |
3564 | } | |
3565 | ||
3566 | spin_unlock_bh(&efx->filter_lock); | |
3567 | ||
3568 | if (failed) | |
3569 | netif_err(efx, hw, efx->net_dev, | |
3570 | "unable to restore all filters\n"); | |
3571 | else | |
3572 | nic_data->must_restore_filters = false; | |
3573 | } | |
3574 | ||
0d322413 | 3575 | /* Caller must hold efx->filter_sem for write */ |
8127d661 BH |
3576 | static void efx_ef10_filter_table_remove(struct efx_nic *efx) |
3577 | { | |
3578 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3579 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
3580 | struct efx_filter_spec *spec; | |
3581 | unsigned int filter_idx; | |
3582 | int rc; | |
3583 | ||
0d322413 EC |
3584 | efx->filter_state = NULL; |
3585 | if (!table) | |
3586 | return; | |
3587 | ||
8127d661 BH |
3588 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { |
3589 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
3590 | if (!spec) | |
3591 | continue; | |
3592 | ||
3593 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
3594 | efx_ef10_filter_is_exclusive(spec) ? | |
3595 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
3596 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
3597 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
3598 | table->entry[filter_idx].handle); | |
3599 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
3600 | NULL, 0, NULL); | |
48ce5634 BH |
3601 | if (rc) |
3602 | netdev_WARN(efx->net_dev, | |
3603 | "filter_idx=%#x handle=%#llx\n", | |
3604 | filter_idx, | |
3605 | table->entry[filter_idx].handle); | |
8127d661 BH |
3606 | kfree(spec); |
3607 | } | |
3608 | ||
3609 | vfree(table->entry); | |
3610 | kfree(table); | |
3611 | } | |
3612 | ||
0d322413 EC |
3613 | /* Caller must hold efx->filter_sem for read if race against |
3614 | * efx_ef10_filter_table_remove() is possible | |
3615 | */ | |
8127d661 BH |
3616 | static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx) |
3617 | { | |
3618 | struct efx_ef10_filter_table *table = efx->filter_state; | |
3619 | struct net_device *net_dev = efx->net_dev; | |
3620 | struct efx_filter_spec spec; | |
3621 | bool remove_failed = false; | |
3622 | struct netdev_hw_addr *uc; | |
3623 | struct netdev_hw_addr *mc; | |
3624 | unsigned int filter_idx; | |
3625 | int i, n, rc; | |
3626 | ||
3627 | if (!efx_dev_registered(efx)) | |
3628 | return; | |
3629 | ||
0d322413 EC |
3630 | if (!table) |
3631 | return; | |
3632 | ||
8127d661 BH |
3633 | /* Mark old filters that may need to be removed */ |
3634 | spin_lock_bh(&efx->filter_lock); | |
b59e6ef8 | 3635 | n = table->dev_uc_count < 0 ? 1 : table->dev_uc_count; |
8127d661 | 3636 | for (i = 0; i < n; i++) { |
b59e6ef8 BH |
3637 | filter_idx = table->dev_uc_list[i].id % HUNT_FILTER_TBL_ROWS; |
3638 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; | |
8127d661 | 3639 | } |
b59e6ef8 | 3640 | n = table->dev_mc_count < 0 ? 1 : table->dev_mc_count; |
8127d661 | 3641 | for (i = 0; i < n; i++) { |
b59e6ef8 BH |
3642 | filter_idx = table->dev_mc_list[i].id % HUNT_FILTER_TBL_ROWS; |
3643 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_AUTO_OLD; | |
8127d661 BH |
3644 | } |
3645 | spin_unlock_bh(&efx->filter_lock); | |
3646 | ||
3647 | /* Copy/convert the address lists; add the primary station | |
3648 | * address and broadcast address | |
3649 | */ | |
3650 | netif_addr_lock_bh(net_dev); | |
3651 | if (net_dev->flags & IFF_PROMISC || | |
b59e6ef8 BH |
3652 | netdev_uc_count(net_dev) >= EFX_EF10_FILTER_DEV_UC_MAX) { |
3653 | table->dev_uc_count = -1; | |
8127d661 | 3654 | } else { |
b59e6ef8 | 3655 | table->dev_uc_count = 1 + netdev_uc_count(net_dev); |
cd84ff4d | 3656 | ether_addr_copy(table->dev_uc_list[0].addr, net_dev->dev_addr); |
8127d661 BH |
3657 | i = 1; |
3658 | netdev_for_each_uc_addr(uc, net_dev) { | |
cd84ff4d | 3659 | ether_addr_copy(table->dev_uc_list[i].addr, uc->addr); |
8127d661 BH |
3660 | i++; |
3661 | } | |
3662 | } | |
3663 | if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) || | |
b59e6ef8 BH |
3664 | netdev_mc_count(net_dev) >= EFX_EF10_FILTER_DEV_MC_MAX) { |
3665 | table->dev_mc_count = -1; | |
8127d661 | 3666 | } else { |
b59e6ef8 BH |
3667 | table->dev_mc_count = 1 + netdev_mc_count(net_dev); |
3668 | eth_broadcast_addr(table->dev_mc_list[0].addr); | |
8127d661 BH |
3669 | i = 1; |
3670 | netdev_for_each_mc_addr(mc, net_dev) { | |
cd84ff4d | 3671 | ether_addr_copy(table->dev_mc_list[i].addr, mc->addr); |
8127d661 BH |
3672 | i++; |
3673 | } | |
3674 | } | |
3675 | netif_addr_unlock_bh(net_dev); | |
3676 | ||
3677 | /* Insert/renew unicast filters */ | |
b59e6ef8 BH |
3678 | if (table->dev_uc_count >= 0) { |
3679 | for (i = 0; i < table->dev_uc_count; i++) { | |
7665d1ab BH |
3680 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3681 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3682 | 0); |
3683 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
b59e6ef8 | 3684 | table->dev_uc_list[i].addr); |
8127d661 BH |
3685 | rc = efx_ef10_filter_insert(efx, &spec, true); |
3686 | if (rc < 0) { | |
3687 | /* Fall back to unicast-promisc */ | |
3688 | while (i--) | |
3689 | efx_ef10_filter_remove_safe( | |
7665d1ab | 3690 | efx, EFX_FILTER_PRI_AUTO, |
b59e6ef8 BH |
3691 | table->dev_uc_list[i].id); |
3692 | table->dev_uc_count = -1; | |
8127d661 BH |
3693 | break; |
3694 | } | |
b59e6ef8 | 3695 | table->dev_uc_list[i].id = rc; |
8127d661 BH |
3696 | } |
3697 | } | |
b59e6ef8 | 3698 | if (table->dev_uc_count < 0) { |
7665d1ab BH |
3699 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3700 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3701 | 0); |
3702 | efx_filter_set_uc_def(&spec); | |
3703 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
3704 | if (rc < 0) { | |
3705 | WARN_ON(1); | |
b59e6ef8 | 3706 | table->dev_uc_count = 0; |
8127d661 | 3707 | } else { |
b59e6ef8 | 3708 | table->dev_uc_list[0].id = rc; |
8127d661 BH |
3709 | } |
3710 | } | |
3711 | ||
3712 | /* Insert/renew multicast filters */ | |
b59e6ef8 BH |
3713 | if (table->dev_mc_count >= 0) { |
3714 | for (i = 0; i < table->dev_mc_count; i++) { | |
7665d1ab BH |
3715 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3716 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3717 | 0); |
3718 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
b59e6ef8 | 3719 | table->dev_mc_list[i].addr); |
8127d661 BH |
3720 | rc = efx_ef10_filter_insert(efx, &spec, true); |
3721 | if (rc < 0) { | |
3722 | /* Fall back to multicast-promisc */ | |
3723 | while (i--) | |
3724 | efx_ef10_filter_remove_safe( | |
7665d1ab | 3725 | efx, EFX_FILTER_PRI_AUTO, |
b59e6ef8 BH |
3726 | table->dev_mc_list[i].id); |
3727 | table->dev_mc_count = -1; | |
8127d661 BH |
3728 | break; |
3729 | } | |
b59e6ef8 | 3730 | table->dev_mc_list[i].id = rc; |
8127d661 BH |
3731 | } |
3732 | } | |
b59e6ef8 | 3733 | if (table->dev_mc_count < 0) { |
7665d1ab BH |
3734 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_AUTO, |
3735 | EFX_FILTER_FLAG_RX_RSS, | |
8127d661 BH |
3736 | 0); |
3737 | efx_filter_set_mc_def(&spec); | |
3738 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
3739 | if (rc < 0) { | |
3740 | WARN_ON(1); | |
b59e6ef8 | 3741 | table->dev_mc_count = 0; |
8127d661 | 3742 | } else { |
b59e6ef8 | 3743 | table->dev_mc_list[0].id = rc; |
8127d661 BH |
3744 | } |
3745 | } | |
3746 | ||
3747 | /* Remove filters that weren't renewed. Since nothing else | |
b59e6ef8 | 3748 | * changes the AUTO_OLD flag or removes these filters, we |
8127d661 BH |
3749 | * don't need to hold the filter_lock while scanning for |
3750 | * these filters. | |
3751 | */ | |
3752 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { | |
3753 | if (ACCESS_ONCE(table->entry[i].spec) & | |
b59e6ef8 | 3754 | EFX_EF10_FILTER_FLAG_AUTO_OLD) { |
7665d1ab | 3755 | if (efx_ef10_filter_remove_internal( |
fbd79120 BH |
3756 | efx, 1U << EFX_FILTER_PRI_AUTO, |
3757 | i, true) < 0) | |
8127d661 BH |
3758 | remove_failed = true; |
3759 | } | |
3760 | } | |
3761 | WARN_ON(remove_failed); | |
3762 | } | |
3763 | ||
910c8789 SS |
3764 | static int efx_ef10_set_mac_address(struct efx_nic *efx) |
3765 | { | |
3766 | MCDI_DECLARE_BUF(inbuf, MC_CMD_VADAPTOR_SET_MAC_IN_LEN); | |
3767 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
3768 | bool was_enabled = efx->port_enabled; | |
3769 | int rc; | |
3770 | ||
3771 | efx_device_detach_sync(efx); | |
3772 | efx_net_stop(efx->net_dev); | |
3773 | down_write(&efx->filter_sem); | |
3774 | efx_ef10_filter_table_remove(efx); | |
3775 | ||
3776 | ether_addr_copy(MCDI_PTR(inbuf, VADAPTOR_SET_MAC_IN_MACADDR), | |
3777 | efx->net_dev->dev_addr); | |
3778 | MCDI_SET_DWORD(inbuf, VADAPTOR_SET_MAC_IN_UPSTREAM_PORT_ID, | |
3779 | nic_data->vport_id); | |
3780 | rc = efx_mcdi_rpc(efx, MC_CMD_VADAPTOR_SET_MAC, inbuf, | |
3781 | sizeof(inbuf), NULL, 0, NULL); | |
3782 | ||
3783 | efx_ef10_filter_table_probe(efx); | |
3784 | up_write(&efx->filter_sem); | |
3785 | if (was_enabled) | |
3786 | efx_net_open(efx->net_dev); | |
3787 | netif_device_attach(efx->net_dev); | |
3788 | ||
3789 | #if !defined(CONFIG_SFC_SRIOV) | |
3790 | if (rc == -EPERM) | |
3791 | netif_err(efx, drv, efx->net_dev, | |
3792 | "Cannot change MAC address; use sfboot to enable mac-spoofing" | |
3793 | " on this interface\n"); | |
3794 | #else | |
3795 | if (rc == -EPERM) { | |
3796 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; | |
3797 | ||
3798 | /* Switch to PF and change MAC address on vport */ | |
3799 | if (efx->pci_dev->is_virtfn && pci_dev_pf) { | |
3800 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); | |
3801 | ||
3802 | if (!efx_ef10_sriov_set_vf_mac(efx_pf, | |
3803 | nic_data->vf_index, | |
3804 | efx->net_dev->dev_addr)) | |
3805 | return 0; | |
3806 | } | |
3807 | netif_err(efx, drv, efx->net_dev, | |
3808 | "Cannot change MAC address; use sfboot to enable mac-spoofing" | |
3809 | " on this interface\n"); | |
3810 | } else if (efx->pci_dev->is_virtfn) { | |
3811 | /* Successfully changed by VF (with MAC spoofing), so update the | |
3812 | * parent PF if possible. | |
3813 | */ | |
3814 | struct pci_dev *pci_dev_pf = efx->pci_dev->physfn; | |
3815 | ||
3816 | if (pci_dev_pf) { | |
3817 | struct efx_nic *efx_pf = pci_get_drvdata(pci_dev_pf); | |
3818 | struct efx_ef10_nic_data *nic_data = efx_pf->nic_data; | |
3819 | unsigned int i; | |
3820 | ||
3821 | for (i = 0; i < efx_pf->vf_count; ++i) { | |
3822 | struct ef10_vf *vf = nic_data->vf + i; | |
3823 | ||
3824 | if (vf->efx == efx) { | |
3825 | ether_addr_copy(vf->mac, | |
3826 | efx->net_dev->dev_addr); | |
3827 | return 0; | |
3828 | } | |
3829 | } | |
3830 | } | |
3831 | } | |
3832 | #endif | |
3833 | return rc; | |
3834 | } | |
3835 | ||
8127d661 BH |
3836 | static int efx_ef10_mac_reconfigure(struct efx_nic *efx) |
3837 | { | |
3838 | efx_ef10_filter_sync_rx_mode(efx); | |
3839 | ||
3840 | return efx_mcdi_set_mac(efx); | |
3841 | } | |
3842 | ||
862f894c SS |
3843 | static int efx_ef10_mac_reconfigure_vf(struct efx_nic *efx) |
3844 | { | |
3845 | efx_ef10_filter_sync_rx_mode(efx); | |
3846 | ||
3847 | return 0; | |
3848 | } | |
3849 | ||
74cd60a4 JC |
3850 | static int efx_ef10_start_bist(struct efx_nic *efx, u32 bist_type) |
3851 | { | |
3852 | MCDI_DECLARE_BUF(inbuf, MC_CMD_START_BIST_IN_LEN); | |
3853 | ||
3854 | MCDI_SET_DWORD(inbuf, START_BIST_IN_TYPE, bist_type); | |
3855 | return efx_mcdi_rpc(efx, MC_CMD_START_BIST, inbuf, sizeof(inbuf), | |
3856 | NULL, 0, NULL); | |
3857 | } | |
3858 | ||
3859 | /* MC BISTs follow a different poll mechanism to phy BISTs. | |
3860 | * The BIST is done in the poll handler on the MC, and the MCDI command | |
3861 | * will block until the BIST is done. | |
3862 | */ | |
3863 | static int efx_ef10_poll_bist(struct efx_nic *efx) | |
3864 | { | |
3865 | int rc; | |
3866 | MCDI_DECLARE_BUF(outbuf, MC_CMD_POLL_BIST_OUT_LEN); | |
3867 | size_t outlen; | |
3868 | u32 result; | |
3869 | ||
3870 | rc = efx_mcdi_rpc(efx, MC_CMD_POLL_BIST, NULL, 0, | |
3871 | outbuf, sizeof(outbuf), &outlen); | |
3872 | if (rc != 0) | |
3873 | return rc; | |
3874 | ||
3875 | if (outlen < MC_CMD_POLL_BIST_OUT_LEN) | |
3876 | return -EIO; | |
3877 | ||
3878 | result = MCDI_DWORD(outbuf, POLL_BIST_OUT_RESULT); | |
3879 | switch (result) { | |
3880 | case MC_CMD_POLL_BIST_PASSED: | |
3881 | netif_dbg(efx, hw, efx->net_dev, "BIST passed.\n"); | |
3882 | return 0; | |
3883 | case MC_CMD_POLL_BIST_TIMEOUT: | |
3884 | netif_err(efx, hw, efx->net_dev, "BIST timed out\n"); | |
3885 | return -EIO; | |
3886 | case MC_CMD_POLL_BIST_FAILED: | |
3887 | netif_err(efx, hw, efx->net_dev, "BIST failed.\n"); | |
3888 | return -EIO; | |
3889 | default: | |
3890 | netif_err(efx, hw, efx->net_dev, | |
3891 | "BIST returned unknown result %u", result); | |
3892 | return -EIO; | |
3893 | } | |
3894 | } | |
3895 | ||
3896 | static int efx_ef10_run_bist(struct efx_nic *efx, u32 bist_type) | |
3897 | { | |
3898 | int rc; | |
3899 | ||
3900 | netif_dbg(efx, drv, efx->net_dev, "starting BIST type %u\n", bist_type); | |
3901 | ||
3902 | rc = efx_ef10_start_bist(efx, bist_type); | |
3903 | if (rc != 0) | |
3904 | return rc; | |
3905 | ||
3906 | return efx_ef10_poll_bist(efx); | |
3907 | } | |
3908 | ||
3909 | static int | |
3910 | efx_ef10_test_chip(struct efx_nic *efx, struct efx_self_tests *tests) | |
3911 | { | |
3912 | int rc, rc2; | |
3913 | ||
3914 | efx_reset_down(efx, RESET_TYPE_WORLD); | |
3915 | ||
3916 | rc = efx_mcdi_rpc(efx, MC_CMD_ENABLE_OFFLINE_BIST, | |
3917 | NULL, 0, NULL, 0, NULL); | |
3918 | if (rc != 0) | |
3919 | goto out; | |
3920 | ||
3921 | tests->memory = efx_ef10_run_bist(efx, MC_CMD_MC_MEM_BIST) ? -1 : 1; | |
3922 | tests->registers = efx_ef10_run_bist(efx, MC_CMD_REG_BIST) ? -1 : 1; | |
3923 | ||
3924 | rc = efx_mcdi_reset(efx, RESET_TYPE_WORLD); | |
3925 | ||
3926 | out: | |
3927 | rc2 = efx_reset_up(efx, RESET_TYPE_WORLD, rc == 0); | |
3928 | return rc ? rc : rc2; | |
3929 | } | |
3930 | ||
8127d661 BH |
3931 | #ifdef CONFIG_SFC_MTD |
3932 | ||
3933 | struct efx_ef10_nvram_type_info { | |
3934 | u16 type, type_mask; | |
3935 | u8 port; | |
3936 | const char *name; | |
3937 | }; | |
3938 | ||
3939 | static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { | |
3940 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" }, | |
3941 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" }, | |
3942 | { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" }, | |
3943 | { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" }, | |
3944 | { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" }, | |
3945 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" }, | |
3946 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" }, | |
3947 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" }, | |
3948 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" }, | |
a84f3bf9 | 3949 | { NVRAM_PARTITION_TYPE_LICENSE, 0, 0, "sfc_license" }, |
8127d661 BH |
3950 | { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, |
3951 | }; | |
3952 | ||
3953 | static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, | |
3954 | struct efx_mcdi_mtd_partition *part, | |
3955 | unsigned int type) | |
3956 | { | |
3957 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); | |
3958 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); | |
3959 | const struct efx_ef10_nvram_type_info *info; | |
3960 | size_t size, erase_size, outlen; | |
3961 | bool protected; | |
3962 | int rc; | |
3963 | ||
3964 | for (info = efx_ef10_nvram_types; ; info++) { | |
3965 | if (info == | |
3966 | efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) | |
3967 | return -ENODEV; | |
3968 | if ((type & ~info->type_mask) == info->type) | |
3969 | break; | |
3970 | } | |
3971 | if (info->port != efx_port_num(efx)) | |
3972 | return -ENODEV; | |
3973 | ||
3974 | rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected); | |
3975 | if (rc) | |
3976 | return rc; | |
3977 | if (protected) | |
3978 | return -ENODEV; /* hide it */ | |
3979 | ||
3980 | part->nvram_type = type; | |
3981 | ||
3982 | MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); | |
3983 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf), | |
3984 | outbuf, sizeof(outbuf), &outlen); | |
3985 | if (rc) | |
3986 | return rc; | |
3987 | if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) | |
3988 | return -EIO; | |
3989 | if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) & | |
3990 | (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) | |
3991 | part->fw_subtype = MCDI_DWORD(outbuf, | |
3992 | NVRAM_METADATA_OUT_SUBTYPE); | |
3993 | ||
3994 | part->common.dev_type_name = "EF10 NVRAM manager"; | |
3995 | part->common.type_name = info->name; | |
3996 | ||
3997 | part->common.mtd.type = MTD_NORFLASH; | |
3998 | part->common.mtd.flags = MTD_CAP_NORFLASH; | |
3999 | part->common.mtd.size = size; | |
4000 | part->common.mtd.erasesize = erase_size; | |
4001 | ||
4002 | return 0; | |
4003 | } | |
4004 | ||
4005 | static int efx_ef10_mtd_probe(struct efx_nic *efx) | |
4006 | { | |
4007 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); | |
4008 | struct efx_mcdi_mtd_partition *parts; | |
4009 | size_t outlen, n_parts_total, i, n_parts; | |
4010 | unsigned int type; | |
4011 | int rc; | |
4012 | ||
4013 | ASSERT_RTNL(); | |
4014 | ||
4015 | BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0); | |
4016 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0, | |
4017 | outbuf, sizeof(outbuf), &outlen); | |
4018 | if (rc) | |
4019 | return rc; | |
4020 | if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN) | |
4021 | return -EIO; | |
4022 | ||
4023 | n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS); | |
4024 | if (n_parts_total > | |
4025 | MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID)) | |
4026 | return -EIO; | |
4027 | ||
4028 | parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL); | |
4029 | if (!parts) | |
4030 | return -ENOMEM; | |
4031 | ||
4032 | n_parts = 0; | |
4033 | for (i = 0; i < n_parts_total; i++) { | |
4034 | type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, | |
4035 | i); | |
4036 | rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); | |
4037 | if (rc == 0) | |
4038 | n_parts++; | |
4039 | else if (rc != -ENODEV) | |
4040 | goto fail; | |
4041 | } | |
4042 | ||
4043 | rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); | |
4044 | fail: | |
4045 | if (rc) | |
4046 | kfree(parts); | |
4047 | return rc; | |
4048 | } | |
4049 | ||
4050 | #endif /* CONFIG_SFC_MTD */ | |
4051 | ||
4052 | static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time) | |
4053 | { | |
4054 | _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD); | |
4055 | } | |
4056 | ||
02246a7f SS |
4057 | static void efx_ef10_ptp_write_host_time_vf(struct efx_nic *efx, |
4058 | u32 host_time) {} | |
4059 | ||
bd9a265d JC |
4060 | static int efx_ef10_rx_enable_timestamping(struct efx_channel *channel, |
4061 | bool temp) | |
4062 | { | |
4063 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_SUBSCRIBE_LEN); | |
4064 | int rc; | |
4065 | ||
4066 | if (channel->sync_events_state == SYNC_EVENTS_REQUESTED || | |
4067 | channel->sync_events_state == SYNC_EVENTS_VALID || | |
4068 | (temp && channel->sync_events_state == SYNC_EVENTS_DISABLED)) | |
4069 | return 0; | |
4070 | channel->sync_events_state = SYNC_EVENTS_REQUESTED; | |
4071 | ||
4072 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_SUBSCRIBE); | |
4073 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); | |
4074 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_SUBSCRIBE_QUEUE, | |
4075 | channel->channel); | |
4076 | ||
4077 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, | |
4078 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
4079 | ||
4080 | if (rc != 0) | |
4081 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : | |
4082 | SYNC_EVENTS_DISABLED; | |
4083 | ||
4084 | return rc; | |
4085 | } | |
4086 | ||
4087 | static int efx_ef10_rx_disable_timestamping(struct efx_channel *channel, | |
4088 | bool temp) | |
4089 | { | |
4090 | MCDI_DECLARE_BUF(inbuf, MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_LEN); | |
4091 | int rc; | |
4092 | ||
4093 | if (channel->sync_events_state == SYNC_EVENTS_DISABLED || | |
4094 | (temp && channel->sync_events_state == SYNC_EVENTS_QUIESCENT)) | |
4095 | return 0; | |
4096 | if (channel->sync_events_state == SYNC_EVENTS_QUIESCENT) { | |
4097 | channel->sync_events_state = SYNC_EVENTS_DISABLED; | |
4098 | return 0; | |
4099 | } | |
4100 | channel->sync_events_state = temp ? SYNC_EVENTS_QUIESCENT : | |
4101 | SYNC_EVENTS_DISABLED; | |
4102 | ||
4103 | MCDI_SET_DWORD(inbuf, PTP_IN_OP, MC_CMD_PTP_OP_TIME_EVENT_UNSUBSCRIBE); | |
4104 | MCDI_SET_DWORD(inbuf, PTP_IN_PERIPH_ID, 0); | |
4105 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_CONTROL, | |
4106 | MC_CMD_PTP_IN_TIME_EVENT_UNSUBSCRIBE_SINGLE); | |
4107 | MCDI_SET_DWORD(inbuf, PTP_IN_TIME_EVENT_UNSUBSCRIBE_QUEUE, | |
4108 | channel->channel); | |
4109 | ||
4110 | rc = efx_mcdi_rpc(channel->efx, MC_CMD_PTP, | |
4111 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
4112 | ||
4113 | return rc; | |
4114 | } | |
4115 | ||
4116 | static int efx_ef10_ptp_set_ts_sync_events(struct efx_nic *efx, bool en, | |
4117 | bool temp) | |
4118 | { | |
4119 | int (*set)(struct efx_channel *channel, bool temp); | |
4120 | struct efx_channel *channel; | |
4121 | ||
4122 | set = en ? | |
4123 | efx_ef10_rx_enable_timestamping : | |
4124 | efx_ef10_rx_disable_timestamping; | |
4125 | ||
4126 | efx_for_each_channel(channel, efx) { | |
4127 | int rc = set(channel, temp); | |
4128 | if (en && rc != 0) { | |
4129 | efx_ef10_ptp_set_ts_sync_events(efx, false, temp); | |
4130 | return rc; | |
4131 | } | |
4132 | } | |
4133 | ||
4134 | return 0; | |
4135 | } | |
4136 | ||
02246a7f SS |
4137 | static int efx_ef10_ptp_set_ts_config_vf(struct efx_nic *efx, |
4138 | struct hwtstamp_config *init) | |
4139 | { | |
4140 | return -EOPNOTSUPP; | |
4141 | } | |
4142 | ||
bd9a265d JC |
4143 | static int efx_ef10_ptp_set_ts_config(struct efx_nic *efx, |
4144 | struct hwtstamp_config *init) | |
4145 | { | |
4146 | int rc; | |
4147 | ||
4148 | switch (init->rx_filter) { | |
4149 | case HWTSTAMP_FILTER_NONE: | |
4150 | efx_ef10_ptp_set_ts_sync_events(efx, false, false); | |
4151 | /* if TX timestamping is still requested then leave PTP on */ | |
4152 | return efx_ptp_change_mode(efx, | |
4153 | init->tx_type != HWTSTAMP_TX_OFF, 0); | |
4154 | case HWTSTAMP_FILTER_ALL: | |
4155 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: | |
4156 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: | |
4157 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: | |
4158 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: | |
4159 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: | |
4160 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: | |
4161 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: | |
4162 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: | |
4163 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: | |
4164 | case HWTSTAMP_FILTER_PTP_V2_EVENT: | |
4165 | case HWTSTAMP_FILTER_PTP_V2_SYNC: | |
4166 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: | |
4167 | init->rx_filter = HWTSTAMP_FILTER_ALL; | |
4168 | rc = efx_ptp_change_mode(efx, true, 0); | |
4169 | if (!rc) | |
4170 | rc = efx_ef10_ptp_set_ts_sync_events(efx, true, false); | |
4171 | if (rc) | |
4172 | efx_ptp_change_mode(efx, false, 0); | |
4173 | return rc; | |
4174 | default: | |
4175 | return -ERANGE; | |
4176 | } | |
4177 | } | |
4178 | ||
02246a7f | 4179 | const struct efx_nic_type efx_hunt_a0_vf_nic_type = { |
6f7f8aa6 | 4180 | .is_vf = true, |
02246a7f SS |
4181 | .mem_bar = EFX_MEM_VF_BAR, |
4182 | .mem_map_size = efx_ef10_mem_map_size, | |
4183 | .probe = efx_ef10_probe_vf, | |
4184 | .remove = efx_ef10_remove, | |
4185 | .dimension_resources = efx_ef10_dimension_resources, | |
4186 | .init = efx_ef10_init_nic, | |
4187 | .fini = efx_port_dummy_op_void, | |
087e9025 | 4188 | .map_reset_reason = efx_ef10_map_reset_reason, |
02246a7f SS |
4189 | .map_reset_flags = efx_ef10_map_reset_flags, |
4190 | .reset = efx_ef10_reset, | |
4191 | .probe_port = efx_mcdi_port_probe, | |
4192 | .remove_port = efx_mcdi_port_remove, | |
4193 | .fini_dmaq = efx_ef10_fini_dmaq, | |
4194 | .prepare_flr = efx_ef10_prepare_flr, | |
4195 | .finish_flr = efx_port_dummy_op_void, | |
4196 | .describe_stats = efx_ef10_describe_stats, | |
d7788196 | 4197 | .update_stats = efx_ef10_update_stats_vf, |
02246a7f SS |
4198 | .start_stats = efx_port_dummy_op_void, |
4199 | .pull_stats = efx_port_dummy_op_void, | |
4200 | .stop_stats = efx_port_dummy_op_void, | |
4201 | .set_id_led = efx_mcdi_set_id_led, | |
4202 | .push_irq_moderation = efx_ef10_push_irq_moderation, | |
862f894c | 4203 | .reconfigure_mac = efx_ef10_mac_reconfigure_vf, |
02246a7f SS |
4204 | .check_mac_fault = efx_mcdi_mac_check_fault, |
4205 | .reconfigure_port = efx_mcdi_port_reconfigure, | |
4206 | .get_wol = efx_ef10_get_wol_vf, | |
4207 | .set_wol = efx_ef10_set_wol_vf, | |
4208 | .resume_wol = efx_port_dummy_op_void, | |
4209 | .mcdi_request = efx_ef10_mcdi_request, | |
4210 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, | |
4211 | .mcdi_read_response = efx_ef10_mcdi_read_response, | |
4212 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, | |
4213 | .irq_enable_master = efx_port_dummy_op_void, | |
4214 | .irq_test_generate = efx_ef10_irq_test_generate, | |
4215 | .irq_disable_non_ev = efx_port_dummy_op_void, | |
4216 | .irq_handle_msi = efx_ef10_msi_interrupt, | |
4217 | .irq_handle_legacy = efx_ef10_legacy_interrupt, | |
4218 | .tx_probe = efx_ef10_tx_probe, | |
4219 | .tx_init = efx_ef10_tx_init, | |
4220 | .tx_remove = efx_ef10_tx_remove, | |
4221 | .tx_write = efx_ef10_tx_write, | |
267c0157 | 4222 | .rx_push_rss_config = efx_ef10_vf_rx_push_rss_config, |
02246a7f SS |
4223 | .rx_probe = efx_ef10_rx_probe, |
4224 | .rx_init = efx_ef10_rx_init, | |
4225 | .rx_remove = efx_ef10_rx_remove, | |
4226 | .rx_write = efx_ef10_rx_write, | |
4227 | .rx_defer_refill = efx_ef10_rx_defer_refill, | |
4228 | .ev_probe = efx_ef10_ev_probe, | |
4229 | .ev_init = efx_ef10_ev_init, | |
4230 | .ev_fini = efx_ef10_ev_fini, | |
4231 | .ev_remove = efx_ef10_ev_remove, | |
4232 | .ev_process = efx_ef10_ev_process, | |
4233 | .ev_read_ack = efx_ef10_ev_read_ack, | |
4234 | .ev_test_generate = efx_ef10_ev_test_generate, | |
4235 | .filter_table_probe = efx_ef10_filter_table_probe, | |
4236 | .filter_table_restore = efx_ef10_filter_table_restore, | |
4237 | .filter_table_remove = efx_ef10_filter_table_remove, | |
4238 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, | |
4239 | .filter_insert = efx_ef10_filter_insert, | |
4240 | .filter_remove_safe = efx_ef10_filter_remove_safe, | |
4241 | .filter_get_safe = efx_ef10_filter_get_safe, | |
4242 | .filter_clear_rx = efx_ef10_filter_clear_rx, | |
4243 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, | |
4244 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, | |
4245 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, | |
4246 | #ifdef CONFIG_RFS_ACCEL | |
4247 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, | |
4248 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, | |
4249 | #endif | |
4250 | #ifdef CONFIG_SFC_MTD | |
4251 | .mtd_probe = efx_port_dummy_op_int, | |
4252 | #endif | |
4253 | .ptp_write_host_time = efx_ef10_ptp_write_host_time_vf, | |
4254 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config_vf, | |
4255 | #ifdef CONFIG_SFC_SRIOV | |
7b8c7b54 SS |
4256 | .vswitching_probe = efx_ef10_vswitching_probe_vf, |
4257 | .vswitching_restore = efx_ef10_vswitching_restore_vf, | |
4258 | .vswitching_remove = efx_ef10_vswitching_remove_vf, | |
1d051e00 | 4259 | .sriov_get_phys_port_id = efx_ef10_sriov_get_phys_port_id, |
02246a7f | 4260 | #endif |
0d5e0fbb | 4261 | .get_mac_address = efx_ef10_get_mac_address_vf, |
910c8789 | 4262 | .set_mac_address = efx_ef10_set_mac_address, |
0d5e0fbb | 4263 | |
02246a7f SS |
4264 | .revision = EFX_REV_HUNT_A0, |
4265 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), | |
4266 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, | |
4267 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, | |
4268 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, | |
4269 | .can_rx_scatter = true, | |
4270 | .always_rx_scatter = true, | |
4271 | .max_interrupt_mode = EFX_INT_MODE_MSIX, | |
4272 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, | |
4273 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
4274 | NETIF_F_RXHASH | NETIF_F_NTUPLE), | |
4275 | .mcdi_max_ver = 2, | |
4276 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, | |
4277 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | | |
4278 | 1 << HWTSTAMP_FILTER_ALL, | |
4279 | }; | |
4280 | ||
8127d661 | 4281 | const struct efx_nic_type efx_hunt_a0_nic_type = { |
6f7f8aa6 | 4282 | .is_vf = false, |
02246a7f | 4283 | .mem_bar = EFX_MEM_BAR, |
8127d661 | 4284 | .mem_map_size = efx_ef10_mem_map_size, |
02246a7f | 4285 | .probe = efx_ef10_probe_pf, |
8127d661 BH |
4286 | .remove = efx_ef10_remove, |
4287 | .dimension_resources = efx_ef10_dimension_resources, | |
4288 | .init = efx_ef10_init_nic, | |
4289 | .fini = efx_port_dummy_op_void, | |
087e9025 | 4290 | .map_reset_reason = efx_ef10_map_reset_reason, |
8127d661 | 4291 | .map_reset_flags = efx_ef10_map_reset_flags, |
3e336261 | 4292 | .reset = efx_ef10_reset, |
8127d661 BH |
4293 | .probe_port = efx_mcdi_port_probe, |
4294 | .remove_port = efx_mcdi_port_remove, | |
4295 | .fini_dmaq = efx_ef10_fini_dmaq, | |
e283546c EC |
4296 | .prepare_flr = efx_ef10_prepare_flr, |
4297 | .finish_flr = efx_port_dummy_op_void, | |
8127d661 | 4298 | .describe_stats = efx_ef10_describe_stats, |
d7788196 | 4299 | .update_stats = efx_ef10_update_stats_pf, |
8127d661 | 4300 | .start_stats = efx_mcdi_mac_start_stats, |
f8f3b5ae | 4301 | .pull_stats = efx_mcdi_mac_pull_stats, |
8127d661 BH |
4302 | .stop_stats = efx_mcdi_mac_stop_stats, |
4303 | .set_id_led = efx_mcdi_set_id_led, | |
4304 | .push_irq_moderation = efx_ef10_push_irq_moderation, | |
4305 | .reconfigure_mac = efx_ef10_mac_reconfigure, | |
4306 | .check_mac_fault = efx_mcdi_mac_check_fault, | |
4307 | .reconfigure_port = efx_mcdi_port_reconfigure, | |
4308 | .get_wol = efx_ef10_get_wol, | |
4309 | .set_wol = efx_ef10_set_wol, | |
4310 | .resume_wol = efx_port_dummy_op_void, | |
74cd60a4 | 4311 | .test_chip = efx_ef10_test_chip, |
8127d661 BH |
4312 | .test_nvram = efx_mcdi_nvram_test_all, |
4313 | .mcdi_request = efx_ef10_mcdi_request, | |
4314 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, | |
4315 | .mcdi_read_response = efx_ef10_mcdi_read_response, | |
4316 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, | |
4317 | .irq_enable_master = efx_port_dummy_op_void, | |
4318 | .irq_test_generate = efx_ef10_irq_test_generate, | |
4319 | .irq_disable_non_ev = efx_port_dummy_op_void, | |
4320 | .irq_handle_msi = efx_ef10_msi_interrupt, | |
4321 | .irq_handle_legacy = efx_ef10_legacy_interrupt, | |
4322 | .tx_probe = efx_ef10_tx_probe, | |
4323 | .tx_init = efx_ef10_tx_init, | |
4324 | .tx_remove = efx_ef10_tx_remove, | |
4325 | .tx_write = efx_ef10_tx_write, | |
267c0157 | 4326 | .rx_push_rss_config = efx_ef10_pf_rx_push_rss_config, |
8127d661 BH |
4327 | .rx_probe = efx_ef10_rx_probe, |
4328 | .rx_init = efx_ef10_rx_init, | |
4329 | .rx_remove = efx_ef10_rx_remove, | |
4330 | .rx_write = efx_ef10_rx_write, | |
4331 | .rx_defer_refill = efx_ef10_rx_defer_refill, | |
4332 | .ev_probe = efx_ef10_ev_probe, | |
4333 | .ev_init = efx_ef10_ev_init, | |
4334 | .ev_fini = efx_ef10_ev_fini, | |
4335 | .ev_remove = efx_ef10_ev_remove, | |
4336 | .ev_process = efx_ef10_ev_process, | |
4337 | .ev_read_ack = efx_ef10_ev_read_ack, | |
4338 | .ev_test_generate = efx_ef10_ev_test_generate, | |
4339 | .filter_table_probe = efx_ef10_filter_table_probe, | |
4340 | .filter_table_restore = efx_ef10_filter_table_restore, | |
4341 | .filter_table_remove = efx_ef10_filter_table_remove, | |
4342 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, | |
4343 | .filter_insert = efx_ef10_filter_insert, | |
4344 | .filter_remove_safe = efx_ef10_filter_remove_safe, | |
4345 | .filter_get_safe = efx_ef10_filter_get_safe, | |
4346 | .filter_clear_rx = efx_ef10_filter_clear_rx, | |
4347 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, | |
4348 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, | |
4349 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, | |
4350 | #ifdef CONFIG_RFS_ACCEL | |
4351 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, | |
4352 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, | |
4353 | #endif | |
4354 | #ifdef CONFIG_SFC_MTD | |
4355 | .mtd_probe = efx_ef10_mtd_probe, | |
4356 | .mtd_rename = efx_mcdi_mtd_rename, | |
4357 | .mtd_read = efx_mcdi_mtd_read, | |
4358 | .mtd_erase = efx_mcdi_mtd_erase, | |
4359 | .mtd_write = efx_mcdi_mtd_write, | |
4360 | .mtd_sync = efx_mcdi_mtd_sync, | |
4361 | #endif | |
4362 | .ptp_write_host_time = efx_ef10_ptp_write_host_time, | |
bd9a265d JC |
4363 | .ptp_set_ts_sync_events = efx_ef10_ptp_set_ts_sync_events, |
4364 | .ptp_set_ts_config = efx_ef10_ptp_set_ts_config, | |
7fa8d547 | 4365 | #ifdef CONFIG_SFC_SRIOV |
834e23dd | 4366 | .sriov_configure = efx_ef10_sriov_configure, |
d98a4ffe SS |
4367 | .sriov_init = efx_ef10_sriov_init, |
4368 | .sriov_fini = efx_ef10_sriov_fini, | |
d98a4ffe SS |
4369 | .sriov_wanted = efx_ef10_sriov_wanted, |
4370 | .sriov_reset = efx_ef10_sriov_reset, | |
7fa8d547 SS |
4371 | .sriov_flr = efx_ef10_sriov_flr, |
4372 | .sriov_set_vf_mac = efx_ef10_sriov_set_vf_mac, | |
4373 | .sriov_set_vf_vlan = efx_ef10_sriov_set_vf_vlan, | |
4374 | .sriov_set_vf_spoofchk = efx_ef10_sriov_set_vf_spoofchk, | |
4375 | .sriov_get_vf_config = efx_ef10_sriov_get_vf_config, | |
4392dc69 | 4376 | .sriov_set_vf_link_state = efx_ef10_sriov_set_vf_link_state, |
7b8c7b54 SS |
4377 | .vswitching_probe = efx_ef10_vswitching_probe_pf, |
4378 | .vswitching_restore = efx_ef10_vswitching_restore_pf, | |
4379 | .vswitching_remove = efx_ef10_vswitching_remove_pf, | |
7fa8d547 | 4380 | #endif |
0d5e0fbb | 4381 | .get_mac_address = efx_ef10_get_mac_address_pf, |
910c8789 | 4382 | .set_mac_address = efx_ef10_set_mac_address, |
8127d661 BH |
4383 | |
4384 | .revision = EFX_REV_HUNT_A0, | |
4385 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), | |
4386 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, | |
4387 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, | |
bd9a265d | 4388 | .rx_ts_offset = ES_DZ_RX_PREFIX_TSTAMP_OFST, |
8127d661 BH |
4389 | .can_rx_scatter = true, |
4390 | .always_rx_scatter = true, | |
4391 | .max_interrupt_mode = EFX_INT_MODE_MSIX, | |
4392 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, | |
4393 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
4394 | NETIF_F_RXHASH | NETIF_F_NTUPLE), | |
4395 | .mcdi_max_ver = 2, | |
4396 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, | |
bd9a265d JC |
4397 | .hwtstamp_filters = 1 << HWTSTAMP_FILTER_NONE | |
4398 | 1 << HWTSTAMP_FILTER_ALL, | |
8127d661 | 4399 | }; |