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