123353Smckusick /* 235039Sbostic * Copyright (c) 1988 Regents of the University of California. 335039Sbostic * All rights reserved. 432523Sbostic * 535039Sbostic * This code is derived from software contributed to Berkeley by 635039Sbostic * Chris Torek. 732523Sbostic * 8*44554Sbostic * %sccs.include.redist.c% 935039Sbostic * 10*44554Sbostic * @(#)uda.c 7.28 (Berkeley) 06/28/90 1123353Smckusick */ 1223353Smckusick 1332523Sbostic /* 1432523Sbostic * UDA50/MSCP device driver 1517553Skarels */ 1617553Skarels 1732523Sbostic #define POLLSTATS 1832523Sbostic 1932523Sbostic /* 2032523Sbostic * TODO 2132523Sbostic * write bad block forwarding code 2232523Sbostic */ 2332523Sbostic 244743Swnj #include "ra.h" 2532523Sbostic 2617642Skarels #if NUDA > 0 2732523Sbostic 284743Swnj /* 2932523Sbostic * CONFIGURATION OPTIONS. The next three defines are tunable -- tune away! 304743Swnj * 3132523Sbostic * COMPAT_42 enables 4.2/4.3 compatibility (label mapping) 3232523Sbostic * 3332523Sbostic * NRSPL2 and NCMDL2 control the number of response and command 3432523Sbostic * packets respectively. They may be any value from 0 to 7, though 3532523Sbostic * setting them higher than 5 is unlikely to be of any value. 3632523Sbostic * If you get warnings about your command ring being too small, 3732523Sbostic * try increasing the values by one. 3832523Sbostic * 3932523Sbostic * MAXUNIT controls the maximum unit number (number of drives per 4032523Sbostic * controller) we are prepared to handle. 4132523Sbostic * 4232523Sbostic * DEFAULT_BURST must be at least 1. 434743Swnj */ 4432523Sbostic #define COMPAT_42 4532523Sbostic 4632523Sbostic #define NRSPL2 5 /* log2 number of response packets */ 4732523Sbostic #define NCMDL2 5 /* log2 number of command packets */ 4832523Sbostic #define MAXUNIT 8 /* maximum allowed unit number */ 4932523Sbostic #define DEFAULT_BURST 4 /* default DMA burst size */ 5032523Sbostic 5117553Skarels #include "param.h" 5217553Skarels #include "systm.h" 5317553Skarels #include "buf.h" 5417553Skarels #include "conf.h" 5530536Skarels #include "file.h" 5630536Skarels #include "ioctl.h" 5717553Skarels #include "user.h" 5817553Skarels #include "map.h" 5917553Skarels #include "vm.h" 6030536Skarels #include "dkstat.h" 6117553Skarels #include "cmap.h" 6230536Skarels #include "disklabel.h" 6330536Skarels #include "syslog.h" 6430773Skarels #include "stat.h" 654743Swnj 6637512Smckusick #include "machine/pte.h" 6734283Skarels 688482Sroot #include "../vax/cpu.h" 6917553Skarels #include "ubareg.h" 7017553Skarels #include "ubavar.h" 718613Sroot 7232523Sbostic #define NRSP (1 << NRSPL2) 7332523Sbostic #define NCMD (1 << NCMDL2) 748613Sroot 7532523Sbostic #include "udareg.h" 768482Sroot #include "../vax/mscp.h" 7732523Sbostic #include "../vax/mscpvar.h" 7832523Sbostic #include "../vax/mtpr.h" 794743Swnj 8032523Sbostic /* 8132523Sbostic * UDA communications area and MSCP packet pools, per controller. 8232523Sbostic */ 8332523Sbostic struct uda { 8432523Sbostic struct udaca uda_ca; /* communications area */ 8532523Sbostic struct mscp uda_rsp[NRSP]; /* response packets */ 8632523Sbostic struct mscp uda_cmd[NCMD]; /* command packets */ 874743Swnj } uda[NUDA]; 884743Swnj 8932523Sbostic /* 9032523Sbostic * Software status, per controller. 9132523Sbostic */ 9232523Sbostic struct uda_softc { 9332523Sbostic struct uda *sc_uda; /* Unibus address of uda struct */ 9432523Sbostic short sc_state; /* UDA50 state; see below */ 9532523Sbostic short sc_flags; /* flags; see below */ 9632523Sbostic int sc_micro; /* microcode revision */ 9732523Sbostic int sc_ivec; /* interrupt vector address */ 9836036Skarels short sc_ipl; /* interrupt priority, Q-bus */ 9932523Sbostic struct mscp_info sc_mi;/* MSCP info (per mscpvar.h) */ 10032523Sbostic #ifndef POLLSTATS 10132523Sbostic int sc_wticks; /* watchdog timer ticks */ 10232523Sbostic #else 10332523Sbostic short sc_wticks; 10432523Sbostic short sc_ncmd; 10532523Sbostic #endif 10632523Sbostic } uda_softc[NUDA]; 10724742Sbloom 10832523Sbostic #ifdef POLLSTATS 10932523Sbostic struct udastats { 11032523Sbostic int ncmd; 11132523Sbostic int cmd[NCMD + 1]; 11232523Sbostic } udastats = { NCMD + 1 }; 11332523Sbostic #endif 11417553Skarels 11532523Sbostic /* 11632523Sbostic * Controller states 11732523Sbostic */ 11832523Sbostic #define ST_IDLE 0 /* uninitialised */ 11932523Sbostic #define ST_STEP1 1 /* in `STEP 1' */ 12032523Sbostic #define ST_STEP2 2 /* in `STEP 2' */ 12132523Sbostic #define ST_STEP3 3 /* in `STEP 3' */ 12232523Sbostic #define ST_SETCHAR 4 /* in `Set Controller Characteristics' */ 12332523Sbostic #define ST_RUN 5 /* up and running */ 1244743Swnj 12532523Sbostic /* 12632523Sbostic * Flags 12732523Sbostic */ 12832523Sbostic #define SC_MAPPED 0x01 /* mapped in Unibus I/O space */ 12932523Sbostic #define SC_INSTART 0x02 /* inside udastart() */ 13032523Sbostic #define SC_GRIPED 0x04 /* griped about cmd ring too small */ 13132523Sbostic #define SC_INSLAVE 0x08 /* inside udaslave() */ 13232523Sbostic #define SC_DOWAKE 0x10 /* wakeup when ctlr init done */ 13332523Sbostic #define SC_STARTPOLL 0x20 /* need to initiate polling */ 13412421Ssam 13532523Sbostic /* 13632523Sbostic * Device to unit number and partition and back 13732523Sbostic */ 13832523Sbostic #define UNITSHIFT 3 13932523Sbostic #define UNITMASK 7 14032523Sbostic #define udaunit(dev) (minor(dev) >> UNITSHIFT) 14132523Sbostic #define udapart(dev) (minor(dev) & UNITMASK) 14232523Sbostic #define udaminor(u, p) (((u) << UNITSHIFT) | (p)) 1434743Swnj 14417553Skarels /* 14532523Sbostic * Drive status, per drive 14617553Skarels */ 14732523Sbostic struct ra_info { 14832523Sbostic daddr_t ra_dsize; /* size in sectors */ 14933444Sbostic /* u_long ra_type; /* drive type */ 15032523Sbostic u_long ra_mediaid; /* media id */ 15132523Sbostic int ra_state; /* open/closed state */ 15232523Sbostic struct ra_geom { /* geometry information */ 15332523Sbostic u_short rg_nsectors; /* sectors/track */ 15432523Sbostic u_short rg_ngroups; /* track groups */ 15532523Sbostic u_short rg_ngpc; /* groups/cylinder */ 15632523Sbostic u_short rg_ntracks; /* ngroups*ngpc */ 15732523Sbostic u_short rg_ncyl; /* ra_dsize/ntracks/nsectors */ 15832523Sbostic #ifdef notyet 15932523Sbostic u_short rg_rctsize; /* size of rct */ 16032523Sbostic u_short rg_rbns; /* replacement blocks per track */ 16132523Sbostic u_short rg_nrct; /* number of rct copies */ 16232523Sbostic #endif 16332523Sbostic } ra_geom; 16433443Skarels int ra_wlabel; /* label sector is currently writable */ 16532523Sbostic u_long ra_openpart; /* partitions open */ 16632523Sbostic u_long ra_bopenpart; /* block partitions open */ 16732523Sbostic u_long ra_copenpart; /* character partitions open */ 16832523Sbostic } ra_info[NRA]; 16917553Skarels 17030536Skarels /* 17130536Skarels * Software state, per drive 17230536Skarels */ 17330536Skarels #define CLOSED 0 17430536Skarels #define WANTOPEN 1 17530536Skarels #define RDLABEL 2 17630536Skarels #define OPEN 3 17730536Skarels #define OPENRAW 4 17817553Skarels 17932523Sbostic /* 18032523Sbostic * Definition of the driver for autoconf. 18132523Sbostic */ 18232523Sbostic int udaprobe(), udaslave(), udaattach(), udadgo(), udaintr(); 18332523Sbostic struct uba_ctlr *udaminfo[NUDA]; 18432523Sbostic struct uba_device *udadinfo[NRA]; 18532523Sbostic struct disklabel udalabel[NRA]; 18617553Skarels 18732523Sbostic u_short udastd[] = { 0772150, 0772550, 0777550, 0 }; 18832523Sbostic struct uba_driver udadriver = 18932523Sbostic { udaprobe, udaslave, udaattach, udadgo, udastd, "ra", udadinfo, "uda", 19032523Sbostic udaminfo }; 19117553Skarels 19232523Sbostic /* 19332523Sbostic * More driver definitions, for generic MSCP code. 19432523Sbostic */ 19532523Sbostic int udadgram(), udactlrdone(), udaunconf(), udaiodone(); 19632523Sbostic int udaonline(), udagotstatus(), udaioerror(), udareplace(), udabb(); 1974743Swnj 19832523Sbostic struct buf udautab[NRA]; /* per drive transfer queue */ 1994743Swnj 20032523Sbostic struct mscp_driver udamscpdriver = 20134524Skarels { MAXUNIT, NRA, UNITSHIFT, udautab, udalabel, udadinfo, 20232523Sbostic udadgram, udactlrdone, udaunconf, udaiodone, 20332523Sbostic udaonline, udagotstatus, udareplace, udaioerror, udabb, 20432523Sbostic "uda", "ra" }; 20532523Sbostic 20632523Sbostic /* 20732523Sbostic * Miscellaneous private variables. 20832523Sbostic */ 20932523Sbostic char udasr_bits[] = UDASR_BITS; 21032523Sbostic 21132523Sbostic struct uba_device *udaip[NUDA][MAXUNIT]; 21232523Sbostic /* inverting pointers: ctlr & unit => Unibus 21332523Sbostic device pointer */ 21432523Sbostic 21532523Sbostic int udaburst[NUDA] = { 0 }; /* burst size, per UDA50, zero => default; 21632523Sbostic in data space so patchable via adb */ 21732523Sbostic 21832523Sbostic struct mscp udaslavereply; /* get unit status response packet, set 21932523Sbostic for udaslave by udaunconf, via udaintr */ 22032523Sbostic 22132523Sbostic static struct uba_ctlr *probeum;/* this is a hack---autoconf should pass ctlr 22232523Sbostic info to slave routine; instead, we remember 22332523Sbostic the last ctlr argument to probe */ 22432523Sbostic 22532523Sbostic int udawstart, udawatch(); /* watchdog timer */ 22632523Sbostic 22732523Sbostic /* 22832523Sbostic * Externals 22932523Sbostic */ 23032523Sbostic int wakeup(); 23132523Sbostic int hz; 23232523Sbostic 23332523Sbostic /* 23432523Sbostic * Poke at a supposed UDA50 to see if it is there. 23532523Sbostic * This routine duplicates some of the code in udainit() only 23632523Sbostic * because autoconf has not set up the right information yet. 23732523Sbostic * We have to do everything `by hand'. 23832523Sbostic */ 23932523Sbostic udaprobe(reg, ctlr, um) 2404743Swnj caddr_t reg; 2414743Swnj int ctlr; 24232523Sbostic struct uba_ctlr *um; 2434743Swnj { 2444743Swnj register int br, cvec; 24532523Sbostic register struct uda_softc *sc; 24632523Sbostic register struct udadevice *udaddr; 24732523Sbostic register struct mscp_info *mi; 24836036Skarels int timeout, tries, s; 2494743Swnj 25032523Sbostic #ifdef VAX750 25132523Sbostic /* 25232523Sbostic * The UDA50 wants to share BDPs on 750s, but not on 780s or 25332523Sbostic * 8600s. (730s have no BDPs anyway.) Toward this end, we 25432523Sbostic * here set the `keep bdp' flag in the per-driver information 25532523Sbostic * if this is a 750. (We just need to do it once, but it is 25632523Sbostic * easiest to do it now, for each UDA50.) 25732523Sbostic */ 25832523Sbostic if (cpu == VAX_750) 25932523Sbostic udadriver.ud_keepbdp = 1; 26032523Sbostic #endif 26117553Skarels 26232523Sbostic probeum = um; /* remember for udaslave() */ 2634743Swnj #ifdef lint 26432523Sbostic br = 0; cvec = br; br = cvec; udaintr(0); 2654743Swnj #endif 26632523Sbostic /* 26732523Sbostic * Set up the controller-specific generic MSCP driver info. 26832523Sbostic * Note that this should really be done in the (nonexistent) 26932523Sbostic * controller attach routine. 27032523Sbostic */ 27132523Sbostic sc = &uda_softc[ctlr]; 27232523Sbostic mi = &sc->sc_mi; 27332523Sbostic mi->mi_md = &udamscpdriver; 27432523Sbostic mi->mi_ctlr = um->um_ctlr; 27532523Sbostic mi->mi_tab = &um->um_tab; 27632523Sbostic mi->mi_ip = udaip[ctlr]; 27732523Sbostic mi->mi_cmd.mri_size = NCMD; 27832523Sbostic mi->mi_cmd.mri_desc = uda[ctlr].uda_ca.ca_cmddsc; 27932523Sbostic mi->mi_cmd.mri_ring = uda[ctlr].uda_cmd; 28032523Sbostic mi->mi_rsp.mri_size = NRSP; 28132523Sbostic mi->mi_rsp.mri_desc = uda[ctlr].uda_ca.ca_rspdsc; 28232523Sbostic mi->mi_rsp.mri_ring = uda[ctlr].uda_rsp; 28332523Sbostic mi->mi_wtab.av_forw = mi->mi_wtab.av_back = &mi->mi_wtab; 28432523Sbostic 28532523Sbostic /* 28632523Sbostic * More controller specific variables. Again, this should 28732523Sbostic * be in the controller attach routine. 28832523Sbostic */ 28932523Sbostic if (udaburst[ctlr] == 0) 29032523Sbostic udaburst[ctlr] = DEFAULT_BURST; 29132523Sbostic 29232523Sbostic /* 29332523Sbostic * Get an interrupt vector. Note that even if the controller 29432523Sbostic * does not respond, we keep the vector. This is not a serious 29532523Sbostic * problem; but it would be easily fixed if we had a controller 29632523Sbostic * attach routine. Sigh. 29732523Sbostic */ 29832523Sbostic sc->sc_ivec = (uba_hd[numuba].uh_lastiv -= 4); 29917553Skarels udaddr = (struct udadevice *) reg; 30017553Skarels 30132523Sbostic /* 30232523Sbostic * Initialise the controller (partially). The UDA50 programmer's 30332523Sbostic * manual states that if initialisation fails, it should be retried 30432523Sbostic * at least once, but after a second failure the port should be 30532523Sbostic * considered `down'; it also mentions that the controller should 30632523Sbostic * initialise within ten seconds. Or so I hear; I have not seen 30732523Sbostic * this manual myself. 30832523Sbostic */ 30936036Skarels #ifdef QBA 31036036Skarels s = spl6(); 31136036Skarels #endif 31232523Sbostic tries = 0; 31332523Sbostic again: 31432523Sbostic udaddr->udaip = 0; /* start initialisation */ 31532523Sbostic timeout = todr() + 1000; /* timeout in 10 seconds */ 31632523Sbostic while ((udaddr->udasa & UDA_STEP1) == 0) 31732523Sbostic if (todr() > timeout) 31832523Sbostic goto bad; 31932523Sbostic udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 32032523Sbostic (sc->sc_ivec >> 2); 32132523Sbostic while ((udaddr->udasa & UDA_STEP2) == 0) 32232523Sbostic if (todr() > timeout) 32332523Sbostic goto bad; 32432523Sbostic 32532523Sbostic /* should have interrupted by now */ 32635401Stef #ifdef QBA 32736036Skarels sc->sc_ipl = br = qbgetpri(); 32827254Skridle #endif 32932523Sbostic return (sizeof (struct udadevice)); 33032523Sbostic bad: 33132523Sbostic if (++tries < 2) 33232523Sbostic goto again; 33336036Skarels splx(s); 33432523Sbostic return (0); 3354743Swnj } 3364743Swnj 33732523Sbostic /* 33832523Sbostic * Find a slave. We allow wildcard slave numbers (something autoconf 33932523Sbostic * is not really prepared to deal with); and we need to know the 34032523Sbostic * controller number to talk to the UDA. For the latter, we keep 34132523Sbostic * track of the last controller probed, since a controller probe 34232523Sbostic * immediately precedes all slave probes for that controller. For the 34332523Sbostic * former, we simply put the unit number into ui->ui_slave after we 34432523Sbostic * have found one. 34532523Sbostic * 34632523Sbostic * Note that by the time udaslave is called, the interrupt vector 34732523Sbostic * for the UDA50 has been set up (so that udaunconf() will be called). 34832523Sbostic */ 34932523Sbostic udaslave(ui, reg) 35032523Sbostic register struct uba_device *ui; 3514743Swnj caddr_t reg; 3524743Swnj { 35332523Sbostic register struct uba_ctlr *um = probeum; 35432523Sbostic register struct mscp *mp; 35532523Sbostic register struct uda_softc *sc; 35633443Skarels int next = 0, timeout, tries, i; 35717553Skarels 35832523Sbostic #ifdef lint 35932523Sbostic i = 0; i = i; 36032523Sbostic #endif 36132523Sbostic /* 36232523Sbostic * Make sure the controller is fully initialised, by waiting 36332523Sbostic * for it if necessary. 36432523Sbostic */ 36532523Sbostic sc = &uda_softc[um->um_ctlr]; 36632523Sbostic if (sc->sc_state == ST_RUN) 36732523Sbostic goto findunit; 36832523Sbostic tries = 0; 36932523Sbostic again: 37032523Sbostic if (udainit(ui->ui_ctlr)) 37132523Sbostic return (0); 37232523Sbostic timeout = todr() + 1000; /* 10 seconds */ 37332523Sbostic while (todr() < timeout) 37432523Sbostic if (sc->sc_state == ST_RUN) /* made it */ 37532523Sbostic goto findunit; 37632523Sbostic if (++tries < 2) 37732523Sbostic goto again; 37832523Sbostic printf("uda%d: controller hung\n", um->um_ctlr); 37932523Sbostic return (0); 38017553Skarels 38132523Sbostic /* 38232523Sbostic * The controller is all set; go find the unit. Grab an 38332523Sbostic * MSCP packet and send out a Get Unit Status command, with 38432523Sbostic * the `next unit' modifier if we are looking for a generic 38532523Sbostic * unit. We set the `in slave' flag so that udaunconf() 38632523Sbostic * knows to copy the response to `udaslavereply'. 38732523Sbostic */ 38832523Sbostic findunit: 38932523Sbostic udaslavereply.mscp_opcode = 0; 39032523Sbostic sc->sc_flags |= SC_INSLAVE; 39132523Sbostic if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) 39232523Sbostic panic("udaslave"); /* `cannot happen' */ 39332523Sbostic mp->mscp_opcode = M_OP_GETUNITST; 39432523Sbostic if (ui->ui_slave == '?') { 39532523Sbostic mp->mscp_unit = next; 39632523Sbostic mp->mscp_modifier = M_GUM_NEXTUNIT; 39732523Sbostic } else { 39832523Sbostic mp->mscp_unit = ui->ui_slave; 39932523Sbostic mp->mscp_modifier = 0; 40017553Skarels } 40132523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 40232523Sbostic i = ((struct udadevice *) reg)->udaip; /* initiate polling */ 40332523Sbostic mp = &udaslavereply; 40432523Sbostic timeout = todr() + 1000; 40532523Sbostic while (todr() < timeout) 40632523Sbostic if (mp->mscp_opcode) 40732523Sbostic goto gotit; 40832523Sbostic printf("uda%d: no response to Get Unit Status request\n", 40932523Sbostic um->um_ctlr); 41032523Sbostic sc->sc_flags &= ~SC_INSLAVE; 41132523Sbostic return (0); 41232523Sbostic 41332523Sbostic gotit: 41432523Sbostic sc->sc_flags &= ~SC_INSLAVE; 41532523Sbostic 41632523Sbostic /* 41732523Sbostic * Got a slave response. If the unit is there, use it. 41832523Sbostic */ 41932523Sbostic switch (mp->mscp_status & M_ST_MASK) { 42032523Sbostic 42132523Sbostic case M_ST_SUCCESS: /* worked */ 42232523Sbostic case M_ST_AVAILABLE: /* found another drive */ 42332523Sbostic break; /* use it */ 42432523Sbostic 42532523Sbostic case M_ST_OFFLINE: 42632523Sbostic /* 42732523Sbostic * Figure out why it is off line. It may be because 42832523Sbostic * it is nonexistent, or because it is spun down, or 42932523Sbostic * for some other reason. 43032523Sbostic */ 43132523Sbostic switch (mp->mscp_status & ~M_ST_MASK) { 43232523Sbostic 43332523Sbostic case M_OFFLINE_UNKNOWN: 43432523Sbostic /* 43532523Sbostic * No such drive, and there are none with 43632523Sbostic * higher unit numbers either, if we are 43732523Sbostic * using M_GUM_NEXTUNIT. 43832523Sbostic */ 43932523Sbostic return (0); 44032523Sbostic 44132523Sbostic case M_OFFLINE_UNMOUNTED: 44232523Sbostic /* 44332523Sbostic * The drive is not spun up. Use it anyway. 44432523Sbostic * 44532523Sbostic * N.B.: this seems to be a common occurrance 44632523Sbostic * after a power failure. The first attempt 44732523Sbostic * to bring it on line seems to spin it up 44832523Sbostic * (and thus takes several minutes). Perhaps 44932523Sbostic * we should note here that the on-line may 45032523Sbostic * take longer than usual. 45132523Sbostic */ 45232523Sbostic break; 45332523Sbostic 45432523Sbostic default: 45532523Sbostic /* 45632523Sbostic * In service, or something else equally unusable. 45732523Sbostic */ 45832523Sbostic printf("uda%d: unit %d off line: ", um->um_ctlr, 45932523Sbostic mp->mscp_unit); 46032523Sbostic mscp_printevent(mp); 46132523Sbostic goto try_another; 46232523Sbostic } 46332523Sbostic break; 46432523Sbostic 46532523Sbostic default: 46632523Sbostic printf("uda%d: unable to get unit status: ", um->um_ctlr); 46732523Sbostic mscp_printevent(mp); 46832523Sbostic return (0); 46917553Skarels } 47032523Sbostic 47132523Sbostic /* 47232523Sbostic * Does this ever happen? What (if anything) does it mean? 47332523Sbostic */ 47432523Sbostic if (mp->mscp_unit < next) { 47532523Sbostic printf("uda%d: unit %d, next %d\n", 47632523Sbostic um->um_ctlr, mp->mscp_unit, next); 47732523Sbostic return (0); 47817553Skarels } 47932523Sbostic 48032523Sbostic if (mp->mscp_unit >= MAXUNIT) { 48132523Sbostic printf("uda%d: cannot handle unit number %d (max is %d)\n", 48232523Sbostic um->um_ctlr, mp->mscp_unit, MAXUNIT - 1); 48332523Sbostic return (0); 48432523Sbostic } 48532523Sbostic 48632523Sbostic /* 48732523Sbostic * See if we already handle this drive. 48832523Sbostic * (Only likely if ui->ui_slave=='?'.) 48932523Sbostic */ 49032523Sbostic if (udaip[um->um_ctlr][mp->mscp_unit] != NULL) { 49132523Sbostic try_another: 49232523Sbostic if (ui->ui_slave != '?') 49332523Sbostic return (0); 49432523Sbostic next = mp->mscp_unit + 1; 49532523Sbostic goto findunit; 49632523Sbostic } 49732523Sbostic 49832523Sbostic /* 49932523Sbostic * Voila! 50032523Sbostic */ 50132523Sbostic uda_rasave(ui->ui_unit, mp, 0); 50232523Sbostic ui->ui_flags = 0; /* not on line, nor anything else */ 50332523Sbostic ui->ui_slave = mp->mscp_unit; 50432523Sbostic return (1); 5054743Swnj } 5064743Swnj 50732523Sbostic /* 50832523Sbostic * Attach a found slave. Make sure the watchdog timer is running. 50940045Smarc * If this disk is being profiled, fill in the `wpms' value (used by 51032523Sbostic * what?). Set up the inverting pointer, and attempt to bring the 51132523Sbostic * drive on line and read its label. 51232523Sbostic */ 51332523Sbostic udaattach(ui) 5144743Swnj register struct uba_device *ui; 5154743Swnj { 51632523Sbostic register int unit = ui->ui_unit; 51732523Sbostic 51832523Sbostic if (udawstart == 0) { 51932523Sbostic timeout(udawatch, (caddr_t) 0, hz); 52032523Sbostic udawstart++; 52132523Sbostic } 52233444Sbostic 52333444Sbostic /* 52433444Sbostic * Floppies cannot be brought on line unless there is 52533444Sbostic * a disk in the drive. Since an ONLINE while cold 52633444Sbostic * takes ten seconds to fail, and (when notyet becomes now) 52733444Sbostic * no sensible person will swap to one, we just 52833444Sbostic * defer the ONLINE until someone tries to use the drive. 52933444Sbostic * 53033444Sbostic * THIS ASSUMES THAT DRIVE TYPES ?X? ARE FLOPPIES 53133444Sbostic */ 53233444Sbostic if (MSCP_MID_ECH(1, ra_info[unit].ra_mediaid) == 'X' - '@') { 53334283Skarels printf(": floppy"); 53433444Sbostic return; 53533444Sbostic } 53634649Skarels if (ui->ui_dk >= 0) 53740045Smarc dk_wpms[ui->ui_dk] = (60 * 31 * 256); /* approx */ 53832523Sbostic udaip[ui->ui_ctlr][ui->ui_slave] = ui; 53933195Sbostic 54032523Sbostic if (uda_rainit(ui, 0)) 54134283Skarels printf(": offline"); 54236036Skarels else if (ra_info[unit].ra_state == OPEN) { 54334283Skarels printf(": %s, size = %d sectors", 54434283Skarels udalabel[unit].d_typename, ra_info[unit].ra_dsize); 54532523Sbostic #ifdef notyet 54632523Sbostic addswap(makedev(UDADEVNUM, udaminor(unit, 0)), &udalabel[unit]); 54726295Skarels #endif 54830536Skarels } 54932523Sbostic } 55032523Sbostic 55132523Sbostic /* 55232523Sbostic * Initialise a UDA50. Return true iff something goes wrong. 55332523Sbostic */ 55432523Sbostic udainit(ctlr) 55532523Sbostic int ctlr; 55632523Sbostic { 55732523Sbostic register struct uda_softc *sc; 55832523Sbostic register struct udadevice *udaddr; 55932523Sbostic struct uba_ctlr *um; 56032523Sbostic int timo, ubinfo; 56132523Sbostic 56232523Sbostic sc = &uda_softc[ctlr]; 56332523Sbostic um = udaminfo[ctlr]; 56432523Sbostic if ((sc->sc_flags & SC_MAPPED) == 0) { 56532523Sbostic /* 56632523Sbostic * Map the communication area and command and 56732523Sbostic * response packets into Unibus space. 56832523Sbostic */ 56932523Sbostic ubinfo = uballoc(um->um_ubanum, (caddr_t) &uda[ctlr], 57032523Sbostic sizeof (struct uda), UBA_CANTWAIT); 57132523Sbostic if (ubinfo == 0) { 57232523Sbostic printf("uda%d: uballoc map failed\n", ctlr); 57332523Sbostic return (-1); 57432523Sbostic } 57536036Skarels sc->sc_uda = (struct uda *) UBAI_ADDR(ubinfo); 57632523Sbostic sc->sc_flags |= SC_MAPPED; 57732523Sbostic } 57832523Sbostic 57930536Skarels /* 58032523Sbostic * While we are thinking about it, reset the next command 58132523Sbostic * and response indicies. 58230536Skarels */ 58332523Sbostic sc->sc_mi.mi_cmd.mri_next = 0; 58432523Sbostic sc->sc_mi.mi_rsp.mri_next = 0; 58532523Sbostic 58632523Sbostic /* 58732523Sbostic * Start up the hardware initialisation sequence. 58832523Sbostic */ 58932523Sbostic #define STEP0MASK (UDA_ERR | UDA_STEP4 | UDA_STEP3 | UDA_STEP2 | \ 59032523Sbostic UDA_STEP1 | UDA_NV) 59132523Sbostic 59232523Sbostic sc->sc_state = ST_IDLE; /* in case init fails */ 59333444Sbostic udaddr = (struct udadevice *)um->um_addr; 59432523Sbostic udaddr->udaip = 0; 59532523Sbostic timo = todr() + 1000; 59632523Sbostic while ((udaddr->udasa & STEP0MASK) == 0) { 59732523Sbostic if (todr() > timo) { 59832523Sbostic printf("uda%d: timeout during init\n", ctlr); 59932523Sbostic return (-1); 60032523Sbostic } 60132523Sbostic } 60232523Sbostic if ((udaddr->udasa & STEP0MASK) != UDA_STEP1) { 60332523Sbostic printf("uda%d: init failed, sa=%b\n", ctlr, 60432523Sbostic udaddr->udasa, udasr_bits); 60533444Sbostic udasaerror(um, 0); 60632523Sbostic return (-1); 60732523Sbostic } 60832523Sbostic 60932523Sbostic /* 61032523Sbostic * Success! Record new state, and start step 1 initialisation. 61132523Sbostic * The rest is done in the interrupt handler. 61232523Sbostic */ 61332523Sbostic sc->sc_state = ST_STEP1; 61432523Sbostic udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 61532523Sbostic (sc->sc_ivec >> 2); 61632523Sbostic return (0); 6174743Swnj } 6184743Swnj 6194743Swnj /* 62032523Sbostic * Open a drive. 6214743Swnj */ 62232523Sbostic /*ARGSUSED*/ 62332523Sbostic udaopen(dev, flag, fmt) 6244743Swnj dev_t dev; 62530773Skarels int flag, fmt; 6264743Swnj { 62732523Sbostic register int unit; 6284743Swnj register struct uba_device *ui; 6294743Swnj register struct uda_softc *sc; 63030536Skarels register struct disklabel *lp; 63130536Skarels register struct partition *pp; 63230916Skarels register struct ra_info *ra; 63332523Sbostic int s, i, part, mask, error = 0; 63430536Skarels daddr_t start, end; 63530536Skarels 63632523Sbostic /* 63732523Sbostic * Make sure this is a reasonable open request. 63832523Sbostic */ 63932523Sbostic unit = udaunit(dev); 64032523Sbostic if (unit >= NRA || (ui = udadinfo[unit]) == 0 || ui->ui_alive == 0) 6418576Sroot return (ENXIO); 64232523Sbostic 64332523Sbostic /* 64432523Sbostic * Make sure the controller is running, by (re)initialising it if 64532523Sbostic * necessary. 64632523Sbostic */ 6474743Swnj sc = &uda_softc[ui->ui_ctlr]; 6485434Sroot s = spl5(); 64932523Sbostic if (sc->sc_state != ST_RUN) { 65032523Sbostic if (sc->sc_state == ST_IDLE && udainit(ui->ui_ctlr)) { 65132523Sbostic splx(s); 6528576Sroot return (EIO); 65317553Skarels } 65432523Sbostic /* 65532523Sbostic * In case it does not come up, make sure we will be 65632523Sbostic * restarted in 10 seconds. This corresponds to the 65732523Sbostic * 10 second timeouts in udaprobe() and udaslave(). 65832523Sbostic */ 65932523Sbostic sc->sc_flags |= SC_DOWAKE; 66032523Sbostic timeout(wakeup, (caddr_t) sc, 10 * hz); 66132523Sbostic sleep((caddr_t) sc, PRIBIO); 66232523Sbostic if (sc->sc_state != ST_RUN) { 66332523Sbostic splx(s); 66432523Sbostic printf("uda%d: controller hung\n", ui->ui_ctlr); 66532523Sbostic return (EIO); 66632523Sbostic } 66732523Sbostic untimeout(wakeup, (caddr_t) sc); 6684743Swnj } 66932523Sbostic 67032523Sbostic /* 67132523Sbostic * Wait for the state to settle 67232523Sbostic */ 67332523Sbostic ra = &ra_info[unit]; 67432523Sbostic while (ra->ra_state != OPEN && ra->ra_state != OPENRAW && 67532523Sbostic ra->ra_state != CLOSED) 67640726Skarels if (error = tsleep((caddr_t)ra, (PZERO + 1) | PCATCH, 67740726Skarels devopn, 0)) { 67840726Skarels splx(s); 67940726Skarels return (error); 68040726Skarels } 68132523Sbostic 68232523Sbostic /* 68332523Sbostic * If not on line, or we are not sure of the label, reinitialise 68432523Sbostic * the drive. 68532523Sbostic */ 68632523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0 || 68732523Sbostic (ra->ra_state != OPEN && ra->ra_state != OPENRAW)) 68832523Sbostic error = uda_rainit(ui, flag); 68930916Skarels splx(s); 69032523Sbostic if (error) 69132523Sbostic return (error); 69230536Skarels 69332523Sbostic part = udapart(dev); 69432523Sbostic lp = &udalabel[unit]; 69530536Skarels if (part >= lp->d_npartitions) 69630536Skarels return (ENXIO); 69730536Skarels /* 69832523Sbostic * Warn if a partition is opened that overlaps another 69932523Sbostic * already open, unless either is the `raw' partition 70032523Sbostic * (whole disk). 70130536Skarels */ 70232523Sbostic #define RAWPART 2 /* 'c' partition */ /* XXX */ 70332523Sbostic mask = 1 << part; 70432523Sbostic if ((ra->ra_openpart & mask) == 0 && part != RAWPART) { 70530536Skarels pp = &lp->d_partitions[part]; 70630536Skarels start = pp->p_offset; 70730536Skarels end = pp->p_offset + pp->p_size; 70832523Sbostic for (pp = lp->d_partitions, i = 0; 70932523Sbostic i < lp->d_npartitions; pp++, i++) { 71030536Skarels if (pp->p_offset + pp->p_size <= start || 71132523Sbostic pp->p_offset >= end || i == RAWPART) 71230536Skarels continue; 71332523Sbostic if (ra->ra_openpart & (1 << i)) 71430536Skarels log(LOG_WARNING, 71530536Skarels "ra%d%c: overlaps open partition (%c)\n", 71632523Sbostic unit, part + 'a', i + 'a'); 71717553Skarels } 71817553Skarels } 71930773Skarels switch (fmt) { 72030773Skarels case S_IFCHR: 72132523Sbostic ra->ra_copenpart |= mask; 72230773Skarels break; 72330773Skarels case S_IFBLK: 72432523Sbostic ra->ra_bopenpart |= mask; 72530773Skarels break; 72630773Skarels } 72732523Sbostic ra->ra_openpart |= mask; 7288576Sroot return (0); 7294743Swnj } 7304743Swnj 73133444Sbostic /* ARGSUSED */ 73232523Sbostic udaclose(dev, flags, fmt) 73330536Skarels dev_t dev; 73430773Skarels int flags, fmt; 73530536Skarels { 73632523Sbostic register int unit = udaunit(dev); 73730773Skarels register struct ra_info *ra = &ra_info[unit]; 73832523Sbostic int s, mask = (1 << udapart(dev)); 73930536Skarels 74030773Skarels switch (fmt) { 74130773Skarels case S_IFCHR: 74232523Sbostic ra->ra_copenpart &= ~mask; 74330773Skarels break; 74430773Skarels case S_IFBLK: 74532523Sbostic ra->ra_bopenpart &= ~mask; 74630773Skarels break; 74730773Skarels } 74832523Sbostic ra->ra_openpart = ra->ra_copenpart | ra->ra_bopenpart; 74932523Sbostic 75030536Skarels /* 75132523Sbostic * Should wait for I/O to complete on this partition even if 75232523Sbostic * others are open, but wait for work on blkflush(). 75330536Skarels */ 75432523Sbostic if (ra->ra_openpart == 0) { 75530536Skarels s = spl5(); 75632523Sbostic while (udautab[unit].b_actf) 75732523Sbostic sleep((caddr_t)&udautab[unit], PZERO - 1); 75830536Skarels splx(s); 75932523Sbostic ra->ra_state = CLOSED; 76033443Skarels ra->ra_wlabel = 0; 76130536Skarels } 76230773Skarels return (0); 76330536Skarels } 76430536Skarels 7654743Swnj /* 76632523Sbostic * Initialise a drive. If it is not already, bring it on line, 76732523Sbostic * and set a timeout on it in case it fails to respond. 76832523Sbostic * When on line, read in the pack label. 7694743Swnj */ 77032523Sbostic uda_rainit(ui, flags) 77130536Skarels register struct uba_device *ui; 77232523Sbostic int flags; 77330536Skarels { 77432523Sbostic register struct uda_softc *sc = &uda_softc[ui->ui_ctlr]; 77534283Skarels register struct disklabel *lp; 77630536Skarels register struct mscp *mp; 77732523Sbostic register int unit = ui->ui_unit; 77832523Sbostic register struct ra_info *ra; 77930773Skarels char *msg, *readdisklabel(); 78032523Sbostic int s, i, udastrategy(); 78130536Skarels extern int cold; 78230536Skarels 78332523Sbostic ra = &ra_info[unit]; 78432523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0) { 78532523Sbostic mp = mscp_getcp(&sc->sc_mi, MSCP_WAIT); 78632523Sbostic mp->mscp_opcode = M_OP_ONLINE; 78732523Sbostic mp->mscp_unit = ui->ui_slave; 78832523Sbostic mp->mscp_cmdref = (long)&ui->ui_flags; 78932523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 79032523Sbostic ra->ra_state = WANTOPEN; 79132523Sbostic if (!cold) 79232523Sbostic s = spl5(); 79332523Sbostic i = ((struct udadevice *)ui->ui_addr)->udaip; 79430536Skarels 79530916Skarels if (cold) { 79632523Sbostic i = todr() + 1000; 79732523Sbostic while ((ui->ui_flags & UNIT_ONLINE) == 0) 79832523Sbostic if (todr() > i) 79932523Sbostic break; 80030916Skarels } else { 80132523Sbostic timeout(wakeup, (caddr_t)&ui->ui_flags, 10 * hz); 80232523Sbostic sleep((caddr_t)&ui->ui_flags, PSWP + 1); 80332523Sbostic splx(s); 80432523Sbostic untimeout(wakeup, (caddr_t)&ui->ui_flags); 80530916Skarels } 80632523Sbostic if (ra->ra_state != OPENRAW) { 80732523Sbostic ra->ra_state = CLOSED; 80832523Sbostic wakeup((caddr_t)ra); 80930916Skarels return (EIO); 81030916Skarels } 81130536Skarels } 81230536Skarels 81332523Sbostic lp = &udalabel[unit]; 81430916Skarels lp->d_secsize = DEV_BSIZE; 81532523Sbostic lp->d_secperunit = ra->ra_dsize; 81630916Skarels 81730536Skarels if (flags & O_NDELAY) 81830536Skarels return (0); 81932523Sbostic ra->ra_state = RDLABEL; 82030536Skarels /* 82132523Sbostic * Set up default sizes until we have the label, or longer 82232523Sbostic * if there is none. Set secpercyl, as readdisklabel wants 82338979Skarels * to compute b_cylin (although we do not need it), and set 82438979Skarels * nsectors in case diskerr is called. 82530536Skarels */ 82630916Skarels lp->d_secpercyl = 1; 82730536Skarels lp->d_npartitions = 1; 82836036Skarels lp->d_secsize = 512; 82936036Skarels lp->d_secperunit = ra->ra_dsize; 83038979Skarels lp->d_nsectors = ra->ra_geom.rg_nsectors; 83130536Skarels lp->d_partitions[0].p_size = lp->d_secperunit; 83230536Skarels lp->d_partitions[0].p_offset = 0; 83332523Sbostic 83430536Skarels /* 83530536Skarels * Read pack label. 83630536Skarels */ 83732523Sbostic if ((msg = readdisklabel(udaminor(unit, 0), udastrategy, lp)) != NULL) { 83834283Skarels if (cold) 83934283Skarels printf(": %s", msg); 84034283Skarels else 84136036Skarels log(LOG_ERR, "ra%d: %s", unit, msg); 84230536Skarels #ifdef COMPAT_42 84332523Sbostic if (udamaptype(unit, lp)) 84432523Sbostic ra->ra_state = OPEN; 84530536Skarels else 84632523Sbostic ra->ra_state = OPENRAW; 84731022Skarels #else 84832523Sbostic ra->ra_state = OPENRAW; 84936036Skarels uda_makefakelabel(ra, lp); 85030536Skarels #endif 85130773Skarels } else 85232523Sbostic ra->ra_state = OPEN; 85330916Skarels wakeup((caddr_t)ra); 85430916Skarels return (0); 85530536Skarels } 85630536Skarels 85732523Sbostic /* 85832523Sbostic * Copy the geometry information for the given ra from a 85932523Sbostic * GET UNIT STATUS response. If check, see if it changed. 86032523Sbostic */ 86132523Sbostic uda_rasave(unit, mp, check) 86232523Sbostic int unit; 86332523Sbostic register struct mscp *mp; 86432523Sbostic int check; 86532523Sbostic { 86632523Sbostic register struct ra_info *ra = &ra_info[unit]; 86732523Sbostic 86834283Skarels if (check && ra->ra_mediaid != mp->mscp_guse.guse_mediaid) { 86933443Skarels printf("ra%d: changed types! was %d now %d\n", unit, 87034283Skarels ra->ra_mediaid, mp->mscp_guse.guse_mediaid); 87132523Sbostic ra->ra_state = CLOSED; /* ??? */ 87232523Sbostic } 87333444Sbostic /* ra->ra_type = mp->mscp_guse.guse_drivetype; */ 87432523Sbostic ra->ra_mediaid = mp->mscp_guse.guse_mediaid; 87532523Sbostic ra->ra_geom.rg_nsectors = mp->mscp_guse.guse_nspt; 87632523Sbostic ra->ra_geom.rg_ngroups = mp->mscp_guse.guse_group; 87732523Sbostic ra->ra_geom.rg_ngpc = mp->mscp_guse.guse_ngpc; 87832523Sbostic ra->ra_geom.rg_ntracks = ra->ra_geom.rg_ngroups * ra->ra_geom.rg_ngpc; 87932523Sbostic /* ra_geom.rg_ncyl cannot be computed until we have ra_dsize */ 88032523Sbostic #ifdef notyet 88132523Sbostic ra->ra_geom.rg_rctsize = mp->mscp_guse.guse_rctsize; 88232523Sbostic ra->ra_geom.rg_rbns = mp->mscp_guse.guse_nrpt; 88332523Sbostic ra->ra_geom.rg_nrct = mp->mscp_guse.guse_nrct; 88432523Sbostic #endif 88532523Sbostic } 88632523Sbostic 88732523Sbostic /* 88832523Sbostic * Queue a transfer request, and if possible, hand it to the controller. 88932523Sbostic * 89032523Sbostic * This routine is broken into two so that the internal version 89132523Sbostic * udastrat1() can be called by the (nonexistent, as yet) bad block 89232523Sbostic * revectoring routine. 89332523Sbostic */ 89432523Sbostic udastrategy(bp) 8954743Swnj register struct buf *bp; 8964743Swnj { 89732523Sbostic register int unit; 8984743Swnj register struct uba_device *ui; 89932523Sbostic register struct ra_info *ra; 90032523Sbostic struct partition *pp; 90132523Sbostic int p; 9024743Swnj daddr_t sz, maxsz; 9034743Swnj 90432523Sbostic /* 90532523Sbostic * Make sure this is a reasonable drive to use. 90632523Sbostic */ 90732523Sbostic if ((unit = udaunit(bp->b_dev)) >= NRA || 90832523Sbostic (ui = udadinfo[unit]) == NULL || ui->ui_alive == 0 || 90932523Sbostic (ra = &ra_info[unit])->ra_state == CLOSED) { 91024742Sbloom bp->b_error = ENXIO; 9114743Swnj goto bad; 91224742Sbloom } 91332523Sbostic 91432523Sbostic /* 91532523Sbostic * If drive is open `raw' or reading label, let it at it. 91632523Sbostic */ 91732523Sbostic if (ra->ra_state < OPEN) { 91832523Sbostic udastrat1(bp); 91932523Sbostic return; 92024742Sbloom } 92132523Sbostic p = udapart(bp->b_dev); 92233443Skarels if ((ra->ra_openpart & (1 << p)) == 0) { 92333443Skarels bp->b_error = ENODEV; 92433443Skarels goto bad; 92533443Skarels } 92632523Sbostic 92732523Sbostic /* 92832523Sbostic * Determine the size of the transfer, and make sure it is 92932523Sbostic * within the boundaries of the partition. 93032523Sbostic */ 93132523Sbostic pp = &udalabel[unit].d_partitions[p]; 93232523Sbostic maxsz = pp->p_size; 93332523Sbostic if (pp->p_offset + pp->p_size > ra->ra_dsize) 93432523Sbostic maxsz = ra->ra_dsize - pp->p_offset; 93530536Skarels sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 93633443Skarels if (bp->b_blkno + pp->p_offset <= LABELSECTOR && 93733443Skarels #if LABELSECTOR != 0 93833443Skarels bp->b_blkno + pp->p_offset + sz > LABELSECTOR && 93933443Skarels #endif 94033443Skarels (bp->b_flags & B_READ) == 0 && ra->ra_wlabel == 0) { 94133443Skarels bp->b_error = EROFS; 94233443Skarels goto bad; 94333443Skarels } 94430536Skarels if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) { 94532523Sbostic /* if exactly at end of disk, return an EOF */ 94624787Skarels if (bp->b_blkno == maxsz) { 94724787Skarels bp->b_resid = bp->b_bcount; 94832523Sbostic biodone(bp); 94932523Sbostic return; 95024787Skarels } 95132523Sbostic /* or truncate if part of it fits */ 95230536Skarels sz = maxsz - bp->b_blkno; 95330536Skarels if (sz <= 0) { 95432523Sbostic bp->b_error = EINVAL; /* or hang it up */ 95530536Skarels goto bad; 95630536Skarels } 95730536Skarels bp->b_bcount = sz << DEV_BSHIFT; 95824742Sbloom } 95932523Sbostic udastrat1(bp); 96032523Sbostic return; 96132523Sbostic bad: 96232523Sbostic bp->b_flags |= B_ERROR; 96332523Sbostic biodone(bp); 96432523Sbostic } 96532523Sbostic 96632523Sbostic /* 96732523Sbostic * Work routine for udastrategy. 96832523Sbostic */ 96932523Sbostic udastrat1(bp) 97032523Sbostic register struct buf *bp; 97132523Sbostic { 97232523Sbostic register int unit = udaunit(bp->b_dev); 97332523Sbostic register struct uba_ctlr *um; 97432523Sbostic register struct buf *dp; 97532523Sbostic struct uba_device *ui; 97632523Sbostic int s = spl5(); 97732523Sbostic 9784743Swnj /* 97932523Sbostic * Append the buffer to the drive queue, and if it is not 98032523Sbostic * already there, the drive to the controller queue. (However, 98132523Sbostic * if the drive queue is marked to be requeued, we must be 98232523Sbostic * awaiting an on line or get unit status command; in this 98332523Sbostic * case, leave it off the controller queue.) 9844743Swnj */ 98532523Sbostic um = (ui = udadinfo[unit])->ui_mi; 98632523Sbostic dp = &udautab[unit]; 98732523Sbostic APPEND(bp, dp, av_forw); 98832523Sbostic if (dp->b_active == 0 && (ui->ui_flags & UNIT_REQUEUE) == 0) { 98932523Sbostic APPEND(dp, &um->um_tab, b_forw); 99032523Sbostic dp->b_active++; 99132523Sbostic } 99232523Sbostic 9934743Swnj /* 99432523Sbostic * Start activity on the controller. Note that unlike other 99532523Sbostic * Unibus drivers, we must always do this, not just when the 99632523Sbostic * controller is not active. 9974743Swnj */ 99832523Sbostic udastart(um); 9995434Sroot splx(s); 10004743Swnj } 10014743Swnj 100232523Sbostic /* 100332523Sbostic * Start up whatever transfers we can find. 100432523Sbostic * Note that udastart() must be called at spl5(). 100532523Sbostic */ 100632523Sbostic udastart(um) 10074743Swnj register struct uba_ctlr *um; 10084743Swnj { 100932523Sbostic register struct uda_softc *sc = &uda_softc[um->um_ctlr]; 10104743Swnj register struct buf *bp, *dp; 10114743Swnj register struct mscp *mp; 101232523Sbostic struct uba_device *ui; 10134743Swnj struct udadevice *udaddr; 101432523Sbostic struct partition *pp; 101532523Sbostic int i, sz; 10164743Swnj 101732523Sbostic #ifdef lint 101832523Sbostic i = 0; i = i; 101932523Sbostic #endif 102032523Sbostic /* 102132523Sbostic * If it is not running, try (again and again...) to initialise 102232523Sbostic * it. If it is currently initialising just ignore it for now. 102332523Sbostic */ 102432523Sbostic if (sc->sc_state != ST_RUN) { 102532523Sbostic if (sc->sc_state == ST_IDLE && udainit(um->um_ctlr)) 102632523Sbostic printf("uda%d: still hung\n", um->um_ctlr); 102732523Sbostic return; 102832523Sbostic } 102932523Sbostic 103032523Sbostic /* 103132523Sbostic * If um_cmd is nonzero, this controller is on the Unibus 103232523Sbostic * resource wait queue. It will not help to try more requests; 103332523Sbostic * instead, when the Unibus unblocks and calls udadgo(), we 103432523Sbostic * will call udastart() again. 103532523Sbostic */ 103632523Sbostic if (um->um_cmd) 103732523Sbostic return; 103832523Sbostic 103932523Sbostic sc->sc_flags |= SC_INSTART; 104032523Sbostic udaddr = (struct udadevice *) um->um_addr; 104132523Sbostic 10424743Swnj loop: 104332523Sbostic /* 104432523Sbostic * Service the drive at the head of the queue. It may not 104532523Sbostic * need anything, in which case it might be shutting down 104632523Sbostic * in udaclose(). 104732523Sbostic */ 104832523Sbostic if ((dp = um->um_tab.b_actf) == NULL) 104932523Sbostic goto out; 10504743Swnj if ((bp = dp->b_actf) == NULL) { 10514743Swnj dp->b_active = 0; 10524743Swnj um->um_tab.b_actf = dp->b_forw; 105332523Sbostic if (ra_info[dp - udautab].ra_openpart == 0) 105432523Sbostic wakeup((caddr_t)dp); /* finish close protocol */ 105532523Sbostic goto loop; 10564743Swnj } 105732523Sbostic 105832523Sbostic if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 105933444Sbostic udasaerror(um, 1); 106032523Sbostic goto out; 10614743Swnj } 106232523Sbostic 106332523Sbostic /* 106432523Sbostic * Get an MSCP packet, then figure out what to do. If 106532523Sbostic * we cannot get a command packet, the command ring may 106632523Sbostic * be too small: We should have at least as many command 106732523Sbostic * packets as credits, for best performance. 106832523Sbostic */ 106932523Sbostic if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) { 107032523Sbostic if (sc->sc_mi.mi_credits > MSCP_MINCREDITS && 107132523Sbostic (sc->sc_flags & SC_GRIPED) == 0) { 107232523Sbostic log(LOG_NOTICE, "uda%d: command ring too small\n", 107332523Sbostic um->um_ctlr); 107432523Sbostic sc->sc_flags |= SC_GRIPED;/* complain only once */ 107517553Skarels } 107632523Sbostic goto out; 10774743Swnj } 10784743Swnj 107932523Sbostic /* 108032523Sbostic * Bring the drive on line if it is not already. Get its status 108132523Sbostic * if we do not already have it. Otherwise just start the transfer. 108232523Sbostic */ 108332523Sbostic ui = udadinfo[udaunit(bp->b_dev)]; 108432523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0) { 108532523Sbostic mp->mscp_opcode = M_OP_ONLINE; 108632523Sbostic goto common; 10874743Swnj } 108832523Sbostic if ((ui->ui_flags & UNIT_HAVESTATUS) == 0) { 108932523Sbostic mp->mscp_opcode = M_OP_GETUNITST; 109032523Sbostic common: 109132523Sbostic if (ui->ui_flags & UNIT_REQUEUE) panic("udastart"); 109232523Sbostic /* 109332523Sbostic * Take the drive off the controller queue. When the 109432523Sbostic * command finishes, make sure the drive is requeued. 109532523Sbostic */ 109632523Sbostic um->um_tab.b_actf = dp->b_forw; 109732523Sbostic dp->b_active = 0; 109832523Sbostic ui->ui_flags |= UNIT_REQUEUE; 109932523Sbostic mp->mscp_unit = ui->ui_slave; 110032523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 110132523Sbostic sc->sc_flags |= SC_STARTPOLL; 110232523Sbostic #ifdef POLLSTATS 110332523Sbostic sc->sc_ncmd++; 110425653Skarels #endif 110532523Sbostic goto loop; 110617553Skarels } 110732523Sbostic 110832523Sbostic pp = &udalabel[ui->ui_unit].d_partitions[udapart(bp->b_dev)]; 110932523Sbostic mp->mscp_opcode = (bp->b_flags & B_READ) ? M_OP_READ : M_OP_WRITE; 11104743Swnj mp->mscp_unit = ui->ui_slave; 111132523Sbostic mp->mscp_seq.seq_lbn = bp->b_blkno + pp->p_offset; 111230536Skarels sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 111332523Sbostic mp->mscp_seq.seq_bytecount = bp->b_blkno + sz > pp->p_size ? 111432523Sbostic (pp->p_size - bp->b_blkno) >> DEV_BSHIFT : bp->b_bcount; 111532523Sbostic /* mscp_cmdref is filled in by mscp_go() */ 11164743Swnj 11174743Swnj /* 111832523Sbostic * Drop the packet pointer into the `command' field so udadgo() 111932523Sbostic * can tell what to start. If ubago returns 1, we can do another 112032523Sbostic * transfer. If not, um_cmd will still point at mp, so we will 112132523Sbostic * know that we are waiting for resources. 11224743Swnj */ 112332523Sbostic um->um_cmd = (int)mp; 112432523Sbostic if (ubago(ui)) 112532523Sbostic goto loop; 112632523Sbostic 112732523Sbostic /* 112832523Sbostic * All done, or blocked in ubago(). If we managed to 112932523Sbostic * issue some commands, start up the beast. 113032523Sbostic */ 113132523Sbostic out: 113232523Sbostic if (sc->sc_flags & SC_STARTPOLL) { 113332523Sbostic #ifdef POLLSTATS 113432523Sbostic udastats.cmd[sc->sc_ncmd]++; 113532523Sbostic sc->sc_ncmd = 0; 113632523Sbostic #endif 113733444Sbostic i = ((struct udadevice *)um->um_addr)->udaip; 11384743Swnj } 113932523Sbostic sc->sc_flags &= ~(SC_INSTART | SC_STARTPOLL); 114032523Sbostic } 114132523Sbostic 114232523Sbostic /* 114332523Sbostic * Start a transfer. 114432523Sbostic * 114532523Sbostic * If we are not called from within udastart(), we must have been 114632523Sbostic * blocked, so call udastart to do more requests (if any). If 114732523Sbostic * this calls us again immediately we will not recurse, because 114832523Sbostic * that time we will be in udastart(). Clever.... 114932523Sbostic */ 115032523Sbostic udadgo(um) 115132523Sbostic register struct uba_ctlr *um; 115232523Sbostic { 115332523Sbostic struct uda_softc *sc = &uda_softc[um->um_ctlr]; 115432523Sbostic struct mscp *mp = (struct mscp *)um->um_cmd; 115532523Sbostic 115632523Sbostic um->um_tab.b_active++; /* another transfer going */ 115732523Sbostic 11584743Swnj /* 115932523Sbostic * Fill in the MSCP packet and move the buffer to the 116032523Sbostic * I/O wait queue. Mark the controller as no longer on 116132523Sbostic * the resource queue, and remember to initiate polling. 11624743Swnj */ 116336036Skarels mp->mscp_seq.seq_buffer = UBAI_ADDR(um->um_ubinfo) | 116432523Sbostic (UBAI_BDP(um->um_ubinfo) << 24); 116532523Sbostic mscp_go(&sc->sc_mi, mp, um->um_ubinfo); 116632523Sbostic um->um_cmd = 0; 116732523Sbostic um->um_ubinfo = 0; /* tyke it awye */ 116832523Sbostic sc->sc_flags |= SC_STARTPOLL; 116932523Sbostic #ifdef POLLSTATS 117032523Sbostic sc->sc_ncmd++; 117132523Sbostic #endif 117232523Sbostic if ((sc->sc_flags & SC_INSTART) == 0) 117332523Sbostic udastart(um); 11744743Swnj } 11754743Swnj 117632523Sbostic udaiodone(mi, bp, info) 117732523Sbostic register struct mscp_info *mi; 117832523Sbostic struct buf *bp; 117932523Sbostic int info; 118032523Sbostic { 118132523Sbostic register struct uba_ctlr *um = udaminfo[mi->mi_ctlr]; 118232523Sbostic 118332523Sbostic um->um_ubinfo = info; 118432523Sbostic ubadone(um); 118532523Sbostic biodone(bp); 118632523Sbostic if (um->um_bdp && mi->mi_wtab.av_forw == &mi->mi_wtab) 118732523Sbostic ubarelse(um->um_ubanum, &um->um_bdp); 118832523Sbostic um->um_tab.b_active--; /* another transfer done */ 118932523Sbostic } 119032523Sbostic 119133444Sbostic static struct saerr { 119233444Sbostic int code; /* error code (including UDA_ERR) */ 119333444Sbostic char *desc; /* what it means: Efoo => foo error */ 119433444Sbostic } saerr[] = { 119533444Sbostic { 0100001, "Eunibus packet read" }, 119633444Sbostic { 0100002, "Eunibus packet write" }, 119733444Sbostic { 0100003, "EUDA ROM and RAM parity" }, 119833444Sbostic { 0100004, "EUDA RAM parity" }, 119933444Sbostic { 0100005, "EUDA ROM parity" }, 120033444Sbostic { 0100006, "Eunibus ring read" }, 120133444Sbostic { 0100007, "Eunibus ring write" }, 120233444Sbostic { 0100010, " unibus interrupt master failure" }, 120333444Sbostic { 0100011, "Ehost access timeout" }, 120433444Sbostic { 0100012, " host exceeded command limit" }, 120533444Sbostic { 0100013, " unibus bus master failure" }, 120633444Sbostic { 0100014, " DM XFC fatal error" }, 120733444Sbostic { 0100015, " hardware timeout of instruction loop" }, 120833444Sbostic { 0100016, " invalid virtual circuit id" }, 120933444Sbostic { 0100017, "Eunibus interrupt write" }, 121033444Sbostic { 0104000, "Efatal sequence" }, 121133444Sbostic { 0104040, " D proc ALU" }, 121233444Sbostic { 0104041, "ED proc control ROM parity" }, 121333444Sbostic { 0105102, "ED proc w/no BD#2 or RAM parity" }, 121433444Sbostic { 0105105, "ED proc RAM buffer" }, 121533444Sbostic { 0105152, "ED proc SDI" }, 121633444Sbostic { 0105153, "ED proc write mode wrap serdes" }, 121733444Sbostic { 0105154, "ED proc read mode serdes, RSGEN & ECC" }, 121833444Sbostic { 0106040, "EU proc ALU" }, 121933444Sbostic { 0106041, "EU proc control reg" }, 122033444Sbostic { 0106042, " U proc DFAIL/cntl ROM parity/BD #1 test CNT" }, 122133444Sbostic { 0106047, " U proc const PROM err w/D proc running SDI test" }, 122233444Sbostic { 0106055, " unexpected trap" }, 122333444Sbostic { 0106071, "EU proc const PROM" }, 122433444Sbostic { 0106072, "EU proc control ROM parity" }, 122533444Sbostic { 0106200, "Estep 1 data" }, 122633444Sbostic { 0107103, "EU proc RAM parity" }, 122733444Sbostic { 0107107, "EU proc RAM buffer" }, 122833444Sbostic { 0107115, " test count wrong (BD 12)" }, 122933444Sbostic { 0112300, "Estep 2" }, 123033444Sbostic { 0122240, "ENPR" }, 123133444Sbostic { 0122300, "Estep 3" }, 123233444Sbostic { 0142300, "Estep 4" }, 123333444Sbostic { 0, " unknown error code" } 123433444Sbostic }; 123533444Sbostic 12364743Swnj /* 123733444Sbostic * If the error bit was set in the controller status register, gripe, 123833444Sbostic * then (optionally) reset the controller and requeue pending transfers. 12394743Swnj */ 124033444Sbostic udasaerror(um, doreset) 124132523Sbostic register struct uba_ctlr *um; 124233444Sbostic int doreset; 12434743Swnj { 124433444Sbostic register int code = ((struct udadevice *)um->um_addr)->udasa; 124533444Sbostic register struct saerr *e; 124632523Sbostic 124733444Sbostic if ((code & UDA_ERR) == 0) 124833444Sbostic return; 124933444Sbostic for (e = saerr; e->code; e++) 125033444Sbostic if (e->code == code) 125133444Sbostic break; 125233444Sbostic printf("uda%d: controller error, sa=0%o (%s%s)\n", 125333444Sbostic um->um_ctlr, code, e->desc + 1, 125433444Sbostic *e->desc == 'E' ? " error" : ""); 125533444Sbostic if (doreset) { 125633444Sbostic mscp_requeue(&uda_softc[um->um_ctlr].sc_mi); 125733444Sbostic (void) udainit(um->um_ctlr); 125833444Sbostic } 125932523Sbostic } 126032523Sbostic 126132523Sbostic /* 126232523Sbostic * Interrupt routine. Depending on the state of the controller, 126332523Sbostic * continue initialisation, or acknowledge command and response 126432523Sbostic * interrupts, and process responses. 126532523Sbostic */ 126632523Sbostic udaintr(ctlr) 126732523Sbostic int ctlr; 126832523Sbostic { 126932523Sbostic register struct uba_ctlr *um = udaminfo[ctlr]; 127032523Sbostic register struct uda_softc *sc = &uda_softc[ctlr]; 127133444Sbostic register struct udadevice *udaddr = (struct udadevice *)um->um_addr; 127232523Sbostic register struct uda *ud; 127332523Sbostic register struct mscp *mp; 12744743Swnj register int i; 12754743Swnj 127635401Stef #ifdef QBA 127736036Skarels splx(sc->sc_ipl); /* Qbus interrupt protocol is odd */ 127827254Skridle #endif 127932523Sbostic sc->sc_wticks = 0; /* reset interrupt watchdog */ 128032523Sbostic 128132523Sbostic /* 128232523Sbostic * Combinations during steps 1, 2, and 3: STEPnMASK 128332523Sbostic * corresponds to which bits should be tested; 128432523Sbostic * STEPnGOOD corresponds to the pattern that should 128532523Sbostic * appear after the interrupt from STEPn initialisation. 128632523Sbostic * All steps test the bits in ALLSTEPS. 128732523Sbostic */ 128832523Sbostic #define ALLSTEPS (UDA_ERR|UDA_STEP4|UDA_STEP3|UDA_STEP2|UDA_STEP1) 128932523Sbostic 129032523Sbostic #define STEP1MASK (ALLSTEPS | UDA_IE | UDA_NCNRMASK) 129132523Sbostic #define STEP1GOOD (UDA_STEP2 | UDA_IE | (NCMDL2 << 3) | NRSPL2) 129232523Sbostic 129332523Sbostic #define STEP2MASK (ALLSTEPS | UDA_IE | UDA_IVECMASK) 129432523Sbostic #define STEP2GOOD (UDA_STEP3 | UDA_IE | (sc->sc_ivec >> 2)) 129532523Sbostic 129632523Sbostic #define STEP3MASK ALLSTEPS 129732523Sbostic #define STEP3GOOD UDA_STEP4 129832523Sbostic 12994743Swnj switch (sc->sc_state) { 130032523Sbostic 130132523Sbostic case ST_IDLE: 130232523Sbostic /* 130332523Sbostic * Ignore unsolicited interrupts. 130432523Sbostic */ 130532523Sbostic log(LOG_WARNING, "uda%d: stray intr\n", ctlr); 13064743Swnj return; 13074743Swnj 130832523Sbostic case ST_STEP1: 130932523Sbostic /* 131032523Sbostic * Begin step two initialisation. 131132523Sbostic */ 131232523Sbostic if ((udaddr->udasa & STEP1MASK) != STEP1GOOD) { 131332523Sbostic i = 1; 131432523Sbostic initfailed: 131532523Sbostic printf("uda%d: init step %d failed, sa=%b\n", 131632523Sbostic ctlr, i, udaddr->udasa, udasr_bits); 131733444Sbostic udasaerror(um, 0); 131832523Sbostic sc->sc_state = ST_IDLE; 131932523Sbostic if (sc->sc_flags & SC_DOWAKE) { 132032523Sbostic sc->sc_flags &= ~SC_DOWAKE; 132133444Sbostic wakeup((caddr_t)sc); 132232523Sbostic } 13234743Swnj return; 13244743Swnj } 132533444Sbostic udaddr->udasa = (int)&sc->sc_uda->uda_ca.ca_rspdsc[0] | 132632523Sbostic (cpu == VAX_780 || cpu == VAX_8600 ? UDA_PI : 0); 132732523Sbostic sc->sc_state = ST_STEP2; 13284743Swnj return; 13294743Swnj 133032523Sbostic case ST_STEP2: 133132523Sbostic /* 133232523Sbostic * Begin step 3 initialisation. 133332523Sbostic */ 133432523Sbostic if ((udaddr->udasa & STEP2MASK) != STEP2GOOD) { 133532523Sbostic i = 2; 133632523Sbostic goto initfailed; 13374743Swnj } 133833444Sbostic udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_rspdsc[0]) >> 16; 133932523Sbostic sc->sc_state = ST_STEP3; 13404743Swnj return; 13414743Swnj 134232523Sbostic case ST_STEP3: 134332523Sbostic /* 134432523Sbostic * Set controller characteristics (finish initialisation). 134532523Sbostic */ 134632523Sbostic if ((udaddr->udasa & STEP3MASK) != STEP3GOOD) { 134732523Sbostic i = 3; 134832523Sbostic goto initfailed; 13494743Swnj } 135032523Sbostic i = udaddr->udasa & 0xff; 135132523Sbostic if (i != sc->sc_micro) { 135232523Sbostic sc->sc_micro = i; 135332523Sbostic printf("uda%d: version %d model %d\n", 135432523Sbostic ctlr, i & 0xf, i >> 4); 135532523Sbostic } 135632523Sbostic 135717553Skarels /* 135832523Sbostic * Present the burst size, then remove it. Why this 135932523Sbostic * should be done this way, I have no idea. 136032523Sbostic * 136132523Sbostic * Note that this assumes udaburst[ctlr] > 0. 136217553Skarels */ 136332523Sbostic udaddr->udasa = UDA_GO | (udaburst[ctlr] - 1) << 2; 13644743Swnj udaddr->udasa = UDA_GO; 136532523Sbostic printf("uda%d: DMA burst size set to %d\n", 136632523Sbostic ctlr, udaburst[ctlr]); 13674743Swnj 136832523Sbostic udainitds(ctlr); /* initialise data structures */ 136932523Sbostic 13704743Swnj /* 137132523Sbostic * Before we can get a command packet, we need some 137232523Sbostic * credits. Fake some up to keep mscp_getcp() happy, 137332523Sbostic * get a packet, and cancel all credits (the right 137432523Sbostic * number should come back in the response to the 137532523Sbostic * SCC packet). 13764743Swnj */ 137732523Sbostic sc->sc_mi.mi_credits = MSCP_MINCREDITS + 1; 137832523Sbostic mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT); 137932523Sbostic if (mp == NULL) /* `cannot happen' */ 138032523Sbostic panic("udaintr"); 138132523Sbostic sc->sc_mi.mi_credits = 0; 138232523Sbostic mp->mscp_opcode = M_OP_SETCTLRC; 138332523Sbostic mp->mscp_unit = 0; 138432523Sbostic mp->mscp_sccc.sccc_ctlrflags = M_CF_ATTN | M_CF_MISC | 138532523Sbostic M_CF_THIS; 138632523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 138732523Sbostic i = udaddr->udaip; 138832523Sbostic sc->sc_state = ST_SETCHAR; 13894743Swnj return; 13904743Swnj 139132523Sbostic case ST_SETCHAR: 139232523Sbostic case ST_RUN: 139332523Sbostic /* 139432523Sbostic * Handle Set Ctlr Characteristics responses and operational 139532523Sbostic * responses (via mscp_dorsp). 139632523Sbostic */ 13974743Swnj break; 13984743Swnj 13994743Swnj default: 140032523Sbostic printf("uda%d: driver bug, state %d\n", ctlr, sc->sc_state); 140132523Sbostic panic("udastate"); 14024743Swnj } 14034743Swnj 140432523Sbostic if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 140533444Sbostic udasaerror(um, 1); 140632523Sbostic return; 14074743Swnj } 14084743Swnj 140932523Sbostic ud = &uda[ctlr]; 141032523Sbostic 14114743Swnj /* 141232523Sbostic * Handle buffer purge requests. 14134743Swnj */ 14144743Swnj if (ud->uda_ca.ca_bdp) { 141526372Skarels UBAPURGE(um->um_hd->uh_uba, ud->uda_ca.ca_bdp); 14164743Swnj ud->uda_ca.ca_bdp = 0; 141732523Sbostic udaddr->udasa = 0; /* signal purge complete */ 14184743Swnj } 14194743Swnj 14204743Swnj /* 142132523Sbostic * Check for response and command ring transitions. 14224743Swnj */ 14234743Swnj if (ud->uda_ca.ca_rspint) { 14244743Swnj ud->uda_ca.ca_rspint = 0; 142532523Sbostic mscp_dorsp(&sc->sc_mi); 14264743Swnj } 14274743Swnj if (ud->uda_ca.ca_cmdint) { 14284743Swnj ud->uda_ca.ca_cmdint = 0; 142932523Sbostic MSCP_DOCMD(&sc->sc_mi); 14304743Swnj } 143132523Sbostic udastart(um); 14324743Swnj } 14334743Swnj 14344743Swnj /* 143532523Sbostic * Initialise the various data structures that control the UDA50. 143617553Skarels */ 143732523Sbostic udainitds(ctlr) 143832523Sbostic int ctlr; 143932523Sbostic { 144032523Sbostic register struct uda *ud = &uda[ctlr]; 144132523Sbostic register struct uda *uud = uda_softc[ctlr].sc_uda; 144232523Sbostic register struct mscp *mp; 144332523Sbostic register int i; 14444743Swnj 144532523Sbostic for (i = 0, mp = ud->uda_rsp; i < NRSP; i++, mp++) { 144632523Sbostic ud->uda_ca.ca_rspdsc[i] = MSCP_OWN | MSCP_INT | 144732523Sbostic (long)&uud->uda_rsp[i].mscp_cmdref; 144832523Sbostic mp->mscp_addr = &ud->uda_ca.ca_rspdsc[i]; 144932523Sbostic mp->mscp_msglen = MSCP_MSGLEN; 14504743Swnj } 145132523Sbostic for (i = 0, mp = ud->uda_cmd; i < NCMD; i++, mp++) { 145232523Sbostic ud->uda_ca.ca_cmddsc[i] = MSCP_INT | 145332523Sbostic (long)&uud->uda_cmd[i].mscp_cmdref; 145432523Sbostic mp->mscp_addr = &ud->uda_ca.ca_cmddsc[i]; 145532523Sbostic mp->mscp_msglen = MSCP_MSGLEN; 145632523Sbostic } 14574743Swnj } 14584743Swnj 14594743Swnj /* 146033444Sbostic * Handle an error datagram. 14614743Swnj */ 146232523Sbostic udadgram(mi, mp) 146332523Sbostic struct mscp_info *mi; 146432523Sbostic struct mscp *mp; 14654743Swnj { 146617553Skarels 146732523Sbostic mscp_decodeerror(mi->mi_md->md_mname, mi->mi_ctlr, mp); 146833444Sbostic /* 146933444Sbostic * SDI status information bytes 10 and 11 are the microprocessor 147033444Sbostic * error code and front panel code respectively. These vary per 147133444Sbostic * drive type and are printed purely for field service information. 147233444Sbostic */ 147333444Sbostic if (mp->mscp_format == M_FM_SDI) 147433444Sbostic printf("\tsdi uproc error code 0x%x, front panel code 0x%x\n", 147533444Sbostic mp->mscp_erd.erd_sdistat[10], 147633444Sbostic mp->mscp_erd.erd_sdistat[11]); 147732523Sbostic } 147817553Skarels 147932523Sbostic /* 148032523Sbostic * The Set Controller Characteristics command finished. 148132523Sbostic * Record the new state of the controller. 148232523Sbostic */ 148332523Sbostic udactlrdone(mi, mp) 148432523Sbostic register struct mscp_info *mi; 148532523Sbostic struct mscp *mp; 148632523Sbostic { 148732523Sbostic register struct uda_softc *sc = &uda_softc[mi->mi_ctlr]; 148817553Skarels 148932523Sbostic if ((mp->mscp_status & M_ST_MASK) == M_ST_SUCCESS) 149032523Sbostic sc->sc_state = ST_RUN; 149132523Sbostic else { 149232523Sbostic printf("uda%d: SETCTLRC failed: ", 149332523Sbostic mi->mi_ctlr, mp->mscp_status); 149432523Sbostic mscp_printevent(mp); 149532523Sbostic sc->sc_state = ST_IDLE; 14964743Swnj } 149732523Sbostic if (sc->sc_flags & SC_DOWAKE) { 149832523Sbostic sc->sc_flags &= ~SC_DOWAKE; 149932523Sbostic wakeup((caddr_t)sc); 15006964Ssam } 15014743Swnj } 15024743Swnj 15034743Swnj /* 150432523Sbostic * Received a response from an as-yet unconfigured drive. Configure it 150532523Sbostic * in, if possible. 15064743Swnj */ 150732523Sbostic udaunconf(mi, mp) 150832523Sbostic struct mscp_info *mi; 150932523Sbostic register struct mscp *mp; 15104743Swnj { 15114743Swnj 151217553Skarels /* 151332523Sbostic * If it is a slave response, copy it to udaslavereply for 151432523Sbostic * udaslave() to look at. 151517553Skarels */ 151632523Sbostic if (mp->mscp_opcode == (M_OP_GETUNITST | M_OP_END) && 151732523Sbostic (uda_softc[mi->mi_ctlr].sc_flags & SC_INSLAVE) != 0) { 151832523Sbostic udaslavereply = *mp; 151932523Sbostic return (MSCP_DONE); 15204743Swnj } 152132523Sbostic 152232523Sbostic /* 152332523Sbostic * Otherwise, it had better be an available attention response. 152432523Sbostic */ 152532523Sbostic if (mp->mscp_opcode != M_OP_AVAILATTN) 152632523Sbostic return (MSCP_FAILED); 152732523Sbostic 152832523Sbostic /* do what autoconf does */ 152932523Sbostic return (MSCP_FAILED); /* not yet, arwhite, not yet */ 15304743Swnj } 15314743Swnj 153232523Sbostic /* 153332523Sbostic * A drive came on line. Check its type and size. Return DONE if 153432523Sbostic * we think the drive is truly on line. In any case, awaken anyone 153532523Sbostic * sleeping on the drive on-line-ness. 153632523Sbostic */ 153732523Sbostic udaonline(ui, mp) 153832523Sbostic register struct uba_device *ui; 153932523Sbostic struct mscp *mp; 15404743Swnj { 154132523Sbostic register struct ra_info *ra = &ra_info[ui->ui_unit]; 15424743Swnj 154332523Sbostic wakeup((caddr_t)&ui->ui_flags); 154432523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 154536036Skarels if (!cold) 154636036Skarels printf("uda%d: ra%d", ui->ui_ctlr, ui->ui_unit); 154736036Skarels printf(": attempt to bring on line failed: "); 154832523Sbostic mscp_printevent(mp); 154932523Sbostic ra->ra_state = CLOSED; 155032523Sbostic return (MSCP_FAILED); 155132523Sbostic } 155232523Sbostic 155332523Sbostic ra->ra_state = OPENRAW; 155432523Sbostic ra->ra_dsize = (daddr_t)mp->mscp_onle.onle_unitsize; 155534283Skarels if (!cold) 155634283Skarels printf("ra%d: uda%d, unit %d, size = %d sectors\n", ui->ui_unit, 155734283Skarels ui->ui_ctlr, mp->mscp_unit, ra->ra_dsize); 155832523Sbostic /* can now compute ncyl */ 155932523Sbostic ra->ra_geom.rg_ncyl = ra->ra_dsize / ra->ra_geom.rg_ntracks / 156032523Sbostic ra->ra_geom.rg_nsectors; 156132523Sbostic return (MSCP_DONE); 15624743Swnj } 15634743Swnj 156432523Sbostic /* 156532523Sbostic * We got some (configured) unit's status. Return DONE if it succeeded. 156632523Sbostic */ 156732523Sbostic udagotstatus(ui, mp) 156832523Sbostic register struct uba_device *ui; 156932523Sbostic register struct mscp *mp; 15704743Swnj { 15714743Swnj 157232523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 157332523Sbostic printf("uda%d: attempt to get status for ra%d failed: ", 157432523Sbostic ui->ui_ctlr, ui->ui_unit); 157532523Sbostic mscp_printevent(mp); 157632523Sbostic return (MSCP_FAILED); 157732523Sbostic } 157832523Sbostic /* record for (future) bad block forwarding and whatever else */ 157932523Sbostic uda_rasave(ui->ui_unit, mp, 1); 158032523Sbostic return (MSCP_DONE); 15814743Swnj } 15824743Swnj 158332523Sbostic /* 158432523Sbostic * A transfer failed. We get a chance to fix or restart it. 158532523Sbostic * Need to write the bad block forwaring code first.... 158632523Sbostic */ 158732523Sbostic /*ARGSUSED*/ 158832523Sbostic udaioerror(ui, mp, bp) 158932523Sbostic register struct uba_device *ui; 159032523Sbostic register struct mscp *mp; 159132523Sbostic struct buf *bp; 15924743Swnj { 15934743Swnj 159432523Sbostic if (mp->mscp_flags & M_EF_BBLKR) { 159532523Sbostic /* 159632523Sbostic * A bad block report. Eventually we will 159732523Sbostic * restart this transfer, but for now, just 159832523Sbostic * log it and give up. 159932523Sbostic */ 160032523Sbostic log(LOG_ERR, "ra%d: bad block report: %d%s\n", 160132523Sbostic ui->ui_unit, mp->mscp_seq.seq_lbn, 160232523Sbostic mp->mscp_flags & M_EF_BBLKU ? " + others" : ""); 160332523Sbostic } else { 160432523Sbostic /* 160532523Sbostic * What the heck IS a `serious exception' anyway? 160632523Sbostic * IT SURE WOULD BE NICE IF DEC SOLD DOCUMENTATION 160732523Sbostic * FOR THEIR OWN CONTROLLERS. 160832523Sbostic */ 160932523Sbostic if (mp->mscp_flags & M_EF_SEREX) 161032523Sbostic log(LOG_ERR, "ra%d: serious exception reported\n", 161132523Sbostic ui->ui_unit); 16124743Swnj } 161332523Sbostic return (MSCP_FAILED); 16144743Swnj } 16154743Swnj 161632523Sbostic /* 161732523Sbostic * A replace operation finished. 161832523Sbostic */ 161932523Sbostic /*ARGSUSED*/ 162032523Sbostic udareplace(ui, mp) 162132523Sbostic struct uba_device *ui; 162232523Sbostic struct mscp *mp; 16234743Swnj { 162417553Skarels 162532523Sbostic panic("udareplace"); 16264743Swnj } 162717553Skarels 162832523Sbostic /* 162932523Sbostic * A bad block related operation finished. 163032523Sbostic */ 163132523Sbostic /*ARGSUSED*/ 163232523Sbostic udabb(ui, mp, bp) 163332523Sbostic struct uba_device *ui; 163432523Sbostic struct mscp *mp; 163532523Sbostic struct buf *bp; 163617553Skarels { 163717553Skarels 163832523Sbostic panic("udabb"); 163917553Skarels } 164017553Skarels 164132523Sbostic 164232523Sbostic /* 164332523Sbostic * I/O controls. 164432523Sbostic */ 164532523Sbostic udaioctl(dev, cmd, data, flag) 164612511Ssam dev_t dev; 164730536Skarels int cmd; 164830536Skarels caddr_t data; 164930536Skarels int flag; 165012511Ssam { 165132523Sbostic register int unit = udaunit(dev); 165230536Skarels register struct disklabel *lp; 165333443Skarels register struct ra_info *ra = &ra_info[unit]; 165434638Skarels int error = 0; 165512511Ssam 165632523Sbostic lp = &udalabel[unit]; 165730536Skarels 165830536Skarels switch (cmd) { 165930536Skarels 166030536Skarels case DIOCGDINFO: 166130536Skarels *(struct disklabel *)data = *lp; 166230536Skarels break; 166330536Skarels 166430773Skarels case DIOCGPART: 166530773Skarels ((struct partinfo *)data)->disklab = lp; 166630773Skarels ((struct partinfo *)data)->part = 166732523Sbostic &lp->d_partitions[udapart(dev)]; 166830536Skarels break; 166930536Skarels 167030536Skarels case DIOCSDINFO: 167130536Skarels if ((flag & FWRITE) == 0) 167230536Skarels error = EBADF; 167330536Skarels else 167432574Skarels error = setdisklabel(lp, (struct disklabel *)data, 167534283Skarels (ra->ra_state == OPENRAW) ? 0 : ra->ra_openpart); 167630536Skarels break; 167730536Skarels 167833443Skarels case DIOCWLABEL: 167933443Skarels if ((flag & FWRITE) == 0) 168033443Skarels error = EBADF; 168133443Skarels else 168233443Skarels ra->ra_wlabel = *(int *)data; 168333443Skarels break; 168433443Skarels 168532574Skarels case DIOCWDINFO: 168632574Skarels if ((flag & FWRITE) == 0) 168732523Sbostic error = EBADF; 168832574Skarels else if ((error = setdisklabel(lp, (struct disklabel *)data, 168934283Skarels (ra->ra_state == OPENRAW) ? 0 : ra->ra_openpart)) == 0) { 169034638Skarels int wlab; 169134638Skarels 169234283Skarels ra->ra_state = OPEN; 169334638Skarels /* simulate opening partition 0 so write succeeds */ 169434638Skarels ra->ra_openpart |= (1 << 0); /* XXX */ 169534638Skarels wlab = ra->ra_wlabel; 169634638Skarels ra->ra_wlabel = 1; 169732574Skarels error = writedisklabel(dev, udastrategy, lp); 169834638Skarels ra->ra_openpart = ra->ra_copenpart | ra->ra_bopenpart; 169934638Skarels ra->ra_wlabel = wlab; 170034283Skarels } 170130536Skarels break; 170230536Skarels 170332523Sbostic #ifdef notyet 170432523Sbostic case UDAIOCREPLACE: 170532523Sbostic /* 170632523Sbostic * Initiate bad block replacement for the given LBN. 170732523Sbostic * (Should we allow modifiers?) 170832523Sbostic */ 170932523Sbostic error = EOPNOTSUPP; 171032523Sbostic break; 171132523Sbostic 171232523Sbostic case UDAIOCGMICRO: 171332523Sbostic /* 171432523Sbostic * Return the microcode revision for the UDA50 running 171532523Sbostic * this drive. 171632523Sbostic */ 171733444Sbostic *(int *)data = uda_softc[uddinfo[unit]->ui_ctlr].sc_micro; 171832523Sbostic break; 171932523Sbostic #endif 172032523Sbostic 172130536Skarels default: 172230536Skarels error = ENOTTY; 172330536Skarels break; 172430536Skarels } 172532523Sbostic return (error); 172632523Sbostic } 172732523Sbostic 172832523Sbostic /* 172932523Sbostic * A Unibus reset has occurred on UBA uban. Reinitialise the controller(s) 173032523Sbostic * on that Unibus, and requeue outstanding I/O. 173132523Sbostic */ 173232523Sbostic udareset(uban) 173332523Sbostic int uban; 173432523Sbostic { 173532523Sbostic register struct uba_ctlr *um; 173632523Sbostic register struct uda_softc *sc; 173732523Sbostic register int ctlr; 173832523Sbostic 173932523Sbostic for (ctlr = 0, sc = uda_softc; ctlr < NUDA; ctlr++, sc++) { 174032523Sbostic if ((um = udaminfo[ctlr]) == NULL || um->um_ubanum != uban || 174132523Sbostic um->um_alive == 0) 174232523Sbostic continue; 174332523Sbostic printf(" uda%d", ctlr); 174432523Sbostic 174532523Sbostic /* 174632523Sbostic * Our BDP (if any) is gone; our command (if any) is 174732523Sbostic * flushed; the device is no longer mapped; and the 174832523Sbostic * UDA50 is not yet initialised. 174932523Sbostic */ 175032523Sbostic if (um->um_bdp) { 175132523Sbostic printf("<%d>", UBAI_BDP(um->um_bdp)); 175232523Sbostic um->um_bdp = 0; 175332523Sbostic } 175432523Sbostic um->um_ubinfo = 0; 175532523Sbostic um->um_cmd = 0; 175632523Sbostic sc->sc_flags &= ~SC_MAPPED; 175732523Sbostic sc->sc_state = ST_IDLE; 175832523Sbostic 175932523Sbostic /* reset queues and requeue pending transfers */ 176032523Sbostic mscp_requeue(&sc->sc_mi); 176132523Sbostic 176232523Sbostic /* 176332523Sbostic * If it fails to initialise we will notice later and 176432523Sbostic * try again (and again...). Do not call udastart() 176532523Sbostic * here; it will be done after the controller finishes 176632523Sbostic * initialisation. 176732523Sbostic */ 176832523Sbostic if (udainit(ctlr)) 176932523Sbostic printf(" (hung)"); 177032523Sbostic } 177132523Sbostic } 177232523Sbostic 177332523Sbostic /* 177432523Sbostic * Watchdog timer: If the controller is active, and no interrupts 177532523Sbostic * have occurred for 30 seconds, assume it has gone away. 177632523Sbostic */ 177732523Sbostic udawatch() 177832523Sbostic { 177932523Sbostic register int i; 178032523Sbostic register struct uba_ctlr *um; 178132523Sbostic register struct uda_softc *sc; 178232523Sbostic 178332523Sbostic timeout(udawatch, (caddr_t) 0, hz); /* every second */ 178432523Sbostic for (i = 0, sc = uda_softc; i < NUDA; i++, sc++) { 178532523Sbostic if ((um = udaminfo[i]) == 0 || !um->um_alive) 178632523Sbostic continue; 178732523Sbostic if (sc->sc_state == ST_IDLE) 178832523Sbostic continue; 178932523Sbostic if (sc->sc_state == ST_RUN && !um->um_tab.b_active) 179032523Sbostic sc->sc_wticks = 0; 179132523Sbostic else if (++sc->sc_wticks >= 30) { 179232523Sbostic sc->sc_wticks = 0; 179332523Sbostic printf("uda%d: lost interrupt\n", i); 179432523Sbostic ubareset(um->um_ubanum); 179532523Sbostic } 179632523Sbostic } 179732523Sbostic } 179832523Sbostic 179932523Sbostic /* 180032523Sbostic * Do a panic dump. We set up the controller for one command packet 180132523Sbostic * and one response packet, for which we use `struct uda1'. 180232523Sbostic */ 180332523Sbostic struct uda1 { 180432523Sbostic struct uda1ca uda1_ca; /* communications area */ 180532523Sbostic struct mscp uda1_rsp; /* response packet */ 180632523Sbostic struct mscp uda1_cmd; /* command packet */ 180732523Sbostic } uda1; 180832523Sbostic 180932523Sbostic #define DBSIZE 32 /* dump 16K at a time */ 181032523Sbostic 181132523Sbostic udadump(dev) 181232523Sbostic dev_t dev; 181332523Sbostic { 181432523Sbostic struct udadevice *udaddr; 181532523Sbostic struct uda1 *ud_ubaddr; 181632523Sbostic char *start; 181732523Sbostic int num, blk, unit, maxsz, blkoff, reg; 181832523Sbostic struct partition *pp; 181932523Sbostic register struct uba_regs *uba; 182032523Sbostic register struct uba_device *ui; 182132523Sbostic register struct uda1 *ud; 182232523Sbostic register struct pte *io; 182332523Sbostic register int i; 182432523Sbostic 182532523Sbostic /* 182632523Sbostic * Make sure the device is a reasonable place on which to dump. 182732523Sbostic */ 182832523Sbostic unit = udaunit(dev); 182932523Sbostic if (unit >= NRA) 183032523Sbostic return (ENXIO); 183133444Sbostic #define phys(cast, addr) ((cast) ((int)addr & 0x7fffffff)) 183232523Sbostic ui = phys(struct uba_device *, udadinfo[unit]); 183332523Sbostic if (ui == NULL || ui->ui_alive == 0) 183432523Sbostic return (ENXIO); 183532523Sbostic 183632523Sbostic /* 183732523Sbostic * Find and initialise the UBA; get the physical address of the 183832523Sbostic * device registers, and of communications area and command and 183932523Sbostic * response packet. 184032523Sbostic */ 184132523Sbostic uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 184232523Sbostic ubainit(uba); 184332523Sbostic udaddr = (struct udadevice *)ui->ui_physaddr; 184432523Sbostic ud = phys(struct uda1 *, &uda1); 184532523Sbostic 184632523Sbostic /* 184732523Sbostic * Map the ca+packets into Unibus I/O space so the UDA50 can get 184832523Sbostic * at them. Use the registers at the end of the Unibus map (since 184932523Sbostic * we will use the registers at the beginning to map the memory 185032523Sbostic * we are dumping). 185132523Sbostic */ 185232523Sbostic num = btoc(sizeof(struct uda1)) + 1; 185332523Sbostic reg = NUBMREG - num; 185432523Sbostic io = &uba->uba_map[reg]; 185532523Sbostic for (i = 0; i < num; i++) 185632523Sbostic *(int *)io++ = UBAMR_MRV | (btop(ud) + i); 185732523Sbostic ud_ubaddr = (struct uda1 *)(((int)ud & PGOFSET) | (reg << 9)); 185832523Sbostic 185932523Sbostic /* 186032523Sbostic * Initialise the controller, with one command and one response 186132523Sbostic * packet. 186232523Sbostic */ 186332523Sbostic udaddr->udaip = 0; 186432523Sbostic if (udadumpwait(udaddr, UDA_STEP1)) 186532523Sbostic return (EFAULT); 186632523Sbostic udaddr->udasa = UDA_ERR; 186732523Sbostic if (udadumpwait(udaddr, UDA_STEP2)) 186832523Sbostic return (EFAULT); 186932523Sbostic udaddr->udasa = (int)&ud_ubaddr->uda1_ca.ca_rspdsc; 187032523Sbostic if (udadumpwait(udaddr, UDA_STEP3)) 187132523Sbostic return (EFAULT); 187232523Sbostic udaddr->udasa = ((int)&ud_ubaddr->uda1_ca.ca_rspdsc) >> 16; 187332523Sbostic if (udadumpwait(udaddr, UDA_STEP4)) 187432523Sbostic return (EFAULT); 187532523Sbostic uda_softc[ui->ui_ctlr].sc_micro = udaddr->udasa & 0xff; 187632523Sbostic udaddr->udasa = UDA_GO; 187732523Sbostic 187832523Sbostic /* 187932523Sbostic * Set up the command and response descriptor, then set the 188032523Sbostic * controller characteristics and bring the drive on line. 188132523Sbostic * Note that all uninitialised locations in uda1_cmd are zero. 188232523Sbostic */ 188332523Sbostic ud->uda1_ca.ca_rspdsc = (long)&ud_ubaddr->uda1_rsp.mscp_cmdref; 188432523Sbostic ud->uda1_ca.ca_cmddsc = (long)&ud_ubaddr->uda1_cmd.mscp_cmdref; 188532523Sbostic /* ud->uda1_cmd.mscp_sccc.sccc_ctlrflags = 0; */ 188632523Sbostic /* ud->uda1_cmd.mscp_sccc.sccc_version = 0; */ 188732523Sbostic if (udadumpcmd(M_OP_SETCTLRC, ud, ui)) 188832523Sbostic return (EFAULT); 188932523Sbostic ud->uda1_cmd.mscp_unit = ui->ui_slave; 189032523Sbostic if (udadumpcmd(M_OP_ONLINE, ud, ui)) 189132523Sbostic return (EFAULT); 189232523Sbostic 189332523Sbostic pp = phys(struct partition *, 189432523Sbostic &udalabel[unit].d_partitions[udapart(dev)]); 189532523Sbostic maxsz = pp->p_size; 189632523Sbostic blkoff = pp->p_offset; 189732523Sbostic 189832523Sbostic /* 189932523Sbostic * Dump all of physical memory, or as much as will fit in the 190032523Sbostic * space provided. 190132523Sbostic */ 190232523Sbostic start = 0; 190332523Sbostic num = maxfree; 190432523Sbostic if (dumplo + num >= maxsz) 190532523Sbostic num = maxsz - dumplo; 190632523Sbostic blkoff += dumplo; 190732523Sbostic 190832523Sbostic /* 190932523Sbostic * Write out memory, DBSIZE pages at a time. 191032523Sbostic * N.B.: this code depends on the fact that the sector 191132523Sbostic * size == the page size. 191232523Sbostic */ 191332523Sbostic while (num > 0) { 191432523Sbostic blk = num > DBSIZE ? DBSIZE : num; 191532523Sbostic io = uba->uba_map; 191632523Sbostic /* 191732523Sbostic * Map in the pages to write, leaving an invalid entry 191832523Sbostic * at the end to guard against wild Unibus transfers. 191932523Sbostic * Then do the write. 192032523Sbostic */ 192132523Sbostic for (i = 0; i < blk; i++) 192233444Sbostic *(int *)io++ = UBAMR_MRV | (btop(start) + i); 192333444Sbostic *(int *)io = 0; 192432523Sbostic ud->uda1_cmd.mscp_unit = ui->ui_slave; 192532523Sbostic ud->uda1_cmd.mscp_seq.seq_lbn = btop(start) + blkoff; 192632523Sbostic ud->uda1_cmd.mscp_seq.seq_bytecount = blk << PGSHIFT; 192732523Sbostic if (udadumpcmd(M_OP_WRITE, ud, ui)) 192832523Sbostic return (EIO); 192932523Sbostic start += blk << PGSHIFT; 193032523Sbostic num -= blk; 193132523Sbostic } 193232523Sbostic return (0); /* made it! */ 193332523Sbostic } 193432523Sbostic 193532523Sbostic /* 193632523Sbostic * Wait for some of the bits in `bits' to come on. If the error bit 193732523Sbostic * comes on, or ten seconds pass without response, return true (error). 193832523Sbostic */ 193932523Sbostic udadumpwait(udaddr, bits) 194032523Sbostic register struct udadevice *udaddr; 194132523Sbostic register int bits; 194232523Sbostic { 194332523Sbostic register int timo = todr() + 1000; 194432523Sbostic 194532523Sbostic while ((udaddr->udasa & bits) == 0) { 194632523Sbostic if (udaddr->udasa & UDA_ERR) { 194732523Sbostic printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 194832523Sbostic return (1); 194932523Sbostic } 195032523Sbostic if (todr() >= timo) { 195132523Sbostic printf("timeout\ndump "); 195232523Sbostic return (1); 195332523Sbostic } 195432523Sbostic } 195530536Skarels return (0); 195630536Skarels } 195730536Skarels 195832523Sbostic /* 195932523Sbostic * Feed a command to the UDA50, wait for its response, and return 196032523Sbostic * true iff something went wrong. 196132523Sbostic */ 196232523Sbostic udadumpcmd(op, ud, ui) 196332523Sbostic int op; 196432523Sbostic register struct uda1 *ud; 196532523Sbostic struct uba_device *ui; 196632523Sbostic { 196732523Sbostic register struct udadevice *udaddr; 196832523Sbostic register int n; 196932523Sbostic #define mp (&ud->uda1_rsp) 197032523Sbostic 197133444Sbostic udaddr = (struct udadevice *)ui->ui_physaddr; 197232523Sbostic ud->uda1_cmd.mscp_opcode = op; 197332523Sbostic ud->uda1_cmd.mscp_msglen = MSCP_MSGLEN; 197432523Sbostic ud->uda1_rsp.mscp_msglen = MSCP_MSGLEN; 197532523Sbostic ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 197632523Sbostic ud->uda1_ca.ca_cmddsc |= MSCP_OWN | MSCP_INT; 197732523Sbostic if (udaddr->udasa & UDA_ERR) { 197832523Sbostic printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 197932523Sbostic return (1); 198032523Sbostic } 198132523Sbostic n = udaddr->udaip; 198232523Sbostic n = todr() + 1000; 198332523Sbostic for (;;) { 198432523Sbostic if (todr() > n) { 198532523Sbostic printf("timeout\ndump "); 198632523Sbostic return (1); 198732523Sbostic } 198832523Sbostic if (ud->uda1_ca.ca_cmdint) 198932523Sbostic ud->uda1_ca.ca_cmdint = 0; 199032523Sbostic if (ud->uda1_ca.ca_rspint == 0) 199132523Sbostic continue; 199232523Sbostic ud->uda1_ca.ca_rspint = 0; 199332523Sbostic if (mp->mscp_opcode == (op | M_OP_END)) 199432523Sbostic break; 199532523Sbostic printf("\n"); 199632523Sbostic switch (MSCP_MSGTYPE(mp->mscp_msgtc)) { 199732523Sbostic 199832523Sbostic case MSCPT_SEQ: 199932523Sbostic printf("sequential"); 200032523Sbostic break; 200132523Sbostic 200232523Sbostic case MSCPT_DATAGRAM: 200332523Sbostic mscp_decodeerror("uda", ui->ui_ctlr, mp); 200432523Sbostic printf("datagram"); 200532523Sbostic break; 200632523Sbostic 200732523Sbostic case MSCPT_CREDITS: 200832523Sbostic printf("credits"); 200932523Sbostic break; 201032523Sbostic 201132523Sbostic case MSCPT_MAINTENANCE: 201232523Sbostic printf("maintenance"); 201332523Sbostic break; 201432523Sbostic 201532523Sbostic default: 201632523Sbostic printf("unknown (type 0x%x)", 201732523Sbostic MSCP_MSGTYPE(mp->mscp_msgtc)); 201832523Sbostic break; 201932523Sbostic } 202032523Sbostic printf(" ignored\ndump "); 202132523Sbostic ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 202232523Sbostic } 202332523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 202432523Sbostic printf("error: op 0x%x => 0x%x status 0x%x\ndump ", op, 202532523Sbostic mp->mscp_opcode, mp->mscp_status); 202632523Sbostic return (1); 202732523Sbostic } 202832523Sbostic return (0); 202932523Sbostic #undef mp 203032523Sbostic } 203132523Sbostic 203232523Sbostic /* 203332523Sbostic * Return the size of a partition, if known, or -1 if not. 203432523Sbostic */ 203532523Sbostic udasize(dev) 203630536Skarels dev_t dev; 203730536Skarels { 203832523Sbostic register int unit = udaunit(dev); 203930536Skarels register struct uba_device *ui; 204030536Skarels 204132523Sbostic if (unit >= NRA || (ui = udadinfo[unit]) == NULL || 204232523Sbostic ui->ui_alive == 0 || (ui->ui_flags & UNIT_ONLINE) == 0 || 204332523Sbostic ra_info[unit].ra_state != OPEN) 204412511Ssam return (-1); 204532523Sbostic return ((int)udalabel[unit].d_partitions[udapart(dev)].p_size); 204612511Ssam } 204717553Skarels 204830536Skarels #ifdef COMPAT_42 204932523Sbostic /* 205032523Sbostic * Tables mapping unlabelled drives. 205132523Sbostic */ 205230536Skarels struct size { 205330536Skarels daddr_t nblocks; 205430536Skarels daddr_t blkoff; 205533444Sbostic } ra60_sizes[8] = { 205630536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 205730536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 205830536Skarels 400176, 0, /* C=sectors 0 thru 400175 */ 205930536Skarels 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 206030536Skarels 268772, 131404, /* 4.2 H => E=sectors 131404 thru 400175 */ 206130536Skarels 350852, 49324, /* F=sectors 49324 thru 400175 */ 206230536Skarels 157570, 242606, /* UCB G => G=sectors 242606 thru 400175 */ 206330536Skarels 193282, 49324, /* UCB H => H=sectors 49324 thru 242605 */ 206433444Sbostic }, ra70_sizes[8] = { 206533444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 206633444Sbostic 33440, 15972, /* B=blk 15972 thru 49323 */ 206733444Sbostic -1, 0, /* C=blk 0 thru end */ 206833444Sbostic 15884, 341220, /* D=blk 341220 thru 357103 */ 206933444Sbostic 55936, 357192, /* E=blk 357192 thru 413127 */ 207033444Sbostic -1, 413457, /* F=blk 413457 thru end */ 207133444Sbostic -1, 341220, /* G=blk 341220 thru end */ 207233444Sbostic 291346, 49731, /* H=blk 49731 thru 341076 */ 207330536Skarels }, ra80_sizes[8] = { 207430536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 207530536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 207630536Skarels 242606, 0, /* C=sectors 0 thru 242605 */ 207730536Skarels 0, 0, /* D=unused */ 207830536Skarels 193282, 49324, /* UCB H => E=sectors 49324 thru 242605 */ 207930536Skarels 82080, 49324, /* 4.2 G => F=sectors 49324 thru 131403 */ 208030536Skarels 192696, 49910, /* G=sectors 49910 thru 242605 */ 208130536Skarels 111202, 131404, /* 4.2 H => H=sectors 131404 thru 242605 */ 208230536Skarels }, ra81_sizes[8] ={ 208330536Skarels /* 208430536Skarels * These are the new standard partition sizes for ra81's. 208530536Skarels * An RA_COMPAT system is compiled with D, E, and F corresponding 208630536Skarels * to the 4.2 partitions for G, H, and F respectively. 208730536Skarels */ 208830536Skarels #ifndef UCBRA 208930536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 209030536Skarels 66880, 16422, /* B=sectors 16422 thru 83301 */ 209130536Skarels 891072, 0, /* C=sectors 0 thru 891071 */ 209230536Skarels #ifdef RA_COMPAT 209330536Skarels 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 209430536Skarels 759668, 131404, /* 4.2 H => E=sectors 131404 thru 891071 */ 209530536Skarels 478582, 412490, /* 4.2 F => F=sectors 412490 thru 891071 */ 209630536Skarels #else 209730536Skarels 15884, 375564, /* D=sectors 375564 thru 391447 */ 209830536Skarels 307200, 391986, /* E=sectors 391986 thru 699185 */ 209930536Skarels 191352, 699720, /* F=sectors 699720 thru 891071 */ 210030536Skarels #endif RA_COMPAT 210130536Skarels 515508, 375564, /* G=sectors 375564 thru 891071 */ 210230536Skarels 291346, 83538, /* H=sectors 83538 thru 374883 */ 210330536Skarels 210430536Skarels /* 210530536Skarels * These partitions correspond to the sizes used by sites at Berkeley, 210630536Skarels * and by those sites that have received copies of the Berkeley driver 210730536Skarels * with deltas 6.2 or greater (11/15/83). 210830536Skarels */ 210930536Skarels #else UCBRA 211030536Skarels 211130536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 211230536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 211330536Skarels 891072, 0, /* C=sectors 0 thru 891071 */ 211430536Skarels 15884, 242606, /* D=sectors 242606 thru 258489 */ 211530536Skarels 307200, 258490, /* E=sectors 258490 thru 565689 */ 211630536Skarels 325382, 565690, /* F=sectors 565690 thru 891071 */ 211730536Skarels 648466, 242606, /* G=sectors 242606 thru 891071 */ 211830536Skarels 193282, 49324, /* H=sectors 49324 thru 242605 */ 211930536Skarels 212030536Skarels #endif UCBRA 212133444Sbostic }, ra82_sizes[8] = { 212233444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 212333444Sbostic 66880, 16245, /* B=blk 16245 thru 83124 */ 212433444Sbostic -1, 0, /* C=blk 0 thru end */ 212533444Sbostic 15884, 375345, /* D=blk 375345 thru 391228 */ 212633444Sbostic 307200, 391590, /* E=blk 391590 thru 698789 */ 212733444Sbostic -1, 699390, /* F=blk 699390 thru end */ 212833444Sbostic -1, 375345, /* G=blk 375345 thru end */ 212933444Sbostic 291346, 83790, /* H=blk 83790 thru 375135 */ 213033444Sbostic }, rc25_sizes[8] = { 213133444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 213233444Sbostic 10032, 15884, /* B=blk 15884 thru 49323 */ 213333444Sbostic -1, 0, /* C=blk 0 thru end */ 213433444Sbostic 0, 0, /* D=blk 340670 thru 356553 */ 213533444Sbostic 0, 0, /* E=blk 356554 thru 412489 */ 213633444Sbostic 0, 0, /* F=blk 412490 thru end */ 213733444Sbostic -1, 25916, /* G=blk 49324 thru 131403 */ 213833444Sbostic 0, 0, /* H=blk 131404 thru end */ 213933444Sbostic }, rd52_sizes[8] = { 214033444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 214133444Sbostic 9766, 15884, /* B=blk 15884 thru 25649 */ 214233444Sbostic -1, 0, /* C=blk 0 thru end */ 214333444Sbostic 0, 0, /* D=unused */ 214433444Sbostic 0, 0, /* E=unused */ 214533444Sbostic 0, 0, /* F=unused */ 214633444Sbostic -1, 25650, /* G=blk 25650 thru end */ 214733444Sbostic 0, 0, /* H=unused */ 214833444Sbostic }, rd53_sizes[8] = { 214933444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 215033444Sbostic 33440, 15884, /* B=blk 15884 thru 49323 */ 215133444Sbostic -1, 0, /* C=blk 0 thru end */ 215233444Sbostic 0, 0, /* D=unused */ 215333444Sbostic 33440, 0, /* E=blk 0 thru 33439 */ 215433444Sbostic -1, 33440, /* F=blk 33440 thru end */ 215533444Sbostic -1, 49324, /* G=blk 49324 thru end */ 215633444Sbostic -1, 15884, /* H=blk 15884 thru end */ 215733444Sbostic }, rx50_sizes[8] = { 215833444Sbostic 800, 0, /* A=blk 0 thru 799 */ 215933444Sbostic 0, 0, 216033444Sbostic -1, 0, /* C=blk 0 thru end */ 216133444Sbostic 0, 0, 216233444Sbostic 0, 0, 216333444Sbostic 0, 0, 216433444Sbostic 0, 0, 216533444Sbostic 0, 0, 216630536Skarels }; 216730536Skarels 216832523Sbostic /* 216933444Sbostic * Media ID decoding table. 217032523Sbostic */ 217132523Sbostic struct udatypes { 217233444Sbostic u_long ut_id; /* media drive ID */ 217332523Sbostic char *ut_name; /* drive type name */ 217432523Sbostic struct size *ut_sizes; /* partition tables */ 217532523Sbostic int ut_nsectors, ut_ntracks, ut_ncylinders; 217632523Sbostic } udatypes[] = { 217733444Sbostic { MSCP_MKDRIVE2('R', 'A', 60), "ra60", ra60_sizes, 42, 4, 2382 }, 217833444Sbostic { MSCP_MKDRIVE2('R', 'A', 70), "ra70", ra70_sizes, 33, 11, 1507 }, 217933444Sbostic { MSCP_MKDRIVE2('R', 'A', 80), "ra80", ra80_sizes, 31, 14, 559 }, 218033444Sbostic { MSCP_MKDRIVE2('R', 'A', 81), "ra81", ra81_sizes, 51, 14, 1248 }, 218133444Sbostic { MSCP_MKDRIVE2('R', 'A', 82), "ra82", ra82_sizes, 57, 14, 1423 }, 218233444Sbostic { MSCP_MKDRIVE2('R', 'C', 25), "rc25-removable", 218333444Sbostic rc25_sizes, 42, 4, 302 }, 218433444Sbostic { MSCP_MKDRIVE3('R', 'C', 'F', 25), "rc25-fixed", 218533444Sbostic rc25_sizes, 42, 4, 302 }, 218633444Sbostic { MSCP_MKDRIVE2('R', 'D', 52), "rd52", rd52_sizes, 18, 7, 480 }, 218733444Sbostic { MSCP_MKDRIVE2('R', 'D', 53), "rd53", rd53_sizes, 18, 8, 963 }, 218833444Sbostic { MSCP_MKDRIVE2('R', 'X', 50), "rx50", rx50_sizes, 10, 1, 80 }, 218933444Sbostic 0 219032523Sbostic }; 219132523Sbostic 219232523Sbostic #define NTYPES (sizeof(udatypes) / sizeof(*udatypes)) 219332523Sbostic 219432523Sbostic udamaptype(unit, lp) 219532523Sbostic int unit; 219630536Skarels register struct disklabel *lp; 219730536Skarels { 219832523Sbostic register struct udatypes *ut; 219932523Sbostic register struct size *sz; 220030536Skarels register struct partition *pp; 220132523Sbostic register char *p; 220232523Sbostic register int i; 220332523Sbostic register struct ra_info *ra = &ra_info[unit]; 220430536Skarels 220533444Sbostic i = MSCP_MEDIA_DRIVE(ra->ra_mediaid); 220633444Sbostic for (ut = udatypes; ut->ut_id; ut++) 220736036Skarels if (ut->ut_id == i && 220836036Skarels ut->ut_nsectors == ra->ra_geom.rg_nsectors && 220936036Skarels ut->ut_ntracks == ra->ra_geom.rg_ntracks && 221036036Skarels ut->ut_ncylinders == ra->ra_geom.rg_ncyl) 221133444Sbostic goto found; 221233444Sbostic 221333444Sbostic /* not one we know; fake up a label for the whole drive */ 221436036Skarels uda_makefakelabel(ra, lp); 221533444Sbostic i = ra->ra_mediaid; /* print the port type too */ 221636036Skarels addlog(": no partition table for %c%c %c%c%c%d, size %d;\n\ 221734283Skarels using (s,t,c)=(%d,%d,%d)", 221834283Skarels MSCP_MID_CHAR(4, i), MSCP_MID_CHAR(3, i), 221933444Sbostic MSCP_MID_CHAR(2, i), MSCP_MID_CHAR(1, i), 222036036Skarels MSCP_MID_CHAR(0, i), MSCP_MID_NUM(i), lp->d_secperunit, 222136036Skarels lp->d_nsectors, lp->d_ntracks, lp->d_ncylinders); 222234283Skarels if (!cold) 222334283Skarels addlog("\n"); 222433444Sbostic return (0); 222533444Sbostic found: 222632523Sbostic p = ut->ut_name; 222732523Sbostic for (i = 0; i < sizeof(lp->d_typename) - 1 && *p; i++) 222832523Sbostic lp->d_typename[i] = *p++; 222932523Sbostic lp->d_typename[i] = 0; 223032523Sbostic sz = ut->ut_sizes; 223132523Sbostic lp->d_nsectors = ut->ut_nsectors; 223232523Sbostic lp->d_ntracks = ut->ut_ntracks; 223332523Sbostic lp->d_ncylinders = ut->ut_ncylinders; 223430536Skarels lp->d_npartitions = 8; 223530536Skarels lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 223632523Sbostic for (pp = lp->d_partitions; pp < &lp->d_partitions[8]; pp++, sz++) { 223732523Sbostic pp->p_offset = sz->blkoff; 223832523Sbostic if ((pp->p_size = sz->nblocks) == (u_long)-1) 223932523Sbostic pp->p_size = ra->ra_dsize - sz->blkoff; 224030536Skarels } 224130536Skarels return (1); 224230536Skarels } 224332523Sbostic #endif /* COMPAT_42 */ 224436036Skarels 224536036Skarels /* 224636036Skarels * Construct a label for a drive from geometry information 224736036Skarels * if we have no better information. 224836036Skarels */ 224936036Skarels uda_makefakelabel(ra, lp) 225036036Skarels register struct ra_info *ra; 225136036Skarels register struct disklabel *lp; 225236036Skarels { 225336036Skarels lp->d_nsectors = ra->ra_geom.rg_nsectors; 225436036Skarels lp->d_ntracks = ra->ra_geom.rg_ntracks; 225536036Skarels lp->d_ncylinders = ra->ra_geom.rg_ncyl; 225636036Skarels lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 225736036Skarels bcopy("ra??", lp->d_typename, sizeof("ra??")); 225836036Skarels lp->d_npartitions = 1; 225936036Skarels lp->d_partitions[0].p_offset = 0; 226036036Skarels lp->d_partitions[0].p_size = lp->d_secperunit; 226136036Skarels } 226232523Sbostic #endif /* NUDA > 0 */ 2263