Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /****************************************************************************
0003  * Driver for Solarflare network controllers and boards
0004  * Copyright 2008-2013 Solarflare Communications Inc.
0005  */
0006 
0007 #ifndef EFX_MCDI_H
0008 #define EFX_MCDI_H
0009 
0010 /**
0011  * enum efx_mcdi_state - MCDI request handling state
0012  * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
0013  *  mcdi @iface_lock then they are able to move to %MCDI_STATE_RUNNING
0014  * @MCDI_STATE_RUNNING_SYNC: There is a synchronous MCDI request pending.
0015  *  Only the thread that moved into this state is allowed to move out of it.
0016  * @MCDI_STATE_RUNNING_ASYNC: There is an asynchronous MCDI request pending.
0017  * @MCDI_STATE_PROXY_WAIT: An MCDI request has completed with a response that
0018  *  indicates we must wait for a proxy try again message.
0019  * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread
0020  *  has not yet consumed the result. For all other threads, equivalent to
0021  *  %MCDI_STATE_RUNNING.
0022  */
0023 enum efx_mcdi_state {
0024     MCDI_STATE_QUIESCENT,
0025     MCDI_STATE_RUNNING_SYNC,
0026     MCDI_STATE_RUNNING_ASYNC,
0027     MCDI_STATE_PROXY_WAIT,
0028     MCDI_STATE_COMPLETED,
0029 };
0030 
0031 /**
0032  * enum efx_mcdi_mode - MCDI transaction mode
0033  * @MCDI_MODE_POLL: poll for MCDI completion, until timeout
0034  * @MCDI_MODE_EVENTS: wait for an mcdi_event.  On timeout, poll once
0035  * @MCDI_MODE_FAIL: we think MCDI is dead, so fail-fast all calls
0036  */
0037 enum efx_mcdi_mode {
0038     MCDI_MODE_POLL,
0039     MCDI_MODE_EVENTS,
0040     MCDI_MODE_FAIL,
0041 };
0042 
0043 /**
0044  * struct efx_mcdi_iface - MCDI protocol context
0045  * @efx: The associated NIC.
0046  * @state: Request handling state. Waited for by @wq.
0047  * @mode: Poll for mcdi completion, or wait for an mcdi_event.
0048  * @wq: Wait queue for threads waiting for @state != %MCDI_STATE_RUNNING
0049  * @new_epoch: Indicates start of day or start of MC reboot recovery
0050  * @iface_lock: Serialises access to @seqno, @credits and response metadata
0051  * @seqno: The next sequence number to use for mcdi requests.
0052  * @credits: Number of spurious MCDI completion events allowed before we
0053  *     trigger a fatal error
0054  * @resprc: Response error/success code (Linux numbering)
0055  * @resp_hdr_len: Response header length
0056  * @resp_data_len: Response data (SDU or error) length
0057  * @async_lock: Serialises access to @async_list while event processing is
0058  *  enabled
0059  * @async_list: Queue of asynchronous requests
0060  * @async_timer: Timer for asynchronous request timeout
0061  * @logging_buffer: buffer that may be used to build MCDI tracing messages
0062  * @logging_enabled: whether to trace MCDI
0063  * @proxy_rx_handle: Most recently received proxy authorisation handle
0064  * @proxy_rx_status: Status of most recent proxy authorisation
0065  * @proxy_rx_wq: Wait queue for updates to proxy_rx_handle
0066  */
0067 struct efx_mcdi_iface {
0068     struct efx_nic *efx;
0069     enum efx_mcdi_state state;
0070     enum efx_mcdi_mode mode;
0071     wait_queue_head_t wq;
0072     spinlock_t iface_lock;
0073     bool new_epoch;
0074     unsigned int credits;
0075     unsigned int seqno;
0076     int resprc;
0077     int resprc_raw;
0078     size_t resp_hdr_len;
0079     size_t resp_data_len;
0080     spinlock_t async_lock;
0081     struct list_head async_list;
0082     struct timer_list async_timer;
0083 #ifdef CONFIG_SFC_SIENA_MCDI_LOGGING
0084     char *logging_buffer;
0085     bool logging_enabled;
0086 #endif
0087     unsigned int proxy_rx_handle;
0088     int proxy_rx_status;
0089     wait_queue_head_t proxy_rx_wq;
0090 };
0091 
0092 struct efx_mcdi_mon {
0093     struct efx_buffer dma_buf;
0094     struct mutex update_lock;
0095     unsigned long last_update;
0096     struct device *device;
0097     struct efx_mcdi_mon_attribute *attrs;
0098     struct attribute_group group;
0099     const struct attribute_group *groups[2];
0100     unsigned int n_attrs;
0101 };
0102 
0103 struct efx_mcdi_mtd_partition {
0104     struct efx_mtd_partition common;
0105     bool updating;
0106     u16 nvram_type;
0107     u16 fw_subtype;
0108 };
0109 
0110 #define to_efx_mcdi_mtd_partition(mtd)              \
0111     container_of(mtd, struct efx_mcdi_mtd_partition, common.mtd)
0112 
0113 /**
0114  * struct efx_mcdi_data - extra state for NICs that implement MCDI
0115  * @iface: Interface/protocol state
0116  * @hwmon: Hardware monitor state
0117  * @fn_flags: Flags for this function, as returned by %MC_CMD_DRV_ATTACH.
0118  */
0119 struct efx_mcdi_data {
0120     struct efx_mcdi_iface iface;
0121 #ifdef CONFIG_SFC_SIENA_MCDI_MON
0122     struct efx_mcdi_mon hwmon;
0123 #endif
0124     u32 fn_flags;
0125 };
0126 
0127 static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx)
0128 {
0129     EFX_WARN_ON_PARANOID(!efx->mcdi);
0130     return &efx->mcdi->iface;
0131 }
0132 
0133 #ifdef CONFIG_SFC_SIENA_MCDI_MON
0134 static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
0135 {
0136     EFX_WARN_ON_PARANOID(!efx->mcdi);
0137     return &efx->mcdi->hwmon;
0138 }
0139 #endif
0140 
0141 int efx_siena_mcdi_init(struct efx_nic *efx);
0142 void efx_siena_mcdi_detach(struct efx_nic *efx);
0143 void efx_siena_mcdi_fini(struct efx_nic *efx);
0144 
0145 int efx_siena_mcdi_rpc(struct efx_nic *efx, unsigned int cmd,
0146                const efx_dword_t *inbuf, size_t inlen,
0147                efx_dword_t *outbuf, size_t outlen,
0148                size_t *outlen_actual);
0149 int efx_siena_mcdi_rpc_quiet(struct efx_nic *efx, unsigned int cmd,
0150                  const efx_dword_t *inbuf, size_t inlen,
0151                  efx_dword_t *outbuf, size_t outlen,
0152                  size_t *outlen_actual);
0153 
0154 int efx_siena_mcdi_rpc_start(struct efx_nic *efx, unsigned int cmd,
0155                  const efx_dword_t *inbuf, size_t inlen);
0156 int efx_siena_mcdi_rpc_finish(struct efx_nic *efx, unsigned int cmd,
0157                   size_t inlen, efx_dword_t *outbuf, size_t outlen,
0158                   size_t *outlen_actual);
0159 int efx_siena_mcdi_rpc_finish_quiet(struct efx_nic *efx, unsigned int cmd,
0160                     size_t inlen, efx_dword_t *outbuf,
0161                     size_t outlen, size_t *outlen_actual);
0162 
0163 typedef void efx_mcdi_async_completer(struct efx_nic *efx,
0164                       unsigned long cookie, int rc,
0165                       efx_dword_t *outbuf,
0166                       size_t outlen_actual);
0167 int efx_siena_mcdi_rpc_async(struct efx_nic *efx, unsigned int cmd,
0168                  const efx_dword_t *inbuf, size_t inlen,
0169                  size_t outlen,
0170                  efx_mcdi_async_completer *complete,
0171                  unsigned long cookie);
0172 int efx_siena_mcdi_rpc_async_quiet(struct efx_nic *efx, unsigned int cmd,
0173                    const efx_dword_t *inbuf, size_t inlen,
0174                    size_t outlen,
0175                    efx_mcdi_async_completer *complete,
0176                    unsigned long cookie);
0177 
0178 void efx_siena_mcdi_display_error(struct efx_nic *efx, unsigned int cmd,
0179                   size_t inlen, efx_dword_t *outbuf,
0180                   size_t outlen, int rc);
0181 
0182 int efx_siena_mcdi_poll_reboot(struct efx_nic *efx);
0183 void efx_siena_mcdi_mode_poll(struct efx_nic *efx);
0184 void efx_siena_mcdi_mode_event(struct efx_nic *efx);
0185 void efx_siena_mcdi_flush_async(struct efx_nic *efx);
0186 
0187 void efx_siena_mcdi_process_event(struct efx_channel *channel, efx_qword_t *event);
0188 void efx_siena_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
0189 
0190 /* We expect that 16- and 32-bit fields in MCDI requests and responses
0191  * are appropriately aligned, but 64-bit fields are only
0192  * 32-bit-aligned.  Also, on Siena we must copy to the MC shared
0193  * memory strictly 32 bits at a time, so add any necessary padding.
0194  */
0195 #define MCDI_TX_BUF_LEN(_len) DIV_ROUND_UP((_len), 4)
0196 #define _MCDI_DECLARE_BUF(_name, _len)                  \
0197     efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
0198 #define MCDI_DECLARE_BUF(_name, _len)                   \
0199     _MCDI_DECLARE_BUF(_name, _len) = {{{0}}}
0200 #define MCDI_DECLARE_BUF_ERR(_name)                 \
0201     MCDI_DECLARE_BUF(_name, 8)
0202 #define _MCDI_PTR(_buf, _offset)                    \
0203     ((u8 *)(_buf) + (_offset))
0204 #define MCDI_PTR(_buf, _field)                      \
0205     _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
0206 #define _MCDI_CHECK_ALIGN(_ofst, _align)                \
0207     ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
0208 #define _MCDI_DWORD(_buf, _field)                   \
0209     ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
0210 
0211 #define MCDI_BYTE(_buf, _field)                     \
0212     ((void)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 1),   \
0213      *MCDI_PTR(_buf, _field))
0214 #define MCDI_WORD(_buf, _field)                     \
0215     ((u16)BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) +   \
0216      le16_to_cpu(*(__force const __le16 *)MCDI_PTR(_buf, _field)))
0217 #define MCDI_SET_DWORD(_buf, _field, _value)                \
0218     EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
0219 #define MCDI_DWORD(_buf, _field)                    \
0220     EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
0221 #define MCDI_POPULATE_DWORD_1(_buf, _field, _name1, _value1)        \
0222     EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field),        \
0223                  MC_CMD_ ## _name1, _value1)
0224 #define MCDI_POPULATE_DWORD_2(_buf, _field, _name1, _value1,        \
0225                   _name2, _value2)              \
0226     EFX_POPULATE_DWORD_2(*_MCDI_DWORD(_buf, _field),        \
0227                  MC_CMD_ ## _name1, _value1,        \
0228                  MC_CMD_ ## _name2, _value2)
0229 #define MCDI_POPULATE_DWORD_3(_buf, _field, _name1, _value1,        \
0230                   _name2, _value2, _name3, _value3)     \
0231     EFX_POPULATE_DWORD_3(*_MCDI_DWORD(_buf, _field),        \
0232                  MC_CMD_ ## _name1, _value1,        \
0233                  MC_CMD_ ## _name2, _value2,        \
0234                  MC_CMD_ ## _name3, _value3)
0235 #define MCDI_POPULATE_DWORD_4(_buf, _field, _name1, _value1,        \
0236                   _name2, _value2, _name3, _value3,     \
0237                   _name4, _value4)              \
0238     EFX_POPULATE_DWORD_4(*_MCDI_DWORD(_buf, _field),        \
0239                  MC_CMD_ ## _name1, _value1,        \
0240                  MC_CMD_ ## _name2, _value2,        \
0241                  MC_CMD_ ## _name3, _value3,        \
0242                  MC_CMD_ ## _name4, _value4)
0243 #define MCDI_POPULATE_DWORD_5(_buf, _field, _name1, _value1,        \
0244                   _name2, _value2, _name3, _value3,     \
0245                   _name4, _value4, _name5, _value5)     \
0246     EFX_POPULATE_DWORD_5(*_MCDI_DWORD(_buf, _field),        \
0247                  MC_CMD_ ## _name1, _value1,        \
0248                  MC_CMD_ ## _name2, _value2,        \
0249                  MC_CMD_ ## _name3, _value3,        \
0250                  MC_CMD_ ## _name4, _value4,        \
0251                  MC_CMD_ ## _name5, _value5)
0252 #define MCDI_POPULATE_DWORD_6(_buf, _field, _name1, _value1,        \
0253                   _name2, _value2, _name3, _value3,     \
0254                   _name4, _value4, _name5, _value5,     \
0255                   _name6, _value6)              \
0256     EFX_POPULATE_DWORD_6(*_MCDI_DWORD(_buf, _field),        \
0257                  MC_CMD_ ## _name1, _value1,        \
0258                  MC_CMD_ ## _name2, _value2,        \
0259                  MC_CMD_ ## _name3, _value3,        \
0260                  MC_CMD_ ## _name4, _value4,        \
0261                  MC_CMD_ ## _name5, _value5,        \
0262                  MC_CMD_ ## _name6, _value6)
0263 #define MCDI_POPULATE_DWORD_7(_buf, _field, _name1, _value1,        \
0264                   _name2, _value2, _name3, _value3,     \
0265                   _name4, _value4, _name5, _value5,     \
0266                   _name6, _value6, _name7, _value7)     \
0267     EFX_POPULATE_DWORD_7(*_MCDI_DWORD(_buf, _field),        \
0268                  MC_CMD_ ## _name1, _value1,        \
0269                  MC_CMD_ ## _name2, _value2,        \
0270                  MC_CMD_ ## _name3, _value3,        \
0271                  MC_CMD_ ## _name4, _value4,        \
0272                  MC_CMD_ ## _name5, _value5,        \
0273                  MC_CMD_ ## _name6, _value6,        \
0274                  MC_CMD_ ## _name7, _value7)
0275 #define MCDI_SET_QWORD(_buf, _field, _value)                \
0276     do {                                \
0277         EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0],  \
0278                      EFX_DWORD_0, (u32)(_value));   \
0279         EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1],  \
0280                      EFX_DWORD_0, (u64)(_value) >> 32); \
0281     } while (0)
0282 #define MCDI_QWORD(_buf, _field)                    \
0283     (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) |   \
0284     (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
0285 #define MCDI_FIELD(_ptr, _type, _field)                 \
0286     EFX_EXTRACT_DWORD(                      \
0287         *(efx_dword_t *)                    \
0288         _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
0289         MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
0290         (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) +  \
0291         MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
0292 
0293 #define _MCDI_ARRAY_PTR(_buf, _field, _index, _align)           \
0294     (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
0295      + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
0296 #define MCDI_DECLARE_STRUCT_PTR(_name)                  \
0297     efx_dword_t *_name
0298 #define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index)         \
0299     ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
0300 #define MCDI_VAR_ARRAY_LEN(_len, _field)                \
0301     min_t(size_t, MC_CMD_ ## _field ## _MAXNUM,         \
0302           ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
0303 #define MCDI_ARRAY_WORD(_buf, _field, _index)               \
0304     (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) +        \
0305      le16_to_cpu(*(__force const __le16 *)              \
0306              _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
0307 #define _MCDI_ARRAY_DWORD(_buf, _field, _index)             \
0308     (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) +        \
0309      (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
0310 #define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value)      \
0311     EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index),   \
0312                 EFX_DWORD_0, _value)
0313 #define MCDI_ARRAY_DWORD(_buf, _field, _index)              \
0314     EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
0315 #define _MCDI_ARRAY_QWORD(_buf, _field, _index)             \
0316     (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) +        \
0317      (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
0318 #define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value)      \
0319     do {                                \
0320         EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
0321                     EFX_DWORD_0, (u32)(_value));    \
0322         EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
0323                     EFX_DWORD_0, (u64)(_value) >> 32);  \
0324     } while (0)
0325 #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2)     \
0326     MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index),    \
0327            _type ## _TYPEDEF, _field2)
0328 
0329 #define MCDI_EVENT_FIELD(_ev, _field)           \
0330     EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
0331 
0332 #define MCDI_CAPABILITY(field)                      \
0333     MC_CMD_GET_CAPABILITIES_V8_OUT_ ## field ## _LBN
0334 
0335 #define MCDI_CAPABILITY_OFST(field) \
0336     MC_CMD_GET_CAPABILITIES_V8_OUT_ ## field ## _OFST
0337 
0338 #define efx_has_cap(efx, field) \
0339     efx->type->check_caps(efx, \
0340                   MCDI_CAPABILITY(field), \
0341                   MCDI_CAPABILITY_OFST(field))
0342 
0343 void efx_siena_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
0344 int efx_siena_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
0345                  u16 *fw_subtype_list, u32 *capabilities);
0346 int efx_siena_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart,
0347                 u32 dest_evq);
0348 int efx_siena_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
0349 int efx_siena_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
0350                   size_t *size_out, size_t *erase_size_out,
0351                   bool *protected_out);
0352 int efx_siena_mcdi_nvram_test_all(struct efx_nic *efx);
0353 int efx_siena_mcdi_handle_assertion(struct efx_nic *efx);
0354 int efx_siena_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
0355 int efx_siena_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac,
0356                     int *id_out);
0357 int efx_siena_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
0358 int efx_siena_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
0359 int efx_siena_mcdi_wol_filter_reset(struct efx_nic *efx);
0360 int efx_siena_mcdi_flush_rxqs(struct efx_nic *efx);
0361 void efx_siena_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
0362 void efx_siena_mcdi_mac_start_stats(struct efx_nic *efx);
0363 void efx_siena_mcdi_mac_stop_stats(struct efx_nic *efx);
0364 void efx_siena_mcdi_mac_pull_stats(struct efx_nic *efx);
0365 enum reset_type efx_siena_mcdi_map_reset_reason(enum reset_type reason);
0366 int efx_siena_mcdi_reset(struct efx_nic *efx, enum reset_type method);
0367 
0368 #ifdef CONFIG_SFC_SIENA_MCDI_MON
0369 int efx_siena_mcdi_mon_probe(struct efx_nic *efx);
0370 void efx_siena_mcdi_mon_remove(struct efx_nic *efx);
0371 #else
0372 static inline int efx_siena_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
0373 static inline void efx_siena_mcdi_mon_remove(struct efx_nic *efx) {}
0374 #endif
0375 
0376 #ifdef CONFIG_SFC_SIENA_MTD
0377 int efx_siena_mcdi_mtd_read(struct mtd_info *mtd, loff_t start, size_t len,
0378                 size_t *retlen, u8 *buffer);
0379 int efx_siena_mcdi_mtd_erase(struct mtd_info *mtd, loff_t start, size_t len);
0380 int efx_siena_mcdi_mtd_write(struct mtd_info *mtd, loff_t start, size_t len,
0381                  size_t *retlen, const u8 *buffer);
0382 int efx_siena_mcdi_mtd_sync(struct mtd_info *mtd);
0383 void efx_siena_mcdi_mtd_rename(struct efx_mtd_partition *part);
0384 #endif
0385 
0386 #endif /* EFX_MCDI_H */