rport_ftrs.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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. * rport_ftrs.c Remote port features (RPF) implementation.
  19. */
  20. #include <bfa.h>
  21. #include <bfa_svc.h>
  22. #include "fcbuild.h"
  23. #include "fcs_rport.h"
  24. #include "fcs_lport.h"
  25. #include "fcs_trcmod.h"
  26. #include "fcs_fcxp.h"
  27. #include "fcs.h"
  28. BFA_TRC_FILE(FCS, RPORT_FTRS);
  29. #define BFA_FCS_RPF_RETRIES (3)
  30. #define BFA_FCS_RPF_RETRY_TIMEOUT (1000) /* 1 sec (In millisecs) */
  31. static void bfa_fcs_rpf_send_rpsc2(void *rport_cbarg,
  32. struct bfa_fcxp_s *fcxp_alloced);
  33. static void bfa_fcs_rpf_rpsc2_response(void *fcsarg,
  34. struct bfa_fcxp_s *fcxp, void *cbarg,
  35. bfa_status_t req_status, u32 rsp_len,
  36. u32 resid_len,
  37. struct fchs_s *rsp_fchs);
  38. static void bfa_fcs_rpf_timeout(void *arg);
  39. /**
  40. * fcs_rport_ftrs_sm FCS rport state machine events
  41. */
  42. enum rpf_event {
  43. RPFSM_EVENT_RPORT_OFFLINE = 1, /* Rport offline */
  44. RPFSM_EVENT_RPORT_ONLINE = 2, /* Rport online */
  45. RPFSM_EVENT_FCXP_SENT = 3, /* Frame from has been sent */
  46. RPFSM_EVENT_TIMEOUT = 4, /* Rport SM timeout event */
  47. RPFSM_EVENT_RPSC_COMP = 5,
  48. RPFSM_EVENT_RPSC_FAIL = 6,
  49. RPFSM_EVENT_RPSC_ERROR = 7,
  50. };
  51. static void bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf,
  52. enum rpf_event event);
  53. static void bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf,
  54. enum rpf_event event);
  55. static void bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf,
  56. enum rpf_event event);
  57. static void bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf,
  58. enum rpf_event event);
  59. static void bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf,
  60. enum rpf_event event);
  61. static void bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf,
  62. enum rpf_event event);
  63. static void
  64. bfa_fcs_rpf_sm_uninit(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  65. {
  66. struct bfa_fcs_rport_s *rport = rpf->rport;
  67. struct bfa_fcs_fabric_s *fabric = &rport->fcs->fabric;
  68. bfa_trc(rport->fcs, rport->pwwn);
  69. bfa_trc(rport->fcs, rport->pid);
  70. bfa_trc(rport->fcs, event);
  71. switch (event) {
  72. case RPFSM_EVENT_RPORT_ONLINE:
  73. /* Send RPSC2 to a Brocade fabric only. */
  74. if ((!BFA_FCS_PID_IS_WKA(rport->pid)) &&
  75. ((bfa_lps_is_brcd_fabric(rport->port->fabric->lps)) ||
  76. (bfa_fcs_fabric_get_switch_oui(fabric) ==
  77. BFA_FCS_BRCD_SWITCH_OUI))) {
  78. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  79. rpf->rpsc_retries = 0;
  80. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  81. }
  82. break;
  83. case RPFSM_EVENT_RPORT_OFFLINE:
  84. break;
  85. default:
  86. bfa_sm_fault(rport->fcs, event);
  87. }
  88. }
  89. static void
  90. bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  91. {
  92. struct bfa_fcs_rport_s *rport = rpf->rport;
  93. bfa_trc(rport->fcs, event);
  94. switch (event) {
  95. case RPFSM_EVENT_FCXP_SENT:
  96. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
  97. break;
  98. case RPFSM_EVENT_RPORT_OFFLINE:
  99. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  100. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
  101. rpf->rpsc_retries = 0;
  102. break;
  103. default:
  104. bfa_sm_fault(rport->fcs, event);
  105. }
  106. }
  107. static void
  108. bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  109. {
  110. struct bfa_fcs_rport_s *rport = rpf->rport;
  111. bfa_trc(rport->fcs, rport->pid);
  112. bfa_trc(rport->fcs, event);
  113. switch (event) {
  114. case RPFSM_EVENT_RPSC_COMP:
  115. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  116. /* Update speed info in f/w via BFA */
  117. if (rpf->rpsc_speed != BFA_PPORT_SPEED_UNKNOWN)
  118. bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
  119. else if (rpf->assigned_speed != BFA_PPORT_SPEED_UNKNOWN)
  120. bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
  121. break;
  122. case RPFSM_EVENT_RPSC_FAIL:
  123. /* RPSC not supported by rport */
  124. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  125. break;
  126. case RPFSM_EVENT_RPSC_ERROR:
  127. /* need to retry...delayed a bit. */
  128. if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
  129. bfa_timer_start(rport->fcs->bfa, &rpf->timer,
  130. bfa_fcs_rpf_timeout, rpf,
  131. BFA_FCS_RPF_RETRY_TIMEOUT);
  132. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
  133. } else {
  134. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  135. }
  136. break;
  137. case RPFSM_EVENT_RPORT_OFFLINE:
  138. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  139. bfa_fcxp_discard(rpf->fcxp);
  140. rpf->rpsc_retries = 0;
  141. break;
  142. default:
  143. bfa_sm_fault(rport->fcs, event);
  144. }
  145. }
  146. static void
  147. bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  148. {
  149. struct bfa_fcs_rport_s *rport = rpf->rport;
  150. bfa_trc(rport->fcs, rport->pid);
  151. bfa_trc(rport->fcs, event);
  152. switch (event) {
  153. case RPFSM_EVENT_TIMEOUT:
  154. /* re-send the RPSC */
  155. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  156. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  157. break;
  158. case RPFSM_EVENT_RPORT_OFFLINE:
  159. bfa_timer_stop(&rpf->timer);
  160. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  161. rpf->rpsc_retries = 0;
  162. break;
  163. default:
  164. bfa_sm_fault(rport->fcs, event);
  165. }
  166. }
  167. static void
  168. bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  169. {
  170. struct bfa_fcs_rport_s *rport = rpf->rport;
  171. bfa_trc(rport->fcs, rport->pwwn);
  172. bfa_trc(rport->fcs, rport->pid);
  173. bfa_trc(rport->fcs, event);
  174. switch (event) {
  175. case RPFSM_EVENT_RPORT_OFFLINE:
  176. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  177. rpf->rpsc_retries = 0;
  178. break;
  179. default:
  180. bfa_sm_fault(rport->fcs, event);
  181. }
  182. }
  183. static void
  184. bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  185. {
  186. struct bfa_fcs_rport_s *rport = rpf->rport;
  187. bfa_trc(rport->fcs, rport->pwwn);
  188. bfa_trc(rport->fcs, rport->pid);
  189. bfa_trc(rport->fcs, event);
  190. switch (event) {
  191. case RPFSM_EVENT_RPORT_ONLINE:
  192. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  193. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  194. break;
  195. case RPFSM_EVENT_RPORT_OFFLINE:
  196. break;
  197. default:
  198. bfa_sm_fault(rport->fcs, event);
  199. }
  200. }
  201. /**
  202. * Called when Rport is created.
  203. */
  204. void bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
  205. {
  206. struct bfa_fcs_rpf_s *rpf = &rport->rpf;
  207. bfa_trc(rport->fcs, rport->pid);
  208. rpf->rport = rport;
  209. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
  210. }
  211. /**
  212. * Called when Rport becomes online
  213. */
  214. void bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
  215. {
  216. bfa_trc(rport->fcs, rport->pid);
  217. if (__fcs_min_cfg(rport->port->fcs))
  218. return;
  219. if (bfa_fcs_fabric_is_switched(rport->port->fabric))
  220. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
  221. }
  222. /**
  223. * Called when Rport becomes offline
  224. */
  225. void bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
  226. {
  227. bfa_trc(rport->fcs, rport->pid);
  228. if (__fcs_min_cfg(rport->port->fcs))
  229. return;
  230. rport->rpf.rpsc_speed = 0;
  231. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
  232. }
  233. static void
  234. bfa_fcs_rpf_timeout(void *arg)
  235. {
  236. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
  237. struct bfa_fcs_rport_s *rport = rpf->rport;
  238. bfa_trc(rport->fcs, rport->pid);
  239. bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
  240. }
  241. static void
  242. bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  243. {
  244. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
  245. struct bfa_fcs_rport_s *rport = rpf->rport;
  246. struct bfa_fcs_port_s *port = rport->port;
  247. struct fchs_s fchs;
  248. int len;
  249. struct bfa_fcxp_s *fcxp;
  250. bfa_trc(rport->fcs, rport->pwwn);
  251. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  252. if (!fcxp) {
  253. bfa_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
  254. bfa_fcs_rpf_send_rpsc2, rpf);
  255. return;
  256. }
  257. rpf->fcxp = fcxp;
  258. len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  259. bfa_fcs_port_get_fcid(port), &rport->pid, 1);
  260. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  261. FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
  262. rpf, FC_MAX_PDUSZ, FC_ELS_TOV);
  263. rport->stats.rpsc_sent++;
  264. bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
  265. }
  266. static void
  267. bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  268. bfa_status_t req_status, u32 rsp_len,
  269. u32 resid_len, struct fchs_s *rsp_fchs)
  270. {
  271. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
  272. struct bfa_fcs_rport_s *rport = rpf->rport;
  273. struct fc_ls_rjt_s *ls_rjt;
  274. struct fc_rpsc2_acc_s *rpsc2_acc;
  275. u16 num_ents;
  276. bfa_trc(rport->fcs, req_status);
  277. if (req_status != BFA_STATUS_OK) {
  278. bfa_trc(rport->fcs, req_status);
  279. if (req_status == BFA_STATUS_ETIMER)
  280. rport->stats.rpsc_failed++;
  281. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  282. return;
  283. }
  284. rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
  285. if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
  286. rport->stats.rpsc_accs++;
  287. num_ents = bfa_os_ntohs(rpsc2_acc->num_pids);
  288. bfa_trc(rport->fcs, num_ents);
  289. if (num_ents > 0) {
  290. bfa_assert(rpsc2_acc->port_info[0].pid != rport->pid);
  291. bfa_trc(rport->fcs,
  292. bfa_os_ntohs(rpsc2_acc->port_info[0].pid));
  293. bfa_trc(rport->fcs,
  294. bfa_os_ntohs(rpsc2_acc->port_info[0].speed));
  295. bfa_trc(rport->fcs,
  296. bfa_os_ntohs(rpsc2_acc->port_info[0].index));
  297. bfa_trc(rport->fcs,
  298. rpsc2_acc->port_info[0].type);
  299. if (rpsc2_acc->port_info[0].speed == 0) {
  300. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  301. return;
  302. }
  303. rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
  304. bfa_os_ntohs(rpsc2_acc->port_info[0].speed));
  305. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
  306. }
  307. } else {
  308. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  309. bfa_trc(rport->fcs, ls_rjt->reason_code);
  310. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  311. rport->stats.rpsc_rejects++;
  312. if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP)
  313. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
  314. else
  315. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  316. }
  317. }