zfcp_erp.c 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756
  1. /*
  2. *
  3. * linux/drivers/s390/scsi/zfcp_erp.c
  4. *
  5. * FCP adapter driver for IBM eServer zSeries
  6. *
  7. * (C) Copyright IBM Corp. 2002, 2004
  8. *
  9. * Author(s): Martin Peschke <mpeschke@de.ibm.com>
  10. * Raimund Schroeder <raimund.schroeder@de.ibm.com>
  11. * Aron Zeh
  12. * Wolfgang Taphorn
  13. * Stefan Bader <stefan.bader@de.ibm.com>
  14. * Heiko Carstens <heiko.carstens@de.ibm.com>
  15. * Andreas Herrmann <aherrman@de.ibm.com>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2, or (at your option)
  20. * any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. */
  31. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
  32. #define ZFCP_ERP_REVISION "$Revision: 1.86 $"
  33. #include "zfcp_ext.h"
  34. static int zfcp_erp_adisc(struct zfcp_port *);
  35. static void zfcp_erp_adisc_handler(unsigned long);
  36. static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
  37. static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
  38. static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
  39. static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
  40. static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
  41. static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
  42. static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
  43. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
  44. static void zfcp_erp_port_block(struct zfcp_port *, int);
  45. static void zfcp_erp_port_unblock(struct zfcp_port *);
  46. static void zfcp_erp_unit_block(struct zfcp_unit *, int);
  47. static void zfcp_erp_unit_unblock(struct zfcp_unit *);
  48. static int zfcp_erp_thread(void *);
  49. static int zfcp_erp_strategy(struct zfcp_erp_action *);
  50. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
  51. static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
  52. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
  53. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
  54. static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
  55. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
  56. static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
  57. struct zfcp_port *,
  58. struct zfcp_unit *, int);
  59. static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
  60. static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
  61. struct zfcp_port *,
  62. struct zfcp_unit *, int);
  63. static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
  64. static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
  65. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
  66. static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
  67. static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
  68. static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
  69. static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
  70. static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
  71. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
  72. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
  73. static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
  74. static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
  75. static int zfcp_erp_adapter_strategy_open_fsf_statusread(
  76. struct zfcp_erp_action *);
  77. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
  78. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
  79. static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
  80. static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
  81. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
  82. static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
  83. static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
  84. static int zfcp_erp_port_strategy_open_nameserver_wakeup(
  85. struct zfcp_erp_action *);
  86. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
  87. static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
  88. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
  89. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
  90. static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
  91. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
  92. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
  93. static int zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
  94. static int zfcp_erp_action_dismiss_port(struct zfcp_port *);
  95. static int zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
  96. static int zfcp_erp_action_dismiss(struct zfcp_erp_action *);
  97. static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
  98. struct zfcp_port *, struct zfcp_unit *);
  99. static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
  100. static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
  101. struct zfcp_port *, struct zfcp_unit *,
  102. int);
  103. static void zfcp_erp_action_ready(struct zfcp_erp_action *);
  104. static int zfcp_erp_action_exists(struct zfcp_erp_action *);
  105. static inline void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
  106. static inline void zfcp_erp_action_to_running(struct zfcp_erp_action *);
  107. static void zfcp_erp_memwait_handler(unsigned long);
  108. static void zfcp_erp_timeout_handler(unsigned long);
  109. static inline void zfcp_erp_timeout_init(struct zfcp_erp_action *);
  110. /**
  111. * zfcp_fsf_request_timeout_handler - called if a request timed out
  112. * @data: pointer to adapter for handler function
  113. *
  114. * This function needs to be called if requests (ELS, Generic Service,
  115. * or SCSI commands) exceed a certain time limit. The assumption is
  116. * that after the time limit the adapter get stuck. So we trigger a reopen of
  117. * the adapter. This should not be used for error recovery, SCSI abort
  118. * commands and SCSI requests from SCSI mid-layer.
  119. */
  120. void
  121. zfcp_fsf_request_timeout_handler(unsigned long data)
  122. {
  123. struct zfcp_adapter *adapter;
  124. adapter = (struct zfcp_adapter *) data;
  125. zfcp_erp_adapter_reopen(adapter, 0);
  126. }
  127. /*
  128. * function: zfcp_fsf_scsi_er_timeout_handler
  129. *
  130. * purpose: This function needs to be called whenever a SCSI error recovery
  131. * action (abort/reset) does not return.
  132. * Re-opening the adapter means that the command can be returned
  133. * by zfcp (it is guarranteed that it does not return via the
  134. * adapter anymore). The buffer can then be used again.
  135. *
  136. * returns: sod all
  137. */
  138. void
  139. zfcp_fsf_scsi_er_timeout_handler(unsigned long data)
  140. {
  141. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  142. ZFCP_LOG_NORMAL("warning: SCSI error recovery timed out. "
  143. "Restarting all operations on the adapter %s\n",
  144. zfcp_get_busid_by_adapter(adapter));
  145. debug_text_event(adapter->erp_dbf, 1, "eh_lmem_tout");
  146. zfcp_erp_adapter_reopen(adapter, 0);
  147. return;
  148. }
  149. /*
  150. * function:
  151. *
  152. * purpose: called if an adapter failed,
  153. * initiates adapter recovery which is done
  154. * asynchronously
  155. *
  156. * returns: 0 - initiated action succesfully
  157. * <0 - failed to initiate action
  158. */
  159. int
  160. zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *adapter, int clear_mask)
  161. {
  162. int retval;
  163. debug_text_event(adapter->erp_dbf, 5, "a_ro");
  164. ZFCP_LOG_DEBUG("reopen adapter %s\n",
  165. zfcp_get_busid_by_adapter(adapter));
  166. zfcp_erp_adapter_block(adapter, clear_mask);
  167. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
  168. ZFCP_LOG_DEBUG("skipped reopen of failed adapter %s\n",
  169. zfcp_get_busid_by_adapter(adapter));
  170. debug_text_event(adapter->erp_dbf, 5, "a_ro_f");
  171. /* ensure propagation of failed status to new devices */
  172. zfcp_erp_adapter_failed(adapter);
  173. retval = -EIO;
  174. goto out;
  175. }
  176. retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_ADAPTER,
  177. adapter, NULL, NULL);
  178. out:
  179. return retval;
  180. }
  181. /*
  182. * function:
  183. *
  184. * purpose: Wrappper for zfcp_erp_adapter_reopen_internal
  185. * used to ensure the correct locking
  186. *
  187. * returns: 0 - initiated action succesfully
  188. * <0 - failed to initiate action
  189. */
  190. int
  191. zfcp_erp_adapter_reopen(struct zfcp_adapter *adapter, int clear_mask)
  192. {
  193. int retval;
  194. unsigned long flags;
  195. read_lock_irqsave(&zfcp_data.config_lock, flags);
  196. write_lock(&adapter->erp_lock);
  197. retval = zfcp_erp_adapter_reopen_internal(adapter, clear_mask);
  198. write_unlock(&adapter->erp_lock);
  199. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  200. return retval;
  201. }
  202. /*
  203. * function:
  204. *
  205. * purpose:
  206. *
  207. * returns:
  208. */
  209. int
  210. zfcp_erp_adapter_shutdown(struct zfcp_adapter *adapter, int clear_mask)
  211. {
  212. int retval;
  213. retval = zfcp_erp_adapter_reopen(adapter,
  214. ZFCP_STATUS_COMMON_RUNNING |
  215. ZFCP_STATUS_COMMON_ERP_FAILED |
  216. clear_mask);
  217. return retval;
  218. }
  219. /*
  220. * function:
  221. *
  222. * purpose:
  223. *
  224. * returns:
  225. */
  226. int
  227. zfcp_erp_port_shutdown(struct zfcp_port *port, int clear_mask)
  228. {
  229. int retval;
  230. retval = zfcp_erp_port_reopen(port,
  231. ZFCP_STATUS_COMMON_RUNNING |
  232. ZFCP_STATUS_COMMON_ERP_FAILED |
  233. clear_mask);
  234. return retval;
  235. }
  236. /*
  237. * function:
  238. *
  239. * purpose:
  240. *
  241. * returns:
  242. */
  243. int
  244. zfcp_erp_unit_shutdown(struct zfcp_unit *unit, int clear_mask)
  245. {
  246. int retval;
  247. retval = zfcp_erp_unit_reopen(unit,
  248. ZFCP_STATUS_COMMON_RUNNING |
  249. ZFCP_STATUS_COMMON_ERP_FAILED |
  250. clear_mask);
  251. return retval;
  252. }
  253. /**
  254. * zfcp_erp_adisc - send ADISC ELS command
  255. * @port: port structure
  256. */
  257. int
  258. zfcp_erp_adisc(struct zfcp_port *port)
  259. {
  260. struct zfcp_adapter *adapter = port->adapter;
  261. struct zfcp_send_els *send_els;
  262. struct zfcp_ls_adisc *adisc;
  263. void *address = NULL;
  264. int retval = 0;
  265. struct timer_list *timer;
  266. send_els = kmalloc(sizeof(struct zfcp_send_els), GFP_ATOMIC);
  267. if (send_els == NULL)
  268. goto nomem;
  269. memset(send_els, 0, sizeof(*send_els));
  270. send_els->req = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
  271. if (send_els->req == NULL)
  272. goto nomem;
  273. memset(send_els->req, 0, sizeof(*send_els->req));
  274. send_els->resp = kmalloc(sizeof(struct scatterlist), GFP_ATOMIC);
  275. if (send_els->resp == NULL)
  276. goto nomem;
  277. memset(send_els->resp, 0, sizeof(*send_els->resp));
  278. address = (void *) get_zeroed_page(GFP_ATOMIC);
  279. if (address == NULL)
  280. goto nomem;
  281. zfcp_address_to_sg(address, send_els->req);
  282. address += PAGE_SIZE >> 1;
  283. zfcp_address_to_sg(address, send_els->resp);
  284. send_els->req_count = send_els->resp_count = 1;
  285. send_els->adapter = adapter;
  286. send_els->port = port;
  287. send_els->d_id = port->d_id;
  288. send_els->handler = zfcp_erp_adisc_handler;
  289. send_els->handler_data = (unsigned long) send_els;
  290. adisc = zfcp_sg_to_address(send_els->req);
  291. send_els->ls_code = adisc->code = ZFCP_LS_ADISC;
  292. send_els->req->length = sizeof(struct zfcp_ls_adisc);
  293. send_els->resp->length = sizeof(struct zfcp_ls_adisc_acc);
  294. /* acc. to FC-FS, hard_nport_id in ADISC should not be set for ports
  295. without FC-AL-2 capability, so we don't set it */
  296. adisc->wwpn = fc_host_port_name(adapter->scsi_host);
  297. adisc->wwnn = fc_host_node_name(adapter->scsi_host);
  298. adisc->nport_id = fc_host_port_id(adapter->scsi_host);
  299. ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x "
  300. "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
  301. "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
  302. adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
  303. (wwn_t) adisc->wwnn, adisc->hard_nport_id,
  304. adisc->nport_id);
  305. timer = kmalloc(sizeof(struct timer_list), GFP_ATOMIC);
  306. if (!timer)
  307. goto nomem;
  308. init_timer(timer);
  309. timer->function = zfcp_fsf_request_timeout_handler;
  310. timer->data = (unsigned long) adapter;
  311. timer->expires = ZFCP_FSF_REQUEST_TIMEOUT;
  312. send_els->timer = timer;
  313. retval = zfcp_fsf_send_els(send_els);
  314. if (retval != 0) {
  315. ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
  316. "0x%08x on adapter %s\n", send_els->d_id,
  317. zfcp_get_busid_by_adapter(adapter));
  318. del_timer(send_els->timer);
  319. goto freemem;
  320. }
  321. goto out;
  322. nomem:
  323. retval = -ENOMEM;
  324. freemem:
  325. if (address != NULL)
  326. __free_pages(send_els->req->page, 0);
  327. if (send_els != NULL) {
  328. kfree(send_els->timer);
  329. kfree(send_els->req);
  330. kfree(send_els->resp);
  331. kfree(send_els);
  332. }
  333. out:
  334. return retval;
  335. }
  336. /**
  337. * zfcp_erp_adisc_handler - handler for ADISC ELS command
  338. * @data: pointer to struct zfcp_send_els
  339. *
  340. * If ADISC failed (LS_RJT or timed out) forced reopen of the port is triggered.
  341. */
  342. void
  343. zfcp_erp_adisc_handler(unsigned long data)
  344. {
  345. struct zfcp_send_els *send_els;
  346. struct zfcp_port *port;
  347. struct zfcp_adapter *adapter;
  348. u32 d_id;
  349. struct zfcp_ls_adisc_acc *adisc;
  350. send_els = (struct zfcp_send_els *) data;
  351. del_timer(send_els->timer);
  352. adapter = send_els->adapter;
  353. port = send_els->port;
  354. d_id = send_els->d_id;
  355. /* request rejected or timed out */
  356. if (send_els->status != 0) {
  357. ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
  358. "force physical port reopen "
  359. "(adapter %s, port d_id=0x%08x)\n",
  360. zfcp_get_busid_by_adapter(adapter), d_id);
  361. debug_text_event(adapter->erp_dbf, 3, "forcreop");
  362. if (zfcp_erp_port_forced_reopen(port, 0))
  363. ZFCP_LOG_NORMAL("failed reopen of port "
  364. "(adapter %s, wwpn=0x%016Lx)\n",
  365. zfcp_get_busid_by_port(port),
  366. port->wwpn);
  367. goto out;
  368. }
  369. adisc = zfcp_sg_to_address(send_els->resp);
  370. ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id "
  371. "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
  372. "hard_nport_id=0x%08x, nport_id=0x%08x)\n",
  373. d_id, fc_host_port_id(adapter->scsi_host),
  374. (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
  375. adisc->hard_nport_id, adisc->nport_id);
  376. /* set wwnn for port */
  377. if (port->wwnn == 0)
  378. port->wwnn = adisc->wwnn;
  379. if (port->wwpn != adisc->wwpn) {
  380. ZFCP_LOG_NORMAL("d_id assignment changed, reopening "
  381. "port (adapter %s, wwpn=0x%016Lx, "
  382. "adisc_resp_wwpn=0x%016Lx)\n",
  383. zfcp_get_busid_by_port(port),
  384. port->wwpn, (wwn_t) adisc->wwpn);
  385. if (zfcp_erp_port_reopen(port, 0))
  386. ZFCP_LOG_NORMAL("failed reopen of port "
  387. "(adapter %s, wwpn=0x%016Lx)\n",
  388. zfcp_get_busid_by_port(port),
  389. port->wwpn);
  390. }
  391. out:
  392. zfcp_port_put(port);
  393. __free_pages(send_els->req->page, 0);
  394. kfree(send_els->timer);
  395. kfree(send_els->req);
  396. kfree(send_els->resp);
  397. kfree(send_els);
  398. }
  399. /**
  400. * zfcp_test_link - lightweight link test procedure
  401. * @port: port to be tested
  402. *
  403. * Test status of a link to a remote port using the ELS command ADISC.
  404. */
  405. int
  406. zfcp_test_link(struct zfcp_port *port)
  407. {
  408. int retval;
  409. zfcp_port_get(port);
  410. retval = zfcp_erp_adisc(port);
  411. if (retval != 0) {
  412. zfcp_port_put(port);
  413. ZFCP_LOG_NORMAL("reopen needed for port 0x%016Lx "
  414. "on adapter %s\n ", port->wwpn,
  415. zfcp_get_busid_by_port(port));
  416. retval = zfcp_erp_port_forced_reopen(port, 0);
  417. if (retval != 0) {
  418. ZFCP_LOG_NORMAL("reopen of remote port 0x%016Lx "
  419. "on adapter %s failed\n", port->wwpn,
  420. zfcp_get_busid_by_port(port));
  421. retval = -EPERM;
  422. }
  423. }
  424. return retval;
  425. }
  426. /*
  427. * function:
  428. *
  429. * purpose: called if a port failed to be opened normally
  430. * initiates Forced Reopen recovery which is done
  431. * asynchronously
  432. *
  433. * returns: 0 - initiated action succesfully
  434. * <0 - failed to initiate action
  435. */
  436. static int
  437. zfcp_erp_port_forced_reopen_internal(struct zfcp_port *port, int clear_mask)
  438. {
  439. int retval;
  440. struct zfcp_adapter *adapter = port->adapter;
  441. debug_text_event(adapter->erp_dbf, 5, "pf_ro");
  442. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  443. ZFCP_LOG_DEBUG("forced reopen of port 0x%016Lx on adapter %s\n",
  444. port->wwpn, zfcp_get_busid_by_port(port));
  445. zfcp_erp_port_block(port, clear_mask);
  446. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  447. ZFCP_LOG_DEBUG("skipped forced reopen of failed port 0x%016Lx "
  448. "on adapter %s\n", port->wwpn,
  449. zfcp_get_busid_by_port(port));
  450. debug_text_event(adapter->erp_dbf, 5, "pf_ro_f");
  451. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  452. retval = -EIO;
  453. goto out;
  454. }
  455. retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT_FORCED,
  456. port->adapter, port, NULL);
  457. out:
  458. return retval;
  459. }
  460. /*
  461. * function:
  462. *
  463. * purpose: Wrappper for zfcp_erp_port_forced_reopen_internal
  464. * used to ensure the correct locking
  465. *
  466. * returns: 0 - initiated action succesfully
  467. * <0 - failed to initiate action
  468. */
  469. int
  470. zfcp_erp_port_forced_reopen(struct zfcp_port *port, int clear_mask)
  471. {
  472. int retval;
  473. unsigned long flags;
  474. struct zfcp_adapter *adapter;
  475. adapter = port->adapter;
  476. read_lock_irqsave(&zfcp_data.config_lock, flags);
  477. write_lock(&adapter->erp_lock);
  478. retval = zfcp_erp_port_forced_reopen_internal(port, clear_mask);
  479. write_unlock(&adapter->erp_lock);
  480. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  481. return retval;
  482. }
  483. /*
  484. * function:
  485. *
  486. * purpose: called if a port is to be opened
  487. * initiates Reopen recovery which is done
  488. * asynchronously
  489. *
  490. * returns: 0 - initiated action succesfully
  491. * <0 - failed to initiate action
  492. */
  493. static int
  494. zfcp_erp_port_reopen_internal(struct zfcp_port *port, int clear_mask)
  495. {
  496. int retval;
  497. struct zfcp_adapter *adapter = port->adapter;
  498. debug_text_event(adapter->erp_dbf, 5, "p_ro");
  499. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  500. ZFCP_LOG_DEBUG("reopen of port 0x%016Lx on adapter %s\n",
  501. port->wwpn, zfcp_get_busid_by_port(port));
  502. zfcp_erp_port_block(port, clear_mask);
  503. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  504. ZFCP_LOG_DEBUG("skipped reopen of failed port 0x%016Lx "
  505. "on adapter %s\n", port->wwpn,
  506. zfcp_get_busid_by_port(port));
  507. debug_text_event(adapter->erp_dbf, 5, "p_ro_f");
  508. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  509. /* ensure propagation of failed status to new devices */
  510. zfcp_erp_port_failed(port);
  511. retval = -EIO;
  512. goto out;
  513. }
  514. retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_PORT,
  515. port->adapter, port, NULL);
  516. out:
  517. return retval;
  518. }
  519. /**
  520. * zfcp_erp_port_reopen - initiate reopen of a remote port
  521. * @port: port to be reopened
  522. * @clear_mask: specifies flags in port status to be cleared
  523. * Return: 0 on success, < 0 on error
  524. *
  525. * This is a wrappper function for zfcp_erp_port_reopen_internal. It ensures
  526. * correct locking. An error recovery task is initiated to do the reopen.
  527. * To wait for the completion of the reopen zfcp_erp_wait should be used.
  528. */
  529. int
  530. zfcp_erp_port_reopen(struct zfcp_port *port, int clear_mask)
  531. {
  532. int retval;
  533. unsigned long flags;
  534. struct zfcp_adapter *adapter = port->adapter;
  535. read_lock_irqsave(&zfcp_data.config_lock, flags);
  536. write_lock(&adapter->erp_lock);
  537. retval = zfcp_erp_port_reopen_internal(port, clear_mask);
  538. write_unlock(&adapter->erp_lock);
  539. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  540. return retval;
  541. }
  542. /*
  543. * function:
  544. *
  545. * purpose: called if a unit is to be opened
  546. * initiates Reopen recovery which is done
  547. * asynchronously
  548. *
  549. * returns: 0 - initiated action succesfully
  550. * <0 - failed to initiate action
  551. */
  552. static int
  553. zfcp_erp_unit_reopen_internal(struct zfcp_unit *unit, int clear_mask)
  554. {
  555. int retval;
  556. struct zfcp_adapter *adapter = unit->port->adapter;
  557. debug_text_event(adapter->erp_dbf, 5, "u_ro");
  558. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
  559. ZFCP_LOG_DEBUG("reopen of unit 0x%016Lx on port 0x%016Lx "
  560. "on adapter %s\n", unit->fcp_lun,
  561. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  562. zfcp_erp_unit_block(unit, clear_mask);
  563. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
  564. ZFCP_LOG_DEBUG("skipped reopen of failed unit 0x%016Lx "
  565. "on port 0x%016Lx on adapter %s\n",
  566. unit->fcp_lun, unit->port->wwpn,
  567. zfcp_get_busid_by_unit(unit));
  568. debug_text_event(adapter->erp_dbf, 5, "u_ro_f");
  569. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  570. sizeof (fcp_lun_t));
  571. retval = -EIO;
  572. goto out;
  573. }
  574. retval = zfcp_erp_action_enqueue(ZFCP_ERP_ACTION_REOPEN_UNIT,
  575. unit->port->adapter, unit->port, unit);
  576. out:
  577. return retval;
  578. }
  579. /**
  580. * zfcp_erp_unit_reopen - initiate reopen of a unit
  581. * @unit: unit to be reopened
  582. * @clear_mask: specifies flags in unit status to be cleared
  583. * Return: 0 on success, < 0 on error
  584. *
  585. * This is a wrappper for zfcp_erp_unit_reopen_internal. It ensures correct
  586. * locking. An error recovery task is initiated to do the reopen.
  587. * To wait for the completion of the reopen zfcp_erp_wait should be used.
  588. */
  589. int
  590. zfcp_erp_unit_reopen(struct zfcp_unit *unit, int clear_mask)
  591. {
  592. int retval;
  593. unsigned long flags;
  594. struct zfcp_adapter *adapter;
  595. struct zfcp_port *port;
  596. port = unit->port;
  597. adapter = port->adapter;
  598. read_lock_irqsave(&zfcp_data.config_lock, flags);
  599. write_lock(&adapter->erp_lock);
  600. retval = zfcp_erp_unit_reopen_internal(unit, clear_mask);
  601. write_unlock(&adapter->erp_lock);
  602. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  603. return retval;
  604. }
  605. /*
  606. * function:
  607. *
  608. * purpose: disable I/O,
  609. * return any open requests and clean them up,
  610. * aim: no pending and incoming I/O
  611. *
  612. * returns:
  613. */
  614. static void
  615. zfcp_erp_adapter_block(struct zfcp_adapter *adapter, int clear_mask)
  616. {
  617. debug_text_event(adapter->erp_dbf, 6, "a_bl");
  618. zfcp_erp_modify_adapter_status(adapter,
  619. ZFCP_STATUS_COMMON_UNBLOCKED |
  620. clear_mask, ZFCP_CLEAR);
  621. }
  622. /*
  623. * function:
  624. *
  625. * purpose: enable I/O
  626. *
  627. * returns:
  628. */
  629. static void
  630. zfcp_erp_adapter_unblock(struct zfcp_adapter *adapter)
  631. {
  632. debug_text_event(adapter->erp_dbf, 6, "a_ubl");
  633. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status);
  634. }
  635. /*
  636. * function:
  637. *
  638. * purpose: disable I/O,
  639. * return any open requests and clean them up,
  640. * aim: no pending and incoming I/O
  641. *
  642. * returns:
  643. */
  644. static void
  645. zfcp_erp_port_block(struct zfcp_port *port, int clear_mask)
  646. {
  647. struct zfcp_adapter *adapter = port->adapter;
  648. debug_text_event(adapter->erp_dbf, 6, "p_bl");
  649. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  650. zfcp_erp_modify_port_status(port,
  651. ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
  652. ZFCP_CLEAR);
  653. }
  654. /*
  655. * function:
  656. *
  657. * purpose: enable I/O
  658. *
  659. * returns:
  660. */
  661. static void
  662. zfcp_erp_port_unblock(struct zfcp_port *port)
  663. {
  664. struct zfcp_adapter *adapter = port->adapter;
  665. debug_text_event(adapter->erp_dbf, 6, "p_ubl");
  666. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  667. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &port->status);
  668. }
  669. /*
  670. * function:
  671. *
  672. * purpose: disable I/O,
  673. * return any open requests and clean them up,
  674. * aim: no pending and incoming I/O
  675. *
  676. * returns:
  677. */
  678. static void
  679. zfcp_erp_unit_block(struct zfcp_unit *unit, int clear_mask)
  680. {
  681. struct zfcp_adapter *adapter = unit->port->adapter;
  682. debug_text_event(adapter->erp_dbf, 6, "u_bl");
  683. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  684. zfcp_erp_modify_unit_status(unit,
  685. ZFCP_STATUS_COMMON_UNBLOCKED | clear_mask,
  686. ZFCP_CLEAR);
  687. }
  688. /*
  689. * function:
  690. *
  691. * purpose: enable I/O
  692. *
  693. * returns:
  694. */
  695. static void
  696. zfcp_erp_unit_unblock(struct zfcp_unit *unit)
  697. {
  698. struct zfcp_adapter *adapter = unit->port->adapter;
  699. debug_text_event(adapter->erp_dbf, 6, "u_ubl");
  700. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  701. atomic_set_mask(ZFCP_STATUS_COMMON_UNBLOCKED, &unit->status);
  702. }
  703. /*
  704. * function:
  705. *
  706. * purpose:
  707. *
  708. * returns:
  709. */
  710. static void
  711. zfcp_erp_action_ready(struct zfcp_erp_action *erp_action)
  712. {
  713. struct zfcp_adapter *adapter = erp_action->adapter;
  714. debug_text_event(adapter->erp_dbf, 4, "a_ar");
  715. debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
  716. zfcp_erp_action_to_ready(erp_action);
  717. up(&adapter->erp_ready_sem);
  718. }
  719. /*
  720. * function:
  721. *
  722. * purpose:
  723. *
  724. * returns: <0 erp_action not found in any list
  725. * ZFCP_ERP_ACTION_READY erp_action is in ready list
  726. * ZFCP_ERP_ACTION_RUNNING erp_action is in running list
  727. *
  728. * locks: erp_lock must be held
  729. */
  730. static int
  731. zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
  732. {
  733. int retval = -EINVAL;
  734. struct list_head *entry;
  735. struct zfcp_erp_action *entry_erp_action;
  736. struct zfcp_adapter *adapter = erp_action->adapter;
  737. /* search in running list */
  738. list_for_each(entry, &adapter->erp_running_head) {
  739. entry_erp_action =
  740. list_entry(entry, struct zfcp_erp_action, list);
  741. if (entry_erp_action == erp_action) {
  742. retval = ZFCP_ERP_ACTION_RUNNING;
  743. goto out;
  744. }
  745. }
  746. /* search in ready list */
  747. list_for_each(entry, &adapter->erp_ready_head) {
  748. entry_erp_action =
  749. list_entry(entry, struct zfcp_erp_action, list);
  750. if (entry_erp_action == erp_action) {
  751. retval = ZFCP_ERP_ACTION_READY;
  752. goto out;
  753. }
  754. }
  755. out:
  756. return retval;
  757. }
  758. /*
  759. * purpose: checks current status of action (timed out, dismissed, ...)
  760. * and does appropriate preparations (dismiss fsf request, ...)
  761. *
  762. * locks: called under erp_lock (disabled interrupts)
  763. *
  764. * returns: 0
  765. */
  766. static int
  767. zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
  768. {
  769. int retval = 0;
  770. struct zfcp_fsf_req *fsf_req = NULL;
  771. struct zfcp_adapter *adapter = erp_action->adapter;
  772. if (erp_action->fsf_req) {
  773. /* take lock to ensure that request is not being deleted meanwhile */
  774. spin_lock(&adapter->fsf_req_list_lock);
  775. /* check whether fsf req does still exist */
  776. list_for_each_entry(fsf_req, &adapter->fsf_req_list_head, list)
  777. if (fsf_req == erp_action->fsf_req)
  778. break;
  779. if (fsf_req && (fsf_req->erp_action == erp_action)) {
  780. /* fsf_req still exists */
  781. debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
  782. debug_event(adapter->erp_dbf, 3, &fsf_req,
  783. sizeof (unsigned long));
  784. /* dismiss fsf_req of timed out or dismissed erp_action */
  785. if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
  786. ZFCP_STATUS_ERP_TIMEDOUT)) {
  787. debug_text_event(adapter->erp_dbf, 3,
  788. "a_ca_disreq");
  789. fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  790. }
  791. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
  792. ZFCP_LOG_NORMAL("error: erp step timed out "
  793. "(action=%d, fsf_req=%p)\n ",
  794. erp_action->action,
  795. erp_action->fsf_req);
  796. }
  797. /*
  798. * If fsf_req is neither dismissed nor completed
  799. * then keep it running asynchronously and don't mess
  800. * with the association of erp_action and fsf_req.
  801. */
  802. if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED |
  803. ZFCP_STATUS_FSFREQ_DISMISSED)) {
  804. /* forget about association between fsf_req
  805. and erp_action */
  806. fsf_req->erp_action = NULL;
  807. erp_action->fsf_req = NULL;
  808. }
  809. } else {
  810. debug_text_event(adapter->erp_dbf, 3, "a_ca_gonereq");
  811. /*
  812. * even if this fsf_req has gone, forget about
  813. * association between erp_action and fsf_req
  814. */
  815. erp_action->fsf_req = NULL;
  816. }
  817. spin_unlock(&adapter->fsf_req_list_lock);
  818. } else
  819. debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
  820. return retval;
  821. }
  822. /*
  823. * purpose: generic handler for asynchronous events related to erp_action events
  824. * (normal completion, time-out, dismissing, retry after
  825. * low memory condition)
  826. *
  827. * note: deletion of timer is not required (e.g. in case of a time-out),
  828. * but a second try does no harm,
  829. * we leave it in here to allow for greater simplification
  830. *
  831. * returns: 0 - there was an action to handle
  832. * !0 - otherwise
  833. */
  834. static int
  835. zfcp_erp_async_handler_nolock(struct zfcp_erp_action *erp_action,
  836. unsigned long set_mask)
  837. {
  838. int retval;
  839. struct zfcp_adapter *adapter = erp_action->adapter;
  840. if (zfcp_erp_action_exists(erp_action) == ZFCP_ERP_ACTION_RUNNING) {
  841. debug_text_event(adapter->erp_dbf, 2, "a_asyh_ex");
  842. debug_event(adapter->erp_dbf, 2, &erp_action->action,
  843. sizeof (int));
  844. if (!(set_mask & ZFCP_STATUS_ERP_TIMEDOUT))
  845. del_timer(&erp_action->timer);
  846. erp_action->status |= set_mask;
  847. zfcp_erp_action_ready(erp_action);
  848. retval = 0;
  849. } else {
  850. /* action is ready or gone - nothing to do */
  851. debug_text_event(adapter->erp_dbf, 3, "a_asyh_gone");
  852. debug_event(adapter->erp_dbf, 3, &erp_action->action,
  853. sizeof (int));
  854. retval = 1;
  855. }
  856. return retval;
  857. }
  858. /*
  859. * purpose: generic handler for asynchronous events related to erp_action
  860. * events (normal completion, time-out, dismissing, retry after
  861. * low memory condition)
  862. *
  863. * note: deletion of timer is not required (e.g. in case of a time-out),
  864. * but a second try does no harm,
  865. * we leave it in here to allow for greater simplification
  866. *
  867. * returns: 0 - there was an action to handle
  868. * !0 - otherwise
  869. */
  870. int
  871. zfcp_erp_async_handler(struct zfcp_erp_action *erp_action,
  872. unsigned long set_mask)
  873. {
  874. struct zfcp_adapter *adapter = erp_action->adapter;
  875. unsigned long flags;
  876. int retval;
  877. write_lock_irqsave(&adapter->erp_lock, flags);
  878. retval = zfcp_erp_async_handler_nolock(erp_action, set_mask);
  879. write_unlock_irqrestore(&adapter->erp_lock, flags);
  880. return retval;
  881. }
  882. /*
  883. * purpose: is called for erp_action which was slept waiting for
  884. * memory becoming avaliable,
  885. * will trigger that this action will be continued
  886. */
  887. static void
  888. zfcp_erp_memwait_handler(unsigned long data)
  889. {
  890. struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
  891. struct zfcp_adapter *adapter = erp_action->adapter;
  892. debug_text_event(adapter->erp_dbf, 2, "a_mwh");
  893. debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
  894. zfcp_erp_async_handler(erp_action, 0);
  895. }
  896. /*
  897. * purpose: is called if an asynchronous erp step timed out,
  898. * action gets an appropriate flag and will be processed
  899. * accordingly
  900. */
  901. static void
  902. zfcp_erp_timeout_handler(unsigned long data)
  903. {
  904. struct zfcp_erp_action *erp_action = (struct zfcp_erp_action *) data;
  905. struct zfcp_adapter *adapter = erp_action->adapter;
  906. debug_text_event(adapter->erp_dbf, 2, "a_th");
  907. debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
  908. zfcp_erp_async_handler(erp_action, ZFCP_STATUS_ERP_TIMEDOUT);
  909. }
  910. /*
  911. * purpose: is called for an erp_action which needs to be ended
  912. * though not being done,
  913. * this is usually required if an higher is generated,
  914. * action gets an appropriate flag and will be processed
  915. * accordingly
  916. *
  917. * locks: erp_lock held (thus we need to call another handler variant)
  918. */
  919. static int
  920. zfcp_erp_action_dismiss(struct zfcp_erp_action *erp_action)
  921. {
  922. struct zfcp_adapter *adapter = erp_action->adapter;
  923. debug_text_event(adapter->erp_dbf, 2, "a_adis");
  924. debug_event(adapter->erp_dbf, 2, &erp_action->action, sizeof (int));
  925. zfcp_erp_async_handler_nolock(erp_action, ZFCP_STATUS_ERP_DISMISSED);
  926. return 0;
  927. }
  928. int
  929. zfcp_erp_thread_setup(struct zfcp_adapter *adapter)
  930. {
  931. int retval = 0;
  932. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  933. rwlock_init(&adapter->erp_lock);
  934. INIT_LIST_HEAD(&adapter->erp_ready_head);
  935. INIT_LIST_HEAD(&adapter->erp_running_head);
  936. sema_init(&adapter->erp_ready_sem, 0);
  937. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  938. if (retval < 0) {
  939. ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
  940. "adapter %s\n",
  941. zfcp_get_busid_by_adapter(adapter));
  942. debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
  943. } else {
  944. wait_event(adapter->erp_thread_wqh,
  945. atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
  946. &adapter->status));
  947. debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
  948. }
  949. return (retval < 0);
  950. }
  951. /*
  952. * function:
  953. *
  954. * purpose:
  955. *
  956. * returns:
  957. *
  958. * context: process (i.e. proc-fs or rmmod/insmod)
  959. *
  960. * note: The caller of this routine ensures that the specified
  961. * adapter has been shut down and that this operation
  962. * has been completed. Thus, there are no pending erp_actions
  963. * which would need to be handled here.
  964. */
  965. int
  966. zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  967. {
  968. int retval = 0;
  969. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  970. up(&adapter->erp_ready_sem);
  971. wait_event(adapter->erp_thread_wqh,
  972. !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
  973. &adapter->status));
  974. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  975. &adapter->status);
  976. debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
  977. return retval;
  978. }
  979. /*
  980. * purpose: is run as a kernel thread,
  981. * goes through list of error recovery actions of associated adapter
  982. * and delegates single action to execution
  983. *
  984. * returns: 0
  985. */
  986. static int
  987. zfcp_erp_thread(void *data)
  988. {
  989. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  990. struct list_head *next;
  991. struct zfcp_erp_action *erp_action;
  992. unsigned long flags;
  993. daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
  994. /* Block all signals */
  995. siginitsetinv(&current->blocked, 0);
  996. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  997. debug_text_event(adapter->erp_dbf, 5, "a_th_run");
  998. wake_up(&adapter->erp_thread_wqh);
  999. while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  1000. &adapter->status)) {
  1001. write_lock_irqsave(&adapter->erp_lock, flags);
  1002. next = adapter->erp_ready_head.prev;
  1003. write_unlock_irqrestore(&adapter->erp_lock, flags);
  1004. if (next != &adapter->erp_ready_head) {
  1005. erp_action =
  1006. list_entry(next, struct zfcp_erp_action, list);
  1007. /*
  1008. * process action (incl. [re]moving it
  1009. * from 'ready' queue)
  1010. */
  1011. zfcp_erp_strategy(erp_action);
  1012. }
  1013. /*
  1014. * sleep as long as there is nothing to do, i.e.
  1015. * no action in 'ready' queue to be processed and
  1016. * thread is not to be killed
  1017. */
  1018. down_interruptible(&adapter->erp_ready_sem);
  1019. debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
  1020. }
  1021. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1022. debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
  1023. wake_up(&adapter->erp_thread_wqh);
  1024. return 0;
  1025. }
  1026. /*
  1027. * function:
  1028. *
  1029. * purpose: drives single error recovery action and schedules higher and
  1030. * subordinate actions, if necessary
  1031. *
  1032. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  1033. * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
  1034. * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
  1035. * ZFCP_ERP_EXIT - action finished (dequeued), offline
  1036. * ZFCP_ERP_DISMISSED - action canceled (dequeued)
  1037. */
  1038. static int
  1039. zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1040. {
  1041. int retval = 0;
  1042. struct zfcp_adapter *adapter = erp_action->adapter;
  1043. struct zfcp_port *port = erp_action->port;
  1044. struct zfcp_unit *unit = erp_action->unit;
  1045. int action = erp_action->action;
  1046. u32 status = erp_action->status;
  1047. unsigned long flags;
  1048. /* serialise dismissing, timing out, moving, enqueueing */
  1049. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1050. write_lock(&adapter->erp_lock);
  1051. /* dequeue dismissed action and leave, if required */
  1052. retval = zfcp_erp_strategy_check_action(erp_action, retval);
  1053. if (retval == ZFCP_ERP_DISMISSED) {
  1054. debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
  1055. goto unlock;
  1056. }
  1057. /*
  1058. * move action to 'running' queue before processing it
  1059. * (to avoid a race condition regarding moving the
  1060. * action to the 'running' queue and back)
  1061. */
  1062. zfcp_erp_action_to_running(erp_action);
  1063. /*
  1064. * try to process action as far as possible,
  1065. * no lock to allow for blocking operations (kmalloc, qdio, ...),
  1066. * afterwards the lock is required again for the following reasons:
  1067. * - dequeueing of finished action and enqueueing of
  1068. * follow-up actions must be atomic so that any other
  1069. * reopen-routine does not believe there is nothing to do
  1070. * and that it is safe to enqueue something else,
  1071. * - we want to force any control thread which is dismissing
  1072. * actions to finish this before we decide about
  1073. * necessary steps to be taken here further
  1074. */
  1075. write_unlock(&adapter->erp_lock);
  1076. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1077. retval = zfcp_erp_strategy_do_action(erp_action);
  1078. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1079. write_lock(&adapter->erp_lock);
  1080. /*
  1081. * check for dismissed status again to avoid follow-up actions,
  1082. * failing of targets and so on for dismissed actions
  1083. */
  1084. retval = zfcp_erp_strategy_check_action(erp_action, retval);
  1085. switch (retval) {
  1086. case ZFCP_ERP_DISMISSED:
  1087. /* leave since this action has ridden to its ancestors */
  1088. debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
  1089. goto unlock;
  1090. case ZFCP_ERP_NOMEM:
  1091. /* no memory to continue immediately, let it sleep */
  1092. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1093. ++adapter->erp_low_mem_count;
  1094. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1095. }
  1096. /* This condition is true if there is no memory available
  1097. for any erp_action on this adapter. This implies that there
  1098. are no elements in the memory pool(s) left for erp_actions.
  1099. This might happen if an erp_action that used a memory pool
  1100. element was timed out.
  1101. */
  1102. if (adapter->erp_total_count == adapter->erp_low_mem_count) {
  1103. debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
  1104. ZFCP_LOG_NORMAL("error: no mempool elements available, "
  1105. "restarting I/O on adapter %s "
  1106. "to free mempool\n",
  1107. zfcp_get_busid_by_adapter(adapter));
  1108. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1109. } else {
  1110. debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
  1111. retval = zfcp_erp_strategy_memwait(erp_action);
  1112. }
  1113. goto unlock;
  1114. case ZFCP_ERP_CONTINUES:
  1115. /* leave since this action runs asynchronously */
  1116. debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
  1117. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1118. --adapter->erp_low_mem_count;
  1119. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1120. }
  1121. goto unlock;
  1122. }
  1123. /* ok, finished action (whatever its result is) */
  1124. /* check for unrecoverable targets */
  1125. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1126. /* action must be dequeued (here to allow for further ones) */
  1127. zfcp_erp_action_dequeue(erp_action);
  1128. /*
  1129. * put this target through the erp mill again if someone has
  1130. * requested to change the status of a target being online
  1131. * to offline or the other way around
  1132. * (old retval is preserved if nothing has to be done here)
  1133. */
  1134. retval = zfcp_erp_strategy_statechange(action, status, adapter,
  1135. port, unit, retval);
  1136. /*
  1137. * leave if target is in permanent error state or if
  1138. * action is repeated in order to process state change
  1139. */
  1140. if (retval == ZFCP_ERP_EXIT) {
  1141. debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
  1142. goto unlock;
  1143. }
  1144. /* trigger follow up actions */
  1145. zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
  1146. unlock:
  1147. write_unlock(&adapter->erp_lock);
  1148. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1149. if (retval != ZFCP_ERP_CONTINUES)
  1150. zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
  1151. /*
  1152. * a few tasks remain when the erp queues are empty
  1153. * (don't do that if the last action evaluated was dismissed
  1154. * since this clearly indicates that there is more to come) :
  1155. * - close the name server port if it is open yet
  1156. * (enqueues another [probably] final action)
  1157. * - otherwise, wake up whoever wants to be woken when we are
  1158. * done with erp
  1159. */
  1160. if (retval != ZFCP_ERP_DISMISSED)
  1161. zfcp_erp_strategy_check_queues(adapter);
  1162. debug_text_event(adapter->erp_dbf, 6, "a_st_done");
  1163. return retval;
  1164. }
  1165. /*
  1166. * function:
  1167. *
  1168. * purpose:
  1169. *
  1170. * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
  1171. * retval - otherwise
  1172. */
  1173. static int
  1174. zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
  1175. {
  1176. struct zfcp_adapter *adapter = erp_action->adapter;
  1177. zfcp_erp_strategy_check_fsfreq(erp_action);
  1178. debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
  1179. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1180. debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
  1181. zfcp_erp_action_dequeue(erp_action);
  1182. retval = ZFCP_ERP_DISMISSED;
  1183. } else
  1184. debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
  1185. return retval;
  1186. }
  1187. /*
  1188. * function:
  1189. *
  1190. * purpose:
  1191. *
  1192. * returns:
  1193. */
  1194. static int
  1195. zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1196. {
  1197. int retval = ZFCP_ERP_FAILED;
  1198. struct zfcp_adapter *adapter = erp_action->adapter;
  1199. /*
  1200. * try to execute/continue action as far as possible,
  1201. * note: no lock in subsequent strategy routines
  1202. * (this allows these routine to call schedule, e.g.
  1203. * kmalloc with such flags or qdio_initialize & friends)
  1204. * Note: in case of timeout, the seperate strategies will fail
  1205. * anyhow. No need for a special action. Even worse, a nameserver
  1206. * failure would not wake up waiting ports without the call.
  1207. */
  1208. switch (erp_action->action) {
  1209. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1210. retval = zfcp_erp_adapter_strategy(erp_action);
  1211. break;
  1212. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1213. retval = zfcp_erp_port_forced_strategy(erp_action);
  1214. break;
  1215. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1216. retval = zfcp_erp_port_strategy(erp_action);
  1217. break;
  1218. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1219. retval = zfcp_erp_unit_strategy(erp_action);
  1220. break;
  1221. default:
  1222. debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
  1223. debug_event(adapter->erp_dbf, 1, &erp_action->action,
  1224. sizeof (int));
  1225. ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
  1226. "adapter %s (action=%d)\n",
  1227. zfcp_get_busid_by_adapter(erp_action->adapter),
  1228. erp_action->action);
  1229. }
  1230. return retval;
  1231. }
  1232. /*
  1233. * function:
  1234. *
  1235. * purpose: triggers retry of this action after a certain amount of time
  1236. * by means of timer provided by erp_action
  1237. *
  1238. * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
  1239. */
  1240. static int
  1241. zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  1242. {
  1243. int retval = ZFCP_ERP_CONTINUES;
  1244. struct zfcp_adapter *adapter = erp_action->adapter;
  1245. debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
  1246. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  1247. init_timer(&erp_action->timer);
  1248. erp_action->timer.function = zfcp_erp_memwait_handler;
  1249. erp_action->timer.data = (unsigned long) erp_action;
  1250. erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
  1251. add_timer(&erp_action->timer);
  1252. return retval;
  1253. }
  1254. /*
  1255. * function: zfcp_erp_adapter_failed
  1256. *
  1257. * purpose: sets the adapter and all underlying devices to ERP_FAILED
  1258. *
  1259. */
  1260. void
  1261. zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
  1262. {
  1263. zfcp_erp_modify_adapter_status(adapter,
  1264. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1265. ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
  1266. zfcp_get_busid_by_adapter(adapter));
  1267. debug_text_event(adapter->erp_dbf, 2, "a_afail");
  1268. }
  1269. /*
  1270. * function: zfcp_erp_port_failed
  1271. *
  1272. * purpose: sets the port and all underlying devices to ERP_FAILED
  1273. *
  1274. */
  1275. void
  1276. zfcp_erp_port_failed(struct zfcp_port *port)
  1277. {
  1278. zfcp_erp_modify_port_status(port,
  1279. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1280. if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  1281. ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
  1282. "port d_id=0x%08x)\n",
  1283. zfcp_get_busid_by_port(port), port->d_id);
  1284. else
  1285. ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
  1286. zfcp_get_busid_by_port(port), port->wwpn);
  1287. debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
  1288. debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
  1289. }
  1290. /*
  1291. * function: zfcp_erp_unit_failed
  1292. *
  1293. * purpose: sets the unit to ERP_FAILED
  1294. *
  1295. */
  1296. void
  1297. zfcp_erp_unit_failed(struct zfcp_unit *unit)
  1298. {
  1299. zfcp_erp_modify_unit_status(unit,
  1300. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1301. ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
  1302. " on adapter %s\n", unit->fcp_lun,
  1303. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  1304. debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
  1305. debug_event(unit->port->adapter->erp_dbf, 2,
  1306. &unit->fcp_lun, sizeof (fcp_lun_t));
  1307. }
  1308. /*
  1309. * function: zfcp_erp_strategy_check_target
  1310. *
  1311. * purpose: increments the erp action count on the device currently in
  1312. * recovery if the action failed or resets the count in case of
  1313. * success. If a maximum count is exceeded the device is marked
  1314. * as ERP_FAILED.
  1315. * The 'blocked' state of a target which has been recovered
  1316. * successfully is reset.
  1317. *
  1318. * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
  1319. * ZFCP_ERP_SUCCEEDED - action finished successfully
  1320. * ZFCP_ERP_EXIT - action failed and will not continue
  1321. */
  1322. static int
  1323. zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
  1324. {
  1325. struct zfcp_adapter *adapter = erp_action->adapter;
  1326. struct zfcp_port *port = erp_action->port;
  1327. struct zfcp_unit *unit = erp_action->unit;
  1328. debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
  1329. debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
  1330. debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
  1331. switch (erp_action->action) {
  1332. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1333. result = zfcp_erp_strategy_check_unit(unit, result);
  1334. break;
  1335. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1336. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1337. result = zfcp_erp_strategy_check_port(port, result);
  1338. break;
  1339. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1340. result = zfcp_erp_strategy_check_adapter(adapter, result);
  1341. break;
  1342. }
  1343. return result;
  1344. }
  1345. /*
  1346. * function:
  1347. *
  1348. * purpose:
  1349. *
  1350. * returns:
  1351. */
  1352. static int
  1353. zfcp_erp_strategy_statechange(int action,
  1354. u32 status,
  1355. struct zfcp_adapter *adapter,
  1356. struct zfcp_port *port,
  1357. struct zfcp_unit *unit, int retval)
  1358. {
  1359. debug_text_event(adapter->erp_dbf, 3, "a_stsc");
  1360. debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
  1361. switch (action) {
  1362. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1363. if (zfcp_erp_strategy_statechange_detected(&adapter->status,
  1364. status)) {
  1365. zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  1366. retval = ZFCP_ERP_EXIT;
  1367. }
  1368. break;
  1369. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1370. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1371. if (zfcp_erp_strategy_statechange_detected(&port->status,
  1372. status)) {
  1373. zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
  1374. retval = ZFCP_ERP_EXIT;
  1375. }
  1376. break;
  1377. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1378. if (zfcp_erp_strategy_statechange_detected(&unit->status,
  1379. status)) {
  1380. zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  1381. retval = ZFCP_ERP_EXIT;
  1382. }
  1383. break;
  1384. }
  1385. return retval;
  1386. }
  1387. /*
  1388. * function:
  1389. *
  1390. * purpose:
  1391. *
  1392. * returns:
  1393. */
  1394. static inline int
  1395. zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
  1396. {
  1397. return
  1398. /* take it online */
  1399. (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
  1400. (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
  1401. /* take it offline */
  1402. (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
  1403. !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
  1404. }
  1405. /*
  1406. * function:
  1407. *
  1408. * purpose:
  1409. *
  1410. * returns:
  1411. */
  1412. static int
  1413. zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  1414. {
  1415. debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
  1416. debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
  1417. sizeof (fcp_lun_t));
  1418. switch (result) {
  1419. case ZFCP_ERP_SUCCEEDED :
  1420. atomic_set(&unit->erp_counter, 0);
  1421. zfcp_erp_unit_unblock(unit);
  1422. break;
  1423. case ZFCP_ERP_FAILED :
  1424. atomic_inc(&unit->erp_counter);
  1425. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
  1426. zfcp_erp_unit_failed(unit);
  1427. break;
  1428. case ZFCP_ERP_EXIT :
  1429. /* nothing */
  1430. break;
  1431. }
  1432. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
  1433. zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
  1434. result = ZFCP_ERP_EXIT;
  1435. }
  1436. return result;
  1437. }
  1438. /*
  1439. * function:
  1440. *
  1441. * purpose:
  1442. *
  1443. * returns:
  1444. */
  1445. static int
  1446. zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  1447. {
  1448. debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
  1449. debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  1450. switch (result) {
  1451. case ZFCP_ERP_SUCCEEDED :
  1452. atomic_set(&port->erp_counter, 0);
  1453. zfcp_erp_port_unblock(port);
  1454. break;
  1455. case ZFCP_ERP_FAILED :
  1456. atomic_inc(&port->erp_counter);
  1457. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
  1458. zfcp_erp_port_failed(port);
  1459. break;
  1460. case ZFCP_ERP_EXIT :
  1461. /* nothing */
  1462. break;
  1463. }
  1464. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  1465. zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
  1466. result = ZFCP_ERP_EXIT;
  1467. }
  1468. return result;
  1469. }
  1470. /*
  1471. * function:
  1472. *
  1473. * purpose:
  1474. *
  1475. * returns:
  1476. */
  1477. static int
  1478. zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
  1479. {
  1480. debug_text_event(adapter->erp_dbf, 5, "a_stct");
  1481. switch (result) {
  1482. case ZFCP_ERP_SUCCEEDED :
  1483. atomic_set(&adapter->erp_counter, 0);
  1484. zfcp_erp_adapter_unblock(adapter);
  1485. break;
  1486. case ZFCP_ERP_FAILED :
  1487. atomic_inc(&adapter->erp_counter);
  1488. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
  1489. zfcp_erp_adapter_failed(adapter);
  1490. break;
  1491. case ZFCP_ERP_EXIT :
  1492. /* nothing */
  1493. break;
  1494. }
  1495. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
  1496. zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
  1497. result = ZFCP_ERP_EXIT;
  1498. }
  1499. return result;
  1500. }
  1501. /*
  1502. * function:
  1503. *
  1504. * purpose: remaining things in good cases,
  1505. * escalation in bad cases
  1506. *
  1507. * returns:
  1508. */
  1509. static int
  1510. zfcp_erp_strategy_followup_actions(int action,
  1511. struct zfcp_adapter *adapter,
  1512. struct zfcp_port *port,
  1513. struct zfcp_unit *unit, int status)
  1514. {
  1515. debug_text_event(adapter->erp_dbf, 5, "a_stfol");
  1516. debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
  1517. /* initiate follow-up actions depending on success of finished action */
  1518. switch (action) {
  1519. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1520. if (status == ZFCP_ERP_SUCCEEDED)
  1521. zfcp_erp_port_reopen_all_internal(adapter, 0);
  1522. else
  1523. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1524. break;
  1525. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1526. if (status == ZFCP_ERP_SUCCEEDED)
  1527. zfcp_erp_port_reopen_internal(port, 0);
  1528. else
  1529. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1530. break;
  1531. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1532. if (status == ZFCP_ERP_SUCCEEDED)
  1533. zfcp_erp_unit_reopen_all_internal(port, 0);
  1534. else
  1535. zfcp_erp_port_forced_reopen_internal(port, 0);
  1536. break;
  1537. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1538. if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
  1539. else
  1540. zfcp_erp_port_reopen_internal(unit->port, 0);
  1541. break;
  1542. }
  1543. return 0;
  1544. }
  1545. /*
  1546. * function:
  1547. *
  1548. * purpose:
  1549. *
  1550. * returns:
  1551. */
  1552. static int
  1553. zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
  1554. {
  1555. unsigned long flags;
  1556. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1557. read_lock(&adapter->erp_lock);
  1558. if (list_empty(&adapter->erp_ready_head) &&
  1559. list_empty(&adapter->erp_running_head)) {
  1560. debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
  1561. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  1562. &adapter->status);
  1563. wake_up(&adapter->erp_done_wqh);
  1564. } else
  1565. debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
  1566. read_unlock(&adapter->erp_lock);
  1567. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1568. return 0;
  1569. }
  1570. /**
  1571. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1572. * @adapter: adapter for which to wait for completion of its error recovery
  1573. * Return: 0
  1574. */
  1575. int
  1576. zfcp_erp_wait(struct zfcp_adapter *adapter)
  1577. {
  1578. int retval = 0;
  1579. wait_event(adapter->erp_done_wqh,
  1580. !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  1581. &adapter->status));
  1582. return retval;
  1583. }
  1584. /*
  1585. * function: zfcp_erp_modify_adapter_status
  1586. *
  1587. * purpose:
  1588. *
  1589. */
  1590. void
  1591. zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
  1592. u32 mask, int set_or_clear)
  1593. {
  1594. struct zfcp_port *port;
  1595. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1596. if (set_or_clear == ZFCP_SET) {
  1597. atomic_set_mask(mask, &adapter->status);
  1598. debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
  1599. } else {
  1600. atomic_clear_mask(mask, &adapter->status);
  1601. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1602. atomic_set(&adapter->erp_counter, 0);
  1603. debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
  1604. }
  1605. debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
  1606. /* Deal with all underlying devices, only pass common_mask */
  1607. if (common_mask)
  1608. list_for_each_entry(port, &adapter->port_list_head, list)
  1609. zfcp_erp_modify_port_status(port, common_mask,
  1610. set_or_clear);
  1611. }
  1612. /*
  1613. * function: zfcp_erp_modify_port_status
  1614. *
  1615. * purpose: sets the port and all underlying devices to ERP_FAILED
  1616. *
  1617. */
  1618. void
  1619. zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
  1620. {
  1621. struct zfcp_unit *unit;
  1622. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1623. if (set_or_clear == ZFCP_SET) {
  1624. atomic_set_mask(mask, &port->status);
  1625. debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
  1626. } else {
  1627. atomic_clear_mask(mask, &port->status);
  1628. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1629. atomic_set(&port->erp_counter, 0);
  1630. debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
  1631. }
  1632. debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  1633. debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
  1634. /* Modify status of all underlying devices, only pass common mask */
  1635. if (common_mask)
  1636. list_for_each_entry(unit, &port->unit_list_head, list)
  1637. zfcp_erp_modify_unit_status(unit, common_mask,
  1638. set_or_clear);
  1639. }
  1640. /*
  1641. * function: zfcp_erp_modify_unit_status
  1642. *
  1643. * purpose: sets the unit to ERP_FAILED
  1644. *
  1645. */
  1646. void
  1647. zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
  1648. {
  1649. if (set_or_clear == ZFCP_SET) {
  1650. atomic_set_mask(mask, &unit->status);
  1651. debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
  1652. } else {
  1653. atomic_clear_mask(mask, &unit->status);
  1654. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1655. atomic_set(&unit->erp_counter, 0);
  1656. }
  1657. debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
  1658. }
  1659. debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
  1660. sizeof (fcp_lun_t));
  1661. debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
  1662. }
  1663. /*
  1664. * function:
  1665. *
  1666. * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
  1667. * used to ensure the correct locking
  1668. *
  1669. * returns: 0 - initiated action succesfully
  1670. * <0 - failed to initiate action
  1671. */
  1672. int
  1673. zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
  1674. {
  1675. int retval;
  1676. unsigned long flags;
  1677. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1678. write_lock(&adapter->erp_lock);
  1679. retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
  1680. write_unlock(&adapter->erp_lock);
  1681. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1682. return retval;
  1683. }
  1684. /*
  1685. * function:
  1686. *
  1687. * purpose:
  1688. *
  1689. * returns: FIXME
  1690. */
  1691. static int
  1692. zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
  1693. {
  1694. int retval = 0;
  1695. struct zfcp_port *port;
  1696. list_for_each_entry(port, &adapter->port_list_head, list)
  1697. if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  1698. zfcp_erp_port_reopen_internal(port, clear_mask);
  1699. return retval;
  1700. }
  1701. /*
  1702. * function:
  1703. *
  1704. * purpose:
  1705. *
  1706. * returns: FIXME
  1707. */
  1708. static int
  1709. zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
  1710. {
  1711. int retval = 0;
  1712. struct zfcp_unit *unit;
  1713. list_for_each_entry(unit, &port->unit_list_head, list)
  1714. zfcp_erp_unit_reopen_internal(unit, clear_mask);
  1715. return retval;
  1716. }
  1717. /*
  1718. * function:
  1719. *
  1720. * purpose: this routine executes the 'Reopen Adapter' action
  1721. * (the entire action is processed synchronously, since
  1722. * there are no actions which might be run concurrently
  1723. * per definition)
  1724. *
  1725. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1726. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1727. */
  1728. static int
  1729. zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
  1730. {
  1731. int retval;
  1732. struct zfcp_adapter *adapter = erp_action->adapter;
  1733. retval = zfcp_erp_adapter_strategy_close(erp_action);
  1734. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  1735. retval = ZFCP_ERP_EXIT;
  1736. else
  1737. retval = zfcp_erp_adapter_strategy_open(erp_action);
  1738. debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
  1739. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  1740. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  1741. if (retval == ZFCP_ERP_FAILED) {
  1742. ZFCP_LOG_INFO("Waiting to allow the adapter %s "
  1743. "to recover itself\n",
  1744. zfcp_get_busid_by_adapter(adapter));
  1745. msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
  1746. }
  1747. return retval;
  1748. }
  1749. /*
  1750. * function:
  1751. *
  1752. * purpose:
  1753. *
  1754. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1755. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1756. */
  1757. static int
  1758. zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
  1759. {
  1760. int retval;
  1761. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
  1762. &erp_action->adapter->status);
  1763. retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
  1764. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
  1765. &erp_action->adapter->status);
  1766. return retval;
  1767. }
  1768. /*
  1769. * function:
  1770. *
  1771. * purpose:
  1772. *
  1773. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1774. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1775. */
  1776. static int
  1777. zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
  1778. {
  1779. int retval;
  1780. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
  1781. &erp_action->adapter->status);
  1782. retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
  1783. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
  1784. &erp_action->adapter->status);
  1785. return retval;
  1786. }
  1787. /*
  1788. * function: zfcp_register_adapter
  1789. *
  1790. * purpose: allocate the irq associated with this devno and register
  1791. * the FSF adapter with the SCSI stack
  1792. *
  1793. * returns:
  1794. */
  1795. static int
  1796. zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
  1797. {
  1798. int retval = ZFCP_ERP_SUCCEEDED;
  1799. if (close)
  1800. goto close_only;
  1801. retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
  1802. if (retval != ZFCP_ERP_SUCCEEDED)
  1803. goto failed_qdio;
  1804. retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
  1805. if (retval != ZFCP_ERP_SUCCEEDED)
  1806. goto failed_openfcp;
  1807. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
  1808. goto out;
  1809. close_only:
  1810. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1811. &erp_action->adapter->status);
  1812. failed_openfcp:
  1813. zfcp_erp_adapter_strategy_close_qdio(erp_action);
  1814. zfcp_erp_adapter_strategy_close_fsf(erp_action);
  1815. failed_qdio:
  1816. out:
  1817. return retval;
  1818. }
  1819. /*
  1820. * function: zfcp_qdio_init
  1821. *
  1822. * purpose: setup QDIO operation for specified adapter
  1823. *
  1824. * returns: 0 - successful setup
  1825. * !0 - failed setup
  1826. */
  1827. int
  1828. zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
  1829. {
  1830. int retval;
  1831. int i;
  1832. volatile struct qdio_buffer_element *sbale;
  1833. struct zfcp_adapter *adapter = erp_action->adapter;
  1834. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  1835. ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
  1836. "adapter %s\n",
  1837. zfcp_get_busid_by_adapter(adapter));
  1838. goto failed_sanity;
  1839. }
  1840. if (qdio_establish(&adapter->qdio_init_data) != 0) {
  1841. ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
  1842. "on adapter %s\n",
  1843. zfcp_get_busid_by_adapter(adapter));
  1844. goto failed_qdio_establish;
  1845. }
  1846. debug_text_event(adapter->erp_dbf, 3, "qdio_est");
  1847. if (qdio_activate(adapter->ccw_device, 0) != 0) {
  1848. ZFCP_LOG_INFO("error: activation of QDIO queues failed "
  1849. "on adapter %s\n",
  1850. zfcp_get_busid_by_adapter(adapter));
  1851. goto failed_qdio_activate;
  1852. }
  1853. debug_text_event(adapter->erp_dbf, 3, "qdio_act");
  1854. /*
  1855. * put buffers into response queue,
  1856. */
  1857. for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
  1858. sbale = &(adapter->response_queue.buffer[i]->element[0]);
  1859. sbale->length = 0;
  1860. sbale->flags = SBAL_FLAGS_LAST_ENTRY;
  1861. sbale->addr = 0;
  1862. }
  1863. ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
  1864. "queue_no=%i, index_in_queue=%i, count=%i)\n",
  1865. zfcp_get_busid_by_adapter(adapter),
  1866. QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
  1867. retval = do_QDIO(adapter->ccw_device,
  1868. QDIO_FLAG_SYNC_INPUT,
  1869. 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
  1870. if (retval) {
  1871. ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
  1872. retval);
  1873. goto failed_do_qdio;
  1874. } else {
  1875. adapter->response_queue.free_index = 0;
  1876. atomic_set(&adapter->response_queue.free_count, 0);
  1877. ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
  1878. "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
  1879. }
  1880. /* set index of first avalable SBALS / number of available SBALS */
  1881. adapter->request_queue.free_index = 0;
  1882. atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
  1883. adapter->request_queue.distance_from_int = 0;
  1884. /* initialize waitqueue used to wait for free SBALs in requests queue */
  1885. init_waitqueue_head(&adapter->request_wq);
  1886. /* ok, we did it - skip all cleanups for different failures */
  1887. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
  1888. retval = ZFCP_ERP_SUCCEEDED;
  1889. goto out;
  1890. failed_do_qdio:
  1891. /* NOP */
  1892. failed_qdio_activate:
  1893. debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
  1894. while (qdio_shutdown(adapter->ccw_device,
  1895. QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
  1896. msleep(1000);
  1897. debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
  1898. failed_qdio_establish:
  1899. failed_sanity:
  1900. retval = ZFCP_ERP_FAILED;
  1901. out:
  1902. return retval;
  1903. }
  1904. /*
  1905. * function: zfcp_qdio_cleanup
  1906. *
  1907. * purpose: cleans up QDIO operation for the specified adapter
  1908. *
  1909. * returns: 0 - successful cleanup
  1910. * !0 - failed cleanup
  1911. */
  1912. int
  1913. zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
  1914. {
  1915. int retval = ZFCP_ERP_SUCCEEDED;
  1916. int first_used;
  1917. int used_count;
  1918. struct zfcp_adapter *adapter = erp_action->adapter;
  1919. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  1920. ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
  1921. "queues on adapter %s\n",
  1922. zfcp_get_busid_by_adapter(adapter));
  1923. retval = ZFCP_ERP_FAILED;
  1924. goto out;
  1925. }
  1926. /*
  1927. * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
  1928. * do_QDIO won't be called while qdio_shutdown is in progress.
  1929. */
  1930. write_lock_irq(&adapter->request_queue.queue_lock);
  1931. atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
  1932. write_unlock_irq(&adapter->request_queue.queue_lock);
  1933. debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
  1934. while (qdio_shutdown(adapter->ccw_device,
  1935. QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
  1936. msleep(1000);
  1937. debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
  1938. /*
  1939. * First we had to stop QDIO operation.
  1940. * Now it is safe to take the following actions.
  1941. */
  1942. /* Cleanup only necessary when there are unacknowledged buffers */
  1943. if (atomic_read(&adapter->request_queue.free_count)
  1944. < QDIO_MAX_BUFFERS_PER_Q) {
  1945. first_used = (adapter->request_queue.free_index +
  1946. atomic_read(&adapter->request_queue.free_count))
  1947. % QDIO_MAX_BUFFERS_PER_Q;
  1948. used_count = QDIO_MAX_BUFFERS_PER_Q -
  1949. atomic_read(&adapter->request_queue.free_count);
  1950. zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
  1951. first_used, used_count);
  1952. }
  1953. adapter->response_queue.free_index = 0;
  1954. atomic_set(&adapter->response_queue.free_count, 0);
  1955. adapter->request_queue.free_index = 0;
  1956. atomic_set(&adapter->request_queue.free_count, 0);
  1957. adapter->request_queue.distance_from_int = 0;
  1958. out:
  1959. return retval;
  1960. }
  1961. /*
  1962. * function: zfcp_fsf_init
  1963. *
  1964. * purpose: initializes FSF operation for the specified adapter
  1965. *
  1966. * returns: 0 - succesful initialization of FSF operation
  1967. * !0 - failed to initialize FSF operation
  1968. */
  1969. static int
  1970. zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
  1971. {
  1972. int xconfig, xport;
  1973. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  1974. &erp_action->adapter->status)) {
  1975. zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
  1976. atomic_set(&erp_action->adapter->erp_counter, 0);
  1977. return ZFCP_ERP_FAILED;
  1978. }
  1979. xconfig = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
  1980. xport = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
  1981. if ((xconfig == ZFCP_ERP_FAILED) || (xport == ZFCP_ERP_FAILED))
  1982. return ZFCP_ERP_FAILED;
  1983. return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
  1984. }
  1985. /*
  1986. * function:
  1987. *
  1988. * purpose:
  1989. *
  1990. * returns:
  1991. */
  1992. static int
  1993. zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
  1994. {
  1995. int retval = ZFCP_ERP_SUCCEEDED;
  1996. int retries;
  1997. int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
  1998. struct zfcp_adapter *adapter = erp_action->adapter;
  1999. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  2000. for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
  2001. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  2002. &adapter->status);
  2003. ZFCP_LOG_DEBUG("Doing exchange config data\n");
  2004. write_lock(&adapter->erp_lock);
  2005. zfcp_erp_action_to_running(erp_action);
  2006. write_unlock(&adapter->erp_lock);
  2007. zfcp_erp_timeout_init(erp_action);
  2008. if (zfcp_fsf_exchange_config_data(erp_action)) {
  2009. retval = ZFCP_ERP_FAILED;
  2010. debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
  2011. ZFCP_LOG_INFO("error: initiation of exchange of "
  2012. "configuration data failed for "
  2013. "adapter %s\n",
  2014. zfcp_get_busid_by_adapter(adapter));
  2015. break;
  2016. }
  2017. debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
  2018. ZFCP_LOG_DEBUG("Xchange underway\n");
  2019. /*
  2020. * Why this works:
  2021. * Both the normal completion handler as well as the timeout
  2022. * handler will do an 'up' when the 'exchange config data'
  2023. * request completes or times out. Thus, the signal to go on
  2024. * won't be lost utilizing this semaphore.
  2025. * Furthermore, this 'adapter_reopen' action is
  2026. * guaranteed to be the only action being there (highest action
  2027. * which prevents other actions from being created).
  2028. * Resulting from that, the wake signal recognized here
  2029. * _must_ be the one belonging to the 'exchange config
  2030. * data' request.
  2031. */
  2032. down(&adapter->erp_ready_sem);
  2033. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
  2034. ZFCP_LOG_INFO("error: exchange of configuration data "
  2035. "for adapter %s timed out\n",
  2036. zfcp_get_busid_by_adapter(adapter));
  2037. break;
  2038. }
  2039. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  2040. &adapter->status))
  2041. break;
  2042. ZFCP_LOG_DEBUG("host connection still initialising... "
  2043. "waiting and retrying...\n");
  2044. /* sleep a little bit before retry */
  2045. msleep(jiffies_to_msecs(sleep));
  2046. sleep *= 2;
  2047. }
  2048. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  2049. &adapter->status)) {
  2050. ZFCP_LOG_INFO("error: exchange of configuration data for "
  2051. "adapter %s failed\n",
  2052. zfcp_get_busid_by_adapter(adapter));
  2053. retval = ZFCP_ERP_FAILED;
  2054. }
  2055. return retval;
  2056. }
  2057. static int
  2058. zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
  2059. {
  2060. int retval = ZFCP_ERP_SUCCEEDED;
  2061. int retries;
  2062. int sleep;
  2063. struct zfcp_adapter *adapter = erp_action->adapter;
  2064. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2065. for (retries = 0; ; retries++) {
  2066. ZFCP_LOG_DEBUG("Doing exchange port data\n");
  2067. zfcp_erp_action_to_running(erp_action);
  2068. zfcp_erp_timeout_init(erp_action);
  2069. if (zfcp_fsf_exchange_port_data(erp_action, adapter, NULL)) {
  2070. retval = ZFCP_ERP_FAILED;
  2071. debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
  2072. ZFCP_LOG_INFO("error: initiation of exchange of "
  2073. "port data failed for adapter %s\n",
  2074. zfcp_get_busid_by_adapter(adapter));
  2075. break;
  2076. }
  2077. debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
  2078. ZFCP_LOG_DEBUG("Xchange underway\n");
  2079. /*
  2080. * Why this works:
  2081. * Both the normal completion handler as well as the timeout
  2082. * handler will do an 'up' when the 'exchange port data'
  2083. * request completes or times out. Thus, the signal to go on
  2084. * won't be lost utilizing this semaphore.
  2085. * Furthermore, this 'adapter_reopen' action is
  2086. * guaranteed to be the only action being there (highest action
  2087. * which prevents other actions from being created).
  2088. * Resulting from that, the wake signal recognized here
  2089. * _must_ be the one belonging to the 'exchange port
  2090. * data' request.
  2091. */
  2092. down(&adapter->erp_ready_sem);
  2093. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
  2094. ZFCP_LOG_INFO("error: exchange of port data "
  2095. "for adapter %s timed out\n",
  2096. zfcp_get_busid_by_adapter(adapter));
  2097. break;
  2098. }
  2099. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  2100. &adapter->status))
  2101. break;
  2102. ZFCP_LOG_DEBUG("host connection still initialising... "
  2103. "waiting and retrying...\n");
  2104. /* sleep a little bit before retry */
  2105. sleep = retries < ZFCP_EXCHANGE_PORT_DATA_SHORT_RETRIES ?
  2106. ZFCP_EXCHANGE_PORT_DATA_SHORT_SLEEP :
  2107. ZFCP_EXCHANGE_PORT_DATA_LONG_SLEEP;
  2108. msleep(jiffies_to_msecs(sleep));
  2109. }
  2110. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  2111. &adapter->status)) {
  2112. ZFCP_LOG_INFO("error: exchange of port data for "
  2113. "adapter %s failed\n",
  2114. zfcp_get_busid_by_adapter(adapter));
  2115. retval = ZFCP_ERP_FAILED;
  2116. }
  2117. return retval;
  2118. }
  2119. /*
  2120. * function:
  2121. *
  2122. * purpose:
  2123. *
  2124. * returns:
  2125. */
  2126. static int
  2127. zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
  2128. *erp_action)
  2129. {
  2130. int retval = ZFCP_ERP_SUCCEEDED;
  2131. int temp_ret;
  2132. struct zfcp_adapter *adapter = erp_action->adapter;
  2133. int i;
  2134. adapter->status_read_failed = 0;
  2135. for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
  2136. temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
  2137. if (temp_ret < 0) {
  2138. ZFCP_LOG_INFO("error: set-up of unsolicited status "
  2139. "notification failed on adapter %s\n",
  2140. zfcp_get_busid_by_adapter(adapter));
  2141. retval = ZFCP_ERP_FAILED;
  2142. i--;
  2143. break;
  2144. }
  2145. }
  2146. return retval;
  2147. }
  2148. /*
  2149. * function: zfcp_fsf_cleanup
  2150. *
  2151. * purpose: cleanup FSF operation for specified adapter
  2152. *
  2153. * returns: 0 - FSF operation successfully cleaned up
  2154. * !0 - failed to cleanup FSF operation for this adapter
  2155. */
  2156. static int
  2157. zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
  2158. {
  2159. int retval = ZFCP_ERP_SUCCEEDED;
  2160. struct zfcp_adapter *adapter = erp_action->adapter;
  2161. /*
  2162. * wake waiting initiators of requests,
  2163. * return SCSI commands (with error status),
  2164. * clean up all requests (synchronously)
  2165. */
  2166. zfcp_fsf_req_dismiss_all(adapter);
  2167. /* reset FSF request sequence number */
  2168. adapter->fsf_req_seq_no = 0;
  2169. /* all ports and units are closed */
  2170. zfcp_erp_modify_adapter_status(adapter,
  2171. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  2172. return retval;
  2173. }
  2174. /*
  2175. * function:
  2176. *
  2177. * purpose: this routine executes the 'Reopen Physical Port' action
  2178. *
  2179. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2180. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2181. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2182. */
  2183. static int
  2184. zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  2185. {
  2186. int retval = ZFCP_ERP_FAILED;
  2187. struct zfcp_port *port = erp_action->port;
  2188. struct zfcp_adapter *adapter = erp_action->adapter;
  2189. switch (erp_action->step) {
  2190. /*
  2191. * FIXME:
  2192. * the ULP spec. begs for waiting for oustanding commands
  2193. */
  2194. case ZFCP_ERP_STEP_UNINITIALIZED:
  2195. zfcp_erp_port_strategy_clearstati(port);
  2196. /*
  2197. * it would be sufficient to test only the normal open flag
  2198. * since the phys. open flag cannot be set if the normal
  2199. * open flag is unset - however, this is for readabilty ...
  2200. */
  2201. if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
  2202. ZFCP_STATUS_COMMON_OPEN),
  2203. &port->status)) {
  2204. ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
  2205. "close physical\n", port->wwpn);
  2206. retval =
  2207. zfcp_erp_port_forced_strategy_close(erp_action);
  2208. } else
  2209. retval = ZFCP_ERP_FAILED;
  2210. break;
  2211. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2212. if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
  2213. &port->status)) {
  2214. ZFCP_LOG_DEBUG("close physical failed for port "
  2215. "0x%016Lx\n", port->wwpn);
  2216. retval = ZFCP_ERP_FAILED;
  2217. } else
  2218. retval = ZFCP_ERP_SUCCEEDED;
  2219. break;
  2220. }
  2221. debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
  2222. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  2223. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2224. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2225. return retval;
  2226. }
  2227. /*
  2228. * function:
  2229. *
  2230. * purpose: this routine executes the 'Reopen Port' action
  2231. *
  2232. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2233. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2234. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2235. */
  2236. static int
  2237. zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  2238. {
  2239. int retval = ZFCP_ERP_FAILED;
  2240. struct zfcp_port *port = erp_action->port;
  2241. struct zfcp_adapter *adapter = erp_action->adapter;
  2242. switch (erp_action->step) {
  2243. /*
  2244. * FIXME:
  2245. * the ULP spec. begs for waiting for oustanding commands
  2246. */
  2247. case ZFCP_ERP_STEP_UNINITIALIZED:
  2248. zfcp_erp_port_strategy_clearstati(port);
  2249. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2250. ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
  2251. "close\n", port->wwpn);
  2252. retval = zfcp_erp_port_strategy_close(erp_action);
  2253. goto out;
  2254. } /* else it's already closed, open it */
  2255. break;
  2256. case ZFCP_ERP_STEP_PORT_CLOSING:
  2257. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2258. ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
  2259. port->wwpn);
  2260. retval = ZFCP_ERP_FAILED;
  2261. goto out;
  2262. } /* else it's closed now, open it */
  2263. break;
  2264. }
  2265. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  2266. retval = ZFCP_ERP_EXIT;
  2267. else
  2268. retval = zfcp_erp_port_strategy_open(erp_action);
  2269. out:
  2270. debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
  2271. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  2272. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2273. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2274. return retval;
  2275. }
  2276. /*
  2277. * function:
  2278. *
  2279. * purpose:
  2280. *
  2281. * returns:
  2282. */
  2283. static int
  2284. zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
  2285. {
  2286. int retval;
  2287. if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
  2288. &erp_action->port->status))
  2289. retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
  2290. else
  2291. retval = zfcp_erp_port_strategy_open_common(erp_action);
  2292. return retval;
  2293. }
  2294. /*
  2295. * function:
  2296. *
  2297. * purpose:
  2298. *
  2299. * returns:
  2300. *
  2301. * FIXME(design): currently only prepared for fabric (nameserver!)
  2302. */
  2303. static int
  2304. zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
  2305. {
  2306. int retval = 0;
  2307. struct zfcp_adapter *adapter = erp_action->adapter;
  2308. struct zfcp_port *port = erp_action->port;
  2309. switch (erp_action->step) {
  2310. case ZFCP_ERP_STEP_UNINITIALIZED:
  2311. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2312. case ZFCP_ERP_STEP_PORT_CLOSING:
  2313. if (adapter->fc_topology == FSF_TOPO_P2P) {
  2314. if (port->wwpn != adapter->peer_wwpn) {
  2315. ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
  2316. "on adapter %s.\nPeer WWPN "
  2317. "0x%016Lx does not match\n",
  2318. port->wwpn,
  2319. zfcp_get_busid_by_adapter(adapter),
  2320. adapter->peer_wwpn);
  2321. zfcp_erp_port_failed(port);
  2322. retval = ZFCP_ERP_FAILED;
  2323. break;
  2324. }
  2325. port->d_id = adapter->peer_d_id;
  2326. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  2327. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2328. break;
  2329. }
  2330. if (!(adapter->nameserver_port)) {
  2331. retval = zfcp_nameserver_enqueue(adapter);
  2332. if (retval != 0) {
  2333. ZFCP_LOG_NORMAL("error: nameserver port "
  2334. "unavailable for adapter %s\n",
  2335. zfcp_get_busid_by_adapter(adapter));
  2336. retval = ZFCP_ERP_FAILED;
  2337. break;
  2338. }
  2339. }
  2340. if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  2341. &adapter->nameserver_port->status)) {
  2342. ZFCP_LOG_DEBUG("nameserver port is not open -> open "
  2343. "nameserver port\n");
  2344. /* nameserver port may live again */
  2345. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
  2346. &adapter->nameserver_port->status);
  2347. if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
  2348. >= 0) {
  2349. erp_action->step =
  2350. ZFCP_ERP_STEP_NAMESERVER_OPEN;
  2351. retval = ZFCP_ERP_CONTINUES;
  2352. } else
  2353. retval = ZFCP_ERP_FAILED;
  2354. break;
  2355. }
  2356. /* else nameserver port is already open, fall through */
  2357. case ZFCP_ERP_STEP_NAMESERVER_OPEN:
  2358. if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
  2359. &adapter->nameserver_port->status)) {
  2360. ZFCP_LOG_DEBUG("open failed for nameserver port\n");
  2361. retval = ZFCP_ERP_FAILED;
  2362. } else {
  2363. ZFCP_LOG_DEBUG("nameserver port is open -> "
  2364. "nameserver look-up for port 0x%016Lx\n",
  2365. port->wwpn);
  2366. retval = zfcp_erp_port_strategy_open_common_lookup
  2367. (erp_action);
  2368. }
  2369. break;
  2370. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  2371. if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
  2372. if (atomic_test_mask
  2373. (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
  2374. ZFCP_LOG_DEBUG("nameserver look-up failed "
  2375. "for port 0x%016Lx "
  2376. "(misconfigured WWPN?)\n",
  2377. port->wwpn);
  2378. zfcp_erp_port_failed(port);
  2379. retval = ZFCP_ERP_EXIT;
  2380. } else {
  2381. ZFCP_LOG_DEBUG("nameserver look-up failed for "
  2382. "port 0x%016Lx\n", port->wwpn);
  2383. retval = ZFCP_ERP_FAILED;
  2384. }
  2385. } else {
  2386. ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
  2387. "trying open\n", port->wwpn, port->d_id);
  2388. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2389. }
  2390. break;
  2391. case ZFCP_ERP_STEP_PORT_OPENING:
  2392. /* D_ID might have changed during open */
  2393. if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
  2394. ZFCP_STATUS_PORT_DID_DID),
  2395. &port->status)) {
  2396. ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
  2397. retval = ZFCP_ERP_SUCCEEDED;
  2398. } else {
  2399. ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
  2400. port->wwpn);
  2401. retval = ZFCP_ERP_FAILED;
  2402. }
  2403. break;
  2404. default:
  2405. ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
  2406. erp_action->step);
  2407. retval = ZFCP_ERP_FAILED;
  2408. }
  2409. return retval;
  2410. }
  2411. /*
  2412. * function:
  2413. *
  2414. * purpose:
  2415. *
  2416. * returns:
  2417. */
  2418. static int
  2419. zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
  2420. {
  2421. int retval;
  2422. struct zfcp_port *port = erp_action->port;
  2423. switch (erp_action->step) {
  2424. case ZFCP_ERP_STEP_UNINITIALIZED:
  2425. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2426. case ZFCP_ERP_STEP_PORT_CLOSING:
  2427. ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
  2428. port->wwpn, port->d_id);
  2429. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2430. break;
  2431. case ZFCP_ERP_STEP_PORT_OPENING:
  2432. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2433. ZFCP_LOG_DEBUG("WKA port is open\n");
  2434. retval = ZFCP_ERP_SUCCEEDED;
  2435. } else {
  2436. ZFCP_LOG_DEBUG("open failed for WKA port\n");
  2437. retval = ZFCP_ERP_FAILED;
  2438. }
  2439. /* this is needed anyway (dont care for retval of wakeup) */
  2440. ZFCP_LOG_DEBUG("continue other open port operations\n");
  2441. zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
  2442. break;
  2443. default:
  2444. ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
  2445. erp_action->step);
  2446. retval = ZFCP_ERP_FAILED;
  2447. }
  2448. return retval;
  2449. }
  2450. /*
  2451. * function:
  2452. *
  2453. * purpose: makes the erp thread continue with reopen (physical) port
  2454. * actions which have been paused until the name server port
  2455. * is opened (or failed)
  2456. *
  2457. * returns: 0 (a kind of void retval, its not used)
  2458. */
  2459. static int
  2460. zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
  2461. *ns_erp_action)
  2462. {
  2463. int retval = 0;
  2464. unsigned long flags;
  2465. struct zfcp_adapter *adapter = ns_erp_action->adapter;
  2466. struct zfcp_erp_action *erp_action, *tmp;
  2467. read_lock_irqsave(&adapter->erp_lock, flags);
  2468. list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
  2469. list) {
  2470. debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
  2471. debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
  2472. sizeof (wwn_t));
  2473. if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
  2474. debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
  2475. debug_event(adapter->erp_dbf, 3,
  2476. &erp_action->port->wwpn, sizeof (wwn_t));
  2477. if (atomic_test_mask(
  2478. ZFCP_STATUS_COMMON_ERP_FAILED,
  2479. &adapter->nameserver_port->status))
  2480. zfcp_erp_port_failed(erp_action->port);
  2481. zfcp_erp_action_ready(erp_action);
  2482. }
  2483. }
  2484. read_unlock_irqrestore(&adapter->erp_lock, flags);
  2485. return retval;
  2486. }
  2487. /*
  2488. * function:
  2489. *
  2490. * purpose:
  2491. *
  2492. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2493. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2494. */
  2495. static int
  2496. zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
  2497. {
  2498. int retval;
  2499. struct zfcp_adapter *adapter = erp_action->adapter;
  2500. struct zfcp_port *port = erp_action->port;
  2501. zfcp_erp_timeout_init(erp_action);
  2502. retval = zfcp_fsf_close_physical_port(erp_action);
  2503. if (retval == -ENOMEM) {
  2504. debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
  2505. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2506. retval = ZFCP_ERP_NOMEM;
  2507. goto out;
  2508. }
  2509. erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  2510. if (retval != 0) {
  2511. debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
  2512. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2513. /* could not send 'open', fail */
  2514. retval = ZFCP_ERP_FAILED;
  2515. goto out;
  2516. }
  2517. debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
  2518. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2519. retval = ZFCP_ERP_CONTINUES;
  2520. out:
  2521. return retval;
  2522. }
  2523. /*
  2524. * function:
  2525. *
  2526. * purpose:
  2527. *
  2528. * returns:
  2529. */
  2530. static int
  2531. zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  2532. {
  2533. int retval = 0;
  2534. struct zfcp_adapter *adapter = port->adapter;
  2535. debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
  2536. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2537. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  2538. ZFCP_STATUS_COMMON_CLOSING |
  2539. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2540. ZFCP_STATUS_PORT_DID_DID |
  2541. ZFCP_STATUS_PORT_PHYS_CLOSING |
  2542. ZFCP_STATUS_PORT_INVALID_WWPN,
  2543. &port->status);
  2544. return retval;
  2545. }
  2546. /*
  2547. * function:
  2548. *
  2549. * purpose:
  2550. *
  2551. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2552. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2553. */
  2554. static int
  2555. zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  2556. {
  2557. int retval;
  2558. struct zfcp_adapter *adapter = erp_action->adapter;
  2559. struct zfcp_port *port = erp_action->port;
  2560. zfcp_erp_timeout_init(erp_action);
  2561. retval = zfcp_fsf_close_port(erp_action);
  2562. if (retval == -ENOMEM) {
  2563. debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
  2564. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2565. retval = ZFCP_ERP_NOMEM;
  2566. goto out;
  2567. }
  2568. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  2569. if (retval != 0) {
  2570. debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
  2571. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2572. /* could not send 'close', fail */
  2573. retval = ZFCP_ERP_FAILED;
  2574. goto out;
  2575. }
  2576. debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
  2577. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2578. retval = ZFCP_ERP_CONTINUES;
  2579. out:
  2580. return retval;
  2581. }
  2582. /*
  2583. * function:
  2584. *
  2585. * purpose:
  2586. *
  2587. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2588. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2589. */
  2590. static int
  2591. zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  2592. {
  2593. int retval;
  2594. struct zfcp_adapter *adapter = erp_action->adapter;
  2595. struct zfcp_port *port = erp_action->port;
  2596. zfcp_erp_timeout_init(erp_action);
  2597. retval = zfcp_fsf_open_port(erp_action);
  2598. if (retval == -ENOMEM) {
  2599. debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
  2600. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2601. retval = ZFCP_ERP_NOMEM;
  2602. goto out;
  2603. }
  2604. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  2605. if (retval != 0) {
  2606. debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
  2607. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2608. /* could not send 'open', fail */
  2609. retval = ZFCP_ERP_FAILED;
  2610. goto out;
  2611. }
  2612. debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
  2613. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2614. retval = ZFCP_ERP_CONTINUES;
  2615. out:
  2616. return retval;
  2617. }
  2618. /*
  2619. * function:
  2620. *
  2621. * purpose:
  2622. *
  2623. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2624. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2625. */
  2626. static int
  2627. zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
  2628. {
  2629. int retval;
  2630. struct zfcp_adapter *adapter = erp_action->adapter;
  2631. struct zfcp_port *port = erp_action->port;
  2632. zfcp_erp_timeout_init(erp_action);
  2633. retval = zfcp_ns_gid_pn_request(erp_action);
  2634. if (retval == -ENOMEM) {
  2635. debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
  2636. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2637. retval = ZFCP_ERP_NOMEM;
  2638. goto out;
  2639. }
  2640. erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  2641. if (retval != 0) {
  2642. debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
  2643. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2644. /* could not send nameserver request, fail */
  2645. retval = ZFCP_ERP_FAILED;
  2646. goto out;
  2647. }
  2648. debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
  2649. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2650. retval = ZFCP_ERP_CONTINUES;
  2651. out:
  2652. return retval;
  2653. }
  2654. /*
  2655. * function:
  2656. *
  2657. * purpose: this routine executes the 'Reopen Unit' action
  2658. * currently no retries
  2659. *
  2660. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2661. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2662. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2663. */
  2664. static int
  2665. zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  2666. {
  2667. int retval = ZFCP_ERP_FAILED;
  2668. struct zfcp_unit *unit = erp_action->unit;
  2669. struct zfcp_adapter *adapter = erp_action->adapter;
  2670. switch (erp_action->step) {
  2671. /*
  2672. * FIXME:
  2673. * the ULP spec. begs for waiting for oustanding commands
  2674. */
  2675. case ZFCP_ERP_STEP_UNINITIALIZED:
  2676. zfcp_erp_unit_strategy_clearstati(unit);
  2677. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2678. ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
  2679. "trying close\n", unit->fcp_lun);
  2680. retval = zfcp_erp_unit_strategy_close(erp_action);
  2681. break;
  2682. }
  2683. /* else it's already closed, fall through */
  2684. case ZFCP_ERP_STEP_UNIT_CLOSING:
  2685. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2686. ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
  2687. unit->fcp_lun);
  2688. retval = ZFCP_ERP_FAILED;
  2689. } else {
  2690. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  2691. retval = ZFCP_ERP_EXIT;
  2692. else {
  2693. ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
  2694. "trying open\n", unit->fcp_lun);
  2695. retval =
  2696. zfcp_erp_unit_strategy_open(erp_action);
  2697. }
  2698. }
  2699. break;
  2700. case ZFCP_ERP_STEP_UNIT_OPENING:
  2701. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2702. ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
  2703. unit->fcp_lun);
  2704. retval = ZFCP_ERP_SUCCEEDED;
  2705. } else {
  2706. ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
  2707. unit->fcp_lun);
  2708. retval = ZFCP_ERP_FAILED;
  2709. }
  2710. break;
  2711. }
  2712. debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
  2713. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
  2714. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2715. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2716. return retval;
  2717. }
  2718. /*
  2719. * function:
  2720. *
  2721. * purpose:
  2722. *
  2723. * returns:
  2724. */
  2725. static int
  2726. zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  2727. {
  2728. int retval = 0;
  2729. struct zfcp_adapter *adapter = unit->port->adapter;
  2730. debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
  2731. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
  2732. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  2733. ZFCP_STATUS_COMMON_CLOSING |
  2734. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2735. ZFCP_STATUS_UNIT_SHARED |
  2736. ZFCP_STATUS_UNIT_READONLY,
  2737. &unit->status);
  2738. return retval;
  2739. }
  2740. /*
  2741. * function:
  2742. *
  2743. * purpose:
  2744. *
  2745. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2746. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2747. */
  2748. static int
  2749. zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  2750. {
  2751. int retval;
  2752. struct zfcp_adapter *adapter = erp_action->adapter;
  2753. struct zfcp_unit *unit = erp_action->unit;
  2754. zfcp_erp_timeout_init(erp_action);
  2755. retval = zfcp_fsf_close_unit(erp_action);
  2756. if (retval == -ENOMEM) {
  2757. debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
  2758. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2759. sizeof (fcp_lun_t));
  2760. retval = ZFCP_ERP_NOMEM;
  2761. goto out;
  2762. }
  2763. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  2764. if (retval != 0) {
  2765. debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
  2766. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2767. sizeof (fcp_lun_t));
  2768. /* could not send 'close', fail */
  2769. retval = ZFCP_ERP_FAILED;
  2770. goto out;
  2771. }
  2772. debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
  2773. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  2774. retval = ZFCP_ERP_CONTINUES;
  2775. out:
  2776. return retval;
  2777. }
  2778. /*
  2779. * function:
  2780. *
  2781. * purpose:
  2782. *
  2783. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2784. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2785. */
  2786. static int
  2787. zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  2788. {
  2789. int retval;
  2790. struct zfcp_adapter *adapter = erp_action->adapter;
  2791. struct zfcp_unit *unit = erp_action->unit;
  2792. zfcp_erp_timeout_init(erp_action);
  2793. retval = zfcp_fsf_open_unit(erp_action);
  2794. if (retval == -ENOMEM) {
  2795. debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
  2796. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2797. sizeof (fcp_lun_t));
  2798. retval = ZFCP_ERP_NOMEM;
  2799. goto out;
  2800. }
  2801. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  2802. if (retval != 0) {
  2803. debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
  2804. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2805. sizeof (fcp_lun_t));
  2806. /* could not send 'open', fail */
  2807. retval = ZFCP_ERP_FAILED;
  2808. goto out;
  2809. }
  2810. debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
  2811. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  2812. retval = ZFCP_ERP_CONTINUES;
  2813. out:
  2814. return retval;
  2815. }
  2816. /*
  2817. * function:
  2818. *
  2819. * purpose:
  2820. *
  2821. * returns:
  2822. */
  2823. static inline void
  2824. zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
  2825. {
  2826. init_timer(&erp_action->timer);
  2827. erp_action->timer.function = zfcp_erp_timeout_handler;
  2828. erp_action->timer.data = (unsigned long) erp_action;
  2829. /* jiffies will be added in zfcp_fsf_req_send */
  2830. erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
  2831. }
  2832. /*
  2833. * function:
  2834. *
  2835. * purpose: enqueue the specified error recovery action, if needed
  2836. *
  2837. * returns:
  2838. */
  2839. static int
  2840. zfcp_erp_action_enqueue(int action,
  2841. struct zfcp_adapter *adapter,
  2842. struct zfcp_port *port, struct zfcp_unit *unit)
  2843. {
  2844. int retval = 1;
  2845. struct zfcp_erp_action *erp_action = NULL;
  2846. int stronger_action = 0;
  2847. u32 status = 0;
  2848. /*
  2849. * We need some rules here which check whether we really need
  2850. * this action or whether we should just drop it.
  2851. * E.g. if there is a unfinished 'Reopen Port' request then we drop a
  2852. * 'Reopen Unit' request for an associated unit since we can't
  2853. * satisfy this request now. A 'Reopen Port' action will trigger
  2854. * 'Reopen Unit' actions when it completes.
  2855. * Thus, there are only actions in the queue which can immediately be
  2856. * executed. This makes the processing of the action queue more
  2857. * efficient.
  2858. */
  2859. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
  2860. &adapter->status))
  2861. return -EIO;
  2862. debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
  2863. /* check whether we really need this */
  2864. switch (action) {
  2865. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2866. if (atomic_test_mask
  2867. (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
  2868. debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
  2869. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2870. sizeof (wwn_t));
  2871. debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
  2872. sizeof (fcp_lun_t));
  2873. goto out;
  2874. }
  2875. if (!atomic_test_mask
  2876. (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
  2877. atomic_test_mask
  2878. (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  2879. goto out;
  2880. }
  2881. if (!atomic_test_mask
  2882. (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
  2883. stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
  2884. unit = NULL;
  2885. }
  2886. /* fall through !!! */
  2887. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2888. if (atomic_test_mask
  2889. (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
  2890. debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
  2891. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2892. sizeof (wwn_t));
  2893. goto out;
  2894. }
  2895. /* fall through !!! */
  2896. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2897. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2898. &port->status)) {
  2899. if (port->erp_action.action !=
  2900. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
  2901. ZFCP_LOG_INFO("dropped erp action %i (port "
  2902. "0x%016Lx, action in use: %i)\n",
  2903. action, port->wwpn,
  2904. port->erp_action.action);
  2905. debug_text_event(adapter->erp_dbf, 4,
  2906. "pf_actenq_drp");
  2907. } else
  2908. debug_text_event(adapter->erp_dbf, 4,
  2909. "pf_actenq_drpcp");
  2910. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2911. sizeof (wwn_t));
  2912. goto out;
  2913. }
  2914. if (!atomic_test_mask
  2915. (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
  2916. atomic_test_mask
  2917. (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
  2918. goto out;
  2919. }
  2920. if (!atomic_test_mask
  2921. (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
  2922. stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  2923. port = NULL;
  2924. }
  2925. /* fall through !!! */
  2926. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2927. if (atomic_test_mask
  2928. (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
  2929. debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
  2930. goto out;
  2931. }
  2932. break;
  2933. default:
  2934. debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
  2935. debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
  2936. ZFCP_LOG_NORMAL("bug: unknown erp action requested "
  2937. "on adapter %s (action=%d)\n",
  2938. zfcp_get_busid_by_adapter(adapter), action);
  2939. goto out;
  2940. }
  2941. /* check whether we need something stronger first */
  2942. if (stronger_action) {
  2943. debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
  2944. debug_event(adapter->erp_dbf, 4, &stronger_action,
  2945. sizeof (int));
  2946. ZFCP_LOG_DEBUG("stronger erp action %d needed before "
  2947. "erp action %d on adapter %s\n",
  2948. stronger_action, action,
  2949. zfcp_get_busid_by_adapter(adapter));
  2950. action = stronger_action;
  2951. }
  2952. /* mark adapter to have some error recovery pending */
  2953. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  2954. /* setup error recovery action */
  2955. switch (action) {
  2956. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2957. zfcp_unit_get(unit);
  2958. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  2959. erp_action = &unit->erp_action;
  2960. if (!atomic_test_mask
  2961. (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
  2962. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2963. break;
  2964. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2965. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2966. zfcp_port_get(port);
  2967. zfcp_erp_action_dismiss_port(port);
  2968. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  2969. erp_action = &port->erp_action;
  2970. if (!atomic_test_mask
  2971. (ZFCP_STATUS_COMMON_RUNNING, &port->status))
  2972. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2973. break;
  2974. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2975. zfcp_adapter_get(adapter);
  2976. zfcp_erp_action_dismiss_adapter(adapter);
  2977. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  2978. erp_action = &adapter->erp_action;
  2979. if (!atomic_test_mask
  2980. (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
  2981. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2982. break;
  2983. }
  2984. debug_text_event(adapter->erp_dbf, 4, "a_actenq");
  2985. memset(erp_action, 0, sizeof (struct zfcp_erp_action));
  2986. erp_action->adapter = adapter;
  2987. erp_action->port = port;
  2988. erp_action->unit = unit;
  2989. erp_action->action = action;
  2990. erp_action->status = status;
  2991. ++adapter->erp_total_count;
  2992. /* finally put it into 'ready' queue and kick erp thread */
  2993. list_add(&erp_action->list, &adapter->erp_ready_head);
  2994. up(&adapter->erp_ready_sem);
  2995. retval = 0;
  2996. out:
  2997. return retval;
  2998. }
  2999. /*
  3000. * function:
  3001. *
  3002. * purpose:
  3003. *
  3004. * returns:
  3005. */
  3006. static int
  3007. zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  3008. {
  3009. int retval = 0;
  3010. struct zfcp_adapter *adapter = erp_action->adapter;
  3011. --adapter->erp_total_count;
  3012. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  3013. --adapter->erp_low_mem_count;
  3014. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  3015. }
  3016. debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
  3017. debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
  3018. list_del(&erp_action->list);
  3019. switch (erp_action->action) {
  3020. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  3021. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  3022. &erp_action->unit->status);
  3023. break;
  3024. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  3025. case ZFCP_ERP_ACTION_REOPEN_PORT:
  3026. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  3027. &erp_action->port->status);
  3028. break;
  3029. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  3030. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  3031. &erp_action->adapter->status);
  3032. break;
  3033. default:
  3034. /* bug */
  3035. break;
  3036. }
  3037. return retval;
  3038. }
  3039. /**
  3040. * zfcp_erp_action_cleanup
  3041. *
  3042. * Register unit with scsi stack if appropiate and fix reference counts.
  3043. * Note: Temporary units are not registered with scsi stack.
  3044. */
  3045. static void
  3046. zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
  3047. struct zfcp_port *port, struct zfcp_unit *unit,
  3048. int result)
  3049. {
  3050. switch (action) {
  3051. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  3052. if ((result == ZFCP_ERP_SUCCEEDED)
  3053. && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
  3054. &unit->status))
  3055. && !unit->device
  3056. && port->rport)
  3057. scsi_add_device(port->adapter->scsi_host, 0,
  3058. port->rport->scsi_target_id,
  3059. unit->scsi_lun);
  3060. zfcp_unit_put(unit);
  3061. break;
  3062. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  3063. case ZFCP_ERP_ACTION_REOPEN_PORT:
  3064. if ((result == ZFCP_ERP_SUCCEEDED)
  3065. && !atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
  3066. &port->status)
  3067. && !port->rport) {
  3068. struct fc_rport_identifiers ids;
  3069. ids.node_name = port->wwnn;
  3070. ids.port_name = port->wwpn;
  3071. ids.port_id = port->d_id;
  3072. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  3073. port->rport =
  3074. fc_remote_port_add(adapter->scsi_host, 0, &ids);
  3075. if (!port->rport)
  3076. ZFCP_LOG_NORMAL("failed registration of rport"
  3077. "(adapter %s, wwpn=0x%016Lx)\n",
  3078. zfcp_get_busid_by_port(port),
  3079. port->wwpn);
  3080. }
  3081. zfcp_port_put(port);
  3082. break;
  3083. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  3084. zfcp_adapter_put(adapter);
  3085. break;
  3086. default:
  3087. break;
  3088. }
  3089. }
  3090. /*
  3091. * function:
  3092. *
  3093. * purpose:
  3094. *
  3095. * returns: FIXME
  3096. */
  3097. static int
  3098. zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  3099. {
  3100. int retval = 0;
  3101. struct zfcp_port *port;
  3102. debug_text_event(adapter->erp_dbf, 5, "a_actab");
  3103. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
  3104. zfcp_erp_action_dismiss(&adapter->erp_action);
  3105. else
  3106. list_for_each_entry(port, &adapter->port_list_head, list)
  3107. zfcp_erp_action_dismiss_port(port);
  3108. return retval;
  3109. }
  3110. /*
  3111. * function:
  3112. *
  3113. * purpose:
  3114. *
  3115. * returns: FIXME
  3116. */
  3117. static int
  3118. zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  3119. {
  3120. int retval = 0;
  3121. struct zfcp_unit *unit;
  3122. struct zfcp_adapter *adapter = port->adapter;
  3123. debug_text_event(adapter->erp_dbf, 5, "p_actab");
  3124. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  3125. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
  3126. zfcp_erp_action_dismiss(&port->erp_action);
  3127. else
  3128. list_for_each_entry(unit, &port->unit_list_head, list)
  3129. zfcp_erp_action_dismiss_unit(unit);
  3130. return retval;
  3131. }
  3132. /*
  3133. * function:
  3134. *
  3135. * purpose:
  3136. *
  3137. * returns: FIXME
  3138. */
  3139. static int
  3140. zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  3141. {
  3142. int retval = 0;
  3143. struct zfcp_adapter *adapter = unit->port->adapter;
  3144. debug_text_event(adapter->erp_dbf, 5, "u_actab");
  3145. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
  3146. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
  3147. zfcp_erp_action_dismiss(&unit->erp_action);
  3148. return retval;
  3149. }
  3150. /*
  3151. * function:
  3152. *
  3153. * purpose: moves erp_action to 'erp running list'
  3154. *
  3155. * returns:
  3156. */
  3157. static inline void
  3158. zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  3159. {
  3160. struct zfcp_adapter *adapter = erp_action->adapter;
  3161. debug_text_event(adapter->erp_dbf, 6, "a_toru");
  3162. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  3163. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  3164. }
  3165. /*
  3166. * function:
  3167. *
  3168. * purpose: moves erp_action to 'erp ready list'
  3169. *
  3170. * returns:
  3171. */
  3172. static inline void
  3173. zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
  3174. {
  3175. struct zfcp_adapter *adapter = erp_action->adapter;
  3176. debug_text_event(adapter->erp_dbf, 6, "a_tore");
  3177. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  3178. list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
  3179. }
  3180. /*
  3181. * function: zfcp_erp_port_boxed
  3182. *
  3183. * purpose:
  3184. */
  3185. void
  3186. zfcp_erp_port_boxed(struct zfcp_port *port)
  3187. {
  3188. struct zfcp_adapter *adapter = port->adapter;
  3189. unsigned long flags;
  3190. debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
  3191. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  3192. read_lock_irqsave(&zfcp_data.config_lock, flags);
  3193. zfcp_erp_modify_port_status(port,
  3194. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3195. ZFCP_SET);
  3196. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  3197. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
  3198. }
  3199. /*
  3200. * function: zfcp_erp_unit_boxed
  3201. *
  3202. * purpose:
  3203. */
  3204. void
  3205. zfcp_erp_unit_boxed(struct zfcp_unit *unit)
  3206. {
  3207. struct zfcp_adapter *adapter = unit->port->adapter;
  3208. debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
  3209. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  3210. zfcp_erp_modify_unit_status(unit,
  3211. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3212. ZFCP_SET);
  3213. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  3214. }
  3215. /*
  3216. * function: zfcp_erp_port_access_denied
  3217. *
  3218. * purpose:
  3219. */
  3220. void
  3221. zfcp_erp_port_access_denied(struct zfcp_port *port)
  3222. {
  3223. struct zfcp_adapter *adapter = port->adapter;
  3224. unsigned long flags;
  3225. debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
  3226. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  3227. read_lock_irqsave(&zfcp_data.config_lock, flags);
  3228. zfcp_erp_modify_port_status(port,
  3229. ZFCP_STATUS_COMMON_ERP_FAILED |
  3230. ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3231. ZFCP_SET);
  3232. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  3233. }
  3234. /*
  3235. * function: zfcp_erp_unit_access_denied
  3236. *
  3237. * purpose:
  3238. */
  3239. void
  3240. zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
  3241. {
  3242. struct zfcp_adapter *adapter = unit->port->adapter;
  3243. debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
  3244. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  3245. zfcp_erp_modify_unit_status(unit,
  3246. ZFCP_STATUS_COMMON_ERP_FAILED |
  3247. ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3248. ZFCP_SET);
  3249. }
  3250. /*
  3251. * function: zfcp_erp_adapter_access_changed
  3252. *
  3253. * purpose:
  3254. */
  3255. void
  3256. zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
  3257. {
  3258. struct zfcp_port *port;
  3259. unsigned long flags;
  3260. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  3261. return;
  3262. debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
  3263. debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
  3264. read_lock_irqsave(&zfcp_data.config_lock, flags);
  3265. if (adapter->nameserver_port)
  3266. zfcp_erp_port_access_changed(adapter->nameserver_port);
  3267. list_for_each_entry(port, &adapter->port_list_head, list)
  3268. if (port != adapter->nameserver_port)
  3269. zfcp_erp_port_access_changed(port);
  3270. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  3271. }
  3272. /*
  3273. * function: zfcp_erp_port_access_changed
  3274. *
  3275. * purpose:
  3276. */
  3277. void
  3278. zfcp_erp_port_access_changed(struct zfcp_port *port)
  3279. {
  3280. struct zfcp_adapter *adapter = port->adapter;
  3281. struct zfcp_unit *unit;
  3282. debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
  3283. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  3284. if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3285. &port->status) &&
  3286. !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3287. &port->status)) {
  3288. if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  3289. list_for_each_entry(unit, &port->unit_list_head, list)
  3290. zfcp_erp_unit_access_changed(unit);
  3291. return;
  3292. }
  3293. ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
  3294. "(due to ACT update)\n",
  3295. port->wwpn, zfcp_get_busid_by_adapter(adapter));
  3296. if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
  3297. ZFCP_LOG_NORMAL("failed reopen of port"
  3298. "(adapter %s, wwpn=0x%016Lx)\n",
  3299. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  3300. }
  3301. /*
  3302. * function: zfcp_erp_unit_access_changed
  3303. *
  3304. * purpose:
  3305. */
  3306. void
  3307. zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
  3308. {
  3309. struct zfcp_adapter *adapter = unit->port->adapter;
  3310. debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
  3311. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  3312. if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3313. &unit->status) &&
  3314. !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3315. &unit->status))
  3316. return;
  3317. ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
  3318. " on adapter %s (due to ACT update)\n",
  3319. unit->fcp_lun, unit->port->wwpn,
  3320. zfcp_get_busid_by_adapter(adapter));
  3321. if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
  3322. ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
  3323. "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
  3324. zfcp_get_busid_by_adapter(adapter),
  3325. unit->port->wwpn, unit->fcp_lun);
  3326. }
  3327. #undef ZFCP_LOG_AREA