wdsc(4): testing device/softc split

Ben Harris <[email protected]>
Newsgroups gmane.os.netbsd.ports.sgimips
Message-ID <[email protected]>
I'm doing some work on various device drivers for NetBSD/acorn26, and this 
has ended up touching the wdsc(4) driver on NetBSD/sgimips.  I've compiled 
it, but my Indy isn't working so I'm not in a position to test it.  I've 
attached a patch, and I've uploaded a -current kernel to 
<http://bjh21.me.uk/junk/netbsd.ip2x.wdsc-split>.  I'd be very grateful if 
someone with a wdsc(4) could test this and tell me whether I seem to have 
broken anything.  If no-one tells me it's broken in the next week or so, 
I'll commit it.

Thanks in advance.

-- 
Ben Harris                                                   <[email protected]>
Portmaster, NetBSD/acorn26               <http://www.NetBSD.org/Ports/acorn26/>
wd33c93-split.diff (text/x-patch, 9.7 KB)
? dev/ic/i82595.c
? dev/ic/i82595var.h
? dev/ic/r6522reg.h
? dev/ic/r6551.c
? dev/ic/r6551reg.h
? dev/ic/r6551var.h
Index: dev/podulebus/sec.c
===================================================================
RCS file: /cvsroot/src/sys/dev/podulebus/sec.c,v
retrieving revision 1.12
diff -u -r1.12 sec.c
--- dev/podulebus/sec.c	20 Jan 2009 20:45:11 -0000	1.12
+++ dev/podulebus/sec.c	21 Jan 2009 22:02:18 -0000
@@ -109,7 +109,7 @@
 
 void sec_dumpdma(void *arg);
 
