zfcp_erp.c 98 KB

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