bfa_cee.c 6.9 KB

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