net/bnxt: support get and clear VF specific stats
[dpdk.git] / drivers / net / bnxt / bnxt_hwrm.c
index 3e595c3..6ea31ca 100644 (file)
@@ -213,7 +213,10 @@ int bnxt_hwrm_cfa_l2_clear_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        return rc;
 }
 
-int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
+int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp,
+                                struct bnxt_vnic_info *vnic,
+                                uint16_t vlan_count,
+                                struct bnxt_vlan_table_entry *vlan_table)
 {
        int rc = 0;
        struct hwrm_cfa_l2_set_rx_mask_input req = {.req_type = 0 };
@@ -237,6 +240,12 @@ int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        }
        req.mask = rte_cpu_to_le_32(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST |
                                    mask);
+       if (vlan_count && vlan_table) {
+               mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLANONLY;
+               req.vlan_tag_tbl_addr = rte_cpu_to_le_16(
+                        rte_mem_virt2phy(vlan_table));
+               req.num_vlan_tags = rte_cpu_to_le_32((uint32_t)vlan_count);
+       }
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
 
@@ -296,6 +305,10 @@ int bnxt_hwrm_set_filter(struct bnxt *bp,
        if (enables &
            HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN_MASK)
                req.l2_ovlan_mask = filter->l2_ovlan_mask;
+       if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_ID)
+               req.src_id = rte_cpu_to_le_32(filter->src_id);
+       if (enables & HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_SRC_TYPE)
+               req.src_type = filter->src_type;
 
        req.enables = rte_cpu_to_le_32(enables);
 
@@ -821,13 +834,12 @@ int bnxt_hwrm_stat_clear(struct bnxt *bp, struct bnxt_cp_ring_info *cpr)
        struct hwrm_stat_ctx_clr_stats_input req = {.req_type = 0 };
        struct hwrm_stat_ctx_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
 
-       HWRM_PREP(req, STAT_CTX_CLR_STATS, -1, resp);
-
        if (cpr->hw_stats_ctx_id == (uint32_t)HWRM_NA_SIGNATURE)
                return rc;
 
+       HWRM_PREP(req, STAT_CTX_CLR_STATS, -1, resp);
+
        req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
-       req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++);
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
 
@@ -845,9 +857,8 @@ int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
 
        HWRM_PREP(req, STAT_CTX_ALLOC, -1, resp);
 
-       req.update_period_ms = rte_cpu_to_le_32(1000);
+       req.update_period_ms = rte_cpu_to_le_32(0);
 
-       req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++);
        req.stats_dma_addr =
            rte_cpu_to_le_64(cpr->hw_stats_map);
 
@@ -870,7 +881,6 @@ int bnxt_hwrm_stat_ctx_free(struct bnxt *bp, struct bnxt_cp_ring_info *cpr,
        HWRM_PREP(req, STAT_CTX_FREE, -1, resp);
 
        req.stat_ctx_id = rte_cpu_to_le_16(cpr->hw_stats_ctx_id);
-       req.seq_id = rte_cpu_to_le_16(bp->hwrm_cmd_seq++);
 
        rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
 
@@ -1227,6 +1237,81 @@ int bnxt_hwrm_func_vf_mac(struct bnxt *bp, uint16_t vf, const uint8_t *mac_addr)
        return rc;
 }
 
