zfcp_fsf.c 152 KB

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