Deleted Added
full compact
if_fxp.c (29681) if_fxp.c (29974)
1/*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Modifications to support NetBSD and media selection:
6 * Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
1/*
2 * Copyright (c) 1995, David Greenman
3 * All rights reserved.
4 *
5 * Modifications to support NetBSD and media selection:
6 * Copyright (c) 1997 Jason R. Thorpe. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $Id: if_fxp.c,v 1.39 1997/09/05 10:23:54 davidg Exp $
30 * $Id: if_fxp.c,v 1.40 1997/09/21 22:02:08 gibbs Exp $
31 */
32
33/*
34 * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
35 */
36
37#include "bpfilter.h"
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/mbuf.h>
42#include <sys/malloc.h>
43#include <sys/kernel.h>
44#include <sys/socket.h>
45#include <sys/syslog.h>
46
47#include <net/if.h>
31 */
32
33/*
34 * Intel EtherExpress Pro/100B PCI Fast Ethernet driver
35 */
36
37#include "bpfilter.h"
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/mbuf.h>
42#include <sys/malloc.h>
43#include <sys/kernel.h>
44#include <sys/socket.h>
45#include <sys/syslog.h>
46
47#include <net/if.h>
48#include <net/if_dl.h>
48#include <net/if_media.h>
49
50#ifdef INET
51#include <netinet/in.h>
52#endif
53
54#ifdef NS
55#include <netns/ns.h>

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

157 0x0, /* 13 */
158 0xf2, /* 14 */
159 0x48, /* 15 */
160 0x0, /* 16 */
161 0x40, /* 17 */
162 0xf3, /* 18 */
163 0x0, /* 19 */
164 0x3f, /* 20 */
49#include <net/if_media.h>
50
51#ifdef INET
52#include <netinet/in.h>
53#endif
54
55#ifdef NS
56#include <netns/ns.h>

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

158 0x0, /* 13 */
159 0xf2, /* 14 */
160 0x48, /* 15 */
161 0x0, /* 16 */
162 0x40, /* 17 */
163 0xf3, /* 18 */
164 0x0, /* 19 */
165 0x3f, /* 20 */
165 0x5, /* 21 */
166 0x0, 0x0
166 0x5 /* 21 */
167};
168
169/* Supported media types. */
170struct fxp_supported_media {
171 const int fsm_phy; /* PHY type */
172 const int *fsm_media; /* the media array */
173 const int fsm_nmedia; /* the number of supported media */
174 const int fsm_defmedia; /* default media for this PHY */

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

201 { FXP_PHY_80C24, fxp_media_default,
202 sizeof(fxp_media_default) / sizeof(fxp_media_default[0]),
203 FXP_MEDIA_DEFAULT_DEFMEDIA },
204};
205#define NFXPMEDIA (sizeof(fxp_media) / sizeof(fxp_media[0]))
206
207static int fxp_mediachange __P((struct ifnet *));
208static void fxp_mediastatus __P((struct ifnet *, struct ifmediareq *));
167};
168
169/* Supported media types. */
170struct fxp_supported_media {
171 const int fsm_phy; /* PHY type */
172 const int *fsm_media; /* the media array */
173 const int fsm_nmedia; /* the number of supported media */
174 const int fsm_defmedia; /* default media for this PHY */

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

201 { FXP_PHY_80C24, fxp_media_default,
202 sizeof(fxp_media_default) / sizeof(fxp_media_default[0]),
203 FXP_MEDIA_DEFAULT_DEFMEDIA },
204};
205#define NFXPMEDIA (sizeof(fxp_media) / sizeof(fxp_media[0]))
206
207static int fxp_mediachange __P((struct ifnet *));
208static void fxp_mediastatus __P((struct ifnet *, struct ifmediareq *));
209
210void fxp_set_media __P((struct fxp_softc *, int));
209void fxp_set_media __P((struct fxp_softc *, int));
211
212static inline void fxp_scb_wait __P((struct fxp_softc *));
213static FXP_INTR_TYPE fxp_intr __P((void *));
214static void fxp_start __P((struct ifnet *));
215static int fxp_ioctl __P((struct ifnet *,
216 FXP_IOCTLCMD_TYPE, caddr_t));
217static void fxp_init __P((void *));
218static void fxp_stop __P((struct fxp_softc *));
219static void fxp_watchdog __P((struct ifnet *));
220static int fxp_add_rfabuf __P((struct fxp_softc *, struct mbuf *));
221static int fxp_mdi_read __P((struct fxp_softc *, int, int));
222static void fxp_mdi_write __P((struct fxp_softc *, int, int, int));
223static void fxp_read_eeprom __P((struct fxp_softc *, u_int16_t *,
224 int, int));
225static int fxp_attach_common __P((struct fxp_softc *, u_int8_t *));
210static inline void fxp_scb_wait __P((struct fxp_softc *));
211static FXP_INTR_TYPE fxp_intr __P((void *));
212static void fxp_start __P((struct ifnet *));
213static int fxp_ioctl __P((struct ifnet *,
214 FXP_IOCTLCMD_TYPE, caddr_t));
215static void fxp_init __P((void *));
216static void fxp_stop __P((struct fxp_softc *));
217static void fxp_watchdog __P((struct ifnet *));
218static int fxp_add_rfabuf __P((struct fxp_softc *, struct mbuf *));
219static int fxp_mdi_read __P((struct fxp_softc *, int, int));
220static void fxp_mdi_write __P((struct fxp_softc *, int, int, int));
221static void fxp_read_eeprom __P((struct fxp_softc *, u_int16_t *,
222 int, int));
223static int fxp_attach_common __P((struct fxp_softc *, u_int8_t *));
226
227void fxp_stats_update __P((void *));
224void fxp_stats_update __P((void *));
225static void fxp_mc_setup __P((struct fxp_softc *));
228
229/*
230 * Set initial transmit threshold at 64 (512 bytes). This is
231 * increased by 64 (512 bytes) at a time, to maximum of 192
232 * (1536 bytes), if an underrun occurs.
233 */
234static int tx_threshold = 64;
235

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

