get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/955606/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 955606,
    "url": "http://patchwork.ozlabs.org/api/patches/955606/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20180809132958.23036-7-anirudh.venkataramanan@intel.com/",
    "project": {
        "id": 46,
        "url": "http://patchwork.ozlabs.org/api/projects/46/?format=api",
        "name": "Intel Wired Ethernet development",
        "link_name": "intel-wired-lan",
        "list_id": "intel-wired-lan.osuosl.org",
        "list_email": "intel-wired-lan@osuosl.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20180809132958.23036-7-anirudh.venkataramanan@intel.com>",
    "list_archive_url": null,
    "date": "2018-08-09T13:29:49",
    "name": "[v3,06/15] ice: Refactor switch rule management structures and functions",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "1975a54f6fbd5b534b382b99751990547ec895b4",
    "submitter": {
        "id": 73601,
        "url": "http://patchwork.ozlabs.org/api/people/73601/?format=api",
        "name": "Anirudh Venkataramanan",
        "email": "anirudh.venkataramanan@intel.com"
    },
    "delegate": {
        "id": 68,
        "url": "http://patchwork.ozlabs.org/api/users/68/?format=api",
        "username": "jtkirshe",
        "first_name": "Jeff",
        "last_name": "Kirsher",
        "email": "jeffrey.t.kirsher@intel.com"
    },
    "mbox": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/20180809132958.23036-7-anirudh.venkataramanan@intel.com/mbox/",
    "series": [
        {
            "id": 60078,
            "url": "http://patchwork.ozlabs.org/api/series/60078/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/list/?series=60078",
            "date": "2018-08-09T13:29:43",
            "name": "Feature updates for ice",
            "version": 3,
            "mbox": "http://patchwork.ozlabs.org/series/60078/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/955606/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/955606/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<intel-wired-lan-bounces@osuosl.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "intel-wired-lan@lists.osuosl.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@bilbo.ozlabs.org",
            "intel-wired-lan@lists.osuosl.org"
        ],
        "Authentication-Results": [
            "ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=osuosl.org\n\t(client-ip=140.211.166.133; helo=hemlock.osuosl.org;\n\tenvelope-from=intel-wired-lan-bounces@osuosl.org;\n\treceiver=<UNKNOWN>)",
            "ozlabs.org;\n\tdmarc=fail (p=none dis=none) header.from=intel.com"
        ],
        "Received": [
            "from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 41mTdw1WSvz9s0n\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu,  9 Aug 2018 23:30:28 +1000 (AEST)",
            "from localhost (localhost [127.0.0.1])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id AD72288347;\n\tThu,  9 Aug 2018 13:30:26 +0000 (UTC)",
            "from hemlock.osuosl.org ([127.0.0.1])\n\tby localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id X4nm0XAUvRo1; Thu,  9 Aug 2018 13:30:22 +0000 (UTC)",
            "from ash.osuosl.org (ash.osuosl.org [140.211.166.34])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id C5A6C88350;\n\tThu,  9 Aug 2018 13:30:22 +0000 (UTC)",
            "from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138])\n\tby ash.osuosl.org (Postfix) with ESMTP id D7E6D1C3F93\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tThu,  9 Aug 2018 13:30:21 +0000 (UTC)",
            "from localhost (localhost [127.0.0.1])\n\tby whitealder.osuosl.org (Postfix) with ESMTP id C995787A31\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tThu,  9 Aug 2018 13:30:21 +0000 (UTC)",
            "from whitealder.osuosl.org ([127.0.0.1])\n\tby localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id nMJbk2yf2Cza for <intel-wired-lan@lists.osuosl.org>;\n\tThu,  9 Aug 2018 13:30:16 +0000 (UTC)",
            "from mga12.intel.com (mga12.intel.com [192.55.52.136])\n\tby whitealder.osuosl.org (Postfix) with ESMTPS id 98BF3879CF\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tThu,  9 Aug 2018 13:30:16 +0000 (UTC)",
            "from fmsmga006.fm.intel.com ([10.253.24.20])\n\tby fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t09 Aug 2018 06:30:16 -0700",
            "from kyungmin-mobl.amr.corp.intel.com (HELO\n\tavenkata-mobl4.localdomain) ([10.254.101.153])\n\tby fmsmga006.fm.intel.com with ESMTP; 09 Aug 2018 06:30:14 -0700"
        ],
        "X-Virus-Scanned": [
            "amavisd-new at osuosl.org",
            "amavisd-new at osuosl.org"
        ],
        "X-Greylist": "domain auto-whitelisted by SQLgrey-1.7.6",
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.53,215,1531810800\"; d=\"scan'208\";a=\"253368132\"",
        "From": "Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>",
        "To": "intel-wired-lan@lists.osuosl.org",
        "Date": "Thu,  9 Aug 2018 06:29:49 -0700",
        "Message-Id": "<20180809132958.23036-7-anirudh.venkataramanan@intel.com>",
        "X-Mailer": "git-send-email 2.17.1",
        "In-Reply-To": "<20180809132958.23036-1-anirudh.venkataramanan@intel.com>",
        "References": "<20180809132958.23036-1-anirudh.venkataramanan@intel.com>",
        "Subject": "[Intel-wired-lan] [PATCH v3 06/15] ice: Refactor switch rule\n\tmanagement structures and functions",
        "X-BeenThere": "intel-wired-lan@osuosl.org",
        "X-Mailman-Version": "2.1.24",
        "Precedence": "list",
        "List-Id": "Intel Wired Ethernet Linux Kernel Driver Development\n\t<intel-wired-lan.osuosl.org>",
        "List-Unsubscribe": "<https://lists.osuosl.org/mailman/options/intel-wired-lan>, \n\t<mailto:intel-wired-lan-request@osuosl.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.osuosl.org/pipermail/intel-wired-lan/>",
        "List-Post": "<mailto:intel-wired-lan@osuosl.org>",
        "List-Help": "<mailto:intel-wired-lan-request@osuosl.org?subject=help>",
        "List-Subscribe": "<https://lists.osuosl.org/mailman/listinfo/intel-wired-lan>, \n\t<mailto:intel-wired-lan-request@osuosl.org?subject=subscribe>",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "intel-wired-lan-bounces@osuosl.org",
        "Sender": "\"Intel-wired-lan\" <intel-wired-lan-bounces@osuosl.org>"
    },
    "content": "This patch is an adaptation of the work originally done by Grishma\nKotecha <grishma.kotecha@intel.com> that in summary refactors the\nswitch filtering logic in the driver. More specifically,\n - Update the recipe structure to also store list of rules\n - Update the existing code for recipes like mac, vlan, ethtype etc to\n   use list head that is attached to switch recipe structure\n - Add a common function to search for a rule entry and add a new rule\n   entry. Update the code to use this new function.\n - Refactor the rem_handle_vsi_list function to simplify the logic\n\nCC: Shannon Nelson <shannon.nelson@oracle.com>\nSigned-off-by: Anirudh Venkataramanan <anirudh.venkataramanan@intel.com>\n---\n .../net/ethernet/intel/ice/ice_adminq_cmd.h   |   2 +\n drivers/net/ethernet/intel/ice/ice_common.c   |  36 +-\n drivers/net/ethernet/intel/ice/ice_switch.c   | 968 ++++++++----------\n drivers/net/ethernet/intel/ice/ice_switch.h   |  35 +-\n drivers/net/ethernet/intel/ice/ice_type.h     |  13 +-\n 5 files changed, 501 insertions(+), 553 deletions(-)",
    "diff": "diff --git a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h\nindex 9a33fb95c0ea..87b304db9cad 100644\n--- a/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h\n+++ b/drivers/net/ethernet/intel/ice/ice_adminq_cmd.h\n@@ -443,6 +443,8 @@ struct ice_aqc_vsi_props {\n \tu8 reserved[24];\n };\n \n+#define ICE_MAX_NUM_RECIPES 64\n+\n /* Add/Update/Remove/Get switch rules (indirect 0x02A0, 0x02A1, 0x02A2, 0x02A3)\n  */\n struct ice_aqc_sw_rules {\ndiff --git a/drivers/net/ethernet/intel/ice/ice_common.c b/drivers/net/ethernet/intel/ice/ice_common.c\nindex caf2620b7852..d5c845148c6d 100644\n--- a/drivers/net/ethernet/intel/ice/ice_common.c\n+++ b/drivers/net/ethernet/intel/ice/ice_common.c\n@@ -388,20 +388,7 @@ static enum ice_status ice_init_fltr_mgmt_struct(struct ice_hw *hw)\n \n \tINIT_LIST_HEAD(&sw->vsi_list_map_head);\n \n-\tmutex_init(&sw->mac_list_lock);\n-\tINIT_LIST_HEAD(&sw->mac_list_head);\n-\n-\tmutex_init(&sw->vlan_list_lock);\n-\tINIT_LIST_HEAD(&sw->vlan_list_head);\n-\n-\tmutex_init(&sw->eth_m_list_lock);\n-\tINIT_LIST_HEAD(&sw->eth_m_list_head);\n-\n-\tmutex_init(&sw->promisc_list_lock);\n-\tINIT_LIST_HEAD(&sw->promisc_list_head);\n-\n-\tmutex_init(&sw->mac_vlan_list_lock);\n-\tINIT_LIST_HEAD(&sw->mac_vlan_list_head);\n+\tice_init_def_sw_recp(hw);\n \n \treturn 0;\n }\n@@ -415,19 +402,28 @@ static void ice_cleanup_fltr_mgmt_struct(struct ice_hw *hw)\n \tstruct ice_switch_info *sw = hw->switch_info;\n \tstruct ice_vsi_list_map_info *v_pos_map;\n \tstruct ice_vsi_list_map_info *v_tmp_map;\n+\tstruct ice_sw_recipe *recps;\n+\tu8 i;\n \n \tlist_for_each_entry_safe(v_pos_map, v_tmp_map, &sw->vsi_list_map_head,\n \t\t\t\t list_entry) {\n \t\tlist_del(&v_pos_map->list_entry);\n \t\tdevm_kfree(ice_hw_to_dev(hw), v_pos_map);\n \t}\n+\trecps = hw->switch_info->recp_list;\n+\tfor (i = 0; i < ICE_SW_LKUP_LAST; i++) {\n+\t\tstruct ice_fltr_mgmt_list_entry *lst_itr, *tmp_entry;\n+\n+\t\trecps[i].root_rid = i;\n+\t\tmutex_destroy(&recps[i].filt_rule_lock);\n+\t\tlist_for_each_entry_safe(lst_itr, tmp_entry,\n+\t\t\t\t\t &recps[i].filt_rules, list_entry) {\n+\t\t\tlist_del(&lst_itr->list_entry);\n+\t\t\tdevm_kfree(ice_hw_to_dev(hw), lst_itr);\n+\t\t}\n+\t}\n \n-\tmutex_destroy(&sw->mac_list_lock);\n-\tmutex_destroy(&sw->vlan_list_lock);\n-\tmutex_destroy(&sw->eth_m_list_lock);\n-\tmutex_destroy(&sw->promisc_list_lock);\n-\tmutex_destroy(&sw->mac_vlan_list_lock);\n-\n+\tdevm_kfree(ice_hw_to_dev(hw), sw->recp_list);\n \tdevm_kfree(ice_hw_to_dev(hw), sw);\n }\n \ndiff --git a/drivers/net/ethernet/intel/ice/ice_switch.c b/drivers/net/ethernet/intel/ice/ice_switch.c\nindex d8b18cabc3a8..1c3522a5ec62 100644\n--- a/drivers/net/ethernet/intel/ice/ice_switch.c\n+++ b/drivers/net/ethernet/intel/ice/ice_switch.c\n@@ -85,6 +85,35 @@ ice_aq_alloc_free_res(struct ice_hw *hw, u16 num_entries,\n \treturn ice_aq_send_cmd(hw, &desc, buf, buf_size, cd);\n }\n \n+/**\n+ * ice_init_def_sw_recp - initialize the recipe book keeping tables\n+ * @hw: pointer to the hw struct\n+ *\n+ * Allocate memory for the entire recipe table and initialize the structures/\n+ * entries corresponding to basic recipes.\n+ */\n+enum ice_status\n+ice_init_def_sw_recp(struct ice_hw *hw)\n+{\n+\tstruct ice_sw_recipe *recps;\n+\tu8 i;\n+\n+\trecps = devm_kcalloc(ice_hw_to_dev(hw), ICE_MAX_NUM_RECIPES,\n+\t\t\t     sizeof(struct ice_sw_recipe), GFP_KERNEL);\n+\tif (!recps)\n+\t\treturn ICE_ERR_NO_MEMORY;\n+\n+\tfor (i = 0; i < ICE_SW_LKUP_LAST; i++) {\n+\t\trecps[i].root_rid = i;\n+\t\tINIT_LIST_HEAD(&recps[i].filt_rules);\n+\t\tmutex_init(&recps[i].filt_rule_lock);\n+\t}\n+\n+\thw->switch_info->recp_list = recps;\n+\n+\treturn 0;\n+}\n+\n /**\n  * ice_aq_get_sw_cfg - get switch configuration\n  * @hw: pointer to the hardware structure\n@@ -818,10 +847,10 @@ static enum ice_status\n ice_create_pkt_fwd_rule(struct ice_hw *hw,\n \t\t\tstruct ice_fltr_list_entry *f_entry)\n {\n-\tstruct ice_switch_info *sw = hw->switch_info;\n \tstruct ice_fltr_mgmt_list_entry *fm_entry;\n \tstruct ice_aqc_sw_rules_elem *s_rule;\n \tenum ice_sw_lkup_type l_type;\n+\tstruct ice_sw_recipe *recp;\n \tenum ice_status status;\n \n \ts_rule = devm_kzalloc(ice_hw_to_dev(hw),\n@@ -862,31 +891,9 @@ ice_create_pkt_fwd_rule(struct ice_hw *hw,\n \t * calls remove filter AQ command\n \t */\n \tl_type = fm_entry->fltr_info.lkup_type;\n-\tif (l_type == ICE_SW_LKUP_MAC) {\n-\t\tmutex_lock(&sw->mac_list_lock);\n-\t\tlist_add(&fm_entry->list_entry, &sw->mac_list_head);\n-\t\tmutex_unlock(&sw->mac_list_lock);\n-\t} else if (l_type == ICE_SW_LKUP_VLAN) {\n-\t\tmutex_lock(&sw->vlan_list_lock);\n-\t\tlist_add(&fm_entry->list_entry, &sw->vlan_list_head);\n-\t\tmutex_unlock(&sw->vlan_list_lock);\n-\t} else if (l_type == ICE_SW_LKUP_ETHERTYPE ||\n-\t\t   l_type == ICE_SW_LKUP_ETHERTYPE_MAC) {\n-\t\tmutex_lock(&sw->eth_m_list_lock);\n-\t\tlist_add(&fm_entry->list_entry, &sw->eth_m_list_head);\n-\t\tmutex_unlock(&sw->eth_m_list_lock);\n-\t} else if (l_type == ICE_SW_LKUP_PROMISC ||\n-\t\t   l_type == ICE_SW_LKUP_PROMISC_VLAN) {\n-\t\tmutex_lock(&sw->promisc_list_lock);\n-\t\tlist_add(&fm_entry->list_entry, &sw->promisc_list_head);\n-\t\tmutex_unlock(&sw->promisc_list_lock);\n-\t} else if (fm_entry->fltr_info.lkup_type == ICE_SW_LKUP_MAC_VLAN) {\n-\t\tmutex_lock(&sw->mac_vlan_list_lock);\n-\t\tlist_add(&fm_entry->list_entry, &sw->mac_vlan_list_head);\n-\t\tmutex_unlock(&sw->mac_vlan_list_lock);\n-\t} else {\n-\t\tstatus = ICE_ERR_NOT_IMPL;\n-\t}\n+\trecp = &hw->switch_info->recp_list[l_type];\n+\tlist_add(&fm_entry->list_entry, &recp->filt_rules);\n+\n ice_create_pkt_fwd_rule_exit:\n \tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n \treturn status;\n@@ -895,19 +902,15 @@ ice_create_pkt_fwd_rule(struct ice_hw *hw,\n /**\n  * ice_update_pkt_fwd_rule\n  * @hw: pointer to the hardware structure\n- * @rule_id: rule of previously created switch rule to update\n- * @vsi_list_id: VSI list id to be updated with\n- * @f_info: ice_fltr_info to pull other information for switch rule\n+ * @f_info: filter information for switch rule\n  *\n  * Call AQ command to update a previously created switch rule with a\n  * VSI list id\n  */\n static enum ice_status\n-ice_update_pkt_fwd_rule(struct ice_hw *hw, u16 rule_id, u16 vsi_list_id,\n-\t\t\tstruct ice_fltr_info f_info)\n+ice_update_pkt_fwd_rule(struct ice_hw *hw, struct ice_fltr_info *f_info)\n {\n \tstruct ice_aqc_sw_rules_elem *s_rule;\n-\tstruct ice_fltr_info tmp_fltr;\n \tenum ice_status status;\n \n \ts_rule = devm_kzalloc(ice_hw_to_dev(hw),\n@@ -915,14 +918,9 @@ ice_update_pkt_fwd_rule(struct ice_hw *hw, u16 rule_id, u16 vsi_list_id,\n \tif (!s_rule)\n \t\treturn ICE_ERR_NO_MEMORY;\n \n-\ttmp_fltr = f_info;\n-\ttmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;\n-\ttmp_fltr.fwd_id.vsi_list_id = vsi_list_id;\n-\n-\tice_fill_sw_rule(hw, &tmp_fltr, s_rule,\n-\t\t\t ice_aqc_opc_update_sw_rules);\n+\tice_fill_sw_rule(hw, f_info, s_rule, ice_aqc_opc_update_sw_rules);\n \n-\ts_rule->pdata.lkup_tx_rx.index = cpu_to_le16(rule_id);\n+\ts_rule->pdata.lkup_tx_rx.index = cpu_to_le16(f_info->fltr_rule_id);\n \n \t/* Update switch rule with new rule set to forward VSI list */\n \tstatus = ice_aq_sw_rules(hw, s_rule, ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,\n@@ -933,7 +931,7 @@ ice_update_pkt_fwd_rule(struct ice_hw *hw, u16 rule_id, u16 vsi_list_id,\n }\n \n /**\n- * ice_handle_vsi_list_mgmt\n+ * ice_add_update_vsi_list\n  * @hw: pointer to the hardware structure\n  * @m_entry: pointer to current filter management list entry\n  * @cur_fltr: filter information from the book keeping entry\n@@ -954,10 +952,10 @@ ice_update_pkt_fwd_rule(struct ice_hw *hw, u16 rule_id, u16 vsi_list_id,\n  *\t\tusing the update switch rule command\n  */\n static enum ice_status\n-ice_handle_vsi_list_mgmt(struct ice_hw *hw,\n-\t\t\t struct ice_fltr_mgmt_list_entry *m_entry,\n-\t\t\t struct ice_fltr_info *cur_fltr,\n-\t\t\t struct ice_fltr_info *new_fltr)\n+ice_add_update_vsi_list(struct ice_hw *hw,\n+\t\t\tstruct ice_fltr_mgmt_list_entry *m_entry,\n+\t\t\tstruct ice_fltr_info *cur_fltr,\n+\t\t\tstruct ice_fltr_info *new_fltr)\n {\n \tenum ice_status status = 0;\n \tu16 vsi_list_id = 0;\n@@ -977,8 +975,8 @@ ice_handle_vsi_list_mgmt(struct ice_hw *hw,\n \t\t * a part of a VSI list. So, create a VSI list with the old and\n \t\t * new VSIs.\n \t\t */\n+\t\tstruct ice_fltr_info tmp_fltr;\n \t\tu16 vsi_id_arr[2];\n-\t\tu16 fltr_rule;\n \n \t\t/* A rule already exists with the new VSI being added */\n \t\tif (cur_fltr->fwd_id.vsi_id == new_fltr->fwd_id.vsi_id)\n@@ -992,12 +990,14 @@ ice_handle_vsi_list_mgmt(struct ice_hw *hw,\n \t\tif (status)\n \t\t\treturn status;\n \n-\t\tfltr_rule = cur_fltr->fltr_rule_id;\n+\t\ttmp_fltr = *new_fltr;\n+\t\ttmp_fltr.fltr_rule_id = cur_fltr->fltr_rule_id;\n+\t\ttmp_fltr.fltr_act = ICE_FWD_TO_VSI_LIST;\n+\t\ttmp_fltr.fwd_id.vsi_list_id = vsi_list_id;\n \t\t/* Update the previous switch rule of \"MAC forward to VSI\" to\n \t\t * \"MAC fwd to VSI list\"\n \t\t */\n-\t\tstatus = ice_update_pkt_fwd_rule(hw, fltr_rule, vsi_list_id,\n-\t\t\t\t\t\t *new_fltr);\n+\t\tstatus = ice_update_pkt_fwd_rule(hw, &tmp_fltr);\n \t\tif (status)\n \t\t\treturn status;\n \n@@ -1042,54 +1042,246 @@ ice_handle_vsi_list_mgmt(struct ice_hw *hw,\n }\n \n /**\n- * ice_find_mac_entry\n+ * ice_find_rule_entry - Search a rule entry\n  * @hw: pointer to the hardware structure\n- * @mac_addr: MAC address to search for\n+ * @recp_id: lookup type for which the specified rule needs to be searched\n+ * @f_info: rule information\n  *\n- * Helper function to search for a MAC entry using a given MAC address\n- * Returns pointer to the entry if found.\n+ * Helper function to search for a given rule entry\n+ * Returns pointer to entry storing the rule if found\n  */\n static struct ice_fltr_mgmt_list_entry *\n-ice_find_mac_entry(struct ice_hw *hw, u8 *mac_addr)\n+ice_find_rule_entry(struct ice_hw *hw, u8 recp_id, struct ice_fltr_info *f_info)\n {\n-\tstruct ice_fltr_mgmt_list_entry *m_list_itr, *mac_ret = NULL;\n+\tstruct ice_fltr_mgmt_list_entry *list_itr, *ret = NULL;\n \tstruct ice_switch_info *sw = hw->switch_info;\n-\n-\tmutex_lock(&sw->mac_list_lock);\n-\tlist_for_each_entry(m_list_itr, &sw->mac_list_head, list_entry) {\n-\t\tu8 *buf = &m_list_itr->fltr_info.l_data.mac.mac_addr[0];\n-\n-\t\tif (ether_addr_equal(buf, mac_addr)) {\n-\t\t\tmac_ret = m_list_itr;\n+\tstruct list_head *list_head;\n+\n+\tlist_head = &sw->recp_list[recp_id].filt_rules;\n+\tlist_for_each_entry(list_itr, list_head, list_entry) {\n+\t\tif (!memcmp(&f_info->l_data, &list_itr->fltr_info.l_data,\n+\t\t\t    sizeof(f_info->l_data)) &&\n+\t\t    f_info->flag == list_itr->fltr_info.flag) {\n+\t\t\tret = list_itr;\n \t\t\tbreak;\n \t\t}\n \t}\n-\tmutex_unlock(&sw->mac_list_lock);\n-\treturn mac_ret;\n+\treturn ret;\n }\n \n /**\n- * ice_add_shared_mac - Add one MAC shared filter rule\n+ * ice_add_rule_internal - add rule for a given lookup type\n  * @hw: pointer to the hardware structure\n+ * @recp_id: lookup type (recipe id) for which rule has to be added\n  * @f_entry: structure containing MAC forwarding information\n  *\n- * Adds or updates the book keeping list for the MAC addresses\n+ * Adds or updates the rule lists for a given recipe\n  */\n static enum ice_status\n-ice_add_shared_mac(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)\n+ice_add_rule_internal(struct ice_hw *hw, u8 recp_id,\n+\t\t      struct ice_fltr_list_entry *f_entry)\n {\n+\tstruct ice_switch_info *sw = hw->switch_info;\n \tstruct ice_fltr_info *new_fltr, *cur_fltr;\n \tstruct ice_fltr_mgmt_list_entry *m_entry;\n+\tstruct mutex *rule_lock; /* Lock to protect filter rule list */\n+\tenum ice_status status = 0;\n \n-\tnew_fltr = &f_entry->fltr_info;\n+\trule_lock = &sw->recp_list[recp_id].filt_rule_lock;\n \n-\tm_entry = ice_find_mac_entry(hw, &new_fltr->l_data.mac.mac_addr[0]);\n-\tif (!m_entry)\n+\tmutex_lock(rule_lock);\n+\tnew_fltr = &f_entry->fltr_info;\n+\tif (new_fltr->flag & ICE_FLTR_RX)\n+\t\tnew_fltr->src = hw->port_info->lport;\n+\telse if (new_fltr->flag & ICE_FLTR_TX)\n+\t\tnew_fltr->src = f_entry->fltr_info.fwd_id.vsi_id;\n+\n+\tm_entry = ice_find_rule_entry(hw, recp_id, new_fltr);\n+\tif (!m_entry) {\n+\t\tmutex_unlock(rule_lock);\n \t\treturn ice_create_pkt_fwd_rule(hw, f_entry);\n+\t}\n \n \tcur_fltr = &m_entry->fltr_info;\n+\tstatus = ice_add_update_vsi_list(hw, m_entry, cur_fltr, new_fltr);\n+\tmutex_unlock(rule_lock);\n+\n+\treturn status;\n+}\n+\n+/**\n+ * ice_remove_vsi_list_rule\n+ * @hw: pointer to the hardware structure\n+ * @vsi_list_id: VSI list id generated as part of allocate resource\n+ * @lkup_type: switch rule filter lookup type\n+ *\n+ * The VSI list should be emptied before this function is called to remove the\n+ * VSI list.\n+ */\n+static enum ice_status\n+ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,\n+\t\t\t enum ice_sw_lkup_type lkup_type)\n+{\n+\tstruct ice_aqc_sw_rules_elem *s_rule;\n+\tenum ice_status status;\n+\tu16 s_rule_size;\n+\n+\ts_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);\n+\ts_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);\n+\tif (!s_rule)\n+\t\treturn ICE_ERR_NO_MEMORY;\n+\n+\ts_rule->type = cpu_to_le16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);\n+\ts_rule->pdata.vsi_list.index = cpu_to_le16(vsi_list_id);\n+\n+\t/* Free the vsi_list resource that we allocated. It is assumed that the\n+\t * list is empty at this point.\n+\t */\n+\tstatus = ice_aq_alloc_free_vsi_list(hw, &vsi_list_id, lkup_type,\n+\t\t\t\t\t    ice_aqc_opc_free_res);\n+\n+\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n+\treturn status;\n+}\n+\n+/**\n+ * ice_rem_update_vsi_list\n+ * @hw: pointer to the hardware structure\n+ * @vsi_id: ID of the VSI to remove\n+ * @fm_list: filter management entry for which the VSI list management needs to\n+ *\t     be done\n+ */\n+static enum ice_status\n+ice_rem_update_vsi_list(struct ice_hw *hw, u16 vsi_id,\n+\t\t\tstruct ice_fltr_mgmt_list_entry *fm_list)\n+{\n+\tenum ice_sw_lkup_type lkup_type;\n+\tenum ice_status status = 0;\n+\tu16 vsi_list_id;\n+\n+\tif (fm_list->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST ||\n+\t    fm_list->vsi_count == 0)\n+\t\treturn ICE_ERR_PARAM;\n+\n+\t/* A rule with the VSI being removed does not exist */\n+\tif (!test_bit(vsi_id, fm_list->vsi_list_info->vsi_map))\n+\t\treturn ICE_ERR_DOES_NOT_EXIST;\n+\n+\tlkup_type = fm_list->fltr_info.lkup_type;\n+\tvsi_list_id = fm_list->fltr_info.fwd_id.vsi_list_id;\n+\n+\tstatus = ice_update_vsi_list_rule(hw, &vsi_id, 1, vsi_list_id, true,\n+\t\t\t\t\t  ice_aqc_opc_update_sw_rules,\n+\t\t\t\t\t  lkup_type);\n+\tif (status)\n+\t\treturn status;\n+\n+\tfm_list->vsi_count--;\n+\tclear_bit(vsi_id, fm_list->vsi_list_info->vsi_map);\n+\n+\tif ((fm_list->vsi_count == 1 && lkup_type != ICE_SW_LKUP_VLAN) ||\n+\t    (fm_list->vsi_count == 0 && lkup_type == ICE_SW_LKUP_VLAN)) {\n+\t\tstruct ice_vsi_list_map_info *vsi_list_info =\n+\t\t\tfm_list->vsi_list_info;\n+\t\tu16 rem_vsi_id;\n+\n+\t\trem_vsi_id = find_first_bit(vsi_list_info->vsi_map,\n+\t\t\t\t\t    ICE_MAX_VSI);\n+\t\tif (rem_vsi_id == ICE_MAX_VSI)\n+\t\t\treturn ICE_ERR_OUT_OF_RANGE;\n+\n+\t\tstatus = ice_update_vsi_list_rule(hw, &rem_vsi_id, 1,\n+\t\t\t\t\t\t  vsi_list_id, true,\n+\t\t\t\t\t\t  ice_aqc_opc_update_sw_rules,\n+\t\t\t\t\t\t  lkup_type);\n+\t\tif (status)\n+\t\t\treturn status;\n+\n+\t\t/* Remove the VSI list since it is no longer used */\n+\t\tstatus = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);\n+\t\tif (status)\n+\t\t\treturn status;\n+\n+\t\t/* Change the list entry action from VSI_LIST to VSI */\n+\t\tfm_list->fltr_info.fltr_act = ICE_FWD_TO_VSI;\n+\t\tfm_list->fltr_info.fwd_id.vsi_id = rem_vsi_id;\n+\n+\t\tlist_del(&vsi_list_info->list_entry);\n+\t\tdevm_kfree(ice_hw_to_dev(hw), vsi_list_info);\n+\t\tfm_list->vsi_list_info = NULL;\n+\t}\n+\n+\treturn status;\n+}\n+\n+/**\n+ * ice_remove_rule_internal - Remove a filter rule of a given type\n+ *\n+ * @hw: pointer to the hardware structure\n+ * @recp_id: recipe id for which the rule needs to removed\n+ * @f_entry: rule entry containing filter information\n+ */\n+static enum ice_status\n+ice_remove_rule_internal(struct ice_hw *hw, u8 recp_id,\n+\t\t\t struct ice_fltr_list_entry *f_entry)\n+{\n+\tstruct ice_switch_info *sw = hw->switch_info;\n+\tstruct ice_fltr_mgmt_list_entry *list_elem;\n+\tstruct mutex *rule_lock; /* Lock to protect filter rule list */\n+\tenum ice_status status = 0;\n+\tbool remove_rule = false;\n+\tu16 vsi_id;\n+\n+\trule_lock = &sw->recp_list[recp_id].filt_rule_lock;\n+\tmutex_lock(rule_lock);\n+\tlist_elem = ice_find_rule_entry(hw, recp_id, &f_entry->fltr_info);\n+\tif (!list_elem) {\n+\t\tstatus = ICE_ERR_DOES_NOT_EXIST;\n+\t\tgoto exit;\n+\t}\n+\n+\tif (list_elem->fltr_info.fltr_act != ICE_FWD_TO_VSI_LIST) {\n+\t\tremove_rule = true;\n+\t} else {\n+\t\tvsi_id = f_entry->fltr_info.fwd_id.vsi_id;\n+\t\tstatus = ice_rem_update_vsi_list(hw, vsi_id, list_elem);\n+\t\tif (status)\n+\t\t\tgoto exit;\n+\t\t/* if vsi count goes to zero after updating the vsi list */\n+\t\tif (list_elem->vsi_count == 0)\n+\t\t\tremove_rule = true;\n+\t}\n+\n+\tif (remove_rule) {\n+\t\t/* Remove the lookup rule */\n+\t\tstruct ice_aqc_sw_rules_elem *s_rule;\n+\n+\t\ts_rule = devm_kzalloc(ice_hw_to_dev(hw),\n+\t\t\t\t      ICE_SW_RULE_RX_TX_NO_HDR_SIZE,\n+\t\t\t\t      GFP_KERNEL);\n+\t\tif (!s_rule) {\n+\t\t\tstatus = ICE_ERR_NO_MEMORY;\n+\t\t\tgoto exit;\n+\t\t}\n+\n+\t\tice_fill_sw_rule(hw, &list_elem->fltr_info, s_rule,\n+\t\t\t\t ice_aqc_opc_remove_sw_rules);\n+\n+\t\tstatus = ice_aq_sw_rules(hw, s_rule,\n+\t\t\t\t\t ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,\n+\t\t\t\t\t ice_aqc_opc_remove_sw_rules, NULL);\n+\t\tif (status)\n+\t\t\tgoto exit;\n+\n+\t\t/* Remove a book keeping from the list */\n+\t\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n \n-\treturn ice_handle_vsi_list_mgmt(hw, m_entry, cur_fltr, new_fltr);\n+\t\tlist_del(&list_elem->list_entry);\n+\t\tdevm_kfree(ice_hw_to_dev(hw), list_elem);\n+\t}\n+exit:\n+\tmutex_unlock(rule_lock);\n+\treturn status;\n }\n \n /**\n@@ -1108,7 +1300,10 @@ ice_add_mac(struct ice_hw *hw, struct list_head *m_list)\n {\n \tstruct ice_aqc_sw_rules_elem *s_rule, *r_iter;\n \tstruct ice_fltr_list_entry *m_list_itr;\n+\tstruct list_head *rule_head;\n \tu16 elem_sent, total_elem_left;\n+\tstruct ice_switch_info *sw;\n+\tstruct mutex *rule_lock; /* Lock to protect filter rule list */\n \tenum ice_status status = 0;\n \tu16 num_unicast = 0;\n \tu16 s_rule_size;\n@@ -1116,48 +1311,62 @@ ice_add_mac(struct ice_hw *hw, struct list_head *m_list)\n \tif (!m_list || !hw)\n \t\treturn ICE_ERR_PARAM;\n \n+\ts_rule = NULL;\n+\tsw = hw->switch_info;\n+\trule_lock = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rule_lock;\n \tlist_for_each_entry(m_list_itr, m_list, list_entry) {\n \t\tu8 *add = &m_list_itr->fltr_info.l_data.mac.mac_addr[0];\n \n-\t\tif (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC)\n-\t\t\treturn ICE_ERR_PARAM;\n-\t\tif (is_zero_ether_addr(add))\n+\t\tm_list_itr->fltr_info.flag = ICE_FLTR_TX;\n+\t\tif (m_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_MAC ||\n+\t\t    is_zero_ether_addr(add))\n \t\t\treturn ICE_ERR_PARAM;\n \t\tif (is_unicast_ether_addr(add) && !hw->ucast_shared) {\n \t\t\t/* Don't overwrite the unicast address */\n-\t\t\tif (ice_find_mac_entry(hw, add))\n+\t\t\tmutex_lock(rule_lock);\n+\t\t\tif (ice_find_rule_entry(hw, ICE_SW_LKUP_MAC,\n+\t\t\t\t\t\t&m_list_itr->fltr_info)) {\n+\t\t\t\tmutex_unlock(rule_lock);\n \t\t\t\treturn ICE_ERR_ALREADY_EXISTS;\n+\t\t\t}\n+\t\t\tmutex_unlock(rule_lock);\n \t\t\tnum_unicast++;\n \t\t} else if (is_multicast_ether_addr(add) ||\n \t\t\t   (is_unicast_ether_addr(add) && hw->ucast_shared)) {\n-\t\t\tstatus = ice_add_shared_mac(hw, m_list_itr);\n-\t\t\tif (status) {\n-\t\t\t\tm_list_itr->status = ICE_FLTR_STATUS_FW_FAIL;\n-\t\t\t\treturn status;\n-\t\t\t}\n-\t\t\tm_list_itr->status = ICE_FLTR_STATUS_FW_SUCCESS;\n+\t\t\tm_list_itr->status =\n+\t\t\t\tice_add_rule_internal(hw, ICE_SW_LKUP_MAC,\n+\t\t\t\t\t\t      m_list_itr);\n+\t\t\tif (m_list_itr->status)\n+\t\t\t\treturn m_list_itr->status;\n \t\t}\n \t}\n \n+\tmutex_lock(rule_lock);\n \t/* Exit if no suitable entries were found for adding bulk switch rule */\n-\tif (!num_unicast)\n-\t\treturn 0;\n+\tif (!num_unicast) {\n+\t\tstatus = 0;\n+\t\tgoto ice_add_mac_exit;\n+\t}\n+\n+\trule_head = &sw->recp_list[ICE_SW_LKUP_MAC].filt_rules;\n \n \t/* Allocate switch rule buffer for the bulk update for unicast */\n \ts_rule_size = ICE_SW_RULE_RX_TX_ETH_HDR_SIZE;\n \ts_rule = devm_kcalloc(ice_hw_to_dev(hw), num_unicast, s_rule_size,\n \t\t\t      GFP_KERNEL);\n-\tif (!s_rule)\n-\t\treturn ICE_ERR_NO_MEMORY;\n+\tif (!s_rule) {\n+\t\tstatus = ICE_ERR_NO_MEMORY;\n+\t\tgoto ice_add_mac_exit;\n+\t}\n \n \tr_iter = s_rule;\n \tlist_for_each_entry(m_list_itr, m_list, list_entry) {\n \t\tstruct ice_fltr_info *f_info = &m_list_itr->fltr_info;\n-\t\tu8 *addr = &f_info->l_data.mac.mac_addr[0];\n+\t\tu8 *mac_addr = &f_info->l_data.mac.mac_addr[0];\n \n-\t\tif (is_unicast_ether_addr(addr)) {\n-\t\t\tice_fill_sw_rule(hw, &m_list_itr->fltr_info,\n-\t\t\t\t\t r_iter, ice_aqc_opc_add_sw_rules);\n+\t\tif (is_unicast_ether_addr(mac_addr)) {\n+\t\t\tice_fill_sw_rule(hw, &m_list_itr->fltr_info, r_iter,\n+\t\t\t\t\t ice_aqc_opc_add_sw_rules);\n \t\t\tr_iter = (struct ice_aqc_sw_rules_elem *)\n \t\t\t\t((u8 *)r_iter + s_rule_size);\n \t\t}\n@@ -1185,11 +1394,10 @@ ice_add_mac(struct ice_hw *hw, struct list_head *m_list)\n \tr_iter = s_rule;\n \tlist_for_each_entry(m_list_itr, m_list, list_entry) {\n \t\tstruct ice_fltr_info *f_info = &m_list_itr->fltr_info;\n-\t\tu8 *addr = &f_info->l_data.mac.mac_addr[0];\n-\t\tstruct ice_switch_info *sw = hw->switch_info;\n+\t\tu8 *mac_addr = &f_info->l_data.mac.mac_addr[0];\n \t\tstruct ice_fltr_mgmt_list_entry *fm_entry;\n \n-\t\tif (is_unicast_ether_addr(addr)) {\n+\t\tif (is_unicast_ether_addr(mac_addr)) {\n \t\t\tf_info->fltr_rule_id =\n \t\t\t\tle16_to_cpu(r_iter->pdata.lkup_tx_rx.index);\n \t\t\tf_info->fltr_act = ICE_FWD_TO_VSI;\n@@ -1205,45 +1413,20 @@ ice_add_mac(struct ice_hw *hw, struct list_head *m_list)\n \t\t\t/* The book keeping entries will get removed when\n \t\t\t * base driver calls remove filter AQ command\n \t\t\t */\n-\t\t\tmutex_lock(&sw->mac_list_lock);\n-\t\t\tlist_add(&fm_entry->list_entry, &sw->mac_list_head);\n-\t\t\tmutex_unlock(&sw->mac_list_lock);\n \n+\t\t\tlist_add(&fm_entry->list_entry, rule_head);\n \t\t\tr_iter = (struct ice_aqc_sw_rules_elem *)\n \t\t\t\t((u8 *)r_iter + s_rule_size);\n \t\t}\n \t}\n \n ice_add_mac_exit:\n-\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n+\tmutex_unlock(rule_lock);\n+\tif (s_rule)\n+\t\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n \treturn status;\n }\n \n-/**\n- * ice_find_vlan_entry\n- * @hw: pointer to the hardware structure\n- * @vlan_id: VLAN id to search for\n- *\n- * Helper function to search for a VLAN entry using a given VLAN id\n- * Returns pointer to the entry if found.\n- */\n-static struct ice_fltr_mgmt_list_entry *\n-ice_find_vlan_entry(struct ice_hw *hw, u16 vlan_id)\n-{\n-\tstruct ice_fltr_mgmt_list_entry *vlan_list_itr, *vlan_ret = NULL;\n-\tstruct ice_switch_info *sw = hw->switch_info;\n-\n-\tmutex_lock(&sw->vlan_list_lock);\n-\tlist_for_each_entry(vlan_list_itr, &sw->vlan_list_head, list_entry)\n-\t\tif (vlan_list_itr->fltr_info.l_data.vlan.vlan_id == vlan_id) {\n-\t\t\tvlan_ret = vlan_list_itr;\n-\t\t\tbreak;\n-\t\t}\n-\n-\tmutex_unlock(&sw->vlan_list_lock);\n-\treturn vlan_ret;\n-}\n-\n /**\n  * ice_add_vlan_internal - Add one VLAN based filter rule\n  * @hw: pointer to the hardware structure\n@@ -1252,20 +1435,22 @@ ice_find_vlan_entry(struct ice_hw *hw, u16 vlan_id)\n static enum ice_status\n ice_add_vlan_internal(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)\n {\n+\tstruct ice_switch_info *sw = hw->switch_info;\n \tstruct ice_fltr_info *new_fltr, *cur_fltr;\n \tstruct ice_fltr_mgmt_list_entry *v_list_itr;\n-\tu16 vlan_id;\n+\tstruct mutex *rule_lock; /* Lock to protect filter rule list */\n+\tenum ice_status status = 0;\n \n \tnew_fltr = &f_entry->fltr_info;\n \t/* VLAN id should only be 12 bits */\n \tif (new_fltr->l_data.vlan.vlan_id > ICE_MAX_VLAN_ID)\n \t\treturn ICE_ERR_PARAM;\n \n-\tvlan_id = new_fltr->l_data.vlan.vlan_id;\n-\tv_list_itr = ice_find_vlan_entry(hw, vlan_id);\n+\trule_lock = &sw->recp_list[ICE_SW_LKUP_VLAN].filt_rule_lock;\n+\tmutex_lock(rule_lock);\n+\tv_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN, new_fltr);\n \tif (!v_list_itr) {\n \t\tu16 vsi_id = ICE_VSI_INVAL_ID;\n-\t\tenum ice_status status;\n \t\tu16 vsi_list_id = 0;\n \n \t\tif (new_fltr->fltr_act == ICE_FWD_TO_VSI) {\n@@ -1279,26 +1464,33 @@ ice_add_vlan_internal(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)\n \t\t\t\t\t\t\t  &vsi_list_id,\n \t\t\t\t\t\t\t  lkup_type);\n \t\t\tif (status)\n-\t\t\t\treturn status;\n+\t\t\t\tgoto exit;\n \t\t\tnew_fltr->fltr_act = ICE_FWD_TO_VSI_LIST;\n \t\t\tnew_fltr->fwd_id.vsi_list_id = vsi_list_id;\n \t\t}\n \n \t\tstatus = ice_create_pkt_fwd_rule(hw, f_entry);\n \t\tif (!status && vsi_id != ICE_VSI_INVAL_ID) {\n-\t\t\tv_list_itr = ice_find_vlan_entry(hw, vlan_id);\n-\t\t\tif (!v_list_itr)\n-\t\t\t\treturn ICE_ERR_DOES_NOT_EXIST;\n+\t\t\tv_list_itr = ice_find_rule_entry(hw, ICE_SW_LKUP_VLAN,\n+\t\t\t\t\t\t\t new_fltr);\n+\t\t\tif (!v_list_itr) {\n+\t\t\t\tstatus = ICE_ERR_DOES_NOT_EXIST;\n+\t\t\t\tgoto exit;\n+\t\t\t}\n \t\t\tv_list_itr->vsi_list_info =\n \t\t\t\tice_create_vsi_list_map(hw, &vsi_id, 1,\n \t\t\t\t\t\t\tvsi_list_id);\n \t\t}\n \n-\t\treturn status;\n+\t\tgoto exit;\n \t}\n \n \tcur_fltr = &v_list_itr->fltr_info;\n-\treturn ice_handle_vsi_list_mgmt(hw, v_list_itr, cur_fltr, new_fltr);\n+\tstatus = ice_add_update_vsi_list(hw, v_list_itr, cur_fltr, new_fltr);\n+\n+exit:\n+\tmutex_unlock(rule_lock);\n+\treturn status;\n }\n \n /**\n@@ -1315,326 +1507,25 @@ ice_add_vlan(struct ice_hw *hw, struct list_head *v_list)\n \t\treturn ICE_ERR_PARAM;\n \n \tlist_for_each_entry(v_list_itr, v_list, list_entry) {\n-\t\tenum ice_status status;\n-\n \t\tif (v_list_itr->fltr_info.lkup_type != ICE_SW_LKUP_VLAN)\n \t\t\treturn ICE_ERR_PARAM;\n-\n-\t\tstatus = ice_add_vlan_internal(hw, v_list_itr);\n-\t\tif (status) {\n-\t\t\tv_list_itr->status = ICE_FLTR_STATUS_FW_FAIL;\n-\t\t\treturn status;\n-\t\t}\n-\t\tv_list_itr->status = ICE_FLTR_STATUS_FW_SUCCESS;\n+\t\tv_list_itr->fltr_info.flag = ICE_FLTR_TX;\n+\t\tv_list_itr->status = ice_add_vlan_internal(hw, v_list_itr);\n+\t\tif (v_list_itr->status)\n+\t\t\treturn v_list_itr->status;\n \t}\n \treturn 0;\n }\n \n /**\n- * ice_remove_vsi_list_rule\n- * @hw: pointer to the hardware structure\n- * @vsi_list_id: VSI list id generated as part of allocate resource\n- * @lkup_type: switch rule filter lookup type\n- */\n-static enum ice_status\n-ice_remove_vsi_list_rule(struct ice_hw *hw, u16 vsi_list_id,\n-\t\t\t enum ice_sw_lkup_type lkup_type)\n-{\n-\tstruct ice_aqc_sw_rules_elem *s_rule;\n-\tenum ice_status status;\n-\tu16 s_rule_size;\n-\n-\ts_rule_size = (u16)ICE_SW_RULE_VSI_LIST_SIZE(0);\n-\ts_rule = devm_kzalloc(ice_hw_to_dev(hw), s_rule_size, GFP_KERNEL);\n-\tif (!s_rule)\n-\t\treturn ICE_ERR_NO_MEMORY;\n-\n-\ts_rule->type = cpu_to_le16(ICE_AQC_SW_RULES_T_VSI_LIST_CLEAR);\n-\ts_rule->pdata.vsi_list.index = cpu_to_le16(vsi_list_id);\n-\t/* FW expects number of VSIs in vsi_list resource to be 0 for clear\n-\t * command. Since memory is zero'ed out during initialization, it's not\n-\t * necessary to explicitly initialize the variable to 0.\n-\t */\n-\n-\tstatus = ice_aq_sw_rules(hw, s_rule, s_rule_size, 1,\n-\t\t\t\t ice_aqc_opc_remove_sw_rules, NULL);\n-\tif (!status)\n-\t\t/* Free the vsi_list resource that we allocated */\n-\t\tstatus = ice_aq_alloc_free_vsi_list(hw, &vsi_list_id, lkup_type,\n-\t\t\t\t\t\t    ice_aqc_opc_free_res);\n-\n-\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n-\treturn status;\n-}\n-\n-/**\n- * ice_handle_rem_vsi_list_mgmt\n- * @hw: pointer to the hardware structure\n- * @vsi_id: ID of the VSI to remove\n- * @fm_list_itr: filter management entry for which the VSI list management\n- * needs to be done\n- */\n-static enum ice_status\n-ice_handle_rem_vsi_list_mgmt(struct ice_hw *hw, u16 vsi_id,\n-\t\t\t     struct ice_fltr_mgmt_list_entry *fm_list_itr)\n-{\n-\tstruct ice_switch_info *sw = hw->switch_info;\n-\tenum ice_status status = 0;\n-\tenum ice_sw_lkup_type lkup_type;\n-\tbool is_last_elem = true;\n-\tbool conv_list = false;\n-\tbool del_list = false;\n-\tu16 vsi_list_id;\n-\n-\tlkup_type = fm_list_itr->fltr_info.lkup_type;\n-\tvsi_list_id = fm_list_itr->fltr_info.fwd_id.vsi_list_id;\n-\n-\tif (fm_list_itr->vsi_count > 1) {\n-\t\tstatus = ice_update_vsi_list_rule(hw, &vsi_id, 1, vsi_list_id,\n-\t\t\t\t\t\t  true,\n-\t\t\t\t\t\t  ice_aqc_opc_update_sw_rules,\n-\t\t\t\t\t\t  lkup_type);\n-\t\tif (status)\n-\t\t\treturn status;\n-\t\tfm_list_itr->vsi_count--;\n-\t\tis_last_elem = false;\n-\t\tclear_bit(vsi_id, fm_list_itr->vsi_list_info->vsi_map);\n-\t}\n-\n-\t/* For non-VLAN rules that forward packets to a VSI list, convert them\n-\t * to forwarding packets to a VSI if there is only one VSI left in the\n-\t * list.  Unused lists are then removed.\n-\t * VLAN rules need to use VSI lists even with only one VSI.\n-\t */\n-\tif (fm_list_itr->fltr_info.fltr_act == ICE_FWD_TO_VSI_LIST) {\n-\t\tif (lkup_type == ICE_SW_LKUP_VLAN) {\n-\t\t\tdel_list = is_last_elem;\n-\t\t} else if (fm_list_itr->vsi_count == 1) {\n-\t\t\tconv_list = true;\n-\t\t\tdel_list = true;\n-\t\t}\n-\t}\n-\n-\tif (del_list) {\n-\t\t/* Remove the VSI list since it is no longer used */\n-\t\tstruct ice_vsi_list_map_info *vsi_list_info =\n-\t\t\tfm_list_itr->vsi_list_info;\n-\n-\t\tstatus = ice_remove_vsi_list_rule(hw, vsi_list_id, lkup_type);\n-\t\tif (status)\n-\t\t\treturn status;\n-\n-\t\tif (conv_list) {\n-\t\t\tu16 rem_vsi_id;\n-\n-\t\t\trem_vsi_id = find_first_bit(vsi_list_info->vsi_map,\n-\t\t\t\t\t\t    ICE_MAX_VSI);\n-\n-\t\t\t/* Error out when the expected last element is not in\n-\t\t\t * the VSI list map\n-\t\t\t */\n-\t\t\tif (rem_vsi_id == ICE_MAX_VSI)\n-\t\t\t\treturn ICE_ERR_OUT_OF_RANGE;\n-\n-\t\t\t/* Change the list entry action from VSI_LIST to VSI */\n-\t\t\tfm_list_itr->fltr_info.fltr_act = ICE_FWD_TO_VSI;\n-\t\t\tfm_list_itr->fltr_info.fwd_id.vsi_id = rem_vsi_id;\n-\t\t}\n-\n-\t\tlist_del(&vsi_list_info->list_entry);\n-\t\tdevm_kfree(ice_hw_to_dev(hw), vsi_list_info);\n-\t\tfm_list_itr->vsi_list_info = NULL;\n-\t}\n-\n-\tif (conv_list) {\n-\t\t/* Convert the rule's forward action to forwarding packets to\n-\t\t * a VSI\n-\t\t */\n-\t\tstruct ice_aqc_sw_rules_elem *s_rule;\n-\n-\t\ts_rule = devm_kzalloc(ice_hw_to_dev(hw),\n-\t\t\t\t      ICE_SW_RULE_RX_TX_ETH_HDR_SIZE,\n-\t\t\t\t      GFP_KERNEL);\n-\t\tif (!s_rule)\n-\t\t\treturn ICE_ERR_NO_MEMORY;\n-\n-\t\tice_fill_sw_rule(hw, &fm_list_itr->fltr_info, s_rule,\n-\t\t\t\t ice_aqc_opc_update_sw_rules);\n-\n-\t\ts_rule->pdata.lkup_tx_rx.index =\n-\t\t\tcpu_to_le16(fm_list_itr->fltr_info.fltr_rule_id);\n-\n-\t\tstatus = ice_aq_sw_rules(hw, s_rule,\n-\t\t\t\t\t ICE_SW_RULE_RX_TX_ETH_HDR_SIZE, 1,\n-\t\t\t\t\t ice_aqc_opc_update_sw_rules, NULL);\n-\t\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n-\t\tif (status)\n-\t\t\treturn status;\n-\t}\n-\n-\tif (is_last_elem) {\n-\t\t/* Remove the lookup rule */\n-\t\tstruct ice_aqc_sw_rules_elem *s_rule;\n-\n-\t\ts_rule = devm_kzalloc(ice_hw_to_dev(hw),\n-\t\t\t\t      ICE_SW_RULE_RX_TX_NO_HDR_SIZE,\n-\t\t\t\t      GFP_KERNEL);\n-\t\tif (!s_rule)\n-\t\t\treturn ICE_ERR_NO_MEMORY;\n-\n-\t\tice_fill_sw_rule(hw, &fm_list_itr->fltr_info, s_rule,\n-\t\t\t\t ice_aqc_opc_remove_sw_rules);\n-\n-\t\tstatus = ice_aq_sw_rules(hw, s_rule,\n-\t\t\t\t\t ICE_SW_RULE_RX_TX_NO_HDR_SIZE, 1,\n-\t\t\t\t\t ice_aqc_opc_remove_sw_rules, NULL);\n-\t\tif (status)\n-\t\t\treturn status;\n-\n-\t\t/* Remove a book keeping entry from the MAC address list */\n-\t\tmutex_lock(&sw->mac_list_lock);\n-\t\tlist_del(&fm_list_itr->list_entry);\n-\t\tmutex_unlock(&sw->mac_list_lock);\n-\t\tdevm_kfree(ice_hw_to_dev(hw), fm_list_itr);\n-\t\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n-\t}\n-\treturn status;\n-}\n-\n-/**\n- * ice_remove_mac_entry\n- * @hw: pointer to the hardware structure\n- * @f_entry: structure containing MAC forwarding information\n- */\n-static enum ice_status\n-ice_remove_mac_entry(struct ice_hw *hw, struct ice_fltr_list_entry *f_entry)\n-{\n-\tstruct ice_fltr_mgmt_list_entry *m_entry;\n-\tu16 vsi_id;\n-\tu8 *add;\n-\n-\tadd = &f_entry->fltr_info.l_data.mac.mac_addr[0];\n-\n-\tm_entry = ice_find_mac_entry(hw, add);\n-\tif (!m_entry)\n-\t\treturn ICE_ERR_PARAM;\n-\n-\tvsi_id = f_entry->fltr_info.fwd_id.vsi_id;\n-\treturn ice_handle_rem_vsi_list_mgmt(hw, vsi_id, m_entry);\n-}\n-\n-/**\n- * ice_remove_mac - remove a MAC address based filter rule\n- * @hw: pointer to the hardware structure\n- * @m_list: list of MAC addresses and forwarding information\n- *\n- * This function removes either a MAC filter rule or a specific VSI from a\n- * VSI list for a multicast MAC address.\n- *\n- * Returns ICE_ERR_DOES_NOT_EXIST if a given entry was not added by\n- * ice_add_mac. Caller should be aware that this call will only work if all\n- * the entries passed into m_list were added previously. It will not attempt to\n- * do a partial remove of entries that were found.\n- */\n-enum ice_status\n-ice_remove_mac(struct ice_hw *hw, struct list_head *m_list)\n-{\n-\tstruct ice_aqc_sw_rules_elem *s_rule, *r_iter;\n-\tu8 s_rule_size = ICE_SW_RULE_RX_TX_NO_HDR_SIZE;\n-\tstruct ice_switch_info *sw = hw->switch_info;\n-\tstruct ice_fltr_mgmt_list_entry *m_entry;\n-\tstruct ice_fltr_list_entry *m_list_itr;\n-\tu16 elem_sent, total_elem_left;\n-\tenum ice_status status = 0;\n-\tu16 num_unicast = 0;\n-\n-\tif (!m_list)\n-\t\treturn ICE_ERR_PARAM;\n-\n-\tlist_for_each_entry(m_list_itr, m_list, list_entry) {\n-\t\tu8 *addr = m_list_itr->fltr_info.l_data.mac.mac_addr;\n-\n-\t\tif (is_unicast_ether_addr(addr) && !hw->ucast_shared)\n-\t\t\tnum_unicast++;\n-\t\telse if (is_multicast_ether_addr(addr) ||\n-\t\t\t (is_unicast_ether_addr(addr) && hw->ucast_shared))\n-\t\t\tice_remove_mac_entry(hw, m_list_itr);\n-\t}\n-\n-\t/* Exit if no unicast addresses found. Multicast switch rules\n-\t * were added individually\n-\t */\n-\tif (!num_unicast)\n-\t\treturn 0;\n-\n-\t/* Allocate switch rule buffer for the bulk update for unicast */\n-\ts_rule = devm_kcalloc(ice_hw_to_dev(hw), num_unicast, s_rule_size,\n-\t\t\t      GFP_KERNEL);\n-\tif (!s_rule)\n-\t\treturn ICE_ERR_NO_MEMORY;\n-\n-\tr_iter = s_rule;\n-\tlist_for_each_entry(m_list_itr, m_list, list_entry) {\n-\t\tu8 *addr = m_list_itr->fltr_info.l_data.mac.mac_addr;\n-\n-\t\tif (is_unicast_ether_addr(addr)) {\n-\t\t\tm_entry = ice_find_mac_entry(hw, addr);\n-\t\t\tif (!m_entry) {\n-\t\t\t\tstatus = ICE_ERR_DOES_NOT_EXIST;\n-\t\t\t\tgoto ice_remove_mac_exit;\n-\t\t\t}\n-\n-\t\t\tice_fill_sw_rule(hw, &m_entry->fltr_info,\n-\t\t\t\t\t r_iter, ice_aqc_opc_remove_sw_rules);\n-\t\t\tr_iter = (struct ice_aqc_sw_rules_elem *)\n-\t\t\t\t((u8 *)r_iter + s_rule_size);\n-\t\t}\n-\t}\n-\n-\t/* Call AQ bulk switch rule update for all unicast addresses */\n-\tr_iter = s_rule;\n-\t/* Call AQ switch rule in AQ_MAX chunk */\n-\tfor (total_elem_left = num_unicast; total_elem_left > 0;\n-\t     total_elem_left -= elem_sent) {\n-\t\tstruct ice_aqc_sw_rules_elem *entry = r_iter;\n-\n-\t\telem_sent = min(total_elem_left,\n-\t\t\t\t(u16)(ICE_AQ_MAX_BUF_LEN / s_rule_size));\n-\t\tstatus = ice_aq_sw_rules(hw, entry, elem_sent * s_rule_size,\n-\t\t\t\t\t elem_sent, ice_aqc_opc_remove_sw_rules,\n-\t\t\t\t\t NULL);\n-\t\tif (status)\n-\t\t\tbreak;\n-\t\tr_iter = (struct ice_aqc_sw_rules_elem *)\n-\t\t\t((u8 *)r_iter + s_rule_size);\n-\t}\n-\n-\tlist_for_each_entry(m_list_itr, m_list, list_entry) {\n-\t\tu8 *addr = m_list_itr->fltr_info.l_data.mac.mac_addr;\n-\n-\t\tif (is_unicast_ether_addr(addr)) {\n-\t\t\tm_entry = ice_find_mac_entry(hw, addr);\n-\t\t\tif (!m_entry)\n-\t\t\t\treturn ICE_ERR_OUT_OF_RANGE;\n-\t\t\tmutex_lock(&sw->mac_list_lock);\n-\t\t\tlist_del(&m_entry->list_entry);\n-\t\t\tmutex_unlock(&sw->mac_list_lock);\n-\t\t\tdevm_kfree(ice_hw_to_dev(hw), m_entry);\n-\t\t}\n-\t}\n-\n-ice_remove_mac_exit:\n-\tdevm_kfree(ice_hw_to_dev(hw), s_rule);\n-\treturn status;\n-}\n-\n-/**\n- * ice_cfg_dflt_vsi - add filter rule to set/unset given VSI as default\n- * VSI for the switch (represented by swid)\n+ * ice_cfg_dflt_vsi - change state of VSI to set/clear default\n  * @hw: pointer to the hardware structure\n  * @vsi_id: number of VSI to set as default\n  * @set: true to add the above mentioned switch rule, false to remove it\n  * @direction: ICE_FLTR_RX or ICE_FLTR_TX\n+ *\n+ * add filter rule to set/unset given VSI as default VSI for the switch\n+ * (represented by swid)\n  */\n enum ice_status\n ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_id, bool set, u8 direction)\n@@ -1706,26 +1597,38 @@ ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_id, bool set, u8 direction)\n }\n \n /**\n- * ice_remove_vlan_internal - Remove one VLAN based filter rule\n+ * ice_remove_mac - remove a MAC address based filter rule\n  * @hw: pointer to the hardware structure\n- * @f_entry: filter entry containing one VLAN information\n+ * @m_list: list of MAC addresses and forwarding information\n+ *\n+ * This function removes either a MAC filter rule or a specific VSI from a\n+ * VSI list for a multicast MAC address.\n+ *\n+ * Returns ICE_ERR_DOES_NOT_EXIST if a given entry was not added by\n+ * ice_add_mac. Caller should be aware that this call will only work if all\n+ * the entries passed into m_list were added previously. It will not attempt to\n+ * do a partial remove of entries that were found.\n  */\n-static enum ice_status\n-ice_remove_vlan_internal(struct ice_hw *hw,\n-\t\t\t struct ice_fltr_list_entry *f_entry)\n+enum ice_status\n+ice_remove_mac(struct ice_hw *hw, struct list_head *m_list)\n {\n-\tstruct ice_fltr_info *new_fltr;\n-\tstruct ice_fltr_mgmt_list_entry *v_list_elem;\n-\tu16 vsi_id;\n-\n-\tnew_fltr = &f_entry->fltr_info;\n+\tstruct ice_fltr_list_entry *list_itr;\n \n-\tv_list_elem = ice_find_vlan_entry(hw, new_fltr->l_data.vlan.vlan_id);\n-\tif (!v_list_elem)\n+\tif (!m_list)\n \t\treturn ICE_ERR_PARAM;\n \n-\tvsi_id = f_entry->fltr_info.fwd_id.vsi_id;\n-\treturn ice_handle_rem_vsi_list_mgmt(hw, vsi_id, v_list_elem);\n+\tlist_for_each_entry(list_itr, m_list, list_entry) {\n+\t\tenum ice_sw_lkup_type l_type = list_itr->fltr_info.lkup_type;\n+\n+\t\tif (l_type != ICE_SW_LKUP_MAC)\n+\t\t\treturn ICE_ERR_PARAM;\n+\t\tlist_itr->status = ice_remove_rule_internal(hw,\n+\t\t\t\t\t\t\t    ICE_SW_LKUP_MAC,\n+\t\t\t\t\t\t\t    list_itr);\n+\t\tif (list_itr->status)\n+\t\t\treturn list_itr->status;\n+\t}\n+\treturn 0;\n }\n \n /**\n@@ -1737,20 +1640,78 @@ enum ice_status\n ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list)\n {\n \tstruct ice_fltr_list_entry *v_list_itr;\n-\tenum ice_status status = 0;\n \n \tif (!v_list || !hw)\n \t\treturn ICE_ERR_PARAM;\n \n \tlist_for_each_entry(v_list_itr, v_list, list_entry) {\n-\t\tstatus = ice_remove_vlan_internal(hw, v_list_itr);\n-\t\tif (status) {\n-\t\t\tv_list_itr->status = ICE_FLTR_STATUS_FW_FAIL;\n-\t\t\treturn status;\n-\t\t}\n-\t\tv_list_itr->status = ICE_FLTR_STATUS_FW_SUCCESS;\n+\t\tenum ice_sw_lkup_type l_type = v_list_itr->fltr_info.lkup_type;\n+\n+\t\tif (l_type != ICE_SW_LKUP_VLAN)\n+\t\t\treturn ICE_ERR_PARAM;\n+\t\tv_list_itr->status = ice_remove_rule_internal(hw,\n+\t\t\t\t\t\t\t      ICE_SW_LKUP_VLAN,\n+\t\t\t\t\t\t\t      v_list_itr);\n+\t\tif (v_list_itr->status)\n+\t\t\treturn v_list_itr->status;\n \t}\n-\treturn status;\n+\treturn 0;\n+}\n+\n+/**\n+ * ice_vsi_uses_fltr - Determine if given VSI uses specified filter\n+ * @fm_entry: filter entry to inspect\n+ * @vsi_id: ID of VSI to compare with filter info\n+ */\n+static bool\n+ice_vsi_uses_fltr(struct ice_fltr_mgmt_list_entry *fm_entry, u16 vsi_id)\n+{\n+\treturn ((fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI &&\n+\t\t fm_entry->fltr_info.fwd_id.vsi_id == vsi_id) ||\n+\t\t(fm_entry->fltr_info.fltr_act == ICE_FWD_TO_VSI_LIST &&\n+\t\t (test_bit(vsi_id, fm_entry->vsi_list_info->vsi_map))));\n+}\n+\n+/**\n+ * ice_add_entry_to_vsi_fltr_list - Add copy of fltr_list_entry to remove list\n+ * @hw: pointer to the hardware structure\n+ * @vsi_id: ID of VSI to remove filters from\n+ * @vsi_list_head: pointer to the list to add entry to\n+ * @fi: pointer to fltr_info of filter entry to copy & add\n+ *\n+ * Helper function, used when creating a list of filters to remove from\n+ * a specific VSI. The entry added to vsi_list_head is a COPY of the\n+ * original filter entry, with the exception of fltr_info.fltr_act and\n+ * fltr_info.fwd_id fields. These are set such that later logic can\n+ * extract which VSI to remove the fltr from, and pass on that information.\n+ */\n+static enum ice_status\n+ice_add_entry_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_id,\n+\t\t\t       struct list_head *vsi_list_head,\n+\t\t\t       struct ice_fltr_info *fi)\n+{\n+\tstruct ice_fltr_list_entry *tmp;\n+\n+\t/* this memory is freed up in the caller function\n+\t * once filters for this VSI are removed\n+\t */\n+\ttmp = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*tmp), GFP_KERNEL);\n+\tif (!tmp)\n+\t\treturn ICE_ERR_NO_MEMORY;\n+\n+\ttmp->fltr_info = *fi;\n+\n+\t/* Overwrite these fields to indicate which VSI to remove filter from,\n+\t * so find and remove logic can extract the information from the\n+\t * list entries. Note that original entries will still have proper\n+\t * values.\n+\t */\n+\ttmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;\n+\ttmp->fltr_info.fwd_id.vsi_id = vsi_id;\n+\n+\tlist_add(&tmp->list_entry, vsi_list_head);\n+\n+\treturn 0;\n }\n \n /**\n@@ -1759,6 +1720,12 @@ ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list)\n  * @vsi_id: ID of VSI to remove filters from\n  * @lkup_list_head: pointer to the list that has certain lookup type filters\n  * @vsi_list_head: pointer to the list pertaining to VSI with vsi_id\n+ *\n+ * Locates all filters in lkup_list_head that are used by the given VSI,\n+ * and adds COPIES of those entries to vsi_list_head (intended to be used\n+ * to remove the listed filters).\n+ * Note that this means all entries in vsi_list_head must be explicitly\n+ * deallocated by the caller when done with list.\n  */\n static enum ice_status\n ice_add_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_id,\n@@ -1766,46 +1733,25 @@ ice_add_to_vsi_fltr_list(struct ice_hw *hw, u16 vsi_id,\n \t\t\t struct list_head *vsi_list_head)\n {\n \tstruct ice_fltr_mgmt_list_entry *fm_entry;\n+\tenum ice_status status = 0;\n \n \t/* check to make sure VSI id is valid and within boundary */\n-\tif (vsi_id >=\n-\t    (sizeof(fm_entry->vsi_list_info->vsi_map) * BITS_PER_BYTE - 1))\n+\tif (vsi_id >= ICE_MAX_VSI)\n \t\treturn ICE_ERR_PARAM;\n \n \tlist_for_each_entry(fm_entry, lkup_list_head, list_entry) {\n \t\tstruct ice_fltr_info *fi;\n \n \t\tfi = &fm_entry->fltr_info;\n-\t\tif ((fi->fltr_act == ICE_FWD_TO_VSI &&\n-\t\t     fi->fwd_id.vsi_id == vsi_id) ||\n-\t\t    (fi->fltr_act == ICE_FWD_TO_VSI_LIST &&\n-\t\t     (test_bit(vsi_id, fm_entry->vsi_list_info->vsi_map)))) {\n-\t\t\tstruct ice_fltr_list_entry *tmp;\n-\n-\t\t\t/* this memory is freed up in the caller function\n-\t\t\t * ice_remove_vsi_lkup_fltr() once filters for\n-\t\t\t * this VSI are removed\n-\t\t\t */\n-\t\t\ttmp = devm_kzalloc(ice_hw_to_dev(hw), sizeof(*tmp),\n-\t\t\t\t\t   GFP_KERNEL);\n-\t\t\tif (!tmp)\n-\t\t\t\treturn ICE_ERR_NO_MEMORY;\n-\n-\t\t\tmemcpy(&tmp->fltr_info, fi, sizeof(*fi));\n-\n-\t\t\t/* Expected below fields to be set to ICE_FWD_TO_VSI and\n-\t\t\t * the particular VSI id since we are only removing this\n-\t\t\t * one VSI\n-\t\t\t */\n-\t\t\tif (fi->fltr_act == ICE_FWD_TO_VSI_LIST) {\n-\t\t\t\ttmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;\n-\t\t\t\ttmp->fltr_info.fwd_id.vsi_id = vsi_id;\n-\t\t\t}\n+\t\tif (!ice_vsi_uses_fltr(fm_entry, vsi_id))\n+\t\t\tcontinue;\n \n-\t\t\tlist_add(&tmp->list_entry, vsi_list_head);\n-\t\t}\n+\t\tstatus = ice_add_entry_to_vsi_fltr_list(hw, vsi_id,\n+\t\t\t\t\t\t\tvsi_list_head, fi);\n+\t\tif (status)\n+\t\t\treturn status;\n \t}\n-\treturn 0;\n+\treturn status;\n }\n \n /**\n@@ -1821,46 +1767,40 @@ ice_remove_vsi_lkup_fltr(struct ice_hw *hw, u16 vsi_id,\n \tstruct ice_switch_info *sw = hw->switch_info;\n \tstruct ice_fltr_list_entry *fm_entry;\n \tstruct list_head remove_list_head;\n+\tstruct list_head *rule_head;\n \tstruct ice_fltr_list_entry *tmp;\n+\tstruct mutex *rule_lock;\t/* Lock to protect filter rule list */\n \tenum ice_status status;\n \n \tINIT_LIST_HEAD(&remove_list_head);\n+\trule_lock = &sw->recp_list[lkup].filt_rule_lock;\n+\trule_head = &sw->recp_list[lkup].filt_rules;\n+\tmutex_lock(rule_lock);\n+\tstatus = ice_add_to_vsi_fltr_list(hw, vsi_id, rule_head,\n+\t\t\t\t\t  &remove_list_head);\n+\tmutex_unlock(rule_lock);\n+\tif (status)\n+\t\treturn;\n+\n \tswitch (lkup) {\n \tcase ICE_SW_LKUP_MAC:\n-\t\tmutex_lock(&sw->mac_list_lock);\n-\t\tstatus = ice_add_to_vsi_fltr_list(hw, vsi_id,\n-\t\t\t\t\t\t  &sw->mac_list_head,\n-\t\t\t\t\t\t  &remove_list_head);\n-\t\tmutex_unlock(&sw->mac_list_lock);\n-\t\tif (!status) {\n-\t\t\tice_remove_mac(hw, &remove_list_head);\n-\t\t\tgoto free_fltr_list;\n-\t\t}\n+\t\tice_remove_mac(hw, &remove_list_head);\n \t\tbreak;\n \tcase ICE_SW_LKUP_VLAN:\n-\t\tmutex_lock(&sw->vlan_list_lock);\n-\t\tstatus = ice_add_to_vsi_fltr_list(hw, vsi_id,\n-\t\t\t\t\t\t  &sw->vlan_list_head,\n-\t\t\t\t\t\t  &remove_list_head);\n-\t\tmutex_unlock(&sw->vlan_list_lock);\n-\t\tif (!status) {\n-\t\t\tice_remove_vlan(hw, &remove_list_head);\n-\t\t\tgoto free_fltr_list;\n-\t\t}\n+\t\tice_remove_vlan(hw, &remove_list_head);\n \t\tbreak;\n \tcase ICE_SW_LKUP_MAC_VLAN:\n \tcase ICE_SW_LKUP_ETHERTYPE:\n \tcase ICE_SW_LKUP_ETHERTYPE_MAC:\n \tcase ICE_SW_LKUP_PROMISC:\n-\tcase ICE_SW_LKUP_PROMISC_VLAN:\n \tcase ICE_SW_LKUP_DFLT:\n-\t\tice_debug(hw, ICE_DBG_SW,\n-\t\t\t  \"Remove filters for this lookup type hasn't been implemented yet\\n\");\n+\tcase ICE_SW_LKUP_PROMISC_VLAN:\n+\tcase ICE_SW_LKUP_LAST:\n+\tdefault:\n+\t\tice_debug(hw, ICE_DBG_SW, \"Unsupported lookup type %d\\n\", lkup);\n \t\tbreak;\n \t}\n \n-\treturn;\n-free_fltr_list:\n \tlist_for_each_entry_safe(fm_entry, tmp, &remove_list_head, list_entry) {\n \t\tlist_del(&fm_entry->list_entry);\n \t\tdevm_kfree(ice_hw_to_dev(hw), fm_entry);\ndiff --git a/drivers/net/ethernet/intel/ice/ice_switch.h b/drivers/net/ethernet/intel/ice/ice_switch.h\nindex 9b8ec128ee31..09a3b6d6541a 100644\n--- a/drivers/net/ethernet/intel/ice/ice_switch.h\n+++ b/drivers/net/ethernet/intel/ice/ice_switch.h\n@@ -39,6 +39,7 @@ enum ice_sw_lkup_type {\n \tICE_SW_LKUP_DFLT = 5,\n \tICE_SW_LKUP_ETHERTYPE_MAC = 8,\n \tICE_SW_LKUP_PROMISC_VLAN = 9,\n+\tICE_SW_LKUP_LAST\n };\n \n struct ice_fltr_info {\n@@ -98,6 +99,31 @@ struct ice_fltr_info {\n \tu8 lan_en;\t/* Indicate if packet can be forwarded to the uplink */\n };\n \n+struct ice_sw_recipe {\n+\tstruct list_head l_entry;\n+\n+\t/* To protect modification of filt_rule list\n+\t * defined below\n+\t */\n+\tstruct mutex filt_rule_lock;\n+\n+\t/* List of type ice_fltr_mgmt_list_entry */\n+\tstruct list_head filt_rules;\n+\n+\t/* linked list of type recipe_list_entry */\n+\tstruct list_head rg_list;\n+\t/* linked list of type ice_sw_fv_list_entry*/\n+\tstruct list_head fv_list;\n+\tstruct ice_aqc_recipe_data_elem *r_buf;\n+\tu8 recp_count;\n+\tu8 root_rid;\n+\tu8 num_profs;\n+\tu8 *prof_ids;\n+\n+\t/* recipe bitmap: what all recipes makes this recipe */\n+\tDECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES);\n+};\n+\n /* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list id */\n struct ice_vsi_list_map_info {\n \tstruct list_head list_entry;\n@@ -105,15 +131,9 @@ struct ice_vsi_list_map_info {\n \tu16 vsi_list_id;\n };\n \n-enum ice_sw_fltr_status {\n-\tICE_FLTR_STATUS_NEW = 0,\n-\tICE_FLTR_STATUS_FW_SUCCESS,\n-\tICE_FLTR_STATUS_FW_FAIL,\n-};\n-\n struct ice_fltr_list_entry {\n \tstruct list_head list_entry;\n-\tenum ice_sw_fltr_status status;\n+\tenum ice_status status;\n \tstruct ice_fltr_info fltr_info;\n };\n \n@@ -157,5 +177,6 @@ enum ice_status ice_add_vlan(struct ice_hw *hw, struct list_head *m_list);\n enum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list);\n enum ice_status\n ice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_id, bool set, u8 direction);\n+enum ice_status ice_init_def_sw_recp(struct ice_hw *hw);\n \n #endif /* _ICE_SWITCH_H_ */\ndiff --git a/drivers/net/ethernet/intel/ice/ice_type.h b/drivers/net/ethernet/intel/ice/ice_type.h\nindex adfe131bd3f3..473d82fdb570 100644\n--- a/drivers/net/ethernet/intel/ice/ice_type.h\n+++ b/drivers/net/ethernet/intel/ice/ice_type.h\n@@ -253,19 +253,8 @@ struct ice_port_info {\n };\n \n struct ice_switch_info {\n-\t/* Switch VSI lists to MAC/VLAN translation */\n-\tstruct mutex mac_list_lock;\t\t/* protect MAC list */\n-\tstruct list_head mac_list_head;\n-\tstruct mutex vlan_list_lock;\t\t/* protect VLAN list */\n-\tstruct list_head vlan_list_head;\n-\tstruct mutex eth_m_list_lock;\t/* protect ethtype list */\n-\tstruct list_head eth_m_list_head;\n-\tstruct mutex promisc_list_lock;\t/* protect promisc mode list */\n-\tstruct list_head promisc_list_head;\n-\tstruct mutex mac_vlan_list_lock;\t/* protect MAC-VLAN list */\n-\tstruct list_head mac_vlan_list_head;\n-\n \tstruct list_head vsi_list_map_head;\n+\tstruct ice_sw_recipe *recp_list;\n };\n \n /* Port hardware description */\n",
    "prefixes": [
        "v3",
        "06/15"
    ]
}