zfcp_fsf.c 151 KB

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