blob: 9081f84a26043ad2a8f853106849566fbb6c87f2 [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Ben Hutchingsafd4aea2009-11-29 15:15:25 +00002/****************************************************************************
Ben Hutchingsf7a6d2c2013-08-29 23:32:48 +01003 * Driver for Solarflare network controllers and boards
4 * Copyright 2008-2013 Solarflare Communications Inc.
Ben Hutchingsafd4aea2009-11-29 15:15:25 +00005 */
6
7#ifndef EFX_MCDI_H
8#define EFX_MCDI_H
9
10/**
Ben Hutchingsf76fe122012-10-26 17:53:11 +010011 * enum efx_mcdi_state - MCDI request handling state
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000012 * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
Ben Hutchingsf76fe122012-10-26 17:53:11 +010013 * mcdi @iface_lock then they are able to move to %MCDI_STATE_RUNNING
Ben Hutchingscade7152013-08-27 23:12:31 +010014 * @MCDI_STATE_RUNNING_SYNC: There is a synchronous MCDI request pending.
15 * Only the thread that moved into this state is allowed to move out of it.
16 * @MCDI_STATE_RUNNING_ASYNC: There is an asynchronous MCDI request pending.
Bert Kenwardacd43a92015-12-23 08:57:18 +000017 * @MCDI_STATE_PROXY_WAIT: An MCDI request has completed with a response that
18 * indicates we must wait for a proxy try again message.
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000019 * @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
Ben Hutchingsf76fe122012-10-26 17:53:11 +010021 * %MCDI_STATE_RUNNING.
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000022 */
23enum efx_mcdi_state {
24 MCDI_STATE_QUIESCENT,
Ben Hutchingscade7152013-08-27 23:12:31 +010025 MCDI_STATE_RUNNING_SYNC,
26 MCDI_STATE_RUNNING_ASYNC,
Bert Kenwardacd43a92015-12-23 08:57:18 +000027 MCDI_STATE_PROXY_WAIT,
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000028 MCDI_STATE_COMPLETED,
29};
30
Edward Creee2835462014-04-16 19:27:48 +010031/**
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 */
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000037enum efx_mcdi_mode {
38 MCDI_MODE_POLL,
39 MCDI_MODE_EVENTS,
Edward Creee2835462014-04-16 19:27:48 +010040 MCDI_MODE_FAIL,
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000041};
42
43/**
Ben Hutchingsf76fe122012-10-26 17:53:11 +010044 * struct efx_mcdi_iface - MCDI protocol context
Ben Hutchingscade7152013-08-27 23:12:31 +010045 * @efx: The associated NIC.
Ben Hutchingsf76fe122012-10-26 17:53:11 +010046 * @state: Request handling state. Waited for by @wq.
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000047 * @mode: Poll for mcdi completion, or wait for an mcdi_event.
Ben Hutchingsf76fe122012-10-26 17:53:11 +010048 * @wq: Wait queue for threads waiting for @state != %MCDI_STATE_RUNNING
Daniel Pieczkod36a08b2013-06-20 11:40:07 +010049 * @new_epoch: Indicates start of day or start of MC reboot recovery
Ben Hutchingscade7152013-08-27 23:12:31 +010050 * @iface_lock: Serialises access to @seqno, @credits and response metadata
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000051 * @seqno: The next sequence number to use for mcdi requests.
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000052 * @credits: Number of spurious MCDI completion events allowed before we
Ben Hutchingsf76fe122012-10-26 17:53:11 +010053 * trigger a fatal error
Ben Hutchings5bc283e2012-10-08 21:43:00 +010054 * @resprc: Response error/success code (Linux numbering)
Ben Hutchingsdf2cd8a2012-09-19 00:56:18 +010055 * @resp_hdr_len: Response header length
56 * @resp_data_len: Response data (SDU or error) length
Ben Hutchingscade7152013-08-27 23:12:31 +010057 * @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
Edward Cree75aba2a2015-05-27 13:13:54 +010061 * @logging_buffer: buffer that may be used to build MCDI tracing messages
Edward Creee7fef9b2015-05-27 13:14:01 +010062 * @logging_enabled: whether to trace MCDI
Bert Kenwardacd43a92015-12-23 08:57:18 +000063 * @proxy_rx_handle: Most recently received proxy authorisation handle
64 * @proxy_rx_status: Status of most recent proxy authorisation
65 * @proxy_rx_wq: Wait queue for updates to proxy_rx_handle
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000066 */
67struct efx_mcdi_iface {
Ben Hutchingscade7152013-08-27 23:12:31 +010068 struct efx_nic *efx;
Ben Hutchings251111d2013-08-27 23:04:29 +010069 enum efx_mcdi_state state;
Ben Hutchingsf76fe122012-10-26 17:53:11 +010070 enum efx_mcdi_mode mode;
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000071 wait_queue_head_t wq;
72 spinlock_t iface_lock;
Daniel Pieczkod36a08b2013-06-20 11:40:07 +010073 bool new_epoch;
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000074 unsigned int credits;
75 unsigned int seqno;
Ben Hutchings5bc283e2012-10-08 21:43:00 +010076 int resprc;
Bert Kenwardac28d172015-12-23 08:56:40 +000077 int resprc_raw;
Ben Hutchingsdf2cd8a2012-09-19 00:56:18 +010078 size_t resp_hdr_len;
79 size_t resp_data_len;
Ben Hutchingscade7152013-08-27 23:12:31 +010080 spinlock_t async_lock;
81 struct list_head async_list;
82 struct timer_list async_timer;
Edward Cree75aba2a2015-05-27 13:13:54 +010083#ifdef CONFIG_SFC_MCDI_LOGGING
84 char *logging_buffer;
Edward Creee7fef9b2015-05-27 13:14:01 +010085 bool logging_enabled;
Edward Cree75aba2a2015-05-27 13:13:54 +010086#endif
Bert Kenwardacd43a92015-12-23 08:57:18 +000087 unsigned int proxy_rx_handle;
88 int proxy_rx_status;
89 wait_queue_head_t proxy_rx_wq;
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000090};
91
Ben Hutchings55c5e0f82012-01-06 20:25:39 +000092struct efx_mcdi_mon {
93 struct efx_buffer dma_buf;
94 struct mutex update_lock;
95 unsigned long last_update;
96 struct device *device;
97 struct efx_mcdi_mon_attribute *attrs;
Guenter Roeck85493e62013-11-27 18:54:31 -080098 struct attribute_group group;
99 const struct attribute_group *groups[2];
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000100 unsigned int n_attrs;
101};
102
Ben Hutchings45a3fd52012-11-28 04:38:14 +0000103struct efx_mcdi_mtd_partition {
104 struct efx_mtd_partition common;
105 bool updating;
Ben Hutchings8127d662013-08-29 19:19:29 +0100106 u16 nvram_type;
Ben Hutchings45a3fd52012-11-28 04:38:14 +0000107 u16 fw_subtype;
108};
109
110#define to_efx_mcdi_mtd_partition(mtd) \
111 container_of(mtd, struct efx_mcdi_mtd_partition, common.mtd)
112
Ben Hutchingsf3ad5002012-09-18 02:33:56 +0100113/**
114 * struct efx_mcdi_data - extra state for NICs that implement MCDI
115 * @iface: Interface/protocol state
116 * @hwmon: Hardware monitor state
Ben Hutchings8349f7f2013-10-16 18:32:34 +0100117 * @fn_flags: Flags for this function, as returned by %MC_CMD_DRV_ATTACH.
Ben Hutchingsf3ad5002012-09-18 02:33:56 +0100118 */
119struct efx_mcdi_data {
120 struct efx_mcdi_iface iface;
121#ifdef CONFIG_SFC_MCDI_MON
122 struct efx_mcdi_mon hwmon;
123#endif
Ben Hutchings8349f7f2013-10-16 18:32:34 +0100124 u32 fn_flags;
Ben Hutchingsf3ad5002012-09-18 02:33:56 +0100125};
126
Edward Creee2835462014-04-16 19:27:48 +0100127static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx)
128{
Edward Creee01b16a2016-12-02 15:51:33 +0000129 EFX_WARN_ON_PARANOID(!efx->mcdi);
Edward Creee2835462014-04-16 19:27:48 +0100130 return &efx->mcdi->iface;
131}
132
Ben Hutchingsf3ad5002012-09-18 02:33:56 +0100133#ifdef CONFIG_SFC_MCDI_MON
134static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
135{
Edward Creee01b16a2016-12-02 15:51:33 +0000136 EFX_WARN_ON_PARANOID(!efx->mcdi);
Ben Hutchingsf3ad5002012-09-18 02:33:56 +0100137 return &efx->mcdi->hwmon;
138}
139#endif
140
Joe Perches00aef982013-09-23 11:37:59 -0700141int efx_mcdi_init(struct efx_nic *efx);
Jon Coopere5fbd972017-02-08 16:52:10 +0000142void efx_mcdi_detach(struct efx_nic *efx);
Joe Perches00aef982013-09-23 11:37:59 -0700143void efx_mcdi_fini(struct efx_nic *efx);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000144
Joe Perches00aef982013-09-23 11:37:59 -0700145int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const efx_dword_t *inbuf,
146 size_t inlen, efx_dword_t *outbuf, size_t outlen,
147 size_t *outlen_actual);
Edward Cree1e0b8122013-05-31 18:36:12 +0100148int efx_mcdi_rpc_quiet(struct efx_nic *efx, unsigned cmd,
149 const efx_dword_t *inbuf, size_t inlen,
150 efx_dword_t *outbuf, size_t outlen,
151 size_t *outlen_actual);
Joe Perches00aef982013-09-23 11:37:59 -0700152
153int efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
154 const efx_dword_t *inbuf, size_t inlen);
155int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
Ben Hutchings9528b922012-09-14 17:31:41 +0100156 efx_dword_t *outbuf, size_t outlen,
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000157 size_t *outlen_actual);
Edward Cree1e0b8122013-05-31 18:36:12 +0100158int efx_mcdi_rpc_finish_quiet(struct efx_nic *efx, unsigned cmd,
159 size_t inlen, efx_dword_t *outbuf,
160 size_t outlen, size_t *outlen_actual);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000161
Ben Hutchingscade7152013-08-27 23:12:31 +0100162typedef void efx_mcdi_async_completer(struct efx_nic *efx,
163 unsigned long cookie, int rc,
164 efx_dword_t *outbuf,
165 size_t outlen_actual);
Joe Perches00aef982013-09-23 11:37:59 -0700166int efx_mcdi_rpc_async(struct efx_nic *efx, unsigned int cmd,
167 const efx_dword_t *inbuf, size_t inlen, size_t outlen,
168 efx_mcdi_async_completer *complete,
169 unsigned long cookie);
Edward Cree1e0b8122013-05-31 18:36:12 +0100170int efx_mcdi_rpc_async_quiet(struct efx_nic *efx, unsigned int cmd,
171 const efx_dword_t *inbuf, size_t inlen,
172 size_t outlen,
173 efx_mcdi_async_completer *complete,
174 unsigned long cookie);
175
176void efx_mcdi_display_error(struct efx_nic *efx, unsigned cmd,
177 size_t inlen, efx_dword_t *outbuf,
178 size_t outlen, int rc);
Ben Hutchings9528b922012-09-14 17:31:41 +0100179
Joe Perches00aef982013-09-23 11:37:59 -0700180int efx_mcdi_poll_reboot(struct efx_nic *efx);
181void efx_mcdi_mode_poll(struct efx_nic *efx);
182void efx_mcdi_mode_event(struct efx_nic *efx);
183void efx_mcdi_flush_async(struct efx_nic *efx);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000184
Joe Perches00aef982013-09-23 11:37:59 -0700185void efx_mcdi_process_event(struct efx_channel *channel, efx_qword_t *event);
186void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000187
Ben Hutchings9528b922012-09-14 17:31:41 +0100188/* We expect that 16- and 32-bit fields in MCDI requests and responses
Ben Hutchings338f74d2012-10-10 23:20:17 +0100189 * are appropriately aligned, but 64-bit fields are only
190 * 32-bit-aligned. Also, on Siena we must copy to the MC shared
191 * memory strictly 32 bits at a time, so add any necessary padding.
Ben Hutchings9528b922012-09-14 17:31:41 +0100192 */
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100193#define _MCDI_DECLARE_BUF(_name, _len) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100194 efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
Jon Cooperaa09a3d2015-05-20 11:10:41 +0100195#define MCDI_DECLARE_BUF(_name, _len) \
196 _MCDI_DECLARE_BUF(_name, _len) = {{{0}}}
197#define MCDI_DECLARE_BUF_ERR(_name) \
198 MCDI_DECLARE_BUF(_name, 8)
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100199#define _MCDI_PTR(_buf, _offset) \
200 ((u8 *)(_buf) + (_offset))
Ben Hutchings30af6912012-09-14 17:30:44 +0100201#define MCDI_PTR(_buf, _field) \
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100202 _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
Ben Hutchings9528b922012-09-14 17:31:41 +0100203#define _MCDI_CHECK_ALIGN(_ofst, _align) \
204 ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
Ben Hutchings30af6912012-09-14 17:30:44 +0100205#define _MCDI_DWORD(_buf, _field) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100206 ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
Ben Hutchings59cfc472012-09-14 17:30:10 +0100207
Edward Cree71827442017-12-18 16:56:19 +0000208#define MCDI_BYTE(_buf, _field) \
209 ((void)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 1), \
210 *MCDI_PTR(_buf, _field))
Ben Hutchings8127d662013-08-29 19:19:29 +0100211#define MCDI_WORD(_buf, _field) \
212 ((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
213 le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field)))
Ben Hutchings30af6912012-09-14 17:30:44 +0100214#define MCDI_SET_DWORD(_buf, _field, _value) \
215 EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
216#define MCDI_DWORD(_buf, _field) \
217 EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
Ben Hutchingsf5253d92012-10-10 23:24:51 +0100218#define MCDI_POPULATE_DWORD_1(_buf, _field, _name1, _value1) \
219 EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), \
220 MC_CMD_ ## _name1, _value1)
221#define MCDI_POPULATE_DWORD_2(_buf, _field, _name1, _value1, \
222 _name2, _value2) \
223 EFX_POPULATE_DWORD_2(*_MCDI_DWORD(_buf, _field), \
224 MC_CMD_ ## _name1, _value1, \
225 MC_CMD_ ## _name2, _value2)
226#define MCDI_POPULATE_DWORD_3(_buf, _field, _name1, _value1, \
227 _name2, _value2, _name3, _value3) \
228 EFX_POPULATE_DWORD_3(*_MCDI_DWORD(_buf, _field), \
229 MC_CMD_ ## _name1, _value1, \
230 MC_CMD_ ## _name2, _value2, \
231 MC_CMD_ ## _name3, _value3)
232#define MCDI_POPULATE_DWORD_4(_buf, _field, _name1, _value1, \
233 _name2, _value2, _name3, _value3, \
234 _name4, _value4) \
235 EFX_POPULATE_DWORD_4(*_MCDI_DWORD(_buf, _field), \
236 MC_CMD_ ## _name1, _value1, \
237 MC_CMD_ ## _name2, _value2, \
238 MC_CMD_ ## _name3, _value3, \
239 MC_CMD_ ## _name4, _value4)
240#define MCDI_POPULATE_DWORD_5(_buf, _field, _name1, _value1, \
241 _name2, _value2, _name3, _value3, \
242 _name4, _value4, _name5, _value5) \
243 EFX_POPULATE_DWORD_5(*_MCDI_DWORD(_buf, _field), \
244 MC_CMD_ ## _name1, _value1, \
245 MC_CMD_ ## _name2, _value2, \
246 MC_CMD_ ## _name3, _value3, \
247 MC_CMD_ ## _name4, _value4, \
248 MC_CMD_ ## _name5, _value5)
249#define MCDI_POPULATE_DWORD_6(_buf, _field, _name1, _value1, \
250 _name2, _value2, _name3, _value3, \
251 _name4, _value4, _name5, _value5, \
252 _name6, _value6) \
253 EFX_POPULATE_DWORD_6(*_MCDI_DWORD(_buf, _field), \
254 MC_CMD_ ## _name1, _value1, \
255 MC_CMD_ ## _name2, _value2, \
256 MC_CMD_ ## _name3, _value3, \
257 MC_CMD_ ## _name4, _value4, \
258 MC_CMD_ ## _name5, _value5, \
259 MC_CMD_ ## _name6, _value6)
260#define MCDI_POPULATE_DWORD_7(_buf, _field, _name1, _value1, \
261 _name2, _value2, _name3, _value3, \
262 _name4, _value4, _name5, _value5, \
263 _name6, _value6, _name7, _value7) \
264 EFX_POPULATE_DWORD_7(*_MCDI_DWORD(_buf, _field), \
265 MC_CMD_ ## _name1, _value1, \
266 MC_CMD_ ## _name2, _value2, \
267 MC_CMD_ ## _name3, _value3, \
268 MC_CMD_ ## _name4, _value4, \
269 MC_CMD_ ## _name5, _value5, \
270 MC_CMD_ ## _name6, _value6, \
271 MC_CMD_ ## _name7, _value7)
Ben Hutchings338f74d2012-10-10 23:20:17 +0100272#define MCDI_SET_QWORD(_buf, _field, _value) \
273 do { \
274 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \
275 EFX_DWORD_0, (u32)(_value)); \
276 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \
277 EFX_DWORD_0, (u64)(_value) >> 32); \
278 } while (0)
Ben Hutchings30af6912012-09-14 17:30:44 +0100279#define MCDI_QWORD(_buf, _field) \
280 (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \
281 (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100282#define MCDI_FIELD(_ptr, _type, _field) \
Ben Hutchings0a6e5002012-09-11 21:46:41 +0100283 EFX_EXTRACT_DWORD( \
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100284 *(efx_dword_t *) \
285 _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
286 MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
287 (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \
288 MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
289
Ben Hutchings9528b922012-09-14 17:31:41 +0100290#define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \
291 (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
292 + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100293#define MCDI_DECLARE_STRUCT_PTR(_name) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100294 efx_dword_t *_name
295#define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \
296 ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100297#define MCDI_VAR_ARRAY_LEN(_len, _field) \
298 min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \
299 ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
300#define MCDI_ARRAY_WORD(_buf, _field, _index) \
301 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
302 le16_to_cpu(*(__force const __le16 *) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100303 _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100304#define _MCDI_ARRAY_DWORD(_buf, _field, _index) \
305 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \
Ben Hutchings9528b922012-09-14 17:31:41 +0100306 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100307#define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \
308 EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \
309 EFX_DWORD_0, _value)
310#define MCDI_ARRAY_DWORD(_buf, _field, _index) \
311 EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
Ben Hutchings338f74d2012-10-10 23:20:17 +0100312#define _MCDI_ARRAY_QWORD(_buf, _field, _index) \
313 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \
314 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
315#define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \
316 do { \
317 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
318 EFX_DWORD_0, (u32)(_value)); \
319 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
320 EFX_DWORD_0, (u64)(_value) >> 32); \
321 } while (0)
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100322#define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
323 MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \
324 _type ## _TYPEDEF, _field2)
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000325
Ben Hutchings30af6912012-09-14 17:30:44 +0100326#define MCDI_EVENT_FIELD(_ev, _field) \
327 EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
328
Joe Perches00aef982013-09-23 11:37:59 -0700329void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
330int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
331 u16 *fw_subtype_list, u32 *capabilities);
332int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq);
333int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
334int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
335 size_t *size_out, size_t *erase_size_out,
336 bool *protected_out);
337int efx_mcdi_nvram_test_all(struct efx_nic *efx);
338int efx_mcdi_handle_assertion(struct efx_nic *efx);
339void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
340int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac,
341 int *id_out);
342int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
343int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
344int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
345int efx_mcdi_flush_rxqs(struct efx_nic *efx);
346int efx_mcdi_port_probe(struct efx_nic *efx);
347void efx_mcdi_port_remove(struct efx_nic *efx);
348int efx_mcdi_port_reconfigure(struct efx_nic *efx);
349int efx_mcdi_port_get_number(struct efx_nic *efx);
350u32 efx_mcdi_phy_get_caps(struct efx_nic *efx);
351void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
352int efx_mcdi_set_mac(struct efx_nic *efx);
Ben Hutchings43f775b22012-09-18 02:33:54 +0100353#define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1))
Joe Perches00aef982013-09-23 11:37:59 -0700354void efx_mcdi_mac_start_stats(struct efx_nic *efx);
355void efx_mcdi_mac_stop_stats(struct efx_nic *efx);
Jon Cooperf8f3b5a2013-09-30 17:36:50 +0100356void efx_mcdi_mac_pull_stats(struct efx_nic *efx);
Joe Perches00aef982013-09-23 11:37:59 -0700357bool efx_mcdi_mac_check_fault(struct efx_nic *efx);
358enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason);
359int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method);
Daniel Pieczko34ccfe62015-07-21 15:09:43 +0100360int efx_mcdi_set_workaround(struct efx_nic *efx, u32 type, bool enabled,
361 unsigned int *flags);
Edward Cree267d9d72015-05-06 00:59:18 +0100362int efx_mcdi_get_workarounds(struct efx_nic *efx, unsigned int *impl_out,
363 unsigned int *enabled_out);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000364
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000365#ifdef CONFIG_SFC_MCDI_MON
Joe Perches00aef982013-09-23 11:37:59 -0700366int efx_mcdi_mon_probe(struct efx_nic *efx);
367void efx_mcdi_mon_remove(struct efx_nic *efx);
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000368#else
369static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
370static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {}
371#endif
372
Ben Hutchings45a3fd52012-11-28 04:38:14 +0000373#ifdef CONFIG_SFC_MTD
Joe Perches00aef982013-09-23 11:37:59 -0700374int efx_mcdi_mtd_read(struct mtd_info *mtd, loff_t start, size_t len,
375 size_t *retlen, u8 *buffer);
376int efx_mcdi_mtd_erase(struct mtd_info *mtd, loff_t start, size_t len);
377int efx_mcdi_mtd_write(struct mtd_info *mtd, loff_t start, size_t len,
378 size_t *retlen, const u8 *buffer);
379int efx_mcdi_mtd_sync(struct mtd_info *mtd);
380void efx_mcdi_mtd_rename(struct efx_mtd_partition *part);
Ben Hutchings45a3fd52012-11-28 04:38:14 +0000381#endif
382
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000383#endif /* EFX_MCDI_H */