Deleted Added
full compact
if_ti.c (195049) if_ti.c (199559)
1/*-
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. 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

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

72 * - Raymond Lee of Netgear, for providing a pair of Netgear
73 * GA620 Tigon 2 boards for testing
74 * - Ulf Zimmermann, for bringing the GA260 to my attention and
75 * convincing me to write this driver.
76 * - Andrew Gallatin for providing FreeBSD/Alpha support.
77 */
78
79#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ctr.columbia.edu>. 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

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

72 * - Raymond Lee of Netgear, for providing a pair of Netgear
73 * GA620 Tigon 2 boards for testing
74 * - Ulf Zimmermann, for bringing the GA260 to my attention and
75 * convincing me to write this driver.
76 * - Andrew Gallatin for providing FreeBSD/Alpha support.
77 */
78
79#include <sys/cdefs.h>
80__FBSDID("$FreeBSD: head/sys/dev/ti/if_ti.c 195049 2009-06-26 11:45:06Z rwatson $");
80__FBSDID("$FreeBSD: head/sys/dev/ti/if_ti.c 199559 2009-11-19 22:06:40Z jhb $");
81
82#include "opt_ti.h"
83
84#include <sys/param.h>
85#include <sys/systm.h>
86#include <sys/sockio.h>
87#include <sys/mbuf.h>
88#include <sys/malloc.h>

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

189static void ti_intr(void *);
190static void ti_start(struct ifnet *);
191static void ti_start_locked(struct ifnet *);
192static int ti_ioctl(struct ifnet *, u_long, caddr_t);
193static void ti_init(void *);
194static void ti_init_locked(void *);
195static void ti_init2(struct ti_softc *);
196static void ti_stop(struct ti_softc *);
81
82#include "opt_ti.h"
83
84#include <sys/param.h>
85#include <sys/systm.h>
86#include <sys/sockio.h>
87#include <sys/mbuf.h>
88#include <sys/malloc.h>

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

189static void ti_intr(void *);
190static void ti_start(struct ifnet *);
191static void ti_start_locked(struct ifnet *);
192static int ti_ioctl(struct ifnet *, u_long, caddr_t);
193static void ti_init(void *);
194static void ti_init_locked(void *);
195static void ti_init2(struct ti_softc *);
196static void ti_stop(struct ti_softc *);
197static void ti_watchdog(struct ifnet *);
197static void ti_watchdog(void *);
198static int ti_shutdown(device_t);
199static int ti_ifmedia_upd(struct ifnet *);
200static void ti_ifmedia_sts(struct ifnet *, struct ifmediareq *);
201
202static u_int32_t ti_eeprom_putbyte(struct ti_softc *, int);
203static u_int8_t ti_eeprom_getbyte(struct ti_softc *, int, u_int8_t *);
204static int ti_read_eeprom(struct ti_softc *, caddr_t, int, int);
205

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

2280 u_char eaddr[6];
2281
2282 sc = device_get_softc(dev);
2283 sc->ti_unit = device_get_unit(dev);
2284 sc->ti_dev = dev;
2285
2286 mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2287 MTX_DEF);
198static int ti_shutdown(device_t);
199static int ti_ifmedia_upd(struct ifnet *);
200static void ti_ifmedia_sts(struct ifnet *, struct ifmediareq *);
201
202static u_int32_t ti_eeprom_putbyte(struct ti_softc *, int);
203static u_int8_t ti_eeprom_getbyte(struct ti_softc *, int, u_int8_t *);
204static int ti_read_eeprom(struct ti_softc *, caddr_t, int, int);
205

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

2280 u_char eaddr[6];
2281
2282 sc = device_get_softc(dev);
2283 sc->ti_unit = device_get_unit(dev);
2284 sc->ti_dev = dev;
2285
2286 mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2287 MTX_DEF);
2288 callout_init_mtx(&sc->ti_watchdog, &sc->ti_mtx, 0);
2288 ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts);
2289 ifp = sc->ti_ifp = if_alloc(IFT_ETHER);
2290 if (ifp == NULL) {
2291 device_printf(dev, "can not if_alloc()\n");
2292 error = ENOSPC;
2293 goto fail;
2294 }
2295 sc->ti_ifp->if_capabilities = IFCAP_HWCSUM |

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

