rport_ftrs.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. bfa_trc(rport->fcs, rport->pwwn);
  68. bfa_trc(rport->fcs, rport->pid);
  69. bfa_trc(rport->fcs, event);
  70. switch (event) {
  71. case RPFSM_EVENT_RPORT_ONLINE :
  72. if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
  73. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  74. rpf->rpsc_retries = 0;
  75. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  76. break;
  77. };
  78. case RPFSM_EVENT_RPORT_OFFLINE :
  79. break;
  80. default:
  81. bfa_assert(0);
  82. }
  83. }
  84. static void
  85. bfa_fcs_rpf_sm_rpsc_sending(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  86. {
  87. struct bfa_fcs_rport_s *rport = rpf->rport;
  88. bfa_trc(rport->fcs, event);
  89. switch (event) {
  90. case RPFSM_EVENT_FCXP_SENT:
  91. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc);
  92. break;
  93. case RPFSM_EVENT_RPORT_OFFLINE :
  94. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  95. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rpf->fcxp_wqe);
  96. rpf->rpsc_retries = 0;
  97. break;
  98. default:
  99. bfa_assert(0);
  100. }
  101. }
  102. static void
  103. bfa_fcs_rpf_sm_rpsc(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  104. {
  105. struct bfa_fcs_rport_s *rport = rpf->rport;
  106. bfa_trc(rport->fcs, rport->pid);
  107. bfa_trc(rport->fcs, event);
  108. switch (event) {
  109. case RPFSM_EVENT_RPSC_COMP:
  110. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  111. /* Update speed info in f/w via BFA */
  112. if (rpf->rpsc_speed != BFA_PPORT_SPEED_UNKNOWN) {
  113. bfa_rport_speed(rport->bfa_rport, rpf->rpsc_speed);
  114. } else if (rpf->assigned_speed != BFA_PPORT_SPEED_UNKNOWN) {
  115. bfa_rport_speed(rport->bfa_rport, rpf->assigned_speed);
  116. }
  117. break;
  118. case RPFSM_EVENT_RPSC_FAIL:
  119. /* RPSC not supported by rport */
  120. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  121. break;
  122. case RPFSM_EVENT_RPSC_ERROR:
  123. /* need to retry...delayed a bit. */
  124. if (rpf->rpsc_retries++ < BFA_FCS_RPF_RETRIES) {
  125. bfa_timer_start(rport->fcs->bfa, &rpf->timer,
  126. bfa_fcs_rpf_timeout, rpf,
  127. BFA_FCS_RPF_RETRY_TIMEOUT);
  128. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_retry);
  129. } else {
  130. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_online);
  131. }
  132. break;
  133. case RPFSM_EVENT_RPORT_OFFLINE :
  134. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  135. bfa_fcxp_discard(rpf->fcxp);
  136. rpf->rpsc_retries = 0;
  137. break;
  138. default:
  139. bfa_assert(0);
  140. }
  141. }
  142. static void
  143. bfa_fcs_rpf_sm_rpsc_retry(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  144. {
  145. struct bfa_fcs_rport_s *rport = rpf->rport;
  146. bfa_trc(rport->fcs, rport->pid);
  147. bfa_trc(rport->fcs, event);
  148. switch (event) {
  149. case RPFSM_EVENT_TIMEOUT :
  150. /* re-send the RPSC */
  151. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  152. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  153. break;
  154. case RPFSM_EVENT_RPORT_OFFLINE :
  155. bfa_timer_stop(&rpf->timer);
  156. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  157. rpf->rpsc_retries = 0;
  158. break;
  159. default:
  160. bfa_assert(0);
  161. }
  162. }
  163. static void
  164. bfa_fcs_rpf_sm_online(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  165. {
  166. struct bfa_fcs_rport_s *rport = rpf->rport;
  167. bfa_trc(rport->fcs, rport->pwwn);
  168. bfa_trc(rport->fcs, rport->pid);
  169. bfa_trc(rport->fcs, event);
  170. switch (event) {
  171. case RPFSM_EVENT_RPORT_OFFLINE :
  172. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_offline);
  173. rpf->rpsc_retries = 0;
  174. break;
  175. default:
  176. bfa_assert(0);
  177. }
  178. }
  179. static void
  180. bfa_fcs_rpf_sm_offline(struct bfa_fcs_rpf_s *rpf, enum rpf_event event)
  181. {
  182. struct bfa_fcs_rport_s *rport = rpf->rport;
  183. bfa_trc(rport->fcs, rport->pwwn);
  184. bfa_trc(rport->fcs, rport->pid);
  185. bfa_trc(rport->fcs, event);
  186. switch (event) {
  187. case RPFSM_EVENT_RPORT_ONLINE :
  188. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_rpsc_sending);
  189. bfa_fcs_rpf_send_rpsc2(rpf, NULL);
  190. break;
  191. case RPFSM_EVENT_RPORT_OFFLINE :
  192. break;
  193. default:
  194. bfa_assert(0);
  195. }
  196. }
  197. /**
  198. * Called when Rport is created.
  199. */
  200. void bfa_fcs_rpf_init(struct bfa_fcs_rport_s *rport)
  201. {
  202. struct bfa_fcs_rpf_s *rpf = &rport->rpf;
  203. bfa_trc(rport->fcs, rport->pid);
  204. rpf->rport = rport;
  205. bfa_sm_set_state(rpf, bfa_fcs_rpf_sm_uninit);
  206. }
  207. /**
  208. * Called when Rport becomes online
  209. */
  210. void bfa_fcs_rpf_rport_online(struct bfa_fcs_rport_s *rport)
  211. {
  212. bfa_trc(rport->fcs, rport->pid);
  213. if (__fcs_min_cfg(rport->port->fcs))
  214. return;
  215. if (bfa_fcs_fabric_is_switched(rport->port->fabric))
  216. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_ONLINE);
  217. }
  218. /**
  219. * Called when Rport becomes offline
  220. */
  221. void bfa_fcs_rpf_rport_offline(struct bfa_fcs_rport_s *rport)
  222. {
  223. bfa_trc(rport->fcs, rport->pid);
  224. if (__fcs_min_cfg(rport->port->fcs))
  225. return;
  226. bfa_sm_send_event(&rport->rpf, RPFSM_EVENT_RPORT_OFFLINE);
  227. }
  228. static void
  229. bfa_fcs_rpf_timeout(void *arg)
  230. {
  231. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) arg;
  232. struct bfa_fcs_rport_s *rport = rpf->rport;
  233. bfa_trc(rport->fcs, rport->pid);
  234. bfa_sm_send_event(rpf, RPFSM_EVENT_TIMEOUT);
  235. }
  236. static void
  237. bfa_fcs_rpf_send_rpsc2(void *rpf_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  238. {
  239. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *)rpf_cbarg;
  240. struct bfa_fcs_rport_s *rport = rpf->rport;
  241. struct bfa_fcs_port_s *port = rport->port;
  242. struct fchs_s fchs;
  243. int len;
  244. struct bfa_fcxp_s *fcxp;
  245. bfa_trc(rport->fcs, rport->pwwn);
  246. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  247. if (!fcxp) {
  248. bfa_fcxp_alloc_wait(port->fcs->bfa, &rpf->fcxp_wqe,
  249. bfa_fcs_rpf_send_rpsc2, rpf);
  250. return;
  251. }
  252. rpf->fcxp = fcxp;
  253. len = fc_rpsc2_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  254. bfa_fcs_port_get_fcid(port), &rport->pid, 1);
  255. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  256. FC_CLASS_3, len, &fchs, bfa_fcs_rpf_rpsc2_response,
  257. rpf, FC_MAX_PDUSZ, FC_RA_TOV);
  258. rport->stats.rpsc_sent++;
  259. bfa_sm_send_event(rpf, RPFSM_EVENT_FCXP_SENT);
  260. }
  261. static void
  262. bfa_fcs_rpf_rpsc2_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  263. bfa_status_t req_status, u32 rsp_len,
  264. u32 resid_len, struct fchs_s *rsp_fchs)
  265. {
  266. struct bfa_fcs_rpf_s *rpf = (struct bfa_fcs_rpf_s *) cbarg;
  267. struct bfa_fcs_rport_s *rport = rpf->rport;
  268. struct fc_ls_rjt_s *ls_rjt;
  269. struct fc_rpsc2_acc_s *rpsc2_acc;
  270. u16 num_ents;
  271. bfa_trc(rport->fcs, req_status);
  272. if (req_status != BFA_STATUS_OK) {
  273. bfa_trc(rport->fcs, req_status);
  274. if (req_status == BFA_STATUS_ETIMER)
  275. rport->stats.rpsc_failed++;
  276. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  277. return;
  278. }
  279. rpsc2_acc = (struct fc_rpsc2_acc_s *) BFA_FCXP_RSP_PLD(fcxp);
  280. if (rpsc2_acc->els_cmd == FC_ELS_ACC) {
  281. rport->stats.rpsc_accs++;
  282. num_ents = bfa_os_ntohs(rpsc2_acc->num_pids);
  283. bfa_trc(rport->fcs, num_ents);
  284. if (num_ents > 0) {
  285. bfa_assert(rpsc2_acc->port_info[0].pid != rport->pid);
  286. bfa_trc(rport->fcs,
  287. bfa_os_ntohs(rpsc2_acc->port_info[0].pid));
  288. bfa_trc(rport->fcs,
  289. bfa_os_ntohs(rpsc2_acc->port_info[0].speed));
  290. bfa_trc(rport->fcs,
  291. bfa_os_ntohs(rpsc2_acc->port_info[0].index));
  292. bfa_trc(rport->fcs,
  293. rpsc2_acc->port_info[0].type);
  294. if (rpsc2_acc->port_info[0].speed == 0) {
  295. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  296. return;
  297. }
  298. rpf->rpsc_speed = fc_rpsc_operspeed_to_bfa_speed(
  299. bfa_os_ntohs(rpsc2_acc->port_info[0].speed));
  300. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_COMP);
  301. }
  302. } else {
  303. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  304. bfa_trc(rport->fcs, ls_rjt->reason_code);
  305. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  306. rport->stats.rpsc_rejects++;
  307. if (ls_rjt->reason_code == FC_LS_RJT_RSN_CMD_NOT_SUPP) {
  308. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_FAIL);
  309. } else {
  310. bfa_sm_send_event(rpf, RPFSM_EVENT_RPSC_ERROR);
  311. }
  312. }
  313. }