bfa_cee.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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()
  49. *
  50. * @brief Returns the size of the DMA memory needed by CEE attributes
  51. *
  52. * @param[in] void
  53. *
  54. * @return Size of DMA region
  55. */
  56. static u32
  57. bfa_cee_attr_meminfo(void)
  58. {
  59. return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
  60. }
  61. /**
  62. * bfa_cee_stats_meminfo()
  63. *
  64. * @brief Returns the size of the DMA memory needed by CEE stats
  65. *
  66. * @param[in] void
  67. *
  68. * @return Size of DMA region
  69. */
  70. static u32
  71. bfa_cee_stats_meminfo(void)
  72. {
  73. return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
  74. }
  75. /**
  76. * bfa_cee_get_attr_isr()
  77. *
  78. * @brief CEE ISR for get-attributes responses from f/w
  79. *
  80. * @param[in] cee - Pointer to the CEE module
  81. * status - Return status from the f/w
  82. *
  83. * @return void
  84. */
  85. static void
  86. bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
  87. {
  88. cee->get_attr_status = status;
  89. if (status == BFA_STATUS_OK) {
  90. memcpy(cee->attr, cee->attr_dma.kva,
  91. sizeof(struct bfa_cee_attr));
  92. bfa_cee_format_cee_cfg(cee->attr);
  93. }
  94. cee->get_attr_pending = false;
  95. if (cee->cbfn.get_attr_cbfn)
  96. cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
  97. }
  98. /**
  99. * bfa_cee_get_attr_isr()
  100. *
  101. * @brief CEE ISR for get-stats responses from f/w
  102. *
  103. * @param[in] cee - Pointer to the CEE module
  104. * status - Return status from the f/w
  105. *
  106. * @return void
  107. */
  108. static void
  109. bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
  110. {
  111. cee->get_stats_status = status;
  112. if (status == BFA_STATUS_OK) {
  113. memcpy(cee->stats, cee->stats_dma.kva,
  114. sizeof(struct bfa_cee_stats));
  115. bfa_cee_stats_swap(cee->stats);
  116. }
  117. cee->get_stats_pending = false;
  118. if (cee->cbfn.get_stats_cbfn)
  119. cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
  120. }
  121. /**
  122. * bfa_cee_get_attr_isr()
  123. *
  124. * @brief CEE ISR for reset-stats responses from f/w
  125. *
  126. * @param[in] cee - Pointer to the CEE module
  127. * status - Return status from the f/w
  128. *
  129. * @return void
  130. */
  131. static void
  132. bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
  133. {
  134. cee->reset_stats_status = status;
  135. cee->reset_stats_pending = false;
  136. if (cee->cbfn.reset_stats_cbfn)
  137. cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
  138. }
  139. /**
  140. * bfa_nw_cee_meminfo()
  141. *
  142. * @brief Returns the size of the DMA memory needed by CEE module
  143. *
  144. * @param[in] void
  145. *
  146. * @return Size of DMA region
  147. */
  148. u32
  149. bfa_nw_cee_meminfo(void)
  150. {
  151. return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
  152. }
  153. /**
  154. * bfa_nw_cee_mem_claim()
  155. *
  156. * @brief Initialized CEE DMA Memory
  157. *
  158. * @param[in] cee CEE module pointer
  159. * dma_kva Kernel Virtual Address of CEE DMA Memory
  160. * dma_pa Physical Address of CEE DMA Memory
  161. *
  162. * @return void
  163. */
  164. void
  165. bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
  166. {
  167. cee->attr_dma.kva = dma_kva;
  168. cee->attr_dma.pa = dma_pa;
  169. cee->stats_dma.kva = dma_kva + bfa_cee_attr_meminfo();
  170. cee->stats_dma.pa = dma_pa + bfa_cee_attr_meminfo();
  171. cee->attr = (struct bfa_cee_attr *) dma_kva;
  172. cee->stats = (struct bfa_cee_stats *)
  173. (dma_kva + bfa_cee_attr_meminfo());
  174. }
  175. /**
  176. * bfa_cee_isrs()
  177. *
  178. * @brief Handles Mail-box interrupts for CEE module.
  179. *
  180. * @param[in] Pointer to the CEE module data structure.
  181. *
  182. * @return void
  183. */
  184. static void
  185. bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
  186. {
  187. union bfi_cee_i2h_msg_u *msg;
  188. struct bfi_cee_get_rsp *get_rsp;
  189. struct bfa_cee *cee = (struct bfa_cee *) cbarg;
  190. msg = (union bfi_cee_i2h_msg_u *) m;
  191. get_rsp = (struct bfi_cee_get_rsp *) m;
  192. switch (msg->mh.msg_id) {
  193. case BFI_CEE_I2H_GET_CFG_RSP:
  194. bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
  195. break;
  196. case BFI_CEE_I2H_GET_STATS_RSP:
  197. bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
  198. break;
  199. case BFI_CEE_I2H_RESET_STATS_RSP:
  200. bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
  201. break;
  202. default:
  203. BUG_ON(1);
  204. }
  205. }
  206. /**
  207. * bfa_cee_notify()
  208. *
  209. * @brief CEE module heart-beat failure handler.
  210. * @brief CEE module IOC event handler.
  211. *
  212. * @param[in] IOC event type
  213. *
  214. * @return void
  215. */
  216. static void
  217. bfa_cee_notify(void *arg, enum bfa_ioc_event event)
  218. {
  219. struct bfa_cee *cee;
  220. cee = (struct bfa_cee *) arg;
  221. switch (event) {
  222. case BFA_IOC_E_DISABLED:
  223. case BFA_IOC_E_FAILED:
  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(
  229. cee->cbfn.get_attr_cbarg,
  230. BFA_STATUS_FAILED);
  231. }
  232. }
  233. if (cee->get_stats_pending == true) {
  234. cee->get_stats_status = BFA_STATUS_FAILED;
  235. cee->get_stats_pending = false;
  236. if (cee->cbfn.get_stats_cbfn) {
  237. cee->cbfn.get_stats_cbfn(
  238. cee->cbfn.get_stats_cbarg,
  239. BFA_STATUS_FAILED);
  240. }
  241. }
  242. if (cee->reset_stats_pending == true) {
  243. cee->reset_stats_status = BFA_STATUS_FAILED;
  244. cee->reset_stats_pending = false;
  245. if (cee->cbfn.reset_stats_cbfn) {
  246. cee->cbfn.reset_stats_cbfn(
  247. cee->cbfn.reset_stats_cbarg,
  248. BFA_STATUS_FAILED);
  249. }
  250. }
  251. break;
  252. default:
  253. break;
  254. }
  255. }
  256. /**
  257. * bfa_nw_cee_attach()
  258. *
  259. * @brief CEE module-attach API
  260. *
  261. * @param[in] cee - Pointer to the CEE module data structure
  262. * ioc - Pointer to the ioc module data structure
  263. * dev - Pointer to the device driver module data structure
  264. * The device driver specific mbox ISR functions have
  265. * this pointer as one of the parameters.
  266. *
  267. * @return void
  268. */
  269. void
  270. bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
  271. void *dev)
  272. {
  273. BUG_ON(!(cee != NULL));
  274. cee->dev = dev;
  275. cee->ioc = ioc;
  276. bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
  277. bfa_q_qe_init(&cee->ioc_notify);
  278. bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
  279. bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);
  280. }