New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / qede / base / ecore_l2.c
index e3afc8a..8b9817e 100644 (file)
@@ -1,9 +1,7 @@
-/*
- * Copyright (c) 2016 QLogic Corporation.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2016 - 2018 Cavium Inc.
  * All rights reserved.
- * www.qlogic.com
- *
- * See LICENSE.qede_pmd for copyright and licensing details.
+ * www.cavium.com
  */
 
 #include "bcm_osal.h"
@@ -77,7 +75,8 @@ enum _ecore_status_t ecore_l2_alloc(struct ecore_hwfn *p_hwfn)
        }
 
 #ifdef CONFIG_ECORE_LOCK_ALLOC
-       OSAL_MUTEX_ALLOC(p_hwfn, &p_l2_info->lock);
+       if (OSAL_MUTEX_ALLOC(p_hwfn, &p_l2_info->lock))
+               return ECORE_NOMEM;
 #endif
 
        return ECORE_SUCCESS;
@@ -110,6 +109,7 @@ void ecore_l2_free(struct ecore_hwfn *p_hwfn)
                        break;
                OSAL_VFREE(p_hwfn->p_dev,
                           p_hwfn->p_l2_info->pp_qid_usage[i]);
+               p_hwfn->p_l2_info->pp_qid_usage[i] = OSAL_NULL;
        }
 
 #ifdef CONFIG_ECORE_LOCK_ALLOC
@@ -119,6 +119,7 @@ void ecore_l2_free(struct ecore_hwfn *p_hwfn)
 #endif
 
        OSAL_VFREE(p_hwfn->p_dev, p_hwfn->p_l2_info->pp_qid_usage);
+       p_hwfn->p_l2_info->pp_qid_usage = OSAL_NULL;
 
 out_l2_info:
        OSAL_VFREE(p_hwfn->p_dev, p_hwfn->p_l2_info);
