Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Jun 2012 21:25:22 GMT
From:      Brooks Davis <brooks@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 212344 for review
Message-ID:  <201206052125.q55LPMOv073707@skunkworks.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@212344?ac=10

Change 212344 by brooks@brooks_ecr_current on 2012/06/05 21:25:01

	Put detailed debugging information under an isf_debug variable and
	disable it by default.
	
	Put the dump of device info under bootverbose.
	
	Add completely undtested support for the device IDs listed in the
	datasheet and remove the hardcoded ISF_MEDIASIZE restruction in
	the process (now it's a hardcoded table instead :).
	
	Reduce the number of XXX comments.

Affected files ...

.. //depot/projects/ctsrd/beribsd/src/sys/dev/isf/isf.c#8 edit
.. //depot/projects/ctsrd/beribsd/src/sys/dev/isf/isf.h#7 edit

Differences ...

==== //depot/projects/ctsrd/beribsd/src/sys/dev/isf/isf.c#8 (text+ko) ====

@@ -123,6 +123,23 @@
 #define ISF_BUFFER_PROGRAM
 
 MALLOC_DEFINE(M_ISF, "isf_data", "Intel StrateFlash driver");
+static int	isf_debug = 0;
+
+static struct isf_chips {
+	uint16_t	 chip_id;
+	size_t		 chip_size;
+	const char	*chip_desc;
+} chip_ids[] = {
+	{ 0x8817, 0x0800000, "64-Mbit Top Parameter" },
+	{ 0x881A, 0x0800000, "64-Mbit Bottom Parameter" },
+	{ 0x8818, 0x1000000, "128-Mbit Top Parameter" },
+	{ 0x881B, 0x1000000, "128-Mbit Bottom Parameter" },
+	{ 0x8919, 0x2000000, "256-Mbit Top Parameter" },
+	{ 0x891C, 0x2000000, "256-Mbit Bottom Parameter" },
+	{ 0x8961, 0x2000000, "512-Mbit package (half)" },
+	{ 0x0000, 0x0000000, NULL }
+};
+
 static void	isf_task(void *arg);
 
 /* 
@@ -138,7 +155,8 @@
 isf_read_reg(struct isf_softc *sc, uint32_t reg)
 {
 
-	device_printf(sc->isf_dev, "isf_read_reg(0x%02x)\n", reg);
+	if (isf_debug)
+		device_printf(sc->isf_dev, "isf_read_reg(0x%02x)\n", reg);
 	return (le16toh(bus_read_2(sc->isf_res, reg * 2)));
 }
 
@@ -148,7 +166,8 @@
 	uint64_t val;
 	uint16_t *val16 = (uint16_t *)&val;
 
-	device_printf(sc->isf_dev, "isf_read_reg64(0x%02x)\n", reg);
+	if (isf_debug)
+		device_printf(sc->isf_dev, "isf_read_reg64(0x%02x)\n", reg);
 	val16[0] = bus_read_2(sc->isf_res, reg * 2);
 	val16[1] = bus_read_2(sc->isf_res, (reg+1) * 2);
 	val16[2] = bus_read_2(sc->isf_res, (reg+2) * 2);
@@ -161,8 +180,9 @@
 isf_write_cmd(struct isf_softc *sc, off_t off, uint16_t cmd)
 {
 	
-	device_printf(sc->isf_dev, "isf_write_cmd(0x%08jx, 0x%02x)\n",
-	    off, cmd);
+	if (isf_debug)
+		device_printf(sc->isf_dev, "isf_write_cmd(0x%08jx, 0x%02x)\n",
+		    off, cmd);
 	bus_write_2(sc->isf_res, off, htole16(cmd));
 }
 
@@ -247,7 +267,7 @@
 static int
 isf_write(struct isf_softc *sc, off_t off, void *data, size_t len)
 {
-	int		 error = 0;
+	int		 cycles, error = 0;
 	uint16_t	*dp;
 	uint16_t	 status;
 	off_t		 coff;
@@ -270,9 +290,12 @@
 	    dp += 32, coff += 64) {
 		isf_clear_status(sc);
 		isf_write_cmd(sc, coff, ISF_CMD_BPS);
-		while ( !(isf_read_reg(sc, coff) & ISF_SR_DWS) )
-			/* XXX: should have a timeout */
+		cycles = 0xFFFF;
+		while ( !(isf_read_reg(sc, coff) & ISF_SR_DWS) ) {
+			if (cycles-- == 0)
+				return (EIO);
 			isf_write_cmd(sc, coff, ISF_CMD_BPS);
+		}
 
 		/* When writing N blocks, send N-1 as the count */
 		isf_write_cmd(sc, coff, 31);
@@ -506,7 +529,6 @@
 		    (uintmax_t)isf_read_reg64(sc, reg));
 	}
 
