Deleted Added
full compact
if_sk.c (64137) if_sk.c (64837)
1/*
2 * Copyright (c) 1997, 1998, 1999, 2000
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, 2000
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/sk/if_sk.c 64137 2000-08-02 18:19:00Z wpaul $
32 * $FreeBSD: head/sys/dev/sk/if_sk.c 64837 2000-08-19 08:32:59Z dwmalone $
33 */
34
35/*
36 * SysKonnect SK-NET gigabit ethernet driver for FreeBSD. Supports
37 * the SK-984x series adapters, both single port and dual port.
38 * References:
39 * The XaQti XMAC II datasheet,
40 * http://www.freebsd.org/~wpaul/SysKonnect/xmacii_datasheet_rev_c_9-29.pdf

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

107
108MODULE_DEPEND(sk, miibus, 1, 1, 1);
109
110/* "controller miibus0" required. See GENERIC if you get errors here. */
111#include "miibus_if.h"
112
113#ifndef lint
114static const char rcsid[] =
33 */
34
35/*
36 * SysKonnect SK-NET gigabit ethernet driver for FreeBSD. Supports
37 * the SK-984x series adapters, both single port and dual port.
38 * References:
39 * The XaQti XMAC II datasheet,
40 * http://www.freebsd.org/~wpaul/SysKonnect/xmacii_datasheet_rev_c_9-29.pdf

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

107
108MODULE_DEPEND(sk, miibus, 1, 1, 1);
109
110/* "controller miibus0" required. See GENERIC if you get errors here. */
111#include "miibus_if.h"
112
113#ifndef lint
114static const char rcsid[] =
115 "$FreeBSD: head/sys/dev/sk/if_sk.c 64137 2000-08-02 18:19:00Z wpaul $";
115 "$FreeBSD: head/sys/dev/sk/if_sk.c 64837 2000-08-19 08:32:59Z dwmalone $";
116#endif
117
118static struct sk_type sk_devs[] = {
119 { SK_VENDORID, SK_DEVICEID_GE, "SysKonnect Gigabit Ethernet" },
120 { 0, 0, NULL }
121};
122
123static int sk_probe __P((device_t));

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

143static void sk_shutdown __P((device_t));
144static int sk_ifmedia_upd __P((struct ifnet *));
145static void sk_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
146static void sk_reset __P((struct sk_softc *));
147static int sk_newbuf __P((struct sk_if_softc *,
148 struct sk_chain *, struct mbuf *));
149static int sk_alloc_jumbo_mem __P((struct sk_if_softc *));
150static void *sk_jalloc __P((struct sk_if_softc *));
116#endif
117
118static struct sk_type sk_devs[] = {
119 { SK_VENDORID, SK_DEVICEID_GE, "SysKonnect Gigabit Ethernet" },
120 { 0, 0, NULL }
121};
122
123static int sk_probe __P((device_t));

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

143static void sk_shutdown __P((device_t));
144static int sk_ifmedia_upd __P((struct ifnet *));
145static void sk_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
146static void sk_reset __P((struct sk_softc *));
147static int sk_newbuf __P((struct sk_if_softc *,
148 struct sk_chain *, struct mbuf *));
149static int sk_alloc_jumbo_mem __P((struct sk_if_softc *));
150static void *sk_jalloc __P((struct sk_if_softc *));
151static void sk_jfree __P((caddr_t, u_int));
152static void sk_jref __P((caddr_t, u_int));
151static void sk_jfree __P((caddr_t, void *));
153static int sk_init_rx_ring __P((struct sk_if_softc *));
154static void sk_init_tx_ring __P((struct sk_if_softc *));
155static u_int32_t sk_win_read_4 __P((struct sk_softc *, int));
156static u_int16_t sk_win_read_2 __P((struct sk_softc *, int));
157static u_int8_t sk_win_read_1 __P((struct sk_softc *, int));
158static void sk_win_write_4 __P((struct sk_softc *, int, u_int32_t));
159static void sk_win_write_2 __P((struct sk_softc *, int, u_int32_t));
160static void sk_win_write_1 __P((struct sk_softc *, int, u_int32_t));

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

685#ifdef SK_VERBOSE
686 printf("sk%d: jumbo allocation failed "
687 "-- packet dropped!\n", sc_if->sk_unit);
688#endif
689 return(ENOBUFS);
690 }
691
692 /* Attach the buffer to the mbuf */
152static int sk_init_rx_ring __P((struct sk_if_softc *));
153static void sk_init_tx_ring __P((struct sk_if_softc *));
154static u_int32_t sk_win_read_4 __P((struct sk_softc *, int));
155static u_int16_t sk_win_read_2 __P((struct sk_softc *, int));
156static u_int8_t sk_win_read_1 __P((struct sk_softc *, int));
157static void sk_win_write_4 __P((struct sk_softc *, int, u_int32_t));
158static void sk_win_write_2 __P((struct sk_softc *, int, u_int32_t));
159static void sk_win_write_1 __P((struct sk_softc *, int, u_int32_t));

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