241#define FXP_NTXCB 128
242
243/*
244 * TxCB list index mask. This is used to do list wrap-around.
245 */
246#define FXP_TXCB_MASK (FXP_NTXCB - 1)
247
248/*
226
227/*
228 * Set initial transmit threshold at 64 (512 bytes). This is
229 * increased by 64 (512 bytes) at a time, to maximum of 192
230 * (1536 bytes), if an underrun occurs.
231 */
232static int tx_threshold = 64;
233

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

239#define FXP_NTXCB 128
240
241/*
242 * TxCB list index mask. This is used to do list wrap-around.
243 */
244#define FXP_TXCB_MASK (FXP_NTXCB - 1)
245
246/*
249 * Number of DMA segments in a TxCB. Note that this is carefully
250 * chosen to make the total struct size an even power of two. It's
251 * critical that no TxCB be split across a page boundry since
252 * no attempt is made to allocate physically contiguous memory.
253 *
254 * XXX - don't forget to change the hard-coded constant in the
255 * fxp_cb_tx struct (defined in if_fxpreg.h), too!
256 */
257#define FXP_NTXSEG 29
258
259/*
260 * Number of receive frame area buffers. These are large so chose
261 * wisely.
262 */
263#define FXP_NRFABUFS 32
264
265/*
247 * Number of receive frame area buffers. These are large so chose
248 * wisely.
249 */
250#define FXP_NRFABUFS 32
251
252/*
253 * Maximum number of seconds that the receiver can be idle before we
254 * assume it's dead and attempt to reset it by reprogramming the
255 * multicast filter. This is part of a work-around for a bug in the
256 * NIC. See fxp_stats_update().
257 */
258#define FXP_MAX_RX_IDLE 15
259
260/*
266 * Wait for the previous command to be accepted (but not necessarily
267 * completed).
268 */
269static inline void
270fxp_scb_wait(sc)
271 struct fxp_softc *sc;
272{
273 int i = 10000;
274
261 * Wait for the previous command to be accepted (but not necessarily
262 * completed).
263 */
264static inline void
265fxp_scb_wait(sc)
266 struct fxp_softc *sc;
267{
268 int i = 10000;
269
275 while ((CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) & FXP_SCB_COMMAND_MASK)
276 && --i);
270 while (CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) && --i);
277}
278
279/*************************************************************
280 * Operating system-specific autoconfiguration glue
281 *************************************************************/
282
283#if defined(__NetBSD__)
284

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

624 if (sc->cbl_base == NULL)
625 goto fail;
626
627 sc->fxp_stats = malloc(sizeof(struct fxp_stats), M_DEVBUF, M_NOWAIT);
628 if (sc->fxp_stats == NULL)
629 goto fail;
630 bzero(sc->fxp_stats, sizeof(struct fxp_stats));
631
271}
272
273/*************************************************************
274 * Operating system-specific autoconfiguration glue
275 *************************************************************/
276
277#if defined(__NetBSD__)
278

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

