zfcp_erp.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399
  1. /*
  2. * This file is part of the zfcp device driver for
  3. * FCP adapters for IBM System z9 and zSeries.
  4. *
  5. * (C) Copyright IBM Corp. 2002, 2006
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2, or (at your option)
  10. * any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_ERP
  22. #include "zfcp_ext.h"
  23. static int zfcp_erp_adisc(struct zfcp_port *);
  24. static void zfcp_erp_adisc_handler(unsigned long);
  25. static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
  26. static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
  27. static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
  28. static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
  29. static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
  30. static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
  31. static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
  32. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
  33. static void zfcp_erp_port_block(struct zfcp_port *, int);
  34. static void zfcp_erp_port_unblock(struct zfcp_port *);
  35. static void zfcp_erp_unit_block(struct zfcp_unit *, int);
  36. static void zfcp_erp_unit_unblock(struct zfcp_unit *);
  37. static int zfcp_erp_thread(void *);
  38. static int zfcp_erp_strategy(struct zfcp_erp_action *);
  39. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
  40. static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
  41. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
  42. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
  43. static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
  44. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
  45. static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
  46. struct zfcp_port *,
  47. struct zfcp_unit *, int);
  48. static int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
  49. static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
  50. struct zfcp_port *,
  51. struct zfcp_unit *, int);
  52. static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
  53. static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
  54. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
  55. static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
  56. static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
  57. static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
  58. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
  59. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
  60. static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
  61. static int zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *);
  62. static int zfcp_erp_adapter_strategy_open_fsf_statusread(
  63. struct zfcp_erp_action *);
  64. static int zfcp_erp_port_forced_strategy(struct zfcp_erp_action *);
  65. static int zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *);
  66. static int zfcp_erp_port_strategy(struct zfcp_erp_action *);
  67. static int zfcp_erp_port_strategy_clearstati(struct zfcp_port *);
  68. static int zfcp_erp_port_strategy_close(struct zfcp_erp_action *);
  69. static int zfcp_erp_port_strategy_open(struct zfcp_erp_action *);
  70. static int zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *);
  71. static int zfcp_erp_port_strategy_open_nameserver_wakeup(
  72. struct zfcp_erp_action *);
  73. static int zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *);
  74. static int zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *);
  75. static int zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *);
  76. static int zfcp_erp_unit_strategy(struct zfcp_erp_action *);
  77. static int zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *);
  78. static int zfcp_erp_unit_strategy_close(struct zfcp_erp_action *);
  79. static int zfcp_erp_unit_strategy_open(struct zfcp_erp_action *);
  80. static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *);
  81. static void zfcp_erp_action_dismiss_port(struct zfcp_port *);
  82. static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *);
  83. static void zfcp_erp_action_dismiss(struct zfcp_erp_action *);
  84. static int zfcp_erp_action_enqueue(int, struct zfcp_adapter *,
  85. struct zfcp_port *, struct zfcp_unit *);
  86. static int zfcp_erp_action_dequeue(struct zfcp_erp_action *);
  87. static void zfcp_erp_action_cleanup(int, struct zfcp_adapter *,
  88. struct zfcp_port *, struct zfcp_unit *,
  89. int);
  90. static void zfcp_erp_action_ready(struct zfcp_erp_action *);
  91. static int zfcp_erp_action_exists(struct zfcp_erp_action *);
  92. static void zfcp_erp_action_to_ready(struct zfcp_erp_action *);
  93. static void zfcp_erp_action_to_running(struct zfcp_erp_action *);
  94. static void zfcp_erp_memwait_handler(unsigned long);
  95. /**
  96. * zfcp_close_qdio - close qdio queues for an adapter
  97. */
  98. static void zfcp_close_qdio(struct zfcp_adapter *adapter)
  99. {
  100. struct zfcp_qdio_queue *req_queue;
  101. int first, count;
  102. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status))
  103. return;
  104. /* clear QDIOUP flag, thus do_QDIO is not called during qdio_shutdown */
  105. req_queue = &adapter->request_queue;
  106. write_lock_irq(&req_queue->queue_lock);
  107. atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
  108. write_unlock_irq(&req_queue->queue_lock);
  109. debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
  110. while (qdio_shutdown(adapter->ccw_device,
  111. QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
  112. ssleep(1);
  113. debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
  114. /* cleanup used outbound sbals */
  115. count = atomic_read(&req_queue->free_count);
  116. if (count < QDIO_MAX_BUFFERS_PER_Q) {
  117. first = (req_queue->free_index+count) % QDIO_MAX_BUFFERS_PER_Q;
  118. count = QDIO_MAX_BUFFERS_PER_Q - count;
  119. zfcp_qdio_zero_sbals(req_queue->buffer, first, count);
  120. }
  121. req_queue->free_index = 0;
  122. atomic_set(&req_queue->free_count, 0);
  123. req_queue->distance_from_int = 0;
  124. adapter->response_queue.free_index = 0;
  125. atomic_set(&adapter->response_queue.free_count, 0);
  126. }
  127. /**
  128. * zfcp_close_fsf - stop FSF operations for an adapter
  129. *
  130. * Dismiss and cleanup all pending fsf_reqs (this wakes up all initiators of
  131. * requests waiting for completion; especially this returns SCSI commands
  132. * with error state).
  133. */
  134. static void zfcp_close_fsf(struct zfcp_adapter *adapter)
  135. {
  136. /* close queues to ensure that buffers are not accessed by adapter */
  137. zfcp_close_qdio(adapter);
  138. zfcp_fsf_req_dismiss_all(adapter);
  139. /* reset FSF request sequence number */
  140. adapter->fsf_req_seq_no = 0;
  141. /* all ports and units are closed */
  142. zfcp_erp_modify_adapter_status(adapter,
  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.next;
  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. * we go through down() here because there has been an up()
  1006. */
  1007. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED)
  1008. retval = ZFCP_ERP_CONTINUES;
  1009. switch (retval) {
  1010. case ZFCP_ERP_NOMEM:
  1011. /* no memory to continue immediately, let it sleep */
  1012. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1013. ++adapter->erp_low_mem_count;
  1014. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1015. }
  1016. /* This condition is true if there is no memory available
  1017. for any erp_action on this adapter. This implies that there
  1018. are no elements in the memory pool(s) left for erp_actions.
  1019. This might happen if an erp_action that used a memory pool
  1020. element was timed out.
  1021. */
  1022. if (adapter->erp_total_count == adapter->erp_low_mem_count) {
  1023. debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
  1024. ZFCP_LOG_NORMAL("error: no mempool elements available, "
  1025. "restarting I/O on adapter %s "
  1026. "to free mempool\n",
  1027. zfcp_get_busid_by_adapter(adapter));
  1028. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1029. } else {
  1030. debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
  1031. retval = zfcp_erp_strategy_memwait(erp_action);
  1032. }
  1033. goto unlock;
  1034. case ZFCP_ERP_CONTINUES:
  1035. /* leave since this action runs asynchronously */
  1036. debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
  1037. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1038. --adapter->erp_low_mem_count;
  1039. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1040. }
  1041. goto unlock;
  1042. }
  1043. /* ok, finished action (whatever its result is) */
  1044. /* check for unrecoverable targets */
  1045. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1046. /* action must be dequeued (here to allow for further ones) */
  1047. zfcp_erp_action_dequeue(erp_action);
  1048. /*
  1049. * put this target through the erp mill again if someone has
  1050. * requested to change the status of a target being online
  1051. * to offline or the other way around
  1052. * (old retval is preserved if nothing has to be done here)
  1053. */
  1054. retval = zfcp_erp_strategy_statechange(action, status, adapter,
  1055. port, unit, retval);
  1056. /*
  1057. * leave if target is in permanent error state or if
  1058. * action is repeated in order to process state change
  1059. */
  1060. if (retval == ZFCP_ERP_EXIT) {
  1061. debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
  1062. goto unlock;
  1063. }
  1064. /* trigger follow up actions */
  1065. zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
  1066. unlock:
  1067. write_unlock(&adapter->erp_lock);
  1068. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1069. if (retval != ZFCP_ERP_CONTINUES)
  1070. zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
  1071. /*
  1072. * a few tasks remain when the erp queues are empty
  1073. * (don't do that if the last action evaluated was dismissed
  1074. * since this clearly indicates that there is more to come) :
  1075. * - close the name server port if it is open yet
  1076. * (enqueues another [probably] final action)
  1077. * - otherwise, wake up whoever wants to be woken when we are
  1078. * done with erp
  1079. */
  1080. if (retval != ZFCP_ERP_DISMISSED)
  1081. zfcp_erp_strategy_check_queues(adapter);
  1082. debug_text_event(adapter->erp_dbf, 6, "a_st_done");
  1083. return retval;
  1084. }
  1085. /*
  1086. * function:
  1087. *
  1088. * purpose:
  1089. *
  1090. * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
  1091. * retval - otherwise
  1092. */
  1093. static int
  1094. zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
  1095. {
  1096. struct zfcp_adapter *adapter = erp_action->adapter;
  1097. zfcp_erp_strategy_check_fsfreq(erp_action);
  1098. debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
  1099. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1100. debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
  1101. zfcp_erp_action_dequeue(erp_action);
  1102. retval = ZFCP_ERP_DISMISSED;
  1103. } else
  1104. debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
  1105. return retval;
  1106. }
  1107. static int
  1108. zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1109. {
  1110. int retval = ZFCP_ERP_FAILED;
  1111. struct zfcp_adapter *adapter = erp_action->adapter;
  1112. /*
  1113. * try to execute/continue action as far as possible,
  1114. * note: no lock in subsequent strategy routines
  1115. * (this allows these routine to call schedule, e.g.
  1116. * kmalloc with such flags or qdio_initialize & friends)
  1117. * Note: in case of timeout, the seperate strategies will fail
  1118. * anyhow. No need for a special action. Even worse, a nameserver
  1119. * failure would not wake up waiting ports without the call.
  1120. */
  1121. switch (erp_action->action) {
  1122. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1123. retval = zfcp_erp_adapter_strategy(erp_action);
  1124. break;
  1125. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1126. retval = zfcp_erp_port_forced_strategy(erp_action);
  1127. break;
  1128. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1129. retval = zfcp_erp_port_strategy(erp_action);
  1130. break;
  1131. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1132. retval = zfcp_erp_unit_strategy(erp_action);
  1133. break;
  1134. default:
  1135. debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
  1136. debug_event(adapter->erp_dbf, 1, &erp_action->action,
  1137. sizeof (int));
  1138. ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
  1139. "adapter %s (action=%d)\n",
  1140. zfcp_get_busid_by_adapter(erp_action->adapter),
  1141. erp_action->action);
  1142. }
  1143. return retval;
  1144. }
  1145. /*
  1146. * function:
  1147. *
  1148. * purpose: triggers retry of this action after a certain amount of time
  1149. * by means of timer provided by erp_action
  1150. *
  1151. * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
  1152. */
  1153. static int
  1154. zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  1155. {
  1156. int retval = ZFCP_ERP_CONTINUES;
  1157. struct zfcp_adapter *adapter = erp_action->adapter;
  1158. debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
  1159. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  1160. init_timer(&erp_action->timer);
  1161. erp_action->timer.function = zfcp_erp_memwait_handler;
  1162. erp_action->timer.data = (unsigned long) erp_action;
  1163. erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
  1164. add_timer(&erp_action->timer);
  1165. return retval;
  1166. }
  1167. /*
  1168. * function: zfcp_erp_adapter_failed
  1169. *
  1170. * purpose: sets the adapter and all underlying devices to ERP_FAILED
  1171. *
  1172. */
  1173. void
  1174. zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
  1175. {
  1176. zfcp_erp_modify_adapter_status(adapter,
  1177. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1178. ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
  1179. zfcp_get_busid_by_adapter(adapter));
  1180. debug_text_event(adapter->erp_dbf, 2, "a_afail");
  1181. }
  1182. /*
  1183. * function: zfcp_erp_port_failed
  1184. *
  1185. * purpose: sets the port and all underlying devices to ERP_FAILED
  1186. *
  1187. */
  1188. void
  1189. zfcp_erp_port_failed(struct zfcp_port *port)
  1190. {
  1191. zfcp_erp_modify_port_status(port,
  1192. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1193. if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  1194. ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
  1195. "port d_id=0x%06x)\n",
  1196. zfcp_get_busid_by_port(port), port->d_id);
  1197. else
  1198. ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
  1199. zfcp_get_busid_by_port(port), port->wwpn);
  1200. debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
  1201. debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
  1202. }
  1203. /*
  1204. * function: zfcp_erp_unit_failed
  1205. *
  1206. * purpose: sets the unit to ERP_FAILED
  1207. *
  1208. */
  1209. void
  1210. zfcp_erp_unit_failed(struct zfcp_unit *unit)
  1211. {
  1212. zfcp_erp_modify_unit_status(unit,
  1213. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1214. ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
  1215. " on adapter %s\n", unit->fcp_lun,
  1216. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  1217. debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
  1218. debug_event(unit->port->adapter->erp_dbf, 2,
  1219. &unit->fcp_lun, sizeof (fcp_lun_t));
  1220. }
  1221. /*
  1222. * function: zfcp_erp_strategy_check_target
  1223. *
  1224. * purpose: increments the erp action count on the device currently in
  1225. * recovery if the action failed or resets the count in case of
  1226. * success. If a maximum count is exceeded the device is marked
  1227. * as ERP_FAILED.
  1228. * The 'blocked' state of a target which has been recovered
  1229. * successfully is reset.
  1230. *
  1231. * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
  1232. * ZFCP_ERP_SUCCEEDED - action finished successfully
  1233. * ZFCP_ERP_EXIT - action failed and will not continue
  1234. */
  1235. static int
  1236. zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
  1237. {
  1238. struct zfcp_adapter *adapter = erp_action->adapter;
  1239. struct zfcp_port *port = erp_action->port;
  1240. struct zfcp_unit *unit = erp_action->unit;
  1241. debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
  1242. debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
  1243. debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
  1244. switch (erp_action->action) {
  1245. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1246. result = zfcp_erp_strategy_check_unit(unit, result);
  1247. break;
  1248. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1249. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1250. result = zfcp_erp_strategy_check_port(port, result);
  1251. break;
  1252. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1253. result = zfcp_erp_strategy_check_adapter(adapter, result);
  1254. break;
  1255. }
  1256. return result;
  1257. }
  1258. static int
  1259. zfcp_erp_strategy_statechange(int action,
  1260. u32 status,
  1261. struct zfcp_adapter *adapter,
  1262. struct zfcp_port *port,
  1263. struct zfcp_unit *unit, int retval)
  1264. {
  1265. debug_text_event(adapter->erp_dbf, 3, "a_stsc");
  1266. debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
  1267. switch (action) {
  1268. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1269. if (zfcp_erp_strategy_statechange_detected(&adapter->status,
  1270. status)) {
  1271. zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  1272. retval = ZFCP_ERP_EXIT;
  1273. }
  1274. break;
  1275. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1276. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1277. if (zfcp_erp_strategy_statechange_detected(&port->status,
  1278. status)) {
  1279. zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
  1280. retval = ZFCP_ERP_EXIT;
  1281. }
  1282. break;
  1283. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1284. if (zfcp_erp_strategy_statechange_detected(&unit->status,
  1285. status)) {
  1286. zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  1287. retval = ZFCP_ERP_EXIT;
  1288. }
  1289. break;
  1290. }
  1291. return retval;
  1292. }
  1293. static int
  1294. zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
  1295. {
  1296. return
  1297. /* take it online */
  1298. (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
  1299. (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
  1300. /* take it offline */
  1301. (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
  1302. !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
  1303. }
  1304. static int
  1305. zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  1306. {
  1307. debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
  1308. debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
  1309. sizeof (fcp_lun_t));
  1310. switch (result) {
  1311. case ZFCP_ERP_SUCCEEDED :
  1312. atomic_set(&unit->erp_counter, 0);
  1313. zfcp_erp_unit_unblock(unit);
  1314. break;
  1315. case ZFCP_ERP_FAILED :
  1316. atomic_inc(&unit->erp_counter);
  1317. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
  1318. zfcp_erp_unit_failed(unit);
  1319. break;
  1320. case ZFCP_ERP_EXIT :
  1321. /* nothing */
  1322. break;
  1323. }
  1324. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
  1325. zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
  1326. result = ZFCP_ERP_EXIT;
  1327. }
  1328. return result;
  1329. }
  1330. static int
  1331. zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  1332. {
  1333. debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
  1334. debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  1335. switch (result) {
  1336. case ZFCP_ERP_SUCCEEDED :
  1337. atomic_set(&port->erp_counter, 0);
  1338. zfcp_erp_port_unblock(port);
  1339. break;
  1340. case ZFCP_ERP_FAILED :
  1341. atomic_inc(&port->erp_counter);
  1342. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
  1343. zfcp_erp_port_failed(port);
  1344. break;
  1345. case ZFCP_ERP_EXIT :
  1346. /* nothing */
  1347. break;
  1348. }
  1349. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  1350. zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
  1351. result = ZFCP_ERP_EXIT;
  1352. }
  1353. return result;
  1354. }
  1355. static int
  1356. zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
  1357. {
  1358. debug_text_event(adapter->erp_dbf, 5, "a_stct");
  1359. switch (result) {
  1360. case ZFCP_ERP_SUCCEEDED :
  1361. atomic_set(&adapter->erp_counter, 0);
  1362. zfcp_erp_adapter_unblock(adapter);
  1363. break;
  1364. case ZFCP_ERP_FAILED :
  1365. atomic_inc(&adapter->erp_counter);
  1366. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
  1367. zfcp_erp_adapter_failed(adapter);
  1368. break;
  1369. case ZFCP_ERP_EXIT :
  1370. /* nothing */
  1371. break;
  1372. }
  1373. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
  1374. zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
  1375. result = ZFCP_ERP_EXIT;
  1376. }
  1377. return result;
  1378. }
  1379. struct zfcp_erp_add_work {
  1380. struct zfcp_unit *unit;
  1381. struct work_struct work;
  1382. };
  1383. /**
  1384. * zfcp_erp_scsi_scan
  1385. * @data: pointer to a struct zfcp_erp_add_work
  1386. *
  1387. * Registers a logical unit with the SCSI stack.
  1388. */
  1389. static void zfcp_erp_scsi_scan(struct work_struct *work)
  1390. {
  1391. struct zfcp_erp_add_work *p =
  1392. container_of(work, struct zfcp_erp_add_work, work);
  1393. struct zfcp_unit *unit = p->unit;
  1394. struct fc_rport *rport = unit->port->rport;
  1395. scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
  1396. unit->scsi_lun, 0);
  1397. atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1398. zfcp_unit_put(unit);
  1399. kfree(p);
  1400. }
  1401. /**
  1402. * zfcp_erp_schedule_work
  1403. * @unit: pointer to unit which should be registered with SCSI stack
  1404. *
  1405. * Schedules work which registers a unit with the SCSI stack
  1406. */
  1407. static void
  1408. zfcp_erp_schedule_work(struct zfcp_unit *unit)
  1409. {
  1410. struct zfcp_erp_add_work *p;
  1411. p = kzalloc(sizeof(*p), GFP_KERNEL);
  1412. if (!p) {
  1413. ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
  1414. "the FCP-LUN 0x%Lx connected to "
  1415. "the port with WWPN 0x%Lx connected to "
  1416. "the adapter %s with the SCSI stack.\n",
  1417. unit->fcp_lun,
  1418. unit->port->wwpn,
  1419. zfcp_get_busid_by_unit(unit));
  1420. return;
  1421. }
  1422. zfcp_unit_get(unit);
  1423. atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
  1424. INIT_WORK(&p->work, zfcp_erp_scsi_scan);
  1425. p->unit = unit;
  1426. schedule_work(&p->work);
  1427. }
  1428. /*
  1429. * function:
  1430. *
  1431. * purpose: remaining things in good cases,
  1432. * escalation in bad cases
  1433. *
  1434. * returns:
  1435. */
  1436. static int
  1437. zfcp_erp_strategy_followup_actions(int action,
  1438. struct zfcp_adapter *adapter,
  1439. struct zfcp_port *port,
  1440. struct zfcp_unit *unit, int status)
  1441. {
  1442. debug_text_event(adapter->erp_dbf, 5, "a_stfol");
  1443. debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
  1444. /* initiate follow-up actions depending on success of finished action */
  1445. switch (action) {
  1446. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1447. if (status == ZFCP_ERP_SUCCEEDED)
  1448. zfcp_erp_port_reopen_all_internal(adapter, 0);
  1449. else
  1450. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1451. break;
  1452. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1453. if (status == ZFCP_ERP_SUCCEEDED)
  1454. zfcp_erp_port_reopen_internal(port, 0);
  1455. else
  1456. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1457. break;
  1458. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1459. if (status == ZFCP_ERP_SUCCEEDED)
  1460. zfcp_erp_unit_reopen_all_internal(port, 0);
  1461. else
  1462. zfcp_erp_port_forced_reopen_internal(port, 0);
  1463. break;
  1464. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1465. /* Nothing to do if status == ZFCP_ERP_SUCCEEDED */
  1466. if (status != ZFCP_ERP_SUCCEEDED)
  1467. zfcp_erp_port_reopen_internal(unit->port, 0);
  1468. break;
  1469. }
  1470. return 0;
  1471. }
  1472. static int
  1473. zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
  1474. {
  1475. unsigned long flags;
  1476. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1477. read_lock(&adapter->erp_lock);
  1478. if (list_empty(&adapter->erp_ready_head) &&
  1479. list_empty(&adapter->erp_running_head)) {
  1480. debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
  1481. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  1482. &adapter->status);
  1483. wake_up(&adapter->erp_done_wqh);
  1484. } else
  1485. debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
  1486. read_unlock(&adapter->erp_lock);
  1487. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1488. return 0;
  1489. }
  1490. /**
  1491. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1492. * @adapter: adapter for which to wait for completion of its error recovery
  1493. * Return: 0
  1494. */
  1495. int
  1496. zfcp_erp_wait(struct zfcp_adapter *adapter)
  1497. {
  1498. int retval = 0;
  1499. wait_event(adapter->erp_done_wqh,
  1500. !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  1501. &adapter->status));
  1502. return retval;
  1503. }
  1504. void
  1505. zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
  1506. u32 mask, int set_or_clear)
  1507. {
  1508. struct zfcp_port *port;
  1509. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1510. if (set_or_clear == ZFCP_SET) {
  1511. atomic_set_mask(mask, &adapter->status);
  1512. debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
  1513. } else {
  1514. atomic_clear_mask(mask, &adapter->status);
  1515. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1516. atomic_set(&adapter->erp_counter, 0);
  1517. debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
  1518. }
  1519. debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
  1520. /* Deal with all underlying devices, only pass common_mask */
  1521. if (common_mask)
  1522. list_for_each_entry(port, &adapter->port_list_head, list)
  1523. zfcp_erp_modify_port_status(port, common_mask,
  1524. set_or_clear);
  1525. }
  1526. /*
  1527. * function: zfcp_erp_modify_port_status
  1528. *
  1529. * purpose: sets the port and all underlying devices to ERP_FAILED
  1530. *
  1531. */
  1532. void
  1533. zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
  1534. {
  1535. struct zfcp_unit *unit;
  1536. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1537. if (set_or_clear == ZFCP_SET) {
  1538. atomic_set_mask(mask, &port->status);
  1539. debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
  1540. } else {
  1541. atomic_clear_mask(mask, &port->status);
  1542. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1543. atomic_set(&port->erp_counter, 0);
  1544. debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
  1545. }
  1546. debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  1547. debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
  1548. /* Modify status of all underlying devices, only pass common mask */
  1549. if (common_mask)
  1550. list_for_each_entry(unit, &port->unit_list_head, list)
  1551. zfcp_erp_modify_unit_status(unit, common_mask,
  1552. set_or_clear);
  1553. }
  1554. /*
  1555. * function: zfcp_erp_modify_unit_status
  1556. *
  1557. * purpose: sets the unit to ERP_FAILED
  1558. *
  1559. */
  1560. void
  1561. zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
  1562. {
  1563. if (set_or_clear == ZFCP_SET) {
  1564. atomic_set_mask(mask, &unit->status);
  1565. debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
  1566. } else {
  1567. atomic_clear_mask(mask, &unit->status);
  1568. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1569. atomic_set(&unit->erp_counter, 0);
  1570. }
  1571. debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
  1572. }
  1573. debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
  1574. sizeof (fcp_lun_t));
  1575. debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
  1576. }
  1577. /*
  1578. * function:
  1579. *
  1580. * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
  1581. * used to ensure the correct locking
  1582. *
  1583. * returns: 0 - initiated action successfully
  1584. * <0 - failed to initiate action
  1585. */
  1586. int
  1587. zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
  1588. {
  1589. int retval;
  1590. unsigned long flags;
  1591. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1592. write_lock(&adapter->erp_lock);
  1593. retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
  1594. write_unlock(&adapter->erp_lock);
  1595. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1596. return retval;
  1597. }
  1598. static int
  1599. zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
  1600. {
  1601. int retval = 0;
  1602. struct zfcp_port *port;
  1603. list_for_each_entry(port, &adapter->port_list_head, list)
  1604. if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  1605. zfcp_erp_port_reopen_internal(port, clear_mask);
  1606. return retval;
  1607. }
  1608. /*
  1609. * function:
  1610. *
  1611. * purpose:
  1612. *
  1613. * returns: FIXME
  1614. */
  1615. static int
  1616. zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
  1617. {
  1618. int retval = 0;
  1619. struct zfcp_unit *unit;
  1620. list_for_each_entry(unit, &port->unit_list_head, list)
  1621. zfcp_erp_unit_reopen_internal(unit, clear_mask);
  1622. return retval;
  1623. }
  1624. /*
  1625. * function:
  1626. *
  1627. * purpose: this routine executes the 'Reopen Adapter' action
  1628. * (the entire action is processed synchronously, since
  1629. * there are no actions which might be run concurrently
  1630. * per definition)
  1631. *
  1632. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1633. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1634. */
  1635. static int
  1636. zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
  1637. {
  1638. int retval;
  1639. struct zfcp_adapter *adapter = erp_action->adapter;
  1640. retval = zfcp_erp_adapter_strategy_close(erp_action);
  1641. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  1642. retval = ZFCP_ERP_EXIT;
  1643. else
  1644. retval = zfcp_erp_adapter_strategy_open(erp_action);
  1645. debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
  1646. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  1647. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  1648. if (retval == ZFCP_ERP_FAILED) {
  1649. ZFCP_LOG_INFO("Waiting to allow the adapter %s "
  1650. "to recover itself\n",
  1651. zfcp_get_busid_by_adapter(adapter));
  1652. ssleep(ZFCP_TYPE2_RECOVERY_TIME);
  1653. }
  1654. return retval;
  1655. }
  1656. /*
  1657. * function:
  1658. *
  1659. * purpose:
  1660. *
  1661. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1662. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1663. */
  1664. static int
  1665. zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
  1666. {
  1667. int retval;
  1668. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
  1669. &erp_action->adapter->status);
  1670. retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
  1671. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
  1672. &erp_action->adapter->status);
  1673. return retval;
  1674. }
  1675. /*
  1676. * function:
  1677. *
  1678. * purpose:
  1679. *
  1680. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1681. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1682. */
  1683. static int
  1684. zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
  1685. {
  1686. int retval;
  1687. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
  1688. &erp_action->adapter->status);
  1689. retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
  1690. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
  1691. &erp_action->adapter->status);
  1692. return retval;
  1693. }
  1694. /*
  1695. * function: zfcp_register_adapter
  1696. *
  1697. * purpose: allocate the irq associated with this devno and register
  1698. * the FSF adapter with the SCSI stack
  1699. *
  1700. * returns:
  1701. */
  1702. static int
  1703. zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
  1704. {
  1705. int retval = ZFCP_ERP_SUCCEEDED;
  1706. if (close)
  1707. goto close_only;
  1708. retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
  1709. if (retval != ZFCP_ERP_SUCCEEDED)
  1710. goto failed_qdio;
  1711. retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
  1712. if (retval != ZFCP_ERP_SUCCEEDED)
  1713. goto failed_openfcp;
  1714. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
  1715. goto out;
  1716. close_only:
  1717. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1718. &erp_action->adapter->status);
  1719. failed_openfcp:
  1720. zfcp_close_fsf(erp_action->adapter);
  1721. failed_qdio:
  1722. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK |
  1723. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED |
  1724. ZFCP_STATUS_ADAPTER_XPORT_OK,
  1725. &erp_action->adapter->status);
  1726. out:
  1727. return retval;
  1728. }
  1729. /*
  1730. * function: zfcp_qdio_init
  1731. *
  1732. * purpose: setup QDIO operation for specified adapter
  1733. *
  1734. * returns: 0 - successful setup
  1735. * !0 - failed setup
  1736. */
  1737. static int
  1738. zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
  1739. {
  1740. int retval;
  1741. int i;
  1742. volatile struct qdio_buffer_element *sbale;
  1743. struct zfcp_adapter *adapter = erp_action->adapter;
  1744. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  1745. ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
  1746. "adapter %s\n",
  1747. zfcp_get_busid_by_adapter(adapter));
  1748. goto failed_sanity;
  1749. }
  1750. if (qdio_establish(&adapter->qdio_init_data) != 0) {
  1751. ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
  1752. "on adapter %s\n",
  1753. zfcp_get_busid_by_adapter(adapter));
  1754. goto failed_qdio_establish;
  1755. }
  1756. debug_text_event(adapter->erp_dbf, 3, "qdio_est");
  1757. if (qdio_activate(adapter->ccw_device, 0) != 0) {
  1758. ZFCP_LOG_INFO("error: activation of QDIO queues failed "
  1759. "on adapter %s\n",
  1760. zfcp_get_busid_by_adapter(adapter));
  1761. goto failed_qdio_activate;
  1762. }
  1763. debug_text_event(adapter->erp_dbf, 3, "qdio_act");
  1764. /*
  1765. * put buffers into response queue,
  1766. */
  1767. for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
  1768. sbale = &(adapter->response_queue.buffer[i]->element[0]);
  1769. sbale->length = 0;
  1770. sbale->flags = SBAL_FLAGS_LAST_ENTRY;
  1771. sbale->addr = NULL;
  1772. }
  1773. ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
  1774. "queue_no=%i, index_in_queue=%i, count=%i)\n",
  1775. zfcp_get_busid_by_adapter(adapter),
  1776. QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
  1777. retval = do_QDIO(adapter->ccw_device,
  1778. QDIO_FLAG_SYNC_INPUT,
  1779. 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
  1780. if (retval) {
  1781. ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
  1782. retval);
  1783. goto failed_do_qdio;
  1784. } else {
  1785. adapter->response_queue.free_index = 0;
  1786. atomic_set(&adapter->response_queue.free_count, 0);
  1787. ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
  1788. "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
  1789. }
  1790. /* set index of first avalable SBALS / number of available SBALS */
  1791. adapter->request_queue.free_index = 0;
  1792. atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
  1793. adapter->request_queue.distance_from_int = 0;
  1794. /* initialize waitqueue used to wait for free SBALs in requests queue */
  1795. init_waitqueue_head(&adapter->request_wq);
  1796. /* ok, we did it - skip all cleanups for different failures */
  1797. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
  1798. retval = ZFCP_ERP_SUCCEEDED;
  1799. goto out;
  1800. failed_do_qdio:
  1801. /* NOP */
  1802. failed_qdio_activate:
  1803. debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
  1804. while (qdio_shutdown(adapter->ccw_device,
  1805. QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
  1806. ssleep(1);
  1807. debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
  1808. failed_qdio_establish:
  1809. failed_sanity:
  1810. retval = ZFCP_ERP_FAILED;
  1811. out:
  1812. return retval;
  1813. }
  1814. static int
  1815. zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
  1816. {
  1817. int retval;
  1818. retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
  1819. if (retval == ZFCP_ERP_FAILED)
  1820. return ZFCP_ERP_FAILED;
  1821. retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
  1822. if (retval == ZFCP_ERP_FAILED)
  1823. return ZFCP_ERP_FAILED;
  1824. return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
  1825. }
  1826. static int
  1827. zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
  1828. {
  1829. int retval = ZFCP_ERP_SUCCEEDED;
  1830. int retries;
  1831. int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
  1832. struct zfcp_adapter *adapter = erp_action->adapter;
  1833. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  1834. for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
  1835. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  1836. &adapter->status);
  1837. ZFCP_LOG_DEBUG("Doing exchange config data\n");
  1838. write_lock_irq(&adapter->erp_lock);
  1839. zfcp_erp_action_to_running(erp_action);
  1840. write_unlock_irq(&adapter->erp_lock);
  1841. if (zfcp_fsf_exchange_config_data(erp_action)) {
  1842. retval = ZFCP_ERP_FAILED;
  1843. debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
  1844. ZFCP_LOG_INFO("error: initiation of exchange of "
  1845. "configuration data failed for "
  1846. "adapter %s\n",
  1847. zfcp_get_busid_by_adapter(adapter));
  1848. break;
  1849. }
  1850. debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
  1851. ZFCP_LOG_DEBUG("Xchange underway\n");
  1852. /*
  1853. * Why this works:
  1854. * Both the normal completion handler as well as the timeout
  1855. * handler will do an 'up' when the 'exchange config data'
  1856. * request completes or times out. Thus, the signal to go on
  1857. * won't be lost utilizing this semaphore.
  1858. * Furthermore, this 'adapter_reopen' action is
  1859. * guaranteed to be the only action being there (highest action
  1860. * which prevents other actions from being created).
  1861. * Resulting from that, the wake signal recognized here
  1862. * _must_ be the one belonging to the 'exchange config
  1863. * data' request.
  1864. */
  1865. down(&adapter->erp_ready_sem);
  1866. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
  1867. ZFCP_LOG_INFO("error: exchange of configuration data "
  1868. "for adapter %s timed out\n",
  1869. zfcp_get_busid_by_adapter(adapter));
  1870. break;
  1871. }
  1872. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  1873. &adapter->status))
  1874. break;
  1875. ZFCP_LOG_DEBUG("host connection still initialising... "
  1876. "waiting and retrying...\n");
  1877. /* sleep a little bit before retry */
  1878. ssleep(sleep);
  1879. sleep *= 2;
  1880. }
  1881. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  1882. &adapter->status);
  1883. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1884. &adapter->status)) {
  1885. ZFCP_LOG_INFO("error: exchange of configuration data for "
  1886. "adapter %s failed\n",
  1887. zfcp_get_busid_by_adapter(adapter));
  1888. retval = ZFCP_ERP_FAILED;
  1889. }
  1890. return retval;
  1891. }
  1892. static int
  1893. zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
  1894. {
  1895. int ret;
  1896. struct zfcp_adapter *adapter;
  1897. adapter = erp_action->adapter;
  1898. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  1899. write_lock_irq(&adapter->erp_lock);
  1900. zfcp_erp_action_to_running(erp_action);
  1901. write_unlock_irq(&adapter->erp_lock);
  1902. ret = zfcp_fsf_exchange_port_data(erp_action);
  1903. if (ret == -EOPNOTSUPP) {
  1904. debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
  1905. return ZFCP_ERP_SUCCEEDED;
  1906. } else if (ret) {
  1907. debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
  1908. return ZFCP_ERP_FAILED;
  1909. }
  1910. debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
  1911. ret = ZFCP_ERP_SUCCEEDED;
  1912. down(&adapter->erp_ready_sem);
  1913. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
  1914. ZFCP_LOG_INFO("error: exchange port data timed out (adapter "
  1915. "%s)\n", zfcp_get_busid_by_adapter(adapter));
  1916. ret = ZFCP_ERP_FAILED;
  1917. }
  1918. /* don't treat as error for the sake of compatibility */
  1919. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status))
  1920. ZFCP_LOG_INFO("warning: exchange port data failed (adapter "
  1921. "%s\n", zfcp_get_busid_by_adapter(adapter));
  1922. return ret;
  1923. }
  1924. static int
  1925. zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
  1926. *erp_action)
  1927. {
  1928. int retval = ZFCP_ERP_SUCCEEDED;
  1929. int temp_ret;
  1930. struct zfcp_adapter *adapter = erp_action->adapter;
  1931. int i;
  1932. adapter->status_read_failed = 0;
  1933. for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
  1934. temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
  1935. if (temp_ret < 0) {
  1936. ZFCP_LOG_INFO("error: set-up of unsolicited status "
  1937. "notification failed on adapter %s\n",
  1938. zfcp_get_busid_by_adapter(adapter));
  1939. retval = ZFCP_ERP_FAILED;
  1940. i--;
  1941. break;
  1942. }
  1943. }
  1944. return retval;
  1945. }
  1946. /*
  1947. * function:
  1948. *
  1949. * purpose: this routine executes the 'Reopen Physical Port' action
  1950. *
  1951. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  1952. * ZFCP_ERP_SUCCEEDED - action finished successfully
  1953. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1954. */
  1955. static int
  1956. zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  1957. {
  1958. int retval = ZFCP_ERP_FAILED;
  1959. struct zfcp_port *port = erp_action->port;
  1960. struct zfcp_adapter *adapter = erp_action->adapter;
  1961. switch (erp_action->step) {
  1962. /*
  1963. * FIXME:
  1964. * the ULP spec. begs for waiting for oustanding commands
  1965. */
  1966. case ZFCP_ERP_STEP_UNINITIALIZED:
  1967. zfcp_erp_port_strategy_clearstati(port);
  1968. /*
  1969. * it would be sufficient to test only the normal open flag
  1970. * since the phys. open flag cannot be set if the normal
  1971. * open flag is unset - however, this is for readabilty ...
  1972. */
  1973. if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
  1974. ZFCP_STATUS_COMMON_OPEN),
  1975. &port->status)) {
  1976. ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
  1977. "close physical\n", port->wwpn);
  1978. retval =
  1979. zfcp_erp_port_forced_strategy_close(erp_action);
  1980. } else
  1981. retval = ZFCP_ERP_FAILED;
  1982. break;
  1983. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  1984. if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
  1985. &port->status)) {
  1986. ZFCP_LOG_DEBUG("close physical failed for port "
  1987. "0x%016Lx\n", port->wwpn);
  1988. retval = ZFCP_ERP_FAILED;
  1989. } else
  1990. retval = ZFCP_ERP_SUCCEEDED;
  1991. break;
  1992. }
  1993. debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
  1994. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  1995. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  1996. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  1997. return retval;
  1998. }
  1999. /*
  2000. * function:
  2001. *
  2002. * purpose: this routine executes the 'Reopen Port' action
  2003. *
  2004. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2005. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2006. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2007. */
  2008. static int
  2009. zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  2010. {
  2011. int retval = ZFCP_ERP_FAILED;
  2012. struct zfcp_port *port = erp_action->port;
  2013. struct zfcp_adapter *adapter = erp_action->adapter;
  2014. switch (erp_action->step) {
  2015. /*
  2016. * FIXME:
  2017. * the ULP spec. begs for waiting for oustanding commands
  2018. */
  2019. case ZFCP_ERP_STEP_UNINITIALIZED:
  2020. zfcp_erp_port_strategy_clearstati(port);
  2021. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2022. ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
  2023. "close\n", port->wwpn);
  2024. retval = zfcp_erp_port_strategy_close(erp_action);
  2025. goto out;
  2026. } /* else it's already closed, open it */
  2027. break;
  2028. case ZFCP_ERP_STEP_PORT_CLOSING:
  2029. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2030. ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
  2031. port->wwpn);
  2032. retval = ZFCP_ERP_FAILED;
  2033. goto out;
  2034. } /* else it's closed now, open it */
  2035. break;
  2036. }
  2037. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  2038. retval = ZFCP_ERP_EXIT;
  2039. else
  2040. retval = zfcp_erp_port_strategy_open(erp_action);
  2041. out:
  2042. debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
  2043. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  2044. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2045. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2046. return retval;
  2047. }
  2048. static int
  2049. zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
  2050. {
  2051. int retval;
  2052. if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
  2053. &erp_action->port->status))
  2054. retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
  2055. else
  2056. retval = zfcp_erp_port_strategy_open_common(erp_action);
  2057. return retval;
  2058. }
  2059. static int
  2060. zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
  2061. {
  2062. int retval = 0;
  2063. struct zfcp_adapter *adapter = erp_action->adapter;
  2064. struct zfcp_port *port = erp_action->port;
  2065. switch (erp_action->step) {
  2066. case ZFCP_ERP_STEP_UNINITIALIZED:
  2067. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2068. case ZFCP_ERP_STEP_PORT_CLOSING:
  2069. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
  2070. if (port->wwpn != adapter->peer_wwpn) {
  2071. ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
  2072. "on adapter %s.\nPeer WWPN "
  2073. "0x%016Lx does not match\n",
  2074. port->wwpn,
  2075. zfcp_get_busid_by_adapter(adapter),
  2076. adapter->peer_wwpn);
  2077. zfcp_erp_port_failed(port);
  2078. retval = ZFCP_ERP_FAILED;
  2079. break;
  2080. }
  2081. port->d_id = adapter->peer_d_id;
  2082. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  2083. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2084. break;
  2085. }
  2086. if (!(adapter->nameserver_port)) {
  2087. retval = zfcp_nameserver_enqueue(adapter);
  2088. if (retval != 0) {
  2089. ZFCP_LOG_NORMAL("error: nameserver port "
  2090. "unavailable for adapter %s\n",
  2091. zfcp_get_busid_by_adapter(adapter));
  2092. retval = ZFCP_ERP_FAILED;
  2093. break;
  2094. }
  2095. }
  2096. if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  2097. &adapter->nameserver_port->status)) {
  2098. ZFCP_LOG_DEBUG("nameserver port is not open -> open "
  2099. "nameserver port\n");
  2100. /* nameserver port may live again */
  2101. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
  2102. &adapter->nameserver_port->status);
  2103. if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
  2104. >= 0) {
  2105. erp_action->step =
  2106. ZFCP_ERP_STEP_NAMESERVER_OPEN;
  2107. retval = ZFCP_ERP_CONTINUES;
  2108. } else
  2109. retval = ZFCP_ERP_FAILED;
  2110. break;
  2111. }
  2112. /* else nameserver port is already open, fall through */
  2113. case ZFCP_ERP_STEP_NAMESERVER_OPEN:
  2114. if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
  2115. &adapter->nameserver_port->status)) {
  2116. ZFCP_LOG_DEBUG("open failed for nameserver port\n");
  2117. retval = ZFCP_ERP_FAILED;
  2118. } else {
  2119. ZFCP_LOG_DEBUG("nameserver port is open -> "
  2120. "nameserver look-up for port 0x%016Lx\n",
  2121. port->wwpn);
  2122. retval = zfcp_erp_port_strategy_open_common_lookup
  2123. (erp_action);
  2124. }
  2125. break;
  2126. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  2127. if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
  2128. if (atomic_test_mask
  2129. (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
  2130. ZFCP_LOG_DEBUG("nameserver look-up failed "
  2131. "for port 0x%016Lx "
  2132. "(misconfigured WWPN?)\n",
  2133. port->wwpn);
  2134. zfcp_erp_port_failed(port);
  2135. retval = ZFCP_ERP_EXIT;
  2136. } else {
  2137. ZFCP_LOG_DEBUG("nameserver look-up failed for "
  2138. "port 0x%016Lx\n", port->wwpn);
  2139. retval = ZFCP_ERP_FAILED;
  2140. }
  2141. } else {
  2142. ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
  2143. "trying open\n", port->wwpn, port->d_id);
  2144. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2145. }
  2146. break;
  2147. case ZFCP_ERP_STEP_PORT_OPENING:
  2148. /* D_ID might have changed during open */
  2149. if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
  2150. ZFCP_STATUS_PORT_DID_DID),
  2151. &port->status)) {
  2152. ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
  2153. retval = ZFCP_ERP_SUCCEEDED;
  2154. } else {
  2155. ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
  2156. port->wwpn);
  2157. retval = ZFCP_ERP_FAILED;
  2158. }
  2159. break;
  2160. default:
  2161. ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
  2162. erp_action->step);
  2163. retval = ZFCP_ERP_FAILED;
  2164. }
  2165. return retval;
  2166. }
  2167. static int
  2168. zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
  2169. {
  2170. int retval;
  2171. struct zfcp_port *port = erp_action->port;
  2172. switch (erp_action->step) {
  2173. case ZFCP_ERP_STEP_UNINITIALIZED:
  2174. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2175. case ZFCP_ERP_STEP_PORT_CLOSING:
  2176. ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
  2177. port->wwpn, port->d_id);
  2178. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2179. break;
  2180. case ZFCP_ERP_STEP_PORT_OPENING:
  2181. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2182. ZFCP_LOG_DEBUG("WKA port is open\n");
  2183. retval = ZFCP_ERP_SUCCEEDED;
  2184. } else {
  2185. ZFCP_LOG_DEBUG("open failed for WKA port\n");
  2186. retval = ZFCP_ERP_FAILED;
  2187. }
  2188. /* this is needed anyway (dont care for retval of wakeup) */
  2189. ZFCP_LOG_DEBUG("continue other open port operations\n");
  2190. zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
  2191. break;
  2192. default:
  2193. ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
  2194. erp_action->step);
  2195. retval = ZFCP_ERP_FAILED;
  2196. }
  2197. return retval;
  2198. }
  2199. /*
  2200. * function:
  2201. *
  2202. * purpose: makes the erp thread continue with reopen (physical) port
  2203. * actions which have been paused until the name server port
  2204. * is opened (or failed)
  2205. *
  2206. * returns: 0 (a kind of void retval, its not used)
  2207. */
  2208. static int
  2209. zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
  2210. *ns_erp_action)
  2211. {
  2212. int retval = 0;
  2213. unsigned long flags;
  2214. struct zfcp_adapter *adapter = ns_erp_action->adapter;
  2215. struct zfcp_erp_action *erp_action, *tmp;
  2216. read_lock_irqsave(&adapter->erp_lock, flags);
  2217. list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
  2218. list) {
  2219. debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
  2220. debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
  2221. sizeof (wwn_t));
  2222. if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
  2223. debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
  2224. debug_event(adapter->erp_dbf, 3,
  2225. &erp_action->port->wwpn, sizeof (wwn_t));
  2226. if (atomic_test_mask(
  2227. ZFCP_STATUS_COMMON_ERP_FAILED,
  2228. &adapter->nameserver_port->status))
  2229. zfcp_erp_port_failed(erp_action->port);
  2230. zfcp_erp_action_ready(erp_action);
  2231. }
  2232. }
  2233. read_unlock_irqrestore(&adapter->erp_lock, flags);
  2234. return retval;
  2235. }
  2236. /*
  2237. * function:
  2238. *
  2239. * purpose:
  2240. *
  2241. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2242. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2243. */
  2244. static int
  2245. zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
  2246. {
  2247. int retval;
  2248. struct zfcp_adapter *adapter = erp_action->adapter;
  2249. struct zfcp_port *port = erp_action->port;
  2250. retval = zfcp_fsf_close_physical_port(erp_action);
  2251. if (retval == -ENOMEM) {
  2252. debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
  2253. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2254. retval = ZFCP_ERP_NOMEM;
  2255. goto out;
  2256. }
  2257. erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  2258. if (retval != 0) {
  2259. debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
  2260. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2261. /* could not send 'open', fail */
  2262. retval = ZFCP_ERP_FAILED;
  2263. goto out;
  2264. }
  2265. debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
  2266. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2267. retval = ZFCP_ERP_CONTINUES;
  2268. out:
  2269. return retval;
  2270. }
  2271. static int
  2272. zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  2273. {
  2274. int retval = 0;
  2275. struct zfcp_adapter *adapter = port->adapter;
  2276. debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
  2277. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2278. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  2279. ZFCP_STATUS_COMMON_CLOSING |
  2280. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2281. ZFCP_STATUS_PORT_DID_DID |
  2282. ZFCP_STATUS_PORT_PHYS_CLOSING |
  2283. ZFCP_STATUS_PORT_INVALID_WWPN,
  2284. &port->status);
  2285. return retval;
  2286. }
  2287. /*
  2288. * function:
  2289. *
  2290. * purpose:
  2291. *
  2292. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2293. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2294. */
  2295. static int
  2296. zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  2297. {
  2298. int retval;
  2299. struct zfcp_adapter *adapter = erp_action->adapter;
  2300. struct zfcp_port *port = erp_action->port;
  2301. retval = zfcp_fsf_close_port(erp_action);
  2302. if (retval == -ENOMEM) {
  2303. debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
  2304. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2305. retval = ZFCP_ERP_NOMEM;
  2306. goto out;
  2307. }
  2308. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  2309. if (retval != 0) {
  2310. debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
  2311. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2312. /* could not send 'close', fail */
  2313. retval = ZFCP_ERP_FAILED;
  2314. goto out;
  2315. }
  2316. debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
  2317. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2318. retval = ZFCP_ERP_CONTINUES;
  2319. out:
  2320. return retval;
  2321. }
  2322. /*
  2323. * function:
  2324. *
  2325. * purpose:
  2326. *
  2327. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2328. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2329. */
  2330. static int
  2331. zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  2332. {
  2333. int retval;
  2334. struct zfcp_adapter *adapter = erp_action->adapter;
  2335. struct zfcp_port *port = erp_action->port;
  2336. retval = zfcp_fsf_open_port(erp_action);
  2337. if (retval == -ENOMEM) {
  2338. debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
  2339. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2340. retval = ZFCP_ERP_NOMEM;
  2341. goto out;
  2342. }
  2343. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  2344. if (retval != 0) {
  2345. debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
  2346. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2347. /* could not send 'open', fail */
  2348. retval = ZFCP_ERP_FAILED;
  2349. goto out;
  2350. }
  2351. debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
  2352. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2353. retval = ZFCP_ERP_CONTINUES;
  2354. out:
  2355. return retval;
  2356. }
  2357. /*
  2358. * function:
  2359. *
  2360. * purpose:
  2361. *
  2362. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2363. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2364. */
  2365. static int
  2366. zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
  2367. {
  2368. int retval;
  2369. struct zfcp_adapter *adapter = erp_action->adapter;
  2370. struct zfcp_port *port = erp_action->port;
  2371. retval = zfcp_ns_gid_pn_request(erp_action);
  2372. if (retval == -ENOMEM) {
  2373. debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
  2374. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2375. retval = ZFCP_ERP_NOMEM;
  2376. goto out;
  2377. }
  2378. erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  2379. if (retval != 0) {
  2380. debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
  2381. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2382. /* could not send nameserver request, fail */
  2383. retval = ZFCP_ERP_FAILED;
  2384. goto out;
  2385. }
  2386. debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
  2387. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2388. retval = ZFCP_ERP_CONTINUES;
  2389. out:
  2390. return retval;
  2391. }
  2392. /*
  2393. * function:
  2394. *
  2395. * purpose: this routine executes the 'Reopen Unit' action
  2396. * currently no retries
  2397. *
  2398. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2399. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2400. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2401. */
  2402. static int
  2403. zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  2404. {
  2405. int retval = ZFCP_ERP_FAILED;
  2406. struct zfcp_unit *unit = erp_action->unit;
  2407. struct zfcp_adapter *adapter = erp_action->adapter;
  2408. switch (erp_action->step) {
  2409. /*
  2410. * FIXME:
  2411. * the ULP spec. begs for waiting for oustanding commands
  2412. */
  2413. case ZFCP_ERP_STEP_UNINITIALIZED:
  2414. zfcp_erp_unit_strategy_clearstati(unit);
  2415. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2416. ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
  2417. "trying close\n", unit->fcp_lun);
  2418. retval = zfcp_erp_unit_strategy_close(erp_action);
  2419. break;
  2420. }
  2421. /* else it's already closed, fall through */
  2422. case ZFCP_ERP_STEP_UNIT_CLOSING:
  2423. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2424. ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
  2425. unit->fcp_lun);
  2426. retval = ZFCP_ERP_FAILED;
  2427. } else {
  2428. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  2429. retval = ZFCP_ERP_EXIT;
  2430. else {
  2431. ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
  2432. "trying open\n", unit->fcp_lun);
  2433. retval =
  2434. zfcp_erp_unit_strategy_open(erp_action);
  2435. }
  2436. }
  2437. break;
  2438. case ZFCP_ERP_STEP_UNIT_OPENING:
  2439. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2440. ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
  2441. unit->fcp_lun);
  2442. retval = ZFCP_ERP_SUCCEEDED;
  2443. } else {
  2444. ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
  2445. unit->fcp_lun);
  2446. retval = ZFCP_ERP_FAILED;
  2447. }
  2448. break;
  2449. }
  2450. debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
  2451. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
  2452. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2453. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2454. return retval;
  2455. }
  2456. static int
  2457. zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  2458. {
  2459. int retval = 0;
  2460. struct zfcp_adapter *adapter = unit->port->adapter;
  2461. debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
  2462. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
  2463. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  2464. ZFCP_STATUS_COMMON_CLOSING |
  2465. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2466. ZFCP_STATUS_UNIT_SHARED |
  2467. ZFCP_STATUS_UNIT_READONLY,
  2468. &unit->status);
  2469. return retval;
  2470. }
  2471. /*
  2472. * function:
  2473. *
  2474. * purpose:
  2475. *
  2476. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2477. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2478. */
  2479. static int
  2480. zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  2481. {
  2482. int retval;
  2483. struct zfcp_adapter *adapter = erp_action->adapter;
  2484. struct zfcp_unit *unit = erp_action->unit;
  2485. retval = zfcp_fsf_close_unit(erp_action);
  2486. if (retval == -ENOMEM) {
  2487. debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
  2488. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2489. sizeof (fcp_lun_t));
  2490. retval = ZFCP_ERP_NOMEM;
  2491. goto out;
  2492. }
  2493. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  2494. if (retval != 0) {
  2495. debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
  2496. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2497. sizeof (fcp_lun_t));
  2498. /* could not send 'close', fail */
  2499. retval = ZFCP_ERP_FAILED;
  2500. goto out;
  2501. }
  2502. debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
  2503. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  2504. retval = ZFCP_ERP_CONTINUES;
  2505. out:
  2506. return retval;
  2507. }
  2508. /*
  2509. * function:
  2510. *
  2511. * purpose:
  2512. *
  2513. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2514. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2515. */
  2516. static int
  2517. zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  2518. {
  2519. int retval;
  2520. struct zfcp_adapter *adapter = erp_action->adapter;
  2521. struct zfcp_unit *unit = erp_action->unit;
  2522. retval = zfcp_fsf_open_unit(erp_action);
  2523. if (retval == -ENOMEM) {
  2524. debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
  2525. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2526. sizeof (fcp_lun_t));
  2527. retval = ZFCP_ERP_NOMEM;
  2528. goto out;
  2529. }
  2530. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  2531. if (retval != 0) {
  2532. debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
  2533. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2534. sizeof (fcp_lun_t));
  2535. /* could not send 'open', fail */
  2536. retval = ZFCP_ERP_FAILED;
  2537. goto out;
  2538. }
  2539. debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
  2540. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  2541. retval = ZFCP_ERP_CONTINUES;
  2542. out:
  2543. return retval;
  2544. }
  2545. void zfcp_erp_start_timer(struct zfcp_fsf_req *fsf_req)
  2546. {
  2547. BUG_ON(!fsf_req->erp_action);
  2548. fsf_req->timer.function = zfcp_erp_timeout_handler;
  2549. fsf_req->timer.data = (unsigned long) fsf_req->erp_action;
  2550. fsf_req->timer.expires = jiffies + ZFCP_ERP_FSFREQ_TIMEOUT;
  2551. add_timer(&fsf_req->timer);
  2552. }
  2553. /*
  2554. * function:
  2555. *
  2556. * purpose: enqueue the specified error recovery action, if needed
  2557. *
  2558. * returns:
  2559. */
  2560. static int
  2561. zfcp_erp_action_enqueue(int action,
  2562. struct zfcp_adapter *adapter,
  2563. struct zfcp_port *port, struct zfcp_unit *unit)
  2564. {
  2565. int retval = 1;
  2566. struct zfcp_erp_action *erp_action = NULL;
  2567. int stronger_action = 0;
  2568. u32 status = 0;
  2569. /*
  2570. * We need some rules here which check whether we really need
  2571. * this action or whether we should just drop it.
  2572. * E.g. if there is a unfinished 'Reopen Port' request then we drop a
  2573. * 'Reopen Unit' request for an associated unit since we can't
  2574. * satisfy this request now. A 'Reopen Port' action will trigger
  2575. * 'Reopen Unit' actions when it completes.
  2576. * Thus, there are only actions in the queue which can immediately be
  2577. * executed. This makes the processing of the action queue more
  2578. * efficient.
  2579. */
  2580. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
  2581. &adapter->status))
  2582. return -EIO;
  2583. debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
  2584. /* check whether we really need this */
  2585. switch (action) {
  2586. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2587. if (atomic_test_mask
  2588. (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
  2589. debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
  2590. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2591. sizeof (wwn_t));
  2592. debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
  2593. sizeof (fcp_lun_t));
  2594. goto out;
  2595. }
  2596. if (!atomic_test_mask
  2597. (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
  2598. atomic_test_mask
  2599. (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  2600. goto out;
  2601. }
  2602. if (!atomic_test_mask
  2603. (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
  2604. stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
  2605. unit = NULL;
  2606. }
  2607. /* fall through !!! */
  2608. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2609. if (atomic_test_mask
  2610. (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
  2611. debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
  2612. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2613. sizeof (wwn_t));
  2614. goto out;
  2615. }
  2616. /* fall through !!! */
  2617. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2618. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2619. &port->status)) {
  2620. if (port->erp_action.action !=
  2621. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
  2622. ZFCP_LOG_INFO("dropped erp action %i (port "
  2623. "0x%016Lx, action in use: %i)\n",
  2624. action, port->wwpn,
  2625. port->erp_action.action);
  2626. debug_text_event(adapter->erp_dbf, 4,
  2627. "pf_actenq_drp");
  2628. } else
  2629. debug_text_event(adapter->erp_dbf, 4,
  2630. "pf_actenq_drpcp");
  2631. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2632. sizeof (wwn_t));
  2633. goto out;
  2634. }
  2635. if (!atomic_test_mask
  2636. (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
  2637. atomic_test_mask
  2638. (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
  2639. goto out;
  2640. }
  2641. if (!atomic_test_mask
  2642. (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
  2643. stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  2644. port = NULL;
  2645. }
  2646. /* fall through !!! */
  2647. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2648. if (atomic_test_mask
  2649. (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
  2650. debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
  2651. goto out;
  2652. }
  2653. break;
  2654. default:
  2655. debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
  2656. debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
  2657. ZFCP_LOG_NORMAL("bug: unknown erp action requested "
  2658. "on adapter %s (action=%d)\n",
  2659. zfcp_get_busid_by_adapter(adapter), action);
  2660. goto out;
  2661. }
  2662. /* check whether we need something stronger first */
  2663. if (stronger_action) {
  2664. debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
  2665. debug_event(adapter->erp_dbf, 4, &stronger_action,
  2666. sizeof (int));
  2667. ZFCP_LOG_DEBUG("stronger erp action %d needed before "
  2668. "erp action %d on adapter %s\n",
  2669. stronger_action, action,
  2670. zfcp_get_busid_by_adapter(adapter));
  2671. action = stronger_action;
  2672. }
  2673. /* mark adapter to have some error recovery pending */
  2674. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  2675. /* setup error recovery action */
  2676. switch (action) {
  2677. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2678. zfcp_unit_get(unit);
  2679. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  2680. erp_action = &unit->erp_action;
  2681. if (!atomic_test_mask
  2682. (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
  2683. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2684. break;
  2685. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2686. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2687. zfcp_port_get(port);
  2688. zfcp_erp_action_dismiss_port(port);
  2689. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  2690. erp_action = &port->erp_action;
  2691. if (!atomic_test_mask
  2692. (ZFCP_STATUS_COMMON_RUNNING, &port->status))
  2693. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2694. break;
  2695. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2696. zfcp_adapter_get(adapter);
  2697. zfcp_erp_action_dismiss_adapter(adapter);
  2698. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  2699. erp_action = &adapter->erp_action;
  2700. if (!atomic_test_mask
  2701. (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
  2702. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2703. break;
  2704. }
  2705. debug_text_event(adapter->erp_dbf, 4, "a_actenq");
  2706. memset(erp_action, 0, sizeof (struct zfcp_erp_action));
  2707. erp_action->adapter = adapter;
  2708. erp_action->port = port;
  2709. erp_action->unit = unit;
  2710. erp_action->action = action;
  2711. erp_action->status = status;
  2712. ++adapter->erp_total_count;
  2713. /* finally put it into 'ready' queue and kick erp thread */
  2714. list_add_tail(&erp_action->list, &adapter->erp_ready_head);
  2715. up(&adapter->erp_ready_sem);
  2716. retval = 0;
  2717. out:
  2718. return retval;
  2719. }
  2720. static int
  2721. zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  2722. {
  2723. int retval = 0;
  2724. struct zfcp_adapter *adapter = erp_action->adapter;
  2725. --adapter->erp_total_count;
  2726. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  2727. --adapter->erp_low_mem_count;
  2728. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  2729. }
  2730. debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
  2731. debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
  2732. list_del(&erp_action->list);
  2733. switch (erp_action->action) {
  2734. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2735. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2736. &erp_action->unit->status);
  2737. break;
  2738. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2739. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2740. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2741. &erp_action->port->status);
  2742. break;
  2743. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2744. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2745. &erp_action->adapter->status);
  2746. break;
  2747. default:
  2748. /* bug */
  2749. break;
  2750. }
  2751. return retval;
  2752. }
  2753. /**
  2754. * zfcp_erp_action_cleanup
  2755. *
  2756. * Register unit with scsi stack if appropriate and fix reference counts.
  2757. * Note: Temporary units are not registered with scsi stack.
  2758. */
  2759. static void
  2760. zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
  2761. struct zfcp_port *port, struct zfcp_unit *unit,
  2762. int result)
  2763. {
  2764. switch (action) {
  2765. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2766. if ((result == ZFCP_ERP_SUCCEEDED)
  2767. && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
  2768. &unit->status))
  2769. && !unit->device
  2770. && port->rport) {
  2771. atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
  2772. &unit->status);
  2773. if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
  2774. &unit->status) == 0)
  2775. zfcp_erp_schedule_work(unit);
  2776. }
  2777. zfcp_unit_put(unit);
  2778. break;
  2779. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2780. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2781. if (atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
  2782. &port->status)) {
  2783. zfcp_port_put(port);
  2784. break;
  2785. }
  2786. if ((result == ZFCP_ERP_SUCCEEDED)
  2787. && !port->rport) {
  2788. struct fc_rport_identifiers ids;
  2789. ids.node_name = port->wwnn;
  2790. ids.port_name = port->wwpn;
  2791. ids.port_id = port->d_id;
  2792. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  2793. port->rport =
  2794. fc_remote_port_add(adapter->scsi_host, 0, &ids);
  2795. if (!port->rport)
  2796. ZFCP_LOG_NORMAL("failed registration of rport"
  2797. "(adapter %s, wwpn=0x%016Lx)\n",
  2798. zfcp_get_busid_by_port(port),
  2799. port->wwpn);
  2800. else {
  2801. scsi_target_unblock(&port->rport->dev);
  2802. port->rport->maxframe_size = port->maxframe_size;
  2803. port->rport->supported_classes =
  2804. port->supported_classes;
  2805. }
  2806. }
  2807. if ((result != ZFCP_ERP_SUCCEEDED) && port->rport) {
  2808. fc_remote_port_delete(port->rport);
  2809. port->rport = NULL;
  2810. }
  2811. zfcp_port_put(port);
  2812. break;
  2813. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2814. if (result != ZFCP_ERP_SUCCEEDED) {
  2815. list_for_each_entry(port, &adapter->port_list_head, list)
  2816. if (port->rport &&
  2817. !atomic_test_mask(ZFCP_STATUS_PORT_WKA,
  2818. &port->status)) {
  2819. fc_remote_port_delete(port->rport);
  2820. port->rport = NULL;
  2821. }
  2822. }
  2823. zfcp_adapter_put(adapter);
  2824. break;
  2825. default:
  2826. break;
  2827. }
  2828. }
  2829. static void zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  2830. {
  2831. struct zfcp_port *port;
  2832. debug_text_event(adapter->erp_dbf, 5, "a_actab");
  2833. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
  2834. zfcp_erp_action_dismiss(&adapter->erp_action);
  2835. else
  2836. list_for_each_entry(port, &adapter->port_list_head, list)
  2837. zfcp_erp_action_dismiss_port(port);
  2838. }
  2839. static void zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  2840. {
  2841. struct zfcp_unit *unit;
  2842. struct zfcp_adapter *adapter = port->adapter;
  2843. debug_text_event(adapter->erp_dbf, 5, "p_actab");
  2844. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2845. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
  2846. zfcp_erp_action_dismiss(&port->erp_action);
  2847. else
  2848. list_for_each_entry(unit, &port->unit_list_head, list)
  2849. zfcp_erp_action_dismiss_unit(unit);
  2850. }
  2851. static void zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  2852. {
  2853. struct zfcp_adapter *adapter = unit->port->adapter;
  2854. debug_text_event(adapter->erp_dbf, 5, "u_actab");
  2855. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
  2856. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
  2857. zfcp_erp_action_dismiss(&unit->erp_action);
  2858. }
  2859. static void zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  2860. {
  2861. struct zfcp_adapter *adapter = erp_action->adapter;
  2862. debug_text_event(adapter->erp_dbf, 6, "a_toru");
  2863. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  2864. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  2865. }
  2866. static void zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
  2867. {
  2868. struct zfcp_adapter *adapter = erp_action->adapter;
  2869. debug_text_event(adapter->erp_dbf, 6, "a_tore");
  2870. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  2871. list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
  2872. }
  2873. void
  2874. zfcp_erp_port_boxed(struct zfcp_port *port)
  2875. {
  2876. struct zfcp_adapter *adapter = port->adapter;
  2877. unsigned long flags;
  2878. debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
  2879. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  2880. read_lock_irqsave(&zfcp_data.config_lock, flags);
  2881. zfcp_erp_modify_port_status(port,
  2882. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  2883. ZFCP_SET);
  2884. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  2885. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
  2886. }
  2887. void
  2888. zfcp_erp_unit_boxed(struct zfcp_unit *unit)
  2889. {
  2890. struct zfcp_adapter *adapter = unit->port->adapter;
  2891. debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
  2892. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  2893. zfcp_erp_modify_unit_status(unit,
  2894. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  2895. ZFCP_SET);
  2896. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  2897. }
  2898. void
  2899. zfcp_erp_port_access_denied(struct zfcp_port *port)
  2900. {
  2901. struct zfcp_adapter *adapter = port->adapter;
  2902. unsigned long flags;
  2903. debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
  2904. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  2905. read_lock_irqsave(&zfcp_data.config_lock, flags);
  2906. zfcp_erp_modify_port_status(port,
  2907. ZFCP_STATUS_COMMON_ERP_FAILED |
  2908. ZFCP_STATUS_COMMON_ACCESS_DENIED,
  2909. ZFCP_SET);
  2910. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  2911. }
  2912. void
  2913. zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
  2914. {
  2915. struct zfcp_adapter *adapter = unit->port->adapter;
  2916. debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
  2917. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  2918. zfcp_erp_modify_unit_status(unit,
  2919. ZFCP_STATUS_COMMON_ERP_FAILED |
  2920. ZFCP_STATUS_COMMON_ACCESS_DENIED,
  2921. ZFCP_SET);
  2922. }
  2923. void
  2924. zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
  2925. {
  2926. struct zfcp_port *port;
  2927. unsigned long flags;
  2928. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  2929. return;
  2930. debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
  2931. debug_event(adapter->erp_dbf, 3, zfcp_get_busid_by_adapter(adapter), 8);
  2932. read_lock_irqsave(&zfcp_data.config_lock, flags);
  2933. if (adapter->nameserver_port)
  2934. zfcp_erp_port_access_changed(adapter->nameserver_port);
  2935. list_for_each_entry(port, &adapter->port_list_head, list)
  2936. if (port != adapter->nameserver_port)
  2937. zfcp_erp_port_access_changed(port);
  2938. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  2939. }
  2940. void
  2941. zfcp_erp_port_access_changed(struct zfcp_port *port)
  2942. {
  2943. struct zfcp_adapter *adapter = port->adapter;
  2944. struct zfcp_unit *unit;
  2945. debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
  2946. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  2947. if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
  2948. &port->status) &&
  2949. !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  2950. &port->status)) {
  2951. if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  2952. list_for_each_entry(unit, &port->unit_list_head, list)
  2953. zfcp_erp_unit_access_changed(unit);
  2954. return;
  2955. }
  2956. ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
  2957. "(due to ACT update)\n",
  2958. port->wwpn, zfcp_get_busid_by_adapter(adapter));
  2959. if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
  2960. ZFCP_LOG_NORMAL("failed reopen of port"
  2961. "(adapter %s, wwpn=0x%016Lx)\n",
  2962. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  2963. }
  2964. void
  2965. zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
  2966. {
  2967. struct zfcp_adapter *adapter = unit->port->adapter;
  2968. debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
  2969. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  2970. if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
  2971. &unit->status) &&
  2972. !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  2973. &unit->status))
  2974. return;
  2975. ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
  2976. " on adapter %s (due to ACT update)\n",
  2977. unit->fcp_lun, unit->port->wwpn,
  2978. zfcp_get_busid_by_adapter(adapter));
  2979. if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
  2980. ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
  2981. "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
  2982. zfcp_get_busid_by_adapter(adapter),
  2983. unit->port->wwpn, unit->fcp_lun);
  2984. }
  2985. #undef ZFCP_LOG_AREA