bfa_fcs_rport.c 76 KB

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