zfcp_erp.c 97 KB

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