Commit | Line | Data |
---|---|---|
afd4aea0 BH |
1 | /**************************************************************************** |
2 | * Driver for Solarflare Solarstorm network controllers and boards | |
0a6f40c6 | 3 | * Copyright 2008-2010 Solarflare Communications Inc. |
afd4aea0 BH |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms of the GNU General Public License version 2 as published | |
7 | * by the Free Software Foundation, incorporated herein by reference. | |
8 | */ | |
9 | ||
10 | #ifndef EFX_MCDI_H | |
11 | #define EFX_MCDI_H | |
12 | ||
13 | /** | |
f76fe120 | 14 | * enum efx_mcdi_state - MCDI request handling state |
afd4aea0 | 15 | * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the |
f76fe120 | 16 | * mcdi @iface_lock then they are able to move to %MCDI_STATE_RUNNING |
afd4aea0 BH |
17 | * @MCDI_STATE_RUNNING: There is an MCDI request pending. Only the thread that |
18 | * moved into this state is allowed to move out of it. | |
19 | * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread | |
20 | * has not yet consumed the result. For all other threads, equivalent to | |
f76fe120 | 21 | * %MCDI_STATE_RUNNING. |
afd4aea0 BH |
22 | */ |
23 | enum efx_mcdi_state { | |
24 | MCDI_STATE_QUIESCENT, | |
25 | MCDI_STATE_RUNNING, | |
26 | MCDI_STATE_COMPLETED, | |
27 | }; | |
28 | ||
29 | enum efx_mcdi_mode { | |
30 | MCDI_MODE_POLL, | |
31 | MCDI_MODE_EVENTS, | |
32 | }; | |
33 | ||
34 | /** | |
f76fe120 BH |
35 | * struct efx_mcdi_iface - MCDI protocol context |
36 | * @state: Request handling state. Waited for by @wq. | |
afd4aea0 | 37 | * @mode: Poll for mcdi completion, or wait for an mcdi_event. |
f76fe120 BH |
38 | * @wq: Wait queue for threads waiting for @state != %MCDI_STATE_RUNNING |
39 | * @iface_lock: Serialises access to all the following fields | |
afd4aea0 | 40 | * @seqno: The next sequence number to use for mcdi requests. |
afd4aea0 | 41 | * @credits: Number of spurious MCDI completion events allowed before we |
f76fe120 | 42 | * trigger a fatal error |
5bc283e5 | 43 | * @resprc: Response error/success code (Linux numbering) |
df2cd8af BH |
44 | * @resp_hdr_len: Response header length |
45 | * @resp_data_len: Response data (SDU or error) length | |
afd4aea0 BH |
46 | */ |
47 | struct efx_mcdi_iface { | |
48 | atomic_t state; | |
f76fe120 | 49 | enum efx_mcdi_mode mode; |
afd4aea0 BH |
50 | wait_queue_head_t wq; |
51 | spinlock_t iface_lock; | |
afd4aea0 BH |
52 | unsigned int credits; |
53 | unsigned int seqno; | |
5bc283e5 | 54 | int resprc; |
df2cd8af BH |
55 | size_t resp_hdr_len; |
56 | size_t resp_data_len; | |
afd4aea0 BH |
57 | }; |
58 | ||
55c5e0f8 BH |
59 | struct efx_mcdi_mon { |
60 | struct efx_buffer dma_buf; | |
61 | struct mutex update_lock; | |
62 | unsigned long last_update; | |
63 | struct device *device; | |
64 | struct efx_mcdi_mon_attribute *attrs; | |
65 | unsigned int n_attrs; | |
66 | }; | |
67 | ||
45a3fd55 BH |
68 | struct efx_mcdi_mtd_partition { |
69 | struct efx_mtd_partition common; | |
70 | bool updating; | |
71 | u8 nvram_type; | |
72 | u16 fw_subtype; | |
73 | }; | |
74 | ||
75 | #define to_efx_mcdi_mtd_partition(mtd) \ | |
76 | container_of(mtd, struct efx_mcdi_mtd_partition, common.mtd) | |
77 | ||
f3ad5003 BH |
78 | /** |
79 | * struct efx_mcdi_data - extra state for NICs that implement MCDI | |
80 | * @iface: Interface/protocol state | |
81 | * @hwmon: Hardware monitor state | |
82 | */ | |
83 | struct efx_mcdi_data { | |
84 | struct efx_mcdi_iface iface; | |
85 | #ifdef CONFIG_SFC_MCDI_MON | |
86 | struct efx_mcdi_mon hwmon; | |
87 | #endif | |
88 | }; | |
89 | ||
90 | #ifdef CONFIG_SFC_MCDI_MON | |
91 | static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx) | |
92 | { | |
93 | EFX_BUG_ON_PARANOID(!efx->mcdi); | |
94 | return &efx->mcdi->hwmon; | |
95 | } | |
96 | #endif | |
97 | ||
f073dde0 | 98 | extern int efx_mcdi_init(struct efx_nic *efx); |
f3ad5003 | 99 | extern void efx_mcdi_fini(struct efx_nic *efx); |
afd4aea0 | 100 | |
9528b921 BH |
101 | extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, |
102 | const efx_dword_t *inbuf, size_t inlen, | |
103 | efx_dword_t *outbuf, size_t outlen, | |
afd4aea0 BH |
104 | size_t *outlen_actual); |
105 | ||
df2cd8af BH |
106 | extern int efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd, |
107 | const efx_dword_t *inbuf, size_t inlen); | |
c3cba721 | 108 | extern int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen, |
9528b921 | 109 | efx_dword_t *outbuf, size_t outlen, |
c3cba721 SH |
110 | size_t *outlen_actual); |
111 | ||
9528b921 | 112 | |
afd4aea0 BH |
113 | extern int efx_mcdi_poll_reboot(struct efx_nic *efx); |
114 | extern void efx_mcdi_mode_poll(struct efx_nic *efx); | |
115 | extern void efx_mcdi_mode_event(struct efx_nic *efx); | |
116 | ||
117 | extern void efx_mcdi_process_event(struct efx_channel *channel, | |
118 | efx_qword_t *event); | |
55c5e0f8 | 119 | extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); |
afd4aea0 | 120 | |
9528b921 | 121 | /* We expect that 16- and 32-bit fields in MCDI requests and responses |
338f74df BH |
122 | * are appropriately aligned, but 64-bit fields are only |
123 | * 32-bit-aligned. Also, on Siena we must copy to the MC shared | |
124 | * memory strictly 32 bits at a time, so add any necessary padding. | |
9528b921 | 125 | */ |
59cfc479 | 126 | #define MCDI_DECLARE_BUF(_name, _len) \ |
9528b921 | 127 | efx_dword_t _name[DIV_ROUND_UP(_len, 4)] |
a649dfcb BH |
128 | #define _MCDI_PTR(_buf, _offset) \ |
129 | ((u8 *)(_buf) + (_offset)) | |
30af6910 | 130 | #define MCDI_PTR(_buf, _field) \ |
a649dfcb | 131 | _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST) |
9528b921 BH |
132 | #define _MCDI_CHECK_ALIGN(_ofst, _align) \ |
133 | ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1))) | |
30af6910 | 134 | #define _MCDI_DWORD(_buf, _field) \ |
9528b921 | 135 | ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2)) |
59cfc479 | 136 | |
30af6910 BH |
137 | #define MCDI_SET_DWORD(_buf, _field, _value) \ |
138 | EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value) | |
139 | #define MCDI_DWORD(_buf, _field) \ | |
140 | EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0) | |
f5253d92 BH |
141 | #define MCDI_POPULATE_DWORD_1(_buf, _field, _name1, _value1) \ |
142 | EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), \ | |
143 | MC_CMD_ ## _name1, _value1) | |
144 | #define MCDI_POPULATE_DWORD_2(_buf, _field, _name1, _value1, \ | |
145 | _name2, _value2) \ | |
146 | EFX_POPULATE_DWORD_2(*_MCDI_DWORD(_buf, _field), \ | |
147 | MC_CMD_ ## _name1, _value1, \ | |
148 | MC_CMD_ ## _name2, _value2) | |
149 | #define MCDI_POPULATE_DWORD_3(_buf, _field, _name1, _value1, \ | |
150 | _name2, _value2, _name3, _value3) \ | |
151 | EFX_POPULATE_DWORD_3(*_MCDI_DWORD(_buf, _field), \ | |
152 | MC_CMD_ ## _name1, _value1, \ | |
153 | MC_CMD_ ## _name2, _value2, \ | |
154 | MC_CMD_ ## _name3, _value3) | |
155 | #define MCDI_POPULATE_DWORD_4(_buf, _field, _name1, _value1, \ | |
156 | _name2, _value2, _name3, _value3, \ | |
157 | _name4, _value4) \ | |
158 | EFX_POPULATE_DWORD_4(*_MCDI_DWORD(_buf, _field), \ | |
159 | MC_CMD_ ## _name1, _value1, \ | |
160 | MC_CMD_ ## _name2, _value2, \ | |
161 | MC_CMD_ ## _name3, _value3, \ | |
162 | MC_CMD_ ## _name4, _value4) | |
163 | #define MCDI_POPULATE_DWORD_5(_buf, _field, _name1, _value1, \ | |
164 | _name2, _value2, _name3, _value3, \ | |
165 | _name4, _value4, _name5, _value5) \ | |
166 | EFX_POPULATE_DWORD_5(*_MCDI_DWORD(_buf, _field), \ | |
167 | MC_CMD_ ## _name1, _value1, \ | |
168 | MC_CMD_ ## _name2, _value2, \ | |
169 | MC_CMD_ ## _name3, _value3, \ | |
170 | MC_CMD_ ## _name4, _value4, \ | |
171 | MC_CMD_ ## _name5, _value5) | |
172 | #define MCDI_POPULATE_DWORD_6(_buf, _field, _name1, _value1, \ | |
173 | _name2, _value2, _name3, _value3, \ | |
174 | _name4, _value4, _name5, _value5, \ | |
175 | _name6, _value6) \ | |
176 | EFX_POPULATE_DWORD_6(*_MCDI_DWORD(_buf, _field), \ | |
177 | MC_CMD_ ## _name1, _value1, \ | |
178 | MC_CMD_ ## _name2, _value2, \ | |
179 | MC_CMD_ ## _name3, _value3, \ | |
180 | MC_CMD_ ## _name4, _value4, \ | |
181 | MC_CMD_ ## _name5, _value5, \ | |
182 | MC_CMD_ ## _name6, _value6) | |
183 | #define MCDI_POPULATE_DWORD_7(_buf, _field, _name1, _value1, \ | |
184 | _name2, _value2, _name3, _value3, \ | |
185 | _name4, _value4, _name5, _value5, \ | |
186 | _name6, _value6, _name7, _value7) \ | |
187 | EFX_POPULATE_DWORD_7(*_MCDI_DWORD(_buf, _field), \ | |
188 | MC_CMD_ ## _name1, _value1, \ | |
189 | MC_CMD_ ## _name2, _value2, \ | |
190 | MC_CMD_ ## _name3, _value3, \ | |
191 | MC_CMD_ ## _name4, _value4, \ | |
192 | MC_CMD_ ## _name5, _value5, \ | |
193 | MC_CMD_ ## _name6, _value6, \ | |
194 | MC_CMD_ ## _name7, _value7) | |
338f74df BH |
195 | #define MCDI_SET_QWORD(_buf, _field, _value) \ |
196 | do { \ | |
197 | EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \ | |
198 | EFX_DWORD_0, (u32)(_value)); \ | |
199 | EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \ | |
200 | EFX_DWORD_0, (u64)(_value) >> 32); \ | |
201 | } while (0) | |
30af6910 BH |
202 | #define MCDI_QWORD(_buf, _field) \ |
203 | (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \ | |
204 | (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32) | |
a649dfcb BH |
205 | #define MCDI_FIELD(_ptr, _type, _field) \ |
206 | EFX_EXTRACT_DWORD( \ | |
207 | *(efx_dword_t *) \ | |
208 | _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\ | |
209 | MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \ | |
210 | (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \ | |
211 | MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1) | |
30af6910 | 212 | |
9528b921 BH |
213 | #define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \ |
214 | (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\ | |
215 | + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align)) | |
a649dfcb | 216 | #define MCDI_DECLARE_STRUCT_PTR(_name) \ |
9528b921 BH |
217 | efx_dword_t *_name |
218 | #define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \ | |
219 | ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) | |
a649dfcb BH |
220 | #define MCDI_VAR_ARRAY_LEN(_len, _field) \ |
221 | min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \ | |
222 | ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN) | |
223 | #define MCDI_ARRAY_WORD(_buf, _field, _index) \ | |
224 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \ | |
225 | le16_to_cpu(*(__force const __le16 *) \ | |
9528b921 | 226 | _MCDI_ARRAY_PTR(_buf, _field, _index, 2))) |
a649dfcb BH |
227 | #define _MCDI_ARRAY_DWORD(_buf, _field, _index) \ |
228 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \ | |
9528b921 | 229 | (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) |
a649dfcb BH |
230 | #define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \ |
231 | EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \ | |
232 | EFX_DWORD_0, _value) | |
233 | #define MCDI_ARRAY_DWORD(_buf, _field, _index) \ | |
234 | EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0) | |
338f74df BH |
235 | #define _MCDI_ARRAY_QWORD(_buf, _field, _index) \ |
236 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \ | |
237 | (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) | |
238 | #define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \ | |
239 | do { \ | |
240 | EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\ | |
241 | EFX_DWORD_0, (u32)(_value)); \ | |
242 | EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\ | |
243 | EFX_DWORD_0, (u64)(_value) >> 32); \ | |
244 | } while (0) | |
55c5e0f8 | 245 | #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \ |
a649dfcb BH |
246 | MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \ |
247 | _type ## _TYPEDEF, _field2) | |
afd4aea0 | 248 | |
30af6910 BH |
249 | #define MCDI_EVENT_FIELD(_ev, _field) \ |
250 | EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field) | |
251 | ||
e5f0fd27 | 252 | extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len); |
afd4aea0 BH |
253 | extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating, |
254 | bool *was_attached_out); | |
255 | extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address, | |
6aa9c7f6 | 256 | u16 *fw_subtype_list, u32 *capabilities); |
afd4aea0 BH |
257 | extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, |
258 | u32 dest_evq); | |
259 | extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out); | |
260 | extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type, | |
261 | size_t *size_out, size_t *erase_size_out, | |
262 | bool *protected_out); | |
2e803407 | 263 | extern int efx_mcdi_nvram_test_all(struct efx_nic *efx); |
afd4aea0 BH |
264 | extern int efx_mcdi_handle_assertion(struct efx_nic *efx); |
265 | extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode); | |
afd4aea0 BH |
266 | extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, |
267 | const u8 *mac, int *id_out); | |
268 | extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out); | |
269 | extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id); | |
270 | extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx); | |
cd2d5b52 | 271 | extern int efx_mcdi_flush_rxqs(struct efx_nic *efx); |
43f775b2 BH |
272 | extern int efx_mcdi_port_probe(struct efx_nic *efx); |
273 | extern void efx_mcdi_port_remove(struct efx_nic *efx); | |
274 | extern int efx_mcdi_port_reconfigure(struct efx_nic *efx); | |
275 | extern void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev); | |
cd2d5b52 | 276 | extern int efx_mcdi_set_mac(struct efx_nic *efx); |
43f775b2 BH |
277 | #define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1)) |
278 | extern void efx_mcdi_mac_start_stats(struct efx_nic *efx); | |
279 | extern void efx_mcdi_mac_stop_stats(struct efx_nic *efx); | |
710b208d | 280 | extern bool efx_mcdi_mac_check_fault(struct efx_nic *efx); |
6bff861d BH |
281 | extern enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason); |
282 | extern int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method); | |
afd4aea0 | 283 | |
55c5e0f8 BH |
284 | #ifdef CONFIG_SFC_MCDI_MON |
285 | extern int efx_mcdi_mon_probe(struct efx_nic *efx); | |
286 | extern void efx_mcdi_mon_remove(struct efx_nic *efx); | |
287 | #else | |
288 | static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; } | |
289 | static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {} | |
290 | #endif | |
291 | ||
45a3fd55 BH |
292 | #ifdef CONFIG_SFC_MTD |
293 | extern int efx_mcdi_mtd_read(struct mtd_info *mtd, loff_t start, | |
294 | size_t len, size_t *retlen, u8 *buffer); | |
295 | extern int efx_mcdi_mtd_erase(struct mtd_info *mtd, loff_t start, size_t len); | |
296 | extern int efx_mcdi_mtd_write(struct mtd_info *mtd, loff_t start, | |
297 | size_t len, size_t *retlen, const u8 *buffer); | |
298 | extern int efx_mcdi_mtd_sync(struct mtd_info *mtd); | |
299 | extern void efx_mcdi_mtd_rename(struct efx_mtd_partition *part); | |
300 | #endif | |
301 | ||
afd4aea0 | 302 | #endif /* EFX_MCDI_H */ |