mcdi.h 15 KB

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