X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fcommon%2Focteontx2%2Fotx2_mbox.c;h=2b7810929add1b14205565b3c6ac672a21f5fbf7;hb=4211cc0e922616f9d017504b0db6d3f91b111bcd;hp=86559fa98766090968d40dfe75ba1ec600f68776;hpb=c707a7332daed2f0569b5fb30d282f38af226d2d;p=dpdk.git diff --git a/drivers/common/octeontx2/otx2_mbox.c b/drivers/common/octeontx2/otx2_mbox.c index 86559fa987..2b7810929a 100644 --- a/drivers/common/octeontx2/otx2_mbox.c +++ b/drivers/common/octeontx2/otx2_mbox.c @@ -11,6 +11,7 @@ #include #include "otx2_mbox.h" +#include "otx2_dev.h" #define RVU_AF_AFPF_MBOX0 (0x02000) #define RVU_AF_AFPF_MBOX1 (0x02008) @@ -59,12 +60,13 @@ otx2_mbox_reset(struct otx2_mbox *mbox, int devid) } int -otx2_mbox_init(struct otx2_mbox *mbox, uintptr_t hwbase, - uintptr_t reg_base, int direction, int ndevs) +otx2_mbox_init(struct otx2_mbox *mbox, uintptr_t hwbase, uintptr_t reg_base, + int direction, int ndevs, uint64_t intr_offset) { struct otx2_mbox_dev *mdev; int devid; + mbox->intr_offset = intr_offset; mbox->reg_base = reg_base; mbox->hwbase = hwbase; @@ -244,6 +246,39 @@ otx2_mbox_get_rsp(struct otx2_mbox *mbox, int devid, void **msg) return msghdr->rc; } +/** + * Polling for given wait time to get mailbox response + */ +static int +mbox_poll(struct otx2_mbox *mbox, uint32_t wait) +{ + uint32_t timeout = 0, sleep = 1; + uint32_t wait_us = wait * 1000; + uint64_t rsp_reg = 0; + uintptr_t reg_addr; + + reg_addr = mbox->reg_base + mbox->intr_offset; + do { + rsp_reg = otx2_read64(reg_addr); + + if (timeout >= wait_us) + return -ETIMEDOUT; + + rte_delay_us(sleep); + timeout += sleep; + } while (!rsp_reg); + + rte_smp_rmb(); + + /* Clear interrupt */ + otx2_write64(rsp_reg, reg_addr); + + /* Reset mbox */ + otx2_mbox_reset(mbox, 0); + + return 0; +} + /** * @internal * Wait and get mailbox response with timeout @@ -278,8 +313,9 @@ mbox_wait(struct otx2_mbox *mbox, int devid, uint32_t rst_timo) volatile struct otx2_mbox_dev *mdev = &mbox->dev[devid]; uint32_t timeout = 0, sleep = 1; + rst_timo = rst_timo * 1000; /* Milli seconds to micro seconds */ while (mdev->num_msgs > mdev->msgs_acked) { - rte_delay_ms(sleep); + rte_delay_us(sleep); timeout += sleep; if (timeout >= rst_timo) { struct mbox_hdr *tx_hdr = @@ -321,11 +357,15 @@ otx2_mbox_wait_for_rsp_tmo(struct otx2_mbox *mbox, int devid, uint32_t tmo) } /* Wait message */ - rc = mbox_wait(mbox, devid, tmo); - if (rc) - return rc; + if (rte_thread_is_intr()) + rc = mbox_poll(mbox, tmo); + else + rc = mbox_wait(mbox, devid, tmo); + + if (!rc) + rc = mdev->num_msgs; - return mdev->msgs_acked; + return rc; } /** @@ -364,6 +404,12 @@ otx2_send_ready_msg(struct otx2_mbox *mbox, uint16_t *pcifunc) if (rc) return rc; + if (rsp->hdr.ver != OTX2_MBOX_VERSION) { + otx2_err("Incompatible MBox versions(AF: 0x%04x DPDK: 0x%04x)", + rsp->hdr.ver, OTX2_MBOX_VERSION); + return -EPIPE; + } + if (pcifunc) *pcifunc = rsp->hdr.pcifunc;