zfcp_erp.c 81 KB

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