zfcp_erp.c 99 KB

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