141480Smckusick /* 241480Smckusick * Copyright (c) 1988 University of Utah. 341480Smckusick * Copyright (c) 1982, 1990 The Regents of the University of California. 441480Smckusick * All rights reserved. 541480Smckusick * 641480Smckusick * This code is derived from software contributed to Berkeley by 741480Smckusick * the Systems Programming Group of the University of Utah Computer 841480Smckusick * Science Department. 941480Smckusick * 1041480Smckusick * %sccs.include.redist.c% 1141480Smckusick * 1249303Shibler * from: Utah $Hdr: rd.c 1.38 90/10/12$ 1341480Smckusick * 14*56507Sbostic * @(#)rd.c 7.17 (Berkeley) 10/11/92 1541480Smckusick */ 1641480Smckusick 1741480Smckusick /* 1841480Smckusick * CS80/SS80 disk driver 1941480Smckusick */ 2041480Smckusick #include "rd.h" 2141480Smckusick #if NRD > 0 2241480Smckusick 23*56507Sbostic #include <sys/param.h> 24*56507Sbostic #include <sys/systm.h> 25*56507Sbostic #include <sys/errno.h> 26*56507Sbostic #include <sys/dkstat.h> 27*56507Sbostic #include <sys/disklabel.h> 28*56507Sbostic #include <sys/buf.h> 29*56507Sbostic #include <sys/uio.h> 3041480Smckusick 31*56507Sbostic #include <hp/dev/device.h> 32*56507Sbostic #include <hp300/dev/rdreg.h> 3341480Smckusick 34*56507Sbostic #include <vm/vm_param.h> 35*56507Sbostic #include <vm/lock.h> 36*56507Sbostic #include <vm/vm_prot.h> 37*56507Sbostic #include <vm/pmap.h> 3845750Smckusick 3941480Smckusick int rdinit(), rdstart(), rdgo(), rdintr(); 4041480Smckusick struct driver rddriver = { 4141480Smckusick rdinit, "rd", rdstart, rdgo, rdintr, 4241480Smckusick }; 4341480Smckusick 4441480Smckusick struct rd_softc { 4541480Smckusick struct hp_device *sc_hd; 4642361Smckusick int sc_flags; 4742361Smckusick short sc_type; 4842361Smckusick short sc_punit; 4942361Smckusick char *sc_addr; 5042361Smckusick int sc_resid; 5142361Smckusick u_int sc_wpms; 5242361Smckusick struct rdinfo *sc_info; 5342361Smckusick struct devqueue sc_dq; 5441480Smckusick struct rd_iocmd sc_ioc; 5541480Smckusick struct rd_rscmd sc_rsc; 5641480Smckusick struct rd_stat sc_stat; 5741480Smckusick struct rd_ssmcmd sc_ssmc; 5841480Smckusick struct rd_srcmd sc_src; 5941480Smckusick struct rd_clearcmd sc_clear; 6041480Smckusick } rd_softc[NRD]; 6141480Smckusick 6241480Smckusick /* sc_flags values */ 6341480Smckusick #define RDF_ALIVE 0x1 6441480Smckusick #define RDF_SEEK 0x2 6541480Smckusick #define RDF_SWAIT 0x4 6641480Smckusick 6741480Smckusick struct size { 6841480Smckusick daddr_t nblocks; 6941480Smckusick int cyloff; 7041480Smckusick }; 7141480Smckusick 7241480Smckusick #ifdef DEBUG 7341480Smckusick int rddebug = 0x80; 7441480Smckusick #define RDB_FOLLOW 0x01 7541480Smckusick #define RDB_STATUS 0x02 7641480Smckusick #define RDB_IDENT 0x04 7741480Smckusick #define RDB_IO 0x08 7841480Smckusick #define RDB_ASYNC 0x10 7941480Smckusick #define RDB_ERROR 0x80 8041480Smckusick #define RDB_DUMP 0x80000000 8141480Smckusick 8241480Smckusick struct rdstats { 8341480Smckusick long rdretries; 8441480Smckusick long rdresets; 8541480Smckusick long rdtimeouts; 8641480Smckusick long rdpolltries; 8741480Smckusick long rdpollwaits; 8841480Smckusick } rdstats[NRD]; 8941480Smckusick 9041480Smckusick /* error message tables */ 9141480Smckusick char *err_reject[] = { 9241480Smckusick 0, 0, 9341480Smckusick "channel parity error", /* 0x2000 */ 9441480Smckusick 0, 0, 9541480Smckusick "illegal opcode", /* 0x0400 */ 9641480Smckusick "module addressing", /* 0x0200 */ 9741480Smckusick "address bounds", /* 0x0100 */ 9841480Smckusick "parameter bounds", /* 0x0080 */ 9941480Smckusick "illegal parameter", /* 0x0040 */ 10041480Smckusick "message sequence", /* 0x0020 */ 10141480Smckusick 0, 10241480Smckusick "message length", /* 0x0008 */ 10341480Smckusick 0, 0, 0 10441480Smckusick }; 10541480Smckusick 10641480Smckusick char *err_fault[] = { 10741480Smckusick 0, 10841480Smckusick "cross unit", /* 0x4000 */ 10941480Smckusick 0, 11041480Smckusick "controller fault", /* 0x1000 */ 11141480Smckusick 0, 0, 11241480Smckusick "unit fault", /* 0x0200 */ 11341480Smckusick 0, 11441480Smckusick "diagnostic result", /* 0x0080 */ 11541480Smckusick 0, 11641480Smckusick "operator release request", /* 0x0020 */ 11741480Smckusick "diagnostic release request", /* 0x0010 */ 11841480Smckusick "internal maintenance release request", /* 0x0008 */ 11941480Smckusick 0, 12041480Smckusick "power fail", /* 0x0002 */ 12141480Smckusick "retransmit" /* 0x0001 */ 12241480Smckusick }; 12341480Smckusick 12441480Smckusick char *err_access[] = { 12541480Smckusick "illegal parallel operation", /* 0x8000 */ 12641480Smckusick "uninitialized media", /* 0x4000 */ 12741480Smckusick "no spares available", /* 0x2000 */ 12841480Smckusick "not ready", /* 0x1000 */ 12941480Smckusick "write protect", /* 0x0800 */ 13041480Smckusick "no data found", /* 0x0400 */ 13141480Smckusick 0, 0, 13241480Smckusick "unrecoverable data overflow", /* 0x0080 */ 13341480Smckusick "unrecoverable data", /* 0x0040 */ 13441480Smckusick 0, 13541480Smckusick "end of file", /* 0x0010 */ 13641480Smckusick "end of volume", /* 0x0008 */ 13741480Smckusick 0, 0, 0 13841480Smckusick }; 13941480Smckusick 14041480Smckusick char *err_info[] = { 14141480Smckusick "operator release request", /* 0x8000 */ 14241480Smckusick "diagnostic release request", /* 0x4000 */ 14341480Smckusick "internal maintenance release request", /* 0x2000 */ 14441480Smckusick "media wear", /* 0x1000 */ 14541480Smckusick "latency induced", /* 0x0800 */ 14641480Smckusick 0, 0, 14741480Smckusick "auto sparing invoked", /* 0x0100 */ 14841480Smckusick 0, 14941480Smckusick "recoverable data overflow", /* 0x0040 */ 15041480Smckusick "marginal data", /* 0x0020 */ 15141480Smckusick "recoverable data", /* 0x0010 */ 15241480Smckusick 0, 15341480Smckusick "maintenance track overflow", /* 0x0004 */ 15441480Smckusick 0, 0 15541480Smckusick }; 15641480Smckusick #endif 15741480Smckusick 15841480Smckusick /* 15941480Smckusick * CS/80 partitions. We reserve the first cylinder for a LIF 16041480Smckusick * style boot directory (the 8k allowed in the BSD filesystem 16141480Smckusick * is just way too small). This boot area is outside of all but 16241480Smckusick * the C partition. This implies that you cannot use the C 16341480Smckusick * partition on a bootable disk since the filesystem would overlay 16441480Smckusick * the boot area. You must use the A partition. 16541480Smckusick * 16641480Smckusick * These maps support four basic layouts: 16741480Smckusick * 16841480Smckusick * A/B/G: This is the "traditional" setup for a bootable disk. 16941480Smckusick * A is the root partition, B the swap, and G a user partition. 17041480Smckusick * A/D/H: This is a setup for bootable systems requiring more swap 17141480Smckusick * (e.g. those who use HPCL). It has A as the root, D as a 17241480Smckusick * larger swap, and H as a smaller user partition. 17341480Smckusick * A/D/E/F: Similar to A/D/H with E and F breaking H into two partitions. 17441480Smckusick * E could be used for /usr and F for users. 17541480Smckusick * C: This gives a single, non-bootable, large user filesystem. 17641480Smckusick * Good for second drives on a machine (e.g. /usr/src). 17741480Smckusick */ 17841480Smckusick struct size rd7945A_sizes[8] = { 17941480Smckusick RDSZ(15904), 1, /* A=cyl 1 thru 142 */ 18041480Smckusick RDSZ(20160), 143, /* B=cyl 143 thru 322 */ 18141480Smckusick RDSZ(108416), 0, /* C=cyl 0 thru 967 */ 18241480Smckusick RDSZ(40320), 143, /* D=cyl 143 thru 502 */ 18341480Smckusick RDSZ(0), 0, /* E=<undefined> */ 18441480Smckusick RDSZ(0), 0, /* F=<undefined> */ 18541480Smckusick RDSZ(72240), 323, /* G=cyl 323 thru 967 */ 18641480Smckusick RDSZ(52080), 503, /* H=cyl 503 thru 967 */ 18741480Smckusick }, rd9134D_sizes[8] = { 18841480Smckusick RDSZ(15936), 1, /* A=cyl 1 thru 166 */ 18941480Smckusick RDSZ(13056), 167, /* B=cyl 167 thru 302 */ 19041480Smckusick RDSZ(29088), 0, /* C=cyl 0 thru 302 */ 19141480Smckusick RDSZ(0), 0, /* D=<undefined> */ 19241480Smckusick RDSZ(0), 0, /* E=<undefined> */ 19341480Smckusick RDSZ(0), 0, /* F=<undefined> */ 19441480Smckusick RDSZ(0), 0, /* G=<undefined> */ 19541480Smckusick RDSZ(0), 0, /* H=<undefined> */ 19641480Smckusick }, rd9122S_sizes[8] = { 19741480Smckusick RDSZ(0), 0, /* A=<undefined> */ 19841480Smckusick RDSZ(0), 0, /* B=<undefined> */ 19941480Smckusick RDSZ(1232), 0, /* C=cyl 0 thru 76 */ 20041480Smckusick RDSZ(0), 0, /* D=<undefined> */ 20141480Smckusick RDSZ(0), 0, /* E=<undefined> */ 20241480Smckusick RDSZ(0), 0, /* F=<undefined> */ 20341480Smckusick RDSZ(0), 0, /* G=<undefined> */ 20441480Smckusick RDSZ(0), 0, /* H=<undefined> */ 20541480Smckusick }, rd7912P_sizes[8] = { 20641480Smckusick RDSZ(15904), 0, /* A=cyl 1 thru 71 */ 20741480Smckusick RDSZ(22400), 72, /* B=cyl 72 thru 171 */ 20841480Smckusick RDSZ(128128), 0, /* C=cyl 0 thru 571 */ 20941480Smckusick RDSZ(42560), 72, /* D=cyl 72 thru 261 */ 21041480Smckusick RDSZ(0), 292, /* E=<undefined> */ 21141480Smckusick RDSZ(0), 542, /* F=<undefined> */ 21241480Smckusick RDSZ(89600), 172, /* G=cyl 221 thru 571 */ 21341480Smckusick RDSZ(69440), 262, /* H=cyl 262 thru 571 */ 21441480Smckusick }, rd7914P_sizes[8] = { 21541480Smckusick RDSZ(15904), 1, /* A=cyl 1 thru 71 */ 21641480Smckusick RDSZ(40320), 72, /* B=cyl 72 thru 251 */ 21741480Smckusick RDSZ(258048), 0, /* C=cyl 0 thru 1151 */ 21841480Smckusick RDSZ(64960), 72, /* D=cyl 72 thru 361 */ 21941480Smckusick RDSZ(98560), 362, /* E=cyl 362 thru 801 */ 22041480Smckusick RDSZ(78400), 802, /* F=cyl 802 thru 1151 */ 22141480Smckusick RDSZ(201600), 252, /* G=cyl 221 thru 1151 */ 22241480Smckusick RDSZ(176960), 362, /* H=cyl 362 thru 1151 */ 22341480Smckusick }, rd7933H_sizes[8] = { 22441480Smckusick RDSZ(16146), 1, /* A=cyl 1 thru 27 */ 22541480Smckusick RDSZ(66976), 28, /* B=cyl 28 thru 139 */ 22641480Smckusick RDSZ(789958), 0, /* C=cyl 0 thru 1320 */ 22741480Smckusick RDSZ(16146), 140, /* D=cyl 140 thru 166 */ 22841480Smckusick RDSZ(165646), 167, /* E=cyl 167 thru 443 */ 22941480Smckusick RDSZ(165646), 444, /* F=cyl 444 thru 720 */ 23041480Smckusick RDSZ(706238), 140, /* G=cyl 140 thru 1320 */ 23141480Smckusick RDSZ(358800), 721, /* H=cyl 721 thru 1320 */ 23241480Smckusick }, rd9134L_sizes[8] = { 23341480Smckusick RDSZ(15920), 1, /* A=cyl 1 thru 199 */ 23441480Smckusick RDSZ(20000), 200, /* B=cyl 200 thru 449 */ 23541480Smckusick RDSZ(77840), 0, /* C=cyl 0 thru 972 */ 23641480Smckusick RDSZ(32000), 200, /* D=cyl 200 thru 599 */ 23741480Smckusick RDSZ(0), 0, /* E=<undefined> */ 23841480Smckusick RDSZ(0), 0, /* F=<undefined> */ 23941480Smckusick RDSZ(41840), 450, /* G=cyl 450 thru 972 */ 24041480Smckusick RDSZ(29840), 600, /* H=cyl 600 thru 972 */ 24141480Smckusick }, rd7957A_sizes[8] = { 24241480Smckusick RDSZ(16016), 1, /* A=cyl 1 thru 104 */ 24341480Smckusick RDSZ(24640), 105, /* B=cyl 105 thru 264 */ 24441480Smckusick RDSZ(159544), 0, /* C=cyl 0 thru 1035 */ 24541480Smckusick RDSZ(42350), 105, /* D=cyl 105 thru 379 */ 24641480Smckusick RDSZ(54824), 380, /* E=cyl 380 thru 735 */ 24741480Smckusick RDSZ(46200), 736, /* F=cyl 736 thru 1035 */ 24841480Smckusick RDSZ(118734), 265, /* G=cyl 265 thru 1035 */ 24941480Smckusick RDSZ(101024), 380, /* H=cyl 380 thru 1035 */ 25041480Smckusick }, rd7958A_sizes[8] = { 25141480Smckusick RDSZ(16128), 1, /* A=cyl 1 thru 64 */ 25241480Smckusick RDSZ(32256), 65, /* B=cyl 65 thru 192 */ 25341480Smckusick RDSZ(255276), 0, /* C=cyl 0 thru 1012 */ 25441480Smckusick RDSZ(48384), 65, /* D=cyl 65 thru 256 */ 25541480Smckusick RDSZ(100800), 257, /* E=cyl 257 thru 656 */ 25641480Smckusick RDSZ(89712), 657, /* F=cyl 657 thru 1012 */ 25741480Smckusick RDSZ(206640), 193, /* G=cyl 193 thru 1012 */ 25841480Smckusick RDSZ(190512), 257, /* H=cyl 257 thru 1012 */ 25941480Smckusick }, rd7957B_sizes[8] = { 26041480Smckusick RDSZ(16002), 1, /* A=cyl 1 thru 127 */ 26141480Smckusick RDSZ(32760), 128, /* B=cyl 128 thru 387 */ 26241480Smckusick RDSZ(159894), 0, /* C=cyl 0 thru 1268 */ 26341480Smckusick RDSZ(49140), 128, /* D=cyl 128 thru 517 */ 26441480Smckusick RDSZ(50400), 518, /* E=cyl 518 thru 917 */ 26541480Smckusick RDSZ(44226), 918, /* F=cyl 918 thru 1268 */ 26641480Smckusick RDSZ(111006), 388, /* G=cyl 388 thru 1268 */ 26741480Smckusick RDSZ(94626), 518, /* H=cyl 518 thru 1268 */ 26841480Smckusick }, rd7958B_sizes[8] = { 26941480Smckusick RDSZ(16254), 1, /* A=cyl 1 thru 43 */ 27041480Smckusick RDSZ(32886), 44, /* B=cyl 44 thru 130 */ 27141480Smckusick RDSZ(297108), 0, /* C=cyl 0 thru 785 */ 27241480Smckusick RDSZ(49140), 44, /* D=cyl 44 thru 173 */ 27341480Smckusick RDSZ(121716), 174, /* E=cyl 174 thru 495 */ 27441480Smckusick RDSZ(109620), 496, /* F=cyl 496 thru 785 */ 27541480Smckusick RDSZ(247590), 131, /* G=cyl 131 thru 785 */ 27641480Smckusick RDSZ(231336), 174, /* H=cyl 174 thru 785 */ 27741480Smckusick }, rd7959B_sizes[8] = { 27841480Smckusick RDSZ(16254), 1, /* A=cyl 1 thru 43 */ 27941480Smckusick RDSZ(49140), 44, /* B=cyl 44 thru 173 */ 28041480Smckusick RDSZ(594216), 0, /* C=cyl 0 thru 1571 */ 28141480Smckusick RDSZ(65772), 44, /* D=cyl 44 thru 217 */ 28241480Smckusick RDSZ(303912), 218, /* E=cyl 218 thru 1021 */ 28341480Smckusick RDSZ(207900), 1022, /* F=cyl 1022 thru 1571 */ 28441480Smckusick RDSZ(528444), 174, /* G=cyl 174 thru 1571 */ 28541480Smckusick RDSZ(511812), 218, /* H=cyl 218 thru 1571 */ 28646681Smckusick }, rd2200A_sizes[8] = { 28746681Smckusick RDSZ(16272), 1, /* A=cyl 1 thru 36 */ 28846681Smckusick RDSZ(49720), 37, /* B=cyl 37 thru 146 */ 28946681Smckusick RDSZ(654948), 0, /* C=cyl 0 thru 1448 */ 29046681Smckusick RDSZ(65992), 37, /* D=cyl 37 thru 182 */ 29146681Smckusick RDSZ(304648), 183, /* E=cyl 183 thru 856 */ 29246681Smckusick RDSZ(267584), 857, /* F=cyl 857 thru 1448 */ 29346681Smckusick RDSZ(588504), 147, /* G=cyl 147 thru 1448 */ 29446681Smckusick RDSZ(572232), 183, /* H=cyl 183 thru 1448 */ 29546681Smckusick }, rd2203A_sizes[8] = { 29646681Smckusick /* modelled after the 7937; i.e. bogus */ 29746681Smckusick RDSZ(16272), 1, /* A=cyl 1 thru 18 */ 29846681Smckusick RDSZ(67800), 19, /* B=cyl 19 thru 93 */ 29946681Smckusick RDSZ(1309896), 0, /* C=cyl 0 thru 1448 */ 30046681Smckusick RDSZ(16272), 94, /* D=cyl 19 thru 111 */ 30146681Smckusick RDSZ(305552), 112, /* E=cyl 112 thru 449 */ 30246681Smckusick RDSZ(305552), 450, /* F=cyl 450 thru 787 */ 30346681Smckusick RDSZ(1224920), 94, /* G=cyl 94 thru 1448 */ 30446681Smckusick RDSZ(597544), 788, /* H=cyl 788 thru 1448 */ 30541480Smckusick 30641480Smckusick #if DEV_BSIZE == 512 30741480Smckusick /* 30841480Smckusick * These values would not work for 1k, 30941480Smckusick * since the number of cylinders would be different. 31041480Smckusick */ 31141480Smckusick }, rd7936H_sizes[8] = { 31241480Smckusick RDSZ(16359), 1, /* A=cyl 1 thru 19 */ 31341480Smckusick RDSZ(67158), 20, /* B=cyl 20 thru 97 */ 31441480Smckusick RDSZ(600978), 0, /* C=cyl 0 thru 697 */ 31541480Smckusick RDSZ(16359), 98, /* D=cyl 98 thru 116 */ 31641480Smckusick RDSZ(120540), 117, /* E=cyl 117 thru 256 */ 31741480Smckusick RDSZ(120540), 256, /* F=cyl 256 thru 396 */ 31841480Smckusick RDSZ(516600), 98, /* G=cyl 98 thru 697 */ 31941480Smckusick RDSZ(259161), 397, /* H=cyl 397 thru 697 */ 32041480Smckusick }, rd7937H_sizes[8] = { 32141480Smckusick RDSZ(15990), 1, /* A=cyl 1 thru 10 */ 32241480Smckusick RDSZ(67158), 11, /* B=cyl 11 thru 52 */ 32341480Smckusick RDSZ(1116102), 0, /* C=cyl 0 thru 697 */ 32441480Smckusick RDSZ(124722), 53, /* D=cyl 53 thru 130 */ 32541480Smckusick RDSZ(163098), 131, /* E=cyl 131 thru 232 */ 32641480Smckusick RDSZ(287820), 233, /* F=cyl 233 thru 412 */ 32741480Smckusick RDSZ(1031355), 53, /* G=cyl 53 thru 697 */ 32841480Smckusick RDSZ(455715), 413, /* H=cyl 413 thru 697 */ 32941480Smckusick #endif 33041480Smckusick }; 33141480Smckusick 33241480Smckusick struct rdinfo { 33341480Smckusick int nbpt; /* DEV_BSIZE blocks per track */ 33441480Smckusick int ntpc; /* tracks per cylinder */ 33541480Smckusick int nbpc; /* blocks per cylinder */ 33641480Smckusick struct size *sizes; /* default partition info (if no disklabel) */ 33741480Smckusick short hwid; /* 2 byte HW id */ 33841480Smckusick short maxunum; /* maximum allowed unit number */ 33941480Smckusick char *desc; /* drive type description */ 34041480Smckusick }; 34141480Smckusick 34241480Smckusick struct rdinfo rdinfo[] = { 34341480Smckusick NRD7945ABPT, NRD7945ATRK, NRD7945ABPT * NRD7945ATRK, 34441480Smckusick rd7945A_sizes, RD7946AID, 0, "7945A", 34541480Smckusick NRD9134DBPT, NRD9134DTRK, NRD9134DBPT * NRD9134DTRK, 34641480Smckusick rd9134D_sizes, RD9134DID, 1, "9134D", 34741480Smckusick NRD9122SBPT, NRD9122STRK, NRD9122SBPT * NRD9122STRK, 34841480Smckusick rd9122S_sizes, RD9134LID, 1, "9122S", 34941480Smckusick NRD7912PBPT, NRD7912PTRK, NRD7912PBPT * NRD7912PTRK, 35041480Smckusick rd7912P_sizes, RD7912PID, 0, "7912P", 35141480Smckusick NRD7914PBPT, NRD7914PTRK, NRD7914PBPT * NRD7914PTRK, 35241480Smckusick rd7914P_sizes, RD7914PID, 0, "7914P", 35341480Smckusick NRD7958ABPT, NRD7958ATRK, NRD7958ABPT * NRD7958ATRK, 35441480Smckusick rd7958A_sizes, RD7958AID, 0, "7958A", 35541480Smckusick NRD7957ABPT, NRD7957ATRK, NRD7957ABPT * NRD7957ATRK, 35641480Smckusick rd7957A_sizes, RD7957AID, 0, "7957A", 35741480Smckusick NRD7933HBPT, NRD7933HTRK, NRD7933HBPT * NRD7933HTRK, 35841480Smckusick rd7933H_sizes, RD7933HID, 0, "7933H", 35941480Smckusick NRD9134LBPT, NRD9134LTRK, NRD9134LBPT * NRD9134LTRK, 36041480Smckusick rd9134L_sizes, RD9134LID, 1, "9134L", 36141480Smckusick NRD7936HBPT, NRD7936HTRK, NRD7936HBPT * NRD7936HTRK, 36241480Smckusick rd7936H_sizes, RD7936HID, 0, "7936H", 36341480Smckusick NRD7937HBPT, NRD7937HTRK, NRD7937HBPT * NRD7937HTRK, 36441480Smckusick rd7937H_sizes, RD7937HID, 0, "7937H", 36541480Smckusick NRD7914PBPT, NRD7914PTRK, NRD7914PBPT * NRD7914PTRK, 36641480Smckusick rd7914P_sizes, RD7914CTID, 0, "7914CT", 36741480Smckusick NRD7945ABPT, NRD7945ATRK, NRD7945ABPT * NRD7945ATRK, 36841480Smckusick rd7945A_sizes, RD7946AID, 0, "7946A", 36941480Smckusick NRD9122SBPT, NRD9122STRK, NRD9122SBPT * NRD9122STRK, 37041480Smckusick rd9122S_sizes, RD9134LID, 1, "9122D", 37141480Smckusick NRD7957BBPT, NRD7957BTRK, NRD7957BBPT * NRD7957BTRK, 37241480Smckusick rd7957B_sizes, RD7957BID, 0, "7957B", 37341480Smckusick NRD7958BBPT, NRD7958BTRK, NRD7958BBPT * NRD7958BTRK, 37441480Smckusick rd7958B_sizes, RD7958BID, 0, "7958B", 37541480Smckusick NRD7959BBPT, NRD7959BTRK, NRD7959BBPT * NRD7959BTRK, 37641480Smckusick rd7959B_sizes, RD7959BID, 0, "7959B", 37746681Smckusick NRD2200ABPT, NRD2200ATRK, NRD2200ABPT * NRD2200ATRK, 37846681Smckusick rd2200A_sizes, RD2200AID, 0, "2200A", 37946681Smckusick NRD2203ABPT, NRD2203ATRK, NRD2203ABPT * NRD2203ATRK, 38046681Smckusick rd2203A_sizes, RD2203AID, 0, "2203A", 38141480Smckusick }; 38241480Smckusick int nrdinfo = sizeof(rdinfo) / sizeof(rdinfo[0]); 38341480Smckusick 38441480Smckusick struct buf rdtab[NRD]; 38541480Smckusick 38649133Skarels #define rdunit(x) (minor(x) >> 3) 38741480Smckusick #define rdpart(x) (minor(x) & 0x7) 38841480Smckusick #define rdpunit(x) ((x) & 7) 38941480Smckusick #define b_cylin b_resid 39041480Smckusick #define RDRETRY 5 39141480Smckusick #define RDWAITC 1 /* min time for timeout in seconds */ 39241480Smckusick 39342361Smckusick int rderrthresh = RDRETRY-1; /* when to start reporting errors */ 39442361Smckusick 39541480Smckusick rdinit(hd) 39641480Smckusick register struct hp_device *hd; 39741480Smckusick { 39841480Smckusick register struct rd_softc *rs = &rd_softc[hd->hp_unit]; 39941480Smckusick 40041480Smckusick rs->sc_hd = hd; 40141480Smckusick rs->sc_punit = rdpunit(hd->hp_flags); 40241480Smckusick rs->sc_type = rdident(rs, hd); 40341480Smckusick if (rs->sc_type < 0) 40441480Smckusick return(0); 40541480Smckusick rs->sc_dq.dq_ctlr = hd->hp_ctlr; 40641480Smckusick rs->sc_dq.dq_unit = hd->hp_unit; 40741480Smckusick rs->sc_dq.dq_slave = hd->hp_slave; 40841480Smckusick rs->sc_dq.dq_driver = &rddriver; 40941480Smckusick rs->sc_info = &rdinfo[rs->sc_type]; 41041480Smckusick rs->sc_flags = RDF_ALIVE; 41142361Smckusick #ifdef DEBUG 41242361Smckusick /* always report errors */ 41342361Smckusick if (rddebug & RDB_ERROR) 41442361Smckusick rderrthresh = 0; 41542361Smckusick #endif 41641480Smckusick return(1); 41741480Smckusick } 41841480Smckusick 41941480Smckusick rdident(rs, hd) 42041480Smckusick struct rd_softc *rs; 42141480Smckusick struct hp_device *hd; 42241480Smckusick { 42341480Smckusick struct rd_describe desc; 42441480Smckusick u_char stat, cmd[3]; 42541480Smckusick int unit, lunit; 42641480Smckusick char name[7]; 42741480Smckusick register int ctlr, slave, id, i; 42841480Smckusick 42941480Smckusick ctlr = hd->hp_ctlr; 43041480Smckusick slave = hd->hp_slave; 43141480Smckusick unit = rs->sc_punit; 43241480Smckusick lunit = hd->hp_unit; 43341480Smckusick 43441480Smckusick /* 43541480Smckusick * Grab device id and make sure: 43641480Smckusick * 1. It is a CS80 device. 43741480Smckusick * 2. It is one of the types we support. 43841480Smckusick * 3. If it is a 7946, we are accessing the disk unit (0) 43941480Smckusick */ 44041480Smckusick id = hpibid(ctlr, slave); 44146681Smckusick #ifdef DEBUG 44246681Smckusick if (rddebug & RDB_IDENT) 44346681Smckusick printf("hpibid(%d, %d) -> %x\n", ctlr, slave, id); 44446681Smckusick #endif 44541480Smckusick if ((id & 0x200) == 0) 44641480Smckusick return(-1); 44741480Smckusick for (i = 0; i < nrdinfo; i++) 44841480Smckusick if (id == rdinfo[i].hwid) 44941480Smckusick break; 45041480Smckusick if (i == nrdinfo || unit > rdinfo[i].maxunum) 45141480Smckusick return(-1); 45241480Smckusick id = i; 45341480Smckusick 45441480Smckusick /* 45541480Smckusick * Reset drive and collect device description. 45641480Smckusick * Don't really use the description info right now but 45741480Smckusick * might come in handy in the future (for disk labels). 45841480Smckusick */ 45941480Smckusick rdreset(rs, hd); 46041480Smckusick cmd[0] = C_SUNIT(unit); 46141480Smckusick cmd[1] = C_SVOL(0); 46241480Smckusick cmd[2] = C_DESC; 46341480Smckusick hpibsend(ctlr, slave, C_CMD, cmd, sizeof(cmd)); 46441480Smckusick hpibrecv(ctlr, slave, C_EXEC, &desc, 37); 46541480Smckusick hpibrecv(ctlr, slave, C_QSTAT, &stat, sizeof(stat)); 46641480Smckusick bzero(name, sizeof(name)); 46741480Smckusick if (!stat) { 46841480Smckusick register int n = desc.d_name; 46941480Smckusick for (i = 5; i >= 0; i--) { 47041480Smckusick name[i] = (n & 0xf) + '0'; 47141480Smckusick n >>= 4; 47241480Smckusick } 47342361Smckusick /* use drive characteristics to calculate xfer rate */ 47442361Smckusick rs->sc_wpms = 1000000 * (desc.d_sectsize/2) / desc.d_blocktime; 47541480Smckusick } 47641480Smckusick #ifdef DEBUG 47741480Smckusick if (rddebug & RDB_IDENT) { 47841480Smckusick printf("rd%d: name: %x ('%s')\n", 47941480Smckusick lunit, desc.d_name, name); 48041480Smckusick printf(" iuw %x, maxxfr %d, ctype %d\n", 48141480Smckusick desc.d_iuw, desc.d_cmaxxfr, desc.d_ctype); 48241480Smckusick printf(" utype %d, bps %d, blkbuf %d, burst %d, blktime %d\n", 48341480Smckusick desc.d_utype, desc.d_sectsize, 48441480Smckusick desc.d_blkbuf, desc.d_burstsize, desc.d_blocktime); 48541480Smckusick printf(" avxfr %d, ort %d, atp %d, maxint %d, fv %x, rv %x\n", 48641480Smckusick desc.d_uavexfr, desc.d_retry, desc.d_access, 48741480Smckusick desc.d_maxint, desc.d_fvbyte, desc.d_rvbyte); 48841480Smckusick printf(" maxcyl/head/sect %d/%d/%d, maxvsect %d, inter %d\n", 48941480Smckusick desc.d_maxcyl, desc.d_maxhead, desc.d_maxsect, 49041480Smckusick desc.d_maxvsectl, desc.d_interleave); 49141480Smckusick } 49241480Smckusick #endif 49341480Smckusick /* 49441480Smckusick * Take care of a couple of anomolies: 49541480Smckusick * 1. 7945A and 7946A both return same HW id 49641480Smckusick * 2. 9122S and 9134D both return same HW id 49741480Smckusick * 3. 9122D and 9134L both return same HW id 49841480Smckusick */ 49941480Smckusick switch (rdinfo[id].hwid) { 50041480Smckusick case RD7946AID: 50141480Smckusick if (bcmp(name, "079450", 6) == 0) 50241480Smckusick id = RD7945A; 50341480Smckusick else 50441480Smckusick id = RD7946A; 50541480Smckusick break; 50641480Smckusick 50741480Smckusick case RD9134LID: 50841480Smckusick if (bcmp(name, "091340", 6) == 0) 50941480Smckusick id = RD9134L; 51041480Smckusick else 51141480Smckusick id = RD9122D; 51241480Smckusick break; 51341480Smckusick 51441480Smckusick case RD9134DID: 51541480Smckusick if (bcmp(name, "091220", 6) == 0) 51641480Smckusick id = RD9122S; 51741480Smckusick else 51841480Smckusick id = RD9134D; 51941480Smckusick break; 52041480Smckusick } 52141480Smckusick printf("rd%d: %s\n", lunit, rdinfo[id].desc); 52241480Smckusick return(id); 52341480Smckusick } 52441480Smckusick 52541480Smckusick rdreset(rs, hd) 52641480Smckusick register struct rd_softc *rs; 52741480Smckusick register struct hp_device *hd; 52841480Smckusick { 52941480Smckusick u_char stat; 53041480Smckusick 53141480Smckusick rs->sc_clear.c_unit = C_SUNIT(rs->sc_punit); 53241480Smckusick rs->sc_clear.c_cmd = C_CLEAR; 53341480Smckusick hpibsend(hd->hp_ctlr, hd->hp_slave, C_TCMD, &rs->sc_clear, 53441480Smckusick sizeof(rs->sc_clear)); 53541480Smckusick hpibswait(hd->hp_ctlr, hd->hp_slave); 53641480Smckusick hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat)); 53741480Smckusick rs->sc_src.c_unit = C_SUNIT(RDCTLR); 53841480Smckusick rs->sc_src.c_nop = C_NOP; 53941480Smckusick rs->sc_src.c_cmd = C_SREL; 54041480Smckusick rs->sc_src.c_param = C_REL; 54141480Smckusick hpibsend(hd->hp_ctlr, hd->hp_slave, C_CMD, &rs->sc_src, 54241480Smckusick sizeof(rs->sc_src)); 54341480Smckusick hpibswait(hd->hp_ctlr, hd->hp_slave); 54441480Smckusick hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat)); 54541480Smckusick rs->sc_ssmc.c_unit = C_SUNIT(rs->sc_punit); 54641480Smckusick rs->sc_ssmc.c_cmd = C_SSM; 54741480Smckusick rs->sc_ssmc.c_refm = REF_MASK; 54841480Smckusick rs->sc_ssmc.c_fefm = FEF_MASK; 54941480Smckusick rs->sc_ssmc.c_aefm = AEF_MASK; 55041480Smckusick rs->sc_ssmc.c_iefm = IEF_MASK; 55141480Smckusick hpibsend(hd->hp_ctlr, hd->hp_slave, C_CMD, &rs->sc_ssmc, 55241480Smckusick sizeof(rs->sc_ssmc)); 55341480Smckusick hpibswait(hd->hp_ctlr, hd->hp_slave); 55441480Smckusick hpibrecv(hd->hp_ctlr, hd->hp_slave, C_QSTAT, &stat, sizeof(stat)); 55541480Smckusick #ifdef DEBUG 55641480Smckusick rdstats[hd->hp_unit].rdresets++; 55741480Smckusick #endif 55841480Smckusick } 55941480Smckusick 56049303Shibler int 56149303Shibler rdopen(dev, flags, mode, p) 56241480Smckusick dev_t dev; 56349303Shibler int flags, mode; 56449303Shibler struct proc *p; 56541480Smckusick { 56641480Smckusick register int unit = rdunit(dev); 56741480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 56841480Smckusick 56941480Smckusick if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0) 57041480Smckusick return(ENXIO); 57142361Smckusick if (rs->sc_hd->hp_dk >= 0) { 57242361Smckusick /* guess at xfer rate based on 3600 rpm (60 rps) */ 57342361Smckusick if (rs->sc_wpms == 0) 57442361Smckusick rs->sc_wpms = 60 * rs->sc_info->nbpt * DEV_BSIZE / 2; 57542361Smckusick dk_wpms[rs->sc_hd->hp_dk] = rs->sc_wpms; 57642361Smckusick } 57741480Smckusick return(0); 57841480Smckusick } 57941480Smckusick 58041480Smckusick rdstrategy(bp) 58141480Smckusick register struct buf *bp; 58241480Smckusick { 58341480Smckusick register int unit = rdunit(bp->b_dev); 58441480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 58545750Smckusick register struct size *pinfo = &rs->sc_info->sizes[rdpart(bp->b_dev)]; 58641480Smckusick register struct buf *dp = &rdtab[unit]; 58745750Smckusick register daddr_t bn; 58845750Smckusick register int sz, s; 58941480Smckusick 59041480Smckusick #ifdef DEBUG 59141480Smckusick if (rddebug & RDB_FOLLOW) 59241480Smckusick printf("rdstrategy(%x): dev %x, bn %x, bcount %x, %c\n", 59341480Smckusick bp, bp->b_dev, bp->b_blkno, bp->b_bcount, 59441480Smckusick (bp->b_flags & B_READ) ? 'R' : 'W'); 59541480Smckusick #endif 59641480Smckusick bn = bp->b_blkno; 59745750Smckusick sz = howmany(bp->b_bcount, DEV_BSIZE); 59845750Smckusick if (bn < 0 || bn + sz > pinfo->nblocks) { 59945750Smckusick sz = pinfo->nblocks - bn; 60045750Smckusick if (sz == 0) { 60141480Smckusick bp->b_resid = bp->b_bcount; 60241480Smckusick goto done; 60341480Smckusick } 60445750Smckusick if (sz < 0) { 60545750Smckusick bp->b_error = EINVAL; 60645750Smckusick bp->b_flags |= B_ERROR; 60745750Smckusick goto done; 60845750Smckusick } 60945750Smckusick bp->b_bcount = dbtob(sz); 61041480Smckusick } 61145750Smckusick bp->b_cylin = bn / rs->sc_info->nbpc + pinfo->cyloff; 61241480Smckusick s = splbio(); 61341480Smckusick disksort(dp, bp); 61441480Smckusick if (dp->b_active == 0) { 61541480Smckusick dp->b_active = 1; 61641480Smckusick rdustart(unit); 61741480Smckusick } 61841480Smckusick splx(s); 61941480Smckusick return; 62041480Smckusick done: 62141480Smckusick biodone(bp); 62241480Smckusick } 62341480Smckusick 62441480Smckusick /* 62541480Smckusick * Called from timeout() when handling maintenance releases 62641480Smckusick */ 62754770Storek void 62854770Storek rdrestart(arg) 62954770Storek void *arg; 63041480Smckusick { 63141480Smckusick int s = splbio(); 63254770Storek rdustart((int)arg); 63341480Smckusick splx(s); 63441480Smckusick } 63541480Smckusick 63641480Smckusick rdustart(unit) 63741480Smckusick register int unit; 63841480Smckusick { 63941480Smckusick register struct buf *bp; 64041480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 64141480Smckusick 64241480Smckusick bp = rdtab[unit].b_actf; 64341480Smckusick rs->sc_addr = bp->b_un.b_addr; 64441480Smckusick rs->sc_resid = bp->b_bcount; 64541480Smckusick if (hpibreq(&rs->sc_dq)) 64641480Smckusick rdstart(unit); 64741480Smckusick } 64841480Smckusick 64941480Smckusick rdstart(unit) 65041480Smckusick register int unit; 65141480Smckusick { 65241480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 65341480Smckusick register struct buf *bp = rdtab[unit].b_actf; 65441480Smckusick register struct hp_device *hp = rs->sc_hd; 65541480Smckusick register int part; 65641480Smckusick 65741480Smckusick again: 65841480Smckusick #ifdef DEBUG 65941480Smckusick if (rddebug & RDB_FOLLOW) 66041480Smckusick printf("rdstart(%d): bp %x, %c\n", unit, bp, 66141480Smckusick (bp->b_flags & B_READ) ? 'R' : 'W'); 66241480Smckusick #endif 66341480Smckusick part = rdpart(bp->b_dev); 66441480Smckusick rs->sc_flags |= RDF_SEEK; 66541480Smckusick rs->sc_ioc.c_unit = C_SUNIT(rs->sc_punit); 66641480Smckusick rs->sc_ioc.c_volume = C_SVOL(0); 66741480Smckusick rs->sc_ioc.c_saddr = C_SADDR; 66841480Smckusick rs->sc_ioc.c_hiaddr = 0; 66941480Smckusick rs->sc_ioc.c_addr = RDBTOS(bp->b_blkno + rs->sc_info->nbpc * 67041480Smckusick rs->sc_info->sizes[part].cyloff); 67141480Smckusick rs->sc_ioc.c_nop2 = C_NOP; 67241480Smckusick rs->sc_ioc.c_slen = C_SLEN; 67341480Smckusick rs->sc_ioc.c_len = rs->sc_resid; 67441480Smckusick rs->sc_ioc.c_cmd = bp->b_flags & B_READ ? C_READ : C_WRITE; 67541480Smckusick #ifdef DEBUG 67641480Smckusick if (rddebug & RDB_IO) 67741480Smckusick printf("rdstart: hpibsend(%x, %x, %x, %x, %x)\n", 67841480Smckusick hp->hp_ctlr, hp->hp_slave, C_CMD, 67941480Smckusick &rs->sc_ioc.c_unit, sizeof(rs->sc_ioc)-2); 68041480Smckusick #endif 68141480Smckusick if (hpibsend(hp->hp_ctlr, hp->hp_slave, C_CMD, &rs->sc_ioc.c_unit, 68241480Smckusick sizeof(rs->sc_ioc)-2) == sizeof(rs->sc_ioc)-2) { 68341480Smckusick if (hp->hp_dk >= 0) { 68441480Smckusick dk_busy |= 1 << hp->hp_dk; 68541480Smckusick dk_seek[hp->hp_dk]++; 68641480Smckusick } 68741480Smckusick #ifdef DEBUG 68841480Smckusick if (rddebug & RDB_IO) 68941480Smckusick printf("rdstart: hpibawait(%x)\n", hp->hp_ctlr); 69041480Smckusick #endif 69141480Smckusick hpibawait(hp->hp_ctlr); 69241480Smckusick return; 69341480Smckusick } 69441480Smckusick /* 69541480Smckusick * Experience has shown that the hpibwait in this hpibsend will 69641480Smckusick * occasionally timeout. It appears to occur mostly on old 7914 69741480Smckusick * drives with full maintenance tracks. We should probably 69841480Smckusick * integrate this with the backoff code in rderror. 69941480Smckusick */ 70041480Smckusick #ifdef DEBUG 70141480Smckusick if (rddebug & RDB_ERROR) 70241480Smckusick printf("rd%d: rdstart: cmd %x adr %d blk %d len %d ecnt %d\n", 70341480Smckusick unit, rs->sc_ioc.c_cmd, rs->sc_ioc.c_addr, 70441480Smckusick bp->b_blkno, rs->sc_resid, rdtab[unit].b_errcnt); 70541480Smckusick rdstats[unit].rdretries++; 70641480Smckusick #endif 70741480Smckusick rs->sc_flags &= ~RDF_SEEK; 70841480Smckusick rdreset(rs, hp); 70941480Smckusick if (rdtab[unit].b_errcnt++ < RDRETRY) 71041480Smckusick goto again; 71141480Smckusick printf("rd%d: rdstart err: cmd 0x%x sect %d blk %d len %d\n", 71241480Smckusick unit, rs->sc_ioc.c_cmd, rs->sc_ioc.c_addr, 71341480Smckusick bp->b_blkno, rs->sc_resid); 71441480Smckusick rdtab[unit].b_errcnt = 0; 71541480Smckusick rdtab[unit].b_actf = bp->b_actf; 71641480Smckusick bp->b_flags |= B_ERROR; 71741480Smckusick bp->b_error = EIO; 71841480Smckusick bp->b_resid = 0; 71941480Smckusick biodone(bp); 72041480Smckusick hpibfree(&rs->sc_dq); 72141480Smckusick bp = rdtab[unit].b_actf; 72241480Smckusick if (bp == NULL) { 72341480Smckusick rdtab[unit].b_active = 0; 72441480Smckusick return; 72541480Smckusick } 72641480Smckusick rs->sc_addr = bp->b_un.b_addr; 72741480Smckusick rs->sc_resid = bp->b_bcount; 72841480Smckusick if (hpibreq(&rs->sc_dq)) 72941480Smckusick goto again; 73041480Smckusick } 73141480Smckusick 73241480Smckusick rdgo(unit) 73341480Smckusick register int unit; 73441480Smckusick { 73541480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 73641480Smckusick register struct hp_device *hp = rs->sc_hd; 73741480Smckusick struct buf *bp = rdtab[unit].b_actf; 73841480Smckusick 73941480Smckusick if (hp->hp_dk >= 0) { 74041480Smckusick dk_busy |= 1 << hp->hp_dk; 74141480Smckusick dk_xfer[hp->hp_dk]++; 74241480Smckusick dk_wds[hp->hp_dk] += rs->sc_resid >> 6; 74341480Smckusick } 74441480Smckusick hpibgo(hp->hp_ctlr, hp->hp_slave, C_EXEC, 74541480Smckusick rs->sc_addr, rs->sc_resid, bp->b_flags & B_READ); 74641480Smckusick } 74741480Smckusick 74841480Smckusick rdintr(unit) 74941480Smckusick register int unit; 75041480Smckusick { 75141480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 75241480Smckusick register struct buf *bp = rdtab[unit].b_actf; 75341480Smckusick register struct hp_device *hp = rs->sc_hd; 75441480Smckusick u_char stat = 13; /* in case hpibrecv fails */ 75545750Smckusick int rv, restart; 75641480Smckusick 75741480Smckusick #ifdef DEBUG 75841480Smckusick if (rddebug & RDB_FOLLOW) 75941480Smckusick printf("rdintr(%d): bp %x, %c, flags %x\n", unit, bp, 76041480Smckusick (bp->b_flags & B_READ) ? 'R' : 'W', rs->sc_flags); 76141480Smckusick if (bp == NULL) { 76241480Smckusick printf("rd%d: bp == NULL\n", unit); 76341480Smckusick return; 76441480Smckusick } 76541480Smckusick #endif 76641480Smckusick if (hp->hp_dk >= 0) 76741480Smckusick dk_busy &= ~(1 << hp->hp_dk); 76841480Smckusick if (rs->sc_flags & RDF_SEEK) { 76941480Smckusick rs->sc_flags &= ~RDF_SEEK; 77041480Smckusick if (hpibustart(hp->hp_ctlr)) 77141480Smckusick rdgo(unit); 77241480Smckusick return; 77341480Smckusick } 77441480Smckusick if ((rs->sc_flags & RDF_SWAIT) == 0) { 77541480Smckusick #ifdef DEBUG 77641480Smckusick rdstats[unit].rdpolltries++; 77741480Smckusick #endif 77841480Smckusick if (hpibpptest(hp->hp_ctlr, hp->hp_slave) == 0) { 77941480Smckusick #ifdef DEBUG 78041480Smckusick rdstats[unit].rdpollwaits++; 78141480Smckusick #endif 78241480Smckusick if (hp->hp_dk >= 0) 78341480Smckusick dk_busy |= 1 << hp->hp_dk; 78441480Smckusick rs->sc_flags |= RDF_SWAIT; 78541480Smckusick hpibawait(hp->hp_ctlr); 78641480Smckusick return; 78741480Smckusick } 78841480Smckusick } else 78941480Smckusick rs->sc_flags &= ~RDF_SWAIT; 79045750Smckusick rv = hpibrecv(hp->hp_ctlr, hp->hp_slave, C_QSTAT, &stat, 1); 79145750Smckusick if (rv != 1 || stat) { 79241480Smckusick #ifdef DEBUG 79341480Smckusick if (rddebug & RDB_ERROR) 79441480Smckusick printf("rdintr: recv failed or bad stat %d\n", stat); 79541480Smckusick #endif 79641480Smckusick restart = rderror(unit); 79741480Smckusick #ifdef DEBUG 79841480Smckusick rdstats[unit].rdretries++; 79941480Smckusick #endif 80041480Smckusick if (rdtab[unit].b_errcnt++ < RDRETRY) { 80141480Smckusick if (restart) 80241480Smckusick rdstart(unit); 80341480Smckusick return; 80441480Smckusick } 80541480Smckusick bp->b_flags |= B_ERROR; 80641480Smckusick bp->b_error = EIO; 80741480Smckusick } 80841480Smckusick rdtab[unit].b_errcnt = 0; 80941480Smckusick rdtab[unit].b_actf = bp->b_actf; 81041480Smckusick bp->b_resid = 0; 81141480Smckusick biodone(bp); 81241480Smckusick hpibfree(&rs->sc_dq); 81341480Smckusick if (rdtab[unit].b_actf) 81441480Smckusick rdustart(unit); 81541480Smckusick else 81641480Smckusick rdtab[unit].b_active = 0; 81741480Smckusick } 81841480Smckusick 81941480Smckusick rdstatus(rs) 82041480Smckusick register struct rd_softc *rs; 82141480Smckusick { 82241480Smckusick register int c, s; 82341480Smckusick u_char stat; 82441480Smckusick int rv; 82541480Smckusick 82641480Smckusick c = rs->sc_hd->hp_ctlr; 82741480Smckusick s = rs->sc_hd->hp_slave; 82841480Smckusick rs->sc_rsc.c_unit = C_SUNIT(rs->sc_punit); 82941480Smckusick rs->sc_rsc.c_sram = C_SRAM; 83041480Smckusick rs->sc_rsc.c_ram = C_RAM; 83141480Smckusick rs->sc_rsc.c_cmd = C_STATUS; 83241480Smckusick bzero((caddr_t)&rs->sc_stat, sizeof(rs->sc_stat)); 83341480Smckusick rv = hpibsend(c, s, C_CMD, &rs->sc_rsc, sizeof(rs->sc_rsc)); 83441480Smckusick if (rv != sizeof(rs->sc_rsc)) { 83541480Smckusick #ifdef DEBUG 83641480Smckusick if (rddebug & RDB_STATUS) 83741480Smckusick printf("rdstatus: send C_CMD failed %d != %d\n", 83841480Smckusick rv, sizeof(rs->sc_rsc)); 83941480Smckusick #endif 84041480Smckusick return(1); 84141480Smckusick } 84241480Smckusick rv = hpibrecv(c, s, C_EXEC, &rs->sc_stat, sizeof(rs->sc_stat)); 84341480Smckusick if (rv != sizeof(rs->sc_stat)) { 84441480Smckusick #ifdef DEBUG 84541480Smckusick if (rddebug & RDB_STATUS) 84641480Smckusick printf("rdstatus: send C_EXEC failed %d != %d\n", 84741480Smckusick rv, sizeof(rs->sc_stat)); 84841480Smckusick #endif 84941480Smckusick return(1); 85041480Smckusick } 85141480Smckusick rv = hpibrecv(c, s, C_QSTAT, &stat, 1); 85241480Smckusick if (rv != 1 || stat) { 85341480Smckusick #ifdef DEBUG 85441480Smckusick if (rddebug & RDB_STATUS) 85541480Smckusick printf("rdstatus: recv failed %d or bad stat %d\n", 85641480Smckusick rv, stat); 85741480Smckusick #endif 85841480Smckusick return(1); 85941480Smckusick } 86041480Smckusick return(0); 86141480Smckusick } 86241480Smckusick 86341480Smckusick /* 86441480Smckusick * Deal with errors. 86541480Smckusick * Returns 1 if request should be restarted, 86641480Smckusick * 0 if we should just quietly give up. 86741480Smckusick */ 86841480Smckusick rderror(unit) 86941480Smckusick int unit; 87041480Smckusick { 87141480Smckusick struct rd_softc *rs = &rd_softc[unit]; 87241480Smckusick register struct rd_stat *sp; 87341480Smckusick struct buf *bp; 87442361Smckusick daddr_t hwbn, pbn; 87541480Smckusick 87641480Smckusick if (rdstatus(rs)) { 87741480Smckusick #ifdef DEBUG 87841480Smckusick printf("rd%d: couldn't get status\n", unit); 87941480Smckusick #endif 88041480Smckusick rdreset(rs, rs->sc_hd); 88141480Smckusick return(1); 88241480Smckusick } 88341480Smckusick sp = &rs->sc_stat; 88441480Smckusick if (sp->c_fef & FEF_REXMT) 88541480Smckusick return(1); 88641480Smckusick if (sp->c_fef & FEF_PF) { 88741480Smckusick rdreset(rs, rs->sc_hd); 88841480Smckusick return(1); 88941480Smckusick } 89041480Smckusick /* 89141480Smckusick * Unit requests release for internal maintenance. 89241480Smckusick * We just delay awhile and try again later. Use expontially 89341480Smckusick * increasing backoff ala ethernet drivers since we don't really 89441480Smckusick * know how long the maintenance will take. With RDWAITC and 89541480Smckusick * RDRETRY as defined, the range is 1 to 32 seconds. 89641480Smckusick */ 89741480Smckusick if (sp->c_fef & FEF_IMR) { 89841480Smckusick extern int hz; 89941480Smckusick int rdtimo = RDWAITC << rdtab[unit].b_errcnt; 90041480Smckusick #ifdef DEBUG 90141480Smckusick printf("rd%d: internal maintenance, %d second timeout\n", 90241480Smckusick unit, rdtimo); 90341480Smckusick rdstats[unit].rdtimeouts++; 90441480Smckusick #endif 90541480Smckusick hpibfree(&rs->sc_dq); 90654770Storek timeout(rdrestart, (void *)unit, rdtimo * hz); 90741480Smckusick return(0); 90841480Smckusick } 90941480Smckusick /* 91042361Smckusick * Only report error if we have reached the error reporting 91142361Smckusick * threshhold. By default, this will only report after the 91242361Smckusick * retry limit has been exceeded. 91342361Smckusick */ 91442361Smckusick if (rdtab[unit].b_errcnt < rderrthresh) 91542361Smckusick return(1); 91642361Smckusick 91742361Smckusick /* 91841480Smckusick * First conjure up the block number at which the error occured. 91941480Smckusick * Note that not all errors report a block number, in that case 92041480Smckusick * we just use b_blkno. 92141480Smckusick */ 92242361Smckusick bp = rdtab[unit].b_actf; 92342361Smckusick pbn = rs->sc_info->nbpc * 92442361Smckusick rs->sc_info->sizes[rdpart(bp->b_dev)].cyloff; 92541480Smckusick if ((sp->c_fef & FEF_CU) || (sp->c_fef & FEF_DR) || 92641480Smckusick (sp->c_ief & IEF_RRMASK)) { 92742361Smckusick hwbn = RDBTOS(pbn + bp->b_blkno); 92841480Smckusick pbn = bp->b_blkno; 92941480Smckusick } else { 93042361Smckusick hwbn = sp->c_blk; 93142361Smckusick pbn = RDSTOB(hwbn) - pbn; 93241480Smckusick } 93341480Smckusick /* 93441480Smckusick * Now output a generic message suitable for badsect. 93541480Smckusick * Note that we don't use harderr cuz it just prints 93641480Smckusick * out b_blkno which is just the beginning block number 93741480Smckusick * of the transfer, not necessary where the error occured. 93841480Smckusick */ 93941480Smckusick printf("rd%d%c: hard error sn%d\n", 94041480Smckusick rdunit(bp->b_dev), 'a'+rdpart(bp->b_dev), pbn); 94141480Smckusick /* 94241480Smckusick * Now report the status as returned by the hardware with 94341480Smckusick * attempt at interpretation (unless debugging). 94441480Smckusick */ 94541480Smckusick printf("rd%d %s error:", 94641480Smckusick unit, (bp->b_flags & B_READ) ? "read" : "write"); 94741480Smckusick #ifdef DEBUG 94841480Smckusick if (rddebug & RDB_ERROR) { 94941480Smckusick /* status info */ 95041480Smckusick printf("\n volume: %d, unit: %d\n", 95141480Smckusick (sp->c_vu>>4)&0xF, sp->c_vu&0xF); 95241480Smckusick rdprinterr("reject", sp->c_ref, err_reject); 95341480Smckusick rdprinterr("fault", sp->c_fef, err_fault); 95441480Smckusick rdprinterr("access", sp->c_aef, err_access); 95541480Smckusick rdprinterr("info", sp->c_ief, err_info); 95642361Smckusick printf(" block: %d, P1-P10: ", hwbn); 95741480Smckusick printf("%s", hexstr(*(u_int *)&sp->c_raw[0], 8)); 95841480Smckusick printf("%s", hexstr(*(u_int *)&sp->c_raw[4], 8)); 95941480Smckusick printf("%s\n", hexstr(*(u_short *)&sp->c_raw[8], 4)); 96041480Smckusick /* command */ 96141480Smckusick printf(" ioc: "); 96241480Smckusick printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_pad, 8)); 96341480Smckusick printf("%s", hexstr(*(u_short *)&rs->sc_ioc.c_hiaddr, 4)); 96441480Smckusick printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_addr, 8)); 96541480Smckusick printf("%s", hexstr(*(u_short *)&rs->sc_ioc.c_nop2, 4)); 96641480Smckusick printf("%s", hexstr(*(u_int *)&rs->sc_ioc.c_len, 8)); 96741480Smckusick printf("%s\n", hexstr(*(u_short *)&rs->sc_ioc.c_cmd, 4)); 96841480Smckusick return(1); 96941480Smckusick } 97041480Smckusick #endif 97141480Smckusick printf(" v%d u%d, R0x%x F0x%x A0x%x I0x%x\n", 97241480Smckusick (sp->c_vu>>4)&0xF, sp->c_vu&0xF, 97341480Smckusick sp->c_ref, sp->c_fef, sp->c_aef, sp->c_ief); 97441480Smckusick printf("P1-P10: "); 97541480Smckusick printf("%s", hexstr(*(u_int *)&sp->c_raw[0], 8)); 97641480Smckusick printf("%s", hexstr(*(u_int *)&sp->c_raw[4], 8)); 97741480Smckusick printf("%s\n", hexstr(*(u_short *)&sp->c_raw[8], 4)); 97841480Smckusick return(1); 97941480Smckusick } 98041480Smckusick 98149303Shibler int 98249303Shibler rdread(dev, uio, flags) 98341480Smckusick dev_t dev; 98441480Smckusick struct uio *uio; 98549303Shibler int flags; 98641480Smckusick { 98741480Smckusick register int unit = rdunit(dev); 98841480Smckusick 98949303Shibler return (physio(rdstrategy, NULL, dev, B_READ, minphys, uio)); 99041480Smckusick } 99141480Smckusick 99249303Shibler int 99349303Shibler rdwrite(dev, uio, flags) 99441480Smckusick dev_t dev; 99541480Smckusick struct uio *uio; 99649303Shibler int flags; 99741480Smckusick { 99841480Smckusick register int unit = rdunit(dev); 99941480Smckusick 100049303Shibler return (physio(rdstrategy, NULL, dev, B_WRITE, minphys, uio)); 100141480Smckusick } 100241480Smckusick 100349303Shibler int 100449303Shibler rdioctl(dev, cmd, data, flag, p) 100541480Smckusick dev_t dev; 100641480Smckusick int cmd; 100741480Smckusick caddr_t data; 100841480Smckusick int flag; 100949303Shibler struct proc *p; 101041480Smckusick { 101141480Smckusick return(EINVAL); 101241480Smckusick } 101341480Smckusick 101449303Shibler int 101541480Smckusick rdsize(dev) 101641480Smckusick dev_t dev; 101741480Smckusick { 101841480Smckusick register int unit = rdunit(dev); 101941480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 102041480Smckusick 102141480Smckusick if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0) 102241480Smckusick return(-1); 102341480Smckusick return(rs->sc_info->sizes[rdpart(dev)].nblocks); 102441480Smckusick } 102541480Smckusick 102641480Smckusick #ifdef DEBUG 102741480Smckusick rdprinterr(str, err, tab) 102841480Smckusick char *str; 102941480Smckusick short err; 103041480Smckusick char *tab[]; 103141480Smckusick { 103241480Smckusick register int i; 103341480Smckusick int printed; 103441480Smckusick 103541480Smckusick if (err == 0) 103641480Smckusick return; 103741480Smckusick printf(" %s error field:", str, err); 103841480Smckusick printed = 0; 103941480Smckusick for (i = 0; i < 16; i++) 104041480Smckusick if (err & (0x8000 >> i)) 104141480Smckusick printf("%s%s", printed++ ? " + " : " ", tab[i]); 104241480Smckusick printf("\n"); 104341480Smckusick } 104441480Smckusick #endif 104541480Smckusick 104641480Smckusick /* 104741480Smckusick * Non-interrupt driven, non-dma dump routine. 104841480Smckusick */ 104949303Shibler int 105041480Smckusick rddump(dev) 105141480Smckusick dev_t dev; 105241480Smckusick { 105341480Smckusick int part = rdpart(dev); 105441480Smckusick int unit = rdunit(dev); 105541480Smckusick register struct rd_softc *rs = &rd_softc[unit]; 105641480Smckusick register struct hp_device *hp = rs->sc_hd; 105741480Smckusick register daddr_t baddr; 105845750Smckusick register int maddr, pages, i; 105941480Smckusick char stat; 106041480Smckusick extern int lowram, dumpsize; 106145750Smckusick #ifdef DEBUG 106245750Smckusick extern int pmapdebug; 106345750Smckusick pmapdebug = 0; 106445750Smckusick #endif 106541480Smckusick 106641480Smckusick pages = dumpsize; 106741480Smckusick #ifdef DEBUG 106841480Smckusick if (rddebug & RDB_DUMP) 106941480Smckusick printf("rddump(%x): u %d p %d dumplo %d ram %x pmem %d\n", 107041480Smckusick dev, unit, part, dumplo, lowram, ctod(pages)); 107141480Smckusick #endif 107241480Smckusick /* is drive ok? */ 107341480Smckusick if (unit >= NRD || (rs->sc_flags & RDF_ALIVE) == 0) 107441480Smckusick return (ENXIO); 107541480Smckusick /* HPIB idle? */ 107641480Smckusick if (!hpibreq(&rs->sc_dq)) { 107741480Smckusick #ifdef DEBUG 107841480Smckusick /* is this a safe thing to do?? */ 107941480Smckusick hpibreset(hp->hp_ctlr); 108041480Smckusick rdreset(rs, rs->sc_hd); 108141480Smckusick printf("[ drive %d reset ] ", unit); 108241480Smckusick #else 108341480Smckusick return (EFAULT); 108441480Smckusick #endif 108541480Smckusick } 108641480Smckusick /* dump parameters in range? */ 108741480Smckusick if (dumplo < 0 || dumplo >= rs->sc_info->sizes[part].nblocks) 108841480Smckusick return (EINVAL); 108941480Smckusick if (dumplo + ctod(pages) > rs->sc_info->sizes[part].nblocks) 109041480Smckusick pages = dtoc(rs->sc_info->sizes[part].nblocks - dumplo); 109141480Smckusick maddr = lowram; 109241480Smckusick baddr = dumplo + rs->sc_info->nbpc * rs->sc_info->sizes[part].cyloff; 109341480Smckusick #ifdef DEBUG 109441480Smckusick if (rddebug & RDB_DUMP) 109541480Smckusick printf("rddump: dumping %d pages from %x to disk block %d\n", 109641480Smckusick pages, maddr, baddr); 109741480Smckusick #endif 109841480Smckusick for (i = 0; i < pages; i++) { 109941480Smckusick #ifdef DEBUG 110041480Smckusick #define NPGMB (1024*1024/NBPG) 110141480Smckusick /* print out how many Mbs we have dumped */ 110241480Smckusick if (i && (i % NPGMB) == 0) 110341480Smckusick printf("%d ", i / NPGMB); 110441480Smckusick #undef NPBMG 110541480Smckusick #endif 110641480Smckusick rs->sc_ioc.c_unit = C_SUNIT(rs->sc_punit); 110741480Smckusick rs->sc_ioc.c_volume = C_SVOL(0); 110841480Smckusick rs->sc_ioc.c_saddr = C_SADDR; 110941480Smckusick rs->sc_ioc.c_hiaddr = 0; 111041480Smckusick rs->sc_ioc.c_addr = RDBTOS(baddr); 111141480Smckusick rs->sc_ioc.c_nop2 = C_NOP; 111241480Smckusick rs->sc_ioc.c_slen = C_SLEN; 111341480Smckusick rs->sc_ioc.c_len = NBPG; 111441480Smckusick rs->sc_ioc.c_cmd = C_WRITE; 111541480Smckusick hpibsend(hp->hp_ctlr, hp->hp_slave, C_CMD, 111641480Smckusick &rs->sc_ioc.c_unit, sizeof(rs->sc_ioc)-2); 111741480Smckusick if (hpibswait(hp->hp_ctlr, hp->hp_slave)) { 111841480Smckusick #ifdef DEBUG 111941480Smckusick if (rddebug & RDB_DUMP) 112041480Smckusick printf("rddump: IOC wait timeout\n"); 112141480Smckusick #endif 112241480Smckusick return (EIO); 112341480Smckusick } 112452614Smckusick pmap_enter(kernel_pmap, (vm_offset_t)vmmap, maddr, 112551576Smckusick VM_PROT_READ, TRUE); 112641480Smckusick hpibsend(hp->hp_ctlr, hp->hp_slave, C_EXEC, vmmap, NBPG); 112741480Smckusick if (hpibswait(hp->hp_ctlr, hp->hp_slave)) { 112841480Smckusick #ifdef DEBUG 112941480Smckusick if (rddebug & RDB_DUMP) 113041480Smckusick printf("rddump: write wait timeout\n"); 113141480Smckusick #endif 113241480Smckusick } 113341480Smckusick hpibrecv(hp->hp_ctlr, hp->hp_slave, C_QSTAT, &stat, 1); 113441480Smckusick if (stat) { 113541480Smckusick #ifdef DEBUG 113641480Smckusick if (rddebug & RDB_DUMP) 113741480Smckusick printf("rddump: write failed, status %x\n", 113841480Smckusick stat); 113941480Smckusick #endif 114041480Smckusick return (EIO); 114141480Smckusick } 114241480Smckusick maddr += NBPG; 114341480Smckusick baddr += ctod(1); 114441480Smckusick } 114541480Smckusick return (0); 114641480Smckusick } 114741480Smckusick #endif 1148