zfcp_fsf.c 139 KB

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