Deleted Added
full compact
if_bge.c (153234) if_bge.c (153239)
1/*-
2 * Copyright (c) 2001 Wind River Systems
3 * Copyright (c) 1997, 1998, 1999, 2001
4 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

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

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

27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/dev/bge/if_bge.c 153234 2005-12-08 13:31:52Z oleg $");
35__FBSDID("$FreeBSD: head/sys/dev/bge/if_bge.c 153239 2005-12-08 16:11:45Z glebius $");
36
37/*
38 * Broadcom BCM570x family gigabit ethernet driver for FreeBSD.
39 *
40 * The Broadcom BCM5700 is based on technology originally developed by
41 * Alteon Networks as part of the Tigon I and Tigon II gigabit ethernet
42 * MAC chips. The BCM5700, sometimes refered to as the Tigon III, has
43 * two on-board MIPS R4000 CPUs and can have as much as 16MB of external

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

74#include <sys/endian.h>
75#include <sys/systm.h>
76#include <sys/sockio.h>
77#include <sys/mbuf.h>
78#include <sys/malloc.h>
79#include <sys/kernel.h>
80#include <sys/module.h>
81#include <sys/socket.h>
36
37/*
38 * Broadcom BCM570x family gigabit ethernet driver for FreeBSD.
39 *
40 * The Broadcom BCM5700 is based on technology originally developed by
41 * Alteon Networks as part of the Tigon I and Tigon II gigabit ethernet
42 * MAC chips. The BCM5700, sometimes refered to as the Tigon III, has
43 * two on-board MIPS R4000 CPUs and can have as much as 16MB of external

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

74#include <sys/endian.h>
75#include <sys/systm.h>
76#include <sys/sockio.h>
77#include <sys/mbuf.h>
78#include <sys/malloc.h>
79#include <sys/kernel.h>
80#include <sys/module.h>
81#include <sys/socket.h>
82#include <sys/queue.h>
83
84#include <net/if.h>
85#include <net/if_arp.h>
86#include <net/ethernet.h>
87#include <net/if_dl.h>
88#include <net/if_media.h>
89
90#include <net/bpf.h>

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

232static void bge_ifmedia_sts (struct ifnet *, struct ifmediareq *);
233
234static u_int8_t bge_eeprom_getbyte (struct bge_softc *, int, u_int8_t *);
235static int bge_read_eeprom (struct bge_softc *, caddr_t, int, int);
236
237static void bge_setmulti (struct bge_softc *);
238
239static void bge_handle_events (struct bge_softc *);
82
83#include <net/if.h>
84#include <net/if_arp.h>
85#include <net/ethernet.h>
86#include <net/if_dl.h>
87#include <net/if_media.h>
88
89#include <net/bpf.h>

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

231static void bge_ifmedia_sts (struct ifnet *, struct ifmediareq *);
232
233static u_int8_t bge_eeprom_getbyte (struct bge_softc *, int, u_int8_t *);
234static int bge_read_eeprom (struct bge_softc *, caddr_t, int, int);
235
236static void bge_setmulti (struct bge_softc *);
237
238static void bge_handle_events (struct bge_softc *);
240static int bge_alloc_jumbo_mem (struct bge_softc *);
241static void bge_free_jumbo_mem (struct bge_softc *);
242static void *bge_jalloc (struct bge_softc *);
243static void bge_jfree (void *, void *);
244static int bge_newbuf_std (struct bge_softc *, int, struct mbuf *);
245static int bge_newbuf_jumbo (struct bge_softc *, int, struct mbuf *);
246static int bge_init_rx_ring_std (struct bge_softc *);
247static void bge_free_rx_ring_std (struct bge_softc *);
248static int bge_init_rx_ring_jumbo (struct bge_softc *);
249static void bge_free_rx_ring_jumbo (struct bge_softc *);
250static void bge_free_tx_ring (struct bge_softc *);
251static int bge_init_tx_ring (struct bge_softc *);

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

443
444 d->bge_flags |= htole16(BGE_TXBDFLAG_END);
445 ctx->bge_maxsegs = nseg;
446 ctx->bge_idx = idx;
447
448 return;
449}
450
239static int bge_newbuf_std (struct bge_softc *, int, struct mbuf *);
240static int bge_newbuf_jumbo (struct bge_softc *, int, struct mbuf *);
241static int bge_init_rx_ring_std (struct bge_softc *);
242static void bge_free_rx_ring_std (struct bge_softc *);
243static int bge_init_rx_ring_jumbo (struct bge_softc *);
244static void bge_free_rx_ring_jumbo (struct bge_softc *);
245static void bge_free_tx_ring (struct bge_softc *);
246static int bge_init_tx_ring (struct bge_softc *);

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

438
439 d->bge_flags |= htole16(BGE_TXBDFLAG_END);
440 ctx->bge_maxsegs = nseg;
441 ctx->bge_idx = idx;
442
443 return;
444}
445
451
452#ifdef notdef
453static u_int8_t
454bge_vpd_readbyte(sc, addr)
455 struct bge_softc *sc;
456 int addr;
457{
458 int i;
459 device_t dev;

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

742bge_handle_events(sc)
743 struct bge_softc *sc;
744{
745
746 return;
747}
748
749/*
446#ifdef notdef
447static u_int8_t
448bge_vpd_readbyte(sc, addr)
449 struct bge_softc *sc;
450 int addr;
451{
452 int i;
453 device_t dev;

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

736bge_handle_events(sc)
737 struct bge_softc *sc;
738{
739
740 return;
741}
742
743/*
750 * Memory management for jumbo frames.
751 */
752
753static int
754bge_alloc_jumbo_mem(sc)
755 struct bge_softc *sc;
756{
757 caddr_t ptr;
758 register int i, error;
759 struct bge_jpool_entry *entry;
760
761 /* Create tag for jumbo buffer block */
762
763 error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag,
764 PAGE_SIZE, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
765 NULL, BGE_JMEM, 1, BGE_JMEM, 0, NULL, NULL,
766 &sc->bge_cdata.bge_jumbo_tag);
767
768 if (error) {
769 printf("bge%d: could not allocate jumbo dma tag\n",
770 sc->bge_unit);
771 return (ENOMEM);
772 }
773
774 /* Allocate DMA'able memory for jumbo buffer block */
775
776 error = bus_dmamem_alloc(sc->bge_cdata.bge_jumbo_tag,
777 (void **)&sc->bge_ldata.bge_jumbo_buf, BUS_DMA_NOWAIT,
778 &sc->bge_cdata.bge_jumbo_map);
779
780 if (error)
781 return (ENOMEM);
782
783 SLIST_INIT(&sc->bge_jfree_listhead);
784 SLIST_INIT(&sc->bge_jinuse_listhead);
785
786 /*
787 * Now divide it up into 9K pieces and save the addresses
788 * in an array.
789 */
790 ptr = sc->bge_ldata.bge_jumbo_buf;
791 for (i = 0; i < BGE_JSLOTS; i++) {
792 sc->bge_cdata.bge_jslots[i] = ptr;
793 ptr += BGE_JLEN;
794 entry = malloc(sizeof(struct bge_jpool_entry),
795 M_DEVBUF, M_NOWAIT);
796 if (entry == NULL) {
797 bge_free_jumbo_mem(sc);
798 sc->bge_ldata.bge_jumbo_buf = NULL;
799 printf("bge%d: no memory for jumbo "
800 "buffer queue!\n", sc->bge_unit);
801 return(ENOBUFS);
802 }
803 entry->slot = i;
804 SLIST_INSERT_HEAD(&sc->bge_jfree_listhead,
805 entry, jpool_entries);
806 }
807
808 return(0);
809}
810
811static void
812bge_free_jumbo_mem(sc)
813 struct bge_softc *sc;
814{
815 int i;
816 struct bge_jpool_entry *entry;
817
818 for (i = 0; i < BGE_JSLOTS; i++) {
819 entry = SLIST_FIRST(&sc->bge_jfree_listhead);
820 SLIST_REMOVE_HEAD(&sc->bge_jfree_listhead, jpool_entries);
821 free(entry, M_DEVBUF);
822 }
823
824 /* Destroy jumbo buffer block */
825
826 if (sc->bge_ldata.bge_rx_jumbo_ring)
827 bus_dmamem_free(sc->bge_cdata.bge_jumbo_tag,
828 sc->bge_ldata.bge_jumbo_buf,
829 sc->bge_cdata.bge_jumbo_map);
830
831 if (sc->bge_cdata.bge_rx_jumbo_ring_map)
832 bus_dmamap_destroy(sc->bge_cdata.bge_jumbo_tag,
833 sc->bge_cdata.bge_jumbo_map);
834
835 if (sc->bge_cdata.bge_jumbo_tag)
836 bus_dma_tag_destroy(sc->bge_cdata.bge_jumbo_tag);
837
838 return;
839}
840
841/*
842 * Allocate a jumbo buffer.
843 */
844static void *
845bge_jalloc(sc)
846 struct bge_softc *sc;
847{
848 struct bge_jpool_entry *entry;
849
850 entry = SLIST_FIRST(&sc->bge_jfree_listhead);
851
852 if (entry == NULL) {
853 printf("bge%d: no free jumbo buffers\n", sc->bge_unit);
854 return(NULL);
855 }
856
857 SLIST_REMOVE_HEAD(&sc->bge_jfree_listhead, jpool_entries);
858 SLIST_INSERT_HEAD(&sc->bge_jinuse_listhead, entry, jpool_entries);
859 return(sc->bge_cdata.bge_jslots[entry->slot]);
860}
861
862/*
863 * Release a jumbo buffer.
864 */
865static void
866bge_jfree(buf, args)
867 void *buf;
868 void *args;
869{
870 struct bge_jpool_entry *entry;
871 struct bge_softc *sc;
872 int i;
873
874 /* Extract the softc struct pointer. */
875 sc = (struct bge_softc *)args;
876
877 if (sc == NULL)
878 panic("bge_jfree: can't find softc pointer!");
879
880 /* calculate the slot this buffer belongs to */
881
882 i = ((vm_offset_t)buf
883 - (vm_offset_t)sc->bge_ldata.bge_jumbo_buf) / BGE_JLEN;
884
885 if ((i < 0) || (i >= BGE_JSLOTS))
886 panic("bge_jfree: asked to free buffer that we don't manage!");
887
888 entry = SLIST_FIRST(&sc->bge_jinuse_listhead);
889 if (entry == NULL)
890 panic("bge_jfree: buffer not in use!");
891 entry->slot = i;
892 SLIST_REMOVE_HEAD(&sc->bge_jinuse_listhead, jpool_entries);
893 SLIST_INSERT_HEAD(&sc->bge_jfree_listhead, entry, jpool_entries);
894
895 return;
896}
897
898
899/*
900 * Intialize a standard receive ring descriptor.
901 */
902static int
903bge_newbuf_std(sc, i, m)
904 struct bge_softc *sc;
905 int i;
906 struct mbuf *m;
907{

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

962 * a jumbo buffer from the pool managed internally by the driver.
963 */
964static int
965bge_newbuf_jumbo(sc, i, m)
966 struct bge_softc *sc;
967 int i;
968 struct mbuf *m;
969{
744 * Intialize a standard receive ring descriptor.
745 */
746static int
747bge_newbuf_std(sc, i, m)
748 struct bge_softc *sc;
749 int i;
750 struct mbuf *m;
751{

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

806 * a jumbo buffer from the pool managed internally by the driver.
807 */
808static int
809bge_newbuf_jumbo(sc, i, m)
810 struct bge_softc *sc;
811 int i;
812 struct mbuf *m;
813{
814 bus_dma_segment_t segs[BGE_NSEG_JUMBO];
815 struct bge_extrx_bd *r;
970 struct mbuf *m_new = NULL;
816 struct mbuf *m_new = NULL;
971 struct bge_rx_bd *r;
972 struct bge_dmamap_arg ctx;
817 int nsegs;
973 int error;
974
975 if (m == NULL) {
818 int error;
819
820 if (m == NULL) {
976 caddr_t *buf = NULL;
977
978 /* Allocate the mbuf. */
979 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
821 MGETHDR(m_new, M_DONTWAIT, MT_DATA);
980 if (m_new == NULL) {
822 if (m_new == NULL)
981 return(ENOBUFS);
823 return(ENOBUFS);
982 }
983
824
984 /* Allocate the jumbo buffer */
985 buf = bge_jalloc(sc);
986 if (buf == NULL) {
825 m_cljget(m_new, M_DONTWAIT, MJUM9BYTES);
826 if (!(m_new->m_flags & M_EXT)) {
987 m_freem(m_new);
827 m_freem(m_new);
988 printf("bge%d: jumbo allocation failed "
989 "-- packet dropped!\n", sc->bge_unit);
990 return(ENOBUFS);
991 }
828 return(ENOBUFS);
829 }
992
993 /* Attach the buffer to the mbuf. */
994 m_new->m_data = (void *) buf;
995 m_new->m_len = m_new->m_pkthdr.len = BGE_JUMBO_FRAMELEN;
996 MEXTADD(m_new, buf, BGE_JUMBO_FRAMELEN, bge_jfree,
997 (struct bge_softc *)sc, 0, EXT_NET_DRV);
830 m_new->m_len = m_new->m_pkthdr.len = MJUM9BYTES;
998 } else {
999 m_new = m;
831 } else {
832 m_new = m;
833 m_new->m_len = m_new->m_pkthdr.len = MJUM9BYTES;
1000 m_new->m_data = m_new->m_ext.ext_buf;
834 m_new->m_data = m_new->m_ext.ext_buf;
1001 m_new->m_ext.ext_size = BGE_JUMBO_FRAMELEN;
1002 }
1003
1004 if (!sc->bge_rx_alignment_bug)
1005 m_adj(m_new, ETHER_ALIGN);
835 }
836
837 if (!sc->bge_rx_alignment_bug)
838 m_adj(m_new, ETHER_ALIGN);
1006 /* Set up the descriptor. */
1007 sc->bge_cdata.bge_rx_jumbo_chain[i] = m_new;
1008 r = &sc->bge_ldata.bge_rx_jumbo_ring[i];
1009 ctx.bge_maxsegs = 1;
1010 ctx.sc = sc;
1011 error = bus_dmamap_load(sc->bge_cdata.bge_mtag_jumbo,
1012 sc->bge_cdata.bge_rx_jumbo_dmamap[i], mtod(m_new, void *),
1013 m_new->m_len, bge_dma_map_addr, &ctx, BUS_DMA_NOWAIT);
1014 if (error || ctx.bge_maxsegs == 0) {
1015 if (m == NULL) {
1016 sc->bge_cdata.bge_rx_jumbo_chain[i] = NULL;
839
840 error = bus_dmamap_load_mbuf_sg(sc->bge_cdata.bge_mtag_jumbo,
841 sc->bge_cdata.bge_rx_jumbo_dmamap[i],
842 m_new, segs, &nsegs, BUS_DMA_NOWAIT);
843 if (error) {
844 if (m == NULL)
1017 m_freem(m_new);
845 m_freem(m_new);
1018 }
1019 return(ENOMEM);
846 return(error);
1020 }
847 }
1021 r->bge_addr.bge_addr_lo = htole32(BGE_ADDR_LO(ctx.bge_busaddr));
1022 r->bge_addr.bge_addr_hi = htole32(BGE_ADDR_HI(ctx.bge_busaddr));
1023 r->bge_flags = htole16(BGE_RXBDFLAG_END|BGE_RXBDFLAG_JUMBO_RING);
1024 r->bge_len = htole16(m_new->m_len);
848 KASSERT(nsegs == BGE_NSEG_JUMBO, ("%s: %d segments", __func__, nsegs));
849
850 sc->bge_cdata.bge_rx_jumbo_chain[i] = m_new;
851
852 /*
853 * Fill in the extended RX buffer descriptor.
854 */
855 r = &sc->bge_ldata.bge_rx_jumbo_ring[i];
856 r->bge_addr0.bge_addr_lo = htole32(BGE_ADDR_LO(segs[0].ds_addr));
857 r->bge_addr0.bge_addr_hi = htole32(BGE_ADDR_HI(segs[0].ds_addr));
858 r->bge_len0 = htole16(segs[0].ds_len);
859 r->bge_addr1.bge_addr_lo = htole32(BGE_ADDR_LO(segs[1].ds_addr));
860 r->bge_addr1.bge_addr_hi = htole32(BGE_ADDR_HI(segs[1].ds_addr));
861 r->bge_len1 = htole16(segs[1].ds_len);
862 r->bge_addr2.bge_addr_lo = htole32(BGE_ADDR_LO(segs[2].ds_addr));
863 r->bge_addr2.bge_addr_hi = htole32(BGE_ADDR_HI(segs[2].ds_addr));
864 r->bge_len2 = htole16(segs[2].ds_len);
865 r->bge_len3 = htole16(0);
866 r->bge_flags = htole16(BGE_RXBDFLAG_JUMBO_RING|BGE_RXBDFLAG_END);
1025 r->bge_idx = htole16(i);
1026
1027 bus_dmamap_sync(sc->bge_cdata.bge_mtag,
1028 sc->bge_cdata.bge_rx_jumbo_dmamap[i],
1029 BUS_DMASYNC_PREREAD);
1030
867 r->bge_idx = htole16(i);
868
869 bus_dmamap_sync(sc->bge_cdata.bge_mtag,
870 sc->bge_cdata.bge_rx_jumbo_dmamap[i],
871 BUS_DMASYNC_PREREAD);
872
1031 return(0);
873 return (0);
1032}
1033
1034/*
1035 * The standard receive ring has 512 entries in it. At 2K per mbuf cluster,
1036 * that's 1MB or memory, which is a lot. For now, we fill only the first
1037 * 256 ring entries and hope that our CPU is fast enough to keep up with
1038 * the NIC.
1039 */

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

1077
1078 return;
1079}
1080
1081static int
1082bge_init_rx_ring_jumbo(sc)
1083 struct bge_softc *sc;
1084{
874}
875
876/*
877 * The standard receive ring has 512 entries in it. At 2K per mbuf cluster,
878 * that's 1MB or memory, which is a lot. For now, we fill only the first
879 * 256 ring entries and hope that our CPU is fast enough to keep up with
880 * the NIC.
881 */

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

919
920 return;
921}
922
923static int
924bge_init_rx_ring_jumbo(sc)
925 struct bge_softc *sc;
926{
1085 int i;
1086 struct bge_rcb *rcb;
927 struct bge_rcb *rcb;
928 int i;
1087
1088 for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) {
1089 if (bge_newbuf_jumbo(sc, i, NULL) == ENOBUFS)
1090 return(ENOBUFS);
1091 };
1092
1093 bus_dmamap_sync(sc->bge_cdata.bge_rx_jumbo_ring_tag,
1094 sc->bge_cdata.bge_rx_jumbo_ring_map,
1095 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
1096
1097 sc->bge_jumbo = i - 1;
1098
1099 rcb = &sc->bge_ldata.bge_info.bge_jumbo_rx_rcb;
929
930 for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) {
931 if (bge_newbuf_jumbo(sc, i, NULL) == ENOBUFS)
932 return(ENOBUFS);
933 };
934
935 bus_dmamap_sync(sc->bge_cdata.bge_rx_jumbo_ring_tag,
936 sc->bge_cdata.bge_rx_jumbo_ring_map,
937 BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
938
939 sc->bge_jumbo = i - 1;
940
941 rcb = &sc->bge_ldata.bge_info.bge_jumbo_rx_rcb;
1100 rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0, 0);
942 rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0,
943 BGE_RCB_FLAG_USE_EXT_RX_BD);
1101 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags);
1102
1103 CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
1104
1105 return(0);
1106}
1107
1108static void

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

