mcdi.h 15.1 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
/****************************************************************************
B
Ben Hutchings 已提交
3 4
 * Driver for Solarflare network controllers and boards
 * Copyright 2008-2013 Solarflare Communications Inc.
5 6 7 8 9 10
 */

#ifndef EFX_MCDI_H
#define EFX_MCDI_H

/**
11
 * enum efx_mcdi_state - MCDI request handling state
12
 * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
13
 *	mcdi @iface_lock then they are able to move to %MCDI_STATE_RUNNING
14 15 16
 * @MCDI_STATE_RUNNING_SYNC: There is a synchronous MCDI request pending.
 *	Only the thread that moved into this state is allowed to move out of it.
 * @MCDI_STATE_RUNNING_ASYNC: There is an asynchronous MCDI request pending.
17 18
 * @MCDI_STATE_PROXY_WAIT: An MCDI request has completed with a response that
 *	indicates we must wait for a proxy try again message.
19 20
 * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread
 *	has not yet consumed the result. For all other threads, equivalent to
21
 *	%MCDI_STATE_RUNNING.
22 23 24
 */
enum efx_mcdi_state {
	MCDI_STATE_QUIESCENT,
25 26
	MCDI_STATE_RUNNING_SYNC,
	MCDI_STATE_RUNNING_ASYNC,
27
	MCDI_STATE_PROXY_WAIT,
28 29 30
	MCDI_STATE_COMPLETED,
};

31 32 33 34 35 36
/**
 * enum efx_mcdi_mode - MCDI transaction mode
 * @MCDI_MODE_POLL: poll for MCDI completion, until timeout
 * @MCDI_MODE_EVENTS: wait for an mcdi_event.  On timeout, poll once
 * @MCDI_MODE_FAIL: we think MCDI is dead, so fail-fast all calls
 */
37 38 39
enum efx_mcdi_mode {
	MCDI_MODE_POLL,
	MCDI_MODE_EVENTS,
40
	MCDI_MODE_FAIL,
41 42 43
};

/**
44
 * struct efx_mcdi_iface - MCDI protocol context
45
 * @efx: The associated NIC.
46
 * @state: Request handling state. Waited for by @wq.
47
 * @mode: Poll for mcdi completion, or wait for an mcdi_event.
48
 * @wq: Wait queue for threads waiting for @state != %MCDI_STATE_RUNNING
49
 * @new_epoch: Indicates start of day or start of MC reboot recovery
50
 * @iface_lock: Serialises access to @seqno, @credits and response metadata
51 52
 * @seqno: The next sequence number to use for mcdi requests.
 * @credits: Number of spurious MCDI completion events allowed before we
53
 *     trigger a fatal error
54
 * @resprc: Response error/success code (Linux numbering)
B
Ben Hutchings 已提交
55 56
 * @resp_hdr_len: Response header length
 * @resp_data_len: Response data (SDU or error) length
57 58 59 60
 * @async_lock: Serialises access to @async_list while event processing is
 *	enabled
 * @async_list: Queue of asynchronous requests
 * @async_timer: Timer for asynchronous request timeout
E
Edward Cree 已提交
61
 * @logging_buffer: buffer that may be used to build MCDI tracing messages
62
 * @logging_enabled: whether to trace MCDI
63 64 65
 * @proxy_rx_handle: Most recently received proxy authorisation handle
 * @proxy_rx_status: Status of most recent proxy authorisation
 * @proxy_rx_wq: Wait queue for updates to proxy_rx_handle
66 67
 */
struct efx_mcdi_iface {
68
	struct efx_nic *efx;
69
	enum efx_mcdi_state state;
70
	enum efx_mcdi_mode mode;
71 72
	wait_queue_head_t wq;
	spinlock_t iface_lock;
73
	bool new_epoch;
74 75
	unsigned int credits;
	unsigned int seqno;
76
	int resprc;
77
	int resprc_raw;
B
Ben Hutchings 已提交
78 79
	size_t resp_hdr_len;
	size_t resp_data_len;
80 81 82
	spinlock_t async_lock;
	struct list_head async_list;
	struct timer_list async_timer;
E
Edward Cree 已提交
83 84
#ifdef CONFIG_SFC_MCDI_LOGGING
	char *logging_buffer;
85
	bool logging_enabled;
E
Edward Cree 已提交
86
#endif
87 88 89
	unsigned int proxy_rx_handle;
	int proxy_rx_status;
	wait_queue_head_t proxy_rx_wq;
90 91
};

