Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Jan 2012 20:50:48 +0000 (UTC)
From:      Pyun YongHyeon <yongari@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r229422 - in stable/8/sys: conf dev/ti
Message-ID:  <201201032050.q03Komjg042360@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: yongari
Date: Tue Jan  3 20:50:48 2012
New Revision: 229422
URL: http://svn.freebsd.org/changeset/base/229422

Log:
  MFC r227311-227312,227318-227319,227322-227324:
  r227311:
    Remove ti_unit member variable in softc.
    While I'm here use PCIR_BAR macro.
  
  r227312:
     o Remove unnecessary controller reinitialization.
     o Do not blindly UP controller when MTU is changed. Reinitialize
       controller only if driver is running.
     o Remove useless ti_stop() in ti_watchdog() since ti_init_locked()
       always invokes ti_stop().
  
  r227318:
    Track which ring was updated in RX handler and update only modified
    ring. This should reduce unnecessary register accesses.
  
  r227319:
    Mini ring is not available on Tigon 1 so do not create DMA maps for
    mini ring on Tigon 1 to save resources.
  
  r227322:
    Show RX buffer allocation failure and do not blindly send alive
    message to firmware. Probably the correct way for this error is to
    send a TI_CMD_CODE_STACK_DOWN message to firmware and let firmware
    handle the rest.
  
  r227323:
    If ti_chipinit() fails in ti_stop(), ignore the error and release
    all allocated TX/RX buffer resources. If the interface is brought
    to up again after the error, we will leak allocated TX/RX buffers.
  
  r227324:
    Do not allow changing MTU to be less than the minimum.

Modified:
  stable/8/sys/dev/ti/if_ti.c
  stable/8/sys/dev/ti/if_tireg.h
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/conf/ldscript.mips.octeon1.32   (props changed)
  stable/8/sys/conf/ldscript.mips.octeon1.64   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/dev/ti/if_ti.c
==============================================================================
--- stable/8/sys/dev/ti/if_ti.c	Tue Jan  3 20:48:28 2012	(r229421)
+++ stable/8/sys/dev/ti/if_ti.c	Tue Jan  3 20:50:48 2012	(r229422)
@@ -998,6 +998,11 @@ ti_alloc_dmamaps(struct ti_softc *sc)
 				      &sc->ti_cdata.ti_rx_jumbo_maps[i]))
 			return (ENOBUFS);
 	}
+
+	/* Mini ring is not available on Tigon 1. */
+	if (sc->ti_hwrev == TI_HWREV_TIGON)
+		return (0);
+
 	for (i = 0; i < TI_MINI_RX_RING_CNT; i++) {
 		if (bus_dmamap_create(sc->ti_mbufrx_dmat, 0,
 				      &sc->ti_cdata.ti_rx_mini_maps[i]))
@@ -2224,7 +2229,6 @@ ti_attach(device_t dev)
 	u_char eaddr[6];
 
 	sc = device_get_softc(dev);
-	sc->ti_unit = device_get_unit(dev);
 	sc->ti_dev = dev;
 
 	mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
@@ -2246,7 +2250,7 @@ ti_attach(device_t dev)
 	 */
 	pci_enable_busmaster(dev);
 
-	rid = TI_PCI_LOMEM;
+	rid = PCIR_BAR(0);
 	sc->ti_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid,
 	    RF_ACTIVE);
 
@@ -2473,8 +2477,8 @@ ti_attach(device_t dev)
 	 */
 
 	/* Register the device */
