qed_mcp.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #ifndef _QED_MCP_H
  33. #define _QED_MCP_H
  34. #include <linux/types.h>
  35. #include <linux/delay.h>
  36. #include <linux/slab.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/qed/qed_fcoe_if.h>
  39. #include "qed_hsi.h"
  40. #include "qed_dev_api.h"
  41. struct qed_mcp_link_speed_params {
  42. bool autoneg;
  43. u32 advertised_speeds; /* bitmask of DRV_SPEED_CAPABILITY */
  44. u32 forced_speed; /* In Mb/s */
  45. };
  46. struct qed_mcp_link_pause_params {
  47. bool autoneg;
  48. bool forced_rx;
  49. bool forced_tx;
  50. };
  51. enum qed_mcp_eee_mode {
  52. QED_MCP_EEE_DISABLED,
  53. QED_MCP_EEE_ENABLED,
  54. QED_MCP_EEE_UNSUPPORTED
  55. };
  56. struct qed_mcp_link_params {
  57. struct qed_mcp_link_speed_params speed;
  58. struct qed_mcp_link_pause_params pause;
  59. u32 loopback_mode;
  60. struct qed_link_eee_params eee;
  61. };
  62. struct qed_mcp_link_capabilities {
  63. u32 speed_capabilities;
  64. bool default_speed_autoneg;
  65. enum qed_mcp_eee_mode default_eee;
  66. u32 eee_lpi_timer;
  67. u8 eee_speed_caps;
  68. };
  69. struct qed_mcp_link_state {
  70. bool link_up;
  71. u32 min_pf_rate;
  72. /* Actual link speed in Mb/s */
  73. u32 line_speed;
  74. /* PF max speed in Mb/s, deduced from line_speed
  75. * according to PF max bandwidth configuration.
  76. */
  77. u32 speed;
  78. bool full_duplex;
  79. bool an;
  80. bool an_complete;
  81. bool parallel_detection;
  82. bool pfc_enabled;
  83. #define QED_LINK_PARTNER_SPEED_1G_HD BIT(0)
  84. #define QED_LINK_PARTNER_SPEED_1G_FD BIT(1)
  85. #define QED_LINK_PARTNER_SPEED_10G BIT(2)
  86. #define QED_LINK_PARTNER_SPEED_20G BIT(3)
  87. #define QED_LINK_PARTNER_SPEED_25G BIT(4)
  88. #define QED_LINK_PARTNER_SPEED_40G BIT(5)
  89. #define QED_LINK_PARTNER_SPEED_50G BIT(6)
  90. #define QED_LINK_PARTNER_SPEED_100G BIT(7)
  91. u32 partner_adv_speed;
  92. bool partner_tx_flow_ctrl_en;
  93. bool partner_rx_flow_ctrl_en;
  94. #define QED_LINK_PARTNER_SYMMETRIC_PAUSE (1)
  95. #define QED_LINK_PARTNER_ASYMMETRIC_PAUSE (2)
  96. #define QED_LINK_PARTNER_BOTH_PAUSE (3)
  97. u8 partner_adv_pause;
  98. bool sfp_tx_fault;
  99. bool eee_active;
  100. u8 eee_adv_caps;
  101. u8 eee_lp_adv_caps;
  102. };
  103. struct qed_mcp_function_info {
  104. u8 pause_on_host;
  105. enum qed_pci_personality protocol;
  106. u8 bandwidth_min;
  107. u8 bandwidth_max;
  108. u8 mac[ETH_ALEN];
  109. u64 wwn_port;
  110. u64 wwn_node;
  111. #define QED_MCP_VLAN_UNSET (0xffff)
  112. u16 ovlan;
  113. u16 mtu;
  114. };
  115. struct qed_mcp_nvm_common {
  116. u32 offset;
  117. u32 param;
  118. u32 resp;
  119. u32 cmd;
  120. };
  121. struct qed_mcp_drv_version {
  122. u32 version;
  123. u8 name[MCP_DRV_VER_STR_SIZE - 4];
  124. };
  125. struct qed_mcp_lan_stats {
  126. u64 ucast_rx_pkts;
  127. u64 ucast_tx_pkts;
  128. u32 fcs_err;
  129. };
  130. struct qed_mcp_fcoe_stats {
  131. u64 rx_pkts;
  132. u64 tx_pkts;
  133. u32 fcs_err;
  134. u32 login_failure;
  135. };
  136. struct qed_mcp_iscsi_stats {
  137. u64 rx_pdus;
  138. u64 tx_pdus;
  139. u64 rx_bytes;
  140. u64 tx_bytes;
  141. };
  142. struct qed_mcp_rdma_stats {
  143. u64 rx_pkts;
  144. u64 tx_pkts;
  145. u64 rx_bytes;
  146. u64 tx_byts;
  147. };
  148. enum qed_mcp_protocol_type {
  149. QED_MCP_LAN_STATS,
  150. QED_MCP_FCOE_STATS,
  151. QED_MCP_ISCSI_STATS,
  152. QED_MCP_RDMA_STATS
  153. };
  154. union qed_mcp_protocol_stats {
  155. struct qed_mcp_lan_stats lan_stats;
  156. struct qed_mcp_fcoe_stats fcoe_stats;
  157. struct qed_mcp_iscsi_stats iscsi_stats;
  158. struct qed_mcp_rdma_stats rdma_stats;
  159. };
  160. enum qed_ov_eswitch {
  161. QED_OV_ESWITCH_NONE,
  162. QED_OV_ESWITCH_VEB,
  163. QED_OV_ESWITCH_VEPA
  164. };
  165. enum qed_ov_client {
  166. QED_OV_CLIENT_DRV,
  167. QED_OV_CLIENT_USER,
  168. QED_OV_CLIENT_VENDOR_SPEC
  169. };
  170. enum qed_ov_driver_state {
  171. QED_OV_DRIVER_STATE_NOT_LOADED,
  172. QED_OV_DRIVER_STATE_DISABLED,
  173. QED_OV_DRIVER_STATE_ACTIVE
  174. };
  175. enum qed_ov_wol {
  176. QED_OV_WOL_DEFAULT,
  177. QED_OV_WOL_DISABLED,
  178. QED_OV_WOL_ENABLED
  179. };
  180. /**
  181. * @brief - returns the link params of the hw function
  182. *
  183. * @param p_hwfn
  184. *
  185. * @returns pointer to link params
  186. */
  187. struct qed_mcp_link_params *qed_mcp_get_link_params(struct qed_hwfn *);
  188. /**
  189. * @brief - return the link state of the hw function
  190. *
  191. * @param p_hwfn
  192. *
  193. * @returns pointer to link state
  194. */
  195. struct qed_mcp_link_state *qed_mcp_get_link_state(struct qed_hwfn *);
  196. /**
  197. * @brief - return the link capabilities of the hw function
  198. *
  199. * @param p_hwfn
  200. *
  201. * @returns pointer to link capabilities
  202. */
  203. struct qed_mcp_link_capabilities
  204. *qed_mcp_get_link_capabilities(struct qed_hwfn *p_hwfn);
  205. /**
  206. * @brief Request the MFW to set the the link according to 'link_input'.
  207. *
  208. * @param p_hwfn
  209. * @param p_ptt
  210. * @param b_up - raise link if `true'. Reset link if `false'.
  211. *
  212. * @return int
  213. */
  214. int qed_mcp_set_link(struct qed_hwfn *p_hwfn,
  215. struct qed_ptt *p_ptt,
  216. bool b_up);
  217. /**
  218. * @brief Get the management firmware version value
  219. *
  220. * @param p_hwfn
  221. * @param p_ptt
  222. * @param p_mfw_ver - mfw version value
  223. * @param p_running_bundle_id - image id in nvram; Optional.
  224. *
  225. * @return int - 0 - operation was successful.
  226. */
  227. int qed_mcp_get_mfw_ver(struct qed_hwfn *p_hwfn,
  228. struct qed_ptt *p_ptt,
  229. u32 *p_mfw_ver, u32 *p_running_bundle_id);
  230. /**
  231. * @brief Get the MBI version value
  232. *
  233. * @param p_hwfn
  234. * @param p_ptt
  235. * @param p_mbi_ver - A pointer to a variable to be filled with the MBI version.
  236. *
  237. * @return int - 0 - operation was successful.
  238. */
  239. int qed_mcp_get_mbi_ver(struct qed_hwfn *p_hwfn,
  240. struct qed_ptt *p_ptt, u32 *p_mbi_ver);
  241. /**
  242. * @brief Get media type value of the port.
  243. *
  244. * @param cdev - qed dev pointer
  245. * @param mfw_ver - media type value
  246. *
  247. * @return int -
  248. * 0 - Operation was successul.
  249. * -EBUSY - Operation failed
  250. */
  251. int qed_mcp_get_media_type(struct qed_dev *cdev,
  252. u32 *media_type);
  253. /**
  254. * @brief General function for sending commands to the MCP
  255. * mailbox. It acquire mutex lock for the entire
  256. * operation, from sending the request until the MCP
  257. * response. Waiting for MCP response will be checked up
  258. * to 5 seconds every 5ms.
  259. *
  260. * @param p_hwfn - hw function
  261. * @param p_ptt - PTT required for register access
  262. * @param cmd - command to be sent to the MCP.
  263. * @param param - Optional param
  264. * @param o_mcp_resp - The MCP response code (exclude sequence).
  265. * @param o_mcp_param- Optional parameter provided by the MCP
  266. * response
  267. * @return int - 0 - operation
  268. * was successul.
  269. */
  270. int qed_mcp_cmd(struct qed_hwfn *p_hwfn,
  271. struct qed_ptt *p_ptt,
  272. u32 cmd,
  273. u32 param,
  274. u32 *o_mcp_resp,
  275. u32 *o_mcp_param);
  276. /**
  277. * @brief - drains the nig, allowing completion to pass in case of pauses.
  278. * (Should be called only from sleepable context)
  279. *
  280. * @param p_hwfn
  281. * @param p_ptt
  282. */
  283. int qed_mcp_drain(struct qed_hwfn *p_hwfn,
  284. struct qed_ptt *p_ptt);
  285. /**
  286. * @brief Get the flash size value
  287. *
  288. * @param p_hwfn
  289. * @param p_ptt
  290. * @param p_flash_size - flash size in bytes to be filled.
  291. *
  292. * @return int - 0 - operation was successul.
  293. */
  294. int qed_mcp_get_flash_size(struct qed_hwfn *p_hwfn,
  295. struct qed_ptt *p_ptt,
  296. u32 *p_flash_size);
  297. /**
  298. * @brief Send driver version to MFW
  299. *
  300. * @param p_hwfn
  301. * @param p_ptt
  302. * @param version - Version value
  303. * @param name - Protocol driver name
  304. *
  305. * @return int - 0 - operation was successul.
  306. */
  307. int
  308. qed_mcp_send_drv_version(struct qed_hwfn *p_hwfn,
  309. struct qed_ptt *p_ptt,
  310. struct qed_mcp_drv_version *p_ver);
  311. /**
  312. * @brief Notify MFW about the change in base device properties
  313. *
  314. * @param p_hwfn
  315. * @param p_ptt
  316. * @param client - qed client type
  317. *
  318. * @return int - 0 - operation was successful.
  319. */
  320. int qed_mcp_ov_update_current_config(struct qed_hwfn *p_hwfn,
  321. struct qed_ptt *p_ptt,
  322. enum qed_ov_client client);
  323. /**
  324. * @brief Notify MFW about the driver state
  325. *
  326. * @param p_hwfn
  327. * @param p_ptt
  328. * @param drv_state - Driver state
  329. *
  330. * @return int - 0 - operation was successful.
  331. */
  332. int qed_mcp_ov_update_driver_state(struct qed_hwfn *p_hwfn,
  333. struct qed_ptt *p_ptt,
  334. enum qed_ov_driver_state drv_state);
  335. /**
  336. * @brief Send MTU size to MFW
  337. *
  338. * @param p_hwfn
  339. * @param p_ptt
  340. * @param mtu - MTU size
  341. *
  342. * @return int - 0 - operation was successful.
  343. */
  344. int qed_mcp_ov_update_mtu(struct qed_hwfn *p_hwfn,
  345. struct qed_ptt *p_ptt, u16 mtu);
  346. /**
  347. * @brief Send MAC address to MFW
  348. *
  349. * @param p_hwfn
  350. * @param p_ptt
  351. * @param mac - MAC address
  352. *
  353. * @return int - 0 - operation was successful.
  354. */
  355. int qed_mcp_ov_update_mac(struct qed_hwfn *p_hwfn,
  356. struct qed_ptt *p_ptt, u8 *mac);
  357. /**
  358. * @brief Send WOL mode to MFW
  359. *
  360. * @param p_hwfn
  361. * @param p_ptt
  362. * @param wol - WOL mode
  363. *
  364. * @return int - 0 - operation was successful.
  365. */
  366. int qed_mcp_ov_update_wol(struct qed_hwfn *p_hwfn,
  367. struct qed_ptt *p_ptt,
  368. enum qed_ov_wol wol);
  369. /**
  370. * @brief Set LED status
  371. *
  372. * @param p_hwfn
  373. * @param p_ptt
  374. * @param mode - LED mode
  375. *
  376. * @return int - 0 - operation was successful.
  377. */
  378. int qed_mcp_set_led(struct qed_hwfn *p_hwfn,
  379. struct qed_ptt *p_ptt,
  380. enum qed_led_mode mode);
  381. /**
  382. * @brief Read from nvm
  383. *
  384. * @param cdev
  385. * @param addr - nvm offset
  386. * @param p_buf - nvm read buffer
  387. * @param len - buffer len
  388. *
  389. * @return int - 0 - operation was successful.
  390. */
  391. int qed_mcp_nvm_read(struct qed_dev *cdev, u32 addr, u8 *p_buf, u32 len);
  392. /**
  393. * @brief Write to nvm
  394. *
  395. * @param cdev
  396. * @param addr - nvm offset
  397. * @param cmd - nvm command
  398. * @param p_buf - nvm write buffer
  399. * @param len - buffer len
  400. *
  401. * @return int - 0 - operation was successful.
  402. */
  403. int qed_mcp_nvm_write(struct qed_dev *cdev,
  404. u32 cmd, u32 addr, u8 *p_buf, u32 len);
  405. /**
  406. * @brief Put file begin
  407. *
  408. * @param cdev
  409. * @param addr - nvm offset
  410. *
  411. * @return int - 0 - operation was successful.
  412. */
  413. int qed_mcp_nvm_put_file_begin(struct qed_dev *cdev, u32 addr);
  414. /**
  415. * @brief Check latest response
  416. *
  417. * @param cdev
  418. * @param p_buf - nvm write buffer
  419. *
  420. * @return int - 0 - operation was successful.
  421. */
  422. int qed_mcp_nvm_resp(struct qed_dev *cdev, u8 *p_buf);
  423. struct qed_nvm_image_att {
  424. u32 start_addr;
  425. u32 length;
  426. };
  427. /**
  428. * @brief Allows reading a whole nvram image
  429. *
  430. * @param p_hwfn
  431. * @param p_ptt
  432. * @param image_id - image requested for reading
  433. * @param p_buffer - allocated buffer into which to fill data
  434. * @param buffer_len - length of the allocated buffer.
  435. *
  436. * @return 0 iff p_buffer now contains the nvram image.
  437. */
  438. int qed_mcp_get_nvm_image(struct qed_hwfn *p_hwfn,
  439. struct qed_ptt *p_ptt,
  440. enum qed_nvm_images image_id,
  441. u8 *p_buffer, u32 buffer_len);
  442. /**
  443. * @brief Bist register test
  444. *
  445. * @param p_hwfn - hw function
  446. * @param p_ptt - PTT required for register access
  447. *
  448. * @return int - 0 - operation was successful.
  449. */
  450. int qed_mcp_bist_register_test(struct qed_hwfn *p_hwfn,
  451. struct qed_ptt *p_ptt);
  452. /**
  453. * @brief Bist clock test
  454. *
  455. * @param p_hwfn - hw function
  456. * @param p_ptt - PTT required for register access
  457. *
  458. * @return int - 0 - operation was successful.
  459. */
  460. int qed_mcp_bist_clock_test(struct qed_hwfn *p_hwfn,
  461. struct qed_ptt *p_ptt);
  462. /**
  463. * @brief Bist nvm test - get number of images
  464. *
  465. * @param p_hwfn - hw function
  466. * @param p_ptt - PTT required for register access
  467. * @param num_images - number of images if operation was
  468. * successful. 0 if not.
  469. *
  470. * @return int - 0 - operation was successful.
  471. */
  472. int qed_mcp_bist_nvm_get_num_images(struct qed_hwfn *p_hwfn,
  473. struct qed_ptt *p_ptt,
  474. u32 *num_images);
  475. /**
  476. * @brief Bist nvm test - get image attributes by index
  477. *
  478. * @param p_hwfn - hw function
  479. * @param p_ptt - PTT required for register access
  480. * @param p_image_att - Attributes of image
  481. * @param image_index - Index of image to get information for
  482. *
  483. * @return int - 0 - operation was successful.
  484. */
  485. int qed_mcp_bist_nvm_get_image_att(struct qed_hwfn *p_hwfn,
  486. struct qed_ptt *p_ptt,
  487. struct bist_nvm_image_att *p_image_att,
  488. u32 image_index);
  489. /* Using hwfn number (and not pf_num) is required since in CMT mode,
  490. * same pf_num may be used by two different hwfn
  491. * TODO - this shouldn't really be in .h file, but until all fields
  492. * required during hw-init will be placed in their correct place in shmem
  493. * we need it in qed_dev.c [for readin the nvram reflection in shmem].
  494. */
  495. #define MCP_PF_ID_BY_REL(p_hwfn, rel_pfid) (QED_IS_BB((p_hwfn)->cdev) ? \
  496. ((rel_pfid) | \
  497. ((p_hwfn)->abs_pf_id & 1) << 3) : \
  498. rel_pfid)
  499. #define MCP_PF_ID(p_hwfn) MCP_PF_ID_BY_REL(p_hwfn, (p_hwfn)->rel_pf_id)
  500. #define MFW_PORT(_p_hwfn) ((_p_hwfn)->abs_pf_id % \
  501. ((_p_hwfn)->cdev->num_ports_in_engine * \
  502. qed_device_num_engines((_p_hwfn)->cdev)))
  503. struct qed_mcp_info {
  504. /* List for mailbox commands which were sent and wait for a response */
  505. struct list_head cmd_list;
  506. /* Spinlock used for protecting the access to the mailbox commands list
  507. * and the sending of the commands.
  508. */
  509. spinlock_t cmd_lock;
  510. /* Spinlock used for syncing SW link-changes and link-changes
  511. * originating from attention context.
  512. */
  513. spinlock_t link_lock;
  514. bool block_mb_sending;
  515. u32 public_base;
  516. u32 drv_mb_addr;
  517. u32 mfw_mb_addr;
  518. u32 port_addr;
  519. u16 drv_mb_seq;
  520. u16 drv_pulse_seq;
  521. struct qed_mcp_link_params link_input;
  522. struct qed_mcp_link_state link_output;
  523. struct qed_mcp_link_capabilities link_capabilities;
  524. struct qed_mcp_function_info func_info;
  525. u8 *mfw_mb_cur;
  526. u8 *mfw_mb_shadow;
  527. u16 mfw_mb_length;
  528. u32 mcp_hist;
  529. /* Capabilties negotiated with the MFW */
  530. u32 capabilities;
  531. };
  532. struct qed_mcp_mb_params {
  533. u32 cmd;
  534. u32 param;
  535. void *p_data_src;
  536. u8 data_src_size;
  537. void *p_data_dst;
  538. u8 data_dst_size;
  539. u32 mcp_resp;
  540. u32 mcp_param;
  541. };
  542. /**
  543. * @brief Initialize the interface with the MCP
  544. *
  545. * @param p_hwfn - HW func
  546. * @param p_ptt - PTT required for register access
  547. *
  548. * @return int
  549. */
  550. int qed_mcp_cmd_init(struct qed_hwfn *p_hwfn,
  551. struct qed_ptt *p_ptt);
  552. /**
  553. * @brief Initialize the port interface with the MCP
  554. *
  555. * @param p_hwfn
  556. * @param p_ptt
  557. * Can only be called after `num_ports_in_engines' is set
  558. */
  559. void qed_mcp_cmd_port_init(struct qed_hwfn *p_hwfn,
  560. struct qed_ptt *p_ptt);
  561. /**
  562. * @brief Releases resources allocated during the init process.
  563. *
  564. * @param p_hwfn - HW func
  565. * @param p_ptt - PTT required for register access
  566. *
  567. * @return int
  568. */
  569. int qed_mcp_free(struct qed_hwfn *p_hwfn);
  570. /**
  571. * @brief This function is called from the DPC context. After
  572. * pointing PTT to the mfw mb, check for events sent by the MCP
  573. * to the driver and ack them. In case a critical event
  574. * detected, it will be handled here, otherwise the work will be
  575. * queued to a sleepable work-queue.
  576. *
  577. * @param p_hwfn - HW function
  578. * @param p_ptt - PTT required for register access
  579. * @return int - 0 - operation
  580. * was successul.
  581. */
  582. int qed_mcp_handle_events(struct qed_hwfn *p_hwfn,
  583. struct qed_ptt *p_ptt);
  584. enum qed_drv_role {
  585. QED_DRV_ROLE_OS,
  586. QED_DRV_ROLE_KDUMP,
  587. };
  588. struct qed_load_req_params {
  589. /* Input params */
  590. enum qed_drv_role drv_role;
  591. u8 timeout_val;
  592. bool avoid_eng_reset;
  593. enum qed_override_force_load override_force_load;
  594. /* Output params */
  595. u32 load_code;
  596. };
  597. /**
  598. * @brief Sends a LOAD_REQ to the MFW, and in case the operation succeeds,
  599. * returns whether this PF is the first on the engine/port or function.
  600. *
  601. * @param p_hwfn
  602. * @param p_ptt
  603. * @param p_params
  604. *
  605. * @return int - 0 - Operation was successful.
  606. */
  607. int qed_mcp_load_req(struct qed_hwfn *p_hwfn,
  608. struct qed_ptt *p_ptt,
  609. struct qed_load_req_params *p_params);
  610. /**
  611. * @brief Sends a UNLOAD_REQ message to the MFW
  612. *
  613. * @param p_hwfn
  614. * @param p_ptt
  615. *
  616. * @return int - 0 - Operation was successful.
  617. */
  618. int qed_mcp_unload_req(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  619. /**
  620. * @brief Sends a UNLOAD_DONE message to the MFW
  621. *
  622. * @param p_hwfn
  623. * @param p_ptt
  624. *
  625. * @return int - 0 - Operation was successful.
  626. */
  627. int qed_mcp_unload_done(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  628. /**
  629. * @brief Read the MFW mailbox into Current buffer.
  630. *
  631. * @param p_hwfn
  632. * @param p_ptt
  633. */
  634. void qed_mcp_read_mb(struct qed_hwfn *p_hwfn,
  635. struct qed_ptt *p_ptt);
  636. /**
  637. * @brief Ack to mfw that driver finished FLR process for VFs
  638. *
  639. * @param p_hwfn
  640. * @param p_ptt
  641. * @param vfs_to_ack - bit mask of all engine VFs for which the PF acks.
  642. *
  643. * @param return int - 0 upon success.
  644. */
  645. int qed_mcp_ack_vf_flr(struct qed_hwfn *p_hwfn,
  646. struct qed_ptt *p_ptt, u32 *vfs_to_ack);
  647. /**
  648. * @brief - calls during init to read shmem of all function-related info.
  649. *
  650. * @param p_hwfn
  651. *
  652. * @param return 0 upon success.
  653. */
  654. int qed_mcp_fill_shmem_func_info(struct qed_hwfn *p_hwfn,
  655. struct qed_ptt *p_ptt);
  656. /**
  657. * @brief - Reset the MCP using mailbox command.
  658. *
  659. * @param p_hwfn
  660. * @param p_ptt
  661. *
  662. * @param return 0 upon success.
  663. */
  664. int qed_mcp_reset(struct qed_hwfn *p_hwfn,
  665. struct qed_ptt *p_ptt);
  666. /**
  667. * @brief - Sends an NVM read command request to the MFW to get
  668. * a buffer.
  669. *
  670. * @param p_hwfn
  671. * @param p_ptt
  672. * @param cmd - Command: DRV_MSG_CODE_NVM_GET_FILE_DATA or
  673. * DRV_MSG_CODE_NVM_READ_NVRAM commands
  674. * @param param - [0:23] - Offset [24:31] - Size
  675. * @param o_mcp_resp - MCP response
  676. * @param o_mcp_param - MCP response param
  677. * @param o_txn_size - Buffer size output
  678. * @param o_buf - Pointer to the buffer returned by the MFW.
  679. *
  680. * @param return 0 upon success.
  681. */
  682. int qed_mcp_nvm_rd_cmd(struct qed_hwfn *p_hwfn,
  683. struct qed_ptt *p_ptt,
  684. u32 cmd,
  685. u32 param,
  686. u32 *o_mcp_resp,
  687. u32 *o_mcp_param, u32 *o_txn_size, u32 *o_buf);
  688. /**
  689. * @brief indicates whether the MFW objects [under mcp_info] are accessible
  690. *
  691. * @param p_hwfn
  692. *
  693. * @return true iff MFW is running and mcp_info is initialized
  694. */
  695. bool qed_mcp_is_init(struct qed_hwfn *p_hwfn);
  696. /**
  697. * @brief request MFW to configure MSI-X for a VF
  698. *
  699. * @param p_hwfn
  700. * @param p_ptt
  701. * @param vf_id - absolute inside engine
  702. * @param num_sbs - number of entries to request
  703. *
  704. * @return int
  705. */
  706. int qed_mcp_config_vf_msix(struct qed_hwfn *p_hwfn,
  707. struct qed_ptt *p_ptt, u8 vf_id, u8 num);
  708. /**
  709. * @brief - Halt the MCP.
  710. *
  711. * @param p_hwfn
  712. * @param p_ptt
  713. *
  714. * @param return 0 upon success.
  715. */
  716. int qed_mcp_halt(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  717. /**
  718. * @brief - Wake up the MCP.
  719. *
  720. * @param p_hwfn
  721. * @param p_ptt
  722. *
  723. * @param return 0 upon success.
  724. */
  725. int qed_mcp_resume(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  726. int qed_configure_pf_min_bandwidth(struct qed_dev *cdev, u8 min_bw);
  727. int qed_configure_pf_max_bandwidth(struct qed_dev *cdev, u8 max_bw);
  728. int __qed_configure_pf_max_bandwidth(struct qed_hwfn *p_hwfn,
  729. struct qed_ptt *p_ptt,
  730. struct qed_mcp_link_state *p_link,
  731. u8 max_bw);
  732. int __qed_configure_pf_min_bandwidth(struct qed_hwfn *p_hwfn,
  733. struct qed_ptt *p_ptt,
  734. struct qed_mcp_link_state *p_link,
  735. u8 min_bw);
  736. int qed_mcp_mask_parities(struct qed_hwfn *p_hwfn,
  737. struct qed_ptt *p_ptt, u32 mask_parities);
  738. /**
  739. * @brief - Sets the MFW's max value for the given resource
  740. *
  741. * @param p_hwfn
  742. * @param p_ptt
  743. * @param res_id
  744. * @param resc_max_val
  745. * @param p_mcp_resp
  746. *
  747. * @return int - 0 - operation was successful.
  748. */
  749. int
  750. qed_mcp_set_resc_max_val(struct qed_hwfn *p_hwfn,
  751. struct qed_ptt *p_ptt,
  752. enum qed_resources res_id,
  753. u32 resc_max_val, u32 *p_mcp_resp);
  754. /**
  755. * @brief - Gets the MFW allocation info for the given resource
  756. *
  757. * @param p_hwfn
  758. * @param p_ptt
  759. * @param res_id
  760. * @param p_mcp_resp
  761. * @param p_resc_num
  762. * @param p_resc_start
  763. *
  764. * @return int - 0 - operation was successful.
  765. */
  766. int
  767. qed_mcp_get_resc_info(struct qed_hwfn *p_hwfn,
  768. struct qed_ptt *p_ptt,
  769. enum qed_resources res_id,
  770. u32 *p_mcp_resp, u32 *p_resc_num, u32 *p_resc_start);
  771. /**
  772. * @brief Send eswitch mode to MFW
  773. *
  774. * @param p_hwfn
  775. * @param p_ptt
  776. * @param eswitch - eswitch mode
  777. *
  778. * @return int - 0 - operation was successful.
  779. */
  780. int qed_mcp_ov_update_eswitch(struct qed_hwfn *p_hwfn,
  781. struct qed_ptt *p_ptt,
  782. enum qed_ov_eswitch eswitch);
  783. #define QED_MCP_RESC_LOCK_MIN_VAL RESOURCE_DUMP
  784. #define QED_MCP_RESC_LOCK_MAX_VAL 31
  785. enum qed_resc_lock {
  786. QED_RESC_LOCK_DBG_DUMP = QED_MCP_RESC_LOCK_MIN_VAL,
  787. QED_RESC_LOCK_PTP_PORT0,
  788. QED_RESC_LOCK_PTP_PORT1,
  789. QED_RESC_LOCK_PTP_PORT2,
  790. QED_RESC_LOCK_PTP_PORT3,
  791. QED_RESC_LOCK_RESC_ALLOC = QED_MCP_RESC_LOCK_MAX_VAL,
  792. QED_RESC_LOCK_RESC_INVALID
  793. };
  794. /**
  795. * @brief - Initiates PF FLR
  796. *
  797. * @param p_hwfn
  798. * @param p_ptt
  799. *
  800. * @return int - 0 - operation was successful.
  801. */
  802. int qed_mcp_initiate_pf_flr(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  803. struct qed_resc_lock_params {
  804. /* Resource number [valid values are 0..31] */
  805. u8 resource;
  806. /* Lock timeout value in seconds [default, none or 1..254] */
  807. u8 timeout;
  808. #define QED_MCP_RESC_LOCK_TO_DEFAULT 0
  809. #define QED_MCP_RESC_LOCK_TO_NONE 255
  810. /* Number of times to retry locking */
  811. u8 retry_num;
  812. #define QED_MCP_RESC_LOCK_RETRY_CNT_DFLT 10
  813. /* The interval in usec between retries */
  814. u16 retry_interval;
  815. #define QED_MCP_RESC_LOCK_RETRY_VAL_DFLT 10000
  816. /* Use sleep or delay between retries */
  817. bool sleep_b4_retry;
  818. /* Will be set as true if the resource is free and granted */
  819. bool b_granted;
  820. /* Will be filled with the resource owner.
  821. * [0..15 = PF0-15, 16 = MFW]
  822. */
  823. u8 owner;
  824. };
  825. /**
  826. * @brief Acquires MFW generic resource lock
  827. *
  828. * @param p_hwfn
  829. * @param p_ptt
  830. * @param p_params
  831. *
  832. * @return int - 0 - operation was successful.
  833. */
  834. int
  835. qed_mcp_resc_lock(struct qed_hwfn *p_hwfn,
  836. struct qed_ptt *p_ptt, struct qed_resc_lock_params *p_params);
  837. struct qed_resc_unlock_params {
  838. /* Resource number [valid values are 0..31] */
  839. u8 resource;
  840. /* Allow to release a resource even if belongs to another PF */
  841. bool b_force;
  842. /* Will be set as true if the resource is released */
  843. bool b_released;
  844. };
  845. /**
  846. * @brief Releases MFW generic resource lock
  847. *
  848. * @param p_hwfn
  849. * @param p_ptt
  850. * @param p_params
  851. *
  852. * @return int - 0 - operation was successful.
  853. */
  854. int
  855. qed_mcp_resc_unlock(struct qed_hwfn *p_hwfn,
  856. struct qed_ptt *p_ptt,
  857. struct qed_resc_unlock_params *p_params);
  858. /**
  859. * @brief - default initialization for lock/unlock resource structs
  860. *
  861. * @param p_lock - lock params struct to be initialized; Can be NULL
  862. * @param p_unlock - unlock params struct to be initialized; Can be NULL
  863. * @param resource - the requested resource
  864. * @paral b_is_permanent - disable retries & aging when set
  865. */
  866. void qed_mcp_resc_lock_default_init(struct qed_resc_lock_params *p_lock,
  867. struct qed_resc_unlock_params *p_unlock,
  868. enum qed_resc_lock
  869. resource, bool b_is_permanent);
  870. /**
  871. * @brief Learn of supported MFW features; To be done during early init
  872. *
  873. * @param p_hwfn
  874. * @param p_ptt
  875. */
  876. int qed_mcp_get_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  877. /**
  878. * @brief Inform MFW of set of features supported by driver. Should be done
  879. * inside the content of the LOAD_REQ.
  880. *
  881. * @param p_hwfn
  882. * @param p_ptt
  883. */
  884. int qed_mcp_set_capabilities(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt);
  885. /**
  886. * @brief Populate the nvm info shadow in the given hardware function
  887. *
  888. * @param p_hwfn
  889. */
  890. int qed_mcp_nvm_info_populate(struct qed_hwfn *p_hwfn);
  891. #endif