Subject: Re: CVS commit: src/sys/dev/pcmcia
To: None <briggs@NetBSD.org>
From: enami tsugutomo <enami@sm.sony.co.jp>
List: source-changes
Date: 10/22/2003 20:09:54
Allen Briggs <briggs@NetBSD.org> writes:

> Module Name:	src
> Committed By:	briggs
> Date:		Wed Oct 22 07:48:25 UTC 2003
> 
> Modified Files:
> 	src/sys/dev/pcmcia: wdc_pcmcia.c
> 
> Log Message:
> Since we enable the pcmcia function on attach, disable it on the detach.

No.  Your change is wrong.  The reason why enable/disable become
unbalance is because now real wd probe/attach jobs is done via atabus
kernel thread and wdcattach itself returns after creating the kernel
thread.  So, the correct fix is to disable the device when exiting
wdc_pcmcia_attach().

enami.

Index: wdc_pcmcia.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pcmcia/wdc_pcmcia.c,v
retrieving revision 1.61
diff -c -r1.61 wdc_pcmcia.c
*** wdc_pcmcia.c	22 Oct 2003 07:48:25 -0000	1.61
--- wdc_pcmcia.c	22 Oct 2003 08:27:08 -0000
***************
*** 74,80 ****
  	void *sc_ih;
  	struct pcmcia_function *sc_pf;
  	int sc_flags;
- #define	WDC_PCMCIA_ATTACH	0x0001
  #define WDC_PCMCIA_MEMMODE	0x0002
  };
  
--- 74,79 ----
***************
*** 376,384 ****
  	sc->sc_wdcdev.sc_atapi_adapter._generic.adapt_enable =
  	    wdc_pcmcia_enable;
  
- 	sc->sc_flags |= WDC_PCMCIA_ATTACH;
  	wdcattach(&sc->wdc_channel);
! 	sc->sc_flags &= ~WDC_PCMCIA_ATTACH;
  	return;
  
   mapaux_failed:
--- 375,385 ----
  	sc->sc_wdcdev.sc_atapi_adapter._generic.adapt_enable =
  	    wdc_pcmcia_enable;
  
  	wdcattach(&sc->wdc_channel);
! 
! 	/* Disable the function */
! 	pcmcia_function_disable(sc->sc_pf);
! 
  	return;
  
   mapaux_failed:
***************
*** 433,441 ****
  		}
  	}
  
- 	/* Disable the function */
- 	pcmcia_function_disable(sc->sc_pf);
- 
  	return (0);
  }
  
--- 434,439 ----
***************
*** 456,472 ****
  			return (EIO);
  		}
  
! 		/*
! 		 * If attach is in progress, we know that card power is
! 		 * enabled.
! 		 */
! 		if ((sc->sc_flags & WDC_PCMCIA_ATTACH) == 0) {
! 			if (pcmcia_function_enable(sc->sc_pf)) {
! 				printf("%s: couldn't enable PCMCIA function\n",
! 				    sc->sc_wdcdev.sc_dev.dv_xname);
! 				pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
! 				return (EIO);
! 			}
  		}
  	} else {
  		pcmcia_function_disable(sc->sc_pf);
--- 454,464 ----
  			return (EIO);
  		}
  
! 		if (pcmcia_function_enable(sc->sc_pf)) {
! 			printf("%s: couldn't enable PCMCIA function\n",
! 			    sc->sc_wdcdev.sc_dev.dv_xname);
! 			pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
! 			return (EIO);
  		}
  	} else {
  		pcmcia_function_disable(sc->sc_pf);