1114 for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) {
1115 if (sc->bge_cdata.bge_rx_jumbo_chain[i] != NULL) {
1116 m_freem(sc->bge_cdata.bge_rx_jumbo_chain[i]);
1117 sc->bge_cdata.bge_rx_jumbo_chain[i] = NULL;
1118 bus_dmamap_unload(sc->bge_cdata.bge_mtag_jumbo,
1119 sc->bge_cdata.bge_rx_jumbo_dmamap[i]);
1120 }
1121 bzero((char *)&sc->bge_ldata.bge_rx_jumbo_ring[i],
944 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_MAXLEN_FLAGS, rcb->bge_maxlen_flags);
945
946 CSR_WRITE_4(sc, BGE_MBX_RX_JUMBO_PROD_LO, sc->bge_jumbo);
947
948 return(0);
949}
950
951static void

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

957 for (i = 0; i < BGE_JUMBO_RX_RING_CNT; i++) {
958 if (sc->bge_cdata.bge_rx_jumbo_chain[i] != NULL) {
959 m_freem(sc->bge_cdata.bge_rx_jumbo_chain[i]);
960 sc->bge_cdata.bge_rx_jumbo_chain[i] = NULL;
961 bus_dmamap_unload(sc->bge_cdata.bge_mtag_jumbo,
962 sc->bge_cdata.bge_rx_jumbo_dmamap[i]);
963 }
964 bzero((char *)&sc->bge_ldata.bge_rx_jumbo_ring[i],
1122 sizeof(struct bge_rx_bd));
965 sizeof(struct bge_extrx_bd));
1123 }
1124
1125 return;
1126}
1127
1128static void
1129bge_free_tx_ring(sc)
1130 struct bge_softc *sc;

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

