dasd_eckd.c 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338
  1. /*
  2. * File...........: linux/drivers/s390/block/dasd_eckd.c
  3. * Author(s)......: Holger Smolinski <Holger.Smolinski@de.ibm.com>
  4. * Horst Hummel <Horst.Hummel@de.ibm.com>
  5. * Carsten Otte <Cotte@de.ibm.com>
  6. * Martin Schwidefsky <schwidefsky@de.ibm.com>
  7. * Bugreports.to..: <Linux390@de.ibm.com>
  8. * Copyright IBM Corp. 1999, 2009
  9. * EMC Symmetrix ioctl Copyright EMC Corporation, 2008
  10. * Author.........: Nigel Hislop <hislop_nigel@emc.com>
  11. */
  12. #define KMSG_COMPONENT "dasd-eckd"
  13. #include <linux/stddef.h>
  14. #include <linux/kernel.h>
  15. #include <linux/slab.h>
  16. #include <linux/hdreg.h> /* HDIO_GETGEO */
  17. #include <linux/bio.h>
  18. #include <linux/module.h>
  19. #include <linux/compat.h>
  20. #include <linux/init.h>
  21. #include <asm/debug.h>
  22. #include <asm/idals.h>
  23. #include <asm/ebcdic.h>
  24. #include <asm/io.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/cio.h>
  27. #include <asm/ccwdev.h>
  28. #include <asm/itcw.h>
  29. #include "dasd_int.h"
  30. #include "dasd_eckd.h"
  31. #include "../cio/chsc.h"
  32. #ifdef PRINTK_HEADER
  33. #undef PRINTK_HEADER
  34. #endif /* PRINTK_HEADER */
  35. #define PRINTK_HEADER "dasd(eckd):"
  36. #define ECKD_C0(i) (i->home_bytes)
  37. #define ECKD_F(i) (i->formula)
  38. #define ECKD_F1(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f1):\
  39. (i->factors.f_0x02.f1))
  40. #define ECKD_F2(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f2):\
  41. (i->factors.f_0x02.f2))
  42. #define ECKD_F3(i) (ECKD_F(i)==0x01?(i->factors.f_0x01.f3):\
  43. (i->factors.f_0x02.f3))
  44. #define ECKD_F4(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f4):0)
  45. #define ECKD_F5(i) (ECKD_F(i)==0x02?(i->factors.f_0x02.f5):0)
  46. #define ECKD_F6(i) (i->factor6)
  47. #define ECKD_F7(i) (i->factor7)
  48. #define ECKD_F8(i) (i->factor8)
  49. /*
  50. * raw track access always map to 64k in memory
  51. * so it maps to 16 blocks of 4k per track
  52. */
  53. #define DASD_RAW_BLOCK_PER_TRACK 16
  54. #define DASD_RAW_BLOCKSIZE 4096
  55. /* 64k are 128 x 512 byte sectors */
  56. #define DASD_RAW_SECTORS_PER_TRACK 128
  57. MODULE_LICENSE("GPL");
  58. static struct dasd_discipline dasd_eckd_discipline;
  59. /* The ccw bus type uses this table to find devices that it sends to
  60. * dasd_eckd_probe */
  61. static struct ccw_device_id dasd_eckd_ids[] = {
  62. { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3390, 0), .driver_info = 0x1},
  63. { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3390, 0), .driver_info = 0x2},
  64. { CCW_DEVICE_DEVTYPE (0x3880, 0, 0x3380, 0), .driver_info = 0x3},
  65. { CCW_DEVICE_DEVTYPE (0x3990, 0, 0x3380, 0), .driver_info = 0x4},
  66. { CCW_DEVICE_DEVTYPE (0x2105, 0, 0x3380, 0), .driver_info = 0x5},
  67. { CCW_DEVICE_DEVTYPE (0x9343, 0, 0x9345, 0), .driver_info = 0x6},
  68. { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3390, 0), .driver_info = 0x7},
  69. { CCW_DEVICE_DEVTYPE (0x2107, 0, 0x3380, 0), .driver_info = 0x8},
  70. { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3390, 0), .driver_info = 0x9},
  71. { CCW_DEVICE_DEVTYPE (0x1750, 0, 0x3380, 0), .driver_info = 0xa},
  72. { /* end of list */ },
  73. };
  74. MODULE_DEVICE_TABLE(ccw, dasd_eckd_ids);
  75. static struct ccw_driver dasd_eckd_driver; /* see below */
  76. #define INIT_CQR_OK 0
  77. #define INIT_CQR_UNFORMATTED 1
  78. #define INIT_CQR_ERROR 2
  79. /* emergency request for reserve/release */
  80. static struct {
  81. struct dasd_ccw_req cqr;
  82. struct ccw1 ccw;
  83. char data[32];
  84. } *dasd_reserve_req;
  85. static DEFINE_MUTEX(dasd_reserve_mutex);
  86. /* definitions for the path verification worker */
  87. struct path_verification_work_data {
  88. struct work_struct worker;
  89. struct dasd_device *device;
  90. struct dasd_ccw_req cqr;
  91. struct ccw1 ccw;
  92. __u8 rcd_buffer[DASD_ECKD_RCD_DATA_SIZE];
  93. int isglobal;
  94. __u8 tbvpm;
  95. };
  96. static struct path_verification_work_data *path_verification_worker;
  97. static DEFINE_MUTEX(dasd_path_verification_mutex);
  98. /* initial attempt at a probe function. this can be simplified once
  99. * the other detection code is gone */
  100. static int
  101. dasd_eckd_probe (struct ccw_device *cdev)
  102. {
  103. int ret;
  104. /* set ECKD specific ccw-device options */
  105. ret = ccw_device_set_options(cdev, CCWDEV_ALLOW_FORCE |
  106. CCWDEV_DO_PATHGROUP | CCWDEV_DO_MULTIPATH);
  107. if (ret) {
  108. DBF_EVENT_DEVID(DBF_WARNING, cdev, "%s",
  109. "dasd_eckd_probe: could not set "
  110. "ccw-device options");
  111. return ret;
  112. }
  113. ret = dasd_generic_probe(cdev, &dasd_eckd_discipline);
  114. return ret;
  115. }
  116. static int
  117. dasd_eckd_set_online(struct ccw_device *cdev)
  118. {
  119. return dasd_generic_set_online(cdev, &dasd_eckd_discipline);
  120. }
  121. static const int sizes_trk0[] = { 28, 148, 84 };
  122. #define LABEL_SIZE 140
  123. static inline unsigned int
  124. round_up_multiple(unsigned int no, unsigned int mult)
  125. {
  126. int rem = no % mult;
  127. return (rem ? no - rem + mult : no);
  128. }
  129. static inline unsigned int
  130. ceil_quot(unsigned int d1, unsigned int d2)
  131. {
  132. return (d1 + (d2 - 1)) / d2;
  133. }
  134. static unsigned int
  135. recs_per_track(struct dasd_eckd_characteristics * rdc,
  136. unsigned int kl, unsigned int dl)
  137. {
  138. int dn, kn;
  139. switch (rdc->dev_type) {
  140. case 0x3380:
  141. if (kl)
  142. return 1499 / (15 + 7 + ceil_quot(kl + 12, 32) +
  143. ceil_quot(dl + 12, 32));
  144. else
  145. return 1499 / (15 + ceil_quot(dl + 12, 32));
  146. case 0x3390:
  147. dn = ceil_quot(dl + 6, 232) + 1;
  148. if (kl) {
  149. kn = ceil_quot(kl + 6, 232) + 1;
  150. return 1729 / (10 + 9 + ceil_quot(kl + 6 * kn, 34) +
  151. 9 + ceil_quot(dl + 6 * dn, 34));
  152. } else
  153. return 1729 / (10 + 9 + ceil_quot(dl + 6 * dn, 34));
  154. case 0x9345:
  155. dn = ceil_quot(dl + 6, 232) + 1;
  156. if (kl) {
  157. kn = ceil_quot(kl + 6, 232) + 1;
  158. return 1420 / (18 + 7 + ceil_quot(kl + 6 * kn, 34) +
  159. ceil_quot(dl + 6 * dn, 34));
  160. } else
  161. return 1420 / (18 + 7 + ceil_quot(dl + 6 * dn, 34));
  162. }
  163. return 0;
  164. }
  165. static void set_ch_t(struct ch_t *geo, __u32 cyl, __u8 head)
  166. {
  167. geo->cyl = (__u16) cyl;
  168. geo->head = cyl >> 16;
  169. geo->head <<= 4;
  170. geo->head |= head;
  171. }
  172. static int
  173. check_XRC (struct ccw1 *de_ccw,
  174. struct DE_eckd_data *data,
  175. struct dasd_device *device)
  176. {
  177. struct dasd_eckd_private *private;
  178. int rc;
  179. private = (struct dasd_eckd_private *) device->private;
  180. if (!private->rdc_data.facilities.XRC_supported)
  181. return 0;
  182. /* switch on System Time Stamp - needed for XRC Support */
  183. data->ga_extended |= 0x08; /* switch on 'Time Stamp Valid' */
  184. data->ga_extended |= 0x02; /* switch on 'Extended Parameter' */
  185. rc = get_sync_clock(&data->ep_sys_time);
  186. /* Ignore return code if sync clock is switched off. */
  187. if (rc == -ENOSYS || rc == -EACCES)
  188. rc = 0;
  189. de_ccw->count = sizeof(struct DE_eckd_data);
  190. de_ccw->flags |= CCW_FLAG_SLI;
  191. return rc;
  192. }
  193. static int
  194. define_extent(struct ccw1 *ccw, struct DE_eckd_data *data, unsigned int trk,
  195. unsigned int totrk, int cmd, struct dasd_device *device)
  196. {
  197. struct dasd_eckd_private *private;
  198. u32 begcyl, endcyl;
  199. u16 heads, beghead, endhead;
  200. int rc = 0;
  201. private = (struct dasd_eckd_private *) device->private;
  202. ccw->cmd_code = DASD_ECKD_CCW_DEFINE_EXTENT;
  203. ccw->flags = 0;
  204. ccw->count = 16;
  205. ccw->cda = (__u32) __pa(data);
  206. memset(data, 0, sizeof(struct DE_eckd_data));
  207. switch (cmd) {
  208. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  209. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  210. case DASD_ECKD_CCW_READ:
  211. case DASD_ECKD_CCW_READ_MT:
  212. case DASD_ECKD_CCW_READ_CKD:
  213. case DASD_ECKD_CCW_READ_CKD_MT:
  214. case DASD_ECKD_CCW_READ_KD:
  215. case DASD_ECKD_CCW_READ_KD_MT:
  216. case DASD_ECKD_CCW_READ_COUNT:
  217. data->mask.perm = 0x1;
  218. data->attributes.operation = private->attrib.operation;
  219. break;
  220. case DASD_ECKD_CCW_WRITE:
  221. case DASD_ECKD_CCW_WRITE_MT:
  222. case DASD_ECKD_CCW_WRITE_KD:
  223. case DASD_ECKD_CCW_WRITE_KD_MT:
  224. data->mask.perm = 0x02;
  225. data->attributes.operation = private->attrib.operation;
  226. rc = check_XRC (ccw, data, device);
  227. break;
  228. case DASD_ECKD_CCW_WRITE_CKD:
  229. case DASD_ECKD_CCW_WRITE_CKD_MT:
  230. data->attributes.operation = DASD_BYPASS_CACHE;
  231. rc = check_XRC (ccw, data, device);
  232. break;
  233. case DASD_ECKD_CCW_ERASE:
  234. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  235. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  236. data->mask.perm = 0x3;
  237. data->mask.auth = 0x1;
  238. data->attributes.operation = DASD_BYPASS_CACHE;
  239. rc = check_XRC (ccw, data, device);
  240. break;
  241. default:
  242. dev_err(&device->cdev->dev,
  243. "0x%x is not a known command\n", cmd);
  244. break;
  245. }
  246. data->attributes.mode = 0x3; /* ECKD */
  247. if ((private->rdc_data.cu_type == 0x2105 ||
  248. private->rdc_data.cu_type == 0x2107 ||
  249. private->rdc_data.cu_type == 0x1750)
  250. && !(private->uses_cdl && trk < 2))
  251. data->ga_extended |= 0x40; /* Regular Data Format Mode */
  252. heads = private->rdc_data.trk_per_cyl;
  253. begcyl = trk / heads;
  254. beghead = trk % heads;
  255. endcyl = totrk / heads;
  256. endhead = totrk % heads;
  257. /* check for sequential prestage - enhance cylinder range */
  258. if (data->attributes.operation == DASD_SEQ_PRESTAGE ||
  259. data->attributes.operation == DASD_SEQ_ACCESS) {
  260. if (endcyl + private->attrib.nr_cyl < private->real_cyl)
  261. endcyl += private->attrib.nr_cyl;
  262. else
  263. endcyl = (private->real_cyl - 1);
  264. }
  265. set_ch_t(&data->beg_ext, begcyl, beghead);
  266. set_ch_t(&data->end_ext, endcyl, endhead);
  267. return rc;
  268. }
  269. static int check_XRC_on_prefix(struct PFX_eckd_data *pfxdata,
  270. struct dasd_device *device)
  271. {
  272. struct dasd_eckd_private *private;
  273. int rc;
  274. private = (struct dasd_eckd_private *) device->private;
  275. if (!private->rdc_data.facilities.XRC_supported)
  276. return 0;
  277. /* switch on System Time Stamp - needed for XRC Support */
  278. pfxdata->define_extent.ga_extended |= 0x08; /* 'Time Stamp Valid' */
  279. pfxdata->define_extent.ga_extended |= 0x02; /* 'Extended Parameter' */
  280. pfxdata->validity.time_stamp = 1; /* 'Time Stamp Valid' */
  281. rc = get_sync_clock(&pfxdata->define_extent.ep_sys_time);
  282. /* Ignore return code if sync clock is switched off. */
  283. if (rc == -ENOSYS || rc == -EACCES)
  284. rc = 0;
  285. return rc;
  286. }
  287. static void fill_LRE_data(struct LRE_eckd_data *data, unsigned int trk,
  288. unsigned int rec_on_trk, int count, int cmd,
  289. struct dasd_device *device, unsigned int reclen,
  290. unsigned int tlf)
  291. {
  292. struct dasd_eckd_private *private;
  293. int sector;
  294. int dn, d;
  295. private = (struct dasd_eckd_private *) device->private;
  296. memset(data, 0, sizeof(*data));
  297. sector = 0;
  298. if (rec_on_trk) {
  299. switch (private->rdc_data.dev_type) {
  300. case 0x3390:
  301. dn = ceil_quot(reclen + 6, 232);
  302. d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
  303. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  304. break;
  305. case 0x3380:
  306. d = 7 + ceil_quot(reclen + 12, 32);
  307. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  308. break;
  309. }
  310. }
  311. data->sector = sector;
  312. /* note: meaning of count depends on the operation
  313. * for record based I/O it's the number of records, but for
  314. * track based I/O it's the number of tracks
  315. */
  316. data->count = count;
  317. switch (cmd) {
  318. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  319. data->operation.orientation = 0x3;
  320. data->operation.operation = 0x03;
  321. break;
  322. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  323. data->operation.orientation = 0x3;
  324. data->operation.operation = 0x16;
  325. break;
  326. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  327. data->operation.orientation = 0x1;
  328. data->operation.operation = 0x03;
  329. data->count++;
  330. break;
  331. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  332. data->operation.orientation = 0x3;
  333. data->operation.operation = 0x16;
  334. data->count++;
  335. break;
  336. case DASD_ECKD_CCW_WRITE:
  337. case DASD_ECKD_CCW_WRITE_MT:
  338. case DASD_ECKD_CCW_WRITE_KD:
  339. case DASD_ECKD_CCW_WRITE_KD_MT:
  340. data->auxiliary.length_valid = 0x1;
  341. data->length = reclen;
  342. data->operation.operation = 0x01;
  343. break;
  344. case DASD_ECKD_CCW_WRITE_CKD:
  345. case DASD_ECKD_CCW_WRITE_CKD_MT:
  346. data->auxiliary.length_valid = 0x1;
  347. data->length = reclen;
  348. data->operation.operation = 0x03;
  349. break;
  350. case DASD_ECKD_CCW_WRITE_FULL_TRACK:
  351. data->operation.orientation = 0x0;
  352. data->operation.operation = 0x3F;
  353. data->extended_operation = 0x11;
  354. data->length = 0;
  355. data->extended_parameter_length = 0x02;
  356. if (data->count > 8) {
  357. data->extended_parameter[0] = 0xFF;
  358. data->extended_parameter[1] = 0xFF;
  359. data->extended_parameter[1] <<= (16 - count);
  360. } else {
  361. data->extended_parameter[0] = 0xFF;
  362. data->extended_parameter[0] <<= (8 - count);
  363. data->extended_parameter[1] = 0x00;
  364. }
  365. data->sector = 0xFF;
  366. break;
  367. case DASD_ECKD_CCW_WRITE_TRACK_DATA:
  368. data->auxiliary.length_valid = 0x1;
  369. data->length = reclen; /* not tlf, as one might think */
  370. data->operation.operation = 0x3F;
  371. data->extended_operation = 0x23;
  372. break;
  373. case DASD_ECKD_CCW_READ:
  374. case DASD_ECKD_CCW_READ_MT:
  375. case DASD_ECKD_CCW_READ_KD:
  376. case DASD_ECKD_CCW_READ_KD_MT:
  377. data->auxiliary.length_valid = 0x1;
  378. data->length = reclen;
  379. data->operation.operation = 0x06;
  380. break;
  381. case DASD_ECKD_CCW_READ_CKD:
  382. case DASD_ECKD_CCW_READ_CKD_MT:
  383. data->auxiliary.length_valid = 0x1;
  384. data->length = reclen;
  385. data->operation.operation = 0x16;
  386. break;
  387. case DASD_ECKD_CCW_READ_COUNT:
  388. data->operation.operation = 0x06;
  389. break;
  390. case DASD_ECKD_CCW_READ_TRACK:
  391. data->operation.orientation = 0x1;
  392. data->operation.operation = 0x0C;
  393. data->extended_parameter_length = 0;
  394. data->sector = 0xFF;
  395. break;
  396. case DASD_ECKD_CCW_READ_TRACK_DATA:
  397. data->auxiliary.length_valid = 0x1;
  398. data->length = tlf;
  399. data->operation.operation = 0x0C;
  400. break;
  401. case DASD_ECKD_CCW_ERASE:
  402. data->length = reclen;
  403. data->auxiliary.length_valid = 0x1;
  404. data->operation.operation = 0x0b;
  405. break;
  406. default:
  407. DBF_DEV_EVENT(DBF_ERR, device,
  408. "fill LRE unknown opcode 0x%x", cmd);
  409. BUG();
  410. }
  411. set_ch_t(&data->seek_addr,
  412. trk / private->rdc_data.trk_per_cyl,
  413. trk % private->rdc_data.trk_per_cyl);
  414. data->search_arg.cyl = data->seek_addr.cyl;
  415. data->search_arg.head = data->seek_addr.head;
  416. data->search_arg.record = rec_on_trk;
  417. }
  418. static int prefix_LRE(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
  419. unsigned int trk, unsigned int totrk, int cmd,
  420. struct dasd_device *basedev, struct dasd_device *startdev,
  421. unsigned char format, unsigned int rec_on_trk, int count,
  422. unsigned int blksize, unsigned int tlf)
  423. {
  424. struct dasd_eckd_private *basepriv, *startpriv;
  425. struct DE_eckd_data *dedata;
  426. struct LRE_eckd_data *lredata;
  427. u32 begcyl, endcyl;
  428. u16 heads, beghead, endhead;
  429. int rc = 0;
  430. basepriv = (struct dasd_eckd_private *) basedev->private;
  431. startpriv = (struct dasd_eckd_private *) startdev->private;
  432. dedata = &pfxdata->define_extent;
  433. lredata = &pfxdata->locate_record;
  434. ccw->cmd_code = DASD_ECKD_CCW_PFX;
  435. ccw->flags = 0;
  436. if (cmd == DASD_ECKD_CCW_WRITE_FULL_TRACK) {
  437. ccw->count = sizeof(*pfxdata) + 2;
  438. ccw->cda = (__u32) __pa(pfxdata);
  439. memset(pfxdata, 0, sizeof(*pfxdata) + 2);
  440. } else {
  441. ccw->count = sizeof(*pfxdata);
  442. ccw->cda = (__u32) __pa(pfxdata);
  443. memset(pfxdata, 0, sizeof(*pfxdata));
  444. }
  445. /* prefix data */
  446. if (format > 1) {
  447. DBF_DEV_EVENT(DBF_ERR, basedev,
  448. "PFX LRE unknown format 0x%x", format);
  449. BUG();
  450. return -EINVAL;
  451. }
  452. pfxdata->format = format;
  453. pfxdata->base_address = basepriv->ned->unit_addr;
  454. pfxdata->base_lss = basepriv->ned->ID;
  455. pfxdata->validity.define_extent = 1;
  456. /* private uid is kept up to date, conf_data may be outdated */
  457. if (startpriv->uid.type != UA_BASE_DEVICE) {
  458. pfxdata->validity.verify_base = 1;
  459. if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
  460. pfxdata->validity.hyper_pav = 1;
  461. }
  462. /* define extend data (mostly)*/
  463. switch (cmd) {
  464. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  465. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  466. case DASD_ECKD_CCW_READ:
  467. case DASD_ECKD_CCW_READ_MT:
  468. case DASD_ECKD_CCW_READ_CKD:
  469. case DASD_ECKD_CCW_READ_CKD_MT:
  470. case DASD_ECKD_CCW_READ_KD:
  471. case DASD_ECKD_CCW_READ_KD_MT:
  472. case DASD_ECKD_CCW_READ_COUNT:
  473. dedata->mask.perm = 0x1;
  474. dedata->attributes.operation = basepriv->attrib.operation;
  475. break;
  476. case DASD_ECKD_CCW_READ_TRACK:
  477. case DASD_ECKD_CCW_READ_TRACK_DATA:
  478. dedata->mask.perm = 0x1;
  479. dedata->attributes.operation = basepriv->attrib.operation;
  480. dedata->blk_size = 0;
  481. break;
  482. case DASD_ECKD_CCW_WRITE:
  483. case DASD_ECKD_CCW_WRITE_MT:
  484. case DASD_ECKD_CCW_WRITE_KD:
  485. case DASD_ECKD_CCW_WRITE_KD_MT:
  486. dedata->mask.perm = 0x02;
  487. dedata->attributes.operation = basepriv->attrib.operation;
  488. rc = check_XRC_on_prefix(pfxdata, basedev);
  489. break;
  490. case DASD_ECKD_CCW_WRITE_CKD:
  491. case DASD_ECKD_CCW_WRITE_CKD_MT:
  492. dedata->attributes.operation = DASD_BYPASS_CACHE;
  493. rc = check_XRC_on_prefix(pfxdata, basedev);
  494. break;
  495. case DASD_ECKD_CCW_ERASE:
  496. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  497. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  498. dedata->mask.perm = 0x3;
  499. dedata->mask.auth = 0x1;
  500. dedata->attributes.operation = DASD_BYPASS_CACHE;
  501. rc = check_XRC_on_prefix(pfxdata, basedev);
  502. break;
  503. case DASD_ECKD_CCW_WRITE_FULL_TRACK:
  504. dedata->mask.perm = 0x03;
  505. dedata->attributes.operation = basepriv->attrib.operation;
  506. dedata->blk_size = 0;
  507. break;
  508. case DASD_ECKD_CCW_WRITE_TRACK_DATA:
  509. dedata->mask.perm = 0x02;
  510. dedata->attributes.operation = basepriv->attrib.operation;
  511. dedata->blk_size = blksize;
  512. rc = check_XRC_on_prefix(pfxdata, basedev);
  513. break;
  514. default:
  515. DBF_DEV_EVENT(DBF_ERR, basedev,
  516. "PFX LRE unknown opcode 0x%x", cmd);
  517. BUG();
  518. return -EINVAL;
  519. }
  520. dedata->attributes.mode = 0x3; /* ECKD */
  521. if ((basepriv->rdc_data.cu_type == 0x2105 ||
  522. basepriv->rdc_data.cu_type == 0x2107 ||
  523. basepriv->rdc_data.cu_type == 0x1750)
  524. && !(basepriv->uses_cdl && trk < 2))
  525. dedata->ga_extended |= 0x40; /* Regular Data Format Mode */
  526. heads = basepriv->rdc_data.trk_per_cyl;
  527. begcyl = trk / heads;
  528. beghead = trk % heads;
  529. endcyl = totrk / heads;
  530. endhead = totrk % heads;
  531. /* check for sequential prestage - enhance cylinder range */
  532. if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
  533. dedata->attributes.operation == DASD_SEQ_ACCESS) {
  534. if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
  535. endcyl += basepriv->attrib.nr_cyl;
  536. else
  537. endcyl = (basepriv->real_cyl - 1);
  538. }
  539. set_ch_t(&dedata->beg_ext, begcyl, beghead);
  540. set_ch_t(&dedata->end_ext, endcyl, endhead);
  541. if (format == 1) {
  542. fill_LRE_data(lredata, trk, rec_on_trk, count, cmd,
  543. basedev, blksize, tlf);
  544. }
  545. return rc;
  546. }
  547. static int prefix(struct ccw1 *ccw, struct PFX_eckd_data *pfxdata,
  548. unsigned int trk, unsigned int totrk, int cmd,
  549. struct dasd_device *basedev, struct dasd_device *startdev)
  550. {
  551. return prefix_LRE(ccw, pfxdata, trk, totrk, cmd, basedev, startdev,
  552. 0, 0, 0, 0, 0);
  553. }
  554. static void
  555. locate_record(struct ccw1 *ccw, struct LO_eckd_data *data, unsigned int trk,
  556. unsigned int rec_on_trk, int no_rec, int cmd,
  557. struct dasd_device * device, int reclen)
  558. {
  559. struct dasd_eckd_private *private;
  560. int sector;
  561. int dn, d;
  562. private = (struct dasd_eckd_private *) device->private;
  563. DBF_DEV_EVENT(DBF_INFO, device,
  564. "Locate: trk %d, rec %d, no_rec %d, cmd %d, reclen %d",
  565. trk, rec_on_trk, no_rec, cmd, reclen);
  566. ccw->cmd_code = DASD_ECKD_CCW_LOCATE_RECORD;
  567. ccw->flags = 0;
  568. ccw->count = 16;
  569. ccw->cda = (__u32) __pa(data);
  570. memset(data, 0, sizeof(struct LO_eckd_data));
  571. sector = 0;
  572. if (rec_on_trk) {
  573. switch (private->rdc_data.dev_type) {
  574. case 0x3390:
  575. dn = ceil_quot(reclen + 6, 232);
  576. d = 9 + ceil_quot(reclen + 6 * (dn + 1), 34);
  577. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  578. break;
  579. case 0x3380:
  580. d = 7 + ceil_quot(reclen + 12, 32);
  581. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  582. break;
  583. }
  584. }
  585. data->sector = sector;
  586. data->count = no_rec;
  587. switch (cmd) {
  588. case DASD_ECKD_CCW_WRITE_HOME_ADDRESS:
  589. data->operation.orientation = 0x3;
  590. data->operation.operation = 0x03;
  591. break;
  592. case DASD_ECKD_CCW_READ_HOME_ADDRESS:
  593. data->operation.orientation = 0x3;
  594. data->operation.operation = 0x16;
  595. break;
  596. case DASD_ECKD_CCW_WRITE_RECORD_ZERO:
  597. data->operation.orientation = 0x1;
  598. data->operation.operation = 0x03;
  599. data->count++;
  600. break;
  601. case DASD_ECKD_CCW_READ_RECORD_ZERO:
  602. data->operation.orientation = 0x3;
  603. data->operation.operation = 0x16;
  604. data->count++;
  605. break;
  606. case DASD_ECKD_CCW_WRITE:
  607. case DASD_ECKD_CCW_WRITE_MT:
  608. case DASD_ECKD_CCW_WRITE_KD:
  609. case DASD_ECKD_CCW_WRITE_KD_MT:
  610. data->auxiliary.last_bytes_used = 0x1;
  611. data->length = reclen;
  612. data->operation.operation = 0x01;
  613. break;
  614. case DASD_ECKD_CCW_WRITE_CKD:
  615. case DASD_ECKD_CCW_WRITE_CKD_MT:
  616. data->auxiliary.last_bytes_used = 0x1;
  617. data->length = reclen;
  618. data->operation.operation = 0x03;
  619. break;
  620. case DASD_ECKD_CCW_READ:
  621. case DASD_ECKD_CCW_READ_MT:
  622. case DASD_ECKD_CCW_READ_KD:
  623. case DASD_ECKD_CCW_READ_KD_MT:
  624. data->auxiliary.last_bytes_used = 0x1;
  625. data->length = reclen;
  626. data->operation.operation = 0x06;
  627. break;
  628. case DASD_ECKD_CCW_READ_CKD:
  629. case DASD_ECKD_CCW_READ_CKD_MT:
  630. data->auxiliary.last_bytes_used = 0x1;
  631. data->length = reclen;
  632. data->operation.operation = 0x16;
  633. break;
  634. case DASD_ECKD_CCW_READ_COUNT:
  635. data->operation.operation = 0x06;
  636. break;
  637. case DASD_ECKD_CCW_ERASE:
  638. data->length = reclen;
  639. data->auxiliary.last_bytes_used = 0x1;
  640. data->operation.operation = 0x0b;
  641. break;
  642. default:
  643. DBF_DEV_EVENT(DBF_ERR, device, "unknown locate record "
  644. "opcode 0x%x", cmd);
  645. }
  646. set_ch_t(&data->seek_addr,
  647. trk / private->rdc_data.trk_per_cyl,
  648. trk % private->rdc_data.trk_per_cyl);
  649. data->search_arg.cyl = data->seek_addr.cyl;
  650. data->search_arg.head = data->seek_addr.head;
  651. data->search_arg.record = rec_on_trk;
  652. }
  653. /*
  654. * Returns 1 if the block is one of the special blocks that needs
  655. * to get read/written with the KD variant of the command.
  656. * That is DASD_ECKD_READ_KD_MT instead of DASD_ECKD_READ_MT and
  657. * DASD_ECKD_WRITE_KD_MT instead of DASD_ECKD_WRITE_MT.
  658. * Luckily the KD variants differ only by one bit (0x08) from the
  659. * normal variant. So don't wonder about code like:
  660. * if (dasd_eckd_cdl_special(blk_per_trk, recid))
  661. * ccw->cmd_code |= 0x8;
  662. */
  663. static inline int
  664. dasd_eckd_cdl_special(int blk_per_trk, int recid)
  665. {
  666. if (recid < 3)
  667. return 1;
  668. if (recid < blk_per_trk)
  669. return 0;
  670. if (recid < 2 * blk_per_trk)
  671. return 1;
  672. return 0;
  673. }
  674. /*
  675. * Returns the record size for the special blocks of the cdl format.
  676. * Only returns something useful if dasd_eckd_cdl_special is true
  677. * for the recid.
  678. */
  679. static inline int
  680. dasd_eckd_cdl_reclen(int recid)
  681. {
  682. if (recid < 3)
  683. return sizes_trk0[recid];
  684. return LABEL_SIZE;
  685. }
  686. /* create unique id from private structure. */
  687. static void create_uid(struct dasd_eckd_private *private)
  688. {
  689. int count;
  690. struct dasd_uid *uid;
  691. uid = &private->uid;
  692. memset(uid, 0, sizeof(struct dasd_uid));
  693. memcpy(uid->vendor, private->ned->HDA_manufacturer,
  694. sizeof(uid->vendor) - 1);
  695. EBCASC(uid->vendor, sizeof(uid->vendor) - 1);
  696. memcpy(uid->serial, private->ned->HDA_location,
  697. sizeof(uid->serial) - 1);
  698. EBCASC(uid->serial, sizeof(uid->serial) - 1);
  699. uid->ssid = private->gneq->subsystemID;
  700. uid->real_unit_addr = private->ned->unit_addr;
  701. if (private->sneq) {
  702. uid->type = private->sneq->sua_flags;
  703. if (uid->type == UA_BASE_PAV_ALIAS)
  704. uid->base_unit_addr = private->sneq->base_unit_addr;
  705. } else {
  706. uid->type = UA_BASE_DEVICE;
  707. }
  708. if (private->vdsneq) {
  709. for (count = 0; count < 16; count++) {
  710. sprintf(uid->vduit+2*count, "%02x",
  711. private->vdsneq->uit[count]);
  712. }
  713. }
  714. }
  715. /*
  716. * Generate device unique id that specifies the physical device.
  717. */
  718. static int dasd_eckd_generate_uid(struct dasd_device *device)
  719. {
  720. struct dasd_eckd_private *private;
  721. unsigned long flags;
  722. private = (struct dasd_eckd_private *) device->private;
  723. if (!private)
  724. return -ENODEV;
  725. if (!private->ned || !private->gneq)
  726. return -ENODEV;
  727. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  728. create_uid(private);
  729. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  730. return 0;
  731. }
  732. static int dasd_eckd_get_uid(struct dasd_device *device, struct dasd_uid *uid)
  733. {
  734. struct dasd_eckd_private *private;
  735. unsigned long flags;
  736. if (device->private) {
  737. private = (struct dasd_eckd_private *)device->private;
  738. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  739. *uid = private->uid;
  740. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  741. return 0;
  742. }
  743. return -EINVAL;
  744. }
  745. /*
  746. * compare device UID with data of a given dasd_eckd_private structure
  747. * return 0 for match
  748. */
  749. static int dasd_eckd_compare_path_uid(struct dasd_device *device,
  750. struct dasd_eckd_private *private)
  751. {
  752. struct dasd_uid device_uid;
  753. create_uid(private);
  754. dasd_eckd_get_uid(device, &device_uid);
  755. return memcmp(&device_uid, &private->uid, sizeof(struct dasd_uid));
  756. }
  757. static void dasd_eckd_fill_rcd_cqr(struct dasd_device *device,
  758. struct dasd_ccw_req *cqr,
  759. __u8 *rcd_buffer,
  760. __u8 lpm)
  761. {
  762. struct ccw1 *ccw;
  763. /*
  764. * buffer has to start with EBCDIC "V1.0" to show
  765. * support for virtual device SNEQ
  766. */
  767. rcd_buffer[0] = 0xE5;
  768. rcd_buffer[1] = 0xF1;
  769. rcd_buffer[2] = 0x4B;
  770. rcd_buffer[3] = 0xF0;
  771. ccw = cqr->cpaddr;
  772. ccw->cmd_code = DASD_ECKD_CCW_RCD;
  773. ccw->flags = 0;
  774. ccw->cda = (__u32)(addr_t)rcd_buffer;
  775. ccw->count = DASD_ECKD_RCD_DATA_SIZE;
  776. cqr->magic = DASD_ECKD_MAGIC;
  777. cqr->startdev = device;
  778. cqr->memdev = device;
  779. cqr->block = NULL;
  780. cqr->expires = 10*HZ;
  781. cqr->lpm = lpm;
  782. cqr->retries = 256;
  783. cqr->buildclk = get_clock();
  784. cqr->status = DASD_CQR_FILLED;
  785. set_bit(DASD_CQR_VERIFY_PATH, &cqr->flags);
  786. }
  787. /*
  788. * Wakeup helper for read_conf
  789. * if the cqr is not done and needs some error recovery
  790. * the buffer has to be re-initialized with the EBCDIC "V1.0"
  791. * to show support for virtual device SNEQ
  792. */
  793. static void read_conf_cb(struct dasd_ccw_req *cqr, void *data)
  794. {
  795. struct ccw1 *ccw;
  796. __u8 *rcd_buffer;
  797. if (cqr->status != DASD_CQR_DONE) {
  798. ccw = cqr->cpaddr;
  799. rcd_buffer = (__u8 *)((addr_t) ccw->cda);
  800. memset(rcd_buffer, 0, sizeof(*rcd_buffer));
  801. rcd_buffer[0] = 0xE5;
  802. rcd_buffer[1] = 0xF1;
  803. rcd_buffer[2] = 0x4B;
  804. rcd_buffer[3] = 0xF0;
  805. }
  806. dasd_wakeup_cb(cqr, data);
  807. }
  808. static int dasd_eckd_read_conf_immediately(struct dasd_device *device,
  809. struct dasd_ccw_req *cqr,
  810. __u8 *rcd_buffer,
  811. __u8 lpm)
  812. {
  813. struct ciw *ciw;
  814. int rc;
  815. /*
  816. * sanity check: scan for RCD command in extended SenseID data
  817. * some devices do not support RCD
  818. */
  819. ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
  820. if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD)
  821. return -EOPNOTSUPP;
  822. dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buffer, lpm);
  823. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  824. set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
  825. cqr->retries = 5;
  826. cqr->callback = read_conf_cb;
  827. rc = dasd_sleep_on_immediatly(cqr);
  828. return rc;
  829. }
  830. static int dasd_eckd_read_conf_lpm(struct dasd_device *device,
  831. void **rcd_buffer,
  832. int *rcd_buffer_size, __u8 lpm)
  833. {
  834. struct ciw *ciw;
  835. char *rcd_buf = NULL;
  836. int ret;
  837. struct dasd_ccw_req *cqr;
  838. /*
  839. * sanity check: scan for RCD command in extended SenseID data
  840. * some devices do not support RCD
  841. */
  842. ciw = ccw_device_get_ciw(device->cdev, CIW_TYPE_RCD);
  843. if (!ciw || ciw->cmd != DASD_ECKD_CCW_RCD) {
  844. ret = -EOPNOTSUPP;
  845. goto out_error;
  846. }
  847. rcd_buf = kzalloc(DASD_ECKD_RCD_DATA_SIZE, GFP_KERNEL | GFP_DMA);
  848. if (!rcd_buf) {
  849. ret = -ENOMEM;
  850. goto out_error;
  851. }
  852. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* RCD */,
  853. 0, /* use rcd_buf as data ara */
  854. device);
  855. if (IS_ERR(cqr)) {
  856. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  857. "Could not allocate RCD request");
  858. ret = -ENOMEM;
  859. goto out_error;
  860. }
  861. dasd_eckd_fill_rcd_cqr(device, cqr, rcd_buf, lpm);
  862. cqr->callback = read_conf_cb;
  863. ret = dasd_sleep_on(cqr);
  864. /*
  865. * on success we update the user input parms
  866. */
  867. dasd_sfree_request(cqr, cqr->memdev);
  868. if (ret)
  869. goto out_error;
  870. *rcd_buffer_size = DASD_ECKD_RCD_DATA_SIZE;
  871. *rcd_buffer = rcd_buf;
  872. return 0;
  873. out_error:
  874. kfree(rcd_buf);
  875. *rcd_buffer = NULL;
  876. *rcd_buffer_size = 0;
  877. return ret;
  878. }
  879. static int dasd_eckd_identify_conf_parts(struct dasd_eckd_private *private)
  880. {
  881. struct dasd_sneq *sneq;
  882. int i, count;
  883. private->ned = NULL;
  884. private->sneq = NULL;
  885. private->vdsneq = NULL;
  886. private->gneq = NULL;
  887. count = private->conf_len / sizeof(struct dasd_sneq);
  888. sneq = (struct dasd_sneq *)private->conf_data;
  889. for (i = 0; i < count; ++i) {
  890. if (sneq->flags.identifier == 1 && sneq->format == 1)
  891. private->sneq = sneq;
  892. else if (sneq->flags.identifier == 1 && sneq->format == 4)
  893. private->vdsneq = (struct vd_sneq *)sneq;
  894. else if (sneq->flags.identifier == 2)
  895. private->gneq = (struct dasd_gneq *)sneq;
  896. else if (sneq->flags.identifier == 3 && sneq->res1 == 1)
  897. private->ned = (struct dasd_ned *)sneq;
  898. sneq++;
  899. }
  900. if (!private->ned || !private->gneq) {
  901. private->ned = NULL;
  902. private->sneq = NULL;
  903. private->vdsneq = NULL;
  904. private->gneq = NULL;
  905. return -EINVAL;
  906. }
  907. return 0;
  908. };
  909. static unsigned char dasd_eckd_path_access(void *conf_data, int conf_len)
  910. {
  911. struct dasd_gneq *gneq;
  912. int i, count, found;
  913. count = conf_len / sizeof(*gneq);
  914. gneq = (struct dasd_gneq *)conf_data;
  915. found = 0;
  916. for (i = 0; i < count; ++i) {
  917. if (gneq->flags.identifier == 2) {
  918. found = 1;
  919. break;
  920. }
  921. gneq++;
  922. }
  923. if (found)
  924. return ((char *)gneq)[18] & 0x07;
  925. else
  926. return 0;
  927. }
  928. static int dasd_eckd_read_conf(struct dasd_device *device)
  929. {
  930. void *conf_data;
  931. int conf_len, conf_data_saved;
  932. int rc;
  933. __u8 lpm, opm;
  934. struct dasd_eckd_private *private, path_private;
  935. struct dasd_path *path_data;
  936. struct dasd_uid *uid;
  937. char print_path_uid[60], print_device_uid[60];
  938. private = (struct dasd_eckd_private *) device->private;
  939. path_data = &device->path_data;
  940. opm = ccw_device_get_path_mask(device->cdev);
  941. conf_data_saved = 0;
  942. /* get configuration data per operational path */
  943. for (lpm = 0x80; lpm; lpm>>= 1) {
  944. if (!(lpm & opm))
  945. continue;
  946. rc = dasd_eckd_read_conf_lpm(device, &conf_data,
  947. &conf_len, lpm);
  948. if (rc && rc != -EOPNOTSUPP) { /* -EOPNOTSUPP is ok */
  949. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  950. "Read configuration data returned "
  951. "error %d", rc);
  952. return rc;
  953. }
  954. if (conf_data == NULL) {
  955. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  956. "No configuration data "
  957. "retrieved");
  958. /* no further analysis possible */
  959. path_data->opm |= lpm;
  960. continue; /* no error */
  961. }
  962. /* save first valid configuration data */
  963. if (!conf_data_saved) {
  964. kfree(private->conf_data);
  965. private->conf_data = conf_data;
  966. private->conf_len = conf_len;
  967. if (dasd_eckd_identify_conf_parts(private)) {
  968. private->conf_data = NULL;
  969. private->conf_len = 0;
  970. kfree(conf_data);
  971. continue;
  972. }
  973. /*
  974. * build device UID that other path data
  975. * can be compared to it
  976. */
  977. dasd_eckd_generate_uid(device);
  978. conf_data_saved++;
  979. } else {
  980. path_private.conf_data = conf_data;
  981. path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
  982. if (dasd_eckd_identify_conf_parts(
  983. &path_private)) {
  984. path_private.conf_data = NULL;
  985. path_private.conf_len = 0;
  986. kfree(conf_data);
  987. continue;
  988. }
  989. if (dasd_eckd_compare_path_uid(
  990. device, &path_private)) {
  991. uid = &path_private.uid;
  992. if (strlen(uid->vduit) > 0)
  993. snprintf(print_path_uid,
  994. sizeof(print_path_uid),
  995. "%s.%s.%04x.%02x.%s",
  996. uid->vendor, uid->serial,
  997. uid->ssid, uid->real_unit_addr,
  998. uid->vduit);
  999. else
  1000. snprintf(print_path_uid,
  1001. sizeof(print_path_uid),
  1002. "%s.%s.%04x.%02x",
  1003. uid->vendor, uid->serial,
  1004. uid->ssid,
  1005. uid->real_unit_addr);
  1006. uid = &private->uid;
  1007. if (strlen(uid->vduit) > 0)
  1008. snprintf(print_device_uid,
  1009. sizeof(print_device_uid),
  1010. "%s.%s.%04x.%02x.%s",
  1011. uid->vendor, uid->serial,
  1012. uid->ssid, uid->real_unit_addr,
  1013. uid->vduit);
  1014. else
  1015. snprintf(print_device_uid,
  1016. sizeof(print_device_uid),
  1017. "%s.%s.%04x.%02x",
  1018. uid->vendor, uid->serial,
  1019. uid->ssid,
  1020. uid->real_unit_addr);
  1021. dev_err(&device->cdev->dev,
  1022. "Not all channel paths lead to "
  1023. "the same device, path %02X leads to "
  1024. "device %s instead of %s\n", lpm,
  1025. print_path_uid, print_device_uid);
  1026. return -EINVAL;
  1027. }
  1028. path_private.conf_data = NULL;
  1029. path_private.conf_len = 0;
  1030. }
  1031. switch (dasd_eckd_path_access(conf_data, conf_len)) {
  1032. case 0x02:
  1033. path_data->npm |= lpm;
  1034. break;
  1035. case 0x03:
  1036. path_data->ppm |= lpm;
  1037. break;
  1038. }
  1039. path_data->opm |= lpm;
  1040. if (conf_data != private->conf_data)
  1041. kfree(conf_data);
  1042. }
  1043. return 0;
  1044. }
  1045. static int verify_fcx_max_data(struct dasd_device *device, __u8 lpm)
  1046. {
  1047. struct dasd_eckd_private *private;
  1048. int mdc;
  1049. u32 fcx_max_data;
  1050. private = (struct dasd_eckd_private *) device->private;
  1051. if (private->fcx_max_data) {
  1052. mdc = ccw_device_get_mdc(device->cdev, lpm);
  1053. if ((mdc < 0)) {
  1054. dev_warn(&device->cdev->dev,
  1055. "Detecting the maximum data size for zHPF "
  1056. "requests failed (rc=%d) for a new path %x\n",
  1057. mdc, lpm);
  1058. return mdc;
  1059. }
  1060. fcx_max_data = mdc * FCX_MAX_DATA_FACTOR;
  1061. if (fcx_max_data < private->fcx_max_data) {
  1062. dev_warn(&device->cdev->dev,
  1063. "The maximum data size for zHPF requests %u "
  1064. "on a new path %x is below the active maximum "
  1065. "%u\n", fcx_max_data, lpm,
  1066. private->fcx_max_data);
  1067. return -EACCES;
  1068. }
  1069. }
  1070. return 0;
  1071. }
  1072. static int rebuild_device_uid(struct dasd_device *device,
  1073. struct path_verification_work_data *data)
  1074. {
  1075. struct dasd_eckd_private *private;
  1076. struct dasd_path *path_data;
  1077. __u8 lpm, opm;
  1078. int rc;
  1079. rc = -ENODEV;
  1080. private = (struct dasd_eckd_private *) device->private;
  1081. path_data = &device->path_data;
  1082. opm = device->path_data.opm;
  1083. for (lpm = 0x80; lpm; lpm >>= 1) {
  1084. if (!(lpm & opm))
  1085. continue;
  1086. memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
  1087. memset(&data->cqr, 0, sizeof(data->cqr));
  1088. data->cqr.cpaddr = &data->ccw;
  1089. rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
  1090. data->rcd_buffer,
  1091. lpm);
  1092. if (rc) {
  1093. if (rc == -EOPNOTSUPP) /* -EOPNOTSUPP is ok */
  1094. continue;
  1095. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  1096. "Read configuration data "
  1097. "returned error %d", rc);
  1098. break;
  1099. }
  1100. memcpy(private->conf_data, data->rcd_buffer,
  1101. DASD_ECKD_RCD_DATA_SIZE);
  1102. if (dasd_eckd_identify_conf_parts(private)) {
  1103. rc = -ENODEV;
  1104. } else /* first valid path is enough */
  1105. break;
  1106. }
  1107. if (!rc)
  1108. rc = dasd_eckd_generate_uid(device);
  1109. return rc;
  1110. }
  1111. static void do_path_verification_work(struct work_struct *work)
  1112. {
  1113. struct path_verification_work_data *data;
  1114. struct dasd_device *device;
  1115. struct dasd_eckd_private path_private;
  1116. struct dasd_uid *uid;
  1117. __u8 path_rcd_buf[DASD_ECKD_RCD_DATA_SIZE];
  1118. __u8 lpm, opm, npm, ppm, epm;
  1119. unsigned long flags;
  1120. char print_uid[60];
  1121. int rc;
  1122. data = container_of(work, struct path_verification_work_data, worker);
  1123. device = data->device;
  1124. /* delay path verification until device was resumed */
  1125. if (test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
  1126. schedule_work(work);
  1127. return;
  1128. }
  1129. opm = 0;
  1130. npm = 0;
  1131. ppm = 0;
  1132. epm = 0;
  1133. for (lpm = 0x80; lpm; lpm >>= 1) {
  1134. if (!(lpm & data->tbvpm))
  1135. continue;
  1136. memset(&data->rcd_buffer, 0, sizeof(data->rcd_buffer));
  1137. memset(&data->cqr, 0, sizeof(data->cqr));
  1138. data->cqr.cpaddr = &data->ccw;
  1139. rc = dasd_eckd_read_conf_immediately(device, &data->cqr,
  1140. data->rcd_buffer,
  1141. lpm);
  1142. if (!rc) {
  1143. switch (dasd_eckd_path_access(data->rcd_buffer,
  1144. DASD_ECKD_RCD_DATA_SIZE)
  1145. ) {
  1146. case 0x02:
  1147. npm |= lpm;
  1148. break;
  1149. case 0x03:
  1150. ppm |= lpm;
  1151. break;
  1152. }
  1153. opm |= lpm;
  1154. } else if (rc == -EOPNOTSUPP) {
  1155. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  1156. "path verification: No configuration "
  1157. "data retrieved");
  1158. opm |= lpm;
  1159. } else if (rc == -EAGAIN) {
  1160. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  1161. "path verification: device is stopped,"
  1162. " try again later");
  1163. epm |= lpm;
  1164. } else {
  1165. dev_warn(&device->cdev->dev,
  1166. "Reading device feature codes failed "
  1167. "(rc=%d) for new path %x\n", rc, lpm);
  1168. continue;
  1169. }
  1170. if (verify_fcx_max_data(device, lpm)) {
  1171. opm &= ~lpm;
  1172. npm &= ~lpm;
  1173. ppm &= ~lpm;
  1174. continue;
  1175. }
  1176. /*
  1177. * save conf_data for comparison after
  1178. * rebuild_device_uid may have changed
  1179. * the original data
  1180. */
  1181. memcpy(&path_rcd_buf, data->rcd_buffer,
  1182. DASD_ECKD_RCD_DATA_SIZE);
  1183. path_private.conf_data = (void *) &path_rcd_buf;
  1184. path_private.conf_len = DASD_ECKD_RCD_DATA_SIZE;
  1185. if (dasd_eckd_identify_conf_parts(&path_private)) {
  1186. path_private.conf_data = NULL;
  1187. path_private.conf_len = 0;
  1188. continue;
  1189. }
  1190. /*
  1191. * compare path UID with device UID only if at least
  1192. * one valid path is left
  1193. * in other case the device UID may have changed and
  1194. * the first working path UID will be used as device UID
  1195. */
  1196. if (device->path_data.opm &&
  1197. dasd_eckd_compare_path_uid(device, &path_private)) {
  1198. /*
  1199. * the comparison was not successful
  1200. * rebuild the device UID with at least one
  1201. * known path in case a z/VM hyperswap command
  1202. * has changed the device
  1203. *
  1204. * after this compare again
  1205. *
  1206. * if either the rebuild or the recompare fails
  1207. * the path can not be used
  1208. */
  1209. if (rebuild_device_uid(device, data) ||
  1210. dasd_eckd_compare_path_uid(
  1211. device, &path_private)) {
  1212. uid = &path_private.uid;
  1213. if (strlen(uid->vduit) > 0)
  1214. snprintf(print_uid, sizeof(print_uid),
  1215. "%s.%s.%04x.%02x.%s",
  1216. uid->vendor, uid->serial,
  1217. uid->ssid, uid->real_unit_addr,
  1218. uid->vduit);
  1219. else
  1220. snprintf(print_uid, sizeof(print_uid),
  1221. "%s.%s.%04x.%02x",
  1222. uid->vendor, uid->serial,
  1223. uid->ssid,
  1224. uid->real_unit_addr);
  1225. dev_err(&device->cdev->dev,
  1226. "The newly added channel path %02X "
  1227. "will not be used because it leads "
  1228. "to a different device %s\n",
  1229. lpm, print_uid);
  1230. opm &= ~lpm;
  1231. npm &= ~lpm;
  1232. ppm &= ~lpm;
  1233. continue;
  1234. }
  1235. }
  1236. /*
  1237. * There is a small chance that a path is lost again between
  1238. * above path verification and the following modification of
  1239. * the device opm mask. We could avoid that race here by using
  1240. * yet another path mask, but we rather deal with this unlikely
  1241. * situation in dasd_start_IO.
  1242. */
  1243. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  1244. if (!device->path_data.opm && opm) {
  1245. device->path_data.opm = opm;
  1246. dasd_generic_path_operational(device);
  1247. } else
  1248. device->path_data.opm |= opm;
  1249. device->path_data.npm |= npm;
  1250. device->path_data.ppm |= ppm;
  1251. device->path_data.tbvpm |= epm;
  1252. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  1253. }
  1254. dasd_put_device(device);
  1255. if (data->isglobal)
  1256. mutex_unlock(&dasd_path_verification_mutex);
  1257. else
  1258. kfree(data);
  1259. }
  1260. static int dasd_eckd_verify_path(struct dasd_device *device, __u8 lpm)
  1261. {
  1262. struct path_verification_work_data *data;
  1263. data = kmalloc(sizeof(*data), GFP_ATOMIC | GFP_DMA);
  1264. if (!data) {
  1265. if (mutex_trylock(&dasd_path_verification_mutex)) {
  1266. data = path_verification_worker;
  1267. data->isglobal = 1;
  1268. } else
  1269. return -ENOMEM;
  1270. } else {
  1271. memset(data, 0, sizeof(*data));
  1272. data->isglobal = 0;
  1273. }
  1274. INIT_WORK(&data->worker, do_path_verification_work);
  1275. dasd_get_device(device);
  1276. data->device = device;
  1277. data->tbvpm = lpm;
  1278. schedule_work(&data->worker);
  1279. return 0;
  1280. }
  1281. static int dasd_eckd_read_features(struct dasd_device *device)
  1282. {
  1283. struct dasd_psf_prssd_data *prssdp;
  1284. struct dasd_rssd_features *features;
  1285. struct dasd_ccw_req *cqr;
  1286. struct ccw1 *ccw;
  1287. int rc;
  1288. struct dasd_eckd_private *private;
  1289. private = (struct dasd_eckd_private *) device->private;
  1290. memset(&private->features, 0, sizeof(struct dasd_rssd_features));
  1291. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  1292. (sizeof(struct dasd_psf_prssd_data) +
  1293. sizeof(struct dasd_rssd_features)),
  1294. device);
  1295. if (IS_ERR(cqr)) {
  1296. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s", "Could not "
  1297. "allocate initialization request");
  1298. return PTR_ERR(cqr);
  1299. }
  1300. cqr->startdev = device;
  1301. cqr->memdev = device;
  1302. cqr->block = NULL;
  1303. cqr->retries = 256;
  1304. cqr->expires = 10 * HZ;
  1305. /* Prepare for Read Subsystem Data */
  1306. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1307. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  1308. prssdp->order = PSF_ORDER_PRSSD;
  1309. prssdp->suborder = 0x41; /* Read Feature Codes */
  1310. /* all other bytes of prssdp must be zero */
  1311. ccw = cqr->cpaddr;
  1312. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  1313. ccw->count = sizeof(struct dasd_psf_prssd_data);
  1314. ccw->flags |= CCW_FLAG_CC;
  1315. ccw->cda = (__u32)(addr_t) prssdp;
  1316. /* Read Subsystem Data - feature codes */
  1317. features = (struct dasd_rssd_features *) (prssdp + 1);
  1318. memset(features, 0, sizeof(struct dasd_rssd_features));
  1319. ccw++;
  1320. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  1321. ccw->count = sizeof(struct dasd_rssd_features);
  1322. ccw->cda = (__u32)(addr_t) features;
  1323. cqr->buildclk = get_clock();
  1324. cqr->status = DASD_CQR_FILLED;
  1325. rc = dasd_sleep_on(cqr);
  1326. if (rc == 0) {
  1327. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  1328. features = (struct dasd_rssd_features *) (prssdp + 1);
  1329. memcpy(&private->features, features,
  1330. sizeof(struct dasd_rssd_features));
  1331. } else
  1332. dev_warn(&device->cdev->dev, "Reading device feature codes"
  1333. " failed with rc=%d\n", rc);
  1334. dasd_sfree_request(cqr, cqr->memdev);
  1335. return rc;
  1336. }
  1337. /*
  1338. * Build CP for Perform Subsystem Function - SSC.
  1339. */
  1340. static struct dasd_ccw_req *dasd_eckd_build_psf_ssc(struct dasd_device *device,
  1341. int enable_pav)
  1342. {
  1343. struct dasd_ccw_req *cqr;
  1344. struct dasd_psf_ssc_data *psf_ssc_data;
  1345. struct ccw1 *ccw;
  1346. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ ,
  1347. sizeof(struct dasd_psf_ssc_data),
  1348. device);
  1349. if (IS_ERR(cqr)) {
  1350. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  1351. "Could not allocate PSF-SSC request");
  1352. return cqr;
  1353. }
  1354. psf_ssc_data = (struct dasd_psf_ssc_data *)cqr->data;
  1355. psf_ssc_data->order = PSF_ORDER_SSC;
  1356. psf_ssc_data->suborder = 0xc0;
  1357. if (enable_pav) {
  1358. psf_ssc_data->suborder |= 0x08;
  1359. psf_ssc_data->reserved[0] = 0x88;
  1360. }
  1361. ccw = cqr->cpaddr;
  1362. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  1363. ccw->cda = (__u32)(addr_t)psf_ssc_data;
  1364. ccw->count = 66;
  1365. cqr->startdev = device;
  1366. cqr->memdev = device;
  1367. cqr->block = NULL;
  1368. cqr->retries = 256;
  1369. cqr->expires = 10*HZ;
  1370. cqr->buildclk = get_clock();
  1371. cqr->status = DASD_CQR_FILLED;
  1372. return cqr;
  1373. }
  1374. /*
  1375. * Perform Subsystem Function.
  1376. * It is necessary to trigger CIO for channel revalidation since this
  1377. * call might change behaviour of DASD devices.
  1378. */
  1379. static int
  1380. dasd_eckd_psf_ssc(struct dasd_device *device, int enable_pav)
  1381. {
  1382. struct dasd_ccw_req *cqr;
  1383. int rc;
  1384. cqr = dasd_eckd_build_psf_ssc(device, enable_pav);
  1385. if (IS_ERR(cqr))
  1386. return PTR_ERR(cqr);
  1387. rc = dasd_sleep_on(cqr);
  1388. if (!rc)
  1389. /* trigger CIO to reprobe devices */
  1390. css_schedule_reprobe();
  1391. dasd_sfree_request(cqr, cqr->memdev);
  1392. return rc;
  1393. }
  1394. /*
  1395. * Valide storage server of current device.
  1396. */
  1397. static void dasd_eckd_validate_server(struct dasd_device *device)
  1398. {
  1399. int rc;
  1400. struct dasd_eckd_private *private;
  1401. int enable_pav;
  1402. private = (struct dasd_eckd_private *) device->private;
  1403. if (private->uid.type == UA_BASE_PAV_ALIAS ||
  1404. private->uid.type == UA_HYPER_PAV_ALIAS)
  1405. return;
  1406. if (dasd_nopav || MACHINE_IS_VM)
  1407. enable_pav = 0;
  1408. else
  1409. enable_pav = 1;
  1410. rc = dasd_eckd_psf_ssc(device, enable_pav);
  1411. /* may be requested feature is not available on server,
  1412. * therefore just report error and go ahead */
  1413. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
  1414. "returned rc=%d", private->uid.ssid, rc);
  1415. }
  1416. /*
  1417. * worker to do a validate server in case of a lost pathgroup
  1418. */
  1419. static void dasd_eckd_do_validate_server(struct work_struct *work)
  1420. {
  1421. struct dasd_device *device = container_of(work, struct dasd_device,
  1422. kick_validate);
  1423. dasd_eckd_validate_server(device);
  1424. dasd_put_device(device);
  1425. }
  1426. static void dasd_eckd_kick_validate_server(struct dasd_device *device)
  1427. {
  1428. dasd_get_device(device);
  1429. /* exit if device not online or in offline processing */
  1430. if (test_bit(DASD_FLAG_OFFLINE, &device->flags) ||
  1431. device->state < DASD_STATE_ONLINE) {
  1432. dasd_put_device(device);
  1433. return;
  1434. }
  1435. /* queue call to do_validate_server to the kernel event daemon. */
  1436. schedule_work(&device->kick_validate);
  1437. }
  1438. static u32 get_fcx_max_data(struct dasd_device *device)
  1439. {
  1440. #if defined(CONFIG_64BIT)
  1441. int tpm, mdc;
  1442. int fcx_in_css, fcx_in_gneq, fcx_in_features;
  1443. struct dasd_eckd_private *private;
  1444. if (dasd_nofcx)
  1445. return 0;
  1446. /* is transport mode supported? */
  1447. private = (struct dasd_eckd_private *) device->private;
  1448. fcx_in_css = css_general_characteristics.fcx;
  1449. fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
  1450. fcx_in_features = private->features.feature[40] & 0x80;
  1451. tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
  1452. if (!tpm)
  1453. return 0;
  1454. mdc = ccw_device_get_mdc(device->cdev, 0);
  1455. if (mdc < 0) {
  1456. dev_warn(&device->cdev->dev, "Detecting the maximum supported"
  1457. " data size for zHPF requests failed\n");
  1458. return 0;
  1459. } else
  1460. return mdc * FCX_MAX_DATA_FACTOR;
  1461. #else
  1462. return 0;
  1463. #endif
  1464. }
  1465. /*
  1466. * Check device characteristics.
  1467. * If the device is accessible using ECKD discipline, the device is enabled.
  1468. */
  1469. static int
  1470. dasd_eckd_check_characteristics(struct dasd_device *device)
  1471. {
  1472. struct dasd_eckd_private *private;
  1473. struct dasd_block *block;
  1474. struct dasd_uid temp_uid;
  1475. int rc, i;
  1476. int readonly;
  1477. unsigned long value;
  1478. /* setup work queue for validate server*/
  1479. INIT_WORK(&device->kick_validate, dasd_eckd_do_validate_server);
  1480. if (!ccw_device_is_pathgroup(device->cdev)) {
  1481. dev_warn(&device->cdev->dev,
  1482. "A channel path group could not be established\n");
  1483. return -EIO;
  1484. }
  1485. if (!ccw_device_is_multipath(device->cdev)) {
  1486. dev_info(&device->cdev->dev,
  1487. "The DASD is not operating in multipath mode\n");
  1488. }
  1489. private = (struct dasd_eckd_private *) device->private;
  1490. if (!private) {
  1491. private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
  1492. if (!private) {
  1493. dev_warn(&device->cdev->dev,
  1494. "Allocating memory for private DASD data "
  1495. "failed\n");
  1496. return -ENOMEM;
  1497. }
  1498. device->private = (void *) private;
  1499. } else {
  1500. memset(private, 0, sizeof(*private));
  1501. }
  1502. /* Invalidate status of initial analysis. */
  1503. private->init_cqr_status = -1;
  1504. /* Set default cache operations. */
  1505. private->attrib.operation = DASD_NORMAL_CACHE;
  1506. private->attrib.nr_cyl = 0;
  1507. /* Read Configuration Data */
  1508. rc = dasd_eckd_read_conf(device);
  1509. if (rc)
  1510. goto out_err1;
  1511. /* set default timeout */
  1512. device->default_expires = DASD_EXPIRES;
  1513. if (private->gneq) {
  1514. value = 1;
  1515. for (i = 0; i < private->gneq->timeout.value; i++)
  1516. value = 10 * value;
  1517. value = value * private->gneq->timeout.number;
  1518. /* do not accept useless values */
  1519. if (value != 0 && value <= DASD_EXPIRES_MAX)
  1520. device->default_expires = value;
  1521. }
  1522. dasd_eckd_get_uid(device, &temp_uid);
  1523. if (temp_uid.type == UA_BASE_DEVICE) {
  1524. block = dasd_alloc_block();
  1525. if (IS_ERR(block)) {
  1526. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  1527. "could not allocate dasd "
  1528. "block structure");
  1529. rc = PTR_ERR(block);
  1530. goto out_err1;
  1531. }
  1532. device->block = block;
  1533. block->base = device;
  1534. }
  1535. /* register lcu with alias handling, enable PAV */
  1536. rc = dasd_alias_make_device_known_to_lcu(device);
  1537. if (rc)
  1538. goto out_err2;
  1539. dasd_eckd_validate_server(device);
  1540. /* device may report different configuration data after LCU setup */
  1541. rc = dasd_eckd_read_conf(device);
  1542. if (rc)
  1543. goto out_err3;
  1544. /* Read Feature Codes */
  1545. dasd_eckd_read_features(device);
  1546. /* Read Device Characteristics */
  1547. rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
  1548. &private->rdc_data, 64);
  1549. if (rc) {
  1550. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  1551. "Read device characteristic failed, rc=%d", rc);
  1552. goto out_err3;
  1553. }
  1554. if ((device->features & DASD_FEATURE_USERAW) &&
  1555. !(private->rdc_data.facilities.RT_in_LR)) {
  1556. dev_err(&device->cdev->dev, "The storage server does not "
  1557. "support raw-track access\n");
  1558. rc = -EINVAL;
  1559. goto out_err3;
  1560. }
  1561. /* find the valid cylinder size */
  1562. if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
  1563. private->rdc_data.long_no_cyl)
  1564. private->real_cyl = private->rdc_data.long_no_cyl;
  1565. else
  1566. private->real_cyl = private->rdc_data.no_cyl;
  1567. private->fcx_max_data = get_fcx_max_data(device);
  1568. readonly = dasd_device_is_ro(device);
  1569. if (readonly)
  1570. set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  1571. dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
  1572. "with %d cylinders, %d heads, %d sectors%s\n",
  1573. private->rdc_data.dev_type,
  1574. private->rdc_data.dev_model,
  1575. private->rdc_data.cu_type,
  1576. private->rdc_data.cu_model.model,
  1577. private->real_cyl,
  1578. private->rdc_data.trk_per_cyl,
  1579. private->rdc_data.sec_per_trk,
  1580. readonly ? ", read-only device" : "");
  1581. return 0;
  1582. out_err3:
  1583. dasd_alias_disconnect_device_from_lcu(device);
  1584. out_err2:
  1585. dasd_free_block(device->block);
  1586. device->block = NULL;
  1587. out_err1:
  1588. kfree(private->conf_data);
  1589. kfree(device->private);
  1590. device->private = NULL;
  1591. return rc;
  1592. }
  1593. static void dasd_eckd_uncheck_device(struct dasd_device *device)
  1594. {
  1595. struct dasd_eckd_private *private;
  1596. private = (struct dasd_eckd_private *) device->private;
  1597. dasd_alias_disconnect_device_from_lcu(device);
  1598. private->ned = NULL;
  1599. private->sneq = NULL;
  1600. private->vdsneq = NULL;
  1601. private->gneq = NULL;
  1602. private->conf_len = 0;
  1603. kfree(private->conf_data);
  1604. private->conf_data = NULL;
  1605. }
  1606. static struct dasd_ccw_req *
  1607. dasd_eckd_analysis_ccw(struct dasd_device *device)
  1608. {
  1609. struct dasd_eckd_private *private;
  1610. struct eckd_count *count_data;
  1611. struct LO_eckd_data *LO_data;
  1612. struct dasd_ccw_req *cqr;
  1613. struct ccw1 *ccw;
  1614. int cplength, datasize;
  1615. int i;
  1616. private = (struct dasd_eckd_private *) device->private;
  1617. cplength = 8;
  1618. datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
  1619. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
  1620. if (IS_ERR(cqr))
  1621. return cqr;
  1622. ccw = cqr->cpaddr;
  1623. /* Define extent for the first 3 tracks. */
  1624. define_extent(ccw++, cqr->data, 0, 2,
  1625. DASD_ECKD_CCW_READ_COUNT, device);
  1626. LO_data = cqr->data + sizeof(struct DE_eckd_data);
  1627. /* Locate record for the first 4 records on track 0. */
  1628. ccw[-1].flags |= CCW_FLAG_CC;
  1629. locate_record(ccw++, LO_data++, 0, 0, 4,
  1630. DASD_ECKD_CCW_READ_COUNT, device, 0);
  1631. count_data = private->count_area;
  1632. for (i = 0; i < 4; i++) {
  1633. ccw[-1].flags |= CCW_FLAG_CC;
  1634. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  1635. ccw->flags = 0;
  1636. ccw->count = 8;
  1637. ccw->cda = (__u32)(addr_t) count_data;
  1638. ccw++;
  1639. count_data++;
  1640. }
  1641. /* Locate record for the first record on track 2. */
  1642. ccw[-1].flags |= CCW_FLAG_CC;
  1643. locate_record(ccw++, LO_data++, 2, 0, 1,
  1644. DASD_ECKD_CCW_READ_COUNT, device, 0);
  1645. /* Read count ccw. */
  1646. ccw[-1].flags |= CCW_FLAG_CC;
  1647. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  1648. ccw->flags = 0;
  1649. ccw->count = 8;
  1650. ccw->cda = (__u32)(addr_t) count_data;
  1651. cqr->block = NULL;
  1652. cqr->startdev = device;
  1653. cqr->memdev = device;
  1654. cqr->retries = 255;
  1655. cqr->buildclk = get_clock();
  1656. cqr->status = DASD_CQR_FILLED;
  1657. return cqr;
  1658. }
  1659. /* differentiate between 'no record found' and any other error */
  1660. static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
  1661. {
  1662. char *sense;
  1663. if (init_cqr->status == DASD_CQR_DONE)
  1664. return INIT_CQR_OK;
  1665. else if (init_cqr->status == DASD_CQR_NEED_ERP ||
  1666. init_cqr->status == DASD_CQR_FAILED) {
  1667. sense = dasd_get_sense(&init_cqr->irb);
  1668. if (sense && (sense[1] & SNS1_NO_REC_FOUND))
  1669. return INIT_CQR_UNFORMATTED;
  1670. else
  1671. return INIT_CQR_ERROR;
  1672. } else
  1673. return INIT_CQR_ERROR;
  1674. }
  1675. /*
  1676. * This is the callback function for the init_analysis cqr. It saves
  1677. * the status of the initial analysis ccw before it frees it and kicks
  1678. * the device to continue the startup sequence. This will call
  1679. * dasd_eckd_do_analysis again (if the devices has not been marked
  1680. * for deletion in the meantime).
  1681. */
  1682. static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
  1683. void *data)
  1684. {
  1685. struct dasd_eckd_private *private;
  1686. struct dasd_device *device;
  1687. device = init_cqr->startdev;
  1688. private = (struct dasd_eckd_private *) device->private;
  1689. private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
  1690. dasd_sfree_request(init_cqr, device);
  1691. dasd_kick_device(device);
  1692. }
  1693. static int dasd_eckd_start_analysis(struct dasd_block *block)
  1694. {
  1695. struct dasd_ccw_req *init_cqr;
  1696. init_cqr = dasd_eckd_analysis_ccw(block->base);
  1697. if (IS_ERR(init_cqr))
  1698. return PTR_ERR(init_cqr);
  1699. init_cqr->callback = dasd_eckd_analysis_callback;
  1700. init_cqr->callback_data = NULL;
  1701. init_cqr->expires = 5*HZ;
  1702. /* first try without ERP, so we can later handle unformatted
  1703. * devices as special case
  1704. */
  1705. clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
  1706. init_cqr->retries = 0;
  1707. dasd_add_request_head(init_cqr);
  1708. return -EAGAIN;
  1709. }
  1710. static int dasd_eckd_end_analysis(struct dasd_block *block)
  1711. {
  1712. struct dasd_device *device;
  1713. struct dasd_eckd_private *private;
  1714. struct eckd_count *count_area;
  1715. unsigned int sb, blk_per_trk;
  1716. int status, i;
  1717. struct dasd_ccw_req *init_cqr;
  1718. device = block->base;
  1719. private = (struct dasd_eckd_private *) device->private;
  1720. status = private->init_cqr_status;
  1721. private->init_cqr_status = -1;
  1722. if (status == INIT_CQR_ERROR) {
  1723. /* try again, this time with full ERP */
  1724. init_cqr = dasd_eckd_analysis_ccw(device);
  1725. dasd_sleep_on(init_cqr);
  1726. status = dasd_eckd_analysis_evaluation(init_cqr);
  1727. dasd_sfree_request(init_cqr, device);
  1728. }
  1729. if (device->features & DASD_FEATURE_USERAW) {
  1730. block->bp_block = DASD_RAW_BLOCKSIZE;
  1731. blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
  1732. block->s2b_shift = 3;
  1733. goto raw;
  1734. }
  1735. if (status == INIT_CQR_UNFORMATTED) {
  1736. dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
  1737. return -EMEDIUMTYPE;
  1738. } else if (status == INIT_CQR_ERROR) {
  1739. dev_err(&device->cdev->dev,
  1740. "Detecting the DASD disk layout failed because "
  1741. "of an I/O error\n");
  1742. return -EIO;
  1743. }
  1744. private->uses_cdl = 1;
  1745. /* Check Track 0 for Compatible Disk Layout */
  1746. count_area = NULL;
  1747. for (i = 0; i < 3; i++) {
  1748. if (private->count_area[i].kl != 4 ||
  1749. private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
  1750. private->uses_cdl = 0;
  1751. break;
  1752. }
  1753. }
  1754. if (i == 3)
  1755. count_area = &private->count_area[4];
  1756. if (private->uses_cdl == 0) {
  1757. for (i = 0; i < 5; i++) {
  1758. if ((private->count_area[i].kl != 0) ||
  1759. (private->count_area[i].dl !=
  1760. private->count_area[0].dl))
  1761. break;
  1762. }
  1763. if (i == 5)
  1764. count_area = &private->count_area[0];
  1765. } else {
  1766. if (private->count_area[3].record == 1)
  1767. dev_warn(&device->cdev->dev,
  1768. "Track 0 has no records following the VTOC\n");
  1769. }
  1770. if (count_area != NULL && count_area->kl == 0) {
  1771. /* we found notthing violating our disk layout */
  1772. if (dasd_check_blocksize(count_area->dl) == 0)
  1773. block->bp_block = count_area->dl;
  1774. }
  1775. if (block->bp_block == 0) {
  1776. dev_warn(&device->cdev->dev,
  1777. "The disk layout of the DASD is not supported\n");
  1778. return -EMEDIUMTYPE;
  1779. }
  1780. block->s2b_shift = 0; /* bits to shift 512 to get a block */
  1781. for (sb = 512; sb < block->bp_block; sb = sb << 1)
  1782. block->s2b_shift++;
  1783. blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
  1784. raw:
  1785. block->blocks = (private->real_cyl *
  1786. private->rdc_data.trk_per_cyl *
  1787. blk_per_trk);
  1788. dev_info(&device->cdev->dev,
  1789. "DASD with %d KB/block, %d KB total size, %d KB/track, "
  1790. "%s\n", (block->bp_block >> 10),
  1791. ((private->real_cyl *
  1792. private->rdc_data.trk_per_cyl *
  1793. blk_per_trk * (block->bp_block >> 9)) >> 1),
  1794. ((blk_per_trk * block->bp_block) >> 10),
  1795. private->uses_cdl ?
  1796. "compatible disk layout" : "linux disk layout");
  1797. return 0;
  1798. }
  1799. static int dasd_eckd_do_analysis(struct dasd_block *block)
  1800. {
  1801. struct dasd_eckd_private *private;
  1802. private = (struct dasd_eckd_private *) block->base->private;
  1803. if (private->init_cqr_status < 0)
  1804. return dasd_eckd_start_analysis(block);
  1805. else
  1806. return dasd_eckd_end_analysis(block);
  1807. }
  1808. static int dasd_eckd_ready_to_online(struct dasd_device *device)
  1809. {
  1810. return dasd_alias_add_device(device);
  1811. };
  1812. static int dasd_eckd_online_to_ready(struct dasd_device *device)
  1813. {
  1814. cancel_work_sync(&device->reload_device);
  1815. cancel_work_sync(&device->kick_validate);
  1816. return dasd_alias_remove_device(device);
  1817. };
  1818. static int
  1819. dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
  1820. {
  1821. struct dasd_eckd_private *private;
  1822. private = (struct dasd_eckd_private *) block->base->private;
  1823. if (dasd_check_blocksize(block->bp_block) == 0) {
  1824. geo->sectors = recs_per_track(&private->rdc_data,
  1825. 0, block->bp_block);
  1826. }
  1827. geo->cylinders = private->rdc_data.no_cyl;
  1828. geo->heads = private->rdc_data.trk_per_cyl;
  1829. return 0;
  1830. }
  1831. static struct dasd_ccw_req *
  1832. dasd_eckd_format_device(struct dasd_device * device,
  1833. struct format_data_t * fdata)
  1834. {
  1835. struct dasd_eckd_private *private;
  1836. struct dasd_ccw_req *fcp;
  1837. struct eckd_count *ect;
  1838. struct ccw1 *ccw;
  1839. void *data;
  1840. int rpt;
  1841. struct ch_t address;
  1842. int cplength, datasize;
  1843. int i;
  1844. int intensity = 0;
  1845. int r0_perm;
  1846. private = (struct dasd_eckd_private *) device->private;
  1847. rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
  1848. set_ch_t(&address,
  1849. fdata->start_unit / private->rdc_data.trk_per_cyl,
  1850. fdata->start_unit % private->rdc_data.trk_per_cyl);
  1851. /* Sanity checks. */
  1852. if (fdata->start_unit >=
  1853. (private->real_cyl * private->rdc_data.trk_per_cyl)) {
  1854. dev_warn(&device->cdev->dev, "Start track number %d used in "
  1855. "formatting is too big\n", fdata->start_unit);
  1856. return ERR_PTR(-EINVAL);
  1857. }
  1858. if (fdata->start_unit > fdata->stop_unit) {
  1859. dev_warn(&device->cdev->dev, "Start track %d used in "
  1860. "formatting exceeds end track\n", fdata->start_unit);
  1861. return ERR_PTR(-EINVAL);
  1862. }
  1863. if (dasd_check_blocksize(fdata->blksize) != 0) {
  1864. dev_warn(&device->cdev->dev,
  1865. "The DASD cannot be formatted with block size %d\n",
  1866. fdata->blksize);
  1867. return ERR_PTR(-EINVAL);
  1868. }
  1869. /*
  1870. * fdata->intensity is a bit string that tells us what to do:
  1871. * Bit 0: write record zero
  1872. * Bit 1: write home address, currently not supported
  1873. * Bit 2: invalidate tracks
  1874. * Bit 3: use OS/390 compatible disk layout (cdl)
  1875. * Bit 4: do not allow storage subsystem to modify record zero
  1876. * Only some bit combinations do make sense.
  1877. */
  1878. if (fdata->intensity & 0x10) {
  1879. r0_perm = 0;
  1880. intensity = fdata->intensity & ~0x10;
  1881. } else {
  1882. r0_perm = 1;
  1883. intensity = fdata->intensity;
  1884. }
  1885. switch (intensity) {
  1886. case 0x00: /* Normal format */
  1887. case 0x08: /* Normal format, use cdl. */
  1888. cplength = 2 + rpt;
  1889. datasize = sizeof(struct DE_eckd_data) +
  1890. sizeof(struct LO_eckd_data) +
  1891. rpt * sizeof(struct eckd_count);
  1892. break;
  1893. case 0x01: /* Write record zero and format track. */
  1894. case 0x09: /* Write record zero and format track, use cdl. */
  1895. cplength = 3 + rpt;
  1896. datasize = sizeof(struct DE_eckd_data) +
  1897. sizeof(struct LO_eckd_data) +
  1898. sizeof(struct eckd_count) +
  1899. rpt * sizeof(struct eckd_count);
  1900. break;
  1901. case 0x04: /* Invalidate track. */
  1902. case 0x0c: /* Invalidate track, use cdl. */
  1903. cplength = 3;
  1904. datasize = sizeof(struct DE_eckd_data) +
  1905. sizeof(struct LO_eckd_data) +
  1906. sizeof(struct eckd_count);
  1907. break;
  1908. default:
  1909. dev_warn(&device->cdev->dev, "An I/O control call used "
  1910. "incorrect flags 0x%x\n", fdata->intensity);
  1911. return ERR_PTR(-EINVAL);
  1912. }
  1913. /* Allocate the format ccw request. */
  1914. fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
  1915. if (IS_ERR(fcp))
  1916. return fcp;
  1917. data = fcp->data;
  1918. ccw = fcp->cpaddr;
  1919. switch (intensity & ~0x08) {
  1920. case 0x00: /* Normal format. */
  1921. define_extent(ccw++, (struct DE_eckd_data *) data,
  1922. fdata->start_unit, fdata->start_unit,
  1923. DASD_ECKD_CCW_WRITE_CKD, device);
  1924. /* grant subsystem permission to format R0 */
  1925. if (r0_perm)
  1926. ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
  1927. data += sizeof(struct DE_eckd_data);
  1928. ccw[-1].flags |= CCW_FLAG_CC;
  1929. locate_record(ccw++, (struct LO_eckd_data *) data,
  1930. fdata->start_unit, 0, rpt,
  1931. DASD_ECKD_CCW_WRITE_CKD, device,
  1932. fdata->blksize);
  1933. data += sizeof(struct LO_eckd_data);
  1934. break;
  1935. case 0x01: /* Write record zero + format track. */
  1936. define_extent(ccw++, (struct DE_eckd_data *) data,
  1937. fdata->start_unit, fdata->start_unit,
  1938. DASD_ECKD_CCW_WRITE_RECORD_ZERO,
  1939. device);
  1940. data += sizeof(struct DE_eckd_data);
  1941. ccw[-1].flags |= CCW_FLAG_CC;
  1942. locate_record(ccw++, (struct LO_eckd_data *) data,
  1943. fdata->start_unit, 0, rpt + 1,
  1944. DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
  1945. device->block->bp_block);
  1946. data += sizeof(struct LO_eckd_data);
  1947. break;
  1948. case 0x04: /* Invalidate track. */
  1949. define_extent(ccw++, (struct DE_eckd_data *) data,
  1950. fdata->start_unit, fdata->start_unit,
  1951. DASD_ECKD_CCW_WRITE_CKD, device);
  1952. data += sizeof(struct DE_eckd_data);
  1953. ccw[-1].flags |= CCW_FLAG_CC;
  1954. locate_record(ccw++, (struct LO_eckd_data *) data,
  1955. fdata->start_unit, 0, 1,
  1956. DASD_ECKD_CCW_WRITE_CKD, device, 8);
  1957. data += sizeof(struct LO_eckd_data);
  1958. break;
  1959. }
  1960. if (intensity & 0x01) { /* write record zero */
  1961. ect = (struct eckd_count *) data;
  1962. data += sizeof(struct eckd_count);
  1963. ect->cyl = address.cyl;
  1964. ect->head = address.head;
  1965. ect->record = 0;
  1966. ect->kl = 0;
  1967. ect->dl = 8;
  1968. ccw[-1].flags |= CCW_FLAG_CC;
  1969. ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
  1970. ccw->flags = CCW_FLAG_SLI;
  1971. ccw->count = 8;
  1972. ccw->cda = (__u32)(addr_t) ect;
  1973. ccw++;
  1974. }
  1975. if ((intensity & ~0x08) & 0x04) { /* erase track */
  1976. ect = (struct eckd_count *) data;
  1977. data += sizeof(struct eckd_count);
  1978. ect->cyl = address.cyl;
  1979. ect->head = address.head;
  1980. ect->record = 1;
  1981. ect->kl = 0;
  1982. ect->dl = 0;
  1983. ccw[-1].flags |= CCW_FLAG_CC;
  1984. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  1985. ccw->flags = CCW_FLAG_SLI;
  1986. ccw->count = 8;
  1987. ccw->cda = (__u32)(addr_t) ect;
  1988. } else { /* write remaining records */
  1989. for (i = 0; i < rpt; i++) {
  1990. ect = (struct eckd_count *) data;
  1991. data += sizeof(struct eckd_count);
  1992. ect->cyl = address.cyl;
  1993. ect->head = address.head;
  1994. ect->record = i + 1;
  1995. ect->kl = 0;
  1996. ect->dl = fdata->blksize;
  1997. /* Check for special tracks 0-1 when formatting CDL */
  1998. if ((intensity & 0x08) &&
  1999. fdata->start_unit == 0) {
  2000. if (i < 3) {
  2001. ect->kl = 4;
  2002. ect->dl = sizes_trk0[i] - 4;
  2003. }
  2004. }
  2005. if ((intensity & 0x08) &&
  2006. fdata->start_unit == 1) {
  2007. ect->kl = 44;
  2008. ect->dl = LABEL_SIZE - 44;
  2009. }
  2010. ccw[-1].flags |= CCW_FLAG_CC;
  2011. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  2012. ccw->flags = CCW_FLAG_SLI;
  2013. ccw->count = 8;
  2014. ccw->cda = (__u32)(addr_t) ect;
  2015. ccw++;
  2016. }
  2017. }
  2018. fcp->startdev = device;
  2019. fcp->memdev = device;
  2020. fcp->retries = 256;
  2021. fcp->buildclk = get_clock();
  2022. fcp->status = DASD_CQR_FILLED;
  2023. return fcp;
  2024. }
  2025. static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
  2026. {
  2027. cqr->status = DASD_CQR_FILLED;
  2028. if (cqr->block && (cqr->startdev != cqr->block->base)) {
  2029. dasd_eckd_reset_ccw_to_base_io(cqr);
  2030. cqr->startdev = cqr->block->base;
  2031. cqr->lpm = cqr->block->base->path_data.opm;
  2032. }
  2033. };
  2034. static dasd_erp_fn_t
  2035. dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
  2036. {
  2037. struct dasd_device *device = (struct dasd_device *) cqr->startdev;
  2038. struct ccw_device *cdev = device->cdev;
  2039. switch (cdev->id.cu_type) {
  2040. case 0x3990:
  2041. case 0x2105:
  2042. case 0x2107:
  2043. case 0x1750:
  2044. return dasd_3990_erp_action;
  2045. case 0x9343:
  2046. case 0x3880:
  2047. default:
  2048. return dasd_default_erp_action;
  2049. }
  2050. }
  2051. static dasd_erp_fn_t
  2052. dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
  2053. {
  2054. return dasd_default_erp_postaction;
  2055. }
  2056. static void dasd_eckd_check_for_device_change(struct dasd_device *device,
  2057. struct dasd_ccw_req *cqr,
  2058. struct irb *irb)
  2059. {
  2060. char mask;
  2061. char *sense = NULL;
  2062. struct dasd_eckd_private *private;
  2063. private = (struct dasd_eckd_private *) device->private;
  2064. /* first of all check for state change pending interrupt */
  2065. mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
  2066. if ((scsw_dstat(&irb->scsw) & mask) == mask) {
  2067. /*
  2068. * for alias only, not in offline processing
  2069. * and only if not suspended
  2070. */
  2071. if (!device->block && private->lcu &&
  2072. device->state == DASD_STATE_ONLINE &&
  2073. !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
  2074. !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
  2075. /*
  2076. * the state change could be caused by an alias
  2077. * reassignment remove device from alias handling
  2078. * to prevent new requests from being scheduled on
  2079. * the wrong alias device
  2080. */
  2081. dasd_alias_remove_device(device);
  2082. /* schedule worker to reload device */
  2083. dasd_reload_device(device);
  2084. }
  2085. dasd_generic_handle_state_change(device);
  2086. return;
  2087. }
  2088. sense = dasd_get_sense(irb);
  2089. if (!sense)
  2090. return;
  2091. /* summary unit check */
  2092. if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
  2093. (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
  2094. dasd_alias_handle_summary_unit_check(device, irb);
  2095. return;
  2096. }
  2097. /* service information message SIM */
  2098. if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
  2099. ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
  2100. dasd_3990_erp_handle_sim(device, sense);
  2101. return;
  2102. }
  2103. /* loss of device reservation is handled via base devices only
  2104. * as alias devices may be used with several bases
  2105. */
  2106. if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
  2107. (sense[7] == 0x3F) &&
  2108. (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
  2109. test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
  2110. if (device->features & DASD_FEATURE_FAILONSLCK)
  2111. set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
  2112. clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  2113. dev_err(&device->cdev->dev,
  2114. "The device reservation was lost\n");
  2115. }
  2116. }
  2117. static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
  2118. struct dasd_device *startdev,
  2119. struct dasd_block *block,
  2120. struct request *req,
  2121. sector_t first_rec,
  2122. sector_t last_rec,
  2123. sector_t first_trk,
  2124. sector_t last_trk,
  2125. unsigned int first_offs,
  2126. unsigned int last_offs,
  2127. unsigned int blk_per_trk,
  2128. unsigned int blksize)
  2129. {
  2130. struct dasd_eckd_private *private;
  2131. unsigned long *idaws;
  2132. struct LO_eckd_data *LO_data;
  2133. struct dasd_ccw_req *cqr;
  2134. struct ccw1 *ccw;
  2135. struct req_iterator iter;
  2136. struct bio_vec *bv;
  2137. char *dst;
  2138. unsigned int off;
  2139. int count, cidaw, cplength, datasize;
  2140. sector_t recid;
  2141. unsigned char cmd, rcmd;
  2142. int use_prefix;
  2143. struct dasd_device *basedev;
  2144. basedev = block->base;
  2145. private = (struct dasd_eckd_private *) basedev->private;
  2146. if (rq_data_dir(req) == READ)
  2147. cmd = DASD_ECKD_CCW_READ_MT;
  2148. else if (rq_data_dir(req) == WRITE)
  2149. cmd = DASD_ECKD_CCW_WRITE_MT;
  2150. else
  2151. return ERR_PTR(-EINVAL);
  2152. /* Check struct bio and count the number of blocks for the request. */
  2153. count = 0;
  2154. cidaw = 0;
  2155. rq_for_each_segment(bv, req, iter) {
  2156. if (bv->bv_len & (blksize - 1))
  2157. /* Eckd can only do full blocks. */
  2158. return ERR_PTR(-EINVAL);
  2159. count += bv->bv_len >> (block->s2b_shift + 9);
  2160. #if defined(CONFIG_64BIT)
  2161. if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
  2162. cidaw += bv->bv_len >> (block->s2b_shift + 9);
  2163. #endif
  2164. }
  2165. /* Paranoia. */
  2166. if (count != last_rec - first_rec + 1)
  2167. return ERR_PTR(-EINVAL);
  2168. /* use the prefix command if available */
  2169. use_prefix = private->features.feature[8] & 0x01;
  2170. if (use_prefix) {
  2171. /* 1x prefix + number of blocks */
  2172. cplength = 2 + count;
  2173. /* 1x prefix + cidaws*sizeof(long) */
  2174. datasize = sizeof(struct PFX_eckd_data) +
  2175. sizeof(struct LO_eckd_data) +
  2176. cidaw * sizeof(unsigned long);
  2177. } else {
  2178. /* 1x define extent + 1x locate record + number of blocks */
  2179. cplength = 2 + count;
  2180. /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
  2181. datasize = sizeof(struct DE_eckd_data) +
  2182. sizeof(struct LO_eckd_data) +
  2183. cidaw * sizeof(unsigned long);
  2184. }
  2185. /* Find out the number of additional locate record ccws for cdl. */
  2186. if (private->uses_cdl && first_rec < 2*blk_per_trk) {
  2187. if (last_rec >= 2*blk_per_trk)
  2188. count = 2*blk_per_trk - first_rec;
  2189. cplength += count;
  2190. datasize += count*sizeof(struct LO_eckd_data);
  2191. }
  2192. /* Allocate the ccw request. */
  2193. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
  2194. startdev);
  2195. if (IS_ERR(cqr))
  2196. return cqr;
  2197. ccw = cqr->cpaddr;
  2198. /* First ccw is define extent or prefix. */
  2199. if (use_prefix) {
  2200. if (prefix(ccw++, cqr->data, first_trk,
  2201. last_trk, cmd, basedev, startdev) == -EAGAIN) {
  2202. /* Clock not in sync and XRC is enabled.
  2203. * Try again later.
  2204. */
  2205. dasd_sfree_request(cqr, startdev);
  2206. return ERR_PTR(-EAGAIN);
  2207. }
  2208. idaws = (unsigned long *) (cqr->data +
  2209. sizeof(struct PFX_eckd_data));
  2210. } else {
  2211. if (define_extent(ccw++, cqr->data, first_trk,
  2212. last_trk, cmd, basedev) == -EAGAIN) {
  2213. /* Clock not in sync and XRC is enabled.
  2214. * Try again later.
  2215. */
  2216. dasd_sfree_request(cqr, startdev);
  2217. return ERR_PTR(-EAGAIN);
  2218. }
  2219. idaws = (unsigned long *) (cqr->data +
  2220. sizeof(struct DE_eckd_data));
  2221. }
  2222. /* Build locate_record+read/write/ccws. */
  2223. LO_data = (struct LO_eckd_data *) (idaws + cidaw);
  2224. recid = first_rec;
  2225. if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
  2226. /* Only standard blocks so there is just one locate record. */
  2227. ccw[-1].flags |= CCW_FLAG_CC;
  2228. locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
  2229. last_rec - recid + 1, cmd, basedev, blksize);
  2230. }
  2231. rq_for_each_segment(bv, req, iter) {
  2232. dst = page_address(bv->bv_page) + bv->bv_offset;
  2233. if (dasd_page_cache) {
  2234. char *copy = kmem_cache_alloc(dasd_page_cache,
  2235. GFP_DMA | __GFP_NOWARN);
  2236. if (copy && rq_data_dir(req) == WRITE)
  2237. memcpy(copy + bv->bv_offset, dst, bv->bv_len);
  2238. if (copy)
  2239. dst = copy + bv->bv_offset;
  2240. }
  2241. for (off = 0; off < bv->bv_len; off += blksize) {
  2242. sector_t trkid = recid;
  2243. unsigned int recoffs = sector_div(trkid, blk_per_trk);
  2244. rcmd = cmd;
  2245. count = blksize;
  2246. /* Locate record for cdl special block ? */
  2247. if (private->uses_cdl && recid < 2*blk_per_trk) {
  2248. if (dasd_eckd_cdl_special(blk_per_trk, recid)){
  2249. rcmd |= 0x8;
  2250. count = dasd_eckd_cdl_reclen(recid);
  2251. if (count < blksize &&
  2252. rq_data_dir(req) == READ)
  2253. memset(dst + count, 0xe5,
  2254. blksize - count);
  2255. }
  2256. ccw[-1].flags |= CCW_FLAG_CC;
  2257. locate_record(ccw++, LO_data++,
  2258. trkid, recoffs + 1,
  2259. 1, rcmd, basedev, count);
  2260. }
  2261. /* Locate record for standard blocks ? */
  2262. if (private->uses_cdl && recid == 2*blk_per_trk) {
  2263. ccw[-1].flags |= CCW_FLAG_CC;
  2264. locate_record(ccw++, LO_data++,
  2265. trkid, recoffs + 1,
  2266. last_rec - recid + 1,
  2267. cmd, basedev, count);
  2268. }
  2269. /* Read/write ccw. */
  2270. ccw[-1].flags |= CCW_FLAG_CC;
  2271. ccw->cmd_code = rcmd;
  2272. ccw->count = count;
  2273. if (idal_is_needed(dst, blksize)) {
  2274. ccw->cda = (__u32)(addr_t) idaws;
  2275. ccw->flags = CCW_FLAG_IDA;
  2276. idaws = idal_create_words(idaws, dst, blksize);
  2277. } else {
  2278. ccw->cda = (__u32)(addr_t) dst;
  2279. ccw->flags = 0;
  2280. }
  2281. ccw++;
  2282. dst += blksize;
  2283. recid++;
  2284. }
  2285. }
  2286. if (blk_noretry_request(req) ||
  2287. block->base->features & DASD_FEATURE_FAILFAST)
  2288. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2289. cqr->startdev = startdev;
  2290. cqr->memdev = startdev;
  2291. cqr->block = block;
  2292. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  2293. cqr->lpm = startdev->path_data.ppm;
  2294. cqr->retries = 256;
  2295. cqr->buildclk = get_clock();
  2296. cqr->status = DASD_CQR_FILLED;
  2297. return cqr;
  2298. }
  2299. static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
  2300. struct dasd_device *startdev,
  2301. struct dasd_block *block,
  2302. struct request *req,
  2303. sector_t first_rec,
  2304. sector_t last_rec,
  2305. sector_t first_trk,
  2306. sector_t last_trk,
  2307. unsigned int first_offs,
  2308. unsigned int last_offs,
  2309. unsigned int blk_per_trk,
  2310. unsigned int blksize)
  2311. {
  2312. unsigned long *idaws;
  2313. struct dasd_ccw_req *cqr;
  2314. struct ccw1 *ccw;
  2315. struct req_iterator iter;
  2316. struct bio_vec *bv;
  2317. char *dst, *idaw_dst;
  2318. unsigned int cidaw, cplength, datasize;
  2319. unsigned int tlf;
  2320. sector_t recid;
  2321. unsigned char cmd;
  2322. struct dasd_device *basedev;
  2323. unsigned int trkcount, count, count_to_trk_end;
  2324. unsigned int idaw_len, seg_len, part_len, len_to_track_end;
  2325. unsigned char new_track, end_idaw;
  2326. sector_t trkid;
  2327. unsigned int recoffs;
  2328. basedev = block->base;
  2329. if (rq_data_dir(req) == READ)
  2330. cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
  2331. else if (rq_data_dir(req) == WRITE)
  2332. cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
  2333. else
  2334. return ERR_PTR(-EINVAL);
  2335. /* Track based I/O needs IDAWs for each page, and not just for
  2336. * 64 bit addresses. We need additional idals for pages
  2337. * that get filled from two tracks, so we use the number
  2338. * of records as upper limit.
  2339. */
  2340. cidaw = last_rec - first_rec + 1;
  2341. trkcount = last_trk - first_trk + 1;
  2342. /* 1x prefix + one read/write ccw per track */
  2343. cplength = 1 + trkcount;
  2344. /* on 31-bit we need space for two 32 bit addresses per page
  2345. * on 64-bit one 64 bit address
  2346. */
  2347. datasize = sizeof(struct PFX_eckd_data) +
  2348. cidaw * sizeof(unsigned long long);
  2349. /* Allocate the ccw request. */
  2350. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
  2351. startdev);
  2352. if (IS_ERR(cqr))
  2353. return cqr;
  2354. ccw = cqr->cpaddr;
  2355. /* transfer length factor: how many bytes to read from the last track */
  2356. if (first_trk == last_trk)
  2357. tlf = last_offs - first_offs + 1;
  2358. else
  2359. tlf = last_offs + 1;
  2360. tlf *= blksize;
  2361. if (prefix_LRE(ccw++, cqr->data, first_trk,
  2362. last_trk, cmd, basedev, startdev,
  2363. 1 /* format */, first_offs + 1,
  2364. trkcount, blksize,
  2365. tlf) == -EAGAIN) {
  2366. /* Clock not in sync and XRC is enabled.
  2367. * Try again later.
  2368. */
  2369. dasd_sfree_request(cqr, startdev);
  2370. return ERR_PTR(-EAGAIN);
  2371. }
  2372. /*
  2373. * The translation of request into ccw programs must meet the
  2374. * following conditions:
  2375. * - all idaws but the first and the last must address full pages
  2376. * (or 2K blocks on 31-bit)
  2377. * - the scope of a ccw and it's idal ends with the track boundaries
  2378. */
  2379. idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
  2380. recid = first_rec;
  2381. new_track = 1;
  2382. end_idaw = 0;
  2383. len_to_track_end = 0;
  2384. idaw_dst = NULL;
  2385. idaw_len = 0;
  2386. rq_for_each_segment(bv, req, iter) {
  2387. dst = page_address(bv->bv_page) + bv->bv_offset;
  2388. seg_len = bv->bv_len;
  2389. while (seg_len) {
  2390. if (new_track) {
  2391. trkid = recid;
  2392. recoffs = sector_div(trkid, blk_per_trk);
  2393. count_to_trk_end = blk_per_trk - recoffs;
  2394. count = min((last_rec - recid + 1),
  2395. (sector_t)count_to_trk_end);
  2396. len_to_track_end = count * blksize;
  2397. ccw[-1].flags |= CCW_FLAG_CC;
  2398. ccw->cmd_code = cmd;
  2399. ccw->count = len_to_track_end;
  2400. ccw->cda = (__u32)(addr_t)idaws;
  2401. ccw->flags = CCW_FLAG_IDA;
  2402. ccw++;
  2403. recid += count;
  2404. new_track = 0;
  2405. /* first idaw for a ccw may start anywhere */
  2406. if (!idaw_dst)
  2407. idaw_dst = dst;
  2408. }
  2409. /* If we start a new idaw, we must make sure that it
  2410. * starts on an IDA_BLOCK_SIZE boundary.
  2411. * If we continue an idaw, we must make sure that the
  2412. * current segment begins where the so far accumulated
  2413. * idaw ends
  2414. */
  2415. if (!idaw_dst) {
  2416. if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
  2417. dasd_sfree_request(cqr, startdev);
  2418. return ERR_PTR(-ERANGE);
  2419. } else
  2420. idaw_dst = dst;
  2421. }
  2422. if ((idaw_dst + idaw_len) != dst) {
  2423. dasd_sfree_request(cqr, startdev);
  2424. return ERR_PTR(-ERANGE);
  2425. }
  2426. part_len = min(seg_len, len_to_track_end);
  2427. seg_len -= part_len;
  2428. dst += part_len;
  2429. idaw_len += part_len;
  2430. len_to_track_end -= part_len;
  2431. /* collected memory area ends on an IDA_BLOCK border,
  2432. * -> create an idaw
  2433. * idal_create_words will handle cases where idaw_len
  2434. * is larger then IDA_BLOCK_SIZE
  2435. */
  2436. if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
  2437. end_idaw = 1;
  2438. /* We also need to end the idaw at track end */
  2439. if (!len_to_track_end) {
  2440. new_track = 1;
  2441. end_idaw = 1;
  2442. }
  2443. if (end_idaw) {
  2444. idaws = idal_create_words(idaws, idaw_dst,
  2445. idaw_len);
  2446. idaw_dst = NULL;
  2447. idaw_len = 0;
  2448. end_idaw = 0;
  2449. }
  2450. }
  2451. }
  2452. if (blk_noretry_request(req) ||
  2453. block->base->features & DASD_FEATURE_FAILFAST)
  2454. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2455. cqr->startdev = startdev;
  2456. cqr->memdev = startdev;
  2457. cqr->block = block;
  2458. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  2459. cqr->lpm = startdev->path_data.ppm;
  2460. cqr->retries = 256;
  2461. cqr->buildclk = get_clock();
  2462. cqr->status = DASD_CQR_FILLED;
  2463. return cqr;
  2464. }
  2465. static int prepare_itcw(struct itcw *itcw,
  2466. unsigned int trk, unsigned int totrk, int cmd,
  2467. struct dasd_device *basedev,
  2468. struct dasd_device *startdev,
  2469. unsigned int rec_on_trk, int count,
  2470. unsigned int blksize,
  2471. unsigned int total_data_size,
  2472. unsigned int tlf,
  2473. unsigned int blk_per_trk)
  2474. {
  2475. struct PFX_eckd_data pfxdata;
  2476. struct dasd_eckd_private *basepriv, *startpriv;
  2477. struct DE_eckd_data *dedata;
  2478. struct LRE_eckd_data *lredata;
  2479. struct dcw *dcw;
  2480. u32 begcyl, endcyl;
  2481. u16 heads, beghead, endhead;
  2482. u8 pfx_cmd;
  2483. int rc = 0;
  2484. int sector = 0;
  2485. int dn, d;
  2486. /* setup prefix data */
  2487. basepriv = (struct dasd_eckd_private *) basedev->private;
  2488. startpriv = (struct dasd_eckd_private *) startdev->private;
  2489. dedata = &pfxdata.define_extent;
  2490. lredata = &pfxdata.locate_record;
  2491. memset(&pfxdata, 0, sizeof(pfxdata));
  2492. pfxdata.format = 1; /* PFX with LRE */
  2493. pfxdata.base_address = basepriv->ned->unit_addr;
  2494. pfxdata.base_lss = basepriv->ned->ID;
  2495. pfxdata.validity.define_extent = 1;
  2496. /* private uid is kept up to date, conf_data may be outdated */
  2497. if (startpriv->uid.type != UA_BASE_DEVICE) {
  2498. pfxdata.validity.verify_base = 1;
  2499. if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
  2500. pfxdata.validity.hyper_pav = 1;
  2501. }
  2502. switch (cmd) {
  2503. case DASD_ECKD_CCW_READ_TRACK_DATA:
  2504. dedata->mask.perm = 0x1;
  2505. dedata->attributes.operation = basepriv->attrib.operation;
  2506. dedata->blk_size = blksize;
  2507. dedata->ga_extended |= 0x42;
  2508. lredata->operation.orientation = 0x0;
  2509. lredata->operation.operation = 0x0C;
  2510. lredata->auxiliary.check_bytes = 0x01;
  2511. pfx_cmd = DASD_ECKD_CCW_PFX_READ;
  2512. break;
  2513. case DASD_ECKD_CCW_WRITE_TRACK_DATA:
  2514. dedata->mask.perm = 0x02;
  2515. dedata->attributes.operation = basepriv->attrib.operation;
  2516. dedata->blk_size = blksize;
  2517. rc = check_XRC_on_prefix(&pfxdata, basedev);
  2518. dedata->ga_extended |= 0x42;
  2519. lredata->operation.orientation = 0x0;
  2520. lredata->operation.operation = 0x3F;
  2521. lredata->extended_operation = 0x23;
  2522. lredata->auxiliary.check_bytes = 0x2;
  2523. pfx_cmd = DASD_ECKD_CCW_PFX;
  2524. break;
  2525. default:
  2526. DBF_DEV_EVENT(DBF_ERR, basedev,
  2527. "prepare itcw, unknown opcode 0x%x", cmd);
  2528. BUG();
  2529. break;
  2530. }
  2531. if (rc)
  2532. return rc;
  2533. dedata->attributes.mode = 0x3; /* ECKD */
  2534. heads = basepriv->rdc_data.trk_per_cyl;
  2535. begcyl = trk / heads;
  2536. beghead = trk % heads;
  2537. endcyl = totrk / heads;
  2538. endhead = totrk % heads;
  2539. /* check for sequential prestage - enhance cylinder range */
  2540. if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
  2541. dedata->attributes.operation == DASD_SEQ_ACCESS) {
  2542. if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
  2543. endcyl += basepriv->attrib.nr_cyl;
  2544. else
  2545. endcyl = (basepriv->real_cyl - 1);
  2546. }
  2547. set_ch_t(&dedata->beg_ext, begcyl, beghead);
  2548. set_ch_t(&dedata->end_ext, endcyl, endhead);
  2549. dedata->ep_format = 0x20; /* records per track is valid */
  2550. dedata->ep_rec_per_track = blk_per_trk;
  2551. if (rec_on_trk) {
  2552. switch (basepriv->rdc_data.dev_type) {
  2553. case 0x3390:
  2554. dn = ceil_quot(blksize + 6, 232);
  2555. d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
  2556. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  2557. break;
  2558. case 0x3380:
  2559. d = 7 + ceil_quot(blksize + 12, 32);
  2560. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  2561. break;
  2562. }
  2563. }
  2564. lredata->auxiliary.length_valid = 1;
  2565. lredata->auxiliary.length_scope = 1;
  2566. lredata->auxiliary.imbedded_ccw_valid = 1;
  2567. lredata->length = tlf;
  2568. lredata->imbedded_ccw = cmd;
  2569. lredata->count = count;
  2570. lredata->sector = sector;
  2571. set_ch_t(&lredata->seek_addr, begcyl, beghead);
  2572. lredata->search_arg.cyl = lredata->seek_addr.cyl;
  2573. lredata->search_arg.head = lredata->seek_addr.head;
  2574. lredata->search_arg.record = rec_on_trk;
  2575. dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
  2576. &pfxdata, sizeof(pfxdata), total_data_size);
  2577. return IS_ERR(dcw) ? PTR_ERR(dcw) : 0;
  2578. }
  2579. static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
  2580. struct dasd_device *startdev,
  2581. struct dasd_block *block,
  2582. struct request *req,
  2583. sector_t first_rec,
  2584. sector_t last_rec,
  2585. sector_t first_trk,
  2586. sector_t last_trk,
  2587. unsigned int first_offs,
  2588. unsigned int last_offs,
  2589. unsigned int blk_per_trk,
  2590. unsigned int blksize)
  2591. {
  2592. struct dasd_ccw_req *cqr;
  2593. struct req_iterator iter;
  2594. struct bio_vec *bv;
  2595. char *dst;
  2596. unsigned int trkcount, ctidaw;
  2597. unsigned char cmd;
  2598. struct dasd_device *basedev;
  2599. unsigned int tlf;
  2600. struct itcw *itcw;
  2601. struct tidaw *last_tidaw = NULL;
  2602. int itcw_op;
  2603. size_t itcw_size;
  2604. u8 tidaw_flags;
  2605. unsigned int seg_len, part_len, len_to_track_end;
  2606. unsigned char new_track;
  2607. sector_t recid, trkid;
  2608. unsigned int offs;
  2609. unsigned int count, count_to_trk_end;
  2610. int ret;
  2611. basedev = block->base;
  2612. if (rq_data_dir(req) == READ) {
  2613. cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
  2614. itcw_op = ITCW_OP_READ;
  2615. } else if (rq_data_dir(req) == WRITE) {
  2616. cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
  2617. itcw_op = ITCW_OP_WRITE;
  2618. } else
  2619. return ERR_PTR(-EINVAL);
  2620. /* trackbased I/O needs address all memory via TIDAWs,
  2621. * not just for 64 bit addresses. This allows us to map
  2622. * each segment directly to one tidaw.
  2623. * In the case of write requests, additional tidaws may
  2624. * be needed when a segment crosses a track boundary.
  2625. */
  2626. trkcount = last_trk - first_trk + 1;
  2627. ctidaw = 0;
  2628. rq_for_each_segment(bv, req, iter) {
  2629. ++ctidaw;
  2630. }
  2631. if (rq_data_dir(req) == WRITE)
  2632. ctidaw += (last_trk - first_trk);
  2633. /* Allocate the ccw request. */
  2634. itcw_size = itcw_calc_size(0, ctidaw, 0);
  2635. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
  2636. if (IS_ERR(cqr))
  2637. return cqr;
  2638. /* transfer length factor: how many bytes to read from the last track */
  2639. if (first_trk == last_trk)
  2640. tlf = last_offs - first_offs + 1;
  2641. else
  2642. tlf = last_offs + 1;
  2643. tlf *= blksize;
  2644. itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
  2645. if (IS_ERR(itcw)) {
  2646. ret = -EINVAL;
  2647. goto out_error;
  2648. }
  2649. cqr->cpaddr = itcw_get_tcw(itcw);
  2650. if (prepare_itcw(itcw, first_trk, last_trk,
  2651. cmd, basedev, startdev,
  2652. first_offs + 1,
  2653. trkcount, blksize,
  2654. (last_rec - first_rec + 1) * blksize,
  2655. tlf, blk_per_trk) == -EAGAIN) {
  2656. /* Clock not in sync and XRC is enabled.
  2657. * Try again later.
  2658. */
  2659. ret = -EAGAIN;
  2660. goto out_error;
  2661. }
  2662. len_to_track_end = 0;
  2663. /*
  2664. * A tidaw can address 4k of memory, but must not cross page boundaries
  2665. * We can let the block layer handle this by setting
  2666. * blk_queue_segment_boundary to page boundaries and
  2667. * blk_max_segment_size to page size when setting up the request queue.
  2668. * For write requests, a TIDAW must not cross track boundaries, because
  2669. * we have to set the CBC flag on the last tidaw for each track.
  2670. */
  2671. if (rq_data_dir(req) == WRITE) {
  2672. new_track = 1;
  2673. recid = first_rec;
  2674. rq_for_each_segment(bv, req, iter) {
  2675. dst = page_address(bv->bv_page) + bv->bv_offset;
  2676. seg_len = bv->bv_len;
  2677. while (seg_len) {
  2678. if (new_track) {
  2679. trkid = recid;
  2680. offs = sector_div(trkid, blk_per_trk);
  2681. count_to_trk_end = blk_per_trk - offs;
  2682. count = min((last_rec - recid + 1),
  2683. (sector_t)count_to_trk_end);
  2684. len_to_track_end = count * blksize;
  2685. recid += count;
  2686. new_track = 0;
  2687. }
  2688. part_len = min(seg_len, len_to_track_end);
  2689. seg_len -= part_len;
  2690. len_to_track_end -= part_len;
  2691. /* We need to end the tidaw at track end */
  2692. if (!len_to_track_end) {
  2693. new_track = 1;
  2694. tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
  2695. } else
  2696. tidaw_flags = 0;
  2697. last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
  2698. dst, part_len);
  2699. if (IS_ERR(last_tidaw)) {
  2700. ret = -EINVAL;
  2701. goto out_error;
  2702. }
  2703. dst += part_len;
  2704. }
  2705. }
  2706. } else {
  2707. rq_for_each_segment(bv, req, iter) {
  2708. dst = page_address(bv->bv_page) + bv->bv_offset;
  2709. last_tidaw = itcw_add_tidaw(itcw, 0x00,
  2710. dst, bv->bv_len);
  2711. if (IS_ERR(last_tidaw)) {
  2712. ret = -EINVAL;
  2713. goto out_error;
  2714. }
  2715. }
  2716. }
  2717. last_tidaw->flags |= TIDAW_FLAGS_LAST;
  2718. last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
  2719. itcw_finalize(itcw);
  2720. if (blk_noretry_request(req) ||
  2721. block->base->features & DASD_FEATURE_FAILFAST)
  2722. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2723. cqr->cpmode = 1;
  2724. cqr->startdev = startdev;
  2725. cqr->memdev = startdev;
  2726. cqr->block = block;
  2727. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  2728. cqr->lpm = startdev->path_data.ppm;
  2729. cqr->retries = 256;
  2730. cqr->buildclk = get_clock();
  2731. cqr->status = DASD_CQR_FILLED;
  2732. return cqr;
  2733. out_error:
  2734. dasd_sfree_request(cqr, startdev);
  2735. return ERR_PTR(ret);
  2736. }
  2737. static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
  2738. struct dasd_block *block,
  2739. struct request *req)
  2740. {
  2741. int cmdrtd, cmdwtd;
  2742. int use_prefix;
  2743. int fcx_multitrack;
  2744. struct dasd_eckd_private *private;
  2745. struct dasd_device *basedev;
  2746. sector_t first_rec, last_rec;
  2747. sector_t first_trk, last_trk;
  2748. unsigned int first_offs, last_offs;
  2749. unsigned int blk_per_trk, blksize;
  2750. int cdlspecial;
  2751. unsigned int data_size;
  2752. struct dasd_ccw_req *cqr;
  2753. basedev = block->base;
  2754. private = (struct dasd_eckd_private *) basedev->private;
  2755. /* Calculate number of blocks/records per track. */
  2756. blksize = block->bp_block;
  2757. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  2758. if (blk_per_trk == 0)
  2759. return ERR_PTR(-EINVAL);
  2760. /* Calculate record id of first and last block. */
  2761. first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
  2762. first_offs = sector_div(first_trk, blk_per_trk);
  2763. last_rec = last_trk =
  2764. (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
  2765. last_offs = sector_div(last_trk, blk_per_trk);
  2766. cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
  2767. fcx_multitrack = private->features.feature[40] & 0x20;
  2768. data_size = blk_rq_bytes(req);
  2769. /* tpm write request add CBC data on each track boundary */
  2770. if (rq_data_dir(req) == WRITE)
  2771. data_size += (last_trk - first_trk) * 4;
  2772. /* is read track data and write track data in command mode supported? */
  2773. cmdrtd = private->features.feature[9] & 0x20;
  2774. cmdwtd = private->features.feature[12] & 0x40;
  2775. use_prefix = private->features.feature[8] & 0x01;
  2776. cqr = NULL;
  2777. if (cdlspecial || dasd_page_cache) {
  2778. /* do nothing, just fall through to the cmd mode single case */
  2779. } else if ((data_size <= private->fcx_max_data)
  2780. && (fcx_multitrack || (first_trk == last_trk))) {
  2781. cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
  2782. first_rec, last_rec,
  2783. first_trk, last_trk,
  2784. first_offs, last_offs,
  2785. blk_per_trk, blksize);
  2786. if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
  2787. (PTR_ERR(cqr) != -ENOMEM))
  2788. cqr = NULL;
  2789. } else if (use_prefix &&
  2790. (((rq_data_dir(req) == READ) && cmdrtd) ||
  2791. ((rq_data_dir(req) == WRITE) && cmdwtd))) {
  2792. cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
  2793. first_rec, last_rec,
  2794. first_trk, last_trk,
  2795. first_offs, last_offs,
  2796. blk_per_trk, blksize);
  2797. if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
  2798. (PTR_ERR(cqr) != -ENOMEM))
  2799. cqr = NULL;
  2800. }
  2801. if (!cqr)
  2802. cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
  2803. first_rec, last_rec,
  2804. first_trk, last_trk,
  2805. first_offs, last_offs,
  2806. blk_per_trk, blksize);
  2807. return cqr;
  2808. }
  2809. static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
  2810. struct dasd_block *block,
  2811. struct request *req)
  2812. {
  2813. unsigned long *idaws;
  2814. struct dasd_device *basedev;
  2815. struct dasd_ccw_req *cqr;
  2816. struct ccw1 *ccw;
  2817. struct req_iterator iter;
  2818. struct bio_vec *bv;
  2819. char *dst;
  2820. unsigned char cmd;
  2821. unsigned int trkcount;
  2822. unsigned int seg_len, len_to_track_end;
  2823. unsigned int first_offs;
  2824. unsigned int cidaw, cplength, datasize;
  2825. sector_t first_trk, last_trk;
  2826. unsigned int pfx_datasize;
  2827. /*
  2828. * raw track access needs to be mutiple of 64k and on 64k boundary
  2829. */
  2830. if ((blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK) != 0) {
  2831. cqr = ERR_PTR(-EINVAL);
  2832. goto out;
  2833. }
  2834. if (((blk_rq_pos(req) + blk_rq_sectors(req)) %
  2835. DASD_RAW_SECTORS_PER_TRACK) != 0) {
  2836. cqr = ERR_PTR(-EINVAL);
  2837. goto out;
  2838. }
  2839. first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
  2840. last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
  2841. DASD_RAW_SECTORS_PER_TRACK;
  2842. trkcount = last_trk - first_trk + 1;
  2843. first_offs = 0;
  2844. basedev = block->base;
  2845. if (rq_data_dir(req) == READ)
  2846. cmd = DASD_ECKD_CCW_READ_TRACK;
  2847. else if (rq_data_dir(req) == WRITE)
  2848. cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
  2849. else {
  2850. cqr = ERR_PTR(-EINVAL);
  2851. goto out;
  2852. }
  2853. /*
  2854. * Raw track based I/O needs IDAWs for each page,
  2855. * and not just for 64 bit addresses.
  2856. */
  2857. cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
  2858. /* 1x prefix + one read/write ccw per track */
  2859. cplength = 1 + trkcount;
  2860. /*
  2861. * struct PFX_eckd_data has up to 2 byte as extended parameter
  2862. * this is needed for write full track and has to be mentioned
  2863. * separately
  2864. * add 8 instead of 2 to keep 8 byte boundary
  2865. */
  2866. pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
  2867. datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
  2868. /* Allocate the ccw request. */
  2869. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
  2870. datasize, startdev);
  2871. if (IS_ERR(cqr))
  2872. goto out;
  2873. ccw = cqr->cpaddr;
  2874. if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
  2875. basedev, startdev, 1 /* format */, first_offs + 1,
  2876. trkcount, 0, 0) == -EAGAIN) {
  2877. /* Clock not in sync and XRC is enabled.
  2878. * Try again later.
  2879. */
  2880. dasd_sfree_request(cqr, startdev);
  2881. cqr = ERR_PTR(-EAGAIN);
  2882. goto out;
  2883. }
  2884. idaws = (unsigned long *)(cqr->data + pfx_datasize);
  2885. len_to_track_end = 0;
  2886. rq_for_each_segment(bv, req, iter) {
  2887. dst = page_address(bv->bv_page) + bv->bv_offset;
  2888. seg_len = bv->bv_len;
  2889. if (!len_to_track_end) {
  2890. ccw[-1].flags |= CCW_FLAG_CC;
  2891. ccw->cmd_code = cmd;
  2892. /* maximum 3390 track size */
  2893. ccw->count = 57326;
  2894. /* 64k map to one track */
  2895. len_to_track_end = 65536;
  2896. ccw->cda = (__u32)(addr_t)idaws;
  2897. ccw->flags |= CCW_FLAG_IDA;
  2898. ccw->flags |= CCW_FLAG_SLI;
  2899. ccw++;
  2900. }
  2901. len_to_track_end -= seg_len;
  2902. idaws = idal_create_words(idaws, dst, seg_len);
  2903. }
  2904. if (blk_noretry_request(req) ||
  2905. block->base->features & DASD_FEATURE_FAILFAST)
  2906. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2907. cqr->startdev = startdev;
  2908. cqr->memdev = startdev;
  2909. cqr->block = block;
  2910. cqr->expires = startdev->default_expires * HZ;
  2911. cqr->lpm = startdev->path_data.ppm;
  2912. cqr->retries = 256;
  2913. cqr->buildclk = get_clock();
  2914. cqr->status = DASD_CQR_FILLED;
  2915. if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
  2916. cqr = NULL;
  2917. out:
  2918. return cqr;
  2919. }
  2920. static int
  2921. dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
  2922. {
  2923. struct dasd_eckd_private *private;
  2924. struct ccw1 *ccw;
  2925. struct req_iterator iter;
  2926. struct bio_vec *bv;
  2927. char *dst, *cda;
  2928. unsigned int blksize, blk_per_trk, off;
  2929. sector_t recid;
  2930. int status;
  2931. if (!dasd_page_cache)
  2932. goto out;
  2933. private = (struct dasd_eckd_private *) cqr->block->base->private;
  2934. blksize = cqr->block->bp_block;
  2935. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  2936. recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
  2937. ccw = cqr->cpaddr;
  2938. /* Skip over define extent & locate record. */
  2939. ccw++;
  2940. if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
  2941. ccw++;
  2942. rq_for_each_segment(bv, req, iter) {
  2943. dst = page_address(bv->bv_page) + bv->bv_offset;
  2944. for (off = 0; off < bv->bv_len; off += blksize) {
  2945. /* Skip locate record. */
  2946. if (private->uses_cdl && recid <= 2*blk_per_trk)
  2947. ccw++;
  2948. if (dst) {
  2949. if (ccw->flags & CCW_FLAG_IDA)
  2950. cda = *((char **)((addr_t) ccw->cda));
  2951. else
  2952. cda = (char *)((addr_t) ccw->cda);
  2953. if (dst != cda) {
  2954. if (rq_data_dir(req) == READ)
  2955. memcpy(dst, cda, bv->bv_len);
  2956. kmem_cache_free(dasd_page_cache,
  2957. (void *)((addr_t)cda & PAGE_MASK));
  2958. }
  2959. dst = NULL;
  2960. }
  2961. ccw++;
  2962. recid++;
  2963. }
  2964. }
  2965. out:
  2966. status = cqr->status == DASD_CQR_DONE;
  2967. dasd_sfree_request(cqr, cqr->memdev);
  2968. return status;
  2969. }
  2970. /*
  2971. * Modify ccw/tcw in cqr so it can be started on a base device.
  2972. *
  2973. * Note that this is not enough to restart the cqr!
  2974. * Either reset cqr->startdev as well (summary unit check handling)
  2975. * or restart via separate cqr (as in ERP handling).
  2976. */
  2977. void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
  2978. {
  2979. struct ccw1 *ccw;
  2980. struct PFX_eckd_data *pfxdata;
  2981. struct tcw *tcw;
  2982. struct tccb *tccb;
  2983. struct dcw *dcw;
  2984. if (cqr->cpmode == 1) {
  2985. tcw = cqr->cpaddr;
  2986. tccb = tcw_get_tccb(tcw);
  2987. dcw = (struct dcw *)&tccb->tca[0];
  2988. pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
  2989. pfxdata->validity.verify_base = 0;
  2990. pfxdata->validity.hyper_pav = 0;
  2991. } else {
  2992. ccw = cqr->cpaddr;
  2993. pfxdata = cqr->data;
  2994. if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
  2995. pfxdata->validity.verify_base = 0;
  2996. pfxdata->validity.hyper_pav = 0;
  2997. }
  2998. }
  2999. }
  3000. #define DASD_ECKD_CHANQ_MAX_SIZE 4
  3001. static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
  3002. struct dasd_block *block,
  3003. struct request *req)
  3004. {
  3005. struct dasd_eckd_private *private;
  3006. struct dasd_device *startdev;
  3007. unsigned long flags;
  3008. struct dasd_ccw_req *cqr;
  3009. startdev = dasd_alias_get_start_dev(base);
  3010. if (!startdev)
  3011. startdev = base;
  3012. private = (struct dasd_eckd_private *) startdev->private;
  3013. if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
  3014. return ERR_PTR(-EBUSY);
  3015. spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
  3016. private->count++;
  3017. if ((base->features & DASD_FEATURE_USERAW))
  3018. cqr = dasd_raw_build_cp(startdev, block, req);
  3019. else
  3020. cqr = dasd_eckd_build_cp(startdev, block, req);
  3021. if (IS_ERR(cqr))
  3022. private->count--;
  3023. spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
  3024. return cqr;
  3025. }
  3026. static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
  3027. struct request *req)
  3028. {
  3029. struct dasd_eckd_private *private;
  3030. unsigned long flags;
  3031. spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
  3032. private = (struct dasd_eckd_private *) cqr->memdev->private;
  3033. private->count--;
  3034. spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
  3035. return dasd_eckd_free_cp(cqr, req);
  3036. }
  3037. static int
  3038. dasd_eckd_fill_info(struct dasd_device * device,
  3039. struct dasd_information2_t * info)
  3040. {
  3041. struct dasd_eckd_private *private;
  3042. private = (struct dasd_eckd_private *) device->private;
  3043. info->label_block = 2;
  3044. info->FBA_layout = private->uses_cdl ? 0 : 1;
  3045. info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
  3046. info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
  3047. memcpy(info->characteristics, &private->rdc_data,
  3048. sizeof(struct dasd_eckd_characteristics));
  3049. info->confdata_size = min((unsigned long)private->conf_len,
  3050. sizeof(info->configuration_data));
  3051. memcpy(info->configuration_data, private->conf_data,
  3052. info->confdata_size);
  3053. return 0;
  3054. }
  3055. /*
  3056. * SECTION: ioctl functions for eckd devices.
  3057. */
  3058. /*
  3059. * Release device ioctl.
  3060. * Buils a channel programm to releases a prior reserved
  3061. * (see dasd_eckd_reserve) device.
  3062. */
  3063. static int
  3064. dasd_eckd_release(struct dasd_device *device)
  3065. {
  3066. struct dasd_ccw_req *cqr;
  3067. int rc;
  3068. struct ccw1 *ccw;
  3069. int useglobal;
  3070. if (!capable(CAP_SYS_ADMIN))
  3071. return -EACCES;
  3072. useglobal = 0;
  3073. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3074. if (IS_ERR(cqr)) {
  3075. mutex_lock(&dasd_reserve_mutex);
  3076. useglobal = 1;
  3077. cqr = &dasd_reserve_req->cqr;
  3078. memset(cqr, 0, sizeof(*cqr));
  3079. memset(&dasd_reserve_req->ccw, 0,
  3080. sizeof(dasd_reserve_req->ccw));
  3081. cqr->cpaddr = &dasd_reserve_req->ccw;
  3082. cqr->data = &dasd_reserve_req->data;
  3083. cqr->magic = DASD_ECKD_MAGIC;
  3084. }
  3085. ccw = cqr->cpaddr;
  3086. ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
  3087. ccw->flags |= CCW_FLAG_SLI;
  3088. ccw->count = 32;
  3089. ccw->cda = (__u32)(addr_t) cqr->data;
  3090. cqr->startdev = device;
  3091. cqr->memdev = device;
  3092. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3093. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3094. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3095. cqr->expires = 2 * HZ;
  3096. cqr->buildclk = get_clock();
  3097. cqr->status = DASD_CQR_FILLED;
  3098. rc = dasd_sleep_on_immediatly(cqr);
  3099. if (!rc)
  3100. clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3101. if (useglobal)
  3102. mutex_unlock(&dasd_reserve_mutex);
  3103. else
  3104. dasd_sfree_request(cqr, cqr->memdev);
  3105. return rc;
  3106. }
  3107. /*
  3108. * Reserve device ioctl.
  3109. * Options are set to 'synchronous wait for interrupt' and
  3110. * 'timeout the request'. This leads to a terminate IO if
  3111. * the interrupt is outstanding for a certain time.
  3112. */
  3113. static int
  3114. dasd_eckd_reserve(struct dasd_device *device)
  3115. {
  3116. struct dasd_ccw_req *cqr;
  3117. int rc;
  3118. struct ccw1 *ccw;
  3119. int useglobal;
  3120. if (!capable(CAP_SYS_ADMIN))
  3121. return -EACCES;
  3122. useglobal = 0;
  3123. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3124. if (IS_ERR(cqr)) {
  3125. mutex_lock(&dasd_reserve_mutex);
  3126. useglobal = 1;
  3127. cqr = &dasd_reserve_req->cqr;
  3128. memset(cqr, 0, sizeof(*cqr));
  3129. memset(&dasd_reserve_req->ccw, 0,
  3130. sizeof(dasd_reserve_req->ccw));
  3131. cqr->cpaddr = &dasd_reserve_req->ccw;
  3132. cqr->data = &dasd_reserve_req->data;
  3133. cqr->magic = DASD_ECKD_MAGIC;
  3134. }
  3135. ccw = cqr->cpaddr;
  3136. ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
  3137. ccw->flags |= CCW_FLAG_SLI;
  3138. ccw->count = 32;
  3139. ccw->cda = (__u32)(addr_t) cqr->data;
  3140. cqr->startdev = device;
  3141. cqr->memdev = device;
  3142. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3143. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3144. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3145. cqr->expires = 2 * HZ;
  3146. cqr->buildclk = get_clock();
  3147. cqr->status = DASD_CQR_FILLED;
  3148. rc = dasd_sleep_on_immediatly(cqr);
  3149. if (!rc)
  3150. set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3151. if (useglobal)
  3152. mutex_unlock(&dasd_reserve_mutex);
  3153. else
  3154. dasd_sfree_request(cqr, cqr->memdev);
  3155. return rc;
  3156. }
  3157. /*
  3158. * Steal lock ioctl - unconditional reserve device.
  3159. * Buils a channel programm to break a device's reservation.
  3160. * (unconditional reserve)
  3161. */
  3162. static int
  3163. dasd_eckd_steal_lock(struct dasd_device *device)
  3164. {
  3165. struct dasd_ccw_req *cqr;
  3166. int rc;
  3167. struct ccw1 *ccw;
  3168. int useglobal;
  3169. if (!capable(CAP_SYS_ADMIN))
  3170. return -EACCES;
  3171. useglobal = 0;
  3172. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3173. if (IS_ERR(cqr)) {
  3174. mutex_lock(&dasd_reserve_mutex);
  3175. useglobal = 1;
  3176. cqr = &dasd_reserve_req->cqr;
  3177. memset(cqr, 0, sizeof(*cqr));
  3178. memset(&dasd_reserve_req->ccw, 0,
  3179. sizeof(dasd_reserve_req->ccw));
  3180. cqr->cpaddr = &dasd_reserve_req->ccw;
  3181. cqr->data = &dasd_reserve_req->data;
  3182. cqr->magic = DASD_ECKD_MAGIC;
  3183. }
  3184. ccw = cqr->cpaddr;
  3185. ccw->cmd_code = DASD_ECKD_CCW_SLCK;
  3186. ccw->flags |= CCW_FLAG_SLI;
  3187. ccw->count = 32;
  3188. ccw->cda = (__u32)(addr_t) cqr->data;
  3189. cqr->startdev = device;
  3190. cqr->memdev = device;
  3191. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3192. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3193. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3194. cqr->expires = 2 * HZ;
  3195. cqr->buildclk = get_clock();
  3196. cqr->status = DASD_CQR_FILLED;
  3197. rc = dasd_sleep_on_immediatly(cqr);
  3198. if (!rc)
  3199. set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3200. if (useglobal)
  3201. mutex_unlock(&dasd_reserve_mutex);
  3202. else
  3203. dasd_sfree_request(cqr, cqr->memdev);
  3204. return rc;
  3205. }
  3206. /*
  3207. * SNID - Sense Path Group ID
  3208. * This ioctl may be used in situations where I/O is stalled due to
  3209. * a reserve, so if the normal dasd_smalloc_request fails, we use the
  3210. * preallocated dasd_reserve_req.
  3211. */
  3212. static int dasd_eckd_snid(struct dasd_device *device,
  3213. void __user *argp)
  3214. {
  3215. struct dasd_ccw_req *cqr;
  3216. int rc;
  3217. struct ccw1 *ccw;
  3218. int useglobal;
  3219. struct dasd_snid_ioctl_data usrparm;
  3220. if (!capable(CAP_SYS_ADMIN))
  3221. return -EACCES;
  3222. if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
  3223. return -EFAULT;
  3224. useglobal = 0;
  3225. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
  3226. sizeof(struct dasd_snid_data), device);
  3227. if (IS_ERR(cqr)) {
  3228. mutex_lock(&dasd_reserve_mutex);
  3229. useglobal = 1;
  3230. cqr = &dasd_reserve_req->cqr;
  3231. memset(cqr, 0, sizeof(*cqr));
  3232. memset(&dasd_reserve_req->ccw, 0,
  3233. sizeof(dasd_reserve_req->ccw));
  3234. cqr->cpaddr = &dasd_reserve_req->ccw;
  3235. cqr->data = &dasd_reserve_req->data;
  3236. cqr->magic = DASD_ECKD_MAGIC;
  3237. }
  3238. ccw = cqr->cpaddr;
  3239. ccw->cmd_code = DASD_ECKD_CCW_SNID;
  3240. ccw->flags |= CCW_FLAG_SLI;
  3241. ccw->count = 12;
  3242. ccw->cda = (__u32)(addr_t) cqr->data;
  3243. cqr->startdev = device;
  3244. cqr->memdev = device;
  3245. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3246. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3247. set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
  3248. cqr->retries = 5;
  3249. cqr->expires = 10 * HZ;
  3250. cqr->buildclk = get_clock();
  3251. cqr->status = DASD_CQR_FILLED;
  3252. cqr->lpm = usrparm.path_mask;
  3253. rc = dasd_sleep_on_immediatly(cqr);
  3254. /* verify that I/O processing didn't modify the path mask */
  3255. if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
  3256. rc = -EIO;
  3257. if (!rc) {
  3258. usrparm.data = *((struct dasd_snid_data *)cqr->data);
  3259. if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
  3260. rc = -EFAULT;
  3261. }
  3262. if (useglobal)
  3263. mutex_unlock(&dasd_reserve_mutex);
  3264. else
  3265. dasd_sfree_request(cqr, cqr->memdev);
  3266. return rc;
  3267. }
  3268. /*
  3269. * Read performance statistics
  3270. */
  3271. static int
  3272. dasd_eckd_performance(struct dasd_device *device, void __user *argp)
  3273. {
  3274. struct dasd_psf_prssd_data *prssdp;
  3275. struct dasd_rssd_perf_stats_t *stats;
  3276. struct dasd_ccw_req *cqr;
  3277. struct ccw1 *ccw;
  3278. int rc;
  3279. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  3280. (sizeof(struct dasd_psf_prssd_data) +
  3281. sizeof(struct dasd_rssd_perf_stats_t)),
  3282. device);
  3283. if (IS_ERR(cqr)) {
  3284. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3285. "Could not allocate initialization request");
  3286. return PTR_ERR(cqr);
  3287. }
  3288. cqr->startdev = device;
  3289. cqr->memdev = device;
  3290. cqr->retries = 0;
  3291. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3292. cqr->expires = 10 * HZ;
  3293. /* Prepare for Read Subsystem Data */
  3294. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  3295. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  3296. prssdp->order = PSF_ORDER_PRSSD;
  3297. prssdp->suborder = 0x01; /* Performance Statistics */
  3298. prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
  3299. ccw = cqr->cpaddr;
  3300. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  3301. ccw->count = sizeof(struct dasd_psf_prssd_data);
  3302. ccw->flags |= CCW_FLAG_CC;
  3303. ccw->cda = (__u32)(addr_t) prssdp;
  3304. /* Read Subsystem Data - Performance Statistics */
  3305. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  3306. memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
  3307. ccw++;
  3308. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  3309. ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
  3310. ccw->cda = (__u32)(addr_t) stats;
  3311. cqr->buildclk = get_clock();
  3312. cqr->status = DASD_CQR_FILLED;
  3313. rc = dasd_sleep_on(cqr);
  3314. if (rc == 0) {
  3315. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  3316. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  3317. if (copy_to_user(argp, stats,
  3318. sizeof(struct dasd_rssd_perf_stats_t)))
  3319. rc = -EFAULT;
  3320. }
  3321. dasd_sfree_request(cqr, cqr->memdev);
  3322. return rc;
  3323. }
  3324. /*
  3325. * Get attributes (cache operations)
  3326. * Returnes the cache attributes used in Define Extend (DE).
  3327. */
  3328. static int
  3329. dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
  3330. {
  3331. struct dasd_eckd_private *private =
  3332. (struct dasd_eckd_private *)device->private;
  3333. struct attrib_data_t attrib = private->attrib;
  3334. int rc;
  3335. if (!capable(CAP_SYS_ADMIN))
  3336. return -EACCES;
  3337. if (!argp)
  3338. return -EINVAL;
  3339. rc = 0;
  3340. if (copy_to_user(argp, (long *) &attrib,
  3341. sizeof(struct attrib_data_t)))
  3342. rc = -EFAULT;
  3343. return rc;
  3344. }
  3345. /*
  3346. * Set attributes (cache operations)
  3347. * Stores the attributes for cache operation to be used in Define Extend (DE).
  3348. */
  3349. static int
  3350. dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
  3351. {
  3352. struct dasd_eckd_private *private =
  3353. (struct dasd_eckd_private *)device->private;
  3354. struct attrib_data_t attrib;
  3355. if (!capable(CAP_SYS_ADMIN))
  3356. return -EACCES;
  3357. if (!argp)
  3358. return -EINVAL;
  3359. if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
  3360. return -EFAULT;
  3361. private->attrib = attrib;
  3362. dev_info(&device->cdev->dev,
  3363. "The DASD cache mode was set to %x (%i cylinder prestage)\n",
  3364. private->attrib.operation, private->attrib.nr_cyl);
  3365. return 0;
  3366. }
  3367. /*
  3368. * Issue syscall I/O to EMC Symmetrix array.
  3369. * CCWs are PSF and RSSD
  3370. */
  3371. static int dasd_symm_io(struct dasd_device *device, void __user *argp)
  3372. {
  3373. struct dasd_symmio_parms usrparm;
  3374. char *psf_data, *rssd_result;
  3375. struct dasd_ccw_req *cqr;
  3376. struct ccw1 *ccw;
  3377. char psf0, psf1;
  3378. int rc;
  3379. if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
  3380. return -EACCES;
  3381. psf0 = psf1 = 0;
  3382. /* Copy parms from caller */
  3383. rc = -EFAULT;
  3384. if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
  3385. goto out;
  3386. if (is_compat_task() || sizeof(long) == 4) {
  3387. /* Make sure pointers are sane even on 31 bit. */
  3388. rc = -EINVAL;
  3389. if ((usrparm.psf_data >> 32) != 0)
  3390. goto out;
  3391. if ((usrparm.rssd_result >> 32) != 0)
  3392. goto out;
  3393. usrparm.psf_data &= 0x7fffffffULL;
  3394. usrparm.rssd_result &= 0x7fffffffULL;
  3395. }
  3396. /* alloc I/O data area */
  3397. psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
  3398. rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
  3399. if (!psf_data || !rssd_result) {
  3400. rc = -ENOMEM;
  3401. goto out_free;
  3402. }
  3403. /* get syscall header from user space */
  3404. rc = -EFAULT;
  3405. if (copy_from_user(psf_data,
  3406. (void __user *)(unsigned long) usrparm.psf_data,
  3407. usrparm.psf_data_len))
  3408. goto out_free;
  3409. psf0 = psf_data[0];
  3410. psf1 = psf_data[1];
  3411. /* setup CCWs for PSF + RSSD */
  3412. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
  3413. if (IS_ERR(cqr)) {
  3414. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3415. "Could not allocate initialization request");
  3416. rc = PTR_ERR(cqr);
  3417. goto out_free;
  3418. }
  3419. cqr->startdev = device;
  3420. cqr->memdev = device;
  3421. cqr->retries = 3;
  3422. cqr->expires = 10 * HZ;
  3423. cqr->buildclk = get_clock();
  3424. cqr->status = DASD_CQR_FILLED;
  3425. /* Build the ccws */
  3426. ccw = cqr->cpaddr;
  3427. /* PSF ccw */
  3428. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  3429. ccw->count = usrparm.psf_data_len;
  3430. ccw->flags |= CCW_FLAG_CC;
  3431. ccw->cda = (__u32)(addr_t) psf_data;
  3432. ccw++;
  3433. /* RSSD ccw */
  3434. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  3435. ccw->count = usrparm.rssd_result_len;
  3436. ccw->flags = CCW_FLAG_SLI ;
  3437. ccw->cda = (__u32)(addr_t) rssd_result;
  3438. rc = dasd_sleep_on(cqr);
  3439. if (rc)
  3440. goto out_sfree;
  3441. rc = -EFAULT;
  3442. if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
  3443. rssd_result, usrparm.rssd_result_len))
  3444. goto out_sfree;
  3445. rc = 0;
  3446. out_sfree:
  3447. dasd_sfree_request(cqr, cqr->memdev);
  3448. out_free:
  3449. kfree(rssd_result);
  3450. kfree(psf_data);
  3451. out:
  3452. DBF_DEV_EVENT(DBF_WARNING, device,
  3453. "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
  3454. (int) psf0, (int) psf1, rc);
  3455. return rc;
  3456. }
  3457. static int
  3458. dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
  3459. {
  3460. struct dasd_device *device = block->base;
  3461. switch (cmd) {
  3462. case BIODASDGATTR:
  3463. return dasd_eckd_get_attrib(device, argp);
  3464. case BIODASDSATTR:
  3465. return dasd_eckd_set_attrib(device, argp);
  3466. case BIODASDPSRD:
  3467. return dasd_eckd_performance(device, argp);
  3468. case BIODASDRLSE:
  3469. return dasd_eckd_release(device);
  3470. case BIODASDRSRV:
  3471. return dasd_eckd_reserve(device);
  3472. case BIODASDSLCK:
  3473. return dasd_eckd_steal_lock(device);
  3474. case BIODASDSNID:
  3475. return dasd_eckd_snid(device, argp);
  3476. case BIODASDSYMMIO:
  3477. return dasd_symm_io(device, argp);
  3478. default:
  3479. return -ENOIOCTLCMD;
  3480. }
  3481. }
  3482. /*
  3483. * Dump the range of CCWs into 'page' buffer
  3484. * and return number of printed chars.
  3485. */
  3486. static int
  3487. dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
  3488. {
  3489. int len, count;
  3490. char *datap;
  3491. len = 0;
  3492. while (from <= to) {
  3493. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3494. " CCW %p: %08X %08X DAT:",
  3495. from, ((int *) from)[0], ((int *) from)[1]);
  3496. /* get pointer to data (consider IDALs) */
  3497. if (from->flags & CCW_FLAG_IDA)
  3498. datap = (char *) *((addr_t *) (addr_t) from->cda);
  3499. else
  3500. datap = (char *) ((addr_t) from->cda);
  3501. /* dump data (max 32 bytes) */
  3502. for (count = 0; count < from->count && count < 32; count++) {
  3503. if (count % 8 == 0) len += sprintf(page + len, " ");
  3504. if (count % 4 == 0) len += sprintf(page + len, " ");
  3505. len += sprintf(page + len, "%02x", datap[count]);
  3506. }
  3507. len += sprintf(page + len, "\n");
  3508. from++;
  3509. }
  3510. return len;
  3511. }
  3512. static void
  3513. dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
  3514. char *reason)
  3515. {
  3516. u64 *sense;
  3517. u64 *stat;
  3518. sense = (u64 *) dasd_get_sense(irb);
  3519. stat = (u64 *) &irb->scsw;
  3520. if (sense) {
  3521. DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
  3522. "%016llx %016llx %016llx %016llx",
  3523. reason, *stat, *((u32 *) (stat + 1)),
  3524. sense[0], sense[1], sense[2], sense[3]);
  3525. } else {
  3526. DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
  3527. reason, *stat, *((u32 *) (stat + 1)),
  3528. "NO VALID SENSE");
  3529. }
  3530. }
  3531. /*
  3532. * Print sense data and related channel program.
  3533. * Parts are printed because printk buffer is only 1024 bytes.
  3534. */
  3535. static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
  3536. struct dasd_ccw_req *req, struct irb *irb)
  3537. {
  3538. char *page;
  3539. struct ccw1 *first, *last, *fail, *from, *to;
  3540. int len, sl, sct;
  3541. page = (char *) get_zeroed_page(GFP_ATOMIC);
  3542. if (page == NULL) {
  3543. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3544. "No memory to dump sense data\n");
  3545. return;
  3546. }
  3547. /* dump the sense data */
  3548. len = sprintf(page, KERN_ERR PRINTK_HEADER
  3549. " I/O status report for device %s:\n",
  3550. dev_name(&device->cdev->dev));
  3551. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3552. " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
  3553. "CS:%02X RC:%d\n",
  3554. req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
  3555. scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
  3556. scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
  3557. req ? req->intrc : 0);
  3558. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3559. " device %s: Failing CCW: %p\n",
  3560. dev_name(&device->cdev->dev),
  3561. (void *) (addr_t) irb->scsw.cmd.cpa);
  3562. if (irb->esw.esw0.erw.cons) {
  3563. for (sl = 0; sl < 4; sl++) {
  3564. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3565. " Sense(hex) %2d-%2d:",
  3566. (8 * sl), ((8 * sl) + 7));
  3567. for (sct = 0; sct < 8; sct++) {
  3568. len += sprintf(page + len, " %02x",
  3569. irb->ecw[8 * sl + sct]);
  3570. }
  3571. len += sprintf(page + len, "\n");
  3572. }
  3573. if (irb->ecw[27] & DASD_SENSE_BIT_0) {
  3574. /* 24 Byte Sense Data */
  3575. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3576. " 24 Byte: %x MSG %x, "
  3577. "%s MSGb to SYSOP\n",
  3578. irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
  3579. irb->ecw[1] & 0x10 ? "" : "no");
  3580. } else {
  3581. /* 32 Byte Sense Data */
  3582. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3583. " 32 Byte: Format: %x "
  3584. "Exception class %x\n",
  3585. irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
  3586. }
  3587. } else {
  3588. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3589. " SORRY - NO VALID SENSE AVAILABLE\n");
  3590. }
  3591. printk("%s", page);
  3592. if (req) {
  3593. /* req == NULL for unsolicited interrupts */
  3594. /* dump the Channel Program (max 140 Bytes per line) */
  3595. /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
  3596. first = req->cpaddr;
  3597. for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
  3598. to = min(first + 6, last);
  3599. len = sprintf(page, KERN_ERR PRINTK_HEADER
  3600. " Related CP in req: %p\n", req);
  3601. dasd_eckd_dump_ccw_range(first, to, page + len);
  3602. printk("%s", page);
  3603. /* print failing CCW area (maximum 4) */
  3604. /* scsw->cda is either valid or zero */
  3605. len = 0;
  3606. from = ++to;
  3607. fail = (struct ccw1 *)(addr_t)
  3608. irb->scsw.cmd.cpa; /* failing CCW */
  3609. if (from < fail - 2) {
  3610. from = fail - 2; /* there is a gap - print header */
  3611. len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
  3612. }
  3613. to = min(fail + 1, last);
  3614. len += dasd_eckd_dump_ccw_range(from, to, page + len);
  3615. /* print last CCWs (maximum 2) */
  3616. from = max(from, ++to);
  3617. if (from < last - 1) {
  3618. from = last - 1; /* there is a gap - print header */
  3619. len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
  3620. }
  3621. len += dasd_eckd_dump_ccw_range(from, last, page + len);
  3622. if (len > 0)
  3623. printk("%s", page);
  3624. }
  3625. free_page((unsigned long) page);
  3626. }
  3627. /*
  3628. * Print sense data from a tcw.
  3629. */
  3630. static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
  3631. struct dasd_ccw_req *req, struct irb *irb)
  3632. {
  3633. char *page;
  3634. int len, sl, sct, residual;
  3635. struct tsb *tsb;
  3636. u8 *sense, *rcq;
  3637. page = (char *) get_zeroed_page(GFP_ATOMIC);
  3638. if (page == NULL) {
  3639. DBF_DEV_EVENT(DBF_WARNING, device, " %s",
  3640. "No memory to dump sense data");
  3641. return;
  3642. }
  3643. /* dump the sense data */
  3644. len = sprintf(page, KERN_ERR PRINTK_HEADER
  3645. " I/O status report for device %s:\n",
  3646. dev_name(&device->cdev->dev));
  3647. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3648. " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
  3649. "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
  3650. req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
  3651. scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
  3652. scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
  3653. irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
  3654. req ? req->intrc : 0);
  3655. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3656. " device %s: Failing TCW: %p\n",
  3657. dev_name(&device->cdev->dev),
  3658. (void *) (addr_t) irb->scsw.tm.tcw);
  3659. tsb = NULL;
  3660. sense = NULL;
  3661. if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
  3662. tsb = tcw_get_tsb(
  3663. (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
  3664. if (tsb) {
  3665. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3666. " tsb->length %d\n", tsb->length);
  3667. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3668. " tsb->flags %x\n", tsb->flags);
  3669. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3670. " tsb->dcw_offset %d\n", tsb->dcw_offset);
  3671. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3672. " tsb->count %d\n", tsb->count);
  3673. residual = tsb->count - 28;
  3674. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3675. " residual %d\n", residual);
  3676. switch (tsb->flags & 0x07) {
  3677. case 1: /* tsa_iostat */
  3678. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3679. " tsb->tsa.iostat.dev_time %d\n",
  3680. tsb->tsa.iostat.dev_time);
  3681. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3682. " tsb->tsa.iostat.def_time %d\n",
  3683. tsb->tsa.iostat.def_time);
  3684. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3685. " tsb->tsa.iostat.queue_time %d\n",
  3686. tsb->tsa.iostat.queue_time);
  3687. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3688. " tsb->tsa.iostat.dev_busy_time %d\n",
  3689. tsb->tsa.iostat.dev_busy_time);
  3690. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3691. " tsb->tsa.iostat.dev_act_time %d\n",
  3692. tsb->tsa.iostat.dev_act_time);
  3693. sense = tsb->tsa.iostat.sense;
  3694. break;
  3695. case 2: /* ts_ddpc */
  3696. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3697. " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
  3698. for (sl = 0; sl < 2; sl++) {
  3699. len += sprintf(page + len,
  3700. KERN_ERR PRINTK_HEADER
  3701. " tsb->tsa.ddpc.rcq %2d-%2d: ",
  3702. (8 * sl), ((8 * sl) + 7));
  3703. rcq = tsb->tsa.ddpc.rcq;
  3704. for (sct = 0; sct < 8; sct++) {
  3705. len += sprintf(page + len, " %02x",
  3706. rcq[8 * sl + sct]);
  3707. }
  3708. len += sprintf(page + len, "\n");
  3709. }
  3710. sense = tsb->tsa.ddpc.sense;
  3711. break;
  3712. case 3: /* tsa_intrg */
  3713. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3714. " tsb->tsa.intrg.: not supportet yet \n");
  3715. break;
  3716. }
  3717. if (sense) {
  3718. for (sl = 0; sl < 4; sl++) {
  3719. len += sprintf(page + len,
  3720. KERN_ERR PRINTK_HEADER
  3721. " Sense(hex) %2d-%2d:",
  3722. (8 * sl), ((8 * sl) + 7));
  3723. for (sct = 0; sct < 8; sct++) {
  3724. len += sprintf(page + len, " %02x",
  3725. sense[8 * sl + sct]);
  3726. }
  3727. len += sprintf(page + len, "\n");
  3728. }
  3729. if (sense[27] & DASD_SENSE_BIT_0) {
  3730. /* 24 Byte Sense Data */
  3731. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3732. " 24 Byte: %x MSG %x, "
  3733. "%s MSGb to SYSOP\n",
  3734. sense[7] >> 4, sense[7] & 0x0f,
  3735. sense[1] & 0x10 ? "" : "no");
  3736. } else {
  3737. /* 32 Byte Sense Data */
  3738. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3739. " 32 Byte: Format: %x "
  3740. "Exception class %x\n",
  3741. sense[6] & 0x0f, sense[22] >> 4);
  3742. }
  3743. } else {
  3744. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3745. " SORRY - NO VALID SENSE AVAILABLE\n");
  3746. }
  3747. } else {
  3748. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3749. " SORRY - NO TSB DATA AVAILABLE\n");
  3750. }
  3751. printk("%s", page);
  3752. free_page((unsigned long) page);
  3753. }
  3754. static void dasd_eckd_dump_sense(struct dasd_device *device,
  3755. struct dasd_ccw_req *req, struct irb *irb)
  3756. {
  3757. if (scsw_is_tm(&irb->scsw))
  3758. dasd_eckd_dump_sense_tcw(device, req, irb);
  3759. else
  3760. dasd_eckd_dump_sense_ccw(device, req, irb);
  3761. }
  3762. static int dasd_eckd_pm_freeze(struct dasd_device *device)
  3763. {
  3764. /*
  3765. * the device should be disconnected from our LCU structure
  3766. * on restore we will reconnect it and reread LCU specific
  3767. * information like PAV support that might have changed
  3768. */
  3769. dasd_alias_remove_device(device);
  3770. dasd_alias_disconnect_device_from_lcu(device);
  3771. return 0;
  3772. }
  3773. static int dasd_eckd_restore_device(struct dasd_device *device)
  3774. {
  3775. struct dasd_eckd_private *private;
  3776. struct dasd_eckd_characteristics temp_rdc_data;
  3777. int rc;
  3778. struct dasd_uid temp_uid;
  3779. unsigned long flags;
  3780. private = (struct dasd_eckd_private *) device->private;
  3781. /* Read Configuration Data */
  3782. rc = dasd_eckd_read_conf(device);
  3783. if (rc)
  3784. goto out_err;
  3785. dasd_eckd_get_uid(device, &temp_uid);
  3786. /* Generate device unique id */
  3787. rc = dasd_eckd_generate_uid(device);
  3788. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  3789. if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
  3790. dev_err(&device->cdev->dev, "The UID of the DASD has "
  3791. "changed\n");
  3792. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  3793. if (rc)
  3794. goto out_err;
  3795. /* register lcu with alias handling, enable PAV if this is a new lcu */
  3796. rc = dasd_alias_make_device_known_to_lcu(device);
  3797. if (rc)
  3798. return rc;
  3799. dasd_eckd_validate_server(device);
  3800. /* RE-Read Configuration Data */
  3801. rc = dasd_eckd_read_conf(device);
  3802. if (rc)
  3803. goto out_err;
  3804. /* Read Feature Codes */
  3805. dasd_eckd_read_features(device);
  3806. /* Read Device Characteristics */
  3807. rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
  3808. &temp_rdc_data, 64);
  3809. if (rc) {
  3810. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  3811. "Read device characteristic failed, rc=%d", rc);
  3812. goto out_err;
  3813. }
  3814. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  3815. memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
  3816. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  3817. /* add device to alias management */
  3818. dasd_alias_add_device(device);
  3819. return 0;
  3820. out_err:
  3821. return -1;
  3822. }
  3823. static int dasd_eckd_reload_device(struct dasd_device *device)
  3824. {
  3825. struct dasd_eckd_private *private;
  3826. int rc, old_base;
  3827. char print_uid[60];
  3828. struct dasd_uid uid;
  3829. unsigned long flags;
  3830. private = (struct dasd_eckd_private *) device->private;
  3831. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  3832. old_base = private->uid.base_unit_addr;
  3833. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  3834. /* Read Configuration Data */
  3835. rc = dasd_eckd_read_conf(device);
  3836. if (rc)
  3837. goto out_err;
  3838. rc = dasd_eckd_generate_uid(device);
  3839. if (rc)
  3840. goto out_err;
  3841. /*
  3842. * update unit address configuration and
  3843. * add device to alias management
  3844. */
  3845. dasd_alias_update_add_device(device);
  3846. dasd_eckd_get_uid(device, &uid);
  3847. if (old_base != uid.base_unit_addr) {
  3848. if (strlen(uid.vduit) > 0)
  3849. snprintf(print_uid, sizeof(print_uid),
  3850. "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
  3851. uid.ssid, uid.base_unit_addr, uid.vduit);
  3852. else
  3853. snprintf(print_uid, sizeof(print_uid),
  3854. "%s.%s.%04x.%02x", uid.vendor, uid.serial,
  3855. uid.ssid, uid.base_unit_addr);
  3856. dev_info(&device->cdev->dev,
  3857. "An Alias device was reassigned to a new base device "
  3858. "with UID: %s\n", print_uid);
  3859. }
  3860. return 0;
  3861. out_err:
  3862. return -1;
  3863. }
  3864. static struct ccw_driver dasd_eckd_driver = {
  3865. .driver = {
  3866. .name = "dasd-eckd",
  3867. .owner = THIS_MODULE,
  3868. },
  3869. .ids = dasd_eckd_ids,
  3870. .probe = dasd_eckd_probe,
  3871. .remove = dasd_generic_remove,
  3872. .set_offline = dasd_generic_set_offline,
  3873. .set_online = dasd_eckd_set_online,
  3874. .notify = dasd_generic_notify,
  3875. .path_event = dasd_generic_path_event,
  3876. .freeze = dasd_generic_pm_freeze,
  3877. .thaw = dasd_generic_restore_device,
  3878. .restore = dasd_generic_restore_device,
  3879. .uc_handler = dasd_generic_uc_handler,
  3880. .int_class = IOINT_DAS,
  3881. };
  3882. /*
  3883. * max_blocks is dependent on the amount of storage that is available
  3884. * in the static io buffer for each device. Currently each device has
  3885. * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
  3886. * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
  3887. * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
  3888. * addition we have one define extent ccw + 16 bytes of data and one
  3889. * locate record ccw + 16 bytes of data. That makes:
  3890. * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
  3891. * We want to fit two into the available memory so that we can immediately
  3892. * start the next request if one finishes off. That makes 249.5 blocks
  3893. * for one request. Give a little safety and the result is 240.
  3894. */
  3895. static struct dasd_discipline dasd_eckd_discipline = {
  3896. .owner = THIS_MODULE,
  3897. .name = "ECKD",
  3898. .ebcname = "ECKD",
  3899. .max_blocks = 190,
  3900. .check_device = dasd_eckd_check_characteristics,
  3901. .uncheck_device = dasd_eckd_uncheck_device,
  3902. .do_analysis = dasd_eckd_do_analysis,
  3903. .verify_path = dasd_eckd_verify_path,
  3904. .ready_to_online = dasd_eckd_ready_to_online,
  3905. .online_to_ready = dasd_eckd_online_to_ready,
  3906. .fill_geometry = dasd_eckd_fill_geometry,
  3907. .start_IO = dasd_start_IO,
  3908. .term_IO = dasd_term_IO,
  3909. .handle_terminated_request = dasd_eckd_handle_terminated_request,
  3910. .format_device = dasd_eckd_format_device,
  3911. .erp_action = dasd_eckd_erp_action,
  3912. .erp_postaction = dasd_eckd_erp_postaction,
  3913. .check_for_device_change = dasd_eckd_check_for_device_change,
  3914. .build_cp = dasd_eckd_build_alias_cp,
  3915. .free_cp = dasd_eckd_free_alias_cp,
  3916. .dump_sense = dasd_eckd_dump_sense,
  3917. .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
  3918. .fill_info = dasd_eckd_fill_info,
  3919. .ioctl = dasd_eckd_ioctl,
  3920. .freeze = dasd_eckd_pm_freeze,
  3921. .restore = dasd_eckd_restore_device,
  3922. .reload = dasd_eckd_reload_device,
  3923. .get_uid = dasd_eckd_get_uid,
  3924. .kick_validate = dasd_eckd_kick_validate_server,
  3925. };
  3926. static int __init
  3927. dasd_eckd_init(void)
  3928. {
  3929. int ret;
  3930. ASCEBC(dasd_eckd_discipline.ebcname, 4);
  3931. dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
  3932. GFP_KERNEL | GFP_DMA);
  3933. if (!dasd_reserve_req)
  3934. return -ENOMEM;
  3935. path_verification_worker = kmalloc(sizeof(*path_verification_worker),
  3936. GFP_KERNEL | GFP_DMA);
  3937. if (!path_verification_worker) {
  3938. kfree(dasd_reserve_req);
  3939. return -ENOMEM;
  3940. }
  3941. ret = ccw_driver_register(&dasd_eckd_driver);
  3942. if (!ret)
  3943. wait_for_device_probe();
  3944. else {
  3945. kfree(path_verification_worker);
  3946. kfree(dasd_reserve_req);
  3947. }
  3948. return ret;
  3949. }
  3950. static void __exit
  3951. dasd_eckd_cleanup(void)
  3952. {
  3953. ccw_driver_unregister(&dasd_eckd_driver);
  3954. kfree(path_verification_worker);
  3955. kfree(dasd_reserve_req);
  3956. }
  3957. module_init(dasd_eckd_init);
  3958. module_exit(dasd_eckd_cleanup);