92 93 94 95 96 97
struct efx_mcdi_mon {
	struct efx_buffer dma_buf;
	struct mutex update_lock;
	unsigned long last_update;
	struct device *device;
	struct efx_mcdi_mon_attribute *attrs;
98 99
	struct attribute_group group;
	const struct attribute_group *groups[2];
100 101 102
	unsigned int n_attrs;
};

103 104 105
struct efx_mcdi_mtd_partition {
	struct efx_mtd_partition common;
	bool updating;
106
	u16 nvram_type;
107 108 109 110 111 112
	u16 fw_subtype;
};

#define to_efx_mcdi_mtd_partition(mtd)				\
	container_of(mtd, struct efx_mcdi_mtd_partition, common.mtd)

113 114 115 116
/**
 * struct efx_mcdi_data - extra state for NICs that implement MCDI
 * @iface: Interface/protocol state
 * @hwmon: Hardware monitor state
117
 * @fn_flags: Flags for this function, as returned by %MC_CMD_DRV_ATTACH.
118 119 120 121 122 123
 */
struct efx_mcdi_data {
	struct efx_mcdi_iface iface;
#ifdef CONFIG_SFC_MCDI_MON
	struct efx_mcdi_mon hwmon;
#endif
124
	u32 fn_flags;
125 126
};

127 128
static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx)
{
129
	EFX_WARN_ON_PARANOID(!efx->mcdi);
130 131 132
	return &efx->mcdi->iface;
}

133 134 135
#ifdef CONFIG_SFC_MCDI_MON
static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
{
136
	EFX_WARN_ON_PARANOID(!efx->mcdi);
137 138 139 140
	return &efx->mcdi->hwmon;
}
#endif

141
int efx_mcdi_init(struct efx_nic *efx);
142
void efx_mcdi_detach(struct efx_nic *efx);
143
void efx_mcdi_fini(struct efx_nic *efx);
144

145 146 147
int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const efx_dword_t *inbuf,
		 size_t inlen, efx_dword_t *outbuf, size_t outlen,
		 size_t *outlen_actual);
E
Edward Cree 已提交
148 149 150 151
int efx_mcdi_rpc_quiet(struct efx_nic *efx, unsigned cmd,
		       const efx_dword_t *inbuf, size_t inlen,
		       efx_dword_t *outbuf, size_t outlen,
		       size_t *outlen_actual);
152 153 154 155

int efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
		       const efx_dword_t *inbuf, size_t inlen);
int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
156
			efx_dword_t *outbuf, size_t outlen,
157
			size_t *outlen_actual);
E
Edward Cree 已提交
158 159 160
int efx_mcdi_rpc_finish_quiet(struct efx_nic *efx, unsigned cmd,
			      size_t inlen, efx_dword_t *outbuf,
			      size_t outlen, size_t *outlen_actual);
161

162 163 164 165
typedef void efx_mcdi_async_completer(struct efx_nic *efx,
				      unsigned long cookie, int rc,
				      efx_dword_t *outbuf,
				      size_t outlen_actual);
166 167 168 169
int efx_mcdi_rpc_async(struct efx_nic *efx, unsigned int cmd,
		       const efx_dword_t *inbuf, size_t inlen, size_t outlen,
		       efx_mcdi_async_completer *complete,
		       unsigned long cookie);
E
Edward Cree 已提交
170 171 172 173 174 175 176 177 178
int efx_mcdi_rpc_async_quiet(struct efx_nic *efx, unsigned int cmd,
			     const efx_dword_t *inbuf, size_t inlen,
			     size_t outlen,
			     efx_mcdi_async_completer *complete,
			     unsigned long cookie);

void efx_mcdi_display_error(struct efx_nic *efx, unsigned cmd,
			    size_t inlen, efx_dword_t *outbuf,
			    size_t outlen, int rc);
179

180 181 182 183
int efx_mcdi_poll_reboot(struct efx_nic *efx);
void efx_mcdi_mode_poll(struct efx_nic *efx);
void efx_mcdi_mode_event(struct efx_nic *efx);
void efx_mcdi_flush_async(struct efx_nic *efx);
184

185 186
void efx_mcdi_process_event(struct efx_channel *channel, efx_qword_t *event);
void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
187

188
/* We expect that 16- and 32-bit fields in MCDI requests and responses
189 190 191
 * are appropriately aligned, but 64-bit fields are only
 * 32-bit-aligned.  Also, on Siena we must copy to the MC shared
 * memory strictly 32 bits at a time, so add any necessary padding.
192
 */
193
#define _MCDI_DECLARE_BUF(_name, _len)					\
194
	efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
195 196 197 198
#define MCDI_DECLARE_BUF(_name, _len)					\
	_MCDI_DECLARE_BUF(_name, _len) = {{{0}}}
