18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* Copyright (c) 2018, Intel Corporation. */ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#ifndef _ICE_SWITCH_H_ 58c2ecf20Sopenharmony_ci#define _ICE_SWITCH_H_ 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#include "ice_common.h" 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define ICE_SW_CFG_MAX_BUF_LEN 2048 108c2ecf20Sopenharmony_ci#define ICE_DFLT_VSI_INVAL 0xff 118c2ecf20Sopenharmony_ci#define ICE_FLTR_RX BIT(0) 128c2ecf20Sopenharmony_ci#define ICE_FLTR_TX BIT(1) 138c2ecf20Sopenharmony_ci#define ICE_FLTR_TX_RX (ICE_FLTR_RX | ICE_FLTR_TX) 148c2ecf20Sopenharmony_ci#define ICE_VSI_INVAL_ID 0xffff 158c2ecf20Sopenharmony_ci#define ICE_INVAL_Q_HANDLE 0xFFFF 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* VSI context structure for add/get/update/free operations */ 188c2ecf20Sopenharmony_cistruct ice_vsi_ctx { 198c2ecf20Sopenharmony_ci u16 vsi_num; 208c2ecf20Sopenharmony_ci u16 vsis_allocd; 218c2ecf20Sopenharmony_ci u16 vsis_unallocated; 228c2ecf20Sopenharmony_ci u16 flags; 238c2ecf20Sopenharmony_ci struct ice_aqc_vsi_props info; 248c2ecf20Sopenharmony_ci struct ice_sched_vsi_info sched; 258c2ecf20Sopenharmony_ci u8 alloc_from_pool; 268c2ecf20Sopenharmony_ci u8 vf_num; 278c2ecf20Sopenharmony_ci u16 num_lan_q_entries[ICE_MAX_TRAFFIC_CLASS]; 288c2ecf20Sopenharmony_ci struct ice_q_ctx *lan_q_ctx[ICE_MAX_TRAFFIC_CLASS]; 298c2ecf20Sopenharmony_ci}; 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_cienum ice_sw_fwd_act_type { 328c2ecf20Sopenharmony_ci ICE_FWD_TO_VSI = 0, 338c2ecf20Sopenharmony_ci ICE_FWD_TO_VSI_LIST, /* Do not use this when adding filter */ 348c2ecf20Sopenharmony_ci ICE_FWD_TO_Q, 358c2ecf20Sopenharmony_ci ICE_FWD_TO_QGRP, 368c2ecf20Sopenharmony_ci ICE_DROP_PACKET, 378c2ecf20Sopenharmony_ci ICE_INVAL_ACT 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_ci/* Switch recipe ID enum values are specific to hardware */ 418c2ecf20Sopenharmony_cienum ice_sw_lkup_type { 428c2ecf20Sopenharmony_ci ICE_SW_LKUP_ETHERTYPE = 0, 438c2ecf20Sopenharmony_ci ICE_SW_LKUP_MAC = 1, 448c2ecf20Sopenharmony_ci ICE_SW_LKUP_MAC_VLAN = 2, 458c2ecf20Sopenharmony_ci ICE_SW_LKUP_PROMISC = 3, 468c2ecf20Sopenharmony_ci ICE_SW_LKUP_VLAN = 4, 478c2ecf20Sopenharmony_ci ICE_SW_LKUP_DFLT = 5, 488c2ecf20Sopenharmony_ci ICE_SW_LKUP_ETHERTYPE_MAC = 8, 498c2ecf20Sopenharmony_ci ICE_SW_LKUP_PROMISC_VLAN = 9, 508c2ecf20Sopenharmony_ci ICE_SW_LKUP_LAST 518c2ecf20Sopenharmony_ci}; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci/* type of filter src ID */ 548c2ecf20Sopenharmony_cienum ice_src_id { 558c2ecf20Sopenharmony_ci ICE_SRC_ID_UNKNOWN = 0, 568c2ecf20Sopenharmony_ci ICE_SRC_ID_VSI, 578c2ecf20Sopenharmony_ci ICE_SRC_ID_QUEUE, 588c2ecf20Sopenharmony_ci ICE_SRC_ID_LPORT, 598c2ecf20Sopenharmony_ci}; 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_cistruct ice_fltr_info { 628c2ecf20Sopenharmony_ci /* Look up information: how to look up packet */ 638c2ecf20Sopenharmony_ci enum ice_sw_lkup_type lkup_type; 648c2ecf20Sopenharmony_ci /* Forward action: filter action to do after lookup */ 658c2ecf20Sopenharmony_ci enum ice_sw_fwd_act_type fltr_act; 668c2ecf20Sopenharmony_ci /* rule ID returned by firmware once filter rule is created */ 678c2ecf20Sopenharmony_ci u16 fltr_rule_id; 688c2ecf20Sopenharmony_ci u16 flag; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci /* Source VSI for LOOKUP_TX or source port for LOOKUP_RX */ 718c2ecf20Sopenharmony_ci u16 src; 728c2ecf20Sopenharmony_ci enum ice_src_id src_id; 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci union { 758c2ecf20Sopenharmony_ci struct { 768c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 778c2ecf20Sopenharmony_ci } mac; 788c2ecf20Sopenharmony_ci struct { 798c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 808c2ecf20Sopenharmony_ci u16 vlan_id; 818c2ecf20Sopenharmony_ci } mac_vlan; 828c2ecf20Sopenharmony_ci struct { 838c2ecf20Sopenharmony_ci u16 vlan_id; 848c2ecf20Sopenharmony_ci } vlan; 858c2ecf20Sopenharmony_ci /* Set lkup_type as ICE_SW_LKUP_ETHERTYPE 868c2ecf20Sopenharmony_ci * if just using ethertype as filter. Set lkup_type as 878c2ecf20Sopenharmony_ci * ICE_SW_LKUP_ETHERTYPE_MAC if MAC also needs to be 888c2ecf20Sopenharmony_ci * passed in as filter. 898c2ecf20Sopenharmony_ci */ 908c2ecf20Sopenharmony_ci struct { 918c2ecf20Sopenharmony_ci u16 ethertype; 928c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; /* optional */ 938c2ecf20Sopenharmony_ci } ethertype_mac; 948c2ecf20Sopenharmony_ci } l_data; /* Make sure to zero out the memory of l_data before using 958c2ecf20Sopenharmony_ci * it or only set the data associated with lookup match 968c2ecf20Sopenharmony_ci * rest everything should be zero 978c2ecf20Sopenharmony_ci */ 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci /* Depending on filter action */ 1008c2ecf20Sopenharmony_ci union { 1018c2ecf20Sopenharmony_ci /* queue ID in case of ICE_FWD_TO_Q and starting 1028c2ecf20Sopenharmony_ci * queue ID in case of ICE_FWD_TO_QGRP. 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ci u16 q_id:11; 1058c2ecf20Sopenharmony_ci u16 hw_vsi_id:10; 1068c2ecf20Sopenharmony_ci u16 vsi_list_id:10; 1078c2ecf20Sopenharmony_ci } fwd_id; 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci /* Sw VSI handle */ 1108c2ecf20Sopenharmony_ci u16 vsi_handle; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci /* Set to num_queues if action is ICE_FWD_TO_QGRP. This field 1138c2ecf20Sopenharmony_ci * determines the range of queues the packet needs to be forwarded to. 1148c2ecf20Sopenharmony_ci * Note that qgrp_size must be set to a power of 2. 1158c2ecf20Sopenharmony_ci */ 1168c2ecf20Sopenharmony_ci u8 qgrp_size; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci /* Rule creations populate these indicators basing on the switch type */ 1198c2ecf20Sopenharmony_ci u8 lb_en; /* Indicate if packet can be looped back */ 1208c2ecf20Sopenharmony_ci u8 lan_en; /* Indicate if packet can be forwarded to the uplink */ 1218c2ecf20Sopenharmony_ci}; 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cistruct ice_sw_recipe { 1248c2ecf20Sopenharmony_ci struct list_head l_entry; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci /* To protect modification of filt_rule list 1278c2ecf20Sopenharmony_ci * defined below 1288c2ecf20Sopenharmony_ci */ 1298c2ecf20Sopenharmony_ci struct mutex filt_rule_lock; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci /* List of type ice_fltr_mgmt_list_entry */ 1328c2ecf20Sopenharmony_ci struct list_head filt_rules; 1338c2ecf20Sopenharmony_ci struct list_head filt_replay_rules; 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_ci /* linked list of type recipe_list_entry */ 1368c2ecf20Sopenharmony_ci struct list_head rg_list; 1378c2ecf20Sopenharmony_ci /* linked list of type ice_sw_fv_list_entry*/ 1388c2ecf20Sopenharmony_ci struct list_head fv_list; 1398c2ecf20Sopenharmony_ci struct ice_aqc_recipe_data_elem *r_buf; 1408c2ecf20Sopenharmony_ci u8 recp_count; 1418c2ecf20Sopenharmony_ci u8 root_rid; 1428c2ecf20Sopenharmony_ci u8 num_profs; 1438c2ecf20Sopenharmony_ci u8 *prof_ids; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci /* recipe bitmap: what all recipes makes this recipe */ 1468c2ecf20Sopenharmony_ci DECLARE_BITMAP(r_bitmap, ICE_MAX_NUM_RECIPES); 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* Bookkeeping structure to hold bitmap of VSIs corresponding to VSI list ID */ 1508c2ecf20Sopenharmony_cistruct ice_vsi_list_map_info { 1518c2ecf20Sopenharmony_ci struct list_head list_entry; 1528c2ecf20Sopenharmony_ci DECLARE_BITMAP(vsi_map, ICE_MAX_VSI); 1538c2ecf20Sopenharmony_ci u16 vsi_list_id; 1548c2ecf20Sopenharmony_ci /* counter to track how many rules are reusing this VSI list */ 1558c2ecf20Sopenharmony_ci u16 ref_cnt; 1568c2ecf20Sopenharmony_ci}; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_cistruct ice_fltr_list_entry { 1598c2ecf20Sopenharmony_ci struct list_head list_entry; 1608c2ecf20Sopenharmony_ci enum ice_status status; 1618c2ecf20Sopenharmony_ci struct ice_fltr_info fltr_info; 1628c2ecf20Sopenharmony_ci}; 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci/* This defines an entry in the list that maintains MAC or VLAN membership 1658c2ecf20Sopenharmony_ci * to HW list mapping, since multiple VSIs can subscribe to the same MAC or 1668c2ecf20Sopenharmony_ci * VLAN. As an optimization the VSI list should be created only when a 1678c2ecf20Sopenharmony_ci * second VSI becomes a subscriber to the same MAC address. VSI lists are always 1688c2ecf20Sopenharmony_ci * used for VLAN membership. 1698c2ecf20Sopenharmony_ci */ 1708c2ecf20Sopenharmony_cistruct ice_fltr_mgmt_list_entry { 1718c2ecf20Sopenharmony_ci /* back pointer to VSI list ID to VSI list mapping */ 1728c2ecf20Sopenharmony_ci struct ice_vsi_list_map_info *vsi_list_info; 1738c2ecf20Sopenharmony_ci u16 vsi_count; 1748c2ecf20Sopenharmony_ci#define ICE_INVAL_LG_ACT_INDEX 0xffff 1758c2ecf20Sopenharmony_ci u16 lg_act_idx; 1768c2ecf20Sopenharmony_ci#define ICE_INVAL_SW_MARKER_ID 0xffff 1778c2ecf20Sopenharmony_ci u16 sw_marker_id; 1788c2ecf20Sopenharmony_ci struct list_head list_entry; 1798c2ecf20Sopenharmony_ci struct ice_fltr_info fltr_info; 1808c2ecf20Sopenharmony_ci#define ICE_INVAL_COUNTER_ID 0xff 1818c2ecf20Sopenharmony_ci u8 counter_index; 1828c2ecf20Sopenharmony_ci}; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cienum ice_promisc_flags { 1858c2ecf20Sopenharmony_ci ICE_PROMISC_UCAST_RX = 0x1, 1868c2ecf20Sopenharmony_ci ICE_PROMISC_UCAST_TX = 0x2, 1878c2ecf20Sopenharmony_ci ICE_PROMISC_MCAST_RX = 0x4, 1888c2ecf20Sopenharmony_ci ICE_PROMISC_MCAST_TX = 0x8, 1898c2ecf20Sopenharmony_ci ICE_PROMISC_BCAST_RX = 0x10, 1908c2ecf20Sopenharmony_ci ICE_PROMISC_BCAST_TX = 0x20, 1918c2ecf20Sopenharmony_ci ICE_PROMISC_VLAN_RX = 0x40, 1928c2ecf20Sopenharmony_ci ICE_PROMISC_VLAN_TX = 0x80, 1938c2ecf20Sopenharmony_ci}; 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci/* VSI related commands */ 1968c2ecf20Sopenharmony_cienum ice_status 1978c2ecf20Sopenharmony_ciice_add_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 1988c2ecf20Sopenharmony_ci struct ice_sq_cd *cd); 1998c2ecf20Sopenharmony_cienum ice_status 2008c2ecf20Sopenharmony_ciice_free_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 2018c2ecf20Sopenharmony_ci bool keep_vsi_alloc, struct ice_sq_cd *cd); 2028c2ecf20Sopenharmony_cienum ice_status 2038c2ecf20Sopenharmony_ciice_update_vsi(struct ice_hw *hw, u16 vsi_handle, struct ice_vsi_ctx *vsi_ctx, 2048c2ecf20Sopenharmony_ci struct ice_sq_cd *cd); 2058c2ecf20Sopenharmony_cibool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle); 2068c2ecf20Sopenharmony_cistruct ice_vsi_ctx *ice_get_vsi_ctx(struct ice_hw *hw, u16 vsi_handle); 2078c2ecf20Sopenharmony_civoid ice_clear_all_vsi_ctx(struct ice_hw *hw); 2088c2ecf20Sopenharmony_ci/* Switch config */ 2098c2ecf20Sopenharmony_cienum ice_status ice_get_initial_sw_cfg(struct ice_hw *hw); 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_cienum ice_status 2128c2ecf20Sopenharmony_ciice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items, 2138c2ecf20Sopenharmony_ci u16 *counter_id); 2148c2ecf20Sopenharmony_cienum ice_status 2158c2ecf20Sopenharmony_ciice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items, 2168c2ecf20Sopenharmony_ci u16 counter_id); 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci/* Switch/bridge related commands */ 2198c2ecf20Sopenharmony_cienum ice_status ice_update_sw_rule_bridge_mode(struct ice_hw *hw); 2208c2ecf20Sopenharmony_cienum ice_status ice_add_mac(struct ice_hw *hw, struct list_head *m_lst); 2218c2ecf20Sopenharmony_cienum ice_status ice_remove_mac(struct ice_hw *hw, struct list_head *m_lst); 2228c2ecf20Sopenharmony_cienum ice_status 2238c2ecf20Sopenharmony_ciice_add_eth_mac(struct ice_hw *hw, struct list_head *em_list); 2248c2ecf20Sopenharmony_cienum ice_status 2258c2ecf20Sopenharmony_ciice_remove_eth_mac(struct ice_hw *hw, struct list_head *em_list); 2268c2ecf20Sopenharmony_civoid ice_remove_vsi_fltr(struct ice_hw *hw, u16 vsi_handle); 2278c2ecf20Sopenharmony_cienum ice_status 2288c2ecf20Sopenharmony_ciice_add_vlan(struct ice_hw *hw, struct list_head *m_list); 2298c2ecf20Sopenharmony_cienum ice_status ice_remove_vlan(struct ice_hw *hw, struct list_head *v_list); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci/* Promisc/defport setup for VSIs */ 2328c2ecf20Sopenharmony_cienum ice_status 2338c2ecf20Sopenharmony_ciice_cfg_dflt_vsi(struct ice_hw *hw, u16 vsi_handle, bool set, u8 direction); 2348c2ecf20Sopenharmony_cienum ice_status 2358c2ecf20Sopenharmony_ciice_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, 2368c2ecf20Sopenharmony_ci u16 vid); 2378c2ecf20Sopenharmony_cienum ice_status 2388c2ecf20Sopenharmony_ciice_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, 2398c2ecf20Sopenharmony_ci u16 vid); 2408c2ecf20Sopenharmony_cienum ice_status 2418c2ecf20Sopenharmony_ciice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, 2428c2ecf20Sopenharmony_ci bool rm_vlan_promisc); 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_cienum ice_status ice_init_def_sw_recp(struct ice_hw *hw); 2458c2ecf20Sopenharmony_ciu16 ice_get_hw_vsi_num(struct ice_hw *hw, u16 vsi_handle); 2468c2ecf20Sopenharmony_cibool ice_is_vsi_valid(struct ice_hw *hw, u16 vsi_handle); 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_cienum ice_status ice_replay_vsi_all_fltr(struct ice_hw *hw, u16 vsi_handle); 2498c2ecf20Sopenharmony_civoid ice_rm_all_sw_replay_rule_info(struct ice_hw *hw); 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci#endif /* _ICE_SWITCH_H_ */ 252