xref: /openbmc/linux/drivers/net/ethernet/sfc/mae.h (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1da56552dSEdward Cree /* SPDX-License-Identifier: GPL-2.0-only */
2da56552dSEdward Cree /****************************************************************************
3da56552dSEdward Cree  * Driver for Solarflare network controllers and boards
4da56552dSEdward Cree  * Copyright 2019 Solarflare Communications Inc.
5da56552dSEdward Cree  * Copyright 2020-2022 Xilinx Inc.
6da56552dSEdward Cree  *
7da56552dSEdward Cree  * This program is free software; you can redistribute it and/or modify it
8da56552dSEdward Cree  * under the terms of the GNU General Public License version 2 as published
9da56552dSEdward Cree  * by the Free Software Foundation, incorporated herein by reference.
10da56552dSEdward Cree  */
11da56552dSEdward Cree 
12da56552dSEdward Cree #ifndef EF100_MAE_H
13da56552dSEdward Cree #define EF100_MAE_H
14da56552dSEdward Cree /* MCDI interface for the ef100 Match-Action Engine */
15da56552dSEdward Cree 
1625414b2aSAlejandro Lucero #include <net/devlink.h>
17da56552dSEdward Cree #include "net_driver.h"
1867ab160eSEdward Cree #include "tc.h"
1967ab160eSEdward Cree #include "mcdi_pcol.h" /* needed for various MC_CMD_MAE_*_NULL defines */
20da56552dSEdward Cree 
21e37f3b15SEdward Cree int efx_mae_allocate_mport(struct efx_nic *efx, u32 *id, u32 *label);
22e37f3b15SEdward Cree int efx_mae_free_mport(struct efx_nic *efx, u32 id);
23e37f3b15SEdward Cree 
246f6838aaSEdward Cree void efx_mae_mport_wire(struct efx_nic *efx, u32 *out);
2567ab160eSEdward Cree void efx_mae_mport_uplink(struct efx_nic *efx, u32 *out);
26da56552dSEdward Cree void efx_mae_mport_vf(struct efx_nic *efx, u32 vf_id, u32 *out);
2767ab160eSEdward Cree void efx_mae_mport_mport(struct efx_nic *efx, u32 mport_id, u32 *out);
28da56552dSEdward Cree 
29da56552dSEdward Cree int efx_mae_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id);
30da56552dSEdward Cree 
31a6a15acaSAlejandro Lucero struct mae_mport_desc {
32a6a15acaSAlejandro Lucero 	u32 mport_id;
33a6a15acaSAlejandro Lucero 	u32 flags;
34a6a15acaSAlejandro Lucero 	u32 caller_flags; /* enum mae_mport_desc_caller_flags */
35a6a15acaSAlejandro Lucero 	u32 mport_type; /* MAE_MPORT_DESC_MPORT_TYPE_* */
36a6a15acaSAlejandro Lucero 	union {
37a6a15acaSAlejandro Lucero 		u32 port_idx; /* for mport_type == NET_PORT */
38a6a15acaSAlejandro Lucero 		u32 alias_mport_id; /* for mport_type == ALIAS */
39a6a15acaSAlejandro Lucero 		struct { /* for mport_type == VNIC */
40a6a15acaSAlejandro Lucero 			u32 vnic_client_type; /* MAE_MPORT_DESC_VNIC_CLIENT_TYPE_* */
41a6a15acaSAlejandro Lucero 			u32 interface_idx;
42a6a15acaSAlejandro Lucero 			u16 pf_idx;
43a6a15acaSAlejandro Lucero 			u16 vf_idx;
44a6a15acaSAlejandro Lucero 		};
45a6a15acaSAlejandro Lucero 	};
46a6a15acaSAlejandro Lucero 	struct rhash_head linkage;
4725414b2aSAlejandro Lucero 	struct devlink_port dl_port;
48a6a15acaSAlejandro Lucero };
49a6a15acaSAlejandro Lucero 
50a6a15acaSAlejandro Lucero int efx_mae_enumerate_mports(struct efx_nic *efx);
51a6a15acaSAlejandro Lucero struct mae_mport_desc *efx_mae_get_mport(struct efx_nic *efx, u32 mport_id);
52a6a15acaSAlejandro Lucero void efx_mae_put_mport(struct efx_nic *efx, struct mae_mport_desc *desc);
53a6a15acaSAlejandro Lucero 
54a6a15acaSAlejandro Lucero /**
55a6a15acaSAlejandro Lucero  * struct efx_mae - MAE information
56a6a15acaSAlejandro Lucero  *
57a6a15acaSAlejandro Lucero  * @efx: The associated NIC
58a6a15acaSAlejandro Lucero  * @mports_ht: m-port descriptions from MC_CMD_MAE_MPORT_READ_JOURNAL
59a6a15acaSAlejandro Lucero  */
60a6a15acaSAlejandro Lucero struct efx_mae {
61a6a15acaSAlejandro Lucero 	struct efx_nic *efx;
62a6a15acaSAlejandro Lucero 	struct rhashtable mports_ht;
63a6a15acaSAlejandro Lucero };
64a6a15acaSAlejandro Lucero 
65e5731274SEdward Cree int efx_mae_start_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue);
66e5731274SEdward Cree int efx_mae_stop_counters(struct efx_nic *efx, struct efx_rx_queue *rx_queue);
67e5731274SEdward Cree void efx_mae_counters_grant_credits(struct work_struct *work);
68e5731274SEdward Cree 
693bf969e8SEdward Cree int efx_mae_get_tables(struct efx_nic *efx);
703bf969e8SEdward Cree void efx_mae_free_tables(struct efx_nic *efx);
713bf969e8SEdward Cree 
727ce3e235SEdward Cree #define MAE_NUM_FIELDS	(MAE_FIELD_ENC_VNET_ID + 1)
737ce3e235SEdward Cree 
747ce3e235SEdward Cree struct mae_caps {
757ce3e235SEdward Cree 	u32 match_field_count;
7617654d84SEdward Cree 	u32 encap_types;
777ce3e235SEdward Cree 	u32 action_prios;
787ce3e235SEdward Cree 	u8 action_rule_fields[MAE_NUM_FIELDS];
79b9d5c9b7SEdward Cree 	u8 outer_rule_fields[MAE_NUM_FIELDS];
807ce3e235SEdward Cree };
817ce3e235SEdward Cree 
827ce3e235SEdward Cree int efx_mae_get_caps(struct efx_nic *efx, struct mae_caps *caps);
837ce3e235SEdward Cree 
84d902e1a7SEdward Cree int efx_mae_match_check_caps(struct efx_nic *efx,
85d902e1a7SEdward Cree 			     const struct efx_tc_match_fields *mask,
86d902e1a7SEdward Cree 			     struct netlink_ext_ack *extack);
8701ad088fSEdward Cree int efx_mae_match_check_caps_lhs(struct efx_nic *efx,
8801ad088fSEdward Cree 				 const struct efx_tc_match_fields *mask,
8901ad088fSEdward Cree 				 struct netlink_ext_ack *extack);
90b9d5c9b7SEdward Cree int efx_mae_check_encap_match_caps(struct efx_nic *efx, bool ipv6,
91b6583d5eSEdward Cree 				   u8 ip_tos_mask, __be16 udp_sport_mask,
92b9d5c9b7SEdward Cree 				   struct netlink_ext_ack *extack);
9317654d84SEdward Cree int efx_mae_check_encap_type_supported(struct efx_nic *efx,
9417654d84SEdward Cree 				       enum efx_encap_type typ);
95d902e1a7SEdward Cree 
960363aa29SEdward Cree int efx_mae_allocate_counter(struct efx_nic *efx, struct efx_tc_counter *cnt);
970363aa29SEdward Cree int efx_mae_free_counter(struct efx_nic *efx, struct efx_tc_counter *cnt);
980363aa29SEdward Cree 
99f1363154SEdward Cree int efx_mae_allocate_encap_md(struct efx_nic *efx,
100f1363154SEdward Cree 			      struct efx_tc_encap_action *encap);
101f1363154SEdward Cree int efx_mae_update_encap_md(struct efx_nic *efx,
102f1363154SEdward Cree 			    struct efx_tc_encap_action *encap);
103f1363154SEdward Cree int efx_mae_free_encap_md(struct efx_nic *efx,
104f1363154SEdward Cree 			  struct efx_tc_encap_action *encap);
105f1363154SEdward Cree 
106*439c4be9SPieter Jansen van Vuuren int efx_mae_allocate_pedit_mac(struct efx_nic *efx,
107*439c4be9SPieter Jansen van Vuuren 			       struct efx_tc_mac_pedit_action *ped);
108*439c4be9SPieter Jansen van Vuuren void efx_mae_free_pedit_mac(struct efx_nic *efx,
109*439c4be9SPieter Jansen van Vuuren 			    struct efx_tc_mac_pedit_action *ped);
11067ab160eSEdward Cree int efx_mae_alloc_action_set(struct efx_nic *efx, struct efx_tc_action_set *act);
11167ab160eSEdward Cree int efx_mae_free_action_set(struct efx_nic *efx, u32 fw_id);
11267ab160eSEdward Cree 
11367ab160eSEdward Cree int efx_mae_alloc_action_set_list(struct efx_nic *efx,
11467ab160eSEdward Cree 				  struct efx_tc_action_set_list *acts);
11567ab160eSEdward Cree int efx_mae_free_action_set_list(struct efx_nic *efx,
11667ab160eSEdward Cree 				 struct efx_tc_action_set_list *acts);
11767ab160eSEdward Cree 
1182245eb00SEdward Cree int efx_mae_register_encap_match(struct efx_nic *efx,
1192245eb00SEdward Cree 				 struct efx_tc_encap_match *encap);
1202245eb00SEdward Cree int efx_mae_unregister_encap_match(struct efx_nic *efx,
1212245eb00SEdward Cree 				   struct efx_tc_encap_match *encap);
12201ad088fSEdward Cree int efx_mae_insert_lhs_rule(struct efx_nic *efx, struct efx_tc_lhs_rule *rule,
12301ad088fSEdward Cree 			    u32 prio);
12401ad088fSEdward Cree int efx_mae_remove_lhs_rule(struct efx_nic *efx, struct efx_tc_lhs_rule *rule);
12594aa05bdSEdward Cree struct efx_tc_ct_entry; /* see tc_conntrack.h */
12694aa05bdSEdward Cree int efx_mae_insert_ct(struct efx_nic *efx, struct efx_tc_ct_entry *conn);
12794aa05bdSEdward Cree int efx_mae_remove_ct(struct efx_nic *efx, struct efx_tc_ct_entry *conn);
1282245eb00SEdward Cree 
12967ab160eSEdward Cree int efx_mae_insert_rule(struct efx_nic *efx, const struct efx_tc_match *match,
13067ab160eSEdward Cree 			u32 prio, u32 acts_id, u32 *id);
13169819d3bSEdward Cree int efx_mae_update_rule(struct efx_nic *efx, u32 acts_id, u32 id);
13267ab160eSEdward Cree int efx_mae_delete_rule(struct efx_nic *efx, u32 id);
13367ab160eSEdward Cree 
134a6a15acaSAlejandro Lucero int efx_init_mae(struct efx_nic *efx);
135a6a15acaSAlejandro Lucero void efx_fini_mae(struct efx_nic *efx);
136a6a15acaSAlejandro Lucero void efx_mae_remove_mport(void *desc, void *arg);
1375227adffSAlejandro Lucero int efx_mae_fw_lookup_mport(struct efx_nic *efx, u32 selector, u32 *id);
1385227adffSAlejandro Lucero int efx_mae_lookup_mport(struct efx_nic *efx, u32 vf, u32 *id);
139da56552dSEdward Cree #endif /* EF100_MAE_H */
140