684#ifdef SK_VERBOSE
685 printf("sk%d: jumbo allocation failed "
686 "-- packet dropped!\n", sc_if->sk_unit);
687#endif
688 return(ENOBUFS);
689 }
690
691 /* Attach the buffer to the mbuf */
693 m_new->m_data = m_new->m_ext.ext_buf = (void *)buf;
694 m_new->m_flags |= M_EXT;
695 m_new->m_ext.ext_size = m_new->m_pkthdr.len =
696 m_new->m_len = SK_MCLBYTES;
697 m_new->m_ext.ext_free = sk_jfree;
698 m_new->m_ext.ext_ref = sk_jref;
692 MEXTADD(m_new, buf, SK_MCLBYTES, sk_jfree, NULL);
693 m_new->m_data = (void *)buf;
694 m_new->m_pkthdr.len = m_new->m_len = SK_MCLBYTES;
699 } else {
700 /*
701 * We're re-using a previously allocated mbuf;
702 * be sure to re-init pointers and lengths to
703 * default values.
704 */
705 m_new = m;
706 m_new->m_len = m_new->m_pkthdr.len = SK_MCLBYTES;

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

760 */
761 ptr = sc_if->sk_cdata.sk_jumbo_buf;
762 for (i = 0; i < SK_JSLOTS; i++) {
763 u_int64_t **aptr;
764 aptr = (u_int64_t **)ptr;
765 aptr[0] = (u_int64_t *)sc_if;
766 ptr += sizeof(u_int64_t);
767 sc_if->sk_cdata.sk_jslots[i].sk_buf = ptr;
695 } else {
696 /*
697 * We're re-using a previously allocated mbuf;
698 * be sure to re-init pointers and lengths to
699 * default values.
700 */
701 m_new = m;
702 m_new->m_len = m_new->m_pkthdr.len = SK_MCLBYTES;

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

756 */
757 ptr = sc_if->sk_cdata.sk_jumbo_buf;
758 for (i = 0; i < SK_JSLOTS; i++) {
759 u_int64_t **aptr;
760 aptr = (u_int64_t **)ptr;
761 aptr[0] = (u_int64_t *)sc_if;
762 ptr += sizeof(u_int64_t);
763 sc_if->sk_cdata.sk_jslots[i].sk_buf = ptr;
768 sc_if->sk_cdata.sk_jslots[i].sk_inuse = 0;
769 ptr += SK_MCLBYTES;
770 entry = malloc(sizeof(struct sk_jpool_entry),
771 M_DEVBUF, M_NOWAIT);
772 if (entry == NULL) {
773 free(sc_if->sk_cdata.sk_jumbo_buf, M_DEVBUF);
774 sc_if->sk_cdata.sk_jumbo_buf = NULL;
775 printf("sk%d: no memory for jumbo "
776 "buffer queue!\n", sc_if->sk_unit);

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

798#ifdef SK_VERBOSE
799 printf("sk%d: no free jumbo buffers\n", sc_if->sk_unit);
800#endif
801 return(NULL);
802 }
803
804 SLIST_REMOVE_HEAD(&sc_if->sk_jfree_listhead, jpool_entries);
805 SLIST_INSERT_HEAD(&sc_if->sk_jinuse_listhead, entry, jpool_entries);
764 ptr += SK_MCLBYTES;
765 entry = malloc(sizeof(struct sk_jpool_entry),
766 M_DEVBUF, M_NOWAIT);
767 if (entry == NULL) {
768 free(sc_if->sk_cdata.sk_jumbo_buf, M_DEVBUF);
769 sc_if->sk_cdata.sk_jumbo_buf = NULL;
770 printf("sk%d: no memory for jumbo "
771 "buffer queue!\n", sc_if->sk_unit);

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

793#ifdef SK_VERBOSE
794 printf("sk%d: no free jumbo buffers\n", sc_if->sk_unit);
795#endif
796 return(NULL);
797 }
798
799 SLIST_REMOVE_HEAD(&sc_if->sk_jfree_listhead, jpool_entries);
800 SLIST_INSERT_HEAD(&sc_if->sk_jinuse_listhead, entry, jpool_entries);
806 sc_if->sk_cdata.sk_jslots[entry->slot].sk_inuse = 1;
807 return(sc_if->sk_cdata.sk_jslots[entry->slot].sk_buf);
808}
809
810/*
801 return(sc_if->sk_cdata.sk_jslots[entry->slot].sk_buf);
802}
803
804/*
811 * Adjust usage count on a jumbo buffer. In general this doesn't
812 * get used much because our jumbo buffers don't get passed around
813 * a lot, but it's implemented for correctness.
814 */
815static void sk_jref(buf, size)
816 caddr_t buf;
817 u_int size;
818{
819 struct sk_if_softc *sc_if;
820 u_int64_t **aptr;
821 register int i;
822
823 /* Extract the softc struct pointer. */
824 aptr = (u_int64_t **)(buf - sizeof(u_int64_t));
825 sc_if = (struct sk_if_softc *)(aptr[0]);
826
827 if (sc_if == NULL)
828 panic("sk_jref: can't find softc pointer!");
829
830 if (size != SK_MCLBYTES)
831 panic("sk_jref: adjusting refcount of buf of wrong size!");
832
833 /* calculate the slot this buffer belongs to */
834
835 i = ((vm_offset_t)aptr
836 - (vm_offset_t)sc_if->sk_cdata.sk_jumbo_buf) / SK_JLEN;
837
838 if ((i < 0) || (i >= SK_JSLOTS))
839 panic("sk_jref: asked to reference buffer "
840 "that we don't manage!");
841 else if (sc_if->sk_cdata.sk_jslots[i].sk_inuse == 0)
842 panic("sk_jref: buffer already free!");
843 else
844 sc_if->sk_cdata.sk_jslots[i].sk_inuse++;
845
846 return;
847}
848
849/*
850 * Release a jumbo buffer.
851 */
805 * Release a jumbo buffer.
806 */
852static void sk_jfree(buf, size)
807static void sk_jfree(buf, args)
853 caddr_t buf;
808 caddr_t buf;
854 u_int size;
809 void *args;
855{
856 struct sk_if_softc *sc_if;
857 u_int64_t **aptr;
858 int i;
859 struct sk_jpool_entry *entry;
860
861 /* Extract the softc struct pointer. */
862 aptr = (u_int64_t **)(buf - sizeof(u_int64_t));
863 sc_if = (struct sk_if_softc *)(aptr[0]);
864
865 if (sc_if == NULL)
866 panic("sk_jfree: can't find softc pointer!");
867
810{
811 struct sk_if_softc *sc_if;
812 u_int64_t **aptr;
813 int i;
814 struct sk_jpool_entry *entry;
815
816 /* Extract the softc struct pointer. */
817 aptr = (u_int64_t **)(buf - sizeof(u_int64_t));
818 sc_if = (struct sk_if_softc *)(aptr[0]);
819
820 if (sc_if == NULL)
821 panic("sk_jfree: can't find softc pointer!");
822
868 if (size != SK_MCLBYTES)
869 panic("sk_jfree: freeing buffer of wrong size!");
870
871 /* calculate the slot this buffer belongs to */
823 /* calculate the slot this buffer belongs to */
872
873 i = ((vm_offset_t)aptr
874 - (vm_offset_t)sc_if->sk_cdata.sk_jumbo_buf) / SK_JLEN;
875
876 if ((i < 0) || (i >= SK_JSLOTS))
877 panic("sk_jfree: asked to free buffer that we don't manage!");
824 i = ((vm_offset_t)aptr
825 - (vm_offset_t)sc_if->sk_cdata.sk_jumbo_buf) / SK_JLEN;
826
827 if ((i < 0) || (i >= SK_JSLOTS))
828 panic("sk_jfree: asked to free buffer that we don't manage!");
878 else if (sc_if->sk_cdata.sk_jslots[i].sk_inuse == 0)
879 panic("sk_jfree: buffer already free!");
880 else {
881 sc_if->sk_cdata.sk_jslots[i].sk_inuse--;
882 if(sc_if->sk_cdata.sk_jslots[i].sk_inuse == 0) {
883 entry = SLIST_FIRST(&sc_if->sk_jinuse_listhead);
884 if (entry == NULL)
885 panic("sk_jfree: buffer not in use!");
886 entry->slot = i;
887 SLIST_REMOVE_HEAD(&sc_if->sk_jinuse_listhead,
888 jpool_entries);
889 SLIST_INSERT_HEAD(&sc_if->sk_jfree_listhead,
890 entry, jpool_entries);
891 }
892 }
893
829
830 entry = SLIST_FIRST(&sc_if->sk_jinuse_listhead);
831 if (entry == NULL)
832 panic("sk_jfree: buffer not in use!");
833 entry->slot = i;
834 SLIST_REMOVE_HEAD(&sc_if->sk_jinuse_listhead, jpool_entries);
835 SLIST_INSERT_HEAD(&sc_if->sk_jfree_listhead, entry, jpool_entries);
836
894 return;
895}
896
897/*
898 * Set media options.
899 */
900static int sk_ifmedia_upd(ifp)
901 struct ifnet *ifp;

--- 1368 unchanged lines hidden ---
837 return;
838}
839
840/*
841 * Set media options.
842 */
843static int sk_ifmedia_upd(ifp)
844 struct ifnet *ifp;

--- 1368 unchanged lines hidden ---