1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include "otx2_ethdev.h"
8 otx2_nix_rxchan_bpid_cfg(struct rte_eth_dev *eth_dev, bool enb)
10 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
11 struct otx2_fc_info *fc = &dev->fc_info;
12 struct otx2_mbox *mbox = dev->mbox;
13 struct nix_bp_cfg_req *req;
14 struct nix_bp_cfg_rsp *rsp;
18 req = otx2_mbox_alloc_msg_nix_bp_enable(mbox);
21 req->bpid_per_chan = 0;
23 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
24 if (rc || req->chan_cnt != rsp->chan_cnt) {
25 otx2_err("Insufficient BPIDs, alloc=%u < req=%u rc=%d",
26 rsp->chan_cnt, req->chan_cnt, rc);
30 fc->bpid[0] = rsp->chan_bpid[0];
32 req = otx2_mbox_alloc_msg_nix_bp_disable(mbox);
36 rc = otx2_mbox_process(mbox);
38 memset(fc->bpid, 0, sizeof(uint16_t) * NIX_MAX_CHAN);
45 otx2_nix_flow_ctrl_get(struct rte_eth_dev *eth_dev,
46 struct rte_eth_fc_conf *fc_conf)
48 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
49 struct cgx_pause_frm_cfg *req, *rsp;
50 struct otx2_mbox *mbox = dev->mbox;
53 req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(mbox);
56 rc = otx2_mbox_process_msg(mbox, (void *)&rsp);
60 if (rsp->rx_pause && rsp->tx_pause)
61 fc_conf->mode = RTE_FC_FULL;
62 else if (rsp->rx_pause)
63 fc_conf->mode = RTE_FC_RX_PAUSE;
64 else if (rsp->tx_pause)
65 fc_conf->mode = RTE_FC_TX_PAUSE;
67 fc_conf->mode = RTE_FC_NONE;
74 otx2_nix_cq_bp_cfg(struct rte_eth_dev *eth_dev, bool enb)
76 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
77 struct otx2_fc_info *fc = &dev->fc_info;
78 struct otx2_mbox *mbox = dev->mbox;
79 struct nix_aq_enq_req *aq;
80 struct otx2_eth_rxq *rxq;
83 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
84 rxq = eth_dev->data->rx_queues[i];
86 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
88 /* The shared memory buffer can be full.
91 otx2_mbox_msg_send(mbox, 0);
92 rc = otx2_mbox_wait_for_rsp(mbox, 0);
96 aq = otx2_mbox_alloc_msg_nix_aq_enq(mbox);
101 aq->ctype = NIX_AQ_CTYPE_CQ;
102 aq->op = NIX_AQ_INSTOP_WRITE;
105 aq->cq.bpid = fc->bpid[0];
106 aq->cq_mask.bpid = ~(aq->cq_mask.bpid);
107 aq->cq.bp = rxq->cq_drop;
108 aq->cq_mask.bp = ~(aq->cq_mask.bp);
111 aq->cq.bp_ena = !!enb;
112 aq->cq_mask.bp_ena = ~(aq->cq_mask.bp_ena);
115 otx2_mbox_msg_send(mbox, 0);
116 rc = otx2_mbox_wait_for_rsp(mbox, 0);
124 otx2_nix_rx_fc_cfg(struct rte_eth_dev *eth_dev, bool enb)
126 return otx2_nix_cq_bp_cfg(eth_dev, enb);
130 otx2_nix_flow_ctrl_set(struct rte_eth_dev *eth_dev,
131 struct rte_eth_fc_conf *fc_conf)
133 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
134 struct otx2_fc_info *fc = &dev->fc_info;
135 struct otx2_mbox *mbox = dev->mbox;
136 struct cgx_pause_frm_cfg *req;
137 uint8_t tx_pause, rx_pause;
140 if (fc_conf->high_water || fc_conf->low_water || fc_conf->pause_time ||
141 fc_conf->mac_ctrl_frame_fwd || fc_conf->autoneg) {
142 otx2_info("Flowctrl parameter is not supported");
146 if (fc_conf->mode == fc->mode)
149 rx_pause = (fc_conf->mode == RTE_FC_FULL) ||
150 (fc_conf->mode == RTE_FC_RX_PAUSE);
151 tx_pause = (fc_conf->mode == RTE_FC_FULL) ||
152 (fc_conf->mode == RTE_FC_TX_PAUSE);
154 /* Check if TX pause frame is already enabled or not */
155 if (fc->tx_pause ^ tx_pause) {
156 if (otx2_dev_is_Ax(dev) && eth_dev->data->dev_started) {
157 /* on Ax, CQ should be in disabled state
158 * while setting flow control configuration.
160 otx2_info("Stop the port=%d for setting flow control\n",
161 eth_dev->data->port_id);
164 /* TX pause frames, enable/disable flowctrl on RX side. */
165 rc = otx2_nix_rx_fc_cfg(eth_dev, tx_pause);
170 req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(mbox);
172 req->rx_pause = rx_pause;
173 req->tx_pause = tx_pause;
175 rc = otx2_mbox_process(mbox);
179 fc->tx_pause = tx_pause;
180 fc->rx_pause = rx_pause;
181 fc->mode = fc_conf->mode;
187 otx2_nix_update_flow_ctrl_mode(struct rte_eth_dev *eth_dev)
189 struct otx2_eth_dev *dev = otx2_eth_pmd_priv(eth_dev);
190 struct rte_eth_fc_conf fc_conf;
192 memset(&fc_conf, 0, sizeof(struct rte_eth_fc_conf));
193 /* Both Rx & Tx flow ctrl get enabled(RTE_FC_FULL) in HW
194 * by AF driver, update those info in PMD structure.
196 otx2_nix_flow_ctrl_get(eth_dev, &fc_conf);
198 /* To avoid Link credit deadlock on Ax, disable Tx FC if it's enabled */
199 if (otx2_dev_is_Ax(dev) &&
200 (fc_conf.mode == RTE_FC_FULL || fc_conf.mode == RTE_FC_RX_PAUSE)) {
202 (fc_conf.mode == RTE_FC_FULL ||
203 fc_conf.mode == RTE_FC_TX_PAUSE) ?
204 RTE_FC_TX_PAUSE : RTE_FC_NONE;
207 return otx2_nix_flow_ctrl_set(eth_dev, &fc_conf);