Skip to content

Commit 50fe6c0

Browse files
Linu Cheriandavem330
authored andcommitted
octeontx2-pf: Register and handle link notifications
PF and AF (admin function) shares 64KB of reserved memory region for communication. This region is shared for - Messages sent by PF and responses sent by AF. - Notifications sent by AF and ACKs sent by PF. This patch adds infrastructure to handle notifications sent by AF and adds handlers to process them. One of the main usecase of notifications from AF is physical link changes. So this patch adds registration of PF with AF to receive link status change notifications and also adds the handler for that notification. Signed-off-by: Linu Cherian <[email protected]> Signed-off-by: Tomasz Duszynski <[email protected]> Signed-off-by: Sunil Goutham <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 3ca6c4c commit 50fe6c0

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ struct otx2_nic {
135135
void *iommu_domain;
136136
u16 rbsize; /* Receive buffer size */
137137

138+
#define OTX2_FLAG_INTF_DOWN BIT_ULL(2)
139+
u64 flags;
140+
138141
struct otx2_qset qset;
139142
struct otx2_hw hw;
140143
struct pci_dev *pdev;
@@ -145,6 +148,7 @@ struct otx2_nic {
145148
struct workqueue_struct *mbox_wq;
146149

147150
u16 pcifunc; /* RVU PF_FUNC */
151+
struct cgx_link_user_info linfo;
148152

149153
/* Block address of NIX either BLKADDR_NIX0 or BLKADDR_NIX1 */
150154
int nix_blkaddr;
@@ -485,6 +489,7 @@ int otx2_txschq_stop(struct otx2_nic *pfvf);
485489
void otx2_sqb_flush(struct otx2_nic *pfvf);
486490
dma_addr_t otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool,
487491
gfp_t gfp);
492+
int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable);
488493
void otx2_ctx_disable(struct mbox *mbox, int type, bool npa);
489494
void otx2_cleanup_rx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);
490495
void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq);

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

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,38 @@ static void otx2_pfaf_mbox_handler(struct work_struct *work)
167167
otx2_mbox_reset(mbox, 0);
168168
}
169169

170+
static void otx2_handle_link_event(struct otx2_nic *pf)
171+
{
172+
struct cgx_link_user_info *linfo = &pf->linfo;
173+
struct net_device *netdev = pf->netdev;
174+
175+
pr_info("%s NIC Link is %s %d Mbps %s duplex\n", netdev->name,
176+
linfo->link_up ? "UP" : "DOWN", linfo->speed,
177+
linfo->full_duplex ? "Full" : "Half");
178+
if (linfo->link_up) {
179+
netif_carrier_on(netdev);
180+
netif_tx_start_all_queues(netdev);
181+
} else {
182+
netif_tx_stop_all_queues(netdev);
183+
netif_carrier_off(netdev);
184+
}
185+
}
186+
187+
int otx2_mbox_up_handler_cgx_link_event(struct otx2_nic *pf,
188+
struct cgx_link_info_msg *msg,
189+
struct msg_rsp *rsp)
190+
{
191+
/* Copy the link info sent by AF */
192+
pf->linfo = msg->link_info;
193+
194+
/* interface has not been fully configured yet */
195+
if (pf->flags & OTX2_FLAG_INTF_DOWN)
196+
return 0;
197+
198+
otx2_handle_link_event(pf);
199+
return 0;
200+
}
201+
170202
static int otx2_process_mbox_msg_up(struct otx2_nic *pf,
171203
struct mbox_msghdr *req)
172204
{
@@ -367,6 +399,27 @@ static int otx2_pfaf_mbox_init(struct otx2_nic *pf)
367399
return err;
368400
}
369401

