qed_mcp.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015 QLogic Corporation
  3. *
  4. * This software is available under the terms of the GNU General Public License
  5. * (GPL) Version 2, available from the file COPYING in the main directory of
  6. * this source tree.
  7. */
  8. #ifndef _QED_MCP_H
  9. #define _QED_MCP_H
  10. #include <linux/types.h>
  11. #include <linux/delay.h>
  12. #include <linux/mutex.h>
  13. #include <linux/slab.h>
  14. #include "qed_hsi.h"
  15. struct qed_mcp_link_speed_params {
  16. bool autoneg;
  17. u32 advertised_speeds; /* bitmask of DRV_SPEED_CAPABILITY */
  18. u32 forced_speed; /* In Mb/s */
  19. };
  20. struct qed_mcp_link_pause_params {
  21. bool autoneg;
  22. bool forced_rx;
  23. bool forced_tx;
  24. };
  25. struct qed_mcp_link_params {
  26. struct qed_mcp_link_speed_params speed;
  27. struct qed_mcp_link_pause_params pause;
  28. u32 loopback_mode;
  29. };
  30. struct qed_mcp_link_capabilities {
  31. u32 speed_capabilities;
  32. };
  33. struct qed_mcp_link_state {
  34. bool link_up;
  35. u32 speed; /* In Mb/s */
  36. bool full_duplex;
  37. bool an;
  38. bool an_complete;
  39. bool parallel_detection;
  40. bool pfc_enabled;
  41. #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
  42. #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
  43. #define QED_LINK_PARTNER_SPEED_10G BIT(2)
  44. #define QED_LINK_PARTNER_SPEED_20G BIT(3)
  45. #define QED_LINK_PARTNER_SPEED_40G BIT(4)
  46. #define QED_LINK_PARTNER_SPEED_50G BIT(5)
  47. #define QED_LINK_PARTNER_SPEED_100G BIT(6)
  48. u32 partner_adv_speed;
  49. bool partner_tx_flow_ctrl_en;
  50. bool partner_rx_flow_ctrl_en;
  51. #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
  52. #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
  53. #define QED_LINK_PARTNER_BOTH_PAUSE (3)
  54. u8 partner_adv_pause;
  55. bool sfp_tx_fault;
  56. };
  57. struct qed_mcp_function_info {
  58. u8 pause_on_host;
  59. enum qed_pci_personality protocol;
  60. u8 bandwidth_min;
  61. u8 bandwidth_max;
  62. u8 mac[ETH_ALEN];
  63. u64 wwn_port;
  64. u64 wwn_node;
  65. #define QED_MCP_VLAN_UNSET (0xffff)
  66. u16 ovlan;
  67. };
  68. struct qed_mcp_nvm_common {
  69. u32 offset;
  70. u32 param;
  71. u32 resp;
  72. u32 cmd;
  73. };
  74. struct qed_mcp_drv_version {
  75. u32 version;
  76. u8 name[MCP_DRV_VER_STR_SIZE - 4];
  77. };
  78. /**
  79. * @brief - returns the link params of the hw function
  80. *
  81. * @param p_hwfn
  82. *
  83. * @returns pointer to link params
  84. */
  85. struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
  86. /**
  87. * @brief - return the link state of the hw function
  88. *
  89. * @param p_hwfn
  90. *
  91. * @returns pointer to link state
  92. */
  93. struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
  94. /**
  95. * @brief - return the link capabilities of the hw function
  96. *
  97. * @param p_hwfn
  98. *
  99. * @returns pointer to link capabilities
  100. */
  101. struct qed_mcp_link_capabilities
  102. *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
  103. /**
  104. * @brief Request the MFW to set the the link according to 'link_input'.
  105. *
  106. * @param p_hwfn
  107. * @param p_ptt
  108. * @param b_up - raise link if `true'. Reset link if `false'.
  109. *
  110. * @return int
  111. */
  112. int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
  113. struct qed_ptt *p_ptt,
  114. bool b_up);
  115. /**
  116. * @brief Get the management firmware version value
  117. *
  118. * @param cdev - qed dev pointer
  119. * @param mfw_ver - mfw version value
  120. *
  121. * @return int - 0 - operation was successul.
  122. */
  123. int qed_mcp_get_mfw_ver(struct qed_dev *cdev,
  124. u32 *mfw_ver);
  125. /**
  126. * @brief Get media type value of the port.
  127. *
  128. * @param cdev - qed dev pointer
  129. * @param mfw_ver - media type value
  130. *
  131. * @return int -
  132. * 0 - Operation was successul.
  133. * -EBUSY - Operation failed
  134. */
  135. int qed_mcp_get_media_type(struct qed_dev *cdev,
  136. u32 *media_type);
  137. /**
  138. * @brief General function for sending commands to the MCP
  139. * mailbox. It acquire mutex lock for the entire
  140. * operation, from sending the request until the MCP
  141. * response. Waiting for MCP response will be checked up
  142. * to 5 seconds every 5ms.
  143. *
  144. * @param p_hwfn - hw function
  145. * @param p_ptt - PTT required for register access
  146. * @param cmd - command to be sent to the MCP.
  147. * @param param - Optional param
  148. * @param o_mcp_resp - The MCP response code (exclude sequence).
  149. * @param o_mcp_param- Optional parameter provided by the MCP
  150. * response
  151. * @return int - 0 - operation
  152. * was successul.
  153. */
  154. int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
  155. struct qed_ptt *p_ptt,
  156. u32 cmd,
  157. u32 param,
  158. u32 *o_mcp_resp,
  159. u32 *o_mcp_param);
  160. /**
  161. * @brief - drains the nig, allowing completion to pass in case of pauses.
  162. * (Should be called only from sleepable context)
  163. *
  164. * @param p_hwfn
  165. * @param p_ptt
  166. */
  167. int qed_mcp_drain(struct qed_hwfn *p_hwfn,
  168. struct qed_ptt *p_ptt);
  169. /**
  170. * @brief Get the flash size value
  171. *
  172. * @param p_hwfn
  173. * @param p_ptt
  174. * @param p_flash_size - flash size in bytes to be filled.
  175. *
  176. * @return int - 0 - operation was successul.
  177. */
  178. int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
  179. struct qed_ptt *p_ptt,
  180. u32 *p_flash_size);
  181. /**
  182. * @brief Send driver version to MFW
  183. *
  184. * @param p_hwfn
  185. * @param p_ptt
  186. * @param version - Version value
  187. * @param name - Protocol driver name
  188. *
  189. * @return int - 0 - operation was successul.
  190. */
  191. int
  192. qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
  193. struct qed_ptt *p_ptt,
  194. struct qed_mcp_drv_version *p_ver);
  195. /* Using hwfn number (and not pf_num) is required since in CMT mode,
  196. * same pf_num may be used by two different hwfn
  197. * TODO - this shouldn't really be in .h file, but until all fields
  198. * required during hw-init will be placed in their correct place in shmem
  199. * we need it in qed_dev.c [for readin the nvram reflection in shmem].
  200. */
  201. #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
  202. ((rel_pfid) | \
  203. ((p_hwfn)->abs_pf_id & 1) << 3) : \
  204. rel_pfid)
  205. #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
  206. /* TODO - this is only correct as long as only BB is supported, and
  207. * no port-swapping is implemented; Afterwards we'll need to fix it.
  208. */
  209. #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
  210. ((_p_hwfn)->cdev->num_ports_in_engines * 2))
  211. struct qed_mcp_info {
  212. struct mutex mutex; /* MCP access lock */
  213. u32 public_base;
  214. u32 drv_mb_addr;
  215. u32 mfw_mb_addr;
  216. u32 port_addr;
  217. u16 drv_mb_seq;
  218. u16 drv_pulse_seq;
  219. struct qed_mcp_link_params link_input;
  220. struct qed_mcp_link_state link_output;
  221. struct qed_mcp_link_capabilities link_capabilities;
  222. struct qed_mcp_function_info func_info;
  223. u8 *mfw_mb_cur;
  224. u8 *mfw_mb_shadow;
  225. u16 mfw_mb_length;
  226. u16 mcp_hist;
  227. };
  228. /**
  229. * @brief Initialize the interface with the MCP
  230. *
  231. * @param p_hwfn - HW func
  232. * @param p_ptt - PTT required for register access
  233. *
  234. * @return int
  235. */
  236. int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
  237. struct qed_ptt *p_ptt);
  238. /**
  239. * @brief Initialize the port interface with the MCP
  240. *
  241. * @param p_hwfn
  242. * @param p_ptt
  243. * Can only be called after `num_ports_in_engines' is set
  244. */
  245. void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
  246. struct qed_ptt *p_ptt);
  247. /**
  248. * @brief Releases resources allocated during the init process.
  249. *
  250. * @param p_hwfn - HW func
  251. * @param p_ptt - PTT required for register access
  252. *
  253. * @return int
  254. */
  255. int qed_mcp_free(struct qed_hwfn *p_hwfn);
  256. /**
  257. * @brief This function is called from the DPC context. After
  258. * pointing PTT to the mfw mb, check for events sent by the MCP
  259. * to the driver and ack them. In case a critical event
  260. * detected, it will be handled here, otherwise the work will be
  261. * queued to a sleepable work-queue.
  262. *
  263. * @param p_hwfn - HW function
  264. * @param p_ptt - PTT required for register access
  265. * @return int - 0 - operation
  266. * was successul.
  267. */
  268. int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
  269. struct qed_ptt *p_ptt);
  270. /**
  271. * @brief Sends a LOAD_REQ to the MFW, and in case operation
  272. * succeed, returns whether this PF is the first on the
  273. * chip/engine/port or function. This function should be
  274. * called when driver is ready to accept MFW events after
  275. * Storms initializations are done.
  276. *
  277. * @param p_hwfn - hw function
  278. * @param p_ptt - PTT required for register access
  279. * @param p_load_code - The MCP response param containing one
  280. * of the following:
  281. * FW_MSG_CODE_DRV_LOAD_ENGINE
  282. * FW_MSG_CODE_DRV_LOAD_PORT
  283. * FW_MSG_CODE_DRV_LOAD_FUNCTION
  284. * @return int -
  285. * 0 - Operation was successul.
  286. * -EBUSY - Operation failed
  287. */
  288. int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
  289. struct qed_ptt *p_ptt,
  290. u32 *p_load_code);
  291. /**
  292. * @brief Read the MFW mailbox into Current buffer.
  293. *
  294. * @param p_hwfn
  295. * @param p_ptt
  296. */
  297. void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
  298. struct qed_ptt *p_ptt);
  299. /**
  300. * @brief - calls during init to read shmem of all function-related info.
  301. *
  302. * @param p_hwfn
  303. *
  304. * @param return 0 upon success.
  305. */
  306. int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
  307. struct qed_ptt *p_ptt);
  308. /**
  309. * @brief - Reset the MCP using mailbox command.
  310. *
  311. * @param p_hwfn
  312. * @param p_ptt
  313. *
  314. * @param return 0 upon success.
  315. */
  316. int qed_mcp_reset(struct qed_hwfn *p_hwfn,
  317. struct qed_ptt *p_ptt);
  318. /**
  319. * @brief indicates whether the MFW objects [under mcp_info] are accessible
  320. *
  321. * @param p_hwfn
  322. *
  323. * @return true iff MFW is running and mcp_info is initialized
  324. */
  325. bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
  326. #endif