Subject: Re: wi0: device timeout
To: None <kanaoka@ann.hi-ho.ne.jp>
From: Brook Milligan <brook@biology.nmsu.edu>
List: current-users
Date: 10/22/2001 21:28:38
   $ I regularly get the following message when trying to use my
   $ Lucent/Orinoco wireless card:
   $ 
   $ 	       wi0: device timeout
   $ 
   $ The kernel recognizes the device fine (PCI->CardBus->PCMCIA->wi0) and
   $ both ifconfig and wiconfig seem to configure it fine.  Only when
   $ trying to actually use the card does it timeout.  The card works fine
   $ in another machine (ISA->PCMCIA->wi0).
   $ 
   $ This happens with both 1.5 and 1.5.2 kernels.

   I think of change of sys/dev/pci/pccbb.c in -current.
   It does not pull-up to 1.5 branch yet.

   <URL:http://cvsweb.netbsd.org/cgi-bin/cvsweb.cgi/syssrc/sys/dev/pci/pccbb.c.di
   ff?cvsroot=cvs.netbsd.org&r1=1.56&r2=1.57&f=u>

   How about trying with a patch for pccbb.

OK.  I tried this patch (see below for exact one) on the following
version of pccbb.c (from 1.5.2):

	/* $NetBSD: pccbb.c,v 1.42.2.4 2001/05/01 12:54:28 he Exp $	*/

I also tried an equivalent patch against 1.42.2.2 (from 1.5).  Neither
fixed the wi0: device timeout error.

An edited version of dmesg output (with RBUS_DEBUG and CBB_DEBUG
defined) is appended below in the hopes that someone will have further
suggestions.  I have included all the kernel probe output associated
with the pci->cardbus->pcmcia->wi devices + the error message at the
end when filesystems are being mounted.

Do these drivers work reliably in -current?

Thanks for your help.

Cheers,
Brook

===========================================================================
--- pccbb.c.orig	Mon Oct 22 20:36:34 2001
+++ pccbb.c	Mon Oct 22 20:39:42 2001
@@ -1897,6 +1897,8 @@
 	int flags = 0;
 	bus_space_tag_t iot;
 	bus_space_handle_t ioh;
+	bus_addr_t mask;
+
 #if rbus
 	rbus_tag_t rb;
 #endif
@@ -1910,10 +1912,38 @@
 
 	iot = ((struct pccbb_softc *)(ph->ph_parent))->sc_iot;
 
+	if (start != 0) {
+		/* XXX: assume all card decode lower 10 bits by its hardware */
+		mask = 0x3ff;
+		DPRINTF(("pccbb_pcmcia_io_alloc start=0x%lx; mask=0x%lx\n", start, mask)); /* XXX */
+	} else {
+		/*
+		 * calculate mask:
+		 *  1. get the most significant bit of size (call it msb).
+		 *  2. compare msb with the value of size.
+		 *  3. if size is larger, shift msb left once.
+		 *  4. obtain mask value to decrement msb.
+		 */
+		bus_size_t size_tmp = size;
+		int shifts = 0;
+
+		mask = 1;
+		while (size_tmp) {
+			++shifts;
+			size_tmp >>= 1;
+		}
+		mask = (1 << shifts);
+		if (mask < size) {
+			mask <<= 1;
+		}
+		--mask;
+		DPRINTF(("pccbb_pcmcia_io_alloc start=0x%lx; size=0x%lx; mask=0x%lx\n", start, size, mask)); /* XXX */
+	}
+
 #if rbus
 	rb = ((struct pccbb_softc *)(ph->ph_parent))->sc_rbus_iot;
 	/* XXX: I assume all card decode lower 10 bits by its hardware */
