qed_hw.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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_HW_H
  33. #define _QED_HW_H
  34. #include <linux/types.h>
  35. #include <linux/bitops.h>
  36. #include <linux/slab.h>
  37. #include <linux/string.h>
  38. #include "qed.h"
  39. #include "qed_dev_api.h"
  40. /* Forward decleration */
  41. struct qed_ptt;
  42. enum reserved_ptts {
  43. RESERVED_PTT_EDIAG,
  44. RESERVED_PTT_USER_SPACE,
  45. RESERVED_PTT_MAIN,
  46. RESERVED_PTT_DPC,
  47. RESERVED_PTT_MAX
  48. };
  49. enum _dmae_cmd_dst_mask {
  50. DMAE_CMD_DST_MASK_NONE = 0,
  51. DMAE_CMD_DST_MASK_PCIE = 1,
  52. DMAE_CMD_DST_MASK_GRC = 2
  53. };
  54. enum _dmae_cmd_src_mask {
  55. DMAE_CMD_SRC_MASK_PCIE = 0,
  56. DMAE_CMD_SRC_MASK_GRC = 1
  57. };
  58. enum _dmae_cmd_crc_mask {
  59. DMAE_CMD_COMP_CRC_EN_MASK_NONE = 0,
  60. DMAE_CMD_COMP_CRC_EN_MASK_SET = 1
  61. };
  62. /* definitions for DMA constants */
  63. #define DMAE_GO_VALUE 0x1
  64. #define DMAE_COMPLETION_VAL 0xD1AE
  65. #define DMAE_CMD_ENDIANITY 0x2
  66. #define DMAE_CMD_SIZE 14
  67. #define DMAE_CMD_SIZE_TO_FILL (DMAE_CMD_SIZE - 5)
  68. #define DMAE_MIN_WAIT_TIME 0x2
  69. #define DMAE_MAX_CLIENTS 32
  70. /**
  71. * @brief qed_gtt_init - Initialize GTT windows
  72. *
  73. * @param p_hwfn
  74. */
  75. void qed_gtt_init(struct qed_hwfn *p_hwfn);
  76. /**
  77. * @brief qed_ptt_invalidate - Forces all ptt entries to be re-configured
  78. *
  79. * @param p_hwfn
  80. */
  81. void qed_ptt_invalidate(struct qed_hwfn *p_hwfn);
  82. /**
  83. * @brief qed_ptt_pool_alloc - Allocate and initialize PTT pool
  84. *
  85. * @param p_hwfn
  86. *
  87. * @return struct _qed_status - success (0), negative - error.
  88. */
  89. int qed_ptt_pool_alloc(struct qed_hwfn *p_hwfn);
  90. /**
  91. * @brief qed_ptt_pool_free -
  92. *
  93. * @param p_hwfn
  94. */
  95. void qed_ptt_pool_free(struct qed_hwfn *p_hwfn);
  96. /**
  97. * @brief qed_ptt_get_hw_addr - Get PTT's GRC/HW address
  98. *
  99. * @param p_hwfn
  100. * @param p_ptt
  101. *
  102. * @return u32
  103. */
  104. u32 qed_ptt_get_hw_addr(struct qed_hwfn *p_hwfn,
  105. struct qed_ptt *p_ptt);
  106. /**
  107. * @brief qed_ptt_get_bar_addr - Get PPT's external BAR address
  108. *
  109. * @param p_hwfn
  110. * @param p_ptt
  111. *
  112. * @return u32
  113. */
  114. u32 qed_ptt_get_bar_addr(struct qed_ptt *p_ptt);
  115. /**
  116. * @brief qed_ptt_set_win - Set PTT Window's GRC BAR address
  117. *
  118. * @param p_hwfn
  119. * @param new_hw_addr
  120. * @param p_ptt
  121. */
  122. void qed_ptt_set_win(struct qed_hwfn *p_hwfn,
  123. struct qed_ptt *p_ptt,
  124. u32 new_hw_addr);
  125. /**
  126. * @brief qed_get_reserved_ptt - Get a specific reserved PTT
  127. *
  128. * @param p_hwfn
  129. * @param ptt_idx
  130. *
  131. * @return struct qed_ptt *
  132. */
  133. struct qed_ptt *qed_get_reserved_ptt(struct qed_hwfn *p_hwfn,
  134. enum reserved_ptts ptt_idx);
  135. /**
  136. * @brief qed_wr - Write value to BAR using the given ptt
  137. *
  138. * @param p_hwfn
  139. * @param p_ptt
  140. * @param val
  141. * @param hw_addr
  142. */
  143. void qed_wr(struct qed_hwfn *p_hwfn,
  144. struct qed_ptt *p_ptt,
  145. u32 hw_addr,
  146. u32 val);
  147. /**
  148. * @brief qed_rd - Read value from BAR using the given ptt
  149. *
  150. * @param p_hwfn
  151. * @param p_ptt
  152. * @param val
  153. * @param hw_addr
  154. */
  155. u32 qed_rd(struct qed_hwfn *p_hwfn,
  156. struct qed_ptt *p_ptt,
  157. u32 hw_addr);
  158. /**
  159. * @brief qed_memcpy_from - copy n bytes from BAR using the given
  160. * ptt
  161. *
  162. * @param p_hwfn
  163. * @param p_ptt
  164. * @param dest
  165. * @param hw_addr
  166. * @param n
  167. */
  168. void qed_memcpy_from(struct qed_hwfn *p_hwfn,
  169. struct qed_ptt *p_ptt,
  170. void *dest,
  171. u32 hw_addr,
  172. size_t n);
  173. /**
  174. * @brief qed_memcpy_to - copy n bytes to BAR using the given
  175. * ptt
  176. *
  177. * @param p_hwfn
  178. * @param p_ptt
  179. * @param hw_addr
  180. * @param src
  181. * @param n
  182. */
  183. void qed_memcpy_to(struct qed_hwfn *p_hwfn,
  184. struct qed_ptt *p_ptt,
  185. u32 hw_addr,
  186. void *src,
  187. size_t n);
  188. /**
  189. * @brief qed_fid_pretend - pretend to another function when
  190. * accessing the ptt window. There is no way to unpretend
  191. * a function. The only way to cancel a pretend is to
  192. * pretend back to the original function.
  193. *
  194. * @param p_hwfn
  195. * @param p_ptt
  196. * @param fid - fid field of pxp_pretend structure. Can contain
  197. * either pf / vf, port/path fields are don't care.
  198. */
  199. void qed_fid_pretend(struct qed_hwfn *p_hwfn,
  200. struct qed_ptt *p_ptt,
  201. u16 fid);
  202. /**
  203. * @brief qed_port_pretend - pretend to another port when
  204. * accessing the ptt window
  205. *
  206. * @param p_hwfn
  207. * @param p_ptt
  208. * @param port_id - the port to pretend to
  209. */
  210. void qed_port_pretend(struct qed_hwfn *p_hwfn,
  211. struct qed_ptt *p_ptt,
  212. u8 port_id);
  213. /**
  214. * @brief qed_port_unpretend - cancel any previously set port
  215. * pretend
  216. *
  217. * @param p_hwfn
  218. * @param p_ptt
  219. */
  220. void qed_port_unpretend(struct qed_hwfn *p_hwfn,
  221. struct qed_ptt *p_ptt);
  222. /**
  223. * @brief qed_port_fid_pretend - pretend to another port and another function
  224. * when accessing the ptt window
  225. *
  226. * @param p_hwfn
  227. * @param p_ptt
  228. * @param port_id - the port to pretend to
  229. * @param fid - fid field of pxp_pretend structure. Can contain either pf / vf.
  230. */
  231. void qed_port_fid_pretend(struct qed_hwfn *p_hwfn,
  232. struct qed_ptt *p_ptt, u8 port_id, u16 fid);
  233. /**
  234. * @brief qed_vfid_to_concrete - build a concrete FID for a
  235. * given VF ID
  236. *
  237. * @param p_hwfn
  238. * @param p_ptt
  239. * @param vfid
  240. */
  241. u32 qed_vfid_to_concrete(struct qed_hwfn *p_hwfn, u8 vfid);
  242. /**
  243. * @brief qed_dmae_idx_to_go_cmd - map the idx to dmae cmd
  244. * this is declared here since other files will require it.
  245. * @param idx
  246. */
  247. u32 qed_dmae_idx_to_go_cmd(u8 idx);
  248. /**
  249. * @brief qed_dmae_info_alloc - Init the dmae_info structure
  250. * which is part of p_hwfn.
  251. * @param p_hwfn
  252. */
  253. int qed_dmae_info_alloc(struct qed_hwfn *p_hwfn);
  254. /**
  255. * @brief qed_dmae_info_free - Free the dmae_info structure
  256. * which is part of p_hwfn
  257. *
  258. * @param p_hwfn
  259. */
  260. void qed_dmae_info_free(struct qed_hwfn *p_hwfn);
  261. union qed_qm_pq_params {
  262. struct {
  263. u8 q_idx;
  264. } iscsi;
  265. struct {
  266. u8 tc;
  267. } core;
  268. struct {
  269. u8 is_vf;
  270. u8 vf_id;
  271. u8 tc;
  272. } eth;
  273. struct {
  274. u8 dcqcn;
  275. u8 qpid; /* roce relative */
  276. } roce;
  277. };
  278. int qed_init_fw_data(struct qed_dev *cdev,
  279. const u8 *fw_data);
  280. int qed_dmae_sanity(struct qed_hwfn *p_hwfn,
  281. struct qed_ptt *p_ptt, const char *phase);
  282. #endif