zfcp_fsf.c 152 KB

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