zfcp_erp.c 95 KB

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