bfa_cee.c 7.2 KB

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