zfcp_fsf.c 151 KB

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