bfa_port.c 10 KB

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