ms.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. #include <bfa.h>
  18. #include <bfa_svc.h>
  19. #include "fcs_lport.h"
  20. #include "fcs_rport.h"
  21. #include "fcs_trcmod.h"
  22. #include "fcs_fcxp.h"
  23. #include "lport_priv.h"
  24. BFA_TRC_FILE(FCS, MS);
  25. #define BFA_FCS_MS_CMD_MAX_RETRIES 2
  26. /*
  27. * forward declarations
  28. */
  29. static void bfa_fcs_port_ms_send_plogi(void *ms_cbarg,
  30. struct bfa_fcxp_s *fcxp_alloced);
  31. static void bfa_fcs_port_ms_timeout(void *arg);
  32. static void bfa_fcs_port_ms_plogi_response(void *fcsarg,
  33. struct bfa_fcxp_s *fcxp,
  34. void *cbarg,
  35. bfa_status_t req_status,
  36. u32 rsp_len,
  37. u32 resid_len,
  38. struct fchs_s *rsp_fchs);
  39. static void bfa_fcs_port_ms_send_gmal(void *ms_cbarg,
  40. struct bfa_fcxp_s *fcxp_alloced);
  41. static void bfa_fcs_port_ms_gmal_response(void *fcsarg,
  42. struct bfa_fcxp_s *fcxp,
  43. void *cbarg,
  44. bfa_status_t req_status,
  45. u32 rsp_len,
  46. u32 resid_len,
  47. struct fchs_s *rsp_fchs);
  48. static void bfa_fcs_port_ms_send_gfn(void *ms_cbarg,
  49. struct bfa_fcxp_s *fcxp_alloced);
  50. static void bfa_fcs_port_ms_gfn_response(void *fcsarg,
  51. struct bfa_fcxp_s *fcxp,
  52. void *cbarg,
  53. bfa_status_t req_status,
  54. u32 rsp_len,
  55. u32 resid_len,
  56. struct fchs_s *rsp_fchs);
  57. /**
  58. * fcs_ms_sm FCS MS state machine
  59. */
  60. /**
  61. * MS State Machine events
  62. */
  63. enum port_ms_event {
  64. MSSM_EVENT_PORT_ONLINE = 1,
  65. MSSM_EVENT_PORT_OFFLINE = 2,
  66. MSSM_EVENT_RSP_OK = 3,
  67. MSSM_EVENT_RSP_ERROR = 4,
  68. MSSM_EVENT_TIMEOUT = 5,
  69. MSSM_EVENT_FCXP_SENT = 6,
  70. MSSM_EVENT_PORT_FABRIC_RSCN = 7
  71. };
  72. static void bfa_fcs_port_ms_sm_offline(struct bfa_fcs_port_ms_s *ms,
  73. enum port_ms_event event);
  74. static void bfa_fcs_port_ms_sm_plogi_sending(struct bfa_fcs_port_ms_s *ms,
  75. enum port_ms_event event);
  76. static void bfa_fcs_port_ms_sm_plogi(struct bfa_fcs_port_ms_s *ms,
  77. enum port_ms_event event);
  78. static void bfa_fcs_port_ms_sm_plogi_retry(struct bfa_fcs_port_ms_s *ms,
  79. enum port_ms_event event);
  80. static void bfa_fcs_port_ms_sm_gmal_sending(struct bfa_fcs_port_ms_s *ms,
  81. enum port_ms_event event);
  82. static void bfa_fcs_port_ms_sm_gmal(struct bfa_fcs_port_ms_s *ms,
  83. enum port_ms_event event);
  84. static void bfa_fcs_port_ms_sm_gmal_retry(struct bfa_fcs_port_ms_s *ms,
  85. enum port_ms_event event);
  86. static void bfa_fcs_port_ms_sm_gfn_sending(struct bfa_fcs_port_ms_s *ms,
  87. enum port_ms_event event);
  88. static void bfa_fcs_port_ms_sm_gfn(struct bfa_fcs_port_ms_s *ms,
  89. enum port_ms_event event);
  90. static void bfa_fcs_port_ms_sm_gfn_retry(struct bfa_fcs_port_ms_s *ms,
  91. enum port_ms_event event);
  92. static void bfa_fcs_port_ms_sm_online(struct bfa_fcs_port_ms_s *ms,
  93. enum port_ms_event event);
  94. /**
  95. * Start in offline state - awaiting NS to send start.
  96. */
  97. static void
  98. bfa_fcs_port_ms_sm_offline(struct bfa_fcs_port_ms_s *ms,
  99. enum port_ms_event event)
  100. {
  101. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  102. bfa_trc(ms->port->fcs, event);
  103. switch (event) {
  104. case MSSM_EVENT_PORT_ONLINE:
  105. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi_sending);
  106. bfa_fcs_port_ms_send_plogi(ms, NULL);
  107. break;
  108. case MSSM_EVENT_PORT_OFFLINE:
  109. break;
  110. default:
  111. bfa_sm_fault(ms->port->fcs, event);
  112. }
  113. }
  114. static void
  115. bfa_fcs_port_ms_sm_plogi_sending(struct bfa_fcs_port_ms_s *ms,
  116. enum port_ms_event event)
  117. {
  118. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  119. bfa_trc(ms->port->fcs, event);
  120. switch (event) {
  121. case MSSM_EVENT_FCXP_SENT:
  122. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi);
  123. break;
  124. case MSSM_EVENT_PORT_OFFLINE:
  125. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  126. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  127. &ms->fcxp_wqe);
  128. break;
  129. default:
  130. bfa_sm_fault(ms->port->fcs, event);
  131. }
  132. }
  133. static void
  134. bfa_fcs_port_ms_sm_plogi(struct bfa_fcs_port_ms_s *ms, enum port_ms_event event)
  135. {
  136. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  137. bfa_trc(ms->port->fcs, event);
  138. switch (event) {
  139. case MSSM_EVENT_RSP_ERROR:
  140. /*
  141. * Start timer for a delayed retry
  142. */
  143. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi_retry);
  144. ms->port->stats.ms_retries++;
  145. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port), &ms->timer,
  146. bfa_fcs_port_ms_timeout, ms,
  147. BFA_FCS_RETRY_TIMEOUT);
  148. break;
  149. case MSSM_EVENT_RSP_OK:
  150. /*
  151. * since plogi is done, now invoke MS related sub-modules
  152. */
  153. bfa_fcs_port_fdmi_online(ms);
  154. /**
  155. * if this is a Vport, go to online state.
  156. */
  157. if (ms->port->vport) {
  158. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_online);
  159. break;
  160. }
  161. /*
  162. * For a base port we need to get the
  163. * switch's IP address.
  164. */
  165. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal_sending);
  166. bfa_fcs_port_ms_send_gmal(ms, NULL);
  167. break;
  168. case MSSM_EVENT_PORT_OFFLINE:
  169. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  170. bfa_fcxp_discard(ms->fcxp);
  171. break;
  172. default:
  173. bfa_sm_fault(ms->port->fcs, event);
  174. }
  175. }
  176. static void
  177. bfa_fcs_port_ms_sm_plogi_retry(struct bfa_fcs_port_ms_s *ms,
  178. enum port_ms_event event)
  179. {
  180. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  181. bfa_trc(ms->port->fcs, event);
  182. switch (event) {
  183. case MSSM_EVENT_TIMEOUT:
  184. /*
  185. * Retry Timer Expired. Re-send
  186. */
  187. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_plogi_sending);
  188. bfa_fcs_port_ms_send_plogi(ms, NULL);
  189. break;
  190. case MSSM_EVENT_PORT_OFFLINE:
  191. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  192. bfa_timer_stop(&ms->timer);
  193. break;
  194. default:
  195. bfa_sm_fault(ms->port->fcs, event);
  196. }
  197. }
  198. static void
  199. bfa_fcs_port_ms_sm_online(struct bfa_fcs_port_ms_s *ms,
  200. enum port_ms_event event)
  201. {
  202. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  203. bfa_trc(ms->port->fcs, event);
  204. switch (event) {
  205. case MSSM_EVENT_PORT_OFFLINE:
  206. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  207. break;
  208. case MSSM_EVENT_PORT_FABRIC_RSCN:
  209. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
  210. ms->retry_cnt = 0;
  211. bfa_fcs_port_ms_send_gfn(ms, NULL);
  212. break;
  213. default:
  214. bfa_sm_fault(ms->port->fcs, event);
  215. }
  216. }
  217. static void
  218. bfa_fcs_port_ms_sm_gmal_sending(struct bfa_fcs_port_ms_s *ms,
  219. enum port_ms_event event)
  220. {
  221. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  222. bfa_trc(ms->port->fcs, event);
  223. switch (event) {
  224. case MSSM_EVENT_FCXP_SENT:
  225. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal);
  226. break;
  227. case MSSM_EVENT_PORT_OFFLINE:
  228. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  229. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  230. &ms->fcxp_wqe);
  231. break;
  232. default:
  233. bfa_sm_fault(ms->port->fcs, event);
  234. }
  235. }
  236. static void
  237. bfa_fcs_port_ms_sm_gmal(struct bfa_fcs_port_ms_s *ms, enum port_ms_event event)
  238. {
  239. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  240. bfa_trc(ms->port->fcs, event);
  241. switch (event) {
  242. case MSSM_EVENT_RSP_ERROR:
  243. /*
  244. * Start timer for a delayed retry
  245. */
  246. if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
  247. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal_retry);
  248. ms->port->stats.ms_retries++;
  249. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  250. &ms->timer, bfa_fcs_port_ms_timeout, ms,
  251. BFA_FCS_RETRY_TIMEOUT);
  252. } else {
  253. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
  254. bfa_fcs_port_ms_send_gfn(ms, NULL);
  255. ms->retry_cnt = 0;
  256. }
  257. break;
  258. case MSSM_EVENT_RSP_OK:
  259. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
  260. bfa_fcs_port_ms_send_gfn(ms, NULL);
  261. break;
  262. case MSSM_EVENT_PORT_OFFLINE:
  263. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  264. bfa_fcxp_discard(ms->fcxp);
  265. break;
  266. default:
  267. bfa_sm_fault(ms->port->fcs, event);
  268. }
  269. }
  270. static void
  271. bfa_fcs_port_ms_sm_gmal_retry(struct bfa_fcs_port_ms_s *ms,
  272. enum port_ms_event event)
  273. {
  274. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  275. bfa_trc(ms->port->fcs, event);
  276. switch (event) {
  277. case MSSM_EVENT_TIMEOUT:
  278. /*
  279. * Retry Timer Expired. Re-send
  280. */
  281. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gmal_sending);
  282. bfa_fcs_port_ms_send_gmal(ms, NULL);
  283. break;
  284. case MSSM_EVENT_PORT_OFFLINE:
  285. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  286. bfa_timer_stop(&ms->timer);
  287. break;
  288. default:
  289. bfa_sm_fault(ms->port->fcs, event);
  290. }
  291. }
  292. /**
  293. * ms_pvt MS local functions
  294. */
  295. static void
  296. bfa_fcs_port_ms_send_gmal(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  297. {
  298. struct bfa_fcs_port_ms_s *ms = ms_cbarg;
  299. struct bfa_fcs_port_s *port = ms->port;
  300. struct fchs_s fchs;
  301. int len;
  302. struct bfa_fcxp_s *fcxp;
  303. bfa_trc(port->fcs, port->pid);
  304. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  305. if (!fcxp) {
  306. bfa_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
  307. bfa_fcs_port_ms_send_gmal, ms);
  308. return;
  309. }
  310. ms->fcxp = fcxp;
  311. len = fc_gmal_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  312. bfa_fcs_port_get_fcid(port),
  313. bfa_lps_get_peer_nwwn(port->fabric->lps));
  314. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  315. FC_CLASS_3, len, &fchs, bfa_fcs_port_ms_gmal_response,
  316. (void *)ms, FC_MAX_PDUSZ, FC_FCCT_TOV);
  317. bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
  318. }
  319. static void
  320. bfa_fcs_port_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  321. void *cbarg, bfa_status_t req_status,
  322. u32 rsp_len, u32 resid_len,
  323. struct fchs_s *rsp_fchs)
  324. {
  325. struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)cbarg;
  326. struct bfa_fcs_port_s *port = ms->port;
  327. struct ct_hdr_s *cthdr = NULL;
  328. struct fcgs_gmal_resp_s *gmal_resp;
  329. struct fc_gmal_entry_s *gmal_entry;
  330. u32 num_entries;
  331. u8 *rsp_str;
  332. bfa_trc(port->fcs, req_status);
  333. bfa_trc(port->fcs, port->port_cfg.pwwn);
  334. /*
  335. * Sanity Checks
  336. */
  337. if (req_status != BFA_STATUS_OK) {
  338. bfa_trc(port->fcs, req_status);
  339. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  340. return;
  341. }
  342. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  343. cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
  344. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  345. gmal_resp = (struct fcgs_gmal_resp_s *)(cthdr + 1);
  346. num_entries = bfa_os_ntohl(gmal_resp->ms_len);
  347. if (num_entries == 0) {
  348. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  349. return;
  350. }
  351. /*
  352. * The response could contain multiple Entries.
  353. * Entries for SNMP interface, etc.
  354. * We look for the entry with a telnet prefix.
  355. * First "http://" entry refers to IP addr
  356. */
  357. gmal_entry = (struct fc_gmal_entry_s *)gmal_resp->ms_ma;
  358. while (num_entries > 0) {
  359. if (strncmp
  360. (gmal_entry->prefix, CT_GMAL_RESP_PREFIX_HTTP,
  361. sizeof(gmal_entry->prefix)) == 0) {
  362. /*
  363. * if the IP address is terminating with a '/',
  364. * remove it. *Byte 0 consists of the length
  365. * of the string.
  366. */
  367. rsp_str = &(gmal_entry->prefix[0]);
  368. if (rsp_str[gmal_entry->len - 1] == '/')
  369. rsp_str[gmal_entry->len - 1] = 0;
  370. /*
  371. * copy IP Address to fabric
  372. */
  373. strncpy(bfa_fcs_port_get_fabric_ipaddr(port),
  374. gmal_entry->ip_addr,
  375. BFA_FCS_FABRIC_IPADDR_SZ);
  376. break;
  377. } else {
  378. --num_entries;
  379. ++gmal_entry;
  380. }
  381. }
  382. bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
  383. return;
  384. }
  385. bfa_trc(port->fcs, cthdr->reason_code);
  386. bfa_trc(port->fcs, cthdr->exp_code);
  387. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  388. }
  389. static void
  390. bfa_fcs_port_ms_sm_gfn_sending(struct bfa_fcs_port_ms_s *ms,
  391. enum port_ms_event event)
  392. {
  393. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  394. bfa_trc(ms->port->fcs, event);
  395. switch (event) {
  396. case MSSM_EVENT_FCXP_SENT:
  397. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn);
  398. break;
  399. case MSSM_EVENT_PORT_OFFLINE:
  400. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  401. bfa_fcxp_walloc_cancel(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  402. &ms->fcxp_wqe);
  403. break;
  404. default:
  405. bfa_sm_fault(ms->port->fcs, event);
  406. }
  407. }
  408. static void
  409. bfa_fcs_port_ms_sm_gfn(struct bfa_fcs_port_ms_s *ms, enum port_ms_event event)
  410. {
  411. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  412. bfa_trc(ms->port->fcs, event);
  413. switch (event) {
  414. case MSSM_EVENT_RSP_ERROR:
  415. /*
  416. * Start timer for a delayed retry
  417. */
  418. if (ms->retry_cnt++ < BFA_FCS_MS_CMD_MAX_RETRIES) {
  419. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_retry);
  420. ms->port->stats.ms_retries++;
  421. bfa_timer_start(BFA_FCS_GET_HAL_FROM_PORT(ms->port),
  422. &ms->timer, bfa_fcs_port_ms_timeout, ms,
  423. BFA_FCS_RETRY_TIMEOUT);
  424. } else {
  425. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_online);
  426. ms->retry_cnt = 0;
  427. }
  428. break;
  429. case MSSM_EVENT_RSP_OK:
  430. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_online);
  431. break;
  432. case MSSM_EVENT_PORT_OFFLINE:
  433. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  434. bfa_fcxp_discard(ms->fcxp);
  435. break;
  436. default:
  437. bfa_sm_fault(ms->port->fcs, event);
  438. }
  439. }
  440. static void
  441. bfa_fcs_port_ms_sm_gfn_retry(struct bfa_fcs_port_ms_s *ms,
  442. enum port_ms_event event)
  443. {
  444. bfa_trc(ms->port->fcs, ms->port->port_cfg.pwwn);
  445. bfa_trc(ms->port->fcs, event);
  446. switch (event) {
  447. case MSSM_EVENT_TIMEOUT:
  448. /*
  449. * Retry Timer Expired. Re-send
  450. */
  451. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_gfn_sending);
  452. bfa_fcs_port_ms_send_gfn(ms, NULL);
  453. break;
  454. case MSSM_EVENT_PORT_OFFLINE:
  455. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  456. bfa_timer_stop(&ms->timer);
  457. break;
  458. default:
  459. bfa_sm_fault(ms->port->fcs, event);
  460. }
  461. }
  462. /**
  463. * ms_pvt MS local functions
  464. */
  465. static void
  466. bfa_fcs_port_ms_send_gfn(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  467. {
  468. struct bfa_fcs_port_ms_s *ms = ms_cbarg;
  469. struct bfa_fcs_port_s *port = ms->port;
  470. struct fchs_s fchs;
  471. int len;
  472. struct bfa_fcxp_s *fcxp;
  473. bfa_trc(port->fcs, port->pid);
  474. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  475. if (!fcxp) {
  476. bfa_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
  477. bfa_fcs_port_ms_send_gfn, ms);
  478. return;
  479. }
  480. ms->fcxp = fcxp;
  481. len = fc_gfn_req_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  482. bfa_fcs_port_get_fcid(port),
  483. bfa_lps_get_peer_nwwn(port->fabric->lps));
  484. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  485. FC_CLASS_3, len, &fchs, bfa_fcs_port_ms_gfn_response,
  486. (void *)ms, FC_MAX_PDUSZ, FC_FCCT_TOV);
  487. bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
  488. }
  489. static void
  490. bfa_fcs_port_ms_gfn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  491. bfa_status_t req_status, u32 rsp_len,
  492. u32 resid_len, struct fchs_s *rsp_fchs)
  493. {
  494. struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)cbarg;
  495. struct bfa_fcs_port_s *port = ms->port;
  496. struct ct_hdr_s *cthdr = NULL;
  497. wwn_t *gfn_resp;
  498. bfa_trc(port->fcs, req_status);
  499. bfa_trc(port->fcs, port->port_cfg.pwwn);
  500. /*
  501. * Sanity Checks
  502. */
  503. if (req_status != BFA_STATUS_OK) {
  504. bfa_trc(port->fcs, req_status);
  505. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  506. return;
  507. }
  508. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  509. cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
  510. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  511. gfn_resp = (wwn_t *) (cthdr + 1);
  512. /*
  513. * check if it has actually changed
  514. */
  515. if ((memcmp
  516. ((void *)&bfa_fcs_port_get_fabric_name(port), gfn_resp,
  517. sizeof(wwn_t)) != 0))
  518. bfa_fcs_fabric_set_fabric_name(port->fabric, *gfn_resp);
  519. bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
  520. return;
  521. }
  522. bfa_trc(port->fcs, cthdr->reason_code);
  523. bfa_trc(port->fcs, cthdr->exp_code);
  524. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  525. }
  526. /**
  527. * ms_pvt MS local functions
  528. */
  529. static void
  530. bfa_fcs_port_ms_send_plogi(void *ms_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  531. {
  532. struct bfa_fcs_port_ms_s *ms = ms_cbarg;
  533. struct bfa_fcs_port_s *port = ms->port;
  534. struct fchs_s fchs;
  535. int len;
  536. struct bfa_fcxp_s *fcxp;
  537. bfa_trc(port->fcs, port->pid);
  538. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  539. if (!fcxp) {
  540. port->stats.ms_plogi_alloc_wait++;
  541. bfa_fcxp_alloc_wait(port->fcs->bfa, &ms->fcxp_wqe,
  542. bfa_fcs_port_ms_send_plogi, ms);
  543. return;
  544. }
  545. ms->fcxp = fcxp;
  546. len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  547. bfa_os_hton3b(FC_MGMT_SERVER),
  548. bfa_fcs_port_get_fcid(port), 0,
  549. port->port_cfg.pwwn, port->port_cfg.nwwn,
  550. bfa_fcport_get_maxfrsize(port->fcs->bfa));
  551. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  552. FC_CLASS_3, len, &fchs, bfa_fcs_port_ms_plogi_response,
  553. (void *)ms, FC_MAX_PDUSZ, FC_ELS_TOV);
  554. port->stats.ms_plogi_sent++;
  555. bfa_sm_send_event(ms, MSSM_EVENT_FCXP_SENT);
  556. }
  557. static void
  558. bfa_fcs_port_ms_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  559. void *cbarg, bfa_status_t req_status,
  560. u32 rsp_len, u32 resid_len,
  561. struct fchs_s *rsp_fchs)
  562. {
  563. struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)cbarg;
  564. struct bfa_fcs_port_s *port = ms->port;
  565. struct fc_els_cmd_s *els_cmd;
  566. struct fc_ls_rjt_s *ls_rjt;
  567. bfa_trc(port->fcs, req_status);
  568. bfa_trc(port->fcs, port->port_cfg.pwwn);
  569. /*
  570. * Sanity Checks
  571. */
  572. if (req_status != BFA_STATUS_OK) {
  573. port->stats.ms_plogi_rsp_err++;
  574. bfa_trc(port->fcs, req_status);
  575. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  576. return;
  577. }
  578. els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
  579. switch (els_cmd->els_code) {
  580. case FC_ELS_ACC:
  581. if (rsp_len < sizeof(struct fc_logi_s)) {
  582. bfa_trc(port->fcs, rsp_len);
  583. port->stats.ms_plogi_acc_err++;
  584. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  585. break;
  586. }
  587. port->stats.ms_plogi_accepts++;
  588. bfa_sm_send_event(ms, MSSM_EVENT_RSP_OK);
  589. break;
  590. case FC_ELS_LS_RJT:
  591. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  592. bfa_trc(port->fcs, ls_rjt->reason_code);
  593. bfa_trc(port->fcs, ls_rjt->reason_code_expl);
  594. port->stats.ms_rejects++;
  595. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  596. break;
  597. default:
  598. port->stats.ms_plogi_unknown_rsp++;
  599. bfa_trc(port->fcs, els_cmd->els_code);
  600. bfa_sm_send_event(ms, MSSM_EVENT_RSP_ERROR);
  601. }
  602. }
  603. static void
  604. bfa_fcs_port_ms_timeout(void *arg)
  605. {
  606. struct bfa_fcs_port_ms_s *ms = (struct bfa_fcs_port_ms_s *)arg;
  607. ms->port->stats.ms_timeouts++;
  608. bfa_sm_send_event(ms, MSSM_EVENT_TIMEOUT);
  609. }
  610. void
  611. bfa_fcs_port_ms_init(struct bfa_fcs_port_s *port)
  612. {
  613. struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  614. ms->port = port;
  615. bfa_sm_set_state(ms, bfa_fcs_port_ms_sm_offline);
  616. /*
  617. * Invoke init routines of sub modules.
  618. */
  619. bfa_fcs_port_fdmi_init(ms);
  620. }
  621. void
  622. bfa_fcs_port_ms_offline(struct bfa_fcs_port_s *port)
  623. {
  624. struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  625. ms->port = port;
  626. bfa_sm_send_event(ms, MSSM_EVENT_PORT_OFFLINE);
  627. bfa_fcs_port_fdmi_offline(ms);
  628. }
  629. void
  630. bfa_fcs_port_ms_online(struct bfa_fcs_port_s *port)
  631. {
  632. struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  633. ms->port = port;
  634. bfa_sm_send_event(ms, MSSM_EVENT_PORT_ONLINE);
  635. }
  636. void
  637. bfa_fcs_port_ms_fabric_rscn(struct bfa_fcs_port_s *port)
  638. {
  639. struct bfa_fcs_port_ms_s *ms = BFA_FCS_GET_MS_FROM_PORT(port);
  640. /*
  641. * @todo. Handle this only when in Online state
  642. */
  643. if (bfa_sm_cmp_state(ms, bfa_fcs_port_ms_sm_online))
  644. bfa_sm_send_event(ms, MSSM_EVENT_PORT_FABRIC_RSCN);
  645. }