vport.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  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. * bfa_fcs_vport.c FCS virtual port state machine
  19. */
  20. #include <bfa.h>
  21. #include <bfa_svc.h>
  22. #include <fcbuild.h>
  23. #include "fcs_fabric.h"
  24. #include "fcs_lport.h"
  25. #include "fcs_vport.h"
  26. #include "fcs_trcmod.h"
  27. #include "fcs.h"
  28. #include <aen/bfa_aen_lport.h>
  29. BFA_TRC_FILE(FCS, VPORT);
  30. #define __vport_fcs(__vp) ((__vp)->lport.fcs)
  31. #define __vport_pwwn(__vp) ((__vp)->lport.port_cfg.pwwn)
  32. #define __vport_nwwn(__vp) ((__vp)->lport.port_cfg.nwwn)
  33. #define __vport_bfa(__vp) ((__vp)->lport.fcs->bfa)
  34. #define __vport_fcid(__vp) ((__vp)->lport.pid)
  35. #define __vport_fabric(__vp) ((__vp)->lport.fabric)
  36. #define __vport_vfid(__vp) ((__vp)->lport.fabric->vf_id)
  37. #define BFA_FCS_VPORT_MAX_RETRIES 5
  38. /*
  39. * Forward declarations
  40. */
  41. static void bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport);
  42. static void bfa_fcs_vport_timeout(void *vport_arg);
  43. static void bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport);
  44. static void bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport);
  45. /**
  46. * fcs_vport_sm FCS virtual port state machine
  47. */
  48. /**
  49. * VPort State Machine events
  50. */
  51. enum bfa_fcs_vport_event {
  52. BFA_FCS_VPORT_SM_CREATE = 1, /* vport create event */
  53. BFA_FCS_VPORT_SM_DELETE = 2, /* vport delete event */
  54. BFA_FCS_VPORT_SM_START = 3, /* vport start request */
  55. BFA_FCS_VPORT_SM_STOP = 4, /* stop: unsupported */
  56. BFA_FCS_VPORT_SM_ONLINE = 5, /* fabric online */
  57. BFA_FCS_VPORT_SM_OFFLINE = 6, /* fabric offline event */
  58. BFA_FCS_VPORT_SM_FRMSENT = 7, /* fdisc/logo sent events */
  59. BFA_FCS_VPORT_SM_RSP_OK = 8, /* good response */
  60. BFA_FCS_VPORT_SM_RSP_ERROR = 9, /* error/bad response */
  61. BFA_FCS_VPORT_SM_TIMEOUT = 10, /* delay timer event */
  62. BFA_FCS_VPORT_SM_DELCOMP = 11, /* lport delete completion */
  63. BFA_FCS_VPORT_SM_RSP_DUP_WWN = 12, /* Dup wnn error */
  64. BFA_FCS_VPORT_SM_RSP_FAILED = 13, /* non-retryable failure */
  65. };
  66. static void bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
  67. enum bfa_fcs_vport_event event);
  68. static void bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
  69. enum bfa_fcs_vport_event event);
  70. static void bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
  71. enum bfa_fcs_vport_event event);
  72. static void bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
  73. enum bfa_fcs_vport_event event);
  74. static void bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
  75. enum bfa_fcs_vport_event event);
  76. static void bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
  77. enum bfa_fcs_vport_event event);
  78. static void bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
  79. enum bfa_fcs_vport_event event);
  80. static void bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
  81. enum bfa_fcs_vport_event event);
  82. static void bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
  83. enum bfa_fcs_vport_event event);
  84. static void bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
  85. enum bfa_fcs_vport_event event);
  86. static struct bfa_sm_table_s vport_sm_table[] = {
  87. {BFA_SM(bfa_fcs_vport_sm_uninit), BFA_FCS_VPORT_UNINIT},
  88. {BFA_SM(bfa_fcs_vport_sm_created), BFA_FCS_VPORT_CREATED},
  89. {BFA_SM(bfa_fcs_vport_sm_offline), BFA_FCS_VPORT_OFFLINE},
  90. {BFA_SM(bfa_fcs_vport_sm_fdisc), BFA_FCS_VPORT_FDISC},
  91. {BFA_SM(bfa_fcs_vport_sm_fdisc_retry), BFA_FCS_VPORT_FDISC_RETRY},
  92. {BFA_SM(bfa_fcs_vport_sm_online), BFA_FCS_VPORT_ONLINE},
  93. {BFA_SM(bfa_fcs_vport_sm_deleting), BFA_FCS_VPORT_DELETING},
  94. {BFA_SM(bfa_fcs_vport_sm_cleanup), BFA_FCS_VPORT_CLEANUP},
  95. {BFA_SM(bfa_fcs_vport_sm_logo), BFA_FCS_VPORT_LOGO},
  96. {BFA_SM(bfa_fcs_vport_sm_error), BFA_FCS_VPORT_ERROR}
  97. };
  98. /**
  99. * Beginning state.
  100. */
  101. static void
  102. bfa_fcs_vport_sm_uninit(struct bfa_fcs_vport_s *vport,
  103. enum bfa_fcs_vport_event event)
  104. {
  105. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  106. bfa_trc(__vport_fcs(vport), event);
  107. switch (event) {
  108. case BFA_FCS_VPORT_SM_CREATE:
  109. bfa_sm_set_state(vport, bfa_fcs_vport_sm_created);
  110. bfa_fcs_fabric_addvport(__vport_fabric(vport), vport);
  111. break;
  112. default:
  113. bfa_sm_fault(__vport_fcs(vport), event);
  114. }
  115. }
  116. /**
  117. * Created state - a start event is required to start up the state machine.
  118. */
  119. static void
  120. bfa_fcs_vport_sm_created(struct bfa_fcs_vport_s *vport,
  121. enum bfa_fcs_vport_event event)
  122. {
  123. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  124. bfa_trc(__vport_fcs(vport), event);
  125. switch (event) {
  126. case BFA_FCS_VPORT_SM_START:
  127. if (bfa_fcs_fabric_is_online(__vport_fabric(vport))
  128. && bfa_fcs_fabric_npiv_capable(__vport_fabric(vport))) {
  129. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
  130. bfa_fcs_vport_do_fdisc(vport);
  131. } else {
  132. /**
  133. * Fabric is offline or not NPIV capable, stay in
  134. * offline state.
  135. */
  136. vport->vport_stats.fab_no_npiv++;
  137. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  138. }
  139. break;
  140. case BFA_FCS_VPORT_SM_DELETE:
  141. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  142. bfa_fcs_port_delete(&vport->lport);
  143. break;
  144. case BFA_FCS_VPORT_SM_ONLINE:
  145. case BFA_FCS_VPORT_SM_OFFLINE:
  146. /**
  147. * Ignore ONLINE/OFFLINE events from fabric till vport is started.
  148. */
  149. break;
  150. default:
  151. bfa_sm_fault(__vport_fcs(vport), event);
  152. }
  153. }
  154. /**
  155. * Offline state - awaiting ONLINE event from fabric SM.
  156. */
  157. static void
  158. bfa_fcs_vport_sm_offline(struct bfa_fcs_vport_s *vport,
  159. enum bfa_fcs_vport_event event)
  160. {
  161. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  162. bfa_trc(__vport_fcs(vport), event);
  163. switch (event) {
  164. case BFA_FCS_VPORT_SM_DELETE:
  165. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  166. bfa_fcs_port_delete(&vport->lport);
  167. break;
  168. case BFA_FCS_VPORT_SM_ONLINE:
  169. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
  170. vport->fdisc_retries = 0;
  171. bfa_fcs_vport_do_fdisc(vport);
  172. break;
  173. case BFA_FCS_VPORT_SM_OFFLINE:
  174. /*
  175. * This can happen if the vport couldn't be initialzied due
  176. * the fact that the npiv was not enabled on the switch. In
  177. * that case we will put the vport in offline state. However,
  178. * the link can go down and cause the this event to be sent when
  179. * we are already offline. Ignore it.
  180. */
  181. break;
  182. default:
  183. bfa_sm_fault(__vport_fcs(vport), event);
  184. }
  185. }
  186. /**
  187. * FDISC is sent and awaiting reply from fabric.
  188. */
  189. static void
  190. bfa_fcs_vport_sm_fdisc(struct bfa_fcs_vport_s *vport,
  191. enum bfa_fcs_vport_event event)
  192. {
  193. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  194. bfa_trc(__vport_fcs(vport), event);
  195. switch (event) {
  196. case BFA_FCS_VPORT_SM_DELETE:
  197. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  198. bfa_lps_discard(vport->lps);
  199. bfa_fcs_port_delete(&vport->lport);
  200. break;
  201. case BFA_FCS_VPORT_SM_OFFLINE:
  202. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  203. bfa_lps_discard(vport->lps);
  204. break;
  205. case BFA_FCS_VPORT_SM_RSP_OK:
  206. bfa_sm_set_state(vport, bfa_fcs_vport_sm_online);
  207. bfa_fcs_port_online(&vport->lport);
  208. break;
  209. case BFA_FCS_VPORT_SM_RSP_ERROR:
  210. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc_retry);
  211. bfa_timer_start(__vport_bfa(vport), &vport->timer,
  212. bfa_fcs_vport_timeout, vport,
  213. BFA_FCS_RETRY_TIMEOUT);
  214. break;
  215. case BFA_FCS_VPORT_SM_RSP_FAILED:
  216. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  217. break;
  218. case BFA_FCS_VPORT_SM_RSP_DUP_WWN:
  219. bfa_sm_set_state(vport, bfa_fcs_vport_sm_error);
  220. break;
  221. default:
  222. bfa_sm_fault(__vport_fcs(vport), event);
  223. }
  224. }
  225. /**
  226. * FDISC attempt failed - a timer is active to retry FDISC.
  227. */
  228. static void
  229. bfa_fcs_vport_sm_fdisc_retry(struct bfa_fcs_vport_s *vport,
  230. enum bfa_fcs_vport_event event)
  231. {
  232. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  233. bfa_trc(__vport_fcs(vport), event);
  234. switch (event) {
  235. case BFA_FCS_VPORT_SM_DELETE:
  236. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  237. bfa_timer_stop(&vport->timer);
  238. bfa_fcs_port_delete(&vport->lport);
  239. break;
  240. case BFA_FCS_VPORT_SM_OFFLINE:
  241. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  242. bfa_timer_stop(&vport->timer);
  243. break;
  244. case BFA_FCS_VPORT_SM_TIMEOUT:
  245. bfa_sm_set_state(vport, bfa_fcs_vport_sm_fdisc);
  246. vport->vport_stats.fdisc_retries++;
  247. vport->fdisc_retries++;
  248. bfa_fcs_vport_do_fdisc(vport);
  249. break;
  250. default:
  251. bfa_sm_fault(__vport_fcs(vport), event);
  252. }
  253. }
  254. /**
  255. * Vport is online (FDISC is complete).
  256. */
  257. static void
  258. bfa_fcs_vport_sm_online(struct bfa_fcs_vport_s *vport,
  259. enum bfa_fcs_vport_event event)
  260. {
  261. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  262. bfa_trc(__vport_fcs(vport), event);
  263. switch (event) {
  264. case BFA_FCS_VPORT_SM_DELETE:
  265. bfa_sm_set_state(vport, bfa_fcs_vport_sm_deleting);
  266. bfa_fcs_port_delete(&vport->lport);
  267. break;
  268. case BFA_FCS_VPORT_SM_OFFLINE:
  269. bfa_sm_set_state(vport, bfa_fcs_vport_sm_offline);
  270. bfa_lps_discard(vport->lps);
  271. bfa_fcs_port_offline(&vport->lport);
  272. break;
  273. default:
  274. bfa_sm_fault(__vport_fcs(vport), event);
  275. }
  276. }
  277. /**
  278. * Vport is being deleted - awaiting lport delete completion to send
  279. * LOGO to fabric.
  280. */
  281. static void
  282. bfa_fcs_vport_sm_deleting(struct bfa_fcs_vport_s *vport,
  283. enum bfa_fcs_vport_event event)
  284. {
  285. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  286. bfa_trc(__vport_fcs(vport), event);
  287. switch (event) {
  288. case BFA_FCS_VPORT_SM_DELETE:
  289. break;
  290. case BFA_FCS_VPORT_SM_DELCOMP:
  291. bfa_sm_set_state(vport, bfa_fcs_vport_sm_logo);
  292. bfa_fcs_vport_do_logo(vport);
  293. break;
  294. case BFA_FCS_VPORT_SM_OFFLINE:
  295. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  296. break;
  297. default:
  298. bfa_sm_fault(__vport_fcs(vport), event);
  299. }
  300. }
  301. /**
  302. * Error State.
  303. * This state will be set when the Vport Creation fails due to errors like
  304. * Dup WWN. In this state only operation allowed is a Vport Delete.
  305. */
  306. static void
  307. bfa_fcs_vport_sm_error(struct bfa_fcs_vport_s *vport,
  308. enum bfa_fcs_vport_event event)
  309. {
  310. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  311. bfa_trc(__vport_fcs(vport), event);
  312. switch (event) {
  313. case BFA_FCS_VPORT_SM_DELETE:
  314. bfa_sm_set_state(vport, bfa_fcs_vport_sm_cleanup);
  315. bfa_fcs_port_delete(&vport->lport);
  316. break;
  317. default:
  318. bfa_trc(__vport_fcs(vport), event);
  319. }
  320. }
  321. /**
  322. * Lport cleanup is in progress since vport is being deleted. Fabric is
  323. * offline, so no LOGO is needed to complete vport deletion.
  324. */
  325. static void
  326. bfa_fcs_vport_sm_cleanup(struct bfa_fcs_vport_s *vport,
  327. enum bfa_fcs_vport_event event)
  328. {
  329. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  330. bfa_trc(__vport_fcs(vport), event);
  331. switch (event) {
  332. case BFA_FCS_VPORT_SM_DELCOMP:
  333. bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
  334. bfa_fcs_vport_free(vport);
  335. break;
  336. case BFA_FCS_VPORT_SM_DELETE:
  337. break;
  338. default:
  339. bfa_sm_fault(__vport_fcs(vport), event);
  340. }
  341. }
  342. /**
  343. * LOGO is sent to fabric. Vport delete is in progress. Lport delete cleanup
  344. * is done.
  345. */
  346. static void
  347. bfa_fcs_vport_sm_logo(struct bfa_fcs_vport_s *vport,
  348. enum bfa_fcs_vport_event event)
  349. {
  350. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  351. bfa_trc(__vport_fcs(vport), event);
  352. switch (event) {
  353. case BFA_FCS_VPORT_SM_OFFLINE:
  354. bfa_lps_discard(vport->lps);
  355. /*
  356. * !!! fall through !!!
  357. */
  358. case BFA_FCS_VPORT_SM_RSP_OK:
  359. case BFA_FCS_VPORT_SM_RSP_ERROR:
  360. bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
  361. bfa_fcs_vport_free(vport);
  362. break;
  363. case BFA_FCS_VPORT_SM_DELETE:
  364. break;
  365. default:
  366. bfa_sm_fault(__vport_fcs(vport), event);
  367. }
  368. }
  369. /**
  370. * fcs_vport_private FCS virtual port private functions
  371. */
  372. /**
  373. * Send AEN notification
  374. */
  375. static void
  376. bfa_fcs_vport_aen_post(bfa_fcs_lport_t *port, enum bfa_lport_aen_event event)
  377. {
  378. union bfa_aen_data_u aen_data;
  379. struct bfa_log_mod_s *logmod = port->fcs->logm;
  380. enum bfa_port_role role = port->port_cfg.roles;
  381. wwn_t lpwwn = bfa_fcs_port_get_pwwn(port);
  382. char lpwwn_ptr[BFA_STRING_32];
  383. char *role_str[BFA_PORT_ROLE_FCP_MAX / 2 + 1] =
  384. { "Initiator", "Target", "IPFC" };
  385. wwn2str(lpwwn_ptr, lpwwn);
  386. bfa_assert(role <= BFA_PORT_ROLE_FCP_MAX);
  387. bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_LPORT, event), lpwwn_ptr,
  388. role_str[role/2]);
  389. aen_data.lport.vf_id = port->fabric->vf_id;
  390. aen_data.lport.roles = role;
  391. aen_data.lport.ppwwn =
  392. bfa_fcs_port_get_pwwn(bfa_fcs_get_base_port(port->fcs));
  393. aen_data.lport.lpwwn = lpwwn;
  394. }
  395. /**
  396. * This routine will be called to send a FDISC command.
  397. */
  398. static void
  399. bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
  400. {
  401. bfa_lps_fdisc(vport->lps, vport,
  402. bfa_fcport_get_maxfrsize(__vport_bfa(vport)),
  403. __vport_pwwn(vport), __vport_nwwn(vport));
  404. vport->vport_stats.fdisc_sent++;
  405. }
  406. static void
  407. bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
  408. {
  409. u8 lsrjt_rsn = bfa_lps_get_lsrjt_rsn(vport->lps);
  410. u8 lsrjt_expl = bfa_lps_get_lsrjt_expl(vport->lps);
  411. bfa_trc(__vport_fcs(vport), lsrjt_rsn);
  412. bfa_trc(__vport_fcs(vport), lsrjt_expl);
  413. /*
  414. * For certain reason codes, we don't want to retry.
  415. */
  416. switch (bfa_lps_get_lsrjt_expl(vport->lps)) {
  417. case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
  418. case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
  419. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  420. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  421. else {
  422. bfa_fcs_vport_aen_post(&vport->lport,
  423. BFA_LPORT_AEN_NPIV_DUP_WWN);
  424. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
  425. }
  426. break;
  427. case FC_LS_RJT_EXP_INSUFF_RES:
  428. /*
  429. * This means max logins per port/switch setting on the
  430. * switch was exceeded.
  431. */
  432. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  433. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  434. else {
  435. bfa_fcs_vport_aen_post(&vport->lport,
  436. BFA_LPORT_AEN_NPIV_FABRIC_MAX);
  437. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
  438. }
  439. break;
  440. default:
  441. if (vport->fdisc_retries == 0) /* Print only once */
  442. bfa_fcs_vport_aen_post(&vport->lport,
  443. BFA_LPORT_AEN_NPIV_UNKNOWN);
  444. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  445. }
  446. }
  447. /**
  448. * Called to send a logout to the fabric. Used when a V-Port is
  449. * deleted/stopped.
  450. */
  451. static void
  452. bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
  453. {
  454. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  455. vport->vport_stats.logo_sent++;
  456. bfa_lps_fdisclogo(vport->lps);
  457. }
  458. /**
  459. * This routine will be called by bfa_timer on timer timeouts.
  460. *
  461. * param[in] vport - pointer to bfa_fcs_vport_t.
  462. * param[out] vport_status - pointer to return vport status in
  463. *
  464. * return
  465. * void
  466. *
  467. * Special Considerations:
  468. *
  469. * note
  470. */
  471. static void
  472. bfa_fcs_vport_timeout(void *vport_arg)
  473. {
  474. struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *)vport_arg;
  475. vport->vport_stats.fdisc_timeouts++;
  476. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
  477. }
  478. static void
  479. bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
  480. {
  481. bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
  482. bfa_fcb_vport_delete(vport->vport_drv);
  483. bfa_lps_delete(vport->lps);
  484. }
  485. /**
  486. * fcs_vport_public FCS virtual port public interfaces
  487. */
  488. /**
  489. * Online notification from fabric SM.
  490. */
  491. void
  492. bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
  493. {
  494. vport->vport_stats.fab_online++;
  495. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
  496. }
  497. /**
  498. * Offline notification from fabric SM.
  499. */
  500. void
  501. bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
  502. {
  503. vport->vport_stats.fab_offline++;
  504. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
  505. }
  506. /**
  507. * Cleanup notification from fabric SM on link timer expiry.
  508. */
  509. void
  510. bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
  511. {
  512. vport->vport_stats.fab_cleanup++;
  513. }
  514. /**
  515. * delete notification from fabric SM. To be invoked from within FCS.
  516. */
  517. void
  518. bfa_fcs_vport_fcs_delete(struct bfa_fcs_vport_s *vport)
  519. {
  520. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
  521. }
  522. /**
  523. * Delete completion callback from associated lport
  524. */
  525. void
  526. bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
  527. {
  528. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
  529. }
  530. /**
  531. * fcs_vport_api Virtual port API
  532. */
  533. /**
  534. * Use this function to instantiate a new FCS vport object. This
  535. * function will not trigger any HW initialization process (which will be
  536. * done in vport_start() call)
  537. *
  538. * param[in] vport - pointer to bfa_fcs_vport_t. This space
  539. * needs to be allocated by the driver.
  540. * param[in] fcs - FCS instance
  541. * param[in] vport_cfg - vport configuration
  542. * param[in] vf_id - VF_ID if vport is created within a VF.
  543. * FC_VF_ID_NULL to specify base fabric.
  544. * param[in] vport_drv - Opaque handle back to the driver's vport
  545. * structure
  546. *
  547. * retval BFA_STATUS_OK - on success.
  548. * retval BFA_STATUS_FAILED - on failure.
  549. */
  550. bfa_status_t
  551. bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
  552. u16 vf_id, struct bfa_port_cfg_s *vport_cfg,
  553. struct bfad_vport_s *vport_drv)
  554. {
  555. if (vport_cfg->pwwn == 0)
  556. return BFA_STATUS_INVALID_WWN;
  557. if (bfa_fcs_port_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
  558. return BFA_STATUS_VPORT_WWN_BP;
  559. if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
  560. return BFA_STATUS_VPORT_EXISTS;
  561. if (bfa_fcs_fabric_vport_count(&fcs->fabric) ==
  562. bfa_lps_get_max_vport(fcs->bfa))
  563. return BFA_STATUS_VPORT_MAX;
  564. vport->lps = bfa_lps_alloc(fcs->bfa);
  565. if (!vport->lps)
  566. return BFA_STATUS_VPORT_MAX;
  567. vport->vport_drv = vport_drv;
  568. vport_cfg->preboot_vp = BFA_FALSE;
  569. bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
  570. bfa_fcs_lport_attach(&vport->lport, fcs, vf_id, vport);
  571. bfa_fcs_lport_init(&vport->lport, vport_cfg);
  572. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
  573. return BFA_STATUS_OK;
  574. }
  575. /**
  576. * Use this function to instantiate a new FCS PBC vport object. This
  577. * function will not trigger any HW initialization process (which will be
  578. * done in vport_start() call)
  579. *
  580. * param[in] vport - pointer to bfa_fcs_vport_t. This space
  581. * needs to be allocated by the driver.
  582. * param[in] fcs - FCS instance
  583. * param[in] vport_cfg - vport configuration
  584. * param[in] vf_id - VF_ID if vport is created within a VF.
  585. * FC_VF_ID_NULL to specify base fabric.
  586. * param[in] vport_drv - Opaque handle back to the driver's vport
  587. * structure
  588. *
  589. * retval BFA_STATUS_OK - on success.
  590. * retval BFA_STATUS_FAILED - on failure.
  591. */
  592. bfa_status_t
  593. bfa_fcs_pbc_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
  594. uint16_t vf_id, struct bfa_port_cfg_s *vport_cfg,
  595. struct bfad_vport_s *vport_drv)
  596. {
  597. bfa_status_t rc;
  598. rc = bfa_fcs_vport_create(vport, fcs, vf_id, vport_cfg, vport_drv);
  599. vport->lport.port_cfg.preboot_vp = BFA_TRUE;
  600. return rc;
  601. }
  602. /**
  603. * Use this function initialize the vport.
  604. *
  605. * @param[in] vport - pointer to bfa_fcs_vport_t.
  606. *
  607. * @returns None
  608. */
  609. bfa_status_t
  610. bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
  611. {
  612. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
  613. return BFA_STATUS_OK;
  614. }
  615. /**
  616. * Use this function quiese the vport object. This function will return
  617. * immediately, when the vport is actually stopped, the
  618. * bfa_drv_vport_stop_cb() will be called.
  619. *
  620. * param[in] vport - pointer to bfa_fcs_vport_t.
  621. *
  622. * return None
  623. */
  624. bfa_status_t
  625. bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
  626. {
  627. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
  628. return BFA_STATUS_OK;
  629. }
  630. /**
  631. * Use this function to delete a vport object. Fabric object should
  632. * be stopped before this function call.
  633. *
  634. * Donot invoke this from within FCS
  635. *
  636. * param[in] vport - pointer to bfa_fcs_vport_t.
  637. *
  638. * return None
  639. */
  640. bfa_status_t
  641. bfa_fcs_vport_delete(struct bfa_fcs_vport_s *vport)
  642. {
  643. if (vport->lport.port_cfg.preboot_vp)
  644. return BFA_STATUS_PBC;
  645. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
  646. return BFA_STATUS_OK;
  647. }
  648. /**
  649. * Use this function to get vport's current status info.
  650. *
  651. * param[in] vport pointer to bfa_fcs_vport_t.
  652. * param[out] attr pointer to return vport attributes
  653. *
  654. * return None
  655. */
  656. void
  657. bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
  658. struct bfa_vport_attr_s *attr)
  659. {
  660. if (vport == NULL || attr == NULL)
  661. return;
  662. bfa_os_memset(attr, 0, sizeof(struct bfa_vport_attr_s));
  663. bfa_fcs_port_get_attr(&vport->lport, &attr->port_attr);
  664. attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
  665. }
  666. /**
  667. * Use this function to get vport's statistics.
  668. *
  669. * param[in] vport pointer to bfa_fcs_vport_t.
  670. * param[out] stats pointer to return vport statistics in
  671. *
  672. * return None
  673. */
  674. void
  675. bfa_fcs_vport_get_stats(struct bfa_fcs_vport_s *vport,
  676. struct bfa_vport_stats_s *stats)
  677. {
  678. *stats = vport->vport_stats;
  679. }
  680. /**
  681. * Use this function to clear vport's statistics.
  682. *
  683. * param[in] vport pointer to bfa_fcs_vport_t.
  684. *
  685. * return None
  686. */
  687. void
  688. bfa_fcs_vport_clr_stats(struct bfa_fcs_vport_s *vport)
  689. {
  690. bfa_os_memset(&vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s));
  691. }
  692. /**
  693. * Lookup a virtual port. Excludes base port from lookup.
  694. */
  695. struct bfa_fcs_vport_s *
  696. bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
  697. {
  698. struct bfa_fcs_vport_s *vport;
  699. struct bfa_fcs_fabric_s *fabric;
  700. bfa_trc(fcs, vf_id);
  701. bfa_trc(fcs, vpwwn);
  702. fabric = bfa_fcs_vf_lookup(fcs, vf_id);
  703. if (!fabric) {
  704. bfa_trc(fcs, vf_id);
  705. return NULL;
  706. }
  707. vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
  708. return vport;
  709. }
  710. /**
  711. * FDISC Response
  712. */
  713. void
  714. bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
  715. {
  716. struct bfa_fcs_vport_s *vport = uarg;
  717. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  718. bfa_trc(__vport_fcs(vport), status);
  719. switch (status) {
  720. case BFA_STATUS_OK:
  721. /*
  722. * Initialize the V-Port fields
  723. */
  724. __vport_fcid(vport) = bfa_lps_get_pid(vport->lps);
  725. vport->vport_stats.fdisc_accepts++;
  726. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
  727. break;
  728. case BFA_STATUS_INVALID_MAC:
  729. /*
  730. * Only for CNA
  731. */
  732. vport->vport_stats.fdisc_acc_bad++;
  733. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  734. break;
  735. case BFA_STATUS_EPROTOCOL:
  736. switch (bfa_lps_get_extstatus(vport->lps)) {
  737. case BFA_EPROTO_BAD_ACCEPT:
  738. vport->vport_stats.fdisc_acc_bad++;
  739. break;
  740. case BFA_EPROTO_UNKNOWN_RSP:
  741. vport->vport_stats.fdisc_unknown_rsp++;
  742. break;
  743. default:
  744. break;
  745. }
  746. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  747. break;
  748. case BFA_STATUS_FABRIC_RJT:
  749. vport->vport_stats.fdisc_rejects++;
  750. bfa_fcs_vport_fdisc_rejected(vport);
  751. break;
  752. default:
  753. vport->vport_stats.fdisc_rsp_err++;
  754. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  755. }
  756. }
  757. /**
  758. * LOGO response
  759. */
  760. void
  761. bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
  762. {
  763. struct bfa_fcs_vport_s *vport = uarg;
  764. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
  765. }
  766. /**
  767. * Received clear virtual link
  768. */
  769. void
  770. bfa_cb_lps_cvl_event(void *bfad, void *uarg)
  771. {
  772. struct bfa_fcs_vport_s *vport = uarg;
  773. /* Send an Offline followed by an ONLINE */
  774. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
  775. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
  776. }