• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
3 
4 #include <linux/kernel.h>
5 #include <linux/slab.h>
6 #include <linux/list.h>
7 #include <linux/errno.h>
8 
9 #include "item.h"
10 #include "core_acl_flex_keys.h"
11 
12 /* For the purpose of the driver, define an internal storage scratchpad
13  * that will be used to store key/mask values. For each defined element type
14  * define an internal storage geometry.
15  *
16  * When adding new elements, MLXSW_AFK_ELEMENT_STORAGE_SIZE must be increased
17  * accordingly.
18  */
19 static const struct mlxsw_afk_element_info mlxsw_afk_element_infos[] = {
20 	MLXSW_AFK_ELEMENT_INFO_U32(SRC_SYS_PORT, 0x00, 16, 16),
21 	MLXSW_AFK_ELEMENT_INFO_BUF(DMAC_32_47, 0x04, 2),
22 	MLXSW_AFK_ELEMENT_INFO_BUF(DMAC_0_31, 0x06, 4),
23 	MLXSW_AFK_ELEMENT_INFO_BUF(SMAC_32_47, 0x0A, 2),
24 	MLXSW_AFK_ELEMENT_INFO_BUF(SMAC_0_31, 0x0C, 4),
25 	MLXSW_AFK_ELEMENT_INFO_U32(ETHERTYPE, 0x00, 0, 16),
26 	MLXSW_AFK_ELEMENT_INFO_U32(IP_PROTO, 0x10, 0, 8),
27 	MLXSW_AFK_ELEMENT_INFO_U32(VID, 0x10, 8, 12),
28 	MLXSW_AFK_ELEMENT_INFO_U32(PCP, 0x10, 20, 3),
29 	MLXSW_AFK_ELEMENT_INFO_U32(TCP_FLAGS, 0x10, 23, 9),
30 	MLXSW_AFK_ELEMENT_INFO_U32(DST_L4_PORT, 0x14, 0, 16),
31 	MLXSW_AFK_ELEMENT_INFO_U32(SRC_L4_PORT, 0x14, 16, 16),
32 	MLXSW_AFK_ELEMENT_INFO_U32(IP_TTL_, 0x18, 0, 8),
33 	MLXSW_AFK_ELEMENT_INFO_U32(IP_ECN, 0x18, 9, 2),
34 	MLXSW_AFK_ELEMENT_INFO_U32(IP_DSCP, 0x18, 11, 6),
35 	MLXSW_AFK_ELEMENT_INFO_U32(VIRT_ROUTER_8_10, 0x18, 17, 3),
36 	MLXSW_AFK_ELEMENT_INFO_U32(VIRT_ROUTER_0_7, 0x18, 20, 8),
37 	MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP_96_127, 0x20, 4),
38 	MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP_64_95, 0x24, 4),
39 	MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP_32_63, 0x28, 4),
40 	MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP_0_31, 0x2C, 4),
41 	MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP_96_127, 0x30, 4),
42 	MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP_64_95, 0x34, 4),
43 	MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP_32_63, 0x38, 4),
44 	MLXSW_AFK_ELEMENT_INFO_BUF(DST_IP_0_31, 0x3C, 4),
45 };
46 
47 struct mlxsw_afk {
48 	struct list_head key_info_list;
49 	unsigned int max_blocks;
50 	const struct mlxsw_afk_ops *ops;
51 	const struct mlxsw_afk_block *blocks;
52 	unsigned int blocks_count;
53 };
54 
mlxsw_afk_blocks_check(struct mlxsw_afk * mlxsw_afk)55 static bool mlxsw_afk_blocks_check(struct mlxsw_afk *mlxsw_afk)
56 {
57 	int i;
58 	int j;
59 
60 	for (i = 0; i < mlxsw_afk->blocks_count; i++) {
61 		const struct mlxsw_afk_block *block = &mlxsw_afk->blocks[i];
62 
63 		for (j = 0; j < block->instances_count; j++) {
64 			const struct mlxsw_afk_element_info *elinfo;
65 			struct mlxsw_afk_element_inst *elinst;
66 
67 			elinst = &block->instances[j];
68 			elinfo = &mlxsw_afk_element_infos[elinst->element];
69 			if (elinst->type != elinfo->type ||
70 			    (!elinst->avoid_size_check &&
71 			     elinst->item.size.bits !=
72 			     elinfo->item.size.bits))
73 				return false;
74 		}
75 	}
76 	return true;
77 }
78 
mlxsw_afk_create(unsigned int max_blocks,const struct mlxsw_afk_ops * ops)79 struct mlxsw_afk *mlxsw_afk_create(unsigned int max_blocks,
80 				   const struct mlxsw_afk_ops *ops)
81 {
82 	struct mlxsw_afk *mlxsw_afk;
83 
84 	mlxsw_afk = kzalloc(sizeof(*mlxsw_afk), GFP_KERNEL);
85 	if (!mlxsw_afk)
86 		return NULL;
87 	INIT_LIST_HEAD(&mlxsw_afk->key_info_list);
88 	mlxsw_afk->max_blocks = max_blocks;
89 	mlxsw_afk->ops = ops;
90 	mlxsw_afk->blocks = ops->blocks;
91 	mlxsw_afk->blocks_count = ops->blocks_count;
92 	WARN_ON(!mlxsw_afk_blocks_check(mlxsw_afk));
93 	return mlxsw_afk;
94 }
95 EXPORT_SYMBOL(mlxsw_afk_create);
96 
mlxsw_afk_destroy(struct mlxsw_afk * mlxsw_afk)97 void mlxsw_afk_destroy(struct mlxsw_afk *mlxsw_afk)
98 {
99 	WARN_ON(!list_empty(&mlxsw_afk->key_info_list));
100 	kfree(mlxsw_afk);
101 }
102 EXPORT_SYMBOL(mlxsw_afk_destroy);
103 
104 struct mlxsw_afk_key_info {
105 	struct list_head list;
106 	unsigned int ref_count;
107 	unsigned int blocks_count;
108 	int element_to_block[MLXSW_AFK_ELEMENT_MAX]; /* index is element, value
109 						      * is index inside "blocks"
110 						      */
111 	struct mlxsw_afk_element_usage elusage;
112 	const struct mlxsw_afk_block *blocks[];
113 };
114 
115 static bool
mlxsw_afk_key_info_elements_eq(struct mlxsw_afk_key_info * key_info,struct mlxsw_afk_element_usage * elusage)116 mlxsw_afk_key_info_elements_eq(struct mlxsw_afk_key_info *key_info,
117 			       struct mlxsw_afk_element_usage *elusage)
118 {
119 	return memcmp(&key_info->elusage, elusage, sizeof(*elusage)) == 0;
120 }
121 
122 static struct mlxsw_afk_key_info *
mlxsw_afk_key_info_find(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_element_usage * elusage)123 mlxsw_afk_key_info_find(struct mlxsw_afk *mlxsw_afk,
124 			struct mlxsw_afk_element_usage *elusage)
125 {
126 	struct mlxsw_afk_key_info *key_info;
127 
128 	list_for_each_entry(key_info, &mlxsw_afk->key_info_list, list) {
129 		if (mlxsw_afk_key_info_elements_eq(key_info, elusage))
130 			return key_info;
131 	}
132 	return NULL;
133 }
134 
135 struct mlxsw_afk_picker {
136 	struct {
137 		DECLARE_BITMAP(element, MLXSW_AFK_ELEMENT_MAX);
138 		unsigned int total;
139 	} hits[0];
140 };
141 
mlxsw_afk_picker_count_hits(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_picker * picker,enum mlxsw_afk_element element)142 static void mlxsw_afk_picker_count_hits(struct mlxsw_afk *mlxsw_afk,
143 					struct mlxsw_afk_picker *picker,
144 					enum mlxsw_afk_element element)
145 {
146 	int i;
147 	int j;
148 
149 	for (i = 0; i < mlxsw_afk->blocks_count; i++) {
150 		const struct mlxsw_afk_block *block = &mlxsw_afk->blocks[i];
151 
152 		for (j = 0; j < block->instances_count; j++) {
153 			struct mlxsw_afk_element_inst *elinst;
154 
155 			elinst = &block->instances[j];
156 			if (elinst->element == element) {
157 				__set_bit(element, picker->hits[i].element);
158 				picker->hits[i].total++;
159 			}
160 		}
161 	}
162 }
163 
mlxsw_afk_picker_subtract_hits(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_picker * picker,int block_index)164 static void mlxsw_afk_picker_subtract_hits(struct mlxsw_afk *mlxsw_afk,
165 					   struct mlxsw_afk_picker *picker,
166 					   int block_index)
167 {
168 	DECLARE_BITMAP(hits_element, MLXSW_AFK_ELEMENT_MAX);
169 	int i;
170 	int j;
171 
172 	memcpy(&hits_element, &picker->hits[block_index].element,
173 	       sizeof(hits_element));
174 
175 	for (i = 0; i < mlxsw_afk->blocks_count; i++) {
176 		for_each_set_bit(j, hits_element, MLXSW_AFK_ELEMENT_MAX) {
177 			if (__test_and_clear_bit(j, picker->hits[i].element))
178 				picker->hits[i].total--;
179 		}
180 	}
181 }
182 
mlxsw_afk_picker_most_hits_get(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_picker * picker)183 static int mlxsw_afk_picker_most_hits_get(struct mlxsw_afk *mlxsw_afk,
184 					  struct mlxsw_afk_picker *picker)
185 {
186 	int most_index = -EINVAL; /* Should never happen to return this */
187 	int most_hits = 0;
188 	int i;
189 
190 	for (i = 0; i < mlxsw_afk->blocks_count; i++) {
191 		if (picker->hits[i].total > most_hits) {
192 			most_hits = picker->hits[i].total;
193 			most_index = i;
194 		}
195 	}
196 	return most_index;
197 }
198 
mlxsw_afk_picker_key_info_add(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_picker * picker,int block_index,struct mlxsw_afk_key_info * key_info)199 static int mlxsw_afk_picker_key_info_add(struct mlxsw_afk *mlxsw_afk,
200 					 struct mlxsw_afk_picker *picker,
201 					 int block_index,
202 					 struct mlxsw_afk_key_info *key_info)
203 {
204 	enum mlxsw_afk_element element;
205 
206 	if (key_info->blocks_count == mlxsw_afk->max_blocks)
207 		return -EINVAL;
208 
209 	for_each_set_bit(element, picker->hits[block_index].element,
210 			 MLXSW_AFK_ELEMENT_MAX) {
211 		key_info->element_to_block[element] = key_info->blocks_count;
212 		mlxsw_afk_element_usage_add(&key_info->elusage, element);
213 	}
214 
215 	key_info->blocks[key_info->blocks_count] =
216 					&mlxsw_afk->blocks[block_index];
217 	key_info->blocks_count++;
218 	return 0;
219 }
220 
mlxsw_afk_picker(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_key_info * key_info,struct mlxsw_afk_element_usage * elusage)221 static int mlxsw_afk_picker(struct mlxsw_afk *mlxsw_afk,
222 			    struct mlxsw_afk_key_info *key_info,
223 			    struct mlxsw_afk_element_usage *elusage)
224 {
225 	struct mlxsw_afk_picker *picker;
226 	enum mlxsw_afk_element element;
227 	size_t alloc_size;
228 	int err;
229 
230 	alloc_size = sizeof(picker->hits[0]) * mlxsw_afk->blocks_count;
231 	picker = kzalloc(alloc_size, GFP_KERNEL);
232 	if (!picker)
233 		return -ENOMEM;
234 
235 	/* Since the same elements could be present in multiple blocks,
236 	 * we must find out optimal block list in order to make the
237 	 * block count as low as possible.
238 	 *
239 	 * First, we count hits. We go over all available blocks and count
240 	 * how many of requested elements are covered by each.
241 	 *
242 	 * Then in loop, we find block with most hits and add it to
243 	 * output key_info. Then we have to subtract this block hits so
244 	 * the next iteration will find most suitable block for
245 	 * the rest of requested elements.
246 	 */
247 
248 	mlxsw_afk_element_usage_for_each(element, elusage)
249 		mlxsw_afk_picker_count_hits(mlxsw_afk, picker, element);
250 
251 	do {
252 		int block_index;
253 
254 		block_index = mlxsw_afk_picker_most_hits_get(mlxsw_afk, picker);
255 		if (block_index < 0) {
256 			err = block_index;
257 			goto out;
258 		}
259 		err = mlxsw_afk_picker_key_info_add(mlxsw_afk, picker,
260 						    block_index, key_info);
261 		if (err)
262 			goto out;
263 		mlxsw_afk_picker_subtract_hits(mlxsw_afk, picker, block_index);
264 	} while (!mlxsw_afk_key_info_elements_eq(key_info, elusage));
265 
266 	err = 0;
267 out:
268 	kfree(picker);
269 	return err;
270 }
271 
272 static struct mlxsw_afk_key_info *
mlxsw_afk_key_info_create(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_element_usage * elusage)273 mlxsw_afk_key_info_create(struct mlxsw_afk *mlxsw_afk,
274 			  struct mlxsw_afk_element_usage *elusage)
275 {
276 	struct mlxsw_afk_key_info *key_info;
277 	int err;
278 
279 	key_info = kzalloc(struct_size(key_info, blocks, mlxsw_afk->max_blocks),
280 			   GFP_KERNEL);
281 	if (!key_info)
282 		return ERR_PTR(-ENOMEM);
283 	err = mlxsw_afk_picker(mlxsw_afk, key_info, elusage);
284 	if (err)
285 		goto err_picker;
286 	list_add(&key_info->list, &mlxsw_afk->key_info_list);
287 	key_info->ref_count = 1;
288 	return key_info;
289 
290 err_picker:
291 	kfree(key_info);
292 	return ERR_PTR(err);
293 }
294 
mlxsw_afk_key_info_destroy(struct mlxsw_afk_key_info * key_info)295 static void mlxsw_afk_key_info_destroy(struct mlxsw_afk_key_info *key_info)
296 {
297 	list_del(&key_info->list);
298 	kfree(key_info);
299 }
300 
301 struct mlxsw_afk_key_info *
mlxsw_afk_key_info_get(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_element_usage * elusage)302 mlxsw_afk_key_info_get(struct mlxsw_afk *mlxsw_afk,
303 		       struct mlxsw_afk_element_usage *elusage)
304 {
305 	struct mlxsw_afk_key_info *key_info;
306 
307 	key_info = mlxsw_afk_key_info_find(mlxsw_afk, elusage);
308 	if (key_info) {
309 		key_info->ref_count++;
310 		return key_info;
311 	}
312 	return mlxsw_afk_key_info_create(mlxsw_afk, elusage);
313 }
314 EXPORT_SYMBOL(mlxsw_afk_key_info_get);
315 
mlxsw_afk_key_info_put(struct mlxsw_afk_key_info * key_info)316 void mlxsw_afk_key_info_put(struct mlxsw_afk_key_info *key_info)
317 {
318 	if (--key_info->ref_count)
319 		return;
320 	mlxsw_afk_key_info_destroy(key_info);
321 }
322 EXPORT_SYMBOL(mlxsw_afk_key_info_put);
323 
mlxsw_afk_key_info_subset(struct mlxsw_afk_key_info * key_info,struct mlxsw_afk_element_usage * elusage)324 bool mlxsw_afk_key_info_subset(struct mlxsw_afk_key_info *key_info,
325 			       struct mlxsw_afk_element_usage *elusage)
326 {
327 	return mlxsw_afk_element_usage_subset(elusage, &key_info->elusage);
328 }
329 EXPORT_SYMBOL(mlxsw_afk_key_info_subset);
330 
331 static const struct mlxsw_afk_element_inst *
mlxsw_afk_block_elinst_get(const struct mlxsw_afk_block * block,enum mlxsw_afk_element element)332 mlxsw_afk_block_elinst_get(const struct mlxsw_afk_block *block,
333 			   enum mlxsw_afk_element element)
334 {
335 	int i;
336 
337 	for (i = 0; i < block->instances_count; i++) {
338 		struct mlxsw_afk_element_inst *elinst;
339 
340 		elinst = &block->instances[i];
341 		if (elinst->element == element)
342 			return elinst;
343 	}
344 	return NULL;
345 }
346 
347 static const struct mlxsw_afk_element_inst *
mlxsw_afk_key_info_elinst_get(struct mlxsw_afk_key_info * key_info,enum mlxsw_afk_element element,int * p_block_index)348 mlxsw_afk_key_info_elinst_get(struct mlxsw_afk_key_info *key_info,
349 			      enum mlxsw_afk_element element,
350 			      int *p_block_index)
351 {
352 	const struct mlxsw_afk_element_inst *elinst;
353 	const struct mlxsw_afk_block *block;
354 	int block_index;
355 
356 	if (WARN_ON(!test_bit(element, key_info->elusage.usage)))
357 		return NULL;
358 	block_index = key_info->element_to_block[element];
359 	block = key_info->blocks[block_index];
360 
361 	elinst = mlxsw_afk_block_elinst_get(block, element);
362 	if (WARN_ON(!elinst))
363 		return NULL;
364 
365 	*p_block_index = block_index;
366 	return elinst;
367 }
368 
369 u16
mlxsw_afk_key_info_block_encoding_get(const struct mlxsw_afk_key_info * key_info,int block_index)370 mlxsw_afk_key_info_block_encoding_get(const struct mlxsw_afk_key_info *key_info,
371 				      int block_index)
372 {
373 	return key_info->blocks[block_index]->encoding;
374 }
375 EXPORT_SYMBOL(mlxsw_afk_key_info_block_encoding_get);
376 
377 unsigned int
mlxsw_afk_key_info_blocks_count_get(const struct mlxsw_afk_key_info * key_info)378 mlxsw_afk_key_info_blocks_count_get(const struct mlxsw_afk_key_info *key_info)
379 {
380 	return key_info->blocks_count;
381 }
382 EXPORT_SYMBOL(mlxsw_afk_key_info_blocks_count_get);
383 
mlxsw_afk_values_add_u32(struct mlxsw_afk_element_values * values,enum mlxsw_afk_element element,u32 key_value,u32 mask_value)384 void mlxsw_afk_values_add_u32(struct mlxsw_afk_element_values *values,
385 			      enum mlxsw_afk_element element,
386 			      u32 key_value, u32 mask_value)
387 {
388 	const struct mlxsw_afk_element_info *elinfo =
389 				&mlxsw_afk_element_infos[element];
390 	const struct mlxsw_item *storage_item = &elinfo->item;
391 
392 	if (!mask_value)
393 		return;
394 	if (WARN_ON(elinfo->type != MLXSW_AFK_ELEMENT_TYPE_U32))
395 		return;
396 	__mlxsw_item_set32(values->storage.key, storage_item, 0, key_value);
397 	__mlxsw_item_set32(values->storage.mask, storage_item, 0, mask_value);
398 	mlxsw_afk_element_usage_add(&values->elusage, element);
399 }
400 EXPORT_SYMBOL(mlxsw_afk_values_add_u32);
401 
mlxsw_afk_values_add_buf(struct mlxsw_afk_element_values * values,enum mlxsw_afk_element element,const char * key_value,const char * mask_value,unsigned int len)402 void mlxsw_afk_values_add_buf(struct mlxsw_afk_element_values *values,
403 			      enum mlxsw_afk_element element,
404 			      const char *key_value, const char *mask_value,
405 			      unsigned int len)
406 {
407 	const struct mlxsw_afk_element_info *elinfo =
408 				&mlxsw_afk_element_infos[element];
409 	const struct mlxsw_item *storage_item = &elinfo->item;
410 
411 	if (!memchr_inv(mask_value, 0, len)) /* If mask is zero */
412 		return;
413 	if (WARN_ON(elinfo->type != MLXSW_AFK_ELEMENT_TYPE_BUF) ||
414 	    WARN_ON(elinfo->item.size.bytes != len))
415 		return;
416 	__mlxsw_item_memcpy_to(values->storage.key, key_value,
417 			       storage_item, 0);
418 	__mlxsw_item_memcpy_to(values->storage.mask, mask_value,
419 			       storage_item, 0);
420 	mlxsw_afk_element_usage_add(&values->elusage, element);
421 }
422 EXPORT_SYMBOL(mlxsw_afk_values_add_buf);
423 
mlxsw_sp_afk_encode_u32(const struct mlxsw_item * storage_item,const struct mlxsw_item * output_item,char * storage,char * output,int diff)424 static void mlxsw_sp_afk_encode_u32(const struct mlxsw_item *storage_item,
425 				    const struct mlxsw_item *output_item,
426 				    char *storage, char *output, int diff)
427 {
428 	u32 value;
429 
430 	value = __mlxsw_item_get32(storage, storage_item, 0);
431 	__mlxsw_item_set32(output, output_item, 0, value + diff);
432 }
433 
mlxsw_sp_afk_encode_buf(const struct mlxsw_item * storage_item,const struct mlxsw_item * output_item,char * storage,char * output)434 static void mlxsw_sp_afk_encode_buf(const struct mlxsw_item *storage_item,
435 				    const struct mlxsw_item *output_item,
436 				    char *storage, char *output)
437 {
438 	char *storage_data = __mlxsw_item_data(storage, storage_item, 0);
439 	char *output_data = __mlxsw_item_data(output, output_item, 0);
440 	size_t len = output_item->size.bytes;
441 
442 	memcpy(output_data, storage_data, len);
443 }
444 
445 static void
mlxsw_sp_afk_encode_one(const struct mlxsw_afk_element_inst * elinst,char * output,char * storage,int u32_diff)446 mlxsw_sp_afk_encode_one(const struct mlxsw_afk_element_inst *elinst,
447 			char *output, char *storage, int u32_diff)
448 {
449 	const struct mlxsw_item *output_item = &elinst->item;
450 	const struct mlxsw_afk_element_info *elinfo;
451 	const struct mlxsw_item *storage_item;
452 
453 	elinfo = &mlxsw_afk_element_infos[elinst->element];
454 	storage_item = &elinfo->item;
455 	if (elinst->type == MLXSW_AFK_ELEMENT_TYPE_U32)
456 		mlxsw_sp_afk_encode_u32(storage_item, output_item,
457 					storage, output, u32_diff);
458 	else if (elinst->type == MLXSW_AFK_ELEMENT_TYPE_BUF)
459 		mlxsw_sp_afk_encode_buf(storage_item, output_item,
460 					storage, output);
461 }
462 
463 #define MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE 16
464 
mlxsw_afk_encode(struct mlxsw_afk * mlxsw_afk,struct mlxsw_afk_key_info * key_info,struct mlxsw_afk_element_values * values,char * key,char * mask)465 void mlxsw_afk_encode(struct mlxsw_afk *mlxsw_afk,
466 		      struct mlxsw_afk_key_info *key_info,
467 		      struct mlxsw_afk_element_values *values,
468 		      char *key, char *mask)
469 {
470 	unsigned int blocks_count =
471 			mlxsw_afk_key_info_blocks_count_get(key_info);
472 	char block_mask[MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE];
473 	char block_key[MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE];
474 	const struct mlxsw_afk_element_inst *elinst;
475 	enum mlxsw_afk_element element;
476 	int block_index, i;
477 
478 	for (i = 0; i < blocks_count; i++) {
479 		memset(block_key, 0, MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE);
480 		memset(block_mask, 0, MLXSW_SP_AFK_KEY_BLOCK_MAX_SIZE);
481 
482 		mlxsw_afk_element_usage_for_each(element, &values->elusage) {
483 			elinst = mlxsw_afk_key_info_elinst_get(key_info,
484 							       element,
485 							       &block_index);
486 			if (!elinst || block_index != i)
487 				continue;
488 
489 			mlxsw_sp_afk_encode_one(elinst, block_key,
490 						values->storage.key,
491 						elinst->u32_key_diff);
492 			mlxsw_sp_afk_encode_one(elinst, block_mask,
493 						values->storage.mask, 0);
494 		}
495 
496 		mlxsw_afk->ops->encode_block(key, i, block_key);
497 		mlxsw_afk->ops->encode_block(mask, i, block_mask);
498 	}
499 }
500 EXPORT_SYMBOL(mlxsw_afk_encode);
501 
mlxsw_afk_clear(struct mlxsw_afk * mlxsw_afk,char * key,int block_start,int block_end)502 void mlxsw_afk_clear(struct mlxsw_afk *mlxsw_afk, char *key,
503 		     int block_start, int block_end)
504 {
505 	int i;
506 
507 	for (i = block_start; i <= block_end; i++)
508 		mlxsw_afk->ops->clear_block(key, i);
509 }
510 EXPORT_SYMBOL(mlxsw_afk_clear);
511