Skip to content

Commit 75f3627

Browse files
Geetha sowjanyadavem330
authored andcommitted
octeontx2-pf: Support to enable/disable pause frames via ethtool
Added mailbox requests to retrieve backpressure IDs from AF and Aura, CQ contexts are configured with these BPIDs. So that when resource levels reach configured thresholds they assert backpressure on the interface which is also mapped to same BPID. Also added support to enable/disable pause frames generation via ethtool. Signed-off-by: Geetha sowjanya <[email protected]> Signed-off-by: Sunil Goutham <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f7e086e commit 75f3627

File tree

4 files changed

+125
-0
lines changed

4 files changed

+125
-0
lines changed

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu)
220220
return err;
221221
}
222222

223+
int otx2_config_pause_frm(struct otx2_nic *pfvf)
224+
{
225+
struct cgx_pause_frm_cfg *req;
226+
int err;
227+
228+
otx2_mbox_lock(&pfvf->mbox);
229+
req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(&pfvf->mbox);
230+
if (!req)
231+
return -ENOMEM;
232+
233+
req->rx_pause = !!(pfvf->flags & OTX2_FLAG_RX_PAUSE_ENABLED);
234+
req->tx_pause = !!(pfvf->flags & OTX2_FLAG_TX_PAUSE_ENABLED);
235+
req->set = 1;
236+
237+
err = otx2_sync_mbox_msg(&pfvf->mbox);
238+
otx2_mbox_unlock(&pfvf->mbox);
239+
return err;
240+
}
241+
223242
int otx2_set_flowkey_cfg(struct otx2_nic *pfvf)
224243
{
225244
struct otx2_rss_info *rss = &pfvf->hw.rss_info;
@@ -580,6 +599,7 @@ void otx2_sqb_flush(struct otx2_nic *pfvf)
580599
* RED accepts pkts if free pointers > 102 & <= 205.
581600
* Drops pkts if free pointers < 102.
582601
*/
602+
#define RQ_BP_LVL_AURA (255 - ((85 * 256) / 100)) /* BP when 85% is full */
583603
#define RQ_PASS_LVL_AURA (255 - ((95 * 256) / 100)) /* RED when 95% is full */
584604
#define RQ_DROP_LVL_AURA (255 - ((99 * 256) / 100)) /* Drop when 99% is full */
585605

@@ -741,6 +761,13 @@ static int otx2_cq_init(struct otx2_nic *pfvf, u16 qidx)
741761
if (qidx < pfvf->hw.rx_queues) {
742762
aq->cq.drop = RQ_DROP_LVL_CQ(pfvf->hw.rq_skid, cq->cqe_cnt);
743763
aq->cq.drop_ena = 1;
764+
765+
/* Enable receive CQ backpressure */
766+
aq->cq.bp_ena = 1;
767+
aq->cq.bpid = pfvf->bpid[0];
768+
769+
/* Set backpressure level is same as cq pass level */
770+
aq->cq.bp = RQ_PASS_LVL_CQ(pfvf->hw.rq_skid, qset->rqe_cnt);
744771
}
745772

746773
/* Fill AQ info */
@@ -996,6 +1023,14 @@ static int otx2_aura_init(struct otx2_nic *pfvf, int aura_id,
9961023
aq->aura.fc_addr = pool->fc_addr->iova;
9971024
aq->aura.fc_hyst_bits = 0; /* Store count on all updates */
9981025

1026+
/* Enable backpressure for RQ aura */
1027+
if (aura_id < pfvf->hw.rqpool_cnt) {
1028+
aq->aura.bp_ena = 0;
1029+
aq->aura.nix0_bpid = pfvf->bpid[0];
1030+
/* Set backpressure level for RQ's Aura */
1031+
aq->aura.bp = RQ_BP_LVL_AURA;
1032+
}
1033+
9991034
/* Fill AQ info */
10001035
aq->ctype = NPA_AQ_CTYPE_AURA;
10011036
aq->op = NPA_AQ_INSTOP_INIT;
@@ -1307,6 +1342,25 @@ void otx2_ctx_disable(struct mbox *mbox, int type, bool npa)
13071342
otx2_mbox_unlock(mbox);
13081343
}
13091344

1345+
int otx2_nix_config_bp(struct otx2_nic *pfvf, bool enable)
1346+
{
1347+
struct nix_bp_cfg_req *req;
1348+
1349+
if (enable)
1350+
req = otx2_mbox_alloc_msg_nix_bp_enable(&pfvf->mbox);
1351+
else
1352+
req = otx2_mbox_alloc_msg_nix_bp_disable(&pfvf->mbox);
1353+
1354+
if (!req)
1355+
return -ENOMEM;
1356+
1357+
req->chan_base = 0;
1358+
req->chan_cnt = 1;
1359+
req->bpid_per_chan = 0;
1360+
1361+
return otx2_sync_mbox_msg(&pfvf->mbox);
1362+
}
1363+
13101364
/* Mbox message handlers */
13111365
void mbox_handler_cgx_stats(struct otx2_nic *pfvf,
13121366
struct cgx_stats_rsp *rsp)
@@ -1355,6 +1409,17 @@ void mbox_handler_msix_offset(struct otx2_nic *pfvf,
13551409
pfvf->hw.nix_msixoff = rsp->nix_msixoff;
13561410
}
13571411

1412+
void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,
1413+
struct nix_bp_cfg_rsp *rsp)
1414+
{
1415+
int chan, chan_id;
1416+
1417+
for (chan = 0; chan < rsp->chan_cnt; chan++) {
1418+
chan_id = ((rsp->chan_bpid[chan] >> 10) & 0x7F);
1419+
pfvf->bpid[chan_id] = rsp->chan_bpid[chan] & 0x3FF;
1420+
}
1421+
}
1422+
13581423
void otx2_free_cints(struct otx2_nic *pfvf, int n)
13591424
{
13601425
struct otx2_qset *qset = &pfvf->qset;

drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ struct otx2_nic {
204204
u16 rbsize; /* Receive buffer size */
205205

206206
#define OTX2_FLAG_INTF_DOWN BIT_ULL(2)
207+
#define OTX2_FLAG_RX_PAUSE_ENABLED BIT_ULL(9)
208+
#define OTX2_FLAG_TX_PAUSE_ENABLED BIT_ULL(10)
207209
u64 flags;
208210

209211
struct otx2_qset qset;
@@ -216,6 +218,7 @@ struct otx2_nic {
216218
struct workqueue_struct *mbox_wq;
217219

218220
u16 pcifunc; /* RVU PF_FUNC */
221+
u16 bpid[NIX_MAX_BPID_CHAN];
219222
struct cgx_link_user_info linfo;
220223

221224
u64 reset_count;
@@ -558,6 +561,7 @@ int otx2_hw_set_mtu(struct otx2_nic *pfvf, int mtu);
558561
void otx2_tx_timeout(struct net_device *netdev, unsigned int txq);
559562
void otx2_get_mac_from_af(struct net_device *netdev);
560563
void otx2_config_irq_coalescing(struct otx2_nic *pfvf, int qidx);
564+
int otx2_config_pause_frm(struct otx2_nic *pfvf);
561565

562566
/* RVU block related APIs */
563567
int otx2_attach_npa_nix(struct otx2_nic *pfvf);
@@ -578,6 +582,7 @@ dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
578582
gfp_t gfp);
579583
int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable);
580584
void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
585+
int otx2_nix_config_bp(struct otx2_nic *pfvf, bool enable);
581586
void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
582587
void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
583588

@@ -598,6 +603,8 @@ void mbox_handler_nix_txsch_alloc(struct otx2_nic *pf,
598603
struct nix_txsch_alloc_rsp *rsp);
599604
void mbox_handler_cgx_stats(struct otx2_nic *pfvf,
600605
struct cgx_stats_rsp *rsp);
606+
void mbox_handler_nix_bp_enable(struct otx2_nic *pfvf,
607+
struct nix_bp_cfg_rsp *rsp);
601608

602609
/* Device stats APIs */
603610
void otx2_get_dev_stats(struct otx2_nic *pfvf);

drivers/net/ethernet/marvell/octeontx2/nic/otx2_ethtool.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,45 @@ static int otx2_set_channels(struct net_device *dev,
253253
return err;
254254
}
255255

256+
static void otx2_get_pauseparam(struct net_device *netdev,
257+
struct ethtool_pauseparam *pause)
258+
{
259+
struct otx2_nic *pfvf = netdev_priv(netdev);
260+
struct cgx_pause_frm_cfg *req, *rsp;
261+
262+
req = otx2_mbox_alloc_msg_cgx_cfg_pause_frm(&pfvf->mbox);
263+
if (!req)
264+
return;
265+
266+
if (!otx2_sync_mbox_msg(&pfvf->mbox)) {
267+
rsp = (struct cgx_pause_frm_cfg *)
268+
otx2_mbox_get_rsp(&pfvf->mbox.mbox, 0, &req->hdr);
269+
pause->rx_pause = rsp->rx_pause;
270+
pause->tx_pause = rsp->tx_pause;
271+
}
272+
}
273+
274+
static int otx2_set_pauseparam(struct net_device *netdev,
275+
struct ethtool_pauseparam *pause)
276+
{
277+
struct otx2_nic *pfvf = netdev_priv(netdev);
278+
279+
if (pause->autoneg)
280+
return -EOPNOTSUPP;
281+
282+
if (pause->rx_pause)
283+
pfvf->flags |= OTX2_FLAG_RX_PAUSE_ENABLED;
284+
else
285+
pfvf->flags &= ~OTX2_FLAG_RX_PAUSE_ENABLED;
286+
287+
if (pause->tx_pause)
288+
pfvf->flags |= OTX2_FLAG_TX_PAUSE_ENABLED;
289+
else
290+
pfvf->flags &= ~OTX2_FLAG_TX_PAUSE_ENABLED;
291+
292+
return otx2_config_pause_frm(pfvf);
293+
}
294+
256295
static void otx2_get_ringparam(struct net_device *netdev,
257296
struct ethtool_ringparam *ring)
258297
{
@@ -654,6 +693,8 @@ static const struct ethtool_ops otx2_ethtool_ops = {
654693
.set_rxfh = otx2_set_rxfh,
655694
.get_msglevel = otx2_get_msglevel,
656695
.set_msglevel = otx2_set_msglevel,
696+
.get_pauseparam = otx2_get_pauseparam,
697+
.set_pauseparam = otx2_set_pauseparam,
657698
};
658699

659700
void otx2_set_ethtool_ops(struct net_device *netdev)

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ static void otx2_process_pfaf_mbox_msg(struct otx2_nic *pf,
148148
mbox_handler_nix_txsch_alloc(pf,
149149
(struct nix_txsch_alloc_rsp *)msg);
150150
break;
151+
case MBOX_MSG_NIX_BP_ENABLE:
152+
mbox_handler_nix_bp_enable(pf, (struct nix_bp_cfg_rsp *)msg);
153+
break;
151154
case MBOX_MSG_CGX_STATS:
152155
mbox_handler_cgx_stats(pf, (struct cgx_stats_rsp *)msg);
153156
break;
@@ -654,6 +657,9 @@ static int otx2_init_hw_resources(struct otx2_nic *pf)
654657
if (err)
655658
goto err_free_npa_lf;
656659

660+
/* Enable backpressure */
661+
otx2_nix_config_bp(pf, true);
662+
657663
/* Init Auras and pools used by NIX RQ, for free buffer ptrs */
658664
err = otx2_rq_aura_pool_init(pf);
659665
if (err) {
@@ -737,6 +743,12 @@ static void otx2_free_hw_resources(struct otx2_nic *pf)
737743
if (err)
738744
dev_err(pf->dev, "RVUPF: Failed to stop/free TX schedulers\n");
739745

746+
otx2_mbox_lock(mbox);
747+
/* Disable backpressure */
748+
if (!(pf->pcifunc & RVU_PFVF_FUNC_MASK))
749+
otx2_nix_config_bp(pf, false);
750+
otx2_mbox_unlock(mbox);
751+
740752
/* Disable RQs */
741753
otx2_ctx_disable(mbox, NIX_AQ_CTYPE_RQ, false);
742754

0 commit comments

Comments
 (0)