From 0bfe758858663611e758a7ade961122da9ee4a7e Mon Sep 17 00:00:00 2001 From: Shijith Thotton Date: Sat, 25 Mar 2017 11:54:21 +0530 Subject: [PATCH] net/liquidio: add API to setup mbox registers Map and initialize mbox registers. Signed-off-by: Shijith Thotton Signed-off-by: Jerin Jacob Signed-off-by: Derek Chickles Signed-off-by: Venkat Koppula Signed-off-by: Srisivasubramanian S Signed-off-by: Mallesham Jatharakonda --- drivers/net/liquidio/base/lio_23xx_vf.c | 61 +++++++++++++++++++++++++ drivers/net/liquidio/lio_ethdev.c | 15 +++++- drivers/net/liquidio/lio_struct.h | 3 ++ 3 files changed, 77 insertions(+), 2 deletions(-) diff --git a/drivers/net/liquidio/base/lio_23xx_vf.c b/drivers/net/liquidio/base/lio_23xx_vf.c index f61f185c45..70faa9bb1e 100644 --- a/drivers/net/liquidio/base/lio_23xx_vf.c +++ b/drivers/net/liquidio/base/lio_23xx_vf.c @@ -38,6 +38,7 @@ #include "lio_logs.h" #include "lio_23xx_vf.h" #include "lio_23xx_reg.h" +#include "lio_mbox.h" static int cn23xx_vf_reset_io_queues(struct lio_device *lio_dev, uint32_t num_queues) @@ -197,6 +198,63 @@ cn23xx_vf_setup_device_regs(struct lio_device *lio_dev) return 0; } +static void +cn23xx_vf_free_mbox(struct lio_device *lio_dev) +{ + PMD_INIT_FUNC_TRACE(); + + rte_free(lio_dev->mbox[0]); + lio_dev->mbox[0] = NULL; + + rte_free(lio_dev->mbox); + lio_dev->mbox = NULL; +} + +static int +cn23xx_vf_setup_mbox(struct lio_device *lio_dev) +{ + struct lio_mbox *mbox; + + PMD_INIT_FUNC_TRACE(); + + if (lio_dev->mbox == NULL) { + lio_dev->mbox = rte_zmalloc(NULL, sizeof(void *), 0); + if (lio_dev->mbox == NULL) + return -ENOMEM; + } + + mbox = rte_zmalloc(NULL, sizeof(struct lio_mbox), 0); + if (mbox == NULL) { + rte_free(lio_dev->mbox); + lio_dev->mbox = NULL; + return -ENOMEM; + } + + rte_spinlock_init(&mbox->lock); + + mbox->lio_dev = lio_dev; + + mbox->q_no = 0; + + mbox->state = LIO_MBOX_STATE_IDLE; + + /* VF mbox interrupt reg */ + mbox->mbox_int_reg = (uint8_t *)lio_dev->hw_addr + + CN23XX_VF_SLI_PKT_MBOX_INT(0); + /* VF reads from SIG0 reg */ + mbox->mbox_read_reg = (uint8_t *)lio_dev->hw_addr + + CN23XX_SLI_PKT_PF_VF_MBOX_SIG(0, 0); + /* VF writes into SIG1 reg */ + mbox->mbox_write_reg = (uint8_t *)lio_dev->hw_addr + + CN23XX_SLI_PKT_PF_VF_MBOX_SIG(0, 1); + + lio_dev->mbox[0] = mbox; + + rte_write64(LIO_PFVFSIG, mbox->mbox_read_reg); + + return 0; +} + int cn23xx_vf_setup_device(struct lio_device *lio_dev) { @@ -221,6 +279,9 @@ cn23xx_vf_setup_device(struct lio_device *lio_dev) if (lio_dev->default_config == NULL) return -1; + lio_dev->fn_list.setup_mbox = cn23xx_vf_setup_mbox; + lio_dev->fn_list.free_mbox = cn23xx_vf_free_mbox; + lio_dev->fn_list.setup_device_regs = cn23xx_vf_setup_device_regs; return 0; diff --git a/drivers/net/liquidio/lio_ethdev.c b/drivers/net/liquidio/lio_ethdev.c index 34b7b54645..5ee1bb51c4 100644 --- a/drivers/net/liquidio/lio_ethdev.c +++ b/drivers/net/liquidio/lio_ethdev.c @@ -86,14 +86,19 @@ lio_first_time_init(struct lio_device *lio_dev, return -1; } + if (lio_dev->fn_list.setup_mbox(lio_dev)) { + lio_dev_err(lio_dev, "Mailbox setup failed\n"); + goto error; + } + if (cn23xx_vf_set_io_queues_off(lio_dev)) { lio_dev_err(lio_dev, "Setting io queues off failed\n"); - return -1; + goto error; } if (lio_dev->fn_list.setup_device_regs(lio_dev)) { lio_dev_err(lio_dev, "Failed to configure device registers\n"); - return -1; + goto error; } dpdk_queues = (int)lio_dev->sriov_info.rings_per_vf; @@ -102,6 +107,12 @@ lio_first_time_init(struct lio_device *lio_dev, lio_dev->max_rx_queues = dpdk_queues; return 0; + +error: + if (lio_dev->mbox[0]) + lio_dev->fn_list.free_mbox(lio_dev); + + return -1; } static int diff --git a/drivers/net/liquidio/lio_struct.h b/drivers/net/liquidio/lio_struct.h index 0af4fe3357..01b57161bf 100644 --- a/drivers/net/liquidio/lio_struct.h +++ b/drivers/net/liquidio/lio_struct.h @@ -45,6 +45,9 @@ struct lio_device; struct lio_fn_list { + int (*setup_mbox)(struct lio_device *); + void (*free_mbox)(struct lio_device *); + int (*setup_device_regs)(struct lio_device *); }; -- 2.20.1