zfcp_erp.c 97 KB

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