zfcp_erp.c 98 KB

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