zfcp_fsf.c 151 KB

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