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