Skip to content

Commit 2b64beb

Browse files
ogerlitzSaeed Mahameed
authored andcommitted
net/mlx5e: Support header re-write of partial fields in TC pedit offload
Using a per field mask field, the TC pedit action supports modifying partial fields. E.g if using the TC tool, the following example would make the kernel to only re-write two bytes of the src ip address: tc filter add dev enp1s0 protocol ip parent ffff: prio 30 flower skip_sw ip_proto udp dst_port 8001 action pedit ex munge ip src set 10.1.0.0 retain 0xffff0000 We add driver support for offload these partial re-writes, by setting the per FW action offset-in-field and length-from-offset attributes. The 1st bit set in the mask specifies both the offset and the right shift to apply on the value such that the 1st bit which needs to be set will reside in bit 0 of the FW data field. Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Reviewed-by: Paul Blakey <paulb@mellanox.com> Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
1 parent 3099eb5 commit 2b64beb

File tree

1 file changed

+19
-9
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+19
-9
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_tc.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,12 +1091,14 @@ static int offload_pedit_fields(struct pedit_headers *masks,
10911091
struct mlx5e_tc_flow_parse_attr *parse_attr)
10921092
{
10931093
struct pedit_headers *set_masks, *add_masks, *set_vals, *add_vals;
1094-
int i, action_size, nactions, max_actions, first, last, first_z;
1094+
int i, action_size, nactions, max_actions, first, last, next_z;
10951095
void *s_masks_p, *a_masks_p, *vals_p;
10961096
struct mlx5_fields *f;
10971097
u8 cmd, field_bsize;
10981098
u32 s_mask, a_mask;
10991099
unsigned long mask;
1100+
__be32 mask_be32;
1101+
__be16 mask_be16;
11001102
void *action;
11011103

11021104
set_masks = &masks[TCA_PEDIT_KEY_EX_CMD_SET];
@@ -1150,11 +1152,19 @@ static int offload_pedit_fields(struct pedit_headers *masks,
11501152

11511153
field_bsize = f->size * BITS_PER_BYTE;
11521154

1153-
first_z = find_first_zero_bit(&mask, field_bsize);
1155+
if (field_bsize == 32) {
1156+
mask_be32 = *(__be32 *)&mask;
1157+
mask = (__force unsigned long)cpu_to_le32(be32_to_cpu(mask_be32));
1158+
} else if (field_bsize == 16) {
1159+
mask_be16 = *(__be16 *)&mask;
1160+
mask = (__force unsigned long)cpu_to_le16(be16_to_cpu(mask_be16));
1161+
}
1162+
11541163
first = find_first_bit(&mask, field_bsize);
1164+
next_z = find_next_zero_bit(&mask, field_bsize, first);
11551165
last = find_last_bit(&mask, field_bsize);
1156-
if (first > 0 || last != (field_bsize - 1) || first_z < last) {
1157-
printk(KERN_WARNING "mlx5: partial rewrite (mask %lx) is currently not offloaded\n",
1166+
if (first < next_z && next_z < last) {
1167+
printk(KERN_WARNING "mlx5: rewrite of few sub-fields (mask %lx) isn't offloaded\n",
11581168
mask);
11591169
return -EOPNOTSUPP;
11601170
}
@@ -1163,17 +1173,17 @@ static int offload_pedit_fields(struct pedit_headers *masks,
11631173
MLX5_SET(set_action_in, action, field, f->field);
11641174

11651175
if (cmd == MLX5_ACTION_TYPE_SET) {
1166-
MLX5_SET(set_action_in, action, offset, 0);
1176+
MLX5_SET(set_action_in, action, offset, first);
11671177
/* length is num of bits to be written, zero means length of 32 */
1168-
MLX5_SET(set_action_in, action, length, field_bsize);
1178+
MLX5_SET(set_action_in, action, length, (last - first + 1));
11691179
}
11701180

11711181
if (field_bsize == 32)
1172-
MLX5_SET(set_action_in, action, data, ntohl(*(__be32 *)vals_p));
1182+
MLX5_SET(set_action_in, action, data, ntohl(*(__be32 *)vals_p) >> first);
11731183
else if (field_bsize == 16)
1174-
MLX5_SET(set_action_in, action, data, ntohs(*(__be16 *)vals_p));
1184+
MLX5_SET(set_action_in, action, data, ntohs(*(__be16 *)vals_p) >> first);
11751185
else if (field_bsize == 8)
1176-
MLX5_SET(set_action_in, action, data, *(u8 *)vals_p);
1186+
MLX5_SET(set_action_in, action, data, *(u8 *)vals_p >> first);
11771187

11781188
action += action_size;
11791189
nactions++;

0 commit comments

Comments
 (0)