bfa_cee.c 7.0 KB

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