bfa_port.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  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 is d-port enabled, return error */
  224. if (port->dport_enabled) {
  225. bfa_trc(port, BFA_STATUS_DPORT_ERR);
  226. return BFA_STATUS_DPORT_ERR;
  227. }
  228. if (port->endis_pending) {
  229. bfa_trc(port, BFA_STATUS_DEVBUSY);
  230. return BFA_STATUS_DEVBUSY;
  231. }
  232. m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
  233. port->msgtag++;
  234. port->endis_cbfn = cbfn;
  235. port->endis_cbarg = cbarg;
  236. port->endis_pending = BFA_TRUE;
  237. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
  238. bfa_ioc_portid(port->ioc));
  239. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  240. return BFA_STATUS_OK;
  241. }
  242. /*
  243. * bfa_port_disable()
  244. *
  245. * Send the Port disable request to the f/w
  246. *
  247. * @param[in] Pointer to the Port module data structure.
  248. *
  249. * @return Status
  250. */
  251. bfa_status_t
  252. bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  253. void *cbarg)
  254. {
  255. struct bfi_port_generic_req_s *m;
  256. /* If port is PBC disabled, return error */
  257. if (port->pbc_disabled) {
  258. bfa_trc(port, BFA_STATUS_PBC);
  259. return BFA_STATUS_PBC;
  260. }
  261. if (bfa_ioc_is_disabled(port->ioc)) {
  262. bfa_trc(port, BFA_STATUS_IOC_DISABLED);
  263. return BFA_STATUS_IOC_DISABLED;
  264. }
  265. if (!bfa_ioc_is_operational(port->ioc)) {
  266. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  267. return BFA_STATUS_IOC_FAILURE;
  268. }
  269. /* if port is d-port enabled, return error */
  270. if (port->dport_enabled) {
  271. bfa_trc(port, BFA_STATUS_DPORT_ERR);
  272. return BFA_STATUS_DPORT_ERR;
  273. }
  274. if (port->endis_pending) {
  275. bfa_trc(port, BFA_STATUS_DEVBUSY);
  276. return BFA_STATUS_DEVBUSY;
  277. }
  278. m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
  279. port->msgtag++;
  280. port->endis_cbfn = cbfn;
  281. port->endis_cbarg = cbarg;
  282. port->endis_pending = BFA_TRUE;
  283. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
  284. bfa_ioc_portid(port->ioc));
  285. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  286. return BFA_STATUS_OK;
  287. }
  288. /*
  289. * bfa_port_get_stats()
  290. *
  291. * Send the request to the f/w to fetch Port statistics.
  292. *
  293. * @param[in] Pointer to the Port module data structure.
  294. *
  295. * @return Status
  296. */
  297. bfa_status_t
  298. bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
  299. bfa_port_stats_cbfn_t cbfn, void *cbarg)
  300. {
  301. struct bfi_port_get_stats_req_s *m;
  302. if (!bfa_ioc_is_operational(port->ioc)) {
  303. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  304. return BFA_STATUS_IOC_FAILURE;
  305. }
  306. if (port->stats_busy) {
  307. bfa_trc(port, BFA_STATUS_DEVBUSY);
  308. return BFA_STATUS_DEVBUSY;
  309. }
  310. m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg;
  311. port->stats = stats;
  312. port->stats_cbfn = cbfn;
  313. port->stats_cbarg = cbarg;
  314. port->stats_busy = BFA_TRUE;
  315. bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
  316. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
  317. bfa_ioc_portid(port->ioc));
  318. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  319. return BFA_STATUS_OK;
  320. }
  321. /*
  322. * bfa_port_clear_stats()
  323. *
  324. *
  325. * @param[in] Pointer to the Port module data structure.
  326. *
  327. * @return Status
  328. */
  329. bfa_status_t
  330. bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
  331. void *cbarg)
  332. {
  333. struct bfi_port_generic_req_s *m;
  334. if (!bfa_ioc_is_operational(port->ioc)) {
  335. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  336. return BFA_STATUS_IOC_FAILURE;
  337. }
  338. if (port->stats_busy) {
  339. bfa_trc(port, BFA_STATUS_DEVBUSY);
  340. return BFA_STATUS_DEVBUSY;
  341. }
  342. m = (struct bfi_port_generic_req_s *) port->stats_mb.msg;
  343. port->stats_cbfn = cbfn;
  344. port->stats_cbarg = cbarg;
  345. port->stats_busy = BFA_TRUE;
  346. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
  347. bfa_ioc_portid(port->ioc));
  348. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  349. return BFA_STATUS_OK;
  350. }
  351. /*
  352. * bfa_port_notify()
  353. *
  354. * Port module IOC event handler
  355. *
  356. * @param[in] Pointer to the Port module data structure.
  357. * @param[in] IOC event structure
  358. *
  359. * @return void
  360. */
  361. void
  362. bfa_port_notify(void *arg, enum bfa_ioc_event_e event)
  363. {
  364. struct bfa_port_s *port = (struct bfa_port_s *) arg;
  365. switch (event) {
  366. case BFA_IOC_E_DISABLED:
  367. case BFA_IOC_E_FAILED:
  368. /* Fail any pending get_stats/clear_stats requests */
  369. if (port->stats_busy) {
  370. if (port->stats_cbfn)
  371. port->stats_cbfn(port->stats_cbarg,
  372. BFA_STATUS_FAILED);
  373. port->stats_cbfn = NULL;
  374. port->stats_busy = BFA_FALSE;
  375. }
  376. /* Clear any enable/disable is pending */
  377. if (port->endis_pending) {
  378. if (port->endis_cbfn)
  379. port->endis_cbfn(port->endis_cbarg,
  380. BFA_STATUS_FAILED);
  381. port->endis_cbfn = NULL;
  382. port->endis_pending = BFA_FALSE;
  383. }
  384. /* clear D-port mode */
  385. if (port->dport_enabled)
  386. bfa_port_set_dportenabled(port, BFA_FALSE);
  387. break;
  388. default:
  389. break;
  390. }
  391. }
  392. /*
  393. * bfa_port_attach()
  394. *
  395. *
  396. * @param[in] port - Pointer to the Port module data structure
  397. * ioc - Pointer to the ioc module data structure
  398. * dev - Pointer to the device driver module data structure
  399. * The device driver specific mbox ISR functions have
  400. * this pointer as one of the parameters.
  401. * trcmod -
  402. *
  403. * @return void
  404. */
  405. void
  406. bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
  407. void *dev, struct bfa_trc_mod_s *trcmod)
  408. {
  409. struct timeval tv;
  410. WARN_ON(!port);
  411. port->dev = dev;
  412. port->ioc = ioc;
  413. port->trcmod = trcmod;
  414. port->stats_busy = BFA_FALSE;
  415. port->endis_pending = BFA_FALSE;
  416. port->stats_cbfn = NULL;
  417. port->endis_cbfn = NULL;
  418. port->pbc_disabled = BFA_FALSE;
  419. port->dport_enabled = BFA_FALSE;
  420. bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
  421. bfa_q_qe_init(&port->ioc_notify);
  422. bfa_ioc_notify_init(&port->ioc_notify, bfa_port_notify, port);
  423. list_add_tail(&port->ioc_notify.qe, &port->ioc->notify_q);
  424. /*
  425. * initialize time stamp for stats reset
  426. */
  427. do_gettimeofday(&tv);
  428. port->stats_reset_time = tv.tv_sec;
  429. bfa_trc(port, 0);
  430. }
  431. /*
  432. * bfa_port_set_dportenabled();
  433. *
  434. * Port module- set pbc disabled flag
  435. *
  436. * @param[in] port - Pointer to the Port module data structure
  437. *
  438. * @return void
  439. */
  440. void
  441. bfa_port_set_dportenabled(struct bfa_port_s *port, bfa_boolean_t enabled)
  442. {
  443. port->dport_enabled = enabled;
  444. }
  445. /*
  446. * CEE module specific definitions
  447. */
  448. /*
  449. * bfa_cee_get_attr_isr()
  450. *
  451. * @brief CEE ISR for get-attributes responses from f/w
  452. *
  453. * @param[in] cee - Pointer to the CEE module
  454. * status - Return status from the f/w
  455. *
  456. * @return void
  457. */
  458. static void
  459. bfa_cee_get_attr_isr(struct bfa_cee_s *cee, bfa_status_t status)
  460. {
  461. struct bfa_cee_lldp_cfg_s *lldp_cfg = &cee->attr->lldp_remote;
  462. cee->get_attr_status = status;
  463. bfa_trc(cee, 0);
  464. if (status == BFA_STATUS_OK) {
  465. bfa_trc(cee, 0);
  466. memcpy(cee->attr, cee->attr_dma.kva,
  467. sizeof(struct bfa_cee_attr_s));
  468. lldp_cfg->time_to_live = be16_to_cpu(lldp_cfg->time_to_live);
  469. lldp_cfg->enabled_system_cap =
  470. be16_to_cpu(lldp_cfg->enabled_system_cap);
  471. }
  472. cee->get_attr_pending = BFA_FALSE;
  473. if (cee->cbfn.get_attr_cbfn) {
  474. bfa_trc(cee, 0);
  475. cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
  476. }
  477. }
  478. /*
  479. * bfa_cee_get_stats_isr()
  480. *
  481. * @brief CEE ISR for get-stats responses from f/w
  482. *
  483. * @param[in] cee - Pointer to the CEE module
  484. * status - Return status from the f/w
  485. *
  486. * @return void
  487. */
  488. static void
  489. bfa_cee_get_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
  490. {
  491. u32 *buffer;
  492. int i;
  493. cee->get_stats_status = status;
  494. bfa_trc(cee, 0);
  495. if (status == BFA_STATUS_OK) {
  496. bfa_trc(cee, 0);
  497. memcpy(cee->stats, cee->stats_dma.kva,
  498. sizeof(struct bfa_cee_stats_s));
  499. /* swap the cee stats */
  500. buffer = (u32 *)cee->stats;
  501. for (i = 0; i < (sizeof(struct bfa_cee_stats_s) /
  502. sizeof(u32)); i++)
  503. buffer[i] = cpu_to_be32(buffer[i]);
  504. }
  505. cee->get_stats_pending = BFA_FALSE;
  506. bfa_trc(cee, 0);
  507. if (cee->cbfn.get_stats_cbfn) {
  508. bfa_trc(cee, 0);
  509. cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
  510. }
  511. }
  512. /*
  513. * bfa_cee_reset_stats_isr()
  514. *
  515. * @brief CEE ISR for reset-stats responses from f/w
  516. *
  517. * @param[in] cee - Pointer to the CEE module
  518. * status - Return status from the f/w
  519. *
  520. * @return void
  521. */
  522. static void
  523. bfa_cee_reset_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
  524. {
  525. cee->reset_stats_status = status;
  526. cee->reset_stats_pending = BFA_FALSE;
  527. if (cee->cbfn.reset_stats_cbfn)
  528. cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
  529. }
  530. /*
  531. * bfa_cee_meminfo()
  532. *
  533. * @brief Returns the size of the DMA memory needed by CEE module
  534. *
  535. * @param[in] void
  536. *
  537. * @return Size of DMA region
  538. */
  539. u32
  540. bfa_cee_meminfo(void)
  541. {
  542. return BFA_ROUNDUP(sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ) +
  543. BFA_ROUNDUP(sizeof(struct bfa_cee_stats_s), BFA_DMA_ALIGN_SZ);
  544. }
  545. /*
  546. * bfa_cee_mem_claim()
  547. *
  548. * @brief Initialized CEE DMA Memory
  549. *
  550. * @param[in] cee CEE module pointer
  551. * dma_kva Kernel Virtual Address of CEE DMA Memory
  552. * dma_pa Physical Address of CEE DMA Memory
  553. *
  554. * @return void
  555. */
  556. void
  557. bfa_cee_mem_claim(struct bfa_cee_s *cee, u8 *dma_kva, u64 dma_pa)
  558. {
  559. cee->attr_dma.kva = dma_kva;
  560. cee->attr_dma.pa = dma_pa;
  561. cee->stats_dma.kva = dma_kva + BFA_ROUNDUP(
  562. sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
  563. cee->stats_dma.pa = dma_pa + BFA_ROUNDUP(
  564. sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
  565. cee->attr = (struct bfa_cee_attr_s *) dma_kva;
  566. cee->stats = (struct bfa_cee_stats_s *) (dma_kva + BFA_ROUNDUP(
  567. sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ));
  568. }
  569. /*
  570. * bfa_cee_get_attr()
  571. *
  572. * @brief
  573. * Send the request to the f/w to fetch CEE attributes.
  574. *
  575. * @param[in] Pointer to the CEE module data structure.
  576. *
  577. * @return Status
  578. */
  579. bfa_status_t
  580. bfa_cee_get_attr(struct bfa_cee_s *cee, struct bfa_cee_attr_s *attr,
  581. bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
  582. {
  583. struct bfi_cee_get_req_s *cmd;
  584. WARN_ON((cee == NULL) || (cee->ioc == NULL));
  585. bfa_trc(cee, 0);
  586. if (!bfa_ioc_is_operational(cee->ioc)) {
  587. bfa_trc(cee, 0);
  588. return BFA_STATUS_IOC_FAILURE;
  589. }
  590. if (cee->get_attr_pending == BFA_TRUE) {
  591. bfa_trc(cee, 0);
  592. return BFA_STATUS_DEVBUSY;
  593. }
  594. cee->get_attr_pending = BFA_TRUE;
  595. cmd = (struct bfi_cee_get_req_s *) cee->get_cfg_mb.msg;
  596. cee->attr = attr;
  597. cee->cbfn.get_attr_cbfn = cbfn;
  598. cee->cbfn.get_attr_cbarg = cbarg;
  599. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
  600. bfa_ioc_portid(cee->ioc));
  601. bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
  602. bfa_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb);
  603. return BFA_STATUS_OK;
  604. }
  605. /*
  606. * bfa_cee_get_stats()
  607. *
  608. * @brief
  609. * Send the request to the f/w to fetch CEE statistics.
  610. *
  611. * @param[in] Pointer to the CEE module data structure.
  612. *
  613. * @return Status
  614. */
  615. bfa_status_t
  616. bfa_cee_get_stats(struct bfa_cee_s *cee, struct bfa_cee_stats_s *stats,
  617. bfa_cee_get_stats_cbfn_t cbfn, void *cbarg)
  618. {
  619. struct bfi_cee_get_req_s *cmd;
  620. WARN_ON((cee == NULL) || (cee->ioc == NULL));
  621. if (!bfa_ioc_is_operational(cee->ioc)) {
  622. bfa_trc(cee, 0);
  623. return BFA_STATUS_IOC_FAILURE;
  624. }
  625. if (cee->get_stats_pending == BFA_TRUE) {
  626. bfa_trc(cee, 0);
  627. return BFA_STATUS_DEVBUSY;
  628. }
  629. cee->get_stats_pending = BFA_TRUE;
  630. cmd = (struct bfi_cee_get_req_s *) cee->get_stats_mb.msg;
  631. cee->stats = stats;
  632. cee->cbfn.get_stats_cbfn = cbfn;
  633. cee->cbfn.get_stats_cbarg = cbarg;
  634. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_STATS_REQ,
  635. bfa_ioc_portid(cee->ioc));
  636. bfa_dma_be_addr_set(cmd->dma_addr, cee->stats_dma.pa);
  637. bfa_ioc_mbox_queue(cee->ioc, &cee->get_stats_mb);
  638. return BFA_STATUS_OK;
  639. }
  640. /*
  641. * bfa_cee_reset_stats()
  642. *
  643. * @brief Clears CEE Stats in the f/w.
  644. *
  645. * @param[in] Pointer to the CEE module data structure.
  646. *
  647. * @return Status
  648. */
  649. bfa_status_t
  650. bfa_cee_reset_stats(struct bfa_cee_s *cee,
  651. bfa_cee_reset_stats_cbfn_t cbfn, void *cbarg)
  652. {
  653. struct bfi_cee_reset_stats_s *cmd;
  654. WARN_ON((cee == NULL) || (cee->ioc == NULL));
  655. if (!bfa_ioc_is_operational(cee->ioc)) {
  656. bfa_trc(cee, 0);
  657. return BFA_STATUS_IOC_FAILURE;
  658. }
  659. if (cee->reset_stats_pending == BFA_TRUE) {
  660. bfa_trc(cee, 0);
  661. return BFA_STATUS_DEVBUSY;
  662. }
  663. cee->reset_stats_pending = BFA_TRUE;
  664. cmd = (struct bfi_cee_reset_stats_s *) cee->reset_stats_mb.msg;
  665. cee->cbfn.reset_stats_cbfn = cbfn;
  666. cee->cbfn.reset_stats_cbarg = cbarg;
  667. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_RESET_STATS,
  668. bfa_ioc_portid(cee->ioc));
  669. bfa_ioc_mbox_queue(cee->ioc, &cee->reset_stats_mb);
  670. return BFA_STATUS_OK;
  671. }
  672. /*
  673. * bfa_cee_isrs()
  674. *
  675. * @brief Handles Mail-box interrupts for CEE module.
  676. *
  677. * @param[in] Pointer to the CEE module data structure.
  678. *
  679. * @return void
  680. */
  681. void
  682. bfa_cee_isr(void *cbarg, struct bfi_mbmsg_s *m)
  683. {
  684. union bfi_cee_i2h_msg_u *msg;
  685. struct bfi_cee_get_rsp_s *get_rsp;
  686. struct bfa_cee_s *cee = (struct bfa_cee_s *) cbarg;
  687. msg = (union bfi_cee_i2h_msg_u *) m;
  688. get_rsp = (struct bfi_cee_get_rsp_s *) m;
  689. bfa_trc(cee, msg->mh.msg_id);
  690. switch (msg->mh.msg_id) {
  691. case BFI_CEE_I2H_GET_CFG_RSP:
  692. bfa_trc(cee, get_rsp->cmd_status);
  693. bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
  694. break;
  695. case BFI_CEE_I2H_GET_STATS_RSP:
  696. bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
  697. break;
  698. case BFI_CEE_I2H_RESET_STATS_RSP:
  699. bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
  700. break;
  701. default:
  702. WARN_ON(1);
  703. }
  704. }
  705. /*
  706. * bfa_cee_notify()
  707. *
  708. * @brief CEE module IOC event handler.
  709. *
  710. * @param[in] Pointer to the CEE module data structure.
  711. * @param[in] IOC event type
  712. *
  713. * @return void
  714. */
  715. void
  716. bfa_cee_notify(void *arg, enum bfa_ioc_event_e event)
  717. {
  718. struct bfa_cee_s *cee = (struct bfa_cee_s *) arg;
  719. bfa_trc(cee, event);
  720. switch (event) {
  721. case BFA_IOC_E_DISABLED:
  722. case BFA_IOC_E_FAILED:
  723. if (cee->get_attr_pending == BFA_TRUE) {
  724. cee->get_attr_status = BFA_STATUS_FAILED;
  725. cee->get_attr_pending = BFA_FALSE;
  726. if (cee->cbfn.get_attr_cbfn) {
  727. cee->cbfn.get_attr_cbfn(
  728. cee->cbfn.get_attr_cbarg,
  729. BFA_STATUS_FAILED);
  730. }
  731. }
  732. if (cee->get_stats_pending == BFA_TRUE) {
  733. cee->get_stats_status = BFA_STATUS_FAILED;
  734. cee->get_stats_pending = BFA_FALSE;
  735. if (cee->cbfn.get_stats_cbfn) {
  736. cee->cbfn.get_stats_cbfn(
  737. cee->cbfn.get_stats_cbarg,
  738. BFA_STATUS_FAILED);
  739. }
  740. }
  741. if (cee->reset_stats_pending == BFA_TRUE) {
  742. cee->reset_stats_status = BFA_STATUS_FAILED;
  743. cee->reset_stats_pending = BFA_FALSE;
  744. if (cee->cbfn.reset_stats_cbfn) {
  745. cee->cbfn.reset_stats_cbfn(
  746. cee->cbfn.reset_stats_cbarg,
  747. BFA_STATUS_FAILED);
  748. }
  749. }
  750. break;
  751. default:
  752. break;
  753. }
  754. }
  755. /*
  756. * bfa_cee_attach()
  757. *
  758. * @brief CEE module-attach API
  759. *
  760. * @param[in] cee - Pointer to the CEE module data structure
  761. * ioc - Pointer to the ioc module data structure
  762. * dev - Pointer to the device driver module data structure
  763. * The device driver specific mbox ISR functions have
  764. * this pointer as one of the parameters.
  765. *
  766. * @return void
  767. */
  768. void
  769. bfa_cee_attach(struct bfa_cee_s *cee, struct bfa_ioc_s *ioc,
  770. void *dev)
  771. {
  772. WARN_ON(cee == NULL);
  773. cee->dev = dev;
  774. cee->ioc = ioc;
  775. bfa_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
  776. bfa_q_qe_init(&cee->ioc_notify);
  777. bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
  778. list_add_tail(&cee->ioc_notify.qe, &cee->ioc->notify_q);
  779. }