zfcp_erp.c 101 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724
  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. #include "zfcp_ext.h"
  33. static int zfcp_erp_adisc(struct zfcp_port *);
  34. static void zfcp_erp_adisc_handler(unsigned long);
  35. static int zfcp_erp_adapter_reopen_internal(struct zfcp_adapter *, int);
  36. static int zfcp_erp_port_forced_reopen_internal(struct zfcp_port *, int);
  37. static int zfcp_erp_port_reopen_internal(struct zfcp_port *, int);
  38. static int zfcp_erp_unit_reopen_internal(struct zfcp_unit *, int);
  39. static int zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *, int);
  40. static int zfcp_erp_unit_reopen_all_internal(struct zfcp_port *, int);
  41. static void zfcp_erp_adapter_block(struct zfcp_adapter *, int);
  42. static void zfcp_erp_adapter_unblock(struct zfcp_adapter *);
  43. static void zfcp_erp_port_block(struct zfcp_port *, int);
  44. static void zfcp_erp_port_unblock(struct zfcp_port *);
  45. static void zfcp_erp_unit_block(struct zfcp_unit *, int);
  46. static void zfcp_erp_unit_unblock(struct zfcp_unit *);
  47. static int zfcp_erp_thread(void *);
  48. static int zfcp_erp_strategy(struct zfcp_erp_action *);
  49. static int zfcp_erp_strategy_do_action(struct zfcp_erp_action *);
  50. static int zfcp_erp_strategy_memwait(struct zfcp_erp_action *);
  51. static int zfcp_erp_strategy_check_target(struct zfcp_erp_action *, int);
  52. static int zfcp_erp_strategy_check_unit(struct zfcp_unit *, int);
  53. static int zfcp_erp_strategy_check_port(struct zfcp_port *, int);
  54. static int zfcp_erp_strategy_check_adapter(struct zfcp_adapter *, int);
  55. static int zfcp_erp_strategy_statechange(int, u32, struct zfcp_adapter *,
  56. struct zfcp_port *,
  57. struct zfcp_unit *, int);
  58. static inline int zfcp_erp_strategy_statechange_detected(atomic_t *, u32);
  59. static int zfcp_erp_strategy_followup_actions(int, struct zfcp_adapter *,
  60. struct zfcp_port *,
  61. struct zfcp_unit *, int);
  62. static int zfcp_erp_strategy_check_queues(struct zfcp_adapter *);
  63. static int zfcp_erp_strategy_check_action(struct zfcp_erp_action *, int);
  64. static int zfcp_erp_adapter_strategy(struct zfcp_erp_action *);
  65. static int zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *, int);
  66. static int zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *);
  67. static int zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *);
  68. static int zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *);
  69. static int zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *);
  70. static int zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *);
  71. static int zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *);
  72. static int zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *);
  73. static int zfcp_erp_adapter_strategy_open_fsf_xport(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 = fc_host_port_name(adapter->scsi_host);
  296. adisc->wwnn = fc_host_node_name(adapter->scsi_host);
  297. adisc->nport_id = fc_host_port_id(adapter->scsi_host);
  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. adisc->nport_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. u32 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, fc_host_port_id(adapter->scsi_host),
  373. (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
  374. adisc->hard_nport_id, 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 = NULL;
  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 && (fsf_req->erp_action == erp_action)) {
  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. retval = kernel_thread(zfcp_erp_thread, adapter, SIGCHLD);
  933. if (retval < 0) {
  934. ZFCP_LOG_NORMAL("error: creation of erp thread failed for "
  935. "adapter %s\n",
  936. zfcp_get_busid_by_adapter(adapter));
  937. debug_text_event(adapter->erp_dbf, 5, "a_thset_fail");
  938. } else {
  939. wait_event(adapter->erp_thread_wqh,
  940. atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
  941. &adapter->status));
  942. debug_text_event(adapter->erp_dbf, 5, "a_thset_ok");
  943. }
  944. return (retval < 0);
  945. }
  946. /*
  947. * function:
  948. *
  949. * purpose:
  950. *
  951. * returns:
  952. *
  953. * context: process (i.e. proc-fs or rmmod/insmod)
  954. *
  955. * note: The caller of this routine ensures that the specified
  956. * adapter has been shut down and that this operation
  957. * has been completed. Thus, there are no pending erp_actions
  958. * which would need to be handled here.
  959. */
  960. int
  961. zfcp_erp_thread_kill(struct zfcp_adapter *adapter)
  962. {
  963. int retval = 0;
  964. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL, &adapter->status);
  965. up(&adapter->erp_ready_sem);
  966. wait_event(adapter->erp_thread_wqh,
  967. !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
  968. &adapter->status));
  969. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  970. &adapter->status);
  971. debug_text_event(adapter->erp_dbf, 5, "a_thki_ok");
  972. return retval;
  973. }
  974. /*
  975. * purpose: is run as a kernel thread,
  976. * goes through list of error recovery actions of associated adapter
  977. * and delegates single action to execution
  978. *
  979. * returns: 0
  980. */
  981. static int
  982. zfcp_erp_thread(void *data)
  983. {
  984. struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
  985. struct list_head *next;
  986. struct zfcp_erp_action *erp_action;
  987. unsigned long flags;
  988. daemonize("zfcperp%s", zfcp_get_busid_by_adapter(adapter));
  989. /* Block all signals */
  990. siginitsetinv(&current->blocked, 0);
  991. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  992. debug_text_event(adapter->erp_dbf, 5, "a_th_run");
  993. wake_up(&adapter->erp_thread_wqh);
  994. while (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_KILL,
  995. &adapter->status)) {
  996. write_lock_irqsave(&adapter->erp_lock, flags);
  997. next = adapter->erp_ready_head.prev;
  998. write_unlock_irqrestore(&adapter->erp_lock, flags);
  999. if (next != &adapter->erp_ready_head) {
  1000. erp_action =
  1001. list_entry(next, struct zfcp_erp_action, list);
  1002. /*
  1003. * process action (incl. [re]moving it
  1004. * from 'ready' queue)
  1005. */
  1006. zfcp_erp_strategy(erp_action);
  1007. }
  1008. /*
  1009. * sleep as long as there is nothing to do, i.e.
  1010. * no action in 'ready' queue to be processed and
  1011. * thread is not to be killed
  1012. */
  1013. down_interruptible(&adapter->erp_ready_sem);
  1014. debug_text_event(adapter->erp_dbf, 5, "a_th_woken");
  1015. }
  1016. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP, &adapter->status);
  1017. debug_text_event(adapter->erp_dbf, 5, "a_th_stop");
  1018. wake_up(&adapter->erp_thread_wqh);
  1019. return 0;
  1020. }
  1021. /*
  1022. * function:
  1023. *
  1024. * purpose: drives single error recovery action and schedules higher and
  1025. * subordinate actions, if necessary
  1026. *
  1027. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  1028. * ZFCP_ERP_SUCCEEDED - action finished successfully (deqd)
  1029. * ZFCP_ERP_FAILED - action finished unsuccessfully (deqd)
  1030. * ZFCP_ERP_EXIT - action finished (dequeued), offline
  1031. * ZFCP_ERP_DISMISSED - action canceled (dequeued)
  1032. */
  1033. static int
  1034. zfcp_erp_strategy(struct zfcp_erp_action *erp_action)
  1035. {
  1036. int retval = 0;
  1037. struct zfcp_adapter *adapter = erp_action->adapter;
  1038. struct zfcp_port *port = erp_action->port;
  1039. struct zfcp_unit *unit = erp_action->unit;
  1040. int action = erp_action->action;
  1041. u32 status = erp_action->status;
  1042. unsigned long flags;
  1043. /* serialise dismissing, timing out, moving, enqueueing */
  1044. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1045. write_lock(&adapter->erp_lock);
  1046. /* dequeue dismissed action and leave, if required */
  1047. retval = zfcp_erp_strategy_check_action(erp_action, retval);
  1048. if (retval == ZFCP_ERP_DISMISSED) {
  1049. debug_text_event(adapter->erp_dbf, 4, "a_st_dis1");
  1050. goto unlock;
  1051. }
  1052. /*
  1053. * move action to 'running' queue before processing it
  1054. * (to avoid a race condition regarding moving the
  1055. * action to the 'running' queue and back)
  1056. */
  1057. zfcp_erp_action_to_running(erp_action);
  1058. /*
  1059. * try to process action as far as possible,
  1060. * no lock to allow for blocking operations (kmalloc, qdio, ...),
  1061. * afterwards the lock is required again for the following reasons:
  1062. * - dequeueing of finished action and enqueueing of
  1063. * follow-up actions must be atomic so that any other
  1064. * reopen-routine does not believe there is nothing to do
  1065. * and that it is safe to enqueue something else,
  1066. * - we want to force any control thread which is dismissing
  1067. * actions to finish this before we decide about
  1068. * necessary steps to be taken here further
  1069. */
  1070. write_unlock(&adapter->erp_lock);
  1071. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1072. retval = zfcp_erp_strategy_do_action(erp_action);
  1073. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1074. write_lock(&adapter->erp_lock);
  1075. /*
  1076. * check for dismissed status again to avoid follow-up actions,
  1077. * failing of targets and so on for dismissed actions
  1078. */
  1079. retval = zfcp_erp_strategy_check_action(erp_action, retval);
  1080. switch (retval) {
  1081. case ZFCP_ERP_DISMISSED:
  1082. /* leave since this action has ridden to its ancestors */
  1083. debug_text_event(adapter->erp_dbf, 6, "a_st_dis2");
  1084. goto unlock;
  1085. case ZFCP_ERP_NOMEM:
  1086. /* no memory to continue immediately, let it sleep */
  1087. if (!(erp_action->status & ZFCP_STATUS_ERP_LOWMEM)) {
  1088. ++adapter->erp_low_mem_count;
  1089. erp_action->status |= ZFCP_STATUS_ERP_LOWMEM;
  1090. }
  1091. /* This condition is true if there is no memory available
  1092. for any erp_action on this adapter. This implies that there
  1093. are no elements in the memory pool(s) left for erp_actions.
  1094. This might happen if an erp_action that used a memory pool
  1095. element was timed out.
  1096. */
  1097. if (adapter->erp_total_count == adapter->erp_low_mem_count) {
  1098. debug_text_event(adapter->erp_dbf, 3, "a_st_lowmem");
  1099. ZFCP_LOG_NORMAL("error: no mempool elements available, "
  1100. "restarting I/O on adapter %s "
  1101. "to free mempool\n",
  1102. zfcp_get_busid_by_adapter(adapter));
  1103. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1104. } else {
  1105. debug_text_event(adapter->erp_dbf, 2, "a_st_memw");
  1106. retval = zfcp_erp_strategy_memwait(erp_action);
  1107. }
  1108. goto unlock;
  1109. case ZFCP_ERP_CONTINUES:
  1110. /* leave since this action runs asynchronously */
  1111. debug_text_event(adapter->erp_dbf, 6, "a_st_cont");
  1112. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  1113. --adapter->erp_low_mem_count;
  1114. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  1115. }
  1116. goto unlock;
  1117. }
  1118. /* ok, finished action (whatever its result is) */
  1119. /* check for unrecoverable targets */
  1120. retval = zfcp_erp_strategy_check_target(erp_action, retval);
  1121. /* action must be dequeued (here to allow for further ones) */
  1122. zfcp_erp_action_dequeue(erp_action);
  1123. /*
  1124. * put this target through the erp mill again if someone has
  1125. * requested to change the status of a target being online
  1126. * to offline or the other way around
  1127. * (old retval is preserved if nothing has to be done here)
  1128. */
  1129. retval = zfcp_erp_strategy_statechange(action, status, adapter,
  1130. port, unit, retval);
  1131. /*
  1132. * leave if target is in permanent error state or if
  1133. * action is repeated in order to process state change
  1134. */
  1135. if (retval == ZFCP_ERP_EXIT) {
  1136. debug_text_event(adapter->erp_dbf, 2, "a_st_exit");
  1137. goto unlock;
  1138. }
  1139. /* trigger follow up actions */
  1140. zfcp_erp_strategy_followup_actions(action, adapter, port, unit, retval);
  1141. unlock:
  1142. write_unlock(&adapter->erp_lock);
  1143. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1144. if (retval != ZFCP_ERP_CONTINUES)
  1145. zfcp_erp_action_cleanup(action, adapter, port, unit, retval);
  1146. /*
  1147. * a few tasks remain when the erp queues are empty
  1148. * (don't do that if the last action evaluated was dismissed
  1149. * since this clearly indicates that there is more to come) :
  1150. * - close the name server port if it is open yet
  1151. * (enqueues another [probably] final action)
  1152. * - otherwise, wake up whoever wants to be woken when we are
  1153. * done with erp
  1154. */
  1155. if (retval != ZFCP_ERP_DISMISSED)
  1156. zfcp_erp_strategy_check_queues(adapter);
  1157. debug_text_event(adapter->erp_dbf, 6, "a_st_done");
  1158. return retval;
  1159. }
  1160. /*
  1161. * function:
  1162. *
  1163. * purpose:
  1164. *
  1165. * returns: ZFCP_ERP_DISMISSED - if action has been dismissed
  1166. * retval - otherwise
  1167. */
  1168. static int
  1169. zfcp_erp_strategy_check_action(struct zfcp_erp_action *erp_action, int retval)
  1170. {
  1171. struct zfcp_adapter *adapter = erp_action->adapter;
  1172. zfcp_erp_strategy_check_fsfreq(erp_action);
  1173. debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
  1174. if (erp_action->status & ZFCP_STATUS_ERP_DISMISSED) {
  1175. debug_text_event(adapter->erp_dbf, 3, "a_stcd_dis");
  1176. zfcp_erp_action_dequeue(erp_action);
  1177. retval = ZFCP_ERP_DISMISSED;
  1178. } else
  1179. debug_text_event(adapter->erp_dbf, 5, "a_stcd_nodis");
  1180. return retval;
  1181. }
  1182. /*
  1183. * function:
  1184. *
  1185. * purpose:
  1186. *
  1187. * returns:
  1188. */
  1189. static int
  1190. zfcp_erp_strategy_do_action(struct zfcp_erp_action *erp_action)
  1191. {
  1192. int retval = ZFCP_ERP_FAILED;
  1193. struct zfcp_adapter *adapter = erp_action->adapter;
  1194. /*
  1195. * try to execute/continue action as far as possible,
  1196. * note: no lock in subsequent strategy routines
  1197. * (this allows these routine to call schedule, e.g.
  1198. * kmalloc with such flags or qdio_initialize & friends)
  1199. * Note: in case of timeout, the seperate strategies will fail
  1200. * anyhow. No need for a special action. Even worse, a nameserver
  1201. * failure would not wake up waiting ports without the call.
  1202. */
  1203. switch (erp_action->action) {
  1204. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1205. retval = zfcp_erp_adapter_strategy(erp_action);
  1206. break;
  1207. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1208. retval = zfcp_erp_port_forced_strategy(erp_action);
  1209. break;
  1210. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1211. retval = zfcp_erp_port_strategy(erp_action);
  1212. break;
  1213. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1214. retval = zfcp_erp_unit_strategy(erp_action);
  1215. break;
  1216. default:
  1217. debug_text_exception(adapter->erp_dbf, 1, "a_stda_bug");
  1218. debug_event(adapter->erp_dbf, 1, &erp_action->action,
  1219. sizeof (int));
  1220. ZFCP_LOG_NORMAL("bug: unknown erp action requested on "
  1221. "adapter %s (action=%d)\n",
  1222. zfcp_get_busid_by_adapter(erp_action->adapter),
  1223. erp_action->action);
  1224. }
  1225. return retval;
  1226. }
  1227. /*
  1228. * function:
  1229. *
  1230. * purpose: triggers retry of this action after a certain amount of time
  1231. * by means of timer provided by erp_action
  1232. *
  1233. * returns: ZFCP_ERP_CONTINUES - erp_action sleeps in erp running queue
  1234. */
  1235. static int
  1236. zfcp_erp_strategy_memwait(struct zfcp_erp_action *erp_action)
  1237. {
  1238. int retval = ZFCP_ERP_CONTINUES;
  1239. struct zfcp_adapter *adapter = erp_action->adapter;
  1240. debug_text_event(adapter->erp_dbf, 6, "a_mwinit");
  1241. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  1242. init_timer(&erp_action->timer);
  1243. erp_action->timer.function = zfcp_erp_memwait_handler;
  1244. erp_action->timer.data = (unsigned long) erp_action;
  1245. erp_action->timer.expires = jiffies + ZFCP_ERP_MEMWAIT_TIMEOUT;
  1246. add_timer(&erp_action->timer);
  1247. return retval;
  1248. }
  1249. /*
  1250. * function: zfcp_erp_adapter_failed
  1251. *
  1252. * purpose: sets the adapter and all underlying devices to ERP_FAILED
  1253. *
  1254. */
  1255. void
  1256. zfcp_erp_adapter_failed(struct zfcp_adapter *adapter)
  1257. {
  1258. zfcp_erp_modify_adapter_status(adapter,
  1259. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1260. ZFCP_LOG_NORMAL("adapter erp failed on adapter %s\n",
  1261. zfcp_get_busid_by_adapter(adapter));
  1262. debug_text_event(adapter->erp_dbf, 2, "a_afail");
  1263. }
  1264. /*
  1265. * function: zfcp_erp_port_failed
  1266. *
  1267. * purpose: sets the port and all underlying devices to ERP_FAILED
  1268. *
  1269. */
  1270. void
  1271. zfcp_erp_port_failed(struct zfcp_port *port)
  1272. {
  1273. zfcp_erp_modify_port_status(port,
  1274. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1275. if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  1276. ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
  1277. "port d_id=0x%08x)\n",
  1278. zfcp_get_busid_by_port(port), port->d_id);
  1279. else
  1280. ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
  1281. zfcp_get_busid_by_port(port), port->wwpn);
  1282. debug_text_event(port->adapter->erp_dbf, 2, "p_pfail");
  1283. debug_event(port->adapter->erp_dbf, 2, &port->wwpn, sizeof (wwn_t));
  1284. }
  1285. /*
  1286. * function: zfcp_erp_unit_failed
  1287. *
  1288. * purpose: sets the unit to ERP_FAILED
  1289. *
  1290. */
  1291. void
  1292. zfcp_erp_unit_failed(struct zfcp_unit *unit)
  1293. {
  1294. zfcp_erp_modify_unit_status(unit,
  1295. ZFCP_STATUS_COMMON_ERP_FAILED, ZFCP_SET);
  1296. ZFCP_LOG_NORMAL("unit erp failed on unit 0x%016Lx on port 0x%016Lx "
  1297. " on adapter %s\n", unit->fcp_lun,
  1298. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  1299. debug_text_event(unit->port->adapter->erp_dbf, 2, "u_ufail");
  1300. debug_event(unit->port->adapter->erp_dbf, 2,
  1301. &unit->fcp_lun, sizeof (fcp_lun_t));
  1302. }
  1303. /*
  1304. * function: zfcp_erp_strategy_check_target
  1305. *
  1306. * purpose: increments the erp action count on the device currently in
  1307. * recovery if the action failed or resets the count in case of
  1308. * success. If a maximum count is exceeded the device is marked
  1309. * as ERP_FAILED.
  1310. * The 'blocked' state of a target which has been recovered
  1311. * successfully is reset.
  1312. *
  1313. * returns: ZFCP_ERP_CONTINUES - action continues (not considered)
  1314. * ZFCP_ERP_SUCCEEDED - action finished successfully
  1315. * ZFCP_ERP_EXIT - action failed and will not continue
  1316. */
  1317. static int
  1318. zfcp_erp_strategy_check_target(struct zfcp_erp_action *erp_action, int result)
  1319. {
  1320. struct zfcp_adapter *adapter = erp_action->adapter;
  1321. struct zfcp_port *port = erp_action->port;
  1322. struct zfcp_unit *unit = erp_action->unit;
  1323. debug_text_event(adapter->erp_dbf, 5, "a_stct_norm");
  1324. debug_event(adapter->erp_dbf, 5, &erp_action->action, sizeof (int));
  1325. debug_event(adapter->erp_dbf, 5, &result, sizeof (int));
  1326. switch (erp_action->action) {
  1327. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1328. result = zfcp_erp_strategy_check_unit(unit, result);
  1329. break;
  1330. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1331. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1332. result = zfcp_erp_strategy_check_port(port, result);
  1333. break;
  1334. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1335. result = zfcp_erp_strategy_check_adapter(adapter, result);
  1336. break;
  1337. }
  1338. return result;
  1339. }
  1340. /*
  1341. * function:
  1342. *
  1343. * purpose:
  1344. *
  1345. * returns:
  1346. */
  1347. static int
  1348. zfcp_erp_strategy_statechange(int action,
  1349. u32 status,
  1350. struct zfcp_adapter *adapter,
  1351. struct zfcp_port *port,
  1352. struct zfcp_unit *unit, int retval)
  1353. {
  1354. debug_text_event(adapter->erp_dbf, 3, "a_stsc");
  1355. debug_event(adapter->erp_dbf, 3, &action, sizeof (int));
  1356. switch (action) {
  1357. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1358. if (zfcp_erp_strategy_statechange_detected(&adapter->status,
  1359. status)) {
  1360. zfcp_erp_adapter_reopen_internal(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
  1361. retval = ZFCP_ERP_EXIT;
  1362. }
  1363. break;
  1364. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1365. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1366. if (zfcp_erp_strategy_statechange_detected(&port->status,
  1367. status)) {
  1368. zfcp_erp_port_reopen_internal(port, ZFCP_STATUS_COMMON_ERP_FAILED);
  1369. retval = ZFCP_ERP_EXIT;
  1370. }
  1371. break;
  1372. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1373. if (zfcp_erp_strategy_statechange_detected(&unit->status,
  1374. status)) {
  1375. zfcp_erp_unit_reopen_internal(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  1376. retval = ZFCP_ERP_EXIT;
  1377. }
  1378. break;
  1379. }
  1380. return retval;
  1381. }
  1382. /*
  1383. * function:
  1384. *
  1385. * purpose:
  1386. *
  1387. * returns:
  1388. */
  1389. static inline int
  1390. zfcp_erp_strategy_statechange_detected(atomic_t * target_status, u32 erp_status)
  1391. {
  1392. return
  1393. /* take it online */
  1394. (atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
  1395. (ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status)) ||
  1396. /* take it offline */
  1397. (!atomic_test_mask(ZFCP_STATUS_COMMON_RUNNING, target_status) &&
  1398. !(ZFCP_STATUS_ERP_CLOSE_ONLY & erp_status));
  1399. }
  1400. /*
  1401. * function:
  1402. *
  1403. * purpose:
  1404. *
  1405. * returns:
  1406. */
  1407. static int
  1408. zfcp_erp_strategy_check_unit(struct zfcp_unit *unit, int result)
  1409. {
  1410. debug_text_event(unit->port->adapter->erp_dbf, 5, "u_stct");
  1411. debug_event(unit->port->adapter->erp_dbf, 5, &unit->fcp_lun,
  1412. sizeof (fcp_lun_t));
  1413. switch (result) {
  1414. case ZFCP_ERP_SUCCEEDED :
  1415. atomic_set(&unit->erp_counter, 0);
  1416. zfcp_erp_unit_unblock(unit);
  1417. break;
  1418. case ZFCP_ERP_FAILED :
  1419. atomic_inc(&unit->erp_counter);
  1420. if (atomic_read(&unit->erp_counter) > ZFCP_MAX_ERPS)
  1421. zfcp_erp_unit_failed(unit);
  1422. break;
  1423. case ZFCP_ERP_EXIT :
  1424. /* nothing */
  1425. break;
  1426. }
  1427. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) {
  1428. zfcp_erp_unit_block(unit, 0); /* for ZFCP_ERP_SUCCEEDED */
  1429. result = ZFCP_ERP_EXIT;
  1430. }
  1431. return result;
  1432. }
  1433. /*
  1434. * function:
  1435. *
  1436. * purpose:
  1437. *
  1438. * returns:
  1439. */
  1440. static int
  1441. zfcp_erp_strategy_check_port(struct zfcp_port *port, int result)
  1442. {
  1443. debug_text_event(port->adapter->erp_dbf, 5, "p_stct");
  1444. debug_event(port->adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  1445. switch (result) {
  1446. case ZFCP_ERP_SUCCEEDED :
  1447. atomic_set(&port->erp_counter, 0);
  1448. zfcp_erp_port_unblock(port);
  1449. break;
  1450. case ZFCP_ERP_FAILED :
  1451. atomic_inc(&port->erp_counter);
  1452. if (atomic_read(&port->erp_counter) > ZFCP_MAX_ERPS)
  1453. zfcp_erp_port_failed(port);
  1454. break;
  1455. case ZFCP_ERP_EXIT :
  1456. /* nothing */
  1457. break;
  1458. }
  1459. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  1460. zfcp_erp_port_block(port, 0); /* for ZFCP_ERP_SUCCEEDED */
  1461. result = ZFCP_ERP_EXIT;
  1462. }
  1463. return result;
  1464. }
  1465. /*
  1466. * function:
  1467. *
  1468. * purpose:
  1469. *
  1470. * returns:
  1471. */
  1472. static int
  1473. zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
  1474. {
  1475. debug_text_event(adapter->erp_dbf, 5, "a_stct");
  1476. switch (result) {
  1477. case ZFCP_ERP_SUCCEEDED :
  1478. atomic_set(&adapter->erp_counter, 0);
  1479. zfcp_erp_adapter_unblock(adapter);
  1480. break;
  1481. case ZFCP_ERP_FAILED :
  1482. atomic_inc(&adapter->erp_counter);
  1483. if (atomic_read(&adapter->erp_counter) > ZFCP_MAX_ERPS)
  1484. zfcp_erp_adapter_failed(adapter);
  1485. break;
  1486. case ZFCP_ERP_EXIT :
  1487. /* nothing */
  1488. break;
  1489. }
  1490. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
  1491. zfcp_erp_adapter_block(adapter, 0); /* for ZFCP_ERP_SUCCEEDED */
  1492. result = ZFCP_ERP_EXIT;
  1493. }
  1494. return result;
  1495. }
  1496. /*
  1497. * function:
  1498. *
  1499. * purpose: remaining things in good cases,
  1500. * escalation in bad cases
  1501. *
  1502. * returns:
  1503. */
  1504. static int
  1505. zfcp_erp_strategy_followup_actions(int action,
  1506. struct zfcp_adapter *adapter,
  1507. struct zfcp_port *port,
  1508. struct zfcp_unit *unit, int status)
  1509. {
  1510. debug_text_event(adapter->erp_dbf, 5, "a_stfol");
  1511. debug_event(adapter->erp_dbf, 5, &action, sizeof (int));
  1512. /* initiate follow-up actions depending on success of finished action */
  1513. switch (action) {
  1514. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  1515. if (status == ZFCP_ERP_SUCCEEDED)
  1516. zfcp_erp_port_reopen_all_internal(adapter, 0);
  1517. else
  1518. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1519. break;
  1520. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  1521. if (status == ZFCP_ERP_SUCCEEDED)
  1522. zfcp_erp_port_reopen_internal(port, 0);
  1523. else
  1524. zfcp_erp_adapter_reopen_internal(adapter, 0);
  1525. break;
  1526. case ZFCP_ERP_ACTION_REOPEN_PORT:
  1527. if (status == ZFCP_ERP_SUCCEEDED)
  1528. zfcp_erp_unit_reopen_all_internal(port, 0);
  1529. else
  1530. zfcp_erp_port_forced_reopen_internal(port, 0);
  1531. break;
  1532. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  1533. if (status == ZFCP_ERP_SUCCEEDED) ; /* no further action */
  1534. else
  1535. zfcp_erp_port_reopen_internal(unit->port, 0);
  1536. break;
  1537. }
  1538. return 0;
  1539. }
  1540. /*
  1541. * function:
  1542. *
  1543. * purpose:
  1544. *
  1545. * returns:
  1546. */
  1547. static int
  1548. zfcp_erp_strategy_check_queues(struct zfcp_adapter *adapter)
  1549. {
  1550. unsigned long flags;
  1551. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1552. read_lock(&adapter->erp_lock);
  1553. if (list_empty(&adapter->erp_ready_head) &&
  1554. list_empty(&adapter->erp_running_head)) {
  1555. debug_text_event(adapter->erp_dbf, 4, "a_cq_wake");
  1556. atomic_clear_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  1557. &adapter->status);
  1558. wake_up(&adapter->erp_done_wqh);
  1559. } else
  1560. debug_text_event(adapter->erp_dbf, 5, "a_cq_notempty");
  1561. read_unlock(&adapter->erp_lock);
  1562. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1563. return 0;
  1564. }
  1565. /**
  1566. * zfcp_erp_wait - wait for completion of error recovery on an adapter
  1567. * @adapter: adapter for which to wait for completion of its error recovery
  1568. * Return: 0
  1569. */
  1570. int
  1571. zfcp_erp_wait(struct zfcp_adapter *adapter)
  1572. {
  1573. int retval = 0;
  1574. wait_event(adapter->erp_done_wqh,
  1575. !atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING,
  1576. &adapter->status));
  1577. return retval;
  1578. }
  1579. /*
  1580. * function: zfcp_erp_modify_adapter_status
  1581. *
  1582. * purpose:
  1583. *
  1584. */
  1585. void
  1586. zfcp_erp_modify_adapter_status(struct zfcp_adapter *adapter,
  1587. u32 mask, int set_or_clear)
  1588. {
  1589. struct zfcp_port *port;
  1590. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1591. if (set_or_clear == ZFCP_SET) {
  1592. atomic_set_mask(mask, &adapter->status);
  1593. debug_text_event(adapter->erp_dbf, 3, "a_mod_as_s");
  1594. } else {
  1595. atomic_clear_mask(mask, &adapter->status);
  1596. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1597. atomic_set(&adapter->erp_counter, 0);
  1598. debug_text_event(adapter->erp_dbf, 3, "a_mod_as_c");
  1599. }
  1600. debug_event(adapter->erp_dbf, 3, &mask, sizeof (u32));
  1601. /* Deal with all underlying devices, only pass common_mask */
  1602. if (common_mask)
  1603. list_for_each_entry(port, &adapter->port_list_head, list)
  1604. zfcp_erp_modify_port_status(port, common_mask,
  1605. set_or_clear);
  1606. }
  1607. /*
  1608. * function: zfcp_erp_modify_port_status
  1609. *
  1610. * purpose: sets the port and all underlying devices to ERP_FAILED
  1611. *
  1612. */
  1613. void
  1614. zfcp_erp_modify_port_status(struct zfcp_port *port, u32 mask, int set_or_clear)
  1615. {
  1616. struct zfcp_unit *unit;
  1617. u32 common_mask = mask & ZFCP_COMMON_FLAGS;
  1618. if (set_or_clear == ZFCP_SET) {
  1619. atomic_set_mask(mask, &port->status);
  1620. debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_s");
  1621. } else {
  1622. atomic_clear_mask(mask, &port->status);
  1623. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED)
  1624. atomic_set(&port->erp_counter, 0);
  1625. debug_text_event(port->adapter->erp_dbf, 3, "p_mod_ps_c");
  1626. }
  1627. debug_event(port->adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  1628. debug_event(port->adapter->erp_dbf, 3, &mask, sizeof (u32));
  1629. /* Modify status of all underlying devices, only pass common mask */
  1630. if (common_mask)
  1631. list_for_each_entry(unit, &port->unit_list_head, list)
  1632. zfcp_erp_modify_unit_status(unit, common_mask,
  1633. set_or_clear);
  1634. }
  1635. /*
  1636. * function: zfcp_erp_modify_unit_status
  1637. *
  1638. * purpose: sets the unit to ERP_FAILED
  1639. *
  1640. */
  1641. void
  1642. zfcp_erp_modify_unit_status(struct zfcp_unit *unit, u32 mask, int set_or_clear)
  1643. {
  1644. if (set_or_clear == ZFCP_SET) {
  1645. atomic_set_mask(mask, &unit->status);
  1646. debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_s");
  1647. } else {
  1648. atomic_clear_mask(mask, &unit->status);
  1649. if (mask & ZFCP_STATUS_COMMON_ERP_FAILED) {
  1650. atomic_set(&unit->erp_counter, 0);
  1651. }
  1652. debug_text_event(unit->port->adapter->erp_dbf, 3, "u_mod_us_c");
  1653. }
  1654. debug_event(unit->port->adapter->erp_dbf, 3, &unit->fcp_lun,
  1655. sizeof (fcp_lun_t));
  1656. debug_event(unit->port->adapter->erp_dbf, 3, &mask, sizeof (u32));
  1657. }
  1658. /*
  1659. * function:
  1660. *
  1661. * purpose: Wrappper for zfcp_erp_port_reopen_all_internal
  1662. * used to ensure the correct locking
  1663. *
  1664. * returns: 0 - initiated action succesfully
  1665. * <0 - failed to initiate action
  1666. */
  1667. int
  1668. zfcp_erp_port_reopen_all(struct zfcp_adapter *adapter, int clear_mask)
  1669. {
  1670. int retval;
  1671. unsigned long flags;
  1672. read_lock_irqsave(&zfcp_data.config_lock, flags);
  1673. write_lock(&adapter->erp_lock);
  1674. retval = zfcp_erp_port_reopen_all_internal(adapter, clear_mask);
  1675. write_unlock(&adapter->erp_lock);
  1676. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  1677. return retval;
  1678. }
  1679. /*
  1680. * function:
  1681. *
  1682. * purpose:
  1683. *
  1684. * returns: FIXME
  1685. */
  1686. static int
  1687. zfcp_erp_port_reopen_all_internal(struct zfcp_adapter *adapter, int clear_mask)
  1688. {
  1689. int retval = 0;
  1690. struct zfcp_port *port;
  1691. list_for_each_entry(port, &adapter->port_list_head, list)
  1692. if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  1693. zfcp_erp_port_reopen_internal(port, clear_mask);
  1694. return retval;
  1695. }
  1696. /*
  1697. * function:
  1698. *
  1699. * purpose:
  1700. *
  1701. * returns: FIXME
  1702. */
  1703. static int
  1704. zfcp_erp_unit_reopen_all_internal(struct zfcp_port *port, int clear_mask)
  1705. {
  1706. int retval = 0;
  1707. struct zfcp_unit *unit;
  1708. list_for_each_entry(unit, &port->unit_list_head, list)
  1709. zfcp_erp_unit_reopen_internal(unit, clear_mask);
  1710. return retval;
  1711. }
  1712. /*
  1713. * function:
  1714. *
  1715. * purpose: this routine executes the 'Reopen Adapter' action
  1716. * (the entire action is processed synchronously, since
  1717. * there are no actions which might be run concurrently
  1718. * per definition)
  1719. *
  1720. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1721. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1722. */
  1723. static int
  1724. zfcp_erp_adapter_strategy(struct zfcp_erp_action *erp_action)
  1725. {
  1726. int retval;
  1727. struct zfcp_adapter *adapter = erp_action->adapter;
  1728. retval = zfcp_erp_adapter_strategy_close(erp_action);
  1729. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  1730. retval = ZFCP_ERP_EXIT;
  1731. else
  1732. retval = zfcp_erp_adapter_strategy_open(erp_action);
  1733. debug_text_event(adapter->erp_dbf, 3, "a_ast/ret");
  1734. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  1735. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  1736. if (retval == ZFCP_ERP_FAILED) {
  1737. ZFCP_LOG_INFO("Waiting to allow the adapter %s "
  1738. "to recover itself\n",
  1739. zfcp_get_busid_by_adapter(adapter));
  1740. msleep(jiffies_to_msecs(ZFCP_TYPE2_RECOVERY_TIME));
  1741. }
  1742. return retval;
  1743. }
  1744. /*
  1745. * function:
  1746. *
  1747. * purpose:
  1748. *
  1749. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1750. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1751. */
  1752. static int
  1753. zfcp_erp_adapter_strategy_close(struct zfcp_erp_action *erp_action)
  1754. {
  1755. int retval;
  1756. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING,
  1757. &erp_action->adapter->status);
  1758. retval = zfcp_erp_adapter_strategy_generic(erp_action, 1);
  1759. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING,
  1760. &erp_action->adapter->status);
  1761. return retval;
  1762. }
  1763. /*
  1764. * function:
  1765. *
  1766. * purpose:
  1767. *
  1768. * returns: ZFCP_ERP_SUCCEEDED - action finished successfully
  1769. * ZFCP_ERP_FAILED - action finished unsuccessfully
  1770. */
  1771. static int
  1772. zfcp_erp_adapter_strategy_open(struct zfcp_erp_action *erp_action)
  1773. {
  1774. int retval;
  1775. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING,
  1776. &erp_action->adapter->status);
  1777. retval = zfcp_erp_adapter_strategy_generic(erp_action, 0);
  1778. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING,
  1779. &erp_action->adapter->status);
  1780. return retval;
  1781. }
  1782. /*
  1783. * function: zfcp_register_adapter
  1784. *
  1785. * purpose: allocate the irq associated with this devno and register
  1786. * the FSF adapter with the SCSI stack
  1787. *
  1788. * returns:
  1789. */
  1790. static int
  1791. zfcp_erp_adapter_strategy_generic(struct zfcp_erp_action *erp_action, int close)
  1792. {
  1793. int retval = ZFCP_ERP_SUCCEEDED;
  1794. if (close)
  1795. goto close_only;
  1796. retval = zfcp_erp_adapter_strategy_open_qdio(erp_action);
  1797. if (retval != ZFCP_ERP_SUCCEEDED)
  1798. goto failed_qdio;
  1799. retval = zfcp_erp_adapter_strategy_open_fsf(erp_action);
  1800. if (retval != ZFCP_ERP_SUCCEEDED)
  1801. goto failed_openfcp;
  1802. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &erp_action->adapter->status);
  1803. goto out;
  1804. close_only:
  1805. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  1806. &erp_action->adapter->status);
  1807. failed_openfcp:
  1808. zfcp_erp_adapter_strategy_close_qdio(erp_action);
  1809. zfcp_erp_adapter_strategy_close_fsf(erp_action);
  1810. failed_qdio:
  1811. out:
  1812. return retval;
  1813. }
  1814. /*
  1815. * function: zfcp_qdio_init
  1816. *
  1817. * purpose: setup QDIO operation for specified adapter
  1818. *
  1819. * returns: 0 - successful setup
  1820. * !0 - failed setup
  1821. */
  1822. int
  1823. zfcp_erp_adapter_strategy_open_qdio(struct zfcp_erp_action *erp_action)
  1824. {
  1825. int retval;
  1826. int i;
  1827. volatile struct qdio_buffer_element *sbale;
  1828. struct zfcp_adapter *adapter = erp_action->adapter;
  1829. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  1830. ZFCP_LOG_NORMAL("bug: second attempt to set up QDIO on "
  1831. "adapter %s\n",
  1832. zfcp_get_busid_by_adapter(adapter));
  1833. goto failed_sanity;
  1834. }
  1835. if (qdio_establish(&adapter->qdio_init_data) != 0) {
  1836. ZFCP_LOG_INFO("error: establishment of QDIO queues failed "
  1837. "on adapter %s\n",
  1838. zfcp_get_busid_by_adapter(adapter));
  1839. goto failed_qdio_establish;
  1840. }
  1841. debug_text_event(adapter->erp_dbf, 3, "qdio_est");
  1842. if (qdio_activate(adapter->ccw_device, 0) != 0) {
  1843. ZFCP_LOG_INFO("error: activation of QDIO queues failed "
  1844. "on adapter %s\n",
  1845. zfcp_get_busid_by_adapter(adapter));
  1846. goto failed_qdio_activate;
  1847. }
  1848. debug_text_event(adapter->erp_dbf, 3, "qdio_act");
  1849. /*
  1850. * put buffers into response queue,
  1851. */
  1852. for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; i++) {
  1853. sbale = &(adapter->response_queue.buffer[i]->element[0]);
  1854. sbale->length = 0;
  1855. sbale->flags = SBAL_FLAGS_LAST_ENTRY;
  1856. sbale->addr = 0;
  1857. }
  1858. ZFCP_LOG_TRACE("calling do_QDIO on adapter %s (flags=0x%x, "
  1859. "queue_no=%i, index_in_queue=%i, count=%i)\n",
  1860. zfcp_get_busid_by_adapter(adapter),
  1861. QDIO_FLAG_SYNC_INPUT, 0, 0, QDIO_MAX_BUFFERS_PER_Q);
  1862. retval = do_QDIO(adapter->ccw_device,
  1863. QDIO_FLAG_SYNC_INPUT,
  1864. 0, 0, QDIO_MAX_BUFFERS_PER_Q, NULL);
  1865. if (retval) {
  1866. ZFCP_LOG_NORMAL("bug: setup of QDIO failed (retval=%d)\n",
  1867. retval);
  1868. goto failed_do_qdio;
  1869. } else {
  1870. adapter->response_queue.free_index = 0;
  1871. atomic_set(&adapter->response_queue.free_count, 0);
  1872. ZFCP_LOG_DEBUG("%i buffers successfully enqueued to "
  1873. "response queue\n", QDIO_MAX_BUFFERS_PER_Q);
  1874. }
  1875. /* set index of first avalable SBALS / number of available SBALS */
  1876. adapter->request_queue.free_index = 0;
  1877. atomic_set(&adapter->request_queue.free_count, QDIO_MAX_BUFFERS_PER_Q);
  1878. adapter->request_queue.distance_from_int = 0;
  1879. /* initialize waitqueue used to wait for free SBALs in requests queue */
  1880. init_waitqueue_head(&adapter->request_wq);
  1881. /* ok, we did it - skip all cleanups for different failures */
  1882. atomic_set_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
  1883. retval = ZFCP_ERP_SUCCEEDED;
  1884. goto out;
  1885. failed_do_qdio:
  1886. /* NOP */
  1887. failed_qdio_activate:
  1888. debug_text_event(adapter->erp_dbf, 3, "qdio_down1a");
  1889. while (qdio_shutdown(adapter->ccw_device,
  1890. QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
  1891. msleep(1000);
  1892. debug_text_event(adapter->erp_dbf, 3, "qdio_down1b");
  1893. failed_qdio_establish:
  1894. failed_sanity:
  1895. retval = ZFCP_ERP_FAILED;
  1896. out:
  1897. return retval;
  1898. }
  1899. /*
  1900. * function: zfcp_qdio_cleanup
  1901. *
  1902. * purpose: cleans up QDIO operation for the specified adapter
  1903. *
  1904. * returns: 0 - successful cleanup
  1905. * !0 - failed cleanup
  1906. */
  1907. int
  1908. zfcp_erp_adapter_strategy_close_qdio(struct zfcp_erp_action *erp_action)
  1909. {
  1910. int retval = ZFCP_ERP_SUCCEEDED;
  1911. int first_used;
  1912. int used_count;
  1913. struct zfcp_adapter *adapter = erp_action->adapter;
  1914. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  1915. ZFCP_LOG_DEBUG("error: attempt to shut down inactive QDIO "
  1916. "queues on adapter %s\n",
  1917. zfcp_get_busid_by_adapter(adapter));
  1918. retval = ZFCP_ERP_FAILED;
  1919. goto out;
  1920. }
  1921. /*
  1922. * Get queue_lock and clear QDIOUP flag. Thus it's guaranteed that
  1923. * do_QDIO won't be called while qdio_shutdown is in progress.
  1924. */
  1925. write_lock_irq(&adapter->request_queue.queue_lock);
  1926. atomic_clear_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status);
  1927. write_unlock_irq(&adapter->request_queue.queue_lock);
  1928. debug_text_event(adapter->erp_dbf, 3, "qdio_down2a");
  1929. while (qdio_shutdown(adapter->ccw_device,
  1930. QDIO_FLAG_CLEANUP_USING_CLEAR) == -EINPROGRESS)
  1931. msleep(1000);
  1932. debug_text_event(adapter->erp_dbf, 3, "qdio_down2b");
  1933. /*
  1934. * First we had to stop QDIO operation.
  1935. * Now it is safe to take the following actions.
  1936. */
  1937. /* Cleanup only necessary when there are unacknowledged buffers */
  1938. if (atomic_read(&adapter->request_queue.free_count)
  1939. < QDIO_MAX_BUFFERS_PER_Q) {
  1940. first_used = (adapter->request_queue.free_index +
  1941. atomic_read(&adapter->request_queue.free_count))
  1942. % QDIO_MAX_BUFFERS_PER_Q;
  1943. used_count = QDIO_MAX_BUFFERS_PER_Q -
  1944. atomic_read(&adapter->request_queue.free_count);
  1945. zfcp_qdio_zero_sbals(adapter->request_queue.buffer,
  1946. first_used, used_count);
  1947. }
  1948. adapter->response_queue.free_index = 0;
  1949. atomic_set(&adapter->response_queue.free_count, 0);
  1950. adapter->request_queue.free_index = 0;
  1951. atomic_set(&adapter->request_queue.free_count, 0);
  1952. adapter->request_queue.distance_from_int = 0;
  1953. out:
  1954. return retval;
  1955. }
  1956. static int
  1957. zfcp_erp_adapter_strategy_open_fsf(struct zfcp_erp_action *erp_action)
  1958. {
  1959. int retval;
  1960. if ((atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  1961. &erp_action->adapter->status)) &&
  1962. (erp_action->adapter->adapter_features &
  1963. FSF_FEATURE_HBAAPI_MANAGEMENT)) {
  1964. zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
  1965. atomic_set(&erp_action->adapter->erp_counter, 0);
  1966. return ZFCP_ERP_FAILED;
  1967. }
  1968. retval = zfcp_erp_adapter_strategy_open_fsf_xconfig(erp_action);
  1969. if (retval == ZFCP_ERP_FAILED)
  1970. return ZFCP_ERP_FAILED;
  1971. retval = zfcp_erp_adapter_strategy_open_fsf_xport(erp_action);
  1972. if (retval == ZFCP_ERP_FAILED)
  1973. return ZFCP_ERP_FAILED;
  1974. return zfcp_erp_adapter_strategy_open_fsf_statusread(erp_action);
  1975. }
  1976. /*
  1977. * function:
  1978. *
  1979. * purpose:
  1980. *
  1981. * returns:
  1982. */
  1983. static int
  1984. zfcp_erp_adapter_strategy_open_fsf_xconfig(struct zfcp_erp_action *erp_action)
  1985. {
  1986. int retval = ZFCP_ERP_SUCCEEDED;
  1987. int retries;
  1988. int sleep = ZFCP_EXCHANGE_CONFIG_DATA_FIRST_SLEEP;
  1989. struct zfcp_adapter *adapter = erp_action->adapter;
  1990. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK, &adapter->status);
  1991. for (retries = ZFCP_EXCHANGE_CONFIG_DATA_RETRIES; retries; retries--) {
  1992. atomic_clear_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  1993. &adapter->status);
  1994. ZFCP_LOG_DEBUG("Doing exchange config data\n");
  1995. write_lock(&adapter->erp_lock);
  1996. zfcp_erp_action_to_running(erp_action);
  1997. write_unlock(&adapter->erp_lock);
  1998. zfcp_erp_timeout_init(erp_action);
  1999. if (zfcp_fsf_exchange_config_data(erp_action)) {
  2000. retval = ZFCP_ERP_FAILED;
  2001. debug_text_event(adapter->erp_dbf, 5, "a_fstx_xf");
  2002. ZFCP_LOG_INFO("error: initiation of exchange of "
  2003. "configuration data failed for "
  2004. "adapter %s\n",
  2005. zfcp_get_busid_by_adapter(adapter));
  2006. break;
  2007. }
  2008. debug_text_event(adapter->erp_dbf, 6, "a_fstx_xok");
  2009. ZFCP_LOG_DEBUG("Xchange underway\n");
  2010. /*
  2011. * Why this works:
  2012. * Both the normal completion handler as well as the timeout
  2013. * handler will do an 'up' when the 'exchange config data'
  2014. * request completes or times out. Thus, the signal to go on
  2015. * won't be lost utilizing this semaphore.
  2016. * Furthermore, this 'adapter_reopen' action is
  2017. * guaranteed to be the only action being there (highest action
  2018. * which prevents other actions from being created).
  2019. * Resulting from that, the wake signal recognized here
  2020. * _must_ be the one belonging to the 'exchange config
  2021. * data' request.
  2022. */
  2023. down(&adapter->erp_ready_sem);
  2024. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
  2025. ZFCP_LOG_INFO("error: exchange of configuration data "
  2026. "for adapter %s timed out\n",
  2027. zfcp_get_busid_by_adapter(adapter));
  2028. break;
  2029. }
  2030. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  2031. &adapter->status))
  2032. break;
  2033. ZFCP_LOG_DEBUG("host connection still initialising... "
  2034. "waiting and retrying...\n");
  2035. /* sleep a little bit before retry */
  2036. msleep(jiffies_to_msecs(sleep));
  2037. sleep *= 2;
  2038. }
  2039. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  2040. &adapter->status)) {
  2041. ZFCP_LOG_INFO("error: exchange of configuration data for "
  2042. "adapter %s failed\n",
  2043. zfcp_get_busid_by_adapter(adapter));
  2044. retval = ZFCP_ERP_FAILED;
  2045. }
  2046. return retval;
  2047. }
  2048. static int
  2049. zfcp_erp_adapter_strategy_open_fsf_xport(struct zfcp_erp_action *erp_action)
  2050. {
  2051. int ret;
  2052. int retries;
  2053. int sleep;
  2054. struct zfcp_adapter *adapter = erp_action->adapter;
  2055. atomic_clear_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2056. retries = 0;
  2057. do {
  2058. write_lock(&adapter->erp_lock);
  2059. zfcp_erp_action_to_running(erp_action);
  2060. write_unlock(&adapter->erp_lock);
  2061. zfcp_erp_timeout_init(erp_action);
  2062. ret = zfcp_fsf_exchange_port_data(erp_action, adapter, NULL);
  2063. if (ret == -EOPNOTSUPP) {
  2064. debug_text_event(adapter->erp_dbf, 3, "a_xport_notsupp");
  2065. return ZFCP_ERP_SUCCEEDED;
  2066. } else if (ret) {
  2067. debug_text_event(adapter->erp_dbf, 3, "a_xport_failed");
  2068. return ZFCP_ERP_FAILED;
  2069. }
  2070. debug_text_event(adapter->erp_dbf, 6, "a_xport_ok");
  2071. down(&adapter->erp_ready_sem);
  2072. if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
  2073. ZFCP_LOG_INFO("error: exchange of port data "
  2074. "for adapter %s timed out\n",
  2075. zfcp_get_busid_by_adapter(adapter));
  2076. break;
  2077. }
  2078. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  2079. &adapter->status))
  2080. break;
  2081. if (retries < ZFCP_EXCHANGE_PORT_DATA_SHORT_RETRIES) {
  2082. sleep = ZFCP_EXCHANGE_PORT_DATA_SHORT_SLEEP;
  2083. retries++;
  2084. } else
  2085. sleep = ZFCP_EXCHANGE_PORT_DATA_LONG_SLEEP;
  2086. schedule_timeout(sleep);
  2087. } while (1);
  2088. return ZFCP_ERP_SUCCEEDED;
  2089. }
  2090. /*
  2091. * function:
  2092. *
  2093. * purpose:
  2094. *
  2095. * returns:
  2096. */
  2097. static int
  2098. zfcp_erp_adapter_strategy_open_fsf_statusread(struct zfcp_erp_action
  2099. *erp_action)
  2100. {
  2101. int retval = ZFCP_ERP_SUCCEEDED;
  2102. int temp_ret;
  2103. struct zfcp_adapter *adapter = erp_action->adapter;
  2104. int i;
  2105. adapter->status_read_failed = 0;
  2106. for (i = 0; i < ZFCP_STATUS_READS_RECOM; i++) {
  2107. temp_ret = zfcp_fsf_status_read(adapter, ZFCP_WAIT_FOR_SBAL);
  2108. if (temp_ret < 0) {
  2109. ZFCP_LOG_INFO("error: set-up of unsolicited status "
  2110. "notification failed on adapter %s\n",
  2111. zfcp_get_busid_by_adapter(adapter));
  2112. retval = ZFCP_ERP_FAILED;
  2113. i--;
  2114. break;
  2115. }
  2116. }
  2117. return retval;
  2118. }
  2119. /*
  2120. * function: zfcp_fsf_cleanup
  2121. *
  2122. * purpose: cleanup FSF operation for specified adapter
  2123. *
  2124. * returns: 0 - FSF operation successfully cleaned up
  2125. * !0 - failed to cleanup FSF operation for this adapter
  2126. */
  2127. static int
  2128. zfcp_erp_adapter_strategy_close_fsf(struct zfcp_erp_action *erp_action)
  2129. {
  2130. int retval = ZFCP_ERP_SUCCEEDED;
  2131. struct zfcp_adapter *adapter = erp_action->adapter;
  2132. /*
  2133. * wake waiting initiators of requests,
  2134. * return SCSI commands (with error status),
  2135. * clean up all requests (synchronously)
  2136. */
  2137. zfcp_fsf_req_dismiss_all(adapter);
  2138. /* reset FSF request sequence number */
  2139. adapter->fsf_req_seq_no = 0;
  2140. /* all ports and units are closed */
  2141. zfcp_erp_modify_adapter_status(adapter,
  2142. ZFCP_STATUS_COMMON_OPEN, ZFCP_CLEAR);
  2143. return retval;
  2144. }
  2145. /*
  2146. * function:
  2147. *
  2148. * purpose: this routine executes the 'Reopen Physical Port' action
  2149. *
  2150. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2151. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2152. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2153. */
  2154. static int
  2155. zfcp_erp_port_forced_strategy(struct zfcp_erp_action *erp_action)
  2156. {
  2157. int retval = ZFCP_ERP_FAILED;
  2158. struct zfcp_port *port = erp_action->port;
  2159. struct zfcp_adapter *adapter = erp_action->adapter;
  2160. switch (erp_action->step) {
  2161. /*
  2162. * FIXME:
  2163. * the ULP spec. begs for waiting for oustanding commands
  2164. */
  2165. case ZFCP_ERP_STEP_UNINITIALIZED:
  2166. zfcp_erp_port_strategy_clearstati(port);
  2167. /*
  2168. * it would be sufficient to test only the normal open flag
  2169. * since the phys. open flag cannot be set if the normal
  2170. * open flag is unset - however, this is for readabilty ...
  2171. */
  2172. if (atomic_test_mask((ZFCP_STATUS_PORT_PHYS_OPEN |
  2173. ZFCP_STATUS_COMMON_OPEN),
  2174. &port->status)) {
  2175. ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
  2176. "close physical\n", port->wwpn);
  2177. retval =
  2178. zfcp_erp_port_forced_strategy_close(erp_action);
  2179. } else
  2180. retval = ZFCP_ERP_FAILED;
  2181. break;
  2182. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2183. if (atomic_test_mask(ZFCP_STATUS_PORT_PHYS_OPEN,
  2184. &port->status)) {
  2185. ZFCP_LOG_DEBUG("close physical failed for port "
  2186. "0x%016Lx\n", port->wwpn);
  2187. retval = ZFCP_ERP_FAILED;
  2188. } else
  2189. retval = ZFCP_ERP_SUCCEEDED;
  2190. break;
  2191. }
  2192. debug_text_event(adapter->erp_dbf, 3, "p_pfst/ret");
  2193. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  2194. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2195. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2196. return retval;
  2197. }
  2198. /*
  2199. * function:
  2200. *
  2201. * purpose: this routine executes the 'Reopen Port' action
  2202. *
  2203. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2204. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2205. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2206. */
  2207. static int
  2208. zfcp_erp_port_strategy(struct zfcp_erp_action *erp_action)
  2209. {
  2210. int retval = ZFCP_ERP_FAILED;
  2211. struct zfcp_port *port = erp_action->port;
  2212. struct zfcp_adapter *adapter = erp_action->adapter;
  2213. switch (erp_action->step) {
  2214. /*
  2215. * FIXME:
  2216. * the ULP spec. begs for waiting for oustanding commands
  2217. */
  2218. case ZFCP_ERP_STEP_UNINITIALIZED:
  2219. zfcp_erp_port_strategy_clearstati(port);
  2220. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2221. ZFCP_LOG_DEBUG("port 0x%016Lx is open -> trying "
  2222. "close\n", port->wwpn);
  2223. retval = zfcp_erp_port_strategy_close(erp_action);
  2224. goto out;
  2225. } /* else it's already closed, open it */
  2226. break;
  2227. case ZFCP_ERP_STEP_PORT_CLOSING:
  2228. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2229. ZFCP_LOG_DEBUG("close failed for port 0x%016Lx\n",
  2230. port->wwpn);
  2231. retval = ZFCP_ERP_FAILED;
  2232. goto out;
  2233. } /* else it's closed now, open it */
  2234. break;
  2235. }
  2236. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  2237. retval = ZFCP_ERP_EXIT;
  2238. else
  2239. retval = zfcp_erp_port_strategy_open(erp_action);
  2240. out:
  2241. debug_text_event(adapter->erp_dbf, 3, "p_pst/ret");
  2242. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof (wwn_t));
  2243. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2244. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2245. return retval;
  2246. }
  2247. /*
  2248. * function:
  2249. *
  2250. * purpose:
  2251. *
  2252. * returns:
  2253. */
  2254. static int
  2255. zfcp_erp_port_strategy_open(struct zfcp_erp_action *erp_action)
  2256. {
  2257. int retval;
  2258. if (atomic_test_mask(ZFCP_STATUS_PORT_WKA,
  2259. &erp_action->port->status))
  2260. retval = zfcp_erp_port_strategy_open_nameserver(erp_action);
  2261. else
  2262. retval = zfcp_erp_port_strategy_open_common(erp_action);
  2263. return retval;
  2264. }
  2265. /*
  2266. * function:
  2267. *
  2268. * purpose:
  2269. *
  2270. * returns:
  2271. *
  2272. * FIXME(design): currently only prepared for fabric (nameserver!)
  2273. */
  2274. static int
  2275. zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
  2276. {
  2277. int retval = 0;
  2278. struct zfcp_adapter *adapter = erp_action->adapter;
  2279. struct zfcp_port *port = erp_action->port;
  2280. switch (erp_action->step) {
  2281. case ZFCP_ERP_STEP_UNINITIALIZED:
  2282. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2283. case ZFCP_ERP_STEP_PORT_CLOSING:
  2284. if (fc_host_port_type(adapter->scsi_host) == FC_PORTTYPE_PTP) {
  2285. if (port->wwpn != adapter->peer_wwpn) {
  2286. ZFCP_LOG_NORMAL("Failed to open port 0x%016Lx "
  2287. "on adapter %s.\nPeer WWPN "
  2288. "0x%016Lx does not match\n",
  2289. port->wwpn,
  2290. zfcp_get_busid_by_adapter(adapter),
  2291. adapter->peer_wwpn);
  2292. zfcp_erp_port_failed(port);
  2293. retval = ZFCP_ERP_FAILED;
  2294. break;
  2295. }
  2296. port->d_id = adapter->peer_d_id;
  2297. atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
  2298. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2299. break;
  2300. }
  2301. if (!(adapter->nameserver_port)) {
  2302. retval = zfcp_nameserver_enqueue(adapter);
  2303. if (retval != 0) {
  2304. ZFCP_LOG_NORMAL("error: nameserver port "
  2305. "unavailable for adapter %s\n",
  2306. zfcp_get_busid_by_adapter(adapter));
  2307. retval = ZFCP_ERP_FAILED;
  2308. break;
  2309. }
  2310. }
  2311. if (!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  2312. &adapter->nameserver_port->status)) {
  2313. ZFCP_LOG_DEBUG("nameserver port is not open -> open "
  2314. "nameserver port\n");
  2315. /* nameserver port may live again */
  2316. atomic_set_mask(ZFCP_STATUS_COMMON_RUNNING,
  2317. &adapter->nameserver_port->status);
  2318. if (zfcp_erp_port_reopen(adapter->nameserver_port, 0)
  2319. >= 0) {
  2320. erp_action->step =
  2321. ZFCP_ERP_STEP_NAMESERVER_OPEN;
  2322. retval = ZFCP_ERP_CONTINUES;
  2323. } else
  2324. retval = ZFCP_ERP_FAILED;
  2325. break;
  2326. }
  2327. /* else nameserver port is already open, fall through */
  2328. case ZFCP_ERP_STEP_NAMESERVER_OPEN:
  2329. if (!atomic_test_mask(ZFCP_STATUS_COMMON_OPEN,
  2330. &adapter->nameserver_port->status)) {
  2331. ZFCP_LOG_DEBUG("open failed for nameserver port\n");
  2332. retval = ZFCP_ERP_FAILED;
  2333. } else {
  2334. ZFCP_LOG_DEBUG("nameserver port is open -> "
  2335. "nameserver look-up for port 0x%016Lx\n",
  2336. port->wwpn);
  2337. retval = zfcp_erp_port_strategy_open_common_lookup
  2338. (erp_action);
  2339. }
  2340. break;
  2341. case ZFCP_ERP_STEP_NAMESERVER_LOOKUP:
  2342. if (!atomic_test_mask(ZFCP_STATUS_PORT_DID_DID, &port->status)) {
  2343. if (atomic_test_mask
  2344. (ZFCP_STATUS_PORT_INVALID_WWPN, &port->status)) {
  2345. ZFCP_LOG_DEBUG("nameserver look-up failed "
  2346. "for port 0x%016Lx "
  2347. "(misconfigured WWPN?)\n",
  2348. port->wwpn);
  2349. zfcp_erp_port_failed(port);
  2350. retval = ZFCP_ERP_EXIT;
  2351. } else {
  2352. ZFCP_LOG_DEBUG("nameserver look-up failed for "
  2353. "port 0x%016Lx\n", port->wwpn);
  2354. retval = ZFCP_ERP_FAILED;
  2355. }
  2356. } else {
  2357. ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> "
  2358. "trying open\n", port->wwpn, port->d_id);
  2359. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2360. }
  2361. break;
  2362. case ZFCP_ERP_STEP_PORT_OPENING:
  2363. /* D_ID might have changed during open */
  2364. if (atomic_test_mask((ZFCP_STATUS_COMMON_OPEN |
  2365. ZFCP_STATUS_PORT_DID_DID),
  2366. &port->status)) {
  2367. ZFCP_LOG_DEBUG("port 0x%016Lx is open\n", port->wwpn);
  2368. retval = ZFCP_ERP_SUCCEEDED;
  2369. } else {
  2370. ZFCP_LOG_DEBUG("open failed for port 0x%016Lx\n",
  2371. port->wwpn);
  2372. retval = ZFCP_ERP_FAILED;
  2373. }
  2374. break;
  2375. default:
  2376. ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
  2377. erp_action->step);
  2378. retval = ZFCP_ERP_FAILED;
  2379. }
  2380. return retval;
  2381. }
  2382. /*
  2383. * function:
  2384. *
  2385. * purpose:
  2386. *
  2387. * returns:
  2388. */
  2389. static int
  2390. zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
  2391. {
  2392. int retval;
  2393. struct zfcp_port *port = erp_action->port;
  2394. switch (erp_action->step) {
  2395. case ZFCP_ERP_STEP_UNINITIALIZED:
  2396. case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
  2397. case ZFCP_ERP_STEP_PORT_CLOSING:
  2398. ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n",
  2399. port->wwpn, port->d_id);
  2400. retval = zfcp_erp_port_strategy_open_port(erp_action);
  2401. break;
  2402. case ZFCP_ERP_STEP_PORT_OPENING:
  2403. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &port->status)) {
  2404. ZFCP_LOG_DEBUG("WKA port is open\n");
  2405. retval = ZFCP_ERP_SUCCEEDED;
  2406. } else {
  2407. ZFCP_LOG_DEBUG("open failed for WKA port\n");
  2408. retval = ZFCP_ERP_FAILED;
  2409. }
  2410. /* this is needed anyway (dont care for retval of wakeup) */
  2411. ZFCP_LOG_DEBUG("continue other open port operations\n");
  2412. zfcp_erp_port_strategy_open_nameserver_wakeup(erp_action);
  2413. break;
  2414. default:
  2415. ZFCP_LOG_NORMAL("bug: unknown erp step 0x%08x\n",
  2416. erp_action->step);
  2417. retval = ZFCP_ERP_FAILED;
  2418. }
  2419. return retval;
  2420. }
  2421. /*
  2422. * function:
  2423. *
  2424. * purpose: makes the erp thread continue with reopen (physical) port
  2425. * actions which have been paused until the name server port
  2426. * is opened (or failed)
  2427. *
  2428. * returns: 0 (a kind of void retval, its not used)
  2429. */
  2430. static int
  2431. zfcp_erp_port_strategy_open_nameserver_wakeup(struct zfcp_erp_action
  2432. *ns_erp_action)
  2433. {
  2434. int retval = 0;
  2435. unsigned long flags;
  2436. struct zfcp_adapter *adapter = ns_erp_action->adapter;
  2437. struct zfcp_erp_action *erp_action, *tmp;
  2438. read_lock_irqsave(&adapter->erp_lock, flags);
  2439. list_for_each_entry_safe(erp_action, tmp, &adapter->erp_running_head,
  2440. list) {
  2441. debug_text_event(adapter->erp_dbf, 4, "p_pstnsw_n");
  2442. debug_event(adapter->erp_dbf, 4, &erp_action->port->wwpn,
  2443. sizeof (wwn_t));
  2444. if (erp_action->step == ZFCP_ERP_STEP_NAMESERVER_OPEN) {
  2445. debug_text_event(adapter->erp_dbf, 3, "p_pstnsw_w");
  2446. debug_event(adapter->erp_dbf, 3,
  2447. &erp_action->port->wwpn, sizeof (wwn_t));
  2448. if (atomic_test_mask(
  2449. ZFCP_STATUS_COMMON_ERP_FAILED,
  2450. &adapter->nameserver_port->status))
  2451. zfcp_erp_port_failed(erp_action->port);
  2452. zfcp_erp_action_ready(erp_action);
  2453. }
  2454. }
  2455. read_unlock_irqrestore(&adapter->erp_lock, flags);
  2456. return retval;
  2457. }
  2458. /*
  2459. * function:
  2460. *
  2461. * purpose:
  2462. *
  2463. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2464. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2465. */
  2466. static int
  2467. zfcp_erp_port_forced_strategy_close(struct zfcp_erp_action *erp_action)
  2468. {
  2469. int retval;
  2470. struct zfcp_adapter *adapter = erp_action->adapter;
  2471. struct zfcp_port *port = erp_action->port;
  2472. zfcp_erp_timeout_init(erp_action);
  2473. retval = zfcp_fsf_close_physical_port(erp_action);
  2474. if (retval == -ENOMEM) {
  2475. debug_text_event(adapter->erp_dbf, 5, "o_pfstc_nomem");
  2476. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2477. retval = ZFCP_ERP_NOMEM;
  2478. goto out;
  2479. }
  2480. erp_action->step = ZFCP_ERP_STEP_PHYS_PORT_CLOSING;
  2481. if (retval != 0) {
  2482. debug_text_event(adapter->erp_dbf, 5, "o_pfstc_cpf");
  2483. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2484. /* could not send 'open', fail */
  2485. retval = ZFCP_ERP_FAILED;
  2486. goto out;
  2487. }
  2488. debug_text_event(adapter->erp_dbf, 6, "o_pfstc_cpok");
  2489. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2490. retval = ZFCP_ERP_CONTINUES;
  2491. out:
  2492. return retval;
  2493. }
  2494. /*
  2495. * function:
  2496. *
  2497. * purpose:
  2498. *
  2499. * returns:
  2500. */
  2501. static int
  2502. zfcp_erp_port_strategy_clearstati(struct zfcp_port *port)
  2503. {
  2504. int retval = 0;
  2505. struct zfcp_adapter *adapter = port->adapter;
  2506. debug_text_event(adapter->erp_dbf, 5, "p_pstclst");
  2507. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2508. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  2509. ZFCP_STATUS_COMMON_CLOSING |
  2510. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2511. ZFCP_STATUS_PORT_DID_DID |
  2512. ZFCP_STATUS_PORT_PHYS_CLOSING |
  2513. ZFCP_STATUS_PORT_INVALID_WWPN,
  2514. &port->status);
  2515. return retval;
  2516. }
  2517. /*
  2518. * function:
  2519. *
  2520. * purpose:
  2521. *
  2522. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2523. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2524. */
  2525. static int
  2526. zfcp_erp_port_strategy_close(struct zfcp_erp_action *erp_action)
  2527. {
  2528. int retval;
  2529. struct zfcp_adapter *adapter = erp_action->adapter;
  2530. struct zfcp_port *port = erp_action->port;
  2531. zfcp_erp_timeout_init(erp_action);
  2532. retval = zfcp_fsf_close_port(erp_action);
  2533. if (retval == -ENOMEM) {
  2534. debug_text_event(adapter->erp_dbf, 5, "p_pstc_nomem");
  2535. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2536. retval = ZFCP_ERP_NOMEM;
  2537. goto out;
  2538. }
  2539. erp_action->step = ZFCP_ERP_STEP_PORT_CLOSING;
  2540. if (retval != 0) {
  2541. debug_text_event(adapter->erp_dbf, 5, "p_pstc_cpf");
  2542. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2543. /* could not send 'close', fail */
  2544. retval = ZFCP_ERP_FAILED;
  2545. goto out;
  2546. }
  2547. debug_text_event(adapter->erp_dbf, 6, "p_pstc_cpok");
  2548. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2549. retval = ZFCP_ERP_CONTINUES;
  2550. out:
  2551. return retval;
  2552. }
  2553. /*
  2554. * function:
  2555. *
  2556. * purpose:
  2557. *
  2558. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2559. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2560. */
  2561. static int
  2562. zfcp_erp_port_strategy_open_port(struct zfcp_erp_action *erp_action)
  2563. {
  2564. int retval;
  2565. struct zfcp_adapter *adapter = erp_action->adapter;
  2566. struct zfcp_port *port = erp_action->port;
  2567. zfcp_erp_timeout_init(erp_action);
  2568. retval = zfcp_fsf_open_port(erp_action);
  2569. if (retval == -ENOMEM) {
  2570. debug_text_event(adapter->erp_dbf, 5, "p_psto_nomem");
  2571. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2572. retval = ZFCP_ERP_NOMEM;
  2573. goto out;
  2574. }
  2575. erp_action->step = ZFCP_ERP_STEP_PORT_OPENING;
  2576. if (retval != 0) {
  2577. debug_text_event(adapter->erp_dbf, 5, "p_psto_opf");
  2578. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2579. /* could not send 'open', fail */
  2580. retval = ZFCP_ERP_FAILED;
  2581. goto out;
  2582. }
  2583. debug_text_event(adapter->erp_dbf, 6, "p_psto_opok");
  2584. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2585. retval = ZFCP_ERP_CONTINUES;
  2586. out:
  2587. return retval;
  2588. }
  2589. /*
  2590. * function:
  2591. *
  2592. * purpose:
  2593. *
  2594. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2595. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2596. */
  2597. static int
  2598. zfcp_erp_port_strategy_open_common_lookup(struct zfcp_erp_action *erp_action)
  2599. {
  2600. int retval;
  2601. struct zfcp_adapter *adapter = erp_action->adapter;
  2602. struct zfcp_port *port = erp_action->port;
  2603. zfcp_erp_timeout_init(erp_action);
  2604. retval = zfcp_ns_gid_pn_request(erp_action);
  2605. if (retval == -ENOMEM) {
  2606. debug_text_event(adapter->erp_dbf, 5, "p_pstn_nomem");
  2607. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2608. retval = ZFCP_ERP_NOMEM;
  2609. goto out;
  2610. }
  2611. erp_action->step = ZFCP_ERP_STEP_NAMESERVER_LOOKUP;
  2612. if (retval != 0) {
  2613. debug_text_event(adapter->erp_dbf, 5, "p_pstn_ref");
  2614. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  2615. /* could not send nameserver request, fail */
  2616. retval = ZFCP_ERP_FAILED;
  2617. goto out;
  2618. }
  2619. debug_text_event(adapter->erp_dbf, 6, "p_pstn_reok");
  2620. debug_event(adapter->erp_dbf, 6, &port->wwpn, sizeof (wwn_t));
  2621. retval = ZFCP_ERP_CONTINUES;
  2622. out:
  2623. return retval;
  2624. }
  2625. /*
  2626. * function:
  2627. *
  2628. * purpose: this routine executes the 'Reopen Unit' action
  2629. * currently no retries
  2630. *
  2631. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2632. * ZFCP_ERP_SUCCEEDED - action finished successfully
  2633. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2634. */
  2635. static int
  2636. zfcp_erp_unit_strategy(struct zfcp_erp_action *erp_action)
  2637. {
  2638. int retval = ZFCP_ERP_FAILED;
  2639. struct zfcp_unit *unit = erp_action->unit;
  2640. struct zfcp_adapter *adapter = erp_action->adapter;
  2641. switch (erp_action->step) {
  2642. /*
  2643. * FIXME:
  2644. * the ULP spec. begs for waiting for oustanding commands
  2645. */
  2646. case ZFCP_ERP_STEP_UNINITIALIZED:
  2647. zfcp_erp_unit_strategy_clearstati(unit);
  2648. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2649. ZFCP_LOG_DEBUG("unit 0x%016Lx is open -> "
  2650. "trying close\n", unit->fcp_lun);
  2651. retval = zfcp_erp_unit_strategy_close(erp_action);
  2652. break;
  2653. }
  2654. /* else it's already closed, fall through */
  2655. case ZFCP_ERP_STEP_UNIT_CLOSING:
  2656. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2657. ZFCP_LOG_DEBUG("close failed for unit 0x%016Lx\n",
  2658. unit->fcp_lun);
  2659. retval = ZFCP_ERP_FAILED;
  2660. } else {
  2661. if (erp_action->status & ZFCP_STATUS_ERP_CLOSE_ONLY)
  2662. retval = ZFCP_ERP_EXIT;
  2663. else {
  2664. ZFCP_LOG_DEBUG("unit 0x%016Lx is not open -> "
  2665. "trying open\n", unit->fcp_lun);
  2666. retval =
  2667. zfcp_erp_unit_strategy_open(erp_action);
  2668. }
  2669. }
  2670. break;
  2671. case ZFCP_ERP_STEP_UNIT_OPENING:
  2672. if (atomic_test_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status)) {
  2673. ZFCP_LOG_DEBUG("unit 0x%016Lx is open\n",
  2674. unit->fcp_lun);
  2675. retval = ZFCP_ERP_SUCCEEDED;
  2676. } else {
  2677. ZFCP_LOG_DEBUG("open failed for unit 0x%016Lx\n",
  2678. unit->fcp_lun);
  2679. retval = ZFCP_ERP_FAILED;
  2680. }
  2681. break;
  2682. }
  2683. debug_text_event(adapter->erp_dbf, 3, "u_ust/ret");
  2684. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof (fcp_lun_t));
  2685. debug_event(adapter->erp_dbf, 3, &erp_action->action, sizeof (int));
  2686. debug_event(adapter->erp_dbf, 3, &retval, sizeof (int));
  2687. return retval;
  2688. }
  2689. /*
  2690. * function:
  2691. *
  2692. * purpose:
  2693. *
  2694. * returns:
  2695. */
  2696. static int
  2697. zfcp_erp_unit_strategy_clearstati(struct zfcp_unit *unit)
  2698. {
  2699. int retval = 0;
  2700. struct zfcp_adapter *adapter = unit->port->adapter;
  2701. debug_text_event(adapter->erp_dbf, 5, "u_ustclst");
  2702. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
  2703. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING |
  2704. ZFCP_STATUS_COMMON_CLOSING |
  2705. ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2706. ZFCP_STATUS_UNIT_SHARED |
  2707. ZFCP_STATUS_UNIT_READONLY,
  2708. &unit->status);
  2709. return retval;
  2710. }
  2711. /*
  2712. * function:
  2713. *
  2714. * purpose:
  2715. *
  2716. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2717. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2718. */
  2719. static int
  2720. zfcp_erp_unit_strategy_close(struct zfcp_erp_action *erp_action)
  2721. {
  2722. int retval;
  2723. struct zfcp_adapter *adapter = erp_action->adapter;
  2724. struct zfcp_unit *unit = erp_action->unit;
  2725. zfcp_erp_timeout_init(erp_action);
  2726. retval = zfcp_fsf_close_unit(erp_action);
  2727. if (retval == -ENOMEM) {
  2728. debug_text_event(adapter->erp_dbf, 5, "u_ustc_nomem");
  2729. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2730. sizeof (fcp_lun_t));
  2731. retval = ZFCP_ERP_NOMEM;
  2732. goto out;
  2733. }
  2734. erp_action->step = ZFCP_ERP_STEP_UNIT_CLOSING;
  2735. if (retval != 0) {
  2736. debug_text_event(adapter->erp_dbf, 5, "u_ustc_cuf");
  2737. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2738. sizeof (fcp_lun_t));
  2739. /* could not send 'close', fail */
  2740. retval = ZFCP_ERP_FAILED;
  2741. goto out;
  2742. }
  2743. debug_text_event(adapter->erp_dbf, 6, "u_ustc_cuok");
  2744. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  2745. retval = ZFCP_ERP_CONTINUES;
  2746. out:
  2747. return retval;
  2748. }
  2749. /*
  2750. * function:
  2751. *
  2752. * purpose:
  2753. *
  2754. * returns: ZFCP_ERP_CONTINUES - action continues (asynchronously)
  2755. * ZFCP_ERP_FAILED - action finished unsuccessfully
  2756. */
  2757. static int
  2758. zfcp_erp_unit_strategy_open(struct zfcp_erp_action *erp_action)
  2759. {
  2760. int retval;
  2761. struct zfcp_adapter *adapter = erp_action->adapter;
  2762. struct zfcp_unit *unit = erp_action->unit;
  2763. zfcp_erp_timeout_init(erp_action);
  2764. retval = zfcp_fsf_open_unit(erp_action);
  2765. if (retval == -ENOMEM) {
  2766. debug_text_event(adapter->erp_dbf, 5, "u_usto_nomem");
  2767. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2768. sizeof (fcp_lun_t));
  2769. retval = ZFCP_ERP_NOMEM;
  2770. goto out;
  2771. }
  2772. erp_action->step = ZFCP_ERP_STEP_UNIT_OPENING;
  2773. if (retval != 0) {
  2774. debug_text_event(adapter->erp_dbf, 5, "u_usto_ouf");
  2775. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun,
  2776. sizeof (fcp_lun_t));
  2777. /* could not send 'open', fail */
  2778. retval = ZFCP_ERP_FAILED;
  2779. goto out;
  2780. }
  2781. debug_text_event(adapter->erp_dbf, 6, "u_usto_ouok");
  2782. debug_event(adapter->erp_dbf, 6, &unit->fcp_lun, sizeof (fcp_lun_t));
  2783. retval = ZFCP_ERP_CONTINUES;
  2784. out:
  2785. return retval;
  2786. }
  2787. /*
  2788. * function:
  2789. *
  2790. * purpose:
  2791. *
  2792. * returns:
  2793. */
  2794. static inline void
  2795. zfcp_erp_timeout_init(struct zfcp_erp_action *erp_action)
  2796. {
  2797. init_timer(&erp_action->timer);
  2798. erp_action->timer.function = zfcp_erp_timeout_handler;
  2799. erp_action->timer.data = (unsigned long) erp_action;
  2800. /* jiffies will be added in zfcp_fsf_req_send */
  2801. erp_action->timer.expires = ZFCP_ERP_FSFREQ_TIMEOUT;
  2802. }
  2803. /*
  2804. * function:
  2805. *
  2806. * purpose: enqueue the specified error recovery action, if needed
  2807. *
  2808. * returns:
  2809. */
  2810. static int
  2811. zfcp_erp_action_enqueue(int action,
  2812. struct zfcp_adapter *adapter,
  2813. struct zfcp_port *port, struct zfcp_unit *unit)
  2814. {
  2815. int retval = 1;
  2816. struct zfcp_erp_action *erp_action = NULL;
  2817. int stronger_action = 0;
  2818. u32 status = 0;
  2819. /*
  2820. * We need some rules here which check whether we really need
  2821. * this action or whether we should just drop it.
  2822. * E.g. if there is a unfinished 'Reopen Port' request then we drop a
  2823. * 'Reopen Unit' request for an associated unit since we can't
  2824. * satisfy this request now. A 'Reopen Port' action will trigger
  2825. * 'Reopen Unit' actions when it completes.
  2826. * Thus, there are only actions in the queue which can immediately be
  2827. * executed. This makes the processing of the action queue more
  2828. * efficient.
  2829. */
  2830. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_ERP_THREAD_UP,
  2831. &adapter->status))
  2832. return -EIO;
  2833. debug_event(adapter->erp_dbf, 4, &action, sizeof (int));
  2834. /* check whether we really need this */
  2835. switch (action) {
  2836. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2837. if (atomic_test_mask
  2838. (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)) {
  2839. debug_text_event(adapter->erp_dbf, 4, "u_actenq_drp");
  2840. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2841. sizeof (wwn_t));
  2842. debug_event(adapter->erp_dbf, 4, &unit->fcp_lun,
  2843. sizeof (fcp_lun_t));
  2844. goto out;
  2845. }
  2846. if (!atomic_test_mask
  2847. (ZFCP_STATUS_COMMON_RUNNING, &port->status) ||
  2848. atomic_test_mask
  2849. (ZFCP_STATUS_COMMON_ERP_FAILED, &port->status)) {
  2850. goto out;
  2851. }
  2852. if (!atomic_test_mask
  2853. (ZFCP_STATUS_COMMON_UNBLOCKED, &port->status)) {
  2854. stronger_action = ZFCP_ERP_ACTION_REOPEN_PORT;
  2855. unit = NULL;
  2856. }
  2857. /* fall through !!! */
  2858. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2859. if (atomic_test_mask
  2860. (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status)) {
  2861. debug_text_event(adapter->erp_dbf, 4, "p_actenq_drp");
  2862. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2863. sizeof (wwn_t));
  2864. goto out;
  2865. }
  2866. /* fall through !!! */
  2867. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2868. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2869. &port->status)) {
  2870. if (port->erp_action.action !=
  2871. ZFCP_ERP_ACTION_REOPEN_PORT_FORCED) {
  2872. ZFCP_LOG_INFO("dropped erp action %i (port "
  2873. "0x%016Lx, action in use: %i)\n",
  2874. action, port->wwpn,
  2875. port->erp_action.action);
  2876. debug_text_event(adapter->erp_dbf, 4,
  2877. "pf_actenq_drp");
  2878. } else
  2879. debug_text_event(adapter->erp_dbf, 4,
  2880. "pf_actenq_drpcp");
  2881. debug_event(adapter->erp_dbf, 4, &port->wwpn,
  2882. sizeof (wwn_t));
  2883. goto out;
  2884. }
  2885. if (!atomic_test_mask
  2886. (ZFCP_STATUS_COMMON_RUNNING, &adapter->status) ||
  2887. atomic_test_mask
  2888. (ZFCP_STATUS_COMMON_ERP_FAILED, &adapter->status)) {
  2889. goto out;
  2890. }
  2891. if (!atomic_test_mask
  2892. (ZFCP_STATUS_COMMON_UNBLOCKED, &adapter->status)) {
  2893. stronger_action = ZFCP_ERP_ACTION_REOPEN_ADAPTER;
  2894. port = NULL;
  2895. }
  2896. /* fall through !!! */
  2897. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2898. if (atomic_test_mask
  2899. (ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status)) {
  2900. debug_text_event(adapter->erp_dbf, 4, "a_actenq_drp");
  2901. goto out;
  2902. }
  2903. break;
  2904. default:
  2905. debug_text_exception(adapter->erp_dbf, 1, "a_actenq_bug");
  2906. debug_event(adapter->erp_dbf, 1, &action, sizeof (int));
  2907. ZFCP_LOG_NORMAL("bug: unknown erp action requested "
  2908. "on adapter %s (action=%d)\n",
  2909. zfcp_get_busid_by_adapter(adapter), action);
  2910. goto out;
  2911. }
  2912. /* check whether we need something stronger first */
  2913. if (stronger_action) {
  2914. debug_text_event(adapter->erp_dbf, 4, "a_actenq_str");
  2915. debug_event(adapter->erp_dbf, 4, &stronger_action,
  2916. sizeof (int));
  2917. ZFCP_LOG_DEBUG("stronger erp action %d needed before "
  2918. "erp action %d on adapter %s\n",
  2919. stronger_action, action,
  2920. zfcp_get_busid_by_adapter(adapter));
  2921. action = stronger_action;
  2922. }
  2923. /* mark adapter to have some error recovery pending */
  2924. atomic_set_mask(ZFCP_STATUS_ADAPTER_ERP_PENDING, &adapter->status);
  2925. /* setup error recovery action */
  2926. switch (action) {
  2927. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2928. zfcp_unit_get(unit);
  2929. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status);
  2930. erp_action = &unit->erp_action;
  2931. if (!atomic_test_mask
  2932. (ZFCP_STATUS_COMMON_RUNNING, &unit->status))
  2933. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2934. break;
  2935. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2936. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2937. zfcp_port_get(port);
  2938. zfcp_erp_action_dismiss_port(port);
  2939. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status);
  2940. erp_action = &port->erp_action;
  2941. if (!atomic_test_mask
  2942. (ZFCP_STATUS_COMMON_RUNNING, &port->status))
  2943. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2944. break;
  2945. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  2946. zfcp_adapter_get(adapter);
  2947. zfcp_erp_action_dismiss_adapter(adapter);
  2948. atomic_set_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status);
  2949. erp_action = &adapter->erp_action;
  2950. if (!atomic_test_mask
  2951. (ZFCP_STATUS_COMMON_RUNNING, &adapter->status))
  2952. status = ZFCP_STATUS_ERP_CLOSE_ONLY;
  2953. break;
  2954. }
  2955. debug_text_event(adapter->erp_dbf, 4, "a_actenq");
  2956. memset(erp_action, 0, sizeof (struct zfcp_erp_action));
  2957. erp_action->adapter = adapter;
  2958. erp_action->port = port;
  2959. erp_action->unit = unit;
  2960. erp_action->action = action;
  2961. erp_action->status = status;
  2962. ++adapter->erp_total_count;
  2963. /* finally put it into 'ready' queue and kick erp thread */
  2964. list_add(&erp_action->list, &adapter->erp_ready_head);
  2965. up(&adapter->erp_ready_sem);
  2966. retval = 0;
  2967. out:
  2968. return retval;
  2969. }
  2970. /*
  2971. * function:
  2972. *
  2973. * purpose:
  2974. *
  2975. * returns:
  2976. */
  2977. static int
  2978. zfcp_erp_action_dequeue(struct zfcp_erp_action *erp_action)
  2979. {
  2980. int retval = 0;
  2981. struct zfcp_adapter *adapter = erp_action->adapter;
  2982. --adapter->erp_total_count;
  2983. if (erp_action->status & ZFCP_STATUS_ERP_LOWMEM) {
  2984. --adapter->erp_low_mem_count;
  2985. erp_action->status &= ~ZFCP_STATUS_ERP_LOWMEM;
  2986. }
  2987. debug_text_event(adapter->erp_dbf, 4, "a_actdeq");
  2988. debug_event(adapter->erp_dbf, 4, &erp_action->action, sizeof (int));
  2989. list_del(&erp_action->list);
  2990. switch (erp_action->action) {
  2991. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  2992. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2993. &erp_action->unit->status);
  2994. break;
  2995. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  2996. case ZFCP_ERP_ACTION_REOPEN_PORT:
  2997. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  2998. &erp_action->port->status);
  2999. break;
  3000. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  3001. atomic_clear_mask(ZFCP_STATUS_COMMON_ERP_INUSE,
  3002. &erp_action->adapter->status);
  3003. break;
  3004. default:
  3005. /* bug */
  3006. break;
  3007. }
  3008. return retval;
  3009. }
  3010. /**
  3011. * zfcp_erp_action_cleanup
  3012. *
  3013. * Register unit with scsi stack if appropriate and fix reference counts.
  3014. * Note: Temporary units are not registered with scsi stack.
  3015. */
  3016. static void
  3017. zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
  3018. struct zfcp_port *port, struct zfcp_unit *unit,
  3019. int result)
  3020. {
  3021. switch (action) {
  3022. case ZFCP_ERP_ACTION_REOPEN_UNIT:
  3023. if ((result == ZFCP_ERP_SUCCEEDED)
  3024. && (!atomic_test_mask(ZFCP_STATUS_UNIT_TEMPORARY,
  3025. &unit->status))
  3026. && !unit->device
  3027. && port->rport)
  3028. scsi_add_device(port->adapter->scsi_host, 0,
  3029. port->rport->scsi_target_id,
  3030. unit->scsi_lun);
  3031. zfcp_unit_put(unit);
  3032. break;
  3033. case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED:
  3034. case ZFCP_ERP_ACTION_REOPEN_PORT:
  3035. if ((result == ZFCP_ERP_SUCCEEDED)
  3036. && !atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN,
  3037. &port->status)
  3038. && !port->rport) {
  3039. struct fc_rport_identifiers ids;
  3040. ids.node_name = port->wwnn;
  3041. ids.port_name = port->wwpn;
  3042. ids.port_id = port->d_id;
  3043. ids.roles = FC_RPORT_ROLE_FCP_TARGET;
  3044. port->rport =
  3045. fc_remote_port_add(adapter->scsi_host, 0, &ids);
  3046. if (!port->rport)
  3047. ZFCP_LOG_NORMAL("failed registration of rport"
  3048. "(adapter %s, wwpn=0x%016Lx)\n",
  3049. zfcp_get_busid_by_port(port),
  3050. port->wwpn);
  3051. }
  3052. zfcp_port_put(port);
  3053. break;
  3054. case ZFCP_ERP_ACTION_REOPEN_ADAPTER:
  3055. zfcp_adapter_put(adapter);
  3056. break;
  3057. default:
  3058. break;
  3059. }
  3060. }
  3061. /*
  3062. * function:
  3063. *
  3064. * purpose:
  3065. *
  3066. * returns: FIXME
  3067. */
  3068. static int
  3069. zfcp_erp_action_dismiss_adapter(struct zfcp_adapter *adapter)
  3070. {
  3071. int retval = 0;
  3072. struct zfcp_port *port;
  3073. debug_text_event(adapter->erp_dbf, 5, "a_actab");
  3074. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &adapter->status))
  3075. zfcp_erp_action_dismiss(&adapter->erp_action);
  3076. else
  3077. list_for_each_entry(port, &adapter->port_list_head, list)
  3078. zfcp_erp_action_dismiss_port(port);
  3079. return retval;
  3080. }
  3081. /*
  3082. * function:
  3083. *
  3084. * purpose:
  3085. *
  3086. * returns: FIXME
  3087. */
  3088. static int
  3089. zfcp_erp_action_dismiss_port(struct zfcp_port *port)
  3090. {
  3091. int retval = 0;
  3092. struct zfcp_unit *unit;
  3093. struct zfcp_adapter *adapter = port->adapter;
  3094. debug_text_event(adapter->erp_dbf, 5, "p_actab");
  3095. debug_event(adapter->erp_dbf, 5, &port->wwpn, sizeof (wwn_t));
  3096. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &port->status))
  3097. zfcp_erp_action_dismiss(&port->erp_action);
  3098. else
  3099. list_for_each_entry(unit, &port->unit_list_head, list)
  3100. zfcp_erp_action_dismiss_unit(unit);
  3101. return retval;
  3102. }
  3103. /*
  3104. * function:
  3105. *
  3106. * purpose:
  3107. *
  3108. * returns: FIXME
  3109. */
  3110. static int
  3111. zfcp_erp_action_dismiss_unit(struct zfcp_unit *unit)
  3112. {
  3113. int retval = 0;
  3114. struct zfcp_adapter *adapter = unit->port->adapter;
  3115. debug_text_event(adapter->erp_dbf, 5, "u_actab");
  3116. debug_event(adapter->erp_dbf, 5, &unit->fcp_lun, sizeof (fcp_lun_t));
  3117. if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status))
  3118. zfcp_erp_action_dismiss(&unit->erp_action);
  3119. return retval;
  3120. }
  3121. /*
  3122. * function:
  3123. *
  3124. * purpose: moves erp_action to 'erp running list'
  3125. *
  3126. * returns:
  3127. */
  3128. static inline void
  3129. zfcp_erp_action_to_running(struct zfcp_erp_action *erp_action)
  3130. {
  3131. struct zfcp_adapter *adapter = erp_action->adapter;
  3132. debug_text_event(adapter->erp_dbf, 6, "a_toru");
  3133. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  3134. list_move(&erp_action->list, &erp_action->adapter->erp_running_head);
  3135. }
  3136. /*
  3137. * function:
  3138. *
  3139. * purpose: moves erp_action to 'erp ready list'
  3140. *
  3141. * returns:
  3142. */
  3143. static inline void
  3144. zfcp_erp_action_to_ready(struct zfcp_erp_action *erp_action)
  3145. {
  3146. struct zfcp_adapter *adapter = erp_action->adapter;
  3147. debug_text_event(adapter->erp_dbf, 6, "a_tore");
  3148. debug_event(adapter->erp_dbf, 6, &erp_action->action, sizeof (int));
  3149. list_move(&erp_action->list, &erp_action->adapter->erp_ready_head);
  3150. }
  3151. /*
  3152. * function: zfcp_erp_port_boxed
  3153. *
  3154. * purpose:
  3155. */
  3156. void
  3157. zfcp_erp_port_boxed(struct zfcp_port *port)
  3158. {
  3159. struct zfcp_adapter *adapter = port->adapter;
  3160. unsigned long flags;
  3161. debug_text_event(adapter->erp_dbf, 3, "p_access_boxed");
  3162. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  3163. read_lock_irqsave(&zfcp_data.config_lock, flags);
  3164. zfcp_erp_modify_port_status(port,
  3165. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3166. ZFCP_SET);
  3167. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  3168. zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED);
  3169. }
  3170. /*
  3171. * function: zfcp_erp_unit_boxed
  3172. *
  3173. * purpose:
  3174. */
  3175. void
  3176. zfcp_erp_unit_boxed(struct zfcp_unit *unit)
  3177. {
  3178. struct zfcp_adapter *adapter = unit->port->adapter;
  3179. debug_text_event(adapter->erp_dbf, 3, "u_access_boxed");
  3180. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  3181. zfcp_erp_modify_unit_status(unit,
  3182. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3183. ZFCP_SET);
  3184. zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED);
  3185. }
  3186. /*
  3187. * function: zfcp_erp_port_access_denied
  3188. *
  3189. * purpose:
  3190. */
  3191. void
  3192. zfcp_erp_port_access_denied(struct zfcp_port *port)
  3193. {
  3194. struct zfcp_adapter *adapter = port->adapter;
  3195. unsigned long flags;
  3196. debug_text_event(adapter->erp_dbf, 3, "p_access_denied");
  3197. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  3198. read_lock_irqsave(&zfcp_data.config_lock, flags);
  3199. zfcp_erp_modify_port_status(port,
  3200. ZFCP_STATUS_COMMON_ERP_FAILED |
  3201. ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3202. ZFCP_SET);
  3203. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  3204. }
  3205. /*
  3206. * function: zfcp_erp_unit_access_denied
  3207. *
  3208. * purpose:
  3209. */
  3210. void
  3211. zfcp_erp_unit_access_denied(struct zfcp_unit *unit)
  3212. {
  3213. struct zfcp_adapter *adapter = unit->port->adapter;
  3214. debug_text_event(adapter->erp_dbf, 3, "u_access_denied");
  3215. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  3216. zfcp_erp_modify_unit_status(unit,
  3217. ZFCP_STATUS_COMMON_ERP_FAILED |
  3218. ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3219. ZFCP_SET);
  3220. }
  3221. /*
  3222. * function: zfcp_erp_adapter_access_changed
  3223. *
  3224. * purpose:
  3225. */
  3226. void
  3227. zfcp_erp_adapter_access_changed(struct zfcp_adapter *adapter)
  3228. {
  3229. struct zfcp_port *port;
  3230. unsigned long flags;
  3231. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  3232. return;
  3233. debug_text_event(adapter->erp_dbf, 3, "a_access_recover");
  3234. debug_event(adapter->erp_dbf, 3, &adapter->name, 8);
  3235. read_lock_irqsave(&zfcp_data.config_lock, flags);
  3236. if (adapter->nameserver_port)
  3237. zfcp_erp_port_access_changed(adapter->nameserver_port);
  3238. list_for_each_entry(port, &adapter->port_list_head, list)
  3239. if (port != adapter->nameserver_port)
  3240. zfcp_erp_port_access_changed(port);
  3241. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  3242. }
  3243. /*
  3244. * function: zfcp_erp_port_access_changed
  3245. *
  3246. * purpose:
  3247. */
  3248. void
  3249. zfcp_erp_port_access_changed(struct zfcp_port *port)
  3250. {
  3251. struct zfcp_adapter *adapter = port->adapter;
  3252. struct zfcp_unit *unit;
  3253. debug_text_event(adapter->erp_dbf, 3, "p_access_recover");
  3254. debug_event(adapter->erp_dbf, 3, &port->wwpn, sizeof(wwn_t));
  3255. if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3256. &port->status) &&
  3257. !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3258. &port->status)) {
  3259. if (!atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
  3260. list_for_each_entry(unit, &port->unit_list_head, list)
  3261. zfcp_erp_unit_access_changed(unit);
  3262. return;
  3263. }
  3264. ZFCP_LOG_NORMAL("reopen of port 0x%016Lx on adapter %s "
  3265. "(due to ACT update)\n",
  3266. port->wwpn, zfcp_get_busid_by_adapter(adapter));
  3267. if (zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
  3268. ZFCP_LOG_NORMAL("failed reopen of port"
  3269. "(adapter %s, wwpn=0x%016Lx)\n",
  3270. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  3271. }
  3272. /*
  3273. * function: zfcp_erp_unit_access_changed
  3274. *
  3275. * purpose:
  3276. */
  3277. void
  3278. zfcp_erp_unit_access_changed(struct zfcp_unit *unit)
  3279. {
  3280. struct zfcp_adapter *adapter = unit->port->adapter;
  3281. debug_text_event(adapter->erp_dbf, 3, "u_access_recover");
  3282. debug_event(adapter->erp_dbf, 3, &unit->fcp_lun, sizeof(fcp_lun_t));
  3283. if (!atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED,
  3284. &unit->status) &&
  3285. !atomic_test_mask(ZFCP_STATUS_COMMON_ACCESS_BOXED,
  3286. &unit->status))
  3287. return;
  3288. ZFCP_LOG_NORMAL("reopen of unit 0x%016Lx on port 0x%016Lx "
  3289. " on adapter %s (due to ACT update)\n",
  3290. unit->fcp_lun, unit->port->wwpn,
  3291. zfcp_get_busid_by_adapter(adapter));
  3292. if (zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED) != 0)
  3293. ZFCP_LOG_NORMAL("failed reopen of unit (adapter %s, "
  3294. "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
  3295. zfcp_get_busid_by_adapter(adapter),
  3296. unit->port->wwpn, unit->fcp_lun);
  3297. }
  3298. #undef ZFCP_LOG_AREA