@@ -607,6 +608,9 @@ ecore_sp_update_accept_mode(struct ecore_hwfn *p_hwfn,
                SET_FIELD(state, ETH_VPORT_RX_MODE_BCAST_ACCEPT_ALL,
                          !!(accept_filter & ECORE_ACCEPT_BCAST));
 
+               SET_FIELD(state, ETH_VPORT_RX_MODE_ACCEPT_ANY_VNI,
+                         !!(accept_filter & ECORE_ACCEPT_ANY_VNI));
+
                p_ramrod->rx_mode.state = OSAL_CPU_TO_LE16(state);
                DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
                           "vport[%02x] p_ramrod->rx_mode.state = 0x%x\n",
@@ -687,7 +691,7 @@ ecore_sp_update_mcast_bin(struct vport_update_ramrod_data *p_ramrod,
 
        p_ramrod->common.update_approx_mcast_flg = 1;
        for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
-               u32 *p_bins = (u32 *)p_params->bins;
+               u32 *p_bins = p_params->bins;
 
                p_ramrod->approx_mcast.bins[i] = OSAL_CPU_TO_LE32(p_bins[i]);
        }
@@ -782,6 +786,11 @@ ecore_sp_vport_update(struct ecore_hwfn *p_hwfn,
                return rc;
        }
 
+       if (p_params->update_ctl_frame_check) {
+               p_cmn->ctl_frame_mac_check_en = p_params->mac_chk_en;
+               p_cmn->ctl_frame_ethtype_check_en = p_params->ethtype_chk_en;
+       }
+
        /* Update mcast bins for VFs, PF doesn't use this functionality */
        ecore_sp_update_mcast_bin(p_ramrod, p_params);
 
@@ -1185,11 +1194,20 @@ ecore_eth_pf_tx_queue_start(struct ecore_hwfn *p_hwfn,
                            void OSAL_IOMEM * *pp_doorbell)
 {
        enum _ecore_status_t rc;
+       u16 pq_id;
+
+       /* TODO - set tc in the pq_params for multi-cos.
+        * If pacing is enabled then select queue according to
+        * rate limiter availability otherwise select queue based
+        * on multi cos.
+        */
+       if (IS_ECORE_PACING(p_hwfn))
+               pq_id = ecore_get_cm_pq_idx_rl(p_hwfn, p_cid->rel.queue_id);
+       else
+               pq_id = ecore_get_cm_pq_idx_mcos(p_hwfn, tc);
 
-       /* TODO - set tc in the pq_params for multi-cos */
-       rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid,
-                                       pbl_addr, pbl_size,
-                                       ecore_get_cm_pq_idx_mcos(p_hwfn, tc));
+       rc = ecore_eth_txq_start_ramrod(p_hwfn, p_cid, pbl_addr,
+                                       pbl_size, pq_id);
        if (rc != ECORE_SUCCESS)
                return rc;
 
@@ -1556,8 +1574,8 @@ ecore_sp_eth_filter_mcast(struct ecore_hwfn *p_hwfn,
                          enum spq_mode comp_mode,
                          struct ecore_spq_comp_cb *p_comp_data)
 {
-       unsigned long bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
        struct vport_update_ramrod_data *p_ramrod = OSAL_NULL;
+       u32 bins[ETH_MULTICAST_MAC_BINS_IN_REGS];
        struct ecore_spq_entry *p_ent = OSAL_NULL;
        struct ecore_sp_init_data init_data;
        u8 abs_vport_id = 0;
@@ -1596,8 +1614,7 @@ ecore_sp_eth_filter_mcast(struct ecore_hwfn *p_hwfn,
        /* explicitly clear out the entire vector */
        OSAL_MEMSET(&p_ramrod->approx_mcast.bins,
                    0, sizeof(p_ramrod->approx_mcast.bins));
-       OSAL_MEMSET(bins, 0, sizeof(unsigned long) *
-                   ETH_MULTICAST_MAC_BINS_IN_REGS);
+       OSAL_MEMSET(bins, 0, sizeof(u32) * ETH_MULTICAST_MAC_BINS_IN_REGS);
        /* filter ADD op is explicit set op and it removes
        *  any existing filters for the vport.
        */
@@ -1606,16 +1623,15 @@ ecore_sp_eth_filter_mcast(struct ecore_hwfn *p_hwfn,
                        u32 bit;
 
                        bit = ecore_mcast_bin_from_mac(p_filter_cmd->mac[i]);
-                       OSAL_SET_BIT(bit, bins);
+                       bins[bit / 32] |= 1 << (bit % 32);
                }
 
                /* Convert to correct endianity */
                for (i = 0; i < ETH_MULTICAST_MAC_BINS_IN_REGS; i++) {
                        struct vport_update_ramrod_mcast *p_ramrod_bins;
-                       u32 *p_bins = (u32 *)bins;
 
                        p_ramrod_bins = &p_ramrod->approx_mcast;
-                       p_ramrod_bins->bins[i] = OSAL_CPU_TO_LE32(p_bins[i]);
+                       p_ramrod_bins->bins[i] = OSAL_CPU_TO_LE32(bins[i]);
                }
        }
 
@@ -1945,6 +1961,11 @@ static void __ecore_get_vport_port_stats(struct ecore_hwfn *p_hwfn,
                p_ah->tx_1519_to_max_byte_packets =
                        port_stats.eth.u1.ah1.t1519_to_max;
        }
+
+       p_common->link_change_count = ecore_rd(p_hwfn, p_ptt,
+                                              p_hwfn->mcp_info->port_addr +
+                                              OFFSETOF(struct public_port,
+                                                       link_change_count));
 }
 
 void __ecore_get_vport_stats(struct ecore_hwfn *p_hwfn,
@@ -2061,11 +2082,32 @@ void ecore_reset_vport_stats(struct ecore_dev *p_dev)
 
        /* PORT statistics are not necessarily reset, so we need to
         * read and create a baseline for future statistics.
+        * Link change stat is maintained by MFW, return its value as is.
         */
        if (!p_dev->reset_stats)
                DP_INFO(p_dev, "Reset stats not allocated\n");
-       else
+       else {
                _ecore_get_vport_stats(p_dev, p_dev->reset_stats);
+               p_dev->reset_stats->common.link_change_count = 0;
+       }
+}
+
+static enum gft_profile_type
+ecore_arfs_mode_to_hsi(enum ecore_filter_config_mode mode)
+{
+       if (mode == ECORE_FILTER_CONFIG_MODE_5_TUPLE)
+               return GFT_PROFILE_TYPE_4_TUPLE;
+
+       if (mode == ECORE_FILTER_CONFIG_MODE_IP_DEST)
+               return GFT_PROFILE_TYPE_IP_DST_ADDR;
+
+       if (mode == ECORE_FILTER_CONFIG_MODE_TUNN_TYPE)
+               return GFT_PROFILE_TYPE_TUNNEL_TYPE;
+
+       if (mode == ECORE_FILTER_CONFIG_MODE_IP_SRC)
+               return GFT_PROFILE_TYPE_IP_SRC_ADDR;
+
+       return GFT_PROFILE_TYPE_L4_DST_PORT;
 }
 
 void ecore_arfs_mode_configure(struct ecore_hwfn *p_hwfn,
@@ -2075,13 +2117,13 @@ void ecore_arfs_mode_configure(struct ecore_hwfn *p_hwfn,
        if (OSAL_TEST_BIT(ECORE_MF_DISABLE_ARFS, &p_hwfn->p_dev->mf_bits))
                return;
 
-       if (p_cfg_params->arfs_enable) {
+       if (p_cfg_params->mode != ECORE_FILTER_CONFIG_MODE_DISABLE) {
                ecore_gft_config(p_hwfn, p_ptt, p_hwfn->rel_pf_id,
                                 p_cfg_params->tcp,
                                 p_cfg_params->udp,
                                 p_cfg_params->ipv4,
                                 p_cfg_params->ipv6,
-                                GFT_PROFILE_TYPE_4_TUPLE);
+                                ecore_arfs_mode_to_hsi(p_cfg_params->mode));
                DP_VERBOSE(p_hwfn, ECORE_MSG_SP,
                           "tcp = %s, udp = %s, ipv4 = %s, ipv6 =%s\n",
                           p_cfg_params->tcp ? "Enable" : "Disable",
@@ -2091,8 +2133,8 @@ void ecore_arfs_mode_configure(struct ecore_hwfn *p_hwfn,
        } else {
                ecore_gft_disable(p_hwfn, p_ptt, p_hwfn->rel_pf_id);
        }
-       DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "Configured ARFS mode : %s\n",
-                  p_cfg_params->arfs_enable ? "Enable" : "Disable");
+       DP_VERBOSE(p_hwfn, ECORE_MSG_SP, "Configured ARFS mode : %d\n",
+                  (int)p_cfg_params->mode);
 }
 
 enum _ecore_status_t
@@ -2150,7 +2192,7 @@ ecore_configure_rfs_ntuple_filter(struct ecore_hwfn *p_hwfn,
        p_ramrod->flow_id_valid = 0;
        p_ramrod->flow_id = 0;
 
-       p_ramrod->vport_id = abs_vport_id;
+       p_ramrod->vport_id = OSAL_CPU_TO_LE16((u16)abs_vport_id);
        p_ramrod->filter_action = b_is_add ? GFT_ADD_FILTER
                                           : GFT_DELETE_FILTER;
 
@@ -2163,10 +2205,10 @@ ecore_configure_rfs_ntuple_filter(struct ecore_hwfn *p_hwfn,
        return ecore_spq_post(p_hwfn, p_ent, OSAL_NULL);
 }
 
-int ecore_get_rxq_coalesce(struct ecore_hwfn *p_hwfn,
-                          struct ecore_ptt *p_ptt,
-                          struct ecore_queue_cid *p_cid,
-                          u16 *p_rx_coal)
+enum _ecore_status_t ecore_get_rxq_coalesce(struct ecore_hwfn *p_hwfn,
+                                           struct ecore_ptt *p_ptt,
+                                           struct ecore_queue_cid *p_cid,
+                                           u16 *p_rx_coal)
 {
        u32 coalesce, address, is_valid;
        struct cau_sb_entry sb_entry;
@@ -2175,7 +2217,8 @@ int ecore_get_rxq_coalesce(struct ecore_hwfn *p_hwfn,
 
        rc = ecore_dmae_grc2host(p_hwfn, p_ptt, CAU_REG_SB_VAR_MEMORY +
                                 p_cid->sb_igu_id * sizeof(u64),
-                                (u64)(osal_uintptr_t)&sb_entry, 2, 0);
+                                (u64)(osal_uintptr_t)&sb_entry, 2,
+                                OSAL_NULL /* default parameters */);
        if (rc != ECORE_SUCCESS) {
                DP_ERR(p_hwfn, "dmae_grc2host failed %d\n", rc);
                return rc;
@@ -2197,10 +2240,10 @@ int ecore_get_rxq_coalesce(struct ecore_hwfn *p_hwfn,
        return ECORE_SUCCESS;
 }
 
-int ecore_get_txq_coalesce(struct ecore_hwfn *p_hwfn,
-                          struct ecore_ptt *p_ptt,
-                          struct ecore_queue_cid *p_cid,
-                          u16 *p_tx_coal)
+enum _ecore_status_t ecore_get_txq_coalesce(struct ecore_hwfn *p_hwfn,
+                                           struct ecore_ptt *p_ptt,
+                                           struct ecore_queue_cid *p_cid,
+                                           u16 *p_tx_coal)
 {
        u32 coalesce, address, is_valid;
        struct cau_sb_entry sb_entry;
@@ -2209,7 +2252,8 @@ int ecore_get_txq_coalesce(struct ecore_hwfn *p_hwfn,
 
        rc = ecore_dmae_grc2host(p_hwfn, p_ptt, CAU_REG_SB_VAR_MEMORY +
                                 p_cid->sb_igu_id * sizeof(u64),
-                                (u64)(osal_uintptr_t)&sb_entry, 2, 0);
+                                (u64)(osal_uintptr_t)&sb_entry, 2,
+                                OSAL_NULL /* default parameters */);
        if (rc != ECORE_SUCCESS) {
                DP_ERR(p_hwfn, "dmae_grc2host failed %d\n", rc);
                return rc;
@@ -2267,3 +2311,74 @@ out:
 
        return rc;
 }
+
+enum _ecore_status_t
+ecore_eth_tx_queue_maxrate(struct ecore_hwfn *p_hwfn,
+                          struct ecore_ptt *p_ptt,
+                          struct ecore_queue_cid *p_cid, u32 rate)
+{
+       struct ecore_mcp_link_state *p_link;
+       u8 vport;
+
+       vport = (u8)ecore_get_qm_vport_idx_rl(p_hwfn, p_cid->rel.queue_id);
+       p_link = &ECORE_LEADING_HWFN(p_hwfn->p_dev)->mcp_info->link_output;
+
+       DP_VERBOSE(p_hwfn, ECORE_MSG_LINK,
+                  "About to rate limit qm vport %d for queue %d with rate %d\n",
+                  vport, p_cid->rel.queue_id, rate);
+
+       return ecore_init_vport_rl(p_hwfn, p_ptt, vport, rate,
+                                  p_link->speed);
+}
+
+#define RSS_TSTORM_UPDATE_STATUS_MAX_POLL_COUNT    100
+#define RSS_TSTORM_UPDATE_STATUS_POLL_PERIOD_US    1
+
+enum _ecore_status_t
+ecore_update_eth_rss_ind_table_entry(struct ecore_hwfn *p_hwfn,
+                                    u8 vport_id,
+                                    u8 ind_table_index,
+                                    u16 ind_table_value)
+{
+       struct eth_tstorm_rss_update_data update_data = { 0 };
+       void OSAL_IOMEM *addr = OSAL_NULL;
+       enum _ecore_status_t rc;
+       u8 abs_vport_id;
+       u32 cnt = 0;
+
+       OSAL_BUILD_BUG_ON(sizeof(update_data) != sizeof(u64));
+
+       rc = ecore_fw_vport(p_hwfn, vport_id, &abs_vport_id);
+       if (rc != ECORE_SUCCESS)
+               return rc;
+
+       addr = (u8 OSAL_IOMEM *)p_hwfn->regview +
+              GTT_BAR0_MAP_REG_TSDM_RAM +
+              TSTORM_ETH_RSS_UPDATE_OFFSET(p_hwfn->rel_pf_id);
+
+       *(u64 *)(&update_data) = DIRECT_REG_RD64(p_hwfn, addr);
+
+       for (cnt = 0; update_data.valid &&
+            cnt < RSS_TSTORM_UPDATE_STATUS_MAX_POLL_COUNT; cnt++) {
+               OSAL_UDELAY(RSS_TSTORM_UPDATE_STATUS_POLL_PERIOD_US);
+               *(u64 *)(&update_data) = DIRECT_REG_RD64(p_hwfn, addr);
+       }
+
+       if (update_data.valid) {
+               DP_NOTICE(p_hwfn, true,
+                         "rss update valid status is not clear! valid=0x%x vport id=%d ind_Table_idx=%d ind_table_value=%d.\n",
+                         update_data.valid, vport_id, ind_table_index,
+                         ind_table_value);
+
+               return ECORE_AGAIN;
+       }
+
+       update_data.valid           = 1;
+       update_data.ind_table_index = ind_table_index;
+       update_data.ind_table_value = ind_table_value;
+       update_data.vport_id        = abs_vport_id;
+
+       DIRECT_REG_WR64(p_hwfn, addr, *(u64 *)(&update_data));
+
+       return ECORE_SUCCESS;
+}