+int bnxt_hwrm_func_qstats_tx_drop(struct bnxt *bp, uint16_t fid,
+                                 uint64_t *dropped)
+{
+       int rc = 0;
+       struct hwrm_func_qstats_input req = {.req_type = 0};
+       struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
+
+       HWRM_PREP(req, FUNC_QSTATS, -1, resp);
+
+       req.fid = rte_cpu_to_le_16(fid);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT;
+
+       if (dropped)
+               *dropped = rte_le_to_cpu_64(resp->tx_drop_pkts);
+
+       return rc;
+}
+
+int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
+                         struct rte_eth_stats *stats)
+{
+       int rc = 0;
+       struct hwrm_func_qstats_input req = {.req_type = 0};
+       struct hwrm_func_qstats_output *resp = bp->hwrm_cmd_resp_addr;
+
+       HWRM_PREP(req, FUNC_QSTATS, -1, resp);
+
+       req.fid = rte_cpu_to_le_16(fid);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT;
+
+       stats->ipackets = rte_le_to_cpu_64(resp->rx_ucast_pkts);
+       stats->ipackets += rte_le_to_cpu_64(resp->rx_mcast_pkts);
+       stats->ipackets += rte_le_to_cpu_64(resp->rx_bcast_pkts);
+       stats->ibytes = rte_le_to_cpu_64(resp->rx_ucast_bytes);
+       stats->ibytes += rte_le_to_cpu_64(resp->rx_mcast_bytes);
+       stats->ibytes += rte_le_to_cpu_64(resp->rx_bcast_bytes);
+
+       stats->opackets = rte_le_to_cpu_64(resp->tx_ucast_pkts);
+       stats->opackets += rte_le_to_cpu_64(resp->tx_mcast_pkts);
+       stats->opackets += rte_le_to_cpu_64(resp->tx_bcast_pkts);
+       stats->obytes = rte_le_to_cpu_64(resp->tx_ucast_bytes);
+       stats->obytes += rte_le_to_cpu_64(resp->tx_mcast_bytes);
+       stats->obytes += rte_le_to_cpu_64(resp->tx_bcast_bytes);
+
+       stats->ierrors = rte_le_to_cpu_64(resp->rx_err_pkts);
+       stats->oerrors = rte_le_to_cpu_64(resp->tx_err_pkts);
+
+       stats->imissed = rte_le_to_cpu_64(resp->rx_drop_pkts);
+
+       return rc;
+}
+
+int bnxt_hwrm_func_clr_stats(struct bnxt *bp, uint16_t fid)
+{
+       int rc = 0;
+       struct hwrm_func_clr_stats_input req = {.req_type = 0};
+       struct hwrm_func_clr_stats_output *resp = bp->hwrm_cmd_resp_addr;
+
+       HWRM_PREP(req, FUNC_CLR_STATS, -1, resp);
+
+       req.fid = rte_cpu_to_le_16(fid);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT;
+
+       return rc;
+}
+
 /*
  * HWRM utility functions
  */
@@ -2134,6 +2219,24 @@ error_free:
        return rc;
 }
 
+int bnxt_hwrm_pf_evb_mode(struct bnxt *bp)
+{
+       struct hwrm_func_cfg_input req = {0};
+       struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
+       int rc;
+
+       HWRM_PREP(req, FUNC_CFG, -1, resp);
+
+       req.fid = rte_cpu_to_le_16(0xffff);
+       req.enables = rte_cpu_to_le_32(HWRM_FUNC_CFG_INPUT_ENABLES_EVB_MODE);
+       req.evb_mode = bp->pf.evb_mode;
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT;
+
+       return rc;
+}
+
 int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, uint16_t port,
                                uint8_t tunnel_type)
 {
@@ -2178,6 +2281,21 @@ int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, uint16_t port,
        return rc;
 }
 
+int bnxt_hwrm_func_cfg_vf_set_flags(struct bnxt *bp, uint16_t vf)
+{
+       struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
+       struct hwrm_func_cfg_input req = {0};
+       int rc;
+
+       HWRM_PREP(req, FUNC_CFG, -1, resp);
+       req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
+       req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT;
+
+       return rc;
+}
+
 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
 {
        int rc = 0;
@@ -2287,6 +2405,24 @@ int bnxt_hwrm_set_default_vlan(struct bnxt *bp, int vf, uint8_t is_vf)
        return rc;
 }
 
+int bnxt_hwrm_func_bw_cfg(struct bnxt *bp, uint16_t vf,
+                       uint16_t max_bw, uint16_t enables)
+{
+       struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
+       struct hwrm_func_cfg_input req = {0};
+       int rc;
+
+       HWRM_PREP(req, FUNC_CFG, -1, resp);
+       req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
+       req.enables |= rte_cpu_to_le_32(enables);
+       req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
+       req.max_bw = rte_cpu_to_le_32(max_bw);
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT;
+
+       return rc;
+}
+
 int bnxt_hwrm_reject_fwd_resp(struct bnxt *bp, uint16_t target_id,
                              void *encaped, size_t ec_size)
 {
@@ -2348,6 +2484,42 @@ int bnxt_hwrm_exec_fwd_resp(struct bnxt *bp, uint16_t target_id,
        return rc;
 }
 
+int bnxt_hwrm_ctx_qstats(struct bnxt *bp, uint32_t cid, int idx,
+                        struct rte_eth_stats *stats)
+{
+       int rc = 0;
+       struct hwrm_stat_ctx_query_input req = {.req_type = 0};
+       struct hwrm_stat_ctx_query_output *resp = bp->hwrm_cmd_resp_addr;
+
+       HWRM_PREP(req, STAT_CTX_QUERY, -1, resp);
+
+       req.stat_ctx_id = rte_cpu_to_le_32(cid);
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+
+       HWRM_CHECK_RESULT;
+
+       stats->q_ipackets[idx] = rte_le_to_cpu_64(resp->rx_ucast_pkts);
+       stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_mcast_pkts);
+       stats->q_ipackets[idx] += rte_le_to_cpu_64(resp->rx_bcast_pkts);
+       stats->q_ibytes[idx] = rte_le_to_cpu_64(resp->rx_ucast_bytes);
+       stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_mcast_bytes);
+       stats->q_ibytes[idx] += rte_le_to_cpu_64(resp->rx_bcast_bytes);
+
+       stats->q_opackets[idx] = rte_le_to_cpu_64(resp->tx_ucast_pkts);
+       stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_mcast_pkts);
+       stats->q_opackets[idx] += rte_le_to_cpu_64(resp->tx_bcast_pkts);
+       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->rx_err_pkts);
+       stats->q_errors[idx] += rte_le_to_cpu_64(resp->tx_err_pkts);
+       stats->q_errors[idx] += rte_le_to_cpu_64(resp->rx_drop_pkts);
+
+       return rc;
+}
+
 int bnxt_hwrm_port_qstats(struct bnxt *bp)
 {
        struct hwrm_port_qstats_input req = {0};
@@ -2383,3 +2555,230 @@ int bnxt_hwrm_port_clr_stats(struct bnxt *bp)
        HWRM_CHECK_RESULT;
        return rc;
 }
