svn commit: r272214 - in head/sys: boot/i386/libfirewire dev/firewire

Alexander Kabaev kan at FreeBSD.org
Sat Sep 27 16:50:22 UTC 2014


Author: kan
Date: Sat Sep 27 16:50:21 2014
New Revision: 272214
URL: http://svnweb.freebsd.org/changeset/base/272214

Log:
  Remove obsolete compatibility glue and improve firewire code readability.
  
  Commit my version of style(9) pass over the firewire code. Now that
  other people have started changing the code carrying this is as a
  local patch is not longer a viable option.
  
  MFC after:	1 month

Modified:
  head/sys/boot/i386/libfirewire/fwohcireg.h
  head/sys/dev/firewire/firewire.c
  head/sys/dev/firewire/firewire.h
  head/sys/dev/firewire/firewire_phy.h
  head/sys/dev/firewire/firewirereg.h
  head/sys/dev/firewire/fwcrom.c
  head/sys/dev/firewire/fwdev.c
  head/sys/dev/firewire/fwdma.c
  head/sys/dev/firewire/fwdma.h
  head/sys/dev/firewire/fwmem.c
  head/sys/dev/firewire/fwohci.c
  head/sys/dev/firewire/fwohci_pci.c
  head/sys/dev/firewire/fwohcireg.h
  head/sys/dev/firewire/fwohcivar.h
  head/sys/dev/firewire/iec68113.h
  head/sys/dev/firewire/if_fwe.c
  head/sys/dev/firewire/if_fwip.c
  head/sys/dev/firewire/sbp.c
  head/sys/dev/firewire/sbp.h
  head/sys/dev/firewire/sbp_targ.c

