net/bnxt: support extended HWRM request sizes
[dpdk.git] / drivers / net / bnxt / bnxt_hwrm.c
index 38698e2..45d37f1 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <rte_io.h>
 
-#define HWRM_CMD_TIMEOUT               10000
+#define HWRM_CMD_TIMEOUT               6000000
 #define HWRM_SPEC_CODE_1_8_3           0x10803
 #define HWRM_VERSION_1_9_1             0x10901
 
@@ -85,10 +85,11 @@ static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
        uint16_t mb_trigger_offset = use_kong_mb ?
                GRCPF_REG_KONG_COMM_TRIGGER : GRCPF_REG_CHIMP_COMM_TRIGGER;
 
-       if (bp->flags & BNXT_FLAG_SHORT_CMD) {
+       if (bp->flags & BNXT_FLAG_SHORT_CMD ||
+           msg_len > bp->max_req_len) {
                void *short_cmd_req = bp->hwrm_short_cmd_req_addr;
 
-               memset(short_cmd_req, 0, bp->max_req_len);
+               memset(short_cmd_req, 0, bp->hwrm_max_ext_req_len);
                memcpy(short_cmd_req, req, msg_len);
 
                short_input.req_type = rte_cpu_to_le_16(req->req_type);
@@ -128,14 +129,13 @@ static int bnxt_hwrm_send_message(struct bnxt *bp, void *msg,
        for (i = 0; i < HWRM_CMD_TIMEOUT; i++) {
                /* Sanity check on the resp->resp_len */
                rte_rmb();
-               if (resp->resp_len && resp->resp_len <=
-                               bp->max_resp_len) {
+               if (resp->resp_len && resp->resp_len <= bp->max_resp_len) {
                        /* Last byte of resp contains the valid key */
                        valid = (uint8_t *)resp + resp->resp_len - 1;
                        if (*valid == HWRM_RESP_VALID_KEY)
                                break;
                }
-               rte_delay_us(600);
+               rte_delay_us(1);
        }
 
        if (i >= HWRM_CMD_TIMEOUT) {
@@ -393,11 +393,11 @@ int bnxt_hwrm_set_l2_filter(struct bnxt *bp,
        if (enables &
            HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR)
                memcpy(req.l2_addr, filter->l2_addr,
-                      ETHER_ADDR_LEN);
+                      RTE_ETHER_ADDR_LEN);
        if (enables &
            HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK)
                memcpy(req.l2_addr_mask, filter->l2_addr_mask,
-                      ETHER_ADDR_LEN);
+                      RTE_ETHER_ADDR_LEN);
        if (enables &
            HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN)
                req.l2_ovlan = filter->l2_ovlan;
@@ -571,7 +571,7 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
        }
 
        bp->fw_fid = rte_le_to_cpu_32(resp->fid);
-       memcpy(bp->dflt_mac_addr, &resp->mac_address, ETHER_ADDR_LEN);
+       memcpy(bp->dflt_mac_addr, &resp->mac_address, RTE_ETHER_ADDR_LEN);
        bp->max_rsscos_ctx = rte_le_to_cpu_16(resp->max_rsscos_ctx);
        bp->max_cp_rings = rte_le_to_cpu_16(resp->max_cmpl_rings);
        bp->max_tx_rings = rte_le_to_cpu_16(resp->max_tx_rings);
@@ -591,7 +591,7 @@ static int __bnxt_hwrm_func_qcaps(struct bnxt *bp)
                bp->pf.total_vnics = rte_le_to_cpu_16(resp->max_vnics);
                if (flags & HWRM_FUNC_QCAPS_OUTPUT_FLAGS_PTP_SUPPORTED) {
                        bp->flags |= BNXT_FLAG_PTP_SUPPORTED;
-                       PMD_DRV_LOG(INFO, "PTP SUPPORTED\n");
+                       PMD_DRV_LOG(DEBUG, "PTP SUPPORTED\n");
                        HWRM_UNLOCK();
                        bnxt_hwrm_ptp_qcfg(bp);
                }
@@ -789,7 +789,6 @@ int bnxt_hwrm_ver_get(struct bnxt *bp)
        int rc = 0;
        struct hwrm_ver_get_input req = {.req_type = 0 };
        struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr;
-       uint32_t my_version;
        uint32_t fw_version;
        uint16_t max_resp_len;
        char type[RTE_MEMZONE_NAMESIZE];
@@ -817,10 +816,6 @@ int bnxt_hwrm_ver_get(struct bnxt *bp)
        PMD_DRV_LOG(INFO, "Driver HWRM version: %d.%d.%d\n",
                HWRM_VERSION_MAJOR, HWRM_VERSION_MINOR, HWRM_VERSION_UPDATE);
 
-       my_version = HWRM_VERSION_MAJOR << 16;
-       my_version |= HWRM_VERSION_MINOR << 8;
-       my_version |= HWRM_VERSION_UPDATE;
-
        fw_version = resp->hwrm_intf_maj_8b << 16;
        fw_version |= resp->hwrm_intf_min_8b << 8;
        fw_version |= resp->hwrm_intf_upd_8b;
@@ -832,27 +827,16 @@ int bnxt_hwrm_ver_get(struct bnxt *bp)
                goto error;
        }
 
-       if (my_version != fw_version) {
-               PMD_DRV_LOG(INFO, "BNXT Driver/HWRM API mismatch.\n");
-               if (my_version < fw_version) {
-                       PMD_DRV_LOG(INFO,
-                               "Firmware API version is newer than driver.\n");
-                       PMD_DRV_LOG(INFO,
-                               "The driver may be missing features.\n");
-               } else {
-                       PMD_DRV_LOG(INFO,
-                               "Firmware API version is older than driver.\n");
-                       PMD_DRV_LOG(INFO,
-                               "Not all driver features may be functional.\n");
-               }
-       }
-
        if (bp->max_req_len > resp->max_req_win_len) {
                PMD_DRV_LOG(ERR, "Unsupported request length\n");
                rc = -EINVAL;
        }
        bp->max_req_len = rte_le_to_cpu_16(resp->max_req_win_len);
-       max_resp_len = resp->max_resp_len;
+       bp->hwrm_max_ext_req_len = rte_le_to_cpu_16(resp->max_ext_req_len);
+       if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN)
+               bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN;
+
+       max_resp_len = rte_le_to_cpu_16(resp->max_resp_len);
        dev_caps_cfg = rte_le_to_cpu_32(resp->dev_caps_cfg);
 
        if (bp->max_resp_len != max_resp_len) {
@@ -884,11 +868,22 @@ int bnxt_hwrm_ver_get(struct bnxt *bp)
            (dev_caps_cfg &
             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) {
                PMD_DRV_LOG(DEBUG, "Short command supported\n");
+               bp->flags |= BNXT_FLAG_SHORT_CMD;
+       }
+
+       if (((dev_caps_cfg &
+             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) &&
+            (dev_caps_cfg &
+             HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) ||
+           bp->hwrm_max_ext_req_len > HWRM_MAX_REQ_LEN) {
+               sprintf(type, "bnxt_hwrm_short_%04x:%02x:%02x:%02x",
+                       bp->pdev->addr.domain, bp->pdev->addr.bus,
+                       bp->pdev->addr.devid, bp->pdev->addr.function);
 
                rte_free(bp->hwrm_short_cmd_req_addr);
 
-               bp->hwrm_short_cmd_req_addr = rte_malloc(type,
-                                                       bp->max_req_len, 0);
+               bp->hwrm_short_cmd_req_addr =
+                               rte_malloc(type, bp->hwrm_max_ext_req_len, 0);
                if (bp->hwrm_short_cmd_req_addr == NULL) {
                        rc = -ENOMEM;
                        goto error;
@@ -903,8 +898,6 @@ int bnxt_hwrm_ver_get(struct bnxt *bp)
                        rc = -ENOMEM;
                        goto error;
                }
-
-               bp->flags |= BNXT_FLAG_SHORT_CMD;
        }
        if (dev_caps_cfg &
            HWRM_VER_GET_OUTPUT_DEV_CAPS_CFG_KONG_MB_CHNL_SUPPORTED) {
@@ -1129,7 +1122,7 @@ int bnxt_hwrm_ring_alloc(struct bnxt *bp,
        case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
                req.ring_type = ring_type;
                req.cmpl_ring_id = rte_cpu_to_le_16(cmpl_ring_id);
-               req.stat_ctx_id = rte_cpu_to_le_16(stats_ctx_id);
+               req.stat_ctx_id = rte_cpu_to_le_32(stats_ctx_id);
                if (stats_ctx_id != INVALID_STATS_CTX_ID)
                        enables |=
                        HWRM_RING_ALLOC_INPUT_ENABLES_STAT_CTX_ID_VALID;
@@ -1156,17 +1149,17 @@ int bnxt_hwrm_ring_alloc(struct bnxt *bp,
                if (rc == 0 && resp->error_code)
                        rc = rte_le_to_cpu_16(resp->error_code);
                switch (ring_type) {
-               case HWRM_RING_FREE_INPUT_RING_TYPE_L2_CMPL:
+               case HWRM_RING_ALLOC_INPUT_RING_TYPE_L2_CMPL:
                        PMD_DRV_LOG(ERR,
                                "hwrm_ring_alloc cp failed. rc:%d\n", rc);
                        HWRM_UNLOCK();
                        return rc;
-               case HWRM_RING_FREE_INPUT_RING_TYPE_RX:
+               case HWRM_RING_ALLOC_INPUT_RING_TYPE_RX:
                        PMD_DRV_LOG(ERR,
                                "hwrm_ring_alloc rx failed. rc:%d\n", rc);
                        HWRM_UNLOCK();
                        return rc;
-               case HWRM_RING_FREE_INPUT_RING_TYPE_TX:
+               case HWRM_RING_ALLOC_INPUT_RING_TYPE_TX:
                        PMD_DRV_LOG(ERR,
                                "hwrm_ring_alloc tx failed. rc:%d\n", rc);
                        HWRM_UNLOCK();
@@ -1279,7 +1272,7 @@ int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
 
        HWRM_PREP(req, STAT_CTX_CLR_STATS, BNXT_USE_CHIMP_MB);
 
-       req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
+       req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
 
@@ -1307,7 +1300,7 @@ int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
 
        HWRM_CHECK_RESULT();
 
-       cpr->hw_stats_ctx_id = rte_le_to_cpu_16(resp->stat_ctx_id);
+       cpr->hw_stats_ctx_id = rte_le_to_cpu_32(resp->stat_ctx_id);
 
        HWRM_UNLOCK();
 
@@ -1323,7 +1316,7 @@ int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
 
        HWRM_PREP(req, STAT_CTX_FREE, BNXT_USE_CHIMP_MB);
 
-       req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
+       req.stat_ctx_id = rte_cpu_to_le_32(cpr->hw_stats_ctx_id);
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
 
@@ -1349,8 +1342,8 @@ int bnxt_hwrm_vnic_alloc(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
        vnic->cos_rule = (uint16_t)HWRM_NA_SIGNATURE;
        vnic->lb_rule = (uint16_t)HWRM_NA_SIGNATURE;
-       vnic->mru = bp->eth_dev->data->mtu + ETHER_HDR_LEN +
-                               ETHER_CRC_LEN + VLAN_TAG_SIZE;
+       vnic->mru = bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
+                               RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE;
        HWRM_PREP(req, VNIC_ALLOC, BNXT_USE_CHIMP_MB);
 
        if (vnic->func_default)
@@ -1449,7 +1442,7 @@ int bnxt_hwrm_vnic_cfg(struct bnxt *bp, struct bnxt_vnic_info *vnic)
                ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_LB_RULE;
        if (vnic->cos_rule != 0xffff)
                ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_COS_RULE;
-       if (vnic->rss_rule != 0xffff) {
+       if (vnic->rss_rule != (uint16_t)HWRM_NA_SIGNATURE) {
                ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_MRU;
                ctx_enable_flag |= HWRM_VNIC_CFG_INPUT_ENABLES_RSS_RULE;
        }
@@ -1564,7 +1557,7 @@ int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        struct hwrm_vnic_rss_cos_lb_ctx_free_output *resp =
                                                bp->hwrm_cmd_resp_addr;
 
-       if (vnic->rss_rule == 0xffff) {
+       if (vnic->rss_rule == (uint16_t)HWRM_NA_SIGNATURE) {
                PMD_DRV_LOG(DEBUG, "VNIC RSS Rule %x\n", vnic->rss_rule);
                return rc;
        }
@@ -1577,7 +1570,7 @@ int bnxt_hwrm_vnic_ctx_free(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        HWRM_CHECK_RESULT();
        HWRM_UNLOCK();
 
-       vnic->rss_rule = INVALID_HW_RING_ID;
+       vnic->rss_rule = (uint16_t)HWRM_NA_SIGNATURE;
 
        return rc;
 }
@@ -1627,6 +1620,7 @@ int bnxt_hwrm_vnic_rss_cfg(struct bnxt *bp,
        req.hash_key_tbl_addr =
            rte_cpu_to_le_64(vnic->rss_hash_key_dma_addr);
        req.rss_ctx_idx = rte_cpu_to_le_16(vnic->rss_rule);
+       req.vnic_id = rte_cpu_to_le_16(vnic->fw_vnic_id);
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req), BNXT_USE_CHIMP_MB);
 
@@ -2536,8 +2530,8 @@ static int bnxt_hwrm_pf_func_cfg(struct bnxt *bp, int tx_rings)
                        HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
        req.flags = rte_cpu_to_le_32(bp->pf.func_cfg_flags);
        req.mtu = rte_cpu_to_le_16(BNXT_MAX_MTU);
-       req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
-                                  ETHER_CRC_LEN + VLAN_TAG_SIZE *
+       req.mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
+                                  RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
                                   BNXT_NUM_VLANS);
        req.num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx);
        req.num_stat_ctxs = rte_cpu_to_le_16(bp->max_stat_ctx);
@@ -2574,11 +2568,11 @@ static void populate_vf_func_cfg_req(struct bnxt *bp,
                        HWRM_FUNC_CFG_INPUT_ENABLES_NUM_VNICS |
                        HWRM_FUNC_CFG_INPUT_ENABLES_NUM_HW_RING_GRPS);
 
-       req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
-                                   ETHER_CRC_LEN + VLAN_TAG_SIZE *
+       req->mtu = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
+                                   RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
                                    BNXT_NUM_VLANS);
-       req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + ETHER_HDR_LEN +
-                                   ETHER_CRC_LEN + VLAN_TAG_SIZE *
+       req->mru = rte_cpu_to_le_16(bp->eth_dev->data->mtu + RTE_ETHER_HDR_LEN +
+                                   RTE_ETHER_CRC_LEN + VLAN_TAG_SIZE *
                                    BNXT_NUM_VLANS);
        req->num_rsscos_ctxs = rte_cpu_to_le_16(bp->max_rsscos_ctx /
                                                (num_vfs + 1));
@@ -2598,7 +2592,7 @@ static void add_random_mac_if_needed(struct bnxt *bp,
                                     struct hwrm_func_cfg_input *cfg_req,
                                     int vf)
 {
-       struct ether_addr mac;
+       struct rte_ether_addr mac;
 
        if (bnxt_hwrm_func_qcfg_vf_default_mac(bp, vf, &mac))
                return;
@@ -2606,10 +2600,11 @@ static void add_random_mac_if_needed(struct bnxt *bp,
        if (memcmp(mac.addr_bytes, "\x00\x00\x00\x00\x00", 6) == 0) {
                cfg_req->enables |=
                rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_DFLT_MAC_ADDR);
-               eth_random_addr(cfg_req->dflt_mac_addr);
+               rte_eth_random_addr(cfg_req->dflt_mac_addr);
                bp->pf.vf_info[vf].random_mac = true;
        } else {
-               memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes, ETHER_ADDR_LEN);
+               memcpy(cfg_req->dflt_mac_addr, mac.addr_bytes,
+                       RTE_ETHER_ADDR_LEN);
        }
 }
 
@@ -3132,7 +3127,7 @@ int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
 }
 
 int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
-                                      struct ether_addr *mac)
+                                      struct rte_ether_addr *mac)
 {
        struct hwrm_func_qcfg_input req = {0};
        struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
@@ -3145,7 +3140,7 @@ int bnxt_hwrm_func_qcfg_vf_default_mac(struct bnxt *bp, uint16_t vf,
 
        HWRM_CHECK_RESULT();
 
-       memcpy(mac->addr_bytes, resp->mac_address, ETHER_ADDR_LEN);
+       memcpy(mac->addr_bytes, resp->mac_address, RTE_ETHER_ADDR_LEN);
 
        HWRM_UNLOCK();
 
@@ -3206,7 +3201,6 @@ int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
                stats->q_obytes[idx] = rte_le_to_cpu_64(resp->tx_ucast_bytes);
                stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_mcast_bytes);
                stats->q_obytes[idx] += rte_le_to_cpu_64(resp->tx_bcast_bytes);
-               stats->q_errors[idx] += rte_le_to_cpu_64(resp->tx_err_pkts);
        }
 
 
@@ -3716,11 +3710,11 @@ int bnxt_hwrm_set_em_filter(struct bnxt *bp,
        if (enables &
            HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_SRC_MACADDR)
                memcpy(req.src_macaddr, filter->src_macaddr,
-                      ETHER_ADDR_LEN);
+                      RTE_ETHER_ADDR_LEN);
        if (enables &
            HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_DST_MACADDR)
                memcpy(req.dst_macaddr, filter->dst_macaddr,
-                      ETHER_ADDR_LEN);
+                      RTE_ETHER_ADDR_LEN);
        if (enables &
            HWRM_CFA_EM_FLOW_ALLOC_INPUT_ENABLES_OVLAN_VID)
                req.ovlan_vid = filter->l2_ovlan;
@@ -3819,11 +3813,11 @@ int bnxt_hwrm_set_ntuple_filter(struct bnxt *bp,
        if (enables &
            HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_SRC_MACADDR)
                memcpy(req.src_macaddr, filter->src_macaddr,
-                      ETHER_ADDR_LEN);
+                      RTE_ETHER_ADDR_LEN);
        //if (enables &
            //HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_DST_MACADDR)
                //memcpy(req.dst_macaddr, filter->dst_macaddr,
-                      //ETHER_ADDR_LEN);
+                      //RTE_ETHER_ADDR_LEN);
        if (enables &
            HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_ETHERTYPE)
                req.ethertype = rte_cpu_to_be_16(filter->ethertype);