1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include <rte_mbuf_pool_ops.h>
7 #include "otx2_ethdev.h"
10 otx2_nix_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
12 uint32_t buffsz, frame_size = mtu + NIX_L2_OVERHEAD;
13 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
14 struct rte_eth_dev_data *data = eth_dev->data;
15 struct otx2_mbox *mbox = dev->mbox;
16 struct nix_frs_cfg *req;
19 /* Check if MTU is within the allowed range */
20 if (frame_size < NIX_MIN_FRS || frame_size > NIX_MAX_FRS)
23 buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
25 /* Refuse MTU that requires the support of scattered packets
26 * when this feature has not been enabled before.
28 if (data->dev_started && frame_size > buffsz &&
29 !(dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER))
32 /* Check <seg size> * <max_seg> >= max_frame */
33 if ((dev->rx_offloads & DEV_RX_OFFLOAD_SCATTER) &&
34 (frame_size > buffsz * NIX_RX_NB_SEG_MAX))
37 req = otx2_mbox_alloc_msg_nix_set_hw_frs(mbox);
38 req->update_smq = true;
39 /* FRS HW config should exclude FCS but include NPC VTAG insert size */
40 req->maxlen = frame_size - RTE_ETHER_CRC_LEN + NIX_MAX_VTAG_ACT_SIZE;
42 rc = otx2_mbox_process(mbox);
46 /* Now just update Rx MAXLEN */
47 req = otx2_mbox_alloc_msg_nix_set_hw_frs(mbox);
48 req->maxlen = frame_size - RTE_ETHER_CRC_LEN;
50 rc = otx2_mbox_process(mbox);
54 if (frame_size > RTE_ETHER_MAX_LEN)
55 dev->rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
57 dev->rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
59 /* Update max_rx_pkt_len */
60 data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
66 otx2_nix_recalc_mtu(struct rte_eth_dev *eth_dev)
68 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
69 struct rte_eth_dev_data *data = eth_dev->data;
70 struct rte_pktmbuf_pool_private *mbp_priv;
71 struct otx2_eth_rxq *rxq;
76 /* Get rx buffer size */
77 rxq = data->rx_queues[0];
78 mbp_priv = rte_mempool_get_priv(rxq->pool);
79 buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
81 /* Setup scatter mode if needed by jumbo */
82 if (data->dev_conf.rxmode.max_rx_pkt_len > buffsz)
83 dev->rx_offloads |= DEV_RX_OFFLOAD_SCATTER;
85 /* Setup MTU based on max_rx_pkt_len */
86 mtu = data->dev_conf.rxmode.max_rx_pkt_len - NIX_L2_OVERHEAD;
88 rc = otx2_nix_mtu_set(eth_dev, mtu);
90 otx2_err("Failed to set default MTU size %d", rc);
96 nix_cgx_promisc_config(struct rte_eth_dev *eth_dev, int en)
98 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
99 struct otx2_mbox *mbox = dev->mbox;
101 if (otx2_dev_is_vf(dev))
105 otx2_mbox_alloc_msg_cgx_promisc_enable(mbox);
107 otx2_mbox_alloc_msg_cgx_promisc_disable(mbox);
109 otx2_mbox_process(mbox);
113 otx2_nix_promisc_config(struct rte_eth_dev *eth_dev, int en)
115 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
116 struct otx2_mbox *mbox = dev->mbox;
117 struct nix_rx_mode *req;
119 if (otx2_dev_is_vf(dev))
122 req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
125 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
127 otx2_mbox_process(mbox);
128 eth_dev->data->promiscuous = en;
129 otx2_nix_vlan_update_promisc(eth_dev, en);
133 otx2_nix_promisc_enable(struct rte_eth_dev *eth_dev)
135 otx2_nix_promisc_config(eth_dev, 1);
136 nix_cgx_promisc_config(eth_dev, 1);
140 otx2_nix_promisc_disable(struct rte_eth_dev *eth_dev)
142 otx2_nix_promisc_config(eth_dev, 0);
143 nix_cgx_promisc_config(eth_dev, 0);
147 nix_allmulticast_config(struct rte_eth_dev *eth_dev, int en)
149 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
150 struct otx2_mbox *mbox = dev->mbox;
151 struct nix_rx_mode *req;
153 if (otx2_dev_is_vf(dev))
156 req = otx2_mbox_alloc_msg_nix_set_rx_mode(mbox);
159 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_ALLMULTI;
160 else if (eth_dev->data->promiscuous)
161 req->mode = NIX_RX_MODE_UCAST | NIX_RX_MODE_PROMISC;
163 otx2_mbox_process(mbox);
167 otx2_nix_allmulticast_enable(struct rte_eth_dev *eth_dev)
169 nix_allmulticast_config(eth_dev, 1);
173 otx2_nix_allmulticast_disable(struct rte_eth_dev *eth_dev)
175 nix_allmulticast_config(eth_dev, 0);
179 otx2_nix_rxq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
180 struct rte_eth_rxq_info *qinfo)
182 struct otx2_eth_rxq *rxq;
184 rxq = eth_dev->data->rx_queues[queue_id];
186 qinfo->mp = rxq->pool;
187 qinfo->scattered_rx = eth_dev->data->scattered_rx;
188 qinfo->nb_desc = rxq->qconf.nb_desc;
190 qinfo->conf.rx_free_thresh = 0;
191 qinfo->conf.rx_drop_en = 0;
192 qinfo->conf.rx_deferred_start = 0;
193 qinfo->conf.offloads = rxq->offloads;
197 otx2_nix_txq_info_get(struct rte_eth_dev *eth_dev, uint16_t queue_id,
198 struct rte_eth_txq_info *qinfo)
200 struct otx2_eth_txq *txq;
202 txq = eth_dev->data->tx_queues[queue_id];
204 qinfo->nb_desc = txq->qconf.nb_desc;
206 qinfo->conf.tx_thresh.pthresh = 0;
207 qinfo->conf.tx_thresh.hthresh = 0;
208 qinfo->conf.tx_thresh.wthresh = 0;
210 qinfo->conf.tx_free_thresh = 0;
211 qinfo->conf.tx_rs_thresh = 0;
212 qinfo->conf.offloads = txq->offloads;
213 qinfo->conf.tx_deferred_start = 0;
217 nix_rx_head_tail_get(struct otx2_eth_dev *dev,
218 uint32_t *head, uint32_t *tail, uint16_t queue_idx)
222 if (head == NULL || tail == NULL)
225 reg = (((uint64_t)queue_idx) << 32);
226 val = otx2_atomic64_add_nosync(reg, (int64_t *)
227 (dev->base + NIX_LF_CQ_OP_STATUS));
228 if (val & (OP_ERR | CQ_ERR))
231 *tail = (uint32_t)(val & 0xFFFFF);
232 *head = (uint32_t)((val >> 20) & 0xFFFFF);
236 otx2_nix_rx_queue_count(struct rte_eth_dev *eth_dev, uint16_t queue_idx)
238 struct otx2_eth_rxq *rxq = eth_dev->data->rx_queues[queue_idx];
239 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
242 nix_rx_head_tail_get(dev, &head, &tail, queue_idx);
243 return (tail - head) % rxq->qlen;
247 nix_offset_has_packet(uint32_t head, uint32_t tail, uint16_t offset)
249 /* Check given offset(queue index) has packet filled by HW */
250 if (tail > head && offset <= tail && offset >= head)
252 /* Wrap around case */
253 if (head > tail && (offset >= head || offset <= tail))
260 otx2_nix_rx_descriptor_done(void *rx_queue, uint16_t offset)
262 struct otx2_eth_rxq *rxq = rx_queue;
265 nix_rx_head_tail_get(otx2_eth_pmd_priv(rxq->eth_dev),
266 &head, &tail, rxq->rq);
268 return nix_offset_has_packet(head, tail, offset);
272 otx2_nix_rx_descriptor_status(void *rx_queue, uint16_t offset)
274 struct otx2_eth_rxq *rxq = rx_queue;
277 if (rxq->qlen >= offset)
280 nix_rx_head_tail_get(otx2_eth_pmd_priv(rxq->eth_dev),
281 &head, &tail, rxq->rq);
283 if (nix_offset_has_packet(head, tail, offset))
284 return RTE_ETH_RX_DESC_DONE;
286 return RTE_ETH_RX_DESC_AVAIL;
289 /* It is a NOP for octeontx2 as HW frees the buffer on xmit */
291 otx2_nix_tx_done_cleanup(void *txq, uint32_t free_cnt)
294 RTE_SET_USED(free_cnt);
300 otx2_nix_fw_version_get(struct rte_eth_dev *eth_dev, char *fw_version,
303 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
304 int rc = (int)fw_size;
306 if (fw_size > sizeof(dev->mkex_pfl_name))
307 rc = sizeof(dev->mkex_pfl_name);
309 rc = strlcpy(fw_version, (char *)dev->mkex_pfl_name, rc);
311 rc += 1; /* Add the size of '\0' */
312 if (fw_size < (uint32_t)rc)
319 otx2_nix_pool_ops_supported(struct rte_eth_dev *eth_dev, const char *pool)
321 RTE_SET_USED(eth_dev);
323 if (!strcmp(pool, rte_mbuf_platform_mempool_ops()))
330 otx2_nix_dev_filter_ctrl(struct rte_eth_dev *eth_dev,
331 enum rte_filter_type filter_type,
332 enum rte_filter_op filter_op, void *arg)
334 RTE_SET_USED(eth_dev);
336 if (filter_type != RTE_ETH_FILTER_GENERIC) {
337 otx2_err("Unsupported filter type %d", filter_type);
341 if (filter_op == RTE_ETH_FILTER_GET) {
342 *(const void **)arg = &otx2_flow_ops;
346 otx2_err("Invalid filter_op %d", filter_op);
350 static struct cgx_fw_data *
351 nix_get_fwdata(struct otx2_eth_dev *dev)
353 struct otx2_mbox *mbox = dev->mbox;
354 struct cgx_fw_data *rsp = NULL;
357 otx2_mbox_alloc_msg_cgx_get_aux_link_info(mbox);
359 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
361 otx2_err("Failed to get fw data: %d", rc);
369 otx2_nix_get_module_info(struct rte_eth_dev *eth_dev,
370 struct rte_eth_dev_module_info *modinfo)
372 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
373 struct cgx_fw_data *rsp;
375 rsp = nix_get_fwdata(dev);
379 modinfo->type = rsp->fwdata.sfp_eeprom.sff_id;
380 modinfo->eeprom_len = SFP_EEPROM_SIZE;
386 otx2_nix_get_module_eeprom(struct rte_eth_dev *eth_dev,
387 struct rte_dev_eeprom_info *info)
389 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
390 struct cgx_fw_data *rsp;
392 if (!info->data || !info->length ||
393 (info->offset + info->length > SFP_EEPROM_SIZE))
396 rsp = nix_get_fwdata(dev);
400 otx2_mbox_memcpy(info->data, rsp->fwdata.sfp_eeprom.buf + info->offset,
407 otx2_nix_info_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *devinfo)
409 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
410 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
412 devinfo->min_rx_bufsize = NIX_MIN_FRS;
413 devinfo->max_rx_pktlen = NIX_MAX_FRS;
414 devinfo->max_rx_queues = RTE_MAX_QUEUES_PER_PORT;
415 devinfo->max_tx_queues = RTE_MAX_QUEUES_PER_PORT;
416 devinfo->max_mac_addrs = dev->max_mac_entries;
417 devinfo->max_vfs = pci_dev->max_vfs;
418 devinfo->max_mtu = devinfo->max_rx_pktlen - NIX_L2_OVERHEAD;
419 devinfo->min_mtu = devinfo->min_rx_bufsize - NIX_L2_OVERHEAD;
421 devinfo->rx_offload_capa = dev->rx_offload_capa;
422 devinfo->tx_offload_capa = dev->tx_offload_capa;
423 devinfo->rx_queue_offload_capa = 0;
424 devinfo->tx_queue_offload_capa = 0;
426 devinfo->reta_size = dev->rss_info.rss_size;
427 devinfo->hash_key_size = NIX_HASH_KEY_SIZE;
428 devinfo->flow_type_rss_offloads = NIX_RSS_OFFLOAD;
430 devinfo->default_rxconf = (struct rte_eth_rxconf) {
435 devinfo->default_txconf = (struct rte_eth_txconf) {
439 devinfo->default_rxportconf = (struct rte_eth_dev_portconf) {
440 .ring_size = NIX_RX_DEFAULT_RING_SZ,
443 devinfo->rx_desc_lim = (struct rte_eth_desc_lim) {
444 .nb_max = UINT16_MAX,
445 .nb_min = NIX_RX_MIN_DESC,
446 .nb_align = NIX_RX_MIN_DESC_ALIGN,
447 .nb_seg_max = NIX_RX_NB_SEG_MAX,
448 .nb_mtu_seg_max = NIX_RX_NB_SEG_MAX,
450 devinfo->rx_desc_lim.nb_max =
451 RTE_ALIGN_MUL_FLOOR(devinfo->rx_desc_lim.nb_max,
452 NIX_RX_MIN_DESC_ALIGN);
454 devinfo->tx_desc_lim = (struct rte_eth_desc_lim) {
455 .nb_max = UINT16_MAX,
458 .nb_seg_max = NIX_TX_NB_SEG_MAX,
459 .nb_mtu_seg_max = NIX_TX_NB_SEG_MAX,
462 /* Auto negotiation disabled */
463 devinfo->speed_capa = ETH_LINK_SPEED_FIXED;
464 devinfo->speed_capa |= ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
465 ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
466 ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G;
468 devinfo->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
469 RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;