-	if (rbus_space_alloc(rb, start, size, 0x3ff, align, 0, &ioaddr, &ioh)) {
+	if (rbus_space_alloc(rb, start, size, mask, align, 0, &ioaddr, &ioh)) {
 		return 1;
 	}
 #else
===========================================================================
mainbus0 (root)
pci0 at mainbus0 bus 0: configuration mode 1
pci0: i/o space, memory space enabled
cbb0 at pci0 dev 11 function 0: Texas Instruments product 0xac50 (rev. 0x01) (chipflags 2)
cbb0: intrpin A, intrtag 10
cbb0: CardBus resister address 0x40000000 -> 0x40000000
CardBus latency timer 0x20 (20000000)
PCI latency timer 0x20 (22008)
pccbb_power: CARDBUS_VCC_0V and CARDBUS_VPP_0V [44]
cbb0: interrupting at irq 10
cbb0: cacheline 0x8 lattimer 0x20
cbb0: bhlc 0x22008 lscp 0x20000000
cardslot0 at cbb0 slot 0 flags 0
cardbus0 at cardslot0: bus 0 device 0 cacheline 0x8, lattimer 0x20
pcmcia0 at cardslot0
pccbb_pcmcia_card_detect
pccbbattach: found cardslot
pccbb_pcmcia_socket_enable: 5V card
pccbb_power: CARDBUS_VCC_0V and CARDBUS_VPP_0V [44]
pccbb_power: CARDBUS_VCC_5V and CARDBUS_VPP_VCC [15]
pccbb_pcmcia_wait_ready: status 0x6f
cbb0: pccbb_pcmcia_socket_enable 00 cardtype mem 50
pccbb_pcmcia_alloc_mem: addr 0x40001000 size 0x400, realsize 0x1000
pccbb_pcmcia_mem_map window 0 bus 40001000+0+400 at card addr 0
pccbb_pcmcia_do_mem_map: start 0x40001000 end 0x400013ff off 0xbffff000
pccbb_pcmcia_do_mem_map window 0: 0100 0180 ff7f 40
pccbb_pcmcia_mem_map window 0 bus 40001000+0+400 at card addr 0
pccbb_pcmcia_do_mem_map: start 0x40001000 end 0x400013ff off 0xbffff000
pccbb_pcmcia_do_mem_map window 0: 0100 0180 ff3f 40
pccbb_pcmcia_socket_disable
pccbb_power: CARDBUS_VCC_0V and CARDBUS_VPP_0V [44]
wi0 at pcmcia0 function 0pccbb_pcmcia_socket_enable: 5V card
pccbb_power: CARDBUS_VCC_0V and CARDBUS_VPP_0V [44]
pccbb_power: CARDBUS_VCC_5V and CARDBUS_VPP_VCC [15]
pccbb_pcmcia_wait_ready: status 0x6f
cbb0: pccbb_pcmcia_socket_enable 00 cardtype io 70
pccbb_pcmcia_alloc_mem: addr 0x40001000 size 0x14, realsize 0x1000
pccbb_pcmcia_mem_map window 0 bus 40001000+3e0+14 at card addr 0
pccbb_pcmcia_do_mem_map: start 0x40001000 end 0x400013f3 off 0xbffff000
pccbb_pcmcia_do_mem_map window 0: 0100 0180 ff7f 40
pccbb_pcmcia_io_alloc start=0x0; size=0x40; mask=0x7f
pccbb_pcmcia_io_map window 0 io16 port 2000+40
pccbb_pcmcia_do_io_map win 0 addr 0x2000 size 0x40 width 16
 start 00 20, stop 3f 20, ioctl 01 enable 41

wi0: address 00:02:2d:04:dd:07
pccbb_pcmcia_socket_disable
pccbb_power: CARDBUS_VCC_0V and CARDBUS_VPP_0V [44]
pccbb_intr_establish start. 0x0
pccbb_intr_establish add pil. 0xc0810a60
pccbb_pcmcia_socket_enable: 5V card
pccbb_power: CARDBUS_VCC_0V and CARDBUS_VPP_0V [44]
pccbb_power: CARDBUS_VCC_5V and CARDBUS_VPP_VCC [15]
pccbb_pcmcia_wait_ready: status 0x6f
cbb0: pccbb_pcmcia_socket_enable 00 cardtype io 70
pccbb_pcmcia_do_io_map win 0 addr 0x2000 size 0x40 width 16
 start 00 20, stop 3f 20, ioctl 01 enable 40
pccbb_pcmcia_alloc_mem: addr 0x40001000 size 0x14, realsize 0x1000
pccbb_pcmcia_mem_map window 0 bus 40001000+3e0+14 at card addr 0
pccbb_pcmcia_do_mem_map: start 0x40001000 end 0x400013f3 off 0xbffff000
pccbb_pcmcia_do_mem_map window 0: 0100 0180 ff7f 40
wi0: device timeout