zfcp_fsf.c 152 KB

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