zfcp_fsf.c 152 KB

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