loop.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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. * port_loop.c vport private loop implementation.
  19. */
  20. #include <bfa.h>
  21. #include <bfa_svc.h>
  22. #include "fcs_lport.h"
  23. #include "fcs_rport.h"
  24. #include "fcs_trcmod.h"
  25. #include "lport_priv.h"
  26. BFA_TRC_FILE(FCS, LOOP);
  27. /**
  28. * ALPA to LIXA bitmap mapping
  29. *
  30. * ALPA 0x00 (Word 0, Bit 30) is invalid for N_Ports. Also Word 0 Bit 31
  31. * is for L_bit (login required) and is filled as ALPA 0x00 here.
  32. */
  33. static const u8 port_loop_alpa_map[] = {
  34. 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, /* Word 3 Bits 0..7 */
  35. 0xD9, 0xD6, 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, /* Word 3 Bits 8..15 */
  36. 0xCD, 0xCC, 0xCB, 0xCA, 0xC9, 0xC7, 0xC6, 0xC5, /* Word 3 Bits 16..23 */
  37. 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5, 0xB4, 0xB3, /* Word 3 Bits 24..31 */
  38. 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9, /* Word 2 Bits 0..7 */
  39. 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, /* Word 2 Bits 8..15 */
  40. 0x98, 0x97, 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, /* Word 2 Bits 16..23 */
  41. 0x80, 0x7C, 0x7A, 0x79, 0x76, 0x75, 0x74, 0x73, /* Word 2 Bits 24..31 */
  42. 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B, 0x6A, 0x69, /* Word 1 Bits 0..7 */
  43. 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56, /* Word 1 Bits 8..15 */
  44. 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, /* Word 1 Bits 16..23 */
  45. 0x4B, 0x4A, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, /* Word 1 Bits 24..31 */
  46. 0x3A, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, /* Word 0 Bits 0..7 */
  47. 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29, 0x27, 0x26, /* Word 0 Bits 8..15 */
  48. 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17, /* Word 0 Bits 16..23 */
  49. 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00, /* Word 0 Bits 24..31 */
  50. };
  51. /*
  52. * Local Functions
  53. */
  54. bfa_status_t bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port,
  55. u8 alpa);
  56. void bfa_fcs_port_loop_plogi_response(void *fcsarg,
  57. struct bfa_fcxp_s *fcxp,
  58. void *cbarg,
  59. bfa_status_t req_status,
  60. u32 rsp_len,
  61. u32 resid_len,
  62. struct fchs_s *rsp_fchs);
  63. bfa_status_t bfa_fcs_port_loop_send_adisc(struct bfa_fcs_port_s *port,
  64. u8 alpa);
  65. void bfa_fcs_port_loop_adisc_response(void *fcsarg,
  66. struct bfa_fcxp_s *fcxp,
  67. void *cbarg,
  68. bfa_status_t req_status,
  69. u32 rsp_len,
  70. u32 resid_len,
  71. struct fchs_s *rsp_fchs);
  72. bfa_status_t bfa_fcs_port_loop_send_plogi_acc(struct bfa_fcs_port_s *port,
  73. u8 alpa);
  74. void bfa_fcs_port_loop_plogi_acc_response(void *fcsarg,
  75. struct bfa_fcxp_s *fcxp,
  76. void *cbarg,
  77. bfa_status_t req_status,
  78. u32 rsp_len,
  79. u32 resid_len,
  80. struct fchs_s *rsp_fchs);
  81. bfa_status_t bfa_fcs_port_loop_send_adisc_acc(struct bfa_fcs_port_s *port,
  82. u8 alpa);
  83. void bfa_fcs_port_loop_adisc_acc_response(void *fcsarg,
  84. struct bfa_fcxp_s *fcxp,
  85. void *cbarg,
  86. bfa_status_t req_status,
  87. u32 rsp_len,
  88. u32 resid_len,
  89. struct fchs_s *rsp_fchs);
  90. /**
  91. * Called by port to initializar in provate LOOP topology.
  92. */
  93. void
  94. bfa_fcs_port_loop_init(struct bfa_fcs_port_s *port)
  95. {
  96. }
  97. /**
  98. * Called by port to notify transition to online state.
  99. */
  100. void
  101. bfa_fcs_port_loop_online(struct bfa_fcs_port_s *port)
  102. {
  103. u8 num_alpa = port->port_topo.ploop.num_alpa;
  104. u8 *alpa_pos_map = port->port_topo.ploop.alpa_pos_map;
  105. struct bfa_fcs_rport_s *r_port;
  106. int ii = 0;
  107. /*
  108. * If the port role is Initiator Mode, create Rports.
  109. */
  110. if (port->port_cfg.roles == BFA_PORT_ROLE_FCP_IM) {
  111. /*
  112. * Check if the ALPA positional bitmap is available.
  113. * if not, we send PLOGI to all possible ALPAs.
  114. */
  115. if (num_alpa > 0) {
  116. for (ii = 0; ii < num_alpa; ii++) {
  117. /*
  118. * ignore ALPA of bfa port
  119. */
  120. if (alpa_pos_map[ii] != port->pid) {
  121. r_port = bfa_fcs_rport_create(port,
  122. alpa_pos_map[ii]);
  123. }
  124. }
  125. } else {
  126. for (ii = 0; ii < MAX_ALPA_COUNT; ii++) {
  127. /*
  128. * ignore ALPA of bfa port
  129. */
  130. if ((port_loop_alpa_map[ii] > 0)
  131. && (port_loop_alpa_map[ii] != port->pid))
  132. bfa_fcs_port_loop_send_plogi(port,
  133. port_loop_alpa_map[ii]);
  134. /**TBD */
  135. }
  136. }
  137. } else {
  138. /*
  139. * TBD Target Mode ??
  140. */
  141. }
  142. }
  143. /**
  144. * Called by port to notify transition to offline state.
  145. */
  146. void
  147. bfa_fcs_port_loop_offline(struct bfa_fcs_port_s *port)
  148. {
  149. }
  150. /**
  151. * Called by port to notify a LIP on the loop.
  152. */
  153. void
  154. bfa_fcs_port_loop_lip(struct bfa_fcs_port_s *port)
  155. {
  156. }
  157. /**
  158. * Local Functions.
  159. */
  160. bfa_status_t
  161. bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port, u8 alpa)
  162. {
  163. struct fchs_s fchs;
  164. struct bfa_fcxp_s *fcxp = NULL;
  165. int len;
  166. bfa_trc(port->fcs, alpa);
  167. fcxp = bfa_fcxp_alloc(NULL, port->fcs->bfa, 0, 0, NULL, NULL, NULL,
  168. NULL);
  169. bfa_assert(fcxp);
  170. len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), alpa,
  171. bfa_fcs_port_get_fcid(port), 0,
  172. port->port_cfg.pwwn, port->port_cfg.nwwn,
  173. bfa_pport_get_maxfrsize(port->fcs->bfa));
  174. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  175. FC_CLASS_3, len, &fchs,
  176. bfa_fcs_port_loop_plogi_response, (void *)port,
  177. FC_MAX_PDUSZ, FC_RA_TOV);
  178. return BFA_STATUS_OK;
  179. }
  180. /**
  181. * Called by fcxp to notify the Plogi response
  182. */
  183. void
  184. bfa_fcs_port_loop_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  185. void *cbarg, bfa_status_t req_status,
  186. u32 rsp_len, u32 resid_len,
  187. struct fchs_s *rsp_fchs)
  188. {
  189. struct bfa_fcs_port_s *port = (struct bfa_fcs_port_s *) cbarg;
  190. struct fc_logi_s *plogi_resp;
  191. struct fc_els_cmd_s *els_cmd;
  192. bfa_trc(port->fcs, req_status);
  193. /*
  194. * Sanity Checks
  195. */
  196. if (req_status != BFA_STATUS_OK) {
  197. bfa_trc(port->fcs, req_status);
  198. /*
  199. * @todo
  200. * This could mean that the device with this APLA does not
  201. * exist on the loop.
  202. */
  203. return;
  204. }
  205. els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
  206. plogi_resp = (struct fc_logi_s *) els_cmd;
  207. if (els_cmd->els_code == FC_ELS_ACC) {
  208. bfa_fcs_rport_start(port, rsp_fchs, plogi_resp);
  209. } else {
  210. bfa_trc(port->fcs, plogi_resp->els_cmd.els_code);
  211. bfa_assert(0);
  212. }
  213. }
  214. bfa_status_t
  215. bfa_fcs_port_loop_send_plogi_acc(struct bfa_fcs_port_s *port, u8 alpa)
  216. {
  217. struct fchs_s fchs;
  218. struct bfa_fcxp_s *fcxp;
  219. int len;
  220. bfa_trc(port->fcs, alpa);
  221. fcxp = bfa_fcxp_alloc(NULL, port->fcs->bfa, 0, 0, NULL, NULL, NULL,
  222. NULL);
  223. bfa_assert(fcxp);
  224. len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), alpa,
  225. bfa_fcs_port_get_fcid(port), 0,
  226. port->port_cfg.pwwn, port->port_cfg.nwwn,
  227. bfa_pport_get_maxfrsize(port->fcs->bfa));
  228. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  229. FC_CLASS_3, len, &fchs,
  230. bfa_fcs_port_loop_plogi_acc_response,
  231. (void *)port, FC_MAX_PDUSZ, 0); /* No response
  232. * expected
  233. */
  234. return BFA_STATUS_OK;
  235. }
  236. /*
  237. * Plogi Acc Response
  238. * We donot do any processing here.
  239. */
  240. void
  241. bfa_fcs_port_loop_plogi_acc_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  242. void *cbarg, bfa_status_t req_status,
  243. u32 rsp_len, u32 resid_len,
  244. struct fchs_s *rsp_fchs)
  245. {
  246. struct bfa_fcs_port_s *port = (struct bfa_fcs_port_s *) cbarg;
  247. bfa_trc(port->fcs, port->pid);
  248. /*
  249. * Sanity Checks
  250. */
  251. if (req_status != BFA_STATUS_OK) {
  252. bfa_trc(port->fcs, req_status);
  253. return;
  254. }
  255. }
  256. bfa_status_t
  257. bfa_fcs_port_loop_send_adisc(struct bfa_fcs_port_s *port, u8 alpa)
  258. {
  259. struct fchs_s fchs;
  260. struct bfa_fcxp_s *fcxp;
  261. int len;
  262. bfa_trc(port->fcs, alpa);
  263. fcxp = bfa_fcxp_alloc(NULL, port->fcs->bfa, 0, 0, NULL, NULL, NULL,
  264. NULL);
  265. bfa_assert(fcxp);
  266. len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), alpa,
  267. bfa_fcs_port_get_fcid(port), 0,
  268. port->port_cfg.pwwn, port->port_cfg.nwwn);
  269. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  270. FC_CLASS_3, len, &fchs,
  271. bfa_fcs_port_loop_adisc_response, (void *)port,
  272. FC_MAX_PDUSZ, FC_RA_TOV);
  273. return BFA_STATUS_OK;
  274. }
  275. /**
  276. * Called by fcxp to notify the ADISC response
  277. */
  278. void
  279. bfa_fcs_port_loop_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  280. void *cbarg, bfa_status_t req_status,
  281. u32 rsp_len, u32 resid_len,
  282. struct fchs_s *rsp_fchs)
  283. {
  284. struct bfa_fcs_port_s *port = (struct bfa_fcs_port_s *) cbarg;
  285. struct bfa_fcs_rport_s *rport;
  286. struct fc_adisc_s *adisc_resp;
  287. struct fc_els_cmd_s *els_cmd;
  288. u32 pid = rsp_fchs->s_id;
  289. bfa_trc(port->fcs, req_status);
  290. /*
  291. * Sanity Checks
  292. */
  293. if (req_status != BFA_STATUS_OK) {
  294. /*
  295. * TBD : we may need to retry certain requests
  296. */
  297. bfa_fcxp_free(fcxp);
  298. return;
  299. }
  300. els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
  301. adisc_resp = (struct fc_adisc_s *) els_cmd;
  302. if (els_cmd->els_code == FC_ELS_ACC) {
  303. } else {
  304. bfa_trc(port->fcs, adisc_resp->els_cmd.els_code);
  305. /*
  306. * TBD: we may need to check for reject codes and retry
  307. */
  308. rport = bfa_fcs_port_get_rport_by_pid(port, pid);
  309. if (rport) {
  310. list_del(&rport->qe);
  311. bfa_fcs_rport_delete(rport);
  312. }
  313. }
  314. return;
  315. }
  316. bfa_status_t
  317. bfa_fcs_port_loop_send_adisc_acc(struct bfa_fcs_port_s *port, u8 alpa)
  318. {
  319. struct fchs_s fchs;
  320. struct bfa_fcxp_s *fcxp;
  321. int len;
  322. bfa_trc(port->fcs, alpa);
  323. fcxp = bfa_fcxp_alloc(NULL, port->fcs->bfa, 0, 0, NULL, NULL, NULL,
  324. NULL);
  325. bfa_assert(fcxp);
  326. len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), alpa,
  327. bfa_fcs_port_get_fcid(port), 0,
  328. port->port_cfg.pwwn, port->port_cfg.nwwn);
  329. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  330. FC_CLASS_3, len, &fchs,
  331. bfa_fcs_port_loop_adisc_acc_response,
  332. (void *)port, FC_MAX_PDUSZ, 0); /* no reponse
  333. * expected
  334. */
  335. return BFA_STATUS_OK;
  336. }
  337. /*
  338. * Adisc Acc Response
  339. * We donot do any processing here.
  340. */
  341. void
  342. bfa_fcs_port_loop_adisc_acc_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  343. void *cbarg, bfa_status_t req_status,
  344. u32 rsp_len, u32 resid_len,
  345. struct fchs_s *rsp_fchs)
  346. {
  347. struct bfa_fcs_port_s *port = (struct bfa_fcs_port_s *) cbarg;
  348. bfa_trc(port->fcs, port->pid);
  349. /*
  350. * Sanity Checks
  351. */
  352. if (req_status != BFA_STATUS_OK) {
  353. bfa_trc(port->fcs, req_status);
  354. return;
  355. }
  356. }