Linux Audio

Check our new training course

Linux debugging, profiling, tracing and performance analysis training

Apr 14-17, 2025
Register
Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0
  2/* Copyright (C) 2021, Intel Corporation. */
  3
  4#include "ice_virtchnl_allowlist.h"
  5
  6/* Purpose of this file is to share functionality to allowlist or denylist
  7 * opcodes used in PF <-> VF communication. Group of opcodes:
  8 * - default -> should be always allowed after creating VF,
  9 *   default_allowlist_opcodes
 10 * - opcodes needed by VF to work correctly, but not associated with caps ->
 11 *   should be allowed after successful VF resources allocation,
 12 *   working_allowlist_opcodes
 13 * - opcodes needed by VF when caps are activated
 14 *
 15 * Caps that don't use new opcodes (no opcodes should be allowed):
 
 
 16 * - VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
 17 * - VIRTCHNL_VF_OFFLOAD_CRC
 18 * - VIRTCHNL_VF_OFFLOAD_RX_POLLING
 19 * - VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
 20 * - VIRTCHNL_VF_OFFLOAD_ENCAP
 21 * - VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
 22 * - VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM
 23 * - VIRTCHNL_VF_OFFLOAD_USO
 24 */
 25
 26/* default opcodes to communicate with VF */
 27static const u32 default_allowlist_opcodes[] = {
 28	VIRTCHNL_OP_GET_VF_RESOURCES, VIRTCHNL_OP_VERSION, VIRTCHNL_OP_RESET_VF,
 29};
 30
 31/* opcodes supported after successful VIRTCHNL_OP_GET_VF_RESOURCES */
 32static const u32 working_allowlist_opcodes[] = {
 33	VIRTCHNL_OP_CONFIG_TX_QUEUE, VIRTCHNL_OP_CONFIG_RX_QUEUE,
 34	VIRTCHNL_OP_CONFIG_VSI_QUEUES, VIRTCHNL_OP_CONFIG_IRQ_MAP,
 35	VIRTCHNL_OP_ENABLE_QUEUES, VIRTCHNL_OP_DISABLE_QUEUES,
 36	VIRTCHNL_OP_GET_STATS, VIRTCHNL_OP_EVENT,
 37};
 38
 39/* VIRTCHNL_VF_OFFLOAD_L2 */
 40static const u32 l2_allowlist_opcodes[] = {
 41	VIRTCHNL_OP_ADD_ETH_ADDR, VIRTCHNL_OP_DEL_ETH_ADDR,
 42	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
 43};
 44
 45/* VIRTCHNL_VF_OFFLOAD_REQ_QUEUES */
 46static const u32 req_queues_allowlist_opcodes[] = {
 47	VIRTCHNL_OP_REQUEST_QUEUES,
 48};
 49
 50/* VIRTCHNL_VF_OFFLOAD_VLAN */
 51static const u32 vlan_allowlist_opcodes[] = {
 52	VIRTCHNL_OP_ADD_VLAN, VIRTCHNL_OP_DEL_VLAN,
 53	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
 54};
 55
 56/* VIRTCHNL_VF_OFFLOAD_VLAN_V2 */
 57static const u32 vlan_v2_allowlist_opcodes[] = {
 58	VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS, VIRTCHNL_OP_ADD_VLAN_V2,
 59	VIRTCHNL_OP_DEL_VLAN_V2, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
 60	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
 61	VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
 62	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
 63};
 64
 65/* VIRTCHNL_VF_OFFLOAD_RSS_PF */
 66static const u32 rss_pf_allowlist_opcodes[] = {
 67	VIRTCHNL_OP_CONFIG_RSS_KEY, VIRTCHNL_OP_CONFIG_RSS_LUT,
 68	VIRTCHNL_OP_GET_RSS_HENA_CAPS, VIRTCHNL_OP_SET_RSS_HENA,
 69	VIRTCHNL_OP_CONFIG_RSS_HFUNC,
 70};
 71
 72/* VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC */
 73static const u32 rx_flex_desc_allowlist_opcodes[] = {
 74	VIRTCHNL_OP_GET_SUPPORTED_RXDIDS,
 75};
 76
 77/* VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF */
 78static const u32 adv_rss_pf_allowlist_opcodes[] = {
 79	VIRTCHNL_OP_ADD_RSS_CFG, VIRTCHNL_OP_DEL_RSS_CFG,
 80};
 81
 82/* VIRTCHNL_VF_OFFLOAD_FDIR_PF */
 83static const u32 fdir_pf_allowlist_opcodes[] = {
 84	VIRTCHNL_OP_ADD_FDIR_FILTER, VIRTCHNL_OP_DEL_FDIR_FILTER,
 85};
 86
 87static const u32 tc_allowlist_opcodes[] = {
 88	VIRTCHNL_OP_GET_QOS_CAPS, VIRTCHNL_OP_CONFIG_QUEUE_BW,
 89	VIRTCHNL_OP_CONFIG_QUANTA,
 90};
 91
 92struct allowlist_opcode_info {
 93	const u32 *opcodes;
 94	size_t size;
 95};
 96
 97#define BIT_INDEX(caps) (HWEIGHT((caps) - 1))
 98#define ALLOW_ITEM(caps, list) \
 99	[BIT_INDEX(caps)] = { \
100		.opcodes = list, \
101		.size = ARRAY_SIZE(list) \
102	}
103static const struct allowlist_opcode_info allowlist_opcodes[] = {
104	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_L2, l2_allowlist_opcodes),
105	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_REQ_QUEUES, req_queues_allowlist_opcodes),
106	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_VLAN, vlan_allowlist_opcodes),
107	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_RSS_PF, rss_pf_allowlist_opcodes),
108	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC, rx_flex_desc_allowlist_opcodes),
109	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF, adv_rss_pf_allowlist_opcodes),
110	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_FDIR_PF, fdir_pf_allowlist_opcodes),
111	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_VLAN_V2, vlan_v2_allowlist_opcodes),
112	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_QOS, tc_allowlist_opcodes),
113};
114
115/**
116 * ice_vc_is_opcode_allowed - check if this opcode is allowed on this VF
117 * @vf: pointer to VF structure
118 * @opcode: virtchnl opcode
119 *
120 * Return true if message is allowed on this VF
121 */
122bool ice_vc_is_opcode_allowed(struct ice_vf *vf, u32 opcode)
123{
124	if (opcode >= VIRTCHNL_OP_MAX)
125		return false;
126
127	return test_bit(opcode, vf->opcodes_allowlist);
128}
129
130/**
131 * ice_vc_allowlist_opcodes - allowlist selected opcodes
132 * @vf: pointer to VF structure
133 * @opcodes: array of opocodes to allowlist
134 * @size: size of opcodes array
135 *
136 * Function should be called to allowlist opcodes on VF.
137 */
138static void
139ice_vc_allowlist_opcodes(struct ice_vf *vf, const u32 *opcodes, size_t size)
140{
141	unsigned int i;
142
143	for (i = 0; i < size; i++)
144		set_bit(opcodes[i], vf->opcodes_allowlist);
145}
146
147/**
148 * ice_vc_clear_allowlist - clear all allowlist opcodes
149 * @vf: pointer to VF structure
150 */
151static void ice_vc_clear_allowlist(struct ice_vf *vf)
152{
153	bitmap_zero(vf->opcodes_allowlist, VIRTCHNL_OP_MAX);
154}
155
156/**
157 * ice_vc_set_default_allowlist - allowlist default opcodes for VF
158 * @vf: pointer to VF structure
159 */
160void ice_vc_set_default_allowlist(struct ice_vf *vf)
161{
162	ice_vc_clear_allowlist(vf);
163	ice_vc_allowlist_opcodes(vf, default_allowlist_opcodes,
164				 ARRAY_SIZE(default_allowlist_opcodes));
165}
166
167/**
168 * ice_vc_set_working_allowlist - allowlist opcodes needed to by VF to work
169 * @vf: pointer to VF structure
170 *
171 * allowlist opcodes that aren't associated with specific caps, but
172 * are needed by VF to work.
173 */
174void ice_vc_set_working_allowlist(struct ice_vf *vf)
175{
176	ice_vc_allowlist_opcodes(vf, working_allowlist_opcodes,
177				 ARRAY_SIZE(working_allowlist_opcodes));
178}
179
180/**
181 * ice_vc_set_caps_allowlist - allowlist VF opcodes according caps
182 * @vf: pointer to VF structure
183 */
184void ice_vc_set_caps_allowlist(struct ice_vf *vf)
185{
186	unsigned long caps = vf->driver_caps;
187	unsigned int i;
188
189	for_each_set_bit(i, &caps, ARRAY_SIZE(allowlist_opcodes))
190		ice_vc_allowlist_opcodes(vf, allowlist_opcodes[i].opcodes,
191					 allowlist_opcodes[i].size);
192}
v6.2
  1// SPDX-License-Identifier: GPL-2.0
  2/* Copyright (C) 2021, Intel Corporation. */
  3
  4#include "ice_virtchnl_allowlist.h"
  5
  6/* Purpose of this file is to share functionality to allowlist or denylist
  7 * opcodes used in PF <-> VF communication. Group of opcodes:
  8 * - default -> should be always allowed after creating VF,
  9 *   default_allowlist_opcodes
 10 * - opcodes needed by VF to work correctly, but not associated with caps ->
 11 *   should be allowed after successful VF resources allocation,
 12 *   working_allowlist_opcodes
 13 * - opcodes needed by VF when caps are activated
 14 *
 15 * Caps that don't use new opcodes (no opcodes should be allowed):
 16 * - VIRTCHNL_VF_OFFLOAD_RSS_AQ
 17 * - VIRTCHNL_VF_OFFLOAD_RSS_REG
 18 * - VIRTCHNL_VF_OFFLOAD_WB_ON_ITR
 19 * - VIRTCHNL_VF_OFFLOAD_CRC
 20 * - VIRTCHNL_VF_OFFLOAD_RX_POLLING
 21 * - VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2
 22 * - VIRTCHNL_VF_OFFLOAD_ENCAP
 23 * - VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM
 24 * - VIRTCHNL_VF_OFFLOAD_RX_ENCAP_CSUM
 25 * - VIRTCHNL_VF_OFFLOAD_USO
 26 */
 27
 28/* default opcodes to communicate with VF */
 29static const u32 default_allowlist_opcodes[] = {
 30	VIRTCHNL_OP_GET_VF_RESOURCES, VIRTCHNL_OP_VERSION, VIRTCHNL_OP_RESET_VF,
 31};
 32
 33/* opcodes supported after successful VIRTCHNL_OP_GET_VF_RESOURCES */
 34static const u32 working_allowlist_opcodes[] = {
 35	VIRTCHNL_OP_CONFIG_TX_QUEUE, VIRTCHNL_OP_CONFIG_RX_QUEUE,
 36	VIRTCHNL_OP_CONFIG_VSI_QUEUES, VIRTCHNL_OP_CONFIG_IRQ_MAP,
 37	VIRTCHNL_OP_ENABLE_QUEUES, VIRTCHNL_OP_DISABLE_QUEUES,
 38	VIRTCHNL_OP_GET_STATS, VIRTCHNL_OP_EVENT,
 39};
 40
 41/* VIRTCHNL_VF_OFFLOAD_L2 */
 42static const u32 l2_allowlist_opcodes[] = {
 43	VIRTCHNL_OP_ADD_ETH_ADDR, VIRTCHNL_OP_DEL_ETH_ADDR,
 44	VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
 45};
 46
 47/* VIRTCHNL_VF_OFFLOAD_REQ_QUEUES */
 48static const u32 req_queues_allowlist_opcodes[] = {
 49	VIRTCHNL_OP_REQUEST_QUEUES,
 50};
 51
 52/* VIRTCHNL_VF_OFFLOAD_VLAN */
 53static const u32 vlan_allowlist_opcodes[] = {
 54	VIRTCHNL_OP_ADD_VLAN, VIRTCHNL_OP_DEL_VLAN,
 55	VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING,
 56};
 57
 58/* VIRTCHNL_VF_OFFLOAD_VLAN_V2 */
 59static const u32 vlan_v2_allowlist_opcodes[] = {
 60	VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS, VIRTCHNL_OP_ADD_VLAN_V2,
 61	VIRTCHNL_OP_DEL_VLAN_V2, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2,
 62	VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2,
 63	VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2,
 64	VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2,
 65};
 66
 67/* VIRTCHNL_VF_OFFLOAD_RSS_PF */
 68static const u32 rss_pf_allowlist_opcodes[] = {
 69	VIRTCHNL_OP_CONFIG_RSS_KEY, VIRTCHNL_OP_CONFIG_RSS_LUT,
 70	VIRTCHNL_OP_GET_RSS_HENA_CAPS, VIRTCHNL_OP_SET_RSS_HENA,
 
 71};
 72
 73/* VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC */
 74static const u32 rx_flex_desc_allowlist_opcodes[] = {
 75	VIRTCHNL_OP_GET_SUPPORTED_RXDIDS,
 76};
 77
 78/* VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF */
 79static const u32 adv_rss_pf_allowlist_opcodes[] = {
 80	VIRTCHNL_OP_ADD_RSS_CFG, VIRTCHNL_OP_DEL_RSS_CFG,
 81};
 82
 83/* VIRTCHNL_VF_OFFLOAD_FDIR_PF */
 84static const u32 fdir_pf_allowlist_opcodes[] = {
 85	VIRTCHNL_OP_ADD_FDIR_FILTER, VIRTCHNL_OP_DEL_FDIR_FILTER,
 86};
 87
 
 
 
 
 
 88struct allowlist_opcode_info {
 89	const u32 *opcodes;
 90	size_t size;
 91};
 92
 93#define BIT_INDEX(caps) (HWEIGHT((caps) - 1))
 94#define ALLOW_ITEM(caps, list) \
 95	[BIT_INDEX(caps)] = { \
 96		.opcodes = list, \
 97		.size = ARRAY_SIZE(list) \
 98	}
 99static const struct allowlist_opcode_info allowlist_opcodes[] = {
100	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_L2, l2_allowlist_opcodes),
101	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_REQ_QUEUES, req_queues_allowlist_opcodes),
102	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_VLAN, vlan_allowlist_opcodes),
103	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_RSS_PF, rss_pf_allowlist_opcodes),
104	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_RX_FLEX_DESC, rx_flex_desc_allowlist_opcodes),
105	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF, adv_rss_pf_allowlist_opcodes),
106	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_FDIR_PF, fdir_pf_allowlist_opcodes),
107	ALLOW_ITEM(VIRTCHNL_VF_OFFLOAD_VLAN_V2, vlan_v2_allowlist_opcodes),
 
