bfa_port.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. /*
  2. * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
  3. * Copyright (c) 2014- QLogic Corporation.
  4. * All rights reserved
  5. * www.qlogic.com
  6. *
  7. * Linux driver for QLogic BR-series Fibre Channel Host Bus Adapter.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License (GPL) Version 2 as
  11. * published by the Free Software Foundation
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #include "bfad_drv.h"
  19. #include "bfa_defs_svc.h"
  20. #include "bfa_port.h"
  21. #include "bfi.h"
  22. #include "bfa_ioc.h"
  23. BFA_TRC_FILE(CNA, PORT);
  24. static void
  25. bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats)
  26. {
  27. u32 *dip = (u32 *) stats;
  28. __be32 t0, t1;
  29. int i;
  30. for (i = 0; i < sizeof(union bfa_port_stats_u)/sizeof(u32);
  31. i += 2) {
  32. t0 = dip[i];
  33. t1 = dip[i + 1];
  34. #ifdef __BIG_ENDIAN
  35. dip[i] = be32_to_cpu(t0);
  36. dip[i + 1] = be32_to_cpu(t1);
  37. #else
  38. dip[i] = be32_to_cpu(t1);
  39. dip[i + 1] = be32_to_cpu(t0);
  40. #endif
  41. }
  42. }
  43. /*
  44. * bfa_port_enable_isr()
  45. *
  46. *
  47. * @param[in] port - Pointer to the port module
  48. * status - Return status from the f/w
  49. *
  50. * @return void
  51. */
  52. static void
  53. bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
  54. {
  55. bfa_trc(port, status);
  56. port->endis_pending = BFA_FALSE;
  57. port->endis_cbfn(port->endis_cbarg, status);
  58. }
  59. /*
  60. * bfa_port_disable_isr()
  61. *
  62. *
  63. * @param[in] port - Pointer to the port module
  64. * status - Return status from the f/w
  65. *
  66. * @return void
  67. */
  68. static void
  69. bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
  70. {
  71. bfa_trc(port, status);
  72. port->endis_pending = BFA_FALSE;
  73. port->endis_cbfn(port->endis_cbarg, status);
  74. }
  75. /*
  76. * bfa_port_get_stats_isr()
  77. *
  78. *
  79. * @param[in] port - Pointer to the Port module
  80. * status - Return status from the f/w
  81. *
  82. * @return void
  83. */
  84. static void
  85. bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
  86. {
  87. port->stats_status = status;
  88. port->stats_busy = BFA_FALSE;
  89. if (status == BFA_STATUS_OK) {
  90. struct timeval tv;
  91. memcpy(port->stats, port->stats_dma.kva,
  92. sizeof(union bfa_port_stats_u));
  93. bfa_port_stats_swap(port, port->stats);
  94. do_gettimeofday(&tv);
  95. port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time;
  96. }
  97. if (port->stats_cbfn) {
  98. port->stats_cbfn(port->stats_cbarg, status);
  99. port->stats_cbfn = NULL;
  100. }
  101. }
  102. /*
  103. * bfa_port_clear_stats_isr()
  104. *
  105. *
  106. * @param[in] port - Pointer to the Port module
  107. * status - Return status from the f/w
  108. *
  109. * @return void
  110. */
  111. static void
  112. bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
  113. {
  114. struct timeval tv;
  115. port->stats_status = status;
  116. port->stats_busy = BFA_FALSE;
  117. /*
  118. * re-initialize time stamp for stats reset
  119. */
  120. do_gettimeofday(&tv);
  121. port->stats_reset_time = tv.tv_sec;
  122. if (port->stats_cbfn) {
  123. port->stats_cbfn(port->stats_cbarg, status);
  124. port->stats_cbfn = NULL;
  125. }
  126. }
  127. /*
  128. * bfa_port_isr()
  129. *
  130. *
  131. * @param[in] Pointer to the Port module data structure.
  132. *
  133. * @return void
  134. */
  135. static void
  136. bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
  137. {
  138. struct bfa_port_s *port = (struct bfa_port_s *) cbarg;
  139. union bfi_port_i2h_msg_u *i2hmsg;
  140. i2hmsg = (union bfi_port_i2h_msg_u *) m;
  141. bfa_trc(port, m->mh.msg_id);
  142. switch (m->mh.msg_id) {
  143. case BFI_PORT_I2H_ENABLE_RSP:
  144. if (port->endis_pending == BFA_FALSE)
  145. break;
  146. bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
  147. break;
  148. case BFI_PORT_I2H_DISABLE_RSP:
  149. if (port->endis_pending == BFA_FALSE)
  150. break;
  151. bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
  152. break;
  153. case BFI_PORT_I2H_GET_STATS_RSP:
  154. /* Stats busy flag is still set? (may be cmd timed out) */
  155. if (port->stats_busy == BFA_FALSE)
  156. break;
  157. bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
  158. break;
  159. case BFI_PORT_I2H_CLEAR_STATS_RSP:
  160. if (port->stats_busy == BFA_FALSE)
  161. break;
  162. bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
  163. break;
  164. default:
  165. WARN_ON(1);
  166. }
  167. }
  168. /*
  169. * bfa_port_meminfo()
  170. *
  171. *
  172. * @param[in] void
  173. *
  174. * @return Size of DMA region
  175. */
  176. u32
  177. bfa_port_meminfo(void)
  178. {
  179. return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ);
  180. }
  181. /*
  182. * bfa_port_mem_claim()
  183. *
  184. *
  185. * @param[in] port Port module pointer
  186. * dma_kva Kernel Virtual Address of Port DMA Memory
  187. * dma_pa Physical Address of Port DMA Memory
  188. *
  189. * @return void
  190. */
  191. void
  192. bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
  193. {
  194. port->stats_dma.kva = dma_kva;
  195. port->stats_dma.pa = dma_pa;
  196. }
  197. /*
  198. * bfa_port_enable()
  199. *
  200. * Send the Port enable request to the f/w
  201. *
  202. * @param[in] Pointer to the Port module data structure.
  203. *
  204. * @return Status
  205. */
  206. bfa_status_t
  207. bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  208. void *cbarg)
  209. {
  210. struct bfi_port_generic_req_s *m;
  211. /* If port is PBC disabled, return error */
  212. if (port->pbc_disabled) {
  213. bfa_trc(port, BFA_STATUS_PBC);
  214. return BFA_STATUS_PBC;
  215. }
  216. if (bfa_ioc_is_disabled(port->ioc)) {
  217. bfa_trc(port, BFA_STATUS_IOC_DISABLED);
  218. return BFA_STATUS_IOC_DISABLED;
  219. }
  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 is d-port enabled, return error */
  225. if (port->dport_enabled) {
  226. bfa_trc(port, BFA_STATUS_DPORT_ERR);
  227. return BFA_STATUS_DPORT_ERR;
  228. }
  229. if (port->endis_pending) {
  230. bfa_trc(port, BFA_STATUS_DEVBUSY);
  231. return BFA_STATUS_DEVBUSY;
  232. }
  233. m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
  234. port->msgtag++;
  235. port->endis_cbfn = cbfn;
  236. port->endis_cbarg = cbarg;
  237. port->endis_pending = BFA_TRUE;
  238. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
  239. bfa_ioc_portid(port->ioc));
  240. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  241. return BFA_STATUS_OK;
  242. }
  243. /*
  244. * bfa_port_disable()
  245. *
  246. * Send the Port disable request to the f/w
  247. *
  248. * @param[in] Pointer to the Port module data structure.
  249. *
  250. * @return Status
  251. */
  252. bfa_status_t
  253. bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
  254. void *cbarg)
  255. {
  256. struct bfi_port_generic_req_s *m;
  257. /* If port is PBC disabled, return error */
  258. if (port->pbc_disabled) {
  259. bfa_trc(port, BFA_STATUS_PBC);
  260. return BFA_STATUS_PBC;
  261. }
  262. if (bfa_ioc_is_disabled(port->ioc)) {
  263. bfa_trc(port, BFA_STATUS_IOC_DISABLED);
  264. return BFA_STATUS_IOC_DISABLED;
  265. }
  266. if (!bfa_ioc_is_operational(port->ioc)) {
  267. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  268. return BFA_STATUS_IOC_FAILURE;
  269. }
  270. /* if port is d-port enabled, return error */
  271. if (port->dport_enabled) {
  272. bfa_trc(port, BFA_STATUS_DPORT_ERR);
  273. return BFA_STATUS_DPORT_ERR;
  274. }
  275. if (port->endis_pending) {
  276. bfa_trc(port, BFA_STATUS_DEVBUSY);
  277. return BFA_STATUS_DEVBUSY;
  278. }
  279. m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
  280. port->msgtag++;
  281. port->endis_cbfn = cbfn;
  282. port->endis_cbarg = cbarg;
  283. port->endis_pending = BFA_TRUE;
  284. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
  285. bfa_ioc_portid(port->ioc));
  286. bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
  287. return BFA_STATUS_OK;
  288. }
  289. /*
  290. * bfa_port_get_stats()
  291. *
  292. * Send the request to the f/w to fetch Port statistics.
  293. *
  294. * @param[in] Pointer to the Port module data structure.
  295. *
  296. * @return Status
  297. */
  298. bfa_status_t
  299. bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
  300. bfa_port_stats_cbfn_t cbfn, void *cbarg)
  301. {
  302. struct bfi_port_get_stats_req_s *m;
  303. if (!bfa_ioc_is_operational(port->ioc)) {
  304. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  305. return BFA_STATUS_IOC_FAILURE;
  306. }
  307. if (port->stats_busy) {
  308. bfa_trc(port, BFA_STATUS_DEVBUSY);
  309. return BFA_STATUS_DEVBUSY;
  310. }
  311. m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg;
  312. port->stats = stats;
  313. port->stats_cbfn = cbfn;
  314. port->stats_cbarg = cbarg;
  315. port->stats_busy = BFA_TRUE;
  316. bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
  317. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
  318. bfa_ioc_portid(port->ioc));
  319. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  320. return BFA_STATUS_OK;
  321. }
  322. /*
  323. * bfa_port_clear_stats()
  324. *
  325. *
  326. * @param[in] Pointer to the Port module data structure.
  327. *
  328. * @return Status
  329. */
  330. bfa_status_t
  331. bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
  332. void *cbarg)
  333. {
  334. struct bfi_port_generic_req_s *m;
  335. if (!bfa_ioc_is_operational(port->ioc)) {
  336. bfa_trc(port, BFA_STATUS_IOC_FAILURE);
  337. return BFA_STATUS_IOC_FAILURE;
  338. }
  339. if (port->stats_busy) {
  340. bfa_trc(port, BFA_STATUS_DEVBUSY);
  341. return BFA_STATUS_DEVBUSY;
  342. }
  343. m = (struct bfi_port_generic_req_s *) port->stats_mb.msg;
  344. port->stats_cbfn = cbfn;
  345. port->stats_cbarg = cbarg;
  346. port->stats_busy = BFA_TRUE;
  347. bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
  348. bfa_ioc_portid(port->ioc));
  349. bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
  350. return BFA_STATUS_OK;
  351. }
  352. /*
  353. * bfa_port_notify()
  354. *
  355. * Port module IOC event handler
  356. *
  357. * @param[in] Pointer to the Port module data structure.
  358. * @param[in] IOC event structure
  359. *
  360. * @return void
  361. */
  362. void
  363. bfa_port_notify(void *arg, enum bfa_ioc_event_e event)
  364. {
  365. struct bfa_port_s *port = (struct bfa_port_s *) arg;
  366. switch (event) {
  367. case BFA_IOC_E_DISABLED:
  368. case BFA_IOC_E_FAILED:
  369. /* Fail any pending get_stats/clear_stats requests */
  370. if (port->stats_busy) {
  371. if (port->stats_cbfn)
  372. port->stats_cbfn(port->stats_cbarg,
  373. BFA_STATUS_FAILED);
  374. port->stats_cbfn = NULL;
  375. port->stats_busy = BFA_FALSE;
  376. }
  377. /* Clear any enable/disable is pending */
  378. if (port->endis_pending) {
  379. if (port->endis_cbfn)
  380. port->endis_cbfn(port->endis_cbarg,
  381. BFA_STATUS_FAILED);
  382. port->endis_cbfn = NULL;
  383. port->endis_pending = BFA_FALSE;
  384. }
  385. /* clear D-port mode */
  386. if (port->dport_enabled)
  387. bfa_port_set_dportenabled(port, BFA_FALSE);
  388. break;
  389. default:
  390. break;
  391. }
  392. }
  393. /*
  394. * bfa_port_attach()
  395. *
  396. *
  397. * @param[in] port - Pointer to the Port module data structure
  398. * ioc - Pointer to the ioc module data structure
  399. * dev - Pointer to the device driver module data structure
  400. * The device driver specific mbox ISR functions have
  401. * this pointer as one of the parameters.
  402. * trcmod -
  403. *
  404. * @return void
  405. */
  406. void
  407. bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
  408. void *dev, struct bfa_trc_mod_s *trcmod)
  409. {
  410. struct timeval tv;
  411. WARN_ON(!port);
  412. port->dev = dev;
  413. port->ioc = ioc;
  414. port->trcmod = trcmod;
  415. port->stats_busy = BFA_FALSE;
  416. port->endis_pending = BFA_FALSE;
  417. port->stats_cbfn = NULL;
  418. port->endis_cbfn = NULL;
  419. port->pbc_disabled = BFA_FALSE;
  420. port->dport_enabled = BFA_FALSE;
  421. bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
  422. bfa_q_qe_init(&port->ioc_notify);
  423. bfa_ioc_notify_init(&port->ioc_notify, bfa_port_notify, port);
  424. list_add_tail(&port->ioc_notify.qe, &port->ioc->notify_q);
  425. /*
  426. * initialize time stamp for stats reset
  427. */
  428. do_gettimeofday(&tv);
  429. port->stats_reset_time = tv.tv_sec;
  430. bfa_trc(port, 0);
  431. }
  432. /*
  433. * bfa_port_set_dportenabled();
  434. *
  435. * Port module- set pbc disabled flag
  436. *
  437. * @param[in] port - Pointer to the Port module data structure
  438. *
  439. * @return void
  440. */
  441. void
  442. bfa_port_set_dportenabled(struct bfa_port_s *port, bfa_boolean_t enabled)
  443. {
  444. port->dport_enabled = enabled;
  445. }
  446. /*
  447. * CEE module specific definitions
  448. */
  449. /*
  450. * bfa_cee_get_attr_isr()
  451. *
  452. * @brief CEE ISR for get-attributes responses from f/w
  453. *
  454. * @param[in] cee - Pointer to the CEE module
  455. * status - Return status from the f/w
  456. *
  457. * @return void
  458. */
  459. static void
  460. bfa_cee_get_attr_isr(struct bfa_cee_s *cee, bfa_status_t status)
  461. {
  462. struct bfa_cee_lldp_cfg_s *lldp_cfg = &cee->attr->lldp_remote;
  463. cee->get_attr_status = status;
  464. bfa_trc(cee, 0);
  465. if (status == BFA_STATUS_OK) {
  466. bfa_trc(cee, 0);
  467. memcpy(cee->attr, cee->attr_dma.kva,
  468. sizeof(struct bfa_cee_attr_s));
  469. lldp_cfg->time_to_live = be16_to_cpu(lldp_cfg->time_to_live);
  470. lldp_cfg->enabled_system_cap =
  471. be16_to_cpu(lldp_cfg->enabled_system_cap);
  472. }
  473. cee->get_attr_pending = BFA_FALSE;
  474. if (cee->cbfn.get_attr_cbfn) {
  475. bfa_trc(cee, 0);
  476. cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
  477. }
  478. }
  479. /*
  480. * bfa_cee_get_stats_isr()
  481. *
  482. * @brief CEE ISR for get-stats responses from f/w
  483. *
  484. * @param[in] cee - Pointer to the CEE module
  485. * status - Return status from the f/w
  486. *
  487. * @return void
  488. */
  489. static void
  490. bfa_cee_get_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
  491. {
  492. u32 *buffer;
  493. int i;
  494. cee->get_stats_status = status;
  495. bfa_trc(cee, 0);
  496. if (status == BFA_STATUS_OK) {
  497. bfa_trc(cee, 0);
  498. memcpy(cee->stats, cee->stats_dma.kva,
  499. sizeof(struct bfa_cee_stats_s));
  500. /* swap the cee stats */
  501. buffer = (u32 *)cee->stats;
  502. for (i = 0; i < (sizeof(struct bfa_cee_stats_s) /
  503. sizeof(u32)); i++)
  504. buffer[i] = cpu_to_be32(buffer[i]);
  505. }
  506. cee->get_stats_pending = BFA_FALSE;
  507. bfa_trc(cee, 0);
  508. if (cee->cbfn.get_stats_cbfn) {
  509. bfa_trc(cee, 0);
  510. cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
  511. }
  512. }
  513. /*
  514. * bfa_cee_reset_stats_isr()
  515. *
  516. * @brief CEE ISR for reset-stats responses from f/w
  517. *
  518. * @param[in] cee - Pointer to the CEE module
  519. * status - Return status from the f/w
  520. *
  521. * @return void
  522. */
  523. static void
  524. bfa_cee_reset_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
  525. {
  526. cee->reset_stats_status = status;
  527. cee->reset_stats_pending = BFA_FALSE;
  528. if (cee->cbfn.reset_stats_cbfn)
  529. cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
  530. }
  531. /*
  532. * bfa_cee_meminfo()
  533. *
  534. * @brief Returns the size of the DMA memory needed by CEE module
  535. *
  536. * @param[in] void
  537. *
  538. * @return Size of DMA region
  539. */
  540. u32
  541. bfa_cee_meminfo(void)
  542. {
  543. return BFA_ROUNDUP(sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ) +
  544. BFA_ROUNDUP(sizeof(struct bfa_cee_stats_s), BFA_DMA_ALIGN_SZ);
  545. }
  546. /*
  547. * bfa_cee_mem_claim()
  548. *
  549. * @brief Initialized CEE DMA Memory
  550. *
  551. * @param[in] cee CEE module pointer
  552. * dma_kva Kernel Virtual Address of CEE DMA Memory
  553. * dma_pa Physical Address of CEE DMA Memory
  554. *
  555. * @return void
  556. */
  557. void
  558. bfa_cee_mem_claim(struct bfa_cee_s *cee, u8 *dma_kva, u64 dma_pa)
  559. {
  560. cee->attr_dma.kva = dma_kva;
  561. cee->attr_dma.pa = dma_pa;
  562. cee->stats_dma.kva = dma_kva + BFA_ROUNDUP(
  563. sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
  564. cee->stats_dma.pa = dma_pa + BFA_ROUNDUP(
  565. sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
  566. cee->attr = (struct bfa_cee_attr_s *) dma_kva;
  567. cee->stats = (struct bfa_cee_stats_s *) (dma_kva + BFA_ROUNDUP(
  568. sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ));
  569. }
  570. /*
  571. * bfa_cee_get_attr()
  572. *
  573. * @brief
  574. * Send the request to the f/w to fetch CEE attributes.
  575. *
  576. * @param[in] Pointer to the CEE module data structure.
  577. *
  578. * @return Status
  579. */
  580. bfa_status_t
  581. bfa_cee_get_attr(struct bfa_cee_s *cee, struct bfa_cee_attr_s *attr,
  582. bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
  583. {
  584. struct bfi_cee_get_req_s *cmd;
  585. WARN_ON((cee == NULL) || (cee->ioc == NULL));
  586. bfa_trc(cee, 0);
  587. if (!bfa_ioc_is_operational(cee->ioc)) {
  588. bfa_trc(cee, 0);
  589. return BFA_STATUS_IOC_FAILURE;
  590. }
  591. if (cee->get_attr_pending == BFA_TRUE) {
  592. bfa_trc(cee, 0);
  593. return BFA_STATUS_DEVBUSY;
  594. }
  595. cee->get_attr_pending = BFA_TRUE;
  596. cmd = (struct bfi_cee_get_req_s *) cee->get_cfg_mb.msg;
  597. cee->attr = attr;
  598. cee->cbfn.get_attr_cbfn = cbfn;
  599. cee->cbfn.get_attr_cbarg = cbarg;
  600. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
  601. bfa_ioc_portid(cee->ioc));
  602. bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
  603. bfa_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb);
  604. return BFA_STATUS_OK;
  605. }
  606. /*
  607. * bfa_cee_get_stats()
  608. *
  609. * @brief
  610. * Send the request to the f/w to fetch CEE statistics.
  611. *
  612. * @param[in] Pointer to the CEE module data structure.
  613. *
  614. * @return Status
  615. */
  616. bfa_status_t
  617. bfa_cee_get_stats(struct bfa_cee_s *cee, struct bfa_cee_stats_s *stats,
  618. bfa_cee_get_stats_cbfn_t cbfn, void *cbarg)
  619. {
  620. struct bfi_cee_get_req_s *cmd;
  621. WARN_ON((cee == NULL) || (cee->ioc == NULL));
  622. if (!bfa_ioc_is_operational(cee->ioc)) {
  623. bfa_trc(cee, 0);
  624. return BFA_STATUS_IOC_FAILURE;
  625. }
  626. if (cee->get_stats_pending == BFA_TRUE) {
  627. bfa_trc(cee, 0);
  628. return BFA_STATUS_DEVBUSY;
  629. }
  630. cee->get_stats_pending = BFA_TRUE;
  631. cmd = (struct bfi_cee_get_req_s *) cee->get_stats_mb.msg;
  632. cee->stats = stats;
  633. cee->cbfn.get_stats_cbfn = cbfn;
  634. cee->cbfn.get_stats_cbarg = cbarg;
  635. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_STATS_REQ,
  636. bfa_ioc_portid(cee->ioc));
  637. bfa_dma_be_addr_set(cmd->dma_addr, cee->stats_dma.pa);
  638. bfa_ioc_mbox_queue(cee->ioc, &cee->get_stats_mb);
  639. return BFA_STATUS_OK;
  640. }
  641. /*
  642. * bfa_cee_reset_stats()
  643. *
  644. * @brief Clears CEE Stats in the f/w.
  645. *
  646. * @param[in] Pointer to the CEE module data structure.
  647. *
  648. * @return Status
  649. */
  650. bfa_status_t
  651. bfa_cee_reset_stats(struct bfa_cee_s *cee,
  652. bfa_cee_reset_stats_cbfn_t cbfn, void *cbarg)
  653. {
  654. struct bfi_cee_reset_stats_s *cmd;
  655. WARN_ON((cee == NULL) || (cee->ioc == NULL));
  656. if (!bfa_ioc_is_operational(cee->ioc)) {
  657. bfa_trc(cee, 0);
  658. return BFA_STATUS_IOC_FAILURE;
  659. }
  660. if (cee->reset_stats_pending == BFA_TRUE) {
  661. bfa_trc(cee, 0);
  662. return BFA_STATUS_DEVBUSY;
  663. }
  664. cee->reset_stats_pending = BFA_TRUE;
  665. cmd = (struct bfi_cee_reset_stats_s *) cee->reset_stats_mb.msg;
  666. cee->cbfn.reset_stats_cbfn = cbfn;
  667. cee->cbfn.reset_stats_cbarg = cbarg;
  668. bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_RESET_STATS,
  669. bfa_ioc_portid(cee->ioc));
  670. bfa_ioc_mbox_queue(cee->ioc, &cee->reset_stats_mb);
  671. return BFA_STATUS_OK;
  672. }
  673. /*
  674. * bfa_cee_isrs()
  675. *
  676. * @brief Handles Mail-box interrupts for CEE module.
  677. *
  678. * @param[in] Pointer to the CEE module data structure.
  679. *
  680. * @return void
  681. */
  682. void
  683. bfa_cee_isr(void *cbarg, struct bfi_mbmsg_s *m)
  684. {
  685. union bfi_cee_i2h_msg_u *msg;
  686. struct bfi_cee_get_rsp_s *get_rsp;
  687. struct bfa_cee_s *cee = (struct bfa_cee_s *) cbarg;
  688. msg = (union bfi_cee_i2h_msg_u *) m;
  689. get_rsp = (struct bfi_cee_get_rsp_s *) m;
  690. bfa_trc(cee, msg->mh.msg_id);
  691. switch (msg->mh.msg_id) {
  692. case BFI_CEE_I2H_GET_CFG_RSP:
  693. bfa_trc(cee, get_rsp->cmd_status);
  694. bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
  695. break;
  696. case BFI_CEE_I2H_GET_STATS_RSP:
  697. bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
  698. break;
  699. case BFI_CEE_I2H_RESET_STATS_RSP:
  700. bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
  701. break;
  702. default:
  703. WARN_ON(1);
  704. }
  705. }
  706. /*
  707. * bfa_cee_notify()
  708. *
  709. * @brief CEE module IOC event handler.
  710. *
  711. * @param[in] Pointer to the CEE module data structure.
  712. * @param[in] IOC event type
  713. *
  714. * @return void
  715. */
  716. void
  717. bfa_cee_notify(void *arg, enum bfa_ioc_event_e event)
  718. {
  719. struct bfa_cee_s *cee = (struct bfa_cee_s *) arg;
  720. bfa_trc(cee, event);
  721. switch (event) {
  722. case BFA_IOC_E_DISABLED:
  723. case BFA_IOC_E_FAILED:
  724. if (cee->get_attr_pending == BFA_TRUE) {
  725. cee->get_attr_status = BFA_STATUS_FAILED;
  726. cee->get_attr_pending = BFA_FALSE;
  727. if (cee->cbfn.get_attr_cbfn) {
  728. cee->cbfn.get_attr_cbfn(
  729. cee->cbfn.get_attr_cbarg,
  730. BFA_STATUS_FAILED);
  731. }
  732. }
  733. if (cee->get_stats_pending == BFA_TRUE) {
  734. cee->get_stats_status = BFA_STATUS_FAILED;
  735. cee->get_stats_pending = BFA_FALSE;
  736. if (cee->cbfn.get_stats_cbfn) {
  737. cee->cbfn.get_stats_cbfn(
  738. cee->cbfn.get_stats_cbarg,
  739. BFA_STATUS_FAILED);
  740. }
  741. }
  742. if (cee->reset_stats_pending == BFA_TRUE) {
  743. cee->reset_stats_status = BFA_STATUS_FAILED;
  744. cee->reset_stats_pending = BFA_FALSE;
  745. if (cee->cbfn.reset_stats_cbfn) {
  746. cee->cbfn.reset_stats_cbfn(
  747. cee->cbfn.reset_stats_cbarg,
  748. BFA_STATUS_FAILED);
  749. }
  750. }
  751. break;
  752. default:
  753. break;
  754. }
  755. }
  756. /*
  757. * bfa_cee_attach()
  758. *
  759. * @brief CEE module-attach API
  760. *
  761. * @param[in] cee - Pointer to the CEE module data structure
  762. * ioc - Pointer to the ioc module data structure
  763. * dev - Pointer to the device driver module data structure
  764. * The device driver specific mbox ISR functions have
  765. * this pointer as one of the parameters.
  766. *
  767. * @return void
  768. */
  769. void
  770. bfa_cee_attach(struct bfa_cee_s *cee, struct bfa_ioc_s *ioc,
  771. void *dev)
  772. {
  773. WARN_ON(cee == NULL);
  774. cee->dev = dev;
  775. cee->ioc = ioc;
  776. bfa_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
  777. bfa_q_qe_init(&cee->ioc_notify);
  778. bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
  779. list_add_tail(&cee->ioc_notify.qe, &cee->ioc->notify_q);
  780. }