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 * $FreeBSD$
28 */
29
30 #include <dev/ips/ips.h>
31 #include <dev/ips/ips_disk.h>
32 #include <sys/stat.h>
33
34 static int ipsd_probe(device_t dev);
35 static int ipsd_attach(device_t dev);
36 static int ipsd_detach(device_t dev);
37
38 static d_open_t ipsd_open;
39 static d_close_t ipsd_close;
40 static d_strategy_t ipsd_strategy;
41
42 #define IPSD_CDEV_MAJOR 176
43
44 static struct cdevsw ipsd_cdevsw = {
45 ipsd_open,
46 ipsd_close,
47 physread,
48 physwrite,
49 noioctl,
50 nopoll,
51 nommap,
52 ipsd_strategy,
53 "ipsd",
54 IPSD_CDEV_MAJOR,
55 nodump,
56 nopsize,
57 D_DISK,
58 -1
59 };
60
61 static struct cdevsw ipsd_disk_cdevsw;
62 static int disks_registered;
63
64 static device_method_t ipsd_methods[] = {
65 DEVMETHOD(device_probe, ipsd_probe),
66 DEVMETHOD(device_attach, ipsd_attach),
67 DEVMETHOD(device_detach, ipsd_detach),
68 { 0, 0 }
69 };
70
71 static driver_t ipsd_driver = {
72 "ipsd",
73 ipsd_methods,
74 sizeof(ipsdisk_softc_t)
75 };
76
77 static devclass_t ipsd_devclass;
78 DRIVER_MODULE(ipsd, ips, ipsd_driver, ipsd_devclass, 0, 0);
79
80 /* handle opening of disk device. It must set up all
81 information about the geometry and size of the disk */
82 static int ipsd_open(dev_t dev, int flags, int fmt, struct proc *p)
83 {
84 ipsdisk_softc_t *dsc = dev->si_drv1;
85 struct disklabel *label;
86
87 dsc->state |= IPS_DEV_OPEN;
88 DEVICE_PRINTF(2, dsc->dev, "I'm open\n");
89
90 label = &dsc->ipsd_disk.d_label;
91 bzero(label, sizeof(*label));
92 label->d_type = DTYPE_ESDI;
93 label->d_secsize = IPS_BLKSIZE;
94 label->d_nsectors = dsc->sectors;
95 label->d_ntracks = dsc->heads;
96 label->d_ncylinders = dsc->cylinders;
97 label->d_secpercyl = dsc->sectors * dsc->heads;
98 label->d_secperunit = dsc->size;
99
100 return 0;
101 }
102
103 static int ipsd_close(dev_t dev, int flags, int fmt, struct proc *p)
104 {
105 ipsdisk_softc_t *dsc = dev->si_drv1;
106 dsc->state &= ~IPS_DEV_OPEN;
107 DEVICE_PRINTF(2, dsc->dev, "I'm closed for the day\n");
108 return 0;
109 }
110
111 /* ipsd_finish is called to clean up and return a completed IO request */
112 void ipsd_finish(struct buf *iobuf)
113 {
114 ipsdisk_softc_t *dsc;
115 dsc = iobuf->b_dev->si_drv1;
116
117 if (iobuf->b_flags & B_ERROR) {
118 device_printf(dsc->dev, "iobuf error %d\n", iobuf->b_error);
119 } else
120 iobuf->b_resid = 0;
121
122 devstat_end_transaction_buf(&dsc->stats, iobuf);
123 biodone(iobuf);
124 ips_start_io_request(dsc->sc);
125 }
126
127
128 static void ipsd_strategy(struct buf *iobuf)
129 {
130 ipsdisk_softc_t *dsc;
131
132 dsc = iobuf->b_dev->si_drv1;
133 DEVICE_PRINTF(8,dsc->dev,"in strategy\n");
134 devstat_start_transaction(&dsc->stats);
135 iobuf->b_driver1 = (void *)(uintptr_t)dsc->sc->drives[dsc->disk_number].drivenum;
136 bufqdisksort(&dsc->sc->queue, iobuf);
137 ips_start_io_request(dsc->sc);
138 }
139
140 static int ipsd_probe(device_t dev)
141 {
142 DEVICE_PRINTF(2,dev, "in probe\n");
143 device_set_desc(dev, "Logical Drive");
144 return 0;
145 }
146
147 static int ipsd_attach(device_t dev)
148 {
149 device_t adapter;
150 ipsdisk_softc_t *dsc;
151
152 DEVICE_PRINTF(2,dev, "in attach\n");
153
154 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
155 bzero(dsc, sizeof(ipsdisk_softc_t));
156 adapter = device_get_parent(dev);
157 dsc->dev = dev;
158 dsc->sc = device_get_softc(adapter);
159 dsc->unit = device_get_unit(dev);
160 dsc->disk_number = (uintptr_t) device_get_ivars(dev);
161
162 dsc->size = dsc->sc->drives[dsc->disk_number].sector_count;
163 if ((dsc->size > 0x400000) &&
164 ((dsc->sc->adapter_info.miscflags & 0x8) == 0)) {
165 dsc->heads = IPS_NORM_HEADS;
166 dsc->sectors = IPS_NORM_SECTORS;
167 } else {
168 dsc->heads = IPS_COMP_HEADS;
169 dsc->sectors = IPS_COMP_SECTORS;
170 }
171 dsc->cylinders = (dsc->size / (dsc->heads * dsc->sectors));
172 dsc->ipsd_dev = disk_create(dsc->unit, &dsc->ipsd_disk, 0,
173 &ipsd_cdevsw, &ipsd_disk_cdevsw);
174 dsc->ipsd_dev->si_drv1 = dsc;
175 dsc->ipsd_dev->si_iosize_max = IPS_MAX_IO_SIZE;
176
177 devstat_add_entry(&dsc->stats, "ipsd", dsc->unit, IPS_BLKSIZE,
178 DEVSTAT_NO_ORDERED_TAGS, DEVSTAT_TYPE_STORARRAY |
179 DEVSTAT_TYPE_IF_OTHER, DEVSTAT_PRIORITY_ARRAY);
180
181 disks_registered++;
182
183 device_printf(dev, "Logical Drive (%dMB)\n",
184 dsc->sc->drives[dsc->disk_number].sector_count >> 11);
185 return 0;
186 }
187
188 static int ipsd_detach(device_t dev)
189 {
190 ipsdisk_softc_t *dsc;
191
192 DEVICE_PRINTF(2, dev,"in detach\n");
193 dsc = (ipsdisk_softc_t *)device_get_softc(dev);
194 if(dsc->state & IPS_DEV_OPEN)
195 return (EBUSY);
196 devstat_remove_entry(&dsc->stats);
197 disk_destroy(dsc->ipsd_dev);
198 if (--disks_registered == 0)
199 cdevsw_remove(&ipsd_cdevsw);
200 return 0;
201 }
Cache object: 8eeee59291554947a523cb6f0c5caa2a
|