Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
| 2 | * Driver for Solarflare Solarstorm network controllers and boards |
Ben Hutchings | 0a6f40c | 2011-02-25 00:01:34 +0000 | [diff] [blame] | 3 | * Copyright 2008-2010 Solarflare Communications Inc. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 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 | /** |
| 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 | */ |
| 23 | enum efx_mcdi_state { |
| 24 | MCDI_STATE_QUIESCENT, |
| 25 | MCDI_STATE_RUNNING, |
| 26 | MCDI_STATE_COMPLETED, |
| 27 | }; |
| 28 | |
| 29 | enum 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 Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 45 | * @resprc: Response error/success code (Linux numbering) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 46 | * @resplen: Returned payload length |
| 47 | */ |
| 48 | struct efx_mcdi_iface { |
| 49 | atomic_t state; |
| 50 | wait_queue_head_t wq; |
| 51 | spinlock_t iface_lock; |
| 52 | enum efx_mcdi_mode mode; |
| 53 | unsigned int credits; |
| 54 | unsigned int seqno; |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame^] | 55 | int resprc; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 56 | size_t resplen; |
| 57 | }; |
| 58 | |
Ben Hutchings | 55c5e0f8 | 2012-01-06 20:25:39 +0000 | [diff] [blame] | 59 | struct efx_mcdi_mon { |
| 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; |
| 65 | unsigned int n_attrs; |
| 66 | }; |
| 67 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 68 | /** |
| 69 | * struct efx_mcdi_data - extra state for NICs that implement MCDI |
| 70 | * @iface: Interface/protocol state |
| 71 | * @hwmon: Hardware monitor state |
| 72 | */ |
| 73 | struct efx_mcdi_data { |
| 74 | struct efx_mcdi_iface iface; |
| 75 | #ifdef CONFIG_SFC_MCDI_MON |
| 76 | struct efx_mcdi_mon hwmon; |
| 77 | #endif |
| 78 | }; |
| 79 | |
| 80 | #ifdef CONFIG_SFC_MCDI_MON |
| 81 | static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx) |
| 82 | { |
| 83 | EFX_BUG_ON_PARANOID(!efx->mcdi); |
| 84 | return &efx->mcdi->hwmon; |
| 85 | } |
| 86 | #endif |
| 87 | |
Ben Hutchings | f073dde | 2012-09-18 02:33:55 +0100 | [diff] [blame] | 88 | extern int efx_mcdi_init(struct efx_nic *efx); |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 89 | extern void efx_mcdi_fini(struct efx_nic *efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 90 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 91 | extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, |
| 92 | const efx_dword_t *inbuf, size_t inlen, |
| 93 | efx_dword_t *outbuf, size_t outlen, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 94 | size_t *outlen_actual); |
| 95 | |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 96 | extern void efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd, |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 97 | const efx_dword_t *inbuf, size_t inlen); |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 98 | extern int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen, |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 99 | efx_dword_t *outbuf, size_t outlen, |
Stuart Hodgson | c3cba72 | 2012-07-16 17:40:47 +0100 | [diff] [blame] | 100 | size_t *outlen_actual); |
| 101 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 102 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 103 | extern int efx_mcdi_poll_reboot(struct efx_nic *efx); |
| 104 | extern void efx_mcdi_mode_poll(struct efx_nic *efx); |
| 105 | extern void efx_mcdi_mode_event(struct efx_nic *efx); |
| 106 | |
| 107 | extern void efx_mcdi_process_event(struct efx_channel *channel, |
| 108 | efx_qword_t *event); |
Ben Hutchings | 55c5e0f8 | 2012-01-06 20:25:39 +0000 | [diff] [blame] | 109 | extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 110 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 111 | /* We expect that 16- and 32-bit fields in MCDI requests and responses |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 112 | * are appropriately aligned, but 64-bit fields are only |
| 113 | * 32-bit-aligned. Also, on Siena we must copy to the MC shared |
| 114 | * memory strictly 32 bits at a time, so add any necessary padding. |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 115 | */ |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 116 | #define MCDI_DECLARE_BUF(_name, _len) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 117 | efx_dword_t _name[DIV_ROUND_UP(_len, 4)] |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 118 | #define _MCDI_PTR(_buf, _offset) \ |
| 119 | ((u8 *)(_buf) + (_offset)) |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 120 | #define MCDI_PTR(_buf, _field) \ |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 121 | _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST) |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 122 | #define _MCDI_CHECK_ALIGN(_ofst, _align) \ |
| 123 | ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1))) |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 124 | #define _MCDI_DWORD(_buf, _field) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 125 | ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2)) |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 126 | |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 127 | #define MCDI_SET_DWORD(_buf, _field, _value) \ |
| 128 | EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value) |
| 129 | #define MCDI_DWORD(_buf, _field) \ |
| 130 | EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0) |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 131 | #define MCDI_SET_QWORD(_buf, _field, _value) \ |
| 132 | do { \ |
| 133 | EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \ |
| 134 | EFX_DWORD_0, (u32)(_value)); \ |
| 135 | EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \ |
| 136 | EFX_DWORD_0, (u64)(_value) >> 32); \ |
| 137 | } while (0) |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 138 | #define MCDI_QWORD(_buf, _field) \ |
| 139 | (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \ |
| 140 | (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 141 | #define MCDI_FIELD(_ptr, _type, _field) \ |
Ben Hutchings | 0a6e500 | 2012-09-11 21:46:41 +0100 | [diff] [blame] | 142 | EFX_EXTRACT_DWORD( \ |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 143 | *(efx_dword_t *) \ |
| 144 | _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\ |
| 145 | MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \ |
| 146 | (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \ |
| 147 | MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1) |
| 148 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 149 | #define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \ |
| 150 | (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\ |
| 151 | + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align)) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 152 | #define MCDI_DECLARE_STRUCT_PTR(_name) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 153 | efx_dword_t *_name |
| 154 | #define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \ |
| 155 | ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 156 | #define MCDI_VAR_ARRAY_LEN(_len, _field) \ |
| 157 | min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \ |
| 158 | ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN) |
| 159 | #define MCDI_ARRAY_WORD(_buf, _field, _index) \ |
| 160 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \ |
| 161 | le16_to_cpu(*(__force const __le16 *) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 162 | _MCDI_ARRAY_PTR(_buf, _field, _index, 2))) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 163 | #define _MCDI_ARRAY_DWORD(_buf, _field, _index) \ |
| 164 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 165 | (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 166 | #define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \ |
| 167 | EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \ |
| 168 | EFX_DWORD_0, _value) |
| 169 | #define MCDI_ARRAY_DWORD(_buf, _field, _index) \ |
| 170 | EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0) |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 171 | #define _MCDI_ARRAY_QWORD(_buf, _field, _index) \ |
| 172 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \ |
| 173 | (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) |
| 174 | #define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \ |
| 175 | do { \ |
| 176 | EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\ |
| 177 | EFX_DWORD_0, (u32)(_value)); \ |
| 178 | EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\ |
| 179 | EFX_DWORD_0, (u64)(_value) >> 32); \ |
| 180 | } while (0) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 181 | #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \ |
| 182 | MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \ |
| 183 | _type ## _TYPEDEF, _field2) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 184 | |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 185 | #define MCDI_EVENT_FIELD(_ev, _field) \ |
| 186 | EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field) |
| 187 | |
Ben Hutchings | e5f0fd2 | 2011-02-24 23:57:47 +0000 | [diff] [blame] | 188 | extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 189 | extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating, |
| 190 | bool *was_attached_out); |
| 191 | extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address, |
Matthew Slattery | 6aa9c7f | 2010-07-14 15:36:19 +0100 | [diff] [blame] | 192 | u16 *fw_subtype_list, u32 *capabilities); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 193 | extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, |
| 194 | u32 dest_evq); |
| 195 | extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out); |
| 196 | extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type, |
| 197 | size_t *size_out, size_t *erase_size_out, |
| 198 | bool *protected_out); |
| 199 | extern int efx_mcdi_nvram_update_start(struct efx_nic *efx, |
| 200 | unsigned int type); |
| 201 | extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type, |
| 202 | loff_t offset, u8 *buffer, size_t length); |
| 203 | extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type, |
| 204 | loff_t offset, const u8 *buffer, |
| 205 | size_t length); |
Ben Hutchings | 5a27e86 | 2010-01-25 15:49:59 -0800 | [diff] [blame] | 206 | #define EFX_MCDI_NVRAM_LEN_MAX 128 |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 207 | extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type, |
| 208 | loff_t offset, size_t length); |
| 209 | extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx, |
| 210 | unsigned int type); |
Ben Hutchings | 2e80340 | 2010-02-03 09:31:01 +0000 | [diff] [blame] | 211 | extern int efx_mcdi_nvram_test_all(struct efx_nic *efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 212 | extern int efx_mcdi_handle_assertion(struct efx_nic *efx); |
| 213 | extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 214 | extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, |
| 215 | const u8 *mac, int *id_out); |
| 216 | extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out); |
| 217 | extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id); |
| 218 | extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 219 | extern int efx_mcdi_flush_rxqs(struct efx_nic *efx); |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 220 | extern int efx_mcdi_port_probe(struct efx_nic *efx); |
| 221 | extern void efx_mcdi_port_remove(struct efx_nic *efx); |
| 222 | extern int efx_mcdi_port_reconfigure(struct efx_nic *efx); |
| 223 | extern void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev); |
Ben Hutchings | cd2d5b5 | 2012-02-14 00:48:07 +0000 | [diff] [blame] | 224 | extern int efx_mcdi_set_mac(struct efx_nic *efx); |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 225 | #define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1)) |
| 226 | extern void efx_mcdi_mac_start_stats(struct efx_nic *efx); |
| 227 | extern void efx_mcdi_mac_stop_stats(struct efx_nic *efx); |
Ben Hutchings | 710b208 | 2011-09-03 00:15:00 +0100 | [diff] [blame] | 228 | extern bool efx_mcdi_mac_check_fault(struct efx_nic *efx); |
Ben Hutchings | 6bff861 | 2012-09-18 02:33:52 +0100 | [diff] [blame] | 229 | extern enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason); |
| 230 | extern int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 231 | |
Ben Hutchings | 55c5e0f8 | 2012-01-06 20:25:39 +0000 | [diff] [blame] | 232 | #ifdef CONFIG_SFC_MCDI_MON |
| 233 | extern int efx_mcdi_mon_probe(struct efx_nic *efx); |
| 234 | extern void efx_mcdi_mon_remove(struct efx_nic *efx); |
| 235 | #else |
| 236 | static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; } |
| 237 | static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {} |
| 238 | #endif |
| 239 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 240 | #endif /* EFX_MCDI_H */ |