From nobody@FreeBSD.org  Wed Nov  5 12:22:43 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id F27FD106564A
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  5 Nov 2008 12:22:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id E14F38FC13
	for <freebsd-gnats-submit@FreeBSD.org>; Wed,  5 Nov 2008 12:22:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id mA5CMgdx068202
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 5 Nov 2008 12:22:42 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id mA5CMgr4068200;
	Wed, 5 Nov 2008 12:22:42 GMT
	(envelope-from nobody)
Message-Id: <200811051222.mA5CMgr4068200@www.freebsd.org>
Date: Wed, 5 Nov 2008 12:22:42 GMT
From: Nick Hibma <nick@anywi.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] add support for powering down and up Cardbus cards
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         128608
>Category:       kern
>Synopsis:       [pccbb] [patch] add support for powering down and up Cardbus cards
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    imp
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Nov 05 12:30:05 UTC 2008
>Closed-Date:    
>Last-Modified:  Fri Mar 12 06:30:39 UTC 2010
>Originator:     Nick Hibma
>Release:        FSBD-7-STABLE
>Organization:
AnyWi Technologies
>Environment:
FreeBSD hind.van-laarhoven.org 7.0-STABLE FreeBSD 7.0-STABLE #3: Thu Aug 14 21:10:55 CEST 2008     toor@hind.van-laarhoven.org:/usr/src/sys/i386/compile/HIND  i386

>Description:
The supplied patch allows powering down and up cardbus slots through a sysctl.

Warner has been sent this patch for review as I do not know whether a sysctl is the right way.

With his permission I would be happy to commit this patch into current, followed by MFC to 7 and then 6.

Possible problems:

- need to check whether detachment is done properly (it does IMHO).
- usability: what about having switched off the power and then inserting a card, and ... surprise, surprise... the card does not work. Can this be detected and power automatically switched on? Haven't tried whether this is a problem at all.
>How-To-Repeat:
% sysctl dev.cbb.0.powered
dev.cbb.0.powered: 1
% sudo sysctl dev.cbb.0.powered=0
dev.cbb.0.powered: 1 -> 0
% sysctl dev.cbb.0.powered
dev.cbb.0.powered: 0
% sudo sysctl dev.cbb.0.powered=1
dev.cbb.0.powered: 0 -> 1

>Fix:
See attached diff.

Patch attached with submission follows:

Index: pccbb.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/pccbb/pccbb.c,v
retrieving revision 1.165
diff -u -r1.165 pccbb.c
--- pccbb.c	30 Sep 2007 11:05:15 -0000	1.165
+++ pccbb.c	11 Aug 2008 12:49:34 -0000
@@ -479,7 +479,7 @@
 		mtx_lock(&Giant);
 		status = cbb_get(sc, CBB_SOCKET_STATE);
 		DPRINTF(("Status is 0x%x\n", status));
-		if (!CBB_CARD_PRESENT(status)) {
+		if (!CBB_CARD_PRESENT(status) || !sc->powered) {
 			not_a_card = 0;		/* We know card type */
 			cbb_removal(sc);
 		} else if (status & CBB_STATE_NOT_A_CARD) {
@@ -1557,3 +1557,24 @@
 	sockstate = cbb_get(sc, CBB_SOCKET_STATE);
 	return (CBB_CARD_PRESENT(sockstate) && sc->cardok);
 }
+
+int
+cbb_powered_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	int error, powered;
+	struct cbb_softc *sc = (struct cbb_softc *)arg1;
+
+	powered = sc->powered;
+        error = sysctl_handle_int(oidp, &powered, 0, req);
+        if (error || !req->newptr) 
+                return error;
+
+	if (powered != sc->powered) {
+	    sc->powered = powered;
+	    cv_signal(&sc->cv);
+	}
+
+	return error;
+}
+
+
Index: pccbb_pci.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/pccbb/pccbb_pci.c,v
retrieving revision 1.26
diff -u -r1.26 pccbb_pci.c
--- pccbb_pci.c	30 Sep 2007 11:05:15 -0000	1.26
+++ pccbb_pci.c	11 Aug 2008 12:50:33 -0000
@@ -365,6 +365,9 @@
 	SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "io2",
 	    CTLFLAG_RD, &sc->subbus, 0, "io range 2 open");
 #endif
+	SYSCTL_ADD_PROC(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "powered",
+	    CTLTYPE_INT|CTLFLAG_RW, (void *)sc, 0, cbb_powered_sysctl, "I", "Slots powered");
+	sc->powered = 1;
 
 	/*
 	 * This is a gross hack.  We should be scanning the entire pci
Index: pccbbvar.h
===================================================================
RCS file: /home/ncvs/src/sys/dev/pccbb/pccbbvar.h,v
retrieving revision 1.32
diff -u -r1.32 pccbbvar.h
--- pccbbvar.h	30 Sep 2007 11:05:15 -0000	1.32
+++ pccbbvar.h	11 Aug 2008 12:50:07 -0000
@@ -90,6 +90,8 @@
 	struct proc	*event_thread;
 	void (*chipinit)(struct cbb_softc *);
 	volatile int	powerintr;
+
+	int	powered;
 };
 
 /* result of detect_card */
@@ -145,6 +147,7 @@
 	    void *cookie);
 int	cbb_write_ivar(device_t brdev, device_t child, int which,
 	    uintptr_t value);
+int	cbb_powered_sysctl(SYSCTL_HANDLER_ARGS);
 
 /*
  */


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->imp 
Responsible-Changed-By: brooks 
Responsible-Changed-When: Fri Mar 12 06:29:07 UTC 2010 
Responsible-Changed-Why:  
Warner maintains cardbus. 

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