bfa_cee.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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_get_attr()
  177. *
  178. * @brief Send the request to the f/w to fetch CEE attributes.
  179. *
  180. * @param[in] Pointer to the CEE module data structure.
  181. *
  182. * @return Status
  183. */
  184. enum bfa_status
  185. bfa_nw_cee_get_attr(struct bfa_cee *cee, struct bfa_cee_attr *attr,
  186. bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
  187. {
  188. struct bfi_cee_get_req *cmd;
  189. BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
  190. if (!bfa_nw_ioc_is_operational(cee->ioc))
  191. return BFA_STATUS_IOC_FAILURE;
  192. if (cee->get_attr_pending)
  193. return BFA_STATUS_DEVBUSY;
  194. cee->get_attr_pending = true;
  195. cmd = (struct bfi_cee_get_req *) cee->get_cfg_mb.msg;
  196. cee->attr = attr;
  197. cee->cbfn.get_attr_cbfn = cbfn;
  198. cee->cbfn.get_attr_cbarg = cbarg;
  199. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
  200. bfa_ioc_portid(cee->ioc));
  201. bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
  202. bfa_nw_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb, NULL, NULL);
  203. return BFA_STATUS_OK;
  204. }
  205. /**
  206. * bfa_cee_isrs()
  207. *
  208. * @brief Handles Mail-box interrupts for CEE module.
  209. *
  210. * @param[in] Pointer to the CEE module data structure.
  211. *
  212. * @return void
  213. */
  214. static void
  215. bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
  216. {
  217. union bfi_cee_i2h_msg_u *msg;
  218. struct bfi_cee_get_rsp *get_rsp;
  219. struct bfa_cee *cee = (struct bfa_cee *) cbarg;
  220. msg = (union bfi_cee_i2h_msg_u *) m;
  221. get_rsp = (struct bfi_cee_get_rsp *) m;
  222. switch (msg->mh.msg_id) {
  223. case BFI_CEE_I2H_GET_CFG_RSP:
  224. bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
  225. break;
  226. case BFI_CEE_I2H_GET_STATS_RSP:
  227. bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
  228. break;
  229. case BFI_CEE_I2H_RESET_STATS_RSP:
  230. bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
  231. break;
  232. default:
  233. BUG_ON(1);
  234. }
  235. }
  236. /**
  237. * bfa_cee_notify()
  238. *
  239. * @brief CEE module heart-beat failure handler.
  240. * @brief CEE module IOC event handler.
  241. *
  242. * @param[in] IOC event type
  243. *
  244. * @return void
  245. */
  246. static void
  247. bfa_cee_notify(void *arg, enum bfa_ioc_event event)
  248. {
  249. struct bfa_cee *cee;
  250. cee = (struct bfa_cee *) arg;
  251. switch (event) {
  252. case BFA_IOC_E_DISABLED:
  253. case BFA_IOC_E_FAILED:
  254. if (cee->get_attr_pending) {
  255. cee->get_attr_status = BFA_STATUS_FAILED;
  256. cee->get_attr_pending = false;
  257. if (cee->cbfn.get_attr_cbfn) {
  258. cee->cbfn.get_attr_cbfn(
  259. cee->cbfn.get_attr_cbarg,
  260. BFA_STATUS_FAILED);
  261. }
  262. }
  263. if (cee->get_stats_pending) {
  264. cee->get_stats_status = BFA_STATUS_FAILED;
  265. cee->get_stats_pending = false;
  266. if (cee->cbfn.get_stats_cbfn) {
  267. cee->cbfn.get_stats_cbfn(
  268. cee->cbfn.get_stats_cbarg,
  269. BFA_STATUS_FAILED);
  270. }
  271. }
  272. if (cee->reset_stats_pending) {
  273. cee->reset_stats_status = BFA_STATUS_FAILED;
  274. cee->reset_stats_pending = false;
  275. if (cee->cbfn.reset_stats_cbfn) {
  276. cee->cbfn.reset_stats_cbfn(
  277. cee->cbfn.reset_stats_cbarg,
  278. BFA_STATUS_FAILED);
  279. }
  280. }
  281. break;
  282. default:
  283. break;
  284. }
  285. }
  286. /**
  287. * bfa_nw_cee_attach()
  288. *
  289. * @brief CEE module-attach API
  290. *
  291. * @param[in] cee - Pointer to the CEE module data structure
  292. * ioc - Pointer to the ioc module data structure
  293. * dev - Pointer to the device driver module data structure
  294. * The device driver specific mbox ISR functions have
  295. * this pointer as one of the parameters.
  296. *
  297. * @return void
  298. */
  299. void
  300. bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
  301. void *dev)
  302. {
  303. BUG_ON(!(cee != NULL));
  304. cee->dev = dev;
  305. cee->ioc = ioc;
  306. bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
  307. bfa_q_qe_init(&cee->ioc_notify);
  308. bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
  309. bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);
  310. }