zfcp_fsf.c 153 KB

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