zfcp_fsf.c 149 KB

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