618 if (sc->cbl_base == NULL)
619 goto fail;
620
621 sc->fxp_stats = malloc(sizeof(struct fxp_stats), M_DEVBUF, M_NOWAIT);
622 if (sc->fxp_stats == NULL)
623 goto fail;
624 bzero(sc->fxp_stats, sizeof(struct fxp_stats));
625
626 sc->mcsp = malloc(sizeof(struct fxp_cb_mcs), M_DEVBUF, M_NOWAIT);
627 if (sc->mcsp == NULL)
628 goto fail;
629
632 /*
633 * Pre-allocate our receive buffers.
634 */
635 for (i = 0; i < FXP_NRFABUFS; i++) {
636 if (fxp_add_rfabuf(sc, NULL) != 0) {
637 goto fail;
638 }
639 }

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

678 return (0);
679
680 fail:
681 printf(FXP_FORMAT ": Failed to malloc memory\n", FXP_ARGS(sc));
682 if (sc->cbl_base)
683 free(sc->cbl_base, M_DEVBUF);
684 if (sc->fxp_stats)
685 free(sc->fxp_stats, M_DEVBUF);
630 /*
631 * Pre-allocate our receive buffers.
632 */
633 for (i = 0; i < FXP_NRFABUFS; i++) {
634 if (fxp_add_rfabuf(sc, NULL) != 0) {
635 goto fail;
636 }
637 }

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

