eal/arm64: add pause function
[dpdk.git] / drivers / net / bnxt / bnxt_hwrm.c
index a1aa80e..f45b883 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 };
@@ -226,15 +229,27 @@ int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, struct bnxt_vnic_info *vnic)
        /* FIXME add multicast flag, when multicast adding options is supported
         * by ethtool.
         */
+       if (vnic->flags & BNXT_VNIC_INFO_BCAST)
+               mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST;
+       if (vnic->flags & BNXT_VNIC_INFO_UNTAGGED)
+               mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_VLAN_NONVLAN;
        if (vnic->flags & BNXT_VNIC_INFO_PROMISC)
-               mask = HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
+               mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_PROMISCUOUS;
        if (vnic->flags & BNXT_VNIC_INFO_ALLMULTI)
                mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_ALL_MCAST;
+       if (vnic->flags & BNXT_VNIC_INFO_MCAST)
+               mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
        if (vnic->mc_addr_cnt) {
                mask |= HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_MCAST;
                req.num_mc_entries = rte_cpu_to_le_32(vnic->mc_addr_cnt);
                req.mc_tbl_addr = rte_cpu_to_le_64(vnic->mc_list_dma_addr);
        }
+       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);
+       }
        req.mask = rte_cpu_to_le_32(HWRM_CFA_L2_SET_RX_MASK_INPUT_MASK_BCAST |
                                    mask);
 
@@ -296,6 +311,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);
 
@@ -611,7 +630,7 @@ static int bnxt_hwrm_port_phy_qcfg(struct bnxt *bp,
        HWRM_CHECK_RESULT;
 
        link_info->phy_link_status = resp->link;
-       if (link_info->phy_link_status != HWRM_PORT_PHY_QCFG_OUTPUT_LINK_NO_LINK) {
+       if (link_info->phy_link_status == HWRM_PORT_PHY_QCFG_OUTPUT_LINK_LINK) {
                link_info->link_up = 1;
                link_info->link_speed = rte_le_to_cpu_16(resp->link_speed);
        } else {
@@ -1224,6 +1243,27 @@ 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)
 {
@@ -1261,6 +1301,23 @@ int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,
        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
  */
@@ -1774,7 +1831,7 @@ int bnxt_get_hwrm_link_config(struct bnxt *bp, struct rte_eth_link *link)
                link->link_speed =
                        bnxt_parse_hw_link_speed(link_info->link_speed);
        else
-               link->link_speed = ETH_LINK_SPEED_10M;
+               link->link_speed = ETH_SPEED_NUM_NONE;
        link->link_duplex = bnxt_parse_hw_link_duplex(link_info->duplex);
        link->link_status = link_info->link_up;
        link->link_autoneg = link_info->auto_mode ==
@@ -2018,6 +2075,27 @@ static void reserve_resources_from_vf(struct bnxt *bp,
        bp->max_ring_grps -= rte_le_to_cpu_16(resp->max_hw_ring_grps);
 }
 
+int bnxt_hwrm_func_qcfg_current_vf_vlan(struct bnxt *bp, int vf)
+{
+       struct hwrm_func_qcfg_input req = {0};
+       struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr;
+       int rc;
+
+       /* Check for zero MAC address */
+       HWRM_PREP(req, FUNC_QCFG, -1, resp);
+       req.fid = rte_cpu_to_le_16(bp->pf.vf_info[vf].fid);
+       rc = bnxt_hwrm_send_message(bp, &req, sizeof(req));
+       if (rc) {
+               RTE_LOG(ERR, PMD, "hwrm_func_qcfg 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_qcfg error %d\n", rc);
+               return -1;
+       }
+       return rte_le_to_cpu_16(resp->vlan);
+}
+
 static int update_pf_resource_max(struct bnxt *bp)
 {
        struct hwrm_func_qcfg_input req = {0};
@@ -2168,6 +2246,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)
 {
@@ -2212,6 +2308,33 @@ 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;
+}
+
+void vf_vnic_set_rxmask_cb(struct bnxt_vnic_info *vnic, void *flagp)
+{
+       uint32_t *flag = flagp;
+
+       vnic->flags = *flag;
+}
+
+int bnxt_set_rx_mask_no_vlan(struct bnxt *bp, struct bnxt_vnic_info *vnic)
+{
+       return bnxt_hwrm_cfa_l2_set_rx_mask(bp, vnic, 0, NULL);
+}
+
 int bnxt_hwrm_func_buf_rgtr(struct bnxt *bp)
 {
        int rc = 0;
@@ -2321,6 +2444,42 @@ 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_set_vf_vlan(struct bnxt *bp, int vf)
+{
+       struct hwrm_func_cfg_input req = {0};
+       struct hwrm_func_cfg_output *resp = bp->hwrm_cmd_resp_addr;
+       int rc = 0;
+
+       HWRM_PREP(req, FUNC_CFG, -1, resp);
+       req.flags = rte_cpu_to_le_32(bp->pf.vf_info[vf].func_cfg_flags);
+       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_DFLT_VLAN);
+       req.dflt_vlan = rte_cpu_to_le_16(bp->pf.vf_info[vf].dflt_vlan);
+
+       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)
 {
@@ -2453,3 +2612,254 @@ 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 void bnxt_vnic_count(struct bnxt_vnic_info *vnic, void *cbdata)
+{
+       uint32_t *count = cbdata;
+
+       if (vnic->func_default)
+               *count = *count + 1;
+}
+
+static int bnxt_vnic_count_hwrm_stub(struct bnxt *bp __rte_unused,
+                                    struct bnxt_vnic_info *vnic __rte_unused)
+{
+       return 0;
+}
+
+int bnxt_vf_default_vnic_count(struct bnxt *bp, uint16_t vf)
+{
+       uint32_t count = 0;
+
+       bnxt_hwrm_func_vf_vnic_query_and_config(bp, vf, bnxt_vnic_count,
+           &count, bnxt_vnic_count_hwrm_stub);
+
+       return count;
+}
+
+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;
+}