net/ice/base: add method to disable FDIR swap option
[dpdk.git] / drivers / net / ice / base / ice_proto_grp.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2021 Intel Corporation
3  */
4
5 #include "ice_common.h"
6 #include "ice_parser_util.h"
7
8 #define ICE_PROTO_GRP_TABLE_SIZE 192
9
10 static void _proto_off_dump(struct ice_hw *hw, struct ice_proto_off *po,
11                             int idx)
12 {
13         ice_info(hw, "proto %d\n", idx);
14         ice_info(hw, "\tpolarity = %d\n", po->polarity);
15         ice_info(hw, "\tproto_id = %d\n", po->proto_id);
16         ice_info(hw, "\toffset = %d\n", po->offset);
17 }
18
19 /**
20  * ice_proto_grp_dump - dump a proto group item info
21  * @ice_hw: pointer to the hardware structure
22  * @item: proto group item to dump
23  */
24 void ice_proto_grp_dump(struct ice_hw *hw, struct ice_proto_grp_item *item)
25 {
26         int i;
27
28         ice_info(hw, "index = %d\n", item->idx);
29
30         for (i = 0; i < ICE_PROTO_COUNT_PER_GRP; i++)
31                 _proto_off_dump(hw, &item->po[i], i);
32 }
33
34 /** The function parses a 22 bits Protocol entry with below format:
35  *  BIT 0:      Polarity of Protocol Offset (po->polarity)
36  *  BIT 1-8:    Protocol ID (po->proto_id)
37  *  BIT 9-11:   reserved
38  *  BIT 12-21:  Protocol Offset (po->offset)
39  */
40 static void _proto_off_parse(struct ice_proto_off *po, u32 data)
41 {
42         po->polarity = (data & 0x1) != 0;
43         po->proto_id = (u8)((data >> 1) & 0xff);
44         po->offset = (u16)((data >> 12) & 0x3ff);
45 }
46
47 /** The function parses a 192 bits Protocol Group Table entry with below
48  *  format:
49  *  BIT 0-21:   Protocol 0 (grp->po[0])
50  *  BIT 22-43:  Protocol 1 (grp->po[1])
51  *  BIT 44-65:  Protocol 2 (grp->po[2])
52  *  BIT 66-87:  Protocol 3 (grp->po[3])
53  *  BIT 88-109: Protocol 4 (grp->po[4])
54  *  BIT 110-131:Protocol 5 (grp->po[5])
55  *  BIT 132-153:Protocol 6 (grp->po[6])
56  *  BIT 154-175:Protocol 7 (grp->po[7])
57  *  BIT 176-191:reserved
58  */
59 static void _proto_grp_parse_item(struct ice_hw *hw, u16 idx, void *item,
60                                   void *data, int size)
61 {
62         struct ice_proto_grp_item *grp = (struct ice_proto_grp_item *)item;
63         u8 *buf = (u8 *)data;
64         u32 d32;
65
66         grp->idx = idx;
67
68         d32 = *(u32 *)buf;
69         _proto_off_parse(&grp->po[0], d32);
70
71         d32 = (*(u32 *)&buf[2] >> 6);
72         _proto_off_parse(&grp->po[1], d32);
73
74         d32 = (*(u32 *)&buf[5] >> 4);
75         _proto_off_parse(&grp->po[2], d32);
76
77         d32 = (*(u32 *)&buf[8] >> 2);
78         _proto_off_parse(&grp->po[3], d32);
79
80         d32 = *(u32 *)&buf[11];
81         _proto_off_parse(&grp->po[4], d32);
82
83         d32 = (*(u32 *)&buf[13] >> 6);
84         _proto_off_parse(&grp->po[5], d32);
85
86         d32 = (*(u32 *)&buf[16] >> 4);
87         _proto_off_parse(&grp->po[6], d32);
88
89         d32 = (*(u32 *)&buf[19] >> 2);
90         _proto_off_parse(&grp->po[7], d32);
91
92         if (hw->debug_mask & ICE_DBG_PARSER)
93                 ice_proto_grp_dump(hw, grp);
94 }
95
96 /**
97  * ice_proto_grp_table_get - create a proto group table
98  * @ice_hw: pointer to the hardware structure
99  */
100 struct ice_proto_grp_item *ice_proto_grp_table_get(struct ice_hw *hw)
101 {
102         return (struct ice_proto_grp_item *)
103                 ice_parser_create_table(hw, ICE_SID_RXPARSER_PROTO_GRP,
104                                         sizeof(struct ice_proto_grp_item),
105                                         ICE_PROTO_GRP_TABLE_SIZE,
106                                         ice_parser_sect_item_get,
107                                         _proto_grp_parse_item, false);
108 }