1465
1466 rcb->bge_hostaddr.bge_addr_lo =
1467 BGE_ADDR_LO(sc->bge_ldata.bge_rx_jumbo_ring_paddr);
1468 rcb->bge_hostaddr.bge_addr_hi =
1469 BGE_ADDR_HI(sc->bge_ldata.bge_rx_jumbo_ring_paddr);
1470 bus_dmamap_sync(sc->bge_cdata.bge_rx_jumbo_ring_tag,
1471 sc->bge_cdata.bge_rx_jumbo_ring_map,
1472 BUS_DMASYNC_PREREAD);
966 }
967
968 return;
969}
970
971static void
972bge_free_tx_ring(sc)
973 struct bge_softc *sc;

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

1308
1309 rcb->bge_hostaddr.bge_addr_lo =
1310 BGE_ADDR_LO(sc->bge_ldata.bge_rx_jumbo_ring_paddr);
1311 rcb->bge_hostaddr.bge_addr_hi =
1312 BGE_ADDR_HI(sc->bge_ldata.bge_rx_jumbo_ring_paddr);
1313 bus_dmamap_sync(sc->bge_cdata.bge_rx_jumbo_ring_tag,
1314 sc->bge_cdata.bge_rx_jumbo_ring_map,
1315 BUS_DMASYNC_PREREAD);
1473 rcb->bge_maxlen_flags =
1474 BGE_RCB_MAXLEN_FLAGS(BGE_MAX_FRAMELEN,
1475 BGE_RCB_FLAG_RING_DISABLED);
1316 rcb->bge_maxlen_flags = BGE_RCB_MAXLEN_FLAGS(0,
1317 BGE_RCB_FLAG_USE_EXT_RX_BD|BGE_RCB_FLAG_RING_DISABLED);
1476 if (sc->bge_extram)
1477 rcb->bge_nicaddr = BGE_EXT_JUMBO_RX_RINGS;
1478 else
1479 rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS;
1480 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI,
1481 rcb->bge_hostaddr.bge_addr_hi);
1482 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO,
1483 rcb->bge_hostaddr.bge_addr_lo);

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

