zfcp_erp.c 99 KB

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