zfcp_fsf.c 150 KB

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