zfcp_fsf.c 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727
  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. #include "zfcp_ext.h"
  22. static int zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *);
  23. static void zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *);
  24. static int zfcp_fsf_open_port_handler(struct zfcp_fsf_req *);
  25. static int zfcp_fsf_close_port_handler(struct zfcp_fsf_req *);
  26. static int zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *);
  27. static int zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *);
  28. static int zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *);
  29. static int zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *);
  30. static int zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *);
  31. static int zfcp_fsf_send_fcp_command_task_management_handler(
  32. struct zfcp_fsf_req *);
  33. static int zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *);
  34. static int zfcp_fsf_status_read_handler(struct zfcp_fsf_req *);
  35. static int zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *);
  36. static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *);
  37. static int zfcp_fsf_control_file_handler(struct zfcp_fsf_req *);
  38. static inline int zfcp_fsf_req_sbal_check(
  39. unsigned long *, struct zfcp_qdio_queue *, int);
  40. static inline int zfcp_use_one_sbal(
  41. struct scatterlist *, int, struct scatterlist *, int);
  42. static struct zfcp_fsf_req *zfcp_fsf_req_alloc(mempool_t *, int);
  43. static int zfcp_fsf_req_send(struct zfcp_fsf_req *);
  44. static int zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *);
  45. static int zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *);
  46. static int zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *);
  47. static void zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *, u8,
  48. struct fsf_link_down_info *);
  49. static int zfcp_fsf_req_dispatch(struct zfcp_fsf_req *);
  50. /* association between FSF command and FSF QTCB type */
  51. static u32 fsf_qtcb_type[] = {
  52. [FSF_QTCB_FCP_CMND] = FSF_IO_COMMAND,
  53. [FSF_QTCB_ABORT_FCP_CMND] = FSF_SUPPORT_COMMAND,
  54. [FSF_QTCB_OPEN_PORT_WITH_DID] = FSF_SUPPORT_COMMAND,
  55. [FSF_QTCB_OPEN_LUN] = FSF_SUPPORT_COMMAND,
  56. [FSF_QTCB_CLOSE_LUN] = FSF_SUPPORT_COMMAND,
  57. [FSF_QTCB_CLOSE_PORT] = FSF_SUPPORT_COMMAND,
  58. [FSF_QTCB_CLOSE_PHYSICAL_PORT] = FSF_SUPPORT_COMMAND,
  59. [FSF_QTCB_SEND_ELS] = FSF_SUPPORT_COMMAND,
  60. [FSF_QTCB_SEND_GENERIC] = FSF_SUPPORT_COMMAND,
  61. [FSF_QTCB_EXCHANGE_CONFIG_DATA] = FSF_CONFIG_COMMAND,
  62. [FSF_QTCB_EXCHANGE_PORT_DATA] = FSF_PORT_COMMAND,
  63. [FSF_QTCB_DOWNLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND,
  64. [FSF_QTCB_UPLOAD_CONTROL_FILE] = FSF_SUPPORT_COMMAND
  65. };
  66. static const char zfcp_act_subtable_type[5][8] = {
  67. "unknown", "OS", "WWPN", "DID", "LUN"
  68. };
  69. /****************************************************************/
  70. /*************** FSF related Functions *************************/
  71. /****************************************************************/
  72. #define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
  73. /*
  74. * function: zfcp_fsf_req_alloc
  75. *
  76. * purpose: Obtains an fsf_req and potentially a qtcb (for all but
  77. * unsolicited requests) via helper functions
  78. * Does some initial fsf request set-up.
  79. *
  80. * returns: pointer to allocated fsf_req if successfull
  81. * NULL otherwise
  82. *
  83. * locks: none
  84. *
  85. */
  86. static struct zfcp_fsf_req *
  87. zfcp_fsf_req_alloc(mempool_t *pool, int req_flags)
  88. {
  89. size_t size;
  90. void *ptr;
  91. struct zfcp_fsf_req *fsf_req = NULL;
  92. if (req_flags & ZFCP_REQ_NO_QTCB)
  93. size = sizeof(struct zfcp_fsf_req);
  94. else
  95. size = sizeof(struct zfcp_fsf_req_qtcb);
  96. if (likely(pool))
  97. ptr = mempool_alloc(pool, GFP_ATOMIC);
  98. else {
  99. if (req_flags & ZFCP_REQ_NO_QTCB)
  100. ptr = kmalloc(size, GFP_ATOMIC);
  101. else
  102. ptr = kmem_cache_alloc(zfcp_data.fsf_req_qtcb_cache,
  103. GFP_ATOMIC);
  104. }
  105. if (unlikely(!ptr))
  106. goto out;
  107. memset(ptr, 0, size);
  108. if (req_flags & ZFCP_REQ_NO_QTCB) {
  109. fsf_req = (struct zfcp_fsf_req *) ptr;
  110. } else {
  111. fsf_req = &((struct zfcp_fsf_req_qtcb *) ptr)->fsf_req;
  112. fsf_req->qtcb = &((struct zfcp_fsf_req_qtcb *) ptr)->qtcb;
  113. }
  114. fsf_req->pool = pool;
  115. out:
  116. return fsf_req;
  117. }
  118. /*
  119. * function: zfcp_fsf_req_free
  120. *
  121. * purpose: Frees the memory of an fsf_req (and potentially a qtcb) or
  122. * returns it into the pool via helper functions.
  123. *
  124. * returns: sod all
  125. *
  126. * locks: none
  127. */
  128. void
  129. zfcp_fsf_req_free(struct zfcp_fsf_req *fsf_req)
  130. {
  131. if (likely(fsf_req->pool)) {
  132. mempool_free(fsf_req, fsf_req->pool);
  133. return;
  134. }
  135. if (fsf_req->qtcb) {
  136. kmem_cache_free(zfcp_data.fsf_req_qtcb_cache, fsf_req);
  137. return;
  138. }
  139. kfree(fsf_req);
  140. }
  141. /*
  142. * Never ever call this without shutting down the adapter first.
  143. * Otherwise the adapter would continue using and corrupting s390 storage.
  144. * Included BUG_ON() call to ensure this is done.
  145. * ERP is supposed to be the only user of this function.
  146. */
  147. void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
  148. {
  149. struct zfcp_fsf_req *fsf_req, *tmp;
  150. unsigned long flags;
  151. LIST_HEAD(remove_queue);
  152. unsigned int i;
  153. BUG_ON(atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status));
  154. spin_lock_irqsave(&adapter->req_list_lock, flags);
  155. atomic_set(&adapter->reqs_active, 0);
  156. for (i = 0; i < REQUEST_LIST_SIZE; i++)
  157. list_splice_init(&adapter->req_list[i], &remove_queue);
  158. spin_unlock_irqrestore(&adapter->req_list_lock, flags);
  159. list_for_each_entry_safe(fsf_req, tmp, &remove_queue, list) {
  160. list_del(&fsf_req->list);
  161. fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED;
  162. zfcp_fsf_req_complete(fsf_req);
  163. }
  164. }
  165. /*
  166. * function: zfcp_fsf_req_complete
  167. *
  168. * purpose: Updates active counts and timers for openfcp-reqs
  169. * May cleanup request after req_eval returns
  170. *
  171. * returns: 0 - success
  172. * !0 - failure
  173. *
  174. * context:
  175. */
  176. int
  177. zfcp_fsf_req_complete(struct zfcp_fsf_req *fsf_req)
  178. {
  179. int retval = 0;
  180. int cleanup;
  181. if (unlikely(fsf_req->fsf_command == FSF_QTCB_UNSOLICITED_STATUS)) {
  182. ZFCP_LOG_DEBUG("Status read response received\n");
  183. /*
  184. * Note: all cleanup handling is done in the callchain of
  185. * the function call-chain below.
  186. */
  187. zfcp_fsf_status_read_handler(fsf_req);
  188. goto out;
  189. } else {
  190. del_timer(&fsf_req->timer);
  191. zfcp_fsf_protstatus_eval(fsf_req);
  192. }
  193. /*
  194. * fsf_req may be deleted due to waking up functions, so
  195. * cleanup is saved here and used later
  196. */
  197. if (likely(fsf_req->status & ZFCP_STATUS_FSFREQ_CLEANUP))
  198. cleanup = 1;
  199. else
  200. cleanup = 0;
  201. fsf_req->status |= ZFCP_STATUS_FSFREQ_COMPLETED;
  202. /* cleanup request if requested by initiator */
  203. if (likely(cleanup)) {
  204. ZFCP_LOG_TRACE("removing FSF request %p\n", fsf_req);
  205. /*
  206. * lock must not be held here since it will be
  207. * grabed by the called routine, too
  208. */
  209. zfcp_fsf_req_free(fsf_req);
  210. } else {
  211. /* notify initiator waiting for the requests completion */
  212. ZFCP_LOG_TRACE("waking initiator of FSF request %p\n",fsf_req);
  213. /*
  214. * FIXME: Race! We must not access fsf_req here as it might have been
  215. * cleaned up already due to the set ZFCP_STATUS_FSFREQ_COMPLETED
  216. * flag. It's an improbable case. But, we have the same paranoia for
  217. * the cleanup flag already.
  218. * Might better be handled using complete()?
  219. * (setting the flag and doing wakeup ought to be atomic
  220. * with regard to checking the flag as long as waitqueue is
  221. * part of the to be released structure)
  222. */
  223. wake_up(&fsf_req->completion_wq);
  224. }
  225. out:
  226. return retval;
  227. }
  228. /*
  229. * function: zfcp_fsf_protstatus_eval
  230. *
  231. * purpose: evaluates the QTCB of the finished FSF request
  232. * and initiates appropriate actions
  233. * (usually calling FSF command specific handlers)
  234. *
  235. * returns:
  236. *
  237. * context:
  238. *
  239. * locks:
  240. */
  241. static int
  242. zfcp_fsf_protstatus_eval(struct zfcp_fsf_req *fsf_req)
  243. {
  244. int retval = 0;
  245. struct zfcp_adapter *adapter = fsf_req->adapter;
  246. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  247. union fsf_prot_status_qual *prot_status_qual =
  248. &qtcb->prefix.prot_status_qual;
  249. zfcp_hba_dbf_event_fsf_response(fsf_req);
  250. if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  251. ZFCP_LOG_DEBUG("fsf_req 0x%lx has been dismissed\n",
  252. (unsigned long) fsf_req);
  253. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  254. ZFCP_STATUS_FSFREQ_RETRY; /* only for SCSI cmnds. */
  255. goto skip_protstatus;
  256. }
  257. /* evaluate FSF Protocol Status */
  258. switch (qtcb->prefix.prot_status) {
  259. case FSF_PROT_GOOD:
  260. case FSF_PROT_FSF_STATUS_PRESENTED:
  261. break;
  262. case FSF_PROT_QTCB_VERSION_ERROR:
  263. ZFCP_LOG_NORMAL("error: The adapter %s contains "
  264. "microcode of version 0x%x, the device driver "
  265. "only supports 0x%x. Aborting.\n",
  266. zfcp_get_busid_by_adapter(adapter),
  267. prot_status_qual->version_error.fsf_version,
  268. ZFCP_QTCB_VERSION);
  269. zfcp_erp_adapter_shutdown(adapter, 0, 117, fsf_req);
  270. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  271. break;
  272. case FSF_PROT_SEQ_NUMB_ERROR:
  273. ZFCP_LOG_NORMAL("bug: Sequence number mismatch between "
  274. "driver (0x%x) and adapter %s (0x%x). "
  275. "Restarting all operations on this adapter.\n",
  276. qtcb->prefix.req_seq_no,
  277. zfcp_get_busid_by_adapter(adapter),
  278. prot_status_qual->sequence_error.exp_req_seq_no);
  279. zfcp_erp_adapter_reopen(adapter, 0, 98, fsf_req);
  280. fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  281. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  282. break;
  283. case FSF_PROT_UNSUPP_QTCB_TYPE:
  284. ZFCP_LOG_NORMAL("error: Packet header type used by the "
  285. "device driver is incompatible with "
  286. "that used on adapter %s. "
  287. "Stopping all operations on this adapter.\n",
  288. zfcp_get_busid_by_adapter(adapter));
  289. zfcp_erp_adapter_shutdown(adapter, 0, 118, fsf_req);
  290. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  291. break;
  292. case FSF_PROT_HOST_CONNECTION_INITIALIZING:
  293. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  294. atomic_set_mask(ZFCP_STATUS_ADAPTER_HOST_CON_INIT,
  295. &(adapter->status));
  296. break;
  297. case FSF_PROT_DUPLICATE_REQUEST_ID:
  298. ZFCP_LOG_NORMAL("bug: The request identifier 0x%Lx "
  299. "to the adapter %s is ambiguous. "
  300. "Stopping all operations on this adapter.\n",
  301. *(unsigned long long*)
  302. (&qtcb->bottom.support.req_handle),
  303. zfcp_get_busid_by_adapter(adapter));
  304. zfcp_erp_adapter_shutdown(adapter, 0, 78, fsf_req);
  305. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  306. break;
  307. case FSF_PROT_LINK_DOWN:
  308. zfcp_fsf_link_down_info_eval(fsf_req, 37,
  309. &prot_status_qual->link_down_info);
  310. /* FIXME: reopening adapter now? better wait for link up */
  311. zfcp_erp_adapter_reopen(adapter, 0, 79, fsf_req);
  312. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  313. break;
  314. case FSF_PROT_REEST_QUEUE:
  315. ZFCP_LOG_NORMAL("The local link to adapter with "
  316. "%s was re-plugged. "
  317. "Re-starting operations on this adapter.\n",
  318. zfcp_get_busid_by_adapter(adapter));
  319. /* All ports should be marked as ready to run again */
  320. zfcp_erp_modify_adapter_status(adapter, 28, NULL,
  321. ZFCP_STATUS_COMMON_RUNNING,
  322. ZFCP_SET);
  323. zfcp_erp_adapter_reopen(adapter,
  324. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
  325. | ZFCP_STATUS_COMMON_ERP_FAILED,
  326. 99, fsf_req);
  327. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  328. break;
  329. case FSF_PROT_ERROR_STATE:
  330. ZFCP_LOG_NORMAL("error: The adapter %s "
  331. "has entered the error state. "
  332. "Restarting all operations on this "
  333. "adapter.\n",
  334. zfcp_get_busid_by_adapter(adapter));
  335. zfcp_erp_adapter_reopen(adapter, 0, 100, fsf_req);
  336. fsf_req->status |= ZFCP_STATUS_FSFREQ_RETRY;
  337. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  338. break;
  339. default:
  340. ZFCP_LOG_NORMAL("bug: Transfer protocol status information "
  341. "provided by the adapter %s "
  342. "is not compatible with the device driver. "
  343. "Stopping all operations on this adapter. "
  344. "(debug info 0x%x).\n",
  345. zfcp_get_busid_by_adapter(adapter),
  346. qtcb->prefix.prot_status);
  347. zfcp_erp_adapter_shutdown(adapter, 0, 119, fsf_req);
  348. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  349. }
  350. skip_protstatus:
  351. /*
  352. * always call specific handlers to give them a chance to do
  353. * something meaningful even in error cases
  354. */
  355. zfcp_fsf_fsfstatus_eval(fsf_req);
  356. return retval;
  357. }
  358. /*
  359. * function: zfcp_fsf_fsfstatus_eval
  360. *
  361. * purpose: evaluates FSF status of completed FSF request
  362. * and acts accordingly
  363. *
  364. * returns:
  365. */
  366. static int
  367. zfcp_fsf_fsfstatus_eval(struct zfcp_fsf_req *fsf_req)
  368. {
  369. int retval = 0;
  370. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  371. goto skip_fsfstatus;
  372. }
  373. /* evaluate FSF Status */
  374. switch (fsf_req->qtcb->header.fsf_status) {
  375. case FSF_UNKNOWN_COMMAND:
  376. ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
  377. "not known by the adapter %s "
  378. "Stopping all operations on this adapter. "
  379. "(debug info 0x%x).\n",
  380. zfcp_get_busid_by_adapter(fsf_req->adapter),
  381. fsf_req->qtcb->header.fsf_command);
  382. zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 120, fsf_req);
  383. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  384. break;
  385. case FSF_FCP_RSP_AVAILABLE:
  386. ZFCP_LOG_DEBUG("FCP Sense data will be presented to the "
  387. "SCSI stack.\n");
  388. break;
  389. case FSF_ADAPTER_STATUS_AVAILABLE:
  390. zfcp_fsf_fsfstatus_qual_eval(fsf_req);
  391. break;
  392. }
  393. skip_fsfstatus:
  394. /*
  395. * always call specific handlers to give them a chance to do
  396. * something meaningful even in error cases
  397. */
  398. zfcp_fsf_req_dispatch(fsf_req);
  399. return retval;
  400. }
  401. /*
  402. * function: zfcp_fsf_fsfstatus_qual_eval
  403. *
  404. * purpose: evaluates FSF status-qualifier of completed FSF request
  405. * and acts accordingly
  406. *
  407. * returns:
  408. */
  409. static int
  410. zfcp_fsf_fsfstatus_qual_eval(struct zfcp_fsf_req *fsf_req)
  411. {
  412. int retval = 0;
  413. switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  414. case FSF_SQ_FCP_RSP_AVAILABLE:
  415. break;
  416. case FSF_SQ_RETRY_IF_POSSIBLE:
  417. /* The SCSI-stack may now issue retries or escalate */
  418. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  419. break;
  420. case FSF_SQ_COMMAND_ABORTED:
  421. /* Carry the aborted state on to upper layer */
  422. fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTED;
  423. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  424. break;
  425. case FSF_SQ_NO_RECOM:
  426. ZFCP_LOG_NORMAL("bug: No recommendation could be given for a "
  427. "problem on the adapter %s "
  428. "Stopping all operations on this adapter. ",
  429. zfcp_get_busid_by_adapter(fsf_req->adapter));
  430. zfcp_erp_adapter_shutdown(fsf_req->adapter, 0, 121, fsf_req);
  431. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  432. break;
  433. case FSF_SQ_ULP_PROGRAMMING_ERROR:
  434. ZFCP_LOG_NORMAL("error: not enough SBALs for data transfer "
  435. "(adapter %s)\n",
  436. zfcp_get_busid_by_adapter(fsf_req->adapter));
  437. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  438. break;
  439. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  440. case FSF_SQ_NO_RETRY_POSSIBLE:
  441. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  442. /* dealt with in the respective functions */
  443. break;
  444. default:
  445. ZFCP_LOG_NORMAL("bug: Additional status info could "
  446. "not be interpreted properly.\n");
  447. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  448. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  449. sizeof (union fsf_status_qual));
  450. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  451. break;
  452. }
  453. return retval;
  454. }
  455. /**
  456. * zfcp_fsf_link_down_info_eval - evaluate link down information block
  457. */
  458. static void
  459. zfcp_fsf_link_down_info_eval(struct zfcp_fsf_req *fsf_req, u8 id,
  460. struct fsf_link_down_info *link_down)
  461. {
  462. struct zfcp_adapter *adapter = fsf_req->adapter;
  463. if (atomic_test_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED,
  464. &adapter->status))
  465. return;
  466. atomic_set_mask(ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED, &adapter->status);
  467. if (link_down == NULL)
  468. goto out;
  469. switch (link_down->error_code) {
  470. case FSF_PSQ_LINK_NO_LIGHT:
  471. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  472. "(no light detected)\n",
  473. zfcp_get_busid_by_adapter(adapter));
  474. break;
  475. case FSF_PSQ_LINK_WRAP_PLUG:
  476. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  477. "(wrap plug detected)\n",
  478. zfcp_get_busid_by_adapter(adapter));
  479. break;
  480. case FSF_PSQ_LINK_NO_FCP:
  481. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  482. "(adjacent node on link does not support FCP)\n",
  483. zfcp_get_busid_by_adapter(adapter));
  484. break;
  485. case FSF_PSQ_LINK_FIRMWARE_UPDATE:
  486. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  487. "(firmware update in progress)\n",
  488. zfcp_get_busid_by_adapter(adapter));
  489. break;
  490. case FSF_PSQ_LINK_INVALID_WWPN:
  491. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  492. "(duplicate or invalid WWPN detected)\n",
  493. zfcp_get_busid_by_adapter(adapter));
  494. break;
  495. case FSF_PSQ_LINK_NO_NPIV_SUPPORT:
  496. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  497. "(no support for NPIV by Fabric)\n",
  498. zfcp_get_busid_by_adapter(adapter));
  499. break;
  500. case FSF_PSQ_LINK_NO_FCP_RESOURCES:
  501. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  502. "(out of resource in FCP daughtercard)\n",
  503. zfcp_get_busid_by_adapter(adapter));
  504. break;
  505. case FSF_PSQ_LINK_NO_FABRIC_RESOURCES:
  506. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  507. "(out of resource in Fabric)\n",
  508. zfcp_get_busid_by_adapter(adapter));
  509. break;
  510. case FSF_PSQ_LINK_FABRIC_LOGIN_UNABLE:
  511. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  512. "(unable to Fabric login)\n",
  513. zfcp_get_busid_by_adapter(adapter));
  514. break;
  515. case FSF_PSQ_LINK_WWPN_ASSIGNMENT_CORRUPTED:
  516. ZFCP_LOG_NORMAL("WWPN assignment file corrupted on adapter %s\n",
  517. zfcp_get_busid_by_adapter(adapter));
  518. break;
  519. case FSF_PSQ_LINK_MODE_TABLE_CURRUPTED:
  520. ZFCP_LOG_NORMAL("Mode table corrupted on adapter %s\n",
  521. zfcp_get_busid_by_adapter(adapter));
  522. break;
  523. case FSF_PSQ_LINK_NO_WWPN_ASSIGNMENT:
  524. ZFCP_LOG_NORMAL("No WWPN for assignment table on adapter %s\n",
  525. zfcp_get_busid_by_adapter(adapter));
  526. break;
  527. default:
  528. ZFCP_LOG_NORMAL("The local link to adapter %s is down "
  529. "(warning: unknown reason code %d)\n",
  530. zfcp_get_busid_by_adapter(adapter),
  531. link_down->error_code);
  532. }
  533. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  534. ZFCP_LOG_DEBUG("Debug information to link down: "
  535. "primary_status=0x%02x "
  536. "ioerr_code=0x%02x "
  537. "action_code=0x%02x "
  538. "reason_code=0x%02x "
  539. "explanation_code=0x%02x "
  540. "vendor_specific_code=0x%02x\n",
  541. link_down->primary_status,
  542. link_down->ioerr_code,
  543. link_down->action_code,
  544. link_down->reason_code,
  545. link_down->explanation_code,
  546. link_down->vendor_specific_code);
  547. out:
  548. zfcp_erp_adapter_failed(adapter, id, fsf_req);
  549. }
  550. /*
  551. * function: zfcp_fsf_req_dispatch
  552. *
  553. * purpose: calls the appropriate command specific handler
  554. *
  555. * returns:
  556. */
  557. static int
  558. zfcp_fsf_req_dispatch(struct zfcp_fsf_req *fsf_req)
  559. {
  560. struct zfcp_erp_action *erp_action = fsf_req->erp_action;
  561. struct zfcp_adapter *adapter = fsf_req->adapter;
  562. int retval = 0;
  563. switch (fsf_req->fsf_command) {
  564. case FSF_QTCB_FCP_CMND:
  565. zfcp_fsf_send_fcp_command_handler(fsf_req);
  566. break;
  567. case FSF_QTCB_ABORT_FCP_CMND:
  568. zfcp_fsf_abort_fcp_command_handler(fsf_req);
  569. break;
  570. case FSF_QTCB_SEND_GENERIC:
  571. zfcp_fsf_send_ct_handler(fsf_req);
  572. break;
  573. case FSF_QTCB_OPEN_PORT_WITH_DID:
  574. zfcp_fsf_open_port_handler(fsf_req);
  575. break;
  576. case FSF_QTCB_OPEN_LUN:
  577. zfcp_fsf_open_unit_handler(fsf_req);
  578. break;
  579. case FSF_QTCB_CLOSE_LUN:
  580. zfcp_fsf_close_unit_handler(fsf_req);
  581. break;
  582. case FSF_QTCB_CLOSE_PORT:
  583. zfcp_fsf_close_port_handler(fsf_req);
  584. break;
  585. case FSF_QTCB_CLOSE_PHYSICAL_PORT:
  586. zfcp_fsf_close_physical_port_handler(fsf_req);
  587. break;
  588. case FSF_QTCB_EXCHANGE_CONFIG_DATA:
  589. zfcp_fsf_exchange_config_data_handler(fsf_req);
  590. break;
  591. case FSF_QTCB_EXCHANGE_PORT_DATA:
  592. zfcp_fsf_exchange_port_data_handler(fsf_req);
  593. break;
  594. case FSF_QTCB_SEND_ELS:
  595. zfcp_fsf_send_els_handler(fsf_req);
  596. break;
  597. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  598. zfcp_fsf_control_file_handler(fsf_req);
  599. break;
  600. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  601. zfcp_fsf_control_file_handler(fsf_req);
  602. break;
  603. default:
  604. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  605. ZFCP_LOG_NORMAL("bug: Command issued by the device driver is "
  606. "not supported by the adapter %s\n",
  607. zfcp_get_busid_by_adapter(adapter));
  608. if (fsf_req->fsf_command != fsf_req->qtcb->header.fsf_command)
  609. ZFCP_LOG_NORMAL
  610. ("bug: Command issued by the device driver differs "
  611. "from the command returned by the adapter %s "
  612. "(debug info 0x%x, 0x%x).\n",
  613. zfcp_get_busid_by_adapter(adapter),
  614. fsf_req->fsf_command,
  615. fsf_req->qtcb->header.fsf_command);
  616. }
  617. if (!erp_action)
  618. return retval;
  619. zfcp_erp_async_handler(erp_action, 0);
  620. return retval;
  621. }
  622. /*
  623. * function: zfcp_fsf_status_read
  624. *
  625. * purpose: initiates a Status Read command at the specified adapter
  626. *
  627. * returns:
  628. */
  629. int
  630. zfcp_fsf_status_read(struct zfcp_adapter *adapter, int req_flags)
  631. {
  632. struct zfcp_fsf_req *fsf_req;
  633. struct fsf_status_read_buffer *status_buffer;
  634. unsigned long lock_flags;
  635. volatile struct qdio_buffer_element *sbale;
  636. int retval = 0;
  637. /* setup new FSF request */
  638. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_UNSOLICITED_STATUS,
  639. req_flags | ZFCP_REQ_NO_QTCB,
  640. adapter->pool.fsf_req_status_read,
  641. &lock_flags, &fsf_req);
  642. if (retval < 0) {
  643. ZFCP_LOG_INFO("error: Could not create unsolicited status "
  644. "buffer for adapter %s.\n",
  645. zfcp_get_busid_by_adapter(adapter));
  646. goto failed_req_create;
  647. }
  648. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  649. sbale[0].flags |= SBAL_FLAGS0_TYPE_STATUS;
  650. sbale[2].flags |= SBAL_FLAGS_LAST_ENTRY;
  651. fsf_req->sbale_curr = 2;
  652. status_buffer =
  653. mempool_alloc(adapter->pool.data_status_read, GFP_ATOMIC);
  654. if (!status_buffer) {
  655. ZFCP_LOG_NORMAL("bug: could not get some buffer\n");
  656. goto failed_buf;
  657. }
  658. memset(status_buffer, 0, sizeof (struct fsf_status_read_buffer));
  659. fsf_req->data = (unsigned long) status_buffer;
  660. /* insert pointer to respective buffer */
  661. sbale = zfcp_qdio_sbale_curr(fsf_req);
  662. sbale->addr = (void *) status_buffer;
  663. sbale->length = sizeof(struct fsf_status_read_buffer);
  664. retval = zfcp_fsf_req_send(fsf_req);
  665. if (retval) {
  666. ZFCP_LOG_DEBUG("error: Could not set-up unsolicited status "
  667. "environment.\n");
  668. goto failed_req_send;
  669. }
  670. ZFCP_LOG_TRACE("Status Read request initiated (adapter%s)\n",
  671. zfcp_get_busid_by_adapter(adapter));
  672. goto out;
  673. failed_req_send:
  674. mempool_free(status_buffer, adapter->pool.data_status_read);
  675. failed_buf:
  676. zfcp_fsf_req_free(fsf_req);
  677. failed_req_create:
  678. zfcp_hba_dbf_event_fsf_unsol("fail", adapter, NULL);
  679. out:
  680. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  681. return retval;
  682. }
  683. static int
  684. zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
  685. {
  686. struct fsf_status_read_buffer *status_buffer;
  687. struct zfcp_adapter *adapter;
  688. struct zfcp_port *port;
  689. unsigned long flags;
  690. status_buffer = (struct fsf_status_read_buffer *) fsf_req->data;
  691. adapter = fsf_req->adapter;
  692. read_lock_irqsave(&zfcp_data.config_lock, flags);
  693. list_for_each_entry(port, &adapter->port_list_head, list)
  694. if (port->d_id == (status_buffer->d_id & ZFCP_DID_MASK))
  695. break;
  696. read_unlock_irqrestore(&zfcp_data.config_lock, flags);
  697. if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
  698. ZFCP_LOG_NORMAL("bug: Reopen port indication received for "
  699. "nonexisting port with d_id 0x%06x on "
  700. "adapter %s. Ignored.\n",
  701. status_buffer->d_id & ZFCP_DID_MASK,
  702. zfcp_get_busid_by_adapter(adapter));
  703. goto out;
  704. }
  705. switch (status_buffer->status_subtype) {
  706. case FSF_STATUS_READ_SUB_CLOSE_PHYS_PORT:
  707. zfcp_erp_port_reopen(port, 0, 101, fsf_req);
  708. break;
  709. case FSF_STATUS_READ_SUB_ERROR_PORT:
  710. zfcp_erp_port_shutdown(port, 0, 122, fsf_req);
  711. break;
  712. default:
  713. ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
  714. "for a reopen indication on port with "
  715. "d_id 0x%06x on the adapter %s. "
  716. "Ignored. (debug info 0x%x)\n",
  717. status_buffer->d_id,
  718. zfcp_get_busid_by_adapter(adapter),
  719. status_buffer->status_subtype);
  720. }
  721. out:
  722. return 0;
  723. }
  724. /*
  725. * function: zfcp_fsf_status_read_handler
  726. *
  727. * purpose: is called for finished Open Port command
  728. *
  729. * returns:
  730. */
  731. static int
  732. zfcp_fsf_status_read_handler(struct zfcp_fsf_req *fsf_req)
  733. {
  734. int retval = 0;
  735. struct zfcp_adapter *adapter = fsf_req->adapter;
  736. struct fsf_status_read_buffer *status_buffer =
  737. (struct fsf_status_read_buffer *) fsf_req->data;
  738. struct fsf_bit_error_payload *fsf_bit_error;
  739. if (fsf_req->status & ZFCP_STATUS_FSFREQ_DISMISSED) {
  740. zfcp_hba_dbf_event_fsf_unsol("dism", adapter, status_buffer);
  741. mempool_free(status_buffer, adapter->pool.data_status_read);
  742. zfcp_fsf_req_free(fsf_req);
  743. goto out;
  744. }
  745. zfcp_hba_dbf_event_fsf_unsol("read", adapter, status_buffer);
  746. switch (status_buffer->status_type) {
  747. case FSF_STATUS_READ_PORT_CLOSED:
  748. zfcp_fsf_status_read_port_closed(fsf_req);
  749. break;
  750. case FSF_STATUS_READ_INCOMING_ELS:
  751. zfcp_fsf_incoming_els(fsf_req);
  752. break;
  753. case FSF_STATUS_READ_SENSE_DATA_AVAIL:
  754. ZFCP_LOG_INFO("unsolicited sense data received (adapter %s)\n",
  755. zfcp_get_busid_by_adapter(adapter));
  756. break;
  757. case FSF_STATUS_READ_BIT_ERROR_THRESHOLD:
  758. fsf_bit_error = (struct fsf_bit_error_payload *)
  759. status_buffer->payload;
  760. ZFCP_LOG_NORMAL("Warning: bit error threshold data "
  761. "received (adapter %s, "
  762. "link failures = %i, loss of sync errors = %i, "
  763. "loss of signal errors = %i, "
  764. "primitive sequence errors = %i, "
  765. "invalid transmission word errors = %i, "
  766. "CRC errors = %i)\n",
  767. zfcp_get_busid_by_adapter(adapter),
  768. fsf_bit_error->link_failure_error_count,
  769. fsf_bit_error->loss_of_sync_error_count,
  770. fsf_bit_error->loss_of_signal_error_count,
  771. fsf_bit_error->primitive_sequence_error_count,
  772. fsf_bit_error->invalid_transmission_word_error_count,
  773. fsf_bit_error->crc_error_count);
  774. ZFCP_LOG_INFO("Additional bit error threshold data "
  775. "(adapter %s, "
  776. "primitive sequence event time-outs = %i, "
  777. "elastic buffer overrun errors = %i, "
  778. "advertised receive buffer-to-buffer credit = %i, "
  779. "current receice buffer-to-buffer credit = %i, "
  780. "advertised transmit buffer-to-buffer credit = %i, "
  781. "current transmit buffer-to-buffer credit = %i)\n",
  782. zfcp_get_busid_by_adapter(adapter),
  783. fsf_bit_error->primitive_sequence_event_timeout_count,
  784. fsf_bit_error->elastic_buffer_overrun_error_count,
  785. fsf_bit_error->advertised_receive_b2b_credit,
  786. fsf_bit_error->current_receive_b2b_credit,
  787. fsf_bit_error->advertised_transmit_b2b_credit,
  788. fsf_bit_error->current_transmit_b2b_credit);
  789. break;
  790. case FSF_STATUS_READ_LINK_DOWN:
  791. switch (status_buffer->status_subtype) {
  792. case FSF_STATUS_READ_SUB_NO_PHYSICAL_LINK:
  793. ZFCP_LOG_INFO("Physical link to adapter %s is down\n",
  794. zfcp_get_busid_by_adapter(adapter));
  795. zfcp_fsf_link_down_info_eval(fsf_req, 38,
  796. (struct fsf_link_down_info *)
  797. &status_buffer->payload);
  798. break;
  799. case FSF_STATUS_READ_SUB_FDISC_FAILED:
  800. ZFCP_LOG_INFO("Local link to adapter %s is down "
  801. "due to failed FDISC login\n",
  802. zfcp_get_busid_by_adapter(adapter));
  803. zfcp_fsf_link_down_info_eval(fsf_req, 39,
  804. (struct fsf_link_down_info *)
  805. &status_buffer->payload);
  806. break;
  807. case FSF_STATUS_READ_SUB_FIRMWARE_UPDATE:
  808. ZFCP_LOG_INFO("Local link to adapter %s is down "
  809. "due to firmware update on adapter\n",
  810. zfcp_get_busid_by_adapter(adapter));
  811. zfcp_fsf_link_down_info_eval(fsf_req, 40, NULL);
  812. break;
  813. default:
  814. ZFCP_LOG_INFO("Local link to adapter %s is down "
  815. "due to unknown reason\n",
  816. zfcp_get_busid_by_adapter(adapter));
  817. zfcp_fsf_link_down_info_eval(fsf_req, 41, NULL);
  818. };
  819. break;
  820. case FSF_STATUS_READ_LINK_UP:
  821. ZFCP_LOG_NORMAL("Local link to adapter %s was replugged. "
  822. "Restarting operations on this adapter\n",
  823. zfcp_get_busid_by_adapter(adapter));
  824. /* All ports should be marked as ready to run again */
  825. zfcp_erp_modify_adapter_status(adapter, 30, NULL,
  826. ZFCP_STATUS_COMMON_RUNNING,
  827. ZFCP_SET);
  828. zfcp_erp_adapter_reopen(adapter,
  829. ZFCP_STATUS_ADAPTER_LINK_UNPLUGGED
  830. | ZFCP_STATUS_COMMON_ERP_FAILED,
  831. 102, fsf_req);
  832. break;
  833. case FSF_STATUS_READ_NOTIFICATION_LOST:
  834. ZFCP_LOG_NORMAL("Unsolicited status notification(s) lost: "
  835. "adapter %s%s%s%s%s%s%s%s%s\n",
  836. zfcp_get_busid_by_adapter(adapter),
  837. (status_buffer->status_subtype &
  838. FSF_STATUS_READ_SUB_INCOMING_ELS) ?
  839. ", incoming ELS" : "",
  840. (status_buffer->status_subtype &
  841. FSF_STATUS_READ_SUB_SENSE_DATA) ?
  842. ", sense data" : "",
  843. (status_buffer->status_subtype &
  844. FSF_STATUS_READ_SUB_LINK_STATUS) ?
  845. ", link status change" : "",
  846. (status_buffer->status_subtype &
  847. FSF_STATUS_READ_SUB_PORT_CLOSED) ?
  848. ", port close" : "",
  849. (status_buffer->status_subtype &
  850. FSF_STATUS_READ_SUB_BIT_ERROR_THRESHOLD) ?
  851. ", bit error exception" : "",
  852. (status_buffer->status_subtype &
  853. FSF_STATUS_READ_SUB_ACT_UPDATED) ?
  854. ", ACT update" : "",
  855. (status_buffer->status_subtype &
  856. FSF_STATUS_READ_SUB_ACT_HARDENED) ?
  857. ", ACT hardening" : "",
  858. (status_buffer->status_subtype &
  859. FSF_STATUS_READ_SUB_FEATURE_UPDATE_ALERT) ?
  860. ", adapter feature change" : "");
  861. if (status_buffer->status_subtype &
  862. FSF_STATUS_READ_SUB_ACT_UPDATED)
  863. zfcp_erp_adapter_access_changed(adapter, 135, fsf_req);
  864. break;
  865. case FSF_STATUS_READ_CFDC_UPDATED:
  866. ZFCP_LOG_NORMAL("CFDC has been updated on the adapter %s\n",
  867. zfcp_get_busid_by_adapter(adapter));
  868. zfcp_erp_adapter_access_changed(adapter, 136, fsf_req);
  869. break;
  870. case FSF_STATUS_READ_CFDC_HARDENED:
  871. switch (status_buffer->status_subtype) {
  872. case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE:
  873. ZFCP_LOG_NORMAL("CFDC of adapter %s saved on SE\n",
  874. zfcp_get_busid_by_adapter(adapter));
  875. break;
  876. case FSF_STATUS_READ_SUB_CFDC_HARDENED_ON_SE2:
  877. ZFCP_LOG_NORMAL("CFDC of adapter %s has been copied "
  878. "to the secondary SE\n",
  879. zfcp_get_busid_by_adapter(adapter));
  880. break;
  881. default:
  882. ZFCP_LOG_NORMAL("CFDC of adapter %s has been hardened\n",
  883. zfcp_get_busid_by_adapter(adapter));
  884. }
  885. break;
  886. case FSF_STATUS_READ_FEATURE_UPDATE_ALERT:
  887. ZFCP_LOG_INFO("List of supported features on adapter %s has "
  888. "been changed from 0x%08X to 0x%08X\n",
  889. zfcp_get_busid_by_adapter(adapter),
  890. *(u32*) (status_buffer->payload + 4),
  891. *(u32*) (status_buffer->payload));
  892. adapter->adapter_features = *(u32*) status_buffer->payload;
  893. break;
  894. default:
  895. ZFCP_LOG_NORMAL("warning: An unsolicited status packet of unknown "
  896. "type was received (debug info 0x%x)\n",
  897. status_buffer->status_type);
  898. ZFCP_LOG_DEBUG("Dump of status_read_buffer %p:\n",
  899. status_buffer);
  900. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  901. (char *) status_buffer,
  902. sizeof (struct fsf_status_read_buffer));
  903. break;
  904. }
  905. mempool_free(status_buffer, adapter->pool.data_status_read);
  906. zfcp_fsf_req_free(fsf_req);
  907. /*
  908. * recycle buffer and start new request repeat until outbound
  909. * queue is empty or adapter shutdown is requested
  910. */
  911. /*
  912. * FIXME(qdio):
  913. * we may wait in the req_create for 5s during shutdown, so
  914. * qdio_cleanup will have to wait at least that long before returning
  915. * with failure to allow us a proper cleanup under all circumstances
  916. */
  917. /*
  918. * FIXME:
  919. * allocation failure possible? (Is this code needed?)
  920. */
  921. atomic_inc(&adapter->stat_miss);
  922. schedule_work(&adapter->stat_work);
  923. out:
  924. return retval;
  925. }
  926. /*
  927. * function: zfcp_fsf_abort_fcp_command
  928. *
  929. * purpose: tells FSF to abort a running SCSI command
  930. *
  931. * returns: address of initiated FSF request
  932. * NULL - request could not be initiated
  933. *
  934. * FIXME(design): should be watched by a timeout !!!
  935. * FIXME(design) shouldn't this be modified to return an int
  936. * also...don't know how though
  937. */
  938. struct zfcp_fsf_req *
  939. zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  940. struct zfcp_adapter *adapter,
  941. struct zfcp_unit *unit, int req_flags)
  942. {
  943. volatile struct qdio_buffer_element *sbale;
  944. struct zfcp_fsf_req *fsf_req = NULL;
  945. unsigned long lock_flags;
  946. int retval = 0;
  947. /* setup new FSF request */
  948. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  949. req_flags, adapter->pool.fsf_req_abort,
  950. &lock_flags, &fsf_req);
  951. if (retval < 0) {
  952. ZFCP_LOG_INFO("error: Failed to create an abort command "
  953. "request for lun 0x%016Lx on port 0x%016Lx "
  954. "on adapter %s.\n",
  955. unit->fcp_lun,
  956. unit->port->wwpn,
  957. zfcp_get_busid_by_adapter(adapter));
  958. goto out;
  959. }
  960. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  961. &unit->status)))
  962. goto unit_blocked;
  963. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  964. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  965. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  966. fsf_req->data = (unsigned long) unit;
  967. /* set handles of unit and its parent port in QTCB */
  968. fsf_req->qtcb->header.lun_handle = unit->handle;
  969. fsf_req->qtcb->header.port_handle = unit->port->handle;
  970. /* set handle of request which should be aborted */
  971. fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  972. zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
  973. retval = zfcp_fsf_req_send(fsf_req);
  974. if (!retval)
  975. goto out;
  976. unit_blocked:
  977. zfcp_fsf_req_free(fsf_req);
  978. fsf_req = NULL;
  979. out:
  980. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  981. return fsf_req;
  982. }
  983. /*
  984. * function: zfcp_fsf_abort_fcp_command_handler
  985. *
  986. * purpose: is called for finished Abort FCP Command request
  987. *
  988. * returns:
  989. */
  990. static int
  991. zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
  992. {
  993. int retval = -EINVAL;
  994. struct zfcp_unit *unit;
  995. union fsf_status_qual *fsf_stat_qual =
  996. &new_fsf_req->qtcb->header.fsf_status_qual;
  997. if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  998. /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
  999. goto skip_fsfstatus;
  1000. }
  1001. unit = (struct zfcp_unit *) new_fsf_req->data;
  1002. /* evaluate FSF status in QTCB */
  1003. switch (new_fsf_req->qtcb->header.fsf_status) {
  1004. case FSF_PORT_HANDLE_NOT_VALID:
  1005. if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
  1006. /*
  1007. * In this case a command that was sent prior to a port
  1008. * reopen was aborted (handles are different). This is
  1009. * fine.
  1010. */
  1011. } else {
  1012. ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
  1013. "port 0x%016Lx on adapter %s invalid. "
  1014. "This may happen occasionally.\n",
  1015. unit->port->handle,
  1016. unit->port->wwpn,
  1017. zfcp_get_busid_by_unit(unit));
  1018. ZFCP_LOG_INFO("status qualifier:\n");
  1019. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1020. (char *) &new_fsf_req->qtcb->header.
  1021. fsf_status_qual,
  1022. sizeof (union fsf_status_qual));
  1023. /* Let's hope this sorts out the mess */
  1024. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  1025. new_fsf_req);
  1026. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1027. }
  1028. break;
  1029. case FSF_LUN_HANDLE_NOT_VALID:
  1030. if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
  1031. /*
  1032. * In this case a command that was sent prior to a unit
  1033. * reopen was aborted (handles are different).
  1034. * This is fine.
  1035. */
  1036. } else {
  1037. ZFCP_LOG_INFO
  1038. ("Warning: Temporary LUN identifier 0x%x of LUN "
  1039. "0x%016Lx on port 0x%016Lx on adapter %s is "
  1040. "invalid. This may happen in rare cases. "
  1041. "Trying to re-establish link.\n",
  1042. unit->handle,
  1043. unit->fcp_lun,
  1044. unit->port->wwpn,
  1045. zfcp_get_busid_by_unit(unit));
  1046. ZFCP_LOG_DEBUG("Status qualifier data:\n");
  1047. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  1048. (char *) &new_fsf_req->qtcb->header.
  1049. fsf_status_qual,
  1050. sizeof (union fsf_status_qual));
  1051. /* Let's hope this sorts out the mess */
  1052. zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
  1053. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1054. }
  1055. break;
  1056. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  1057. retval = 0;
  1058. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  1059. break;
  1060. case FSF_PORT_BOXED:
  1061. ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
  1062. "be reopened\n", unit->port->wwpn,
  1063. zfcp_get_busid_by_unit(unit));
  1064. zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
  1065. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1066. | ZFCP_STATUS_FSFREQ_RETRY;
  1067. break;
  1068. case FSF_LUN_BOXED:
  1069. ZFCP_LOG_INFO(
  1070. "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
  1071. "to be reopened\n",
  1072. unit->fcp_lun, unit->port->wwpn,
  1073. zfcp_get_busid_by_unit(unit));
  1074. zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
  1075. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1076. | ZFCP_STATUS_FSFREQ_RETRY;
  1077. break;
  1078. case FSF_ADAPTER_STATUS_AVAILABLE:
  1079. switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  1080. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1081. zfcp_test_link(unit->port);
  1082. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1083. break;
  1084. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1085. /* SCSI stack will escalate */
  1086. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1087. break;
  1088. default:
  1089. ZFCP_LOG_NORMAL
  1090. ("bug: Wrong status qualifier 0x%x arrived.\n",
  1091. new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
  1092. break;
  1093. }
  1094. break;
  1095. case FSF_GOOD:
  1096. retval = 0;
  1097. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  1098. break;
  1099. default:
  1100. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  1101. "(debug info 0x%x)\n",
  1102. new_fsf_req->qtcb->header.fsf_status);
  1103. break;
  1104. }
  1105. skip_fsfstatus:
  1106. return retval;
  1107. }
  1108. /**
  1109. * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
  1110. * one SBALE
  1111. * Two scatter-gather lists are passed, one for the reqeust and one for the
  1112. * response.
  1113. */
  1114. static inline int
  1115. zfcp_use_one_sbal(struct scatterlist *req, int req_count,
  1116. struct scatterlist *resp, int resp_count)
  1117. {
  1118. return ((req_count == 1) &&
  1119. (resp_count == 1) &&
  1120. (((unsigned long) zfcp_sg_to_address(&req[0]) &
  1121. PAGE_MASK) ==
  1122. ((unsigned long) (zfcp_sg_to_address(&req[0]) +
  1123. req[0].length - 1) & PAGE_MASK)) &&
  1124. (((unsigned long) zfcp_sg_to_address(&resp[0]) &
  1125. PAGE_MASK) ==
  1126. ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
  1127. resp[0].length - 1) & PAGE_MASK)));
  1128. }
  1129. /**
  1130. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  1131. * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
  1132. * the request
  1133. * @pool: pointer to memory pool, if non-null this pool is used to allocate
  1134. * a struct zfcp_fsf_req
  1135. * @erp_action: pointer to erp_action, if non-null the Generic Service request
  1136. * is sent within error recovery
  1137. */
  1138. int
  1139. zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  1140. struct zfcp_erp_action *erp_action)
  1141. {
  1142. volatile struct qdio_buffer_element *sbale;
  1143. struct zfcp_port *port;
  1144. struct zfcp_adapter *adapter;
  1145. struct zfcp_fsf_req *fsf_req;
  1146. unsigned long lock_flags;
  1147. int bytes;
  1148. int ret = 0;
  1149. port = ct->port;
  1150. adapter = port->adapter;
  1151. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  1152. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  1153. pool, &lock_flags, &fsf_req);
  1154. if (ret < 0) {
  1155. ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
  1156. "adapter: %s\n",
  1157. zfcp_get_busid_by_adapter(adapter));
  1158. goto failed_req;
  1159. }
  1160. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1161. if (zfcp_use_one_sbal(ct->req, ct->req_count,
  1162. ct->resp, ct->resp_count)){
  1163. /* both request buffer and response buffer
  1164. fit into one sbale each */
  1165. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  1166. sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
  1167. sbale[2].length = ct->req[0].length;
  1168. sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
  1169. sbale[3].length = ct->resp[0].length;
  1170. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  1171. } else if (adapter->adapter_features &
  1172. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  1173. /* try to use chained SBALs */
  1174. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1175. SBAL_FLAGS0_TYPE_WRITE_READ,
  1176. ct->req, ct->req_count,
  1177. ZFCP_MAX_SBALS_PER_CT_REQ);
  1178. if (bytes <= 0) {
  1179. ZFCP_LOG_INFO("error: creation of CT request failed "
  1180. "on adapter %s\n",
  1181. zfcp_get_busid_by_adapter(adapter));
  1182. if (bytes == 0)
  1183. ret = -ENOMEM;
  1184. else
  1185. ret = bytes;
  1186. goto failed_send;
  1187. }
  1188. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1189. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1190. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1191. SBAL_FLAGS0_TYPE_WRITE_READ,
  1192. ct->resp, ct->resp_count,
  1193. ZFCP_MAX_SBALS_PER_CT_REQ);
  1194. if (bytes <= 0) {
  1195. ZFCP_LOG_INFO("error: creation of CT request failed "
  1196. "on adapter %s\n",
  1197. zfcp_get_busid_by_adapter(adapter));
  1198. if (bytes == 0)
  1199. ret = -ENOMEM;
  1200. else
  1201. ret = bytes;
  1202. goto failed_send;
  1203. }
  1204. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1205. } else {
  1206. /* reject send generic request */
  1207. ZFCP_LOG_INFO(
  1208. "error: microcode does not support chained SBALs,"
  1209. "CT request too big (adapter %s)\n",
  1210. zfcp_get_busid_by_adapter(adapter));
  1211. ret = -EOPNOTSUPP;
  1212. goto failed_send;
  1213. }
  1214. /* settings in QTCB */
  1215. fsf_req->qtcb->header.port_handle = port->handle;
  1216. fsf_req->qtcb->bottom.support.service_class =
  1217. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1218. fsf_req->qtcb->bottom.support.timeout = ct->timeout;
  1219. fsf_req->data = (unsigned long) ct;
  1220. zfcp_san_dbf_event_ct_request(fsf_req);
  1221. if (erp_action) {
  1222. erp_action->fsf_req = fsf_req;
  1223. fsf_req->erp_action = erp_action;
  1224. zfcp_erp_start_timer(fsf_req);
  1225. } else
  1226. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1227. ret = zfcp_fsf_req_send(fsf_req);
  1228. if (ret) {
  1229. ZFCP_LOG_DEBUG("error: initiation of CT request failed "
  1230. "(adapter %s, port 0x%016Lx)\n",
  1231. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  1232. goto failed_send;
  1233. }
  1234. ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
  1235. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  1236. goto out;
  1237. failed_send:
  1238. zfcp_fsf_req_free(fsf_req);
  1239. if (erp_action != NULL) {
  1240. erp_action->fsf_req = NULL;
  1241. }
  1242. failed_req:
  1243. out:
  1244. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1245. lock_flags);
  1246. return ret;
  1247. }
  1248. /**
  1249. * zfcp_fsf_send_ct_handler - handler for Generic Service requests
  1250. * @fsf_req: pointer to struct zfcp_fsf_req
  1251. *
  1252. * Data specific for the Generic Service request is passed using
  1253. * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
  1254. * Usually a specific handler for the CT request is called which is
  1255. * found in this structure.
  1256. */
  1257. static int
  1258. zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
  1259. {
  1260. struct zfcp_port *port;
  1261. struct zfcp_adapter *adapter;
  1262. struct zfcp_send_ct *send_ct;
  1263. struct fsf_qtcb_header *header;
  1264. struct fsf_qtcb_bottom_support *bottom;
  1265. int retval = -EINVAL;
  1266. u16 subtable, rule, counter;
  1267. adapter = fsf_req->adapter;
  1268. send_ct = (struct zfcp_send_ct *) fsf_req->data;
  1269. port = send_ct->port;
  1270. header = &fsf_req->qtcb->header;
  1271. bottom = &fsf_req->qtcb->bottom.support;
  1272. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1273. goto skip_fsfstatus;
  1274. /* evaluate FSF status in QTCB */
  1275. switch (header->fsf_status) {
  1276. case FSF_GOOD:
  1277. zfcp_san_dbf_event_ct_response(fsf_req);
  1278. retval = 0;
  1279. break;
  1280. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1281. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  1282. "class %d.\n",
  1283. zfcp_get_busid_by_port(port),
  1284. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  1285. /* stop operation for this adapter */
  1286. zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
  1287. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1288. break;
  1289. case FSF_ADAPTER_STATUS_AVAILABLE:
  1290. switch (header->fsf_status_qual.word[0]){
  1291. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1292. /* reopening link to port */
  1293. zfcp_test_link(port);
  1294. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1295. break;
  1296. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1297. /* ERP strategy will escalate */
  1298. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1299. break;
  1300. default:
  1301. ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
  1302. "arrived.\n",
  1303. header->fsf_status_qual.word[0]);
  1304. break;
  1305. }
  1306. break;
  1307. case FSF_ACCESS_DENIED:
  1308. ZFCP_LOG_NORMAL("access denied, cannot send generic service "
  1309. "command (adapter %s, port d_id=0x%06x)\n",
  1310. zfcp_get_busid_by_port(port), port->d_id);
  1311. for (counter = 0; counter < 2; counter++) {
  1312. subtable = header->fsf_status_qual.halfword[counter * 2];
  1313. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  1314. switch (subtable) {
  1315. case FSF_SQ_CFDC_SUBTABLE_OS:
  1316. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  1317. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  1318. case FSF_SQ_CFDC_SUBTABLE_LUN:
  1319. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  1320. zfcp_act_subtable_type[subtable], rule);
  1321. break;
  1322. }
  1323. }
  1324. zfcp_erp_port_access_denied(port, 55, fsf_req);
  1325. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1326. break;
  1327. case FSF_GENERIC_COMMAND_REJECTED:
  1328. ZFCP_LOG_INFO("generic service command rejected "
  1329. "(adapter %s, port d_id=0x%06x)\n",
  1330. zfcp_get_busid_by_port(port), port->d_id);
  1331. ZFCP_LOG_INFO("status qualifier:\n");
  1332. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1333. (char *) &header->fsf_status_qual,
  1334. sizeof (union fsf_status_qual));
  1335. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1336. break;
  1337. case FSF_PORT_HANDLE_NOT_VALID:
  1338. ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
  1339. "0x%016Lx on adapter %s invalid. This may "
  1340. "happen occasionally.\n", port->handle,
  1341. port->wwpn, zfcp_get_busid_by_port(port));
  1342. ZFCP_LOG_INFO("status qualifier:\n");
  1343. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1344. (char *) &header->fsf_status_qual,
  1345. sizeof (union fsf_status_qual));
  1346. zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
  1347. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1348. break;
  1349. case FSF_PORT_BOXED:
  1350. ZFCP_LOG_INFO("port needs to be reopened "
  1351. "(adapter %s, port d_id=0x%06x)\n",
  1352. zfcp_get_busid_by_port(port), port->d_id);
  1353. zfcp_erp_port_boxed(port, 49, fsf_req);
  1354. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1355. | ZFCP_STATUS_FSFREQ_RETRY;
  1356. break;
  1357. /* following states should never occure, all cases avoided
  1358. in zfcp_fsf_send_ct - but who knows ... */
  1359. case FSF_PAYLOAD_SIZE_MISMATCH:
  1360. ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
  1361. "req_buf_length=%d, resp_buf_length=%d)\n",
  1362. zfcp_get_busid_by_adapter(adapter),
  1363. bottom->req_buf_length, bottom->resp_buf_length);
  1364. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1365. break;
  1366. case FSF_REQUEST_SIZE_TOO_LARGE:
  1367. ZFCP_LOG_INFO("request size too large (adapter: %s, "
  1368. "req_buf_length=%d)\n",
  1369. zfcp_get_busid_by_adapter(adapter),
  1370. bottom->req_buf_length);
  1371. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1372. break;
  1373. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1374. ZFCP_LOG_INFO("response size too large (adapter: %s, "
  1375. "resp_buf_length=%d)\n",
  1376. zfcp_get_busid_by_adapter(adapter),
  1377. bottom->resp_buf_length);
  1378. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1379. break;
  1380. case FSF_SBAL_MISMATCH:
  1381. ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
  1382. "resp_buf_length=%d)\n",
  1383. zfcp_get_busid_by_adapter(adapter),
  1384. bottom->req_buf_length, bottom->resp_buf_length);
  1385. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1386. break;
  1387. default:
  1388. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  1389. "(debug info 0x%x)\n", header->fsf_status);
  1390. break;
  1391. }
  1392. skip_fsfstatus:
  1393. send_ct->status = retval;
  1394. if (send_ct->handler != NULL)
  1395. send_ct->handler(send_ct->handler_data);
  1396. return retval;
  1397. }
  1398. /**
  1399. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1400. * @els: pointer to struct zfcp_send_els which contains all needed data for
  1401. * the command.
  1402. */
  1403. int
  1404. zfcp_fsf_send_els(struct zfcp_send_els *els)
  1405. {
  1406. volatile struct qdio_buffer_element *sbale;
  1407. struct zfcp_fsf_req *fsf_req;
  1408. u32 d_id;
  1409. struct zfcp_adapter *adapter;
  1410. unsigned long lock_flags;
  1411. int bytes;
  1412. int ret = 0;
  1413. d_id = els->d_id;
  1414. adapter = els->adapter;
  1415. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1416. ZFCP_REQ_AUTO_CLEANUP,
  1417. NULL, &lock_flags, &fsf_req);
  1418. if (ret < 0) {
  1419. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1420. "(adapter %s, port d_id: 0x%06x)\n",
  1421. zfcp_get_busid_by_adapter(adapter), d_id);
  1422. goto failed_req;
  1423. }
  1424. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  1425. &els->port->status))) {
  1426. ret = -EBUSY;
  1427. goto port_blocked;
  1428. }
  1429. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1430. if (zfcp_use_one_sbal(els->req, els->req_count,
  1431. els->resp, els->resp_count)){
  1432. /* both request buffer and response buffer
  1433. fit into one sbale each */
  1434. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  1435. sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
  1436. sbale[2].length = els->req[0].length;
  1437. sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
  1438. sbale[3].length = els->resp[0].length;
  1439. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  1440. } else if (adapter->adapter_features &
  1441. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  1442. /* try to use chained SBALs */
  1443. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1444. SBAL_FLAGS0_TYPE_WRITE_READ,
  1445. els->req, els->req_count,
  1446. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1447. if (bytes <= 0) {
  1448. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1449. "(adapter %s, port d_id: 0x%06x)\n",
  1450. zfcp_get_busid_by_adapter(adapter), d_id);
  1451. if (bytes == 0) {
  1452. ret = -ENOMEM;
  1453. } else {
  1454. ret = bytes;
  1455. }
  1456. goto failed_send;
  1457. }
  1458. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1459. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1460. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1461. SBAL_FLAGS0_TYPE_WRITE_READ,
  1462. els->resp, els->resp_count,
  1463. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1464. if (bytes <= 0) {
  1465. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1466. "(adapter %s, port d_id: 0x%06x)\n",
  1467. zfcp_get_busid_by_adapter(adapter), d_id);
  1468. if (bytes == 0) {
  1469. ret = -ENOMEM;
  1470. } else {
  1471. ret = bytes;
  1472. }
  1473. goto failed_send;
  1474. }
  1475. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1476. } else {
  1477. /* reject request */
  1478. ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
  1479. ", ELS request too big (adapter %s, "
  1480. "port d_id: 0x%06x)\n",
  1481. zfcp_get_busid_by_adapter(adapter), d_id);
  1482. ret = -EOPNOTSUPP;
  1483. goto failed_send;
  1484. }
  1485. /* settings in QTCB */
  1486. fsf_req->qtcb->bottom.support.d_id = d_id;
  1487. fsf_req->qtcb->bottom.support.service_class =
  1488. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1489. fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
  1490. fsf_req->data = (unsigned long) els;
  1491. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1492. zfcp_san_dbf_event_els_request(fsf_req);
  1493. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1494. ret = zfcp_fsf_req_send(fsf_req);
  1495. if (ret) {
  1496. ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
  1497. "(adapter %s, port d_id: 0x%06x)\n",
  1498. zfcp_get_busid_by_adapter(adapter), d_id);
  1499. goto failed_send;
  1500. }
  1501. ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
  1502. "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
  1503. goto out;
  1504. port_blocked:
  1505. failed_send:
  1506. zfcp_fsf_req_free(fsf_req);
  1507. failed_req:
  1508. out:
  1509. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1510. lock_flags);
  1511. return ret;
  1512. }
  1513. /**
  1514. * zfcp_fsf_send_els_handler - handler for ELS commands
  1515. * @fsf_req: pointer to struct zfcp_fsf_req
  1516. *
  1517. * Data specific for the ELS command is passed using
  1518. * fsf_req->data. There we find the pointer to struct zfcp_send_els.
  1519. * Usually a specific handler for the ELS command is called which is
  1520. * found in this structure.
  1521. */
  1522. static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
  1523. {
  1524. struct zfcp_adapter *adapter;
  1525. struct zfcp_port *port;
  1526. u32 d_id;
  1527. struct fsf_qtcb_header *header;
  1528. struct fsf_qtcb_bottom_support *bottom;
  1529. struct zfcp_send_els *send_els;
  1530. int retval = -EINVAL;
  1531. u16 subtable, rule, counter;
  1532. send_els = (struct zfcp_send_els *) fsf_req->data;
  1533. adapter = send_els->adapter;
  1534. port = send_els->port;
  1535. d_id = send_els->d_id;
  1536. header = &fsf_req->qtcb->header;
  1537. bottom = &fsf_req->qtcb->bottom.support;
  1538. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1539. goto skip_fsfstatus;
  1540. switch (header->fsf_status) {
  1541. case FSF_GOOD:
  1542. zfcp_san_dbf_event_els_response(fsf_req);
  1543. retval = 0;
  1544. break;
  1545. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1546. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  1547. "class %d.\n",
  1548. zfcp_get_busid_by_adapter(adapter),
  1549. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  1550. /* stop operation for this adapter */
  1551. zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
  1552. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1553. break;
  1554. case FSF_ADAPTER_STATUS_AVAILABLE:
  1555. switch (header->fsf_status_qual.word[0]){
  1556. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1557. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1558. zfcp_test_link(port);
  1559. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1560. break;
  1561. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1562. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1563. retval =
  1564. zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
  1565. (struct zfcp_ls_rjt_par *)
  1566. &header->fsf_status_qual.word[2]);
  1567. break;
  1568. case FSF_SQ_RETRY_IF_POSSIBLE:
  1569. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1570. break;
  1571. default:
  1572. ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
  1573. header->fsf_status_qual.word[0]);
  1574. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1575. (char*)header->fsf_status_qual.word, 16);
  1576. }
  1577. break;
  1578. case FSF_ELS_COMMAND_REJECTED:
  1579. ZFCP_LOG_INFO("ELS has been rejected because command filter "
  1580. "prohibited sending "
  1581. "(adapter: %s, port d_id: 0x%06x)\n",
  1582. zfcp_get_busid_by_adapter(adapter), d_id);
  1583. break;
  1584. case FSF_PAYLOAD_SIZE_MISMATCH:
  1585. ZFCP_LOG_INFO(
  1586. "ELS request size and ELS response size must be either "
  1587. "both 0, or both greater than 0 "
  1588. "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
  1589. zfcp_get_busid_by_adapter(adapter),
  1590. bottom->req_buf_length,
  1591. bottom->resp_buf_length);
  1592. break;
  1593. case FSF_REQUEST_SIZE_TOO_LARGE:
  1594. ZFCP_LOG_INFO(
  1595. "Length of the ELS request buffer, "
  1596. "specified in QTCB bottom, "
  1597. "exceeds the size of the buffers "
  1598. "that have been allocated for ELS request data "
  1599. "(adapter: %s, req_buf_length=%d)\n",
  1600. zfcp_get_busid_by_adapter(adapter),
  1601. bottom->req_buf_length);
  1602. break;
  1603. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1604. ZFCP_LOG_INFO(
  1605. "Length of the ELS response buffer, "
  1606. "specified in QTCB bottom, "
  1607. "exceeds the size of the buffers "
  1608. "that have been allocated for ELS response data "
  1609. "(adapter: %s, resp_buf_length=%d)\n",
  1610. zfcp_get_busid_by_adapter(adapter),
  1611. bottom->resp_buf_length);
  1612. break;
  1613. case FSF_SBAL_MISMATCH:
  1614. /* should never occure, avoided in zfcp_fsf_send_els */
  1615. ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
  1616. "resp_buf_length=%d)\n",
  1617. zfcp_get_busid_by_adapter(adapter),
  1618. bottom->req_buf_length, bottom->resp_buf_length);
  1619. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1620. break;
  1621. case FSF_ACCESS_DENIED:
  1622. ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
  1623. "(adapter %s, port d_id=0x%06x)\n",
  1624. zfcp_get_busid_by_adapter(adapter), d_id);
  1625. for (counter = 0; counter < 2; counter++) {
  1626. subtable = header->fsf_status_qual.halfword[counter * 2];
  1627. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  1628. switch (subtable) {
  1629. case FSF_SQ_CFDC_SUBTABLE_OS:
  1630. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  1631. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  1632. case FSF_SQ_CFDC_SUBTABLE_LUN:
  1633. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  1634. zfcp_act_subtable_type[subtable], rule);
  1635. break;
  1636. }
  1637. }
  1638. if (port != NULL)
  1639. zfcp_erp_port_access_denied(port, 56, fsf_req);
  1640. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1641. break;
  1642. default:
  1643. ZFCP_LOG_NORMAL(
  1644. "bug: An unknown FSF Status was presented "
  1645. "(adapter: %s, fsf_status=0x%08x)\n",
  1646. zfcp_get_busid_by_adapter(adapter),
  1647. header->fsf_status);
  1648. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1649. break;
  1650. }
  1651. skip_fsfstatus:
  1652. send_els->status = retval;
  1653. if (send_els->handler)
  1654. send_els->handler(send_els->handler_data);
  1655. return retval;
  1656. }
  1657. int
  1658. zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1659. {
  1660. volatile struct qdio_buffer_element *sbale;
  1661. struct zfcp_fsf_req *fsf_req;
  1662. struct zfcp_adapter *adapter = erp_action->adapter;
  1663. unsigned long lock_flags;
  1664. int retval;
  1665. /* setup new FSF request */
  1666. retval = zfcp_fsf_req_create(adapter,
  1667. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1668. ZFCP_REQ_AUTO_CLEANUP,
  1669. adapter->pool.fsf_req_erp,
  1670. &lock_flags, &fsf_req);
  1671. if (retval) {
  1672. ZFCP_LOG_INFO("error: Could not create exchange configuration "
  1673. "data request for adapter %s.\n",
  1674. zfcp_get_busid_by_adapter(adapter));
  1675. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1676. lock_flags);
  1677. return retval;
  1678. }
  1679. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1680. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1681. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1682. fsf_req->qtcb->bottom.config.feature_selection =
  1683. FSF_FEATURE_CFDC |
  1684. FSF_FEATURE_LUN_SHARING |
  1685. FSF_FEATURE_NOTIFICATION_LOST |
  1686. FSF_FEATURE_UPDATE_ALERT;
  1687. fsf_req->erp_action = erp_action;
  1688. erp_action->fsf_req = fsf_req;
  1689. zfcp_erp_start_timer(fsf_req);
  1690. retval = zfcp_fsf_req_send(fsf_req);
  1691. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1692. lock_flags);
  1693. if (retval) {
  1694. ZFCP_LOG_INFO("error: Could not send exchange configuration "
  1695. "data command on the adapter %s\n",
  1696. zfcp_get_busid_by_adapter(adapter));
  1697. zfcp_fsf_req_free(fsf_req);
  1698. erp_action->fsf_req = NULL;
  1699. }
  1700. else
  1701. ZFCP_LOG_DEBUG("exchange configuration data request initiated "
  1702. "(adapter %s)\n",
  1703. zfcp_get_busid_by_adapter(adapter));
  1704. return retval;
  1705. }
  1706. int
  1707. zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1708. struct fsf_qtcb_bottom_config *data)
  1709. {
  1710. volatile struct qdio_buffer_element *sbale;
  1711. struct zfcp_fsf_req *fsf_req;
  1712. unsigned long lock_flags;
  1713. int retval;
  1714. /* setup new FSF request */
  1715. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1716. ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
  1717. &fsf_req);
  1718. if (retval) {
  1719. ZFCP_LOG_INFO("error: Could not create exchange configuration "
  1720. "data request for adapter %s.\n",
  1721. zfcp_get_busid_by_adapter(adapter));
  1722. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1723. lock_flags);
  1724. return retval;
  1725. }
  1726. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1727. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1728. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1729. fsf_req->qtcb->bottom.config.feature_selection =
  1730. FSF_FEATURE_CFDC |
  1731. FSF_FEATURE_LUN_SHARING |
  1732. FSF_FEATURE_NOTIFICATION_LOST |
  1733. FSF_FEATURE_UPDATE_ALERT;
  1734. if (data)
  1735. fsf_req->data = (unsigned long) data;
  1736. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1737. retval = zfcp_fsf_req_send(fsf_req);
  1738. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1739. lock_flags);
  1740. if (retval)
  1741. ZFCP_LOG_INFO("error: Could not send exchange configuration "
  1742. "data command on the adapter %s\n",
  1743. zfcp_get_busid_by_adapter(adapter));
  1744. else
  1745. wait_event(fsf_req->completion_wq,
  1746. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1747. zfcp_fsf_req_free(fsf_req);
  1748. return retval;
  1749. }
  1750. /**
  1751. * zfcp_fsf_exchange_config_evaluate
  1752. * @fsf_req: fsf_req which belongs to xchg config data request
  1753. * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
  1754. *
  1755. * returns: -EIO on error, 0 otherwise
  1756. */
  1757. static int
  1758. zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  1759. {
  1760. struct fsf_qtcb_bottom_config *bottom;
  1761. struct zfcp_adapter *adapter = fsf_req->adapter;
  1762. struct Scsi_Host *shost = adapter->scsi_host;
  1763. bottom = &fsf_req->qtcb->bottom.config;
  1764. ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
  1765. bottom->low_qtcb_version, bottom->high_qtcb_version);
  1766. adapter->fsf_lic_version = bottom->lic_version;
  1767. adapter->adapter_features = bottom->adapter_features;
  1768. adapter->connection_features = bottom->connection_features;
  1769. adapter->peer_wwpn = 0;
  1770. adapter->peer_wwnn = 0;
  1771. adapter->peer_d_id = 0;
  1772. if (xchg_ok) {
  1773. if (fsf_req->data)
  1774. memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
  1775. bottom, sizeof (struct fsf_qtcb_bottom_config));
  1776. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  1777. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  1778. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  1779. fc_host_speed(shost) = bottom->fc_link_speed;
  1780. fc_host_supported_classes(shost) =
  1781. FC_COS_CLASS2 | FC_COS_CLASS3;
  1782. adapter->hydra_version = bottom->adapter_type;
  1783. adapter->timer_ticks = bottom->timer_interval;
  1784. if (fc_host_permanent_port_name(shost) == -1)
  1785. fc_host_permanent_port_name(shost) =
  1786. fc_host_port_name(shost);
  1787. if (bottom->fc_topology == FSF_TOPO_P2P) {
  1788. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  1789. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  1790. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  1791. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  1792. } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
  1793. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  1794. else if (bottom->fc_topology == FSF_TOPO_AL)
  1795. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  1796. else
  1797. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1798. } else {
  1799. fc_host_node_name(shost) = 0;
  1800. fc_host_port_name(shost) = 0;
  1801. fc_host_port_id(shost) = 0;
  1802. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1803. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1804. adapter->hydra_version = 0;
  1805. }
  1806. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  1807. adapter->hardware_version = bottom->hardware_version;
  1808. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  1809. min(FC_SERIAL_NUMBER_SIZE, 17));
  1810. EBCASC(fc_host_serial_number(shost),
  1811. min(FC_SERIAL_NUMBER_SIZE, 17));
  1812. }
  1813. if (fsf_req->erp_action)
  1814. ZFCP_LOG_NORMAL("The adapter %s reported the following "
  1815. "characteristics:\n"
  1816. "WWNN 0x%016Lx, WWPN 0x%016Lx, "
  1817. "S_ID 0x%06x,\n"
  1818. "adapter version 0x%x, "
  1819. "LIC version 0x%x, "
  1820. "FC link speed %d Gb/s\n",
  1821. zfcp_get_busid_by_adapter(adapter),
  1822. (wwn_t) fc_host_node_name(shost),
  1823. (wwn_t) fc_host_port_name(shost),
  1824. fc_host_port_id(shost),
  1825. adapter->hydra_version,
  1826. adapter->fsf_lic_version,
  1827. fc_host_speed(shost));
  1828. if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
  1829. ZFCP_LOG_NORMAL("error: the adapter %s "
  1830. "only supports newer control block "
  1831. "versions in comparison to this device "
  1832. "driver (try updated device driver)\n",
  1833. zfcp_get_busid_by_adapter(adapter));
  1834. zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
  1835. return -EIO;
  1836. }
  1837. if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
  1838. ZFCP_LOG_NORMAL("error: the adapter %s "
  1839. "only supports older control block "
  1840. "versions than this device driver uses"
  1841. "(consider a microcode upgrade)\n",
  1842. zfcp_get_busid_by_adapter(adapter));
  1843. zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
  1844. return -EIO;
  1845. }
  1846. return 0;
  1847. }
  1848. /**
  1849. * function: zfcp_fsf_exchange_config_data_handler
  1850. *
  1851. * purpose: is called for finished Exchange Configuration Data command
  1852. *
  1853. * returns:
  1854. */
  1855. static int
  1856. zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
  1857. {
  1858. struct fsf_qtcb_bottom_config *bottom;
  1859. struct zfcp_adapter *adapter = fsf_req->adapter;
  1860. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  1861. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1862. return -EIO;
  1863. switch (qtcb->header.fsf_status) {
  1864. case FSF_GOOD:
  1865. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
  1866. return -EIO;
  1867. switch (fc_host_port_type(adapter->scsi_host)) {
  1868. case FC_PORTTYPE_PTP:
  1869. ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
  1870. "configuration detected at adapter %s\n"
  1871. "Peer WWNN 0x%016llx, "
  1872. "peer WWPN 0x%016llx, "
  1873. "peer d_id 0x%06x\n",
  1874. zfcp_get_busid_by_adapter(adapter),
  1875. adapter->peer_wwnn,
  1876. adapter->peer_wwpn,
  1877. adapter->peer_d_id);
  1878. break;
  1879. case FC_PORTTYPE_NLPORT:
  1880. ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
  1881. "topology detected at adapter %s "
  1882. "unsupported, shutting down adapter\n",
  1883. zfcp_get_busid_by_adapter(adapter));
  1884. zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
  1885. return -EIO;
  1886. case FC_PORTTYPE_NPORT:
  1887. if (fsf_req->erp_action)
  1888. ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
  1889. "network detected at adapter "
  1890. "%s.\n",
  1891. zfcp_get_busid_by_adapter(adapter));
  1892. break;
  1893. default:
  1894. ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
  1895. "reported by the exchange "
  1896. "configuration command for "
  1897. "the adapter %s is not "
  1898. "of a type known to the zfcp "
  1899. "driver, shutting down adapter\n",
  1900. zfcp_get_busid_by_adapter(adapter));
  1901. zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
  1902. return -EIO;
  1903. }
  1904. bottom = &qtcb->bottom.config;
  1905. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  1906. ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
  1907. "allowed by the adapter %s "
  1908. "is lower than the minimum "
  1909. "required by the driver (%ld bytes).\n",
  1910. bottom->max_qtcb_size,
  1911. zfcp_get_busid_by_adapter(adapter),
  1912. sizeof(struct fsf_qtcb));
  1913. zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
  1914. return -EIO;
  1915. }
  1916. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1917. &adapter->status);
  1918. break;
  1919. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  1920. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
  1921. return -EIO;
  1922. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1923. &adapter->status);
  1924. zfcp_fsf_link_down_info_eval(fsf_req, 42,
  1925. &qtcb->header.fsf_status_qual.link_down_info);
  1926. break;
  1927. default:
  1928. zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
  1929. return -EIO;
  1930. }
  1931. return 0;
  1932. }
  1933. /**
  1934. * zfcp_fsf_exchange_port_data - request information about local port
  1935. * @erp_action: ERP action for the adapter for which port data is requested
  1936. */
  1937. int
  1938. zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1939. {
  1940. volatile struct qdio_buffer_element *sbale;
  1941. struct zfcp_fsf_req *fsf_req;
  1942. struct zfcp_adapter *adapter = erp_action->adapter;
  1943. unsigned long lock_flags;
  1944. int retval;
  1945. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
  1946. ZFCP_LOG_INFO("error: exchange port data "
  1947. "command not supported by adapter %s\n",
  1948. zfcp_get_busid_by_adapter(adapter));
  1949. return -EOPNOTSUPP;
  1950. }
  1951. /* setup new FSF request */
  1952. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1953. ZFCP_REQ_AUTO_CLEANUP,
  1954. adapter->pool.fsf_req_erp,
  1955. &lock_flags, &fsf_req);
  1956. if (retval) {
  1957. ZFCP_LOG_INFO("error: Out of resources. Could not create an "
  1958. "exchange port data request for "
  1959. "the adapter %s.\n",
  1960. zfcp_get_busid_by_adapter(adapter));
  1961. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1962. lock_flags);
  1963. return retval;
  1964. }
  1965. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1966. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1967. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1968. erp_action->fsf_req = fsf_req;
  1969. fsf_req->erp_action = erp_action;
  1970. zfcp_erp_start_timer(fsf_req);
  1971. retval = zfcp_fsf_req_send(fsf_req);
  1972. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  1973. if (retval) {
  1974. ZFCP_LOG_INFO("error: Could not send an exchange port data "
  1975. "command on the adapter %s\n",
  1976. zfcp_get_busid_by_adapter(adapter));
  1977. zfcp_fsf_req_free(fsf_req);
  1978. erp_action->fsf_req = NULL;
  1979. }
  1980. else
  1981. ZFCP_LOG_DEBUG("exchange port data request initiated "
  1982. "(adapter %s)\n",
  1983. zfcp_get_busid_by_adapter(adapter));
  1984. return retval;
  1985. }
  1986. /**
  1987. * zfcp_fsf_exchange_port_data_sync - request information about local port
  1988. * and wait until information is ready
  1989. */
  1990. int
  1991. zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  1992. struct fsf_qtcb_bottom_port *data)
  1993. {
  1994. volatile struct qdio_buffer_element *sbale;
  1995. struct zfcp_fsf_req *fsf_req;
  1996. unsigned long lock_flags;
  1997. int retval;
  1998. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
  1999. ZFCP_LOG_INFO("error: exchange port data "
  2000. "command not supported by adapter %s\n",
  2001. zfcp_get_busid_by_adapter(adapter));
  2002. return -EOPNOTSUPP;
  2003. }
  2004. /* setup new FSF request */
  2005. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  2006. 0, NULL, &lock_flags, &fsf_req);
  2007. if (retval) {
  2008. ZFCP_LOG_INFO("error: Out of resources. Could not create an "
  2009. "exchange port data request for "
  2010. "the adapter %s.\n",
  2011. zfcp_get_busid_by_adapter(adapter));
  2012. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  2013. lock_flags);
  2014. return retval;
  2015. }
  2016. if (data)
  2017. fsf_req->data = (unsigned long) data;
  2018. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2019. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2020. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2021. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  2022. retval = zfcp_fsf_req_send(fsf_req);
  2023. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  2024. if (retval)
  2025. ZFCP_LOG_INFO("error: Could not send an exchange port data "
  2026. "command on the adapter %s\n",
  2027. zfcp_get_busid_by_adapter(adapter));
  2028. else
  2029. wait_event(fsf_req->completion_wq,
  2030. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2031. zfcp_fsf_req_free(fsf_req);
  2032. return retval;
  2033. }
  2034. /**
  2035. * zfcp_fsf_exchange_port_evaluate
  2036. * @fsf_req: fsf_req which belongs to xchg port data request
  2037. * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
  2038. */
  2039. static void
  2040. zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  2041. {
  2042. struct zfcp_adapter *adapter;
  2043. struct fsf_qtcb_bottom_port *bottom;
  2044. struct Scsi_Host *shost;
  2045. adapter = fsf_req->adapter;
  2046. bottom = &fsf_req->qtcb->bottom.port;
  2047. shost = adapter->scsi_host;
  2048. if (fsf_req->data)
  2049. memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
  2050. sizeof(struct fsf_qtcb_bottom_port));
  2051. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  2052. fc_host_permanent_port_name(shost) = bottom->wwpn;
  2053. else
  2054. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  2055. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  2056. fc_host_supported_speeds(shost) = bottom->supported_speed;
  2057. }
  2058. /**
  2059. * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
  2060. * @fsf_req: pointer to struct zfcp_fsf_req
  2061. */
  2062. static void
  2063. zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
  2064. {
  2065. struct zfcp_adapter *adapter;
  2066. struct fsf_qtcb *qtcb;
  2067. adapter = fsf_req->adapter;
  2068. qtcb = fsf_req->qtcb;
  2069. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  2070. return;
  2071. switch (qtcb->header.fsf_status) {
  2072. case FSF_GOOD:
  2073. zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
  2074. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2075. break;
  2076. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  2077. zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
  2078. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2079. zfcp_fsf_link_down_info_eval(fsf_req, 43,
  2080. &qtcb->header.fsf_status_qual.link_down_info);
  2081. break;
  2082. }
  2083. }
  2084. /*
  2085. * function: zfcp_fsf_open_port
  2086. *
  2087. * purpose:
  2088. *
  2089. * returns: address of initiated FSF request
  2090. * NULL - request could not be initiated
  2091. */
  2092. int
  2093. zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  2094. {
  2095. volatile struct qdio_buffer_element *sbale;
  2096. struct zfcp_fsf_req *fsf_req;
  2097. unsigned long lock_flags;
  2098. int retval = 0;
  2099. /* setup new FSF request */
  2100. retval = zfcp_fsf_req_create(erp_action->adapter,
  2101. FSF_QTCB_OPEN_PORT_WITH_DID,
  2102. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2103. erp_action->adapter->pool.fsf_req_erp,
  2104. &lock_flags, &fsf_req);
  2105. if (retval < 0) {
  2106. ZFCP_LOG_INFO("error: Could not create open port request "
  2107. "for port 0x%016Lx on adapter %s.\n",
  2108. erp_action->port->wwpn,
  2109. zfcp_get_busid_by_adapter(erp_action->adapter));
  2110. goto out;
  2111. }
  2112. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2113. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2114. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2115. fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  2116. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
  2117. fsf_req->data = (unsigned long) erp_action->port;
  2118. fsf_req->erp_action = erp_action;
  2119. erp_action->fsf_req = fsf_req;
  2120. zfcp_erp_start_timer(fsf_req);
  2121. retval = zfcp_fsf_req_send(fsf_req);
  2122. if (retval) {
  2123. ZFCP_LOG_INFO("error: Could not send open port request for "
  2124. "port 0x%016Lx on adapter %s.\n",
  2125. erp_action->port->wwpn,
  2126. zfcp_get_busid_by_adapter(erp_action->adapter));
  2127. zfcp_fsf_req_free(fsf_req);
  2128. erp_action->fsf_req = NULL;
  2129. goto out;
  2130. }
  2131. ZFCP_LOG_DEBUG("open port request initiated "
  2132. "(adapter %s, port 0x%016Lx)\n",
  2133. zfcp_get_busid_by_adapter(erp_action->adapter),
  2134. erp_action->port->wwpn);
  2135. out:
  2136. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2137. lock_flags);
  2138. return retval;
  2139. }
  2140. /*
  2141. * function: zfcp_fsf_open_port_handler
  2142. *
  2143. * purpose: is called for finished Open Port command
  2144. *
  2145. * returns:
  2146. */
  2147. static int
  2148. zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
  2149. {
  2150. int retval = -EINVAL;
  2151. struct zfcp_port *port;
  2152. struct fsf_plogi *plogi;
  2153. struct fsf_qtcb_header *header;
  2154. u16 subtable, rule, counter;
  2155. port = (struct zfcp_port *) fsf_req->data;
  2156. header = &fsf_req->qtcb->header;
  2157. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2158. /* don't change port status in our bookkeeping */
  2159. goto skip_fsfstatus;
  2160. }
  2161. /* evaluate FSF status in QTCB */
  2162. switch (header->fsf_status) {
  2163. case FSF_PORT_ALREADY_OPEN:
  2164. ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
  2165. "is already open.\n",
  2166. port->wwpn, zfcp_get_busid_by_port(port));
  2167. /*
  2168. * This is a bug, however operation should continue normally
  2169. * if it is simply ignored
  2170. */
  2171. break;
  2172. case FSF_ACCESS_DENIED:
  2173. ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
  2174. "on adapter %s\n",
  2175. port->wwpn, zfcp_get_busid_by_port(port));
  2176. for (counter = 0; counter < 2; counter++) {
  2177. subtable = header->fsf_status_qual.halfword[counter * 2];
  2178. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2179. switch (subtable) {
  2180. case FSF_SQ_CFDC_SUBTABLE_OS:
  2181. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2182. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2183. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2184. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2185. zfcp_act_subtable_type[subtable], rule);
  2186. break;
  2187. }
  2188. }
  2189. zfcp_erp_port_access_denied(port, 57, fsf_req);
  2190. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2191. break;
  2192. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  2193. ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
  2194. "The remote port 0x%016Lx on adapter %s "
  2195. "could not be opened. Disabling it.\n",
  2196. port->wwpn, zfcp_get_busid_by_port(port));
  2197. zfcp_erp_port_failed(port, 31, fsf_req);
  2198. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2199. break;
  2200. case FSF_ADAPTER_STATUS_AVAILABLE:
  2201. switch (header->fsf_status_qual.word[0]) {
  2202. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2203. /* ERP strategy will escalate */
  2204. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2205. break;
  2206. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2207. /* ERP strategy will escalate */
  2208. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2209. break;
  2210. case FSF_SQ_NO_RETRY_POSSIBLE:
  2211. ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
  2212. "adapter %s could not be opened. "
  2213. "Disabling it.\n",
  2214. port->wwpn,
  2215. zfcp_get_busid_by_port(port));
  2216. zfcp_erp_port_failed(port, 32, fsf_req);
  2217. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2218. break;
  2219. default:
  2220. ZFCP_LOG_NORMAL
  2221. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2222. header->fsf_status_qual.word[0]);
  2223. break;
  2224. }
  2225. break;
  2226. case FSF_GOOD:
  2227. /* save port handle assigned by FSF */
  2228. port->handle = header->port_handle;
  2229. ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
  2230. "was opened, it's port handle is 0x%x\n",
  2231. port->wwpn, zfcp_get_busid_by_port(port),
  2232. port->handle);
  2233. /* mark port as open */
  2234. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  2235. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2236. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2237. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  2238. &port->status);
  2239. retval = 0;
  2240. /* check whether D_ID has changed during open */
  2241. /*
  2242. * FIXME: This check is not airtight, as the FCP channel does
  2243. * not monitor closures of target port connections caused on
  2244. * the remote side. Thus, they might miss out on invalidating
  2245. * locally cached WWPNs (and other N_Port parameters) of gone
  2246. * target ports. So, our heroic attempt to make things safe
  2247. * could be undermined by 'open port' response data tagged with
  2248. * obsolete WWPNs. Another reason to monitor potential
  2249. * connection closures ourself at least (by interpreting
  2250. * incoming ELS' and unsolicited status). It just crosses my
  2251. * mind that one should be able to cross-check by means of
  2252. * another GID_PN straight after a port has been opened.
  2253. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  2254. */
  2255. plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
  2256. if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
  2257. {
  2258. if (fsf_req->qtcb->bottom.support.els1_length <
  2259. sizeof (struct fsf_plogi)) {
  2260. ZFCP_LOG_INFO(
  2261. "warning: insufficient length of "
  2262. "PLOGI payload (%i)\n",
  2263. fsf_req->qtcb->bottom.support.els1_length);
  2264. /* skip sanity check and assume wwpn is ok */
  2265. } else {
  2266. if (plogi->serv_param.wwpn != port->wwpn) {
  2267. ZFCP_LOG_INFO("warning: d_id of port "
  2268. "0x%016Lx changed during "
  2269. "open\n", port->wwpn);
  2270. atomic_clear_mask(
  2271. ZFCP_STATUS_PORT_DID_DID,
  2272. &port->status);
  2273. } else {
  2274. port->wwnn = plogi->serv_param.wwnn;
  2275. zfcp_plogi_evaluate(port, plogi);
  2276. }
  2277. }
  2278. }
  2279. break;
  2280. case FSF_UNKNOWN_OP_SUBTYPE:
  2281. /* should never occure, subtype not set in zfcp_fsf_open_port */
  2282. ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
  2283. "op_subtype=0x%x)\n",
  2284. zfcp_get_busid_by_port(port),
  2285. fsf_req->qtcb->bottom.support.operation_subtype);
  2286. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2287. break;
  2288. default:
  2289. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2290. "(debug info 0x%x)\n",
  2291. header->fsf_status);
  2292. break;
  2293. }
  2294. skip_fsfstatus:
  2295. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
  2296. return retval;
  2297. }
  2298. /*
  2299. * function: zfcp_fsf_close_port
  2300. *
  2301. * purpose: submit FSF command "close port"
  2302. *
  2303. * returns: address of initiated FSF request
  2304. * NULL - request could not be initiated
  2305. */
  2306. int
  2307. zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  2308. {
  2309. volatile struct qdio_buffer_element *sbale;
  2310. struct zfcp_fsf_req *fsf_req;
  2311. unsigned long lock_flags;
  2312. int retval = 0;
  2313. /* setup new FSF request */
  2314. retval = zfcp_fsf_req_create(erp_action->adapter,
  2315. FSF_QTCB_CLOSE_PORT,
  2316. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2317. erp_action->adapter->pool.fsf_req_erp,
  2318. &lock_flags, &fsf_req);
  2319. if (retval < 0) {
  2320. ZFCP_LOG_INFO("error: Could not create a close port request "
  2321. "for port 0x%016Lx on adapter %s.\n",
  2322. erp_action->port->wwpn,
  2323. zfcp_get_busid_by_adapter(erp_action->adapter));
  2324. goto out;
  2325. }
  2326. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2327. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2328. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2329. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
  2330. fsf_req->data = (unsigned long) erp_action->port;
  2331. fsf_req->erp_action = erp_action;
  2332. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2333. fsf_req->erp_action = erp_action;
  2334. erp_action->fsf_req = fsf_req;
  2335. zfcp_erp_start_timer(fsf_req);
  2336. retval = zfcp_fsf_req_send(fsf_req);
  2337. if (retval) {
  2338. ZFCP_LOG_INFO("error: Could not send a close port request for "
  2339. "port 0x%016Lx on adapter %s.\n",
  2340. erp_action->port->wwpn,
  2341. zfcp_get_busid_by_adapter(erp_action->adapter));
  2342. zfcp_fsf_req_free(fsf_req);
  2343. erp_action->fsf_req = NULL;
  2344. goto out;
  2345. }
  2346. ZFCP_LOG_TRACE("close port request initiated "
  2347. "(adapter %s, port 0x%016Lx)\n",
  2348. zfcp_get_busid_by_adapter(erp_action->adapter),
  2349. erp_action->port->wwpn);
  2350. out:
  2351. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2352. lock_flags);
  2353. return retval;
  2354. }
  2355. /*
  2356. * function: zfcp_fsf_close_port_handler
  2357. *
  2358. * purpose: is called for finished Close Port FSF command
  2359. *
  2360. * returns:
  2361. */
  2362. static int
  2363. zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
  2364. {
  2365. int retval = -EINVAL;
  2366. struct zfcp_port *port;
  2367. port = (struct zfcp_port *) fsf_req->data;
  2368. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2369. /* don't change port status in our bookkeeping */
  2370. goto skip_fsfstatus;
  2371. }
  2372. /* evaluate FSF status in QTCB */
  2373. switch (fsf_req->qtcb->header.fsf_status) {
  2374. case FSF_PORT_HANDLE_NOT_VALID:
  2375. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  2376. "0x%016Lx on adapter %s invalid. This may happen "
  2377. "occasionally.\n", port->handle,
  2378. port->wwpn, zfcp_get_busid_by_port(port));
  2379. ZFCP_LOG_DEBUG("status qualifier:\n");
  2380. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2381. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  2382. sizeof (union fsf_status_qual));
  2383. zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
  2384. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2385. break;
  2386. case FSF_ADAPTER_STATUS_AVAILABLE:
  2387. /* Note: FSF has actually closed the port in this case.
  2388. * The status code is just daft. Fingers crossed for a change
  2389. */
  2390. retval = 0;
  2391. break;
  2392. case FSF_GOOD:
  2393. ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
  2394. "port handle 0x%x\n", port->wwpn,
  2395. zfcp_get_busid_by_port(port), port->handle);
  2396. zfcp_erp_modify_port_status(port, 33, fsf_req,
  2397. ZFCP_STATUS_COMMON_OPEN,
  2398. ZFCP_CLEAR);
  2399. retval = 0;
  2400. break;
  2401. default:
  2402. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2403. "(debug info 0x%x)\n",
  2404. fsf_req->qtcb->header.fsf_status);
  2405. break;
  2406. }
  2407. skip_fsfstatus:
  2408. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
  2409. return retval;
  2410. }
  2411. /*
  2412. * function: zfcp_fsf_close_physical_port
  2413. *
  2414. * purpose: submit FSF command "close physical port"
  2415. *
  2416. * returns: address of initiated FSF request
  2417. * NULL - request could not be initiated
  2418. */
  2419. int
  2420. zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  2421. {
  2422. volatile struct qdio_buffer_element *sbale;
  2423. struct zfcp_fsf_req *fsf_req;
  2424. unsigned long lock_flags;
  2425. int retval = 0;
  2426. /* setup new FSF request */
  2427. retval = zfcp_fsf_req_create(erp_action->adapter,
  2428. FSF_QTCB_CLOSE_PHYSICAL_PORT,
  2429. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2430. erp_action->adapter->pool.fsf_req_erp,
  2431. &lock_flags, &fsf_req);
  2432. if (retval < 0) {
  2433. ZFCP_LOG_INFO("error: Could not create close physical port "
  2434. "request (adapter %s, port 0x%016Lx)\n",
  2435. zfcp_get_busid_by_adapter(erp_action->adapter),
  2436. erp_action->port->wwpn);
  2437. goto out;
  2438. }
  2439. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2440. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2441. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2442. /* mark port as being closed */
  2443. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  2444. &erp_action->port->status);
  2445. /* save a pointer to this port */
  2446. fsf_req->data = (unsigned long) erp_action->port;
  2447. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2448. fsf_req->erp_action = erp_action;
  2449. erp_action->fsf_req = fsf_req;
  2450. zfcp_erp_start_timer(fsf_req);
  2451. retval = zfcp_fsf_req_send(fsf_req);
  2452. if (retval) {
  2453. ZFCP_LOG_INFO("error: Could not send close physical port "
  2454. "request (adapter %s, port 0x%016Lx)\n",
  2455. zfcp_get_busid_by_adapter(erp_action->adapter),
  2456. erp_action->port->wwpn);
  2457. zfcp_fsf_req_free(fsf_req);
  2458. erp_action->fsf_req = NULL;
  2459. goto out;
  2460. }
  2461. ZFCP_LOG_TRACE("close physical port request initiated "
  2462. "(adapter %s, port 0x%016Lx)\n",
  2463. zfcp_get_busid_by_adapter(erp_action->adapter),
  2464. erp_action->port->wwpn);
  2465. out:
  2466. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2467. lock_flags);
  2468. return retval;
  2469. }
  2470. /*
  2471. * function: zfcp_fsf_close_physical_port_handler
  2472. *
  2473. * purpose: is called for finished Close Physical Port FSF command
  2474. *
  2475. * returns:
  2476. */
  2477. static int
  2478. zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
  2479. {
  2480. int retval = -EINVAL;
  2481. struct zfcp_port *port;
  2482. struct zfcp_unit *unit;
  2483. struct fsf_qtcb_header *header;
  2484. u16 subtable, rule, counter;
  2485. port = (struct zfcp_port *) fsf_req->data;
  2486. header = &fsf_req->qtcb->header;
  2487. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2488. /* don't change port status in our bookkeeping */
  2489. goto skip_fsfstatus;
  2490. }
  2491. /* evaluate FSF status in QTCB */
  2492. switch (header->fsf_status) {
  2493. case FSF_PORT_HANDLE_NOT_VALID:
  2494. ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
  2495. "(adapter %s, port 0x%016Lx). "
  2496. "This may happen occasionally.\n",
  2497. port->handle,
  2498. zfcp_get_busid_by_port(port),
  2499. port->wwpn);
  2500. ZFCP_LOG_DEBUG("status qualifier:\n");
  2501. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2502. (char *) &header->fsf_status_qual,
  2503. sizeof (union fsf_status_qual));
  2504. zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
  2505. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2506. break;
  2507. case FSF_ACCESS_DENIED:
  2508. ZFCP_LOG_NORMAL("Access denied, cannot close "
  2509. "physical port 0x%016Lx on adapter %s\n",
  2510. port->wwpn, zfcp_get_busid_by_port(port));
  2511. for (counter = 0; counter < 2; counter++) {
  2512. subtable = header->fsf_status_qual.halfword[counter * 2];
  2513. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2514. switch (subtable) {
  2515. case FSF_SQ_CFDC_SUBTABLE_OS:
  2516. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2517. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2518. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2519. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2520. zfcp_act_subtable_type[subtable], rule);
  2521. break;
  2522. }
  2523. }
  2524. zfcp_erp_port_access_denied(port, 58, fsf_req);
  2525. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2526. break;
  2527. case FSF_PORT_BOXED:
  2528. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
  2529. "%s needs to be reopened but it was attempted "
  2530. "to close it physically.\n",
  2531. port->wwpn,
  2532. zfcp_get_busid_by_port(port));
  2533. zfcp_erp_port_boxed(port, 50, fsf_req);
  2534. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2535. ZFCP_STATUS_FSFREQ_RETRY;
  2536. /* can't use generic zfcp_erp_modify_port_status because
  2537. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  2538. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2539. list_for_each_entry(unit, &port->unit_list_head, list)
  2540. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  2541. &unit->status);
  2542. break;
  2543. case FSF_ADAPTER_STATUS_AVAILABLE:
  2544. switch (header->fsf_status_qual.word[0]) {
  2545. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2546. /* This will now be escalated by ERP */
  2547. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2548. break;
  2549. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2550. /* ERP strategy will escalate */
  2551. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2552. break;
  2553. default:
  2554. ZFCP_LOG_NORMAL
  2555. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2556. header->fsf_status_qual.word[0]);
  2557. break;
  2558. }
  2559. break;
  2560. case FSF_GOOD:
  2561. ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
  2562. "physically closed, port handle 0x%x\n",
  2563. port->wwpn,
  2564. zfcp_get_busid_by_port(port), port->handle);
  2565. /* can't use generic zfcp_erp_modify_port_status because
  2566. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  2567. */
  2568. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2569. list_for_each_entry(unit, &port->unit_list_head, list)
  2570. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2571. retval = 0;
  2572. break;
  2573. default:
  2574. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2575. "(debug info 0x%x)\n",
  2576. header->fsf_status);
  2577. break;
  2578. }
  2579. skip_fsfstatus:
  2580. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  2581. return retval;
  2582. }
  2583. /*
  2584. * function: zfcp_fsf_open_unit
  2585. *
  2586. * purpose:
  2587. *
  2588. * returns:
  2589. *
  2590. * assumptions: This routine does not check whether the associated
  2591. * remote port has already been opened. This should be
  2592. * done by calling routines. Otherwise some status
  2593. * may be presented by FSF
  2594. */
  2595. int
  2596. zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  2597. {
  2598. volatile struct qdio_buffer_element *sbale;
  2599. struct zfcp_fsf_req *fsf_req;
  2600. unsigned long lock_flags;
  2601. int retval = 0;
  2602. /* setup new FSF request */
  2603. retval = zfcp_fsf_req_create(erp_action->adapter,
  2604. FSF_QTCB_OPEN_LUN,
  2605. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2606. erp_action->adapter->pool.fsf_req_erp,
  2607. &lock_flags, &fsf_req);
  2608. if (retval < 0) {
  2609. ZFCP_LOG_INFO("error: Could not create open unit request for "
  2610. "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
  2611. erp_action->unit->fcp_lun,
  2612. erp_action->unit->port->wwpn,
  2613. zfcp_get_busid_by_adapter(erp_action->adapter));
  2614. goto out;
  2615. }
  2616. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2617. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2618. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2619. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2620. fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  2621. if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  2622. fsf_req->qtcb->bottom.support.option =
  2623. FSF_OPEN_LUN_SUPPRESS_BOXING;
  2624. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
  2625. fsf_req->data = (unsigned long) erp_action->unit;
  2626. fsf_req->erp_action = erp_action;
  2627. erp_action->fsf_req = fsf_req;
  2628. zfcp_erp_start_timer(fsf_req);
  2629. retval = zfcp_fsf_req_send(erp_action->fsf_req);
  2630. if (retval) {
  2631. ZFCP_LOG_INFO("error: Could not send an open unit request "
  2632. "on the adapter %s, port 0x%016Lx for "
  2633. "unit 0x%016Lx\n",
  2634. zfcp_get_busid_by_adapter(erp_action->adapter),
  2635. erp_action->port->wwpn,
  2636. erp_action->unit->fcp_lun);
  2637. zfcp_fsf_req_free(fsf_req);
  2638. erp_action->fsf_req = NULL;
  2639. goto out;
  2640. }
  2641. ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
  2642. "port 0x%016Lx, unit 0x%016Lx)\n",
  2643. zfcp_get_busid_by_adapter(erp_action->adapter),
  2644. erp_action->port->wwpn, erp_action->unit->fcp_lun);
  2645. out:
  2646. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2647. lock_flags);
  2648. return retval;
  2649. }
  2650. /*
  2651. * function: zfcp_fsf_open_unit_handler
  2652. *
  2653. * purpose: is called for finished Open LUN command
  2654. *
  2655. * returns:
  2656. */
  2657. static int
  2658. zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
  2659. {
  2660. int retval = -EINVAL;
  2661. struct zfcp_adapter *adapter;
  2662. struct zfcp_unit *unit;
  2663. struct fsf_qtcb_header *header;
  2664. struct fsf_qtcb_bottom_support *bottom;
  2665. struct fsf_queue_designator *queue_designator;
  2666. u16 subtable, rule, counter;
  2667. int exclusive, readwrite;
  2668. unit = (struct zfcp_unit *) fsf_req->data;
  2669. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2670. /* don't change unit status in our bookkeeping */
  2671. goto skip_fsfstatus;
  2672. }
  2673. adapter = fsf_req->adapter;
  2674. header = &fsf_req->qtcb->header;
  2675. bottom = &fsf_req->qtcb->bottom.support;
  2676. queue_designator = &header->fsf_status_qual.fsf_queue_designator;
  2677. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2678. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  2679. ZFCP_STATUS_UNIT_SHARED |
  2680. ZFCP_STATUS_UNIT_READONLY,
  2681. &unit->status);
  2682. /* evaluate FSF status in QTCB */
  2683. switch (header->fsf_status) {
  2684. case FSF_PORT_HANDLE_NOT_VALID:
  2685. ZFCP_LOG_INFO("Temporary port identifier 0x%x "
  2686. "for port 0x%016Lx on adapter %s invalid "
  2687. "This may happen occasionally\n",
  2688. unit->port->handle,
  2689. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2690. ZFCP_LOG_DEBUG("status qualifier:\n");
  2691. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2692. (char *) &header->fsf_status_qual,
  2693. sizeof (union fsf_status_qual));
  2694. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
  2695. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2696. break;
  2697. case FSF_LUN_ALREADY_OPEN:
  2698. ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
  2699. "remote port 0x%016Lx on adapter %s twice.\n",
  2700. unit->fcp_lun,
  2701. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2702. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2703. break;
  2704. case FSF_ACCESS_DENIED:
  2705. ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
  2706. "remote port 0x%016Lx on adapter %s\n",
  2707. unit->fcp_lun, unit->port->wwpn,
  2708. zfcp_get_busid_by_unit(unit));
  2709. for (counter = 0; counter < 2; counter++) {
  2710. subtable = header->fsf_status_qual.halfword[counter * 2];
  2711. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2712. switch (subtable) {
  2713. case FSF_SQ_CFDC_SUBTABLE_OS:
  2714. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2715. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2716. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2717. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2718. zfcp_act_subtable_type[subtable], rule);
  2719. break;
  2720. }
  2721. }
  2722. zfcp_erp_unit_access_denied(unit, 59, fsf_req);
  2723. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2724. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2725. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2726. break;
  2727. case FSF_PORT_BOXED:
  2728. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  2729. "needs to be reopened\n",
  2730. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2731. zfcp_erp_port_boxed(unit->port, 51, fsf_req);
  2732. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2733. ZFCP_STATUS_FSFREQ_RETRY;
  2734. break;
  2735. case FSF_LUN_SHARING_VIOLATION:
  2736. if (header->fsf_status_qual.word[0] != 0) {
  2737. ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
  2738. "with WWPN 0x%Lx "
  2739. "connected to the adapter %s "
  2740. "is already in use in LPAR%d, CSS%d\n",
  2741. unit->fcp_lun,
  2742. unit->port->wwpn,
  2743. zfcp_get_busid_by_unit(unit),
  2744. queue_designator->hla,
  2745. queue_designator->cssid);
  2746. } else {
  2747. subtable = header->fsf_status_qual.halfword[4];
  2748. rule = header->fsf_status_qual.halfword[5];
  2749. switch (subtable) {
  2750. case FSF_SQ_CFDC_SUBTABLE_OS:
  2751. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2752. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2753. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2754. ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
  2755. "remote port with WWPN 0x%Lx "
  2756. "connected to the adapter %s "
  2757. "is denied (%s rule %d)\n",
  2758. unit->fcp_lun,
  2759. unit->port->wwpn,
  2760. zfcp_get_busid_by_unit(unit),
  2761. zfcp_act_subtable_type[subtable],
  2762. rule);
  2763. break;
  2764. }
  2765. }
  2766. ZFCP_LOG_DEBUG("status qualifier:\n");
  2767. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2768. (char *) &header->fsf_status_qual,
  2769. sizeof (union fsf_status_qual));
  2770. zfcp_erp_unit_access_denied(unit, 60, fsf_req);
  2771. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2772. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2773. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2774. break;
  2775. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  2776. ZFCP_LOG_INFO("error: The adapter ran out of resources. "
  2777. "There is no handle (temporary port identifier) "
  2778. "available for unit 0x%016Lx on port 0x%016Lx "
  2779. "on adapter %s\n",
  2780. unit->fcp_lun,
  2781. unit->port->wwpn,
  2782. zfcp_get_busid_by_unit(unit));
  2783. zfcp_erp_unit_failed(unit, 34, fsf_req);
  2784. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2785. break;
  2786. case FSF_ADAPTER_STATUS_AVAILABLE:
  2787. switch (header->fsf_status_qual.word[0]) {
  2788. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2789. /* Re-establish link to port */
  2790. zfcp_test_link(unit->port);
  2791. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2792. break;
  2793. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2794. /* ERP strategy will escalate */
  2795. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2796. break;
  2797. default:
  2798. ZFCP_LOG_NORMAL
  2799. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2800. header->fsf_status_qual.word[0]);
  2801. }
  2802. break;
  2803. case FSF_INVALID_COMMAND_OPTION:
  2804. ZFCP_LOG_NORMAL(
  2805. "Invalid option 0x%x has been specified "
  2806. "in QTCB bottom sent to the adapter %s\n",
  2807. bottom->option,
  2808. zfcp_get_busid_by_adapter(adapter));
  2809. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2810. retval = -EINVAL;
  2811. break;
  2812. case FSF_GOOD:
  2813. /* save LUN handle assigned by FSF */
  2814. unit->handle = header->lun_handle;
  2815. ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
  2816. "adapter %s opened, port handle 0x%x\n",
  2817. unit->fcp_lun,
  2818. unit->port->wwpn,
  2819. zfcp_get_busid_by_unit(unit),
  2820. unit->handle);
  2821. /* mark unit as open */
  2822. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2823. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  2824. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  2825. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  2826. exclusive = (bottom->lun_access_info &
  2827. FSF_UNIT_ACCESS_EXCLUSIVE);
  2828. readwrite = (bottom->lun_access_info &
  2829. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  2830. if (!exclusive)
  2831. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  2832. &unit->status);
  2833. if (!readwrite) {
  2834. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  2835. &unit->status);
  2836. ZFCP_LOG_NORMAL("read-only access for unit "
  2837. "(adapter %s, wwpn=0x%016Lx, "
  2838. "fcp_lun=0x%016Lx)\n",
  2839. zfcp_get_busid_by_unit(unit),
  2840. unit->port->wwpn,
  2841. unit->fcp_lun);
  2842. }
  2843. if (exclusive && !readwrite) {
  2844. ZFCP_LOG_NORMAL("exclusive access of read-only "
  2845. "unit not supported\n");
  2846. zfcp_erp_unit_failed(unit, 35, fsf_req);
  2847. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2848. zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
  2849. } else if (!exclusive && readwrite) {
  2850. ZFCP_LOG_NORMAL("shared access of read-write "
  2851. "unit not supported\n");
  2852. zfcp_erp_unit_failed(unit, 36, fsf_req);
  2853. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2854. zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
  2855. }
  2856. }
  2857. retval = 0;
  2858. break;
  2859. default:
  2860. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2861. "(debug info 0x%x)\n",
  2862. header->fsf_status);
  2863. break;
  2864. }
  2865. skip_fsfstatus:
  2866. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
  2867. return retval;
  2868. }
  2869. /*
  2870. * function: zfcp_fsf_close_unit
  2871. *
  2872. * purpose:
  2873. *
  2874. * returns: address of fsf_req - request successfully initiated
  2875. * NULL -
  2876. *
  2877. * assumptions: This routine does not check whether the associated
  2878. * remote port/lun has already been opened. This should be
  2879. * done by calling routines. Otherwise some status
  2880. * may be presented by FSF
  2881. */
  2882. int
  2883. zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  2884. {
  2885. volatile struct qdio_buffer_element *sbale;
  2886. struct zfcp_fsf_req *fsf_req;
  2887. unsigned long lock_flags;
  2888. int retval = 0;
  2889. /* setup new FSF request */
  2890. retval = zfcp_fsf_req_create(erp_action->adapter,
  2891. FSF_QTCB_CLOSE_LUN,
  2892. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2893. erp_action->adapter->pool.fsf_req_erp,
  2894. &lock_flags, &fsf_req);
  2895. if (retval < 0) {
  2896. ZFCP_LOG_INFO("error: Could not create close unit request for "
  2897. "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
  2898. erp_action->unit->fcp_lun,
  2899. erp_action->port->wwpn,
  2900. zfcp_get_busid_by_adapter(erp_action->adapter));
  2901. goto out;
  2902. }
  2903. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2904. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2905. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2906. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2907. fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
  2908. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
  2909. fsf_req->data = (unsigned long) erp_action->unit;
  2910. fsf_req->erp_action = erp_action;
  2911. erp_action->fsf_req = fsf_req;
  2912. zfcp_erp_start_timer(fsf_req);
  2913. retval = zfcp_fsf_req_send(erp_action->fsf_req);
  2914. if (retval) {
  2915. ZFCP_LOG_INFO("error: Could not send a close unit request for "
  2916. "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
  2917. erp_action->unit->fcp_lun,
  2918. erp_action->port->wwpn,
  2919. zfcp_get_busid_by_adapter(erp_action->adapter));
  2920. zfcp_fsf_req_free(fsf_req);
  2921. erp_action->fsf_req = NULL;
  2922. goto out;
  2923. }
  2924. ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
  2925. "port 0x%016Lx, unit 0x%016Lx)\n",
  2926. zfcp_get_busid_by_adapter(erp_action->adapter),
  2927. erp_action->port->wwpn, erp_action->unit->fcp_lun);
  2928. out:
  2929. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2930. lock_flags);
  2931. return retval;
  2932. }
  2933. /*
  2934. * function: zfcp_fsf_close_unit_handler
  2935. *
  2936. * purpose: is called for finished Close LUN FSF command
  2937. *
  2938. * returns:
  2939. */
  2940. static int
  2941. zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
  2942. {
  2943. int retval = -EINVAL;
  2944. struct zfcp_unit *unit;
  2945. unit = (struct zfcp_unit *) fsf_req->data;
  2946. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2947. /* don't change unit status in our bookkeeping */
  2948. goto skip_fsfstatus;
  2949. }
  2950. /* evaluate FSF status in QTCB */
  2951. switch (fsf_req->qtcb->header.fsf_status) {
  2952. case FSF_PORT_HANDLE_NOT_VALID:
  2953. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  2954. "0x%016Lx on adapter %s invalid. This may "
  2955. "happen in rare circumstances\n",
  2956. unit->port->handle,
  2957. unit->port->wwpn,
  2958. zfcp_get_busid_by_unit(unit));
  2959. ZFCP_LOG_DEBUG("status qualifier:\n");
  2960. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2961. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  2962. sizeof (union fsf_status_qual));
  2963. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
  2964. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2965. break;
  2966. case FSF_LUN_HANDLE_NOT_VALID:
  2967. ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
  2968. "0x%016Lx on port 0x%016Lx on adapter %s is "
  2969. "invalid. This may happen occasionally.\n",
  2970. unit->handle,
  2971. unit->fcp_lun,
  2972. unit->port->wwpn,
  2973. zfcp_get_busid_by_unit(unit));
  2974. ZFCP_LOG_DEBUG("Status qualifier data:\n");
  2975. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2976. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  2977. sizeof (union fsf_status_qual));
  2978. zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
  2979. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2980. break;
  2981. case FSF_PORT_BOXED:
  2982. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  2983. "needs to be reopened\n",
  2984. unit->port->wwpn,
  2985. zfcp_get_busid_by_unit(unit));
  2986. zfcp_erp_port_boxed(unit->port, 52, fsf_req);
  2987. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2988. ZFCP_STATUS_FSFREQ_RETRY;
  2989. break;
  2990. case FSF_ADAPTER_STATUS_AVAILABLE:
  2991. switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  2992. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2993. /* re-establish link to port */
  2994. zfcp_test_link(unit->port);
  2995. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2996. break;
  2997. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2998. /* ERP strategy will escalate */
  2999. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3000. break;
  3001. default:
  3002. ZFCP_LOG_NORMAL
  3003. ("bug: Wrong status qualifier 0x%x arrived.\n",
  3004. fsf_req->qtcb->header.fsf_status_qual.word[0]);
  3005. break;
  3006. }
  3007. break;
  3008. case FSF_GOOD:
  3009. ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
  3010. "closed, port handle 0x%x\n",
  3011. unit->fcp_lun,
  3012. unit->port->wwpn,
  3013. zfcp_get_busid_by_unit(unit),
  3014. unit->handle);
  3015. /* mark unit as closed */
  3016. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  3017. retval = 0;
  3018. break;
  3019. default:
  3020. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  3021. "(debug info 0x%x)\n",
  3022. fsf_req->qtcb->header.fsf_status);
  3023. break;
  3024. }
  3025. skip_fsfstatus:
  3026. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
  3027. return retval;
  3028. }
  3029. /**
  3030. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  3031. * @adapter: adapter where scsi command is issued
  3032. * @unit: unit where command is sent to
  3033. * @scsi_cmnd: scsi command to be sent
  3034. * @timer: timer to be started when request is initiated
  3035. * @req_flags: flags for fsf_request
  3036. */
  3037. int
  3038. zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  3039. struct zfcp_unit *unit,
  3040. struct scsi_cmnd * scsi_cmnd,
  3041. int use_timer, int req_flags)
  3042. {
  3043. struct zfcp_fsf_req *fsf_req = NULL;
  3044. struct fcp_cmnd_iu *fcp_cmnd_iu;
  3045. unsigned int sbtype;
  3046. unsigned long lock_flags;
  3047. int real_bytes = 0;
  3048. int retval = 0;
  3049. int mask;
  3050. /* setup new FSF request */
  3051. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  3052. adapter->pool.fsf_req_scsi,
  3053. &lock_flags, &fsf_req);
  3054. if (unlikely(retval < 0)) {
  3055. ZFCP_LOG_DEBUG("error: Could not create FCP command request "
  3056. "for unit 0x%016Lx on port 0x%016Lx on "
  3057. "adapter %s\n",
  3058. unit->fcp_lun,
  3059. unit->port->wwpn,
  3060. zfcp_get_busid_by_adapter(adapter));
  3061. goto failed_req_create;
  3062. }
  3063. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  3064. &unit->status))) {
  3065. retval = -EBUSY;
  3066. goto unit_blocked;
  3067. }
  3068. zfcp_unit_get(unit);
  3069. fsf_req->unit = unit;
  3070. /* associate FSF request with SCSI request (for look up on abort) */
  3071. scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
  3072. /* associate SCSI command with FSF request */
  3073. fsf_req->data = (unsigned long) scsi_cmnd;
  3074. /* set handles of unit and its parent port in QTCB */
  3075. fsf_req->qtcb->header.lun_handle = unit->handle;
  3076. fsf_req->qtcb->header.port_handle = unit->port->handle;
  3077. /* FSF does not define the structure of the FCP_CMND IU */
  3078. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3079. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3080. /*
  3081. * set depending on data direction:
  3082. * data direction bits in SBALE (SB Type)
  3083. * data direction bits in QTCB
  3084. * data direction bits in FCP_CMND IU
  3085. */
  3086. switch (scsi_cmnd->sc_data_direction) {
  3087. case DMA_NONE:
  3088. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  3089. /*
  3090. * FIXME(qdio):
  3091. * what is the correct type for commands
  3092. * without 'real' data buffers?
  3093. */
  3094. sbtype = SBAL_FLAGS0_TYPE_READ;
  3095. break;
  3096. case DMA_FROM_DEVICE:
  3097. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  3098. sbtype = SBAL_FLAGS0_TYPE_READ;
  3099. fcp_cmnd_iu->rddata = 1;
  3100. break;
  3101. case DMA_TO_DEVICE:
  3102. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  3103. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  3104. fcp_cmnd_iu->wddata = 1;
  3105. break;
  3106. case DMA_BIDIRECTIONAL:
  3107. default:
  3108. /*
  3109. * dummy, catch this condition earlier
  3110. * in zfcp_scsi_queuecommand
  3111. */
  3112. goto failed_scsi_cmnd;
  3113. }
  3114. /* set FC service class in QTCB (3 per default) */
  3115. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  3116. /* set FCP_LUN in FCP_CMND IU in QTCB */
  3117. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  3118. mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
  3119. /* set task attributes in FCP_CMND IU in QTCB */
  3120. if (likely((scsi_cmnd->device->simple_tags) ||
  3121. (atomic_test_mask(mask, &unit->status))))
  3122. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  3123. else
  3124. fcp_cmnd_iu->task_attribute = UNTAGGED;
  3125. /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
  3126. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
  3127. fcp_cmnd_iu->add_fcp_cdb_length
  3128. = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  3129. ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
  3130. "additional FCP_CDB length is 0x%x "
  3131. "(shifted right 2 bits)\n",
  3132. scsi_cmnd->cmd_len,
  3133. fcp_cmnd_iu->add_fcp_cdb_length);
  3134. }
  3135. /*
  3136. * copy SCSI CDB (including additional length, if any) to
  3137. * FCP_CDB in FCP_CMND IU in QTCB
  3138. */
  3139. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  3140. /* FCP CMND IU length in QTCB */
  3141. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  3142. sizeof (struct fcp_cmnd_iu) +
  3143. fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
  3144. /* generate SBALEs from data buffer */
  3145. real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
  3146. if (unlikely(real_bytes < 0)) {
  3147. if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
  3148. ZFCP_LOG_DEBUG(
  3149. "Data did not fit into available buffer(s), "
  3150. "waiting for more...\n");
  3151. retval = -EIO;
  3152. } else {
  3153. ZFCP_LOG_NORMAL("error: No truncation implemented but "
  3154. "required. Shutting down unit "
  3155. "(adapter %s, port 0x%016Lx, "
  3156. "unit 0x%016Lx)\n",
  3157. zfcp_get_busid_by_unit(unit),
  3158. unit->port->wwpn,
  3159. unit->fcp_lun);
  3160. zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
  3161. retval = -EINVAL;
  3162. }
  3163. goto no_fit;
  3164. }
  3165. /* set length of FCP data length in FCP_CMND IU in QTCB */
  3166. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  3167. ZFCP_LOG_DEBUG("Sending SCSI command:\n");
  3168. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3169. (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  3170. if (use_timer)
  3171. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  3172. retval = zfcp_fsf_req_send(fsf_req);
  3173. if (unlikely(retval < 0)) {
  3174. ZFCP_LOG_INFO("error: Could not send FCP command request "
  3175. "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
  3176. zfcp_get_busid_by_adapter(adapter),
  3177. unit->port->wwpn,
  3178. unit->fcp_lun);
  3179. goto send_failed;
  3180. }
  3181. ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
  3182. "port 0x%016Lx, unit 0x%016Lx)\n",
  3183. zfcp_get_busid_by_adapter(adapter),
  3184. unit->port->wwpn,
  3185. unit->fcp_lun);
  3186. goto success;
  3187. send_failed:
  3188. no_fit:
  3189. failed_scsi_cmnd:
  3190. zfcp_unit_put(unit);
  3191. unit_blocked:
  3192. zfcp_fsf_req_free(fsf_req);
  3193. fsf_req = NULL;
  3194. scsi_cmnd->host_scribble = NULL;
  3195. success:
  3196. failed_req_create:
  3197. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3198. return retval;
  3199. }
  3200. struct zfcp_fsf_req *
  3201. zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
  3202. struct zfcp_unit *unit,
  3203. u8 tm_flags, int req_flags)
  3204. {
  3205. struct zfcp_fsf_req *fsf_req = NULL;
  3206. int retval = 0;
  3207. struct fcp_cmnd_iu *fcp_cmnd_iu;
  3208. unsigned long lock_flags;
  3209. volatile struct qdio_buffer_element *sbale;
  3210. /* setup new FSF request */
  3211. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  3212. adapter->pool.fsf_req_scsi,
  3213. &lock_flags, &fsf_req);
  3214. if (retval < 0) {
  3215. ZFCP_LOG_INFO("error: Could not create FCP command (task "
  3216. "management) request for adapter %s, port "
  3217. " 0x%016Lx, unit 0x%016Lx.\n",
  3218. zfcp_get_busid_by_adapter(adapter),
  3219. unit->port->wwpn, unit->fcp_lun);
  3220. goto out;
  3221. }
  3222. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  3223. &unit->status)))
  3224. goto unit_blocked;
  3225. /*
  3226. * Used to decide on proper handler in the return path,
  3227. * could be either zfcp_fsf_send_fcp_command_task_handler or
  3228. * zfcp_fsf_send_fcp_command_task_management_handler */
  3229. fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  3230. /*
  3231. * hold a pointer to the unit being target of this
  3232. * task management request
  3233. */
  3234. fsf_req->data = (unsigned long) unit;
  3235. /* set FSF related fields in QTCB */
  3236. fsf_req->qtcb->header.lun_handle = unit->handle;
  3237. fsf_req->qtcb->header.port_handle = unit->port->handle;
  3238. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  3239. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  3240. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  3241. sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
  3242. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  3243. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  3244. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  3245. /* set FCP related fields in FCP_CMND IU in QTCB */
  3246. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3247. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3248. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  3249. fcp_cmnd_iu->task_management_flags = tm_flags;
  3250. zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
  3251. retval = zfcp_fsf_req_send(fsf_req);
  3252. if (!retval)
  3253. goto out;
  3254. unit_blocked:
  3255. zfcp_fsf_req_free(fsf_req);
  3256. fsf_req = NULL;
  3257. out:
  3258. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3259. return fsf_req;
  3260. }
  3261. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  3262. {
  3263. lat_rec->sum += lat;
  3264. if (lat_rec->min > lat)
  3265. lat_rec->min = lat;
  3266. if (lat_rec->max < lat)
  3267. lat_rec->max = lat;
  3268. }
  3269. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req)
  3270. {
  3271. struct fsf_qual_latency_info *lat_inf;
  3272. struct latency_cont *lat;
  3273. struct zfcp_unit *unit;
  3274. unsigned long flags;
  3275. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  3276. unit = fsf_req->unit;
  3277. switch (fsf_req->qtcb->bottom.io.data_direction) {
  3278. case FSF_DATADIR_READ:
  3279. lat = &unit->latencies.read;
  3280. break;
  3281. case FSF_DATADIR_WRITE:
  3282. lat = &unit->latencies.write;
  3283. break;
  3284. case FSF_DATADIR_CMND:
  3285. lat = &unit->latencies.cmd;
  3286. break;
  3287. default:
  3288. return;
  3289. }
  3290. spin_lock_irqsave(&unit->latencies.lock, flags);
  3291. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  3292. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  3293. lat->counter++;
  3294. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  3295. }
  3296. /*
  3297. * function: zfcp_fsf_send_fcp_command_handler
  3298. *
  3299. * purpose: is called for finished Send FCP Command
  3300. *
  3301. * returns:
  3302. */
  3303. static int
  3304. zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
  3305. {
  3306. int retval = -EINVAL;
  3307. struct zfcp_unit *unit;
  3308. struct fsf_qtcb_header *header;
  3309. u16 subtable, rule, counter;
  3310. header = &fsf_req->qtcb->header;
  3311. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  3312. unit = (struct zfcp_unit *) fsf_req->data;
  3313. else
  3314. unit = fsf_req->unit;
  3315. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  3316. /* go directly to calls of special handlers */
  3317. goto skip_fsfstatus;
  3318. }
  3319. /* evaluate FSF status in QTCB */
  3320. switch (header->fsf_status) {
  3321. case FSF_PORT_HANDLE_NOT_VALID:
  3322. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  3323. "0x%016Lx on adapter %s invalid\n",
  3324. unit->port->handle,
  3325. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  3326. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3327. (char *) &header->fsf_status_qual,
  3328. sizeof (union fsf_status_qual));
  3329. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
  3330. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3331. break;
  3332. case FSF_LUN_HANDLE_NOT_VALID:
  3333. ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
  3334. "0x%016Lx on port 0x%016Lx on adapter %s is "
  3335. "invalid. This may happen occasionally.\n",
  3336. unit->handle,
  3337. unit->fcp_lun,
  3338. unit->port->wwpn,
  3339. zfcp_get_busid_by_unit(unit));
  3340. ZFCP_LOG_NORMAL("Status qualifier data:\n");
  3341. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  3342. (char *) &header->fsf_status_qual,
  3343. sizeof (union fsf_status_qual));
  3344. zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
  3345. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3346. break;
  3347. case FSF_HANDLE_MISMATCH:
  3348. ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
  3349. "unexpectedly. (adapter %s, port 0x%016Lx, "
  3350. "unit 0x%016Lx)\n",
  3351. unit->port->handle,
  3352. zfcp_get_busid_by_unit(unit),
  3353. unit->port->wwpn,
  3354. unit->fcp_lun);
  3355. ZFCP_LOG_NORMAL("status qualifier:\n");
  3356. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  3357. (char *) &header->fsf_status_qual,
  3358. sizeof (union fsf_status_qual));
  3359. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
  3360. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3361. break;
  3362. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  3363. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  3364. "class %d.\n",
  3365. zfcp_get_busid_by_unit(unit),
  3366. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  3367. /* stop operation for this adapter */
  3368. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
  3369. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3370. break;
  3371. case FSF_FCPLUN_NOT_VALID:
  3372. ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
  3373. "adapter %s does not have correct unit "
  3374. "handle 0x%x\n",
  3375. unit->fcp_lun,
  3376. unit->port->wwpn,
  3377. zfcp_get_busid_by_unit(unit),
  3378. unit->handle);
  3379. ZFCP_LOG_DEBUG("status qualifier:\n");
  3380. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3381. (char *) &header->fsf_status_qual,
  3382. sizeof (union fsf_status_qual));
  3383. zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
  3384. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3385. break;
  3386. case FSF_ACCESS_DENIED:
  3387. ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
  3388. "unit 0x%016Lx on port 0x%016Lx on "
  3389. "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
  3390. zfcp_get_busid_by_unit(unit));
  3391. for (counter = 0; counter < 2; counter++) {
  3392. subtable = header->fsf_status_qual.halfword[counter * 2];
  3393. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  3394. switch (subtable) {
  3395. case FSF_SQ_CFDC_SUBTABLE_OS:
  3396. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  3397. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  3398. case FSF_SQ_CFDC_SUBTABLE_LUN:
  3399. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  3400. zfcp_act_subtable_type[subtable], rule);
  3401. break;
  3402. }
  3403. }
  3404. zfcp_erp_unit_access_denied(unit, 61, fsf_req);
  3405. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3406. break;
  3407. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  3408. ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
  3409. "0x%016Lx on port 0x%016Lx on adapter %s "
  3410. "(debug info %d)\n",
  3411. unit->fcp_lun,
  3412. unit->port->wwpn,
  3413. zfcp_get_busid_by_unit(unit),
  3414. fsf_req->qtcb->bottom.io.data_direction);
  3415. /* stop operation for this adapter */
  3416. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
  3417. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3418. break;
  3419. case FSF_CMND_LENGTH_NOT_VALID:
  3420. ZFCP_LOG_NORMAL
  3421. ("bug: An invalid control-data-block length field "
  3422. "was found in a command for unit 0x%016Lx on port "
  3423. "0x%016Lx on adapter %s " "(debug info %d)\n",
  3424. unit->fcp_lun, unit->port->wwpn,
  3425. zfcp_get_busid_by_unit(unit),
  3426. fsf_req->qtcb->bottom.io.fcp_cmnd_length);
  3427. /* stop operation for this adapter */
  3428. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
  3429. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3430. break;
  3431. case FSF_PORT_BOXED:
  3432. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  3433. "needs to be reopened\n",
  3434. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  3435. zfcp_erp_port_boxed(unit->port, 53, fsf_req);
  3436. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  3437. ZFCP_STATUS_FSFREQ_RETRY;
  3438. break;
  3439. case FSF_LUN_BOXED:
  3440. ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
  3441. "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
  3442. zfcp_get_busid_by_unit(unit),
  3443. unit->port->wwpn, unit->fcp_lun);
  3444. zfcp_erp_unit_boxed(unit, 54, fsf_req);
  3445. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  3446. | ZFCP_STATUS_FSFREQ_RETRY;
  3447. break;
  3448. case FSF_ADAPTER_STATUS_AVAILABLE:
  3449. switch (header->fsf_status_qual.word[0]) {
  3450. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  3451. /* re-establish link to port */
  3452. zfcp_test_link(unit->port);
  3453. break;
  3454. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  3455. /* FIXME(hw) need proper specs for proper action */
  3456. /* let scsi stack deal with retries and escalation */
  3457. break;
  3458. default:
  3459. ZFCP_LOG_NORMAL
  3460. ("Unknown status qualifier 0x%x arrived.\n",
  3461. header->fsf_status_qual.word[0]);
  3462. break;
  3463. }
  3464. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3465. break;
  3466. case FSF_GOOD:
  3467. break;
  3468. case FSF_FCP_RSP_AVAILABLE:
  3469. break;
  3470. }
  3471. skip_fsfstatus:
  3472. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
  3473. retval =
  3474. zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
  3475. } else {
  3476. retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
  3477. fsf_req->unit = NULL;
  3478. zfcp_unit_put(unit);
  3479. }
  3480. return retval;
  3481. }
  3482. /*
  3483. * function: zfcp_fsf_send_fcp_command_task_handler
  3484. *
  3485. * purpose: evaluates FCP_RSP IU
  3486. *
  3487. * returns:
  3488. */
  3489. static int
  3490. zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
  3491. {
  3492. int retval = 0;
  3493. struct scsi_cmnd *scpnt;
  3494. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  3495. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  3496. struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3497. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3498. u32 sns_len;
  3499. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  3500. unsigned long flags;
  3501. struct zfcp_unit *unit = fsf_req->unit;
  3502. read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
  3503. scpnt = (struct scsi_cmnd *) fsf_req->data;
  3504. if (unlikely(!scpnt)) {
  3505. ZFCP_LOG_DEBUG
  3506. ("Command with fsf_req %p is not associated to "
  3507. "a scsi command anymore. Aborted?\n", fsf_req);
  3508. goto out;
  3509. }
  3510. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  3511. /* FIXME: (design) mid-layer should handle DID_ABORT like
  3512. * DID_SOFT_ERROR by retrying the request for devices
  3513. * that allow retries.
  3514. */
  3515. ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
  3516. set_host_byte(&scpnt->result, DID_SOFT_ERROR);
  3517. set_driver_byte(&scpnt->result, SUGGEST_RETRY);
  3518. goto skip_fsfstatus;
  3519. }
  3520. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  3521. ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
  3522. set_host_byte(&scpnt->result, DID_ERROR);
  3523. goto skip_fsfstatus;
  3524. }
  3525. /* set message byte of result in SCSI command */
  3526. scpnt->result |= COMMAND_COMPLETE << 8;
  3527. /*
  3528. * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
  3529. * of result in SCSI command
  3530. */
  3531. scpnt->result |= fcp_rsp_iu->scsi_status;
  3532. if (unlikely(fcp_rsp_iu->scsi_status)) {
  3533. /* DEBUG */
  3534. ZFCP_LOG_DEBUG("status for SCSI Command:\n");
  3535. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3536. scpnt->cmnd, scpnt->cmd_len);
  3537. ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
  3538. fcp_rsp_iu->scsi_status);
  3539. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3540. (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
  3541. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3542. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
  3543. fcp_rsp_iu->fcp_sns_len);
  3544. }
  3545. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  3546. zfcp_fsf_req_latency(fsf_req);
  3547. /* check FCP_RSP_INFO */
  3548. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  3549. ZFCP_LOG_DEBUG("rsp_len is valid\n");
  3550. switch (fcp_rsp_info[3]) {
  3551. case RSP_CODE_GOOD:
  3552. /* ok, continue */
  3553. ZFCP_LOG_TRACE("no failure or Task Management "
  3554. "Function complete\n");
  3555. set_host_byte(&scpnt->result, DID_OK);
  3556. break;
  3557. case RSP_CODE_LENGTH_MISMATCH:
  3558. /* hardware bug */
  3559. ZFCP_LOG_NORMAL("bug: FCP response code indictates "
  3560. "that the fibrechannel protocol data "
  3561. "length differs from the burst length. "
  3562. "The problem occured on unit 0x%016Lx "
  3563. "on port 0x%016Lx on adapter %s",
  3564. unit->fcp_lun,
  3565. unit->port->wwpn,
  3566. zfcp_get_busid_by_unit(unit));
  3567. /* dump SCSI CDB as prepared by zfcp */
  3568. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3569. (char *) &fsf_req->qtcb->
  3570. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3571. set_host_byte(&scpnt->result, DID_ERROR);
  3572. goto skip_fsfstatus;
  3573. case RSP_CODE_FIELD_INVALID:
  3574. /* driver or hardware bug */
  3575. ZFCP_LOG_NORMAL("bug: FCP response code indictates "
  3576. "that the fibrechannel protocol data "
  3577. "fields were incorrectly set up. "
  3578. "The problem occured on the unit "
  3579. "0x%016Lx on port 0x%016Lx on "
  3580. "adapter %s",
  3581. unit->fcp_lun,
  3582. unit->port->wwpn,
  3583. zfcp_get_busid_by_unit(unit));
  3584. /* dump SCSI CDB as prepared by zfcp */
  3585. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3586. (char *) &fsf_req->qtcb->
  3587. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3588. set_host_byte(&scpnt->result, DID_ERROR);
  3589. goto skip_fsfstatus;
  3590. case RSP_CODE_RO_MISMATCH:
  3591. /* hardware bug */
  3592. ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
  3593. "that conflicting values for the "
  3594. "fibrechannel payload offset from the "
  3595. "header were found. "
  3596. "The problem occured on unit 0x%016Lx "
  3597. "on port 0x%016Lx on adapter %s.\n",
  3598. unit->fcp_lun,
  3599. unit->port->wwpn,
  3600. zfcp_get_busid_by_unit(unit));
  3601. /* dump SCSI CDB as prepared by zfcp */
  3602. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3603. (char *) &fsf_req->qtcb->
  3604. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3605. set_host_byte(&scpnt->result, DID_ERROR);
  3606. goto skip_fsfstatus;
  3607. default:
  3608. ZFCP_LOG_NORMAL("bug: An invalid FCP response "
  3609. "code was detected for a command. "
  3610. "The problem occured on the unit "
  3611. "0x%016Lx on port 0x%016Lx on "
  3612. "adapter %s (debug info 0x%x)\n",
  3613. unit->fcp_lun,
  3614. unit->port->wwpn,
  3615. zfcp_get_busid_by_unit(unit),
  3616. fcp_rsp_info[3]);
  3617. /* dump SCSI CDB as prepared by zfcp */
  3618. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3619. (char *) &fsf_req->qtcb->
  3620. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3621. set_host_byte(&scpnt->result, DID_ERROR);
  3622. goto skip_fsfstatus;
  3623. }
  3624. }
  3625. /* check for sense data */
  3626. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  3627. sns_len = FSF_FCP_RSP_SIZE -
  3628. sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
  3629. ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
  3630. sns_len);
  3631. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  3632. ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
  3633. SCSI_SENSE_BUFFERSIZE);
  3634. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  3635. ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
  3636. scpnt->result);
  3637. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
  3638. scpnt->cmnd, scpnt->cmd_len);
  3639. ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
  3640. fcp_rsp_iu->fcp_sns_len);
  3641. memcpy(scpnt->sense_buffer,
  3642. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  3643. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
  3644. (void *)scpnt->sense_buffer, sns_len);
  3645. }
  3646. /* check for overrun */
  3647. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
  3648. ZFCP_LOG_INFO("A data overrun was detected for a command. "
  3649. "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
  3650. "The response data length is "
  3651. "%d, the original length was %d.\n",
  3652. unit->fcp_lun,
  3653. unit->port->wwpn,
  3654. zfcp_get_busid_by_unit(unit),
  3655. fcp_rsp_iu->fcp_resid,
  3656. (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
  3657. }
  3658. /* check for underrun */
  3659. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  3660. ZFCP_LOG_INFO("A data underrun was detected for a command. "
  3661. "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
  3662. "The response data length is "
  3663. "%d, the original length was %d.\n",
  3664. unit->fcp_lun,
  3665. unit->port->wwpn,
  3666. zfcp_get_busid_by_unit(unit),
  3667. fcp_rsp_iu->fcp_resid,
  3668. (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
  3669. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  3670. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  3671. scpnt->underflow)
  3672. set_host_byte(&scpnt->result, DID_ERROR);
  3673. }
  3674. skip_fsfstatus:
  3675. ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
  3676. if (scpnt->result != 0)
  3677. zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
  3678. else if (scpnt->retries > 0)
  3679. zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
  3680. else
  3681. zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
  3682. /* cleanup pointer (need this especially for abort) */
  3683. scpnt->host_scribble = NULL;
  3684. /* always call back */
  3685. (scpnt->scsi_done) (scpnt);
  3686. /*
  3687. * We must hold this lock until scsi_done has been called.
  3688. * Otherwise we may call scsi_done after abort regarding this
  3689. * command has completed.
  3690. * Note: scsi_done must not block!
  3691. */
  3692. out:
  3693. read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
  3694. return retval;
  3695. }
  3696. /*
  3697. * function: zfcp_fsf_send_fcp_command_task_management_handler
  3698. *
  3699. * purpose: evaluates FCP_RSP IU
  3700. *
  3701. * returns:
  3702. */
  3703. static int
  3704. zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
  3705. {
  3706. int retval = 0;
  3707. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  3708. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  3709. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  3710. struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
  3711. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  3712. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3713. goto skip_fsfstatus;
  3714. }
  3715. /* check FCP_RSP_INFO */
  3716. switch (fcp_rsp_info[3]) {
  3717. case RSP_CODE_GOOD:
  3718. /* ok, continue */
  3719. ZFCP_LOG_DEBUG("no failure or Task Management "
  3720. "Function complete\n");
  3721. break;
  3722. case RSP_CODE_TASKMAN_UNSUPP:
  3723. ZFCP_LOG_NORMAL("bug: A reuested task management function "
  3724. "is not supported on the target device "
  3725. "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
  3726. unit->fcp_lun,
  3727. unit->port->wwpn,
  3728. zfcp_get_busid_by_unit(unit));
  3729. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
  3730. break;
  3731. case RSP_CODE_TASKMAN_FAILED:
  3732. ZFCP_LOG_NORMAL("bug: A reuested task management function "
  3733. "failed to complete successfully. "
  3734. "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
  3735. unit->fcp_lun,
  3736. unit->port->wwpn,
  3737. zfcp_get_busid_by_unit(unit));
  3738. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3739. break;
  3740. default:
  3741. ZFCP_LOG_NORMAL("bug: An invalid FCP response "
  3742. "code was detected for a command. "
  3743. "unit 0x%016Lx, port 0x%016Lx, adapter %s "
  3744. "(debug info 0x%x)\n",
  3745. unit->fcp_lun,
  3746. unit->port->wwpn,
  3747. zfcp_get_busid_by_unit(unit),
  3748. fcp_rsp_info[3]);
  3749. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3750. }
  3751. skip_fsfstatus:
  3752. return retval;
  3753. }
  3754. /*
  3755. * function: zfcp_fsf_control_file
  3756. *
  3757. * purpose: Initiator of the control file upload/download FSF requests
  3758. *
  3759. * returns: 0 - FSF request is successfuly created and queued
  3760. * -EOPNOTSUPP - The FCP adapter does not have Control File support
  3761. * -EINVAL - Invalid direction specified
  3762. * -ENOMEM - Insufficient memory
  3763. * -EPERM - Cannot create FSF request or place it in QDIO queue
  3764. */
  3765. int
  3766. zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  3767. struct zfcp_fsf_req **fsf_req_ptr,
  3768. u32 fsf_command,
  3769. u32 option,
  3770. struct zfcp_sg_list *sg_list)
  3771. {
  3772. struct zfcp_fsf_req *fsf_req;
  3773. struct fsf_qtcb_bottom_support *bottom;
  3774. volatile struct qdio_buffer_element *sbale;
  3775. unsigned long lock_flags;
  3776. int req_flags = 0;
  3777. int direction;
  3778. int retval = 0;
  3779. if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
  3780. ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
  3781. zfcp_get_busid_by_adapter(adapter));
  3782. retval = -EOPNOTSUPP;
  3783. goto out;
  3784. }
  3785. switch (fsf_command) {
  3786. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  3787. direction = SBAL_FLAGS0_TYPE_WRITE;
  3788. if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
  3789. (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
  3790. req_flags = ZFCP_WAIT_FOR_SBAL;
  3791. break;
  3792. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  3793. direction = SBAL_FLAGS0_TYPE_READ;
  3794. break;
  3795. default:
  3796. ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
  3797. retval = -EINVAL;
  3798. goto out;
  3799. }
  3800. retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
  3801. NULL, &lock_flags, &fsf_req);
  3802. if (retval < 0) {
  3803. ZFCP_LOG_INFO("error: Could not create FSF request for the "
  3804. "adapter %s\n",
  3805. zfcp_get_busid_by_adapter(adapter));
  3806. retval = -EPERM;
  3807. goto unlock_queue_lock;
  3808. }
  3809. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  3810. sbale[0].flags |= direction;
  3811. bottom = &fsf_req->qtcb->bottom.support;
  3812. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  3813. bottom->option = option;
  3814. if (sg_list->count > 0) {
  3815. int bytes;
  3816. bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
  3817. sg_list->sg, sg_list->count,
  3818. ZFCP_MAX_SBALS_PER_REQ);
  3819. if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
  3820. ZFCP_LOG_INFO(
  3821. "error: Could not create sufficient number of "
  3822. "SBALS for an FSF request to the adapter %s\n",
  3823. zfcp_get_busid_by_adapter(adapter));
  3824. retval = -ENOMEM;
  3825. goto free_fsf_req;
  3826. }
  3827. } else
  3828. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  3829. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  3830. retval = zfcp_fsf_req_send(fsf_req);
  3831. if (retval < 0) {
  3832. ZFCP_LOG_INFO("initiation of cfdc up/download failed"
  3833. "(adapter %s)\n",
  3834. zfcp_get_busid_by_adapter(adapter));
  3835. retval = -EPERM;
  3836. goto free_fsf_req;
  3837. }
  3838. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3839. ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
  3840. "adapter %s\n",
  3841. fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
  3842. "download" : "upload",
  3843. zfcp_get_busid_by_adapter(adapter));
  3844. wait_event(fsf_req->completion_wq,
  3845. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  3846. *fsf_req_ptr = fsf_req;
  3847. goto out;
  3848. free_fsf_req:
  3849. zfcp_fsf_req_free(fsf_req);
  3850. unlock_queue_lock:
  3851. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3852. out:
  3853. return retval;
  3854. }
  3855. /*
  3856. * function: zfcp_fsf_control_file_handler
  3857. *
  3858. * purpose: Handler of the control file upload/download FSF requests
  3859. *
  3860. * returns: 0 - FSF request successfuly processed
  3861. * -EAGAIN - Operation has to be repeated because of a temporary problem
  3862. * -EACCES - There is no permission to execute an operation
  3863. * -EPERM - The control file is not in a right format
  3864. * -EIO - There is a problem with the FCP adapter
  3865. * -EINVAL - Invalid operation
  3866. * -EFAULT - User space memory I/O operation fault
  3867. */
  3868. static int
  3869. zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
  3870. {
  3871. struct zfcp_adapter *adapter = fsf_req->adapter;
  3872. struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
  3873. struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
  3874. int retval = 0;
  3875. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  3876. retval = -EINVAL;
  3877. goto skip_fsfstatus;
  3878. }
  3879. switch (header->fsf_status) {
  3880. case FSF_GOOD:
  3881. ZFCP_LOG_NORMAL(
  3882. "The FSF request has been successfully completed "
  3883. "on the adapter %s\n",
  3884. zfcp_get_busid_by_adapter(adapter));
  3885. break;
  3886. case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
  3887. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
  3888. switch (header->fsf_status_qual.word[0]) {
  3889. case FSF_SQ_CFDC_HARDENED_ON_SE:
  3890. ZFCP_LOG_NORMAL(
  3891. "CFDC on the adapter %s has being "
  3892. "hardened on primary and secondary SE\n",
  3893. zfcp_get_busid_by_adapter(adapter));
  3894. break;
  3895. case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
  3896. ZFCP_LOG_NORMAL(
  3897. "CFDC of the adapter %s could not "
  3898. "be saved on the SE\n",
  3899. zfcp_get_busid_by_adapter(adapter));
  3900. break;
  3901. case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
  3902. ZFCP_LOG_NORMAL(
  3903. "CFDC of the adapter %s could not "
  3904. "be copied to the secondary SE\n",
  3905. zfcp_get_busid_by_adapter(adapter));
  3906. break;
  3907. default:
  3908. ZFCP_LOG_NORMAL(
  3909. "CFDC could not be hardened "
  3910. "on the adapter %s\n",
  3911. zfcp_get_busid_by_adapter(adapter));
  3912. }
  3913. }
  3914. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3915. retval = -EAGAIN;
  3916. break;
  3917. case FSF_AUTHORIZATION_FAILURE:
  3918. ZFCP_LOG_NORMAL(
  3919. "Adapter %s does not accept privileged commands\n",
  3920. zfcp_get_busid_by_adapter(adapter));
  3921. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3922. retval = -EACCES;
  3923. break;
  3924. case FSF_CFDC_ERROR_DETECTED:
  3925. ZFCP_LOG_NORMAL(
  3926. "Error at position %d in the CFDC, "
  3927. "CFDC is discarded by the adapter %s\n",
  3928. header->fsf_status_qual.word[0],
  3929. zfcp_get_busid_by_adapter(adapter));
  3930. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3931. retval = -EPERM;
  3932. break;
  3933. case FSF_CONTROL_FILE_UPDATE_ERROR:
  3934. ZFCP_LOG_NORMAL(
  3935. "Adapter %s cannot harden the control file, "
  3936. "file is discarded\n",
  3937. zfcp_get_busid_by_adapter(adapter));
  3938. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3939. retval = -EIO;
  3940. break;
  3941. case FSF_CONTROL_FILE_TOO_LARGE:
  3942. ZFCP_LOG_NORMAL(
  3943. "Control file is too large, file is discarded "
  3944. "by the adapter %s\n",
  3945. zfcp_get_busid_by_adapter(adapter));
  3946. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3947. retval = -EIO;
  3948. break;
  3949. case FSF_ACCESS_CONFLICT_DETECTED:
  3950. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
  3951. ZFCP_LOG_NORMAL(
  3952. "CFDC has been discarded by the adapter %s, "
  3953. "because activation would impact "
  3954. "%d active connection(s)\n",
  3955. zfcp_get_busid_by_adapter(adapter),
  3956. header->fsf_status_qual.word[0]);
  3957. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3958. retval = -EIO;
  3959. break;
  3960. case FSF_CONFLICTS_OVERRULED:
  3961. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
  3962. ZFCP_LOG_NORMAL(
  3963. "CFDC has been activated on the adapter %s, "
  3964. "but activation has impacted "
  3965. "%d active connection(s)\n",
  3966. zfcp_get_busid_by_adapter(adapter),
  3967. header->fsf_status_qual.word[0]);
  3968. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3969. retval = -EIO;
  3970. break;
  3971. case FSF_UNKNOWN_OP_SUBTYPE:
  3972. ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
  3973. "op_subtype=0x%x)\n",
  3974. zfcp_get_busid_by_adapter(adapter),
  3975. bottom->operation_subtype);
  3976. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3977. retval = -EINVAL;
  3978. break;
  3979. case FSF_INVALID_COMMAND_OPTION:
  3980. ZFCP_LOG_NORMAL(
  3981. "Invalid option 0x%x has been specified "
  3982. "in QTCB bottom sent to the adapter %s\n",
  3983. bottom->option,
  3984. zfcp_get_busid_by_adapter(adapter));
  3985. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3986. retval = -EINVAL;
  3987. break;
  3988. default:
  3989. ZFCP_LOG_NORMAL(
  3990. "bug: An unknown/unexpected FSF status 0x%08x "
  3991. "was presented on the adapter %s\n",
  3992. header->fsf_status,
  3993. zfcp_get_busid_by_adapter(adapter));
  3994. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3995. retval = -EINVAL;
  3996. break;
  3997. }
  3998. skip_fsfstatus:
  3999. return retval;
  4000. }
  4001. static inline int
  4002. zfcp_fsf_req_sbal_check(unsigned long *flags,
  4003. struct zfcp_qdio_queue *queue, int needed)
  4004. {
  4005. write_lock_irqsave(&queue->queue_lock, *flags);
  4006. if (likely(atomic_read(&queue->free_count) >= needed))
  4007. return 1;
  4008. write_unlock_irqrestore(&queue->queue_lock, *flags);
  4009. return 0;
  4010. }
  4011. /*
  4012. * set qtcb pointer in fsf_req and initialize QTCB
  4013. */
  4014. static void
  4015. zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
  4016. {
  4017. if (likely(fsf_req->qtcb != NULL)) {
  4018. fsf_req->qtcb->prefix.req_seq_no =
  4019. fsf_req->adapter->fsf_req_seq_no;
  4020. fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
  4021. fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
  4022. fsf_req->qtcb->prefix.qtcb_type =
  4023. fsf_qtcb_type[fsf_req->fsf_command];
  4024. fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
  4025. fsf_req->qtcb->header.req_handle = fsf_req->req_id;
  4026. fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
  4027. }
  4028. }
  4029. /**
  4030. * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
  4031. * @adapter: adapter for which request queue is examined
  4032. * @req_flags: flags indicating whether to wait for needed SBAL or not
  4033. * @lock_flags: lock_flags if queue_lock is taken
  4034. * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
  4035. * Locks: lock adapter->request_queue->queue_lock on success
  4036. */
  4037. static int
  4038. zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
  4039. unsigned long *lock_flags)
  4040. {
  4041. long ret;
  4042. struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
  4043. if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
  4044. ret = wait_event_interruptible_timeout(adapter->request_wq,
  4045. zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
  4046. ZFCP_SBAL_TIMEOUT);
  4047. if (ret < 0)
  4048. return ret;
  4049. if (!ret)
  4050. return -EIO;
  4051. } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
  4052. return -EIO;
  4053. return 0;
  4054. }
  4055. /*
  4056. * function: zfcp_fsf_req_create
  4057. *
  4058. * purpose: create an FSF request at the specified adapter and
  4059. * setup common fields
  4060. *
  4061. * returns: -ENOMEM if there was insufficient memory for a request
  4062. * -EIO if no qdio buffers could be allocate to the request
  4063. * -EINVAL/-EPERM on bug conditions in req_dequeue
  4064. * 0 in success
  4065. *
  4066. * note: The created request is returned by reference.
  4067. *
  4068. * locks: lock of concerned request queue must not be held,
  4069. * but is held on completion (write, irqsave)
  4070. */
  4071. int
  4072. zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
  4073. mempool_t *pool, unsigned long *lock_flags,
  4074. struct zfcp_fsf_req **fsf_req_p)
  4075. {
  4076. volatile struct qdio_buffer_element *sbale;
  4077. struct zfcp_fsf_req *fsf_req = NULL;
  4078. int ret = 0;
  4079. struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
  4080. /* allocate new FSF request */
  4081. fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
  4082. if (unlikely(NULL == fsf_req)) {
  4083. ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
  4084. "the outbound (send) queue.\n");
  4085. ret = -ENOMEM;
  4086. goto failed_fsf_req;
  4087. }
  4088. fsf_req->adapter = adapter;
  4089. fsf_req->fsf_command = fsf_cmd;
  4090. INIT_LIST_HEAD(&fsf_req->list);
  4091. init_timer(&fsf_req->timer);
  4092. /* initialize waitqueue which may be used to wait on
  4093. this request completion */
  4094. init_waitqueue_head(&fsf_req->completion_wq);
  4095. ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
  4096. if (ret < 0)
  4097. goto failed_sbals;
  4098. /* this is serialized (we are holding req_queue-lock of adapter) */
  4099. if (adapter->req_no == 0)
  4100. adapter->req_no++;
  4101. fsf_req->req_id = adapter->req_no++;
  4102. zfcp_fsf_req_qtcb_init(fsf_req);
  4103. /*
  4104. * We hold queue_lock here. Check if QDIOUP is set and let request fail
  4105. * if it is not set (see also *_open_qdio and *_close_qdio).
  4106. */
  4107. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  4108. write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
  4109. ret = -EIO;
  4110. goto failed_sbals;
  4111. }
  4112. if (fsf_req->qtcb) {
  4113. fsf_req->seq_no = adapter->fsf_req_seq_no;
  4114. fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  4115. }
  4116. fsf_req->sbal_number = 1;
  4117. fsf_req->sbal_first = req_queue->free_index;
  4118. fsf_req->sbal_curr = req_queue->free_index;
  4119. fsf_req->sbale_curr = 1;
  4120. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
  4121. fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  4122. }
  4123. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  4124. /* setup common SBALE fields */
  4125. sbale[0].addr = (void *) fsf_req->req_id;
  4126. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  4127. if (likely(fsf_req->qtcb != NULL)) {
  4128. sbale[1].addr = (void *) fsf_req->qtcb;
  4129. sbale[1].length = sizeof(struct fsf_qtcb);
  4130. }
  4131. ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
  4132. fsf_req->sbal_number, fsf_req->sbal_first);
  4133. goto success;
  4134. failed_sbals:
  4135. /* dequeue new FSF request previously enqueued */
  4136. zfcp_fsf_req_free(fsf_req);
  4137. fsf_req = NULL;
  4138. failed_fsf_req:
  4139. write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
  4140. success:
  4141. *fsf_req_p = fsf_req;
  4142. return ret;
  4143. }
  4144. /*
  4145. * function: zfcp_fsf_req_send
  4146. *
  4147. * purpose: start transfer of FSF request via QDIO
  4148. *
  4149. * returns: 0 - request transfer succesfully started
  4150. * !0 - start of request transfer failed
  4151. */
  4152. static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
  4153. {
  4154. struct zfcp_adapter *adapter;
  4155. struct zfcp_qdio_queue *req_queue;
  4156. volatile struct qdio_buffer_element *sbale;
  4157. int inc_seq_no;
  4158. int new_distance_from_int;
  4159. int retval = 0;
  4160. adapter = fsf_req->adapter;
  4161. req_queue = &adapter->request_queue,
  4162. /* FIXME(debug): remove it later */
  4163. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
  4164. ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
  4165. ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
  4166. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
  4167. sbale[1].length);
  4168. /* put allocated FSF request into hash table */
  4169. spin_lock(&adapter->req_list_lock);
  4170. zfcp_reqlist_add(adapter, fsf_req);
  4171. spin_unlock(&adapter->req_list_lock);
  4172. inc_seq_no = (fsf_req->qtcb != NULL);
  4173. ZFCP_LOG_TRACE("request queue of adapter %s: "
  4174. "next free SBAL is %i, %i free SBALs\n",
  4175. zfcp_get_busid_by_adapter(adapter),
  4176. req_queue->free_index,
  4177. atomic_read(&req_queue->free_count));
  4178. ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
  4179. "index_in_queue=%i, count=%i, buffers=%p\n",
  4180. zfcp_get_busid_by_adapter(adapter),
  4181. QDIO_FLAG_SYNC_OUTPUT,
  4182. 0, fsf_req->sbal_first, fsf_req->sbal_number,
  4183. &req_queue->buffer[fsf_req->sbal_first]);
  4184. /*
  4185. * adjust the number of free SBALs in request queue as well as
  4186. * position of first one
  4187. */
  4188. atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
  4189. ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
  4190. req_queue->free_index += fsf_req->sbal_number; /* increase */
  4191. req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
  4192. new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
  4193. fsf_req->issued = get_clock();
  4194. retval = do_QDIO(adapter->ccw_device,
  4195. QDIO_FLAG_SYNC_OUTPUT,
  4196. 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
  4197. if (unlikely(retval)) {
  4198. /* Queues are down..... */
  4199. retval = -EIO;
  4200. del_timer(&fsf_req->timer);
  4201. spin_lock(&adapter->req_list_lock);
  4202. zfcp_reqlist_remove(adapter, fsf_req);
  4203. spin_unlock(&adapter->req_list_lock);
  4204. /* undo changes in request queue made for this request */
  4205. zfcp_qdio_zero_sbals(req_queue->buffer,
  4206. fsf_req->sbal_first, fsf_req->sbal_number);
  4207. atomic_add(fsf_req->sbal_number, &req_queue->free_count);
  4208. req_queue->free_index -= fsf_req->sbal_number;
  4209. req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
  4210. req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
  4211. zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
  4212. } else {
  4213. req_queue->distance_from_int = new_distance_from_int;
  4214. /*
  4215. * increase FSF sequence counter -
  4216. * this must only be done for request successfully enqueued to
  4217. * QDIO this rejected requests may be cleaned up by calling
  4218. * routines resulting in missing sequence counter values
  4219. * otherwise,
  4220. */
  4221. /* Don't increase for unsolicited status */
  4222. if (inc_seq_no)
  4223. adapter->fsf_req_seq_no++;
  4224. /* count FSF requests pending */
  4225. atomic_inc(&adapter->reqs_active);
  4226. }
  4227. return retval;
  4228. }
  4229. #undef ZFCP_LOG_AREA