Commit a88e0f93 authored by Subbaraya Sundeep's avatar Subbaraya Sundeep Committed by David S. Miller
Browse files

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.

Fixes: 5a6d7c9d ("octeontx2-pf: Mailbox communication with AF")
Signed-off-by: default avatarSubbaraya Sundeep <sbhatta@marvell.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 94e3ca2f
Loading
Loading
Loading
Loading
+41 −2
Original line number Diff line number Diff line
@@ -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)
{
+6 −0
Original line number Diff line number Diff line
@@ -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
+11 −6
Original line number Diff line number Diff line
@@ -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;
}
+11 −3
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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)
Loading