Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Mar 2013 19:12:38 +0000 (UTC)
From:      Marius Strobl <marius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r247565 - head/sys/dev/bce
Message-ID:  <201303011912.r21JCdRw056476@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marius
Date: Fri Mar  1 19:12:38 2013
New Revision: 247565
URL: http://svnweb.freebsd.org/changeset/base/247565

Log:
  - Make tables, device ID strings etc const.
  - Use NULL instead of 0 for pointers.
  - Remove redundant bzero(9)'ing of the softc.
  - Remove redundant/unused softc members.
  - Don't allocate MSI/MSI-X as RF_SHAREABLE.
  - Re-use bus accessor macros instead of duplicating them.
  - In bce_miibus_{read,write}_reg(), remove superfluous limiting of the PHY
    address (missed in r213893).
  
  MFC after:	1 week

Modified:
  head/sys/dev/bce/if_bce.c
  head/sys/dev/bce/if_bcereg.h

Modified: head/sys/dev/bce/if_bce.c
==============================================================================
--- head/sys/dev/bce/if_bce.c	Fri Mar  1 19:02:41 2013	(r247564)
+++ head/sys/dev/bce/if_bce.c	Fri Mar  1 19:12:38 2013	(r247565)
@@ -95,7 +95,7 @@ __FBSDID("$FreeBSD$");
 /****************************************************************************/
 #define BCE_DEVDESC_MAX		64
 
