2 * Copyright (c) 2016 QLogic Corporation.
6 * See LICENSE.qede_pmd for copyright and licensing details.
11 static bool gro_disable = 1; /* mod_param */
13 static inline int qede_alloc_rx_buffer(struct qede_rx_queue *rxq)
15 struct rte_mbuf *new_mb = NULL;
16 struct eth_rx_bd *rx_bd;
18 uint16_t idx = rxq->sw_rx_prod & NUM_RX_BDS(rxq);
20 new_mb = rte_mbuf_raw_alloc(rxq->mb_pool);
21 if (unlikely(!new_mb)) {
23 "Failed to allocate rx buffer "
24 "sw_rx_prod %u sw_rx_cons %u mp entries %u free %u",
25 idx, rxq->sw_rx_cons & NUM_RX_BDS(rxq),
26 rte_mempool_count(rxq->mb_pool),
27 rte_mempool_free_count(rxq->mb_pool));
30 rxq->sw_rx_ring[idx].mbuf = new_mb;
31 rxq->sw_rx_ring[idx].page_offset = 0;
32 mapping = rte_mbuf_data_dma_addr_default(new_mb);
33 /* Advance PROD and get BD pointer */
34 rx_bd = (struct eth_rx_bd *)ecore_chain_produce(&rxq->rx_bd_ring);
35 rx_bd->addr.hi = rte_cpu_to_le_32(U64_HI(mapping));
36 rx_bd->addr.lo = rte_cpu_to_le_32(U64_LO(mapping));
41 static void qede_rx_queue_release_mbufs(struct qede_rx_queue *rxq)
45 if (rxq->sw_rx_ring != NULL) {
46 for (i = 0; i < rxq->nb_rx_desc; i++) {
47 if (rxq->sw_rx_ring[i].mbuf != NULL) {
48 rte_pktmbuf_free(rxq->sw_rx_ring[i].mbuf);
49 rxq->sw_rx_ring[i].mbuf = NULL;
55 void qede_rx_queue_release(void *rx_queue)
57 struct qede_rx_queue *rxq = rx_queue;
60 qede_rx_queue_release_mbufs(rxq);
61 rte_free(rxq->sw_rx_ring);
62 rxq->sw_rx_ring = NULL;
69 qede_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
70 uint16_t nb_desc, unsigned int socket_id,
71 const struct rte_eth_rxconf *rx_conf,
72 struct rte_mempool *mp)
74 struct qede_dev *qdev = dev->data->dev_private;
75 struct ecore_dev *edev = &qdev->edev;
76 struct rte_eth_dev_data *eth_data = dev->data;
77 struct qede_rx_queue *rxq;
78 uint16_t pkt_len = (uint16_t)dev->data->dev_conf.rxmode.max_rx_pkt_len;
84 PMD_INIT_FUNC_TRACE(edev);
86 /* Note: Ring size/align is controlled by struct rte_eth_desc_lim */
87 if (!rte_is_power_of_2(nb_desc)) {
88 DP_ERR(edev, "Ring size %u is not power of 2\n",
93 /* Free memory prior to re-allocation if needed... */
94 if (dev->data->rx_queues[queue_idx] != NULL) {
95 qede_rx_queue_release(dev->data->rx_queues[queue_idx]);
96 dev->data->rx_queues[queue_idx] = NULL;
99 /* First allocate the rx queue data structure */
100 rxq = rte_zmalloc_socket("qede_rx_queue", sizeof(struct qede_rx_queue),
101 RTE_CACHE_LINE_SIZE, socket_id);
104 DP_ERR(edev, "Unable to allocate memory for rxq on socket %u",
111 rxq->nb_rx_desc = nb_desc;
112 rxq->queue_id = queue_idx;
113 rxq->port_id = dev->data->port_id;
116 data_size = (uint16_t)rte_pktmbuf_data_room_size(mp) -
117 RTE_PKTMBUF_HEADROOM;
119 if (pkt_len > data_size) {
120 DP_ERR(edev, "MTU %u should not exceed dataroom %u\n",
127 rxq->rx_buf_size = pkt_len + QEDE_ETH_OVERHEAD;
129 DP_INFO(edev, "MTU = %u ; RX buffer = %u\n",
130 qdev->mtu, rxq->rx_buf_size);
132 if (pkt_len > ETHER_MAX_LEN) {
133 dev->data->dev_conf.rxmode.jumbo_frame = 1;
134 DP_NOTICE(edev, false, "jumbo frame enabled\n");
136 dev->data->dev_conf.rxmode.jumbo_frame = 0;
139 /* Allocate the parallel driver ring for Rx buffers */
140 size = sizeof(*rxq->sw_rx_ring) * rxq->nb_rx_desc;
141 rxq->sw_rx_ring = rte_zmalloc_socket("sw_rx_ring", size,
142 RTE_CACHE_LINE_SIZE, socket_id);
143 if (!rxq->sw_rx_ring) {
144 DP_NOTICE(edev, false,
145 "Unable to alloc memory for sw_rx_ring on socket %u\n",
152 /* Allocate FW Rx ring */
153 rc = qdev->ops->common->chain_alloc(edev,
154 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
155 ECORE_CHAIN_MODE_NEXT_PTR,
156 ECORE_CHAIN_CNT_TYPE_U16,
158 sizeof(struct eth_rx_bd),
161 if (rc != ECORE_SUCCESS) {
162 DP_NOTICE(edev, false,
163 "Unable to alloc memory for rxbd ring on socket %u\n",
165 rte_free(rxq->sw_rx_ring);
166 rxq->sw_rx_ring = NULL;
171 /* Allocate FW completion ring */
172 rc = qdev->ops->common->chain_alloc(edev,
173 ECORE_CHAIN_USE_TO_CONSUME,
174 ECORE_CHAIN_MODE_PBL,
175 ECORE_CHAIN_CNT_TYPE_U16,
177 sizeof(union eth_rx_cqe),
180 if (rc != ECORE_SUCCESS) {
181 DP_NOTICE(edev, false,
182 "Unable to alloc memory for cqe ring on socket %u\n",
184 /* TBD: Freeing RX BD ring */
185 rte_free(rxq->sw_rx_ring);
186 rxq->sw_rx_ring = NULL;
190 /* Allocate buffers for the Rx ring */
191 for (i = 0; i < rxq->nb_rx_desc; i++) {
192 rc = qede_alloc_rx_buffer(rxq);
194 DP_NOTICE(edev, false,
195 "RX buffer allocation failed at idx=%d\n", i);
200 dev->data->rx_queues[queue_idx] = rxq;
201 if (!qdev->rx_queues)
202 qdev->rx_queues = (struct qede_rx_queue **)dev->data->rx_queues;
204 DP_INFO(edev, "rxq %d num_desc %u rx_buf_size=%u socket %u\n",
205 queue_idx, nb_desc, qdev->mtu, socket_id);
209 qede_rx_queue_release(rxq);
213 static void qede_tx_queue_release_mbufs(struct qede_tx_queue *txq)
217 PMD_TX_LOG(DEBUG, txq, "releasing %u mbufs\n", txq->nb_tx_desc);
219 if (txq->sw_tx_ring != NULL) {
220 for (i = 0; i < txq->nb_tx_desc; i++) {
221 if (txq->sw_tx_ring[i].mbuf != NULL) {
222 rte_pktmbuf_free(txq->sw_tx_ring[i].mbuf);
223 txq->sw_tx_ring[i].mbuf = NULL;
229 void qede_tx_queue_release(void *tx_queue)
231 struct qede_tx_queue *txq = tx_queue;
234 qede_tx_queue_release_mbufs(txq);
235 if (txq->sw_tx_ring) {
236 rte_free(txq->sw_tx_ring);
237 txq->sw_tx_ring = NULL;
245 qede_tx_queue_setup(struct rte_eth_dev *dev,
248 unsigned int socket_id,
249 const struct rte_eth_txconf *tx_conf)
251 struct qede_dev *qdev = dev->data->dev_private;
252 struct ecore_dev *edev = &qdev->edev;
253 struct qede_tx_queue *txq;
256 PMD_INIT_FUNC_TRACE(edev);
258 if (!rte_is_power_of_2(nb_desc)) {
259 DP_ERR(edev, "Ring size %u is not power of 2\n",
264 /* Free memory prior to re-allocation if needed... */
265 if (dev->data->tx_queues[queue_idx] != NULL) {
266 qede_tx_queue_release(dev->data->tx_queues[queue_idx]);
267 dev->data->tx_queues[queue_idx] = NULL;
270 txq = rte_zmalloc_socket("qede_tx_queue", sizeof(struct qede_tx_queue),
271 RTE_CACHE_LINE_SIZE, socket_id);
275 "Unable to allocate memory for txq on socket %u",
280 txq->nb_tx_desc = nb_desc;
282 txq->port_id = dev->data->port_id;
284 rc = qdev->ops->common->chain_alloc(edev,
285 ECORE_CHAIN_USE_TO_CONSUME_PRODUCE,
286 ECORE_CHAIN_MODE_PBL,
287 ECORE_CHAIN_CNT_TYPE_U16,
289 sizeof(union eth_tx_bd_types),
291 if (rc != ECORE_SUCCESS) {
293 "Unable to allocate memory for txbd ring on socket %u",
295 qede_tx_queue_release(txq);
299 /* Allocate software ring */
300 txq->sw_tx_ring = rte_zmalloc_socket("txq->sw_tx_ring",
301 (sizeof(struct qede_tx_entry) *
303 RTE_CACHE_LINE_SIZE, socket_id);
305 if (!txq->sw_tx_ring) {
307 "Unable to allocate memory for txbd ring on socket %u",
309 qede_tx_queue_release(txq);
313 txq->queue_id = queue_idx;
315 txq->nb_tx_avail = txq->nb_tx_desc;
317 txq->tx_free_thresh =
318 tx_conf->tx_free_thresh ? tx_conf->tx_free_thresh :
319 (txq->nb_tx_desc - QEDE_DEFAULT_TX_FREE_THRESH);
321 dev->data->tx_queues[queue_idx] = txq;
322 if (!qdev->tx_queues)
323 qdev->tx_queues = (struct qede_tx_queue **)dev->data->tx_queues;
325 txq->txq_counter = 0;
328 "txq %u num_desc %u tx_free_thresh %u socket %u\n",
329 queue_idx, nb_desc, txq->tx_free_thresh, socket_id);
334 /* This function inits fp content and resets the SB, RXQ and TXQ arrays */
335 static void qede_init_fp(struct qede_dev *qdev)
337 struct qede_fastpath *fp;
338 int rss_id, txq_index, tc;
340 memset((void *)qdev->fp_array, 0, (QEDE_RSS_CNT(qdev) *
341 sizeof(*qdev->fp_array)));
342 memset((void *)qdev->sb_array, 0, (QEDE_RSS_CNT(qdev) *
343 sizeof(*qdev->sb_array)));
344 for_each_rss(rss_id) {
345 fp = &qdev->fp_array[rss_id];
350 /* Point rxq to generic rte queues that was created
351 * as part of queue creation.
353 fp->rxq = qdev->rx_queues[rss_id];
354 fp->sb_info = &qdev->sb_array[rss_id];
356 for (tc = 0; tc < qdev->num_tc; tc++) {
357 txq_index = tc * QEDE_RSS_CNT(qdev) + rss_id;
358 fp->txqs[tc] = qdev->tx_queues[txq_index];
359 fp->txqs[tc]->queue_id = txq_index;
360 /* Updating it to main structure */
361 snprintf(fp->name, sizeof(fp->name), "%s-fp-%d",
366 qdev->gro_disable = gro_disable;
369 void qede_free_fp_arrays(struct qede_dev *qdev)
371 /* It asseumes qede_free_mem_load() is called before */
372 if (qdev->fp_array != NULL) {
373 rte_free(qdev->fp_array);
374 qdev->fp_array = NULL;
377 if (qdev->sb_array != NULL) {
378 rte_free(qdev->sb_array);
379 qdev->sb_array = NULL;
383 int qede_alloc_fp_array(struct qede_dev *qdev)
385 struct qede_fastpath *fp;
386 struct ecore_dev *edev = &qdev->edev;
389 qdev->fp_array = rte_calloc("fp", QEDE_RSS_CNT(qdev),
390 sizeof(*qdev->fp_array),
391 RTE_CACHE_LINE_SIZE);
393 if (!qdev->fp_array) {
394 DP_ERR(edev, "fp array allocation failed\n");
398 qdev->sb_array = rte_calloc("sb", QEDE_RSS_CNT(qdev),
399 sizeof(*qdev->sb_array),
400 RTE_CACHE_LINE_SIZE);
402 if (!qdev->sb_array) {
403 DP_ERR(edev, "sb array allocation failed\n");
404 rte_free(qdev->fp_array);
411 /* This function allocates fast-path status block memory */
413 qede_alloc_mem_sb(struct qede_dev *qdev, struct ecore_sb_info *sb_info,
416 struct ecore_dev *edev = &qdev->edev;
417 struct status_block *sb_virt;
421 sb_virt = OSAL_DMA_ALLOC_COHERENT(edev, &sb_phys, sizeof(*sb_virt));
424 DP_ERR(edev, "Status block allocation failed\n");
428 rc = qdev->ops->common->sb_init(edev, sb_info,
429 sb_virt, sb_phys, sb_id,
430 QED_SB_TYPE_L2_QUEUE);
432 DP_ERR(edev, "Status block initialization failed\n");
433 /* TBD: No dma_free_coherent possible */
440 static int qede_alloc_mem_fp(struct qede_dev *qdev, struct qede_fastpath *fp)
442 return qede_alloc_mem_sb(qdev, fp->sb_info, fp->rss_id);
445 static void qede_shrink_txq(struct qede_dev *qdev, uint16_t num_rss)
447 /* @@@TBD - this should also re-set the qed interrupts */
450 /* This function allocates all qede memory at NIC load. */
451 static int qede_alloc_mem_load(struct qede_dev *qdev)
454 struct ecore_dev *edev = &qdev->edev;
456 for (rss_id = 0; rss_id < QEDE_RSS_CNT(qdev); rss_id++) {
457 struct qede_fastpath *fp = &qdev->fp_array[rss_id];
459 rc = qede_alloc_mem_fp(qdev, fp);
464 if (rss_id != QEDE_RSS_CNT(qdev)) {
465 /* Failed allocating memory for all the queues */
468 "Failed to alloc memory for leading queue\n");
471 DP_NOTICE(edev, false,
472 "Failed to allocate memory for all of "
474 "Desired: %d queues, allocated: %d queues\n",
475 QEDE_RSS_CNT(qdev), rss_id);
476 qede_shrink_txq(qdev, rss_id);
478 qdev->num_rss = rss_id;
485 qede_update_rx_prod(struct qede_dev *edev, struct qede_rx_queue *rxq)
487 uint16_t bd_prod = ecore_chain_get_prod_idx(&rxq->rx_bd_ring);
488 uint16_t cqe_prod = ecore_chain_get_prod_idx(&rxq->rx_comp_ring);
489 struct eth_rx_prod_data rx_prods = { 0 };
491 /* Update producers */
492 rx_prods.bd_prod = rte_cpu_to_le_16(bd_prod);
493 rx_prods.cqe_prod = rte_cpu_to_le_16(cqe_prod);
495 /* Make sure that the BD and SGE data is updated before updating the
496 * producers since FW might read the BD/SGE right after the producer
501 internal_ram_wr(rxq->hw_rxq_prod_addr, sizeof(rx_prods),
502 (uint32_t *)&rx_prods);
504 /* mmiowb is needed to synchronize doorbell writes from more than one
505 * processor. It guarantees that the write arrives to the device before
506 * the napi lock is released and another qede_poll is called (possibly
507 * on another CPU). Without this barrier, the next doorbell can bypass
508 * this doorbell. This is applicable to IA64/Altix systems.
512 PMD_RX_LOG(DEBUG, rxq, "bd_prod %u cqe_prod %u\n", bd_prod, cqe_prod);
515 static inline uint32_t
516 qede_rxfh_indir_default(uint32_t index, uint32_t n_rx_rings)
518 return index % n_rx_rings;
521 static void qede_prandom_bytes(uint32_t *buff, size_t bytes)
525 srand((unsigned int)time(NULL));
527 for (i = 0; i < ECORE_RSS_KEY_SIZE; i++)
532 qede_config_rss(struct rte_eth_dev *eth_dev,
533 struct qed_update_vport_rss_params *rss_params)
535 enum rte_eth_rx_mq_mode mode = eth_dev->data->dev_conf.rxmode.mq_mode;
536 struct rte_eth_rss_conf rss_conf =
537 eth_dev->data->dev_conf.rx_adv_conf.rss_conf;
538 struct qede_dev *qdev = eth_dev->data->dev_private;
539 struct ecore_dev *edev = &qdev->edev;
542 PMD_INIT_FUNC_TRACE(edev);
544 /* Check if RSS conditions are met.
545 * Note: Even though its meaningless to enable RSS with one queue, it
546 * could be used to produce RSS Hash, so skipping that check.
549 if (!(mode & ETH_MQ_RX_RSS)) {
550 DP_INFO(edev, "RSS flag is not set\n");
554 DP_INFO(edev, "RSS flag is set\n");
556 if (rss_conf.rss_hf == 0) {
557 DP_NOTICE(edev, false, "No RSS hash function to apply\n");
561 if (rss_conf.rss_key != NULL) {
562 DP_NOTICE(edev, false,
563 "User provided RSS key is not supported\n");
567 memset(rss_params, 0, sizeof(*rss_params));
569 for (i = 0; i < ECORE_RSS_IND_TABLE_SIZE; i++)
570 rss_params->rss_ind_table[i] = qede_rxfh_indir_default(i,
573 qede_prandom_bytes(rss_params->rss_key,
574 sizeof(rss_params->rss_key));
576 DP_INFO(edev, "RSS check passes\n");
581 static int qede_start_queues(struct rte_eth_dev *eth_dev, bool clear_stats)
583 struct qede_dev *qdev = eth_dev->data->dev_private;
584 struct ecore_dev *edev = &qdev->edev;
585 struct qed_update_vport_rss_params *rss_params = &qdev->rss_params;
586 struct qed_dev_info *qed_info = &qdev->dev_info.common;
587 struct qed_update_vport_params vport_update_params;
588 struct qed_start_vport_params start = { 0 };
589 int vlan_removal_en = 1;
592 if (!qdev->num_rss) {
594 "Cannot update V-VPORT as active as "
595 "there are no Rx queues\n");
599 start.remove_inner_vlan = vlan_removal_en;
600 start.gro_enable = !qdev->gro_disable;
601 start.mtu = qdev->mtu;
603 start.drop_ttl0 = true;
604 start.clear_stats = clear_stats;
606 rc = qdev->ops->vport_start(edev, &start);
608 DP_ERR(edev, "Start V-PORT failed %d\n", rc);
613 "Start vport ramrod passed, vport_id = %d,"
614 " MTU = %d, vlan_removal_en = %d\n",
615 start.vport_id, qdev->mtu, vlan_removal_en);
618 struct qede_fastpath *fp = &qdev->fp_array[i];
619 dma_addr_t p_phys_table;
622 p_phys_table = ecore_chain_get_pbl_phys(&fp->rxq->rx_comp_ring);
623 page_cnt = ecore_chain_get_page_cnt(&fp->rxq->rx_comp_ring);
625 ecore_sb_ack(fp->sb_info, IGU_INT_DISABLE, 0); /* @DPDK */
627 rc = qdev->ops->q_rx_start(edev, i, i, 0,
628 fp->sb_info->igu_sb_id,
630 fp->rxq->rx_buf_size,
631 fp->rxq->rx_bd_ring.p_phys_addr,
634 &fp->rxq->hw_rxq_prod_addr);
636 DP_ERR(edev, "Start RXQ #%d failed %d\n", i, rc);
640 fp->rxq->hw_cons_ptr = &fp->sb_info->sb_virt->pi_array[RX_PI];
642 qede_update_rx_prod(qdev, fp->rxq);
644 for (tc = 0; tc < qdev->num_tc; tc++) {
645 struct qede_tx_queue *txq = fp->txqs[tc];
646 int txq_index = tc * QEDE_RSS_CNT(qdev) + i;
648 p_phys_table = ecore_chain_get_pbl_phys(&txq->tx_pbl);
649 page_cnt = ecore_chain_get_page_cnt(&txq->tx_pbl);
650 rc = qdev->ops->q_tx_start(edev, i, txq_index,
652 fp->sb_info->igu_sb_id,
654 p_phys_table, page_cnt,
655 &txq->doorbell_addr);
657 DP_ERR(edev, "Start txq %u failed %d\n",
663 &fp->sb_info->sb_virt->pi_array[TX_PI(tc)];
664 SET_FIELD(txq->tx_db.data.params,
665 ETH_DB_DATA_DEST, DB_DEST_XCM);
666 SET_FIELD(txq->tx_db.data.params, ETH_DB_DATA_AGG_CMD,
668 SET_FIELD(txq->tx_db.data.params,
669 ETH_DB_DATA_AGG_VAL_SEL,
670 DQ_XCM_ETH_TX_BD_PROD_CMD);
672 txq->tx_db.data.agg_flags = DQ_XCM_ETH_DQ_CF_CMD;
676 /* Prepare and send the vport enable */
677 memset(&vport_update_params, 0, sizeof(vport_update_params));
678 vport_update_params.vport_id = start.vport_id;
679 vport_update_params.update_vport_active_flg = 1;
680 vport_update_params.vport_active_flg = 1;
683 if (qed_info->mf_mode == MF_NPAR && qed_info->tx_switching) {
684 /* TBD: Check SRIOV enabled for VF */
685 vport_update_params.update_tx_switching_flg = 1;
686 vport_update_params.tx_switching_flg = 1;
689 if (!qede_config_rss(eth_dev, rss_params)) {
690 vport_update_params.update_rss_flg = 1;
692 qdev->rss_enabled = 1;
693 DP_INFO(edev, "Updating RSS flag\n");
695 qdev->rss_enabled = 0;
696 DP_INFO(edev, "Not Updating RSS flag\n");
699 rte_memcpy(&vport_update_params.rss_params, rss_params,
700 sizeof(*rss_params));
702 rc = qdev->ops->vport_update(edev, &vport_update_params);
704 DP_ERR(edev, "Update V-PORT failed %d\n", rc);
712 static bool qede_tunn_exist(uint16_t flag)
714 return !!((PARSING_AND_ERR_FLAGS_TUNNELEXIST_MASK <<
715 PARSING_AND_ERR_FLAGS_TUNNELEXIST_SHIFT) & flag);
718 static inline uint8_t qede_check_tunn_csum(uint16_t flag)
721 uint16_t csum_flag = 0;
723 if ((PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMWASCALCULATED_MASK <<
724 PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMWASCALCULATED_SHIFT) & flag)
725 csum_flag |= PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_MASK <<
726 PARSING_AND_ERR_FLAGS_TUNNELL4CHKSMERROR_SHIFT;
728 if ((PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK <<
729 PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT) & flag) {
730 csum_flag |= PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<
731 PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT;
732 tcsum = QEDE_TUNN_CSUM_UNNECESSARY;
735 csum_flag |= PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_MASK <<
736 PARSING_AND_ERR_FLAGS_TUNNELIPHDRERROR_SHIFT |
737 PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<
738 PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT;
740 if (csum_flag & flag)
741 return QEDE_CSUM_ERROR;
743 return QEDE_CSUM_UNNECESSARY | tcsum;
746 static inline uint8_t qede_tunn_exist(uint16_t flag)
751 static inline uint8_t qede_check_tunn_csum(uint16_t flag)
757 static inline uint8_t qede_check_notunn_csum(uint16_t flag)
760 uint16_t csum_flag = 0;
762 if ((PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_MASK <<
763 PARSING_AND_ERR_FLAGS_L4CHKSMWASCALCULATED_SHIFT) & flag) {
764 csum_flag |= PARSING_AND_ERR_FLAGS_L4CHKSMERROR_MASK <<
765 PARSING_AND_ERR_FLAGS_L4CHKSMERROR_SHIFT;
766 csum = QEDE_CSUM_UNNECESSARY;
769 csum_flag |= PARSING_AND_ERR_FLAGS_IPHDRERROR_MASK <<
770 PARSING_AND_ERR_FLAGS_IPHDRERROR_SHIFT;
772 if (csum_flag & flag)
773 return QEDE_CSUM_ERROR;
778 static inline uint8_t qede_check_csum(uint16_t flag)
780 if (likely(!qede_tunn_exist(flag)))
781 return qede_check_notunn_csum(flag);
783 return qede_check_tunn_csum(flag);
786 static inline void qede_rx_bd_ring_consume(struct qede_rx_queue *rxq)
788 ecore_chain_consume(&rxq->rx_bd_ring);
793 qede_reuse_page(struct qede_dev *qdev,
794 struct qede_rx_queue *rxq, struct qede_rx_entry *curr_cons)
796 struct eth_rx_bd *rx_bd_prod = ecore_chain_produce(&rxq->rx_bd_ring);
797 uint16_t idx = rxq->sw_rx_cons & NUM_RX_BDS(rxq);
798 struct qede_rx_entry *curr_prod;
799 dma_addr_t new_mapping;
801 curr_prod = &rxq->sw_rx_ring[idx];
802 *curr_prod = *curr_cons;
804 new_mapping = rte_mbuf_data_dma_addr_default(curr_prod->mbuf) +
805 curr_prod->page_offset;
807 rx_bd_prod->addr.hi = rte_cpu_to_le_32(U64_HI(new_mapping));
808 rx_bd_prod->addr.lo = rte_cpu_to_le_32(U64_LO(new_mapping));
814 qede_recycle_rx_bd_ring(struct qede_rx_queue *rxq,
815 struct qede_dev *qdev, uint8_t count)
817 struct qede_rx_entry *curr_cons;
819 for (; count > 0; count--) {
820 curr_cons = &rxq->sw_rx_ring[rxq->sw_rx_cons & NUM_RX_BDS(rxq)];
821 qede_reuse_page(qdev, rxq, curr_cons);
822 qede_rx_bd_ring_consume(rxq);
826 static inline uint32_t qede_rx_cqe_to_pkt_type(uint16_t flags)
829 /* TBD - L4 indications needed ? */
830 uint16_t protocol = ((PARSING_AND_ERR_FLAGS_L3TYPE_MASK <<
831 PARSING_AND_ERR_FLAGS_L3TYPE_SHIFT) & flags);
833 /* protocol = 3 means LLC/SNAP over Ethernet */
834 if (unlikely(protocol == 0 || protocol == 3))
835 p_type = RTE_PTYPE_UNKNOWN;
836 else if (protocol == 1)
837 p_type = RTE_PTYPE_L3_IPV4;
838 else if (protocol == 2)
839 p_type = RTE_PTYPE_L3_IPV6;
841 return RTE_PTYPE_L2_ETHER | p_type;
845 qede_recv_pkts(void *p_rxq, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
847 struct qede_rx_queue *rxq = p_rxq;
848 struct qede_dev *qdev = rxq->qdev;
849 struct ecore_dev *edev = &qdev->edev;
850 struct qede_fastpath *fp = &qdev->fp_array[rxq->queue_id];
851 uint16_t hw_comp_cons, sw_comp_cons, sw_rx_index;
853 union eth_rx_cqe *cqe;
854 struct eth_fast_path_rx_reg_cqe *fp_cqe;
855 register struct rte_mbuf *rx_mb = NULL;
856 enum eth_rx_cqe_type cqe_type;
858 uint16_t preload_idx;
861 enum rss_hash_type htype;
863 hw_comp_cons = rte_le_to_cpu_16(*rxq->hw_cons_ptr);
864 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
868 if (hw_comp_cons == sw_comp_cons)
871 while (sw_comp_cons != hw_comp_cons) {
872 /* Get the CQE from the completion ring */
874 (union eth_rx_cqe *)ecore_chain_consume(&rxq->rx_comp_ring);
875 cqe_type = cqe->fast_path_regular.type;
877 if (unlikely(cqe_type == ETH_RX_CQE_TYPE_SLOW_PATH)) {
878 PMD_RX_LOG(DEBUG, rxq, "Got a slowath CQE\n");
880 qdev->ops->eth_cqe_completion(edev, fp->rss_id,
881 (struct eth_slow_path_rx_cqe *)cqe);
885 /* Get the data from the SW ring */
886 sw_rx_index = rxq->sw_rx_cons & NUM_RX_BDS(rxq);
887 rx_mb = rxq->sw_rx_ring[sw_rx_index].mbuf;
888 assert(rx_mb != NULL);
891 fp_cqe = &cqe->fast_path_regular;
893 len = rte_le_to_cpu_16(fp_cqe->len_on_first_bd);
894 pad = fp_cqe->placement_offset;
895 assert((len + pad) <= rx_mb->buf_len);
897 PMD_RX_LOG(DEBUG, rxq,
898 "CQE type = 0x%x, flags = 0x%x, vlan = 0x%x"
899 " len = %u, parsing_flags = %d\n",
900 cqe_type, fp_cqe->bitfields,
901 rte_le_to_cpu_16(fp_cqe->vlan_tag),
902 len, rte_le_to_cpu_16(fp_cqe->pars_flags.flags));
904 /* If this is an error packet then drop it */
906 rte_le_to_cpu_16(cqe->fast_path_regular.pars_flags.flags);
907 csum_flag = qede_check_csum(parse_flag);
908 if (unlikely(csum_flag == QEDE_CSUM_ERROR)) {
910 "CQE in CONS = %u has error, flags = 0x%x "
911 "dropping incoming packet\n",
912 sw_comp_cons, parse_flag);
914 qede_recycle_rx_bd_ring(rxq, qdev, fp_cqe->bd_num);
918 if (unlikely(qede_alloc_rx_buffer(rxq) != 0)) {
920 "New buffer allocation failed,"
921 "dropping incoming packet\n");
922 qede_recycle_rx_bd_ring(rxq, qdev, fp_cqe->bd_num);
923 rte_eth_devices[rxq->port_id].
924 data->rx_mbuf_alloc_failed++;
925 rxq->rx_alloc_errors++;
929 qede_rx_bd_ring_consume(rxq);
931 /* Prefetch next mbuf while processing current one. */
932 preload_idx = rxq->sw_rx_cons & NUM_RX_BDS(rxq);
933 rte_prefetch0(rxq->sw_rx_ring[preload_idx].mbuf);
935 if (fp_cqe->bd_num != 1)
936 PMD_RX_LOG(DEBUG, rxq,
937 "Jumbo-over-BD packet not supported\n");
939 /* Update MBUF fields */
941 rx_mb->data_off = pad + RTE_PKTMBUF_HEADROOM;
943 rx_mb->data_len = len;
944 rx_mb->pkt_len = len;
945 rx_mb->port = rxq->port_id;
946 rx_mb->packet_type = qede_rx_cqe_to_pkt_type(parse_flag);
948 htype = (uint8_t)GET_FIELD(fp_cqe->bitfields,
949 ETH_FAST_PATH_RX_REG_CQE_RSS_HASH_TYPE);
950 if (qdev->rss_enabled && htype) {
951 rx_mb->ol_flags |= PKT_RX_RSS_HASH;
952 rx_mb->hash.rss = rte_le_to_cpu_32(fp_cqe->rss_hash);
953 PMD_RX_LOG(DEBUG, rxq, "Hash result 0x%x\n",
957 rte_prefetch1(rte_pktmbuf_mtod(rx_mb, void *));
959 if (CQE_HAS_VLAN(parse_flag)) {
960 rx_mb->vlan_tci = rte_le_to_cpu_16(fp_cqe->vlan_tag);
961 rx_mb->ol_flags |= PKT_RX_VLAN_PKT;
964 if (CQE_HAS_OUTER_VLAN(parse_flag)) {
965 /* FW does not provide indication of Outer VLAN tag,
966 * which is always stripped, so vlan_tci_outer is set
967 * to 0. Here vlan_tag represents inner VLAN tag.
969 rx_mb->vlan_tci = rte_le_to_cpu_16(fp_cqe->vlan_tag);
970 rx_mb->ol_flags |= PKT_RX_QINQ_PKT;
973 rx_pkts[rx_pkt] = rx_mb;
976 ecore_chain_recycle_consumed(&rxq->rx_comp_ring);
977 sw_comp_cons = ecore_chain_get_cons_idx(&rxq->rx_comp_ring);
978 if (rx_pkt == nb_pkts) {
979 PMD_RX_LOG(DEBUG, rxq,
980 "Budget reached nb_pkts=%u received=%u\n",
986 qede_update_rx_prod(qdev, rxq);
988 PMD_RX_LOG(DEBUG, rxq, "rx_pkts=%u core=%d\n", rx_pkt, rte_lcore_id());
994 qede_free_tx_pkt(struct ecore_dev *edev, struct qede_tx_queue *txq)
996 uint16_t idx = TX_CONS(txq);
997 struct eth_tx_bd *tx_data_bd;
998 struct rte_mbuf *mbuf = txq->sw_tx_ring[idx].mbuf;
1000 if (unlikely(!mbuf)) {
1001 PMD_TX_LOG(ERR, txq,
1002 "null mbuf nb_tx_desc %u nb_tx_avail %u "
1003 "sw_tx_cons %u sw_tx_prod %u\n",
1004 txq->nb_tx_desc, txq->nb_tx_avail, idx,
1010 rte_pktmbuf_free_seg(mbuf);
1011 txq->sw_tx_ring[idx].mbuf = NULL;
1012 ecore_chain_consume(&txq->tx_pbl);
1018 static inline uint16_t
1019 qede_process_tx_compl(struct ecore_dev *edev, struct qede_tx_queue *txq)
1021 uint16_t tx_compl = 0;
1022 uint16_t hw_bd_cons;
1025 hw_bd_cons = rte_le_to_cpu_16(*txq->hw_cons_ptr);
1026 rte_compiler_barrier();
1028 while (hw_bd_cons != ecore_chain_get_cons_idx(&txq->tx_pbl)) {
1029 rc = qede_free_tx_pkt(edev, txq);
1031 DP_NOTICE(edev, false,
1032 "hw_bd_cons = %d, chain_cons=%d\n",
1034 ecore_chain_get_cons_idx(&txq->tx_pbl));
1037 txq->sw_tx_cons++; /* Making TXD available */
1041 PMD_TX_LOG(DEBUG, txq, "Tx compl %u sw_tx_cons %u avail %u\n",
1042 tx_compl, txq->sw_tx_cons, txq->nb_tx_avail);
1047 qede_xmit_pkts(void *p_txq, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1049 struct qede_tx_queue *txq = p_txq;
1050 struct qede_dev *qdev = txq->qdev;
1051 struct ecore_dev *edev = &qdev->edev;
1052 struct qede_fastpath *fp = &qdev->fp_array[txq->queue_id];
1053 struct eth_tx_1st_bd *first_bd;
1054 uint16_t nb_tx_pkts;
1055 uint16_t nb_pkt_sent = 0;
1060 if (unlikely(txq->nb_tx_avail < txq->tx_free_thresh)) {
1061 PMD_TX_LOG(DEBUG, txq, "send=%u avail=%u free_thresh=%u\n",
1062 nb_pkts, txq->nb_tx_avail, txq->tx_free_thresh);
1063 (void)qede_process_tx_compl(edev, txq);
1066 nb_tx_pkts = RTE_MIN(nb_pkts, (txq->nb_tx_avail / MAX_NUM_TX_BDS));
1067 if (unlikely(nb_tx_pkts == 0)) {
1068 PMD_TX_LOG(DEBUG, txq, "Out of BDs nb_pkts=%u avail=%u\n",
1069 nb_pkts, txq->nb_tx_avail);
1073 tx_count = nb_tx_pkts;
1074 while (nb_tx_pkts--) {
1075 /* Fill the entry in the SW ring and the BDs in the FW ring */
1077 struct rte_mbuf *mbuf = *tx_pkts++;
1078 txq->sw_tx_ring[idx].mbuf = mbuf;
1079 first_bd = (struct eth_tx_1st_bd *)
1080 ecore_chain_produce(&txq->tx_pbl);
1081 first_bd->data.bd_flags.bitfields =
1082 1 << ETH_TX_1ST_BD_FLAGS_START_BD_SHIFT;
1083 /* Map MBUF linear data for DMA and set in the first BD */
1084 QEDE_BD_SET_ADDR_LEN(first_bd, rte_mbuf_data_dma_addr(mbuf),
1087 /* Descriptor based VLAN insertion */
1088 if (mbuf->ol_flags & (PKT_TX_VLAN_PKT | PKT_TX_QINQ_PKT)) {
1089 first_bd->data.vlan = rte_cpu_to_le_16(mbuf->vlan_tci);
1090 first_bd->data.bd_flags.bitfields |=
1091 1 << ETH_TX_1ST_BD_FLAGS_VLAN_INSERTION_SHIFT;
1094 /* Offload the IP checksum in the hardware */
1095 if (mbuf->ol_flags & PKT_TX_IP_CKSUM) {
1096 first_bd->data.bd_flags.bitfields |=
1097 1 << ETH_TX_1ST_BD_FLAGS_IP_CSUM_SHIFT;
1100 /* L4 checksum offload (tcp or udp) */
1101 if (mbuf->ol_flags & (PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
1102 first_bd->data.bd_flags.bitfields |=
1103 1 << ETH_TX_1ST_BD_FLAGS_L4_CSUM_SHIFT;
1104 /* IPv6 + extn. -> later */
1106 first_bd->data.nbds = MAX_NUM_TX_BDS;
1108 rte_prefetch0(txq->sw_tx_ring[TX_PROD(txq)].mbuf);
1111 rte_cpu_to_le_16(ecore_chain_get_prod_idx(&txq->tx_pbl));
1115 /* Write value of prod idx into bd_prod */
1116 txq->tx_db.data.bd_prod = bd_prod;
1118 rte_compiler_barrier();
1119 DIRECT_REG_WR(edev, txq->doorbell_addr, txq->tx_db.raw);
1122 /* Check again for Tx completions */
1123 (void)qede_process_tx_compl(edev, txq);
1125 PMD_TX_LOG(DEBUG, txq, "to_send=%u can_send=%u sent=%u core=%d\n",
1126 nb_pkts, tx_count, nb_pkt_sent, rte_lcore_id());
1131 int qede_dev_start(struct rte_eth_dev *eth_dev)
1133 struct qede_dev *qdev = eth_dev->data->dev_private;
1134 struct ecore_dev *edev = &qdev->edev;
1135 struct qed_link_output link_output;
1138 DP_INFO(edev, "port %u\n", eth_dev->data->port_id);
1140 if (qdev->state == QEDE_START) {
1141 DP_INFO(edev, "device already started\n");
1145 if (qdev->state == QEDE_CLOSE) {
1146 rc = qede_alloc_fp_array(qdev);
1148 rc = qede_alloc_mem_load(qdev);
1149 DP_INFO(edev, "Allocated %d RSS queues on %d TC/s\n",
1150 QEDE_RSS_CNT(qdev), qdev->num_tc);
1151 } else if (qdev->state == QEDE_STOP) {
1152 DP_INFO(edev, "restarting port %u\n", eth_dev->data->port_id);
1154 DP_INFO(edev, "unknown state port %u\n",
1155 eth_dev->data->port_id);
1159 rc = qede_start_queues(eth_dev, true);
1162 DP_ERR(edev, "Failed to start queues\n");
1167 DP_INFO(edev, "Start VPORT, RXQ and TXQ succeeded\n");
1169 qede_dev_set_link_state(eth_dev, true);
1171 /* Query whether link is already-up */
1172 memset(&link_output, 0, sizeof(link_output));
1173 qdev->ops->common->get_link(edev, &link_output);
1174 DP_NOTICE(edev, false, "link status: %s\n",
1175 link_output.link_up ? "up" : "down");
1177 qdev->state = QEDE_START;
1179 qede_config_rx_mode(eth_dev);
1181 DP_INFO(edev, "dev_state is QEDE_START\n");
1186 static int qede_drain_txq(struct qede_dev *qdev,
1187 struct qede_tx_queue *txq, bool allow_drain)
1189 struct ecore_dev *edev = &qdev->edev;
1192 while (txq->sw_tx_cons != txq->sw_tx_prod) {
1193 qede_process_tx_compl(edev, txq);
1196 DP_NOTICE(edev, false,
1197 "Tx queue[%u] is stuck,"
1198 "requesting MCP to drain\n",
1200 rc = qdev->ops->common->drain(edev);
1203 return qede_drain_txq(qdev, txq, false);
1206 DP_NOTICE(edev, false,
1207 "Timeout waiting for tx queue[%d]:"
1208 "PROD=%d, CONS=%d\n",
1209 txq->queue_id, txq->sw_tx_prod,
1215 rte_compiler_barrier();
1218 /* FW finished processing, wait for HW to transmit all tx packets */
1224 static int qede_stop_queues(struct qede_dev *qdev)
1226 struct qed_update_vport_params vport_update_params;
1227 struct ecore_dev *edev = &qdev->edev;
1230 /* Disable the vport */
1231 memset(&vport_update_params, 0, sizeof(vport_update_params));
1232 vport_update_params.vport_id = 0;
1233 vport_update_params.update_vport_active_flg = 1;
1234 vport_update_params.vport_active_flg = 0;
1235 vport_update_params.update_rss_flg = 0;
1237 DP_INFO(edev, "vport_update\n");
1239 rc = qdev->ops->vport_update(edev, &vport_update_params);
1241 DP_ERR(edev, "Failed to update vport\n");
1245 DP_INFO(edev, "Flushing tx queues\n");
1247 /* Flush Tx queues. If needed, request drain from MCP */
1249 struct qede_fastpath *fp = &qdev->fp_array[i];
1250 for (tc = 0; tc < qdev->num_tc; tc++) {
1251 struct qede_tx_queue *txq = fp->txqs[tc];
1252 rc = qede_drain_txq(qdev, txq, true);
1258 /* Stop all Queues in reverse order */
1259 for (i = QEDE_RSS_CNT(qdev) - 1; i >= 0; i--) {
1260 struct qed_stop_rxq_params rx_params;
1262 /* Stop the Tx Queue(s) */
1263 for (tc = 0; tc < qdev->num_tc; tc++) {
1264 struct qed_stop_txq_params tx_params;
1266 tx_params.rss_id = i;
1267 tx_params.tx_queue_id = tc * QEDE_RSS_CNT(qdev) + i;
1269 DP_INFO(edev, "Stopping tx queues\n");
1270 rc = qdev->ops->q_tx_stop(edev, &tx_params);
1272 DP_ERR(edev, "Failed to stop TXQ #%d\n",
1273 tx_params.tx_queue_id);
1278 /* Stop the Rx Queue */
1279 memset(&rx_params, 0, sizeof(rx_params));
1280 rx_params.rss_id = i;
1281 rx_params.rx_queue_id = i;
1282 rx_params.eq_completion_only = 1;
1284 DP_INFO(edev, "Stopping rx queues\n");
1286 rc = qdev->ops->q_rx_stop(edev, &rx_params);
1288 DP_ERR(edev, "Failed to stop RXQ #%d\n", i);
1293 DP_INFO(edev, "Stopping vports\n");
1295 /* Stop the vport */
1296 rc = qdev->ops->vport_stop(edev, 0);
1298 DP_ERR(edev, "Failed to stop VPORT\n");
1303 void qede_reset_fp_rings(struct qede_dev *qdev)
1308 for_each_rss(rss_id) {
1309 DP_INFO(&qdev->edev, "reset fp chain for rss %u\n", rss_id);
1310 struct qede_fastpath *fp = &qdev->fp_array[rss_id];
1311 ecore_chain_reset(&fp->rxq->rx_bd_ring);
1312 ecore_chain_reset(&fp->rxq->rx_comp_ring);
1313 for (tc = 0; tc < qdev->num_tc; tc++) {
1314 struct qede_tx_queue *txq = fp->txqs[tc];
1315 ecore_chain_reset(&txq->tx_pbl);
1320 /* This function frees all memory of a single fp */
1321 static void qede_free_mem_fp(struct qede_dev *qdev, struct qede_fastpath *fp)
1325 qede_rx_queue_release(fp->rxq);
1326 for (tc = 0; tc < qdev->num_tc; tc++)
1327 qede_tx_queue_release(fp->txqs[tc]);
1330 void qede_free_mem_load(struct qede_dev *qdev)
1334 for_each_rss(rss_id) {
1335 struct qede_fastpath *fp = &qdev->fp_array[rss_id];
1336 qede_free_mem_fp(qdev, fp);
1338 /* qdev->num_rss = 0; */
1342 * Stop an Ethernet device. The device can be restarted with a call to
1343 * rte_eth_dev_start().
1344 * Do not change link state and do not release sw structures.
1346 void qede_dev_stop(struct rte_eth_dev *eth_dev)
1348 struct qede_dev *qdev = eth_dev->data->dev_private;
1349 struct ecore_dev *edev = &qdev->edev;
1352 DP_INFO(edev, "port %u\n", eth_dev->data->port_id);
1354 if (qdev->state != QEDE_START) {
1355 DP_INFO(edev, "device not yet started\n");
1359 rc = qede_stop_queues(qdev);
1362 DP_ERR(edev, "Didn't succeed to close queues\n");
1364 DP_INFO(edev, "Stopped queues\n");
1366 qdev->ops->fastpath_stop(edev);
1368 qede_reset_fp_rings(qdev);
1370 qdev->state = QEDE_STOP;
1372 DP_INFO(edev, "dev_state is QEDE_STOP\n");