From dmlb@ragnet.demon.co.uk  Sat May 13 04:30:38 2000
Return-Path: <dmlb@ragnet.demon.co.uk>
Received: from finch-post-10.mail.demon.net (finch-post-10.mail.demon.net [194.217.242.38])
	by hub.freebsd.org (Postfix) with ESMTP id D2CFA37BB3F
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 13 May 2000 04:30:36 -0700 (PDT)
	(envelope-from dmlb@ragnet.demon.co.uk)
Received: from ragnet.demon.co.uk ([158.152.46.40])
	by finch-post-10.mail.demon.net with esmtp (Exim 2.12 #1)
	id 12qa7u-000OEL-0A; Sat, 13 May 2000 11:30:34 +0000
Received: from dmlb by ragnet.demon.co.uk with local (Exim 3.03 #1)
	id 12qZ9C-000LxK-00; Sat, 13 May 2000 11:27:50 +0100
Message-Id: <E12qZ9C-000LxK-00@ragnet.demon.co.uk>
Date: Sat, 13 May 2000 11:27:50 +0100
From: Duncan Barclay <dmlb@ragnet.demon.co.uk>
Reply-To: dmlb@ragnet.demon.co.uk
To: FreeBSD-gnats-submit@freebsd.org
Cc: imp@village.org
Subject: Patches for if_xe to run under -current
X-Send-Pr-Version: 3.2

>Number:         18528
>Category:       kern
>Synopsis:       realports don't work
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    imp
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat May 13 04:40:00 PDT 2000
>Closed-Date:    Sun Sep 29 17:29:54 MDT 2002
>Last-Modified:  Sun Sep 29 17:29:54 MDT 2002
>Originator:     Duncan Barclay
>Release:        -current
>Organization:
>Environment:

	Current cvsupd on May 5, 2000

>Description:

	Making a PR so it doesn't drop down the cracks, and so
	someone other than Warner knows about this.

>How-To-Repeat:

>Fix:
	
	Apply attached patch in /sys/dev/xe and commit!
	Tested by a number of people on freebsd-xirom list.

Index: if_xe.c
===================================================================
RCS file: /steer/ncvs/src/sys/dev/xe/if_xe.c,v
retrieving revision 1.18
diff -u -r1.18 if_xe.c
--- if_xe.c	2000/05/01 04:41:04	1.18
+++ if_xe.c	2000/05/08 21:15:19
@@ -33,7 +33,6 @@
  * I've pushed this fairly far, but there are some things that need to be
  * done here.  I'm documenting them here in case I get destracted. -- imp
  *
- * xe_memwrite -- maybe better handled pccard layer?
  * xe_cem56fix -- need to figure out how to map the extra stuff.
  */
 
@@ -205,6 +204,7 @@
 /*
  * Debug functions
  */
+#define XE_DEBUG 2
 #ifdef XE_DEBUG
 #define XE_REG_DUMP(scp)		xe_reg_dump((scp))
 #define XE_MII_DUMP(scp)		xe_mii_dump((scp))
@@ -216,91 +216,62 @@
 #endif
 
 /*
- * Two routines to read from/write to the attribute memory
- * the write portion is used only for fixing up the RealPort cards,
- * the reader portion was needed for debugging info, and duplicated some
- * code in xe_card_init(), so it appears here instead with suitable
- * modifications to xe_card_init()
- * -aDe Lovett
+ * Fixing for RealPort cards - they need a little furtling to get the
+ * ethernet working
  */
 static int
-xe_memwrite(device_t dev, off_t offset, u_char byte)
+xe_cem56fix(device_t dev)
 {
-	/* XXX */
-  return (-1);
-}
-
-/*
- * Hacking for RealPort cards
- */
-static int
-xe_cem56fix(struct xe_softc *scp)
-{
-#if XXX		/* Need to revisit */
-  int ioport, fail;
-
-  /* allocate a new I/O slot for the ethernet */
-  /* XXX: ctrl->mapio() always appears to return 0 (success), so
-   *      this may cause problems if another device is listening
-   *	  on 0x300 already.  In this case, you should choose a
-   *      known free I/O port address in the kernel config line
-   *      for the driver.  It will be picked up here and used
-   *      instead of the autodetected value.
-   */
-  slt->io[1].window = 1;
-  slt->io[1].flags = IODF_WS|IODF_16BIT|IODF_ZEROWS|IODF_ACTIVE;
-  slt->io[1].size = 0x10;
-
-#ifdef	XE_IOBASE
-
-  device_printf(scp->dev, "user requested ioport 0x%x\n", XE_IOBASE );
-  ioport = XE_IOBASE;
-  slt->io[1].start = ioport;
-  fail = ctrl->mapio(slt, 1);
-
-#else
+  struct xe_softc *sc = (struct xe_softc *) device_get_softc(dev);
+  bus_space_tag_t bst;
+  bus_space_handle_t bsh;
+  struct resource *r;
+  int rid;
+  int ioport;
 
-  for (ioport = 0x300; ioport < 0x400; ioport += 0x10) {
-    slt->io[1].start = ioport;
-    if ((fail = ctrl->mapio( slt, 1 )) == 0)
-      break;
-  }
+#ifdef XE_DEBUG
+  device_printf(dev, "Hacking your Realport, master\n");
+#endif
 
+#if XE_DEBUG > 1
+  device_printf(dev, "Realport port 0x%0lx, size 0x%0lx\n",
+      bus_get_resource_start(dev, SYS_RES_IOPORT, sc->port_rid),
+      bus_get_resource_count(dev, SYS_RES_IOPORT, sc->port_rid));
 #endif
 
-  /* did we find one? */
-  if (fail) {
-    device_printf(scp->dev, "xe_cem56fix: no free address space\n");
+  rid = 0;
+  r = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid, 0, ~0, 4 << 10, RF_ACTIVE);
+  if (!r) {
+#if XE_DEBUG > 0
+    device_printf(dev, "Can't map in attribute memory\n");
+#endif
     return -1;
   }
 
+  bsh = rman_get_bushandle(r);
+  bst = rman_get_bustag(r);
 
-  /* munge the id_iobase entry for use by the rest of the driver */
-#if XE_DEBUG > 1
-  device_printf(scp->dev, "using 0x%x for RealPort ethernet\n", ioport);
-#endif
-#if 0
-  scp->dev->id_iobase = ioport;
-#endif
+  CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY, rid,
+      PCCARD_A_MEM_ATTR);
+
+  bus_space_write_1(bst, bsh, DINGO_ECOR, DINGO_ECOR_IRQ_LEVEL |
+					  DINGO_ECOR_INT_ENABLE |
+					  DINGO_ECOR_IOB_ENABLE |
+               				  DINGO_ECOR_ETH_ENABLE);
+  ioport = bus_get_resource_start(dev, SYS_RES_IOPORT, sc->port_rid);
+  bus_space_write_1(bst, bsh, DINGO_EBAR0, ioport & 0xff);
+  bus_space_write_1(bst, bsh, DINGO_EBAR1, (ioport >> 8) & 0xff);
+
+  bus_space_write_1(bst, bsh, DINGO_DCOR0, DINGO_DCOR0_SF_INT);
+  bus_space_write_1(bst, bsh, DINGO_DCOR1, DINGO_DCOR1_INT_LEVEL |
+  					   DINGO_DCOR1_EEDIO);
+  bus_space_write_1(bst, bsh, DINGO_DCOR2, 0x00);
+  bus_space_write_1(bst, bsh, DINGO_DCOR3, 0x00);
+  bus_space_write_1(bst, bsh, DINGO_DCOR4, 0x00);
 
-  /* magic to set up the ethernet */
-  xe_memwrite( scp->dev, DINGO_ECOR, DINGO_ECOR_IRQ_LEVEL|
-               DINGO_ECOR_INT_ENABLE|DINGO_ECOR_IOB_ENABLE|
-               DINGO_ECOR_ETH_ENABLE );
-  xe_memwrite( scp->dev, DINGO_EBAR0, ioport & 0xff );
-  xe_memwrite( scp->dev, DINGO_EBAR1, (ioport >> 8) & 0xff );
-
-  xe_memwrite( scp->dev, DINGO_DCOR0, DINGO_DCOR0_SF_INT );
-  xe_memwrite( scp->dev, DINGO_DCOR1, DINGO_DCOR1_INT_LEVEL|DINGO_DCOR1_EEDIO );
-  xe_memwrite( scp->dev, DINGO_DCOR2, 0x00 );
-  xe_memwrite( scp->dev, DINGO_DCOR3, 0x00 );
-  xe_memwrite( scp->dev, DINGO_DCOR4, 0x00 );
+  bus_release_resource(dev, SYS_RES_MEMORY, rid, r);
 
-  /* success! */
   return 0;
-#else
-  return -1;
-#endif /* XXX */
 }
 	
 /*
@@ -532,7 +503,7 @@
   scp->autoneg_status = 0;
 
   /* Hack RealPorts into submission */
-  if (scp->dingo && xe_cem56fix(scp) < 0) {
+  if (scp->dingo && xe_cem56fix(dev) < 0) {
     device_printf(dev, "Unable to fix your RealPort\n");
     xe_deactivate(dev);
     return ENODEV;
@@ -2210,11 +2181,39 @@
 xe_activate(device_t dev)
 {
 	struct xe_softc *sc = device_get_softc(dev);
-	int err;
+	int start, err;
 
-	sc->port_rid = 0;
-	sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
-	    0, ~0, 16, RF_ACTIVE);
+	if (!sc->dingo) {
+		sc->port_rid = 0;	/* 0 is managed by pccard */
+		sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT,
+		    &sc->port_rid, 0, ~0, 16, RF_ACTIVE);
+	} else {
+		/*
+		 * Find a 16 byte aligned ioport for the card.
+		 */
+#if XE_DEBUG > 0
+		device_printf(dev, "Finding an aligned port for RealPort\n");
+#endif /* XE_DEBUG */
+		sc->port_rid = 1;	/* 0 is managed by pccard */
+		start = 0x100;
+		do {
+			sc->port_res = bus_alloc_resource(dev,
+			    SYS_RES_IOPORT, &sc->port_rid, start, 0x3ff, 16,
+			    RF_ACTIVE);
+			if (sc->port_res == 0)
+				break;		/* we failed */
+			if ((rman_get_start(sc->port_res) & 0xf) == 0)
+				break;		/* good */
+			bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid, 
+			    sc->port_res);
+			start = (rman_get_start(sc->port_res) + 15) & ~0xf;
+		} while (1);
+#if XE_DEBUG > 2
+		device_printf(dev, "port 0x%0lx, size 0x%0lx\n",
+		    bus_get_resource_start(dev, SYS_RES_IOPORT, sc->port_rid),
+		    bus_get_resource_count(dev, SYS_RES_IOPORT, sc->port_rid));
+#endif /* XE_DEBUG */
+	}
 	if (!sc->port_res) {
 #if XE_DEBUG > 0
 		device_printf(dev, "Cannot allocate ioport\n");

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: dougb 
Responsible-Changed-When: Mon May 28 17:13:58 PDT 2001 
Responsible-Changed-Why:  

If Warner doesn't know the answer, he'll know who does 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=18528 
State-Changed-From-To: open->closed 
State-Changed-By: imp 
State-Changed-When: Sun Sep 29 17:29:36 MDT 2002 
State-Changed-Why:  
This appears to have been committed some time ago. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=18528 
>Unformatted:
