From ga9@buffy.york.ac.uk  Thu Aug 28 20:07:05 2008
Return-Path: <ga9@buffy.york.ac.uk>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 304D6106567D
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Aug 2008 20:07:05 +0000 (UTC)
	(envelope-from ga9@buffy.york.ac.uk)
Received: from buffy.york.ac.uk (buffy.york.ac.uk [144.32.226.160])
	by mx1.freebsd.org (Postfix) with ESMTP id D056A8FC1B
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Aug 2008 20:07:04 +0000 (UTC)
	(envelope-from ga9@buffy.york.ac.uk)
Received: from buffy.york.ac.uk (localhost [127.0.0.1])
	by buffy.york.ac.uk (8.14.2/8.14.2) with ESMTP id m7SK73J1050147
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 28 Aug 2008 21:07:03 +0100 (BST)
	(envelope-from ga9@buffy.york.ac.uk)
Received: (from ga9@localhost)
	by buffy.york.ac.uk (8.14.2/8.14.2/Submit) id m7SK73HZ050146;
	Thu, 28 Aug 2008 21:07:03 +0100 (BST)
	(envelope-from ga9)
Message-Id: <200808282007.m7SK73HZ050146@buffy.york.ac.uk>
Date: Thu, 28 Aug 2008 21:07:03 +0100 (BST)
From: Gavin Atkinson <gavin@freebsd.org>
Reply-To: Gavin Atkinson <gavin@freebsd.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [an] [patch] printf -> device_printf and simplify probe
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         126924
>Category:       kern
>Synopsis:       [an] [patch] printf -> device_printf and simplify probe
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 28 20:10:01 UTC 2008
>Closed-Date:    Fri Nov 06 18:33:33 UTC 2009
>Last-Modified:  Fri Nov 06 18:33:33 UTC 2009
>Originator:     Gavin Atkinson
>Release:        FreeBSD 7.0-STABLE amd64
>Organization:
>Environment:
System: FreeBSD buffy.york.ac.uk 7.0-STABLE FreeBSD 7.0-STABLE #3: Fri Jun 20 09:21:51 UTC 2008 root@buffy.york.ac.uk:/usr/obj/usr/src/sys/GENERIC amd64

>Description:
	There's an bit of duplicated code in thhe probe routine of if_an_pci.c
which is presumably left over from a previous version of this driver, but which
can simply be rolled into the existing probe code now.
	While here, convert printf() to device_printf and add a couple of
extra messages to cover various failure modes.
	Net change to driver size is ~20 bytes.
>How-To-Repeat:
	N/A.  Changes tested with an MPI350.
>Fix:

--- an-device_printf.diff begins here ---
Index: src/sys/dev/an/if_an_pci.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/an/if_an_pci.c,v
retrieving revision 1.30
diff -u -r1.30 if_an_pci.c
--- src/sys/dev/an/if_an_pci.c	18 Jan 2008 16:34:18 -0000	1.30
+++ src/sys/dev/an/if_an_pci.c	28 Aug 2008 19:59:55 -0000
@@ -103,6 +103,7 @@
 
 static struct an_type an_devs[] = {
 	{ AIRONET_VENDORID, AIRONET_DEVICEID_35x, "Cisco Aironet 350 Series" },
+	{ AIRONET_VENDORID, AIRONET_DEVICEID_MPI350, "Cisco Aironet MPI350" },
 	{ AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" },
 	{ AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" },
 	{ AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" },
@@ -133,13 +134,6 @@
 		t++;
 	}
 
-	if (pci_get_vendor(dev) == AIRONET_VENDORID &&
-	    pci_get_device(dev) == AIRONET_DEVICEID_MPI350) {
-		device_set_desc(dev, "Cisco Aironet MPI350");
-		an_pci_probe(dev);
-		return(BUS_PROBE_DEFAULT);
-	}
-
 	return(ENXIO);
 }
 
@@ -169,7 +163,7 @@
 		command = pci_read_config(dev, PCIR_COMMAND, 4);
 
 		if (!(command & PCIM_CMD_PORTEN)) {
-			printf("an%d: failed to enable I/O ports!\n", unit);
+			device_printf(dev, "failed to enable I/O ports!\n");
 			error = ENXIO;
 			goto fail;
 		}
@@ -178,7 +172,7 @@
 	error = an_alloc_port(dev, sc->port_rid, 1);
 
 	if (error) {
-		printf("an%d: couldn't map ports\n", unit);
+		device_printf(dev, "couldn't map ports\n");
 		goto fail;
 	}
 
@@ -191,7 +185,7 @@
 		sc->mem_rid = PCIR_BAR(1);
 		error = an_alloc_memory(dev, sc->mem_rid, 1);
 		if (error) {
-			printf("an%d: couldn't map memory\n", unit);
+			device_printf(dev, "couldn't map memory\n");
 			goto fail;
 		}
 		sc->an_mem_btag = rman_get_bustag(sc->mem_res);
@@ -202,7 +196,7 @@
 		error = an_alloc_aux_memory(dev, sc->mem_aux_rid, 
 		    AN_AUX_MEM_SIZE);
 		if (error) {
-			printf("an%d: couldn't map aux memory\n", unit);
+			device_printf(dev, "couldn't map aux memory\n");
 			goto fail;
 		}
 		sc->an_mem_aux_btag = rman_get_bustag(sc->mem_aux_res);
@@ -222,7 +216,7 @@
 			       NULL,			/* lockarg */
 			       &sc->an_dtag);
 		if (error) {
-			printf("an%d: couldn't get DMA region\n", unit);
+			device_printf(dev, "couldn't get DMA region\n");
 			goto fail;
 		}
 	}
