Deleted Added
full compact
if_ti.c (106627) if_ti.c (106936)
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

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

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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 *
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

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

24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
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 * $FreeBSD: head/sys/dev/ti/if_ti.c 106627 2002-11-08 14:58:35Z jhb $
32 * $FreeBSD: head/sys/dev/ti/if_ti.c 106936 2002-11-14 23:49:09Z sam $
33 */
34
35/*
36 * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD.
37 * Manuals, sample driver and firmware source kits are available
38 * from http://www.alteon.com/support/openkits.
39 *
40 * Written by Bill Paul <wpaul@ctr.columbia.edu>

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

147 * BDs.
148 */
149#if defined(TI_JUMBO_HDRSPLIT) && defined(TI_PRIVATE_JUMBOS)
150#error "options TI_JUMBO_HDRSPLIT and TI_PRIVATE_JUMBOS are mutually exclusive"
151#endif /* TI_JUMBO_HDRSPLIT && TI_JUMBO_HDRSPLIT */
152
153#if !defined(lint)
154static const char rcsid[] =
33 */
34
35/*
36 * Alteon Networks Tigon PCI gigabit ethernet driver for FreeBSD.
37 * Manuals, sample driver and firmware source kits are available
38 * from http://www.alteon.com/support/openkits.
39 *
40 * Written by Bill Paul <wpaul@ctr.columbia.edu>

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

147 * BDs.
148 */
149#if defined(TI_JUMBO_HDRSPLIT) && defined(TI_PRIVATE_JUMBOS)
150#error "options TI_JUMBO_HDRSPLIT and TI_PRIVATE_JUMBOS are mutually exclusive"
151#endif /* TI_JUMBO_HDRSPLIT && TI_JUMBO_HDRSPLIT */
152
153#if !defined(lint)
154static const char rcsid[] =
155 "$FreeBSD: head/sys/dev/ti/if_ti.c 106627 2002-11-08 14:58:35Z jhb $";
155 "$FreeBSD: head/sys/dev/ti/if_ti.c 106936 2002-11-14 23:49:09Z sam $";
156#endif
157
158struct ti_softc *tis[8];
159
160typedef enum {
161 TI_SWAP_HTON,
162 TI_SWAP_NTOH
163} ti_swap_type;

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

2122#endif
2123
2124 sc = device_get_softc(dev);
2125 unit = device_get_unit(dev);
2126 bzero(sc, sizeof(struct ti_softc));
2127
2128 mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2129 MTX_DEF | MTX_RECURSE);
156#endif
157
158struct ti_softc *tis[8];
159
160typedef enum {
161 TI_SWAP_HTON,
162 TI_SWAP_NTOH
163} ti_swap_type;

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

2122#endif
2123
2124 sc = device_get_softc(dev);
2125 unit = device_get_unit(dev);
2126 bzero(sc, sizeof(struct ti_softc));
2127
2128 mtx_init(&sc->ti_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
2129 MTX_DEF | MTX_RECURSE);
2130 sc->arpcom.ac_if.if_capabilities = IFCAP_HWCSUM;
2130 sc->arpcom.ac_if.if_capabilities = IFCAP_HWCSUM | IFCAP_VLAN_HWTAGGING;
2131 sc->arpcom.ac_if.if_capenable = sc->arpcom.ac_if.if_capabilities;
2132
2133 /*
2134 * Map control/status registers.
2135 */
2136 pci_enable_busmaster(dev);
2137 pci_enable_io(dev, SYS_RES_MEMORY);
2138 command = pci_read_config(dev, PCIR_COMMAND, 4);

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

2361
2362 /* Register the device */
2363 sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
2364 0600, "ti%d", sc->ti_unit);
2365
2366 /*
2367 * Call MI attach routine.
2368 */
2131 sc->arpcom.ac_if.if_capenable = sc->arpcom.ac_if.if_capabilities;
2132
2133 /*
2134 * Map control/status registers.
2135 */
2136 pci_enable_busmaster(dev);
2137 pci_enable_io(dev, SYS_RES_MEMORY);
2138 command = pci_read_config(dev, PCIR_COMMAND, 4);

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

