zfcp_fsf.c 144 KB

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