loop.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. static bfa_status_t bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port,
  55. u8 alpa);
  56. static 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. /**
  64. * Called by port to initializar in provate LOOP topology.
  65. */
  66. void
  67. bfa_fcs_port_loop_init(struct bfa_fcs_port_s *port)
  68. {
  69. }
  70. /**
  71. * Called by port to notify transition to online state.
  72. */
  73. void
  74. bfa_fcs_port_loop_online(struct bfa_fcs_port_s *port)
  75. {
  76. u8 num_alpa = port->port_topo.ploop.num_alpa;
  77. u8 *alpa_pos_map = port->port_topo.ploop.alpa_pos_map;
  78. struct bfa_fcs_rport_s *r_port;
  79. int ii = 0;
  80. /*
  81. * If the port role is Initiator Mode, create Rports.
  82. */
  83. if (port->port_cfg.roles == BFA_PORT_ROLE_FCP_IM) {
  84. /*
  85. * Check if the ALPA positional bitmap is available.
  86. * if not, we send PLOGI to all possible ALPAs.
  87. */
  88. if (num_alpa > 0) {
  89. for (ii = 0; ii < num_alpa; ii++) {
  90. /*
  91. * ignore ALPA of bfa port
  92. */
  93. if (alpa_pos_map[ii] != port->pid) {
  94. r_port = bfa_fcs_rport_create(port,
  95. alpa_pos_map[ii]);
  96. }
  97. }
  98. } else {
  99. for (ii = 0; ii < MAX_ALPA_COUNT; ii++) {
  100. /*
  101. * ignore ALPA of bfa port
  102. */
  103. if ((port_loop_alpa_map[ii] > 0)
  104. && (port_loop_alpa_map[ii] != port->pid))
  105. bfa_fcs_port_loop_send_plogi(port,
  106. port_loop_alpa_map[ii]);
  107. /**TBD */
  108. }
  109. }
  110. } else {
  111. /*
  112. * TBD Target Mode ??
  113. */
  114. }
  115. }
  116. /**
  117. * Called by port to notify transition to offline state.
  118. */
  119. void
  120. bfa_fcs_port_loop_offline(struct bfa_fcs_port_s *port)
  121. {
  122. }
  123. /**
  124. * Called by port to notify a LIP on the loop.
  125. */
  126. void
  127. bfa_fcs_port_loop_lip(struct bfa_fcs_port_s *port)
  128. {
  129. }
  130. /**
  131. * Local Functions.
  132. */
  133. static bfa_status_t
  134. bfa_fcs_port_loop_send_plogi(struct bfa_fcs_port_s *port, u8 alpa)
  135. {
  136. struct fchs_s fchs;
  137. struct bfa_fcxp_s *fcxp = NULL;
  138. int len;
  139. bfa_trc(port->fcs, alpa);
  140. fcxp = bfa_fcxp_alloc(NULL, port->fcs->bfa, 0, 0, NULL, NULL, NULL,
  141. NULL);
  142. bfa_assert(fcxp);
  143. len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), alpa,
  144. bfa_fcs_port_get_fcid(port), 0,
  145. port->port_cfg.pwwn, port->port_cfg.nwwn,
  146. bfa_pport_get_maxfrsize(port->fcs->bfa));
  147. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  148. FC_CLASS_3, len, &fchs,
  149. bfa_fcs_port_loop_plogi_response, (void *)port,
  150. FC_MAX_PDUSZ, FC_RA_TOV);
  151. return BFA_STATUS_OK;
  152. }
  153. /**
  154. * Called by fcxp to notify the Plogi response
  155. */
  156. static void
  157. bfa_fcs_port_loop_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
  158. void *cbarg, bfa_status_t req_status,
  159. u32 rsp_len, u32 resid_len,
  160. struct fchs_s *rsp_fchs)
  161. {
  162. struct bfa_fcs_port_s *port = (struct bfa_fcs_port_s *) cbarg;
  163. struct fc_logi_s *plogi_resp;
  164. struct fc_els_cmd_s *els_cmd;
  165. bfa_trc(port->fcs, req_status);
  166. /*
  167. * Sanity Checks
  168. */
  169. if (req_status != BFA_STATUS_OK) {
  170. bfa_trc(port->fcs, req_status);
  171. /*
  172. * @todo
  173. * This could mean that the device with this APLA does not
  174. * exist on the loop.
  175. */
  176. return;
  177. }
  178. els_cmd = (struct fc_els_cmd_s *) BFA_FCXP_RSP_PLD(fcxp);
  179. plogi_resp = (struct fc_logi_s *) els_cmd;
  180. if (els_cmd->els_code == FC_ELS_ACC) {
  181. bfa_fcs_rport_start(port, rsp_fchs, plogi_resp);
  182. } else {
  183. bfa_trc(port->fcs, plogi_resp->els_cmd.els_code);
  184. bfa_assert(0);
  185. }
  186. }