676 return (0);
677
678 fail:
679 printf(FXP_FORMAT ": Failed to malloc memory\n", FXP_ARGS(sc));
680 if (sc->cbl_base)
681 free(sc->cbl_base, M_DEVBUF);
682 if (sc->fxp_stats)
683 free(sc->fxp_stats, M_DEVBUF);
684 if (sc->mcsp)
685 free(sc->mcsp, M_DEVBUF);
686 /* frees entire chain */
687 if (sc->rfa_headm)
688 m_freem(sc->rfa_headm);
689
690 return (ENOMEM);
691}
692
693/*

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

770{
771 struct fxp_softc *sc = ifp->if_softc;
772 struct fxp_cb_tx *txp;
773 struct mbuf *m, *mb_head;
774 int segment, first = 1;
775
776txloop:
777 /*
686 /* frees entire chain */
687 if (sc->rfa_headm)
688 m_freem(sc->rfa_headm);
689
690 return (ENOMEM);
691}
692
693/*

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

770{
771 struct fxp_softc *sc = ifp->if_softc;
772 struct fxp_cb_tx *txp;
773 struct mbuf *m, *mb_head;
774 int segment, first = 1;
775
776txloop:
777 /*
778 * See if we're all filled up with buffers to transmit.
778 * See if we're all filled up with buffers to transmit, or
779 * if we need to suspend xmit until the multicast filter
780 * has been reprogrammed (which can only be done at the
781 * head of the command chain).
779 */
782 */
780 if (sc->tx_queued >= FXP_NTXCB)
783 if (sc->tx_queued >= FXP_NTXCB || sc->need_mcsetup)
781 return;
782
783 /*
784 * Grab a packet to transmit.
785 */
786 IF_DEQUEUE(&ifp->if_snd, mb_head);
787 if (mb_head == NULL) {
788 /*

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

920 CSR_WRITE_1(sc, FXP_CSR_SCB_STATACK, statack);
921
922 /*
923 * Free any finished transmit mbuf chains.
924 */
925 if (statack & FXP_SCB_STATACK_CNA) {
926 struct fxp_cb_tx *txp;
927
784 return;
785
786 /*
787 * Grab a packet to transmit.
788 */
789 IF_DEQUEUE(&ifp->if_snd, mb_head);
790 if (mb_head == NULL) {
791 /*

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

923 CSR_WRITE_1(sc, FXP_CSR_SCB_STATACK, statack);
924
925 /*
926 * Free any finished transmit mbuf chains.
927 */
928 if (statack & FXP_SCB_STATACK_CNA) {
929 struct fxp_cb_tx *txp;
930
928 for (txp = sc->cbl_first;
931 for (txp = sc->cbl_first; sc->tx_queued &&
929 (txp->cb_status & FXP_CB_STATUS_C) != 0;
930 txp = txp->next) {
931 if (txp->mb_head != NULL) {
932 m_freem(txp->mb_head);
933 txp->mb_head = NULL;
932 (txp->cb_status & FXP_CB_STATUS_C) != 0;
933 txp = txp->next) {
934 if (txp->mb_head != NULL) {
935 m_freem(txp->mb_head);
936 txp->mb_head = NULL;
934 sc->tx_queued--;
935 }
937 }
936 if (txp == sc->cbl_last)
937 break;
938 sc->tx_queued--;
938 }
939 sc->cbl_first = txp;
939 }
940 sc->cbl_first = txp;
940 ifp->if_timer = 0;
941 if (sc->tx_queued == 0) {
942 ifp->if_timer = 0;
943 if (sc->need_mcsetup)
944 fxp_mc_setup(sc);
945 }
941 /*
942 * Try to start more packets transmitting.
943 */
944 if (ifp->if_snd.ifq_head != NULL)
945 fxp_start(ifp);
946 }
947 /*
948 * Process receiver interrupts. If a no-resource (RNR)

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

1039 */
1040void
1041fxp_stats_update(arg)
1042 void *arg;
1043{
1044 struct fxp_softc *sc = arg;
1045 struct ifnet *ifp = &sc->sc_if;
1046 struct fxp_stats *sp = sc->fxp_stats;
946 /*
947 * Try to start more packets transmitting.
948 */
949 if (ifp->if_snd.ifq_head != NULL)
950 fxp_start(ifp);
951 }
952 /*
953 * Process receiver interrupts. If a no-resource (RNR)

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

1044 */
1045void
1046fxp_stats_update(arg)
1047 void *arg;
1048{
1049 struct fxp_softc *sc = arg;
1050 struct ifnet *ifp = &sc->sc_if;
1051 struct fxp_stats *sp = sc->fxp_stats;
1052 int s;
1047
1048 ifp->if_opackets += sp->tx_good;
1049 ifp->if_collisions += sp->tx_total_collisions;
1050 ifp->if_ipackets += sp->rx_good;
1053
1054 ifp->if_opackets += sp->tx_good;
1055 ifp->if_collisions += sp->tx_total_collisions;
1056 ifp->if_ipackets += sp->rx_good;
1057 if (sp->rx_good) {
1058 ifp->if_ipackets += sp->rx_good;
1059 sc->rx_idle_secs = 0;
1060 } else {
1061 sc->rx_idle_secs++;
1062 }
1051 ifp->if_ierrors +=
1052 sp->rx_crc_errors +
1053 sp->rx_alignment_errors +
1054 sp->rx_rnr_errors +
1055 sp->rx_overrun_errors;
1056 /*
1057 * If any transmit underruns occured, bump up the transmit
1058 * threshold by another 512 bytes (64 * 8).
1059 */
1060 if (sp->tx_underruns) {
1061 ifp->if_oerrors += sp->tx_underruns;
1062 if (tx_threshold < 192)
1063 tx_threshold += 64;
1064 }
1063 ifp->if_ierrors +=
1064 sp->rx_crc_errors +
1065 sp->rx_alignment_errors +
1066 sp->rx_rnr_errors +
1067 sp->rx_overrun_errors;
1068 /*
1069 * If any transmit underruns occured, bump up the transmit
1070 * threshold by another 512 bytes (64 * 8).
1071 */
1072 if (sp->tx_underruns) {
1073 ifp->if_oerrors += sp->tx_underruns;
1074 if (tx_threshold < 192)
1075 tx_threshold += 64;
1076 }
1077 s = splimp();
1065 /*
1078 /*
1079 * If we haven't received any packets in FXP_MAC_RX_IDLE seconds,
1080 * then assume the receiver has locked up and attempt to clear
1081 * the condition by reprogramming the multicast filter. This is
1082 * a work-around for a bug in the 82557 where the receiver locks
1083 * up if it gets certain types of garbage in the syncronization
1084 * bits prior to the packet header. This bug is supposed to only
1085 * occur in 10Mbps mode, but has been seen to occur in 100Mbps
1086 * mode as well (perhaps due to a 10/100 speed transition).
1087 */
1088 if (sc->rx_idle_secs > FXP_MAX_RX_IDLE) {
1089 sc->rx_idle_secs = 0;
1090 fxp_mc_setup(sc);
1091 }
1092 /*
1066 * If there is no pending command, start another stats
1067 * dump. Otherwise punt for now.
1068 */
1093 * If there is no pending command, start another stats
1094 * dump. Otherwise punt for now.
1095 */
1069 if ((CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) &
1070 FXP_SCB_COMMAND_MASK) == 0) {
1096 if (CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) == 0) {
1071 /*
1097 /*
1072 * Start another stats dump. By waiting for it to be
1073 * accepted, we avoid having to do splhigh locking when
1074 * writing scb_command in other parts of the driver.
1098 * Start another stats dump.
1075 */
1076 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND,
1077 FXP_SCB_COMMAND_CU_DUMPRESET);
1099 */
1100 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND,
1101 FXP_SCB_COMMAND_CU_DUMPRESET);
1078 fxp_scb_wait(sc);
1079 } else {
1080 /*
1081 * A previous command is still waiting to be accepted.
1082 * Just zero our copy of the stats and wait for the
1083 * next timer event to update them.
1084 */
1085 sp->tx_good = 0;
1086 sp->tx_underruns = 0;
1087 sp->tx_total_collisions = 0;
1088
1089 sp->rx_good = 0;
1090 sp->rx_crc_errors = 0;
1091 sp->rx_alignment_errors = 0;
1092 sp->rx_rnr_errors = 0;
1093 sp->rx_overrun_errors = 0;
1094 }
1102 } else {
1103 /*
1104 * A previous command is still waiting to be accepted.
1105 * Just zero our copy of the stats and wait for the
1106 * next timer event to update them.
1107 */
1108 sp->tx_good = 0;
1109 sp->tx_underruns = 0;
1110 sp->tx_total_collisions = 0;
1111
1112 sp->rx_good = 0;
1113 sp->rx_crc_errors = 0;
1114 sp->rx_alignment_errors = 0;
1115 sp->rx_rnr_errors = 0;
1116 sp->rx_overrun_errors = 0;
1117 }
1118 splx(s);
1095 /*
1096 * Schedule another timeout one second from now.
1097 */
1119 /*
1120 * Schedule another timeout one second from now.
1121 */
1098 timeout(fxp_stats_update, sc, hz);
1122 sc->stat_ch = timeout(fxp_stats_update, sc, hz);
1099}
1100
1101/*
1102 * Stop the interface. Cancels the statistics updater and resets
1103 * the interface.
1104 */
1105static void
1106fxp_stop(sc)

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

