zfcp_erp.c 96 KB

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