bfa_port.c 20 KB

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