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 frame_size += NIX_TIMESYNC_RX_OFFSET * otx2_ethdev_is_ptp_en(dev);
22 /* Check if MTU is within the allowed range */
23 if (frame_size < NIX_MIN_FRS || frame_size > NIX_MAX_FRS)
26 buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
28 /* Refuse MTU that requires the support of scattered packets
29 * when this feature has not been enabled before.
31 if (data->dev_started && frame_size > buffsz &&
32 !(dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER))
35 /* Check <seg size> * <max_seg> >= max_frame */
36 if ((dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER) &&
37 (frame_size > buffsz * NIX_RX_NB_SEG_MAX))
40 req = otx2_mbox_alloc_msg_nix_set_hw_frs(mbox);
41 req->update_smq = true;
42 if (otx2_dev_is_sdp(dev))
44 /* FRS HW config should exclude FCS but include NPC VTAG insert size */
45 req->maxlen = frame_size - RTE_ETHER_CRC_LEN + NIX_MAX_VTAG_ACT_SIZE;
47 rc = otx2_mbox_process(mbox);
51 /* Now just update Rx MAXLEN */
52 req = otx2_mbox_alloc_msg_nix_set_hw_frs(mbox);
53 req->maxlen = frame_size - RTE_ETHER_CRC_LEN;
54 if (otx2_dev_is_sdp(dev))
57 rc = otx2_mbox_process(mbox);
61 if (frame_size > RTE_ETHER_MAX_LEN)
62 dev->rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
64 dev->rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
66 /* Update max_rx_pkt_len */
67 data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
73 otx2_nix_recalc_mtu(struct rte_eth_dev *eth_dev)
75 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
76 struct rte_eth_dev_data *data = eth_dev->data;
77 struct rte_pktmbuf_pool_private *mbp_priv;
78 struct otx2_eth_rxq *rxq;
83 /* Get rx buffer size */
84 rxq = data->rx_queues[0];
85 mbp_priv = rte_mempool_get_priv(rxq->pool);
86 buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
88 /* Setup scatter mode if needed by jumbo */
89 if (data->dev_conf.rxmode.max_rx_pkt_len > buffsz)
90 dev->rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
92 /* Setup MTU based on max_rx_pkt_len */
93 mtu = data->dev_conf.rxmode.max_rx_pkt_len - NIX_L2_OVERHEAD;
95 rc = otx2_nix_mtu_set(eth_dev, mtu);
97 otx2_err("Failed to set default MTU size %d", rc);
103 nix_cgx_promisc_config(struct rte_eth_dev *eth_dev, int en)
105 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
106 struct otx2_mbox *mbox = dev->mbox;
108 if (otx2_dev_is_vf_or_sdp(dev))
112 otx2_mbox_alloc_msg_cgx_promisc_enable(mbox);
114 otx2_mbox_alloc_msg_cgx_promisc_disable(mbox);
116 otx2_mbox_process(mbox);
120 otx2_nix_promisc_config(struct rte_eth_dev *eth_dev, int en)
122 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
123 struct otx2_mbox *mbox = dev->mbox;
124 struct nix_rx_mode *req;
126 if (otx2_dev_is_vf(dev))
129 req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
132 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
134 otx2_mbox_process(mbox);
135 eth_dev->data->promiscuous = en;
136 otx2_nix_vlan_update_promisc(eth_dev, en);
140 otx2_nix_promisc_enable(struct rte_eth_dev *eth_dev)
142 otx2_nix_promisc_config(eth_dev, 1);
143 nix_cgx_promisc_config(eth_dev, 1);
149 otx2_nix_promisc_disable(struct rte_eth_dev *eth_dev)
151 otx2_nix_promisc_config(eth_dev, 0);
152 nix_cgx_promisc_config(eth_dev, 0);
158 nix_allmulticast_config(struct rte_eth_dev *eth_dev, int en)
160 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
161 struct otx2_mbox *mbox = dev->mbox;
162 struct nix_rx_mode *req;
164 if (otx2_dev_is_vf(dev))
167 req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
170 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_ALLMULTI;
171 else if (eth_dev->data->promiscuous)
172 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
174 otx2_mbox_process(mbox);
178 otx2_nix_allmulticast_enable(struct rte_eth_dev *eth_dev)
180 nix_allmulticast_config(eth_dev, 1);
186 otx2_nix_allmulticast_disable(struct rte_eth_dev *eth_dev)
188 nix_allmulticast_config(eth_dev, 0);
194 otx2_nix_rxq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
195 struct rte_eth_rxq_info *qinfo)
197 struct otx2_eth_rxq *rxq;
199 rxq = eth_dev->data->rx_queues[queue_id];
201 qinfo->mp = rxq->pool;
202 qinfo->scattered_rx = eth_dev->data->scattered_rx;
203 qinfo->nb_desc = rxq->qconf.nb_desc;
205 qinfo->conf.rx_free_thresh = 0;
206 qinfo->conf.rx_drop_en = 0;
207 qinfo->conf.rx_deferred_start = 0;
208 qinfo->conf.offloads = rxq->offloads;
212 otx2_nix_txq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
213 struct rte_eth_txq_info *qinfo)
215 struct otx2_eth_txq *txq;
217 txq = eth_dev->data->tx_queues[queue_id];
219 qinfo->nb_desc = txq->qconf.nb_desc;
221 qinfo->conf.tx_thresh.pthresh = 0;
222 qinfo->conf.tx_thresh.hthresh = 0;
223 qinfo->conf.tx_thresh.wthresh = 0;
225 qinfo->conf.tx_free_thresh = 0;
226 qinfo->conf.tx_rs_thresh = 0;
227 qinfo->conf.offloads = txq->offloads;
228 qinfo->conf.tx_deferred_start = 0;
232 otx2_rx_burst_mode_get(struct rte_eth_dev *eth_dev,
233 __rte_unused uint16_t queue_id,
234 struct rte_eth_burst_mode *mode)
236 ssize_t bytes = 0, str_size = RTE_ETH_BURST_MODE_INFO_SIZE, rc;
237 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
238 const struct burst_info {
241 } rx_offload_map[] = {
242 {NIX_RX_OFFLOAD_RSS_F, "RSS,"},
243 {NIX_RX_OFFLOAD_PTYPE_F, " Ptype,"},
244 {NIX_RX_OFFLOAD_CHECKSUM_F, " Checksum,"},
245 {NIX_RX_OFFLOAD_VLAN_STRIP_F, " VLAN Strip,"},
246 {NIX_RX_OFFLOAD_MARK_UPDATE_F, " Mark Update,"},
247 {NIX_RX_OFFLOAD_TSTAMP_F, " Timestamp,"},
248 {NIX_RX_MULTI_SEG_F, " Scattered,"}
250 static const char *const burst_mode[] = {"Vector Neon, Rx Offloads:",
251 "Scalar, Rx Offloads:"
255 /* Update burst mode info */
256 rc = rte_strscpy(mode->info + bytes, burst_mode[dev->scalar_ena],
263 /* Update Rx offload info */
264 for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
265 if (dev->rx_offload_flags & rx_offload_map[i].flags) {
266 rc = rte_strscpy(mode->info + bytes,
267 rx_offload_map[i].output,
281 otx2_tx_burst_mode_get(struct rte_eth_dev *eth_dev,
282 __rte_unused uint16_t queue_id,
283 struct rte_eth_burst_mode *mode)
285 ssize_t bytes = 0, str_size = RTE_ETH_BURST_MODE_INFO_SIZE, rc;
286 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
287 const struct burst_info {
290 } tx_offload_map[] = {
291 {NIX_TX_OFFLOAD_L3_L4_CSUM_F, " Inner L3/L4 csum,"},
292 {NIX_TX_OFFLOAD_OL3_OL4_CSUM_F, " Outer L3/L4 csum,"},
293 {NIX_TX_OFFLOAD_VLAN_QINQ_F, " VLAN Insertion,"},
294 {NIX_TX_OFFLOAD_MBUF_NOFF_F, " MBUF free disable,"},
295 {NIX_TX_OFFLOAD_TSTAMP_F, " Timestamp,"},
296 {NIX_TX_OFFLOAD_TSO_F, " TSO,"},
297 {NIX_TX_MULTI_SEG_F, " Scattered,"}
299 static const char *const burst_mode[] = {"Vector Neon, Tx Offloads:",
300 "Scalar, Tx Offloads:"
304 /* Update burst mode info */
305 rc = rte_strscpy(mode->info + bytes, burst_mode[dev->scalar_ena],
312 /* Update Tx offload info */
313 for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
314 if (dev->tx_offload_flags & tx_offload_map[i].flags) {
315 rc = rte_strscpy(mode->info + bytes,
316 tx_offload_map[i].output,
330 nix_rx_head_tail_get(struct otx2_eth_dev *dev,
331 uint32_t *head, uint32_t *tail, uint16_t queue_idx)
335 if (head == NULL || tail == NULL)
338 reg = (((uint64_t)queue_idx) << 32);
339 val = otx2_atomic64_add_nosync(reg, (int64_t *)
340 (dev->base + NIX_LF_CQ_OP_STATUS));
341 if (val & (OP_ERR | CQ_ERR))
344 *tail = (uint32_t)(val & 0xFFFFF);
345 *head = (uint32_t)((val >> 20) & 0xFFFFF);
349 otx2_nix_rx_queue_count(struct rte_eth_dev *eth_dev, uint16_t queue_idx)
351 struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[queue_idx];
352 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
355 nix_rx_head_tail_get(dev, &head, &tail, queue_idx);
356 return (tail - head) % rxq->qlen;
360 nix_offset_has_packet(uint32_t head, uint32_t tail, uint16_t offset)
362 /* Check given offset(queue index) has packet filled by HW */
363 if (tail > head && offset <= tail && offset >= head)
365 /* Wrap around case */
366 if (head > tail && (offset >= head || offset <= tail))
373 otx2_nix_rx_descriptor_done(void *rx_queue, uint16_t offset)
375 struct otx2_eth_rxq *rxq = rx_queue;
378 nix_rx_head_tail_get(otx2_eth_pmd_priv(rxq->eth_dev),
379 &head, &tail, rxq->rq);
381 return nix_offset_has_packet(head, tail, offset);
385 otx2_nix_rx_descriptor_status(void *rx_queue, uint16_t offset)
387 struct otx2_eth_rxq *rxq = rx_queue;
390 if (rxq->qlen <= offset)
393 nix_rx_head_tail_get(otx2_eth_pmd_priv(rxq->eth_dev),
394 &head, &tail, rxq->rq);
396 if (nix_offset_has_packet(head, tail, offset))
397 return RTE_ETH_RX_DESC_DONE;
399 return RTE_ETH_RX_DESC_AVAIL;
403 nix_tx_head_tail_get(struct otx2_eth_dev *dev,
404 uint32_t *head, uint32_t *tail, uint16_t queue_idx)
408 if (head == NULL || tail == NULL)
411 reg = (((uint64_t)queue_idx) << 32);
412 val = otx2_atomic64_add_nosync(reg, (int64_t *)
413 (dev->base + NIX_LF_SQ_OP_STATUS));
417 *tail = (uint32_t)((val >> 28) & 0x3F);
418 *head = (uint32_t)((val >> 20) & 0x3F);
422 otx2_nix_tx_descriptor_status(void *tx_queue, uint16_t offset)
424 struct otx2_eth_txq *txq = tx_queue;
427 if (txq->qconf.nb_desc <= offset)
430 nix_tx_head_tail_get(txq->dev, &head, &tail, txq->sq);
432 if (nix_offset_has_packet(head, tail, offset))
433 return RTE_ETH_TX_DESC_DONE;
435 return RTE_ETH_TX_DESC_FULL;
438 /* It is a NOP for octeontx2 as HW frees the buffer on xmit */
440 otx2_nix_tx_done_cleanup(void *txq, uint32_t free_cnt)
443 RTE_SET_USED(free_cnt);
449 otx2_nix_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version,
452 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
453 int rc = (int)fw_size;
455 if (fw_size > sizeof(dev->mkex_pfl_name))
456 rc = sizeof(dev->mkex_pfl_name);
458 rc = strlcpy(fw_version, (char *)dev->mkex_pfl_name, rc);
460 rc += 1; /* Add the size of '\0' */
461 if (fw_size < (uint32_t)rc)
468 otx2_nix_pool_ops_supported(struct rte_eth_dev *eth_dev, const char *pool)
470 RTE_SET_USED(eth_dev);
472 if (!strcmp(pool, rte_mbuf_platform_mempool_ops()))
479 otx2_nix_dev_filter_ctrl(struct rte_eth_dev *eth_dev,
480 enum rte_filter_type filter_type,
481 enum rte_filter_op filter_op, void *arg)
483 RTE_SET_USED(eth_dev);
485 if (filter_type != RTE_ETH_FILTER_GENERIC) {
486 otx2_err("Unsupported filter type %d", filter_type);
490 if (filter_op == RTE_ETH_FILTER_GET) {
491 *(const void **)arg = &otx2_flow_ops;
495 otx2_err("Invalid filter_op %d", filter_op);
499 static struct cgx_fw_data *
500 nix_get_fwdata(struct otx2_eth_dev *dev)
502 struct otx2_mbox *mbox = dev->mbox;
503 struct cgx_fw_data *rsp = NULL;
506 otx2_mbox_alloc_msg_cgx_get_aux_link_info(mbox);
508 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
510 otx2_err("Failed to get fw data: %d", rc);
518 otx2_nix_get_module_info(struct rte_eth_dev *eth_dev,
519 struct rte_eth_dev_module_info *modinfo)
521 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
522 struct cgx_fw_data *rsp;
524 rsp = nix_get_fwdata(dev);
528 modinfo->type = rsp->fwdata.sfp_eeprom.sff_id;
529 modinfo->eeprom_len = SFP_EEPROM_SIZE;
535 otx2_nix_get_module_eeprom(struct rte_eth_dev *eth_dev,
536 struct rte_dev_eeprom_info *info)
538 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
539 struct cgx_fw_data *rsp;
541 if (!info->data || !info->length ||
542 (info->offset + info->length > SFP_EEPROM_SIZE))
545 rsp = nix_get_fwdata(dev);
549 otx2_mbox_memcpy(info->data, rsp->fwdata.sfp_eeprom.buf + info->offset,
556 otx2_nix_info_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *devinfo)
558 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
559 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
561 devinfo->min_rx_bufsize = NIX_MIN_FRS;
562 devinfo->max_rx_pktlen = NIX_MAX_FRS;
563 devinfo->max_rx_queues = RTE_MAX_QUEUES_PER_PORT;
564 devinfo->max_tx_queues = RTE_MAX_QUEUES_PER_PORT;
565 devinfo->max_mac_addrs = dev->max_mac_entries;
566 devinfo->max_vfs = pci_dev->max_vfs;
567 devinfo->max_mtu = devinfo->max_rx_pktlen - NIX_L2_OVERHEAD;
568 devinfo->min_mtu = devinfo->min_rx_bufsize - NIX_L2_OVERHEAD;
570 devinfo->rx_offload_capa = dev->rx_offload_capa;
571 devinfo->tx_offload_capa = dev->tx_offload_capa;
572 devinfo->rx_queue_offload_capa = 0;
573 devinfo->tx_queue_offload_capa = 0;
575 devinfo->reta_size = dev->rss_info.rss_size;
576 devinfo->hash_key_size = NIX_HASH_KEY_SIZE;
577 devinfo->flow_type_rss_offloads = NIX_RSS_OFFLOAD;
579 devinfo->default_rxconf = (struct rte_eth_rxconf) {
584 devinfo->default_txconf = (struct rte_eth_txconf) {
588 devinfo->default_rxportconf = (struct rte_eth_dev_portconf) {
589 .ring_size = NIX_RX_DEFAULT_RING_SZ,
592 devinfo->rx_desc_lim = (struct rte_eth_desc_lim) {
593 .nb_max = UINT16_MAX,
594 .nb_min = NIX_RX_MIN_DESC,
595 .nb_align = NIX_RX_MIN_DESC_ALIGN,
596 .nb_seg_max = NIX_RX_NB_SEG_MAX,
597 .nb_mtu_seg_max = NIX_RX_NB_SEG_MAX,
599 devinfo->rx_desc_lim.nb_max =
600 RTE_ALIGN_MUL_FLOOR(devinfo->rx_desc_lim.nb_max,
601 NIX_RX_MIN_DESC_ALIGN);
603 devinfo->tx_desc_lim = (struct rte_eth_desc_lim) {
604 .nb_max = UINT16_MAX,
607 .nb_seg_max = NIX_TX_NB_SEG_MAX,
608 .nb_mtu_seg_max = NIX_TX_NB_SEG_MAX,
611 /* Auto negotiation disabled */
612 devinfo->speed_capa = ETH_LINK_SPEED_FIXED;
613 devinfo->speed_capa |= ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
614 ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
615 ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G;
617 devinfo->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
618 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;