zfcp_erp.c 99 KB

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