zfcp_fsf.c 145 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739
  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. retval = zfcp_fsf_status_read(adapter, 0);
  922. if (retval < 0) {
  923. ZFCP_LOG_INFO("Failed to create unsolicited status read "
  924. "request for the adapter %s.\n",
  925. zfcp_get_busid_by_adapter(adapter));
  926. /* temporary fix to avoid status read buffer shortage */
  927. adapter->status_read_failed++;
  928. if ((ZFCP_STATUS_READS_RECOM - adapter->status_read_failed)
  929. < ZFCP_STATUS_READ_FAILED_THRESHOLD) {
  930. ZFCP_LOG_INFO("restart adapter %s due to status read "
  931. "buffer shortage\n",
  932. zfcp_get_busid_by_adapter(adapter));
  933. zfcp_erp_adapter_reopen(adapter, 0, 103, fsf_req);
  934. }
  935. }
  936. out:
  937. return retval;
  938. }
  939. /*
  940. * function: zfcp_fsf_abort_fcp_command
  941. *
  942. * purpose: tells FSF to abort a running SCSI command
  943. *
  944. * returns: address of initiated FSF request
  945. * NULL - request could not be initiated
  946. *
  947. * FIXME(design): should be watched by a timeout !!!
  948. * FIXME(design) shouldn't this be modified to return an int
  949. * also...don't know how though
  950. */
  951. struct zfcp_fsf_req *
  952. zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
  953. struct zfcp_adapter *adapter,
  954. struct zfcp_unit *unit, int req_flags)
  955. {
  956. volatile struct qdio_buffer_element *sbale;
  957. struct zfcp_fsf_req *fsf_req = NULL;
  958. unsigned long lock_flags;
  959. int retval = 0;
  960. /* setup new FSF request */
  961. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_ABORT_FCP_CMND,
  962. req_flags, adapter->pool.fsf_req_abort,
  963. &lock_flags, &fsf_req);
  964. if (retval < 0) {
  965. ZFCP_LOG_INFO("error: Failed to create an abort command "
  966. "request for lun 0x%016Lx on port 0x%016Lx "
  967. "on adapter %s.\n",
  968. unit->fcp_lun,
  969. unit->port->wwpn,
  970. zfcp_get_busid_by_adapter(adapter));
  971. goto out;
  972. }
  973. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  974. &unit->status)))
  975. goto unit_blocked;
  976. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  977. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  978. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  979. fsf_req->data = (unsigned long) unit;
  980. /* set handles of unit and its parent port in QTCB */
  981. fsf_req->qtcb->header.lun_handle = unit->handle;
  982. fsf_req->qtcb->header.port_handle = unit->port->handle;
  983. /* set handle of request which should be aborted */
  984. fsf_req->qtcb->bottom.support.req_handle = (u64) old_req_id;
  985. zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
  986. retval = zfcp_fsf_req_send(fsf_req);
  987. if (!retval)
  988. goto out;
  989. unit_blocked:
  990. zfcp_fsf_req_free(fsf_req);
  991. fsf_req = NULL;
  992. out:
  993. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  994. return fsf_req;
  995. }
  996. /*
  997. * function: zfcp_fsf_abort_fcp_command_handler
  998. *
  999. * purpose: is called for finished Abort FCP Command request
  1000. *
  1001. * returns:
  1002. */
  1003. static int
  1004. zfcp_fsf_abort_fcp_command_handler(struct zfcp_fsf_req *new_fsf_req)
  1005. {
  1006. int retval = -EINVAL;
  1007. struct zfcp_unit *unit;
  1008. union fsf_status_qual *fsf_stat_qual =
  1009. &new_fsf_req->qtcb->header.fsf_status_qual;
  1010. if (new_fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  1011. /* do not set ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED */
  1012. goto skip_fsfstatus;
  1013. }
  1014. unit = (struct zfcp_unit *) new_fsf_req->data;
  1015. /* evaluate FSF status in QTCB */
  1016. switch (new_fsf_req->qtcb->header.fsf_status) {
  1017. case FSF_PORT_HANDLE_NOT_VALID:
  1018. if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
  1019. /*
  1020. * In this case a command that was sent prior to a port
  1021. * reopen was aborted (handles are different). This is
  1022. * fine.
  1023. */
  1024. } else {
  1025. ZFCP_LOG_INFO("Temporary port identifier 0x%x for "
  1026. "port 0x%016Lx on adapter %s invalid. "
  1027. "This may happen occasionally.\n",
  1028. unit->port->handle,
  1029. unit->port->wwpn,
  1030. zfcp_get_busid_by_unit(unit));
  1031. ZFCP_LOG_INFO("status qualifier:\n");
  1032. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1033. (char *) &new_fsf_req->qtcb->header.
  1034. fsf_status_qual,
  1035. sizeof (union fsf_status_qual));
  1036. /* Let's hope this sorts out the mess */
  1037. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 104,
  1038. new_fsf_req);
  1039. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1040. }
  1041. break;
  1042. case FSF_LUN_HANDLE_NOT_VALID:
  1043. if (fsf_stat_qual->word[0] != fsf_stat_qual->word[1]) {
  1044. /*
  1045. * In this case a command that was sent prior to a unit
  1046. * reopen was aborted (handles are different).
  1047. * This is fine.
  1048. */
  1049. } else {
  1050. ZFCP_LOG_INFO
  1051. ("Warning: Temporary LUN identifier 0x%x of LUN "
  1052. "0x%016Lx on port 0x%016Lx on adapter %s is "
  1053. "invalid. This may happen in rare cases. "
  1054. "Trying to re-establish link.\n",
  1055. unit->handle,
  1056. unit->fcp_lun,
  1057. unit->port->wwpn,
  1058. zfcp_get_busid_by_unit(unit));
  1059. ZFCP_LOG_DEBUG("Status qualifier data:\n");
  1060. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  1061. (char *) &new_fsf_req->qtcb->header.
  1062. fsf_status_qual,
  1063. sizeof (union fsf_status_qual));
  1064. /* Let's hope this sorts out the mess */
  1065. zfcp_erp_port_reopen(unit->port, 0, 105, new_fsf_req);
  1066. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1067. }
  1068. break;
  1069. case FSF_FCP_COMMAND_DOES_NOT_EXIST:
  1070. retval = 0;
  1071. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTNOTNEEDED;
  1072. break;
  1073. case FSF_PORT_BOXED:
  1074. ZFCP_LOG_INFO("Remote port 0x%016Lx on adapter %s needs to "
  1075. "be reopened\n", unit->port->wwpn,
  1076. zfcp_get_busid_by_unit(unit));
  1077. zfcp_erp_port_boxed(unit->port, 47, new_fsf_req);
  1078. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1079. | ZFCP_STATUS_FSFREQ_RETRY;
  1080. break;
  1081. case FSF_LUN_BOXED:
  1082. ZFCP_LOG_INFO(
  1083. "unit 0x%016Lx on port 0x%016Lx on adapter %s needs "
  1084. "to be reopened\n",
  1085. unit->fcp_lun, unit->port->wwpn,
  1086. zfcp_get_busid_by_unit(unit));
  1087. zfcp_erp_unit_boxed(unit, 48, new_fsf_req);
  1088. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1089. | ZFCP_STATUS_FSFREQ_RETRY;
  1090. break;
  1091. case FSF_ADAPTER_STATUS_AVAILABLE:
  1092. switch (new_fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  1093. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1094. zfcp_test_link(unit->port);
  1095. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1096. break;
  1097. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1098. /* SCSI stack will escalate */
  1099. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1100. break;
  1101. default:
  1102. ZFCP_LOG_NORMAL
  1103. ("bug: Wrong status qualifier 0x%x arrived.\n",
  1104. new_fsf_req->qtcb->header.fsf_status_qual.word[0]);
  1105. break;
  1106. }
  1107. break;
  1108. case FSF_GOOD:
  1109. retval = 0;
  1110. new_fsf_req->status |= ZFCP_STATUS_FSFREQ_ABORTSUCCEEDED;
  1111. break;
  1112. default:
  1113. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  1114. "(debug info 0x%x)\n",
  1115. new_fsf_req->qtcb->header.fsf_status);
  1116. break;
  1117. }
  1118. skip_fsfstatus:
  1119. return retval;
  1120. }
  1121. /**
  1122. * zfcp_use_one_sbal - checks whether req buffer and resp bother each fit into
  1123. * one SBALE
  1124. * Two scatter-gather lists are passed, one for the reqeust and one for the
  1125. * response.
  1126. */
  1127. static inline int
  1128. zfcp_use_one_sbal(struct scatterlist *req, int req_count,
  1129. struct scatterlist *resp, int resp_count)
  1130. {
  1131. return ((req_count == 1) &&
  1132. (resp_count == 1) &&
  1133. (((unsigned long) zfcp_sg_to_address(&req[0]) &
  1134. PAGE_MASK) ==
  1135. ((unsigned long) (zfcp_sg_to_address(&req[0]) +
  1136. req[0].length - 1) & PAGE_MASK)) &&
  1137. (((unsigned long) zfcp_sg_to_address(&resp[0]) &
  1138. PAGE_MASK) ==
  1139. ((unsigned long) (zfcp_sg_to_address(&resp[0]) +
  1140. resp[0].length - 1) & PAGE_MASK)));
  1141. }
  1142. /**
  1143. * zfcp_fsf_send_ct - initiate a Generic Service request (FC-GS)
  1144. * @ct: pointer to struct zfcp_send_ct which conatins all needed data for
  1145. * the request
  1146. * @pool: pointer to memory pool, if non-null this pool is used to allocate
  1147. * a struct zfcp_fsf_req
  1148. * @erp_action: pointer to erp_action, if non-null the Generic Service request
  1149. * is sent within error recovery
  1150. */
  1151. int
  1152. zfcp_fsf_send_ct(struct zfcp_send_ct *ct, mempool_t *pool,
  1153. struct zfcp_erp_action *erp_action)
  1154. {
  1155. volatile struct qdio_buffer_element *sbale;
  1156. struct zfcp_port *port;
  1157. struct zfcp_adapter *adapter;
  1158. struct zfcp_fsf_req *fsf_req;
  1159. unsigned long lock_flags;
  1160. int bytes;
  1161. int ret = 0;
  1162. port = ct->port;
  1163. adapter = port->adapter;
  1164. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_GENERIC,
  1165. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  1166. pool, &lock_flags, &fsf_req);
  1167. if (ret < 0) {
  1168. ZFCP_LOG_INFO("error: Could not create CT request (FC-GS) for "
  1169. "adapter: %s\n",
  1170. zfcp_get_busid_by_adapter(adapter));
  1171. goto failed_req;
  1172. }
  1173. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1174. if (zfcp_use_one_sbal(ct->req, ct->req_count,
  1175. ct->resp, ct->resp_count)){
  1176. /* both request buffer and response buffer
  1177. fit into one sbale each */
  1178. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  1179. sbale[2].addr = zfcp_sg_to_address(&ct->req[0]);
  1180. sbale[2].length = ct->req[0].length;
  1181. sbale[3].addr = zfcp_sg_to_address(&ct->resp[0]);
  1182. sbale[3].length = ct->resp[0].length;
  1183. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  1184. } else if (adapter->adapter_features &
  1185. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  1186. /* try to use chained SBALs */
  1187. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1188. SBAL_FLAGS0_TYPE_WRITE_READ,
  1189. ct->req, ct->req_count,
  1190. ZFCP_MAX_SBALS_PER_CT_REQ);
  1191. if (bytes <= 0) {
  1192. ZFCP_LOG_INFO("error: creation of CT request failed "
  1193. "on adapter %s\n",
  1194. zfcp_get_busid_by_adapter(adapter));
  1195. if (bytes == 0)
  1196. ret = -ENOMEM;
  1197. else
  1198. ret = bytes;
  1199. goto failed_send;
  1200. }
  1201. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1202. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1203. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1204. SBAL_FLAGS0_TYPE_WRITE_READ,
  1205. ct->resp, ct->resp_count,
  1206. ZFCP_MAX_SBALS_PER_CT_REQ);
  1207. if (bytes <= 0) {
  1208. ZFCP_LOG_INFO("error: creation of CT request failed "
  1209. "on adapter %s\n",
  1210. zfcp_get_busid_by_adapter(adapter));
  1211. if (bytes == 0)
  1212. ret = -ENOMEM;
  1213. else
  1214. ret = bytes;
  1215. goto failed_send;
  1216. }
  1217. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1218. } else {
  1219. /* reject send generic request */
  1220. ZFCP_LOG_INFO(
  1221. "error: microcode does not support chained SBALs,"
  1222. "CT request too big (adapter %s)\n",
  1223. zfcp_get_busid_by_adapter(adapter));
  1224. ret = -EOPNOTSUPP;
  1225. goto failed_send;
  1226. }
  1227. /* settings in QTCB */
  1228. fsf_req->qtcb->header.port_handle = port->handle;
  1229. fsf_req->qtcb->bottom.support.service_class =
  1230. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1231. fsf_req->qtcb->bottom.support.timeout = ct->timeout;
  1232. fsf_req->data = (unsigned long) ct;
  1233. zfcp_san_dbf_event_ct_request(fsf_req);
  1234. if (erp_action) {
  1235. erp_action->fsf_req = fsf_req;
  1236. fsf_req->erp_action = erp_action;
  1237. zfcp_erp_start_timer(fsf_req);
  1238. } else
  1239. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1240. ret = zfcp_fsf_req_send(fsf_req);
  1241. if (ret) {
  1242. ZFCP_LOG_DEBUG("error: initiation of CT request failed "
  1243. "(adapter %s, port 0x%016Lx)\n",
  1244. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  1245. goto failed_send;
  1246. }
  1247. ZFCP_LOG_DEBUG("CT request initiated (adapter %s, port 0x%016Lx)\n",
  1248. zfcp_get_busid_by_adapter(adapter), port->wwpn);
  1249. goto out;
  1250. failed_send:
  1251. zfcp_fsf_req_free(fsf_req);
  1252. if (erp_action != NULL) {
  1253. erp_action->fsf_req = NULL;
  1254. }
  1255. failed_req:
  1256. out:
  1257. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1258. lock_flags);
  1259. return ret;
  1260. }
  1261. /**
  1262. * zfcp_fsf_send_ct_handler - handler for Generic Service requests
  1263. * @fsf_req: pointer to struct zfcp_fsf_req
  1264. *
  1265. * Data specific for the Generic Service request is passed using
  1266. * fsf_req->data. There we find the pointer to struct zfcp_send_ct.
  1267. * Usually a specific handler for the CT request is called which is
  1268. * found in this structure.
  1269. */
  1270. static int
  1271. zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
  1272. {
  1273. struct zfcp_port *port;
  1274. struct zfcp_adapter *adapter;
  1275. struct zfcp_send_ct *send_ct;
  1276. struct fsf_qtcb_header *header;
  1277. struct fsf_qtcb_bottom_support *bottom;
  1278. int retval = -EINVAL;
  1279. u16 subtable, rule, counter;
  1280. adapter = fsf_req->adapter;
  1281. send_ct = (struct zfcp_send_ct *) fsf_req->data;
  1282. port = send_ct->port;
  1283. header = &fsf_req->qtcb->header;
  1284. bottom = &fsf_req->qtcb->bottom.support;
  1285. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1286. goto skip_fsfstatus;
  1287. /* evaluate FSF status in QTCB */
  1288. switch (header->fsf_status) {
  1289. case FSF_GOOD:
  1290. zfcp_san_dbf_event_ct_response(fsf_req);
  1291. retval = 0;
  1292. break;
  1293. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1294. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  1295. "class %d.\n",
  1296. zfcp_get_busid_by_port(port),
  1297. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  1298. /* stop operation for this adapter */
  1299. zfcp_erp_adapter_shutdown(adapter, 0, 123, fsf_req);
  1300. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1301. break;
  1302. case FSF_ADAPTER_STATUS_AVAILABLE:
  1303. switch (header->fsf_status_qual.word[0]){
  1304. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1305. /* reopening link to port */
  1306. zfcp_test_link(port);
  1307. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1308. break;
  1309. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1310. /* ERP strategy will escalate */
  1311. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1312. break;
  1313. default:
  1314. ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x "
  1315. "arrived.\n",
  1316. header->fsf_status_qual.word[0]);
  1317. break;
  1318. }
  1319. break;
  1320. case FSF_ACCESS_DENIED:
  1321. ZFCP_LOG_NORMAL("access denied, cannot send generic service "
  1322. "command (adapter %s, port d_id=0x%06x)\n",
  1323. zfcp_get_busid_by_port(port), port->d_id);
  1324. for (counter = 0; counter < 2; counter++) {
  1325. subtable = header->fsf_status_qual.halfword[counter * 2];
  1326. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  1327. switch (subtable) {
  1328. case FSF_SQ_CFDC_SUBTABLE_OS:
  1329. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  1330. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  1331. case FSF_SQ_CFDC_SUBTABLE_LUN:
  1332. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  1333. zfcp_act_subtable_type[subtable], rule);
  1334. break;
  1335. }
  1336. }
  1337. zfcp_erp_port_access_denied(port, 55, fsf_req);
  1338. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1339. break;
  1340. case FSF_GENERIC_COMMAND_REJECTED:
  1341. ZFCP_LOG_INFO("generic service command rejected "
  1342. "(adapter %s, port d_id=0x%06x)\n",
  1343. zfcp_get_busid_by_port(port), port->d_id);
  1344. ZFCP_LOG_INFO("status qualifier:\n");
  1345. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1346. (char *) &header->fsf_status_qual,
  1347. sizeof (union fsf_status_qual));
  1348. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1349. break;
  1350. case FSF_PORT_HANDLE_NOT_VALID:
  1351. ZFCP_LOG_DEBUG("Temporary port identifier 0x%x for port "
  1352. "0x%016Lx on adapter %s invalid. This may "
  1353. "happen occasionally.\n", port->handle,
  1354. port->wwpn, zfcp_get_busid_by_port(port));
  1355. ZFCP_LOG_INFO("status qualifier:\n");
  1356. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1357. (char *) &header->fsf_status_qual,
  1358. sizeof (union fsf_status_qual));
  1359. zfcp_erp_adapter_reopen(adapter, 0, 106, fsf_req);
  1360. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1361. break;
  1362. case FSF_PORT_BOXED:
  1363. ZFCP_LOG_INFO("port needs to be reopened "
  1364. "(adapter %s, port d_id=0x%06x)\n",
  1365. zfcp_get_busid_by_port(port), port->d_id);
  1366. zfcp_erp_port_boxed(port, 49, fsf_req);
  1367. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  1368. | ZFCP_STATUS_FSFREQ_RETRY;
  1369. break;
  1370. /* following states should never occure, all cases avoided
  1371. in zfcp_fsf_send_ct - but who knows ... */
  1372. case FSF_PAYLOAD_SIZE_MISMATCH:
  1373. ZFCP_LOG_INFO("payload size mismatch (adapter: %s, "
  1374. "req_buf_length=%d, resp_buf_length=%d)\n",
  1375. zfcp_get_busid_by_adapter(adapter),
  1376. bottom->req_buf_length, bottom->resp_buf_length);
  1377. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1378. break;
  1379. case FSF_REQUEST_SIZE_TOO_LARGE:
  1380. ZFCP_LOG_INFO("request size too large (adapter: %s, "
  1381. "req_buf_length=%d)\n",
  1382. zfcp_get_busid_by_adapter(adapter),
  1383. bottom->req_buf_length);
  1384. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1385. break;
  1386. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1387. ZFCP_LOG_INFO("response size too large (adapter: %s, "
  1388. "resp_buf_length=%d)\n",
  1389. zfcp_get_busid_by_adapter(adapter),
  1390. bottom->resp_buf_length);
  1391. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1392. break;
  1393. case FSF_SBAL_MISMATCH:
  1394. ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
  1395. "resp_buf_length=%d)\n",
  1396. zfcp_get_busid_by_adapter(adapter),
  1397. bottom->req_buf_length, bottom->resp_buf_length);
  1398. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1399. break;
  1400. default:
  1401. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  1402. "(debug info 0x%x)\n", header->fsf_status);
  1403. break;
  1404. }
  1405. skip_fsfstatus:
  1406. send_ct->status = retval;
  1407. if (send_ct->handler != NULL)
  1408. send_ct->handler(send_ct->handler_data);
  1409. return retval;
  1410. }
  1411. /**
  1412. * zfcp_fsf_send_els - initiate an ELS command (FC-FS)
  1413. * @els: pointer to struct zfcp_send_els which contains all needed data for
  1414. * the command.
  1415. */
  1416. int
  1417. zfcp_fsf_send_els(struct zfcp_send_els *els)
  1418. {
  1419. volatile struct qdio_buffer_element *sbale;
  1420. struct zfcp_fsf_req *fsf_req;
  1421. u32 d_id;
  1422. struct zfcp_adapter *adapter;
  1423. unsigned long lock_flags;
  1424. int bytes;
  1425. int ret = 0;
  1426. d_id = els->d_id;
  1427. adapter = els->adapter;
  1428. ret = zfcp_fsf_req_create(adapter, FSF_QTCB_SEND_ELS,
  1429. ZFCP_REQ_AUTO_CLEANUP,
  1430. NULL, &lock_flags, &fsf_req);
  1431. if (ret < 0) {
  1432. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1433. "(adapter %s, port d_id: 0x%06x)\n",
  1434. zfcp_get_busid_by_adapter(adapter), d_id);
  1435. goto failed_req;
  1436. }
  1437. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  1438. &els->port->status))) {
  1439. ret = -EBUSY;
  1440. goto port_blocked;
  1441. }
  1442. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1443. if (zfcp_use_one_sbal(els->req, els->req_count,
  1444. els->resp, els->resp_count)){
  1445. /* both request buffer and response buffer
  1446. fit into one sbale each */
  1447. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE_READ;
  1448. sbale[2].addr = zfcp_sg_to_address(&els->req[0]);
  1449. sbale[2].length = els->req[0].length;
  1450. sbale[3].addr = zfcp_sg_to_address(&els->resp[0]);
  1451. sbale[3].length = els->resp[0].length;
  1452. sbale[3].flags |= SBAL_FLAGS_LAST_ENTRY;
  1453. } else if (adapter->adapter_features &
  1454. FSF_FEATURE_ELS_CT_CHAINED_SBALS) {
  1455. /* try to use chained SBALs */
  1456. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1457. SBAL_FLAGS0_TYPE_WRITE_READ,
  1458. els->req, els->req_count,
  1459. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1460. if (bytes <= 0) {
  1461. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1462. "(adapter %s, port d_id: 0x%06x)\n",
  1463. zfcp_get_busid_by_adapter(adapter), d_id);
  1464. if (bytes == 0) {
  1465. ret = -ENOMEM;
  1466. } else {
  1467. ret = bytes;
  1468. }
  1469. goto failed_send;
  1470. }
  1471. fsf_req->qtcb->bottom.support.req_buf_length = bytes;
  1472. fsf_req->sbale_curr = ZFCP_LAST_SBALE_PER_SBAL;
  1473. bytes = zfcp_qdio_sbals_from_sg(fsf_req,
  1474. SBAL_FLAGS0_TYPE_WRITE_READ,
  1475. els->resp, els->resp_count,
  1476. ZFCP_MAX_SBALS_PER_ELS_REQ);
  1477. if (bytes <= 0) {
  1478. ZFCP_LOG_INFO("error: creation of ELS request failed "
  1479. "(adapter %s, port d_id: 0x%06x)\n",
  1480. zfcp_get_busid_by_adapter(adapter), d_id);
  1481. if (bytes == 0) {
  1482. ret = -ENOMEM;
  1483. } else {
  1484. ret = bytes;
  1485. }
  1486. goto failed_send;
  1487. }
  1488. fsf_req->qtcb->bottom.support.resp_buf_length = bytes;
  1489. } else {
  1490. /* reject request */
  1491. ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
  1492. ", ELS request too big (adapter %s, "
  1493. "port d_id: 0x%06x)\n",
  1494. zfcp_get_busid_by_adapter(adapter), d_id);
  1495. ret = -EOPNOTSUPP;
  1496. goto failed_send;
  1497. }
  1498. /* settings in QTCB */
  1499. fsf_req->qtcb->bottom.support.d_id = d_id;
  1500. fsf_req->qtcb->bottom.support.service_class =
  1501. ZFCP_FC_SERVICE_CLASS_DEFAULT;
  1502. fsf_req->qtcb->bottom.support.timeout = ZFCP_ELS_TIMEOUT;
  1503. fsf_req->data = (unsigned long) els;
  1504. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1505. zfcp_san_dbf_event_els_request(fsf_req);
  1506. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1507. ret = zfcp_fsf_req_send(fsf_req);
  1508. if (ret) {
  1509. ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
  1510. "(adapter %s, port d_id: 0x%06x)\n",
  1511. zfcp_get_busid_by_adapter(adapter), d_id);
  1512. goto failed_send;
  1513. }
  1514. ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
  1515. "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
  1516. goto out;
  1517. port_blocked:
  1518. failed_send:
  1519. zfcp_fsf_req_free(fsf_req);
  1520. failed_req:
  1521. out:
  1522. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1523. lock_flags);
  1524. return ret;
  1525. }
  1526. /**
  1527. * zfcp_fsf_send_els_handler - handler for ELS commands
  1528. * @fsf_req: pointer to struct zfcp_fsf_req
  1529. *
  1530. * Data specific for the ELS command is passed using
  1531. * fsf_req->data. There we find the pointer to struct zfcp_send_els.
  1532. * Usually a specific handler for the ELS command is called which is
  1533. * found in this structure.
  1534. */
  1535. static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
  1536. {
  1537. struct zfcp_adapter *adapter;
  1538. struct zfcp_port *port;
  1539. u32 d_id;
  1540. struct fsf_qtcb_header *header;
  1541. struct fsf_qtcb_bottom_support *bottom;
  1542. struct zfcp_send_els *send_els;
  1543. int retval = -EINVAL;
  1544. u16 subtable, rule, counter;
  1545. send_els = (struct zfcp_send_els *) fsf_req->data;
  1546. adapter = send_els->adapter;
  1547. port = send_els->port;
  1548. d_id = send_els->d_id;
  1549. header = &fsf_req->qtcb->header;
  1550. bottom = &fsf_req->qtcb->bottom.support;
  1551. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1552. goto skip_fsfstatus;
  1553. switch (header->fsf_status) {
  1554. case FSF_GOOD:
  1555. zfcp_san_dbf_event_els_response(fsf_req);
  1556. retval = 0;
  1557. break;
  1558. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  1559. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  1560. "class %d.\n",
  1561. zfcp_get_busid_by_adapter(adapter),
  1562. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  1563. /* stop operation for this adapter */
  1564. zfcp_erp_adapter_shutdown(adapter, 0, 124, fsf_req);
  1565. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1566. break;
  1567. case FSF_ADAPTER_STATUS_AVAILABLE:
  1568. switch (header->fsf_status_qual.word[0]){
  1569. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  1570. if (port && (send_els->ls_code != ZFCP_LS_ADISC))
  1571. zfcp_test_link(port);
  1572. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1573. break;
  1574. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  1575. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1576. retval =
  1577. zfcp_handle_els_rjt(header->fsf_status_qual.word[1],
  1578. (struct zfcp_ls_rjt_par *)
  1579. &header->fsf_status_qual.word[2]);
  1580. break;
  1581. case FSF_SQ_RETRY_IF_POSSIBLE:
  1582. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1583. break;
  1584. default:
  1585. ZFCP_LOG_INFO("bug: Wrong status qualifier 0x%x\n",
  1586. header->fsf_status_qual.word[0]);
  1587. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
  1588. (char*)header->fsf_status_qual.word, 16);
  1589. }
  1590. break;
  1591. case FSF_ELS_COMMAND_REJECTED:
  1592. ZFCP_LOG_INFO("ELS has been rejected because command filter "
  1593. "prohibited sending "
  1594. "(adapter: %s, port d_id: 0x%06x)\n",
  1595. zfcp_get_busid_by_adapter(adapter), d_id);
  1596. break;
  1597. case FSF_PAYLOAD_SIZE_MISMATCH:
  1598. ZFCP_LOG_INFO(
  1599. "ELS request size and ELS response size must be either "
  1600. "both 0, or both greater than 0 "
  1601. "(adapter: %s, req_buf_length=%d resp_buf_length=%d)\n",
  1602. zfcp_get_busid_by_adapter(adapter),
  1603. bottom->req_buf_length,
  1604. bottom->resp_buf_length);
  1605. break;
  1606. case FSF_REQUEST_SIZE_TOO_LARGE:
  1607. ZFCP_LOG_INFO(
  1608. "Length of the ELS request buffer, "
  1609. "specified in QTCB bottom, "
  1610. "exceeds the size of the buffers "
  1611. "that have been allocated for ELS request data "
  1612. "(adapter: %s, req_buf_length=%d)\n",
  1613. zfcp_get_busid_by_adapter(adapter),
  1614. bottom->req_buf_length);
  1615. break;
  1616. case FSF_RESPONSE_SIZE_TOO_LARGE:
  1617. ZFCP_LOG_INFO(
  1618. "Length of the ELS response buffer, "
  1619. "specified in QTCB bottom, "
  1620. "exceeds the size of the buffers "
  1621. "that have been allocated for ELS response data "
  1622. "(adapter: %s, resp_buf_length=%d)\n",
  1623. zfcp_get_busid_by_adapter(adapter),
  1624. bottom->resp_buf_length);
  1625. break;
  1626. case FSF_SBAL_MISMATCH:
  1627. /* should never occure, avoided in zfcp_fsf_send_els */
  1628. ZFCP_LOG_INFO("SBAL mismatch (adapter: %s, req_buf_length=%d, "
  1629. "resp_buf_length=%d)\n",
  1630. zfcp_get_busid_by_adapter(adapter),
  1631. bottom->req_buf_length, bottom->resp_buf_length);
  1632. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1633. break;
  1634. case FSF_ACCESS_DENIED:
  1635. ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
  1636. "(adapter %s, port d_id=0x%06x)\n",
  1637. zfcp_get_busid_by_adapter(adapter), d_id);
  1638. for (counter = 0; counter < 2; counter++) {
  1639. subtable = header->fsf_status_qual.halfword[counter * 2];
  1640. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  1641. switch (subtable) {
  1642. case FSF_SQ_CFDC_SUBTABLE_OS:
  1643. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  1644. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  1645. case FSF_SQ_CFDC_SUBTABLE_LUN:
  1646. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  1647. zfcp_act_subtable_type[subtable], rule);
  1648. break;
  1649. }
  1650. }
  1651. if (port != NULL)
  1652. zfcp_erp_port_access_denied(port, 56, fsf_req);
  1653. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1654. break;
  1655. default:
  1656. ZFCP_LOG_NORMAL(
  1657. "bug: An unknown FSF Status was presented "
  1658. "(adapter: %s, fsf_status=0x%08x)\n",
  1659. zfcp_get_busid_by_adapter(adapter),
  1660. header->fsf_status);
  1661. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  1662. break;
  1663. }
  1664. skip_fsfstatus:
  1665. send_els->status = retval;
  1666. if (send_els->handler)
  1667. send_els->handler(send_els->handler_data);
  1668. return retval;
  1669. }
  1670. int
  1671. zfcp_fsf_exchange_config_data(struct zfcp_erp_action *erp_action)
  1672. {
  1673. volatile struct qdio_buffer_element *sbale;
  1674. struct zfcp_fsf_req *fsf_req;
  1675. struct zfcp_adapter *adapter = erp_action->adapter;
  1676. unsigned long lock_flags;
  1677. int retval;
  1678. /* setup new FSF request */
  1679. retval = zfcp_fsf_req_create(adapter,
  1680. FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1681. ZFCP_REQ_AUTO_CLEANUP,
  1682. adapter->pool.fsf_req_erp,
  1683. &lock_flags, &fsf_req);
  1684. if (retval) {
  1685. ZFCP_LOG_INFO("error: Could not create exchange configuration "
  1686. "data request for adapter %s.\n",
  1687. zfcp_get_busid_by_adapter(adapter));
  1688. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1689. lock_flags);
  1690. return retval;
  1691. }
  1692. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1693. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1694. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1695. fsf_req->qtcb->bottom.config.feature_selection =
  1696. FSF_FEATURE_CFDC |
  1697. FSF_FEATURE_LUN_SHARING |
  1698. FSF_FEATURE_NOTIFICATION_LOST |
  1699. FSF_FEATURE_UPDATE_ALERT;
  1700. fsf_req->erp_action = erp_action;
  1701. erp_action->fsf_req = fsf_req;
  1702. zfcp_erp_start_timer(fsf_req);
  1703. retval = zfcp_fsf_req_send(fsf_req);
  1704. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1705. lock_flags);
  1706. if (retval) {
  1707. ZFCP_LOG_INFO("error: Could not send exchange configuration "
  1708. "data command on the adapter %s\n",
  1709. zfcp_get_busid_by_adapter(adapter));
  1710. zfcp_fsf_req_free(fsf_req);
  1711. erp_action->fsf_req = NULL;
  1712. }
  1713. else
  1714. ZFCP_LOG_DEBUG("exchange configuration data request initiated "
  1715. "(adapter %s)\n",
  1716. zfcp_get_busid_by_adapter(adapter));
  1717. return retval;
  1718. }
  1719. int
  1720. zfcp_fsf_exchange_config_data_sync(struct zfcp_adapter *adapter,
  1721. struct fsf_qtcb_bottom_config *data)
  1722. {
  1723. volatile struct qdio_buffer_element *sbale;
  1724. struct zfcp_fsf_req *fsf_req;
  1725. unsigned long lock_flags;
  1726. int retval;
  1727. /* setup new FSF request */
  1728. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_CONFIG_DATA,
  1729. ZFCP_WAIT_FOR_SBAL, NULL, &lock_flags,
  1730. &fsf_req);
  1731. if (retval) {
  1732. ZFCP_LOG_INFO("error: Could not create exchange configuration "
  1733. "data request for adapter %s.\n",
  1734. zfcp_get_busid_by_adapter(adapter));
  1735. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1736. lock_flags);
  1737. return retval;
  1738. }
  1739. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1740. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1741. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1742. fsf_req->qtcb->bottom.config.feature_selection =
  1743. FSF_FEATURE_CFDC |
  1744. FSF_FEATURE_LUN_SHARING |
  1745. FSF_FEATURE_NOTIFICATION_LOST |
  1746. FSF_FEATURE_UPDATE_ALERT;
  1747. if (data)
  1748. fsf_req->data = (unsigned long) data;
  1749. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  1750. retval = zfcp_fsf_req_send(fsf_req);
  1751. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1752. lock_flags);
  1753. if (retval)
  1754. ZFCP_LOG_INFO("error: Could not send exchange configuration "
  1755. "data command on the adapter %s\n",
  1756. zfcp_get_busid_by_adapter(adapter));
  1757. else
  1758. wait_event(fsf_req->completion_wq,
  1759. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  1760. zfcp_fsf_req_free(fsf_req);
  1761. return retval;
  1762. }
  1763. /**
  1764. * zfcp_fsf_exchange_config_evaluate
  1765. * @fsf_req: fsf_req which belongs to xchg config data request
  1766. * @xchg_ok: specifies if xchg config data was incomplete or complete (0/1)
  1767. *
  1768. * returns: -EIO on error, 0 otherwise
  1769. */
  1770. static int
  1771. zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  1772. {
  1773. struct fsf_qtcb_bottom_config *bottom;
  1774. struct zfcp_adapter *adapter = fsf_req->adapter;
  1775. struct Scsi_Host *shost = adapter->scsi_host;
  1776. bottom = &fsf_req->qtcb->bottom.config;
  1777. ZFCP_LOG_DEBUG("low/high QTCB version 0x%x/0x%x of FSF\n",
  1778. bottom->low_qtcb_version, bottom->high_qtcb_version);
  1779. adapter->fsf_lic_version = bottom->lic_version;
  1780. adapter->adapter_features = bottom->adapter_features;
  1781. adapter->connection_features = bottom->connection_features;
  1782. adapter->peer_wwpn = 0;
  1783. adapter->peer_wwnn = 0;
  1784. adapter->peer_d_id = 0;
  1785. if (xchg_ok) {
  1786. if (fsf_req->data)
  1787. memcpy((struct fsf_qtcb_bottom_config *) fsf_req->data,
  1788. bottom, sizeof (struct fsf_qtcb_bottom_config));
  1789. fc_host_node_name(shost) = bottom->nport_serv_param.wwnn;
  1790. fc_host_port_name(shost) = bottom->nport_serv_param.wwpn;
  1791. fc_host_port_id(shost) = bottom->s_id & ZFCP_DID_MASK;
  1792. fc_host_speed(shost) = bottom->fc_link_speed;
  1793. fc_host_supported_classes(shost) =
  1794. FC_COS_CLASS2 | FC_COS_CLASS3;
  1795. adapter->hydra_version = bottom->adapter_type;
  1796. adapter->timer_ticks = bottom->timer_interval;
  1797. if (fc_host_permanent_port_name(shost) == -1)
  1798. fc_host_permanent_port_name(shost) =
  1799. fc_host_port_name(shost);
  1800. if (bottom->fc_topology == FSF_TOPO_P2P) {
  1801. adapter->peer_d_id = bottom->peer_d_id & ZFCP_DID_MASK;
  1802. adapter->peer_wwpn = bottom->plogi_payload.wwpn;
  1803. adapter->peer_wwnn = bottom->plogi_payload.wwnn;
  1804. fc_host_port_type(shost) = FC_PORTTYPE_PTP;
  1805. } else if (bottom->fc_topology == FSF_TOPO_FABRIC)
  1806. fc_host_port_type(shost) = FC_PORTTYPE_NPORT;
  1807. else if (bottom->fc_topology == FSF_TOPO_AL)
  1808. fc_host_port_type(shost) = FC_PORTTYPE_NLPORT;
  1809. else
  1810. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1811. } else {
  1812. fc_host_node_name(shost) = 0;
  1813. fc_host_port_name(shost) = 0;
  1814. fc_host_port_id(shost) = 0;
  1815. fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
  1816. fc_host_port_type(shost) = FC_PORTTYPE_UNKNOWN;
  1817. adapter->hydra_version = 0;
  1818. }
  1819. if (adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT) {
  1820. adapter->hardware_version = bottom->hardware_version;
  1821. memcpy(fc_host_serial_number(shost), bottom->serial_number,
  1822. min(FC_SERIAL_NUMBER_SIZE, 17));
  1823. EBCASC(fc_host_serial_number(shost),
  1824. min(FC_SERIAL_NUMBER_SIZE, 17));
  1825. }
  1826. if (fsf_req->erp_action)
  1827. ZFCP_LOG_NORMAL("The adapter %s reported the following "
  1828. "characteristics:\n"
  1829. "WWNN 0x%016Lx, WWPN 0x%016Lx, "
  1830. "S_ID 0x%06x,\n"
  1831. "adapter version 0x%x, "
  1832. "LIC version 0x%x, "
  1833. "FC link speed %d Gb/s\n",
  1834. zfcp_get_busid_by_adapter(adapter),
  1835. (wwn_t) fc_host_node_name(shost),
  1836. (wwn_t) fc_host_port_name(shost),
  1837. fc_host_port_id(shost),
  1838. adapter->hydra_version,
  1839. adapter->fsf_lic_version,
  1840. fc_host_speed(shost));
  1841. if (ZFCP_QTCB_VERSION < bottom->low_qtcb_version) {
  1842. ZFCP_LOG_NORMAL("error: the adapter %s "
  1843. "only supports newer control block "
  1844. "versions in comparison to this device "
  1845. "driver (try updated device driver)\n",
  1846. zfcp_get_busid_by_adapter(adapter));
  1847. zfcp_erp_adapter_shutdown(adapter, 0, 125, fsf_req);
  1848. return -EIO;
  1849. }
  1850. if (ZFCP_QTCB_VERSION > bottom->high_qtcb_version) {
  1851. ZFCP_LOG_NORMAL("error: the adapter %s "
  1852. "only supports older control block "
  1853. "versions than this device driver uses"
  1854. "(consider a microcode upgrade)\n",
  1855. zfcp_get_busid_by_adapter(adapter));
  1856. zfcp_erp_adapter_shutdown(adapter, 0, 126, fsf_req);
  1857. return -EIO;
  1858. }
  1859. return 0;
  1860. }
  1861. /**
  1862. * function: zfcp_fsf_exchange_config_data_handler
  1863. *
  1864. * purpose: is called for finished Exchange Configuration Data command
  1865. *
  1866. * returns:
  1867. */
  1868. static int
  1869. zfcp_fsf_exchange_config_data_handler(struct zfcp_fsf_req *fsf_req)
  1870. {
  1871. struct fsf_qtcb_bottom_config *bottom;
  1872. struct zfcp_adapter *adapter = fsf_req->adapter;
  1873. struct fsf_qtcb *qtcb = fsf_req->qtcb;
  1874. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  1875. return -EIO;
  1876. switch (qtcb->header.fsf_status) {
  1877. case FSF_GOOD:
  1878. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 1))
  1879. return -EIO;
  1880. switch (fc_host_port_type(adapter->scsi_host)) {
  1881. case FC_PORTTYPE_PTP:
  1882. ZFCP_LOG_NORMAL("Point-to-Point fibrechannel "
  1883. "configuration detected at adapter %s\n"
  1884. "Peer WWNN 0x%016llx, "
  1885. "peer WWPN 0x%016llx, "
  1886. "peer d_id 0x%06x\n",
  1887. zfcp_get_busid_by_adapter(adapter),
  1888. adapter->peer_wwnn,
  1889. adapter->peer_wwpn,
  1890. adapter->peer_d_id);
  1891. break;
  1892. case FC_PORTTYPE_NLPORT:
  1893. ZFCP_LOG_NORMAL("error: Arbitrated loop fibrechannel "
  1894. "topology detected at adapter %s "
  1895. "unsupported, shutting down adapter\n",
  1896. zfcp_get_busid_by_adapter(adapter));
  1897. zfcp_erp_adapter_shutdown(adapter, 0, 127, fsf_req);
  1898. return -EIO;
  1899. case FC_PORTTYPE_NPORT:
  1900. if (fsf_req->erp_action)
  1901. ZFCP_LOG_NORMAL("Switched fabric fibrechannel "
  1902. "network detected at adapter "
  1903. "%s.\n",
  1904. zfcp_get_busid_by_adapter(adapter));
  1905. break;
  1906. default:
  1907. ZFCP_LOG_NORMAL("bug: The fibrechannel topology "
  1908. "reported by the exchange "
  1909. "configuration command for "
  1910. "the adapter %s is not "
  1911. "of a type known to the zfcp "
  1912. "driver, shutting down adapter\n",
  1913. zfcp_get_busid_by_adapter(adapter));
  1914. zfcp_erp_adapter_shutdown(adapter, 0, 128, fsf_req);
  1915. return -EIO;
  1916. }
  1917. bottom = &qtcb->bottom.config;
  1918. if (bottom->max_qtcb_size < sizeof(struct fsf_qtcb)) {
  1919. ZFCP_LOG_NORMAL("bug: Maximum QTCB size (%d bytes) "
  1920. "allowed by the adapter %s "
  1921. "is lower than the minimum "
  1922. "required by the driver (%ld bytes).\n",
  1923. bottom->max_qtcb_size,
  1924. zfcp_get_busid_by_adapter(adapter),
  1925. sizeof(struct fsf_qtcb));
  1926. zfcp_erp_adapter_shutdown(adapter, 0, 129, fsf_req);
  1927. return -EIO;
  1928. }
  1929. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1930. &adapter->status);
  1931. break;
  1932. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  1933. if (zfcp_fsf_exchange_config_evaluate(fsf_req, 0))
  1934. return -EIO;
  1935. atomic_set_mask(ZFCP_STATUS_ADAPTER_XCONFIG_OK,
  1936. &adapter->status);
  1937. zfcp_fsf_link_down_info_eval(fsf_req, 42,
  1938. &qtcb->header.fsf_status_qual.link_down_info);
  1939. break;
  1940. default:
  1941. zfcp_erp_adapter_shutdown(adapter, 0, 130, fsf_req);
  1942. return -EIO;
  1943. }
  1944. return 0;
  1945. }
  1946. /**
  1947. * zfcp_fsf_exchange_port_data - request information about local port
  1948. * @erp_action: ERP action for the adapter for which port data is requested
  1949. */
  1950. int
  1951. zfcp_fsf_exchange_port_data(struct zfcp_erp_action *erp_action)
  1952. {
  1953. volatile struct qdio_buffer_element *sbale;
  1954. struct zfcp_fsf_req *fsf_req;
  1955. struct zfcp_adapter *adapter = erp_action->adapter;
  1956. unsigned long lock_flags;
  1957. int retval;
  1958. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
  1959. ZFCP_LOG_INFO("error: exchange port data "
  1960. "command not supported by adapter %s\n",
  1961. zfcp_get_busid_by_adapter(adapter));
  1962. return -EOPNOTSUPP;
  1963. }
  1964. /* setup new FSF request */
  1965. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  1966. ZFCP_REQ_AUTO_CLEANUP,
  1967. adapter->pool.fsf_req_erp,
  1968. &lock_flags, &fsf_req);
  1969. if (retval) {
  1970. ZFCP_LOG_INFO("error: Out of resources. Could not create an "
  1971. "exchange port data request for "
  1972. "the adapter %s.\n",
  1973. zfcp_get_busid_by_adapter(adapter));
  1974. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  1975. lock_flags);
  1976. return retval;
  1977. }
  1978. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  1979. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  1980. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  1981. erp_action->fsf_req = fsf_req;
  1982. fsf_req->erp_action = erp_action;
  1983. zfcp_erp_start_timer(fsf_req);
  1984. retval = zfcp_fsf_req_send(fsf_req);
  1985. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  1986. if (retval) {
  1987. ZFCP_LOG_INFO("error: Could not send an exchange port data "
  1988. "command on the adapter %s\n",
  1989. zfcp_get_busid_by_adapter(adapter));
  1990. zfcp_fsf_req_free(fsf_req);
  1991. erp_action->fsf_req = NULL;
  1992. }
  1993. else
  1994. ZFCP_LOG_DEBUG("exchange port data request initiated "
  1995. "(adapter %s)\n",
  1996. zfcp_get_busid_by_adapter(adapter));
  1997. return retval;
  1998. }
  1999. /**
  2000. * zfcp_fsf_exchange_port_data_sync - request information about local port
  2001. * and wait until information is ready
  2002. */
  2003. int
  2004. zfcp_fsf_exchange_port_data_sync(struct zfcp_adapter *adapter,
  2005. struct fsf_qtcb_bottom_port *data)
  2006. {
  2007. volatile struct qdio_buffer_element *sbale;
  2008. struct zfcp_fsf_req *fsf_req;
  2009. unsigned long lock_flags;
  2010. int retval;
  2011. if (!(adapter->adapter_features & FSF_FEATURE_HBAAPI_MANAGEMENT)) {
  2012. ZFCP_LOG_INFO("error: exchange port data "
  2013. "command not supported by adapter %s\n",
  2014. zfcp_get_busid_by_adapter(adapter));
  2015. return -EOPNOTSUPP;
  2016. }
  2017. /* setup new FSF request */
  2018. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_EXCHANGE_PORT_DATA,
  2019. 0, NULL, &lock_flags, &fsf_req);
  2020. if (retval) {
  2021. ZFCP_LOG_INFO("error: Out of resources. Could not create an "
  2022. "exchange port data request for "
  2023. "the adapter %s.\n",
  2024. zfcp_get_busid_by_adapter(adapter));
  2025. write_unlock_irqrestore(&adapter->request_queue.queue_lock,
  2026. lock_flags);
  2027. return retval;
  2028. }
  2029. if (data)
  2030. fsf_req->data = (unsigned long) data;
  2031. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2032. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2033. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2034. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  2035. retval = zfcp_fsf_req_send(fsf_req);
  2036. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  2037. if (retval)
  2038. ZFCP_LOG_INFO("error: Could not send an exchange port data "
  2039. "command on the adapter %s\n",
  2040. zfcp_get_busid_by_adapter(adapter));
  2041. else
  2042. wait_event(fsf_req->completion_wq,
  2043. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  2044. zfcp_fsf_req_free(fsf_req);
  2045. return retval;
  2046. }
  2047. /**
  2048. * zfcp_fsf_exchange_port_evaluate
  2049. * @fsf_req: fsf_req which belongs to xchg port data request
  2050. * @xchg_ok: specifies if xchg port data was incomplete or complete (0/1)
  2051. */
  2052. static void
  2053. zfcp_fsf_exchange_port_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
  2054. {
  2055. struct zfcp_adapter *adapter;
  2056. struct fsf_qtcb_bottom_port *bottom;
  2057. struct Scsi_Host *shost;
  2058. adapter = fsf_req->adapter;
  2059. bottom = &fsf_req->qtcb->bottom.port;
  2060. shost = adapter->scsi_host;
  2061. if (fsf_req->data)
  2062. memcpy((struct fsf_qtcb_bottom_port*) fsf_req->data, bottom,
  2063. sizeof(struct fsf_qtcb_bottom_port));
  2064. if (adapter->connection_features & FSF_FEATURE_NPIV_MODE)
  2065. fc_host_permanent_port_name(shost) = bottom->wwpn;
  2066. else
  2067. fc_host_permanent_port_name(shost) = fc_host_port_name(shost);
  2068. fc_host_maxframe_size(shost) = bottom->maximum_frame_size;
  2069. fc_host_supported_speeds(shost) = bottom->supported_speed;
  2070. }
  2071. /**
  2072. * zfcp_fsf_exchange_port_data_handler - handler for exchange_port_data request
  2073. * @fsf_req: pointer to struct zfcp_fsf_req
  2074. */
  2075. static void
  2076. zfcp_fsf_exchange_port_data_handler(struct zfcp_fsf_req *fsf_req)
  2077. {
  2078. struct zfcp_adapter *adapter;
  2079. struct fsf_qtcb *qtcb;
  2080. adapter = fsf_req->adapter;
  2081. qtcb = fsf_req->qtcb;
  2082. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)
  2083. return;
  2084. switch (qtcb->header.fsf_status) {
  2085. case FSF_GOOD:
  2086. zfcp_fsf_exchange_port_evaluate(fsf_req, 1);
  2087. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2088. break;
  2089. case FSF_EXCHANGE_CONFIG_DATA_INCOMPLETE:
  2090. zfcp_fsf_exchange_port_evaluate(fsf_req, 0);
  2091. atomic_set_mask(ZFCP_STATUS_ADAPTER_XPORT_OK, &adapter->status);
  2092. zfcp_fsf_link_down_info_eval(fsf_req, 43,
  2093. &qtcb->header.fsf_status_qual.link_down_info);
  2094. break;
  2095. }
  2096. }
  2097. /*
  2098. * function: zfcp_fsf_open_port
  2099. *
  2100. * purpose:
  2101. *
  2102. * returns: address of initiated FSF request
  2103. * NULL - request could not be initiated
  2104. */
  2105. int
  2106. zfcp_fsf_open_port(struct zfcp_erp_action *erp_action)
  2107. {
  2108. volatile struct qdio_buffer_element *sbale;
  2109. struct zfcp_fsf_req *fsf_req;
  2110. unsigned long lock_flags;
  2111. int retval = 0;
  2112. /* setup new FSF request */
  2113. retval = zfcp_fsf_req_create(erp_action->adapter,
  2114. FSF_QTCB_OPEN_PORT_WITH_DID,
  2115. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2116. erp_action->adapter->pool.fsf_req_erp,
  2117. &lock_flags, &fsf_req);
  2118. if (retval < 0) {
  2119. ZFCP_LOG_INFO("error: Could not create open port request "
  2120. "for port 0x%016Lx on adapter %s.\n",
  2121. erp_action->port->wwpn,
  2122. zfcp_get_busid_by_adapter(erp_action->adapter));
  2123. goto out;
  2124. }
  2125. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2126. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2127. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2128. fsf_req->qtcb->bottom.support.d_id = erp_action->port->d_id;
  2129. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->port->status);
  2130. fsf_req->data = (unsigned long) erp_action->port;
  2131. fsf_req->erp_action = erp_action;
  2132. erp_action->fsf_req = fsf_req;
  2133. zfcp_erp_start_timer(fsf_req);
  2134. retval = zfcp_fsf_req_send(fsf_req);
  2135. if (retval) {
  2136. ZFCP_LOG_INFO("error: Could not send open port request for "
  2137. "port 0x%016Lx on adapter %s.\n",
  2138. erp_action->port->wwpn,
  2139. zfcp_get_busid_by_adapter(erp_action->adapter));
  2140. zfcp_fsf_req_free(fsf_req);
  2141. erp_action->fsf_req = NULL;
  2142. goto out;
  2143. }
  2144. ZFCP_LOG_DEBUG("open port request initiated "
  2145. "(adapter %s, port 0x%016Lx)\n",
  2146. zfcp_get_busid_by_adapter(erp_action->adapter),
  2147. erp_action->port->wwpn);
  2148. out:
  2149. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2150. lock_flags);
  2151. return retval;
  2152. }
  2153. /*
  2154. * function: zfcp_fsf_open_port_handler
  2155. *
  2156. * purpose: is called for finished Open Port command
  2157. *
  2158. * returns:
  2159. */
  2160. static int
  2161. zfcp_fsf_open_port_handler(struct zfcp_fsf_req *fsf_req)
  2162. {
  2163. int retval = -EINVAL;
  2164. struct zfcp_port *port;
  2165. struct fsf_plogi *plogi;
  2166. struct fsf_qtcb_header *header;
  2167. u16 subtable, rule, counter;
  2168. port = (struct zfcp_port *) fsf_req->data;
  2169. header = &fsf_req->qtcb->header;
  2170. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2171. /* don't change port status in our bookkeeping */
  2172. goto skip_fsfstatus;
  2173. }
  2174. /* evaluate FSF status in QTCB */
  2175. switch (header->fsf_status) {
  2176. case FSF_PORT_ALREADY_OPEN:
  2177. ZFCP_LOG_NORMAL("bug: remote port 0x%016Lx on adapter %s "
  2178. "is already open.\n",
  2179. port->wwpn, zfcp_get_busid_by_port(port));
  2180. /*
  2181. * This is a bug, however operation should continue normally
  2182. * if it is simply ignored
  2183. */
  2184. break;
  2185. case FSF_ACCESS_DENIED:
  2186. ZFCP_LOG_NORMAL("Access denied, cannot open port 0x%016Lx "
  2187. "on adapter %s\n",
  2188. port->wwpn, zfcp_get_busid_by_port(port));
  2189. for (counter = 0; counter < 2; counter++) {
  2190. subtable = header->fsf_status_qual.halfword[counter * 2];
  2191. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2192. switch (subtable) {
  2193. case FSF_SQ_CFDC_SUBTABLE_OS:
  2194. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2195. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2196. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2197. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2198. zfcp_act_subtable_type[subtable], rule);
  2199. break;
  2200. }
  2201. }
  2202. zfcp_erp_port_access_denied(port, 57, fsf_req);
  2203. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2204. break;
  2205. case FSF_MAXIMUM_NUMBER_OF_PORTS_EXCEEDED:
  2206. ZFCP_LOG_INFO("error: The FSF adapter is out of resources. "
  2207. "The remote port 0x%016Lx on adapter %s "
  2208. "could not be opened. Disabling it.\n",
  2209. port->wwpn, zfcp_get_busid_by_port(port));
  2210. zfcp_erp_port_failed(port, 31, fsf_req);
  2211. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2212. break;
  2213. case FSF_ADAPTER_STATUS_AVAILABLE:
  2214. switch (header->fsf_status_qual.word[0]) {
  2215. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2216. /* ERP strategy will escalate */
  2217. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2218. break;
  2219. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2220. /* ERP strategy will escalate */
  2221. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2222. break;
  2223. case FSF_SQ_NO_RETRY_POSSIBLE:
  2224. ZFCP_LOG_NORMAL("The remote port 0x%016Lx on "
  2225. "adapter %s could not be opened. "
  2226. "Disabling it.\n",
  2227. port->wwpn,
  2228. zfcp_get_busid_by_port(port));
  2229. zfcp_erp_port_failed(port, 32, fsf_req);
  2230. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2231. break;
  2232. default:
  2233. ZFCP_LOG_NORMAL
  2234. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2235. header->fsf_status_qual.word[0]);
  2236. break;
  2237. }
  2238. break;
  2239. case FSF_GOOD:
  2240. /* save port handle assigned by FSF */
  2241. port->handle = header->port_handle;
  2242. ZFCP_LOG_INFO("The remote port 0x%016Lx via adapter %s "
  2243. "was opened, it's port handle is 0x%x\n",
  2244. port->wwpn, zfcp_get_busid_by_port(port),
  2245. port->handle);
  2246. /* mark port as open */
  2247. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN |
  2248. ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2249. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2250. ZFCP_STATUS_COMMON_ACCESS_BOXED,
  2251. &port->status);
  2252. retval = 0;
  2253. /* check whether D_ID has changed during open */
  2254. /*
  2255. * FIXME: This check is not airtight, as the FCP channel does
  2256. * not monitor closures of target port connections caused on
  2257. * the remote side. Thus, they might miss out on invalidating
  2258. * locally cached WWPNs (and other N_Port parameters) of gone
  2259. * target ports. So, our heroic attempt to make things safe
  2260. * could be undermined by 'open port' response data tagged with
  2261. * obsolete WWPNs. Another reason to monitor potential
  2262. * connection closures ourself at least (by interpreting
  2263. * incoming ELS' and unsolicited status). It just crosses my
  2264. * mind that one should be able to cross-check by means of
  2265. * another GID_PN straight after a port has been opened.
  2266. * Alternately, an ADISC/PDISC ELS should suffice, as well.
  2267. */
  2268. plogi = (struct fsf_plogi *) fsf_req->qtcb->bottom.support.els;
  2269. if (!atomic_test_mask(ZFCP_STATUS_PORT_NO_WWPN, &port->status))
  2270. {
  2271. if (fsf_req->qtcb->bottom.support.els1_length <
  2272. sizeof (struct fsf_plogi)) {
  2273. ZFCP_LOG_INFO(
  2274. "warning: insufficient length of "
  2275. "PLOGI payload (%i)\n",
  2276. fsf_req->qtcb->bottom.support.els1_length);
  2277. /* skip sanity check and assume wwpn is ok */
  2278. } else {
  2279. if (plogi->serv_param.wwpn != port->wwpn) {
  2280. ZFCP_LOG_INFO("warning: d_id of port "
  2281. "0x%016Lx changed during "
  2282. "open\n", port->wwpn);
  2283. atomic_clear_mask(
  2284. ZFCP_STATUS_PORT_DID_DID,
  2285. &port->status);
  2286. } else {
  2287. port->wwnn = plogi->serv_param.wwnn;
  2288. zfcp_plogi_evaluate(port, plogi);
  2289. }
  2290. }
  2291. }
  2292. break;
  2293. case FSF_UNKNOWN_OP_SUBTYPE:
  2294. /* should never occure, subtype not set in zfcp_fsf_open_port */
  2295. ZFCP_LOG_INFO("unknown operation subtype (adapter: %s, "
  2296. "op_subtype=0x%x)\n",
  2297. zfcp_get_busid_by_port(port),
  2298. fsf_req->qtcb->bottom.support.operation_subtype);
  2299. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2300. break;
  2301. default:
  2302. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2303. "(debug info 0x%x)\n",
  2304. header->fsf_status);
  2305. break;
  2306. }
  2307. skip_fsfstatus:
  2308. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &port->status);
  2309. return retval;
  2310. }
  2311. /*
  2312. * function: zfcp_fsf_close_port
  2313. *
  2314. * purpose: submit FSF command "close port"
  2315. *
  2316. * returns: address of initiated FSF request
  2317. * NULL - request could not be initiated
  2318. */
  2319. int
  2320. zfcp_fsf_close_port(struct zfcp_erp_action *erp_action)
  2321. {
  2322. volatile struct qdio_buffer_element *sbale;
  2323. struct zfcp_fsf_req *fsf_req;
  2324. unsigned long lock_flags;
  2325. int retval = 0;
  2326. /* setup new FSF request */
  2327. retval = zfcp_fsf_req_create(erp_action->adapter,
  2328. FSF_QTCB_CLOSE_PORT,
  2329. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2330. erp_action->adapter->pool.fsf_req_erp,
  2331. &lock_flags, &fsf_req);
  2332. if (retval < 0) {
  2333. ZFCP_LOG_INFO("error: Could not create a close port request "
  2334. "for port 0x%016Lx on adapter %s.\n",
  2335. erp_action->port->wwpn,
  2336. zfcp_get_busid_by_adapter(erp_action->adapter));
  2337. goto out;
  2338. }
  2339. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2340. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2341. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2342. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->port->status);
  2343. fsf_req->data = (unsigned long) erp_action->port;
  2344. fsf_req->erp_action = erp_action;
  2345. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2346. fsf_req->erp_action = erp_action;
  2347. erp_action->fsf_req = fsf_req;
  2348. zfcp_erp_start_timer(fsf_req);
  2349. retval = zfcp_fsf_req_send(fsf_req);
  2350. if (retval) {
  2351. ZFCP_LOG_INFO("error: Could not send a close port request for "
  2352. "port 0x%016Lx on adapter %s.\n",
  2353. erp_action->port->wwpn,
  2354. zfcp_get_busid_by_adapter(erp_action->adapter));
  2355. zfcp_fsf_req_free(fsf_req);
  2356. erp_action->fsf_req = NULL;
  2357. goto out;
  2358. }
  2359. ZFCP_LOG_TRACE("close port request initiated "
  2360. "(adapter %s, port 0x%016Lx)\n",
  2361. zfcp_get_busid_by_adapter(erp_action->adapter),
  2362. erp_action->port->wwpn);
  2363. out:
  2364. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2365. lock_flags);
  2366. return retval;
  2367. }
  2368. /*
  2369. * function: zfcp_fsf_close_port_handler
  2370. *
  2371. * purpose: is called for finished Close Port FSF command
  2372. *
  2373. * returns:
  2374. */
  2375. static int
  2376. zfcp_fsf_close_port_handler(struct zfcp_fsf_req *fsf_req)
  2377. {
  2378. int retval = -EINVAL;
  2379. struct zfcp_port *port;
  2380. port = (struct zfcp_port *) fsf_req->data;
  2381. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2382. /* don't change port status in our bookkeeping */
  2383. goto skip_fsfstatus;
  2384. }
  2385. /* evaluate FSF status in QTCB */
  2386. switch (fsf_req->qtcb->header.fsf_status) {
  2387. case FSF_PORT_HANDLE_NOT_VALID:
  2388. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  2389. "0x%016Lx on adapter %s invalid. This may happen "
  2390. "occasionally.\n", port->handle,
  2391. port->wwpn, zfcp_get_busid_by_port(port));
  2392. ZFCP_LOG_DEBUG("status qualifier:\n");
  2393. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2394. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  2395. sizeof (union fsf_status_qual));
  2396. zfcp_erp_adapter_reopen(port->adapter, 0, 107, fsf_req);
  2397. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2398. break;
  2399. case FSF_ADAPTER_STATUS_AVAILABLE:
  2400. /* Note: FSF has actually closed the port in this case.
  2401. * The status code is just daft. Fingers crossed for a change
  2402. */
  2403. retval = 0;
  2404. break;
  2405. case FSF_GOOD:
  2406. ZFCP_LOG_TRACE("remote port 0x016%Lx on adapter %s closed, "
  2407. "port handle 0x%x\n", port->wwpn,
  2408. zfcp_get_busid_by_port(port), port->handle);
  2409. zfcp_erp_modify_port_status(port, 33, fsf_req,
  2410. ZFCP_STATUS_COMMON_OPEN,
  2411. ZFCP_CLEAR);
  2412. retval = 0;
  2413. break;
  2414. default:
  2415. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2416. "(debug info 0x%x)\n",
  2417. fsf_req->qtcb->header.fsf_status);
  2418. break;
  2419. }
  2420. skip_fsfstatus:
  2421. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &port->status);
  2422. return retval;
  2423. }
  2424. /*
  2425. * function: zfcp_fsf_close_physical_port
  2426. *
  2427. * purpose: submit FSF command "close physical port"
  2428. *
  2429. * returns: address of initiated FSF request
  2430. * NULL - request could not be initiated
  2431. */
  2432. int
  2433. zfcp_fsf_close_physical_port(struct zfcp_erp_action *erp_action)
  2434. {
  2435. volatile struct qdio_buffer_element *sbale;
  2436. struct zfcp_fsf_req *fsf_req;
  2437. unsigned long lock_flags;
  2438. int retval = 0;
  2439. /* setup new FSF request */
  2440. retval = zfcp_fsf_req_create(erp_action->adapter,
  2441. FSF_QTCB_CLOSE_PHYSICAL_PORT,
  2442. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2443. erp_action->adapter->pool.fsf_req_erp,
  2444. &lock_flags, &fsf_req);
  2445. if (retval < 0) {
  2446. ZFCP_LOG_INFO("error: Could not create close physical port "
  2447. "request (adapter %s, port 0x%016Lx)\n",
  2448. zfcp_get_busid_by_adapter(erp_action->adapter),
  2449. erp_action->port->wwpn);
  2450. goto out;
  2451. }
  2452. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2453. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2454. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2455. /* mark port as being closed */
  2456. atomic_set_mask(ZFCP_STATUS_PORT_PHYS_CLOSING,
  2457. &erp_action->port->status);
  2458. /* save a pointer to this port */
  2459. fsf_req->data = (unsigned long) erp_action->port;
  2460. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2461. fsf_req->erp_action = erp_action;
  2462. erp_action->fsf_req = fsf_req;
  2463. zfcp_erp_start_timer(fsf_req);
  2464. retval = zfcp_fsf_req_send(fsf_req);
  2465. if (retval) {
  2466. ZFCP_LOG_INFO("error: Could not send close physical port "
  2467. "request (adapter %s, port 0x%016Lx)\n",
  2468. zfcp_get_busid_by_adapter(erp_action->adapter),
  2469. erp_action->port->wwpn);
  2470. zfcp_fsf_req_free(fsf_req);
  2471. erp_action->fsf_req = NULL;
  2472. goto out;
  2473. }
  2474. ZFCP_LOG_TRACE("close physical port request initiated "
  2475. "(adapter %s, port 0x%016Lx)\n",
  2476. zfcp_get_busid_by_adapter(erp_action->adapter),
  2477. erp_action->port->wwpn);
  2478. out:
  2479. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2480. lock_flags);
  2481. return retval;
  2482. }
  2483. /*
  2484. * function: zfcp_fsf_close_physical_port_handler
  2485. *
  2486. * purpose: is called for finished Close Physical Port FSF command
  2487. *
  2488. * returns:
  2489. */
  2490. static int
  2491. zfcp_fsf_close_physical_port_handler(struct zfcp_fsf_req *fsf_req)
  2492. {
  2493. int retval = -EINVAL;
  2494. struct zfcp_port *port;
  2495. struct zfcp_unit *unit;
  2496. struct fsf_qtcb_header *header;
  2497. u16 subtable, rule, counter;
  2498. port = (struct zfcp_port *) fsf_req->data;
  2499. header = &fsf_req->qtcb->header;
  2500. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2501. /* don't change port status in our bookkeeping */
  2502. goto skip_fsfstatus;
  2503. }
  2504. /* evaluate FSF status in QTCB */
  2505. switch (header->fsf_status) {
  2506. case FSF_PORT_HANDLE_NOT_VALID:
  2507. ZFCP_LOG_INFO("Temporary port identifier 0x%x invalid"
  2508. "(adapter %s, port 0x%016Lx). "
  2509. "This may happen occasionally.\n",
  2510. port->handle,
  2511. zfcp_get_busid_by_port(port),
  2512. port->wwpn);
  2513. ZFCP_LOG_DEBUG("status qualifier:\n");
  2514. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2515. (char *) &header->fsf_status_qual,
  2516. sizeof (union fsf_status_qual));
  2517. zfcp_erp_adapter_reopen(port->adapter, 0, 108, fsf_req);
  2518. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2519. break;
  2520. case FSF_ACCESS_DENIED:
  2521. ZFCP_LOG_NORMAL("Access denied, cannot close "
  2522. "physical port 0x%016Lx on adapter %s\n",
  2523. port->wwpn, zfcp_get_busid_by_port(port));
  2524. for (counter = 0; counter < 2; counter++) {
  2525. subtable = header->fsf_status_qual.halfword[counter * 2];
  2526. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2527. switch (subtable) {
  2528. case FSF_SQ_CFDC_SUBTABLE_OS:
  2529. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2530. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2531. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2532. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2533. zfcp_act_subtable_type[subtable], rule);
  2534. break;
  2535. }
  2536. }
  2537. zfcp_erp_port_access_denied(port, 58, fsf_req);
  2538. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2539. break;
  2540. case FSF_PORT_BOXED:
  2541. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter "
  2542. "%s needs to be reopened but it was attempted "
  2543. "to close it physically.\n",
  2544. port->wwpn,
  2545. zfcp_get_busid_by_port(port));
  2546. zfcp_erp_port_boxed(port, 50, fsf_req);
  2547. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2548. ZFCP_STATUS_FSFREQ_RETRY;
  2549. /* can't use generic zfcp_erp_modify_port_status because
  2550. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port */
  2551. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2552. list_for_each_entry(unit, &port->unit_list_head, list)
  2553. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN,
  2554. &unit->status);
  2555. break;
  2556. case FSF_ADAPTER_STATUS_AVAILABLE:
  2557. switch (header->fsf_status_qual.word[0]) {
  2558. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2559. /* This will now be escalated by ERP */
  2560. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2561. break;
  2562. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2563. /* ERP strategy will escalate */
  2564. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2565. break;
  2566. default:
  2567. ZFCP_LOG_NORMAL
  2568. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2569. header->fsf_status_qual.word[0]);
  2570. break;
  2571. }
  2572. break;
  2573. case FSF_GOOD:
  2574. ZFCP_LOG_DEBUG("Remote port 0x%016Lx via adapter %s "
  2575. "physically closed, port handle 0x%x\n",
  2576. port->wwpn,
  2577. zfcp_get_busid_by_port(port), port->handle);
  2578. /* can't use generic zfcp_erp_modify_port_status because
  2579. * ZFCP_STATUS_COMMON_OPEN must not be reset for the port
  2580. */
  2581. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_OPEN, &port->status);
  2582. list_for_each_entry(unit, &port->unit_list_head, list)
  2583. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2584. retval = 0;
  2585. break;
  2586. default:
  2587. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2588. "(debug info 0x%x)\n",
  2589. header->fsf_status);
  2590. break;
  2591. }
  2592. skip_fsfstatus:
  2593. atomic_clear_mask(ZFCP_STATUS_PORT_PHYS_CLOSING, &port->status);
  2594. return retval;
  2595. }
  2596. /*
  2597. * function: zfcp_fsf_open_unit
  2598. *
  2599. * purpose:
  2600. *
  2601. * returns:
  2602. *
  2603. * assumptions: This routine does not check whether the associated
  2604. * remote port has already been opened. This should be
  2605. * done by calling routines. Otherwise some status
  2606. * may be presented by FSF
  2607. */
  2608. int
  2609. zfcp_fsf_open_unit(struct zfcp_erp_action *erp_action)
  2610. {
  2611. volatile struct qdio_buffer_element *sbale;
  2612. struct zfcp_fsf_req *fsf_req;
  2613. unsigned long lock_flags;
  2614. int retval = 0;
  2615. /* setup new FSF request */
  2616. retval = zfcp_fsf_req_create(erp_action->adapter,
  2617. FSF_QTCB_OPEN_LUN,
  2618. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2619. erp_action->adapter->pool.fsf_req_erp,
  2620. &lock_flags, &fsf_req);
  2621. if (retval < 0) {
  2622. ZFCP_LOG_INFO("error: Could not create open unit request for "
  2623. "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
  2624. erp_action->unit->fcp_lun,
  2625. erp_action->unit->port->wwpn,
  2626. zfcp_get_busid_by_adapter(erp_action->adapter));
  2627. goto out;
  2628. }
  2629. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2630. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2631. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2632. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2633. fsf_req->qtcb->bottom.support.fcp_lun = erp_action->unit->fcp_lun;
  2634. if (!(erp_action->adapter->connection_features & FSF_FEATURE_NPIV_MODE))
  2635. fsf_req->qtcb->bottom.support.option =
  2636. FSF_OPEN_LUN_SUPPRESS_BOXING;
  2637. atomic_set_mask(ZFCP_STATUS_COMMON_OPENING, &erp_action->unit->status);
  2638. fsf_req->data = (unsigned long) erp_action->unit;
  2639. fsf_req->erp_action = erp_action;
  2640. erp_action->fsf_req = fsf_req;
  2641. zfcp_erp_start_timer(fsf_req);
  2642. retval = zfcp_fsf_req_send(erp_action->fsf_req);
  2643. if (retval) {
  2644. ZFCP_LOG_INFO("error: Could not send an open unit request "
  2645. "on the adapter %s, port 0x%016Lx for "
  2646. "unit 0x%016Lx\n",
  2647. zfcp_get_busid_by_adapter(erp_action->adapter),
  2648. erp_action->port->wwpn,
  2649. erp_action->unit->fcp_lun);
  2650. zfcp_fsf_req_free(fsf_req);
  2651. erp_action->fsf_req = NULL;
  2652. goto out;
  2653. }
  2654. ZFCP_LOG_TRACE("Open LUN request initiated (adapter %s, "
  2655. "port 0x%016Lx, unit 0x%016Lx)\n",
  2656. zfcp_get_busid_by_adapter(erp_action->adapter),
  2657. erp_action->port->wwpn, erp_action->unit->fcp_lun);
  2658. out:
  2659. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2660. lock_flags);
  2661. return retval;
  2662. }
  2663. /*
  2664. * function: zfcp_fsf_open_unit_handler
  2665. *
  2666. * purpose: is called for finished Open LUN command
  2667. *
  2668. * returns:
  2669. */
  2670. static int
  2671. zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
  2672. {
  2673. int retval = -EINVAL;
  2674. struct zfcp_adapter *adapter;
  2675. struct zfcp_unit *unit;
  2676. struct fsf_qtcb_header *header;
  2677. struct fsf_qtcb_bottom_support *bottom;
  2678. struct fsf_queue_designator *queue_designator;
  2679. u16 subtable, rule, counter;
  2680. int exclusive, readwrite;
  2681. unit = (struct zfcp_unit *) fsf_req->data;
  2682. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2683. /* don't change unit status in our bookkeeping */
  2684. goto skip_fsfstatus;
  2685. }
  2686. adapter = fsf_req->adapter;
  2687. header = &fsf_req->qtcb->header;
  2688. bottom = &fsf_req->qtcb->bottom.support;
  2689. queue_designator = &header->fsf_status_qual.fsf_queue_designator;
  2690. atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
  2691. ZFCP_STATUS_COMMON_ACCESS_BOXED |
  2692. ZFCP_STATUS_UNIT_SHARED |
  2693. ZFCP_STATUS_UNIT_READONLY,
  2694. &unit->status);
  2695. /* evaluate FSF status in QTCB */
  2696. switch (header->fsf_status) {
  2697. case FSF_PORT_HANDLE_NOT_VALID:
  2698. ZFCP_LOG_INFO("Temporary port identifier 0x%x "
  2699. "for port 0x%016Lx on adapter %s invalid "
  2700. "This may happen occasionally\n",
  2701. unit->port->handle,
  2702. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2703. ZFCP_LOG_DEBUG("status qualifier:\n");
  2704. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2705. (char *) &header->fsf_status_qual,
  2706. sizeof (union fsf_status_qual));
  2707. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 109, fsf_req);
  2708. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2709. break;
  2710. case FSF_LUN_ALREADY_OPEN:
  2711. ZFCP_LOG_NORMAL("bug: Attempted to open unit 0x%016Lx on "
  2712. "remote port 0x%016Lx on adapter %s twice.\n",
  2713. unit->fcp_lun,
  2714. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2715. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2716. break;
  2717. case FSF_ACCESS_DENIED:
  2718. ZFCP_LOG_NORMAL("Access denied, cannot open unit 0x%016Lx on "
  2719. "remote port 0x%016Lx on adapter %s\n",
  2720. unit->fcp_lun, unit->port->wwpn,
  2721. zfcp_get_busid_by_unit(unit));
  2722. for (counter = 0; counter < 2; counter++) {
  2723. subtable = header->fsf_status_qual.halfword[counter * 2];
  2724. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  2725. switch (subtable) {
  2726. case FSF_SQ_CFDC_SUBTABLE_OS:
  2727. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2728. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2729. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2730. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  2731. zfcp_act_subtable_type[subtable], rule);
  2732. break;
  2733. }
  2734. }
  2735. zfcp_erp_unit_access_denied(unit, 59, fsf_req);
  2736. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2737. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2738. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2739. break;
  2740. case FSF_PORT_BOXED:
  2741. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  2742. "needs to be reopened\n",
  2743. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  2744. zfcp_erp_port_boxed(unit->port, 51, fsf_req);
  2745. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  2746. ZFCP_STATUS_FSFREQ_RETRY;
  2747. break;
  2748. case FSF_LUN_SHARING_VIOLATION:
  2749. if (header->fsf_status_qual.word[0] != 0) {
  2750. ZFCP_LOG_NORMAL("FCP-LUN 0x%Lx at the remote port "
  2751. "with WWPN 0x%Lx "
  2752. "connected to the adapter %s "
  2753. "is already in use in LPAR%d, CSS%d\n",
  2754. unit->fcp_lun,
  2755. unit->port->wwpn,
  2756. zfcp_get_busid_by_unit(unit),
  2757. queue_designator->hla,
  2758. queue_designator->cssid);
  2759. } else {
  2760. subtable = header->fsf_status_qual.halfword[4];
  2761. rule = header->fsf_status_qual.halfword[5];
  2762. switch (subtable) {
  2763. case FSF_SQ_CFDC_SUBTABLE_OS:
  2764. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  2765. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  2766. case FSF_SQ_CFDC_SUBTABLE_LUN:
  2767. ZFCP_LOG_NORMAL("Access to FCP-LUN 0x%Lx at the "
  2768. "remote port with WWPN 0x%Lx "
  2769. "connected to the adapter %s "
  2770. "is denied (%s rule %d)\n",
  2771. unit->fcp_lun,
  2772. unit->port->wwpn,
  2773. zfcp_get_busid_by_unit(unit),
  2774. zfcp_act_subtable_type[subtable],
  2775. rule);
  2776. break;
  2777. }
  2778. }
  2779. ZFCP_LOG_DEBUG("status qualifier:\n");
  2780. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2781. (char *) &header->fsf_status_qual,
  2782. sizeof (union fsf_status_qual));
  2783. zfcp_erp_unit_access_denied(unit, 60, fsf_req);
  2784. atomic_clear_mask(ZFCP_STATUS_UNIT_SHARED, &unit->status);
  2785. atomic_clear_mask(ZFCP_STATUS_UNIT_READONLY, &unit->status);
  2786. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2787. break;
  2788. case FSF_MAXIMUM_NUMBER_OF_LUNS_EXCEEDED:
  2789. ZFCP_LOG_INFO("error: The adapter ran out of resources. "
  2790. "There is no handle (temporary port identifier) "
  2791. "available for unit 0x%016Lx on port 0x%016Lx "
  2792. "on adapter %s\n",
  2793. unit->fcp_lun,
  2794. unit->port->wwpn,
  2795. zfcp_get_busid_by_unit(unit));
  2796. zfcp_erp_unit_failed(unit, 34, fsf_req);
  2797. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2798. break;
  2799. case FSF_ADAPTER_STATUS_AVAILABLE:
  2800. switch (header->fsf_status_qual.word[0]) {
  2801. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  2802. /* Re-establish link to port */
  2803. zfcp_test_link(unit->port);
  2804. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2805. break;
  2806. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  2807. /* ERP strategy will escalate */
  2808. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2809. break;
  2810. default:
  2811. ZFCP_LOG_NORMAL
  2812. ("bug: Wrong status qualifier 0x%x arrived.\n",
  2813. header->fsf_status_qual.word[0]);
  2814. }
  2815. break;
  2816. case FSF_INVALID_COMMAND_OPTION:
  2817. ZFCP_LOG_NORMAL(
  2818. "Invalid option 0x%x has been specified "
  2819. "in QTCB bottom sent to the adapter %s\n",
  2820. bottom->option,
  2821. zfcp_get_busid_by_adapter(adapter));
  2822. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2823. retval = -EINVAL;
  2824. break;
  2825. case FSF_GOOD:
  2826. /* save LUN handle assigned by FSF */
  2827. unit->handle = header->lun_handle;
  2828. ZFCP_LOG_TRACE("unit 0x%016Lx on remote port 0x%016Lx on "
  2829. "adapter %s opened, port handle 0x%x\n",
  2830. unit->fcp_lun,
  2831. unit->port->wwpn,
  2832. zfcp_get_busid_by_unit(unit),
  2833. unit->handle);
  2834. /* mark unit as open */
  2835. atomic_set_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  2836. if (!(adapter->connection_features & FSF_FEATURE_NPIV_MODE) &&
  2837. (adapter->adapter_features & FSF_FEATURE_LUN_SHARING) &&
  2838. (adapter->ccw_device->id.dev_model != ZFCP_DEVICE_MODEL_PRIV)) {
  2839. exclusive = (bottom->lun_access_info &
  2840. FSF_UNIT_ACCESS_EXCLUSIVE);
  2841. readwrite = (bottom->lun_access_info &
  2842. FSF_UNIT_ACCESS_OUTBOUND_TRANSFER);
  2843. if (!exclusive)
  2844. atomic_set_mask(ZFCP_STATUS_UNIT_SHARED,
  2845. &unit->status);
  2846. if (!readwrite) {
  2847. atomic_set_mask(ZFCP_STATUS_UNIT_READONLY,
  2848. &unit->status);
  2849. ZFCP_LOG_NORMAL("read-only access for unit "
  2850. "(adapter %s, wwpn=0x%016Lx, "
  2851. "fcp_lun=0x%016Lx)\n",
  2852. zfcp_get_busid_by_unit(unit),
  2853. unit->port->wwpn,
  2854. unit->fcp_lun);
  2855. }
  2856. if (exclusive && !readwrite) {
  2857. ZFCP_LOG_NORMAL("exclusive access of read-only "
  2858. "unit not supported\n");
  2859. zfcp_erp_unit_failed(unit, 35, fsf_req);
  2860. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2861. zfcp_erp_unit_shutdown(unit, 0, 80, fsf_req);
  2862. } else if (!exclusive && readwrite) {
  2863. ZFCP_LOG_NORMAL("shared access of read-write "
  2864. "unit not supported\n");
  2865. zfcp_erp_unit_failed(unit, 36, fsf_req);
  2866. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2867. zfcp_erp_unit_shutdown(unit, 0, 81, fsf_req);
  2868. }
  2869. }
  2870. retval = 0;
  2871. break;
  2872. default:
  2873. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  2874. "(debug info 0x%x)\n",
  2875. header->fsf_status);
  2876. break;
  2877. }
  2878. skip_fsfstatus:
  2879. atomic_clear_mask(ZFCP_STATUS_COMMON_OPENING, &unit->status);
  2880. return retval;
  2881. }
  2882. /*
  2883. * function: zfcp_fsf_close_unit
  2884. *
  2885. * purpose:
  2886. *
  2887. * returns: address of fsf_req - request successfully initiated
  2888. * NULL -
  2889. *
  2890. * assumptions: This routine does not check whether the associated
  2891. * remote port/lun has already been opened. This should be
  2892. * done by calling routines. Otherwise some status
  2893. * may be presented by FSF
  2894. */
  2895. int
  2896. zfcp_fsf_close_unit(struct zfcp_erp_action *erp_action)
  2897. {
  2898. volatile struct qdio_buffer_element *sbale;
  2899. struct zfcp_fsf_req *fsf_req;
  2900. unsigned long lock_flags;
  2901. int retval = 0;
  2902. /* setup new FSF request */
  2903. retval = zfcp_fsf_req_create(erp_action->adapter,
  2904. FSF_QTCB_CLOSE_LUN,
  2905. ZFCP_WAIT_FOR_SBAL | ZFCP_REQ_AUTO_CLEANUP,
  2906. erp_action->adapter->pool.fsf_req_erp,
  2907. &lock_flags, &fsf_req);
  2908. if (retval < 0) {
  2909. ZFCP_LOG_INFO("error: Could not create close unit request for "
  2910. "unit 0x%016Lx on port 0x%016Lx on adapter %s.\n",
  2911. erp_action->unit->fcp_lun,
  2912. erp_action->port->wwpn,
  2913. zfcp_get_busid_by_adapter(erp_action->adapter));
  2914. goto out;
  2915. }
  2916. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  2917. sbale[0].flags |= SBAL_FLAGS0_TYPE_READ;
  2918. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  2919. fsf_req->qtcb->header.port_handle = erp_action->port->handle;
  2920. fsf_req->qtcb->header.lun_handle = erp_action->unit->handle;
  2921. atomic_set_mask(ZFCP_STATUS_COMMON_CLOSING, &erp_action->unit->status);
  2922. fsf_req->data = (unsigned long) erp_action->unit;
  2923. fsf_req->erp_action = erp_action;
  2924. erp_action->fsf_req = fsf_req;
  2925. zfcp_erp_start_timer(fsf_req);
  2926. retval = zfcp_fsf_req_send(erp_action->fsf_req);
  2927. if (retval) {
  2928. ZFCP_LOG_INFO("error: Could not send a close unit request for "
  2929. "unit 0x%016Lx on port 0x%016Lx onadapter %s.\n",
  2930. erp_action->unit->fcp_lun,
  2931. erp_action->port->wwpn,
  2932. zfcp_get_busid_by_adapter(erp_action->adapter));
  2933. zfcp_fsf_req_free(fsf_req);
  2934. erp_action->fsf_req = NULL;
  2935. goto out;
  2936. }
  2937. ZFCP_LOG_TRACE("Close LUN request initiated (adapter %s, "
  2938. "port 0x%016Lx, unit 0x%016Lx)\n",
  2939. zfcp_get_busid_by_adapter(erp_action->adapter),
  2940. erp_action->port->wwpn, erp_action->unit->fcp_lun);
  2941. out:
  2942. write_unlock_irqrestore(&erp_action->adapter->request_queue.queue_lock,
  2943. lock_flags);
  2944. return retval;
  2945. }
  2946. /*
  2947. * function: zfcp_fsf_close_unit_handler
  2948. *
  2949. * purpose: is called for finished Close LUN FSF command
  2950. *
  2951. * returns:
  2952. */
  2953. static int
  2954. zfcp_fsf_close_unit_handler(struct zfcp_fsf_req *fsf_req)
  2955. {
  2956. int retval = -EINVAL;
  2957. struct zfcp_unit *unit;
  2958. unit = (struct zfcp_unit *) fsf_req->data;
  2959. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  2960. /* don't change unit status in our bookkeeping */
  2961. goto skip_fsfstatus;
  2962. }
  2963. /* evaluate FSF status in QTCB */
  2964. switch (fsf_req->qtcb->header.fsf_status) {
  2965. case FSF_PORT_HANDLE_NOT_VALID:
  2966. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  2967. "0x%016Lx on adapter %s invalid. This may "
  2968. "happen in rare circumstances\n",
  2969. unit->port->handle,
  2970. unit->port->wwpn,
  2971. zfcp_get_busid_by_unit(unit));
  2972. ZFCP_LOG_DEBUG("status qualifier:\n");
  2973. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2974. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  2975. sizeof (union fsf_status_qual));
  2976. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 110, fsf_req);
  2977. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2978. break;
  2979. case FSF_LUN_HANDLE_NOT_VALID:
  2980. ZFCP_LOG_INFO("Temporary LUN identifier 0x%x of unit "
  2981. "0x%016Lx on port 0x%016Lx on adapter %s is "
  2982. "invalid. This may happen occasionally.\n",
  2983. unit->handle,
  2984. unit->fcp_lun,
  2985. unit->port->wwpn,
  2986. zfcp_get_busid_by_unit(unit));
  2987. ZFCP_LOG_DEBUG("Status qualifier data:\n");
  2988. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  2989. (char *) &fsf_req->qtcb->header.fsf_status_qual,
  2990. sizeof (union fsf_status_qual));
  2991. zfcp_erp_port_reopen(unit->port, 0, 111, fsf_req);
  2992. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  2993. break;
  2994. case FSF_PORT_BOXED:
  2995. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  2996. "needs to be reopened\n",
  2997. unit->port->wwpn,
  2998. zfcp_get_busid_by_unit(unit));
  2999. zfcp_erp_port_boxed(unit->port, 52, fsf_req);
  3000. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  3001. ZFCP_STATUS_FSFREQ_RETRY;
  3002. break;
  3003. case FSF_ADAPTER_STATUS_AVAILABLE:
  3004. switch (fsf_req->qtcb->header.fsf_status_qual.word[0]) {
  3005. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  3006. /* re-establish link to port */
  3007. zfcp_test_link(unit->port);
  3008. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3009. break;
  3010. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  3011. /* ERP strategy will escalate */
  3012. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3013. break;
  3014. default:
  3015. ZFCP_LOG_NORMAL
  3016. ("bug: Wrong status qualifier 0x%x arrived.\n",
  3017. fsf_req->qtcb->header.fsf_status_qual.word[0]);
  3018. break;
  3019. }
  3020. break;
  3021. case FSF_GOOD:
  3022. ZFCP_LOG_TRACE("unit 0x%016Lx on port 0x%016Lx on adapter %s "
  3023. "closed, port handle 0x%x\n",
  3024. unit->fcp_lun,
  3025. unit->port->wwpn,
  3026. zfcp_get_busid_by_unit(unit),
  3027. unit->handle);
  3028. /* mark unit as closed */
  3029. atomic_clear_mask(ZFCP_STATUS_COMMON_OPEN, &unit->status);
  3030. retval = 0;
  3031. break;
  3032. default:
  3033. ZFCP_LOG_NORMAL("bug: An unknown FSF Status was presented "
  3034. "(debug info 0x%x)\n",
  3035. fsf_req->qtcb->header.fsf_status);
  3036. break;
  3037. }
  3038. skip_fsfstatus:
  3039. atomic_clear_mask(ZFCP_STATUS_COMMON_CLOSING, &unit->status);
  3040. return retval;
  3041. }
  3042. /**
  3043. * zfcp_fsf_send_fcp_command_task - initiate an FCP command (for a SCSI command)
  3044. * @adapter: adapter where scsi command is issued
  3045. * @unit: unit where command is sent to
  3046. * @scsi_cmnd: scsi command to be sent
  3047. * @timer: timer to be started when request is initiated
  3048. * @req_flags: flags for fsf_request
  3049. */
  3050. int
  3051. zfcp_fsf_send_fcp_command_task(struct zfcp_adapter *adapter,
  3052. struct zfcp_unit *unit,
  3053. struct scsi_cmnd * scsi_cmnd,
  3054. int use_timer, int req_flags)
  3055. {
  3056. struct zfcp_fsf_req *fsf_req = NULL;
  3057. struct fcp_cmnd_iu *fcp_cmnd_iu;
  3058. unsigned int sbtype;
  3059. unsigned long lock_flags;
  3060. int real_bytes = 0;
  3061. int retval = 0;
  3062. int mask;
  3063. /* setup new FSF request */
  3064. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  3065. adapter->pool.fsf_req_scsi,
  3066. &lock_flags, &fsf_req);
  3067. if (unlikely(retval < 0)) {
  3068. ZFCP_LOG_DEBUG("error: Could not create FCP command request "
  3069. "for unit 0x%016Lx on port 0x%016Lx on "
  3070. "adapter %s\n",
  3071. unit->fcp_lun,
  3072. unit->port->wwpn,
  3073. zfcp_get_busid_by_adapter(adapter));
  3074. goto failed_req_create;
  3075. }
  3076. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  3077. &unit->status))) {
  3078. retval = -EBUSY;
  3079. goto unit_blocked;
  3080. }
  3081. zfcp_unit_get(unit);
  3082. fsf_req->unit = unit;
  3083. /* associate FSF request with SCSI request (for look up on abort) */
  3084. scsi_cmnd->host_scribble = (unsigned char *) fsf_req->req_id;
  3085. /* associate SCSI command with FSF request */
  3086. fsf_req->data = (unsigned long) scsi_cmnd;
  3087. /* set handles of unit and its parent port in QTCB */
  3088. fsf_req->qtcb->header.lun_handle = unit->handle;
  3089. fsf_req->qtcb->header.port_handle = unit->port->handle;
  3090. /* FSF does not define the structure of the FCP_CMND IU */
  3091. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3092. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3093. /*
  3094. * set depending on data direction:
  3095. * data direction bits in SBALE (SB Type)
  3096. * data direction bits in QTCB
  3097. * data direction bits in FCP_CMND IU
  3098. */
  3099. switch (scsi_cmnd->sc_data_direction) {
  3100. case DMA_NONE:
  3101. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  3102. /*
  3103. * FIXME(qdio):
  3104. * what is the correct type for commands
  3105. * without 'real' data buffers?
  3106. */
  3107. sbtype = SBAL_FLAGS0_TYPE_READ;
  3108. break;
  3109. case DMA_FROM_DEVICE:
  3110. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_READ;
  3111. sbtype = SBAL_FLAGS0_TYPE_READ;
  3112. fcp_cmnd_iu->rddata = 1;
  3113. break;
  3114. case DMA_TO_DEVICE:
  3115. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_WRITE;
  3116. sbtype = SBAL_FLAGS0_TYPE_WRITE;
  3117. fcp_cmnd_iu->wddata = 1;
  3118. break;
  3119. case DMA_BIDIRECTIONAL:
  3120. default:
  3121. /*
  3122. * dummy, catch this condition earlier
  3123. * in zfcp_scsi_queuecommand
  3124. */
  3125. goto failed_scsi_cmnd;
  3126. }
  3127. /* set FC service class in QTCB (3 per default) */
  3128. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  3129. /* set FCP_LUN in FCP_CMND IU in QTCB */
  3130. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  3131. mask = ZFCP_STATUS_UNIT_READONLY | ZFCP_STATUS_UNIT_SHARED;
  3132. /* set task attributes in FCP_CMND IU in QTCB */
  3133. if (likely((scsi_cmnd->device->simple_tags) ||
  3134. (atomic_test_mask(mask, &unit->status))))
  3135. fcp_cmnd_iu->task_attribute = SIMPLE_Q;
  3136. else
  3137. fcp_cmnd_iu->task_attribute = UNTAGGED;
  3138. /* set additional length of FCP_CDB in FCP_CMND IU in QTCB, if needed */
  3139. if (unlikely(scsi_cmnd->cmd_len > FCP_CDB_LENGTH)) {
  3140. fcp_cmnd_iu->add_fcp_cdb_length
  3141. = (scsi_cmnd->cmd_len - FCP_CDB_LENGTH) >> 2;
  3142. ZFCP_LOG_TRACE("SCSI CDB length is 0x%x, "
  3143. "additional FCP_CDB length is 0x%x "
  3144. "(shifted right 2 bits)\n",
  3145. scsi_cmnd->cmd_len,
  3146. fcp_cmnd_iu->add_fcp_cdb_length);
  3147. }
  3148. /*
  3149. * copy SCSI CDB (including additional length, if any) to
  3150. * FCP_CDB in FCP_CMND IU in QTCB
  3151. */
  3152. memcpy(fcp_cmnd_iu->fcp_cdb, scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  3153. /* FCP CMND IU length in QTCB */
  3154. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  3155. sizeof (struct fcp_cmnd_iu) +
  3156. fcp_cmnd_iu->add_fcp_cdb_length + sizeof (fcp_dl_t);
  3157. /* generate SBALEs from data buffer */
  3158. real_bytes = zfcp_qdio_sbals_from_scsicmnd(fsf_req, sbtype, scsi_cmnd);
  3159. if (unlikely(real_bytes < 0)) {
  3160. if (fsf_req->sbal_number < ZFCP_MAX_SBALS_PER_REQ) {
  3161. ZFCP_LOG_DEBUG(
  3162. "Data did not fit into available buffer(s), "
  3163. "waiting for more...\n");
  3164. retval = -EIO;
  3165. } else {
  3166. ZFCP_LOG_NORMAL("error: No truncation implemented but "
  3167. "required. Shutting down unit "
  3168. "(adapter %s, port 0x%016Lx, "
  3169. "unit 0x%016Lx)\n",
  3170. zfcp_get_busid_by_unit(unit),
  3171. unit->port->wwpn,
  3172. unit->fcp_lun);
  3173. zfcp_erp_unit_shutdown(unit, 0, 131, fsf_req);
  3174. retval = -EINVAL;
  3175. }
  3176. goto no_fit;
  3177. }
  3178. /* set length of FCP data length in FCP_CMND IU in QTCB */
  3179. zfcp_set_fcp_dl(fcp_cmnd_iu, real_bytes);
  3180. ZFCP_LOG_DEBUG("Sending SCSI command:\n");
  3181. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3182. (char *) scsi_cmnd->cmnd, scsi_cmnd->cmd_len);
  3183. if (use_timer)
  3184. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  3185. retval = zfcp_fsf_req_send(fsf_req);
  3186. if (unlikely(retval < 0)) {
  3187. ZFCP_LOG_INFO("error: Could not send FCP command request "
  3188. "on adapter %s, port 0x%016Lx, unit 0x%016Lx\n",
  3189. zfcp_get_busid_by_adapter(adapter),
  3190. unit->port->wwpn,
  3191. unit->fcp_lun);
  3192. goto send_failed;
  3193. }
  3194. ZFCP_LOG_TRACE("Send FCP Command initiated (adapter %s, "
  3195. "port 0x%016Lx, unit 0x%016Lx)\n",
  3196. zfcp_get_busid_by_adapter(adapter),
  3197. unit->port->wwpn,
  3198. unit->fcp_lun);
  3199. goto success;
  3200. send_failed:
  3201. no_fit:
  3202. failed_scsi_cmnd:
  3203. zfcp_unit_put(unit);
  3204. unit_blocked:
  3205. zfcp_fsf_req_free(fsf_req);
  3206. fsf_req = NULL;
  3207. scsi_cmnd->host_scribble = NULL;
  3208. success:
  3209. failed_req_create:
  3210. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3211. return retval;
  3212. }
  3213. struct zfcp_fsf_req *
  3214. zfcp_fsf_send_fcp_command_task_management(struct zfcp_adapter *adapter,
  3215. struct zfcp_unit *unit,
  3216. u8 tm_flags, int req_flags)
  3217. {
  3218. struct zfcp_fsf_req *fsf_req = NULL;
  3219. int retval = 0;
  3220. struct fcp_cmnd_iu *fcp_cmnd_iu;
  3221. unsigned long lock_flags;
  3222. volatile struct qdio_buffer_element *sbale;
  3223. /* setup new FSF request */
  3224. retval = zfcp_fsf_req_create(adapter, FSF_QTCB_FCP_CMND, req_flags,
  3225. adapter->pool.fsf_req_scsi,
  3226. &lock_flags, &fsf_req);
  3227. if (retval < 0) {
  3228. ZFCP_LOG_INFO("error: Could not create FCP command (task "
  3229. "management) request for adapter %s, port "
  3230. " 0x%016Lx, unit 0x%016Lx.\n",
  3231. zfcp_get_busid_by_adapter(adapter),
  3232. unit->port->wwpn, unit->fcp_lun);
  3233. goto out;
  3234. }
  3235. if (unlikely(!atomic_test_mask(ZFCP_STATUS_COMMON_UNBLOCKED,
  3236. &unit->status)))
  3237. goto unit_blocked;
  3238. /*
  3239. * Used to decide on proper handler in the return path,
  3240. * could be either zfcp_fsf_send_fcp_command_task_handler or
  3241. * zfcp_fsf_send_fcp_command_task_management_handler */
  3242. fsf_req->status |= ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT;
  3243. /*
  3244. * hold a pointer to the unit being target of this
  3245. * task management request
  3246. */
  3247. fsf_req->data = (unsigned long) unit;
  3248. /* set FSF related fields in QTCB */
  3249. fsf_req->qtcb->header.lun_handle = unit->handle;
  3250. fsf_req->qtcb->header.port_handle = unit->port->handle;
  3251. fsf_req->qtcb->bottom.io.data_direction = FSF_DATADIR_CMND;
  3252. fsf_req->qtcb->bottom.io.service_class = ZFCP_FC_SERVICE_CLASS_DEFAULT;
  3253. fsf_req->qtcb->bottom.io.fcp_cmnd_length =
  3254. sizeof (struct fcp_cmnd_iu) + sizeof (fcp_dl_t);
  3255. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  3256. sbale[0].flags |= SBAL_FLAGS0_TYPE_WRITE;
  3257. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  3258. /* set FCP related fields in FCP_CMND IU in QTCB */
  3259. fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3260. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3261. fcp_cmnd_iu->fcp_lun = unit->fcp_lun;
  3262. fcp_cmnd_iu->task_management_flags = tm_flags;
  3263. zfcp_fsf_start_timer(fsf_req, ZFCP_SCSI_ER_TIMEOUT);
  3264. retval = zfcp_fsf_req_send(fsf_req);
  3265. if (!retval)
  3266. goto out;
  3267. unit_blocked:
  3268. zfcp_fsf_req_free(fsf_req);
  3269. fsf_req = NULL;
  3270. out:
  3271. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3272. return fsf_req;
  3273. }
  3274. static void zfcp_fsf_update_lat(struct fsf_latency_record *lat_rec, u32 lat)
  3275. {
  3276. lat_rec->sum += lat;
  3277. if (lat_rec->min > lat)
  3278. lat_rec->min = lat;
  3279. if (lat_rec->max < lat)
  3280. lat_rec->max = lat;
  3281. }
  3282. static void zfcp_fsf_req_latency(struct zfcp_fsf_req *fsf_req)
  3283. {
  3284. struct fsf_qual_latency_info *lat_inf;
  3285. struct latency_cont *lat;
  3286. struct zfcp_unit *unit;
  3287. unsigned long flags;
  3288. lat_inf = &fsf_req->qtcb->prefix.prot_status_qual.latency_info;
  3289. unit = fsf_req->unit;
  3290. switch (fsf_req->qtcb->bottom.io.data_direction) {
  3291. case FSF_DATADIR_READ:
  3292. lat = &unit->latencies.read;
  3293. break;
  3294. case FSF_DATADIR_WRITE:
  3295. lat = &unit->latencies.write;
  3296. break;
  3297. case FSF_DATADIR_CMND:
  3298. lat = &unit->latencies.cmd;
  3299. break;
  3300. default:
  3301. return;
  3302. }
  3303. spin_lock_irqsave(&unit->latencies.lock, flags);
  3304. zfcp_fsf_update_lat(&lat->channel, lat_inf->channel_lat);
  3305. zfcp_fsf_update_lat(&lat->fabric, lat_inf->fabric_lat);
  3306. lat->counter++;
  3307. spin_unlock_irqrestore(&unit->latencies.lock, flags);
  3308. }
  3309. /*
  3310. * function: zfcp_fsf_send_fcp_command_handler
  3311. *
  3312. * purpose: is called for finished Send FCP Command
  3313. *
  3314. * returns:
  3315. */
  3316. static int
  3317. zfcp_fsf_send_fcp_command_handler(struct zfcp_fsf_req *fsf_req)
  3318. {
  3319. int retval = -EINVAL;
  3320. struct zfcp_unit *unit;
  3321. struct fsf_qtcb_header *header;
  3322. u16 subtable, rule, counter;
  3323. header = &fsf_req->qtcb->header;
  3324. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT))
  3325. unit = (struct zfcp_unit *) fsf_req->data;
  3326. else
  3327. unit = fsf_req->unit;
  3328. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  3329. /* go directly to calls of special handlers */
  3330. goto skip_fsfstatus;
  3331. }
  3332. /* evaluate FSF status in QTCB */
  3333. switch (header->fsf_status) {
  3334. case FSF_PORT_HANDLE_NOT_VALID:
  3335. ZFCP_LOG_INFO("Temporary port identifier 0x%x for port "
  3336. "0x%016Lx on adapter %s invalid\n",
  3337. unit->port->handle,
  3338. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  3339. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3340. (char *) &header->fsf_status_qual,
  3341. sizeof (union fsf_status_qual));
  3342. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 112, fsf_req);
  3343. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3344. break;
  3345. case FSF_LUN_HANDLE_NOT_VALID:
  3346. ZFCP_LOG_INFO("Temporary LUN identifier 0x%x for unit "
  3347. "0x%016Lx on port 0x%016Lx on adapter %s is "
  3348. "invalid. This may happen occasionally.\n",
  3349. unit->handle,
  3350. unit->fcp_lun,
  3351. unit->port->wwpn,
  3352. zfcp_get_busid_by_unit(unit));
  3353. ZFCP_LOG_NORMAL("Status qualifier data:\n");
  3354. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  3355. (char *) &header->fsf_status_qual,
  3356. sizeof (union fsf_status_qual));
  3357. zfcp_erp_port_reopen(unit->port, 0, 113, fsf_req);
  3358. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3359. break;
  3360. case FSF_HANDLE_MISMATCH:
  3361. ZFCP_LOG_NORMAL("bug: The port handle 0x%x has changed "
  3362. "unexpectedly. (adapter %s, port 0x%016Lx, "
  3363. "unit 0x%016Lx)\n",
  3364. unit->port->handle,
  3365. zfcp_get_busid_by_unit(unit),
  3366. unit->port->wwpn,
  3367. unit->fcp_lun);
  3368. ZFCP_LOG_NORMAL("status qualifier:\n");
  3369. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
  3370. (char *) &header->fsf_status_qual,
  3371. sizeof (union fsf_status_qual));
  3372. zfcp_erp_adapter_reopen(unit->port->adapter, 0, 114, fsf_req);
  3373. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3374. break;
  3375. case FSF_SERVICE_CLASS_NOT_SUPPORTED:
  3376. ZFCP_LOG_INFO("error: adapter %s does not support fc "
  3377. "class %d.\n",
  3378. zfcp_get_busid_by_unit(unit),
  3379. ZFCP_FC_SERVICE_CLASS_DEFAULT);
  3380. /* stop operation for this adapter */
  3381. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 132, fsf_req);
  3382. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3383. break;
  3384. case FSF_FCPLUN_NOT_VALID:
  3385. ZFCP_LOG_NORMAL("bug: unit 0x%016Lx on port 0x%016Lx on "
  3386. "adapter %s does not have correct unit "
  3387. "handle 0x%x\n",
  3388. unit->fcp_lun,
  3389. unit->port->wwpn,
  3390. zfcp_get_busid_by_unit(unit),
  3391. unit->handle);
  3392. ZFCP_LOG_DEBUG("status qualifier:\n");
  3393. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3394. (char *) &header->fsf_status_qual,
  3395. sizeof (union fsf_status_qual));
  3396. zfcp_erp_port_reopen(unit->port, 0, 115, fsf_req);
  3397. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3398. break;
  3399. case FSF_ACCESS_DENIED:
  3400. ZFCP_LOG_NORMAL("Access denied, cannot send FCP command to "
  3401. "unit 0x%016Lx on port 0x%016Lx on "
  3402. "adapter %s\n", unit->fcp_lun, unit->port->wwpn,
  3403. zfcp_get_busid_by_unit(unit));
  3404. for (counter = 0; counter < 2; counter++) {
  3405. subtable = header->fsf_status_qual.halfword[counter * 2];
  3406. rule = header->fsf_status_qual.halfword[counter * 2 + 1];
  3407. switch (subtable) {
  3408. case FSF_SQ_CFDC_SUBTABLE_OS:
  3409. case FSF_SQ_CFDC_SUBTABLE_PORT_WWPN:
  3410. case FSF_SQ_CFDC_SUBTABLE_PORT_DID:
  3411. case FSF_SQ_CFDC_SUBTABLE_LUN:
  3412. ZFCP_LOG_INFO("Access denied (%s rule %d)\n",
  3413. zfcp_act_subtable_type[subtable], rule);
  3414. break;
  3415. }
  3416. }
  3417. zfcp_erp_unit_access_denied(unit, 61, fsf_req);
  3418. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3419. break;
  3420. case FSF_DIRECTION_INDICATOR_NOT_VALID:
  3421. ZFCP_LOG_INFO("bug: Invalid data direction given for unit "
  3422. "0x%016Lx on port 0x%016Lx on adapter %s "
  3423. "(debug info %d)\n",
  3424. unit->fcp_lun,
  3425. unit->port->wwpn,
  3426. zfcp_get_busid_by_unit(unit),
  3427. fsf_req->qtcb->bottom.io.data_direction);
  3428. /* stop operation for this adapter */
  3429. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 133, fsf_req);
  3430. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3431. break;
  3432. case FSF_CMND_LENGTH_NOT_VALID:
  3433. ZFCP_LOG_NORMAL
  3434. ("bug: An invalid control-data-block length field "
  3435. "was found in a command for unit 0x%016Lx on port "
  3436. "0x%016Lx on adapter %s " "(debug info %d)\n",
  3437. unit->fcp_lun, unit->port->wwpn,
  3438. zfcp_get_busid_by_unit(unit),
  3439. fsf_req->qtcb->bottom.io.fcp_cmnd_length);
  3440. /* stop operation for this adapter */
  3441. zfcp_erp_adapter_shutdown(unit->port->adapter, 0, 134, fsf_req);
  3442. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3443. break;
  3444. case FSF_PORT_BOXED:
  3445. ZFCP_LOG_DEBUG("The remote port 0x%016Lx on adapter %s "
  3446. "needs to be reopened\n",
  3447. unit->port->wwpn, zfcp_get_busid_by_unit(unit));
  3448. zfcp_erp_port_boxed(unit->port, 53, fsf_req);
  3449. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR |
  3450. ZFCP_STATUS_FSFREQ_RETRY;
  3451. break;
  3452. case FSF_LUN_BOXED:
  3453. ZFCP_LOG_NORMAL("unit needs to be reopened (adapter %s, "
  3454. "wwpn=0x%016Lx, fcp_lun=0x%016Lx)\n",
  3455. zfcp_get_busid_by_unit(unit),
  3456. unit->port->wwpn, unit->fcp_lun);
  3457. zfcp_erp_unit_boxed(unit, 54, fsf_req);
  3458. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR
  3459. | ZFCP_STATUS_FSFREQ_RETRY;
  3460. break;
  3461. case FSF_ADAPTER_STATUS_AVAILABLE:
  3462. switch (header->fsf_status_qual.word[0]) {
  3463. case FSF_SQ_INVOKE_LINK_TEST_PROCEDURE:
  3464. /* re-establish link to port */
  3465. zfcp_test_link(unit->port);
  3466. break;
  3467. case FSF_SQ_ULP_DEPENDENT_ERP_REQUIRED:
  3468. /* FIXME(hw) need proper specs for proper action */
  3469. /* let scsi stack deal with retries and escalation */
  3470. break;
  3471. default:
  3472. ZFCP_LOG_NORMAL
  3473. ("Unknown status qualifier 0x%x arrived.\n",
  3474. header->fsf_status_qual.word[0]);
  3475. break;
  3476. }
  3477. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3478. break;
  3479. case FSF_GOOD:
  3480. break;
  3481. case FSF_FCP_RSP_AVAILABLE:
  3482. break;
  3483. }
  3484. skip_fsfstatus:
  3485. if (fsf_req->status & ZFCP_STATUS_FSFREQ_TASK_MANAGEMENT) {
  3486. retval =
  3487. zfcp_fsf_send_fcp_command_task_management_handler(fsf_req);
  3488. } else {
  3489. retval = zfcp_fsf_send_fcp_command_task_handler(fsf_req);
  3490. fsf_req->unit = NULL;
  3491. zfcp_unit_put(unit);
  3492. }
  3493. return retval;
  3494. }
  3495. /*
  3496. * function: zfcp_fsf_send_fcp_command_task_handler
  3497. *
  3498. * purpose: evaluates FCP_RSP IU
  3499. *
  3500. * returns:
  3501. */
  3502. static int
  3503. zfcp_fsf_send_fcp_command_task_handler(struct zfcp_fsf_req *fsf_req)
  3504. {
  3505. int retval = 0;
  3506. struct scsi_cmnd *scpnt;
  3507. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  3508. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  3509. struct fcp_cmnd_iu *fcp_cmnd_iu = (struct fcp_cmnd_iu *)
  3510. &(fsf_req->qtcb->bottom.io.fcp_cmnd);
  3511. u32 sns_len;
  3512. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  3513. unsigned long flags;
  3514. struct zfcp_unit *unit = fsf_req->unit;
  3515. read_lock_irqsave(&fsf_req->adapter->abort_lock, flags);
  3516. scpnt = (struct scsi_cmnd *) fsf_req->data;
  3517. if (unlikely(!scpnt)) {
  3518. ZFCP_LOG_DEBUG
  3519. ("Command with fsf_req %p is not associated to "
  3520. "a scsi command anymore. Aborted?\n", fsf_req);
  3521. goto out;
  3522. }
  3523. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ABORTED)) {
  3524. /* FIXME: (design) mid-layer should handle DID_ABORT like
  3525. * DID_SOFT_ERROR by retrying the request for devices
  3526. * that allow retries.
  3527. */
  3528. ZFCP_LOG_DEBUG("Setting DID_SOFT_ERROR and SUGGEST_RETRY\n");
  3529. set_host_byte(&scpnt->result, DID_SOFT_ERROR);
  3530. set_driver_byte(&scpnt->result, SUGGEST_RETRY);
  3531. goto skip_fsfstatus;
  3532. }
  3533. if (unlikely(fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR)) {
  3534. ZFCP_LOG_DEBUG("Setting DID_ERROR\n");
  3535. set_host_byte(&scpnt->result, DID_ERROR);
  3536. goto skip_fsfstatus;
  3537. }
  3538. /* set message byte of result in SCSI command */
  3539. scpnt->result |= COMMAND_COMPLETE << 8;
  3540. /*
  3541. * copy SCSI status code of FCP_STATUS of FCP_RSP IU to status byte
  3542. * of result in SCSI command
  3543. */
  3544. scpnt->result |= fcp_rsp_iu->scsi_status;
  3545. if (unlikely(fcp_rsp_iu->scsi_status)) {
  3546. /* DEBUG */
  3547. ZFCP_LOG_DEBUG("status for SCSI Command:\n");
  3548. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3549. scpnt->cmnd, scpnt->cmd_len);
  3550. ZFCP_LOG_DEBUG("SCSI status code 0x%x\n",
  3551. fcp_rsp_iu->scsi_status);
  3552. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3553. (void *) fcp_rsp_iu, sizeof (struct fcp_rsp_iu));
  3554. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3555. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu),
  3556. fcp_rsp_iu->fcp_sns_len);
  3557. }
  3558. if (fsf_req->adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA)
  3559. zfcp_fsf_req_latency(fsf_req);
  3560. /* check FCP_RSP_INFO */
  3561. if (unlikely(fcp_rsp_iu->validity.bits.fcp_rsp_len_valid)) {
  3562. ZFCP_LOG_DEBUG("rsp_len is valid\n");
  3563. switch (fcp_rsp_info[3]) {
  3564. case RSP_CODE_GOOD:
  3565. /* ok, continue */
  3566. ZFCP_LOG_TRACE("no failure or Task Management "
  3567. "Function complete\n");
  3568. set_host_byte(&scpnt->result, DID_OK);
  3569. break;
  3570. case RSP_CODE_LENGTH_MISMATCH:
  3571. /* hardware bug */
  3572. ZFCP_LOG_NORMAL("bug: FCP response code indictates "
  3573. "that the fibrechannel protocol data "
  3574. "length differs from the burst length. "
  3575. "The problem occured on unit 0x%016Lx "
  3576. "on port 0x%016Lx on adapter %s",
  3577. unit->fcp_lun,
  3578. unit->port->wwpn,
  3579. zfcp_get_busid_by_unit(unit));
  3580. /* dump SCSI CDB as prepared by zfcp */
  3581. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3582. (char *) &fsf_req->qtcb->
  3583. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3584. set_host_byte(&scpnt->result, DID_ERROR);
  3585. goto skip_fsfstatus;
  3586. case RSP_CODE_FIELD_INVALID:
  3587. /* driver or hardware bug */
  3588. ZFCP_LOG_NORMAL("bug: FCP response code indictates "
  3589. "that the fibrechannel protocol data "
  3590. "fields were incorrectly set up. "
  3591. "The problem occured on the unit "
  3592. "0x%016Lx on port 0x%016Lx on "
  3593. "adapter %s",
  3594. unit->fcp_lun,
  3595. unit->port->wwpn,
  3596. zfcp_get_busid_by_unit(unit));
  3597. /* dump SCSI CDB as prepared by zfcp */
  3598. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3599. (char *) &fsf_req->qtcb->
  3600. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3601. set_host_byte(&scpnt->result, DID_ERROR);
  3602. goto skip_fsfstatus;
  3603. case RSP_CODE_RO_MISMATCH:
  3604. /* hardware bug */
  3605. ZFCP_LOG_NORMAL("bug: The FCP response code indicates "
  3606. "that conflicting values for the "
  3607. "fibrechannel payload offset from the "
  3608. "header were found. "
  3609. "The problem occured on unit 0x%016Lx "
  3610. "on port 0x%016Lx on adapter %s.\n",
  3611. unit->fcp_lun,
  3612. unit->port->wwpn,
  3613. zfcp_get_busid_by_unit(unit));
  3614. /* dump SCSI CDB as prepared by zfcp */
  3615. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3616. (char *) &fsf_req->qtcb->
  3617. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3618. set_host_byte(&scpnt->result, DID_ERROR);
  3619. goto skip_fsfstatus;
  3620. default:
  3621. ZFCP_LOG_NORMAL("bug: An invalid FCP response "
  3622. "code was detected for a command. "
  3623. "The problem occured on the unit "
  3624. "0x%016Lx on port 0x%016Lx on "
  3625. "adapter %s (debug info 0x%x)\n",
  3626. unit->fcp_lun,
  3627. unit->port->wwpn,
  3628. zfcp_get_busid_by_unit(unit),
  3629. fcp_rsp_info[3]);
  3630. /* dump SCSI CDB as prepared by zfcp */
  3631. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_DEBUG,
  3632. (char *) &fsf_req->qtcb->
  3633. bottom.io.fcp_cmnd, FSF_FCP_CMND_SIZE);
  3634. set_host_byte(&scpnt->result, DID_ERROR);
  3635. goto skip_fsfstatus;
  3636. }
  3637. }
  3638. /* check for sense data */
  3639. if (unlikely(fcp_rsp_iu->validity.bits.fcp_sns_len_valid)) {
  3640. sns_len = FSF_FCP_RSP_SIZE -
  3641. sizeof (struct fcp_rsp_iu) + fcp_rsp_iu->fcp_rsp_len;
  3642. ZFCP_LOG_TRACE("room for %i bytes sense data in QTCB\n",
  3643. sns_len);
  3644. sns_len = min(sns_len, (u32) SCSI_SENSE_BUFFERSIZE);
  3645. ZFCP_LOG_TRACE("room for %i bytes sense data in SCSI command\n",
  3646. SCSI_SENSE_BUFFERSIZE);
  3647. sns_len = min(sns_len, fcp_rsp_iu->fcp_sns_len);
  3648. ZFCP_LOG_TRACE("scpnt->result =0x%x, command was:\n",
  3649. scpnt->result);
  3650. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
  3651. scpnt->cmnd, scpnt->cmd_len);
  3652. ZFCP_LOG_TRACE("%i bytes sense data provided by FCP\n",
  3653. fcp_rsp_iu->fcp_sns_len);
  3654. memcpy(scpnt->sense_buffer,
  3655. zfcp_get_fcp_sns_info_ptr(fcp_rsp_iu), sns_len);
  3656. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE,
  3657. (void *)scpnt->sense_buffer, sns_len);
  3658. }
  3659. /* check for overrun */
  3660. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_over)) {
  3661. ZFCP_LOG_INFO("A data overrun was detected for a command. "
  3662. "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
  3663. "The response data length is "
  3664. "%d, the original length was %d.\n",
  3665. unit->fcp_lun,
  3666. unit->port->wwpn,
  3667. zfcp_get_busid_by_unit(unit),
  3668. fcp_rsp_iu->fcp_resid,
  3669. (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
  3670. }
  3671. /* check for underrun */
  3672. if (unlikely(fcp_rsp_iu->validity.bits.fcp_resid_under)) {
  3673. ZFCP_LOG_INFO("A data underrun was detected for a command. "
  3674. "unit 0x%016Lx, port 0x%016Lx, adapter %s. "
  3675. "The response data length is "
  3676. "%d, the original length was %d.\n",
  3677. unit->fcp_lun,
  3678. unit->port->wwpn,
  3679. zfcp_get_busid_by_unit(unit),
  3680. fcp_rsp_iu->fcp_resid,
  3681. (int) zfcp_get_fcp_dl(fcp_cmnd_iu));
  3682. scsi_set_resid(scpnt, fcp_rsp_iu->fcp_resid);
  3683. if (scsi_bufflen(scpnt) - scsi_get_resid(scpnt) <
  3684. scpnt->underflow)
  3685. set_host_byte(&scpnt->result, DID_ERROR);
  3686. }
  3687. skip_fsfstatus:
  3688. ZFCP_LOG_DEBUG("scpnt->result =0x%x\n", scpnt->result);
  3689. if (scpnt->result != 0)
  3690. zfcp_scsi_dbf_event_result("erro", 3, fsf_req->adapter, scpnt, fsf_req);
  3691. else if (scpnt->retries > 0)
  3692. zfcp_scsi_dbf_event_result("retr", 4, fsf_req->adapter, scpnt, fsf_req);
  3693. else
  3694. zfcp_scsi_dbf_event_result("norm", 6, fsf_req->adapter, scpnt, fsf_req);
  3695. /* cleanup pointer (need this especially for abort) */
  3696. scpnt->host_scribble = NULL;
  3697. /* always call back */
  3698. (scpnt->scsi_done) (scpnt);
  3699. /*
  3700. * We must hold this lock until scsi_done has been called.
  3701. * Otherwise we may call scsi_done after abort regarding this
  3702. * command has completed.
  3703. * Note: scsi_done must not block!
  3704. */
  3705. out:
  3706. read_unlock_irqrestore(&fsf_req->adapter->abort_lock, flags);
  3707. return retval;
  3708. }
  3709. /*
  3710. * function: zfcp_fsf_send_fcp_command_task_management_handler
  3711. *
  3712. * purpose: evaluates FCP_RSP IU
  3713. *
  3714. * returns:
  3715. */
  3716. static int
  3717. zfcp_fsf_send_fcp_command_task_management_handler(struct zfcp_fsf_req *fsf_req)
  3718. {
  3719. int retval = 0;
  3720. struct fcp_rsp_iu *fcp_rsp_iu = (struct fcp_rsp_iu *)
  3721. &(fsf_req->qtcb->bottom.io.fcp_rsp);
  3722. char *fcp_rsp_info = zfcp_get_fcp_rsp_info_ptr(fcp_rsp_iu);
  3723. struct zfcp_unit *unit = (struct zfcp_unit *) fsf_req->data;
  3724. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  3725. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3726. goto skip_fsfstatus;
  3727. }
  3728. /* check FCP_RSP_INFO */
  3729. switch (fcp_rsp_info[3]) {
  3730. case RSP_CODE_GOOD:
  3731. /* ok, continue */
  3732. ZFCP_LOG_DEBUG("no failure or Task Management "
  3733. "Function complete\n");
  3734. break;
  3735. case RSP_CODE_TASKMAN_UNSUPP:
  3736. ZFCP_LOG_NORMAL("bug: A reuested task management function "
  3737. "is not supported on the target device "
  3738. "unit 0x%016Lx, port 0x%016Lx, adapter %s\n ",
  3739. unit->fcp_lun,
  3740. unit->port->wwpn,
  3741. zfcp_get_busid_by_unit(unit));
  3742. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCNOTSUPP;
  3743. break;
  3744. case RSP_CODE_TASKMAN_FAILED:
  3745. ZFCP_LOG_NORMAL("bug: A reuested task management function "
  3746. "failed to complete successfully. "
  3747. "unit 0x%016Lx, port 0x%016Lx, adapter %s.\n",
  3748. unit->fcp_lun,
  3749. unit->port->wwpn,
  3750. zfcp_get_busid_by_unit(unit));
  3751. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3752. break;
  3753. default:
  3754. ZFCP_LOG_NORMAL("bug: An invalid FCP response "
  3755. "code was detected for a command. "
  3756. "unit 0x%016Lx, port 0x%016Lx, adapter %s "
  3757. "(debug info 0x%x)\n",
  3758. unit->fcp_lun,
  3759. unit->port->wwpn,
  3760. zfcp_get_busid_by_unit(unit),
  3761. fcp_rsp_info[3]);
  3762. fsf_req->status |= ZFCP_STATUS_FSFREQ_TMFUNCFAILED;
  3763. }
  3764. skip_fsfstatus:
  3765. return retval;
  3766. }
  3767. /*
  3768. * function: zfcp_fsf_control_file
  3769. *
  3770. * purpose: Initiator of the control file upload/download FSF requests
  3771. *
  3772. * returns: 0 - FSF request is successfuly created and queued
  3773. * -EOPNOTSUPP - The FCP adapter does not have Control File support
  3774. * -EINVAL - Invalid direction specified
  3775. * -ENOMEM - Insufficient memory
  3776. * -EPERM - Cannot create FSF request or place it in QDIO queue
  3777. */
  3778. int
  3779. zfcp_fsf_control_file(struct zfcp_adapter *adapter,
  3780. struct zfcp_fsf_req **fsf_req_ptr,
  3781. u32 fsf_command,
  3782. u32 option,
  3783. struct zfcp_sg_list *sg_list)
  3784. {
  3785. struct zfcp_fsf_req *fsf_req;
  3786. struct fsf_qtcb_bottom_support *bottom;
  3787. volatile struct qdio_buffer_element *sbale;
  3788. unsigned long lock_flags;
  3789. int req_flags = 0;
  3790. int direction;
  3791. int retval = 0;
  3792. if (!(adapter->adapter_features & FSF_FEATURE_CFDC)) {
  3793. ZFCP_LOG_INFO("cfdc not supported (adapter %s)\n",
  3794. zfcp_get_busid_by_adapter(adapter));
  3795. retval = -EOPNOTSUPP;
  3796. goto out;
  3797. }
  3798. switch (fsf_command) {
  3799. case FSF_QTCB_DOWNLOAD_CONTROL_FILE:
  3800. direction = SBAL_FLAGS0_TYPE_WRITE;
  3801. if ((option != FSF_CFDC_OPTION_FULL_ACCESS) &&
  3802. (option != FSF_CFDC_OPTION_RESTRICTED_ACCESS))
  3803. req_flags = ZFCP_WAIT_FOR_SBAL;
  3804. break;
  3805. case FSF_QTCB_UPLOAD_CONTROL_FILE:
  3806. direction = SBAL_FLAGS0_TYPE_READ;
  3807. break;
  3808. default:
  3809. ZFCP_LOG_INFO("Invalid FSF command code 0x%08x\n", fsf_command);
  3810. retval = -EINVAL;
  3811. goto out;
  3812. }
  3813. retval = zfcp_fsf_req_create(adapter, fsf_command, req_flags,
  3814. NULL, &lock_flags, &fsf_req);
  3815. if (retval < 0) {
  3816. ZFCP_LOG_INFO("error: Could not create FSF request for the "
  3817. "adapter %s\n",
  3818. zfcp_get_busid_by_adapter(adapter));
  3819. retval = -EPERM;
  3820. goto unlock_queue_lock;
  3821. }
  3822. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  3823. sbale[0].flags |= direction;
  3824. bottom = &fsf_req->qtcb->bottom.support;
  3825. bottom->operation_subtype = FSF_CFDC_OPERATION_SUBTYPE;
  3826. bottom->option = option;
  3827. if (sg_list->count > 0) {
  3828. int bytes;
  3829. bytes = zfcp_qdio_sbals_from_sg(fsf_req, direction,
  3830. sg_list->sg, sg_list->count,
  3831. ZFCP_MAX_SBALS_PER_REQ);
  3832. if (bytes != ZFCP_CFDC_MAX_CONTROL_FILE_SIZE) {
  3833. ZFCP_LOG_INFO(
  3834. "error: Could not create sufficient number of "
  3835. "SBALS for an FSF request to the adapter %s\n",
  3836. zfcp_get_busid_by_adapter(adapter));
  3837. retval = -ENOMEM;
  3838. goto free_fsf_req;
  3839. }
  3840. } else
  3841. sbale[1].flags |= SBAL_FLAGS_LAST_ENTRY;
  3842. zfcp_fsf_start_timer(fsf_req, ZFCP_FSF_REQUEST_TIMEOUT);
  3843. retval = zfcp_fsf_req_send(fsf_req);
  3844. if (retval < 0) {
  3845. ZFCP_LOG_INFO("initiation of cfdc up/download failed"
  3846. "(adapter %s)\n",
  3847. zfcp_get_busid_by_adapter(adapter));
  3848. retval = -EPERM;
  3849. goto free_fsf_req;
  3850. }
  3851. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3852. ZFCP_LOG_NORMAL("Control file %s FSF request has been sent to the "
  3853. "adapter %s\n",
  3854. fsf_command == FSF_QTCB_DOWNLOAD_CONTROL_FILE ?
  3855. "download" : "upload",
  3856. zfcp_get_busid_by_adapter(adapter));
  3857. wait_event(fsf_req->completion_wq,
  3858. fsf_req->status & ZFCP_STATUS_FSFREQ_COMPLETED);
  3859. *fsf_req_ptr = fsf_req;
  3860. goto out;
  3861. free_fsf_req:
  3862. zfcp_fsf_req_free(fsf_req);
  3863. unlock_queue_lock:
  3864. write_unlock_irqrestore(&adapter->request_queue.queue_lock, lock_flags);
  3865. out:
  3866. return retval;
  3867. }
  3868. /*
  3869. * function: zfcp_fsf_control_file_handler
  3870. *
  3871. * purpose: Handler of the control file upload/download FSF requests
  3872. *
  3873. * returns: 0 - FSF request successfuly processed
  3874. * -EAGAIN - Operation has to be repeated because of a temporary problem
  3875. * -EACCES - There is no permission to execute an operation
  3876. * -EPERM - The control file is not in a right format
  3877. * -EIO - There is a problem with the FCP adapter
  3878. * -EINVAL - Invalid operation
  3879. * -EFAULT - User space memory I/O operation fault
  3880. */
  3881. static int
  3882. zfcp_fsf_control_file_handler(struct zfcp_fsf_req *fsf_req)
  3883. {
  3884. struct zfcp_adapter *adapter = fsf_req->adapter;
  3885. struct fsf_qtcb_header *header = &fsf_req->qtcb->header;
  3886. struct fsf_qtcb_bottom_support *bottom = &fsf_req->qtcb->bottom.support;
  3887. int retval = 0;
  3888. if (fsf_req->status & ZFCP_STATUS_FSFREQ_ERROR) {
  3889. retval = -EINVAL;
  3890. goto skip_fsfstatus;
  3891. }
  3892. switch (header->fsf_status) {
  3893. case FSF_GOOD:
  3894. ZFCP_LOG_NORMAL(
  3895. "The FSF request has been successfully completed "
  3896. "on the adapter %s\n",
  3897. zfcp_get_busid_by_adapter(adapter));
  3898. break;
  3899. case FSF_OPERATION_PARTIALLY_SUCCESSFUL:
  3900. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE) {
  3901. switch (header->fsf_status_qual.word[0]) {
  3902. case FSF_SQ_CFDC_HARDENED_ON_SE:
  3903. ZFCP_LOG_NORMAL(
  3904. "CFDC on the adapter %s has being "
  3905. "hardened on primary and secondary SE\n",
  3906. zfcp_get_busid_by_adapter(adapter));
  3907. break;
  3908. case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE:
  3909. ZFCP_LOG_NORMAL(
  3910. "CFDC of the adapter %s could not "
  3911. "be saved on the SE\n",
  3912. zfcp_get_busid_by_adapter(adapter));
  3913. break;
  3914. case FSF_SQ_CFDC_COULD_NOT_HARDEN_ON_SE2:
  3915. ZFCP_LOG_NORMAL(
  3916. "CFDC of the adapter %s could not "
  3917. "be copied to the secondary SE\n",
  3918. zfcp_get_busid_by_adapter(adapter));
  3919. break;
  3920. default:
  3921. ZFCP_LOG_NORMAL(
  3922. "CFDC could not be hardened "
  3923. "on the adapter %s\n",
  3924. zfcp_get_busid_by_adapter(adapter));
  3925. }
  3926. }
  3927. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3928. retval = -EAGAIN;
  3929. break;
  3930. case FSF_AUTHORIZATION_FAILURE:
  3931. ZFCP_LOG_NORMAL(
  3932. "Adapter %s does not accept privileged commands\n",
  3933. zfcp_get_busid_by_adapter(adapter));
  3934. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3935. retval = -EACCES;
  3936. break;
  3937. case FSF_CFDC_ERROR_DETECTED:
  3938. ZFCP_LOG_NORMAL(
  3939. "Error at position %d in the CFDC, "
  3940. "CFDC is discarded by the adapter %s\n",
  3941. header->fsf_status_qual.word[0],
  3942. zfcp_get_busid_by_adapter(adapter));
  3943. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3944. retval = -EPERM;
  3945. break;
  3946. case FSF_CONTROL_FILE_UPDATE_ERROR:
  3947. ZFCP_LOG_NORMAL(
  3948. "Adapter %s cannot harden the control file, "
  3949. "file is discarded\n",
  3950. zfcp_get_busid_by_adapter(adapter));
  3951. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3952. retval = -EIO;
  3953. break;
  3954. case FSF_CONTROL_FILE_TOO_LARGE:
  3955. ZFCP_LOG_NORMAL(
  3956. "Control file is too large, file is discarded "
  3957. "by the adapter %s\n",
  3958. zfcp_get_busid_by_adapter(adapter));
  3959. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3960. retval = -EIO;
  3961. break;
  3962. case FSF_ACCESS_CONFLICT_DETECTED:
  3963. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
  3964. ZFCP_LOG_NORMAL(
  3965. "CFDC has been discarded by the adapter %s, "
  3966. "because activation would impact "
  3967. "%d active connection(s)\n",
  3968. zfcp_get_busid_by_adapter(adapter),
  3969. header->fsf_status_qual.word[0]);
  3970. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3971. retval = -EIO;
  3972. break;
  3973. case FSF_CONFLICTS_OVERRULED:
  3974. if (bottom->operation_subtype == FSF_CFDC_OPERATION_SUBTYPE)
  3975. ZFCP_LOG_NORMAL(
  3976. "CFDC has been activated on the adapter %s, "
  3977. "but activation has impacted "
  3978. "%d active connection(s)\n",
  3979. zfcp_get_busid_by_adapter(adapter),
  3980. header->fsf_status_qual.word[0]);
  3981. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3982. retval = -EIO;
  3983. break;
  3984. case FSF_UNKNOWN_OP_SUBTYPE:
  3985. ZFCP_LOG_NORMAL("unknown operation subtype (adapter: %s, "
  3986. "op_subtype=0x%x)\n",
  3987. zfcp_get_busid_by_adapter(adapter),
  3988. bottom->operation_subtype);
  3989. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3990. retval = -EINVAL;
  3991. break;
  3992. case FSF_INVALID_COMMAND_OPTION:
  3993. ZFCP_LOG_NORMAL(
  3994. "Invalid option 0x%x has been specified "
  3995. "in QTCB bottom sent to the adapter %s\n",
  3996. bottom->option,
  3997. zfcp_get_busid_by_adapter(adapter));
  3998. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  3999. retval = -EINVAL;
  4000. break;
  4001. default:
  4002. ZFCP_LOG_NORMAL(
  4003. "bug: An unknown/unexpected FSF status 0x%08x "
  4004. "was presented on the adapter %s\n",
  4005. header->fsf_status,
  4006. zfcp_get_busid_by_adapter(adapter));
  4007. fsf_req->status |= ZFCP_STATUS_FSFREQ_ERROR;
  4008. retval = -EINVAL;
  4009. break;
  4010. }
  4011. skip_fsfstatus:
  4012. return retval;
  4013. }
  4014. static inline int
  4015. zfcp_fsf_req_sbal_check(unsigned long *flags,
  4016. struct zfcp_qdio_queue *queue, int needed)
  4017. {
  4018. write_lock_irqsave(&queue->queue_lock, *flags);
  4019. if (likely(atomic_read(&queue->free_count) >= needed))
  4020. return 1;
  4021. write_unlock_irqrestore(&queue->queue_lock, *flags);
  4022. return 0;
  4023. }
  4024. /*
  4025. * set qtcb pointer in fsf_req and initialize QTCB
  4026. */
  4027. static void
  4028. zfcp_fsf_req_qtcb_init(struct zfcp_fsf_req *fsf_req)
  4029. {
  4030. if (likely(fsf_req->qtcb != NULL)) {
  4031. fsf_req->qtcb->prefix.req_seq_no =
  4032. fsf_req->adapter->fsf_req_seq_no;
  4033. fsf_req->qtcb->prefix.req_id = fsf_req->req_id;
  4034. fsf_req->qtcb->prefix.ulp_info = ZFCP_ULP_INFO_VERSION;
  4035. fsf_req->qtcb->prefix.qtcb_type =
  4036. fsf_qtcb_type[fsf_req->fsf_command];
  4037. fsf_req->qtcb->prefix.qtcb_version = ZFCP_QTCB_VERSION;
  4038. fsf_req->qtcb->header.req_handle = fsf_req->req_id;
  4039. fsf_req->qtcb->header.fsf_command = fsf_req->fsf_command;
  4040. }
  4041. }
  4042. /**
  4043. * zfcp_fsf_req_sbal_get - try to get one SBAL in the request queue
  4044. * @adapter: adapter for which request queue is examined
  4045. * @req_flags: flags indicating whether to wait for needed SBAL or not
  4046. * @lock_flags: lock_flags if queue_lock is taken
  4047. * Return: 0 on success, otherwise -EIO, or -ERESTARTSYS
  4048. * Locks: lock adapter->request_queue->queue_lock on success
  4049. */
  4050. static int
  4051. zfcp_fsf_req_sbal_get(struct zfcp_adapter *adapter, int req_flags,
  4052. unsigned long *lock_flags)
  4053. {
  4054. long ret;
  4055. struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
  4056. if (unlikely(req_flags & ZFCP_WAIT_FOR_SBAL)) {
  4057. ret = wait_event_interruptible_timeout(adapter->request_wq,
  4058. zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1),
  4059. ZFCP_SBAL_TIMEOUT);
  4060. if (ret < 0)
  4061. return ret;
  4062. if (!ret)
  4063. return -EIO;
  4064. } else if (!zfcp_fsf_req_sbal_check(lock_flags, req_queue, 1))
  4065. return -EIO;
  4066. return 0;
  4067. }
  4068. /*
  4069. * function: zfcp_fsf_req_create
  4070. *
  4071. * purpose: create an FSF request at the specified adapter and
  4072. * setup common fields
  4073. *
  4074. * returns: -ENOMEM if there was insufficient memory for a request
  4075. * -EIO if no qdio buffers could be allocate to the request
  4076. * -EINVAL/-EPERM on bug conditions in req_dequeue
  4077. * 0 in success
  4078. *
  4079. * note: The created request is returned by reference.
  4080. *
  4081. * locks: lock of concerned request queue must not be held,
  4082. * but is held on completion (write, irqsave)
  4083. */
  4084. int
  4085. zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
  4086. mempool_t *pool, unsigned long *lock_flags,
  4087. struct zfcp_fsf_req **fsf_req_p)
  4088. {
  4089. volatile struct qdio_buffer_element *sbale;
  4090. struct zfcp_fsf_req *fsf_req = NULL;
  4091. int ret = 0;
  4092. struct zfcp_qdio_queue *req_queue = &adapter->request_queue;
  4093. /* allocate new FSF request */
  4094. fsf_req = zfcp_fsf_req_alloc(pool, req_flags);
  4095. if (unlikely(NULL == fsf_req)) {
  4096. ZFCP_LOG_DEBUG("error: Could not put an FSF request into "
  4097. "the outbound (send) queue.\n");
  4098. ret = -ENOMEM;
  4099. goto failed_fsf_req;
  4100. }
  4101. fsf_req->adapter = adapter;
  4102. fsf_req->fsf_command = fsf_cmd;
  4103. INIT_LIST_HEAD(&fsf_req->list);
  4104. init_timer(&fsf_req->timer);
  4105. /* initialize waitqueue which may be used to wait on
  4106. this request completion */
  4107. init_waitqueue_head(&fsf_req->completion_wq);
  4108. ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
  4109. if (ret < 0)
  4110. goto failed_sbals;
  4111. /* this is serialized (we are holding req_queue-lock of adapter) */
  4112. if (adapter->req_no == 0)
  4113. adapter->req_no++;
  4114. fsf_req->req_id = adapter->req_no++;
  4115. zfcp_fsf_req_qtcb_init(fsf_req);
  4116. /*
  4117. * We hold queue_lock here. Check if QDIOUP is set and let request fail
  4118. * if it is not set (see also *_open_qdio and *_close_qdio).
  4119. */
  4120. if (!atomic_test_mask(ZFCP_STATUS_ADAPTER_QDIOUP, &adapter->status)) {
  4121. write_unlock_irqrestore(&req_queue->queue_lock, *lock_flags);
  4122. ret = -EIO;
  4123. goto failed_sbals;
  4124. }
  4125. if (fsf_req->qtcb) {
  4126. fsf_req->seq_no = adapter->fsf_req_seq_no;
  4127. fsf_req->qtcb->prefix.req_seq_no = adapter->fsf_req_seq_no;
  4128. }
  4129. fsf_req->sbal_number = 1;
  4130. fsf_req->sbal_first = req_queue->free_index;
  4131. fsf_req->sbal_curr = req_queue->free_index;
  4132. fsf_req->sbale_curr = 1;
  4133. if (likely(req_flags & ZFCP_REQ_AUTO_CLEANUP)) {
  4134. fsf_req->status |= ZFCP_STATUS_FSFREQ_CLEANUP;
  4135. }
  4136. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_curr, 0);
  4137. /* setup common SBALE fields */
  4138. sbale[0].addr = (void *) fsf_req->req_id;
  4139. sbale[0].flags |= SBAL_FLAGS0_COMMAND;
  4140. if (likely(fsf_req->qtcb != NULL)) {
  4141. sbale[1].addr = (void *) fsf_req->qtcb;
  4142. sbale[1].length = sizeof(struct fsf_qtcb);
  4143. }
  4144. ZFCP_LOG_TRACE("got %i free BUFFERs starting at index %i\n",
  4145. fsf_req->sbal_number, fsf_req->sbal_first);
  4146. goto success;
  4147. failed_sbals:
  4148. /* dequeue new FSF request previously enqueued */
  4149. zfcp_fsf_req_free(fsf_req);
  4150. fsf_req = NULL;
  4151. failed_fsf_req:
  4152. write_lock_irqsave(&req_queue->queue_lock, *lock_flags);
  4153. success:
  4154. *fsf_req_p = fsf_req;
  4155. return ret;
  4156. }
  4157. /*
  4158. * function: zfcp_fsf_req_send
  4159. *
  4160. * purpose: start transfer of FSF request via QDIO
  4161. *
  4162. * returns: 0 - request transfer succesfully started
  4163. * !0 - start of request transfer failed
  4164. */
  4165. static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
  4166. {
  4167. struct zfcp_adapter *adapter;
  4168. struct zfcp_qdio_queue *req_queue;
  4169. volatile struct qdio_buffer_element *sbale;
  4170. int inc_seq_no;
  4171. int new_distance_from_int;
  4172. int retval = 0;
  4173. adapter = fsf_req->adapter;
  4174. req_queue = &adapter->request_queue,
  4175. /* FIXME(debug): remove it later */
  4176. sbale = zfcp_qdio_sbale_req(fsf_req, fsf_req->sbal_first, 0);
  4177. ZFCP_LOG_DEBUG("SBALE0 flags=0x%x\n", sbale[0].flags);
  4178. ZFCP_LOG_TRACE("HEX DUMP OF SBALE1 PAYLOAD:\n");
  4179. ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_TRACE, (char *) sbale[1].addr,
  4180. sbale[1].length);
  4181. /* put allocated FSF request into hash table */
  4182. spin_lock(&adapter->req_list_lock);
  4183. zfcp_reqlist_add(adapter, fsf_req);
  4184. spin_unlock(&adapter->req_list_lock);
  4185. inc_seq_no = (fsf_req->qtcb != NULL);
  4186. ZFCP_LOG_TRACE("request queue of adapter %s: "
  4187. "next free SBAL is %i, %i free SBALs\n",
  4188. zfcp_get_busid_by_adapter(adapter),
  4189. req_queue->free_index,
  4190. atomic_read(&req_queue->free_count));
  4191. ZFCP_LOG_DEBUG("calling do_QDIO adapter %s, flags=0x%x, queue_no=%i, "
  4192. "index_in_queue=%i, count=%i, buffers=%p\n",
  4193. zfcp_get_busid_by_adapter(adapter),
  4194. QDIO_FLAG_SYNC_OUTPUT,
  4195. 0, fsf_req->sbal_first, fsf_req->sbal_number,
  4196. &req_queue->buffer[fsf_req->sbal_first]);
  4197. /*
  4198. * adjust the number of free SBALs in request queue as well as
  4199. * position of first one
  4200. */
  4201. atomic_sub(fsf_req->sbal_number, &req_queue->free_count);
  4202. ZFCP_LOG_TRACE("free_count=%d\n", atomic_read(&req_queue->free_count));
  4203. req_queue->free_index += fsf_req->sbal_number; /* increase */
  4204. req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap if needed */
  4205. new_distance_from_int = zfcp_qdio_determine_pci(req_queue, fsf_req);
  4206. fsf_req->issued = get_clock();
  4207. retval = do_QDIO(adapter->ccw_device,
  4208. QDIO_FLAG_SYNC_OUTPUT,
  4209. 0, fsf_req->sbal_first, fsf_req->sbal_number, NULL);
  4210. if (unlikely(retval)) {
  4211. /* Queues are down..... */
  4212. retval = -EIO;
  4213. del_timer(&fsf_req->timer);
  4214. spin_lock(&adapter->req_list_lock);
  4215. zfcp_reqlist_remove(adapter, fsf_req);
  4216. spin_unlock(&adapter->req_list_lock);
  4217. /* undo changes in request queue made for this request */
  4218. zfcp_qdio_zero_sbals(req_queue->buffer,
  4219. fsf_req->sbal_first, fsf_req->sbal_number);
  4220. atomic_add(fsf_req->sbal_number, &req_queue->free_count);
  4221. req_queue->free_index -= fsf_req->sbal_number;
  4222. req_queue->free_index += QDIO_MAX_BUFFERS_PER_Q;
  4223. req_queue->free_index %= QDIO_MAX_BUFFERS_PER_Q; /* wrap */
  4224. zfcp_erp_adapter_reopen(adapter, 0, 116, fsf_req);
  4225. } else {
  4226. req_queue->distance_from_int = new_distance_from_int;
  4227. /*
  4228. * increase FSF sequence counter -
  4229. * this must only be done for request successfully enqueued to
  4230. * QDIO this rejected requests may be cleaned up by calling
  4231. * routines resulting in missing sequence counter values
  4232. * otherwise,
  4233. */
  4234. /* Don't increase for unsolicited status */
  4235. if (inc_seq_no)
  4236. adapter->fsf_req_seq_no++;
  4237. /* count FSF requests pending */
  4238. atomic_inc(&adapter->reqs_active);
  4239. }
  4240. return retval;
  4241. }
  4242. #undef ZFCP_LOG_AREA