qed_mcp.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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/slab.h>
  13. #include <linux/spinlock.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. /**
  196. * @brief Set LED status
  197. *
  198. * @param p_hwfn
  199. * @param p_ptt
  200. * @param mode - LED mode
  201. *
  202. * @return int - 0 - operation was successful.
  203. */
  204. int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
  205. struct qed_ptt *p_ptt,
  206. enum qed_led_mode mode);
  207. /* Using hwfn number (and not pf_num) is required since in CMT mode,
  208. * same pf_num may be used by two different hwfn
  209. * TODO - this shouldn't really be in .h file, but until all fields
  210. * required during hw-init will be placed in their correct place in shmem
  211. * we need it in qed_dev.c [for readin the nvram reflection in shmem].
  212. */
  213. #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
  214. ((rel_pfid) | \
  215. ((p_hwfn)->abs_pf_id & 1) << 3) : \
  216. rel_pfid)
  217. #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
  218. /* TODO - this is only correct as long as only BB is supported, and
  219. * no port-swapping is implemented; Afterwards we'll need to fix it.
  220. */
  221. #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
  222. ((_p_hwfn)->cdev->num_ports_in_engines * 2))
  223. struct qed_mcp_info {
  224. spinlock_t lock;
  225. bool block_mb_sending;
  226. u32 public_base;
  227. u32 drv_mb_addr;
  228. u32 mfw_mb_addr;
  229. u32 port_addr;
  230. u16 drv_mb_seq;
  231. u16 drv_pulse_seq;
  232. struct qed_mcp_link_params link_input;
  233. struct qed_mcp_link_state link_output;
  234. struct qed_mcp_link_capabilities link_capabilities;
  235. struct qed_mcp_function_info func_info;
  236. u8 *mfw_mb_cur;
  237. u8 *mfw_mb_shadow;
  238. u16 mfw_mb_length;
  239. u16 mcp_hist;
  240. };
  241. struct qed_mcp_mb_params {
  242. u32 cmd;
  243. u32 param;
  244. union drv_union_data *p_data_src;
  245. union drv_union_data *p_data_dst;
  246. u32 mcp_resp;
  247. u32 mcp_param;
  248. };
  249. /**
  250. * @brief Initialize the interface with the MCP
  251. *
  252. * @param p_hwfn - HW func
  253. * @param p_ptt - PTT required for register access
  254. *
  255. * @return int
  256. */
  257. int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
  258. struct qed_ptt *p_ptt);
  259. /**
  260. * @brief Initialize the port interface with the MCP
  261. *
  262. * @param p_hwfn
  263. * @param p_ptt
  264. * Can only be called after `num_ports_in_engines' is set
  265. */
  266. void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
  267. struct qed_ptt *p_ptt);
  268. /**
  269. * @brief Releases resources allocated during the init process.
  270. *
  271. * @param p_hwfn - HW func
  272. * @param p_ptt - PTT required for register access
  273. *
  274. * @return int
  275. */
  276. int qed_mcp_free(struct qed_hwfn *p_hwfn);
  277. /**
  278. * @brief This function is called from the DPC context. After
  279. * pointing PTT to the mfw mb, check for events sent by the MCP
  280. * to the driver and ack them. In case a critical event
  281. * detected, it will be handled here, otherwise the work will be
  282. * queued to a sleepable work-queue.
  283. *
  284. * @param p_hwfn - HW function
  285. * @param p_ptt - PTT required for register access
  286. * @return int - 0 - operation
  287. * was successul.
  288. */
  289. int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
  290. struct qed_ptt *p_ptt);
  291. /**
  292. * @brief Sends a LOAD_REQ to the MFW, and in case operation
  293. * succeed, returns whether this PF is the first on the
  294. * chip/engine/port or function. This function should be
  295. * called when driver is ready to accept MFW events after
  296. * Storms initializations are done.
  297. *
  298. * @param p_hwfn - hw function
  299. * @param p_ptt - PTT required for register access
  300. * @param p_load_code - The MCP response param containing one
  301. * of the following:
  302. * FW_MSG_CODE_DRV_LOAD_ENGINE
  303. * FW_MSG_CODE_DRV_LOAD_PORT
  304. * FW_MSG_CODE_DRV_LOAD_FUNCTION
  305. * @return int -
  306. * 0 - Operation was successul.
  307. * -EBUSY - Operation failed
  308. */
  309. int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
  310. struct qed_ptt *p_ptt,
  311. u32 *p_load_code);
  312. /**
  313. * @brief Read the MFW mailbox into Current buffer.
  314. *
  315. * @param p_hwfn
  316. * @param p_ptt
  317. */
  318. void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
  319. struct qed_ptt *p_ptt);
  320. /**
  321. * @brief - calls during init to read shmem of all function-related info.
  322. *
  323. * @param p_hwfn
  324. *
  325. * @param return 0 upon success.
  326. */
  327. int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
  328. struct qed_ptt *p_ptt);
  329. /**
  330. * @brief - Reset the MCP using mailbox command.
  331. *
  332. * @param p_hwfn
  333. * @param p_ptt
  334. *
  335. * @param return 0 upon success.
  336. */
  337. int qed_mcp_reset(struct qed_hwfn *p_hwfn,
  338. struct qed_ptt *p_ptt);
  339. /**
  340. * @brief indicates whether the MFW objects [under mcp_info] are accessible
  341. *
  342. * @param p_hwfn
  343. *
  344. * @return true iff MFW is running and mcp_info is initialized
  345. */
  346. bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
  347. #endif