bfa_port.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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 "bfad_drv.h"
  18. #include "bfa_defs_svc.h"
  19. #include "bfa_port.h"
  20. #include "bfi.h"
  21. #include "bfa_ioc.h"
  22. BFA_TRC_FILE(CNA, PORT);
  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. __be32 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 __BIG_ENDIAN
  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 timeval 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. do_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 timeval tv;
  114. port->stats_status = status;
  115. port->stats_busy = BFA_FALSE;
  116. /*
  117. * re-initialize time stamp for stats reset
  118. */
  119. do_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. WARN_ON(1);
  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 port is PBC disabled, return error */
  211. if (port->pbc_disabled) {
  212. bfa_trc(port, BFA_STATUS_PBC);
  213. return BFA_STATUS_PBC;
  214. }
  215. if (bfa_ioc_is_disabled(port->ioc)) {
  216. bfa_trc(port, BFA_STATUS_IOC_DISABLED);
  217. return BFA_STATUS_IOC_DISABLED;
  218. }
  219. if (!bfa_ioc_is_operational(port->ioc)) {
  220. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  221. return BFA_STATUS_IOC_FAILURE;
  222. }
  223. if (port->endis_pending) {
  224. bfa_trc(port, BFA_STATUS_DEVBUSY);
  225. return BFA_STATUS_DEVBUSY;
  226. }
  227. m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
  228. port->msgtag++;
  229. port->endis_cbfn = cbfn;
  230. port->endis_cbarg = cbarg;
  231. port->endis_pending = BFA_TRUE;
  232. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
  233. bfa_ioc_portid(port->ioc));
  234. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  235. return BFA_STATUS_OK;
  236. }
  237. /*
  238. * bfa_port_disable()
  239. *
  240. * Send the Port disable request to the f/w
  241. *
  242. * @param[in] Pointer to the Port module data structure.
  243. *
  244. * @return Status
  245. */
  246. bfa_status_t
  247. bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  248. void *cbarg)
  249. {
  250. struct bfi_port_generic_req_s *m;
  251. /* If port is PBC disabled, return error */
  252. if (port->pbc_disabled) {
  253. bfa_trc(port, BFA_STATUS_PBC);
  254. return BFA_STATUS_PBC;
  255. }
  256. if (bfa_ioc_is_disabled(port->ioc)) {
  257. bfa_trc(port, BFA_STATUS_IOC_DISABLED);
  258. return BFA_STATUS_IOC_DISABLED;
  259. }
  260. if (!bfa_ioc_is_operational(port->ioc)) {
  261. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  262. return BFA_STATUS_IOC_FAILURE;
  263. }
  264. if (port->endis_pending) {
  265. bfa_trc(port, BFA_STATUS_DEVBUSY);
  266. return BFA_STATUS_DEVBUSY;
  267. }
  268. m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
  269. port->msgtag++;
  270. port->endis_cbfn = cbfn;
  271. port->endis_cbarg = cbarg;
  272. port->endis_pending = BFA_TRUE;
  273. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
  274. bfa_ioc_portid(port->ioc));
  275. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  276. return BFA_STATUS_OK;
  277. }
  278. /*
  279. * bfa_port_get_stats()
  280. *
  281. * Send the request to the f/w to fetch Port statistics.
  282. *
  283. * @param[in] Pointer to the Port module data structure.
  284. *
  285. * @return Status
  286. */
  287. bfa_status_t
  288. bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
  289. bfa_port_stats_cbfn_t cbfn, void *cbarg)
  290. {
  291. struct bfi_port_get_stats_req_s *m;
  292. if (!bfa_ioc_is_operational(port->ioc)) {
  293. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  294. return BFA_STATUS_IOC_FAILURE;
  295. }
  296. if (port->stats_busy) {
  297. bfa_trc(port, BFA_STATUS_DEVBUSY);
  298. return BFA_STATUS_DEVBUSY;
  299. }
  300. m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg;
  301. port->stats = stats;
  302. port->stats_cbfn = cbfn;
  303. port->stats_cbarg = cbarg;
  304. port->stats_busy = BFA_TRUE;
  305. bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
  306. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
  307. bfa_ioc_portid(port->ioc));
  308. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  309. return BFA_STATUS_OK;
  310. }
  311. /*
  312. * bfa_port_clear_stats()
  313. *
  314. *
  315. * @param[in] Pointer to the Port module data structure.
  316. *
  317. * @return Status
  318. */
  319. bfa_status_t
  320. bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
  321. void *cbarg)
  322. {
  323. struct bfi_port_generic_req_s *m;
  324. if (!bfa_ioc_is_operational(port->ioc)) {
  325. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  326. return BFA_STATUS_IOC_FAILURE;
  327. }
  328. if (port->stats_busy) {
  329. bfa_trc(port, BFA_STATUS_DEVBUSY);
  330. return BFA_STATUS_DEVBUSY;
  331. }
  332. m = (struct bfi_port_generic_req_s *) port->stats_mb.msg;
  333. port->stats_cbfn = cbfn;
  334. port->stats_cbarg = cbarg;
  335. port->stats_busy = BFA_TRUE;
  336. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
  337. bfa_ioc_portid(port->ioc));
  338. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  339. return BFA_STATUS_OK;
  340. }
  341. /*
  342. * bfa_port_notify()
  343. *
  344. * Port module IOC event handler
  345. *
  346. * @param[in] Pointer to the Port module data structure.
  347. * @param[in] IOC event structure
  348. *
  349. * @return void
  350. */
  351. void
  352. bfa_port_notify(void *arg, enum bfa_ioc_event_e event)
  353. {
  354. struct bfa_port_s *port = (struct bfa_port_s *) arg;
  355. switch (event) {
  356. case BFA_IOC_E_DISABLED:
  357. case BFA_IOC_E_FAILED:
  358. /* Fail any pending get_stats/clear_stats requests */
  359. if (port->stats_busy) {
  360. if (port->stats_cbfn)
  361. port->stats_cbfn(port->stats_cbarg,
  362. BFA_STATUS_FAILED);
  363. port->stats_cbfn = NULL;
  364. port->stats_busy = BFA_FALSE;
  365. }
  366. /* Clear any enable/disable is pending */
  367. if (port->endis_pending) {
  368. if (port->endis_cbfn)
  369. port->endis_cbfn(port->endis_cbarg,
  370. BFA_STATUS_FAILED);
  371. port->endis_cbfn = NULL;
  372. port->endis_pending = BFA_FALSE;
  373. }
  374. break;
  375. default:
  376. break;
  377. }
  378. }
  379. /*
  380. * bfa_port_attach()
  381. *
  382. *
  383. * @param[in] port - Pointer to the Port module data structure
  384. * ioc - Pointer to the ioc module data structure
  385. * dev - Pointer to the device driver module data structure
  386. * The device driver specific mbox ISR functions have
  387. * this pointer as one of the parameters.
  388. * trcmod -
  389. *
  390. * @return void
  391. */
  392. void
  393. bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
  394. void *dev, struct bfa_trc_mod_s *trcmod)
  395. {
  396. struct timeval tv;
  397. WARN_ON(!port);
  398. port->dev = dev;
  399. port->ioc = ioc;
  400. port->trcmod = trcmod;
  401. port->stats_busy = BFA_FALSE;
  402. port->endis_pending = BFA_FALSE;
  403. port->stats_cbfn = NULL;
  404. port->endis_cbfn = NULL;
  405. port->pbc_disabled = BFA_FALSE;
  406. bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
  407. bfa_ioc_notify_init(&port->ioc_notify, bfa_port_notify, port);
  408. list_add_tail(&port->ioc_notify.qe, &port->ioc->notify_q);
  409. /*
  410. * initialize time stamp for stats reset
  411. */
  412. do_gettimeofday(&tv);
  413. port->stats_reset_time = tv.tv_sec;
  414. bfa_trc(port, 0);
  415. }