zfcp_erp.c 98 KB

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