Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2013-2016 Intel Corporation
3 : : */
4 : :
5 : : #include <ethdev_driver.h>
6 : : #include <ethdev_pci.h>
7 : : #include <rte_malloc.h>
8 : : #include <rte_memzone.h>
9 : : #include <rte_string_fns.h>
10 : : #include <dev_driver.h>
11 : : #include <rte_spinlock.h>
12 : : #include <rte_kvargs.h>
13 : : #include <rte_vect.h>
14 : :
15 : : #include "fm10k.h"
16 : : #include "base/fm10k_api.h"
17 : :
18 : : /* Default delay to acquire mailbox lock */
19 : : #define FM10K_MBXLOCK_DELAY_US 20
20 : : #define UINT64_LOWER_32BITS_MASK 0x00000000ffffffffULL
21 : :
22 : : #define MAIN_VSI_POOL_NUMBER 0
23 : :
24 : : /* Max try times to acquire switch status */
25 : : #define MAX_QUERY_SWITCH_STATE_TIMES 10
26 : : /* Wait interval to get switch status */
27 : : #define WAIT_SWITCH_MSG_US 100000
28 : : /* A period of quiescence for switch */
29 : : #define FM10K_SWITCH_QUIESCE_US 100000
30 : : /* Number of chars per uint32 type */
31 : : #define CHARS_PER_UINT32 (sizeof(uint32_t))
32 : : #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
33 : :
34 : : /* default 1:1 map from queue ID to interrupt vector ID */
35 : : #define Q2V(pci_dev, queue_id) \
36 : : (rte_intr_vec_list_index_get((pci_dev)->intr_handle, queue_id))
37 : :
38 : : /* First 64 Logical ports for PF/VMDQ, second 64 for Flow director */
39 : : #define MAX_LPORT_NUM 128
40 : : #define GLORT_FD_Q_BASE 0x40
41 : : #define GLORT_PF_MASK 0xFFC0
42 : : #define GLORT_FD_MASK GLORT_PF_MASK
43 : : #define GLORT_FD_INDEX GLORT_FD_Q_BASE
44 : :
45 : : static void fm10k_close_mbx_service(struct fm10k_hw *hw);
46 : : static int fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev);
47 : : static int fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev);
48 : : static int fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev);
49 : : static int fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev);
50 : : static inline int fm10k_glort_valid(struct fm10k_hw *hw);
51 : : static int
52 : : fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on);
53 : : static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
54 : : const u8 *mac, bool add, uint32_t pool);
55 : : static void fm10k_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
56 : : static void fm10k_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
57 : : static void fm10k_set_rx_function(struct rte_eth_dev *dev);
58 : : static void fm10k_set_tx_function(struct rte_eth_dev *dev);
59 : : static int fm10k_check_ftag(struct rte_devargs *devargs);
60 : : static int fm10k_link_update(struct rte_eth_dev *dev, int wait_to_complete);
61 : :
62 : : static int fm10k_dev_infos_get(struct rte_eth_dev *dev,
63 : : struct rte_eth_dev_info *dev_info);
64 : : static uint64_t fm10k_get_rx_queue_offloads_capa(struct rte_eth_dev *dev);
65 : : static uint64_t fm10k_get_rx_port_offloads_capa(struct rte_eth_dev *dev);
66 : : static uint64_t fm10k_get_tx_queue_offloads_capa(struct rte_eth_dev *dev);
67 : : static uint64_t fm10k_get_tx_port_offloads_capa(struct rte_eth_dev *dev);
68 : :
69 : : struct fm10k_xstats_name_off {
70 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
71 : : unsigned offset;
72 : : };
73 : :
74 : : static const struct fm10k_xstats_name_off fm10k_hw_stats_strings[] = {
75 : : {"completion_timeout_count", offsetof(struct fm10k_hw_stats, timeout)},
76 : : {"unsupported_requests_count", offsetof(struct fm10k_hw_stats, ur)},
77 : : {"completer_abort_count", offsetof(struct fm10k_hw_stats, ca)},
78 : : {"unsupported_message_count", offsetof(struct fm10k_hw_stats, um)},
79 : : {"checksum_error_count", offsetof(struct fm10k_hw_stats, xec)},
80 : : {"vlan_dropped", offsetof(struct fm10k_hw_stats, vlan_drop)},
81 : : {"loopback_dropped", offsetof(struct fm10k_hw_stats, loopback_drop)},
82 : : {"rx_mbuf_allocation_errors", offsetof(struct fm10k_hw_stats,
83 : : nodesc_drop)},
84 : : };
85 : :
86 : : #define FM10K_NB_HW_XSTATS (sizeof(fm10k_hw_stats_strings) / \
87 : : sizeof(fm10k_hw_stats_strings[0]))
88 : :
89 : : static const struct fm10k_xstats_name_off fm10k_hw_stats_rx_q_strings[] = {
90 : : {"packets", offsetof(struct fm10k_hw_stats_q, rx_packets)},
91 : : {"bytes", offsetof(struct fm10k_hw_stats_q, rx_bytes)},
92 : : {"dropped", offsetof(struct fm10k_hw_stats_q, rx_drops)},
93 : : };
94 : :
95 : : #define FM10K_NB_RX_Q_XSTATS (sizeof(fm10k_hw_stats_rx_q_strings) / \
96 : : sizeof(fm10k_hw_stats_rx_q_strings[0]))
97 : :
98 : : static const struct fm10k_xstats_name_off fm10k_hw_stats_tx_q_strings[] = {
99 : : {"packets", offsetof(struct fm10k_hw_stats_q, tx_packets)},
100 : : {"bytes", offsetof(struct fm10k_hw_stats_q, tx_bytes)},
101 : : };
102 : :
103 : : #define FM10K_NB_TX_Q_XSTATS (sizeof(fm10k_hw_stats_tx_q_strings) / \
104 : : sizeof(fm10k_hw_stats_tx_q_strings[0]))
105 : :
106 : : #define FM10K_NB_XSTATS (FM10K_NB_HW_XSTATS + FM10K_MAX_QUEUES_PF * \
107 : : (FM10K_NB_RX_Q_XSTATS + FM10K_NB_TX_Q_XSTATS))
108 : : static int
109 : : fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev);
110 : :
111 : : static void
112 : : fm10k_mbx_initlock(struct fm10k_hw *hw)
113 : : {
114 : 0 : rte_spinlock_init(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
115 : : }
116 : :
117 : : static void
118 : : fm10k_mbx_lock(struct fm10k_hw *hw)
119 : : __rte_acquire_capability(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
120 : : {
121 [ # # # # : 0 : while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
122 : 0 : rte_delay_us(FM10K_MBXLOCK_DELAY_US);
123 : : }
124 : :
125 : : static void
126 : : fm10k_mbx_unlock(struct fm10k_hw *hw)
127 : : __rte_release_capability(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back))
128 : : {
129 : 0 : rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
130 : 0 : }
131 : :
132 : : #ifndef RTE_ARCH_X86
133 : : /* Stubs for non x86 architectures. */
134 : : int
135 : : fm10k_rx_vec_condition_check(__rte_unused struct rte_eth_dev *dev)
136 : : {
137 : : return -1;
138 : : }
139 : :
140 : : uint16_t
141 : : fm10k_recv_pkts_vec(
142 : : __rte_unused void *rx_queue,
143 : : __rte_unused struct rte_mbuf **rx_pkts,
144 : : __rte_unused uint16_t nb_pkts)
145 : : {
146 : : return 0;
147 : : }
148 : :
149 : : uint16_t
150 : : fm10k_recv_scattered_pkts_vec(
151 : : __rte_unused void *rx_queue,
152 : : __rte_unused struct rte_mbuf **rx_pkts,
153 : : __rte_unused uint16_t nb_pkts)
154 : : {
155 : : return 0;
156 : : }
157 : :
158 : : int
159 : : fm10k_rxq_vec_setup(__rte_unused struct fm10k_rx_queue *rxq)
160 : :
161 : : {
162 : : return -1;
163 : : }
164 : :
165 : : void
166 : : fm10k_rx_queue_release_mbufs_vec(
167 : : __rte_unused struct fm10k_rx_queue *rxq)
168 : : {
169 : : return;
170 : : }
171 : :
172 : : void
173 : : fm10k_txq_vec_setup(__rte_unused struct fm10k_tx_queue *txq)
174 : : {
175 : : return;
176 : : }
177 : :
178 : : int
179 : : fm10k_tx_vec_condition_check(__rte_unused struct fm10k_tx_queue *txq)
180 : : {
181 : : return -1;
182 : : }
183 : :
184 : : uint16_t
185 : : fm10k_xmit_fixed_burst_vec(__rte_unused void *tx_queue,
186 : : __rte_unused struct rte_mbuf **tx_pkts,
187 : : __rte_unused uint16_t nb_pkts)
188 : : {
189 : : return 0;
190 : : }
191 : : #endif /* RTE_ARCH_X86 */
192 : :
193 : : /*
194 : : * reset queue to initial state, allocate software buffers used when starting
195 : : * device.
196 : : * return 0 on success
197 : : * return -ENOMEM if buffers cannot be allocated
198 : : * return -EINVAL if buffers do not satisfy alignment condition
199 : : */
200 : : static inline int
201 : 0 : rx_queue_reset(struct fm10k_rx_queue *q)
202 : : {
203 : : static const union fm10k_rx_desc zero = {{0} };
204 : : uint64_t dma_addr;
205 : : int i, diag;
206 : 0 : PMD_INIT_FUNC_TRACE();
207 : :
208 [ # # ]: 0 : diag = rte_mbuf_raw_alloc_bulk(q->mp, (void *)q->sw_ring, q->nb_desc);
209 [ # # ]: 0 : if (diag != 0)
210 : : return -ENOMEM;
211 : :
212 [ # # ]: 0 : for (i = 0; i < q->nb_desc; ++i) {
213 : 0 : fm10k_pktmbuf_reset(q->sw_ring[i], q->port_id);
214 [ # # ]: 0 : if (!fm10k_addr_alignment_valid(q->sw_ring[i])) {
215 [ # # ]: 0 : rte_mbuf_raw_free_bulk(q->mp, q->sw_ring, q->nb_desc);
216 : 0 : return -EINVAL;
217 : : }
218 : 0 : dma_addr = MBUF_DMA_ADDR_DEFAULT(q->sw_ring[i]);
219 : 0 : q->hw_ring[i].q.pkt_addr = dma_addr;
220 : 0 : q->hw_ring[i].q.hdr_addr = dma_addr;
221 : : }
222 : :
223 : : /* initialize extra software ring entries. Space for these extra
224 : : * entries is always allocated.
225 : : */
226 : 0 : memset(&q->fake_mbuf, 0x0, sizeof(q->fake_mbuf));
227 [ # # ]: 0 : for (i = 0; i < q->nb_fake_desc; ++i) {
228 : 0 : q->sw_ring[q->nb_desc + i] = &q->fake_mbuf;
229 : 0 : q->hw_ring[q->nb_desc + i] = zero;
230 : : }
231 : :
232 : 0 : q->next_dd = 0;
233 : 0 : q->next_alloc = 0;
234 : 0 : q->next_trigger = q->alloc_thresh - 1;
235 : 0 : FM10K_PCI_REG_WRITE(q->tail_ptr, q->nb_desc - 1);
236 : 0 : q->rxrearm_start = 0;
237 : 0 : q->rxrearm_nb = 0;
238 : :
239 : 0 : return 0;
240 : : }
241 : :
242 : : /*
243 : : * clean queue, descriptor rings, free software buffers used when stopping
244 : : * device.
245 : : */
246 : : static inline void
247 : 0 : rx_queue_clean(struct fm10k_rx_queue *q)
248 : : {
249 : : union fm10k_rx_desc zero = {.q = {0, 0, 0, 0} };
250 : : uint32_t i;
251 : 0 : PMD_INIT_FUNC_TRACE();
252 : :
253 : : /* zero descriptor rings */
254 [ # # ]: 0 : for (i = 0; i < q->nb_desc; ++i)
255 : 0 : q->hw_ring[i] = zero;
256 : :
257 : : /* zero faked descriptors */
258 [ # # ]: 0 : for (i = 0; i < q->nb_fake_desc; ++i)
259 : 0 : q->hw_ring[q->nb_desc + i] = zero;
260 : :
261 : : /* vPMD has a different way of releasing mbufs. */
262 [ # # ]: 0 : if (q->rx_using_sse) {
263 : 0 : fm10k_rx_queue_release_mbufs_vec(q);
264 : : return;
265 : : }
266 : :
267 : : /* free software buffers */
268 [ # # ]: 0 : for (i = 0; i < q->nb_desc; ++i) {
269 [ # # ]: 0 : if (q->sw_ring[i]) {
270 : : rte_pktmbuf_free_seg(q->sw_ring[i]);
271 : 0 : q->sw_ring[i] = NULL;
272 : : }
273 : : }
274 : : }
275 : :
276 : : /*
277 : : * free all queue memory used when releasing the queue (i.e. configure)
278 : : */
279 : : static inline void
280 : 0 : rx_queue_free(struct fm10k_rx_queue *q)
281 : : {
282 : 0 : PMD_INIT_FUNC_TRACE();
283 [ # # ]: 0 : if (q) {
284 : 0 : PMD_INIT_LOG(DEBUG, "Freeing rx queue %p", q);
285 : 0 : rx_queue_clean(q);
286 [ # # ]: 0 : if (q->sw_ring) {
287 : 0 : rte_free(q->sw_ring);
288 : 0 : q->sw_ring = NULL;
289 : : }
290 : 0 : rte_free(q);
291 : : q = NULL;
292 : : }
293 : 0 : }
294 : :
295 : : /*
296 : : * disable RX queue, wait until HW finished necessary flush operation
297 : : */
298 : : static inline int
299 : 0 : rx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
300 : : {
301 : : uint32_t reg, i;
302 : :
303 : 0 : reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
304 : 0 : FM10K_WRITE_REG(hw, FM10K_RXQCTL(qnum),
305 : : reg & ~FM10K_RXQCTL_ENABLE);
306 : :
307 : : /* Wait 100us at most */
308 [ # # ]: 0 : for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
309 : 0 : rte_delay_us(1);
310 : 0 : reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
311 [ # # ]: 0 : if (!(reg & FM10K_RXQCTL_ENABLE))
312 : : break;
313 : : }
314 : :
315 [ # # ]: 0 : if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
316 : 0 : return -1;
317 : :
318 : : return 0;
319 : : }
320 : :
321 : : /*
322 : : * reset queue to initial state, allocate software buffers used when starting
323 : : * device
324 : : */
325 : : static inline void
326 : 0 : tx_queue_reset(struct fm10k_tx_queue *q)
327 : : {
328 : 0 : PMD_INIT_FUNC_TRACE();
329 : 0 : q->last_free = 0;
330 : 0 : q->next_free = 0;
331 : 0 : q->nb_used = 0;
332 : 0 : q->nb_free = q->nb_desc - 1;
333 : 0 : fifo_reset(&q->rs_tracker, (q->nb_desc + 1) / q->rs_thresh);
334 : 0 : FM10K_PCI_REG_WRITE(q->tail_ptr, 0);
335 : 0 : }
336 : :
337 : : /*
338 : : * clean queue, descriptor rings, free software buffers used when stopping
339 : : * device
340 : : */
341 : : static inline void
342 : 0 : tx_queue_clean(struct fm10k_tx_queue *q)
343 : : {
344 : : struct fm10k_tx_desc zero = {0, 0, 0, 0, 0, 0};
345 : : uint32_t i;
346 : 0 : PMD_INIT_FUNC_TRACE();
347 : :
348 : : /* zero descriptor rings */
349 [ # # ]: 0 : for (i = 0; i < q->nb_desc; ++i)
350 : 0 : q->hw_ring[i] = zero;
351 : :
352 : : /* free software buffers */
353 [ # # ]: 0 : for (i = 0; i < q->nb_desc; ++i) {
354 [ # # ]: 0 : if (q->sw_ring[i]) {
355 : : rte_pktmbuf_free_seg(q->sw_ring[i]);
356 : 0 : q->sw_ring[i] = NULL;
357 : : }
358 : : }
359 : 0 : }
360 : :
361 : : /*
362 : : * free all queue memory used when releasing the queue (i.e. configure)
363 : : */
364 : : static inline void
365 : 0 : tx_queue_free(struct fm10k_tx_queue *q)
366 : : {
367 : 0 : PMD_INIT_FUNC_TRACE();
368 [ # # ]: 0 : if (q) {
369 : 0 : PMD_INIT_LOG(DEBUG, "Freeing tx queue %p", q);
370 : 0 : tx_queue_clean(q);
371 [ # # ]: 0 : if (q->rs_tracker.list) {
372 : 0 : rte_free(q->rs_tracker.list);
373 : 0 : q->rs_tracker.list = NULL;
374 : : }
375 [ # # ]: 0 : if (q->sw_ring) {
376 : 0 : rte_free(q->sw_ring);
377 : 0 : q->sw_ring = NULL;
378 : : }
379 : 0 : rte_free(q);
380 : : q = NULL;
381 : : }
382 : 0 : }
383 : :
384 : : /*
385 : : * disable TX queue, wait until HW finished necessary flush operation
386 : : */
387 : : static inline int
388 : 0 : tx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
389 : : {
390 : : uint32_t reg, i;
391 : :
392 : 0 : reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
393 : 0 : FM10K_WRITE_REG(hw, FM10K_TXDCTL(qnum),
394 : : reg & ~FM10K_TXDCTL_ENABLE);
395 : :
396 : : /* Wait 100us at most */
397 [ # # ]: 0 : for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
398 : 0 : rte_delay_us(1);
399 : 0 : reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
400 [ # # ]: 0 : if (!(reg & FM10K_TXDCTL_ENABLE))
401 : : break;
402 : : }
403 : :
404 [ # # ]: 0 : if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
405 : 0 : return -1;
406 : :
407 : : return 0;
408 : : }
409 : :
410 : : static int
411 : 0 : fm10k_check_mq_mode(struct rte_eth_dev *dev)
412 : : {
413 : 0 : enum rte_eth_rx_mq_mode rx_mq_mode = dev->data->dev_conf.rxmode.mq_mode;
414 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
415 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
416 : 0 : uint16_t nb_rx_q = dev->data->nb_rx_queues;
417 : :
418 : : vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
419 : :
420 [ # # ]: 0 : if (rx_mq_mode & RTE_ETH_MQ_RX_DCB_FLAG) {
421 : 0 : PMD_INIT_LOG(ERR, "DCB mode is not supported.");
422 : 0 : return -EINVAL;
423 : : }
424 : :
425 [ # # ]: 0 : if (!(rx_mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG))
426 : : return 0;
427 : :
428 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_vf) {
429 : 0 : PMD_INIT_LOG(ERR, "VMDQ mode is not supported in VF.");
430 : 0 : return -EINVAL;
431 : : }
432 : :
433 : : /* Check VMDQ queue pool number */
434 [ # # ]: 0 : if (vmdq_conf->nb_queue_pools >
435 : 0 : sizeof(vmdq_conf->pool_map[0].pools) * CHAR_BIT ||
436 [ # # ]: 0 : vmdq_conf->nb_queue_pools > nb_rx_q) {
437 : 0 : PMD_INIT_LOG(ERR, "Too many of queue pools: %d",
438 : : vmdq_conf->nb_queue_pools);
439 : 0 : return -EINVAL;
440 : : }
441 : :
442 : : return 0;
443 : : }
444 : :
445 : : static const struct fm10k_txq_ops def_txq_ops = {
446 : : .reset = tx_queue_reset,
447 : : };
448 : :
449 : : static int
450 : 0 : fm10k_dev_configure(struct rte_eth_dev *dev)
451 : : {
452 : : int ret;
453 : :
454 : 0 : PMD_INIT_FUNC_TRACE();
455 : :
456 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
457 : 0 : dev->data->dev_conf.rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
458 : :
459 : : /* multiple queue mode checking */
460 : 0 : ret = fm10k_check_mq_mode(dev);
461 [ # # ]: 0 : if (ret != 0) {
462 : 0 : PMD_DRV_LOG(ERR, "fm10k_check_mq_mode fails with %d.",
463 : : ret);
464 : 0 : return ret;
465 : : }
466 : :
467 : 0 : dev->data->scattered_rx = 0;
468 : :
469 : 0 : return 0;
470 : : }
471 : :
472 : : static void
473 : 0 : fm10k_dev_vmdq_rx_configure(struct rte_eth_dev *dev)
474 : : {
475 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
476 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
477 : : uint32_t i;
478 : :
479 : : vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
480 : :
481 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
482 [ # # ]: 0 : if (!vmdq_conf->pool_map[i].pools)
483 : 0 : continue;
484 : : fm10k_mbx_lock(hw);
485 : 0 : fm10k_update_vlan(hw, vmdq_conf->pool_map[i].vlan_id, 0, true);
486 : : fm10k_mbx_unlock(hw);
487 : : }
488 : 0 : }
489 : :
490 : : static void
491 : : fm10k_dev_pf_main_vsi_reset(struct rte_eth_dev *dev)
492 : : {
493 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
494 : :
495 : : /* Add default mac address */
496 : 0 : fm10k_MAC_filter_set(dev, hw->mac.addr, true,
497 : : MAIN_VSI_POOL_NUMBER);
498 : 0 : }
499 : :
500 : : static void
501 : 0 : fm10k_dev_rss_configure(struct rte_eth_dev *dev)
502 : : {
503 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
504 : : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
505 : : uint32_t mrqc, *key, i, reta, j;
506 : : uint64_t hf;
507 : :
508 : : #define RSS_KEY_SIZE 40
509 : : static uint8_t rss_intel_key[RSS_KEY_SIZE] = {
510 : : 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
511 : : 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
512 : : 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
513 : : 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
514 : : 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
515 : : };
516 : :
517 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode != RTE_ETH_MQ_RX_RSS ||
518 [ # # ]: 0 : dev_conf->rx_adv_conf.rss_conf.rss_hf == 0) {
519 : 0 : FM10K_WRITE_REG(hw, FM10K_MRQC(0), 0);
520 : 0 : return;
521 : : }
522 : :
523 : : /* random key is rss_intel_key (default) or user provided (rss_key) */
524 [ # # ]: 0 : if (dev_conf->rx_adv_conf.rss_conf.rss_key == NULL)
525 : : key = (uint32_t *)rss_intel_key;
526 : : else
527 : : key = (uint32_t *)dev_conf->rx_adv_conf.rss_conf.rss_key;
528 : :
529 : : /* Now fill our hash function seeds, 4 bytes at a time */
530 [ # # ]: 0 : for (i = 0; i < RSS_KEY_SIZE / sizeof(*key); ++i)
531 : 0 : FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
532 : :
533 : : /*
534 : : * Fill in redirection table
535 : : * The byte-swap is needed because NIC registers are in
536 : : * little-endian order.
537 : : */
538 : : reta = 0;
539 [ # # ]: 0 : for (i = 0, j = 0; i < FM10K_MAX_RSS_INDICES; i++, j++) {
540 [ # # ]: 0 : if (j == dev->data->nb_rx_queues)
541 : : j = 0;
542 : 0 : reta = (reta << CHAR_BIT) | j;
543 [ # # ]: 0 : if ((i & 3) == 3)
544 [ # # ]: 0 : FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2),
545 : : rte_bswap32(reta));
546 : : }
547 : :
548 : : /*
549 : : * Generate RSS hash based on packet types, TCP/UDP
550 : : * port numbers and/or IPv4/v6 src and dst addresses
551 : : */
552 : 0 : hf = dev_conf->rx_adv_conf.rss_conf.rss_hf;
553 : : mrqc = 0;
554 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
555 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
556 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
557 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
558 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
559 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
560 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
561 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
562 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
563 : :
564 [ # # ]: 0 : if (mrqc == 0) {
565 : 0 : PMD_INIT_LOG(ERR, "Specified RSS mode 0x%"PRIx64"is not"
566 : : "supported", hf);
567 : 0 : return;
568 : : }
569 : :
570 : 0 : FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
571 : : }
572 : :
573 : : static void
574 : 0 : fm10k_dev_logic_port_update(struct rte_eth_dev *dev, uint16_t nb_lport_new)
575 : : {
576 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
577 : : uint32_t i;
578 : :
579 [ # # ]: 0 : for (i = 0; i < nb_lport_new; i++) {
580 : : /* Set unicast mode by default. App can change
581 : : * to other mode in other API func.
582 : : */
583 : : fm10k_mbx_lock(hw);
584 : 0 : hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map + i,
585 : : FM10K_XCAST_MODE_NONE);
586 : : fm10k_mbx_unlock(hw);
587 : : }
588 : 0 : }
589 : :
590 : : static void
591 : 0 : fm10k_dev_mq_rx_configure(struct rte_eth_dev *dev)
592 : : {
593 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
594 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
595 : : struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
596 : : struct fm10k_macvlan_filter_info *macvlan;
597 : : uint16_t nb_queue_pools = 0; /* pool number in configuration */
598 : : uint16_t nb_lport_new;
599 : :
600 : 0 : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
601 : : vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
602 : :
603 : 0 : fm10k_dev_rss_configure(dev);
604 : :
605 : : /* only PF supports VMDQ */
606 [ # # ]: 0 : if (hw->mac.type != fm10k_mac_pf)
607 : : return;
608 : :
609 [ # # ]: 0 : if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG)
610 : 0 : nb_queue_pools = vmdq_conf->nb_queue_pools;
611 : :
612 : : /* no pool number change, no need to update logic port and VLAN/MAC */
613 [ # # ]: 0 : if (macvlan->nb_queue_pools == nb_queue_pools)
614 : : return;
615 : :
616 : : nb_lport_new = nb_queue_pools ? nb_queue_pools : 1;
617 : 0 : fm10k_dev_logic_port_update(dev, nb_lport_new);
618 : :
619 : : /* reset MAC/VLAN as it's based on VMDQ or PF main VSI */
620 [ # # ]: 0 : memset(dev->data->mac_addrs, 0,
621 : : RTE_ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM);
622 : 0 : rte_ether_addr_copy((const struct rte_ether_addr *)hw->mac.addr,
623 [ # # ]: 0 : &dev->data->mac_addrs[0]);
624 : : memset(macvlan, 0, sizeof(*macvlan));
625 : 0 : macvlan->nb_queue_pools = nb_queue_pools;
626 : :
627 [ # # ]: 0 : if (nb_queue_pools)
628 : 0 : fm10k_dev_vmdq_rx_configure(dev);
629 : : else
630 : : fm10k_dev_pf_main_vsi_reset(dev);
631 : : }
632 : :
633 : : static int
634 : 0 : fm10k_dev_tx_init(struct rte_eth_dev *dev)
635 : : {
636 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
637 : : int i, ret;
638 : : struct fm10k_tx_queue *txq;
639 : : uint64_t base_addr;
640 : : uint32_t size;
641 : :
642 : : /* Disable TXINT to avoid possible interrupt */
643 [ # # ]: 0 : for (i = 0; i < hw->mac.max_queues; i++)
644 : 0 : FM10K_WRITE_REG(hw, FM10K_TXINT(i),
645 : : 3 << FM10K_TXINT_TIMER_SHIFT);
646 : :
647 : : /* Setup TX queue */
648 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; ++i) {
649 : 0 : txq = dev->data->tx_queues[i];
650 : 0 : base_addr = txq->hw_ring_phys_addr;
651 : 0 : size = txq->nb_desc * sizeof(struct fm10k_tx_desc);
652 : :
653 : : /* disable queue to avoid issues while updating state */
654 : 0 : ret = tx_queue_disable(hw, i);
655 [ # # ]: 0 : if (ret) {
656 : 0 : PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
657 : 0 : return -1;
658 : : }
659 : : /* Enable use of FTAG bit in TX descriptor, PFVTCTL
660 : : * register is read-only for VF.
661 : : */
662 [ # # ]: 0 : if (fm10k_check_ftag(dev->device->devargs)) {
663 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf) {
664 : 0 : FM10K_WRITE_REG(hw, FM10K_PFVTCTL(i),
665 : : FM10K_PFVTCTL_FTAG_DESC_ENABLE);
666 : 0 : PMD_INIT_LOG(DEBUG, "FTAG mode is enabled");
667 : : } else {
668 : 0 : PMD_INIT_LOG(ERR, "VF FTAG is not supported.");
669 : 0 : return -ENOTSUP;
670 : : }
671 : : }
672 : :
673 : : /* set location and size for descriptor ring */
674 : 0 : FM10K_WRITE_REG(hw, FM10K_TDBAL(i),
675 : : base_addr & UINT64_LOWER_32BITS_MASK);
676 : 0 : FM10K_WRITE_REG(hw, FM10K_TDBAH(i),
677 : : base_addr >> (CHAR_BIT * sizeof(uint32_t)));
678 : 0 : FM10K_WRITE_REG(hw, FM10K_TDLEN(i), size);
679 : :
680 : : /* assign default SGLORT for each TX queue by PF */
681 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
682 : 0 : FM10K_WRITE_REG(hw, FM10K_TX_SGLORT(i), hw->mac.dglort_map);
683 : : }
684 : :
685 : : /* set up vector or scalar TX function as appropriate */
686 : 0 : fm10k_set_tx_function(dev);
687 : :
688 : 0 : return 0;
689 : : }
690 : :
691 : : static int
692 : 0 : fm10k_dev_rx_init(struct rte_eth_dev *dev)
693 : : {
694 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
695 : : struct fm10k_macvlan_filter_info *macvlan;
696 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
697 : 0 : struct rte_intr_handle *intr_handle = pdev->intr_handle;
698 : : int i, ret;
699 : : struct fm10k_rx_queue *rxq;
700 : : uint64_t base_addr;
701 : : uint32_t size;
702 : : uint32_t rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
703 : 0 : uint32_t logic_port = hw->mac.dglort_map;
704 : : uint16_t buf_size;
705 : : uint16_t queue_stride = 0;
706 : :
707 : : /* enable RXINT for interrupt mode */
708 : : i = 0;
709 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
710 [ # # ]: 0 : for (; i < dev->data->nb_rx_queues; i++) {
711 : 0 : FM10K_WRITE_REG(hw, FM10K_RXINT(i), Q2V(pdev, i));
712 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
713 : 0 : FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
714 : : FM10K_ITR_AUTOMASK |
715 : : FM10K_ITR_MASK_CLEAR);
716 : : else
717 : 0 : FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
718 : : FM10K_ITR_AUTOMASK |
719 : : FM10K_ITR_MASK_CLEAR);
720 : : }
721 : : }
722 : : /* Disable other RXINT to avoid possible interrupt */
723 [ # # ]: 0 : for (; i < hw->mac.max_queues; i++)
724 : 0 : FM10K_WRITE_REG(hw, FM10K_RXINT(i),
725 : : 3 << FM10K_RXINT_TIMER_SHIFT);
726 : :
727 : : /* Setup RX queues */
728 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; ++i) {
729 : 0 : rxq = dev->data->rx_queues[i];
730 : 0 : base_addr = rxq->hw_ring_phys_addr;
731 : 0 : size = rxq->nb_desc * sizeof(union fm10k_rx_desc);
732 : :
733 : : /* disable queue to avoid issues while updating state */
734 : 0 : ret = rx_queue_disable(hw, i);
735 [ # # ]: 0 : if (ret) {
736 : 0 : PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
737 : 0 : return -1;
738 : : }
739 : :
740 : : /* Setup the Base and Length of the Rx Descriptor Ring */
741 : 0 : FM10K_WRITE_REG(hw, FM10K_RDBAL(i),
742 : : base_addr & UINT64_LOWER_32BITS_MASK);
743 : 0 : FM10K_WRITE_REG(hw, FM10K_RDBAH(i),
744 : : base_addr >> (CHAR_BIT * sizeof(uint32_t)));
745 : 0 : FM10K_WRITE_REG(hw, FM10K_RDLEN(i), size);
746 : :
747 : : /* Configure the Rx buffer size for one buff without split */
748 [ # # ]: 0 : buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
749 : : RTE_PKTMBUF_HEADROOM);
750 : : /* As RX buffer is aligned to 512B within mbuf, some bytes are
751 : : * reserved for this purpose, and the worst case could be 511B.
752 : : * But SRR reg assumes all buffers have the same size. In order
753 : : * to fill the gap, we'll have to consider the worst case and
754 : : * assume 512B is reserved. If we don't do so, it's possible
755 : : * for HW to overwrite data to next mbuf.
756 : : */
757 : 0 : buf_size -= FM10K_RX_DATABUF_ALIGN;
758 : :
759 : 0 : FM10K_WRITE_REG(hw, FM10K_SRRCTL(i),
760 : : (buf_size >> FM10K_SRRCTL_BSIZEPKT_SHIFT) |
761 : : FM10K_SRRCTL_LOOPBACK_SUPPRESS);
762 : :
763 : : /* It adds dual VLAN length for supporting dual VLAN */
764 : 0 : if ((dev->data->mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN +
765 [ # # ]: 0 : 2 * RTE_VLAN_HLEN) > buf_size ||
766 [ # # ]: 0 : rxq->offloads & RTE_ETH_RX_OFFLOAD_SCATTER) {
767 : : uint32_t reg;
768 : 0 : dev->data->scattered_rx = 1;
769 : 0 : reg = FM10K_READ_REG(hw, FM10K_SRRCTL(i));
770 : 0 : reg |= FM10K_SRRCTL_BUFFER_CHAINING_EN;
771 : 0 : FM10K_WRITE_REG(hw, FM10K_SRRCTL(i), reg);
772 : : }
773 : :
774 : : /* Enable drop on empty, it's RO for VF */
775 [ # # # # ]: 0 : if (hw->mac.type == fm10k_mac_pf && rxq->drop_en)
776 : : rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
777 : :
778 : 0 : FM10K_WRITE_REG(hw, FM10K_RXDCTL(i), rxdctl);
779 : 0 : FM10K_WRITE_FLUSH(hw);
780 : : }
781 : :
782 : : /* Configure VMDQ/RSS if applicable */
783 : 0 : fm10k_dev_mq_rx_configure(dev);
784 : :
785 : : /* Decide the best RX function */
786 : 0 : fm10k_set_rx_function(dev);
787 : :
788 : : /* update RX_SGLORT for loopback suppress*/
789 [ # # ]: 0 : if (hw->mac.type != fm10k_mac_pf)
790 : : return 0;
791 : 0 : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
792 [ # # ]: 0 : if (macvlan->nb_queue_pools)
793 : 0 : queue_stride = dev->data->nb_rx_queues / macvlan->nb_queue_pools;
794 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; ++i) {
795 [ # # # # ]: 0 : if (i && queue_stride && !(i % queue_stride))
796 : 0 : logic_port++;
797 : 0 : FM10K_WRITE_REG(hw, FM10K_RX_SGLORT(i), logic_port);
798 : : }
799 : :
800 : : return 0;
801 : : }
802 : :
803 : : static int
804 : 0 : fm10k_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
805 : : {
806 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
807 : : int err;
808 : : uint32_t reg;
809 : : struct fm10k_rx_queue *rxq;
810 : :
811 : 0 : PMD_INIT_FUNC_TRACE();
812 : :
813 : 0 : rxq = dev->data->rx_queues[rx_queue_id];
814 : 0 : err = rx_queue_reset(rxq);
815 [ # # ]: 0 : if (err == -ENOMEM) {
816 : 0 : PMD_INIT_LOG(ERR, "Failed to alloc memory : %d", err);
817 : 0 : return err;
818 [ # # ]: 0 : } else if (err == -EINVAL) {
819 : 0 : PMD_INIT_LOG(ERR, "Invalid buffer address alignment :"
820 : : " %d", err);
821 : 0 : return err;
822 : : }
823 : :
824 : : /* Setup the HW Rx Head and Tail Descriptor Pointers
825 : : * Note: this must be done AFTER the queue is enabled on real
826 : : * hardware, but BEFORE the queue is enabled when using the
827 : : * emulation platform. Do it in both places for now and remove
828 : : * this comment and the following two register writes when the
829 : : * emulation platform is no longer being used.
830 : : */
831 : 0 : FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
832 : 0 : FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
833 : :
834 : : /* Set PF ownership flag for PF devices */
835 : 0 : reg = FM10K_READ_REG(hw, FM10K_RXQCTL(rx_queue_id));
836 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
837 : 0 : reg |= FM10K_RXQCTL_PF;
838 : 0 : reg |= FM10K_RXQCTL_ENABLE;
839 : : /* enable RX queue */
840 : 0 : FM10K_WRITE_REG(hw, FM10K_RXQCTL(rx_queue_id), reg);
841 : 0 : FM10K_WRITE_FLUSH(hw);
842 : :
843 : : /* Setup the HW Rx Head and Tail Descriptor Pointers
844 : : * Note: this must be done AFTER the queue is enabled
845 : : */
846 : 0 : FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
847 : 0 : FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
848 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
849 : :
850 : 0 : return 0;
851 : : }
852 : :
853 : : static int
854 : 0 : fm10k_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
855 : : {
856 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
857 : :
858 : 0 : PMD_INIT_FUNC_TRACE();
859 : :
860 : : /* Disable RX queue */
861 : 0 : rx_queue_disable(hw, rx_queue_id);
862 : :
863 : : /* Free mbuf and clean HW ring */
864 : 0 : rx_queue_clean(dev->data->rx_queues[rx_queue_id]);
865 : 0 : dev->data->rx_queue_state[rx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
866 : :
867 : 0 : return 0;
868 : : }
869 : :
870 : : static int
871 : 0 : fm10k_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
872 : : {
873 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
874 : : /** @todo - this should be defined in the shared code */
875 : : #define FM10K_TXDCTL_WRITE_BACK_MIN_DELAY 0x00010000
876 : : uint32_t txdctl = FM10K_TXDCTL_WRITE_BACK_MIN_DELAY;
877 : 0 : struct fm10k_tx_queue *q = dev->data->tx_queues[tx_queue_id];
878 : :
879 : 0 : PMD_INIT_FUNC_TRACE();
880 : :
881 : 0 : q->ops->reset(q);
882 : :
883 : : /* reset head and tail pointers */
884 : 0 : FM10K_WRITE_REG(hw, FM10K_TDH(tx_queue_id), 0);
885 : 0 : FM10K_WRITE_REG(hw, FM10K_TDT(tx_queue_id), 0);
886 : :
887 : : /* enable TX queue */
888 : 0 : FM10K_WRITE_REG(hw, FM10K_TXDCTL(tx_queue_id),
889 : : FM10K_TXDCTL_ENABLE | txdctl);
890 : 0 : FM10K_WRITE_FLUSH(hw);
891 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STARTED;
892 : :
893 : 0 : return 0;
894 : : }
895 : :
896 : : static int
897 : 0 : fm10k_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
898 : : {
899 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
900 : :
901 : 0 : PMD_INIT_FUNC_TRACE();
902 : :
903 : 0 : tx_queue_disable(hw, tx_queue_id);
904 : 0 : tx_queue_clean(dev->data->tx_queues[tx_queue_id]);
905 : 0 : dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
906 : :
907 : 0 : return 0;
908 : : }
909 : :
910 : : static inline int fm10k_glort_valid(struct fm10k_hw *hw)
911 : : {
912 : 0 : return ((hw->mac.dglort_map & FM10K_DGLORTMAP_NONE)
913 : : != FM10K_DGLORTMAP_NONE);
914 : : }
915 : :
916 : : static int
917 : 0 : fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev)
918 : : {
919 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
920 : : int status;
921 : :
922 : 0 : PMD_INIT_FUNC_TRACE();
923 : :
924 : : /* Return if it didn't acquire valid glort range */
925 [ # # # # ]: 0 : if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
926 : : return 0;
927 : :
928 : : fm10k_mbx_lock(hw);
929 : 0 : status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
930 : : FM10K_XCAST_MODE_PROMISC);
931 : : fm10k_mbx_unlock(hw);
932 : :
933 [ # # ]: 0 : if (status != FM10K_SUCCESS) {
934 : 0 : PMD_INIT_LOG(ERR, "Failed to enable promiscuous mode");
935 : 0 : return -EAGAIN;
936 : : }
937 : :
938 : : return 0;
939 : : }
940 : :
941 : : static int
942 : 0 : fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev)
943 : : {
944 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
945 : : uint8_t mode;
946 : : int status;
947 : :
948 : 0 : PMD_INIT_FUNC_TRACE();
949 : :
950 : : /* Return if it didn't acquire valid glort range */
951 [ # # # # ]: 0 : if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
952 : : return 0;
953 : :
954 [ # # ]: 0 : if (dev->data->all_multicast == 1)
955 : : mode = FM10K_XCAST_MODE_ALLMULTI;
956 : : else
957 : : mode = FM10K_XCAST_MODE_NONE;
958 : :
959 : : fm10k_mbx_lock(hw);
960 : 0 : status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
961 : : mode);
962 : : fm10k_mbx_unlock(hw);
963 : :
964 [ # # ]: 0 : if (status != FM10K_SUCCESS) {
965 : 0 : PMD_INIT_LOG(ERR, "Failed to disable promiscuous mode");
966 : 0 : return -EAGAIN;
967 : : }
968 : :
969 : : return 0;
970 : : }
971 : :
972 : : static int
973 : 0 : fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev)
974 : : {
975 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
976 : : int status;
977 : :
978 : 0 : PMD_INIT_FUNC_TRACE();
979 : :
980 : : /* Return if it didn't acquire valid glort range */
981 [ # # # # ]: 0 : if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
982 : : return 0;
983 : :
984 : : /* If promiscuous mode is enabled, it doesn't make sense to enable
985 : : * allmulticast and disable promiscuous since fm10k only can select
986 : : * one of the modes.
987 : : */
988 [ # # ]: 0 : if (dev->data->promiscuous) {
989 : 0 : PMD_INIT_LOG(INFO, "Promiscuous mode is enabled, "\
990 : : "needn't enable allmulticast");
991 : 0 : return 0;
992 : : }
993 : :
994 : : fm10k_mbx_lock(hw);
995 : 0 : status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
996 : : FM10K_XCAST_MODE_ALLMULTI);
997 : : fm10k_mbx_unlock(hw);
998 : :
999 [ # # ]: 0 : if (status != FM10K_SUCCESS) {
1000 : 0 : PMD_INIT_LOG(ERR, "Failed to enable allmulticast mode");
1001 : 0 : return -EAGAIN;
1002 : : }
1003 : :
1004 : : return 0;
1005 : : }
1006 : :
1007 : : static int
1008 : 0 : fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev)
1009 : : {
1010 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1011 : : int status;
1012 : :
1013 : 0 : PMD_INIT_FUNC_TRACE();
1014 : :
1015 : : /* Return if it didn't acquire valid glort range */
1016 [ # # # # ]: 0 : if ((hw->mac.type == fm10k_mac_pf) && !fm10k_glort_valid(hw))
1017 : : return 0;
1018 : :
1019 [ # # ]: 0 : if (dev->data->promiscuous) {
1020 : 0 : PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode "\
1021 : : "since promisc mode is enabled");
1022 : 0 : return -EINVAL;
1023 : : }
1024 : :
1025 : : fm10k_mbx_lock(hw);
1026 : : /* Change mode to unicast mode */
1027 : 0 : status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
1028 : : FM10K_XCAST_MODE_NONE);
1029 : : fm10k_mbx_unlock(hw);
1030 : :
1031 [ # # ]: 0 : if (status != FM10K_SUCCESS) {
1032 : 0 : PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode");
1033 : 0 : return -EAGAIN;
1034 : : }
1035 : :
1036 : : return 0;
1037 : : }
1038 : :
1039 : : static void
1040 : 0 : fm10k_dev_dglort_map_configure(struct rte_eth_dev *dev)
1041 : : {
1042 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1043 : : uint32_t dglortdec, pool_len, rss_len, i, dglortmask;
1044 : : uint16_t nb_queue_pools;
1045 : : struct fm10k_macvlan_filter_info *macvlan;
1046 : :
1047 : : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1048 : 0 : nb_queue_pools = macvlan->nb_queue_pools;
1049 [ # # # # ]: 0 : pool_len = nb_queue_pools ? rte_fls_u32(nb_queue_pools - 1) : 0;
1050 [ # # ]: 0 : rss_len = rte_fls_u32(dev->data->nb_rx_queues - 1) - pool_len;
1051 : :
1052 : : /* GLORT 0x0-0x3F are used by PF and VMDQ, 0x40-0x7F used by FD */
1053 : 0 : dglortdec = (rss_len << FM10K_DGLORTDEC_RSSLENGTH_SHIFT) | pool_len;
1054 : 0 : dglortmask = (GLORT_PF_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
1055 : 0 : hw->mac.dglort_map;
1056 : 0 : FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(0), dglortmask);
1057 : : /* Configure VMDQ/RSS DGlort Decoder */
1058 : 0 : FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(0), dglortdec);
1059 : :
1060 : : /* Flow Director configurations, only queue number is valid. */
1061 [ # # ]: 0 : dglortdec = rte_fls_u32(dev->data->nb_rx_queues - 1);
1062 : 0 : dglortmask = (GLORT_FD_MASK << FM10K_DGLORTMAP_MASK_SHIFT) |
1063 : 0 : (hw->mac.dglort_map + GLORT_FD_Q_BASE);
1064 : 0 : FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(1), dglortmask);
1065 : 0 : FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(1), dglortdec);
1066 : :
1067 : : /* Invalidate all other GLORT entries */
1068 [ # # ]: 0 : for (i = 2; i < FM10K_DGLORT_COUNT; i++)
1069 : 0 : FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(i),
1070 : : FM10K_DGLORTMAP_NONE);
1071 : 0 : }
1072 : :
1073 : : #define BSIZEPKT_ROUNDUP ((1 << FM10K_SRRCTL_BSIZEPKT_SHIFT) - 1)
1074 : : static int
1075 : 0 : fm10k_dev_start(struct rte_eth_dev *dev)
1076 : : {
1077 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1078 : : int i, diag;
1079 : :
1080 : 0 : PMD_INIT_FUNC_TRACE();
1081 : :
1082 : : /* stop, init, then start the hw */
1083 : 0 : diag = fm10k_stop_hw(hw);
1084 [ # # ]: 0 : if (diag != FM10K_SUCCESS) {
1085 : 0 : PMD_INIT_LOG(ERR, "Hardware stop failed: %d", diag);
1086 : 0 : return -EIO;
1087 : : }
1088 : :
1089 : 0 : diag = fm10k_init_hw(hw);
1090 [ # # ]: 0 : if (diag != FM10K_SUCCESS) {
1091 : 0 : PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
1092 : 0 : return -EIO;
1093 : : }
1094 : :
1095 : 0 : diag = fm10k_start_hw(hw);
1096 [ # # ]: 0 : if (diag != FM10K_SUCCESS) {
1097 : 0 : PMD_INIT_LOG(ERR, "Hardware start failed: %d", diag);
1098 : 0 : return -EIO;
1099 : : }
1100 : :
1101 : 0 : diag = fm10k_dev_tx_init(dev);
1102 [ # # ]: 0 : if (diag) {
1103 : 0 : PMD_INIT_LOG(ERR, "TX init failed: %d", diag);
1104 : 0 : return diag;
1105 : : }
1106 : :
1107 [ # # ]: 0 : if (fm10k_dev_rxq_interrupt_setup(dev))
1108 : : return -EIO;
1109 : :
1110 : 0 : diag = fm10k_dev_rx_init(dev);
1111 [ # # ]: 0 : if (diag) {
1112 : 0 : PMD_INIT_LOG(ERR, "RX init failed: %d", diag);
1113 : 0 : return diag;
1114 : : }
1115 : :
1116 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
1117 : 0 : fm10k_dev_dglort_map_configure(dev);
1118 : :
1119 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1120 : : struct fm10k_rx_queue *rxq;
1121 : 0 : rxq = dev->data->rx_queues[i];
1122 : :
1123 [ # # ]: 0 : if (rxq->rx_deferred_start)
1124 : 0 : continue;
1125 : 0 : diag = fm10k_dev_rx_queue_start(dev, i);
1126 [ # # ]: 0 : if (diag != 0) {
1127 : : int j;
1128 [ # # ]: 0 : for (j = 0; j < i; ++j)
1129 : 0 : rx_queue_clean(dev->data->rx_queues[j]);
1130 : : return diag;
1131 : : }
1132 : : }
1133 : :
1134 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1135 : : struct fm10k_tx_queue *txq;
1136 : 0 : txq = dev->data->tx_queues[i];
1137 : :
1138 [ # # ]: 0 : if (txq->tx_deferred_start)
1139 : 0 : continue;
1140 : 0 : diag = fm10k_dev_tx_queue_start(dev, i);
1141 [ # # ]: 0 : if (diag != 0) {
1142 : : int j;
1143 [ # # ]: 0 : for (j = 0; j < i; ++j)
1144 : 0 : tx_queue_clean(dev->data->tx_queues[j]);
1145 [ # # ]: 0 : for (j = 0; j < dev->data->nb_rx_queues; ++j)
1146 : 0 : rx_queue_clean(dev->data->rx_queues[j]);
1147 : : return diag;
1148 : : }
1149 : : }
1150 : :
1151 : : /* Update default vlan when not in VMDQ mode */
1152 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG))
1153 : 0 : fm10k_vlan_filter_set(dev, hw->mac.default_vid, true);
1154 : :
1155 : 0 : fm10k_link_update(dev, 0);
1156 : :
1157 : 0 : return 0;
1158 : : }
1159 : :
1160 : : static int
1161 : 0 : fm10k_dev_stop(struct rte_eth_dev *dev)
1162 : : {
1163 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1164 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
1165 : 0 : struct rte_intr_handle *intr_handle = pdev->intr_handle;
1166 : : int i;
1167 : :
1168 : 0 : PMD_INIT_FUNC_TRACE();
1169 : 0 : dev->data->dev_started = 0;
1170 : :
1171 [ # # ]: 0 : if (dev->data->tx_queues)
1172 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++)
1173 : 0 : fm10k_dev_tx_queue_stop(dev, i);
1174 : :
1175 [ # # ]: 0 : if (dev->data->rx_queues)
1176 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
1177 : 0 : fm10k_dev_rx_queue_stop(dev, i);
1178 : :
1179 : : /* Disable datapath event */
1180 [ # # ]: 0 : if (rte_intr_dp_is_en(intr_handle)) {
1181 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
1182 : 0 : FM10K_WRITE_REG(hw, FM10K_RXINT(i),
1183 : : 3 << FM10K_RXINT_TIMER_SHIFT);
1184 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
1185 : 0 : FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, i)),
1186 : : FM10K_ITR_MASK_SET);
1187 : : else
1188 : 0 : FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, i)),
1189 : : FM10K_ITR_MASK_SET);
1190 : : }
1191 : : }
1192 : : /* Clean datapath event and queue/vec mapping */
1193 : 0 : rte_intr_efd_disable(intr_handle);
1194 : 0 : rte_intr_vec_list_free(intr_handle);
1195 : :
1196 : 0 : return 0;
1197 : : }
1198 : :
1199 : : static void
1200 : 0 : fm10k_dev_queue_release(struct rte_eth_dev *dev)
1201 : : {
1202 : : int i;
1203 : :
1204 : 0 : PMD_INIT_FUNC_TRACE();
1205 : :
1206 [ # # ]: 0 : if (dev->data->tx_queues) {
1207 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
1208 : 0 : struct fm10k_tx_queue *txq = dev->data->tx_queues[i];
1209 : :
1210 : 0 : tx_queue_free(txq);
1211 : : }
1212 : : }
1213 : :
1214 [ # # ]: 0 : if (dev->data->rx_queues) {
1215 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++)
1216 : 0 : fm10k_rx_queue_release(dev, i);
1217 : : }
1218 : 0 : }
1219 : :
1220 : : static int
1221 : 0 : fm10k_link_update(struct rte_eth_dev *dev,
1222 : : __rte_unused int wait_to_complete)
1223 : : {
1224 : : struct fm10k_dev_info *dev_info =
1225 : 0 : FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
1226 : 0 : PMD_INIT_FUNC_TRACE();
1227 : :
1228 : 0 : dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_50G;
1229 : 0 : dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
1230 : 0 : dev->data->dev_link.link_status =
1231 : 0 : dev_info->sm_down ? RTE_ETH_LINK_DOWN : RTE_ETH_LINK_UP;
1232 : 0 : dev->data->dev_link.link_autoneg = RTE_ETH_LINK_FIXED;
1233 : :
1234 : 0 : return 0;
1235 : : }
1236 : :
1237 : 0 : static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
1238 : : struct rte_eth_xstat_name *xstats_names, __rte_unused unsigned limit)
1239 : : {
1240 : : unsigned i, q;
1241 : : unsigned count = 0;
1242 : :
1243 [ # # ]: 0 : if (xstats_names != NULL) {
1244 : : /* Note: limit checked in rte_eth_xstats_names() */
1245 : :
1246 : : /* Global stats */
1247 [ # # ]: 0 : for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
1248 : 0 : snprintf(xstats_names[count].name,
1249 : : sizeof(xstats_names[count].name),
1250 : 0 : "%s", fm10k_hw_stats_strings[count].name);
1251 : 0 : count++;
1252 : : }
1253 : :
1254 : : /* PF queue stats */
1255 [ # # ]: 0 : for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
1256 [ # # ]: 0 : for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
1257 : 0 : snprintf(xstats_names[count].name,
1258 : : sizeof(xstats_names[count].name),
1259 : : "rx_q%u_%s", q,
1260 : 0 : fm10k_hw_stats_rx_q_strings[i].name);
1261 : 0 : count++;
1262 : : }
1263 [ # # ]: 0 : for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
1264 : 0 : snprintf(xstats_names[count].name,
1265 : : sizeof(xstats_names[count].name),
1266 : : "tx_q%u_%s", q,
1267 : 0 : fm10k_hw_stats_tx_q_strings[i].name);
1268 : 0 : count++;
1269 : : }
1270 : : }
1271 : : }
1272 : 0 : return FM10K_NB_XSTATS;
1273 : : }
1274 : :
1275 : : static int
1276 : 0 : fm10k_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
1277 : : unsigned n)
1278 : : {
1279 : 0 : struct fm10k_hw_stats *hw_stats =
1280 : 0 : FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1281 : : unsigned i, q, count = 0;
1282 : :
1283 [ # # ]: 0 : if (n < FM10K_NB_XSTATS)
1284 : : return FM10K_NB_XSTATS;
1285 : :
1286 : : /* Global stats */
1287 [ # # ]: 0 : for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
1288 : 0 : xstats[count].value = *(uint64_t *)(((char *)hw_stats) +
1289 : 0 : fm10k_hw_stats_strings[count].offset);
1290 : 0 : xstats[count].id = count;
1291 : 0 : count++;
1292 : : }
1293 : :
1294 : : /* PF queue stats */
1295 [ # # ]: 0 : for (q = 0; q < FM10K_MAX_QUEUES_PF; q++) {
1296 [ # # ]: 0 : for (i = 0; i < FM10K_NB_RX_Q_XSTATS; i++) {
1297 : 0 : xstats[count].value =
1298 : 0 : *(uint64_t *)(((char *)&hw_stats->q[q]) +
1299 : 0 : fm10k_hw_stats_rx_q_strings[i].offset);
1300 : 0 : xstats[count].id = count;
1301 : 0 : count++;
1302 : : }
1303 [ # # ]: 0 : for (i = 0; i < FM10K_NB_TX_Q_XSTATS; i++) {
1304 : 0 : xstats[count].value =
1305 : 0 : *(uint64_t *)(((char *)&hw_stats->q[q]) +
1306 : 0 : fm10k_hw_stats_tx_q_strings[i].offset);
1307 : 0 : xstats[count].id = count;
1308 : 0 : count++;
1309 : : }
1310 : : }
1311 : :
1312 : : return FM10K_NB_XSTATS;
1313 : : }
1314 : :
1315 : : static int
1316 : 0 : fm10k_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats,
1317 : : struct eth_queue_stats *qstats)
1318 : : {
1319 : : uint64_t ipackets, opackets, ibytes, obytes, imissed;
1320 : 0 : struct fm10k_hw *hw =
1321 : 0 : FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1322 : 0 : struct fm10k_hw_stats *hw_stats =
1323 : : FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1324 : : int i;
1325 : :
1326 : 0 : PMD_INIT_FUNC_TRACE();
1327 : :
1328 : 0 : fm10k_update_hw_stats(hw, hw_stats);
1329 : :
1330 : : ipackets = opackets = ibytes = obytes = imissed = 0;
1331 [ # # ]: 0 : for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
1332 [ # # ]: 0 : (i < hw->mac.max_queues); ++i) {
1333 [ # # ]: 0 : if (qstats != NULL) {
1334 : 0 : qstats->q_ipackets[i] = hw_stats->q[i].rx_packets.count;
1335 : 0 : qstats->q_opackets[i] = hw_stats->q[i].tx_packets.count;
1336 : 0 : qstats->q_ibytes[i] = hw_stats->q[i].rx_bytes.count;
1337 : 0 : qstats->q_obytes[i] = hw_stats->q[i].tx_bytes.count;
1338 : 0 : qstats->q_errors[i] = hw_stats->q[i].rx_drops.count;
1339 : : }
1340 : 0 : ipackets += hw_stats->q[i].rx_packets.count;
1341 : 0 : opackets += hw_stats->q[i].tx_packets.count;
1342 : 0 : ibytes += hw_stats->q[i].rx_bytes.count;
1343 : 0 : obytes += hw_stats->q[i].tx_bytes.count;
1344 : 0 : imissed += hw_stats->q[i].rx_drops.count;
1345 : : }
1346 : 0 : stats->ipackets = ipackets;
1347 : 0 : stats->opackets = opackets;
1348 : 0 : stats->ibytes = ibytes;
1349 : 0 : stats->obytes = obytes;
1350 : 0 : stats->imissed = imissed;
1351 : 0 : return 0;
1352 : : }
1353 : :
1354 : : static int
1355 : 0 : fm10k_stats_reset(struct rte_eth_dev *dev)
1356 : : {
1357 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1358 : 0 : struct fm10k_hw_stats *hw_stats =
1359 : : FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
1360 : :
1361 : 0 : PMD_INIT_FUNC_TRACE();
1362 : :
1363 : : memset(hw_stats, 0, sizeof(*hw_stats));
1364 : 0 : fm10k_rebind_hw_stats(hw, hw_stats);
1365 : :
1366 : 0 : return 0;
1367 : : }
1368 : :
1369 : : static int
1370 : 0 : fm10k_dev_infos_get(struct rte_eth_dev *dev,
1371 : : struct rte_eth_dev_info *dev_info)
1372 : : {
1373 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1374 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
1375 : :
1376 : 0 : PMD_INIT_FUNC_TRACE();
1377 : :
1378 : 0 : dev_info->min_rx_bufsize = FM10K_MIN_RX_BUF_SIZE;
1379 : 0 : dev_info->max_rx_pktlen = FM10K_MAX_PKT_SIZE;
1380 : 0 : dev_info->max_rx_queues = hw->mac.max_queues;
1381 : 0 : dev_info->max_tx_queues = hw->mac.max_queues;
1382 : 0 : dev_info->max_mac_addrs = FM10K_MAX_MACADDR_NUM;
1383 : 0 : dev_info->max_hash_mac_addrs = 0;
1384 : 0 : dev_info->max_vfs = pdev->max_vfs;
1385 : 0 : dev_info->vmdq_pool_base = 0;
1386 : 0 : dev_info->vmdq_queue_base = 0;
1387 : 0 : dev_info->max_vmdq_pools = RTE_ETH_32_POOLS;
1388 : 0 : dev_info->vmdq_queue_num = FM10K_MAX_QUEUES_PF;
1389 : 0 : dev_info->rx_queue_offload_capa = fm10k_get_rx_queue_offloads_capa(dev);
1390 : 0 : dev_info->rx_offload_capa = fm10k_get_rx_port_offloads_capa(dev) |
1391 : : dev_info->rx_queue_offload_capa;
1392 : 0 : dev_info->tx_queue_offload_capa = fm10k_get_tx_queue_offloads_capa(dev);
1393 : 0 : dev_info->tx_offload_capa = fm10k_get_tx_port_offloads_capa(dev) |
1394 : : dev_info->tx_queue_offload_capa;
1395 : :
1396 : 0 : dev_info->hash_key_size = FM10K_RSSRK_SIZE * sizeof(uint32_t);
1397 : 0 : dev_info->reta_size = FM10K_MAX_RSS_INDICES;
1398 : 0 : dev_info->flow_type_rss_offloads = RTE_ETH_RSS_IPV4 |
1399 : : RTE_ETH_RSS_IPV6 |
1400 : : RTE_ETH_RSS_IPV6_EX |
1401 : : RTE_ETH_RSS_NONFRAG_IPV4_TCP |
1402 : : RTE_ETH_RSS_NONFRAG_IPV6_TCP |
1403 : : RTE_ETH_RSS_IPV6_TCP_EX |
1404 : : RTE_ETH_RSS_NONFRAG_IPV4_UDP |
1405 : : RTE_ETH_RSS_NONFRAG_IPV6_UDP |
1406 : : RTE_ETH_RSS_IPV6_UDP_EX;
1407 : :
1408 : 0 : dev_info->default_rxconf = (struct rte_eth_rxconf) {
1409 : : .rx_thresh = {
1410 : : .pthresh = FM10K_DEFAULT_RX_PTHRESH,
1411 : : .hthresh = FM10K_DEFAULT_RX_HTHRESH,
1412 : : .wthresh = FM10K_DEFAULT_RX_WTHRESH,
1413 : : },
1414 : : .rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(0),
1415 : : .rx_drop_en = 0,
1416 : : .offloads = 0,
1417 : : };
1418 : :
1419 : 0 : dev_info->default_txconf = (struct rte_eth_txconf) {
1420 : : .tx_thresh = {
1421 : : .pthresh = FM10K_DEFAULT_TX_PTHRESH,
1422 : : .hthresh = FM10K_DEFAULT_TX_HTHRESH,
1423 : : .wthresh = FM10K_DEFAULT_TX_WTHRESH,
1424 : : },
1425 : : .tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(0),
1426 : : .tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(0),
1427 : : .offloads = 0,
1428 : : };
1429 : :
1430 : 0 : dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1431 : : .nb_max = FM10K_MAX_RX_DESC,
1432 : : .nb_min = FM10K_MIN_RX_DESC,
1433 : : .nb_align = FM10K_MULT_RX_DESC,
1434 : : };
1435 : :
1436 : 0 : dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1437 : : .nb_max = FM10K_MAX_TX_DESC,
1438 : : .nb_min = FM10K_MIN_TX_DESC,
1439 : : .nb_align = FM10K_MULT_TX_DESC,
1440 : : .nb_seg_max = FM10K_TX_MAX_SEG,
1441 : : .nb_mtu_seg_max = FM10K_TX_MAX_MTU_SEG,
1442 : : };
1443 : :
1444 : 0 : dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_2_5G |
1445 : : RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_25G |
1446 : : RTE_ETH_LINK_SPEED_40G | RTE_ETH_LINK_SPEED_100G;
1447 : :
1448 : 0 : return 0;
1449 : : }
1450 : :
1451 : : #ifdef RTE_LIBRTE_FM10K_RX_OLFLAGS_ENABLE
1452 : : static const uint32_t *
1453 : 0 : fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev, size_t *no_of_elements)
1454 : : {
1455 [ # # # # ]: 0 : if (dev->rx_pkt_burst == fm10k_recv_pkts ||
1456 : : dev->rx_pkt_burst == fm10k_recv_scattered_pkts) {
1457 : : static uint32_t ptypes[] = {
1458 : : /* refers to rx_desc_to_ol_flags() */
1459 : : RTE_PTYPE_L2_ETHER,
1460 : : RTE_PTYPE_L3_IPV4,
1461 : : RTE_PTYPE_L3_IPV4_EXT,
1462 : : RTE_PTYPE_L3_IPV6,
1463 : : RTE_PTYPE_L3_IPV6_EXT,
1464 : : RTE_PTYPE_L4_TCP,
1465 : : RTE_PTYPE_L4_UDP,
1466 : : };
1467 : :
1468 : 0 : *no_of_elements = RTE_DIM(ptypes);
1469 : 0 : return ptypes;
1470 [ # # # # ]: 0 : } else if (dev->rx_pkt_burst == fm10k_recv_pkts_vec ||
1471 : : dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec) {
1472 : : static uint32_t ptypes_vec[] = {
1473 : : /* refers to fm10k_desc_to_pktype_v() */
1474 : : RTE_PTYPE_L3_IPV4,
1475 : : RTE_PTYPE_L3_IPV4_EXT,
1476 : : RTE_PTYPE_L3_IPV6,
1477 : : RTE_PTYPE_L3_IPV6_EXT,
1478 : : RTE_PTYPE_L4_TCP,
1479 : : RTE_PTYPE_L4_UDP,
1480 : : RTE_PTYPE_TUNNEL_GENEVE,
1481 : : RTE_PTYPE_TUNNEL_NVGRE,
1482 : : RTE_PTYPE_TUNNEL_VXLAN,
1483 : : RTE_PTYPE_TUNNEL_GRE,
1484 : : };
1485 : :
1486 : 0 : *no_of_elements = RTE_DIM(ptypes_vec);
1487 : 0 : return ptypes_vec;
1488 : : }
1489 : :
1490 : : return NULL;
1491 : : }
1492 : : #else
1493 : : static const uint32_t *
1494 : : fm10k_dev_supported_ptypes_get(struct rte_eth_dev *dev __rte_unused,
1495 : : size_t *no_of_elements)
1496 : : {
1497 : : return NULL;
1498 : : }
1499 : : #endif
1500 : :
1501 : : static int
1502 : 0 : fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1503 : : {
1504 : : s32 result;
1505 : : uint16_t mac_num = 0;
1506 : : uint32_t vid_idx, vid_bit, mac_index;
1507 : : struct fm10k_hw *hw;
1508 : : struct fm10k_macvlan_filter_info *macvlan;
1509 : 0 : struct rte_eth_dev_data *data = dev->data;
1510 : :
1511 : 0 : hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1512 : : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1513 : :
1514 [ # # ]: 0 : if (macvlan->nb_queue_pools > 0) { /* VMDQ mode */
1515 : 0 : PMD_INIT_LOG(ERR, "Cannot change VLAN filter in VMDQ mode");
1516 : 0 : return -EINVAL;
1517 : : }
1518 : :
1519 [ # # ]: 0 : if (vlan_id > RTE_ETH_VLAN_ID_MAX) {
1520 : 0 : PMD_INIT_LOG(ERR, "Invalid vlan_id: must be < 4096");
1521 : 0 : return -EINVAL;
1522 : : }
1523 : :
1524 : 0 : vid_idx = FM10K_VFTA_IDX(vlan_id);
1525 : 0 : vid_bit = FM10K_VFTA_BIT(vlan_id);
1526 : : /* this VLAN ID is already in the VLAN filter table, return SUCCESS */
1527 [ # # # # ]: 0 : if (on && (macvlan->vfta[vid_idx] & vid_bit))
1528 : : return 0;
1529 : : /* this VLAN ID is NOT in the VLAN filter table, cannot remove */
1530 [ # # # # ]: 0 : if (!on && !(macvlan->vfta[vid_idx] & vid_bit)) {
1531 : 0 : PMD_INIT_LOG(ERR, "Invalid vlan_id: not existing "
1532 : : "in the VLAN filter table");
1533 : 0 : return -EINVAL;
1534 : : }
1535 : :
1536 : : fm10k_mbx_lock(hw);
1537 : 0 : result = fm10k_update_vlan(hw, vlan_id, 0, on);
1538 : : fm10k_mbx_unlock(hw);
1539 [ # # ]: 0 : if (result != FM10K_SUCCESS) {
1540 : 0 : PMD_INIT_LOG(ERR, "VLAN update failed: %d", result);
1541 : 0 : return -EIO;
1542 : : }
1543 : :
1544 : 0 : for (mac_index = 0; (mac_index < FM10K_MAX_MACADDR_NUM) &&
1545 [ # # ]: 0 : (result == FM10K_SUCCESS); mac_index++) {
1546 [ # # ]: 0 : if (rte_is_zero_ether_addr(&data->mac_addrs[mac_index]))
1547 : 0 : continue;
1548 [ # # ]: 0 : if (mac_num > macvlan->mac_num - 1) {
1549 : 0 : PMD_INIT_LOG(ERR, "MAC address number "
1550 : : "not match");
1551 : 0 : break;
1552 : : }
1553 : : fm10k_mbx_lock(hw);
1554 : 0 : result = fm10k_update_uc_addr(hw, hw->mac.dglort_map,
1555 : 0 : data->mac_addrs[mac_index].addr_bytes,
1556 : : vlan_id, on, 0);
1557 : : fm10k_mbx_unlock(hw);
1558 : 0 : mac_num++;
1559 : : }
1560 [ # # ]: 0 : if (result != FM10K_SUCCESS) {
1561 : 0 : PMD_INIT_LOG(ERR, "MAC address update failed: %d", result);
1562 : 0 : return -EIO;
1563 : : }
1564 : :
1565 [ # # ]: 0 : if (on) {
1566 : 0 : macvlan->vlan_num++;
1567 : 0 : macvlan->vfta[vid_idx] |= vid_bit;
1568 : : } else {
1569 : 0 : macvlan->vlan_num--;
1570 : 0 : macvlan->vfta[vid_idx] &= ~vid_bit;
1571 : : }
1572 : : return 0;
1573 : : }
1574 : :
1575 : : static int
1576 : 0 : fm10k_vlan_offload_set(struct rte_eth_dev *dev __rte_unused,
1577 : : int mask __rte_unused)
1578 : : {
1579 : 0 : return 0;
1580 : : }
1581 : :
1582 : : /* Add/Remove a MAC address, and update filters to main VSI */
1583 : 0 : static void fm10k_MAC_filter_set_main_vsi(struct rte_eth_dev *dev,
1584 : : const u8 *mac, bool add, uint32_t pool)
1585 : : {
1586 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1587 : : struct fm10k_macvlan_filter_info *macvlan;
1588 : : uint32_t i, j, k;
1589 : :
1590 : : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1591 : :
1592 [ # # ]: 0 : if (pool != MAIN_VSI_POOL_NUMBER) {
1593 : 0 : PMD_DRV_LOG(ERR, "VMDQ not enabled, can't set "
1594 : : "mac to pool %u", pool);
1595 : 0 : return;
1596 : : }
1597 [ # # ]: 0 : for (i = 0, j = 0; j < FM10K_VFTA_SIZE; j++) {
1598 [ # # ]: 0 : if (!macvlan->vfta[j])
1599 : 0 : continue;
1600 [ # # ]: 0 : for (k = 0; k < FM10K_UINT32_BIT_SIZE; k++) {
1601 [ # # ]: 0 : if (!(macvlan->vfta[j] & (1 << k)))
1602 : 0 : continue;
1603 [ # # ]: 0 : if (i + 1 > macvlan->vlan_num) {
1604 : 0 : PMD_INIT_LOG(ERR, "vlan number not match");
1605 : 0 : return;
1606 : : }
1607 : : fm10k_mbx_lock(hw);
1608 : 0 : fm10k_update_uc_addr(hw, hw->mac.dglort_map, mac,
1609 : 0 : j * FM10K_UINT32_BIT_SIZE + k, add, 0);
1610 : : fm10k_mbx_unlock(hw);
1611 : : i++;
1612 : : }
1613 : : }
1614 : : }
1615 : :
1616 : : /* Add/Remove a MAC address, and update filters to VMDQ */
1617 : 0 : static void fm10k_MAC_filter_set_vmdq(struct rte_eth_dev *dev,
1618 : : const u8 *mac, bool add, uint32_t pool)
1619 : : {
1620 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1621 : : struct fm10k_macvlan_filter_info *macvlan;
1622 : : struct rte_eth_vmdq_rx_conf *vmdq_conf;
1623 : : uint32_t i;
1624 : :
1625 : : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1626 : : vmdq_conf = &dev->data->dev_conf.rx_adv_conf.vmdq_rx_conf;
1627 : :
1628 [ # # ]: 0 : if (pool > macvlan->nb_queue_pools) {
1629 : 0 : PMD_DRV_LOG(ERR, "Pool number %u invalid."
1630 : : " Max pool is %u",
1631 : : pool, macvlan->nb_queue_pools);
1632 : 0 : return;
1633 : : }
1634 [ # # ]: 0 : for (i = 0; i < vmdq_conf->nb_pool_maps; i++) {
1635 [ # # ]: 0 : if (!(vmdq_conf->pool_map[i].pools & (1UL << pool)))
1636 : 0 : continue;
1637 : : fm10k_mbx_lock(hw);
1638 : 0 : fm10k_update_uc_addr(hw, hw->mac.dglort_map + pool, mac,
1639 : 0 : vmdq_conf->pool_map[i].vlan_id, add, 0);
1640 : : fm10k_mbx_unlock(hw);
1641 : : }
1642 : : }
1643 : :
1644 : : /* Add/Remove a MAC address, and update filters */
1645 : 0 : static void fm10k_MAC_filter_set(struct rte_eth_dev *dev,
1646 : : const u8 *mac, bool add, uint32_t pool)
1647 : : {
1648 : : struct fm10k_macvlan_filter_info *macvlan;
1649 : :
1650 : 0 : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1651 : :
1652 [ # # ]: 0 : if (macvlan->nb_queue_pools > 0) /* VMDQ mode */
1653 : 0 : fm10k_MAC_filter_set_vmdq(dev, mac, add, pool);
1654 : : else
1655 : 0 : fm10k_MAC_filter_set_main_vsi(dev, mac, add, pool);
1656 : :
1657 [ # # ]: 0 : if (add)
1658 : 0 : macvlan->mac_num++;
1659 : : else
1660 : 0 : macvlan->mac_num--;
1661 : 0 : }
1662 : :
1663 : : /* Add a MAC address, and update filters */
1664 : : static int
1665 : 0 : fm10k_macaddr_add(struct rte_eth_dev *dev,
1666 : : struct rte_ether_addr *mac_addr,
1667 : : uint32_t index,
1668 : : uint32_t pool)
1669 : : {
1670 : : struct fm10k_macvlan_filter_info *macvlan;
1671 : :
1672 : 0 : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1673 : 0 : fm10k_MAC_filter_set(dev, mac_addr->addr_bytes, TRUE, pool);
1674 : 0 : macvlan->mac_vmdq_id[index] = pool;
1675 : 0 : return 0;
1676 : : }
1677 : :
1678 : : /* Remove a MAC address, and update filters */
1679 : : static void
1680 : 0 : fm10k_macaddr_remove(struct rte_eth_dev *dev, uint32_t index)
1681 : : {
1682 : 0 : struct rte_eth_dev_data *data = dev->data;
1683 : : struct fm10k_macvlan_filter_info *macvlan;
1684 : :
1685 : 0 : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1686 : 0 : fm10k_MAC_filter_set(dev, data->mac_addrs[index].addr_bytes,
1687 : 0 : FALSE, macvlan->mac_vmdq_id[index]);
1688 : 0 : macvlan->mac_vmdq_id[index] = 0;
1689 : 0 : }
1690 : :
1691 : : static inline int
1692 : : check_nb_desc(uint16_t min, uint16_t max, uint16_t mult, uint16_t request)
1693 : : {
1694 [ # # # # ]: 0 : if ((request < min) || (request > max) || ((request % mult) != 0))
1695 : : return -1;
1696 : : else
1697 : : return 0;
1698 : : }
1699 : :
1700 : :
1701 : : static inline int
1702 : : check_thresh(uint16_t min, uint16_t max, uint16_t div, uint16_t request)
1703 : : {
1704 [ # # # # ]: 0 : if ((request < min) || (request > max) || ((div % request) != 0))
1705 : : return -1;
1706 : : else
1707 : : return 0;
1708 : : }
1709 : :
1710 : : static inline int
1711 : 0 : handle_rxconf(struct fm10k_rx_queue *q, const struct rte_eth_rxconf *conf)
1712 : : {
1713 : : uint16_t rx_free_thresh;
1714 : :
1715 [ # # ]: 0 : if (conf->rx_free_thresh == 0)
1716 : : rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(q);
1717 : : else
1718 : : rx_free_thresh = conf->rx_free_thresh;
1719 : :
1720 : : /* make sure the requested threshold satisfies the constraints */
1721 : 0 : if (check_thresh(FM10K_RX_FREE_THRESH_MIN(q),
1722 : 0 : FM10K_RX_FREE_THRESH_MAX(q),
1723 [ # # ]: 0 : FM10K_RX_FREE_THRESH_DIV(q),
1724 : : rx_free_thresh)) {
1725 : 0 : PMD_INIT_LOG(ERR, "rx_free_thresh (%u) must be "
1726 : : "less than or equal to %u, "
1727 : : "greater than or equal to %u, "
1728 : : "and a divisor of %u",
1729 : : rx_free_thresh, FM10K_RX_FREE_THRESH_MAX(q),
1730 : : FM10K_RX_FREE_THRESH_MIN(q),
1731 : : FM10K_RX_FREE_THRESH_DIV(q));
1732 : 0 : return -EINVAL;
1733 : : }
1734 : :
1735 : 0 : q->alloc_thresh = rx_free_thresh;
1736 : 0 : q->drop_en = conf->rx_drop_en;
1737 : 0 : q->rx_deferred_start = conf->rx_deferred_start;
1738 : :
1739 : 0 : return 0;
1740 : : }
1741 : :
1742 : : /*
1743 : : * Hardware requires specific alignment for Rx packet buffers. At
1744 : : * least one of the following two conditions must be satisfied.
1745 : : * 1. Address is 512B aligned
1746 : : * 2. Address is 8B aligned and buffer does not cross 4K boundary.
1747 : : *
1748 : : * As such, the driver may need to adjust the DMA address within the
1749 : : * buffer by up to 512B.
1750 : : *
1751 : : * return 1 if the element size is valid, otherwise return 0.
1752 : : */
1753 : : static int
1754 : : mempool_element_size_valid(struct rte_mempool *mp)
1755 : : {
1756 : : uint32_t min_size;
1757 : :
1758 : : /* elt_size includes mbuf header and headroom */
1759 : 0 : min_size = mp->elt_size - sizeof(struct rte_mbuf) -
1760 : : RTE_PKTMBUF_HEADROOM;
1761 : :
1762 : : /* account for up to 512B of alignment */
1763 : : min_size -= FM10K_RX_DATABUF_ALIGN;
1764 : :
1765 : : /* sanity check for overflow */
1766 : 0 : if (min_size > mp->elt_size)
1767 : : return 0;
1768 : :
1769 : : /* size is valid */
1770 : : return 1;
1771 : : }
1772 : :
1773 : : static uint64_t fm10k_get_rx_queue_offloads_capa(struct rte_eth_dev *dev)
1774 : : {
1775 : : RTE_SET_USED(dev);
1776 : :
1777 : : return (uint64_t)(RTE_ETH_RX_OFFLOAD_SCATTER);
1778 : : }
1779 : :
1780 : : static uint64_t fm10k_get_rx_port_offloads_capa(struct rte_eth_dev *dev)
1781 : : {
1782 : : RTE_SET_USED(dev);
1783 : :
1784 : : return (uint64_t)(RTE_ETH_RX_OFFLOAD_VLAN_STRIP |
1785 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
1786 : : RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
1787 : : RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
1788 : : RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
1789 : : RTE_ETH_RX_OFFLOAD_RSS_HASH);
1790 : : }
1791 : :
1792 : : static int
1793 : 0 : fm10k_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1794 : : uint16_t nb_desc, unsigned int socket_id,
1795 : : const struct rte_eth_rxconf *conf, struct rte_mempool *mp)
1796 : : {
1797 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1798 : : struct fm10k_dev_info *dev_info =
1799 : : FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
1800 : : struct fm10k_rx_queue *q;
1801 : : const struct rte_memzone *mz;
1802 : : uint64_t offloads;
1803 : :
1804 : 0 : PMD_INIT_FUNC_TRACE();
1805 : :
1806 [ # # ]: 0 : offloads = conf->offloads | dev->data->dev_conf.rxmode.offloads;
1807 : :
1808 : : /* make sure the mempool element size can account for alignment. */
1809 : : if (!mempool_element_size_valid(mp)) {
1810 : 0 : PMD_INIT_LOG(ERR, "Error : Mempool element size is too small");
1811 : 0 : return -EINVAL;
1812 : : }
1813 : :
1814 : : /* make sure a valid number of descriptors have been requested */
1815 [ # # ]: 0 : if (check_nb_desc(FM10K_MIN_RX_DESC, FM10K_MAX_RX_DESC,
1816 : : FM10K_MULT_RX_DESC, nb_desc)) {
1817 : 0 : PMD_INIT_LOG(ERR, "Number of Rx descriptors (%u) must be "
1818 : : "less than or equal to %"PRIu32", "
1819 : : "greater than or equal to %u, "
1820 : : "and a multiple of %u",
1821 : : nb_desc, (uint32_t)FM10K_MAX_RX_DESC, FM10K_MIN_RX_DESC,
1822 : : FM10K_MULT_RX_DESC);
1823 : 0 : return -EINVAL;
1824 : : }
1825 : :
1826 : : /*
1827 : : * if this queue existed already, free the associated memory. The
1828 : : * queue cannot be reused in case we need to allocate memory on
1829 : : * different socket than was previously used.
1830 : : */
1831 [ # # ]: 0 : if (dev->data->rx_queues[queue_id] != NULL) {
1832 : 0 : rx_queue_free(dev->data->rx_queues[queue_id]);
1833 : 0 : dev->data->rx_queues[queue_id] = NULL;
1834 : : }
1835 : :
1836 : : /* allocate memory for the queue structure */
1837 : 0 : q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
1838 : : socket_id);
1839 [ # # ]: 0 : if (q == NULL) {
1840 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
1841 : 0 : return -ENOMEM;
1842 : : }
1843 : :
1844 : : /* setup queue */
1845 : 0 : q->mp = mp;
1846 : 0 : q->nb_desc = nb_desc;
1847 : 0 : q->nb_fake_desc = FM10K_MULT_RX_DESC;
1848 : 0 : q->port_id = dev->data->port_id;
1849 : 0 : q->queue_id = queue_id;
1850 : 0 : q->tail_ptr = (volatile uint32_t *)
1851 : 0 : &((uint32_t *)hw->hw_addr)[FM10K_RDT(queue_id)];
1852 : 0 : q->offloads = offloads;
1853 [ # # ]: 0 : if (handle_rxconf(q, conf)) {
1854 : 0 : rte_free(q);
1855 : 0 : return -EINVAL;
1856 : : }
1857 : : /* allocate memory for the software ring */
1858 : 0 : q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
1859 : 0 : (nb_desc + q->nb_fake_desc) * sizeof(struct rte_mbuf *),
1860 : : RTE_CACHE_LINE_SIZE, socket_id);
1861 [ # # ]: 0 : if (q->sw_ring == NULL) {
1862 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate software ring");
1863 : 0 : rte_free(q);
1864 : 0 : return -ENOMEM;
1865 : : }
1866 : :
1867 : : /*
1868 : : * allocate memory for the hardware descriptor ring. A memzone large
1869 : : * enough to hold the maximum ring size is requested to allow for
1870 : : * resizing in later calls to the queue setup function.
1871 : : */
1872 : 0 : mz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_id,
1873 : : FM10K_MAX_RX_RING_SZ, FM10K_ALIGN_RX_DESC,
1874 : : socket_id);
1875 [ # # ]: 0 : if (mz == NULL) {
1876 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
1877 : 0 : rte_free(q->sw_ring);
1878 : 0 : rte_free(q);
1879 : 0 : return -ENOMEM;
1880 : : }
1881 : 0 : q->hw_ring = mz->addr;
1882 : 0 : q->hw_ring_phys_addr = mz->iova;
1883 : :
1884 : : /* Check if number of descs satisfied Vector requirement */
1885 [ # # ]: 0 : if (!rte_is_power_of_2(nb_desc)) {
1886 : 0 : PMD_INIT_LOG(DEBUG, "queue[%d] doesn't meet Vector Rx "
1887 : : "preconditions - canceling the feature for "
1888 : : "the whole port[%d]",
1889 : : q->queue_id, q->port_id);
1890 : 0 : dev_info->rx_vec_allowed = false;
1891 : : } else
1892 : 0 : fm10k_rxq_vec_setup(q);
1893 : :
1894 : 0 : dev->data->rx_queues[queue_id] = q;
1895 : 0 : return 0;
1896 : : }
1897 : :
1898 : : static void
1899 : 0 : fm10k_rx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
1900 : : {
1901 : 0 : PMD_INIT_FUNC_TRACE();
1902 : :
1903 : 0 : rx_queue_free(dev->data->rx_queues[qid]);
1904 : 0 : }
1905 : :
1906 : : static inline int
1907 : 0 : handle_txconf(struct fm10k_tx_queue *q, const struct rte_eth_txconf *conf)
1908 : : {
1909 : : uint16_t tx_free_thresh;
1910 : : uint16_t tx_rs_thresh;
1911 : :
1912 : : /* constraint MACROs require that tx_free_thresh is configured
1913 : : * before tx_rs_thresh */
1914 [ # # ]: 0 : if (conf->tx_free_thresh == 0)
1915 : : tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(q);
1916 : : else
1917 : : tx_free_thresh = conf->tx_free_thresh;
1918 : :
1919 : : /* make sure the requested threshold satisfies the constraints */
1920 : 0 : if (check_thresh(FM10K_TX_FREE_THRESH_MIN(q),
1921 [ # # ]: 0 : FM10K_TX_FREE_THRESH_MAX(q),
1922 : : FM10K_TX_FREE_THRESH_DIV(q),
1923 : : tx_free_thresh)) {
1924 : 0 : PMD_INIT_LOG(ERR, "tx_free_thresh (%u) must be "
1925 : : "less than or equal to %u, "
1926 : : "greater than or equal to %u, "
1927 : : "and a divisor of %u",
1928 : : tx_free_thresh, FM10K_TX_FREE_THRESH_MAX(q),
1929 : : FM10K_TX_FREE_THRESH_MIN(q),
1930 : : FM10K_TX_FREE_THRESH_DIV(q));
1931 : 0 : return -EINVAL;
1932 : : }
1933 : :
1934 : 0 : q->free_thresh = tx_free_thresh;
1935 : :
1936 [ # # ]: 0 : if (conf->tx_rs_thresh == 0)
1937 : : tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(q);
1938 : : else
1939 : : tx_rs_thresh = conf->tx_rs_thresh;
1940 : :
1941 : 0 : q->tx_deferred_start = conf->tx_deferred_start;
1942 : :
1943 : : /* make sure the requested threshold satisfies the constraints */
1944 : 0 : if (check_thresh(FM10K_TX_RS_THRESH_MIN(q),
1945 [ # # ]: 0 : FM10K_TX_RS_THRESH_MAX(q),
1946 : : FM10K_TX_RS_THRESH_DIV(q),
1947 : : tx_rs_thresh)) {
1948 : 0 : PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be "
1949 : : "less than or equal to %u, "
1950 : : "greater than or equal to %u, "
1951 : : "and a divisor of %u",
1952 : : tx_rs_thresh, FM10K_TX_RS_THRESH_MAX(q),
1953 : : FM10K_TX_RS_THRESH_MIN(q),
1954 : : FM10K_TX_RS_THRESH_DIV(q));
1955 : 0 : return -EINVAL;
1956 : : }
1957 : :
1958 : 0 : q->rs_thresh = tx_rs_thresh;
1959 : :
1960 : 0 : return 0;
1961 : : }
1962 : :
1963 : : static uint64_t fm10k_get_tx_queue_offloads_capa(struct rte_eth_dev *dev)
1964 : : {
1965 : : RTE_SET_USED(dev);
1966 : :
1967 : : return 0;
1968 : : }
1969 : :
1970 : : static uint64_t fm10k_get_tx_port_offloads_capa(struct rte_eth_dev *dev)
1971 : : {
1972 : : RTE_SET_USED(dev);
1973 : :
1974 : : return (uint64_t)(RTE_ETH_TX_OFFLOAD_VLAN_INSERT |
1975 : : RTE_ETH_TX_OFFLOAD_MULTI_SEGS |
1976 : : RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
1977 : : RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
1978 : : RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
1979 : : RTE_ETH_TX_OFFLOAD_TCP_TSO);
1980 : : }
1981 : :
1982 : : static int
1983 : 0 : fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1984 : : uint16_t nb_desc, unsigned int socket_id,
1985 : : const struct rte_eth_txconf *conf)
1986 : : {
1987 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1988 : : struct fm10k_tx_queue *q;
1989 : : const struct rte_memzone *mz;
1990 : : uint64_t offloads;
1991 : :
1992 : 0 : PMD_INIT_FUNC_TRACE();
1993 : :
1994 : 0 : offloads = conf->offloads | dev->data->dev_conf.txmode.offloads;
1995 : :
1996 : : /* make sure a valid number of descriptors have been requested */
1997 [ # # ]: 0 : if (check_nb_desc(FM10K_MIN_TX_DESC, FM10K_MAX_TX_DESC,
1998 : : FM10K_MULT_TX_DESC, nb_desc)) {
1999 : 0 : PMD_INIT_LOG(ERR, "Number of Tx descriptors (%u) must be "
2000 : : "less than or equal to %"PRIu32", "
2001 : : "greater than or equal to %u, "
2002 : : "and a multiple of %u",
2003 : : nb_desc, (uint32_t)FM10K_MAX_TX_DESC, FM10K_MIN_TX_DESC,
2004 : : FM10K_MULT_TX_DESC);
2005 : 0 : return -EINVAL;
2006 : : }
2007 : :
2008 : : /*
2009 : : * if this queue existed already, free the associated memory. The
2010 : : * queue cannot be reused in case we need to allocate memory on
2011 : : * different socket than was previously used.
2012 : : */
2013 [ # # ]: 0 : if (dev->data->tx_queues[queue_id] != NULL) {
2014 : : struct fm10k_tx_queue *txq = dev->data->tx_queues[queue_id];
2015 : :
2016 : 0 : tx_queue_free(txq);
2017 : 0 : dev->data->tx_queues[queue_id] = NULL;
2018 : : }
2019 : :
2020 : : /* allocate memory for the queue structure */
2021 : 0 : q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
2022 : : socket_id);
2023 [ # # ]: 0 : if (q == NULL) {
2024 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
2025 : 0 : return -ENOMEM;
2026 : : }
2027 : :
2028 : : /* setup queue */
2029 : 0 : q->nb_desc = nb_desc;
2030 : 0 : q->port_id = dev->data->port_id;
2031 : 0 : q->queue_id = queue_id;
2032 : 0 : q->offloads = offloads;
2033 : 0 : q->ops = &def_txq_ops;
2034 : 0 : q->tail_ptr = (volatile uint32_t *)
2035 : 0 : &((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
2036 [ # # ]: 0 : if (handle_txconf(q, conf)) {
2037 : 0 : rte_free(q);
2038 : 0 : return -EINVAL;
2039 : : }
2040 : :
2041 : : /* allocate memory for the software ring */
2042 : 0 : q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
2043 : : nb_desc * sizeof(struct rte_mbuf *),
2044 : : RTE_CACHE_LINE_SIZE, socket_id);
2045 [ # # ]: 0 : if (q->sw_ring == NULL) {
2046 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate software ring");
2047 : 0 : rte_free(q);
2048 : 0 : return -ENOMEM;
2049 : : }
2050 : :
2051 : : /*
2052 : : * allocate memory for the hardware descriptor ring. A memzone large
2053 : : * enough to hold the maximum ring size is requested to allow for
2054 : : * resizing in later calls to the queue setup function.
2055 : : */
2056 : 0 : mz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_id,
2057 : : FM10K_MAX_TX_RING_SZ, FM10K_ALIGN_TX_DESC,
2058 : : socket_id);
2059 [ # # ]: 0 : if (mz == NULL) {
2060 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
2061 : 0 : rte_free(q->sw_ring);
2062 : 0 : rte_free(q);
2063 : 0 : return -ENOMEM;
2064 : : }
2065 : 0 : q->hw_ring = mz->addr;
2066 : 0 : q->hw_ring_phys_addr = mz->iova;
2067 : :
2068 : : /*
2069 : : * allocate memory for the RS bit tracker. Enough slots to hold the
2070 : : * descriptor index for each RS bit needing to be set are required.
2071 : : */
2072 : 0 : q->rs_tracker.list = rte_zmalloc_socket("fm10k rs tracker",
2073 : 0 : ((nb_desc + 1) / q->rs_thresh) *
2074 : : sizeof(uint16_t),
2075 : : RTE_CACHE_LINE_SIZE, socket_id);
2076 [ # # ]: 0 : if (q->rs_tracker.list == NULL) {
2077 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate RS bit tracker");
2078 : 0 : rte_free(q->sw_ring);
2079 : 0 : rte_free(q);
2080 : 0 : return -ENOMEM;
2081 : : }
2082 : :
2083 : 0 : dev->data->tx_queues[queue_id] = q;
2084 : 0 : return 0;
2085 : : }
2086 : :
2087 : : static void
2088 : 0 : fm10k_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid)
2089 : : {
2090 : 0 : struct fm10k_tx_queue *q = dev->data->tx_queues[qid];
2091 : 0 : PMD_INIT_FUNC_TRACE();
2092 : :
2093 : 0 : tx_queue_free(q);
2094 : 0 : }
2095 : :
2096 : : static int
2097 : 0 : fm10k_reta_update(struct rte_eth_dev *dev,
2098 : : struct rte_eth_rss_reta_entry64 *reta_conf,
2099 : : uint16_t reta_size)
2100 : : {
2101 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2102 : : uint16_t i, j, idx, shift;
2103 : : uint8_t mask;
2104 : : uint32_t reta;
2105 : :
2106 : 0 : PMD_INIT_FUNC_TRACE();
2107 : :
2108 [ # # ]: 0 : if (reta_size > FM10K_MAX_RSS_INDICES) {
2109 : 0 : PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
2110 : : "(%d) doesn't match the number hardware can supported "
2111 : : "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
2112 : 0 : return -EINVAL;
2113 : : }
2114 : :
2115 : : /*
2116 : : * Update Redirection Table RETA[n], n=0..31. The redirection table has
2117 : : * 128-entries in 32 registers
2118 : : */
2119 [ # # ]: 0 : for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
2120 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2121 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
2122 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2123 : : BIT_MASK_PER_UINT32);
2124 [ # # ]: 0 : if (mask == 0)
2125 : 0 : continue;
2126 : :
2127 : : reta = 0;
2128 [ # # ]: 0 : if (mask != BIT_MASK_PER_UINT32)
2129 : 0 : reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
2130 : :
2131 [ # # ]: 0 : for (j = 0; j < CHARS_PER_UINT32; j++) {
2132 [ # # ]: 0 : if (mask & (0x1 << j)) {
2133 [ # # ]: 0 : if (mask != 0xF)
2134 : 0 : reta &= ~(UINT8_MAX << CHAR_BIT * j);
2135 : 0 : reta |= reta_conf[idx].reta[shift + j] <<
2136 : 0 : (CHAR_BIT * j);
2137 : : }
2138 : : }
2139 : 0 : FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2), reta);
2140 : : }
2141 : :
2142 : : return 0;
2143 : : }
2144 : :
2145 : : static int
2146 : 0 : fm10k_reta_query(struct rte_eth_dev *dev,
2147 : : struct rte_eth_rss_reta_entry64 *reta_conf,
2148 : : uint16_t reta_size)
2149 : : {
2150 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2151 : : uint16_t i, j, idx, shift;
2152 : : uint8_t mask;
2153 : : uint32_t reta;
2154 : :
2155 : 0 : PMD_INIT_FUNC_TRACE();
2156 : :
2157 [ # # ]: 0 : if (reta_size < FM10K_MAX_RSS_INDICES) {
2158 : 0 : PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
2159 : : "(%d) doesn't match the number hardware can supported "
2160 : : "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
2161 : 0 : return -EINVAL;
2162 : : }
2163 : :
2164 : : /*
2165 : : * Read Redirection Table RETA[n], n=0..31. The redirection table has
2166 : : * 128-entries in 32 registers
2167 : : */
2168 [ # # ]: 0 : for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
2169 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
2170 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
2171 : 0 : mask = (uint8_t)((reta_conf[idx].mask >> shift) &
2172 : : BIT_MASK_PER_UINT32);
2173 [ # # ]: 0 : if (mask == 0)
2174 : 0 : continue;
2175 : :
2176 : 0 : reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
2177 [ # # ]: 0 : for (j = 0; j < CHARS_PER_UINT32; j++) {
2178 [ # # ]: 0 : if (mask & (0x1 << j))
2179 : 0 : reta_conf[idx].reta[shift + j] = ((reta >>
2180 : 0 : CHAR_BIT * j) & UINT8_MAX);
2181 : : }
2182 : : }
2183 : :
2184 : : return 0;
2185 : : }
2186 : :
2187 : : static int
2188 : 0 : fm10k_rss_hash_update(struct rte_eth_dev *dev,
2189 : : struct rte_eth_rss_conf *rss_conf)
2190 : : {
2191 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2192 : 0 : uint32_t *key = (uint32_t *)rss_conf->rss_key;
2193 : : uint32_t mrqc;
2194 : 0 : uint64_t hf = rss_conf->rss_hf;
2195 : : int i;
2196 : :
2197 : 0 : PMD_INIT_FUNC_TRACE();
2198 : :
2199 [ # # # # ]: 0 : if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
2200 : : FM10K_RSSRK_ENTRIES_PER_REG))
2201 : : return -EINVAL;
2202 : :
2203 [ # # ]: 0 : if (hf == 0)
2204 : : return -EINVAL;
2205 : :
2206 : : mrqc = 0;
2207 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
2208 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
2209 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
2210 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
2211 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
2212 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
2213 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
2214 : 0 : mrqc |= (hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
2215 : 0 : mrqc |= (hf & RTE_ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
2216 : :
2217 : : /* If the mapping doesn't fit any supported, return */
2218 [ # # ]: 0 : if (mrqc == 0)
2219 : : return -EINVAL;
2220 : :
2221 [ # # ]: 0 : if (key != NULL)
2222 [ # # ]: 0 : for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
2223 : 0 : FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
2224 : :
2225 : 0 : FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
2226 : :
2227 : 0 : return 0;
2228 : : }
2229 : :
2230 : : static int
2231 : 0 : fm10k_rss_hash_conf_get(struct rte_eth_dev *dev,
2232 : : struct rte_eth_rss_conf *rss_conf)
2233 : : {
2234 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2235 : 0 : uint32_t *key = (uint32_t *)rss_conf->rss_key;
2236 : : uint32_t mrqc;
2237 : : uint64_t hf;
2238 : : int i;
2239 : :
2240 : 0 : PMD_INIT_FUNC_TRACE();
2241 : :
2242 [ # # # # ]: 0 : if (key && (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
2243 : : FM10K_RSSRK_ENTRIES_PER_REG))
2244 : : return -EINVAL;
2245 : :
2246 [ # # ]: 0 : if (key != NULL)
2247 [ # # ]: 0 : for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
2248 : 0 : key[i] = FM10K_READ_REG(hw, FM10K_RSSRK(0, i));
2249 : :
2250 : 0 : mrqc = FM10K_READ_REG(hw, FM10K_MRQC(0));
2251 : : hf = 0;
2252 : 0 : hf |= (mrqc & FM10K_MRQC_IPV4) ? RTE_ETH_RSS_IPV4 : 0;
2253 : 0 : hf |= (mrqc & FM10K_MRQC_IPV6) ? RTE_ETH_RSS_IPV6 : 0;
2254 : 0 : hf |= (mrqc & FM10K_MRQC_IPV6) ? RTE_ETH_RSS_IPV6_EX : 0;
2255 : 0 : hf |= (mrqc & FM10K_MRQC_TCP_IPV4) ? RTE_ETH_RSS_NONFRAG_IPV4_TCP : 0;
2256 : 0 : hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? RTE_ETH_RSS_NONFRAG_IPV6_TCP : 0;
2257 : 0 : hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? RTE_ETH_RSS_IPV6_TCP_EX : 0;
2258 : 0 : hf |= (mrqc & FM10K_MRQC_UDP_IPV4) ? RTE_ETH_RSS_NONFRAG_IPV4_UDP : 0;
2259 : 0 : hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? RTE_ETH_RSS_NONFRAG_IPV6_UDP : 0;
2260 : 0 : hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? RTE_ETH_RSS_IPV6_UDP_EX : 0;
2261 : :
2262 : 0 : rss_conf->rss_hf = hf;
2263 : :
2264 : 0 : return 0;
2265 : : }
2266 : :
2267 : : static void
2268 : 0 : fm10k_dev_enable_intr_pf(struct rte_eth_dev *dev)
2269 : : {
2270 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2271 : : uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
2272 : :
2273 : : /* Bind all local non-queue interrupt to vector 0 */
2274 : : int_map |= FM10K_MISC_VEC_ID;
2275 : :
2276 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
2277 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
2278 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
2279 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
2280 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
2281 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
2282 : :
2283 : : /* Enable misc causes */
2284 : 0 : FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
2285 : : FM10K_EIMR_ENABLE(THI_FAULT) |
2286 : : FM10K_EIMR_ENABLE(FUM_FAULT) |
2287 : : FM10K_EIMR_ENABLE(MAILBOX) |
2288 : : FM10K_EIMR_ENABLE(SWITCHREADY) |
2289 : : FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
2290 : : FM10K_EIMR_ENABLE(SRAMERROR) |
2291 : : FM10K_EIMR_ENABLE(VFLR));
2292 : :
2293 : : /* Enable ITR 0 */
2294 : 0 : FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
2295 : : FM10K_ITR_MASK_CLEAR);
2296 : 0 : FM10K_WRITE_FLUSH(hw);
2297 : 0 : }
2298 : :
2299 : : static void
2300 : 0 : fm10k_dev_disable_intr_pf(struct rte_eth_dev *dev)
2301 : : {
2302 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2303 : : uint32_t int_map = FM10K_INT_MAP_DISABLE;
2304 : :
2305 : : int_map |= FM10K_MISC_VEC_ID;
2306 : :
2307 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_mailbox), int_map);
2308 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_pcie_fault), int_map);
2309 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_up_down), int_map);
2310 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_switch_event), int_map);
2311 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_sram), int_map);
2312 : 0 : FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_vflr), int_map);
2313 : :
2314 : : /* Disable misc causes */
2315 : 0 : FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_DISABLE(PCA_FAULT) |
2316 : : FM10K_EIMR_DISABLE(THI_FAULT) |
2317 : : FM10K_EIMR_DISABLE(FUM_FAULT) |
2318 : : FM10K_EIMR_DISABLE(MAILBOX) |
2319 : : FM10K_EIMR_DISABLE(SWITCHREADY) |
2320 : : FM10K_EIMR_DISABLE(SWITCHNOTREADY) |
2321 : : FM10K_EIMR_DISABLE(SRAMERROR) |
2322 : : FM10K_EIMR_DISABLE(VFLR));
2323 : :
2324 : : /* Disable ITR 0 */
2325 : 0 : FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_MASK_SET);
2326 : 0 : FM10K_WRITE_FLUSH(hw);
2327 : 0 : }
2328 : :
2329 : : static void
2330 : : fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)
2331 : : {
2332 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2333 : : uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
2334 : :
2335 : : /* Bind all local non-queue interrupt to vector 0 */
2336 : : int_map |= FM10K_MISC_VEC_ID;
2337 : :
2338 : : /* Only INT 0 available, other 15 are reserved. */
2339 : 0 : FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
2340 : :
2341 : : /* Enable ITR 0 */
2342 : 0 : FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
2343 : : FM10K_ITR_MASK_CLEAR);
2344 : 0 : FM10K_WRITE_FLUSH(hw);
2345 : 0 : }
2346 : :
2347 : : static void
2348 : : fm10k_dev_disable_intr_vf(struct rte_eth_dev *dev)
2349 : : {
2350 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2351 : : uint32_t int_map = FM10K_INT_MAP_DISABLE;
2352 : :
2353 : : int_map |= FM10K_MISC_VEC_ID;
2354 : :
2355 : : /* Only INT 0 available, other 15 are reserved. */
2356 : 0 : FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
2357 : :
2358 : : /* Disable ITR 0 */
2359 : 0 : FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_MASK_SET);
2360 : 0 : FM10K_WRITE_FLUSH(hw);
2361 : 0 : }
2362 : :
2363 : : static int
2364 : 0 : fm10k_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
2365 : : {
2366 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2367 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
2368 : :
2369 : : /* Enable ITR */
2370 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
2371 : 0 : FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
2372 : : FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
2373 : : else
2374 : 0 : FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
2375 : : FM10K_ITR_AUTOMASK | FM10K_ITR_MASK_CLEAR);
2376 : 0 : rte_intr_ack(pdev->intr_handle);
2377 : 0 : return 0;
2378 : : }
2379 : :
2380 : : static int
2381 : 0 : fm10k_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
2382 : : {
2383 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2384 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
2385 : :
2386 : : /* Disable ITR */
2387 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
2388 : 0 : FM10K_WRITE_REG(hw, FM10K_ITR(Q2V(pdev, queue_id)),
2389 : : FM10K_ITR_MASK_SET);
2390 : : else
2391 : 0 : FM10K_WRITE_REG(hw, FM10K_VFITR(Q2V(pdev, queue_id)),
2392 : : FM10K_ITR_MASK_SET);
2393 : 0 : return 0;
2394 : : }
2395 : :
2396 : : static int
2397 : 0 : fm10k_dev_rxq_interrupt_setup(struct rte_eth_dev *dev)
2398 : : {
2399 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2400 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
2401 : 0 : struct rte_intr_handle *intr_handle = pdev->intr_handle;
2402 : : uint32_t intr_vector, vec;
2403 : : uint16_t queue_id;
2404 : : int result = 0;
2405 : :
2406 : : /* fm10k needs one separate interrupt for mailbox,
2407 : : * so only drivers which support multiple interrupt vectors
2408 : : * e.g. vfio-pci can work for fm10k interrupt mode
2409 : : */
2410 [ # # ]: 0 : if (!rte_intr_cap_multiple(intr_handle) ||
2411 [ # # ]: 0 : dev->data->dev_conf.intr_conf.rxq == 0)
2412 : : return result;
2413 : :
2414 : 0 : intr_vector = dev->data->nb_rx_queues;
2415 : :
2416 : : /* disable interrupt first */
2417 : 0 : rte_intr_disable(intr_handle);
2418 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
2419 : 0 : fm10k_dev_disable_intr_pf(dev);
2420 : : else
2421 : : fm10k_dev_disable_intr_vf(dev);
2422 : :
2423 [ # # ]: 0 : if (rte_intr_efd_enable(intr_handle, intr_vector)) {
2424 : 0 : PMD_INIT_LOG(ERR, "Failed to init event fd");
2425 : : result = -EIO;
2426 : : }
2427 : :
2428 [ # # # # ]: 0 : if (rte_intr_dp_is_en(intr_handle) && !result) {
2429 [ # # ]: 0 : if (!rte_intr_vec_list_alloc(intr_handle, "intr_vec",
2430 : 0 : dev->data->nb_rx_queues)) {
2431 : : for (queue_id = 0, vec = FM10K_RX_VEC_START;
2432 [ # # ]: 0 : queue_id < dev->data->nb_rx_queues;
2433 : 0 : queue_id++) {
2434 : 0 : rte_intr_vec_list_index_set(intr_handle,
2435 : : queue_id, vec);
2436 : : int nb_efd =
2437 : 0 : rte_intr_nb_efd_get(intr_handle);
2438 [ # # ]: 0 : if (vec < (uint32_t)nb_efd - 1 +
2439 : : FM10K_RX_VEC_START)
2440 : 0 : vec++;
2441 : : }
2442 : : } else {
2443 : 0 : PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
2444 : : " intr_vec", dev->data->nb_rx_queues);
2445 : 0 : rte_intr_efd_disable(intr_handle);
2446 : : result = -ENOMEM;
2447 : : }
2448 : : }
2449 : :
2450 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf)
2451 : 0 : fm10k_dev_enable_intr_pf(dev);
2452 : : else
2453 : : fm10k_dev_enable_intr_vf(dev);
2454 : 0 : rte_intr_enable(intr_handle);
2455 : 0 : hw->mac.ops.update_int_moderator(hw);
2456 : 0 : return result;
2457 : : }
2458 : :
2459 : : static int
2460 : 0 : fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)
2461 : : {
2462 : : struct fm10k_fault fault;
2463 : : int err;
2464 : : const char *estr = "Unknown error";
2465 : :
2466 : : /* Process PCA fault */
2467 [ # # ]: 0 : if (eicr & FM10K_EICR_PCA_FAULT) {
2468 : 0 : err = fm10k_get_fault(hw, FM10K_PCA_FAULT, &fault);
2469 [ # # ]: 0 : if (err)
2470 : 0 : goto error;
2471 [ # # # # : 0 : switch (fault.type) {
# # # # ]
2472 : : case PCA_NO_FAULT:
2473 : : estr = "PCA_NO_FAULT"; break;
2474 : 0 : case PCA_UNMAPPED_ADDR:
2475 : 0 : estr = "PCA_UNMAPPED_ADDR"; break;
2476 : 0 : case PCA_BAD_QACCESS_PF:
2477 : 0 : estr = "PCA_BAD_QACCESS_PF"; break;
2478 : 0 : case PCA_BAD_QACCESS_VF:
2479 : 0 : estr = "PCA_BAD_QACCESS_VF"; break;
2480 : 0 : case PCA_MALICIOUS_REQ:
2481 : 0 : estr = "PCA_MALICIOUS_REQ"; break;
2482 : 0 : case PCA_POISONED_TLP:
2483 : 0 : estr = "PCA_POISONED_TLP"; break;
2484 : 0 : case PCA_TLP_ABORT:
2485 : 0 : estr = "PCA_TLP_ABORT"; break;
2486 : 0 : default:
2487 : 0 : goto error;
2488 : : }
2489 [ # # ]: 0 : PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2490 : : estr, fault.func ? "VF" : "PF", fault.func,
2491 : : fault.address, fault.specinfo);
2492 : : }
2493 : :
2494 : : /* Process THI fault */
2495 [ # # ]: 0 : if (eicr & FM10K_EICR_THI_FAULT) {
2496 : 0 : err = fm10k_get_fault(hw, FM10K_THI_FAULT, &fault);
2497 [ # # ]: 0 : if (err)
2498 : 0 : goto error;
2499 [ # # # ]: 0 : switch (fault.type) {
2500 : : case THI_NO_FAULT:
2501 : : estr = "THI_NO_FAULT"; break;
2502 : 0 : case THI_MAL_DIS_Q_FAULT:
2503 : 0 : estr = "THI_MAL_DIS_Q_FAULT"; break;
2504 : 0 : default:
2505 : 0 : goto error;
2506 : : }
2507 [ # # ]: 0 : PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2508 : : estr, fault.func ? "VF" : "PF", fault.func,
2509 : : fault.address, fault.specinfo);
2510 : : }
2511 : :
2512 : : /* Process FUM fault */
2513 [ # # ]: 0 : if (eicr & FM10K_EICR_FUM_FAULT) {
2514 : 0 : err = fm10k_get_fault(hw, FM10K_FUM_FAULT, &fault);
2515 [ # # ]: 0 : if (err)
2516 : 0 : goto error;
2517 [ # # # # : 0 : switch (fault.type) {
# # # # #
# # # # ]
2518 : : case FUM_NO_FAULT:
2519 : : estr = "FUM_NO_FAULT"; break;
2520 : 0 : case FUM_UNMAPPED_ADDR:
2521 : 0 : estr = "FUM_UNMAPPED_ADDR"; break;
2522 : 0 : case FUM_POISONED_TLP:
2523 : 0 : estr = "FUM_POISONED_TLP"; break;
2524 : 0 : case FUM_BAD_VF_QACCESS:
2525 : 0 : estr = "FUM_BAD_VF_QACCESS"; break;
2526 : 0 : case FUM_ADD_DECODE_ERR:
2527 : 0 : estr = "FUM_ADD_DECODE_ERR"; break;
2528 : 0 : case FUM_RO_ERROR:
2529 : 0 : estr = "FUM_RO_ERROR"; break;
2530 : 0 : case FUM_QPRC_CRC_ERROR:
2531 : 0 : estr = "FUM_QPRC_CRC_ERROR"; break;
2532 : 0 : case FUM_CSR_TIMEOUT:
2533 : 0 : estr = "FUM_CSR_TIMEOUT"; break;
2534 : 0 : case FUM_INVALID_TYPE:
2535 : 0 : estr = "FUM_INVALID_TYPE"; break;
2536 : 0 : case FUM_INVALID_LENGTH:
2537 : 0 : estr = "FUM_INVALID_LENGTH"; break;
2538 : 0 : case FUM_INVALID_BE:
2539 : 0 : estr = "FUM_INVALID_BE"; break;
2540 : 0 : case FUM_INVALID_ALIGN:
2541 : 0 : estr = "FUM_INVALID_ALIGN"; break;
2542 : 0 : default:
2543 : 0 : goto error;
2544 : : }
2545 [ # # ]: 0 : PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
2546 : : estr, fault.func ? "VF" : "PF", fault.func,
2547 : : fault.address, fault.specinfo);
2548 : : }
2549 : :
2550 : : return 0;
2551 : 0 : error:
2552 : 0 : PMD_INIT_LOG(ERR, "Failed to handle fault event.");
2553 : 0 : return err;
2554 : : }
2555 : :
2556 : : /**
2557 : : * PF interrupt handler triggered by NIC for handling specific interrupt.
2558 : : *
2559 : : * @param handle
2560 : : * Pointer to interrupt handle.
2561 : : * @param param
2562 : : * The address of parameter (struct rte_eth_dev *) registered before.
2563 : : *
2564 : : * @return
2565 : : * void
2566 : : */
2567 : : static void
2568 : 0 : fm10k_dev_interrupt_handler_pf(void *param)
2569 : : {
2570 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2571 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2572 : : uint32_t cause, status;
2573 : : struct fm10k_dev_info *dev_info =
2574 : : FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2575 : : int status_mbx;
2576 : : s32 err;
2577 : :
2578 [ # # ]: 0 : if (hw->mac.type != fm10k_mac_pf)
2579 : : return;
2580 : :
2581 : 0 : cause = FM10K_READ_REG(hw, FM10K_EICR);
2582 : :
2583 : : /* Handle PCI fault cases */
2584 [ # # ]: 0 : if (cause & FM10K_EICR_FAULT_MASK) {
2585 : 0 : PMD_INIT_LOG(ERR, "INT: find fault!");
2586 : 0 : fm10k_dev_handle_fault(hw, cause);
2587 : : }
2588 : :
2589 : : /* Handle switch up/down */
2590 [ # # ]: 0 : if (cause & FM10K_EICR_SWITCHNOTREADY)
2591 : 0 : PMD_INIT_LOG(ERR, "INT: Switch is not ready");
2592 : :
2593 [ # # ]: 0 : if (cause & FM10K_EICR_SWITCHREADY) {
2594 : 0 : PMD_INIT_LOG(INFO, "INT: Switch is ready");
2595 [ # # ]: 0 : if (dev_info->sm_down == 1) {
2596 : : fm10k_mbx_lock(hw);
2597 : :
2598 : : /* For recreating logical ports */
2599 : 0 : status_mbx = hw->mac.ops.update_lport_state(hw,
2600 : 0 : hw->mac.dglort_map, MAX_LPORT_NUM, 1);
2601 [ # # ]: 0 : if (status_mbx == FM10K_SUCCESS)
2602 : 0 : PMD_INIT_LOG(INFO,
2603 : : "INT: Recreated Logical port");
2604 : : else
2605 : 0 : PMD_INIT_LOG(INFO,
2606 : : "INT: Logical ports weren't recreated");
2607 : :
2608 : 0 : status_mbx = hw->mac.ops.update_xcast_mode(hw,
2609 : 0 : hw->mac.dglort_map, FM10K_XCAST_MODE_NONE);
2610 [ # # ]: 0 : if (status_mbx != FM10K_SUCCESS)
2611 : 0 : PMD_INIT_LOG(ERR, "Failed to set XCAST mode");
2612 : :
2613 : : fm10k_mbx_unlock(hw);
2614 : :
2615 : : /* first clear the internal SW recording structure */
2616 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode &
2617 : : RTE_ETH_MQ_RX_VMDQ_FLAG))
2618 : 0 : fm10k_vlan_filter_set(dev, hw->mac.default_vid,
2619 : : false);
2620 : :
2621 : 0 : fm10k_MAC_filter_set(dev, hw->mac.addr, false,
2622 : : MAIN_VSI_POOL_NUMBER);
2623 : :
2624 : : /*
2625 : : * Add default mac address and vlan for the logical
2626 : : * ports that have been created, leave to the
2627 : : * application to fully recover Rx filtering.
2628 : : */
2629 : 0 : fm10k_MAC_filter_set(dev, hw->mac.addr, true,
2630 : : MAIN_VSI_POOL_NUMBER);
2631 : :
2632 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.mq_mode &
2633 : : RTE_ETH_MQ_RX_VMDQ_FLAG))
2634 : 0 : fm10k_vlan_filter_set(dev, hw->mac.default_vid,
2635 : : true);
2636 : :
2637 : 0 : dev_info->sm_down = 0;
2638 : 0 : rte_eth_dev_callback_process(dev,
2639 : : RTE_ETH_EVENT_INTR_LSC,
2640 : : NULL);
2641 : : }
2642 : : }
2643 : :
2644 : : /* Handle mailbox message */
2645 : : fm10k_mbx_lock(hw);
2646 : 0 : err = hw->mbx.ops.process(hw, &hw->mbx);
2647 : : fm10k_mbx_unlock(hw);
2648 : :
2649 [ # # ]: 0 : if (err == FM10K_ERR_RESET_REQUESTED) {
2650 : 0 : PMD_INIT_LOG(INFO, "INT: Switch is down");
2651 : 0 : dev_info->sm_down = 1;
2652 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
2653 : : }
2654 : :
2655 : : /* Handle SRAM error */
2656 [ # # ]: 0 : if (cause & FM10K_EICR_SRAMERROR) {
2657 : 0 : PMD_INIT_LOG(ERR, "INT: SRAM error on PEP");
2658 : :
2659 : 0 : status = FM10K_READ_REG(hw, FM10K_SRAM_IP);
2660 : : /* Write to clear pending bits */
2661 : 0 : FM10K_WRITE_REG(hw, FM10K_SRAM_IP, status);
2662 : :
2663 : : /* Todo: print out error message after shared code updates */
2664 : : }
2665 : :
2666 : : /* Clear these 3 events if having any */
2667 : 0 : cause &= FM10K_EICR_SWITCHNOTREADY | FM10K_EICR_MAILBOX |
2668 : : FM10K_EICR_SWITCHREADY;
2669 [ # # ]: 0 : if (cause)
2670 : 0 : FM10K_WRITE_REG(hw, FM10K_EICR, cause);
2671 : :
2672 : : /* Re-enable interrupt from device side */
2673 : 0 : FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
2674 : : FM10K_ITR_MASK_CLEAR);
2675 : : /* Re-enable interrupt from host side */
2676 : 0 : rte_intr_ack(dev->intr_handle);
2677 : : }
2678 : :
2679 : : /**
2680 : : * VF interrupt handler triggered by NIC for handling specific interrupt.
2681 : : *
2682 : : * @param handle
2683 : : * Pointer to interrupt handle.
2684 : : * @param param
2685 : : * The address of parameter (struct rte_eth_dev *) registered before.
2686 : : *
2687 : : * @return
2688 : : * void
2689 : : */
2690 : : static void
2691 : 0 : fm10k_dev_interrupt_handler_vf(void *param)
2692 : : {
2693 : : struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
2694 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2695 : : struct fm10k_mbx_info *mbx = &hw->mbx;
2696 : : struct fm10k_dev_info *dev_info =
2697 : : FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2698 : 0 : const enum fm10k_mbx_state state = mbx->state;
2699 : : int status_mbx;
2700 : :
2701 [ # # ]: 0 : if (hw->mac.type != fm10k_mac_vf)
2702 : : return;
2703 : :
2704 : : /* Handle mailbox message if lock is acquired */
2705 : : fm10k_mbx_lock(hw);
2706 : 0 : hw->mbx.ops.process(hw, &hw->mbx);
2707 : : fm10k_mbx_unlock(hw);
2708 : :
2709 [ # # # # ]: 0 : if (state == FM10K_STATE_OPEN && mbx->state == FM10K_STATE_CONNECT) {
2710 : 0 : PMD_INIT_LOG(INFO, "INT: Switch has gone down");
2711 : :
2712 : : fm10k_mbx_lock(hw);
2713 : 0 : hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
2714 : : MAX_LPORT_NUM, 1);
2715 : : fm10k_mbx_unlock(hw);
2716 : :
2717 : : /* Setting reset flag */
2718 : 0 : dev_info->sm_down = 1;
2719 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
2720 : : }
2721 : :
2722 [ # # ]: 0 : if (dev_info->sm_down == 1 &&
2723 [ # # ]: 0 : hw->mac.dglort_map == FM10K_DGLORTMAP_ZERO) {
2724 : 0 : PMD_INIT_LOG(INFO, "INT: Switch has gone up");
2725 : : fm10k_mbx_lock(hw);
2726 : 0 : status_mbx = hw->mac.ops.update_xcast_mode(hw,
2727 : 0 : hw->mac.dglort_map, FM10K_XCAST_MODE_NONE);
2728 [ # # ]: 0 : if (status_mbx != FM10K_SUCCESS)
2729 : 0 : PMD_INIT_LOG(ERR, "Failed to set XCAST mode");
2730 : : fm10k_mbx_unlock(hw);
2731 : :
2732 : : /* first clear the internal SW recording structure */
2733 : 0 : fm10k_vlan_filter_set(dev, hw->mac.default_vid, false);
2734 : 0 : fm10k_MAC_filter_set(dev, hw->mac.addr, false,
2735 : : MAIN_VSI_POOL_NUMBER);
2736 : :
2737 : : /*
2738 : : * Add default mac address and vlan for the logical ports that
2739 : : * have been created, leave to the application to fully recover
2740 : : * Rx filtering.
2741 : : */
2742 : 0 : fm10k_MAC_filter_set(dev, hw->mac.addr, true,
2743 : : MAIN_VSI_POOL_NUMBER);
2744 : 0 : fm10k_vlan_filter_set(dev, hw->mac.default_vid, true);
2745 : :
2746 : 0 : dev_info->sm_down = 0;
2747 : 0 : rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
2748 : : }
2749 : :
2750 : : /* Re-enable interrupt from device side */
2751 : 0 : FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
2752 : : FM10K_ITR_MASK_CLEAR);
2753 : : /* Re-enable interrupt from host side */
2754 : 0 : rte_intr_ack(dev->intr_handle);
2755 : : }
2756 : :
2757 : : /* Mailbox message handler in VF */
2758 : : static const struct fm10k_msg_data fm10k_msgdata_vf[] = {
2759 : : FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
2760 : : FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
2761 : : FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
2762 : : FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
2763 : : };
2764 : :
2765 : : static int
2766 [ # # ]: 0 : fm10k_setup_mbx_service(struct fm10k_hw *hw)
2767 : : {
2768 : : int err = 0;
2769 : :
2770 : : /* Initialize mailbox lock */
2771 : : fm10k_mbx_initlock(hw);
2772 : :
2773 : : /* Replace default message handler with new ones */
2774 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_vf)
2775 : 0 : err = hw->mbx.ops.register_handlers(&hw->mbx, fm10k_msgdata_vf);
2776 : :
2777 [ # # ]: 0 : if (err) {
2778 : 0 : PMD_INIT_LOG(ERR, "Failed to register mailbox handler.err:%d",
2779 : : err);
2780 : 0 : return err;
2781 : : }
2782 : : /* Connect to SM for PF device or PF for VF device */
2783 : 0 : return hw->mbx.ops.connect(hw, &hw->mbx);
2784 : : }
2785 : :
2786 : : static void
2787 : : fm10k_close_mbx_service(struct fm10k_hw *hw)
2788 : : {
2789 : : /* Disconnect from SM for PF device or PF for VF device */
2790 : 0 : hw->mbx.ops.disconnect(hw, &hw->mbx);
2791 : : }
2792 : :
2793 : : static int
2794 : 0 : fm10k_dev_close(struct rte_eth_dev *dev)
2795 : : {
2796 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2797 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
2798 : 0 : struct rte_intr_handle *intr_handle = pdev->intr_handle;
2799 : : int ret;
2800 : :
2801 : 0 : PMD_INIT_FUNC_TRACE();
2802 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2803 : : return 0;
2804 : :
2805 : : fm10k_mbx_lock(hw);
2806 : 0 : hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
2807 : : MAX_LPORT_NUM, false);
2808 : : fm10k_mbx_unlock(hw);
2809 : :
2810 : : /* allow 100ms for device to quiesce */
2811 : 0 : rte_delay_us(FM10K_SWITCH_QUIESCE_US);
2812 : :
2813 : : /* Stop mailbox service first */
2814 : : fm10k_close_mbx_service(hw);
2815 : :
2816 : 0 : ret = fm10k_dev_stop(dev);
2817 : :
2818 : 0 : fm10k_dev_queue_release(dev);
2819 : 0 : fm10k_stop_hw(hw);
2820 : :
2821 : : /* disable uio/vfio intr */
2822 : 0 : rte_intr_disable(intr_handle);
2823 : :
2824 : : /*PF/VF has different interrupt handling mechanism */
2825 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf) {
2826 : : /* disable interrupt */
2827 : 0 : fm10k_dev_disable_intr_pf(dev);
2828 : :
2829 : : /* unregister callback func to eal lib */
2830 : 0 : rte_intr_callback_unregister(intr_handle,
2831 : : fm10k_dev_interrupt_handler_pf, (void *)dev);
2832 : : } else {
2833 : : /* disable interrupt */
2834 : : fm10k_dev_disable_intr_vf(dev);
2835 : :
2836 : 0 : rte_intr_callback_unregister(intr_handle,
2837 : : fm10k_dev_interrupt_handler_vf, (void *)dev);
2838 : : }
2839 : :
2840 : : return ret;
2841 : : }
2842 : :
2843 : : static const struct eth_dev_ops fm10k_eth_dev_ops = {
2844 : : .dev_configure = fm10k_dev_configure,
2845 : : .dev_start = fm10k_dev_start,
2846 : : .dev_stop = fm10k_dev_stop,
2847 : : .dev_close = fm10k_dev_close,
2848 : : .promiscuous_enable = fm10k_dev_promiscuous_enable,
2849 : : .promiscuous_disable = fm10k_dev_promiscuous_disable,
2850 : : .allmulticast_enable = fm10k_dev_allmulticast_enable,
2851 : : .allmulticast_disable = fm10k_dev_allmulticast_disable,
2852 : : .stats_get = fm10k_stats_get,
2853 : : .xstats_get = fm10k_xstats_get,
2854 : : .xstats_get_names = fm10k_xstats_get_names,
2855 : : .stats_reset = fm10k_stats_reset,
2856 : : .xstats_reset = fm10k_stats_reset,
2857 : : .link_update = fm10k_link_update,
2858 : : .dev_infos_get = fm10k_dev_infos_get,
2859 : : .dev_supported_ptypes_get = fm10k_dev_supported_ptypes_get,
2860 : : .vlan_filter_set = fm10k_vlan_filter_set,
2861 : : .vlan_offload_set = fm10k_vlan_offload_set,
2862 : : .mac_addr_add = fm10k_macaddr_add,
2863 : : .mac_addr_remove = fm10k_macaddr_remove,
2864 : : .rx_queue_start = fm10k_dev_rx_queue_start,
2865 : : .rx_queue_stop = fm10k_dev_rx_queue_stop,
2866 : : .tx_queue_start = fm10k_dev_tx_queue_start,
2867 : : .tx_queue_stop = fm10k_dev_tx_queue_stop,
2868 : : .rx_queue_setup = fm10k_rx_queue_setup,
2869 : : .rx_queue_release = fm10k_rx_queue_release,
2870 : : .tx_queue_setup = fm10k_tx_queue_setup,
2871 : : .tx_queue_release = fm10k_tx_queue_release,
2872 : : .rx_queue_intr_enable = fm10k_dev_rx_queue_intr_enable,
2873 : : .rx_queue_intr_disable = fm10k_dev_rx_queue_intr_disable,
2874 : : .reta_update = fm10k_reta_update,
2875 : : .reta_query = fm10k_reta_query,
2876 : : .rss_hash_update = fm10k_rss_hash_update,
2877 : : .rss_hash_conf_get = fm10k_rss_hash_conf_get,
2878 : : };
2879 : :
2880 : 0 : static int ftag_check_handler(__rte_unused const char *key,
2881 : : const char *value, __rte_unused void *opaque)
2882 : : {
2883 [ # # ]: 0 : if (strcmp(value, "1"))
2884 : 0 : return -1;
2885 : :
2886 : : return 0;
2887 : : }
2888 : :
2889 : : static int
2890 : 0 : fm10k_check_ftag(struct rte_devargs *devargs)
2891 : : {
2892 : : struct rte_kvargs *kvlist;
2893 : : const char *ftag_key = "enable_ftag";
2894 : :
2895 [ # # ]: 0 : if (devargs == NULL)
2896 : : return 0;
2897 : :
2898 : 0 : kvlist = rte_kvargs_parse(devargs->args, NULL);
2899 [ # # ]: 0 : if (kvlist == NULL)
2900 : : return 0;
2901 : :
2902 [ # # ]: 0 : if (!rte_kvargs_count(kvlist, ftag_key)) {
2903 : 0 : rte_kvargs_free(kvlist);
2904 : 0 : return 0;
2905 : : }
2906 : : /* FTAG is enabled when there's key-value pair: enable_ftag=1 */
2907 [ # # ]: 0 : if (rte_kvargs_process(kvlist, ftag_key,
2908 : : ftag_check_handler, NULL) < 0) {
2909 : 0 : rte_kvargs_free(kvlist);
2910 : 0 : return 0;
2911 : : }
2912 : 0 : rte_kvargs_free(kvlist);
2913 : :
2914 : 0 : return 1;
2915 : : }
2916 : :
2917 : : static uint16_t
2918 : 0 : fm10k_xmit_pkts_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
2919 : : uint16_t nb_pkts)
2920 : : {
2921 : : uint16_t nb_tx = 0;
2922 : : struct fm10k_tx_queue *txq = (struct fm10k_tx_queue *)tx_queue;
2923 : :
2924 [ # # ]: 0 : while (nb_pkts) {
2925 : : uint16_t ret, num;
2926 : :
2927 : 0 : num = (uint16_t)RTE_MIN(nb_pkts, txq->rs_thresh);
2928 : 0 : ret = fm10k_xmit_fixed_burst_vec(tx_queue, &tx_pkts[nb_tx],
2929 : : num);
2930 : 0 : nb_tx += ret;
2931 : 0 : nb_pkts -= ret;
2932 [ # # ]: 0 : if (ret < num)
2933 : : break;
2934 : : }
2935 : :
2936 : 0 : return nb_tx;
2937 : : }
2938 : :
2939 : : static void __rte_cold
2940 : 0 : fm10k_set_tx_function(struct rte_eth_dev *dev)
2941 : : {
2942 : : struct fm10k_tx_queue *txq;
2943 : : int i;
2944 : : int use_sse = 1;
2945 : : uint16_t tx_ftag_en = 0;
2946 : :
2947 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
2948 : : /* primary process has set the ftag flag and offloads */
2949 : 0 : txq = dev->data->tx_queues[0];
2950 [ # # # # ]: 0 : if (fm10k_tx_vec_condition_check(txq) ||
2951 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
2952 : 0 : dev->tx_pkt_burst = fm10k_xmit_pkts;
2953 : 0 : dev->tx_pkt_prepare = fm10k_prep_pkts;
2954 : 0 : PMD_INIT_LOG(DEBUG, "Use regular Tx func");
2955 : : } else {
2956 : 0 : PMD_INIT_LOG(DEBUG, "Use vector Tx func");
2957 : 0 : dev->tx_pkt_burst = fm10k_xmit_pkts_vec;
2958 : 0 : dev->tx_pkt_prepare = NULL;
2959 : : }
2960 : 0 : return;
2961 : : }
2962 : :
2963 [ # # ]: 0 : if (fm10k_check_ftag(dev->device->devargs))
2964 : : tx_ftag_en = 1;
2965 : :
2966 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2967 : 0 : txq = dev->data->tx_queues[i];
2968 : 0 : txq->tx_ftag_en = tx_ftag_en;
2969 : : /* Check if Vector Tx is satisfied */
2970 [ # # # # ]: 0 : if (fm10k_tx_vec_condition_check(txq) ||
2971 : 0 : rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)
2972 : : use_sse = 0;
2973 : : }
2974 : :
2975 [ # # ]: 0 : if (use_sse) {
2976 : 0 : PMD_INIT_LOG(DEBUG, "Use vector Tx func");
2977 [ # # ]: 0 : for (i = 0; i < dev->data->nb_tx_queues; i++) {
2978 : 0 : txq = dev->data->tx_queues[i];
2979 : 0 : fm10k_txq_vec_setup(txq);
2980 : : }
2981 : 0 : dev->tx_pkt_burst = fm10k_xmit_pkts_vec;
2982 : 0 : dev->tx_pkt_prepare = NULL;
2983 : : } else {
2984 : 0 : dev->tx_pkt_burst = fm10k_xmit_pkts;
2985 : 0 : dev->tx_pkt_prepare = fm10k_prep_pkts;
2986 : 0 : PMD_INIT_LOG(DEBUG, "Use regular Tx func");
2987 : : }
2988 : : }
2989 : :
2990 : : static void __rte_cold
2991 : 0 : fm10k_set_rx_function(struct rte_eth_dev *dev)
2992 : : {
2993 : : struct fm10k_dev_info *dev_info =
2994 : 0 : FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
2995 : : uint16_t i, rx_using_sse;
2996 : : uint16_t rx_ftag_en = 0;
2997 : :
2998 [ # # ]: 0 : if (fm10k_check_ftag(dev->device->devargs))
2999 : : rx_ftag_en = 1;
3000 : :
3001 : : /* In order to allow Vector Rx there are a few configuration
3002 : : * conditions to be met.
3003 : : */
3004 [ # # ]: 0 : if (!fm10k_rx_vec_condition_check(dev) &&
3005 [ # # # # : 0 : dev_info->rx_vec_allowed && !rx_ftag_en &&
# # ]
3006 : 0 : rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_128) {
3007 [ # # ]: 0 : if (dev->data->scattered_rx)
3008 : 0 : dev->rx_pkt_burst = fm10k_recv_scattered_pkts_vec;
3009 : : else
3010 : 0 : dev->rx_pkt_burst = fm10k_recv_pkts_vec;
3011 [ # # ]: 0 : } else if (dev->data->scattered_rx)
3012 : 0 : dev->rx_pkt_burst = fm10k_recv_scattered_pkts;
3013 : : else
3014 : 0 : dev->rx_pkt_burst = fm10k_recv_pkts;
3015 : :
3016 : 0 : rx_using_sse =
3017 [ # # # # ]: 0 : (dev->rx_pkt_burst == fm10k_recv_scattered_pkts_vec ||
3018 : : dev->rx_pkt_burst == fm10k_recv_pkts_vec);
3019 : :
3020 [ # # ]: 0 : if (rx_using_sse)
3021 : 0 : PMD_INIT_LOG(DEBUG, "Use vector Rx func");
3022 : : else
3023 : 0 : PMD_INIT_LOG(DEBUG, "Use regular Rx func");
3024 : :
3025 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY)
3026 : : return;
3027 : :
3028 [ # # ]: 0 : for (i = 0; i < dev->data->nb_rx_queues; i++) {
3029 : 0 : struct fm10k_rx_queue *rxq = dev->data->rx_queues[i];
3030 : :
3031 : 0 : rxq->rx_using_sse = rx_using_sse;
3032 : 0 : rxq->rx_ftag_en = rx_ftag_en;
3033 : : }
3034 : : }
3035 : :
3036 : : static void
3037 : : fm10k_params_init(struct rte_eth_dev *dev)
3038 : : {
3039 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3040 : : struct fm10k_dev_info *info =
3041 : : FM10K_DEV_PRIVATE_TO_INFO(dev->data->dev_private);
3042 : :
3043 : : /* Initialize bus info. Normally we would call fm10k_get_bus_info(), but
3044 : : * there is no way to get link status without reading BAR4. Until this
3045 : : * works, assume we have maximum bandwidth.
3046 : : * @todo - fix bus info
3047 : : */
3048 : 0 : hw->bus_caps.speed = fm10k_bus_speed_8000;
3049 : 0 : hw->bus_caps.width = fm10k_bus_width_pcie_x8;
3050 : 0 : hw->bus_caps.payload = fm10k_bus_payload_512;
3051 : 0 : hw->bus.speed = fm10k_bus_speed_8000;
3052 : 0 : hw->bus.width = fm10k_bus_width_pcie_x8;
3053 : 0 : hw->bus.payload = fm10k_bus_payload_256;
3054 : :
3055 : 0 : info->rx_vec_allowed = true;
3056 : 0 : info->sm_down = false;
3057 : : }
3058 : :
3059 : : static int
3060 : 0 : eth_fm10k_dev_init(struct rte_eth_dev *dev)
3061 : : {
3062 : 0 : struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
3063 : 0 : struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(dev);
3064 : 0 : struct rte_intr_handle *intr_handle = pdev->intr_handle;
3065 : : int diag, i, ret;
3066 : : struct fm10k_macvlan_filter_info *macvlan;
3067 : :
3068 : 0 : PMD_INIT_FUNC_TRACE();
3069 : :
3070 : 0 : dev->dev_ops = &fm10k_eth_dev_ops;
3071 : 0 : dev->rx_queue_count = fm10k_dev_rx_queue_count;
3072 : 0 : dev->rx_descriptor_status = fm10k_dev_rx_descriptor_status;
3073 : 0 : dev->tx_descriptor_status = fm10k_dev_tx_descriptor_status;
3074 : 0 : dev->rx_pkt_burst = &fm10k_recv_pkts;
3075 : 0 : dev->tx_pkt_burst = &fm10k_xmit_pkts;
3076 : 0 : dev->tx_pkt_prepare = &fm10k_prep_pkts;
3077 : :
3078 : : /*
3079 : : * Primary process does the whole initialization, for secondary
3080 : : * processes, we just select the same Rx and Tx function as primary.
3081 : : */
3082 [ # # ]: 0 : if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
3083 : 0 : fm10k_set_rx_function(dev);
3084 : 0 : fm10k_set_tx_function(dev);
3085 : 0 : return 0;
3086 : : }
3087 : :
3088 : 0 : rte_eth_copy_pci_info(dev, pdev);
3089 : 0 : dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
3090 : :
3091 [ # # ]: 0 : macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
3092 : : memset(macvlan, 0, sizeof(*macvlan));
3093 : : /* Vendor and Device ID need to be set before init of shared code */
3094 : : memset(hw, 0, sizeof(*hw));
3095 : 0 : hw->device_id = pdev->id.device_id;
3096 : 0 : hw->vendor_id = pdev->id.vendor_id;
3097 : 0 : hw->subsystem_device_id = pdev->id.subsystem_device_id;
3098 : 0 : hw->subsystem_vendor_id = pdev->id.subsystem_vendor_id;
3099 : : hw->revision_id = 0;
3100 : 0 : hw->hw_addr = (void *)pdev->mem_resource[0].addr;
3101 [ # # ]: 0 : if (hw->hw_addr == NULL) {
3102 : 0 : PMD_INIT_LOG(ERR, "Bad mem resource."
3103 : : " Try to refuse unused devices.");
3104 : 0 : return -EIO;
3105 : : }
3106 : :
3107 : : /* Store fm10k_adapter pointer */
3108 : 0 : hw->back = dev->data->dev_private;
3109 : :
3110 : : /* Initialize the shared code */
3111 : 0 : diag = fm10k_init_shared_code(hw);
3112 [ # # ]: 0 : if (diag != FM10K_SUCCESS) {
3113 : 0 : PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
3114 : 0 : return -EIO;
3115 : : }
3116 : :
3117 : : /* Initialize parameters */
3118 : : fm10k_params_init(dev);
3119 : :
3120 : : /* Initialize the hw */
3121 : 0 : diag = fm10k_init_hw(hw);
3122 [ # # ]: 0 : if (diag != FM10K_SUCCESS) {
3123 : 0 : PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
3124 : 0 : return -EIO;
3125 : : }
3126 : :
3127 : : /* Initialize MAC address(es) */
3128 : 0 : dev->data->mac_addrs = rte_zmalloc("fm10k",
3129 : : RTE_ETHER_ADDR_LEN * FM10K_MAX_MACADDR_NUM, 0);
3130 [ # # ]: 0 : if (dev->data->mac_addrs == NULL) {
3131 : 0 : PMD_INIT_LOG(ERR, "Cannot allocate memory for MAC addresses");
3132 : 0 : return -ENOMEM;
3133 : : }
3134 : :
3135 : 0 : diag = fm10k_read_mac_addr(hw);
3136 : :
3137 : 0 : rte_ether_addr_copy((const struct rte_ether_addr *)hw->mac.addr,
3138 [ # # ]: 0 : &dev->data->mac_addrs[0]);
3139 : :
3140 [ # # ]: 0 : if (diag != FM10K_SUCCESS ||
3141 : : !rte_is_valid_assigned_ether_addr(dev->data->mac_addrs)) {
3142 : :
3143 : : /* Generate a random addr */
3144 : 0 : rte_eth_random_addr(hw->mac.addr);
3145 : 0 : memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN);
3146 : 0 : rte_ether_addr_copy((const struct rte_ether_addr *)hw->mac.addr,
3147 : 0 : &dev->data->mac_addrs[0]);
3148 : : }
3149 : :
3150 : : /* Reset the hw statistics */
3151 : 0 : diag = fm10k_stats_reset(dev);
3152 [ # # ]: 0 : if (diag != 0) {
3153 : 0 : PMD_INIT_LOG(ERR, "Stats reset failed: %d", diag);
3154 : : ret = diag;
3155 : 0 : goto err_stat;
3156 : : }
3157 : :
3158 : : /* Reset the hw */
3159 : 0 : diag = fm10k_reset_hw(hw);
3160 [ # # ]: 0 : if (diag != FM10K_SUCCESS) {
3161 : 0 : PMD_INIT_LOG(ERR, "Hardware reset failed: %d", diag);
3162 : : ret = -EIO;
3163 : 0 : goto err_reset_hw;
3164 : : }
3165 : :
3166 : : /* Setup mailbox service */
3167 : 0 : diag = fm10k_setup_mbx_service(hw);
3168 [ # # ]: 0 : if (diag != FM10K_SUCCESS) {
3169 : 0 : PMD_INIT_LOG(ERR, "Failed to setup mailbox: %d", diag);
3170 : : ret = -EIO;
3171 : 0 : goto err_mbx;
3172 : : }
3173 : :
3174 : : /*PF/VF has different interrupt handling mechanism */
3175 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf) {
3176 : : /* register callback func to eal lib */
3177 : 0 : rte_intr_callback_register(intr_handle,
3178 : : fm10k_dev_interrupt_handler_pf, (void *)dev);
3179 : :
3180 : : /* enable MISC interrupt */
3181 : 0 : fm10k_dev_enable_intr_pf(dev);
3182 : : } else { /* VF */
3183 : 0 : rte_intr_callback_register(intr_handle,
3184 : : fm10k_dev_interrupt_handler_vf, (void *)dev);
3185 : :
3186 : : fm10k_dev_enable_intr_vf(dev);
3187 : : }
3188 : :
3189 : : /* Enable intr after callback registered */
3190 : 0 : rte_intr_enable(intr_handle);
3191 : :
3192 : 0 : hw->mac.ops.update_int_moderator(hw);
3193 : :
3194 : : /* Make sure Switch Manager is ready before going forward. */
3195 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf) {
3196 : 0 : bool switch_ready = false;
3197 : :
3198 [ # # ]: 0 : for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
3199 : : fm10k_mbx_lock(hw);
3200 : 0 : hw->mac.ops.get_host_state(hw, &switch_ready);
3201 : : fm10k_mbx_unlock(hw);
3202 [ # # ]: 0 : if (switch_ready == true)
3203 : : break;
3204 : : /* Delay some time to acquire async LPORT_MAP info. */
3205 : 0 : rte_delay_us(WAIT_SWITCH_MSG_US);
3206 : : }
3207 : :
3208 [ # # ]: 0 : if (switch_ready == false) {
3209 : 0 : PMD_INIT_LOG(ERR, "switch is not ready");
3210 : : ret = -1;
3211 : 0 : goto err_switch_ready;
3212 : : }
3213 : : }
3214 : :
3215 : : /*
3216 : : * Below function will trigger operations on mailbox, acquire lock to
3217 : : * avoid race condition from interrupt handler. Operations on mailbox
3218 : : * FIFO will trigger interrupt to PF/SM, in which interrupt handler
3219 : : * will handle and generate an interrupt to our side. Then, FIFO in
3220 : : * mailbox will be touched.
3221 : : */
3222 : : fm10k_mbx_lock(hw);
3223 : : /* Enable port first */
3224 : 0 : hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map,
3225 : : MAX_LPORT_NUM, 1);
3226 : :
3227 : : /* Set unicast mode by default. App can change to other mode in other
3228 : : * API func.
3229 : : */
3230 : 0 : hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
3231 : : FM10K_XCAST_MODE_NONE);
3232 : :
3233 : : fm10k_mbx_unlock(hw);
3234 : :
3235 : : /* Make sure default VID is ready before going forward. */
3236 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf) {
3237 [ # # ]: 0 : for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
3238 [ # # ]: 0 : if (hw->mac.default_vid)
3239 : : break;
3240 : : /* Delay some time to acquire async port VLAN info. */
3241 : 0 : rte_delay_us(WAIT_SWITCH_MSG_US);
3242 : : }
3243 : :
3244 [ # # ]: 0 : if (!hw->mac.default_vid) {
3245 : 0 : PMD_INIT_LOG(ERR, "default VID is not ready");
3246 : : ret = -1;
3247 : 0 : goto err_vid;
3248 : : }
3249 : : }
3250 : :
3251 : : /* Add default mac address */
3252 : 0 : fm10k_MAC_filter_set(dev, hw->mac.addr, true,
3253 : : MAIN_VSI_POOL_NUMBER);
3254 : :
3255 : 0 : return 0;
3256 : :
3257 : : err_vid:
3258 : 0 : err_switch_ready:
3259 : 0 : rte_intr_disable(intr_handle);
3260 : :
3261 [ # # ]: 0 : if (hw->mac.type == fm10k_mac_pf) {
3262 : 0 : fm10k_dev_disable_intr_pf(dev);
3263 : 0 : rte_intr_callback_unregister(intr_handle,
3264 : : fm10k_dev_interrupt_handler_pf, (void *)dev);
3265 : : } else {
3266 : : fm10k_dev_disable_intr_vf(dev);
3267 : 0 : rte_intr_callback_unregister(intr_handle,
3268 : : fm10k_dev_interrupt_handler_vf, (void *)dev);
3269 : : }
3270 : :
3271 : 0 : err_mbx:
3272 : 0 : err_reset_hw:
3273 : 0 : err_stat:
3274 : 0 : rte_free(dev->data->mac_addrs);
3275 : 0 : dev->data->mac_addrs = NULL;
3276 : :
3277 : 0 : return ret;
3278 : : }
3279 : :
3280 : : static int
3281 : 0 : eth_fm10k_dev_uninit(struct rte_eth_dev *dev)
3282 : : {
3283 : 0 : PMD_INIT_FUNC_TRACE();
3284 : 0 : fm10k_dev_close(dev);
3285 : 0 : return 0;
3286 : : }
3287 : :
3288 : 0 : static int eth_fm10k_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3289 : : struct rte_pci_device *pci_dev)
3290 : : {
3291 : 0 : return rte_eth_dev_pci_generic_probe(pci_dev,
3292 : : sizeof(struct fm10k_adapter), eth_fm10k_dev_init);
3293 : : }
3294 : :
3295 : 0 : static int eth_fm10k_pci_remove(struct rte_pci_device *pci_dev)
3296 : : {
3297 : 0 : return rte_eth_dev_pci_generic_remove(pci_dev, eth_fm10k_dev_uninit);
3298 : : }
3299 : :
3300 : : /*
3301 : : * The set of PCI devices this driver supports. This driver will enable both PF
3302 : : * and SRIOV-VF devices.
3303 : : */
3304 : : static const struct rte_pci_id pci_id_fm10k_map[] = {
3305 : : { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_PF) },
3306 : : { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_SDI_FM10420_QDA2) },
3307 : : { RTE_PCI_DEVICE(FM10K_INTEL_VENDOR_ID, FM10K_DEV_ID_VF) },
3308 : : { .vendor_id = 0, /* sentinel */ },
3309 : : };
3310 : :
3311 : : static struct rte_pci_driver rte_pmd_fm10k = {
3312 : : .id_table = pci_id_fm10k_map,
3313 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
3314 : : .probe = eth_fm10k_pci_probe,
3315 : : .remove = eth_fm10k_pci_remove,
3316 : : };
3317 : :
3318 : 253 : RTE_PMD_REGISTER_PCI(net_fm10k, rte_pmd_fm10k);
3319 : : RTE_PMD_REGISTER_PCI_TABLE(net_fm10k, pci_id_fm10k_map);
3320 : : RTE_PMD_REGISTER_KMOD_DEP(net_fm10k, "* igb_uio | uio_pci_generic | vfio-pci");
3321 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_init, init, NOTICE);
3322 [ - + ]: 253 : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_driver, driver, NOTICE);
3323 : : #ifdef RTE_ETHDEV_DEBUG_RX
3324 : : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_rx, rx, DEBUG);
3325 : : #endif
3326 : : #ifdef RTE_ETHDEV_DEBUG_TX
3327 : : RTE_LOG_REGISTER_SUFFIX(fm10k_logtype_tx, tx, DEBUG);
3328 : : #endif
|