1938 return;
1939}
1940
1941static int
1942bge_dma_alloc(dev)
1943 device_t dev;
1944{
1945 struct bge_softc *sc;
1318 if (sc->bge_extram)
1319 rcb->bge_nicaddr = BGE_EXT_JUMBO_RX_RINGS;
1320 else
1321 rcb->bge_nicaddr = BGE_JUMBO_RX_RINGS;
1322 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_HI,
1323 rcb->bge_hostaddr.bge_addr_hi);
1324 CSR_WRITE_4(sc, BGE_RX_JUMBO_RCB_HADDR_LO,
1325 rcb->bge_hostaddr.bge_addr_lo);

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

1780 return;
1781}
1782
1783static int
1784bge_dma_alloc(dev)
1785 device_t dev;
1786{
1787 struct bge_softc *sc;
1946 int nseg, i, error;
1788 int i, error;
1947 struct bge_dmamap_arg ctx;
1948
1949 sc = device_get_softc(dev);
1950
1951 /*
1952 * Allocate the parent bus DMA tag appropriate for PCI.
1953 */
1789 struct bge_dmamap_arg ctx;
1790
1791 sc = device_get_softc(dev);
1792
1793 /*
1794 * Allocate the parent bus DMA tag appropriate for PCI.
1795 */
1954#define BGE_NSEG_NEW 32
1955 error = bus_dma_tag_create(NULL, /* parent */
1956 PAGE_SIZE, 0, /* alignment, boundary */
1957 BUS_SPACE_MAXADDR, /* lowaddr */
1958 BUS_SPACE_MAXADDR, /* highaddr */
1959 NULL, NULL, /* filter, filterarg */
1960 MAXBSIZE, BGE_NSEG_NEW, /* maxsize, nsegments */
1961 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
1962 0, /* flags */
1963 NULL, NULL, /* lockfunc, lockarg */
1964 &sc->bge_cdata.bge_parent_tag);
1965
1966 /*
1967 * Create tag for RX mbufs.
1968 */
1796 error = bus_dma_tag_create(NULL, /* parent */
1797 PAGE_SIZE, 0, /* alignment, boundary */
1798 BUS_SPACE_MAXADDR, /* lowaddr */
1799 BUS_SPACE_MAXADDR, /* highaddr */
1800 NULL, NULL, /* filter, filterarg */
1801 MAXBSIZE, BGE_NSEG_NEW, /* maxsize, nsegments */
1802 BUS_SPACE_MAXSIZE_32BIT,/* maxsegsize */
1803 0, /* flags */
1804 NULL, NULL, /* lockfunc, lockarg */
1805 &sc->bge_cdata.bge_parent_tag);
1806
1807 /*
1808 * Create tag for RX mbufs.
1809 */
1969 nseg = 32;
1970 error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag, 1,
1971 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1810 error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag, 1,
1811 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1972 NULL, MCLBYTES * nseg, nseg, MCLBYTES, BUS_DMA_ALLOCNOW, NULL, NULL,
1973 &sc->bge_cdata.bge_mtag);
1812 NULL, MCLBYTES * BGE_NSEG_NEW, BGE_NSEG_NEW, MCLBYTES,
1813 BUS_DMA_ALLOCNOW, NULL, NULL, &sc->bge_cdata.bge_mtag);
1974
1975 if (error) {
1976 device_printf(dev, "could not allocate dma tag\n");
1977 return (ENOMEM);
1978 }
1979
1980 /* Create DMA maps for RX buffers */
1981

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

