1 // SPDX-License-Identifier: GPL-2.0-only
2 /****************************************************************************
3 * Driver for Solarflare network controllers and boards
4 * Copyright 2019 Solarflare Communications Inc.
5 * Copyright 2020-2022 Xilinx Inc.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published
9 * by the Free Software Foundation, incorporated herein by reference.
14 #include "ef100_rep.h"
17 static void efx_tc_free_action_set(struct efx_nic *efx,
18 struct efx_tc_action_set *act, bool in_hw)
20 /* Failure paths calling this on the 'running action' set in_hw=false,
21 * because if the alloc had succeeded we'd've put it in acts.list and
22 * not still have it in act.
25 efx_mae_free_action_set(efx, act->fw_id);
26 /* in_hw is true iff we are on an acts.list; make sure to
27 * remove ourselves from that list before we are freed.
34 static void efx_tc_free_action_set_list(struct efx_nic *efx,
35 struct efx_tc_action_set_list *acts,
38 struct efx_tc_action_set *act, *next;
40 /* Failure paths set in_hw=false, because usually the acts didn't get
41 * to efx_mae_alloc_action_set_list(); if they did, the failure tree
42 * has a separate efx_mae_free_action_set_list() before calling us.
45 efx_mae_free_action_set_list(efx, acts);
46 /* Any act that's on the list will be in_hw even if the list isn't */
47 list_for_each_entry_safe(act, next, &acts->list, list)
48 efx_tc_free_action_set(efx, act, true);
49 /* Don't kfree, as acts is embedded inside a struct efx_tc_flow_rule */
52 static void efx_tc_delete_rule(struct efx_nic *efx, struct efx_tc_flow_rule *rule)
54 efx_mae_delete_rule(efx, rule->fw_id);
56 /* Release entries in subsidiary tables */
57 efx_tc_free_action_set_list(efx, &rule->acts, true);
58 rule->fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
61 static int efx_tc_configure_default_rule(struct efx_nic *efx, u32 ing_port,
62 u32 eg_port, struct efx_tc_flow_rule *rule)
64 struct efx_tc_action_set_list *acts = &rule->acts;
65 struct efx_tc_match *match = &rule->match;
66 struct efx_tc_action_set *act;
69 match->value.ingress_port = ing_port;
70 match->mask.ingress_port = ~0;
71 act = kzalloc(sizeof(*act), GFP_KERNEL);
75 act->dest_mport = eg_port;
76 rc = efx_mae_alloc_action_set(efx, act);
79 EFX_WARN_ON_PARANOID(!list_empty(&acts->list));
80 list_add_tail(&act->list, &acts->list);
81 rc = efx_mae_alloc_action_set_list(efx, acts);
84 rc = efx_mae_insert_rule(efx, match, EFX_TC_PRIO_DFLT,
85 acts->fw_id, &rule->fw_id);
90 efx_mae_free_action_set_list(efx, acts);
93 efx_mae_free_action_set(efx, act->fw_id);
99 static int efx_tc_configure_default_rule_pf(struct efx_nic *efx)
101 struct efx_tc_flow_rule *rule = &efx->tc->dflt.pf;
102 u32 ing_port, eg_port;
104 efx_mae_mport_uplink(efx, &ing_port);
105 efx_mae_mport_wire(efx, &eg_port);
106 return efx_tc_configure_default_rule(efx, ing_port, eg_port, rule);
109 static int efx_tc_configure_default_rule_wire(struct efx_nic *efx)
111 struct efx_tc_flow_rule *rule = &efx->tc->dflt.wire;
112 u32 ing_port, eg_port;
114 efx_mae_mport_wire(efx, &ing_port);
115 efx_mae_mport_uplink(efx, &eg_port);
116 return efx_tc_configure_default_rule(efx, ing_port, eg_port, rule);
119 int efx_tc_configure_default_rule_rep(struct efx_rep *efv)
121 struct efx_tc_flow_rule *rule = &efv->dflt;
122 struct efx_nic *efx = efv->parent;
123 u32 ing_port, eg_port;
125 efx_mae_mport_mport(efx, efv->mport, &ing_port);
126 efx_mae_mport_mport(efx, efx->tc->reps_mport_id, &eg_port);
127 return efx_tc_configure_default_rule(efx, ing_port, eg_port, rule);
130 void efx_tc_deconfigure_default_rule(struct efx_nic *efx,
131 struct efx_tc_flow_rule *rule)
133 if (rule->fw_id != MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL)
134 efx_tc_delete_rule(efx, rule);
135 rule->fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
138 static int efx_tc_configure_rep_mport(struct efx_nic *efx)
143 rc = efx_mae_allocate_mport(efx, &efx->tc->reps_mport_id, &rep_mport_label);
146 pci_dbg(efx->pci_dev, "created rep mport 0x%08x (0x%04x)\n",
147 efx->tc->reps_mport_id, rep_mport_label);
148 /* Use mport *selector* as vport ID */
149 efx_mae_mport_mport(efx, efx->tc->reps_mport_id,
150 &efx->tc->reps_mport_vport_id);
154 static void efx_tc_deconfigure_rep_mport(struct efx_nic *efx)
156 efx_mae_free_mport(efx, efx->tc->reps_mport_id);
157 efx->tc->reps_mport_id = MAE_MPORT_SELECTOR_NULL;
160 int efx_tc_insert_rep_filters(struct efx_nic *efx)
162 struct efx_filter_spec promisc, allmulti;
165 if (efx->type->is_vf)
169 efx_filter_init_rx(&promisc, EFX_FILTER_PRI_REQUIRED, 0, 0);
170 efx_filter_set_uc_def(&promisc);
171 efx_filter_set_vport_id(&promisc, efx->tc->reps_mport_vport_id);
172 rc = efx_filter_insert_filter(efx, &promisc, false);
175 efx->tc->reps_filter_uc = rc;
176 efx_filter_init_rx(&allmulti, EFX_FILTER_PRI_REQUIRED, 0, 0);
177 efx_filter_set_mc_def(&allmulti);
178 efx_filter_set_vport_id(&allmulti, efx->tc->reps_mport_vport_id);
179 rc = efx_filter_insert_filter(efx, &allmulti, false);
182 efx->tc->reps_filter_mc = rc;
186 void efx_tc_remove_rep_filters(struct efx_nic *efx)
188 if (efx->type->is_vf)
192 if (efx->tc->reps_filter_mc >= 0)
193 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, efx->tc->reps_filter_mc);
194 efx->tc->reps_filter_mc = -1;
195 if (efx->tc->reps_filter_uc >= 0)
196 efx_filter_remove_id_safe(efx, EFX_FILTER_PRI_REQUIRED, efx->tc->reps_filter_uc);
197 efx->tc->reps_filter_uc = -1;
200 int efx_init_tc(struct efx_nic *efx)
204 rc = efx_tc_configure_default_rule_pf(efx);
207 rc = efx_tc_configure_default_rule_wire(efx);
210 return efx_tc_configure_rep_mport(efx);
213 void efx_fini_tc(struct efx_nic *efx)
215 /* We can get called even if efx_init_struct_tc() failed */
218 efx_tc_deconfigure_rep_mport(efx);
219 efx_tc_deconfigure_default_rule(efx, &efx->tc->dflt.pf);
220 efx_tc_deconfigure_default_rule(efx, &efx->tc->dflt.wire);
223 int efx_init_struct_tc(struct efx_nic *efx)
225 if (efx->type->is_vf)
228 efx->tc = kzalloc(sizeof(*efx->tc), GFP_KERNEL);
232 efx->tc->reps_filter_uc = -1;
233 efx->tc->reps_filter_mc = -1;
234 INIT_LIST_HEAD(&efx->tc->dflt.pf.acts.list);
235 efx->tc->dflt.pf.fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
236 INIT_LIST_HEAD(&efx->tc->dflt.wire.acts.list);
237 efx->tc->dflt.wire.fw_id = MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL;
241 void efx_fini_struct_tc(struct efx_nic *efx)
246 EFX_WARN_ON_PARANOID(efx->tc->dflt.pf.fw_id !=
247 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);
248 EFX_WARN_ON_PARANOID(efx->tc->dflt.wire.fw_id !=
249 MC_CMD_MAE_ACTION_RULE_INSERT_OUT_ACTION_RULE_ID_NULL);