bfa_cee.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Linux network driver for QLogic BR-series Converged Network Adapter.
  4. */
  5. /*
  6. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  7. * Copyright (c) 2014-2015 QLogic Corporation
  8. * All rights reserved
  9. * www.qlogic.com
  10. */
  11. #include "bfa_cee.h"
  12. #include "bfi_cna.h"
  13. #include "bfa_ioc.h"
  14. static void bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg);
  15. static void bfa_cee_format_cee_cfg(void *buffer);
  16. static void
  17. bfa_cee_format_cee_cfg(void *buffer)
  18. {
  19. struct bfa_cee_attr *cee_cfg = buffer;
  20. bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
  21. }
  22. static void
  23. bfa_cee_stats_swap(struct bfa_cee_stats *stats)
  24. {
  25. u32 *buffer = (u32 *)stats;
  26. int i;
  27. for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
  28. i++) {
  29. buffer[i] = ntohl(buffer[i]);
  30. }
  31. }
  32. static void
  33. bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
  34. {
  35. lldp_cfg->time_to_live =
  36. ntohs(lldp_cfg->time_to_live);
  37. lldp_cfg->enabled_system_cap =
  38. ntohs(lldp_cfg->enabled_system_cap);
  39. }
  40. /**
  41. * bfa_cee_attr_meminfo - Returns the size of the DMA memory needed by CEE attributes
  42. */
  43. static u32
  44. bfa_cee_attr_meminfo(void)
  45. {
  46. return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
  47. }
  48. /**
  49. * bfa_cee_stats_meminfo - Returns the size of the DMA memory needed by CEE stats
  50. */
  51. static u32
  52. bfa_cee_stats_meminfo(void)
  53. {
  54. return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
  55. }
  56. /**
  57. * bfa_cee_get_attr_isr - CEE ISR for get-attributes responses from f/w
  58. *
  59. * @cee: Pointer to the CEE module
  60. * @status: Return status from the f/w
  61. */
  62. static void
  63. bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
  64. {
  65. cee->get_attr_status = status;
  66. if (status == BFA_STATUS_OK) {
  67. memcpy(cee->attr, cee->attr_dma.kva,
  68. sizeof(struct bfa_cee_attr));
  69. bfa_cee_format_cee_cfg(cee->attr);
  70. }
  71. cee->get_attr_pending = false;
  72. if (cee->cbfn.get_attr_cbfn)
  73. cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
  74. }
  75. /**
  76. * bfa_cee_get_stats_isr - CEE ISR for get-stats responses from f/w
  77. *
  78. * @cee: Pointer to the CEE module
  79. * @status: Return status from the f/w
  80. */
  81. static void
  82. bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
  83. {
  84. cee->get_stats_status = status;
  85. if (status == BFA_STATUS_OK) {
  86. memcpy(cee->stats, cee->stats_dma.kva,
  87. sizeof(struct bfa_cee_stats));
  88. bfa_cee_stats_swap(cee->stats);
  89. }
  90. cee->get_stats_pending = false;
  91. if (cee->cbfn.get_stats_cbfn)
  92. cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
  93. }
  94. /**
  95. * bfa_cee_reset_stats_isr - CEE ISR for reset-stats responses from f/w
  96. *
  97. * @cee: Input Pointer to the CEE module
  98. * @status: Return status from the f/w
  99. */
  100. static void
  101. bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
  102. {
  103. cee->reset_stats_status = status;
  104. cee->reset_stats_pending = false;
  105. if (cee->cbfn.reset_stats_cbfn)
  106. cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
  107. }
  108. /**
  109. * bfa_nw_cee_meminfo - Returns the size of the DMA memory needed by CEE module
  110. */
  111. u32
  112. bfa_nw_cee_meminfo(void)
  113. {
  114. return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
  115. }
  116. /**
  117. * bfa_nw_cee_mem_claim - Initialized CEE DMA Memory
  118. *
  119. * @cee: CEE module pointer
  120. * @dma_kva: Kernel Virtual Address of CEE DMA Memory
  121. * @dma_pa: Physical Address of CEE DMA Memory
  122. */
  123. void
  124. bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
  125. {
  126. cee->attr_dma.kva = dma_kva;
  127. cee->attr_dma.pa = dma_pa;
  128. cee->stats_dma.kva = dma_kva + bfa_cee_attr_meminfo();
  129. cee->stats_dma.pa = dma_pa + bfa_cee_attr_meminfo();
  130. cee->attr = (struct bfa_cee_attr *) dma_kva;
  131. cee->stats = (struct bfa_cee_stats *)
  132. (dma_kva + bfa_cee_attr_meminfo());
  133. }
  134. /**
  135. * bfa_nw_cee_get_attr - Send the request to the f/w to fetch CEE attributes.
  136. *
  137. * @cee: Pointer to the CEE module data structure.
  138. * @attr: attribute requested
  139. * @cbfn: function pointer
  140. * @cbarg: function pointer arguments
  141. *
  142. * Return: status
  143. */
  144. enum bfa_status
  145. bfa_nw_cee_get_attr(struct bfa_cee *cee, struct bfa_cee_attr *attr,
  146. bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
  147. {
  148. struct bfi_cee_get_req *cmd;
  149. BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
  150. if (!bfa_nw_ioc_is_operational(cee->ioc))
  151. return BFA_STATUS_IOC_FAILURE;
  152. if (cee->get_attr_pending)
  153. return BFA_STATUS_DEVBUSY;
  154. cee->get_attr_pending = true;
  155. cmd = (struct bfi_cee_get_req *) cee->get_cfg_mb.msg;
  156. cee->attr = attr;
  157. cee->cbfn.get_attr_cbfn = cbfn;
  158. cee->cbfn.get_attr_cbarg = cbarg;
  159. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
  160. bfa_ioc_portid(cee->ioc));
  161. bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
  162. bfa_nw_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb, NULL, NULL);
  163. return BFA_STATUS_OK;
  164. }
  165. /**
  166. * bfa_cee_isr - Handles Mail-box interrupts for CEE module.
  167. * @cbarg: argument passed containing pointer to the CEE module data structure.
  168. * @m: message pointer
  169. */
  170. static void
  171. bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
  172. {
  173. union bfi_cee_i2h_msg_u *msg;
  174. struct bfi_cee_get_rsp *get_rsp;
  175. struct bfa_cee *cee = (struct bfa_cee *) cbarg;
  176. msg = (union bfi_cee_i2h_msg_u *) m;
  177. get_rsp = (struct bfi_cee_get_rsp *) m;
  178. switch (msg->mh.msg_id) {
  179. case BFI_CEE_I2H_GET_CFG_RSP:
  180. bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
  181. break;
  182. case BFI_CEE_I2H_GET_STATS_RSP:
  183. bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
  184. break;
  185. case BFI_CEE_I2H_RESET_STATS_RSP:
  186. bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
  187. break;
  188. default:
  189. BUG_ON(1);
  190. }
  191. }
  192. /**
  193. * bfa_cee_notify - CEE module heart-beat failure handler.
  194. *
  195. * @arg: argument passed containing pointer to the CEE module data structure.
  196. * @event: IOC event type
  197. */
  198. static void
  199. bfa_cee_notify(void *arg, enum bfa_ioc_event event)
  200. {
  201. struct bfa_cee *cee;
  202. cee = (struct bfa_cee *) arg;
  203. switch (event) {
  204. case BFA_IOC_E_DISABLED:
  205. case BFA_IOC_E_FAILED:
  206. if (cee->get_attr_pending) {
  207. cee->get_attr_status = BFA_STATUS_FAILED;
  208. cee->get_attr_pending = false;
  209. if (cee->cbfn.get_attr_cbfn) {
  210. cee->cbfn.get_attr_cbfn(
  211. cee->cbfn.get_attr_cbarg,
  212. BFA_STATUS_FAILED);
  213. }
  214. }
  215. if (cee->get_stats_pending) {
  216. cee->get_stats_status = BFA_STATUS_FAILED;
  217. cee->get_stats_pending = false;
  218. if (cee->cbfn.get_stats_cbfn) {
  219. cee->cbfn.get_stats_cbfn(
  220. cee->cbfn.get_stats_cbarg,
  221. BFA_STATUS_FAILED);
  222. }
  223. }
  224. if (cee->reset_stats_pending) {
  225. cee->reset_stats_status = BFA_STATUS_FAILED;
  226. cee->reset_stats_pending = false;
  227. if (cee->cbfn.reset_stats_cbfn) {
  228. cee->cbfn.reset_stats_cbfn(
  229. cee->cbfn.reset_stats_cbarg,
  230. BFA_STATUS_FAILED);
  231. }
  232. }
  233. break;
  234. default:
  235. break;
  236. }
  237. }
  238. /**
  239. * bfa_nw_cee_attach - CEE module-attach API
  240. *
  241. * @cee: Pointer to the CEE module data structure
  242. * @ioc: Pointer to the ioc module data structure
  243. * @dev: Pointer to the device driver module data structure.
  244. * The device driver specific mbox ISR functions have
  245. * this pointer as one of the parameters.
  246. */
  247. void
  248. bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
  249. void *dev)
  250. {
  251. BUG_ON(!(cee != NULL));
  252. cee->dev = dev;
  253. cee->ioc = ioc;
  254. bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
  255. bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
  256. bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);
  257. }