fdmi.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. /*
  2. * Copyright (c) 2005-2009 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. /**
  18. * port_api.c BFA FCS port
  19. */
  20. #include <bfa.h>
  21. #include <bfa_svc.h>
  22. #include "fcs_lport.h"
  23. #include "fcs_rport.h"
  24. #include "lport_priv.h"
  25. #include "fcs_trcmod.h"
  26. #include "fcs_fcxp.h"
  27. #include <fcs/bfa_fcs_fdmi.h>
  28. BFA_TRC_FILE(FCS, FDMI);
  29. #define BFA_FCS_FDMI_CMD_MAX_RETRIES 2
  30. /*
  31. * forward declarations
  32. */
  33. static void bfa_fcs_port_fdmi_send_rhba(void *fdmi_cbarg,
  34. struct bfa_fcxp_s *fcxp_alloced);
  35. static void bfa_fcs_port_fdmi_send_rprt(void *fdmi_cbarg,
  36. struct bfa_fcxp_s *fcxp_alloced);
  37. static void bfa_fcs_port_fdmi_send_rpa(void *fdmi_cbarg,
  38. struct bfa_fcxp_s *fcxp_alloced);
  39. static void bfa_fcs_port_fdmi_rhba_response(void *fcsarg,
  40. struct bfa_fcxp_s *fcxp,
  41. void *cbarg,
  42. bfa_status_t req_status,
  43. u32 rsp_len,
  44. u32 resid_len,
  45. struct fchs_s *rsp_fchs);
  46. static void bfa_fcs_port_fdmi_rprt_response(void *fcsarg,
  47. struct bfa_fcxp_s *fcxp,
  48. void *cbarg,
  49. bfa_status_t req_status,
  50. u32 rsp_len,
  51. u32 resid_len,
  52. struct fchs_s *rsp_fchs);
  53. static void bfa_fcs_port_fdmi_rpa_response(void *fcsarg,
  54. struct bfa_fcxp_s *fcxp,
  55. void *cbarg,
  56. bfa_status_t req_status,
  57. u32 rsp_len,
  58. u32 resid_len,
  59. struct fchs_s *rsp_fchs);
  60. static void bfa_fcs_port_fdmi_timeout(void *arg);
  61. static u16 bfa_fcs_port_fdmi_build_rhba_pyld(
  62. struct bfa_fcs_port_fdmi_s *fdmi, u8 *pyld);
  63. static u16 bfa_fcs_port_fdmi_build_rprt_pyld(
  64. struct bfa_fcs_port_fdmi_s *fdmi, u8 *pyld);
  65. static u16 bfa_fcs_port_fdmi_build_rpa_pyld(
  66. struct bfa_fcs_port_fdmi_s *fdmi, u8 *pyld);
  67. static u16 bfa_fcs_port_fdmi_build_portattr_block(
  68. struct bfa_fcs_port_fdmi_s *fdmi, u8 *pyld);
  69. static void bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_port_fdmi_s *fdmi,
  70. struct bfa_fcs_fdmi_hba_attr_s *hba_attr);
  71. static void bfa_fcs_fdmi_get_portattr(struct bfa_fcs_port_fdmi_s *fdmi,
  72. struct bfa_fcs_fdmi_port_attr_s *port_attr);
  73. /**
  74. * fcs_fdmi_sm FCS FDMI state machine
  75. */
  76. /**
  77. * FDMI State Machine events
  78. */
  79. enum port_fdmi_event {
  80. FDMISM_EVENT_PORT_ONLINE = 1,
  81. FDMISM_EVENT_PORT_OFFLINE = 2,
  82. FDMISM_EVENT_RSP_OK = 4,
  83. FDMISM_EVENT_RSP_ERROR = 5,
  84. FDMISM_EVENT_TIMEOUT = 6,
  85. FDMISM_EVENT_RHBA_SENT = 7,
  86. FDMISM_EVENT_RPRT_SENT = 8,
  87. FDMISM_EVENT_RPA_SENT = 9,
  88. };
  89. static void bfa_fcs_port_fdmi_sm_offline(struct bfa_fcs_port_fdmi_s *fdmi,
  90. enum port_fdmi_event event);
  91. static void bfa_fcs_port_fdmi_sm_sending_rhba(struct bfa_fcs_port_fdmi_s *fdmi,
  92. enum port_fdmi_event event);
  93. static void bfa_fcs_port_fdmi_sm_rhba(struct bfa_fcs_port_fdmi_s *fdmi,
  94. enum port_fdmi_event event);
  95. static void bfa_fcs_port_fdmi_sm_rhba_retry(struct bfa_fcs_port_fdmi_s *fdmi,
  96. enum port_fdmi_event event);
  97. static void bfa_fcs_port_fdmi_sm_sending_rprt(struct bfa_fcs_port_fdmi_s *fdmi,
  98. enum port_fdmi_event event);
  99. static void bfa_fcs_port_fdmi_sm_rprt(struct bfa_fcs_port_fdmi_s *fdmi,
  100. enum port_fdmi_event event);
  101. static void bfa_fcs_port_fdmi_sm_rprt_retry(struct bfa_fcs_port_fdmi_s *fdmi,
  102. enum port_fdmi_event event);
  103. static void bfa_fcs_port_fdmi_sm_sending_rpa(struct bfa_fcs_port_fdmi_s *fdmi,
  104. enum port_fdmi_event event);
  105. static void bfa_fcs_port_fdmi_sm_rpa(struct bfa_fcs_port_fdmi_s *fdmi,
  106. enum port_fdmi_event event);
  107. static void bfa_fcs_port_fdmi_sm_rpa_retry(struct bfa_fcs_port_fdmi_s *fdmi,
  108. enum port_fdmi_event event);
  109. static void bfa_fcs_port_fdmi_sm_online(struct bfa_fcs_port_fdmi_s *fdmi,
  110. enum port_fdmi_event event);
  111. static void bfa_fcs_port_fdmi_sm_disabled(struct bfa_fcs_port_fdmi_s *fdmi,
  112. enum port_fdmi_event event);
  113. /**
  114. * Start in offline state - awaiting MS to send start.
  115. */
  116. static void
  117. bfa_fcs_port_fdmi_sm_offline(struct bfa_fcs_port_fdmi_s *fdmi,
  118. enum port_fdmi_event event)
  119. {
  120. struct bfa_fcs_port_s *port = fdmi->ms->port;
  121. bfa_trc(port->fcs, port->port_cfg.pwwn);
  122. bfa_trc(port->fcs, event);
  123. fdmi->retry_cnt = 0;
  124. switch (event) {
  125. case FDMISM_EVENT_PORT_ONLINE:
  126. if (port->vport) {
  127. /*
  128. * For Vports, register a new port.
  129. */
  130. bfa_sm_set_state(fdmi,
  131. bfa_fcs_port_fdmi_sm_sending_rprt);
  132. bfa_fcs_port_fdmi_send_rprt(fdmi, NULL);
  133. } else {
  134. /*
  135. * For a base port, we should first register the HBA
  136. * atribute. The HBA attribute also contains the base
  137. * port registration.
  138. */
  139. bfa_sm_set_state(fdmi,
  140. bfa_fcs_port_fdmi_sm_sending_rhba);
  141. bfa_fcs_port_fdmi_send_rhba(fdmi, NULL);
  142. }
  143. break;
  144. case FDMISM_EVENT_PORT_OFFLINE:
  145. break;
  146. default:
  147. bfa_assert(0);
  148. }
  149. }
  150. static void
  151. bfa_fcs_port_fdmi_sm_sending_rhba(struct bfa_fcs_port_fdmi_s *fdmi,
  152. enum port_fdmi_event event)
  153. {
  154. struct bfa_fcs_port_s *port = fdmi->ms->port;
  155. bfa_trc(port->fcs, port->port_cfg.pwwn);
  156. bfa_trc(port->fcs, event);
  157. switch (event) {
  158. case FDMISM_EVENT_RHBA_SENT:
  159. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_rhba);
  160. break;
  161. case FDMISM_EVENT_PORT_OFFLINE:
  162. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  163. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
  164. &fdmi->fcxp_wqe);
  165. break;
  166. default:
  167. bfa_assert(0);
  168. }
  169. }
  170. static void
  171. bfa_fcs_port_fdmi_sm_rhba(struct bfa_fcs_port_fdmi_s *fdmi,
  172. enum port_fdmi_event event)
  173. {
  174. struct bfa_fcs_port_s *port = fdmi->ms->port;
  175. bfa_trc(port->fcs, port->port_cfg.pwwn);
  176. bfa_trc(port->fcs, event);
  177. switch (event) {
  178. case FDMISM_EVENT_RSP_ERROR:
  179. /*
  180. * if max retries have not been reached, start timer for a
  181. * delayed retry
  182. */
  183. if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
  184. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_rhba_retry);
  185. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
  186. &fdmi->timer, bfa_fcs_port_fdmi_timeout,
  187. fdmi, BFA_FCS_RETRY_TIMEOUT);
  188. } else {
  189. /*
  190. * set state to offline
  191. */
  192. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  193. }
  194. break;
  195. case FDMISM_EVENT_RSP_OK:
  196. /*
  197. * Initiate Register Port Attributes
  198. */
  199. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_sending_rpa);
  200. fdmi->retry_cnt = 0;
  201. bfa_fcs_port_fdmi_send_rpa(fdmi, NULL);
  202. break;
  203. case FDMISM_EVENT_PORT_OFFLINE:
  204. bfa_fcxp_discard(fdmi->fcxp);
  205. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  206. break;
  207. default:
  208. bfa_assert(0);
  209. }
  210. }
  211. static void
  212. bfa_fcs_port_fdmi_sm_rhba_retry(struct bfa_fcs_port_fdmi_s *fdmi,
  213. enum port_fdmi_event event)
  214. {
  215. struct bfa_fcs_port_s *port = fdmi->ms->port;
  216. bfa_trc(port->fcs, port->port_cfg.pwwn);
  217. bfa_trc(port->fcs, event);
  218. switch (event) {
  219. case FDMISM_EVENT_TIMEOUT:
  220. /*
  221. * Retry Timer Expired. Re-send
  222. */
  223. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_sending_rhba);
  224. bfa_fcs_port_fdmi_send_rhba(fdmi, NULL);
  225. break;
  226. case FDMISM_EVENT_PORT_OFFLINE:
  227. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  228. bfa_timer_stop(&fdmi->timer);
  229. break;
  230. default:
  231. bfa_assert(0);
  232. }
  233. }
  234. /*
  235. * RPRT : Register Port
  236. */
  237. static void
  238. bfa_fcs_port_fdmi_sm_sending_rprt(struct bfa_fcs_port_fdmi_s *fdmi,
  239. enum port_fdmi_event event)
  240. {
  241. struct bfa_fcs_port_s *port = fdmi->ms->port;
  242. bfa_trc(port->fcs, port->port_cfg.pwwn);
  243. bfa_trc(port->fcs, event);
  244. switch (event) {
  245. case FDMISM_EVENT_RPRT_SENT:
  246. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_rprt);
  247. break;
  248. case FDMISM_EVENT_PORT_OFFLINE:
  249. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  250. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
  251. &fdmi->fcxp_wqe);
  252. break;
  253. default:
  254. bfa_assert(0);
  255. }
  256. }
  257. static void
  258. bfa_fcs_port_fdmi_sm_rprt(struct bfa_fcs_port_fdmi_s *fdmi,
  259. enum port_fdmi_event event)
  260. {
  261. struct bfa_fcs_port_s *port = fdmi->ms->port;
  262. bfa_trc(port->fcs, port->port_cfg.pwwn);
  263. bfa_trc(port->fcs, event);
  264. switch (event) {
  265. case FDMISM_EVENT_RSP_ERROR:
  266. /*
  267. * if max retries have not been reached, start timer for a
  268. * delayed retry
  269. */
  270. if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
  271. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_rprt_retry);
  272. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
  273. &fdmi->timer, bfa_fcs_port_fdmi_timeout,
  274. fdmi, BFA_FCS_RETRY_TIMEOUT);
  275. } else {
  276. /*
  277. * set state to offline
  278. */
  279. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  280. fdmi->retry_cnt = 0;
  281. }
  282. break;
  283. case FDMISM_EVENT_RSP_OK:
  284. fdmi->retry_cnt = 0;
  285. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_online);
  286. break;
  287. case FDMISM_EVENT_PORT_OFFLINE:
  288. bfa_fcxp_discard(fdmi->fcxp);
  289. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  290. break;
  291. default:
  292. bfa_assert(0);
  293. }
  294. }
  295. static void
  296. bfa_fcs_port_fdmi_sm_rprt_retry(struct bfa_fcs_port_fdmi_s *fdmi,
  297. enum port_fdmi_event event)
  298. {
  299. struct bfa_fcs_port_s *port = fdmi->ms->port;
  300. bfa_trc(port->fcs, port->port_cfg.pwwn);
  301. bfa_trc(port->fcs, event);
  302. switch (event) {
  303. case FDMISM_EVENT_TIMEOUT:
  304. /*
  305. * Retry Timer Expired. Re-send
  306. */
  307. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_sending_rprt);
  308. bfa_fcs_port_fdmi_send_rprt(fdmi, NULL);
  309. break;
  310. case FDMISM_EVENT_PORT_OFFLINE:
  311. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  312. bfa_timer_stop(&fdmi->timer);
  313. break;
  314. default:
  315. bfa_assert(0);
  316. }
  317. }
  318. /*
  319. * Register Port Attributes
  320. */
  321. static void
  322. bfa_fcs_port_fdmi_sm_sending_rpa(struct bfa_fcs_port_fdmi_s *fdmi,
  323. enum port_fdmi_event event)
  324. {
  325. struct bfa_fcs_port_s *port = fdmi->ms->port;
  326. bfa_trc(port->fcs, port->port_cfg.pwwn);
  327. bfa_trc(port->fcs, event);
  328. switch (event) {
  329. case FDMISM_EVENT_RPA_SENT:
  330. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_rpa);
  331. break;
  332. case FDMISM_EVENT_PORT_OFFLINE:
  333. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  334. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(port),
  335. &fdmi->fcxp_wqe);
  336. break;
  337. default:
  338. bfa_assert(0);
  339. }
  340. }
  341. static void
  342. bfa_fcs_port_fdmi_sm_rpa(struct bfa_fcs_port_fdmi_s *fdmi,
  343. enum port_fdmi_event event)
  344. {
  345. struct bfa_fcs_port_s *port = fdmi->ms->port;
  346. bfa_trc(port->fcs, port->port_cfg.pwwn);
  347. bfa_trc(port->fcs, event);
  348. switch (event) {
  349. case FDMISM_EVENT_RSP_ERROR:
  350. /*
  351. * if max retries have not been reached, start timer for a
  352. * delayed retry
  353. */
  354. if (fdmi->retry_cnt++ < BFA_FCS_FDMI_CMD_MAX_RETRIES) {
  355. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_rpa_retry);
  356. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(port),
  357. &fdmi->timer, bfa_fcs_port_fdmi_timeout,
  358. fdmi, BFA_FCS_RETRY_TIMEOUT);
  359. } else {
  360. /*
  361. * set state to offline
  362. */
  363. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  364. fdmi->retry_cnt = 0;
  365. }
  366. break;
  367. case FDMISM_EVENT_RSP_OK:
  368. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_online);
  369. fdmi->retry_cnt = 0;
  370. break;
  371. case FDMISM_EVENT_PORT_OFFLINE:
  372. bfa_fcxp_discard(fdmi->fcxp);
  373. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  374. break;
  375. default:
  376. bfa_assert(0);
  377. }
  378. }
  379. static void
  380. bfa_fcs_port_fdmi_sm_rpa_retry(struct bfa_fcs_port_fdmi_s *fdmi,
  381. enum port_fdmi_event event)
  382. {
  383. struct bfa_fcs_port_s *port = fdmi->ms->port;
  384. bfa_trc(port->fcs, port->port_cfg.pwwn);
  385. bfa_trc(port->fcs, event);
  386. switch (event) {
  387. case FDMISM_EVENT_TIMEOUT:
  388. /*
  389. * Retry Timer Expired. Re-send
  390. */
  391. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_sending_rpa);
  392. bfa_fcs_port_fdmi_send_rpa(fdmi, NULL);
  393. break;
  394. case FDMISM_EVENT_PORT_OFFLINE:
  395. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  396. bfa_timer_stop(&fdmi->timer);
  397. break;
  398. default:
  399. bfa_assert(0);
  400. }
  401. }
  402. static void
  403. bfa_fcs_port_fdmi_sm_online(struct bfa_fcs_port_fdmi_s *fdmi,
  404. enum port_fdmi_event event)
  405. {
  406. struct bfa_fcs_port_s *port = fdmi->ms->port;
  407. bfa_trc(port->fcs, port->port_cfg.pwwn);
  408. bfa_trc(port->fcs, event);
  409. switch (event) {
  410. case FDMISM_EVENT_PORT_OFFLINE:
  411. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  412. break;
  413. default:
  414. bfa_assert(0);
  415. }
  416. }
  417. /**
  418. * FDMI is disabled state.
  419. */
  420. static void
  421. bfa_fcs_port_fdmi_sm_disabled(struct bfa_fcs_port_fdmi_s *fdmi,
  422. enum port_fdmi_event event)
  423. {
  424. struct bfa_fcs_port_s *port = fdmi->ms->port;
  425. bfa_trc(port->fcs, port->port_cfg.pwwn);
  426. bfa_trc(port->fcs, event);
  427. /* No op State. It can only be enabled at Driver Init. */
  428. }
  429. /**
  430. * RHBA : Register HBA Attributes.
  431. */
  432. static void
  433. bfa_fcs_port_fdmi_send_rhba(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  434. {
  435. struct bfa_fcs_port_fdmi_s *fdmi = fdmi_cbarg;
  436. struct bfa_fcs_port_s *port = fdmi->ms->port;
  437. struct fchs_s fchs;
  438. int len, attr_len;
  439. struct bfa_fcxp_s *fcxp;
  440. u8 *pyld;
  441. bfa_trc(port->fcs, port->port_cfg.pwwn);
  442. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  443. if (!fcxp) {
  444. bfa_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
  445. bfa_fcs_port_fdmi_send_rhba, fdmi);
  446. return;
  447. }
  448. fdmi->fcxp = fcxp;
  449. pyld = bfa_fcxp_get_reqbuf(fcxp);
  450. bfa_os_memset(pyld, 0, FC_MAX_PDUSZ);
  451. len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_port_get_fcid(port),
  452. FDMI_RHBA);
  453. attr_len = bfa_fcs_port_fdmi_build_rhba_pyld(fdmi,
  454. (u8 *) ((struct ct_hdr_s *) pyld + 1));
  455. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  456. FC_CLASS_3, (len + attr_len), &fchs,
  457. bfa_fcs_port_fdmi_rhba_response, (void *)fdmi,
  458. FC_MAX_PDUSZ, FC_RA_TOV);
  459. bfa_sm_send_event(fdmi, FDMISM_EVENT_RHBA_SENT);
  460. }
  461. static u16
  462. bfa_fcs_port_fdmi_build_rhba_pyld(struct bfa_fcs_port_fdmi_s *fdmi,
  463. u8 *pyld)
  464. {
  465. struct bfa_fcs_port_s *port = fdmi->ms->port;
  466. struct bfa_fcs_fdmi_hba_attr_s hba_attr; /* @todo */
  467. struct bfa_fcs_fdmi_hba_attr_s *fcs_hba_attr = &hba_attr; /* @todo */
  468. struct fdmi_rhba_s *rhba = (struct fdmi_rhba_s *) pyld;
  469. struct fdmi_attr_s *attr;
  470. u8 *curr_ptr;
  471. u16 len, count;
  472. /*
  473. * get hba attributes
  474. */
  475. bfa_fcs_fdmi_get_hbaattr(fdmi, fcs_hba_attr);
  476. rhba->hba_id = bfa_fcs_port_get_pwwn(port);
  477. rhba->port_list.num_ports = bfa_os_htonl(1);
  478. rhba->port_list.port_entry = bfa_fcs_port_get_pwwn(port);
  479. len = sizeof(rhba->hba_id) + sizeof(rhba->port_list);
  480. count = 0;
  481. len += sizeof(rhba->hba_attr_blk.attr_count);
  482. /*
  483. * fill out the invididual entries of the HBA attrib Block
  484. */
  485. curr_ptr = (u8 *) &rhba->hba_attr_blk.hba_attr;
  486. /*
  487. * Node Name
  488. */
  489. attr = (struct fdmi_attr_s *) curr_ptr;
  490. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_NODENAME);
  491. attr->len = sizeof(wwn_t);
  492. memcpy(attr->value, &bfa_fcs_port_get_nwwn(port), attr->len);
  493. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  494. len += attr->len;
  495. count++;
  496. attr->len =
  497. bfa_os_htons(attr->len + sizeof(attr->type) +
  498. sizeof(attr->len));
  499. /*
  500. * Manufacturer
  501. */
  502. attr = (struct fdmi_attr_s *) curr_ptr;
  503. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MANUFACTURER);
  504. attr->len = (u16) strlen(fcs_hba_attr->manufacturer);
  505. memcpy(attr->value, fcs_hba_attr->manufacturer, attr->len);
  506. /* variable fields need to be 4 byte aligned */
  507. attr->len = fc_roundup(attr->len, sizeof(u32));
  508. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  509. len += attr->len;
  510. count++;
  511. attr->len =
  512. bfa_os_htons(attr->len + sizeof(attr->type) +
  513. sizeof(attr->len));
  514. /*
  515. * Serial Number
  516. */
  517. attr = (struct fdmi_attr_s *) curr_ptr;
  518. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_SERIALNUM);
  519. attr->len = (u16) strlen(fcs_hba_attr->serial_num);
  520. memcpy(attr->value, fcs_hba_attr->serial_num, attr->len);
  521. /* variable fields need to be 4 byte aligned */
  522. attr->len = fc_roundup(attr->len, sizeof(u32));
  523. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  524. len += attr->len;
  525. count++;
  526. attr->len =
  527. bfa_os_htons(attr->len + sizeof(attr->type) +
  528. sizeof(attr->len));
  529. /*
  530. * Model
  531. */
  532. attr = (struct fdmi_attr_s *) curr_ptr;
  533. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MODEL);
  534. attr->len = (u16) strlen(fcs_hba_attr->model);
  535. memcpy(attr->value, fcs_hba_attr->model, attr->len);
  536. /* variable fields need to be 4 byte aligned */
  537. attr->len = fc_roundup(attr->len, sizeof(u32));
  538. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  539. len += attr->len;
  540. count++;
  541. attr->len =
  542. bfa_os_htons(attr->len + sizeof(attr->type) +
  543. sizeof(attr->len));
  544. /*
  545. * Model Desc
  546. */
  547. attr = (struct fdmi_attr_s *) curr_ptr;
  548. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MODEL_DESC);
  549. attr->len = (u16) strlen(fcs_hba_attr->model_desc);
  550. memcpy(attr->value, fcs_hba_attr->model_desc, attr->len);
  551. /* variable fields need to be 4 byte aligned */
  552. attr->len = fc_roundup(attr->len, sizeof(u32));
  553. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  554. len += attr->len;
  555. count++;
  556. attr->len =
  557. bfa_os_htons(attr->len + sizeof(attr->type) +
  558. sizeof(attr->len));
  559. /*
  560. * H/W Version
  561. */
  562. if (fcs_hba_attr->hw_version[0] != '\0') {
  563. attr = (struct fdmi_attr_s *) curr_ptr;
  564. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_HW_VERSION);
  565. attr->len = (u16) strlen(fcs_hba_attr->hw_version);
  566. memcpy(attr->value, fcs_hba_attr->hw_version, attr->len);
  567. /* variable fields need to be 4 byte aligned */
  568. attr->len = fc_roundup(attr->len, sizeof(u32));
  569. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  570. len += attr->len;
  571. count++;
  572. attr->len =
  573. bfa_os_htons(attr->len + sizeof(attr->type) +
  574. sizeof(attr->len));
  575. }
  576. /*
  577. * Driver Version
  578. */
  579. attr = (struct fdmi_attr_s *) curr_ptr;
  580. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_DRIVER_VERSION);
  581. attr->len = (u16) strlen(fcs_hba_attr->driver_version);
  582. memcpy(attr->value, fcs_hba_attr->driver_version, attr->len);
  583. /* variable fields need to be 4 byte aligned */
  584. attr->len = fc_roundup(attr->len, sizeof(u32));
  585. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  586. len += attr->len;;
  587. count++;
  588. attr->len =
  589. bfa_os_htons(attr->len + sizeof(attr->type) +
  590. sizeof(attr->len));
  591. /*
  592. * Option Rom Version
  593. */
  594. if (fcs_hba_attr->option_rom_ver[0] != '\0') {
  595. attr = (struct fdmi_attr_s *) curr_ptr;
  596. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_ROM_VERSION);
  597. attr->len = (u16) strlen(fcs_hba_attr->option_rom_ver);
  598. memcpy(attr->value, fcs_hba_attr->option_rom_ver, attr->len);
  599. /* variable fields need to be 4 byte aligned */
  600. attr->len = fc_roundup(attr->len, sizeof(u32));
  601. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  602. len += attr->len;
  603. count++;
  604. attr->len =
  605. bfa_os_htons(attr->len + sizeof(attr->type) +
  606. sizeof(attr->len));
  607. }
  608. /*
  609. * f/w Version = driver version
  610. */
  611. attr = (struct fdmi_attr_s *) curr_ptr;
  612. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_FW_VERSION);
  613. attr->len = (u16) strlen(fcs_hba_attr->driver_version);
  614. memcpy(attr->value, fcs_hba_attr->driver_version, attr->len);
  615. /* variable fields need to be 4 byte aligned */
  616. attr->len = fc_roundup(attr->len, sizeof(u32));
  617. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  618. len += attr->len;
  619. count++;
  620. attr->len =
  621. bfa_os_htons(attr->len + sizeof(attr->type) +
  622. sizeof(attr->len));
  623. /*
  624. * OS Name
  625. */
  626. if (fcs_hba_attr->os_name[0] != '\0') {
  627. attr = (struct fdmi_attr_s *) curr_ptr;
  628. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_OS_NAME);
  629. attr->len = (u16) strlen(fcs_hba_attr->os_name);
  630. memcpy(attr->value, fcs_hba_attr->os_name, attr->len);
  631. /* variable fields need to be 4 byte aligned */
  632. attr->len = fc_roundup(attr->len, sizeof(u32));
  633. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  634. len += attr->len;
  635. count++;
  636. attr->len =
  637. bfa_os_htons(attr->len + sizeof(attr->type) +
  638. sizeof(attr->len));
  639. }
  640. /*
  641. * MAX_CT_PAYLOAD
  642. */
  643. attr = (struct fdmi_attr_s *) curr_ptr;
  644. attr->type = bfa_os_htons(FDMI_HBA_ATTRIB_MAX_CT);
  645. attr->len = sizeof(fcs_hba_attr->max_ct_pyld);
  646. memcpy(attr->value, &fcs_hba_attr->max_ct_pyld, attr->len);
  647. len += attr->len;
  648. count++;
  649. attr->len =
  650. bfa_os_htons(attr->len + sizeof(attr->type) +
  651. sizeof(attr->len));
  652. /*
  653. * Update size of payload
  654. */
  655. len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
  656. rhba->hba_attr_blk.attr_count = bfa_os_htonl(count);
  657. return len;
  658. }
  659. static void
  660. bfa_fcs_port_fdmi_rhba_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  661. void *cbarg, bfa_status_t req_status,
  662. u32 rsp_len, u32 resid_len,
  663. struct fchs_s *rsp_fchs)
  664. {
  665. struct bfa_fcs_port_fdmi_s *fdmi = (struct bfa_fcs_port_fdmi_s *)cbarg;
  666. struct bfa_fcs_port_s *port = fdmi->ms->port;
  667. struct ct_hdr_s *cthdr = NULL;
  668. bfa_trc(port->fcs, port->port_cfg.pwwn);
  669. /*
  670. * Sanity Checks
  671. */
  672. if (req_status != BFA_STATUS_OK) {
  673. bfa_trc(port->fcs, req_status);
  674. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  675. return;
  676. }
  677. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  678. cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
  679. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  680. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
  681. return;
  682. }
  683. bfa_trc(port->fcs, cthdr->reason_code);
  684. bfa_trc(port->fcs, cthdr->exp_code);
  685. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  686. }
  687. /**
  688. * RPRT : Register Port
  689. */
  690. static void
  691. bfa_fcs_port_fdmi_send_rprt(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  692. {
  693. struct bfa_fcs_port_fdmi_s *fdmi = fdmi_cbarg;
  694. struct bfa_fcs_port_s *port = fdmi->ms->port;
  695. struct fchs_s fchs;
  696. u16 len, attr_len;
  697. struct bfa_fcxp_s *fcxp;
  698. u8 *pyld;
  699. bfa_trc(port->fcs, port->port_cfg.pwwn);
  700. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  701. if (!fcxp) {
  702. bfa_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
  703. bfa_fcs_port_fdmi_send_rprt, fdmi);
  704. return;
  705. }
  706. fdmi->fcxp = fcxp;
  707. pyld = bfa_fcxp_get_reqbuf(fcxp);
  708. bfa_os_memset(pyld, 0, FC_MAX_PDUSZ);
  709. len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_port_get_fcid(port),
  710. FDMI_RPRT);
  711. attr_len = bfa_fcs_port_fdmi_build_rprt_pyld(fdmi,
  712. (u8 *) ((struct ct_hdr_s *) pyld + 1));
  713. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  714. FC_CLASS_3, len + attr_len, &fchs,
  715. bfa_fcs_port_fdmi_rprt_response, (void *)fdmi,
  716. FC_MAX_PDUSZ, FC_RA_TOV);
  717. bfa_sm_send_event(fdmi, FDMISM_EVENT_RPRT_SENT);
  718. }
  719. /**
  720. * This routine builds Port Attribute Block that used in RPA, RPRT commands.
  721. */
  722. static u16
  723. bfa_fcs_port_fdmi_build_portattr_block(struct bfa_fcs_port_fdmi_s *fdmi,
  724. u8 *pyld)
  725. {
  726. struct bfa_fcs_fdmi_port_attr_s fcs_port_attr;
  727. struct fdmi_port_attr_s *port_attrib = (struct fdmi_port_attr_s *) pyld;
  728. struct fdmi_attr_s *attr;
  729. u8 *curr_ptr;
  730. u16 len;
  731. u8 count = 0;
  732. /*
  733. * get port attributes
  734. */
  735. bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
  736. len = sizeof(port_attrib->attr_count);
  737. /*
  738. * fill out the invididual entries
  739. */
  740. curr_ptr = (u8 *) &port_attrib->port_attr;
  741. /*
  742. * FC4 Types
  743. */
  744. attr = (struct fdmi_attr_s *) curr_ptr;
  745. attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_FC4_TYPES);
  746. attr->len = sizeof(fcs_port_attr.supp_fc4_types);
  747. memcpy(attr->value, fcs_port_attr.supp_fc4_types, attr->len);
  748. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  749. len += attr->len;
  750. ++count;
  751. attr->len =
  752. bfa_os_htons(attr->len + sizeof(attr->type) +
  753. sizeof(attr->len));
  754. /*
  755. * Supported Speed
  756. */
  757. attr = (struct fdmi_attr_s *) curr_ptr;
  758. attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_SUPP_SPEED);
  759. attr->len = sizeof(fcs_port_attr.supp_speed);
  760. memcpy(attr->value, &fcs_port_attr.supp_speed, attr->len);
  761. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  762. len += attr->len;
  763. ++count;
  764. attr->len =
  765. bfa_os_htons(attr->len + sizeof(attr->type) +
  766. sizeof(attr->len));
  767. /*
  768. * current Port Speed
  769. */
  770. attr = (struct fdmi_attr_s *) curr_ptr;
  771. attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_PORT_SPEED);
  772. attr->len = sizeof(fcs_port_attr.curr_speed);
  773. memcpy(attr->value, &fcs_port_attr.curr_speed, attr->len);
  774. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  775. len += attr->len;
  776. ++count;
  777. attr->len =
  778. bfa_os_htons(attr->len + sizeof(attr->type) +
  779. sizeof(attr->len));
  780. /*
  781. * max frame size
  782. */
  783. attr = (struct fdmi_attr_s *) curr_ptr;
  784. attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_FRAME_SIZE);
  785. attr->len = sizeof(fcs_port_attr.max_frm_size);
  786. memcpy(attr->value, &fcs_port_attr.max_frm_size, attr->len);
  787. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  788. len += attr->len;
  789. ++count;
  790. attr->len =
  791. bfa_os_htons(attr->len + sizeof(attr->type) +
  792. sizeof(attr->len));
  793. /*
  794. * OS Device Name
  795. */
  796. if (fcs_port_attr.os_device_name[0] != '\0') {
  797. attr = (struct fdmi_attr_s *) curr_ptr;
  798. attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_DEV_NAME);
  799. attr->len = (u16) strlen(fcs_port_attr.os_device_name);
  800. memcpy(attr->value, fcs_port_attr.os_device_name, attr->len);
  801. /* variable fields need to be 4 byte aligned */
  802. attr->len = fc_roundup(attr->len, sizeof(u32));
  803. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  804. len += attr->len;
  805. ++count;
  806. attr->len =
  807. bfa_os_htons(attr->len + sizeof(attr->type) +
  808. sizeof(attr->len));
  809. }
  810. /*
  811. * Host Name
  812. */
  813. if (fcs_port_attr.host_name[0] != '\0') {
  814. attr = (struct fdmi_attr_s *) curr_ptr;
  815. attr->type = bfa_os_htons(FDMI_PORT_ATTRIB_HOST_NAME);
  816. attr->len = (u16) strlen(fcs_port_attr.host_name);
  817. memcpy(attr->value, fcs_port_attr.host_name, attr->len);
  818. /* variable fields need to be 4 byte aligned */
  819. attr->len = fc_roundup(attr->len, sizeof(u32));
  820. curr_ptr += sizeof(attr->type) + sizeof(attr->len) + attr->len;
  821. len += attr->len;
  822. ++count;
  823. attr->len =
  824. bfa_os_htons(attr->len + sizeof(attr->type) +
  825. sizeof(attr->len));
  826. }
  827. /*
  828. * Update size of payload
  829. */
  830. port_attrib->attr_count = bfa_os_htonl(count);
  831. len += ((sizeof(attr->type) + sizeof(attr->len)) * count);
  832. return len;
  833. }
  834. static u16
  835. bfa_fcs_port_fdmi_build_rprt_pyld(struct bfa_fcs_port_fdmi_s *fdmi,
  836. u8 *pyld)
  837. {
  838. struct bfa_fcs_port_s *port = fdmi->ms->port;
  839. struct fdmi_rprt_s *rprt = (struct fdmi_rprt_s *) pyld;
  840. u16 len;
  841. rprt->hba_id = bfa_fcs_port_get_pwwn(bfa_fcs_get_base_port(port->fcs));
  842. rprt->port_name = bfa_fcs_port_get_pwwn(port);
  843. len = bfa_fcs_port_fdmi_build_portattr_block(fdmi,
  844. (u8 *) &rprt->port_attr_blk);
  845. len += sizeof(rprt->hba_id) + sizeof(rprt->port_name);
  846. return len;
  847. }
  848. static void
  849. bfa_fcs_port_fdmi_rprt_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  850. void *cbarg, bfa_status_t req_status,
  851. u32 rsp_len, u32 resid_len,
  852. struct fchs_s *rsp_fchs)
  853. {
  854. struct bfa_fcs_port_fdmi_s *fdmi = (struct bfa_fcs_port_fdmi_s *)cbarg;
  855. struct bfa_fcs_port_s *port = fdmi->ms->port;
  856. struct ct_hdr_s *cthdr = NULL;
  857. bfa_trc(port->fcs, port->port_cfg.pwwn);
  858. /*
  859. * Sanity Checks
  860. */
  861. if (req_status != BFA_STATUS_OK) {
  862. bfa_trc(port->fcs, req_status);
  863. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  864. return;
  865. }
  866. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  867. cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
  868. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  869. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
  870. return;
  871. }
  872. bfa_trc(port->fcs, cthdr->reason_code);
  873. bfa_trc(port->fcs, cthdr->exp_code);
  874. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  875. }
  876. /**
  877. * RPA : Register Port Attributes.
  878. */
  879. static void
  880. bfa_fcs_port_fdmi_send_rpa(void *fdmi_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  881. {
  882. struct bfa_fcs_port_fdmi_s *fdmi = fdmi_cbarg;
  883. struct bfa_fcs_port_s *port = fdmi->ms->port;
  884. struct fchs_s fchs;
  885. u16 len, attr_len;
  886. struct bfa_fcxp_s *fcxp;
  887. u8 *pyld;
  888. bfa_trc(port->fcs, port->port_cfg.pwwn);
  889. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  890. if (!fcxp) {
  891. bfa_fcxp_alloc_wait(port->fcs->bfa, &fdmi->fcxp_wqe,
  892. bfa_fcs_port_fdmi_send_rpa, fdmi);
  893. return;
  894. }
  895. fdmi->fcxp = fcxp;
  896. pyld = bfa_fcxp_get_reqbuf(fcxp);
  897. bfa_os_memset(pyld, 0, FC_MAX_PDUSZ);
  898. len = fc_fdmi_reqhdr_build(&fchs, pyld, bfa_fcs_port_get_fcid(port),
  899. FDMI_RPA);
  900. attr_len = bfa_fcs_port_fdmi_build_rpa_pyld(fdmi,
  901. (u8 *) ((struct ct_hdr_s *) pyld + 1));
  902. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  903. FC_CLASS_3, len + attr_len, &fchs,
  904. bfa_fcs_port_fdmi_rpa_response, (void *)fdmi,
  905. FC_MAX_PDUSZ, FC_RA_TOV);
  906. bfa_sm_send_event(fdmi, FDMISM_EVENT_RPA_SENT);
  907. }
  908. static u16
  909. bfa_fcs_port_fdmi_build_rpa_pyld(struct bfa_fcs_port_fdmi_s *fdmi,
  910. u8 *pyld)
  911. {
  912. struct bfa_fcs_port_s *port = fdmi->ms->port;
  913. struct fdmi_rpa_s *rpa = (struct fdmi_rpa_s *) pyld;
  914. u16 len;
  915. rpa->port_name = bfa_fcs_port_get_pwwn(port);
  916. len = bfa_fcs_port_fdmi_build_portattr_block(fdmi,
  917. (u8 *) &rpa->port_attr_blk);
  918. len += sizeof(rpa->port_name);
  919. return len;
  920. }
  921. static void
  922. bfa_fcs_port_fdmi_rpa_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  923. void *cbarg, bfa_status_t req_status,
  924. u32 rsp_len, u32 resid_len,
  925. struct fchs_s *rsp_fchs)
  926. {
  927. struct bfa_fcs_port_fdmi_s *fdmi = (struct bfa_fcs_port_fdmi_s *)cbarg;
  928. struct bfa_fcs_port_s *port = fdmi->ms->port;
  929. struct ct_hdr_s *cthdr = NULL;
  930. bfa_trc(port->fcs, port->port_cfg.pwwn);
  931. /*
  932. * Sanity Checks
  933. */
  934. if (req_status != BFA_STATUS_OK) {
  935. bfa_trc(port->fcs, req_status);
  936. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  937. return;
  938. }
  939. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  940. cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
  941. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  942. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_OK);
  943. return;
  944. }
  945. bfa_trc(port->fcs, cthdr->reason_code);
  946. bfa_trc(port->fcs, cthdr->exp_code);
  947. bfa_sm_send_event(fdmi, FDMISM_EVENT_RSP_ERROR);
  948. }
  949. static void
  950. bfa_fcs_port_fdmi_timeout(void *arg)
  951. {
  952. struct bfa_fcs_port_fdmi_s *fdmi = (struct bfa_fcs_port_fdmi_s *)arg;
  953. bfa_sm_send_event(fdmi, FDMISM_EVENT_TIMEOUT);
  954. }
  955. static void
  956. bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_port_fdmi_s *fdmi,
  957. struct bfa_fcs_fdmi_hba_attr_s *hba_attr)
  958. {
  959. struct bfa_fcs_port_s *port = fdmi->ms->port;
  960. struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
  961. struct bfa_adapter_attr_s adapter_attr;
  962. bfa_os_memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
  963. bfa_os_memset(&adapter_attr, 0, sizeof(struct bfa_adapter_attr_s));
  964. bfa_ioc_get_adapter_attr(&port->fcs->bfa->ioc, &adapter_attr);
  965. strncpy(hba_attr->manufacturer, adapter_attr.manufacturer,
  966. sizeof(adapter_attr.manufacturer));
  967. strncpy(hba_attr->serial_num, adapter_attr.serial_num,
  968. sizeof(adapter_attr.serial_num));
  969. strncpy(hba_attr->model, adapter_attr.model, sizeof(hba_attr->model));
  970. strncpy(hba_attr->model_desc, adapter_attr.model_descr,
  971. sizeof(hba_attr->model_desc));
  972. strncpy(hba_attr->hw_version, adapter_attr.hw_ver,
  973. sizeof(hba_attr->hw_version));
  974. strncpy(hba_attr->driver_version, (char *)driver_info->version,
  975. sizeof(hba_attr->driver_version));
  976. strncpy(hba_attr->option_rom_ver, adapter_attr.optrom_ver,
  977. sizeof(hba_attr->option_rom_ver));
  978. strncpy(hba_attr->fw_version, adapter_attr.fw_ver,
  979. sizeof(hba_attr->fw_version));
  980. strncpy(hba_attr->os_name, driver_info->host_os_name,
  981. sizeof(hba_attr->os_name));
  982. /*
  983. * If there is a patch level, append it to the os name along with a
  984. * separator
  985. */
  986. if (driver_info->host_os_patch[0] != '\0') {
  987. strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  988. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  989. strncat(hba_attr->os_name, driver_info->host_os_patch,
  990. sizeof(driver_info->host_os_patch));
  991. }
  992. hba_attr->max_ct_pyld = bfa_os_htonl(FC_MAX_PDUSZ);
  993. }
  994. static void
  995. bfa_fcs_fdmi_get_portattr(struct bfa_fcs_port_fdmi_s *fdmi,
  996. struct bfa_fcs_fdmi_port_attr_s *port_attr)
  997. {
  998. struct bfa_fcs_port_s *port = fdmi->ms->port;
  999. struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
  1000. struct bfa_pport_attr_s pport_attr;
  1001. bfa_os_memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
  1002. /*
  1003. * get pport attributes from hal
  1004. */
  1005. bfa_pport_get_attr(port->fcs->bfa, &pport_attr);
  1006. /*
  1007. * get FC4 type Bitmask
  1008. */
  1009. fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
  1010. /*
  1011. * Supported Speeds
  1012. */
  1013. port_attr->supp_speed = bfa_os_htonl(BFA_FCS_FDMI_SUPORTED_SPEEDS);
  1014. /*
  1015. * Current Speed
  1016. */
  1017. port_attr->curr_speed = bfa_os_htonl(pport_attr.speed);
  1018. /*
  1019. * Max PDU Size.
  1020. */
  1021. port_attr->max_frm_size = bfa_os_htonl(FC_MAX_PDUSZ);
  1022. /*
  1023. * OS device Name
  1024. */
  1025. strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
  1026. sizeof(port_attr->os_device_name));
  1027. /*
  1028. * Host name
  1029. */
  1030. strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
  1031. sizeof(port_attr->host_name));
  1032. }
  1033. void
  1034. bfa_fcs_port_fdmi_init(struct bfa_fcs_port_ms_s *ms)
  1035. {
  1036. struct bfa_fcs_port_fdmi_s *fdmi = &ms->fdmi;
  1037. fdmi->ms = ms;
  1038. if (ms->port->fcs->fdmi_enabled)
  1039. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  1040. else
  1041. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_disabled);
  1042. }
  1043. void
  1044. bfa_fcs_port_fdmi_offline(struct bfa_fcs_port_ms_s *ms)
  1045. {
  1046. struct bfa_fcs_port_fdmi_s *fdmi = &ms->fdmi;
  1047. fdmi->ms = ms;
  1048. bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
  1049. }
  1050. void
  1051. bfa_fcs_port_fdmi_online(struct bfa_fcs_port_ms_s *ms)
  1052. {
  1053. struct bfa_fcs_port_fdmi_s *fdmi = &ms->fdmi;
  1054. fdmi->ms = ms;
  1055. bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
  1056. }