zfcp_fsf.c 151 KB

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