Subject: fwohci + cardbus
To: None <current-users@netbsd.org>
From: Love <lha@stacken.kth.se>
List: current-users
Date: 12/13/2001 07:57:32
Hi

I just bought a cardbus fwohci controller and after some time I got fed up
with that the computer fell over when I removed the card. Too much memory,
dumping takes too long :)

One problem I have with the patch is that the interrupt handler for the
card seem to be called after the card is removed, and 0xffffffff is
returned. How should this be handled ?

Love

Index: cardbus/fwohci_cardbus.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/cardbus/fwohci_cardbus.c,v
retrieving revision 1.3
diff -w -u -r1.3 fwohci_cardbus.c
--- fwohci_cardbus.c	2001/11/15 09:48:02	1.3
+++ fwohci_cardbus.c	2001/12/13 05:43:57
@@ -64,16 +64,16 @@
 	cardbus_function_tag_t	sc_cf;
 	cardbus_devfunc_t	sc_ct;
 	void		       *sc_ih;
+	bus_addr_t		sc_base_reg;
 };
 
 static int fwohci_cardbus_match(struct device *, struct cfdata *, void *);
 static void fwohci_cardbus_attach(struct device *, struct device *, void *);
+static int fwohci_cardbus_detach(struct device *, int);
 
 struct cfattach fwohci_cardbus_ca = {
-	sizeof(struct fwohci_cardbus_softc), fwohci_cardbus_match, fwohci_cardbus_attach,
-#if 0
-	fwohci_cardbus_detach, fwohci_activate
-#endif
+	sizeof(struct fwohci_cardbus_softc), fwohci_cardbus_match,
+	    fwohci_cardbus_attach, fwohci_cardbus_detach
 };
 
 #define CARDBUS_OHCI_MAP_REGISTER PCI_OHCI_MAP_REGISTER
@@ -114,7 +114,7 @@
 	if (Cardbus_mapreg_map(ct, CARDBUS_OHCI_MAP_REGISTER,
 	      CARDBUS_MAPREG_TYPE_MEM, 0,
 	      &sc->sc_sc.sc_memt, &sc->sc_sc.sc_memh,
-	      NULL, &sc->sc_sc.sc_memsize)) {
+	      &sc->sc_base_reg, &sc->sc_sc.sc_memsize)) {
 		printf("%s: can't map OCHI register space\n", devname);
 		return;
 	}
@@ -156,10 +156,27 @@
 	}
 	printf("%s: interrupting at %d\n", devname, ca->ca_intrline);
 
-	/* XXX NULL should be replaced by some call to Cardbus coed */
+	/* XXX NULL should be replaced by some call to Cardbus code */
 	if (fwohci_init(&sc->sc_sc, NULL) != 0) {
 		cardbus_intr_disestablish(cc, cf, sc->sc_ih);
-		bus_space_unmap(sc->sc_sc.sc_memt, sc->sc_sc.sc_memh,
+		Cardbus_mapreg_unmap(sc->sc_ct, sc->sc_base_reg,
+		    sc->sc_sc.sc_memt, sc->sc_sc.sc_memh,
+		    sc->sc_sc.sc_memsize);
+	}
+}
+
+static int
+fwohci_cardbus_detach(struct device *self, int flags)
+{
+	struct fwohci_cardbus_softc *sc = (struct fwohci_cardbus_softc *)self;
+	int rv;
+
+	if ((rv = fwohci_detach(&sc->sc_sc)) == 0) {
+		cardbus_intr_disestablish(sc->sc_cc, sc->sc_cf, sc->sc_ih);
+		Cardbus_mapreg_unmap(sc->sc_ct, sc->sc_base_reg,
+		    sc->sc_sc.sc_memt, sc->sc_sc.sc_memh,
 		    sc->sc_sc.sc_memsize);
 	}
+
+	return rv;
 }
Index: ieee1394/fwohci.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/ieee1394/fwohci.c,v
retrieving revision 1.46
diff -w -u -r1.46 fwohci.c
--- fwohci.c	2001/11/15 09:48:08	1.46
+++ fwohci.c	2001/12/13 05:43:59
@@ -281,6 +281,44 @@
 	return 0;
 }
 