Modified: head/sys/boot/i386/libfirewire/fwohcireg.h
==============================================================================
--- head/sys/boot/i386/libfirewire/fwohcireg.h	Sat Sep 27 14:39:00 2014	(r272213)
+++ head/sys/boot/i386/libfirewire/fwohcireg.h	Sat Sep 27 16:50:21 2014	(r272214)
@@ -235,7 +235,7 @@ struct ohci_registers {
 	fwohcireg_t	config_rom;	/* config ROM map 0x34 */
 	fwohcireg_t	post_wr_lo;	/* post write addr lo 0x38 */
 	fwohcireg_t	post_wr_hi;	/* post write addr hi 0x3c */
-	fwohcireg_t	vender;		/* vender ID 0x40 */
+	fwohcireg_t	vendor;		/* vendor ID 0x40 */
 	fwohcireg_t	dummy1[3];	/* dummy 0x44-0x4c */
 	fwohcireg_t	hcc_cntl_set;	/* HCC control set 0x50 */
 	fwohcireg_t	hcc_cntl_clr;	/* HCC control clr 0x54 */

Modified: head/sys/dev/firewire/firewire.c
==============================================================================
--- head/sys/dev/firewire/firewire.c	Sat Sep 27 14:39:00 2014	(r272213)
+++ head/sys/dev/firewire/firewire.c	Sat Sep 27 16:50:21 2014	(r272214)
@@ -48,7 +48,6 @@ __FBSDID("$FreeBSD$");
 #include <sys/kthread.h>
 
 #include <sys/kdb.h>
-
 #include <sys/bus.h>		/* used by smbus and newbus */
 #include <machine/bus.h>
 
@@ -65,7 +64,7 @@ struct crom_src_buf {
 	struct crom_chunk hw;
 };
 
-int firewire_debug=0, try_bmr=1, hold_count=0;
+int firewire_debug = 0, try_bmr = 1, hold_count = 0;
 SYSCTL_INT(_debug, OID_AUTO, firewire_debug, CTLFLAG_RW, &firewire_debug, 0,
 	"FireWire driver debug flag");
 SYSCTL_NODE(_hw, OID_AUTO, firewire, CTLFLAG_RD, 0, "FireWire Subsystem");
@@ -81,19 +80,19 @@ MALLOC_DEFINE(M_FWXFER, "fw_xfer", "XFER
 
 devclass_t firewire_devclass;
 
-static void firewire_identify	(driver_t *, device_t);
-static int firewire_probe	(device_t);
-static int firewire_attach      (device_t);
-static int firewire_detach      (device_t);
-static int firewire_resume      (device_t);
+static void firewire_identify(driver_t *, device_t);
+static int firewire_probe(device_t);
+static int firewire_attach(device_t);
+static int firewire_detach(device_t);
+static int firewire_resume(device_t);
 static void firewire_xfer_timeout(void *, int);
 static device_t firewire_add_child(device_t, u_int, const char *, int);
-static void fw_try_bmr (void *);
-static void fw_try_bmr_callback (struct fw_xfer *);
-static void fw_asystart (struct fw_xfer *);
-static int fw_get_tlabel (struct firewire_comm *, struct fw_xfer *);
-static void fw_bus_probe (struct firewire_comm *);
-static void fw_attach_dev (struct firewire_comm *);
+static void fw_try_bmr(void *);
+static void fw_try_bmr_callback(struct fw_xfer *);
+static void fw_asystart(struct fw_xfer *);
+static int fw_get_tlabel(struct firewire_comm *, struct fw_xfer *);
+static void fw_bus_probe(void *);
+static void fw_attach_dev(struct firewire_comm *);
 static void fw_bus_probe_thread(void *);
 #ifdef FW_VMACCESS
 static void fw_vmaccess (struct fw_xfer *);
@@ -116,6 +115,7 @@ static device_method_t firewire_methods[
 
 	DEVMETHOD_END
 };
+
 char *linkspeed[] = {
 	"S100", "S200", "S400", "S800",
 	"S1600", "S3200", "undef", "undef"
@@ -174,8 +174,10 @@ fw_noderesolve_eui64(struct firewire_com
 	FW_GUNLOCK(fc);
 	splx(s);
 
-	if(fwdev == NULL) return NULL;
-	if(fwdev->status == FWDEVINVAL) return NULL;
+	if (fwdev == NULL)
+		return NULL;
+	if (fwdev->status == FWDEVINVAL)
+		return NULL;
 	return fwdev;
 }
 
@@ -192,8 +194,9 @@ fw_asyreq(struct firewire_comm *fc, int 
 	int tcode;
 	struct tcode_info *info;
 
-	if(xfer == NULL) return EINVAL;
-	if(xfer->hand == NULL){
+	if (xfer == NULL)
+		return EINVAL;
+	if (xfer->hand == NULL) {
 		printf("hand == NULL\n");
 		return EINVAL;
 	}
@@ -231,17 +234,17 @@ fw_asyreq(struct firewire_comm *fc, int 
 		len = fp->mode.rresb.len;
 	else
 		len = 0;
-	if (len != xfer->send.pay_len){
+	if (len != xfer->send.pay_len) {
 		printf("len(%d) != send.pay_len(%d) %s(%x)\n",
 		    len, xfer->send.pay_len, tcode_str[tcode], tcode);
-		return EINVAL; 
+		return EINVAL;
 	}
 
-	if(xferq->start == NULL){
+	if (xferq->start == NULL) {
 		printf("xferq->start == NULL\n");
 		return EINVAL;
 	}
-	if(!(xferq->queued < xferq->maxq)){
+	if (!(xferq->queued < xferq->maxq)) {
 		device_printf(fc->bdev, "Discard a packet (queued=%d)\n",
 			xferq->queued);
 		return EAGAIN;
@@ -260,6 +263,7 @@ fw_asyreq(struct firewire_comm *fc, int 
 	fw_asystart(xfer);
 	return err;
 }
+
 /*
  * Wakeup blocked process.
  */
@@ -283,8 +287,8 @@ fw_xferwait(struct fw_xfer *xfer)
 	int err = 0;
 
 	mtx_lock(lock);
-	if ((xfer->flag & FWXF_WAKE) == 0)
-		err = msleep((void *)xfer, lock, PWAIT|PCATCH, "fw_xferwait", 0);
+	while ((xfer->flag & FWXF_WAKE) == 0)
+		err = msleep(xfer, lock, PWAIT|PCATCH, "fw_xferwait", 0);
 	mtx_unlock(lock);
 
 	return (err);
@@ -298,13 +302,14 @@ fw_asystart(struct fw_xfer *xfer)
 {
 	struct firewire_comm *fc = xfer->fc;
 	int s;
+
 	s = splfw();
 	/* Protect from interrupt/timeout */
 	FW_GLOCK(fc);
 	xfer->flag = FWXF_INQ;
 	STAILQ_INSERT_TAIL(&xfer->q->q, xfer, link);
 #if 0
-	xfer->q->queued ++;
+	xfer->q->queued++;
 #endif
 	FW_GUNLOCK(fc);
 	splx(s);
@@ -346,7 +351,7 @@ firewire_xfer_timeout(void *arg, int pen
 
 	s = splfw();
 	mtx_lock(&fc->tlabel_lock);
-	for (i = 0; i < 0x40; i ++) {
+	for (i = 0; i < 0x40; i++) {
 		while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
 			if ((xfer->flag & FWXF_SENT) == 0)
 				/* not sent yet */
@@ -355,8 +360,8 @@ firewire_xfer_timeout(void *arg, int pen
 				/* the rests are newer than this */
 				break;
 			device_printf(fc->bdev,
-				"split transaction timeout: "
-				"tl=0x%x flag=0x%02x\n", i, xfer->flag);
+			    "split transaction timeout: tl=0x%x flag=0x%02x\n",
+			    i, xfer->flag);
 			fw_dump_hdr(&xfer->send.hdr, "send");
 			xfer->resp = ETIMEDOUT;
 			xfer->tl = -1;
@@ -369,7 +374,7 @@ firewire_xfer_timeout(void *arg, int pen
 	fc->timeout(fc);
 
 	STAILQ_FOREACH_SAFE(xfer, &xfer_timeout, tlabel, txfer)
-		xfer->hand(xfer);	
+		xfer->hand(xfer);
 }
 
 #define WATCHDOG_HZ 10
@@ -379,7 +384,7 @@ firewire_watchdog(void *arg)
 	struct firewire_comm *fc;
 	static int watchdog_clock = 0;
 
-	fc = (struct firewire_comm *)arg;
+	fc = arg;
 
 	/*
 	 * At boot stage, the device interrupt is disabled and
@@ -389,10 +394,10 @@ firewire_watchdog(void *arg)
 	if (watchdog_clock > WATCHDOG_HZ * 15)
 		taskqueue_enqueue(fc->taskqueue, &fc->task_timeout);
 	else
-		watchdog_clock ++;
+		watchdog_clock++;
 
 	callout_reset(&fc->timeout_callout, hz / WATCHDOG_HZ,
-			(void *)firewire_watchdog, (void *)fc);
+	    firewire_watchdog, fc);
 }
 
 /*
@@ -406,35 +411,36 @@ firewire_attach(device_t dev)
 	device_t pa = device_get_parent(dev);
 	struct firewire_comm *fc;
 
-	fc = (struct firewire_comm *)device_get_softc(pa);
+	fc = device_get_softc(pa);
 	sc->fc = fc;
 	fc->status = FWBUSNOTREADY;
 
 	unit = device_get_unit(dev);
-	if( fc->nisodma > FWMAXNDMA) fc->nisodma = FWMAXNDMA;
+	if (fc->nisodma > FWMAXNDMA)
+		fc->nisodma = FWMAXNDMA;
 
 	fwdev_makedev(sc);
 
-	fc->crom_src_buf = (struct crom_src_buf *)malloc(
-				sizeof(struct crom_src_buf),
-				M_FW, M_NOWAIT | M_ZERO);
+	fc->crom_src_buf = malloc(sizeof(struct crom_src_buf),
+	    M_FW, M_NOWAIT | M_ZERO);
 	if (fc->crom_src_buf == NULL) {
-		device_printf(fc->dev, "%s: Malloc Failure crom src buff\n", __func__);
+		device_printf(fc->dev,
+		    "%s: unable to allocate crom src buffer\n", __func__);
 		return ENOMEM;
 	}
-	fc->topology_map = (struct fw_topology_map *)malloc(
-				sizeof(struct fw_topology_map),
-				M_FW, M_NOWAIT | M_ZERO);
+	fc->topology_map = malloc(sizeof(struct fw_topology_map),
+	    M_FW, M_NOWAIT | M_ZERO);
 	if (fc->topology_map == NULL) {
-		device_printf(fc->dev, "%s: Malloc Failure topology map\n", __func__);
+		device_printf(fc->dev, "%s: unable to allocate topology map\n",
+		    __func__);
 		free(fc->crom_src_buf, M_FW);
 		return ENOMEM;
 	}
-	fc->speed_map = (struct fw_speed_map *)malloc(
-				sizeof(struct fw_speed_map),
-				M_FW, M_NOWAIT | M_ZERO);
+	fc->speed_map = malloc(sizeof(struct fw_speed_map),
+	    M_FW, M_NOWAIT | M_ZERO);
 	if (fc->speed_map == NULL) {
-		device_printf(fc->dev, "%s: Malloc Failure speed map\n", __func__);
+		device_printf(fc->dev, "%s: unable to allocate speed map\n",
+		    __func__);
 		free(fc->crom_src_buf, M_FW);
 		free(fc->topology_map, M_FW);
 		return ENOMEM;
@@ -445,14 +451,14 @@ firewire_attach(device_t dev)
 	CALLOUT_INIT(&fc->timeout_callout);
 	CALLOUT_INIT(&fc->bmr_callout);
 	CALLOUT_INIT(&fc->busprobe_callout);
-	TASK_INIT(&fc->task_timeout, 0, firewire_xfer_timeout, (void *)fc);
+	TASK_INIT(&fc->task_timeout, 0, firewire_xfer_timeout, fc);
 
 	callout_reset(&sc->fc->timeout_callout, hz,
-			(void *)firewire_watchdog, (void *)sc->fc);
+	    firewire_watchdog, sc->fc);
 
 	/* create thread */
-	kproc_create(fw_bus_probe_thread, (void *)fc, &fc->probe_thread,
-		0, 0, "fw%d_probe", unit);
+	kproc_create(fw_bus_probe_thread, fc, &fc->probe_thread,
+	    0, 0, "fw%d_probe", unit);
 
 	/* Locate our children */
 	bus_generic_probe(dev);
@@ -475,10 +481,10 @@ firewire_attach(device_t dev)
 static device_t
 firewire_add_child(device_t dev, u_int order, const char *name, int unit)
 {
-        device_t child;
+	device_t child;
 	struct firewire_softc *sc;
 
-	sc = (struct firewire_softc *)device_get_softc(dev);
+	sc = device_get_softc(dev);
 	child = device_add_child(dev, name, unit);
 	if (child) {
 		device_set_ivars(child, sc->fc);
@@ -493,16 +499,16 @@ firewire_resume(device_t dev)
 {
 	struct firewire_softc *sc;
 
-	sc = (struct firewire_softc *)device_get_softc(dev);
+	sc = device_get_softc(dev);
 	sc->fc->status = FWBUSNOTREADY;
-	
+
 	bus_generic_resume(dev);
 
-	return(0);
+	return (0);
 }
 
 /*
- * Dettach it.
+ * Detach it.
  */
 static int
 firewire_detach(device_t dev)
@@ -512,7 +518,7 @@ firewire_detach(device_t dev)
 	struct fw_device *fwdev, *fwdev_next;
 	int err;
 
-	sc = (struct firewire_softc *)device_get_softc(dev);
+	sc = device_get_softc(dev);
 	fc = sc->fc;
 	mtx_lock(&fc->wait_lock);
 	fc->status = FWBUSDETACH;
@@ -521,7 +527,7 @@ firewire_detach(device_t dev)
 		printf("firewire probe thread didn't die\n");
 	mtx_unlock(&fc->wait_lock);
 
-	if (fc->arq !=0 && fc->arq->maxq > 0)
+	if (fc->arq != 0 && fc->arq->maxq > 0)
 		fw_drain_txq(fc);
 
 	if ((err = fwdev_destroydev(sc)) != 0)
@@ -536,7 +542,7 @@ firewire_detach(device_t dev)
 
 	/* XXX xfer_free and untimeout on all xfers */
 	for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL;
-							fwdev = fwdev_next) {
+	     fwdev = fwdev_next) {
 		fwdev_next = STAILQ_NEXT(fwdev, link);
 		free(fwdev, M_FW);
 	}
@@ -546,7 +552,7 @@ firewire_detach(device_t dev)
 
 	mtx_destroy(&fc->tlabel_lock);
 	mtx_destroy(&fc->wait_lock);
-	return(0);
+	return (0);
 }
 
 static void
@@ -557,7 +563,7 @@ fw_xferq_drain(struct fw_xferq *xferq)
 	while ((xfer = STAILQ_FIRST(&xferq->q)) != NULL) {
 		STAILQ_REMOVE_HEAD(&xferq->q, link);
 #if 0
-		xferq->queued --;
+		xferq->queued--;
 #endif
 		xfer->resp = EAGAIN;
 		xfer->flag = FWXF_SENTERR;
@@ -577,12 +583,12 @@ fw_drain_txq(struct firewire_comm *fc)
 	FW_GLOCK(fc);
 	fw_xferq_drain(fc->atq);
 	fw_xferq_drain(fc->ats);
-	for(i = 0; i < fc->nisodma; i++)
+	for (i = 0; i < fc->nisodma; i++)
 		fw_xferq_drain(fc->it[i]);
 	FW_GUNLOCK(fc);
 
 	mtx_lock(&fc->tlabel_lock);
-	for (i = 0; i < 0x40; i ++)
+	for (i = 0; i < 0x40; i++)
 		while ((xfer = STAILQ_FIRST(&fc->tlabels[i])) != NULL) {
 			if (firewire_debug)
 				printf("tl=%d flag=%d\n", i, xfer->flag);
@@ -594,7 +600,7 @@ fw_drain_txq(struct firewire_comm *fc)
 	mtx_unlock(&fc->tlabel_lock);
 
 	STAILQ_FOREACH_SAFE(xfer, &xfer_drain, tlabel, txfer)
-		xfer->hand(xfer);	
+		xfer->hand(xfer);
 }
 
 static void
@@ -603,7 +609,7 @@ fw_reset_csr(struct firewire_comm *fc)
 	int i;
 
 	CSRARC(fc, STATE_CLEAR)
-			= 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ;
+			= 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14;
 	CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
 	CSRARC(fc, NODE_IDS) = 0x3f;
 
@@ -612,10 +618,10 @@ fw_reset_csr(struct firewire_comm *fc)
 
 	fc->max_node = -1;
 
-	for(i = 2; i < 0x100/4 - 2 ; i++){
+	for (i = 2; i < 0x100 / 4 - 2; i++) {
 		CSRARC(fc, SPED_MAP + i * 4) = 0;
 	}
-	CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14 ;
+	CSRARC(fc, STATE_CLEAR) = 1 << 23 | 0 << 17 | 1 << 16 | 1 << 15 | 1 << 14;
 	CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
 	CSRARC(fc, RESET_START) = 0;
 	CSRARC(fc, SPLIT_TIMEOUT_HI) = 0;
@@ -631,14 +637,14 @@ fw_reset_csr(struct firewire_comm *fc)
 	CSRARC(fc, CONF_ROM) = 0x04 << 24;
 	CSRARC(fc, CONF_ROM + 4) = 0x31333934; /* means strings 1394 */
 	CSRARC(fc, CONF_ROM + 8) = 1 << 31 | 1 << 30 | 1 << 29 |
-				1 << 28 | 0xff << 16 | 0x09 << 8;
+	    1 << 28 | 0xff << 16 | 0x09 << 8;
 	CSRARC(fc, CONF_ROM + 0xc) = 0;
 
-/* DV depend CSRs see blue book */
-	CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON; 
-	CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON; 
+	/* DV depend CSRs see blue book */
+	CSRARC(fc, oPCR) &= ~DV_BROADCAST_ON;
+	CSRARC(fc, iPCR) &= ~DV_BROADCAST_ON;
 
-	CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14 );
+	CSRARC(fc, STATE_CLEAR) &= ~(1 << 23 | 1 << 15 | 1 << 14);
 	CSRARC(fc, STATE_SET) = CSRARC(fc, STATE_CLEAR);
 }
 
@@ -694,13 +700,8 @@ fw_reset_crom(struct firewire_comm *fc)
 	crom_add_entry(root, CSRKEY_NCAP, 0x0083c0); /* XXX */
 	/* private company_id */
 	crom_add_entry(root, CSRKEY_VENDOR, CSRVAL_VENDOR_PRIVATE);
-#ifdef __DragonFly__
-	crom_add_simple_text(src, root, &buf->vendor, "DragonFly Project");
-	crom_add_entry(root, CSRKEY_HW, __DragonFly_cc_version);
-#else
 	crom_add_simple_text(src, root, &buf->vendor, "FreeBSD Project");
 	crom_add_entry(root, CSRKEY_HW, __FreeBSD_version);
-#endif
 	mtx_lock(&prison0.pr_mtx);
 	crom_add_simple_text(src, root, &buf->hw, prison0.pr_hostname);
 	mtx_unlock(&prison0.pr_mtx);
@@ -731,8 +732,8 @@ fw_busreset(struct firewire_comm *fc, ui
 	fw_reset_crom(fc);
 
 	if (device_get_children(fc->bdev, &devlistp, &devcnt) == 0) {
-		for( i = 0 ; i < devcnt ; i++)
-			if (device_get_state(devlistp[i]) >= DS_ATTACHED)  {
+		for (i = 0; i < devcnt; i++)
+			if (device_get_state(devlistp[i]) >= DS_ATTACHED) {
 				fdc = device_get_softc(devlistp[i]);
 				if (fdc->post_busreset != NULL)
 					fdc->post_busreset(fdc);
@@ -741,31 +742,30 @@ fw_busreset(struct firewire_comm *fc, ui
 	}
 
 	src = &fc->crom_src_buf->src;
-        /*
-         * If the old config rom needs to be overwritten,
-         * bump the businfo.generation indicator to 
-         * indicate that we need to be reprobed
-         * See 1394a-2000 8.3.2.5.4 for more details.
-         * generation starts at 2 and rolls over at 0xF
-         * back to 2.
-         * 
-         * A generation of 0 indicates a device
-         * that is not 1394a-2000 compliant.
-         * A generation of 1 indicates a device that
-         * does not change it's Bus Info Block or 
-         * Configuration ROM.
-         */
+	/*
+	 * If the old config rom needs to be overwritten,
+	 * bump the businfo.generation indicator to
+	 * indicate that we need to be reprobed
+	 * See 1394a-2000 8.3.2.5.4 for more details.
+	 * generation starts at 2 and rolls over at 0xF
+	 * back to 2.
+	 *
+	 * A generation of 0 indicates a device
+	 * that is not 1394a-2000 compliant.
+	 * A generation of 1 indicates a device that
+	 * does not change it's Bus Info Block or
+	 * Configuration ROM.
+	 */
 #define FW_MAX_GENERATION 0xF
 	newrom = malloc(CROMSIZE, M_FW, M_NOWAIT | M_ZERO);
 	src = &fc->crom_src_buf->src;
 	crom_load(src, newrom, CROMSIZE);
 	if (bcmp(newrom, fc->config_rom, CROMSIZE) != 0) {
-		if ( src->businfo.generation++ > FW_MAX_GENERATION )
+		if (src->businfo.generation++ > FW_MAX_GENERATION)
 			src->businfo.generation = FW_GENERATION_CHANGEABLE;
-		bcopy(newrom, (void *)fc->config_rom, CROMSIZE);
+		bcopy(newrom, fc->config_rom, CROMSIZE);
 	}
 	free(newrom, M_FW);
-
 }
 
 /* Call once after reboot */
@@ -795,7 +795,7 @@ void fw_init(struct firewire_comm *fc)
 	STAILQ_INIT(&fc->atq->q);
 	STAILQ_INIT(&fc->ats->q);
 
-	for( i = 0 ; i < fc->nisodma ; i ++ ){
+	for (i = 0; i < fc->nisodma; i++) {
 		fc->it[i]->queued = 0;
 		fc->ir[i]->queued = 0;
 
@@ -817,7 +817,7 @@ void fw_init(struct firewire_comm *fc)
 	fc->atq->maxq = FWMAXQUEUE;
 	fc->ats->maxq = FWMAXQUEUE;
 
-	for( i = 0 ; i < fc->nisodma ; i++){
+	for (i = 0; i < fc->nisodma; i++) {
 		fc->ir[i]->maxq = FWMAXQUEUE;
 		fc->it[i]->maxq = FWMAXQUEUE;
 	}
@@ -829,9 +829,9 @@ void fw_init(struct firewire_comm *fc)
 
 	STAILQ_INIT(&fc->devices);
 
-/* Initialize Async handlers */
+	/* Initialize Async handlers */
 	STAILQ_INIT(&fc->binds);
-	for( i = 0 ; i < 0x40 ; i++){
+	for (i = 0; i < 0x40; i++) {
 		STAILQ_INIT(&fc->tlabels[i]);
 	}
 
@@ -839,14 +839,14 @@ void fw_init(struct firewire_comm *fc)
 #if 0
 	CSRARC(fc, oMPR) = 0x3fff0001; /* # output channel = 1 */
 	CSRARC(fc, oPCR) = 0x8000007a;
-	for(i = 4 ; i < 0x7c/4 ; i+=4){
-		CSRARC(fc, i + oPCR) = 0x8000007a; 
+	for (i = 4; i < 0x7c/4; i += 4) {
+		CSRARC(fc, i + oPCR) = 0x8000007a;
 	}
- 
+
 	CSRARC(fc, iMPR) = 0x00ff0001; /* # input channel = 1 */
 	CSRARC(fc, iPCR) = 0x803f0000;
-	for(i = 4 ; i < 0x7c/4 ; i+=4){
-		CSRARC(fc, i + iPCR) = 0x0; 
+	for (i = 4; i < 0x7c/4; i += 4) {
+		CSRARC(fc, i + iPCR) = 0x0;
 	}
 #endif
 
@@ -854,10 +854,11 @@ void fw_init(struct firewire_comm *fc)
 
 #ifdef FW_VMACCESS
 	xfer = fw_xfer_alloc();
-	if(xfer == NULL) return;
+	if (xfer == NULL)
+		return;
 
-	fwb = (struct fw_bind *)malloc(sizeof (struct fw_bind), M_FW, M_NOWAIT);
-	if(fwb == NULL){
+	fwb = malloc(sizeof(struct fw_bind), M_FW, M_NOWAIT);
+	if (fwb == NULL) {
 		fw_xfer_free(xfer);
 		return;
 	}
@@ -873,8 +874,8 @@ void fw_init(struct firewire_comm *fc)
 #endif
 }
 
-#define BIND_CMP(addr, fwb) (((addr) < (fwb)->start)?-1:\
-    ((fwb)->end < (addr))?1:0)
+#define BIND_CMP(addr, fwb) (((addr) < (fwb)->start)? -1 : \
+    ((fwb)->end < (addr)) ? 1 : 0)
 
 /*
  * To lookup bound process from IEEE1394 address.
@@ -893,7 +894,7 @@ fw_bindlookup(struct firewire_comm *fc, 
 			break;
 		}
 	FW_GUNLOCK(fc);
-	return(r);
+	return (r);
 }
 
 /*
@@ -978,7 +979,7 @@ fw_xferlist_add(struct fw_xferlist *q, s
 	for (i = 0; i < n; i++) {
 		xfer = fw_xfer_alloc_buf(type, slen, rlen);
 		if (xfer == NULL)
-			return (n);
+			return (i);
 		xfer->fc = fc;
 		xfer->sc = sc;
 		xfer->hand = hand;
@@ -995,10 +996,10 @@ fw_xferlist_remove(struct fw_xferlist *q
 	struct fw_xfer *xfer, *next;
 
 	for (xfer = STAILQ_FIRST(q); xfer != NULL; xfer = next) {
-                next = STAILQ_NEXT(xfer, link);
-                fw_xfer_free_buf(xfer);
-        }
-        STAILQ_INIT(q);
+		next = STAILQ_NEXT(xfer, link);
+		fw_xfer_free_buf(xfer);
+	}
+	STAILQ_INIT(q);
 }
 /*
  * dump packet header
@@ -1031,7 +1032,7 @@ fw_tl_free(struct firewire_comm *fc, str
 	}
 	/* make sure the label is allocated */
 	STAILQ_FOREACH(txfer, &fc->tlabels[xfer->tl], tlabel)
-		if(txfer == xfer)
+		if (txfer == xfer)
 			break;
 	if (txfer == NULL) {
 		printf("%s: the xfer is not in the queue "
@@ -1064,7 +1065,7 @@ fw_tl2xfer(struct firewire_comm *fc, int
 
 	mtx_lock(&fc->tlabel_lock);
 	STAILQ_FOREACH(xfer, &fc->tlabels[tlabel], tlabel)
-		if(xfer->send.hdr.mode.hdr.dst == node) {
+		if (xfer->send.hdr.mode.hdr.dst == node) {
 			mtx_unlock(&fc->tlabel_lock);
 			splx(s);
 			KASSERT(xfer->tl == tlabel,
@@ -1075,18 +1076,18 @@ fw_tl2xfer(struct firewire_comm *fc, int
 				printf("%s: invalid response tcode "
 				    "(0x%x for 0x%x)\n", __FUNCTION__,
 				    tcode, req);
-				return(NULL);
+				return (NULL);
 			}
-			
+
 			if (firewire_debug > 2)
 				printf("fw_tl2xfer: found tl=%d\n", tlabel);
-			return(xfer);
+			return (xfer);
 		}
 	mtx_unlock(&fc->tlabel_lock);
 	if (firewire_debug > 1)
 		printf("fw_tl2xfer: not found tl=%d\n", tlabel);
 	splx(s);
-	return(NULL);
+	return (NULL);
 }
 
 /*
@@ -1113,14 +1114,14 @@ fw_xfer_alloc_buf(struct malloc_type *ty
 
 	xfer = fw_xfer_alloc(type);
 	if (xfer == NULL)
-		return(NULL);
+		return (NULL);
 	xfer->send.pay_len = send_len;
 	xfer->recv.pay_len = recv_len;
 	if (send_len > 0) {
 		xfer->send.payload = malloc(send_len, type, M_NOWAIT | M_ZERO);
 		if (xfer->send.payload == NULL) {
 			fw_xfer_free(xfer);
-			return(NULL);
+			return (NULL);
 		}
 	}
 	if (recv_len > 0) {
@@ -1129,10 +1130,10 @@ fw_xfer_alloc_buf(struct malloc_type *ty
 			if (xfer->send.payload != NULL)
 				free(xfer->send.payload, type);
 			fw_xfer_free(xfer);
-			return(NULL);
+			return (NULL);
 		}
 	}
-	return(xfer);
+	return (xfer);
 }
 
 /*
@@ -1154,18 +1155,19 @@ fw_xfer_done(struct fw_xfer *xfer)
 }
 
 void
-fw_xfer_unload(struct fw_xfer* xfer)
+fw_xfer_unload(struct fw_xfer *xfer)
 {
 	int s;
 
-	if(xfer == NULL ) return;
-	if(xfer->flag & FWXF_INQ){
+	if (xfer == NULL)
+		return;
+	if (xfer->flag & FWXF_INQ) {
 		printf("fw_xfer_free FWXF_INQ\n");
 		s = splfw();
 		FW_GLOCK(xfer->fc);
 		STAILQ_REMOVE(&xfer->q->q, xfer, fw_xfer, link);
 #if 0
-		xfer->q->queued --;
+		xfer->q->queued--;
 #endif
 		FW_GUNLOCK(xfer->fc);
 		splx(s);
@@ -1177,7 +1179,7 @@ fw_xfer_unload(struct fw_xfer* xfer)
 		 */
 		fw_tl_free(xfer->fc, xfer);
 #if 1
-		if(xfer->flag & FWXF_START)
+		if (xfer->flag & FWXF_START)
 			/*
 			 * This could happen if:
 			 *  1. We call fwohci_arcv() before fwohci_txd().
@@ -1189,28 +1191,27 @@ fw_xfer_unload(struct fw_xfer* xfer)
 	xfer->flag = FWXF_INIT;
 	xfer->resp = 0;
 }
+
 /*
- * To free IEEE1394 XFER structure. 
+ * To free IEEE1394 XFER structure.
  */
 void
-fw_xfer_free_buf( struct fw_xfer* xfer)
+fw_xfer_free_buf(struct fw_xfer *xfer)
 {
 	if (xfer == NULL) {
 		printf("%s: xfer == NULL\n", __func__);
 		return;
 	}
 	fw_xfer_unload(xfer);
-	if(xfer->send.payload != NULL){
+	if (xfer->send.payload != NULL)
 		free(xfer->send.payload, xfer->malloc);
-	}
-	if(xfer->recv.payload != NULL){
+	if (xfer->recv.payload != NULL)
 		free(xfer->recv.payload, xfer->malloc);
-	}
 	free(xfer, xfer->malloc);
 }
 
 void
-fw_xfer_free( struct fw_xfer* xfer)
+fw_xfer_free(struct fw_xfer *xfer)
 {
 	if (xfer == NULL) {
 		printf("%s: xfer == NULL\n", __func__);
@@ -1231,7 +1232,7 @@ fw_asy_callback_free(struct fw_xfer *xfe
 }
 
 /*
- * To configure PHY. 
+ * To configure PHY.
  */
 static void
 fw_phy_config(struct firewire_comm *fc, int root_node, int gap_count)
@@ -1250,9 +1251,9 @@ fw_phy_config(struct firewire_comm *fc, 
 	fp = &xfer->send.hdr;
 	fp->mode.ld[1] = 0;
 	if (root_node >= 0)
-		fp->mode.ld[1] |= (root_node & 0x3f) << 24 | 1 << 23;
+		fp->mode.ld[1] |= (1 << 23) | (root_node & 0x3f) << 24;
 	if (gap_count >= 0)
-		fp->mode.ld[1] |= 1 << 22 | (gap_count & 0x3f) << 16;
+		fp->mode.ld[1] |= (1 << 22) | (gap_count & 0x3f) << 16;
 	fp->mode.ld[2] = ~fp->mode.ld[1];
 /* XXX Dangerous, how to pass PHY packet to device driver */
 	fp->mode.common.tcode |= FWTCODE_PHY;
@@ -1264,113 +1265,107 @@ fw_phy_config(struct firewire_comm *fc, 
 }
 
 /*
- * Dump self ID. 
+ * Dump self ID.
  */
 static void
 fw_print_sid(uint32_t sid)
 {
 	union fw_self_id *s;
 	s = (union fw_self_id *) &sid;
-	if ( s->p0.sequel ) {
-		if ( s->p1.sequence_num == FW_SELF_ID_PAGE0 ) {
+	if (s->p0.sequel) {
+		if (s->p1.sequence_num == FW_SELF_ID_PAGE0) {
 			printf("node:%d p3:%d p4:%d p5:%d p6:%d p7:%d"
-				"p8:%d p9:%d p10:%d\n",
-				s->p1.phy_id, s->p1.port3, s->p1.port4,
-				s->p1.port5, s->p1.port6, s->p1.port7,
-				s->p1.port8, s->p1.port9, s->p1.port10);
-		} else if (s->p2.sequence_num == FW_SELF_ID_PAGE1 ){
+			    "p8:%d p9:%d p10:%d\n",
+			    s->p1.phy_id, s->p1.port3, s->p1.port4,
+			    s->p1.port5, s->p1.port6, s->p1.port7,
+			    s->p1.port8, s->p1.port9, s->p1.port10);
+		} else if (s->p2.sequence_num == FW_SELF_ID_PAGE1) {
 			printf("node:%d p11:%d p12:%d p13:%d p14:%d p15:%d\n",
-				s->p2.phy_id, s->p2.port11, s->p2.port12,
-				s->p2.port13, s->p2.port14, s->p2.port15);
+			    s->p2.phy_id, s->p2.port11, s->p2.port12,
+			    s->p2.port13, s->p2.port14, s->p2.port15);
 		} else {
 			printf("node:%d Unknown Self ID Page number %d\n",
-				s->p1.phy_id, s->p1.sequence_num);
+			    s->p1.phy_id, s->p1.sequence_num);
 		}
 	} else {
 		printf("node:%d link:%d gap:%d spd:%d con:%d pwr:%d"
-			" p0:%d p1:%d p2:%d i:%d m:%d\n",
-			s->p0.phy_id, s->p0.link_active, s->p0.gap_count,
-			s->p0.phy_speed, s->p0.contender,
-			s->p0.power_class, s->p0.port0, s->p0.port1,
-			s->p0.port2, s->p0.initiated_reset, s->p0.more_packets);
+		    " p0:%d p1:%d p2:%d i:%d m:%d\n",
+		    s->p0.phy_id, s->p0.link_active, s->p0.gap_count,
+		    s->p0.phy_speed, s->p0.contender,
+		    s->p0.power_class, s->p0.port0, s->p0.port1,
+		    s->p0.port2, s->p0.initiated_reset, s->p0.more_packets);
 	}
 }
 
 /*
- * To receive self ID. 
+ * To receive self ID.
  */
-void fw_sidrcv(struct firewire_comm* fc, uint32_t *sid, u_int len)
+void fw_sidrcv(struct firewire_comm *fc, uint32_t *sid, u_int len)
 {
 	uint32_t *p;
 	union fw_self_id *self_id;
 	u_int i, j, node, c_port = 0, i_branch = 0;
 
-	fc->sid_cnt = len /(sizeof(uint32_t) * 2);
+	fc->sid_cnt = len / (sizeof(uint32_t) * 2);
 	fc->max_node = fc->nodeid & 0x3f;
 	CSRARC(fc, NODE_IDS) = ((uint32_t)fc->nodeid) << 16;
 	fc->status = FWBUSCYMELECT;
 	fc->topology_map->crc_len = 2;
-	fc->topology_map->generation ++;
+	fc->topology_map->generation++;
 	fc->topology_map->self_id_count = 0;
-	fc->topology_map->node_count = 0;
-	fc->speed_map->generation ++;
-	fc->speed_map->crc_len = 1 + (64*64 + 3) / 4;
+	fc->topology_map->node_count= 0;
+	fc->speed_map->generation++;
+	fc->speed_map->crc_len = 1 + (64 * 64 + 3) / 4;
 	self_id = &fc->topology_map->self_id[0];
-	for(i = 0; i < fc->sid_cnt; i ++){
+	for (i = 0; i < fc->sid_cnt; i++) {
 		if (sid[1] != ~sid[0]) {
-			device_printf(fc->bdev, "%s: ERROR invalid self-id packet\n",
-						__func__);
+			device_printf(fc->bdev,
+			    "%s: ERROR invalid self-id packet\n", __func__);
 			sid += 2;
 			continue;
 		}
 		*self_id = *((union fw_self_id *)sid);
 		fc->topology_map->crc_len++;
-		if(self_id->p0.sequel == 0){
-			fc->topology_map->node_count ++;
+		if (self_id->p0.sequel == 0) {
+			fc->topology_map->node_count++;
 			c_port = 0;
 			if (firewire_debug)
 				fw_print_sid(sid[0]);
 			node = self_id->p0.phy_id;
-			if(fc->max_node < node){
+			if (fc->max_node < node)
 				fc->max_node = self_id->p0.phy_id;
-			}
 			/* XXX I'm not sure this is the right speed_map */
-			fc->speed_map->speed[node][node]
-					= self_id->p0.phy_speed;
-			for (j = 0; j < node; j ++) {
-				fc->speed_map->speed[j][node]
-					= fc->speed_map->speed[node][j]
-					= min(fc->speed_map->speed[j][j],
-							self_id->p0.phy_speed);
+			fc->speed_map->speed[node][node] =
+			    self_id->p0.phy_speed;
+			for (j = 0; j < node; j++) {
+				fc->speed_map->speed[j][node] =
+				    fc->speed_map->speed[node][j] =
+				    min(fc->speed_map->speed[j][j],
+					self_id->p0.phy_speed);
 			}
 			if ((fc->irm == -1 || self_id->p0.phy_id > fc->irm) &&
-			  (self_id->p0.link_active && self_id->p0.contender)) {
+			  (self_id->p0.link_active && self_id->p0.contender))
 				fc->irm = self_id->p0.phy_id;
-			}
-			if(self_id->p0.port0 >= 0x2){
+			if (self_id->p0.port0 >= 0x2)
 				c_port++;
-			}
-			if(self_id->p0.port1 >= 0x2){
+			if (self_id->p0.port1 >= 0x2)
 				c_port++;
-			}
-			if(self_id->p0.port2 >= 0x2){
+			if (self_id->p0.port2 >= 0x2)
 				c_port++;
-			}
 		}
-		if(c_port > 2){
+		if (c_port > 2)
 			i_branch += (c_port - 2);
-		}
 		sid += 2;
 		self_id++;
-		fc->topology_map->self_id_count ++;
+		fc->topology_map->self_id_count++;
 	}
 	/* CRC */
 	fc->topology_map->crc = fw_crc16(
-			(uint32_t *)&fc->topology_map->generation,
-			fc->topology_map->crc_len * 4);
+	    (uint32_t *)&fc->topology_map->generation,
+	    fc->topology_map->crc_len * 4);
 	fc->speed_map->crc = fw_crc16(
-			(uint32_t *)&fc->speed_map->generation,
-			fc->speed_map->crc_len * 4);
+	    (uint32_t *)&fc->speed_map->generation,
+	    fc->speed_map->crc_len * 4);
 	/* byteswap and copy to CSR */
 	p = (uint32_t *)fc->topology_map;
 	for (i = 0; i <= fc->topology_map->crc_len; i++)
@@ -1379,14 +1374,13 @@ void fw_sidrcv(struct firewire_comm* fc,
 	CSRARC(fc, SPED_MAP) = htonl(*p++);
 	CSRARC(fc, SPED_MAP + 4) = htonl(*p++);
 	/* don't byte-swap uint8_t array */
-	bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1)*4);
+	bcopy(p, &CSRARC(fc, SPED_MAP + 8), (fc->speed_map->crc_len - 1) * 4);
 
 	fc->max_hop = fc->max_node - i_branch;
 	device_printf(fc->bdev, "%d nodes, maxhop <= %d %s irm(%d) %s\n",
-			fc->max_node + 1, fc->max_hop,
-			(fc->irm == -1) ? "Not IRM capable" : "cable IRM",
-			fc->irm,
-			(fc->irm == fc->nodeid) ? " (me) " : "");
+	    fc->max_node + 1, fc->max_hop,
+	    (fc->irm == -1) ? "Not IRM capable" : "cable IRM",
+	    fc->irm, (fc->irm == fc->nodeid) ? " (me) " : "");
 
 	if (try_bmr && (fc->irm != -1) && (CSRARC(fc, BUS_MGR_ID) == 0x3f)) {
 		if (fc->irm == fc->nodeid) {
@@ -1395,26 +1389,27 @@ void fw_sidrcv(struct firewire_comm* fc,
 			fw_bmr(fc);
 		} else {
 			fc->status = FWBUSMGRELECT;
-			callout_reset(&fc->bmr_callout, hz/8,
-				(void *)fw_try_bmr, (void *)fc);
+			callout_reset(&fc->bmr_callout, hz / 8,
+			    fw_try_bmr, fc);
 		}
 	} else
 		fc->status = FWBUSMGRDONE;
 
-	callout_reset(&fc->busprobe_callout, hz/4,
-			(void *)fw_bus_probe, (void *)fc);
+	callout_reset(&fc->busprobe_callout, hz / 4, fw_bus_probe, fc);
 }
 
 /*
- * To probe devices on the IEEE1394 bus. 
+ * To probe devices on the IEEE1394 bus.
  */
 static void
-fw_bus_probe(struct firewire_comm *fc)
+fw_bus_probe(void *arg)
 {
-	int s;
+	struct firewire_comm *fc;
 	struct fw_device *fwdev;
+	int s;
 
 	s = splfw();
+	fc = arg;
 	fc->status = FWBUSEXPLORE;
 
 	/* Invalidate all devices, just after bus reset. */
@@ -1438,7 +1433,7 @@ fw_bus_probe(struct firewire_comm *fc)
 		}
 	splx(s);
 
-	wakeup((void *)fc);
+	wakeup(fc);
 }
 
 static int
@@ -1449,10 +1444,9 @@ fw_explore_read_quads(struct fw_device *
 	uint32_t tmp;
 	int i, error;
 
-	for (i = 0; i < length; i ++, offset += sizeof(uint32_t)) {
-		xfer = fwmem_read_quad(fwdev, NULL, -1,
-		    0xffff, 0xf0000000 | offset, (void *)&tmp,
-		    fw_xferwake);
+	for (i = 0; i < length; i++, offset += sizeof(uint32_t)) {
+		xfer = fwmem_read_quad(fwdev, NULL, -1, 0xffff,
+		    0xf0000000 | offset, &tmp, fw_xferwake);
 		if (xfer == NULL)
 			return (-1);
 		fw_xferwait(xfer);
@@ -1476,14 +1470,14 @@ fw_explore_csrblock(struct fw_device *fw
 	struct csrdirectory *dir;
 	struct csrreg *reg;
 

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-src-head mailing list