zfcp_fsf.c 154 KB

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