wdc.c revision 1.3 1 1.3 christos /* $NetBSD: wdc.c,v 1.3 2019/01/08 17:15:31 christos Exp $ */
2 1.1 kiyohara
3 1.1 kiyohara /*-
4 1.1 kiyohara * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 1.1 kiyohara * All rights reserved.
6 1.1 kiyohara *
7 1.1 kiyohara * This code is derived from software contributed to The NetBSD Foundation
8 1.1 kiyohara * by Manuel Bouyer.
9 1.1 kiyohara *
10 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
11 1.1 kiyohara * modification, are permitted provided that the following conditions
12 1.1 kiyohara * are met:
13 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
14 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
15 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
17 1.1 kiyohara * documentation and/or other materials provided with the distribution.
18 1.1 kiyohara *
19 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 kiyohara * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 kiyohara * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 kiyohara * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 kiyohara * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 kiyohara * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 kiyohara * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 kiyohara * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 kiyohara * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 kiyohara * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
30 1.1 kiyohara */
31 1.1 kiyohara
32 1.3 christos #include <sys/param.h>
33 1.1 kiyohara #include <sys/types.h>
34 1.1 kiyohara #include <sys/disklabel.h>
35 1.1 kiyohara #include <sys/bootblock.h>
36 1.1 kiyohara
37 1.1 kiyohara #include <lib/libsa/stand.h>
38 1.1 kiyohara #include <lib/libkern/libkern.h>
39 1.1 kiyohara #include <machine/param.h>
40 1.1 kiyohara
41 1.1 kiyohara #include "boot.h"
42 1.1 kiyohara #include "wdvar.h"
43 1.1 kiyohara
44 1.1 kiyohara #if defined(SH3)
45 1.1 kiyohara #define MMEYE_WDC0_IOBASE 0xb6000000
46 1.1 kiyohara #define MMEYE_WDC1_IOBASE 0xb7000000
47 1.1 kiyohara #elif defined(SH4)
48 1.1 kiyohara #define MMEYE_WDC0_IOBASE 0xb6000000
49 1.1 kiyohara #define MMEYE_WDC1_IOBASE 0xb7000000
50 1.1 kiyohara #endif
51 1.1 kiyohara #define MMEYE_WDC_CTLBASE 0x206
52 1.1 kiyohara
53 1.1 kiyohara #define WDCDELAY 100
54 1.1 kiyohara #define WDCNDELAY_RST 31000 * 10
55 1.1 kiyohara
56 1.1 kiyohara static int wdcprobe(struct wdc_channel *chp);
57 1.1 kiyohara static int wdc_wait_for_ready(struct wdc_channel *chp);
58 1.1 kiyohara static int wdc_read_block(struct wd_softc *sc, struct wdc_command *wd_c);
59 1.1 kiyohara static int __wdcwait_reset(struct wdc_channel *chp, int drv_mask);
60 1.1 kiyohara
61 1.1 kiyohara /*
62 1.1 kiyohara * Reset the controller.
63 1.1 kiyohara */
64 1.1 kiyohara static int
65 1.1 kiyohara __wdcwait_reset(struct wdc_channel *chp, int drv_mask)
66 1.1 kiyohara {
67 1.1 kiyohara int timeout;
68 1.1 kiyohara uint8_t st0, st1;
69 1.1 kiyohara
70 1.1 kiyohara /* wait for BSY to deassert */
71 1.1 kiyohara for (timeout = 0; timeout < WDCNDELAY_RST; timeout++) {
72 1.1 kiyohara WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM); /* master */
73 1.1 kiyohara delay(10);
74 1.1 kiyohara st0 = WDC_READ_REG(chp, wd_status);
75 1.1 kiyohara WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM | 0x10); /* slave */
76 1.1 kiyohara delay(10);
77 1.1 kiyohara st1 = WDC_READ_REG(chp, wd_status);
78 1.1 kiyohara
79 1.1 kiyohara if ((drv_mask & 0x01) == 0) {
80 1.1 kiyohara /* no master */
81 1.1 kiyohara if ((drv_mask & 0x02) != 0 && (st1 & WDCS_BSY) == 0) {
82 1.1 kiyohara /* No master, slave is ready, it's done */
83 1.1 kiyohara goto end;
84 1.1 kiyohara }
85 1.1 kiyohara } else if ((drv_mask & 0x02) == 0) {
86 1.1 kiyohara /* no slave */
87 1.1 kiyohara if ((drv_mask & 0x01) != 0 && (st0 & WDCS_BSY) == 0) {
88 1.1 kiyohara /* No slave, master is ready, it's done */
89 1.1 kiyohara goto end;
90 1.1 kiyohara }
91 1.1 kiyohara } else {
92 1.1 kiyohara /* Wait for both master and slave to be ready */
93 1.1 kiyohara if ((st0 & WDCS_BSY) == 0 && (st1 & WDCS_BSY) == 0) {
94 1.1 kiyohara goto end;
95 1.1 kiyohara }
96 1.1 kiyohara }
97 1.1 kiyohara
98 1.1 kiyohara delay(WDCDELAY);
99 1.1 kiyohara }
100 1.1 kiyohara
101 1.1 kiyohara /* Reset timed out. Maybe it's because drv_mask was not right */
102 1.1 kiyohara if (st0 & WDCS_BSY)
103 1.1 kiyohara drv_mask &= ~0x01;
104 1.1 kiyohara if (st1 & WDCS_BSY)
105 1.1 kiyohara drv_mask &= ~0x02;
106 1.1 kiyohara
107 1.1 kiyohara end:
108 1.1 kiyohara return drv_mask;
109 1.1 kiyohara }
110 1.1 kiyohara
111 1.1 kiyohara /* Test to see controller with at last one attached drive is there.
112 1.1 kiyohara * Returns a bit for each possible drive found (0x01 for drive 0,
113 1.1 kiyohara * 0x02 for drive 1).
114 1.1 kiyohara * Logic:
115 1.1 kiyohara * - If a status register is at 0xff, assume there is no drive here
116 1.1 kiyohara * (ISA has pull-up resistors). Similarly if the status register has
117 1.1 kiyohara * the value we last wrote to the bus (for IDE interfaces without pullups).
118 1.1 kiyohara * If no drive at all -> return.
119 1.1 kiyohara * - reset the controller, wait for it to complete (may take up to 31s !).
120 1.1 kiyohara * If timeout -> return.
121 1.1 kiyohara */
122 1.1 kiyohara static int
123 1.1 kiyohara wdcprobe(struct wdc_channel *chp)
124 1.1 kiyohara {
125 1.1 kiyohara uint8_t st0, st1;
126 1.1 kiyohara uint8_t ret_value = 0x03;
127 1.1 kiyohara uint8_t drive;
128 1.1 kiyohara
129 1.1 kiyohara /*
130 1.1 kiyohara * Sanity check to see if the wdc channel responds at all.
131 1.1 kiyohara */
132 1.1 kiyohara WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM);
133 1.1 kiyohara delay(10);
134 1.1 kiyohara st0 = WDC_READ_REG(chp, wd_status);
135 1.1 kiyohara WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM | 0x10);
136 1.1 kiyohara delay(10);
137 1.1 kiyohara st1 = WDC_READ_REG(chp, wd_status);
138 1.1 kiyohara
139 1.1 kiyohara if (st0 == 0xff || st0 == WDSD_IBM)
140 1.1 kiyohara ret_value &= ~0x01;
141 1.1 kiyohara if (st1 == 0xff || st1 == (WDSD_IBM | 0x10))
142 1.1 kiyohara ret_value &= ~0x02;
143 1.1 kiyohara if (ret_value == 0)
144 1.1 kiyohara return ENXIO;
145 1.1 kiyohara
146 1.1 kiyohara /* assert SRST, wait for reset to complete */
147 1.1 kiyohara WDC_WRITE_REG(chp, wd_sdh, WDSD_IBM);
148 1.1 kiyohara delay(10);
149 1.1 kiyohara WDC_WRITE_CTLREG(chp, wd_aux_ctlr, WDCTL_RST | WDCTL_IDS);
150 1.1 kiyohara delay(1000);
151 1.1 kiyohara WDC_WRITE_CTLREG(chp, wd_aux_ctlr, WDCTL_IDS);
152 1.1 kiyohara delay(1000);
153 1.1 kiyohara (void) WDC_READ_REG(chp, wd_error);
154 1.1 kiyohara WDC_WRITE_CTLREG(chp, wd_aux_ctlr, WDCTL_4BIT);
155 1.1 kiyohara delay(10);
156 1.1 kiyohara
157 1.1 kiyohara ret_value = __wdcwait_reset(chp, ret_value);
158 1.1 kiyohara
159 1.1 kiyohara /* if reset failed, there's nothing here */
160 1.1 kiyohara if (ret_value == 0)
161 1.1 kiyohara return ENXIO;
162 1.1 kiyohara
163 1.1 kiyohara /*
164 1.1 kiyohara * Test presence of drives. First test register signatures looking for
165 1.1 kiyohara * ATAPI devices. If it's not an ATAPI and reset said there may be
166 1.1 kiyohara * something here assume it's ATA or OLD. Ghost will be killed later in
167 1.1 kiyohara * attach routine.
168 1.1 kiyohara */
169 1.1 kiyohara for (drive = 0; drive < 2; drive++) {
170 1.1 kiyohara if ((ret_value & (0x01 << drive)) == 0)
171 1.1 kiyohara continue;
172 1.1 kiyohara return 0;
173 1.1 kiyohara }
174 1.1 kiyohara return ENXIO;
175 1.1 kiyohara }
176 1.1 kiyohara
177 1.1 kiyohara /*
178 1.1 kiyohara * Initialize the device.
179 1.1 kiyohara */
180 1.1 kiyohara int
181 1.1 kiyohara wdc_init(struct wd_softc *sc, u_int *unit)
182 1.1 kiyohara {
183 1.1 kiyohara struct wdc_channel *chp = &sc->sc_channel;
184 1.1 kiyohara uint32_t cmdreg, ctlreg;
185 1.1 kiyohara int i;
186 1.1 kiyohara
187 1.1 kiyohara /* XXXX: Shuld reset CF COR here? */
188 1.1 kiyohara
189 1.1 kiyohara switch (*unit) {
190 1.1 kiyohara case 0: cmdreg = MMEYE_WDC0_IOBASE; break;
191 1.1 kiyohara case 1: cmdreg = MMEYE_WDC1_IOBASE; break;
192 1.1 kiyohara
193 1.1 kiyohara default:
194 1.1 kiyohara return ENXIO;
195 1.1 kiyohara }
196 1.1 kiyohara ctlreg = cmdreg + MMEYE_WDC_CTLBASE;
197 1.1 kiyohara
198 1.2 kamil /* set up cmd registers */
199 1.1 kiyohara chp->c_cmdbase = (uint8_t *)cmdreg;
200 1.1 kiyohara chp->c_data = (uint16_t *)(cmdreg + wd_data);
201 1.1 kiyohara for (i = 0; i < WDC_NPORTS; i++)
202 1.1 kiyohara chp->c_cmdreg[i] = chp->c_cmdbase + i;
203 1.1 kiyohara /* set up shadow registers */
204 1.1 kiyohara chp->c_cmdreg[wd_status] = chp->c_cmdreg[wd_command];
205 1.1 kiyohara chp->c_cmdreg[wd_features] = chp->c_cmdreg[wd_precomp];
206 1.1 kiyohara /* set up ctl registers */
207 1.1 kiyohara chp->c_ctlbase = (uint8_t *)ctlreg;
208 1.1 kiyohara
209 1.1 kiyohara if (wdcprobe(&sc->sc_channel) != 0)
210 1.1 kiyohara return ENXIO;
211 1.1 kiyohara return 0;
212 1.1 kiyohara }
213 1.1 kiyohara
214 1.1 kiyohara /*
215 1.1 kiyohara * Wait until the device is ready.
216 1.1 kiyohara */
217 1.1 kiyohara int
218 1.1 kiyohara wdc_wait_for_ready(struct wdc_channel *chp)
219 1.1 kiyohara {
220 1.1 kiyohara u_int timeout;
221 1.1 kiyohara
222 1.1 kiyohara for (timeout = WDC_TIMEOUT; timeout > 0; --timeout) {
223 1.1 kiyohara if ((WDC_READ_REG(chp, wd_status) & (WDCS_BSY | WDCS_DRDY))
224 1.1 kiyohara == WDCS_DRDY)
225 1.1 kiyohara return 0;
226 1.1 kiyohara delay(1);
227 1.1 kiyohara }
228 1.1 kiyohara return ENXIO;
229 1.1 kiyohara }
230 1.1 kiyohara
231 1.1 kiyohara /*
232 1.1 kiyohara * Read one block off the device.
233 1.1 kiyohara */
234 1.1 kiyohara int
235 1.1 kiyohara wdc_read_block(struct wd_softc *sc, struct wdc_command *wd_c)
236 1.1 kiyohara {
237 1.1 kiyohara int i;
238 1.1 kiyohara struct wdc_channel *chp = &sc->sc_channel;
239 1.1 kiyohara uint16_t *ptr = (uint16_t *)wd_c->data;
240 1.1 kiyohara
241 1.1 kiyohara if (ptr == NULL)
242 1.1 kiyohara return 0;
243 1.1 kiyohara
244 1.1 kiyohara if (wd_c->r_command == WDCC_IDENTIFY)
245 1.1 kiyohara for (i = wd_c->bcount; i > 0; i -= sizeof(uint16_t))
246 1.1 kiyohara *ptr++ = WDC_READ_DATA(chp);
247 1.1 kiyohara else
248 1.1 kiyohara for (i = wd_c->bcount; i > 0; i -= sizeof(uint16_t))
249 1.1 kiyohara *ptr++ = WDC_READ_DATA_STREAM(chp);
250 1.1 kiyohara
251 1.1 kiyohara return 0;
252 1.1 kiyohara }
253 1.1 kiyohara
254 1.1 kiyohara /*
255 1.1 kiyohara * Send a command to the device (CHS and LBA addressing).
256 1.1 kiyohara */
257 1.1 kiyohara int
258 1.1 kiyohara wdccommand(struct wd_softc *sc, struct wdc_command *wd_c)
259 1.1 kiyohara {
260 1.1 kiyohara struct wdc_channel *chp = &sc->sc_channel;
261 1.1 kiyohara
262 1.1 kiyohara #if 0
263 1.1 kiyohara DPRINTF(("wdccommand(%d, %d, %d, %d, %d, %d, %d)\n",
264 1.1 kiyohara wd_c->drive, wd_c->r_command, wd_c->r_cyl,
265 1.1 kiyohara wd_c->r_head, wd_c->r_sector, wd_c->bcount,
266 1.1 kiyohara wd_c->r_precomp));
267 1.1 kiyohara #endif
268 1.1 kiyohara
269 1.1 kiyohara WDC_WRITE_REG(chp, wd_features, wd_c->r_features);
270 1.1 kiyohara WDC_WRITE_REG(chp, wd_seccnt, wd_c->r_count);
271 1.1 kiyohara WDC_WRITE_REG(chp, wd_sector, wd_c->r_sector);
272 1.1 kiyohara WDC_WRITE_REG(chp, wd_cyl_lo, wd_c->r_cyl);
273 1.1 kiyohara WDC_WRITE_REG(chp, wd_cyl_hi, wd_c->r_cyl >> 8);
274 1.1 kiyohara WDC_WRITE_REG(chp, wd_sdh,
275 1.1 kiyohara WDSD_IBM | (wd_c->drive << 4) | wd_c->r_head);
276 1.1 kiyohara WDC_WRITE_REG(chp, wd_command, wd_c->r_command);
277 1.1 kiyohara
278 1.1 kiyohara if (wdc_wait_for_ready(chp) != 0)
279 1.1 kiyohara return ENXIO;
280 1.1 kiyohara
281 1.1 kiyohara if (WDC_READ_REG(chp, wd_status) & WDCS_ERR) {
282 1.1 kiyohara printf("wd%d: error %x\n", chp->compatchan,
283 1.1 kiyohara WDC_READ_REG(chp, wd_error));
284 1.1 kiyohara return ENXIO;
285 1.1 kiyohara }
286 1.1 kiyohara
287 1.1 kiyohara return 0;
288 1.1 kiyohara }
289 1.1 kiyohara
290 1.1 kiyohara /*
291 1.1 kiyohara * Send a command to the device (LBA48 addressing).
292 1.1 kiyohara */
293 1.1 kiyohara int
294 1.1 kiyohara wdccommandext(struct wd_softc *wd, struct wdc_command *wd_c)
295 1.1 kiyohara {
296 1.1 kiyohara struct wdc_channel *chp = &wd->sc_channel;
297 1.1 kiyohara
298 1.1 kiyohara #if 0
299 1.1 kiyohara DPRINTF(("%s(%d, %x, %" PRId64 ", %d)\n", __func__,
300 1.1 kiyohara wd_c->drive, wd_c->r_command,
301 1.1 kiyohara wd_c->r_blkno, wd_c->r_count));
302 1.1 kiyohara #endif
303 1.1 kiyohara
304 1.1 kiyohara /* Select drive, head, and addressing mode. */
305 1.1 kiyohara WDC_WRITE_REG(chp, wd_sdh, (wd_c->drive << 4) | WDSD_LBA);
306 1.1 kiyohara
307 1.1 kiyohara /* previous */
308 1.1 kiyohara WDC_WRITE_REG(chp, wd_features, 0);
309 1.1 kiyohara WDC_WRITE_REG(chp, wd_seccnt, wd_c->r_count >> 8);
310 1.1 kiyohara WDC_WRITE_REG(chp, wd_lba_hi, wd_c->r_blkno >> 40);
311 1.1 kiyohara WDC_WRITE_REG(chp, wd_lba_mi, wd_c->r_blkno >> 32);
312 1.1 kiyohara WDC_WRITE_REG(chp, wd_lba_lo, wd_c->r_blkno >> 24);
313 1.1 kiyohara
314 1.1 kiyohara /* current */
315 1.1 kiyohara WDC_WRITE_REG(chp, wd_features, 0);
316 1.1 kiyohara WDC_WRITE_REG(chp, wd_seccnt, wd_c->r_count);
317 1.1 kiyohara WDC_WRITE_REG(chp, wd_lba_hi, wd_c->r_blkno >> 16);
318 1.1 kiyohara WDC_WRITE_REG(chp, wd_lba_mi, wd_c->r_blkno >> 8);
319 1.1 kiyohara WDC_WRITE_REG(chp, wd_lba_lo, wd_c->r_blkno);
320 1.1 kiyohara
321 1.1 kiyohara /* Send command. */
322 1.1 kiyohara WDC_WRITE_REG(chp, wd_command, wd_c->r_command);
323 1.1 kiyohara
324 1.1 kiyohara if (wdc_wait_for_ready(chp) != 0)
325 1.1 kiyohara return ENXIO;
326 1.1 kiyohara
327 1.1 kiyohara if (WDC_READ_REG(chp, wd_status) & WDCS_ERR) {
328 1.1 kiyohara printf("wd%d: error %x\n", chp->compatchan,
329 1.1 kiyohara WDC_READ_REG(chp, wd_error));
330 1.1 kiyohara return ENXIO;
331 1.1 kiyohara }
332 1.1 kiyohara
333 1.1 kiyohara return 0;
334 1.1 kiyohara }
335 1.1 kiyohara
336 1.1 kiyohara /*
337 1.1 kiyohara * Issue 'device identify' command.
338 1.1 kiyohara */
339 1.1 kiyohara int
340 1.1 kiyohara wdc_exec_identify(struct wd_softc *wd, void *data)
341 1.1 kiyohara {
342 1.1 kiyohara int error;
343 1.1 kiyohara struct wdc_command wd_c;
344 1.1 kiyohara
345 1.1 kiyohara memset(&wd_c, 0, sizeof(wd_c));
346 1.1 kiyohara
347 1.1 kiyohara wd_c.drive = 0;
348 1.1 kiyohara wd_c.r_command = WDCC_IDENTIFY;
349 1.1 kiyohara wd_c.bcount = DEV_BSIZE;
350 1.1 kiyohara wd_c.data = data;
351 1.1 kiyohara
352 1.1 kiyohara if ((error = wdccommand(wd, &wd_c)) != 0)
353 1.1 kiyohara return error;
354 1.1 kiyohara
355 1.1 kiyohara return wdc_read_block(wd, &wd_c);
356 1.1 kiyohara }
357 1.1 kiyohara
358 1.1 kiyohara /*
359 1.1 kiyohara * Issue 'read' command.
360 1.1 kiyohara */
361 1.1 kiyohara int
362 1.1 kiyohara wdc_exec_read(struct wd_softc *wd, uint8_t cmd, daddr_t blkno, void *data)
363 1.1 kiyohara {
364 1.1 kiyohara int error;
365 1.1 kiyohara struct wdc_command wd_c;
366 1.1 kiyohara bool lba, lba48;
367 1.1 kiyohara
368 1.1 kiyohara memset(&wd_c, 0, sizeof(wd_c));
369 1.1 kiyohara lba = false;
370 1.1 kiyohara lba48 = false;
371 1.1 kiyohara
372 1.1 kiyohara wd_c.data = data;
373 1.1 kiyohara wd_c.r_count = 1;
374 1.1 kiyohara wd_c.r_features = 0;
375 1.1 kiyohara wd_c.drive = 0;
376 1.1 kiyohara wd_c.bcount = wd->sc_label.d_secsize;
377 1.1 kiyohara
378 1.1 kiyohara if ((wd->sc_flags & WDF_LBA48) != 0 && blkno > wd->sc_capacity28)
379 1.1 kiyohara lba48 = true;
380 1.1 kiyohara else if ((wd->sc_flags & WDF_LBA) != 0)
381 1.1 kiyohara lba = true;
382 1.1 kiyohara
383 1.1 kiyohara if (lba48) {
384 1.1 kiyohara /* LBA48 */
385 1.1 kiyohara wd_c.r_command = atacmd_to48(cmd);
386 1.1 kiyohara wd_c.r_blkno = blkno;
387 1.1 kiyohara } else if (lba) {
388 1.1 kiyohara /* LBA */
389 1.1 kiyohara wd_c.r_command = cmd;
390 1.1 kiyohara wd_c.r_sector = (blkno >> 0) & 0xff;
391 1.1 kiyohara wd_c.r_cyl = (blkno >> 8) & 0xffff;
392 1.1 kiyohara wd_c.r_head = (blkno >> 24) & 0x0f;
393 1.1 kiyohara wd_c.r_head |= WDSD_LBA;
394 1.1 kiyohara } else {
395 1.1 kiyohara /* CHS */
396 1.1 kiyohara wd_c.r_command = cmd;
397 1.1 kiyohara wd_c.r_sector = blkno % wd->sc_label.d_nsectors;
398 1.1 kiyohara wd_c.r_sector++; /* Sectors begin with 1, not 0. */
399 1.1 kiyohara blkno /= wd->sc_label.d_nsectors;
400 1.1 kiyohara wd_c.r_head = blkno % wd->sc_label.d_ntracks;
401 1.1 kiyohara blkno /= wd->sc_label.d_ntracks;
402 1.1 kiyohara wd_c.r_cyl = blkno;
403 1.1 kiyohara wd_c.r_head |= WDSD_CHS;
404 1.1 kiyohara }
405 1.1 kiyohara
406 1.1 kiyohara if (lba48)
407 1.1 kiyohara error = wdccommandext(wd, &wd_c);
408 1.1 kiyohara else
409 1.1 kiyohara error = wdccommand(wd, &wd_c);
410 1.1 kiyohara
411 1.1 kiyohara if (error != 0)
412 1.1 kiyohara return error;
413 1.1 kiyohara
414 1.1 kiyohara return wdc_read_block(wd, &wd_c);
415 1.1 kiyohara }
416