zfcp_erp.c 99 KB

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