402+
static int otx2_cgx_config_linkevents(struct otx2_nic *pf, bool enable)
403+
{
404+
struct msg_req *msg;
405+
int err;
406+
407+
otx2_mbox_lock(&pf->mbox);
408+
if (enable)
409+
msg = otx2_mbox_alloc_msg_cgx_start_linkevents(&pf->mbox);
410+
else
411+
msg = otx2_mbox_alloc_msg_cgx_stop_linkevents(&pf->mbox);
412+
413+
if (!msg) {
414+
otx2_mbox_unlock(&pf->mbox);
415+
return -ENOMEM;
416+
}
417+
418+
err = otx2_sync_mbox_msg(&pf->mbox);
419+
otx2_mbox_unlock(&pf->mbox);
420+
return err;
421+
}
422+
370423
static int otx2_set_real_num_queues(struct net_device *netdev,
371424
int tx_queues, int rx_queues)
372425
{
@@ -690,6 +743,18 @@ static int otx2_open(struct net_device *netdev)
690743

691744
otx2_set_cints_affinity(pf);
692745

746+
pf->flags &= ~OTX2_FLAG_INTF_DOWN;
747+
/* 'intf_down' may be checked on any cpu */
748+
smp_wmb();
749+
750+
/* we have already received link status notification */
751+
if (pf->linfo.link_up && !(pf->pcifunc & RVU_PFVF_FUNC_MASK))
752+
otx2_handle_link_event(pf);
753+
754+
err = otx2_rxtx_enable(pf, true);
755+
if (err)
756+
goto err_free_cints;
757+
693758
return 0;
694759

695760
err_free_cints:
@@ -713,6 +778,13 @@ static int otx2_stop(struct net_device *netdev)
713778
netif_carrier_off(netdev);
714779
netif_tx_stop_all_queues(netdev);
715780

781+
pf->flags |= OTX2_FLAG_INTF_DOWN;
782+
/* 'intf_down' may be checked on any cpu */
783+
smp_wmb();
784+
785+
/* First stop packet Rx/Tx */
786+
otx2_rxtx_enable(pf, false);
787+
716788
/* Cleanup CQ NAPI and IRQ */
717789
vec = pf->hw.nix_msixoff + NIX_LF_CINT_VEC_START;
718790
for (qidx = 0; qidx < pf->hw.cint_cnt; qidx++) {
@@ -867,6 +939,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
867939
pf->netdev = netdev;
868940
pf->pdev = pdev;
869941
pf->dev = dev;
942+
pf->flags |= OTX2_FLAG_INTF_DOWN;
870943

871944
hw = &pf->hw;
872945
hw->pdev = pdev;
@@ -959,6 +1032,9 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
9591032
goto err_detach_rsrc;
9601033
}
9611034

1035+
/* Enable link notifications */
1036+
otx2_cgx_config_linkevents(pf, true);
1037+
9621038
return 0;
9631039

9641040
err_detach_rsrc:
@@ -987,6 +1063,9 @@ static void otx2_remove(struct pci_dev *pdev)
9871063

9881064
pf = netdev_priv(netdev);
9891065

1066+
/* Disable link notifications */
1067+
otx2_cgx_config_linkevents(pf, false);
1068+
9901069
unregister_netdev(netdev);
9911070
otx2_detach_resources(&pf->mbox);
9921071
otx2_disable_mbox_intr(pf);

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@ int otx2_napi_handler(struct napi_struct *napi, int budget)
315315
otx2_write64(pfvf, NIX_LF_CINTX_INT(cq_poll->cint_idx), BIT_ULL(0));
316316

317317
if (workdone < budget && napi_complete_done(napi, workdone)) {
318+
/* If interface is going down, don't re-enable IRQ */
319+
if (pfvf->flags & OTX2_FLAG_INTF_DOWN)
320+
return workdone;
321+
318322
/* Re-enable interrupts */
319323
otx2_write64(pfvf, NIX_LF_CINTX_ENA_W1S(cq_poll->cint_idx),
320324
BIT_ULL(0));
@@ -531,3 +535,24 @@ void otx2_cleanup_tx_cqes(struct otx2_nic *pfvf, struct otx2_cq_queue *cq)
531535
otx2_write64(pfvf, NIX_LF_CQ_OP_DOOR,
532536
((u64)cq->cq_idx << 32) | processed_cqe);
533537
}
538+
539+
int otx2_rxtx_enable(struct otx2_nic *pfvf, bool enable)
540+
{
541+
struct msg_req *msg;
542+
int err;
543+
544+
otx2_mbox_lock(&pfvf->mbox);
545+
if (enable)
546+
msg = otx2_mbox_alloc_msg_nix_lf_start_rx(&pfvf->mbox);
547+
else
548+
msg = otx2_mbox_alloc_msg_nix_lf_stop_rx(&pfvf->mbox);
549+
550+
if (!msg) {
551+
otx2_mbox_unlock(&pfvf->mbox);
552+
return -ENOMEM;
553+
}
554+
555+
err = otx2_sync_mbox_msg(&pfvf->mbox);
556+
otx2_mbox_unlock(&pfvf->mbox);
557+
return err;
558+
}

0 commit comments

Comments
 (0)