1 /* $NetBSD: ctu.c,v 1.3 2000/05/20 13:30:03 ragge Exp $ */ 2 /* 3 * Copyright (c) 1996 Ludd, University of Lule}, Sweden. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed at Ludd, University of 17 * Lule}, Sweden and its contributors. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * Standalone device driver for 11/750 Console TU58. 35 * It can only handle reads, and doesn't calculate checksum. 36 */ 37 38 #include <sys/param.h> 39 40 #include <lib/libsa/stand.h> 41 42 #include <machine/mtpr.h> 43 #include <machine/rsp.h> 44 45 #include "vaxstand.h" 46 47 static short ctu_cksum(unsigned short *, int); 48 49 enum tu_state { 50 SC_INIT, 51 SC_READY, 52 SC_SEND_CMD, 53 SC_GET_RESP, 54 }; 55 56 volatile struct tu_softc { 57 enum tu_state sc_state; 58 char sc_rsp[15]; /* Should be struct rsb; but don't work */ 59 u_char *sc_xfptr; /* Current char to xfer */ 60 int sc_nbytes; /* Number of bytes to xfer */ 61 int sc_xbytes; /* Number of xfer'd bytes */ 62 int sc_bbytes; /* Number of xfer'd bytes this block */ 63 } tu_sc; 64 65 void ctutintr __P((void)); 66 void cturintr __P((void)); 67 68 int 69 ctuopen(f, adapt, ctlr, unit, part) 70 struct open_file *f; 71 int ctlr, unit, part; 72 { 73 74 tu_sc.sc_state = SC_INIT; 75 76 mtpr(RSP_TYP_INIT, PR_CSTD); 77 cturintr(); 78 tu_sc.sc_state = SC_READY; 79 return 0; 80 81 } 82 83 int 84 ctustrategy(f, func, dblk, size, buf, rsize) 85 void *f; 86 int func; 87 daddr_t dblk; 88 void *buf; 89 size_t size, *rsize; 90 { 91 struct rsp *rsp = (struct rsp *)tu_sc.sc_rsp; 92 93 tu_sc.sc_xfptr = buf; 94 tu_sc.sc_nbytes = size; 95 tu_sc.sc_xbytes = tu_sc.sc_bbytes = 0; 96 97 rsp->rsp_typ = RSP_TYP_COMMAND; 98 rsp->rsp_sz = 012; 99 rsp->rsp_op = RSP_OP_READ; 100 rsp->rsp_mod = 0; 101 rsp->rsp_drv = 0; 102 rsp->rsp_sw = rsp->rsp_xx1 = rsp->rsp_xx2 = 0; 103 rsp->rsp_cnt = tu_sc.sc_nbytes; 104 rsp->rsp_blk = dblk; 105 rsp->rsp_sum = ctu_cksum((u_short *)rsp, 6); 106 tu_sc.sc_state = SC_SEND_CMD; 107 while (tu_sc.sc_state != SC_GET_RESP) 108 ctutintr(); 109 while (tu_sc.sc_state != SC_READY) 110 cturintr(); 111 *rsize = size; 112 return 0; 113 } 114 115 void 116 cturintr() 117 { 118 int status; 119 120 while ((mfpr(PR_CSRS) & 0x80) == 0) 121 ; 122 123 status = mfpr(PR_CSRD); 124 125 switch (tu_sc.sc_state) { 126 127 case SC_INIT: 128 break; 129 130 case SC_GET_RESP: 131 if (tu_sc.sc_xbytes == tu_sc.sc_nbytes) { 132 tu_sc.sc_bbytes++; 133 if (tu_sc.sc_bbytes == 146) 134 tu_sc.sc_state = SC_READY; 135 break; 136 } 137 tu_sc.sc_bbytes++; 138 if (tu_sc.sc_bbytes < 3) /* Data header */ 139 break; 140 if (tu_sc.sc_bbytes == 132) { /* Finished */ 141 tu_sc.sc_bbytes = 0; 142 break; 143 } 144 if (tu_sc.sc_bbytes == 131) /* First checksum */ 145 break; 146 tu_sc.sc_xfptr[tu_sc.sc_xbytes++] = status; 147 break; 148 149 case SC_READY: 150 case SC_SEND_CMD: 151 break; 152 } 153 154 } 155 156 void 157 ctutintr() 158 { 159 int c; 160 161 while ((mfpr(PR_CSTS) & 0x80) == 0) 162 ; 163 164 c = tu_sc.sc_rsp[tu_sc.sc_xbytes++] & 0xff; 165 mtpr(c, PR_CSTD); 166 if (tu_sc.sc_xbytes > 13) { 167 tu_sc.sc_state = SC_GET_RESP; 168 tu_sc.sc_xbytes = 0; 169 } 170 } 171 172 short 173 ctu_cksum(buf, words) 174 unsigned short *buf; 175 int words; 176 { 177 int i, cksum; 178 179 for (i = cksum = 0; i < words; i++) 180 cksum += buf[i]; 181 182 hej: if (cksum > 65535) { 183 cksum = (cksum & 65535) + (cksum >> 16); 184 goto hej; 185 } 186 return cksum; 187 } 188