From 205b742952828afa26ca00c590cf00cb12939bea Mon Sep 17 00:00:00 2001 From: Ajit Khaparde Date: Fri, 15 May 2020 00:01:51 -0700 Subject: [PATCH] net/bnxt: fix allocation of LED config info 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 Signed-off-by: Kalesh AP Reviewed-by: Somnath Kotur --- drivers/net/bnxt/bnxt.h | 4 ++-- drivers/net/bnxt/bnxt_ethdev.c | 23 +++++++++++++++++++++++ drivers/net/bnxt/bnxt_hwrm.c | 14 +++++++------- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/drivers/net/bnxt/bnxt.h b/drivers/net/bnxt/bnxt.h index bf5b39cd30..f4b39b3458 100644 --- a/drivers/net/bnxt/bnxt.h +++ b/drivers/net/bnxt/bnxt.h @@ -147,6 +147,7 @@ #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; diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c index 2ba9d6bad7..3bd30dfa1b 100644 --- a/drivers/net/bnxt/bnxt_ethdev.c +++ b/drivers/net/bnxt/bnxt_ethdev.c @@ -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; diff --git a/drivers/net/bnxt/bnxt_hwrm.c b/drivers/net/bnxt/bnxt_hwrm.c index d80d67a2d5..1480009340 100644 --- a/drivers/net/bnxt/bnxt_hwrm.c +++ b/drivers/net/bnxt/bnxt_hwrm.c @@ -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; -- 2.20.1