2481 sc->ti_tx_buf_ratio = 21;
2482
2483 /* Set up ifnet structure */
2484 ifp->if_softc = sc;
2485 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
2486 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2487 ifp->if_ioctl = ti_ioctl;
2488 ifp->if_start = ti_start;
2289 ifmedia_init(&sc->ifmedia, IFM_IMASK, ti_ifmedia_upd, ti_ifmedia_sts);
2290 ifp = sc->ti_ifp = if_alloc(IFT_ETHER);
2291 if (ifp == NULL) {
2292 device_printf(dev, "can not if_alloc()\n");
2293 error = ENOSPC;
2294 goto fail;
2295 }
2296 sc->ti_ifp->if_capabilities = IFCAP_HWCSUM |

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

2482 sc->ti_tx_buf_ratio = 21;
2483
2484 /* Set up ifnet structure */
2485 ifp->if_softc = sc;
2486 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
2487 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
2488 ifp->if_ioctl = ti_ioctl;
2489 ifp->if_start = ti_start;
2489 ifp->if_watchdog = ti_watchdog;
2490 ifp->if_init = ti_init;
2491 ifp->if_baudrate = 1000000000;
2492 ifp->if_mtu = ETHERMTU;
2493 ifp->if_snd.ifq_maxlen = TI_TX_RING_CNT - 1;
2494
2495 /* Set up ifmedia support. */
2496 if (sc->ti_copper) {
2497 /*

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

2560 * allocated.
2561 */
2562static int
2563ti_detach(dev)
2564 device_t dev;
2565{
2566 struct ti_softc *sc;
2567 struct ifnet *ifp;
2490 ifp->if_init = ti_init;
2491 ifp->if_baudrate = 1000000000;
2492 ifp->if_mtu = ETHERMTU;
2493 ifp->if_snd.ifq_maxlen = TI_TX_RING_CNT - 1;
2494
2495 /* Set up ifmedia support. */
2496 if (sc->ti_copper) {
2497 /*

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

2560 * allocated.
2561 */
2562static int
2563ti_detach(dev)
2564 device_t dev;
2565{
2566 struct ti_softc *sc;
2567 struct ifnet *ifp;
2568 int attached;
2569
2570 sc = device_get_softc(dev);
2571 if (sc->dev)
2572 destroy_dev(sc->dev);
2573 KASSERT(mtx_initialized(&sc->ti_mtx), ("ti mutex not initialized"));
2568
2569 sc = device_get_softc(dev);
2570 if (sc->dev)
2571 destroy_dev(sc->dev);
2572 KASSERT(mtx_initialized(&sc->ti_mtx), ("ti mutex not initialized"));
2574 attached = device_is_attached(dev);
2575 TI_LOCK(sc);
2576 ifp = sc->ti_ifp;
2573 ifp = sc->ti_ifp;
2577 if (attached)
2578 ti_stop(sc);
2579 TI_UNLOCK(sc);
2580 if (attached)
2574 if (device_is_attached(dev)) {
2581 ether_ifdetach(ifp);
2575 ether_ifdetach(ifp);
2576 TI_LOCK(sc);
2577 ti_stop(sc);
2578 TI_UNLOCK(sc);
2579 }
2582
2583 /* These should only be active if attach succeeded */
2580
2581 /* These should only be active if attach succeeded */
2584 if (attached)
2585 bus_generic_detach(dev);
2582 callout_drain(&sc->ti_watchdog);
2583 bus_generic_detach(dev);
2586 ti_free_dmamaps(sc);
2587 ifmedia_removeall(&sc->ifmedia);
2588
2589#ifdef TI_PRIVATE_JUMBOS
2590 if (sc->ti_cdata.ti_jumbo_buf)
2591 bus_dmamem_free(sc->ti_jumbo_dmat, sc->ti_cdata.ti_jumbo_buf,
2592 sc->ti_jumbo_dmamap);
2593#endif

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

2861 m_freem(txd->tx_m);
2862 txd->tx_m = NULL;
2863 STAILQ_REMOVE_HEAD(&sc->ti_cdata.ti_txbusyq, tx_q);
2864 STAILQ_INSERT_TAIL(&sc->ti_cdata.ti_txfreeq, txd, tx_q);
2865 txd = STAILQ_FIRST(&sc->ti_cdata.ti_txbusyq);
2866 }
2867 sc->ti_tx_saved_considx = idx;
2868
2584 ti_free_dmamaps(sc);
2585 ifmedia_removeall(&sc->ifmedia);
2586
2587#ifdef TI_PRIVATE_JUMBOS
2588 if (sc->ti_cdata.ti_jumbo_buf)
2589 bus_dmamem_free(sc->ti_jumbo_dmat, sc->ti_cdata.ti_jumbo_buf,
2590 sc->ti_jumbo_dmamap);
2591#endif

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

2859 m_freem(txd->tx_m);
2860 txd->tx_m = NULL;
2861 STAILQ_REMOVE_HEAD(&sc->ti_cdata.ti_txbusyq, tx_q);
2862 STAILQ_INSERT_TAIL(&sc->ti_cdata.ti_txfreeq, txd, tx_q);
2863 txd = STAILQ_FIRST(&sc->ti_cdata.ti_txbusyq);
2864 }
2865 sc->ti_tx_saved_considx = idx;
2866
2869 ifp->if_timer = sc->ti_txcnt > 0 ? 5 : 0;
2867 sc->ti_timer = sc->ti_txcnt > 0 ? 5 : 0;
2870}
2871
2872static void
2873ti_intr(xsc)
2874 void *xsc;
2875{
2876 struct ti_softc *sc;
2877 struct ifnet *ifp;

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

3116
3117 if (enq > 0) {
3118 /* Transmit */
3119 CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, sc->ti_tx_saved_prodidx);
3120
3121 /*
3122 * Set a timeout in case the chip goes out to lunch.
3123 */
2868}
2869
2870static void
2871ti_intr(xsc)
2872 void *xsc;
2873{
2874 struct ti_softc *sc;
2875 struct ifnet *ifp;

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

3114
3115 if (enq > 0) {
3116 /* Transmit */
3117 CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, sc->ti_tx_saved_prodidx);
3118
3119 /*
3120 * Set a timeout in case the chip goes out to lunch.
3121 */
3124 ifp->if_timer = 5;
3122 sc->ti_timer = 5;
3125 }
3126}
3127
3128static void
3129ti_init(xsc)
3130 void *xsc;
3131{
3132 struct ti_softc *sc;

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

3220 /* Tell firmware we're alive. */
3221 TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_UP, 0);
3222
3223 /* Enable host interrupts. */
3224 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
3225
3226 ifp->if_drv_flags |= IFF_DRV_RUNNING;
3227 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3123 }
3124}
3125
3126static void
3127ti_init(xsc)
3128 void *xsc;
3129{
3130 struct ti_softc *sc;

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

3218 /* Tell firmware we're alive. */
3219 TI_DO_CMD(TI_CMD_HOST_STATE, TI_CMD_CODE_STACK_UP, 0);
3220
3221 /* Enable host interrupts. */
3222 CSR_WRITE_4(sc, TI_MB_HOSTINTR, 0);
3223
3224 ifp->if_drv_flags |= IFF_DRV_RUNNING;
3225 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
3226 callout_reset(&sc->ti_watchdog, hz, ti_watchdog, sc);
3228
3229 /*
3230 * Make sure to set media properly. We have to do this
3231 * here since we have to issue commands in order to set
3232 * the link negotiation and we can't issue commands until
3233 * the firmware is running.
3234 */
3235 ifm = &sc->ifmedia;

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

3781 default:
3782 error = ENOTTY;
3783 break;
3784 }
3785 return (error);
3786}
3787
3788static void
3227
3228 /*
3229 * Make sure to set media properly. We have to do this
3230 * here since we have to issue commands in order to set
3231 * the link negotiation and we can't issue commands until
3232 * the firmware is running.
3233 */
3234 ifm = &sc->ifmedia;

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

