zfcp_erp.c 97 KB

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