csio_mb.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * This file is part of the Chelsio FCoE driver for Linux.
  3. *
  4. * Copyright (c) 2008-2012 Chelsio Communications, Inc. All rights reserved.
  5. *
  6. * This software is available to you under a choice of one of two
  7. * licenses. You may choose to be licensed under the terms of the GNU
  8. * General Public License (GPL) Version 2, available from the file
  9. * COPYING in the main directory of this source tree, or the
  10. * OpenIB.org BSD license below:
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above
  17. * copyright notice, this list of conditions and the following
  18. * disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials
  23. * provided with the distribution.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  29. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  30. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  31. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  32. * SOFTWARE.
  33. */
  34. #ifndef __CSIO_MB_H__
  35. #define __CSIO_MB_H__
  36. #include <linux/timer.h>
  37. #include <linux/completion.h>
  38. #include "t4fw_api.h"
  39. #include "t4fw_api_stor.h"
  40. #include "csio_defs.h"
  41. #define CSIO_STATS_OFFSET (2)
  42. #define CSIO_NUM_STATS_PER_MB (6)
  43. struct fw_fcoe_port_cmd_params {
  44. uint8_t portid;
  45. uint8_t idx;
  46. uint8_t nstats;
  47. };
  48. #define CSIO_DUMP_MB(__hw, __num, __mb) \
  49. csio_dbg(__hw, "\t%llx %llx %llx %llx %llx %llx %llx %llx\n", \
  50. (unsigned long long)csio_rd_reg64(__hw, __mb), \
  51. (unsigned long long)csio_rd_reg64(__hw, __mb + 8), \
  52. (unsigned long long)csio_rd_reg64(__hw, __mb + 16), \
  53. (unsigned long long)csio_rd_reg64(__hw, __mb + 24), \
  54. (unsigned long long)csio_rd_reg64(__hw, __mb + 32), \
  55. (unsigned long long)csio_rd_reg64(__hw, __mb + 40), \
  56. (unsigned long long)csio_rd_reg64(__hw, __mb + 48), \
  57. (unsigned long long)csio_rd_reg64(__hw, __mb + 56))
  58. #define CSIO_MB_MAX_REGS 8
  59. #define CSIO_MAX_MB_SIZE 64
  60. #define CSIO_MB_POLL_FREQ 5 /* 5 ms */
  61. #define CSIO_MB_DEFAULT_TMO FW_CMD_MAX_TIMEOUT
  62. /* Device master in HELLO command */
  63. enum csio_dev_master { CSIO_MASTER_CANT, CSIO_MASTER_MAY, CSIO_MASTER_MUST };
  64. enum csio_mb_owner { CSIO_MBOWNER_NONE, CSIO_MBOWNER_FW, CSIO_MBOWNER_PL };
  65. enum csio_dev_state {
  66. CSIO_DEV_STATE_UNINIT,
  67. CSIO_DEV_STATE_INIT,
  68. CSIO_DEV_STATE_ERR
  69. };
  70. #define FW_PARAM_DEV(param) \
  71. (FW_PARAMS_MNEM(FW_PARAMS_MNEM_DEV) | \
  72. FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_DEV_##param))
  73. #define FW_PARAM_PFVF(param) \
  74. (FW_PARAMS_MNEM(FW_PARAMS_MNEM_PFVF) | \
  75. FW_PARAMS_PARAM_X(FW_PARAMS_PARAM_PFVF_##param)| \
  76. FW_PARAMS_PARAM_Y(0) | \
  77. FW_PARAMS_PARAM_Z(0))
  78. enum {
  79. PAUSE_RX = 1 << 0,
  80. PAUSE_TX = 1 << 1,
  81. PAUSE_AUTONEG = 1 << 2
  82. };
  83. #define CSIO_INIT_MBP(__mbp, __cp, __tmo, __priv, __fn, __clear) \
  84. do { \
  85. if (__clear) \
  86. memset((__cp), 0, \
  87. CSIO_MB_MAX_REGS * sizeof(__be64)); \
  88. INIT_LIST_HEAD(&(__mbp)->list); \
  89. (__mbp)->tmo = (__tmo); \
  90. (__mbp)->priv = (void *)(__priv); \
  91. (__mbp)->mb_cbfn = (__fn); \
  92. (__mbp)->mb_size = sizeof(*(__cp)); \
  93. } while (0)
  94. struct csio_mbm_stats {
  95. uint32_t n_req; /* number of mbox req */
  96. uint32_t n_rsp; /* number of mbox rsp */
  97. uint32_t n_activeq; /* number of mbox req active Q */
  98. uint32_t n_cbfnq; /* number of mbox req cbfn Q */
  99. uint32_t n_tmo; /* number of mbox timeout */
  100. uint32_t n_cancel; /* number of mbox cancel */
  101. uint32_t n_err; /* number of mbox error */
  102. };
  103. /* Driver version of Mailbox */
  104. struct csio_mb {
  105. struct list_head list; /* for req/resp */
  106. /* queue in driver */
  107. __be64 mb[CSIO_MB_MAX_REGS]; /* MB in HW format */
  108. int mb_size; /* Size of this
  109. * mailbox.
  110. */
  111. uint32_t tmo; /* Timeout */
  112. struct completion cmplobj; /* MB Completion
  113. * object
  114. */
  115. void (*mb_cbfn) (struct csio_hw *, struct csio_mb *);
  116. /* Callback fn */
  117. void *priv; /* Owner private ptr */
  118. };
  119. struct csio_mbm {
  120. uint32_t a_mbox; /* Async mbox num */
  121. uint32_t intr_idx; /* Interrupt index */
  122. struct timer_list timer; /* Mbox timer */
  123. struct list_head req_q; /* Mbox request queue */
  124. struct list_head cbfn_q; /* Mbox completion q */
  125. struct csio_mb *mcurrent; /* Current mailbox */
  126. uint32_t req_q_cnt; /* Outstanding mbox
  127. * cmds
  128. */
  129. struct csio_mbm_stats stats; /* Statistics */
  130. };
  131. #define csio_set_mb_intr_idx(_m, _i) ((_m)->intr_idx = (_i))
  132. #define csio_get_mb_intr_idx(_m) ((_m)->intr_idx)
  133. struct csio_iq_params;
  134. struct csio_eq_params;
  135. enum fw_retval csio_mb_fw_retval(struct csio_mb *);
  136. /* MB helpers */
  137. void csio_mb_hello(struct csio_hw *, struct csio_mb *, uint32_t,
  138. uint32_t, uint32_t, enum csio_dev_master,
  139. void (*)(struct csio_hw *, struct csio_mb *));
  140. void csio_mb_process_hello_rsp(struct csio_hw *, struct csio_mb *,
  141. enum fw_retval *, enum csio_dev_state *,
  142. uint8_t *);
  143. void csio_mb_bye(struct csio_hw *, struct csio_mb *, uint32_t,
  144. void (*)(struct csio_hw *, struct csio_mb *));
  145. void csio_mb_reset(struct csio_hw *, struct csio_mb *, uint32_t, int, int,
  146. void (*)(struct csio_hw *, struct csio_mb *));
  147. void csio_mb_params(struct csio_hw *, struct csio_mb *, uint32_t, unsigned int,
  148. unsigned int, unsigned int, const u32 *, u32 *, bool,
  149. void (*)(struct csio_hw *, struct csio_mb *));
  150. void csio_mb_process_read_params_rsp(struct csio_hw *, struct csio_mb *,
  151. enum fw_retval *, unsigned int , u32 *);
  152. void csio_mb_ldst(struct csio_hw *hw, struct csio_mb *mbp, uint32_t tmo,
  153. int reg);
  154. void csio_mb_caps_config(struct csio_hw *, struct csio_mb *, uint32_t,
  155. bool, bool, bool, bool,
  156. void (*)(struct csio_hw *, struct csio_mb *));
  157. void csio_rss_glb_config(struct csio_hw *, struct csio_mb *,
  158. uint32_t, uint8_t, unsigned int,
  159. void (*)(struct csio_hw *, struct csio_mb *));
  160. void csio_mb_pfvf(struct csio_hw *, struct csio_mb *, uint32_t,
  161. unsigned int, unsigned int, unsigned int,
  162. unsigned int, unsigned int, unsigned int,
  163. unsigned int, unsigned int, unsigned int,
  164. unsigned int, unsigned int, unsigned int,
  165. unsigned int, void (*) (struct csio_hw *, struct csio_mb *));
  166. void csio_mb_port(struct csio_hw *, struct csio_mb *, uint32_t,
  167. uint8_t, bool, uint32_t, uint16_t,
  168. void (*) (struct csio_hw *, struct csio_mb *));
  169. void csio_mb_process_read_port_rsp(struct csio_hw *, struct csio_mb *,
  170. enum fw_retval *, uint16_t *);
  171. void csio_mb_initialize(struct csio_hw *, struct csio_mb *, uint32_t,
  172. void (*)(struct csio_hw *, struct csio_mb *));
  173. void csio_mb_iq_alloc_write(struct csio_hw *, struct csio_mb *, void *,
  174. uint32_t, struct csio_iq_params *,
  175. void (*) (struct csio_hw *, struct csio_mb *));
  176. void csio_mb_iq_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
  177. enum fw_retval *, struct csio_iq_params *);
  178. void csio_mb_iq_free(struct csio_hw *, struct csio_mb *, void *,
  179. uint32_t, struct csio_iq_params *,
  180. void (*) (struct csio_hw *, struct csio_mb *));
  181. void csio_mb_eq_ofld_alloc_write(struct csio_hw *, struct csio_mb *, void *,
  182. uint32_t, struct csio_eq_params *,
  183. void (*) (struct csio_hw *, struct csio_mb *));
  184. void csio_mb_eq_ofld_alloc_write_rsp(struct csio_hw *, struct csio_mb *,
  185. enum fw_retval *, struct csio_eq_params *);
  186. void csio_mb_eq_ofld_free(struct csio_hw *, struct csio_mb *, void *,
  187. uint32_t , struct csio_eq_params *,
  188. void (*) (struct csio_hw *, struct csio_mb *));
  189. void csio_fcoe_read_res_info_init_mb(struct csio_hw *, struct csio_mb *,
  190. uint32_t,
  191. void (*) (struct csio_hw *, struct csio_mb *));
  192. void csio_write_fcoe_link_cond_init_mb(struct csio_lnode *, struct csio_mb *,
  193. uint32_t, uint8_t, uint32_t, uint8_t, bool, uint32_t,
  194. void (*) (struct csio_hw *, struct csio_mb *));
  195. void csio_fcoe_vnp_alloc_init_mb(struct csio_lnode *, struct csio_mb *,
  196. uint32_t, uint32_t , uint32_t , uint16_t,
  197. uint8_t [8], uint8_t [8],
  198. void (*) (struct csio_hw *, struct csio_mb *));
  199. void csio_fcoe_vnp_read_init_mb(struct csio_lnode *, struct csio_mb *,
  200. uint32_t, uint32_t , uint32_t ,
  201. void (*) (struct csio_hw *, struct csio_mb *));
  202. void csio_fcoe_vnp_free_init_mb(struct csio_lnode *, struct csio_mb *,
  203. uint32_t , uint32_t, uint32_t ,
  204. void (*) (struct csio_hw *, struct csio_mb *));
  205. void csio_fcoe_read_fcf_init_mb(struct csio_lnode *, struct csio_mb *,
  206. uint32_t, uint32_t, uint32_t,
  207. void (*cbfn) (struct csio_hw *, struct csio_mb *));
  208. void csio_fcoe_read_portparams_init_mb(struct csio_hw *hw,
  209. struct csio_mb *mbp, uint32_t mb_tmo,
  210. struct fw_fcoe_port_cmd_params *portparams,
  211. void (*cbfn)(struct csio_hw *, struct csio_mb *));
  212. void csio_mb_process_portparams_rsp(struct csio_hw *hw, struct csio_mb *mbp,
  213. enum fw_retval *retval,
  214. struct fw_fcoe_port_cmd_params *portparams,
  215. struct fw_fcoe_port_stats *portstats);
  216. /* MB module functions */
  217. int csio_mbm_init(struct csio_mbm *, struct csio_hw *,
  218. void (*)(uintptr_t));
  219. void csio_mbm_exit(struct csio_mbm *);
  220. void csio_mb_intr_enable(struct csio_hw *);
  221. void csio_mb_intr_disable(struct csio_hw *);
  222. int csio_mb_issue(struct csio_hw *, struct csio_mb *);
  223. void csio_mb_completions(struct csio_hw *, struct list_head *);
  224. int csio_mb_fwevt_handler(struct csio_hw *, __be64 *);
  225. int csio_mb_isr_handler(struct csio_hw *);
  226. struct csio_mb *csio_mb_tmo_handler(struct csio_hw *);
  227. void csio_mb_cancel_all(struct csio_hw *, struct list_head *);
  228. #endif /* ifndef __CSIO_MB_H__ */