zfcp_erp.c 97 KB

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