1/* 2 * Product specific probe and attach routines for: 3 * Buslogic BT-54X and BT-445 cards 4 * 5 * Copyright (c) 1998, 1999 Justin T. Gibbs 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions, and the following disclaimer, 13 * without modification, immediately at the beginning of the file. 14 * 2. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 *
| 1/* 2 * Product specific probe and attach routines for: 3 * Buslogic BT-54X and BT-445 cards 4 * 5 * Copyright (c) 1998, 1999 Justin T. Gibbs 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions, and the following disclaimer, 13 * without modification, immediately at the beginning of the file. 14 * 2. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 *
|
29 * $Id: bt_isa.c,v 1.7 1999/04/06 21:15:18 phk Exp $
| 29 * $Id: bt_isa.c,v 1.8 1999/04/18 15:50:35 peter Exp $
|
30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36#include <sys/bus.h> 37 38#include <machine/bus_pio.h> 39#include <machine/bus.h> 40#include <machine/resource.h> 41#include <sys/rman.h> 42 43#include <isa/isavar.h> 44#include <i386/isa/isa_dma.h> 45#include <dev/buslogic/btreg.h> 46 47#include <cam/scsi/scsi_all.h> 48 49static bus_dma_filter_t btvlbouncefilter; 50static bus_dmamap_callback_t btmapsensebuffers; 51 52static int 53bt_isa_alloc_resources(device_t dev) 54{ 55 int rid; 56 struct resource *port; 57 struct resource *irq; 58 struct resource *drq; 59 60 rid = 0; 61 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 62 0, ~0, 1, RF_ACTIVE); 63 if (!port) 64 return (ENOMEM); 65 66 if (isa_get_irq(dev) != -1) { 67 rid = 0; 68 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 69 0, ~0, 1, RF_ACTIVE); 70 if (!irq) { 71 if (port) 72 bus_release_resource(dev, SYS_RES_IOPORT, 73 0, port); 74 return (ENOMEM); 75 } 76 } else 77 irq = 0; 78 79 if (isa_get_drq(dev) != -1) { 80 rid = 0; 81 drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid, 82 0, ~0, 1, RF_ACTIVE); 83 if (!drq) { 84 if (port) 85 bus_release_resource(dev, SYS_RES_IOPORT, 86 0, port); 87 if (irq) 88 bus_release_resource(dev, SYS_RES_IRQ, 89 0, irq); 90 return (ENOMEM); 91 } 92 } else 93 drq = 0; 94 95 bt_init_softc(dev, port, irq, drq); 96 97 return (0); 98} 99 100static void 101bt_isa_release_resources(device_t dev) 102{ 103 struct bt_softc *bt = device_get_softc(dev); 104 105 if (bt->port) 106 bus_release_resource(dev, SYS_RES_IOPORT, 0, bt->port); 107 if (bt->irq)
| 30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> 35#include <sys/module.h> 36#include <sys/bus.h> 37 38#include <machine/bus_pio.h> 39#include <machine/bus.h> 40#include <machine/resource.h> 41#include <sys/rman.h> 42 43#include <isa/isavar.h> 44#include <i386/isa/isa_dma.h> 45#include <dev/buslogic/btreg.h> 46 47#include <cam/scsi/scsi_all.h> 48 49static bus_dma_filter_t btvlbouncefilter; 50static bus_dmamap_callback_t btmapsensebuffers; 51 52static int 53bt_isa_alloc_resources(device_t dev) 54{ 55 int rid; 56 struct resource *port; 57 struct resource *irq; 58 struct resource *drq; 59 60 rid = 0; 61 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 62 0, ~0, 1, RF_ACTIVE); 63 if (!port) 64 return (ENOMEM); 65 66 if (isa_get_irq(dev) != -1) { 67 rid = 0; 68 irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 69 0, ~0, 1, RF_ACTIVE); 70 if (!irq) { 71 if (port) 72 bus_release_resource(dev, SYS_RES_IOPORT, 73 0, port); 74 return (ENOMEM); 75 } 76 } else 77 irq = 0; 78 79 if (isa_get_drq(dev) != -1) { 80 rid = 0; 81 drq = bus_alloc_resource(dev, SYS_RES_DRQ, &rid, 82 0, ~0, 1, RF_ACTIVE); 83 if (!drq) { 84 if (port) 85 bus_release_resource(dev, SYS_RES_IOPORT, 86 0, port); 87 if (irq) 88 bus_release_resource(dev, SYS_RES_IRQ, 89 0, irq); 90 return (ENOMEM); 91 } 92 } else 93 drq = 0; 94 95 bt_init_softc(dev, port, irq, drq); 96 97 return (0); 98} 99 100static void 101bt_isa_release_resources(device_t dev) 102{ 103 struct bt_softc *bt = device_get_softc(dev); 104 105 if (bt->port) 106 bus_release_resource(dev, SYS_RES_IOPORT, 0, bt->port); 107 if (bt->irq)
|
108 bus_release_resource(dev, SYS_RES_IOPORT, 0, bt->irq);
| 108 bus_release_resource(dev, SYS_RES_IRQ, 0, bt->irq);
|
109 if (bt->drq)
| 109 if (bt->drq)
|
110 bus_release_resource(dev, SYS_RES_IOPORT, 0, bt->drq);
| 110 bus_release_resource(dev, SYS_RES_DRQ, 0, bt->drq);
|
111 bt_free_softc(dev); 112} 113 114/* 115 * Check if the device can be found at the port given 116 * and if so, set it up ready for further work 117 * as an argument, takes the isa_device structure from 118 * autoconf.c 119 */ 120static int 121bt_isa_probe(device_t dev) 122{ 123 /* 124 * find unit and check we have that many defined 125 */ 126 int port_index; 127 int max_port_index; 128 129 port_index = 0; 130 max_port_index = BT_NUM_ISAPORTS - 1; 131 /* 132 * Bound our board search if the user has 133 * specified an exact port. 134 */ 135 bt_find_probe_range(isa_get_port(dev), &port_index, &max_port_index); 136 137 if (port_index < 0) 138 return (ENXIO); 139 140 /* Attempt to find an adapter */ 141 for (;port_index <= max_port_index; port_index++) { 142 struct bt_probe_info info; 143 u_int ioport; 144 145 ioport = bt_iop_from_bio(port_index); 146 isa_set_port(dev, ioport); 147 isa_set_portsize(dev, BT_NREGS); 148 149 /* 150 * Ensure this port has not already been claimed already 151 * by a PCI, EISA or ISA adapter. 152 */ 153 if (bt_check_probed_iop(ioport) != 0) 154 continue; 155 156 /* Initialise the softc for use during probing */ 157 if (bt_isa_alloc_resources(dev) != 0) 158 continue; 159 160 /* We're going to attempt to probe it now, so mark it probed */ 161 bt_mark_probed_bio(port_index); 162 163 if (bt_port_probe(dev, &info) != 0) { 164 printf("bt_isa_probe: Probe failed for card at 0x%x\n", 165 ioport); 166 bt_isa_release_resources(dev); 167 continue; 168 } 169 170 bt_isa_release_resources(dev); 171
| 111 bt_free_softc(dev); 112} 113 114/* 115 * Check if the device can be found at the port given 116 * and if so, set it up ready for further work 117 * as an argument, takes the isa_device structure from 118 * autoconf.c 119 */ 120static int 121bt_isa_probe(device_t dev) 122{ 123 /* 124 * find unit and check we have that many defined 125 */ 126 int port_index; 127 int max_port_index; 128 129 port_index = 0; 130 max_port_index = BT_NUM_ISAPORTS - 1; 131 /* 132 * Bound our board search if the user has 133 * specified an exact port. 134 */ 135 bt_find_probe_range(isa_get_port(dev), &port_index, &max_port_index); 136 137 if (port_index < 0) 138 return (ENXIO); 139 140 /* Attempt to find an adapter */ 141 for (;port_index <= max_port_index; port_index++) { 142 struct bt_probe_info info; 143 u_int ioport; 144 145 ioport = bt_iop_from_bio(port_index); 146 isa_set_port(dev, ioport); 147 isa_set_portsize(dev, BT_NREGS); 148 149 /* 150 * Ensure this port has not already been claimed already 151 * by a PCI, EISA or ISA adapter. 152 */ 153 if (bt_check_probed_iop(ioport) != 0) 154 continue; 155 156 /* Initialise the softc for use during probing */ 157 if (bt_isa_alloc_resources(dev) != 0) 158 continue; 159 160 /* We're going to attempt to probe it now, so mark it probed */ 161 bt_mark_probed_bio(port_index); 162 163 if (bt_port_probe(dev, &info) != 0) { 164 printf("bt_isa_probe: Probe failed for card at 0x%x\n", 165 ioport); 166 bt_isa_release_resources(dev); 167 continue; 168 } 169 170 bt_isa_release_resources(dev); 171
|
| 172 isa_set_port(dev, ioport);
|
172 isa_set_drq(dev, info.drq); 173 isa_set_irq(dev, info.irq); 174 175 return (0); 176 } 177 178 return (ENXIO); 179} 180 181/* 182 * Attach all the sub-devices we can find 183 */ 184static int 185bt_isa_attach(device_t dev) 186{ 187 struct bt_softc *bt = device_get_softc(dev); 188 bus_dma_filter_t *filter; 189 void *filter_arg; 190 bus_addr_t lowaddr;
| 173 isa_set_drq(dev, info.drq); 174 isa_set_irq(dev, info.irq); 175 176 return (0); 177 } 178 179 return (ENXIO); 180} 181 182/* 183 * Attach all the sub-devices we can find 184 */ 185static int 186bt_isa_attach(device_t dev) 187{ 188 struct bt_softc *bt = device_get_softc(dev); 189 bus_dma_filter_t *filter; 190 void *filter_arg; 191 bus_addr_t lowaddr;
|
191 int error;
| 192 int error, drq;
|
192 193 /* Initialise softc */ 194 error = bt_isa_alloc_resources(dev); 195 if (error) { 196 device_printf(dev, "can't allocate resources in bt_isa_attach\n"); 197 return error; 198 } 199
| 193 194 /* Initialise softc */ 195 error = bt_isa_alloc_resources(dev); 196 if (error) { 197 device_printf(dev, "can't allocate resources in bt_isa_attach\n"); 198 return error; 199 } 200
|
| 201 /* Program the DMA channel for external control */ 202 if ((drq = isa_get_drq(dev)) != -1) 203 isa_dmacascade(drq); 204
|
200 /* Allocate our parent dmatag */ 201 filter = NULL; 202 filter_arg = NULL; 203 lowaddr = BUS_SPACE_MAXADDR_24BIT; 204 if (bt->model[0] == '4') { 205 /* 206 * This is a VL adapter. Typically, VL devices have access 207 * to the full 32bit address space. On BT-445S adapters 208 * prior to revision E, there is a hardware bug that causes 209 * corruption of transfers to/from addresses in the range of 210 * the BIOS modulo 16MB. The only properly functioning 211 * BT-445S Host Adapters have firmware version 3.37. 212 * If we encounter one of these adapters and the BIOS is 213 * installed, install a filter function for our bus_dma_map 214 * that will catch these accesses and bounce them to a safe 215 * region of memory. 216 */ 217 if (bt->bios_addr != 0 218 && strcmp(bt->model, "445S") == 0 219 && strcmp(bt->firmware_ver, "3.37") < 0) { 220 filter = btvlbouncefilter; 221 filter_arg = bt; 222 } else { 223 lowaddr = BUS_SPACE_MAXADDR_32BIT; 224 } 225 } 226 227 /* XXX Should be a child of the ISA or VL bus dma tag */ 228 if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/0, /*boundary*/0, 229 lowaddr, /*highaddr*/BUS_SPACE_MAXADDR, 230 filter, filter_arg, 231 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT, 232 /*nsegments*/BUS_SPACE_UNRESTRICTED, 233 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, 234 /*flags*/0, &bt->parent_dmat) != 0) { 235 bt_isa_release_resources(dev); 236 return (ENOMEM); 237 } 238
| 205 /* Allocate our parent dmatag */ 206 filter = NULL; 207 filter_arg = NULL; 208 lowaddr = BUS_SPACE_MAXADDR_24BIT; 209 if (bt->model[0] == '4') { 210 /* 211 * This is a VL adapter. Typically, VL devices have access 212 * to the full 32bit address space. On BT-445S adapters 213 * prior to revision E, there is a hardware bug that causes 214 * corruption of transfers to/from addresses in the range of 215 * the BIOS modulo 16MB. The only properly functioning 216 * BT-445S Host Adapters have firmware version 3.37. 217 * If we encounter one of these adapters and the BIOS is 218 * installed, install a filter function for our bus_dma_map 219 * that will catch these accesses and bounce them to a safe 220 * region of memory. 221 */ 222 if (bt->bios_addr != 0 223 && strcmp(bt->model, "445S") == 0 224 && strcmp(bt->firmware_ver, "3.37") < 0) { 225 filter = btvlbouncefilter; 226 filter_arg = bt; 227 } else { 228 lowaddr = BUS_SPACE_MAXADDR_32BIT; 229 } 230 } 231 232 /* XXX Should be a child of the ISA or VL bus dma tag */ 233 if (bus_dma_tag_create(/*parent*/NULL, /*alignemnt*/0, /*boundary*/0, 234 lowaddr, /*highaddr*/BUS_SPACE_MAXADDR, 235 filter, filter_arg, 236 /*maxsize*/BUS_SPACE_MAXSIZE_32BIT, 237 /*nsegments*/BUS_SPACE_UNRESTRICTED, 238 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, 239 /*flags*/0, &bt->parent_dmat) != 0) { 240 bt_isa_release_resources(dev); 241 return (ENOMEM); 242 } 243
|
239 if (bt_init(dev)) {
| 244 error = bt_init(dev); 245 if (error) {
|
240 bt_isa_release_resources(dev); 241 return (ENOMEM); 242 } 243 244 if (lowaddr != BUS_SPACE_MAXADDR_32BIT) { 245 /* DMA tag for our sense buffers */ 246 if (bus_dma_tag_create(bt->parent_dmat, /*alignment*/0, 247 /*boundary*/0, 248 /*lowaddr*/BUS_SPACE_MAXADDR, 249 /*highaddr*/BUS_SPACE_MAXADDR, 250 /*filter*/NULL, /*filterarg*/NULL, 251 bt->max_ccbs 252 * sizeof(struct scsi_sense_data), 253 /*nsegments*/1, 254 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, 255 /*flags*/0, &bt->sense_dmat) != 0) { 256 bt_isa_release_resources(dev); 257 return (ENOMEM); 258 } 259 260 bt->init_level++; 261 262 /* Allocation of sense buffers */ 263 if (bus_dmamem_alloc(bt->sense_dmat, 264 (void **)&bt->sense_buffers, 265 BUS_DMA_NOWAIT, &bt->sense_dmamap) != 0) { 266 bt_isa_release_resources(dev); 267 return (ENOMEM); 268 } 269 270 bt->init_level++; 271 272 /* And permanently map them */ 273 bus_dmamap_load(bt->sense_dmat, bt->sense_dmamap, 274 bt->sense_buffers, 275 bt->max_ccbs * sizeof(*bt->sense_buffers), 276 btmapsensebuffers, bt, /*flags*/0); 277 278 bt->init_level++; 279 } 280 281 error = bt_attach(dev); 282 if (error) { 283 bt_isa_release_resources(dev); 284 return (error); 285 } 286 287 return (0); 288} 289 290#define BIOS_MAP_SIZE (16 * 1024) 291 292static int 293btvlbouncefilter(void *arg, bus_addr_t addr) 294{ 295 struct bt_softc *bt; 296 297 bt = (struct bt_softc *)arg; 298 299 addr &= BUS_SPACE_MAXADDR_24BIT; 300 301 if (addr == 0 302 || (addr >= bt->bios_addr 303 && addr < (bt->bios_addr + BIOS_MAP_SIZE))) 304 return (1); 305 return (0); 306} 307 308static void 309btmapsensebuffers(void *arg, bus_dma_segment_t *segs, int nseg, int error) 310{ 311 struct bt_softc* bt; 312 313 bt = (struct bt_softc*)arg; 314 bt->sense_buffers_physbase = segs->ds_addr; 315} 316 317static device_method_t bt_isa_methods[] = { 318 /* Device interface */ 319 DEVMETHOD(device_probe, bt_isa_probe), 320 DEVMETHOD(device_attach, bt_isa_attach), 321 322 { 0, 0 } 323}; 324 325static driver_t bt_isa_driver = { 326 "bt", 327 bt_isa_methods, 328 DRIVER_TYPE_CAM, 329 sizeof(struct bt_softc), 330}; 331 332static devclass_t bt_devclass; 333 334DRIVER_MODULE(bt, isa, bt_isa_driver, bt_devclass, 0, 0);
| 246 bt_isa_release_resources(dev); 247 return (ENOMEM); 248 } 249 250 if (lowaddr != BUS_SPACE_MAXADDR_32BIT) { 251 /* DMA tag for our sense buffers */ 252 if (bus_dma_tag_create(bt->parent_dmat, /*alignment*/0, 253 /*boundary*/0, 254 /*lowaddr*/BUS_SPACE_MAXADDR, 255 /*highaddr*/BUS_SPACE_MAXADDR, 256 /*filter*/NULL, /*filterarg*/NULL, 257 bt->max_ccbs 258 * sizeof(struct scsi_sense_data), 259 /*nsegments*/1, 260 /*maxsegsz*/BUS_SPACE_MAXSIZE_32BIT, 261 /*flags*/0, &bt->sense_dmat) != 0) { 262 bt_isa_release_resources(dev); 263 return (ENOMEM); 264 } 265 266 bt->init_level++; 267 268 /* Allocation of sense buffers */ 269 if (bus_dmamem_alloc(bt->sense_dmat, 270 (void **)&bt->sense_buffers, 271 BUS_DMA_NOWAIT, &bt->sense_dmamap) != 0) { 272 bt_isa_release_resources(dev); 273 return (ENOMEM); 274 } 275 276 bt->init_level++; 277 278 /* And permanently map them */ 279 bus_dmamap_load(bt->sense_dmat, bt->sense_dmamap, 280 bt->sense_buffers, 281 bt->max_ccbs * sizeof(*bt->sense_buffers), 282 btmapsensebuffers, bt, /*flags*/0); 283 284 bt->init_level++; 285 } 286 287 error = bt_attach(dev); 288 if (error) { 289 bt_isa_release_resources(dev); 290 return (error); 291 } 292 293 return (0); 294} 295 296#define BIOS_MAP_SIZE (16 * 1024) 297 298static int 299btvlbouncefilter(void *arg, bus_addr_t addr) 300{ 301 struct bt_softc *bt; 302 303 bt = (struct bt_softc *)arg; 304 305 addr &= BUS_SPACE_MAXADDR_24BIT; 306 307 if (addr == 0 308 || (addr >= bt->bios_addr 309 && addr < (bt->bios_addr + BIOS_MAP_SIZE))) 310 return (1); 311 return (0); 312} 313 314static void 315btmapsensebuffers(void *arg, bus_dma_segment_t *segs, int nseg, int error) 316{ 317 struct bt_softc* bt; 318 319 bt = (struct bt_softc*)arg; 320 bt->sense_buffers_physbase = segs->ds_addr; 321} 322 323static device_method_t bt_isa_methods[] = { 324 /* Device interface */ 325 DEVMETHOD(device_probe, bt_isa_probe), 326 DEVMETHOD(device_attach, bt_isa_attach), 327 328 { 0, 0 } 329}; 330 331static driver_t bt_isa_driver = { 332 "bt", 333 bt_isa_methods, 334 DRIVER_TYPE_CAM, 335 sizeof(struct bt_softc), 336}; 337 338static devclass_t bt_devclass; 339 340DRIVER_MODULE(bt, isa, bt_isa_driver, bt_devclass, 0, 0);
|