blob: 0cb0d5a8b7f663946b02d0eeace9bf9caf9e1a7a [file] [log] [blame]
Ben Hutchingsafd4aea2009-11-29 15:15:25 +00001/****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
Ben Hutchings0a6f40c2011-02-25 00:01:34 +00003 * Copyright 2008-2010 Solarflare Communications Inc.
Ben Hutchingsafd4aea2009-11-29 15:15:25 +00004 *
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/**
14 * enum efx_mcdi_state
15 * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
16 * mcdi_lock then they are able to move to MCDI_STATE_RUNNING
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
21 * MCDI_STATE_RUNNING.
22 */
23enum efx_mcdi_state {
24 MCDI_STATE_QUIESCENT,
25 MCDI_STATE_RUNNING,
26 MCDI_STATE_COMPLETED,
27};
28
29enum efx_mcdi_mode {
30 MCDI_MODE_POLL,
31 MCDI_MODE_EVENTS,
32};
33
34/**
35 * struct efx_mcdi_iface
36 * @state: Interface state. Waited for by mcdi_wq.
37 * @wq: Wait queue for threads waiting for state != STATE_RUNNING
38 * @iface_lock: Protects @credits, @seqno, @resprc, @resplen
39 * @mode: Poll for mcdi completion, or wait for an mcdi_event.
40 * Serialised by @lock
41 * @seqno: The next sequence number to use for mcdi requests.
42 * Serialised by @lock
43 * @credits: Number of spurious MCDI completion events allowed before we
44 * trigger a fatal error. Protected by @lock
Ben Hutchings5bc283e2012-10-08 21:43:00 +010045 * @resprc: Response error/success code (Linux numbering)
Ben Hutchingsdf2cd8a2012-09-19 00:56:18 +010046 * @resp_hdr_len: Response header length
47 * @resp_data_len: Response data (SDU or error) length
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000048 */
49struct efx_mcdi_iface {
50 atomic_t state;
51 wait_queue_head_t wq;
52 spinlock_t iface_lock;
53 enum efx_mcdi_mode mode;
54 unsigned int credits;
55 unsigned int seqno;
Ben Hutchings5bc283e2012-10-08 21:43:00 +010056 int resprc;
Ben Hutchingsdf2cd8a2012-09-19 00:56:18 +010057 size_t resp_hdr_len;
58 size_t resp_data_len;
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000059};
60
Ben Hutchings55c5e0f82012-01-06 20:25:39 +000061struct efx_mcdi_mon {
62 struct efx_buffer dma_buf;
63 struct mutex update_lock;
64 unsigned long last_update;
65 struct device *device;
66 struct efx_mcdi_mon_attribute *attrs;
67 unsigned int n_attrs;
68};
69
Ben Hutchingsf3ad5002012-09-18 02:33:56 +010070/**
71 * struct efx_mcdi_data - extra state for NICs that implement MCDI
72 * @iface: Interface/protocol state
73 * @hwmon: Hardware monitor state
74 */
75struct efx_mcdi_data {
76 struct efx_mcdi_iface iface;
77#ifdef CONFIG_SFC_MCDI_MON
78 struct efx_mcdi_mon hwmon;
79#endif
80};
81
82#ifdef CONFIG_SFC_MCDI_MON
83static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
84{
85 EFX_BUG_ON_PARANOID(!efx->mcdi);
86 return &efx->mcdi->hwmon;
87}
88#endif
89
Ben Hutchingsf073dde2012-09-18 02:33:55 +010090extern int efx_mcdi_init(struct efx_nic *efx);
Ben Hutchingsf3ad5002012-09-18 02:33:56 +010091extern void efx_mcdi_fini(struct efx_nic *efx);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000092
Ben Hutchings9528b922012-09-14 17:31:41 +010093extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd,
94 const efx_dword_t *inbuf, size_t inlen,
95 efx_dword_t *outbuf, size_t outlen,
Ben Hutchingsafd4aea2009-11-29 15:15:25 +000096 size_t *outlen_actual);
97
Ben Hutchingsdf2cd8a2012-09-19 00:56:18 +010098extern int efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
99 const efx_dword_t *inbuf, size_t inlen);
Stuart Hodgsonc3cba722012-07-16 17:40:47 +0100100extern int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
Ben Hutchings9528b922012-09-14 17:31:41 +0100101 efx_dword_t *outbuf, size_t outlen,
Stuart Hodgsonc3cba722012-07-16 17:40:47 +0100102 size_t *outlen_actual);
103
Ben Hutchings9528b922012-09-14 17:31:41 +0100104
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000105extern int efx_mcdi_poll_reboot(struct efx_nic *efx);
106extern void efx_mcdi_mode_poll(struct efx_nic *efx);
107extern void efx_mcdi_mode_event(struct efx_nic *efx);
108
109extern void efx_mcdi_process_event(struct efx_channel *channel,
110 efx_qword_t *event);
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000111extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000112
Ben Hutchings9528b922012-09-14 17:31:41 +0100113/* We expect that 16- and 32-bit fields in MCDI requests and responses
Ben Hutchings338f74d2012-10-10 23:20:17 +0100114 * are appropriately aligned, but 64-bit fields are only
115 * 32-bit-aligned. Also, on Siena we must copy to the MC shared
116 * memory strictly 32 bits at a time, so add any necessary padding.
Ben Hutchings9528b922012-09-14 17:31:41 +0100117 */
Ben Hutchings59cfc472012-09-14 17:30:10 +0100118#define MCDI_DECLARE_BUF(_name, _len) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100119 efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100120#define _MCDI_PTR(_buf, _offset) \
121 ((u8 *)(_buf) + (_offset))
Ben Hutchings30af6912012-09-14 17:30:44 +0100122#define MCDI_PTR(_buf, _field) \
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100123 _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
Ben Hutchings9528b922012-09-14 17:31:41 +0100124#define _MCDI_CHECK_ALIGN(_ofst, _align) \
125 ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
Ben Hutchings30af6912012-09-14 17:30:44 +0100126#define _MCDI_DWORD(_buf, _field) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100127 ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
Ben Hutchings59cfc472012-09-14 17:30:10 +0100128
Ben Hutchings30af6912012-09-14 17:30:44 +0100129#define MCDI_SET_DWORD(_buf, _field, _value) \
130 EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
131#define MCDI_DWORD(_buf, _field) \
132 EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
Ben Hutchings338f74d2012-10-10 23:20:17 +0100133#define MCDI_SET_QWORD(_buf, _field, _value) \
134 do { \
135 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \
136 EFX_DWORD_0, (u32)(_value)); \
137 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \
138 EFX_DWORD_0, (u64)(_value) >> 32); \
139 } while (0)
Ben Hutchings30af6912012-09-14 17:30:44 +0100140#define MCDI_QWORD(_buf, _field) \
141 (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \
142 (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100143#define MCDI_FIELD(_ptr, _type, _field) \
Ben Hutchings0a6e5002012-09-11 21:46:41 +0100144 EFX_EXTRACT_DWORD( \
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100145 *(efx_dword_t *) \
146 _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
147 MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
148 (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \
149 MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
150
Ben Hutchings9528b922012-09-14 17:31:41 +0100151#define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \
152 (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
153 + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100154#define MCDI_DECLARE_STRUCT_PTR(_name) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100155 efx_dword_t *_name
156#define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \
157 ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100158#define MCDI_VAR_ARRAY_LEN(_len, _field) \
159 min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \
160 ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
161#define MCDI_ARRAY_WORD(_buf, _field, _index) \
162 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
163 le16_to_cpu(*(__force const __le16 *) \
Ben Hutchings9528b922012-09-14 17:31:41 +0100164 _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100165#define _MCDI_ARRAY_DWORD(_buf, _field, _index) \
166 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \
Ben Hutchings9528b922012-09-14 17:31:41 +0100167 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100168#define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \
169 EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \
170 EFX_DWORD_0, _value)
171#define MCDI_ARRAY_DWORD(_buf, _field, _index) \
172 EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
Ben Hutchings338f74d2012-10-10 23:20:17 +0100173#define _MCDI_ARRAY_QWORD(_buf, _field, _index) \
174 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \
175 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
176#define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \
177 do { \
178 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
179 EFX_DWORD_0, (u32)(_value)); \
180 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
181 EFX_DWORD_0, (u64)(_value) >> 32); \
182 } while (0)
Ben Hutchingsa649dfc2012-09-14 17:30:58 +0100183#define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
184 MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \
185 _type ## _TYPEDEF, _field2)
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000186
Ben Hutchings30af6912012-09-14 17:30:44 +0100187#define MCDI_EVENT_FIELD(_ev, _field) \
188 EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
189
Ben Hutchingse5f0fd22011-02-24 23:57:47 +0000190extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000191extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
192 bool *was_attached_out);
193extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
Matthew Slattery6aa9c7f2010-07-14 15:36:19 +0100194 u16 *fw_subtype_list, u32 *capabilities);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000195extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart,
196 u32 dest_evq);
197extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
198extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
199 size_t *size_out, size_t *erase_size_out,
200 bool *protected_out);
201extern int efx_mcdi_nvram_update_start(struct efx_nic *efx,
202 unsigned int type);
203extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
204 loff_t offset, u8 *buffer, size_t length);
205extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
206 loff_t offset, const u8 *buffer,
207 size_t length);
Ben Hutchings5a27e862010-01-25 15:49:59 -0800208#define EFX_MCDI_NVRAM_LEN_MAX 128
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000209extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
210 loff_t offset, size_t length);
211extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx,
212 unsigned int type);
Ben Hutchings2e803402010-02-03 09:31:01 +0000213extern int efx_mcdi_nvram_test_all(struct efx_nic *efx);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000214extern int efx_mcdi_handle_assertion(struct efx_nic *efx);
215extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000216extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx,
217 const u8 *mac, int *id_out);
218extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
219extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
220extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000221extern int efx_mcdi_flush_rxqs(struct efx_nic *efx);
Ben Hutchings43f775b22012-09-18 02:33:54 +0100222extern int efx_mcdi_port_probe(struct efx_nic *efx);
223extern void efx_mcdi_port_remove(struct efx_nic *efx);
224extern int efx_mcdi_port_reconfigure(struct efx_nic *efx);
225extern void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
Ben Hutchingscd2d5b52012-02-14 00:48:07 +0000226extern int efx_mcdi_set_mac(struct efx_nic *efx);
Ben Hutchings43f775b22012-09-18 02:33:54 +0100227#define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1))
228extern void efx_mcdi_mac_start_stats(struct efx_nic *efx);
229extern void efx_mcdi_mac_stop_stats(struct efx_nic *efx);
Ben Hutchings710b2082011-09-03 00:15:00 +0100230extern bool efx_mcdi_mac_check_fault(struct efx_nic *efx);
Ben Hutchings6bff8612012-09-18 02:33:52 +0100231extern enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason);
232extern int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method);
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000233
Ben Hutchings55c5e0f82012-01-06 20:25:39 +0000234#ifdef CONFIG_SFC_MCDI_MON
235extern int efx_mcdi_mon_probe(struct efx_nic *efx);
236extern void efx_mcdi_mon_remove(struct efx_nic *efx);
237#else
238static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
239static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {}
240#endif
241
Ben Hutchingsafd4aea2009-11-29 15:15:25 +0000242#endif /* EFX_MCDI_H */