Subject: Apple Ethernet Twisted-Pair NB (Re: IIsi Ethernet)
To: None <dair@dircon.co.uk>
From: Ken Nakata <kenn@synap.ne.jp>
List: port-mac68k
Date: 11/02/1998 23:29:27
----Next_Part(Mon_Nov__2_23:28:14_1998_595)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Ok,

Here's the patch.  Apply the attached diffs to your 1.3.2 source,
configure and build a kernel, and try the kernel.  I'm fairly
confident it'll recognize your card and find the hardware address
correctly.

But you have to understand, this is a snapshot of my sn driver
enhancement effort as of the time I had lost physical access to the
Apple Ethernet Twisted Pair NB and the IIci.  I *think* I only got it
half-working because of my (rather stupid) misconfiguration of the
interface rather than of the half-finished driver, but I can't be
sure.  If it doesn't work, I'm sorry but I can't help you anymore.

Anyway, good luck,

Ken

----Next_Part(Mon_Nov__2_23:28:14_1998_595)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

*** dev.orig/if_sn.c	Tue May  5 15:48:14 1998
--- dev/if_sn.c	Wed Dec 24 21:35:50 1997
***************
*** 131,137 ****
  	 * for its descriptor areas, or expect the MD attach code
  	 * to do that?
  	 */
! 	sc->space = malloc((SN_NPAGES + 1) * NBPG, M_DEVBUF, M_WAITOK);
  	if (sc->space == NULL) {
  		printf ("%s: memory allocation for descriptors failed\n",
  		    sc->sc_dev.dv_xname);
--- 131,138 ----
  	 * for its descriptor areas, or expect the MD attach code
  	 * to do that?
  	 */
! 	if (sc->space == NULL)
! 		sc->space = malloc((SN_NPAGES + 1) * NBPG, M_DEVBUF, M_WAITOK);
  	if (sc->space == NULL) {
  		printf ("%s: memory allocation for descriptors failed\n",
  		    sc->sc_dev.dv_xname);
***************
*** 213,218 ****
--- 214,223 ----
  	sc->sc_nrda = NBPG / RXPKT_SIZE(sc);
  	sc->p_rda = (caddr_t) p;
  	sc->v_rda = SONIC_GETDMA(p);
+ #if SN_DEBUG
+ 	printf("%s: p_rda = %08x, v_rda = %08x\n", sc->sc_dev.dv_xname, (unsigned)sc->p_rda,
+ 		(unsigned)sc->v_rda);
+ #endif
  
  	p = pp + NBPG;
  
***************
*** 1205,1215 ****
  #define bbr(v)	((bbr4[(v)&0xf] << 4) | bbr4[((v)>>4) & 0xf])
  
  void
! sn_get_enaddr(t, h, o, dst)
  	bus_space_tag_t	t;
  	bus_space_handle_t h;
  	vm_offset_t o;
  	u_char *dst;
  {
  	int	i, do_bbr;
  	u_char	b;
--- 1210,1221 ----
  #define bbr(v)	((bbr4[(v)&0xf] << 4) | bbr4[((v)>>4) & 0xf])
  
  void
! sn_get_enaddr(t, h, o, dst, incr)
  	bus_space_tag_t	t;
  	bus_space_handle_t h;
  	vm_offset_t o;
  	u_char *dst;
+ 	int incr;
  {
  	int	i, do_bbr;
  	u_char	b;
***************
*** 1251,1257 ****
  	dst[0] = (do_bbr) ? bbr(b) : b;
  
  	for (i = 1 ; i < ETHER_ADDR_LEN ; i++) {
! 		b = bus_space_read_1(t, h, o+i);
  		dst[i] = (do_bbr) ? bbr(b) : b;
  	}
  }
--- 1257,1263 ----
  	dst[0] = (do_bbr) ? bbr(b) : b;
  
  	for (i = 1 ; i < ETHER_ADDR_LEN ; i++) {
! 		b = bus_space_read_1(t, h, o+(i*incr));
  		dst[i] = (do_bbr) ? bbr(b) : b;
  	}
  }
*** dev.orig/if_sn_nubus.c	Tue May  5 15:48:15 1998
--- dev/if_sn_nubus.c	Wed Dec 24 00:35:54 1997
***************
*** 41,46 ****
--- 41,47 ----
  #include <net/if.h>
  #include <net/if_ether.h>
  
+ 
  #if 0 /* XXX this shouldn't be necessary; else reinsert */
  #ifdef INET
  #include <netinet/in.h>
***************
*** 55,60 ****
--- 56,63 ----
  #include <mac68k/dev/if_snreg.h>
  #include <mac68k/dev/if_snvar.h>
  
+ #include <machine/pte.h>
+ 
  static int	sn_nubus_match __P((struct device *, struct cfdata *, void *));
  static void	sn_nubus_attach __P((struct device *, struct device *, void *));
  static int	sn_nb_card_vendor __P((bus_space_tag_t, bus_space_handle_t,
***************
*** 88,95 ****
  			break;
  
  		case SN_VENDOR_APPLE:
- 		case SN_VENDOR_APPLE16:
  		case SN_VENDOR_DAYNA:
  			rv = 1;
  			break;
  		}
--- 91,99 ----
  			break;
  
  		case SN_VENDOR_APPLE:
  		case SN_VENDOR_DAYNA:
+ 		case SN_VENDOR_APPLE16:
+ 		case SN_VENDOR_APPLE16NB:
  			rv = 1;
  			break;
  		}
***************
*** 110,116 ****
  {
  	struct sn_softc *sc = (void *)self;
  	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
! 	int i, success, offset;
  	bus_space_tag_t	bst;
  	bus_space_handle_t bsh, tmp_bsh;
  	u_int8_t myaddr[ETHER_ADDR_LEN];
--- 114,120 ----
  {
  	struct sn_softc *sc = (void *)self;
  	struct nubus_attach_args *na = (struct nubus_attach_args *)aux;
! 	int i, success, offset, distance;
  	bus_space_tag_t	bst;
  	bus_space_handle_t bsh, tmp_bsh;
  	u_int8_t myaddr[ETHER_ADDR_LEN];
***************
*** 129,134 ****
--- 133,141 ----
  
  	sc->slotno = na->slot;
  
+ 	distance = 4;
+ 	sc->space = NULL;
+ 
  	switch (sn_nb_card_vendor(bst, bsh, na)) {
  	case SN_VENDOR_DAYNA:
  		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
***************
*** 148,154 ****
  			break;
  		}
  
! 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
  
  		offset = 2;
  		success = 1;
--- 155,161 ----
  			break;
  		}
  
! 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr, 1);
  
  		offset = 2;
  		success = 1;
***************
*** 172,178 ****
  			break;
  		}
  
! 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
  
  		offset = 0;
  		success = 1;
--- 179,185 ----
  			break;
  		}
  
