net/bnxt: fix allocation of LED config info
authorAjit Khaparde <ajit.khaparde@broadcom.com>
Fri, 15 May 2020 07:01:51 +0000 (00:01 -0700)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 18 May 2020 18:35:57 +0000 (20:35 +0200)
Dynamically allocate bnxt_led_cfg.
This helps reduces memory footprint of struct bnxt.

Fixes: bb81e07323bb ("net/bnxt: support LED on/off")
Cc: stable@dpdk.org
Signed-off-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Signed-off-by: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>
Reviewed-by: Somnath Kotur <somnath.kotur@broadcom.com>
drivers/net/bnxt/bnxt.h
drivers/net/bnxt/bnxt_ethdev.c
drivers/net/bnxt/bnxt_hwrm.c

index bf5b39c..f4b39b3 100644 (file)
 #define BNXT_NUM_CMPL_DMA_AGGR_DURING_INT      12
 
 struct bnxt_led_info {
+       uint8_t      num_leds;
        uint8_t      led_id;
        uint8_t      led_type;
        uint8_t      led_group_id;
@@ -686,8 +687,7 @@ struct bnxt {
        uint32_t                fw_ver;
        uint32_t                hwrm_spec_code;
 
-       struct bnxt_led_info    leds[BNXT_MAX_LED];
-       uint8_t                 num_leds;
+       struct bnxt_led_info    *leds;
        struct bnxt_ptp_cfg     *ptp_cfg;
        uint16_t                vf_resv_strategy;
        struct bnxt_ctx_mem_info        *ctx;
index 2ba9d6b..3bd30df 100644 (file)
@@ -191,6 +191,12 @@ static uint16_t  bnxt_rss_hash_tbl_size(const struct bnxt *bp)
        return bnxt_rss_ctxts(bp) * BNXT_RSS_ENTRIES_PER_CTX_THOR;
 }
 
+static void bnxt_free_leds_info(struct bnxt *bp)
+{
+       rte_free(bp->leds);
+       bp->leds = NULL;
+}
+
 static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
 {
        bnxt_free_filter_mem(bp);
@@ -213,6 +219,17 @@ static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
        bp->grp_info = NULL;
 }
 
+static int bnxt_alloc_leds_info(struct bnxt *bp)
+{
+       bp->leds = rte_zmalloc("bnxt_leds",
+                              BNXT_MAX_LED * sizeof(struct bnxt_led_info),
+                              0);
+       if (bp->leds == NULL)
+               return -ENOMEM;
+
+       return 0;
+}
+
 static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
 {
        int rc;
@@ -1216,6 +1233,8 @@ static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
 
        bnxt_uninit_resources(bp, false);
 
+       bnxt_free_leds_info(bp);
+
        eth_dev->dev_ops = NULL;
        eth_dev->rx_pkt_burst = NULL;
        eth_dev->tx_pkt_burst = NULL;
@@ -5359,6 +5378,10 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
                            "Failed to allocate hwrm resource rc: %x\n", rc);
                goto error_free;
        }
+       rc = bnxt_alloc_leds_info(bp);
+       if (rc)
+               goto error_free;
+
        rc = bnxt_init_resources(bp, false);
        if (rc)
                goto error_free;
index d80d67a..1480009 100644 (file)
@@ -3900,17 +3900,17 @@ int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
        if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
                unsigned int i;
 
-               bp->num_leds = resp->num_leds;
+               bp->leds->num_leds = resp->num_leds;
                memcpy(bp->leds, &resp->led0_id,
-                       sizeof(bp->leds[0]) * bp->num_leds);
-               for (i = 0; i < bp->num_leds; i++) {
+                       sizeof(bp->leds[0]) * bp->leds->num_leds);
+               for (i = 0; i < bp->leds->num_leds; i++) {
                        struct bnxt_led_info *led = &bp->leds[i];
 
                        uint16_t caps = led->led_state_caps;
 
                        if (!led->led_group_id ||
                                !BNXT_LED_ALT_BLINK_CAP(caps)) {
-                               bp->num_leds = 0;
+                               bp->leds->num_leds = 0;
                                break;
                        }
                }
@@ -3930,7 +3930,7 @@ int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
        uint16_t duration = 0;
        int rc, i;
 
-       if (!bp->num_leds || BNXT_VF(bp))
+       if (!bp->leds->num_leds || BNXT_VF(bp))
                return -EOPNOTSUPP;
 
        HWRM_PREP(&req, HWRM_PORT_LED_CFG, BNXT_USE_CHIMP_MB);
@@ -3940,9 +3940,9 @@ int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
                duration = rte_cpu_to_le_16(500);
        }
        req.port_id = bp->pf.port_id;
-       req.num_leds = bp->num_leds;
+       req.num_leds = bp->leds->num_leds;
        led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
-       for (i = 0; i < bp->num_leds; i++, led_cfg++) {
+       for (i = 0; i < bp->leds->num_leds; i++, led_cfg++) {
                req.enables |= BNXT_LED_DFLT_ENABLES(i);
                led_cfg->led_id = bp->leds[i].led_id;
                led_cfg->led_state = led_state;