-static struct bce_type bce_devs[] = {
+static const struct bce_type bce_devs[] = {
 	/* BCM5706C Controllers and OEM boards. */
 	{ BRCM_VENDORID, BRCM_DEVICEID_BCM5706,  HP_VENDORID, 0x3101,
 		"HP NC370T Multifunction Gigabit Server Adapter" },
@@ -161,7 +161,7 @@ static struct bce_type bce_devs[] = {
 /****************************************************************************/
 /* Supported Flash NVRAM device data.                                       */
 /****************************************************************************/
-static struct flash_spec flash_table[] =
+static const struct flash_spec flash_table[] =
 {
 #define BUFFERED_FLAGS		(BCE_NV_BUFFERED | BCE_NV_TRANSLATE)
 #define NONBUFFERED_FLAGS	(BCE_NV_WREN)
@@ -258,7 +258,7 @@ static struct flash_spec flash_table[] =
  * logical-to-physical mapping is required in the
  * driver.
  */
-static struct flash_spec flash_5709 = {
+static const struct flash_spec flash_5709 = {
 	.flags		= BCE_NV_BUFFERED,
 	.page_bits	= BCM5709_FLASH_PAGE_BITS,
 	.page_size	= BCM5709_FLASH_PAGE_SIZE,
@@ -481,8 +481,8 @@ MODULE_DEPEND(bce, pci, 1, 1, 1);
 MODULE_DEPEND(bce, ether, 1, 1, 1);
 MODULE_DEPEND(bce, miibus, 1, 1, 1);
 
-DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, 0, 0);
-DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, 0, 0);
+DRIVER_MODULE(bce, pci, bce_driver, bce_devclass, NULL, NULL);
+DRIVER_MODULE(miibus, bce, miibus_driver, miibus_devclass, NULL, NULL);
 
 
 /****************************************************************************/
@@ -647,7 +647,7 @@ SYSCTL_UINT(_hw_bce, OID_AUTO, rx_ticks,
 static int
 bce_probe(device_t dev)
 {
-	struct bce_type *t;
+	const struct bce_type *t;
 	struct bce_softc *sc;
 	char *descbuf;
 	u16 vid = 0, did = 0, svid = 0, sdid = 0;
@@ -655,7 +655,6 @@ bce_probe(device_t dev)
 	t = bce_devs;
 
 	sc = device_get_softc(dev);
-	bzero(sc, sizeof(struct bce_softc));
 	sc->bce_unit = device_get_unit(dev);
 	sc->bce_dev = dev;
 
@@ -1040,7 +1039,7 @@ bce_attach(device_t dev)
 	struct bce_softc *sc;
 	struct ifnet *ifp;
 	u32 val;
-	int error, rid, rc = 0;
+	int count, error, rc = 0, rid;
 
 	sc = device_get_softc(dev);
 	sc->bce_dev = dev;
@@ -1084,14 +1083,14 @@ bce_attach(device_t dev)
 		((sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
 		&rid, RF_ACTIVE)) != NULL)) {
 
-		msi_needed = sc->bce_msi_count = 1;
+		msi_needed = count = 1;
 
-		if (((error = pci_alloc_msix(dev, &sc->bce_msi_count)) != 0) ||
-			(sc->bce_msi_count != msi_needed)) {
+		if (((error = pci_alloc_msix(dev, &count)) != 0) ||
+			(count != msi_needed)) {
 			BCE_PRINTF("%s(%d): MSI-X allocation failed! Requested = %d,"
 				"Received = %d, error = %d\n", __FILE__, __LINE__,
-				msi_needed, sc->bce_msi_count, error);
-			sc->bce_msi_count = 0;
+				msi_needed, count, error);
+			count = 0;
 			pci_release_msi(dev);
 			bus_release_resource(dev, SYS_RES_MEMORY, rid,
 				sc->bce_res_irq);
@@ -1100,19 +1099,18 @@ bce_attach(device_t dev)
 			DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI-X interrupt.\n",
 				__FUNCTION__);
 			sc->bce_flags |= BCE_USING_MSIX_FLAG;
-			sc->bce_intr = bce_intr;
 		}
 	}
 #endif
 
 	/* Try allocating a MSI interrupt. */
 	if ((sc->bce_cap_flags & BCE_MSI_CAPABLE_FLAG) &&
-		(bce_msi_enable >= 1) && (sc->bce_msi_count == 0)) {
-		sc->bce_msi_count = 1;
-		if ((error = pci_alloc_msi(dev, &sc->bce_msi_count)) != 0) {
+		(bce_msi_enable >= 1) && (count == 0)) {
+		count = 1;
+		if ((error = pci_alloc_msi(dev, &count)) != 0) {
 			BCE_PRINTF("%s(%d): MSI allocation failed! "
 			    "error = %d\n", __FILE__, __LINE__, error);
-			sc->bce_msi_count = 0;
+			count = 0;
 			pci_release_msi(dev);
 		} else {
 			DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using MSI "
@@ -1120,23 +1118,19 @@ bce_attach(device_t dev)
 			sc->bce_flags |= BCE_USING_MSI_FLAG;
 			if (BCE_CHIP_NUM(sc) == BCE_CHIP_NUM_5709)
 				sc->bce_flags |= BCE_ONE_SHOT_MSI_FLAG;
-			sc->bce_irq_rid = 1;
-			sc->bce_intr = bce_intr;
+			rid = 1;
 		}
 	}
 
 	/* Try allocating a legacy interrupt. */
-	if (sc->bce_msi_count == 0) {
+	if (count == 0) {
 		DBPRINT(sc, BCE_INFO_LOAD, "%s(): Using INTx interrupt.\n",
 			__FUNCTION__);
 		rid = 0;
-		sc->bce_intr = bce_intr;
 	}
 
 	sc->bce_res_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ,
-	    &rid, RF_SHAREABLE | RF_ACTIVE);
-
-	sc->bce_irq_rid = rid;
+	    &rid, RF_ACTIVE | (count != 0 ? 0 : RF_SHAREABLE));
 
 	/* Report any IRQ allocation errors. */
 	if (sc->bce_res_irq == NULL) {
@@ -1635,7 +1629,7 @@ bce_shutdown(device_t dev)
 static u32
 bce_reg_rd(struct bce_softc *sc, u32 offset)
 {
-	u32 val = bus_space_read_4(sc->bce_btag, sc->bce_bhandle, offset);
+	u32 val = REG_RD(sc, offset);
 	DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
 		__FUNCTION__, offset, val);
 	return val;
@@ -1653,7 +1647,7 @@ bce_reg_wr16(struct bce_softc *sc, u32 o
 {
 	DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%04X\n",
 		__FUNCTION__, offset, val);
-	bus_space_write_2(sc->bce_btag, sc->bce_bhandle, offset, val);
+	REG_WR16(sc, offset, val);
 }
 
 
@@ -1668,7 +1662,7 @@ bce_reg_wr(struct bce_softc *sc, u32 off
 {
 	DBPRINT(sc, BCE_INSANE_REG, "%s(); offset = 0x%08X, val = 0x%08X\n",
 		__FUNCTION__, offset, val);
-	bus_space_write_4(sc->bce_btag, sc->bce_bhandle, offset, val);
+	REG_WR(sc, offset, val);
 }
 #endif
 
@@ -1879,13 +1873,6 @@ bce_miibus_read_reg(device_t dev, int ph
 
 	sc = device_get_softc(dev);
 
-	/* Make sure we are accessing the correct PHY address. */
-	if (phy != sc->bce_phy_addr) {
-		DBPRINT(sc, BCE_INSANE_PHY, "Invalid PHY address %d "
-		    "for PHY read!\n", phy);
-		return(0);
-	}
-
     /*
      * The 5709S PHY is an IEEE Clause 45 PHY
      * with special mappings to work with IEEE
@@ -1968,13 +1955,6 @@ bce_miibus_write_reg(device_t dev, int p
 
 	sc = device_get_softc(dev);
 
-	/* Make sure we are accessing the correct PHY address. */
-	if (phy != sc->bce_phy_addr) {
-		DBPRINT(sc, BCE_INSANE_PHY, "Invalid PHY address %d "
-		    "for PHY write!\n", phy);
-		return(0);
-	}
-
 	DB_PRINT_PHY_REG(reg, val);
 
 	/*
@@ -2535,7 +2515,7 @@ bce_init_nvram(struct bce_softc *sc)
 {
 	u32 val;
 	int j, entry_count, rc = 0;
-	struct flash_spec *flash;
+	const struct flash_spec *flash;
 
 	DBENTER(BCE_VERBOSE_NVRAM);
 
@@ -3949,8 +3929,8 @@ bce_release_resources(struct bce_softc *
 
 	if (sc->bce_res_irq != NULL) {
 		DBPRINT(sc, BCE_INFO_RESET, "Releasing IRQ.\n");
-		bus_release_resource(dev, SYS_RES_IRQ, sc->bce_irq_rid,
-		    sc->bce_res_irq);
+		bus_release_resource(dev, SYS_RES_IRQ,
+		    rman_get_rid(sc->bce_res_irq), sc->bce_res_irq);
 	}
 
 	if (sc->bce_flags & (BCE_USING_MSI_FLAG | BCE_USING_MSIX_FLAG)) {
@@ -11650,4 +11630,3 @@ bce_breakpoint(struct bce_softc *sc)
 	return;
 }
 #endif
-

Modified: head/sys/dev/bce/if_bcereg.h
==============================================================================
--- head/sys/dev/bce/if_bcereg.h	Fri Mar  1 19:02:41 2013	(r247564)
+++ head/sys/dev/bce/if_bcereg.h	Fri Mar  1 19:12:38 2013	(r247565)
@@ -622,7 +622,7 @@ struct bce_type {
 	u_int16_t bce_did;
 	u_int16_t bce_svid;
 	u_int16_t bce_sdid;
-	char      *bce_name;
+	const char *bce_name;
 };
 
 /****************************************************************************/
@@ -716,7 +716,7 @@ struct flash_spec {
 	u32 page_size;
 	u32 addr_mask;
 	u32 total_size;
-	u8  *name;
+	const u8 *name;
 };
 
 
@@ -2001,7 +2001,7 @@ struct l2_fhdr {
 #define BCE_MISC_ENABLE_CLR_BITS_UMP_ENABLE				(1L<<27)
 #define BCE_MISC_ENABLE_CLR_BITS_RV2P_CMD_SCHEDULER_ENABLE	(1L<<28)
 #define BCE_MISC_ENABLE_CLR_BITS_RSVD_FUTURE_ENABLE		(0x7L<<29)
-
+
 #define BCE_MISC_ENABLE_CLR_DEFAULT						0x17ffffff
 
 #define BCE_MISC_CLOCK_CONTROL_BITS			0x00000818
@@ -6318,19 +6318,19 @@ struct fw_info {
 	u32 text_addr;
 	u32 text_len;
 	u32 text_index;
-	u32 *text;
+	const u32 *text;
 
 	/* Data section. */
 	u32 data_addr;
 	u32 data_len;
 	u32 data_index;
-	u32 *data;
+	const u32 *data;
 
 	/* SBSS section. */
 	u32 sbss_addr;
 	u32 sbss_len;
 	u32 sbss_index;
-	u32 *sbss;
+	const u32 *sbss;
 
 	/* BSS section. */
 	u32 bss_addr;
@@ -6421,7 +6421,7 @@ struct fw_info {
 
 struct bce_softc
 {
-	/* Interface info.  Must be first!! */
+	/* Interface info */
 	struct ifnet		*bce_ifp;
 
 	/* Parent device handle */
@@ -6451,10 +6451,7 @@ struct bce_softc
 	struct mtx		bce_mtx;
 
 	/* Interrupt handler. */
-	driver_intr_t		*bce_intr;
 	void			*bce_intrhand;
-	int			bce_irq_rid;
-	int			bce_msi_count;
 
 	/* ASIC Chip ID. */
 	u32			bce_chipid;
@@ -6509,7 +6506,7 @@ struct bce_softc
 	u16			link_speed;
 
 	/* Flash NVRAM settings */
-	struct flash_spec	*bce_flash_info;
+	const struct flash_spec	*bce_flash_info;
 
 	/* Flash NVRAM size */
 	u32			bce_flash_size;
@@ -6518,7 +6515,7 @@ struct bce_softc
 	u32			bce_shmem_base;
 
 	/* Name string */
-	char			*bce_name;
+	const char		*bce_name;
 
 	/* Tracks the version of bootcode firmware. */
 	char			bce_bc_ver[32];
@@ -6834,4 +6831,3 @@ struct bce_softc
 };
 
 #endif /* __BCEREG_H_DEFINED */
-



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201303011912.r21JCdRw056476>