4 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <rte_ethdev.h>
35 #include <rte_malloc.h>
36 #include <rte_memzone.h>
37 #include <rte_string_fns.h>
39 #include <rte_spinlock.h>
42 #include "base/fm10k_api.h"
44 /* Default delay to acquire mailbox lock */
45 #define FM10K_MBXLOCK_DELAY_US 20
46 #define UINT64_LOWER_32BITS_MASK 0x00000000ffffffffULL
48 /* Max try times to acquire switch status */
49 #define MAX_QUERY_SWITCH_STATE_TIMES 10
50 /* Wait interval to get switch status */
51 #define WAIT_SWITCH_MSG_US 100000
52 /* Number of chars per uint32 type */
53 #define CHARS_PER_UINT32 (sizeof(uint32_t))
54 #define BIT_MASK_PER_UINT32 ((1 << CHARS_PER_UINT32) - 1)
56 static void fm10k_close_mbx_service(struct fm10k_hw *hw);
57 static void fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev);
58 static void fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev);
59 static void fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev);
60 static void fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev);
61 static inline int fm10k_glort_valid(struct fm10k_hw *hw);
64 fm10k_mbx_initlock(struct fm10k_hw *hw)
66 rte_spinlock_init(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
70 fm10k_mbx_lock(struct fm10k_hw *hw)
72 while (!rte_spinlock_trylock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back)))
73 rte_delay_us(FM10K_MBXLOCK_DELAY_US);
77 fm10k_mbx_unlock(struct fm10k_hw *hw)
79 rte_spinlock_unlock(FM10K_DEV_PRIVATE_TO_MBXLOCK(hw->back));
83 * reset queue to initial state, allocate software buffers used when starting
86 * return -ENOMEM if buffers cannot be allocated
87 * return -EINVAL if buffers do not satisfy alignment condition
90 rx_queue_reset(struct fm10k_rx_queue *q)
94 PMD_INIT_FUNC_TRACE();
96 diag = rte_mempool_get_bulk(q->mp, (void **)q->sw_ring, q->nb_desc);
100 for (i = 0; i < q->nb_desc; ++i) {
101 fm10k_pktmbuf_reset(q->sw_ring[i], q->port_id);
102 if (!fm10k_addr_alignment_valid(q->sw_ring[i])) {
103 rte_mempool_put_bulk(q->mp, (void **)q->sw_ring,
107 dma_addr = MBUF_DMA_ADDR_DEFAULT(q->sw_ring[i]);
108 q->hw_ring[i].q.pkt_addr = dma_addr;
109 q->hw_ring[i].q.hdr_addr = dma_addr;
114 q->next_trigger = q->alloc_thresh - 1;
115 FM10K_PCI_REG_WRITE(q->tail_ptr, q->nb_desc - 1);
120 * clean queue, descriptor rings, free software buffers used when stopping
124 rx_queue_clean(struct fm10k_rx_queue *q)
126 union fm10k_rx_desc zero = {.q = {0, 0, 0, 0} };
128 PMD_INIT_FUNC_TRACE();
130 /* zero descriptor rings */
131 for (i = 0; i < q->nb_desc; ++i)
132 q->hw_ring[i] = zero;
134 /* free software buffers */
135 for (i = 0; i < q->nb_desc; ++i) {
137 rte_pktmbuf_free_seg(q->sw_ring[i]);
138 q->sw_ring[i] = NULL;
144 * free all queue memory used when releasing the queue (i.e. configure)
147 rx_queue_free(struct fm10k_rx_queue *q)
149 PMD_INIT_FUNC_TRACE();
151 PMD_INIT_LOG(DEBUG, "Freeing rx queue %p", q);
154 rte_free(q->sw_ring);
163 * disable RX queue, wait unitl HW finished necessary flush operation
166 rx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
170 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(qnum));
171 FM10K_WRITE_REG(hw, FM10K_RXQCTL(qnum),
172 reg & ~FM10K_RXQCTL_ENABLE);
174 /* Wait 100us at most */
175 for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
177 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(i));
178 if (!(reg & FM10K_RXQCTL_ENABLE))
182 if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
189 * reset queue to initial state, allocate software buffers used when starting
193 tx_queue_reset(struct fm10k_tx_queue *q)
195 PMD_INIT_FUNC_TRACE();
199 q->nb_free = q->nb_desc - 1;
200 q->free_trigger = q->nb_free - q->free_thresh;
201 fifo_reset(&q->rs_tracker, (q->nb_desc + 1) / q->rs_thresh);
202 FM10K_PCI_REG_WRITE(q->tail_ptr, 0);
206 * clean queue, descriptor rings, free software buffers used when stopping
210 tx_queue_clean(struct fm10k_tx_queue *q)
212 struct fm10k_tx_desc zero = {0, 0, 0, 0, 0, 0};
214 PMD_INIT_FUNC_TRACE();
216 /* zero descriptor rings */
217 for (i = 0; i < q->nb_desc; ++i)
218 q->hw_ring[i] = zero;
220 /* free software buffers */
221 for (i = 0; i < q->nb_desc; ++i) {
223 rte_pktmbuf_free_seg(q->sw_ring[i]);
224 q->sw_ring[i] = NULL;
230 * free all queue memory used when releasing the queue (i.e. configure)
233 tx_queue_free(struct fm10k_tx_queue *q)
235 PMD_INIT_FUNC_TRACE();
237 PMD_INIT_LOG(DEBUG, "Freeing tx queue %p", q);
239 if (q->rs_tracker.list) {
240 rte_free(q->rs_tracker.list);
241 q->rs_tracker.list = NULL;
244 rte_free(q->sw_ring);
253 * disable TX queue, wait unitl HW finished necessary flush operation
256 tx_queue_disable(struct fm10k_hw *hw, uint16_t qnum)
260 reg = FM10K_READ_REG(hw, FM10K_TXDCTL(qnum));
261 FM10K_WRITE_REG(hw, FM10K_TXDCTL(qnum),
262 reg & ~FM10K_TXDCTL_ENABLE);
264 /* Wait 100us at most */
265 for (i = 0; i < FM10K_QUEUE_DISABLE_TIMEOUT; i++) {
267 reg = FM10K_READ_REG(hw, FM10K_TXDCTL(i));
268 if (!(reg & FM10K_TXDCTL_ENABLE))
272 if (i == FM10K_QUEUE_DISABLE_TIMEOUT)
279 fm10k_dev_configure(struct rte_eth_dev *dev)
281 PMD_INIT_FUNC_TRACE();
283 if (dev->data->dev_conf.rxmode.hw_strip_crc == 0)
284 PMD_INIT_LOG(WARNING, "fm10k always strip CRC");
290 fm10k_dev_mq_rx_configure(struct rte_eth_dev *dev)
292 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
293 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
294 uint32_t mrqc, *key, i, reta, j;
297 #define RSS_KEY_SIZE 40
298 static uint8_t rss_intel_key[RSS_KEY_SIZE] = {
299 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
300 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
301 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
302 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
303 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA,
306 if (dev->data->nb_rx_queues == 1 ||
307 dev_conf->rxmode.mq_mode != ETH_MQ_RX_RSS ||
308 dev_conf->rx_adv_conf.rss_conf.rss_hf == 0)
311 /* random key is rss_intel_key (default) or user provided (rss_key) */
312 if (dev_conf->rx_adv_conf.rss_conf.rss_key == NULL)
313 key = (uint32_t *)rss_intel_key;
315 key = (uint32_t *)dev_conf->rx_adv_conf.rss_conf.rss_key;
317 /* Now fill our hash function seeds, 4 bytes at a time */
318 for (i = 0; i < RSS_KEY_SIZE / sizeof(*key); ++i)
319 FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
322 * Fill in redirection table
323 * The byte-swap is needed because NIC registers are in
324 * little-endian order.
327 for (i = 0, j = 0; i < FM10K_RETA_SIZE; i++, j++) {
328 if (j == dev->data->nb_rx_queues)
330 reta = (reta << CHAR_BIT) | j;
332 FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2),
337 * Generate RSS hash based on packet types, TCP/UDP
338 * port numbers and/or IPv4/v6 src and dst addresses
340 hf = dev_conf->rx_adv_conf.rss_conf.rss_hf;
342 mrqc |= (hf & ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
343 mrqc |= (hf & ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
344 mrqc |= (hf & ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
345 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
346 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
347 mrqc |= (hf & ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
348 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
349 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
350 mrqc |= (hf & ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
353 PMD_INIT_LOG(ERR, "Specified RSS mode 0x%"PRIx64"is not"
358 FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
362 fm10k_dev_tx_init(struct rte_eth_dev *dev)
364 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
366 struct fm10k_tx_queue *txq;
370 /* Disable TXINT to avoid possible interrupt */
371 for (i = 0; i < hw->mac.max_queues; i++)
372 FM10K_WRITE_REG(hw, FM10K_TXINT(i),
373 3 << FM10K_TXINT_TIMER_SHIFT);
376 for (i = 0; i < dev->data->nb_tx_queues; ++i) {
377 txq = dev->data->tx_queues[i];
378 base_addr = txq->hw_ring_phys_addr;
379 size = txq->nb_desc * sizeof(struct fm10k_tx_desc);
381 /* disable queue to avoid issues while updating state */
382 ret = tx_queue_disable(hw, i);
384 PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
388 /* set location and size for descriptor ring */
389 FM10K_WRITE_REG(hw, FM10K_TDBAL(i),
390 base_addr & UINT64_LOWER_32BITS_MASK);
391 FM10K_WRITE_REG(hw, FM10K_TDBAH(i),
392 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
393 FM10K_WRITE_REG(hw, FM10K_TDLEN(i), size);
399 fm10k_dev_rx_init(struct rte_eth_dev *dev)
401 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
403 struct fm10k_rx_queue *rxq;
406 uint32_t rxdctl = FM10K_RXDCTL_WRITE_BACK_MIN_DELAY;
409 /* Disable RXINT to avoid possible interrupt */
410 for (i = 0; i < hw->mac.max_queues; i++)
411 FM10K_WRITE_REG(hw, FM10K_RXINT(i),
412 3 << FM10K_RXINT_TIMER_SHIFT);
414 /* Setup RX queues */
415 for (i = 0; i < dev->data->nb_rx_queues; ++i) {
416 rxq = dev->data->rx_queues[i];
417 base_addr = rxq->hw_ring_phys_addr;
418 size = rxq->nb_desc * sizeof(union fm10k_rx_desc);
420 /* disable queue to avoid issues while updating state */
421 ret = rx_queue_disable(hw, i);
423 PMD_INIT_LOG(ERR, "failed to disable queue %d", i);
427 /* Setup the Base and Length of the Rx Descriptor Ring */
428 FM10K_WRITE_REG(hw, FM10K_RDBAL(i),
429 base_addr & UINT64_LOWER_32BITS_MASK);
430 FM10K_WRITE_REG(hw, FM10K_RDBAH(i),
431 base_addr >> (CHAR_BIT * sizeof(uint32_t)));
432 FM10K_WRITE_REG(hw, FM10K_RDLEN(i), size);
434 /* Configure the Rx buffer size for one buff without split */
435 buf_size = (uint16_t)(rte_pktmbuf_data_room_size(rxq->mp) -
436 RTE_PKTMBUF_HEADROOM);
437 /* As RX buffer is aligned to 512B within mbuf, some bytes are
438 * reserved for this purpose, and the worst case could be 511B.
439 * But SRR reg assumes all buffers have the same size. In order
440 * to fill the gap, we'll have to consider the worst case and
441 * assume 512B is reserved. If we don't do so, it's possible
442 * for HW to overwrite data to next mbuf.
444 buf_size -= FM10K_RX_DATABUF_ALIGN;
446 FM10K_WRITE_REG(hw, FM10K_SRRCTL(i),
447 buf_size >> FM10K_SRRCTL_BSIZEPKT_SHIFT);
449 /* It adds dual VLAN length for supporting dual VLAN */
450 if ((dev->data->dev_conf.rxmode.max_rx_pkt_len +
451 2 * FM10K_VLAN_TAG_SIZE) > buf_size ||
452 dev->data->dev_conf.rxmode.enable_scatter) {
454 dev->data->scattered_rx = 1;
455 dev->rx_pkt_burst = fm10k_recv_scattered_pkts;
456 reg = FM10K_READ_REG(hw, FM10K_SRRCTL(i));
457 reg |= FM10K_SRRCTL_BUFFER_CHAINING_EN;
458 FM10K_WRITE_REG(hw, FM10K_SRRCTL(i), reg);
461 /* Enable drop on empty, it's RO for VF */
462 if (hw->mac.type == fm10k_mac_pf && rxq->drop_en)
463 rxdctl |= FM10K_RXDCTL_DROP_ON_EMPTY;
465 FM10K_WRITE_REG(hw, FM10K_RXDCTL(i), rxdctl);
466 FM10K_WRITE_FLUSH(hw);
469 /* Configure RSS if applicable */
470 fm10k_dev_mq_rx_configure(dev);
475 fm10k_dev_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
477 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
480 struct fm10k_rx_queue *rxq;
482 PMD_INIT_FUNC_TRACE();
484 if (rx_queue_id < dev->data->nb_rx_queues) {
485 rxq = dev->data->rx_queues[rx_queue_id];
486 err = rx_queue_reset(rxq);
487 if (err == -ENOMEM) {
488 PMD_INIT_LOG(ERR, "Failed to alloc memory : %d", err);
490 } else if (err == -EINVAL) {
491 PMD_INIT_LOG(ERR, "Invalid buffer address alignment :"
496 /* Setup the HW Rx Head and Tail Descriptor Pointers
497 * Note: this must be done AFTER the queue is enabled on real
498 * hardware, but BEFORE the queue is enabled when using the
499 * emulation platform. Do it in both places for now and remove
500 * this comment and the following two register writes when the
501 * emulation platform is no longer being used.
503 FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
504 FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
506 /* Set PF ownership flag for PF devices */
507 reg = FM10K_READ_REG(hw, FM10K_RXQCTL(rx_queue_id));
508 if (hw->mac.type == fm10k_mac_pf)
509 reg |= FM10K_RXQCTL_PF;
510 reg |= FM10K_RXQCTL_ENABLE;
511 /* enable RX queue */
512 FM10K_WRITE_REG(hw, FM10K_RXQCTL(rx_queue_id), reg);
513 FM10K_WRITE_FLUSH(hw);
515 /* Setup the HW Rx Head and Tail Descriptor Pointers
516 * Note: this must be done AFTER the queue is enabled
518 FM10K_WRITE_REG(hw, FM10K_RDH(rx_queue_id), 0);
519 FM10K_WRITE_REG(hw, FM10K_RDT(rx_queue_id), rxq->nb_desc - 1);
526 fm10k_dev_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
528 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
530 PMD_INIT_FUNC_TRACE();
532 if (rx_queue_id < dev->data->nb_rx_queues) {
533 /* Disable RX queue */
534 rx_queue_disable(hw, rx_queue_id);
536 /* Free mbuf and clean HW ring */
537 rx_queue_clean(dev->data->rx_queues[rx_queue_id]);
544 fm10k_dev_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
546 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
547 /** @todo - this should be defined in the shared code */
548 #define FM10K_TXDCTL_WRITE_BACK_MIN_DELAY 0x00010000
549 uint32_t txdctl = FM10K_TXDCTL_WRITE_BACK_MIN_DELAY;
552 PMD_INIT_FUNC_TRACE();
554 if (tx_queue_id < dev->data->nb_tx_queues) {
555 tx_queue_reset(dev->data->tx_queues[tx_queue_id]);
557 /* reset head and tail pointers */
558 FM10K_WRITE_REG(hw, FM10K_TDH(tx_queue_id), 0);
559 FM10K_WRITE_REG(hw, FM10K_TDT(tx_queue_id), 0);
561 /* enable TX queue */
562 FM10K_WRITE_REG(hw, FM10K_TXDCTL(tx_queue_id),
563 FM10K_TXDCTL_ENABLE | txdctl);
564 FM10K_WRITE_FLUSH(hw);
572 fm10k_dev_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
574 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
576 PMD_INIT_FUNC_TRACE();
578 if (tx_queue_id < dev->data->nb_tx_queues) {
579 tx_queue_disable(hw, tx_queue_id);
580 tx_queue_clean(dev->data->tx_queues[tx_queue_id]);
586 static inline int fm10k_glort_valid(struct fm10k_hw *hw)
588 return ((hw->mac.dglort_map & FM10K_DGLORTMAP_NONE)
589 != FM10K_DGLORTMAP_NONE);
593 fm10k_dev_promiscuous_enable(struct rte_eth_dev *dev)
595 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
598 PMD_INIT_FUNC_TRACE();
600 /* Return if it didn't acquire valid glort range */
601 if (!fm10k_glort_valid(hw))
605 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
606 FM10K_XCAST_MODE_PROMISC);
607 fm10k_mbx_unlock(hw);
609 if (status != FM10K_SUCCESS)
610 PMD_INIT_LOG(ERR, "Failed to enable promiscuous mode");
614 fm10k_dev_promiscuous_disable(struct rte_eth_dev *dev)
616 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
620 PMD_INIT_FUNC_TRACE();
622 /* Return if it didn't acquire valid glort range */
623 if (!fm10k_glort_valid(hw))
626 if (dev->data->all_multicast == 1)
627 mode = FM10K_XCAST_MODE_ALLMULTI;
629 mode = FM10K_XCAST_MODE_NONE;
632 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
634 fm10k_mbx_unlock(hw);
636 if (status != FM10K_SUCCESS)
637 PMD_INIT_LOG(ERR, "Failed to disable promiscuous mode");
641 fm10k_dev_allmulticast_enable(struct rte_eth_dev *dev)
643 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
646 PMD_INIT_FUNC_TRACE();
648 /* Return if it didn't acquire valid glort range */
649 if (!fm10k_glort_valid(hw))
652 /* If promiscuous mode is enabled, it doesn't make sense to enable
653 * allmulticast and disable promiscuous since fm10k only can select
656 if (dev->data->promiscuous) {
657 PMD_INIT_LOG(INFO, "Promiscuous mode is enabled, "\
658 "needn't enable allmulticast");
663 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
664 FM10K_XCAST_MODE_ALLMULTI);
665 fm10k_mbx_unlock(hw);
667 if (status != FM10K_SUCCESS)
668 PMD_INIT_LOG(ERR, "Failed to enable allmulticast mode");
672 fm10k_dev_allmulticast_disable(struct rte_eth_dev *dev)
674 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
677 PMD_INIT_FUNC_TRACE();
679 /* Return if it didn't acquire valid glort range */
680 if (!fm10k_glort_valid(hw))
683 if (dev->data->promiscuous) {
684 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode "\
685 "since promisc mode is enabled");
690 /* Change mode to unicast mode */
691 status = hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
692 FM10K_XCAST_MODE_NONE);
693 fm10k_mbx_unlock(hw);
695 if (status != FM10K_SUCCESS)
696 PMD_INIT_LOG(ERR, "Failed to disable allmulticast mode");
699 /* fls = find last set bit = 32 minus the number of leading zeros */
701 #define fls(x) (((x) == 0) ? 0 : (32 - __builtin_clz((x))))
703 #define BSIZEPKT_ROUNDUP ((1 << FM10K_SRRCTL_BSIZEPKT_SHIFT) - 1)
705 fm10k_dev_start(struct rte_eth_dev *dev)
707 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
710 PMD_INIT_FUNC_TRACE();
712 /* stop, init, then start the hw */
713 diag = fm10k_stop_hw(hw);
714 if (diag != FM10K_SUCCESS) {
715 PMD_INIT_LOG(ERR, "Hardware stop failed: %d", diag);
719 diag = fm10k_init_hw(hw);
720 if (diag != FM10K_SUCCESS) {
721 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
725 diag = fm10k_start_hw(hw);
726 if (diag != FM10K_SUCCESS) {
727 PMD_INIT_LOG(ERR, "Hardware start failed: %d", diag);
731 diag = fm10k_dev_tx_init(dev);
733 PMD_INIT_LOG(ERR, "TX init failed: %d", diag);
737 diag = fm10k_dev_rx_init(dev);
739 PMD_INIT_LOG(ERR, "RX init failed: %d", diag);
743 if (hw->mac.type == fm10k_mac_pf) {
744 /* Establish only VSI 0 as valid */
745 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(0), FM10K_DGLORTMAP_ANY);
747 /* Configure RSS bits used in RETA table */
748 FM10K_WRITE_REG(hw, FM10K_DGLORTDEC(0),
749 fls(dev->data->nb_rx_queues - 1) <<
750 FM10K_DGLORTDEC_RSSLENGTH_SHIFT);
752 /* Invalidate all other GLORT entries */
753 for (i = 1; i < FM10K_DGLORT_COUNT; i++)
754 FM10K_WRITE_REG(hw, FM10K_DGLORTMAP(i),
755 FM10K_DGLORTMAP_NONE);
758 for (i = 0; i < dev->data->nb_rx_queues; i++) {
759 struct fm10k_rx_queue *rxq;
760 rxq = dev->data->rx_queues[i];
762 if (rxq->rx_deferred_start)
764 diag = fm10k_dev_rx_queue_start(dev, i);
767 for (j = 0; j < i; ++j)
768 rx_queue_clean(dev->data->rx_queues[j]);
773 for (i = 0; i < dev->data->nb_tx_queues; i++) {
774 struct fm10k_tx_queue *txq;
775 txq = dev->data->tx_queues[i];
777 if (txq->tx_deferred_start)
779 diag = fm10k_dev_tx_queue_start(dev, i);
782 for (j = 0; j < dev->data->nb_rx_queues; ++j)
783 rx_queue_clean(dev->data->rx_queues[j]);
788 if (hw->mac.default_vid && hw->mac.default_vid <= ETHER_MAX_VLAN_ID) {
790 /* Update default vlan */
791 hw->mac.ops.update_vlan(hw, hw->mac.default_vid, 0, true);
793 /* Add default mac/vlan filter to PF/Switch manager */
794 hw->mac.ops.update_uc_addr(hw, hw->mac.dglort_map, hw->mac.addr,
795 hw->mac.default_vid, true, 0);
796 fm10k_mbx_unlock(hw);
803 fm10k_dev_stop(struct rte_eth_dev *dev)
807 PMD_INIT_FUNC_TRACE();
809 for (i = 0; i < dev->data->nb_tx_queues; i++)
810 fm10k_dev_tx_queue_stop(dev, i);
812 for (i = 0; i < dev->data->nb_rx_queues; i++)
813 fm10k_dev_rx_queue_stop(dev, i);
817 fm10k_dev_close(struct rte_eth_dev *dev)
819 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
821 PMD_INIT_FUNC_TRACE();
823 /* Stop mailbox service first */
824 fm10k_close_mbx_service(hw);
830 fm10k_link_update(struct rte_eth_dev *dev,
831 __rte_unused int wait_to_complete)
833 PMD_INIT_FUNC_TRACE();
835 /* The host-interface link is always up. The speed is ~50Gbps per Gen3
836 * x8 PCIe interface. For now, we leave the speed undefined since there
837 * is no 50Gbps Ethernet. */
838 dev->data->dev_link.link_speed = 0;
839 dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
840 dev->data->dev_link.link_status = 1;
846 fm10k_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
848 uint64_t ipackets, opackets, ibytes, obytes;
849 struct fm10k_hw *hw =
850 FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
851 struct fm10k_hw_stats *hw_stats =
852 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
855 PMD_INIT_FUNC_TRACE();
857 fm10k_update_hw_stats(hw, hw_stats);
859 ipackets = opackets = ibytes = obytes = 0;
860 for (i = 0; (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) &&
861 (i < hw->mac.max_queues); ++i) {
862 stats->q_ipackets[i] = hw_stats->q[i].rx_packets.count;
863 stats->q_opackets[i] = hw_stats->q[i].tx_packets.count;
864 stats->q_ibytes[i] = hw_stats->q[i].rx_bytes.count;
865 stats->q_obytes[i] = hw_stats->q[i].tx_bytes.count;
866 ipackets += stats->q_ipackets[i];
867 opackets += stats->q_opackets[i];
868 ibytes += stats->q_ibytes[i];
869 obytes += stats->q_obytes[i];
871 stats->ipackets = ipackets;
872 stats->opackets = opackets;
873 stats->ibytes = ibytes;
874 stats->obytes = obytes;
878 fm10k_stats_reset(struct rte_eth_dev *dev)
880 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
881 struct fm10k_hw_stats *hw_stats =
882 FM10K_DEV_PRIVATE_TO_STATS(dev->data->dev_private);
884 PMD_INIT_FUNC_TRACE();
886 memset(hw_stats, 0, sizeof(*hw_stats));
887 fm10k_rebind_hw_stats(hw, hw_stats);
891 fm10k_dev_infos_get(struct rte_eth_dev *dev,
892 struct rte_eth_dev_info *dev_info)
894 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
896 PMD_INIT_FUNC_TRACE();
898 dev_info->min_rx_bufsize = FM10K_MIN_RX_BUF_SIZE;
899 dev_info->max_rx_pktlen = FM10K_MAX_PKT_SIZE;
900 dev_info->max_rx_queues = hw->mac.max_queues;
901 dev_info->max_tx_queues = hw->mac.max_queues;
902 dev_info->max_mac_addrs = 1;
903 dev_info->max_hash_mac_addrs = 0;
904 dev_info->max_vfs = dev->pci_dev->max_vfs;
905 dev_info->max_vmdq_pools = ETH_64_POOLS;
906 dev_info->rx_offload_capa =
907 DEV_RX_OFFLOAD_IPV4_CKSUM |
908 DEV_RX_OFFLOAD_UDP_CKSUM |
909 DEV_RX_OFFLOAD_TCP_CKSUM;
910 dev_info->tx_offload_capa = 0;
911 dev_info->reta_size = FM10K_MAX_RSS_INDICES;
913 dev_info->default_rxconf = (struct rte_eth_rxconf) {
915 .pthresh = FM10K_DEFAULT_RX_PTHRESH,
916 .hthresh = FM10K_DEFAULT_RX_HTHRESH,
917 .wthresh = FM10K_DEFAULT_RX_WTHRESH,
919 .rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(0),
923 dev_info->default_txconf = (struct rte_eth_txconf) {
925 .pthresh = FM10K_DEFAULT_TX_PTHRESH,
926 .hthresh = FM10K_DEFAULT_TX_HTHRESH,
927 .wthresh = FM10K_DEFAULT_TX_WTHRESH,
929 .tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(0),
930 .tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(0),
931 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
932 ETH_TXQ_FLAGS_NOOFFLOADS,
938 fm10k_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
941 uint32_t vid_idx, vid_bit, mac_index;
943 struct fm10k_macvlan_filter_info *macvlan;
944 struct rte_eth_dev_data *data = dev->data;
946 hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
947 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
949 /* @todo - add support for the VF */
950 if (hw->mac.type != fm10k_mac_pf) {
951 PMD_INIT_LOG(ERR, "VLAN filter not available on VF");
955 if (vlan_id > ETH_VLAN_ID_MAX) {
956 PMD_INIT_LOG(ERR, "Invalid vlan_id: must be < 4096");
960 vid_idx = FM10K_VFTA_IDX(vlan_id);
961 vid_bit = FM10K_VFTA_BIT(vlan_id);
962 /* this VLAN ID is already in the VLAN filter table, return SUCCESS */
963 if (on && (macvlan->vfta[vid_idx] & vid_bit))
965 /* this VLAN ID is NOT in the VLAN filter table, cannot remove */
966 if (!on && !(macvlan->vfta[vid_idx] & vid_bit)) {
967 PMD_INIT_LOG(ERR, "Invalid vlan_id: not existing "
968 "in the VLAN filter table");
973 result = fm10k_update_vlan(hw, vlan_id, 0, on);
974 fm10k_mbx_unlock(hw);
975 if (result != FM10K_SUCCESS) {
976 PMD_INIT_LOG(ERR, "VLAN update failed: %d", result);
980 for (mac_index = 0; (mac_index < FM10K_MAX_MACADDR_NUM) &&
981 (result == FM10K_SUCCESS); mac_index++) {
982 if (is_zero_ether_addr(&data->mac_addrs[mac_index]))
985 result = fm10k_update_uc_addr(hw, hw->mac.dglort_map,
986 data->mac_addrs[mac_index].addr_bytes,
988 fm10k_mbx_unlock(hw);
990 if (result != FM10K_SUCCESS) {
991 PMD_INIT_LOG(ERR, "MAC address update failed: %d", result);
997 macvlan->vfta[vid_idx] |= vid_bit;
1000 macvlan->vfta[vid_idx] &= ~vid_bit;
1006 check_nb_desc(uint16_t min, uint16_t max, uint16_t mult, uint16_t request)
1008 if ((request < min) || (request > max) || ((request % mult) != 0))
1015 * Create a memzone for hardware descriptor rings. Malloc cannot be used since
1016 * the physical address is required. If the memzone is already created, then
1017 * this function returns a pointer to the existing memzone.
1019 static inline const struct rte_memzone *
1020 allocate_hw_ring(const char *driver_name, const char *ring_name,
1021 uint8_t port_id, uint16_t queue_id, int socket_id,
1022 uint32_t size, uint32_t align)
1024 char name[RTE_MEMZONE_NAMESIZE];
1025 const struct rte_memzone *mz;
1027 snprintf(name, sizeof(name), "%s_%s_%d_%d_%d",
1028 driver_name, ring_name, port_id, queue_id, socket_id);
1030 /* return the memzone if it already exists */
1031 mz = rte_memzone_lookup(name);
1035 #ifdef RTE_LIBRTE_XEN_DOM0
1036 return rte_memzone_reserve_bounded(name, size, socket_id, 0, align,
1039 return rte_memzone_reserve_aligned(name, size, socket_id, 0, align);
1044 check_thresh(uint16_t min, uint16_t max, uint16_t div, uint16_t request)
1046 if ((request < min) || (request > max) || ((div % request) != 0))
1053 handle_rxconf(struct fm10k_rx_queue *q, const struct rte_eth_rxconf *conf)
1055 uint16_t rx_free_thresh;
1057 if (conf->rx_free_thresh == 0)
1058 rx_free_thresh = FM10K_RX_FREE_THRESH_DEFAULT(q);
1060 rx_free_thresh = conf->rx_free_thresh;
1062 /* make sure the requested threshold satisfies the constraints */
1063 if (check_thresh(FM10K_RX_FREE_THRESH_MIN(q),
1064 FM10K_RX_FREE_THRESH_MAX(q),
1065 FM10K_RX_FREE_THRESH_DIV(q),
1067 PMD_INIT_LOG(ERR, "rx_free_thresh (%u) must be "
1068 "less than or equal to %u, "
1069 "greater than or equal to %u, "
1070 "and a divisor of %u",
1071 rx_free_thresh, FM10K_RX_FREE_THRESH_MAX(q),
1072 FM10K_RX_FREE_THRESH_MIN(q),
1073 FM10K_RX_FREE_THRESH_DIV(q));
1077 q->alloc_thresh = rx_free_thresh;
1078 q->drop_en = conf->rx_drop_en;
1079 q->rx_deferred_start = conf->rx_deferred_start;
1085 * Hardware requires specific alignment for Rx packet buffers. At
1086 * least one of the following two conditions must be satisfied.
1087 * 1. Address is 512B aligned
1088 * 2. Address is 8B aligned and buffer does not cross 4K boundary.
1090 * As such, the driver may need to adjust the DMA address within the
1091 * buffer by up to 512B.
1093 * return 1 if the element size is valid, otherwise return 0.
1096 mempool_element_size_valid(struct rte_mempool *mp)
1100 /* elt_size includes mbuf header and headroom */
1101 min_size = mp->elt_size - sizeof(struct rte_mbuf) -
1102 RTE_PKTMBUF_HEADROOM;
1104 /* account for up to 512B of alignment */
1105 min_size -= FM10K_RX_DATABUF_ALIGN;
1107 /* sanity check for overflow */
1108 if (min_size > mp->elt_size)
1116 fm10k_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1117 uint16_t nb_desc, unsigned int socket_id,
1118 const struct rte_eth_rxconf *conf, struct rte_mempool *mp)
1120 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1121 struct fm10k_rx_queue *q;
1122 const struct rte_memzone *mz;
1124 PMD_INIT_FUNC_TRACE();
1126 /* make sure the mempool element size can account for alignment. */
1127 if (!mempool_element_size_valid(mp)) {
1128 PMD_INIT_LOG(ERR, "Error : Mempool element size is too small");
1132 /* make sure a valid number of descriptors have been requested */
1133 if (check_nb_desc(FM10K_MIN_RX_DESC, FM10K_MAX_RX_DESC,
1134 FM10K_MULT_RX_DESC, nb_desc)) {
1135 PMD_INIT_LOG(ERR, "Number of Rx descriptors (%u) must be "
1136 "less than or equal to %"PRIu32", "
1137 "greater than or equal to %u, "
1138 "and a multiple of %u",
1139 nb_desc, (uint32_t)FM10K_MAX_RX_DESC, FM10K_MIN_RX_DESC,
1140 FM10K_MULT_RX_DESC);
1145 * if this queue existed already, free the associated memory. The
1146 * queue cannot be reused in case we need to allocate memory on
1147 * different socket than was previously used.
1149 if (dev->data->rx_queues[queue_id] != NULL) {
1150 rx_queue_free(dev->data->rx_queues[queue_id]);
1151 dev->data->rx_queues[queue_id] = NULL;
1154 /* allocate memory for the queue structure */
1155 q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
1158 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
1164 q->nb_desc = nb_desc;
1165 q->port_id = dev->data->port_id;
1166 q->queue_id = queue_id;
1167 q->tail_ptr = (volatile uint32_t *)
1168 &((uint32_t *)hw->hw_addr)[FM10K_RDT(queue_id)];
1169 if (handle_rxconf(q, conf))
1172 /* allocate memory for the software ring */
1173 q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
1174 nb_desc * sizeof(struct rte_mbuf *),
1175 RTE_CACHE_LINE_SIZE, socket_id);
1176 if (q->sw_ring == NULL) {
1177 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
1183 * allocate memory for the hardware descriptor ring. A memzone large
1184 * enough to hold the maximum ring size is requested to allow for
1185 * resizing in later calls to the queue setup function.
1187 mz = allocate_hw_ring(dev->driver->pci_drv.name, "rx_ring",
1188 dev->data->port_id, queue_id, socket_id,
1189 FM10K_MAX_RX_RING_SZ, FM10K_ALIGN_RX_DESC);
1191 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
1192 rte_free(q->sw_ring);
1196 q->hw_ring = mz->addr;
1197 q->hw_ring_phys_addr = mz->phys_addr;
1199 dev->data->rx_queues[queue_id] = q;
1204 fm10k_rx_queue_release(void *queue)
1206 PMD_INIT_FUNC_TRACE();
1208 rx_queue_free(queue);
1212 handle_txconf(struct fm10k_tx_queue *q, const struct rte_eth_txconf *conf)
1214 uint16_t tx_free_thresh;
1215 uint16_t tx_rs_thresh;
1217 /* constraint MACROs require that tx_free_thresh is configured
1218 * before tx_rs_thresh */
1219 if (conf->tx_free_thresh == 0)
1220 tx_free_thresh = FM10K_TX_FREE_THRESH_DEFAULT(q);
1222 tx_free_thresh = conf->tx_free_thresh;
1224 /* make sure the requested threshold satisfies the constraints */
1225 if (check_thresh(FM10K_TX_FREE_THRESH_MIN(q),
1226 FM10K_TX_FREE_THRESH_MAX(q),
1227 FM10K_TX_FREE_THRESH_DIV(q),
1229 PMD_INIT_LOG(ERR, "tx_free_thresh (%u) must be "
1230 "less than or equal to %u, "
1231 "greater than or equal to %u, "
1232 "and a divisor of %u",
1233 tx_free_thresh, FM10K_TX_FREE_THRESH_MAX(q),
1234 FM10K_TX_FREE_THRESH_MIN(q),
1235 FM10K_TX_FREE_THRESH_DIV(q));
1239 q->free_thresh = tx_free_thresh;
1241 if (conf->tx_rs_thresh == 0)
1242 tx_rs_thresh = FM10K_TX_RS_THRESH_DEFAULT(q);
1244 tx_rs_thresh = conf->tx_rs_thresh;
1246 q->tx_deferred_start = conf->tx_deferred_start;
1248 /* make sure the requested threshold satisfies the constraints */
1249 if (check_thresh(FM10K_TX_RS_THRESH_MIN(q),
1250 FM10K_TX_RS_THRESH_MAX(q),
1251 FM10K_TX_RS_THRESH_DIV(q),
1253 PMD_INIT_LOG(ERR, "tx_rs_thresh (%u) must be "
1254 "less than or equal to %u, "
1255 "greater than or equal to %u, "
1256 "and a divisor of %u",
1257 tx_rs_thresh, FM10K_TX_RS_THRESH_MAX(q),
1258 FM10K_TX_RS_THRESH_MIN(q),
1259 FM10K_TX_RS_THRESH_DIV(q));
1263 q->rs_thresh = tx_rs_thresh;
1269 fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
1270 uint16_t nb_desc, unsigned int socket_id,
1271 const struct rte_eth_txconf *conf)
1273 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1274 struct fm10k_tx_queue *q;
1275 const struct rte_memzone *mz;
1277 PMD_INIT_FUNC_TRACE();
1279 /* make sure a valid number of descriptors have been requested */
1280 if (check_nb_desc(FM10K_MIN_TX_DESC, FM10K_MAX_TX_DESC,
1281 FM10K_MULT_TX_DESC, nb_desc)) {
1282 PMD_INIT_LOG(ERR, "Number of Tx descriptors (%u) must be "
1283 "less than or equal to %"PRIu32", "
1284 "greater than or equal to %u, "
1285 "and a multiple of %u",
1286 nb_desc, (uint32_t)FM10K_MAX_TX_DESC, FM10K_MIN_TX_DESC,
1287 FM10K_MULT_TX_DESC);
1292 * if this queue existed already, free the associated memory. The
1293 * queue cannot be reused in case we need to allocate memory on
1294 * different socket than was previously used.
1296 if (dev->data->tx_queues[queue_id] != NULL) {
1297 tx_queue_free(dev->data->tx_queues[queue_id]);
1298 dev->data->tx_queues[queue_id] = NULL;
1301 /* allocate memory for the queue structure */
1302 q = rte_zmalloc_socket("fm10k", sizeof(*q), RTE_CACHE_LINE_SIZE,
1305 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
1310 q->nb_desc = nb_desc;
1311 q->port_id = dev->data->port_id;
1312 q->queue_id = queue_id;
1313 q->tail_ptr = (volatile uint32_t *)
1314 &((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
1315 if (handle_txconf(q, conf))
1318 /* allocate memory for the software ring */
1319 q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
1320 nb_desc * sizeof(struct rte_mbuf *),
1321 RTE_CACHE_LINE_SIZE, socket_id);
1322 if (q->sw_ring == NULL) {
1323 PMD_INIT_LOG(ERR, "Cannot allocate software ring");
1329 * allocate memory for the hardware descriptor ring. A memzone large
1330 * enough to hold the maximum ring size is requested to allow for
1331 * resizing in later calls to the queue setup function.
1333 mz = allocate_hw_ring(dev->driver->pci_drv.name, "tx_ring",
1334 dev->data->port_id, queue_id, socket_id,
1335 FM10K_MAX_TX_RING_SZ, FM10K_ALIGN_TX_DESC);
1337 PMD_INIT_LOG(ERR, "Cannot allocate hardware ring");
1338 rte_free(q->sw_ring);
1342 q->hw_ring = mz->addr;
1343 q->hw_ring_phys_addr = mz->phys_addr;
1346 * allocate memory for the RS bit tracker. Enough slots to hold the
1347 * descriptor index for each RS bit needing to be set are required.
1349 q->rs_tracker.list = rte_zmalloc_socket("fm10k rs tracker",
1350 ((nb_desc + 1) / q->rs_thresh) *
1352 RTE_CACHE_LINE_SIZE, socket_id);
1353 if (q->rs_tracker.list == NULL) {
1354 PMD_INIT_LOG(ERR, "Cannot allocate RS bit tracker");
1355 rte_free(q->sw_ring);
1360 dev->data->tx_queues[queue_id] = q;
1365 fm10k_tx_queue_release(void *queue)
1367 PMD_INIT_FUNC_TRACE();
1369 tx_queue_free(queue);
1373 fm10k_reta_update(struct rte_eth_dev *dev,
1374 struct rte_eth_rss_reta_entry64 *reta_conf,
1377 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1378 uint16_t i, j, idx, shift;
1382 PMD_INIT_FUNC_TRACE();
1384 if (reta_size > FM10K_MAX_RSS_INDICES) {
1385 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
1386 "(%d) doesn't match the number hardware can supported "
1387 "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
1392 * Update Redirection Table RETA[n], n=0..31. The redirection table has
1393 * 128-entries in 32 registers
1395 for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
1396 idx = i / RTE_RETA_GROUP_SIZE;
1397 shift = i % RTE_RETA_GROUP_SIZE;
1398 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
1399 BIT_MASK_PER_UINT32);
1404 if (mask != BIT_MASK_PER_UINT32)
1405 reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
1407 for (j = 0; j < CHARS_PER_UINT32; j++) {
1408 if (mask & (0x1 << j)) {
1410 reta &= ~(UINT8_MAX << CHAR_BIT * j);
1411 reta |= reta_conf[idx].reta[shift + j] <<
1415 FM10K_WRITE_REG(hw, FM10K_RETA(0, i >> 2), reta);
1422 fm10k_reta_query(struct rte_eth_dev *dev,
1423 struct rte_eth_rss_reta_entry64 *reta_conf,
1426 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1427 uint16_t i, j, idx, shift;
1431 PMD_INIT_FUNC_TRACE();
1433 if (reta_size < FM10K_MAX_RSS_INDICES) {
1434 PMD_INIT_LOG(ERR, "The size of hash lookup table configured "
1435 "(%d) doesn't match the number hardware can supported "
1436 "(%d)", reta_size, FM10K_MAX_RSS_INDICES);
1441 * Read Redirection Table RETA[n], n=0..31. The redirection table has
1442 * 128-entries in 32 registers
1444 for (i = 0; i < FM10K_MAX_RSS_INDICES; i += CHARS_PER_UINT32) {
1445 idx = i / RTE_RETA_GROUP_SIZE;
1446 shift = i % RTE_RETA_GROUP_SIZE;
1447 mask = (uint8_t)((reta_conf[idx].mask >> shift) &
1448 BIT_MASK_PER_UINT32);
1452 reta = FM10K_READ_REG(hw, FM10K_RETA(0, i >> 2));
1453 for (j = 0; j < CHARS_PER_UINT32; j++) {
1454 if (mask & (0x1 << j))
1455 reta_conf[idx].reta[shift + j] = ((reta >>
1456 CHAR_BIT * j) & UINT8_MAX);
1464 fm10k_rss_hash_update(struct rte_eth_dev *dev,
1465 struct rte_eth_rss_conf *rss_conf)
1467 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1468 uint32_t *key = (uint32_t *)rss_conf->rss_key;
1470 uint64_t hf = rss_conf->rss_hf;
1473 PMD_INIT_FUNC_TRACE();
1475 if (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
1476 FM10K_RSSRK_ENTRIES_PER_REG)
1483 mrqc |= (hf & ETH_RSS_IPV4) ? FM10K_MRQC_IPV4 : 0;
1484 mrqc |= (hf & ETH_RSS_IPV6) ? FM10K_MRQC_IPV6 : 0;
1485 mrqc |= (hf & ETH_RSS_IPV6_EX) ? FM10K_MRQC_IPV6 : 0;
1486 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_TCP) ? FM10K_MRQC_TCP_IPV4 : 0;
1487 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_TCP) ? FM10K_MRQC_TCP_IPV6 : 0;
1488 mrqc |= (hf & ETH_RSS_IPV6_TCP_EX) ? FM10K_MRQC_TCP_IPV6 : 0;
1489 mrqc |= (hf & ETH_RSS_NONFRAG_IPV4_UDP) ? FM10K_MRQC_UDP_IPV4 : 0;
1490 mrqc |= (hf & ETH_RSS_NONFRAG_IPV6_UDP) ? FM10K_MRQC_UDP_IPV6 : 0;
1491 mrqc |= (hf & ETH_RSS_IPV6_UDP_EX) ? FM10K_MRQC_UDP_IPV6 : 0;
1493 /* If the mapping doesn't fit any supported, return */
1498 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
1499 FM10K_WRITE_REG(hw, FM10K_RSSRK(0, i), key[i]);
1501 FM10K_WRITE_REG(hw, FM10K_MRQC(0), mrqc);
1507 fm10k_rss_hash_conf_get(struct rte_eth_dev *dev,
1508 struct rte_eth_rss_conf *rss_conf)
1510 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1511 uint32_t *key = (uint32_t *)rss_conf->rss_key;
1516 PMD_INIT_FUNC_TRACE();
1518 if (rss_conf->rss_key_len < FM10K_RSSRK_SIZE *
1519 FM10K_RSSRK_ENTRIES_PER_REG)
1523 for (i = 0; i < FM10K_RSSRK_SIZE; ++i)
1524 key[i] = FM10K_READ_REG(hw, FM10K_RSSRK(0, i));
1526 mrqc = FM10K_READ_REG(hw, FM10K_MRQC(0));
1528 hf |= (mrqc & FM10K_MRQC_IPV4) ? ETH_RSS_IPV4 : 0;
1529 hf |= (mrqc & FM10K_MRQC_IPV6) ? ETH_RSS_IPV6 : 0;
1530 hf |= (mrqc & FM10K_MRQC_IPV6) ? ETH_RSS_IPV6_EX : 0;
1531 hf |= (mrqc & FM10K_MRQC_TCP_IPV4) ? ETH_RSS_NONFRAG_IPV4_TCP : 0;
1532 hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? ETH_RSS_NONFRAG_IPV6_TCP : 0;
1533 hf |= (mrqc & FM10K_MRQC_TCP_IPV6) ? ETH_RSS_IPV6_TCP_EX : 0;
1534 hf |= (mrqc & FM10K_MRQC_UDP_IPV4) ? ETH_RSS_NONFRAG_IPV4_UDP : 0;
1535 hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? ETH_RSS_NONFRAG_IPV6_UDP : 0;
1536 hf |= (mrqc & FM10K_MRQC_UDP_IPV6) ? ETH_RSS_IPV6_UDP_EX : 0;
1538 rss_conf->rss_hf = hf;
1544 fm10k_dev_enable_intr_pf(struct rte_eth_dev *dev)
1546 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1547 uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
1549 /* Bind all local non-queue interrupt to vector 0 */
1552 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_Mailbox), int_map);
1553 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_PCIeFault), int_map);
1554 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SwitchUpDown), int_map);
1555 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SwitchEvent), int_map);
1556 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_SRAM), int_map);
1557 FM10K_WRITE_REG(hw, FM10K_INT_MAP(fm10k_int_VFLR), int_map);
1559 /* Enable misc causes */
1560 FM10K_WRITE_REG(hw, FM10K_EIMR, FM10K_EIMR_ENABLE(PCA_FAULT) |
1561 FM10K_EIMR_ENABLE(THI_FAULT) |
1562 FM10K_EIMR_ENABLE(FUM_FAULT) |
1563 FM10K_EIMR_ENABLE(MAILBOX) |
1564 FM10K_EIMR_ENABLE(SWITCHREADY) |
1565 FM10K_EIMR_ENABLE(SWITCHNOTREADY) |
1566 FM10K_EIMR_ENABLE(SRAMERROR) |
1567 FM10K_EIMR_ENABLE(VFLR));
1570 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
1571 FM10K_ITR_MASK_CLEAR);
1572 FM10K_WRITE_FLUSH(hw);
1576 fm10k_dev_enable_intr_vf(struct rte_eth_dev *dev)
1578 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1579 uint32_t int_map = FM10K_INT_MAP_IMMEDIATE;
1581 /* Bind all local non-queue interrupt to vector 0 */
1584 /* Only INT 0 available, other 15 are reserved. */
1585 FM10K_WRITE_REG(hw, FM10K_VFINT_MAP, int_map);
1588 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
1589 FM10K_ITR_MASK_CLEAR);
1590 FM10K_WRITE_FLUSH(hw);
1594 fm10k_dev_handle_fault(struct fm10k_hw *hw, uint32_t eicr)
1596 struct fm10k_fault fault;
1598 const char *estr = "Unknown error";
1600 /* Process PCA fault */
1601 if (eicr & FM10K_EIMR_PCA_FAULT) {
1602 err = fm10k_get_fault(hw, FM10K_PCA_FAULT, &fault);
1605 switch (fault.type) {
1607 estr = "PCA_NO_FAULT"; break;
1608 case PCA_UNMAPPED_ADDR:
1609 estr = "PCA_UNMAPPED_ADDR"; break;
1610 case PCA_BAD_QACCESS_PF:
1611 estr = "PCA_BAD_QACCESS_PF"; break;
1612 case PCA_BAD_QACCESS_VF:
1613 estr = "PCA_BAD_QACCESS_VF"; break;
1614 case PCA_MALICIOUS_REQ:
1615 estr = "PCA_MALICIOUS_REQ"; break;
1616 case PCA_POISONED_TLP:
1617 estr = "PCA_POISONED_TLP"; break;
1619 estr = "PCA_TLP_ABORT"; break;
1623 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
1624 estr, fault.func ? "VF" : "PF", fault.func,
1625 fault.address, fault.specinfo);
1628 /* Process THI fault */
1629 if (eicr & FM10K_EIMR_THI_FAULT) {
1630 err = fm10k_get_fault(hw, FM10K_THI_FAULT, &fault);
1633 switch (fault.type) {
1635 estr = "THI_NO_FAULT"; break;
1636 case THI_MAL_DIS_Q_FAULT:
1637 estr = "THI_MAL_DIS_Q_FAULT"; break;
1641 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
1642 estr, fault.func ? "VF" : "PF", fault.func,
1643 fault.address, fault.specinfo);
1646 /* Process FUM fault */
1647 if (eicr & FM10K_EIMR_FUM_FAULT) {
1648 err = fm10k_get_fault(hw, FM10K_FUM_FAULT, &fault);
1651 switch (fault.type) {
1653 estr = "FUM_NO_FAULT"; break;
1654 case FUM_UNMAPPED_ADDR:
1655 estr = "FUM_UNMAPPED_ADDR"; break;
1656 case FUM_POISONED_TLP:
1657 estr = "FUM_POISONED_TLP"; break;
1658 case FUM_BAD_VF_QACCESS:
1659 estr = "FUM_BAD_VF_QACCESS"; break;
1660 case FUM_ADD_DECODE_ERR:
1661 estr = "FUM_ADD_DECODE_ERR"; break;
1663 estr = "FUM_RO_ERROR"; break;
1664 case FUM_QPRC_CRC_ERROR:
1665 estr = "FUM_QPRC_CRC_ERROR"; break;
1666 case FUM_CSR_TIMEOUT:
1667 estr = "FUM_CSR_TIMEOUT"; break;
1668 case FUM_INVALID_TYPE:
1669 estr = "FUM_INVALID_TYPE"; break;
1670 case FUM_INVALID_LENGTH:
1671 estr = "FUM_INVALID_LENGTH"; break;
1672 case FUM_INVALID_BE:
1673 estr = "FUM_INVALID_BE"; break;
1674 case FUM_INVALID_ALIGN:
1675 estr = "FUM_INVALID_ALIGN"; break;
1679 PMD_INIT_LOG(ERR, "%s: %s(%d) Addr:0x%"PRIx64" Spec: 0x%x",
1680 estr, fault.func ? "VF" : "PF", fault.func,
1681 fault.address, fault.specinfo);
1688 PMD_INIT_LOG(ERR, "Failed to handle fault event.");
1693 * PF interrupt handler triggered by NIC for handling specific interrupt.
1696 * Pointer to interrupt handle.
1698 * The address of parameter (struct rte_eth_dev *) regsitered before.
1704 fm10k_dev_interrupt_handler_pf(
1705 __rte_unused struct rte_intr_handle *handle,
1708 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1709 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1710 uint32_t cause, status;
1712 if (hw->mac.type != fm10k_mac_pf)
1715 cause = FM10K_READ_REG(hw, FM10K_EICR);
1717 /* Handle PCI fault cases */
1718 if (cause & FM10K_EICR_FAULT_MASK) {
1719 PMD_INIT_LOG(ERR, "INT: find fault!");
1720 fm10k_dev_handle_fault(hw, cause);
1723 /* Handle switch up/down */
1724 if (cause & FM10K_EICR_SWITCHNOTREADY)
1725 PMD_INIT_LOG(ERR, "INT: Switch is not ready");
1727 if (cause & FM10K_EICR_SWITCHREADY)
1728 PMD_INIT_LOG(INFO, "INT: Switch is ready");
1730 /* Handle mailbox message */
1732 hw->mbx.ops.process(hw, &hw->mbx);
1733 fm10k_mbx_unlock(hw);
1735 /* Handle SRAM error */
1736 if (cause & FM10K_EICR_SRAMERROR) {
1737 PMD_INIT_LOG(ERR, "INT: SRAM error on PEP");
1739 status = FM10K_READ_REG(hw, FM10K_SRAM_IP);
1740 /* Write to clear pending bits */
1741 FM10K_WRITE_REG(hw, FM10K_SRAM_IP, status);
1743 /* Todo: print out error message after shared code updates */
1746 /* Clear these 3 events if having any */
1747 cause &= FM10K_EICR_SWITCHNOTREADY | FM10K_EICR_MAILBOX |
1748 FM10K_EICR_SWITCHREADY;
1750 FM10K_WRITE_REG(hw, FM10K_EICR, cause);
1752 /* Re-enable interrupt from device side */
1753 FM10K_WRITE_REG(hw, FM10K_ITR(0), FM10K_ITR_AUTOMASK |
1754 FM10K_ITR_MASK_CLEAR);
1755 /* Re-enable interrupt from host side */
1756 rte_intr_enable(&(dev->pci_dev->intr_handle));
1760 * VF interrupt handler triggered by NIC for handling specific interrupt.
1763 * Pointer to interrupt handle.
1765 * The address of parameter (struct rte_eth_dev *) regsitered before.
1771 fm10k_dev_interrupt_handler_vf(
1772 __rte_unused struct rte_intr_handle *handle,
1775 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1776 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1778 if (hw->mac.type != fm10k_mac_vf)
1781 /* Handle mailbox message if lock is acquired */
1783 hw->mbx.ops.process(hw, &hw->mbx);
1784 fm10k_mbx_unlock(hw);
1786 /* Re-enable interrupt from device side */
1787 FM10K_WRITE_REG(hw, FM10K_VFITR(0), FM10K_ITR_AUTOMASK |
1788 FM10K_ITR_MASK_CLEAR);
1789 /* Re-enable interrupt from host side */
1790 rte_intr_enable(&(dev->pci_dev->intr_handle));
1793 /* Mailbox message handler in VF */
1794 static const struct fm10k_msg_data fm10k_msgdata_vf[] = {
1795 FM10K_TLV_MSG_TEST_HANDLER(fm10k_tlv_msg_test),
1796 FM10K_VF_MSG_MAC_VLAN_HANDLER(fm10k_msg_mac_vlan_vf),
1797 FM10K_VF_MSG_LPORT_STATE_HANDLER(fm10k_msg_lport_state_vf),
1798 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
1801 /* Mailbox message handler in PF */
1802 static const struct fm10k_msg_data fm10k_msgdata_pf[] = {
1803 FM10K_PF_MSG_ERR_HANDLER(XCAST_MODES, fm10k_msg_err_pf),
1804 FM10K_PF_MSG_ERR_HANDLER(UPDATE_MAC_FWD_RULE, fm10k_msg_err_pf),
1805 FM10K_PF_MSG_LPORT_MAP_HANDLER(fm10k_msg_lport_map_pf),
1806 FM10K_PF_MSG_ERR_HANDLER(LPORT_CREATE, fm10k_msg_err_pf),
1807 FM10K_PF_MSG_ERR_HANDLER(LPORT_DELETE, fm10k_msg_err_pf),
1808 FM10K_PF_MSG_UPDATE_PVID_HANDLER(fm10k_msg_update_pvid_pf),
1809 FM10K_TLV_MSG_ERROR_HANDLER(fm10k_tlv_msg_error),
1813 fm10k_setup_mbx_service(struct fm10k_hw *hw)
1817 /* Initialize mailbox lock */
1818 fm10k_mbx_initlock(hw);
1820 /* Replace default message handler with new ones */
1821 if (hw->mac.type == fm10k_mac_pf)
1822 err = hw->mbx.ops.register_handlers(&hw->mbx, fm10k_msgdata_pf);
1824 err = hw->mbx.ops.register_handlers(&hw->mbx, fm10k_msgdata_vf);
1827 PMD_INIT_LOG(ERR, "Failed to register mailbox handler.err:%d",
1831 /* Connect to SM for PF device or PF for VF device */
1832 return hw->mbx.ops.connect(hw, &hw->mbx);
1836 fm10k_close_mbx_service(struct fm10k_hw *hw)
1838 /* Disconnect from SM for PF device or PF for VF device */
1839 hw->mbx.ops.disconnect(hw, &hw->mbx);
1842 static const struct eth_dev_ops fm10k_eth_dev_ops = {
1843 .dev_configure = fm10k_dev_configure,
1844 .dev_start = fm10k_dev_start,
1845 .dev_stop = fm10k_dev_stop,
1846 .dev_close = fm10k_dev_close,
1847 .promiscuous_enable = fm10k_dev_promiscuous_enable,
1848 .promiscuous_disable = fm10k_dev_promiscuous_disable,
1849 .allmulticast_enable = fm10k_dev_allmulticast_enable,
1850 .allmulticast_disable = fm10k_dev_allmulticast_disable,
1851 .stats_get = fm10k_stats_get,
1852 .stats_reset = fm10k_stats_reset,
1853 .link_update = fm10k_link_update,
1854 .dev_infos_get = fm10k_dev_infos_get,
1855 .vlan_filter_set = fm10k_vlan_filter_set,
1856 .rx_queue_start = fm10k_dev_rx_queue_start,
1857 .rx_queue_stop = fm10k_dev_rx_queue_stop,
1858 .tx_queue_start = fm10k_dev_tx_queue_start,
1859 .tx_queue_stop = fm10k_dev_tx_queue_stop,
1860 .rx_queue_setup = fm10k_rx_queue_setup,
1861 .rx_queue_release = fm10k_rx_queue_release,
1862 .tx_queue_setup = fm10k_tx_queue_setup,
1863 .tx_queue_release = fm10k_tx_queue_release,
1864 .reta_update = fm10k_reta_update,
1865 .reta_query = fm10k_reta_query,
1866 .rss_hash_update = fm10k_rss_hash_update,
1867 .rss_hash_conf_get = fm10k_rss_hash_conf_get,
1871 eth_fm10k_dev_init(struct rte_eth_dev *dev)
1873 struct fm10k_hw *hw = FM10K_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1875 struct fm10k_macvlan_filter_info *macvlan;
1877 PMD_INIT_FUNC_TRACE();
1879 dev->dev_ops = &fm10k_eth_dev_ops;
1880 dev->rx_pkt_burst = &fm10k_recv_pkts;
1881 dev->tx_pkt_burst = &fm10k_xmit_pkts;
1883 if (dev->data->scattered_rx)
1884 dev->rx_pkt_burst = &fm10k_recv_scattered_pkts;
1886 /* only initialize in the primary process */
1887 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1890 macvlan = FM10K_DEV_PRIVATE_TO_MACVLAN(dev->data->dev_private);
1891 memset(macvlan, 0, sizeof(*macvlan));
1892 /* Vendor and Device ID need to be set before init of shared code */
1893 memset(hw, 0, sizeof(*hw));
1894 hw->device_id = dev->pci_dev->id.device_id;
1895 hw->vendor_id = dev->pci_dev->id.vendor_id;
1896 hw->subsystem_device_id = dev->pci_dev->id.subsystem_device_id;
1897 hw->subsystem_vendor_id = dev->pci_dev->id.subsystem_vendor_id;
1898 hw->revision_id = 0;
1899 hw->hw_addr = (void *)dev->pci_dev->mem_resource[0].addr;
1900 if (hw->hw_addr == NULL) {
1901 PMD_INIT_LOG(ERR, "Bad mem resource."
1902 " Try to blacklist unused devices.");
1906 /* Store fm10k_adapter pointer */
1907 hw->back = dev->data->dev_private;
1909 /* Initialize the shared code */
1910 diag = fm10k_init_shared_code(hw);
1911 if (diag != FM10K_SUCCESS) {
1912 PMD_INIT_LOG(ERR, "Shared code init failed: %d", diag);
1917 * Inialize bus info. Normally we would call fm10k_get_bus_info(), but
1918 * there is no way to get link status without reading BAR4. Until this
1919 * works, assume we have maximum bandwidth.
1920 * @todo - fix bus info
1922 hw->bus_caps.speed = fm10k_bus_speed_8000;
1923 hw->bus_caps.width = fm10k_bus_width_pcie_x8;
1924 hw->bus_caps.payload = fm10k_bus_payload_512;
1925 hw->bus.speed = fm10k_bus_speed_8000;
1926 hw->bus.width = fm10k_bus_width_pcie_x8;
1927 hw->bus.payload = fm10k_bus_payload_256;
1929 /* Initialize the hw */
1930 diag = fm10k_init_hw(hw);
1931 if (diag != FM10K_SUCCESS) {
1932 PMD_INIT_LOG(ERR, "Hardware init failed: %d", diag);
1936 /* Initialize MAC address(es) */
1937 dev->data->mac_addrs = rte_zmalloc("fm10k", ETHER_ADDR_LEN, 0);
1938 if (dev->data->mac_addrs == NULL) {
1939 PMD_INIT_LOG(ERR, "Cannot allocate memory for MAC addresses");
1943 diag = fm10k_read_mac_addr(hw);
1945 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
1946 &dev->data->mac_addrs[0]);
1948 if (diag != FM10K_SUCCESS ||
1949 !is_valid_assigned_ether_addr(dev->data->mac_addrs)) {
1951 /* Generate a random addr */
1952 eth_random_addr(hw->mac.addr);
1953 memcpy(hw->mac.perm_addr, hw->mac.addr, ETH_ALEN);
1954 ether_addr_copy((const struct ether_addr *)hw->mac.addr,
1955 &dev->data->mac_addrs[0]);
1958 /* Reset the hw statistics */
1959 fm10k_stats_reset(dev);
1962 diag = fm10k_reset_hw(hw);
1963 if (diag != FM10K_SUCCESS) {
1964 PMD_INIT_LOG(ERR, "Hardware reset failed: %d", diag);
1968 /* Setup mailbox service */
1969 diag = fm10k_setup_mbx_service(hw);
1970 if (diag != FM10K_SUCCESS) {
1971 PMD_INIT_LOG(ERR, "Failed to setup mailbox: %d", diag);
1975 /*PF/VF has different interrupt handling mechanism */
1976 if (hw->mac.type == fm10k_mac_pf) {
1977 /* register callback func to eal lib */
1978 rte_intr_callback_register(&(dev->pci_dev->intr_handle),
1979 fm10k_dev_interrupt_handler_pf, (void *)dev);
1981 /* enable MISC interrupt */
1982 fm10k_dev_enable_intr_pf(dev);
1984 rte_intr_callback_register(&(dev->pci_dev->intr_handle),
1985 fm10k_dev_interrupt_handler_vf, (void *)dev);
1987 fm10k_dev_enable_intr_vf(dev);
1990 /* Enable uio intr after callback registered */
1991 rte_intr_enable(&(dev->pci_dev->intr_handle));
1993 hw->mac.ops.update_int_moderator(hw);
1995 /* Make sure Switch Manager is ready before going forward. */
1996 if (hw->mac.type == fm10k_mac_pf) {
1997 int switch_ready = 0;
2000 for (i = 0; i < MAX_QUERY_SWITCH_STATE_TIMES; i++) {
2002 hw->mac.ops.get_host_state(hw, &switch_ready);
2003 fm10k_mbx_unlock(hw);
2006 /* Delay some time to acquire async LPORT_MAP info. */
2007 rte_delay_us(WAIT_SWITCH_MSG_US);
2010 if (switch_ready == 0) {
2011 PMD_INIT_LOG(ERR, "switch is not ready");
2017 * Below function will trigger operations on mailbox, acquire lock to
2018 * avoid race condition from interrupt handler. Operations on mailbox
2019 * FIFO will trigger interrupt to PF/SM, in which interrupt handler
2020 * will handle and generate an interrupt to our side. Then, FIFO in
2021 * mailbox will be touched.
2024 /* Enable port first */
2025 hw->mac.ops.update_lport_state(hw, hw->mac.dglort_map, 1, 1);
2028 * Add default mac. glort is assigned by SM for PF, while is
2029 * unused for VF. PF will assign correct glort for VF.
2031 hw->mac.ops.update_uc_addr(hw, hw->mac.dglort_map, hw->mac.addr,
2034 /* Set unicast mode by default. App can change to other mode in other
2037 hw->mac.ops.update_xcast_mode(hw, hw->mac.dglort_map,
2038 FM10K_XCAST_MODE_NONE);
2040 fm10k_mbx_unlock(hw);
2047 * The set of PCI devices this driver supports. This driver will enable both PF
2048 * and SRIOV-VF devices.
2050 static const struct rte_pci_id pci_id_fm10k_map[] = {
2051 #define RTE_PCI_DEV_ID_DECL_FM10K(vend, dev) { RTE_PCI_DEVICE(vend, dev) },
2052 #define RTE_PCI_DEV_ID_DECL_FM10KVF(vend, dev) { RTE_PCI_DEVICE(vend, dev) },
2053 #include "rte_pci_dev_ids.h"
2054 { .vendor_id = 0, /* sentinel */ },
2057 static struct eth_driver rte_pmd_fm10k = {
2059 .name = "rte_pmd_fm10k",
2060 .id_table = pci_id_fm10k_map,
2061 .drv_flags = RTE_PCI_DRV_NEED_MAPPING,
2063 .eth_dev_init = eth_fm10k_dev_init,
2064 .dev_private_size = sizeof(struct fm10k_adapter),
2068 * Driver initialization routine.
2069 * Invoked once at EAL init time.
2070 * Register itself as the [Poll Mode] Driver of PCI FM10K devices.
2073 rte_pmd_fm10k_init(__rte_unused const char *name,
2074 __rte_unused const char *params)
2076 PMD_INIT_FUNC_TRACE();
2077 rte_eth_driver_register(&rte_pmd_fm10k);
2081 static struct rte_driver rte_fm10k_driver = {
2083 .init = rte_pmd_fm10k_init,
2086 PMD_REGISTER_DRIVER(rte_fm10k_driver);