1 /* $NetBSD: iwm_fd.c,v 1.45 2009/01/11 21:55:45 oster Exp $ */
4 * Copyright (c) 1997, 1998 Hauke Fath. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * iwm_fd.c -- Sony (floppy disk) driver for m68k Macintoshes
30 * The present implementation supports the GCR format (800K) on
31 * non-{DMA,IOP} machines.
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: iwm_fd.c,v 1.45 2009/01/11 21:55:45 oster Exp $");
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/callout.h>
46 #include <sys/kernel.h>
48 #include <sys/ioctl.h>
49 #include <sys/malloc.h>
50 #include <sys/device.h>
51 #include <sys/event.h>
55 #include <sys/disklabel.h>
58 #include <sys/dkbad.h>
63 #include <sys/syslog.h>
66 #include <machine/autoconf.h>
67 #include <machine/cpu.h>
69 #include <mac68k/obio/iwmreg.h>
70 #include <mac68k/obio/iwm_fdvar.h>
75 static int map_iwm_base(vm_offset_t
);
78 int iwm_match(struct device
*, struct cfdata
*, void *);
79 void iwm_attach(struct device
*, struct device
*, void *);
80 int iwm_print(void *, const char *);
81 int fd_match(struct device
*, struct cfdata
*, void *);
82 void fd_attach(struct device
*, struct device
*, void *);
83 int fd_print(void *, const char *);
86 static void fdGetDiskLabel(fd_softc_t
*, dev_t
);
87 static void fdPrintDiskLabel(struct disklabel
*);
89 static fdInfo_t
*getFDType(short);
90 static fdInfo_t
*fdDeviceToType(fd_softc_t
*, dev_t
);
92 static void fdstart(fd_softc_t
*);
93 static void remap_geometry(daddr_t
, int, diskPosition_t
*);
94 static void motor_off(void *);
95 static int seek(fd_softc_t
*, int);
96 static int checkTrack(diskPosition_t
*, int);
97 static int initCylinderCache(fd_softc_t
*);
98 static void invalidateCylinderCache(fd_softc_t
*);
101 static int probe_fd(void);
102 int fd_mod_init(void);
103 void fd_mod_free(void);
106 static int fdstart_Init(fd_softc_t
*);
107 static int fdstart_Seek(fd_softc_t
*);
108 static int fdstart_Read(fd_softc_t
*);
109 static int fdstart_Write(fd_softc_t
*);
110 static int fdstart_Flush(fd_softc_t
*);
111 static int fdstart_IOFinish(fd_softc_t
*);
112 static int fdstart_IOErr(fd_softc_t
*);
113 static int fdstart_Fault(fd_softc_t
*);
114 static int fdstart_Exit(fd_softc_t
*);
126 static void hexDump(u_char
*, int);
129 * Stuff taken from Egan/Teixeira ch 8: 'if(TRACE_FOO)' debug output
130 * statements don't break indentation, and when DEBUG is not defined,
131 * the compiler code optimizer drops them as dead code.
134 #define M_TRACE_CONFIG 0x0001
135 #define M_TRACE_OPEN 0x0002
136 #define M_TRACE_CLOSE 0x0004
137 #define M_TRACE_READ 0x0008
138 #define M_TRACE_WRITE 0x0010
139 #define M_TRACE_STRAT (M_TRACE_READ | M_TRACE_WRITE)
140 #define M_TRACE_IOCTL 0x0020
141 #define M_TRACE_STEP 0x0040
142 #define M_TRACE_ALL 0xFFFF
144 #define TRACE_CONFIG (iwmDebugging & M_TRACE_CONFIG)
145 #define TRACE_OPEN (iwmDebugging & M_TRACE_OPEN)
146 #define TRACE_CLOSE (iwmDebugging & M_TRACE_CLOSE)
147 #define TRACE_READ (iwmDebugging & M_TRACE_READ)
148 #define TRACE_WRITE (iwmDebugging & M_TRACE_WRITE)
149 #define TRACE_STRAT (iwmDebugging & M_TRACE_STRAT)
150 #define TRACE_IOCTL (iwmDebugging & M_TRACE_IOCTL)
151 #define TRACE_STEP (iwmDebugging & M_TRACE_STEP)
152 #define TRACE_ALL (iwmDebugging & M_TRACE_ALL)
154 /* -1 = all active */
155 int iwmDebugging
= 0 /* | M_TRACE_OPEN | M_TRACE_STRAT | M_TRACE_IOCTL */ ;
158 #define TRACE_CONFIG 0
160 #define TRACE_CLOSE 0
162 #define TRACE_WRITE 0
163 #define TRACE_STRAT 0
164 #define TRACE_IOCTL 0
174 ** Module-global Variables
177 /* The IWM base address */
181 * Table of supported disk types.
182 * The table order seems to be pretty standardized across NetBSD ports, but
183 * then, they are all MFM... So we roll our own for now.
185 static fdInfo_t fdTypes
[] = {
186 {1, 80, 512, 10, 10, 800, 12, 2, IWM_GCR
, "400K Sony"},
187 {2, 80, 512, 10, 20, 1600, 12, 2, IWM_GCR
, "800K Sony"}
190 /* Table of GCR disk zones for one side (see IM II-211, The Disk Driver) */
191 static diskZone_t diskZones
[] = {
199 /* Drive format codes/indexes */
209 ** Autoconfiguration code
213 * Autoconfig data structures
215 * These data structures (see <sys/device.h>) are referenced in
216 * compile/$KERNEL/ioconf.c, which is generated by config(8).
217 * Their names are formed like {device}_{ca,cd}.
220 * is used for dynamically allocating driver data, probing and
221 * attaching a device;
224 * references all found devices of a type.
228 extern struct cfdriver iwm_cd
;
229 extern struct cfdriver fd_cd
;
231 #endif /* defined _MODULE */
233 /* IWM floppy disk controller */
234 CFATTACH_DECL(iwm
, sizeof(iwm_softc_t
),
235 iwm_match
, iwm_attach
, NULL
, NULL
);
237 /* Attached floppy disk drives */
238 CFATTACH_DECL(fd
, sizeof(fd_softc_t
),
239 fd_match
, fd_attach
, NULL
, NULL
);
241 dev_type_open(fdopen
);
242 dev_type_close(fdclose
);
243 dev_type_read(fdread
);
244 dev_type_write(fdwrite
);
245 dev_type_ioctl(fdioctl
);
246 dev_type_strategy(fdstrategy
);
248 const struct bdevsw fd_bdevsw
= {
249 fdopen
, fdclose
, fdstrategy
, fdioctl
, nodump
, nosize
, D_DISK
252 const struct cdevsw fd_cdevsw
= {
253 fdopen
, fdclose
, fdread
, fdwrite
, fdioctl
,
254 nostop
, notty
, nopoll
, nommap
, nokqfilter
, D_DISK
257 /* disk(9) framework device switch */
258 struct dkdriver fd_dkDriver
= {
262 /*** Configure the IWM controller ***/
267 * Is the IWM chip present? Here, *auxp is a ptr to struct confargs
268 * (see <mac68k/mac68k/autoconf.h>), which does not hold any information
269 * to match against. After all, that's what the obio concept is
270 * about: Onboard components that are present depending (only)
274 iwm_match(struct device
*parent
, struct cfdata
*match
, void *auxp
)
280 extern u_long IOBase
; /* from mac68k/machdep.c */
281 extern u_long IWMBase
;
283 if (0 == map_iwm_base(IOBase
)) {
285 * Unknown machine HW:
286 * The SWIM II/III chips that are present in post-Q700
287 * '040 Macs have dropped the IWM register structure.
288 * We know next to nothing about the SWIM.
292 printf("IWM or SWIM not found: Unknown location (SWIM II?).\n");
296 printf("iwm: IWMBase mapped to 0x%lx in VM.\n",
302 printf("initIWM() says %d.\n", iwmErr
);
303 matched
= (iwmErr
== 0) ? 1 : 0;
313 * The IWM is present, initialize it. Then look up the connected drives
317 iwm_attach(struct device
*parent
, struct device
*self
, void *auxp
)
323 printf(": Apple GCR floppy disk controller\n");
324 iwm
= (iwm_softc_t
*)self
;
328 printf("initIWM() says %d.\n", iwmErr
);
331 /* Set up the IWM softc */
332 iwm
->maxRetries
= 10;
334 /* Look for attached drives */
335 for (ia
.unit
= 0; ia
.unit
< IWM_MAX_DRIVE
; ia
.unit
++) {
336 iwm
->fd
[ia
.unit
] = NULL
;
337 ia
.driveType
= getFDType(ia
.unit
);
338 if (NULL
!= ia
.driveType
)
339 config_found(self
, (void *)&ia
,
343 printf("iwm: Initialization completed.\n");
345 printf("iwm: Chip revision not supported (%d)\n", iwmErr
);
351 * iwm_print -- print device configuration.
353 * If the device is not configured 'controller' it is NULL and
354 * we print a message in the *Attach routine; the return value
355 * of *Print() is ignored.
358 iwm_print(void *auxp
, const char *controller
)
367 * Map physical IO address of IWM to VM address
370 map_iwm_base(vm_offset_t base
)
373 extern u_long IWMBase
;
375 switch (current_mac_model
->class) {
379 IWMBase
= base
+ 0x1E000;
389 IWMBase
= base
+ 0x16000;
396 * Neither IIfx/Q9[05]0 style IOP controllers nor
397 * Q[68]40AV DMA based controllers are supported.
400 printf("Unknown floppy controller chip.\n");
409 /*** Configure Sony disk drive(s) ***/
415 fd_match(struct device
*parent
, struct cfdata
*match
, void *auxp
)
419 iwmAttachArgs_t
*fdParams
;
422 fdParams
= (iwmAttachArgs_t
*)auxp
;
423 cfUnit
= cfp
->cf_loc
[IWMCF_DRIVE
];
424 matched
= (cfUnit
== fdParams
->unit
|| cfUnit
== -1) ? 1 : 0;
426 printf("fdMatch() drive %d ? cfUnit = %d\n",
427 fdParams
->unit
, cfUnit
);
436 * We have checked that the IWM is fine and the drive is present,
437 * so we can attach it.
440 fd_attach(struct device
*parent
, struct device
*self
, void *auxp
)
447 iwm
= (iwm_softc_t
*)parent
;
448 fd
= (fd_softc_t
*)self
;
449 ia
= (iwmAttachArgs_t
*)auxp
;
451 driveInfo
= iwmCheckDrive(ia
->unit
);
453 fd
->currentType
= ia
->driveType
;
455 fd
->defaultType
= &fdTypes
[IWM_800K_GCR
];
456 fd
->stepDirection
= 0;
458 iwm
->fd
[ia
->unit
] = fd
; /* iwm has ptr to this drive */
461 bufq_alloc(&fd
->bufQueue
, "disksort", BUFQ_SORT_CYLINDER
);
462 callout_init(&fd
->motor_ch
, 0);
464 printf(" drive %d: ", fd
->unit
);
466 if (IWM_NO_DISK
& driveInfo
) {
467 printf("(drive empty)\n");
469 if (!(IWM_DD_DISK
& driveInfo
)) {
470 printf("(HD disk -- not supported)\n");
471 iwmDiskEject(fd
->unit
); /* XXX */
473 printf("%s %d cyl, %d head(s)\n",
474 fd
->currentType
->description
,
475 fd
->currentType
->tracks
,
476 fd
->currentType
->heads
);
481 /* List contents of drive status registers */
483 for (reg
= 0; reg
< 0x10; reg
++) {
484 flags
= iwmQueryDrvFlag(fd
->unit
, reg
);
485 printf("iwm: Drive register 0x%x = 0x%x\n", reg
, flags
);
489 disk_init(&fd
->diskInfo
, fd
->devInfo
.dv_xname
, &fd_dkDriver
);
490 disk_attach(&fd
->diskInfo
);
495 * fdPrint -- print device configuration.
497 * If the device is not configured 'controller' refers to a name string
499 * Else it is NULL and we print a message in the *Attach routine; the
500 * return value of *Print() is ignored.
503 fd_print(void *auxp
, const char *controller
)
507 ia
= (iwmAttachArgs_t
*)auxp
;
508 if (NULL
!= controller
)
509 aprint_normal("fd%d at %s", ia
->unit
, controller
);
516 static iwm_softc_t
*iwm
;
521 * Any initializations necessary after loading the module happen here.
528 iwm
= (iwm_softc_t
*)malloc(sizeof(iwm_softc_t
), M_DEVBUF
, M_WAITOK
);
530 err
= (1 == iwm_match(NULL
, NULL
, NULL
)) ? 0 : EIO
;
532 memset(iwm
, 0, sizeof(iwm_softc_t
));
533 iwm
->maxRetries
= 10;
534 err
= (0 == probe_fd()) ? 0 : EIO
;
543 * Necessary clean-up before unloading the module.
551 /* Release any allocated memory */
552 for (unit
= 0; unit
< IWM_MAX_DRIVE
; unit
++)
553 if (iwm
->fd
[unit
] != NULL
) {
555 * Let's hope there is only one task per drive,
558 callout_stop(&iwm
->fd
[unit
]->motor_ch
);
559 disk_detach(&iwm
->fd
[unit
]->diskInfo
);
560 disk_destroy(&iwm
->fd
[unit
]->diskInfo
);
561 free(iwm
->fd
[unit
], M_DEVBUF
);
562 iwm
->fd
[unit
] = NULL
;
572 * See if there are any drives out there and configure them.
573 * If we find a drive we allocate a softc structure for it and
574 * insert its address into the iwm_softc.
576 * XXX Merge the remainder of probeFD() with the autoconfig framework.
586 for (ia
.unit
= 0; ia
.unit
< IWM_MAX_DRIVE
; ia
.unit
++) {
587 ia
.driveType
= getFDType(ia
.unit
);
588 if (NULL
== ia
.driveType
) {
589 iwm
->fd
[ia
.unit
] = NULL
;
592 fd
= (fd_softc_t
*)malloc(sizeof(fd_softc_t
),
598 memset(fd
, 0, sizeof(fd_softc_t
));
600 /* This is usually set by the autoconfig framework */
601 sprintf(fd
->devInfo
.dv_xname
, "fd%d%c", ia
.unit
, 'a');
602 fd_attach((struct device
*)iwm
, (struct device
*)fd
,
607 /* Release any allocated memory */
608 for (unit
= 0; unit
< IWM_MAX_DRIVE
; unit
++)
609 if (iwm
->fd
[unit
] != NULL
) {
610 free(iwm
->fd
[unit
], M_DEVBUF
);
611 iwm
->fd
[unit
] = NULL
;
617 #endif /* defined _MODULE */
621 ** Implementation section of driver interface
623 ** The prototypes for these functions are set up automagically
624 ** by macros in mac68k/conf.c. Their names are generated from {fd}
625 ** and {open,close,strategy,dump,size,read,write}. The driver entry
626 ** points are then plugged into bdevsw[] and cdevsw[].
633 * Open a floppy disk device.
636 fdopen(dev_t dev
, int flags
, int devType
, struct lwp
*l
)
644 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0); /* XXX */
646 info
= NULL
; /* XXX shut up egcs */
647 fd
= NULL
; /* XXX shut up gcc3 */
650 * See <device.h> for struct cfdriver, <disklabel.h> for
651 * DISKUNIT() and <atari/atari/device.h> for getsoftc().
653 fdType
= minor(dev
) % MAXPARTITIONS
;
654 fdUnit
= minor(dev
) / MAXPARTITIONS
;
656 printf("iwm: Open drive %d", fdUnit
);
658 /* Check if device # is valid */
659 err
= (iwm
->drives
< fdUnit
) ? ENXIO
: 0;
661 (void)iwmSelectDrive(fdUnit
);
663 printf(".\n Get softc");
666 fd
= iwm
->fd
[fdUnit
];
667 err
= (NULL
== fd
) ? ENXIO
: 0;
670 if (fd
->state
& IWM_FD_IS_OPEN
) {
672 * Allow multiple open calls only if for identical
676 printf(".\n Drive already opened!\n");
677 err
= (fd
->partition
== fdType
) ? 0 : ENXIO
;
680 printf(".\n Get format info");
682 /* Get format type */
683 info
= fdDeviceToType(fd
, dev
);
687 printf(".\n No such drive.\n");
691 if (!err
&& !(fd
->state
& IWM_FD_IS_OPEN
)) {
693 printf(".\n Set diskInfo flags.\n");
695 fd
->writeLabel
= 0; /* XXX currently unused */
696 fd
->partition
= fdType
;
697 fd
->currentType
= info
;
698 fd
->drvFlags
= iwmCheckDrive(fd
->unit
);
700 if (fd
->drvFlags
& IWM_NO_DISK
) {
703 printf(" Drive %d is empty.\n", fd
->unit
);
706 if (!(fd
->drvFlags
& IWM_WRITABLE
) && (flags
& FWRITE
)) {
710 printf(" Disk is write protected.\n");
713 if (!(fd
->drvFlags
& IWM_DD_DISK
)) {
716 printf(" HD format not supported.\n");
718 (void)iwmDiskEject(fd
->unit
);
720 /* We're open now! */
721 fd
->state
|= IWM_FD_IS_OPEN
;
722 err
= initCylinderCache(fd
);
729 * Later, we might not want to recalibrate the drive when it
730 * is already open. For now, it doesn't hurt.
733 printf(" Seek track 00 says");
735 memset(&fd
->pos
, 0, sizeof(diskPosition_t
));
736 ierr
= seek(fd
, IWM_SEEK_RECAL
);
738 printf(" %d.\n", ierr
);
739 err
= (0 == ierr
) ? 0 : EIO
;
743 * Update disklabel if we are not yet open.
744 * (We shouldn't be: We are synchronous.)
746 if (fd
->diskInfo
.dk_openmask
== 0)
747 fdGetDiskLabel(fd
, dev
);
749 partitionMask
= (1 << fdType
);
753 fd
->diskInfo
.dk_copenmask
|= partitionMask
;
757 fd
->diskInfo
.dk_bopenmask
|= partitionMask
;
760 fd
->diskInfo
.dk_openmask
=
761 fd
->diskInfo
.dk_copenmask
| fd
->diskInfo
.dk_bopenmask
;
764 printf("iwm: fdopen() says %d.\n", err
);
773 fdclose(dev_t dev
, int flags
, int devType
, struct lwp
*l
)
776 int partitionMask
, fdUnit
, fdType
;
778 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0);
782 printf("iwm: Closing driver.");
783 fdUnit
= minor(dev
) / MAXPARTITIONS
;
784 fdType
= minor(dev
) % MAXPARTITIONS
;
785 fd
= iwm
->fd
[fdUnit
];
786 /* release cylinder cache memory */
787 if (fd
->cbuf
!= NULL
)
788 free(fd
->cbuf
, M_DEVBUF
);
790 partitionMask
= (1 << fdType
);
792 /* Set state flag. */
793 fd
->state
&= ~IWM_FD_IS_OPEN
;
797 fd
->diskInfo
.dk_copenmask
&= ~partitionMask
;
801 fd
->diskInfo
.dk_bopenmask
&= ~partitionMask
;
804 fd
->diskInfo
.dk_openmask
=
805 fd
->diskInfo
.dk_copenmask
| fd
->diskInfo
.dk_bopenmask
;
813 * We deal with all the disk-specific ioctls in <sys/dkio.h> here even if
814 * we do not support them.
817 fdioctl(dev_t dev
, u_long cmd
, void *data
, int flags
, struct lwp
*l
)
819 int result
, fdUnit
, fdType
;
822 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0);
826 printf("iwm: Execute ioctl... ");
828 /* Check if device # is valid and get its softc */
829 fdUnit
= minor(dev
) / MAXPARTITIONS
;
830 fdType
= minor(dev
) % MAXPARTITIONS
;
831 if (fdUnit
>= iwm
->drives
) {
833 printf("iwm: Wanted device no (%d) is >= %d.\n",
834 fdUnit
, iwm
->drives
);
838 fd
= iwm
->fd
[fdUnit
];
844 printf(" DIOCGDINFO: Get in-core disklabel.\n");
845 *(struct disklabel
*) data
= *(fd
->diskInfo
.dk_label
);
851 printf(" DIOCSDINFO: Set in-core disklabel.\n");
852 result
= ((flags
& FWRITE
) == 0) ? EBADF
: 0;
854 result
= setdisklabel(fd
->diskInfo
.dk_label
,
855 (struct disklabel
*)data
, 0,
856 fd
->diskInfo
.dk_cpulabel
);
861 printf(" DIOCWDINFO: Set in-core disklabel "
863 result
= ((flags
& FWRITE
) == 0) ? EBADF
: 0;
866 result
= setdisklabel(fd
->diskInfo
.dk_label
,
867 (struct disklabel
*)data
, 0,
868 fd
->diskInfo
.dk_cpulabel
);
870 result
= writedisklabel(dev
, fdstrategy
,
871 fd
->diskInfo
.dk_label
,
872 fd
->diskInfo
.dk_cpulabel
);
877 printf(" DIOCGPART: Get disklabel & partition table.\n");
878 ((struct partinfo
*)data
)->disklab
= fd
->diskInfo
.dk_label
;
879 ((struct partinfo
*)data
)->part
=
880 &fd
->diskInfo
.dk_label
->d_partitions
[fdType
];
887 printf(" DIOC{R,W}FORMAT: No formatter support (yet?).\n");
893 printf(" DIOCSSTEP: IWM does step handshake.\n");
899 printf(" DIOCSRETRIES: Set max. # of retries.\n");
900 if (*(int *)data
< 0)
903 iwm
->maxRetries
= *(int *)data
;
910 printf(" DIOCWLABEL: Set write access to disklabel.\n");
911 result
= ((flags
& FWRITE
) == 0) ? EBADF
: 0;
914 fd
->writeLabel
= *(int *)data
;
919 printf(" DIOCSBAD: No bad144-style handling.\n");
925 /* XXX Eject disk only when unlocked */
927 printf(" DIOCEJECT: Eject disk from unit %d.\n",
929 result
= iwmDiskEject(fd
->unit
);
933 /* XXX Use lock to prevent ejectimg a mounted disk */
935 printf(" DIOCLOCK: No need to (un)lock Sony drive.\n");
941 printf(" Not a disk related ioctl!\n");
953 fdread(dev_t dev
, struct uio
*uio
, int flags
)
955 return physio(fdstrategy
, NULL
, dev
, B_READ
, minphys
, uio
);
963 fdwrite(dev_t dev
, struct uio
*uio
, int flags
)
965 return physio(fdstrategy
, NULL
, dev
, B_WRITE
, minphys
, uio
);
972 * Entry point for read and write requests. The strategy routine usually
973 * queues io requests and kicks off the next transfer if the device is idle;
974 * but we get no interrupts from the IWM and have to do synchronous
975 * transfers - no queue.
978 fdstrategy(struct buf
*bp
)
980 int fdUnit
, err
, done
, spl
;
981 int sectSize
, transferSize
;
982 diskPosition_t physDiskLoc
;
985 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0);
990 sectSize
= 0; /* XXX shut up gcc3 */
991 fd
= NULL
; /* XXX shut up gcc3 */
993 fdUnit
= minor(bp
->b_dev
) / MAXPARTITIONS
;
995 printf("iwm: fdstrategy()...\n");
996 printf(" struct buf is at %p\n", bp
);
997 printf(" Allocated buffer size (b_bufsize): 0x0%x\n",
999 printf(" Base address of buffer (b_data): %p\n",
1001 printf(" Bytes to be transferred (b_bcount): 0x0%x\n",
1003 printf(" Remaining I/O (b_resid): 0x0%x\n",
1006 /* Check for valid fd unit, controller and io request */
1008 if (fdUnit
>= iwm
->drives
) {
1010 printf(" No such unit (%d)\n", fdUnit
);
1014 fd
= iwm
->fd
[fdUnit
];
1015 err
= (NULL
== fd
) ? EINVAL
: 0;
1018 sectSize
= fd
->currentType
->sectorSize
;
1020 || (bp
->b_bcount
% sectSize
) != 0) {
1022 printf(" Illegal transfer size: "
1023 "block %lld, %d bytes\n",
1024 (long long) bp
->b_blkno
, bp
->b_bcount
);
1029 /* Null transfer: Return, nothing to do. */
1030 if (0 == bp
->b_bcount
) {
1032 printf(" Zero transfer length.\n");
1036 if (!err
&& !done
) {
1037 /* What to do if we touch the boundaries of the disk? */
1038 transferSize
= (bp
->b_bcount
+ (sectSize
- 1)) / sectSize
;
1039 if (bp
->b_blkno
+ transferSize
> fd
->currentType
->secPerDisk
) {
1041 printf("iwm: Transfer beyond end of disk!\n" \
1042 " (Starting block %lld, # of blocks %d," \
1043 " last disk block %d).\n",
1044 (long long) bp
->b_blkno
, transferSize
,
1045 fd
->currentType
->secPerDisk
);
1047 /* Return EOF if we are exactly at the end of the
1048 * disk, EINVAL if we try to reach past the end; else
1049 * truncate the request. */
1050 transferSize
= fd
->currentType
->secPerDisk
-
1052 if (0 == transferSize
) {
1053 bp
->b_resid
= bp
->b_bcount
;
1056 if (0 > transferSize
)
1059 bp
->b_bcount
= transferSize
<< DEV_BSHIFT
;
1062 if (!err
&& !done
) {
1064 * Calculate cylinder # for disksort().
1066 * XXX Shouldn't we use the (fake) logical cyl no here?
1068 remap_geometry(bp
->b_blkno
, fd
->currentType
->heads
,
1070 bp
->b_rawblkno
= bp
->b_blkno
;
1071 bp
->b_cylinder
= physDiskLoc
.track
;
1074 printf(" This job starts at b_blkno %lld; ",
1075 (long long) bp
->b_blkno
);
1076 printf("it gets sorted for cylinder # %d.\n",
1080 callout_stop(&fd
->motor_ch
);
1081 bufq_put(fd
->bufQueue
, bp
);
1082 if (fd
->sc_active
== 0)
1086 /* Clean up, if necessary */
1089 printf(" fdstrategy() finished early, err = %d.\n",
1093 bp
->b_resid
= bp
->b_bcount
;
1096 /* Comment on results */
1098 printf("iwm: fdstrategy() done.\n");
1099 printf(" We have b_resid = %d bytes left, " \
1100 "b_error is %d;\n", bp
->b_resid
, bp
->b_error
);
1101 printf(" b_flags are 0x0%x.\n", bp
->b_flags
);
1107 /* ======================================================================== */
1113 * we are called from the strategy() routine to perform a data transfer.
1115 * The disk(9) framework demands we run at splbio(); our caller
1116 * takes care of that.
1118 * Wish we had pascalish local functions here...
1121 /* fdstart FSM states */
1136 fdstart(fd_softc_t
*fd
)
1140 static const char *stateDesc
[] = {
1152 int (*state
[])(fd_softc_t
*) = {
1167 printf(" fdstart state %d [%s] ",
1170 st
= (*state
[st
])(fd
);
1174 } while (st
!= state_Done
);
1184 fdstart_Init(fd_softc_t
*fd
)
1189 * Get the first entry from the queue. This is the buf we gave to
1190 * fdstrategy(); disksort() put it into our softc.
1192 bp
= bufq_peek(fd
->bufQueue
);
1195 printf("Queue empty: Nothing to do");
1198 fd
->ioDirection
= bp
->b_flags
& B_READ
;
1200 disk_busy(&fd
->diskInfo
);
1201 if (!(fd
->state
& IWM_FD_MOTOR_ON
)) {
1202 iwmMotor(fd
->unit
, 1);
1203 fd
->state
|= IWM_FD_MOTOR_ON
;
1205 fd
->current_buffer
= bp
->b_data
;
1207 /* XXX - assumes blocks of 512 bytes */
1208 fd
->startBlk
= bp
->b_blkno
;
1211 fd
->ioRetries
= 0; /* XXX */
1212 fd
->seekRetries
= 0;
1214 fd
->bytesLeft
= bp
->b_bcount
;
1223 fdstart_Seek(fd_softc_t
*fd
)
1227 /* Calculate the side/track/sector our block is at. */
1229 printf(" Remap block %lld ", (long long) fd
->startBlk
);
1230 remap_geometry(fd
->startBlk
,
1231 fd
->currentType
->heads
, &fd
->pos
);
1233 printf("to c%d_h%d_s%d ", fd
->pos
.track
,
1234 fd
->pos
.side
, fd
->pos
.sector
);
1236 if (fd
->cachedSide
!= fd
->pos
.side
) {
1238 printf(" (invalidate cache) ");
1239 invalidateCylinderCache(fd
);
1240 fd
->cachedSide
= fd
->pos
.side
;
1244 * If necessary, seek to wanted track. Note that
1245 * seek() performs any necessary retries.
1247 if (fd
->pos
.track
!= fd
->pos
.oldTrack
&&
1248 0 != (fd
->iwmErr
= seek(fd
, IWM_SEEK_VANILLA
))) {
1249 state
= state_Fault
;
1251 state
= (fd
->ioDirection
== IWM_WRITE
)
1252 ? state_Write
: state_Read
;
1261 * Transfer a sector from disk. Get it from the track cache, if available;
1262 * otherwise, while we are at it, store in the cache all the sectors we find
1265 * Track buffering reads:
1266 * o Look if the sector is already cached.
1267 * o Else, read sectors into track cache until we meet the header of
1268 * the sector we want.
1269 * o Read that sector directly to fs buffer and return.
1272 fdstart_Read(fd_softc_t
*fd
)
1275 diskPosition_t
*pos
;
1278 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0); /* XXX */
1281 /* Initialize retry counters */
1282 fd
->seekRetries
= 0;
1283 fd
->sectRetries
= 0;
1288 printf("<%s c%d_h%d_s%d> ",
1289 fd
->ioDirection
? "Read" : "Write",
1290 pos
->track
, pos
->side
, pos
->sector
);
1292 /* Sector already cached? */
1294 if (fd
->r_slots
[i
].valid
) {
1297 memcpy(fd
->current_buffer
, fd
->r_slots
[i
].secbuf
,
1298 fd
->currentType
->sectorSize
);
1299 return state_IOFinish
;
1302 /* Get sector from disk */
1303 shdr
->side
= pos
->side
;
1304 shdr
->sector
= pos
->sector
;
1305 shdr
->track
= pos
->track
;
1307 (void)iwmSelectSide(pos
->side
);
1308 fd
->iwmErr
= iwmReadSector(&fd
->sHdr
, fd
->r_slots
,
1309 fd
->current_buffer
);
1311 /* Check possible error conditions */
1313 printf("c%d_h%d_s%d_err(%d)_sr%d ",
1314 shdr
->track
, shdr
->side
>> 3,
1315 shdr
->sector
, fd
->iwmErr
, fd
->sectRetries
);
1318 if (fd
->iwmErr
!= 0)
1321 /* Bad seek? Retry */
1322 if (shdr
->track
!= pos
->track
) {
1324 printf("Wanted track %d, got %d, %d seek retries.\n",
1325 pos
->track
, shdr
->track
, fd
->seekRetries
);
1327 if (iwm
->maxRetries
> fd
->seekRetries
++) {
1328 fd
->iwmErr
= seek(fd
, IWM_SEEK_RECAL
);
1330 printf("[%d]", fd
->seekRetries
);
1331 (void)checkTrack(&fd
->pos
, 1);
1334 fd
->iwmErr
= seekErr
;
1335 return (0 == fd
->iwmErr
) ? state_Read
: state_Fault
;
1338 /* Sector not found? */
1339 if (shdr
->sector
!= pos
->sector
) {
1341 printf("c%d_h%d_s%d sect not found, %d retries ",
1342 shdr
->track
, shdr
->side
>> 3,
1343 shdr
->sector
, fd
->sectRetries
);
1344 fd
->iwmErr
= noAdrMkErr
;
1349 return state_IOFinish
;
1356 * Insert a sector into a write buffer slot and mark the slot dirty.
1359 fdstart_Write(fd_softc_t
*fd
)
1363 /* XXX let's see... */
1364 fd
->sHdr
.side
= fd
->pos
.side
;
1365 fd
->sHdr
.sector
= fd
->pos
.sector
;
1366 fd
->sHdr
.track
= fd
->pos
.track
;
1369 fd
->w_slots
[i
].secbuf
= fd
->current_buffer
;
1370 fd
->w_slots
[i
].valid
= 1; /* "valid" is a dirty buffer here */
1373 printf("<%s c%d_h%d_s%d> (cached) ",
1374 fd
->ioDirection
? "Read" : "Write",
1375 fd
->pos
.track
, fd
->pos
.side
, fd
->pos
.sector
);
1376 return state_IOFinish
;
1384 * Flush dirty buffers in the track cache to disk.
1387 fdstart_Flush(fd_softc_t
*fd
)
1391 diskPosition_t
*pos
;
1394 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0); /* XXX */
1401 for (i
=0; i
< IWM_MAX_GCR_SECTORS
; i
++)
1402 if (fd
->w_slots
[i
].valid
) {
1408 printf(" <%s c%d_h%d_#s%d>\n",
1409 fd
->ioDirection
? "Read" : "Write",
1410 pos
->track
, pos
->side
, dcnt
);
1412 (void)iwmSelectSide(pos
->side
);
1413 fd
->iwmErr
= iwmWriteSector(&fd
->sHdr
, fd
->w_slots
);
1415 switch (fd
->iwmErr
) {
1416 case noErr
: /* Success */
1418 /* XXX Panic if buffer not clean? */
1419 for (i
=0; i
<IWM_MAX_GCR_SECTORS
; i
++)
1420 if (0 != fd
->w_slots
[i
].valid
)
1421 printf("Oops! <c%d_h%d_s%d> not flushed.\n",
1422 fd
->pos
.track
, fd
->pos
.side
,
1426 printf("(Cache flushed, re-initialize) ");
1427 for (i
=0; i
< IWM_MAX_GCR_SECTORS
; i
++) {
1428 fd
->w_slots
[i
].valid
= 0;
1429 fd
->w_slots
[i
].secbuf
= NULL
;
1431 fd
->seekRetries
= 0;
1435 case seekErr
: /* Bad seek? Retry */
1437 printf("Wanted track %d, got %d, %d seek retries.\n",
1438 pos
->track
, shdr
->track
, fd
->seekRetries
);
1440 if (iwm
->maxRetries
> fd
->seekRetries
++) {
1441 fd
->iwmErr
= seek(fd
, IWM_SEEK_RECAL
);
1443 printf("[%d]", fd
->seekRetries
);
1446 state
= (0 == fd
->iwmErr
) ? state_Exit
: state_Fault
;
1449 default: /* General IWM IO error? */
1450 state
= state_IOErr
;
1459 * Prepare for next block, if any is available
1462 fdstart_IOFinish(fd_softc_t
*fd
)
1466 if (DISABLED
&& TRACE_STRAT
)
1467 printf("%s c%d_h%d_s%d ok ",
1468 fd
->ioDirection
? "Read" : "Write",
1469 fd
->sHdr
.track
, fd
->sHdr
.side
>> 3, fd
->sHdr
.sector
);
1471 fd
->bytesDone
+= fd
->currentType
->sectorSize
;
1472 fd
->bytesLeft
-= fd
->currentType
->sectorSize
;
1473 fd
->current_buffer
+= fd
->currentType
->sectorSize
;
1475 * Instead of recalculating the chs mapping for
1476 * each and every sector, check for
1477 * 'current sector# <= max sector#' and recalculate
1481 if (fd
->bytesLeft
> 0) {
1482 if (++fd
->pos
.sector
< fd
->pos
.maxSect
) {
1485 state
= (fd
->ioDirection
== IWM_WRITE
)
1486 ? state_Write
: state_Read
;
1490 * Invalidate read cache when changing track;
1491 * flush write cache to disk.
1493 if (fd
->ioDirection
== IWM_WRITE
) {
1496 state
= (state_Exit
== fdstart_Flush(fd
))
1497 ? state_Seek
: state_IOErr
;
1502 invalidateCylinderCache(fd
);
1507 state
= (fd
->ioDirection
== IWM_WRITE
)
1508 ? state_Flush
: state_Exit
;
1520 fdstart_IOErr(fd_softc_t
*fd
)
1524 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0); /* XXX */
1528 printf("iwm%sSector() err = %d, %d retries, on c%d_h%d_s%d.\n",
1529 fd
->ioDirection
? "Read" : "Write",
1530 fd
->iwmErr
, fd
->ioRetries
, fd
->pos
.track
,
1531 fd
->pos
.side
, fd
->pos
.sector
);
1533 /* XXX Do statistics */
1534 if (fd
->ioRetries
++ < iwm
->maxRetries
)
1535 state
= (fd
->ioDirection
== IWM_WRITE
)
1536 ? state_Flush
: state_Read
;
1538 state
= state_Fault
;
1546 * A non-recoverable error
1549 fdstart_Fault(fd_softc_t
*fd
)
1552 printf("Seek retries %d, IO retries %d, sect retries %d :\n" \
1553 "\t\t only found c%d_h%d_s%d \n",
1554 fd
->seekRetries
, fd
->ioRetries
, fd
->sectRetries
,
1555 fd
->sHdr
.track
, fd
->sHdr
.side
>> 3, fd
->sHdr
.sector
);
1556 printf("A non-recoverable error: %d ", fd
->iwmErr
);
1567 * We are done, for good or bad
1570 fdstart_Exit(fd_softc_t
*fd
)
1577 invalidateCylinderCache(fd
);
1580 /* XXX Panic if buffer not clean? */
1581 for (i
=0; i
<IWM_MAX_GCR_SECTORS
; i
++)
1582 if (0 != fd
->w_slots
[i
].valid
)
1583 printf("Oops! <c%d_h%d_s%d> not flushed.\n",
1584 fd
->pos
.track
, fd
->pos
.side
, fd
->pos
.sector
);
1587 bp
= bufq_get(fd
->bufQueue
);
1589 bp
->b_resid
= fd
->bytesLeft
;
1590 bp
->b_error
= (0 == fd
->iwmErr
) ? 0 : EIO
;
1593 printf(" fdstart() finished job; fd->iwmErr = %d, b_error = %d",
1594 fd
->iwmErr
, bp
->b_error
);
1596 hexDump(bp
->b_data
, bp
->b_bcount
);
1598 if (DISABLED
&& TRACE_STRAT
)
1599 printf(" Next buf (bufQueue first) at %p\n",
1600 bufq_peek(fd
->bufQueue
));
1601 disk_unbusy(&fd
->diskInfo
, bp
->b_bcount
- bp
->b_resid
,
1602 (bp
->b_flags
& B_READ
));
1605 * Stop motor after 10s
1607 * XXX Unloading the module while the timeout is still
1608 * running WILL crash the machine.
1610 callout_reset(&fd
->motor_ch
, 10 * hz
, motor_off
, fd
);
1619 * Remap the rigid UN*X view of a disk's cylinder/sector geometry
1620 * to our zone recorded real Sony drive by splitting the disk
1624 * Look if logical block number is in current zone
1625 * NO: Add # of tracks for current zone to track counter
1628 * YES: Subtract (number of first sector of current zone times heads)
1629 * from logical block number, then break up the difference
1630 * in tracks/side/sectors (spt is constant within a zone).
1635 remap_geometry(daddr_t block
, int heads
, diskPosition_t
*loc
)
1638 extern diskZone_t diskZones
[];
1640 spt
= 0; /* XXX Shut up egcs warning */
1641 loc
->oldTrack
= loc
->track
;
1644 for (zone
= 0; zone
< IWM_GCR_DISK_ZONES
; zone
++) {
1645 if (block
>= heads
* (diskZones
[zone
].lastBlock
+ 1)) {
1646 /* Process full zones */
1647 loc
->track
+= diskZones
[zone
].tracks
;
1649 /* Process partial zone */
1650 spt
= diskZones
[zone
].sectPerTrack
;
1651 block
-= heads
* diskZones
[zone
].firstBlock
;
1652 loc
->track
+= block
/ (spt
* heads
);
1653 loc
->sector
= (block
% spt
);
1654 loc
->side
= (block
% (spt
* heads
)) / spt
;
1665 * Callback for timeout()
1668 motor_off(void *param
)
1673 fd
= (fd_softc_t
*)param
;
1675 printf("iwm: Switching motor OFF (timeout).\n");
1677 (void)iwmMotor(fd
->unit
, 0);
1678 fd
->state
&= ~IWM_FD_MOTOR_ON
;
1686 * Set up disk label with parameters from current disk type.
1687 * Then call the generic disklabel read routine which tries to
1688 * read a label from disk and insert it. If it doesn't exist use
1692 fdGetDiskLabel(fd_softc_t
*fd
, dev_t dev
)
1696 struct disklabel
*lp
;
1697 struct cpu_disklabel
*clp
;
1700 printf("iwm: fdGetDiskLabel() for disk %" PRIu64
".\n",
1701 (dev_t
) (minor(dev
) / MAXPARTITIONS
));
1702 fdType
= minor(dev
) % MAXPARTITIONS
;
1703 lp
= fd
->diskInfo
.dk_label
;
1704 clp
= fd
->diskInfo
.dk_cpulabel
;
1705 memset(lp
, 0, sizeof(struct disklabel
));
1706 memset(clp
, 0, sizeof(struct cpu_disklabel
));
1708 * How to describe a drive with a variable # of sectors per
1709 * track (8..12) and variable rpm (300..550)? Apple came up
1710 * with ZBR in 1983! Un*x drive management sucks.
1712 lp
->d_type
= DTYPE_FLOPPY
;
1714 lp
->d_secsize
= fd
->currentType
->sectorSize
;
1715 lp
->d_ntracks
= fd
->currentType
->heads
;
1716 lp
->d_ncylinders
= fd
->currentType
->tracks
;
1717 lp
->d_nsectors
= fd
->currentType
->secPerTrack
;
1718 lp
->d_secpercyl
= fd
->currentType
->secPerCyl
;
1719 lp
->d_secperunit
= fd
->currentType
->secPerDisk
;
1720 lp
->d_interleave
= fd
->currentType
->interleave
;
1721 lp
->d_trkseek
= fd
->currentType
->stepRate
;
1723 strcpy(lp
->d_typename
, dktypenames
[DTYPE_FLOPPY
]);
1724 strncpy(lp
->d_packname
, "fictitious", sizeof(lp
->d_packname
));
1726 lp
->d_npartitions
= fdType
+ 1;
1727 lp
->d_partitions
[fdType
].p_offset
= 0;
1728 lp
->d_partitions
[fdType
].p_size
= lp
->d_secperunit
;
1729 lp
->d_partitions
[fdType
].p_fstype
= FS_BSDFFS
;
1730 lp
->d_partitions
[fdType
].p_fsize
= 512;
1731 lp
->d_partitions
[fdType
].p_frag
= 8;
1733 lp
->d_magic
= DISKMAGIC
;
1734 lp
->d_magic2
= DISKMAGIC
;
1735 lp
->d_checksum
= dkcksum(lp
);
1737 * Call the generic disklabel extraction routine. If we don't
1738 * find a label on disk, keep our faked one.
1741 printf(" now calling readdisklabel()...\n");
1743 msg
= readdisklabel(dev
, fdstrategy
, lp
, clp
);
1745 strncpy(lp
->d_packname
, "default label",
1746 sizeof(lp
->d_packname
)); /* XXX - ?? */
1750 printf("iwm: %s.\n", msg
);
1753 fdPrintDiskLabel(lp
);
1761 * Allocate cylinder cache and set up pointers to sectors.
1764 initCylinderCache(fd_softc_t
*fd
)
1771 secsize
= fd
->currentType
->sectorSize
;
1774 fd
->cbuf
= (unsigned char *) malloc(IWM_MAX_GCR_SECTORS
1775 * secsize
, M_DEVBUF
, M_WAITOK
);
1776 if (NULL
== fd
->cbuf
)
1779 for (i
=0; i
< IWM_MAX_GCR_SECTORS
; i
++) {
1780 fd
->w_slots
[i
].valid
= 0;
1781 fd
->w_slots
[i
].secbuf
= NULL
;
1783 fd
->r_slots
[i
].valid
= 0;
1784 fd
->r_slots
[i
].secbuf
= fd
->cbuf
+ i
* secsize
;
1791 * invalidateCylinderCache
1793 * Switching cylinders (tracks?) invalidates the read cache.
1796 invalidateCylinderCache(fd_softc_t
*fd
)
1801 for (i
=0; i
< IWM_MAX_GCR_SECTORS
; i
++) {
1802 fd
->r_slots
[i
].valid
= 0;
1810 * return pointer to disk format description
1813 getFDType(short unit
)
1817 extern fdInfo_t fdTypes
[];
1819 driveFlags
= iwmCheckDrive(unit
);
1821 * Drive flags are: Bit 0 - 1 = Drive is double sided
1822 * 1 - 1 = No disk inserted
1823 * 2 - 1 = Motor is off
1824 * 3 - 1 = Disk is writable
1825 * 4 - 1 = Disk is DD (800/720K)
1826 * 31 - 1 = No drive / invalid drive #
1829 printf("iwm: Drive %d says 0x0%x (%d)\n",
1830 unit
, driveFlags
, driveFlags
);
1833 thisType
= NULL
;/* no such drive */
1835 if (driveFlags
& 0x01)
1836 thisType
= &fdTypes
[1]; /* double sided */
1838 thisType
= &fdTypes
[0]; /* single sided */
1847 * maps the minor device number (elsewhere: partition type) to
1848 * a corresponding disk format.
1849 * This is currently:
1850 * fdXa default (800K GCR)
1855 fdDeviceToType(fd_softc_t
*fd
, dev_t dev
)
1859 /* XXX This broke with egcs 1.0.2 */
1860 /* extern fdInfo_t fdTypes[]; */
1862 type
= minor(dev
) % MAXPARTITIONS
; /* 1,2,... */
1863 if (type
> sizeof(fdTypes
) / sizeof(fdTypes
[0]))
1866 thisInfo
= (type
== 0) ? fd
->defaultType
: &fdTypes
[type
- 1];
1874 * Step to given track; optionally restore to track zero before
1875 * and/or verify correct track.
1876 * Note that any necessary retries are done here.
1877 * We keep the current position on disk in a 'struct diskPosition'.
1880 seek(fd_softc_t
*fd
, int style
)
1886 diskPosition_t
*loc
;
1890 iwm_softc_t
*iwm
= device_lookup_private(&iwm_cd
, 0); /* XXX */
1893 const char *stateDesc
[] = {
1901 seek_state_Init
= 0,
1903 seek_state_Recalibrate
,
1908 done
= err
= ierr
= 0;
1909 fd
->seekRetries
= 0;
1910 fd
->verifyRetries
= 0;
1914 state
= seek_state_Init
;
1917 printf(" seek state %d [%s].\n",
1918 state
, stateDesc
[state
]);
1921 case seek_state_Init
:
1923 printf("Current track is %d, new track %d.\n",
1924 loc
->oldTrack
, loc
->track
);
1925 memset(&hdr
, 0, sizeof(hdr
));
1927 fd
->seekRetries
= 0;
1928 fd
->verifyRetries
= 0;
1929 state
= (style
== IWM_SEEK_RECAL
)
1930 ? seek_state_Recalibrate
: seek_state_Seek
;
1934 case seek_state_Recalibrate
:
1935 ierr
= iwmTrack00();
1938 state
= seek_state_Seek
;
1940 strncpy(action
, "Recalibrate (track 0)",
1942 state
= seek_state_Exit
;
1946 case seek_state_Seek
:
1948 steps
= loc
->track
- loc
->oldTrack
;
1951 ierr
= iwmSeek(steps
);
1953 /* No error or nothing to do */
1954 state
= (style
== IWM_SEEK_VERIFY
)
1955 ? seek_state_Verify
: seek_state_Exit
;
1957 if (fd
->seekRetries
++ < iwm
->maxRetries
)
1958 state
= seek_state_Recalibrate
;
1960 strncpy(action
, "Seek retries",
1962 state
= seek_state_Exit
;
1967 case seek_state_Verify
:
1968 ierr
= checkTrack(loc
, TRACE_STEP
);
1969 if (ierr
== 0 && loc
->track
== hdr
.track
)
1970 state
= seek_state_Exit
;
1972 if (fd
->verifyRetries
++ < iwm
->maxRetries
)
1973 state
= seek_state_Recalibrate
;
1975 strncpy(action
, "Verify retries",
1977 state
= seek_state_Exit
;
1982 case seek_state_Exit
:
1984 loc
->oldTrack
= loc
->track
;
1986 /* Give the head some time to settle down */
1990 printf(" seek() action \"%s\", err = %d.\n",
2006 * After positioning, get a sector header for validation
2009 checkTrack(diskPosition_t
*loc
, int debugFlag
)
2016 iwmSelectSide(loc
->side
);
2017 iwmErr
= iwmReadSectHdr(&hdr
);
2020 printf("Seeked for %d, got at %d, Hdr read err %d.\n",
2021 loc
->track
, hdr
.track
, iwmErr
);
2027 /* Debugging stuff */
2030 hexDump(u_char
*buf
, int len
)
2035 printf("\nDump %d from %p:\n", len
, buf
);
2037 if (NULL
!= buf
) do {
2038 printf("%04x: ", i
);
2039 for (j
= 0; j
< 8; j
++)
2040 printf("%02x ", buf
[i
+ j
]);
2042 for (j
= 8; j
< 16; j
++)
2043 printf("%02x ", buf
[i
+ j
]);
2045 for (j
= 0; j
< 16; j
++) {
2047 if (ch
> 31 && ch
< 127)
2059 fdPrintDiskLabel(struct disklabel
*lp
)
2063 printf("iwm: Disklabel entries of current floppy.\n");
2064 printf("\t d_type:\t%d (%s)\n", lp
->d_type
,
2065 dktypenames
[lp
->d_type
]);
2066 printf("\t d_typename:\t%s\n", lp
->d_typename
);
2067 printf("\t d_packname:\t%s\n", lp
->d_packname
);
2069 printf("\t d_secsize:\t%d\n", lp
->d_secsize
);
2070 printf("\t d_nsectors:\t%d\n", lp
->d_nsectors
);
2071 printf("\t d_ntracks:\t%d\n", lp
->d_ntracks
);
2072 printf("\t d_ncylinders:\t%d\n", lp
->d_ncylinders
);
2073 printf("\t d_secpercyl:\t%d\n", lp
->d_secpercyl
);
2074 printf("\t d_secperunit:\t%d\n", lp
->d_secperunit
);
2076 printf("\t d_rpm: \t%d\n", lp
->d_rpm
);
2077 printf("\t d_interleave:\t%d\n", lp
->d_interleave
);
2078 printf("\t d_trkseek:\t%d [ms]\n", lp
->d_trkseek
);
2080 printf(" d_npartitions:\t%d\n", lp
->d_npartitions
);
2081 for (i
= 0; i
< lp
->d_npartitions
; i
++) {
2082 printf("\t d_partitions[%d].p_offset:\t%d\n", i
,
2083 lp
->d_partitions
[i
].p_offset
);
2084 printf("\t d_partitions[%d].p_size:\t%d\n", i
,
2085 lp
->d_partitions
[i
].p_size
);
2086 printf("\t d_partitions[%d].p_fstype:\t%d (%s)\n", i
,
2087 lp
->d_partitions
[i
].p_fstype
,
2088 fstypenames
[lp
->d_partitions
[i
].p_fstype
]);
2089 printf("\t d_partitions[%d].p_frag:\t%d\n", i
,
2090 lp
->d_partitions
[i
].p_frag
);