2361
2362 /* Register the device */
2363 sc->dev = make_dev(&ti_cdevsw, sc->ti_unit, UID_ROOT, GID_OPERATOR,
2364 0600, "ti%d", sc->ti_unit);
2365
2366 /*
2367 * Call MI attach routine.
2368 */
2369 ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
2369 ether_ifattach(ifp, sc->arpcom.ac_enaddr);
2370 return(0);
2371
2372fail:
2373 mtx_destroy(&sc->ti_mtx);
2374 return(error);
2375}
2376
2377/*

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

2411
2412 if (ti_unref_special(dev))
2413 return EBUSY;
2414
2415 sc = device_get_softc(dev);
2416 TI_LOCK(sc);
2417 ifp = &sc->arpcom.ac_if;
2418
2370 return(0);
2371
2372fail:
2373 mtx_destroy(&sc->ti_mtx);
2374 return(error);
2375}
2376
2377/*

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

2411
2412 if (ti_unref_special(dev))
2413 return EBUSY;
2414
2415 sc = device_get_softc(dev);
2416 TI_LOCK(sc);
2417 ifp = &sc->arpcom.ac_if;
2418
2419 ether_ifdetach(ifp, ETHER_BPF_SUPPORTED);
2419 ether_ifdetach(ifp);
2420 ti_stop(sc);
2421
2422 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2423 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2424 bus_release_resource(dev, SYS_RES_MEMORY, TI_PCI_LOMEM, sc->ti_res);
2425
2426#ifdef TI_PRIVATE_JUMBOS
2427 contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM, M_DEVBUF);

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

2588 m->m_len = cur_rx->ti_len;
2589 }
2590
2591 m->m_pkthdr.len = cur_rx->ti_len;
2592 ifp->if_ipackets++;
2593 eh = mtod(m, struct ether_header *);
2594 m->m_pkthdr.rcvif = ifp;
2595
2420 ti_stop(sc);
2421
2422 bus_teardown_intr(dev, sc->ti_irq, sc->ti_intrhand);
2423 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->ti_irq);
2424 bus_release_resource(dev, SYS_RES_MEMORY, TI_PCI_LOMEM, sc->ti_res);
2425
2426#ifdef TI_PRIVATE_JUMBOS
2427 contigfree(sc->ti_cdata.ti_jumbo_buf, TI_JMEM, M_DEVBUF);

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

2588 m->m_len = cur_rx->ti_len;
2589 }
2590
2591 m->m_pkthdr.len = cur_rx->ti_len;
2592 ifp->if_ipackets++;
2593 eh = mtod(m, struct ether_header *);
2594 m->m_pkthdr.rcvif = ifp;
2595
2596 /* Remove header from mbuf and pass it on. */
2597 m_adj(m, sizeof(struct ether_header));
2598
2599 if (ifp->if_hwassist) {
2600 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED |
2601 CSUM_DATA_VALID;
2602 if ((cur_rx->ti_ip_cksum ^ 0xffff) == 0)
2603 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2604 m->m_pkthdr.csum_data = cur_rx->ti_tcp_udp_cksum;
2605 }
2606
2607 /*
2596 if (ifp->if_hwassist) {
2597 m->m_pkthdr.csum_flags |= CSUM_IP_CHECKED |
2598 CSUM_DATA_VALID;
2599 if ((cur_rx->ti_ip_cksum ^ 0xffff) == 0)
2600 m->m_pkthdr.csum_flags |= CSUM_IP_VALID;
2601 m->m_pkthdr.csum_data = cur_rx->ti_tcp_udp_cksum;
2602 }
2603
2604 /*
2608 * If we received a packet with a vlan tag, pass it
2609 * to vlan_input() instead of ether_input().
2605 * If we received a packet with a vlan tag,
2606 * tag it before passing the packet upward.
2610 */
2607 */
2611 if (have_tag) {
2612 VLAN_INPUT_TAG(eh, m, vlan_tag);
2613 have_tag = vlan_tag = 0;
2614 continue;
2615 }
2616 ether_input(ifp, eh, m);
2608 if (have_tag)
2609 VLAN_INPUT_TAG(ifp, m, vlan_tag, continue);
2610 (*ifp->if_input)(ifp, m);
2617 }
2618
2619 /* Only necessary on the Tigon 1. */
2620 if (sc->ti_hwrev == TI_HWREV_TIGON)
2621 CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX,
2622 sc->ti_rx_saved_considx);
2623
2624 TI_UPDATE_STDPROD(sc, sc->ti_std);

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