1160 * card has wedged for some reason.
1161 */
1162static void
1163fxp_watchdog(ifp)
1164 struct ifnet *ifp;
1165{
1166 struct fxp_softc *sc = ifp->if_softc;
1167
1123}
1124
1125/*
1126 * Stop the interface. Cancels the statistics updater and resets
1127 * the interface.
1128 */
1129static void
1130fxp_stop(sc)

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

1184 * card has wedged for some reason.
1185 */
1186static void
1187fxp_watchdog(ifp)
1188 struct ifnet *ifp;
1189{
1190 struct fxp_softc *sc = ifp->if_softc;
1191
1168 log(LOG_ERR, FXP_FORMAT ": device timeout\n", FXP_ARGS(sc));
1192 printf(FXP_FORMAT ": device timeout\n", FXP_ARGS(sc));
1169 ifp->if_oerrors++;
1170
1171 fxp_init(sc);
1172}
1173
1174static void
1175fxp_init(xsc)
1176 void *xsc;
1177{
1178 struct fxp_softc *sc = xsc;
1179 struct ifnet *ifp = &sc->sc_if;
1180 struct fxp_cb_config *cbp;
1181 struct fxp_cb_ias *cb_ias;
1182 struct fxp_cb_tx *txp;
1193 ifp->if_oerrors++;
1194
1195 fxp_init(sc);
1196}
1197
1198static void
1199fxp_init(xsc)
1200 void *xsc;
1201{
1202 struct fxp_softc *sc = xsc;
1203 struct ifnet *ifp = &sc->sc_if;
1204 struct fxp_cb_config *cbp;
1205 struct fxp_cb_ias *cb_ias;
1206 struct fxp_cb_tx *txp;
1183 int i, s, mcast, prm;
1207 int i, s, prm;
1184
1185 s = splimp();
1186 /*
1187 * Cancel any pending I/O
1188 */
1189 fxp_stop(sc);
1190
1191 prm = (ifp->if_flags & IFF_PROMISC) ? 1 : 0;
1192 sc->promisc_mode = prm;
1208
1209 s = splimp();
1210 /*
1211 * Cancel any pending I/O
1212 */
1213 fxp_stop(sc);
1214
1215 prm = (ifp->if_flags & IFF_PROMISC) ? 1 : 0;
1216 sc->promisc_mode = prm;
1193 /*
1194 * Sleeze out here and enable reception of all multicasts if
1195 * multicasts are enabled. Ideally, we'd program the multicast
1196 * address filter to only accept specific multicasts.
1197 */
1198 mcast = (ifp->if_flags & (IFF_MULTICAST|IFF_ALLMULTI)) ? 1 : 0;
1199
1200 /*
1201 * Initialize base of CBL and RFA memory. Loading with zero
1202 * sets it up for regular linear addressing.
1203 */
1204 CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, 0);
1205 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_BASE);
1206

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

1221 */
1222 cbp = (struct fxp_cb_config *) sc->cbl_base;
1223
1224 /*
1225 * This bcopy is kind of disgusting, but there are a bunch of must be
1226 * zero and must be one bits in this structure and this is the easiest
1227 * way to initialize them all to proper values.
1228 */
1217
1218 /*
1219 * Initialize base of CBL and RFA memory. Loading with zero
1220 * sets it up for regular linear addressing.
1221 */
1222 CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, 0);
1223 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_BASE);
1224

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

