Commit | Line | Data |
---|---|---|
93c1edb2 JP |
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 "cmd.h" | |
48 | ||
49 | #define MLXSW_MODULE_ALIAS_PREFIX "mlxsw-driver-" | |
50 | #define MODULE_MLXSW_DRIVER_ALIAS(kind) \ | |
51 | MODULE_ALIAS(MLXSW_MODULE_ALIAS_PREFIX kind) | |
52 | ||
53 | struct mlxsw_core; | |
54 | struct mlxsw_driver; | |
55 | struct mlxsw_bus; | |
56 | struct mlxsw_bus_info; | |
57 | ||
58 | int mlxsw_core_driver_register(struct mlxsw_driver *mlxsw_driver); | |
59 | void mlxsw_core_driver_unregister(struct mlxsw_driver *mlxsw_driver); | |
60 | ||
61 | int mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, | |
62 | const struct mlxsw_bus *mlxsw_bus, | |
63 | void *bus_priv); | |
64 | void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core); | |
65 | ||
66 | struct mlxsw_tx_info { | |
67 | u8 local_port; | |
68 | bool is_emad; | |
69 | }; | |
70 | ||
71 | int mlxsw_core_skb_transmit(void *driver_priv, struct sk_buff *skb, | |
72 | const struct mlxsw_tx_info *tx_info); | |
73 | ||
74 | struct mlxsw_rx_listener { | |
75 | void (*func)(struct sk_buff *skb, u8 local_port, void *priv); | |
76 | u8 local_port; | |
77 | u16 trap_id; | |
78 | }; | |
79 | ||
80 | int mlxsw_core_rx_listener_register(struct mlxsw_core *mlxsw_core, | |
81 | const struct mlxsw_rx_listener *rxl, | |
82 | void *priv); | |
83 | void mlxsw_core_rx_listener_unregister(struct mlxsw_core *mlxsw_core, | |
84 | const struct mlxsw_rx_listener *rxl, | |
85 | void *priv); | |
86 | ||
87 | struct mlxsw_rx_info { | |
88 | u16 sys_port; | |
89 | int trap_id; | |
90 | }; | |
91 | ||
92 | void mlxsw_core_skb_receive(struct mlxsw_core *mlxsw_core, struct sk_buff *skb, | |
93 | struct mlxsw_rx_info *rx_info); | |
94 | ||
95 | #define MLXSW_CONFIG_PROFILE_SWID_COUNT 8 | |
96 | ||
97 | struct mlxsw_swid_config { | |
98 | u8 used_type:1, | |
99 | used_properties:1; | |
100 | u8 type; | |
101 | u8 properties; | |
102 | }; | |
103 | ||
104 | struct mlxsw_config_profile { | |
105 | u16 used_max_vepa_channels:1, | |
106 | used_max_lag:1, | |
107 | used_max_port_per_lag:1, | |
108 | used_max_mid:1, | |
109 | used_max_pgt:1, | |
110 | used_max_system_port:1, | |
111 | used_max_vlan_groups:1, | |
112 | used_max_regions:1, | |
113 | used_flood_tables:1, | |
114 | used_flood_mode:1, | |
115 | used_max_ib_mc:1, | |
116 | used_max_pkey:1, | |
117 | used_ar_sec:1, | |
118 | used_adaptive_routing_group_cap:1; | |
119 | u8 max_vepa_channels; | |
120 | u16 max_lag; | |
121 | u16 max_port_per_lag; | |
122 | u16 max_mid; | |
123 | u16 max_pgt; | |
124 | u16 max_system_port; | |
125 | u16 max_vlan_groups; | |
126 | u16 max_regions; | |
127 | u8 max_flood_tables; | |
128 | u8 max_vid_flood_tables; | |
129 | u8 flood_mode; | |
130 | u16 max_ib_mc; | |
131 | u16 max_pkey; | |
132 | u8 ar_sec; | |
133 | u16 adaptive_routing_group_cap; | |
134 | u8 arn; | |
135 | struct mlxsw_swid_config swid_config[MLXSW_CONFIG_PROFILE_SWID_COUNT]; | |
136 | }; | |
137 | ||
138 | struct mlxsw_driver { | |
139 | struct list_head list; | |
140 | const char *kind; | |
141 | struct module *owner; | |
142 | size_t priv_size; | |
143 | int (*init)(void *driver_priv, struct mlxsw_core *mlxsw_core, | |
144 | const struct mlxsw_bus_info *mlxsw_bus_info); | |
145 | void (*fini)(void *driver_priv); | |
146 | void (*txhdr_construct)(struct sk_buff *skb, | |
147 | const struct mlxsw_tx_info *tx_info); | |
148 | u8 txhdr_len; | |
149 | const struct mlxsw_config_profile *profile; | |
150 | }; | |
151 | ||
152 | struct mlxsw_bus { | |
153 | const char *kind; | |
154 | int (*init)(void *bus_priv, struct mlxsw_core *mlxsw_core, | |
155 | const struct mlxsw_config_profile *profile); | |
156 | void (*fini)(void *bus_priv); | |
157 | int (*skb_transmit)(void *bus_priv, struct sk_buff *skb, | |
158 | const struct mlxsw_tx_info *tx_info); | |
159 | int (*cmd_exec)(void *bus_priv, u16 opcode, u8 opcode_mod, | |
160 | u32 in_mod, bool out_mbox_direct, | |
161 | char *in_mbox, size_t in_mbox_size, | |
162 | char *out_mbox, size_t out_mbox_size, | |
163 | u8 *p_status); | |
164 | }; | |
165 | ||
166 | struct mlxsw_bus_info { | |
167 | const char *device_kind; | |
168 | const char *device_name; | |
169 | struct device *dev; | |
170 | struct { | |
171 | u16 major; | |
172 | u16 minor; | |
173 | u16 subminor; | |
174 | } fw_rev; | |
175 | u8 vsd[MLXSW_CMD_BOARDINFO_VSD_LEN]; | |
176 | u8 psid[MLXSW_CMD_BOARDINFO_PSID_LEN]; | |
177 | }; | |
178 | ||
179 | #endif |