-	sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
-			   0600, "ti%d", sc->ti_unit);
+	sc->dev = make_dev(&ti_cdevsw, device_get_unit(dev), UID_ROOT,
+	    GID_OPERATOR, 0600, "ti%d", device_get_unit(dev));
 	sc->dev->si_drv1 = sc;
 
 	/*
@@ -2565,7 +2569,7 @@ ti_detach(device_t dev)
 	if (sc->ti_irq)
 		bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
 	if (sc->ti_res) {
-		bus_release_resource(dev, SYS_RES_MEMORY, TI_PCI_LOMEM,
+		bus_release_resource(dev, SYS_RES_MEMORY, PCIR_BAR(0),
 		    sc->ti_res);
 	}
 	if (ifp)
@@ -2650,15 +2654,17 @@ ti_rxeof(struct ti_softc *sc)
 	struct ifnet *ifp;
 	bus_dmamap_t map;
 	struct ti_cmd_desc cmd;
+	int jumbocnt, minicnt, stdcnt;
 
 	TI_LOCK_ASSERT(sc);
 
 	ifp = sc->ti_ifp;
 
+	jumbocnt = minicnt = stdcnt = 0;
 	while (sc->ti_rx_saved_considx != sc->ti_return_prodidx.ti_idx) {
 		struct ti_rx_desc *cur_rx;
-		struct mbuf *m = NULL;
 		uint32_t rxidx;
+		struct mbuf *m = NULL;
 		uint16_t vlan_tag = 0;
 		int have_tag = 0;
 
@@ -2673,7 +2679,7 @@ ti_rxeof(struct ti_softc *sc)
 		}
 
 		if (cur_rx->ti_flags & TI_BDFLAG_JUMBO_RING) {
-
+			jumbocnt++;
 			TI_INC(sc->ti_jumbo, TI_JUMBO_RX_RING_CNT);
 			m = sc->ti_cdata.ti_rx_jumbo_chain[rxidx];
 			sc->ti_cdata.ti_rx_jumbo_chain[rxidx] = NULL;
@@ -2703,6 +2709,7 @@ ti_rxeof(struct ti_softc *sc)
 			m_adj(m, cur_rx->ti_len - m->m_pkthdr.len);
 #endif /* TI_PRIVATE_JUMBOS */
 		} else if (cur_rx->ti_flags & TI_BDFLAG_MINI_RING) {
+			minicnt++;
 			TI_INC(sc->ti_mini, TI_MINI_RX_RING_CNT);
 			m = sc->ti_cdata.ti_rx_mini_chain[rxidx];
 			sc->ti_cdata.ti_rx_mini_chain[rxidx] = NULL;
@@ -2722,6 +2729,7 @@ ti_rxeof(struct ti_softc *sc)
 			}
 			m->m_len = cur_rx->ti_len;
 		} else {
+			stdcnt++;
 			TI_INC(sc->ti_std, TI_STD_RX_RING_CNT);
 			m = sc->ti_cdata.ti_rx_std_chain[rxidx];
 			sc->ti_cdata.ti_rx_std_chain[rxidx] = NULL;
@@ -2777,9 +2785,12 @@ ti_rxeof(struct ti_softc *sc)
 		CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX,
 		    sc->ti_rx_saved_considx);
 
-	TI_UPDATE_STDPROD(sc, sc->ti_std);
-	TI_UPDATE_MINIPROD(sc, sc->ti_mini);
-	TI_UPDATE_JUMBOPROD(sc, sc->ti_jumbo);
+	if (stdcnt > 0)
+		TI_UPDATE_STDPROD(sc, sc->ti_std);
+	if (minicnt > 0)
+		TI_UPDATE_MINIPROD(sc, sc->ti_mini);
+	if (jumbocnt > 0)
+		TI_UPDATE_JUMBOPROD(sc, sc->ti_jumbo);
 }
 
 static void