1239 */
1240 cbp = (struct fxp_cb_config *) sc->cbl_base;
1241
1242 /*
1243 * This bcopy is kind of disgusting, but there are a bunch of must be
1244 * zero and must be one bits in this structure and this is the easiest
1245 * way to initialize them all to proper values.
1246 */
1229 bcopy(fxp_cb_config_template, cbp, sizeof(struct fxp_cb_config));
1247 bcopy(fxp_cb_config_template, (void *)&cbp->cb_status,
1248 sizeof(fxp_cb_config_template));
1230
1231 cbp->cb_status = 0;
1232 cbp->cb_command = FXP_CB_COMMAND_CONFIG | FXP_CB_COMMAND_EL;
1233 cbp->link_addr = -1; /* (no) next command */
1234 cbp->byte_count = 22; /* (22) bytes to config */
1235 cbp->rx_fifo_limit = 8; /* rx fifo threshold (32 bytes) */
1236 cbp->tx_fifo_limit = 0; /* tx fifo threshold (0 bytes) */
1237 cbp->adaptive_ifs = 0; /* (no) adaptive interframe spacing */

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

1255 cbp->bcast_disable = 0; /* (don't) disable broadcasts */
1256 cbp->crscdt = 0; /* (CRS only) */
1257 cbp->stripping = !prm; /* truncate rx packet to byte count */
1258 cbp->padding = 1; /* (do) pad short tx packets */
1259 cbp->rcv_crc_xfer = 0; /* (don't) xfer CRC to host */
1260 cbp->force_fdx = 0; /* (don't) force full duplex */
1261 cbp->fdx_pin_en = 1; /* (enable) FDX# pin */
1262 cbp->multi_ia = 0; /* (don't) accept multiple IAs */
1249
1250 cbp->cb_status = 0;
1251 cbp->cb_command = FXP_CB_COMMAND_CONFIG | FXP_CB_COMMAND_EL;
1252 cbp->link_addr = -1; /* (no) next command */
1253 cbp->byte_count = 22; /* (22) bytes to config */
1254 cbp->rx_fifo_limit = 8; /* rx fifo threshold (32 bytes) */
1255 cbp->tx_fifo_limit = 0; /* tx fifo threshold (0 bytes) */
1256 cbp->adaptive_ifs = 0; /* (no) adaptive interframe spacing */

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

1274 cbp->bcast_disable = 0; /* (don't) disable broadcasts */
1275 cbp->crscdt = 0; /* (CRS only) */
1276 cbp->stripping = !prm; /* truncate rx packet to byte count */
1277 cbp->padding = 1; /* (do) pad short tx packets */
1278 cbp->rcv_crc_xfer = 0; /* (don't) xfer CRC to host */
1279 cbp->force_fdx = 0; /* (don't) force full duplex */
1280 cbp->fdx_pin_en = 1; /* (enable) FDX# pin */
1281 cbp->multi_ia = 0; /* (don't) accept multiple IAs */
1263 cbp->mc_all = mcast; /* accept all multicasts */
1282 cbp->mc_all = sc->all_mcasts;/* accept all multicasts */
1264
1265 /*
1266 * Start the config command/DMA.
1267 */
1268 fxp_scb_wait(sc);
1283
1284 /*
1285 * Start the config command/DMA.
1286 */
1287 fxp_scb_wait(sc);
1269 CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, vtophys(cbp));
1288 CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, vtophys(&cbp->cb_status));
1270 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
1271 /* ...and wait for it to complete. */
1272 while (!(cbp->cb_status & FXP_CB_STATUS_C));
1273
1274 /*
1275 * Now initialize the station address. Temporarily use the TxCB
1276 * memory area like we did above for the config CB.
1277 */

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

