Deleted Added
full compact
if_re.c (191301) if_re.c (193096)
1/*-
2 * Copyright (c) 1997, 1998-2003
3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997, 1998-2003
3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/dev/re/if_re.c 191301 2009-04-20 07:13:04Z yongari $");
34__FBSDID("$FreeBSD: head/sys/dev/re/if_re.c 193096 2009-05-30 15:14:44Z attilio $");
35
36/*
37 * RealTek 8139C+/8169/8169S/8110S/8168/8111/8101E PCI NIC driver
38 *
39 * Written by Bill Paul <wpaul@windriver.com>
40 * Senior Networking Software Engineer
41 * Wind River Systems
42 */

--- 189 unchanged lines hidden (view full) ---

232 (struct rl_softc *, int);
233static int re_newbuf (struct rl_softc *, int);
234static int re_rx_list_init (struct rl_softc *);
235static int re_tx_list_init (struct rl_softc *);
236#ifdef RE_FIXUP_RX
237static __inline void re_fixup_rx
238 (struct mbuf *);
239#endif
35
36/*
37 * RealTek 8139C+/8169/8169S/8110S/8168/8111/8101E PCI NIC driver
38 *
39 * Written by Bill Paul <wpaul@windriver.com>
40 * Senior Networking Software Engineer
41 * Wind River Systems
42 */

--- 189 unchanged lines hidden (view full) ---

232 (struct rl_softc *, int);
233static int re_newbuf (struct rl_softc *, int);
234static int re_rx_list_init (struct rl_softc *);
235static int re_tx_list_init (struct rl_softc *);
236#ifdef RE_FIXUP_RX
237static __inline void re_fixup_rx
238 (struct mbuf *);
239#endif
240static int re_rxeof (struct rl_softc *);
240static int re_rxeof (struct rl_softc *, int *);
241static void re_txeof (struct rl_softc *);
242#ifdef DEVICE_POLLING
241static void re_txeof (struct rl_softc *);
242#ifdef DEVICE_POLLING
243static void re_poll (struct ifnet *, enum poll_cmd, int);
244static void re_poll_locked (struct ifnet *, enum poll_cmd, int);
243static int re_poll (struct ifnet *, enum poll_cmd, int);
244static int re_poll_locked (struct ifnet *, enum poll_cmd, int);
245#endif
246static int re_intr (void *);
247static void re_tick (void *);
248static void re_tx_task (void *, int);
249static void re_int_task (void *, int);
250static void re_start (struct ifnet *);
251static int re_ioctl (struct ifnet *, u_long, caddr_t);
252static void re_init (void *);

--- 1534 unchanged lines hidden (view full) ---

1787}
1788
1789/*
1790 * RX handler for C+ and 8169. For the gigE chips, we support
1791 * the reception of jumbo frames that have been fragmented
1792 * across multiple 2K mbuf cluster buffers.
1793 */
1794static int
245#endif
246static int re_intr (void *);
247static void re_tick (void *);
248static void re_tx_task (void *, int);
249static void re_int_task (void *, int);
250static void re_start (struct ifnet *);
251static int re_ioctl (struct ifnet *, u_long, caddr_t);
252static void re_init (void *);

--- 1534 unchanged lines hidden (view full) ---

1787}
1788
1789/*
1790 * RX handler for C+ and 8169. For the gigE chips, we support
1791 * the reception of jumbo frames that have been fragmented
1792 * across multiple 2K mbuf cluster buffers.
1793 */
1794static int
1795re_rxeof(struct rl_softc *sc)
1795re_rxeof(struct rl_softc *sc, int *rx_npktsp)
1796{
1797 struct mbuf *m;
1798 struct ifnet *ifp;
1799 int i, total_len;
1800 struct rl_desc *cur_rx;
1801 u_int32_t rxstat, rxvlan;
1796{
1797 struct mbuf *m;
1798 struct ifnet *ifp;
1799 int i, total_len;
1800 struct rl_desc *cur_rx;
1801 u_int32_t rxstat, rxvlan;
1802 int maxpkt = 16;
1802 int maxpkt = 16, rx_npkts = 0;
1803
1804 RL_LOCK_ASSERT(sc);
1805
1806 ifp = sc->rl_ifp;
1807
1808 /* Invalidate the descriptor memory */
1809
1810 bus_dmamap_sync(sc->rl_ldata.rl_rx_list_tag,

--- 166 unchanged lines hidden (view full) ---

1977 if (rxvlan & RL_RDESC_VLANCTL_TAG) {
1978 m->m_pkthdr.ether_vtag =
1979 bswap16((rxvlan & RL_RDESC_VLANCTL_DATA));
1980 m->m_flags |= M_VLANTAG;
1981 }
1982 RL_UNLOCK(sc);
1983 (*ifp->if_input)(ifp, m);
1984 RL_LOCK(sc);
1803
1804 RL_LOCK_ASSERT(sc);
1805
1806 ifp = sc->rl_ifp;
1807
1808 /* Invalidate the descriptor memory */
1809
1810 bus_dmamap_sync(sc->rl_ldata.rl_rx_list_tag,

--- 166 unchanged lines hidden (view full) ---

1977 if (rxvlan & RL_RDESC_VLANCTL_TAG) {
1978 m->m_pkthdr.ether_vtag =
1979 bswap16((rxvlan & RL_RDESC_VLANCTL_DATA));
1980 m->m_flags |= M_VLANTAG;
1981 }
1982 RL_UNLOCK(sc);
1983 (*ifp->if_input)(ifp, m);
1984 RL_LOCK(sc);
1985 rx_npkts++;
1985 }
1986
1987 /* Flush the RX DMA ring */
1988
1989 bus_dmamap_sync(sc->rl_ldata.rl_rx_list_tag,
1990 sc->rl_ldata.rl_rx_list_map,
1991 BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
1992
1993 sc->rl_ldata.rl_rx_prodidx = i;
1994
1986 }
1987
1988 /* Flush the RX DMA ring */
1989
1990 bus_dmamap_sync(sc->rl_ldata.rl_rx_list_tag,
1991 sc->rl_ldata.rl_rx_list_map,
1992 BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
1993
1994 sc->rl_ldata.rl_rx_prodidx = i;
1995
1996 if (rx_npktsp != NULL)
1997 *rx_npktsp = rx_npkts;
1995 if (maxpkt)
1996 return(EAGAIN);
1997
1998 return(0);
1999}
2000
2001static void
2002re_txeof(struct rl_softc *sc)

--- 84 unchanged lines hidden (view full) ---

2087 * lost on PCIe based controllers under certain situations.
2088 */
2089 re_txeof(sc);
2090 re_watchdog(sc);
2091 callout_reset(&sc->rl_stat_callout, hz, re_tick, sc);
2092}
2093
2094#ifdef DEVICE_POLLING
1998 if (maxpkt)
1999 return(EAGAIN);
2000
2001 return(0);
2002}
2003
2004static void
2005re_txeof(struct rl_softc *sc)

--- 84 unchanged lines hidden (view full) ---

2090 * lost on PCIe based controllers under certain situations.
2091 */
2092 re_txeof(sc);
2093 re_watchdog(sc);
2094 callout_reset(&sc->rl_stat_callout, hz, re_tick, sc);
2095}
2096
2097#ifdef DEVICE_POLLING
2095static void
2098static int
2096re_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
2097{
2098 struct rl_softc *sc = ifp->if_softc;
2099re_poll(struct ifnet *ifp, enum poll_cmd cmd, int count)
2100{
2101 struct rl_softc *sc = ifp->if_softc;
2102 int rx_npkts = 0;
2099
2100 RL_LOCK(sc);
2101 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2103
2104 RL_LOCK(sc);
2105 if (ifp->if_drv_flags & IFF_DRV_RUNNING)
2102 re_poll_locked(ifp, cmd, count);
2106 rx_npkts = re_poll_locked(ifp, cmd, count);
2103 RL_UNLOCK(sc);
2107 RL_UNLOCK(sc);
2108 return (rx_npkts);
2104}
2105
2109}
2110
2106static void
2111static int
2107re_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count)
2108{
2109 struct rl_softc *sc = ifp->if_softc;
2112re_poll_locked(struct ifnet *ifp, enum poll_cmd cmd, int count)
2113{
2114 struct rl_softc *sc = ifp->if_softc;
2115 int rx_npkts;
2110
2111 RL_LOCK_ASSERT(sc);
2112
2113 sc->rxcycles = count;
2116
2117 RL_LOCK_ASSERT(sc);
2118
2119 sc->rxcycles = count;
2114 re_rxeof(sc);
2120 re_rxeof(sc, &rx_npkts);
2115 re_txeof(sc);
2116
2117 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
2118 taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask);
2119
2120 if (cmd == POLL_AND_CHECK_STATUS) { /* also check status register */
2121 u_int16_t status;
2122
2123 status = CSR_READ_2(sc, RL_ISR);
2124 if (status == 0xffff)
2121 re_txeof(sc);
2122
2123 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
2124 taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask);
2125
2126 if (cmd == POLL_AND_CHECK_STATUS) { /* also check status register */
2127 u_int16_t status;
2128
2129 status = CSR_READ_2(sc, RL_ISR);
2130 if (status == 0xffff)
2125 return;
2131 return (rx_npkts);
2126 if (status)
2127 CSR_WRITE_2(sc, RL_ISR, status);
2128 if ((status & (RL_ISR_TX_OK | RL_ISR_TX_DESC_UNAVAIL)) &&
2129 (sc->rl_flags & RL_FLAG_PCIE))
2130 CSR_WRITE_1(sc, sc->rl_txstart, RL_TXSTART_START);
2131
2132 /*
2133 * XXX check behaviour on receiver stalls.
2134 */
2135
2136 if (status & RL_ISR_SYSTEM_ERR)
2137 re_init_locked(sc);
2138 }
2132 if (status)
2133 CSR_WRITE_2(sc, RL_ISR, status);
2134 if ((status & (RL_ISR_TX_OK | RL_ISR_TX_DESC_UNAVAIL)) &&
2135 (sc->rl_flags & RL_FLAG_PCIE))
2136 CSR_WRITE_1(sc, sc->rl_txstart, RL_TXSTART_START);
2137
2138 /*
2139 * XXX check behaviour on receiver stalls.
2140 */
2141
2142 if (status & RL_ISR_SYSTEM_ERR)
2143 re_init_locked(sc);
2144 }
2145 return (rx_npkts);
2139}
2140#endif /* DEVICE_POLLING */
2141
2142static int
2143re_intr(void *arg)
2144{
2145 struct rl_softc *sc;
2146 uint16_t status;

--- 35 unchanged lines hidden (view full) ---

2182#ifdef DEVICE_POLLING
2183 if (ifp->if_capenable & IFCAP_POLLING) {
2184 RL_UNLOCK(sc);
2185 return;
2186 }
2187#endif
2188
2189 if (status & (RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_FIFO_OFLOW))
2146}
2147#endif /* DEVICE_POLLING */
2148
2149static int
2150re_intr(void *arg)
2151{
2152 struct rl_softc *sc;
2153 uint16_t status;

--- 35 unchanged lines hidden (view full) ---

2189#ifdef DEVICE_POLLING
2190 if (ifp->if_capenable & IFCAP_POLLING) {
2191 RL_UNLOCK(sc);
2192 return;
2193 }
2194#endif
2195
2196 if (status & (RL_ISR_RX_OK|RL_ISR_RX_ERR|RL_ISR_FIFO_OFLOW))
2190 rval = re_rxeof(sc);
2197 rval = re_rxeof(sc, NULL);
2191
2192 /*
2193 * Some chips will ignore a second TX request issued
2194 * while an existing transmission is in progress. If
2195 * the transmitter goes idle but there are still
2196 * packets waiting to be sent, we need to restart the
2197 * channel here to flush them out. This only seems to
2198 * be required with the PCIe devices.

--- 681 unchanged lines hidden (view full) ---

2880 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
2881 taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask);
2882 return;
2883 }
2884
2885 if_printf(ifp, "watchdog timeout\n");
2886 ifp->if_oerrors++;
2887
2198
2199 /*
2200 * Some chips will ignore a second TX request issued
2201 * while an existing transmission is in progress. If
2202 * the transmitter goes idle but there are still
2203 * packets waiting to be sent, we need to restart the
2204 * channel here to flush them out. This only seems to
2205 * be required with the PCIe devices.

--- 681 unchanged lines hidden (view full) ---

2887 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
2888 taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask);
2889 return;
2890 }
2891
2892 if_printf(ifp, "watchdog timeout\n");
2893 ifp->if_oerrors++;
2894
2888 re_rxeof(sc);
2895 re_rxeof(sc, NULL);
2889 re_init_locked(sc);
2890 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
2891 taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask);
2892}
2893
2894/*
2895 * Stop the adapter and free any mbufs allocated to the
2896 * RX and TX lists.

--- 237 unchanged lines hidden ---
2896 re_init_locked(sc);
2897 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
2898 taskqueue_enqueue_fast(taskqueue_fast, &sc->rl_txtask);
2899}
2900
2901/*
2902 * Stop the adapter and free any mbufs allocated to the
2903 * RX and TX lists.

--- 237 unchanged lines hidden ---