xref: /linux/drivers/net/ethernet/mellanox/mlxsw/core.h (revision ca55b2fef3a9373fcfc30f82fd26bc7fccbda732)
1 /*
2  * drivers/net/ethernet/mellanox/mlxsw/core.h
3  * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
4  * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
5  * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
6  * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the names of the copyright holders nor the names of its
17  *    contributors may be used to endorse or promote products derived from
18  *    this software without specific prior written permission.
19  *
20  * Alternatively, this software may be distributed under the terms of the
21  * GNU General Public License ("GPL") version 2 as published by the Free
22  * Software Foundation.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #ifndef _MLXSW_CORE_H
38 #define _MLXSW_CORE_H
39 
40 #include <linux/module.h>
41 #include <linux/device.h>
42 #include <linux/slab.h>
43 #include <linux/gfp.h>
44 #include <linux/types.h>
45 #include <linux/skbuff.h>
46 
47 #include "trap.h"
48 #include "reg.h"
49 
50 #include "cmd.h"
51 
52 #define MLXSW_MODULE_ALIAS_PREFIX "mlxsw-driver-"
53 #define MODULE_MLXSW_DRIVER_ALIAS(kind)	\
54 	MODULE_ALIAS(MLXSW_MODULE_ALIAS_PREFIX kind)
55 
56 #define MLXSW_DEVICE_KIND_SWITCHX2 "switchx2"
57 
58 struct mlxsw_core;
59 struct mlxsw_driver;
60 struct mlxsw_bus;
61 struct mlxsw_bus_info;
62 
63 int mlxsw_core_driver_register(struct mlxsw_driver *mlxsw_driver);
64 void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver);
65 
66 int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info,
67 				   const struct mlxsw_bus *mlxsw_bus,
68 				   void *bus_priv);
69 void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core);
70 
71 struct mlxsw_tx_info {
72 	u8 local_port;
73 	bool is_emad;
74 };
75 
76 bool mlxsw_core_skb_transmit_busy(void *driver_priv,
77 				  const struct mlxsw_tx_info *tx_info);
78 
79 int mlxsw_core_skb_transmit(void *driver_priv, struct sk_buff *skb,
80 			    const struct mlxsw_tx_info *tx_info);
81 
82 struct mlxsw_rx_listener {
83 	void (*func)(struct sk_buff *skb, u8 local_port, void *priv);
84 	u8 local_port;
85 	u16 trap_id;
86 };
87 
88 struct mlxsw_event_listener {
89 	void (*func)(const struct mlxsw_reg_info *reg,
90 		     char *payload, void *priv);
91 	enum mlxsw_event_trap_id trap_id;
92 };
93 
94 int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core,
95 				    const struct mlxsw_rx_listener *rxl,
96 				    void *priv);
97 void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core,
98 				       const struct mlxsw_rx_listener *rxl,
99 				       void *priv);
100 
101 int mlxsw_core_event_listener_register(struct mlxsw_core *mlxsw_core,
102 				       const struct mlxsw_event_listener *el,
103 				       void *priv);
104 void mlxsw_core_event_listener_unregister(struct mlxsw_core *mlxsw_core,
105 					  const struct mlxsw_event_listener *el,
106 					  void *priv);
107 
108 int mlxsw_reg_query(struct mlxsw_core *mlxsw_core,
109 		    const struct mlxsw_reg_info *reg, char *payload);
110 int mlxsw_reg_write(struct mlxsw_core *mlxsw_core,
111 		    const struct mlxsw_reg_info *reg, char *payload);
112 
113 struct mlxsw_rx_info {
114 	u16 sys_port;
115 	int trap_id;
116 };
117 
118 void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb,
119 			    struct mlxsw_rx_info *rx_info);
120 
121 #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8
122 
123 struct mlxsw_swid_config {
124 	u8	used_type:1,
125 		used_properties:1;
126 	u8	type;
127 	u8	properties;
128 };
129 
130 struct mlxsw_config_profile {
131 	u16	used_max_vepa_channels:1,
132 		used_max_lag:1,
133 		used_max_port_per_lag:1,
134 		used_max_mid:1,
135 		used_max_pgt:1,
136 		used_max_system_port:1,
137 		used_max_vlan_groups:1,
138 		used_max_regions:1,
139 		used_flood_tables:1,
140 		used_flood_mode:1,
141 		used_max_ib_mc:1,
142 		used_max_pkey:1,
143 		used_ar_sec:1,
144 		used_adaptive_routing_group_cap:1;
145 	u8	max_vepa_channels;
146 	u16	max_lag;
147 	u16	max_port_per_lag;
148 	u16	max_mid;
149 	u16	max_pgt;
150 	u16	max_system_port;
151 	u16	max_vlan_groups;
152 	u16	max_regions;
153 	u8	max_flood_tables;
154 	u8	max_vid_flood_tables;
155 	u8	flood_mode;
156 	u16	max_ib_mc;
157 	u16	max_pkey;
158 	u8	ar_sec;
159 	u16	adaptive_routing_group_cap;
160 	u8	arn;
161 	struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT];
162 };
163 
164 struct mlxsw_driver {
165 	struct list_head list;
166 	const char *kind;
167 	struct module *owner;
168 	size_t priv_size;
169 	int (*init)(void *driver_priv, struct mlxsw_core *mlxsw_core,
170 		    const struct mlxsw_bus_info *mlxsw_bus_info);
171 	void (*fini)(void *driver_priv);
172 	void (*txhdr_construct)(struct sk_buff *skb,
173 				const struct mlxsw_tx_info *tx_info);
174 	u8 txhdr_len;
175 	const struct mlxsw_config_profile *profile;
176 };
177 
178 struct mlxsw_bus {
179 	const char *kind;
180 	int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core,
181 		    const struct mlxsw_config_profile *profile);
182 	void (*fini)(void *bus_priv);
183 	bool (*skb_transmit_busy)(void *bus_priv,
184 				  const struct mlxsw_tx_info *tx_info);
185 	int (*skb_transmit)(void *bus_priv, struct sk_buff *skb,
186 			    const struct mlxsw_tx_info *tx_info);
187 	int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod,
188 			u32 in_mod, bool out_mbox_direct,
189 			char *in_mbox, size_t in_mbox_size,
190 			char *out_mbox, size_t out_mbox_size,
191 			u8 *p_status);
192 };
193 
194 struct mlxsw_bus_info {
195 	const char *device_kind;
196 	const char *device_name;
197 	struct device *dev;
198 	struct {
199 		u16 major;
200 		u16 minor;
201 		u16 subminor;
202 	} fw_rev;
203 	u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN];
204 	u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN];
205 };
206 
207 #endif
208