net/i40e: fix ethernet flow rule
[dpdk.git] / drivers / net / dpaa2 / mc / dpkg.c
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2017 NXP
4  *
5  */
6 #include <fsl_mc_sys.h>
7 #include <fsl_mc_cmd.h>
8 #include <fsl_dpkg.h>
9
10 /**
11  * dpkg_prepare_key_cfg() - function prepare extract parameters
12  * @cfg: defining a full Key Generation profile (rule)
13  * @key_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
14  *
15  * This function has to be called before the following functions:
16  *      - dpni_set_rx_tc_dist()
17  *      - dpni_set_qos_table()
18  *      - dpkg_prepare_key_cfg()
19  */
20 int
21 dpkg_prepare_key_cfg(const struct dpkg_profile_cfg *cfg, uint8_t *key_cfg_buf)
22 {
23         int i, j;
24         struct dpni_ext_set_rx_tc_dist *dpni_ext;
25         struct dpni_dist_extract *extr;
26
27         if (cfg->num_extracts > DPKG_MAX_NUM_OF_EXTRACTS)
28                 return -EINVAL;
29
30         dpni_ext = (struct dpni_ext_set_rx_tc_dist *)key_cfg_buf;
31         dpni_ext->num_extracts = cfg->num_extracts;
32
33         for (i = 0; i < cfg->num_extracts; i++) {
34                 extr = &dpni_ext->extracts[i];
35
36                 switch (cfg->extracts[i].type) {
37                 case DPKG_EXTRACT_FROM_HDR:
38                         extr->prot = cfg->extracts[i].extract.from_hdr.prot;
39                         dpkg_set_field(extr->efh_type, EFH_TYPE,
40                                        cfg->extracts[i].extract.from_hdr.type);
41                         extr->size = cfg->extracts[i].extract.from_hdr.size;
42                         extr->offset = cfg->extracts[i].extract.from_hdr.offset;
43                         extr->field = cpu_to_le32(
44                                 cfg->extracts[i].extract.from_hdr.field);
45                         extr->hdr_index =
46                                 cfg->extracts[i].extract.from_hdr.hdr_index;
47                         break;
48                 case DPKG_EXTRACT_FROM_DATA:
49                         extr->size = cfg->extracts[i].extract.from_data.size;
50                         extr->offset =
51                                 cfg->extracts[i].extract.from_data.offset;
52                         break;
53                 case DPKG_EXTRACT_FROM_PARSE:
54                         extr->size = cfg->extracts[i].extract.from_parse.size;
55                         extr->offset =
56                                 cfg->extracts[i].extract.from_parse.offset;
57                         break;
58                 default:
59                         return -EINVAL;
60                 }
61
62                 extr->num_of_byte_masks = cfg->extracts[i].num_of_byte_masks;
63                 dpkg_set_field(extr->extract_type, EXTRACT_TYPE,
64                                cfg->extracts[i].type);
65
66                 for (j = 0; j < DPKG_NUM_OF_MASKS; j++) {
67                         extr->masks[j].mask = cfg->extracts[i].masks[j].mask;
68                         extr->masks[j].offset =
69                                 cfg->extracts[i].masks[j].offset;
70                 }
71         }
72
73         return 0;
74 }