3780 default:
3781 error = ENOTTY;
3782 break;
3783 }
3784 return (error);
3785}
3786
3787static void
3789ti_watchdog(ifp)
3790 struct ifnet *ifp;
3788ti_watchdog(void *arg)
3791{
3792 struct ti_softc *sc;
3789{
3790 struct ti_softc *sc;
3791 struct ifnet *ifp;
3793
3792
3794 sc = ifp->if_softc;
3795 TI_LOCK(sc);
3793 sc = arg;
3794 TI_LOCK_ASSERT(sc);
3795 callout_reset(&sc->ti_watchdog, hz, ti_watchdog, sc);
3796 if (sc->ti_timer == 0 || --sc->ti_timer > 0)
3797 return;
3796
3797 /*
3798 * When we're debugging, the chip is often stopped for long periods
3799 * of time, and that would normally cause the watchdog timer to fire.
3800 * Since that impedes debugging, we don't want to do that.
3801 */
3798
3799 /*
3800 * When we're debugging, the chip is often stopped for long periods
3801 * of time, and that would normally cause the watchdog timer to fire.
3802 * Since that impedes debugging, we don't want to do that.
3803 */
3802 if (sc->ti_flags & TI_FLAG_DEBUGING) {
3803 TI_UNLOCK(sc);
3804 if (sc->ti_flags & TI_FLAG_DEBUGING)
3804 return;
3805 return;
3805 }
3806
3806
3807 ifp = sc->ti_ifp;
3807 if_printf(ifp, "watchdog timeout -- resetting\n");
3808 ti_stop(sc);
3809 ti_init_locked(sc);
3810
3811 ifp->if_oerrors++;
3808 if_printf(ifp, "watchdog timeout -- resetting\n");
3809 ti_stop(sc);
3810 ti_init_locked(sc);
3811
3812 ifp->if_oerrors++;
3812 TI_UNLOCK(sc);
3813}
3814
3815/*
3816 * Stop the adapter and free any mbufs allocated to the
3817 * RX and TX lists.
3818 */
3819static void
3820ti_stop(sc)

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

3854 ti_free_tx_ring(sc);
3855
3856 sc->ti_ev_prodidx.ti_idx = 0;
3857 sc->ti_return_prodidx.ti_idx = 0;
3858 sc->ti_tx_considx.ti_idx = 0;
3859 sc->ti_tx_saved_considx = TI_TXCONS_UNSET;
3860
3861 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
3813}
3814
3815/*
3816 * Stop the adapter and free any mbufs allocated to the
3817 * RX and TX lists.
3818 */
3819static void
3820ti_stop(sc)

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

