zfcp_erp.c 86 KB

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