xref: /dpdk/drivers/net/sfc/sfc_switch.h (revision ef96f7eb4cce942d5a10de0c8ceab21ebe7d17c3)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2019-2021 Xilinx, Inc.
4  * Copyright(c) 2019 Solarflare Communications Inc.
5  *
6  * This software was jointly developed between OKTET Labs (under contract
7  * for Solarflare) and Solarflare Communications, Inc.
8  */
9 
10 #ifndef _SFC_SWITCH_H
11 #define _SFC_SWITCH_H
12 
13 #include <stdint.h>
14 
15 #include "efx.h"
16 
17 #include "sfc.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /** Options for MAE switch port type */
24 enum sfc_mae_switch_port_type {
25 	/**
26 	 * The switch port is operated by a self-sufficient RTE ethdev
27 	 * and thus refers to its underlying PCIe function
28 	 */
29 	SFC_MAE_SWITCH_PORT_INDEPENDENT = 0,
30 	/**
31 	 * The switch port is operated by a representor RTE ethdev
32 	 * and thus refers to the represented PCIe function
33 	 */
34 	SFC_MAE_SWITCH_PORT_REPRESENTOR,
35 };
36 
37 struct sfc_mae_switch_port_indep_data {
38 	bool					mae_admin;
39 };
40 
41 struct sfc_mae_switch_port_repr_data {
42 	efx_pcie_interface_t			intf;
43 	uint16_t				pf;
44 	uint16_t				vf;
45 };
46 
47 union sfc_mae_switch_port_data {
48 	struct sfc_mae_switch_port_indep_data	indep;
49 	struct sfc_mae_switch_port_repr_data	repr;
50 };
51 
52 struct sfc_mae_switch_port_request {
53 	enum sfc_mae_switch_port_type		type;
54 	const efx_mport_sel_t			*entity_mportp;
55 	const efx_mport_sel_t			*ethdev_mportp;
56 	uint16_t				ethdev_port_id;
57 	union sfc_mae_switch_port_data		port_data;
58 };
59 
60 typedef void (sfc_mae_switch_port_iterator_cb)(
61 		enum sfc_mae_switch_port_type type,
62 		const efx_mport_sel_t *ethdev_mportp,
63 		uint16_t ethdev_port_id,
64 		const efx_mport_sel_t *entity_mportp,
65 		uint16_t switch_port_id,
66 		union sfc_mae_switch_port_data *port_datap,
67 		void *user_datap);
68 
69 int sfc_mae_switch_ports_iterate(uint16_t switch_domain_id,
70 				 sfc_mae_switch_port_iterator_cb *cb,
71 				 void *data);
72 
73 int sfc_mae_assign_switch_domain(struct sfc_adapter *sa,
74 				 uint16_t *switch_domain_id);
75 
76 int sfc_mae_switch_domain_controllers(uint16_t switch_domain_id,
77 				      const efx_pcie_interface_t **controllers,
78 				      size_t *nb_controllers);
79 
80 int sfc_mae_switch_domain_map_controllers(uint16_t switch_domain_id,
81 					  efx_pcie_interface_t *controllers,
82 					  size_t nb_controllers);
83 
84 int sfc_mae_switch_controller_from_mapping(
85 		const efx_pcie_interface_t *controllers,
86 		size_t nb_controllers,
87 		efx_pcie_interface_t intf,
88 		int *controller);
89 
90 int sfc_mae_switch_domain_get_controller(uint16_t switch_domain_id,
91 				   efx_pcie_interface_t intf,
92 				   int *controller);
93 
94 int sfc_mae_switch_domain_get_intf(uint16_t switch_domain_id,
95 				   int controller,
96 				   efx_pcie_interface_t *intf);
97 
98 int sfc_mae_assign_switch_port(uint16_t switch_domain_id,
99 			       const struct sfc_mae_switch_port_request *req,
100 			       uint16_t *switch_port_id);
101 
102 int sfc_mae_clear_switch_port(uint16_t switch_domain_id,
103 			      uint16_t switch_port_id);
104 
105 /*
106  * For user flows, allowed_mae_switch_port_types can only contain bit
107  * SFC_MAE_SWITCH_PORT_INDEPENDENT, meaning that only those ethdevs
108  * that have their own MAE m-ports can be accessed by a port-based
109  * action. For driver-internal flows, this mask can also contain
110  * bit SFC_MAE_SWITCH_PORT_REPRESENTOR to allow VF traffic to be
111  * sent to the common MAE m-port of all such REPRESENTOR ports
112  * via a port-based action, for default switch interconnection.
113  */
114 int sfc_mae_switch_get_ethdev_mport(uint16_t switch_domain_id,
115 				    uint16_t ethdev_port_id,
116 				    unsigned int allowed_mae_switch_port_types,
117 				    efx_mport_sel_t *mport_sel);
118 
119 int sfc_mae_switch_get_entity_mport(uint16_t switch_domain_id,
120 				    uint16_t ethdev_port_id,
121 				    efx_mport_sel_t *mport_sel);
122 
123 int sfc_mae_switch_port_id_by_entity(uint16_t switch_domain_id,
124 				     const efx_mport_sel_t *entity_mportp,
125 				     enum sfc_mae_switch_port_type type,
126 				     uint16_t *switch_port_id);
127 
128 int sfc_mae_get_switch_domain_admin(uint16_t switch_domain_id,
129 				    uint16_t *port_id);
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 #endif /* _SFC_SWITCH_H */
135