zfcp_fsf.c 152 KB

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