bfa_port.c 19 KB

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