|
38 | 38 | #include "spectrum.h" |
39 | 39 | #include "spectrum_dpipe.h" |
40 | 40 |
|
41 | | -static struct devlink_dpipe_header *mlxsw_dpipe_headers[] = {}; |
| 41 | +enum mlxsw_sp_field_metadata_id { |
| 42 | + MLXSW_SP_DPIPE_FIELD_METADATA_ERIF_PORT, |
| 43 | + MLXSW_SP_DPIPE_FIELD_METADATA_L3_FORWARD, |
| 44 | + MLXSW_SP_DPIPE_FIELD_METADATA_L3_DROP, |
| 45 | +}; |
| 46 | + |
| 47 | +static struct devlink_dpipe_field mlxsw_sp_dpipe_fields_metadata[] = { |
| 48 | + { .name = "erif_port", |
| 49 | + .id = MLXSW_SP_DPIPE_FIELD_METADATA_ERIF_PORT, |
| 50 | + .bitwidth = 32, |
| 51 | + .mapping_type = DEVLINK_DPIPE_FIELD_MAPPING_TYPE_IFINDEX, |
| 52 | + }, |
| 53 | + { .name = "l3_forward", |
| 54 | + .id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_FORWARD, |
| 55 | + .bitwidth = 1, |
| 56 | + }, |
| 57 | + { .name = "l3_drop", |
| 58 | + .id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_DROP, |
| 59 | + .bitwidth = 1, |
| 60 | + }, |
| 61 | +}; |
| 62 | + |
| 63 | +enum mlxsw_sp_dpipe_header_id { |
| 64 | + MLXSW_SP_DPIPE_HEADER_METADATA, |
| 65 | +}; |
| 66 | + |
| 67 | +static struct devlink_dpipe_header mlxsw_sp_dpipe_header_metadata = { |
| 68 | + .name = "mlxsw_meta", |
| 69 | + .id = MLXSW_SP_DPIPE_HEADER_METADATA, |
| 70 | + .fields = mlxsw_sp_dpipe_fields_metadata, |
| 71 | + .fields_count = ARRAY_SIZE(mlxsw_sp_dpipe_fields_metadata), |
| 72 | +}; |
| 73 | + |
| 74 | +static struct devlink_dpipe_header *mlxsw_dpipe_headers[] = { |
| 75 | + &mlxsw_sp_dpipe_header_metadata, |
| 76 | +}; |
42 | 77 |
|
43 | 78 | static struct devlink_dpipe_headers mlxsw_sp_dpipe_headers = { |
44 | 79 | .headers = mlxsw_dpipe_headers, |
45 | 80 | .headers_count = ARRAY_SIZE(mlxsw_dpipe_headers), |
46 | 81 | }; |
47 | 82 |
|
| 83 | +static int mlxsw_sp_dpipe_table_erif_actions_dump(void *priv, |
| 84 | + struct sk_buff *skb) |
| 85 | +{ |
| 86 | + struct devlink_dpipe_action action = {0}; |
| 87 | + int err; |
| 88 | + |
| 89 | + action.type = DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY; |
| 90 | + action.header = &mlxsw_sp_dpipe_header_metadata; |
| 91 | + action.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_FORWARD; |
| 92 | + |
| 93 | + err = devlink_dpipe_action_put(skb, &action); |
| 94 | + if (err) |
| 95 | + return err; |
| 96 | + |
| 97 | + action.type = DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY; |
| 98 | + action.header = &mlxsw_sp_dpipe_header_metadata; |
| 99 | + action.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_DROP; |
| 100 | + |
| 101 | + return devlink_dpipe_action_put(skb, &action); |
| 102 | +} |
| 103 | + |
| 104 | +static int mlxsw_sp_dpipe_table_erif_matches_dump(void *priv, |
| 105 | + struct sk_buff *skb) |
| 106 | +{ |
| 107 | + struct devlink_dpipe_match match = {0}; |
| 108 | + |
| 109 | + match.type = DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT; |
| 110 | + match.header = &mlxsw_sp_dpipe_header_metadata; |
| 111 | + match.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_ERIF_PORT; |
| 112 | + |
| 113 | + return devlink_dpipe_match_put(skb, &match); |
| 114 | +} |
| 115 | + |
| 116 | +static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = { |
| 117 | + .matches_dump = mlxsw_sp_dpipe_table_erif_matches_dump, |
| 118 | + .actions_dump = mlxsw_sp_dpipe_table_erif_actions_dump, |
| 119 | +}; |
| 120 | + |
| 121 | +static int mlxsw_sp_dpipe_erif_table_init(struct mlxsw_sp *mlxsw_sp) |
| 122 | +{ |
| 123 | + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); |
| 124 | + u64 table_size; |
| 125 | + |
| 126 | + table_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS); |
| 127 | + return devlink_dpipe_table_register(devlink, |
| 128 | + MLXSW_SP_DPIPE_TABLE_NAME_ERIF, |
| 129 | + &mlxsw_sp_erif_ops, |
| 130 | + mlxsw_sp, table_size, |
| 131 | + false); |
| 132 | +} |
| 133 | + |
| 134 | +static void mlxsw_sp_dpipe_erif_table_fini(struct mlxsw_sp *mlxsw_sp) |
| 135 | +{ |
| 136 | + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); |
| 137 | + |
| 138 | + devlink_dpipe_table_unregister(devlink, MLXSW_SP_DPIPE_TABLE_NAME_ERIF); |
| 139 | +} |
| 140 | + |
48 | 141 | int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp) |
49 | 142 | { |
50 | | - return devlink_dpipe_headers_register(priv_to_devlink(mlxsw_sp->core), |
51 | | - &mlxsw_sp_dpipe_headers); |
| 143 | + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); |
| 144 | + int err; |
| 145 | + |
| 146 | + err = devlink_dpipe_headers_register(devlink, |
| 147 | + &mlxsw_sp_dpipe_headers); |
| 148 | + if (err) |
| 149 | + return err; |
| 150 | + err = mlxsw_sp_dpipe_erif_table_init(mlxsw_sp); |
| 151 | + if (err) |
| 152 | + goto err_erif_register; |
| 153 | + return 0; |
| 154 | + |
| 155 | +err_erif_register: |
| 156 | + devlink_dpipe_headers_unregister(priv_to_devlink(mlxsw_sp->core)); |
| 157 | + return err; |
52 | 158 | } |
53 | 159 |
|
54 | 160 | void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp) |
55 | 161 | { |
56 | | - devlink_dpipe_headers_unregister(priv_to_devlink(mlxsw_sp->core)); |
| 162 | + struct devlink *devlink = priv_to_devlink(mlxsw_sp->core); |
| 163 | + |
| 164 | + mlxsw_sp_dpipe_erif_table_fini(mlxsw_sp); |
| 165 | + devlink_dpipe_headers_unregister(devlink); |
57 | 166 | } |
0 commit comments