! 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr, 1);
  
  		offset = 0;
  		success = 1;
***************
*** 196,204 ****
  			break;
  		}
  
! 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr);
  
  		offset = 0;
  		success = 1;
  		break;
  
--- 203,256 ----
  			break;
  		}
  
! 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr, 1);
! 
! 		offset = 0;
! 		success = 1;
! 		break;
! 
! 	case SN_VENDOR_APPLE16NB:
! 		sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 |
! 		    DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT24;
! 		sc->snr_dcr2 = 0;
! 		sc->bitmode = 0; /* 16 bit card */
! 
! 		if (bus_space_subregion(bst, bsh,
! 		    0xc0000, SN_REGSIZE, &sc->sc_regh)) {
! 			printf(": failed to map register space.\n");
! 			break;
! 		}
! 
! 		if (bus_space_subregion(bst, bsh,
! 		    0x400001, ETHER_ADDR_LEN * 2, &tmp_bsh)) {
! 			printf(": failed to map ROM space.\n");
! 			break;
! 		}
! 
! 		sn_get_enaddr(bst, tmp_bsh, 0, myaddr, 2);
  
+ #define ENNBTP 1
+ #if ENNBTP==0
+ 		physaccess((caddr_t)NUBUS_SLOT2PA(na->slot),
+ 			(caddr_t)NUBUS_SLOT2PA(na->slot),
+ 			(SN_NPAGES + 1) * NBPG, PG_V|PG_RW|PG_CI);
+ 		sc->space = (void*)NUBUS_SLOT2PA(na->slot);
+ #elif ENNBTP==1
+ 		if (bus_space_subregion(bst, bsh,
+ 		    0, (SN_NPAGES + 1) * NBPG, &tmp_bsh)) {
+ 			printf(": failed to map buffer RAM space.\n");
+ 			break;
+ 		}
+ 		/* XXX: isn't there a better way to convert a bus handle to a pointer? */
+ 		sc->space = (void *)tmp_bsh;
+ #else
+ 		sc->space = (void*)NUBUS_SLOT2PA(na->slot);
+ #endif
+ #if SN_DEBUG
+ 		printf(": mapping adapter memory at %08x\n", (unsigned)sc->space); 
+ #endif  
  		offset = 0;
