1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
4 #include <linux/kernel.h>
5 #include <linux/errno.h>
6 #include <linux/parman.h>
11 #include "spectrum_acl_tcam.h"
14 mlxsw_sp_acl_ctcam_region_resize(struct mlxsw_sp
*mlxsw_sp
,
15 struct mlxsw_sp_acl_tcam_region
*region
,
18 char ptar_pl
[MLXSW_REG_PTAR_LEN
];
20 mlxsw_reg_ptar_pack(ptar_pl
, MLXSW_REG_PTAR_OP_RESIZE
,
21 region
->key_type
, new_size
, region
->id
,
22 region
->tcam_region_info
);
23 return mlxsw_reg_write(mlxsw_sp
->core
, MLXSW_REG(ptar
), ptar_pl
);
27 mlxsw_sp_acl_ctcam_region_move(struct mlxsw_sp
*mlxsw_sp
,
28 struct mlxsw_sp_acl_tcam_region
*region
,
29 u16 src_offset
, u16 dst_offset
, u16 size
)
31 char prcr_pl
[MLXSW_REG_PRCR_LEN
];
33 mlxsw_reg_prcr_pack(prcr_pl
, MLXSW_REG_PRCR_OP_MOVE
,
34 region
->tcam_region_info
, src_offset
,
35 region
->tcam_region_info
, dst_offset
, size
);
36 mlxsw_reg_write(mlxsw_sp
->core
, MLXSW_REG(prcr
), prcr_pl
);
40 mlxsw_sp_acl_ctcam_region_entry_insert(struct mlxsw_sp
*mlxsw_sp
,
41 struct mlxsw_sp_acl_ctcam_region
*cregion
,
42 struct mlxsw_sp_acl_ctcam_entry
*centry
,
43 struct mlxsw_sp_acl_rule_info
*rulei
,
46 struct mlxsw_sp_acl_tcam_region
*region
= cregion
->region
;
47 struct mlxsw_afk
*afk
= mlxsw_sp_acl_afk(mlxsw_sp
->acl
);
48 char ptce2_pl
[MLXSW_REG_PTCE2_LEN
];
55 err
= mlxsw_sp_acl_tcam_priority_get(mlxsw_sp
, rulei
, &priority
,
60 mlxsw_reg_ptce2_pack(ptce2_pl
, true, MLXSW_REG_PTCE2_OP_WRITE_WRITE
,
61 region
->tcam_region_info
,
62 centry
->parman_item
.index
, priority
);
63 key
= mlxsw_reg_ptce2_flex_key_blocks_data(ptce2_pl
);
64 mask
= mlxsw_reg_ptce2_mask_data(ptce2_pl
);
65 mlxsw_afk_encode(afk
, region
->key_info
, &rulei
->values
, key
, mask
);
67 err
= cregion
->ops
->entry_insert(cregion
, centry
, mask
);
71 /* Only the first action set belongs here, the rest is in KVD */
72 act_set
= mlxsw_afa_block_first_set(rulei
->act_block
);
73 mlxsw_reg_ptce2_flex_action_set_memcpy_to(ptce2_pl
, act_set
);
75 err
= mlxsw_reg_write(mlxsw_sp
->core
, MLXSW_REG(ptce2
), ptce2_pl
);
82 cregion
->ops
->entry_remove(cregion
, centry
);
87 mlxsw_sp_acl_ctcam_region_entry_remove(struct mlxsw_sp
*mlxsw_sp
,
88 struct mlxsw_sp_acl_ctcam_region
*cregion
,
89 struct mlxsw_sp_acl_ctcam_entry
*centry
)
91 char ptce2_pl
[MLXSW_REG_PTCE2_LEN
];
93 mlxsw_reg_ptce2_pack(ptce2_pl
, false, MLXSW_REG_PTCE2_OP_WRITE_WRITE
,
94 cregion
->region
->tcam_region_info
,
95 centry
->parman_item
.index
, 0);
96 mlxsw_reg_write(mlxsw_sp
->core
, MLXSW_REG(ptce2
), ptce2_pl
);
97 cregion
->ops
->entry_remove(cregion
, centry
);
101 mlxsw_sp_acl_ctcam_region_entry_action_replace(struct mlxsw_sp
*mlxsw_sp
,
102 struct mlxsw_sp_acl_ctcam_region
*cregion
,
103 struct mlxsw_sp_acl_ctcam_entry
*centry
,
104 struct mlxsw_afa_block
*afa_block
,
105 unsigned int priority
)
107 char ptce2_pl
[MLXSW_REG_PTCE2_LEN
];
110 mlxsw_reg_ptce2_pack(ptce2_pl
, true, MLXSW_REG_PTCE2_OP_WRITE_UPDATE
,
111 cregion
->region
->tcam_region_info
,
112 centry
->parman_item
.index
, priority
);
114 act_set
= mlxsw_afa_block_first_set(afa_block
);
115 mlxsw_reg_ptce2_flex_action_set_memcpy_to(ptce2_pl
, act_set
);
117 return mlxsw_reg_write(mlxsw_sp
->core
, MLXSW_REG(ptce2
), ptce2_pl
);
121 static int mlxsw_sp_acl_ctcam_region_parman_resize(void *priv
,
122 unsigned long new_count
)
124 struct mlxsw_sp_acl_ctcam_region
*cregion
= priv
;
125 struct mlxsw_sp_acl_tcam_region
*region
= cregion
->region
;
126 struct mlxsw_sp
*mlxsw_sp
= region
->mlxsw_sp
;
129 max_tcam_rules
= MLXSW_CORE_RES_GET(mlxsw_sp
->core
, ACL_MAX_TCAM_RULES
);
130 if (new_count
> max_tcam_rules
)
132 return mlxsw_sp_acl_ctcam_region_resize(mlxsw_sp
, region
, new_count
);
135 static void mlxsw_sp_acl_ctcam_region_parman_move(void *priv
,
136 unsigned long from_index
,
137 unsigned long to_index
,
140 struct mlxsw_sp_acl_ctcam_region
*cregion
= priv
;
141 struct mlxsw_sp_acl_tcam_region
*region
= cregion
->region
;
142 struct mlxsw_sp
*mlxsw_sp
= region
->mlxsw_sp
;
144 mlxsw_sp_acl_ctcam_region_move(mlxsw_sp
, region
,
145 from_index
, to_index
, count
);
148 static const struct parman_ops mlxsw_sp_acl_ctcam_region_parman_ops
= {
149 .base_count
= MLXSW_SP_ACL_TCAM_REGION_BASE_COUNT
,
150 .resize_step
= MLXSW_SP_ACL_TCAM_REGION_RESIZE_STEP
,
151 .resize
= mlxsw_sp_acl_ctcam_region_parman_resize
,
152 .move
= mlxsw_sp_acl_ctcam_region_parman_move
,
153 .algo
= PARMAN_ALGO_TYPE_LSORT
,
157 mlxsw_sp_acl_ctcam_region_init(struct mlxsw_sp
*mlxsw_sp
,
158 struct mlxsw_sp_acl_ctcam_region
*cregion
,
159 struct mlxsw_sp_acl_tcam_region
*region
,
160 const struct mlxsw_sp_acl_ctcam_region_ops
*ops
)
162 cregion
->region
= region
;
164 cregion
->parman
= parman_create(&mlxsw_sp_acl_ctcam_region_parman_ops
,
166 if (!cregion
->parman
)
171 void mlxsw_sp_acl_ctcam_region_fini(struct mlxsw_sp_acl_ctcam_region
*cregion
)
173 parman_destroy(cregion
->parman
);
176 void mlxsw_sp_acl_ctcam_chunk_init(struct mlxsw_sp_acl_ctcam_region
*cregion
,
177 struct mlxsw_sp_acl_ctcam_chunk
*cchunk
,
178 unsigned int priority
)
180 parman_prio_init(cregion
->parman
, &cchunk
->parman_prio
, priority
);
183 void mlxsw_sp_acl_ctcam_chunk_fini(struct mlxsw_sp_acl_ctcam_chunk
*cchunk
)
185 parman_prio_fini(&cchunk
->parman_prio
);
188 int mlxsw_sp_acl_ctcam_entry_add(struct mlxsw_sp
*mlxsw_sp
,
189 struct mlxsw_sp_acl_ctcam_region
*cregion
,
190 struct mlxsw_sp_acl_ctcam_chunk
*cchunk
,
191 struct mlxsw_sp_acl_ctcam_entry
*centry
,
192 struct mlxsw_sp_acl_rule_info
*rulei
,
193 bool fillup_priority
)
197 err
= parman_item_add(cregion
->parman
, &cchunk
->parman_prio
,
198 ¢ry
->parman_item
);
202 err
= mlxsw_sp_acl_ctcam_region_entry_insert(mlxsw_sp
, cregion
, centry
,
203 rulei
, fillup_priority
);
205 goto err_rule_insert
;
209 parman_item_remove(cregion
->parman
, &cchunk
->parman_prio
,
210 ¢ry
->parman_item
);
214 void mlxsw_sp_acl_ctcam_entry_del(struct mlxsw_sp
*mlxsw_sp
,
215 struct mlxsw_sp_acl_ctcam_region
*cregion
,
216 struct mlxsw_sp_acl_ctcam_chunk
*cchunk
,
217 struct mlxsw_sp_acl_ctcam_entry
*centry
)
219 mlxsw_sp_acl_ctcam_region_entry_remove(mlxsw_sp
, cregion
, centry
);
220 parman_item_remove(cregion
->parman
, &cchunk
->parman_prio
,
221 ¢ry
->parman_item
);
224 int mlxsw_sp_acl_ctcam_entry_action_replace(struct mlxsw_sp
*mlxsw_sp
,
225 struct mlxsw_sp_acl_ctcam_region
*cregion
,
226 struct mlxsw_sp_acl_ctcam_chunk
*cchunk
,
227 struct mlxsw_sp_acl_ctcam_entry
*centry
,
228 struct mlxsw_sp_acl_rule_info
*rulei
)
230 return mlxsw_sp_acl_ctcam_region_entry_action_replace(mlxsw_sp
, cregion
,