zfcp_fsf.c 162 KB

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