net/mlx5_core: Print resource number on QP/SRQ async events
[deliverable/linux.git] / drivers / net / ethernet / sfc / mcdi.h
CommitLineData
afd4aea0 1/****************************************************************************
f7a6d2c4
BH
2 * Driver for Solarflare network controllers and boards
3 * Copyright 2008-2013 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
cade715f
BH
17 * @MCDI_STATE_RUNNING_SYNC: There is a synchronous MCDI request pending.
18 * Only the thread that moved into this state is allowed to move out of it.
19 * @MCDI_STATE_RUNNING_ASYNC: There is an asynchronous MCDI request pending.
afd4aea0
BH
20 * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread
21 * has not yet consumed the result. For all other threads, equivalent to
f76fe120 22 * %MCDI_STATE_RUNNING.
afd4aea0
BH
23 */
24enum efx_mcdi_state {
25 MCDI_STATE_QUIESCENT,
cade715f
BH
26 MCDI_STATE_RUNNING_SYNC,
27 MCDI_STATE_RUNNING_ASYNC,
afd4aea0
BH
28 MCDI_STATE_COMPLETED,
29};
30
e283546c
EC
31/**
32 * enum efx_mcdi_mode - MCDI transaction mode
33 * @MCDI_MODE_POLL: poll for MCDI completion, until timeout
34 * @MCDI_MODE_EVENTS: wait for an mcdi_event. On timeout, poll once
35 * @MCDI_MODE_FAIL: we think MCDI is dead, so fail-fast all calls
36 */
afd4aea0
BH
37enum efx_mcdi_mode {
38 MCDI_MODE_POLL,
39 MCDI_MODE_EVENTS,
e283546c 40 MCDI_MODE_FAIL,
afd4aea0
BH
41};
42
43/**
f76fe120 44 * struct efx_mcdi_iface - MCDI protocol context
cade715f 45 * @efx: The associated NIC.
f76fe120 46 * @state: Request handling state. Waited for by @wq.
afd4aea0 47 * @mode: Poll for mcdi completion, or wait for an mcdi_event.
f76fe120 48 * @wq: Wait queue for threads waiting for @state != %MCDI_STATE_RUNNING
d36a08b4 49 * @new_epoch: Indicates start of day or start of MC reboot recovery
cade715f 50 * @iface_lock: Serialises access to @seqno, @credits and response metadata
afd4aea0 51 * @seqno: The next sequence number to use for mcdi requests.
afd4aea0 52 * @credits: Number of spurious MCDI completion events allowed before we
f76fe120 53 * trigger a fatal error
5bc283e5 54 * @resprc: Response error/success code (Linux numbering)
df2cd8af
BH
55 * @resp_hdr_len: Response header length
56 * @resp_data_len: Response data (SDU or error) length
cade715f
BH
57 * @async_lock: Serialises access to @async_list while event processing is
58 * enabled
59 * @async_list: Queue of asynchronous requests
60 * @async_timer: Timer for asynchronous request timeout
afd4aea0
BH
61 */
62struct efx_mcdi_iface {
cade715f 63 struct efx_nic *efx;
251111d9 64 enum efx_mcdi_state state;
f76fe120 65 enum efx_mcdi_mode mode;
afd4aea0
BH
66 wait_queue_head_t wq;
67 spinlock_t iface_lock;
d36a08b4 68 bool new_epoch;
afd4aea0
BH
69 unsigned int credits;
70 unsigned int seqno;
5bc283e5 71 int resprc;
df2cd8af
BH
72 size_t resp_hdr_len;
73 size_t resp_data_len;
cade715f
BH
74 spinlock_t async_lock;
75 struct list_head async_list;
76 struct timer_list async_timer;
afd4aea0
BH
77};
78
55c5e0f8
BH
79struct efx_mcdi_mon {
80 struct efx_buffer dma_buf;
81 struct mutex update_lock;
82 unsigned long last_update;
83 struct device *device;
84 struct efx_mcdi_mon_attribute *attrs;
85493e6d
GR
85 struct attribute_group group;
86 const struct attribute_group *groups[2];
55c5e0f8
BH
87 unsigned int n_attrs;
88};
89
45a3fd55
BH
90struct efx_mcdi_mtd_partition {
91 struct efx_mtd_partition common;
92 bool updating;
8127d661 93 u16 nvram_type;
45a3fd55
BH
94 u16 fw_subtype;
95};
96
97#define to_efx_mcdi_mtd_partition(mtd) \
98 container_of(mtd, struct efx_mcdi_mtd_partition, common.mtd)
99
f3ad5003
BH
100/**
101 * struct efx_mcdi_data - extra state for NICs that implement MCDI
102 * @iface: Interface/protocol state
103 * @hwmon: Hardware monitor state
8349f7f6 104 * @fn_flags: Flags for this function, as returned by %MC_CMD_DRV_ATTACH.
f3ad5003
BH
105 */
106struct efx_mcdi_data {
107 struct efx_mcdi_iface iface;
108#ifdef CONFIG_SFC_MCDI_MON
109 struct efx_mcdi_mon hwmon;
110#endif
8349f7f6 111 u32 fn_flags;
f3ad5003
BH
112};
113
e283546c
EC
114static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx)
115{
116 EFX_BUG_ON_PARANOID(!efx->mcdi);
117 return &efx->mcdi->iface;
118}
119
f3ad5003
BH
120#ifdef CONFIG_SFC_MCDI_MON
121static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
122{
123 EFX_BUG_ON_PARANOID(!efx->mcdi);
124 return &efx->mcdi->hwmon;
125}
126#endif
127
00aef986
JP
128int efx_mcdi_init(struct efx_nic *efx);
129void efx_mcdi_fini(struct efx_nic *efx);
afd4aea0 130
00aef986
JP
131int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const efx_dword_t *inbuf,
132 size_t inlen, efx_dword_t *outbuf, size_t outlen,
133 size_t *outlen_actual);
1e0b8120
EC
134int efx_mcdi_rpc_quiet(struct efx_nic *efx, unsigned cmd,
135 const efx_dword_t *inbuf, size_t inlen,
136 efx_dword_t *outbuf, size_t outlen,
137 size_t *outlen_actual);
00aef986
JP
138
139int efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
140 const efx_dword_t *inbuf, size_t inlen);
141int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
9528b921 142 efx_dword_t *outbuf, size_t outlen,
afd4aea0 143 size_t *outlen_actual);
1e0b8120
EC
144int efx_mcdi_rpc_finish_quiet(struct efx_nic *efx, unsigned cmd,
145 size_t inlen, efx_dword_t *outbuf,
146 size_t outlen, size_t *outlen_actual);
afd4aea0 147
cade715f
BH
148typedef void efx_mcdi_async_completer(struct efx_nic *efx,
149 unsigned long cookie, int rc,
150 efx_dword_t *outbuf,
151 size_t outlen_actual);
00aef986
JP
152int efx_mcdi_rpc_async(struct efx_nic *efx, unsigned int cmd,
153 const efx_dword_t *inbuf, size_t inlen, size_t outlen,
154 efx_mcdi_async_completer *complete,
155 unsigned long cookie);
1e0b8120
EC
156int efx_mcdi_rpc_async_quiet(struct efx_nic *efx, unsigned int cmd,
157 const efx_dword_t *inbuf, size_t inlen,
158 size_t outlen,
159 efx_mcdi_async_completer *complete,
160 unsigned long cookie);
161
162void efx_mcdi_display_error(struct efx_nic *efx, unsigned cmd,
163 size_t inlen, efx_dword_t *outbuf,
164 size_t outlen, int rc);
9528b921 165
00aef986
JP
166int efx_mcdi_poll_reboot(struct efx_nic *efx);
167void efx_mcdi_mode_poll(struct efx_nic *efx);
168void efx_mcdi_mode_event(struct efx_nic *efx);
169void efx_mcdi_flush_async(struct efx_nic *efx);
afd4aea0 170
00aef986
JP
171void efx_mcdi_process_event(struct efx_channel *channel, efx_qword_t *event);
172void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
afd4aea0 173
9528b921 174/* We expect that 16- and 32-bit fields in MCDI requests and responses
338f74df
BH
175 * are appropriately aligned, but 64-bit fields are only
176 * 32-bit-aligned. Also, on Siena we must copy to the MC shared
177 * memory strictly 32 bits at a time, so add any necessary padding.
9528b921 178 */
59cfc479 179#define MCDI_DECLARE_BUF(_name, _len) \
9528b921 180 efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
1e0b8120
EC
181#define MCDI_DECLARE_BUF_OUT_OR_ERR(_name, _len) \
182 MCDI_DECLARE_BUF(_name, max_t(size_t, _len, 8))
a649dfcb
BH
183#define _MCDI_PTR(_buf, _offset) \
184 ((u8 *)(_buf) + (_offset))
30af6910 185#define MCDI_PTR(_buf, _field) \
a649dfcb 186 _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
9528b921
BH
187#define _MCDI_CHECK_ALIGN(_ofst, _align) \
188 ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
30af6910 189#define _MCDI_DWORD(_buf, _field) \
9528b921 190 ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
59cfc479 191
8127d661
BH
192#define MCDI_WORD(_buf, _field) \
193 ((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
194 le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field)))
30af6910
BH
195#define MCDI_SET_DWORD(_buf, _field, _value) \
196 EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
197#define MCDI_DWORD(_buf, _field) \
198 EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
f5253d92
BH
199#define MCDI_POPULATE_DWORD_1(_buf, _field, _name1, _value1) \
200 EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), \
201 MC_CMD_ ## _name1, _value1)
202#define MCDI_POPULATE_DWORD_2(_buf, _field, _name1, _value1, \
203 _name2, _value2) \
204 EFX_POPULATE_DWORD_2(*_MCDI_DWORD(_buf, _field), \
205 MC_CMD_ ## _name1, _value1, \
206 MC_CMD_ ## _name2, _value2)
207#define MCDI_POPULATE_DWORD_3(_buf, _field, _name1, _value1, \
208 _name2, _value2, _name3, _value3) \
209 EFX_POPULATE_DWORD_3(*_MCDI_DWORD(_buf, _field), \
210 MC_CMD_ ## _name1, _value1, \
211 MC_CMD_ ## _name2, _value2, \
212 MC_CMD_ ## _name3, _value3)
213#define MCDI_POPULATE_DWORD_4(_buf, _field, _name1, _value1, \
214 _name2, _value2, _name3, _value3, \
215 _name4, _value4) \
216 EFX_POPULATE_DWORD_4(*_MCDI_DWORD(_buf, _field), \
217 MC_CMD_ ## _name1, _value1, \
218 MC_CMD_ ## _name2, _value2, \
219 MC_CMD_ ## _name3, _value3, \
220 MC_CMD_ ## _name4, _value4)
221#define MCDI_POPULATE_DWORD_5(_buf, _field, _name1, _value1, \
222 _name2, _value2, _name3, _value3, \
223 _name4, _value4, _name5, _value5) \
224 EFX_POPULATE_DWORD_5(*_MCDI_DWORD(_buf, _field), \
225 MC_CMD_ ## _name1, _value1, \
226 MC_CMD_ ## _name2, _value2, \
227 MC_CMD_ ## _name3, _value3, \
228 MC_CMD_ ## _name4, _value4, \
229 MC_CMD_ ## _name5, _value5)
230#define MCDI_POPULATE_DWORD_6(_buf, _field, _name1, _value1, \
231 _name2, _value2, _name3, _value3, \
232 _name4, _value4, _name5, _value5, \
233 _name6, _value6) \
234 EFX_POPULATE_DWORD_6(*_MCDI_DWORD(_buf, _field), \
235 MC_CMD_ ## _name1, _value1, \
236 MC_CMD_ ## _name2, _value2, \
237 MC_CMD_ ## _name3, _value3, \
238 MC_CMD_ ## _name4, _value4, \
239 MC_CMD_ ## _name5, _value5, \
240 MC_CMD_ ## _name6, _value6)
241#define MCDI_POPULATE_DWORD_7(_buf, _field, _name1, _value1, \
242 _name2, _value2, _name3, _value3, \
243 _name4, _value4, _name5, _value5, \
244 _name6, _value6, _name7, _value7) \
245 EFX_POPULATE_DWORD_7(*_MCDI_DWORD(_buf, _field), \
246 MC_CMD_ ## _name1, _value1, \
247 MC_CMD_ ## _name2, _value2, \
248 MC_CMD_ ## _name3, _value3, \
249 MC_CMD_ ## _name4, _value4, \
250 MC_CMD_ ## _name5, _value5, \
251 MC_CMD_ ## _name6, _value6, \
252 MC_CMD_ ## _name7, _value7)
338f74df
BH
253#define MCDI_SET_QWORD(_buf, _field, _value) \
254 do { \
255 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \
256 EFX_DWORD_0, (u32)(_value)); \
257 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \
258 EFX_DWORD_0, (u64)(_value) >> 32); \
259 } while (0)
30af6910
BH
260#define MCDI_QWORD(_buf, _field) \
261 (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \
262 (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
a649dfcb
BH
263#define MCDI_FIELD(_ptr, _type, _field) \
264 EFX_EXTRACT_DWORD( \
265 *(efx_dword_t *) \
266 _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
267 MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
268 (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \
269 MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
30af6910 270
9528b921
BH
271#define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \
272 (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
273 + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
a649dfcb 274#define MCDI_DECLARE_STRUCT_PTR(_name) \
9528b921
BH
275 efx_dword_t *_name
276#define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \
277 ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
a649dfcb
BH
278#define MCDI_VAR_ARRAY_LEN(_len, _field) \
279 min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \
280 ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
281#define MCDI_ARRAY_WORD(_buf, _field, _index) \
282 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
283 le16_to_cpu(*(__force const __le16 *) \
9528b921 284 _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
a649dfcb
BH
285#define _MCDI_ARRAY_DWORD(_buf, _field, _index) \
286 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \
9528b921 287 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
a649dfcb
BH
288#define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \
289 EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \
290 EFX_DWORD_0, _value)
291#define MCDI_ARRAY_DWORD(_buf, _field, _index) \
292 EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
338f74df
BH
293#define _MCDI_ARRAY_QWORD(_buf, _field, _index) \
294 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \
295 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
296#define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \
297 do { \
298 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
299 EFX_DWORD_0, (u32)(_value)); \
300 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
301 EFX_DWORD_0, (u64)(_value) >> 32); \
302 } while (0)
55c5e0f8 303#define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
a649dfcb
BH
304 MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \
305 _type ## _TYPEDEF, _field2)
afd4aea0 306
30af6910
BH
307#define MCDI_EVENT_FIELD(_ev, _field) \
308 EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
309
00aef986
JP
310void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
311int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
312 u16 *fw_subtype_list, u32 *capabilities);
313int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq);
314int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
315int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
316 size_t *size_out, size_t *erase_size_out,
317 bool *protected_out);
318int efx_mcdi_nvram_test_all(struct efx_nic *efx);
319int efx_mcdi_handle_assertion(struct efx_nic *efx);
320void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
321int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac,
322 int *id_out);
323int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
324int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
325int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
326int efx_mcdi_flush_rxqs(struct efx_nic *efx);
327int efx_mcdi_port_probe(struct efx_nic *efx);
328void efx_mcdi_port_remove(struct efx_nic *efx);
329int efx_mcdi_port_reconfigure(struct efx_nic *efx);
330int efx_mcdi_port_get_number(struct efx_nic *efx);
331u32 efx_mcdi_phy_get_caps(struct efx_nic *efx);
332void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
333int efx_mcdi_set_mac(struct efx_nic *efx);
43f775b2 334#define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1))
00aef986
JP
335void efx_mcdi_mac_start_stats(struct efx_nic *efx);
336void efx_mcdi_mac_stop_stats(struct efx_nic *efx);
f8f3b5ae 337void efx_mcdi_mac_pull_stats(struct efx_nic *efx);
00aef986
JP
338bool efx_mcdi_mac_check_fault(struct efx_nic *efx);
339enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason);
340int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method);
341int efx_mcdi_set_workaround(struct efx_nic *efx, u32 type, bool enabled);
afd4aea0 342
55c5e0f8 343#ifdef CONFIG_SFC_MCDI_MON
00aef986
JP
344int efx_mcdi_mon_probe(struct efx_nic *efx);
345void efx_mcdi_mon_remove(struct efx_nic *efx);
55c5e0f8
BH
346#else
347static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
348static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {}
349#endif
350
45a3fd55 351#ifdef CONFIG_SFC_MTD
00aef986
JP
352int efx_mcdi_mtd_read(struct mtd_info *mtd, loff_t start, size_t len,
353 size_t *retlen, u8 *buffer);
354int efx_mcdi_mtd_erase(struct mtd_info *mtd, loff_t start, size_t len);
355int efx_mcdi_mtd_write(struct mtd_info *mtd, loff_t start, size_t len,
356 size_t *retlen, const u8 *buffer);
357int efx_mcdi_mtd_sync(struct mtd_info *mtd);
358void efx_mcdi_mtd_rename(struct efx_mtd_partition *part);
45a3fd55
BH
359#endif
360
afd4aea0 361#endif /* EFX_MCDI_H */
This page took 0.665304 seconds and 5 git commands to generate.