zfcp_erp.c 99 KB

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