vport.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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_assert(0);
  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_assert(0);
  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_assert(0);
  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_logo);
  198. bfa_lps_discard(vport->lps);
  199. bfa_fcs_vport_do_logo(vport);
  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_assert(0);
  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_assert(0);
  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_assert(0);
  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_assert(0);
  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_uninit);
  315. bfa_fcs_vport_free(vport);
  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_assert(0);
  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_assert(0);
  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. switch (event) {
  388. case BFA_LPORT_AEN_NPIV_DUP_WWN:
  389. bfa_log(logmod, BFA_AEN_LPORT_NPIV_DUP_WWN, lpwwn_ptr,
  390. role_str[role / 2]);
  391. break;
  392. case BFA_LPORT_AEN_NPIV_FABRIC_MAX:
  393. bfa_log(logmod, BFA_AEN_LPORT_NPIV_FABRIC_MAX, lpwwn_ptr,
  394. role_str[role / 2]);
  395. break;
  396. case BFA_LPORT_AEN_NPIV_UNKNOWN:
  397. bfa_log(logmod, BFA_AEN_LPORT_NPIV_UNKNOWN, lpwwn_ptr,
  398. role_str[role / 2]);
  399. break;
  400. default:
  401. break;
  402. }
  403. aen_data.lport.vf_id = port->fabric->vf_id;
  404. aen_data.lport.roles = role;
  405. aen_data.lport.ppwwn =
  406. bfa_fcs_port_get_pwwn(bfa_fcs_get_base_port(port->fcs));
  407. aen_data.lport.lpwwn = lpwwn;
  408. }
  409. /**
  410. * This routine will be called to send a FDISC command.
  411. */
  412. static void
  413. bfa_fcs_vport_do_fdisc(struct bfa_fcs_vport_s *vport)
  414. {
  415. bfa_lps_fdisc(vport->lps, vport,
  416. bfa_pport_get_maxfrsize(__vport_bfa(vport)),
  417. __vport_pwwn(vport), __vport_nwwn(vport));
  418. vport->vport_stats.fdisc_sent++;
  419. }
  420. static void
  421. bfa_fcs_vport_fdisc_rejected(struct bfa_fcs_vport_s *vport)
  422. {
  423. u8 lsrjt_rsn = bfa_lps_get_lsrjt_rsn(vport->lps);
  424. u8 lsrjt_expl = bfa_lps_get_lsrjt_expl(vport->lps);
  425. bfa_trc(__vport_fcs(vport), lsrjt_rsn);
  426. bfa_trc(__vport_fcs(vport), lsrjt_expl);
  427. /*
  428. * For certain reason codes, we don't want to retry.
  429. */
  430. switch (bfa_lps_get_lsrjt_expl(vport->lps)) {
  431. case FC_LS_RJT_EXP_INV_PORT_NAME: /* by brocade */
  432. case FC_LS_RJT_EXP_INVALID_NPORT_ID: /* by Cisco */
  433. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  434. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  435. else {
  436. bfa_fcs_vport_aen_post(&vport->lport,
  437. BFA_LPORT_AEN_NPIV_DUP_WWN);
  438. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_DUP_WWN);
  439. }
  440. break;
  441. case FC_LS_RJT_EXP_INSUFF_RES:
  442. /*
  443. * This means max logins per port/switch setting on the
  444. * switch was exceeded.
  445. */
  446. if (vport->fdisc_retries < BFA_FCS_VPORT_MAX_RETRIES)
  447. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  448. else {
  449. bfa_fcs_vport_aen_post(&vport->lport,
  450. BFA_LPORT_AEN_NPIV_FABRIC_MAX);
  451. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_FAILED);
  452. }
  453. break;
  454. default:
  455. if (vport->fdisc_retries == 0) /* Print only once */
  456. bfa_fcs_vport_aen_post(&vport->lport,
  457. BFA_LPORT_AEN_NPIV_UNKNOWN);
  458. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  459. }
  460. }
  461. /**
  462. * Called to send a logout to the fabric. Used when a V-Port is
  463. * deleted/stopped.
  464. */
  465. static void
  466. bfa_fcs_vport_do_logo(struct bfa_fcs_vport_s *vport)
  467. {
  468. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  469. vport->vport_stats.logo_sent++;
  470. bfa_lps_fdisclogo(vport->lps);
  471. }
  472. /**
  473. * This routine will be called by bfa_timer on timer timeouts.
  474. *
  475. * param[in] vport - pointer to bfa_fcs_vport_t.
  476. * param[out] vport_status - pointer to return vport status in
  477. *
  478. * return
  479. * void
  480. *
  481. * Special Considerations:
  482. *
  483. * note
  484. */
  485. static void
  486. bfa_fcs_vport_timeout(void *vport_arg)
  487. {
  488. struct bfa_fcs_vport_s *vport = (struct bfa_fcs_vport_s *)vport_arg;
  489. vport->vport_stats.fdisc_timeouts++;
  490. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_TIMEOUT);
  491. }
  492. static void
  493. bfa_fcs_vport_free(struct bfa_fcs_vport_s *vport)
  494. {
  495. bfa_fcs_fabric_delvport(__vport_fabric(vport), vport);
  496. bfa_fcb_vport_delete(vport->vport_drv);
  497. bfa_lps_delete(vport->lps);
  498. }
  499. /**
  500. * fcs_vport_public FCS virtual port public interfaces
  501. */
  502. /**
  503. * Online notification from fabric SM.
  504. */
  505. void
  506. bfa_fcs_vport_online(struct bfa_fcs_vport_s *vport)
  507. {
  508. vport->vport_stats.fab_online++;
  509. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_ONLINE);
  510. }
  511. /**
  512. * Offline notification from fabric SM.
  513. */
  514. void
  515. bfa_fcs_vport_offline(struct bfa_fcs_vport_s *vport)
  516. {
  517. vport->vport_stats.fab_offline++;
  518. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_OFFLINE);
  519. }
  520. /**
  521. * Cleanup notification from fabric SM on link timer expiry.
  522. */
  523. void
  524. bfa_fcs_vport_cleanup(struct bfa_fcs_vport_s *vport)
  525. {
  526. vport->vport_stats.fab_cleanup++;
  527. }
  528. /**
  529. * Delete completion callback from associated lport
  530. */
  531. void
  532. bfa_fcs_vport_delete_comp(struct bfa_fcs_vport_s *vport)
  533. {
  534. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELCOMP);
  535. }
  536. /**
  537. * Module initialization
  538. */
  539. void
  540. bfa_fcs_vport_modinit(struct bfa_fcs_s *fcs)
  541. {
  542. }
  543. /**
  544. * Module cleanup
  545. */
  546. void
  547. bfa_fcs_vport_modexit(struct bfa_fcs_s *fcs)
  548. {
  549. bfa_fcs_modexit_comp(fcs);
  550. }
  551. u32
  552. bfa_fcs_vport_get_max(struct bfa_fcs_s *fcs)
  553. {
  554. struct bfa_ioc_attr_s ioc_attr;
  555. bfa_get_attr(fcs->bfa, &ioc_attr);
  556. if (ioc_attr.pci_attr.device_id == BFA_PCI_DEVICE_ID_CT)
  557. return BFA_FCS_MAX_VPORTS_SUPP_CT;
  558. else
  559. return BFA_FCS_MAX_VPORTS_SUPP_CB;
  560. }
  561. /**
  562. * fcs_vport_api Virtual port API
  563. */
  564. /**
  565. * Use this function to instantiate a new FCS vport object. This
  566. * function will not trigger any HW initialization process (which will be
  567. * done in vport_start() call)
  568. *
  569. * param[in] vport - pointer to bfa_fcs_vport_t. This space
  570. * needs to be allocated by the driver.
  571. * param[in] fcs - FCS instance
  572. * param[in] vport_cfg - vport configuration
  573. * param[in] vf_id - VF_ID if vport is created within a VF.
  574. * FC_VF_ID_NULL to specify base fabric.
  575. * param[in] vport_drv - Opaque handle back to the driver's vport
  576. * structure
  577. *
  578. * retval BFA_STATUS_OK - on success.
  579. * retval BFA_STATUS_FAILED - on failure.
  580. */
  581. bfa_status_t
  582. bfa_fcs_vport_create(struct bfa_fcs_vport_s *vport, struct bfa_fcs_s *fcs,
  583. u16 vf_id, struct bfa_port_cfg_s *vport_cfg,
  584. struct bfad_vport_s *vport_drv)
  585. {
  586. if (vport_cfg->pwwn == 0)
  587. return BFA_STATUS_INVALID_WWN;
  588. if (bfa_fcs_port_get_pwwn(&fcs->fabric.bport) == vport_cfg->pwwn)
  589. return BFA_STATUS_VPORT_WWN_BP;
  590. if (bfa_fcs_vport_lookup(fcs, vf_id, vport_cfg->pwwn) != NULL)
  591. return BFA_STATUS_VPORT_EXISTS;
  592. if (bfa_fcs_fabric_vport_count(&fcs->fabric) ==
  593. bfa_fcs_vport_get_max(fcs))
  594. return BFA_STATUS_VPORT_MAX;
  595. vport->lps = bfa_lps_alloc(fcs->bfa);
  596. if (!vport->lps)
  597. return BFA_STATUS_VPORT_MAX;
  598. vport->vport_drv = vport_drv;
  599. bfa_sm_set_state(vport, bfa_fcs_vport_sm_uninit);
  600. bfa_fcs_lport_init(&vport->lport, fcs, vf_id, vport_cfg, vport);
  601. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_CREATE);
  602. return BFA_STATUS_OK;
  603. }
  604. /**
  605. * Use this function initialize the vport.
  606. *
  607. * @param[in] vport - pointer to bfa_fcs_vport_t.
  608. *
  609. * @returns None
  610. */
  611. bfa_status_t
  612. bfa_fcs_vport_start(struct bfa_fcs_vport_s *vport)
  613. {
  614. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_START);
  615. return BFA_STATUS_OK;
  616. }
  617. /**
  618. * Use this function quiese the vport object. This function will return
  619. * immediately, when the vport is actually stopped, the
  620. * bfa_drv_vport_stop_cb() will be called.
  621. *
  622. * param[in] vport - pointer to bfa_fcs_vport_t.
  623. *
  624. * return None
  625. */
  626. bfa_status_t
  627. bfa_fcs_vport_stop(struct bfa_fcs_vport_s *vport)
  628. {
  629. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_STOP);
  630. return BFA_STATUS_OK;
  631. }
  632. /**
  633. * Use this function to delete a vport object. Fabric object should
  634. * be stopped before this function call.
  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. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_DELETE);
  644. return BFA_STATUS_OK;
  645. }
  646. /**
  647. * Use this function to get vport's current status info.
  648. *
  649. * param[in] vport pointer to bfa_fcs_vport_t.
  650. * param[out] attr pointer to return vport attributes
  651. *
  652. * return None
  653. */
  654. void
  655. bfa_fcs_vport_get_attr(struct bfa_fcs_vport_s *vport,
  656. struct bfa_vport_attr_s *attr)
  657. {
  658. if (vport == NULL || attr == NULL)
  659. return;
  660. bfa_os_memset(attr, 0, sizeof(struct bfa_vport_attr_s));
  661. bfa_fcs_port_get_attr(&vport->lport, &attr->port_attr);
  662. attr->vport_state = bfa_sm_to_state(vport_sm_table, vport->sm);
  663. }
  664. /**
  665. * Use this function to get vport's statistics.
  666. *
  667. * param[in] vport pointer to bfa_fcs_vport_t.
  668. * param[out] stats pointer to return vport statistics in
  669. *
  670. * return None
  671. */
  672. void
  673. bfa_fcs_vport_get_stats(struct bfa_fcs_vport_s *vport,
  674. struct bfa_vport_stats_s *stats)
  675. {
  676. *stats = vport->vport_stats;
  677. }
  678. /**
  679. * Use this function to clear vport's statistics.
  680. *
  681. * param[in] vport pointer to bfa_fcs_vport_t.
  682. *
  683. * return None
  684. */
  685. void
  686. bfa_fcs_vport_clr_stats(struct bfa_fcs_vport_s *vport)
  687. {
  688. bfa_os_memset(&vport->vport_stats, 0, sizeof(struct bfa_vport_stats_s));
  689. }
  690. /**
  691. * Lookup a virtual port. Excludes base port from lookup.
  692. */
  693. struct bfa_fcs_vport_s *
  694. bfa_fcs_vport_lookup(struct bfa_fcs_s *fcs, u16 vf_id, wwn_t vpwwn)
  695. {
  696. struct bfa_fcs_vport_s *vport;
  697. struct bfa_fcs_fabric_s *fabric;
  698. bfa_trc(fcs, vf_id);
  699. bfa_trc(fcs, vpwwn);
  700. fabric = bfa_fcs_vf_lookup(fcs, vf_id);
  701. if (!fabric) {
  702. bfa_trc(fcs, vf_id);
  703. return NULL;
  704. }
  705. vport = bfa_fcs_fabric_vport_lookup(fabric, vpwwn);
  706. return vport;
  707. }
  708. /**
  709. * FDISC Response
  710. */
  711. void
  712. bfa_cb_lps_fdisc_comp(void *bfad, void *uarg, bfa_status_t status)
  713. {
  714. struct bfa_fcs_vport_s *vport = uarg;
  715. bfa_trc(__vport_fcs(vport), __vport_pwwn(vport));
  716. bfa_trc(__vport_fcs(vport), status);
  717. switch (status) {
  718. case BFA_STATUS_OK:
  719. /*
  720. * Initialiaze the V-Port fields
  721. */
  722. __vport_fcid(vport) = bfa_lps_get_pid(vport->lps);
  723. vport->vport_stats.fdisc_accepts++;
  724. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
  725. break;
  726. case BFA_STATUS_INVALID_MAC:
  727. /*
  728. * Only for CNA
  729. */
  730. vport->vport_stats.fdisc_acc_bad++;
  731. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  732. break;
  733. case BFA_STATUS_EPROTOCOL:
  734. switch (bfa_lps_get_extstatus(vport->lps)) {
  735. case BFA_EPROTO_BAD_ACCEPT:
  736. vport->vport_stats.fdisc_acc_bad++;
  737. break;
  738. case BFA_EPROTO_UNKNOWN_RSP:
  739. vport->vport_stats.fdisc_unknown_rsp++;
  740. break;
  741. default:
  742. break;
  743. }
  744. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  745. break;
  746. case BFA_STATUS_FABRIC_RJT:
  747. vport->vport_stats.fdisc_rejects++;
  748. bfa_fcs_vport_fdisc_rejected(vport);
  749. break;
  750. default:
  751. vport->vport_stats.fdisc_rsp_err++;
  752. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_ERROR);
  753. }
  754. }
  755. /**
  756. * LOGO response
  757. */
  758. void
  759. bfa_cb_lps_fdisclogo_comp(void *bfad, void *uarg)
  760. {
  761. struct bfa_fcs_vport_s *vport = uarg;
  762. bfa_sm_send_event(vport, BFA_FCS_VPORT_SM_RSP_OK);
  763. }