2052 * a single segment. I think eventually the driver should
2053 * be changed so that it uses ordinary mbufs and cluster
2054 * buffers, i.e. jumbo frames can span multiple DMA
2055 * descriptors. But that's a project for another day.
2056 */
2057
2058 error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag,
2059 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1814
1815 if (error) {
1816 device_printf(dev, "could not allocate dma tag\n");
1817 return (ENOMEM);
1818 }
1819
1820 /* Create DMA maps for RX buffers */
1821

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

1892 * a single segment. I think eventually the driver should
1893 * be changed so that it uses ordinary mbufs and cluster
1894 * buffers, i.e. jumbo frames can span multiple DMA
1895 * descriptors. But that's a project for another day.
1896 */
1897
1898 error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag,
1899 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
2060 NULL, MCLBYTES * nseg, nseg, BGE_JLEN, 0, NULL, NULL,
2061 &sc->bge_cdata.bge_mtag_jumbo);
1900 NULL, MJUM9BYTES, BGE_NSEG_JUMBO, PAGE_SIZE,
1901 0, NULL, NULL, &sc->bge_cdata.bge_mtag_jumbo);
2062
2063 if (error) {
2064 device_printf(dev, "could not allocate dma tag\n");
2065 return (ENOMEM);
2066 }
2067
2068 /* Create tag for jumbo RX ring */
1902
1903 if (error) {
1904 device_printf(dev, "could not allocate dma tag\n");
1905 return (ENOMEM);
1906 }
1907
1908 /* Create tag for jumbo RX ring */
2069
2070 error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag,
2071 PAGE_SIZE, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
2072 NULL, BGE_JUMBO_RX_RING_SZ, 1, BGE_JUMBO_RX_RING_SZ, 0,
2073 NULL, NULL, &sc->bge_cdata.bge_rx_jumbo_ring_tag);
2074
2075 if (error) {
2076 device_printf(dev, "could not allocate dma tag\n");
2077 return (ENOMEM);
2078 }
2079
2080 /* Allocate DMA'able memory for jumbo RX ring */
1909 error = bus_dma_tag_create(sc->bge_cdata.bge_parent_tag,
1910 PAGE_SIZE, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR, NULL,
1911 NULL, BGE_JUMBO_RX_RING_SZ, 1, BGE_JUMBO_RX_RING_SZ, 0,
1912 NULL, NULL, &sc->bge_cdata.bge_rx_jumbo_ring_tag);
1913
1914 if (error) {
1915 device_printf(dev, "could not allocate dma tag\n");
1916 return (ENOMEM);
1917 }
1918
1919 /* Allocate DMA'able memory for jumbo RX ring */
2081
2082 error = bus_dmamem_alloc(sc->bge_cdata.bge_rx_jumbo_ring_tag,
1920 error = bus_dmamem_alloc(sc->bge_cdata.bge_rx_jumbo_ring_tag,
2083 (void **)&sc->bge_ldata.bge_rx_jumbo_ring, BUS_DMA_NOWAIT,
1921 (void **)&sc->bge_ldata.bge_rx_jumbo_ring,
1922 BUS_DMA_NOWAIT | BUS_DMA_ZERO,
2084 &sc->bge_cdata.bge_rx_jumbo_ring_map);
2085 if (error)
2086 return (ENOMEM);
2087
1923 &sc->bge_cdata.bge_rx_jumbo_ring_map);
1924 if (error)
1925 return (ENOMEM);
1926
2088 bzero((char *)sc->bge_ldata.bge_rx_jumbo_ring,
2089 BGE_JUMBO_RX_RING_SZ);
2090
2091 /* Load the address of the jumbo RX ring */
1927 /* Load the address of the jumbo RX ring */
2092
2093 ctx.bge_maxsegs = 1;
2094 ctx.sc = sc;
2095
2096 error = bus_dmamap_load(sc->bge_cdata.bge_rx_jumbo_ring_tag,
2097 sc->bge_cdata.bge_rx_jumbo_ring_map,
2098 sc->bge_ldata.bge_rx_jumbo_ring, BGE_JUMBO_RX_RING_SZ,
2099 bge_dma_map_addr, &ctx, BUS_DMA_NOWAIT);
2100

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