-CFATTACH_DECL(sec, sizeof(struct sec_softc),
+CFATTACH_DECL_NEW(sec, sizeof(struct sec_softc),
     sec_match, sec_attach, NULL, NULL);
 
 static inline void
@@ -169,6 +169,7 @@
 	struct sec_softc *sc = device_private(self);
 	int i;
 
+	sc->sc_sbic.sc_dev = self;
 	/* Set up bus spaces */
 	sc->sc_pod_t = pa->pa_fast_t;
 	bus_space_map(pa->pa_fast_t, pa->pa_fast_base, 0x1000, 0,
@@ -494,7 +495,7 @@
 
 	dmac_write(sc, NEC71071_CHANNEL, 0);
 	printf("%s: DMA state: cur count %02x%02x cur addr %02x%02x%02x ",
-	    device_xname(&sc->sc_sbic.sc_dev),
+	    device_xname(sc->sc_sbic.sc_dev),
 	    dmac_read(sc, NEC71071_COUNTHI), dmac_read(sc, NEC71071_COUNTLO),
 	    dmac_read(sc, NEC71071_ADDRHI), dmac_read(sc, NEC71071_ADDRMID),
 	    dmac_read(sc, NEC71071_ADDRLO));
@@ -505,11 +506,12 @@
 	    dmac_read(sc, NEC71071_ADDRLO));
 	printf("%s: DMA state: dctrl %1x%02x mode %02x status %02x req %02x "
 	    "mask %02x\n",
-	    device_xname(&sc->sc_sbic.sc_dev), dmac_read(sc, NEC71071_DCTRL2),
+	    device_xname(sc->sc_sbic.sc_dev), dmac_read(sc, NEC71071_DCTRL2),
 	    dmac_read(sc, NEC71071_DCTRL1), dmac_read(sc, NEC71071_MODE),
 	    dmac_read(sc, NEC71071_STATUS), dmac_read(sc, NEC71071_REQUEST),
 	    dmac_read(sc, NEC71071_MASK));
-	printf("%s: soft DMA state: %zd@%p%s%d\n", device_xname(&sc->sc_sbic.sc_dev),
+	printf("%s: soft DMA state: %zd@%p%s%d\n",
+	    device_xname(sc->sc_sbic.sc_dev),
 	    sc->sc_dmalen, sc->sc_dmaaddr, sc->sc_dmain ? "<-" : "->",
 	    sc->sc_dmaoff);
 }
Index: dev/ic/wd33c93.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/wd33c93.c,v
retrieving revision 1.20
diff -u -r1.20 wd33c93.c
--- dev/ic/wd33c93.c	20 Jan 2009 20:57:26 -0000	1.20
+++ dev/ic/wd33c93.c	21 Jan 2009 22:02:21 -0000
@@ -189,7 +189,7 @@
 	struct scsipi_adapter *adapt = &dev->sc_adapter;
 	struct scsipi_channel *chan = &dev->sc_channel;
 
-	adapt->adapt_dev = &dev->sc_dev;
+	adapt->adapt_dev = dev->sc_dev;
 	adapt->adapt_nchannels = 1;
 	adapt->adapt_openings = 256;
 	adapt->adapt_max_periph = 256; /* Max tags per device */
@@ -212,11 +212,11 @@
 	 * config_found() to make sure the adatper is disabled.
 	 */
 	if (scsipi_adapter_addref(&dev->sc_adapter) != 0) {
-		aprint_error_dev(&dev->sc_dev, "unable to enable controller\n");
+		aprint_error_dev(dev->sc_dev, "unable to enable controller\n");
 		return;
 	}
 
-	dev->sc_cfflags = device_cfdata(&dev->sc_dev)->cf_flags;
+	dev->sc_cfflags = device_cfdata(dev->sc_dev)->cf_flags;
 	wd33c93_init(dev);
 	
 	aprint_normal(": %s (%d.%d MHz clock, %s, SCSI ID %d)\n",
@@ -227,14 +227,14 @@
 	    (dev->sc_dmamode == SBIC_CTL_BURST_DMA) ? "BURST DMA" : "PIO",
 	    dev->sc_channel.chan_id);
 	if (dev->sc_chip == SBIC_CHIP_WD33C93B) {
-		aprint_normal_dev(&dev->sc_dev, "microcode revision 0x%02x",
+		aprint_normal_dev(dev->sc_dev, "microcode revision 0x%02x",
 		    dev->sc_rev);
 		if (dev->sc_minsyncperiod < 50)
 			aprint_normal(", Fast SCSI");
 		aprint_normal("\n");
 	}
 
-	dev->sc_child = config_found(&dev->sc_dev, &dev->sc_channel,
+	dev->sc_child = config_found(dev->sc_dev, &dev->sc_channel,
 				     scsiprint);
 	scsipi_adapter_delref(&dev->sc_adapter);
 }
@@ -549,7 +549,8 @@
 void
 wd33c93_scsi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req, void *arg)
 {
-	struct wd33c93_softc *dev = (void *)chan->chan_adapter->adapt_dev;
+	struct wd33c93_softc *dev =
+	    device_private(chan->chan_adapter->adapt_dev);
 	struct scsipi_xfer *xs;
 	struct scsipi_periph *periph;
 	struct wd33c93_acb *acb;
@@ -1545,7 +1546,7 @@
 			case SEND_TAG:
 				printf("%s: tagged queuing rejected: "
 				    "target %d\n",
-				    device_xname(&dev->sc_dev), dev->target);
+				    device_xname(dev->sc_dev), dev->target);
 				ti->flags &= ~T_TAG;
 				li = TINFO_LUN(ti, dev->lun);
 				if (acb->tag_type &&
@@ -1560,7 +1561,7 @@
 
 			case SEND_SDTR:
 				printf("%s: sync transfer rejected: target %d\n",
-				    device_xname(&dev->sc_dev), dev->target);
+				    device_xname(dev->sc_dev), dev->target);
 
 				dev->sc_flags &= ~SBICF_SYNCNEGO;
 				ti->flags &= ~(T_NEGOTIATE | T_SYNCMODE);
@@ -1730,7 +1731,7 @@
 		if ((msgaddr[0]!=MSG_SIMPLE_Q_TAG) || (dev->sc_msgify==0)) {
 			printf("%s: TAG reselect without IDENTIFY;"
 			    " MSG %x; sending DEVICE RESET\n",
-			    device_xname(&dev->sc_dev), msgaddr[0]);
+			    device_xname(dev->sc_dev), msgaddr[0]);
 			goto reset;
 		}
 		SBIC_DEBUG(TAGS, ("TAG %x/%x\n", msgaddr[0], msgaddr[1]));
@@ -1751,7 +1752,7 @@
 			printf("%s: reselect without IDENTIFY;"
 			    " MSG %x;"
 			    " sending DEVICE RESET\n",
-			    device_xname(&dev->sc_dev), msgaddr[0]);
+			    device_xname(dev->sc_dev), msgaddr[0]);
 			goto reset;
 		}
 		break;
@@ -1832,7 +1833,7 @@
 		case SEND_IDENTIFY:
 			if (dev->sc_state != SBIC_CONNECTED) {
 				printf("%s at line %d: no nexus\n",
-				    device_xname(&dev->sc_dev), __LINE__);
+				    device_xname(dev->sc_dev), __LINE__);
 			}
 			dev->sc_omsg[0] =
 			    MSG_IDENTIFY(acb->xs->xs_periph->periph_lun, 0);
@@ -1840,7 +1841,7 @@
 		case SEND_TAG:
 			if (dev->sc_state != SBIC_CONNECTED) {
 				printf("%s at line %d: no nexus\n",
-				    device_xname(&dev->sc_dev), __LINE__);
+				    device_xname(dev->sc_dev), __LINE__);
 			}
 			dev->sc_omsg[0] = acb->tag_type;
 			dev->sc_omsg[1] = acb->tag_id;