3854 ti_free_tx_ring(sc);
3855
3856 sc->ti_ev_prodidx.ti_idx = 0;
3857 sc->ti_return_prodidx.ti_idx = 0;
3858 sc->ti_tx_considx.ti_idx = 0;
3859 sc->ti_tx_saved_considx = TI_TXCONS_UNSET;
3860
3861 ifp->if_drv_flags &= ~(IFF_DRV_RUNNING | IFF_DRV_OACTIVE);
3862 callout_stop(&sc->ti_watchdog);
3862}
3863
3864/*
3865 * Stop all chip I/O so that the kernel's probe routines don't
3866 * get confused by errant DMAs when rebooting.
3867 */
3868static int
3869ti_shutdown(dev)
3870 device_t dev;
3871{
3872 struct ti_softc *sc;
3873
3874 sc = device_get_softc(dev);
3875 TI_LOCK(sc);
3876 ti_chipinit(sc);
3877 TI_UNLOCK(sc);
3878
3879 return (0);
3880}
3863}
3864
3865/*
3866 * Stop all chip I/O so that the kernel's probe routines don't
3867 * get confused by errant DMAs when rebooting.
3868 */
3869static int
3870ti_shutdown(dev)
3871 device_t dev;
3872{
3873 struct ti_softc *sc;
3874
3875 sc = device_get_softc(dev);
3876 TI_LOCK(sc);
3877 ti_chipinit(sc);
3878 TI_UNLOCK(sc);
3879
3880 return (0);
3881}