qed_mcp.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 min_pf_rate;
  36. /* Actual link speed in Mb/s */
  37. u32 line_speed;
  38. /* PF max speed in Mb/s, deduced from line_speed
  39. * according to PF max bandwidth configuration.
  40. */
  41. u32 speed;
  42. bool full_duplex;
  43. bool an;
  44. bool an_complete;
  45. bool parallel_detection;
  46. bool pfc_enabled;
  47. #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
  48. #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
  49. #define QED_LINK_PARTNER_SPEED_10G BIT(2)
  50. #define QED_LINK_PARTNER_SPEED_20G BIT(3)
  51. #define QED_LINK_PARTNER_SPEED_25G BIT(4)
  52. #define QED_LINK_PARTNER_SPEED_40G BIT(5)
  53. #define QED_LINK_PARTNER_SPEED_50G BIT(6)
  54. #define QED_LINK_PARTNER_SPEED_100G BIT(7)
  55. u32 partner_adv_speed;
  56. bool partner_tx_flow_ctrl_en;
  57. bool partner_rx_flow_ctrl_en;
  58. #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
  59. #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
  60. #define QED_LINK_PARTNER_BOTH_PAUSE (3)
  61. u8 partner_adv_pause;
  62. bool sfp_tx_fault;
  63. };
  64. struct qed_mcp_function_info {
  65. u8 pause_on_host;
  66. enum qed_pci_personality protocol;
  67. u8 bandwidth_min;
  68. u8 bandwidth_max;
  69. u8 mac[ETH_ALEN];
  70. u64 wwn_port;
  71. u64 wwn_node;
  72. #define QED_MCP_VLAN_UNSET (0xffff)
  73. u16 ovlan;
  74. };
  75. struct qed_mcp_nvm_common {
  76. u32 offset;
  77. u32 param;
  78. u32 resp;
  79. u32 cmd;
  80. };
  81. struct qed_mcp_drv_version {
  82. u32 version;
  83. u8 name[MCP_DRV_VER_STR_SIZE - 4];
  84. };
  85. struct qed_mcp_lan_stats {
  86. u64 ucast_rx_pkts;
  87. u64 ucast_tx_pkts;
  88. u32 fcs_err;
  89. };
  90. struct qed_mcp_fcoe_stats {
  91. u64 rx_pkts;
  92. u64 tx_pkts;
  93. u32 fcs_err;
  94. u32 login_failure;
  95. };
  96. struct qed_mcp_iscsi_stats {
  97. u64 rx_pdus;
  98. u64 tx_pdus;
  99. u64 rx_bytes;
  100. u64 tx_bytes;
  101. };
  102. struct qed_mcp_rdma_stats {
  103. u64 rx_pkts;
  104. u64 tx_pkts;
  105. u64 rx_bytes;
  106. u64 tx_byts;
  107. };
  108. enum qed_mcp_protocol_type {
  109. QED_MCP_LAN_STATS,
  110. QED_MCP_FCOE_STATS,
  111. QED_MCP_ISCSI_STATS,
  112. QED_MCP_RDMA_STATS
  113. };
  114. union qed_mcp_protocol_stats {
  115. struct qed_mcp_lan_stats lan_stats;
  116. struct qed_mcp_fcoe_stats fcoe_stats;
  117. struct qed_mcp_iscsi_stats iscsi_stats;
  118. struct qed_mcp_rdma_stats rdma_stats;
  119. };
  120. /**
  121. * @brief - returns the link params of the hw function
  122. *
  123. * @param p_hwfn
  124. *
  125. * @returns pointer to link params
  126. */
  127. struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
  128. /**
  129. * @brief - return the link state of the hw function
  130. *
  131. * @param p_hwfn
  132. *
  133. * @returns pointer to link state
  134. */
  135. struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
  136. /**
  137. * @brief - return the link capabilities of the hw function
  138. *
  139. * @param p_hwfn
  140. *
  141. * @returns pointer to link capabilities
  142. */
  143. struct qed_mcp_link_capabilities
  144. *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
  145. /**
  146. * @brief Request the MFW to set the the link according to 'link_input'.
  147. *
  148. * @param p_hwfn
  149. * @param p_ptt
  150. * @param b_up - raise link if `true'. Reset link if `false'.
  151. *
  152. * @return int
  153. */
  154. int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
  155. struct qed_ptt *p_ptt,
  156. bool b_up);
  157. /**
  158. * @brief Get the management firmware version value
  159. *
  160. * @param p_hwfn
  161. * @param p_ptt
  162. * @param p_mfw_ver - mfw version value
  163. * @param p_running_bundle_id - image id in nvram; Optional.
  164. *
  165. * @return int - 0 - operation was successful.
  166. */
  167. int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
  168. struct qed_ptt *p_ptt,
  169. u32 *p_mfw_ver, u32 *p_running_bundle_id);
  170. /**
  171. * @brief Get media type value of the port.
  172. *
  173. * @param cdev - qed dev pointer
  174. * @param mfw_ver - media type value
  175. *
  176. * @return int -
  177. * 0 - Operation was successul.
  178. * -EBUSY - Operation failed
  179. */
  180. int qed_mcp_get_media_type(struct qed_dev *cdev,
  181. u32 *media_type);
  182. /**
  183. * @brief General function for sending commands to the MCP
  184. * mailbox. It acquire mutex lock for the entire
  185. * operation, from sending the request until the MCP
  186. * response. Waiting for MCP response will be checked up
  187. * to 5 seconds every 5ms.
  188. *
  189. * @param p_hwfn - hw function
  190. * @param p_ptt - PTT required for register access
  191. * @param cmd - command to be sent to the MCP.
  192. * @param param - Optional param
  193. * @param o_mcp_resp - The MCP response code (exclude sequence).
  194. * @param o_mcp_param- Optional parameter provided by the MCP
  195. * response
  196. * @return int - 0 - operation
  197. * was successul.
  198. */
  199. int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
  200. struct qed_ptt *p_ptt,
  201. u32 cmd,
  202. u32 param,
  203. u32 *o_mcp_resp,
  204. u32 *o_mcp_param);
  205. /**
  206. * @brief - drains the nig, allowing completion to pass in case of pauses.
  207. * (Should be called only from sleepable context)
  208. *
  209. * @param p_hwfn
  210. * @param p_ptt
  211. */
  212. int qed_mcp_drain(struct qed_hwfn *p_hwfn,
  213. struct qed_ptt *p_ptt);
  214. /**
  215. * @brief Get the flash size value
  216. *
  217. * @param p_hwfn
  218. * @param p_ptt
  219. * @param p_flash_size - flash size in bytes to be filled.
  220. *
  221. * @return int - 0 - operation was successul.
  222. */
  223. int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
  224. struct qed_ptt *p_ptt,
  225. u32 *p_flash_size);
  226. /**
  227. * @brief Send driver version to MFW
  228. *
  229. * @param p_hwfn
  230. * @param p_ptt
  231. * @param version - Version value
  232. * @param name - Protocol driver name
  233. *
  234. * @return int - 0 - operation was successul.
  235. */
  236. int
  237. qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
  238. struct qed_ptt *p_ptt,
  239. struct qed_mcp_drv_version *p_ver);
  240. /**
  241. * @brief Set LED status
  242. *
  243. * @param p_hwfn
  244. * @param p_ptt
  245. * @param mode - LED mode
  246. *
  247. * @return int - 0 - operation was successful.
  248. */
  249. int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
  250. struct qed_ptt *p_ptt,
  251. enum qed_led_mode mode);
  252. /**
  253. * @brief Bist register test
  254. *
  255. * @param p_hwfn - hw function
  256. * @param p_ptt - PTT required for register access
  257. *
  258. * @return int - 0 - operation was successful.
  259. */
  260. int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
  261. struct qed_ptt *p_ptt);
  262. /**
  263. * @brief Bist clock test
  264. *
  265. * @param p_hwfn - hw function
  266. * @param p_ptt - PTT required for register access
  267. *
  268. * @return int - 0 - operation was successful.
  269. */
  270. int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
  271. struct qed_ptt *p_ptt);
  272. /* Using hwfn number (and not pf_num) is required since in CMT mode,
  273. * same pf_num may be used by two different hwfn
  274. * TODO - this shouldn't really be in .h file, but until all fields
  275. * required during hw-init will be placed in their correct place in shmem
  276. * we need it in qed_dev.c [for readin the nvram reflection in shmem].
  277. */
  278. #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
  279. ((rel_pfid) | \
  280. ((p_hwfn)->abs_pf_id & 1) << 3) : \
  281. rel_pfid)
  282. #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
  283. /* TODO - this is only correct as long as only BB is supported, and
  284. * no port-swapping is implemented; Afterwards we'll need to fix it.
  285. */
  286. #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
  287. ((_p_hwfn)->cdev->num_ports_in_engines * 2))
  288. struct qed_mcp_info {
  289. spinlock_t lock;
  290. bool block_mb_sending;
  291. u32 public_base;
  292. u32 drv_mb_addr;
  293. u32 mfw_mb_addr;
  294. u32 port_addr;
  295. u16 drv_mb_seq;
  296. u16 drv_pulse_seq;
  297. struct qed_mcp_link_params link_input;
  298. struct qed_mcp_link_state link_output;
  299. struct qed_mcp_link_capabilities link_capabilities;
  300. struct qed_mcp_function_info func_info;
  301. u8 *mfw_mb_cur;
  302. u8 *mfw_mb_shadow;
  303. u16 mfw_mb_length;
  304. u16 mcp_hist;
  305. };
  306. struct qed_mcp_mb_params {
  307. u32 cmd;
  308. u32 param;
  309. union drv_union_data *p_data_src;
  310. union drv_union_data *p_data_dst;
  311. u32 mcp_resp;
  312. u32 mcp_param;
  313. };
  314. /**
  315. * @brief Initialize the interface with the MCP
  316. *
  317. * @param p_hwfn - HW func
  318. * @param p_ptt - PTT required for register access
  319. *
  320. * @return int
  321. */
  322. int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
  323. struct qed_ptt *p_ptt);
  324. /**
  325. * @brief Initialize the port interface with the MCP
  326. *
  327. * @param p_hwfn
  328. * @param p_ptt
  329. * Can only be called after `num_ports_in_engines' is set
  330. */
  331. void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
  332. struct qed_ptt *p_ptt);
  333. /**
  334. * @brief Releases resources allocated during the init process.
  335. *
  336. * @param p_hwfn - HW func
  337. * @param p_ptt - PTT required for register access
  338. *
  339. * @return int
  340. */
  341. int qed_mcp_free(struct qed_hwfn *p_hwfn);
  342. /**
  343. * @brief This function is called from the DPC context. After
  344. * pointing PTT to the mfw mb, check for events sent by the MCP
  345. * to the driver and ack them. In case a critical event
  346. * detected, it will be handled here, otherwise the work will be
  347. * queued to a sleepable work-queue.
  348. *
  349. * @param p_hwfn - HW function
  350. * @param p_ptt - PTT required for register access
  351. * @return int - 0 - operation
  352. * was successul.
  353. */
  354. int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
  355. struct qed_ptt *p_ptt);
  356. /**
  357. * @brief Sends a LOAD_REQ to the MFW, and in case operation
  358. * succeed, returns whether this PF is the first on the
  359. * chip/engine/port or function. This function should be
  360. * called when driver is ready to accept MFW events after
  361. * Storms initializations are done.
  362. *
  363. * @param p_hwfn - hw function
  364. * @param p_ptt - PTT required for register access
  365. * @param p_load_code - The MCP response param containing one
  366. * of the following:
  367. * FW_MSG_CODE_DRV_LOAD_ENGINE
  368. * FW_MSG_CODE_DRV_LOAD_PORT
  369. * FW_MSG_CODE_DRV_LOAD_FUNCTION
  370. * @return int -
  371. * 0 - Operation was successul.
  372. * -EBUSY - Operation failed
  373. */
  374. int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
  375. struct qed_ptt *p_ptt,
  376. u32 *p_load_code);
  377. /**
  378. * @brief Read the MFW mailbox into Current buffer.
  379. *
  380. * @param p_hwfn
  381. * @param p_ptt
  382. */
  383. void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
  384. struct qed_ptt *p_ptt);
  385. /**
  386. * @brief Ack to mfw that driver finished FLR process for VFs
  387. *
  388. * @param p_hwfn
  389. * @param p_ptt
  390. * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
  391. *
  392. * @param return int - 0 upon success.
  393. */
  394. int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
  395. struct qed_ptt *p_ptt, u32 *vfs_to_ack);
  396. /**
  397. * @brief - calls during init to read shmem of all function-related info.
  398. *
  399. * @param p_hwfn
  400. *
  401. * @param return 0 upon success.
  402. */
  403. int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
  404. struct qed_ptt *p_ptt);
  405. /**
  406. * @brief - Reset the MCP using mailbox command.
  407. *
  408. * @param p_hwfn
  409. * @param p_ptt
  410. *
  411. * @param return 0 upon success.
  412. */
  413. int qed_mcp_reset(struct qed_hwfn *p_hwfn,
  414. struct qed_ptt *p_ptt);
  415. /**
  416. * @brief - Sends an NVM read command request to the MFW to get
  417. * a buffer.
  418. *
  419. * @param p_hwfn
  420. * @param p_ptt
  421. * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
  422. * DRV_MSG_CODE_NVM_READ_NVRAM commands
  423. * @param param - [0:23] - Offset [24:31] - Size
  424. * @param o_mcp_resp - MCP response
  425. * @param o_mcp_param - MCP response param
  426. * @param o_txn_size - Buffer size output
  427. * @param o_buf - Pointer to the buffer returned by the MFW.
  428. *
  429. * @param return 0 upon success.
  430. */
  431. int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
  432. struct qed_ptt *p_ptt,
  433. u32 cmd,
  434. u32 param,
  435. u32 *o_mcp_resp,
  436. u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
  437. /**
  438. * @brief indicates whether the MFW objects [under mcp_info] are accessible
  439. *
  440. * @param p_hwfn
  441. *
  442. * @return true iff MFW is running and mcp_info is initialized
  443. */
  444. bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
  445. /**
  446. * @brief request MFW to configure MSI-X for a VF
  447. *
  448. * @param p_hwfn
  449. * @param p_ptt
  450. * @param vf_id - absolute inside engine
  451. * @param num_sbs - number of entries to request
  452. *
  453. * @return int
  454. */
  455. int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
  456. struct qed_ptt *p_ptt, u8 vf_id, u8 num);
  457. /**
  458. * @brief - Halt the MCP.
  459. *
  460. * @param p_hwfn
  461. * @param p_ptt
  462. *
  463. * @param return 0 upon success.
  464. */
  465. int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  466. /**
  467. * @brief - Wake up the MCP.
  468. *
  469. * @param p_hwfn
  470. * @param p_ptt
  471. *
  472. * @param return 0 upon success.
  473. */
  474. int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  475. int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
  476. int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
  477. int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
  478. struct qed_ptt *p_ptt,
  479. struct qed_mcp_link_state *p_link,
  480. u8 max_bw);
  481. int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
  482. struct qed_ptt *p_ptt,
  483. struct qed_mcp_link_state *p_link,
  484. u8 min_bw);
  485. int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
  486. struct qed_ptt *p_ptt, u32 mask_parities);
  487. #endif