2749 struct ti_softc *sc;
2750 struct mbuf *m_head;
2751 u_int32_t *txidx;
2752{
2753 struct ti_tx_desc *f = NULL;
2754 struct mbuf *m;
2755 u_int32_t frag, cur, cnt = 0;
2756 u_int16_t csum_flags = 0;
2611 }
2612
2613 /* Only necessary on the Tigon 1. */
2614 if (sc->ti_hwrev == TI_HWREV_TIGON)
2615 CSR_WRITE_4(sc, TI_GCR_RXRETURNCONS_IDX,
2616 sc->ti_rx_saved_considx);
2617
2618 TI_UPDATE_STDPROD(sc, sc->ti_std);

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

2743 struct ti_softc *sc;
2744 struct mbuf *m_head;
2745 u_int32_t *txidx;
2746{
2747 struct ti_tx_desc *f = NULL;
2748 struct mbuf *m;
2749 u_int32_t frag, cur, cnt = 0;
2750 u_int16_t csum_flags = 0;
2757 struct ifvlan *ifv = NULL;
2751 struct m_tag *mtag;
2758
2752
2759 if ((m_head->m_flags & (M_PROTO1|M_PKTHDR)) == (M_PROTO1|M_PKTHDR) &&
2760 m_head->m_pkthdr.rcvif != NULL &&
2761 m_head->m_pkthdr.rcvif->if_type == IFT_L2VLAN)
2762 ifv = m_head->m_pkthdr.rcvif->if_softc;
2763
2764 m = m_head;
2765 cur = frag = *txidx;
2766
2767 if (m_head->m_pkthdr.csum_flags) {
2768 if (m_head->m_pkthdr.csum_flags & CSUM_IP)
2769 csum_flags |= TI_BDFLAG_IP_CKSUM;
2770 if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
2771 csum_flags |= TI_BDFLAG_TCP_UDP_CKSUM;
2772 if (m_head->m_flags & M_LASTFRAG)
2773 csum_flags |= TI_BDFLAG_IP_FRAG_END;
2774 else if (m_head->m_flags & M_FRAG)
2775 csum_flags |= TI_BDFLAG_IP_FRAG;
2776 }
2753 m = m_head;
2754 cur = frag = *txidx;
2755
2756 if (m_head->m_pkthdr.csum_flags) {
2757 if (m_head->m_pkthdr.csum_flags & CSUM_IP)
2758 csum_flags |= TI_BDFLAG_IP_CKSUM;
2759 if (m_head->m_pkthdr.csum_flags & (CSUM_TCP | CSUM_UDP))
2760 csum_flags |= TI_BDFLAG_TCP_UDP_CKSUM;
2761 if (m_head->m_flags & M_LASTFRAG)
2762 csum_flags |= TI_BDFLAG_IP_FRAG_END;
2763 else if (m_head->m_flags & M_FRAG)
2764 csum_flags |= TI_BDFLAG_IP_FRAG;
2765 }
2766
2767 mtag = VLAN_OUTPUT_TAG(&sc->arpcom.ac_if, m);
2768
2777 /*
2778 * Start packing the mbufs in this chain into
2779 * the fragment pointers. Stop when we run out
2780 * of fragments or hit the end of the mbuf chain.
2781 */
2782 for (m = m_head; m != NULL; m = m->m_next) {
2783 if (m->m_len != 0) {
2784 if (sc->ti_hwrev == TI_HWREV_TIGON) {

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

2798 } else
2799 f = &sc->ti_rdata->ti_tx_ring[frag];
2800 if (sc->ti_cdata.ti_tx_chain[frag] != NULL)
2801 break;
2802 TI_HOSTADDR(f->ti_addr) = vtophys(mtod(m, vm_offset_t));
2803 f->ti_len = m->m_len;
2804 f->ti_flags = csum_flags;
2805
2769 /*
2770 * Start packing the mbufs in this chain into
2771 * the fragment pointers. Stop when we run out
2772 * of fragments or hit the end of the mbuf chain.
2773 */
2774 for (m = m_head; m != NULL; m = m->m_next) {
2775 if (m->m_len != 0) {
2776 if (sc->ti_hwrev == TI_HWREV_TIGON) {

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

2790 } else
2791 f = &sc->ti_rdata->ti_tx_ring[frag];
2792 if (sc->ti_cdata.ti_tx_chain[frag] != NULL)
2793 break;
2794 TI_HOSTADDR(f->ti_addr) = vtophys(mtod(m, vm_offset_t));
2795 f->ti_len = m->m_len;
2796 f->ti_flags = csum_flags;
2797
2806 if (ifv != NULL) {
2798 if (mtag != NULL) {
2807 f->ti_flags |= TI_BDFLAG_VLAN_TAG;
2799 f->ti_flags |= TI_BDFLAG_VLAN_TAG;
2808 f->ti_vlan_tag = ifv->ifv_tag & 0xfff;
2800 f->ti_vlan_tag = VLAN_TAG_VALUE(mtag) & 0xfff;
2809 } else {
2810 f->ti_vlan_tag = 0;
2811 }
2812
2813 /*
2814 * Sanity check: avoid coming within 16 descriptors
2815 * of the end of the ring.
2816 */

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

2891 ifp->if_flags |= IFF_OACTIVE;
2892 break;
2893 }
2894
2895 /*
2896 * If there's a BPF listener, bounce a copy of this frame
2897 * to him.
2898 */
2801 } else {
2802 f->ti_vlan_tag = 0;
2803 }
2804
2805 /*
2806 * Sanity check: avoid coming within 16 descriptors
2807 * of the end of the ring.
2808 */

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

2883 ifp->if_flags |= IFF_OACTIVE;
2884 break;
2885 }
2886
2887 /*
2888 * If there's a BPF listener, bounce a copy of this frame
2889 * to him.
2890 */
2899 if (ifp->if_bpf)
2900 bpf_mtap(ifp, m_head);
2891 BPF_MTAP(ifp, m_head);
2901 }
2902
2903 /* Transmit */
2904 CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, prodidx);
2905
2906 /*
2907 * Set a timeout in case the chip goes out to lunch.
2908 */

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

3183 struct ti_softc *sc = ifp->if_softc;
3184 struct ifreq *ifr = (struct ifreq *) data;
3185 int mask, error = 0;
3186 struct ti_cmd_desc cmd;
3187
3188 TI_LOCK(sc);
3189
3190 switch(command) {
2892 }
2893
2894 /* Transmit */
2895 CSR_WRITE_4(sc, TI_MB_SENDPROD_IDX, prodidx);
2896
2897 /*
2898 * Set a timeout in case the chip goes out to lunch.
2899 */

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

3174 struct ti_softc *sc = ifp->if_softc;
3175 struct ifreq *ifr = (struct ifreq *) data;
3176 int mask, error = 0;
3177 struct ti_cmd_desc cmd;
3178
3179 TI_LOCK(sc);
3180
3181 switch(command) {
3191 case SIOCSIFADDR:
3192 case SIOCGIFADDR:
3193 error = ether_ioctl(ifp, command, data);
3194 break;
3195 case SIOCSIFMTU:
3196 if (ifr->ifr_mtu > TI_JUMBO_MTU)
3197 error = EINVAL;
3198 else {
3199 ifp->if_mtu = ifr->ifr_mtu;
3200 ti_init(sc);
3201 }
3202 break;

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

3249 else
3250 ifp->if_capenable |= IFCAP_HWCSUM;
3251 if (ifp->if_flags & IFF_RUNNING)
3252 ti_init(sc);
3253 }
3254 error = 0;
3255 break;
3256 default:
3182 case SIOCSIFMTU:
3183 if (ifr->ifr_mtu > TI_JUMBO_MTU)
3184 error = EINVAL;
3185 else {
3186 ifp->if_mtu = ifr->ifr_mtu;
3187 ti_init(sc);
3188 }
3189 break;

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

3236 else
3237 ifp->if_capenable |= IFCAP_HWCSUM;
3238 if (ifp->if_flags & IFF_RUNNING)
3239 ti_init(sc);
3240 }
3241 error = 0;
3242 break;
3243 default:
3257 error = EINVAL;
3244 error = ether_ioctl(ifp, command, data);
3258 break;
3259 }
3260
3261 TI_UNLOCK(sc);
3262
3263 return(error);
3264}
3265

--- 403 unchanged lines hidden ---
3245 break;
3246 }
3247
3248 TI_UNLOCK(sc);
3249
3250 return(error);
3251}
3252

--- 403 unchanged lines hidden ---