jcs's openbsd hax
openbsd

pull in atascsi, a scsi to ata translation layer, so i can work on it in tree. ive lost two large changes today thanks to my own stupidity which could have been avoided if they were in the tree.

discussed with deraadt@

ok jsg@ grange@ an older version was ok marco@

dlg ad254ea8 90fdc30c

+199 -2
+2 -1
sys/conf/files
··· 1 - # $OpenBSD: files,v 1.392 2006/12/06 20:07:52 martin Exp $ 1 + # $OpenBSD: files,v 1.393 2007/02/19 11:44:24 dlg Exp $ 2 2 # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ 3 3 4 4 # @(#)files.newconf 7.5 (Berkeley) 5/10/93 ··· 11 11 define tty 12 12 define audio {} 13 13 define scsi {} 14 + define atascsi {} 14 15 define ifmedia 15 16 define mii {[phy = -1]} 16 17 define midibus {}
+134
sys/dev/ata/atascsi.c
··· 1 + /* $OpenBSD: atascsi.c,v 1.1 2007/02/19 11:44:24 dlg Exp $ */ 2 + 3 + /* 4 + * Copyright (c) 2007 David Gwynne <dlg@openbsd.org> 5 + * 6 + * Permission to use, copy, modify, and distribute this software for any 7 + * purpose with or without fee is hereby granted, provided that the above 8 + * copyright notice and this permission notice appear in all copies. 9 + * 10 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 + */ 18 + 19 + #include <sys/param.h> 20 + #include <sys/systm.h> 21 + #include <sys/buf.h> 22 + #include <sys/kernel.h> 23 + #include <sys/malloc.h> 24 + #include <sys/device.h> 25 + #include <sys/proc.h> 26 + #include <sys/queue.h> 27 + 28 + #include <scsi/scsi_all.h> 29 + #include <scsi/scsiconf.h> 30 + 31 + #include <dev/ata/atascsi.h> 32 + 33 + struct atascsi { 34 + struct device *ab_dev; 35 + void *ab_cookie; 36 + 37 + int *ab_ports; 38 + 39 + struct atascsi_methods *ab_methods; 40 + struct scsi_adapter ab_switch; 41 + struct scsi_link ab_link; 42 + struct scsibus_softc *ab_scsibus; 43 + }; 44 + 45 + int atascsi_probe(struct atascsi *, int); 46 + 47 + int atascsi_cmd(struct scsi_xfer *); 48 + 49 + /* template */ 50 + struct scsi_adapter atascsi_switch = { 51 + atascsi_cmd, /* scsi_cmd */ 52 + minphys, /* scsi_minphys */ 53 + NULL, 54 + NULL, 55 + NULL /* ioctl */ 56 + }; 57 + 58 + struct scsi_device atascsi_device = { 59 + NULL, NULL, NULL, NULL 60 + }; 61 + 62 + struct atascsi * 63 + atascsi_attach(struct device *self, struct atascsi_attach_args *aaa) 64 + { 65 + struct scsibus_attach_args saa; 66 + struct atascsi *ab; 67 + int i; 68 + 69 + ab = malloc(sizeof(struct atascsi), M_DEVBUF, M_WAITOK); 70 + bzero(ab, sizeof(struct atascsi)); 71 + 72 + ab->ab_dev = self; 73 + ab->ab_cookie = aaa->aaa_cookie; 74 + ab->ab_methods = aaa->aaa_methods; 75 + 76 + /* copy from template and modify for ourselves */ 77 + ab->ab_switch = atascsi_switch; 78 + ab->ab_switch.scsi_minphys = aaa->aaa_minphys; 79 + 80 + /* fill in our scsi_link */ 81 + ab->ab_link.device = &atascsi_device; 82 + ab->ab_link.adapter = &ab->ab_switch; 83 + ab->ab_link.adapter_softc = ab; 84 + ab->ab_link.adapter_buswidth = aaa->aaa_nports; 85 + ab->ab_link.luns = 1; /* XXX port multiplier as luns */ 86 + ab->ab_link.adapter_target = aaa->aaa_nports; 87 + ab->ab_link.openings = aaa->aaa_ncmds; 88 + 89 + ab->ab_ports = malloc(sizeof(int) * aaa->aaa_nports, 90 + M_DEVBUF, M_WAITOK); 91 + bzero(ab->ab_ports, sizeof(int) * aaa->aaa_nports); 92 + 93 + /* fill in the port array with the type of devices there */ 94 + for (i = 0; i < ab->ab_link.adapter_buswidth; i++) 95 + atascsi_probe(ab, i); 96 + 97 + bzero(&saa, sizeof(saa)); 98 + saa.saa_sc_link = &ab->ab_link; 99 + 100 + /* stash the scsibus so we can do hotplug on it */ 101 + ab->ab_scsibus = (struct scsibus_softc *)config_found(self, &saa, 102 + scsiprint); 103 + 104 + return (ab); 105 + } 106 + 107 + int 108 + atascsi_detach(struct atascsi *ab) 109 + { 110 + return (0); 111 + } 112 + 113 + int 114 + atascsi_probe(struct atascsi *ab, int port) 115 + { 116 + if (port > ab->ab_link.adapter_buswidth) 117 + return (ENXIO); 118 + 119 + ab->ab_ports[port] = ab->ab_methods->probe(ab->ab_cookie, port); 120 + 121 + return (0); 122 + } 123 + 124 + int 125 + atascsi_cmd(struct scsi_xfer *xs) 126 + { 127 + int s; 128 + 129 + xs->error = XS_DRIVER_STUFFUP; 130 + s = splbio(); 131 + scsi_done(xs); 132 + splx(s); 133 + return (COMPLETE); 134 + }
+60
sys/dev/ata/atascsi.h
··· 1 + /* $OpenBSD: atascsi.h,v 1.1 2007/02/19 11:44:24 dlg Exp $ */ 2 + 3 + /* 4 + * Copyright (c) 2007 David Gwynne <dlg@openbsd.org> 5 + * 6 + * Permission to use, copy, modify, and distribute this software for any 7 + * purpose with or without fee is hereby granted, provided that the above 8 + * copyright notice and this permission notice appear in all copies. 9 + * 10 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 + */ 18 + 19 + struct atascsi; 20 + struct ata_xfer; 21 + 22 + struct atascsi_methods { 23 + int (*probe)(void *, int); 24 + int (*ata_cmd)(void *, struct ata_xfer *); 25 + }; 26 + 27 + struct atascsi_attach_args { 28 + void *aaa_cookie; 29 + 30 + struct atascsi_methods *aaa_methods; 31 + void (*aaa_minphys)(struct buf *); 32 + int aaa_nports; 33 + int aaa_ncmds; 34 + }; 35 + 36 + struct atascsi_port { 37 + int ap_type; 38 + #define ATABUS_PORT_T_NONE 0 39 + #define ATABUS_PORT_T_DISK 1 40 + #define ATABUS_PORT_T_ATAPI 2 41 + }; 42 + 43 + struct ata_xfer { 44 + int port; 45 + 46 + int flags; 47 + #define ATA_F_POLL (1<<0) 48 + #define ATA_F_NOSLEEP (1<<1) 49 + 50 + u_int8_t *cmd; 51 + 52 + u_int8_t *data; 53 + size_t datalen; 54 + }; 55 + 56 + struct atascsi *atascsi_attach(struct device *, struct atascsi_attach_args *); 57 + int atascsi_detach(struct atascsi *); 58 + 59 + int atascsi_probe_dev(struct atascsi *, int); 60 + int atascsi_detach_dev(struct atascsi *, int);
+3 -1
sys/dev/ata/files.ata
··· 1 - # $OpenBSD: files.ata,v 1.2 2002/12/23 02:37:38 grange Exp $ 1 + # $OpenBSD: files.ata,v 1.3 2007/02/19 11:44:24 dlg Exp $ 2 2 # $NetBSD: files.ata,v 1.3 1998/10/12 16:09:16 bouyer Exp $ 3 3 # 4 4 # Config file and device description for machine-independent devices ··· 13 13 file dev/ata/ata_wdc.c wd & wdc_base 14 14 15 15 file dev/ata/ata.c (ata | atapi) & wdc_base 16 + 17 + file dev/ata/atascsi.c atascsi