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 * 844554Sbostic * %sccs.include.redist.c% 935039Sbostic * 10*45577Storek * @(#)uda.c 7.29 (Berkeley) 11/14/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; 248*45577Storek int timeout, tries; 249*45577Storek #ifdef QBA 250*45577Storek int s; 251*45577Storek #endif 2524743Swnj 25332523Sbostic #ifdef VAX750 25432523Sbostic /* 25532523Sbostic * The UDA50 wants to share BDPs on 750s, but not on 780s or 25632523Sbostic * 8600s. (730s have no BDPs anyway.) Toward this end, we 25732523Sbostic * here set the `keep bdp' flag in the per-driver information 25832523Sbostic * if this is a 750. (We just need to do it once, but it is 25932523Sbostic * easiest to do it now, for each UDA50.) 26032523Sbostic */ 26132523Sbostic if (cpu == VAX_750) 26232523Sbostic udadriver.ud_keepbdp = 1; 26332523Sbostic #endif 26417553Skarels 26532523Sbostic probeum = um; /* remember for udaslave() */ 2664743Swnj #ifdef lint 26732523Sbostic br = 0; cvec = br; br = cvec; udaintr(0); 2684743Swnj #endif 26932523Sbostic /* 27032523Sbostic * Set up the controller-specific generic MSCP driver info. 27132523Sbostic * Note that this should really be done in the (nonexistent) 27232523Sbostic * controller attach routine. 27332523Sbostic */ 27432523Sbostic sc = &uda_softc[ctlr]; 27532523Sbostic mi = &sc->sc_mi; 27632523Sbostic mi->mi_md = &udamscpdriver; 27732523Sbostic mi->mi_ctlr = um->um_ctlr; 27832523Sbostic mi->mi_tab = &um->um_tab; 27932523Sbostic mi->mi_ip = udaip[ctlr]; 28032523Sbostic mi->mi_cmd.mri_size = NCMD; 28132523Sbostic mi->mi_cmd.mri_desc = uda[ctlr].uda_ca.ca_cmddsc; 28232523Sbostic mi->mi_cmd.mri_ring = uda[ctlr].uda_cmd; 28332523Sbostic mi->mi_rsp.mri_size = NRSP; 28432523Sbostic mi->mi_rsp.mri_desc = uda[ctlr].uda_ca.ca_rspdsc; 28532523Sbostic mi->mi_rsp.mri_ring = uda[ctlr].uda_rsp; 28632523Sbostic mi->mi_wtab.av_forw = mi->mi_wtab.av_back = &mi->mi_wtab; 28732523Sbostic 28832523Sbostic /* 28932523Sbostic * More controller specific variables. Again, this should 29032523Sbostic * be in the controller attach routine. 29132523Sbostic */ 29232523Sbostic if (udaburst[ctlr] == 0) 29332523Sbostic udaburst[ctlr] = DEFAULT_BURST; 29432523Sbostic 29532523Sbostic /* 29632523Sbostic * Get an interrupt vector. Note that even if the controller 29732523Sbostic * does not respond, we keep the vector. This is not a serious 29832523Sbostic * problem; but it would be easily fixed if we had a controller 29932523Sbostic * attach routine. Sigh. 30032523Sbostic */ 30132523Sbostic sc->sc_ivec = (uba_hd[numuba].uh_lastiv -= 4); 30217553Skarels udaddr = (struct udadevice *) reg; 30317553Skarels 30432523Sbostic /* 30532523Sbostic * Initialise the controller (partially). The UDA50 programmer's 30632523Sbostic * manual states that if initialisation fails, it should be retried 30732523Sbostic * at least once, but after a second failure the port should be 30832523Sbostic * considered `down'; it also mentions that the controller should 30932523Sbostic * initialise within ten seconds. Or so I hear; I have not seen 31032523Sbostic * this manual myself. 31132523Sbostic */ 31236036Skarels #ifdef QBA 31336036Skarels s = spl6(); 31436036Skarels #endif 31532523Sbostic tries = 0; 31632523Sbostic again: 31732523Sbostic udaddr->udaip = 0; /* start initialisation */ 31832523Sbostic timeout = todr() + 1000; /* timeout in 10 seconds */ 31932523Sbostic while ((udaddr->udasa & UDA_STEP1) == 0) 32032523Sbostic if (todr() > timeout) 32132523Sbostic goto bad; 32232523Sbostic udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 32332523Sbostic (sc->sc_ivec >> 2); 32432523Sbostic while ((udaddr->udasa & UDA_STEP2) == 0) 32532523Sbostic if (todr() > timeout) 32632523Sbostic goto bad; 32732523Sbostic 32832523Sbostic /* should have interrupted by now */ 32935401Stef #ifdef QBA 33036036Skarels sc->sc_ipl = br = qbgetpri(); 33127254Skridle #endif 33232523Sbostic return (sizeof (struct udadevice)); 33332523Sbostic bad: 33432523Sbostic if (++tries < 2) 33532523Sbostic goto again; 336*45577Storek #ifdef QBA 33736036Skarels splx(s); 338*45577Storek #endif 33932523Sbostic return (0); 3404743Swnj } 3414743Swnj 34232523Sbostic /* 34332523Sbostic * Find a slave. We allow wildcard slave numbers (something autoconf 34432523Sbostic * is not really prepared to deal with); and we need to know the 34532523Sbostic * controller number to talk to the UDA. For the latter, we keep 34632523Sbostic * track of the last controller probed, since a controller probe 34732523Sbostic * immediately precedes all slave probes for that controller. For the 34832523Sbostic * former, we simply put the unit number into ui->ui_slave after we 34932523Sbostic * have found one. 35032523Sbostic * 35132523Sbostic * Note that by the time udaslave is called, the interrupt vector 35232523Sbostic * for the UDA50 has been set up (so that udaunconf() will be called). 35332523Sbostic */ 35432523Sbostic udaslave(ui, reg) 35532523Sbostic register struct uba_device *ui; 3564743Swnj caddr_t reg; 3574743Swnj { 35832523Sbostic register struct uba_ctlr *um = probeum; 35932523Sbostic register struct mscp *mp; 36032523Sbostic register struct uda_softc *sc; 36133443Skarels int next = 0, timeout, tries, i; 36217553Skarels 36332523Sbostic #ifdef lint 36432523Sbostic i = 0; i = i; 36532523Sbostic #endif 36632523Sbostic /* 36732523Sbostic * Make sure the controller is fully initialised, by waiting 36832523Sbostic * for it if necessary. 36932523Sbostic */ 37032523Sbostic sc = &uda_softc[um->um_ctlr]; 37132523Sbostic if (sc->sc_state == ST_RUN) 37232523Sbostic goto findunit; 37332523Sbostic tries = 0; 37432523Sbostic again: 37532523Sbostic if (udainit(ui->ui_ctlr)) 37632523Sbostic return (0); 37732523Sbostic timeout = todr() + 1000; /* 10 seconds */ 37832523Sbostic while (todr() < timeout) 37932523Sbostic if (sc->sc_state == ST_RUN) /* made it */ 38032523Sbostic goto findunit; 38132523Sbostic if (++tries < 2) 38232523Sbostic goto again; 38332523Sbostic printf("uda%d: controller hung\n", um->um_ctlr); 38432523Sbostic return (0); 38517553Skarels 38632523Sbostic /* 38732523Sbostic * The controller is all set; go find the unit. Grab an 38832523Sbostic * MSCP packet and send out a Get Unit Status command, with 38932523Sbostic * the `next unit' modifier if we are looking for a generic 39032523Sbostic * unit. We set the `in slave' flag so that udaunconf() 39132523Sbostic * knows to copy the response to `udaslavereply'. 39232523Sbostic */ 39332523Sbostic findunit: 39432523Sbostic udaslavereply.mscp_opcode = 0; 39532523Sbostic sc->sc_flags |= SC_INSLAVE; 39632523Sbostic if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) 39732523Sbostic panic("udaslave"); /* `cannot happen' */ 39832523Sbostic mp->mscp_opcode = M_OP_GETUNITST; 39932523Sbostic if (ui->ui_slave == '?') { 40032523Sbostic mp->mscp_unit = next; 40132523Sbostic mp->mscp_modifier = M_GUM_NEXTUNIT; 40232523Sbostic } else { 40332523Sbostic mp->mscp_unit = ui->ui_slave; 40432523Sbostic mp->mscp_modifier = 0; 40517553Skarels } 40632523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 40732523Sbostic i = ((struct udadevice *) reg)->udaip; /* initiate polling */ 40832523Sbostic mp = &udaslavereply; 40932523Sbostic timeout = todr() + 1000; 41032523Sbostic while (todr() < timeout) 41132523Sbostic if (mp->mscp_opcode) 41232523Sbostic goto gotit; 41332523Sbostic printf("uda%d: no response to Get Unit Status request\n", 41432523Sbostic um->um_ctlr); 41532523Sbostic sc->sc_flags &= ~SC_INSLAVE; 41632523Sbostic return (0); 41732523Sbostic 41832523Sbostic gotit: 41932523Sbostic sc->sc_flags &= ~SC_INSLAVE; 42032523Sbostic 42132523Sbostic /* 42232523Sbostic * Got a slave response. If the unit is there, use it. 42332523Sbostic */ 42432523Sbostic switch (mp->mscp_status & M_ST_MASK) { 42532523Sbostic 42632523Sbostic case M_ST_SUCCESS: /* worked */ 42732523Sbostic case M_ST_AVAILABLE: /* found another drive */ 42832523Sbostic break; /* use it */ 42932523Sbostic 43032523Sbostic case M_ST_OFFLINE: 43132523Sbostic /* 43232523Sbostic * Figure out why it is off line. It may be because 43332523Sbostic * it is nonexistent, or because it is spun down, or 43432523Sbostic * for some other reason. 43532523Sbostic */ 43632523Sbostic switch (mp->mscp_status & ~M_ST_MASK) { 43732523Sbostic 43832523Sbostic case M_OFFLINE_UNKNOWN: 43932523Sbostic /* 44032523Sbostic * No such drive, and there are none with 44132523Sbostic * higher unit numbers either, if we are 44232523Sbostic * using M_GUM_NEXTUNIT. 44332523Sbostic */ 44432523Sbostic return (0); 44532523Sbostic 44632523Sbostic case M_OFFLINE_UNMOUNTED: 44732523Sbostic /* 44832523Sbostic * The drive is not spun up. Use it anyway. 44932523Sbostic * 45032523Sbostic * N.B.: this seems to be a common occurrance 45132523Sbostic * after a power failure. The first attempt 45232523Sbostic * to bring it on line seems to spin it up 45332523Sbostic * (and thus takes several minutes). Perhaps 45432523Sbostic * we should note here that the on-line may 45532523Sbostic * take longer than usual. 45632523Sbostic */ 45732523Sbostic break; 45832523Sbostic 45932523Sbostic default: 46032523Sbostic /* 46132523Sbostic * In service, or something else equally unusable. 46232523Sbostic */ 46332523Sbostic printf("uda%d: unit %d off line: ", um->um_ctlr, 46432523Sbostic mp->mscp_unit); 46532523Sbostic mscp_printevent(mp); 46632523Sbostic goto try_another; 46732523Sbostic } 46832523Sbostic break; 46932523Sbostic 47032523Sbostic default: 47132523Sbostic printf("uda%d: unable to get unit status: ", um->um_ctlr); 47232523Sbostic mscp_printevent(mp); 47332523Sbostic return (0); 47417553Skarels } 47532523Sbostic 47632523Sbostic /* 47732523Sbostic * Does this ever happen? What (if anything) does it mean? 47832523Sbostic */ 47932523Sbostic if (mp->mscp_unit < next) { 48032523Sbostic printf("uda%d: unit %d, next %d\n", 48132523Sbostic um->um_ctlr, mp->mscp_unit, next); 48232523Sbostic return (0); 48317553Skarels } 48432523Sbostic 48532523Sbostic if (mp->mscp_unit >= MAXUNIT) { 48632523Sbostic printf("uda%d: cannot handle unit number %d (max is %d)\n", 48732523Sbostic um->um_ctlr, mp->mscp_unit, MAXUNIT - 1); 48832523Sbostic return (0); 48932523Sbostic } 49032523Sbostic 49132523Sbostic /* 49232523Sbostic * See if we already handle this drive. 49332523Sbostic * (Only likely if ui->ui_slave=='?'.) 49432523Sbostic */ 49532523Sbostic if (udaip[um->um_ctlr][mp->mscp_unit] != NULL) { 49632523Sbostic try_another: 49732523Sbostic if (ui->ui_slave != '?') 49832523Sbostic return (0); 49932523Sbostic next = mp->mscp_unit + 1; 50032523Sbostic goto findunit; 50132523Sbostic } 50232523Sbostic 50332523Sbostic /* 50432523Sbostic * Voila! 50532523Sbostic */ 50632523Sbostic uda_rasave(ui->ui_unit, mp, 0); 50732523Sbostic ui->ui_flags = 0; /* not on line, nor anything else */ 50832523Sbostic ui->ui_slave = mp->mscp_unit; 50932523Sbostic return (1); 5104743Swnj } 5114743Swnj 51232523Sbostic /* 51332523Sbostic * Attach a found slave. Make sure the watchdog timer is running. 51440045Smarc * If this disk is being profiled, fill in the `wpms' value (used by 51532523Sbostic * what?). Set up the inverting pointer, and attempt to bring the 51632523Sbostic * drive on line and read its label. 51732523Sbostic */ 51832523Sbostic udaattach(ui) 5194743Swnj register struct uba_device *ui; 5204743Swnj { 52132523Sbostic register int unit = ui->ui_unit; 52232523Sbostic 52332523Sbostic if (udawstart == 0) { 52432523Sbostic timeout(udawatch, (caddr_t) 0, hz); 52532523Sbostic udawstart++; 52632523Sbostic } 52733444Sbostic 52833444Sbostic /* 52933444Sbostic * Floppies cannot be brought on line unless there is 53033444Sbostic * a disk in the drive. Since an ONLINE while cold 53133444Sbostic * takes ten seconds to fail, and (when notyet becomes now) 53233444Sbostic * no sensible person will swap to one, we just 53333444Sbostic * defer the ONLINE until someone tries to use the drive. 53433444Sbostic * 53533444Sbostic * THIS ASSUMES THAT DRIVE TYPES ?X? ARE FLOPPIES 53633444Sbostic */ 53733444Sbostic if (MSCP_MID_ECH(1, ra_info[unit].ra_mediaid) == 'X' - '@') { 53834283Skarels printf(": floppy"); 53933444Sbostic return; 54033444Sbostic } 54134649Skarels if (ui->ui_dk >= 0) 54240045Smarc dk_wpms[ui->ui_dk] = (60 * 31 * 256); /* approx */ 54332523Sbostic udaip[ui->ui_ctlr][ui->ui_slave] = ui; 54433195Sbostic 54532523Sbostic if (uda_rainit(ui, 0)) 54634283Skarels printf(": offline"); 54736036Skarels else if (ra_info[unit].ra_state == OPEN) { 54834283Skarels printf(": %s, size = %d sectors", 54934283Skarels udalabel[unit].d_typename, ra_info[unit].ra_dsize); 55032523Sbostic #ifdef notyet 55132523Sbostic addswap(makedev(UDADEVNUM, udaminor(unit, 0)), &udalabel[unit]); 55226295Skarels #endif 55330536Skarels } 55432523Sbostic } 55532523Sbostic 55632523Sbostic /* 55732523Sbostic * Initialise a UDA50. Return true iff something goes wrong. 55832523Sbostic */ 55932523Sbostic udainit(ctlr) 56032523Sbostic int ctlr; 56132523Sbostic { 56232523Sbostic register struct uda_softc *sc; 56332523Sbostic register struct udadevice *udaddr; 56432523Sbostic struct uba_ctlr *um; 56532523Sbostic int timo, ubinfo; 56632523Sbostic 56732523Sbostic sc = &uda_softc[ctlr]; 56832523Sbostic um = udaminfo[ctlr]; 56932523Sbostic if ((sc->sc_flags & SC_MAPPED) == 0) { 57032523Sbostic /* 57132523Sbostic * Map the communication area and command and 57232523Sbostic * response packets into Unibus space. 57332523Sbostic */ 57432523Sbostic ubinfo = uballoc(um->um_ubanum, (caddr_t) &uda[ctlr], 57532523Sbostic sizeof (struct uda), UBA_CANTWAIT); 57632523Sbostic if (ubinfo == 0) { 57732523Sbostic printf("uda%d: uballoc map failed\n", ctlr); 57832523Sbostic return (-1); 57932523Sbostic } 58036036Skarels sc->sc_uda = (struct uda *) UBAI_ADDR(ubinfo); 58132523Sbostic sc->sc_flags |= SC_MAPPED; 58232523Sbostic } 58332523Sbostic 58430536Skarels /* 58532523Sbostic * While we are thinking about it, reset the next command 58632523Sbostic * and response indicies. 58730536Skarels */ 58832523Sbostic sc->sc_mi.mi_cmd.mri_next = 0; 58932523Sbostic sc->sc_mi.mi_rsp.mri_next = 0; 59032523Sbostic 59132523Sbostic /* 59232523Sbostic * Start up the hardware initialisation sequence. 59332523Sbostic */ 59432523Sbostic #define STEP0MASK (UDA_ERR | UDA_STEP4 | UDA_STEP3 | UDA_STEP2 | \ 59532523Sbostic UDA_STEP1 | UDA_NV) 59632523Sbostic 59732523Sbostic sc->sc_state = ST_IDLE; /* in case init fails */ 59833444Sbostic udaddr = (struct udadevice *)um->um_addr; 59932523Sbostic udaddr->udaip = 0; 60032523Sbostic timo = todr() + 1000; 60132523Sbostic while ((udaddr->udasa & STEP0MASK) == 0) { 60232523Sbostic if (todr() > timo) { 60332523Sbostic printf("uda%d: timeout during init\n", ctlr); 60432523Sbostic return (-1); 60532523Sbostic } 60632523Sbostic } 60732523Sbostic if ((udaddr->udasa & STEP0MASK) != UDA_STEP1) { 60832523Sbostic printf("uda%d: init failed, sa=%b\n", ctlr, 60932523Sbostic udaddr->udasa, udasr_bits); 61033444Sbostic udasaerror(um, 0); 61132523Sbostic return (-1); 61232523Sbostic } 61332523Sbostic 61432523Sbostic /* 61532523Sbostic * Success! Record new state, and start step 1 initialisation. 61632523Sbostic * The rest is done in the interrupt handler. 61732523Sbostic */ 61832523Sbostic sc->sc_state = ST_STEP1; 61932523Sbostic udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 62032523Sbostic (sc->sc_ivec >> 2); 62132523Sbostic return (0); 6224743Swnj } 6234743Swnj 6244743Swnj /* 62532523Sbostic * Open a drive. 6264743Swnj */ 62732523Sbostic /*ARGSUSED*/ 62832523Sbostic udaopen(dev, flag, fmt) 6294743Swnj dev_t dev; 63030773Skarels int flag, fmt; 6314743Swnj { 63232523Sbostic register int unit; 6334743Swnj register struct uba_device *ui; 6344743Swnj register struct uda_softc *sc; 63530536Skarels register struct disklabel *lp; 63630536Skarels register struct partition *pp; 63730916Skarels register struct ra_info *ra; 63832523Sbostic int s, i, part, mask, error = 0; 63930536Skarels daddr_t start, end; 64030536Skarels 64132523Sbostic /* 64232523Sbostic * Make sure this is a reasonable open request. 64332523Sbostic */ 64432523Sbostic unit = udaunit(dev); 64532523Sbostic if (unit >= NRA || (ui = udadinfo[unit]) == 0 || ui->ui_alive == 0) 6468576Sroot return (ENXIO); 64732523Sbostic 64832523Sbostic /* 64932523Sbostic * Make sure the controller is running, by (re)initialising it if 65032523Sbostic * necessary. 65132523Sbostic */ 6524743Swnj sc = &uda_softc[ui->ui_ctlr]; 6535434Sroot s = spl5(); 65432523Sbostic if (sc->sc_state != ST_RUN) { 65532523Sbostic if (sc->sc_state == ST_IDLE && udainit(ui->ui_ctlr)) { 65632523Sbostic splx(s); 6578576Sroot return (EIO); 65817553Skarels } 65932523Sbostic /* 66032523Sbostic * In case it does not come up, make sure we will be 66132523Sbostic * restarted in 10 seconds. This corresponds to the 66232523Sbostic * 10 second timeouts in udaprobe() and udaslave(). 66332523Sbostic */ 66432523Sbostic sc->sc_flags |= SC_DOWAKE; 66532523Sbostic timeout(wakeup, (caddr_t) sc, 10 * hz); 66632523Sbostic sleep((caddr_t) sc, PRIBIO); 66732523Sbostic if (sc->sc_state != ST_RUN) { 66832523Sbostic splx(s); 66932523Sbostic printf("uda%d: controller hung\n", ui->ui_ctlr); 67032523Sbostic return (EIO); 67132523Sbostic } 67232523Sbostic untimeout(wakeup, (caddr_t) sc); 6734743Swnj } 67432523Sbostic 67532523Sbostic /* 67632523Sbostic * Wait for the state to settle 67732523Sbostic */ 67832523Sbostic ra = &ra_info[unit]; 67932523Sbostic while (ra->ra_state != OPEN && ra->ra_state != OPENRAW && 68032523Sbostic ra->ra_state != CLOSED) 68140726Skarels if (error = tsleep((caddr_t)ra, (PZERO + 1) | PCATCH, 68240726Skarels devopn, 0)) { 68340726Skarels splx(s); 68440726Skarels return (error); 68540726Skarels } 68632523Sbostic 68732523Sbostic /* 68832523Sbostic * If not on line, or we are not sure of the label, reinitialise 68932523Sbostic * the drive. 69032523Sbostic */ 69132523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0 || 69232523Sbostic (ra->ra_state != OPEN && ra->ra_state != OPENRAW)) 69332523Sbostic error = uda_rainit(ui, flag); 69430916Skarels splx(s); 69532523Sbostic if (error) 69632523Sbostic return (error); 69730536Skarels 69832523Sbostic part = udapart(dev); 69932523Sbostic lp = &udalabel[unit]; 70030536Skarels if (part >= lp->d_npartitions) 70130536Skarels return (ENXIO); 70230536Skarels /* 70332523Sbostic * Warn if a partition is opened that overlaps another 70432523Sbostic * already open, unless either is the `raw' partition 70532523Sbostic * (whole disk). 70630536Skarels */ 70732523Sbostic #define RAWPART 2 /* 'c' partition */ /* XXX */ 70832523Sbostic mask = 1 << part; 70932523Sbostic if ((ra->ra_openpart & mask) == 0 && part != RAWPART) { 71030536Skarels pp = &lp->d_partitions[part]; 71130536Skarels start = pp->p_offset; 71230536Skarels end = pp->p_offset + pp->p_size; 71332523Sbostic for (pp = lp->d_partitions, i = 0; 71432523Sbostic i < lp->d_npartitions; pp++, i++) { 71530536Skarels if (pp->p_offset + pp->p_size <= start || 71632523Sbostic pp->p_offset >= end || i == RAWPART) 71730536Skarels continue; 71832523Sbostic if (ra->ra_openpart & (1 << i)) 71930536Skarels log(LOG_WARNING, 72030536Skarels "ra%d%c: overlaps open partition (%c)\n", 72132523Sbostic unit, part + 'a', i + 'a'); 72217553Skarels } 72317553Skarels } 72430773Skarels switch (fmt) { 72530773Skarels case S_IFCHR: 72632523Sbostic ra->ra_copenpart |= mask; 72730773Skarels break; 72830773Skarels case S_IFBLK: 72932523Sbostic ra->ra_bopenpart |= mask; 73030773Skarels break; 73130773Skarels } 73232523Sbostic ra->ra_openpart |= mask; 7338576Sroot return (0); 7344743Swnj } 7354743Swnj 73633444Sbostic /* ARGSUSED */ 73732523Sbostic udaclose(dev, flags, fmt) 73830536Skarels dev_t dev; 73930773Skarels int flags, fmt; 74030536Skarels { 74132523Sbostic register int unit = udaunit(dev); 74230773Skarels register struct ra_info *ra = &ra_info[unit]; 74332523Sbostic int s, mask = (1 << udapart(dev)); 74430536Skarels 74530773Skarels switch (fmt) { 74630773Skarels case S_IFCHR: 74732523Sbostic ra->ra_copenpart &= ~mask; 74830773Skarels break; 74930773Skarels case S_IFBLK: 75032523Sbostic ra->ra_bopenpart &= ~mask; 75130773Skarels break; 75230773Skarels } 75332523Sbostic ra->ra_openpart = ra->ra_copenpart | ra->ra_bopenpart; 75432523Sbostic 75530536Skarels /* 75632523Sbostic * Should wait for I/O to complete on this partition even if 75732523Sbostic * others are open, but wait for work on blkflush(). 75830536Skarels */ 75932523Sbostic if (ra->ra_openpart == 0) { 76030536Skarels s = spl5(); 76132523Sbostic while (udautab[unit].b_actf) 76232523Sbostic sleep((caddr_t)&udautab[unit], PZERO - 1); 76330536Skarels splx(s); 76432523Sbostic ra->ra_state = CLOSED; 76533443Skarels ra->ra_wlabel = 0; 76630536Skarels } 76730773Skarels return (0); 76830536Skarels } 76930536Skarels 7704743Swnj /* 77132523Sbostic * Initialise a drive. If it is not already, bring it on line, 77232523Sbostic * and set a timeout on it in case it fails to respond. 77332523Sbostic * When on line, read in the pack label. 7744743Swnj */ 77532523Sbostic uda_rainit(ui, flags) 77630536Skarels register struct uba_device *ui; 77732523Sbostic int flags; 77830536Skarels { 77932523Sbostic register struct uda_softc *sc = &uda_softc[ui->ui_ctlr]; 78034283Skarels register struct disklabel *lp; 78130536Skarels register struct mscp *mp; 78232523Sbostic register int unit = ui->ui_unit; 78332523Sbostic register struct ra_info *ra; 78430773Skarels char *msg, *readdisklabel(); 78532523Sbostic int s, i, udastrategy(); 78630536Skarels extern int cold; 78730536Skarels 78832523Sbostic ra = &ra_info[unit]; 78932523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0) { 79032523Sbostic mp = mscp_getcp(&sc->sc_mi, MSCP_WAIT); 79132523Sbostic mp->mscp_opcode = M_OP_ONLINE; 79232523Sbostic mp->mscp_unit = ui->ui_slave; 79332523Sbostic mp->mscp_cmdref = (long)&ui->ui_flags; 79432523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 79532523Sbostic ra->ra_state = WANTOPEN; 79632523Sbostic if (!cold) 79732523Sbostic s = spl5(); 79832523Sbostic i = ((struct udadevice *)ui->ui_addr)->udaip; 79930536Skarels 80030916Skarels if (cold) { 80132523Sbostic i = todr() + 1000; 80232523Sbostic while ((ui->ui_flags & UNIT_ONLINE) == 0) 80332523Sbostic if (todr() > i) 80432523Sbostic break; 80530916Skarels } else { 80632523Sbostic timeout(wakeup, (caddr_t)&ui->ui_flags, 10 * hz); 80732523Sbostic sleep((caddr_t)&ui->ui_flags, PSWP + 1); 80832523Sbostic splx(s); 80932523Sbostic untimeout(wakeup, (caddr_t)&ui->ui_flags); 81030916Skarels } 81132523Sbostic if (ra->ra_state != OPENRAW) { 81232523Sbostic ra->ra_state = CLOSED; 81332523Sbostic wakeup((caddr_t)ra); 81430916Skarels return (EIO); 81530916Skarels } 81630536Skarels } 81730536Skarels 81832523Sbostic lp = &udalabel[unit]; 81930916Skarels lp->d_secsize = DEV_BSIZE; 82032523Sbostic lp->d_secperunit = ra->ra_dsize; 82130916Skarels 82230536Skarels if (flags & O_NDELAY) 82330536Skarels return (0); 82432523Sbostic ra->ra_state = RDLABEL; 82530536Skarels /* 82632523Sbostic * Set up default sizes until we have the label, or longer 82732523Sbostic * if there is none. Set secpercyl, as readdisklabel wants 82838979Skarels * to compute b_cylin (although we do not need it), and set 82938979Skarels * nsectors in case diskerr is called. 83030536Skarels */ 83130916Skarels lp->d_secpercyl = 1; 83230536Skarels lp->d_npartitions = 1; 83336036Skarels lp->d_secsize = 512; 83436036Skarels lp->d_secperunit = ra->ra_dsize; 83538979Skarels lp->d_nsectors = ra->ra_geom.rg_nsectors; 83630536Skarels lp->d_partitions[0].p_size = lp->d_secperunit; 83730536Skarels lp->d_partitions[0].p_offset = 0; 83832523Sbostic 83930536Skarels /* 84030536Skarels * Read pack label. 84130536Skarels */ 84232523Sbostic if ((msg = readdisklabel(udaminor(unit, 0), udastrategy, lp)) != NULL) { 84334283Skarels if (cold) 84434283Skarels printf(": %s", msg); 84534283Skarels else 84636036Skarels log(LOG_ERR, "ra%d: %s", unit, msg); 84730536Skarels #ifdef COMPAT_42 84832523Sbostic if (udamaptype(unit, lp)) 84932523Sbostic ra->ra_state = OPEN; 85030536Skarels else 85132523Sbostic ra->ra_state = OPENRAW; 85231022Skarels #else 85332523Sbostic ra->ra_state = OPENRAW; 85436036Skarels uda_makefakelabel(ra, lp); 85530536Skarels #endif 85630773Skarels } else 85732523Sbostic ra->ra_state = OPEN; 85830916Skarels wakeup((caddr_t)ra); 85930916Skarels return (0); 86030536Skarels } 86130536Skarels 86232523Sbostic /* 86332523Sbostic * Copy the geometry information for the given ra from a 86432523Sbostic * GET UNIT STATUS response. If check, see if it changed. 86532523Sbostic */ 86632523Sbostic uda_rasave(unit, mp, check) 86732523Sbostic int unit; 86832523Sbostic register struct mscp *mp; 86932523Sbostic int check; 87032523Sbostic { 87132523Sbostic register struct ra_info *ra = &ra_info[unit]; 87232523Sbostic 87334283Skarels if (check && ra->ra_mediaid != mp->mscp_guse.guse_mediaid) { 87433443Skarels printf("ra%d: changed types! was %d now %d\n", unit, 87534283Skarels ra->ra_mediaid, mp->mscp_guse.guse_mediaid); 87632523Sbostic ra->ra_state = CLOSED; /* ??? */ 87732523Sbostic } 87833444Sbostic /* ra->ra_type = mp->mscp_guse.guse_drivetype; */ 87932523Sbostic ra->ra_mediaid = mp->mscp_guse.guse_mediaid; 88032523Sbostic ra->ra_geom.rg_nsectors = mp->mscp_guse.guse_nspt; 88132523Sbostic ra->ra_geom.rg_ngroups = mp->mscp_guse.guse_group; 88232523Sbostic ra->ra_geom.rg_ngpc = mp->mscp_guse.guse_ngpc; 88332523Sbostic ra->ra_geom.rg_ntracks = ra->ra_geom.rg_ngroups * ra->ra_geom.rg_ngpc; 88432523Sbostic /* ra_geom.rg_ncyl cannot be computed until we have ra_dsize */ 88532523Sbostic #ifdef notyet 88632523Sbostic ra->ra_geom.rg_rctsize = mp->mscp_guse.guse_rctsize; 88732523Sbostic ra->ra_geom.rg_rbns = mp->mscp_guse.guse_nrpt; 88832523Sbostic ra->ra_geom.rg_nrct = mp->mscp_guse.guse_nrct; 88932523Sbostic #endif 89032523Sbostic } 89132523Sbostic 89232523Sbostic /* 89332523Sbostic * Queue a transfer request, and if possible, hand it to the controller. 89432523Sbostic * 89532523Sbostic * This routine is broken into two so that the internal version 89632523Sbostic * udastrat1() can be called by the (nonexistent, as yet) bad block 89732523Sbostic * revectoring routine. 89832523Sbostic */ 89932523Sbostic udastrategy(bp) 9004743Swnj register struct buf *bp; 9014743Swnj { 90232523Sbostic register int unit; 9034743Swnj register struct uba_device *ui; 90432523Sbostic register struct ra_info *ra; 90532523Sbostic struct partition *pp; 90632523Sbostic int p; 9074743Swnj daddr_t sz, maxsz; 9084743Swnj 90932523Sbostic /* 91032523Sbostic * Make sure this is a reasonable drive to use. 91132523Sbostic */ 91232523Sbostic if ((unit = udaunit(bp->b_dev)) >= NRA || 91332523Sbostic (ui = udadinfo[unit]) == NULL || ui->ui_alive == 0 || 91432523Sbostic (ra = &ra_info[unit])->ra_state == CLOSED) { 91524742Sbloom bp->b_error = ENXIO; 9164743Swnj goto bad; 91724742Sbloom } 91832523Sbostic 91932523Sbostic /* 92032523Sbostic * If drive is open `raw' or reading label, let it at it. 92132523Sbostic */ 92232523Sbostic if (ra->ra_state < OPEN) { 92332523Sbostic udastrat1(bp); 92432523Sbostic return; 92524742Sbloom } 92632523Sbostic p = udapart(bp->b_dev); 92733443Skarels if ((ra->ra_openpart & (1 << p)) == 0) { 92833443Skarels bp->b_error = ENODEV; 92933443Skarels goto bad; 93033443Skarels } 93132523Sbostic 93232523Sbostic /* 93332523Sbostic * Determine the size of the transfer, and make sure it is 93432523Sbostic * within the boundaries of the partition. 93532523Sbostic */ 93632523Sbostic pp = &udalabel[unit].d_partitions[p]; 93732523Sbostic maxsz = pp->p_size; 93832523Sbostic if (pp->p_offset + pp->p_size > ra->ra_dsize) 93932523Sbostic maxsz = ra->ra_dsize - pp->p_offset; 94030536Skarels sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 94133443Skarels if (bp->b_blkno + pp->p_offset <= LABELSECTOR && 94233443Skarels #if LABELSECTOR != 0 94333443Skarels bp->b_blkno + pp->p_offset + sz > LABELSECTOR && 94433443Skarels #endif 94533443Skarels (bp->b_flags & B_READ) == 0 && ra->ra_wlabel == 0) { 94633443Skarels bp->b_error = EROFS; 94733443Skarels goto bad; 94833443Skarels } 94930536Skarels if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) { 95032523Sbostic /* if exactly at end of disk, return an EOF */ 95124787Skarels if (bp->b_blkno == maxsz) { 95224787Skarels bp->b_resid = bp->b_bcount; 95332523Sbostic biodone(bp); 95432523Sbostic return; 95524787Skarels } 95632523Sbostic /* or truncate if part of it fits */ 95730536Skarels sz = maxsz - bp->b_blkno; 95830536Skarels if (sz <= 0) { 95932523Sbostic bp->b_error = EINVAL; /* or hang it up */ 96030536Skarels goto bad; 96130536Skarels } 96230536Skarels bp->b_bcount = sz << DEV_BSHIFT; 96324742Sbloom } 96432523Sbostic udastrat1(bp); 96532523Sbostic return; 96632523Sbostic bad: 96732523Sbostic bp->b_flags |= B_ERROR; 96832523Sbostic biodone(bp); 96932523Sbostic } 97032523Sbostic 97132523Sbostic /* 97232523Sbostic * Work routine for udastrategy. 97332523Sbostic */ 97432523Sbostic udastrat1(bp) 97532523Sbostic register struct buf *bp; 97632523Sbostic { 97732523Sbostic register int unit = udaunit(bp->b_dev); 97832523Sbostic register struct uba_ctlr *um; 97932523Sbostic register struct buf *dp; 98032523Sbostic struct uba_device *ui; 98132523Sbostic int s = spl5(); 98232523Sbostic 9834743Swnj /* 98432523Sbostic * Append the buffer to the drive queue, and if it is not 98532523Sbostic * already there, the drive to the controller queue. (However, 98632523Sbostic * if the drive queue is marked to be requeued, we must be 98732523Sbostic * awaiting an on line or get unit status command; in this 98832523Sbostic * case, leave it off the controller queue.) 9894743Swnj */ 99032523Sbostic um = (ui = udadinfo[unit])->ui_mi; 99132523Sbostic dp = &udautab[unit]; 99232523Sbostic APPEND(bp, dp, av_forw); 99332523Sbostic if (dp->b_active == 0 && (ui->ui_flags & UNIT_REQUEUE) == 0) { 99432523Sbostic APPEND(dp, &um->um_tab, b_forw); 99532523Sbostic dp->b_active++; 99632523Sbostic } 99732523Sbostic 9984743Swnj /* 99932523Sbostic * Start activity on the controller. Note that unlike other 100032523Sbostic * Unibus drivers, we must always do this, not just when the 100132523Sbostic * controller is not active. 10024743Swnj */ 100332523Sbostic udastart(um); 10045434Sroot splx(s); 10054743Swnj } 10064743Swnj 100732523Sbostic /* 100832523Sbostic * Start up whatever transfers we can find. 100932523Sbostic * Note that udastart() must be called at spl5(). 101032523Sbostic */ 101132523Sbostic udastart(um) 10124743Swnj register struct uba_ctlr *um; 10134743Swnj { 101432523Sbostic register struct uda_softc *sc = &uda_softc[um->um_ctlr]; 10154743Swnj register struct buf *bp, *dp; 10164743Swnj register struct mscp *mp; 101732523Sbostic struct uba_device *ui; 10184743Swnj struct udadevice *udaddr; 101932523Sbostic struct partition *pp; 102032523Sbostic int i, sz; 10214743Swnj 102232523Sbostic #ifdef lint 102332523Sbostic i = 0; i = i; 102432523Sbostic #endif 102532523Sbostic /* 102632523Sbostic * If it is not running, try (again and again...) to initialise 102732523Sbostic * it. If it is currently initialising just ignore it for now. 102832523Sbostic */ 102932523Sbostic if (sc->sc_state != ST_RUN) { 103032523Sbostic if (sc->sc_state == ST_IDLE && udainit(um->um_ctlr)) 103132523Sbostic printf("uda%d: still hung\n", um->um_ctlr); 103232523Sbostic return; 103332523Sbostic } 103432523Sbostic 103532523Sbostic /* 103632523Sbostic * If um_cmd is nonzero, this controller is on the Unibus 103732523Sbostic * resource wait queue. It will not help to try more requests; 103832523Sbostic * instead, when the Unibus unblocks and calls udadgo(), we 103932523Sbostic * will call udastart() again. 104032523Sbostic */ 104132523Sbostic if (um->um_cmd) 104232523Sbostic return; 104332523Sbostic 104432523Sbostic sc->sc_flags |= SC_INSTART; 104532523Sbostic udaddr = (struct udadevice *) um->um_addr; 104632523Sbostic 10474743Swnj loop: 104832523Sbostic /* 104932523Sbostic * Service the drive at the head of the queue. It may not 105032523Sbostic * need anything, in which case it might be shutting down 105132523Sbostic * in udaclose(). 105232523Sbostic */ 105332523Sbostic if ((dp = um->um_tab.b_actf) == NULL) 105432523Sbostic goto out; 10554743Swnj if ((bp = dp->b_actf) == NULL) { 10564743Swnj dp->b_active = 0; 10574743Swnj um->um_tab.b_actf = dp->b_forw; 105832523Sbostic if (ra_info[dp - udautab].ra_openpart == 0) 105932523Sbostic wakeup((caddr_t)dp); /* finish close protocol */ 106032523Sbostic goto loop; 10614743Swnj } 106232523Sbostic 106332523Sbostic if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 106433444Sbostic udasaerror(um, 1); 106532523Sbostic goto out; 10664743Swnj } 106732523Sbostic 106832523Sbostic /* 106932523Sbostic * Get an MSCP packet, then figure out what to do. If 107032523Sbostic * we cannot get a command packet, the command ring may 107132523Sbostic * be too small: We should have at least as many command 107232523Sbostic * packets as credits, for best performance. 107332523Sbostic */ 107432523Sbostic if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) { 107532523Sbostic if (sc->sc_mi.mi_credits > MSCP_MINCREDITS && 107632523Sbostic (sc->sc_flags & SC_GRIPED) == 0) { 107732523Sbostic log(LOG_NOTICE, "uda%d: command ring too small\n", 107832523Sbostic um->um_ctlr); 107932523Sbostic sc->sc_flags |= SC_GRIPED;/* complain only once */ 108017553Skarels } 108132523Sbostic goto out; 10824743Swnj } 10834743Swnj 108432523Sbostic /* 108532523Sbostic * Bring the drive on line if it is not already. Get its status 108632523Sbostic * if we do not already have it. Otherwise just start the transfer. 108732523Sbostic */ 108832523Sbostic ui = udadinfo[udaunit(bp->b_dev)]; 108932523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0) { 109032523Sbostic mp->mscp_opcode = M_OP_ONLINE; 109132523Sbostic goto common; 10924743Swnj } 109332523Sbostic if ((ui->ui_flags & UNIT_HAVESTATUS) == 0) { 109432523Sbostic mp->mscp_opcode = M_OP_GETUNITST; 109532523Sbostic common: 109632523Sbostic if (ui->ui_flags & UNIT_REQUEUE) panic("udastart"); 109732523Sbostic /* 109832523Sbostic * Take the drive off the controller queue. When the 109932523Sbostic * command finishes, make sure the drive is requeued. 110032523Sbostic */ 110132523Sbostic um->um_tab.b_actf = dp->b_forw; 110232523Sbostic dp->b_active = 0; 110332523Sbostic ui->ui_flags |= UNIT_REQUEUE; 110432523Sbostic mp->mscp_unit = ui->ui_slave; 110532523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 110632523Sbostic sc->sc_flags |= SC_STARTPOLL; 110732523Sbostic #ifdef POLLSTATS 110832523Sbostic sc->sc_ncmd++; 110925653Skarels #endif 111032523Sbostic goto loop; 111117553Skarels } 111232523Sbostic 111332523Sbostic pp = &udalabel[ui->ui_unit].d_partitions[udapart(bp->b_dev)]; 111432523Sbostic mp->mscp_opcode = (bp->b_flags & B_READ) ? M_OP_READ : M_OP_WRITE; 11154743Swnj mp->mscp_unit = ui->ui_slave; 111632523Sbostic mp->mscp_seq.seq_lbn = bp->b_blkno + pp->p_offset; 111730536Skarels sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 111832523Sbostic mp->mscp_seq.seq_bytecount = bp->b_blkno + sz > pp->p_size ? 111932523Sbostic (pp->p_size - bp->b_blkno) >> DEV_BSHIFT : bp->b_bcount; 112032523Sbostic /* mscp_cmdref is filled in by mscp_go() */ 11214743Swnj 11224743Swnj /* 112332523Sbostic * Drop the packet pointer into the `command' field so udadgo() 112432523Sbostic * can tell what to start. If ubago returns 1, we can do another 112532523Sbostic * transfer. If not, um_cmd will still point at mp, so we will 112632523Sbostic * know that we are waiting for resources. 11274743Swnj */ 112832523Sbostic um->um_cmd = (int)mp; 112932523Sbostic if (ubago(ui)) 113032523Sbostic goto loop; 113132523Sbostic 113232523Sbostic /* 113332523Sbostic * All done, or blocked in ubago(). If we managed to 113432523Sbostic * issue some commands, start up the beast. 113532523Sbostic */ 113632523Sbostic out: 113732523Sbostic if (sc->sc_flags & SC_STARTPOLL) { 113832523Sbostic #ifdef POLLSTATS 113932523Sbostic udastats.cmd[sc->sc_ncmd]++; 114032523Sbostic sc->sc_ncmd = 0; 114132523Sbostic #endif 114233444Sbostic i = ((struct udadevice *)um->um_addr)->udaip; 11434743Swnj } 114432523Sbostic sc->sc_flags &= ~(SC_INSTART | SC_STARTPOLL); 114532523Sbostic } 114632523Sbostic 114732523Sbostic /* 114832523Sbostic * Start a transfer. 114932523Sbostic * 115032523Sbostic * If we are not called from within udastart(), we must have been 115132523Sbostic * blocked, so call udastart to do more requests (if any). If 115232523Sbostic * this calls us again immediately we will not recurse, because 115332523Sbostic * that time we will be in udastart(). Clever.... 115432523Sbostic */ 115532523Sbostic udadgo(um) 115632523Sbostic register struct uba_ctlr *um; 115732523Sbostic { 115832523Sbostic struct uda_softc *sc = &uda_softc[um->um_ctlr]; 115932523Sbostic struct mscp *mp = (struct mscp *)um->um_cmd; 116032523Sbostic 116132523Sbostic um->um_tab.b_active++; /* another transfer going */ 116232523Sbostic 11634743Swnj /* 116432523Sbostic * Fill in the MSCP packet and move the buffer to the 116532523Sbostic * I/O wait queue. Mark the controller as no longer on 116632523Sbostic * the resource queue, and remember to initiate polling. 11674743Swnj */ 116836036Skarels mp->mscp_seq.seq_buffer = UBAI_ADDR(um->um_ubinfo) | 116932523Sbostic (UBAI_BDP(um->um_ubinfo) << 24); 117032523Sbostic mscp_go(&sc->sc_mi, mp, um->um_ubinfo); 117132523Sbostic um->um_cmd = 0; 117232523Sbostic um->um_ubinfo = 0; /* tyke it awye */ 117332523Sbostic sc->sc_flags |= SC_STARTPOLL; 117432523Sbostic #ifdef POLLSTATS 117532523Sbostic sc->sc_ncmd++; 117632523Sbostic #endif 117732523Sbostic if ((sc->sc_flags & SC_INSTART) == 0) 117832523Sbostic udastart(um); 11794743Swnj } 11804743Swnj 118132523Sbostic udaiodone(mi, bp, info) 118232523Sbostic register struct mscp_info *mi; 118332523Sbostic struct buf *bp; 118432523Sbostic int info; 118532523Sbostic { 118632523Sbostic register struct uba_ctlr *um = udaminfo[mi->mi_ctlr]; 118732523Sbostic 118832523Sbostic um->um_ubinfo = info; 118932523Sbostic ubadone(um); 119032523Sbostic biodone(bp); 119132523Sbostic if (um->um_bdp && mi->mi_wtab.av_forw == &mi->mi_wtab) 119232523Sbostic ubarelse(um->um_ubanum, &um->um_bdp); 119332523Sbostic um->um_tab.b_active--; /* another transfer done */ 119432523Sbostic } 119532523Sbostic 119633444Sbostic static struct saerr { 119733444Sbostic int code; /* error code (including UDA_ERR) */ 119833444Sbostic char *desc; /* what it means: Efoo => foo error */ 119933444Sbostic } saerr[] = { 120033444Sbostic { 0100001, "Eunibus packet read" }, 120133444Sbostic { 0100002, "Eunibus packet write" }, 120233444Sbostic { 0100003, "EUDA ROM and RAM parity" }, 120333444Sbostic { 0100004, "EUDA RAM parity" }, 120433444Sbostic { 0100005, "EUDA ROM parity" }, 120533444Sbostic { 0100006, "Eunibus ring read" }, 120633444Sbostic { 0100007, "Eunibus ring write" }, 120733444Sbostic { 0100010, " unibus interrupt master failure" }, 120833444Sbostic { 0100011, "Ehost access timeout" }, 120933444Sbostic { 0100012, " host exceeded command limit" }, 121033444Sbostic { 0100013, " unibus bus master failure" }, 121133444Sbostic { 0100014, " DM XFC fatal error" }, 121233444Sbostic { 0100015, " hardware timeout of instruction loop" }, 121333444Sbostic { 0100016, " invalid virtual circuit id" }, 121433444Sbostic { 0100017, "Eunibus interrupt write" }, 121533444Sbostic { 0104000, "Efatal sequence" }, 121633444Sbostic { 0104040, " D proc ALU" }, 121733444Sbostic { 0104041, "ED proc control ROM parity" }, 121833444Sbostic { 0105102, "ED proc w/no BD#2 or RAM parity" }, 121933444Sbostic { 0105105, "ED proc RAM buffer" }, 122033444Sbostic { 0105152, "ED proc SDI" }, 122133444Sbostic { 0105153, "ED proc write mode wrap serdes" }, 122233444Sbostic { 0105154, "ED proc read mode serdes, RSGEN & ECC" }, 122333444Sbostic { 0106040, "EU proc ALU" }, 122433444Sbostic { 0106041, "EU proc control reg" }, 122533444Sbostic { 0106042, " U proc DFAIL/cntl ROM parity/BD #1 test CNT" }, 122633444Sbostic { 0106047, " U proc const PROM err w/D proc running SDI test" }, 122733444Sbostic { 0106055, " unexpected trap" }, 122833444Sbostic { 0106071, "EU proc const PROM" }, 122933444Sbostic { 0106072, "EU proc control ROM parity" }, 123033444Sbostic { 0106200, "Estep 1 data" }, 123133444Sbostic { 0107103, "EU proc RAM parity" }, 123233444Sbostic { 0107107, "EU proc RAM buffer" }, 123333444Sbostic { 0107115, " test count wrong (BD 12)" }, 123433444Sbostic { 0112300, "Estep 2" }, 123533444Sbostic { 0122240, "ENPR" }, 123633444Sbostic { 0122300, "Estep 3" }, 123733444Sbostic { 0142300, "Estep 4" }, 123833444Sbostic { 0, " unknown error code" } 123933444Sbostic }; 124033444Sbostic 12414743Swnj /* 124233444Sbostic * If the error bit was set in the controller status register, gripe, 124333444Sbostic * then (optionally) reset the controller and requeue pending transfers. 12444743Swnj */ 124533444Sbostic udasaerror(um, doreset) 124632523Sbostic register struct uba_ctlr *um; 124733444Sbostic int doreset; 12484743Swnj { 124933444Sbostic register int code = ((struct udadevice *)um->um_addr)->udasa; 125033444Sbostic register struct saerr *e; 125132523Sbostic 125233444Sbostic if ((code & UDA_ERR) == 0) 125333444Sbostic return; 125433444Sbostic for (e = saerr; e->code; e++) 125533444Sbostic if (e->code == code) 125633444Sbostic break; 125733444Sbostic printf("uda%d: controller error, sa=0%o (%s%s)\n", 125833444Sbostic um->um_ctlr, code, e->desc + 1, 125933444Sbostic *e->desc == 'E' ? " error" : ""); 126033444Sbostic if (doreset) { 126133444Sbostic mscp_requeue(&uda_softc[um->um_ctlr].sc_mi); 126233444Sbostic (void) udainit(um->um_ctlr); 126333444Sbostic } 126432523Sbostic } 126532523Sbostic 126632523Sbostic /* 126732523Sbostic * Interrupt routine. Depending on the state of the controller, 126832523Sbostic * continue initialisation, or acknowledge command and response 126932523Sbostic * interrupts, and process responses. 127032523Sbostic */ 127132523Sbostic udaintr(ctlr) 127232523Sbostic int ctlr; 127332523Sbostic { 127432523Sbostic register struct uba_ctlr *um = udaminfo[ctlr]; 127532523Sbostic register struct uda_softc *sc = &uda_softc[ctlr]; 127633444Sbostic register struct udadevice *udaddr = (struct udadevice *)um->um_addr; 127732523Sbostic register struct uda *ud; 127832523Sbostic register struct mscp *mp; 12794743Swnj register int i; 12804743Swnj 128135401Stef #ifdef QBA 128236036Skarels splx(sc->sc_ipl); /* Qbus interrupt protocol is odd */ 128327254Skridle #endif 128432523Sbostic sc->sc_wticks = 0; /* reset interrupt watchdog */ 128532523Sbostic 128632523Sbostic /* 128732523Sbostic * Combinations during steps 1, 2, and 3: STEPnMASK 128832523Sbostic * corresponds to which bits should be tested; 128932523Sbostic * STEPnGOOD corresponds to the pattern that should 129032523Sbostic * appear after the interrupt from STEPn initialisation. 129132523Sbostic * All steps test the bits in ALLSTEPS. 129232523Sbostic */ 129332523Sbostic #define ALLSTEPS (UDA_ERR|UDA_STEP4|UDA_STEP3|UDA_STEP2|UDA_STEP1) 129432523Sbostic 129532523Sbostic #define STEP1MASK (ALLSTEPS | UDA_IE | UDA_NCNRMASK) 129632523Sbostic #define STEP1GOOD (UDA_STEP2 | UDA_IE | (NCMDL2 << 3) | NRSPL2) 129732523Sbostic 129832523Sbostic #define STEP2MASK (ALLSTEPS | UDA_IE | UDA_IVECMASK) 129932523Sbostic #define STEP2GOOD (UDA_STEP3 | UDA_IE | (sc->sc_ivec >> 2)) 130032523Sbostic 130132523Sbostic #define STEP3MASK ALLSTEPS 130232523Sbostic #define STEP3GOOD UDA_STEP4 130332523Sbostic 13044743Swnj switch (sc->sc_state) { 130532523Sbostic 130632523Sbostic case ST_IDLE: 130732523Sbostic /* 130832523Sbostic * Ignore unsolicited interrupts. 130932523Sbostic */ 131032523Sbostic log(LOG_WARNING, "uda%d: stray intr\n", ctlr); 13114743Swnj return; 13124743Swnj 131332523Sbostic case ST_STEP1: 131432523Sbostic /* 131532523Sbostic * Begin step two initialisation. 131632523Sbostic */ 131732523Sbostic if ((udaddr->udasa & STEP1MASK) != STEP1GOOD) { 131832523Sbostic i = 1; 131932523Sbostic initfailed: 132032523Sbostic printf("uda%d: init step %d failed, sa=%b\n", 132132523Sbostic ctlr, i, udaddr->udasa, udasr_bits); 132233444Sbostic udasaerror(um, 0); 132332523Sbostic sc->sc_state = ST_IDLE; 132432523Sbostic if (sc->sc_flags & SC_DOWAKE) { 132532523Sbostic sc->sc_flags &= ~SC_DOWAKE; 132633444Sbostic wakeup((caddr_t)sc); 132732523Sbostic } 13284743Swnj return; 13294743Swnj } 133033444Sbostic udaddr->udasa = (int)&sc->sc_uda->uda_ca.ca_rspdsc[0] | 133132523Sbostic (cpu == VAX_780 || cpu == VAX_8600 ? UDA_PI : 0); 133232523Sbostic sc->sc_state = ST_STEP2; 13334743Swnj return; 13344743Swnj 133532523Sbostic case ST_STEP2: 133632523Sbostic /* 133732523Sbostic * Begin step 3 initialisation. 133832523Sbostic */ 133932523Sbostic if ((udaddr->udasa & STEP2MASK) != STEP2GOOD) { 134032523Sbostic i = 2; 134132523Sbostic goto initfailed; 13424743Swnj } 134333444Sbostic udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_rspdsc[0]) >> 16; 134432523Sbostic sc->sc_state = ST_STEP3; 13454743Swnj return; 13464743Swnj 134732523Sbostic case ST_STEP3: 134832523Sbostic /* 134932523Sbostic * Set controller characteristics (finish initialisation). 135032523Sbostic */ 135132523Sbostic if ((udaddr->udasa & STEP3MASK) != STEP3GOOD) { 135232523Sbostic i = 3; 135332523Sbostic goto initfailed; 13544743Swnj } 135532523Sbostic i = udaddr->udasa & 0xff; 135632523Sbostic if (i != sc->sc_micro) { 135732523Sbostic sc->sc_micro = i; 135832523Sbostic printf("uda%d: version %d model %d\n", 135932523Sbostic ctlr, i & 0xf, i >> 4); 136032523Sbostic } 136132523Sbostic 136217553Skarels /* 136332523Sbostic * Present the burst size, then remove it. Why this 136432523Sbostic * should be done this way, I have no idea. 136532523Sbostic * 136632523Sbostic * Note that this assumes udaburst[ctlr] > 0. 136717553Skarels */ 136832523Sbostic udaddr->udasa = UDA_GO | (udaburst[ctlr] - 1) << 2; 13694743Swnj udaddr->udasa = UDA_GO; 137032523Sbostic printf("uda%d: DMA burst size set to %d\n", 137132523Sbostic ctlr, udaburst[ctlr]); 13724743Swnj 137332523Sbostic udainitds(ctlr); /* initialise data structures */ 137432523Sbostic 13754743Swnj /* 137632523Sbostic * Before we can get a command packet, we need some 137732523Sbostic * credits. Fake some up to keep mscp_getcp() happy, 137832523Sbostic * get a packet, and cancel all credits (the right 137932523Sbostic * number should come back in the response to the 138032523Sbostic * SCC packet). 13814743Swnj */ 138232523Sbostic sc->sc_mi.mi_credits = MSCP_MINCREDITS + 1; 138332523Sbostic mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT); 138432523Sbostic if (mp == NULL) /* `cannot happen' */ 138532523Sbostic panic("udaintr"); 138632523Sbostic sc->sc_mi.mi_credits = 0; 138732523Sbostic mp->mscp_opcode = M_OP_SETCTLRC; 138832523Sbostic mp->mscp_unit = 0; 138932523Sbostic mp->mscp_sccc.sccc_ctlrflags = M_CF_ATTN | M_CF_MISC | 139032523Sbostic M_CF_THIS; 139132523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 139232523Sbostic i = udaddr->udaip; 139332523Sbostic sc->sc_state = ST_SETCHAR; 13944743Swnj return; 13954743Swnj 139632523Sbostic case ST_SETCHAR: 139732523Sbostic case ST_RUN: 139832523Sbostic /* 139932523Sbostic * Handle Set Ctlr Characteristics responses and operational 140032523Sbostic * responses (via mscp_dorsp). 140132523Sbostic */ 14024743Swnj break; 14034743Swnj 14044743Swnj default: 140532523Sbostic printf("uda%d: driver bug, state %d\n", ctlr, sc->sc_state); 140632523Sbostic panic("udastate"); 14074743Swnj } 14084743Swnj 140932523Sbostic if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 141033444Sbostic udasaerror(um, 1); 141132523Sbostic return; 14124743Swnj } 14134743Swnj 141432523Sbostic ud = &uda[ctlr]; 141532523Sbostic 14164743Swnj /* 141732523Sbostic * Handle buffer purge requests. 14184743Swnj */ 14194743Swnj if (ud->uda_ca.ca_bdp) { 142026372Skarels UBAPURGE(um->um_hd->uh_uba, ud->uda_ca.ca_bdp); 14214743Swnj ud->uda_ca.ca_bdp = 0; 142232523Sbostic udaddr->udasa = 0; /* signal purge complete */ 14234743Swnj } 14244743Swnj 14254743Swnj /* 142632523Sbostic * Check for response and command ring transitions. 14274743Swnj */ 14284743Swnj if (ud->uda_ca.ca_rspint) { 14294743Swnj ud->uda_ca.ca_rspint = 0; 143032523Sbostic mscp_dorsp(&sc->sc_mi); 14314743Swnj } 14324743Swnj if (ud->uda_ca.ca_cmdint) { 14334743Swnj ud->uda_ca.ca_cmdint = 0; 143432523Sbostic MSCP_DOCMD(&sc->sc_mi); 14354743Swnj } 143632523Sbostic udastart(um); 14374743Swnj } 14384743Swnj 14394743Swnj /* 144032523Sbostic * Initialise the various data structures that control the UDA50. 144117553Skarels */ 144232523Sbostic udainitds(ctlr) 144332523Sbostic int ctlr; 144432523Sbostic { 144532523Sbostic register struct uda *ud = &uda[ctlr]; 144632523Sbostic register struct uda *uud = uda_softc[ctlr].sc_uda; 144732523Sbostic register struct mscp *mp; 144832523Sbostic register int i; 14494743Swnj 145032523Sbostic for (i = 0, mp = ud->uda_rsp; i < NRSP; i++, mp++) { 145132523Sbostic ud->uda_ca.ca_rspdsc[i] = MSCP_OWN | MSCP_INT | 145232523Sbostic (long)&uud->uda_rsp[i].mscp_cmdref; 145332523Sbostic mp->mscp_addr = &ud->uda_ca.ca_rspdsc[i]; 145432523Sbostic mp->mscp_msglen = MSCP_MSGLEN; 14554743Swnj } 145632523Sbostic for (i = 0, mp = ud->uda_cmd; i < NCMD; i++, mp++) { 145732523Sbostic ud->uda_ca.ca_cmddsc[i] = MSCP_INT | 145832523Sbostic (long)&uud->uda_cmd[i].mscp_cmdref; 145932523Sbostic mp->mscp_addr = &ud->uda_ca.ca_cmddsc[i]; 146032523Sbostic mp->mscp_msglen = MSCP_MSGLEN; 146132523Sbostic } 14624743Swnj } 14634743Swnj 14644743Swnj /* 146533444Sbostic * Handle an error datagram. 14664743Swnj */ 146732523Sbostic udadgram(mi, mp) 146832523Sbostic struct mscp_info *mi; 146932523Sbostic struct mscp *mp; 14704743Swnj { 147117553Skarels 147232523Sbostic mscp_decodeerror(mi->mi_md->md_mname, mi->mi_ctlr, mp); 147333444Sbostic /* 147433444Sbostic * SDI status information bytes 10 and 11 are the microprocessor 147533444Sbostic * error code and front panel code respectively. These vary per 147633444Sbostic * drive type and are printed purely for field service information. 147733444Sbostic */ 147833444Sbostic if (mp->mscp_format == M_FM_SDI) 147933444Sbostic printf("\tsdi uproc error code 0x%x, front panel code 0x%x\n", 148033444Sbostic mp->mscp_erd.erd_sdistat[10], 148133444Sbostic mp->mscp_erd.erd_sdistat[11]); 148232523Sbostic } 148317553Skarels 148432523Sbostic /* 148532523Sbostic * The Set Controller Characteristics command finished. 148632523Sbostic * Record the new state of the controller. 148732523Sbostic */ 148832523Sbostic udactlrdone(mi, mp) 148932523Sbostic register struct mscp_info *mi; 149032523Sbostic struct mscp *mp; 149132523Sbostic { 149232523Sbostic register struct uda_softc *sc = &uda_softc[mi->mi_ctlr]; 149317553Skarels 149432523Sbostic if ((mp->mscp_status & M_ST_MASK) == M_ST_SUCCESS) 149532523Sbostic sc->sc_state = ST_RUN; 149632523Sbostic else { 149732523Sbostic printf("uda%d: SETCTLRC failed: ", 149832523Sbostic mi->mi_ctlr, mp->mscp_status); 149932523Sbostic mscp_printevent(mp); 150032523Sbostic sc->sc_state = ST_IDLE; 15014743Swnj } 150232523Sbostic if (sc->sc_flags & SC_DOWAKE) { 150332523Sbostic sc->sc_flags &= ~SC_DOWAKE; 150432523Sbostic wakeup((caddr_t)sc); 15056964Ssam } 15064743Swnj } 15074743Swnj 15084743Swnj /* 150932523Sbostic * Received a response from an as-yet unconfigured drive. Configure it 151032523Sbostic * in, if possible. 15114743Swnj */ 151232523Sbostic udaunconf(mi, mp) 151332523Sbostic struct mscp_info *mi; 151432523Sbostic register struct mscp *mp; 15154743Swnj { 15164743Swnj 151717553Skarels /* 151832523Sbostic * If it is a slave response, copy it to udaslavereply for 151932523Sbostic * udaslave() to look at. 152017553Skarels */ 152132523Sbostic if (mp->mscp_opcode == (M_OP_GETUNITST | M_OP_END) && 152232523Sbostic (uda_softc[mi->mi_ctlr].sc_flags & SC_INSLAVE) != 0) { 152332523Sbostic udaslavereply = *mp; 152432523Sbostic return (MSCP_DONE); 15254743Swnj } 152632523Sbostic 152732523Sbostic /* 152832523Sbostic * Otherwise, it had better be an available attention response. 152932523Sbostic */ 153032523Sbostic if (mp->mscp_opcode != M_OP_AVAILATTN) 153132523Sbostic return (MSCP_FAILED); 153232523Sbostic 153332523Sbostic /* do what autoconf does */ 153432523Sbostic return (MSCP_FAILED); /* not yet, arwhite, not yet */ 15354743Swnj } 15364743Swnj 153732523Sbostic /* 153832523Sbostic * A drive came on line. Check its type and size. Return DONE if 153932523Sbostic * we think the drive is truly on line. In any case, awaken anyone 154032523Sbostic * sleeping on the drive on-line-ness. 154132523Sbostic */ 154232523Sbostic udaonline(ui, mp) 154332523Sbostic register struct uba_device *ui; 154432523Sbostic struct mscp *mp; 15454743Swnj { 154632523Sbostic register struct ra_info *ra = &ra_info[ui->ui_unit]; 15474743Swnj 154832523Sbostic wakeup((caddr_t)&ui->ui_flags); 154932523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 155036036Skarels if (!cold) 155136036Skarels printf("uda%d: ra%d", ui->ui_ctlr, ui->ui_unit); 155236036Skarels printf(": attempt to bring on line failed: "); 155332523Sbostic mscp_printevent(mp); 155432523Sbostic ra->ra_state = CLOSED; 155532523Sbostic return (MSCP_FAILED); 155632523Sbostic } 155732523Sbostic 155832523Sbostic ra->ra_state = OPENRAW; 155932523Sbostic ra->ra_dsize = (daddr_t)mp->mscp_onle.onle_unitsize; 156034283Skarels if (!cold) 156134283Skarels printf("ra%d: uda%d, unit %d, size = %d sectors\n", ui->ui_unit, 156234283Skarels ui->ui_ctlr, mp->mscp_unit, ra->ra_dsize); 156332523Sbostic /* can now compute ncyl */ 156432523Sbostic ra->ra_geom.rg_ncyl = ra->ra_dsize / ra->ra_geom.rg_ntracks / 156532523Sbostic ra->ra_geom.rg_nsectors; 156632523Sbostic return (MSCP_DONE); 15674743Swnj } 15684743Swnj 156932523Sbostic /* 157032523Sbostic * We got some (configured) unit's status. Return DONE if it succeeded. 157132523Sbostic */ 157232523Sbostic udagotstatus(ui, mp) 157332523Sbostic register struct uba_device *ui; 157432523Sbostic register struct mscp *mp; 15754743Swnj { 15764743Swnj 157732523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 157832523Sbostic printf("uda%d: attempt to get status for ra%d failed: ", 157932523Sbostic ui->ui_ctlr, ui->ui_unit); 158032523Sbostic mscp_printevent(mp); 158132523Sbostic return (MSCP_FAILED); 158232523Sbostic } 158332523Sbostic /* record for (future) bad block forwarding and whatever else */ 158432523Sbostic uda_rasave(ui->ui_unit, mp, 1); 158532523Sbostic return (MSCP_DONE); 15864743Swnj } 15874743Swnj 158832523Sbostic /* 158932523Sbostic * A transfer failed. We get a chance to fix or restart it. 159032523Sbostic * Need to write the bad block forwaring code first.... 159132523Sbostic */ 159232523Sbostic /*ARGSUSED*/ 159332523Sbostic udaioerror(ui, mp, bp) 159432523Sbostic register struct uba_device *ui; 159532523Sbostic register struct mscp *mp; 159632523Sbostic struct buf *bp; 15974743Swnj { 15984743Swnj 159932523Sbostic if (mp->mscp_flags & M_EF_BBLKR) { 160032523Sbostic /* 160132523Sbostic * A bad block report. Eventually we will 160232523Sbostic * restart this transfer, but for now, just 160332523Sbostic * log it and give up. 160432523Sbostic */ 160532523Sbostic log(LOG_ERR, "ra%d: bad block report: %d%s\n", 160632523Sbostic ui->ui_unit, mp->mscp_seq.seq_lbn, 160732523Sbostic mp->mscp_flags & M_EF_BBLKU ? " + others" : ""); 160832523Sbostic } else { 160932523Sbostic /* 161032523Sbostic * What the heck IS a `serious exception' anyway? 161132523Sbostic * IT SURE WOULD BE NICE IF DEC SOLD DOCUMENTATION 161232523Sbostic * FOR THEIR OWN CONTROLLERS. 161332523Sbostic */ 161432523Sbostic if (mp->mscp_flags & M_EF_SEREX) 161532523Sbostic log(LOG_ERR, "ra%d: serious exception reported\n", 161632523Sbostic ui->ui_unit); 16174743Swnj } 161832523Sbostic return (MSCP_FAILED); 16194743Swnj } 16204743Swnj 162132523Sbostic /* 162232523Sbostic * A replace operation finished. 162332523Sbostic */ 162432523Sbostic /*ARGSUSED*/ 162532523Sbostic udareplace(ui, mp) 162632523Sbostic struct uba_device *ui; 162732523Sbostic struct mscp *mp; 16284743Swnj { 162917553Skarels 163032523Sbostic panic("udareplace"); 16314743Swnj } 163217553Skarels 163332523Sbostic /* 163432523Sbostic * A bad block related operation finished. 163532523Sbostic */ 163632523Sbostic /*ARGSUSED*/ 163732523Sbostic udabb(ui, mp, bp) 163832523Sbostic struct uba_device *ui; 163932523Sbostic struct mscp *mp; 164032523Sbostic struct buf *bp; 164117553Skarels { 164217553Skarels 164332523Sbostic panic("udabb"); 164417553Skarels } 164517553Skarels 164632523Sbostic 164732523Sbostic /* 164832523Sbostic * I/O controls. 164932523Sbostic */ 165032523Sbostic udaioctl(dev, cmd, data, flag) 165112511Ssam dev_t dev; 165230536Skarels int cmd; 165330536Skarels caddr_t data; 165430536Skarels int flag; 165512511Ssam { 165632523Sbostic register int unit = udaunit(dev); 165730536Skarels register struct disklabel *lp; 165833443Skarels register struct ra_info *ra = &ra_info[unit]; 165934638Skarels int error = 0; 166012511Ssam 166132523Sbostic lp = &udalabel[unit]; 166230536Skarels 166330536Skarels switch (cmd) { 166430536Skarels 166530536Skarels case DIOCGDINFO: 166630536Skarels *(struct disklabel *)data = *lp; 166730536Skarels break; 166830536Skarels 166930773Skarels case DIOCGPART: 167030773Skarels ((struct partinfo *)data)->disklab = lp; 167130773Skarels ((struct partinfo *)data)->part = 167232523Sbostic &lp->d_partitions[udapart(dev)]; 167330536Skarels break; 167430536Skarels 167530536Skarels case DIOCSDINFO: 167630536Skarels if ((flag & FWRITE) == 0) 167730536Skarels error = EBADF; 167830536Skarels else 167932574Skarels error = setdisklabel(lp, (struct disklabel *)data, 168034283Skarels (ra->ra_state == OPENRAW) ? 0 : ra->ra_openpart); 168130536Skarels break; 168230536Skarels 168333443Skarels case DIOCWLABEL: 168433443Skarels if ((flag & FWRITE) == 0) 168533443Skarels error = EBADF; 168633443Skarels else 168733443Skarels ra->ra_wlabel = *(int *)data; 168833443Skarels break; 168933443Skarels 169032574Skarels case DIOCWDINFO: 169132574Skarels if ((flag & FWRITE) == 0) 169232523Sbostic error = EBADF; 169332574Skarels else if ((error = setdisklabel(lp, (struct disklabel *)data, 169434283Skarels (ra->ra_state == OPENRAW) ? 0 : ra->ra_openpart)) == 0) { 169534638Skarels int wlab; 169634638Skarels 169734283Skarels ra->ra_state = OPEN; 169834638Skarels /* simulate opening partition 0 so write succeeds */ 169934638Skarels ra->ra_openpart |= (1 << 0); /* XXX */ 170034638Skarels wlab = ra->ra_wlabel; 170134638Skarels ra->ra_wlabel = 1; 170232574Skarels error = writedisklabel(dev, udastrategy, lp); 170334638Skarels ra->ra_openpart = ra->ra_copenpart | ra->ra_bopenpart; 170434638Skarels ra->ra_wlabel = wlab; 170534283Skarels } 170630536Skarels break; 170730536Skarels 170832523Sbostic #ifdef notyet 170932523Sbostic case UDAIOCREPLACE: 171032523Sbostic /* 171132523Sbostic * Initiate bad block replacement for the given LBN. 171232523Sbostic * (Should we allow modifiers?) 171332523Sbostic */ 171432523Sbostic error = EOPNOTSUPP; 171532523Sbostic break; 171632523Sbostic 171732523Sbostic case UDAIOCGMICRO: 171832523Sbostic /* 171932523Sbostic * Return the microcode revision for the UDA50 running 172032523Sbostic * this drive. 172132523Sbostic */ 172233444Sbostic *(int *)data = uda_softc[uddinfo[unit]->ui_ctlr].sc_micro; 172332523Sbostic break; 172432523Sbostic #endif 172532523Sbostic 172630536Skarels default: 172730536Skarels error = ENOTTY; 172830536Skarels break; 172930536Skarels } 173032523Sbostic return (error); 173132523Sbostic } 173232523Sbostic 173332523Sbostic /* 173432523Sbostic * A Unibus reset has occurred on UBA uban. Reinitialise the controller(s) 173532523Sbostic * on that Unibus, and requeue outstanding I/O. 173632523Sbostic */ 173732523Sbostic udareset(uban) 173832523Sbostic int uban; 173932523Sbostic { 174032523Sbostic register struct uba_ctlr *um; 174132523Sbostic register struct uda_softc *sc; 174232523Sbostic register int ctlr; 174332523Sbostic 174432523Sbostic for (ctlr = 0, sc = uda_softc; ctlr < NUDA; ctlr++, sc++) { 174532523Sbostic if ((um = udaminfo[ctlr]) == NULL || um->um_ubanum != uban || 174632523Sbostic um->um_alive == 0) 174732523Sbostic continue; 174832523Sbostic printf(" uda%d", ctlr); 174932523Sbostic 175032523Sbostic /* 175132523Sbostic * Our BDP (if any) is gone; our command (if any) is 175232523Sbostic * flushed; the device is no longer mapped; and the 175332523Sbostic * UDA50 is not yet initialised. 175432523Sbostic */ 175532523Sbostic if (um->um_bdp) { 175632523Sbostic printf("<%d>", UBAI_BDP(um->um_bdp)); 175732523Sbostic um->um_bdp = 0; 175832523Sbostic } 175932523Sbostic um->um_ubinfo = 0; 176032523Sbostic um->um_cmd = 0; 176132523Sbostic sc->sc_flags &= ~SC_MAPPED; 176232523Sbostic sc->sc_state = ST_IDLE; 176332523Sbostic 176432523Sbostic /* reset queues and requeue pending transfers */ 176532523Sbostic mscp_requeue(&sc->sc_mi); 176632523Sbostic 176732523Sbostic /* 176832523Sbostic * If it fails to initialise we will notice later and 176932523Sbostic * try again (and again...). Do not call udastart() 177032523Sbostic * here; it will be done after the controller finishes 177132523Sbostic * initialisation. 177232523Sbostic */ 177332523Sbostic if (udainit(ctlr)) 177432523Sbostic printf(" (hung)"); 177532523Sbostic } 177632523Sbostic } 177732523Sbostic 177832523Sbostic /* 177932523Sbostic * Watchdog timer: If the controller is active, and no interrupts 178032523Sbostic * have occurred for 30 seconds, assume it has gone away. 178132523Sbostic */ 178232523Sbostic udawatch() 178332523Sbostic { 178432523Sbostic register int i; 178532523Sbostic register struct uba_ctlr *um; 178632523Sbostic register struct uda_softc *sc; 178732523Sbostic 178832523Sbostic timeout(udawatch, (caddr_t) 0, hz); /* every second */ 178932523Sbostic for (i = 0, sc = uda_softc; i < NUDA; i++, sc++) { 179032523Sbostic if ((um = udaminfo[i]) == 0 || !um->um_alive) 179132523Sbostic continue; 179232523Sbostic if (sc->sc_state == ST_IDLE) 179332523Sbostic continue; 179432523Sbostic if (sc->sc_state == ST_RUN && !um->um_tab.b_active) 179532523Sbostic sc->sc_wticks = 0; 179632523Sbostic else if (++sc->sc_wticks >= 30) { 179732523Sbostic sc->sc_wticks = 0; 179832523Sbostic printf("uda%d: lost interrupt\n", i); 179932523Sbostic ubareset(um->um_ubanum); 180032523Sbostic } 180132523Sbostic } 180232523Sbostic } 180332523Sbostic 180432523Sbostic /* 180532523Sbostic * Do a panic dump. We set up the controller for one command packet 180632523Sbostic * and one response packet, for which we use `struct uda1'. 180732523Sbostic */ 180832523Sbostic struct uda1 { 180932523Sbostic struct uda1ca uda1_ca; /* communications area */ 181032523Sbostic struct mscp uda1_rsp; /* response packet */ 181132523Sbostic struct mscp uda1_cmd; /* command packet */ 181232523Sbostic } uda1; 181332523Sbostic 181432523Sbostic #define DBSIZE 32 /* dump 16K at a time */ 181532523Sbostic 181632523Sbostic udadump(dev) 181732523Sbostic dev_t dev; 181832523Sbostic { 181932523Sbostic struct udadevice *udaddr; 182032523Sbostic struct uda1 *ud_ubaddr; 182132523Sbostic char *start; 182232523Sbostic int num, blk, unit, maxsz, blkoff, reg; 182332523Sbostic struct partition *pp; 182432523Sbostic register struct uba_regs *uba; 182532523Sbostic register struct uba_device *ui; 182632523Sbostic register struct uda1 *ud; 182732523Sbostic register struct pte *io; 182832523Sbostic register int i; 182932523Sbostic 183032523Sbostic /* 183132523Sbostic * Make sure the device is a reasonable place on which to dump. 183232523Sbostic */ 183332523Sbostic unit = udaunit(dev); 183432523Sbostic if (unit >= NRA) 183532523Sbostic return (ENXIO); 183633444Sbostic #define phys(cast, addr) ((cast) ((int)addr & 0x7fffffff)) 183732523Sbostic ui = phys(struct uba_device *, udadinfo[unit]); 183832523Sbostic if (ui == NULL || ui->ui_alive == 0) 183932523Sbostic return (ENXIO); 184032523Sbostic 184132523Sbostic /* 184232523Sbostic * Find and initialise the UBA; get the physical address of the 184332523Sbostic * device registers, and of communications area and command and 184432523Sbostic * response packet. 184532523Sbostic */ 184632523Sbostic uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 184732523Sbostic ubainit(uba); 184832523Sbostic udaddr = (struct udadevice *)ui->ui_physaddr; 184932523Sbostic ud = phys(struct uda1 *, &uda1); 185032523Sbostic 185132523Sbostic /* 185232523Sbostic * Map the ca+packets into Unibus I/O space so the UDA50 can get 185332523Sbostic * at them. Use the registers at the end of the Unibus map (since 185432523Sbostic * we will use the registers at the beginning to map the memory 185532523Sbostic * we are dumping). 185632523Sbostic */ 185732523Sbostic num = btoc(sizeof(struct uda1)) + 1; 185832523Sbostic reg = NUBMREG - num; 185932523Sbostic io = &uba->uba_map[reg]; 186032523Sbostic for (i = 0; i < num; i++) 186132523Sbostic *(int *)io++ = UBAMR_MRV | (btop(ud) + i); 186232523Sbostic ud_ubaddr = (struct uda1 *)(((int)ud & PGOFSET) | (reg << 9)); 186332523Sbostic 186432523Sbostic /* 186532523Sbostic * Initialise the controller, with one command and one response 186632523Sbostic * packet. 186732523Sbostic */ 186832523Sbostic udaddr->udaip = 0; 186932523Sbostic if (udadumpwait(udaddr, UDA_STEP1)) 187032523Sbostic return (EFAULT); 187132523Sbostic udaddr->udasa = UDA_ERR; 187232523Sbostic if (udadumpwait(udaddr, UDA_STEP2)) 187332523Sbostic return (EFAULT); 187432523Sbostic udaddr->udasa = (int)&ud_ubaddr->uda1_ca.ca_rspdsc; 187532523Sbostic if (udadumpwait(udaddr, UDA_STEP3)) 187632523Sbostic return (EFAULT); 187732523Sbostic udaddr->udasa = ((int)&ud_ubaddr->uda1_ca.ca_rspdsc) >> 16; 187832523Sbostic if (udadumpwait(udaddr, UDA_STEP4)) 187932523Sbostic return (EFAULT); 188032523Sbostic uda_softc[ui->ui_ctlr].sc_micro = udaddr->udasa & 0xff; 188132523Sbostic udaddr->udasa = UDA_GO; 188232523Sbostic 188332523Sbostic /* 188432523Sbostic * Set up the command and response descriptor, then set the 188532523Sbostic * controller characteristics and bring the drive on line. 188632523Sbostic * Note that all uninitialised locations in uda1_cmd are zero. 188732523Sbostic */ 188832523Sbostic ud->uda1_ca.ca_rspdsc = (long)&ud_ubaddr->uda1_rsp.mscp_cmdref; 188932523Sbostic ud->uda1_ca.ca_cmddsc = (long)&ud_ubaddr->uda1_cmd.mscp_cmdref; 189032523Sbostic /* ud->uda1_cmd.mscp_sccc.sccc_ctlrflags = 0; */ 189132523Sbostic /* ud->uda1_cmd.mscp_sccc.sccc_version = 0; */ 189232523Sbostic if (udadumpcmd(M_OP_SETCTLRC, ud, ui)) 189332523Sbostic return (EFAULT); 189432523Sbostic ud->uda1_cmd.mscp_unit = ui->ui_slave; 189532523Sbostic if (udadumpcmd(M_OP_ONLINE, ud, ui)) 189632523Sbostic return (EFAULT); 189732523Sbostic 189832523Sbostic pp = phys(struct partition *, 189932523Sbostic &udalabel[unit].d_partitions[udapart(dev)]); 190032523Sbostic maxsz = pp->p_size; 190132523Sbostic blkoff = pp->p_offset; 190232523Sbostic 190332523Sbostic /* 190432523Sbostic * Dump all of physical memory, or as much as will fit in the 190532523Sbostic * space provided. 190632523Sbostic */ 190732523Sbostic start = 0; 190832523Sbostic num = maxfree; 190932523Sbostic if (dumplo + num >= maxsz) 191032523Sbostic num = maxsz - dumplo; 191132523Sbostic blkoff += dumplo; 191232523Sbostic 191332523Sbostic /* 191432523Sbostic * Write out memory, DBSIZE pages at a time. 191532523Sbostic * N.B.: this code depends on the fact that the sector 191632523Sbostic * size == the page size. 191732523Sbostic */ 191832523Sbostic while (num > 0) { 191932523Sbostic blk = num > DBSIZE ? DBSIZE : num; 192032523Sbostic io = uba->uba_map; 192132523Sbostic /* 192232523Sbostic * Map in the pages to write, leaving an invalid entry 192332523Sbostic * at the end to guard against wild Unibus transfers. 192432523Sbostic * Then do the write. 192532523Sbostic */ 192632523Sbostic for (i = 0; i < blk; i++) 192733444Sbostic *(int *)io++ = UBAMR_MRV | (btop(start) + i); 192833444Sbostic *(int *)io = 0; 192932523Sbostic ud->uda1_cmd.mscp_unit = ui->ui_slave; 193032523Sbostic ud->uda1_cmd.mscp_seq.seq_lbn = btop(start) + blkoff; 193132523Sbostic ud->uda1_cmd.mscp_seq.seq_bytecount = blk << PGSHIFT; 193232523Sbostic if (udadumpcmd(M_OP_WRITE, ud, ui)) 193332523Sbostic return (EIO); 193432523Sbostic start += blk << PGSHIFT; 193532523Sbostic num -= blk; 193632523Sbostic } 193732523Sbostic return (0); /* made it! */ 193832523Sbostic } 193932523Sbostic 194032523Sbostic /* 194132523Sbostic * Wait for some of the bits in `bits' to come on. If the error bit 194232523Sbostic * comes on, or ten seconds pass without response, return true (error). 194332523Sbostic */ 194432523Sbostic udadumpwait(udaddr, bits) 194532523Sbostic register struct udadevice *udaddr; 194632523Sbostic register int bits; 194732523Sbostic { 194832523Sbostic register int timo = todr() + 1000; 194932523Sbostic 195032523Sbostic while ((udaddr->udasa & bits) == 0) { 195132523Sbostic if (udaddr->udasa & UDA_ERR) { 195232523Sbostic printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 195332523Sbostic return (1); 195432523Sbostic } 195532523Sbostic if (todr() >= timo) { 195632523Sbostic printf("timeout\ndump "); 195732523Sbostic return (1); 195832523Sbostic } 195932523Sbostic } 196030536Skarels return (0); 196130536Skarels } 196230536Skarels 196332523Sbostic /* 196432523Sbostic * Feed a command to the UDA50, wait for its response, and return 196532523Sbostic * true iff something went wrong. 196632523Sbostic */ 196732523Sbostic udadumpcmd(op, ud, ui) 196832523Sbostic int op; 196932523Sbostic register struct uda1 *ud; 197032523Sbostic struct uba_device *ui; 197132523Sbostic { 197232523Sbostic register struct udadevice *udaddr; 197332523Sbostic register int n; 197432523Sbostic #define mp (&ud->uda1_rsp) 197532523Sbostic 197633444Sbostic udaddr = (struct udadevice *)ui->ui_physaddr; 197732523Sbostic ud->uda1_cmd.mscp_opcode = op; 197832523Sbostic ud->uda1_cmd.mscp_msglen = MSCP_MSGLEN; 197932523Sbostic ud->uda1_rsp.mscp_msglen = MSCP_MSGLEN; 198032523Sbostic ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 198132523Sbostic ud->uda1_ca.ca_cmddsc |= MSCP_OWN | MSCP_INT; 198232523Sbostic if (udaddr->udasa & UDA_ERR) { 198332523Sbostic printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 198432523Sbostic return (1); 198532523Sbostic } 198632523Sbostic n = udaddr->udaip; 198732523Sbostic n = todr() + 1000; 198832523Sbostic for (;;) { 198932523Sbostic if (todr() > n) { 199032523Sbostic printf("timeout\ndump "); 199132523Sbostic return (1); 199232523Sbostic } 199332523Sbostic if (ud->uda1_ca.ca_cmdint) 199432523Sbostic ud->uda1_ca.ca_cmdint = 0; 199532523Sbostic if (ud->uda1_ca.ca_rspint == 0) 199632523Sbostic continue; 199732523Sbostic ud->uda1_ca.ca_rspint = 0; 199832523Sbostic if (mp->mscp_opcode == (op | M_OP_END)) 199932523Sbostic break; 200032523Sbostic printf("\n"); 200132523Sbostic switch (MSCP_MSGTYPE(mp->mscp_msgtc)) { 200232523Sbostic 200332523Sbostic case MSCPT_SEQ: 200432523Sbostic printf("sequential"); 200532523Sbostic break; 200632523Sbostic 200732523Sbostic case MSCPT_DATAGRAM: 200832523Sbostic mscp_decodeerror("uda", ui->ui_ctlr, mp); 200932523Sbostic printf("datagram"); 201032523Sbostic break; 201132523Sbostic 201232523Sbostic case MSCPT_CREDITS: 201332523Sbostic printf("credits"); 201432523Sbostic break; 201532523Sbostic 201632523Sbostic case MSCPT_MAINTENANCE: 201732523Sbostic printf("maintenance"); 201832523Sbostic break; 201932523Sbostic 202032523Sbostic default: 202132523Sbostic printf("unknown (type 0x%x)", 202232523Sbostic MSCP_MSGTYPE(mp->mscp_msgtc)); 202332523Sbostic break; 202432523Sbostic } 202532523Sbostic printf(" ignored\ndump "); 202632523Sbostic ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 202732523Sbostic } 202832523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 202932523Sbostic printf("error: op 0x%x => 0x%x status 0x%x\ndump ", op, 203032523Sbostic mp->mscp_opcode, mp->mscp_status); 203132523Sbostic return (1); 203232523Sbostic } 203332523Sbostic return (0); 203432523Sbostic #undef mp 203532523Sbostic } 203632523Sbostic 203732523Sbostic /* 203832523Sbostic * Return the size of a partition, if known, or -1 if not. 203932523Sbostic */ 204032523Sbostic udasize(dev) 204130536Skarels dev_t dev; 204230536Skarels { 204332523Sbostic register int unit = udaunit(dev); 204430536Skarels register struct uba_device *ui; 204530536Skarels 204632523Sbostic if (unit >= NRA || (ui = udadinfo[unit]) == NULL || 204732523Sbostic ui->ui_alive == 0 || (ui->ui_flags & UNIT_ONLINE) == 0 || 204832523Sbostic ra_info[unit].ra_state != OPEN) 204912511Ssam return (-1); 205032523Sbostic return ((int)udalabel[unit].d_partitions[udapart(dev)].p_size); 205112511Ssam } 205217553Skarels 205330536Skarels #ifdef COMPAT_42 205432523Sbostic /* 205532523Sbostic * Tables mapping unlabelled drives. 205632523Sbostic */ 205730536Skarels struct size { 205830536Skarels daddr_t nblocks; 205930536Skarels daddr_t blkoff; 206033444Sbostic } ra60_sizes[8] = { 206130536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 206230536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 206330536Skarels 400176, 0, /* C=sectors 0 thru 400175 */ 206430536Skarels 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 206530536Skarels 268772, 131404, /* 4.2 H => E=sectors 131404 thru 400175 */ 206630536Skarels 350852, 49324, /* F=sectors 49324 thru 400175 */ 206730536Skarels 157570, 242606, /* UCB G => G=sectors 242606 thru 400175 */ 206830536Skarels 193282, 49324, /* UCB H => H=sectors 49324 thru 242605 */ 206933444Sbostic }, ra70_sizes[8] = { 207033444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 207133444Sbostic 33440, 15972, /* B=blk 15972 thru 49323 */ 207233444Sbostic -1, 0, /* C=blk 0 thru end */ 207333444Sbostic 15884, 341220, /* D=blk 341220 thru 357103 */ 207433444Sbostic 55936, 357192, /* E=blk 357192 thru 413127 */ 207533444Sbostic -1, 413457, /* F=blk 413457 thru end */ 207633444Sbostic -1, 341220, /* G=blk 341220 thru end */ 207733444Sbostic 291346, 49731, /* H=blk 49731 thru 341076 */ 207830536Skarels }, ra80_sizes[8] = { 207930536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 208030536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 208130536Skarels 242606, 0, /* C=sectors 0 thru 242605 */ 208230536Skarels 0, 0, /* D=unused */ 208330536Skarels 193282, 49324, /* UCB H => E=sectors 49324 thru 242605 */ 208430536Skarels 82080, 49324, /* 4.2 G => F=sectors 49324 thru 131403 */ 208530536Skarels 192696, 49910, /* G=sectors 49910 thru 242605 */ 208630536Skarels 111202, 131404, /* 4.2 H => H=sectors 131404 thru 242605 */ 208730536Skarels }, ra81_sizes[8] ={ 208830536Skarels /* 208930536Skarels * These are the new standard partition sizes for ra81's. 209030536Skarels * An RA_COMPAT system is compiled with D, E, and F corresponding 209130536Skarels * to the 4.2 partitions for G, H, and F respectively. 209230536Skarels */ 209330536Skarels #ifndef UCBRA 209430536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 209530536Skarels 66880, 16422, /* B=sectors 16422 thru 83301 */ 209630536Skarels 891072, 0, /* C=sectors 0 thru 891071 */ 209730536Skarels #ifdef RA_COMPAT 209830536Skarels 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 209930536Skarels 759668, 131404, /* 4.2 H => E=sectors 131404 thru 891071 */ 210030536Skarels 478582, 412490, /* 4.2 F => F=sectors 412490 thru 891071 */ 210130536Skarels #else 210230536Skarels 15884, 375564, /* D=sectors 375564 thru 391447 */ 210330536Skarels 307200, 391986, /* E=sectors 391986 thru 699185 */ 210430536Skarels 191352, 699720, /* F=sectors 699720 thru 891071 */ 210530536Skarels #endif RA_COMPAT 210630536Skarels 515508, 375564, /* G=sectors 375564 thru 891071 */ 210730536Skarels 291346, 83538, /* H=sectors 83538 thru 374883 */ 210830536Skarels 210930536Skarels /* 211030536Skarels * These partitions correspond to the sizes used by sites at Berkeley, 211130536Skarels * and by those sites that have received copies of the Berkeley driver 211230536Skarels * with deltas 6.2 or greater (11/15/83). 211330536Skarels */ 211430536Skarels #else UCBRA 211530536Skarels 211630536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 211730536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 211830536Skarels 891072, 0, /* C=sectors 0 thru 891071 */ 211930536Skarels 15884, 242606, /* D=sectors 242606 thru 258489 */ 212030536Skarels 307200, 258490, /* E=sectors 258490 thru 565689 */ 212130536Skarels 325382, 565690, /* F=sectors 565690 thru 891071 */ 212230536Skarels 648466, 242606, /* G=sectors 242606 thru 891071 */ 212330536Skarels 193282, 49324, /* H=sectors 49324 thru 242605 */ 212430536Skarels 212530536Skarels #endif UCBRA 212633444Sbostic }, ra82_sizes[8] = { 212733444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 212833444Sbostic 66880, 16245, /* B=blk 16245 thru 83124 */ 212933444Sbostic -1, 0, /* C=blk 0 thru end */ 213033444Sbostic 15884, 375345, /* D=blk 375345 thru 391228 */ 213133444Sbostic 307200, 391590, /* E=blk 391590 thru 698789 */ 213233444Sbostic -1, 699390, /* F=blk 699390 thru end */ 213333444Sbostic -1, 375345, /* G=blk 375345 thru end */ 213433444Sbostic 291346, 83790, /* H=blk 83790 thru 375135 */ 213533444Sbostic }, rc25_sizes[8] = { 213633444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 213733444Sbostic 10032, 15884, /* B=blk 15884 thru 49323 */ 213833444Sbostic -1, 0, /* C=blk 0 thru end */ 213933444Sbostic 0, 0, /* D=blk 340670 thru 356553 */ 214033444Sbostic 0, 0, /* E=blk 356554 thru 412489 */ 214133444Sbostic 0, 0, /* F=blk 412490 thru end */ 214233444Sbostic -1, 25916, /* G=blk 49324 thru 131403 */ 214333444Sbostic 0, 0, /* H=blk 131404 thru end */ 214433444Sbostic }, rd52_sizes[8] = { 214533444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 214633444Sbostic 9766, 15884, /* B=blk 15884 thru 25649 */ 214733444Sbostic -1, 0, /* C=blk 0 thru end */ 214833444Sbostic 0, 0, /* D=unused */ 214933444Sbostic 0, 0, /* E=unused */ 215033444Sbostic 0, 0, /* F=unused */ 215133444Sbostic -1, 25650, /* G=blk 25650 thru end */ 215233444Sbostic 0, 0, /* H=unused */ 215333444Sbostic }, rd53_sizes[8] = { 215433444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 215533444Sbostic 33440, 15884, /* B=blk 15884 thru 49323 */ 215633444Sbostic -1, 0, /* C=blk 0 thru end */ 215733444Sbostic 0, 0, /* D=unused */ 215833444Sbostic 33440, 0, /* E=blk 0 thru 33439 */ 215933444Sbostic -1, 33440, /* F=blk 33440 thru end */ 216033444Sbostic -1, 49324, /* G=blk 49324 thru end */ 216133444Sbostic -1, 15884, /* H=blk 15884 thru end */ 2162*45577Storek }, rd54_sizes[8] = { 2163*45577Storek 15884, 0, /* A=blk 0 thru 15883 */ 2164*45577Storek 33440, 15884, /* B=blk 15884 thru 49323 */ 2165*45577Storek -1, 0, /* C=blk 0 thru end */ 2166*45577Storek 130938, 49324, /* D=blk 49324 thru 180261 */ 2167*45577Storek 130938, 180262, /* E=blk 180262 thru 311199 (end) */ 2168*45577Storek 0, 0, /* F=unused */ 2169*45577Storek 261876, 49324, /* G=blk 49324 thru 311199 (end) */ 2170*45577Storek 0, 0, /* H=unused */ 217133444Sbostic }, rx50_sizes[8] = { 217233444Sbostic 800, 0, /* A=blk 0 thru 799 */ 217333444Sbostic 0, 0, 217433444Sbostic -1, 0, /* C=blk 0 thru end */ 217533444Sbostic 0, 0, 217633444Sbostic 0, 0, 217733444Sbostic 0, 0, 217833444Sbostic 0, 0, 217933444Sbostic 0, 0, 218030536Skarels }; 218130536Skarels 218232523Sbostic /* 218333444Sbostic * Media ID decoding table. 218432523Sbostic */ 218532523Sbostic struct udatypes { 218633444Sbostic u_long ut_id; /* media drive ID */ 218732523Sbostic char *ut_name; /* drive type name */ 218832523Sbostic struct size *ut_sizes; /* partition tables */ 218932523Sbostic int ut_nsectors, ut_ntracks, ut_ncylinders; 219032523Sbostic } udatypes[] = { 219133444Sbostic { MSCP_MKDRIVE2('R', 'A', 60), "ra60", ra60_sizes, 42, 4, 2382 }, 219233444Sbostic { MSCP_MKDRIVE2('R', 'A', 70), "ra70", ra70_sizes, 33, 11, 1507 }, 219333444Sbostic { MSCP_MKDRIVE2('R', 'A', 80), "ra80", ra80_sizes, 31, 14, 559 }, 219433444Sbostic { MSCP_MKDRIVE2('R', 'A', 81), "ra81", ra81_sizes, 51, 14, 1248 }, 219533444Sbostic { MSCP_MKDRIVE2('R', 'A', 82), "ra82", ra82_sizes, 57, 14, 1423 }, 219633444Sbostic { MSCP_MKDRIVE2('R', 'C', 25), "rc25-removable", 219733444Sbostic rc25_sizes, 42, 4, 302 }, 219833444Sbostic { MSCP_MKDRIVE3('R', 'C', 'F', 25), "rc25-fixed", 219933444Sbostic rc25_sizes, 42, 4, 302 }, 220033444Sbostic { MSCP_MKDRIVE2('R', 'D', 52), "rd52", rd52_sizes, 18, 7, 480 }, 220133444Sbostic { MSCP_MKDRIVE2('R', 'D', 53), "rd53", rd53_sizes, 18, 8, 963 }, 2202*45577Storek { MSCP_MKDRIVE2('R', 'D', 32), "rd54-from-rd32", 2203*45577Storek rd54_sizes, 17, 15, 1220 }, 2204*45577Storek { MSCP_MKDRIVE2('R', 'D', 54), "rd54", rd54_sizes, 17, 15, 1220 }, 220533444Sbostic { MSCP_MKDRIVE2('R', 'X', 50), "rx50", rx50_sizes, 10, 1, 80 }, 220633444Sbostic 0 220732523Sbostic }; 220832523Sbostic 220932523Sbostic #define NTYPES (sizeof(udatypes) / sizeof(*udatypes)) 221032523Sbostic 221132523Sbostic udamaptype(unit, lp) 221232523Sbostic int unit; 221330536Skarels register struct disklabel *lp; 221430536Skarels { 221532523Sbostic register struct udatypes *ut; 221632523Sbostic register struct size *sz; 221730536Skarels register struct partition *pp; 221832523Sbostic register char *p; 221932523Sbostic register int i; 222032523Sbostic register struct ra_info *ra = &ra_info[unit]; 222130536Skarels 222233444Sbostic i = MSCP_MEDIA_DRIVE(ra->ra_mediaid); 222333444Sbostic for (ut = udatypes; ut->ut_id; ut++) 222436036Skarels if (ut->ut_id == i && 222536036Skarels ut->ut_nsectors == ra->ra_geom.rg_nsectors && 222636036Skarels ut->ut_ntracks == ra->ra_geom.rg_ntracks && 222736036Skarels ut->ut_ncylinders == ra->ra_geom.rg_ncyl) 222833444Sbostic goto found; 222933444Sbostic 223033444Sbostic /* not one we know; fake up a label for the whole drive */ 223136036Skarels uda_makefakelabel(ra, lp); 223233444Sbostic i = ra->ra_mediaid; /* print the port type too */ 223336036Skarels addlog(": no partition table for %c%c %c%c%c%d, size %d;\n\ 223434283Skarels using (s,t,c)=(%d,%d,%d)", 223534283Skarels MSCP_MID_CHAR(4, i), MSCP_MID_CHAR(3, i), 223633444Sbostic MSCP_MID_CHAR(2, i), MSCP_MID_CHAR(1, i), 223736036Skarels MSCP_MID_CHAR(0, i), MSCP_MID_NUM(i), lp->d_secperunit, 223836036Skarels lp->d_nsectors, lp->d_ntracks, lp->d_ncylinders); 223934283Skarels if (!cold) 224034283Skarels addlog("\n"); 224133444Sbostic return (0); 224233444Sbostic found: 224332523Sbostic p = ut->ut_name; 224432523Sbostic for (i = 0; i < sizeof(lp->d_typename) - 1 && *p; i++) 224532523Sbostic lp->d_typename[i] = *p++; 224632523Sbostic lp->d_typename[i] = 0; 224732523Sbostic sz = ut->ut_sizes; 224832523Sbostic lp->d_nsectors = ut->ut_nsectors; 224932523Sbostic lp->d_ntracks = ut->ut_ntracks; 225032523Sbostic lp->d_ncylinders = ut->ut_ncylinders; 225130536Skarels lp->d_npartitions = 8; 225230536Skarels lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 225332523Sbostic for (pp = lp->d_partitions; pp < &lp->d_partitions[8]; pp++, sz++) { 225432523Sbostic pp->p_offset = sz->blkoff; 225532523Sbostic if ((pp->p_size = sz->nblocks) == (u_long)-1) 225632523Sbostic pp->p_size = ra->ra_dsize - sz->blkoff; 225730536Skarels } 225830536Skarels return (1); 225930536Skarels } 226032523Sbostic #endif /* COMPAT_42 */ 226136036Skarels 226236036Skarels /* 226336036Skarels * Construct a label for a drive from geometry information 226436036Skarels * if we have no better information. 226536036Skarels */ 226636036Skarels uda_makefakelabel(ra, lp) 226736036Skarels register struct ra_info *ra; 226836036Skarels register struct disklabel *lp; 226936036Skarels { 227036036Skarels lp->d_nsectors = ra->ra_geom.rg_nsectors; 227136036Skarels lp->d_ntracks = ra->ra_geom.rg_ntracks; 227236036Skarels lp->d_ncylinders = ra->ra_geom.rg_ncyl; 227336036Skarels lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 227436036Skarels bcopy("ra??", lp->d_typename, sizeof("ra??")); 227536036Skarels lp->d_npartitions = 1; 227636036Skarels lp->d_partitions[0].p_offset = 0; 227736036Skarels lp->d_partitions[0].p_size = lp->d_secperunit; 227836036Skarels } 227932523Sbostic #endif /* NUDA > 0 */ 2280