bfa_fcs_lport.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937
  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_port.c BFA FCS port
  19. */
  20. #include <fcs/bfa_fcs.h>
  21. #include <fcs/bfa_fcs_lport.h>
  22. #include <fcs/bfa_fcs_rport.h>
  23. #include <fcb/bfa_fcb_port.h>
  24. #include <bfa_svc.h>
  25. #include <log/bfa_log_fcs.h>
  26. #include "fcs.h"
  27. #include "fcs_lport.h"
  28. #include "fcs_vport.h"
  29. #include "fcs_rport.h"
  30. #include "fcs_fcxp.h"
  31. #include "fcs_trcmod.h"
  32. #include "lport_priv.h"
  33. #include <aen/bfa_aen_lport.h>
  34. BFA_TRC_FILE(FCS, PORT);
  35. /**
  36. * Forward declarations
  37. */
  38. static void bfa_fcs_port_aen_post(struct bfa_fcs_port_s *port,
  39. enum bfa_lport_aen_event event);
  40. static void bfa_fcs_port_send_ls_rjt(struct bfa_fcs_port_s *port,
  41. struct fchs_s *rx_fchs, u8 reason_code,
  42. u8 reason_code_expl);
  43. static void bfa_fcs_port_plogi(struct bfa_fcs_port_s *port,
  44. struct fchs_s *rx_fchs,
  45. struct fc_logi_s *plogi);
  46. static void bfa_fcs_port_online_actions(struct bfa_fcs_port_s *port);
  47. static void bfa_fcs_port_offline_actions(struct bfa_fcs_port_s *port);
  48. static void bfa_fcs_port_unknown_init(struct bfa_fcs_port_s *port);
  49. static void bfa_fcs_port_unknown_online(struct bfa_fcs_port_s *port);
  50. static void bfa_fcs_port_unknown_offline(struct bfa_fcs_port_s *port);
  51. static void bfa_fcs_port_deleted(struct bfa_fcs_port_s *port);
  52. static void bfa_fcs_port_echo(struct bfa_fcs_port_s *port,
  53. struct fchs_s *rx_fchs,
  54. struct fc_echo_s *echo, u16 len);
  55. static void bfa_fcs_port_rnid(struct bfa_fcs_port_s *port,
  56. struct fchs_s *rx_fchs,
  57. struct fc_rnid_cmd_s *rnid, u16 len);
  58. static void bfa_fs_port_get_gen_topo_data(struct bfa_fcs_port_s *port,
  59. struct fc_rnid_general_topology_data_s *gen_topo_data);
  60. static struct {
  61. void (*init) (struct bfa_fcs_port_s *port);
  62. void (*online) (struct bfa_fcs_port_s *port);
  63. void (*offline) (struct bfa_fcs_port_s *port);
  64. } __port_action[] = {
  65. {
  66. bfa_fcs_port_unknown_init, bfa_fcs_port_unknown_online,
  67. bfa_fcs_port_unknown_offline}, {
  68. bfa_fcs_port_fab_init, bfa_fcs_port_fab_online,
  69. bfa_fcs_port_fab_offline}, {
  70. bfa_fcs_port_loop_init, bfa_fcs_port_loop_online,
  71. bfa_fcs_port_loop_offline}, {
  72. bfa_fcs_port_n2n_init, bfa_fcs_port_n2n_online,
  73. bfa_fcs_port_n2n_offline},};
  74. /**
  75. * fcs_port_sm FCS logical port state machine
  76. */
  77. enum bfa_fcs_port_event {
  78. BFA_FCS_PORT_SM_CREATE = 1,
  79. BFA_FCS_PORT_SM_ONLINE = 2,
  80. BFA_FCS_PORT_SM_OFFLINE = 3,
  81. BFA_FCS_PORT_SM_DELETE = 4,
  82. BFA_FCS_PORT_SM_DELRPORT = 5,
  83. };
  84. static void bfa_fcs_port_sm_uninit(struct bfa_fcs_port_s *port,
  85. enum bfa_fcs_port_event event);
  86. static void bfa_fcs_port_sm_init(struct bfa_fcs_port_s *port,
  87. enum bfa_fcs_port_event event);
  88. static void bfa_fcs_port_sm_online(struct bfa_fcs_port_s *port,
  89. enum bfa_fcs_port_event event);
  90. static void bfa_fcs_port_sm_offline(struct bfa_fcs_port_s *port,
  91. enum bfa_fcs_port_event event);
  92. static void bfa_fcs_port_sm_deleting(struct bfa_fcs_port_s *port,
  93. enum bfa_fcs_port_event event);
  94. static void
  95. bfa_fcs_port_sm_uninit(struct bfa_fcs_port_s *port,
  96. enum bfa_fcs_port_event event)
  97. {
  98. bfa_trc(port->fcs, port->port_cfg.pwwn);
  99. bfa_trc(port->fcs, event);
  100. switch (event) {
  101. case BFA_FCS_PORT_SM_CREATE:
  102. bfa_sm_set_state(port, bfa_fcs_port_sm_init);
  103. break;
  104. default:
  105. bfa_sm_fault(port->fcs, event);
  106. }
  107. }
  108. static void
  109. bfa_fcs_port_sm_init(struct bfa_fcs_port_s *port, enum bfa_fcs_port_event event)
  110. {
  111. bfa_trc(port->fcs, port->port_cfg.pwwn);
  112. bfa_trc(port->fcs, event);
  113. switch (event) {
  114. case BFA_FCS_PORT_SM_ONLINE:
  115. bfa_sm_set_state(port, bfa_fcs_port_sm_online);
  116. bfa_fcs_port_online_actions(port);
  117. break;
  118. case BFA_FCS_PORT_SM_DELETE:
  119. bfa_sm_set_state(port, bfa_fcs_port_sm_uninit);
  120. bfa_fcs_port_deleted(port);
  121. break;
  122. case BFA_FCS_PORT_SM_OFFLINE:
  123. break;
  124. default:
  125. bfa_sm_fault(port->fcs, event);
  126. }
  127. }
  128. static void
  129. bfa_fcs_port_sm_online(struct bfa_fcs_port_s *port,
  130. enum bfa_fcs_port_event event)
  131. {
  132. struct bfa_fcs_rport_s *rport;
  133. struct list_head *qe, *qen;
  134. bfa_trc(port->fcs, port->port_cfg.pwwn);
  135. bfa_trc(port->fcs, event);
  136. switch (event) {
  137. case BFA_FCS_PORT_SM_OFFLINE:
  138. bfa_sm_set_state(port, bfa_fcs_port_sm_offline);
  139. bfa_fcs_port_offline_actions(port);
  140. break;
  141. case BFA_FCS_PORT_SM_DELETE:
  142. __port_action[port->fabric->fab_type].offline(port);
  143. if (port->num_rports == 0) {
  144. bfa_sm_set_state(port, bfa_fcs_port_sm_uninit);
  145. bfa_fcs_port_deleted(port);
  146. } else {
  147. bfa_sm_set_state(port, bfa_fcs_port_sm_deleting);
  148. list_for_each_safe(qe, qen, &port->rport_q) {
  149. rport = (struct bfa_fcs_rport_s *)qe;
  150. bfa_fcs_rport_delete(rport);
  151. }
  152. }
  153. break;
  154. case BFA_FCS_PORT_SM_DELRPORT:
  155. break;
  156. default:
  157. bfa_sm_fault(port->fcs, event);
  158. }
  159. }
  160. static void
  161. bfa_fcs_port_sm_offline(struct bfa_fcs_port_s *port,
  162. enum bfa_fcs_port_event event)
  163. {
  164. struct bfa_fcs_rport_s *rport;
  165. struct list_head *qe, *qen;
  166. bfa_trc(port->fcs, port->port_cfg.pwwn);
  167. bfa_trc(port->fcs, event);
  168. switch (event) {
  169. case BFA_FCS_PORT_SM_ONLINE:
  170. bfa_sm_set_state(port, bfa_fcs_port_sm_online);
  171. bfa_fcs_port_online_actions(port);
  172. break;
  173. case BFA_FCS_PORT_SM_DELETE:
  174. if (port->num_rports == 0) {
  175. bfa_sm_set_state(port, bfa_fcs_port_sm_uninit);
  176. bfa_fcs_port_deleted(port);
  177. } else {
  178. bfa_sm_set_state(port, bfa_fcs_port_sm_deleting);
  179. list_for_each_safe(qe, qen, &port->rport_q) {
  180. rport = (struct bfa_fcs_rport_s *)qe;
  181. bfa_fcs_rport_delete(rport);
  182. }
  183. }
  184. break;
  185. case BFA_FCS_PORT_SM_DELRPORT:
  186. case BFA_FCS_PORT_SM_OFFLINE:
  187. break;
  188. default:
  189. bfa_sm_fault(port->fcs, event);
  190. }
  191. }
  192. static void
  193. bfa_fcs_port_sm_deleting(struct bfa_fcs_port_s *port,
  194. enum bfa_fcs_port_event event)
  195. {
  196. bfa_trc(port->fcs, port->port_cfg.pwwn);
  197. bfa_trc(port->fcs, event);
  198. switch (event) {
  199. case BFA_FCS_PORT_SM_DELRPORT:
  200. if (port->num_rports == 0) {
  201. bfa_sm_set_state(port, bfa_fcs_port_sm_uninit);
  202. bfa_fcs_port_deleted(port);
  203. }
  204. break;
  205. default:
  206. bfa_sm_fault(port->fcs, event);
  207. }
  208. }
  209. /**
  210. * fcs_port_pvt
  211. */
  212. /**
  213. * Send AEN notification
  214. */
  215. static void
  216. bfa_fcs_port_aen_post(struct bfa_fcs_port_s *port,
  217. enum bfa_lport_aen_event event)
  218. {
  219. union bfa_aen_data_u aen_data;
  220. struct bfa_log_mod_s *logmod = port->fcs->logm;
  221. enum bfa_port_role role = port->port_cfg.roles;
  222. wwn_t lpwwn = bfa_fcs_port_get_pwwn(port);
  223. char lpwwn_ptr[BFA_STRING_32];
  224. char *role_str[BFA_PORT_ROLE_FCP_MAX / 2 + 1] =
  225. { "Initiator", "Target", "IPFC" };
  226. wwn2str(lpwwn_ptr, lpwwn);
  227. bfa_assert(role <= BFA_PORT_ROLE_FCP_MAX);
  228. bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_LPORT, event), lpwwn_ptr,
  229. role_str[role/2]);
  230. aen_data.lport.vf_id = port->fabric->vf_id;
  231. aen_data.lport.roles = role;
  232. aen_data.lport.ppwwn =
  233. bfa_fcs_port_get_pwwn(bfa_fcs_get_base_port(port->fcs));
  234. aen_data.lport.lpwwn = lpwwn;
  235. }
  236. /*
  237. * Send a LS reject
  238. */
  239. static void
  240. bfa_fcs_port_send_ls_rjt(struct bfa_fcs_port_s *port, struct fchs_s *rx_fchs,
  241. u8 reason_code, u8 reason_code_expl)
  242. {
  243. struct fchs_s fchs;
  244. struct bfa_fcxp_s *fcxp;
  245. struct bfa_rport_s *bfa_rport = NULL;
  246. int len;
  247. bfa_trc(port->fcs, rx_fchs->s_id);
  248. fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  249. if (!fcxp)
  250. return;
  251. len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rx_fchs->s_id,
  252. bfa_fcs_port_get_fcid(port), rx_fchs->ox_id,
  253. reason_code, reason_code_expl);
  254. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  255. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  256. FC_MAX_PDUSZ, 0);
  257. }
  258. /**
  259. * Process incoming plogi from a remote port.
  260. */
  261. static void
  262. bfa_fcs_port_plogi(struct bfa_fcs_port_s *port, struct fchs_s *rx_fchs,
  263. struct fc_logi_s *plogi)
  264. {
  265. struct bfa_fcs_rport_s *rport;
  266. bfa_trc(port->fcs, rx_fchs->d_id);
  267. bfa_trc(port->fcs, rx_fchs->s_id);
  268. /*
  269. * If min cfg mode is enabled, drop any incoming PLOGIs
  270. */
  271. if (__fcs_min_cfg(port->fcs)) {
  272. bfa_trc(port->fcs, rx_fchs->s_id);
  273. return;
  274. }
  275. if (fc_plogi_parse(rx_fchs) != FC_PARSE_OK) {
  276. bfa_trc(port->fcs, rx_fchs->s_id);
  277. /*
  278. * send a LS reject
  279. */
  280. bfa_fcs_port_send_ls_rjt(port, rx_fchs,
  281. FC_LS_RJT_RSN_PROTOCOL_ERROR,
  282. FC_LS_RJT_EXP_SPARMS_ERR_OPTIONS);
  283. return;
  284. }
  285. /**
  286. * Direct Attach P2P mode : verify address assigned by the r-port.
  287. */
  288. if ((!bfa_fcs_fabric_is_switched(port->fabric))
  289. &&
  290. (memcmp
  291. ((void *)&bfa_fcs_port_get_pwwn(port), (void *)&plogi->port_name,
  292. sizeof(wwn_t)) < 0)) {
  293. if (BFA_FCS_PID_IS_WKA(rx_fchs->d_id)) {
  294. /*
  295. * Address assigned to us cannot be a WKA
  296. */
  297. bfa_fcs_port_send_ls_rjt(port, rx_fchs,
  298. FC_LS_RJT_RSN_PROTOCOL_ERROR,
  299. FC_LS_RJT_EXP_INVALID_NPORT_ID);
  300. return;
  301. }
  302. port->pid = rx_fchs->d_id;
  303. }
  304. /**
  305. * First, check if we know the device by pwwn.
  306. */
  307. rport = bfa_fcs_port_get_rport_by_pwwn(port, plogi->port_name);
  308. if (rport) {
  309. /**
  310. * Direct Attach P2P mode: handle address assigned by the rport.
  311. */
  312. if ((!bfa_fcs_fabric_is_switched(port->fabric))
  313. &&
  314. (memcmp
  315. ((void *)&bfa_fcs_port_get_pwwn(port),
  316. (void *)&plogi->port_name, sizeof(wwn_t)) < 0)) {
  317. port->pid = rx_fchs->d_id;
  318. rport->pid = rx_fchs->s_id;
  319. }
  320. bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
  321. return;
  322. }
  323. /**
  324. * Next, lookup rport by PID.
  325. */
  326. rport = bfa_fcs_port_get_rport_by_pid(port, rx_fchs->s_id);
  327. if (!rport) {
  328. /**
  329. * Inbound PLOGI from a new device.
  330. */
  331. bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
  332. return;
  333. }
  334. /**
  335. * Rport is known only by PID.
  336. */
  337. if (rport->pwwn) {
  338. /**
  339. * This is a different device with the same pid. Old device
  340. * disappeared. Send implicit LOGO to old device.
  341. */
  342. bfa_assert(rport->pwwn != plogi->port_name);
  343. bfa_fcs_rport_logo_imp(rport);
  344. /**
  345. * Inbound PLOGI from a new device (with old PID).
  346. */
  347. bfa_fcs_rport_plogi_create(port, rx_fchs, plogi);
  348. return;
  349. }
  350. /**
  351. * PLOGI crossing each other.
  352. */
  353. bfa_assert(rport->pwwn == WWN_NULL);
  354. bfa_fcs_rport_plogi(rport, rx_fchs, plogi);
  355. }
  356. /*
  357. * Process incoming ECHO.
  358. * Since it does not require a login, it is processed here.
  359. */
  360. static void
  361. bfa_fcs_port_echo(struct bfa_fcs_port_s *port, struct fchs_s *rx_fchs,
  362. struct fc_echo_s *echo, u16 rx_len)
  363. {
  364. struct fchs_s fchs;
  365. struct bfa_fcxp_s *fcxp;
  366. struct bfa_rport_s *bfa_rport = NULL;
  367. int len, pyld_len;
  368. bfa_trc(port->fcs, rx_fchs->s_id);
  369. bfa_trc(port->fcs, rx_fchs->d_id);
  370. bfa_trc(port->fcs, rx_len);
  371. fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  372. if (!fcxp)
  373. return;
  374. len = fc_ls_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rx_fchs->s_id,
  375. bfa_fcs_port_get_fcid(port), rx_fchs->ox_id);
  376. /*
  377. * Copy the payload (if any) from the echo frame
  378. */
  379. pyld_len = rx_len - sizeof(struct fchs_s);
  380. bfa_trc(port->fcs, pyld_len);
  381. if (pyld_len > len)
  382. memcpy(((u8 *) bfa_fcxp_get_reqbuf(fcxp)) +
  383. sizeof(struct fc_echo_s), (echo + 1),
  384. (pyld_len - sizeof(struct fc_echo_s)));
  385. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  386. BFA_FALSE, FC_CLASS_3, pyld_len, &fchs, NULL, NULL,
  387. FC_MAX_PDUSZ, 0);
  388. }
  389. /*
  390. * Process incoming RNID.
  391. * Since it does not require a login, it is processed here.
  392. */
  393. static void
  394. bfa_fcs_port_rnid(struct bfa_fcs_port_s *port, struct fchs_s *rx_fchs,
  395. struct fc_rnid_cmd_s *rnid, u16 rx_len)
  396. {
  397. struct fc_rnid_common_id_data_s common_id_data;
  398. struct fc_rnid_general_topology_data_s gen_topo_data;
  399. struct fchs_s fchs;
  400. struct bfa_fcxp_s *fcxp;
  401. struct bfa_rport_s *bfa_rport = NULL;
  402. u16 len;
  403. u32 data_format;
  404. bfa_trc(port->fcs, rx_fchs->s_id);
  405. bfa_trc(port->fcs, rx_fchs->d_id);
  406. bfa_trc(port->fcs, rx_len);
  407. fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  408. if (!fcxp)
  409. return;
  410. /*
  411. * Check Node Indentification Data Format
  412. * We only support General Topology Discovery Format.
  413. * For any other requested Data Formats, we return Common Node Id Data
  414. * only, as per FC-LS.
  415. */
  416. bfa_trc(port->fcs, rnid->node_id_data_format);
  417. if (rnid->node_id_data_format == RNID_NODEID_DATA_FORMAT_DISCOVERY) {
  418. data_format = RNID_NODEID_DATA_FORMAT_DISCOVERY;
  419. /*
  420. * Get General topology data for this port
  421. */
  422. bfa_fs_port_get_gen_topo_data(port, &gen_topo_data);
  423. } else {
  424. data_format = RNID_NODEID_DATA_FORMAT_COMMON;
  425. }
  426. /*
  427. * Copy the Node Id Info
  428. */
  429. common_id_data.port_name = bfa_fcs_port_get_pwwn(port);
  430. common_id_data.node_name = bfa_fcs_port_get_nwwn(port);
  431. len = fc_rnid_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rx_fchs->s_id,
  432. bfa_fcs_port_get_fcid(port), rx_fchs->ox_id,
  433. data_format, &common_id_data, &gen_topo_data);
  434. bfa_fcxp_send(fcxp, bfa_rport, port->fabric->vf_id, port->lp_tag,
  435. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  436. FC_MAX_PDUSZ, 0);
  437. return;
  438. }
  439. /*
  440. * Fill out General Topolpgy Discovery Data for RNID ELS.
  441. */
  442. static void
  443. bfa_fs_port_get_gen_topo_data(struct bfa_fcs_port_s *port,
  444. struct fc_rnid_general_topology_data_s *gen_topo_data)
  445. {
  446. bfa_os_memset(gen_topo_data, 0,
  447. sizeof(struct fc_rnid_general_topology_data_s));
  448. gen_topo_data->asso_type = bfa_os_htonl(RNID_ASSOCIATED_TYPE_HOST);
  449. gen_topo_data->phy_port_num = 0; /* @todo */
  450. gen_topo_data->num_attached_nodes = bfa_os_htonl(1);
  451. }
  452. static void
  453. bfa_fcs_port_online_actions(struct bfa_fcs_port_s *port)
  454. {
  455. bfa_trc(port->fcs, port->fabric->oper_type);
  456. __port_action[port->fabric->fab_type].init(port);
  457. __port_action[port->fabric->fab_type].online(port);
  458. bfa_fcs_port_aen_post(port, BFA_LPORT_AEN_ONLINE);
  459. bfa_fcb_port_online(port->fcs->bfad, port->port_cfg.roles,
  460. port->fabric->vf_drv, (port->vport == NULL) ?
  461. NULL : port->vport->vport_drv);
  462. }
  463. static void
  464. bfa_fcs_port_offline_actions(struct bfa_fcs_port_s *port)
  465. {
  466. struct list_head *qe, *qen;
  467. struct bfa_fcs_rport_s *rport;
  468. bfa_trc(port->fcs, port->fabric->oper_type);
  469. __port_action[port->fabric->fab_type].offline(port);
  470. if (bfa_fcs_fabric_is_online(port->fabric) == BFA_TRUE)
  471. bfa_fcs_port_aen_post(port, BFA_LPORT_AEN_DISCONNECT);
  472. else
  473. bfa_fcs_port_aen_post(port, BFA_LPORT_AEN_OFFLINE);
  474. bfa_fcb_port_offline(port->fcs->bfad, port->port_cfg.roles,
  475. port->fabric->vf_drv,
  476. (port->vport == NULL) ? NULL : port->vport->vport_drv);
  477. list_for_each_safe(qe, qen, &port->rport_q) {
  478. rport = (struct bfa_fcs_rport_s *)qe;
  479. bfa_fcs_rport_offline(rport);
  480. }
  481. }
  482. static void
  483. bfa_fcs_port_unknown_init(struct bfa_fcs_port_s *port)
  484. {
  485. bfa_assert(0);
  486. }
  487. static void
  488. bfa_fcs_port_unknown_online(struct bfa_fcs_port_s *port)
  489. {
  490. bfa_assert(0);
  491. }
  492. static void
  493. bfa_fcs_port_unknown_offline(struct bfa_fcs_port_s *port)
  494. {
  495. bfa_assert(0);
  496. }
  497. static void
  498. bfa_fcs_port_deleted(struct bfa_fcs_port_s *port)
  499. {
  500. bfa_fcs_port_aen_post(port, BFA_LPORT_AEN_DELETE);
  501. /*
  502. * Base port will be deleted by the OS driver
  503. */
  504. if (port->vport) {
  505. bfa_fcb_port_delete(port->fcs->bfad, port->port_cfg.roles,
  506. port->fabric->vf_drv,
  507. port->vport ? port->vport->vport_drv : NULL);
  508. bfa_fcs_vport_delete_comp(port->vport);
  509. } else {
  510. bfa_fcs_fabric_port_delete_comp(port->fabric);
  511. }
  512. }
  513. /**
  514. * fcs_lport_api BFA FCS port API
  515. */
  516. /**
  517. * Module initialization
  518. */
  519. void
  520. bfa_fcs_port_modinit(struct bfa_fcs_s *fcs)
  521. {
  522. }
  523. /**
  524. * Module cleanup
  525. */
  526. void
  527. bfa_fcs_port_modexit(struct bfa_fcs_s *fcs)
  528. {
  529. bfa_fcs_modexit_comp(fcs);
  530. }
  531. /**
  532. * Unsolicited frame receive handling.
  533. */
  534. void
  535. bfa_fcs_port_uf_recv(struct bfa_fcs_port_s *lport, struct fchs_s *fchs,
  536. u16 len)
  537. {
  538. u32 pid = fchs->s_id;
  539. struct bfa_fcs_rport_s *rport = NULL;
  540. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  541. bfa_stats(lport, uf_recvs);
  542. if (!bfa_fcs_port_is_online(lport)) {
  543. bfa_stats(lport, uf_recv_drops);
  544. return;
  545. }
  546. /**
  547. * First, handle ELSs that donot require a login.
  548. */
  549. /*
  550. * Handle PLOGI first
  551. */
  552. if ((fchs->type == FC_TYPE_ELS) &&
  553. (els_cmd->els_code == FC_ELS_PLOGI)) {
  554. bfa_fcs_port_plogi(lport, fchs, (struct fc_logi_s *) els_cmd);
  555. return;
  556. }
  557. /*
  558. * Handle ECHO separately.
  559. */
  560. if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_ECHO)) {
  561. bfa_fcs_port_echo(lport, fchs,
  562. (struct fc_echo_s *) els_cmd, len);
  563. return;
  564. }
  565. /*
  566. * Handle RNID separately.
  567. */
  568. if ((fchs->type == FC_TYPE_ELS) && (els_cmd->els_code == FC_ELS_RNID)) {
  569. bfa_fcs_port_rnid(lport, fchs,
  570. (struct fc_rnid_cmd_s *) els_cmd, len);
  571. return;
  572. }
  573. /**
  574. * look for a matching remote port ID
  575. */
  576. rport = bfa_fcs_port_get_rport_by_pid(lport, pid);
  577. if (rport) {
  578. bfa_trc(rport->fcs, fchs->s_id);
  579. bfa_trc(rport->fcs, fchs->d_id);
  580. bfa_trc(rport->fcs, fchs->type);
  581. bfa_fcs_rport_uf_recv(rport, fchs, len);
  582. return;
  583. }
  584. /**
  585. * Only handles ELS frames for now.
  586. */
  587. if (fchs->type != FC_TYPE_ELS) {
  588. bfa_trc(lport->fcs, fchs->type);
  589. bfa_assert(0);
  590. return;
  591. }
  592. bfa_trc(lport->fcs, els_cmd->els_code);
  593. if (els_cmd->els_code == FC_ELS_RSCN) {
  594. bfa_fcs_port_scn_process_rscn(lport, fchs, len);
  595. return;
  596. }
  597. if (els_cmd->els_code == FC_ELS_LOGO) {
  598. /**
  599. * @todo Handle LOGO frames received.
  600. */
  601. bfa_trc(lport->fcs, els_cmd->els_code);
  602. return;
  603. }
  604. if (els_cmd->els_code == FC_ELS_PRLI) {
  605. /**
  606. * @todo Handle PRLI frames received.
  607. */
  608. bfa_trc(lport->fcs, els_cmd->els_code);
  609. return;
  610. }
  611. /**
  612. * Unhandled ELS frames. Send a LS_RJT.
  613. */
  614. bfa_fcs_port_send_ls_rjt(lport, fchs, FC_LS_RJT_RSN_CMD_NOT_SUPP,
  615. FC_LS_RJT_EXP_NO_ADDL_INFO);
  616. }
  617. /**
  618. * PID based Lookup for a R-Port in the Port R-Port Queue
  619. */
  620. struct bfa_fcs_rport_s *
  621. bfa_fcs_port_get_rport_by_pid(struct bfa_fcs_port_s *port, u32 pid)
  622. {
  623. struct bfa_fcs_rport_s *rport;
  624. struct list_head *qe;
  625. list_for_each(qe, &port->rport_q) {
  626. rport = (struct bfa_fcs_rport_s *)qe;
  627. if (rport->pid == pid)
  628. return rport;
  629. }
  630. bfa_trc(port->fcs, pid);
  631. return NULL;
  632. }
  633. /**
  634. * PWWN based Lookup for a R-Port in the Port R-Port Queue
  635. */
  636. struct bfa_fcs_rport_s *
  637. bfa_fcs_port_get_rport_by_pwwn(struct bfa_fcs_port_s *port, wwn_t pwwn)
  638. {
  639. struct bfa_fcs_rport_s *rport;
  640. struct list_head *qe;
  641. list_for_each(qe, &port->rport_q) {
  642. rport = (struct bfa_fcs_rport_s *)qe;
  643. if (wwn_is_equal(rport->pwwn, pwwn))
  644. return rport;
  645. }
  646. bfa_trc(port->fcs, pwwn);
  647. return NULL;
  648. }
  649. /**
  650. * NWWN based Lookup for a R-Port in the Port R-Port Queue
  651. */
  652. struct bfa_fcs_rport_s *
  653. bfa_fcs_port_get_rport_by_nwwn(struct bfa_fcs_port_s *port, wwn_t nwwn)
  654. {
  655. struct bfa_fcs_rport_s *rport;
  656. struct list_head *qe;
  657. list_for_each(qe, &port->rport_q) {
  658. rport = (struct bfa_fcs_rport_s *)qe;
  659. if (wwn_is_equal(rport->nwwn, nwwn))
  660. return rport;
  661. }
  662. bfa_trc(port->fcs, nwwn);
  663. return NULL;
  664. }
  665. /**
  666. * Called by rport module when new rports are discovered.
  667. */
  668. void
  669. bfa_fcs_port_add_rport(struct bfa_fcs_port_s *port,
  670. struct bfa_fcs_rport_s *rport)
  671. {
  672. list_add_tail(&rport->qe, &port->rport_q);
  673. port->num_rports++;
  674. }
  675. /**
  676. * Called by rport module to when rports are deleted.
  677. */
  678. void
  679. bfa_fcs_port_del_rport(struct bfa_fcs_port_s *port,
  680. struct bfa_fcs_rport_s *rport)
  681. {
  682. bfa_assert(bfa_q_is_on_q(&port->rport_q, rport));
  683. list_del(&rport->qe);
  684. port->num_rports--;
  685. bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELRPORT);
  686. }
  687. /**
  688. * Called by fabric for base port when fabric login is complete.
  689. * Called by vport for virtual ports when FDISC is complete.
  690. */
  691. void
  692. bfa_fcs_port_online(struct bfa_fcs_port_s *port)
  693. {
  694. bfa_sm_send_event(port, BFA_FCS_PORT_SM_ONLINE);
  695. }
  696. /**
  697. * Called by fabric for base port when fabric goes offline.
  698. * Called by vport for virtual ports when virtual port becomes offline.
  699. */
  700. void
  701. bfa_fcs_port_offline(struct bfa_fcs_port_s *port)
  702. {
  703. bfa_sm_send_event(port, BFA_FCS_PORT_SM_OFFLINE);
  704. }
  705. /**
  706. * Called by fabric to delete base lport and associated resources.
  707. *
  708. * Called by vport to delete lport and associated resources. Should call
  709. * bfa_fcs_vport_delete_comp() for vports on completion.
  710. */
  711. void
  712. bfa_fcs_port_delete(struct bfa_fcs_port_s *port)
  713. {
  714. bfa_sm_send_event(port, BFA_FCS_PORT_SM_DELETE);
  715. }
  716. /**
  717. * Called by fabric in private loop topology to process LIP event.
  718. */
  719. void
  720. bfa_fcs_port_lip(struct bfa_fcs_port_s *port)
  721. {
  722. }
  723. /**
  724. * Return TRUE if port is online, else return FALSE
  725. */
  726. bfa_boolean_t
  727. bfa_fcs_port_is_online(struct bfa_fcs_port_s *port)
  728. {
  729. return bfa_sm_cmp_state(port, bfa_fcs_port_sm_online);
  730. }
  731. /**
  732. * Attach time initialization of logical ports.
  733. */
  734. void
  735. bfa_fcs_lport_attach(struct bfa_fcs_port_s *lport, struct bfa_fcs_s *fcs,
  736. uint16_t vf_id, struct bfa_fcs_vport_s *vport)
  737. {
  738. lport->fcs = fcs;
  739. lport->fabric = bfa_fcs_vf_lookup(fcs, vf_id);
  740. lport->vport = vport;
  741. lport->lp_tag = (vport) ? bfa_lps_get_tag(vport->lps) :
  742. bfa_lps_get_tag(lport->fabric->lps);
  743. INIT_LIST_HEAD(&lport->rport_q);
  744. lport->num_rports = 0;
  745. }
  746. /**
  747. * Logical port initialization of base or virtual port.
  748. * Called by fabric for base port or by vport for virtual ports.
  749. */
  750. void
  751. bfa_fcs_lport_init(struct bfa_fcs_port_s *lport,
  752. struct bfa_port_cfg_s *port_cfg)
  753. {
  754. struct bfa_fcs_vport_s *vport = lport->vport;
  755. bfa_os_assign(lport->port_cfg, *port_cfg);
  756. lport->bfad_port = bfa_fcb_port_new(lport->fcs->bfad, lport,
  757. lport->port_cfg.roles,
  758. lport->fabric->vf_drv,
  759. vport ? vport->vport_drv : NULL);
  760. bfa_fcs_port_aen_post(lport, BFA_LPORT_AEN_NEW);
  761. bfa_sm_set_state(lport, bfa_fcs_port_sm_uninit);
  762. bfa_sm_send_event(lport, BFA_FCS_PORT_SM_CREATE);
  763. }
  764. /**
  765. * fcs_lport_api
  766. */
  767. void
  768. bfa_fcs_port_get_attr(struct bfa_fcs_port_s *port,
  769. struct bfa_port_attr_s *port_attr)
  770. {
  771. if (bfa_sm_cmp_state(port, bfa_fcs_port_sm_online))
  772. port_attr->pid = port->pid;
  773. else
  774. port_attr->pid = 0;
  775. port_attr->port_cfg = port->port_cfg;
  776. if (port->fabric) {
  777. port_attr->port_type = bfa_fcs_fabric_port_type(port->fabric);
  778. port_attr->loopback = bfa_fcs_fabric_is_loopback(port->fabric);
  779. port_attr->authfail =
  780. bfa_fcs_fabric_is_auth_failed(port->fabric);
  781. port_attr->fabric_name = bfa_fcs_port_get_fabric_name(port);
  782. memcpy(port_attr->fabric_ip_addr,
  783. bfa_fcs_port_get_fabric_ipaddr(port),
  784. BFA_FCS_FABRIC_IPADDR_SZ);
  785. if (port->vport != NULL) {
  786. port_attr->port_type = BFA_PPORT_TYPE_VPORT;
  787. port_attr->fpma_mac =
  788. bfa_lps_get_lp_mac(port->vport->lps);
  789. } else
  790. port_attr->fpma_mac =
  791. bfa_lps_get_lp_mac(port->fabric->lps);
  792. } else {
  793. port_attr->port_type = BFA_PPORT_TYPE_UNKNOWN;
  794. port_attr->state = BFA_PORT_UNINIT;
  795. }
  796. }