Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 1 | /**************************************************************************** |
Ben Hutchings | f7a6d2c | 2013-08-29 23:32:48 +0100 | [diff] [blame] | 2 | * Driver for Solarflare network controllers and boards |
| 3 | * Copyright 2008-2013 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 | /** |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 14 | * enum efx_mcdi_state - MCDI request handling state |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 15 | * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 16 | * mcdi @iface_lock then they are able to move to %MCDI_STATE_RUNNING |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 17 | * @MCDI_STATE_RUNNING_SYNC: There is a synchronous MCDI request pending. |
| 18 | * Only the thread that moved into this state is allowed to move out of it. |
| 19 | * @MCDI_STATE_RUNNING_ASYNC: There is an asynchronous MCDI request pending. |
Bert Kenward | acd43a9 | 2015-12-23 08:57:18 +0000 | [diff] [blame^] | 20 | * @MCDI_STATE_PROXY_WAIT: An MCDI request has completed with a response that |
| 21 | * indicates we must wait for a proxy try again message. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 22 | * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread |
| 23 | * has not yet consumed the result. For all other threads, equivalent to |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 24 | * %MCDI_STATE_RUNNING. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 25 | */ |
| 26 | enum efx_mcdi_state { |
| 27 | MCDI_STATE_QUIESCENT, |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 28 | MCDI_STATE_RUNNING_SYNC, |
| 29 | MCDI_STATE_RUNNING_ASYNC, |
Bert Kenward | acd43a9 | 2015-12-23 08:57:18 +0000 | [diff] [blame^] | 30 | MCDI_STATE_PROXY_WAIT, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 31 | MCDI_STATE_COMPLETED, |
| 32 | }; |
| 33 | |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 34 | /** |
| 35 | * enum efx_mcdi_mode - MCDI transaction mode |
| 36 | * @MCDI_MODE_POLL: poll for MCDI completion, until timeout |
| 37 | * @MCDI_MODE_EVENTS: wait for an mcdi_event. On timeout, poll once |
| 38 | * @MCDI_MODE_FAIL: we think MCDI is dead, so fail-fast all calls |
| 39 | */ |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 40 | enum efx_mcdi_mode { |
| 41 | MCDI_MODE_POLL, |
| 42 | MCDI_MODE_EVENTS, |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 43 | MCDI_MODE_FAIL, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | /** |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 47 | * struct efx_mcdi_iface - MCDI protocol context |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 48 | * @efx: The associated NIC. |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 49 | * @state: Request handling state. Waited for by @wq. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 50 | * @mode: Poll for mcdi completion, or wait for an mcdi_event. |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 51 | * @wq: Wait queue for threads waiting for @state != %MCDI_STATE_RUNNING |
Daniel Pieczko | d36a08b | 2013-06-20 11:40:07 +0100 | [diff] [blame] | 52 | * @new_epoch: Indicates start of day or start of MC reboot recovery |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 53 | * @iface_lock: Serialises access to @seqno, @credits and response metadata |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 54 | * @seqno: The next sequence number to use for mcdi requests. |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 55 | * @credits: Number of spurious MCDI completion events allowed before we |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 56 | * trigger a fatal error |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame] | 57 | * @resprc: Response error/success code (Linux numbering) |
Ben Hutchings | df2cd8a | 2012-09-19 00:56:18 +0100 | [diff] [blame] | 58 | * @resp_hdr_len: Response header length |
| 59 | * @resp_data_len: Response data (SDU or error) length |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 60 | * @async_lock: Serialises access to @async_list while event processing is |
| 61 | * enabled |
| 62 | * @async_list: Queue of asynchronous requests |
| 63 | * @async_timer: Timer for asynchronous request timeout |
Edward Cree | 75aba2a | 2015-05-27 13:13:54 +0100 | [diff] [blame] | 64 | * @logging_buffer: buffer that may be used to build MCDI tracing messages |
Edward Cree | e7fef9b | 2015-05-27 13:14:01 +0100 | [diff] [blame] | 65 | * @logging_enabled: whether to trace MCDI |
Bert Kenward | acd43a9 | 2015-12-23 08:57:18 +0000 | [diff] [blame^] | 66 | * @proxy_rx_handle: Most recently received proxy authorisation handle |
| 67 | * @proxy_rx_status: Status of most recent proxy authorisation |
| 68 | * @proxy_rx_wq: Wait queue for updates to proxy_rx_handle |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 69 | */ |
| 70 | struct efx_mcdi_iface { |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 71 | struct efx_nic *efx; |
Ben Hutchings | 251111d | 2013-08-27 23:04:29 +0100 | [diff] [blame] | 72 | enum efx_mcdi_state state; |
Ben Hutchings | f76fe12 | 2012-10-26 17:53:11 +0100 | [diff] [blame] | 73 | enum efx_mcdi_mode mode; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 74 | wait_queue_head_t wq; |
| 75 | spinlock_t iface_lock; |
Daniel Pieczko | d36a08b | 2013-06-20 11:40:07 +0100 | [diff] [blame] | 76 | bool new_epoch; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 77 | unsigned int credits; |
| 78 | unsigned int seqno; |
Ben Hutchings | 5bc283e | 2012-10-08 21:43:00 +0100 | [diff] [blame] | 79 | int resprc; |
Bert Kenward | ac28d17 | 2015-12-23 08:56:40 +0000 | [diff] [blame] | 80 | int resprc_raw; |
Ben Hutchings | df2cd8a | 2012-09-19 00:56:18 +0100 | [diff] [blame] | 81 | size_t resp_hdr_len; |
| 82 | size_t resp_data_len; |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 83 | spinlock_t async_lock; |
| 84 | struct list_head async_list; |
| 85 | struct timer_list async_timer; |
Edward Cree | 75aba2a | 2015-05-27 13:13:54 +0100 | [diff] [blame] | 86 | #ifdef CONFIG_SFC_MCDI_LOGGING |
| 87 | char *logging_buffer; |
Edward Cree | e7fef9b | 2015-05-27 13:14:01 +0100 | [diff] [blame] | 88 | bool logging_enabled; |
Edward Cree | 75aba2a | 2015-05-27 13:13:54 +0100 | [diff] [blame] | 89 | #endif |
Bert Kenward | acd43a9 | 2015-12-23 08:57:18 +0000 | [diff] [blame^] | 90 | unsigned int proxy_rx_handle; |
| 91 | int proxy_rx_status; |
| 92 | wait_queue_head_t proxy_rx_wq; |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 93 | }; |
| 94 | |
Ben Hutchings | 55c5e0f8 | 2012-01-06 20:25:39 +0000 | [diff] [blame] | 95 | struct efx_mcdi_mon { |
| 96 | struct efx_buffer dma_buf; |
| 97 | struct mutex update_lock; |
| 98 | unsigned long last_update; |
| 99 | struct device *device; |
| 100 | struct efx_mcdi_mon_attribute *attrs; |
Guenter Roeck | 85493e6 | 2013-11-27 18:54:31 -0800 | [diff] [blame] | 101 | struct attribute_group group; |
| 102 | const struct attribute_group *groups[2]; |
Ben Hutchings | 55c5e0f8 | 2012-01-06 20:25:39 +0000 | [diff] [blame] | 103 | unsigned int n_attrs; |
| 104 | }; |
| 105 | |
Ben Hutchings | 45a3fd5 | 2012-11-28 04:38:14 +0000 | [diff] [blame] | 106 | struct efx_mcdi_mtd_partition { |
| 107 | struct efx_mtd_partition common; |
| 108 | bool updating; |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 109 | u16 nvram_type; |
Ben Hutchings | 45a3fd5 | 2012-11-28 04:38:14 +0000 | [diff] [blame] | 110 | u16 fw_subtype; |
| 111 | }; |
| 112 | |
| 113 | #define to_efx_mcdi_mtd_partition(mtd) \ |
| 114 | container_of(mtd, struct efx_mcdi_mtd_partition, common.mtd) |
| 115 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 116 | /** |
| 117 | * struct efx_mcdi_data - extra state for NICs that implement MCDI |
| 118 | * @iface: Interface/protocol state |
| 119 | * @hwmon: Hardware monitor state |
Ben Hutchings | 8349f7f | 2013-10-16 18:32:34 +0100 | [diff] [blame] | 120 | * @fn_flags: Flags for this function, as returned by %MC_CMD_DRV_ATTACH. |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 121 | */ |
| 122 | struct efx_mcdi_data { |
| 123 | struct efx_mcdi_iface iface; |
| 124 | #ifdef CONFIG_SFC_MCDI_MON |
| 125 | struct efx_mcdi_mon hwmon; |
| 126 | #endif |
Ben Hutchings | 8349f7f | 2013-10-16 18:32:34 +0100 | [diff] [blame] | 127 | u32 fn_flags; |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 128 | }; |
| 129 | |
Edward Cree | e283546 | 2014-04-16 19:27:48 +0100 | [diff] [blame] | 130 | static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx) |
| 131 | { |
| 132 | EFX_BUG_ON_PARANOID(!efx->mcdi); |
| 133 | return &efx->mcdi->iface; |
| 134 | } |
| 135 | |
Ben Hutchings | f3ad500 | 2012-09-18 02:33:56 +0100 | [diff] [blame] | 136 | #ifdef CONFIG_SFC_MCDI_MON |
| 137 | static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx) |
| 138 | { |
| 139 | EFX_BUG_ON_PARANOID(!efx->mcdi); |
| 140 | return &efx->mcdi->hwmon; |
| 141 | } |
| 142 | #endif |
| 143 | |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 144 | int efx_mcdi_init(struct efx_nic *efx); |
| 145 | void efx_mcdi_fini(struct efx_nic *efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 146 | |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 147 | int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd, const efx_dword_t *inbuf, |
| 148 | size_t inlen, efx_dword_t *outbuf, size_t outlen, |
| 149 | size_t *outlen_actual); |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 150 | int efx_mcdi_rpc_quiet(struct efx_nic *efx, unsigned cmd, |
| 151 | const efx_dword_t *inbuf, size_t inlen, |
| 152 | efx_dword_t *outbuf, size_t outlen, |
| 153 | size_t *outlen_actual); |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 154 | |
| 155 | int efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd, |
| 156 | const efx_dword_t *inbuf, size_t inlen); |
| 157 | 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] | 158 | efx_dword_t *outbuf, size_t outlen, |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 159 | size_t *outlen_actual); |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 160 | int efx_mcdi_rpc_finish_quiet(struct efx_nic *efx, unsigned cmd, |
| 161 | size_t inlen, efx_dword_t *outbuf, |
| 162 | size_t outlen, size_t *outlen_actual); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 163 | |
Ben Hutchings | cade715 | 2013-08-27 23:12:31 +0100 | [diff] [blame] | 164 | typedef void efx_mcdi_async_completer(struct efx_nic *efx, |
| 165 | unsigned long cookie, int rc, |
| 166 | efx_dword_t *outbuf, |
| 167 | size_t outlen_actual); |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 168 | int efx_mcdi_rpc_async(struct efx_nic *efx, unsigned int cmd, |
| 169 | const efx_dword_t *inbuf, size_t inlen, size_t outlen, |
| 170 | efx_mcdi_async_completer *complete, |
| 171 | unsigned long cookie); |
Edward Cree | 1e0b812 | 2013-05-31 18:36:12 +0100 | [diff] [blame] | 172 | int efx_mcdi_rpc_async_quiet(struct efx_nic *efx, unsigned int cmd, |
| 173 | const efx_dword_t *inbuf, size_t inlen, |
| 174 | size_t outlen, |
| 175 | efx_mcdi_async_completer *complete, |
| 176 | unsigned long cookie); |
| 177 | |
| 178 | void efx_mcdi_display_error(struct efx_nic *efx, unsigned cmd, |
| 179 | size_t inlen, efx_dword_t *outbuf, |
| 180 | size_t outlen, int rc); |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 181 | |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 182 | int efx_mcdi_poll_reboot(struct efx_nic *efx); |
| 183 | void efx_mcdi_mode_poll(struct efx_nic *efx); |
| 184 | void efx_mcdi_mode_event(struct efx_nic *efx); |
| 185 | void efx_mcdi_flush_async(struct efx_nic *efx); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 186 | |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 187 | void efx_mcdi_process_event(struct efx_channel *channel, efx_qword_t *event); |
| 188 | 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] | 189 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 190 | /* 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] | 191 | * are appropriately aligned, but 64-bit fields are only |
| 192 | * 32-bit-aligned. Also, on Siena we must copy to the MC shared |
| 193 | * memory strictly 32 bits at a time, so add any necessary padding. |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 194 | */ |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 195 | #define _MCDI_DECLARE_BUF(_name, _len) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 196 | efx_dword_t _name[DIV_ROUND_UP(_len, 4)] |
Jon Cooper | aa09a3d | 2015-05-20 11:10:41 +0100 | [diff] [blame] | 197 | #define MCDI_DECLARE_BUF(_name, _len) \ |
| 198 | _MCDI_DECLARE_BUF(_name, _len) = {{{0}}} |
| 199 | #define MCDI_DECLARE_BUF_ERR(_name) \ |
| 200 | MCDI_DECLARE_BUF(_name, 8) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 201 | #define _MCDI_PTR(_buf, _offset) \ |
| 202 | ((u8 *)(_buf) + (_offset)) |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 203 | #define MCDI_PTR(_buf, _field) \ |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 204 | _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST) |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 205 | #define _MCDI_CHECK_ALIGN(_ofst, _align) \ |
| 206 | ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1))) |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 207 | #define _MCDI_DWORD(_buf, _field) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 208 | ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2)) |
Ben Hutchings | 59cfc47 | 2012-09-14 17:30:10 +0100 | [diff] [blame] | 209 | |
Ben Hutchings | 8127d66 | 2013-08-29 19:19:29 +0100 | [diff] [blame] | 210 | #define MCDI_WORD(_buf, _field) \ |
| 211 | ((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \ |
| 212 | le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field))) |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 213 | #define MCDI_SET_DWORD(_buf, _field, _value) \ |
| 214 | EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value) |
| 215 | #define MCDI_DWORD(_buf, _field) \ |
| 216 | EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0) |
Ben Hutchings | f5253d9 | 2012-10-10 23:24:51 +0100 | [diff] [blame] | 217 | #define MCDI_POPULATE_DWORD_1(_buf, _field, _name1, _value1) \ |
| 218 | EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), \ |
| 219 | MC_CMD_ ## _name1, _value1) |
| 220 | #define MCDI_POPULATE_DWORD_2(_buf, _field, _name1, _value1, \ |
| 221 | _name2, _value2) \ |
| 222 | EFX_POPULATE_DWORD_2(*_MCDI_DWORD(_buf, _field), \ |
| 223 | MC_CMD_ ## _name1, _value1, \ |
| 224 | MC_CMD_ ## _name2, _value2) |
| 225 | #define MCDI_POPULATE_DWORD_3(_buf, _field, _name1, _value1, \ |
| 226 | _name2, _value2, _name3, _value3) \ |
| 227 | EFX_POPULATE_DWORD_3(*_MCDI_DWORD(_buf, _field), \ |
| 228 | MC_CMD_ ## _name1, _value1, \ |
| 229 | MC_CMD_ ## _name2, _value2, \ |
| 230 | MC_CMD_ ## _name3, _value3) |
| 231 | #define MCDI_POPULATE_DWORD_4(_buf, _field, _name1, _value1, \ |
| 232 | _name2, _value2, _name3, _value3, \ |
| 233 | _name4, _value4) \ |
| 234 | EFX_POPULATE_DWORD_4(*_MCDI_DWORD(_buf, _field), \ |
| 235 | MC_CMD_ ## _name1, _value1, \ |
| 236 | MC_CMD_ ## _name2, _value2, \ |
| 237 | MC_CMD_ ## _name3, _value3, \ |
| 238 | MC_CMD_ ## _name4, _value4) |
| 239 | #define MCDI_POPULATE_DWORD_5(_buf, _field, _name1, _value1, \ |
| 240 | _name2, _value2, _name3, _value3, \ |
| 241 | _name4, _value4, _name5, _value5) \ |
| 242 | EFX_POPULATE_DWORD_5(*_MCDI_DWORD(_buf, _field), \ |
| 243 | MC_CMD_ ## _name1, _value1, \ |
| 244 | MC_CMD_ ## _name2, _value2, \ |
| 245 | MC_CMD_ ## _name3, _value3, \ |
| 246 | MC_CMD_ ## _name4, _value4, \ |
| 247 | MC_CMD_ ## _name5, _value5) |
| 248 | #define MCDI_POPULATE_DWORD_6(_buf, _field, _name1, _value1, \ |
| 249 | _name2, _value2, _name3, _value3, \ |
| 250 | _name4, _value4, _name5, _value5, \ |
| 251 | _name6, _value6) \ |
| 252 | EFX_POPULATE_DWORD_6(*_MCDI_DWORD(_buf, _field), \ |
| 253 | MC_CMD_ ## _name1, _value1, \ |
| 254 | MC_CMD_ ## _name2, _value2, \ |
| 255 | MC_CMD_ ## _name3, _value3, \ |
| 256 | MC_CMD_ ## _name4, _value4, \ |
| 257 | MC_CMD_ ## _name5, _value5, \ |
| 258 | MC_CMD_ ## _name6, _value6) |
| 259 | #define MCDI_POPULATE_DWORD_7(_buf, _field, _name1, _value1, \ |
| 260 | _name2, _value2, _name3, _value3, \ |
| 261 | _name4, _value4, _name5, _value5, \ |
| 262 | _name6, _value6, _name7, _value7) \ |
| 263 | EFX_POPULATE_DWORD_7(*_MCDI_DWORD(_buf, _field), \ |
| 264 | MC_CMD_ ## _name1, _value1, \ |
| 265 | MC_CMD_ ## _name2, _value2, \ |
| 266 | MC_CMD_ ## _name3, _value3, \ |
| 267 | MC_CMD_ ## _name4, _value4, \ |
| 268 | MC_CMD_ ## _name5, _value5, \ |
| 269 | MC_CMD_ ## _name6, _value6, \ |
| 270 | MC_CMD_ ## _name7, _value7) |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 271 | #define MCDI_SET_QWORD(_buf, _field, _value) \ |
| 272 | do { \ |
| 273 | EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \ |
| 274 | EFX_DWORD_0, (u32)(_value)); \ |
| 275 | EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \ |
| 276 | EFX_DWORD_0, (u64)(_value) >> 32); \ |
| 277 | } while (0) |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 278 | #define MCDI_QWORD(_buf, _field) \ |
| 279 | (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \ |
| 280 | (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] | 281 | #define MCDI_FIELD(_ptr, _type, _field) \ |
Ben Hutchings | 0a6e500 | 2012-09-11 21:46:41 +0100 | [diff] [blame] | 282 | EFX_EXTRACT_DWORD( \ |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 283 | *(efx_dword_t *) \ |
| 284 | _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\ |
| 285 | MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \ |
| 286 | (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \ |
| 287 | MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1) |
| 288 | |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 289 | #define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \ |
| 290 | (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\ |
| 291 | + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align)) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 292 | #define MCDI_DECLARE_STRUCT_PTR(_name) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 293 | efx_dword_t *_name |
| 294 | #define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \ |
| 295 | ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 296 | #define MCDI_VAR_ARRAY_LEN(_len, _field) \ |
| 297 | min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \ |
| 298 | ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN) |
| 299 | #define MCDI_ARRAY_WORD(_buf, _field, _index) \ |
| 300 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \ |
| 301 | le16_to_cpu(*(__force const __le16 *) \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 302 | _MCDI_ARRAY_PTR(_buf, _field, _index, 2))) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 303 | #define _MCDI_ARRAY_DWORD(_buf, _field, _index) \ |
| 304 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \ |
Ben Hutchings | 9528b92 | 2012-09-14 17:31:41 +0100 | [diff] [blame] | 305 | (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 306 | #define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \ |
| 307 | EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \ |
| 308 | EFX_DWORD_0, _value) |
| 309 | #define MCDI_ARRAY_DWORD(_buf, _field, _index) \ |
| 310 | EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0) |
Ben Hutchings | 338f74d | 2012-10-10 23:20:17 +0100 | [diff] [blame] | 311 | #define _MCDI_ARRAY_QWORD(_buf, _field, _index) \ |
| 312 | (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \ |
| 313 | (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4)) |
| 314 | #define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \ |
| 315 | do { \ |
| 316 | EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\ |
| 317 | EFX_DWORD_0, (u32)(_value)); \ |
| 318 | EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\ |
| 319 | EFX_DWORD_0, (u64)(_value) >> 32); \ |
| 320 | } while (0) |
Ben Hutchings | a649dfc | 2012-09-14 17:30:58 +0100 | [diff] [blame] | 321 | #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \ |
| 322 | MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \ |
| 323 | _type ## _TYPEDEF, _field2) |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 324 | |
Ben Hutchings | 30af691 | 2012-09-14 17:30:44 +0100 | [diff] [blame] | 325 | #define MCDI_EVENT_FIELD(_ev, _field) \ |
| 326 | EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field) |
| 327 | |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 328 | void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len); |
| 329 | int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address, |
| 330 | u16 *fw_subtype_list, u32 *capabilities); |
| 331 | int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq); |
| 332 | int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out); |
| 333 | int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type, |
| 334 | size_t *size_out, size_t *erase_size_out, |
| 335 | bool *protected_out); |
| 336 | int efx_mcdi_nvram_test_all(struct efx_nic *efx); |
| 337 | int efx_mcdi_handle_assertion(struct efx_nic *efx); |
| 338 | void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode); |
| 339 | int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac, |
| 340 | int *id_out); |
| 341 | int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out); |
| 342 | int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id); |
| 343 | int efx_mcdi_wol_filter_reset(struct efx_nic *efx); |
| 344 | int efx_mcdi_flush_rxqs(struct efx_nic *efx); |
| 345 | int efx_mcdi_port_probe(struct efx_nic *efx); |
| 346 | void efx_mcdi_port_remove(struct efx_nic *efx); |
| 347 | int efx_mcdi_port_reconfigure(struct efx_nic *efx); |
| 348 | int efx_mcdi_port_get_number(struct efx_nic *efx); |
| 349 | u32 efx_mcdi_phy_get_caps(struct efx_nic *efx); |
| 350 | void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev); |
| 351 | int efx_mcdi_set_mac(struct efx_nic *efx); |
Ben Hutchings | 43f775b2 | 2012-09-18 02:33:54 +0100 | [diff] [blame] | 352 | #define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1)) |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 353 | void efx_mcdi_mac_start_stats(struct efx_nic *efx); |
| 354 | void efx_mcdi_mac_stop_stats(struct efx_nic *efx); |
Jon Cooper | f8f3b5a | 2013-09-30 17:36:50 +0100 | [diff] [blame] | 355 | void efx_mcdi_mac_pull_stats(struct efx_nic *efx); |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 356 | bool efx_mcdi_mac_check_fault(struct efx_nic *efx); |
| 357 | enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason); |
| 358 | int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method); |
Daniel Pieczko | 34ccfe6 | 2015-07-21 15:09:43 +0100 | [diff] [blame] | 359 | int efx_mcdi_set_workaround(struct efx_nic *efx, u32 type, bool enabled, |
| 360 | unsigned int *flags); |
Edward Cree | 267d9d7 | 2015-05-06 00:59:18 +0100 | [diff] [blame] | 361 | int efx_mcdi_get_workarounds(struct efx_nic *efx, unsigned int *impl_out, |
| 362 | unsigned int *enabled_out); |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 363 | |
Ben Hutchings | 55c5e0f8 | 2012-01-06 20:25:39 +0000 | [diff] [blame] | 364 | #ifdef CONFIG_SFC_MCDI_MON |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 365 | int efx_mcdi_mon_probe(struct efx_nic *efx); |
| 366 | void efx_mcdi_mon_remove(struct efx_nic *efx); |
Ben Hutchings | 55c5e0f8 | 2012-01-06 20:25:39 +0000 | [diff] [blame] | 367 | #else |
| 368 | static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; } |
| 369 | static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {} |
| 370 | #endif |
| 371 | |
Ben Hutchings | 45a3fd5 | 2012-11-28 04:38:14 +0000 | [diff] [blame] | 372 | #ifdef CONFIG_SFC_MTD |
Joe Perches | 00aef98 | 2013-09-23 11:37:59 -0700 | [diff] [blame] | 373 | int efx_mcdi_mtd_read(struct mtd_info *mtd, loff_t start, size_t len, |
| 374 | size_t *retlen, u8 *buffer); |
| 375 | int efx_mcdi_mtd_erase(struct mtd_info *mtd, loff_t start, size_t len); |
| 376 | int efx_mcdi_mtd_write(struct mtd_info *mtd, loff_t start, size_t len, |
| 377 | size_t *retlen, const u8 *buffer); |
| 378 | int efx_mcdi_mtd_sync(struct mtd_info *mtd); |
| 379 | void efx_mcdi_mtd_rename(struct efx_mtd_partition *part); |
Ben Hutchings | 45a3fd5 | 2012-11-28 04:38:14 +0000 | [diff] [blame] | 380 | #endif |
| 381 | |
Ben Hutchings | afd4aea | 2009-11-29 15:15:25 +0000 | [diff] [blame] | 382 | #endif /* EFX_MCDI_H */ |