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