-
 	isf_write_cmd(sc, 0, ISF_CMD_RA);
 }
 
@@ -532,8 +554,8 @@
 	disk->d_maxsize = ISF_SECTORSIZE;
 	sc->isf_disk = disk;
 
-	/* XXXBED: put under bootverbose */
-	isf_dump_info(sc);
+	if (bootverbose)
+		isf_dump_info(sc);
 
 	disk_create(disk, DISK_VERSION);
 	device_printf(sc->isf_dev, "%juM flash device\n",
@@ -568,7 +590,9 @@
 int
 isf_attach(struct isf_softc *sc)
 {
-	u_long start, size;
+	uint16_t		id;
+	u_long			start, size;
+	struct isf_chips	*cp = chip_ids;
 
 	start = rman_get_start(sc->isf_res);
 	if (start % 2 != 0) {
@@ -577,26 +601,29 @@
 		    start);
 		return (ENXIO);
 	}
-	size = rman_get_size(sc->isf_res);
-	if (size != ISF_MEDIASIZE) {
+
+	isf_write_cmd(sc, 0, ISF_CMD_RDI);
+	id = isf_read_reg(sc, ISF_REG_ID);
+	while (cp->chip_id != id)
+		cp++;
+	if (cp->chip_desc == NULL) {
 		device_printf(sc->isf_dev,
-		    "Unsupported flash size %lu\n", size);
+		    "Unsupported device ID 0x%04x\n", id);
 		return (ENXIO);
 	}
+	isf_write_cmd(sc, 0, ISF_CMD_RA);
 
-	isf_write_cmd(sc, 0, ISF_CMD_RDI);
-	if (isf_read_reg(sc, ISF_REG_ID) != 0x8961) {
+	size = rman_get_size(sc->isf_res);
+	if (size != cp->chip_size) {
 		device_printf(sc->isf_dev,
-		    "Unsupported device ID 0x%04x\n",
-		    isf_read_reg(sc, ISF_REG_ID));
+		    "Unsupported flash size %lu\n", size);
 		return (ENXIO);
 	}
-	isf_write_cmd(sc, 0, ISF_CMD_RA);
 
 	bioq_init(&sc->isf_bioq);
 	ISF_LOCK_INIT(sc);
 	sc->isf_disk = NULL;
-	isf_disk_insert(sc, ISF_MEDIASIZE);
+	isf_disk_insert(sc, size);
 	return(0);
 }
 

==== //depot/projects/ctsrd/beribsd/src/sys/dev/isf/isf.h#7 (text+ko) ====

@@ -40,15 +40,11 @@
 #define	ISF_ERASE	_IOW('I', 1, struct isf_range)
 
 /*
- * XXXRW: For now, support only 256Mb parts, but we may want to support others
- * in the future.
- *
- * XXXRW: For read access, declaring a standard 512-byte sector size is fine,
- * and in fact quite convenient for conventional file systems.  However, write
- * sizes need thought, due to large block erase sizes, etc.
+ * Ordinary read and write operations are limited to 512 bytes.
+ * We support erasing 128K blocks and ignore the fact that portions of the
+ * flash are in fact divided into 32K blocks.
  */
 #define	ISF_SECTORSIZE	(512)
-#define	ISF_MEDIASIZE	(256 * 1024 * 1024 / 8)
 #define ISF_ERASE_BLOCK	(128 * 1024)
 
 #ifdef _KERNEL



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