rport_ftrs.c 9.6 KB

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