Re: [patch] ep(4) panic

From: M. Warner Losh <imp_at_bsdimp.com>
Date: Sat, 25 Jun 2005 14:53:57 -0600 (MDT)
In message: <42BD6865.4090608_at_savvis.net>
            Maksim Yevmenkin <maksim.yevmenkin_at_savvis.net> writes:
: the way i understand it: this code is in the "probe" routine and when 
: its called ifp structure was not allocated/setup yet. the "attach" 
: routine will call "ep_attach" later that will allocate/setup ifp and 
: read/set mac address (once again). so, the card works just fine.
: 
: it is interesting that my 4.x has different comment
: 
: $FreeBSD: /repoman/r/ncvs/src/sys/dev/ep/if_ep_pccard.c,v 1.12.2.3 
: 2003/10/06 02:53:51 imp Exp $
: 
: 	/*
: 	 * For some reason the 3c574 needs this.
: 	 */
: 	ep_get_macaddr(sc, (u_char *)&sc->arpcom.ac_enaddr);
: 
: 
: perhaps the comment in -current should be changed as well? can anyone 
: please shed some light on this?

The comment in -current is wrong.  The routine doesn't set the MAC
address, but instead just reads it out of EEPROM.  For reasons I still
don't know or understand, this still seems to be required.  I'll have
to look into when I have an hour or two to kill.

The following patch works on:
	3CCFE547BT, 3C574-TX, 3CCE589EC, 3C589D-TP, 3C589C, 3C589B,
	3C562D/3C563D, 3CCFEM556