2388 if (bge_dma_alloc(dev)) {
2389 printf ("bge%d: failed to allocate DMA resources\n",
2390 sc->bge_unit);
2391 bge_release_resources(sc);
2392 error = ENXIO;
2393 goto fail;
2394 }
2395
1928 ctx.bge_maxsegs = 1;
1929 ctx.sc = sc;
1930
1931 error = bus_dmamap_load(sc->bge_cdata.bge_rx_jumbo_ring_tag,
1932 sc->bge_cdata.bge_rx_jumbo_ring_map,
1933 sc->bge_ldata.bge_rx_jumbo_ring, BGE_JUMBO_RX_RING_SZ,
1934 bge_dma_map_addr, &ctx, BUS_DMA_NOWAIT);
1935

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

2223 if (bge_dma_alloc(dev)) {
2224 printf ("bge%d: failed to allocate DMA resources\n",
2225 sc->bge_unit);
2226 bge_release_resources(sc);
2227 error = ENXIO;
2228 goto fail;
2229 }
2230
2396 /*
2397 * Try to allocate memory for jumbo buffers.
2398 * The 5705 does not appear to support jumbo frames.
2399 */
2400 if (sc->bge_asicrev != BGE_ASICREV_BCM5705 &&
2401 sc->bge_asicrev != BGE_ASICREV_BCM5750) {
2402 if (bge_alloc_jumbo_mem(sc)) {
2403 printf("bge%d: jumbo buffer allocation "
2404 "failed\n", sc->bge_unit);
2405 bge_release_resources(sc);
2406 error = ENXIO;
2407 goto fail;
2408 }
2409 }
2410
2411 /* Set default tuneable values. */
2412 sc->bge_stat_ticks = BGE_TICKS_PER_SEC;
2413 sc->bge_rx_coal_ticks = 150;
2414 sc->bge_tx_coal_ticks = 150;
2415 sc->bge_rx_max_coal_bds = 64;
2416 sc->bge_tx_max_coal_bds = 128;
2417
2418 /* Set up ifnet structure */

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

