FreeBSD/Linux Kernel Cross Reference
sys/dev/ips/ips_disk.c
1 /*-
2 * Written by: David Jeffery
3 * Copyright (c) 2002 Adaptec Inc.
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 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD: releng/5.2/sys/dev/ips/ips_disk.c 120329 2003-09-22 04:59:07Z njl $");
30
31 #include <dev/ips/ips.h>
32 #include <dev/ips/ips_disk.h>
33 #include <sys/stat.h>
34
35 static int ipsd_probe(device_t dev);
36 static int ipsd_attach(device_t dev);
37 static int ipsd_detach(device_t dev);
38
39 static disk_open_t ipsd_open;
40 static disk_close_t ipsd_close;
41 static disk_strategy_t ipsd_strategy;
42
43 static device_method_t ipsd_methods[] = {
44 DEVMETHOD(device_probe, ipsd_probe),
45 DEVMETHOD(device_attach, ipsd_attach),
46 DEVMETHOD(device_detach, ipsd_detach),
47 { 0, 0 }
48 };
49
50
51 static driver_t ipsd_driver = {
52 "ipsd",
53 ipsd_methods,
54 sizeof(ipsdisk_softc_t)
55 };
56
57 static devclass_t ipsd_devclass;
58 DRIVER_MODULE(ipsd, ips, ipsd_driver, ipsd_devclass, 0, 0);
59
60 /* handle opening of disk device. It must set up all
61 information about the geometry and size of the disk */
62 static int ipsd_open(struct disk *dp)
63 {
64 ipsdisk_softc_t *dsc = dp->d_drv1;
65
66 dsc->state |= IPS_DEV_OPEN;
67 DEVICE_PRINTF(2, dsc->dev, "I'm open\n");
68 return 0;
69 }
70
71 static int ipsd_close(struct disk *dp)
72 {
73 ipsdisk_softc_t *dsc = dp->d_drv1;
74 dsc->state &= ~IPS_DEV_OPEN;
75 DEVICE_PRINTF(2, dsc->dev, "I'm closed for the day\n");
76 return 0;
77 }
78
79 /* ipsd_finish is called to clean up and return a completed IO request */
80 void ipsd_finish(struct bio *iobuf)
81 {
82 if (iobuf->bio_flags & BIO_ERROR) {
83 ipsdisk_softc_t *dsc;
84 dsc = iobuf->bio_disk->d_drv1;
85 device_printf(dsc->dev, "iobuf error %d\n", iobuf->bio_error);
86 } else
87 iobuf->bio_resid = 0;
88
89 biodone(iobuf);
90 }
91
92
93 static void ipsd_strategy(struct bio *iobuf)
94 {
95 ipsdisk_softc_t *dsc;
96
97 dsc = iobuf->bio_disk->d_drv1;
98 DEVICE_PRINTF(8,dsc->dev,"in strategy\n");
99 iobuf->bio_driver1 = (void *)(uintptr_t)dsc->sc->drives[dsc->disk_number].drivenum;
100 ips_start_io_request(dsc->sc, iobuf);
101 }
102
103 static int ipsd_probe(device_t dev)
104 {
105 DEVICE_PRINTF(2,dev, "in probe\n");
106 device_set_desc(dev, "Logical Drive");
107 return 0;
108 }
109
110 static int ipsd_attach(device_t dev)
111 {
112 device_t adapter;
113 ipsdisk_softc_t *dsc;
114 u_int totalsectors;
115
116 DEVICE_PRINTF(2,dev, "in attach\n");
117
118 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
119 bzero(dsc, sizeof(ipsdisk_softc_t));
120 adapter = device_get_parent(dev);
121 dsc->dev = dev;
122 dsc->sc = device_get_softc(adapter);
123 dsc->unit = device_get_unit(dev);
124 dsc->disk_number = (uintptr_t) device_get_ivars(dev);
125 dsc->ipsd_disk.d_drv1 = dsc;
126 dsc->ipsd_disk.d_name = "ipsd";
127 dsc->ipsd_disk.d_maxsize = IPS_MAX_IO_SIZE;
128 dsc->ipsd_disk.d_open = ipsd_open;
129 dsc->ipsd_disk.d_close = ipsd_close;
130 dsc->ipsd_disk.d_strategy = ipsd_strategy;
131
132 totalsectors = dsc->sc->drives[dsc->disk_number].sector_count;
133 if ((totalsectors > 0x400000) &&
134 ((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
135 dsc->ipsd_disk.d_fwheads = IPS_NORM_HEADS;
136 dsc->ipsd_disk.d_fwsectors = IPS_NORM_SECTORS;
137 } else {
138 dsc->ipsd_disk.d_fwheads = IPS_COMP_HEADS;
139 dsc->ipsd_disk.d_fwsectors = IPS_COMP_SECTORS;
140 }
141 dsc->ipsd_disk.d_sectorsize = IPS_BLKSIZE;
142 dsc->ipsd_disk.d_mediasize = (off_t)totalsectors * IPS_BLKSIZE;
143 disk_create(dsc->unit, &dsc->ipsd_disk, 0, NULL, NULL);
144
145 device_printf(dev, "Logical Drive (%dMB)\n",
146 dsc->sc->drives[dsc->disk_number].sector_count >> 11);
147 return 0;
148 }
149
150 static int ipsd_detach(device_t dev)
151 {
152 ipsdisk_softc_t *dsc;
153
154 DEVICE_PRINTF(2, dev,"in detach\n");
155 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
156 if(dsc->state & IPS_DEV_OPEN)
157 return (EBUSY);
158 disk_destroy(&dsc->ipsd_disk);
159 return 0;
160 }
161
Cache object: 008611652ccfd6172cd92e313aac6a6a
|