Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 10 Mar 2001 13:51:33 -0700
From:      Warner Losh <imp@harmony.village.org>
To:        sos@freebsd.org, mobile@freebsd.org
Subject:   iomega clik!
Message-ID:  <200103102051.f2AKpXI20839@harmony.village.org>

next in thread | raw e-mail | index | archive | help
I just got one of those cool pccard clik! drives.  The ones with the
drive integrated into the card.

Turns out they don't grok the mode sense for page
ATAPI_REWRITEABLE_CAP_PAGE, nor the ejection prevention commands
(ATAPI_PREVENT_ALLOW).  So we fake it.

These patches are loosely based on patches that Tetsuo Sakaguchi-san
<saka@ulis.ac.jp> posted in [bsd-nomads:14262] against 2.2.8 + PAO
wfd.c.  I didn't see anything in the message to indicate if
Sakagushi-san is the athor of these patches, or if he was just passing
them along.  If you commit this, please give credit something like:

Submitted by: imp based on earlier patches by Tetsuo Sakaguchi-san
	<saka@ulis.ac.jp>

In addition, they fix a kernel panic when an atapi driver fails to
attach and is later detached.  We do this by adding a check to see if
adp is non-NULL before using it in atapi_detach().  Maybe a better way
would be to clear the present bit in the parent bus, but I'm not sure
what the implications of doing that would be.

I don't have any atapi fd devices to test these patches with.  I'm
fairly certain I didn't break anything, but am posting these here in
case I did.

Warner

Index: atapi-all.c
===================================================================
RCS file: /cache/ncvs/src/sys/dev/ata/atapi-all.c,v
retrieving revision 1.63
diff -u -r1.63 atapi-all.c
--- atapi-all.c	2001/02/12 08:34:07	1.63
+++ atapi-all.c	2001/03/10 18:43:13
@@ -121,6 +121,12 @@
 void
 atapi_detach(struct atapi_softc *atp)
 {
+    /*
+     * atp will be NULL when the child failed to attach.
+     */
+    if (atp == NULL)
+	return;
+
     switch (ATP_PARAM->device_type) {
 #ifdef DEV_ATAPICD
     case ATAPI_TYPE_CDROM:
Index: atapi-fd.c
===================================================================
RCS file: /cache/ncvs/src/sys/dev/ata/atapi-fd.c,v
retrieving revision 1.58
diff -u -r1.58 atapi-fd.c
--- atapi-fd.c	2001/03/06 09:42:46	1.58
+++ atapi-fd.c	2001/03/10 20:32:53
@@ -67,6 +67,7 @@
 
 /* prototypes */
 static int afd_sense(struct afd_softc *);
+static int afd_clik_sense(struct afd_softc *);
 static void afd_describe(struct afd_softc *);
 static int afd_partial_done(struct atapi_request *);
 static int afd_done(struct atapi_request *);
@@ -93,13 +94,19 @@
     fdp->atp = atp;
     fdp->lun = ata_get_lun(&afd_lun_map);
 
+    if (!strncmp(ATA_PARAM(atp->controller, atp->unit)->model,
+                 "IOMEGA Clik!", 12))
+	fdp->iomega_clik = 1;
+    else
+	fdp->iomega_clik = 0;
+
     if (afd_sense(fdp)) {
 	free(fdp, M_AFD);
 	return -1;
     }
 
-    if (!strncmp(ATA_PARAM(fdp->atp->controller, fdp->atp->unit)->model, 
-		 "IOMEGA ZIP", 10))
+    if (!strncmp(ATA_PARAM(atp->controller, atp->unit)->model,
+                 "IOMEGA ZIP", 10))
 	fdp->transfersize = 64;
 
     devstat_add_entry(&fdp->stats, "afd", fdp->lun, DEV_BSIZE,
@@ -131,7 +138,35 @@
     free(fdp, M_AFD);
 }   
 
+/*
+ * The iomega clik, like other iomega, it a pain in the backside.
+ * It doesn't support the ATAPI_REWRITABLE_CAP_PAGE, so we have 
+ * to fake it up.  In addition, we have to kick the drive to make
+ * sure that it is something approaching sane.  But test_ready
+ * appears to fail when a disk isn't inserted.
+ */
 static int 
+afd_clik_sense(struct afd_softc *fdp)
+{
+    atapi_test_ready(fdp->atp);
+
+    fdp->transfersize = 64;
+    fdp->header.wp = 0;
+    fdp->header.medium_type = MFD_CLIK;
+    fdp->cap.page_code = ATAPI_REWRITEABLE_CAP_PAGE;
+    fdp->cap.ps = 0;
+    fdp->cap.page_length = 0;
+    fdp->cap.transfer_rate = 500;
+    fdp->cap.heads = CLIK_HEADS;
+    fdp->cap.sectors = CLIK_SECTORS;
+    fdp->cap.sector_size = CLIK_SECTOR_SIZE;
+    fdp->cap.cylinders = CLIK_CYLS;
+    fdp->cap.motor_delay = 1;
+    fdp->cap.rpm = 3600;
+    return 0;
+}
+
+static int 
 afd_sense(struct afd_softc *fdp)
 {
     int8_t buffer[256];
@@ -140,6 +175,8 @@
 		       0, 0, 0, 0, 0, 0, 0 };
     int count, error = 0;
 
+    if (fdp->iomega_clik)
+	return (afd_clik_sense(fdp));
     bzero(buffer, sizeof(buffer));
     /* get drive capabilities, some drives needs this repeated */
     for (count = 0 ; count < 5 ; count++) {
@@ -423,5 +460,8 @@
     int8_t ccb[16] = { ATAPI_PREVENT_ALLOW, 0, 0, 0, lock,
 		       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     
+    if (fdp->iomega_clik)
+	return 0;
+
     return atapi_queue_cmd(fdp->atp, ccb, NULL, 0, 0,30, NULL, NULL);
 }
Index: atapi-fd.h
===================================================================
RCS file: /cache/ncvs/src/sys/dev/ata/atapi-fd.h,v
retrieving revision 1.13
diff -u -r1.13 atapi-fd.h
--- atapi-fd.h	2001/01/10 19:19:47	1.13
+++ atapi-fd.h	2001/03/10 19:39:34
@@ -39,6 +39,7 @@
 #define MFD_HD_12		0x23
 #define MFD_HD_144		0x24
 #define MFD_UHD			0x31
+#define MFD_CLIK		0xfe		/* Fake clik type */
 
 #define MFD_UNKNOWN		0x00
 #define MFD_NO_DISC		0x70
@@ -70,6 +71,12 @@
     u_int8_t	reserved30[2];
 };
 
+/* IOMEGA Clik parameters */
+#define CLIK_SECTOR_SIZE 512
+#define CLIK_CYLS 39441
+#define CLIK_SECTORS 2
+#define CLIK_HEADS 1
+
 struct afd_softc {
     struct atapi_softc		*atp;		/* controller structure */
     int				lun;		/* logical device unit */
@@ -80,5 +87,5 @@
     struct disk			disk;		/* virtual drives */
     struct devstat		stats;
     dev_t			dev;		/* device place holder */
+    int				iomega_clik;
 };
-

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-mobile" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200103102051.f2AKpXI20839>