2479 } else {
2480 /*
2481 * Do transceiver setup.
2482 */
2483 if (mii_phy_probe(dev, &sc->bge_miibus,
2484 bge_ifmedia_upd, bge_ifmedia_sts)) {
2485 printf("bge%d: MII without any PHY!\n", sc->bge_unit);
2486 bge_release_resources(sc);
2231 /* Set default tuneable values. */
2232 sc->bge_stat_ticks = BGE_TICKS_PER_SEC;
2233 sc->bge_rx_coal_ticks = 150;
2234 sc->bge_tx_coal_ticks = 150;
2235 sc->bge_rx_max_coal_bds = 64;
2236 sc->bge_tx_max_coal_bds = 128;
2237
2238 /* Set up ifnet structure */

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

2299 } else {
2300 /*
2301 * Do transceiver setup.
2302 */
2303 if (mii_phy_probe(dev, &sc->bge_miibus,
2304 bge_ifmedia_upd, bge_ifmedia_sts)) {
2305 printf("bge%d: MII without any PHY!\n", sc->bge_unit);
2306 bge_release_resources(sc);
2487 bge_free_jumbo_mem(sc);
2488 error = ENXIO;
2489 goto fail;
2490 }
2491 }
2492
2493 /*
2494 * When using the BCM5701 in PCI-X mode, data corruption has
2495 * been observed in the first few bytes of some received packets.

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

2557 if (sc->bge_tbi) {
2558 ifmedia_removeall(&sc->bge_ifmedia);
2559 } else {
2560 bus_generic_detach(dev);
2561 device_delete_child(dev, sc->bge_miibus);
2562 }
2563
2564 bge_release_resources(sc);
2307 error = ENXIO;
2308 goto fail;
2309 }
2310 }
2311
2312 /*
2313 * When using the BCM5701 in PCI-X mode, data corruption has
2314 * been observed in the first few bytes of some received packets.

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

2376 if (sc->bge_tbi) {
2377 ifmedia_removeall(&sc->bge_ifmedia);
2378 } else {
2379 bus_generic_detach(dev);
2380 device_delete_child(dev, sc->bge_miibus);
2381 }
2382
2383 bge_release_resources(sc);
2565 if (sc->bge_asicrev != BGE_ASICREV_BCM5705 &&
2566 sc->bge_asicrev != BGE_ASICREV_BCM5750)
2567 bge_free_jumbo_mem(sc);
2568
2569 return(0);
2570}
2571
2572static void
2573bge_release_resources(sc)
2574 struct bge_softc *sc;
2575{

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

2734 return;
2735}
2736
2737/*
2738 * Frame reception handling. This is called if there's a frame
2739 * on the receive return list.
2740 *
2741 * Note: we have to be able to handle two possibilities here:
2384
2385 return(0);
2386}
2387
2388static void
2389bge_release_resources(sc)
2390 struct bge_softc *sc;
2391{

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

2550 return;
2551}
2552
2553/*
2554 * Frame reception handling. This is called if there's a frame
2555 * on the receive return list.
2556 *
2557 * Note: we have to be able to handle two possibilities here:
2742 * 1) the frame is from the jumbo recieve ring
2558 * 1) the frame is from the jumbo receive ring
2743 * 2) the frame is from the standard receive ring
2744 */
2745
2746static void
2747bge_rxeof(sc)
2748 struct bge_softc *sc;
2749{
2750 struct ifnet *ifp;

--- 1204 unchanged lines hidden ---
2559 * 2) the frame is from the standard receive ring
2560 */
2561
2562static void
2563bge_rxeof(sc)
2564 struct bge_softc *sc;
2565{
2566 struct ifnet *ifp;

--- 1204 unchanged lines hidden ---