133519Sbostic /* 233519Sbostic * Copyright (c) 1988 Regents of the University of California. 333519Sbostic * All rights reserved. 433519Sbostic * 533519Sbostic * Redistribution and use in source and binary forms are permitted 633519Sbostic * provided that this notice is preserved and that due credit is given 733519Sbostic * to the University of California at Berkeley. The name of the University 833519Sbostic * may not be used to endorse or promote products derived from this 933519Sbostic * software without specific prior written permission. This software 1033519Sbostic * is provided ``as is'' without express or implied warranty. 1133519Sbostic * 12*34460Sbostic * @(#)kdb.c 7.2 (Berkeley) 05/24/88 1333519Sbostic */ 1433519Sbostic 1533519Sbostic /* 1633519Sbostic * KDB50/RAxx disk device driver 1733519Sbostic */ 1833519Sbostic #include "../machine/pte.h" 1933519Sbostic 2033519Sbostic #include "param.h" 2133519Sbostic #include "inode.h" 2233519Sbostic #include "fs.h" 2333519Sbostic #include "disklabel.h" 2433519Sbostic 2533519Sbostic #include "saio.h" 2633519Sbostic #include "savax.h" 2733519Sbostic 2833519Sbostic #define NKRA 8 /* max unit number on ctlr */ 2933519Sbostic #define SECTSIZ 512 /* sector size in bytes */ 3033519Sbostic 3133519Sbostic /* 3233519Sbostic * Parameters for the communications area 3333519Sbostic */ 3433519Sbostic #define NRSP 1 3533519Sbostic #define NCMD 1 3633519Sbostic 37*34460Sbostic #include "../vaxbi/bireg.h" 38*34460Sbostic #include "../vaxbi/kdbreg.h" 3933519Sbostic #include "../vax/mscp.h" 4033519Sbostic 4133519Sbostic struct kdb { 4233519Sbostic struct kdbca kdb_ca; 4333519Sbostic struct mscp kdb_rsp; 4433519Sbostic struct mscp kdb_cmd; 4533519Sbostic } kdb; 4633519Sbostic 4733519Sbostic int kdbinit[MAXNKDB]; 4833519Sbostic char kratype[MAXNKDB * NKRA]; 4933519Sbostic struct disklabel kralabel[MAXNUBA * NKRA]; 5033519Sbostic char lbuf[SECTSIZ]; 5133519Sbostic 5233519Sbostic kraopen(io) 5333519Sbostic register struct iob *io; 5433519Sbostic { 5533519Sbostic register struct mscp *mp; 5633519Sbostic register struct kdb_regs *kr; 5733519Sbostic register struct disklabel *lp; 5833519Sbostic register int i, unit; 5933519Sbostic daddr_t off; 6033519Sbostic 61*34460Sbostic if ((i = io->i_unit) >= nkdb) 62*34460Sbostic return (EUNIT); 6333519Sbostic kr = (struct kdb_regs *)kdbaddr[i]; 6433519Sbostic if (kdbinit[i] == 0) { 6533519Sbostic kr->kdb_bi.bi_csr |= BICSR_NRST; 6633519Sbostic DELAY(10000); /* ??? */ 6733519Sbostic /* clear any bus errors */ 6833519Sbostic kr->kdb_bi.bi_ber = ~(BIBER_MBZ|BIBER_NMR|BIBER_UPEN); 6933519Sbostic while ((kr->kdb_sa & KDB_STEP1) == 0) 7033519Sbostic ; 7133519Sbostic kr->kdb_bi.bi_bcicsr |= BCI_STOPEN | BCI_IDENTEN; 7233519Sbostic kr->kdb_sw = KDB_ERR; 7333519Sbostic while ((kr->kdb_sa & KDB_STEP2) == 0) 7433519Sbostic ; 7533519Sbostic kr->kdb_sw = (int)&kdb.kdb_ca.ca_rspdsc[0]; 7633519Sbostic while ((kr->kdb_sa & KDB_STEP3) == 0) 7733519Sbostic ; 7833519Sbostic kr->kdb_sw = (int)&kdb.kdb_ca.ca_rspdsc[0] >> 16; 7933519Sbostic while ((kr->kdb_sa & KDB_STEP4) == 0) 8033519Sbostic ; 8133519Sbostic kr->kdb_sw = KDB_GO; 8233519Sbostic kdb.kdb_ca.ca_rspdsc[0] = (long)&kdb.kdb_rsp.mscp_cmdref; 8333519Sbostic kdb.kdb_ca.ca_cmddsc[0] = (long)&kdb.kdb_cmd.mscp_cmdref; 8433519Sbostic if (kdbcmd(kr, M_OP_SETCTLRC)) { 8533519Sbostic printf("open error, SETCTLRC"); 8633519Sbostic return (EIO); 8733519Sbostic } 8833519Sbostic kdbinit[i] = 1; 8933519Sbostic } 9033519Sbostic unit = io->i_unit; 9133519Sbostic lp = &kralabel[unit]; 9233519Sbostic if (kratype[unit] == 0) { 9333519Sbostic struct iob tio; 9433519Sbostic 9533519Sbostic kdb.kdb_cmd.mscp_unit = UNITTODRIVE(unit); 9633519Sbostic if (kdbcmd(kr, M_OP_ONLINE)) { 9733519Sbostic printf("open error, ONLINE"); 9833519Sbostic return (EIO); 9933519Sbostic } 10033519Sbostic kratype[unit] = kdb.kdb_rsp.mscp_onle.onle_drivetype; 10133519Sbostic tio = *io; 10233519Sbostic tio.i_bn = LABELSECTOR; 10333519Sbostic tio.i_ma = lbuf; 10433519Sbostic tio.i_cc = SECTSIZ; 10533519Sbostic tio.i_flgs |= F_RDDATA; 106*34460Sbostic if (krastrategy(&tio, READ) != SECTSIZ) 107*34460Sbostic return (ERDLAB); 10833519Sbostic *lp = *(struct disklabel *)(lbuf + LABELOFFSET); 109*34460Sbostic if (lp->d_magic != DISKMAGIC || lp->d_magic2 != DISKMAGIC) 110*34460Sbostic #ifdef COMPAT_42 111*34460Sbostic { 11233519Sbostic printf("kra%d: unlabeled\n", unit); 11333519Sbostic kramaptype(io, lp); 114*34460Sbostic } 11533519Sbostic #else 116*34460Sbostic return (EUNLAB); 11733519Sbostic #endif 11833519Sbostic } 119*34460Sbostic if ((unsigned)io->i_part >= lp->d_npartitions || 120*34460Sbostic (io->i_boff = lp->d_partitions[io->i_part].p_offset) == -1) 121*34460Sbostic return (EPART); 12233519Sbostic return (0); 12333519Sbostic } 12433519Sbostic 12533519Sbostic kdbcmd(kr, op) 12633519Sbostic struct kdb_regs *kr; 12733519Sbostic int op; 12833519Sbostic { 12933519Sbostic register struct kdb *k = &kdb; 13033519Sbostic register struct mscp *mp; 13133519Sbostic int i; 13233519Sbostic 13333519Sbostic k->kdb_cmd.mscp_opcode = op; 13433519Sbostic k->kdb_rsp.mscp_msglen = MSCP_MSGLEN; 13533519Sbostic k->kdb_cmd.mscp_msglen = MSCP_MSGLEN; 13633519Sbostic k->kdb_ca.ca_rspdsc[0] |= MSCP_OWN | MSCP_INT; 13733519Sbostic k->kdb_ca.ca_cmddsc[0] |= MSCP_OWN | MSCP_INT; 13833519Sbostic i = kr->kdb_ip; 13933519Sbostic mp = &k->kdb_rsp; 14033519Sbostic for (;;) { 14133519Sbostic if (k->kdb_ca.ca_cmdint) 14233519Sbostic k->kdb_ca.ca_cmdint = 0; 14333519Sbostic if (k->kdb_ca.ca_rspint == 0) 14433519Sbostic continue; 14533519Sbostic k->kdb_ca.ca_rspint = 0; 14633519Sbostic if (mp->mscp_opcode == (op | M_OP_END)) 14733519Sbostic break; 14833519Sbostic printf("unexpected rsp type %x op %x ignored\n", 14933519Sbostic MSCP_MSGTYPE(mp->mscp_msgtc), mp->mscp_opcode); 15033519Sbostic } 15133519Sbostic if ((mp->mscp_status & M_ST_MASK) != M_ST_SUCCESS) 15233519Sbostic return (-1); 15333519Sbostic return (0); 15433519Sbostic } 15533519Sbostic 15633519Sbostic krastrategy(io, func) 15733519Sbostic register struct iob *io; 15833519Sbostic { 15933519Sbostic register struct mscp *mp; 16033519Sbostic 16133519Sbostic mp = &kdb.kdb_cmd; 16233519Sbostic mp->mscp_unit = io->i_unit & 7; 16333519Sbostic mp->mscp_seq.seq_lbn = io->i_bn; 16433519Sbostic mp->mscp_seq.seq_bytecount = io->i_cc; 16533519Sbostic mp->mscp_seq.seq_buffer = (long)io->i_ma | KDB_PHYS; 16633519Sbostic if (kdbcmd((struct kdb_regs *)kdbaddr[io->i_unit >> 3], 16733519Sbostic func == READ ? M_OP_READ : M_OP_WRITE)) { 16833519Sbostic printf("kra: I/O error\n"); 16933519Sbostic return (-1); 17033519Sbostic } 17133519Sbostic return (io->i_cc); 17233519Sbostic } 17333519Sbostic 17433519Sbostic #ifdef COMPAT_42 17533519Sbostic u_long kra25_off[] = { 0, 15884, 0, -1, -1, -1, 25916, -1 }; 17633519Sbostic u_long kra60_off[] = { 0, 15884, 0, 49324, 131404, 49324, 242606, 49324 }; 17733519Sbostic u_long kra80_off[] = { 0, 15884, 0, -1, 49324, 49324, 49910, 131404 }; 17833519Sbostic u_long kra81_off[] = { 0, 15884, 0, 131404, 49324, 498790, 563050, 131404 }; 17933519Sbostic u_long *kra_off[] = { 18033519Sbostic 0, 18133519Sbostic kra80_off, /* 1 = ra80 */ 18233519Sbostic kra25_off, /* 2 = rc25-r */ 18333519Sbostic kra25_off, /* 3 = rc25-r */ 18433519Sbostic kra60_off, /* 4 = ra60 */ 18533519Sbostic kra81_off, /* 5 = ra81 */ 18633519Sbostic }; 18733519Sbostic #define NOFFS (sizeof(kra_off) / sizeof(kra_off[0])) 18833519Sbostic 18933519Sbostic kramaptype(io, lp) 19033519Sbostic register struct iob *io; 19133519Sbostic register struct disklabel *lp; 19233519Sbostic { 19333519Sbostic register struct partition *pp; 19433519Sbostic register u_int i; 19533519Sbostic register u_long *off; 19633519Sbostic 19733519Sbostic if ((i = kratype[io->i_unit]) >= NOFFS || (off = kra_off[i]) == 0) { 19833519Sbostic printf("kra%d: type %d unsupported\n", io->i_unit, i); 19933519Sbostic lp->d_npartitions = 0; 20033519Sbostic return; 20133519Sbostic } 20233519Sbostic lp->d_npartitions = 8; 20333519Sbostic for (pp = lp->d_partitions, i = 0; i < 8; pp++, i++) 20433519Sbostic pp->p_offset = *off++; 20533519Sbostic } 20633519Sbostic #endif 207