1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include <rte_ethdev.h>
6 #include <rte_mbuf_pool_ops.h>
8 #include "otx2_ethdev.h"
11 otx2_nix_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
13 uint32_t buffsz, frame_size = mtu + NIX_L2_OVERHEAD;
14 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
15 struct rte_eth_dev_data *data = eth_dev->data;
16 struct otx2_mbox *mbox = dev->mbox;
17 struct nix_frs_cfg *req;
20 if (dev->configured && otx2_ethdev_is_ptp_en(dev))
21 frame_size += NIX_TIMESYNC_RX_OFFSET;
23 /* Check if MTU is within the allowed range */
24 if (frame_size < NIX_MIN_FRS || frame_size > NIX_MAX_FRS)
27 buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
29 /* Refuse MTU that requires the support of scattered packets
30 * when this feature has not been enabled before.
32 if (data->dev_started && frame_size > buffsz &&
33 !(dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER))
36 /* Check <seg size> * <max_seg> >= max_frame */
37 if ((dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER) &&
38 (frame_size > buffsz * NIX_RX_NB_SEG_MAX))
41 req = otx2_mbox_alloc_msg_nix_set_hw_frs(mbox);
42 req->update_smq = true;
43 if (otx2_dev_is_sdp(dev))
45 /* FRS HW config should exclude FCS but include NPC VTAG insert size */
46 req->maxlen = frame_size - RTE_ETHER_CRC_LEN + NIX_MAX_VTAG_ACT_SIZE;
48 rc = otx2_mbox_process(mbox);
52 /* Now just update Rx MAXLEN */
53 req = otx2_mbox_alloc_msg_nix_set_hw_frs(mbox);
54 req->maxlen = frame_size - RTE_ETHER_CRC_LEN;
55 if (otx2_dev_is_sdp(dev))
58 rc = otx2_mbox_process(mbox);
62 if (frame_size > NIX_L2_MAX_LEN)
63 dev->rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
65 dev->rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
67 /* Update max_rx_pkt_len */
68 data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
74 otx2_nix_recalc_mtu(struct rte_eth_dev *eth_dev)
76 struct rte_eth_dev_data *data = eth_dev->data;
77 struct otx2_eth_rxq *rxq;
81 rxq = data->rx_queues[0];
83 /* Setup scatter mode if needed by jumbo */
84 otx2_nix_enable_mseg_on_jumbo(rxq);
86 /* Setup MTU based on max_rx_pkt_len */
87 mtu = data->dev_conf.rxmode.max_rx_pkt_len - NIX_L2_OVERHEAD;
89 rc = otx2_nix_mtu_set(eth_dev, mtu);
91 otx2_err("Failed to set default MTU size %d", rc);
97 nix_cgx_promisc_config(struct rte_eth_dev *eth_dev, int en)
99 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
100 struct otx2_mbox *mbox = dev->mbox;
102 if (otx2_dev_is_vf_or_sdp(dev))
106 otx2_mbox_alloc_msg_cgx_promisc_enable(mbox);
108 otx2_mbox_alloc_msg_cgx_promisc_disable(mbox);
110 otx2_mbox_process(mbox);
114 otx2_nix_promisc_config(struct rte_eth_dev *eth_dev, int en)
116 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
117 struct otx2_mbox *mbox = dev->mbox;
118 struct nix_rx_mode *req;
120 if (otx2_dev_is_vf(dev))
123 req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
126 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
128 otx2_mbox_process(mbox);
129 eth_dev->data->promiscuous = en;
130 otx2_nix_vlan_update_promisc(eth_dev, en);
134 otx2_nix_promisc_enable(struct rte_eth_dev *eth_dev)
136 otx2_nix_promisc_config(eth_dev, 1);
137 nix_cgx_promisc_config(eth_dev, 1);
143 otx2_nix_promisc_disable(struct rte_eth_dev *eth_dev)
145 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
146 otx2_nix_promisc_config(eth_dev, dev->dmac_filter_enable);
147 nix_cgx_promisc_config(eth_dev, 0);
148 dev->dmac_filter_enable = false;
154 nix_allmulticast_config(struct rte_eth_dev *eth_dev, int en)
156 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
157 struct otx2_mbox *mbox = dev->mbox;
158 struct nix_rx_mode *req;
160 if (otx2_dev_is_vf(dev))
163 req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
166 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_ALLMULTI;
167 else if (eth_dev->data->promiscuous)
168 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
170 otx2_mbox_process(mbox);
174 otx2_nix_allmulticast_enable(struct rte_eth_dev *eth_dev)
176 nix_allmulticast_config(eth_dev, 1);
182 otx2_nix_allmulticast_disable(struct rte_eth_dev *eth_dev)
184 nix_allmulticast_config(eth_dev, 0);
190 otx2_nix_rxq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
191 struct rte_eth_rxq_info *qinfo)
193 struct otx2_eth_rxq *rxq;
195 rxq = eth_dev->data->rx_queues[queue_id];
197 qinfo->mp = rxq->pool;
198 qinfo->scattered_rx = eth_dev->data->scattered_rx;
199 qinfo->nb_desc = rxq->qconf.nb_desc;
201 qinfo->conf.rx_free_thresh = 0;
202 qinfo->conf.rx_drop_en = 0;
203 qinfo->conf.rx_deferred_start = 0;
204 qinfo->conf.offloads = rxq->offloads;
208 otx2_nix_txq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
209 struct rte_eth_txq_info *qinfo)
211 struct otx2_eth_txq *txq;
213 txq = eth_dev->data->tx_queues[queue_id];
215 qinfo->nb_desc = txq->qconf.nb_desc;
217 qinfo->conf.tx_thresh.pthresh = 0;
218 qinfo->conf.tx_thresh.hthresh = 0;
219 qinfo->conf.tx_thresh.wthresh = 0;
221 qinfo->conf.tx_free_thresh = 0;
222 qinfo->conf.tx_rs_thresh = 0;
223 qinfo->conf.offloads = txq->offloads;
224 qinfo->conf.tx_deferred_start = 0;
228 otx2_rx_burst_mode_get(struct rte_eth_dev *eth_dev,
229 __rte_unused uint16_t queue_id,
230 struct rte_eth_burst_mode *mode)
232 ssize_t bytes = 0, str_size = RTE_ETH_BURST_MODE_INFO_SIZE, rc;
233 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
234 const struct burst_info {
237 } rx_offload_map[] = {
238 {NIX_RX_OFFLOAD_RSS_F, "RSS,"},
239 {NIX_RX_OFFLOAD_PTYPE_F, " Ptype,"},
240 {NIX_RX_OFFLOAD_CHECKSUM_F, " Checksum,"},
241 {NIX_RX_OFFLOAD_VLAN_STRIP_F, " VLAN Strip,"},
242 {NIX_RX_OFFLOAD_MARK_UPDATE_F, " Mark Update,"},
243 {NIX_RX_OFFLOAD_TSTAMP_F, " Timestamp,"},
244 {NIX_RX_MULTI_SEG_F, " Scattered,"}
246 static const char *const burst_mode[] = {"Vector Neon, Rx Offloads:",
247 "Scalar, Rx Offloads:"
251 /* Update burst mode info */
252 rc = rte_strscpy(mode->info + bytes, burst_mode[dev->scalar_ena],
259 /* Update Rx offload info */
260 for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
261 if (dev->rx_offload_flags & rx_offload_map[i].flags) {
262 rc = rte_strscpy(mode->info + bytes,
263 rx_offload_map[i].output,
277 otx2_tx_burst_mode_get(struct rte_eth_dev *eth_dev,
278 __rte_unused uint16_t queue_id,
279 struct rte_eth_burst_mode *mode)
281 ssize_t bytes = 0, str_size = RTE_ETH_BURST_MODE_INFO_SIZE, rc;
282 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
283 const struct burst_info {
286 } tx_offload_map[] = {
287 {NIX_TX_OFFLOAD_L3_L4_CSUM_F, " Inner L3/L4 csum,"},
288 {NIX_TX_OFFLOAD_OL3_OL4_CSUM_F, " Outer L3/L4 csum,"},
289 {NIX_TX_OFFLOAD_VLAN_QINQ_F, " VLAN Insertion,"},
290 {NIX_TX_OFFLOAD_MBUF_NOFF_F, " MBUF free disable,"},
291 {NIX_TX_OFFLOAD_TSTAMP_F, " Timestamp,"},
292 {NIX_TX_OFFLOAD_TSO_F, " TSO,"},
293 {NIX_TX_MULTI_SEG_F, " Scattered,"}
295 static const char *const burst_mode[] = {"Vector Neon, Tx Offloads:",
296 "Scalar, Tx Offloads:"
300 /* Update burst mode info */
301 rc = rte_strscpy(mode->info + bytes, burst_mode[dev->scalar_ena],
308 /* Update Tx offload info */
309 for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
310 if (dev->tx_offload_flags & tx_offload_map[i].flags) {
311 rc = rte_strscpy(mode->info + bytes,
312 tx_offload_map[i].output,
326 nix_rx_head_tail_get(struct otx2_eth_dev *dev,
327 uint32_t *head, uint32_t *tail, uint16_t queue_idx)
331 if (head == NULL || tail == NULL)
334 reg = (((uint64_t)queue_idx) << 32);
335 val = otx2_atomic64_add_nosync(reg, (int64_t *)
336 (dev->base + NIX_LF_CQ_OP_STATUS));
337 if (val & (OP_ERR | CQ_ERR))
340 *tail = (uint32_t)(val & 0xFFFFF);
341 *head = (uint32_t)((val >> 20) & 0xFFFFF);
345 otx2_nix_rx_queue_count(struct rte_eth_dev *eth_dev, uint16_t queue_idx)
347 struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[queue_idx];
348 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
351 nix_rx_head_tail_get(dev, &head, &tail, queue_idx);
352 return (tail - head) % rxq->qlen;
356 nix_offset_has_packet(uint32_t head, uint32_t tail, uint16_t offset)
358 /* Check given offset(queue index) has packet filled by HW */
359 if (tail > head && offset <= tail && offset >= head)
361 /* Wrap around case */
362 if (head > tail && (offset >= head || offset <= tail))
369 otx2_nix_rx_descriptor_status(void *rx_queue, uint16_t offset)
371 struct otx2_eth_rxq *rxq = rx_queue;
374 if (rxq->qlen <= offset)
377 nix_rx_head_tail_get(otx2_eth_pmd_priv(rxq->eth_dev),
378 &head, &tail, rxq->rq);
380 if (nix_offset_has_packet(head, tail, offset))
381 return RTE_ETH_RX_DESC_DONE;
383 return RTE_ETH_RX_DESC_AVAIL;
387 nix_tx_head_tail_get(struct otx2_eth_dev *dev,
388 uint32_t *head, uint32_t *tail, uint16_t queue_idx)
392 if (head == NULL || tail == NULL)
395 reg = (((uint64_t)queue_idx) << 32);
396 val = otx2_atomic64_add_nosync(reg, (int64_t *)
397 (dev->base + NIX_LF_SQ_OP_STATUS));
401 *tail = (uint32_t)((val >> 28) & 0x3F);
402 *head = (uint32_t)((val >> 20) & 0x3F);
406 otx2_nix_tx_descriptor_status(void *tx_queue, uint16_t offset)
408 struct otx2_eth_txq *txq = tx_queue;
411 if (txq->qconf.nb_desc <= offset)
414 nix_tx_head_tail_get(txq->dev, &head, &tail, txq->sq);
416 if (nix_offset_has_packet(head, tail, offset))
417 return RTE_ETH_TX_DESC_DONE;
419 return RTE_ETH_TX_DESC_FULL;
422 /* It is a NOP for octeontx2 as HW frees the buffer on xmit */
424 otx2_nix_tx_done_cleanup(void *txq, uint32_t free_cnt)
427 RTE_SET_USED(free_cnt);
433 otx2_nix_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version,
436 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
437 int rc = (int)fw_size;
439 if (fw_size > sizeof(dev->mkex_pfl_name))
440 rc = sizeof(dev->mkex_pfl_name);
442 rc = strlcpy(fw_version, (char *)dev->mkex_pfl_name, rc);
444 rc += 1; /* Add the size of '\0' */
445 if (fw_size < (size_t)rc)
452 otx2_nix_pool_ops_supported(struct rte_eth_dev *eth_dev, const char *pool)
454 RTE_SET_USED(eth_dev);
456 if (!strcmp(pool, rte_mbuf_platform_mempool_ops()))
463 otx2_nix_dev_flow_ops_get(struct rte_eth_dev *eth_dev __rte_unused,
464 const struct rte_flow_ops **ops)
466 *ops = &otx2_flow_ops;
470 static struct cgx_fw_data *
471 nix_get_fwdata(struct otx2_eth_dev *dev)
473 struct otx2_mbox *mbox = dev->mbox;
474 struct cgx_fw_data *rsp = NULL;
477 otx2_mbox_alloc_msg_cgx_get_aux_link_info(mbox);
479 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
481 otx2_err("Failed to get fw data: %d", rc);
489 otx2_nix_get_module_info(struct rte_eth_dev *eth_dev,
490 struct rte_eth_dev_module_info *modinfo)
492 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
493 struct cgx_fw_data *rsp;
495 rsp = nix_get_fwdata(dev);
499 modinfo->type = rsp->fwdata.sfp_eeprom.sff_id;
500 modinfo->eeprom_len = SFP_EEPROM_SIZE;
506 otx2_nix_get_module_eeprom(struct rte_eth_dev *eth_dev,
507 struct rte_dev_eeprom_info *info)
509 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
510 struct cgx_fw_data *rsp;
512 if (info->offset + info->length > SFP_EEPROM_SIZE)
515 rsp = nix_get_fwdata(dev);
519 otx2_mbox_memcpy(info->data, rsp->fwdata.sfp_eeprom.buf + info->offset,
526 otx2_nix_info_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *devinfo)
528 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
529 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
531 devinfo->min_rx_bufsize = NIX_MIN_FRS;
532 devinfo->max_rx_pktlen = NIX_MAX_FRS;
533 devinfo->max_rx_queues = RTE_MAX_QUEUES_PER_PORT;
534 devinfo->max_tx_queues = RTE_MAX_QUEUES_PER_PORT;
535 devinfo->max_mac_addrs = dev->max_mac_entries;
536 devinfo->max_vfs = pci_dev->max_vfs;
537 devinfo->max_mtu = devinfo->max_rx_pktlen - NIX_L2_OVERHEAD;
538 devinfo->min_mtu = devinfo->min_rx_bufsize - NIX_L2_OVERHEAD;
539 if (dev->configured && otx2_ethdev_is_ptp_en(dev)) {
540 devinfo->max_mtu -= NIX_TIMESYNC_RX_OFFSET;
541 devinfo->min_mtu -= NIX_TIMESYNC_RX_OFFSET;
542 devinfo->max_rx_pktlen -= NIX_TIMESYNC_RX_OFFSET;
545 devinfo->rx_offload_capa = dev->rx_offload_capa;
546 devinfo->tx_offload_capa = dev->tx_offload_capa;
547 devinfo->rx_queue_offload_capa = 0;
548 devinfo->tx_queue_offload_capa = 0;
550 devinfo->reta_size = dev->rss_info.rss_size;
551 devinfo->hash_key_size = NIX_HASH_KEY_SIZE;
552 devinfo->flow_type_rss_offloads = NIX_RSS_OFFLOAD;
554 devinfo->default_rxconf = (struct rte_eth_rxconf) {
559 devinfo->default_txconf = (struct rte_eth_txconf) {
563 devinfo->default_rxportconf = (struct rte_eth_dev_portconf) {
564 .ring_size = NIX_RX_DEFAULT_RING_SZ,
567 devinfo->rx_desc_lim = (struct rte_eth_desc_lim) {
568 .nb_max = UINT16_MAX,
569 .nb_min = NIX_RX_MIN_DESC,
570 .nb_align = NIX_RX_MIN_DESC_ALIGN,
571 .nb_seg_max = NIX_RX_NB_SEG_MAX,
572 .nb_mtu_seg_max = NIX_RX_NB_SEG_MAX,
574 devinfo->rx_desc_lim.nb_max =
575 RTE_ALIGN_MUL_FLOOR(devinfo->rx_desc_lim.nb_max,
576 NIX_RX_MIN_DESC_ALIGN);
578 devinfo->tx_desc_lim = (struct rte_eth_desc_lim) {
579 .nb_max = UINT16_MAX,
582 .nb_seg_max = NIX_TX_NB_SEG_MAX,
583 .nb_mtu_seg_max = NIX_TX_NB_SEG_MAX,
586 /* Auto negotiation disabled */
587 devinfo->speed_capa = ETH_LINK_SPEED_FIXED;
588 if (!otx2_dev_is_vf_or_sdp(dev) && !otx2_dev_is_lbk(dev)) {
589 devinfo->speed_capa |= ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
590 ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G;
592 /* 50G and 100G to be supported for board version C0
595 if (!otx2_dev_is_Ax(dev))
596 devinfo->speed_capa |= ETH_LINK_SPEED_50G |
600 devinfo->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
601 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;