mcdi.h 15 KB

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