+ 		distance = 2;
  		success = 1;
  		break;
  
***************
*** 223,229 ****
  
  	/* Regs are addressed as words, big endian. */
  	for (i = 0; i < SN_NREGS; i++) {
! 		sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset);
  	}
  
  	/* snsetup returns 1 if something fails */
--- 275,281 ----
  
  	/* Regs are addressed as words, big endian. */
  	for (i = 0; i < SN_NREGS; i++) {
! 		sc->sc_reg_map[i] = (bus_size_t)((i * distance) + offset);
  	}
  
  	/* snsetup returns 1 if something fails */
***************
*** 248,254 ****
  	switch (na->drsw) {
  	case NUBUS_DRSW_3COM:
  		if (na->drhw == NUBUS_DRHW_APPLE_SNT)
! 			vendor = SN_VENDOR_APPLE;
  		else if (na->drhw == NUBUS_DRHW_APPLE_SN)
  			vendor = SN_VENDOR_APPLE16;
  		break;
--- 300,306 ----
  	switch (na->drsw) {
  	case NUBUS_DRSW_3COM:
  		if (na->drhw == NUBUS_DRHW_APPLE_SNT)
! 			vendor = SN_VENDOR_APPLE16NB;
  		else if (na->drhw == NUBUS_DRHW_APPLE_SN)
  			vendor = SN_VENDOR_APPLE16;
  		break;
*** dev.orig/if_sn_obio.c	Tue May  5 15:48:15 1998
--- dev/if_sn_obio.c	Fri Dec 19 22:36:23 1997
***************
*** 203,209 ****
  		return (-1);
  	}
  
! 	sn_get_enaddr(sc->sc_regt, bsh, 0, lladdr);
  
  	bus_space_unmap(sc->sc_regt, bsh, NBPG);
  
--- 203,209 ----
  		return (-1);
  	}
  
! 	sn_get_enaddr(sc->sc_regt, bsh, 0, lladdr, 1);
  
  	bus_space_unmap(sc->sc_regt, bsh, NBPG);
  
*** dev.orig/if_snvar.h	Tue May  5 15:48:15 1998
--- dev/if_snvar.h	Fri Dec 19 22:36:45 1997
***************
*** 16,22 ****
  #define	SN_VENDOR_UNKNOWN	0xff	/* Unknown */
  #define	SN_VENDOR_APPLE		0x00	/* Apple Computer/compatible */
  #define	SN_VENDOR_DAYNA		0x01	/* Dayna/Kinetics EtherPort */
! #define	SN_VENDOR_APPLE16	0x02	/* Apple Twisted Pair NB */
  
  /*
   * Memory access macros. Since we handle SONIC in 16 bit mode (PB5X0)
--- 16,23 ----
  #define	SN_VENDOR_UNKNOWN	0xff	/* Unknown */
  #define	SN_VENDOR_APPLE		0x00	/* Apple Computer/compatible */
  #define	SN_VENDOR_DAYNA		0x01	/* Dayna/Kinetics EtherPort */
! #define	SN_VENDOR_APPLE16	0x02	/* Apple Twisted Pair LC */
! #define	SN_VENDOR_APPLE16NB	0x03	/* Apple Twisted Pair NB */
  
  /*
   * Memory access macros. Since we handle SONIC in 16 bit mode (PB5X0)
***************
*** 215,218 ****
  int	snsetup __P((struct sn_softc *sc, u_int8_t *));
  void	snintr __P((void *, int));
  void	sn_get_enaddr __P((bus_space_tag_t t, bus_space_handle_t h,
! 	    vm_offset_t o, u_char *dst));
--- 216,219 ----
  int	snsetup __P((struct sn_softc *sc, u_int8_t *));
  void	snintr __P((void *, int));
  void	sn_get_enaddr __P((bus_space_tag_t t, bus_space_handle_t h,
! 	    vm_offset_t o, u_char *dst, int incr));

----Next_Part(Mon_Nov__2_23:28:14_1998_595)----