rport.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605
  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.c Remote port implementation.
  19. */
  20. #include <bfa.h>
  21. #include <bfa_svc.h>
  22. #include "fcbuild.h"
  23. #include "fcs_vport.h"
  24. #include "fcs_lport.h"
  25. #include "fcs_rport.h"
  26. #include "fcs_fcpim.h"
  27. #include "fcs_fcptm.h"
  28. #include "fcs_trcmod.h"
  29. #include "fcs_fcxp.h"
  30. #include "fcs.h"
  31. #include <fcb/bfa_fcb_rport.h>
  32. #include <aen/bfa_aen_rport.h>
  33. BFA_TRC_FILE(FCS, RPORT);
  34. #define BFA_FCS_RPORT_MAX_RETRIES (5)
  35. /* In millisecs */
  36. static u32 bfa_fcs_rport_del_timeout =
  37. BFA_FCS_RPORT_DEF_DEL_TIMEOUT * 1000;
  38. /*
  39. * forward declarations
  40. */
  41. static struct bfa_fcs_rport_s *bfa_fcs_rport_alloc(struct bfa_fcs_port_s *port,
  42. wwn_t pwwn, u32 rpid);
  43. static void bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport);
  44. static void bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport);
  45. static void bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport);
  46. static void bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport);
  47. static void bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport,
  48. struct fc_logi_s *plogi);
  49. static void bfa_fcs_rport_fc4_pause(struct bfa_fcs_rport_s *rport);
  50. static void bfa_fcs_rport_fc4_resume(struct bfa_fcs_rport_s *rport);
  51. static void bfa_fcs_rport_timeout(void *arg);
  52. static void bfa_fcs_rport_send_plogi(void *rport_cbarg,
  53. struct bfa_fcxp_s *fcxp_alloced);
  54. static void bfa_fcs_rport_send_plogiacc(void *rport_cbarg,
  55. struct bfa_fcxp_s *fcxp_alloced);
  56. static void bfa_fcs_rport_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. static void bfa_fcs_rport_send_adisc(void *rport_cbarg,
  64. struct bfa_fcxp_s *fcxp_alloced);
  65. static void bfa_fcs_rport_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. static void bfa_fcs_rport_send_gidpn(void *rport_cbarg,
  73. struct bfa_fcxp_s *fcxp_alloced);
  74. static void bfa_fcs_rport_gidpn_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. static void bfa_fcs_rport_send_logo(void *rport_cbarg,
  82. struct bfa_fcxp_s *fcxp_alloced);
  83. static void bfa_fcs_rport_send_logo_acc(void *rport_cbarg);
  84. static void bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
  85. struct fchs_s *rx_fchs, u16 len);
  86. static void bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport,
  87. struct fchs_s *rx_fchs, u8 reason_code,
  88. u8 reason_code_expl);
  89. static void bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
  90. struct fchs_s *rx_fchs, u16 len);
  91. /**
  92. * fcs_rport_sm FCS rport state machine events
  93. */
  94. enum rport_event {
  95. RPSM_EVENT_PLOGI_SEND = 1, /* new rport; start with PLOGI */
  96. RPSM_EVENT_PLOGI_RCVD = 2, /* Inbound PLOGI from remote port */
  97. RPSM_EVENT_PLOGI_COMP = 3, /* PLOGI completed to rport */
  98. RPSM_EVENT_LOGO_RCVD = 4, /* LOGO from remote device */
  99. RPSM_EVENT_LOGO_IMP = 5, /* implicit logo for SLER */
  100. RPSM_EVENT_FCXP_SENT = 6, /* Frame from has been sent */
  101. RPSM_EVENT_DELETE = 7, /* RPORT delete request */
  102. RPSM_EVENT_SCN = 8, /* state change notification */
  103. RPSM_EVENT_ACCEPTED = 9,/* Good response from remote device */
  104. RPSM_EVENT_FAILED = 10, /* Request to rport failed. */
  105. RPSM_EVENT_TIMEOUT = 11, /* Rport SM timeout event */
  106. RPSM_EVENT_HCB_ONLINE = 12, /* BFA rport online callback */
  107. RPSM_EVENT_HCB_OFFLINE = 13, /* BFA rport offline callback */
  108. RPSM_EVENT_FC4_OFFLINE = 14, /* FC-4 offline complete */
  109. RPSM_EVENT_ADDRESS_CHANGE = 15, /* Rport's PID has changed */
  110. RPSM_EVENT_ADDRESS_DISC = 16 /* Need to Discover rport's PID */
  111. };
  112. static void bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport,
  113. enum rport_event event);
  114. static void bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
  115. enum rport_event event);
  116. static void bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
  117. enum rport_event event);
  118. static void bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  119. enum rport_event event);
  120. static void bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport,
  121. enum rport_event event);
  122. static void bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  123. enum rport_event event);
  124. static void bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport,
  125. enum rport_event event);
  126. static void bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
  127. enum rport_event event);
  128. static void bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport,
  129. enum rport_event event);
  130. static void bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
  131. enum rport_event event);
  132. static void bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport,
  133. enum rport_event event);
  134. static void bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  135. enum rport_event event);
  136. static void bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
  137. enum rport_event event);
  138. static void bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
  139. enum rport_event event);
  140. static void bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
  141. enum rport_event event);
  142. static void bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  143. enum rport_event event);
  144. static void bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
  145. enum rport_event event);
  146. static void bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
  147. enum rport_event event);
  148. static void bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport,
  149. enum rport_event event);
  150. static void bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
  151. enum rport_event event);
  152. static void bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
  153. enum rport_event event);
  154. static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  155. enum rport_event event);
  156. static void bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  157. enum rport_event event);
  158. static struct bfa_sm_table_s rport_sm_table[] = {
  159. {BFA_SM(bfa_fcs_rport_sm_uninit), BFA_RPORT_UNINIT},
  160. {BFA_SM(bfa_fcs_rport_sm_plogi_sending), BFA_RPORT_PLOGI},
  161. {BFA_SM(bfa_fcs_rport_sm_plogiacc_sending), BFA_RPORT_ONLINE},
  162. {BFA_SM(bfa_fcs_rport_sm_plogi_retry), BFA_RPORT_PLOGI_RETRY},
  163. {BFA_SM(bfa_fcs_rport_sm_plogi), BFA_RPORT_PLOGI},
  164. {BFA_SM(bfa_fcs_rport_sm_hal_online), BFA_RPORT_ONLINE},
  165. {BFA_SM(bfa_fcs_rport_sm_online), BFA_RPORT_ONLINE},
  166. {BFA_SM(bfa_fcs_rport_sm_nsquery_sending), BFA_RPORT_NSQUERY},
  167. {BFA_SM(bfa_fcs_rport_sm_nsquery), BFA_RPORT_NSQUERY},
  168. {BFA_SM(bfa_fcs_rport_sm_adisc_sending), BFA_RPORT_ADISC},
  169. {BFA_SM(bfa_fcs_rport_sm_adisc), BFA_RPORT_ADISC},
  170. {BFA_SM(bfa_fcs_rport_sm_fc4_logorcv), BFA_RPORT_LOGORCV},
  171. {BFA_SM(bfa_fcs_rport_sm_fc4_logosend), BFA_RPORT_LOGO},
  172. {BFA_SM(bfa_fcs_rport_sm_fc4_offline), BFA_RPORT_OFFLINE},
  173. {BFA_SM(bfa_fcs_rport_sm_hcb_offline), BFA_RPORT_OFFLINE},
  174. {BFA_SM(bfa_fcs_rport_sm_hcb_logorcv), BFA_RPORT_LOGORCV},
  175. {BFA_SM(bfa_fcs_rport_sm_hcb_logosend), BFA_RPORT_LOGO},
  176. {BFA_SM(bfa_fcs_rport_sm_logo_sending), BFA_RPORT_LOGO},
  177. {BFA_SM(bfa_fcs_rport_sm_offline), BFA_RPORT_OFFLINE},
  178. {BFA_SM(bfa_fcs_rport_sm_nsdisc_sending), BFA_RPORT_NSDISC},
  179. {BFA_SM(bfa_fcs_rport_sm_nsdisc_retry), BFA_RPORT_NSDISC},
  180. {BFA_SM(bfa_fcs_rport_sm_nsdisc_sent), BFA_RPORT_NSDISC},
  181. };
  182. /**
  183. * Beginning state.
  184. */
  185. static void
  186. bfa_fcs_rport_sm_uninit(struct bfa_fcs_rport_s *rport, enum rport_event event)
  187. {
  188. bfa_trc(rport->fcs, rport->pwwn);
  189. bfa_trc(rport->fcs, rport->pid);
  190. bfa_trc(rport->fcs, event);
  191. switch (event) {
  192. case RPSM_EVENT_PLOGI_SEND:
  193. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  194. rport->plogi_retries = 0;
  195. bfa_fcs_rport_send_plogi(rport, NULL);
  196. break;
  197. case RPSM_EVENT_PLOGI_RCVD:
  198. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  199. bfa_fcs_rport_send_plogiacc(rport, NULL);
  200. break;
  201. case RPSM_EVENT_PLOGI_COMP:
  202. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  203. bfa_fcs_rport_hal_online(rport);
  204. break;
  205. case RPSM_EVENT_ADDRESS_CHANGE:
  206. case RPSM_EVENT_ADDRESS_DISC:
  207. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  208. rport->ns_retries = 0;
  209. bfa_fcs_rport_send_gidpn(rport, NULL);
  210. break;
  211. default:
  212. bfa_sm_fault(rport->fcs, event);
  213. }
  214. }
  215. /**
  216. * PLOGI is being sent.
  217. */
  218. static void
  219. bfa_fcs_rport_sm_plogi_sending(struct bfa_fcs_rport_s *rport,
  220. enum rport_event event)
  221. {
  222. bfa_trc(rport->fcs, rport->pwwn);
  223. bfa_trc(rport->fcs, rport->pid);
  224. bfa_trc(rport->fcs, event);
  225. switch (event) {
  226. case RPSM_EVENT_FCXP_SENT:
  227. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi);
  228. break;
  229. case RPSM_EVENT_DELETE:
  230. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  231. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  232. bfa_fcs_rport_free(rport);
  233. break;
  234. case RPSM_EVENT_PLOGI_RCVD:
  235. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  236. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  237. bfa_fcs_rport_send_plogiacc(rport, NULL);
  238. break;
  239. case RPSM_EVENT_ADDRESS_CHANGE:
  240. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  241. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  242. rport->ns_retries = 0;
  243. bfa_fcs_rport_send_gidpn(rport, NULL);
  244. break;
  245. case RPSM_EVENT_LOGO_IMP:
  246. rport->pid = 0;
  247. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  248. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  249. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  250. bfa_fcs_rport_timeout, rport,
  251. bfa_fcs_rport_del_timeout);
  252. break;
  253. case RPSM_EVENT_SCN:
  254. break;
  255. default:
  256. bfa_sm_fault(rport->fcs, event);
  257. }
  258. }
  259. /**
  260. * PLOGI is being sent.
  261. */
  262. static void
  263. bfa_fcs_rport_sm_plogiacc_sending(struct bfa_fcs_rport_s *rport,
  264. enum rport_event event)
  265. {
  266. bfa_trc(rport->fcs, rport->pwwn);
  267. bfa_trc(rport->fcs, rport->pid);
  268. bfa_trc(rport->fcs, event);
  269. switch (event) {
  270. case RPSM_EVENT_FCXP_SENT:
  271. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  272. bfa_fcs_rport_hal_online(rport);
  273. break;
  274. case RPSM_EVENT_DELETE:
  275. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  276. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  277. bfa_fcs_rport_free(rport);
  278. break;
  279. case RPSM_EVENT_SCN:
  280. /**
  281. * Ignore, SCN is possibly online notification.
  282. */
  283. break;
  284. case RPSM_EVENT_ADDRESS_CHANGE:
  285. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  286. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  287. rport->ns_retries = 0;
  288. bfa_fcs_rport_send_gidpn(rport, NULL);
  289. break;
  290. case RPSM_EVENT_LOGO_IMP:
  291. rport->pid = 0;
  292. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  293. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  294. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  295. bfa_fcs_rport_timeout, rport,
  296. bfa_fcs_rport_del_timeout);
  297. break;
  298. case RPSM_EVENT_HCB_OFFLINE:
  299. /**
  300. * Ignore BFA callback, on a PLOGI receive we call bfa offline.
  301. */
  302. break;
  303. default:
  304. bfa_sm_fault(rport->fcs, event);
  305. }
  306. }
  307. /**
  308. * PLOGI is sent.
  309. */
  310. static void
  311. bfa_fcs_rport_sm_plogi_retry(struct bfa_fcs_rport_s *rport,
  312. enum rport_event event)
  313. {
  314. bfa_trc(rport->fcs, rport->pwwn);
  315. bfa_trc(rport->fcs, rport->pid);
  316. bfa_trc(rport->fcs, event);
  317. switch (event) {
  318. case RPSM_EVENT_SCN:
  319. bfa_timer_stop(&rport->timer);
  320. /*
  321. * !! fall through !!
  322. */
  323. case RPSM_EVENT_TIMEOUT:
  324. rport->plogi_retries++;
  325. if (rport->plogi_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  326. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  327. bfa_fcs_rport_send_plogi(rport, NULL);
  328. } else {
  329. rport->pid = 0;
  330. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  331. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  332. bfa_fcs_rport_timeout, rport,
  333. bfa_fcs_rport_del_timeout);
  334. }
  335. break;
  336. case RPSM_EVENT_DELETE:
  337. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  338. bfa_timer_stop(&rport->timer);
  339. bfa_fcs_rport_free(rport);
  340. break;
  341. case RPSM_EVENT_LOGO_RCVD:
  342. break;
  343. case RPSM_EVENT_PLOGI_RCVD:
  344. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  345. bfa_timer_stop(&rport->timer);
  346. bfa_fcs_rport_send_plogiacc(rport, NULL);
  347. break;
  348. case RPSM_EVENT_ADDRESS_CHANGE:
  349. bfa_timer_stop(&rport->timer);
  350. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  351. rport->ns_retries = 0;
  352. bfa_fcs_rport_send_gidpn(rport, NULL);
  353. break;
  354. case RPSM_EVENT_LOGO_IMP:
  355. rport->pid = 0;
  356. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  357. bfa_timer_stop(&rport->timer);
  358. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  359. bfa_fcs_rport_timeout, rport,
  360. bfa_fcs_rport_del_timeout);
  361. break;
  362. case RPSM_EVENT_PLOGI_COMP:
  363. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  364. bfa_timer_stop(&rport->timer);
  365. bfa_fcs_rport_hal_online(rport);
  366. break;
  367. default:
  368. bfa_sm_fault(rport->fcs, event);
  369. }
  370. }
  371. /**
  372. * PLOGI is sent.
  373. */
  374. static void
  375. bfa_fcs_rport_sm_plogi(struct bfa_fcs_rport_s *rport, enum rport_event event)
  376. {
  377. bfa_trc(rport->fcs, rport->pwwn);
  378. bfa_trc(rport->fcs, rport->pid);
  379. bfa_trc(rport->fcs, event);
  380. switch (event) {
  381. case RPSM_EVENT_ACCEPTED:
  382. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  383. rport->plogi_retries = 0;
  384. bfa_fcs_rport_hal_online(rport);
  385. break;
  386. case RPSM_EVENT_LOGO_RCVD:
  387. bfa_fcs_rport_send_logo_acc(rport);
  388. bfa_fcxp_discard(rport->fcxp);
  389. /*
  390. * !! fall through !!
  391. */
  392. case RPSM_EVENT_FAILED:
  393. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_retry);
  394. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  395. bfa_fcs_rport_timeout, rport,
  396. BFA_FCS_RETRY_TIMEOUT);
  397. break;
  398. case RPSM_EVENT_LOGO_IMP:
  399. rport->pid = 0;
  400. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  401. bfa_fcxp_discard(rport->fcxp);
  402. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  403. bfa_fcs_rport_timeout, rport,
  404. bfa_fcs_rport_del_timeout);
  405. break;
  406. case RPSM_EVENT_ADDRESS_CHANGE:
  407. bfa_fcxp_discard(rport->fcxp);
  408. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  409. rport->ns_retries = 0;
  410. bfa_fcs_rport_send_gidpn(rport, NULL);
  411. break;
  412. case RPSM_EVENT_PLOGI_RCVD:
  413. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  414. bfa_fcxp_discard(rport->fcxp);
  415. bfa_fcs_rport_send_plogiacc(rport, NULL);
  416. break;
  417. case RPSM_EVENT_SCN:
  418. /**
  419. * Ignore SCN - wait for PLOGI response.
  420. */
  421. break;
  422. case RPSM_EVENT_DELETE:
  423. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  424. bfa_fcxp_discard(rport->fcxp);
  425. bfa_fcs_rport_free(rport);
  426. break;
  427. case RPSM_EVENT_PLOGI_COMP:
  428. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  429. bfa_fcxp_discard(rport->fcxp);
  430. bfa_fcs_rport_hal_online(rport);
  431. break;
  432. default:
  433. bfa_sm_fault(rport->fcs, event);
  434. }
  435. }
  436. /**
  437. * PLOGI is complete. Awaiting BFA rport online callback. FC-4s
  438. * are offline.
  439. */
  440. static void
  441. bfa_fcs_rport_sm_hal_online(struct bfa_fcs_rport_s *rport,
  442. enum rport_event event)
  443. {
  444. bfa_trc(rport->fcs, rport->pwwn);
  445. bfa_trc(rport->fcs, rport->pid);
  446. bfa_trc(rport->fcs, event);
  447. switch (event) {
  448. case RPSM_EVENT_HCB_ONLINE:
  449. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  450. bfa_fcs_rport_online_action(rport);
  451. break;
  452. case RPSM_EVENT_LOGO_RCVD:
  453. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
  454. bfa_rport_offline(rport->bfa_rport);
  455. break;
  456. case RPSM_EVENT_LOGO_IMP:
  457. case RPSM_EVENT_ADDRESS_CHANGE:
  458. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
  459. bfa_rport_offline(rport->bfa_rport);
  460. break;
  461. case RPSM_EVENT_PLOGI_RCVD:
  462. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  463. bfa_rport_offline(rport->bfa_rport);
  464. bfa_fcs_rport_send_plogiacc(rport, NULL);
  465. break;
  466. case RPSM_EVENT_DELETE:
  467. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
  468. bfa_rport_offline(rport->bfa_rport);
  469. break;
  470. case RPSM_EVENT_SCN:
  471. /**
  472. * @todo
  473. * Ignore SCN - PLOGI just completed, FC-4 login should detect
  474. * device failures.
  475. */
  476. break;
  477. default:
  478. bfa_sm_fault(rport->fcs, event);
  479. }
  480. }
  481. /**
  482. * Rport is ONLINE. FC-4s active.
  483. */
  484. static void
  485. bfa_fcs_rport_sm_online(struct bfa_fcs_rport_s *rport, enum rport_event event)
  486. {
  487. bfa_trc(rport->fcs, rport->pwwn);
  488. bfa_trc(rport->fcs, rport->pid);
  489. bfa_trc(rport->fcs, event);
  490. switch (event) {
  491. case RPSM_EVENT_SCN:
  492. /**
  493. * Pause FC-4 activity till rport is authenticated.
  494. * In switched fabrics, check presence of device in nameserver
  495. * first.
  496. */
  497. bfa_fcs_rport_fc4_pause(rport);
  498. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  499. bfa_sm_set_state(rport,
  500. bfa_fcs_rport_sm_nsquery_sending);
  501. rport->ns_retries = 0;
  502. bfa_fcs_rport_send_gidpn(rport, NULL);
  503. } else {
  504. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
  505. bfa_fcs_rport_send_adisc(rport, NULL);
  506. }
  507. break;
  508. case RPSM_EVENT_PLOGI_RCVD:
  509. case RPSM_EVENT_LOGO_IMP:
  510. case RPSM_EVENT_ADDRESS_CHANGE:
  511. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  512. bfa_fcs_rport_offline_action(rport);
  513. break;
  514. case RPSM_EVENT_DELETE:
  515. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  516. bfa_fcs_rport_offline_action(rport);
  517. break;
  518. case RPSM_EVENT_LOGO_RCVD:
  519. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  520. bfa_fcs_rport_offline_action(rport);
  521. break;
  522. case RPSM_EVENT_PLOGI_COMP:
  523. break;
  524. default:
  525. bfa_sm_fault(rport->fcs, event);
  526. }
  527. }
  528. /**
  529. * An SCN event is received in ONLINE state. NS query is being sent
  530. * prior to ADISC authentication with rport. FC-4s are paused.
  531. */
  532. static void
  533. bfa_fcs_rport_sm_nsquery_sending(struct bfa_fcs_rport_s *rport,
  534. enum rport_event event)
  535. {
  536. bfa_trc(rport->fcs, rport->pwwn);
  537. bfa_trc(rport->fcs, rport->pid);
  538. bfa_trc(rport->fcs, event);
  539. switch (event) {
  540. case RPSM_EVENT_FCXP_SENT:
  541. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsquery);
  542. break;
  543. case RPSM_EVENT_DELETE:
  544. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  545. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  546. bfa_fcs_rport_offline_action(rport);
  547. break;
  548. case RPSM_EVENT_SCN:
  549. /**
  550. * ignore SCN, wait for response to query itself
  551. */
  552. break;
  553. case RPSM_EVENT_LOGO_RCVD:
  554. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  555. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  556. bfa_fcs_rport_offline_action(rport);
  557. break;
  558. case RPSM_EVENT_LOGO_IMP:
  559. rport->pid = 0;
  560. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  561. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  562. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  563. bfa_fcs_rport_timeout, rport,
  564. bfa_fcs_rport_del_timeout);
  565. break;
  566. case RPSM_EVENT_PLOGI_RCVD:
  567. case RPSM_EVENT_ADDRESS_CHANGE:
  568. case RPSM_EVENT_PLOGI_COMP:
  569. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  570. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  571. bfa_fcs_rport_offline_action(rport);
  572. break;
  573. default:
  574. bfa_sm_fault(rport->fcs, event);
  575. }
  576. }
  577. /**
  578. * An SCN event is received in ONLINE state. NS query is sent to rport.
  579. * FC-4s are paused.
  580. */
  581. static void
  582. bfa_fcs_rport_sm_nsquery(struct bfa_fcs_rport_s *rport, enum rport_event event)
  583. {
  584. bfa_trc(rport->fcs, rport->pwwn);
  585. bfa_trc(rport->fcs, rport->pid);
  586. bfa_trc(rport->fcs, event);
  587. switch (event) {
  588. case RPSM_EVENT_ACCEPTED:
  589. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc_sending);
  590. bfa_fcs_rport_send_adisc(rport, NULL);
  591. break;
  592. case RPSM_EVENT_FAILED:
  593. rport->ns_retries++;
  594. if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  595. bfa_sm_set_state(rport,
  596. bfa_fcs_rport_sm_nsquery_sending);
  597. bfa_fcs_rport_send_gidpn(rport, NULL);
  598. } else {
  599. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  600. bfa_fcs_rport_offline_action(rport);
  601. }
  602. break;
  603. case RPSM_EVENT_DELETE:
  604. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  605. bfa_fcxp_discard(rport->fcxp);
  606. bfa_fcs_rport_offline_action(rport);
  607. break;
  608. case RPSM_EVENT_SCN:
  609. break;
  610. case RPSM_EVENT_LOGO_RCVD:
  611. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  612. bfa_fcxp_discard(rport->fcxp);
  613. bfa_fcs_rport_offline_action(rport);
  614. break;
  615. case RPSM_EVENT_PLOGI_COMP:
  616. case RPSM_EVENT_ADDRESS_CHANGE:
  617. case RPSM_EVENT_PLOGI_RCVD:
  618. case RPSM_EVENT_LOGO_IMP:
  619. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  620. bfa_fcxp_discard(rport->fcxp);
  621. bfa_fcs_rport_offline_action(rport);
  622. break;
  623. default:
  624. bfa_sm_fault(rport->fcs, event);
  625. }
  626. }
  627. /**
  628. * An SCN event is received in ONLINE state. ADISC is being sent for
  629. * authenticating with rport. FC-4s are paused.
  630. */
  631. static void
  632. bfa_fcs_rport_sm_adisc_sending(struct bfa_fcs_rport_s *rport,
  633. enum rport_event event)
  634. {
  635. bfa_trc(rport->fcs, rport->pwwn);
  636. bfa_trc(rport->fcs, rport->pid);
  637. bfa_trc(rport->fcs, event);
  638. switch (event) {
  639. case RPSM_EVENT_FCXP_SENT:
  640. bfa_sm_set_state(rport, bfa_fcs_rport_sm_adisc);
  641. break;
  642. case RPSM_EVENT_DELETE:
  643. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  644. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  645. bfa_fcs_rport_offline_action(rport);
  646. break;
  647. case RPSM_EVENT_LOGO_IMP:
  648. case RPSM_EVENT_ADDRESS_CHANGE:
  649. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  650. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  651. bfa_fcs_rport_offline_action(rport);
  652. break;
  653. case RPSM_EVENT_LOGO_RCVD:
  654. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  655. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  656. bfa_fcs_rport_offline_action(rport);
  657. break;
  658. case RPSM_EVENT_SCN:
  659. break;
  660. case RPSM_EVENT_PLOGI_RCVD:
  661. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  662. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  663. bfa_fcs_rport_offline_action(rport);
  664. break;
  665. default:
  666. bfa_sm_fault(rport->fcs, event);
  667. }
  668. }
  669. /**
  670. * An SCN event is received in ONLINE state. ADISC is to rport.
  671. * FC-4s are paused.
  672. */
  673. static void
  674. bfa_fcs_rport_sm_adisc(struct bfa_fcs_rport_s *rport, enum rport_event event)
  675. {
  676. bfa_trc(rport->fcs, rport->pwwn);
  677. bfa_trc(rport->fcs, rport->pid);
  678. bfa_trc(rport->fcs, event);
  679. switch (event) {
  680. case RPSM_EVENT_ACCEPTED:
  681. bfa_sm_set_state(rport, bfa_fcs_rport_sm_online);
  682. bfa_fcs_rport_fc4_resume(rport);
  683. break;
  684. case RPSM_EVENT_PLOGI_RCVD:
  685. /**
  686. * Too complex to cleanup FC-4 & rport and then acc to PLOGI.
  687. * At least go offline when a PLOGI is received.
  688. */
  689. bfa_fcxp_discard(rport->fcxp);
  690. /*
  691. * !!! fall through !!!
  692. */
  693. case RPSM_EVENT_FAILED:
  694. case RPSM_EVENT_ADDRESS_CHANGE:
  695. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  696. bfa_fcs_rport_offline_action(rport);
  697. break;
  698. case RPSM_EVENT_DELETE:
  699. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  700. bfa_fcxp_discard(rport->fcxp);
  701. bfa_fcs_rport_offline_action(rport);
  702. break;
  703. case RPSM_EVENT_SCN:
  704. /**
  705. * already processing RSCN
  706. */
  707. break;
  708. case RPSM_EVENT_LOGO_IMP:
  709. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_offline);
  710. bfa_fcxp_discard(rport->fcxp);
  711. bfa_fcs_rport_offline_action(rport);
  712. break;
  713. case RPSM_EVENT_LOGO_RCVD:
  714. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logorcv);
  715. bfa_fcxp_discard(rport->fcxp);
  716. bfa_fcs_rport_offline_action(rport);
  717. break;
  718. default:
  719. bfa_sm_fault(rport->fcs, event);
  720. }
  721. }
  722. /**
  723. * Rport has sent LOGO. Awaiting FC-4 offline completion callback.
  724. */
  725. static void
  726. bfa_fcs_rport_sm_fc4_logorcv(struct bfa_fcs_rport_s *rport,
  727. enum rport_event event)
  728. {
  729. bfa_trc(rport->fcs, rport->pwwn);
  730. bfa_trc(rport->fcs, rport->pid);
  731. bfa_trc(rport->fcs, event);
  732. switch (event) {
  733. case RPSM_EVENT_FC4_OFFLINE:
  734. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logorcv);
  735. bfa_rport_offline(rport->bfa_rport);
  736. break;
  737. case RPSM_EVENT_DELETE:
  738. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  739. break;
  740. case RPSM_EVENT_LOGO_RCVD:
  741. case RPSM_EVENT_ADDRESS_CHANGE:
  742. break;
  743. default:
  744. bfa_sm_fault(rport->fcs, event);
  745. }
  746. }
  747. /**
  748. * LOGO needs to be sent to rport. Awaiting FC-4 offline completion
  749. * callback.
  750. */
  751. static void
  752. bfa_fcs_rport_sm_fc4_logosend(struct bfa_fcs_rport_s *rport,
  753. enum rport_event event)
  754. {
  755. bfa_trc(rport->fcs, rport->pwwn);
  756. bfa_trc(rport->fcs, rport->pid);
  757. bfa_trc(rport->fcs, event);
  758. switch (event) {
  759. case RPSM_EVENT_FC4_OFFLINE:
  760. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
  761. bfa_rport_offline(rport->bfa_rport);
  762. break;
  763. default:
  764. bfa_sm_fault(rport->fcs, event);
  765. }
  766. }
  767. /**
  768. * Rport is going offline. Awaiting FC-4 offline completion callback.
  769. */
  770. static void
  771. bfa_fcs_rport_sm_fc4_offline(struct bfa_fcs_rport_s *rport,
  772. enum rport_event event)
  773. {
  774. bfa_trc(rport->fcs, rport->pwwn);
  775. bfa_trc(rport->fcs, rport->pid);
  776. bfa_trc(rport->fcs, event);
  777. switch (event) {
  778. case RPSM_EVENT_FC4_OFFLINE:
  779. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
  780. bfa_rport_offline(rport->bfa_rport);
  781. break;
  782. case RPSM_EVENT_SCN:
  783. case RPSM_EVENT_LOGO_IMP:
  784. case RPSM_EVENT_LOGO_RCVD:
  785. case RPSM_EVENT_ADDRESS_CHANGE:
  786. /**
  787. * rport is already going offline.
  788. * SCN - ignore and wait till transitioning to offline state
  789. */
  790. break;
  791. case RPSM_EVENT_DELETE:
  792. bfa_sm_set_state(rport, bfa_fcs_rport_sm_fc4_logosend);
  793. break;
  794. default:
  795. bfa_sm_fault(rport->fcs, event);
  796. }
  797. }
  798. /**
  799. * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
  800. * callback.
  801. */
  802. static void
  803. bfa_fcs_rport_sm_hcb_offline(struct bfa_fcs_rport_s *rport,
  804. enum rport_event event)
  805. {
  806. bfa_trc(rport->fcs, rport->pwwn);
  807. bfa_trc(rport->fcs, rport->pid);
  808. bfa_trc(rport->fcs, event);
  809. switch (event) {
  810. case RPSM_EVENT_HCB_OFFLINE:
  811. case RPSM_EVENT_ADDRESS_CHANGE:
  812. if (bfa_fcs_port_is_online(rport->port)) {
  813. if (bfa_fcs_fabric_is_switched(rport->port->fabric)) {
  814. bfa_sm_set_state(rport,
  815. bfa_fcs_rport_sm_nsdisc_sending);
  816. rport->ns_retries = 0;
  817. bfa_fcs_rport_send_gidpn(rport, NULL);
  818. } else {
  819. bfa_sm_set_state(rport,
  820. bfa_fcs_rport_sm_plogi_sending);
  821. rport->plogi_retries = 0;
  822. bfa_fcs_rport_send_plogi(rport, NULL);
  823. }
  824. } else {
  825. rport->pid = 0;
  826. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  827. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  828. bfa_fcs_rport_timeout, rport,
  829. bfa_fcs_rport_del_timeout);
  830. }
  831. break;
  832. case RPSM_EVENT_DELETE:
  833. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  834. bfa_fcs_rport_free(rport);
  835. break;
  836. case RPSM_EVENT_SCN:
  837. case RPSM_EVENT_LOGO_RCVD:
  838. /**
  839. * Ignore, already offline.
  840. */
  841. break;
  842. default:
  843. bfa_sm_fault(rport->fcs, event);
  844. }
  845. }
  846. /**
  847. * Rport is offline. FC-4s are offline. Awaiting BFA rport offline
  848. * callback to send LOGO accept.
  849. */
  850. static void
  851. bfa_fcs_rport_sm_hcb_logorcv(struct bfa_fcs_rport_s *rport,
  852. enum rport_event event)
  853. {
  854. bfa_trc(rport->fcs, rport->pwwn);
  855. bfa_trc(rport->fcs, rport->pid);
  856. bfa_trc(rport->fcs, event);
  857. switch (event) {
  858. case RPSM_EVENT_HCB_OFFLINE:
  859. case RPSM_EVENT_ADDRESS_CHANGE:
  860. if (rport->pid)
  861. bfa_fcs_rport_send_logo_acc(rport);
  862. /*
  863. * If the lport is online and if the rport is not a well known
  864. * address port, we try to re-discover the r-port.
  865. */
  866. if (bfa_fcs_port_is_online(rport->port)
  867. && (!BFA_FCS_PID_IS_WKA(rport->pid))) {
  868. bfa_sm_set_state(rport,
  869. bfa_fcs_rport_sm_nsdisc_sending);
  870. rport->ns_retries = 0;
  871. bfa_fcs_rport_send_gidpn(rport, NULL);
  872. } else {
  873. /*
  874. * if it is not a well known address, reset the pid to
  875. *
  876. */
  877. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  878. rport->pid = 0;
  879. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  880. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  881. bfa_fcs_rport_timeout, rport,
  882. bfa_fcs_rport_del_timeout);
  883. }
  884. break;
  885. case RPSM_EVENT_DELETE:
  886. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_logosend);
  887. break;
  888. case RPSM_EVENT_LOGO_IMP:
  889. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hcb_offline);
  890. break;
  891. case RPSM_EVENT_LOGO_RCVD:
  892. /**
  893. * Ignore - already processing a LOGO.
  894. */
  895. break;
  896. default:
  897. bfa_sm_fault(rport->fcs, event);
  898. }
  899. }
  900. /**
  901. * Rport is being deleted. FC-4s are offline. Awaiting BFA rport offline
  902. * callback to send LOGO.
  903. */
  904. static void
  905. bfa_fcs_rport_sm_hcb_logosend(struct bfa_fcs_rport_s *rport,
  906. enum rport_event event)
  907. {
  908. bfa_trc(rport->fcs, rport->pwwn);
  909. bfa_trc(rport->fcs, rport->pid);
  910. bfa_trc(rport->fcs, event);
  911. switch (event) {
  912. case RPSM_EVENT_HCB_OFFLINE:
  913. bfa_sm_set_state(rport, bfa_fcs_rport_sm_logo_sending);
  914. bfa_fcs_rport_send_logo(rport, NULL);
  915. break;
  916. case RPSM_EVENT_LOGO_RCVD:
  917. case RPSM_EVENT_ADDRESS_CHANGE:
  918. break;
  919. default:
  920. bfa_sm_fault(rport->fcs, event);
  921. }
  922. }
  923. /**
  924. * Rport is being deleted. FC-4s are offline. LOGO is being sent.
  925. */
  926. static void
  927. bfa_fcs_rport_sm_logo_sending(struct bfa_fcs_rport_s *rport,
  928. enum rport_event event)
  929. {
  930. bfa_trc(rport->fcs, rport->pwwn);
  931. bfa_trc(rport->fcs, rport->pid);
  932. bfa_trc(rport->fcs, event);
  933. switch (event) {
  934. case RPSM_EVENT_FCXP_SENT:
  935. /*
  936. * Once LOGO is sent, we donot wait for the response
  937. */
  938. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  939. bfa_fcs_rport_free(rport);
  940. break;
  941. case RPSM_EVENT_SCN:
  942. case RPSM_EVENT_ADDRESS_CHANGE:
  943. break;
  944. case RPSM_EVENT_LOGO_RCVD:
  945. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  946. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  947. bfa_fcs_rport_free(rport);
  948. break;
  949. default:
  950. bfa_sm_fault(rport->fcs, event);
  951. }
  952. }
  953. /**
  954. * Rport is offline. FC-4s are offline. BFA rport is offline.
  955. * Timer active to delete stale rport.
  956. */
  957. static void
  958. bfa_fcs_rport_sm_offline(struct bfa_fcs_rport_s *rport, enum rport_event event)
  959. {
  960. bfa_trc(rport->fcs, rport->pwwn);
  961. bfa_trc(rport->fcs, rport->pid);
  962. bfa_trc(rport->fcs, event);
  963. switch (event) {
  964. case RPSM_EVENT_TIMEOUT:
  965. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  966. bfa_fcs_rport_free(rport);
  967. break;
  968. case RPSM_EVENT_SCN:
  969. case RPSM_EVENT_ADDRESS_CHANGE:
  970. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  971. bfa_timer_stop(&rport->timer);
  972. rport->ns_retries = 0;
  973. bfa_fcs_rport_send_gidpn(rport, NULL);
  974. break;
  975. case RPSM_EVENT_DELETE:
  976. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  977. bfa_timer_stop(&rport->timer);
  978. bfa_fcs_rport_free(rport);
  979. break;
  980. case RPSM_EVENT_PLOGI_RCVD:
  981. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  982. bfa_timer_stop(&rport->timer);
  983. bfa_fcs_rport_send_plogiacc(rport, NULL);
  984. break;
  985. case RPSM_EVENT_LOGO_RCVD:
  986. case RPSM_EVENT_LOGO_IMP:
  987. break;
  988. case RPSM_EVENT_PLOGI_COMP:
  989. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  990. bfa_timer_stop(&rport->timer);
  991. bfa_fcs_rport_hal_online(rport);
  992. break;
  993. case RPSM_EVENT_PLOGI_SEND:
  994. bfa_timer_stop(&rport->timer);
  995. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  996. rport->plogi_retries = 0;
  997. bfa_fcs_rport_send_plogi(rport, NULL);
  998. break;
  999. default:
  1000. bfa_sm_fault(rport->fcs, event);
  1001. }
  1002. }
  1003. /**
  1004. * Rport address has changed. Nameserver discovery request is being sent.
  1005. */
  1006. static void
  1007. bfa_fcs_rport_sm_nsdisc_sending(struct bfa_fcs_rport_s *rport,
  1008. enum rport_event event)
  1009. {
  1010. bfa_trc(rport->fcs, rport->pwwn);
  1011. bfa_trc(rport->fcs, rport->pid);
  1012. bfa_trc(rport->fcs, event);
  1013. switch (event) {
  1014. case RPSM_EVENT_FCXP_SENT:
  1015. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sent);
  1016. break;
  1017. case RPSM_EVENT_DELETE:
  1018. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1019. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1020. bfa_fcs_rport_free(rport);
  1021. break;
  1022. case RPSM_EVENT_PLOGI_RCVD:
  1023. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  1024. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1025. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1026. break;
  1027. case RPSM_EVENT_SCN:
  1028. case RPSM_EVENT_LOGO_RCVD:
  1029. case RPSM_EVENT_PLOGI_SEND:
  1030. break;
  1031. case RPSM_EVENT_ADDRESS_CHANGE:
  1032. rport->ns_retries = 0; /* reset the retry count */
  1033. break;
  1034. case RPSM_EVENT_LOGO_IMP:
  1035. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1036. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1037. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1038. bfa_fcs_rport_timeout, rport,
  1039. bfa_fcs_rport_del_timeout);
  1040. break;
  1041. case RPSM_EVENT_PLOGI_COMP:
  1042. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  1043. bfa_fcxp_walloc_cancel(rport->fcs->bfa, &rport->fcxp_wqe);
  1044. bfa_fcs_rport_hal_online(rport);
  1045. break;
  1046. default:
  1047. bfa_sm_fault(rport->fcs, event);
  1048. }
  1049. }
  1050. /**
  1051. * Nameserver discovery failed. Waiting for timeout to retry.
  1052. */
  1053. static void
  1054. bfa_fcs_rport_sm_nsdisc_retry(struct bfa_fcs_rport_s *rport,
  1055. enum rport_event event)
  1056. {
  1057. bfa_trc(rport->fcs, rport->pwwn);
  1058. bfa_trc(rport->fcs, rport->pid);
  1059. bfa_trc(rport->fcs, event);
  1060. switch (event) {
  1061. case RPSM_EVENT_TIMEOUT:
  1062. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  1063. bfa_fcs_rport_send_gidpn(rport, NULL);
  1064. break;
  1065. case RPSM_EVENT_SCN:
  1066. case RPSM_EVENT_ADDRESS_CHANGE:
  1067. bfa_sm_set_state(rport, bfa_fcs_rport_sm_nsdisc_sending);
  1068. bfa_timer_stop(&rport->timer);
  1069. rport->ns_retries = 0;
  1070. bfa_fcs_rport_send_gidpn(rport, NULL);
  1071. break;
  1072. case RPSM_EVENT_DELETE:
  1073. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1074. bfa_timer_stop(&rport->timer);
  1075. bfa_fcs_rport_free(rport);
  1076. break;
  1077. case RPSM_EVENT_PLOGI_RCVD:
  1078. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  1079. bfa_timer_stop(&rport->timer);
  1080. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1081. break;
  1082. case RPSM_EVENT_LOGO_IMP:
  1083. rport->pid = 0;
  1084. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1085. bfa_timer_stop(&rport->timer);
  1086. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1087. bfa_fcs_rport_timeout, rport,
  1088. bfa_fcs_rport_del_timeout);
  1089. break;
  1090. case RPSM_EVENT_LOGO_RCVD:
  1091. bfa_fcs_rport_send_logo_acc(rport);
  1092. break;
  1093. case RPSM_EVENT_PLOGI_COMP:
  1094. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  1095. bfa_timer_stop(&rport->timer);
  1096. bfa_fcs_rport_hal_online(rport);
  1097. break;
  1098. default:
  1099. bfa_sm_fault(rport->fcs, event);
  1100. }
  1101. }
  1102. /**
  1103. * Rport address has changed. Nameserver discovery request is sent.
  1104. */
  1105. static void
  1106. bfa_fcs_rport_sm_nsdisc_sent(struct bfa_fcs_rport_s *rport,
  1107. enum rport_event event)
  1108. {
  1109. bfa_trc(rport->fcs, rport->pwwn);
  1110. bfa_trc(rport->fcs, rport->pid);
  1111. bfa_trc(rport->fcs, event);
  1112. switch (event) {
  1113. case RPSM_EVENT_ACCEPTED:
  1114. case RPSM_EVENT_ADDRESS_CHANGE:
  1115. if (rport->pid) {
  1116. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogi_sending);
  1117. bfa_fcs_rport_send_plogi(rport, NULL);
  1118. } else {
  1119. bfa_sm_set_state(rport,
  1120. bfa_fcs_rport_sm_nsdisc_sending);
  1121. rport->ns_retries = 0;
  1122. bfa_fcs_rport_send_gidpn(rport, NULL);
  1123. }
  1124. break;
  1125. case RPSM_EVENT_FAILED:
  1126. rport->ns_retries++;
  1127. if (rport->ns_retries < BFA_FCS_RPORT_MAX_RETRIES) {
  1128. bfa_sm_set_state(rport,
  1129. bfa_fcs_rport_sm_nsdisc_sending);
  1130. bfa_fcs_rport_send_gidpn(rport, NULL);
  1131. } else {
  1132. rport->pid = 0;
  1133. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1134. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1135. bfa_fcs_rport_timeout, rport,
  1136. bfa_fcs_rport_del_timeout);
  1137. };
  1138. break;
  1139. case RPSM_EVENT_DELETE:
  1140. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1141. bfa_fcxp_discard(rport->fcxp);
  1142. bfa_fcs_rport_free(rport);
  1143. break;
  1144. case RPSM_EVENT_PLOGI_RCVD:
  1145. bfa_sm_set_state(rport, bfa_fcs_rport_sm_plogiacc_sending);
  1146. bfa_fcxp_discard(rport->fcxp);
  1147. bfa_fcs_rport_send_plogiacc(rport, NULL);
  1148. break;
  1149. case RPSM_EVENT_LOGO_IMP:
  1150. rport->pid = 0;
  1151. bfa_sm_set_state(rport, bfa_fcs_rport_sm_offline);
  1152. bfa_fcxp_discard(rport->fcxp);
  1153. bfa_timer_start(rport->fcs->bfa, &rport->timer,
  1154. bfa_fcs_rport_timeout, rport,
  1155. bfa_fcs_rport_del_timeout);
  1156. break;
  1157. case RPSM_EVENT_SCN:
  1158. /**
  1159. * ignore, wait for NS query response
  1160. */
  1161. break;
  1162. case RPSM_EVENT_LOGO_RCVD:
  1163. /**
  1164. * Not logged-in yet. Accept LOGO.
  1165. */
  1166. bfa_fcs_rport_send_logo_acc(rport);
  1167. break;
  1168. case RPSM_EVENT_PLOGI_COMP:
  1169. bfa_sm_set_state(rport, bfa_fcs_rport_sm_hal_online);
  1170. bfa_fcxp_discard(rport->fcxp);
  1171. bfa_fcs_rport_hal_online(rport);
  1172. break;
  1173. default:
  1174. bfa_sm_fault(rport->fcs, event);
  1175. }
  1176. }
  1177. /**
  1178. * fcs_rport_private FCS RPORT provate functions
  1179. */
  1180. static void
  1181. bfa_fcs_rport_send_plogi(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1182. {
  1183. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1184. struct bfa_fcs_port_s *port = rport->port;
  1185. struct fchs_s fchs;
  1186. int len;
  1187. struct bfa_fcxp_s *fcxp;
  1188. bfa_trc(rport->fcs, rport->pwwn);
  1189. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  1190. if (!fcxp) {
  1191. bfa_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1192. bfa_fcs_rport_send_plogi, rport);
  1193. return;
  1194. }
  1195. rport->fcxp = fcxp;
  1196. len = fc_plogi_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1197. bfa_fcs_port_get_fcid(port), 0,
  1198. port->port_cfg.pwwn, port->port_cfg.nwwn,
  1199. bfa_fcport_get_maxfrsize(port->fcs->bfa));
  1200. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1201. FC_CLASS_3, len, &fchs, bfa_fcs_rport_plogi_response,
  1202. (void *)rport, FC_MAX_PDUSZ, FC_RA_TOV);
  1203. rport->stats.plogis++;
  1204. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1205. }
  1206. static void
  1207. bfa_fcs_rport_plogi_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1208. bfa_status_t req_status, u32 rsp_len,
  1209. u32 resid_len, struct fchs_s *rsp_fchs)
  1210. {
  1211. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)cbarg;
  1212. struct fc_logi_s *plogi_rsp;
  1213. struct fc_ls_rjt_s *ls_rjt;
  1214. struct bfa_fcs_rport_s *twin;
  1215. struct list_head *qe;
  1216. bfa_trc(rport->fcs, rport->pwwn);
  1217. /*
  1218. * Sanity Checks
  1219. */
  1220. if (req_status != BFA_STATUS_OK) {
  1221. bfa_trc(rport->fcs, req_status);
  1222. rport->stats.plogi_failed++;
  1223. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1224. return;
  1225. }
  1226. plogi_rsp = (struct fc_logi_s *) BFA_FCXP_RSP_PLD(fcxp);
  1227. /**
  1228. * Check for failure first.
  1229. */
  1230. if (plogi_rsp->els_cmd.els_code != FC_ELS_ACC) {
  1231. ls_rjt = (struct fc_ls_rjt_s *) BFA_FCXP_RSP_PLD(fcxp);
  1232. bfa_trc(rport->fcs, ls_rjt->reason_code);
  1233. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  1234. rport->stats.plogi_rejects++;
  1235. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1236. return;
  1237. }
  1238. /**
  1239. * PLOGI is complete. Make sure this device is not one of the known
  1240. * device with a new FC port address.
  1241. */
  1242. list_for_each(qe, &rport->port->rport_q) {
  1243. twin = (struct bfa_fcs_rport_s *)qe;
  1244. if (twin == rport)
  1245. continue;
  1246. if (!rport->pwwn && (plogi_rsp->port_name == twin->pwwn)) {
  1247. bfa_trc(rport->fcs, twin->pid);
  1248. bfa_trc(rport->fcs, rport->pid);
  1249. /*
  1250. * Update plogi stats in twin
  1251. */
  1252. twin->stats.plogis += rport->stats.plogis;
  1253. twin->stats.plogi_rejects += rport->stats.plogi_rejects;
  1254. twin->stats.plogi_timeouts +=
  1255. rport->stats.plogi_timeouts;
  1256. twin->stats.plogi_failed += rport->stats.plogi_failed;
  1257. twin->stats.plogi_rcvd += rport->stats.plogi_rcvd;
  1258. twin->stats.plogi_accs++;
  1259. bfa_fcs_rport_delete(rport);
  1260. bfa_fcs_rport_update(twin, plogi_rsp);
  1261. twin->pid = rsp_fchs->s_id;
  1262. bfa_sm_send_event(twin, RPSM_EVENT_PLOGI_COMP);
  1263. return;
  1264. }
  1265. }
  1266. /**
  1267. * Normal login path -- no evil twins.
  1268. */
  1269. rport->stats.plogi_accs++;
  1270. bfa_fcs_rport_update(rport, plogi_rsp);
  1271. bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  1272. }
  1273. static void
  1274. bfa_fcs_rport_send_plogiacc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1275. {
  1276. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1277. struct bfa_fcs_port_s *port = rport->port;
  1278. struct fchs_s fchs;
  1279. int len;
  1280. struct bfa_fcxp_s *fcxp;
  1281. bfa_trc(rport->fcs, rport->pwwn);
  1282. bfa_trc(rport->fcs, rport->reply_oxid);
  1283. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  1284. if (!fcxp) {
  1285. bfa_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1286. bfa_fcs_rport_send_plogiacc, rport);
  1287. return;
  1288. }
  1289. rport->fcxp = fcxp;
  1290. len = fc_plogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1291. bfa_fcs_port_get_fcid(port), rport->reply_oxid,
  1292. port->port_cfg.pwwn, port->port_cfg.nwwn,
  1293. bfa_fcport_get_maxfrsize(port->fcs->bfa));
  1294. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1295. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1296. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1297. }
  1298. static void
  1299. bfa_fcs_rport_send_adisc(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1300. {
  1301. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1302. struct bfa_fcs_port_s *port = rport->port;
  1303. struct fchs_s fchs;
  1304. int len;
  1305. struct bfa_fcxp_s *fcxp;
  1306. bfa_trc(rport->fcs, rport->pwwn);
  1307. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  1308. if (!fcxp) {
  1309. bfa_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1310. bfa_fcs_rport_send_adisc, rport);
  1311. return;
  1312. }
  1313. rport->fcxp = fcxp;
  1314. len = fc_adisc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1315. bfa_fcs_port_get_fcid(port), 0,
  1316. port->port_cfg.pwwn, port->port_cfg.nwwn);
  1317. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1318. FC_CLASS_3, len, &fchs, bfa_fcs_rport_adisc_response,
  1319. rport, FC_MAX_PDUSZ, FC_RA_TOV);
  1320. rport->stats.adisc_sent++;
  1321. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1322. }
  1323. static void
  1324. bfa_fcs_rport_adisc_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1325. bfa_status_t req_status, u32 rsp_len,
  1326. u32 resid_len, struct fchs_s *rsp_fchs)
  1327. {
  1328. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)cbarg;
  1329. void *pld = bfa_fcxp_get_rspbuf(fcxp);
  1330. struct fc_ls_rjt_s *ls_rjt;
  1331. if (req_status != BFA_STATUS_OK) {
  1332. bfa_trc(rport->fcs, req_status);
  1333. rport->stats.adisc_failed++;
  1334. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1335. return;
  1336. }
  1337. if (fc_adisc_rsp_parse((struct fc_adisc_s *)pld, rsp_len, rport->pwwn,
  1338. rport->nwwn) == FC_PARSE_OK) {
  1339. rport->stats.adisc_accs++;
  1340. bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  1341. return;
  1342. }
  1343. rport->stats.adisc_rejects++;
  1344. ls_rjt = pld;
  1345. bfa_trc(rport->fcs, ls_rjt->els_cmd.els_code);
  1346. bfa_trc(rport->fcs, ls_rjt->reason_code);
  1347. bfa_trc(rport->fcs, ls_rjt->reason_code_expl);
  1348. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1349. }
  1350. static void
  1351. bfa_fcs_rport_send_gidpn(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1352. {
  1353. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1354. struct bfa_fcs_port_s *port = rport->port;
  1355. struct fchs_s fchs;
  1356. struct bfa_fcxp_s *fcxp;
  1357. int len;
  1358. bfa_trc(rport->fcs, rport->pid);
  1359. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  1360. if (!fcxp) {
  1361. bfa_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1362. bfa_fcs_rport_send_gidpn, rport);
  1363. return;
  1364. }
  1365. rport->fcxp = fcxp;
  1366. len = fc_gidpn_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1367. bfa_fcs_port_get_fcid(port), 0, rport->pwwn);
  1368. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1369. FC_CLASS_3, len, &fchs, bfa_fcs_rport_gidpn_response,
  1370. (void *)rport, FC_MAX_PDUSZ, FC_RA_TOV);
  1371. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1372. }
  1373. static void
  1374. bfa_fcs_rport_gidpn_response(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1375. bfa_status_t req_status, u32 rsp_len,
  1376. u32 resid_len, struct fchs_s *rsp_fchs)
  1377. {
  1378. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)cbarg;
  1379. struct bfa_fcs_rport_s *twin;
  1380. struct list_head *qe;
  1381. struct ct_hdr_s *cthdr;
  1382. struct fcgs_gidpn_resp_s *gidpn_rsp;
  1383. bfa_trc(rport->fcs, rport->pwwn);
  1384. cthdr = (struct ct_hdr_s *) BFA_FCXP_RSP_PLD(fcxp);
  1385. cthdr->cmd_rsp_code = bfa_os_ntohs(cthdr->cmd_rsp_code);
  1386. if (cthdr->cmd_rsp_code == CT_RSP_ACCEPT) {
  1387. /*
  1388. * Check if the pid is the same as before.
  1389. */
  1390. gidpn_rsp = (struct fcgs_gidpn_resp_s *) (cthdr + 1);
  1391. if (gidpn_rsp->dap == rport->pid) {
  1392. /*
  1393. * Device is online
  1394. */
  1395. bfa_sm_send_event(rport, RPSM_EVENT_ACCEPTED);
  1396. } else {
  1397. /*
  1398. * Device's PID has changed. We need to cleanup and
  1399. * re-login. If there is another device with the the
  1400. * newly discovered pid, send an scn notice so that its
  1401. * new pid can be discovered.
  1402. */
  1403. list_for_each(qe, &rport->port->rport_q) {
  1404. twin = (struct bfa_fcs_rport_s *)qe;
  1405. if (twin == rport)
  1406. continue;
  1407. if (gidpn_rsp->dap == twin->pid) {
  1408. bfa_trc(rport->fcs, twin->pid);
  1409. bfa_trc(rport->fcs, rport->pid);
  1410. twin->pid = 0;
  1411. bfa_sm_send_event(twin,
  1412. RPSM_EVENT_ADDRESS_CHANGE);
  1413. }
  1414. }
  1415. rport->pid = gidpn_rsp->dap;
  1416. bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_CHANGE);
  1417. }
  1418. return;
  1419. }
  1420. /*
  1421. * Reject Response
  1422. */
  1423. switch (cthdr->reason_code) {
  1424. case CT_RSN_LOGICAL_BUSY:
  1425. /*
  1426. * Need to retry
  1427. */
  1428. bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  1429. break;
  1430. case CT_RSN_UNABLE_TO_PERF:
  1431. /*
  1432. * device doesn't exist : Start timer to cleanup this later.
  1433. */
  1434. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1435. break;
  1436. default:
  1437. bfa_sm_send_event(rport, RPSM_EVENT_FAILED);
  1438. break;
  1439. }
  1440. }
  1441. /**
  1442. * Called to send a logout to the rport.
  1443. */
  1444. static void
  1445. bfa_fcs_rport_send_logo(void *rport_cbarg, struct bfa_fcxp_s *fcxp_alloced)
  1446. {
  1447. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1448. struct bfa_fcs_port_s *port;
  1449. struct fchs_s fchs;
  1450. struct bfa_fcxp_s *fcxp;
  1451. u16 len;
  1452. bfa_trc(rport->fcs, rport->pid);
  1453. port = rport->port;
  1454. fcxp = fcxp_alloced ? fcxp_alloced : bfa_fcs_fcxp_alloc(port->fcs);
  1455. if (!fcxp) {
  1456. bfa_fcxp_alloc_wait(port->fcs->bfa, &rport->fcxp_wqe,
  1457. bfa_fcs_rport_send_logo, rport);
  1458. return;
  1459. }
  1460. rport->fcxp = fcxp;
  1461. len = fc_logo_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1462. bfa_fcs_port_get_fcid(port), 0,
  1463. bfa_fcs_port_get_pwwn(port));
  1464. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1465. FC_CLASS_3, len, &fchs, NULL, rport, FC_MAX_PDUSZ,
  1466. FC_ED_TOV);
  1467. rport->stats.logos++;
  1468. bfa_fcxp_discard(rport->fcxp);
  1469. bfa_sm_send_event(rport, RPSM_EVENT_FCXP_SENT);
  1470. }
  1471. /**
  1472. * Send ACC for a LOGO received.
  1473. */
  1474. static void
  1475. bfa_fcs_rport_send_logo_acc(void *rport_cbarg)
  1476. {
  1477. struct bfa_fcs_rport_s *rport = rport_cbarg;
  1478. struct bfa_fcs_port_s *port;
  1479. struct fchs_s fchs;
  1480. struct bfa_fcxp_s *fcxp;
  1481. u16 len;
  1482. bfa_trc(rport->fcs, rport->pid);
  1483. port = rport->port;
  1484. fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  1485. if (!fcxp)
  1486. return;
  1487. rport->stats.logo_rcvd++;
  1488. len = fc_logo_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rport->pid,
  1489. bfa_fcs_port_get_fcid(port), rport->reply_oxid);
  1490. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1491. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1492. }
  1493. /**
  1494. * This routine will be called by bfa_timer on timer timeouts.
  1495. *
  1496. * param[in] rport - pointer to bfa_fcs_port_ns_t.
  1497. * param[out] rport_status - pointer to return vport status in
  1498. *
  1499. * return
  1500. * void
  1501. *
  1502. * Special Considerations:
  1503. *
  1504. * note
  1505. */
  1506. static void
  1507. bfa_fcs_rport_timeout(void *arg)
  1508. {
  1509. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)arg;
  1510. rport->stats.plogi_timeouts++;
  1511. bfa_sm_send_event(rport, RPSM_EVENT_TIMEOUT);
  1512. }
  1513. static void
  1514. bfa_fcs_rport_process_prli(struct bfa_fcs_rport_s *rport,
  1515. struct fchs_s *rx_fchs, u16 len)
  1516. {
  1517. struct bfa_fcxp_s *fcxp;
  1518. struct fchs_s fchs;
  1519. struct bfa_fcs_port_s *port = rport->port;
  1520. struct fc_prli_s *prli;
  1521. bfa_trc(port->fcs, rx_fchs->s_id);
  1522. bfa_trc(port->fcs, rx_fchs->d_id);
  1523. rport->stats.prli_rcvd++;
  1524. if (BFA_FCS_VPORT_IS_TARGET_MODE(port)) {
  1525. /*
  1526. * Target Mode : Let the fcptm handle it
  1527. */
  1528. bfa_fcs_tin_rx_prli(rport->tin, rx_fchs, len);
  1529. return;
  1530. }
  1531. /*
  1532. * We are either in Initiator or ipfc Mode
  1533. */
  1534. prli = (struct fc_prli_s *) (rx_fchs + 1);
  1535. if (prli->parampage.servparams.initiator) {
  1536. bfa_trc(rport->fcs, prli->parampage.type);
  1537. rport->scsi_function = BFA_RPORT_INITIATOR;
  1538. bfa_fcs_itnim_is_initiator(rport->itnim);
  1539. } else {
  1540. /*
  1541. * @todo: PRLI from a target ?
  1542. */
  1543. bfa_trc(port->fcs, rx_fchs->s_id);
  1544. rport->scsi_function = BFA_RPORT_TARGET;
  1545. }
  1546. fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  1547. if (!fcxp)
  1548. return;
  1549. len = fc_prli_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rx_fchs->s_id,
  1550. bfa_fcs_port_get_fcid(port), rx_fchs->ox_id,
  1551. port->port_cfg.roles);
  1552. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1553. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1554. }
  1555. static void
  1556. bfa_fcs_rport_process_rpsc(struct bfa_fcs_rport_s *rport,
  1557. struct fchs_s *rx_fchs, u16 len)
  1558. {
  1559. struct bfa_fcxp_s *fcxp;
  1560. struct fchs_s fchs;
  1561. struct bfa_fcs_port_s *port = rport->port;
  1562. struct fc_rpsc_speed_info_s speeds;
  1563. struct bfa_pport_attr_s pport_attr;
  1564. bfa_trc(port->fcs, rx_fchs->s_id);
  1565. bfa_trc(port->fcs, rx_fchs->d_id);
  1566. rport->stats.rpsc_rcvd++;
  1567. speeds.port_speed_cap =
  1568. RPSC_SPEED_CAP_1G | RPSC_SPEED_CAP_2G | RPSC_SPEED_CAP_4G |
  1569. RPSC_SPEED_CAP_8G;
  1570. /*
  1571. * get curent speed from pport attributes from BFA
  1572. */
  1573. bfa_fcport_get_attr(port->fcs->bfa, &pport_attr);
  1574. speeds.port_op_speed = fc_bfa_speed_to_rpsc_operspeed(pport_attr.speed);
  1575. fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  1576. if (!fcxp)
  1577. return;
  1578. len = fc_rpsc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rx_fchs->s_id,
  1579. bfa_fcs_port_get_fcid(port), rx_fchs->ox_id,
  1580. &speeds);
  1581. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  1582. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  1583. }
  1584. static void
  1585. bfa_fcs_rport_process_adisc(struct bfa_fcs_rport_s *rport,
  1586. struct fchs_s *rx_fchs, u16 len)
  1587. {
  1588. struct bfa_fcxp_s *fcxp;
  1589. struct fchs_s fchs;
  1590. struct bfa_fcs_port_s *port = rport->port;
  1591. struct fc_adisc_s *adisc;
  1592. bfa_trc(port->fcs, rx_fchs->s_id);
  1593. bfa_trc(port->fcs, rx_fchs->d_id);
  1594. rport->stats.adisc_rcvd++;
  1595. if (BFA_FCS_VPORT_IS_TARGET_MODE(port)) {
  1596. /*
  1597. * @todo : Target Mode handling
  1598. */
  1599. bfa_trc(port->fcs, rx_fchs->d_id);
  1600. bfa_assert(0);
  1601. return;
  1602. }
  1603. adisc = (struct fc_adisc_s *) (rx_fchs + 1);
  1604. /*
  1605. * Accept if the itnim for this rport is online. Else reject the ADISC
  1606. */
  1607. if (bfa_fcs_itnim_get_online_state(rport->itnim) == BFA_STATUS_OK) {
  1608. fcxp = bfa_fcs_fcxp_alloc(port->fcs);
  1609. if (!fcxp)
  1610. return;
  1611. len = fc_adisc_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1612. rx_fchs->s_id,
  1613. bfa_fcs_port_get_fcid(port),
  1614. rx_fchs->ox_id, port->port_cfg.pwwn,
  1615. port->port_cfg.nwwn);
  1616. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag,
  1617. BFA_FALSE, FC_CLASS_3, len, &fchs, NULL, NULL,
  1618. FC_MAX_PDUSZ, 0);
  1619. } else {
  1620. rport->stats.adisc_rejected++;
  1621. bfa_fcs_rport_send_ls_rjt(rport, rx_fchs,
  1622. FC_LS_RJT_RSN_UNABLE_TO_PERF_CMD,
  1623. FC_LS_RJT_EXP_LOGIN_REQUIRED);
  1624. }
  1625. }
  1626. static void
  1627. bfa_fcs_rport_hal_online(struct bfa_fcs_rport_s *rport)
  1628. {
  1629. struct bfa_fcs_port_s *port = rport->port;
  1630. struct bfa_rport_info_s rport_info;
  1631. rport_info.pid = rport->pid;
  1632. rport_info.local_pid = port->pid;
  1633. rport_info.lp_tag = port->lp_tag;
  1634. rport_info.vf_id = port->fabric->vf_id;
  1635. rport_info.vf_en = port->fabric->is_vf;
  1636. rport_info.fc_class = rport->fc_cos;
  1637. rport_info.cisc = rport->cisc;
  1638. rport_info.max_frmsz = rport->maxfrsize;
  1639. bfa_rport_online(rport->bfa_rport, &rport_info);
  1640. }
  1641. static void
  1642. bfa_fcs_rport_fc4_pause(struct bfa_fcs_rport_s *rport)
  1643. {
  1644. if (bfa_fcs_port_is_initiator(rport->port))
  1645. bfa_fcs_itnim_pause(rport->itnim);
  1646. if (bfa_fcs_port_is_target(rport->port))
  1647. bfa_fcs_tin_pause(rport->tin);
  1648. }
  1649. static void
  1650. bfa_fcs_rport_fc4_resume(struct bfa_fcs_rport_s *rport)
  1651. {
  1652. if (bfa_fcs_port_is_initiator(rport->port))
  1653. bfa_fcs_itnim_resume(rport->itnim);
  1654. if (bfa_fcs_port_is_target(rport->port))
  1655. bfa_fcs_tin_resume(rport->tin);
  1656. }
  1657. static struct bfa_fcs_rport_s *
  1658. bfa_fcs_rport_alloc(struct bfa_fcs_port_s *port, wwn_t pwwn, u32 rpid)
  1659. {
  1660. struct bfa_fcs_s *fcs = port->fcs;
  1661. struct bfa_fcs_rport_s *rport;
  1662. struct bfad_rport_s *rport_drv;
  1663. /**
  1664. * allocate rport
  1665. */
  1666. if (bfa_fcb_rport_alloc(fcs->bfad, &rport, &rport_drv)
  1667. != BFA_STATUS_OK) {
  1668. bfa_trc(fcs, rpid);
  1669. return NULL;
  1670. }
  1671. /*
  1672. * Initialize r-port
  1673. */
  1674. rport->port = port;
  1675. rport->fcs = fcs;
  1676. rport->rp_drv = rport_drv;
  1677. rport->pid = rpid;
  1678. rport->pwwn = pwwn;
  1679. /**
  1680. * allocate BFA rport
  1681. */
  1682. rport->bfa_rport = bfa_rport_create(port->fcs->bfa, rport);
  1683. if (!rport->bfa_rport) {
  1684. bfa_trc(fcs, rpid);
  1685. kfree(rport_drv);
  1686. return NULL;
  1687. }
  1688. /**
  1689. * allocate FC-4s
  1690. */
  1691. bfa_assert(bfa_fcs_port_is_initiator(port) ^
  1692. bfa_fcs_port_is_target(port));
  1693. if (bfa_fcs_port_is_initiator(port)) {
  1694. rport->itnim = bfa_fcs_itnim_create(rport);
  1695. if (!rport->itnim) {
  1696. bfa_trc(fcs, rpid);
  1697. bfa_rport_delete(rport->bfa_rport);
  1698. kfree(rport_drv);
  1699. return NULL;
  1700. }
  1701. }
  1702. if (bfa_fcs_port_is_target(port)) {
  1703. rport->tin = bfa_fcs_tin_create(rport);
  1704. if (!rport->tin) {
  1705. bfa_trc(fcs, rpid);
  1706. bfa_rport_delete(rport->bfa_rport);
  1707. kfree(rport_drv);
  1708. return NULL;
  1709. }
  1710. }
  1711. bfa_fcs_port_add_rport(port, rport);
  1712. bfa_sm_set_state(rport, bfa_fcs_rport_sm_uninit);
  1713. /*
  1714. * Initialize the Rport Features(RPF) Sub Module
  1715. */
  1716. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  1717. bfa_fcs_rpf_init(rport);
  1718. return rport;
  1719. }
  1720. static void
  1721. bfa_fcs_rport_free(struct bfa_fcs_rport_s *rport)
  1722. {
  1723. struct bfa_fcs_port_s *port = rport->port;
  1724. /**
  1725. * - delete FC-4s
  1726. * - delete BFA rport
  1727. * - remove from queue of rports
  1728. */
  1729. if (bfa_fcs_port_is_initiator(port))
  1730. bfa_fcs_itnim_delete(rport->itnim);
  1731. if (bfa_fcs_port_is_target(port))
  1732. bfa_fcs_tin_delete(rport->tin);
  1733. bfa_rport_delete(rport->bfa_rport);
  1734. bfa_fcs_port_del_rport(port, rport);
  1735. kfree(rport->rp_drv);
  1736. }
  1737. static void
  1738. bfa_fcs_rport_aen_post(struct bfa_fcs_rport_s *rport,
  1739. enum bfa_rport_aen_event event,
  1740. struct bfa_rport_aen_data_s *data)
  1741. {
  1742. union bfa_aen_data_u aen_data;
  1743. struct bfa_log_mod_s *logmod = rport->fcs->logm;
  1744. wwn_t lpwwn = bfa_fcs_port_get_pwwn(rport->port);
  1745. wwn_t rpwwn = rport->pwwn;
  1746. char lpwwn_ptr[BFA_STRING_32];
  1747. char rpwwn_ptr[BFA_STRING_32];
  1748. char *prio_str[] = { "unknown", "high", "medium", "low" };
  1749. wwn2str(lpwwn_ptr, lpwwn);
  1750. wwn2str(rpwwn_ptr, rpwwn);
  1751. switch (event) {
  1752. case BFA_RPORT_AEN_ONLINE:
  1753. case BFA_RPORT_AEN_OFFLINE:
  1754. case BFA_RPORT_AEN_DISCONNECT:
  1755. bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_RPORT, event),
  1756. rpwwn_ptr, lpwwn_ptr);
  1757. break;
  1758. case BFA_RPORT_AEN_QOS_PRIO:
  1759. aen_data.rport.priv.qos = data->priv.qos;
  1760. bfa_log(logmod, BFA_AEN_RPORT_QOS_PRIO,
  1761. prio_str[aen_data.rport.priv.qos.qos_priority],
  1762. rpwwn_ptr, lpwwn_ptr);
  1763. break;
  1764. case BFA_RPORT_AEN_QOS_FLOWID:
  1765. aen_data.rport.priv.qos = data->priv.qos;
  1766. bfa_log(logmod, BFA_AEN_RPORT_QOS_FLOWID,
  1767. aen_data.rport.priv.qos.qos_flow_id, rpwwn_ptr,
  1768. lpwwn_ptr);
  1769. break;
  1770. default:
  1771. break;
  1772. }
  1773. aen_data.rport.vf_id = rport->port->fabric->vf_id;
  1774. aen_data.rport.ppwwn =
  1775. bfa_fcs_port_get_pwwn(bfa_fcs_get_base_port(rport->fcs));
  1776. aen_data.rport.lpwwn = lpwwn;
  1777. aen_data.rport.rpwwn = rpwwn;
  1778. }
  1779. static void
  1780. bfa_fcs_rport_online_action(struct bfa_fcs_rport_s *rport)
  1781. {
  1782. struct bfa_fcs_port_s *port = rport->port;
  1783. rport->stats.onlines++;
  1784. if (bfa_fcs_port_is_initiator(port)) {
  1785. bfa_fcs_itnim_rport_online(rport->itnim);
  1786. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  1787. bfa_fcs_rpf_rport_online(rport);
  1788. };
  1789. if (bfa_fcs_port_is_target(port))
  1790. bfa_fcs_tin_rport_online(rport->tin);
  1791. /*
  1792. * Don't post events for well known addresses
  1793. */
  1794. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  1795. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_ONLINE, NULL);
  1796. }
  1797. static void
  1798. bfa_fcs_rport_offline_action(struct bfa_fcs_rport_s *rport)
  1799. {
  1800. struct bfa_fcs_port_s *port = rport->port;
  1801. rport->stats.offlines++;
  1802. /*
  1803. * Don't post events for well known addresses
  1804. */
  1805. if (!BFA_FCS_PID_IS_WKA(rport->pid)) {
  1806. if (bfa_fcs_port_is_online(rport->port) == BFA_TRUE) {
  1807. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_DISCONNECT,
  1808. NULL);
  1809. } else {
  1810. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_OFFLINE,
  1811. NULL);
  1812. }
  1813. }
  1814. if (bfa_fcs_port_is_initiator(port)) {
  1815. bfa_fcs_itnim_rport_offline(rport->itnim);
  1816. if (!BFA_FCS_PID_IS_WKA(rport->pid))
  1817. bfa_fcs_rpf_rport_offline(rport);
  1818. }
  1819. if (bfa_fcs_port_is_target(port))
  1820. bfa_fcs_tin_rport_offline(rport->tin);
  1821. }
  1822. /**
  1823. * Update rport parameters from PLOGI or PLOGI accept.
  1824. */
  1825. static void
  1826. bfa_fcs_rport_update(struct bfa_fcs_rport_s *rport, struct fc_logi_s *plogi)
  1827. {
  1828. struct bfa_fcs_port_s *port = rport->port;
  1829. /**
  1830. * - port name
  1831. * - node name
  1832. */
  1833. rport->pwwn = plogi->port_name;
  1834. rport->nwwn = plogi->node_name;
  1835. /**
  1836. * - class of service
  1837. */
  1838. rport->fc_cos = 0;
  1839. if (plogi->class3.class_valid)
  1840. rport->fc_cos = FC_CLASS_3;
  1841. if (plogi->class2.class_valid)
  1842. rport->fc_cos |= FC_CLASS_2;
  1843. /**
  1844. * - CISC
  1845. * - MAX receive frame size
  1846. */
  1847. rport->cisc = plogi->csp.cisc;
  1848. rport->maxfrsize = bfa_os_ntohs(plogi->class3.rxsz);
  1849. bfa_trc(port->fcs, bfa_os_ntohs(plogi->csp.bbcred));
  1850. bfa_trc(port->fcs, port->fabric->bb_credit);
  1851. /**
  1852. * Direct Attach P2P mode :
  1853. * This is to handle a bug (233476) in IBM targets in Direct Attach
  1854. * Mode. Basically, in FLOGI Accept the target would have erroneously
  1855. * set the BB Credit to the value used in the FLOGI sent by the HBA.
  1856. * It uses the correct value (its own BB credit) in PLOGI.
  1857. */
  1858. if ((!bfa_fcs_fabric_is_switched(port->fabric))
  1859. && (bfa_os_ntohs(plogi->csp.bbcred) < port->fabric->bb_credit)) {
  1860. bfa_trc(port->fcs, bfa_os_ntohs(plogi->csp.bbcred));
  1861. bfa_trc(port->fcs, port->fabric->bb_credit);
  1862. port->fabric->bb_credit = bfa_os_ntohs(plogi->csp.bbcred);
  1863. bfa_fcport_set_tx_bbcredit(port->fcs->bfa,
  1864. port->fabric->bb_credit);
  1865. }
  1866. }
  1867. /**
  1868. * Called to handle LOGO received from an existing remote port.
  1869. */
  1870. static void
  1871. bfa_fcs_rport_process_logo(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs)
  1872. {
  1873. rport->reply_oxid = fchs->ox_id;
  1874. bfa_trc(rport->fcs, rport->reply_oxid);
  1875. rport->stats.logo_rcvd++;
  1876. bfa_sm_send_event(rport, RPSM_EVENT_LOGO_RCVD);
  1877. }
  1878. /**
  1879. * fcs_rport_public FCS rport public interfaces
  1880. */
  1881. /**
  1882. * Called by bport/vport to create a remote port instance for a discovered
  1883. * remote device.
  1884. *
  1885. * @param[in] port - base port or vport
  1886. * @param[in] rpid - remote port ID
  1887. *
  1888. * @return None
  1889. */
  1890. struct bfa_fcs_rport_s *
  1891. bfa_fcs_rport_create(struct bfa_fcs_port_s *port, u32 rpid)
  1892. {
  1893. struct bfa_fcs_rport_s *rport;
  1894. bfa_trc(port->fcs, rpid);
  1895. rport = bfa_fcs_rport_alloc(port, WWN_NULL, rpid);
  1896. if (!rport)
  1897. return NULL;
  1898. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
  1899. return rport;
  1900. }
  1901. /**
  1902. * Called to create a rport for which only the wwn is known.
  1903. *
  1904. * @param[in] port - base port
  1905. * @param[in] rpwwn - remote port wwn
  1906. *
  1907. * @return None
  1908. */
  1909. struct bfa_fcs_rport_s *
  1910. bfa_fcs_rport_create_by_wwn(struct bfa_fcs_port_s *port, wwn_t rpwwn)
  1911. {
  1912. struct bfa_fcs_rport_s *rport;
  1913. bfa_trc(port->fcs, rpwwn);
  1914. rport = bfa_fcs_rport_alloc(port, rpwwn, 0);
  1915. if (!rport)
  1916. return NULL;
  1917. bfa_sm_send_event(rport, RPSM_EVENT_ADDRESS_DISC);
  1918. return rport;
  1919. }
  1920. /**
  1921. * Called by bport in private loop topology to indicate that a
  1922. * rport has been discovered and plogi has been completed.
  1923. *
  1924. * @param[in] port - base port or vport
  1925. * @param[in] rpid - remote port ID
  1926. */
  1927. void
  1928. bfa_fcs_rport_start(struct bfa_fcs_port_s *port, struct fchs_s *fchs,
  1929. struct fc_logi_s *plogi)
  1930. {
  1931. struct bfa_fcs_rport_s *rport;
  1932. rport = bfa_fcs_rport_alloc(port, WWN_NULL, fchs->s_id);
  1933. if (!rport)
  1934. return;
  1935. bfa_fcs_rport_update(rport, plogi);
  1936. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_COMP);
  1937. }
  1938. /**
  1939. * Called by bport/vport to handle PLOGI received from a new remote port.
  1940. * If an existing rport does a plogi, it will be handled separately.
  1941. */
  1942. void
  1943. bfa_fcs_rport_plogi_create(struct bfa_fcs_port_s *port, struct fchs_s *fchs,
  1944. struct fc_logi_s *plogi)
  1945. {
  1946. struct bfa_fcs_rport_s *rport;
  1947. rport = bfa_fcs_rport_alloc(port, plogi->port_name, fchs->s_id);
  1948. if (!rport)
  1949. return;
  1950. bfa_fcs_rport_update(rport, plogi);
  1951. rport->reply_oxid = fchs->ox_id;
  1952. bfa_trc(rport->fcs, rport->reply_oxid);
  1953. rport->stats.plogi_rcvd++;
  1954. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  1955. }
  1956. static int
  1957. wwn_compare(wwn_t wwn1, wwn_t wwn2)
  1958. {
  1959. u8 *b1 = (u8 *) &wwn1;
  1960. u8 *b2 = (u8 *) &wwn2;
  1961. int i;
  1962. for (i = 0; i < sizeof(wwn_t); i++) {
  1963. if (b1[i] < b2[i])
  1964. return -1;
  1965. if (b1[i] > b2[i])
  1966. return 1;
  1967. }
  1968. return 0;
  1969. }
  1970. /**
  1971. * Called by bport/vport to handle PLOGI received from an existing
  1972. * remote port.
  1973. */
  1974. void
  1975. bfa_fcs_rport_plogi(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
  1976. struct fc_logi_s *plogi)
  1977. {
  1978. /**
  1979. * @todo Handle P2P and initiator-initiator.
  1980. */
  1981. bfa_fcs_rport_update(rport, plogi);
  1982. rport->reply_oxid = rx_fchs->ox_id;
  1983. bfa_trc(rport->fcs, rport->reply_oxid);
  1984. /**
  1985. * In Switched fabric topology,
  1986. * PLOGI to each other. If our pwwn is smaller, ignore it,
  1987. * if it is not a well known address.
  1988. * If the link topology is N2N,
  1989. * this Plogi should be accepted.
  1990. */
  1991. if ((wwn_compare(rport->port->port_cfg.pwwn, rport->pwwn) == -1)
  1992. && (bfa_fcs_fabric_is_switched(rport->port->fabric))
  1993. && (!BFA_FCS_PID_IS_WKA(rport->pid))) {
  1994. bfa_trc(rport->fcs, rport->pid);
  1995. return;
  1996. }
  1997. rport->stats.plogi_rcvd++;
  1998. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_RCVD);
  1999. }
  2000. /**
  2001. * Called by bport/vport to delete a remote port instance.
  2002. *
  2003. * Rport delete is called under the following conditions:
  2004. * - vport is deleted
  2005. * - vf is deleted
  2006. * - explicit request from OS to delete rport (vmware)
  2007. */
  2008. void
  2009. bfa_fcs_rport_delete(struct bfa_fcs_rport_s *rport)
  2010. {
  2011. bfa_sm_send_event(rport, RPSM_EVENT_DELETE);
  2012. }
  2013. /**
  2014. * Called by bport/vport to when a target goes offline.
  2015. *
  2016. */
  2017. void
  2018. bfa_fcs_rport_offline(struct bfa_fcs_rport_s *rport)
  2019. {
  2020. bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
  2021. }
  2022. /**
  2023. * Called by bport in n2n when a target (attached port) becomes online.
  2024. *
  2025. */
  2026. void
  2027. bfa_fcs_rport_online(struct bfa_fcs_rport_s *rport)
  2028. {
  2029. bfa_sm_send_event(rport, RPSM_EVENT_PLOGI_SEND);
  2030. }
  2031. /**
  2032. * Called by bport/vport to notify SCN for the remote port
  2033. */
  2034. void
  2035. bfa_fcs_rport_scn(struct bfa_fcs_rport_s *rport)
  2036. {
  2037. rport->stats.rscns++;
  2038. bfa_sm_send_event(rport, RPSM_EVENT_SCN);
  2039. }
  2040. /**
  2041. * Called by fcpim to notify that the ITN cleanup is done.
  2042. */
  2043. void
  2044. bfa_fcs_rport_itnim_ack(struct bfa_fcs_rport_s *rport)
  2045. {
  2046. bfa_sm_send_event(rport, RPSM_EVENT_FC4_OFFLINE);
  2047. }
  2048. /**
  2049. * Called by fcptm to notify that the ITN cleanup is done.
  2050. */
  2051. void
  2052. bfa_fcs_rport_tin_ack(struct bfa_fcs_rport_s *rport)
  2053. {
  2054. bfa_sm_send_event(rport, RPSM_EVENT_FC4_OFFLINE);
  2055. }
  2056. /**
  2057. * This routine BFA callback for bfa_rport_online() call.
  2058. *
  2059. * param[in] cb_arg - rport struct.
  2060. *
  2061. * return
  2062. * void
  2063. *
  2064. * Special Considerations:
  2065. *
  2066. * note
  2067. */
  2068. void
  2069. bfa_cb_rport_online(void *cbarg)
  2070. {
  2071. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)cbarg;
  2072. bfa_trc(rport->fcs, rport->pwwn);
  2073. bfa_sm_send_event(rport, RPSM_EVENT_HCB_ONLINE);
  2074. }
  2075. /**
  2076. * This routine BFA callback for bfa_rport_offline() call.
  2077. *
  2078. * param[in] rport -
  2079. *
  2080. * return
  2081. * void
  2082. *
  2083. * Special Considerations:
  2084. *
  2085. * note
  2086. */
  2087. void
  2088. bfa_cb_rport_offline(void *cbarg)
  2089. {
  2090. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)cbarg;
  2091. bfa_trc(rport->fcs, rport->pwwn);
  2092. bfa_sm_send_event(rport, RPSM_EVENT_HCB_OFFLINE);
  2093. }
  2094. /**
  2095. * This routine is a static BFA callback when there is a QoS flow_id
  2096. * change notification
  2097. *
  2098. * @param[in] rport -
  2099. *
  2100. * @return void
  2101. *
  2102. * Special Considerations:
  2103. *
  2104. * @note
  2105. */
  2106. void
  2107. bfa_cb_rport_qos_scn_flowid(void *cbarg,
  2108. struct bfa_rport_qos_attr_s old_qos_attr,
  2109. struct bfa_rport_qos_attr_s new_qos_attr)
  2110. {
  2111. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)cbarg;
  2112. struct bfa_rport_aen_data_s aen_data;
  2113. bfa_trc(rport->fcs, rport->pwwn);
  2114. aen_data.priv.qos = new_qos_attr;
  2115. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_FLOWID, &aen_data);
  2116. }
  2117. /**
  2118. * This routine is a static BFA callback when there is a QoS priority
  2119. * change notification
  2120. *
  2121. * @param[in] rport -
  2122. *
  2123. * @return void
  2124. *
  2125. * Special Considerations:
  2126. *
  2127. * @note
  2128. */
  2129. void
  2130. bfa_cb_rport_qos_scn_prio(void *cbarg, struct bfa_rport_qos_attr_s old_qos_attr,
  2131. struct bfa_rport_qos_attr_s new_qos_attr)
  2132. {
  2133. struct bfa_fcs_rport_s *rport = (struct bfa_fcs_rport_s *)cbarg;
  2134. struct bfa_rport_aen_data_s aen_data;
  2135. bfa_trc(rport->fcs, rport->pwwn);
  2136. aen_data.priv.qos = new_qos_attr;
  2137. bfa_fcs_rport_aen_post(rport, BFA_RPORT_AEN_QOS_PRIO, &aen_data);
  2138. }
  2139. /**
  2140. * Called to process any unsolicted frames from this remote port
  2141. */
  2142. void
  2143. bfa_fcs_rport_logo_imp(struct bfa_fcs_rport_s *rport)
  2144. {
  2145. bfa_sm_send_event(rport, RPSM_EVENT_LOGO_IMP);
  2146. }
  2147. /**
  2148. * Called to process any unsolicted frames from this remote port
  2149. */
  2150. void
  2151. bfa_fcs_rport_uf_recv(struct bfa_fcs_rport_s *rport, struct fchs_s *fchs,
  2152. u16 len)
  2153. {
  2154. struct bfa_fcs_port_s *port = rport->port;
  2155. struct fc_els_cmd_s *els_cmd;
  2156. bfa_trc(rport->fcs, fchs->s_id);
  2157. bfa_trc(rport->fcs, fchs->d_id);
  2158. bfa_trc(rport->fcs, fchs->type);
  2159. if (fchs->type != FC_TYPE_ELS)
  2160. return;
  2161. els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  2162. bfa_trc(rport->fcs, els_cmd->els_code);
  2163. switch (els_cmd->els_code) {
  2164. case FC_ELS_LOGO:
  2165. bfa_fcs_rport_process_logo(rport, fchs);
  2166. break;
  2167. case FC_ELS_ADISC:
  2168. bfa_fcs_rport_process_adisc(rport, fchs, len);
  2169. break;
  2170. case FC_ELS_PRLO:
  2171. if (bfa_fcs_port_is_initiator(port))
  2172. bfa_fcs_fcpim_uf_recv(rport->itnim, fchs, len);
  2173. if (bfa_fcs_port_is_target(port))
  2174. bfa_fcs_fcptm_uf_recv(rport->tin, fchs, len);
  2175. break;
  2176. case FC_ELS_PRLI:
  2177. bfa_fcs_rport_process_prli(rport, fchs, len);
  2178. break;
  2179. case FC_ELS_RPSC:
  2180. bfa_fcs_rport_process_rpsc(rport, fchs, len);
  2181. break;
  2182. default:
  2183. bfa_fcs_rport_send_ls_rjt(rport, fchs,
  2184. FC_LS_RJT_RSN_CMD_NOT_SUPP,
  2185. FC_LS_RJT_EXP_NO_ADDL_INFO);
  2186. break;
  2187. }
  2188. }
  2189. /*
  2190. * Send a LS reject
  2191. */
  2192. static void
  2193. bfa_fcs_rport_send_ls_rjt(struct bfa_fcs_rport_s *rport, struct fchs_s *rx_fchs,
  2194. u8 reason_code, u8 reason_code_expl)
  2195. {
  2196. struct bfa_fcs_port_s *port = rport->port;
  2197. struct fchs_s fchs;
  2198. struct bfa_fcxp_s *fcxp;
  2199. int len;
  2200. bfa_trc(rport->fcs, rx_fchs->s_id);
  2201. fcxp = bfa_fcs_fcxp_alloc(rport->fcs);
  2202. if (!fcxp)
  2203. return;
  2204. len = fc_ls_rjt_build(&fchs, bfa_fcxp_get_reqbuf(fcxp), rx_fchs->s_id,
  2205. bfa_fcs_port_get_fcid(port), rx_fchs->ox_id,
  2206. reason_code, reason_code_expl);
  2207. bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
  2208. FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
  2209. }
  2210. /**
  2211. * Return state of rport.
  2212. */
  2213. int
  2214. bfa_fcs_rport_get_state(struct bfa_fcs_rport_s *rport)
  2215. {
  2216. return bfa_sm_to_state(rport_sm_table, rport->sm);
  2217. }
  2218. /**
  2219. * Called by the Driver to set rport delete/ageout timeout
  2220. *
  2221. * param[in] rport timeout value in seconds.
  2222. *
  2223. * return None
  2224. */
  2225. void
  2226. bfa_fcs_rport_set_del_timeout(u8 rport_tmo)
  2227. {
  2228. /*
  2229. * convert to Millisecs
  2230. */
  2231. if (rport_tmo > 0)
  2232. bfa_fcs_rport_del_timeout = rport_tmo * 1000;
  2233. }