#define MCDI_DECLARE_BUF_ERR(_name)					\
	MCDI_DECLARE_BUF(_name, 8)
199 200
#define _MCDI_PTR(_buf, _offset)					\
	((u8 *)(_buf) + (_offset))
201
#define MCDI_PTR(_buf, _field)						\
202
	_MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
203 204
#define _MCDI_CHECK_ALIGN(_ofst, _align)				\
	((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
205
#define _MCDI_DWORD(_buf, _field)					\
206
	((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
207

208 209 210
#define MCDI_BYTE(_buf, _field)						\
	((void)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 1),	\
	 *MCDI_PTR(_buf, _field))
211 212 213
#define MCDI_WORD(_buf, _field)						\
	((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) +	\
	 le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field)))
214 215 216 217
#define MCDI_SET_DWORD(_buf, _field, _value)				\
	EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
#define MCDI_DWORD(_buf, _field)					\
	EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
#define MCDI_POPULATE_DWORD_1(_buf, _field, _name1, _value1)		\
	EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field),		\
			     MC_CMD_ ## _name1, _value1)
#define MCDI_POPULATE_DWORD_2(_buf, _field, _name1, _value1,		\
			      _name2, _value2)				\
	EFX_POPULATE_DWORD_2(*_MCDI_DWORD(_buf, _field),		\
			     MC_CMD_ ## _name1, _value1,		\
			     MC_CMD_ ## _name2, _value2)
#define MCDI_POPULATE_DWORD_3(_buf, _field, _name1, _value1,		\
			      _name2, _value2, _name3, _value3)		\
	EFX_POPULATE_DWORD_3(*_MCDI_DWORD(_buf, _field),		\
			     MC_CMD_ ## _name1, _value1,		\
			     MC_CMD_ ## _name2, _value2,		\
			     MC_CMD_ ## _name3, _value3)
#define MCDI_POPULATE_DWORD_4(_buf, _field, _name1, _value1,		\
			      _name2, _value2, _name3, _value3,		\
			      _name4, _value4)				\
	EFX_POPULATE_DWORD_4(*_MCDI_DWORD(_buf, _field),		\
			     MC_CMD_ ## _name1, _value1,		\
			     MC_CMD_ ## _name2, _value2,		\
			     MC_CMD_ ## _name3, _value3,		\
			     MC_CMD_ ## _name4, _value4)
#define MCDI_POPULATE_DWORD_5(_buf, _field, _name1, _value1,		\
			      _name2, _value2, _name3, _value3,		\
			      _name4, _value4, _name5, _value5)		\
	EFX_POPULATE_DWORD_5(*_MCDI_DWORD(_buf, _field),		\
			     MC_CMD_ ## _name1, _value1,		\
			     MC_CMD_ ## _name2, _value2,		\
			     MC_CMD_ ## _name3, _value3,		\
			     MC_CMD_ ## _name4, _value4,		\
			     MC_CMD_ ## _name5, _value5)
#define MCDI_POPULATE_DWORD_6(_buf, _field, _name1, _value1,		\
			      _name2, _value2, _name3, _value3,		\
			      _name4, _value4, _name5, _value5,		\
			      _name6, _value6)				\
	EFX_POPULATE_DWORD_6(*_MCDI_DWORD(_buf, _field),		\
			     MC_CMD_ ## _name1, _value1,		\
			     MC_CMD_ ## _name2, _value2,		\
			     MC_CMD_ ## _name3, _value3,		\
			     MC_CMD_ ## _name4, _value4,		\
			     MC_CMD_ ## _name5, _value5,		\
			     MC_CMD_ ## _name6, _value6)
#define MCDI_POPULATE_DWORD_7(_buf, _field, _name1, _value1,		\
			      _name2, _value2, _name3, _value3,		\
			      _name4, _value4, _name5, _value5,		\
			      _name6, _value6, _name7, _value7)		\
	EFX_POPULATE_DWORD_7(*_MCDI_DWORD(_buf, _field),		\
			     MC_CMD_ ## _name1, _value1,		\
			     MC_CMD_ ## _name2, _value2,		\
			     MC_CMD_ ## _name3, _value3,		\
			     MC_CMD_ ## _name4, _value4,		\
			     MC_CMD_ ## _name5, _value5,		\
			     MC_CMD_ ## _name6, _value6,		\
			     MC_CMD_ ## _name7, _value7)
272 273 274 275 276 277 278
#define MCDI_SET_QWORD(_buf, _field, _value)				\
	do {								\
		EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0],	\
				     EFX_DWORD_0, (u32)(_value));	\
		EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1],	\
				     EFX_DWORD_0, (u64)(_value) >> 32);	\
	} while (0)