+int
+fwohci_detach(struct fwohci_softc *sc)
+{
+	struct ieee1394_softc *iea;
+
+	sc->sc_dying = 1;
+	wakeup(fwohci_event_thread);
+	if (tsleep(sc, PWAIT, "fwohcidet", hz * 60))
+		printf("%s: fw event thread didn't die\n",
+		    sc->sc_sc1394.sc1394_dev.dv_xname);
+	
+	callout_stop(&sc->sc_selfid_callout);
+
+	LIST_FOREACH(iea, &sc->sc_nodelist, sc1394_node)
+		iea->sc1394_node_id = 0xffff;
+	fwohci_check_nodes(sc);
+
+	config_detach(sc->sc_sc1394.sc1394_if, 0);
+
+	fwohci_ctx_free(sc, sc->sc_ctx_arrq);
+	fwohci_ctx_free(sc, sc->sc_ctx_arrs);
+	fwohci_ctx_free(sc, sc->sc_ctx_atrq);
+	fwohci_ctx_free(sc, sc->sc_ctx_atrs);
+	free(sc->sc_ctx_ir, M_DEVBUF);
+
+	fwohci_buf_free(sc, &sc->sc_buf_cnfrom);
+	fwohci_buf_free(sc, &sc->sc_buf_selfid);
+
+	shutdownhook_disestablish(sc->sc_shutdownhook);
+	powerhook_disestablish(sc->sc_powerhook);
+
+	evcnt_detach(&sc->sc_intrcnt);
+	evcnt_detach(&sc->sc_isocnt);
+	evcnt_detach(&sc->sc_isopktcnt);
+
+	return 0;
+}
+
 static int
 fwohci_if_setiso(struct device *self, u_int32_t channel, u_int32_t tag,
     u_int32_t direction, void (*handler)(struct device *, struct mbuf *))
@@ -319,6 +357,9 @@
 	for (;;) {
 		intmask = OHCI_CSR_READ(sc, OHCI_REG_IntEventClear);
 
+		if (intmask == 0xffffffff) /* XXX card removed */
+			return 1;
+
 		/*
 		 * On a bus reset, everything except bus reset gets
 		 * cleared.  That can't get cleared until the selfid
@@ -479,6 +520,9 @@
 	/* Main loop. It's not coming back normally. */
 
 	fwohci_event_thread(sc);
+
+	/* Wakeup parent if needed */
+	wakeup(sc);
 
 	kthread_exit(0);
 }
Index: ieee1394/fwohcivar.h
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/ieee1394/fwohcivar.h,v
retrieving revision 1.15
diff -w -u -r1.15 fwohcivar.h
--- fwohcivar.h	2001/07/17 11:01:04	1.15
+++ fwohcivar.h	2001/12/13 05:43:59
@@ -189,6 +189,7 @@
 };
 
 int fwohci_init (struct fwohci_softc *, const struct evcnt *);
+int fwohci_detach(struct fwohci_softc *);
 int fwohci_intr (void *);
 int fwohci_print (void *, const char *);
 
Index: pci/pcidevs
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/pci/pcidevs,v
retrieving revision 1.372
diff -w -u -r1.372 pcidevs
--- pcidevs	2001/12/11 11:21:01	1.372
+++ pcidevs	2001/12/13 05:44:02
@@ -1875,6 +1875,7 @@
 product V3 V96DPC	0xc960	V96DPC	i960 (Dual) Host-PCI Bridge
 
 /* VIA Technologies products, from http://www.via.com.tw/ */
+procuct	VIATECH	VT6305		0x0130	VT6305 OCHI IEEE 1394 Controller
 product VIATECH VT8363_HB	0x0305	VT8363 KT133 System Controller
 product	VIATECH	VT8371_HB	0x0391	VT8371 (Apollo KX133) Host Bridge
 product VIATECH VT8501_MVP4	0x0501	VT8501 MVP4 System Controller
@@ -1899,6 +1900,7 @@
 product VIATECH VT83C572	0x3038	VT83C572 USB Controller
 product VIATECH VT82C586_PWR	0x3040	VT82C586 (Apollo VP) Power Management Controller
 product VIATECH VT3043		0x3043	VT3043 (Rhine) 10/100 Ethernet
+product	VIATECH VT6306		0x3044	VT3606 OCHI IEEE 1394 Controller
 product VIATECH VT82C686A_SMB	0x3057	VT82C686A SMBus Controller
 product VIATECH VT82C686A_AC97	0x3058	VT82C686A AC-97 Audio Controller
 product VIATECH VT8233_AC97	0x3059	VT8233 AC-97 Audio Controller