108};
109
110/**
111 * ice_vc_is_opcode_allowed - check if this opcode is allowed on this VF
112 * @vf: pointer to VF structure
113 * @opcode: virtchnl opcode
114 *
115 * Return true if message is allowed on this VF
116 */
117bool ice_vc_is_opcode_allowed(struct ice_vf *vf, u32 opcode)
118{
119	if (opcode >= VIRTCHNL_OP_MAX)
120		return false;
121
122	return test_bit(opcode, vf->opcodes_allowlist);
123}
124
125/**
126 * ice_vc_allowlist_opcodes - allowlist selected opcodes
127 * @vf: pointer to VF structure
128 * @opcodes: array of opocodes to allowlist
129 * @size: size of opcodes array
130 *
131 * Function should be called to allowlist opcodes on VF.
132 */
133static void
134ice_vc_allowlist_opcodes(struct ice_vf *vf, const u32 *opcodes, size_t size)
135{
136	unsigned int i;
137
138	for (i = 0; i < size; i++)
139		set_bit(opcodes[i], vf->opcodes_allowlist);
140}
141
142/**
143 * ice_vc_clear_allowlist - clear all allowlist opcodes
144 * @vf: pointer to VF structure
145 */
146static void ice_vc_clear_allowlist(struct ice_vf *vf)
147{
148	bitmap_zero(vf->opcodes_allowlist, VIRTCHNL_OP_MAX);
149}
150
151/**
152 * ice_vc_set_default_allowlist - allowlist default opcodes for VF
153 * @vf: pointer to VF structure
154 */
155void ice_vc_set_default_allowlist(struct ice_vf *vf)
156{
157	ice_vc_clear_allowlist(vf);
158	ice_vc_allowlist_opcodes(vf, default_allowlist_opcodes,
159				 ARRAY_SIZE(default_allowlist_opcodes));
160}
161
162/**
163 * ice_vc_set_working_allowlist - allowlist opcodes needed to by VF to work
164 * @vf: pointer to VF structure
165 *
166 * allowlist opcodes that aren't associated with specific caps, but
167 * are needed by VF to work.
168 */
169void ice_vc_set_working_allowlist(struct ice_vf *vf)
170{
171	ice_vc_allowlist_opcodes(vf, working_allowlist_opcodes,
172				 ARRAY_SIZE(working_allowlist_opcodes));
173}
174
175/**
176 * ice_vc_set_caps_allowlist - allowlist VF opcodes according caps
177 * @vf: pointer to VF structure
178 */
179void ice_vc_set_caps_allowlist(struct ice_vf *vf)
180{
181	unsigned long caps = vf->driver_caps;
182	unsigned int i;
183
184	for_each_set_bit(i, &caps, ARRAY_SIZE(allowlist_opcodes))
185		ice_vc_allowlist_opcodes(vf, allowlist_opcodes[i].opcodes,
186					 allowlist_opcodes[i].size);
187}