279 280 281
#define MCDI_QWORD(_buf, _field)					\
	(EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) |	\
	(u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
282 283 284 285 286 287 288
#define MCDI_FIELD(_ptr, _type, _field)					\
	EFX_EXTRACT_DWORD(						\
		*(efx_dword_t *)					\
		_MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
		MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f,	\
		(MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) +	\
		MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
289

290 291 292
#define _MCDI_ARRAY_PTR(_buf, _field, _index, _align)			\
	(_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
	 + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
293
#define MCDI_DECLARE_STRUCT_PTR(_name)					\
294 295 296
	efx_dword_t *_name
#define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index)			\
	((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
297 298 299 300 301 302
#define MCDI_VAR_ARRAY_LEN(_len, _field)				\
	min_t(size_t, MC_CMD_ ## _field ## _MAXNUM,			\
	      ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
#define MCDI_ARRAY_WORD(_buf, _field, _index)				\
	(BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) +		\
	 le16_to_cpu(*(__force const __le16 *)				\
303
		     _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
304 305
#define _MCDI_ARRAY_DWORD(_buf, _field, _index)				\
	(BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) +		\
306
	 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
307 308 309 310 311
#define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value)		\
	EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index),	\
			    EFX_DWORD_0, _value)
#define MCDI_ARRAY_DWORD(_buf, _field, _index)				\
	EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
312 313 314 315 316 317 318 319 320 321
#define _MCDI_ARRAY_QWORD(_buf, _field, _index)				\
	(BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) +		\
	 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
#define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value)		\
	do {								\
		EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
				    EFX_DWORD_0, (u32)(_value));	\
		EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
				    EFX_DWORD_0, (u64)(_value) >> 32);	\
	} while (0)
322
#define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2)		\
323 324
	MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index),	\
		   _type ## _TYPEDEF, _field2)
325

326 327 328
#define MCDI_EVENT_FIELD(_ev, _field)			\
	EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)

329
#define MCDI_CAPABILITY(field)						\
330
	MC_CMD_GET_CAPABILITIES_V8_OUT_ ## field ## _LBN
331 332

#define MCDI_CAPABILITY_OFST(field) \
333
	MC_CMD_GET_CAPABILITIES_V8_OUT_ ## field ## _OFST
334

335
#define efx_has_cap(efx, field) \
336
	efx->type->check_caps(efx, \
337
			      MCDI_CAPABILITY(field), \
338 339
			      MCDI_CAPABILITY_OFST(field))

340 341 342 343 344 345 346 347
void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
			   u16 *fw_subtype_list, u32 *capabilities);
int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq);
int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
			size_t *size_out, size_t *erase_size_out,
			bool *protected_out);
348
int efx_new_mcdi_nvram_test_all(struct efx_nic *efx);
349 350 351 352 353 354 355 356 357 358 359 360 361
int efx_mcdi_nvram_test_all(struct efx_nic *efx);
int efx_mcdi_handle_assertion(struct efx_nic *efx);
void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac,
				  int *id_out);
int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
int efx_mcdi_flush_rxqs(struct efx_nic *efx);
int efx_mcdi_port_reconfigure(struct efx_nic *efx);
void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
void efx_mcdi_mac_start_stats(struct efx_nic *efx);
void efx_mcdi_mac_stop_stats(struct efx_nic *efx);
362
void efx_mcdi_mac_pull_stats(struct efx_nic *efx);
363 364
enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason);
int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method);
365 366
int efx_mcdi_set_workaround(struct efx_nic *efx, u32 type, bool enabled,
			    unsigned int *flags);
367 368
int efx_mcdi_get_workarounds(struct efx_nic *efx, unsigned int *impl_out,
			     unsigned int *enabled_out);
369

370
#ifdef CONFIG_SFC_MCDI_MON
371 372
int efx_mcdi_mon_probe(struct efx_nic *efx);
void efx_mcdi_mon_remove(struct efx_nic *efx);
373 374 375 376 377
#else
static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {}
#endif

378
#ifdef CONFIG_SFC_MTD
379 380 381 382 383 384 385
int efx_mcdi_mtd_read(struct mtd_info *mtd, loff_t start, size_t len,
		      size_t *retlen, u8 *buffer);
int efx_mcdi_mtd_erase(struct mtd_info *mtd, loff_t start, size_t len);
int efx_mcdi_mtd_write(struct mtd_info *mtd, loff_t start, size_t len,
		       size_t *retlen, const u8 *buffer);
int efx_mcdi_mtd_sync(struct mtd_info *mtd);
void efx_mcdi_mtd_rename(struct efx_mtd_partition *part);
386 387
#endif

388
#endif /* EFX_MCDI_H */