dasd_eckd.c 160 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829
  1. /*
  2. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  3. * Horst Hummel <Horst.Hummel@de.ibm.com>
  4. * Carsten Otte <Cotte@de.ibm.com>
  5. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  6. * Bugreports.to..: <Linux390@de.ibm.com>
  7. * Copyright IBM Corp. 1999, 2009
  8. * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
  9. * Author.........: Nigel Hislop <hislop_nigel@emc.com>
  10. */
  11. #define KMSG_COMPONENT "dasd-eckd"
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/slab.h>
  15. #include <linux/hdreg.h> /* HDIO_GETGEO */
  16. #include <linux/bio.h>
  17. #include <linux/module.h>
  18. #include <linux/compat.h>
  19. #include <linux/init.h>
  20. #include <linux/seq_file.h>
  21. #include <asm/css_chars.h>
  22. #include <asm/debug.h>
  23. #include <asm/idals.h>
  24. #include <asm/ebcdic.h>
  25. #include <asm/io.h>
  26. #include <asm/uaccess.h>
  27. #include <asm/cio.h>
  28. #include <asm/ccwdev.h>
  29. #include <asm/itcw.h>
  30. #include <asm/schid.h>
  31. #include <asm/chpid.h>
  32. #include "dasd_int.h"
  33. #include "dasd_eckd.h"
  34. #ifdef PRINTK_HEADER
  35. #undef PRINTK_HEADER
  36. #endif /* PRINTK_HEADER */
  37. #define PRINTK_HEADER "dasd(eckd):"
  38. #define ECKD_C0(i) (i->home_bytes)
  39. #define ECKD_F(i) (i->formula)
  40. #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
  41. (i->factors.f_0x02.f1))
  42. #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
  43. (i->factors.f_0x02.f2))
  44. #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
  45. (i->factors.f_0x02.f3))
  46. #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
  47. #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
  48. #define ECKD_F6(i) (i->factor6)
  49. #define ECKD_F7(i) (i->factor7)
  50. #define ECKD_F8(i) (i->factor8)
  51. /*
  52. * raw track access always map to 64k in memory
  53. * so it maps to 16 blocks of 4k per track
  54. */
  55. #define DASD_RAW_BLOCK_PER_TRACK 16
  56. #define DASD_RAW_BLOCKSIZE 4096
  57. /* 64k are 128 x 512 byte sectors */
  58. #define DASD_RAW_SECTORS_PER_TRACK 128
  59. MODULE_LICENSE("GPL");
  60. static struct dasd_discipline dasd_eckd_discipline;
  61. /* The ccw bus type uses this table to find devices that it sends to
  62. * dasd_eckd_probe */
  63. static struct ccw_device_id dasd_eckd_ids[] = {
  64. { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
  65. { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
  66. { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
  67. { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
  68. { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
  69. { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
  70. { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
  71. { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
  72. { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
  73. { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
  74. { /* end of list */ },
  75. };
  76. MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
  77. static struct ccw_driver dasd_eckd_driver; /* see below */
  78. static void *rawpadpage;
  79. #define INIT_CQR_OK 0
  80. #define INIT_CQR_UNFORMATTED 1
  81. #define INIT_CQR_ERROR 2
  82. /* emergency request for reserve/release */
  83. static struct {
  84. struct dasd_ccw_req cqr;
  85. struct ccw1 ccw;
  86. char data[32];
  87. } *dasd_reserve_req;
  88. static DEFINE_MUTEX(dasd_reserve_mutex);
  89. /* definitions for the path verification worker */
  90. struct path_verification_work_data {
  91. struct work_struct worker;
  92. struct dasd_device *device;
  93. struct dasd_ccw_req cqr;
  94. struct ccw1 ccw;
  95. __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
  96. int isglobal;
  97. __u8 tbvpm;
  98. };
  99. static struct path_verification_work_data *path_verification_worker;
  100. static DEFINE_MUTEX(dasd_path_verification_mutex);
  101. struct check_attention_work_data {
  102. struct work_struct worker;
  103. struct dasd_device *device;
  104. __u8 lpum;
  105. };
  106. static int prepare_itcw(struct itcw *, unsigned int, unsigned int, int,
  107. struct dasd_device *, struct dasd_device *,
  108. unsigned int, int, unsigned int, unsigned int,
  109. unsigned int, unsigned int);
  110. /* initial attempt at a probe function. this can be simplified once
  111. * the other detection code is gone */
  112. static int
  113. dasd_eckd_probe (struct ccw_device *cdev)
  114. {
  115. int ret;
  116. /* set ECKD specific ccw-device options */
  117. ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
  118. CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
  119. if (ret) {
  120. DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
  121. "dasd_eckd_probe: could not set "
  122. "ccw-device options");
  123. return ret;
  124. }
  125. ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
  126. return ret;
  127. }
  128. static int
  129. dasd_eckd_set_online(struct ccw_device *cdev)
  130. {
  131. return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
  132. }
  133. static const int sizes_trk0[] = { 28, 148, 84 };
  134. #define LABEL_SIZE 140
  135. /* head and record addresses of count_area read in analysis ccw */
  136. static const int count_area_head[] = { 0, 0, 0, 0, 2 };
  137. static const int count_area_rec[] = { 1, 2, 3, 4, 1 };
  138. static inline unsigned int
  139. round_up_multiple(unsigned int no, unsigned int mult)
  140. {
  141. int rem = no % mult;
  142. return (rem ? no - rem + mult : no);
  143. }
  144. static inline unsigned int
  145. ceil_quot(unsigned int d1, unsigned int d2)
  146. {
  147. return (d1 + (d2 - 1)) / d2;
  148. }
  149. static unsigned int
  150. recs_per_track(struct dasd_eckd_characteristics * rdc,
  151. unsigned int kl, unsigned int dl)
  152. {
  153. int dn, kn;
  154. switch (rdc->dev_type) {
  155. case 0x3380:
  156. if (kl)
  157. return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
  158. ceil_quot(dl + 12, 32));
  159. else
  160. return 1499 / (15 + ceil_quot(dl + 12, 32));
  161. case 0x3390:
  162. dn = ceil_quot(dl + 6, 232) + 1;
  163. if (kl) {
  164. kn = ceil_quot(kl + 6, 232) + 1;
  165. return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
  166. 9 + ceil_quot(dl + 6 * dn, 34));
  167. } else
  168. return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
  169. case 0x9345:
  170. dn = ceil_quot(dl + 6, 232) + 1;
  171. if (kl) {
  172. kn = ceil_quot(kl + 6, 232) + 1;
  173. return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
  174. ceil_quot(dl + 6 * dn, 34));
  175. } else
  176. return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
  177. }
  178. return 0;
  179. }
  180. static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
  181. {
  182. geo->cyl = (__u16) cyl;
  183. geo->head = cyl >> 16;
  184. geo->head <<= 4;
  185. geo->head |= head;
  186. }
  187. static int
  188. check_XRC (struct ccw1 *de_ccw,
  189. struct DE_eckd_data *data,
  190. struct dasd_device *device)
  191. {
  192. struct dasd_eckd_private *private = device->private;
  193. int rc;
  194. if (!private->rdc_data.facilities.XRC_supported)
  195. return 0;
  196. /* switch on System Time Stamp - needed for XRC Support */
  197. data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
  198. data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
  199. rc = get_phys_clock(&data->ep_sys_time);
  200. /* Ignore return code if sync clock is switched off. */
  201. if (rc == -EOPNOTSUPP || rc == -EACCES)
  202. rc = 0;
  203. de_ccw->count = sizeof(struct DE_eckd_data);
  204. de_ccw->flags |= CCW_FLAG_SLI;
  205. return rc;
  206. }
  207. static int
  208. define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
  209. unsigned int totrk, int cmd, struct dasd_device *device)
  210. {
  211. struct dasd_eckd_private *private = device->private;
  212. u32 begcyl, endcyl;
  213. u16 heads, beghead, endhead;
  214. int rc = 0;
  215. ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
  216. ccw->flags = 0;
  217. ccw->count = 16;
  218. ccw->cda = (__u32) __pa(data);
  219. memset(data, 0, sizeof(struct DE_eckd_data));
  220. switch (cmd) {
  221. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  222. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  223. case DASD_ECKD_CCW_READ:
  224. case DASD_ECKD_CCW_READ_MT:
  225. case DASD_ECKD_CCW_READ_CKD:
  226. case DASD_ECKD_CCW_READ_CKD_MT:
  227. case DASD_ECKD_CCW_READ_KD:
  228. case DASD_ECKD_CCW_READ_KD_MT:
  229. data->mask.perm = 0x1;
  230. data->attributes.operation = private->attrib.operation;
  231. break;
  232. case DASD_ECKD_CCW_READ_COUNT:
  233. data->mask.perm = 0x1;
  234. data->attributes.operation = DASD_BYPASS_CACHE;
  235. break;
  236. case DASD_ECKD_CCW_WRITE:
  237. case DASD_ECKD_CCW_WRITE_MT:
  238. case DASD_ECKD_CCW_WRITE_KD:
  239. case DASD_ECKD_CCW_WRITE_KD_MT:
  240. data->mask.perm = 0x02;
  241. data->attributes.operation = private->attrib.operation;
  242. rc = check_XRC (ccw, data, device);
  243. break;
  244. case DASD_ECKD_CCW_WRITE_CKD:
  245. case DASD_ECKD_CCW_WRITE_CKD_MT:
  246. data->attributes.operation = DASD_BYPASS_CACHE;
  247. rc = check_XRC (ccw, data, device);
  248. break;
  249. case DASD_ECKD_CCW_ERASE:
  250. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  251. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  252. data->mask.perm = 0x3;
  253. data->mask.auth = 0x1;
  254. data->attributes.operation = DASD_BYPASS_CACHE;
  255. rc = check_XRC (ccw, data, device);
  256. break;
  257. default:
  258. dev_err(&device->cdev->dev,
  259. "0x%x is not a known command\n", cmd);
  260. break;
  261. }
  262. data->attributes.mode = 0x3; /* ECKD */
  263. if ((private->rdc_data.cu_type == 0x2105 ||
  264. private->rdc_data.cu_type == 0x2107 ||
  265. private->rdc_data.cu_type == 0x1750)
  266. && !(private->uses_cdl && trk < 2))
  267. data->ga_extended |= 0x40; /* Regular Data Format Mode */
  268. heads = private->rdc_data.trk_per_cyl;
  269. begcyl = trk / heads;
  270. beghead = trk % heads;
  271. endcyl = totrk / heads;
  272. endhead = totrk % heads;
  273. /* check for sequential prestage - enhance cylinder range */
  274. if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
  275. data->attributes.operation == DASD_SEQ_ACCESS) {
  276. if (endcyl + private->attrib.nr_cyl < private->real_cyl)
  277. endcyl += private->attrib.nr_cyl;
  278. else
  279. endcyl = (private->real_cyl - 1);
  280. }
  281. set_ch_t(&data->beg_ext, begcyl, beghead);
  282. set_ch_t(&data->end_ext, endcyl, endhead);
  283. return rc;
  284. }
  285. static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
  286. struct dasd_device *device)
  287. {
  288. struct dasd_eckd_private *private = device->private;
  289. int rc;
  290. if (!private->rdc_data.facilities.XRC_supported)
  291. return 0;
  292. /* switch on System Time Stamp - needed for XRC Support */
  293. pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
  294. pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
  295. pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
  296. rc = get_phys_clock(&pfxdata->define_extent.ep_sys_time);
  297. /* Ignore return code if sync clock is switched off. */
  298. if (rc == -EOPNOTSUPP || rc == -EACCES)
  299. rc = 0;
  300. return rc;
  301. }
  302. static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
  303. unsigned int rec_on_trk, int count, int cmd,
  304. struct dasd_device *device, unsigned int reclen,
  305. unsigned int tlf)
  306. {
  307. struct dasd_eckd_private *private = device->private;
  308. int sector;
  309. int dn, d;
  310. memset(data, 0, sizeof(*data));
  311. sector = 0;
  312. if (rec_on_trk) {
  313. switch (private->rdc_data.dev_type) {
  314. case 0x3390:
  315. dn = ceil_quot(reclen + 6, 232);
  316. d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
  317. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  318. break;
  319. case 0x3380:
  320. d = 7 + ceil_quot(reclen + 12, 32);
  321. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  322. break;
  323. }
  324. }
  325. data->sector = sector;
  326. /* note: meaning of count depends on the operation
  327. * for record based I/O it's the number of records, but for
  328. * track based I/O it's the number of tracks
  329. */
  330. data->count = count;
  331. switch (cmd) {
  332. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  333. data->operation.orientation = 0x3;
  334. data->operation.operation = 0x03;
  335. break;
  336. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  337. data->operation.orientation = 0x3;
  338. data->operation.operation = 0x16;
  339. break;
  340. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  341. data->operation.orientation = 0x1;
  342. data->operation.operation = 0x03;
  343. data->count++;
  344. break;
  345. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  346. data->operation.orientation = 0x3;
  347. data->operation.operation = 0x16;
  348. data->count++;
  349. break;
  350. case DASD_ECKD_CCW_WRITE:
  351. case DASD_ECKD_CCW_WRITE_MT:
  352. case DASD_ECKD_CCW_WRITE_KD:
  353. case DASD_ECKD_CCW_WRITE_KD_MT:
  354. data->auxiliary.length_valid = 0x1;
  355. data->length = reclen;
  356. data->operation.operation = 0x01;
  357. break;
  358. case DASD_ECKD_CCW_WRITE_CKD:
  359. case DASD_ECKD_CCW_WRITE_CKD_MT:
  360. data->auxiliary.length_valid = 0x1;
  361. data->length = reclen;
  362. data->operation.operation = 0x03;
  363. break;
  364. case DASD_ECKD_CCW_WRITE_FULL_TRACK:
  365. data->operation.orientation = 0x0;
  366. data->operation.operation = 0x3F;
  367. data->extended_operation = 0x11;
  368. data->length = 0;
  369. data->extended_parameter_length = 0x02;
  370. if (data->count > 8) {
  371. data->extended_parameter[0] = 0xFF;
  372. data->extended_parameter[1] = 0xFF;
  373. data->extended_parameter[1] <<= (16 - count);
  374. } else {
  375. data->extended_parameter[0] = 0xFF;
  376. data->extended_parameter[0] <<= (8 - count);
  377. data->extended_parameter[1] = 0x00;
  378. }
  379. data->sector = 0xFF;
  380. break;
  381. case DASD_ECKD_CCW_WRITE_TRACK_DATA:
  382. data->auxiliary.length_valid = 0x1;
  383. data->length = reclen; /* not tlf, as one might think */
  384. data->operation.operation = 0x3F;
  385. data->extended_operation = 0x23;
  386. break;
  387. case DASD_ECKD_CCW_READ:
  388. case DASD_ECKD_CCW_READ_MT:
  389. case DASD_ECKD_CCW_READ_KD:
  390. case DASD_ECKD_CCW_READ_KD_MT:
  391. data->auxiliary.length_valid = 0x1;
  392. data->length = reclen;
  393. data->operation.operation = 0x06;
  394. break;
  395. case DASD_ECKD_CCW_READ_CKD:
  396. case DASD_ECKD_CCW_READ_CKD_MT:
  397. data->auxiliary.length_valid = 0x1;
  398. data->length = reclen;
  399. data->operation.operation = 0x16;
  400. break;
  401. case DASD_ECKD_CCW_READ_COUNT:
  402. data->operation.operation = 0x06;
  403. break;
  404. case DASD_ECKD_CCW_READ_TRACK:
  405. data->operation.orientation = 0x1;
  406. data->operation.operation = 0x0C;
  407. data->extended_parameter_length = 0;
  408. data->sector = 0xFF;
  409. break;
  410. case DASD_ECKD_CCW_READ_TRACK_DATA:
  411. data->auxiliary.length_valid = 0x1;
  412. data->length = tlf;
  413. data->operation.operation = 0x0C;
  414. break;
  415. case DASD_ECKD_CCW_ERASE:
  416. data->length = reclen;
  417. data->auxiliary.length_valid = 0x1;
  418. data->operation.operation = 0x0b;
  419. break;
  420. default:
  421. DBF_DEV_EVENT(DBF_ERR, device,
  422. "fill LRE unknown opcode 0x%x", cmd);
  423. BUG();
  424. }
  425. set_ch_t(&data->seek_addr,
  426. trk / private->rdc_data.trk_per_cyl,
  427. trk % private->rdc_data.trk_per_cyl);
  428. data->search_arg.cyl = data->seek_addr.cyl;
  429. data->search_arg.head = data->seek_addr.head;
  430. data->search_arg.record = rec_on_trk;
  431. }
  432. static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
  433. unsigned int trk, unsigned int totrk, int cmd,
  434. struct dasd_device *basedev, struct dasd_device *startdev,
  435. unsigned char format, unsigned int rec_on_trk, int count,
  436. unsigned int blksize, unsigned int tlf)
  437. {
  438. struct dasd_eckd_private *basepriv, *startpriv;
  439. struct DE_eckd_data *dedata;
  440. struct LRE_eckd_data *lredata;
  441. u32 begcyl, endcyl;
  442. u16 heads, beghead, endhead;
  443. int rc = 0;
  444. basepriv = basedev->private;
  445. startpriv = startdev->private;
  446. dedata = &pfxdata->define_extent;
  447. lredata = &pfxdata->locate_record;
  448. ccw->cmd_code = DASD_ECKD_CCW_PFX;
  449. ccw->flags = 0;
  450. if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
  451. ccw->count = sizeof(*pfxdata) + 2;
  452. ccw->cda = (__u32) __pa(pfxdata);
  453. memset(pfxdata, 0, sizeof(*pfxdata) + 2);
  454. } else {
  455. ccw->count = sizeof(*pfxdata);
  456. ccw->cda = (__u32) __pa(pfxdata);
  457. memset(pfxdata, 0, sizeof(*pfxdata));
  458. }
  459. /* prefix data */
  460. if (format > 1) {
  461. DBF_DEV_EVENT(DBF_ERR, basedev,
  462. "PFX LRE unknown format 0x%x", format);
  463. BUG();
  464. return -EINVAL;
  465. }
  466. pfxdata->format = format;
  467. pfxdata->base_address = basepriv->ned->unit_addr;
  468. pfxdata->base_lss = basepriv->ned->ID;
  469. pfxdata->validity.define_extent = 1;
  470. /* private uid is kept up to date, conf_data may be outdated */
  471. if (startpriv->uid.type == UA_BASE_PAV_ALIAS)
  472. pfxdata->validity.verify_base = 1;
  473. if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) {
  474. pfxdata->validity.verify_base = 1;
  475. pfxdata->validity.hyper_pav = 1;
  476. }
  477. /* define extend data (mostly)*/
  478. switch (cmd) {
  479. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  480. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  481. case DASD_ECKD_CCW_READ:
  482. case DASD_ECKD_CCW_READ_MT:
  483. case DASD_ECKD_CCW_READ_CKD:
  484. case DASD_ECKD_CCW_READ_CKD_MT:
  485. case DASD_ECKD_CCW_READ_KD:
  486. case DASD_ECKD_CCW_READ_KD_MT:
  487. dedata->mask.perm = 0x1;
  488. dedata->attributes.operation = basepriv->attrib.operation;
  489. break;
  490. case DASD_ECKD_CCW_READ_COUNT:
  491. dedata->mask.perm = 0x1;
  492. dedata->attributes.operation = DASD_BYPASS_CACHE;
  493. break;
  494. case DASD_ECKD_CCW_READ_TRACK:
  495. case DASD_ECKD_CCW_READ_TRACK_DATA:
  496. dedata->mask.perm = 0x1;
  497. dedata->attributes.operation = basepriv->attrib.operation;
  498. dedata->blk_size = 0;
  499. break;
  500. case DASD_ECKD_CCW_WRITE:
  501. case DASD_ECKD_CCW_WRITE_MT:
  502. case DASD_ECKD_CCW_WRITE_KD:
  503. case DASD_ECKD_CCW_WRITE_KD_MT:
  504. dedata->mask.perm = 0x02;
  505. dedata->attributes.operation = basepriv->attrib.operation;
  506. rc = check_XRC_on_prefix(pfxdata, basedev);
  507. break;
  508. case DASD_ECKD_CCW_WRITE_CKD:
  509. case DASD_ECKD_CCW_WRITE_CKD_MT:
  510. dedata->attributes.operation = DASD_BYPASS_CACHE;
  511. rc = check_XRC_on_prefix(pfxdata, basedev);
  512. break;
  513. case DASD_ECKD_CCW_ERASE:
  514. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  515. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  516. dedata->mask.perm = 0x3;
  517. dedata->mask.auth = 0x1;
  518. dedata->attributes.operation = DASD_BYPASS_CACHE;
  519. rc = check_XRC_on_prefix(pfxdata, basedev);
  520. break;
  521. case DASD_ECKD_CCW_WRITE_FULL_TRACK:
  522. dedata->mask.perm = 0x03;
  523. dedata->attributes.operation = basepriv->attrib.operation;
  524. dedata->blk_size = 0;
  525. break;
  526. case DASD_ECKD_CCW_WRITE_TRACK_DATA:
  527. dedata->mask.perm = 0x02;
  528. dedata->attributes.operation = basepriv->attrib.operation;
  529. dedata->blk_size = blksize;
  530. rc = check_XRC_on_prefix(pfxdata, basedev);
  531. break;
  532. default:
  533. DBF_DEV_EVENT(DBF_ERR, basedev,
  534. "PFX LRE unknown opcode 0x%x", cmd);
  535. BUG();
  536. return -EINVAL;
  537. }
  538. dedata->attributes.mode = 0x3; /* ECKD */
  539. if ((basepriv->rdc_data.cu_type == 0x2105 ||
  540. basepriv->rdc_data.cu_type == 0x2107 ||
  541. basepriv->rdc_data.cu_type == 0x1750)
  542. && !(basepriv->uses_cdl && trk < 2))
  543. dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
  544. heads = basepriv->rdc_data.trk_per_cyl;
  545. begcyl = trk / heads;
  546. beghead = trk % heads;
  547. endcyl = totrk / heads;
  548. endhead = totrk % heads;
  549. /* check for sequential prestage - enhance cylinder range */
  550. if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
  551. dedata->attributes.operation == DASD_SEQ_ACCESS) {
  552. if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
  553. endcyl += basepriv->attrib.nr_cyl;
  554. else
  555. endcyl = (basepriv->real_cyl - 1);
  556. }
  557. set_ch_t(&dedata->beg_ext, begcyl, beghead);
  558. set_ch_t(&dedata->end_ext, endcyl, endhead);
  559. if (format == 1) {
  560. fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
  561. basedev, blksize, tlf);
  562. }
  563. return rc;
  564. }
  565. static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
  566. unsigned int trk, unsigned int totrk, int cmd,
  567. struct dasd_device *basedev, struct dasd_device *startdev)
  568. {
  569. return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
  570. 0, 0, 0, 0, 0);
  571. }
  572. static void
  573. locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
  574. unsigned int rec_on_trk, int no_rec, int cmd,
  575. struct dasd_device * device, int reclen)
  576. {
  577. struct dasd_eckd_private *private = device->private;
  578. int sector;
  579. int dn, d;
  580. DBF_DEV_EVENT(DBF_INFO, device,
  581. "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
  582. trk, rec_on_trk, no_rec, cmd, reclen);
  583. ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
  584. ccw->flags = 0;
  585. ccw->count = 16;
  586. ccw->cda = (__u32) __pa(data);
  587. memset(data, 0, sizeof(struct LO_eckd_data));
  588. sector = 0;
  589. if (rec_on_trk) {
  590. switch (private->rdc_data.dev_type) {
  591. case 0x3390:
  592. dn = ceil_quot(reclen + 6, 232);
  593. d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
  594. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  595. break;
  596. case 0x3380:
  597. d = 7 + ceil_quot(reclen + 12, 32);
  598. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  599. break;
  600. }
  601. }
  602. data->sector = sector;
  603. data->count = no_rec;
  604. switch (cmd) {
  605. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  606. data->operation.orientation = 0x3;
  607. data->operation.operation = 0x03;
  608. break;
  609. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  610. data->operation.orientation = 0x3;
  611. data->operation.operation = 0x16;
  612. break;
  613. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  614. data->operation.orientation = 0x1;
  615. data->operation.operation = 0x03;
  616. data->count++;
  617. break;
  618. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  619. data->operation.orientation = 0x3;
  620. data->operation.operation = 0x16;
  621. data->count++;
  622. break;
  623. case DASD_ECKD_CCW_WRITE:
  624. case DASD_ECKD_CCW_WRITE_MT:
  625. case DASD_ECKD_CCW_WRITE_KD:
  626. case DASD_ECKD_CCW_WRITE_KD_MT:
  627. data->auxiliary.last_bytes_used = 0x1;
  628. data->length = reclen;
  629. data->operation.operation = 0x01;
  630. break;
  631. case DASD_ECKD_CCW_WRITE_CKD:
  632. case DASD_ECKD_CCW_WRITE_CKD_MT:
  633. data->auxiliary.last_bytes_used = 0x1;
  634. data->length = reclen;
  635. data->operation.operation = 0x03;
  636. break;
  637. case DASD_ECKD_CCW_READ:
  638. case DASD_ECKD_CCW_READ_MT:
  639. case DASD_ECKD_CCW_READ_KD:
  640. case DASD_ECKD_CCW_READ_KD_MT:
  641. data->auxiliary.last_bytes_used = 0x1;
  642. data->length = reclen;
  643. data->operation.operation = 0x06;
  644. break;
  645. case DASD_ECKD_CCW_READ_CKD:
  646. case DASD_ECKD_CCW_READ_CKD_MT:
  647. data->auxiliary.last_bytes_used = 0x1;
  648. data->length = reclen;
  649. data->operation.operation = 0x16;
  650. break;
  651. case DASD_ECKD_CCW_READ_COUNT:
  652. data->operation.operation = 0x06;
  653. break;
  654. case DASD_ECKD_CCW_ERASE:
  655. data->length = reclen;
  656. data->auxiliary.last_bytes_used = 0x1;
  657. data->operation.operation = 0x0b;
  658. break;
  659. default:
  660. DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
  661. "opcode 0x%x", cmd);
  662. }
  663. set_ch_t(&data->seek_addr,
  664. trk / private->rdc_data.trk_per_cyl,
  665. trk % private->rdc_data.trk_per_cyl);
  666. data->search_arg.cyl = data->seek_addr.cyl;
  667. data->search_arg.head = data->seek_addr.head;
  668. data->search_arg.record = rec_on_trk;
  669. }
  670. /*
  671. * Returns 1 if the block is one of the special blocks that needs
  672. * to get read/written with the KD variant of the command.
  673. * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
  674. * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
  675. * Luckily the KD variants differ only by one bit (0x08) from the
  676. * normal variant. So don't wonder about code like:
  677. * if (dasd_eckd_cdl_special(blk_per_trk, recid))
  678. * ccw->cmd_code |= 0x8;
  679. */
  680. static inline int
  681. dasd_eckd_cdl_special(int blk_per_trk, int recid)
  682. {
  683. if (recid < 3)
  684. return 1;
  685. if (recid < blk_per_trk)
  686. return 0;
  687. if (recid < 2 * blk_per_trk)
  688. return 1;
  689. return 0;
  690. }
  691. /*
  692. * Returns the record size for the special blocks of the cdl format.
  693. * Only returns something useful if dasd_eckd_cdl_special is true
  694. * for the recid.
  695. */
  696. static inline int
  697. dasd_eckd_cdl_reclen(int recid)
  698. {
  699. if (recid < 3)
  700. return sizes_trk0[recid];
  701. return LABEL_SIZE;
  702. }
  703. /* create unique id from private structure. */
  704. static void create_uid(struct dasd_eckd_private *private)
  705. {
  706. int count;
  707. struct dasd_uid *uid;
  708. uid = &private->uid;
  709. memset(uid, 0, sizeof(struct dasd_uid));
  710. memcpy(uid->vendor, private->ned->HDA_manufacturer,
  711. sizeof(uid->vendor) - 1);
  712. EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
  713. memcpy(uid->serial, private->ned->HDA_location,
  714. sizeof(uid->serial) - 1);
  715. EBCASC(uid->serial, sizeof(uid->serial) - 1);
  716. uid->ssid = private->gneq->subsystemID;
  717. uid->real_unit_addr = private->ned->unit_addr;
  718. if (private->sneq) {
  719. uid->type = private->sneq->sua_flags;
  720. if (uid->type == UA_BASE_PAV_ALIAS)
  721. uid->base_unit_addr = private->sneq->base_unit_addr;
  722. } else {
  723. uid->type = UA_BASE_DEVICE;
  724. }
  725. if (private->vdsneq) {
  726. for (count = 0; count < 16; count++) {
  727. sprintf(uid->vduit+2*count, "%02x",
  728. private->vdsneq->uit[count]);
  729. }
  730. }
  731. }
  732. /*
  733. * Generate device unique id that specifies the physical device.
  734. */
  735. static int dasd_eckd_generate_uid(struct dasd_device *device)
  736. {
  737. struct dasd_eckd_private *private = device->private;
  738. unsigned long flags;
  739. if (!private)
  740. return -ENODEV;
  741. if (!private->ned || !private->gneq)
  742. return -ENODEV;
  743. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  744. create_uid(private);
  745. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  746. return 0;
  747. }
  748. static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
  749. {
  750. struct dasd_eckd_private *private = device->private;
  751. unsigned long flags;
  752. if (private) {
  753. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  754. *uid = private->uid;
  755. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  756. return 0;
  757. }
  758. return -EINVAL;
  759. }
  760. /*
  761. * compare device UID with data of a given dasd_eckd_private structure
  762. * return 0 for match
  763. */
  764. static int dasd_eckd_compare_path_uid(struct dasd_device *device,
  765. struct dasd_eckd_private *private)
  766. {
  767. struct dasd_uid device_uid;
  768. create_uid(private);
  769. dasd_eckd_get_uid(device, &device_uid);
  770. return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
  771. }
  772. static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
  773. struct dasd_ccw_req *cqr,
  774. __u8 *rcd_buffer,
  775. __u8 lpm)
  776. {
  777. struct ccw1 *ccw;
  778. /*
  779. * buffer has to start with EBCDIC "V1.0" to show
  780. * support for virtual device SNEQ
  781. */
  782. rcd_buffer[0] = 0xE5;
  783. rcd_buffer[1] = 0xF1;
  784. rcd_buffer[2] = 0x4B;
  785. rcd_buffer[3] = 0xF0;
  786. ccw = cqr->cpaddr;
  787. ccw->cmd_code = DASD_ECKD_CCW_RCD;
  788. ccw->flags = 0;
  789. ccw->cda = (__u32)(addr_t)rcd_buffer;
  790. ccw->count = DASD_ECKD_RCD_DATA_SIZE;
  791. cqr->magic = DASD_ECKD_MAGIC;
  792. cqr->startdev = device;
  793. cqr->memdev = device;
  794. cqr->block = NULL;
  795. cqr->expires = 10*HZ;
  796. cqr->lpm = lpm;
  797. cqr->retries = 256;
  798. cqr->buildclk = get_tod_clock();
  799. cqr->status = DASD_CQR_FILLED;
  800. set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
  801. }
  802. /*
  803. * Wakeup helper for read_conf
  804. * if the cqr is not done and needs some error recovery
  805. * the buffer has to be re-initialized with the EBCDIC "V1.0"
  806. * to show support for virtual device SNEQ
  807. */
  808. static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
  809. {
  810. struct ccw1 *ccw;
  811. __u8 *rcd_buffer;
  812. if (cqr->status != DASD_CQR_DONE) {
  813. ccw = cqr->cpaddr;
  814. rcd_buffer = (__u8 *)((addr_t) ccw->cda);
  815. memset(rcd_buffer, 0, sizeof(*rcd_buffer));
  816. rcd_buffer[0] = 0xE5;
  817. rcd_buffer[1] = 0xF1;
  818. rcd_buffer[2] = 0x4B;
  819. rcd_buffer[3] = 0xF0;
  820. }
  821. dasd_wakeup_cb(cqr, data);
  822. }
  823. static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
  824. struct dasd_ccw_req *cqr,
  825. __u8 *rcd_buffer,
  826. __u8 lpm)
  827. {
  828. struct ciw *ciw;
  829. int rc;
  830. /*
  831. * sanity check: scan for RCD command in extended SenseID data
  832. * some devices do not support RCD
  833. */
  834. ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
  835. if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
  836. return -EOPNOTSUPP;
  837. dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
  838. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  839. set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
  840. cqr->retries = 5;
  841. cqr->callback = read_conf_cb;
  842. rc = dasd_sleep_on_immediatly(cqr);
  843. return rc;
  844. }
  845. static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
  846. void **rcd_buffer,
  847. int *rcd_buffer_size, __u8 lpm)
  848. {
  849. struct ciw *ciw;
  850. char *rcd_buf = NULL;
  851. int ret;
  852. struct dasd_ccw_req *cqr;
  853. /*
  854. * sanity check: scan for RCD command in extended SenseID data
  855. * some devices do not support RCD
  856. */
  857. ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
  858. if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
  859. ret = -EOPNOTSUPP;
  860. goto out_error;
  861. }
  862. rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
  863. if (!rcd_buf) {
  864. ret = -ENOMEM;
  865. goto out_error;
  866. }
  867. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
  868. 0, /* use rcd_buf as data ara */
  869. device);
  870. if (IS_ERR(cqr)) {
  871. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  872. "Could not allocate RCD request");
  873. ret = -ENOMEM;
  874. goto out_error;
  875. }
  876. dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
  877. cqr->callback = read_conf_cb;
  878. ret = dasd_sleep_on(cqr);
  879. /*
  880. * on success we update the user input parms
  881. */
  882. dasd_sfree_request(cqr, cqr->memdev);
  883. if (ret)
  884. goto out_error;
  885. *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
  886. *rcd_buffer = rcd_buf;
  887. return 0;
  888. out_error:
  889. kfree(rcd_buf);
  890. *rcd_buffer = NULL;
  891. *rcd_buffer_size = 0;
  892. return ret;
  893. }
  894. static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
  895. {
  896. struct dasd_sneq *sneq;
  897. int i, count;
  898. private->ned = NULL;
  899. private->sneq = NULL;
  900. private->vdsneq = NULL;
  901. private->gneq = NULL;
  902. count = private->conf_len / sizeof(struct dasd_sneq);
  903. sneq = (struct dasd_sneq *)private->conf_data;
  904. for (i = 0; i < count; ++i) {
  905. if (sneq->flags.identifier == 1 && sneq->format == 1)
  906. private->sneq = sneq;
  907. else if (sneq->flags.identifier == 1 && sneq->format == 4)
  908. private->vdsneq = (struct vd_sneq *)sneq;
  909. else if (sneq->flags.identifier == 2)
  910. private->gneq = (struct dasd_gneq *)sneq;
  911. else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
  912. private->ned = (struct dasd_ned *)sneq;
  913. sneq++;
  914. }
  915. if (!private->ned || !private->gneq) {
  916. private->ned = NULL;
  917. private->sneq = NULL;
  918. private->vdsneq = NULL;
  919. private->gneq = NULL;
  920. return -EINVAL;
  921. }
  922. return 0;
  923. };
  924. static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
  925. {
  926. struct dasd_gneq *gneq;
  927. int i, count, found;
  928. count = conf_len / sizeof(*gneq);
  929. gneq = (struct dasd_gneq *)conf_data;
  930. found = 0;
  931. for (i = 0; i < count; ++i) {
  932. if (gneq->flags.identifier == 2) {
  933. found = 1;
  934. break;
  935. }
  936. gneq++;
  937. }
  938. if (found)
  939. return ((char *)gneq)[18] & 0x07;
  940. else
  941. return 0;
  942. }
  943. static void dasd_eckd_clear_conf_data(struct dasd_device *device)
  944. {
  945. struct dasd_eckd_private *private = device->private;
  946. int i;
  947. private->conf_data = NULL;
  948. private->conf_len = 0;
  949. for (i = 0; i < 8; i++) {
  950. kfree(private->path_conf_data[i]);
  951. private->path_conf_data[i] = NULL;
  952. }
  953. }
  954. static int dasd_eckd_read_conf(struct dasd_device *device)
  955. {
  956. void *conf_data;
  957. int conf_len, conf_data_saved;
  958. int rc, path_err, pos;
  959. __u8 lpm, opm;
  960. struct dasd_eckd_private *private, path_private;
  961. struct dasd_path *path_data;
  962. struct dasd_uid *uid;
  963. char print_path_uid[60], print_device_uid[60];
  964. private = device->private;
  965. path_data = &device->path_data;
  966. opm = ccw_device_get_path_mask(device->cdev);
  967. conf_data_saved = 0;
  968. path_err = 0;
  969. /* get configuration data per operational path */
  970. for (lpm = 0x80; lpm; lpm>>= 1) {
  971. if (!(lpm & opm))
  972. continue;
  973. rc = dasd_eckd_read_conf_lpm(device, &conf_data,
  974. &conf_len, lpm);
  975. if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
  976. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  977. "Read configuration data returned "
  978. "error %d", rc);
  979. return rc;
  980. }
  981. if (conf_data == NULL) {
  982. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  983. "No configuration data "
  984. "retrieved");
  985. /* no further analysis possible */
  986. path_data->opm |= lpm;
  987. continue; /* no error */
  988. }
  989. /* save first valid configuration data */
  990. if (!conf_data_saved) {
  991. /* initially clear previously stored conf_data */
  992. dasd_eckd_clear_conf_data(device);
  993. private->conf_data = conf_data;
  994. private->conf_len = conf_len;
  995. if (dasd_eckd_identify_conf_parts(private)) {
  996. private->conf_data = NULL;
  997. private->conf_len = 0;
  998. kfree(conf_data);
  999. continue;
  1000. }
  1001. pos = pathmask_to_pos(lpm);
  1002. /* store per path conf_data */
  1003. private->path_conf_data[pos] =
  1004. (struct dasd_conf_data *) conf_data;
  1005. /*
  1006. * build device UID that other path data
  1007. * can be compared to it
  1008. */
  1009. dasd_eckd_generate_uid(device);
  1010. conf_data_saved++;
  1011. } else {
  1012. path_private.conf_data = conf_data;
  1013. path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
  1014. if (dasd_eckd_identify_conf_parts(
  1015. &path_private)) {
  1016. path_private.conf_data = NULL;
  1017. path_private.conf_len = 0;
  1018. kfree(conf_data);
  1019. continue;
  1020. }
  1021. if (dasd_eckd_compare_path_uid(
  1022. device, &path_private)) {
  1023. uid = &path_private.uid;
  1024. if (strlen(uid->vduit) > 0)
  1025. snprintf(print_path_uid,
  1026. sizeof(print_path_uid),
  1027. "%s.%s.%04x.%02x.%s",
  1028. uid->vendor, uid->serial,
  1029. uid->ssid, uid->real_unit_addr,
  1030. uid->vduit);
  1031. else
  1032. snprintf(print_path_uid,
  1033. sizeof(print_path_uid),
  1034. "%s.%s.%04x.%02x",
  1035. uid->vendor, uid->serial,
  1036. uid->ssid,
  1037. uid->real_unit_addr);
  1038. uid = &private->uid;
  1039. if (strlen(uid->vduit) > 0)
  1040. snprintf(print_device_uid,
  1041. sizeof(print_device_uid),
  1042. "%s.%s.%04x.%02x.%s",
  1043. uid->vendor, uid->serial,
  1044. uid->ssid, uid->real_unit_addr,
  1045. uid->vduit);
  1046. else
  1047. snprintf(print_device_uid,
  1048. sizeof(print_device_uid),
  1049. "%s.%s.%04x.%02x",
  1050. uid->vendor, uid->serial,
  1051. uid->ssid,
  1052. uid->real_unit_addr);
  1053. dev_err(&device->cdev->dev,
  1054. "Not all channel paths lead to "
  1055. "the same device, path %02X leads to "
  1056. "device %s instead of %s\n", lpm,
  1057. print_path_uid, print_device_uid);
  1058. path_err = -EINVAL;
  1059. path_data->cablepm |= lpm;
  1060. continue;
  1061. }
  1062. pos = pathmask_to_pos(lpm);
  1063. /* store per path conf_data */
  1064. private->path_conf_data[pos] =
  1065. (struct dasd_conf_data *) conf_data;
  1066. path_private.conf_data = NULL;
  1067. path_private.conf_len = 0;
  1068. }
  1069. switch (dasd_eckd_path_access(conf_data, conf_len)) {
  1070. case 0x02:
  1071. path_data->npm |= lpm;
  1072. break;
  1073. case 0x03:
  1074. path_data->ppm |= lpm;
  1075. break;
  1076. }
  1077. if (!path_data->opm) {
  1078. path_data->opm = lpm;
  1079. dasd_generic_path_operational(device);
  1080. } else {
  1081. path_data->opm |= lpm;
  1082. }
  1083. /*
  1084. * if the path is used
  1085. * it should not be in one of the negative lists
  1086. */
  1087. path_data->cablepm &= ~lpm;
  1088. path_data->hpfpm &= ~lpm;
  1089. path_data->cuirpm &= ~lpm;
  1090. }
  1091. return path_err;
  1092. }
  1093. static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
  1094. {
  1095. struct dasd_eckd_private *private = device->private;
  1096. int mdc;
  1097. u32 fcx_max_data;
  1098. if (private->fcx_max_data) {
  1099. mdc = ccw_device_get_mdc(device->cdev, lpm);
  1100. if ((mdc < 0)) {
  1101. dev_warn(&device->cdev->dev,
  1102. "Detecting the maximum data size for zHPF "
  1103. "requests failed (rc=%d) for a new path %x\n",
  1104. mdc, lpm);
  1105. return mdc;
  1106. }
  1107. fcx_max_data = (u32)mdc * FCX_MAX_DATA_FACTOR;
  1108. if (fcx_max_data < private->fcx_max_data) {
  1109. dev_warn(&device->cdev->dev,
  1110. "The maximum data size for zHPF requests %u "
  1111. "on a new path %x is below the active maximum "
  1112. "%u\n", fcx_max_data, lpm,
  1113. private->fcx_max_data);
  1114. return -EACCES;
  1115. }
  1116. }
  1117. return 0;
  1118. }
  1119. static int rebuild_device_uid(struct dasd_device *device,
  1120. struct path_verification_work_data *data)
  1121. {
  1122. struct dasd_eckd_private *private = device->private;
  1123. struct dasd_path *path_data = &device->path_data;
  1124. __u8 lpm, opm = path_data->opm;
  1125. int rc = -ENODEV;
  1126. for (lpm = 0x80; lpm; lpm >>= 1) {
  1127. if (!(lpm & opm))
  1128. continue;
  1129. memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
  1130. memset(&data->cqr, 0, sizeof(data->cqr));
  1131. data->cqr.cpaddr = &data->ccw;
  1132. rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
  1133. data->rcd_buffer,
  1134. lpm);
  1135. if (rc) {
  1136. if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
  1137. continue;
  1138. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  1139. "Read configuration data "
  1140. "returned error %d", rc);
  1141. break;
  1142. }
  1143. memcpy(private->conf_data, data->rcd_buffer,
  1144. DASD_ECKD_RCD_DATA_SIZE);
  1145. if (dasd_eckd_identify_conf_parts(private)) {
  1146. rc = -ENODEV;
  1147. } else /* first valid path is enough */
  1148. break;
  1149. }
  1150. if (!rc)
  1151. rc = dasd_eckd_generate_uid(device);
  1152. return rc;
  1153. }
  1154. static void do_path_verification_work(struct work_struct *work)
  1155. {
  1156. struct path_verification_work_data *data;
  1157. struct dasd_device *device;
  1158. struct dasd_eckd_private path_private;
  1159. struct dasd_uid *uid;
  1160. __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
  1161. __u8 lpm, opm, npm, ppm, epm, hpfpm, cablepm;
  1162. unsigned long flags;
  1163. char print_uid[60];
  1164. int rc;
  1165. data = container_of(work, struct path_verification_work_data, worker);
  1166. device = data->device;
  1167. /* delay path verification until device was resumed */
  1168. if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
  1169. schedule_work(work);
  1170. return;
  1171. }
  1172. /* check if path verification already running and delay if so */
  1173. if (test_and_set_bit(DASD_FLAG_PATH_VERIFY, &device->flags)) {
  1174. schedule_work(work);
  1175. return;
  1176. }
  1177. opm = 0;
  1178. npm = 0;
  1179. ppm = 0;
  1180. epm = 0;
  1181. hpfpm = 0;
  1182. cablepm = 0;
  1183. for (lpm = 0x80; lpm; lpm >>= 1) {
  1184. if (!(lpm & data->tbvpm))
  1185. continue;
  1186. memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
  1187. memset(&data->cqr, 0, sizeof(data->cqr));
  1188. data->cqr.cpaddr = &data->ccw;
  1189. rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
  1190. data->rcd_buffer,
  1191. lpm);
  1192. if (!rc) {
  1193. switch (dasd_eckd_path_access(data->rcd_buffer,
  1194. DASD_ECKD_RCD_DATA_SIZE)
  1195. ) {
  1196. case 0x02:
  1197. npm |= lpm;
  1198. break;
  1199. case 0x03:
  1200. ppm |= lpm;
  1201. break;
  1202. }
  1203. opm |= lpm;
  1204. } else if (rc == -EOPNOTSUPP) {
  1205. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  1206. "path verification: No configuration "
  1207. "data retrieved");
  1208. opm |= lpm;
  1209. } else if (rc == -EAGAIN) {
  1210. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  1211. "path verification: device is stopped,"
  1212. " try again later");
  1213. epm |= lpm;
  1214. } else {
  1215. dev_warn(&device->cdev->dev,
  1216. "Reading device feature codes failed "
  1217. "(rc=%d) for new path %x\n", rc, lpm);
  1218. continue;
  1219. }
  1220. if (verify_fcx_max_data(device, lpm)) {
  1221. opm &= ~lpm;
  1222. npm &= ~lpm;
  1223. ppm &= ~lpm;
  1224. hpfpm |= lpm;
  1225. continue;
  1226. }
  1227. /*
  1228. * save conf_data for comparison after
  1229. * rebuild_device_uid may have changed
  1230. * the original data
  1231. */
  1232. memcpy(&path_rcd_buf, data->rcd_buffer,
  1233. DASD_ECKD_RCD_DATA_SIZE);
  1234. path_private.conf_data = (void *) &path_rcd_buf;
  1235. path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
  1236. if (dasd_eckd_identify_conf_parts(&path_private)) {
  1237. path_private.conf_data = NULL;
  1238. path_private.conf_len = 0;
  1239. continue;
  1240. }
  1241. /*
  1242. * compare path UID with device UID only if at least
  1243. * one valid path is left
  1244. * in other case the device UID may have changed and
  1245. * the first working path UID will be used as device UID
  1246. */
  1247. if (device->path_data.opm &&
  1248. dasd_eckd_compare_path_uid(device, &path_private)) {
  1249. /*
  1250. * the comparison was not successful
  1251. * rebuild the device UID with at least one
  1252. * known path in case a z/VM hyperswap command
  1253. * has changed the device
  1254. *
  1255. * after this compare again
  1256. *
  1257. * if either the rebuild or the recompare fails
  1258. * the path can not be used
  1259. */
  1260. if (rebuild_device_uid(device, data) ||
  1261. dasd_eckd_compare_path_uid(
  1262. device, &path_private)) {
  1263. uid = &path_private.uid;
  1264. if (strlen(uid->vduit) > 0)
  1265. snprintf(print_uid, sizeof(print_uid),
  1266. "%s.%s.%04x.%02x.%s",
  1267. uid->vendor, uid->serial,
  1268. uid->ssid, uid->real_unit_addr,
  1269. uid->vduit);
  1270. else
  1271. snprintf(print_uid, sizeof(print_uid),
  1272. "%s.%s.%04x.%02x",
  1273. uid->vendor, uid->serial,
  1274. uid->ssid,
  1275. uid->real_unit_addr);
  1276. dev_err(&device->cdev->dev,
  1277. "The newly added channel path %02X "
  1278. "will not be used because it leads "
  1279. "to a different device %s\n",
  1280. lpm, print_uid);
  1281. opm &= ~lpm;
  1282. npm &= ~lpm;
  1283. ppm &= ~lpm;
  1284. cablepm |= lpm;
  1285. continue;
  1286. }
  1287. }
  1288. /*
  1289. * There is a small chance that a path is lost again between
  1290. * above path verification and the following modification of
  1291. * the device opm mask. We could avoid that race here by using
  1292. * yet another path mask, but we rather deal with this unlikely
  1293. * situation in dasd_start_IO.
  1294. */
  1295. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1296. if (!device->path_data.opm && opm) {
  1297. device->path_data.opm = opm;
  1298. device->path_data.cablepm &= ~opm;
  1299. device->path_data.cuirpm &= ~opm;
  1300. device->path_data.hpfpm &= ~opm;
  1301. dasd_generic_path_operational(device);
  1302. } else {
  1303. device->path_data.opm |= opm;
  1304. device->path_data.cablepm &= ~opm;
  1305. device->path_data.cuirpm &= ~opm;
  1306. device->path_data.hpfpm &= ~opm;
  1307. }
  1308. device->path_data.npm |= npm;
  1309. device->path_data.ppm |= ppm;
  1310. device->path_data.tbvpm |= epm;
  1311. device->path_data.cablepm |= cablepm;
  1312. device->path_data.hpfpm |= hpfpm;
  1313. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1314. }
  1315. clear_bit(DASD_FLAG_PATH_VERIFY, &device->flags);
  1316. dasd_put_device(device);
  1317. if (data->isglobal)
  1318. mutex_unlock(&dasd_path_verification_mutex);
  1319. else
  1320. kfree(data);
  1321. }
  1322. static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
  1323. {
  1324. struct path_verification_work_data *data;
  1325. data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
  1326. if (!data) {
  1327. if (mutex_trylock(&dasd_path_verification_mutex)) {
  1328. data = path_verification_worker;
  1329. data->isglobal = 1;
  1330. } else
  1331. return -ENOMEM;
  1332. } else {
  1333. memset(data, 0, sizeof(*data));
  1334. data->isglobal = 0;
  1335. }
  1336. INIT_WORK(&data->worker, do_path_verification_work);
  1337. dasd_get_device(device);
  1338. data->device = device;
  1339. data->tbvpm = lpm;
  1340. schedule_work(&data->worker);
  1341. return 0;
  1342. }
  1343. static int dasd_eckd_read_features(struct dasd_device *device)
  1344. {
  1345. struct dasd_eckd_private *private = device->private;
  1346. struct dasd_psf_prssd_data *prssdp;
  1347. struct dasd_rssd_features *features;
  1348. struct dasd_ccw_req *cqr;
  1349. struct ccw1 *ccw;
  1350. int rc;
  1351. memset(&private->features, 0, sizeof(struct dasd_rssd_features));
  1352. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  1353. (sizeof(struct dasd_psf_prssd_data) +
  1354. sizeof(struct dasd_rssd_features)),
  1355. device);
  1356. if (IS_ERR(cqr)) {
  1357. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
  1358. "allocate initialization request");
  1359. return PTR_ERR(cqr);
  1360. }
  1361. cqr->startdev = device;
  1362. cqr->memdev = device;
  1363. cqr->block = NULL;
  1364. cqr->retries = 256;
  1365. cqr->expires = 10 * HZ;
  1366. /* Prepare for Read Subsystem Data */
  1367. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1368. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  1369. prssdp->order = PSF_ORDER_PRSSD;
  1370. prssdp->suborder = 0x41; /* Read Feature Codes */
  1371. /* all other bytes of prssdp must be zero */
  1372. ccw = cqr->cpaddr;
  1373. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  1374. ccw->count = sizeof(struct dasd_psf_prssd_data);
  1375. ccw->flags |= CCW_FLAG_CC;
  1376. ccw->cda = (__u32)(addr_t) prssdp;
  1377. /* Read Subsystem Data - feature codes */
  1378. features = (struct dasd_rssd_features *) (prssdp + 1);
  1379. memset(features, 0, sizeof(struct dasd_rssd_features));
  1380. ccw++;
  1381. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  1382. ccw->count = sizeof(struct dasd_rssd_features);
  1383. ccw->cda = (__u32)(addr_t) features;
  1384. cqr->buildclk = get_tod_clock();
  1385. cqr->status = DASD_CQR_FILLED;
  1386. rc = dasd_sleep_on(cqr);
  1387. if (rc == 0) {
  1388. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1389. features = (struct dasd_rssd_features *) (prssdp + 1);
  1390. memcpy(&private->features, features,
  1391. sizeof(struct dasd_rssd_features));
  1392. } else
  1393. dev_warn(&device->cdev->dev, "Reading device feature codes"
  1394. " failed with rc=%d\n", rc);
  1395. dasd_sfree_request(cqr, cqr->memdev);
  1396. return rc;
  1397. }
  1398. /*
  1399. * Build CP for Perform Subsystem Function - SSC.
  1400. */
  1401. static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
  1402. int enable_pav)
  1403. {
  1404. struct dasd_ccw_req *cqr;
  1405. struct dasd_psf_ssc_data *psf_ssc_data;
  1406. struct ccw1 *ccw;
  1407. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
  1408. sizeof(struct dasd_psf_ssc_data),
  1409. device);
  1410. if (IS_ERR(cqr)) {
  1411. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  1412. "Could not allocate PSF-SSC request");
  1413. return cqr;
  1414. }
  1415. psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
  1416. psf_ssc_data->order = PSF_ORDER_SSC;
  1417. psf_ssc_data->suborder = 0xc0;
  1418. if (enable_pav) {
  1419. psf_ssc_data->suborder |= 0x08;
  1420. psf_ssc_data->reserved[0] = 0x88;
  1421. }
  1422. ccw = cqr->cpaddr;
  1423. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  1424. ccw->cda = (__u32)(addr_t)psf_ssc_data;
  1425. ccw->count = 66;
  1426. cqr->startdev = device;
  1427. cqr->memdev = device;
  1428. cqr->block = NULL;
  1429. cqr->retries = 256;
  1430. cqr->expires = 10*HZ;
  1431. cqr->buildclk = get_tod_clock();
  1432. cqr->status = DASD_CQR_FILLED;
  1433. return cqr;
  1434. }
  1435. /*
  1436. * Perform Subsystem Function.
  1437. * It is necessary to trigger CIO for channel revalidation since this
  1438. * call might change behaviour of DASD devices.
  1439. */
  1440. static int
  1441. dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav,
  1442. unsigned long flags)
  1443. {
  1444. struct dasd_ccw_req *cqr;
  1445. int rc;
  1446. cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
  1447. if (IS_ERR(cqr))
  1448. return PTR_ERR(cqr);
  1449. /*
  1450. * set flags e.g. turn on failfast, to prevent blocking
  1451. * the calling function should handle failed requests
  1452. */
  1453. cqr->flags |= flags;
  1454. rc = dasd_sleep_on(cqr);
  1455. if (!rc)
  1456. /* trigger CIO to reprobe devices */
  1457. css_schedule_reprobe();
  1458. else if (cqr->intrc == -EAGAIN)
  1459. rc = -EAGAIN;
  1460. dasd_sfree_request(cqr, cqr->memdev);
  1461. return rc;
  1462. }
  1463. /*
  1464. * Valide storage server of current device.
  1465. */
  1466. static int dasd_eckd_validate_server(struct dasd_device *device,
  1467. unsigned long flags)
  1468. {
  1469. struct dasd_eckd_private *private = device->private;
  1470. int enable_pav, rc;
  1471. if (private->uid.type == UA_BASE_PAV_ALIAS ||
  1472. private->uid.type == UA_HYPER_PAV_ALIAS)
  1473. return 0;
  1474. if (dasd_nopav || MACHINE_IS_VM)
  1475. enable_pav = 0;
  1476. else
  1477. enable_pav = 1;
  1478. rc = dasd_eckd_psf_ssc(device, enable_pav, flags);
  1479. /* may be requested feature is not available on server,
  1480. * therefore just report error and go ahead */
  1481. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
  1482. "returned rc=%d", private->uid.ssid, rc);
  1483. return rc;
  1484. }
  1485. /*
  1486. * worker to do a validate server in case of a lost pathgroup
  1487. */
  1488. static void dasd_eckd_do_validate_server(struct work_struct *work)
  1489. {
  1490. struct dasd_device *device = container_of(work, struct dasd_device,
  1491. kick_validate);
  1492. unsigned long flags = 0;
  1493. set_bit(DASD_CQR_FLAGS_FAILFAST, &flags);
  1494. if (dasd_eckd_validate_server(device, flags)
  1495. == -EAGAIN) {
  1496. /* schedule worker again if failed */
  1497. schedule_work(&device->kick_validate);
  1498. return;
  1499. }
  1500. dasd_put_device(device);
  1501. }
  1502. static void dasd_eckd_kick_validate_server(struct dasd_device *device)
  1503. {
  1504. dasd_get_device(device);
  1505. /* exit if device not online or in offline processing */
  1506. if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
  1507. device->state < DASD_STATE_ONLINE) {
  1508. dasd_put_device(device);
  1509. return;
  1510. }
  1511. /* queue call to do_validate_server to the kernel event daemon. */
  1512. if (!schedule_work(&device->kick_validate))
  1513. dasd_put_device(device);
  1514. }
  1515. static u32 get_fcx_max_data(struct dasd_device *device)
  1516. {
  1517. struct dasd_eckd_private *private = device->private;
  1518. int fcx_in_css, fcx_in_gneq, fcx_in_features;
  1519. int tpm, mdc;
  1520. if (dasd_nofcx)
  1521. return 0;
  1522. /* is transport mode supported? */
  1523. fcx_in_css = css_general_characteristics.fcx;
  1524. fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
  1525. fcx_in_features = private->features.feature[40] & 0x80;
  1526. tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
  1527. if (!tpm)
  1528. return 0;
  1529. mdc = ccw_device_get_mdc(device->cdev, 0);
  1530. if (mdc < 0) {
  1531. dev_warn(&device->cdev->dev, "Detecting the maximum supported"
  1532. " data size for zHPF requests failed\n");
  1533. return 0;
  1534. } else
  1535. return (u32)mdc * FCX_MAX_DATA_FACTOR;
  1536. }
  1537. /*
  1538. * Check device characteristics.
  1539. * If the device is accessible using ECKD discipline, the device is enabled.
  1540. */
  1541. static int
  1542. dasd_eckd_check_characteristics(struct dasd_device *device)
  1543. {
  1544. struct dasd_eckd_private *private = device->private;
  1545. struct dasd_block *block;
  1546. struct dasd_uid temp_uid;
  1547. int rc, i;
  1548. int readonly;
  1549. unsigned long value;
  1550. /* setup work queue for validate server*/
  1551. INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
  1552. /* setup work queue for summary unit check */
  1553. INIT_WORK(&device->suc_work, dasd_alias_handle_summary_unit_check);
  1554. if (!ccw_device_is_pathgroup(device->cdev)) {
  1555. dev_warn(&device->cdev->dev,
  1556. "A channel path group could not be established\n");
  1557. return -EIO;
  1558. }
  1559. if (!ccw_device_is_multipath(device->cdev)) {
  1560. dev_info(&device->cdev->dev,
  1561. "The DASD is not operating in multipath mode\n");
  1562. }
  1563. if (!private) {
  1564. private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
  1565. if (!private) {
  1566. dev_warn(&device->cdev->dev,
  1567. "Allocating memory for private DASD data "
  1568. "failed\n");
  1569. return -ENOMEM;
  1570. }
  1571. device->private = private;
  1572. } else {
  1573. memset(private, 0, sizeof(*private));
  1574. }
  1575. /* Invalidate status of initial analysis. */
  1576. private->init_cqr_status = -1;
  1577. /* Set default cache operations. */
  1578. private->attrib.operation = DASD_NORMAL_CACHE;
  1579. private->attrib.nr_cyl = 0;
  1580. /* Read Configuration Data */
  1581. rc = dasd_eckd_read_conf(device);
  1582. if (rc)
  1583. goto out_err1;
  1584. /* set default timeout */
  1585. device->default_expires = DASD_EXPIRES;
  1586. /* set default retry count */
  1587. device->default_retries = DASD_RETRIES;
  1588. if (private->gneq) {
  1589. value = 1;
  1590. for (i = 0; i < private->gneq->timeout.value; i++)
  1591. value = 10 * value;
  1592. value = value * private->gneq->timeout.number;
  1593. /* do not accept useless values */
  1594. if (value != 0 && value <= DASD_EXPIRES_MAX)
  1595. device->default_expires = value;
  1596. }
  1597. dasd_eckd_get_uid(device, &temp_uid);
  1598. if (temp_uid.type == UA_BASE_DEVICE) {
  1599. block = dasd_alloc_block();
  1600. if (IS_ERR(block)) {
  1601. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  1602. "could not allocate dasd "
  1603. "block structure");
  1604. rc = PTR_ERR(block);
  1605. goto out_err1;
  1606. }
  1607. device->block = block;
  1608. block->base = device;
  1609. }
  1610. /* register lcu with alias handling, enable PAV */
  1611. rc = dasd_alias_make_device_known_to_lcu(device);
  1612. if (rc)
  1613. goto out_err2;
  1614. dasd_eckd_validate_server(device, 0);
  1615. /* device may report different configuration data after LCU setup */
  1616. rc = dasd_eckd_read_conf(device);
  1617. if (rc)
  1618. goto out_err3;
  1619. /* Read Feature Codes */
  1620. dasd_eckd_read_features(device);
  1621. /* Read Device Characteristics */
  1622. rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
  1623. &private->rdc_data, 64);
  1624. if (rc) {
  1625. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  1626. "Read device characteristic failed, rc=%d", rc);
  1627. goto out_err3;
  1628. }
  1629. if ((device->features & DASD_FEATURE_USERAW) &&
  1630. !(private->rdc_data.facilities.RT_in_LR)) {
  1631. dev_err(&device->cdev->dev, "The storage server does not "
  1632. "support raw-track access\n");
  1633. rc = -EINVAL;
  1634. goto out_err3;
  1635. }
  1636. /* find the valid cylinder size */
  1637. if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
  1638. private->rdc_data.long_no_cyl)
  1639. private->real_cyl = private->rdc_data.long_no_cyl;
  1640. else
  1641. private->real_cyl = private->rdc_data.no_cyl;
  1642. private->fcx_max_data = get_fcx_max_data(device);
  1643. readonly = dasd_device_is_ro(device);
  1644. if (readonly)
  1645. set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  1646. dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
  1647. "with %d cylinders, %d heads, %d sectors%s\n",
  1648. private->rdc_data.dev_type,
  1649. private->rdc_data.dev_model,
  1650. private->rdc_data.cu_type,
  1651. private->rdc_data.cu_model.model,
  1652. private->real_cyl,
  1653. private->rdc_data.trk_per_cyl,
  1654. private->rdc_data.sec_per_trk,
  1655. readonly ? ", read-only device" : "");
  1656. return 0;
  1657. out_err3:
  1658. dasd_alias_disconnect_device_from_lcu(device);
  1659. out_err2:
  1660. dasd_free_block(device->block);
  1661. device->block = NULL;
  1662. out_err1:
  1663. kfree(private->conf_data);
  1664. kfree(device->private);
  1665. device->private = NULL;
  1666. return rc;
  1667. }
  1668. static void dasd_eckd_uncheck_device(struct dasd_device *device)
  1669. {
  1670. struct dasd_eckd_private *private = device->private;
  1671. int i;
  1672. dasd_alias_disconnect_device_from_lcu(device);
  1673. private->ned = NULL;
  1674. private->sneq = NULL;
  1675. private->vdsneq = NULL;
  1676. private->gneq = NULL;
  1677. private->conf_len = 0;
  1678. for (i = 0; i < 8; i++) {
  1679. kfree(private->path_conf_data[i]);
  1680. if ((__u8 *)private->path_conf_data[i] ==
  1681. private->conf_data) {
  1682. private->conf_data = NULL;
  1683. private->conf_len = 0;
  1684. }
  1685. private->path_conf_data[i] = NULL;
  1686. }
  1687. kfree(private->conf_data);
  1688. private->conf_data = NULL;
  1689. }
  1690. static struct dasd_ccw_req *
  1691. dasd_eckd_analysis_ccw(struct dasd_device *device)
  1692. {
  1693. struct dasd_eckd_private *private = device->private;
  1694. struct eckd_count *count_data;
  1695. struct LO_eckd_data *LO_data;
  1696. struct dasd_ccw_req *cqr;
  1697. struct ccw1 *ccw;
  1698. int cplength, datasize;
  1699. int i;
  1700. cplength = 8;
  1701. datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
  1702. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
  1703. if (IS_ERR(cqr))
  1704. return cqr;
  1705. ccw = cqr->cpaddr;
  1706. /* Define extent for the first 3 tracks. */
  1707. define_extent(ccw++, cqr->data, 0, 2,
  1708. DASD_ECKD_CCW_READ_COUNT, device);
  1709. LO_data = cqr->data + sizeof(struct DE_eckd_data);
  1710. /* Locate record for the first 4 records on track 0. */
  1711. ccw[-1].flags |= CCW_FLAG_CC;
  1712. locate_record(ccw++, LO_data++, 0, 0, 4,
  1713. DASD_ECKD_CCW_READ_COUNT, device, 0);
  1714. count_data = private->count_area;
  1715. for (i = 0; i < 4; i++) {
  1716. ccw[-1].flags |= CCW_FLAG_CC;
  1717. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  1718. ccw->flags = 0;
  1719. ccw->count = 8;
  1720. ccw->cda = (__u32)(addr_t) count_data;
  1721. ccw++;
  1722. count_data++;
  1723. }
  1724. /* Locate record for the first record on track 2. */
  1725. ccw[-1].flags |= CCW_FLAG_CC;
  1726. locate_record(ccw++, LO_data++, 2, 0, 1,
  1727. DASD_ECKD_CCW_READ_COUNT, device, 0);
  1728. /* Read count ccw. */
  1729. ccw[-1].flags |= CCW_FLAG_CC;
  1730. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  1731. ccw->flags = 0;
  1732. ccw->count = 8;
  1733. ccw->cda = (__u32)(addr_t) count_data;
  1734. cqr->block = NULL;
  1735. cqr->startdev = device;
  1736. cqr->memdev = device;
  1737. cqr->retries = 255;
  1738. cqr->buildclk = get_tod_clock();
  1739. cqr->status = DASD_CQR_FILLED;
  1740. return cqr;
  1741. }
  1742. /* differentiate between 'no record found' and any other error */
  1743. static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
  1744. {
  1745. char *sense;
  1746. if (init_cqr->status == DASD_CQR_DONE)
  1747. return INIT_CQR_OK;
  1748. else if (init_cqr->status == DASD_CQR_NEED_ERP ||
  1749. init_cqr->status == DASD_CQR_FAILED) {
  1750. sense = dasd_get_sense(&init_cqr->irb);
  1751. if (sense && (sense[1] & SNS1_NO_REC_FOUND))
  1752. return INIT_CQR_UNFORMATTED;
  1753. else
  1754. return INIT_CQR_ERROR;
  1755. } else
  1756. return INIT_CQR_ERROR;
  1757. }
  1758. /*
  1759. * This is the callback function for the init_analysis cqr. It saves
  1760. * the status of the initial analysis ccw before it frees it and kicks
  1761. * the device to continue the startup sequence. This will call
  1762. * dasd_eckd_do_analysis again (if the devices has not been marked
  1763. * for deletion in the meantime).
  1764. */
  1765. static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
  1766. void *data)
  1767. {
  1768. struct dasd_device *device = init_cqr->startdev;
  1769. struct dasd_eckd_private *private = device->private;
  1770. private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
  1771. dasd_sfree_request(init_cqr, device);
  1772. dasd_kick_device(device);
  1773. }
  1774. static int dasd_eckd_start_analysis(struct dasd_block *block)
  1775. {
  1776. struct dasd_ccw_req *init_cqr;
  1777. init_cqr = dasd_eckd_analysis_ccw(block->base);
  1778. if (IS_ERR(init_cqr))
  1779. return PTR_ERR(init_cqr);
  1780. init_cqr->callback = dasd_eckd_analysis_callback;
  1781. init_cqr->callback_data = NULL;
  1782. init_cqr->expires = 5*HZ;
  1783. /* first try without ERP, so we can later handle unformatted
  1784. * devices as special case
  1785. */
  1786. clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
  1787. init_cqr->retries = 0;
  1788. dasd_add_request_head(init_cqr);
  1789. return -EAGAIN;
  1790. }
  1791. static int dasd_eckd_end_analysis(struct dasd_block *block)
  1792. {
  1793. struct dasd_device *device = block->base;
  1794. struct dasd_eckd_private *private = device->private;
  1795. struct eckd_count *count_area;
  1796. unsigned int sb, blk_per_trk;
  1797. int status, i;
  1798. struct dasd_ccw_req *init_cqr;
  1799. status = private->init_cqr_status;
  1800. private->init_cqr_status = -1;
  1801. if (status == INIT_CQR_ERROR) {
  1802. /* try again, this time with full ERP */
  1803. init_cqr = dasd_eckd_analysis_ccw(device);
  1804. dasd_sleep_on(init_cqr);
  1805. status = dasd_eckd_analysis_evaluation(init_cqr);
  1806. dasd_sfree_request(init_cqr, device);
  1807. }
  1808. if (device->features & DASD_FEATURE_USERAW) {
  1809. block->bp_block = DASD_RAW_BLOCKSIZE;
  1810. blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
  1811. block->s2b_shift = 3;
  1812. goto raw;
  1813. }
  1814. if (status == INIT_CQR_UNFORMATTED) {
  1815. dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
  1816. return -EMEDIUMTYPE;
  1817. } else if (status == INIT_CQR_ERROR) {
  1818. dev_err(&device->cdev->dev,
  1819. "Detecting the DASD disk layout failed because "
  1820. "of an I/O error\n");
  1821. return -EIO;
  1822. }
  1823. private->uses_cdl = 1;
  1824. /* Check Track 0 for Compatible Disk Layout */
  1825. count_area = NULL;
  1826. for (i = 0; i < 3; i++) {
  1827. if (private->count_area[i].kl != 4 ||
  1828. private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4 ||
  1829. private->count_area[i].cyl != 0 ||
  1830. private->count_area[i].head != count_area_head[i] ||
  1831. private->count_area[i].record != count_area_rec[i]) {
  1832. private->uses_cdl = 0;
  1833. break;
  1834. }
  1835. }
  1836. if (i == 3)
  1837. count_area = &private->count_area[4];
  1838. if (private->uses_cdl == 0) {
  1839. for (i = 0; i < 5; i++) {
  1840. if ((private->count_area[i].kl != 0) ||
  1841. (private->count_area[i].dl !=
  1842. private->count_area[0].dl) ||
  1843. private->count_area[i].cyl != 0 ||
  1844. private->count_area[i].head != count_area_head[i] ||
  1845. private->count_area[i].record != count_area_rec[i])
  1846. break;
  1847. }
  1848. if (i == 5)
  1849. count_area = &private->count_area[0];
  1850. } else {
  1851. if (private->count_area[3].record == 1)
  1852. dev_warn(&device->cdev->dev,
  1853. "Track 0 has no records following the VTOC\n");
  1854. }
  1855. if (count_area != NULL && count_area->kl == 0) {
  1856. /* we found notthing violating our disk layout */
  1857. if (dasd_check_blocksize(count_area->dl) == 0)
  1858. block->bp_block = count_area->dl;
  1859. }
  1860. if (block->bp_block == 0) {
  1861. dev_warn(&device->cdev->dev,
  1862. "The disk layout of the DASD is not supported\n");
  1863. return -EMEDIUMTYPE;
  1864. }
  1865. block->s2b_shift = 0; /* bits to shift 512 to get a block */
  1866. for (sb = 512; sb < block->bp_block; sb = sb << 1)
  1867. block->s2b_shift++;
  1868. blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
  1869. raw:
  1870. block->blocks = (private->real_cyl *
  1871. private->rdc_data.trk_per_cyl *
  1872. blk_per_trk);
  1873. dev_info(&device->cdev->dev,
  1874. "DASD with %d KB/block, %d KB total size, %d KB/track, "
  1875. "%s\n", (block->bp_block >> 10),
  1876. ((private->real_cyl *
  1877. private->rdc_data.trk_per_cyl *
  1878. blk_per_trk * (block->bp_block >> 9)) >> 1),
  1879. ((blk_per_trk * block->bp_block) >> 10),
  1880. private->uses_cdl ?
  1881. "compatible disk layout" : "linux disk layout");
  1882. return 0;
  1883. }
  1884. static int dasd_eckd_do_analysis(struct dasd_block *block)
  1885. {
  1886. struct dasd_eckd_private *private = block->base->private;
  1887. if (private->init_cqr_status < 0)
  1888. return dasd_eckd_start_analysis(block);
  1889. else
  1890. return dasd_eckd_end_analysis(block);
  1891. }
  1892. static int dasd_eckd_basic_to_ready(struct dasd_device *device)
  1893. {
  1894. return dasd_alias_add_device(device);
  1895. };
  1896. static int dasd_eckd_online_to_ready(struct dasd_device *device)
  1897. {
  1898. cancel_work_sync(&device->reload_device);
  1899. cancel_work_sync(&device->kick_validate);
  1900. return 0;
  1901. };
  1902. static int dasd_eckd_basic_to_known(struct dasd_device *device)
  1903. {
  1904. return dasd_alias_remove_device(device);
  1905. };
  1906. static int
  1907. dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
  1908. {
  1909. struct dasd_eckd_private *private = block->base->private;
  1910. if (dasd_check_blocksize(block->bp_block) == 0) {
  1911. geo->sectors = recs_per_track(&private->rdc_data,
  1912. 0, block->bp_block);
  1913. }
  1914. geo->cylinders = private->rdc_data.no_cyl;
  1915. geo->heads = private->rdc_data.trk_per_cyl;
  1916. return 0;
  1917. }
  1918. /*
  1919. * Build the TCW request for the format check
  1920. */
  1921. static struct dasd_ccw_req *
  1922. dasd_eckd_build_check_tcw(struct dasd_device *base, struct format_data_t *fdata,
  1923. int enable_pav, struct eckd_count *fmt_buffer,
  1924. int rpt)
  1925. {
  1926. struct dasd_eckd_private *start_priv;
  1927. struct dasd_device *startdev = NULL;
  1928. struct tidaw *last_tidaw = NULL;
  1929. struct dasd_ccw_req *cqr;
  1930. struct itcw *itcw;
  1931. int itcw_size;
  1932. int count;
  1933. int rc;
  1934. int i;
  1935. if (enable_pav)
  1936. startdev = dasd_alias_get_start_dev(base);
  1937. if (!startdev)
  1938. startdev = base;
  1939. start_priv = startdev->private;
  1940. count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
  1941. /*
  1942. * we're adding 'count' amount of tidaw to the itcw.
  1943. * calculate the corresponding itcw_size
  1944. */
  1945. itcw_size = itcw_calc_size(0, count, 0);
  1946. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
  1947. if (IS_ERR(cqr))
  1948. return cqr;
  1949. start_priv->count++;
  1950. itcw = itcw_init(cqr->data, itcw_size, ITCW_OP_READ, 0, count, 0);
  1951. if (IS_ERR(itcw)) {
  1952. rc = -EINVAL;
  1953. goto out_err;
  1954. }
  1955. cqr->cpaddr = itcw_get_tcw(itcw);
  1956. rc = prepare_itcw(itcw, fdata->start_unit, fdata->stop_unit,
  1957. DASD_ECKD_CCW_READ_COUNT_MT, base, startdev, 0, count,
  1958. sizeof(struct eckd_count),
  1959. count * sizeof(struct eckd_count), 0, rpt);
  1960. if (rc)
  1961. goto out_err;
  1962. for (i = 0; i < count; i++) {
  1963. last_tidaw = itcw_add_tidaw(itcw, 0, fmt_buffer++,
  1964. sizeof(struct eckd_count));
  1965. if (IS_ERR(last_tidaw)) {
  1966. rc = -EINVAL;
  1967. goto out_err;
  1968. }
  1969. }
  1970. last_tidaw->flags |= TIDAW_FLAGS_LAST;
  1971. itcw_finalize(itcw);
  1972. cqr->cpmode = 1;
  1973. cqr->startdev = startdev;
  1974. cqr->memdev = startdev;
  1975. cqr->basedev = base;
  1976. cqr->retries = startdev->default_retries;
  1977. cqr->expires = startdev->default_expires * HZ;
  1978. cqr->buildclk = get_tod_clock();
  1979. cqr->status = DASD_CQR_FILLED;
  1980. /* Set flags to suppress output for expected errors */
  1981. set_bit(DASD_CQR_SUPPRESS_FP, &cqr->flags);
  1982. set_bit(DASD_CQR_SUPPRESS_IL, &cqr->flags);
  1983. return cqr;
  1984. out_err:
  1985. dasd_sfree_request(cqr, startdev);
  1986. return ERR_PTR(rc);
  1987. }
  1988. /*
  1989. * Build the CCW request for the format check
  1990. */
  1991. static struct dasd_ccw_req *
  1992. dasd_eckd_build_check(struct dasd_device *base, struct format_data_t *fdata,
  1993. int enable_pav, struct eckd_count *fmt_buffer, int rpt)
  1994. {
  1995. struct dasd_eckd_private *start_priv;
  1996. struct dasd_eckd_private *base_priv;
  1997. struct dasd_device *startdev = NULL;
  1998. struct dasd_ccw_req *cqr;
  1999. struct ccw1 *ccw;
  2000. void *data;
  2001. int cplength, datasize;
  2002. int use_prefix;
  2003. int count;
  2004. int i;
  2005. if (enable_pav)
  2006. startdev = dasd_alias_get_start_dev(base);
  2007. if (!startdev)
  2008. startdev = base;
  2009. start_priv = startdev->private;
  2010. base_priv = base->private;
  2011. count = rpt * (fdata->stop_unit - fdata->start_unit + 1);
  2012. use_prefix = base_priv->features.feature[8] & 0x01;
  2013. if (use_prefix) {
  2014. cplength = 1;
  2015. datasize = sizeof(struct PFX_eckd_data);
  2016. } else {
  2017. cplength = 2;
  2018. datasize = sizeof(struct DE_eckd_data) +
  2019. sizeof(struct LO_eckd_data);
  2020. }
  2021. cplength += count;
  2022. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
  2023. startdev);
  2024. if (IS_ERR(cqr))
  2025. return cqr;
  2026. start_priv->count++;
  2027. data = cqr->data;
  2028. ccw = cqr->cpaddr;
  2029. if (use_prefix) {
  2030. prefix_LRE(ccw++, data, fdata->start_unit, fdata->stop_unit,
  2031. DASD_ECKD_CCW_READ_COUNT, base, startdev, 1, 0,
  2032. count, 0, 0);
  2033. } else {
  2034. define_extent(ccw++, data, fdata->start_unit, fdata->stop_unit,
  2035. DASD_ECKD_CCW_READ_COUNT, startdev);
  2036. data += sizeof(struct DE_eckd_data);
  2037. ccw[-1].flags |= CCW_FLAG_CC;
  2038. locate_record(ccw++, data, fdata->start_unit, 0, count,
  2039. DASD_ECKD_CCW_READ_COUNT, base, 0);
  2040. }
  2041. for (i = 0; i < count; i++) {
  2042. ccw[-1].flags |= CCW_FLAG_CC;
  2043. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  2044. ccw->flags = CCW_FLAG_SLI;
  2045. ccw->count = 8;
  2046. ccw->cda = (__u32)(addr_t) fmt_buffer;
  2047. ccw++;
  2048. fmt_buffer++;
  2049. }
  2050. cqr->startdev = startdev;
  2051. cqr->memdev = startdev;
  2052. cqr->basedev = base;
  2053. cqr->retries = DASD_RETRIES;
  2054. cqr->expires = startdev->default_expires * HZ;
  2055. cqr->buildclk = get_tod_clock();
  2056. cqr->status = DASD_CQR_FILLED;
  2057. /* Set flags to suppress output for expected errors */
  2058. set_bit(DASD_CQR_SUPPRESS_NRF, &cqr->flags);
  2059. return cqr;
  2060. }
  2061. static struct dasd_ccw_req *
  2062. dasd_eckd_build_format(struct dasd_device *base,
  2063. struct format_data_t *fdata,
  2064. int enable_pav)
  2065. {
  2066. struct dasd_eckd_private *base_priv;
  2067. struct dasd_eckd_private *start_priv;
  2068. struct dasd_device *startdev = NULL;
  2069. struct dasd_ccw_req *fcp;
  2070. struct eckd_count *ect;
  2071. struct ch_t address;
  2072. struct ccw1 *ccw;
  2073. void *data;
  2074. int rpt;
  2075. int cplength, datasize;
  2076. int i, j;
  2077. int intensity = 0;
  2078. int r0_perm;
  2079. int nr_tracks;
  2080. int use_prefix;
  2081. if (enable_pav)
  2082. startdev = dasd_alias_get_start_dev(base);
  2083. if (!startdev)
  2084. startdev = base;
  2085. start_priv = startdev->private;
  2086. base_priv = base->private;
  2087. rpt = recs_per_track(&base_priv->rdc_data, 0, fdata->blksize);
  2088. nr_tracks = fdata->stop_unit - fdata->start_unit + 1;
  2089. /*
  2090. * fdata->intensity is a bit string that tells us what to do:
  2091. * Bit 0: write record zero
  2092. * Bit 1: write home address, currently not supported
  2093. * Bit 2: invalidate tracks
  2094. * Bit 3: use OS/390 compatible disk layout (cdl)
  2095. * Bit 4: do not allow storage subsystem to modify record zero
  2096. * Only some bit combinations do make sense.
  2097. */
  2098. if (fdata->intensity & 0x10) {
  2099. r0_perm = 0;
  2100. intensity = fdata->intensity & ~0x10;
  2101. } else {
  2102. r0_perm = 1;
  2103. intensity = fdata->intensity;
  2104. }
  2105. use_prefix = base_priv->features.feature[8] & 0x01;
  2106. switch (intensity) {
  2107. case 0x00: /* Normal format */
  2108. case 0x08: /* Normal format, use cdl. */
  2109. cplength = 2 + (rpt*nr_tracks);
  2110. if (use_prefix)
  2111. datasize = sizeof(struct PFX_eckd_data) +
  2112. sizeof(struct LO_eckd_data) +
  2113. rpt * nr_tracks * sizeof(struct eckd_count);
  2114. else
  2115. datasize = sizeof(struct DE_eckd_data) +
  2116. sizeof(struct LO_eckd_data) +
  2117. rpt * nr_tracks * sizeof(struct eckd_count);
  2118. break;
  2119. case 0x01: /* Write record zero and format track. */
  2120. case 0x09: /* Write record zero and format track, use cdl. */
  2121. cplength = 2 + rpt * nr_tracks;
  2122. if (use_prefix)
  2123. datasize = sizeof(struct PFX_eckd_data) +
  2124. sizeof(struct LO_eckd_data) +
  2125. sizeof(struct eckd_count) +
  2126. rpt * nr_tracks * sizeof(struct eckd_count);
  2127. else
  2128. datasize = sizeof(struct DE_eckd_data) +
  2129. sizeof(struct LO_eckd_data) +
  2130. sizeof(struct eckd_count) +
  2131. rpt * nr_tracks * sizeof(struct eckd_count);
  2132. break;
  2133. case 0x04: /* Invalidate track. */
  2134. case 0x0c: /* Invalidate track, use cdl. */
  2135. cplength = 3;
  2136. if (use_prefix)
  2137. datasize = sizeof(struct PFX_eckd_data) +
  2138. sizeof(struct LO_eckd_data) +
  2139. sizeof(struct eckd_count);
  2140. else
  2141. datasize = sizeof(struct DE_eckd_data) +
  2142. sizeof(struct LO_eckd_data) +
  2143. sizeof(struct eckd_count);
  2144. break;
  2145. default:
  2146. dev_warn(&startdev->cdev->dev,
  2147. "An I/O control call used incorrect flags 0x%x\n",
  2148. fdata->intensity);
  2149. return ERR_PTR(-EINVAL);
  2150. }
  2151. /* Allocate the format ccw request. */
  2152. fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
  2153. datasize, startdev);
  2154. if (IS_ERR(fcp))
  2155. return fcp;
  2156. start_priv->count++;
  2157. data = fcp->data;
  2158. ccw = fcp->cpaddr;
  2159. switch (intensity & ~0x08) {
  2160. case 0x00: /* Normal format. */
  2161. if (use_prefix) {
  2162. prefix(ccw++, (struct PFX_eckd_data *) data,
  2163. fdata->start_unit, fdata->stop_unit,
  2164. DASD_ECKD_CCW_WRITE_CKD, base, startdev);
  2165. /* grant subsystem permission to format R0 */
  2166. if (r0_perm)
  2167. ((struct PFX_eckd_data *)data)
  2168. ->define_extent.ga_extended |= 0x04;
  2169. data += sizeof(struct PFX_eckd_data);
  2170. } else {
  2171. define_extent(ccw++, (struct DE_eckd_data *) data,
  2172. fdata->start_unit, fdata->stop_unit,
  2173. DASD_ECKD_CCW_WRITE_CKD, startdev);
  2174. /* grant subsystem permission to format R0 */
  2175. if (r0_perm)
  2176. ((struct DE_eckd_data *) data)
  2177. ->ga_extended |= 0x04;
  2178. data += sizeof(struct DE_eckd_data);
  2179. }
  2180. ccw[-1].flags |= CCW_FLAG_CC;
  2181. locate_record(ccw++, (struct LO_eckd_data *) data,
  2182. fdata->start_unit, 0, rpt*nr_tracks,
  2183. DASD_ECKD_CCW_WRITE_CKD, base,
  2184. fdata->blksize);
  2185. data += sizeof(struct LO_eckd_data);
  2186. break;
  2187. case 0x01: /* Write record zero + format track. */
  2188. if (use_prefix) {
  2189. prefix(ccw++, (struct PFX_eckd_data *) data,
  2190. fdata->start_unit, fdata->stop_unit,
  2191. DASD_ECKD_CCW_WRITE_RECORD_ZERO,
  2192. base, startdev);
  2193. data += sizeof(struct PFX_eckd_data);
  2194. } else {
  2195. define_extent(ccw++, (struct DE_eckd_data *) data,
  2196. fdata->start_unit, fdata->stop_unit,
  2197. DASD_ECKD_CCW_WRITE_RECORD_ZERO, startdev);
  2198. data += sizeof(struct DE_eckd_data);
  2199. }
  2200. ccw[-1].flags |= CCW_FLAG_CC;
  2201. locate_record(ccw++, (struct LO_eckd_data *) data,
  2202. fdata->start_unit, 0, rpt * nr_tracks + 1,
  2203. DASD_ECKD_CCW_WRITE_RECORD_ZERO, base,
  2204. base->block->bp_block);
  2205. data += sizeof(struct LO_eckd_data);
  2206. break;
  2207. case 0x04: /* Invalidate track. */
  2208. if (use_prefix) {
  2209. prefix(ccw++, (struct PFX_eckd_data *) data,
  2210. fdata->start_unit, fdata->stop_unit,
  2211. DASD_ECKD_CCW_WRITE_CKD, base, startdev);
  2212. data += sizeof(struct PFX_eckd_data);
  2213. } else {
  2214. define_extent(ccw++, (struct DE_eckd_data *) data,
  2215. fdata->start_unit, fdata->stop_unit,
  2216. DASD_ECKD_CCW_WRITE_CKD, startdev);
  2217. data += sizeof(struct DE_eckd_data);
  2218. }
  2219. ccw[-1].flags |= CCW_FLAG_CC;
  2220. locate_record(ccw++, (struct LO_eckd_data *) data,
  2221. fdata->start_unit, 0, 1,
  2222. DASD_ECKD_CCW_WRITE_CKD, base, 8);
  2223. data += sizeof(struct LO_eckd_data);
  2224. break;
  2225. }
  2226. for (j = 0; j < nr_tracks; j++) {
  2227. /* calculate cylinder and head for the current track */
  2228. set_ch_t(&address,
  2229. (fdata->start_unit + j) /
  2230. base_priv->rdc_data.trk_per_cyl,
  2231. (fdata->start_unit + j) %
  2232. base_priv->rdc_data.trk_per_cyl);
  2233. if (intensity & 0x01) { /* write record zero */
  2234. ect = (struct eckd_count *) data;
  2235. data += sizeof(struct eckd_count);
  2236. ect->cyl = address.cyl;
  2237. ect->head = address.head;
  2238. ect->record = 0;
  2239. ect->kl = 0;
  2240. ect->dl = 8;
  2241. ccw[-1].flags |= CCW_FLAG_CC;
  2242. ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
  2243. ccw->flags = CCW_FLAG_SLI;
  2244. ccw->count = 8;
  2245. ccw->cda = (__u32)(addr_t) ect;
  2246. ccw++;
  2247. }
  2248. if ((intensity & ~0x08) & 0x04) { /* erase track */
  2249. ect = (struct eckd_count *) data;
  2250. data += sizeof(struct eckd_count);
  2251. ect->cyl = address.cyl;
  2252. ect->head = address.head;
  2253. ect->record = 1;
  2254. ect->kl = 0;
  2255. ect->dl = 0;
  2256. ccw[-1].flags |= CCW_FLAG_CC;
  2257. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  2258. ccw->flags = CCW_FLAG_SLI;
  2259. ccw->count = 8;
  2260. ccw->cda = (__u32)(addr_t) ect;
  2261. } else { /* write remaining records */
  2262. for (i = 0; i < rpt; i++) {
  2263. ect = (struct eckd_count *) data;
  2264. data += sizeof(struct eckd_count);
  2265. ect->cyl = address.cyl;
  2266. ect->head = address.head;
  2267. ect->record = i + 1;
  2268. ect->kl = 0;
  2269. ect->dl = fdata->blksize;
  2270. /*
  2271. * Check for special tracks 0-1
  2272. * when formatting CDL
  2273. */
  2274. if ((intensity & 0x08) &&
  2275. address.cyl == 0 && address.head == 0) {
  2276. if (i < 3) {
  2277. ect->kl = 4;
  2278. ect->dl = sizes_trk0[i] - 4;
  2279. }
  2280. }
  2281. if ((intensity & 0x08) &&
  2282. address.cyl == 0 && address.head == 1) {
  2283. ect->kl = 44;
  2284. ect->dl = LABEL_SIZE - 44;
  2285. }
  2286. ccw[-1].flags |= CCW_FLAG_CC;
  2287. if (i != 0 || j == 0)
  2288. ccw->cmd_code =
  2289. DASD_ECKD_CCW_WRITE_CKD;
  2290. else
  2291. ccw->cmd_code =
  2292. DASD_ECKD_CCW_WRITE_CKD_MT;
  2293. ccw->flags = CCW_FLAG_SLI;
  2294. ccw->count = 8;
  2295. ccw->cda = (__u32)(addr_t) ect;
  2296. ccw++;
  2297. }
  2298. }
  2299. }
  2300. fcp->startdev = startdev;
  2301. fcp->memdev = startdev;
  2302. fcp->basedev = base;
  2303. fcp->retries = 256;
  2304. fcp->expires = startdev->default_expires * HZ;
  2305. fcp->buildclk = get_tod_clock();
  2306. fcp->status = DASD_CQR_FILLED;
  2307. return fcp;
  2308. }
  2309. /*
  2310. * Wrapper function to build a CCW request depending on input data
  2311. */
  2312. static struct dasd_ccw_req *
  2313. dasd_eckd_format_build_ccw_req(struct dasd_device *base,
  2314. struct format_data_t *fdata, int enable_pav,
  2315. int tpm, struct eckd_count *fmt_buffer, int rpt)
  2316. {
  2317. struct dasd_ccw_req *ccw_req;
  2318. if (!fmt_buffer) {
  2319. ccw_req = dasd_eckd_build_format(base, fdata, enable_pav);
  2320. } else {
  2321. if (tpm)
  2322. ccw_req = dasd_eckd_build_check_tcw(base, fdata,
  2323. enable_pav,
  2324. fmt_buffer, rpt);
  2325. else
  2326. ccw_req = dasd_eckd_build_check(base, fdata, enable_pav,
  2327. fmt_buffer, rpt);
  2328. }
  2329. return ccw_req;
  2330. }
  2331. /*
  2332. * Sanity checks on format_data
  2333. */
  2334. static int dasd_eckd_format_sanity_checks(struct dasd_device *base,
  2335. struct format_data_t *fdata)
  2336. {
  2337. struct dasd_eckd_private *private = base->private;
  2338. if (fdata->start_unit >=
  2339. (private->real_cyl * private->rdc_data.trk_per_cyl)) {
  2340. dev_warn(&base->cdev->dev,
  2341. "Start track number %u used in formatting is too big\n",
  2342. fdata->start_unit);
  2343. return -EINVAL;
  2344. }
  2345. if (fdata->stop_unit >=
  2346. (private->real_cyl * private->rdc_data.trk_per_cyl)) {
  2347. dev_warn(&base->cdev->dev,
  2348. "Stop track number %u used in formatting is too big\n",
  2349. fdata->stop_unit);
  2350. return -EINVAL;
  2351. }
  2352. if (fdata->start_unit > fdata->stop_unit) {
  2353. dev_warn(&base->cdev->dev,
  2354. "Start track %u used in formatting exceeds end track\n",
  2355. fdata->start_unit);
  2356. return -EINVAL;
  2357. }
  2358. if (dasd_check_blocksize(fdata->blksize) != 0) {
  2359. dev_warn(&base->cdev->dev,
  2360. "The DASD cannot be formatted with block size %u\n",
  2361. fdata->blksize);
  2362. return -EINVAL;
  2363. }
  2364. return 0;
  2365. }
  2366. /*
  2367. * This function will process format_data originally coming from an IOCTL
  2368. */
  2369. static int dasd_eckd_format_process_data(struct dasd_device *base,
  2370. struct format_data_t *fdata,
  2371. int enable_pav, int tpm,
  2372. struct eckd_count *fmt_buffer, int rpt,
  2373. struct irb *irb)
  2374. {
  2375. struct dasd_eckd_private *private = base->private;
  2376. struct dasd_ccw_req *cqr, *n;
  2377. struct list_head format_queue;
  2378. struct dasd_device *device;
  2379. char *sense = NULL;
  2380. int old_start, old_stop, format_step;
  2381. int step, retry;
  2382. int rc;
  2383. rc = dasd_eckd_format_sanity_checks(base, fdata);
  2384. if (rc)
  2385. return rc;
  2386. INIT_LIST_HEAD(&format_queue);
  2387. old_start = fdata->start_unit;
  2388. old_stop = fdata->stop_unit;
  2389. if (!tpm && fmt_buffer != NULL) {
  2390. /* Command Mode / Format Check */
  2391. format_step = 1;
  2392. } else if (tpm && fmt_buffer != NULL) {
  2393. /* Transport Mode / Format Check */
  2394. format_step = DASD_CQR_MAX_CCW / rpt;
  2395. } else {
  2396. /* Normal Formatting */
  2397. format_step = DASD_CQR_MAX_CCW /
  2398. recs_per_track(&private->rdc_data, 0, fdata->blksize);
  2399. }
  2400. do {
  2401. retry = 0;
  2402. while (fdata->start_unit <= old_stop) {
  2403. step = fdata->stop_unit - fdata->start_unit + 1;
  2404. if (step > format_step) {
  2405. fdata->stop_unit =
  2406. fdata->start_unit + format_step - 1;
  2407. }
  2408. cqr = dasd_eckd_format_build_ccw_req(base, fdata,
  2409. enable_pav, tpm,
  2410. fmt_buffer, rpt);
  2411. if (IS_ERR(cqr)) {
  2412. rc = PTR_ERR(cqr);
  2413. if (rc == -ENOMEM) {
  2414. if (list_empty(&format_queue))
  2415. goto out;
  2416. /*
  2417. * not enough memory available, start
  2418. * requests retry after first requests
  2419. * were finished
  2420. */
  2421. retry = 1;
  2422. break;
  2423. }
  2424. goto out_err;
  2425. }
  2426. list_add_tail(&cqr->blocklist, &format_queue);
  2427. if (fmt_buffer) {
  2428. step = fdata->stop_unit - fdata->start_unit + 1;
  2429. fmt_buffer += rpt * step;
  2430. }
  2431. fdata->start_unit = fdata->stop_unit + 1;
  2432. fdata->stop_unit = old_stop;
  2433. }
  2434. rc = dasd_sleep_on_queue(&format_queue);
  2435. out_err:
  2436. list_for_each_entry_safe(cqr, n, &format_queue, blocklist) {
  2437. device = cqr->startdev;
  2438. private = device->private;
  2439. if (cqr->status == DASD_CQR_FAILED) {
  2440. /*
  2441. * Only get sense data if called by format
  2442. * check
  2443. */
  2444. if (fmt_buffer && irb) {
  2445. sense = dasd_get_sense(&cqr->irb);
  2446. memcpy(irb, &cqr->irb, sizeof(*irb));
  2447. }
  2448. rc = -EIO;
  2449. }
  2450. list_del_init(&cqr->blocklist);
  2451. dasd_sfree_request(cqr, device);
  2452. private->count--;
  2453. }
  2454. if (rc && rc != -EIO)
  2455. goto out;
  2456. if (rc == -EIO) {
  2457. /*
  2458. * In case fewer than the expected records are on the
  2459. * track, we will most likely get a 'No Record Found'
  2460. * error (in command mode) or a 'File Protected' error
  2461. * (in transport mode). Those particular cases shouldn't
  2462. * pass the -EIO to the IOCTL, therefore reset the rc
  2463. * and continue.
  2464. */
  2465. if (sense &&
  2466. (sense[1] & SNS1_NO_REC_FOUND ||
  2467. sense[1] & SNS1_FILE_PROTECTED))
  2468. retry = 1;
  2469. else
  2470. goto out;
  2471. }
  2472. } while (retry);
  2473. out:
  2474. fdata->start_unit = old_start;
  2475. fdata->stop_unit = old_stop;
  2476. return rc;
  2477. }
  2478. static int dasd_eckd_format_device(struct dasd_device *base,
  2479. struct format_data_t *fdata, int enable_pav)
  2480. {
  2481. return dasd_eckd_format_process_data(base, fdata, enable_pav, 0, NULL,
  2482. 0, NULL);
  2483. }
  2484. /*
  2485. * Helper function to count consecutive records of a single track.
  2486. */
  2487. static int dasd_eckd_count_records(struct eckd_count *fmt_buffer, int start,
  2488. int max)
  2489. {
  2490. int head;
  2491. int i;
  2492. head = fmt_buffer[start].head;
  2493. /*
  2494. * There are 3 conditions where we stop counting:
  2495. * - if data reoccurs (same head and record may reoccur), which may
  2496. * happen due to the way DASD_ECKD_CCW_READ_COUNT works
  2497. * - when the head changes, because we're iterating over several tracks
  2498. * then (DASD_ECKD_CCW_READ_COUNT_MT)
  2499. * - when we've reached the end of sensible data in the buffer (the
  2500. * record will be 0 then)
  2501. */
  2502. for (i = start; i < max; i++) {
  2503. if (i > start) {
  2504. if ((fmt_buffer[i].head == head &&
  2505. fmt_buffer[i].record == 1) ||
  2506. fmt_buffer[i].head != head ||
  2507. fmt_buffer[i].record == 0)
  2508. break;
  2509. }
  2510. }
  2511. return i - start;
  2512. }
  2513. /*
  2514. * Evaluate a given range of tracks. Data like number of records, blocksize,
  2515. * record ids, and key length are compared with expected data.
  2516. *
  2517. * If a mismatch occurs, the corresponding error bit is set, as well as
  2518. * additional information, depending on the error.
  2519. */
  2520. static void dasd_eckd_format_evaluate_tracks(struct eckd_count *fmt_buffer,
  2521. struct format_check_t *cdata,
  2522. int rpt_max, int rpt_exp,
  2523. int trk_per_cyl, int tpm)
  2524. {
  2525. struct ch_t geo;
  2526. int max_entries;
  2527. int count = 0;
  2528. int trkcount;
  2529. int blksize;
  2530. int pos = 0;
  2531. int i, j;
  2532. int kl;
  2533. trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
  2534. max_entries = trkcount * rpt_max;
  2535. for (i = cdata->expect.start_unit; i <= cdata->expect.stop_unit; i++) {
  2536. /* Calculate the correct next starting position in the buffer */
  2537. if (tpm) {
  2538. while (fmt_buffer[pos].record == 0 &&
  2539. fmt_buffer[pos].dl == 0) {
  2540. if (pos++ > max_entries)
  2541. break;
  2542. }
  2543. } else {
  2544. if (i != cdata->expect.start_unit)
  2545. pos += rpt_max - count;
  2546. }
  2547. /* Calculate the expected geo values for the current track */
  2548. set_ch_t(&geo, i / trk_per_cyl, i % trk_per_cyl);
  2549. /* Count and check number of records */
  2550. count = dasd_eckd_count_records(fmt_buffer, pos, pos + rpt_max);
  2551. if (count < rpt_exp) {
  2552. cdata->result = DASD_FMT_ERR_TOO_FEW_RECORDS;
  2553. break;
  2554. }
  2555. if (count > rpt_exp) {
  2556. cdata->result = DASD_FMT_ERR_TOO_MANY_RECORDS;
  2557. break;
  2558. }
  2559. for (j = 0; j < count; j++, pos++) {
  2560. blksize = cdata->expect.blksize;
  2561. kl = 0;
  2562. /*
  2563. * Set special values when checking CDL formatted
  2564. * devices.
  2565. */
  2566. if ((cdata->expect.intensity & 0x08) &&
  2567. geo.cyl == 0 && geo.head == 0) {
  2568. if (j < 3) {
  2569. blksize = sizes_trk0[j] - 4;
  2570. kl = 4;
  2571. }
  2572. }
  2573. if ((cdata->expect.intensity & 0x08) &&
  2574. geo.cyl == 0 && geo.head == 1) {
  2575. blksize = LABEL_SIZE - 44;
  2576. kl = 44;
  2577. }
  2578. /* Check blocksize */
  2579. if (fmt_buffer[pos].dl != blksize) {
  2580. cdata->result = DASD_FMT_ERR_BLKSIZE;
  2581. goto out;
  2582. }
  2583. /* Check if key length is 0 */
  2584. if (fmt_buffer[pos].kl != kl) {
  2585. cdata->result = DASD_FMT_ERR_KEY_LENGTH;
  2586. goto out;
  2587. }
  2588. /* Check if record_id is correct */
  2589. if (fmt_buffer[pos].cyl != geo.cyl ||
  2590. fmt_buffer[pos].head != geo.head ||
  2591. fmt_buffer[pos].record != (j + 1)) {
  2592. cdata->result = DASD_FMT_ERR_RECORD_ID;
  2593. goto out;
  2594. }
  2595. }
  2596. }
  2597. out:
  2598. /*
  2599. * In case of no errors, we need to decrease by one
  2600. * to get the correct positions.
  2601. */
  2602. if (!cdata->result) {
  2603. i--;
  2604. pos--;
  2605. }
  2606. cdata->unit = i;
  2607. cdata->num_records = count;
  2608. cdata->rec = fmt_buffer[pos].record;
  2609. cdata->blksize = fmt_buffer[pos].dl;
  2610. cdata->key_length = fmt_buffer[pos].kl;
  2611. }
  2612. /*
  2613. * Check the format of a range of tracks of a DASD.
  2614. */
  2615. static int dasd_eckd_check_device_format(struct dasd_device *base,
  2616. struct format_check_t *cdata,
  2617. int enable_pav)
  2618. {
  2619. struct dasd_eckd_private *private = base->private;
  2620. struct eckd_count *fmt_buffer;
  2621. struct irb irb;
  2622. int rpt_max, rpt_exp;
  2623. int fmt_buffer_size;
  2624. int trk_per_cyl;
  2625. int trkcount;
  2626. int tpm = 0;
  2627. int rc;
  2628. trk_per_cyl = private->rdc_data.trk_per_cyl;
  2629. /* Get maximum and expected amount of records per track */
  2630. rpt_max = recs_per_track(&private->rdc_data, 0, 512) + 1;
  2631. rpt_exp = recs_per_track(&private->rdc_data, 0, cdata->expect.blksize);
  2632. trkcount = cdata->expect.stop_unit - cdata->expect.start_unit + 1;
  2633. fmt_buffer_size = trkcount * rpt_max * sizeof(struct eckd_count);
  2634. fmt_buffer = kzalloc(fmt_buffer_size, GFP_KERNEL | GFP_DMA);
  2635. if (!fmt_buffer)
  2636. return -ENOMEM;
  2637. /*
  2638. * A certain FICON feature subset is needed to operate in transport
  2639. * mode. Additionally, the support for transport mode is implicitly
  2640. * checked by comparing the buffer size with fcx_max_data. As long as
  2641. * the buffer size is smaller we can operate in transport mode and
  2642. * process multiple tracks. If not, only one track at once is being
  2643. * processed using command mode.
  2644. */
  2645. if ((private->features.feature[40] & 0x04) &&
  2646. fmt_buffer_size <= private->fcx_max_data)
  2647. tpm = 1;
  2648. rc = dasd_eckd_format_process_data(base, &cdata->expect, enable_pav,
  2649. tpm, fmt_buffer, rpt_max, &irb);
  2650. if (rc && rc != -EIO)
  2651. goto out;
  2652. if (rc == -EIO) {
  2653. /*
  2654. * If our first attempt with transport mode enabled comes back
  2655. * with an incorrect length error, we're going to retry the
  2656. * check with command mode.
  2657. */
  2658. if (tpm && scsw_cstat(&irb.scsw) == 0x40) {
  2659. tpm = 0;
  2660. rc = dasd_eckd_format_process_data(base, &cdata->expect,
  2661. enable_pav, tpm,
  2662. fmt_buffer, rpt_max,
  2663. &irb);
  2664. if (rc)
  2665. goto out;
  2666. } else {
  2667. goto out;
  2668. }
  2669. }
  2670. dasd_eckd_format_evaluate_tracks(fmt_buffer, cdata, rpt_max, rpt_exp,
  2671. trk_per_cyl, tpm);
  2672. out:
  2673. kfree(fmt_buffer);
  2674. return rc;
  2675. }
  2676. static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
  2677. {
  2678. if (cqr->retries < 0) {
  2679. cqr->status = DASD_CQR_FAILED;
  2680. return;
  2681. }
  2682. cqr->status = DASD_CQR_FILLED;
  2683. if (cqr->block && (cqr->startdev != cqr->block->base)) {
  2684. dasd_eckd_reset_ccw_to_base_io(cqr);
  2685. cqr->startdev = cqr->block->base;
  2686. cqr->lpm = cqr->block->base->path_data.opm;
  2687. }
  2688. };
  2689. static dasd_erp_fn_t
  2690. dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
  2691. {
  2692. struct dasd_device *device = (struct dasd_device *) cqr->startdev;
  2693. struct ccw_device *cdev = device->cdev;
  2694. switch (cdev->id.cu_type) {
  2695. case 0x3990:
  2696. case 0x2105:
  2697. case 0x2107:
  2698. case 0x1750:
  2699. return dasd_3990_erp_action;
  2700. case 0x9343:
  2701. case 0x3880:
  2702. default:
  2703. return dasd_default_erp_action;
  2704. }
  2705. }
  2706. static dasd_erp_fn_t
  2707. dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
  2708. {
  2709. return dasd_default_erp_postaction;
  2710. }
  2711. static void dasd_eckd_check_for_device_change(struct dasd_device *device,
  2712. struct dasd_ccw_req *cqr,
  2713. struct irb *irb)
  2714. {
  2715. char mask;
  2716. char *sense = NULL;
  2717. struct dasd_eckd_private *private = device->private;
  2718. /* first of all check for state change pending interrupt */
  2719. mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
  2720. if ((scsw_dstat(&irb->scsw) & mask) == mask) {
  2721. /*
  2722. * for alias only, not in offline processing
  2723. * and only if not suspended
  2724. */
  2725. if (!device->block && private->lcu &&
  2726. device->state == DASD_STATE_ONLINE &&
  2727. !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
  2728. !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
  2729. /* schedule worker to reload device */
  2730. dasd_reload_device(device);
  2731. }
  2732. dasd_generic_handle_state_change(device);
  2733. return;
  2734. }
  2735. sense = dasd_get_sense(irb);
  2736. if (!sense)
  2737. return;
  2738. /* summary unit check */
  2739. if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
  2740. (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
  2741. if (test_and_set_bit(DASD_FLAG_SUC, &device->flags)) {
  2742. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  2743. "eckd suc: device already notified");
  2744. return;
  2745. }
  2746. sense = dasd_get_sense(irb);
  2747. if (!sense) {
  2748. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  2749. "eckd suc: no reason code available");
  2750. clear_bit(DASD_FLAG_SUC, &device->flags);
  2751. return;
  2752. }
  2753. private->suc_reason = sense[8];
  2754. DBF_DEV_EVENT(DBF_NOTICE, device, "%s %x",
  2755. "eckd handle summary unit check: reason",
  2756. private->suc_reason);
  2757. dasd_get_device(device);
  2758. if (!schedule_work(&device->suc_work))
  2759. dasd_put_device(device);
  2760. return;
  2761. }
  2762. /* service information message SIM */
  2763. if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
  2764. ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
  2765. dasd_3990_erp_handle_sim(device, sense);
  2766. return;
  2767. }
  2768. /* loss of device reservation is handled via base devices only
  2769. * as alias devices may be used with several bases
  2770. */
  2771. if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
  2772. (sense[7] == 0x3F) &&
  2773. (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
  2774. test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
  2775. if (device->features & DASD_FEATURE_FAILONSLCK)
  2776. set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
  2777. clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  2778. dev_err(&device->cdev->dev,
  2779. "The device reservation was lost\n");
  2780. }
  2781. }
  2782. static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
  2783. struct dasd_device *startdev,
  2784. struct dasd_block *block,
  2785. struct request *req,
  2786. sector_t first_rec,
  2787. sector_t last_rec,
  2788. sector_t first_trk,
  2789. sector_t last_trk,
  2790. unsigned int first_offs,
  2791. unsigned int last_offs,
  2792. unsigned int blk_per_trk,
  2793. unsigned int blksize)
  2794. {
  2795. struct dasd_eckd_private *private;
  2796. unsigned long *idaws;
  2797. struct LO_eckd_data *LO_data;
  2798. struct dasd_ccw_req *cqr;
  2799. struct ccw1 *ccw;
  2800. struct req_iterator iter;
  2801. struct bio_vec bv;
  2802. char *dst;
  2803. unsigned int off;
  2804. int count, cidaw, cplength, datasize;
  2805. sector_t recid;
  2806. unsigned char cmd, rcmd;
  2807. int use_prefix;
  2808. struct dasd_device *basedev;
  2809. basedev = block->base;
  2810. private = basedev->private;
  2811. if (rq_data_dir(req) == READ)
  2812. cmd = DASD_ECKD_CCW_READ_MT;
  2813. else if (rq_data_dir(req) == WRITE)
  2814. cmd = DASD_ECKD_CCW_WRITE_MT;
  2815. else
  2816. return ERR_PTR(-EINVAL);
  2817. /* Check struct bio and count the number of blocks for the request. */
  2818. count = 0;
  2819. cidaw = 0;
  2820. rq_for_each_segment(bv, req, iter) {
  2821. if (bv.bv_len & (blksize - 1))
  2822. /* Eckd can only do full blocks. */
  2823. return ERR_PTR(-EINVAL);
  2824. count += bv.bv_len >> (block->s2b_shift + 9);
  2825. if (idal_is_needed (page_address(bv.bv_page), bv.bv_len))
  2826. cidaw += bv.bv_len >> (block->s2b_shift + 9);
  2827. }
  2828. /* Paranoia. */
  2829. if (count != last_rec - first_rec + 1)
  2830. return ERR_PTR(-EINVAL);
  2831. /* use the prefix command if available */
  2832. use_prefix = private->features.feature[8] & 0x01;
  2833. if (use_prefix) {
  2834. /* 1x prefix + number of blocks */
  2835. cplength = 2 + count;
  2836. /* 1x prefix + cidaws*sizeof(long) */
  2837. datasize = sizeof(struct PFX_eckd_data) +
  2838. sizeof(struct LO_eckd_data) +
  2839. cidaw * sizeof(unsigned long);
  2840. } else {
  2841. /* 1x define extent + 1x locate record + number of blocks */
  2842. cplength = 2 + count;
  2843. /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
  2844. datasize = sizeof(struct DE_eckd_data) +
  2845. sizeof(struct LO_eckd_data) +
  2846. cidaw * sizeof(unsigned long);
  2847. }
  2848. /* Find out the number of additional locate record ccws for cdl. */
  2849. if (private->uses_cdl && first_rec < 2*blk_per_trk) {
  2850. if (last_rec >= 2*blk_per_trk)
  2851. count = 2*blk_per_trk - first_rec;
  2852. cplength += count;
  2853. datasize += count*sizeof(struct LO_eckd_data);
  2854. }
  2855. /* Allocate the ccw request. */
  2856. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
  2857. startdev);
  2858. if (IS_ERR(cqr))
  2859. return cqr;
  2860. ccw = cqr->cpaddr;
  2861. /* First ccw is define extent or prefix. */
  2862. if (use_prefix) {
  2863. if (prefix(ccw++, cqr->data, first_trk,
  2864. last_trk, cmd, basedev, startdev) == -EAGAIN) {
  2865. /* Clock not in sync and XRC is enabled.
  2866. * Try again later.
  2867. */
  2868. dasd_sfree_request(cqr, startdev);
  2869. return ERR_PTR(-EAGAIN);
  2870. }
  2871. idaws = (unsigned long *) (cqr->data +
  2872. sizeof(struct PFX_eckd_data));
  2873. } else {
  2874. if (define_extent(ccw++, cqr->data, first_trk,
  2875. last_trk, cmd, basedev) == -EAGAIN) {
  2876. /* Clock not in sync and XRC is enabled.
  2877. * Try again later.
  2878. */
  2879. dasd_sfree_request(cqr, startdev);
  2880. return ERR_PTR(-EAGAIN);
  2881. }
  2882. idaws = (unsigned long *) (cqr->data +
  2883. sizeof(struct DE_eckd_data));
  2884. }
  2885. /* Build locate_record+read/write/ccws. */
  2886. LO_data = (struct LO_eckd_data *) (idaws + cidaw);
  2887. recid = first_rec;
  2888. if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
  2889. /* Only standard blocks so there is just one locate record. */
  2890. ccw[-1].flags |= CCW_FLAG_CC;
  2891. locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
  2892. last_rec - recid + 1, cmd, basedev, blksize);
  2893. }
  2894. rq_for_each_segment(bv, req, iter) {
  2895. dst = page_address(bv.bv_page) + bv.bv_offset;
  2896. if (dasd_page_cache) {
  2897. char *copy = kmem_cache_alloc(dasd_page_cache,
  2898. GFP_DMA | __GFP_NOWARN);
  2899. if (copy && rq_data_dir(req) == WRITE)
  2900. memcpy(copy + bv.bv_offset, dst, bv.bv_len);
  2901. if (copy)
  2902. dst = copy + bv.bv_offset;
  2903. }
  2904. for (off = 0; off < bv.bv_len; off += blksize) {
  2905. sector_t trkid = recid;
  2906. unsigned int recoffs = sector_div(trkid, blk_per_trk);
  2907. rcmd = cmd;
  2908. count = blksize;
  2909. /* Locate record for cdl special block ? */
  2910. if (private->uses_cdl && recid < 2*blk_per_trk) {
  2911. if (dasd_eckd_cdl_special(blk_per_trk, recid)){
  2912. rcmd |= 0x8;
  2913. count = dasd_eckd_cdl_reclen(recid);
  2914. if (count < blksize &&
  2915. rq_data_dir(req) == READ)
  2916. memset(dst + count, 0xe5,
  2917. blksize - count);
  2918. }
  2919. ccw[-1].flags |= CCW_FLAG_CC;
  2920. locate_record(ccw++, LO_data++,
  2921. trkid, recoffs + 1,
  2922. 1, rcmd, basedev, count);
  2923. }
  2924. /* Locate record for standard blocks ? */
  2925. if (private->uses_cdl && recid == 2*blk_per_trk) {
  2926. ccw[-1].flags |= CCW_FLAG_CC;
  2927. locate_record(ccw++, LO_data++,
  2928. trkid, recoffs + 1,
  2929. last_rec - recid + 1,
  2930. cmd, basedev, count);
  2931. }
  2932. /* Read/write ccw. */
  2933. ccw[-1].flags |= CCW_FLAG_CC;
  2934. ccw->cmd_code = rcmd;
  2935. ccw->count = count;
  2936. if (idal_is_needed(dst, blksize)) {
  2937. ccw->cda = (__u32)(addr_t) idaws;
  2938. ccw->flags = CCW_FLAG_IDA;
  2939. idaws = idal_create_words(idaws, dst, blksize);
  2940. } else {
  2941. ccw->cda = (__u32)(addr_t) dst;
  2942. ccw->flags = 0;
  2943. }
  2944. ccw++;
  2945. dst += blksize;
  2946. recid++;
  2947. }
  2948. }
  2949. if (blk_noretry_request(req) ||
  2950. block->base->features & DASD_FEATURE_FAILFAST)
  2951. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2952. cqr->startdev = startdev;
  2953. cqr->memdev = startdev;
  2954. cqr->block = block;
  2955. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  2956. cqr->lpm = startdev->path_data.ppm;
  2957. cqr->retries = startdev->default_retries;
  2958. cqr->buildclk = get_tod_clock();
  2959. cqr->status = DASD_CQR_FILLED;
  2960. return cqr;
  2961. }
  2962. static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
  2963. struct dasd_device *startdev,
  2964. struct dasd_block *block,
  2965. struct request *req,
  2966. sector_t first_rec,
  2967. sector_t last_rec,
  2968. sector_t first_trk,
  2969. sector_t last_trk,
  2970. unsigned int first_offs,
  2971. unsigned int last_offs,
  2972. unsigned int blk_per_trk,
  2973. unsigned int blksize)
  2974. {
  2975. unsigned long *idaws;
  2976. struct dasd_ccw_req *cqr;
  2977. struct ccw1 *ccw;
  2978. struct req_iterator iter;
  2979. struct bio_vec bv;
  2980. char *dst, *idaw_dst;
  2981. unsigned int cidaw, cplength, datasize;
  2982. unsigned int tlf;
  2983. sector_t recid;
  2984. unsigned char cmd;
  2985. struct dasd_device *basedev;
  2986. unsigned int trkcount, count, count_to_trk_end;
  2987. unsigned int idaw_len, seg_len, part_len, len_to_track_end;
  2988. unsigned char new_track, end_idaw;
  2989. sector_t trkid;
  2990. unsigned int recoffs;
  2991. basedev = block->base;
  2992. if (rq_data_dir(req) == READ)
  2993. cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
  2994. else if (rq_data_dir(req) == WRITE)
  2995. cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
  2996. else
  2997. return ERR_PTR(-EINVAL);
  2998. /* Track based I/O needs IDAWs for each page, and not just for
  2999. * 64 bit addresses. We need additional idals for pages
  3000. * that get filled from two tracks, so we use the number
  3001. * of records as upper limit.
  3002. */
  3003. cidaw = last_rec - first_rec + 1;
  3004. trkcount = last_trk - first_trk + 1;
  3005. /* 1x prefix + one read/write ccw per track */
  3006. cplength = 1 + trkcount;
  3007. /* on 31-bit we need space for two 32 bit addresses per page
  3008. * on 64-bit one 64 bit address
  3009. */
  3010. datasize = sizeof(struct PFX_eckd_data) +
  3011. cidaw * sizeof(unsigned long long);
  3012. /* Allocate the ccw request. */
  3013. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
  3014. startdev);
  3015. if (IS_ERR(cqr))
  3016. return cqr;
  3017. ccw = cqr->cpaddr;
  3018. /* transfer length factor: how many bytes to read from the last track */
  3019. if (first_trk == last_trk)
  3020. tlf = last_offs - first_offs + 1;
  3021. else
  3022. tlf = last_offs + 1;
  3023. tlf *= blksize;
  3024. if (prefix_LRE(ccw++, cqr->data, first_trk,
  3025. last_trk, cmd, basedev, startdev,
  3026. 1 /* format */, first_offs + 1,
  3027. trkcount, blksize,
  3028. tlf) == -EAGAIN) {
  3029. /* Clock not in sync and XRC is enabled.
  3030. * Try again later.
  3031. */
  3032. dasd_sfree_request(cqr, startdev);
  3033. return ERR_PTR(-EAGAIN);
  3034. }
  3035. /*
  3036. * The translation of request into ccw programs must meet the
  3037. * following conditions:
  3038. * - all idaws but the first and the last must address full pages
  3039. * (or 2K blocks on 31-bit)
  3040. * - the scope of a ccw and it's idal ends with the track boundaries
  3041. */
  3042. idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
  3043. recid = first_rec;
  3044. new_track = 1;
  3045. end_idaw = 0;
  3046. len_to_track_end = 0;
  3047. idaw_dst = NULL;
  3048. idaw_len = 0;
  3049. rq_for_each_segment(bv, req, iter) {
  3050. dst = page_address(bv.bv_page) + bv.bv_offset;
  3051. seg_len = bv.bv_len;
  3052. while (seg_len) {
  3053. if (new_track) {
  3054. trkid = recid;
  3055. recoffs = sector_div(trkid, blk_per_trk);
  3056. count_to_trk_end = blk_per_trk - recoffs;
  3057. count = min((last_rec - recid + 1),
  3058. (sector_t)count_to_trk_end);
  3059. len_to_track_end = count * blksize;
  3060. ccw[-1].flags |= CCW_FLAG_CC;
  3061. ccw->cmd_code = cmd;
  3062. ccw->count = len_to_track_end;
  3063. ccw->cda = (__u32)(addr_t)idaws;
  3064. ccw->flags = CCW_FLAG_IDA;
  3065. ccw++;
  3066. recid += count;
  3067. new_track = 0;
  3068. /* first idaw for a ccw may start anywhere */
  3069. if (!idaw_dst)
  3070. idaw_dst = dst;
  3071. }
  3072. /* If we start a new idaw, we must make sure that it
  3073. * starts on an IDA_BLOCK_SIZE boundary.
  3074. * If we continue an idaw, we must make sure that the
  3075. * current segment begins where the so far accumulated
  3076. * idaw ends
  3077. */
  3078. if (!idaw_dst) {
  3079. if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
  3080. dasd_sfree_request(cqr, startdev);
  3081. return ERR_PTR(-ERANGE);
  3082. } else
  3083. idaw_dst = dst;
  3084. }
  3085. if ((idaw_dst + idaw_len) != dst) {
  3086. dasd_sfree_request(cqr, startdev);
  3087. return ERR_PTR(-ERANGE);
  3088. }
  3089. part_len = min(seg_len, len_to_track_end);
  3090. seg_len -= part_len;
  3091. dst += part_len;
  3092. idaw_len += part_len;
  3093. len_to_track_end -= part_len;
  3094. /* collected memory area ends on an IDA_BLOCK border,
  3095. * -> create an idaw
  3096. * idal_create_words will handle cases where idaw_len
  3097. * is larger then IDA_BLOCK_SIZE
  3098. */
  3099. if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
  3100. end_idaw = 1;
  3101. /* We also need to end the idaw at track end */
  3102. if (!len_to_track_end) {
  3103. new_track = 1;
  3104. end_idaw = 1;
  3105. }
  3106. if (end_idaw) {
  3107. idaws = idal_create_words(idaws, idaw_dst,
  3108. idaw_len);
  3109. idaw_dst = NULL;
  3110. idaw_len = 0;
  3111. end_idaw = 0;
  3112. }
  3113. }
  3114. }
  3115. if (blk_noretry_request(req) ||
  3116. block->base->features & DASD_FEATURE_FAILFAST)
  3117. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3118. cqr->startdev = startdev;
  3119. cqr->memdev = startdev;
  3120. cqr->block = block;
  3121. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  3122. cqr->lpm = startdev->path_data.ppm;
  3123. cqr->retries = startdev->default_retries;
  3124. cqr->buildclk = get_tod_clock();
  3125. cqr->status = DASD_CQR_FILLED;
  3126. return cqr;
  3127. }
  3128. static int prepare_itcw(struct itcw *itcw,
  3129. unsigned int trk, unsigned int totrk, int cmd,
  3130. struct dasd_device *basedev,
  3131. struct dasd_device *startdev,
  3132. unsigned int rec_on_trk, int count,
  3133. unsigned int blksize,
  3134. unsigned int total_data_size,
  3135. unsigned int tlf,
  3136. unsigned int blk_per_trk)
  3137. {
  3138. struct PFX_eckd_data pfxdata;
  3139. struct dasd_eckd_private *basepriv, *startpriv;
  3140. struct DE_eckd_data *dedata;
  3141. struct LRE_eckd_data *lredata;
  3142. struct dcw *dcw;
  3143. u32 begcyl, endcyl;
  3144. u16 heads, beghead, endhead;
  3145. u8 pfx_cmd;
  3146. int rc = 0;
  3147. int sector = 0;
  3148. int dn, d;
  3149. /* setup prefix data */
  3150. basepriv = basedev->private;
  3151. startpriv = startdev->private;
  3152. dedata = &pfxdata.define_extent;
  3153. lredata = &pfxdata.locate_record;
  3154. memset(&pfxdata, 0, sizeof(pfxdata));
  3155. pfxdata.format = 1; /* PFX with LRE */
  3156. pfxdata.base_address = basepriv->ned->unit_addr;
  3157. pfxdata.base_lss = basepriv->ned->ID;
  3158. pfxdata.validity.define_extent = 1;
  3159. /* private uid is kept up to date, conf_data may be outdated */
  3160. if (startpriv->uid.type == UA_BASE_PAV_ALIAS)
  3161. pfxdata.validity.verify_base = 1;
  3162. if (startpriv->uid.type == UA_HYPER_PAV_ALIAS) {
  3163. pfxdata.validity.verify_base = 1;
  3164. pfxdata.validity.hyper_pav = 1;
  3165. }
  3166. switch (cmd) {
  3167. case DASD_ECKD_CCW_READ_TRACK_DATA:
  3168. dedata->mask.perm = 0x1;
  3169. dedata->attributes.operation = basepriv->attrib.operation;
  3170. dedata->blk_size = blksize;
  3171. dedata->ga_extended |= 0x42;
  3172. lredata->operation.orientation = 0x0;
  3173. lredata->operation.operation = 0x0C;
  3174. lredata->auxiliary.check_bytes = 0x01;
  3175. pfx_cmd = DASD_ECKD_CCW_PFX_READ;
  3176. break;
  3177. case DASD_ECKD_CCW_WRITE_TRACK_DATA:
  3178. dedata->mask.perm = 0x02;
  3179. dedata->attributes.operation = basepriv->attrib.operation;
  3180. dedata->blk_size = blksize;
  3181. rc = check_XRC_on_prefix(&pfxdata, basedev);
  3182. dedata->ga_extended |= 0x42;
  3183. lredata->operation.orientation = 0x0;
  3184. lredata->operation.operation = 0x3F;
  3185. lredata->extended_operation = 0x23;
  3186. lredata->auxiliary.check_bytes = 0x2;
  3187. pfx_cmd = DASD_ECKD_CCW_PFX;
  3188. break;
  3189. case DASD_ECKD_CCW_READ_COUNT_MT:
  3190. dedata->mask.perm = 0x1;
  3191. dedata->attributes.operation = DASD_BYPASS_CACHE;
  3192. dedata->ga_extended |= 0x42;
  3193. dedata->blk_size = blksize;
  3194. lredata->operation.orientation = 0x2;
  3195. lredata->operation.operation = 0x16;
  3196. lredata->auxiliary.check_bytes = 0x01;
  3197. pfx_cmd = DASD_ECKD_CCW_PFX_READ;
  3198. break;
  3199. default:
  3200. DBF_DEV_EVENT(DBF_ERR, basedev,
  3201. "prepare itcw, unknown opcode 0x%x", cmd);
  3202. BUG();
  3203. break;
  3204. }
  3205. if (rc)
  3206. return rc;
  3207. dedata->attributes.mode = 0x3; /* ECKD */
  3208. heads = basepriv->rdc_data.trk_per_cyl;
  3209. begcyl = trk / heads;
  3210. beghead = trk % heads;
  3211. endcyl = totrk / heads;
  3212. endhead = totrk % heads;
  3213. /* check for sequential prestage - enhance cylinder range */
  3214. if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
  3215. dedata->attributes.operation == DASD_SEQ_ACCESS) {
  3216. if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
  3217. endcyl += basepriv->attrib.nr_cyl;
  3218. else
  3219. endcyl = (basepriv->real_cyl - 1);
  3220. }
  3221. set_ch_t(&dedata->beg_ext, begcyl, beghead);
  3222. set_ch_t(&dedata->end_ext, endcyl, endhead);
  3223. dedata->ep_format = 0x20; /* records per track is valid */
  3224. dedata->ep_rec_per_track = blk_per_trk;
  3225. if (rec_on_trk) {
  3226. switch (basepriv->rdc_data.dev_type) {
  3227. case 0x3390:
  3228. dn = ceil_quot(blksize + 6, 232);
  3229. d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
  3230. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  3231. break;
  3232. case 0x3380:
  3233. d = 7 + ceil_quot(blksize + 12, 32);
  3234. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  3235. break;
  3236. }
  3237. }
  3238. if (cmd == DASD_ECKD_CCW_READ_COUNT_MT) {
  3239. lredata->auxiliary.length_valid = 0;
  3240. lredata->auxiliary.length_scope = 0;
  3241. lredata->sector = 0xff;
  3242. } else {
  3243. lredata->auxiliary.length_valid = 1;
  3244. lredata->auxiliary.length_scope = 1;
  3245. lredata->sector = sector;
  3246. }
  3247. lredata->auxiliary.imbedded_ccw_valid = 1;
  3248. lredata->length = tlf;
  3249. lredata->imbedded_ccw = cmd;
  3250. lredata->count = count;
  3251. set_ch_t(&lredata->seek_addr, begcyl, beghead);
  3252. lredata->search_arg.cyl = lredata->seek_addr.cyl;
  3253. lredata->search_arg.head = lredata->seek_addr.head;
  3254. lredata->search_arg.record = rec_on_trk;
  3255. dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
  3256. &pfxdata, sizeof(pfxdata), total_data_size);
  3257. return PTR_RET(dcw);
  3258. }
  3259. static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
  3260. struct dasd_device *startdev,
  3261. struct dasd_block *block,
  3262. struct request *req,
  3263. sector_t first_rec,
  3264. sector_t last_rec,
  3265. sector_t first_trk,
  3266. sector_t last_trk,
  3267. unsigned int first_offs,
  3268. unsigned int last_offs,
  3269. unsigned int blk_per_trk,
  3270. unsigned int blksize)
  3271. {
  3272. struct dasd_ccw_req *cqr;
  3273. struct req_iterator iter;
  3274. struct bio_vec bv;
  3275. char *dst;
  3276. unsigned int trkcount, ctidaw;
  3277. unsigned char cmd;
  3278. struct dasd_device *basedev;
  3279. unsigned int tlf;
  3280. struct itcw *itcw;
  3281. struct tidaw *last_tidaw = NULL;
  3282. int itcw_op;
  3283. size_t itcw_size;
  3284. u8 tidaw_flags;
  3285. unsigned int seg_len, part_len, len_to_track_end;
  3286. unsigned char new_track;
  3287. sector_t recid, trkid;
  3288. unsigned int offs;
  3289. unsigned int count, count_to_trk_end;
  3290. int ret;
  3291. basedev = block->base;
  3292. if (rq_data_dir(req) == READ) {
  3293. cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
  3294. itcw_op = ITCW_OP_READ;
  3295. } else if (rq_data_dir(req) == WRITE) {
  3296. cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
  3297. itcw_op = ITCW_OP_WRITE;
  3298. } else
  3299. return ERR_PTR(-EINVAL);
  3300. /* trackbased I/O needs address all memory via TIDAWs,
  3301. * not just for 64 bit addresses. This allows us to map
  3302. * each segment directly to one tidaw.
  3303. * In the case of write requests, additional tidaws may
  3304. * be needed when a segment crosses a track boundary.
  3305. */
  3306. trkcount = last_trk - first_trk + 1;
  3307. ctidaw = 0;
  3308. rq_for_each_segment(bv, req, iter) {
  3309. ++ctidaw;
  3310. }
  3311. if (rq_data_dir(req) == WRITE)
  3312. ctidaw += (last_trk - first_trk);
  3313. /* Allocate the ccw request. */
  3314. itcw_size = itcw_calc_size(0, ctidaw, 0);
  3315. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
  3316. if (IS_ERR(cqr))
  3317. return cqr;
  3318. /* transfer length factor: how many bytes to read from the last track */
  3319. if (first_trk == last_trk)
  3320. tlf = last_offs - first_offs + 1;
  3321. else
  3322. tlf = last_offs + 1;
  3323. tlf *= blksize;
  3324. itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
  3325. if (IS_ERR(itcw)) {
  3326. ret = -EINVAL;
  3327. goto out_error;
  3328. }
  3329. cqr->cpaddr = itcw_get_tcw(itcw);
  3330. if (prepare_itcw(itcw, first_trk, last_trk,
  3331. cmd, basedev, startdev,
  3332. first_offs + 1,
  3333. trkcount, blksize,
  3334. (last_rec - first_rec + 1) * blksize,
  3335. tlf, blk_per_trk) == -EAGAIN) {
  3336. /* Clock not in sync and XRC is enabled.
  3337. * Try again later.
  3338. */
  3339. ret = -EAGAIN;
  3340. goto out_error;
  3341. }
  3342. len_to_track_end = 0;
  3343. /*
  3344. * A tidaw can address 4k of memory, but must not cross page boundaries
  3345. * We can let the block layer handle this by setting
  3346. * blk_queue_segment_boundary to page boundaries and
  3347. * blk_max_segment_size to page size when setting up the request queue.
  3348. * For write requests, a TIDAW must not cross track boundaries, because
  3349. * we have to set the CBC flag on the last tidaw for each track.
  3350. */
  3351. if (rq_data_dir(req) == WRITE) {
  3352. new_track = 1;
  3353. recid = first_rec;
  3354. rq_for_each_segment(bv, req, iter) {
  3355. dst = page_address(bv.bv_page) + bv.bv_offset;
  3356. seg_len = bv.bv_len;
  3357. while (seg_len) {
  3358. if (new_track) {
  3359. trkid = recid;
  3360. offs = sector_div(trkid, blk_per_trk);
  3361. count_to_trk_end = blk_per_trk - offs;
  3362. count = min((last_rec - recid + 1),
  3363. (sector_t)count_to_trk_end);
  3364. len_to_track_end = count * blksize;
  3365. recid += count;
  3366. new_track = 0;
  3367. }
  3368. part_len = min(seg_len, len_to_track_end);
  3369. seg_len -= part_len;
  3370. len_to_track_end -= part_len;
  3371. /* We need to end the tidaw at track end */
  3372. if (!len_to_track_end) {
  3373. new_track = 1;
  3374. tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
  3375. } else
  3376. tidaw_flags = 0;
  3377. last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
  3378. dst, part_len);
  3379. if (IS_ERR(last_tidaw)) {
  3380. ret = -EINVAL;
  3381. goto out_error;
  3382. }
  3383. dst += part_len;
  3384. }
  3385. }
  3386. } else {
  3387. rq_for_each_segment(bv, req, iter) {
  3388. dst = page_address(bv.bv_page) + bv.bv_offset;
  3389. last_tidaw = itcw_add_tidaw(itcw, 0x00,
  3390. dst, bv.bv_len);
  3391. if (IS_ERR(last_tidaw)) {
  3392. ret = -EINVAL;
  3393. goto out_error;
  3394. }
  3395. }
  3396. }
  3397. last_tidaw->flags |= TIDAW_FLAGS_LAST;
  3398. last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
  3399. itcw_finalize(itcw);
  3400. if (blk_noretry_request(req) ||
  3401. block->base->features & DASD_FEATURE_FAILFAST)
  3402. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3403. cqr->cpmode = 1;
  3404. cqr->startdev = startdev;
  3405. cqr->memdev = startdev;
  3406. cqr->block = block;
  3407. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  3408. cqr->lpm = startdev->path_data.ppm;
  3409. cqr->retries = startdev->default_retries;
  3410. cqr->buildclk = get_tod_clock();
  3411. cqr->status = DASD_CQR_FILLED;
  3412. return cqr;
  3413. out_error:
  3414. dasd_sfree_request(cqr, startdev);
  3415. return ERR_PTR(ret);
  3416. }
  3417. static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
  3418. struct dasd_block *block,
  3419. struct request *req)
  3420. {
  3421. int cmdrtd, cmdwtd;
  3422. int use_prefix;
  3423. int fcx_multitrack;
  3424. struct dasd_eckd_private *private;
  3425. struct dasd_device *basedev;
  3426. sector_t first_rec, last_rec;
  3427. sector_t first_trk, last_trk;
  3428. unsigned int first_offs, last_offs;
  3429. unsigned int blk_per_trk, blksize;
  3430. int cdlspecial;
  3431. unsigned int data_size;
  3432. struct dasd_ccw_req *cqr;
  3433. basedev = block->base;
  3434. private = basedev->private;
  3435. /* Calculate number of blocks/records per track. */
  3436. blksize = block->bp_block;
  3437. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  3438. if (blk_per_trk == 0)
  3439. return ERR_PTR(-EINVAL);
  3440. /* Calculate record id of first and last block. */
  3441. first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
  3442. first_offs = sector_div(first_trk, blk_per_trk);
  3443. last_rec = last_trk =
  3444. (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
  3445. last_offs = sector_div(last_trk, blk_per_trk);
  3446. cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
  3447. fcx_multitrack = private->features.feature[40] & 0x20;
  3448. data_size = blk_rq_bytes(req);
  3449. if (data_size % blksize)
  3450. return ERR_PTR(-EINVAL);
  3451. /* tpm write request add CBC data on each track boundary */
  3452. if (rq_data_dir(req) == WRITE)
  3453. data_size += (last_trk - first_trk) * 4;
  3454. /* is read track data and write track data in command mode supported? */
  3455. cmdrtd = private->features.feature[9] & 0x20;
  3456. cmdwtd = private->features.feature[12] & 0x40;
  3457. use_prefix = private->features.feature[8] & 0x01;
  3458. cqr = NULL;
  3459. if (cdlspecial || dasd_page_cache) {
  3460. /* do nothing, just fall through to the cmd mode single case */
  3461. } else if ((data_size <= private->fcx_max_data)
  3462. && (fcx_multitrack || (first_trk == last_trk))) {
  3463. cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
  3464. first_rec, last_rec,
  3465. first_trk, last_trk,
  3466. first_offs, last_offs,
  3467. blk_per_trk, blksize);
  3468. if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
  3469. (PTR_ERR(cqr) != -ENOMEM))
  3470. cqr = NULL;
  3471. } else if (use_prefix &&
  3472. (((rq_data_dir(req) == READ) && cmdrtd) ||
  3473. ((rq_data_dir(req) == WRITE) && cmdwtd))) {
  3474. cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
  3475. first_rec, last_rec,
  3476. first_trk, last_trk,
  3477. first_offs, last_offs,
  3478. blk_per_trk, blksize);
  3479. if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
  3480. (PTR_ERR(cqr) != -ENOMEM))
  3481. cqr = NULL;
  3482. }
  3483. if (!cqr)
  3484. cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
  3485. first_rec, last_rec,
  3486. first_trk, last_trk,
  3487. first_offs, last_offs,
  3488. blk_per_trk, blksize);
  3489. return cqr;
  3490. }
  3491. static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
  3492. struct dasd_block *block,
  3493. struct request *req)
  3494. {
  3495. unsigned long *idaws;
  3496. struct dasd_device *basedev;
  3497. struct dasd_ccw_req *cqr;
  3498. struct ccw1 *ccw;
  3499. struct req_iterator iter;
  3500. struct bio_vec bv;
  3501. char *dst;
  3502. unsigned char cmd;
  3503. unsigned int trkcount;
  3504. unsigned int seg_len, len_to_track_end;
  3505. unsigned int first_offs;
  3506. unsigned int cidaw, cplength, datasize;
  3507. sector_t first_trk, last_trk, sectors;
  3508. sector_t start_padding_sectors, end_sector_offset, end_padding_sectors;
  3509. unsigned int pfx_datasize;
  3510. /*
  3511. * raw track access needs to be mutiple of 64k and on 64k boundary
  3512. * For read requests we can fix an incorrect alignment by padding
  3513. * the request with dummy pages.
  3514. */
  3515. start_padding_sectors = blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK;
  3516. end_sector_offset = (blk_rq_pos(req) + blk_rq_sectors(req)) %
  3517. DASD_RAW_SECTORS_PER_TRACK;
  3518. end_padding_sectors = (DASD_RAW_SECTORS_PER_TRACK - end_sector_offset) %
  3519. DASD_RAW_SECTORS_PER_TRACK;
  3520. basedev = block->base;
  3521. if ((start_padding_sectors || end_padding_sectors) &&
  3522. (rq_data_dir(req) == WRITE)) {
  3523. DBF_DEV_EVENT(DBF_ERR, basedev,
  3524. "raw write not track aligned (%lu,%lu) req %p",
  3525. start_padding_sectors, end_padding_sectors, req);
  3526. cqr = ERR_PTR(-EINVAL);
  3527. goto out;
  3528. }
  3529. first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
  3530. last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
  3531. DASD_RAW_SECTORS_PER_TRACK;
  3532. trkcount = last_trk - first_trk + 1;
  3533. first_offs = 0;
  3534. if (rq_data_dir(req) == READ)
  3535. cmd = DASD_ECKD_CCW_READ_TRACK;
  3536. else if (rq_data_dir(req) == WRITE)
  3537. cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
  3538. else {
  3539. cqr = ERR_PTR(-EINVAL);
  3540. goto out;
  3541. }
  3542. /*
  3543. * Raw track based I/O needs IDAWs for each page,
  3544. * and not just for 64 bit addresses.
  3545. */
  3546. cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
  3547. /* 1x prefix + one read/write ccw per track */
  3548. cplength = 1 + trkcount;
  3549. /*
  3550. * struct PFX_eckd_data has up to 2 byte as extended parameter
  3551. * this is needed for write full track and has to be mentioned
  3552. * separately
  3553. * add 8 instead of 2 to keep 8 byte boundary
  3554. */
  3555. pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
  3556. datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
  3557. /* Allocate the ccw request. */
  3558. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
  3559. datasize, startdev);
  3560. if (IS_ERR(cqr))
  3561. goto out;
  3562. ccw = cqr->cpaddr;
  3563. if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
  3564. basedev, startdev, 1 /* format */, first_offs + 1,
  3565. trkcount, 0, 0) == -EAGAIN) {
  3566. /* Clock not in sync and XRC is enabled.
  3567. * Try again later.
  3568. */
  3569. dasd_sfree_request(cqr, startdev);
  3570. cqr = ERR_PTR(-EAGAIN);
  3571. goto out;
  3572. }
  3573. idaws = (unsigned long *)(cqr->data + pfx_datasize);
  3574. len_to_track_end = 0;
  3575. if (start_padding_sectors) {
  3576. ccw[-1].flags |= CCW_FLAG_CC;
  3577. ccw->cmd_code = cmd;
  3578. /* maximum 3390 track size */
  3579. ccw->count = 57326;
  3580. /* 64k map to one track */
  3581. len_to_track_end = 65536 - start_padding_sectors * 512;
  3582. ccw->cda = (__u32)(addr_t)idaws;
  3583. ccw->flags |= CCW_FLAG_IDA;
  3584. ccw->flags |= CCW_FLAG_SLI;
  3585. ccw++;
  3586. for (sectors = 0; sectors < start_padding_sectors; sectors += 8)
  3587. idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
  3588. }
  3589. rq_for_each_segment(bv, req, iter) {
  3590. dst = page_address(bv.bv_page) + bv.bv_offset;
  3591. seg_len = bv.bv_len;
  3592. if (cmd == DASD_ECKD_CCW_READ_TRACK)
  3593. memset(dst, 0, seg_len);
  3594. if (!len_to_track_end) {
  3595. ccw[-1].flags |= CCW_FLAG_CC;
  3596. ccw->cmd_code = cmd;
  3597. /* maximum 3390 track size */
  3598. ccw->count = 57326;
  3599. /* 64k map to one track */
  3600. len_to_track_end = 65536;
  3601. ccw->cda = (__u32)(addr_t)idaws;
  3602. ccw->flags |= CCW_FLAG_IDA;
  3603. ccw->flags |= CCW_FLAG_SLI;
  3604. ccw++;
  3605. }
  3606. len_to_track_end -= seg_len;
  3607. idaws = idal_create_words(idaws, dst, seg_len);
  3608. }
  3609. for (sectors = 0; sectors < end_padding_sectors; sectors += 8)
  3610. idaws = idal_create_words(idaws, rawpadpage, PAGE_SIZE);
  3611. if (blk_noretry_request(req) ||
  3612. block->base->features & DASD_FEATURE_FAILFAST)
  3613. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3614. cqr->startdev = startdev;
  3615. cqr->memdev = startdev;
  3616. cqr->block = block;
  3617. cqr->expires = startdev->default_expires * HZ;
  3618. cqr->lpm = startdev->path_data.ppm;
  3619. cqr->retries = startdev->default_retries;
  3620. cqr->buildclk = get_tod_clock();
  3621. cqr->status = DASD_CQR_FILLED;
  3622. if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
  3623. cqr = NULL;
  3624. out:
  3625. return cqr;
  3626. }
  3627. static int
  3628. dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
  3629. {
  3630. struct dasd_eckd_private *private;
  3631. struct ccw1 *ccw;
  3632. struct req_iterator iter;
  3633. struct bio_vec bv;
  3634. char *dst, *cda;
  3635. unsigned int blksize, blk_per_trk, off;
  3636. sector_t recid;
  3637. int status;
  3638. if (!dasd_page_cache)
  3639. goto out;
  3640. private = cqr->block->base->private;
  3641. blksize = cqr->block->bp_block;
  3642. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  3643. recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
  3644. ccw = cqr->cpaddr;
  3645. /* Skip over define extent & locate record. */
  3646. ccw++;
  3647. if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
  3648. ccw++;
  3649. rq_for_each_segment(bv, req, iter) {
  3650. dst = page_address(bv.bv_page) + bv.bv_offset;
  3651. for (off = 0; off < bv.bv_len; off += blksize) {
  3652. /* Skip locate record. */
  3653. if (private->uses_cdl && recid <= 2*blk_per_trk)
  3654. ccw++;
  3655. if (dst) {
  3656. if (ccw->flags & CCW_FLAG_IDA)
  3657. cda = *((char **)((addr_t) ccw->cda));
  3658. else
  3659. cda = (char *)((addr_t) ccw->cda);
  3660. if (dst != cda) {
  3661. if (rq_data_dir(req) == READ)
  3662. memcpy(dst, cda, bv.bv_len);
  3663. kmem_cache_free(dasd_page_cache,
  3664. (void *)((addr_t)cda & PAGE_MASK));
  3665. }
  3666. dst = NULL;
  3667. }
  3668. ccw++;
  3669. recid++;
  3670. }
  3671. }
  3672. out:
  3673. status = cqr->status == DASD_CQR_DONE;
  3674. dasd_sfree_request(cqr, cqr->memdev);
  3675. return status;
  3676. }
  3677. /*
  3678. * Modify ccw/tcw in cqr so it can be started on a base device.
  3679. *
  3680. * Note that this is not enough to restart the cqr!
  3681. * Either reset cqr->startdev as well (summary unit check handling)
  3682. * or restart via separate cqr (as in ERP handling).
  3683. */
  3684. void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
  3685. {
  3686. struct ccw1 *ccw;
  3687. struct PFX_eckd_data *pfxdata;
  3688. struct tcw *tcw;
  3689. struct tccb *tccb;
  3690. struct dcw *dcw;
  3691. if (cqr->cpmode == 1) {
  3692. tcw = cqr->cpaddr;
  3693. tccb = tcw_get_tccb(tcw);
  3694. dcw = (struct dcw *)&tccb->tca[0];
  3695. pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
  3696. pfxdata->validity.verify_base = 0;
  3697. pfxdata->validity.hyper_pav = 0;
  3698. } else {
  3699. ccw = cqr->cpaddr;
  3700. pfxdata = cqr->data;
  3701. if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
  3702. pfxdata->validity.verify_base = 0;
  3703. pfxdata->validity.hyper_pav = 0;
  3704. }
  3705. }
  3706. }
  3707. #define DASD_ECKD_CHANQ_MAX_SIZE 4
  3708. static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
  3709. struct dasd_block *block,
  3710. struct request *req)
  3711. {
  3712. struct dasd_eckd_private *private;
  3713. struct dasd_device *startdev;
  3714. unsigned long flags;
  3715. struct dasd_ccw_req *cqr;
  3716. startdev = dasd_alias_get_start_dev(base);
  3717. if (!startdev)
  3718. startdev = base;
  3719. private = startdev->private;
  3720. if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
  3721. return ERR_PTR(-EBUSY);
  3722. spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
  3723. private->count++;
  3724. if ((base->features & DASD_FEATURE_USERAW))
  3725. cqr = dasd_raw_build_cp(startdev, block, req);
  3726. else
  3727. cqr = dasd_eckd_build_cp(startdev, block, req);
  3728. if (IS_ERR(cqr))
  3729. private->count--;
  3730. spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
  3731. return cqr;
  3732. }
  3733. static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
  3734. struct request *req)
  3735. {
  3736. struct dasd_eckd_private *private;
  3737. unsigned long flags;
  3738. spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
  3739. private = cqr->memdev->private;
  3740. private->count--;
  3741. spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
  3742. return dasd_eckd_free_cp(cqr, req);
  3743. }
  3744. static int
  3745. dasd_eckd_fill_info(struct dasd_device * device,
  3746. struct dasd_information2_t * info)
  3747. {
  3748. struct dasd_eckd_private *private = device->private;
  3749. info->label_block = 2;
  3750. info->FBA_layout = private->uses_cdl ? 0 : 1;
  3751. info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
  3752. info->characteristics_size = sizeof(private->rdc_data);
  3753. memcpy(info->characteristics, &private->rdc_data,
  3754. sizeof(private->rdc_data));
  3755. info->confdata_size = min((unsigned long)private->conf_len,
  3756. sizeof(info->configuration_data));
  3757. memcpy(info->configuration_data, private->conf_data,
  3758. info->confdata_size);
  3759. return 0;
  3760. }
  3761. /*
  3762. * SECTION: ioctl functions for eckd devices.
  3763. */
  3764. /*
  3765. * Release device ioctl.
  3766. * Buils a channel programm to releases a prior reserved
  3767. * (see dasd_eckd_reserve) device.
  3768. */
  3769. static int
  3770. dasd_eckd_release(struct dasd_device *device)
  3771. {
  3772. struct dasd_ccw_req *cqr;
  3773. int rc;
  3774. struct ccw1 *ccw;
  3775. int useglobal;
  3776. if (!capable(CAP_SYS_ADMIN))
  3777. return -EACCES;
  3778. useglobal = 0;
  3779. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3780. if (IS_ERR(cqr)) {
  3781. mutex_lock(&dasd_reserve_mutex);
  3782. useglobal = 1;
  3783. cqr = &dasd_reserve_req->cqr;
  3784. memset(cqr, 0, sizeof(*cqr));
  3785. memset(&dasd_reserve_req->ccw, 0,
  3786. sizeof(dasd_reserve_req->ccw));
  3787. cqr->cpaddr = &dasd_reserve_req->ccw;
  3788. cqr->data = &dasd_reserve_req->data;
  3789. cqr->magic = DASD_ECKD_MAGIC;
  3790. }
  3791. ccw = cqr->cpaddr;
  3792. ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
  3793. ccw->flags |= CCW_FLAG_SLI;
  3794. ccw->count = 32;
  3795. ccw->cda = (__u32)(addr_t) cqr->data;
  3796. cqr->startdev = device;
  3797. cqr->memdev = device;
  3798. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3799. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3800. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3801. cqr->expires = 2 * HZ;
  3802. cqr->buildclk = get_tod_clock();
  3803. cqr->status = DASD_CQR_FILLED;
  3804. rc = dasd_sleep_on_immediatly(cqr);
  3805. if (!rc)
  3806. clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3807. if (useglobal)
  3808. mutex_unlock(&dasd_reserve_mutex);
  3809. else
  3810. dasd_sfree_request(cqr, cqr->memdev);
  3811. return rc;
  3812. }
  3813. /*
  3814. * Reserve device ioctl.
  3815. * Options are set to 'synchronous wait for interrupt' and
  3816. * 'timeout the request'. This leads to a terminate IO if
  3817. * the interrupt is outstanding for a certain time.
  3818. */
  3819. static int
  3820. dasd_eckd_reserve(struct dasd_device *device)
  3821. {
  3822. struct dasd_ccw_req *cqr;
  3823. int rc;
  3824. struct ccw1 *ccw;
  3825. int useglobal;
  3826. if (!capable(CAP_SYS_ADMIN))
  3827. return -EACCES;
  3828. useglobal = 0;
  3829. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3830. if (IS_ERR(cqr)) {
  3831. mutex_lock(&dasd_reserve_mutex);
  3832. useglobal = 1;
  3833. cqr = &dasd_reserve_req->cqr;
  3834. memset(cqr, 0, sizeof(*cqr));
  3835. memset(&dasd_reserve_req->ccw, 0,
  3836. sizeof(dasd_reserve_req->ccw));
  3837. cqr->cpaddr = &dasd_reserve_req->ccw;
  3838. cqr->data = &dasd_reserve_req->data;
  3839. cqr->magic = DASD_ECKD_MAGIC;
  3840. }
  3841. ccw = cqr->cpaddr;
  3842. ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
  3843. ccw->flags |= CCW_FLAG_SLI;
  3844. ccw->count = 32;
  3845. ccw->cda = (__u32)(addr_t) cqr->data;
  3846. cqr->startdev = device;
  3847. cqr->memdev = device;
  3848. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3849. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3850. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3851. cqr->expires = 2 * HZ;
  3852. cqr->buildclk = get_tod_clock();
  3853. cqr->status = DASD_CQR_FILLED;
  3854. rc = dasd_sleep_on_immediatly(cqr);
  3855. if (!rc)
  3856. set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3857. if (useglobal)
  3858. mutex_unlock(&dasd_reserve_mutex);
  3859. else
  3860. dasd_sfree_request(cqr, cqr->memdev);
  3861. return rc;
  3862. }
  3863. /*
  3864. * Steal lock ioctl - unconditional reserve device.
  3865. * Buils a channel programm to break a device's reservation.
  3866. * (unconditional reserve)
  3867. */
  3868. static int
  3869. dasd_eckd_steal_lock(struct dasd_device *device)
  3870. {
  3871. struct dasd_ccw_req *cqr;
  3872. int rc;
  3873. struct ccw1 *ccw;
  3874. int useglobal;
  3875. if (!capable(CAP_SYS_ADMIN))
  3876. return -EACCES;
  3877. useglobal = 0;
  3878. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3879. if (IS_ERR(cqr)) {
  3880. mutex_lock(&dasd_reserve_mutex);
  3881. useglobal = 1;
  3882. cqr = &dasd_reserve_req->cqr;
  3883. memset(cqr, 0, sizeof(*cqr));
  3884. memset(&dasd_reserve_req->ccw, 0,
  3885. sizeof(dasd_reserve_req->ccw));
  3886. cqr->cpaddr = &dasd_reserve_req->ccw;
  3887. cqr->data = &dasd_reserve_req->data;
  3888. cqr->magic = DASD_ECKD_MAGIC;
  3889. }
  3890. ccw = cqr->cpaddr;
  3891. ccw->cmd_code = DASD_ECKD_CCW_SLCK;
  3892. ccw->flags |= CCW_FLAG_SLI;
  3893. ccw->count = 32;
  3894. ccw->cda = (__u32)(addr_t) cqr->data;
  3895. cqr->startdev = device;
  3896. cqr->memdev = device;
  3897. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3898. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3899. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3900. cqr->expires = 2 * HZ;
  3901. cqr->buildclk = get_tod_clock();
  3902. cqr->status = DASD_CQR_FILLED;
  3903. rc = dasd_sleep_on_immediatly(cqr);
  3904. if (!rc)
  3905. set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3906. if (useglobal)
  3907. mutex_unlock(&dasd_reserve_mutex);
  3908. else
  3909. dasd_sfree_request(cqr, cqr->memdev);
  3910. return rc;
  3911. }
  3912. /*
  3913. * SNID - Sense Path Group ID
  3914. * This ioctl may be used in situations where I/O is stalled due to
  3915. * a reserve, so if the normal dasd_smalloc_request fails, we use the
  3916. * preallocated dasd_reserve_req.
  3917. */
  3918. static int dasd_eckd_snid(struct dasd_device *device,
  3919. void __user *argp)
  3920. {
  3921. struct dasd_ccw_req *cqr;
  3922. int rc;
  3923. struct ccw1 *ccw;
  3924. int useglobal;
  3925. struct dasd_snid_ioctl_data usrparm;
  3926. if (!capable(CAP_SYS_ADMIN))
  3927. return -EACCES;
  3928. if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
  3929. return -EFAULT;
  3930. useglobal = 0;
  3931. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
  3932. sizeof(struct dasd_snid_data), device);
  3933. if (IS_ERR(cqr)) {
  3934. mutex_lock(&dasd_reserve_mutex);
  3935. useglobal = 1;
  3936. cqr = &dasd_reserve_req->cqr;
  3937. memset(cqr, 0, sizeof(*cqr));
  3938. memset(&dasd_reserve_req->ccw, 0,
  3939. sizeof(dasd_reserve_req->ccw));
  3940. cqr->cpaddr = &dasd_reserve_req->ccw;
  3941. cqr->data = &dasd_reserve_req->data;
  3942. cqr->magic = DASD_ECKD_MAGIC;
  3943. }
  3944. ccw = cqr->cpaddr;
  3945. ccw->cmd_code = DASD_ECKD_CCW_SNID;
  3946. ccw->flags |= CCW_FLAG_SLI;
  3947. ccw->count = 12;
  3948. ccw->cda = (__u32)(addr_t) cqr->data;
  3949. cqr->startdev = device;
  3950. cqr->memdev = device;
  3951. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3952. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3953. set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
  3954. cqr->retries = 5;
  3955. cqr->expires = 10 * HZ;
  3956. cqr->buildclk = get_tod_clock();
  3957. cqr->status = DASD_CQR_FILLED;
  3958. cqr->lpm = usrparm.path_mask;
  3959. rc = dasd_sleep_on_immediatly(cqr);
  3960. /* verify that I/O processing didn't modify the path mask */
  3961. if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
  3962. rc = -EIO;
  3963. if (!rc) {
  3964. usrparm.data = *((struct dasd_snid_data *)cqr->data);
  3965. if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
  3966. rc = -EFAULT;
  3967. }
  3968. if (useglobal)
  3969. mutex_unlock(&dasd_reserve_mutex);
  3970. else
  3971. dasd_sfree_request(cqr, cqr->memdev);
  3972. return rc;
  3973. }
  3974. /*
  3975. * Read performance statistics
  3976. */
  3977. static int
  3978. dasd_eckd_performance(struct dasd_device *device, void __user *argp)
  3979. {
  3980. struct dasd_psf_prssd_data *prssdp;
  3981. struct dasd_rssd_perf_stats_t *stats;
  3982. struct dasd_ccw_req *cqr;
  3983. struct ccw1 *ccw;
  3984. int rc;
  3985. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  3986. (sizeof(struct dasd_psf_prssd_data) +
  3987. sizeof(struct dasd_rssd_perf_stats_t)),
  3988. device);
  3989. if (IS_ERR(cqr)) {
  3990. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3991. "Could not allocate initialization request");
  3992. return PTR_ERR(cqr);
  3993. }
  3994. cqr->startdev = device;
  3995. cqr->memdev = device;
  3996. cqr->retries = 0;
  3997. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3998. cqr->expires = 10 * HZ;
  3999. /* Prepare for Read Subsystem Data */
  4000. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  4001. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  4002. prssdp->order = PSF_ORDER_PRSSD;
  4003. prssdp->suborder = 0x01; /* Performance Statistics */
  4004. prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
  4005. ccw = cqr->cpaddr;
  4006. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  4007. ccw->count = sizeof(struct dasd_psf_prssd_data);
  4008. ccw->flags |= CCW_FLAG_CC;
  4009. ccw->cda = (__u32)(addr_t) prssdp;
  4010. /* Read Subsystem Data - Performance Statistics */
  4011. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  4012. memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
  4013. ccw++;
  4014. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  4015. ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
  4016. ccw->cda = (__u32)(addr_t) stats;
  4017. cqr->buildclk = get_tod_clock();
  4018. cqr->status = DASD_CQR_FILLED;
  4019. rc = dasd_sleep_on(cqr);
  4020. if (rc == 0) {
  4021. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  4022. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  4023. if (copy_to_user(argp, stats,
  4024. sizeof(struct dasd_rssd_perf_stats_t)))
  4025. rc = -EFAULT;
  4026. }
  4027. dasd_sfree_request(cqr, cqr->memdev);
  4028. return rc;
  4029. }
  4030. /*
  4031. * Get attributes (cache operations)
  4032. * Returnes the cache attributes used in Define Extend (DE).
  4033. */
  4034. static int
  4035. dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
  4036. {
  4037. struct dasd_eckd_private *private = device->private;
  4038. struct attrib_data_t attrib = private->attrib;
  4039. int rc;
  4040. if (!capable(CAP_SYS_ADMIN))
  4041. return -EACCES;
  4042. if (!argp)
  4043. return -EINVAL;
  4044. rc = 0;
  4045. if (copy_to_user(argp, (long *) &attrib,
  4046. sizeof(struct attrib_data_t)))
  4047. rc = -EFAULT;
  4048. return rc;
  4049. }
  4050. /*
  4051. * Set attributes (cache operations)
  4052. * Stores the attributes for cache operation to be used in Define Extend (DE).
  4053. */
  4054. static int
  4055. dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
  4056. {
  4057. struct dasd_eckd_private *private = device->private;
  4058. struct attrib_data_t attrib;
  4059. if (!capable(CAP_SYS_ADMIN))
  4060. return -EACCES;
  4061. if (!argp)
  4062. return -EINVAL;
  4063. if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
  4064. return -EFAULT;
  4065. private->attrib = attrib;
  4066. dev_info(&device->cdev->dev,
  4067. "The DASD cache mode was set to %x (%i cylinder prestage)\n",
  4068. private->attrib.operation, private->attrib.nr_cyl);
  4069. return 0;
  4070. }
  4071. /*
  4072. * Issue syscall I/O to EMC Symmetrix array.
  4073. * CCWs are PSF and RSSD
  4074. */
  4075. static int dasd_symm_io(struct dasd_device *device, void __user *argp)
  4076. {
  4077. struct dasd_symmio_parms usrparm;
  4078. char *psf_data, *rssd_result;
  4079. struct dasd_ccw_req *cqr;
  4080. struct ccw1 *ccw;
  4081. char psf0, psf1;
  4082. int rc;
  4083. if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
  4084. return -EACCES;
  4085. psf0 = psf1 = 0;
  4086. /* Copy parms from caller */
  4087. rc = -EFAULT;
  4088. if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
  4089. goto out;
  4090. if (is_compat_task()) {
  4091. /* Make sure pointers are sane even on 31 bit. */
  4092. rc = -EINVAL;
  4093. if ((usrparm.psf_data >> 32) != 0)
  4094. goto out;
  4095. if ((usrparm.rssd_result >> 32) != 0)
  4096. goto out;
  4097. usrparm.psf_data &= 0x7fffffffULL;
  4098. usrparm.rssd_result &= 0x7fffffffULL;
  4099. }
  4100. /* alloc I/O data area */
  4101. psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
  4102. rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
  4103. if (!psf_data || !rssd_result) {
  4104. rc = -ENOMEM;
  4105. goto out_free;
  4106. }
  4107. /* get syscall header from user space */
  4108. rc = -EFAULT;
  4109. if (copy_from_user(psf_data,
  4110. (void __user *)(unsigned long) usrparm.psf_data,
  4111. usrparm.psf_data_len))
  4112. goto out_free;
  4113. psf0 = psf_data[0];
  4114. psf1 = psf_data[1];
  4115. /* setup CCWs for PSF + RSSD */
  4116. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
  4117. if (IS_ERR(cqr)) {
  4118. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  4119. "Could not allocate initialization request");
  4120. rc = PTR_ERR(cqr);
  4121. goto out_free;
  4122. }
  4123. cqr->startdev = device;
  4124. cqr->memdev = device;
  4125. cqr->retries = 3;
  4126. cqr->expires = 10 * HZ;
  4127. cqr->buildclk = get_tod_clock();
  4128. cqr->status = DASD_CQR_FILLED;
  4129. /* Build the ccws */
  4130. ccw = cqr->cpaddr;
  4131. /* PSF ccw */
  4132. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  4133. ccw->count = usrparm.psf_data_len;
  4134. ccw->flags |= CCW_FLAG_CC;
  4135. ccw->cda = (__u32)(addr_t) psf_data;
  4136. ccw++;
  4137. /* RSSD ccw */
  4138. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  4139. ccw->count = usrparm.rssd_result_len;
  4140. ccw->flags = CCW_FLAG_SLI ;
  4141. ccw->cda = (__u32)(addr_t) rssd_result;
  4142. rc = dasd_sleep_on(cqr);
  4143. if (rc)
  4144. goto out_sfree;
  4145. rc = -EFAULT;
  4146. if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
  4147. rssd_result, usrparm.rssd_result_len))
  4148. goto out_sfree;
  4149. rc = 0;
  4150. out_sfree:
  4151. dasd_sfree_request(cqr, cqr->memdev);
  4152. out_free:
  4153. kfree(rssd_result);
  4154. kfree(psf_data);
  4155. out:
  4156. DBF_DEV_EVENT(DBF_WARNING, device,
  4157. "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
  4158. (int) psf0, (int) psf1, rc);
  4159. return rc;
  4160. }
  4161. static int
  4162. dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
  4163. {
  4164. struct dasd_device *device = block->base;
  4165. switch (cmd) {
  4166. case BIODASDGATTR:
  4167. return dasd_eckd_get_attrib(device, argp);
  4168. case BIODASDSATTR:
  4169. return dasd_eckd_set_attrib(device, argp);
  4170. case BIODASDPSRD:
  4171. return dasd_eckd_performance(device, argp);
  4172. case BIODASDRLSE:
  4173. return dasd_eckd_release(device);
  4174. case BIODASDRSRV:
  4175. return dasd_eckd_reserve(device);
  4176. case BIODASDSLCK:
  4177. return dasd_eckd_steal_lock(device);
  4178. case BIODASDSNID:
  4179. return dasd_eckd_snid(device, argp);
  4180. case BIODASDSYMMIO:
  4181. return dasd_symm_io(device, argp);
  4182. default:
  4183. return -ENOTTY;
  4184. }
  4185. }
  4186. /*
  4187. * Dump the range of CCWs into 'page' buffer
  4188. * and return number of printed chars.
  4189. */
  4190. static int
  4191. dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
  4192. {
  4193. int len, count;
  4194. char *datap;
  4195. len = 0;
  4196. while (from <= to) {
  4197. len += sprintf(page + len, PRINTK_HEADER
  4198. " CCW %p: %08X %08X DAT:",
  4199. from, ((int *) from)[0], ((int *) from)[1]);
  4200. /* get pointer to data (consider IDALs) */
  4201. if (from->flags & CCW_FLAG_IDA)
  4202. datap = (char *) *((addr_t *) (addr_t) from->cda);
  4203. else
  4204. datap = (char *) ((addr_t) from->cda);
  4205. /* dump data (max 32 bytes) */
  4206. for (count = 0; count < from->count && count < 32; count++) {
  4207. if (count % 8 == 0) len += sprintf(page + len, " ");
  4208. if (count % 4 == 0) len += sprintf(page + len, " ");
  4209. len += sprintf(page + len, "%02x", datap[count]);
  4210. }
  4211. len += sprintf(page + len, "\n");
  4212. from++;
  4213. }
  4214. return len;
  4215. }
  4216. static void
  4217. dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
  4218. char *reason)
  4219. {
  4220. u64 *sense;
  4221. u64 *stat;
  4222. sense = (u64 *) dasd_get_sense(irb);
  4223. stat = (u64 *) &irb->scsw;
  4224. if (sense) {
  4225. DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
  4226. "%016llx %016llx %016llx %016llx",
  4227. reason, *stat, *((u32 *) (stat + 1)),
  4228. sense[0], sense[1], sense[2], sense[3]);
  4229. } else {
  4230. DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
  4231. reason, *stat, *((u32 *) (stat + 1)),
  4232. "NO VALID SENSE");
  4233. }
  4234. }
  4235. /*
  4236. * Print sense data and related channel program.
  4237. * Parts are printed because printk buffer is only 1024 bytes.
  4238. */
  4239. static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
  4240. struct dasd_ccw_req *req, struct irb *irb)
  4241. {
  4242. char *page;
  4243. struct ccw1 *first, *last, *fail, *from, *to;
  4244. int len, sl, sct;
  4245. page = (char *) get_zeroed_page(GFP_ATOMIC);
  4246. if (page == NULL) {
  4247. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  4248. "No memory to dump sense data\n");
  4249. return;
  4250. }
  4251. /* dump the sense data */
  4252. len = sprintf(page, PRINTK_HEADER
  4253. " I/O status report for device %s:\n",
  4254. dev_name(&device->cdev->dev));
  4255. len += sprintf(page + len, PRINTK_HEADER
  4256. " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
  4257. "CS:%02X RC:%d\n",
  4258. req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
  4259. scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
  4260. scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
  4261. req ? req->intrc : 0);
  4262. len += sprintf(page + len, PRINTK_HEADER
  4263. " device %s: Failing CCW: %p\n",
  4264. dev_name(&device->cdev->dev),
  4265. (void *) (addr_t) irb->scsw.cmd.cpa);
  4266. if (irb->esw.esw0.erw.cons) {
  4267. for (sl = 0; sl < 4; sl++) {
  4268. len += sprintf(page + len, PRINTK_HEADER
  4269. " Sense(hex) %2d-%2d:",
  4270. (8 * sl), ((8 * sl) + 7));
  4271. for (sct = 0; sct < 8; sct++) {
  4272. len += sprintf(page + len, " %02x",
  4273. irb->ecw[8 * sl + sct]);
  4274. }
  4275. len += sprintf(page + len, "\n");
  4276. }
  4277. if (irb->ecw[27] & DASD_SENSE_BIT_0) {
  4278. /* 24 Byte Sense Data */
  4279. sprintf(page + len, PRINTK_HEADER
  4280. " 24 Byte: %x MSG %x, "
  4281. "%s MSGb to SYSOP\n",
  4282. irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
  4283. irb->ecw[1] & 0x10 ? "" : "no");
  4284. } else {
  4285. /* 32 Byte Sense Data */
  4286. sprintf(page + len, PRINTK_HEADER
  4287. " 32 Byte: Format: %x "
  4288. "Exception class %x\n",
  4289. irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
  4290. }
  4291. } else {
  4292. sprintf(page + len, PRINTK_HEADER
  4293. " SORRY - NO VALID SENSE AVAILABLE\n");
  4294. }
  4295. printk(KERN_ERR "%s", page);
  4296. if (req) {
  4297. /* req == NULL for unsolicited interrupts */
  4298. /* dump the Channel Program (max 140 Bytes per line) */
  4299. /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
  4300. first = req->cpaddr;
  4301. for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
  4302. to = min(first + 6, last);
  4303. len = sprintf(page, PRINTK_HEADER
  4304. " Related CP in req: %p\n", req);
  4305. dasd_eckd_dump_ccw_range(first, to, page + len);
  4306. printk(KERN_ERR "%s", page);
  4307. /* print failing CCW area (maximum 4) */
  4308. /* scsw->cda is either valid or zero */
  4309. len = 0;
  4310. from = ++to;
  4311. fail = (struct ccw1 *)(addr_t)
  4312. irb->scsw.cmd.cpa; /* failing CCW */
  4313. if (from < fail - 2) {
  4314. from = fail - 2; /* there is a gap - print header */
  4315. len += sprintf(page, PRINTK_HEADER "......\n");
  4316. }
  4317. to = min(fail + 1, last);
  4318. len += dasd_eckd_dump_ccw_range(from, to, page + len);
  4319. /* print last CCWs (maximum 2) */
  4320. from = max(from, ++to);
  4321. if (from < last - 1) {
  4322. from = last - 1; /* there is a gap - print header */
  4323. len += sprintf(page + len, PRINTK_HEADER "......\n");
  4324. }
  4325. len += dasd_eckd_dump_ccw_range(from, last, page + len);
  4326. if (len > 0)
  4327. printk(KERN_ERR "%s", page);
  4328. }
  4329. free_page((unsigned long) page);
  4330. }
  4331. /*
  4332. * Print sense data from a tcw.
  4333. */
  4334. static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
  4335. struct dasd_ccw_req *req, struct irb *irb)
  4336. {
  4337. char *page;
  4338. int len, sl, sct, residual;
  4339. struct tsb *tsb;
  4340. u8 *sense, *rcq;
  4341. page = (char *) get_zeroed_page(GFP_ATOMIC);
  4342. if (page == NULL) {
  4343. DBF_DEV_EVENT(DBF_WARNING, device, " %s",
  4344. "No memory to dump sense data");
  4345. return;
  4346. }
  4347. /* dump the sense data */
  4348. len = sprintf(page, PRINTK_HEADER
  4349. " I/O status report for device %s:\n",
  4350. dev_name(&device->cdev->dev));
  4351. len += sprintf(page + len, PRINTK_HEADER
  4352. " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
  4353. "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
  4354. req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
  4355. scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
  4356. scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
  4357. irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
  4358. req ? req->intrc : 0);
  4359. len += sprintf(page + len, PRINTK_HEADER
  4360. " device %s: Failing TCW: %p\n",
  4361. dev_name(&device->cdev->dev),
  4362. (void *) (addr_t) irb->scsw.tm.tcw);
  4363. tsb = NULL;
  4364. sense = NULL;
  4365. if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
  4366. tsb = tcw_get_tsb(
  4367. (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
  4368. if (tsb) {
  4369. len += sprintf(page + len, PRINTK_HEADER
  4370. " tsb->length %d\n", tsb->length);
  4371. len += sprintf(page + len, PRINTK_HEADER
  4372. " tsb->flags %x\n", tsb->flags);
  4373. len += sprintf(page + len, PRINTK_HEADER
  4374. " tsb->dcw_offset %d\n", tsb->dcw_offset);
  4375. len += sprintf(page + len, PRINTK_HEADER
  4376. " tsb->count %d\n", tsb->count);
  4377. residual = tsb->count - 28;
  4378. len += sprintf(page + len, PRINTK_HEADER
  4379. " residual %d\n", residual);
  4380. switch (tsb->flags & 0x07) {
  4381. case 1: /* tsa_iostat */
  4382. len += sprintf(page + len, PRINTK_HEADER
  4383. " tsb->tsa.iostat.dev_time %d\n",
  4384. tsb->tsa.iostat.dev_time);
  4385. len += sprintf(page + len, PRINTK_HEADER
  4386. " tsb->tsa.iostat.def_time %d\n",
  4387. tsb->tsa.iostat.def_time);
  4388. len += sprintf(page + len, PRINTK_HEADER
  4389. " tsb->tsa.iostat.queue_time %d\n",
  4390. tsb->tsa.iostat.queue_time);
  4391. len += sprintf(page + len, PRINTK_HEADER
  4392. " tsb->tsa.iostat.dev_busy_time %d\n",
  4393. tsb->tsa.iostat.dev_busy_time);
  4394. len += sprintf(page + len, PRINTK_HEADER
  4395. " tsb->tsa.iostat.dev_act_time %d\n",
  4396. tsb->tsa.iostat.dev_act_time);
  4397. sense = tsb->tsa.iostat.sense;
  4398. break;
  4399. case 2: /* ts_ddpc */
  4400. len += sprintf(page + len, PRINTK_HEADER
  4401. " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
  4402. for (sl = 0; sl < 2; sl++) {
  4403. len += sprintf(page + len, PRINTK_HEADER
  4404. " tsb->tsa.ddpc.rcq %2d-%2d: ",
  4405. (8 * sl), ((8 * sl) + 7));
  4406. rcq = tsb->tsa.ddpc.rcq;
  4407. for (sct = 0; sct < 8; sct++) {
  4408. len += sprintf(page + len, " %02x",
  4409. rcq[8 * sl + sct]);
  4410. }
  4411. len += sprintf(page + len, "\n");
  4412. }
  4413. sense = tsb->tsa.ddpc.sense;
  4414. break;
  4415. case 3: /* tsa_intrg */
  4416. len += sprintf(page + len, PRINTK_HEADER
  4417. " tsb->tsa.intrg.: not supportet yet\n");
  4418. break;
  4419. }
  4420. if (sense) {
  4421. for (sl = 0; sl < 4; sl++) {
  4422. len += sprintf(page + len, PRINTK_HEADER
  4423. " Sense(hex) %2d-%2d:",
  4424. (8 * sl), ((8 * sl) + 7));
  4425. for (sct = 0; sct < 8; sct++) {
  4426. len += sprintf(page + len, " %02x",
  4427. sense[8 * sl + sct]);
  4428. }
  4429. len += sprintf(page + len, "\n");
  4430. }
  4431. if (sense[27] & DASD_SENSE_BIT_0) {
  4432. /* 24 Byte Sense Data */
  4433. sprintf(page + len, PRINTK_HEADER
  4434. " 24 Byte: %x MSG %x, "
  4435. "%s MSGb to SYSOP\n",
  4436. sense[7] >> 4, sense[7] & 0x0f,
  4437. sense[1] & 0x10 ? "" : "no");
  4438. } else {
  4439. /* 32 Byte Sense Data */
  4440. sprintf(page + len, PRINTK_HEADER
  4441. " 32 Byte: Format: %x "
  4442. "Exception class %x\n",
  4443. sense[6] & 0x0f, sense[22] >> 4);
  4444. }
  4445. } else {
  4446. sprintf(page + len, PRINTK_HEADER
  4447. " SORRY - NO VALID SENSE AVAILABLE\n");
  4448. }
  4449. } else {
  4450. sprintf(page + len, PRINTK_HEADER
  4451. " SORRY - NO TSB DATA AVAILABLE\n");
  4452. }
  4453. printk(KERN_ERR "%s", page);
  4454. free_page((unsigned long) page);
  4455. }
  4456. static void dasd_eckd_dump_sense(struct dasd_device *device,
  4457. struct dasd_ccw_req *req, struct irb *irb)
  4458. {
  4459. u8 *sense = dasd_get_sense(irb);
  4460. if (scsw_is_tm(&irb->scsw)) {
  4461. /*
  4462. * In some cases the 'File Protected' or 'Incorrect Length'
  4463. * error might be expected and log messages shouldn't be written
  4464. * then. Check if the according suppress bit is set.
  4465. */
  4466. if (sense && (sense[1] & SNS1_FILE_PROTECTED) &&
  4467. test_bit(DASD_CQR_SUPPRESS_FP, &req->flags))
  4468. return;
  4469. if (scsw_cstat(&irb->scsw) == 0x40 &&
  4470. test_bit(DASD_CQR_SUPPRESS_IL, &req->flags))
  4471. return;
  4472. dasd_eckd_dump_sense_tcw(device, req, irb);
  4473. } else {
  4474. /*
  4475. * In some cases the 'No Record Found' error might be expected
  4476. * and log messages shouldn't be written then. Check if the
  4477. * according suppress bit is set.
  4478. */
  4479. if (sense && sense[1] & SNS1_NO_REC_FOUND &&
  4480. test_bit(DASD_CQR_SUPPRESS_NRF, &req->flags))
  4481. return;
  4482. dasd_eckd_dump_sense_ccw(device, req, irb);
  4483. }
  4484. }
  4485. static int dasd_eckd_pm_freeze(struct dasd_device *device)
  4486. {
  4487. /*
  4488. * the device should be disconnected from our LCU structure
  4489. * on restore we will reconnect it and reread LCU specific
  4490. * information like PAV support that might have changed
  4491. */
  4492. dasd_alias_remove_device(device);
  4493. dasd_alias_disconnect_device_from_lcu(device);
  4494. return 0;
  4495. }
  4496. static int dasd_eckd_restore_device(struct dasd_device *device)
  4497. {
  4498. struct dasd_eckd_private *private = device->private;
  4499. struct dasd_eckd_characteristics temp_rdc_data;
  4500. int rc;
  4501. struct dasd_uid temp_uid;
  4502. unsigned long flags;
  4503. unsigned long cqr_flags = 0;
  4504. /* Read Configuration Data */
  4505. rc = dasd_eckd_read_conf(device);
  4506. if (rc) {
  4507. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  4508. "Read configuration data failed, rc=%d", rc);
  4509. goto out_err;
  4510. }
  4511. dasd_eckd_get_uid(device, &temp_uid);
  4512. /* Generate device unique id */
  4513. rc = dasd_eckd_generate_uid(device);
  4514. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  4515. if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
  4516. dev_err(&device->cdev->dev, "The UID of the DASD has "
  4517. "changed\n");
  4518. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  4519. if (rc)
  4520. goto out_err;
  4521. /* register lcu with alias handling, enable PAV if this is a new lcu */
  4522. rc = dasd_alias_make_device_known_to_lcu(device);
  4523. if (rc)
  4524. goto out_err;
  4525. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr_flags);
  4526. dasd_eckd_validate_server(device, cqr_flags);
  4527. /* RE-Read Configuration Data */
  4528. rc = dasd_eckd_read_conf(device);
  4529. if (rc) {
  4530. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  4531. "Read configuration data failed, rc=%d", rc);
  4532. goto out_err2;
  4533. }
  4534. /* Read Feature Codes */
  4535. dasd_eckd_read_features(device);
  4536. /* Read Device Characteristics */
  4537. rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
  4538. &temp_rdc_data, 64);
  4539. if (rc) {
  4540. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  4541. "Read device characteristic failed, rc=%d", rc);
  4542. goto out_err2;
  4543. }
  4544. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  4545. memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
  4546. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  4547. /* add device to alias management */
  4548. dasd_alias_add_device(device);
  4549. return 0;
  4550. out_err2:
  4551. dasd_alias_disconnect_device_from_lcu(device);
  4552. out_err:
  4553. return -1;
  4554. }
  4555. static int dasd_eckd_reload_device(struct dasd_device *device)
  4556. {
  4557. struct dasd_eckd_private *private = device->private;
  4558. int rc, old_base;
  4559. char print_uid[60];
  4560. struct dasd_uid uid;
  4561. unsigned long flags;
  4562. /*
  4563. * remove device from alias handling to prevent new requests
  4564. * from being scheduled on the wrong alias device
  4565. */
  4566. dasd_alias_remove_device(device);
  4567. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  4568. old_base = private->uid.base_unit_addr;
  4569. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  4570. /* Read Configuration Data */
  4571. rc = dasd_eckd_read_conf(device);
  4572. if (rc)
  4573. goto out_err;
  4574. rc = dasd_eckd_generate_uid(device);
  4575. if (rc)
  4576. goto out_err;
  4577. /*
  4578. * update unit address configuration and
  4579. * add device to alias management
  4580. */
  4581. dasd_alias_update_add_device(device);
  4582. dasd_eckd_get_uid(device, &uid);
  4583. if (old_base != uid.base_unit_addr) {
  4584. if (strlen(uid.vduit) > 0)
  4585. snprintf(print_uid, sizeof(print_uid),
  4586. "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
  4587. uid.ssid, uid.base_unit_addr, uid.vduit);
  4588. else
  4589. snprintf(print_uid, sizeof(print_uid),
  4590. "%s.%s.%04x.%02x", uid.vendor, uid.serial,
  4591. uid.ssid, uid.base_unit_addr);
  4592. dev_info(&device->cdev->dev,
  4593. "An Alias device was reassigned to a new base device "
  4594. "with UID: %s\n", print_uid);
  4595. }
  4596. return 0;
  4597. out_err:
  4598. return -1;
  4599. }
  4600. static int dasd_eckd_read_message_buffer(struct dasd_device *device,
  4601. struct dasd_rssd_messages *messages,
  4602. __u8 lpum)
  4603. {
  4604. struct dasd_rssd_messages *message_buf;
  4605. struct dasd_psf_prssd_data *prssdp;
  4606. struct dasd_ccw_req *cqr;
  4607. struct ccw1 *ccw;
  4608. int rc;
  4609. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  4610. (sizeof(struct dasd_psf_prssd_data) +
  4611. sizeof(struct dasd_rssd_messages)),
  4612. device);
  4613. if (IS_ERR(cqr)) {
  4614. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  4615. "Could not allocate read message buffer request");
  4616. return PTR_ERR(cqr);
  4617. }
  4618. cqr->lpm = lpum;
  4619. retry:
  4620. cqr->startdev = device;
  4621. cqr->memdev = device;
  4622. cqr->block = NULL;
  4623. cqr->expires = 10 * HZ;
  4624. set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
  4625. /* dasd_sleep_on_immediatly does not do complex error
  4626. * recovery so clear erp flag and set retry counter to
  4627. * do basic erp */
  4628. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  4629. cqr->retries = 256;
  4630. /* Prepare for Read Subsystem Data */
  4631. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  4632. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  4633. prssdp->order = PSF_ORDER_PRSSD;
  4634. prssdp->suborder = 0x03; /* Message Buffer */
  4635. /* all other bytes of prssdp must be zero */
  4636. ccw = cqr->cpaddr;
  4637. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  4638. ccw->count = sizeof(struct dasd_psf_prssd_data);
  4639. ccw->flags |= CCW_FLAG_CC;
  4640. ccw->flags |= CCW_FLAG_SLI;
  4641. ccw->cda = (__u32)(addr_t) prssdp;
  4642. /* Read Subsystem Data - message buffer */
  4643. message_buf = (struct dasd_rssd_messages *) (prssdp + 1);
  4644. memset(message_buf, 0, sizeof(struct dasd_rssd_messages));
  4645. ccw++;
  4646. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  4647. ccw->count = sizeof(struct dasd_rssd_messages);
  4648. ccw->flags |= CCW_FLAG_SLI;
  4649. ccw->cda = (__u32)(addr_t) message_buf;
  4650. cqr->buildclk = get_tod_clock();
  4651. cqr->status = DASD_CQR_FILLED;
  4652. rc = dasd_sleep_on_immediatly(cqr);
  4653. if (rc == 0) {
  4654. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  4655. message_buf = (struct dasd_rssd_messages *)
  4656. (prssdp + 1);
  4657. memcpy(messages, message_buf,
  4658. sizeof(struct dasd_rssd_messages));
  4659. } else if (cqr->lpm) {
  4660. /*
  4661. * on z/VM we might not be able to do I/O on the requested path
  4662. * but instead we get the required information on any path
  4663. * so retry with open path mask
  4664. */
  4665. cqr->lpm = 0;
  4666. goto retry;
  4667. } else
  4668. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  4669. "Reading messages failed with rc=%d\n"
  4670. , rc);
  4671. dasd_sfree_request(cqr, cqr->memdev);
  4672. return rc;
  4673. }
  4674. static int dasd_eckd_query_host_access(struct dasd_device *device,
  4675. struct dasd_psf_query_host_access *data)
  4676. {
  4677. struct dasd_eckd_private *private = device->private;
  4678. struct dasd_psf_query_host_access *host_access;
  4679. struct dasd_psf_prssd_data *prssdp;
  4680. struct dasd_ccw_req *cqr;
  4681. struct ccw1 *ccw;
  4682. int rc;
  4683. /* not available for HYPER PAV alias devices */
  4684. if (!device->block && private->lcu->pav == HYPER_PAV)
  4685. return -EOPNOTSUPP;
  4686. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  4687. sizeof(struct dasd_psf_prssd_data) + 1,
  4688. device);
  4689. if (IS_ERR(cqr)) {
  4690. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  4691. "Could not allocate read message buffer request");
  4692. return PTR_ERR(cqr);
  4693. }
  4694. host_access = kzalloc(sizeof(*host_access), GFP_KERNEL | GFP_DMA);
  4695. if (!host_access) {
  4696. dasd_sfree_request(cqr, device);
  4697. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  4698. "Could not allocate host_access buffer");
  4699. return -ENOMEM;
  4700. }
  4701. cqr->startdev = device;
  4702. cqr->memdev = device;
  4703. cqr->block = NULL;
  4704. cqr->retries = 256;
  4705. cqr->expires = 10 * HZ;
  4706. /* Prepare for Read Subsystem Data */
  4707. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  4708. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  4709. prssdp->order = PSF_ORDER_PRSSD;
  4710. prssdp->suborder = PSF_SUBORDER_QHA; /* query host access */
  4711. /* LSS and Volume that will be queried */
  4712. prssdp->lss = private->ned->ID;
  4713. prssdp->volume = private->ned->unit_addr;
  4714. /* all other bytes of prssdp must be zero */
  4715. ccw = cqr->cpaddr;
  4716. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  4717. ccw->count = sizeof(struct dasd_psf_prssd_data);
  4718. ccw->flags |= CCW_FLAG_CC;
  4719. ccw->flags |= CCW_FLAG_SLI;
  4720. ccw->cda = (__u32)(addr_t) prssdp;
  4721. /* Read Subsystem Data - query host access */
  4722. ccw++;
  4723. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  4724. ccw->count = sizeof(struct dasd_psf_query_host_access);
  4725. ccw->flags |= CCW_FLAG_SLI;
  4726. ccw->cda = (__u32)(addr_t) host_access;
  4727. cqr->buildclk = get_tod_clock();
  4728. cqr->status = DASD_CQR_FILLED;
  4729. rc = dasd_sleep_on_interruptible(cqr);
  4730. if (rc == 0) {
  4731. *data = *host_access;
  4732. } else {
  4733. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  4734. "Reading host access data failed with rc=%d\n",
  4735. rc);
  4736. rc = -EOPNOTSUPP;
  4737. }
  4738. dasd_sfree_request(cqr, cqr->memdev);
  4739. kfree(host_access);
  4740. return rc;
  4741. }
  4742. /*
  4743. * return number of grouped devices
  4744. */
  4745. static int dasd_eckd_host_access_count(struct dasd_device *device)
  4746. {
  4747. struct dasd_psf_query_host_access *access;
  4748. struct dasd_ckd_path_group_entry *entry;
  4749. struct dasd_ckd_host_information *info;
  4750. int count = 0;
  4751. int rc, i;
  4752. access = kzalloc(sizeof(*access), GFP_NOIO);
  4753. if (!access) {
  4754. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  4755. "Could not allocate access buffer");
  4756. return -ENOMEM;
  4757. }
  4758. rc = dasd_eckd_query_host_access(device, access);
  4759. if (rc) {
  4760. kfree(access);
  4761. return rc;
  4762. }
  4763. info = (struct dasd_ckd_host_information *)
  4764. access->host_access_information;
  4765. for (i = 0; i < info->entry_count; i++) {
  4766. entry = (struct dasd_ckd_path_group_entry *)
  4767. (info->entry + i * info->entry_size);
  4768. if (entry->status_flags & DASD_ECKD_PG_GROUPED)
  4769. count++;
  4770. }
  4771. kfree(access);
  4772. return count;
  4773. }
  4774. /*
  4775. * write host access information to a sequential file
  4776. */
  4777. static int dasd_hosts_print(struct dasd_device *device, struct seq_file *m)
  4778. {
  4779. struct dasd_psf_query_host_access *access;
  4780. struct dasd_ckd_path_group_entry *entry;
  4781. struct dasd_ckd_host_information *info;
  4782. char sysplex[9] = "";
  4783. int rc, i, j;
  4784. access = kzalloc(sizeof(*access), GFP_NOIO);
  4785. if (!access) {
  4786. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  4787. "Could not allocate access buffer");
  4788. return -ENOMEM;
  4789. }
  4790. rc = dasd_eckd_query_host_access(device, access);
  4791. if (rc) {
  4792. kfree(access);
  4793. return rc;
  4794. }
  4795. info = (struct dasd_ckd_host_information *)
  4796. access->host_access_information;
  4797. for (i = 0; i < info->entry_count; i++) {
  4798. entry = (struct dasd_ckd_path_group_entry *)
  4799. (info->entry + i * info->entry_size);
  4800. /* PGID */
  4801. seq_puts(m, "pgid ");
  4802. for (j = 0; j < 11; j++)
  4803. seq_printf(m, "%02x", entry->pgid[j]);
  4804. seq_putc(m, '\n');
  4805. /* FLAGS */
  4806. seq_printf(m, "status_flags %02x\n", entry->status_flags);
  4807. /* SYSPLEX NAME */
  4808. memcpy(&sysplex, &entry->sysplex_name, sizeof(sysplex) - 1);
  4809. EBCASC(sysplex, sizeof(sysplex));
  4810. seq_printf(m, "sysplex_name %8s\n", sysplex);
  4811. /* SUPPORTED CYLINDER */
  4812. seq_printf(m, "supported_cylinder %d\n", entry->cylinder);
  4813. /* TIMESTAMP */
  4814. seq_printf(m, "timestamp %lu\n", (unsigned long)
  4815. entry->timestamp);
  4816. }
  4817. kfree(access);
  4818. return 0;
  4819. }
  4820. /*
  4821. * Perform Subsystem Function - CUIR response
  4822. */
  4823. static int
  4824. dasd_eckd_psf_cuir_response(struct dasd_device *device, int response,
  4825. __u32 message_id,
  4826. struct channel_path_desc *desc,
  4827. struct subchannel_id sch_id)
  4828. {
  4829. struct dasd_psf_cuir_response *psf_cuir;
  4830. struct dasd_ccw_req *cqr;
  4831. struct ccw1 *ccw;
  4832. int rc;
  4833. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
  4834. sizeof(struct dasd_psf_cuir_response),
  4835. device);
  4836. if (IS_ERR(cqr)) {
  4837. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  4838. "Could not allocate PSF-CUIR request");
  4839. return PTR_ERR(cqr);
  4840. }
  4841. psf_cuir = (struct dasd_psf_cuir_response *)cqr->data;
  4842. psf_cuir->order = PSF_ORDER_CUIR_RESPONSE;
  4843. psf_cuir->cc = response;
  4844. if (desc)
  4845. psf_cuir->chpid = desc->chpid;
  4846. psf_cuir->message_id = message_id;
  4847. psf_cuir->cssid = sch_id.cssid;
  4848. psf_cuir->ssid = sch_id.ssid;
  4849. ccw = cqr->cpaddr;
  4850. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  4851. ccw->cda = (__u32)(addr_t)psf_cuir;
  4852. ccw->flags = CCW_FLAG_SLI;
  4853. ccw->count = sizeof(struct dasd_psf_cuir_response);
  4854. cqr->startdev = device;
  4855. cqr->memdev = device;
  4856. cqr->block = NULL;
  4857. cqr->retries = 256;
  4858. cqr->expires = 10*HZ;
  4859. cqr->buildclk = get_tod_clock();
  4860. cqr->status = DASD_CQR_FILLED;
  4861. set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
  4862. rc = dasd_sleep_on(cqr);
  4863. dasd_sfree_request(cqr, cqr->memdev);
  4864. return rc;
  4865. }
  4866. /*
  4867. * return configuration data that is referenced by record selector
  4868. * if a record selector is specified or per default return the
  4869. * conf_data pointer for the path specified by lpum
  4870. */
  4871. static struct dasd_conf_data *dasd_eckd_get_ref_conf(struct dasd_device *device,
  4872. __u8 lpum,
  4873. struct dasd_cuir_message *cuir)
  4874. {
  4875. struct dasd_eckd_private *private = device->private;
  4876. struct dasd_conf_data *conf_data;
  4877. int path, pos;
  4878. if (cuir->record_selector == 0)
  4879. goto out;
  4880. for (path = 0x80, pos = 0; path; path >>= 1, pos++) {
  4881. conf_data = private->path_conf_data[pos];
  4882. if (conf_data->gneq.record_selector ==
  4883. cuir->record_selector)
  4884. return conf_data;
  4885. }
  4886. out:
  4887. return private->path_conf_data[pathmask_to_pos(lpum)];
  4888. }
  4889. /*
  4890. * This function determines the scope of a reconfiguration request by
  4891. * analysing the path and device selection data provided in the CUIR request.
  4892. * Returns a path mask containing CUIR affected paths for the give device.
  4893. *
  4894. * If the CUIR request does not contain the required information return the
  4895. * path mask of the path the attention message for the CUIR request was reveived
  4896. * on.
  4897. */
  4898. static int dasd_eckd_cuir_scope(struct dasd_device *device, __u8 lpum,
  4899. struct dasd_cuir_message *cuir)
  4900. {
  4901. struct dasd_eckd_private *private = device->private;
  4902. struct dasd_conf_data *ref_conf_data;
  4903. unsigned long bitmask = 0, mask = 0;
  4904. struct dasd_conf_data *conf_data;
  4905. unsigned int pos, path;
  4906. char *ref_gneq, *gneq;
  4907. char *ref_ned, *ned;
  4908. int tbcpm = 0;
  4909. /* if CUIR request does not specify the scope use the path
  4910. the attention message was presented on */
  4911. if (!cuir->ned_map ||
  4912. !(cuir->neq_map[0] | cuir->neq_map[1] | cuir->neq_map[2]))
  4913. return lpum;
  4914. /* get reference conf data */
  4915. ref_conf_data = dasd_eckd_get_ref_conf(device, lpum, cuir);
  4916. /* reference ned is determined by ned_map field */
  4917. pos = 8 - ffs(cuir->ned_map);
  4918. ref_ned = (char *)&ref_conf_data->neds[pos];
  4919. ref_gneq = (char *)&ref_conf_data->gneq;
  4920. /* transfer 24 bit neq_map to mask */
  4921. mask = cuir->neq_map[2];
  4922. mask |= cuir->neq_map[1] << 8;
  4923. mask |= cuir->neq_map[0] << 16;
  4924. for (path = 0x80; path; path >>= 1) {
  4925. /* initialise data per path */
  4926. bitmask = mask;
  4927. pos = pathmask_to_pos(path);
  4928. conf_data = private->path_conf_data[pos];
  4929. pos = 8 - ffs(cuir->ned_map);
  4930. ned = (char *) &conf_data->neds[pos];
  4931. /* compare reference ned and per path ned */
  4932. if (memcmp(ref_ned, ned, sizeof(*ned)) != 0)
  4933. continue;
  4934. gneq = (char *)&conf_data->gneq;
  4935. /* compare reference gneq and per_path gneq under
  4936. 24 bit mask where mask bit 0 equals byte 7 of
  4937. the gneq and mask bit 24 equals byte 31 */
  4938. while (bitmask) {
  4939. pos = ffs(bitmask) - 1;
  4940. if (memcmp(&ref_gneq[31 - pos], &gneq[31 - pos], 1)
  4941. != 0)
  4942. break;
  4943. clear_bit(pos, &bitmask);
  4944. }
  4945. if (bitmask)
  4946. continue;
  4947. /* device and path match the reference values
  4948. add path to CUIR scope */
  4949. tbcpm |= path;
  4950. }
  4951. return tbcpm;
  4952. }
  4953. static void dasd_eckd_cuir_notify_user(struct dasd_device *device,
  4954. unsigned long paths,
  4955. struct subchannel_id sch_id, int action)
  4956. {
  4957. struct channel_path_desc *desc;
  4958. int pos;
  4959. while (paths) {
  4960. /* get position of bit in mask */
  4961. pos = ffs(paths) - 1;
  4962. /* get channel path descriptor from this position */
  4963. desc = ccw_device_get_chp_desc(device->cdev, 7 - pos);
  4964. if (action == CUIR_QUIESCE)
  4965. pr_warn("Service on the storage server caused path "
  4966. "%x.%02x to go offline", sch_id.cssid,
  4967. desc ? desc->chpid : 0);
  4968. else if (action == CUIR_RESUME)
  4969. pr_info("Path %x.%02x is back online after service "
  4970. "on the storage server", sch_id.cssid,
  4971. desc ? desc->chpid : 0);
  4972. kfree(desc);
  4973. clear_bit(pos, &paths);
  4974. }
  4975. }
  4976. static int dasd_eckd_cuir_remove_path(struct dasd_device *device, __u8 lpum,
  4977. struct dasd_cuir_message *cuir)
  4978. {
  4979. unsigned long tbcpm;
  4980. tbcpm = dasd_eckd_cuir_scope(device, lpum, cuir);
  4981. /* nothing to do if path is not in use */
  4982. if (!(device->path_data.opm & tbcpm))
  4983. return 0;
  4984. if (!(device->path_data.opm & ~tbcpm)) {
  4985. /* no path would be left if the CUIR action is taken
  4986. return error */
  4987. return -EINVAL;
  4988. }
  4989. /* remove device from operational path mask */
  4990. device->path_data.opm &= ~tbcpm;
  4991. device->path_data.cuirpm |= tbcpm;
  4992. return tbcpm;
  4993. }
  4994. /*
  4995. * walk through all devices and build a path mask to quiesce them
  4996. * return an error if the last path to a device would be removed
  4997. *
  4998. * if only part of the devices are quiesced and an error
  4999. * occurs no onlining necessary, the storage server will
  5000. * notify the already set offline devices again
  5001. */
  5002. static int dasd_eckd_cuir_quiesce(struct dasd_device *device, __u8 lpum,
  5003. struct subchannel_id sch_id,
  5004. struct dasd_cuir_message *cuir)
  5005. {
  5006. struct dasd_eckd_private *private = device->private;
  5007. struct alias_pav_group *pavgroup, *tempgroup;
  5008. struct dasd_device *dev, *n;
  5009. unsigned long paths = 0;
  5010. unsigned long flags;
  5011. int tbcpm;
  5012. /* active devices */
  5013. list_for_each_entry_safe(dev, n, &private->lcu->active_devices,
  5014. alias_list) {
  5015. spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
  5016. tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
  5017. spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
  5018. if (tbcpm < 0)
  5019. goto out_err;
  5020. paths |= tbcpm;
  5021. }
  5022. /* inactive devices */
  5023. list_for_each_entry_safe(dev, n, &private->lcu->inactive_devices,
  5024. alias_list) {
  5025. spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
  5026. tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
  5027. spin_unlock_irqrestore(get_ccwdev_lock(dev->cdev), flags);
  5028. if (tbcpm < 0)
  5029. goto out_err;
  5030. paths |= tbcpm;
  5031. }
  5032. /* devices in PAV groups */
  5033. list_for_each_entry_safe(pavgroup, tempgroup,
  5034. &private->lcu->grouplist, group) {
  5035. list_for_each_entry_safe(dev, n, &pavgroup->baselist,
  5036. alias_list) {
  5037. spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
  5038. tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
  5039. spin_unlock_irqrestore(
  5040. get_ccwdev_lock(dev->cdev), flags);
  5041. if (tbcpm < 0)
  5042. goto out_err;
  5043. paths |= tbcpm;
  5044. }
  5045. list_for_each_entry_safe(dev, n, &pavgroup->aliaslist,
  5046. alias_list) {
  5047. spin_lock_irqsave(get_ccwdev_lock(dev->cdev), flags);
  5048. tbcpm = dasd_eckd_cuir_remove_path(dev, lpum, cuir);
  5049. spin_unlock_irqrestore(
  5050. get_ccwdev_lock(dev->cdev), flags);
  5051. if (tbcpm < 0)
  5052. goto out_err;
  5053. paths |= tbcpm;
  5054. }
  5055. }
  5056. /* notify user about all paths affected by CUIR action */
  5057. dasd_eckd_cuir_notify_user(device, paths, sch_id, CUIR_QUIESCE);
  5058. return 0;
  5059. out_err:
  5060. return tbcpm;
  5061. }
  5062. static int dasd_eckd_cuir_resume(struct dasd_device *device, __u8 lpum,
  5063. struct subchannel_id sch_id,
  5064. struct dasd_cuir_message *cuir)
  5065. {
  5066. struct dasd_eckd_private *private = device->private;
  5067. struct alias_pav_group *pavgroup, *tempgroup;
  5068. struct dasd_device *dev, *n;
  5069. unsigned long paths = 0;
  5070. int tbcpm;
  5071. /*
  5072. * the path may have been added through a generic path event before
  5073. * only trigger path verification if the path is not already in use
  5074. */
  5075. list_for_each_entry_safe(dev, n,
  5076. &private->lcu->active_devices,
  5077. alias_list) {
  5078. tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
  5079. paths |= tbcpm;
  5080. if (!(dev->path_data.opm & tbcpm)) {
  5081. dev->path_data.tbvpm |= tbcpm;
  5082. dasd_schedule_device_bh(dev);
  5083. }
  5084. }
  5085. list_for_each_entry_safe(dev, n,
  5086. &private->lcu->inactive_devices,
  5087. alias_list) {
  5088. tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
  5089. paths |= tbcpm;
  5090. if (!(dev->path_data.opm & tbcpm)) {
  5091. dev->path_data.tbvpm |= tbcpm;
  5092. dasd_schedule_device_bh(dev);
  5093. }
  5094. }
  5095. /* devices in PAV groups */
  5096. list_for_each_entry_safe(pavgroup, tempgroup,
  5097. &private->lcu->grouplist,
  5098. group) {
  5099. list_for_each_entry_safe(dev, n,
  5100. &pavgroup->baselist,
  5101. alias_list) {
  5102. tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
  5103. paths |= tbcpm;
  5104. if (!(dev->path_data.opm & tbcpm)) {
  5105. dev->path_data.tbvpm |= tbcpm;
  5106. dasd_schedule_device_bh(dev);
  5107. }
  5108. }
  5109. list_for_each_entry_safe(dev, n,
  5110. &pavgroup->aliaslist,
  5111. alias_list) {
  5112. tbcpm = dasd_eckd_cuir_scope(dev, lpum, cuir);
  5113. paths |= tbcpm;
  5114. if (!(dev->path_data.opm & tbcpm)) {
  5115. dev->path_data.tbvpm |= tbcpm;
  5116. dasd_schedule_device_bh(dev);
  5117. }
  5118. }
  5119. }
  5120. /* notify user about all paths affected by CUIR action */
  5121. dasd_eckd_cuir_notify_user(device, paths, sch_id, CUIR_RESUME);
  5122. return 0;
  5123. }
  5124. static void dasd_eckd_handle_cuir(struct dasd_device *device, void *messages,
  5125. __u8 lpum)
  5126. {
  5127. struct dasd_cuir_message *cuir = messages;
  5128. struct channel_path_desc *desc;
  5129. struct subchannel_id sch_id;
  5130. int pos, response;
  5131. DBF_DEV_EVENT(DBF_WARNING, device,
  5132. "CUIR request: %016llx %016llx %016llx %08x",
  5133. ((u64 *)cuir)[0], ((u64 *)cuir)[1], ((u64 *)cuir)[2],
  5134. ((u32 *)cuir)[3]);
  5135. ccw_device_get_schid(device->cdev, &sch_id);
  5136. pos = pathmask_to_pos(lpum);
  5137. desc = ccw_device_get_chp_desc(device->cdev, pos);
  5138. if (cuir->code == CUIR_QUIESCE) {
  5139. /* quiesce */
  5140. if (dasd_eckd_cuir_quiesce(device, lpum, sch_id, cuir))
  5141. response = PSF_CUIR_LAST_PATH;
  5142. else
  5143. response = PSF_CUIR_COMPLETED;
  5144. } else if (cuir->code == CUIR_RESUME) {
  5145. /* resume */
  5146. dasd_eckd_cuir_resume(device, lpum, sch_id, cuir);
  5147. response = PSF_CUIR_COMPLETED;
  5148. } else
  5149. response = PSF_CUIR_NOT_SUPPORTED;
  5150. dasd_eckd_psf_cuir_response(device, response,
  5151. cuir->message_id, desc, sch_id);
  5152. DBF_DEV_EVENT(DBF_WARNING, device,
  5153. "CUIR response: %d on message ID %08x", response,
  5154. cuir->message_id);
  5155. /* free descriptor copy */
  5156. kfree(desc);
  5157. /* to make sure there is no attention left schedule work again */
  5158. device->discipline->check_attention(device, lpum);
  5159. }
  5160. static void dasd_eckd_check_attention_work(struct work_struct *work)
  5161. {
  5162. struct check_attention_work_data *data;
  5163. struct dasd_rssd_messages *messages;
  5164. struct dasd_device *device;
  5165. int rc;
  5166. data = container_of(work, struct check_attention_work_data, worker);
  5167. device = data->device;
  5168. messages = kzalloc(sizeof(*messages), GFP_KERNEL);
  5169. if (!messages) {
  5170. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  5171. "Could not allocate attention message buffer");
  5172. goto out;
  5173. }
  5174. rc = dasd_eckd_read_message_buffer(device, messages, data->lpum);
  5175. if (rc)
  5176. goto out;
  5177. if (messages->length == ATTENTION_LENGTH_CUIR &&
  5178. messages->format == ATTENTION_FORMAT_CUIR)
  5179. dasd_eckd_handle_cuir(device, messages, data->lpum);
  5180. out:
  5181. dasd_put_device(device);
  5182. kfree(messages);
  5183. kfree(data);
  5184. }
  5185. static int dasd_eckd_check_attention(struct dasd_device *device, __u8 lpum)
  5186. {
  5187. struct check_attention_work_data *data;
  5188. data = kzalloc(sizeof(*data), GFP_ATOMIC);
  5189. if (!data)
  5190. return -ENOMEM;
  5191. INIT_WORK(&data->worker, dasd_eckd_check_attention_work);
  5192. dasd_get_device(device);
  5193. data->device = device;
  5194. data->lpum = lpum;
  5195. schedule_work(&data->worker);
  5196. return 0;
  5197. }
  5198. static struct ccw_driver dasd_eckd_driver = {
  5199. .driver = {
  5200. .name = "dasd-eckd",
  5201. .owner = THIS_MODULE,
  5202. },
  5203. .ids = dasd_eckd_ids,
  5204. .probe = dasd_eckd_probe,
  5205. .remove = dasd_generic_remove,
  5206. .set_offline = dasd_generic_set_offline,
  5207. .set_online = dasd_eckd_set_online,
  5208. .notify = dasd_generic_notify,
  5209. .path_event = dasd_generic_path_event,
  5210. .shutdown = dasd_generic_shutdown,
  5211. .freeze = dasd_generic_pm_freeze,
  5212. .thaw = dasd_generic_restore_device,
  5213. .restore = dasd_generic_restore_device,
  5214. .uc_handler = dasd_generic_uc_handler,
  5215. .int_class = IRQIO_DAS,
  5216. };
  5217. /*
  5218. * max_blocks is dependent on the amount of storage that is available
  5219. * in the static io buffer for each device. Currently each device has
  5220. * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
  5221. * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
  5222. * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
  5223. * addition we have one define extent ccw + 16 bytes of data and one
  5224. * locate record ccw + 16 bytes of data. That makes:
  5225. * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
  5226. * We want to fit two into the available memory so that we can immediately
  5227. * start the next request if one finishes off. That makes 249.5 blocks
  5228. * for one request. Give a little safety and the result is 240.
  5229. */
  5230. static struct dasd_discipline dasd_eckd_discipline = {
  5231. .owner = THIS_MODULE,
  5232. .name = "ECKD",
  5233. .ebcname = "ECKD",
  5234. .max_blocks = 190,
  5235. .check_device = dasd_eckd_check_characteristics,
  5236. .uncheck_device = dasd_eckd_uncheck_device,
  5237. .do_analysis = dasd_eckd_do_analysis,
  5238. .verify_path = dasd_eckd_verify_path,
  5239. .basic_to_ready = dasd_eckd_basic_to_ready,
  5240. .online_to_ready = dasd_eckd_online_to_ready,
  5241. .basic_to_known = dasd_eckd_basic_to_known,
  5242. .fill_geometry = dasd_eckd_fill_geometry,
  5243. .start_IO = dasd_start_IO,
  5244. .term_IO = dasd_term_IO,
  5245. .handle_terminated_request = dasd_eckd_handle_terminated_request,
  5246. .format_device = dasd_eckd_format_device,
  5247. .check_device_format = dasd_eckd_check_device_format,
  5248. .erp_action = dasd_eckd_erp_action,
  5249. .erp_postaction = dasd_eckd_erp_postaction,
  5250. .check_for_device_change = dasd_eckd_check_for_device_change,
  5251. .build_cp = dasd_eckd_build_alias_cp,
  5252. .free_cp = dasd_eckd_free_alias_cp,
  5253. .dump_sense = dasd_eckd_dump_sense,
  5254. .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
  5255. .fill_info = dasd_eckd_fill_info,
  5256. .ioctl = dasd_eckd_ioctl,
  5257. .freeze = dasd_eckd_pm_freeze,
  5258. .restore = dasd_eckd_restore_device,
  5259. .reload = dasd_eckd_reload_device,
  5260. .get_uid = dasd_eckd_get_uid,
  5261. .kick_validate = dasd_eckd_kick_validate_server,
  5262. .check_attention = dasd_eckd_check_attention,
  5263. .host_access_count = dasd_eckd_host_access_count,
  5264. .hosts_print = dasd_hosts_print,
  5265. };
  5266. static int __init
  5267. dasd_eckd_init(void)
  5268. {
  5269. int ret;
  5270. ASCEBC(dasd_eckd_discipline.ebcname, 4);
  5271. dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
  5272. GFP_KERNEL | GFP_DMA);
  5273. if (!dasd_reserve_req)
  5274. return -ENOMEM;
  5275. path_verification_worker = kmalloc(sizeof(*path_verification_worker),
  5276. GFP_KERNEL | GFP_DMA);
  5277. if (!path_verification_worker) {
  5278. kfree(dasd_reserve_req);
  5279. return -ENOMEM;
  5280. }
  5281. rawpadpage = (void *)__get_free_page(GFP_KERNEL);
  5282. if (!rawpadpage) {
  5283. kfree(path_verification_worker);
  5284. kfree(dasd_reserve_req);
  5285. return -ENOMEM;
  5286. }
  5287. ret = ccw_driver_register(&dasd_eckd_driver);
  5288. if (!ret)
  5289. wait_for_device_probe();
  5290. else {
  5291. kfree(path_verification_worker);
  5292. kfree(dasd_reserve_req);
  5293. free_page((unsigned long)rawpadpage);
  5294. }
  5295. return ret;
  5296. }
  5297. static void __exit
  5298. dasd_eckd_cleanup(void)
  5299. {
  5300. ccw_driver_unregister(&dasd_eckd_driver);
  5301. kfree(path_verification_worker);
  5302. kfree(dasd_reserve_req);
  5303. free_page((unsigned long)rawpadpage);
  5304. }
  5305. module_init(dasd_eckd_init);
  5306. module_exit(dasd_eckd_cleanup);