zfcp_erp.c 97 KB

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