which covers almost all the cards that are obtainable these days.  It
doesn't work with:

	3C1			(we've never worked with this card)
	3C562 or 3C562B/3C563B	I think that there's an address line
				work around needed for thse two cards.
				5.x doesn't seem to work with them
				either.

So I think it is good/safe to commit.  I'll ask the RE if people here
test it.

Warner




Index: if_ep.c
===================================================================
RCS file: /cache/ncvs/src/sys/dev/ep/if_ep.c,v
retrieving revision 1.137
diff -u -r1.137 if_ep.c
--- if_ep.c	10 Jun 2005 16:49:07 -0000	1.137
+++ if_ep.c	25 Jun 2005 20:12:06 -0000
_at__at_ -129,7 +129,7 _at__at_
  * before
  */
 int
-get_e(struct ep_softc *sc, uint16_t offset, uint16_t *result)
+ep_get_e(struct ep_softc *sc, uint16_t offset, uint16_t *result)
 {
 
 	if (eeprom_rdy(sc))
_at__at_ -158,7 +158,7 _at__at_
 
 	GO_WINDOW(sc, 0);
 	for (i = EEPROM_NODE_ADDR_0; i <= EEPROM_NODE_ADDR_2; i++) {
-		error = get_e(sc, i, &result);
+		error = ep_get_e(sc, i, &result);
 		if (error)
 			return (error);
 		macaddr[i] = htons(result);
_at__at_ -203,12 +203,12 _at__at_
 	GO_WINDOW(sc, 0);
 	sc->epb.cmd_off = 0;
 
-	error = get_e(sc, EEPROM_PROD_ID, &result);
+	error = ep_get_e(sc, EEPROM_PROD_ID, &result);
 	if (error)
 		goto bad;
 	sc->epb.prod_id = result;
 
-	error = get_e(sc, EEPROM_RESOURCE_CFG, &result);
+	error = ep_get_e(sc, EEPROM_RESOURCE_CFG, &result);
 	if (error)
 		goto bad;
 	sc->epb.res_cfg = result;
Index: if_ep_isa.c
===================================================================
RCS file: /cache/ncvs/src/sys/dev/ep/if_ep_isa.c,v
retrieving revision 1.26
diff -u -r1.26 if_ep_isa.c
--- if_ep_isa.c	20 Jan 2005 19:39:33 -0000	1.26
+++ if_ep_isa.c	25 Jun 2005 20:10:50 -0000
_at__at_ -361,13 +361,13 _at__at_
 	uint8_t cksum_high = 0;
 	uint8_t cksum_low = 0;
 
-	error = get_e(sc, 0x0f, &val);
+	error = ep_get_e(sc, 0x0f, &val);
 	if (error)
 		return (ENXIO);
 	cksum = val;
 
 	for (i = 0; i < 0x0f; i++) {
-		error = get_e(sc, i, &val);
+		error = ep_get_e(sc, i, &val);
 		if (error)
 			return (ENXIO);
 		switch (i) {
Index: if_ep_pccard.c
===================================================================
RCS file: /cache/ncvs/src/sys/dev/ep/if_ep_pccard.c,v
retrieving revision 1.44
diff -u -r1.44 if_ep_pccard.c
--- if_ep_pccard.c	24 Jun 2005 14:36:52 -0000	1.44
+++ if_ep_pccard.c	25 Jun 2005 20:46:25 -0000
_at__at_ -73,6 +73,7 _at__at_
 	struct ep_board *epb = &sc->epb;
 	const char *desc;
 	uint16_t result;
+	uint8_t enaddr[6];
 	int error;
 
 	error = ep_alloc(dev);
_at__at_ -96,7 +97,7 _at__at_
 	epb->cmd_off = 0;
 
 	/* XXX check return */
-	error = get_e(sc, EEPROM_PROD_ID, &result);
+	error = ep_get_e(sc, EEPROM_PROD_ID, &result);
 	epb->prod_id = result;
 
 	if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
_at__at_ -105,7 +106,7 _at__at_
 			    "failed (nonfatal) id 0x%x\n", epb->prod_id);
 		epb->cmd_off = 2;
 		/* XXX check return */
-		error = get_e(sc, EEPROM_PROD_ID, &result);
+		error = ep_get_e(sc, EEPROM_PROD_ID, &result);
 		epb->prod_id = result;
 		if ((desc = ep_pccard_identify(epb->prod_id)) == NULL) {
 			device_printf(dev, "Unit failed to come ready or "
_at__at_ -114,14 +115,16 _at__at_
 			return (ENXIO);
 		}
 	}
-	device_set_desc(dev, desc);
-
 	/*
-	 * Newer cards supported by this device need to have their
-	 * MAC address set.
+	 * For reasons unknown, getting the MAC address here makes the
+	 * 3C574 and 3C556 families get the right MAC address later.
+	 * otherwise, the ID field is used for each of the words of the
+	 * MAC address instead of the proper one.  It is unclear why
+	 * ep_get_macaddr would have this side effect, or even what
+	 * that side effect really is.
 	 */
-	error = ep_get_macaddr(sc, (u_char *)&IFP2ENADDR(sc->ifp));
-
+	ep_get_macaddr(sc, enaddr);
+	device_set_desc(dev, desc);
 	ep_free(dev);
 	return (0);
 }
_at__at_ -189,14 +192,14 _at__at_
 	sc->epb.cmd_off = 0;
 
 	/* XXX check return */
-	error = get_e(sc, EEPROM_PROD_ID, &result);
+	error = ep_get_e(sc, EEPROM_PROD_ID, &result);
 	sc->epb.prod_id = result;
 
 	if (!ep_pccard_card_attach(&sc->epb)) {
 		sc->epb.cmd_off = 2;
-		error = get_e(sc, EEPROM_PROD_ID, &result);
+		error = ep_get_e(sc, EEPROM_PROD_ID, &result);
 		sc->epb.prod_id = result;
-		error = get_e(sc, EEPROM_RESOURCE_CFG, &result);
+		error = ep_get_e(sc, EEPROM_RESOURCE_CFG, &result);
 		sc->epb.res_cfg = result;
 		if (!ep_pccard_card_attach(&sc->epb)) {
 			device_printf(dev,
_at__at_ -205,7 +208,7 _at__at_
 			goto bad;
 		}
 	}
-	error = get_e(sc, EEPROM_ADDR_CFG, &result);
+	error = ep_get_e(sc, EEPROM_ADDR_CFG, &result);
 
 	/* ROM size = 0, ROM base = 0 */
 	/* For now, ignore AUTO SELECT feature of 3C589B and later. */
Index: if_epvar.h
===================================================================
RCS file: /cache/ncvs/src/sys/dev/ep/if_epvar.h,v
retrieving revision 1.16
diff -u -r1.16 if_epvar.h
--- if_epvar.h	10 Jun 2005 16:49:07 -0000	1.16
+++ if_epvar.h	25 Jun 2005 20:11:31 -0000
_at__at_ -79,7 +79,7 _at__at_
 void ep_get_media(struct ep_softc *);
 int ep_attach(struct ep_softc *);
 void ep_intr(void *);
-int get_e(struct ep_softc *, uint16_t, uint16_t *);
+int ep_get_e(struct ep_softc *, uint16_t, uint16_t *);
 int ep_get_macaddr(struct ep_softc *, u_char *);
 
 #define CSR_READ_1(sc, off) (bus_space_read_1((sc)->bst, (sc)->bsh, off))
Received on Sat Jun 25 2005 - 18:53:08 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:37 UTC