]>
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" | |
17 | #include <linux/in.h> | |
18 | #include <linux/jhash.h> | |
19 | #include <linux/wait.h> | |
20 | #include <linux/workqueue.h> | |
21 | ||
22 | /* Hardware control for EF10 architecture including 'Huntington'. */ | |
23 | ||
24 | #define EFX_EF10_DRVGEN_EV 7 | |
25 | enum { | |
26 | EFX_EF10_TEST = 1, | |
27 | EFX_EF10_REFILL, | |
28 | }; | |
29 | ||
30 | /* The reserved RSS context value */ | |
31 | #define EFX_EF10_RSS_CONTEXT_INVALID 0xffffffff | |
32 | ||
33 | /* The filter table(s) are managed by firmware and we have write-only | |
34 | * access. When removing filters we must identify them to the | |
35 | * firmware by a 64-bit handle, but this is too wide for Linux kernel | |
36 | * interfaces (32-bit for RX NFC, 16-bit for RFS). Also, we need to | |
37 | * be able to tell in advance whether a requested insertion will | |
38 | * replace an existing filter. Therefore we maintain a software hash | |
39 | * table, which should be at least as large as the hardware hash | |
40 | * table. | |
41 | * | |
42 | * Huntington has a single 8K filter table shared between all filter | |
43 | * types and both ports. | |
44 | */ | |
45 | #define HUNT_FILTER_TBL_ROWS 8192 | |
46 | ||
47 | struct efx_ef10_filter_table { | |
48 | /* The RX match field masks supported by this fw & hw, in order of priority */ | |
49 | enum efx_filter_match_flags rx_match_flags[ | |
50 | MC_CMD_GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES_MAXNUM]; | |
51 | unsigned int rx_match_count; | |
52 | ||
53 | struct { | |
54 | unsigned long spec; /* pointer to spec plus flag bits */ | |
55 | /* BUSY flag indicates that an update is in progress. STACK_OLD is | |
56 | * used to mark and sweep stack-owned MAC filters. | |
57 | */ | |
58 | #define EFX_EF10_FILTER_FLAG_BUSY 1UL | |
59 | #define EFX_EF10_FILTER_FLAG_STACK_OLD 2UL | |
60 | #define EFX_EF10_FILTER_FLAGS 3UL | |
61 | u64 handle; /* firmware handle */ | |
62 | } *entry; | |
63 | wait_queue_head_t waitq; | |
64 | /* Shadow of net_device address lists, guarded by mac_lock */ | |
65 | #define EFX_EF10_FILTER_STACK_UC_MAX 32 | |
66 | #define EFX_EF10_FILTER_STACK_MC_MAX 256 | |
67 | struct { | |
68 | u8 addr[ETH_ALEN]; | |
69 | u16 id; | |
70 | } stack_uc_list[EFX_EF10_FILTER_STACK_UC_MAX], | |
71 | stack_mc_list[EFX_EF10_FILTER_STACK_MC_MAX]; | |
72 | int stack_uc_count; /* negative for PROMISC */ | |
73 | int stack_mc_count; /* negative for PROMISC/ALLMULTI */ | |
74 | }; | |
75 | ||
76 | /* An arbitrary search limit for the software hash table */ | |
77 | #define EFX_EF10_FILTER_SEARCH_LIMIT 200 | |
78 | ||
79 | static void efx_ef10_rx_push_indir_table(struct efx_nic *efx); | |
80 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx); | |
81 | static void efx_ef10_filter_table_remove(struct efx_nic *efx); | |
82 | ||
83 | static int efx_ef10_get_warm_boot_count(struct efx_nic *efx) | |
84 | { | |
85 | efx_dword_t reg; | |
86 | ||
87 | efx_readd(efx, ®, ER_DZ_BIU_MC_SFT_STATUS); | |
88 | return EFX_DWORD_FIELD(reg, EFX_WORD_1) == 0xb007 ? | |
89 | EFX_DWORD_FIELD(reg, EFX_WORD_0) : -EIO; | |
90 | } | |
91 | ||
92 | static unsigned int efx_ef10_mem_map_size(struct efx_nic *efx) | |
93 | { | |
94 | return resource_size(&efx->pci_dev->resource[EFX_MEM_BAR]); | |
95 | } | |
96 | ||
97 | static int efx_ef10_init_capabilities(struct efx_nic *efx) | |
98 | { | |
99 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CAPABILITIES_OUT_LEN); | |
100 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
101 | size_t outlen; | |
102 | int rc; | |
103 | ||
104 | BUILD_BUG_ON(MC_CMD_GET_CAPABILITIES_IN_LEN != 0); | |
105 | ||
106 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CAPABILITIES, NULL, 0, | |
107 | outbuf, sizeof(outbuf), &outlen); | |
108 | if (rc) | |
109 | return rc; | |
110 | ||
111 | if (outlen >= sizeof(outbuf)) { | |
112 | nic_data->datapath_caps = | |
113 | MCDI_DWORD(outbuf, GET_CAPABILITIES_OUT_FLAGS1); | |
114 | if (!(nic_data->datapath_caps & | |
115 | (1 << MC_CMD_GET_CAPABILITIES_OUT_TX_TSO_LBN))) { | |
116 | netif_err(efx, drv, efx->net_dev, | |
117 | "Capabilities don't indicate TSO support.\n"); | |
118 | return -ENODEV; | |
119 | } | |
120 | } | |
121 | ||
122 | return 0; | |
123 | } | |
124 | ||
125 | static int efx_ef10_get_sysclk_freq(struct efx_nic *efx) | |
126 | { | |
127 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_CLOCK_OUT_LEN); | |
128 | int rc; | |
129 | ||
130 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_CLOCK, NULL, 0, | |
131 | outbuf, sizeof(outbuf), NULL); | |
132 | if (rc) | |
133 | return rc; | |
134 | rc = MCDI_DWORD(outbuf, GET_CLOCK_OUT_SYS_FREQ); | |
135 | return rc > 0 ? rc : -ERANGE; | |
136 | } | |
137 | ||
138 | static int efx_ef10_get_mac_address(struct efx_nic *efx, u8 *mac_address) | |
139 | { | |
140 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_MAC_ADDRESSES_OUT_LEN); | |
141 | size_t outlen; | |
142 | int rc; | |
143 | ||
144 | BUILD_BUG_ON(MC_CMD_GET_MAC_ADDRESSES_IN_LEN != 0); | |
145 | ||
146 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_MAC_ADDRESSES, NULL, 0, | |
147 | outbuf, sizeof(outbuf), &outlen); | |
148 | if (rc) | |
149 | return rc; | |
150 | if (outlen < MC_CMD_GET_MAC_ADDRESSES_OUT_LEN) | |
151 | return -EIO; | |
152 | ||
153 | memcpy(mac_address, | |
154 | MCDI_PTR(outbuf, GET_MAC_ADDRESSES_OUT_MAC_ADDR_BASE), ETH_ALEN); | |
155 | return 0; | |
156 | } | |
157 | ||
158 | static int efx_ef10_probe(struct efx_nic *efx) | |
159 | { | |
160 | struct efx_ef10_nic_data *nic_data; | |
161 | int i, rc; | |
162 | ||
163 | /* We can have one VI for each 8K region. However we need | |
164 | * multiple TX queues per channel. | |
165 | */ | |
166 | efx->max_channels = | |
167 | min_t(unsigned int, | |
168 | EFX_MAX_CHANNELS, | |
169 | resource_size(&efx->pci_dev->resource[EFX_MEM_BAR]) / | |
170 | (EFX_VI_PAGE_SIZE * EFX_TXQ_TYPES)); | |
171 | BUG_ON(efx->max_channels == 0); | |
172 | ||
173 | nic_data = kzalloc(sizeof(*nic_data), GFP_KERNEL); | |
174 | if (!nic_data) | |
175 | return -ENOMEM; | |
176 | efx->nic_data = nic_data; | |
177 | ||
178 | rc = efx_nic_alloc_buffer(efx, &nic_data->mcdi_buf, | |
179 | 8 + MCDI_CTL_SDU_LEN_MAX_V2, GFP_KERNEL); | |
180 | if (rc) | |
181 | goto fail1; | |
182 | ||
183 | /* Get the MC's warm boot count. In case it's rebooting right | |
184 | * now, be prepared to retry. | |
185 | */ | |
186 | i = 0; | |
187 | for (;;) { | |
188 | rc = efx_ef10_get_warm_boot_count(efx); | |
189 | if (rc >= 0) | |
190 | break; | |
191 | if (++i == 5) | |
192 | goto fail2; | |
193 | ssleep(1); | |
194 | } | |
195 | nic_data->warm_boot_count = rc; | |
196 | ||
197 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
198 | ||
199 | /* In case we're recovering from a crash (kexec), we want to | |
200 | * cancel any outstanding request by the previous user of this | |
201 | * function. We send a special message using the least | |
202 | * significant bits of the 'high' (doorbell) register. | |
203 | */ | |
204 | _efx_writed(efx, cpu_to_le32(1), ER_DZ_MC_DB_HWRD); | |
205 | ||
206 | rc = efx_mcdi_init(efx); | |
207 | if (rc) | |
208 | goto fail2; | |
209 | ||
210 | /* Reset (most) configuration for this function */ | |
211 | rc = efx_mcdi_reset(efx, RESET_TYPE_ALL); | |
212 | if (rc) | |
213 | goto fail3; | |
214 | ||
215 | /* Enable event logging */ | |
216 | rc = efx_mcdi_log_ctrl(efx, true, false, 0); | |
217 | if (rc) | |
218 | goto fail3; | |
219 | ||
220 | rc = efx_ef10_init_capabilities(efx); | |
221 | if (rc < 0) | |
222 | goto fail3; | |
223 | ||
224 | efx->rx_packet_len_offset = | |
225 | ES_DZ_RX_PREFIX_PKTLEN_OFST - ES_DZ_RX_PREFIX_SIZE; | |
226 | ||
227 | if (!(nic_data->datapath_caps & | |
228 | (1 << MC_CMD_GET_CAPABILITIES_OUT_RX_PREFIX_LEN_14_LBN))) { | |
229 | netif_err(efx, probe, efx->net_dev, | |
230 | "current firmware does not support an RX prefix\n"); | |
231 | rc = -ENODEV; | |
232 | goto fail3; | |
233 | } | |
234 | ||
235 | rc = efx_mcdi_port_get_number(efx); | |
236 | if (rc < 0) | |
237 | goto fail3; | |
238 | efx->port_num = rc; | |
239 | ||
240 | rc = efx_ef10_get_mac_address(efx, efx->net_dev->perm_addr); | |
241 | if (rc) | |
242 | goto fail3; | |
243 | ||
244 | rc = efx_ef10_get_sysclk_freq(efx); | |
245 | if (rc < 0) | |
246 | goto fail3; | |
247 | efx->timer_quantum_ns = 1536000 / rc; /* 1536 cycles */ | |
248 | ||
249 | /* Check whether firmware supports bug 35388 workaround */ | |
250 | rc = efx_mcdi_set_workaround(efx, MC_CMD_WORKAROUND_BUG35388, true); | |
251 | if (rc == 0) | |
252 | nic_data->workaround_35388 = true; | |
253 | else if (rc != -ENOSYS && rc != -ENOENT) | |
254 | goto fail3; | |
255 | netif_dbg(efx, probe, efx->net_dev, | |
256 | "workaround for bug 35388 is %sabled\n", | |
257 | nic_data->workaround_35388 ? "en" : "dis"); | |
258 | ||
259 | rc = efx_mcdi_mon_probe(efx); | |
260 | if (rc) | |
261 | goto fail3; | |
262 | ||
8127d661 BH |
263 | return 0; |
264 | ||
265 | fail3: | |
266 | efx_mcdi_fini(efx); | |
267 | fail2: | |
268 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); | |
269 | fail1: | |
270 | kfree(nic_data); | |
271 | efx->nic_data = NULL; | |
272 | return rc; | |
273 | } | |
274 | ||
275 | static int efx_ef10_free_vis(struct efx_nic *efx) | |
276 | { | |
277 | int rc = efx_mcdi_rpc(efx, MC_CMD_FREE_VIS, NULL, 0, NULL, 0, NULL); | |
278 | ||
279 | /* -EALREADY means nothing to free, so ignore */ | |
280 | if (rc == -EALREADY) | |
281 | rc = 0; | |
282 | return rc; | |
283 | } | |
284 | ||
285 | static void efx_ef10_remove(struct efx_nic *efx) | |
286 | { | |
287 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
288 | int rc; | |
289 | ||
290 | efx_mcdi_mon_remove(efx); | |
291 | ||
292 | /* This needs to be after efx_ptp_remove_channel() with no filters */ | |
293 | efx_ef10_rx_free_indir_table(efx); | |
294 | ||
295 | rc = efx_ef10_free_vis(efx); | |
296 | WARN_ON(rc != 0); | |
297 | ||
298 | efx_mcdi_fini(efx); | |
299 | efx_nic_free_buffer(efx, &nic_data->mcdi_buf); | |
300 | kfree(nic_data); | |
301 | } | |
302 | ||
303 | static int efx_ef10_alloc_vis(struct efx_nic *efx, | |
304 | unsigned int min_vis, unsigned int max_vis) | |
305 | { | |
306 | MCDI_DECLARE_BUF(inbuf, MC_CMD_ALLOC_VIS_IN_LEN); | |
307 | MCDI_DECLARE_BUF(outbuf, MC_CMD_ALLOC_VIS_OUT_LEN); | |
308 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
309 | size_t outlen; | |
310 | int rc; | |
311 | ||
312 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MIN_VI_COUNT, min_vis); | |
313 | MCDI_SET_DWORD(inbuf, ALLOC_VIS_IN_MAX_VI_COUNT, max_vis); | |
314 | rc = efx_mcdi_rpc(efx, MC_CMD_ALLOC_VIS, inbuf, sizeof(inbuf), | |
315 | outbuf, sizeof(outbuf), &outlen); | |
316 | if (rc != 0) | |
317 | return rc; | |
318 | ||
319 | if (outlen < MC_CMD_ALLOC_VIS_OUT_LEN) | |
320 | return -EIO; | |
321 | ||
322 | netif_dbg(efx, drv, efx->net_dev, "base VI is A0x%03x\n", | |
323 | MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE)); | |
324 | ||
325 | nic_data->vi_base = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_BASE); | |
326 | nic_data->n_allocated_vis = MCDI_DWORD(outbuf, ALLOC_VIS_OUT_VI_COUNT); | |
327 | return 0; | |
328 | } | |
329 | ||
330 | static int efx_ef10_dimension_resources(struct efx_nic *efx) | |
331 | { | |
332 | unsigned int n_vis = | |
333 | max(efx->n_channels, efx->n_tx_channels * EFX_TXQ_TYPES); | |
334 | ||
335 | return efx_ef10_alloc_vis(efx, n_vis, n_vis); | |
336 | } | |
337 | ||
338 | static int efx_ef10_init_nic(struct efx_nic *efx) | |
339 | { | |
340 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
341 | int rc; | |
342 | ||
343 | if (nic_data->must_realloc_vis) { | |
344 | /* We cannot let the number of VIs change now */ | |
345 | rc = efx_ef10_alloc_vis(efx, nic_data->n_allocated_vis, | |
346 | nic_data->n_allocated_vis); | |
347 | if (rc) | |
348 | return rc; | |
349 | nic_data->must_realloc_vis = false; | |
350 | } | |
351 | ||
352 | efx_ef10_rx_push_indir_table(efx); | |
353 | return 0; | |
354 | } | |
355 | ||
356 | static int efx_ef10_map_reset_flags(u32 *flags) | |
357 | { | |
358 | enum { | |
359 | EF10_RESET_PORT = ((ETH_RESET_MAC | ETH_RESET_PHY) << | |
360 | ETH_RESET_SHARED_SHIFT), | |
361 | EF10_RESET_MC = ((ETH_RESET_DMA | ETH_RESET_FILTER | | |
362 | ETH_RESET_OFFLOAD | ETH_RESET_MAC | | |
363 | ETH_RESET_PHY | ETH_RESET_MGMT) << | |
364 | ETH_RESET_SHARED_SHIFT) | |
365 | }; | |
366 | ||
367 | /* We assume for now that our PCI function is permitted to | |
368 | * reset everything. | |
369 | */ | |
370 | ||
371 | if ((*flags & EF10_RESET_MC) == EF10_RESET_MC) { | |
372 | *flags &= ~EF10_RESET_MC; | |
373 | return RESET_TYPE_WORLD; | |
374 | } | |
375 | ||
376 | if ((*flags & EF10_RESET_PORT) == EF10_RESET_PORT) { | |
377 | *flags &= ~EF10_RESET_PORT; | |
378 | return RESET_TYPE_ALL; | |
379 | } | |
380 | ||
381 | /* no invisible reset implemented */ | |
382 | ||
383 | return -EINVAL; | |
384 | } | |
385 | ||
386 | #define EF10_DMA_STAT(ext_name, mcdi_name) \ | |
387 | [EF10_STAT_ ## ext_name] = \ | |
388 | { #ext_name, 64, 8 * MC_CMD_MAC_ ## mcdi_name } | |
389 | #define EF10_DMA_INVIS_STAT(int_name, mcdi_name) \ | |
390 | [EF10_STAT_ ## int_name] = \ | |
391 | { NULL, 64, 8 * MC_CMD_MAC_ ## mcdi_name } | |
392 | #define EF10_OTHER_STAT(ext_name) \ | |
393 | [EF10_STAT_ ## ext_name] = { #ext_name, 0, 0 } | |
394 | ||
395 | static const struct efx_hw_stat_desc efx_ef10_stat_desc[EF10_STAT_COUNT] = { | |
396 | EF10_DMA_STAT(tx_bytes, TX_BYTES), | |
397 | EF10_DMA_STAT(tx_packets, TX_PKTS), | |
398 | EF10_DMA_STAT(tx_pause, TX_PAUSE_PKTS), | |
399 | EF10_DMA_STAT(tx_control, TX_CONTROL_PKTS), | |
400 | EF10_DMA_STAT(tx_unicast, TX_UNICAST_PKTS), | |
401 | EF10_DMA_STAT(tx_multicast, TX_MULTICAST_PKTS), | |
402 | EF10_DMA_STAT(tx_broadcast, TX_BROADCAST_PKTS), | |
403 | EF10_DMA_STAT(tx_lt64, TX_LT64_PKTS), | |
404 | EF10_DMA_STAT(tx_64, TX_64_PKTS), | |
405 | EF10_DMA_STAT(tx_65_to_127, TX_65_TO_127_PKTS), | |
406 | EF10_DMA_STAT(tx_128_to_255, TX_128_TO_255_PKTS), | |
407 | EF10_DMA_STAT(tx_256_to_511, TX_256_TO_511_PKTS), | |
408 | EF10_DMA_STAT(tx_512_to_1023, TX_512_TO_1023_PKTS), | |
409 | EF10_DMA_STAT(tx_1024_to_15xx, TX_1024_TO_15XX_PKTS), | |
410 | EF10_DMA_STAT(tx_15xx_to_jumbo, TX_15XX_TO_JUMBO_PKTS), | |
411 | EF10_DMA_STAT(rx_bytes, RX_BYTES), | |
412 | EF10_DMA_INVIS_STAT(rx_bytes_minus_good_bytes, RX_BAD_BYTES), | |
413 | EF10_OTHER_STAT(rx_good_bytes), | |
414 | EF10_OTHER_STAT(rx_bad_bytes), | |
415 | EF10_DMA_STAT(rx_packets, RX_PKTS), | |
416 | EF10_DMA_STAT(rx_good, RX_GOOD_PKTS), | |
417 | EF10_DMA_STAT(rx_bad, RX_BAD_FCS_PKTS), | |
418 | EF10_DMA_STAT(rx_pause, RX_PAUSE_PKTS), | |
419 | EF10_DMA_STAT(rx_control, RX_CONTROL_PKTS), | |
420 | EF10_DMA_STAT(rx_unicast, RX_UNICAST_PKTS), | |
421 | EF10_DMA_STAT(rx_multicast, RX_MULTICAST_PKTS), | |
422 | EF10_DMA_STAT(rx_broadcast, RX_BROADCAST_PKTS), | |
423 | EF10_DMA_STAT(rx_lt64, RX_UNDERSIZE_PKTS), | |
424 | EF10_DMA_STAT(rx_64, RX_64_PKTS), | |
425 | EF10_DMA_STAT(rx_65_to_127, RX_65_TO_127_PKTS), | |
426 | EF10_DMA_STAT(rx_128_to_255, RX_128_TO_255_PKTS), | |
427 | EF10_DMA_STAT(rx_256_to_511, RX_256_TO_511_PKTS), | |
428 | EF10_DMA_STAT(rx_512_to_1023, RX_512_TO_1023_PKTS), | |
429 | EF10_DMA_STAT(rx_1024_to_15xx, RX_1024_TO_15XX_PKTS), | |
430 | EF10_DMA_STAT(rx_15xx_to_jumbo, RX_15XX_TO_JUMBO_PKTS), | |
431 | EF10_DMA_STAT(rx_gtjumbo, RX_GTJUMBO_PKTS), | |
432 | EF10_DMA_STAT(rx_bad_gtjumbo, RX_JABBER_PKTS), | |
433 | EF10_DMA_STAT(rx_overflow, RX_OVERFLOW_PKTS), | |
434 | EF10_DMA_STAT(rx_align_error, RX_ALIGN_ERROR_PKTS), | |
435 | EF10_DMA_STAT(rx_length_error, RX_LENGTH_ERROR_PKTS), | |
436 | EF10_DMA_STAT(rx_nodesc_drops, RX_NODESC_DROPS), | |
437 | }; | |
438 | ||
439 | #define HUNT_COMMON_STAT_MASK ((1ULL << EF10_STAT_tx_bytes) | \ | |
440 | (1ULL << EF10_STAT_tx_packets) | \ | |
441 | (1ULL << EF10_STAT_tx_pause) | \ | |
442 | (1ULL << EF10_STAT_tx_unicast) | \ | |
443 | (1ULL << EF10_STAT_tx_multicast) | \ | |
444 | (1ULL << EF10_STAT_tx_broadcast) | \ | |
445 | (1ULL << EF10_STAT_rx_bytes) | \ | |
446 | (1ULL << EF10_STAT_rx_bytes_minus_good_bytes) | \ | |
447 | (1ULL << EF10_STAT_rx_good_bytes) | \ | |
448 | (1ULL << EF10_STAT_rx_bad_bytes) | \ | |
449 | (1ULL << EF10_STAT_rx_packets) | \ | |
450 | (1ULL << EF10_STAT_rx_good) | \ | |
451 | (1ULL << EF10_STAT_rx_bad) | \ | |
452 | (1ULL << EF10_STAT_rx_pause) | \ | |
453 | (1ULL << EF10_STAT_rx_control) | \ | |
454 | (1ULL << EF10_STAT_rx_unicast) | \ | |
455 | (1ULL << EF10_STAT_rx_multicast) | \ | |
456 | (1ULL << EF10_STAT_rx_broadcast) | \ | |
457 | (1ULL << EF10_STAT_rx_lt64) | \ | |
458 | (1ULL << EF10_STAT_rx_64) | \ | |
459 | (1ULL << EF10_STAT_rx_65_to_127) | \ | |
460 | (1ULL << EF10_STAT_rx_128_to_255) | \ | |
461 | (1ULL << EF10_STAT_rx_256_to_511) | \ | |
462 | (1ULL << EF10_STAT_rx_512_to_1023) | \ | |
463 | (1ULL << EF10_STAT_rx_1024_to_15xx) | \ | |
464 | (1ULL << EF10_STAT_rx_15xx_to_jumbo) | \ | |
465 | (1ULL << EF10_STAT_rx_gtjumbo) | \ | |
466 | (1ULL << EF10_STAT_rx_bad_gtjumbo) | \ | |
467 | (1ULL << EF10_STAT_rx_overflow) | \ | |
468 | (1ULL << EF10_STAT_rx_nodesc_drops)) | |
469 | ||
470 | /* These statistics are only provided by the 10G MAC. For a 10G/40G | |
471 | * switchable port we do not expose these because they might not | |
472 | * include all the packets they should. | |
473 | */ | |
474 | #define HUNT_10G_ONLY_STAT_MASK ((1ULL << EF10_STAT_tx_control) | \ | |
475 | (1ULL << EF10_STAT_tx_lt64) | \ | |
476 | (1ULL << EF10_STAT_tx_64) | \ | |
477 | (1ULL << EF10_STAT_tx_65_to_127) | \ | |
478 | (1ULL << EF10_STAT_tx_128_to_255) | \ | |
479 | (1ULL << EF10_STAT_tx_256_to_511) | \ | |
480 | (1ULL << EF10_STAT_tx_512_to_1023) | \ | |
481 | (1ULL << EF10_STAT_tx_1024_to_15xx) | \ | |
482 | (1ULL << EF10_STAT_tx_15xx_to_jumbo)) | |
483 | ||
484 | /* These statistics are only provided by the 40G MAC. For a 10G/40G | |
485 | * switchable port we do expose these because the errors will otherwise | |
486 | * be silent. | |
487 | */ | |
488 | #define HUNT_40G_EXTRA_STAT_MASK ((1ULL << EF10_STAT_rx_align_error) | \ | |
489 | (1ULL << EF10_STAT_rx_length_error)) | |
490 | ||
491 | #if BITS_PER_LONG == 64 | |
492 | #define STAT_MASK_BITMAP(bits) (bits) | |
493 | #else | |
494 | #define STAT_MASK_BITMAP(bits) (bits) & 0xffffffff, (bits) >> 32 | |
495 | #endif | |
496 | ||
497 | static const unsigned long *efx_ef10_stat_mask(struct efx_nic *efx) | |
498 | { | |
499 | static const unsigned long hunt_40g_stat_mask[] = { | |
500 | STAT_MASK_BITMAP(HUNT_COMMON_STAT_MASK | | |
501 | HUNT_40G_EXTRA_STAT_MASK) | |
502 | }; | |
503 | static const unsigned long hunt_10g_only_stat_mask[] = { | |
504 | STAT_MASK_BITMAP(HUNT_COMMON_STAT_MASK | | |
505 | HUNT_10G_ONLY_STAT_MASK) | |
506 | }; | |
507 | u32 port_caps = efx_mcdi_phy_get_caps(efx); | |
508 | ||
509 | if (port_caps & (1 << MC_CMD_PHY_CAP_40000FDX_LBN)) | |
510 | return hunt_40g_stat_mask; | |
511 | else | |
512 | return hunt_10g_only_stat_mask; | |
513 | } | |
514 | ||
515 | static size_t efx_ef10_describe_stats(struct efx_nic *efx, u8 *names) | |
516 | { | |
517 | return efx_nic_describe_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, | |
518 | efx_ef10_stat_mask(efx), names); | |
519 | } | |
520 | ||
521 | static int efx_ef10_try_update_nic_stats(struct efx_nic *efx) | |
522 | { | |
523 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
524 | const unsigned long *stats_mask = efx_ef10_stat_mask(efx); | |
525 | __le64 generation_start, generation_end; | |
526 | u64 *stats = nic_data->stats; | |
527 | __le64 *dma_stats; | |
528 | ||
529 | dma_stats = efx->stats_buffer.addr; | |
530 | nic_data = efx->nic_data; | |
531 | ||
532 | generation_end = dma_stats[MC_CMD_MAC_GENERATION_END]; | |
533 | if (generation_end == EFX_MC_STATS_GENERATION_INVALID) | |
534 | return 0; | |
535 | rmb(); | |
536 | efx_nic_update_stats(efx_ef10_stat_desc, EF10_STAT_COUNT, stats_mask, | |
537 | stats, efx->stats_buffer.addr, false); | |
538 | generation_start = dma_stats[MC_CMD_MAC_GENERATION_START]; | |
539 | if (generation_end != generation_start) | |
540 | return -EAGAIN; | |
541 | ||
542 | /* Update derived statistics */ | |
543 | stats[EF10_STAT_rx_good_bytes] = | |
544 | stats[EF10_STAT_rx_bytes] - | |
545 | stats[EF10_STAT_rx_bytes_minus_good_bytes]; | |
546 | efx_update_diff_stat(&stats[EF10_STAT_rx_bad_bytes], | |
547 | stats[EF10_STAT_rx_bytes_minus_good_bytes]); | |
548 | ||
549 | return 0; | |
550 | } | |
551 | ||
552 | ||
553 | static size_t efx_ef10_update_stats(struct efx_nic *efx, u64 *full_stats, | |
554 | struct rtnl_link_stats64 *core_stats) | |
555 | { | |
556 | const unsigned long *mask = efx_ef10_stat_mask(efx); | |
557 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
558 | u64 *stats = nic_data->stats; | |
559 | size_t stats_count = 0, index; | |
560 | int retry; | |
561 | ||
562 | /* If we're unlucky enough to read statistics during the DMA, wait | |
563 | * up to 10ms for it to finish (typically takes <500us) | |
564 | */ | |
565 | for (retry = 0; retry < 100; ++retry) { | |
566 | if (efx_ef10_try_update_nic_stats(efx) == 0) | |
567 | break; | |
568 | udelay(100); | |
569 | } | |
570 | ||
571 | if (full_stats) { | |
572 | for_each_set_bit(index, mask, EF10_STAT_COUNT) { | |
573 | if (efx_ef10_stat_desc[index].name) { | |
574 | *full_stats++ = stats[index]; | |
575 | ++stats_count; | |
576 | } | |
577 | } | |
578 | } | |
579 | ||
580 | if (core_stats) { | |
581 | core_stats->rx_packets = stats[EF10_STAT_rx_packets]; | |
582 | core_stats->tx_packets = stats[EF10_STAT_tx_packets]; | |
583 | core_stats->rx_bytes = stats[EF10_STAT_rx_bytes]; | |
584 | core_stats->tx_bytes = stats[EF10_STAT_tx_bytes]; | |
585 | core_stats->rx_dropped = stats[EF10_STAT_rx_nodesc_drops]; | |
586 | core_stats->multicast = stats[EF10_STAT_rx_multicast]; | |
587 | core_stats->rx_length_errors = | |
588 | stats[EF10_STAT_rx_gtjumbo] + | |
589 | stats[EF10_STAT_rx_length_error]; | |
590 | core_stats->rx_crc_errors = stats[EF10_STAT_rx_bad]; | |
591 | core_stats->rx_frame_errors = stats[EF10_STAT_rx_align_error]; | |
592 | core_stats->rx_fifo_errors = stats[EF10_STAT_rx_overflow]; | |
593 | core_stats->rx_errors = (core_stats->rx_length_errors + | |
594 | core_stats->rx_crc_errors + | |
595 | core_stats->rx_frame_errors); | |
596 | } | |
597 | ||
598 | return stats_count; | |
599 | } | |
600 | ||
601 | static void efx_ef10_push_irq_moderation(struct efx_channel *channel) | |
602 | { | |
603 | struct efx_nic *efx = channel->efx; | |
604 | unsigned int mode, value; | |
605 | efx_dword_t timer_cmd; | |
606 | ||
607 | if (channel->irq_moderation) { | |
608 | mode = 3; | |
609 | value = channel->irq_moderation - 1; | |
610 | } else { | |
611 | mode = 0; | |
612 | value = 0; | |
613 | } | |
614 | ||
615 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
616 | EFX_POPULATE_DWORD_3(timer_cmd, ERF_DD_EVQ_IND_TIMER_FLAGS, | |
617 | EFE_DD_EVQ_IND_TIMER_FLAGS, | |
618 | ERF_DD_EVQ_IND_TIMER_MODE, mode, | |
619 | ERF_DD_EVQ_IND_TIMER_VAL, value); | |
620 | efx_writed_page(efx, &timer_cmd, ER_DD_EVQ_INDIRECT, | |
621 | channel->channel); | |
622 | } else { | |
623 | EFX_POPULATE_DWORD_2(timer_cmd, ERF_DZ_TC_TIMER_MODE, mode, | |
624 | ERF_DZ_TC_TIMER_VAL, value); | |
625 | efx_writed_page(efx, &timer_cmd, ER_DZ_EVQ_TMR, | |
626 | channel->channel); | |
627 | } | |
628 | } | |
629 | ||
630 | static void efx_ef10_get_wol(struct efx_nic *efx, struct ethtool_wolinfo *wol) | |
631 | { | |
632 | wol->supported = 0; | |
633 | wol->wolopts = 0; | |
634 | memset(&wol->sopass, 0, sizeof(wol->sopass)); | |
635 | } | |
636 | ||
637 | static int efx_ef10_set_wol(struct efx_nic *efx, u32 type) | |
638 | { | |
639 | if (type != 0) | |
640 | return -EINVAL; | |
641 | return 0; | |
642 | } | |
643 | ||
644 | static void efx_ef10_mcdi_request(struct efx_nic *efx, | |
645 | const efx_dword_t *hdr, size_t hdr_len, | |
646 | const efx_dword_t *sdu, size_t sdu_len) | |
647 | { | |
648 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
649 | u8 *pdu = nic_data->mcdi_buf.addr; | |
650 | ||
651 | memcpy(pdu, hdr, hdr_len); | |
652 | memcpy(pdu + hdr_len, sdu, sdu_len); | |
653 | wmb(); | |
654 | ||
655 | /* The hardware provides 'low' and 'high' (doorbell) registers | |
656 | * for passing the 64-bit address of an MCDI request to | |
657 | * firmware. However the dwords are swapped by firmware. The | |
658 | * least significant bits of the doorbell are then 0 for all | |
659 | * MCDI requests due to alignment. | |
660 | */ | |
661 | _efx_writed(efx, cpu_to_le32((u64)nic_data->mcdi_buf.dma_addr >> 32), | |
662 | ER_DZ_MC_DB_LWRD); | |
663 | _efx_writed(efx, cpu_to_le32((u32)nic_data->mcdi_buf.dma_addr), | |
664 | ER_DZ_MC_DB_HWRD); | |
665 | } | |
666 | ||
667 | static bool efx_ef10_mcdi_poll_response(struct efx_nic *efx) | |
668 | { | |
669 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
670 | const efx_dword_t hdr = *(const efx_dword_t *)nic_data->mcdi_buf.addr; | |
671 | ||
672 | rmb(); | |
673 | return EFX_DWORD_FIELD(hdr, MCDI_HEADER_RESPONSE); | |
674 | } | |
675 | ||
676 | static void | |
677 | efx_ef10_mcdi_read_response(struct efx_nic *efx, efx_dword_t *outbuf, | |
678 | size_t offset, size_t outlen) | |
679 | { | |
680 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
681 | const u8 *pdu = nic_data->mcdi_buf.addr; | |
682 | ||
683 | memcpy(outbuf, pdu + offset, outlen); | |
684 | } | |
685 | ||
686 | static int efx_ef10_mcdi_poll_reboot(struct efx_nic *efx) | |
687 | { | |
688 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
689 | int rc; | |
690 | ||
691 | rc = efx_ef10_get_warm_boot_count(efx); | |
692 | if (rc < 0) { | |
693 | /* The firmware is presumably in the process of | |
694 | * rebooting. However, we are supposed to report each | |
695 | * reboot just once, so we must only do that once we | |
696 | * can read and store the updated warm boot count. | |
697 | */ | |
698 | return 0; | |
699 | } | |
700 | ||
701 | if (rc == nic_data->warm_boot_count) | |
702 | return 0; | |
703 | ||
704 | nic_data->warm_boot_count = rc; | |
705 | ||
706 | /* All our allocations have been reset */ | |
707 | nic_data->must_realloc_vis = true; | |
708 | nic_data->must_restore_filters = true; | |
709 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
710 | ||
869070c5 BH |
711 | /* MAC statistics have been cleared on the NIC; clear the local |
712 | * statistic that we update with efx_update_diff_stat(). | |
713 | */ | |
714 | nic_data->stats[EF10_STAT_rx_bad_bytes] = 0; | |
715 | ||
8127d661 BH |
716 | return -EIO; |
717 | } | |
718 | ||
719 | /* Handle an MSI interrupt | |
720 | * | |
721 | * Handle an MSI hardware interrupt. This routine schedules event | |
722 | * queue processing. No interrupt acknowledgement cycle is necessary. | |
723 | * Also, we never need to check that the interrupt is for us, since | |
724 | * MSI interrupts cannot be shared. | |
725 | */ | |
726 | static irqreturn_t efx_ef10_msi_interrupt(int irq, void *dev_id) | |
727 | { | |
728 | struct efx_msi_context *context = dev_id; | |
729 | struct efx_nic *efx = context->efx; | |
730 | ||
731 | netif_vdbg(efx, intr, efx->net_dev, | |
732 | "IRQ %d on CPU %d\n", irq, raw_smp_processor_id()); | |
733 | ||
734 | if (likely(ACCESS_ONCE(efx->irq_soft_enabled))) { | |
735 | /* Note test interrupts */ | |
736 | if (context->index == efx->irq_level) | |
737 | efx->last_irq_cpu = raw_smp_processor_id(); | |
738 | ||
739 | /* Schedule processing of the channel */ | |
740 | efx_schedule_channel_irq(efx->channel[context->index]); | |
741 | } | |
742 | ||
743 | return IRQ_HANDLED; | |
744 | } | |
745 | ||
746 | static irqreturn_t efx_ef10_legacy_interrupt(int irq, void *dev_id) | |
747 | { | |
748 | struct efx_nic *efx = dev_id; | |
749 | bool soft_enabled = ACCESS_ONCE(efx->irq_soft_enabled); | |
750 | struct efx_channel *channel; | |
751 | efx_dword_t reg; | |
752 | u32 queues; | |
753 | ||
754 | /* Read the ISR which also ACKs the interrupts */ | |
755 | efx_readd(efx, ®, ER_DZ_BIU_INT_ISR); | |
756 | queues = EFX_DWORD_FIELD(reg, ERF_DZ_ISR_REG); | |
757 | ||
758 | if (queues == 0) | |
759 | return IRQ_NONE; | |
760 | ||
761 | if (likely(soft_enabled)) { | |
762 | /* Note test interrupts */ | |
763 | if (queues & (1U << efx->irq_level)) | |
764 | efx->last_irq_cpu = raw_smp_processor_id(); | |
765 | ||
766 | efx_for_each_channel(channel, efx) { | |
767 | if (queues & 1) | |
768 | efx_schedule_channel_irq(channel); | |
769 | queues >>= 1; | |
770 | } | |
771 | } | |
772 | ||
773 | netif_vdbg(efx, intr, efx->net_dev, | |
774 | "IRQ %d on CPU %d status " EFX_DWORD_FMT "\n", | |
775 | irq, raw_smp_processor_id(), EFX_DWORD_VAL(reg)); | |
776 | ||
777 | return IRQ_HANDLED; | |
778 | } | |
779 | ||
780 | static void efx_ef10_irq_test_generate(struct efx_nic *efx) | |
781 | { | |
782 | MCDI_DECLARE_BUF(inbuf, MC_CMD_TRIGGER_INTERRUPT_IN_LEN); | |
783 | ||
784 | BUILD_BUG_ON(MC_CMD_TRIGGER_INTERRUPT_OUT_LEN != 0); | |
785 | ||
786 | MCDI_SET_DWORD(inbuf, TRIGGER_INTERRUPT_IN_INTR_LEVEL, efx->irq_level); | |
787 | (void) efx_mcdi_rpc(efx, MC_CMD_TRIGGER_INTERRUPT, | |
788 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
789 | } | |
790 | ||
791 | static int efx_ef10_tx_probe(struct efx_tx_queue *tx_queue) | |
792 | { | |
793 | return efx_nic_alloc_buffer(tx_queue->efx, &tx_queue->txd.buf, | |
794 | (tx_queue->ptr_mask + 1) * | |
795 | sizeof(efx_qword_t), | |
796 | GFP_KERNEL); | |
797 | } | |
798 | ||
799 | /* This writes to the TX_DESC_WPTR and also pushes data */ | |
800 | static inline void efx_ef10_push_tx_desc(struct efx_tx_queue *tx_queue, | |
801 | const efx_qword_t *txd) | |
802 | { | |
803 | unsigned int write_ptr; | |
804 | efx_oword_t reg; | |
805 | ||
806 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
807 | EFX_POPULATE_OWORD_1(reg, ERF_DZ_TX_DESC_WPTR, write_ptr); | |
808 | reg.qword[0] = *txd; | |
809 | efx_writeo_page(tx_queue->efx, ®, | |
810 | ER_DZ_TX_DESC_UPD, tx_queue->queue); | |
811 | } | |
812 | ||
813 | static void efx_ef10_tx_init(struct efx_tx_queue *tx_queue) | |
814 | { | |
815 | MCDI_DECLARE_BUF(inbuf, MC_CMD_INIT_TXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
816 | EFX_BUF_SIZE)); | |
817 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_TXQ_OUT_LEN); | |
818 | bool csum_offload = tx_queue->queue & EFX_TXQ_TYPE_OFFLOAD; | |
819 | size_t entries = tx_queue->txd.buf.len / EFX_BUF_SIZE; | |
820 | struct efx_channel *channel = tx_queue->channel; | |
821 | struct efx_nic *efx = tx_queue->efx; | |
822 | size_t inlen, outlen; | |
823 | dma_addr_t dma_addr; | |
824 | efx_qword_t *txd; | |
825 | int rc; | |
826 | int i; | |
827 | ||
828 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_SIZE, tx_queue->ptr_mask + 1); | |
829 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_TARGET_EVQ, channel->channel); | |
830 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_LABEL, tx_queue->queue); | |
831 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_INSTANCE, tx_queue->queue); | |
832 | MCDI_POPULATE_DWORD_2(inbuf, INIT_TXQ_IN_FLAGS, | |
833 | INIT_TXQ_IN_FLAG_IP_CSUM_DIS, !csum_offload, | |
834 | INIT_TXQ_IN_FLAG_TCP_CSUM_DIS, !csum_offload); | |
835 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_OWNER_ID, 0); | |
836 | MCDI_SET_DWORD(inbuf, INIT_TXQ_IN_PORT_ID, EVB_PORT_ID_ASSIGNED); | |
837 | ||
838 | dma_addr = tx_queue->txd.buf.dma_addr; | |
839 | ||
840 | netif_dbg(efx, hw, efx->net_dev, "pushing TXQ %d. %zu entries (%llx)\n", | |
841 | tx_queue->queue, entries, (u64)dma_addr); | |
842 | ||
843 | for (i = 0; i < entries; ++i) { | |
844 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_TXQ_IN_DMA_ADDR, i, dma_addr); | |
845 | dma_addr += EFX_BUF_SIZE; | |
846 | } | |
847 | ||
848 | inlen = MC_CMD_INIT_TXQ_IN_LEN(entries); | |
849 | ||
850 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_TXQ, inbuf, inlen, | |
851 | outbuf, sizeof(outbuf), &outlen); | |
852 | if (rc) | |
853 | goto fail; | |
854 | ||
855 | /* A previous user of this TX queue might have set us up the | |
856 | * bomb by writing a descriptor to the TX push collector but | |
857 | * not the doorbell. (Each collector belongs to a port, not a | |
858 | * queue or function, so cannot easily be reset.) We must | |
859 | * attempt to push a no-op descriptor in its place. | |
860 | */ | |
861 | tx_queue->buffer[0].flags = EFX_TX_BUF_OPTION; | |
862 | tx_queue->insert_count = 1; | |
863 | txd = efx_tx_desc(tx_queue, 0); | |
864 | EFX_POPULATE_QWORD_4(*txd, | |
865 | ESF_DZ_TX_DESC_IS_OPT, true, | |
866 | ESF_DZ_TX_OPTION_TYPE, | |
867 | ESE_DZ_TX_OPTION_DESC_CRC_CSUM, | |
868 | ESF_DZ_TX_OPTION_UDP_TCP_CSUM, csum_offload, | |
869 | ESF_DZ_TX_OPTION_IP_CSUM, csum_offload); | |
870 | tx_queue->write_count = 1; | |
871 | wmb(); | |
872 | efx_ef10_push_tx_desc(tx_queue, txd); | |
873 | ||
874 | return; | |
875 | ||
876 | fail: | |
877 | WARN_ON(true); | |
878 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
879 | } | |
880 | ||
881 | static void efx_ef10_tx_fini(struct efx_tx_queue *tx_queue) | |
882 | { | |
883 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_TXQ_IN_LEN); | |
884 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_TXQ_OUT_LEN); | |
885 | struct efx_nic *efx = tx_queue->efx; | |
886 | size_t outlen; | |
887 | int rc; | |
888 | ||
889 | MCDI_SET_DWORD(inbuf, FINI_TXQ_IN_INSTANCE, | |
890 | tx_queue->queue); | |
891 | ||
892 | rc = efx_mcdi_rpc(efx, MC_CMD_FINI_TXQ, inbuf, sizeof(inbuf), | |
893 | outbuf, sizeof(outbuf), &outlen); | |
894 | ||
895 | if (rc && rc != -EALREADY) | |
896 | goto fail; | |
897 | ||
898 | return; | |
899 | ||
900 | fail: | |
901 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
902 | } | |
903 | ||
904 | static void efx_ef10_tx_remove(struct efx_tx_queue *tx_queue) | |
905 | { | |
906 | efx_nic_free_buffer(tx_queue->efx, &tx_queue->txd.buf); | |
907 | } | |
908 | ||
909 | /* This writes to the TX_DESC_WPTR; write pointer for TX descriptor ring */ | |
910 | static inline void efx_ef10_notify_tx_desc(struct efx_tx_queue *tx_queue) | |
911 | { | |
912 | unsigned int write_ptr; | |
913 | efx_dword_t reg; | |
914 | ||
915 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
916 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_TX_DESC_WPTR_DWORD, write_ptr); | |
917 | efx_writed_page(tx_queue->efx, ®, | |
918 | ER_DZ_TX_DESC_UPD_DWORD, tx_queue->queue); | |
919 | } | |
920 | ||
921 | static void efx_ef10_tx_write(struct efx_tx_queue *tx_queue) | |
922 | { | |
923 | unsigned int old_write_count = tx_queue->write_count; | |
924 | struct efx_tx_buffer *buffer; | |
925 | unsigned int write_ptr; | |
926 | efx_qword_t *txd; | |
927 | ||
928 | BUG_ON(tx_queue->write_count == tx_queue->insert_count); | |
929 | ||
930 | do { | |
931 | write_ptr = tx_queue->write_count & tx_queue->ptr_mask; | |
932 | buffer = &tx_queue->buffer[write_ptr]; | |
933 | txd = efx_tx_desc(tx_queue, write_ptr); | |
934 | ++tx_queue->write_count; | |
935 | ||
936 | /* Create TX descriptor ring entry */ | |
937 | if (buffer->flags & EFX_TX_BUF_OPTION) { | |
938 | *txd = buffer->option; | |
939 | } else { | |
940 | BUILD_BUG_ON(EFX_TX_BUF_CONT != 1); | |
941 | EFX_POPULATE_QWORD_3( | |
942 | *txd, | |
943 | ESF_DZ_TX_KER_CONT, | |
944 | buffer->flags & EFX_TX_BUF_CONT, | |
945 | ESF_DZ_TX_KER_BYTE_CNT, buffer->len, | |
946 | ESF_DZ_TX_KER_BUF_ADDR, buffer->dma_addr); | |
947 | } | |
948 | } while (tx_queue->write_count != tx_queue->insert_count); | |
949 | ||
950 | wmb(); /* Ensure descriptors are written before they are fetched */ | |
951 | ||
952 | if (efx_nic_may_push_tx_desc(tx_queue, old_write_count)) { | |
953 | txd = efx_tx_desc(tx_queue, | |
954 | old_write_count & tx_queue->ptr_mask); | |
955 | efx_ef10_push_tx_desc(tx_queue, txd); | |
956 | ++tx_queue->pushes; | |
957 | } else { | |
958 | efx_ef10_notify_tx_desc(tx_queue); | |
959 | } | |
960 | } | |
961 | ||
962 | static int efx_ef10_alloc_rss_context(struct efx_nic *efx, u32 *context) | |
963 | { | |
964 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_ALLOC_IN_LEN); | |
965 | MCDI_DECLARE_BUF(outbuf, MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN); | |
966 | size_t outlen; | |
967 | int rc; | |
968 | ||
969 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_UPSTREAM_PORT_ID, | |
970 | EVB_PORT_ID_ASSIGNED); | |
971 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_TYPE, | |
972 | MC_CMD_RSS_CONTEXT_ALLOC_IN_TYPE_EXCLUSIVE); | |
973 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_ALLOC_IN_NUM_QUEUES, | |
974 | EFX_MAX_CHANNELS); | |
975 | ||
976 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_ALLOC, inbuf, sizeof(inbuf), | |
977 | outbuf, sizeof(outbuf), &outlen); | |
978 | if (rc != 0) | |
979 | return rc; | |
980 | ||
981 | if (outlen < MC_CMD_RSS_CONTEXT_ALLOC_OUT_LEN) | |
982 | return -EIO; | |
983 | ||
984 | *context = MCDI_DWORD(outbuf, RSS_CONTEXT_ALLOC_OUT_RSS_CONTEXT_ID); | |
985 | ||
986 | return 0; | |
987 | } | |
988 | ||
989 | static void efx_ef10_free_rss_context(struct efx_nic *efx, u32 context) | |
990 | { | |
991 | MCDI_DECLARE_BUF(inbuf, MC_CMD_RSS_CONTEXT_FREE_IN_LEN); | |
992 | int rc; | |
993 | ||
994 | MCDI_SET_DWORD(inbuf, RSS_CONTEXT_FREE_IN_RSS_CONTEXT_ID, | |
995 | context); | |
996 | ||
997 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_FREE, inbuf, sizeof(inbuf), | |
998 | NULL, 0, NULL); | |
999 | WARN_ON(rc != 0); | |
1000 | } | |
1001 | ||
1002 | static int efx_ef10_populate_rss_table(struct efx_nic *efx, u32 context) | |
1003 | { | |
1004 | MCDI_DECLARE_BUF(tablebuf, MC_CMD_RSS_CONTEXT_SET_TABLE_IN_LEN); | |
1005 | MCDI_DECLARE_BUF(keybuf, MC_CMD_RSS_CONTEXT_SET_KEY_IN_LEN); | |
1006 | int i, rc; | |
1007 | ||
1008 | MCDI_SET_DWORD(tablebuf, RSS_CONTEXT_SET_TABLE_IN_RSS_CONTEXT_ID, | |
1009 | context); | |
1010 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_indir_table) != | |
1011 | MC_CMD_RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE_LEN); | |
1012 | ||
1013 | for (i = 0; i < ARRAY_SIZE(efx->rx_indir_table); ++i) | |
1014 | MCDI_PTR(tablebuf, | |
1015 | RSS_CONTEXT_SET_TABLE_IN_INDIRECTION_TABLE)[i] = | |
1016 | (u8) efx->rx_indir_table[i]; | |
1017 | ||
1018 | rc = efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_TABLE, tablebuf, | |
1019 | sizeof(tablebuf), NULL, 0, NULL); | |
1020 | if (rc != 0) | |
1021 | return rc; | |
1022 | ||
1023 | MCDI_SET_DWORD(keybuf, RSS_CONTEXT_SET_KEY_IN_RSS_CONTEXT_ID, | |
1024 | context); | |
1025 | BUILD_BUG_ON(ARRAY_SIZE(efx->rx_hash_key) != | |
1026 | MC_CMD_RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY_LEN); | |
1027 | for (i = 0; i < ARRAY_SIZE(efx->rx_hash_key); ++i) | |
1028 | MCDI_PTR(keybuf, RSS_CONTEXT_SET_KEY_IN_TOEPLITZ_KEY)[i] = | |
1029 | efx->rx_hash_key[i]; | |
1030 | ||
1031 | return efx_mcdi_rpc(efx, MC_CMD_RSS_CONTEXT_SET_KEY, keybuf, | |
1032 | sizeof(keybuf), NULL, 0, NULL); | |
1033 | } | |
1034 | ||
1035 | static void efx_ef10_rx_free_indir_table(struct efx_nic *efx) | |
1036 | { | |
1037 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1038 | ||
1039 | if (nic_data->rx_rss_context != EFX_EF10_RSS_CONTEXT_INVALID) | |
1040 | efx_ef10_free_rss_context(efx, nic_data->rx_rss_context); | |
1041 | nic_data->rx_rss_context = EFX_EF10_RSS_CONTEXT_INVALID; | |
1042 | } | |
1043 | ||
1044 | static void efx_ef10_rx_push_indir_table(struct efx_nic *efx) | |
1045 | { | |
1046 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1047 | int rc; | |
1048 | ||
1049 | netif_dbg(efx, drv, efx->net_dev, "pushing RX indirection table\n"); | |
1050 | ||
1051 | if (nic_data->rx_rss_context == EFX_EF10_RSS_CONTEXT_INVALID) { | |
1052 | rc = efx_ef10_alloc_rss_context(efx, &nic_data->rx_rss_context); | |
1053 | if (rc != 0) | |
1054 | goto fail; | |
1055 | } | |
1056 | ||
1057 | rc = efx_ef10_populate_rss_table(efx, nic_data->rx_rss_context); | |
1058 | if (rc != 0) | |
1059 | goto fail; | |
1060 | ||
1061 | return; | |
1062 | ||
1063 | fail: | |
1064 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
1065 | } | |
1066 | ||
1067 | static int efx_ef10_rx_probe(struct efx_rx_queue *rx_queue) | |
1068 | { | |
1069 | return efx_nic_alloc_buffer(rx_queue->efx, &rx_queue->rxd.buf, | |
1070 | (rx_queue->ptr_mask + 1) * | |
1071 | sizeof(efx_qword_t), | |
1072 | GFP_KERNEL); | |
1073 | } | |
1074 | ||
1075 | static void efx_ef10_rx_init(struct efx_rx_queue *rx_queue) | |
1076 | { | |
1077 | MCDI_DECLARE_BUF(inbuf, | |
1078 | MC_CMD_INIT_RXQ_IN_LEN(EFX_MAX_DMAQ_SIZE * 8 / | |
1079 | EFX_BUF_SIZE)); | |
1080 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_RXQ_OUT_LEN); | |
1081 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | |
1082 | size_t entries = rx_queue->rxd.buf.len / EFX_BUF_SIZE; | |
1083 | struct efx_nic *efx = rx_queue->efx; | |
1084 | size_t inlen, outlen; | |
1085 | dma_addr_t dma_addr; | |
1086 | int rc; | |
1087 | int i; | |
1088 | ||
1089 | rx_queue->scatter_n = 0; | |
1090 | rx_queue->scatter_len = 0; | |
1091 | ||
1092 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_SIZE, rx_queue->ptr_mask + 1); | |
1093 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_TARGET_EVQ, channel->channel); | |
1094 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_LABEL, efx_rx_queue_index(rx_queue)); | |
1095 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_INSTANCE, | |
1096 | efx_rx_queue_index(rx_queue)); | |
1097 | MCDI_POPULATE_DWORD_1(inbuf, INIT_RXQ_IN_FLAGS, | |
1098 | INIT_RXQ_IN_FLAG_PREFIX, 1); | |
1099 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_OWNER_ID, 0); | |
1100 | MCDI_SET_DWORD(inbuf, INIT_RXQ_IN_PORT_ID, EVB_PORT_ID_ASSIGNED); | |
1101 | ||
1102 | dma_addr = rx_queue->rxd.buf.dma_addr; | |
1103 | ||
1104 | netif_dbg(efx, hw, efx->net_dev, "pushing RXQ %d. %zu entries (%llx)\n", | |
1105 | efx_rx_queue_index(rx_queue), entries, (u64)dma_addr); | |
1106 | ||
1107 | for (i = 0; i < entries; ++i) { | |
1108 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_RXQ_IN_DMA_ADDR, i, dma_addr); | |
1109 | dma_addr += EFX_BUF_SIZE; | |
1110 | } | |
1111 | ||
1112 | inlen = MC_CMD_INIT_RXQ_IN_LEN(entries); | |
1113 | ||
1114 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_RXQ, inbuf, inlen, | |
1115 | outbuf, sizeof(outbuf), &outlen); | |
1116 | if (rc) | |
1117 | goto fail; | |
1118 | ||
1119 | return; | |
1120 | ||
1121 | fail: | |
1122 | WARN_ON(true); | |
1123 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
1124 | } | |
1125 | ||
1126 | static void efx_ef10_rx_fini(struct efx_rx_queue *rx_queue) | |
1127 | { | |
1128 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_RXQ_IN_LEN); | |
1129 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_RXQ_OUT_LEN); | |
1130 | struct efx_nic *efx = rx_queue->efx; | |
1131 | size_t outlen; | |
1132 | int rc; | |
1133 | ||
1134 | MCDI_SET_DWORD(inbuf, FINI_RXQ_IN_INSTANCE, | |
1135 | efx_rx_queue_index(rx_queue)); | |
1136 | ||
1137 | rc = efx_mcdi_rpc(efx, MC_CMD_FINI_RXQ, inbuf, sizeof(inbuf), | |
1138 | outbuf, sizeof(outbuf), &outlen); | |
1139 | ||
1140 | if (rc && rc != -EALREADY) | |
1141 | goto fail; | |
1142 | ||
1143 | return; | |
1144 | ||
1145 | fail: | |
1146 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
1147 | } | |
1148 | ||
1149 | static void efx_ef10_rx_remove(struct efx_rx_queue *rx_queue) | |
1150 | { | |
1151 | efx_nic_free_buffer(rx_queue->efx, &rx_queue->rxd.buf); | |
1152 | } | |
1153 | ||
1154 | /* This creates an entry in the RX descriptor queue */ | |
1155 | static inline void | |
1156 | efx_ef10_build_rx_desc(struct efx_rx_queue *rx_queue, unsigned int index) | |
1157 | { | |
1158 | struct efx_rx_buffer *rx_buf; | |
1159 | efx_qword_t *rxd; | |
1160 | ||
1161 | rxd = efx_rx_desc(rx_queue, index); | |
1162 | rx_buf = efx_rx_buffer(rx_queue, index); | |
1163 | EFX_POPULATE_QWORD_2(*rxd, | |
1164 | ESF_DZ_RX_KER_BYTE_CNT, rx_buf->len, | |
1165 | ESF_DZ_RX_KER_BUF_ADDR, rx_buf->dma_addr); | |
1166 | } | |
1167 | ||
1168 | static void efx_ef10_rx_write(struct efx_rx_queue *rx_queue) | |
1169 | { | |
1170 | struct efx_nic *efx = rx_queue->efx; | |
1171 | unsigned int write_count; | |
1172 | efx_dword_t reg; | |
1173 | ||
1174 | /* Firmware requires that RX_DESC_WPTR be a multiple of 8 */ | |
1175 | write_count = rx_queue->added_count & ~7; | |
1176 | if (rx_queue->notified_count == write_count) | |
1177 | return; | |
1178 | ||
1179 | do | |
1180 | efx_ef10_build_rx_desc( | |
1181 | rx_queue, | |
1182 | rx_queue->notified_count & rx_queue->ptr_mask); | |
1183 | while (++rx_queue->notified_count != write_count); | |
1184 | ||
1185 | wmb(); | |
1186 | EFX_POPULATE_DWORD_1(reg, ERF_DZ_RX_DESC_WPTR, | |
1187 | write_count & rx_queue->ptr_mask); | |
1188 | efx_writed_page(efx, ®, ER_DZ_RX_DESC_UPD, | |
1189 | efx_rx_queue_index(rx_queue)); | |
1190 | } | |
1191 | ||
1192 | static efx_mcdi_async_completer efx_ef10_rx_defer_refill_complete; | |
1193 | ||
1194 | static void efx_ef10_rx_defer_refill(struct efx_rx_queue *rx_queue) | |
1195 | { | |
1196 | struct efx_channel *channel = efx_rx_queue_channel(rx_queue); | |
1197 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
1198 | efx_qword_t event; | |
1199 | ||
1200 | EFX_POPULATE_QWORD_2(event, | |
1201 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
1202 | ESF_DZ_EV_DATA, EFX_EF10_REFILL); | |
1203 | ||
1204 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
1205 | ||
1206 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
1207 | * already swapped the data to little-endian order. | |
1208 | */ | |
1209 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
1210 | sizeof(efx_qword_t)); | |
1211 | ||
1212 | efx_mcdi_rpc_async(channel->efx, MC_CMD_DRIVER_EVENT, | |
1213 | inbuf, sizeof(inbuf), 0, | |
1214 | efx_ef10_rx_defer_refill_complete, 0); | |
1215 | } | |
1216 | ||
1217 | static void | |
1218 | efx_ef10_rx_defer_refill_complete(struct efx_nic *efx, unsigned long cookie, | |
1219 | int rc, efx_dword_t *outbuf, | |
1220 | size_t outlen_actual) | |
1221 | { | |
1222 | /* nothing to do */ | |
1223 | } | |
1224 | ||
1225 | static int efx_ef10_ev_probe(struct efx_channel *channel) | |
1226 | { | |
1227 | return efx_nic_alloc_buffer(channel->efx, &channel->eventq.buf, | |
1228 | (channel->eventq_mask + 1) * | |
1229 | sizeof(efx_qword_t), | |
1230 | GFP_KERNEL); | |
1231 | } | |
1232 | ||
1233 | static int efx_ef10_ev_init(struct efx_channel *channel) | |
1234 | { | |
1235 | MCDI_DECLARE_BUF(inbuf, | |
1236 | MC_CMD_INIT_EVQ_IN_LEN(EFX_MAX_EVQ_SIZE * 8 / | |
1237 | EFX_BUF_SIZE)); | |
1238 | MCDI_DECLARE_BUF(outbuf, MC_CMD_INIT_EVQ_OUT_LEN); | |
1239 | size_t entries = channel->eventq.buf.len / EFX_BUF_SIZE; | |
1240 | struct efx_nic *efx = channel->efx; | |
1241 | struct efx_ef10_nic_data *nic_data; | |
1242 | bool supports_rx_merge; | |
1243 | size_t inlen, outlen; | |
1244 | dma_addr_t dma_addr; | |
1245 | int rc; | |
1246 | int i; | |
1247 | ||
1248 | nic_data = efx->nic_data; | |
1249 | supports_rx_merge = | |
1250 | !!(nic_data->datapath_caps & | |
1251 | 1 << MC_CMD_GET_CAPABILITIES_OUT_RX_BATCHING_LBN); | |
1252 | ||
1253 | /* Fill event queue with all ones (i.e. empty events) */ | |
1254 | memset(channel->eventq.buf.addr, 0xff, channel->eventq.buf.len); | |
1255 | ||
1256 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_SIZE, channel->eventq_mask + 1); | |
1257 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_INSTANCE, channel->channel); | |
1258 | /* INIT_EVQ expects index in vector table, not absolute */ | |
1259 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_IRQ_NUM, channel->channel); | |
1260 | MCDI_POPULATE_DWORD_4(inbuf, INIT_EVQ_IN_FLAGS, | |
1261 | INIT_EVQ_IN_FLAG_INTERRUPTING, 1, | |
1262 | INIT_EVQ_IN_FLAG_RX_MERGE, 1, | |
1263 | INIT_EVQ_IN_FLAG_TX_MERGE, 1, | |
1264 | INIT_EVQ_IN_FLAG_CUT_THRU, !supports_rx_merge); | |
1265 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_MODE, | |
1266 | MC_CMD_INIT_EVQ_IN_TMR_MODE_DIS); | |
1267 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_LOAD, 0); | |
1268 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_TMR_RELOAD, 0); | |
1269 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_MODE, | |
1270 | MC_CMD_INIT_EVQ_IN_COUNT_MODE_DIS); | |
1271 | MCDI_SET_DWORD(inbuf, INIT_EVQ_IN_COUNT_THRSHLD, 0); | |
1272 | ||
1273 | dma_addr = channel->eventq.buf.dma_addr; | |
1274 | for (i = 0; i < entries; ++i) { | |
1275 | MCDI_SET_ARRAY_QWORD(inbuf, INIT_EVQ_IN_DMA_ADDR, i, dma_addr); | |
1276 | dma_addr += EFX_BUF_SIZE; | |
1277 | } | |
1278 | ||
1279 | inlen = MC_CMD_INIT_EVQ_IN_LEN(entries); | |
1280 | ||
1281 | rc = efx_mcdi_rpc(efx, MC_CMD_INIT_EVQ, inbuf, inlen, | |
1282 | outbuf, sizeof(outbuf), &outlen); | |
1283 | if (rc) | |
1284 | goto fail; | |
1285 | ||
1286 | /* IRQ return is ignored */ | |
1287 | ||
1288 | return 0; | |
1289 | ||
1290 | fail: | |
1291 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
1292 | return rc; | |
1293 | } | |
1294 | ||
1295 | static void efx_ef10_ev_fini(struct efx_channel *channel) | |
1296 | { | |
1297 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FINI_EVQ_IN_LEN); | |
1298 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FINI_EVQ_OUT_LEN); | |
1299 | struct efx_nic *efx = channel->efx; | |
1300 | size_t outlen; | |
1301 | int rc; | |
1302 | ||
1303 | MCDI_SET_DWORD(inbuf, FINI_EVQ_IN_INSTANCE, channel->channel); | |
1304 | ||
1305 | rc = efx_mcdi_rpc(efx, MC_CMD_FINI_EVQ, inbuf, sizeof(inbuf), | |
1306 | outbuf, sizeof(outbuf), &outlen); | |
1307 | ||
1308 | if (rc && rc != -EALREADY) | |
1309 | goto fail; | |
1310 | ||
1311 | return; | |
1312 | ||
1313 | fail: | |
1314 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
1315 | } | |
1316 | ||
1317 | static void efx_ef10_ev_remove(struct efx_channel *channel) | |
1318 | { | |
1319 | efx_nic_free_buffer(channel->efx, &channel->eventq.buf); | |
1320 | } | |
1321 | ||
1322 | static void efx_ef10_handle_rx_wrong_queue(struct efx_rx_queue *rx_queue, | |
1323 | unsigned int rx_queue_label) | |
1324 | { | |
1325 | struct efx_nic *efx = rx_queue->efx; | |
1326 | ||
1327 | netif_info(efx, hw, efx->net_dev, | |
1328 | "rx event arrived on queue %d labeled as queue %u\n", | |
1329 | efx_rx_queue_index(rx_queue), rx_queue_label); | |
1330 | ||
1331 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
1332 | } | |
1333 | ||
1334 | static void | |
1335 | efx_ef10_handle_rx_bad_lbits(struct efx_rx_queue *rx_queue, | |
1336 | unsigned int actual, unsigned int expected) | |
1337 | { | |
1338 | unsigned int dropped = (actual - expected) & rx_queue->ptr_mask; | |
1339 | struct efx_nic *efx = rx_queue->efx; | |
1340 | ||
1341 | netif_info(efx, hw, efx->net_dev, | |
1342 | "dropped %d events (index=%d expected=%d)\n", | |
1343 | dropped, actual, expected); | |
1344 | ||
1345 | efx_schedule_reset(efx, RESET_TYPE_DISABLE); | |
1346 | } | |
1347 | ||
1348 | /* partially received RX was aborted. clean up. */ | |
1349 | static void efx_ef10_handle_rx_abort(struct efx_rx_queue *rx_queue) | |
1350 | { | |
1351 | unsigned int rx_desc_ptr; | |
1352 | ||
1353 | WARN_ON(rx_queue->scatter_n == 0); | |
1354 | ||
1355 | netif_dbg(rx_queue->efx, hw, rx_queue->efx->net_dev, | |
1356 | "scattered RX aborted (dropping %u buffers)\n", | |
1357 | rx_queue->scatter_n); | |
1358 | ||
1359 | rx_desc_ptr = rx_queue->removed_count & rx_queue->ptr_mask; | |
1360 | ||
1361 | efx_rx_packet(rx_queue, rx_desc_ptr, rx_queue->scatter_n, | |
1362 | 0, EFX_RX_PKT_DISCARD); | |
1363 | ||
1364 | rx_queue->removed_count += rx_queue->scatter_n; | |
1365 | rx_queue->scatter_n = 0; | |
1366 | rx_queue->scatter_len = 0; | |
1367 | ++efx_rx_queue_channel(rx_queue)->n_rx_nodesc_trunc; | |
1368 | } | |
1369 | ||
1370 | static int efx_ef10_handle_rx_event(struct efx_channel *channel, | |
1371 | const efx_qword_t *event) | |
1372 | { | |
1373 | unsigned int rx_bytes, next_ptr_lbits, rx_queue_label, rx_l4_class; | |
1374 | unsigned int n_descs, n_packets, i; | |
1375 | struct efx_nic *efx = channel->efx; | |
1376 | struct efx_rx_queue *rx_queue; | |
1377 | bool rx_cont; | |
1378 | u16 flags = 0; | |
1379 | ||
1380 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
1381 | return 0; | |
1382 | ||
1383 | /* Basic packet information */ | |
1384 | rx_bytes = EFX_QWORD_FIELD(*event, ESF_DZ_RX_BYTES); | |
1385 | next_ptr_lbits = EFX_QWORD_FIELD(*event, ESF_DZ_RX_DSC_PTR_LBITS); | |
1386 | rx_queue_label = EFX_QWORD_FIELD(*event, ESF_DZ_RX_QLABEL); | |
1387 | rx_l4_class = EFX_QWORD_FIELD(*event, ESF_DZ_RX_L4_CLASS); | |
1388 | rx_cont = EFX_QWORD_FIELD(*event, ESF_DZ_RX_CONT); | |
1389 | ||
1390 | WARN_ON(EFX_QWORD_FIELD(*event, ESF_DZ_RX_DROP_EVENT)); | |
1391 | ||
1392 | rx_queue = efx_channel_get_rx_queue(channel); | |
1393 | ||
1394 | if (unlikely(rx_queue_label != efx_rx_queue_index(rx_queue))) | |
1395 | efx_ef10_handle_rx_wrong_queue(rx_queue, rx_queue_label); | |
1396 | ||
1397 | n_descs = ((next_ptr_lbits - rx_queue->removed_count) & | |
1398 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
1399 | ||
1400 | if (n_descs != rx_queue->scatter_n + 1) { | |
1401 | /* detect rx abort */ | |
1402 | if (unlikely(n_descs == rx_queue->scatter_n)) { | |
1403 | WARN_ON(rx_bytes != 0); | |
1404 | efx_ef10_handle_rx_abort(rx_queue); | |
1405 | return 0; | |
1406 | } | |
1407 | ||
1408 | if (unlikely(rx_queue->scatter_n != 0)) { | |
1409 | /* Scattered packet completions cannot be | |
1410 | * merged, so something has gone wrong. | |
1411 | */ | |
1412 | efx_ef10_handle_rx_bad_lbits( | |
1413 | rx_queue, next_ptr_lbits, | |
1414 | (rx_queue->removed_count + | |
1415 | rx_queue->scatter_n + 1) & | |
1416 | ((1 << ESF_DZ_RX_DSC_PTR_LBITS_WIDTH) - 1)); | |
1417 | return 0; | |
1418 | } | |
1419 | ||
1420 | /* Merged completion for multiple non-scattered packets */ | |
1421 | rx_queue->scatter_n = 1; | |
1422 | rx_queue->scatter_len = 0; | |
1423 | n_packets = n_descs; | |
1424 | ++channel->n_rx_merge_events; | |
1425 | channel->n_rx_merge_packets += n_packets; | |
1426 | flags |= EFX_RX_PKT_PREFIX_LEN; | |
1427 | } else { | |
1428 | ++rx_queue->scatter_n; | |
1429 | rx_queue->scatter_len += rx_bytes; | |
1430 | if (rx_cont) | |
1431 | return 0; | |
1432 | n_packets = 1; | |
1433 | } | |
1434 | ||
1435 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_ECRC_ERR))) | |
1436 | flags |= EFX_RX_PKT_DISCARD; | |
1437 | ||
1438 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_RX_IPCKSUM_ERR))) { | |
1439 | channel->n_rx_ip_hdr_chksum_err += n_packets; | |
1440 | } else if (unlikely(EFX_QWORD_FIELD(*event, | |
1441 | ESF_DZ_RX_TCPUDP_CKSUM_ERR))) { | |
1442 | channel->n_rx_tcp_udp_chksum_err += n_packets; | |
1443 | } else if (rx_l4_class == ESE_DZ_L4_CLASS_TCP || | |
1444 | rx_l4_class == ESE_DZ_L4_CLASS_UDP) { | |
1445 | flags |= EFX_RX_PKT_CSUMMED; | |
1446 | } | |
1447 | ||
1448 | if (rx_l4_class == ESE_DZ_L4_CLASS_TCP) | |
1449 | flags |= EFX_RX_PKT_TCP; | |
1450 | ||
1451 | channel->irq_mod_score += 2 * n_packets; | |
1452 | ||
1453 | /* Handle received packet(s) */ | |
1454 | for (i = 0; i < n_packets; i++) { | |
1455 | efx_rx_packet(rx_queue, | |
1456 | rx_queue->removed_count & rx_queue->ptr_mask, | |
1457 | rx_queue->scatter_n, rx_queue->scatter_len, | |
1458 | flags); | |
1459 | rx_queue->removed_count += rx_queue->scatter_n; | |
1460 | } | |
1461 | ||
1462 | rx_queue->scatter_n = 0; | |
1463 | rx_queue->scatter_len = 0; | |
1464 | ||
1465 | return n_packets; | |
1466 | } | |
1467 | ||
1468 | static int | |
1469 | efx_ef10_handle_tx_event(struct efx_channel *channel, efx_qword_t *event) | |
1470 | { | |
1471 | struct efx_nic *efx = channel->efx; | |
1472 | struct efx_tx_queue *tx_queue; | |
1473 | unsigned int tx_ev_desc_ptr; | |
1474 | unsigned int tx_ev_q_label; | |
1475 | int tx_descs = 0; | |
1476 | ||
1477 | if (unlikely(ACCESS_ONCE(efx->reset_pending))) | |
1478 | return 0; | |
1479 | ||
1480 | if (unlikely(EFX_QWORD_FIELD(*event, ESF_DZ_TX_DROP_EVENT))) | |
1481 | return 0; | |
1482 | ||
1483 | /* Transmit completion */ | |
1484 | tx_ev_desc_ptr = EFX_QWORD_FIELD(*event, ESF_DZ_TX_DESCR_INDX); | |
1485 | tx_ev_q_label = EFX_QWORD_FIELD(*event, ESF_DZ_TX_QLABEL); | |
1486 | tx_queue = efx_channel_get_tx_queue(channel, | |
1487 | tx_ev_q_label % EFX_TXQ_TYPES); | |
1488 | tx_descs = ((tx_ev_desc_ptr + 1 - tx_queue->read_count) & | |
1489 | tx_queue->ptr_mask); | |
1490 | efx_xmit_done(tx_queue, tx_ev_desc_ptr & tx_queue->ptr_mask); | |
1491 | ||
1492 | return tx_descs; | |
1493 | } | |
1494 | ||
1495 | static void | |
1496 | efx_ef10_handle_driver_event(struct efx_channel *channel, efx_qword_t *event) | |
1497 | { | |
1498 | struct efx_nic *efx = channel->efx; | |
1499 | int subcode; | |
1500 | ||
1501 | subcode = EFX_QWORD_FIELD(*event, ESF_DZ_DRV_SUB_CODE); | |
1502 | ||
1503 | switch (subcode) { | |
1504 | case ESE_DZ_DRV_TIMER_EV: | |
1505 | case ESE_DZ_DRV_WAKE_UP_EV: | |
1506 | break; | |
1507 | case ESE_DZ_DRV_START_UP_EV: | |
1508 | /* event queue init complete. ok. */ | |
1509 | break; | |
1510 | default: | |
1511 | netif_err(efx, hw, efx->net_dev, | |
1512 | "channel %d unknown driver event type %d" | |
1513 | " (data " EFX_QWORD_FMT ")\n", | |
1514 | channel->channel, subcode, | |
1515 | EFX_QWORD_VAL(*event)); | |
1516 | ||
1517 | } | |
1518 | } | |
1519 | ||
1520 | static void efx_ef10_handle_driver_generated_event(struct efx_channel *channel, | |
1521 | efx_qword_t *event) | |
1522 | { | |
1523 | struct efx_nic *efx = channel->efx; | |
1524 | u32 subcode; | |
1525 | ||
1526 | subcode = EFX_QWORD_FIELD(*event, EFX_DWORD_0); | |
1527 | ||
1528 | switch (subcode) { | |
1529 | case EFX_EF10_TEST: | |
1530 | channel->event_test_cpu = raw_smp_processor_id(); | |
1531 | break; | |
1532 | case EFX_EF10_REFILL: | |
1533 | /* The queue must be empty, so we won't receive any rx | |
1534 | * events, so efx_process_channel() won't refill the | |
1535 | * queue. Refill it here | |
1536 | */ | |
1537 | efx_fast_push_rx_descriptors(&channel->rx_queue); | |
1538 | break; | |
1539 | default: | |
1540 | netif_err(efx, hw, efx->net_dev, | |
1541 | "channel %d unknown driver event type %u" | |
1542 | " (data " EFX_QWORD_FMT ")\n", | |
1543 | channel->channel, (unsigned) subcode, | |
1544 | EFX_QWORD_VAL(*event)); | |
1545 | } | |
1546 | } | |
1547 | ||
1548 | static int efx_ef10_ev_process(struct efx_channel *channel, int quota) | |
1549 | { | |
1550 | struct efx_nic *efx = channel->efx; | |
1551 | efx_qword_t event, *p_event; | |
1552 | unsigned int read_ptr; | |
1553 | int ev_code; | |
1554 | int tx_descs = 0; | |
1555 | int spent = 0; | |
1556 | ||
1557 | read_ptr = channel->eventq_read_ptr; | |
1558 | ||
1559 | for (;;) { | |
1560 | p_event = efx_event(channel, read_ptr); | |
1561 | event = *p_event; | |
1562 | ||
1563 | if (!efx_event_present(&event)) | |
1564 | break; | |
1565 | ||
1566 | EFX_SET_QWORD(*p_event); | |
1567 | ||
1568 | ++read_ptr; | |
1569 | ||
1570 | ev_code = EFX_QWORD_FIELD(event, ESF_DZ_EV_CODE); | |
1571 | ||
1572 | netif_vdbg(efx, drv, efx->net_dev, | |
1573 | "processing event on %d " EFX_QWORD_FMT "\n", | |
1574 | channel->channel, EFX_QWORD_VAL(event)); | |
1575 | ||
1576 | switch (ev_code) { | |
1577 | case ESE_DZ_EV_CODE_MCDI_EV: | |
1578 | efx_mcdi_process_event(channel, &event); | |
1579 | break; | |
1580 | case ESE_DZ_EV_CODE_RX_EV: | |
1581 | spent += efx_ef10_handle_rx_event(channel, &event); | |
1582 | if (spent >= quota) { | |
1583 | /* XXX can we split a merged event to | |
1584 | * avoid going over-quota? | |
1585 | */ | |
1586 | spent = quota; | |
1587 | goto out; | |
1588 | } | |
1589 | break; | |
1590 | case ESE_DZ_EV_CODE_TX_EV: | |
1591 | tx_descs += efx_ef10_handle_tx_event(channel, &event); | |
1592 | if (tx_descs > efx->txq_entries) { | |
1593 | spent = quota; | |
1594 | goto out; | |
1595 | } else if (++spent == quota) { | |
1596 | goto out; | |
1597 | } | |
1598 | break; | |
1599 | case ESE_DZ_EV_CODE_DRIVER_EV: | |
1600 | efx_ef10_handle_driver_event(channel, &event); | |
1601 | if (++spent == quota) | |
1602 | goto out; | |
1603 | break; | |
1604 | case EFX_EF10_DRVGEN_EV: | |
1605 | efx_ef10_handle_driver_generated_event(channel, &event); | |
1606 | break; | |
1607 | default: | |
1608 | netif_err(efx, hw, efx->net_dev, | |
1609 | "channel %d unknown event type %d" | |
1610 | " (data " EFX_QWORD_FMT ")\n", | |
1611 | channel->channel, ev_code, | |
1612 | EFX_QWORD_VAL(event)); | |
1613 | } | |
1614 | } | |
1615 | ||
1616 | out: | |
1617 | channel->eventq_read_ptr = read_ptr; | |
1618 | return spent; | |
1619 | } | |
1620 | ||
1621 | static void efx_ef10_ev_read_ack(struct efx_channel *channel) | |
1622 | { | |
1623 | struct efx_nic *efx = channel->efx; | |
1624 | efx_dword_t rptr; | |
1625 | ||
1626 | if (EFX_EF10_WORKAROUND_35388(efx)) { | |
1627 | BUILD_BUG_ON(EFX_MIN_EVQ_SIZE < | |
1628 | (1 << ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
1629 | BUILD_BUG_ON(EFX_MAX_EVQ_SIZE > | |
1630 | (1 << 2 * ERF_DD_EVQ_IND_RPTR_WIDTH)); | |
1631 | ||
1632 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
1633 | EFE_DD_EVQ_IND_RPTR_FLAGS_HIGH, | |
1634 | ERF_DD_EVQ_IND_RPTR, | |
1635 | (channel->eventq_read_ptr & | |
1636 | channel->eventq_mask) >> | |
1637 | ERF_DD_EVQ_IND_RPTR_WIDTH); | |
1638 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
1639 | channel->channel); | |
1640 | EFX_POPULATE_DWORD_2(rptr, ERF_DD_EVQ_IND_RPTR_FLAGS, | |
1641 | EFE_DD_EVQ_IND_RPTR_FLAGS_LOW, | |
1642 | ERF_DD_EVQ_IND_RPTR, | |
1643 | channel->eventq_read_ptr & | |
1644 | ((1 << ERF_DD_EVQ_IND_RPTR_WIDTH) - 1)); | |
1645 | efx_writed_page(efx, &rptr, ER_DD_EVQ_INDIRECT, | |
1646 | channel->channel); | |
1647 | } else { | |
1648 | EFX_POPULATE_DWORD_1(rptr, ERF_DZ_EVQ_RPTR, | |
1649 | channel->eventq_read_ptr & | |
1650 | channel->eventq_mask); | |
1651 | efx_writed_page(efx, &rptr, ER_DZ_EVQ_RPTR, channel->channel); | |
1652 | } | |
1653 | } | |
1654 | ||
1655 | static void efx_ef10_ev_test_generate(struct efx_channel *channel) | |
1656 | { | |
1657 | MCDI_DECLARE_BUF(inbuf, MC_CMD_DRIVER_EVENT_IN_LEN); | |
1658 | struct efx_nic *efx = channel->efx; | |
1659 | efx_qword_t event; | |
1660 | int rc; | |
1661 | ||
1662 | EFX_POPULATE_QWORD_2(event, | |
1663 | ESF_DZ_EV_CODE, EFX_EF10_DRVGEN_EV, | |
1664 | ESF_DZ_EV_DATA, EFX_EF10_TEST); | |
1665 | ||
1666 | MCDI_SET_DWORD(inbuf, DRIVER_EVENT_IN_EVQ, channel->channel); | |
1667 | ||
1668 | /* MCDI_SET_QWORD is not appropriate here since EFX_POPULATE_* has | |
1669 | * already swapped the data to little-endian order. | |
1670 | */ | |
1671 | memcpy(MCDI_PTR(inbuf, DRIVER_EVENT_IN_DATA), &event.u64[0], | |
1672 | sizeof(efx_qword_t)); | |
1673 | ||
1674 | rc = efx_mcdi_rpc(efx, MC_CMD_DRIVER_EVENT, inbuf, sizeof(inbuf), | |
1675 | NULL, 0, NULL); | |
1676 | if (rc != 0) | |
1677 | goto fail; | |
1678 | ||
1679 | return; | |
1680 | ||
1681 | fail: | |
1682 | WARN_ON(true); | |
1683 | netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc); | |
1684 | } | |
1685 | ||
1686 | void efx_ef10_handle_drain_event(struct efx_nic *efx) | |
1687 | { | |
1688 | if (atomic_dec_and_test(&efx->active_queues)) | |
1689 | wake_up(&efx->flush_wq); | |
1690 | ||
1691 | WARN_ON(atomic_read(&efx->active_queues) < 0); | |
1692 | } | |
1693 | ||
1694 | static int efx_ef10_fini_dmaq(struct efx_nic *efx) | |
1695 | { | |
1696 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1697 | struct efx_channel *channel; | |
1698 | struct efx_tx_queue *tx_queue; | |
1699 | struct efx_rx_queue *rx_queue; | |
1700 | int pending; | |
1701 | ||
1702 | /* If the MC has just rebooted, the TX/RX queues will have already been | |
1703 | * torn down, but efx->active_queues needs to be set to zero. | |
1704 | */ | |
1705 | if (nic_data->must_realloc_vis) { | |
1706 | atomic_set(&efx->active_queues, 0); | |
1707 | return 0; | |
1708 | } | |
1709 | ||
1710 | /* Do not attempt to write to the NIC during EEH recovery */ | |
1711 | if (efx->state != STATE_RECOVERY) { | |
1712 | efx_for_each_channel(channel, efx) { | |
1713 | efx_for_each_channel_rx_queue(rx_queue, channel) | |
1714 | efx_ef10_rx_fini(rx_queue); | |
1715 | efx_for_each_channel_tx_queue(tx_queue, channel) | |
1716 | efx_ef10_tx_fini(tx_queue); | |
1717 | } | |
1718 | ||
1719 | wait_event_timeout(efx->flush_wq, | |
1720 | atomic_read(&efx->active_queues) == 0, | |
1721 | msecs_to_jiffies(EFX_MAX_FLUSH_TIME)); | |
1722 | pending = atomic_read(&efx->active_queues); | |
1723 | if (pending) { | |
1724 | netif_err(efx, hw, efx->net_dev, "failed to flush %d queues\n", | |
1725 | pending); | |
1726 | return -ETIMEDOUT; | |
1727 | } | |
1728 | } | |
1729 | ||
1730 | return 0; | |
1731 | } | |
1732 | ||
1733 | static bool efx_ef10_filter_equal(const struct efx_filter_spec *left, | |
1734 | const struct efx_filter_spec *right) | |
1735 | { | |
1736 | if ((left->match_flags ^ right->match_flags) | | |
1737 | ((left->flags ^ right->flags) & | |
1738 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX))) | |
1739 | return false; | |
1740 | ||
1741 | return memcmp(&left->outer_vid, &right->outer_vid, | |
1742 | sizeof(struct efx_filter_spec) - | |
1743 | offsetof(struct efx_filter_spec, outer_vid)) == 0; | |
1744 | } | |
1745 | ||
1746 | static unsigned int efx_ef10_filter_hash(const struct efx_filter_spec *spec) | |
1747 | { | |
1748 | BUILD_BUG_ON(offsetof(struct efx_filter_spec, outer_vid) & 3); | |
1749 | return jhash2((const u32 *)&spec->outer_vid, | |
1750 | (sizeof(struct efx_filter_spec) - | |
1751 | offsetof(struct efx_filter_spec, outer_vid)) / 4, | |
1752 | 0); | |
1753 | /* XXX should we randomise the initval? */ | |
1754 | } | |
1755 | ||
1756 | /* Decide whether a filter should be exclusive or else should allow | |
1757 | * delivery to additional recipients. Currently we decide that | |
1758 | * filters for specific local unicast MAC and IP addresses are | |
1759 | * exclusive. | |
1760 | */ | |
1761 | static bool efx_ef10_filter_is_exclusive(const struct efx_filter_spec *spec) | |
1762 | { | |
1763 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC && | |
1764 | !is_multicast_ether_addr(spec->loc_mac)) | |
1765 | return true; | |
1766 | ||
1767 | if ((spec->match_flags & | |
1768 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) == | |
1769 | (EFX_FILTER_MATCH_ETHER_TYPE | EFX_FILTER_MATCH_LOC_HOST)) { | |
1770 | if (spec->ether_type == htons(ETH_P_IP) && | |
1771 | !ipv4_is_multicast(spec->loc_host[0])) | |
1772 | return true; | |
1773 | if (spec->ether_type == htons(ETH_P_IPV6) && | |
1774 | ((const u8 *)spec->loc_host)[0] != 0xff) | |
1775 | return true; | |
1776 | } | |
1777 | ||
1778 | return false; | |
1779 | } | |
1780 | ||
1781 | static struct efx_filter_spec * | |
1782 | efx_ef10_filter_entry_spec(const struct efx_ef10_filter_table *table, | |
1783 | unsigned int filter_idx) | |
1784 | { | |
1785 | return (struct efx_filter_spec *)(table->entry[filter_idx].spec & | |
1786 | ~EFX_EF10_FILTER_FLAGS); | |
1787 | } | |
1788 | ||
1789 | static unsigned int | |
1790 | efx_ef10_filter_entry_flags(const struct efx_ef10_filter_table *table, | |
1791 | unsigned int filter_idx) | |
1792 | { | |
1793 | return table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAGS; | |
1794 | } | |
1795 | ||
1796 | static void | |
1797 | efx_ef10_filter_set_entry(struct efx_ef10_filter_table *table, | |
1798 | unsigned int filter_idx, | |
1799 | const struct efx_filter_spec *spec, | |
1800 | unsigned int flags) | |
1801 | { | |
1802 | table->entry[filter_idx].spec = (unsigned long)spec | flags; | |
1803 | } | |
1804 | ||
1805 | static void efx_ef10_filter_push_prep(struct efx_nic *efx, | |
1806 | const struct efx_filter_spec *spec, | |
1807 | efx_dword_t *inbuf, u64 handle, | |
1808 | bool replacing) | |
1809 | { | |
1810 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
1811 | ||
1812 | memset(inbuf, 0, MC_CMD_FILTER_OP_IN_LEN); | |
1813 | ||
1814 | if (replacing) { | |
1815 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
1816 | MC_CMD_FILTER_OP_IN_OP_REPLACE); | |
1817 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, handle); | |
1818 | } else { | |
1819 | u32 match_fields = 0; | |
1820 | ||
1821 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
1822 | efx_ef10_filter_is_exclusive(spec) ? | |
1823 | MC_CMD_FILTER_OP_IN_OP_INSERT : | |
1824 | MC_CMD_FILTER_OP_IN_OP_SUBSCRIBE); | |
1825 | ||
1826 | /* Convert match flags and values. Unlike almost | |
1827 | * everything else in MCDI, these fields are in | |
1828 | * network byte order. | |
1829 | */ | |
1830 | if (spec->match_flags & EFX_FILTER_MATCH_LOC_MAC_IG) | |
1831 | match_fields |= | |
1832 | is_multicast_ether_addr(spec->loc_mac) ? | |
1833 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_MCAST_DST_LBN : | |
1834 | 1 << MC_CMD_FILTER_OP_IN_MATCH_UNKNOWN_UCAST_DST_LBN; | |
1835 | #define COPY_FIELD(gen_flag, gen_field, mcdi_field) \ | |
1836 | if (spec->match_flags & EFX_FILTER_MATCH_ ## gen_flag) { \ | |
1837 | match_fields |= \ | |
1838 | 1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
1839 | mcdi_field ## _LBN; \ | |
1840 | BUILD_BUG_ON( \ | |
1841 | MC_CMD_FILTER_OP_IN_ ## mcdi_field ## _LEN < \ | |
1842 | sizeof(spec->gen_field)); \ | |
1843 | memcpy(MCDI_PTR(inbuf, FILTER_OP_IN_ ## mcdi_field), \ | |
1844 | &spec->gen_field, sizeof(spec->gen_field)); \ | |
1845 | } | |
1846 | COPY_FIELD(REM_HOST, rem_host, SRC_IP); | |
1847 | COPY_FIELD(LOC_HOST, loc_host, DST_IP); | |
1848 | COPY_FIELD(REM_MAC, rem_mac, SRC_MAC); | |
1849 | COPY_FIELD(REM_PORT, rem_port, SRC_PORT); | |
1850 | COPY_FIELD(LOC_MAC, loc_mac, DST_MAC); | |
1851 | COPY_FIELD(LOC_PORT, loc_port, DST_PORT); | |
1852 | COPY_FIELD(ETHER_TYPE, ether_type, ETHER_TYPE); | |
1853 | COPY_FIELD(INNER_VID, inner_vid, INNER_VLAN); | |
1854 | COPY_FIELD(OUTER_VID, outer_vid, OUTER_VLAN); | |
1855 | COPY_FIELD(IP_PROTO, ip_proto, IP_PROTO); | |
1856 | #undef COPY_FIELD | |
1857 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_MATCH_FIELDS, | |
1858 | match_fields); | |
1859 | } | |
1860 | ||
1861 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_PORT_ID, EVB_PORT_ID_ASSIGNED); | |
1862 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_DEST, | |
1863 | spec->dmaq_id == EFX_FILTER_RX_DMAQ_ID_DROP ? | |
1864 | MC_CMD_FILTER_OP_IN_RX_DEST_DROP : | |
1865 | MC_CMD_FILTER_OP_IN_RX_DEST_HOST); | |
1866 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_TX_DEST, | |
1867 | MC_CMD_FILTER_OP_IN_TX_DEST_DEFAULT); | |
1868 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_QUEUE, spec->dmaq_id); | |
1869 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_MODE, | |
1870 | (spec->flags & EFX_FILTER_FLAG_RX_RSS) ? | |
1871 | MC_CMD_FILTER_OP_IN_RX_MODE_RSS : | |
1872 | MC_CMD_FILTER_OP_IN_RX_MODE_SIMPLE); | |
1873 | if (spec->flags & EFX_FILTER_FLAG_RX_RSS) | |
1874 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_RX_CONTEXT, | |
1875 | spec->rss_context != | |
1876 | EFX_FILTER_RSS_CONTEXT_DEFAULT ? | |
1877 | spec->rss_context : nic_data->rx_rss_context); | |
1878 | } | |
1879 | ||
1880 | static int efx_ef10_filter_push(struct efx_nic *efx, | |
1881 | const struct efx_filter_spec *spec, | |
1882 | u64 *handle, bool replacing) | |
1883 | { | |
1884 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
1885 | MCDI_DECLARE_BUF(outbuf, MC_CMD_FILTER_OP_OUT_LEN); | |
1886 | int rc; | |
1887 | ||
1888 | efx_ef10_filter_push_prep(efx, spec, inbuf, *handle, replacing); | |
1889 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
1890 | outbuf, sizeof(outbuf), NULL); | |
1891 | if (rc == 0) | |
1892 | *handle = MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
1893 | return rc; | |
1894 | } | |
1895 | ||
1896 | static int efx_ef10_filter_rx_match_pri(struct efx_ef10_filter_table *table, | |
1897 | enum efx_filter_match_flags match_flags) | |
1898 | { | |
1899 | unsigned int match_pri; | |
1900 | ||
1901 | for (match_pri = 0; | |
1902 | match_pri < table->rx_match_count; | |
1903 | match_pri++) | |
1904 | if (table->rx_match_flags[match_pri] == match_flags) | |
1905 | return match_pri; | |
1906 | ||
1907 | return -EPROTONOSUPPORT; | |
1908 | } | |
1909 | ||
1910 | static s32 efx_ef10_filter_insert(struct efx_nic *efx, | |
1911 | struct efx_filter_spec *spec, | |
1912 | bool replace_equal) | |
1913 | { | |
1914 | struct efx_ef10_filter_table *table = efx->filter_state; | |
1915 | DECLARE_BITMAP(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
1916 | struct efx_filter_spec *saved_spec; | |
1917 | unsigned int match_pri, hash; | |
1918 | unsigned int priv_flags; | |
1919 | bool replacing = false; | |
1920 | int ins_index = -1; | |
1921 | DEFINE_WAIT(wait); | |
1922 | bool is_mc_recip; | |
1923 | s32 rc; | |
1924 | ||
1925 | /* For now, only support RX filters */ | |
1926 | if ((spec->flags & (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_TX)) != | |
1927 | EFX_FILTER_FLAG_RX) | |
1928 | return -EINVAL; | |
1929 | ||
1930 | rc = efx_ef10_filter_rx_match_pri(table, spec->match_flags); | |
1931 | if (rc < 0) | |
1932 | return rc; | |
1933 | match_pri = rc; | |
1934 | ||
1935 | hash = efx_ef10_filter_hash(spec); | |
1936 | is_mc_recip = efx_filter_is_mc_recipient(spec); | |
1937 | if (is_mc_recip) | |
1938 | bitmap_zero(mc_rem_map, EFX_EF10_FILTER_SEARCH_LIMIT); | |
1939 | ||
1940 | /* Find any existing filters with the same match tuple or | |
1941 | * else a free slot to insert at. If any of them are busy, | |
1942 | * we have to wait and retry. | |
1943 | */ | |
1944 | for (;;) { | |
1945 | unsigned int depth = 1; | |
1946 | unsigned int i; | |
1947 | ||
1948 | spin_lock_bh(&efx->filter_lock); | |
1949 | ||
1950 | for (;;) { | |
1951 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
1952 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
1953 | ||
1954 | if (!saved_spec) { | |
1955 | if (ins_index < 0) | |
1956 | ins_index = i; | |
1957 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
1958 | if (table->entry[i].spec & | |
1959 | EFX_EF10_FILTER_FLAG_BUSY) | |
1960 | break; | |
1961 | if (spec->priority < saved_spec->priority && | |
1962 | !(saved_spec->priority == | |
1963 | EFX_FILTER_PRI_REQUIRED && | |
1964 | saved_spec->flags & | |
1965 | EFX_FILTER_FLAG_RX_STACK)) { | |
1966 | rc = -EPERM; | |
1967 | goto out_unlock; | |
1968 | } | |
1969 | if (!is_mc_recip) { | |
1970 | /* This is the only one */ | |
1971 | if (spec->priority == | |
1972 | saved_spec->priority && | |
1973 | !replace_equal) { | |
1974 | rc = -EEXIST; | |
1975 | goto out_unlock; | |
1976 | } | |
1977 | ins_index = i; | |
1978 | goto found; | |
1979 | } else if (spec->priority > | |
1980 | saved_spec->priority || | |
1981 | (spec->priority == | |
1982 | saved_spec->priority && | |
1983 | replace_equal)) { | |
1984 | if (ins_index < 0) | |
1985 | ins_index = i; | |
1986 | else | |
1987 | __set_bit(depth, mc_rem_map); | |
1988 | } | |
1989 | } | |
1990 | ||
1991 | /* Once we reach the maximum search depth, use | |
1992 | * the first suitable slot or return -EBUSY if | |
1993 | * there was none | |
1994 | */ | |
1995 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
1996 | if (ins_index < 0) { | |
1997 | rc = -EBUSY; | |
1998 | goto out_unlock; | |
1999 | } | |
2000 | goto found; | |
2001 | } | |
2002 | ||
2003 | ++depth; | |
2004 | } | |
2005 | ||
2006 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
2007 | spin_unlock_bh(&efx->filter_lock); | |
2008 | schedule(); | |
2009 | } | |
2010 | ||
2011 | found: | |
2012 | /* Create a software table entry if necessary, and mark it | |
2013 | * busy. We might yet fail to insert, but any attempt to | |
2014 | * insert a conflicting filter while we're waiting for the | |
2015 | * firmware must find the busy entry. | |
2016 | */ | |
2017 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2018 | if (saved_spec) { | |
2019 | if (spec->flags & EFX_FILTER_FLAG_RX_STACK) { | |
2020 | /* Just make sure it won't be removed */ | |
2021 | saved_spec->flags |= EFX_FILTER_FLAG_RX_STACK; | |
2022 | table->entry[ins_index].spec &= | |
2023 | ~EFX_EF10_FILTER_FLAG_STACK_OLD; | |
2024 | rc = ins_index; | |
2025 | goto out_unlock; | |
2026 | } | |
2027 | replacing = true; | |
2028 | priv_flags = efx_ef10_filter_entry_flags(table, ins_index); | |
2029 | } else { | |
2030 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
2031 | if (!saved_spec) { | |
2032 | rc = -ENOMEM; | |
2033 | goto out_unlock; | |
2034 | } | |
2035 | *saved_spec = *spec; | |
2036 | priv_flags = 0; | |
2037 | } | |
2038 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
2039 | priv_flags | EFX_EF10_FILTER_FLAG_BUSY); | |
2040 | ||
2041 | /* Mark lower-priority multicast recipients busy prior to removal */ | |
2042 | if (is_mc_recip) { | |
2043 | unsigned int depth, i; | |
2044 | ||
2045 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
2046 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2047 | if (test_bit(depth, mc_rem_map)) | |
2048 | table->entry[i].spec |= | |
2049 | EFX_EF10_FILTER_FLAG_BUSY; | |
2050 | } | |
2051 | } | |
2052 | ||
2053 | spin_unlock_bh(&efx->filter_lock); | |
2054 | ||
2055 | rc = efx_ef10_filter_push(efx, spec, &table->entry[ins_index].handle, | |
2056 | replacing); | |
2057 | ||
2058 | /* Finalise the software table entry */ | |
2059 | spin_lock_bh(&efx->filter_lock); | |
2060 | if (rc == 0) { | |
2061 | if (replacing) { | |
2062 | /* Update the fields that may differ */ | |
2063 | saved_spec->priority = spec->priority; | |
2064 | saved_spec->flags &= EFX_FILTER_FLAG_RX_STACK; | |
2065 | saved_spec->flags |= spec->flags; | |
2066 | saved_spec->rss_context = spec->rss_context; | |
2067 | saved_spec->dmaq_id = spec->dmaq_id; | |
2068 | } | |
2069 | } else if (!replacing) { | |
2070 | kfree(saved_spec); | |
2071 | saved_spec = NULL; | |
2072 | } | |
2073 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, priv_flags); | |
2074 | ||
2075 | /* Remove and finalise entries for lower-priority multicast | |
2076 | * recipients | |
2077 | */ | |
2078 | if (is_mc_recip) { | |
2079 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2080 | unsigned int depth, i; | |
2081 | ||
2082 | memset(inbuf, 0, sizeof(inbuf)); | |
2083 | ||
2084 | for (depth = 0; depth < EFX_EF10_FILTER_SEARCH_LIMIT; depth++) { | |
2085 | if (!test_bit(depth, mc_rem_map)) | |
2086 | continue; | |
2087 | ||
2088 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2089 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2090 | priv_flags = efx_ef10_filter_entry_flags(table, i); | |
2091 | ||
2092 | if (rc == 0) { | |
2093 | spin_unlock_bh(&efx->filter_lock); | |
2094 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2095 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
2096 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
2097 | table->entry[i].handle); | |
2098 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
2099 | inbuf, sizeof(inbuf), | |
2100 | NULL, 0, NULL); | |
2101 | spin_lock_bh(&efx->filter_lock); | |
2102 | } | |
2103 | ||
2104 | if (rc == 0) { | |
2105 | kfree(saved_spec); | |
2106 | saved_spec = NULL; | |
2107 | priv_flags = 0; | |
2108 | } else { | |
2109 | priv_flags &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
2110 | } | |
2111 | efx_ef10_filter_set_entry(table, i, saved_spec, | |
2112 | priv_flags); | |
2113 | } | |
2114 | } | |
2115 | ||
2116 | /* If successful, return the inserted filter ID */ | |
2117 | if (rc == 0) | |
2118 | rc = match_pri * HUNT_FILTER_TBL_ROWS + ins_index; | |
2119 | ||
2120 | wake_up_all(&table->waitq); | |
2121 | out_unlock: | |
2122 | spin_unlock_bh(&efx->filter_lock); | |
2123 | finish_wait(&table->waitq, &wait); | |
2124 | return rc; | |
2125 | } | |
2126 | ||
2127 | void efx_ef10_filter_update_rx_scatter(struct efx_nic *efx) | |
2128 | { | |
2129 | /* no need to do anything here on EF10 */ | |
2130 | } | |
2131 | ||
2132 | /* Remove a filter. | |
2133 | * If !stack_requested, remove by ID | |
2134 | * If stack_requested, remove by index | |
2135 | * Filter ID may come from userland and must be range-checked. | |
2136 | */ | |
2137 | static int efx_ef10_filter_remove_internal(struct efx_nic *efx, | |
2138 | enum efx_filter_priority priority, | |
2139 | u32 filter_id, bool stack_requested) | |
2140 | { | |
2141 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
2142 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2143 | MCDI_DECLARE_BUF(inbuf, | |
2144 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
2145 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
2146 | struct efx_filter_spec *spec; | |
2147 | DEFINE_WAIT(wait); | |
2148 | int rc; | |
2149 | ||
2150 | /* Find the software table entry and mark it busy. Don't | |
2151 | * remove it yet; any attempt to update while we're waiting | |
2152 | * for the firmware must find the busy entry. | |
2153 | */ | |
2154 | for (;;) { | |
2155 | spin_lock_bh(&efx->filter_lock); | |
2156 | if (!(table->entry[filter_idx].spec & | |
2157 | EFX_EF10_FILTER_FLAG_BUSY)) | |
2158 | break; | |
2159 | prepare_to_wait(&table->waitq, &wait, TASK_UNINTERRUPTIBLE); | |
2160 | spin_unlock_bh(&efx->filter_lock); | |
2161 | schedule(); | |
2162 | } | |
2163 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
2164 | if (!spec || spec->priority > priority || | |
2165 | (!stack_requested && | |
2166 | efx_ef10_filter_rx_match_pri(table, spec->match_flags) != | |
2167 | filter_id / HUNT_FILTER_TBL_ROWS)) { | |
2168 | rc = -ENOENT; | |
2169 | goto out_unlock; | |
2170 | } | |
2171 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
2172 | spin_unlock_bh(&efx->filter_lock); | |
2173 | ||
2174 | if (spec->flags & EFX_FILTER_FLAG_RX_STACK && !stack_requested) { | |
2175 | /* Reset steering of a stack-owned filter */ | |
2176 | ||
2177 | struct efx_filter_spec new_spec = *spec; | |
2178 | ||
2179 | new_spec.priority = EFX_FILTER_PRI_REQUIRED; | |
2180 | new_spec.flags = (EFX_FILTER_FLAG_RX | | |
2181 | EFX_FILTER_FLAG_RX_RSS | | |
2182 | EFX_FILTER_FLAG_RX_STACK); | |
2183 | new_spec.dmaq_id = 0; | |
2184 | new_spec.rss_context = EFX_FILTER_RSS_CONTEXT_DEFAULT; | |
2185 | rc = efx_ef10_filter_push(efx, &new_spec, | |
2186 | &table->entry[filter_idx].handle, | |
2187 | true); | |
2188 | ||
2189 | spin_lock_bh(&efx->filter_lock); | |
2190 | if (rc == 0) | |
2191 | *spec = new_spec; | |
2192 | } else { | |
2193 | /* Really remove the filter */ | |
2194 | ||
2195 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2196 | efx_ef10_filter_is_exclusive(spec) ? | |
2197 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
2198 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
2199 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
2200 | table->entry[filter_idx].handle); | |
2201 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, | |
2202 | inbuf, sizeof(inbuf), NULL, 0, NULL); | |
2203 | ||
2204 | spin_lock_bh(&efx->filter_lock); | |
2205 | if (rc == 0) { | |
2206 | kfree(spec); | |
2207 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
2208 | } | |
2209 | } | |
2210 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
2211 | wake_up_all(&table->waitq); | |
2212 | out_unlock: | |
2213 | spin_unlock_bh(&efx->filter_lock); | |
2214 | finish_wait(&table->waitq, &wait); | |
2215 | return rc; | |
2216 | } | |
2217 | ||
2218 | static int efx_ef10_filter_remove_safe(struct efx_nic *efx, | |
2219 | enum efx_filter_priority priority, | |
2220 | u32 filter_id) | |
2221 | { | |
2222 | return efx_ef10_filter_remove_internal(efx, priority, filter_id, false); | |
2223 | } | |
2224 | ||
2225 | static int efx_ef10_filter_get_safe(struct efx_nic *efx, | |
2226 | enum efx_filter_priority priority, | |
2227 | u32 filter_id, struct efx_filter_spec *spec) | |
2228 | { | |
2229 | unsigned int filter_idx = filter_id % HUNT_FILTER_TBL_ROWS; | |
2230 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2231 | const struct efx_filter_spec *saved_spec; | |
2232 | int rc; | |
2233 | ||
2234 | spin_lock_bh(&efx->filter_lock); | |
2235 | saved_spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
2236 | if (saved_spec && saved_spec->priority == priority && | |
2237 | efx_ef10_filter_rx_match_pri(table, saved_spec->match_flags) == | |
2238 | filter_id / HUNT_FILTER_TBL_ROWS) { | |
2239 | *spec = *saved_spec; | |
2240 | rc = 0; | |
2241 | } else { | |
2242 | rc = -ENOENT; | |
2243 | } | |
2244 | spin_unlock_bh(&efx->filter_lock); | |
2245 | return rc; | |
2246 | } | |
2247 | ||
2248 | static void efx_ef10_filter_clear_rx(struct efx_nic *efx, | |
2249 | enum efx_filter_priority priority) | |
2250 | { | |
2251 | /* TODO */ | |
2252 | } | |
2253 | ||
2254 | static u32 efx_ef10_filter_count_rx_used(struct efx_nic *efx, | |
2255 | enum efx_filter_priority priority) | |
2256 | { | |
2257 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2258 | unsigned int filter_idx; | |
2259 | s32 count = 0; | |
2260 | ||
2261 | spin_lock_bh(&efx->filter_lock); | |
2262 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
2263 | if (table->entry[filter_idx].spec && | |
2264 | efx_ef10_filter_entry_spec(table, filter_idx)->priority == | |
2265 | priority) | |
2266 | ++count; | |
2267 | } | |
2268 | spin_unlock_bh(&efx->filter_lock); | |
2269 | return count; | |
2270 | } | |
2271 | ||
2272 | static u32 efx_ef10_filter_get_rx_id_limit(struct efx_nic *efx) | |
2273 | { | |
2274 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2275 | ||
2276 | return table->rx_match_count * HUNT_FILTER_TBL_ROWS; | |
2277 | } | |
2278 | ||
2279 | static s32 efx_ef10_filter_get_rx_ids(struct efx_nic *efx, | |
2280 | enum efx_filter_priority priority, | |
2281 | u32 *buf, u32 size) | |
2282 | { | |
2283 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2284 | struct efx_filter_spec *spec; | |
2285 | unsigned int filter_idx; | |
2286 | s32 count = 0; | |
2287 | ||
2288 | spin_lock_bh(&efx->filter_lock); | |
2289 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
2290 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
2291 | if (spec && spec->priority == priority) { | |
2292 | if (count == size) { | |
2293 | count = -EMSGSIZE; | |
2294 | break; | |
2295 | } | |
2296 | buf[count++] = (efx_ef10_filter_rx_match_pri( | |
2297 | table, spec->match_flags) * | |
2298 | HUNT_FILTER_TBL_ROWS + | |
2299 | filter_idx); | |
2300 | } | |
2301 | } | |
2302 | spin_unlock_bh(&efx->filter_lock); | |
2303 | return count; | |
2304 | } | |
2305 | ||
2306 | #ifdef CONFIG_RFS_ACCEL | |
2307 | ||
2308 | static efx_mcdi_async_completer efx_ef10_filter_rfs_insert_complete; | |
2309 | ||
2310 | static s32 efx_ef10_filter_rfs_insert(struct efx_nic *efx, | |
2311 | struct efx_filter_spec *spec) | |
2312 | { | |
2313 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2314 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2315 | struct efx_filter_spec *saved_spec; | |
2316 | unsigned int hash, i, depth = 1; | |
2317 | bool replacing = false; | |
2318 | int ins_index = -1; | |
2319 | u64 cookie; | |
2320 | s32 rc; | |
2321 | ||
2322 | /* Must be an RX filter without RSS and not for a multicast | |
2323 | * destination address (RFS only works for connected sockets). | |
2324 | * These restrictions allow us to pass only a tiny amount of | |
2325 | * data through to the completion function. | |
2326 | */ | |
2327 | EFX_WARN_ON_PARANOID(spec->flags != | |
2328 | (EFX_FILTER_FLAG_RX | EFX_FILTER_FLAG_RX_SCATTER)); | |
2329 | EFX_WARN_ON_PARANOID(spec->priority != EFX_FILTER_PRI_HINT); | |
2330 | EFX_WARN_ON_PARANOID(efx_filter_is_mc_recipient(spec)); | |
2331 | ||
2332 | hash = efx_ef10_filter_hash(spec); | |
2333 | ||
2334 | spin_lock_bh(&efx->filter_lock); | |
2335 | ||
2336 | /* Find any existing filter with the same match tuple or else | |
2337 | * a free slot to insert at. If an existing filter is busy, | |
2338 | * we have to give up. | |
2339 | */ | |
2340 | for (;;) { | |
2341 | i = (hash + depth) & (HUNT_FILTER_TBL_ROWS - 1); | |
2342 | saved_spec = efx_ef10_filter_entry_spec(table, i); | |
2343 | ||
2344 | if (!saved_spec) { | |
2345 | if (ins_index < 0) | |
2346 | ins_index = i; | |
2347 | } else if (efx_ef10_filter_equal(spec, saved_spec)) { | |
2348 | if (table->entry[i].spec & EFX_EF10_FILTER_FLAG_BUSY) { | |
2349 | rc = -EBUSY; | |
2350 | goto fail_unlock; | |
2351 | } | |
2352 | EFX_WARN_ON_PARANOID(saved_spec->flags & | |
2353 | EFX_FILTER_FLAG_RX_STACK); | |
2354 | if (spec->priority < saved_spec->priority) { | |
2355 | rc = -EPERM; | |
2356 | goto fail_unlock; | |
2357 | } | |
2358 | ins_index = i; | |
2359 | break; | |
2360 | } | |
2361 | ||
2362 | /* Once we reach the maximum search depth, use the | |
2363 | * first suitable slot or return -EBUSY if there was | |
2364 | * none | |
2365 | */ | |
2366 | if (depth == EFX_EF10_FILTER_SEARCH_LIMIT) { | |
2367 | if (ins_index < 0) { | |
2368 | rc = -EBUSY; | |
2369 | goto fail_unlock; | |
2370 | } | |
2371 | break; | |
2372 | } | |
2373 | ||
2374 | ++depth; | |
2375 | } | |
2376 | ||
2377 | /* Create a software table entry if necessary, and mark it | |
2378 | * busy. We might yet fail to insert, but any attempt to | |
2379 | * insert a conflicting filter while we're waiting for the | |
2380 | * firmware must find the busy entry. | |
2381 | */ | |
2382 | saved_spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2383 | if (saved_spec) { | |
2384 | replacing = true; | |
2385 | } else { | |
2386 | saved_spec = kmalloc(sizeof(*spec), GFP_ATOMIC); | |
2387 | if (!saved_spec) { | |
2388 | rc = -ENOMEM; | |
2389 | goto fail_unlock; | |
2390 | } | |
2391 | *saved_spec = *spec; | |
2392 | } | |
2393 | efx_ef10_filter_set_entry(table, ins_index, saved_spec, | |
2394 | EFX_EF10_FILTER_FLAG_BUSY); | |
2395 | ||
2396 | spin_unlock_bh(&efx->filter_lock); | |
2397 | ||
2398 | /* Pack up the variables needed on completion */ | |
2399 | cookie = replacing << 31 | ins_index << 16 | spec->dmaq_id; | |
2400 | ||
2401 | efx_ef10_filter_push_prep(efx, spec, inbuf, | |
2402 | table->entry[ins_index].handle, replacing); | |
2403 | efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
2404 | MC_CMD_FILTER_OP_OUT_LEN, | |
2405 | efx_ef10_filter_rfs_insert_complete, cookie); | |
2406 | ||
2407 | return ins_index; | |
2408 | ||
2409 | fail_unlock: | |
2410 | spin_unlock_bh(&efx->filter_lock); | |
2411 | return rc; | |
2412 | } | |
2413 | ||
2414 | static void | |
2415 | efx_ef10_filter_rfs_insert_complete(struct efx_nic *efx, unsigned long cookie, | |
2416 | int rc, efx_dword_t *outbuf, | |
2417 | size_t outlen_actual) | |
2418 | { | |
2419 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2420 | unsigned int ins_index, dmaq_id; | |
2421 | struct efx_filter_spec *spec; | |
2422 | bool replacing; | |
2423 | ||
2424 | /* Unpack the cookie */ | |
2425 | replacing = cookie >> 31; | |
2426 | ins_index = (cookie >> 16) & (HUNT_FILTER_TBL_ROWS - 1); | |
2427 | dmaq_id = cookie & 0xffff; | |
2428 | ||
2429 | spin_lock_bh(&efx->filter_lock); | |
2430 | spec = efx_ef10_filter_entry_spec(table, ins_index); | |
2431 | if (rc == 0) { | |
2432 | table->entry[ins_index].handle = | |
2433 | MCDI_QWORD(outbuf, FILTER_OP_OUT_HANDLE); | |
2434 | if (replacing) | |
2435 | spec->dmaq_id = dmaq_id; | |
2436 | } else if (!replacing) { | |
2437 | kfree(spec); | |
2438 | spec = NULL; | |
2439 | } | |
2440 | efx_ef10_filter_set_entry(table, ins_index, spec, 0); | |
2441 | spin_unlock_bh(&efx->filter_lock); | |
2442 | ||
2443 | wake_up_all(&table->waitq); | |
2444 | } | |
2445 | ||
2446 | static void | |
2447 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
2448 | unsigned long filter_idx, | |
2449 | int rc, efx_dword_t *outbuf, | |
2450 | size_t outlen_actual); | |
2451 | ||
2452 | static bool efx_ef10_filter_rfs_expire_one(struct efx_nic *efx, u32 flow_id, | |
2453 | unsigned int filter_idx) | |
2454 | { | |
2455 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2456 | struct efx_filter_spec *spec = | |
2457 | efx_ef10_filter_entry_spec(table, filter_idx); | |
2458 | MCDI_DECLARE_BUF(inbuf, | |
2459 | MC_CMD_FILTER_OP_IN_HANDLE_OFST + | |
2460 | MC_CMD_FILTER_OP_IN_HANDLE_LEN); | |
2461 | ||
2462 | if (!spec || | |
2463 | (table->entry[filter_idx].spec & EFX_EF10_FILTER_FLAG_BUSY) || | |
2464 | spec->priority != EFX_FILTER_PRI_HINT || | |
2465 | !rps_may_expire_flow(efx->net_dev, spec->dmaq_id, | |
2466 | flow_id, filter_idx)) | |
2467 | return false; | |
2468 | ||
2469 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2470 | MC_CMD_FILTER_OP_IN_OP_REMOVE); | |
2471 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
2472 | table->entry[filter_idx].handle); | |
2473 | if (efx_mcdi_rpc_async(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), 0, | |
2474 | efx_ef10_filter_rfs_expire_complete, filter_idx)) | |
2475 | return false; | |
2476 | ||
2477 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
2478 | return true; | |
2479 | } | |
2480 | ||
2481 | static void | |
2482 | efx_ef10_filter_rfs_expire_complete(struct efx_nic *efx, | |
2483 | unsigned long filter_idx, | |
2484 | int rc, efx_dword_t *outbuf, | |
2485 | size_t outlen_actual) | |
2486 | { | |
2487 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2488 | struct efx_filter_spec *spec = | |
2489 | efx_ef10_filter_entry_spec(table, filter_idx); | |
2490 | ||
2491 | spin_lock_bh(&efx->filter_lock); | |
2492 | if (rc == 0) { | |
2493 | kfree(spec); | |
2494 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
2495 | } | |
2496 | table->entry[filter_idx].spec &= ~EFX_EF10_FILTER_FLAG_BUSY; | |
2497 | wake_up_all(&table->waitq); | |
2498 | spin_unlock_bh(&efx->filter_lock); | |
2499 | } | |
2500 | ||
2501 | #endif /* CONFIG_RFS_ACCEL */ | |
2502 | ||
2503 | static int efx_ef10_filter_match_flags_from_mcdi(u32 mcdi_flags) | |
2504 | { | |
2505 | int match_flags = 0; | |
2506 | ||
2507 | #define MAP_FLAG(gen_flag, mcdi_field) { \ | |
2508 | u32 old_mcdi_flags = mcdi_flags; \ | |
2509 | mcdi_flags &= ~(1 << MC_CMD_FILTER_OP_IN_MATCH_ ## \ | |
2510 | mcdi_field ## _LBN); \ | |
2511 | if (mcdi_flags != old_mcdi_flags) \ | |
2512 | match_flags |= EFX_FILTER_MATCH_ ## gen_flag; \ | |
2513 | } | |
2514 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_UCAST_DST); | |
2515 | MAP_FLAG(LOC_MAC_IG, UNKNOWN_MCAST_DST); | |
2516 | MAP_FLAG(REM_HOST, SRC_IP); | |
2517 | MAP_FLAG(LOC_HOST, DST_IP); | |
2518 | MAP_FLAG(REM_MAC, SRC_MAC); | |
2519 | MAP_FLAG(REM_PORT, SRC_PORT); | |
2520 | MAP_FLAG(LOC_MAC, DST_MAC); | |
2521 | MAP_FLAG(LOC_PORT, DST_PORT); | |
2522 | MAP_FLAG(ETHER_TYPE, ETHER_TYPE); | |
2523 | MAP_FLAG(INNER_VID, INNER_VLAN); | |
2524 | MAP_FLAG(OUTER_VID, OUTER_VLAN); | |
2525 | MAP_FLAG(IP_PROTO, IP_PROTO); | |
2526 | #undef MAP_FLAG | |
2527 | ||
2528 | /* Did we map them all? */ | |
2529 | if (mcdi_flags) | |
2530 | return -EINVAL; | |
2531 | ||
2532 | return match_flags; | |
2533 | } | |
2534 | ||
2535 | static int efx_ef10_filter_table_probe(struct efx_nic *efx) | |
2536 | { | |
2537 | MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_PARSER_DISP_INFO_IN_LEN); | |
2538 | MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_PARSER_DISP_INFO_OUT_LENMAX); | |
2539 | unsigned int pd_match_pri, pd_match_count; | |
2540 | struct efx_ef10_filter_table *table; | |
2541 | size_t outlen; | |
2542 | int rc; | |
2543 | ||
2544 | table = kzalloc(sizeof(*table), GFP_KERNEL); | |
2545 | if (!table) | |
2546 | return -ENOMEM; | |
2547 | ||
2548 | /* Find out which RX filter types are supported, and their priorities */ | |
2549 | MCDI_SET_DWORD(inbuf, GET_PARSER_DISP_INFO_IN_OP, | |
2550 | MC_CMD_GET_PARSER_DISP_INFO_IN_OP_GET_SUPPORTED_RX_MATCHES); | |
2551 | rc = efx_mcdi_rpc(efx, MC_CMD_GET_PARSER_DISP_INFO, | |
2552 | inbuf, sizeof(inbuf), outbuf, sizeof(outbuf), | |
2553 | &outlen); | |
2554 | if (rc) | |
2555 | goto fail; | |
2556 | pd_match_count = MCDI_VAR_ARRAY_LEN( | |
2557 | outlen, GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES); | |
2558 | table->rx_match_count = 0; | |
2559 | ||
2560 | for (pd_match_pri = 0; pd_match_pri < pd_match_count; pd_match_pri++) { | |
2561 | u32 mcdi_flags = | |
2562 | MCDI_ARRAY_DWORD( | |
2563 | outbuf, | |
2564 | GET_PARSER_DISP_INFO_OUT_SUPPORTED_MATCHES, | |
2565 | pd_match_pri); | |
2566 | rc = efx_ef10_filter_match_flags_from_mcdi(mcdi_flags); | |
2567 | if (rc < 0) { | |
2568 | netif_dbg(efx, probe, efx->net_dev, | |
2569 | "%s: fw flags %#x pri %u not supported in driver\n", | |
2570 | __func__, mcdi_flags, pd_match_pri); | |
2571 | } else { | |
2572 | netif_dbg(efx, probe, efx->net_dev, | |
2573 | "%s: fw flags %#x pri %u supported as driver flags %#x pri %u\n", | |
2574 | __func__, mcdi_flags, pd_match_pri, | |
2575 | rc, table->rx_match_count); | |
2576 | table->rx_match_flags[table->rx_match_count++] = rc; | |
2577 | } | |
2578 | } | |
2579 | ||
2580 | table->entry = vzalloc(HUNT_FILTER_TBL_ROWS * sizeof(*table->entry)); | |
2581 | if (!table->entry) { | |
2582 | rc = -ENOMEM; | |
2583 | goto fail; | |
2584 | } | |
2585 | ||
2586 | efx->filter_state = table; | |
2587 | init_waitqueue_head(&table->waitq); | |
2588 | return 0; | |
2589 | ||
2590 | fail: | |
2591 | kfree(table); | |
2592 | return rc; | |
2593 | } | |
2594 | ||
2595 | static void efx_ef10_filter_table_restore(struct efx_nic *efx) | |
2596 | { | |
2597 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2598 | struct efx_ef10_nic_data *nic_data = efx->nic_data; | |
2599 | struct efx_filter_spec *spec; | |
2600 | unsigned int filter_idx; | |
2601 | bool failed = false; | |
2602 | int rc; | |
2603 | ||
2604 | if (!nic_data->must_restore_filters) | |
2605 | return; | |
2606 | ||
2607 | spin_lock_bh(&efx->filter_lock); | |
2608 | ||
2609 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
2610 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
2611 | if (!spec) | |
2612 | continue; | |
2613 | ||
2614 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_BUSY; | |
2615 | spin_unlock_bh(&efx->filter_lock); | |
2616 | ||
2617 | rc = efx_ef10_filter_push(efx, spec, | |
2618 | &table->entry[filter_idx].handle, | |
2619 | false); | |
2620 | if (rc) | |
2621 | failed = true; | |
2622 | ||
2623 | spin_lock_bh(&efx->filter_lock); | |
2624 | if (rc) { | |
2625 | kfree(spec); | |
2626 | efx_ef10_filter_set_entry(table, filter_idx, NULL, 0); | |
2627 | } else { | |
2628 | table->entry[filter_idx].spec &= | |
2629 | ~EFX_EF10_FILTER_FLAG_BUSY; | |
2630 | } | |
2631 | } | |
2632 | ||
2633 | spin_unlock_bh(&efx->filter_lock); | |
2634 | ||
2635 | if (failed) | |
2636 | netif_err(efx, hw, efx->net_dev, | |
2637 | "unable to restore all filters\n"); | |
2638 | else | |
2639 | nic_data->must_restore_filters = false; | |
2640 | } | |
2641 | ||
2642 | static void efx_ef10_filter_table_remove(struct efx_nic *efx) | |
2643 | { | |
2644 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2645 | MCDI_DECLARE_BUF(inbuf, MC_CMD_FILTER_OP_IN_LEN); | |
2646 | struct efx_filter_spec *spec; | |
2647 | unsigned int filter_idx; | |
2648 | int rc; | |
2649 | ||
2650 | for (filter_idx = 0; filter_idx < HUNT_FILTER_TBL_ROWS; filter_idx++) { | |
2651 | spec = efx_ef10_filter_entry_spec(table, filter_idx); | |
2652 | if (!spec) | |
2653 | continue; | |
2654 | ||
2655 | MCDI_SET_DWORD(inbuf, FILTER_OP_IN_OP, | |
2656 | efx_ef10_filter_is_exclusive(spec) ? | |
2657 | MC_CMD_FILTER_OP_IN_OP_REMOVE : | |
2658 | MC_CMD_FILTER_OP_IN_OP_UNSUBSCRIBE); | |
2659 | MCDI_SET_QWORD(inbuf, FILTER_OP_IN_HANDLE, | |
2660 | table->entry[filter_idx].handle); | |
2661 | rc = efx_mcdi_rpc(efx, MC_CMD_FILTER_OP, inbuf, sizeof(inbuf), | |
2662 | NULL, 0, NULL); | |
2663 | ||
2664 | WARN_ON(rc != 0); | |
2665 | kfree(spec); | |
2666 | } | |
2667 | ||
2668 | vfree(table->entry); | |
2669 | kfree(table); | |
2670 | } | |
2671 | ||
2672 | static void efx_ef10_filter_sync_rx_mode(struct efx_nic *efx) | |
2673 | { | |
2674 | struct efx_ef10_filter_table *table = efx->filter_state; | |
2675 | struct net_device *net_dev = efx->net_dev; | |
2676 | struct efx_filter_spec spec; | |
2677 | bool remove_failed = false; | |
2678 | struct netdev_hw_addr *uc; | |
2679 | struct netdev_hw_addr *mc; | |
2680 | unsigned int filter_idx; | |
2681 | int i, n, rc; | |
2682 | ||
2683 | if (!efx_dev_registered(efx)) | |
2684 | return; | |
2685 | ||
2686 | /* Mark old filters that may need to be removed */ | |
2687 | spin_lock_bh(&efx->filter_lock); | |
2688 | n = table->stack_uc_count < 0 ? 1 : table->stack_uc_count; | |
2689 | for (i = 0; i < n; i++) { | |
2690 | filter_idx = table->stack_uc_list[i].id % HUNT_FILTER_TBL_ROWS; | |
2691 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_STACK_OLD; | |
2692 | } | |
2693 | n = table->stack_mc_count < 0 ? 1 : table->stack_mc_count; | |
2694 | for (i = 0; i < n; i++) { | |
2695 | filter_idx = table->stack_mc_list[i].id % HUNT_FILTER_TBL_ROWS; | |
2696 | table->entry[filter_idx].spec |= EFX_EF10_FILTER_FLAG_STACK_OLD; | |
2697 | } | |
2698 | spin_unlock_bh(&efx->filter_lock); | |
2699 | ||
2700 | /* Copy/convert the address lists; add the primary station | |
2701 | * address and broadcast address | |
2702 | */ | |
2703 | netif_addr_lock_bh(net_dev); | |
2704 | if (net_dev->flags & IFF_PROMISC || | |
2705 | netdev_uc_count(net_dev) >= EFX_EF10_FILTER_STACK_UC_MAX) { | |
2706 | table->stack_uc_count = -1; | |
2707 | } else { | |
2708 | table->stack_uc_count = 1 + netdev_uc_count(net_dev); | |
2709 | memcpy(table->stack_uc_list[0].addr, net_dev->dev_addr, | |
2710 | ETH_ALEN); | |
2711 | i = 1; | |
2712 | netdev_for_each_uc_addr(uc, net_dev) { | |
2713 | memcpy(table->stack_uc_list[i].addr, | |
2714 | uc->addr, ETH_ALEN); | |
2715 | i++; | |
2716 | } | |
2717 | } | |
2718 | if (net_dev->flags & (IFF_PROMISC | IFF_ALLMULTI) || | |
2719 | netdev_mc_count(net_dev) >= EFX_EF10_FILTER_STACK_MC_MAX) { | |
2720 | table->stack_mc_count = -1; | |
2721 | } else { | |
2722 | table->stack_mc_count = 1 + netdev_mc_count(net_dev); | |
2723 | eth_broadcast_addr(table->stack_mc_list[0].addr); | |
2724 | i = 1; | |
2725 | netdev_for_each_mc_addr(mc, net_dev) { | |
2726 | memcpy(table->stack_mc_list[i].addr, | |
2727 | mc->addr, ETH_ALEN); | |
2728 | i++; | |
2729 | } | |
2730 | } | |
2731 | netif_addr_unlock_bh(net_dev); | |
2732 | ||
2733 | /* Insert/renew unicast filters */ | |
2734 | if (table->stack_uc_count >= 0) { | |
2735 | for (i = 0; i < table->stack_uc_count; i++) { | |
2736 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_REQUIRED, | |
2737 | EFX_FILTER_FLAG_RX_RSS | | |
2738 | EFX_FILTER_FLAG_RX_STACK, | |
2739 | 0); | |
2740 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
2741 | table->stack_uc_list[i].addr); | |
2742 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
2743 | if (rc < 0) { | |
2744 | /* Fall back to unicast-promisc */ | |
2745 | while (i--) | |
2746 | efx_ef10_filter_remove_safe( | |
2747 | efx, EFX_FILTER_PRI_REQUIRED, | |
2748 | table->stack_uc_list[i].id); | |
2749 | table->stack_uc_count = -1; | |
2750 | break; | |
2751 | } | |
2752 | table->stack_uc_list[i].id = rc; | |
2753 | } | |
2754 | } | |
2755 | if (table->stack_uc_count < 0) { | |
2756 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_REQUIRED, | |
2757 | EFX_FILTER_FLAG_RX_RSS | | |
2758 | EFX_FILTER_FLAG_RX_STACK, | |
2759 | 0); | |
2760 | efx_filter_set_uc_def(&spec); | |
2761 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
2762 | if (rc < 0) { | |
2763 | WARN_ON(1); | |
2764 | table->stack_uc_count = 0; | |
2765 | } else { | |
2766 | table->stack_uc_list[0].id = rc; | |
2767 | } | |
2768 | } | |
2769 | ||
2770 | /* Insert/renew multicast filters */ | |
2771 | if (table->stack_mc_count >= 0) { | |
2772 | for (i = 0; i < table->stack_mc_count; i++) { | |
2773 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_REQUIRED, | |
2774 | EFX_FILTER_FLAG_RX_RSS | | |
2775 | EFX_FILTER_FLAG_RX_STACK, | |
2776 | 0); | |
2777 | efx_filter_set_eth_local(&spec, EFX_FILTER_VID_UNSPEC, | |
2778 | table->stack_mc_list[i].addr); | |
2779 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
2780 | if (rc < 0) { | |
2781 | /* Fall back to multicast-promisc */ | |
2782 | while (i--) | |
2783 | efx_ef10_filter_remove_safe( | |
2784 | efx, EFX_FILTER_PRI_REQUIRED, | |
2785 | table->stack_mc_list[i].id); | |
2786 | table->stack_mc_count = -1; | |
2787 | break; | |
2788 | } | |
2789 | table->stack_mc_list[i].id = rc; | |
2790 | } | |
2791 | } | |
2792 | if (table->stack_mc_count < 0) { | |
2793 | efx_filter_init_rx(&spec, EFX_FILTER_PRI_REQUIRED, | |
2794 | EFX_FILTER_FLAG_RX_RSS | | |
2795 | EFX_FILTER_FLAG_RX_STACK, | |
2796 | 0); | |
2797 | efx_filter_set_mc_def(&spec); | |
2798 | rc = efx_ef10_filter_insert(efx, &spec, true); | |
2799 | if (rc < 0) { | |
2800 | WARN_ON(1); | |
2801 | table->stack_mc_count = 0; | |
2802 | } else { | |
2803 | table->stack_mc_list[0].id = rc; | |
2804 | } | |
2805 | } | |
2806 | ||
2807 | /* Remove filters that weren't renewed. Since nothing else | |
2808 | * changes the STACK_OLD flag or removes these filters, we | |
2809 | * don't need to hold the filter_lock while scanning for | |
2810 | * these filters. | |
2811 | */ | |
2812 | for (i = 0; i < HUNT_FILTER_TBL_ROWS; i++) { | |
2813 | if (ACCESS_ONCE(table->entry[i].spec) & | |
2814 | EFX_EF10_FILTER_FLAG_STACK_OLD) { | |
2815 | if (efx_ef10_filter_remove_internal(efx, | |
2816 | EFX_FILTER_PRI_REQUIRED, | |
2817 | i, true) < 0) | |
2818 | remove_failed = true; | |
2819 | } | |
2820 | } | |
2821 | WARN_ON(remove_failed); | |
2822 | } | |
2823 | ||
2824 | static int efx_ef10_mac_reconfigure(struct efx_nic *efx) | |
2825 | { | |
2826 | efx_ef10_filter_sync_rx_mode(efx); | |
2827 | ||
2828 | return efx_mcdi_set_mac(efx); | |
2829 | } | |
2830 | ||
2831 | #ifdef CONFIG_SFC_MTD | |
2832 | ||
2833 | struct efx_ef10_nvram_type_info { | |
2834 | u16 type, type_mask; | |
2835 | u8 port; | |
2836 | const char *name; | |
2837 | }; | |
2838 | ||
2839 | static const struct efx_ef10_nvram_type_info efx_ef10_nvram_types[] = { | |
2840 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE, 0, 0, "sfc_mcfw" }, | |
2841 | { NVRAM_PARTITION_TYPE_MC_FIRMWARE_BACKUP, 0, 0, "sfc_mcfw_backup" }, | |
2842 | { NVRAM_PARTITION_TYPE_EXPANSION_ROM, 0, 0, "sfc_exp_rom" }, | |
2843 | { NVRAM_PARTITION_TYPE_STATIC_CONFIG, 0, 0, "sfc_static_cfg" }, | |
2844 | { NVRAM_PARTITION_TYPE_DYNAMIC_CONFIG, 0, 0, "sfc_dynamic_cfg" }, | |
2845 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT0, 0, 0, "sfc_exp_rom_cfg" }, | |
2846 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT1, 0, 1, "sfc_exp_rom_cfg" }, | |
2847 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT2, 0, 2, "sfc_exp_rom_cfg" }, | |
2848 | { NVRAM_PARTITION_TYPE_EXPROM_CONFIG_PORT3, 0, 3, "sfc_exp_rom_cfg" }, | |
2849 | { NVRAM_PARTITION_TYPE_PHY_MIN, 0xff, 0, "sfc_phy_fw" }, | |
2850 | }; | |
2851 | ||
2852 | static int efx_ef10_mtd_probe_partition(struct efx_nic *efx, | |
2853 | struct efx_mcdi_mtd_partition *part, | |
2854 | unsigned int type) | |
2855 | { | |
2856 | MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_METADATA_IN_LEN); | |
2857 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_METADATA_OUT_LENMAX); | |
2858 | const struct efx_ef10_nvram_type_info *info; | |
2859 | size_t size, erase_size, outlen; | |
2860 | bool protected; | |
2861 | int rc; | |
2862 | ||
2863 | for (info = efx_ef10_nvram_types; ; info++) { | |
2864 | if (info == | |
2865 | efx_ef10_nvram_types + ARRAY_SIZE(efx_ef10_nvram_types)) | |
2866 | return -ENODEV; | |
2867 | if ((type & ~info->type_mask) == info->type) | |
2868 | break; | |
2869 | } | |
2870 | if (info->port != efx_port_num(efx)) | |
2871 | return -ENODEV; | |
2872 | ||
2873 | rc = efx_mcdi_nvram_info(efx, type, &size, &erase_size, &protected); | |
2874 | if (rc) | |
2875 | return rc; | |
2876 | if (protected) | |
2877 | return -ENODEV; /* hide it */ | |
2878 | ||
2879 | part->nvram_type = type; | |
2880 | ||
2881 | MCDI_SET_DWORD(inbuf, NVRAM_METADATA_IN_TYPE, type); | |
2882 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_METADATA, inbuf, sizeof(inbuf), | |
2883 | outbuf, sizeof(outbuf), &outlen); | |
2884 | if (rc) | |
2885 | return rc; | |
2886 | if (outlen < MC_CMD_NVRAM_METADATA_OUT_LENMIN) | |
2887 | return -EIO; | |
2888 | if (MCDI_DWORD(outbuf, NVRAM_METADATA_OUT_FLAGS) & | |
2889 | (1 << MC_CMD_NVRAM_METADATA_OUT_SUBTYPE_VALID_LBN)) | |
2890 | part->fw_subtype = MCDI_DWORD(outbuf, | |
2891 | NVRAM_METADATA_OUT_SUBTYPE); | |
2892 | ||
2893 | part->common.dev_type_name = "EF10 NVRAM manager"; | |
2894 | part->common.type_name = info->name; | |
2895 | ||
2896 | part->common.mtd.type = MTD_NORFLASH; | |
2897 | part->common.mtd.flags = MTD_CAP_NORFLASH; | |
2898 | part->common.mtd.size = size; | |
2899 | part->common.mtd.erasesize = erase_size; | |
2900 | ||
2901 | return 0; | |
2902 | } | |
2903 | ||
2904 | static int efx_ef10_mtd_probe(struct efx_nic *efx) | |
2905 | { | |
2906 | MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_PARTITIONS_OUT_LENMAX); | |
2907 | struct efx_mcdi_mtd_partition *parts; | |
2908 | size_t outlen, n_parts_total, i, n_parts; | |
2909 | unsigned int type; | |
2910 | int rc; | |
2911 | ||
2912 | ASSERT_RTNL(); | |
2913 | ||
2914 | BUILD_BUG_ON(MC_CMD_NVRAM_PARTITIONS_IN_LEN != 0); | |
2915 | rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_PARTITIONS, NULL, 0, | |
2916 | outbuf, sizeof(outbuf), &outlen); | |
2917 | if (rc) | |
2918 | return rc; | |
2919 | if (outlen < MC_CMD_NVRAM_PARTITIONS_OUT_LENMIN) | |
2920 | return -EIO; | |
2921 | ||
2922 | n_parts_total = MCDI_DWORD(outbuf, NVRAM_PARTITIONS_OUT_NUM_PARTITIONS); | |
2923 | if (n_parts_total > | |
2924 | MCDI_VAR_ARRAY_LEN(outlen, NVRAM_PARTITIONS_OUT_TYPE_ID)) | |
2925 | return -EIO; | |
2926 | ||
2927 | parts = kcalloc(n_parts_total, sizeof(*parts), GFP_KERNEL); | |
2928 | if (!parts) | |
2929 | return -ENOMEM; | |
2930 | ||
2931 | n_parts = 0; | |
2932 | for (i = 0; i < n_parts_total; i++) { | |
2933 | type = MCDI_ARRAY_DWORD(outbuf, NVRAM_PARTITIONS_OUT_TYPE_ID, | |
2934 | i); | |
2935 | rc = efx_ef10_mtd_probe_partition(efx, &parts[n_parts], type); | |
2936 | if (rc == 0) | |
2937 | n_parts++; | |
2938 | else if (rc != -ENODEV) | |
2939 | goto fail; | |
2940 | } | |
2941 | ||
2942 | rc = efx_mtd_add(efx, &parts[0].common, n_parts, sizeof(*parts)); | |
2943 | fail: | |
2944 | if (rc) | |
2945 | kfree(parts); | |
2946 | return rc; | |
2947 | } | |
2948 | ||
2949 | #endif /* CONFIG_SFC_MTD */ | |
2950 | ||
2951 | static void efx_ef10_ptp_write_host_time(struct efx_nic *efx, u32 host_time) | |
2952 | { | |
2953 | _efx_writed(efx, cpu_to_le32(host_time), ER_DZ_MC_DB_LWRD); | |
2954 | } | |
2955 | ||
2956 | const struct efx_nic_type efx_hunt_a0_nic_type = { | |
2957 | .mem_map_size = efx_ef10_mem_map_size, | |
2958 | .probe = efx_ef10_probe, | |
2959 | .remove = efx_ef10_remove, | |
2960 | .dimension_resources = efx_ef10_dimension_resources, | |
2961 | .init = efx_ef10_init_nic, | |
2962 | .fini = efx_port_dummy_op_void, | |
2963 | .map_reset_reason = efx_mcdi_map_reset_reason, | |
2964 | .map_reset_flags = efx_ef10_map_reset_flags, | |
2965 | .reset = efx_mcdi_reset, | |
2966 | .probe_port = efx_mcdi_port_probe, | |
2967 | .remove_port = efx_mcdi_port_remove, | |
2968 | .fini_dmaq = efx_ef10_fini_dmaq, | |
2969 | .describe_stats = efx_ef10_describe_stats, | |
2970 | .update_stats = efx_ef10_update_stats, | |
2971 | .start_stats = efx_mcdi_mac_start_stats, | |
2972 | .stop_stats = efx_mcdi_mac_stop_stats, | |
2973 | .set_id_led = efx_mcdi_set_id_led, | |
2974 | .push_irq_moderation = efx_ef10_push_irq_moderation, | |
2975 | .reconfigure_mac = efx_ef10_mac_reconfigure, | |
2976 | .check_mac_fault = efx_mcdi_mac_check_fault, | |
2977 | .reconfigure_port = efx_mcdi_port_reconfigure, | |
2978 | .get_wol = efx_ef10_get_wol, | |
2979 | .set_wol = efx_ef10_set_wol, | |
2980 | .resume_wol = efx_port_dummy_op_void, | |
2981 | /* TODO: test_chip */ | |
2982 | .test_nvram = efx_mcdi_nvram_test_all, | |
2983 | .mcdi_request = efx_ef10_mcdi_request, | |
2984 | .mcdi_poll_response = efx_ef10_mcdi_poll_response, | |
2985 | .mcdi_read_response = efx_ef10_mcdi_read_response, | |
2986 | .mcdi_poll_reboot = efx_ef10_mcdi_poll_reboot, | |
2987 | .irq_enable_master = efx_port_dummy_op_void, | |
2988 | .irq_test_generate = efx_ef10_irq_test_generate, | |
2989 | .irq_disable_non_ev = efx_port_dummy_op_void, | |
2990 | .irq_handle_msi = efx_ef10_msi_interrupt, | |
2991 | .irq_handle_legacy = efx_ef10_legacy_interrupt, | |
2992 | .tx_probe = efx_ef10_tx_probe, | |
2993 | .tx_init = efx_ef10_tx_init, | |
2994 | .tx_remove = efx_ef10_tx_remove, | |
2995 | .tx_write = efx_ef10_tx_write, | |
2996 | .rx_push_indir_table = efx_ef10_rx_push_indir_table, | |
2997 | .rx_probe = efx_ef10_rx_probe, | |
2998 | .rx_init = efx_ef10_rx_init, | |
2999 | .rx_remove = efx_ef10_rx_remove, | |
3000 | .rx_write = efx_ef10_rx_write, | |
3001 | .rx_defer_refill = efx_ef10_rx_defer_refill, | |
3002 | .ev_probe = efx_ef10_ev_probe, | |
3003 | .ev_init = efx_ef10_ev_init, | |
3004 | .ev_fini = efx_ef10_ev_fini, | |
3005 | .ev_remove = efx_ef10_ev_remove, | |
3006 | .ev_process = efx_ef10_ev_process, | |
3007 | .ev_read_ack = efx_ef10_ev_read_ack, | |
3008 | .ev_test_generate = efx_ef10_ev_test_generate, | |
3009 | .filter_table_probe = efx_ef10_filter_table_probe, | |
3010 | .filter_table_restore = efx_ef10_filter_table_restore, | |
3011 | .filter_table_remove = efx_ef10_filter_table_remove, | |
3012 | .filter_update_rx_scatter = efx_ef10_filter_update_rx_scatter, | |
3013 | .filter_insert = efx_ef10_filter_insert, | |
3014 | .filter_remove_safe = efx_ef10_filter_remove_safe, | |
3015 | .filter_get_safe = efx_ef10_filter_get_safe, | |
3016 | .filter_clear_rx = efx_ef10_filter_clear_rx, | |
3017 | .filter_count_rx_used = efx_ef10_filter_count_rx_used, | |
3018 | .filter_get_rx_id_limit = efx_ef10_filter_get_rx_id_limit, | |
3019 | .filter_get_rx_ids = efx_ef10_filter_get_rx_ids, | |
3020 | #ifdef CONFIG_RFS_ACCEL | |
3021 | .filter_rfs_insert = efx_ef10_filter_rfs_insert, | |
3022 | .filter_rfs_expire_one = efx_ef10_filter_rfs_expire_one, | |
3023 | #endif | |
3024 | #ifdef CONFIG_SFC_MTD | |
3025 | .mtd_probe = efx_ef10_mtd_probe, | |
3026 | .mtd_rename = efx_mcdi_mtd_rename, | |
3027 | .mtd_read = efx_mcdi_mtd_read, | |
3028 | .mtd_erase = efx_mcdi_mtd_erase, | |
3029 | .mtd_write = efx_mcdi_mtd_write, | |
3030 | .mtd_sync = efx_mcdi_mtd_sync, | |
3031 | #endif | |
3032 | .ptp_write_host_time = efx_ef10_ptp_write_host_time, | |
3033 | ||
3034 | .revision = EFX_REV_HUNT_A0, | |
3035 | .max_dma_mask = DMA_BIT_MASK(ESF_DZ_TX_KER_BUF_ADDR_WIDTH), | |
3036 | .rx_prefix_size = ES_DZ_RX_PREFIX_SIZE, | |
3037 | .rx_hash_offset = ES_DZ_RX_PREFIX_HASH_OFST, | |
3038 | .can_rx_scatter = true, | |
3039 | .always_rx_scatter = true, | |
3040 | .max_interrupt_mode = EFX_INT_MODE_MSIX, | |
3041 | .timer_period_max = 1 << ERF_DD_EVQ_IND_TIMER_VAL_WIDTH, | |
3042 | .offload_features = (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | | |
3043 | NETIF_F_RXHASH | NETIF_F_NTUPLE), | |
3044 | .mcdi_max_ver = 2, | |
3045 | .max_rx_ip_filters = HUNT_FILTER_TBL_ROWS, | |
3046 | }; |