1298 * Initialize transmit control block (TxCB) list.
1299 */
1300
1301 txp = sc->cbl_base;
1302 bzero(txp, sizeof(struct fxp_cb_tx) * FXP_NTXCB);
1303 for (i = 0; i < FXP_NTXCB; i++) {
1304 txp[i].cb_status = FXP_CB_STATUS_C | FXP_CB_STATUS_OK;
1305 txp[i].cb_command = FXP_CB_COMMAND_NOP;
1289 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
1290 /* ...and wait for it to complete. */
1291 while (!(cbp->cb_status & FXP_CB_STATUS_C));
1292
1293 /*
1294 * Now initialize the station address. Temporarily use the TxCB
1295 * memory area like we did above for the config CB.
1296 */

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

1317 * Initialize transmit control block (TxCB) list.
1318 */
1319
1320 txp = sc->cbl_base;
1321 bzero(txp, sizeof(struct fxp_cb_tx) * FXP_NTXCB);
1322 for (i = 0; i < FXP_NTXCB; i++) {
1323 txp[i].cb_status = FXP_CB_STATUS_C | FXP_CB_STATUS_OK;
1324 txp[i].cb_command = FXP_CB_COMMAND_NOP;
1306 txp[i].link_addr = vtophys(&txp[(i + 1) & FXP_TXCB_MASK]);
1325 txp[i].link_addr = vtophys(&txp[(i + 1) & FXP_TXCB_MASK].cb_status);
1307 txp[i].tbd_array_addr = vtophys(&txp[i].tbd[0]);
1308 txp[i].next = &txp[(i + 1) & FXP_TXCB_MASK];
1309 }
1310 /*
1326 txp[i].tbd_array_addr = vtophys(&txp[i].tbd[0]);
1327 txp[i].next = &txp[(i + 1) & FXP_TXCB_MASK];
1328 }
1329 /*
1311 * Set the stop flag on the first TxCB and start the control
1330 * Set the suspend flag on the first TxCB and start the control
1312 * unit. It will execute the NOP and then suspend.
1313 */
1314 txp->cb_command = FXP_CB_COMMAND_NOP | FXP_CB_COMMAND_S;
1315 sc->cbl_first = sc->cbl_last = txp;
1331 * unit. It will execute the NOP and then suspend.
1332 */
1333 txp->cb_command = FXP_CB_COMMAND_NOP | FXP_CB_COMMAND_S;
1334 sc->cbl_first = sc->cbl_last = txp;
1316 sc->tx_queued = 0;
1335 sc->tx_queued = 1;
1317
1318 fxp_scb_wait(sc);
1319 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
1320
1321 /*
1322 * Initialize receiver buffer area - RFA.
1323 */
1324 fxp_scb_wait(sc);

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

1587#if !defined(__NetBSD__)
1588 case SIOCGIFADDR:
1589 case SIOCSIFMTU:
1590#endif
1591 error = ether_ioctl(ifp, command, data);
1592 break;
1593
1594 case SIOCSIFFLAGS:
1336
1337 fxp_scb_wait(sc);
1338 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
1339
1340 /*
1341 * Initialize receiver buffer area - RFA.
1342 */
1343 fxp_scb_wait(sc);

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

1606#if !defined(__NetBSD__)
1607 case SIOCGIFADDR:
1608 case SIOCSIFMTU:
1609#endif
1610 error = ether_ioctl(ifp, command, data);
1611 break;
1612
1613 case SIOCSIFFLAGS:
1614 sc->all_mcasts = (ifp->if_flags & IFF_ALLMULTI) ? 1 : 0;
1595
1596 /*
1597 * If interface is marked up and not running, then start it.
1598 * If it is marked down and running, stop it.
1599 * XXX If it's up then re-initialize it. This is so flags
1600 * such as IFF_PROMISC are handled.
1601 */
1602 if (ifp->if_flags & IFF_UP) {
1603 fxp_init(sc);
1604 } else {
1605 if (ifp->if_flags & IFF_RUNNING)
1606 fxp_stop(sc);
1607 }
1608 break;
1609
1610 case SIOCADDMULTI:
1611 case SIOCDELMULTI:
1615
1616 /*
1617 * If interface is marked up and not running, then start it.
1618 * If it is marked down and running, stop it.
1619 * XXX If it's up then re-initialize it. This is so flags
1620 * such as IFF_PROMISC are handled.
1621 */
1622 if (ifp->if_flags & IFF_UP) {
1623 fxp_init(sc);
1624 } else {
1625 if (ifp->if_flags & IFF_RUNNING)
1626 fxp_stop(sc);
1627 }
1628 break;
1629
1630 case SIOCADDMULTI:
1631 case SIOCDELMULTI:
1632 sc->all_mcasts = (ifp->if_flags & IFF_ALLMULTI) ? 1 : 0;
1612#if defined(__NetBSD__)
1613 {
1614 struct ifreq *ifr = (struct ifreq *) data;
1615
1616 error = (command == SIOCADDMULTI) ?
1617 ether_addmulti(ifr, &sc->sc_ethercom) :
1618 ether_delmulti(ifr, &sc->sc_ethercom);
1619
1620 if (error == ENETRESET) {
1621 /*
1622 * Multicast list has changed; set the hardware
1623 * filter accordingly.
1624 */
1633#if defined(__NetBSD__)
1634 {
1635 struct ifreq *ifr = (struct ifreq *) data;
1636
1637 error = (command == SIOCADDMULTI) ?
1638 ether_addmulti(ifr, &sc->sc_ethercom) :
1639 ether_delmulti(ifr, &sc->sc_ethercom);
1640
1641 if (error == ENETRESET) {
1642 /*
1643 * Multicast list has changed; set the hardware
1644 * filter accordingly.
1645 */
1625 fxp_init(sc);
1646 if (!sc->all_mcasts)
1647 fxp_mc_setup(sc);
1648 /*
1649 * fxp_mc_setup() can turn on all_mcasts if we run
1650 * out of space, so check it again rather than else {}.
1651 */
1652 if (sc->all_mcasts)
1653 fxp_init(sc);
1626 error = 0;
1627 }
1628 }
1629#else /* __FreeBSD__ */
1630 /*
1631 * Multicast list has changed; set the hardware filter
1632 * accordingly.
1633 */
1654 error = 0;
1655 }
1656 }
1657#else /* __FreeBSD__ */
1658 /*
1659 * Multicast list has changed; set the hardware filter
1660 * accordingly.
1661 */
1634 fxp_init(sc);
1662 if (!sc->all_mcasts)
1663 fxp_mc_setup(sc);
1664 /*
1665 * fxp_mc_setup() can turn on sc->all_mcasts, so check it
1666 * again rather than else {}.
1667 */
1668 if (sc->all_mcasts)
1669 fxp_init(sc);
1635 error = 0;
1636#endif /* __NetBSD__ */
1637 break;
1638
1639 case SIOCSIFMEDIA:
1640 case SIOCGIFMEDIA:
1641 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, command);
1642 break;
1643
1644 default:
1645 error = EINVAL;
1646 }
1647 (void) splx(s);
1648 return (error);
1649}
1670 error = 0;
1671#endif /* __NetBSD__ */
1672 break;
1673
1674 case SIOCSIFMEDIA:
1675 case SIOCGIFMEDIA:
1676 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, command);
1677 break;
1678
1679 default:
1680 error = EINVAL;
1681 }
1682 (void) splx(s);
1683 return (error);
1684}
1685
1686/*
1687 * Program the multicast filter.
1688 *
1689 * We have an artificial restriction that the multicast setup command
1690 * must be the first command in the chain, so we take steps to ensure
1691 * that. By requiring this, it allows us to keep the performance of
1692 * the pre-initialized command ring (esp. link pointers) by not actually
1693 * inserting the mcsetup command in the ring - i.e. it's link pointer
1694 * points to the TxCB ring, but the mcsetup descriptor itself is not part
1695 * of it. We then can do 'CU_START' on the mcsetup descriptor and have it
1696 * lead into the regular TxCB ring when it completes.
1697 *
1698 * This function must be called at splimp.
1699 */
1700static void
1701fxp_mc_setup(sc)
1702 struct fxp_softc *sc;
1703{
1704 struct fxp_cb_mcs *mcsp = sc->mcsp;
1705 struct ifnet *ifp = &sc->sc_if;
1706 struct ifmultiaddr *ifma;
1707 int nmcasts;
1708
1709 if (sc->tx_queued) {
1710 sc->need_mcsetup = 1;
1711 return;
1712 }
1713 sc->need_mcsetup = 0;
1714
1715 /*
1716 * Initialize multicast setup descriptor.
1717 */
1718 mcsp->next = sc->cbl_base;
1719 mcsp->mb_head = NULL;
1720 mcsp->cb_status = 0;
1721 mcsp->cb_command = FXP_CB_COMMAND_MCAS | FXP_CB_COMMAND_S;
1722 mcsp->link_addr = vtophys(&sc->cbl_base->cb_status);
1723
1724 nmcasts = 0;
1725 if (!sc->all_mcasts) {
1726 for (ifma = ifp->if_multiaddrs.lh_first; ifma != NULL;
1727 ifma = ifma->ifma_link.le_next) {
1728 if (ifma->ifma_addr->sa_family != AF_LINK)
1729 continue;
1730 if (nmcasts >= MAXMCADDR) {
1731 sc->all_mcasts = 1;
1732 nmcasts = 0;
1733 break;
1734 }
1735 bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr),
1736 (void *) &sc->mcsp->mc_addr[nmcasts][0], 6);
1737 nmcasts++;
1738 }
1739 }
1740 mcsp->mc_cnt = nmcasts * 6;
1741 sc->cbl_first = sc->cbl_last = (struct fxp_cb_tx *) mcsp;
1742 sc->tx_queued = 1;
1743
1744 /*
1745 * Wait until command unit is not active. This should never
1746 * be the case when nothing is queued, but make sure anyway.
1747 */
1748 while ((CSR_READ_1(sc, FXP_CSR_SCB_RUSCUS) >> 6) ==
1749 FXP_SCB_CUS_ACTIVE) ;
1750
1751 /*
1752 * Start the multicast setup command.
1753 */
1754 fxp_scb_wait(sc);
1755 CSR_WRITE_4(sc, FXP_CSR_SCB_GENERAL, vtophys(&mcsp->cb_status));
1756 CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_START);
1757
1758 ifp->if_timer = 5;
1759 return;
1760}