@@ -230,12 +224,14 @@
 	/* Allocate interrupt */
 	error = an_alloc_irq(dev, 0, RF_SHAREABLE);
 	if (error) {
+		device_printf(dev, "couldn't get interrupt\n");
 		goto fail;
 	}
 
 	sc->an_dev = dev;
 	error = an_attach(sc, device_get_unit(dev), flags);
 	if (error) {
+		device_printf(dev, "couldn't attach\n");
 		goto fail;
 	}
 
@@ -244,6 +240,8 @@
 	 */
 	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
 	    NULL, an_intr, sc, &sc->irq_handle);
+	if (error)
+		device_printf(dev, "couldn't setup interrupt\n");
 
 fail:
 	if (error)
--- an-device_printf.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: vwe 
Responsible-Changed-When: Sun Oct 5 19:04:54 UTC 2008 
Responsible-Changed-Why:  

Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=126924 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/126924: commit references a PR
Date: Fri,  6 Nov 2009 18:28:24 +0000 (UTC)

 Author: jhb
 Date: Fri Nov  6 18:28:13 2009
 New Revision: 198995
 URL: http://svn.freebsd.org/changeset/base/198995
 
 Log:
   - Use device_printf() instead of printf() with an explicit unit number
     in the PCI attach routine.
   - Simplify PCI probe.
   - Remove no-longer-used 'unit' from an_attach() parameters.
   
   PR:		kern/126924
   Submitted by:	gavin
 
 Modified:
   head/sys/dev/an/if_an.c
   head/sys/dev/an/if_an_isa.c
   head/sys/dev/an/if_an_pccard.c
   head/sys/dev/an/if_an_pci.c
   head/sys/dev/an/if_anreg.h
 
 Modified: head/sys/dev/an/if_an.c
 ==============================================================================
 --- head/sys/dev/an/if_an.c	Fri Nov  6 17:58:44 2009	(r198994)
 +++ head/sys/dev/an/if_an.c	Fri Nov  6 18:28:13 2009	(r198995)
 @@ -674,7 +674,7 @@ an_init_mpi350_desc(struct an_softc *sc)
  }
  
  int
 -an_attach(struct an_softc *sc, int unit, int flags)
 +an_attach(struct an_softc *sc, int flags)
  {
  	struct ifnet		*ifp;
  	int			error = EIO;
 
 Modified: head/sys/dev/an/if_an_isa.c
 ==============================================================================
 --- head/sys/dev/an/if_an_isa.c	Fri Nov  6 17:58:44 2009	(r198994)
 +++ head/sys/dev/an/if_an_isa.c	Fri Nov  6 18:28:13 2009	(r198995)
 @@ -115,7 +115,7 @@ an_attach_isa(device_t dev)
  	sc->an_btag = rman_get_bustag(sc->port_res);
  	sc->an_dev = dev;
  
 -	error = an_attach(sc, device_get_unit(dev), flags);
 +	error = an_attach(sc, flags);
  	if (error) {
  		an_release_resources(dev);
  		return (error);
 
 Modified: head/sys/dev/an/if_an_pccard.c
 ==============================================================================
 --- head/sys/dev/an/if_an_pccard.c	Fri Nov  6 17:58:44 2009	(r198994)
 +++ head/sys/dev/an/if_an_pccard.c	Fri Nov  6 18:28:13 2009	(r198995)
 @@ -145,7 +145,7 @@ an_pccard_attach(device_t dev)
  	sc->an_btag = rman_get_bustag(sc->port_res);
  	sc->an_dev = dev;
  
 -	error = an_attach(sc, device_get_unit(dev), flags);
 +	error = an_attach(sc, flags);
  	if (error)
  		goto fail;
  	
 
 Modified: head/sys/dev/an/if_an_pci.c
 ==============================================================================
 --- head/sys/dev/an/if_an_pci.c	Fri Nov  6 17:58:44 2009	(r198994)
 +++ head/sys/dev/an/if_an_pci.c	Fri Nov  6 18:28:13 2009	(r198995)
 @@ -103,6 +103,7 @@ struct an_type {
  
  static struct an_type an_devs[] = {
  	{ AIRONET_VENDORID, AIRONET_DEVICEID_35x, "Cisco Aironet 350 Series" },
 +	{ AIRONET_VENDORID, AIRONET_DEVICEID_MPI350, "Cisco Aironet MPI350" },
  	{ AIRONET_VENDORID, AIRONET_DEVICEID_4500, "Aironet PCI4500" },
  	{ AIRONET_VENDORID, AIRONET_DEVICEID_4800, "Aironet PCI4800" },
  	{ AIRONET_VENDORID, AIRONET_DEVICEID_4xxx, "Aironet PCI4500/PCI4800" },
 @@ -133,13 +134,6 @@ an_probe_pci(device_t dev)
  		t++;
  	}
  
 -	if (pci_get_vendor(dev) == AIRONET_VENDORID &&
 -	    pci_get_device(dev) == AIRONET_DEVICEID_MPI350) {
 -		device_set_desc(dev, "Cisco Aironet MPI350");
 -		an_pci_probe(dev);
 -		return(BUS_PROBE_DEFAULT);
 -	}
 -
  	return(ENXIO);
  }
  
 @@ -149,10 +143,9 @@ an_attach_pci(dev)
  {
  	u_int32_t		command;
  	struct an_softc		*sc;
 -	int 			unit, flags, error = 0;
 +	int 			flags, error = 0;
  
  	sc = device_get_softc(dev);
 -	unit = device_get_unit(dev);
  	flags = device_get_flags(dev);
  
  	if (pci_get_vendor(dev) == AIRONET_VENDORID &&
 @@ -169,7 +162,7 @@ an_attach_pci(dev)
  		command = pci_read_config(dev, PCIR_COMMAND, 4);
  
  		if (!(command & PCIM_CMD_PORTEN)) {
 -			printf("an%d: failed to enable I/O ports!\n", unit);
 +			device_printf(dev, "failed to enable I/O ports!\n");
  			error = ENXIO;
  			goto fail;
  		}
 @@ -178,7 +171,7 @@ an_attach_pci(dev)
  	error = an_alloc_port(dev, sc->port_rid, 1);
  
  	if (error) {
 -		printf("an%d: couldn't map ports\n", unit);
 +		device_printf(dev, "couldn't map ports\n");
  		goto fail;
  	}
  
 @@ -191,7 +184,7 @@ an_attach_pci(dev)
  		sc->mem_rid = PCIR_BAR(1);
  		error = an_alloc_memory(dev, sc->mem_rid, 1);
  		if (error) {
 -			printf("an%d: couldn't map memory\n", unit);
 +			device_printf(dev, "couldn't map memory\n");
  			goto fail;
  		}
  		sc->an_mem_btag = rman_get_bustag(sc->mem_res);
 @@ -202,7 +195,7 @@ an_attach_pci(dev)
  		error = an_alloc_aux_memory(dev, sc->mem_aux_rid, 
  		    AN_AUX_MEM_SIZE);
  		if (error) {
 -			printf("an%d: couldn't map aux memory\n", unit);
 +			device_printf(dev, "couldn't map aux memory\n");
  			goto fail;
  		}
  		sc->an_mem_aux_btag = rman_get_bustag(sc->mem_aux_res);
 @@ -222,7 +215,7 @@ an_attach_pci(dev)
  			       NULL,			/* lockarg */
  			       &sc->an_dtag);
  		if (error) {
 -			printf("an%d: couldn't get DMA region\n", unit);
 +			device_printf(dev, "couldn't get DMA region\n");
  			goto fail;
  		}
  	}
 @@ -230,12 +223,14 @@ an_attach_pci(dev)
  	/* Allocate interrupt */
  	error = an_alloc_irq(dev, 0, RF_SHAREABLE);
  	if (error) {
 +		device_printf(dev, "couldn't get interrupt\n");
  		goto fail;
  	}
  
  	sc->an_dev = dev;
 -	error = an_attach(sc, device_get_unit(dev), flags);
 +	error = an_attach(sc, flags);
  	if (error) {
 +		device_printf(dev, "couldn't attach\n");
  		goto fail;
  	}
  
 @@ -244,6 +239,8 @@ an_attach_pci(dev)
  	 */
  	error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_NET,
  	    NULL, an_intr, sc, &sc->irq_handle);
 +	if (error)
 +		device_printf(dev, "couldn't setup interrupt\n");
  
  fail:
  	if (error)
 
 Modified: head/sys/dev/an/if_anreg.h
 ==============================================================================
 --- head/sys/dev/an/if_anreg.h	Fri Nov  6 17:58:44 2009	(r198994)
 +++ head/sys/dev/an/if_anreg.h	Fri Nov  6 18:28:13 2009	(r198995)
 @@ -511,7 +511,7 @@ int	an_pci_probe	(device_t);
  int	an_probe	(device_t);
  int	an_shutdown	(device_t);
  void	an_resume	(device_t);
 -int	an_attach		(struct an_softc *, int, int);
 +int	an_attach		(struct an_softc *, int);
  int	an_detach	(device_t);
  void    an_stop		(struct an_softc *);
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->closed 
State-Changed-By: jhb 
State-Changed-When: Fri Nov 6 18:32:46 UTC 2009 
State-Changed-Why:  
Patch applied to HEAD. 

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