1 /****************************************************************************
2 * Driver for Solarflare Solarstorm network controllers and boards
3 * Copyright 2008-2010 Solarflare Communications Inc.
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.
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
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.
41 * @seqno: The next sequence number to use for mcdi requests.
43 * @credits: Number of spurious MCDI completion events allowed before we
44 * trigger a fatal error. Protected by @lock
45 * @resprc: Returned MCDI completion
46 * @resplen: Returned payload length
48 struct efx_mcdi_iface {
51 spinlock_t iface_lock;
52 enum efx_mcdi_mode mode;
60 struct efx_buffer dma_buf;
61 struct mutex update_lock;
62 unsigned long last_update;
63 struct device *device;
64 struct efx_mcdi_mon_attribute *attrs;
68 extern int efx_mcdi_init(struct efx_nic *efx);
70 extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd,
71 const efx_dword_t *inbuf, size_t inlen,
72 efx_dword_t *outbuf, size_t outlen,
73 size_t *outlen_actual);
75 extern void efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
76 const efx_dword_t *inbuf, size_t inlen);
77 extern int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
78 efx_dword_t *outbuf, size_t outlen,
79 size_t *outlen_actual);
82 extern int efx_mcdi_poll_reboot(struct efx_nic *efx);
83 extern void efx_mcdi_mode_poll(struct efx_nic *efx);
84 extern void efx_mcdi_mode_event(struct efx_nic *efx);
86 extern void efx_mcdi_process_event(struct efx_channel *channel,
88 extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
90 /* We expect that 16- and 32-bit fields in MCDI requests and responses
91 * are appropriately aligned, but 64-bit fields are only
92 * 32-bit-aligned. Also, on Siena we must copy to the MC shared
93 * memory strictly 32 bits at a time, so add any necessary padding.
95 #define MCDI_DECLARE_BUF(_name, _len) \
96 efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
97 #define _MCDI_PTR(_buf, _offset) \
98 ((u8 *)(_buf) + (_offset))
99 #define MCDI_PTR(_buf, _field) \
100 _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
101 #define _MCDI_CHECK_ALIGN(_ofst, _align) \
102 ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
103 #define _MCDI_DWORD(_buf, _field) \
104 ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
106 #define MCDI_SET_DWORD(_buf, _field, _value) \
107 EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
108 #define MCDI_DWORD(_buf, _field) \
109 EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
110 #define MCDI_SET_QWORD(_buf, _field, _value) \
112 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \
113 EFX_DWORD_0, (u32)(_value)); \
114 EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \
115 EFX_DWORD_0, (u64)(_value) >> 32); \
117 #define MCDI_QWORD(_buf, _field) \
118 (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \
119 (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
120 #define MCDI_FIELD(_ptr, _type, _field) \
123 _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
124 MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
125 (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \
126 MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
128 #define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \
129 (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
130 + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
131 #define MCDI_DECLARE_STRUCT_PTR(_name) \
133 #define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \
134 ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
135 #define MCDI_VAR_ARRAY_LEN(_len, _field) \
136 min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \
137 ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
138 #define MCDI_ARRAY_WORD(_buf, _field, _index) \
139 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
140 le16_to_cpu(*(__force const __le16 *) \
141 _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
142 #define _MCDI_ARRAY_DWORD(_buf, _field, _index) \
143 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \
144 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
145 #define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \
146 EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \
148 #define MCDI_ARRAY_DWORD(_buf, _field, _index) \
149 EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
150 #define _MCDI_ARRAY_QWORD(_buf, _field, _index) \
151 (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \
152 (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
153 #define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \
155 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
156 EFX_DWORD_0, (u32)(_value)); \
157 EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
158 EFX_DWORD_0, (u64)(_value) >> 32); \
160 #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
161 MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \
162 _type ## _TYPEDEF, _field2)
164 #define MCDI_EVENT_FIELD(_ev, _field) \
165 EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
167 extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
168 extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
169 bool *was_attached_out);
170 extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
171 u16 *fw_subtype_list, u32 *capabilities);
172 extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart,
174 extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
175 extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
176 size_t *size_out, size_t *erase_size_out,
177 bool *protected_out);
178 extern int efx_mcdi_nvram_update_start(struct efx_nic *efx,
180 extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
181 loff_t offset, u8 *buffer, size_t length);
182 extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
183 loff_t offset, const u8 *buffer,
185 #define EFX_MCDI_NVRAM_LEN_MAX 128
186 extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
187 loff_t offset, size_t length);
188 extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx,
190 extern int efx_mcdi_nvram_test_all(struct efx_nic *efx);
191 extern int efx_mcdi_handle_assertion(struct efx_nic *efx);
192 extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
193 extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx,
194 const u8 *mac, int *id_out);
195 extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
196 extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
197 extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
198 extern int efx_mcdi_flush_rxqs(struct efx_nic *efx);
199 extern int efx_mcdi_port_probe(struct efx_nic *efx);
200 extern void efx_mcdi_port_remove(struct efx_nic *efx);
201 extern int efx_mcdi_port_reconfigure(struct efx_nic *efx);
202 extern void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
203 extern int efx_mcdi_set_mac(struct efx_nic *efx);
204 #define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1))
205 extern void efx_mcdi_mac_start_stats(struct efx_nic *efx);
206 extern void efx_mcdi_mac_stop_stats(struct efx_nic *efx);
207 extern bool efx_mcdi_mac_check_fault(struct efx_nic *efx);
208 extern enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason);
209 extern int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method);
211 #ifdef CONFIG_SFC_MCDI_MON
212 extern int efx_mcdi_mon_probe(struct efx_nic *efx);
213 extern void efx_mcdi_mon_remove(struct efx_nic *efx);
215 static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
216 static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {}
219 #endif /* EFX_MCDI_H */