dasd_eckd.c 119 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310
  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/init.h>
  20. #include <asm/debug.h>
  21. #include <asm/idals.h>
  22. #include <asm/ebcdic.h>
  23. #include <asm/compat.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. if (dasd_nopav || MACHINE_IS_VM)
  1403. enable_pav = 0;
  1404. else
  1405. enable_pav = 1;
  1406. rc = dasd_eckd_psf_ssc(device, enable_pav);
  1407. /* may be requested feature is not available on server,
  1408. * therefore just report error and go ahead */
  1409. private = (struct dasd_eckd_private *) device->private;
  1410. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "PSF-SSC for SSID %04x "
  1411. "returned rc=%d", private->uid.ssid, rc);
  1412. }
  1413. static u32 get_fcx_max_data(struct dasd_device *device)
  1414. {
  1415. #if defined(CONFIG_64BIT)
  1416. int tpm, mdc;
  1417. int fcx_in_css, fcx_in_gneq, fcx_in_features;
  1418. struct dasd_eckd_private *private;
  1419. if (dasd_nofcx)
  1420. return 0;
  1421. /* is transport mode supported? */
  1422. private = (struct dasd_eckd_private *) device->private;
  1423. fcx_in_css = css_general_characteristics.fcx;
  1424. fcx_in_gneq = private->gneq->reserved2[7] & 0x04;
  1425. fcx_in_features = private->features.feature[40] & 0x80;
  1426. tpm = fcx_in_css && fcx_in_gneq && fcx_in_features;
  1427. if (!tpm)
  1428. return 0;
  1429. mdc = ccw_device_get_mdc(device->cdev, 0);
  1430. if (mdc < 0) {
  1431. dev_warn(&device->cdev->dev, "Detecting the maximum supported"
  1432. " data size for zHPF requests failed\n");
  1433. return 0;
  1434. } else
  1435. return mdc * FCX_MAX_DATA_FACTOR;
  1436. #else
  1437. return 0;
  1438. #endif
  1439. }
  1440. /*
  1441. * Check device characteristics.
  1442. * If the device is accessible using ECKD discipline, the device is enabled.
  1443. */
  1444. static int
  1445. dasd_eckd_check_characteristics(struct dasd_device *device)
  1446. {
  1447. struct dasd_eckd_private *private;
  1448. struct dasd_block *block;
  1449. struct dasd_uid temp_uid;
  1450. int is_known, rc, i;
  1451. int readonly;
  1452. unsigned long value;
  1453. if (!ccw_device_is_pathgroup(device->cdev)) {
  1454. dev_warn(&device->cdev->dev,
  1455. "A channel path group could not be established\n");
  1456. return -EIO;
  1457. }
  1458. if (!ccw_device_is_multipath(device->cdev)) {
  1459. dev_info(&device->cdev->dev,
  1460. "The DASD is not operating in multipath mode\n");
  1461. }
  1462. private = (struct dasd_eckd_private *) device->private;
  1463. if (!private) {
  1464. private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA);
  1465. if (!private) {
  1466. dev_warn(&device->cdev->dev,
  1467. "Allocating memory for private DASD data "
  1468. "failed\n");
  1469. return -ENOMEM;
  1470. }
  1471. device->private = (void *) private;
  1472. } else {
  1473. memset(private, 0, sizeof(*private));
  1474. }
  1475. /* Invalidate status of initial analysis. */
  1476. private->init_cqr_status = -1;
  1477. /* Set default cache operations. */
  1478. private->attrib.operation = DASD_NORMAL_CACHE;
  1479. private->attrib.nr_cyl = 0;
  1480. /* Read Configuration Data */
  1481. rc = dasd_eckd_read_conf(device);
  1482. if (rc)
  1483. goto out_err1;
  1484. /* set default timeout */
  1485. device->default_expires = DASD_EXPIRES;
  1486. if (private->gneq) {
  1487. value = 1;
  1488. for (i = 0; i < private->gneq->timeout.value; i++)
  1489. value = 10 * value;
  1490. value = value * private->gneq->timeout.number;
  1491. /* do not accept useless values */
  1492. if (value != 0 && value <= DASD_EXPIRES_MAX)
  1493. device->default_expires = value;
  1494. }
  1495. dasd_eckd_get_uid(device, &temp_uid);
  1496. if (temp_uid.type == UA_BASE_DEVICE) {
  1497. block = dasd_alloc_block();
  1498. if (IS_ERR(block)) {
  1499. DBF_EVENT_DEVID(DBF_WARNING, device->cdev, "%s",
  1500. "could not allocate dasd "
  1501. "block structure");
  1502. rc = PTR_ERR(block);
  1503. goto out_err1;
  1504. }
  1505. device->block = block;
  1506. block->base = device;
  1507. }
  1508. /* register lcu with alias handling, enable PAV if this is a new lcu */
  1509. is_known = dasd_alias_make_device_known_to_lcu(device);
  1510. if (is_known < 0) {
  1511. rc = is_known;
  1512. goto out_err2;
  1513. }
  1514. /*
  1515. * dasd_eckd_validate_server is done on the first device that
  1516. * is found for an LCU. All later other devices have to wait
  1517. * for it, so they will read the correct feature codes.
  1518. */
  1519. if (!is_known) {
  1520. dasd_eckd_validate_server(device);
  1521. dasd_alias_lcu_setup_complete(device);
  1522. } else
  1523. dasd_alias_wait_for_lcu_setup(device);
  1524. /* device may report different configuration data after LCU setup */
  1525. rc = dasd_eckd_read_conf(device);
  1526. if (rc)
  1527. goto out_err3;
  1528. /* Read Feature Codes */
  1529. dasd_eckd_read_features(device);
  1530. /* Read Device Characteristics */
  1531. rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
  1532. &private->rdc_data, 64);
  1533. if (rc) {
  1534. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  1535. "Read device characteristic failed, rc=%d", rc);
  1536. goto out_err3;
  1537. }
  1538. if ((device->features & DASD_FEATURE_USERAW) &&
  1539. !(private->rdc_data.facilities.RT_in_LR)) {
  1540. dev_err(&device->cdev->dev, "The storage server does not "
  1541. "support raw-track access\n");
  1542. rc = -EINVAL;
  1543. goto out_err3;
  1544. }
  1545. /* find the valid cylinder size */
  1546. if (private->rdc_data.no_cyl == LV_COMPAT_CYL &&
  1547. private->rdc_data.long_no_cyl)
  1548. private->real_cyl = private->rdc_data.long_no_cyl;
  1549. else
  1550. private->real_cyl = private->rdc_data.no_cyl;
  1551. private->fcx_max_data = get_fcx_max_data(device);
  1552. readonly = dasd_device_is_ro(device);
  1553. if (readonly)
  1554. set_bit(DASD_FLAG_DEVICE_RO, &device->flags);
  1555. dev_info(&device->cdev->dev, "New DASD %04X/%02X (CU %04X/%02X) "
  1556. "with %d cylinders, %d heads, %d sectors%s\n",
  1557. private->rdc_data.dev_type,
  1558. private->rdc_data.dev_model,
  1559. private->rdc_data.cu_type,
  1560. private->rdc_data.cu_model.model,
  1561. private->real_cyl,
  1562. private->rdc_data.trk_per_cyl,
  1563. private->rdc_data.sec_per_trk,
  1564. readonly ? ", read-only device" : "");
  1565. return 0;
  1566. out_err3:
  1567. dasd_alias_disconnect_device_from_lcu(device);
  1568. out_err2:
  1569. dasd_free_block(device->block);
  1570. device->block = NULL;
  1571. out_err1:
  1572. kfree(private->conf_data);
  1573. kfree(device->private);
  1574. device->private = NULL;
  1575. return rc;
  1576. }
  1577. static void dasd_eckd_uncheck_device(struct dasd_device *device)
  1578. {
  1579. struct dasd_eckd_private *private;
  1580. private = (struct dasd_eckd_private *) device->private;
  1581. dasd_alias_disconnect_device_from_lcu(device);
  1582. private->ned = NULL;
  1583. private->sneq = NULL;
  1584. private->vdsneq = NULL;
  1585. private->gneq = NULL;
  1586. private->conf_len = 0;
  1587. kfree(private->conf_data);
  1588. private->conf_data = NULL;
  1589. }
  1590. static struct dasd_ccw_req *
  1591. dasd_eckd_analysis_ccw(struct dasd_device *device)
  1592. {
  1593. struct dasd_eckd_private *private;
  1594. struct eckd_count *count_data;
  1595. struct LO_eckd_data *LO_data;
  1596. struct dasd_ccw_req *cqr;
  1597. struct ccw1 *ccw;
  1598. int cplength, datasize;
  1599. int i;
  1600. private = (struct dasd_eckd_private *) device->private;
  1601. cplength = 8;
  1602. datasize = sizeof(struct DE_eckd_data) + 2*sizeof(struct LO_eckd_data);
  1603. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
  1604. if (IS_ERR(cqr))
  1605. return cqr;
  1606. ccw = cqr->cpaddr;
  1607. /* Define extent for the first 3 tracks. */
  1608. define_extent(ccw++, cqr->data, 0, 2,
  1609. DASD_ECKD_CCW_READ_COUNT, device);
  1610. LO_data = cqr->data + sizeof(struct DE_eckd_data);
  1611. /* Locate record for the first 4 records on track 0. */
  1612. ccw[-1].flags |= CCW_FLAG_CC;
  1613. locate_record(ccw++, LO_data++, 0, 0, 4,
  1614. DASD_ECKD_CCW_READ_COUNT, device, 0);
  1615. count_data = private->count_area;
  1616. for (i = 0; i < 4; i++) {
  1617. ccw[-1].flags |= CCW_FLAG_CC;
  1618. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  1619. ccw->flags = 0;
  1620. ccw->count = 8;
  1621. ccw->cda = (__u32)(addr_t) count_data;
  1622. ccw++;
  1623. count_data++;
  1624. }
  1625. /* Locate record for the first record on track 2. */
  1626. ccw[-1].flags |= CCW_FLAG_CC;
  1627. locate_record(ccw++, LO_data++, 2, 0, 1,
  1628. DASD_ECKD_CCW_READ_COUNT, device, 0);
  1629. /* Read count ccw. */
  1630. ccw[-1].flags |= CCW_FLAG_CC;
  1631. ccw->cmd_code = DASD_ECKD_CCW_READ_COUNT;
  1632. ccw->flags = 0;
  1633. ccw->count = 8;
  1634. ccw->cda = (__u32)(addr_t) count_data;
  1635. cqr->block = NULL;
  1636. cqr->startdev = device;
  1637. cqr->memdev = device;
  1638. cqr->retries = 255;
  1639. cqr->buildclk = get_clock();
  1640. cqr->status = DASD_CQR_FILLED;
  1641. return cqr;
  1642. }
  1643. /* differentiate between 'no record found' and any other error */
  1644. static int dasd_eckd_analysis_evaluation(struct dasd_ccw_req *init_cqr)
  1645. {
  1646. char *sense;
  1647. if (init_cqr->status == DASD_CQR_DONE)
  1648. return INIT_CQR_OK;
  1649. else if (init_cqr->status == DASD_CQR_NEED_ERP ||
  1650. init_cqr->status == DASD_CQR_FAILED) {
  1651. sense = dasd_get_sense(&init_cqr->irb);
  1652. if (sense && (sense[1] & SNS1_NO_REC_FOUND))
  1653. return INIT_CQR_UNFORMATTED;
  1654. else
  1655. return INIT_CQR_ERROR;
  1656. } else
  1657. return INIT_CQR_ERROR;
  1658. }
  1659. /*
  1660. * This is the callback function for the init_analysis cqr. It saves
  1661. * the status of the initial analysis ccw before it frees it and kicks
  1662. * the device to continue the startup sequence. This will call
  1663. * dasd_eckd_do_analysis again (if the devices has not been marked
  1664. * for deletion in the meantime).
  1665. */
  1666. static void dasd_eckd_analysis_callback(struct dasd_ccw_req *init_cqr,
  1667. void *data)
  1668. {
  1669. struct dasd_eckd_private *private;
  1670. struct dasd_device *device;
  1671. device = init_cqr->startdev;
  1672. private = (struct dasd_eckd_private *) device->private;
  1673. private->init_cqr_status = dasd_eckd_analysis_evaluation(init_cqr);
  1674. dasd_sfree_request(init_cqr, device);
  1675. dasd_kick_device(device);
  1676. }
  1677. static int dasd_eckd_start_analysis(struct dasd_block *block)
  1678. {
  1679. struct dasd_ccw_req *init_cqr;
  1680. init_cqr = dasd_eckd_analysis_ccw(block->base);
  1681. if (IS_ERR(init_cqr))
  1682. return PTR_ERR(init_cqr);
  1683. init_cqr->callback = dasd_eckd_analysis_callback;
  1684. init_cqr->callback_data = NULL;
  1685. init_cqr->expires = 5*HZ;
  1686. /* first try without ERP, so we can later handle unformatted
  1687. * devices as special case
  1688. */
  1689. clear_bit(DASD_CQR_FLAGS_USE_ERP, &init_cqr->flags);
  1690. init_cqr->retries = 0;
  1691. dasd_add_request_head(init_cqr);
  1692. return -EAGAIN;
  1693. }
  1694. static int dasd_eckd_end_analysis(struct dasd_block *block)
  1695. {
  1696. struct dasd_device *device;
  1697. struct dasd_eckd_private *private;
  1698. struct eckd_count *count_area;
  1699. unsigned int sb, blk_per_trk;
  1700. int status, i;
  1701. struct dasd_ccw_req *init_cqr;
  1702. device = block->base;
  1703. private = (struct dasd_eckd_private *) device->private;
  1704. status = private->init_cqr_status;
  1705. private->init_cqr_status = -1;
  1706. if (status == INIT_CQR_ERROR) {
  1707. /* try again, this time with full ERP */
  1708. init_cqr = dasd_eckd_analysis_ccw(device);
  1709. dasd_sleep_on(init_cqr);
  1710. status = dasd_eckd_analysis_evaluation(init_cqr);
  1711. dasd_sfree_request(init_cqr, device);
  1712. }
  1713. if (device->features & DASD_FEATURE_USERAW) {
  1714. block->bp_block = DASD_RAW_BLOCKSIZE;
  1715. blk_per_trk = DASD_RAW_BLOCK_PER_TRACK;
  1716. block->s2b_shift = 3;
  1717. goto raw;
  1718. }
  1719. if (status == INIT_CQR_UNFORMATTED) {
  1720. dev_warn(&device->cdev->dev, "The DASD is not formatted\n");
  1721. return -EMEDIUMTYPE;
  1722. } else if (status == INIT_CQR_ERROR) {
  1723. dev_err(&device->cdev->dev,
  1724. "Detecting the DASD disk layout failed because "
  1725. "of an I/O error\n");
  1726. return -EIO;
  1727. }
  1728. private->uses_cdl = 1;
  1729. /* Check Track 0 for Compatible Disk Layout */
  1730. count_area = NULL;
  1731. for (i = 0; i < 3; i++) {
  1732. if (private->count_area[i].kl != 4 ||
  1733. private->count_area[i].dl != dasd_eckd_cdl_reclen(i) - 4) {
  1734. private->uses_cdl = 0;
  1735. break;
  1736. }
  1737. }
  1738. if (i == 3)
  1739. count_area = &private->count_area[4];
  1740. if (private->uses_cdl == 0) {
  1741. for (i = 0; i < 5; i++) {
  1742. if ((private->count_area[i].kl != 0) ||
  1743. (private->count_area[i].dl !=
  1744. private->count_area[0].dl))
  1745. break;
  1746. }
  1747. if (i == 5)
  1748. count_area = &private->count_area[0];
  1749. } else {
  1750. if (private->count_area[3].record == 1)
  1751. dev_warn(&device->cdev->dev,
  1752. "Track 0 has no records following the VTOC\n");
  1753. }
  1754. if (count_area != NULL && count_area->kl == 0) {
  1755. /* we found notthing violating our disk layout */
  1756. if (dasd_check_blocksize(count_area->dl) == 0)
  1757. block->bp_block = count_area->dl;
  1758. }
  1759. if (block->bp_block == 0) {
  1760. dev_warn(&device->cdev->dev,
  1761. "The disk layout of the DASD is not supported\n");
  1762. return -EMEDIUMTYPE;
  1763. }
  1764. block->s2b_shift = 0; /* bits to shift 512 to get a block */
  1765. for (sb = 512; sb < block->bp_block; sb = sb << 1)
  1766. block->s2b_shift++;
  1767. blk_per_trk = recs_per_track(&private->rdc_data, 0, block->bp_block);
  1768. raw:
  1769. block->blocks = (private->real_cyl *
  1770. private->rdc_data.trk_per_cyl *
  1771. blk_per_trk);
  1772. dev_info(&device->cdev->dev,
  1773. "DASD with %d KB/block, %d KB total size, %d KB/track, "
  1774. "%s\n", (block->bp_block >> 10),
  1775. ((private->real_cyl *
  1776. private->rdc_data.trk_per_cyl *
  1777. blk_per_trk * (block->bp_block >> 9)) >> 1),
  1778. ((blk_per_trk * block->bp_block) >> 10),
  1779. private->uses_cdl ?
  1780. "compatible disk layout" : "linux disk layout");
  1781. return 0;
  1782. }
  1783. static int dasd_eckd_do_analysis(struct dasd_block *block)
  1784. {
  1785. struct dasd_eckd_private *private;
  1786. private = (struct dasd_eckd_private *) block->base->private;
  1787. if (private->init_cqr_status < 0)
  1788. return dasd_eckd_start_analysis(block);
  1789. else
  1790. return dasd_eckd_end_analysis(block);
  1791. }
  1792. static int dasd_eckd_ready_to_online(struct dasd_device *device)
  1793. {
  1794. return dasd_alias_add_device(device);
  1795. };
  1796. static int dasd_eckd_online_to_ready(struct dasd_device *device)
  1797. {
  1798. cancel_work_sync(&device->reload_device);
  1799. return dasd_alias_remove_device(device);
  1800. };
  1801. static int
  1802. dasd_eckd_fill_geometry(struct dasd_block *block, struct hd_geometry *geo)
  1803. {
  1804. struct dasd_eckd_private *private;
  1805. private = (struct dasd_eckd_private *) block->base->private;
  1806. if (dasd_check_blocksize(block->bp_block) == 0) {
  1807. geo->sectors = recs_per_track(&private->rdc_data,
  1808. 0, block->bp_block);
  1809. }
  1810. geo->cylinders = private->rdc_data.no_cyl;
  1811. geo->heads = private->rdc_data.trk_per_cyl;
  1812. return 0;
  1813. }
  1814. static struct dasd_ccw_req *
  1815. dasd_eckd_format_device(struct dasd_device * device,
  1816. struct format_data_t * fdata)
  1817. {
  1818. struct dasd_eckd_private *private;
  1819. struct dasd_ccw_req *fcp;
  1820. struct eckd_count *ect;
  1821. struct ccw1 *ccw;
  1822. void *data;
  1823. int rpt;
  1824. struct ch_t address;
  1825. int cplength, datasize;
  1826. int i;
  1827. int intensity = 0;
  1828. int r0_perm;
  1829. private = (struct dasd_eckd_private *) device->private;
  1830. rpt = recs_per_track(&private->rdc_data, 0, fdata->blksize);
  1831. set_ch_t(&address,
  1832. fdata->start_unit / private->rdc_data.trk_per_cyl,
  1833. fdata->start_unit % private->rdc_data.trk_per_cyl);
  1834. /* Sanity checks. */
  1835. if (fdata->start_unit >=
  1836. (private->real_cyl * private->rdc_data.trk_per_cyl)) {
  1837. dev_warn(&device->cdev->dev, "Start track number %d used in "
  1838. "formatting is too big\n", fdata->start_unit);
  1839. return ERR_PTR(-EINVAL);
  1840. }
  1841. if (fdata->start_unit > fdata->stop_unit) {
  1842. dev_warn(&device->cdev->dev, "Start track %d used in "
  1843. "formatting exceeds end track\n", fdata->start_unit);
  1844. return ERR_PTR(-EINVAL);
  1845. }
  1846. if (dasd_check_blocksize(fdata->blksize) != 0) {
  1847. dev_warn(&device->cdev->dev,
  1848. "The DASD cannot be formatted with block size %d\n",
  1849. fdata->blksize);
  1850. return ERR_PTR(-EINVAL);
  1851. }
  1852. /*
  1853. * fdata->intensity is a bit string that tells us what to do:
  1854. * Bit 0: write record zero
  1855. * Bit 1: write home address, currently not supported
  1856. * Bit 2: invalidate tracks
  1857. * Bit 3: use OS/390 compatible disk layout (cdl)
  1858. * Bit 4: do not allow storage subsystem to modify record zero
  1859. * Only some bit combinations do make sense.
  1860. */
  1861. if (fdata->intensity & 0x10) {
  1862. r0_perm = 0;
  1863. intensity = fdata->intensity & ~0x10;
  1864. } else {
  1865. r0_perm = 1;
  1866. intensity = fdata->intensity;
  1867. }
  1868. switch (intensity) {
  1869. case 0x00: /* Normal format */
  1870. case 0x08: /* Normal format, use cdl. */
  1871. cplength = 2 + rpt;
  1872. datasize = sizeof(struct DE_eckd_data) +
  1873. sizeof(struct LO_eckd_data) +
  1874. rpt * sizeof(struct eckd_count);
  1875. break;
  1876. case 0x01: /* Write record zero and format track. */
  1877. case 0x09: /* Write record zero and format track, use cdl. */
  1878. cplength = 3 + rpt;
  1879. datasize = sizeof(struct DE_eckd_data) +
  1880. sizeof(struct LO_eckd_data) +
  1881. sizeof(struct eckd_count) +
  1882. rpt * sizeof(struct eckd_count);
  1883. break;
  1884. case 0x04: /* Invalidate track. */
  1885. case 0x0c: /* Invalidate track, use cdl. */
  1886. cplength = 3;
  1887. datasize = sizeof(struct DE_eckd_data) +
  1888. sizeof(struct LO_eckd_data) +
  1889. sizeof(struct eckd_count);
  1890. break;
  1891. default:
  1892. dev_warn(&device->cdev->dev, "An I/O control call used "
  1893. "incorrect flags 0x%x\n", fdata->intensity);
  1894. return ERR_PTR(-EINVAL);
  1895. }
  1896. /* Allocate the format ccw request. */
  1897. fcp = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize, device);
  1898. if (IS_ERR(fcp))
  1899. return fcp;
  1900. data = fcp->data;
  1901. ccw = fcp->cpaddr;
  1902. switch (intensity & ~0x08) {
  1903. case 0x00: /* Normal format. */
  1904. define_extent(ccw++, (struct DE_eckd_data *) data,
  1905. fdata->start_unit, fdata->start_unit,
  1906. DASD_ECKD_CCW_WRITE_CKD, device);
  1907. /* grant subsystem permission to format R0 */
  1908. if (r0_perm)
  1909. ((struct DE_eckd_data *)data)->ga_extended |= 0x04;
  1910. data += sizeof(struct DE_eckd_data);
  1911. ccw[-1].flags |= CCW_FLAG_CC;
  1912. locate_record(ccw++, (struct LO_eckd_data *) data,
  1913. fdata->start_unit, 0, rpt,
  1914. DASD_ECKD_CCW_WRITE_CKD, device,
  1915. fdata->blksize);
  1916. data += sizeof(struct LO_eckd_data);
  1917. break;
  1918. case 0x01: /* Write record zero + format track. */
  1919. define_extent(ccw++, (struct DE_eckd_data *) data,
  1920. fdata->start_unit, fdata->start_unit,
  1921. DASD_ECKD_CCW_WRITE_RECORD_ZERO,
  1922. device);
  1923. data += sizeof(struct DE_eckd_data);
  1924. ccw[-1].flags |= CCW_FLAG_CC;
  1925. locate_record(ccw++, (struct LO_eckd_data *) data,
  1926. fdata->start_unit, 0, rpt + 1,
  1927. DASD_ECKD_CCW_WRITE_RECORD_ZERO, device,
  1928. device->block->bp_block);
  1929. data += sizeof(struct LO_eckd_data);
  1930. break;
  1931. case 0x04: /* Invalidate track. */
  1932. define_extent(ccw++, (struct DE_eckd_data *) data,
  1933. fdata->start_unit, fdata->start_unit,
  1934. DASD_ECKD_CCW_WRITE_CKD, device);
  1935. data += sizeof(struct DE_eckd_data);
  1936. ccw[-1].flags |= CCW_FLAG_CC;
  1937. locate_record(ccw++, (struct LO_eckd_data *) data,
  1938. fdata->start_unit, 0, 1,
  1939. DASD_ECKD_CCW_WRITE_CKD, device, 8);
  1940. data += sizeof(struct LO_eckd_data);
  1941. break;
  1942. }
  1943. if (intensity & 0x01) { /* write record zero */
  1944. ect = (struct eckd_count *) data;
  1945. data += sizeof(struct eckd_count);
  1946. ect->cyl = address.cyl;
  1947. ect->head = address.head;
  1948. ect->record = 0;
  1949. ect->kl = 0;
  1950. ect->dl = 8;
  1951. ccw[-1].flags |= CCW_FLAG_CC;
  1952. ccw->cmd_code = DASD_ECKD_CCW_WRITE_RECORD_ZERO;
  1953. ccw->flags = CCW_FLAG_SLI;
  1954. ccw->count = 8;
  1955. ccw->cda = (__u32)(addr_t) ect;
  1956. ccw++;
  1957. }
  1958. if ((intensity & ~0x08) & 0x04) { /* erase track */
  1959. ect = (struct eckd_count *) data;
  1960. data += sizeof(struct eckd_count);
  1961. ect->cyl = address.cyl;
  1962. ect->head = address.head;
  1963. ect->record = 1;
  1964. ect->kl = 0;
  1965. ect->dl = 0;
  1966. ccw[-1].flags |= CCW_FLAG_CC;
  1967. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  1968. ccw->flags = CCW_FLAG_SLI;
  1969. ccw->count = 8;
  1970. ccw->cda = (__u32)(addr_t) ect;
  1971. } else { /* write remaining records */
  1972. for (i = 0; i < rpt; i++) {
  1973. ect = (struct eckd_count *) data;
  1974. data += sizeof(struct eckd_count);
  1975. ect->cyl = address.cyl;
  1976. ect->head = address.head;
  1977. ect->record = i + 1;
  1978. ect->kl = 0;
  1979. ect->dl = fdata->blksize;
  1980. /* Check for special tracks 0-1 when formatting CDL */
  1981. if ((intensity & 0x08) &&
  1982. fdata->start_unit == 0) {
  1983. if (i < 3) {
  1984. ect->kl = 4;
  1985. ect->dl = sizes_trk0[i] - 4;
  1986. }
  1987. }
  1988. if ((intensity & 0x08) &&
  1989. fdata->start_unit == 1) {
  1990. ect->kl = 44;
  1991. ect->dl = LABEL_SIZE - 44;
  1992. }
  1993. ccw[-1].flags |= CCW_FLAG_CC;
  1994. ccw->cmd_code = DASD_ECKD_CCW_WRITE_CKD;
  1995. ccw->flags = CCW_FLAG_SLI;
  1996. ccw->count = 8;
  1997. ccw->cda = (__u32)(addr_t) ect;
  1998. ccw++;
  1999. }
  2000. }
  2001. fcp->startdev = device;
  2002. fcp->memdev = device;
  2003. fcp->retries = 256;
  2004. fcp->buildclk = get_clock();
  2005. fcp->status = DASD_CQR_FILLED;
  2006. return fcp;
  2007. }
  2008. static void dasd_eckd_handle_terminated_request(struct dasd_ccw_req *cqr)
  2009. {
  2010. cqr->status = DASD_CQR_FILLED;
  2011. if (cqr->block && (cqr->startdev != cqr->block->base)) {
  2012. dasd_eckd_reset_ccw_to_base_io(cqr);
  2013. cqr->startdev = cqr->block->base;
  2014. cqr->lpm = cqr->block->base->path_data.opm;
  2015. }
  2016. };
  2017. static dasd_erp_fn_t
  2018. dasd_eckd_erp_action(struct dasd_ccw_req * cqr)
  2019. {
  2020. struct dasd_device *device = (struct dasd_device *) cqr->startdev;
  2021. struct ccw_device *cdev = device->cdev;
  2022. switch (cdev->id.cu_type) {
  2023. case 0x3990:
  2024. case 0x2105:
  2025. case 0x2107:
  2026. case 0x1750:
  2027. return dasd_3990_erp_action;
  2028. case 0x9343:
  2029. case 0x3880:
  2030. default:
  2031. return dasd_default_erp_action;
  2032. }
  2033. }
  2034. static dasd_erp_fn_t
  2035. dasd_eckd_erp_postaction(struct dasd_ccw_req * cqr)
  2036. {
  2037. return dasd_default_erp_postaction;
  2038. }
  2039. static void dasd_eckd_check_for_device_change(struct dasd_device *device,
  2040. struct dasd_ccw_req *cqr,
  2041. struct irb *irb)
  2042. {
  2043. char mask;
  2044. char *sense = NULL;
  2045. struct dasd_eckd_private *private;
  2046. private = (struct dasd_eckd_private *) device->private;
  2047. /* first of all check for state change pending interrupt */
  2048. mask = DEV_STAT_ATTENTION | DEV_STAT_DEV_END | DEV_STAT_UNIT_EXCEP;
  2049. if ((scsw_dstat(&irb->scsw) & mask) == mask) {
  2050. /*
  2051. * for alias only, not in offline processing
  2052. * and only if not suspended
  2053. */
  2054. if (!device->block && private->lcu &&
  2055. !test_bit(DASD_FLAG_OFFLINE, &device->flags) &&
  2056. !test_bit(DASD_FLAG_SUSPENDED, &device->flags)) {
  2057. /*
  2058. * the state change could be caused by an alias
  2059. * reassignment remove device from alias handling
  2060. * to prevent new requests from being scheduled on
  2061. * the wrong alias device
  2062. */
  2063. dasd_alias_remove_device(device);
  2064. /* schedule worker to reload device */
  2065. dasd_reload_device(device);
  2066. }
  2067. dasd_generic_handle_state_change(device);
  2068. return;
  2069. }
  2070. sense = dasd_get_sense(irb);
  2071. if (!sense)
  2072. return;
  2073. /* summary unit check */
  2074. if ((sense[27] & DASD_SENSE_BIT_0) && (sense[7] == 0x0D) &&
  2075. (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK)) {
  2076. dasd_alias_handle_summary_unit_check(device, irb);
  2077. return;
  2078. }
  2079. /* service information message SIM */
  2080. if (!cqr && !(sense[27] & DASD_SENSE_BIT_0) &&
  2081. ((sense[6] & DASD_SIM_SENSE) == DASD_SIM_SENSE)) {
  2082. dasd_3990_erp_handle_sim(device, sense);
  2083. return;
  2084. }
  2085. /* loss of device reservation is handled via base devices only
  2086. * as alias devices may be used with several bases
  2087. */
  2088. if (device->block && (sense[27] & DASD_SENSE_BIT_0) &&
  2089. (sense[7] == 0x3F) &&
  2090. (scsw_dstat(&irb->scsw) & DEV_STAT_UNIT_CHECK) &&
  2091. test_bit(DASD_FLAG_IS_RESERVED, &device->flags)) {
  2092. if (device->features & DASD_FEATURE_FAILONSLCK)
  2093. set_bit(DASD_FLAG_LOCK_STOLEN, &device->flags);
  2094. clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  2095. dev_err(&device->cdev->dev,
  2096. "The device reservation was lost\n");
  2097. }
  2098. }
  2099. static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_single(
  2100. struct dasd_device *startdev,
  2101. struct dasd_block *block,
  2102. struct request *req,
  2103. sector_t first_rec,
  2104. sector_t last_rec,
  2105. sector_t first_trk,
  2106. sector_t last_trk,
  2107. unsigned int first_offs,
  2108. unsigned int last_offs,
  2109. unsigned int blk_per_trk,
  2110. unsigned int blksize)
  2111. {
  2112. struct dasd_eckd_private *private;
  2113. unsigned long *idaws;
  2114. struct LO_eckd_data *LO_data;
  2115. struct dasd_ccw_req *cqr;
  2116. struct ccw1 *ccw;
  2117. struct req_iterator iter;
  2118. struct bio_vec *bv;
  2119. char *dst;
  2120. unsigned int off;
  2121. int count, cidaw, cplength, datasize;
  2122. sector_t recid;
  2123. unsigned char cmd, rcmd;
  2124. int use_prefix;
  2125. struct dasd_device *basedev;
  2126. basedev = block->base;
  2127. private = (struct dasd_eckd_private *) basedev->private;
  2128. if (rq_data_dir(req) == READ)
  2129. cmd = DASD_ECKD_CCW_READ_MT;
  2130. else if (rq_data_dir(req) == WRITE)
  2131. cmd = DASD_ECKD_CCW_WRITE_MT;
  2132. else
  2133. return ERR_PTR(-EINVAL);
  2134. /* Check struct bio and count the number of blocks for the request. */
  2135. count = 0;
  2136. cidaw = 0;
  2137. rq_for_each_segment(bv, req, iter) {
  2138. if (bv->bv_len & (blksize - 1))
  2139. /* Eckd can only do full blocks. */
  2140. return ERR_PTR(-EINVAL);
  2141. count += bv->bv_len >> (block->s2b_shift + 9);
  2142. #if defined(CONFIG_64BIT)
  2143. if (idal_is_needed (page_address(bv->bv_page), bv->bv_len))
  2144. cidaw += bv->bv_len >> (block->s2b_shift + 9);
  2145. #endif
  2146. }
  2147. /* Paranoia. */
  2148. if (count != last_rec - first_rec + 1)
  2149. return ERR_PTR(-EINVAL);
  2150. /* use the prefix command if available */
  2151. use_prefix = private->features.feature[8] & 0x01;
  2152. if (use_prefix) {
  2153. /* 1x prefix + number of blocks */
  2154. cplength = 2 + count;
  2155. /* 1x prefix + cidaws*sizeof(long) */
  2156. datasize = sizeof(struct PFX_eckd_data) +
  2157. sizeof(struct LO_eckd_data) +
  2158. cidaw * sizeof(unsigned long);
  2159. } else {
  2160. /* 1x define extent + 1x locate record + number of blocks */
  2161. cplength = 2 + count;
  2162. /* 1x define extent + 1x locate record + cidaws*sizeof(long) */
  2163. datasize = sizeof(struct DE_eckd_data) +
  2164. sizeof(struct LO_eckd_data) +
  2165. cidaw * sizeof(unsigned long);
  2166. }
  2167. /* Find out the number of additional locate record ccws for cdl. */
  2168. if (private->uses_cdl && first_rec < 2*blk_per_trk) {
  2169. if (last_rec >= 2*blk_per_trk)
  2170. count = 2*blk_per_trk - first_rec;
  2171. cplength += count;
  2172. datasize += count*sizeof(struct LO_eckd_data);
  2173. }
  2174. /* Allocate the ccw request. */
  2175. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
  2176. startdev);
  2177. if (IS_ERR(cqr))
  2178. return cqr;
  2179. ccw = cqr->cpaddr;
  2180. /* First ccw is define extent or prefix. */
  2181. if (use_prefix) {
  2182. if (prefix(ccw++, cqr->data, first_trk,
  2183. last_trk, cmd, basedev, startdev) == -EAGAIN) {
  2184. /* Clock not in sync and XRC is enabled.
  2185. * Try again later.
  2186. */
  2187. dasd_sfree_request(cqr, startdev);
  2188. return ERR_PTR(-EAGAIN);
  2189. }
  2190. idaws = (unsigned long *) (cqr->data +
  2191. sizeof(struct PFX_eckd_data));
  2192. } else {
  2193. if (define_extent(ccw++, cqr->data, first_trk,
  2194. last_trk, cmd, basedev) == -EAGAIN) {
  2195. /* Clock not in sync and XRC is enabled.
  2196. * Try again later.
  2197. */
  2198. dasd_sfree_request(cqr, startdev);
  2199. return ERR_PTR(-EAGAIN);
  2200. }
  2201. idaws = (unsigned long *) (cqr->data +
  2202. sizeof(struct DE_eckd_data));
  2203. }
  2204. /* Build locate_record+read/write/ccws. */
  2205. LO_data = (struct LO_eckd_data *) (idaws + cidaw);
  2206. recid = first_rec;
  2207. if (private->uses_cdl == 0 || recid > 2*blk_per_trk) {
  2208. /* Only standard blocks so there is just one locate record. */
  2209. ccw[-1].flags |= CCW_FLAG_CC;
  2210. locate_record(ccw++, LO_data++, first_trk, first_offs + 1,
  2211. last_rec - recid + 1, cmd, basedev, blksize);
  2212. }
  2213. rq_for_each_segment(bv, req, iter) {
  2214. dst = page_address(bv->bv_page) + bv->bv_offset;
  2215. if (dasd_page_cache) {
  2216. char *copy = kmem_cache_alloc(dasd_page_cache,
  2217. GFP_DMA | __GFP_NOWARN);
  2218. if (copy && rq_data_dir(req) == WRITE)
  2219. memcpy(copy + bv->bv_offset, dst, bv->bv_len);
  2220. if (copy)
  2221. dst = copy + bv->bv_offset;
  2222. }
  2223. for (off = 0; off < bv->bv_len; off += blksize) {
  2224. sector_t trkid = recid;
  2225. unsigned int recoffs = sector_div(trkid, blk_per_trk);
  2226. rcmd = cmd;
  2227. count = blksize;
  2228. /* Locate record for cdl special block ? */
  2229. if (private->uses_cdl && recid < 2*blk_per_trk) {
  2230. if (dasd_eckd_cdl_special(blk_per_trk, recid)){
  2231. rcmd |= 0x8;
  2232. count = dasd_eckd_cdl_reclen(recid);
  2233. if (count < blksize &&
  2234. rq_data_dir(req) == READ)
  2235. memset(dst + count, 0xe5,
  2236. blksize - count);
  2237. }
  2238. ccw[-1].flags |= CCW_FLAG_CC;
  2239. locate_record(ccw++, LO_data++,
  2240. trkid, recoffs + 1,
  2241. 1, rcmd, basedev, count);
  2242. }
  2243. /* Locate record for standard blocks ? */
  2244. if (private->uses_cdl && recid == 2*blk_per_trk) {
  2245. ccw[-1].flags |= CCW_FLAG_CC;
  2246. locate_record(ccw++, LO_data++,
  2247. trkid, recoffs + 1,
  2248. last_rec - recid + 1,
  2249. cmd, basedev, count);
  2250. }
  2251. /* Read/write ccw. */
  2252. ccw[-1].flags |= CCW_FLAG_CC;
  2253. ccw->cmd_code = rcmd;
  2254. ccw->count = count;
  2255. if (idal_is_needed(dst, blksize)) {
  2256. ccw->cda = (__u32)(addr_t) idaws;
  2257. ccw->flags = CCW_FLAG_IDA;
  2258. idaws = idal_create_words(idaws, dst, blksize);
  2259. } else {
  2260. ccw->cda = (__u32)(addr_t) dst;
  2261. ccw->flags = 0;
  2262. }
  2263. ccw++;
  2264. dst += blksize;
  2265. recid++;
  2266. }
  2267. }
  2268. if (blk_noretry_request(req) ||
  2269. block->base->features & DASD_FEATURE_FAILFAST)
  2270. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2271. cqr->startdev = startdev;
  2272. cqr->memdev = startdev;
  2273. cqr->block = block;
  2274. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  2275. cqr->lpm = startdev->path_data.ppm;
  2276. cqr->retries = 256;
  2277. cqr->buildclk = get_clock();
  2278. cqr->status = DASD_CQR_FILLED;
  2279. return cqr;
  2280. }
  2281. static struct dasd_ccw_req *dasd_eckd_build_cp_cmd_track(
  2282. struct dasd_device *startdev,
  2283. struct dasd_block *block,
  2284. struct request *req,
  2285. sector_t first_rec,
  2286. sector_t last_rec,
  2287. sector_t first_trk,
  2288. sector_t last_trk,
  2289. unsigned int first_offs,
  2290. unsigned int last_offs,
  2291. unsigned int blk_per_trk,
  2292. unsigned int blksize)
  2293. {
  2294. unsigned long *idaws;
  2295. struct dasd_ccw_req *cqr;
  2296. struct ccw1 *ccw;
  2297. struct req_iterator iter;
  2298. struct bio_vec *bv;
  2299. char *dst, *idaw_dst;
  2300. unsigned int cidaw, cplength, datasize;
  2301. unsigned int tlf;
  2302. sector_t recid;
  2303. unsigned char cmd;
  2304. struct dasd_device *basedev;
  2305. unsigned int trkcount, count, count_to_trk_end;
  2306. unsigned int idaw_len, seg_len, part_len, len_to_track_end;
  2307. unsigned char new_track, end_idaw;
  2308. sector_t trkid;
  2309. unsigned int recoffs;
  2310. basedev = block->base;
  2311. if (rq_data_dir(req) == READ)
  2312. cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
  2313. else if (rq_data_dir(req) == WRITE)
  2314. cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
  2315. else
  2316. return ERR_PTR(-EINVAL);
  2317. /* Track based I/O needs IDAWs for each page, and not just for
  2318. * 64 bit addresses. We need additional idals for pages
  2319. * that get filled from two tracks, so we use the number
  2320. * of records as upper limit.
  2321. */
  2322. cidaw = last_rec - first_rec + 1;
  2323. trkcount = last_trk - first_trk + 1;
  2324. /* 1x prefix + one read/write ccw per track */
  2325. cplength = 1 + trkcount;
  2326. /* on 31-bit we need space for two 32 bit addresses per page
  2327. * on 64-bit one 64 bit address
  2328. */
  2329. datasize = sizeof(struct PFX_eckd_data) +
  2330. cidaw * sizeof(unsigned long long);
  2331. /* Allocate the ccw request. */
  2332. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength, datasize,
  2333. startdev);
  2334. if (IS_ERR(cqr))
  2335. return cqr;
  2336. ccw = cqr->cpaddr;
  2337. /* transfer length factor: how many bytes to read from the last track */
  2338. if (first_trk == last_trk)
  2339. tlf = last_offs - first_offs + 1;
  2340. else
  2341. tlf = last_offs + 1;
  2342. tlf *= blksize;
  2343. if (prefix_LRE(ccw++, cqr->data, first_trk,
  2344. last_trk, cmd, basedev, startdev,
  2345. 1 /* format */, first_offs + 1,
  2346. trkcount, blksize,
  2347. tlf) == -EAGAIN) {
  2348. /* Clock not in sync and XRC is enabled.
  2349. * Try again later.
  2350. */
  2351. dasd_sfree_request(cqr, startdev);
  2352. return ERR_PTR(-EAGAIN);
  2353. }
  2354. /*
  2355. * The translation of request into ccw programs must meet the
  2356. * following conditions:
  2357. * - all idaws but the first and the last must address full pages
  2358. * (or 2K blocks on 31-bit)
  2359. * - the scope of a ccw and it's idal ends with the track boundaries
  2360. */
  2361. idaws = (unsigned long *) (cqr->data + sizeof(struct PFX_eckd_data));
  2362. recid = first_rec;
  2363. new_track = 1;
  2364. end_idaw = 0;
  2365. len_to_track_end = 0;
  2366. idaw_dst = NULL;
  2367. idaw_len = 0;
  2368. rq_for_each_segment(bv, req, iter) {
  2369. dst = page_address(bv->bv_page) + bv->bv_offset;
  2370. seg_len = bv->bv_len;
  2371. while (seg_len) {
  2372. if (new_track) {
  2373. trkid = recid;
  2374. recoffs = sector_div(trkid, blk_per_trk);
  2375. count_to_trk_end = blk_per_trk - recoffs;
  2376. count = min((last_rec - recid + 1),
  2377. (sector_t)count_to_trk_end);
  2378. len_to_track_end = count * blksize;
  2379. ccw[-1].flags |= CCW_FLAG_CC;
  2380. ccw->cmd_code = cmd;
  2381. ccw->count = len_to_track_end;
  2382. ccw->cda = (__u32)(addr_t)idaws;
  2383. ccw->flags = CCW_FLAG_IDA;
  2384. ccw++;
  2385. recid += count;
  2386. new_track = 0;
  2387. /* first idaw for a ccw may start anywhere */
  2388. if (!idaw_dst)
  2389. idaw_dst = dst;
  2390. }
  2391. /* If we start a new idaw, we must make sure that it
  2392. * starts on an IDA_BLOCK_SIZE boundary.
  2393. * If we continue an idaw, we must make sure that the
  2394. * current segment begins where the so far accumulated
  2395. * idaw ends
  2396. */
  2397. if (!idaw_dst) {
  2398. if (__pa(dst) & (IDA_BLOCK_SIZE-1)) {
  2399. dasd_sfree_request(cqr, startdev);
  2400. return ERR_PTR(-ERANGE);
  2401. } else
  2402. idaw_dst = dst;
  2403. }
  2404. if ((idaw_dst + idaw_len) != dst) {
  2405. dasd_sfree_request(cqr, startdev);
  2406. return ERR_PTR(-ERANGE);
  2407. }
  2408. part_len = min(seg_len, len_to_track_end);
  2409. seg_len -= part_len;
  2410. dst += part_len;
  2411. idaw_len += part_len;
  2412. len_to_track_end -= part_len;
  2413. /* collected memory area ends on an IDA_BLOCK border,
  2414. * -> create an idaw
  2415. * idal_create_words will handle cases where idaw_len
  2416. * is larger then IDA_BLOCK_SIZE
  2417. */
  2418. if (!(__pa(idaw_dst + idaw_len) & (IDA_BLOCK_SIZE-1)))
  2419. end_idaw = 1;
  2420. /* We also need to end the idaw at track end */
  2421. if (!len_to_track_end) {
  2422. new_track = 1;
  2423. end_idaw = 1;
  2424. }
  2425. if (end_idaw) {
  2426. idaws = idal_create_words(idaws, idaw_dst,
  2427. idaw_len);
  2428. idaw_dst = NULL;
  2429. idaw_len = 0;
  2430. end_idaw = 0;
  2431. }
  2432. }
  2433. }
  2434. if (blk_noretry_request(req) ||
  2435. block->base->features & DASD_FEATURE_FAILFAST)
  2436. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2437. cqr->startdev = startdev;
  2438. cqr->memdev = startdev;
  2439. cqr->block = block;
  2440. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  2441. cqr->lpm = startdev->path_data.ppm;
  2442. cqr->retries = 256;
  2443. cqr->buildclk = get_clock();
  2444. cqr->status = DASD_CQR_FILLED;
  2445. return cqr;
  2446. }
  2447. static int prepare_itcw(struct itcw *itcw,
  2448. unsigned int trk, unsigned int totrk, int cmd,
  2449. struct dasd_device *basedev,
  2450. struct dasd_device *startdev,
  2451. unsigned int rec_on_trk, int count,
  2452. unsigned int blksize,
  2453. unsigned int total_data_size,
  2454. unsigned int tlf,
  2455. unsigned int blk_per_trk)
  2456. {
  2457. struct PFX_eckd_data pfxdata;
  2458. struct dasd_eckd_private *basepriv, *startpriv;
  2459. struct DE_eckd_data *dedata;
  2460. struct LRE_eckd_data *lredata;
  2461. struct dcw *dcw;
  2462. u32 begcyl, endcyl;
  2463. u16 heads, beghead, endhead;
  2464. u8 pfx_cmd;
  2465. int rc = 0;
  2466. int sector = 0;
  2467. int dn, d;
  2468. /* setup prefix data */
  2469. basepriv = (struct dasd_eckd_private *) basedev->private;
  2470. startpriv = (struct dasd_eckd_private *) startdev->private;
  2471. dedata = &pfxdata.define_extent;
  2472. lredata = &pfxdata.locate_record;
  2473. memset(&pfxdata, 0, sizeof(pfxdata));
  2474. pfxdata.format = 1; /* PFX with LRE */
  2475. pfxdata.base_address = basepriv->ned->unit_addr;
  2476. pfxdata.base_lss = basepriv->ned->ID;
  2477. pfxdata.validity.define_extent = 1;
  2478. /* private uid is kept up to date, conf_data may be outdated */
  2479. if (startpriv->uid.type != UA_BASE_DEVICE) {
  2480. pfxdata.validity.verify_base = 1;
  2481. if (startpriv->uid.type == UA_HYPER_PAV_ALIAS)
  2482. pfxdata.validity.hyper_pav = 1;
  2483. }
  2484. switch (cmd) {
  2485. case DASD_ECKD_CCW_READ_TRACK_DATA:
  2486. dedata->mask.perm = 0x1;
  2487. dedata->attributes.operation = basepriv->attrib.operation;
  2488. dedata->blk_size = blksize;
  2489. dedata->ga_extended |= 0x42;
  2490. lredata->operation.orientation = 0x0;
  2491. lredata->operation.operation = 0x0C;
  2492. lredata->auxiliary.check_bytes = 0x01;
  2493. pfx_cmd = DASD_ECKD_CCW_PFX_READ;
  2494. break;
  2495. case DASD_ECKD_CCW_WRITE_TRACK_DATA:
  2496. dedata->mask.perm = 0x02;
  2497. dedata->attributes.operation = basepriv->attrib.operation;
  2498. dedata->blk_size = blksize;
  2499. rc = check_XRC_on_prefix(&pfxdata, basedev);
  2500. dedata->ga_extended |= 0x42;
  2501. lredata->operation.orientation = 0x0;
  2502. lredata->operation.operation = 0x3F;
  2503. lredata->extended_operation = 0x23;
  2504. lredata->auxiliary.check_bytes = 0x2;
  2505. pfx_cmd = DASD_ECKD_CCW_PFX;
  2506. break;
  2507. default:
  2508. DBF_DEV_EVENT(DBF_ERR, basedev,
  2509. "prepare itcw, unknown opcode 0x%x", cmd);
  2510. BUG();
  2511. break;
  2512. }
  2513. if (rc)
  2514. return rc;
  2515. dedata->attributes.mode = 0x3; /* ECKD */
  2516. heads = basepriv->rdc_data.trk_per_cyl;
  2517. begcyl = trk / heads;
  2518. beghead = trk % heads;
  2519. endcyl = totrk / heads;
  2520. endhead = totrk % heads;
  2521. /* check for sequential prestage - enhance cylinder range */
  2522. if (dedata->attributes.operation == DASD_SEQ_PRESTAGE ||
  2523. dedata->attributes.operation == DASD_SEQ_ACCESS) {
  2524. if (endcyl + basepriv->attrib.nr_cyl < basepriv->real_cyl)
  2525. endcyl += basepriv->attrib.nr_cyl;
  2526. else
  2527. endcyl = (basepriv->real_cyl - 1);
  2528. }
  2529. set_ch_t(&dedata->beg_ext, begcyl, beghead);
  2530. set_ch_t(&dedata->end_ext, endcyl, endhead);
  2531. dedata->ep_format = 0x20; /* records per track is valid */
  2532. dedata->ep_rec_per_track = blk_per_trk;
  2533. if (rec_on_trk) {
  2534. switch (basepriv->rdc_data.dev_type) {
  2535. case 0x3390:
  2536. dn = ceil_quot(blksize + 6, 232);
  2537. d = 9 + ceil_quot(blksize + 6 * (dn + 1), 34);
  2538. sector = (49 + (rec_on_trk - 1) * (10 + d)) / 8;
  2539. break;
  2540. case 0x3380:
  2541. d = 7 + ceil_quot(blksize + 12, 32);
  2542. sector = (39 + (rec_on_trk - 1) * (8 + d)) / 7;
  2543. break;
  2544. }
  2545. }
  2546. lredata->auxiliary.length_valid = 1;
  2547. lredata->auxiliary.length_scope = 1;
  2548. lredata->auxiliary.imbedded_ccw_valid = 1;
  2549. lredata->length = tlf;
  2550. lredata->imbedded_ccw = cmd;
  2551. lredata->count = count;
  2552. lredata->sector = sector;
  2553. set_ch_t(&lredata->seek_addr, begcyl, beghead);
  2554. lredata->search_arg.cyl = lredata->seek_addr.cyl;
  2555. lredata->search_arg.head = lredata->seek_addr.head;
  2556. lredata->search_arg.record = rec_on_trk;
  2557. dcw = itcw_add_dcw(itcw, pfx_cmd, 0,
  2558. &pfxdata, sizeof(pfxdata), total_data_size);
  2559. return IS_ERR(dcw) ? PTR_ERR(dcw) : 0;
  2560. }
  2561. static struct dasd_ccw_req *dasd_eckd_build_cp_tpm_track(
  2562. struct dasd_device *startdev,
  2563. struct dasd_block *block,
  2564. struct request *req,
  2565. sector_t first_rec,
  2566. sector_t last_rec,
  2567. sector_t first_trk,
  2568. sector_t last_trk,
  2569. unsigned int first_offs,
  2570. unsigned int last_offs,
  2571. unsigned int blk_per_trk,
  2572. unsigned int blksize)
  2573. {
  2574. struct dasd_ccw_req *cqr;
  2575. struct req_iterator iter;
  2576. struct bio_vec *bv;
  2577. char *dst;
  2578. unsigned int trkcount, ctidaw;
  2579. unsigned char cmd;
  2580. struct dasd_device *basedev;
  2581. unsigned int tlf;
  2582. struct itcw *itcw;
  2583. struct tidaw *last_tidaw = NULL;
  2584. int itcw_op;
  2585. size_t itcw_size;
  2586. u8 tidaw_flags;
  2587. unsigned int seg_len, part_len, len_to_track_end;
  2588. unsigned char new_track;
  2589. sector_t recid, trkid;
  2590. unsigned int offs;
  2591. unsigned int count, count_to_trk_end;
  2592. basedev = block->base;
  2593. if (rq_data_dir(req) == READ) {
  2594. cmd = DASD_ECKD_CCW_READ_TRACK_DATA;
  2595. itcw_op = ITCW_OP_READ;
  2596. } else if (rq_data_dir(req) == WRITE) {
  2597. cmd = DASD_ECKD_CCW_WRITE_TRACK_DATA;
  2598. itcw_op = ITCW_OP_WRITE;
  2599. } else
  2600. return ERR_PTR(-EINVAL);
  2601. /* trackbased I/O needs address all memory via TIDAWs,
  2602. * not just for 64 bit addresses. This allows us to map
  2603. * each segment directly to one tidaw.
  2604. * In the case of write requests, additional tidaws may
  2605. * be needed when a segment crosses a track boundary.
  2606. */
  2607. trkcount = last_trk - first_trk + 1;
  2608. ctidaw = 0;
  2609. rq_for_each_segment(bv, req, iter) {
  2610. ++ctidaw;
  2611. }
  2612. if (rq_data_dir(req) == WRITE)
  2613. ctidaw += (last_trk - first_trk);
  2614. /* Allocate the ccw request. */
  2615. itcw_size = itcw_calc_size(0, ctidaw, 0);
  2616. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 0, itcw_size, startdev);
  2617. if (IS_ERR(cqr))
  2618. return cqr;
  2619. /* transfer length factor: how many bytes to read from the last track */
  2620. if (first_trk == last_trk)
  2621. tlf = last_offs - first_offs + 1;
  2622. else
  2623. tlf = last_offs + 1;
  2624. tlf *= blksize;
  2625. itcw = itcw_init(cqr->data, itcw_size, itcw_op, 0, ctidaw, 0);
  2626. if (IS_ERR(itcw)) {
  2627. dasd_sfree_request(cqr, startdev);
  2628. return ERR_PTR(-EINVAL);
  2629. }
  2630. cqr->cpaddr = itcw_get_tcw(itcw);
  2631. if (prepare_itcw(itcw, first_trk, last_trk,
  2632. cmd, basedev, startdev,
  2633. first_offs + 1,
  2634. trkcount, blksize,
  2635. (last_rec - first_rec + 1) * blksize,
  2636. tlf, blk_per_trk) == -EAGAIN) {
  2637. /* Clock not in sync and XRC is enabled.
  2638. * Try again later.
  2639. */
  2640. dasd_sfree_request(cqr, startdev);
  2641. return ERR_PTR(-EAGAIN);
  2642. }
  2643. len_to_track_end = 0;
  2644. /*
  2645. * A tidaw can address 4k of memory, but must not cross page boundaries
  2646. * We can let the block layer handle this by setting
  2647. * blk_queue_segment_boundary to page boundaries and
  2648. * blk_max_segment_size to page size when setting up the request queue.
  2649. * For write requests, a TIDAW must not cross track boundaries, because
  2650. * we have to set the CBC flag on the last tidaw for each track.
  2651. */
  2652. if (rq_data_dir(req) == WRITE) {
  2653. new_track = 1;
  2654. recid = first_rec;
  2655. rq_for_each_segment(bv, req, iter) {
  2656. dst = page_address(bv->bv_page) + bv->bv_offset;
  2657. seg_len = bv->bv_len;
  2658. while (seg_len) {
  2659. if (new_track) {
  2660. trkid = recid;
  2661. offs = sector_div(trkid, blk_per_trk);
  2662. count_to_trk_end = blk_per_trk - offs;
  2663. count = min((last_rec - recid + 1),
  2664. (sector_t)count_to_trk_end);
  2665. len_to_track_end = count * blksize;
  2666. recid += count;
  2667. new_track = 0;
  2668. }
  2669. part_len = min(seg_len, len_to_track_end);
  2670. seg_len -= part_len;
  2671. len_to_track_end -= part_len;
  2672. /* We need to end the tidaw at track end */
  2673. if (!len_to_track_end) {
  2674. new_track = 1;
  2675. tidaw_flags = TIDAW_FLAGS_INSERT_CBC;
  2676. } else
  2677. tidaw_flags = 0;
  2678. last_tidaw = itcw_add_tidaw(itcw, tidaw_flags,
  2679. dst, part_len);
  2680. if (IS_ERR(last_tidaw))
  2681. return ERR_PTR(-EINVAL);
  2682. dst += part_len;
  2683. }
  2684. }
  2685. } else {
  2686. rq_for_each_segment(bv, req, iter) {
  2687. dst = page_address(bv->bv_page) + bv->bv_offset;
  2688. last_tidaw = itcw_add_tidaw(itcw, 0x00,
  2689. dst, bv->bv_len);
  2690. if (IS_ERR(last_tidaw))
  2691. return ERR_PTR(-EINVAL);
  2692. }
  2693. }
  2694. last_tidaw->flags |= TIDAW_FLAGS_LAST;
  2695. last_tidaw->flags &= ~TIDAW_FLAGS_INSERT_CBC;
  2696. itcw_finalize(itcw);
  2697. if (blk_noretry_request(req) ||
  2698. block->base->features & DASD_FEATURE_FAILFAST)
  2699. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2700. cqr->cpmode = 1;
  2701. cqr->startdev = startdev;
  2702. cqr->memdev = startdev;
  2703. cqr->block = block;
  2704. cqr->expires = startdev->default_expires * HZ; /* default 5 minutes */
  2705. cqr->lpm = startdev->path_data.ppm;
  2706. cqr->retries = 256;
  2707. cqr->buildclk = get_clock();
  2708. cqr->status = DASD_CQR_FILLED;
  2709. return cqr;
  2710. }
  2711. static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
  2712. struct dasd_block *block,
  2713. struct request *req)
  2714. {
  2715. int cmdrtd, cmdwtd;
  2716. int use_prefix;
  2717. int fcx_multitrack;
  2718. struct dasd_eckd_private *private;
  2719. struct dasd_device *basedev;
  2720. sector_t first_rec, last_rec;
  2721. sector_t first_trk, last_trk;
  2722. unsigned int first_offs, last_offs;
  2723. unsigned int blk_per_trk, blksize;
  2724. int cdlspecial;
  2725. unsigned int data_size;
  2726. struct dasd_ccw_req *cqr;
  2727. basedev = block->base;
  2728. private = (struct dasd_eckd_private *) basedev->private;
  2729. /* Calculate number of blocks/records per track. */
  2730. blksize = block->bp_block;
  2731. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  2732. if (blk_per_trk == 0)
  2733. return ERR_PTR(-EINVAL);
  2734. /* Calculate record id of first and last block. */
  2735. first_rec = first_trk = blk_rq_pos(req) >> block->s2b_shift;
  2736. first_offs = sector_div(first_trk, blk_per_trk);
  2737. last_rec = last_trk =
  2738. (blk_rq_pos(req) + blk_rq_sectors(req) - 1) >> block->s2b_shift;
  2739. last_offs = sector_div(last_trk, blk_per_trk);
  2740. cdlspecial = (private->uses_cdl && first_rec < 2*blk_per_trk);
  2741. fcx_multitrack = private->features.feature[40] & 0x20;
  2742. data_size = blk_rq_bytes(req);
  2743. /* tpm write request add CBC data on each track boundary */
  2744. if (rq_data_dir(req) == WRITE)
  2745. data_size += (last_trk - first_trk) * 4;
  2746. /* is read track data and write track data in command mode supported? */
  2747. cmdrtd = private->features.feature[9] & 0x20;
  2748. cmdwtd = private->features.feature[12] & 0x40;
  2749. use_prefix = private->features.feature[8] & 0x01;
  2750. cqr = NULL;
  2751. if (cdlspecial || dasd_page_cache) {
  2752. /* do nothing, just fall through to the cmd mode single case */
  2753. } else if ((data_size <= private->fcx_max_data)
  2754. && (fcx_multitrack || (first_trk == last_trk))) {
  2755. cqr = dasd_eckd_build_cp_tpm_track(startdev, block, req,
  2756. first_rec, last_rec,
  2757. first_trk, last_trk,
  2758. first_offs, last_offs,
  2759. blk_per_trk, blksize);
  2760. if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
  2761. (PTR_ERR(cqr) != -ENOMEM))
  2762. cqr = NULL;
  2763. } else if (use_prefix &&
  2764. (((rq_data_dir(req) == READ) && cmdrtd) ||
  2765. ((rq_data_dir(req) == WRITE) && cmdwtd))) {
  2766. cqr = dasd_eckd_build_cp_cmd_track(startdev, block, req,
  2767. first_rec, last_rec,
  2768. first_trk, last_trk,
  2769. first_offs, last_offs,
  2770. blk_per_trk, blksize);
  2771. if (IS_ERR(cqr) && (PTR_ERR(cqr) != -EAGAIN) &&
  2772. (PTR_ERR(cqr) != -ENOMEM))
  2773. cqr = NULL;
  2774. }
  2775. if (!cqr)
  2776. cqr = dasd_eckd_build_cp_cmd_single(startdev, block, req,
  2777. first_rec, last_rec,
  2778. first_trk, last_trk,
  2779. first_offs, last_offs,
  2780. blk_per_trk, blksize);
  2781. return cqr;
  2782. }
  2783. static struct dasd_ccw_req *dasd_raw_build_cp(struct dasd_device *startdev,
  2784. struct dasd_block *block,
  2785. struct request *req)
  2786. {
  2787. unsigned long *idaws;
  2788. struct dasd_device *basedev;
  2789. struct dasd_ccw_req *cqr;
  2790. struct ccw1 *ccw;
  2791. struct req_iterator iter;
  2792. struct bio_vec *bv;
  2793. char *dst;
  2794. unsigned char cmd;
  2795. unsigned int trkcount;
  2796. unsigned int seg_len, len_to_track_end;
  2797. unsigned int first_offs;
  2798. unsigned int cidaw, cplength, datasize;
  2799. sector_t first_trk, last_trk;
  2800. unsigned int pfx_datasize;
  2801. /*
  2802. * raw track access needs to be mutiple of 64k and on 64k boundary
  2803. */
  2804. if ((blk_rq_pos(req) % DASD_RAW_SECTORS_PER_TRACK) != 0) {
  2805. cqr = ERR_PTR(-EINVAL);
  2806. goto out;
  2807. }
  2808. if (((blk_rq_pos(req) + blk_rq_sectors(req)) %
  2809. DASD_RAW_SECTORS_PER_TRACK) != 0) {
  2810. cqr = ERR_PTR(-EINVAL);
  2811. goto out;
  2812. }
  2813. first_trk = blk_rq_pos(req) / DASD_RAW_SECTORS_PER_TRACK;
  2814. last_trk = (blk_rq_pos(req) + blk_rq_sectors(req) - 1) /
  2815. DASD_RAW_SECTORS_PER_TRACK;
  2816. trkcount = last_trk - first_trk + 1;
  2817. first_offs = 0;
  2818. basedev = block->base;
  2819. if (rq_data_dir(req) == READ)
  2820. cmd = DASD_ECKD_CCW_READ_TRACK;
  2821. else if (rq_data_dir(req) == WRITE)
  2822. cmd = DASD_ECKD_CCW_WRITE_FULL_TRACK;
  2823. else {
  2824. cqr = ERR_PTR(-EINVAL);
  2825. goto out;
  2826. }
  2827. /*
  2828. * Raw track based I/O needs IDAWs for each page,
  2829. * and not just for 64 bit addresses.
  2830. */
  2831. cidaw = trkcount * DASD_RAW_BLOCK_PER_TRACK;
  2832. /* 1x prefix + one read/write ccw per track */
  2833. cplength = 1 + trkcount;
  2834. /*
  2835. * struct PFX_eckd_data has up to 2 byte as extended parameter
  2836. * this is needed for write full track and has to be mentioned
  2837. * separately
  2838. * add 8 instead of 2 to keep 8 byte boundary
  2839. */
  2840. pfx_datasize = sizeof(struct PFX_eckd_data) + 8;
  2841. datasize = pfx_datasize + cidaw * sizeof(unsigned long long);
  2842. /* Allocate the ccw request. */
  2843. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, cplength,
  2844. datasize, startdev);
  2845. if (IS_ERR(cqr))
  2846. goto out;
  2847. ccw = cqr->cpaddr;
  2848. if (prefix_LRE(ccw++, cqr->data, first_trk, last_trk, cmd,
  2849. basedev, startdev, 1 /* format */, first_offs + 1,
  2850. trkcount, 0, 0) == -EAGAIN) {
  2851. /* Clock not in sync and XRC is enabled.
  2852. * Try again later.
  2853. */
  2854. dasd_sfree_request(cqr, startdev);
  2855. cqr = ERR_PTR(-EAGAIN);
  2856. goto out;
  2857. }
  2858. idaws = (unsigned long *)(cqr->data + pfx_datasize);
  2859. len_to_track_end = 0;
  2860. rq_for_each_segment(bv, req, iter) {
  2861. dst = page_address(bv->bv_page) + bv->bv_offset;
  2862. seg_len = bv->bv_len;
  2863. if (!len_to_track_end) {
  2864. ccw[-1].flags |= CCW_FLAG_CC;
  2865. ccw->cmd_code = cmd;
  2866. /* maximum 3390 track size */
  2867. ccw->count = 57326;
  2868. /* 64k map to one track */
  2869. len_to_track_end = 65536;
  2870. ccw->cda = (__u32)(addr_t)idaws;
  2871. ccw->flags |= CCW_FLAG_IDA;
  2872. ccw->flags |= CCW_FLAG_SLI;
  2873. ccw++;
  2874. }
  2875. len_to_track_end -= seg_len;
  2876. idaws = idal_create_words(idaws, dst, seg_len);
  2877. }
  2878. if (blk_noretry_request(req) ||
  2879. block->base->features & DASD_FEATURE_FAILFAST)
  2880. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  2881. cqr->startdev = startdev;
  2882. cqr->memdev = startdev;
  2883. cqr->block = block;
  2884. cqr->expires = startdev->default_expires * HZ;
  2885. cqr->lpm = startdev->path_data.ppm;
  2886. cqr->retries = 256;
  2887. cqr->buildclk = get_clock();
  2888. cqr->status = DASD_CQR_FILLED;
  2889. if (IS_ERR(cqr) && PTR_ERR(cqr) != -EAGAIN)
  2890. cqr = NULL;
  2891. out:
  2892. return cqr;
  2893. }
  2894. static int
  2895. dasd_eckd_free_cp(struct dasd_ccw_req *cqr, struct request *req)
  2896. {
  2897. struct dasd_eckd_private *private;
  2898. struct ccw1 *ccw;
  2899. struct req_iterator iter;
  2900. struct bio_vec *bv;
  2901. char *dst, *cda;
  2902. unsigned int blksize, blk_per_trk, off;
  2903. sector_t recid;
  2904. int status;
  2905. if (!dasd_page_cache)
  2906. goto out;
  2907. private = (struct dasd_eckd_private *) cqr->block->base->private;
  2908. blksize = cqr->block->bp_block;
  2909. blk_per_trk = recs_per_track(&private->rdc_data, 0, blksize);
  2910. recid = blk_rq_pos(req) >> cqr->block->s2b_shift;
  2911. ccw = cqr->cpaddr;
  2912. /* Skip over define extent & locate record. */
  2913. ccw++;
  2914. if (private->uses_cdl == 0 || recid > 2*blk_per_trk)
  2915. ccw++;
  2916. rq_for_each_segment(bv, req, iter) {
  2917. dst = page_address(bv->bv_page) + bv->bv_offset;
  2918. for (off = 0; off < bv->bv_len; off += blksize) {
  2919. /* Skip locate record. */
  2920. if (private->uses_cdl && recid <= 2*blk_per_trk)
  2921. ccw++;
  2922. if (dst) {
  2923. if (ccw->flags & CCW_FLAG_IDA)
  2924. cda = *((char **)((addr_t) ccw->cda));
  2925. else
  2926. cda = (char *)((addr_t) ccw->cda);
  2927. if (dst != cda) {
  2928. if (rq_data_dir(req) == READ)
  2929. memcpy(dst, cda, bv->bv_len);
  2930. kmem_cache_free(dasd_page_cache,
  2931. (void *)((addr_t)cda & PAGE_MASK));
  2932. }
  2933. dst = NULL;
  2934. }
  2935. ccw++;
  2936. recid++;
  2937. }
  2938. }
  2939. out:
  2940. status = cqr->status == DASD_CQR_DONE;
  2941. dasd_sfree_request(cqr, cqr->memdev);
  2942. return status;
  2943. }
  2944. /*
  2945. * Modify ccw/tcw in cqr so it can be started on a base device.
  2946. *
  2947. * Note that this is not enough to restart the cqr!
  2948. * Either reset cqr->startdev as well (summary unit check handling)
  2949. * or restart via separate cqr (as in ERP handling).
  2950. */
  2951. void dasd_eckd_reset_ccw_to_base_io(struct dasd_ccw_req *cqr)
  2952. {
  2953. struct ccw1 *ccw;
  2954. struct PFX_eckd_data *pfxdata;
  2955. struct tcw *tcw;
  2956. struct tccb *tccb;
  2957. struct dcw *dcw;
  2958. if (cqr->cpmode == 1) {
  2959. tcw = cqr->cpaddr;
  2960. tccb = tcw_get_tccb(tcw);
  2961. dcw = (struct dcw *)&tccb->tca[0];
  2962. pfxdata = (struct PFX_eckd_data *)&dcw->cd[0];
  2963. pfxdata->validity.verify_base = 0;
  2964. pfxdata->validity.hyper_pav = 0;
  2965. } else {
  2966. ccw = cqr->cpaddr;
  2967. pfxdata = cqr->data;
  2968. if (ccw->cmd_code == DASD_ECKD_CCW_PFX) {
  2969. pfxdata->validity.verify_base = 0;
  2970. pfxdata->validity.hyper_pav = 0;
  2971. }
  2972. }
  2973. }
  2974. #define DASD_ECKD_CHANQ_MAX_SIZE 4
  2975. static struct dasd_ccw_req *dasd_eckd_build_alias_cp(struct dasd_device *base,
  2976. struct dasd_block *block,
  2977. struct request *req)
  2978. {
  2979. struct dasd_eckd_private *private;
  2980. struct dasd_device *startdev;
  2981. unsigned long flags;
  2982. struct dasd_ccw_req *cqr;
  2983. startdev = dasd_alias_get_start_dev(base);
  2984. if (!startdev)
  2985. startdev = base;
  2986. private = (struct dasd_eckd_private *) startdev->private;
  2987. if (private->count >= DASD_ECKD_CHANQ_MAX_SIZE)
  2988. return ERR_PTR(-EBUSY);
  2989. spin_lock_irqsave(get_ccwdev_lock(startdev->cdev), flags);
  2990. private->count++;
  2991. if ((base->features & DASD_FEATURE_USERAW))
  2992. cqr = dasd_raw_build_cp(startdev, block, req);
  2993. else
  2994. cqr = dasd_eckd_build_cp(startdev, block, req);
  2995. if (IS_ERR(cqr))
  2996. private->count--;
  2997. spin_unlock_irqrestore(get_ccwdev_lock(startdev->cdev), flags);
  2998. return cqr;
  2999. }
  3000. static int dasd_eckd_free_alias_cp(struct dasd_ccw_req *cqr,
  3001. struct request *req)
  3002. {
  3003. struct dasd_eckd_private *private;
  3004. unsigned long flags;
  3005. spin_lock_irqsave(get_ccwdev_lock(cqr->memdev->cdev), flags);
  3006. private = (struct dasd_eckd_private *) cqr->memdev->private;
  3007. private->count--;
  3008. spin_unlock_irqrestore(get_ccwdev_lock(cqr->memdev->cdev), flags);
  3009. return dasd_eckd_free_cp(cqr, req);
  3010. }
  3011. static int
  3012. dasd_eckd_fill_info(struct dasd_device * device,
  3013. struct dasd_information2_t * info)
  3014. {
  3015. struct dasd_eckd_private *private;
  3016. private = (struct dasd_eckd_private *) device->private;
  3017. info->label_block = 2;
  3018. info->FBA_layout = private->uses_cdl ? 0 : 1;
  3019. info->format = private->uses_cdl ? DASD_FORMAT_CDL : DASD_FORMAT_LDL;
  3020. info->characteristics_size = sizeof(struct dasd_eckd_characteristics);
  3021. memcpy(info->characteristics, &private->rdc_data,
  3022. sizeof(struct dasd_eckd_characteristics));
  3023. info->confdata_size = min((unsigned long)private->conf_len,
  3024. sizeof(info->configuration_data));
  3025. memcpy(info->configuration_data, private->conf_data,
  3026. info->confdata_size);
  3027. return 0;
  3028. }
  3029. /*
  3030. * SECTION: ioctl functions for eckd devices.
  3031. */
  3032. /*
  3033. * Release device ioctl.
  3034. * Buils a channel programm to releases a prior reserved
  3035. * (see dasd_eckd_reserve) device.
  3036. */
  3037. static int
  3038. dasd_eckd_release(struct dasd_device *device)
  3039. {
  3040. struct dasd_ccw_req *cqr;
  3041. int rc;
  3042. struct ccw1 *ccw;
  3043. int useglobal;
  3044. if (!capable(CAP_SYS_ADMIN))
  3045. return -EACCES;
  3046. useglobal = 0;
  3047. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3048. if (IS_ERR(cqr)) {
  3049. mutex_lock(&dasd_reserve_mutex);
  3050. useglobal = 1;
  3051. cqr = &dasd_reserve_req->cqr;
  3052. memset(cqr, 0, sizeof(*cqr));
  3053. memset(&dasd_reserve_req->ccw, 0,
  3054. sizeof(dasd_reserve_req->ccw));
  3055. cqr->cpaddr = &dasd_reserve_req->ccw;
  3056. cqr->data = &dasd_reserve_req->data;
  3057. cqr->magic = DASD_ECKD_MAGIC;
  3058. }
  3059. ccw = cqr->cpaddr;
  3060. ccw->cmd_code = DASD_ECKD_CCW_RELEASE;
  3061. ccw->flags |= CCW_FLAG_SLI;
  3062. ccw->count = 32;
  3063. ccw->cda = (__u32)(addr_t) cqr->data;
  3064. cqr->startdev = device;
  3065. cqr->memdev = device;
  3066. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3067. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3068. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3069. cqr->expires = 2 * HZ;
  3070. cqr->buildclk = get_clock();
  3071. cqr->status = DASD_CQR_FILLED;
  3072. rc = dasd_sleep_on_immediatly(cqr);
  3073. if (!rc)
  3074. clear_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3075. if (useglobal)
  3076. mutex_unlock(&dasd_reserve_mutex);
  3077. else
  3078. dasd_sfree_request(cqr, cqr->memdev);
  3079. return rc;
  3080. }
  3081. /*
  3082. * Reserve device ioctl.
  3083. * Options are set to 'synchronous wait for interrupt' and
  3084. * 'timeout the request'. This leads to a terminate IO if
  3085. * the interrupt is outstanding for a certain time.
  3086. */
  3087. static int
  3088. dasd_eckd_reserve(struct dasd_device *device)
  3089. {
  3090. struct dasd_ccw_req *cqr;
  3091. int rc;
  3092. struct ccw1 *ccw;
  3093. int useglobal;
  3094. if (!capable(CAP_SYS_ADMIN))
  3095. return -EACCES;
  3096. useglobal = 0;
  3097. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3098. if (IS_ERR(cqr)) {
  3099. mutex_lock(&dasd_reserve_mutex);
  3100. useglobal = 1;
  3101. cqr = &dasd_reserve_req->cqr;
  3102. memset(cqr, 0, sizeof(*cqr));
  3103. memset(&dasd_reserve_req->ccw, 0,
  3104. sizeof(dasd_reserve_req->ccw));
  3105. cqr->cpaddr = &dasd_reserve_req->ccw;
  3106. cqr->data = &dasd_reserve_req->data;
  3107. cqr->magic = DASD_ECKD_MAGIC;
  3108. }
  3109. ccw = cqr->cpaddr;
  3110. ccw->cmd_code = DASD_ECKD_CCW_RESERVE;
  3111. ccw->flags |= CCW_FLAG_SLI;
  3112. ccw->count = 32;
  3113. ccw->cda = (__u32)(addr_t) cqr->data;
  3114. cqr->startdev = device;
  3115. cqr->memdev = device;
  3116. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3117. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3118. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3119. cqr->expires = 2 * HZ;
  3120. cqr->buildclk = get_clock();
  3121. cqr->status = DASD_CQR_FILLED;
  3122. rc = dasd_sleep_on_immediatly(cqr);
  3123. if (!rc)
  3124. set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3125. if (useglobal)
  3126. mutex_unlock(&dasd_reserve_mutex);
  3127. else
  3128. dasd_sfree_request(cqr, cqr->memdev);
  3129. return rc;
  3130. }
  3131. /*
  3132. * Steal lock ioctl - unconditional reserve device.
  3133. * Buils a channel programm to break a device's reservation.
  3134. * (unconditional reserve)
  3135. */
  3136. static int
  3137. dasd_eckd_steal_lock(struct dasd_device *device)
  3138. {
  3139. struct dasd_ccw_req *cqr;
  3140. int rc;
  3141. struct ccw1 *ccw;
  3142. int useglobal;
  3143. if (!capable(CAP_SYS_ADMIN))
  3144. return -EACCES;
  3145. useglobal = 0;
  3146. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1, 32, device);
  3147. if (IS_ERR(cqr)) {
  3148. mutex_lock(&dasd_reserve_mutex);
  3149. useglobal = 1;
  3150. cqr = &dasd_reserve_req->cqr;
  3151. memset(cqr, 0, sizeof(*cqr));
  3152. memset(&dasd_reserve_req->ccw, 0,
  3153. sizeof(dasd_reserve_req->ccw));
  3154. cqr->cpaddr = &dasd_reserve_req->ccw;
  3155. cqr->data = &dasd_reserve_req->data;
  3156. cqr->magic = DASD_ECKD_MAGIC;
  3157. }
  3158. ccw = cqr->cpaddr;
  3159. ccw->cmd_code = DASD_ECKD_CCW_SLCK;
  3160. ccw->flags |= CCW_FLAG_SLI;
  3161. ccw->count = 32;
  3162. ccw->cda = (__u32)(addr_t) cqr->data;
  3163. cqr->startdev = device;
  3164. cqr->memdev = device;
  3165. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3166. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3167. cqr->retries = 2; /* set retry counter to enable basic ERP */
  3168. cqr->expires = 2 * HZ;
  3169. cqr->buildclk = get_clock();
  3170. cqr->status = DASD_CQR_FILLED;
  3171. rc = dasd_sleep_on_immediatly(cqr);
  3172. if (!rc)
  3173. set_bit(DASD_FLAG_IS_RESERVED, &device->flags);
  3174. if (useglobal)
  3175. mutex_unlock(&dasd_reserve_mutex);
  3176. else
  3177. dasd_sfree_request(cqr, cqr->memdev);
  3178. return rc;
  3179. }
  3180. /*
  3181. * SNID - Sense Path Group ID
  3182. * This ioctl may be used in situations where I/O is stalled due to
  3183. * a reserve, so if the normal dasd_smalloc_request fails, we use the
  3184. * preallocated dasd_reserve_req.
  3185. */
  3186. static int dasd_eckd_snid(struct dasd_device *device,
  3187. void __user *argp)
  3188. {
  3189. struct dasd_ccw_req *cqr;
  3190. int rc;
  3191. struct ccw1 *ccw;
  3192. int useglobal;
  3193. struct dasd_snid_ioctl_data usrparm;
  3194. if (!capable(CAP_SYS_ADMIN))
  3195. return -EACCES;
  3196. if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
  3197. return -EFAULT;
  3198. useglobal = 0;
  3199. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1,
  3200. sizeof(struct dasd_snid_data), device);
  3201. if (IS_ERR(cqr)) {
  3202. mutex_lock(&dasd_reserve_mutex);
  3203. useglobal = 1;
  3204. cqr = &dasd_reserve_req->cqr;
  3205. memset(cqr, 0, sizeof(*cqr));
  3206. memset(&dasd_reserve_req->ccw, 0,
  3207. sizeof(dasd_reserve_req->ccw));
  3208. cqr->cpaddr = &dasd_reserve_req->ccw;
  3209. cqr->data = &dasd_reserve_req->data;
  3210. cqr->magic = DASD_ECKD_MAGIC;
  3211. }
  3212. ccw = cqr->cpaddr;
  3213. ccw->cmd_code = DASD_ECKD_CCW_SNID;
  3214. ccw->flags |= CCW_FLAG_SLI;
  3215. ccw->count = 12;
  3216. ccw->cda = (__u32)(addr_t) cqr->data;
  3217. cqr->startdev = device;
  3218. cqr->memdev = device;
  3219. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3220. set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
  3221. set_bit(DASD_CQR_ALLOW_SLOCK, &cqr->flags);
  3222. cqr->retries = 5;
  3223. cqr->expires = 10 * HZ;
  3224. cqr->buildclk = get_clock();
  3225. cqr->status = DASD_CQR_FILLED;
  3226. cqr->lpm = usrparm.path_mask;
  3227. rc = dasd_sleep_on_immediatly(cqr);
  3228. /* verify that I/O processing didn't modify the path mask */
  3229. if (!rc && usrparm.path_mask && (cqr->lpm != usrparm.path_mask))
  3230. rc = -EIO;
  3231. if (!rc) {
  3232. usrparm.data = *((struct dasd_snid_data *)cqr->data);
  3233. if (copy_to_user(argp, &usrparm, sizeof(usrparm)))
  3234. rc = -EFAULT;
  3235. }
  3236. if (useglobal)
  3237. mutex_unlock(&dasd_reserve_mutex);
  3238. else
  3239. dasd_sfree_request(cqr, cqr->memdev);
  3240. return rc;
  3241. }
  3242. /*
  3243. * Read performance statistics
  3244. */
  3245. static int
  3246. dasd_eckd_performance(struct dasd_device *device, void __user *argp)
  3247. {
  3248. struct dasd_psf_prssd_data *prssdp;
  3249. struct dasd_rssd_perf_stats_t *stats;
  3250. struct dasd_ccw_req *cqr;
  3251. struct ccw1 *ccw;
  3252. int rc;
  3253. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 1 /* PSF */ + 1 /* RSSD */,
  3254. (sizeof(struct dasd_psf_prssd_data) +
  3255. sizeof(struct dasd_rssd_perf_stats_t)),
  3256. device);
  3257. if (IS_ERR(cqr)) {
  3258. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3259. "Could not allocate initialization request");
  3260. return PTR_ERR(cqr);
  3261. }
  3262. cqr->startdev = device;
  3263. cqr->memdev = device;
  3264. cqr->retries = 0;
  3265. clear_bit(DASD_CQR_FLAGS_USE_ERP, &cqr->flags);
  3266. cqr->expires = 10 * HZ;
  3267. /* Prepare for Read Subsystem Data */
  3268. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  3269. memset(prssdp, 0, sizeof(struct dasd_psf_prssd_data));
  3270. prssdp->order = PSF_ORDER_PRSSD;
  3271. prssdp->suborder = 0x01; /* Performance Statistics */
  3272. prssdp->varies[1] = 0x01; /* Perf Statistics for the Subsystem */
  3273. ccw = cqr->cpaddr;
  3274. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  3275. ccw->count = sizeof(struct dasd_psf_prssd_data);
  3276. ccw->flags |= CCW_FLAG_CC;
  3277. ccw->cda = (__u32)(addr_t) prssdp;
  3278. /* Read Subsystem Data - Performance Statistics */
  3279. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  3280. memset(stats, 0, sizeof(struct dasd_rssd_perf_stats_t));
  3281. ccw++;
  3282. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  3283. ccw->count = sizeof(struct dasd_rssd_perf_stats_t);
  3284. ccw->cda = (__u32)(addr_t) stats;
  3285. cqr->buildclk = get_clock();
  3286. cqr->status = DASD_CQR_FILLED;
  3287. rc = dasd_sleep_on(cqr);
  3288. if (rc == 0) {
  3289. prssdp = (struct dasd_psf_prssd_data *) cqr->data;
  3290. stats = (struct dasd_rssd_perf_stats_t *) (prssdp + 1);
  3291. if (copy_to_user(argp, stats,
  3292. sizeof(struct dasd_rssd_perf_stats_t)))
  3293. rc = -EFAULT;
  3294. }
  3295. dasd_sfree_request(cqr, cqr->memdev);
  3296. return rc;
  3297. }
  3298. /*
  3299. * Get attributes (cache operations)
  3300. * Returnes the cache attributes used in Define Extend (DE).
  3301. */
  3302. static int
  3303. dasd_eckd_get_attrib(struct dasd_device *device, void __user *argp)
  3304. {
  3305. struct dasd_eckd_private *private =
  3306. (struct dasd_eckd_private *)device->private;
  3307. struct attrib_data_t attrib = private->attrib;
  3308. int rc;
  3309. if (!capable(CAP_SYS_ADMIN))
  3310. return -EACCES;
  3311. if (!argp)
  3312. return -EINVAL;
  3313. rc = 0;
  3314. if (copy_to_user(argp, (long *) &attrib,
  3315. sizeof(struct attrib_data_t)))
  3316. rc = -EFAULT;
  3317. return rc;
  3318. }
  3319. /*
  3320. * Set attributes (cache operations)
  3321. * Stores the attributes for cache operation to be used in Define Extend (DE).
  3322. */
  3323. static int
  3324. dasd_eckd_set_attrib(struct dasd_device *device, void __user *argp)
  3325. {
  3326. struct dasd_eckd_private *private =
  3327. (struct dasd_eckd_private *)device->private;
  3328. struct attrib_data_t attrib;
  3329. if (!capable(CAP_SYS_ADMIN))
  3330. return -EACCES;
  3331. if (!argp)
  3332. return -EINVAL;
  3333. if (copy_from_user(&attrib, argp, sizeof(struct attrib_data_t)))
  3334. return -EFAULT;
  3335. private->attrib = attrib;
  3336. dev_info(&device->cdev->dev,
  3337. "The DASD cache mode was set to %x (%i cylinder prestage)\n",
  3338. private->attrib.operation, private->attrib.nr_cyl);
  3339. return 0;
  3340. }
  3341. /*
  3342. * Issue syscall I/O to EMC Symmetrix array.
  3343. * CCWs are PSF and RSSD
  3344. */
  3345. static int dasd_symm_io(struct dasd_device *device, void __user *argp)
  3346. {
  3347. struct dasd_symmio_parms usrparm;
  3348. char *psf_data, *rssd_result;
  3349. struct dasd_ccw_req *cqr;
  3350. struct ccw1 *ccw;
  3351. char psf0, psf1;
  3352. int rc;
  3353. if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
  3354. return -EACCES;
  3355. psf0 = psf1 = 0;
  3356. /* Copy parms from caller */
  3357. rc = -EFAULT;
  3358. if (copy_from_user(&usrparm, argp, sizeof(usrparm)))
  3359. goto out;
  3360. if (is_compat_task() || sizeof(long) == 4) {
  3361. /* Make sure pointers are sane even on 31 bit. */
  3362. rc = -EINVAL;
  3363. if ((usrparm.psf_data >> 32) != 0)
  3364. goto out;
  3365. if ((usrparm.rssd_result >> 32) != 0)
  3366. goto out;
  3367. usrparm.psf_data &= 0x7fffffffULL;
  3368. usrparm.rssd_result &= 0x7fffffffULL;
  3369. }
  3370. /* alloc I/O data area */
  3371. psf_data = kzalloc(usrparm.psf_data_len, GFP_KERNEL | GFP_DMA);
  3372. rssd_result = kzalloc(usrparm.rssd_result_len, GFP_KERNEL | GFP_DMA);
  3373. if (!psf_data || !rssd_result) {
  3374. rc = -ENOMEM;
  3375. goto out_free;
  3376. }
  3377. /* get syscall header from user space */
  3378. rc = -EFAULT;
  3379. if (copy_from_user(psf_data,
  3380. (void __user *)(unsigned long) usrparm.psf_data,
  3381. usrparm.psf_data_len))
  3382. goto out_free;
  3383. psf0 = psf_data[0];
  3384. psf1 = psf_data[1];
  3385. /* setup CCWs for PSF + RSSD */
  3386. cqr = dasd_smalloc_request(DASD_ECKD_MAGIC, 2 , 0, device);
  3387. if (IS_ERR(cqr)) {
  3388. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3389. "Could not allocate initialization request");
  3390. rc = PTR_ERR(cqr);
  3391. goto out_free;
  3392. }
  3393. cqr->startdev = device;
  3394. cqr->memdev = device;
  3395. cqr->retries = 3;
  3396. cqr->expires = 10 * HZ;
  3397. cqr->buildclk = get_clock();
  3398. cqr->status = DASD_CQR_FILLED;
  3399. /* Build the ccws */
  3400. ccw = cqr->cpaddr;
  3401. /* PSF ccw */
  3402. ccw->cmd_code = DASD_ECKD_CCW_PSF;
  3403. ccw->count = usrparm.psf_data_len;
  3404. ccw->flags |= CCW_FLAG_CC;
  3405. ccw->cda = (__u32)(addr_t) psf_data;
  3406. ccw++;
  3407. /* RSSD ccw */
  3408. ccw->cmd_code = DASD_ECKD_CCW_RSSD;
  3409. ccw->count = usrparm.rssd_result_len;
  3410. ccw->flags = CCW_FLAG_SLI ;
  3411. ccw->cda = (__u32)(addr_t) rssd_result;
  3412. rc = dasd_sleep_on(cqr);
  3413. if (rc)
  3414. goto out_sfree;
  3415. rc = -EFAULT;
  3416. if (copy_to_user((void __user *)(unsigned long) usrparm.rssd_result,
  3417. rssd_result, usrparm.rssd_result_len))
  3418. goto out_sfree;
  3419. rc = 0;
  3420. out_sfree:
  3421. dasd_sfree_request(cqr, cqr->memdev);
  3422. out_free:
  3423. kfree(rssd_result);
  3424. kfree(psf_data);
  3425. out:
  3426. DBF_DEV_EVENT(DBF_WARNING, device,
  3427. "Symmetrix ioctl (0x%02x 0x%02x): rc=%d",
  3428. (int) psf0, (int) psf1, rc);
  3429. return rc;
  3430. }
  3431. static int
  3432. dasd_eckd_ioctl(struct dasd_block *block, unsigned int cmd, void __user *argp)
  3433. {
  3434. struct dasd_device *device = block->base;
  3435. switch (cmd) {
  3436. case BIODASDGATTR:
  3437. return dasd_eckd_get_attrib(device, argp);
  3438. case BIODASDSATTR:
  3439. return dasd_eckd_set_attrib(device, argp);
  3440. case BIODASDPSRD:
  3441. return dasd_eckd_performance(device, argp);
  3442. case BIODASDRLSE:
  3443. return dasd_eckd_release(device);
  3444. case BIODASDRSRV:
  3445. return dasd_eckd_reserve(device);
  3446. case BIODASDSLCK:
  3447. return dasd_eckd_steal_lock(device);
  3448. case BIODASDSNID:
  3449. return dasd_eckd_snid(device, argp);
  3450. case BIODASDSYMMIO:
  3451. return dasd_symm_io(device, argp);
  3452. default:
  3453. return -ENOIOCTLCMD;
  3454. }
  3455. }
  3456. /*
  3457. * Dump the range of CCWs into 'page' buffer
  3458. * and return number of printed chars.
  3459. */
  3460. static int
  3461. dasd_eckd_dump_ccw_range(struct ccw1 *from, struct ccw1 *to, char *page)
  3462. {
  3463. int len, count;
  3464. char *datap;
  3465. len = 0;
  3466. while (from <= to) {
  3467. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3468. " CCW %p: %08X %08X DAT:",
  3469. from, ((int *) from)[0], ((int *) from)[1]);
  3470. /* get pointer to data (consider IDALs) */
  3471. if (from->flags & CCW_FLAG_IDA)
  3472. datap = (char *) *((addr_t *) (addr_t) from->cda);
  3473. else
  3474. datap = (char *) ((addr_t) from->cda);
  3475. /* dump data (max 32 bytes) */
  3476. for (count = 0; count < from->count && count < 32; count++) {
  3477. if (count % 8 == 0) len += sprintf(page + len, " ");
  3478. if (count % 4 == 0) len += sprintf(page + len, " ");
  3479. len += sprintf(page + len, "%02x", datap[count]);
  3480. }
  3481. len += sprintf(page + len, "\n");
  3482. from++;
  3483. }
  3484. return len;
  3485. }
  3486. static void
  3487. dasd_eckd_dump_sense_dbf(struct dasd_device *device, struct irb *irb,
  3488. char *reason)
  3489. {
  3490. u64 *sense;
  3491. u64 *stat;
  3492. sense = (u64 *) dasd_get_sense(irb);
  3493. stat = (u64 *) &irb->scsw;
  3494. if (sense) {
  3495. DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : "
  3496. "%016llx %016llx %016llx %016llx",
  3497. reason, *stat, *((u32 *) (stat + 1)),
  3498. sense[0], sense[1], sense[2], sense[3]);
  3499. } else {
  3500. DBF_DEV_EVENT(DBF_EMERG, device, "%s: %016llx %08x : %s",
  3501. reason, *stat, *((u32 *) (stat + 1)),
  3502. "NO VALID SENSE");
  3503. }
  3504. }
  3505. /*
  3506. * Print sense data and related channel program.
  3507. * Parts are printed because printk buffer is only 1024 bytes.
  3508. */
  3509. static void dasd_eckd_dump_sense_ccw(struct dasd_device *device,
  3510. struct dasd_ccw_req *req, struct irb *irb)
  3511. {
  3512. char *page;
  3513. struct ccw1 *first, *last, *fail, *from, *to;
  3514. int len, sl, sct;
  3515. page = (char *) get_zeroed_page(GFP_ATOMIC);
  3516. if (page == NULL) {
  3517. DBF_DEV_EVENT(DBF_WARNING, device, "%s",
  3518. "No memory to dump sense data\n");
  3519. return;
  3520. }
  3521. /* dump the sense data */
  3522. len = sprintf(page, KERN_ERR PRINTK_HEADER
  3523. " I/O status report for device %s:\n",
  3524. dev_name(&device->cdev->dev));
  3525. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3526. " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
  3527. "CS:%02X RC:%d\n",
  3528. req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
  3529. scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
  3530. scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
  3531. req ? req->intrc : 0);
  3532. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3533. " device %s: Failing CCW: %p\n",
  3534. dev_name(&device->cdev->dev),
  3535. (void *) (addr_t) irb->scsw.cmd.cpa);
  3536. if (irb->esw.esw0.erw.cons) {
  3537. for (sl = 0; sl < 4; sl++) {
  3538. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3539. " Sense(hex) %2d-%2d:",
  3540. (8 * sl), ((8 * sl) + 7));
  3541. for (sct = 0; sct < 8; sct++) {
  3542. len += sprintf(page + len, " %02x",
  3543. irb->ecw[8 * sl + sct]);
  3544. }
  3545. len += sprintf(page + len, "\n");
  3546. }
  3547. if (irb->ecw[27] & DASD_SENSE_BIT_0) {
  3548. /* 24 Byte Sense Data */
  3549. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3550. " 24 Byte: %x MSG %x, "
  3551. "%s MSGb to SYSOP\n",
  3552. irb->ecw[7] >> 4, irb->ecw[7] & 0x0f,
  3553. irb->ecw[1] & 0x10 ? "" : "no");
  3554. } else {
  3555. /* 32 Byte Sense Data */
  3556. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3557. " 32 Byte: Format: %x "
  3558. "Exception class %x\n",
  3559. irb->ecw[6] & 0x0f, irb->ecw[22] >> 4);
  3560. }
  3561. } else {
  3562. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3563. " SORRY - NO VALID SENSE AVAILABLE\n");
  3564. }
  3565. printk("%s", page);
  3566. if (req) {
  3567. /* req == NULL for unsolicited interrupts */
  3568. /* dump the Channel Program (max 140 Bytes per line) */
  3569. /* Count CCW and print first CCWs (maximum 1024 % 140 = 7) */
  3570. first = req->cpaddr;
  3571. for (last = first; last->flags & (CCW_FLAG_CC | CCW_FLAG_DC); last++);
  3572. to = min(first + 6, last);
  3573. len = sprintf(page, KERN_ERR PRINTK_HEADER
  3574. " Related CP in req: %p\n", req);
  3575. dasd_eckd_dump_ccw_range(first, to, page + len);
  3576. printk("%s", page);
  3577. /* print failing CCW area (maximum 4) */
  3578. /* scsw->cda is either valid or zero */
  3579. len = 0;
  3580. from = ++to;
  3581. fail = (struct ccw1 *)(addr_t)
  3582. irb->scsw.cmd.cpa; /* failing CCW */
  3583. if (from < fail - 2) {
  3584. from = fail - 2; /* there is a gap - print header */
  3585. len += sprintf(page, KERN_ERR PRINTK_HEADER "......\n");
  3586. }
  3587. to = min(fail + 1, last);
  3588. len += dasd_eckd_dump_ccw_range(from, to, page + len);
  3589. /* print last CCWs (maximum 2) */
  3590. from = max(from, ++to);
  3591. if (from < last - 1) {
  3592. from = last - 1; /* there is a gap - print header */
  3593. len += sprintf(page + len, KERN_ERR PRINTK_HEADER "......\n");
  3594. }
  3595. len += dasd_eckd_dump_ccw_range(from, last, page + len);
  3596. if (len > 0)
  3597. printk("%s", page);
  3598. }
  3599. free_page((unsigned long) page);
  3600. }
  3601. /*
  3602. * Print sense data from a tcw.
  3603. */
  3604. static void dasd_eckd_dump_sense_tcw(struct dasd_device *device,
  3605. struct dasd_ccw_req *req, struct irb *irb)
  3606. {
  3607. char *page;
  3608. int len, sl, sct, residual;
  3609. struct tsb *tsb;
  3610. u8 *sense, *rcq;
  3611. page = (char *) get_zeroed_page(GFP_ATOMIC);
  3612. if (page == NULL) {
  3613. DBF_DEV_EVENT(DBF_WARNING, device, " %s",
  3614. "No memory to dump sense data");
  3615. return;
  3616. }
  3617. /* dump the sense data */
  3618. len = sprintf(page, KERN_ERR PRINTK_HEADER
  3619. " I/O status report for device %s:\n",
  3620. dev_name(&device->cdev->dev));
  3621. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3622. " in req: %p CC:%02X FC:%02X AC:%02X SC:%02X DS:%02X "
  3623. "CS:%02X fcxs:%02X schxs:%02X RC:%d\n",
  3624. req, scsw_cc(&irb->scsw), scsw_fctl(&irb->scsw),
  3625. scsw_actl(&irb->scsw), scsw_stctl(&irb->scsw),
  3626. scsw_dstat(&irb->scsw), scsw_cstat(&irb->scsw),
  3627. irb->scsw.tm.fcxs, irb->scsw.tm.schxs,
  3628. req ? req->intrc : 0);
  3629. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3630. " device %s: Failing TCW: %p\n",
  3631. dev_name(&device->cdev->dev),
  3632. (void *) (addr_t) irb->scsw.tm.tcw);
  3633. tsb = NULL;
  3634. sense = NULL;
  3635. if (irb->scsw.tm.tcw && (irb->scsw.tm.fcxs & 0x01))
  3636. tsb = tcw_get_tsb(
  3637. (struct tcw *)(unsigned long)irb->scsw.tm.tcw);
  3638. if (tsb) {
  3639. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3640. " tsb->length %d\n", tsb->length);
  3641. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3642. " tsb->flags %x\n", tsb->flags);
  3643. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3644. " tsb->dcw_offset %d\n", tsb->dcw_offset);
  3645. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3646. " tsb->count %d\n", tsb->count);
  3647. residual = tsb->count - 28;
  3648. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3649. " residual %d\n", residual);
  3650. switch (tsb->flags & 0x07) {
  3651. case 1: /* tsa_iostat */
  3652. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3653. " tsb->tsa.iostat.dev_time %d\n",
  3654. tsb->tsa.iostat.dev_time);
  3655. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3656. " tsb->tsa.iostat.def_time %d\n",
  3657. tsb->tsa.iostat.def_time);
  3658. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3659. " tsb->tsa.iostat.queue_time %d\n",
  3660. tsb->tsa.iostat.queue_time);
  3661. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3662. " tsb->tsa.iostat.dev_busy_time %d\n",
  3663. tsb->tsa.iostat.dev_busy_time);
  3664. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3665. " tsb->tsa.iostat.dev_act_time %d\n",
  3666. tsb->tsa.iostat.dev_act_time);
  3667. sense = tsb->tsa.iostat.sense;
  3668. break;
  3669. case 2: /* ts_ddpc */
  3670. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3671. " tsb->tsa.ddpc.rc %d\n", tsb->tsa.ddpc.rc);
  3672. for (sl = 0; sl < 2; sl++) {
  3673. len += sprintf(page + len,
  3674. KERN_ERR PRINTK_HEADER
  3675. " tsb->tsa.ddpc.rcq %2d-%2d: ",
  3676. (8 * sl), ((8 * sl) + 7));
  3677. rcq = tsb->tsa.ddpc.rcq;
  3678. for (sct = 0; sct < 8; sct++) {
  3679. len += sprintf(page + len, " %02x",
  3680. rcq[8 * sl + sct]);
  3681. }
  3682. len += sprintf(page + len, "\n");
  3683. }
  3684. sense = tsb->tsa.ddpc.sense;
  3685. break;
  3686. case 3: /* tsa_intrg */
  3687. len += sprintf(page + len, KERN_ERR PRINTK_HEADER
  3688. " tsb->tsa.intrg.: not supportet yet \n");
  3689. break;
  3690. }
  3691. if (sense) {
  3692. for (sl = 0; sl < 4; sl++) {
  3693. len += sprintf(page + len,
  3694. KERN_ERR PRINTK_HEADER
  3695. " Sense(hex) %2d-%2d:",
  3696. (8 * sl), ((8 * sl) + 7));
  3697. for (sct = 0; sct < 8; sct++) {
  3698. len += sprintf(page + len, " %02x",
  3699. sense[8 * sl + sct]);
  3700. }
  3701. len += sprintf(page + len, "\n");
  3702. }
  3703. if (sense[27] & DASD_SENSE_BIT_0) {
  3704. /* 24 Byte Sense Data */
  3705. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3706. " 24 Byte: %x MSG %x, "
  3707. "%s MSGb to SYSOP\n",
  3708. sense[7] >> 4, sense[7] & 0x0f,
  3709. sense[1] & 0x10 ? "" : "no");
  3710. } else {
  3711. /* 32 Byte Sense Data */
  3712. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3713. " 32 Byte: Format: %x "
  3714. "Exception class %x\n",
  3715. sense[6] & 0x0f, sense[22] >> 4);
  3716. }
  3717. } else {
  3718. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3719. " SORRY - NO VALID SENSE AVAILABLE\n");
  3720. }
  3721. } else {
  3722. sprintf(page + len, KERN_ERR PRINTK_HEADER
  3723. " SORRY - NO TSB DATA AVAILABLE\n");
  3724. }
  3725. printk("%s", page);
  3726. free_page((unsigned long) page);
  3727. }
  3728. static void dasd_eckd_dump_sense(struct dasd_device *device,
  3729. struct dasd_ccw_req *req, struct irb *irb)
  3730. {
  3731. if (scsw_is_tm(&irb->scsw))
  3732. dasd_eckd_dump_sense_tcw(device, req, irb);
  3733. else
  3734. dasd_eckd_dump_sense_ccw(device, req, irb);
  3735. }
  3736. static int dasd_eckd_pm_freeze(struct dasd_device *device)
  3737. {
  3738. /*
  3739. * the device should be disconnected from our LCU structure
  3740. * on restore we will reconnect it and reread LCU specific
  3741. * information like PAV support that might have changed
  3742. */
  3743. dasd_alias_remove_device(device);
  3744. dasd_alias_disconnect_device_from_lcu(device);
  3745. return 0;
  3746. }
  3747. static int dasd_eckd_restore_device(struct dasd_device *device)
  3748. {
  3749. struct dasd_eckd_private *private;
  3750. struct dasd_eckd_characteristics temp_rdc_data;
  3751. int is_known, rc;
  3752. struct dasd_uid temp_uid;
  3753. unsigned long flags;
  3754. private = (struct dasd_eckd_private *) device->private;
  3755. /* Read Configuration Data */
  3756. rc = dasd_eckd_read_conf(device);
  3757. if (rc)
  3758. goto out_err;
  3759. dasd_eckd_get_uid(device, &temp_uid);
  3760. /* Generate device unique id */
  3761. rc = dasd_eckd_generate_uid(device);
  3762. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  3763. if (memcmp(&private->uid, &temp_uid, sizeof(struct dasd_uid)) != 0)
  3764. dev_err(&device->cdev->dev, "The UID of the DASD has "
  3765. "changed\n");
  3766. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  3767. if (rc)
  3768. goto out_err;
  3769. /* register lcu with alias handling, enable PAV if this is a new lcu */
  3770. is_known = dasd_alias_make_device_known_to_lcu(device);
  3771. if (is_known < 0)
  3772. return is_known;
  3773. if (!is_known) {
  3774. dasd_eckd_validate_server(device);
  3775. dasd_alias_lcu_setup_complete(device);
  3776. } else
  3777. dasd_alias_wait_for_lcu_setup(device);
  3778. /* RE-Read Configuration Data */
  3779. rc = dasd_eckd_read_conf(device);
  3780. if (rc)
  3781. goto out_err;
  3782. /* Read Feature Codes */
  3783. dasd_eckd_read_features(device);
  3784. /* Read Device Characteristics */
  3785. rc = dasd_generic_read_dev_chars(device, DASD_ECKD_MAGIC,
  3786. &temp_rdc_data, 64);
  3787. if (rc) {
  3788. DBF_EVENT_DEVID(DBF_WARNING, device->cdev,
  3789. "Read device characteristic failed, rc=%d", rc);
  3790. goto out_err;
  3791. }
  3792. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  3793. memcpy(&private->rdc_data, &temp_rdc_data, sizeof(temp_rdc_data));
  3794. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  3795. /* add device to alias management */
  3796. dasd_alias_add_device(device);
  3797. return 0;
  3798. out_err:
  3799. return -1;
  3800. }
  3801. static int dasd_eckd_reload_device(struct dasd_device *device)
  3802. {
  3803. struct dasd_eckd_private *private;
  3804. int rc, old_base;
  3805. char print_uid[60];
  3806. struct dasd_uid uid;
  3807. unsigned long flags;
  3808. private = (struct dasd_eckd_private *) device->private;
  3809. spin_lock_irqsave(get_ccwdev_lock(device->cdev), flags);
  3810. old_base = private->uid.base_unit_addr;
  3811. spin_unlock_irqrestore(get_ccwdev_lock(device->cdev), flags);
  3812. /* Read Configuration Data */
  3813. rc = dasd_eckd_read_conf(device);
  3814. if (rc)
  3815. goto out_err;
  3816. rc = dasd_eckd_generate_uid(device);
  3817. if (rc)
  3818. goto out_err;
  3819. /*
  3820. * update unit address configuration and
  3821. * add device to alias management
  3822. */
  3823. dasd_alias_update_add_device(device);
  3824. dasd_eckd_get_uid(device, &uid);
  3825. if (old_base != uid.base_unit_addr) {
  3826. if (strlen(uid.vduit) > 0)
  3827. snprintf(print_uid, sizeof(print_uid),
  3828. "%s.%s.%04x.%02x.%s", uid.vendor, uid.serial,
  3829. uid.ssid, uid.base_unit_addr, uid.vduit);
  3830. else
  3831. snprintf(print_uid, sizeof(print_uid),
  3832. "%s.%s.%04x.%02x", uid.vendor, uid.serial,
  3833. uid.ssid, uid.base_unit_addr);
  3834. dev_info(&device->cdev->dev,
  3835. "An Alias device was reassigned to a new base device "
  3836. "with UID: %s\n", print_uid);
  3837. }
  3838. return 0;
  3839. out_err:
  3840. return -1;
  3841. }
  3842. static struct ccw_driver dasd_eckd_driver = {
  3843. .driver = {
  3844. .name = "dasd-eckd",
  3845. .owner = THIS_MODULE,
  3846. },
  3847. .ids = dasd_eckd_ids,
  3848. .probe = dasd_eckd_probe,
  3849. .remove = dasd_generic_remove,
  3850. .set_offline = dasd_generic_set_offline,
  3851. .set_online = dasd_eckd_set_online,
  3852. .notify = dasd_generic_notify,
  3853. .path_event = dasd_generic_path_event,
  3854. .freeze = dasd_generic_pm_freeze,
  3855. .thaw = dasd_generic_restore_device,
  3856. .restore = dasd_generic_restore_device,
  3857. .uc_handler = dasd_generic_uc_handler,
  3858. .int_class = IOINT_DAS,
  3859. };
  3860. /*
  3861. * max_blocks is dependent on the amount of storage that is available
  3862. * in the static io buffer for each device. Currently each device has
  3863. * 8192 bytes (=2 pages). For 64 bit one dasd_mchunkt_t structure has
  3864. * 24 bytes, the struct dasd_ccw_req has 136 bytes and each block can use
  3865. * up to 16 bytes (8 for the ccw and 8 for the idal pointer). In
  3866. * addition we have one define extent ccw + 16 bytes of data and one
  3867. * locate record ccw + 16 bytes of data. That makes:
  3868. * (8192 - 24 - 136 - 8 - 16 - 8 - 16) / 16 = 499 blocks at maximum.
  3869. * We want to fit two into the available memory so that we can immediately
  3870. * start the next request if one finishes off. That makes 249.5 blocks
  3871. * for one request. Give a little safety and the result is 240.
  3872. */
  3873. static struct dasd_discipline dasd_eckd_discipline = {
  3874. .owner = THIS_MODULE,
  3875. .name = "ECKD",
  3876. .ebcname = "ECKD",
  3877. .max_blocks = 190,
  3878. .check_device = dasd_eckd_check_characteristics,
  3879. .uncheck_device = dasd_eckd_uncheck_device,
  3880. .do_analysis = dasd_eckd_do_analysis,
  3881. .verify_path = dasd_eckd_verify_path,
  3882. .ready_to_online = dasd_eckd_ready_to_online,
  3883. .online_to_ready = dasd_eckd_online_to_ready,
  3884. .fill_geometry = dasd_eckd_fill_geometry,
  3885. .start_IO = dasd_start_IO,
  3886. .term_IO = dasd_term_IO,
  3887. .handle_terminated_request = dasd_eckd_handle_terminated_request,
  3888. .format_device = dasd_eckd_format_device,
  3889. .erp_action = dasd_eckd_erp_action,
  3890. .erp_postaction = dasd_eckd_erp_postaction,
  3891. .check_for_device_change = dasd_eckd_check_for_device_change,
  3892. .build_cp = dasd_eckd_build_alias_cp,
  3893. .free_cp = dasd_eckd_free_alias_cp,
  3894. .dump_sense = dasd_eckd_dump_sense,
  3895. .dump_sense_dbf = dasd_eckd_dump_sense_dbf,
  3896. .fill_info = dasd_eckd_fill_info,
  3897. .ioctl = dasd_eckd_ioctl,
  3898. .freeze = dasd_eckd_pm_freeze,
  3899. .restore = dasd_eckd_restore_device,
  3900. .reload = dasd_eckd_reload_device,
  3901. .get_uid = dasd_eckd_get_uid,
  3902. };
  3903. static int __init
  3904. dasd_eckd_init(void)
  3905. {
  3906. int ret;
  3907. ASCEBC(dasd_eckd_discipline.ebcname, 4);
  3908. dasd_reserve_req = kmalloc(sizeof(*dasd_reserve_req),
  3909. GFP_KERNEL | GFP_DMA);
  3910. if (!dasd_reserve_req)
  3911. return -ENOMEM;
  3912. path_verification_worker = kmalloc(sizeof(*path_verification_worker),
  3913. GFP_KERNEL | GFP_DMA);
  3914. if (!path_verification_worker) {
  3915. kfree(dasd_reserve_req);
  3916. return -ENOMEM;
  3917. }
  3918. ret = ccw_driver_register(&dasd_eckd_driver);
  3919. if (!ret)
  3920. wait_for_device_probe();
  3921. else {
  3922. kfree(path_verification_worker);
  3923. kfree(dasd_reserve_req);
  3924. }
  3925. return ret;
  3926. }
  3927. static void __exit
  3928. dasd_eckd_cleanup(void)
  3929. {
  3930. ccw_driver_unregister(&dasd_eckd_driver);
  3931. kfree(path_verification_worker);
  3932. kfree(dasd_reserve_req);
  3933. }
  3934. module_init(dasd_eckd_init);
  3935. module_exit(dasd_eckd_cleanup);