1 /* $NetBSD: iris_scsictl.c,v 1.1 2019/01/12 16:44:47 tsutsui Exp $ */
2
3 /*
4 * Copyright (c) 2018 Naruaki Etomi
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 /*
29 * Silicon Graphics "IRIS" series MIPS processors machine bootloader.
30 * Front end of SCSI commands driver.
31 */
32
33 #include <lib/libsa/stand.h>
34
35 #include "iris_machdep.h"
36 #include "iris_scsivar.h"
37 #include "iris_scsicmd.h"
38
39 int
scsi_test_unit_rdy(void)40 scsi_test_unit_rdy(void)
41 {
42 struct wd33c93_softc *sc = &wd33c93_softc[scsi_ctlr];
43 static struct scsi_cdb6 cdb = { CMD_TEST_UNIT_READY };
44
45 return wd33c93_go(sc, (uint8_t *)&cdb, sizeof(cdb), NULL, NULL);
46 }
47
48 int
scsi_read_capacity(uint8_t * buf,size_t olen)49 scsi_read_capacity(uint8_t *buf, size_t olen)
50 {
51 size_t len = olen;
52 size_t *lenp;
53 lenp = &len;
54 struct wd33c93_softc *sc = &wd33c93_softc[scsi_ctlr];
55 static struct scsi_cdb10 cdb = { CMD_READ_CAPACITY };
56
57 return wd33c93_go(sc, (uint8_t *)&cdb, sizeof(cdb), buf, lenp);
58 }
59
60 int
scsi_read(uint8_t * buf,size_t olen,daddr_t blk,u_int nblk)61 scsi_read(uint8_t *buf, size_t olen, daddr_t blk, u_int nblk)
62 {
63 size_t len = olen;
64 size_t *lenp;
65 lenp = &len;
66 struct wd33c93_softc *sc = &wd33c93_softc[scsi_ctlr];
67 struct scsi_cdb10 cdb;
68
69 memset(&cdb, 0, sizeof(cdb));
70 cdb.cmd = CMD_READ_EXT;
71 cdb.lbah = blk >> 24;
72 cdb.lbahm = blk >> 16;
73 cdb.lbalm = blk >> 8;
74 cdb.lbal = blk;
75 cdb.lenh = nblk >> (8 + DEV_BSHIFT);
76 cdb.lenl = nblk >> DEV_BSHIFT;
77 wd33c93_go(sc, (uint8_t *)&cdb, sizeof(cdb), buf, lenp);
78
79 if (*lenp == olen)
80 return 1;
81
82 return 0;
83 }
84
85 int
scsi_write(uint8_t * buf,size_t olen,daddr_t blk,u_int nblk)86 scsi_write(uint8_t *buf, size_t olen, daddr_t blk, u_int nblk)
87 {
88 size_t len = olen;
89 size_t *lenp;
90 lenp = &len;
91
92 struct wd33c93_softc *sc = &wd33c93_softc[scsi_ctlr];
93 struct scsi_cdb10 cdb;
94
95 memset(&cdb, 0, sizeof(cdb));
96 cdb.cmd = CMD_WRITE_EXT;
97 cdb.lbah = blk >> 24;
98 cdb.lbahm = blk >> 16;
99 cdb.lbalm = blk >> 8;
100 cdb.lbal = blk;
101 cdb.lenh = nblk >> (8 + DEV_BSHIFT);
102 cdb.lenl = nblk >> DEV_BSHIFT;
103 wd33c93_go(sc, (uint8_t *)&cdb, sizeof(cdb), buf, lenp);
104
105 if (*lenp == olen)
106 return 1;
107
108 return 0;
109 }
110