zfcp_fsf.c 144 KB

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