zfcp_fsf.c 150 KB

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