fdmi.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_sm_fault(port->fcs, event);
  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_FCCT_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_FCCT_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_FCCT_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. bfa_os_memset(hba_attr, 0, sizeof(struct bfa_fcs_fdmi_hba_attr_s));
  962. bfa_ioc_get_adapter_manufacturer(&port->fcs->bfa->ioc,
  963. hba_attr->manufacturer);
  964. bfa_ioc_get_adapter_serial_num(&port->fcs->bfa->ioc,
  965. hba_attr->serial_num);
  966. bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc, hba_attr->model);
  967. bfa_ioc_get_adapter_model(&port->fcs->bfa->ioc, hba_attr->model_desc);
  968. bfa_ioc_get_pci_chip_rev(&port->fcs->bfa->ioc, hba_attr->hw_version);
  969. bfa_ioc_get_adapter_optrom_ver(&port->fcs->bfa->ioc,
  970. hba_attr->option_rom_ver);
  971. bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc, hba_attr->fw_version);
  972. strncpy(hba_attr->driver_version, (char *)driver_info->version,
  973. sizeof(hba_attr->driver_version));
  974. strncpy(hba_attr->os_name, driver_info->host_os_name,
  975. sizeof(hba_attr->os_name));
  976. /*
  977. * If there is a patch level, append it to the os name along with a
  978. * separator
  979. */
  980. if (driver_info->host_os_patch[0] != '\0') {
  981. strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  982. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  983. strncat(hba_attr->os_name, driver_info->host_os_patch,
  984. sizeof(driver_info->host_os_patch));
  985. }
  986. hba_attr->max_ct_pyld = bfa_os_htonl(FC_MAX_PDUSZ);
  987. }
  988. static void
  989. bfa_fcs_fdmi_get_portattr(struct bfa_fcs_port_fdmi_s *fdmi,
  990. struct bfa_fcs_fdmi_port_attr_s *port_attr)
  991. {
  992. struct bfa_fcs_port_s *port = fdmi->ms->port;
  993. struct bfa_fcs_driver_info_s *driver_info = &port->fcs->driver_info;
  994. struct bfa_pport_attr_s pport_attr;
  995. bfa_os_memset(port_attr, 0, sizeof(struct bfa_fcs_fdmi_port_attr_s));
  996. /*
  997. * get pport attributes from hal
  998. */
  999. bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
  1000. /*
  1001. * get FC4 type Bitmask
  1002. */
  1003. fc_get_fc4type_bitmask(FC_TYPE_FCP, port_attr->supp_fc4_types);
  1004. /*
  1005. * Supported Speeds
  1006. */
  1007. port_attr->supp_speed = bfa_os_htonl(BFA_FCS_FDMI_SUPORTED_SPEEDS);
  1008. /*
  1009. * Current Speed
  1010. */
  1011. port_attr->curr_speed = bfa_os_htonl(pport_attr.speed);
  1012. /*
  1013. * Max PDU Size.
  1014. */
  1015. port_attr->max_frm_size = bfa_os_htonl(FC_MAX_PDUSZ);
  1016. /*
  1017. * OS device Name
  1018. */
  1019. strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
  1020. sizeof(port_attr->os_device_name));
  1021. /*
  1022. * Host name
  1023. */
  1024. strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
  1025. sizeof(port_attr->host_name));
  1026. }
  1027. void
  1028. bfa_fcs_port_fdmi_init(struct bfa_fcs_port_ms_s *ms)
  1029. {
  1030. struct bfa_fcs_port_fdmi_s *fdmi = &ms->fdmi;
  1031. fdmi->ms = ms;
  1032. if (ms->port->fcs->fdmi_enabled)
  1033. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_offline);
  1034. else
  1035. bfa_sm_set_state(fdmi, bfa_fcs_port_fdmi_sm_disabled);
  1036. }
  1037. void
  1038. bfa_fcs_port_fdmi_offline(struct bfa_fcs_port_ms_s *ms)
  1039. {
  1040. struct bfa_fcs_port_fdmi_s *fdmi = &ms->fdmi;
  1041. fdmi->ms = ms;
  1042. bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_OFFLINE);
  1043. }
  1044. void
  1045. bfa_fcs_port_fdmi_online(struct bfa_fcs_port_ms_s *ms)
  1046. {
  1047. struct bfa_fcs_port_fdmi_s *fdmi = &ms->fdmi;
  1048. fdmi->ms = ms;
  1049. bfa_sm_send_event(fdmi, FDMISM_EVENT_PORT_ONLINE);
  1050. }