baseband/la12xx: support multiple modems
[dpdk.git] / drivers / baseband / la12xx / bbdev_la12xx.c
index f5c835e..58defa5 100644 (file)
 #include <rte_bbdev_pmd.h>
 
 #include <bbdev_la12xx_pmd_logs.h>
+#include <bbdev_la12xx_ipc.h>
+#include <bbdev_la12xx.h>
 
 #define DRIVER_NAME baseband_la12xx
 
 /*  Initialisation params structure that can be used by LA12xx BBDEV driver */
 struct bbdev_la12xx_params {
        uint8_t queues_num; /*< LA12xx BBDEV queues number */
+       int8_t modem_id; /*< LA12xx modem instance id */
 };
 
 #define LA12XX_MAX_NB_QUEUES_ARG       "max_nb_queues"
+#define LA12XX_VDEV_MODEM_ID_ARG       "modem"
+#define LA12XX_MAX_MODEM 4
 
 static const char * const bbdev_la12xx_valid_params[] = {
        LA12XX_MAX_NB_QUEUES_ARG,
+       LA12XX_VDEV_MODEM_ID_ARG,
 };
 
-/* private data structure */
-struct bbdev_la12xx_private {
-       unsigned int max_nb_queues;  /**< Max number of queues */
-};
 static inline int
 parse_u16_arg(const char *key, const char *value, void *extra_args)
 {
@@ -51,6 +53,28 @@ parse_u16_arg(const char *key, const char *value, void *extra_args)
        return 0;
 }
 
+/* Parse integer from integer argument */
+static int
+parse_integer_arg(const char *key __rte_unused,
+               const char *value, void *extra_args)
+{
+       int i;
+       char *end;
+
+       errno = 0;
+
+       i = strtol(value, &end, 10);
+       if (*end != 0 || errno != 0 || i < 0 || i > LA12XX_MAX_MODEM) {
+               rte_bbdev_log(ERR, "Supported Port IDS are 0 to %d",
+                       LA12XX_MAX_MODEM - 1);
+               return -EINVAL;
+       }
+
+       *((uint32_t *)extra_args) = i;
+
+       return 0;
+}
+
 /* Parse parameters used to create device */
 static int
 parse_bbdev_la12xx_params(struct bbdev_la12xx_params *params,
@@ -72,6 +96,16 @@ parse_bbdev_la12xx_params(struct bbdev_la12xx_params *params,
                if (ret < 0)
                        goto exit;
 
+               ret = rte_kvargs_process(kvlist,
+                                       bbdev_la12xx_valid_params[1],
+                                       &parse_integer_arg,
+                                       &params->modem_id);
+
+               if (params->modem_id >= LA12XX_MAX_MODEM) {
+                       rte_bbdev_log(ERR, "Invalid modem id, must be < %u",
+                                       LA12XX_MAX_MODEM);
+                       goto exit;
+               }
        }
 
 exit:
@@ -83,10 +117,11 @@ exit:
 /* Create device */
 static int
 la12xx_bbdev_create(struct rte_vdev_device *vdev,
-               struct bbdev_la12xx_params *init_params __rte_unused)
+               struct bbdev_la12xx_params *init_params)
 {
        struct rte_bbdev *bbdev;
        const char *name = rte_vdev_device_name(vdev);
+       struct bbdev_la12xx_private *priv;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -102,6 +137,20 @@ la12xx_bbdev_create(struct rte_vdev_device *vdev,
                return -ENOMEM;
        }
 
+       priv = bbdev->data->dev_private;
+       priv->modem_id = init_params->modem_id;
+       /* if modem id is not configured */
+       if (priv->modem_id == -1)
+               priv->modem_id = bbdev->data->dev_id;
+
+       /* Reset Global variables */
+       priv->num_ldpc_enc_queues = 0;
+       priv->num_ldpc_dec_queues = 0;
+       priv->num_valid_queues = 0;
+       priv->max_nb_queues = init_params->queues_num;
+
+       rte_bbdev_log(INFO, "Setting Up %s: DevId=%d, ModemId=%d",
+                               name, bbdev->data->dev_id, priv->modem_id);
        bbdev->dev_ops = NULL;
        bbdev->device = &vdev->device;
        bbdev->data->socket_id = 0;
@@ -121,7 +170,7 @@ static int
 la12xx_bbdev_probe(struct rte_vdev_device *vdev)
 {
        struct bbdev_la12xx_params init_params = {
-               8
+               8, -1,
        };
        const char *name;
        const char *input_args;
@@ -173,5 +222,6 @@ static struct rte_vdev_driver bbdev_la12xx_pmd_drv = {
 
 RTE_PMD_REGISTER_VDEV(DRIVER_NAME, bbdev_la12xx_pmd_drv);
 RTE_PMD_REGISTER_PARAM_STRING(DRIVER_NAME,
-       LA12XX_MAX_NB_QUEUES_ARG"=<int>");
+       LA12XX_MAX_NB_QUEUES_ARG"=<int>"
+       LA12XX_VDEV_MODEM_ID_ARG "=<int> ");
 RTE_LOG_REGISTER_DEFAULT(bbdev_la12xx_logtype, NOTICE);