bfa_port.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include <defs/bfa_defs_port.h>
  18. #include <cs/bfa_trc.h>
  19. #include <cs/bfa_log.h>
  20. #include <cs/bfa_debug.h>
  21. #include <port/bfa_port.h>
  22. #include <bfi/bfi.h>
  23. #include <bfi/bfi_port.h>
  24. #include <bfa_ioc.h>
  25. #include <cna/bfa_cna_trcmod.h>
  26. BFA_TRC_FILE(CNA, PORT);
  27. #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
  28. #define bfa_lpuid(__arg) bfa_ioc_portid(&(__arg)->ioc)
  29. static void
  30. bfa_port_stats_swap(struct bfa_port_s *port, union bfa_pport_stats_u *stats)
  31. {
  32. u32 *dip = (u32 *) stats;
  33. u32 t0, t1;
  34. int i;
  35. for (i = 0; i < sizeof(union bfa_pport_stats_u) / sizeof(u32);
  36. i += 2) {
  37. t0 = dip[i];
  38. t1 = dip[i + 1];
  39. #ifdef __BIGENDIAN
  40. dip[i] = bfa_os_ntohl(t0);
  41. dip[i + 1] = bfa_os_ntohl(t1);
  42. #else
  43. dip[i] = bfa_os_ntohl(t1);
  44. dip[i + 1] = bfa_os_ntohl(t0);
  45. #endif
  46. }
  47. /** todo
  48. * QoS stats r also swapped as 64bit; that structure also
  49. * has to use 64 bit counters
  50. */
  51. }
  52. /**
  53. * bfa_port_enable_isr()
  54. *
  55. *
  56. * @param[in] port - Pointer to the port module
  57. * status - Return status from the f/w
  58. *
  59. * @return void
  60. */
  61. static void
  62. bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
  63. {
  64. bfa_assert(0);
  65. }
  66. /**
  67. * bfa_port_disable_isr()
  68. *
  69. *
  70. * @param[in] port - Pointer to the port module
  71. * status - Return status from the f/w
  72. *
  73. * @return void
  74. */
  75. static void
  76. bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
  77. {
  78. bfa_assert(0);
  79. }
  80. /**
  81. * bfa_port_get_stats_isr()
  82. *
  83. *
  84. * @param[in] port - Pointer to the Port module
  85. * status - Return status from the f/w
  86. *
  87. * @return void
  88. */
  89. static void
  90. bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
  91. {
  92. port->stats_status = status;
  93. port->stats_busy = BFA_FALSE;
  94. if (status == BFA_STATUS_OK) {
  95. memcpy(port->stats, port->stats_dma.kva,
  96. sizeof(union bfa_pport_stats_u));
  97. bfa_port_stats_swap(port, port->stats);
  98. }
  99. if (port->stats_cbfn) {
  100. port->stats_cbfn(port->stats_cbarg, status);
  101. port->stats_cbfn = NULL;
  102. }
  103. }
  104. /**
  105. * bfa_port_clear_stats_isr()
  106. *
  107. *
  108. * @param[in] port - Pointer to the Port module
  109. * status - Return status from the f/w
  110. *
  111. * @return void
  112. */
  113. static void
  114. bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
  115. {
  116. port->stats_status = status;
  117. port->stats_busy = BFA_FALSE;
  118. if (port->stats_cbfn) {
  119. port->stats_cbfn(port->stats_cbarg, status);
  120. port->stats_cbfn = NULL;
  121. }
  122. }
  123. /**
  124. * bfa_port_isr()
  125. *
  126. *
  127. * @param[in] Pointer to the Port module data structure.
  128. *
  129. * @return void
  130. */
  131. static void
  132. bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
  133. {
  134. struct bfa_port_s *port = (struct bfa_port_s *)cbarg;
  135. union bfi_port_i2h_msg_u *i2hmsg;
  136. i2hmsg = (union bfi_port_i2h_msg_u *)m;
  137. bfa_trc(port, m->mh.msg_id);
  138. switch (m->mh.msg_id) {
  139. case BFI_PORT_I2H_ENABLE_RSP:
  140. if (port->endis_pending == BFA_FALSE)
  141. break;
  142. bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
  143. break;
  144. case BFI_PORT_I2H_DISABLE_RSP:
  145. if (port->endis_pending == BFA_FALSE)
  146. break;
  147. bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
  148. break;
  149. case BFI_PORT_I2H_GET_STATS_RSP:
  150. /*
  151. * Stats busy flag is still set? (may be cmd timed out)
  152. */
  153. if (port->stats_busy == BFA_FALSE)
  154. break;
  155. bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
  156. break;
  157. case BFI_PORT_I2H_CLEAR_STATS_RSP:
  158. if (port->stats_busy == BFA_FALSE)
  159. break;
  160. bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
  161. break;
  162. default:
  163. bfa_assert(0);
  164. }
  165. }
  166. /**
  167. * bfa_port_meminfo()
  168. *
  169. *
  170. * @param[in] void
  171. *
  172. * @return Size of DMA region
  173. */
  174. u32
  175. bfa_port_meminfo(void)
  176. {
  177. return BFA_ROUNDUP(sizeof(union bfa_pport_stats_u), BFA_DMA_ALIGN_SZ);
  178. }
  179. /**
  180. * bfa_port_mem_claim()
  181. *
  182. *
  183. * @param[in] port Port module pointer
  184. * dma_kva Kernel Virtual Address of Port DMA Memory
  185. * dma_pa Physical Address of Port DMA Memory
  186. *
  187. * @return void
  188. */
  189. void
  190. bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
  191. {
  192. port->stats_dma.kva = dma_kva;
  193. port->stats_dma.pa = dma_pa;
  194. }
  195. /**
  196. * bfa_port_enable()
  197. *
  198. * Send the Port enable request to the f/w
  199. *
  200. * @param[in] Pointer to the Port module data structure.
  201. *
  202. * @return Status
  203. */
  204. bfa_status_t
  205. bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  206. void *cbarg)
  207. {
  208. struct bfi_port_generic_req_s *m;
  209. /** todo Not implemented */
  210. bfa_assert(0);
  211. if (!bfa_ioc_is_operational(port->ioc)) {
  212. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  213. return BFA_STATUS_IOC_FAILURE;
  214. }
  215. if (port->endis_pending) {
  216. bfa_trc(port, BFA_STATUS_DEVBUSY);
  217. return BFA_STATUS_DEVBUSY;
  218. }
  219. m = (struct bfi_port_generic_req_s *)port->endis_mb.msg;
  220. port->msgtag++;
  221. port->endis_cbfn = cbfn;
  222. port->endis_cbarg = cbarg;
  223. port->endis_pending = BFA_TRUE;
  224. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
  225. bfa_ioc_portid(port->ioc));
  226. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  227. return BFA_STATUS_OK;
  228. }
  229. /**
  230. * bfa_port_disable()
  231. *
  232. * Send the Port disable request to the f/w
  233. *
  234. * @param[in] Pointer to the Port module data structure.
  235. *
  236. * @return Status
  237. */
  238. bfa_status_t
  239. bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  240. void *cbarg)
  241. {
  242. struct bfi_port_generic_req_s *m;
  243. /** todo Not implemented */
  244. bfa_assert(0);
  245. if (!bfa_ioc_is_operational(port->ioc)) {
  246. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  247. return BFA_STATUS_IOC_FAILURE;
  248. }
  249. if (port->endis_pending) {
  250. bfa_trc(port, BFA_STATUS_DEVBUSY);
  251. return BFA_STATUS_DEVBUSY;
  252. }
  253. m = (struct bfi_port_generic_req_s *)port->endis_mb.msg;
  254. port->msgtag++;
  255. port->endis_cbfn = cbfn;
  256. port->endis_cbarg = cbarg;
  257. port->endis_pending = BFA_TRUE;
  258. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
  259. bfa_ioc_portid(port->ioc));
  260. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  261. return BFA_STATUS_OK;
  262. }
  263. /**
  264. * bfa_port_get_stats()
  265. *
  266. * Send the request to the f/w to fetch Port statistics.
  267. *
  268. * @param[in] Pointer to the Port module data structure.
  269. *
  270. * @return Status
  271. */
  272. bfa_status_t
  273. bfa_port_get_stats(struct bfa_port_s *port, union bfa_pport_stats_u *stats,
  274. bfa_port_stats_cbfn_t cbfn, void *cbarg)
  275. {
  276. struct bfi_port_get_stats_req_s *m;
  277. if (!bfa_ioc_is_operational(port->ioc)) {
  278. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  279. return BFA_STATUS_IOC_FAILURE;
  280. }
  281. if (port->stats_busy) {
  282. bfa_trc(port, BFA_STATUS_DEVBUSY);
  283. return BFA_STATUS_DEVBUSY;
  284. }
  285. m = (struct bfi_port_get_stats_req_s *)port->stats_mb.msg;
  286. port->stats = stats;
  287. port->stats_cbfn = cbfn;
  288. port->stats_cbarg = cbarg;
  289. port->stats_busy = BFA_TRUE;
  290. bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
  291. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
  292. bfa_ioc_portid(port->ioc));
  293. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  294. return BFA_STATUS_OK;
  295. }
  296. /**
  297. * bfa_port_clear_stats()
  298. *
  299. *
  300. * @param[in] Pointer to the Port module data structure.
  301. *
  302. * @return Status
  303. */
  304. bfa_status_t
  305. bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
  306. void *cbarg)
  307. {
  308. struct bfi_port_generic_req_s *m;
  309. if (!bfa_ioc_is_operational(port->ioc)) {
  310. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  311. return BFA_STATUS_IOC_FAILURE;
  312. }
  313. if (port->stats_busy) {
  314. bfa_trc(port, BFA_STATUS_DEVBUSY);
  315. return BFA_STATUS_DEVBUSY;
  316. }
  317. m = (struct bfi_port_generic_req_s *)port->stats_mb.msg;
  318. port->stats_cbfn = cbfn;
  319. port->stats_cbarg = cbarg;
  320. port->stats_busy = BFA_TRUE;
  321. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
  322. bfa_ioc_portid(port->ioc));
  323. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  324. return BFA_STATUS_OK;
  325. }
  326. /**
  327. * bfa_port_hbfail()
  328. *
  329. *
  330. * @param[in] Pointer to the Port module data structure.
  331. *
  332. * @return void
  333. */
  334. void
  335. bfa_port_hbfail(void *arg)
  336. {
  337. struct bfa_port_s *port = (struct bfa_port_s *)arg;
  338. /*
  339. * Fail any pending get_stats/clear_stats requests
  340. */
  341. if (port->stats_busy) {
  342. if (port->stats_cbfn)
  343. port->stats_cbfn(port->dev, BFA_STATUS_FAILED);
  344. port->stats_cbfn = NULL;
  345. port->stats_busy = BFA_FALSE;
  346. }
  347. /*
  348. * Clear any enable/disable is pending
  349. */
  350. if (port->endis_pending) {
  351. if (port->endis_cbfn)
  352. port->endis_cbfn(port->dev, BFA_STATUS_FAILED);
  353. port->endis_cbfn = NULL;
  354. port->endis_pending = BFA_FALSE;
  355. }
  356. }
  357. /**
  358. * bfa_port_attach()
  359. *
  360. *
  361. * @param[in] port - Pointer to the Port module data structure
  362. * ioc - Pointer to the ioc module data structure
  363. * dev - Pointer to the device driver module data structure
  364. * The device driver specific mbox ISR functions have
  365. * this pointer as one of the parameters.
  366. * trcmod -
  367. * logmod -
  368. *
  369. * @return void
  370. */
  371. void
  372. bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc, void *dev,
  373. struct bfa_trc_mod_s *trcmod, struct bfa_log_mod_s *logmod)
  374. {
  375. bfa_assert(port);
  376. port->dev = dev;
  377. port->ioc = ioc;
  378. port->trcmod = trcmod;
  379. port->logmod = logmod;
  380. port->stats_busy = port->endis_pending = BFA_FALSE;
  381. port->stats_cbfn = port->endis_cbfn = NULL;
  382. bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
  383. bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port);
  384. bfa_ioc_hbfail_register(port->ioc, &port->hbfail);
  385. bfa_trc(port, 0);
  386. }
  387. /**
  388. * bfa_port_detach()
  389. *
  390. *
  391. * @param[in] port - Pointer to the Port module data structure
  392. *
  393. * @return void
  394. */
  395. void
  396. bfa_port_detach(struct bfa_port_s *port)
  397. {
  398. bfa_trc(port, 0);
  399. }