mcdi.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2008-2010 Solarflare Communications Inc.
  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. #ifndef EFX_MCDI_H
  10. #define EFX_MCDI_H
  11. /**
  12. * enum efx_mcdi_state
  13. * @MCDI_STATE_QUIESCENT: No pending MCDI requests. If the caller holds the
  14. * mcdi_lock then they are able to move to MCDI_STATE_RUNNING
  15. * @MCDI_STATE_RUNNING: There is an MCDI request pending. Only the thread that
  16. * moved into this state is allowed to move out of it.
  17. * @MCDI_STATE_COMPLETED: An MCDI request has completed, but the owning thread
  18. * has not yet consumed the result. For all other threads, equivalent to
  19. * MCDI_STATE_RUNNING.
  20. */
  21. enum efx_mcdi_state {
  22. MCDI_STATE_QUIESCENT,
  23. MCDI_STATE_RUNNING,
  24. MCDI_STATE_COMPLETED,
  25. };
  26. enum efx_mcdi_mode {
  27. MCDI_MODE_POLL,
  28. MCDI_MODE_EVENTS,
  29. };
  30. /**
  31. * struct efx_mcdi_iface
  32. * @state: Interface state. Waited for by mcdi_wq.
  33. * @wq: Wait queue for threads waiting for state != STATE_RUNNING
  34. * @iface_lock: Protects @credits, @seqno, @resprc, @resplen
  35. * @mode: Poll for mcdi completion, or wait for an mcdi_event.
  36. * Serialised by @lock
  37. * @seqno: The next sequence number to use for mcdi requests.
  38. * Serialised by @lock
  39. * @credits: Number of spurious MCDI completion events allowed before we
  40. * trigger a fatal error. Protected by @lock
  41. * @resprc: Response error/success code (Linux numbering)
  42. * @resp_hdr_len: Response header length
  43. * @resp_data_len: Response data (SDU or error) length
  44. */
  45. struct efx_mcdi_iface {
  46. atomic_t state;
  47. wait_queue_head_t wq;
  48. spinlock_t iface_lock;
  49. enum efx_mcdi_mode mode;
  50. unsigned int credits;
  51. unsigned int seqno;
  52. int resprc;
  53. size_t resp_hdr_len;
  54. size_t resp_data_len;
  55. };
  56. struct efx_mcdi_mon {
  57. struct efx_buffer dma_buf;
  58. struct mutex update_lock;
  59. unsigned long last_update;
  60. struct device *device;
  61. struct efx_mcdi_mon_attribute *attrs;
  62. unsigned int n_attrs;
  63. };
  64. /**
  65. * struct efx_mcdi_data - extra state for NICs that implement MCDI
  66. * @iface: Interface/protocol state
  67. * @hwmon: Hardware monitor state
  68. */
  69. struct efx_mcdi_data {
  70. struct efx_mcdi_iface iface;
  71. #ifdef CONFIG_SFC_MCDI_MON
  72. struct efx_mcdi_mon hwmon;
  73. #endif
  74. };
  75. #ifdef CONFIG_SFC_MCDI_MON
  76. static inline struct efx_mcdi_mon *efx_mcdi_mon(struct efx_nic *efx)
  77. {
  78. EFX_BUG_ON_PARANOID(!efx->mcdi);
  79. return &efx->mcdi->hwmon;
  80. }
  81. #endif
  82. extern int efx_mcdi_init(struct efx_nic *efx);
  83. extern void efx_mcdi_fini(struct efx_nic *efx);
  84. extern int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd,
  85. const efx_dword_t *inbuf, size_t inlen,
  86. efx_dword_t *outbuf, size_t outlen,
  87. size_t *outlen_actual);
  88. extern int efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
  89. const efx_dword_t *inbuf, size_t inlen);
  90. extern int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
  91. efx_dword_t *outbuf, size_t outlen,
  92. size_t *outlen_actual);
  93. extern int efx_mcdi_poll_reboot(struct efx_nic *efx);
  94. extern void efx_mcdi_mode_poll(struct efx_nic *efx);
  95. extern void efx_mcdi_mode_event(struct efx_nic *efx);
  96. extern void efx_mcdi_process_event(struct efx_channel *channel,
  97. efx_qword_t *event);
  98. extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
  99. /* We expect that 16- and 32-bit fields in MCDI requests and responses
  100. * are appropriately aligned, but 64-bit fields are only
  101. * 32-bit-aligned. Also, on Siena we must copy to the MC shared
  102. * memory strictly 32 bits at a time, so add any necessary padding.
  103. */
  104. #define MCDI_DECLARE_BUF(_name, _len) \
  105. efx_dword_t _name[DIV_ROUND_UP(_len, 4)]
  106. #define _MCDI_PTR(_buf, _offset) \
  107. ((u8 *)(_buf) + (_offset))
  108. #define MCDI_PTR(_buf, _field) \
  109. _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
  110. #define _MCDI_CHECK_ALIGN(_ofst, _align) \
  111. ((_ofst) + BUILD_BUG_ON_ZERO((_ofst) & (_align - 1)))
  112. #define _MCDI_DWORD(_buf, _field) \
  113. ((_buf) + (_MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, 4) >> 2))
  114. #define MCDI_SET_DWORD(_buf, _field, _value) \
  115. EFX_POPULATE_DWORD_1(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0, _value)
  116. #define MCDI_DWORD(_buf, _field) \
  117. EFX_DWORD_FIELD(*_MCDI_DWORD(_buf, _field), EFX_DWORD_0)
  118. #define MCDI_SET_QWORD(_buf, _field, _value) \
  119. do { \
  120. EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[0], \
  121. EFX_DWORD_0, (u32)(_value)); \
  122. EFX_POPULATE_DWORD_1(_MCDI_DWORD(_buf, _field)[1], \
  123. EFX_DWORD_0, (u64)(_value) >> 32); \
  124. } while (0)
  125. #define MCDI_QWORD(_buf, _field) \
  126. (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \
  127. (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
  128. #define MCDI_FIELD(_ptr, _type, _field) \
  129. EFX_EXTRACT_DWORD( \
  130. *(efx_dword_t *) \
  131. _MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
  132. MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
  133. (MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \
  134. MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
  135. #define _MCDI_ARRAY_PTR(_buf, _field, _index, _align) \
  136. (_MCDI_PTR(_buf, _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _OFST, _align))\
  137. + (_index) * _MCDI_CHECK_ALIGN(MC_CMD_ ## _field ## _LEN, _align))
  138. #define MCDI_DECLARE_STRUCT_PTR(_name) \
  139. efx_dword_t *_name
  140. #define MCDI_ARRAY_STRUCT_PTR(_buf, _field, _index) \
  141. ((efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
  142. #define MCDI_VAR_ARRAY_LEN(_len, _field) \
  143. min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \
  144. ((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
  145. #define MCDI_ARRAY_WORD(_buf, _field, _index) \
  146. (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
  147. le16_to_cpu(*(__force const __le16 *) \
  148. _MCDI_ARRAY_PTR(_buf, _field, _index, 2)))
  149. #define _MCDI_ARRAY_DWORD(_buf, _field, _index) \
  150. (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \
  151. (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
  152. #define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \
  153. EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \
  154. EFX_DWORD_0, _value)
  155. #define MCDI_ARRAY_DWORD(_buf, _field, _index) \
  156. EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
  157. #define _MCDI_ARRAY_QWORD(_buf, _field, _index) \
  158. (BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 8) + \
  159. (efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index, 4))
  160. #define MCDI_SET_ARRAY_QWORD(_buf, _field, _index, _value) \
  161. do { \
  162. EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[0],\
  163. EFX_DWORD_0, (u32)(_value)); \
  164. EFX_SET_DWORD_FIELD(_MCDI_ARRAY_QWORD(_buf, _field, _index)[1],\
  165. EFX_DWORD_0, (u64)(_value) >> 32); \
  166. } while (0)
  167. #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
  168. MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \
  169. _type ## _TYPEDEF, _field2)
  170. #define MCDI_EVENT_FIELD(_ev, _field) \
  171. EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
  172. extern void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len);
  173. extern int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
  174. bool *was_attached_out);
  175. extern int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
  176. u16 *fw_subtype_list, u32 *capabilities);
  177. extern int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart,
  178. u32 dest_evq);
  179. extern int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out);
  180. extern int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
  181. size_t *size_out, size_t *erase_size_out,
  182. bool *protected_out);
  183. extern int efx_mcdi_nvram_update_start(struct efx_nic *efx,
  184. unsigned int type);
  185. extern int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
  186. loff_t offset, u8 *buffer, size_t length);
  187. extern int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
  188. loff_t offset, const u8 *buffer,
  189. size_t length);
  190. #define EFX_MCDI_NVRAM_LEN_MAX 128
  191. extern int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
  192. loff_t offset, size_t length);
  193. extern int efx_mcdi_nvram_update_finish(struct efx_nic *efx,
  194. unsigned int type);
  195. extern int efx_mcdi_nvram_test_all(struct efx_nic *efx);
  196. extern int efx_mcdi_handle_assertion(struct efx_nic *efx);
  197. extern void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode);
  198. extern int efx_mcdi_wol_filter_set_magic(struct efx_nic *efx,
  199. const u8 *mac, int *id_out);
  200. extern int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out);
  201. extern int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id);
  202. extern int efx_mcdi_wol_filter_reset(struct efx_nic *efx);
  203. extern int efx_mcdi_flush_rxqs(struct efx_nic *efx);
  204. extern int efx_mcdi_port_probe(struct efx_nic *efx);
  205. extern void efx_mcdi_port_remove(struct efx_nic *efx);
  206. extern int efx_mcdi_port_reconfigure(struct efx_nic *efx);
  207. extern void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev);
  208. extern int efx_mcdi_set_mac(struct efx_nic *efx);
  209. #define EFX_MC_STATS_GENERATION_INVALID ((__force __le64)(-1))
  210. extern void efx_mcdi_mac_start_stats(struct efx_nic *efx);
  211. extern void efx_mcdi_mac_stop_stats(struct efx_nic *efx);
  212. extern bool efx_mcdi_mac_check_fault(struct efx_nic *efx);
  213. extern enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason);
  214. extern int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method);
  215. #ifdef CONFIG_SFC_MCDI_MON
  216. extern int efx_mcdi_mon_probe(struct efx_nic *efx);
  217. extern void efx_mcdi_mon_remove(struct efx_nic *efx);
  218. #else
  219. static inline int efx_mcdi_mon_probe(struct efx_nic *efx) { return 0; }
  220. static inline void efx_mcdi_mon_remove(struct efx_nic *efx) {}
  221. #endif
  222. #endif /* EFX_MCDI_H */