octeontx2-pf: RVU Mailbox fixes
Subsystems (4)
Subbaraya Sundeep
maintainerv2 cover octeontx2-pf: RVU Mailbox fixes
This patchset fixes the problems related to RVU mailbox. During long run tests some times VF commands like setting MTU or toggling interface fails because VF mailbox is timedout waiting for response from PF.
Below are the fixes
Patch 1: There are two types of messages in RVU mailbox namely up and down messages. Down messages are synchronous messages where a PF/VF sends a message to AF and AF replies back with response. UP messages are notifications and are asynchronous like AF sending link events to PF. When VF sends a down message to PF, PF forwards to AF and sends the response from AF back to VF. PF has to forward VF messages since there is no path in hardware for VF to send directly to AF.
There is one mailbox interrupt from AF to PF when raised could mean two scenarios one is where AF sending reply to PF for a down message sent by PF and another one is AF sending up message asynchronously when link changed for that PF. Receiving the up message interrupt while PF is in middle of forwarding down message causes mailbox errors. Fix this by receiver detecting the type of message from the mbox data register set by sender.
Patch 2:
During VF driver remove, VF has to wait until last message is completed and then turn off mailbox interrupts from PF.
Patch 3:
Do not use ordered workqueue for message processing since multiple works are queued simultaneously by all the VFs and PF link UP messages.
Patch 4:
When sending link event to VF by PF check whether VF is really up to receive this message.
Patch 5:
In AF driver, use separate interrupt handlers for the AF-VF interrupt and AF-PF interrupt. Sometimes both interrupts are raised to two CPUs at same time and both CPUs execute same function at same time corrupting the data.
v2 changes:
Added missing mutex unlock in error path in patch 1 Refactored if else logic in patch 1 as suggested by Paolo Abeni
Subbaraya Sundeep (5):
octeontx2: Detect the mbox up or down message via register
octeontx2-pf: Wait till detach_resources msg is complete
octeontx2-pf: Use default max_active works instead of one
octeontx2-pf: Send UP messages to VF only when VF is up.
octeontx2-af: Use separate handlers for interrupts
drivers/net/ethernet/marvell/octeontx2/af/mbox.c | 43 +++++++- drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 6 ++ .../net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c | 17 +-- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 31 ++++-- drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 2 + .../net/ethernet/marvell/octeontx2/af/rvu_cgx.c | 20 ++-- .../ethernet/marvell/octeontx2/nic/otx2_common.c | 2 +- .../ethernet/marvell/octeontx2/nic/otx2_common.h | 2 +- .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 119 ++++++++++++++------- .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 71 +++++++----- 10 files changed, 225 insertions(+), 88 deletions(-)
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH v2 1/5 octeontx2: Detect the mbox up or down message via register
A single line of interrupt is used to receive up notifications and down reply messages from AF to PF (similarly from PF to its VF). PF acts as bridge and forwards VF messages to AF and sends respsones back from AF to VF. When an async event like link event is received by up message when PF is in middle of forwarding VF message then mailbox errors occur because PF state machine is corrupted. Since VF is a separate driver or VF driver can be in a VM it is not possible to serialize from the start of communication at VF. Hence to differentiate between type of messages at PF this patch makes sender to set mbox data register with distinct values for up and down messages. Sender also checks whether previous interrupt is received before triggering current interrupt by waiting for mailbox data register to become zero.
--- drivers/net/ethernet/marvell/octeontx2/af/mbox.c | 43 +++++++- drivers/net/ethernet/marvell/octeontx2/af/mbox.h | 6 ++ .../net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c | 17 ++-- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 14 ++- drivers/net/ethernet/marvell/octeontx2/af/rvu.h | 2 + .../net/ethernet/marvell/octeontx2/af/rvu_cgx.c | 20 ++-- .../ethernet/marvell/octeontx2/nic/otx2_common.h | 2 +- .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 113 ++++++++++++++------- .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 71 ++++++++----- 9 files changed, 205 insertions(+), 83 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/mbox.c +41 -2
@@ -214,11 +214,12 @@ int otx2_mbox_busy_poll_for_rsp(struct otx2_mbox *mbox, int devid) }EXPORT_SYMBOL (otx2_mbox_busy_poll_for_rsp); -void otx2_mbox_msg_send (struct otx2_mbox *mbox,int devid) +static void otx2_mbox_msg_send_data (struct otx2_mbox *mbox,int devid,u64 data) {struct otx2_mbox_dev *mdev = &mbox->dev[devid];struct mbox_hdr *tx_hdr, *rx_hdr;void *hw_mbase = mdev->hwbase; +u64 intr_val; tx_hdr = hw_mbase + mbox->tx_start; rx_hdr = hw_mbase + mbox->rx_start;
@@ -254,14 +255,52 @@ void otx2_mbox_msg_send(struct otx2_mbox *mbox, int devid)spin_unlock (&mdev->mbox_lock); +/* Check if interrupt pending */ + intr_val =readq ((void __iomem *)mbox->reg_base + + (mbox->trigger | (devid << mbox->tr_shift))); + + intr_val |= data;/* The interrupt should be fired after num_msgs is written * to the shared memory */ -writeq (1 , (void __iomem *)mbox->reg_base + +writeq (intr_val, (void __iomem *)mbox->reg_base + (mbox->trigger | (devid << mbox->tr_shift))); } + +void otx2_mbox_msg_send (struct otx2_mbox *mbox,int devid) +{ +otx2_mbox_msg_send_data (mbox, devid,MBOX_DOWN_MSG ); +}EXPORT_SYMBOL (otx2_mbox_msg_send); +void otx2_mbox_msg_send_up (struct otx2_mbox *mbox,int devid) +{ +otx2_mbox_msg_send_data (mbox, devid,MBOX_UP_MSG ); +} +EXPORT_SYMBOL (otx2_mbox_msg_send_up); + +bool otx2_mbox_wait_for_zero (struct otx2_mbox *mbox,int devid) +{ +u64 data; + + data =readq ((void __iomem *)mbox->reg_base + + (mbox->trigger | (devid << mbox->tr_shift))); + +/* If data is non-zero wait for ~1ms and return to caller +* whether data has changed to zero or not after the wait. +*/ +if (!data) +return true; + +usleep_range (950 ,1000 ); + + data =readq ((void __iomem *)mbox->reg_base + + (mbox->trigger | (devid << mbox->tr_shift))); + +return data ==0 ; +} +EXPORT_SYMBOL (otx2_mbox_wait_for_zero); +struct mbox_msghdr *otx2_mbox_alloc_msg_rsp (struct otx2_mbox *mbox,int devid,int size,int size_rsp) {
drivers/net/ethernet/marvell/octeontx2/af/mbox.h +6 -0
@@ -16,6 +16,9 @@#define MBOX_SIZE SZ_64K +#define MBOX_DOWN_MSG 1 +#define MBOX_UP_MSG 2 +/* AF/PF: PF initiated, PF/VF VF initiated */ #define MBOX_DOWN_RX_START 0#define MBOX_DOWN_RX_SIZE (46 * SZ_1K)
@@ -101,6 +104,7 @@ int otx2_mbox_regions_init(struct otx2_mbox *mbox, void __force **hwbase, struct pci_dev *pdev, void __force *reg_base, int direction, int ndevs, unsigned long *bmap);void otx2_mbox_msg_send (struct otx2_mbox *mbox,int devid); +void otx2_mbox_msg_send_up (struct otx2_mbox *mbox,int devid);int otx2_mbox_wait_for_rsp (struct otx2_mbox *mbox,int devid);int otx2_mbox_busy_poll_for_rsp (struct otx2_mbox *mbox,int devid); struct mbox_msghdr *otx2_mbox_alloc_msg_rsp(struct otx2_mbox *mbox, int devid,
@@ -118,6 +122,8 @@ static inline struct mbox_msghdr *otx2_mbox_alloc_msg(struct otx2_mbox *mbox,return otx2_mbox_alloc_msg_rsp (mbox, devid, size,0 ); } +bool otx2_mbox_wait_for_zero (struct otx2_mbox *mbox,int devid); +/* Mailbox message types */ #define MBOX_MSG_MASK 0xFFFF#define MBOX_MSG_INVALID 0xFFFE
drivers/net/ethernet/marvell/octeontx2/af/mcs_rvu_if.c +11 -6
@@ -121,13 +121,17 @@ int mcs_add_intr_wq_entry(struct mcs *mcs, struct mcs_intr_event *event)static int mcs_notify_pfvf (struct mcs_intr_event *event,struct rvu *rvu) {struct mcs_intr_info *req; -int err, pf; +int pf; pf =rvu_get_pf (event->pcifunc); +mutex_lock (&rvu->mbox_lock); + req =otx2_mbox_alloc_msg_mcs_intr_notify (rvu, pf); -if (!req) +if (!req) { +mutex_unlock (&rvu->mbox_lock);return -ENOMEM ; + } req->mcs_id = event->mcs_id; req->intr_mask = event->intr_mask;
@@ -135,10 +139,11 @@ static int mcs_notify_pfvf(struct mcs_intr_event *event, struct rvu *rvu) req->hdr.pcifunc = event->pcifunc; req->lmac_id = event->lmac_id; -otx2_mbox_msg_send (&rvu->afpf_wq_info.mbox_up, pf); - err =otx2_mbox_wait_for_rsp (&rvu->afpf_wq_info.mbox_up, pf); -if (err) -dev_warn (rvu->dev,"MCS notification to pf %d failed\n" , pf); +otx2_mbox_wait_for_zero (&rvu->afpf_wq_info.mbox_up, pf); + +otx2_mbox_msg_send_up (&rvu->afpf_wq_info.mbox_up, pf); + +mutex_unlock (&rvu->mbox_lock);return 0 ; }
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +11 -3
@@ -2119,7 +2119,7 @@ MBOX_MESSAGES } } -static void __rvu_mbox_handler (struct rvu_work *mwork,int type) +static void __rvu_mbox_handler (struct rvu_work *mwork,int type,bool poll) {struct rvu *rvu = mwork->rvu;int offset, err, id, devid;
@@ -2186,6 +2186,9 @@ static void __rvu_mbox_handler(struct rvu_work *mwork, int type) } mw->mbox_wrk[devid].num_msgs =0 ; +if (poll) +otx2_mbox_wait_for_zero (mbox, devid); +/* Send mbox responses to VF/PF */ otx2_mbox_msg_send (mbox, devid); }
@@ -2193,15 +2196,18 @@ static void __rvu_mbox_handler(struct rvu_work *mwork, int type)static inline void rvu_afpf_mbox_handler (struct work_struct *work) { struct rvu_work *mwork = container_of(work, struct rvu_work, work); +struct rvu *rvu = mwork->rvu; -__rvu_mbox_handler (mwork,TYPE_AFPF ); +mutex_lock (&rvu->mbox_lock); +__rvu_mbox_handler (mwork,TYPE_AFPF , true); +mutex_unlock (&rvu->mbox_lock); }static inline void rvu_afvf_mbox_handler (struct work_struct *work) { struct rvu_work *mwork = container_of(work, struct rvu_work, work); -__rvu_mbox_handler (mwork,TYPE_AFVF ); +__rvu_mbox_handler (mwork,TYPE_AFVF , false); }static void __rvu_mbox_up_handler (struct rvu_work *mwork,int type)
@@ -2376,6 +2382,8 @@ static int rvu_mbox_init(struct rvu *rvu, struct mbox_wq_info *mw, } } +mutex_init (&rvu->mbox_lock); + mbox_regions =kcalloc (num,sizeof (void *),GFP_KERNEL );if (!mbox_regions) { err = -ENOMEM ;
drivers/net/ethernet/marvell/octeontx2/af/rvu.h +2 -0
@@ -591,6 +591,8 @@ struct rvu {spinlock_t mcs_intrq_lock;/* CPT interrupt lock */ spinlock_t cpt_intr_lock; + +struct mutex mbox_lock;/* Serialize mbox up and down msgs */ };static inline void rvu_write64 (struct rvu *rvu,u64 block,u64 offset,u64 val)
drivers/net/ethernet/marvell/octeontx2/af/rvu_cgx.c +13 -7
@@ -232,7 +232,7 @@ static void cgx_notify_pfs(struct cgx_link_event *event, struct rvu *rvu)struct cgx_link_user_info *linfo;struct cgx_link_info_msg *msg;unsigned long pfmap; -int err, pfid; +int pfid; linfo = &event->link_uinfo; pfmap =cgxlmac_to_pfmap (rvu, event->cgx_id, event->lmac_id);
@@ -255,16 +255,22 @@ static void cgx_notify_pfs(struct cgx_link_event *event, struct rvu *rvu)continue ; } +mutex_lock (&rvu->mbox_lock); +/* Send mbox message to PF */ msg =otx2_mbox_alloc_msg_cgx_link_event (rvu, pfid); -if (!msg) +if (!msg) { +mutex_unlock (&rvu->mbox_lock);continue ; + } + msg->link_info = *linfo; -otx2_mbox_msg_send (&rvu->afpf_wq_info.mbox_up, pfid); - err =otx2_mbox_wait_for_rsp (&rvu->afpf_wq_info.mbox_up, pfid); -if (err) -dev_warn (rvu->dev,"notification to pf %d failed\n" , - pfid); + +otx2_mbox_wait_for_zero (&rvu->afpf_wq_info.mbox_up, pfid); + +otx2_mbox_msg_send_up (&rvu->afpf_wq_info.mbox_up, pfid); + +mutex_unlock (&rvu->mbox_lock); }while (pfmap); }
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.h +1 -1
@@ -815,7 +815,7 @@ static inline int otx2_sync_mbox_up_msg(struct mbox *mbox, int devid)if (!otx2_mbox_nonempty (&mbox->mbox_up, devid))return 0 ; -otx2_mbox_msg_send (&mbox->mbox_up, devid); +otx2_mbox_msg_send_up (&mbox->mbox_up, devid); err =otx2_mbox_wait_for_rsp (&mbox->mbox_up, devid);if (err)return err;
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +77 -36
236 lines not on this page · raw message
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +43 -28
117 lines not on this page · raw message
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH v2 2/5 octeontx2-pf: Wait till detach_resources msg is complete
In reply to Subbaraya SundeepDuring VF driver remove, a message is sent to detach VF resources to PF but VF is not waiting until message is complete. Also mailbox interrupts need to be turned off after the detach resource message is complete. This patch fixes that problem.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 2 +- drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1 -1
@@ -1592,7 +1592,7 @@ int otx2_detach_resources(struct mbox *mbox) detach->partial = false;/* Send detach request to AF */ -otx2_mbox_msg_send (&mbox->mbox,0 ); +otx2_sync_mbox_msg (mbox);mutex_unlock (&mbox->lock);return 0 ; }
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +1 -1
@@ -775,8 +775,8 @@ static void otx2vf_remove(struct pci_dev *pdev)otx2_mcam_flow_del (vf);otx2_shutdown_tc (vf);otx2_shutdown_qos (vf); -otx2vf_disable_mbox_intr (vf);otx2_detach_resources (&vf->mbox); +otx2vf_disable_mbox_intr (vf);free_percpu (vf->hw.lmt_info);if (test_bit (CN10K_LMTST , &vf->hw.cap_flag))qmem_free (vf->dev, vf->dync_lmt);
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH v2 3/5 octeontx2-pf: Use default max_active works instead of one
In reply to Subbaraya SundeepOnly one execution context for the workqueue used for PF and VFs mailbox communication is incorrect since multiple works are queued simultaneously by all the VFs and PF link UP messages. Hence use default number of execution contexts by passing zero as max_active to alloc_workqueue function. With this fix in place, modify UP messages also to wait until completion.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -3
@@ -584,8 +584,9 @@ static int otx2_pfvf_mbox_init(struct otx2_nic *pf, int numvfs)if (!pf->mbox_pfvf)return -ENOMEM ; - pf->mbox_pfvf_wq =alloc_ordered_workqueue ("otx2_pfvf_mailbox" , -WQ_HIGHPRI |WQ_MEM_RECLAIM ); + pf->mbox_pfvf_wq =alloc_workqueue ("otx2_pfvf_mailbox" , +WQ_UNBOUND |WQ_HIGHPRI | +WQ_MEM_RECLAIM ,0 );if (!pf->mbox_pfvf_wq)return -ENOMEM ;
@@ -3146,7 +3147,7 @@ static void otx2_vf_link_event_task(struct work_struct *work)otx2_mbox_wait_for_zero (&pf->mbox_pfvf[0 ].mbox_up, vf_idx); -otx2_mbox_msg_send_up (&pf->mbox_pfvf[0 ].mbox_up, vf_idx); +otx2_sync_mbox_up_msg (&pf->mbox_pfvf[0 ], vf_idx);mutex_unlock (&pf->mbox.lock); }
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH v2 4/5 octeontx2-pf: Send UP messages to VF only when VF is up.
In reply to Subbaraya SundeepWhen PF sending link status messages to VF, it is possible that by the time link_event_task work function is executed VF might have brought down. Hence before sending VF link status message check whether VF is up to receive it.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +3 -0
@@ -3122,6 +3122,9 @@ static void otx2_vf_link_event_task(struct work_struct *work) vf_idx = config - config->pf->vf_configs; pf = config->pf; +if (config->intf_down) +return ; +mutex_lock (&pf->mbox.lock); dwork = &config->link_event_work;
Signature · 1 line
2.7.4
Subbaraya Sundeep
maintainerPATCH v2 5/5 octeontx2-af: Use separate handlers for interrupts
In reply to Subbaraya SundeepFor PF to AF interrupt vector and VF to AF vector same interrupt handler is registered which is causing race condition. When two interrupts are raised to two CPUs at same time then two cores serve same event corrupting the data.
--- drivers/net/ethernet/marvell/octeontx2/af/rvu.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu.c +14 -3
@@ -2533,10 +2533,9 @@ static void rvu_queue_work(struct mbox_wq_info *mw, int first, } } -static irqreturn_t rvu_mbox_intr_handler (int irq,void *rvu_irq) +static irqreturn_t rvu_mbox_pf_intr_handler (int irq,void *rvu_irq) {struct rvu *rvu = (struct rvu *)rvu_irq; -int vfs = rvu->vfs;u64 intr; intr =rvu_read64 (rvu,BLKADDR_RVUM ,RVU_AF_PFAF_MBOX_INT );
@@ -2550,6 +2549,18 @@ static irqreturn_t rvu_mbox_intr_handler(int irq, void *rvu_irq)rvu_queue_work (&rvu->afpf_wq_info,0 , rvu->hw->total_pfs, intr); +return IRQ_HANDLED ; +} + +static irqreturn_t rvu_mbox_intr_handler (int irq,void *rvu_irq) +{ +struct rvu *rvu = (struct rvu *)rvu_irq; +int vfs = rvu->vfs; +u64 intr; + +/* Sync with mbox memory region */ +rmb (); +/* Handle VF interrupts */ if (vfs >64 ) { intr =rvupf_read64 (rvu,RVU_PF_VFPF_MBOX_INTX (1 ));
@@ -2894,7 +2905,7 @@ static int rvu_register_interrupts(struct rvu *rvu)/* Register mailbox interrupt handler */ sprintf (&rvu->irq_name[RVU_AF_INT_VEC_MBOX *NAME_SIZE ],"RVUAF Mbox" ); ret =request_irq (pci_irq_vector (rvu->pdev,RVU_AF_INT_VEC_MBOX ), - rvu_mbox_intr_handler,0 , + rvu_mbox_pf_intr_handler,0 , &rvu->irq_name[RVU_AF_INT_VEC_MBOX *NAME_SIZE ], rvu);if (ret) { dev_err(rvu->dev,
Signature · 1 line
2.7.4
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 21 lines · On Mon, 18 Mar 2024 14:59:53 +0530 you wrote:
This patchset fixes the problems related to RVU mailbox. During long run tests some times VF commands like setting MTU or toggling interface fails because VF mailbox is timedout waiting for response from PF.
Below are the fixes
Patch 1: There are two types of messages in RVU mailbox namely up and down messages. Down messages are synchronous messages where a PF/VF sends a message to AF and AF replies back with response. UP messages are notifications and are asynchronous like AF sending link events to PF. When VF sends a down message to PF, PF forwards to AF and sends the response from AF back to VF. PF has to forward VF messages since there is no path in hardware for VF to send directly to AF.
There is one mailbox interrupt from AF to PF when raised could mean two scenarios one is where AF sending reply to PF for a down message sent by PF and another one is AF sending up message asynchronously when link changed for that PF. Receiving the up message interrupt while PF is in middle of forwarding down message causes mailbox errors. Fix this by receiver detecting the type of message from the mbox data register set by sender.
Quoted 1 line
[...]
Here is the summary with links:
- [v2,net,1/5] octeontx2: Detect the mbox up or down message via register
https://git.kernel.org/netdev/net/c/a88e0f936ba9 - [v2,net,2/5] octeontx2-pf: Wait till detach_resources msg is complete https://git.kernel.org/netdev/net/c/cbf2f24939a5 - [v2,net,3/5] octeontx2-pf: Use default max_active works instead of one https://git.kernel.org/netdev/net/c/7558ce0d974c - [v2,net,4/5] octeontx2-pf: Send UP messages to VF only when VF is up. https://git.kernel.org/netdev/net/c/dfcf6355f53b - [v2,net,5/5] octeontx2-af: Use separate handlers for interrupts https://git.kernel.org/netdev/net/c/50e60de381c3
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html