123353Smckusick /* 232523Sbostic * Copyright (c) 1987 Regents of the University of California. 332523Sbostic * All rights reserved. The Berkeley software License Agreement 432523Sbostic * specifies the terms and conditions for redistribution. 532523Sbostic * 6*34638Skarels * @(#)uda.c 7.17 (Berkeley) 06/04/88 732523Sbostic * 823353Smckusick */ 923353Smckusick 1032523Sbostic /* 1132523Sbostic * UDA50/MSCP device driver 1217553Skarels */ 1317553Skarels 1432523Sbostic #define POLLSTATS 1532523Sbostic 1632523Sbostic /* 1732523Sbostic * TODO 1832523Sbostic * write bad block forwarding code 1932523Sbostic */ 2032523Sbostic 214743Swnj #include "ra.h" 2232523Sbostic 2317642Skarels #if NUDA > 0 2432523Sbostic 254743Swnj /* 2632523Sbostic * CONFIGURATION OPTIONS. The next three defines are tunable -- tune away! 274743Swnj * 2832523Sbostic * COMPAT_42 enables 4.2/4.3 compatibility (label mapping) 2932523Sbostic * 3032523Sbostic * NRSPL2 and NCMDL2 control the number of response and command 3132523Sbostic * packets respectively. They may be any value from 0 to 7, though 3232523Sbostic * setting them higher than 5 is unlikely to be of any value. 3332523Sbostic * If you get warnings about your command ring being too small, 3432523Sbostic * try increasing the values by one. 3532523Sbostic * 3632523Sbostic * MAXUNIT controls the maximum unit number (number of drives per 3732523Sbostic * controller) we are prepared to handle. 3832523Sbostic * 3932523Sbostic * DEFAULT_BURST must be at least 1. 404743Swnj */ 4132523Sbostic #define COMPAT_42 4232523Sbostic 4332523Sbostic #define NRSPL2 5 /* log2 number of response packets */ 4432523Sbostic #define NCMDL2 5 /* log2 number of command packets */ 4532523Sbostic #define MAXUNIT 8 /* maximum allowed unit number */ 4632523Sbostic #define DEFAULT_BURST 4 /* default DMA burst size */ 4732523Sbostic 4817553Skarels #include "param.h" 4917553Skarels #include "systm.h" 5017553Skarels #include "buf.h" 5117553Skarels #include "conf.h" 5217553Skarels #include "dir.h" 5330536Skarels #include "file.h" 5430536Skarels #include "ioctl.h" 5517553Skarels #include "user.h" 5617553Skarels #include "map.h" 5717553Skarels #include "vm.h" 5830536Skarels #include "dkstat.h" 5917553Skarels #include "cmap.h" 6030536Skarels #include "disklabel.h" 6130536Skarels #include "syslog.h" 6230773Skarels #include "stat.h" 634743Swnj 6434283Skarels #include "../machine/pte.h" 6534283Skarels 668482Sroot #include "../vax/cpu.h" 6717553Skarels #include "ubareg.h" 6817553Skarels #include "ubavar.h" 698613Sroot 7032523Sbostic #define NRSP (1 << NRSPL2) 7132523Sbostic #define NCMD (1 << NCMDL2) 728613Sroot 7332523Sbostic #include "udareg.h" 748482Sroot #include "../vax/mscp.h" 7532523Sbostic #include "../vax/mscpvar.h" 7632523Sbostic #include "../vax/mtpr.h" 774743Swnj 7832523Sbostic /* 7932523Sbostic * UDA communications area and MSCP packet pools, per controller. 8032523Sbostic */ 8132523Sbostic struct uda { 8232523Sbostic struct udaca uda_ca; /* communications area */ 8332523Sbostic struct mscp uda_rsp[NRSP]; /* response packets */ 8432523Sbostic struct mscp uda_cmd[NCMD]; /* command packets */ 854743Swnj } uda[NUDA]; 864743Swnj 8732523Sbostic /* 8832523Sbostic * Software status, per controller. 8932523Sbostic */ 9032523Sbostic struct uda_softc { 9132523Sbostic struct uda *sc_uda; /* Unibus address of uda struct */ 9232523Sbostic short sc_state; /* UDA50 state; see below */ 9332523Sbostic short sc_flags; /* flags; see below */ 9432523Sbostic int sc_micro; /* microcode revision */ 9532523Sbostic int sc_ivec; /* interrupt vector address */ 9632523Sbostic struct mscp_info sc_mi;/* MSCP info (per mscpvar.h) */ 9732523Sbostic #ifndef POLLSTATS 9832523Sbostic int sc_wticks; /* watchdog timer ticks */ 9932523Sbostic #else 10032523Sbostic short sc_wticks; 10132523Sbostic short sc_ncmd; 10232523Sbostic #endif 10332523Sbostic } uda_softc[NUDA]; 10424742Sbloom 10532523Sbostic #ifdef POLLSTATS 10632523Sbostic struct udastats { 10732523Sbostic int ncmd; 10832523Sbostic int cmd[NCMD + 1]; 10932523Sbostic } udastats = { NCMD + 1 }; 11032523Sbostic #endif 11117553Skarels 11232523Sbostic /* 11332523Sbostic * Controller states 11432523Sbostic */ 11532523Sbostic #define ST_IDLE 0 /* uninitialised */ 11632523Sbostic #define ST_STEP1 1 /* in `STEP 1' */ 11732523Sbostic #define ST_STEP2 2 /* in `STEP 2' */ 11832523Sbostic #define ST_STEP3 3 /* in `STEP 3' */ 11932523Sbostic #define ST_SETCHAR 4 /* in `Set Controller Characteristics' */ 12032523Sbostic #define ST_RUN 5 /* up and running */ 1214743Swnj 12232523Sbostic /* 12332523Sbostic * Flags 12432523Sbostic */ 12532523Sbostic #define SC_MAPPED 0x01 /* mapped in Unibus I/O space */ 12632523Sbostic #define SC_INSTART 0x02 /* inside udastart() */ 12732523Sbostic #define SC_GRIPED 0x04 /* griped about cmd ring too small */ 12832523Sbostic #define SC_INSLAVE 0x08 /* inside udaslave() */ 12932523Sbostic #define SC_DOWAKE 0x10 /* wakeup when ctlr init done */ 13032523Sbostic #define SC_STARTPOLL 0x20 /* need to initiate polling */ 13112421Ssam 13232523Sbostic /* 13332523Sbostic * Device to unit number and partition and back 13432523Sbostic */ 13532523Sbostic #define UNITSHIFT 3 13632523Sbostic #define UNITMASK 7 13732523Sbostic #define udaunit(dev) (minor(dev) >> UNITSHIFT) 13832523Sbostic #define udapart(dev) (minor(dev) & UNITMASK) 13932523Sbostic #define udaminor(u, p) (((u) << UNITSHIFT) | (p)) 1404743Swnj 14117553Skarels /* 14232523Sbostic * Drive status, per drive 14317553Skarels */ 14432523Sbostic struct ra_info { 14532523Sbostic daddr_t ra_dsize; /* size in sectors */ 14633444Sbostic /* u_long ra_type; /* drive type */ 14733195Sbostic #define RA_TYPE_RX50 7 /* special: see udaopen */ 14832523Sbostic u_long ra_mediaid; /* media id */ 14932523Sbostic int ra_state; /* open/closed state */ 15032523Sbostic struct ra_geom { /* geometry information */ 15132523Sbostic u_short rg_nsectors; /* sectors/track */ 15232523Sbostic u_short rg_ngroups; /* track groups */ 15332523Sbostic u_short rg_ngpc; /* groups/cylinder */ 15432523Sbostic u_short rg_ntracks; /* ngroups*ngpc */ 15532523Sbostic u_short rg_ncyl; /* ra_dsize/ntracks/nsectors */ 15632523Sbostic #ifdef notyet 15732523Sbostic u_short rg_rctsize; /* size of rct */ 15832523Sbostic u_short rg_rbns; /* replacement blocks per track */ 15932523Sbostic u_short rg_nrct; /* number of rct copies */ 16032523Sbostic #endif 16132523Sbostic } ra_geom; 16233443Skarels int ra_wlabel; /* label sector is currently writable */ 16332523Sbostic u_long ra_openpart; /* partitions open */ 16432523Sbostic u_long ra_bopenpart; /* block partitions open */ 16532523Sbostic u_long ra_copenpart; /* character partitions open */ 16632523Sbostic } ra_info[NRA]; 16717553Skarels 16830536Skarels /* 16930536Skarels * Software state, per drive 17030536Skarels */ 17130536Skarels #define CLOSED 0 17230536Skarels #define WANTOPEN 1 17330536Skarels #define RDLABEL 2 17430536Skarels #define OPEN 3 17530536Skarels #define OPENRAW 4 17617553Skarels 17732523Sbostic /* 17832523Sbostic * Definition of the driver for autoconf. 17932523Sbostic */ 18032523Sbostic int udaprobe(), udaslave(), udaattach(), udadgo(), udaintr(); 18132523Sbostic struct uba_ctlr *udaminfo[NUDA]; 18232523Sbostic struct uba_device *udadinfo[NRA]; 18332523Sbostic struct disklabel udalabel[NRA]; 18417553Skarels 18532523Sbostic u_short udastd[] = { 0772150, 0772550, 0777550, 0 }; 18632523Sbostic struct uba_driver udadriver = 18732523Sbostic { udaprobe, udaslave, udaattach, udadgo, udastd, "ra", udadinfo, "uda", 18832523Sbostic udaminfo }; 18917553Skarels 19032523Sbostic /* 19132523Sbostic * More driver definitions, for generic MSCP code. 19232523Sbostic */ 19332523Sbostic int udadgram(), udactlrdone(), udaunconf(), udaiodone(); 19432523Sbostic int udaonline(), udagotstatus(), udaioerror(), udareplace(), udabb(); 1954743Swnj 19632523Sbostic struct buf udautab[NRA]; /* per drive transfer queue */ 1974743Swnj 19832523Sbostic struct mscp_driver udamscpdriver = 19934524Skarels { MAXUNIT, NRA, UNITSHIFT, udautab, udalabel, udadinfo, 20032523Sbostic udadgram, udactlrdone, udaunconf, udaiodone, 20132523Sbostic udaonline, udagotstatus, udareplace, udaioerror, udabb, 20232523Sbostic "uda", "ra" }; 20332523Sbostic 20432523Sbostic /* 20532523Sbostic * Miscellaneous private variables. 20632523Sbostic */ 20732523Sbostic char udasr_bits[] = UDASR_BITS; 20832523Sbostic 20932523Sbostic struct uba_device *udaip[NUDA][MAXUNIT]; 21032523Sbostic /* inverting pointers: ctlr & unit => Unibus 21132523Sbostic device pointer */ 21232523Sbostic 21332523Sbostic int udaburst[NUDA] = { 0 }; /* burst size, per UDA50, zero => default; 21432523Sbostic in data space so patchable via adb */ 21532523Sbostic 21632523Sbostic struct mscp udaslavereply; /* get unit status response packet, set 21732523Sbostic for udaslave by udaunconf, via udaintr */ 21832523Sbostic 21932523Sbostic static struct uba_ctlr *probeum;/* this is a hack---autoconf should pass ctlr 22032523Sbostic info to slave routine; instead, we remember 22132523Sbostic the last ctlr argument to probe */ 22232523Sbostic 22332523Sbostic int udawstart, udawatch(); /* watchdog timer */ 22432523Sbostic 22532523Sbostic /* 22632523Sbostic * Externals 22732523Sbostic */ 22832523Sbostic int wakeup(); 22932523Sbostic int hz; 23032523Sbostic 23132523Sbostic /* 23232523Sbostic * Poke at a supposed UDA50 to see if it is there. 23332523Sbostic * This routine duplicates some of the code in udainit() only 23432523Sbostic * because autoconf has not set up the right information yet. 23532523Sbostic * We have to do everything `by hand'. 23632523Sbostic */ 23732523Sbostic udaprobe(reg, ctlr, um) 2384743Swnj caddr_t reg; 2394743Swnj int ctlr; 24032523Sbostic struct uba_ctlr *um; 2414743Swnj { 2424743Swnj register int br, cvec; 24332523Sbostic register struct uda_softc *sc; 24432523Sbostic register struct udadevice *udaddr; 24532523Sbostic register struct mscp_info *mi; 24632523Sbostic int timeout, tries; 2474743Swnj 24832523Sbostic #ifdef VAX750 24932523Sbostic /* 25032523Sbostic * The UDA50 wants to share BDPs on 750s, but not on 780s or 25132523Sbostic * 8600s. (730s have no BDPs anyway.) Toward this end, we 25232523Sbostic * here set the `keep bdp' flag in the per-driver information 25332523Sbostic * if this is a 750. (We just need to do it once, but it is 25432523Sbostic * easiest to do it now, for each UDA50.) 25532523Sbostic */ 25632523Sbostic if (cpu == VAX_750) 25732523Sbostic udadriver.ud_keepbdp = 1; 25832523Sbostic #endif 25917553Skarels 26032523Sbostic probeum = um; /* remember for udaslave() */ 2614743Swnj #ifdef lint 26232523Sbostic br = 0; cvec = br; br = cvec; udaintr(0); 2634743Swnj #endif 26432523Sbostic /* 26532523Sbostic * Set up the controller-specific generic MSCP driver info. 26632523Sbostic * Note that this should really be done in the (nonexistent) 26732523Sbostic * controller attach routine. 26832523Sbostic */ 26932523Sbostic sc = &uda_softc[ctlr]; 27032523Sbostic mi = &sc->sc_mi; 27132523Sbostic mi->mi_md = &udamscpdriver; 27232523Sbostic mi->mi_ctlr = um->um_ctlr; 27332523Sbostic mi->mi_tab = &um->um_tab; 27432523Sbostic mi->mi_ip = udaip[ctlr]; 27532523Sbostic mi->mi_cmd.mri_size = NCMD; 27632523Sbostic mi->mi_cmd.mri_desc = uda[ctlr].uda_ca.ca_cmddsc; 27732523Sbostic mi->mi_cmd.mri_ring = uda[ctlr].uda_cmd; 27832523Sbostic mi->mi_rsp.mri_size = NRSP; 27932523Sbostic mi->mi_rsp.mri_desc = uda[ctlr].uda_ca.ca_rspdsc; 28032523Sbostic mi->mi_rsp.mri_ring = uda[ctlr].uda_rsp; 28132523Sbostic mi->mi_wtab.av_forw = mi->mi_wtab.av_back = &mi->mi_wtab; 28232523Sbostic 28332523Sbostic /* 28432523Sbostic * More controller specific variables. Again, this should 28532523Sbostic * be in the controller attach routine. 28632523Sbostic */ 28732523Sbostic if (udaburst[ctlr] == 0) 28832523Sbostic udaburst[ctlr] = DEFAULT_BURST; 28932523Sbostic 29032523Sbostic /* 29132523Sbostic * Get an interrupt vector. Note that even if the controller 29232523Sbostic * does not respond, we keep the vector. This is not a serious 29332523Sbostic * problem; but it would be easily fixed if we had a controller 29432523Sbostic * attach routine. Sigh. 29532523Sbostic */ 29632523Sbostic sc->sc_ivec = (uba_hd[numuba].uh_lastiv -= 4); 29717553Skarels udaddr = (struct udadevice *) reg; 29817553Skarels 29932523Sbostic /* 30032523Sbostic * Initialise the controller (partially). The UDA50 programmer's 30132523Sbostic * manual states that if initialisation fails, it should be retried 30232523Sbostic * at least once, but after a second failure the port should be 30332523Sbostic * considered `down'; it also mentions that the controller should 30432523Sbostic * initialise within ten seconds. Or so I hear; I have not seen 30532523Sbostic * this manual myself. 30632523Sbostic */ 30732523Sbostic tries = 0; 30832523Sbostic again: 30932523Sbostic udaddr->udaip = 0; /* start initialisation */ 31032523Sbostic timeout = todr() + 1000; /* timeout in 10 seconds */ 31132523Sbostic while ((udaddr->udasa & UDA_STEP1) == 0) 31232523Sbostic if (todr() > timeout) 31332523Sbostic goto bad; 31432523Sbostic udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 31532523Sbostic (sc->sc_ivec >> 2); 31632523Sbostic while ((udaddr->udasa & UDA_STEP2) == 0) 31732523Sbostic if (todr() > timeout) 31832523Sbostic goto bad; 31932523Sbostic 32032523Sbostic /* should have interrupted by now */ 32132523Sbostic #ifdef VAX630 32232523Sbostic if (cpu == VAX_630) 32332523Sbostic br = 0x15; /* screwy interrupt structure */ 32427254Skridle #endif 32532523Sbostic return (sizeof (struct udadevice)); 32632523Sbostic bad: 32732523Sbostic if (++tries < 2) 32832523Sbostic goto again; 32932523Sbostic return (0); 3304743Swnj } 3314743Swnj 33232523Sbostic /* 33332523Sbostic * Find a slave. We allow wildcard slave numbers (something autoconf 33432523Sbostic * is not really prepared to deal with); and we need to know the 33532523Sbostic * controller number to talk to the UDA. For the latter, we keep 33632523Sbostic * track of the last controller probed, since a controller probe 33732523Sbostic * immediately precedes all slave probes for that controller. For the 33832523Sbostic * former, we simply put the unit number into ui->ui_slave after we 33932523Sbostic * have found one. 34032523Sbostic * 34132523Sbostic * Note that by the time udaslave is called, the interrupt vector 34232523Sbostic * for the UDA50 has been set up (so that udaunconf() will be called). 34332523Sbostic */ 34432523Sbostic udaslave(ui, reg) 34532523Sbostic register struct uba_device *ui; 3464743Swnj caddr_t reg; 3474743Swnj { 34832523Sbostic register struct uba_ctlr *um = probeum; 34932523Sbostic register struct mscp *mp; 35032523Sbostic register struct uda_softc *sc; 35133443Skarels int next = 0, timeout, tries, i; 35217553Skarels 35332523Sbostic #ifdef lint 35432523Sbostic i = 0; i = i; 35532523Sbostic #endif 35632523Sbostic /* 35732523Sbostic * Make sure the controller is fully initialised, by waiting 35832523Sbostic * for it if necessary. 35932523Sbostic */ 36032523Sbostic sc = &uda_softc[um->um_ctlr]; 36132523Sbostic if (sc->sc_state == ST_RUN) 36232523Sbostic goto findunit; 36332523Sbostic tries = 0; 36432523Sbostic again: 36532523Sbostic if (udainit(ui->ui_ctlr)) 36632523Sbostic return (0); 36732523Sbostic timeout = todr() + 1000; /* 10 seconds */ 36832523Sbostic while (todr() < timeout) 36932523Sbostic if (sc->sc_state == ST_RUN) /* made it */ 37032523Sbostic goto findunit; 37132523Sbostic if (++tries < 2) 37232523Sbostic goto again; 37332523Sbostic printf("uda%d: controller hung\n", um->um_ctlr); 37432523Sbostic return (0); 37517553Skarels 37632523Sbostic /* 37732523Sbostic * The controller is all set; go find the unit. Grab an 37832523Sbostic * MSCP packet and send out a Get Unit Status command, with 37932523Sbostic * the `next unit' modifier if we are looking for a generic 38032523Sbostic * unit. We set the `in slave' flag so that udaunconf() 38132523Sbostic * knows to copy the response to `udaslavereply'. 38232523Sbostic */ 38332523Sbostic findunit: 38432523Sbostic udaslavereply.mscp_opcode = 0; 38532523Sbostic sc->sc_flags |= SC_INSLAVE; 38632523Sbostic if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) 38732523Sbostic panic("udaslave"); /* `cannot happen' */ 38832523Sbostic mp->mscp_opcode = M_OP_GETUNITST; 38932523Sbostic if (ui->ui_slave == '?') { 39032523Sbostic mp->mscp_unit = next; 39132523Sbostic mp->mscp_modifier = M_GUM_NEXTUNIT; 39232523Sbostic } else { 39332523Sbostic mp->mscp_unit = ui->ui_slave; 39432523Sbostic mp->mscp_modifier = 0; 39517553Skarels } 39632523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 39732523Sbostic i = ((struct udadevice *) reg)->udaip; /* initiate polling */ 39832523Sbostic mp = &udaslavereply; 39932523Sbostic timeout = todr() + 1000; 40032523Sbostic while (todr() < timeout) 40132523Sbostic if (mp->mscp_opcode) 40232523Sbostic goto gotit; 40332523Sbostic printf("uda%d: no response to Get Unit Status request\n", 40432523Sbostic um->um_ctlr); 40532523Sbostic sc->sc_flags &= ~SC_INSLAVE; 40632523Sbostic return (0); 40732523Sbostic 40832523Sbostic gotit: 40932523Sbostic sc->sc_flags &= ~SC_INSLAVE; 41032523Sbostic 41132523Sbostic /* 41232523Sbostic * Got a slave response. If the unit is there, use it. 41332523Sbostic */ 41432523Sbostic switch (mp->mscp_status & M_ST_MASK) { 41532523Sbostic 41632523Sbostic case M_ST_SUCCESS: /* worked */ 41732523Sbostic case M_ST_AVAILABLE: /* found another drive */ 41832523Sbostic break; /* use it */ 41932523Sbostic 42032523Sbostic case M_ST_OFFLINE: 42132523Sbostic /* 42232523Sbostic * Figure out why it is off line. It may be because 42332523Sbostic * it is nonexistent, or because it is spun down, or 42432523Sbostic * for some other reason. 42532523Sbostic */ 42632523Sbostic switch (mp->mscp_status & ~M_ST_MASK) { 42732523Sbostic 42832523Sbostic case M_OFFLINE_UNKNOWN: 42932523Sbostic /* 43032523Sbostic * No such drive, and there are none with 43132523Sbostic * higher unit numbers either, if we are 43232523Sbostic * using M_GUM_NEXTUNIT. 43332523Sbostic */ 43432523Sbostic return (0); 43532523Sbostic 43632523Sbostic case M_OFFLINE_UNMOUNTED: 43732523Sbostic /* 43832523Sbostic * The drive is not spun up. Use it anyway. 43932523Sbostic * 44032523Sbostic * N.B.: this seems to be a common occurrance 44132523Sbostic * after a power failure. The first attempt 44232523Sbostic * to bring it on line seems to spin it up 44332523Sbostic * (and thus takes several minutes). Perhaps 44432523Sbostic * we should note here that the on-line may 44532523Sbostic * take longer than usual. 44632523Sbostic */ 44732523Sbostic break; 44832523Sbostic 44932523Sbostic default: 45032523Sbostic /* 45132523Sbostic * In service, or something else equally unusable. 45232523Sbostic */ 45332523Sbostic printf("uda%d: unit %d off line: ", um->um_ctlr, 45432523Sbostic mp->mscp_unit); 45532523Sbostic mscp_printevent(mp); 45632523Sbostic goto try_another; 45732523Sbostic } 45832523Sbostic break; 45932523Sbostic 46032523Sbostic default: 46132523Sbostic printf("uda%d: unable to get unit status: ", um->um_ctlr); 46232523Sbostic mscp_printevent(mp); 46332523Sbostic return (0); 46417553Skarels } 46532523Sbostic 46632523Sbostic /* 46732523Sbostic * Does this ever happen? What (if anything) does it mean? 46832523Sbostic */ 46932523Sbostic if (mp->mscp_unit < next) { 47032523Sbostic printf("uda%d: unit %d, next %d\n", 47132523Sbostic um->um_ctlr, mp->mscp_unit, next); 47232523Sbostic return (0); 47317553Skarels } 47432523Sbostic 47532523Sbostic if (mp->mscp_unit >= MAXUNIT) { 47632523Sbostic printf("uda%d: cannot handle unit number %d (max is %d)\n", 47732523Sbostic um->um_ctlr, mp->mscp_unit, MAXUNIT - 1); 47832523Sbostic return (0); 47932523Sbostic } 48032523Sbostic 48132523Sbostic /* 48232523Sbostic * See if we already handle this drive. 48332523Sbostic * (Only likely if ui->ui_slave=='?'.) 48432523Sbostic */ 48532523Sbostic if (udaip[um->um_ctlr][mp->mscp_unit] != NULL) { 48632523Sbostic try_another: 48732523Sbostic if (ui->ui_slave != '?') 48832523Sbostic return (0); 48932523Sbostic next = mp->mscp_unit + 1; 49032523Sbostic goto findunit; 49132523Sbostic } 49232523Sbostic 49332523Sbostic /* 49432523Sbostic * Voila! 49532523Sbostic */ 49632523Sbostic uda_rasave(ui->ui_unit, mp, 0); 49732523Sbostic ui->ui_flags = 0; /* not on line, nor anything else */ 49832523Sbostic ui->ui_slave = mp->mscp_unit; 49932523Sbostic return (1); 5004743Swnj } 5014743Swnj 50232523Sbostic /* 50332523Sbostic * Attach a found slave. Make sure the watchdog timer is running. 50432523Sbostic * If this disk is being profiled, fill in the `mspw' value (used by 50532523Sbostic * what?). Set up the inverting pointer, and attempt to bring the 50632523Sbostic * drive on line and read its label. 50732523Sbostic */ 50832523Sbostic udaattach(ui) 5094743Swnj register struct uba_device *ui; 5104743Swnj { 51132523Sbostic register int unit = ui->ui_unit; 51232523Sbostic 51332523Sbostic if (udawstart == 0) { 51432523Sbostic timeout(udawatch, (caddr_t) 0, hz); 51532523Sbostic udawstart++; 51632523Sbostic } 51712443Ssam if (ui->ui_dk >= 0) 51833444Sbostic 51933444Sbostic /* 52033444Sbostic * Floppies cannot be brought on line unless there is 52133444Sbostic * a disk in the drive. Since an ONLINE while cold 52233444Sbostic * takes ten seconds to fail, and (when notyet becomes now) 52333444Sbostic * no sensible person will swap to one, we just 52433444Sbostic * defer the ONLINE until someone tries to use the drive. 52533444Sbostic * 52633444Sbostic * THIS ASSUMES THAT DRIVE TYPES ?X? ARE FLOPPIES 52733444Sbostic */ 52833444Sbostic if (MSCP_MID_ECH(1, ra_info[unit].ra_mediaid) == 'X' - '@') { 52934283Skarels printf(": floppy"); 53033444Sbostic return; 53133444Sbostic } 53232523Sbostic dk_mspw[ui->ui_dk] = 1.0 / (60 * 31 * 256); /* approx */ 53332523Sbostic udaip[ui->ui_ctlr][ui->ui_slave] = ui; 53433195Sbostic 53534283Skarels #ifdef notdef 53633195Sbostic /* 53733195Sbostic * RX50s cannot be brought on line unless there is 53833195Sbostic * a floppy in the drive. Since an ONLINE while cold 53933195Sbostic * takes ten seconds to fail, and (when notyet becomes now) 54033195Sbostic * no sensible person will swap to an RX50, we just 54133195Sbostic * defer the ONLINE until someone tries to use the drive. 54233195Sbostic */ 54333195Sbostic if (ra_info[unit].ra_type == RA_TYPE_RX50) { 54434283Skarels printf(": rx50"); 54533195Sbostic return; 54633195Sbostic } 54734283Skarels #endif 54832523Sbostic if (uda_rainit(ui, 0)) 54934283Skarels printf(": offline"); 55032523Sbostic else { 55134283Skarels printf(": %s, size = %d sectors", 55234283Skarels udalabel[unit].d_typename, ra_info[unit].ra_dsize); 55332523Sbostic #ifdef notyet 55432523Sbostic addswap(makedev(UDADEVNUM, udaminor(unit, 0)), &udalabel[unit]); 55526295Skarels #endif 55630536Skarels } 55732523Sbostic } 55832523Sbostic 55932523Sbostic /* 56032523Sbostic * Initialise a UDA50. Return true iff something goes wrong. 56132523Sbostic */ 56232523Sbostic udainit(ctlr) 56332523Sbostic int ctlr; 56432523Sbostic { 56532523Sbostic register struct uda_softc *sc; 56632523Sbostic register struct udadevice *udaddr; 56732523Sbostic struct uba_ctlr *um; 56832523Sbostic int timo, ubinfo; 56932523Sbostic 57032523Sbostic sc = &uda_softc[ctlr]; 57132523Sbostic um = udaminfo[ctlr]; 57232523Sbostic if ((sc->sc_flags & SC_MAPPED) == 0) { 57332523Sbostic /* 57432523Sbostic * Map the communication area and command and 57532523Sbostic * response packets into Unibus space. 57632523Sbostic */ 57732523Sbostic ubinfo = uballoc(um->um_ubanum, (caddr_t) &uda[ctlr], 57832523Sbostic sizeof (struct uda), UBA_CANTWAIT); 57932523Sbostic if (ubinfo == 0) { 58032523Sbostic printf("uda%d: uballoc map failed\n", ctlr); 58132523Sbostic return (-1); 58232523Sbostic } 58332523Sbostic sc->sc_uda = (struct uda *) (ubinfo & 0x3ffff); 58432523Sbostic sc->sc_flags |= SC_MAPPED; 58532523Sbostic } 58632523Sbostic 58730536Skarels /* 58832523Sbostic * While we are thinking about it, reset the next command 58932523Sbostic * and response indicies. 59030536Skarels */ 59132523Sbostic sc->sc_mi.mi_cmd.mri_next = 0; 59232523Sbostic sc->sc_mi.mi_rsp.mri_next = 0; 59332523Sbostic 59432523Sbostic /* 59532523Sbostic * Start up the hardware initialisation sequence. 59632523Sbostic */ 59732523Sbostic #define STEP0MASK (UDA_ERR | UDA_STEP4 | UDA_STEP3 | UDA_STEP2 | \ 59832523Sbostic UDA_STEP1 | UDA_NV) 59932523Sbostic 60032523Sbostic sc->sc_state = ST_IDLE; /* in case init fails */ 60133444Sbostic udaddr = (struct udadevice *)um->um_addr; 60232523Sbostic udaddr->udaip = 0; 60332523Sbostic timo = todr() + 1000; 60432523Sbostic while ((udaddr->udasa & STEP0MASK) == 0) { 60532523Sbostic if (todr() > timo) { 60632523Sbostic printf("uda%d: timeout during init\n", ctlr); 60732523Sbostic return (-1); 60832523Sbostic } 60932523Sbostic } 61032523Sbostic if ((udaddr->udasa & STEP0MASK) != UDA_STEP1) { 61132523Sbostic printf("uda%d: init failed, sa=%b\n", ctlr, 61232523Sbostic udaddr->udasa, udasr_bits); 61333444Sbostic udasaerror(um, 0); 61432523Sbostic return (-1); 61532523Sbostic } 61632523Sbostic 61732523Sbostic /* 61832523Sbostic * Success! Record new state, and start step 1 initialisation. 61932523Sbostic * The rest is done in the interrupt handler. 62032523Sbostic */ 62132523Sbostic sc->sc_state = ST_STEP1; 62232523Sbostic udaddr->udasa = UDA_ERR | (NCMDL2 << 11) | (NRSPL2 << 8) | UDA_IE | 62332523Sbostic (sc->sc_ivec >> 2); 62432523Sbostic return (0); 6254743Swnj } 6264743Swnj 6274743Swnj /* 62832523Sbostic * Open a drive. 6294743Swnj */ 63032523Sbostic /*ARGSUSED*/ 63132523Sbostic udaopen(dev, flag, fmt) 6324743Swnj dev_t dev; 63330773Skarels int flag, fmt; 6344743Swnj { 63532523Sbostic register int unit; 6364743Swnj register struct uba_device *ui; 6374743Swnj register struct uda_softc *sc; 63830536Skarels register struct disklabel *lp; 63930536Skarels register struct partition *pp; 64030916Skarels register struct ra_info *ra; 64132523Sbostic int s, i, part, mask, error = 0; 64230536Skarels daddr_t start, end; 64330536Skarels 64432523Sbostic /* 64532523Sbostic * Make sure this is a reasonable open request. 64632523Sbostic */ 64732523Sbostic unit = udaunit(dev); 64832523Sbostic if (unit >= NRA || (ui = udadinfo[unit]) == 0 || ui->ui_alive == 0) 6498576Sroot return (ENXIO); 65032523Sbostic 65132523Sbostic /* 65232523Sbostic * Make sure the controller is running, by (re)initialising it if 65332523Sbostic * necessary. 65432523Sbostic */ 6554743Swnj sc = &uda_softc[ui->ui_ctlr]; 6565434Sroot s = spl5(); 65732523Sbostic if (sc->sc_state != ST_RUN) { 65832523Sbostic if (sc->sc_state == ST_IDLE && udainit(ui->ui_ctlr)) { 65932523Sbostic splx(s); 6608576Sroot return (EIO); 66117553Skarels } 66232523Sbostic /* 66332523Sbostic * In case it does not come up, make sure we will be 66432523Sbostic * restarted in 10 seconds. This corresponds to the 66532523Sbostic * 10 second timeouts in udaprobe() and udaslave(). 66632523Sbostic */ 66732523Sbostic sc->sc_flags |= SC_DOWAKE; 66832523Sbostic timeout(wakeup, (caddr_t) sc, 10 * hz); 66932523Sbostic sleep((caddr_t) sc, PRIBIO); 67032523Sbostic if (sc->sc_state != ST_RUN) { 67132523Sbostic splx(s); 67232523Sbostic printf("uda%d: controller hung\n", ui->ui_ctlr); 67332523Sbostic return (EIO); 67432523Sbostic } 67532523Sbostic untimeout(wakeup, (caddr_t) sc); 6764743Swnj } 67732523Sbostic 67832523Sbostic /* 67932523Sbostic * Wait for the state to settle 68032523Sbostic */ 68132523Sbostic ra = &ra_info[unit]; 68232523Sbostic while (ra->ra_state != OPEN && ra->ra_state != OPENRAW && 68332523Sbostic ra->ra_state != CLOSED) 68432523Sbostic sleep((caddr_t)ra, PZERO + 1); 68532523Sbostic 68632523Sbostic /* 68732523Sbostic * If not on line, or we are not sure of the label, reinitialise 68832523Sbostic * the drive. 68932523Sbostic */ 69032523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0 || 69132523Sbostic (ra->ra_state != OPEN && ra->ra_state != OPENRAW)) 69232523Sbostic error = uda_rainit(ui, flag); 69330916Skarels splx(s); 69432523Sbostic if (error) 69532523Sbostic return (error); 69630536Skarels 69732523Sbostic part = udapart(dev); 69832523Sbostic lp = &udalabel[unit]; 69930536Skarels if (part >= lp->d_npartitions) 70030536Skarels return (ENXIO); 70130536Skarels /* 70232523Sbostic * Warn if a partition is opened that overlaps another 70332523Sbostic * already open, unless either is the `raw' partition 70432523Sbostic * (whole disk). 70530536Skarels */ 70632523Sbostic #define RAWPART 2 /* 'c' partition */ /* XXX */ 70732523Sbostic mask = 1 << part; 70832523Sbostic if ((ra->ra_openpart & mask) == 0 && part != RAWPART) { 70930536Skarels pp = &lp->d_partitions[part]; 71030536Skarels start = pp->p_offset; 71130536Skarels end = pp->p_offset + pp->p_size; 71232523Sbostic for (pp = lp->d_partitions, i = 0; 71332523Sbostic i < lp->d_npartitions; pp++, i++) { 71430536Skarels if (pp->p_offset + pp->p_size <= start || 71532523Sbostic pp->p_offset >= end || i == RAWPART) 71630536Skarels continue; 71732523Sbostic if (ra->ra_openpart & (1 << i)) 71830536Skarels log(LOG_WARNING, 71930536Skarels "ra%d%c: overlaps open partition (%c)\n", 72032523Sbostic unit, part + 'a', i + 'a'); 72117553Skarels } 72217553Skarels } 72330773Skarels switch (fmt) { 72430773Skarels case S_IFCHR: 72532523Sbostic ra->ra_copenpart |= mask; 72630773Skarels break; 72730773Skarels case S_IFBLK: 72832523Sbostic ra->ra_bopenpart |= mask; 72930773Skarels break; 73030773Skarels } 73132523Sbostic ra->ra_openpart |= mask; 7328576Sroot return (0); 7334743Swnj } 7344743Swnj 73533444Sbostic /* ARGSUSED */ 73633443Skarels /*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 82832523Sbostic * to compute b_cylin (although we do not need it). 82930536Skarels */ 83030916Skarels lp->d_secpercyl = 1; 83130536Skarels lp->d_npartitions = 1; 83230536Skarels lp->d_partitions[0].p_size = lp->d_secperunit; 83330536Skarels lp->d_partitions[0].p_offset = 0; 83432523Sbostic 83530536Skarels /* 83630536Skarels * Read pack label. 83730536Skarels */ 83832523Sbostic if ((msg = readdisklabel(udaminor(unit, 0), udastrategy, lp)) != NULL) { 83934283Skarels if (cold) 84034283Skarels printf(": %s", msg); 84134283Skarels else 84234283Skarels log(LOG_ERR, "ra%d: %s\n", unit, msg); 84330536Skarels #ifdef COMPAT_42 84432523Sbostic if (udamaptype(unit, lp)) 84532523Sbostic ra->ra_state = OPEN; 84630536Skarels else 84732523Sbostic ra->ra_state = OPENRAW; 84831022Skarels #else 84932523Sbostic ra->ra_state = OPENRAW; 85032523Sbostic /* uda_makefakelabel(ra, lp); */ 85130536Skarels #endif 85230773Skarels } else 85332523Sbostic ra->ra_state = OPEN; 85430916Skarels wakeup((caddr_t)ra); 85530916Skarels return (0); 85630536Skarels } 85730536Skarels 85832523Sbostic /* 85932523Sbostic * Copy the geometry information for the given ra from a 86032523Sbostic * GET UNIT STATUS response. If check, see if it changed. 86132523Sbostic */ 86232523Sbostic uda_rasave(unit, mp, check) 86332523Sbostic int unit; 86432523Sbostic register struct mscp *mp; 86532523Sbostic int check; 86632523Sbostic { 86732523Sbostic register struct ra_info *ra = &ra_info[unit]; 86832523Sbostic 86934283Skarels if (check && ra->ra_mediaid != mp->mscp_guse.guse_mediaid) { 87033443Skarels printf("ra%d: changed types! was %d now %d\n", unit, 87134283Skarels ra->ra_mediaid, mp->mscp_guse.guse_mediaid); 87232523Sbostic ra->ra_state = CLOSED; /* ??? */ 87332523Sbostic } 87433444Sbostic /* ra->ra_type = mp->mscp_guse.guse_drivetype; */ 87532523Sbostic ra->ra_mediaid = mp->mscp_guse.guse_mediaid; 87632523Sbostic ra->ra_geom.rg_nsectors = mp->mscp_guse.guse_nspt; 87732523Sbostic ra->ra_geom.rg_ngroups = mp->mscp_guse.guse_group; 87832523Sbostic ra->ra_geom.rg_ngpc = mp->mscp_guse.guse_ngpc; 87932523Sbostic ra->ra_geom.rg_ntracks = ra->ra_geom.rg_ngroups * ra->ra_geom.rg_ngpc; 88032523Sbostic /* ra_geom.rg_ncyl cannot be computed until we have ra_dsize */ 88132523Sbostic #ifdef notyet 88232523Sbostic ra->ra_geom.rg_rctsize = mp->mscp_guse.guse_rctsize; 88332523Sbostic ra->ra_geom.rg_rbns = mp->mscp_guse.guse_nrpt; 88432523Sbostic ra->ra_geom.rg_nrct = mp->mscp_guse.guse_nrct; 88532523Sbostic #endif 88632523Sbostic } 88732523Sbostic 88832523Sbostic /* 88932523Sbostic * Queue a transfer request, and if possible, hand it to the controller. 89032523Sbostic * 89132523Sbostic * This routine is broken into two so that the internal version 89232523Sbostic * udastrat1() can be called by the (nonexistent, as yet) bad block 89332523Sbostic * revectoring routine. 89432523Sbostic */ 89532523Sbostic udastrategy(bp) 8964743Swnj register struct buf *bp; 8974743Swnj { 89832523Sbostic register int unit; 8994743Swnj register struct uba_device *ui; 90032523Sbostic register struct ra_info *ra; 90132523Sbostic struct partition *pp; 90232523Sbostic int p; 9034743Swnj daddr_t sz, maxsz; 9044743Swnj 90532523Sbostic /* 90632523Sbostic * Make sure this is a reasonable drive to use. 90732523Sbostic */ 90832523Sbostic if ((unit = udaunit(bp->b_dev)) >= NRA || 90932523Sbostic (ui = udadinfo[unit]) == NULL || ui->ui_alive == 0 || 91032523Sbostic (ra = &ra_info[unit])->ra_state == CLOSED) { 91124742Sbloom bp->b_error = ENXIO; 9124743Swnj goto bad; 91324742Sbloom } 91432523Sbostic 91532523Sbostic /* 91632523Sbostic * If drive is open `raw' or reading label, let it at it. 91732523Sbostic */ 91832523Sbostic if (ra->ra_state < OPEN) { 91932523Sbostic udastrat1(bp); 92032523Sbostic return; 92124742Sbloom } 92232523Sbostic p = udapart(bp->b_dev); 92333443Skarels if ((ra->ra_openpart & (1 << p)) == 0) { 92433443Skarels bp->b_error = ENODEV; 92533443Skarels goto bad; 92633443Skarels } 92732523Sbostic 92832523Sbostic /* 92932523Sbostic * Determine the size of the transfer, and make sure it is 93032523Sbostic * within the boundaries of the partition. 93132523Sbostic */ 93232523Sbostic pp = &udalabel[unit].d_partitions[p]; 93332523Sbostic maxsz = pp->p_size; 93432523Sbostic if (pp->p_offset + pp->p_size > ra->ra_dsize) 93532523Sbostic maxsz = ra->ra_dsize - pp->p_offset; 93630536Skarels sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 93733443Skarels if (bp->b_blkno + pp->p_offset <= LABELSECTOR && 93833443Skarels #if LABELSECTOR != 0 93933443Skarels bp->b_blkno + pp->p_offset + sz > LABELSECTOR && 94033443Skarels #endif 94133443Skarels (bp->b_flags & B_READ) == 0 && ra->ra_wlabel == 0) { 94233443Skarels bp->b_error = EROFS; 94333443Skarels goto bad; 94433443Skarels } 94530536Skarels if (bp->b_blkno < 0 || bp->b_blkno + sz > maxsz) { 94632523Sbostic /* if exactly at end of disk, return an EOF */ 94724787Skarels if (bp->b_blkno == maxsz) { 94824787Skarels bp->b_resid = bp->b_bcount; 94932523Sbostic biodone(bp); 95032523Sbostic return; 95124787Skarels } 95232523Sbostic /* or truncate if part of it fits */ 95330536Skarels sz = maxsz - bp->b_blkno; 95430536Skarels if (sz <= 0) { 95532523Sbostic bp->b_error = EINVAL; /* or hang it up */ 95630536Skarels goto bad; 95730536Skarels } 95830536Skarels bp->b_bcount = sz << DEV_BSHIFT; 95924742Sbloom } 96032523Sbostic udastrat1(bp); 96132523Sbostic return; 96232523Sbostic bad: 96332523Sbostic bp->b_flags |= B_ERROR; 96432523Sbostic biodone(bp); 96532523Sbostic } 96632523Sbostic 96732523Sbostic /* 96832523Sbostic * Work routine for udastrategy. 96932523Sbostic */ 97032523Sbostic udastrat1(bp) 97132523Sbostic register struct buf *bp; 97232523Sbostic { 97332523Sbostic register int unit = udaunit(bp->b_dev); 97432523Sbostic register struct uba_ctlr *um; 97532523Sbostic register struct buf *dp; 97632523Sbostic struct uba_device *ui; 97732523Sbostic int s = spl5(); 97832523Sbostic 9794743Swnj /* 98032523Sbostic * Append the buffer to the drive queue, and if it is not 98132523Sbostic * already there, the drive to the controller queue. (However, 98232523Sbostic * if the drive queue is marked to be requeued, we must be 98332523Sbostic * awaiting an on line or get unit status command; in this 98432523Sbostic * case, leave it off the controller queue.) 9854743Swnj */ 98632523Sbostic um = (ui = udadinfo[unit])->ui_mi; 98732523Sbostic dp = &udautab[unit]; 98832523Sbostic APPEND(bp, dp, av_forw); 98932523Sbostic if (dp->b_active == 0 && (ui->ui_flags & UNIT_REQUEUE) == 0) { 99032523Sbostic APPEND(dp, &um->um_tab, b_forw); 99132523Sbostic dp->b_active++; 99232523Sbostic } 99332523Sbostic 9944743Swnj /* 99532523Sbostic * Start activity on the controller. Note that unlike other 99632523Sbostic * Unibus drivers, we must always do this, not just when the 99732523Sbostic * controller is not active. 9984743Swnj */ 99932523Sbostic udastart(um); 10005434Sroot splx(s); 10014743Swnj } 10024743Swnj 100332523Sbostic /* 100432523Sbostic * Start up whatever transfers we can find. 100532523Sbostic * Note that udastart() must be called at spl5(). 100632523Sbostic */ 100732523Sbostic udastart(um) 10084743Swnj register struct uba_ctlr *um; 10094743Swnj { 101032523Sbostic register struct uda_softc *sc = &uda_softc[um->um_ctlr]; 10114743Swnj register struct buf *bp, *dp; 10124743Swnj register struct mscp *mp; 101332523Sbostic struct uba_device *ui; 10144743Swnj struct udadevice *udaddr; 101532523Sbostic struct partition *pp; 101632523Sbostic int i, sz; 10174743Swnj 101832523Sbostic #ifdef lint 101932523Sbostic i = 0; i = i; 102032523Sbostic #endif 102132523Sbostic /* 102232523Sbostic * If it is not running, try (again and again...) to initialise 102332523Sbostic * it. If it is currently initialising just ignore it for now. 102432523Sbostic */ 102532523Sbostic if (sc->sc_state != ST_RUN) { 102632523Sbostic if (sc->sc_state == ST_IDLE && udainit(um->um_ctlr)) 102732523Sbostic printf("uda%d: still hung\n", um->um_ctlr); 102832523Sbostic return; 102932523Sbostic } 103032523Sbostic 103132523Sbostic /* 103232523Sbostic * If um_cmd is nonzero, this controller is on the Unibus 103332523Sbostic * resource wait queue. It will not help to try more requests; 103432523Sbostic * instead, when the Unibus unblocks and calls udadgo(), we 103532523Sbostic * will call udastart() again. 103632523Sbostic */ 103732523Sbostic if (um->um_cmd) 103832523Sbostic return; 103932523Sbostic 104032523Sbostic sc->sc_flags |= SC_INSTART; 104132523Sbostic udaddr = (struct udadevice *) um->um_addr; 104232523Sbostic 10434743Swnj loop: 104432523Sbostic /* 104532523Sbostic * Service the drive at the head of the queue. It may not 104632523Sbostic * need anything, in which case it might be shutting down 104732523Sbostic * in udaclose(). 104832523Sbostic */ 104932523Sbostic if ((dp = um->um_tab.b_actf) == NULL) 105032523Sbostic goto out; 10514743Swnj if ((bp = dp->b_actf) == NULL) { 10524743Swnj dp->b_active = 0; 10534743Swnj um->um_tab.b_actf = dp->b_forw; 105432523Sbostic if (ra_info[dp - udautab].ra_openpart == 0) 105532523Sbostic wakeup((caddr_t)dp); /* finish close protocol */ 105632523Sbostic goto loop; 10574743Swnj } 105832523Sbostic 105932523Sbostic if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 106033444Sbostic udasaerror(um, 1); 106132523Sbostic goto out; 10624743Swnj } 106332523Sbostic 106432523Sbostic /* 106532523Sbostic * Get an MSCP packet, then figure out what to do. If 106632523Sbostic * we cannot get a command packet, the command ring may 106732523Sbostic * be too small: We should have at least as many command 106832523Sbostic * packets as credits, for best performance. 106932523Sbostic */ 107032523Sbostic if ((mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT)) == NULL) { 107132523Sbostic if (sc->sc_mi.mi_credits > MSCP_MINCREDITS && 107232523Sbostic (sc->sc_flags & SC_GRIPED) == 0) { 107332523Sbostic log(LOG_NOTICE, "uda%d: command ring too small\n", 107432523Sbostic um->um_ctlr); 107532523Sbostic sc->sc_flags |= SC_GRIPED;/* complain only once */ 107617553Skarels } 107732523Sbostic goto out; 10784743Swnj } 10794743Swnj 108032523Sbostic /* 108132523Sbostic * Bring the drive on line if it is not already. Get its status 108232523Sbostic * if we do not already have it. Otherwise just start the transfer. 108332523Sbostic */ 108432523Sbostic ui = udadinfo[udaunit(bp->b_dev)]; 108532523Sbostic if ((ui->ui_flags & UNIT_ONLINE) == 0) { 108632523Sbostic mp->mscp_opcode = M_OP_ONLINE; 108732523Sbostic goto common; 10884743Swnj } 108932523Sbostic if ((ui->ui_flags & UNIT_HAVESTATUS) == 0) { 109032523Sbostic mp->mscp_opcode = M_OP_GETUNITST; 109132523Sbostic common: 109232523Sbostic if (ui->ui_flags & UNIT_REQUEUE) panic("udastart"); 109332523Sbostic /* 109432523Sbostic * Take the drive off the controller queue. When the 109532523Sbostic * command finishes, make sure the drive is requeued. 109632523Sbostic */ 109732523Sbostic um->um_tab.b_actf = dp->b_forw; 109832523Sbostic dp->b_active = 0; 109932523Sbostic ui->ui_flags |= UNIT_REQUEUE; 110032523Sbostic mp->mscp_unit = ui->ui_slave; 110132523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 110232523Sbostic sc->sc_flags |= SC_STARTPOLL; 110332523Sbostic #ifdef POLLSTATS 110432523Sbostic sc->sc_ncmd++; 110525653Skarels #endif 110632523Sbostic goto loop; 110717553Skarels } 110832523Sbostic 110932523Sbostic pp = &udalabel[ui->ui_unit].d_partitions[udapart(bp->b_dev)]; 111032523Sbostic mp->mscp_opcode = (bp->b_flags & B_READ) ? M_OP_READ : M_OP_WRITE; 11114743Swnj mp->mscp_unit = ui->ui_slave; 111232523Sbostic mp->mscp_seq.seq_lbn = bp->b_blkno + pp->p_offset; 111330536Skarels sz = (bp->b_bcount + DEV_BSIZE - 1) >> DEV_BSHIFT; 111432523Sbostic mp->mscp_seq.seq_bytecount = bp->b_blkno + sz > pp->p_size ? 111532523Sbostic (pp->p_size - bp->b_blkno) >> DEV_BSHIFT : bp->b_bcount; 111632523Sbostic /* mscp_cmdref is filled in by mscp_go() */ 11174743Swnj 11184743Swnj /* 111932523Sbostic * Drop the packet pointer into the `command' field so udadgo() 112032523Sbostic * can tell what to start. If ubago returns 1, we can do another 112132523Sbostic * transfer. If not, um_cmd will still point at mp, so we will 112232523Sbostic * know that we are waiting for resources. 11234743Swnj */ 112432523Sbostic um->um_cmd = (int)mp; 112532523Sbostic if (ubago(ui)) 112632523Sbostic goto loop; 112732523Sbostic 112832523Sbostic /* 112932523Sbostic * All done, or blocked in ubago(). If we managed to 113032523Sbostic * issue some commands, start up the beast. 113132523Sbostic */ 113232523Sbostic out: 113332523Sbostic if (sc->sc_flags & SC_STARTPOLL) { 113432523Sbostic #ifdef POLLSTATS 113532523Sbostic udastats.cmd[sc->sc_ncmd]++; 113632523Sbostic sc->sc_ncmd = 0; 113732523Sbostic #endif 113833444Sbostic i = ((struct udadevice *)um->um_addr)->udaip; 11394743Swnj } 114032523Sbostic sc->sc_flags &= ~(SC_INSTART | SC_STARTPOLL); 114132523Sbostic } 114232523Sbostic 114332523Sbostic /* 114432523Sbostic * Start a transfer. 114532523Sbostic * 114632523Sbostic * If we are not called from within udastart(), we must have been 114732523Sbostic * blocked, so call udastart to do more requests (if any). If 114832523Sbostic * this calls us again immediately we will not recurse, because 114932523Sbostic * that time we will be in udastart(). Clever.... 115032523Sbostic */ 115132523Sbostic udadgo(um) 115232523Sbostic register struct uba_ctlr *um; 115332523Sbostic { 115432523Sbostic struct uda_softc *sc = &uda_softc[um->um_ctlr]; 115532523Sbostic struct mscp *mp = (struct mscp *)um->um_cmd; 115632523Sbostic 115732523Sbostic um->um_tab.b_active++; /* another transfer going */ 115832523Sbostic 11594743Swnj /* 116032523Sbostic * Fill in the MSCP packet and move the buffer to the 116132523Sbostic * I/O wait queue. Mark the controller as no longer on 116232523Sbostic * the resource queue, and remember to initiate polling. 11634743Swnj */ 116432523Sbostic mp->mscp_seq.seq_buffer = (um->um_ubinfo & 0x3ffff) | 116532523Sbostic (UBAI_BDP(um->um_ubinfo) << 24); 116632523Sbostic mscp_go(&sc->sc_mi, mp, um->um_ubinfo); 116732523Sbostic um->um_cmd = 0; 116832523Sbostic um->um_ubinfo = 0; /* tyke it awye */ 116932523Sbostic sc->sc_flags |= SC_STARTPOLL; 117032523Sbostic #ifdef POLLSTATS 117132523Sbostic sc->sc_ncmd++; 117232523Sbostic #endif 117332523Sbostic if ((sc->sc_flags & SC_INSTART) == 0) 117432523Sbostic udastart(um); 11754743Swnj } 11764743Swnj 117732523Sbostic udaiodone(mi, bp, info) 117832523Sbostic register struct mscp_info *mi; 117932523Sbostic struct buf *bp; 118032523Sbostic int info; 118132523Sbostic { 118232523Sbostic register struct uba_ctlr *um = udaminfo[mi->mi_ctlr]; 118332523Sbostic 118432523Sbostic um->um_ubinfo = info; 118532523Sbostic ubadone(um); 118632523Sbostic biodone(bp); 118732523Sbostic if (um->um_bdp && mi->mi_wtab.av_forw == &mi->mi_wtab) 118832523Sbostic ubarelse(um->um_ubanum, &um->um_bdp); 118932523Sbostic um->um_tab.b_active--; /* another transfer done */ 119032523Sbostic } 119132523Sbostic 119233444Sbostic static struct saerr { 119333444Sbostic int code; /* error code (including UDA_ERR) */ 119433444Sbostic char *desc; /* what it means: Efoo => foo error */ 119533444Sbostic } saerr[] = { 119633444Sbostic { 0100001, "Eunibus packet read" }, 119733444Sbostic { 0100002, "Eunibus packet write" }, 119833444Sbostic { 0100003, "EUDA ROM and RAM parity" }, 119933444Sbostic { 0100004, "EUDA RAM parity" }, 120033444Sbostic { 0100005, "EUDA ROM parity" }, 120133444Sbostic { 0100006, "Eunibus ring read" }, 120233444Sbostic { 0100007, "Eunibus ring write" }, 120333444Sbostic { 0100010, " unibus interrupt master failure" }, 120433444Sbostic { 0100011, "Ehost access timeout" }, 120533444Sbostic { 0100012, " host exceeded command limit" }, 120633444Sbostic { 0100013, " unibus bus master failure" }, 120733444Sbostic { 0100014, " DM XFC fatal error" }, 120833444Sbostic { 0100015, " hardware timeout of instruction loop" }, 120933444Sbostic { 0100016, " invalid virtual circuit id" }, 121033444Sbostic { 0100017, "Eunibus interrupt write" }, 121133444Sbostic { 0104000, "Efatal sequence" }, 121233444Sbostic { 0104040, " D proc ALU" }, 121333444Sbostic { 0104041, "ED proc control ROM parity" }, 121433444Sbostic { 0105102, "ED proc w/no BD#2 or RAM parity" }, 121533444Sbostic { 0105105, "ED proc RAM buffer" }, 121633444Sbostic { 0105152, "ED proc SDI" }, 121733444Sbostic { 0105153, "ED proc write mode wrap serdes" }, 121833444Sbostic { 0105154, "ED proc read mode serdes, RSGEN & ECC" }, 121933444Sbostic { 0106040, "EU proc ALU" }, 122033444Sbostic { 0106041, "EU proc control reg" }, 122133444Sbostic { 0106042, " U proc DFAIL/cntl ROM parity/BD #1 test CNT" }, 122233444Sbostic { 0106047, " U proc const PROM err w/D proc running SDI test" }, 122333444Sbostic { 0106055, " unexpected trap" }, 122433444Sbostic { 0106071, "EU proc const PROM" }, 122533444Sbostic { 0106072, "EU proc control ROM parity" }, 122633444Sbostic { 0106200, "Estep 1 data" }, 122733444Sbostic { 0107103, "EU proc RAM parity" }, 122833444Sbostic { 0107107, "EU proc RAM buffer" }, 122933444Sbostic { 0107115, " test count wrong (BD 12)" }, 123033444Sbostic { 0112300, "Estep 2" }, 123133444Sbostic { 0122240, "ENPR" }, 123233444Sbostic { 0122300, "Estep 3" }, 123333444Sbostic { 0142300, "Estep 4" }, 123433444Sbostic { 0, " unknown error code" } 123533444Sbostic }; 123633444Sbostic 12374743Swnj /* 123833444Sbostic * If the error bit was set in the controller status register, gripe, 123933444Sbostic * then (optionally) reset the controller and requeue pending transfers. 12404743Swnj */ 124133444Sbostic udasaerror(um, doreset) 124232523Sbostic register struct uba_ctlr *um; 124333444Sbostic int doreset; 12444743Swnj { 124533444Sbostic register int code = ((struct udadevice *)um->um_addr)->udasa; 124633444Sbostic register struct saerr *e; 124732523Sbostic 124833444Sbostic if ((code & UDA_ERR) == 0) 124933444Sbostic return; 125033444Sbostic for (e = saerr; e->code; e++) 125133444Sbostic if (e->code == code) 125233444Sbostic break; 125333444Sbostic printf("uda%d: controller error, sa=0%o (%s%s)\n", 125433444Sbostic um->um_ctlr, code, e->desc + 1, 125533444Sbostic *e->desc == 'E' ? " error" : ""); 125633444Sbostic if (doreset) { 125733444Sbostic mscp_requeue(&uda_softc[um->um_ctlr].sc_mi); 125833444Sbostic (void) udainit(um->um_ctlr); 125933444Sbostic } 126032523Sbostic } 126132523Sbostic 126232523Sbostic /* 126332523Sbostic * Interrupt routine. Depending on the state of the controller, 126432523Sbostic * continue initialisation, or acknowledge command and response 126532523Sbostic * interrupts, and process responses. 126632523Sbostic */ 126732523Sbostic udaintr(ctlr) 126832523Sbostic int ctlr; 126932523Sbostic { 127032523Sbostic register struct uba_ctlr *um = udaminfo[ctlr]; 127132523Sbostic register struct uda_softc *sc = &uda_softc[ctlr]; 127233444Sbostic register struct udadevice *udaddr = (struct udadevice *)um->um_addr; 127332523Sbostic register struct uda *ud; 127432523Sbostic register struct mscp *mp; 12754743Swnj register int i; 12764743Swnj 127727254Skridle #ifdef VAX630 127832523Sbostic (void) spl5(); /* Qbus interrupt protocol is odd */ 127927254Skridle #endif 128032523Sbostic sc->sc_wticks = 0; /* reset interrupt watchdog */ 128132523Sbostic 128232523Sbostic /* 128332523Sbostic * Combinations during steps 1, 2, and 3: STEPnMASK 128432523Sbostic * corresponds to which bits should be tested; 128532523Sbostic * STEPnGOOD corresponds to the pattern that should 128632523Sbostic * appear after the interrupt from STEPn initialisation. 128732523Sbostic * All steps test the bits in ALLSTEPS. 128832523Sbostic */ 128932523Sbostic #define ALLSTEPS (UDA_ERR|UDA_STEP4|UDA_STEP3|UDA_STEP2|UDA_STEP1) 129032523Sbostic 129132523Sbostic #define STEP1MASK (ALLSTEPS | UDA_IE | UDA_NCNRMASK) 129232523Sbostic #define STEP1GOOD (UDA_STEP2 | UDA_IE | (NCMDL2 << 3) | NRSPL2) 129332523Sbostic 129432523Sbostic #define STEP2MASK (ALLSTEPS | UDA_IE | UDA_IVECMASK) 129532523Sbostic #define STEP2GOOD (UDA_STEP3 | UDA_IE | (sc->sc_ivec >> 2)) 129632523Sbostic 129732523Sbostic #define STEP3MASK ALLSTEPS 129832523Sbostic #define STEP3GOOD UDA_STEP4 129932523Sbostic 13004743Swnj switch (sc->sc_state) { 130132523Sbostic 130232523Sbostic case ST_IDLE: 130332523Sbostic /* 130432523Sbostic * Ignore unsolicited interrupts. 130532523Sbostic */ 130632523Sbostic log(LOG_WARNING, "uda%d: stray intr\n", ctlr); 13074743Swnj return; 13084743Swnj 130932523Sbostic case ST_STEP1: 131032523Sbostic /* 131132523Sbostic * Begin step two initialisation. 131232523Sbostic */ 131332523Sbostic if ((udaddr->udasa & STEP1MASK) != STEP1GOOD) { 131432523Sbostic i = 1; 131532523Sbostic initfailed: 131632523Sbostic printf("uda%d: init step %d failed, sa=%b\n", 131732523Sbostic ctlr, i, udaddr->udasa, udasr_bits); 131833444Sbostic udasaerror(um, 0); 131932523Sbostic sc->sc_state = ST_IDLE; 132032523Sbostic if (sc->sc_flags & SC_DOWAKE) { 132132523Sbostic sc->sc_flags &= ~SC_DOWAKE; 132233444Sbostic wakeup((caddr_t)sc); 132332523Sbostic } 13244743Swnj return; 13254743Swnj } 132633444Sbostic udaddr->udasa = (int)&sc->sc_uda->uda_ca.ca_rspdsc[0] | 132732523Sbostic (cpu == VAX_780 || cpu == VAX_8600 ? UDA_PI : 0); 132832523Sbostic sc->sc_state = ST_STEP2; 13294743Swnj return; 13304743Swnj 133132523Sbostic case ST_STEP2: 133232523Sbostic /* 133332523Sbostic * Begin step 3 initialisation. 133432523Sbostic */ 133532523Sbostic if ((udaddr->udasa & STEP2MASK) != STEP2GOOD) { 133632523Sbostic i = 2; 133732523Sbostic goto initfailed; 13384743Swnj } 133933444Sbostic udaddr->udasa = ((int)&sc->sc_uda->uda_ca.ca_rspdsc[0]) >> 16; 134032523Sbostic sc->sc_state = ST_STEP3; 13414743Swnj return; 13424743Swnj 134332523Sbostic case ST_STEP3: 134432523Sbostic /* 134532523Sbostic * Set controller characteristics (finish initialisation). 134632523Sbostic */ 134732523Sbostic if ((udaddr->udasa & STEP3MASK) != STEP3GOOD) { 134832523Sbostic i = 3; 134932523Sbostic goto initfailed; 13504743Swnj } 135132523Sbostic i = udaddr->udasa & 0xff; 135232523Sbostic if (i != sc->sc_micro) { 135332523Sbostic sc->sc_micro = i; 135432523Sbostic printf("uda%d: version %d model %d\n", 135532523Sbostic ctlr, i & 0xf, i >> 4); 135632523Sbostic } 135732523Sbostic 135817553Skarels /* 135932523Sbostic * Present the burst size, then remove it. Why this 136032523Sbostic * should be done this way, I have no idea. 136132523Sbostic * 136232523Sbostic * Note that this assumes udaburst[ctlr] > 0. 136317553Skarels */ 136432523Sbostic udaddr->udasa = UDA_GO | (udaburst[ctlr] - 1) << 2; 13654743Swnj udaddr->udasa = UDA_GO; 136632523Sbostic printf("uda%d: DMA burst size set to %d\n", 136732523Sbostic ctlr, udaburst[ctlr]); 13684743Swnj 136932523Sbostic udainitds(ctlr); /* initialise data structures */ 137032523Sbostic 13714743Swnj /* 137232523Sbostic * Before we can get a command packet, we need some 137332523Sbostic * credits. Fake some up to keep mscp_getcp() happy, 137432523Sbostic * get a packet, and cancel all credits (the right 137532523Sbostic * number should come back in the response to the 137632523Sbostic * SCC packet). 13774743Swnj */ 137832523Sbostic sc->sc_mi.mi_credits = MSCP_MINCREDITS + 1; 137932523Sbostic mp = mscp_getcp(&sc->sc_mi, MSCP_DONTWAIT); 138032523Sbostic if (mp == NULL) /* `cannot happen' */ 138132523Sbostic panic("udaintr"); 138232523Sbostic sc->sc_mi.mi_credits = 0; 138332523Sbostic mp->mscp_opcode = M_OP_SETCTLRC; 138432523Sbostic mp->mscp_unit = 0; 138532523Sbostic mp->mscp_sccc.sccc_ctlrflags = M_CF_ATTN | M_CF_MISC | 138632523Sbostic M_CF_THIS; 138732523Sbostic *mp->mscp_addr |= MSCP_OWN | MSCP_INT; 138832523Sbostic i = udaddr->udaip; 138932523Sbostic sc->sc_state = ST_SETCHAR; 13904743Swnj return; 13914743Swnj 139232523Sbostic case ST_SETCHAR: 139332523Sbostic case ST_RUN: 139432523Sbostic /* 139532523Sbostic * Handle Set Ctlr Characteristics responses and operational 139632523Sbostic * responses (via mscp_dorsp). 139732523Sbostic */ 13984743Swnj break; 13994743Swnj 14004743Swnj default: 140132523Sbostic printf("uda%d: driver bug, state %d\n", ctlr, sc->sc_state); 140232523Sbostic panic("udastate"); 14034743Swnj } 14044743Swnj 140532523Sbostic if (udaddr->udasa & UDA_ERR) { /* ctlr fatal error */ 140633444Sbostic udasaerror(um, 1); 140732523Sbostic return; 14084743Swnj } 14094743Swnj 141032523Sbostic ud = &uda[ctlr]; 141132523Sbostic 14124743Swnj /* 141332523Sbostic * Handle buffer purge requests. 14144743Swnj */ 14154743Swnj if (ud->uda_ca.ca_bdp) { 141626372Skarels UBAPURGE(um->um_hd->uh_uba, ud->uda_ca.ca_bdp); 14174743Swnj ud->uda_ca.ca_bdp = 0; 141832523Sbostic udaddr->udasa = 0; /* signal purge complete */ 14194743Swnj } 14204743Swnj 14214743Swnj /* 142232523Sbostic * Check for response and command ring transitions. 14234743Swnj */ 14244743Swnj if (ud->uda_ca.ca_rspint) { 14254743Swnj ud->uda_ca.ca_rspint = 0; 142632523Sbostic mscp_dorsp(&sc->sc_mi); 14274743Swnj } 14284743Swnj if (ud->uda_ca.ca_cmdint) { 14294743Swnj ud->uda_ca.ca_cmdint = 0; 143032523Sbostic MSCP_DOCMD(&sc->sc_mi); 14314743Swnj } 143232523Sbostic udastart(um); 14334743Swnj } 14344743Swnj 14354743Swnj /* 143632523Sbostic * Initialise the various data structures that control the UDA50. 143717553Skarels */ 143832523Sbostic udainitds(ctlr) 143932523Sbostic int ctlr; 144032523Sbostic { 144132523Sbostic register struct uda *ud = &uda[ctlr]; 144232523Sbostic register struct uda *uud = uda_softc[ctlr].sc_uda; 144332523Sbostic register struct mscp *mp; 144432523Sbostic register int i; 14454743Swnj 144632523Sbostic for (i = 0, mp = ud->uda_rsp; i < NRSP; i++, mp++) { 144732523Sbostic ud->uda_ca.ca_rspdsc[i] = MSCP_OWN | MSCP_INT | 144832523Sbostic (long)&uud->uda_rsp[i].mscp_cmdref; 144932523Sbostic mp->mscp_addr = &ud->uda_ca.ca_rspdsc[i]; 145032523Sbostic mp->mscp_msglen = MSCP_MSGLEN; 14514743Swnj } 145232523Sbostic for (i = 0, mp = ud->uda_cmd; i < NCMD; i++, mp++) { 145332523Sbostic ud->uda_ca.ca_cmddsc[i] = MSCP_INT | 145432523Sbostic (long)&uud->uda_cmd[i].mscp_cmdref; 145532523Sbostic mp->mscp_addr = &ud->uda_ca.ca_cmddsc[i]; 145632523Sbostic mp->mscp_msglen = MSCP_MSGLEN; 145732523Sbostic } 14584743Swnj } 14594743Swnj 14604743Swnj /* 146133444Sbostic * Handle an error datagram. 14624743Swnj */ 146332523Sbostic udadgram(mi, mp) 146432523Sbostic struct mscp_info *mi; 146532523Sbostic struct mscp *mp; 14664743Swnj { 146717553Skarels 146832523Sbostic mscp_decodeerror(mi->mi_md->md_mname, mi->mi_ctlr, mp); 146933444Sbostic /* 147033444Sbostic * SDI status information bytes 10 and 11 are the microprocessor 147133444Sbostic * error code and front panel code respectively. These vary per 147233444Sbostic * drive type and are printed purely for field service information. 147333444Sbostic */ 147433444Sbostic if (mp->mscp_format == M_FM_SDI) 147533444Sbostic printf("\tsdi uproc error code 0x%x, front panel code 0x%x\n", 147633444Sbostic mp->mscp_erd.erd_sdistat[10], 147733444Sbostic mp->mscp_erd.erd_sdistat[11]); 147832523Sbostic } 147917553Skarels 148032523Sbostic /* 148132523Sbostic * The Set Controller Characteristics command finished. 148232523Sbostic * Record the new state of the controller. 148332523Sbostic */ 148432523Sbostic udactlrdone(mi, mp) 148532523Sbostic register struct mscp_info *mi; 148632523Sbostic struct mscp *mp; 148732523Sbostic { 148832523Sbostic register struct uda_softc *sc = &uda_softc[mi->mi_ctlr]; 148917553Skarels 149032523Sbostic if ((mp->mscp_status & M_ST_MASK) == M_ST_SUCCESS) 149132523Sbostic sc->sc_state = ST_RUN; 149232523Sbostic else { 149332523Sbostic printf("uda%d: SETCTLRC failed: ", 149432523Sbostic mi->mi_ctlr, mp->mscp_status); 149532523Sbostic mscp_printevent(mp); 149632523Sbostic sc->sc_state = ST_IDLE; 14974743Swnj } 149832523Sbostic if (sc->sc_flags & SC_DOWAKE) { 149932523Sbostic sc->sc_flags &= ~SC_DOWAKE; 150032523Sbostic wakeup((caddr_t)sc); 15016964Ssam } 15024743Swnj } 15034743Swnj 15044743Swnj /* 150532523Sbostic * Received a response from an as-yet unconfigured drive. Configure it 150632523Sbostic * in, if possible. 15074743Swnj */ 150832523Sbostic udaunconf(mi, mp) 150932523Sbostic struct mscp_info *mi; 151032523Sbostic register struct mscp *mp; 15114743Swnj { 15124743Swnj 151317553Skarels /* 151432523Sbostic * If it is a slave response, copy it to udaslavereply for 151532523Sbostic * udaslave() to look at. 151617553Skarels */ 151732523Sbostic if (mp->mscp_opcode == (M_OP_GETUNITST | M_OP_END) && 151832523Sbostic (uda_softc[mi->mi_ctlr].sc_flags & SC_INSLAVE) != 0) { 151932523Sbostic udaslavereply = *mp; 152032523Sbostic return (MSCP_DONE); 15214743Swnj } 152232523Sbostic 152332523Sbostic /* 152432523Sbostic * Otherwise, it had better be an available attention response. 152532523Sbostic */ 152632523Sbostic if (mp->mscp_opcode != M_OP_AVAILATTN) 152732523Sbostic return (MSCP_FAILED); 152832523Sbostic 152932523Sbostic /* do what autoconf does */ 153032523Sbostic return (MSCP_FAILED); /* not yet, arwhite, not yet */ 15314743Swnj } 15324743Swnj 153332523Sbostic /* 153432523Sbostic * A drive came on line. Check its type and size. Return DONE if 153532523Sbostic * we think the drive is truly on line. In any case, awaken anyone 153632523Sbostic * sleeping on the drive on-line-ness. 153732523Sbostic */ 153832523Sbostic udaonline(ui, mp) 153932523Sbostic register struct uba_device *ui; 154032523Sbostic struct mscp *mp; 15414743Swnj { 154232523Sbostic register struct ra_info *ra = &ra_info[ui->ui_unit]; 15434743Swnj 154432523Sbostic wakeup((caddr_t)&ui->ui_flags); 154532523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 154632523Sbostic printf("uda%d: attempt to bring ra%d on line failed: ", 154732523Sbostic ui->ui_ctlr, ui->ui_unit); 154832523Sbostic mscp_printevent(mp); 154932523Sbostic ra->ra_state = CLOSED; 155032523Sbostic return (MSCP_FAILED); 155132523Sbostic } 155232523Sbostic 155332523Sbostic ra->ra_state = OPENRAW; 155432523Sbostic ra->ra_dsize = (daddr_t)mp->mscp_onle.onle_unitsize; 155534283Skarels if (!cold) 155634283Skarels printf("ra%d: uda%d, unit %d, size = %d sectors\n", ui->ui_unit, 155734283Skarels ui->ui_ctlr, mp->mscp_unit, ra->ra_dsize); 155832523Sbostic /* can now compute ncyl */ 155932523Sbostic ra->ra_geom.rg_ncyl = ra->ra_dsize / ra->ra_geom.rg_ntracks / 156032523Sbostic ra->ra_geom.rg_nsectors; 156132523Sbostic return (MSCP_DONE); 15624743Swnj } 15634743Swnj 156432523Sbostic /* 156532523Sbostic * We got some (configured) unit's status. Return DONE if it succeeded. 156632523Sbostic */ 156732523Sbostic udagotstatus(ui, mp) 156832523Sbostic register struct uba_device *ui; 156932523Sbostic register struct mscp *mp; 15704743Swnj { 15714743Swnj 157232523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 157332523Sbostic printf("uda%d: attempt to get status for ra%d failed: ", 157432523Sbostic ui->ui_ctlr, ui->ui_unit); 157532523Sbostic mscp_printevent(mp); 157632523Sbostic return (MSCP_FAILED); 157732523Sbostic } 157832523Sbostic /* record for (future) bad block forwarding and whatever else */ 157932523Sbostic uda_rasave(ui->ui_unit, mp, 1); 158032523Sbostic return (MSCP_DONE); 15814743Swnj } 15824743Swnj 158332523Sbostic /* 158432523Sbostic * A transfer failed. We get a chance to fix or restart it. 158532523Sbostic * Need to write the bad block forwaring code first.... 158632523Sbostic */ 158732523Sbostic /*ARGSUSED*/ 158832523Sbostic udaioerror(ui, mp, bp) 158932523Sbostic register struct uba_device *ui; 159032523Sbostic register struct mscp *mp; 159132523Sbostic struct buf *bp; 15924743Swnj { 15934743Swnj 159432523Sbostic if (mp->mscp_flags & M_EF_BBLKR) { 159532523Sbostic /* 159632523Sbostic * A bad block report. Eventually we will 159732523Sbostic * restart this transfer, but for now, just 159832523Sbostic * log it and give up. 159932523Sbostic */ 160032523Sbostic log(LOG_ERR, "ra%d: bad block report: %d%s\n", 160132523Sbostic ui->ui_unit, mp->mscp_seq.seq_lbn, 160232523Sbostic mp->mscp_flags & M_EF_BBLKU ? " + others" : ""); 160332523Sbostic } else { 160432523Sbostic /* 160532523Sbostic * What the heck IS a `serious exception' anyway? 160632523Sbostic * IT SURE WOULD BE NICE IF DEC SOLD DOCUMENTATION 160732523Sbostic * FOR THEIR OWN CONTROLLERS. 160832523Sbostic */ 160932523Sbostic if (mp->mscp_flags & M_EF_SEREX) 161032523Sbostic log(LOG_ERR, "ra%d: serious exception reported\n", 161132523Sbostic ui->ui_unit); 16124743Swnj } 161332523Sbostic return (MSCP_FAILED); 16144743Swnj } 16154743Swnj 161632523Sbostic /* 161732523Sbostic * A replace operation finished. 161832523Sbostic */ 161932523Sbostic /*ARGSUSED*/ 162032523Sbostic udareplace(ui, mp) 162132523Sbostic struct uba_device *ui; 162232523Sbostic struct mscp *mp; 16234743Swnj { 162417553Skarels 162532523Sbostic panic("udareplace"); 16264743Swnj } 162717553Skarels 162832523Sbostic /* 162932523Sbostic * A bad block related operation finished. 163032523Sbostic */ 163132523Sbostic /*ARGSUSED*/ 163232523Sbostic udabb(ui, mp, bp) 163332523Sbostic struct uba_device *ui; 163432523Sbostic struct mscp *mp; 163532523Sbostic struct buf *bp; 163617553Skarels { 163717553Skarels 163832523Sbostic panic("udabb"); 163917553Skarels } 164017553Skarels 164132523Sbostic 164232523Sbostic /* 164332523Sbostic * I/O controls. 164432523Sbostic */ 164532523Sbostic udaioctl(dev, cmd, data, flag) 164612511Ssam dev_t dev; 164730536Skarels int cmd; 164830536Skarels caddr_t data; 164930536Skarels int flag; 165012511Ssam { 165132523Sbostic register int unit = udaunit(dev); 165230536Skarels register struct disklabel *lp; 165333443Skarels register struct ra_info *ra = &ra_info[unit]; 1654*34638Skarels int error = 0; 165512511Ssam 165632523Sbostic lp = &udalabel[unit]; 165730536Skarels 165830536Skarels switch (cmd) { 165930536Skarels 166030536Skarels case DIOCGDINFO: 166130536Skarels *(struct disklabel *)data = *lp; 166230536Skarels break; 166330536Skarels 166430773Skarels case DIOCGPART: 166530773Skarels ((struct partinfo *)data)->disklab = lp; 166630773Skarels ((struct partinfo *)data)->part = 166732523Sbostic &lp->d_partitions[udapart(dev)]; 166830536Skarels break; 166930536Skarels 167030536Skarels case DIOCSDINFO: 167130536Skarels if ((flag & FWRITE) == 0) 167230536Skarels error = EBADF; 167330536Skarels else 167432574Skarels error = setdisklabel(lp, (struct disklabel *)data, 167534283Skarels (ra->ra_state == OPENRAW) ? 0 : ra->ra_openpart); 167630536Skarels break; 167730536Skarels 167833443Skarels case DIOCWLABEL: 167933443Skarels if ((flag & FWRITE) == 0) 168033443Skarels error = EBADF; 168133443Skarels else 168233443Skarels ra->ra_wlabel = *(int *)data; 168333443Skarels break; 168433443Skarels 168532574Skarels case DIOCWDINFO: 168632574Skarels if ((flag & FWRITE) == 0) 168732523Sbostic error = EBADF; 168832574Skarels else if ((error = setdisklabel(lp, (struct disklabel *)data, 168934283Skarels (ra->ra_state == OPENRAW) ? 0 : ra->ra_openpart)) == 0) { 1690*34638Skarels int wlab; 1691*34638Skarels 169234283Skarels ra->ra_state = OPEN; 1693*34638Skarels /* simulate opening partition 0 so write succeeds */ 1694*34638Skarels ra->ra_openpart |= (1 << 0); /* XXX */ 1695*34638Skarels wlab = ra->ra_wlabel; 1696*34638Skarels ra->ra_wlabel = 1; 169732574Skarels error = writedisklabel(dev, udastrategy, lp); 1698*34638Skarels ra->ra_openpart = ra->ra_copenpart | ra->ra_bopenpart; 1699*34638Skarels ra->ra_wlabel = wlab; 170034283Skarels } 170130536Skarels break; 170230536Skarels 170332523Sbostic #ifdef notyet 170432523Sbostic case UDAIOCREPLACE: 170532523Sbostic /* 170632523Sbostic * Initiate bad block replacement for the given LBN. 170732523Sbostic * (Should we allow modifiers?) 170832523Sbostic */ 170932523Sbostic error = EOPNOTSUPP; 171032523Sbostic break; 171132523Sbostic 171232523Sbostic case UDAIOCGMICRO: 171332523Sbostic /* 171432523Sbostic * Return the microcode revision for the UDA50 running 171532523Sbostic * this drive. 171632523Sbostic */ 171733444Sbostic *(int *)data = uda_softc[uddinfo[unit]->ui_ctlr].sc_micro; 171832523Sbostic break; 171932523Sbostic #endif 172032523Sbostic 172130536Skarels default: 172230536Skarels error = ENOTTY; 172330536Skarels break; 172430536Skarels } 172532523Sbostic return (error); 172632523Sbostic } 172732523Sbostic 172832523Sbostic /* 172932523Sbostic * A Unibus reset has occurred on UBA uban. Reinitialise the controller(s) 173032523Sbostic * on that Unibus, and requeue outstanding I/O. 173132523Sbostic */ 173232523Sbostic udareset(uban) 173332523Sbostic int uban; 173432523Sbostic { 173532523Sbostic register struct uba_ctlr *um; 173632523Sbostic register struct uda_softc *sc; 173732523Sbostic register int ctlr; 173832523Sbostic 173932523Sbostic for (ctlr = 0, sc = uda_softc; ctlr < NUDA; ctlr++, sc++) { 174032523Sbostic if ((um = udaminfo[ctlr]) == NULL || um->um_ubanum != uban || 174132523Sbostic um->um_alive == 0) 174232523Sbostic continue; 174332523Sbostic printf(" uda%d", ctlr); 174432523Sbostic 174532523Sbostic /* 174632523Sbostic * Our BDP (if any) is gone; our command (if any) is 174732523Sbostic * flushed; the device is no longer mapped; and the 174832523Sbostic * UDA50 is not yet initialised. 174932523Sbostic */ 175032523Sbostic if (um->um_bdp) { 175132523Sbostic printf("<%d>", UBAI_BDP(um->um_bdp)); 175232523Sbostic um->um_bdp = 0; 175332523Sbostic } 175432523Sbostic um->um_ubinfo = 0; 175532523Sbostic um->um_cmd = 0; 175632523Sbostic sc->sc_flags &= ~SC_MAPPED; 175732523Sbostic sc->sc_state = ST_IDLE; 175832523Sbostic 175932523Sbostic /* reset queues and requeue pending transfers */ 176032523Sbostic mscp_requeue(&sc->sc_mi); 176132523Sbostic 176232523Sbostic /* 176332523Sbostic * If it fails to initialise we will notice later and 176432523Sbostic * try again (and again...). Do not call udastart() 176532523Sbostic * here; it will be done after the controller finishes 176632523Sbostic * initialisation. 176732523Sbostic */ 176832523Sbostic if (udainit(ctlr)) 176932523Sbostic printf(" (hung)"); 177032523Sbostic } 177132523Sbostic } 177232523Sbostic 177332523Sbostic /* 177432523Sbostic * Watchdog timer: If the controller is active, and no interrupts 177532523Sbostic * have occurred for 30 seconds, assume it has gone away. 177632523Sbostic */ 177732523Sbostic udawatch() 177832523Sbostic { 177932523Sbostic register int i; 178032523Sbostic register struct uba_ctlr *um; 178132523Sbostic register struct uda_softc *sc; 178232523Sbostic 178332523Sbostic timeout(udawatch, (caddr_t) 0, hz); /* every second */ 178432523Sbostic for (i = 0, sc = uda_softc; i < NUDA; i++, sc++) { 178532523Sbostic if ((um = udaminfo[i]) == 0 || !um->um_alive) 178632523Sbostic continue; 178732523Sbostic if (sc->sc_state == ST_IDLE) 178832523Sbostic continue; 178932523Sbostic if (sc->sc_state == ST_RUN && !um->um_tab.b_active) 179032523Sbostic sc->sc_wticks = 0; 179132523Sbostic else if (++sc->sc_wticks >= 30) { 179232523Sbostic sc->sc_wticks = 0; 179332523Sbostic printf("uda%d: lost interrupt\n", i); 179432523Sbostic ubareset(um->um_ubanum); 179532523Sbostic } 179632523Sbostic } 179732523Sbostic } 179832523Sbostic 179932523Sbostic /* 180032523Sbostic * Do a panic dump. We set up the controller for one command packet 180132523Sbostic * and one response packet, for which we use `struct uda1'. 180232523Sbostic */ 180332523Sbostic struct uda1 { 180432523Sbostic struct uda1ca uda1_ca; /* communications area */ 180532523Sbostic struct mscp uda1_rsp; /* response packet */ 180632523Sbostic struct mscp uda1_cmd; /* command packet */ 180732523Sbostic } uda1; 180832523Sbostic 180932523Sbostic #define DBSIZE 32 /* dump 16K at a time */ 181032523Sbostic 181132523Sbostic udadump(dev) 181232523Sbostic dev_t dev; 181332523Sbostic { 181432523Sbostic struct udadevice *udaddr; 181532523Sbostic struct uda1 *ud_ubaddr; 181632523Sbostic char *start; 181732523Sbostic int num, blk, unit, maxsz, blkoff, reg; 181832523Sbostic struct partition *pp; 181932523Sbostic register struct uba_regs *uba; 182032523Sbostic register struct uba_device *ui; 182132523Sbostic register struct uda1 *ud; 182232523Sbostic register struct pte *io; 182332523Sbostic register int i; 182432523Sbostic 182532523Sbostic /* 182632523Sbostic * Make sure the device is a reasonable place on which to dump. 182732523Sbostic */ 182832523Sbostic unit = udaunit(dev); 182932523Sbostic if (unit >= NRA) 183032523Sbostic return (ENXIO); 183133444Sbostic #define phys(cast, addr) ((cast) ((int)addr & 0x7fffffff)) 183232523Sbostic ui = phys(struct uba_device *, udadinfo[unit]); 183332523Sbostic if (ui == NULL || ui->ui_alive == 0) 183432523Sbostic return (ENXIO); 183532523Sbostic 183632523Sbostic /* 183732523Sbostic * Find and initialise the UBA; get the physical address of the 183832523Sbostic * device registers, and of communications area and command and 183932523Sbostic * response packet. 184032523Sbostic */ 184132523Sbostic uba = phys(struct uba_hd *, ui->ui_hd)->uh_physuba; 184232523Sbostic ubainit(uba); 184332523Sbostic udaddr = (struct udadevice *)ui->ui_physaddr; 184432523Sbostic ud = phys(struct uda1 *, &uda1); 184532523Sbostic 184632523Sbostic /* 184732523Sbostic * Map the ca+packets into Unibus I/O space so the UDA50 can get 184832523Sbostic * at them. Use the registers at the end of the Unibus map (since 184932523Sbostic * we will use the registers at the beginning to map the memory 185032523Sbostic * we are dumping). 185132523Sbostic */ 185232523Sbostic num = btoc(sizeof(struct uda1)) + 1; 185332523Sbostic reg = NUBMREG - num; 185432523Sbostic io = &uba->uba_map[reg]; 185532523Sbostic for (i = 0; i < num; i++) 185632523Sbostic *(int *)io++ = UBAMR_MRV | (btop(ud) + i); 185732523Sbostic ud_ubaddr = (struct uda1 *)(((int)ud & PGOFSET) | (reg << 9)); 185832523Sbostic 185932523Sbostic /* 186032523Sbostic * Initialise the controller, with one command and one response 186132523Sbostic * packet. 186232523Sbostic */ 186332523Sbostic udaddr->udaip = 0; 186432523Sbostic if (udadumpwait(udaddr, UDA_STEP1)) 186532523Sbostic return (EFAULT); 186632523Sbostic udaddr->udasa = UDA_ERR; 186732523Sbostic if (udadumpwait(udaddr, UDA_STEP2)) 186832523Sbostic return (EFAULT); 186932523Sbostic udaddr->udasa = (int)&ud_ubaddr->uda1_ca.ca_rspdsc; 187032523Sbostic if (udadumpwait(udaddr, UDA_STEP3)) 187132523Sbostic return (EFAULT); 187232523Sbostic udaddr->udasa = ((int)&ud_ubaddr->uda1_ca.ca_rspdsc) >> 16; 187332523Sbostic if (udadumpwait(udaddr, UDA_STEP4)) 187432523Sbostic return (EFAULT); 187532523Sbostic uda_softc[ui->ui_ctlr].sc_micro = udaddr->udasa & 0xff; 187632523Sbostic udaddr->udasa = UDA_GO; 187732523Sbostic 187832523Sbostic /* 187932523Sbostic * Set up the command and response descriptor, then set the 188032523Sbostic * controller characteristics and bring the drive on line. 188132523Sbostic * Note that all uninitialised locations in uda1_cmd are zero. 188232523Sbostic */ 188332523Sbostic ud->uda1_ca.ca_rspdsc = (long)&ud_ubaddr->uda1_rsp.mscp_cmdref; 188432523Sbostic ud->uda1_ca.ca_cmddsc = (long)&ud_ubaddr->uda1_cmd.mscp_cmdref; 188532523Sbostic /* ud->uda1_cmd.mscp_sccc.sccc_ctlrflags = 0; */ 188632523Sbostic /* ud->uda1_cmd.mscp_sccc.sccc_version = 0; */ 188732523Sbostic if (udadumpcmd(M_OP_SETCTLRC, ud, ui)) 188832523Sbostic return (EFAULT); 188932523Sbostic ud->uda1_cmd.mscp_unit = ui->ui_slave; 189032523Sbostic if (udadumpcmd(M_OP_ONLINE, ud, ui)) 189132523Sbostic return (EFAULT); 189232523Sbostic 189332523Sbostic pp = phys(struct partition *, 189432523Sbostic &udalabel[unit].d_partitions[udapart(dev)]); 189532523Sbostic maxsz = pp->p_size; 189632523Sbostic blkoff = pp->p_offset; 189732523Sbostic 189832523Sbostic /* 189932523Sbostic * Dump all of physical memory, or as much as will fit in the 190032523Sbostic * space provided. 190132523Sbostic */ 190232523Sbostic start = 0; 190332523Sbostic num = maxfree; 190432523Sbostic if (dumplo < 0) 190532523Sbostic return (EINVAL); 190632523Sbostic if (dumplo + num >= maxsz) 190732523Sbostic num = maxsz - dumplo; 190832523Sbostic blkoff += dumplo; 190932523Sbostic 191032523Sbostic /* 191132523Sbostic * Write out memory, DBSIZE pages at a time. 191232523Sbostic * N.B.: this code depends on the fact that the sector 191332523Sbostic * size == the page size. 191432523Sbostic */ 191532523Sbostic while (num > 0) { 191632523Sbostic blk = num > DBSIZE ? DBSIZE : num; 191732523Sbostic io = uba->uba_map; 191832523Sbostic /* 191932523Sbostic * Map in the pages to write, leaving an invalid entry 192032523Sbostic * at the end to guard against wild Unibus transfers. 192132523Sbostic * Then do the write. 192232523Sbostic */ 192332523Sbostic for (i = 0; i < blk; i++) 192433444Sbostic *(int *)io++ = UBAMR_MRV | (btop(start) + i); 192533444Sbostic *(int *)io = 0; 192632523Sbostic ud->uda1_cmd.mscp_unit = ui->ui_slave; 192732523Sbostic ud->uda1_cmd.mscp_seq.seq_lbn = btop(start) + blkoff; 192832523Sbostic ud->uda1_cmd.mscp_seq.seq_bytecount = blk << PGSHIFT; 192932523Sbostic if (udadumpcmd(M_OP_WRITE, ud, ui)) 193032523Sbostic return (EIO); 193132523Sbostic start += blk << PGSHIFT; 193232523Sbostic num -= blk; 193332523Sbostic } 193432523Sbostic return (0); /* made it! */ 193532523Sbostic } 193632523Sbostic 193732523Sbostic /* 193832523Sbostic * Wait for some of the bits in `bits' to come on. If the error bit 193932523Sbostic * comes on, or ten seconds pass without response, return true (error). 194032523Sbostic */ 194132523Sbostic udadumpwait(udaddr, bits) 194232523Sbostic register struct udadevice *udaddr; 194332523Sbostic register int bits; 194432523Sbostic { 194532523Sbostic register int timo = todr() + 1000; 194632523Sbostic 194732523Sbostic while ((udaddr->udasa & bits) == 0) { 194832523Sbostic if (udaddr->udasa & UDA_ERR) { 194932523Sbostic printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 195032523Sbostic return (1); 195132523Sbostic } 195232523Sbostic if (todr() >= timo) { 195332523Sbostic printf("timeout\ndump "); 195432523Sbostic return (1); 195532523Sbostic } 195632523Sbostic } 195730536Skarels return (0); 195830536Skarels } 195930536Skarels 196032523Sbostic /* 196132523Sbostic * Feed a command to the UDA50, wait for its response, and return 196232523Sbostic * true iff something went wrong. 196332523Sbostic */ 196432523Sbostic udadumpcmd(op, ud, ui) 196532523Sbostic int op; 196632523Sbostic register struct uda1 *ud; 196732523Sbostic struct uba_device *ui; 196832523Sbostic { 196932523Sbostic register struct udadevice *udaddr; 197032523Sbostic register int n; 197132523Sbostic #define mp (&ud->uda1_rsp) 197232523Sbostic 197333444Sbostic udaddr = (struct udadevice *)ui->ui_physaddr; 197432523Sbostic ud->uda1_cmd.mscp_opcode = op; 197532523Sbostic ud->uda1_cmd.mscp_msglen = MSCP_MSGLEN; 197632523Sbostic ud->uda1_rsp.mscp_msglen = MSCP_MSGLEN; 197732523Sbostic ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 197832523Sbostic ud->uda1_ca.ca_cmddsc |= MSCP_OWN | MSCP_INT; 197932523Sbostic if (udaddr->udasa & UDA_ERR) { 198032523Sbostic printf("udasa=%b\ndump ", udaddr->udasa, udasr_bits); 198132523Sbostic return (1); 198232523Sbostic } 198332523Sbostic n = udaddr->udaip; 198432523Sbostic n = todr() + 1000; 198532523Sbostic for (;;) { 198632523Sbostic if (todr() > n) { 198732523Sbostic printf("timeout\ndump "); 198832523Sbostic return (1); 198932523Sbostic } 199032523Sbostic if (ud->uda1_ca.ca_cmdint) 199132523Sbostic ud->uda1_ca.ca_cmdint = 0; 199232523Sbostic if (ud->uda1_ca.ca_rspint == 0) 199332523Sbostic continue; 199432523Sbostic ud->uda1_ca.ca_rspint = 0; 199532523Sbostic if (mp->mscp_opcode == (op | M_OP_END)) 199632523Sbostic break; 199732523Sbostic printf("\n"); 199832523Sbostic switch (MSCP_MSGTYPE(mp->mscp_msgtc)) { 199932523Sbostic 200032523Sbostic case MSCPT_SEQ: 200132523Sbostic printf("sequential"); 200232523Sbostic break; 200332523Sbostic 200432523Sbostic case MSCPT_DATAGRAM: 200532523Sbostic mscp_decodeerror("uda", ui->ui_ctlr, mp); 200632523Sbostic printf("datagram"); 200732523Sbostic break; 200832523Sbostic 200932523Sbostic case MSCPT_CREDITS: 201032523Sbostic printf("credits"); 201132523Sbostic break; 201232523Sbostic 201332523Sbostic case MSCPT_MAINTENANCE: 201432523Sbostic printf("maintenance"); 201532523Sbostic break; 201632523Sbostic 201732523Sbostic default: 201832523Sbostic printf("unknown (type 0x%x)", 201932523Sbostic MSCP_MSGTYPE(mp->mscp_msgtc)); 202032523Sbostic break; 202132523Sbostic } 202232523Sbostic printf(" ignored\ndump "); 202332523Sbostic ud->uda1_ca.ca_rspdsc |= MSCP_OWN | MSCP_INT; 202432523Sbostic } 202532523Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) { 202632523Sbostic printf("error: op 0x%x => 0x%x status 0x%x\ndump ", op, 202732523Sbostic mp->mscp_opcode, mp->mscp_status); 202832523Sbostic return (1); 202932523Sbostic } 203032523Sbostic return (0); 203132523Sbostic #undef mp 203232523Sbostic } 203332523Sbostic 203432523Sbostic /* 203532523Sbostic * Return the size of a partition, if known, or -1 if not. 203632523Sbostic */ 203732523Sbostic udasize(dev) 203830536Skarels dev_t dev; 203930536Skarels { 204032523Sbostic register int unit = udaunit(dev); 204130536Skarels register struct uba_device *ui; 204230536Skarels 204332523Sbostic if (unit >= NRA || (ui = udadinfo[unit]) == NULL || 204432523Sbostic ui->ui_alive == 0 || (ui->ui_flags & UNIT_ONLINE) == 0 || 204532523Sbostic ra_info[unit].ra_state != OPEN) 204612511Ssam return (-1); 204732523Sbostic return ((int)udalabel[unit].d_partitions[udapart(dev)].p_size); 204812511Ssam } 204917553Skarels 205030536Skarels #ifdef COMPAT_42 205132523Sbostic /* 205232523Sbostic * Tables mapping unlabelled drives. 205332523Sbostic */ 205430536Skarels struct size { 205530536Skarels daddr_t nblocks; 205630536Skarels daddr_t blkoff; 205733444Sbostic } ra60_sizes[8] = { 205830536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 205930536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 206030536Skarels 400176, 0, /* C=sectors 0 thru 400175 */ 206130536Skarels 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 206230536Skarels 268772, 131404, /* 4.2 H => E=sectors 131404 thru 400175 */ 206330536Skarels 350852, 49324, /* F=sectors 49324 thru 400175 */ 206430536Skarels 157570, 242606, /* UCB G => G=sectors 242606 thru 400175 */ 206530536Skarels 193282, 49324, /* UCB H => H=sectors 49324 thru 242605 */ 206633444Sbostic }, ra70_sizes[8] = { 206733444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 206833444Sbostic 33440, 15972, /* B=blk 15972 thru 49323 */ 206933444Sbostic -1, 0, /* C=blk 0 thru end */ 207033444Sbostic 15884, 341220, /* D=blk 341220 thru 357103 */ 207133444Sbostic 55936, 357192, /* E=blk 357192 thru 413127 */ 207233444Sbostic -1, 413457, /* F=blk 413457 thru end */ 207333444Sbostic -1, 341220, /* G=blk 341220 thru end */ 207433444Sbostic 291346, 49731, /* H=blk 49731 thru 341076 */ 207530536Skarels }, ra80_sizes[8] = { 207630536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 207730536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 207830536Skarels 242606, 0, /* C=sectors 0 thru 242605 */ 207930536Skarels 0, 0, /* D=unused */ 208030536Skarels 193282, 49324, /* UCB H => E=sectors 49324 thru 242605 */ 208130536Skarels 82080, 49324, /* 4.2 G => F=sectors 49324 thru 131403 */ 208230536Skarels 192696, 49910, /* G=sectors 49910 thru 242605 */ 208330536Skarels 111202, 131404, /* 4.2 H => H=sectors 131404 thru 242605 */ 208430536Skarels }, ra81_sizes[8] ={ 208533444Sbostic #ifdef MARYLAND 208633444Sbostic #ifdef ENEEVAX 208733444Sbostic 30706, 0, /* A=cyl 0 thru 42 + 2 sectors */ 208833444Sbostic 40696, 30706, /* B=cyl 43 thru 99 - 2 sectors */ 208933444Sbostic -1, 0, /* C=cyl 0 thru 1247 */ 209033444Sbostic -1, 71400, /* D=cyl 100 thru 1247 */ 209133444Sbostic 209233444Sbostic 15884, 0, /* E=blk 0 thru 15883 */ 209333444Sbostic 33440, 15884, /* F=blk 15884 thru 49323 */ 209433444Sbostic 82080, 49324, /* G=blk 49324 thru 131403 */ 209533444Sbostic -1, 131404, /* H=blk 131404 thru end */ 209633444Sbostic #else 209733444Sbostic 67832, 0, /* A=cyl 0 thru 94 + 2 sectors */ 209833444Sbostic 67828, 67832, /* B=cyl 95 thru 189 - 2 sectors */ 209933444Sbostic -1, 0, /* C=cyl 0 thru 1247 */ 210033444Sbostic -1, 135660, /* D=cyl 190 thru 1247 */ 210133444Sbostic 0, 0, 210233444Sbostic 0, 0, 210333444Sbostic 0, 0, 210433444Sbostic 0, 0, 210533444Sbostic #endif ENEEVAX 210633444Sbostic #else 210730536Skarels /* 210830536Skarels * These are the new standard partition sizes for ra81's. 210930536Skarels * An RA_COMPAT system is compiled with D, E, and F corresponding 211030536Skarels * to the 4.2 partitions for G, H, and F respectively. 211130536Skarels */ 211230536Skarels #ifndef UCBRA 211330536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 211430536Skarels 66880, 16422, /* B=sectors 16422 thru 83301 */ 211530536Skarels 891072, 0, /* C=sectors 0 thru 891071 */ 211630536Skarels #ifdef RA_COMPAT 211730536Skarels 82080, 49324, /* 4.2 G => D=sectors 49324 thru 131403 */ 211830536Skarels 759668, 131404, /* 4.2 H => E=sectors 131404 thru 891071 */ 211930536Skarels 478582, 412490, /* 4.2 F => F=sectors 412490 thru 891071 */ 212030536Skarels #else 212130536Skarels 15884, 375564, /* D=sectors 375564 thru 391447 */ 212230536Skarels 307200, 391986, /* E=sectors 391986 thru 699185 */ 212330536Skarels 191352, 699720, /* F=sectors 699720 thru 891071 */ 212430536Skarels #endif RA_COMPAT 212530536Skarels 515508, 375564, /* G=sectors 375564 thru 891071 */ 212630536Skarels 291346, 83538, /* H=sectors 83538 thru 374883 */ 212730536Skarels 212830536Skarels /* 212930536Skarels * These partitions correspond to the sizes used by sites at Berkeley, 213030536Skarels * and by those sites that have received copies of the Berkeley driver 213130536Skarels * with deltas 6.2 or greater (11/15/83). 213230536Skarels */ 213330536Skarels #else UCBRA 213430536Skarels 213530536Skarels 15884, 0, /* A=sectors 0 thru 15883 */ 213630536Skarels 33440, 15884, /* B=sectors 15884 thru 49323 */ 213730536Skarels 891072, 0, /* C=sectors 0 thru 891071 */ 213830536Skarels 15884, 242606, /* D=sectors 242606 thru 258489 */ 213930536Skarels 307200, 258490, /* E=sectors 258490 thru 565689 */ 214030536Skarels 325382, 565690, /* F=sectors 565690 thru 891071 */ 214130536Skarels 648466, 242606, /* G=sectors 242606 thru 891071 */ 214230536Skarels 193282, 49324, /* H=sectors 49324 thru 242605 */ 214330536Skarels 214430536Skarels #endif UCBRA 214533444Sbostic #endif MARYLAND 214633444Sbostic }, ra82_sizes[8] = { 214733444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 214833444Sbostic 66880, 16245, /* B=blk 16245 thru 83124 */ 214933444Sbostic -1, 0, /* C=blk 0 thru end */ 215033444Sbostic 15884, 375345, /* D=blk 375345 thru 391228 */ 215133444Sbostic 307200, 391590, /* E=blk 391590 thru 698789 */ 215233444Sbostic -1, 699390, /* F=blk 699390 thru end */ 215333444Sbostic -1, 375345, /* G=blk 375345 thru end */ 215433444Sbostic 291346, 83790, /* H=blk 83790 thru 375135 */ 215533444Sbostic }, rc25_sizes[8] = { 215633444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 215733444Sbostic 10032, 15884, /* B=blk 15884 thru 49323 */ 215833444Sbostic -1, 0, /* C=blk 0 thru end */ 215933444Sbostic 0, 0, /* D=blk 340670 thru 356553 */ 216033444Sbostic 0, 0, /* E=blk 356554 thru 412489 */ 216133444Sbostic 0, 0, /* F=blk 412490 thru end */ 216233444Sbostic -1, 25916, /* G=blk 49324 thru 131403 */ 216333444Sbostic 0, 0, /* H=blk 131404 thru end */ 216433444Sbostic }, rd52_sizes[8] = { 216533444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 216633444Sbostic 9766, 15884, /* B=blk 15884 thru 25649 */ 216733444Sbostic -1, 0, /* C=blk 0 thru end */ 216833444Sbostic 0, 0, /* D=unused */ 216933444Sbostic 0, 0, /* E=unused */ 217033444Sbostic 0, 0, /* F=unused */ 217133444Sbostic -1, 25650, /* G=blk 25650 thru end */ 217233444Sbostic 0, 0, /* H=unused */ 217333444Sbostic }, rd53_sizes[8] = { 217433444Sbostic 15884, 0, /* A=blk 0 thru 15883 */ 217533444Sbostic 33440, 15884, /* B=blk 15884 thru 49323 */ 217633444Sbostic -1, 0, /* C=blk 0 thru end */ 217733444Sbostic 0, 0, /* D=unused */ 217833444Sbostic 33440, 0, /* E=blk 0 thru 33439 */ 217933444Sbostic -1, 33440, /* F=blk 33440 thru end */ 218033444Sbostic -1, 49324, /* G=blk 49324 thru end */ 218133444Sbostic -1, 15884, /* H=blk 15884 thru end */ 218233444Sbostic }, rx50_sizes[8] = { 218333444Sbostic 800, 0, /* A=blk 0 thru 799 */ 218433444Sbostic 0, 0, 218533444Sbostic -1, 0, /* C=blk 0 thru end */ 218633444Sbostic 0, 0, 218733444Sbostic 0, 0, 218833444Sbostic 0, 0, 218933444Sbostic 0, 0, 219033444Sbostic 0, 0, 219130536Skarels }; 219230536Skarels 219332523Sbostic /* 219433444Sbostic * Media ID decoding table. 219532523Sbostic */ 219632523Sbostic struct udatypes { 219733444Sbostic u_long ut_id; /* media drive ID */ 219832523Sbostic char *ut_name; /* drive type name */ 219932523Sbostic struct size *ut_sizes; /* partition tables */ 220032523Sbostic int ut_nsectors, ut_ntracks, ut_ncylinders; 220132523Sbostic } udatypes[] = { 220233444Sbostic { MSCP_MKDRIVE2('R', 'A', 60), "ra60", ra60_sizes, 42, 4, 2382 }, 220333444Sbostic { MSCP_MKDRIVE2('R', 'A', 70), "ra70", ra70_sizes, 33, 11, 1507 }, 220433444Sbostic { MSCP_MKDRIVE2('R', 'A', 80), "ra80", ra80_sizes, 31, 14, 559 }, 220533444Sbostic { MSCP_MKDRIVE2('R', 'A', 81), "ra81", ra81_sizes, 51, 14, 1248 }, 220633444Sbostic { MSCP_MKDRIVE2('R', 'A', 82), "ra82", ra82_sizes, 57, 14, 1423 }, 220733444Sbostic { MSCP_MKDRIVE2('R', 'C', 25), "rc25-removable", 220833444Sbostic rc25_sizes, 42, 4, 302 }, 220933444Sbostic { MSCP_MKDRIVE3('R', 'C', 'F', 25), "rc25-fixed", 221033444Sbostic rc25_sizes, 42, 4, 302 }, 221133444Sbostic { MSCP_MKDRIVE2('R', 'D', 52), "rd52", rd52_sizes, 18, 7, 480 }, 221233444Sbostic { MSCP_MKDRIVE2('R', 'D', 53), "rd53", rd53_sizes, 18, 8, 963 }, 221333444Sbostic { MSCP_MKDRIVE2('R', 'X', 50), "rx50", rx50_sizes, 10, 1, 80 }, 221433444Sbostic 0 221532523Sbostic }; 221632523Sbostic 221732523Sbostic #define NTYPES (sizeof(udatypes) / sizeof(*udatypes)) 221832523Sbostic 221932523Sbostic udamaptype(unit, lp) 222032523Sbostic int unit; 222130536Skarels register struct disklabel *lp; 222230536Skarels { 222332523Sbostic register struct udatypes *ut; 222432523Sbostic register struct size *sz; 222530536Skarels register struct partition *pp; 222632523Sbostic register char *p; 222732523Sbostic register int i; 222832523Sbostic register struct ra_info *ra = &ra_info[unit]; 222930536Skarels 223032523Sbostic lp->d_secsize = 512; 223132523Sbostic lp->d_secperunit = ra->ra_dsize; 223233444Sbostic i = MSCP_MEDIA_DRIVE(ra->ra_mediaid); 223333444Sbostic for (ut = udatypes; ut->ut_id; ut++) 223433444Sbostic if (ut->ut_id == i) 223533444Sbostic goto found; 223633444Sbostic 223733444Sbostic /* not one we know; fake up a label for the whole drive */ 223833444Sbostic lp->d_nsectors = ra->ra_geom.rg_nsectors; 223933444Sbostic lp->d_ntracks = ra->ra_geom.rg_ntracks; 224033444Sbostic lp->d_ncylinders = ra->ra_geom.rg_ncyl; 224133444Sbostic i = ra->ra_mediaid; /* print the port type too */ 224234283Skarels if (!cold) 224334283Skarels log(LOG_ERR, "ra%d", unit); 224434283Skarels addlog(": don't have a partition table for %c%c %c%c%c%d;\n\ 224534283Skarels using (s,t,c)=(%d,%d,%d)", 224634283Skarels MSCP_MID_CHAR(4, i), MSCP_MID_CHAR(3, i), 224733444Sbostic MSCP_MID_CHAR(2, i), MSCP_MID_CHAR(1, i), 224833444Sbostic MSCP_MID_CHAR(0, i), MSCP_MID_CHAR(0, i), 224933444Sbostic MSCP_MID_NUM(i), lp->d_nsectors, 225033444Sbostic lp->d_ntracks, lp->d_ncylinders); 225134283Skarels if (!cold) 225234283Skarels addlog("\n"); 225333444Sbostic lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 225433444Sbostic lp->d_typename[0] = 'r'; 225533444Sbostic lp->d_typename[1] = 'a'; 225633444Sbostic lp->d_typename[2] = '?'; 225733444Sbostic lp->d_typename[3] = '?'; 225833444Sbostic lp->d_typename[4] = 0; 225933444Sbostic lp->d_npartitions = 1; 226033444Sbostic lp->d_partitions[0].p_offset = 0; 226133444Sbostic lp->d_partitions[0].p_size = lp->d_secperunit; 226233444Sbostic return (0); 226333444Sbostic found: 226432523Sbostic p = ut->ut_name; 226532523Sbostic for (i = 0; i < sizeof(lp->d_typename) - 1 && *p; i++) 226632523Sbostic lp->d_typename[i] = *p++; 226732523Sbostic lp->d_typename[i] = 0; 226832523Sbostic sz = ut->ut_sizes; 226932523Sbostic /* GET nsectors, ntracks, ncylinders FROM SAVED GEOMETRY? */ 227032523Sbostic lp->d_nsectors = ut->ut_nsectors; 227132523Sbostic lp->d_ntracks = ut->ut_ntracks; 227232523Sbostic lp->d_ncylinders = ut->ut_ncylinders; 227330536Skarels lp->d_npartitions = 8; 227430536Skarels lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks; 227532523Sbostic for (pp = lp->d_partitions; pp < &lp->d_partitions[8]; pp++, sz++) { 227632523Sbostic pp->p_offset = sz->blkoff; 227732523Sbostic if ((pp->p_size = sz->nblocks) == (u_long)-1) 227832523Sbostic pp->p_size = ra->ra_dsize - sz->blkoff; 227930536Skarels } 228030536Skarels return (1); 228130536Skarels } 228232523Sbostic #endif /* COMPAT_42 */ 228332523Sbostic #endif /* NUDA > 0 */ 2284