@@ -2095,7 +2096,7 @@
 			/* If we didn't get an interrupt, somethink's up */
 			if ((asr & SBIC_ASR_INT) == 0) {
 				printf("%s: Reselect without identify? asr %x\n",
-				    device_xname(&dev->sc_dev), asr);
+				    device_xname(dev->sc_dev), asr);
 				newlun = 0; /* XXXX */
 			} else {
 				/*
@@ -2178,7 +2179,7 @@
 		 * for the best.
 		 */
 		SBIC_DEBUG(RSEL, ("%s: reselect with active command\n",
-			       device_xname(&dev->sc_dev)));
+			       device_xname(dev->sc_dev)));
 		ti = &dev->sc_tinfo[dev->target];
 		li = TINFO_LUN(ti, dev->lun);
 		li->state = L_STATE_IDLE;
@@ -2214,7 +2215,7 @@
 	if (acb == NULL) {
 		printf("%s: reselect from target %d lun %d tag %x:%x "
 		    "with no nexus; sending ABORT\n",
-		    device_xname(&dev->sc_dev), target, lun, tag_type, tag_id);
+		    device_xname(dev->sc_dev), target, lun, tag_type, tag_id);
 		goto abort;
 	}
 
@@ -2279,7 +2280,7 @@
 	struct scsipi_xfer *xs = acb->xs;
 	struct scsipi_periph *periph = xs->xs_periph;
 	struct wd33c93_softc *dev =
-	    (void *)periph->periph_channel->chan_adapter->adapt_dev;
+	    device_private(periph->periph_channel->chan_adapter->adapt_dev);
 	int s, asr;
 
 	s = splbio();
@@ -2289,7 +2290,7 @@
 	scsipi_printaddr(periph);
 	printf("%s: timed out; asr=0x%02x [acb %p (flags 0x%x, dleft %zx)], "
 	    "<state %d, nexus %p, resid %lx, msg(q %x,o %x)>",
-	    device_xname(&dev->sc_dev), asr, acb, acb->flags, acb->dleft,
+	    device_xname(dev->sc_dev), asr, acb, acb->flags, acb->dleft,
 	    dev->sc_state, dev->sc_nexus, (long)dev->sc_dleft,
 	    dev->sc_msgpriq, dev->sc_msgout);
 
Index: dev/ic/wd33c93var.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/wd33c93var.h,v
retrieving revision 1.7
diff -u -r1.7 wd33c93var.h
--- dev/ic/wd33c93var.h	21 May 2007 19:25:55 -0000	1.7
+++ dev/ic/wd33c93var.h	21 Jan 2009 22:02:21 -0000
@@ -118,7 +118,7 @@
 #define TINFO_LUN(t, l) 	((t)->lun[(l)])
 
 struct wd33c93_softc {
-	struct device	sc_dev;
+	device_t	sc_dev;
 
 	struct scsipi_channel sc_channel; /* proto for sub devices */
 	struct scsipi_adapter sc_adapter;
Index: arch/sgimips/hpc/wdsc.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/hpc/wdsc.c,v
retrieving revision 1.25
diff -u -r1.25 wdsc.c
--- arch/sgimips/hpc/wdsc.c	10 May 2008 15:31:05 -0000	1.25
+++ arch/sgimips/hpc/wdsc.c	21 Jan 2009 22:02:21 -0000
@@ -80,7 +80,7 @@
 void	wdsc_attach	(struct device *, struct device *, void *);
 int	wdsc_match	(struct device *, struct cfdata *, void *);
 
-CFATTACH_DECL(wdsc, sizeof(struct wdsc_softc),
+CFATTACH_DECL_NEW(wdsc, sizeof(struct wdsc_softc),
     wdsc_match, wdsc_attach, NULL, NULL);
 
 int	wdsc_dmasetup	(struct wd33c93_softc *, void **,size_t *,
@@ -138,11 +138,12 @@
 void
 wdsc_attach(struct device *pdp, struct device *dp, void *auxp)
 {
-	struct wd33c93_softc *sc = (void *)dp;
-	struct wdsc_softc *wsc = (void *)dp;
+	struct wd33c93_softc *sc = device_private(dp);
+	struct wdsc_softc *wsc = device_private(dp);
 	struct hpc_attach_args *haa = auxp;
 	int err;
 
+	sc->sc_dev = dp;
 	sc->sc_regt = haa->ha_st;
 	wsc->sc_dmat = haa->ha_dmat;
 
@@ -180,7 +181,7 @@
 	sc->sc_dmamode = SBIC_CTL_BURST_DMA;
 
 	evcnt_attach_dynamic(&wsc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
-			     sc->sc_dev.dv_xname, "intr");
+	    device_xname(sc->sc_dev), "intr");
 
 	if ((cpu_intr_establish(haa->ha_irq, IPL_BIO,
 	     wdsc_scsiintr, sc)) == NULL) {
@@ -219,7 +220,7 @@
 				NULL /* kernel address */,
 				BUS_DMA_NOWAIT)) != 0)
 			panic("%s: bus_dmamap_load err=%d",
-			      dev->sc_dev.dv_xname, err);
+			    device_xname(dev->sc_dev), err);
 
 		hpcdma_sglist_create(dsc, wsc->sc_dmamap);
 		wsc->sc_flags |= WDSC_DMA_MAPLOADED;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.