zfcp_erp.c 101 KB

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