@@ -3094,6 +3105,9 @@ ti_init_locked(void *xsc)
 {
 	struct ti_softc *sc = xsc;
 
+	if (sc->ti_ifp->if_drv_flags & IFF_DRV_RUNNING)
+		return;
+
 	/* Cancel pending I/O and flush buffers. */
 	ti_stop(sc);
 
@@ -3117,7 +3131,7 @@ static void ti_init2(struct ti_softc *sc
 	ifp = sc->ti_ifp;
 
 	/* Specify MTU and interface index. */
-	CSR_WRITE_4(sc, TI_GCR_IFINDEX, sc->ti_unit);
+	CSR_WRITE_4(sc, TI_GCR_IFINDEX, device_get_unit(sc->ti_dev));
 	CSR_WRITE_4(sc, TI_GCR_IFMTU, ifp->if_mtu +
 	    ETHER_HDR_LEN + ETHER_CRC_LEN + ETHER_VLAN_ENCAP_LEN);
 	TI_DO_CMD(TI_CMD_UPDATE_GENCOM, 0, 0);
@@ -3148,18 +3162,34 @@ static void ti_init2(struct ti_softc *sc
 	}
 
 	/* Init RX ring. */
-	ti_init_rx_ring_std(sc);
+	if (ti_init_rx_ring_std(sc) != 0) {
+		/* XXX */
+		device_printf(sc->ti_dev, "no memory for std Rx buffers.\n");
+		return;
+	}
 
 	/* Init jumbo RX ring. */
-	if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN))
-		ti_init_rx_ring_jumbo(sc);
+	if (ifp->if_mtu > (ETHERMTU + ETHER_HDR_LEN + ETHER_CRC_LEN)) {
+		if (ti_init_rx_ring_jumbo(sc) != 0) {
+			/* XXX */
+			device_printf(sc->ti_dev,
+			    "no memory for jumbo Rx buffers.\n");
+			return;
+		}
+	}
 
 	/*
 	 * If this is a Tigon 2, we can also configure the
 	 * mini ring.
 	 */
-	if (sc->ti_hwrev == TI_HWREV_TIGON_II)
-		ti_init_rx_ring_mini(sc);
+	if (sc->ti_hwrev == TI_HWREV_TIGON_II) {
+		if (ti_init_rx_ring_mini(sc) != 0) {
+			/* XXX */
+			device_printf(sc->ti_dev,
+			    "no memory for mini Rx buffers.\n");
+			return;
+		}
+	}
 
 	CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX, 0);
 	sc->ti_rx_saved_considx = 0;
@@ -3368,11 +3398,14 @@ ti_ioctl(struct ifnet *ifp, u_long comma
 	switch (command) {
 	case SIOCSIFMTU:
 		TI_LOCK(sc);
-		if (ifr->ifr_mtu > TI_JUMBO_MTU)
+		if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > TI_JUMBO_MTU)
 			error = EINVAL;
 		else {
 			ifp->if_mtu = ifr->ifr_mtu;
-			ti_init_locked(sc);
+			if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
+				ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
+				ti_init_locked(sc);
+			}
 		}
 		TI_UNLOCK(sc);
 		break;
@@ -3786,7 +3819,7 @@ ti_watchdog(void *arg)
 
 	ifp = sc->ti_ifp;
 	if_printf(ifp, "watchdog timeout -- resetting\n");
-	ti_stop(sc);
+	ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
 	ti_init_locked(sc);
 
 	ifp->if_oerrors++;
@@ -3814,11 +3847,11 @@ ti_stop(struct ti_softc *sc)
 	TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_DOWN, 0);
 
 	/* Halt and reinitialize. */
-	if (ti_chipinit(sc) != 0)
-		return;
-	ti_mem_zero(sc, 0x2000, 0x100000 - 0x2000);
-	if (ti_chipinit(sc) != 0)
-		return;
+	if (ti_chipinit(sc) == 0) {
+		ti_mem_zero(sc, 0x2000, 0x100000 - 0x2000);
+		/* XXX ignore init errors. */
+		ti_chipinit(sc);
+	}
 
 	/* Free the RX lists. */
 	ti_free_rx_ring_std(sc);

Modified: stable/8/sys/dev/ti/if_tireg.h
==============================================================================
--- stable/8/sys/dev/ti/if_tireg.h	Tue Jan  3 20:48:28 2012	(r229421)
+++ stable/8/sys/dev/ti/if_tireg.h	Tue Jan  3 20:50:48 2012	(r229422)
@@ -1000,7 +1000,6 @@ struct ti_softc {
 	struct resource		*ti_irq;
 	struct resource		*ti_res;
 	struct ifmedia		ifmedia;	/* media info */
-	uint8_t			ti_unit;	/* interface number */
 	uint8_t			ti_hwrev;	/* Tigon rev (1 or 2) */
 	uint8_t			ti_copper;	/* 1000baseTX card */
 	uint8_t			ti_linkstat;	/* Link state */



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