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