bfa_cee.c 7.2 KB

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