+
+int bnxt_hwrm_port_led_qcaps(struct bnxt *bp)
+{
+       struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr;
+       struct hwrm_port_led_qcaps_input req = {0};
+       int rc;
+
+       if (BNXT_VF(bp))
+               return 0;
+
+       HWRM_PREP(req, PORT_LED_QCAPS, -1, resp);
+       req.port_id = bp->pf.port_id;
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT;
+
+       if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) {
+               unsigned int i;
+
+               bp->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++) {
+                       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;
+                               break;
+                       }
+               }
+       }
+       return rc;
+}
+
+int bnxt_hwrm_port_led_cfg(struct bnxt *bp, bool led_on)
+{
+       struct hwrm_port_led_cfg_output *resp = bp->hwrm_cmd_resp_addr;
+       struct hwrm_port_led_cfg_input req = {0};
+       struct bnxt_led_cfg *led_cfg;
+       uint8_t led_state = HWRM_PORT_LED_QCFG_OUTPUT_LED0_STATE_DEFAULT;
+       uint16_t duration = 0;
+       int rc, i;
+
+       if (!bp->num_leds || BNXT_VF(bp))
+               return -EOPNOTSUPP;
+
+       HWRM_PREP(req, PORT_LED_CFG, -1, resp);
+       if (led_on) {
+               led_state = HWRM_PORT_LED_CFG_INPUT_LED0_STATE_BLINKALT;
+               duration = rte_cpu_to_le_16(500);
+       }
+       req.port_id = bp->pf.port_id;
+       req.num_leds = bp->num_leds;
+       led_cfg = (struct bnxt_led_cfg *)&req.led0_id;
+       for (i = 0; i < bp->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;
+               led_cfg->led_blink_on = duration;
+               led_cfg->led_blink_off = duration;
+               led_cfg->led_group_id = bp->leds[i].led_group_id;
+       }
+
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT;
+
+       return rc;
+}
+
+static int bnxt_hwrm_func_vf_vnic_query(struct bnxt *bp, uint16_t vf,
+                                       uint16_t *vnic_ids)
+{
+       struct hwrm_func_vf_vnic_ids_query_input req = {0};
+       struct hwrm_func_vf_vnic_ids_query_output *resp =
+                                               bp->hwrm_cmd_resp_addr;
+       int rc;
+
+       /* First query all VNIC ids */
+       HWRM_PREP(req, FUNC_VF_VNIC_IDS_QUERY, -1, resp_vf_vnic_ids);
+
+       req.vf_id = rte_cpu_to_le_16(bp->pf.first_vf_id + vf);
+       req.max_vnic_id_cnt = rte_cpu_to_le_32(bp->pf.total_vnics);
+       req.vnic_id_tbl_addr = rte_cpu_to_le_64(rte_mem_virt2phy(vnic_ids));
+
+       if (req.vnic_id_tbl_addr == 0) {
+               RTE_LOG(ERR, PMD,
+               "unable to map VNIC ID table address to physical memory\n");
+               return -ENOMEM;
+       }
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       if (rc) {
+               RTE_LOG(ERR, PMD, "hwrm_func_vf_vnic_query failed rc:%d\n", rc);
+               return -1;
+       } else if (resp->error_code) {
+               rc = rte_le_to_cpu_16(resp->error_code);
+               RTE_LOG(ERR, PMD, "hwrm_func_vf_vnic_query error %d\n", rc);
+               return -1;
+       }
+
+       return rte_le_to_cpu_32(resp->vnic_id_cnt);
+}
+
+/*
+ * This function queries the VNIC IDs  for a specified VF. It then calls
+ * the vnic_cb to update the necessary field in vnic_info with cbdata.
+ * Then it calls the hwrm_cb function to program this new vnic configuration.
+ */
+int bnxt_hwrm_func_vf_vnic_query_and_config(struct bnxt *bp, uint16_t vf,
+       void (*vnic_cb)(struct bnxt_vnic_info *, void *), void *cbdata,
+       int (*hwrm_cb)(struct bnxt *bp, struct bnxt_vnic_info *vnic))
+{
+       struct bnxt_vnic_info vnic;
+       int rc = 0;
+       int i, num_vnic_ids;
+       uint16_t *vnic_ids;
+       size_t vnic_id_sz;
+       size_t sz;
+
+       /* First query all VNIC ids */
+       vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
+       vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
+                       RTE_CACHE_LINE_SIZE);
+       if (vnic_ids == NULL) {
+               rc = -ENOMEM;
+               return rc;
+       }
+       for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
+               rte_mem_lock_page(((char *)vnic_ids) + sz);
+
+       num_vnic_ids = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
+
+       if (num_vnic_ids < 0)
+               return num_vnic_ids;
+
+       /* Retrieve VNIC, update bd_stall then update */
+
+       for (i = 0; i < num_vnic_ids; i++) {
+               memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
+               vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
+               rc = bnxt_hwrm_vnic_qcfg(bp, &vnic, bp->pf.first_vf_id + vf);
+               if (rc)
+                       break;
+               if (vnic.mru == 4)      /* Indicates unallocated */
+                       continue;
+
+               vnic_cb(&vnic, cbdata);
+
+               rc = hwrm_cb(bp, &vnic);
+               if (rc)
+                       break;
+       }
+
+       rte_free(vnic_ids);
+
+       return rc;
+}
+
+int bnxt_hwrm_func_cfg_vf_set_vlan_anti_spoof(struct bnxt *bp, uint16_t vf,
+                                             bool on)
+{
+       struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
+       struct hwrm_func_cfg_input req = {0};
+       int rc;
+
+       HWRM_PREP(req, FUNC_CFG, -1, resp);
+       req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
+       req.enables |= rte_cpu_to_le_32(
+                       HWRM_FUNC_CFG_INPUT_ENABLES_VLAN_ANTISPOOF_MODE);
+       req.vlan_antispoof_mode = on ?
+               HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_VALIDATE_VLAN :
+               HWRM_FUNC_CFG_INPUT_VLAN_ANTISPOOF_MODE_NOCHECK;
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       HWRM_CHECK_RESULT;
+
+       return rc;
+}
+
+int bnxt_hwrm_func_qcfg_vf_dflt_vnic_id(struct bnxt *bp, int vf)
+{
+       struct bnxt_vnic_info vnic;
+       uint16_t *vnic_ids;
+       size_t vnic_id_sz;
+       int num_vnic_ids, i;
+       size_t sz;
+       int rc;
+
+       vnic_id_sz = bp->pf.total_vnics * sizeof(*vnic_ids);
+       vnic_ids = rte_malloc("bnxt_hwrm_vf_vnic_ids_query", vnic_id_sz,
+                       RTE_CACHE_LINE_SIZE);
+       if (vnic_ids == NULL) {
+               rc = -ENOMEM;
+               return rc;
+       }
+
+       for (sz = 0; sz < vnic_id_sz; sz += getpagesize())
+               rte_mem_lock_page(((char *)vnic_ids) + sz);
+
+       rc = bnxt_hwrm_func_vf_vnic_query(bp, vf, vnic_ids);
+       if (rc <= 0)
+               goto exit;
+       num_vnic_ids = rc;
+
+       /*
+        * Loop through to find the default VNIC ID.
+        * TODO: The easier way would be to obtain the resp->dflt_vnic_id
+        * by sending the hwrm_func_qcfg command to the firmware.
+        */
+       for (i = 0; i < num_vnic_ids; i++) {
+               memset(&vnic, 0, sizeof(struct bnxt_vnic_info));
+               vnic.fw_vnic_id = rte_le_to_cpu_16(vnic_ids[i]);
+               rc = bnxt_hwrm_vnic_qcfg(bp, &vnic,
+                                       bp->pf.first_vf_id + vf);
+               if (rc)
+                       goto exit;
+               if (vnic.func_default) {
+                       rte_free(vnic_ids);
+                       return vnic.fw_vnic_id;
+               }
+       }
+       /* Could not find a default VNIC. */
+       RTE_LOG(ERR, PMD, "No default VNIC\n");
+exit:
+       rte_free(vnic_ids);
+       return -1;
+}