zfcp_erp.c 100 KB

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