bfa_fcs_lport.c 22 KB

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