zfcp_fsf.c 150 KB

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