Sync w/ FreeBSD-current-980122:
- Rewrite fxp_start() for better clarity and efficiency. - Remove unused #includes.
This commit is contained in:
parent
a1de770ebd
commit
0916ab379b
@ -1,4 +1,4 @@
|
|||||||
/* $NetBSD: if_fxp.c,v 1.8 1998/01/22 08:04:56 thorpej Exp $ */
|
/* $NetBSD: if_fxp.c,v 1.9 1998/01/22 08:31:33 thorpej Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 1995, David Greenman
|
* Copyright (c) 1995, David Greenman
|
||||||
@ -29,7 +29,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* Id: if_fxp.c,v 1.44 1997/10/17 06:27:44 davidg Exp
|
* Id: if_fxp.c,v 1.47 1998/01/08 23:42:29 eivind Exp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -37,6 +37,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "bpfilter.h"
|
#include "bpfilter.h"
|
||||||
|
#if !defined(__NetBSD__)
|
||||||
|
#include "opt_inet.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/systm.h>
|
#include <sys/systm.h>
|
||||||
@ -44,7 +47,6 @@
|
|||||||
#include <sys/malloc.h>
|
#include <sys/malloc.h>
|
||||||
#include <sys/kernel.h>
|
#include <sys/kernel.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/syslog.h>
|
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <net/if_dl.h>
|
#include <net/if_dl.h>
|
||||||
@ -96,7 +98,12 @@
|
|||||||
|
|
||||||
#include <sys/sockio.h>
|
#include <sys/sockio.h>
|
||||||
|
|
||||||
|
#include <net/ethernet.h>
|
||||||
|
#include <net/if_arp.h>
|
||||||
|
|
||||||
|
#ifdef INET
|
||||||
#include <netinet/if_ether.h>
|
#include <netinet/if_ether.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <vm/vm.h> /* for vtophys */
|
#include <vm/vm.h> /* for vtophys */
|
||||||
#include <vm/pmap.h> /* for vtophys */
|
#include <vm/pmap.h> /* for vtophys */
|
||||||
@ -420,6 +427,10 @@ fxp_attach(parent, self, aux)
|
|||||||
* Attach the interface.
|
* Attach the interface.
|
||||||
*/
|
*/
|
||||||
if_attach(ifp);
|
if_attach(ifp);
|
||||||
|
/*
|
||||||
|
* Let the system queue as many packets as we have TX descriptors.
|
||||||
|
*/
|
||||||
|
ifp->if_snd.ifq_maxlen = FXP_NTXCB;
|
||||||
ether_ifattach(ifp, enaddr);
|
ether_ifattach(ifp, enaddr);
|
||||||
#if NBPFILTER > 0
|
#if NBPFILTER > 0
|
||||||
bpfattach(&sc->sc_ethercom.ec_if.if_bpf, ifp, DLT_EN10MB,
|
bpfattach(&sc->sc_ethercom.ec_if.if_bpf, ifp, DLT_EN10MB,
|
||||||
@ -588,6 +599,10 @@ fxp_attach(config_id, unit)
|
|||||||
* Attach the interface.
|
* Attach the interface.
|
||||||
*/
|
*/
|
||||||
if_attach(ifp);
|
if_attach(ifp);
|
||||||
|
/*
|
||||||
|
* Let the system queue as many packets as we have TX descriptors.
|
||||||
|
*/
|
||||||
|
ifp->if_snd.ifq_maxlen = FXP_NTXCB;
|
||||||
ether_ifattach(ifp);
|
ether_ifattach(ifp);
|
||||||
#if NBPFILTER > 0
|
#if NBPFILTER > 0
|
||||||
bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
|
bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
|
||||||
@ -803,133 +818,126 @@ fxp_start(ifp)
|
|||||||
{
|
{
|
||||||
struct fxp_softc *sc = ifp->if_softc;
|
struct fxp_softc *sc = ifp->if_softc;
|
||||||
struct fxp_cb_tx *txp;
|
struct fxp_cb_tx *txp;
|
||||||
struct mbuf *m, *mb_head;
|
|
||||||
int segment, first = 1;
|
|
||||||
|
|
||||||
txloop:
|
|
||||||
/*
|
/*
|
||||||
* See if we're all filled up with buffers to transmit, or
|
* See if we need to suspend xmit until the multicast filter
|
||||||
* if we need to suspend xmit until the multicast filter
|
* has been reprogrammed (which can only be done at the head
|
||||||
* has been reprogrammed (which can only be done at the
|
* of the command chain).
|
||||||
* head of the command chain).
|
|
||||||
*/
|
*/
|
||||||
if (sc->tx_queued >= FXP_NTXCB || sc->need_mcsetup)
|
if (sc->need_mcsetup)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
txp = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Grab a packet to transmit.
|
* We're finished if there is nothing more to add to the list or if
|
||||||
|
* we're all filled up with buffers to transmit.
|
||||||
*/
|
*/
|
||||||
IF_DEQUEUE(&ifp->if_snd, mb_head);
|
while (ifp->if_snd.ifq_head != NULL && sc->tx_queued < FXP_NTXCB) {
|
||||||
if (mb_head == NULL) {
|
struct mbuf *m, *mb_head;
|
||||||
|
int segment;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No more packets to send.
|
* Grab a packet to transmit.
|
||||||
*/
|
*/
|
||||||
return;
|
IF_DEQUEUE(&ifp->if_snd, mb_head);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get pointer to next available (unused) descriptor.
|
* Get pointer to next available tx desc.
|
||||||
*/
|
*/
|
||||||
txp = sc->cbl_last->next;
|
txp = sc->cbl_last->next;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Go through each of the mbufs in the chain and initialize
|
* Go through each of the mbufs in the chain and initialize
|
||||||
* the transmit buffers descriptors with the physical address
|
* the transmit buffer descriptors with the physical address
|
||||||
* and size of the mbuf.
|
* and size of the mbuf.
|
||||||
*/
|
*/
|
||||||
tbdinit:
|
tbdinit:
|
||||||
for (m = mb_head, segment = 0; m != NULL; m = m->m_next) {
|
for (m = mb_head, segment = 0; m != NULL; m = m->m_next) {
|
||||||
if (m->m_len != 0) {
|
if (m->m_len != 0) {
|
||||||
if (segment == FXP_NTXSEG)
|
if (segment == FXP_NTXSEG)
|
||||||
break;
|
break;
|
||||||
txp->tbd[segment].tb_addr =
|
txp->tbd[segment].tb_addr =
|
||||||
vtophys(mtod(m, vm_offset_t));
|
vtophys(mtod(m, vm_offset_t));
|
||||||
txp->tbd[segment].tb_size = m->m_len;
|
txp->tbd[segment].tb_size = m->m_len;
|
||||||
segment++;
|
segment++;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m != NULL) {
|
|
||||||
struct mbuf *mn;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We ran out of segments. We have to recopy this mbuf
|
|
||||||
* chain first.
|
|
||||||
*/
|
|
||||||
MGETHDR(mn, M_DONTWAIT, MT_DATA);
|
|
||||||
if (mn == NULL) {
|
|
||||||
m_freem(mb_head);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mb_head->m_pkthdr.len > MHLEN) {
|
|
||||||
MCLGET(mn, M_DONTWAIT);
|
|
||||||
if ((mn->m_flags & M_EXT) == 0) {
|
|
||||||
m_freem(mn);
|
|
||||||
m_freem(mb_head);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_copydata(mb_head, 0, mb_head->m_pkthdr.len,
|
if (m != NULL) {
|
||||||
mtod(mn, caddr_t));
|
struct mbuf *mn;
|
||||||
mn->m_pkthdr.len = mn->m_len = mb_head->m_pkthdr.len;
|
|
||||||
m_freem(mb_head);
|
|
||||||
mb_head = mn;
|
|
||||||
goto tbdinit;
|
|
||||||
}
|
|
||||||
|
|
||||||
txp->tbd_number = segment;
|
/*
|
||||||
txp->mb_head = mb_head;
|
* We ran out of segments. We have to recopy this mbuf
|
||||||
|
* chain first. Bail out if we can't get the new
|
||||||
|
* buffers.
|
||||||
|
*/
|
||||||
|
MGETHDR(mn, M_DONTWAIT, MT_DATA);
|
||||||
|
if (mn == NULL) {
|
||||||
|
m_freem(mb_head);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (mb_head->m_pkthdr.len > MHLEN) {
|
||||||
|
MCLGET(mn, M_DONTWAIT);
|
||||||
|
if ((mn->m_flags & M_EXT) == 0) {
|
||||||
|
m_freem(mn);
|
||||||
|
m_freem(mb_head);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_copydata(mb_head, 0, mb_head->m_pkthdr.len,
|
||||||
|
mtod(mn, caddr_t));
|
||||||
|
mn->m_pkthdr.len = mn->m_len = mb_head->m_pkthdr.len;
|
||||||
|
m_freem(mb_head);
|
||||||
|
mb_head = mn;
|
||||||
|
goto tbdinit;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
txp->tbd_number = segment;
|
||||||
* Finish the initialization of this TxCB.
|
txp->mb_head = mb_head;
|
||||||
*/
|
txp->cb_status = 0;
|
||||||
txp->cb_status = 0;
|
txp->cb_command =
|
||||||
txp->cb_command =
|
FXP_CB_COMMAND_XMIT | FXP_CB_COMMAND_SF | FXP_CB_COMMAND_S;
|
||||||
FXP_CB_COMMAND_XMIT | FXP_CB_COMMAND_SF | FXP_CB_COMMAND_S;
|
txp->tx_threshold = tx_threshold;
|
||||||
txp->tx_threshold = tx_threshold;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Advance the end-of-list forward.
|
* Advance the end of list forward.
|
||||||
*/
|
*/
|
||||||
sc->cbl_last->cb_command &= ~FXP_CB_COMMAND_S;
|
sc->cbl_last->cb_command &= ~FXP_CB_COMMAND_S;
|
||||||
sc->cbl_last = txp;
|
sc->cbl_last = txp;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Advance the beginning of the list forward if there are
|
* Advance the beginning of the list forward if there are
|
||||||
* no other packets queued (when nothing is queued, cbl_first
|
* no other packets queued (when nothing is queued, cbl_first
|
||||||
* sits on the last TxCB that was sent out)..
|
* sits on the last TxCB that was sent out).
|
||||||
*/
|
*/
|
||||||
if (sc->tx_queued == 0)
|
if (sc->tx_queued == 0)
|
||||||
sc->cbl_first = txp;
|
sc->cbl_first = txp;
|
||||||
|
|
||||||
sc->tx_queued++;
|
sc->tx_queued++;
|
||||||
|
|
||||||
/*
|
|
||||||
* Only need to wait prior to the first resume command.
|
|
||||||
*/
|
|
||||||
if (first) {
|
|
||||||
first--;
|
|
||||||
fxp_scb_wait(sc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Resume transmission if suspended.
|
|
||||||
*/
|
|
||||||
CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_RESUME);
|
|
||||||
|
|
||||||
#if NBPFILTER > 0
|
#if NBPFILTER > 0
|
||||||
/*
|
/*
|
||||||
* Pass packet to bpf if there is a listener.
|
* Pass packet to bpf if there is a listener.
|
||||||
*/
|
*/
|
||||||
if (ifp->if_bpf)
|
if (ifp->if_bpf)
|
||||||
bpf_mtap(FXP_BPFTAP_ARG(ifp), mb_head);
|
bpf_mtap(FXP_BPFTAP_ARG(ifp), mb_head);
|
||||||
#endif
|
#endif
|
||||||
/*
|
}
|
||||||
* Set a 5 second timer just in case we don't hear from the
|
|
||||||
* card again.
|
|
||||||
*/
|
|
||||||
ifp->if_timer = 5;
|
|
||||||
|
|
||||||
goto txloop;
|
/*
|
||||||
|
* We're finished. If we added to the list, issue a RESUME to get DMA
|
||||||
|
* going again if suspended.
|
||||||
|
*/
|
||||||
|
if (txp != NULL) {
|
||||||
|
fxp_scb_wait(sc);
|
||||||
|
CSR_WRITE_1(sc, FXP_CSR_SCB_COMMAND, FXP_SCB_COMMAND_CU_RESUME);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set a 5 second timer just in case we don't hear from the
|
||||||
|
* card again.
|
||||||
|
*/
|
||||||
|
ifp->if_timer = 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user