bfa_port.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. struct bfa_timeval_s tv;
  96. memcpy(port->stats, port->stats_dma.kva,
  97. sizeof(union bfa_pport_stats_u));
  98. bfa_port_stats_swap(port, port->stats);
  99. bfa_os_gettimeofday(&tv);
  100. port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time;
  101. }
  102. if (port->stats_cbfn) {
  103. port->stats_cbfn(port->stats_cbarg, status);
  104. port->stats_cbfn = NULL;
  105. }
  106. }
  107. /**
  108. * bfa_port_clear_stats_isr()
  109. *
  110. *
  111. * @param[in] port - Pointer to the Port module
  112. * status - Return status from the f/w
  113. *
  114. * @return void
  115. */
  116. static void
  117. bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
  118. {
  119. struct bfa_timeval_s tv;
  120. port->stats_status = status;
  121. port->stats_busy = BFA_FALSE;
  122. /**
  123. * re-initialize time stamp for stats reset
  124. */
  125. bfa_os_gettimeofday(&tv);
  126. port->stats_reset_time = tv.tv_sec;
  127. if (port->stats_cbfn) {
  128. port->stats_cbfn(port->stats_cbarg, status);
  129. port->stats_cbfn = NULL;
  130. }
  131. }
  132. /**
  133. * bfa_port_isr()
  134. *
  135. *
  136. * @param[in] Pointer to the Port module data structure.
  137. *
  138. * @return void
  139. */
  140. static void
  141. bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
  142. {
  143. struct bfa_port_s *port = (struct bfa_port_s *)cbarg;
  144. union bfi_port_i2h_msg_u *i2hmsg;
  145. i2hmsg = (union bfi_port_i2h_msg_u *)m;
  146. bfa_trc(port, m->mh.msg_id);
  147. switch (m->mh.msg_id) {
  148. case BFI_PORT_I2H_ENABLE_RSP:
  149. if (port->endis_pending == BFA_FALSE)
  150. break;
  151. bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
  152. break;
  153. case BFI_PORT_I2H_DISABLE_RSP:
  154. if (port->endis_pending == BFA_FALSE)
  155. break;
  156. bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
  157. break;
  158. case BFI_PORT_I2H_GET_STATS_RSP:
  159. /*
  160. * Stats busy flag is still set? (may be cmd timed out)
  161. */
  162. if (port->stats_busy == BFA_FALSE)
  163. break;
  164. bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
  165. break;
  166. case BFI_PORT_I2H_CLEAR_STATS_RSP:
  167. if (port->stats_busy == BFA_FALSE)
  168. break;
  169. bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
  170. break;
  171. default:
  172. bfa_assert(0);
  173. }
  174. }
  175. /**
  176. * bfa_port_meminfo()
  177. *
  178. *
  179. * @param[in] void
  180. *
  181. * @return Size of DMA region
  182. */
  183. u32
  184. bfa_port_meminfo(void)
  185. {
  186. return BFA_ROUNDUP(sizeof(union bfa_pport_stats_u), BFA_DMA_ALIGN_SZ);
  187. }
  188. /**
  189. * bfa_port_mem_claim()
  190. *
  191. *
  192. * @param[in] port Port module pointer
  193. * dma_kva Kernel Virtual Address of Port DMA Memory
  194. * dma_pa Physical Address of Port DMA Memory
  195. *
  196. * @return void
  197. */
  198. void
  199. bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
  200. {
  201. port->stats_dma.kva = dma_kva;
  202. port->stats_dma.pa = dma_pa;
  203. }
  204. /**
  205. * bfa_port_enable()
  206. *
  207. * Send the Port enable request to the f/w
  208. *
  209. * @param[in] Pointer to the Port module data structure.
  210. *
  211. * @return Status
  212. */
  213. bfa_status_t
  214. bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  215. void *cbarg)
  216. {
  217. struct bfi_port_generic_req_s *m;
  218. /** todo Not implemented */
  219. bfa_assert(0);
  220. if (!bfa_ioc_is_operational(port->ioc)) {
  221. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  222. return BFA_STATUS_IOC_FAILURE;
  223. }
  224. if (port->endis_pending) {
  225. bfa_trc(port, BFA_STATUS_DEVBUSY);
  226. return BFA_STATUS_DEVBUSY;
  227. }
  228. m = (struct bfi_port_generic_req_s *)port->endis_mb.msg;
  229. port->msgtag++;
  230. port->endis_cbfn = cbfn;
  231. port->endis_cbarg = cbarg;
  232. port->endis_pending = BFA_TRUE;
  233. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
  234. bfa_ioc_portid(port->ioc));
  235. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  236. return BFA_STATUS_OK;
  237. }
  238. /**
  239. * bfa_port_disable()
  240. *
  241. * Send the Port disable request to the f/w
  242. *
  243. * @param[in] Pointer to the Port module data structure.
  244. *
  245. * @return Status
  246. */
  247. bfa_status_t
  248. bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  249. void *cbarg)
  250. {
  251. struct bfi_port_generic_req_s *m;
  252. /** todo Not implemented */
  253. bfa_assert(0);
  254. if (!bfa_ioc_is_operational(port->ioc)) {
  255. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  256. return BFA_STATUS_IOC_FAILURE;
  257. }
  258. if (port->endis_pending) {
  259. bfa_trc(port, BFA_STATUS_DEVBUSY);
  260. return BFA_STATUS_DEVBUSY;
  261. }
  262. m = (struct bfi_port_generic_req_s *)port->endis_mb.msg;
  263. port->msgtag++;
  264. port->endis_cbfn = cbfn;
  265. port->endis_cbarg = cbarg;
  266. port->endis_pending = BFA_TRUE;
  267. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
  268. bfa_ioc_portid(port->ioc));
  269. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  270. return BFA_STATUS_OK;
  271. }
  272. /**
  273. * bfa_port_get_stats()
  274. *
  275. * Send the request to the f/w to fetch Port statistics.
  276. *
  277. * @param[in] Pointer to the Port module data structure.
  278. *
  279. * @return Status
  280. */
  281. bfa_status_t
  282. bfa_port_get_stats(struct bfa_port_s *port, union bfa_pport_stats_u *stats,
  283. bfa_port_stats_cbfn_t cbfn, void *cbarg)
  284. {
  285. struct bfi_port_get_stats_req_s *m;
  286. if (!bfa_ioc_is_operational(port->ioc)) {
  287. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  288. return BFA_STATUS_IOC_FAILURE;
  289. }
  290. if (port->stats_busy) {
  291. bfa_trc(port, BFA_STATUS_DEVBUSY);
  292. return BFA_STATUS_DEVBUSY;
  293. }
  294. m = (struct bfi_port_get_stats_req_s *)port->stats_mb.msg;
  295. port->stats = stats;
  296. port->stats_cbfn = cbfn;
  297. port->stats_cbarg = cbarg;
  298. port->stats_busy = BFA_TRUE;
  299. bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
  300. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
  301. bfa_ioc_portid(port->ioc));
  302. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  303. return BFA_STATUS_OK;
  304. }
  305. /**
  306. * bfa_port_clear_stats()
  307. *
  308. *
  309. * @param[in] Pointer to the Port module data structure.
  310. *
  311. * @return Status
  312. */
  313. bfa_status_t
  314. bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
  315. void *cbarg)
  316. {
  317. struct bfi_port_generic_req_s *m;
  318. if (!bfa_ioc_is_operational(port->ioc)) {
  319. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  320. return BFA_STATUS_IOC_FAILURE;
  321. }
  322. if (port->stats_busy) {
  323. bfa_trc(port, BFA_STATUS_DEVBUSY);
  324. return BFA_STATUS_DEVBUSY;
  325. }
  326. m = (struct bfi_port_generic_req_s *)port->stats_mb.msg;
  327. port->stats_cbfn = cbfn;
  328. port->stats_cbarg = cbarg;
  329. port->stats_busy = BFA_TRUE;
  330. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
  331. bfa_ioc_portid(port->ioc));
  332. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  333. return BFA_STATUS_OK;
  334. }
  335. /**
  336. * bfa_port_hbfail()
  337. *
  338. *
  339. * @param[in] Pointer to the Port module data structure.
  340. *
  341. * @return void
  342. */
  343. void
  344. bfa_port_hbfail(void *arg)
  345. {
  346. struct bfa_port_s *port = (struct bfa_port_s *)arg;
  347. /*
  348. * Fail any pending get_stats/clear_stats requests
  349. */
  350. if (port->stats_busy) {
  351. if (port->stats_cbfn)
  352. port->stats_cbfn(port->stats_cbarg, BFA_STATUS_FAILED);
  353. port->stats_cbfn = NULL;
  354. port->stats_busy = BFA_FALSE;
  355. }
  356. /*
  357. * Clear any enable/disable is pending
  358. */
  359. if (port->endis_pending) {
  360. if (port->endis_cbfn)
  361. port->endis_cbfn(port->endis_cbarg, BFA_STATUS_FAILED);
  362. port->endis_cbfn = NULL;
  363. port->endis_pending = BFA_FALSE;
  364. }
  365. }
  366. /**
  367. * bfa_port_attach()
  368. *
  369. *
  370. * @param[in] port - Pointer to the Port module data structure
  371. * ioc - Pointer to the ioc module data structure
  372. * dev - Pointer to the device driver module data structure
  373. * The device driver specific mbox ISR functions have
  374. * this pointer as one of the parameters.
  375. * trcmod -
  376. * logmod -
  377. *
  378. * @return void
  379. */
  380. void
  381. bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc, void *dev,
  382. struct bfa_trc_mod_s *trcmod, struct bfa_log_mod_s *logmod)
  383. {
  384. struct bfa_timeval_s tv;
  385. bfa_assert(port);
  386. port->dev = dev;
  387. port->ioc = ioc;
  388. port->trcmod = trcmod;
  389. port->logmod = logmod;
  390. port->stats_busy = BFA_FALSE;
  391. port->endis_pending = BFA_FALSE;
  392. port->stats_cbfn = NULL;
  393. port->endis_cbfn = NULL;
  394. bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
  395. bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port);
  396. bfa_ioc_hbfail_register(port->ioc, &port->hbfail);
  397. /**
  398. * initialize time stamp for stats reset
  399. */
  400. bfa_os_gettimeofday(&tv);
  401. port->stats_reset_time = tv.tv_sec;
  402. bfa_trc(port, 0);
  403. }
  404. /**
  405. * bfa_port_detach()
  406. *
  407. *
  408. * @param[in] port - Pointer to the Port module data structure
  409. *
  410. * @return void
  411. */
  412. void
  413. bfa_port_detach(struct bfa_port_s *port)
  414. {
  415. bfa_trc(port, 0);
  416. }