2002-10-02 08:55:47 +04:00
|
|
|
/* $NetBSD: if_qn.c,v 1.24 2002/10/02 04:55:51 thorpej Exp $ */
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Mika Kortelainen
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Mika Kortelainen
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* Thanks for Aspecs Oy (Finland) for the data book for the NIC used
|
|
|
|
* in this card and also many thanks for the Resource Management Force
|
|
|
|
* (QuickNet card manufacturer) and especially Daniel Koch for providing
|
|
|
|
* me with the necessary 'inside' information to write the driver.
|
|
|
|
*
|
|
|
|
* This is partly based on other code:
|
1995-11-30 03:56:23 +03:00
|
|
|
* - if_ed.c: basic function structure for Ethernet driver and now also
|
|
|
|
* qn_put() is done similarly, i.e. no extra packet buffers.
|
1995-10-07 21:04:27 +03:00
|
|
|
*
|
|
|
|
* Device driver for National Semiconductor DS8390/WD83C690 based ethernet
|
|
|
|
* adapters.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, David Greenman. This software may be used,
|
|
|
|
* modified, copied, distributed, and sold, in both source and binary
|
|
|
|
* form provided that the above copyright and these terms are retained.
|
|
|
|
* Under no circumstances is the author responsible for the proper
|
|
|
|
* functioning of this software, nor does the author assume any
|
|
|
|
* responsibility for damages incurred with its use.
|
|
|
|
*
|
|
|
|
* - if_es.c: used as an example of -current driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 1995 Michael L. Hitch
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1995-11-30 03:56:23 +03:00
|
|
|
* - if_fe.c: some ideas for error handling for qn_rint() which might
|
|
|
|
* have fixed those random lock ups, too.
|
|
|
|
*
|
|
|
|
* All Rights Reserved, Copyright (C) Fujitsu Limited 1995
|
|
|
|
*
|
1995-10-07 21:04:27 +03:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* - add multicast support
|
|
|
|
*/
|
|
|
|
|
2002-01-28 12:56:43 +03:00
|
|
|
#include <sys/cdefs.h>
|
2002-10-02 08:55:47 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: if_qn.c,v 1.24 2002/10/02 04:55:51 thorpej Exp $");
|
2002-01-28 12:56:43 +03:00
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
#include "qn.h"
|
|
|
|
#if NQN > 0
|
|
|
|
|
|
|
|
#define QN_DEBUG
|
1995-11-30 03:56:23 +03:00
|
|
|
#define QN_DEBUG1_no /* hides some old tests */
|
1996-06-19 00:50:00 +04:00
|
|
|
#define QN_CHECKS_no /* adds some checks (not needed in normal situations) */
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
/*
|
1995-11-30 03:56:23 +03:00
|
|
|
* Fujitsu MB86950 Ethernet Controller (as used in the QuickNet QN2000
|
|
|
|
* Ethernet card)
|
1995-10-07 21:04:27 +03:00
|
|
|
*/
|
|
|
|
|
1998-07-05 04:51:04 +04:00
|
|
|
#include "opt_inet.h"
|
1998-07-05 10:49:00 +04:00
|
|
|
#include "opt_ns.h"
|
1998-07-05 04:51:04 +04:00
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
1997-03-17 21:04:40 +03:00
|
|
|
#include <net/if_dl.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/mtpr.h>
|
|
|
|
#include <amiga/amiga/device.h>
|
|
|
|
#include <amiga/amiga/isr.h>
|
|
|
|
#include <amiga/dev/zbusvar.h>
|
|
|
|
#include <amiga/dev/if_qnreg.h>
|
|
|
|
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
#define NIC_R_MASK (R_INT_PKT_RDY | R_INT_ALG_ERR |\
|
|
|
|
R_INT_CRC_ERR | R_INT_OVR_FLO)
|
|
|
|
#define MAX_PACKETS 30 /* max number of packets read per interrupt */
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet software status per interface
|
|
|
|
*
|
|
|
|
* Each interface is referenced by a network interface structure,
|
|
|
|
* qn_if, which the routing code uses to locate the interface.
|
|
|
|
* This structure contains the output queue for the interface, its address, ...
|
|
|
|
*/
|
|
|
|
struct qn_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct isr sc_isr;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ethercom sc_ethercom; /* Common ethernet structures */
|
1995-10-07 21:04:27 +03:00
|
|
|
u_char volatile *sc_base;
|
|
|
|
u_char volatile *sc_nic_base;
|
|
|
|
u_short volatile *nic_fifo;
|
|
|
|
u_short volatile *nic_r_status;
|
|
|
|
u_short volatile *nic_t_status;
|
|
|
|
u_short volatile *nic_r_mask;
|
|
|
|
u_short volatile *nic_t_mask;
|
|
|
|
u_short volatile *nic_r_mode;
|
|
|
|
u_short volatile *nic_t_mode;
|
|
|
|
u_short volatile *nic_reset;
|
|
|
|
u_short volatile *nic_len;
|
|
|
|
u_char transmit_pending;
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
caddr_t sc_bpf;
|
|
|
|
#endif
|
|
|
|
} qn_softc[NQN];
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2002-01-26 16:40:52 +03:00
|
|
|
int qnmatch(struct device *, struct cfdata *, void *);
|
|
|
|
void qnattach(struct device *, struct device *, void *);
|
|
|
|
int qnintr(void *);
|
|
|
|
int qnioctl(struct ifnet *, u_long, caddr_t);
|
|
|
|
void qnstart(struct ifnet *);
|
|
|
|
void qnwatchdog(struct ifnet *);
|
|
|
|
void qnreset(struct qn_softc *);
|
|
|
|
void qninit(struct qn_softc *);
|
|
|
|
void qnstop(struct qn_softc *);
|
|
|
|
static u_short qn_put(u_short volatile *, struct mbuf *);
|
|
|
|
static void qn_rint(struct qn_softc *, u_short);
|
|
|
|
static void qn_flush(struct qn_softc *);
|
|
|
|
static void inline word_copy_from_card(u_short volatile *, u_short *, u_short);
|
|
|
|
static void inline word_copy_to_card(u_short *, u_short volatile *,
|
|
|
|
register u_short);
|
|
|
|
static void qn_get_packet(struct qn_softc *, u_short);
|
1995-11-30 03:56:23 +03:00
|
|
|
#ifdef QN_DEBUG1
|
2002-01-26 16:40:52 +03:00
|
|
|
static void qn_dump(struct qn_softc *);
|
1995-11-30 03:56:23 +03:00
|
|
|
#endif
|
1995-10-07 21:04:27 +03:00
|
|
|
|
2002-10-02 08:55:47 +04:00
|
|
|
CFATTACH_DECL(qn, sizeof(struct qn_softc),
|
|
|
|
qnmatch, qnattach, NULL, NULL);
|
1996-03-17 04:16:48 +03:00
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
qnmatch(struct device *parent, struct cfdata *cfp, void *aux)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
|
|
|
struct zbus_args *zap;
|
|
|
|
|
|
|
|
zap = (struct zbus_args *)aux;
|
|
|
|
|
|
|
|
/* RMF QuickNet QN2000 EtherNet card */
|
|
|
|
if (zap->manid == 2011 && zap->prodid == 2)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interface exists: make available by filling in network interface
|
|
|
|
* record. System will initialize the interface when it is ready
|
|
|
|
* to accept packets.
|
|
|
|
*/
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
qnattach(struct device *parent, struct device *self, void *aux)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
|
|
|
struct zbus_args *zap;
|
|
|
|
struct qn_softc *sc = (struct qn_softc *)self;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
|
|
|
u_int8_t myaddr[ETHER_ADDR_LEN];
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
zap = (struct zbus_args *)aux;
|
|
|
|
|
|
|
|
sc->sc_base = zap->va;
|
|
|
|
sc->sc_nic_base = sc->sc_base + QUICKNET_NIC_BASE;
|
|
|
|
sc->nic_fifo = (u_short volatile *)(sc->sc_nic_base + NIC_BMPR0);
|
|
|
|
sc->nic_len = (u_short volatile *)(sc->sc_nic_base + NIC_BMPR2);
|
|
|
|
sc->nic_t_status = (u_short volatile *)(sc->sc_nic_base + NIC_DLCR0);
|
|
|
|
sc->nic_r_status = (u_short volatile *)(sc->sc_nic_base + NIC_DLCR2);
|
|
|
|
sc->nic_t_mask = (u_short volatile *)(sc->sc_nic_base + NIC_DLCR1);
|
|
|
|
sc->nic_r_mask = (u_short volatile *)(sc->sc_nic_base + NIC_DLCR3);
|
|
|
|
sc->nic_t_mode = (u_short volatile *)(sc->sc_nic_base + NIC_DLCR4);
|
|
|
|
sc->nic_r_mode = (u_short volatile *)(sc->sc_nic_base + NIC_DLCR5);
|
|
|
|
sc->nic_reset = (u_short volatile *)(sc->sc_nic_base + NIC_DLCR6);
|
|
|
|
sc->transmit_pending = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The ethernet address of the board (1st three bytes are the vendor
|
|
|
|
* address, the rest is the serial number of the board).
|
|
|
|
*/
|
1997-03-15 21:09:08 +03:00
|
|
|
myaddr[0] = 0x5c;
|
|
|
|
myaddr[1] = 0x5c;
|
|
|
|
myaddr[2] = 0x00;
|
|
|
|
myaddr[3] = (zap->serno >> 16) & 0xff;
|
|
|
|
myaddr[4] = (zap->serno >> 8) & 0xff;
|
|
|
|
myaddr[5] = zap->serno & 0xff;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/* set interface to stopped condition (reset) */
|
|
|
|
qnstop(sc);
|
|
|
|
|
1996-05-07 04:46:37 +04:00
|
|
|
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
|
|
|
|
ifp->if_softc = sc;
|
1995-10-07 21:04:27 +03:00
|
|
|
ifp->if_ioctl = qnioctl;
|
|
|
|
ifp->if_watchdog = qnwatchdog;
|
|
|
|
ifp->if_start = qnstart;
|
|
|
|
/* XXX IFF_MULTICAST */
|
|
|
|
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS;
|
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
|
|
|
|
/* Attach the interface. */
|
|
|
|
if_attach(ifp);
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_ifattach(ifp, myaddr);
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
#ifdef QN_DEBUG
|
1997-03-15 21:09:08 +03:00
|
|
|
printf(": hardware address %s\n", ether_sprintf(myaddr));
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->sc_isr.isr_intr = qnintr;
|
|
|
|
sc->sc_isr.isr_arg = sc;
|
|
|
|
sc->sc_isr.isr_ipl = 2;
|
|
|
|
add_isr(&sc->sc_isr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize device
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
qninit(struct qn_softc *sc)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1995-10-07 21:04:27 +03:00
|
|
|
u_short i;
|
1998-04-17 21:38:14 +04:00
|
|
|
static int retry = 0;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
*sc->nic_r_mask = NIC_R_MASK;
|
|
|
|
*sc->nic_t_mode = NO_LOOPBACK;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
if (sc->sc_ethercom.ec_if.if_flags & IFF_PROMISC) {
|
1995-10-07 21:04:27 +03:00
|
|
|
*sc->nic_r_mode = PROMISCUOUS_MODE;
|
|
|
|
log(LOG_INFO, "qn: Promiscuous mode (not tested)\n");
|
|
|
|
} else
|
|
|
|
*sc->nic_r_mode = NORMAL_MODE;
|
|
|
|
|
|
|
|
/* Set physical ethernet address. */
|
|
|
|
for (i = 0; i < ETHER_ADDR_LEN; i++)
|
1995-11-30 03:56:23 +03:00
|
|
|
*((u_short volatile *)(sc->sc_nic_base+
|
|
|
|
QNET_HARDWARE_ADDRESS+2*i)) =
|
1997-03-15 21:09:08 +03:00
|
|
|
((((u_short)LLADDR(ifp->if_sadl)[i]) << 8) |
|
|
|
|
LLADDR(ifp->if_sadl)[i]);
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1995-11-30 03:56:23 +03:00
|
|
|
sc->transmit_pending = 0;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
qn_flush(sc);
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* QuickNet magic. Done ONLY once, otherwise a lockup occurs. */
|
|
|
|
if (retry == 0) {
|
|
|
|
*((u_short volatile *)(sc->sc_nic_base + QNET_MAGIC)) = 0;
|
|
|
|
retry = 1;
|
|
|
|
}
|
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
/* Enable data link controller. */
|
|
|
|
*sc->nic_reset = ENABLE_DLC;
|
|
|
|
|
|
|
|
/* Attempt to start output, if any. */
|
|
|
|
qnstart(ifp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device timeout/watchdog routine. Entered if the device neglects to
|
|
|
|
* generate an interrupt after a transmit has been started on it.
|
|
|
|
*/
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
qnwatchdog(struct ifnet *ifp)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1996-05-07 04:46:37 +04:00
|
|
|
struct qn_softc *sc = ifp->if_softc;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_INFO, "qn: device timeout (watchdog)\n");
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_oerrors;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
qnreset(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-11-30 03:56:23 +03:00
|
|
|
* Flush card's buffer RAM.
|
1995-10-07 21:04:27 +03:00
|
|
|
*/
|
|
|
|
static void
|
2002-01-26 16:40:52 +03:00
|
|
|
qn_flush(struct qn_softc *sc)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1995-11-30 03:56:23 +03:00
|
|
|
#if 1
|
1995-10-07 21:04:27 +03:00
|
|
|
/* Read data until bus read error (i.e. buffer empty). */
|
1995-11-30 03:56:23 +03:00
|
|
|
while (!(*sc->nic_r_status & R_BUS_RD_ERR))
|
1995-10-07 21:04:27 +03:00
|
|
|
(void)(*sc->nic_fifo);
|
1995-11-30 03:56:23 +03:00
|
|
|
#else
|
|
|
|
/* Read data twice to clear some internal pipelines. */
|
|
|
|
(void)(*sc->nic_fifo);
|
|
|
|
(void)(*sc->nic_fifo);
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Clear bus read error. */
|
|
|
|
*sc->nic_r_status = R_BUS_RD_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-11-30 03:56:23 +03:00
|
|
|
* Reset the interface.
|
1995-10-07 21:04:27 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
qnreset(struct qn_softc *sc)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1995-10-07 21:04:27 +03:00
|
|
|
qnstop(sc);
|
|
|
|
qninit(sc);
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-11-30 03:56:23 +03:00
|
|
|
* Take interface offline.
|
1995-10-07 21:04:27 +03:00
|
|
|
*/
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
qnstop(struct qn_softc *sc)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Stop the interface. */
|
1995-11-30 03:56:23 +03:00
|
|
|
*sc->nic_reset = DISABLE_DLC;
|
|
|
|
delay(200);
|
|
|
|
*sc->nic_t_status = CLEAR_T_ERR;
|
|
|
|
*sc->nic_t_mask = CLEAR_T_MASK;
|
|
|
|
*sc->nic_r_status = CLEAR_R_ERR;
|
|
|
|
*sc->nic_r_mask = CLEAR_R_MASK;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Turn DMA off */
|
|
|
|
*((u_short volatile *)(sc->sc_nic_base + NIC_BMPR4)) = 0;
|
|
|
|
|
|
|
|
/* Accept no packets. */
|
|
|
|
*sc->nic_r_mode = 0;
|
|
|
|
*sc->nic_t_mode = 0;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
qn_flush(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start output on interface. Get another datagram to send
|
|
|
|
* off the interface queue, and copy it to the
|
|
|
|
* interface before starting the output.
|
|
|
|
*
|
|
|
|
* This assumes that it is called inside a critical section...
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
2002-01-26 16:40:52 +03:00
|
|
|
qnstart(struct ifnet *ifp)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1996-05-07 04:46:37 +04:00
|
|
|
struct qn_softc *sc = ifp->if_softc;
|
1995-10-07 21:04:27 +03:00
|
|
|
struct mbuf *m;
|
|
|
|
u_short len;
|
1995-11-30 03:56:23 +03:00
|
|
|
int timout = 60000;
|
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
|
1995-10-07 21:04:27 +03:00
|
|
|
return;
|
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m);
|
1995-10-07 21:04:27 +03:00
|
|
|
if (m == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* If bpf is listening on this interface, let it
|
|
|
|
* see the packet before we commit it to the wire
|
|
|
|
*
|
|
|
|
* (can't give the copy in QuickNet card RAM to bpf, because
|
|
|
|
* that RAM is not visible to the host but is read from FIFO)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
if (sc->sc_bpf)
|
|
|
|
bpf_mtap(sc->sc_bpf, m);
|
|
|
|
#endif
|
|
|
|
len = qn_put(sc->nic_fifo, m);
|
1995-11-30 03:56:23 +03:00
|
|
|
m_freem(m);
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/*
|
1995-11-30 03:56:23 +03:00
|
|
|
* Really transmit the packet.
|
1995-10-07 21:04:27 +03:00
|
|
|
*/
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Set packet length (byte-swapped). */
|
1995-10-07 21:04:27 +03:00
|
|
|
len = ((len >> 8) & 0x0007) | TRANSMIT_START | ((len & 0x00ff) << 8);
|
|
|
|
*sc->nic_len = len;
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Wait for the packet to really leave. */
|
|
|
|
while (!(*sc->nic_t_status & T_TMT_OK) && --timout) {
|
|
|
|
if ((timout % 10000) == 0)
|
|
|
|
log(LOG_INFO, "qn: timout...\n");
|
|
|
|
}
|
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
if (timout == 0)
|
|
|
|
/* Maybe we should try to recover from this one? */
|
1995-11-30 03:56:23 +03:00
|
|
|
/* But now, let's just fall thru and hope the best... */
|
|
|
|
log(LOG_INFO, "qn: transmit timout (fatal?)\n");
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
sc->transmit_pending = 1;
|
|
|
|
*sc->nic_t_mask = INT_TMT_OK | INT_SIXTEEN_COL;
|
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
1995-10-07 21:04:27 +03:00
|
|
|
ifp->if_timer = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory copy, copies word at a time
|
|
|
|
*/
|
|
|
|
static void inline
|
2002-01-26 16:40:52 +03:00
|
|
|
word_copy_from_card(u_short volatile *card, u_short *b, u_short len)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
|
|
|
register u_short l = len/2;
|
|
|
|
|
|
|
|
while (l--)
|
|
|
|
*b++ = *card;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void inline
|
2002-01-26 16:40:52 +03:00
|
|
|
word_copy_to_card(u_short *a, u_short volatile *card, register u_short len)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1996-06-19 00:50:00 +04:00
|
|
|
/*register u_short l = len/2;*/
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1996-06-19 00:50:00 +04:00
|
|
|
while (len--)
|
1995-10-07 21:04:27 +03:00
|
|
|
*card = *a++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy packet from mbuf to the board memory
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static u_short
|
2002-01-26 16:40:52 +03:00
|
|
|
qn_put(u_short volatile *addr, struct mbuf *m)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1996-06-19 00:50:00 +04:00
|
|
|
u_short *data;
|
|
|
|
u_char savebyte[2];
|
|
|
|
int len, len1, wantbyte;
|
1995-11-30 03:56:23 +03:00
|
|
|
u_short totlen;
|
|
|
|
|
|
|
|
totlen = wantbyte = 0;
|
|
|
|
|
|
|
|
for (; m != NULL; m = m->m_next) {
|
1996-04-22 01:10:48 +04:00
|
|
|
data = mtod(m, u_short *);
|
1995-11-30 03:56:23 +03:00
|
|
|
len = m->m_len;
|
|
|
|
if (len > 0) {
|
1996-06-19 00:50:00 +04:00
|
|
|
totlen += len;
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Finish the last word. */
|
|
|
|
if (wantbyte) {
|
1996-06-19 00:50:00 +04:00
|
|
|
savebyte[1] = *((u_char *)data);
|
1995-11-30 03:56:23 +03:00
|
|
|
*addr = *((u_short *)savebyte);
|
1996-06-19 00:50:00 +04:00
|
|
|
((u_char *)data)++;
|
1995-11-30 03:56:23 +03:00
|
|
|
len--;
|
|
|
|
wantbyte = 0;
|
|
|
|
}
|
|
|
|
/* Output contiguous words. */
|
|
|
|
if (len > 1) {
|
1996-06-19 00:50:00 +04:00
|
|
|
len1 = len/2;
|
|
|
|
word_copy_to_card(data, addr, len1);
|
|
|
|
data += len1;
|
1995-11-30 03:56:23 +03:00
|
|
|
len &= 1;
|
|
|
|
}
|
|
|
|
/* Save last byte, if necessary. */
|
|
|
|
if (len == 1) {
|
1996-06-19 00:50:00 +04:00
|
|
|
savebyte[0] = *((u_char *)data);
|
1995-11-30 03:56:23 +03:00
|
|
|
wantbyte = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
if (wantbyte) {
|
|
|
|
savebyte[1] = 0;
|
|
|
|
*addr = *((u_short *)savebyte);
|
|
|
|
}
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1999-03-26 02:10:53 +03:00
|
|
|
if(totlen < (ETHER_MIN_LEN - ETHER_CRC_LEN)) {
|
1995-11-30 03:56:23 +03:00
|
|
|
/*
|
|
|
|
* Fill the rest of the packet with zeros.
|
|
|
|
* N.B.: This is required! Otherwise MB86950 fails.
|
|
|
|
*/
|
1999-03-26 02:10:53 +03:00
|
|
|
for(len = totlen + 1; len < (ETHER_MIN_LEN - ETHER_CRC_LEN);
|
|
|
|
len += 2)
|
1995-11-30 03:56:23 +03:00
|
|
|
*addr = (u_short)0x0000;
|
1999-03-26 02:10:53 +03:00
|
|
|
totlen = (ETHER_MIN_LEN - ETHER_CRC_LEN);
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
return (totlen);
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1995-11-30 03:56:23 +03:00
|
|
|
* Copy packet from board RAM.
|
1995-10-07 21:04:27 +03:00
|
|
|
*
|
|
|
|
* Trailers not supported.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void
|
2002-01-26 16:40:52 +03:00
|
|
|
qn_get_packet(struct qn_softc *sc, u_short len)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
|
|
|
register u_short volatile *nic_fifo_ptr = sc->nic_fifo;
|
1997-03-17 21:04:40 +03:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1995-11-30 03:56:23 +03:00
|
|
|
struct mbuf *m, *dst, *head = NULL;
|
1995-10-07 21:04:27 +03:00
|
|
|
register u_short len1;
|
|
|
|
u_short amount;
|
|
|
|
|
|
|
|
/* Allocate header mbuf. */
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
1995-11-30 03:56:23 +03:00
|
|
|
if (m == NULL)
|
1995-10-07 21:04:27 +03:00
|
|
|
goto bad;
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/*
|
|
|
|
* Round len to even value.
|
|
|
|
*/
|
|
|
|
if (len & 1)
|
|
|
|
len++;
|
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
m->m_pkthdr.rcvif = &sc->sc_ethercom.ec_if;
|
1995-10-07 21:04:27 +03:00
|
|
|
m->m_pkthdr.len = len;
|
|
|
|
m->m_len = 0;
|
|
|
|
head = m;
|
|
|
|
|
|
|
|
word_copy_from_card(nic_fifo_ptr,
|
|
|
|
mtod(head, u_short *),
|
|
|
|
sizeof(struct ether_header));
|
|
|
|
|
|
|
|
head->m_len += sizeof(struct ether_header);
|
|
|
|
len -= sizeof(struct ether_header);
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
len1 = len;
|
|
|
|
|
|
|
|
amount = M_TRAILINGSPACE(m);
|
|
|
|
if (amount == 0) {
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Allocate another mbuf. */
|
1995-10-07 21:04:27 +03:00
|
|
|
dst = m;
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
1995-11-30 03:56:23 +03:00
|
|
|
if (m == NULL)
|
1995-10-07 21:04:27 +03:00
|
|
|
goto bad;
|
|
|
|
|
|
|
|
if (len1 >= MINCLSIZE)
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
|
|
|
|
m->m_len = 0;
|
|
|
|
dst->m_next = m;
|
|
|
|
|
|
|
|
amount = M_TRAILINGSPACE(m);
|
|
|
|
}
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
if (amount < len1)
|
1995-10-07 21:04:27 +03:00
|
|
|
len1 = amount;
|
1995-11-30 03:56:23 +03:00
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
word_copy_from_card(nic_fifo_ptr,
|
|
|
|
(u_short *)(mtod(m, caddr_t) + m->m_len),
|
1995-11-30 03:56:23 +03:00
|
|
|
len1);
|
1995-10-07 21:04:27 +03:00
|
|
|
m->m_len += len1;
|
|
|
|
len -= len1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
2000-10-02 03:32:39 +04:00
|
|
|
if (sc->sc_bpf)
|
1995-10-07 21:04:27 +03:00
|
|
|
bpf_mtap(sc->sc_bpf, head);
|
|
|
|
#endif
|
|
|
|
|
1999-05-19 03:52:51 +04:00
|
|
|
(*ifp->if_input)(ifp, head);
|
1995-10-07 21:04:27 +03:00
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
1995-11-30 03:56:23 +03:00
|
|
|
if (head) {
|
1995-10-07 21:04:27 +03:00
|
|
|
m_freem(head);
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_INFO, "qn_get_packet: mbuf alloc failed\n");
|
|
|
|
}
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet interface receiver interrupt.
|
|
|
|
*/
|
|
|
|
static void
|
2002-01-26 16:40:52 +03:00
|
|
|
qn_rint(struct qn_softc *sc, u_short rstat)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u_short len, status;
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Clear the status register. */
|
|
|
|
*sc->nic_r_status = CLEAR_R_ERR;
|
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
/*
|
1995-11-30 03:56:23 +03:00
|
|
|
* Was there some error?
|
|
|
|
* Some of them are senseless because they are masked off.
|
|
|
|
* XXX
|
1995-10-07 21:04:27 +03:00
|
|
|
*/
|
1996-06-19 00:50:00 +04:00
|
|
|
if (rstat & R_INT_OVR_FLO) {
|
1995-10-07 21:04:27 +03:00
|
|
|
#ifdef QN_DEBUG
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_INFO, "Overflow\n");
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_ierrors;
|
1995-11-30 03:56:23 +03:00
|
|
|
}
|
1996-06-19 00:50:00 +04:00
|
|
|
if (rstat & R_INT_CRC_ERR) {
|
1995-10-07 21:04:27 +03:00
|
|
|
#ifdef QN_DEBUG
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_INFO, "CRC Error\n");
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_ierrors;
|
1995-11-30 03:56:23 +03:00
|
|
|
}
|
1996-06-19 00:50:00 +04:00
|
|
|
if (rstat & R_INT_ALG_ERR) {
|
1995-10-07 21:04:27 +03:00
|
|
|
#ifdef QN_DEBUG
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_INFO, "Alignment error\n");
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_ierrors;
|
1995-11-30 03:56:23 +03:00
|
|
|
}
|
1996-06-19 00:50:00 +04:00
|
|
|
if (rstat & R_INT_SRT_PKT) {
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Short packet (these may occur and are
|
|
|
|
* no reason to worry about - or maybe
|
|
|
|
* they are?).
|
|
|
|
*/
|
1995-10-07 21:04:27 +03:00
|
|
|
#ifdef QN_DEBUG
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_INFO, "Short packet\n");
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_ierrors;
|
1995-11-30 03:56:23 +03:00
|
|
|
}
|
|
|
|
if (rstat & 0x4040) {
|
1995-10-07 21:04:27 +03:00
|
|
|
#ifdef QN_DEBUG
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_INFO, "Bus read error\n");
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_ierrors;
|
1995-11-30 03:56:23 +03:00
|
|
|
qnreset(sc);
|
|
|
|
}
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/*
|
|
|
|
* Read at most MAX_PACKETS packets per interrupt
|
|
|
|
*/
|
|
|
|
for (i = 0; i < MAX_PACKETS; i++) {
|
|
|
|
if (*sc->nic_r_mode & RM_BUF_EMP)
|
|
|
|
/* Buffer empty. */
|
|
|
|
break;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/*
|
|
|
|
* Read the first word: upper byte contains useful
|
|
|
|
* information.
|
|
|
|
*/
|
|
|
|
status = *sc->nic_fifo;
|
|
|
|
if ((status & 0x7000) != 0x2000) {
|
|
|
|
log(LOG_INFO, "qn: ERROR: status=%04x\n", status);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read packet length (byte-swapped).
|
|
|
|
* CRC is stripped off by the NIC.
|
|
|
|
*/
|
|
|
|
len = *sc->nic_fifo;
|
|
|
|
len = ((len << 8) & 0xff00) | ((len >> 8) & 0x00ff);
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1996-06-19 00:50:00 +04:00
|
|
|
#ifdef QN_CHECKS
|
1999-03-26 02:10:53 +03:00
|
|
|
if (len > (ETHER_MAX_LEN - ETHER_CRC_LEN) ||
|
|
|
|
len < ETHER_HDR_LEN) {
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_WARNING,
|
|
|
|
"%s: received a %s packet? (%u bytes)\n",
|
|
|
|
sc->sc_dev.dv_xname,
|
1999-03-26 02:10:53 +03:00
|
|
|
len < ETHER_HDR_LEN ? "partial" : "big", len);
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_ierrors;
|
1995-11-30 03:56:23 +03:00
|
|
|
continue;
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
1995-11-30 03:56:23 +03:00
|
|
|
#endif
|
1996-06-19 00:50:00 +04:00
|
|
|
#ifdef QN_CHECKS
|
1999-03-26 02:10:53 +03:00
|
|
|
if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN))
|
1995-11-30 03:56:23 +03:00
|
|
|
log(LOG_WARNING,
|
|
|
|
"%s: received a short packet? (%u bytes)\n",
|
|
|
|
sc->sc_dev.dv_xname, len);
|
2002-01-26 16:40:52 +03:00
|
|
|
#endif
|
1995-11-30 03:56:23 +03:00
|
|
|
|
|
|
|
/* Read the packet. */
|
|
|
|
qn_get_packet(sc, len);
|
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
++sc->sc_ethercom.ec_if.if_ipackets;
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
#ifdef QN_DEBUG
|
|
|
|
/* This print just to see whether MAX_PACKETS is large enough. */
|
|
|
|
if (i == MAX_PACKETS)
|
|
|
|
log(LOG_INFO, "used all the %d loops\n", MAX_PACKETS);
|
|
|
|
#endif
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our interrupt routine
|
|
|
|
*/
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
qnintr(void *arg)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1996-04-22 01:10:48 +04:00
|
|
|
struct qn_softc *sc = arg;
|
1995-11-30 03:56:23 +03:00
|
|
|
u_short tint, rint, tintmask;
|
|
|
|
char return_tintmask = 0;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the driver has not been initialized, just return immediately.
|
|
|
|
* This also happens if there is no QuickNet board present.
|
|
|
|
*/
|
|
|
|
if (sc->sc_base == NULL)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Get interrupt statuses and masks. */
|
1995-11-30 03:56:23 +03:00
|
|
|
rint = (*sc->nic_r_status) & NIC_R_MASK;
|
1995-10-07 21:04:27 +03:00
|
|
|
tintmask = *sc->nic_t_mask;
|
1995-11-30 03:56:23 +03:00
|
|
|
tint = (*sc->nic_t_status) & tintmask;
|
|
|
|
if (tint == 0 && rint == 0)
|
1995-10-07 21:04:27 +03:00
|
|
|
return (0);
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/* Disable interrupts so that we won't miss anything. */
|
1995-10-07 21:04:27 +03:00
|
|
|
*sc->nic_r_mask = CLEAR_R_MASK;
|
1995-11-30 03:56:23 +03:00
|
|
|
*sc->nic_t_mask = CLEAR_T_MASK;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle transmitter interrupts. Some of them are not asked for
|
|
|
|
* but do happen, anyway.
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
|
|
|
|
if (tint != 0) {
|
|
|
|
/* Clear transmit interrupt status. */
|
1995-10-07 21:04:27 +03:00
|
|
|
*sc->nic_t_status = CLEAR_T_ERR;
|
1995-11-30 03:56:23 +03:00
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
if (sc->transmit_pending && (tint & T_TMT_OK)) {
|
|
|
|
sc->transmit_pending = 0;
|
|
|
|
/*
|
|
|
|
* Update total number of successfully
|
|
|
|
* transmitted packets.
|
|
|
|
*/
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_opackets++;
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tint & T_SIXTEEN_COL) {
|
|
|
|
/*
|
|
|
|
* 16 collision (i.e., packet lost).
|
|
|
|
*/
|
|
|
|
log(LOG_INFO, "qn: 16 collision - packet lost\n");
|
1995-11-30 03:56:23 +03:00
|
|
|
#ifdef QN_DEBUG1
|
|
|
|
qn_dump(sc);
|
|
|
|
#endif
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_oerrors++;
|
|
|
|
sc->sc_ethercom.ec_if.if_collisions += 16;
|
1995-10-07 21:04:27 +03:00
|
|
|
sc->transmit_pending = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->transmit_pending) {
|
|
|
|
log(LOG_INFO, "qn:still pending...\n");
|
1995-11-30 03:56:23 +03:00
|
|
|
|
|
|
|
/* Must return transmission interrupt mask. */
|
|
|
|
return_tintmask = 1;
|
1995-10-07 21:04:27 +03:00
|
|
|
} else {
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_flags &= ~IFF_OACTIVE;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/* Clear watchdog timer. */
|
1997-03-15 21:09:08 +03:00
|
|
|
sc->sc_ethercom.ec_if.if_timer = 0;
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
1995-11-30 03:56:23 +03:00
|
|
|
} else
|
|
|
|
return_tintmask = 1;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle receiver interrupts.
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
if (rint != 0)
|
|
|
|
qn_rint(sc, rint);
|
1995-10-07 21:04:27 +03:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
if ((sc->sc_ethercom.ec_if.if_flags & IFF_OACTIVE) == 0)
|
|
|
|
qnstart(&sc->sc_ethercom.ec_if);
|
1995-11-30 03:56:23 +03:00
|
|
|
else if (return_tintmask == 1)
|
|
|
|
*sc->nic_t_mask = tintmask;
|
|
|
|
|
|
|
|
/* Set receive interrupt mask back. */
|
|
|
|
*sc->nic_r_mask = NIC_R_MASK;
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request. This code needs some work - it looks pretty ugly.
|
|
|
|
* I somehow think that this is quite a common excuse... ;-)
|
|
|
|
*/
|
|
|
|
int
|
2002-01-26 16:40:52 +03:00
|
|
|
qnioctl(register struct ifnet *ifp, u_long command, caddr_t data)
|
1995-10-07 21:04:27 +03:00
|
|
|
{
|
1996-05-07 04:46:37 +04:00
|
|
|
struct qn_softc *sc = ifp->if_softc;
|
1995-10-07 21:04:27 +03:00
|
|
|
register struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
#if 0
|
|
|
|
struct ifreg *ifr = (struct ifreg *)data;
|
|
|
|
#endif
|
|
|
|
int s, error = 0;
|
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
1995-11-30 03:56:23 +03:00
|
|
|
qnstop(sc);
|
1995-10-07 21:04:27 +03:00
|
|
|
qninit(sc);
|
1997-03-15 21:09:08 +03:00
|
|
|
arp_ifinit(ifp, ifa);
|
1995-10-07 21:04:27 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NS
|
|
|
|
case AF_NS:
|
|
|
|
{
|
|
|
|
register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
|
|
|
|
|
|
|
|
if (ns_nullhost(*ina))
|
|
|
|
ina->x_host =
|
1997-03-15 21:09:08 +03:00
|
|
|
*(union ns_host *)LLADDR(ifp->if_sadl);
|
1995-10-07 21:04:27 +03:00
|
|
|
else
|
|
|
|
bcopy(ina->x_host.c_host,
|
1997-03-15 21:09:08 +03:00
|
|
|
LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
|
1995-11-30 03:56:23 +03:00
|
|
|
qnstop(sc);
|
1995-10-07 21:04:27 +03:00
|
|
|
qninit(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
log(LOG_INFO, "qn:sa_family:default (not tested)\n");
|
1995-11-30 03:56:23 +03:00
|
|
|
qnstop(sc);
|
1995-10-07 21:04:27 +03:00
|
|
|
qninit(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) != 0) {
|
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
#ifdef QN_DEBUG1
|
|
|
|
qn_dump(sc);
|
|
|
|
#endif
|
1995-10-07 21:04:27 +03:00
|
|
|
qnstop(sc);
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
} else if ((ifp->if_flags & IFF_UP) != 0 &&
|
1995-11-30 03:56:23 +03:00
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0) {
|
1995-10-07 21:04:27 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
qninit(sc);
|
1995-11-30 03:56:23 +03:00
|
|
|
} else {
|
1995-10-07 21:04:27 +03:00
|
|
|
/*
|
|
|
|
* Something else... we won't do anything so we won't
|
|
|
|
* break anything (hope so).
|
|
|
|
*/
|
1995-11-30 03:56:23 +03:00
|
|
|
#ifdef QN_DEBUG1
|
|
|
|
log(LOG_INFO, "Else branch...\n");
|
|
|
|
#endif
|
1995-10-07 21:04:27 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
log(LOG_INFO, "qnioctl: multicast not done yet\n");
|
|
|
|
#if 0
|
|
|
|
error = (command == SIOCADDMULTI) ?
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_addmulti(ifr, &sc->sc_ethercom) :
|
|
|
|
ether_delmulti(ifr, &sc->sc_ethercom);
|
1995-10-07 21:04:27 +03:00
|
|
|
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
|
|
|
*/
|
|
|
|
log(LOG_INFO, "qnioctl: multicast not done yet\n");
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
error = EINVAL;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
log(LOG_INFO, "qnioctl: default\n");
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
splx(s);
|
1995-10-07 21:04:27 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
1995-11-30 03:56:23 +03:00
|
|
|
/*
|
|
|
|
* Dump some register information.
|
|
|
|
*/
|
|
|
|
#ifdef QN_DEBUG1
|
|
|
|
static void
|
2002-01-26 16:40:52 +03:00
|
|
|
qn_dump(struct qn_softc *sc)
|
1995-11-30 03:56:23 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
log(LOG_INFO, "t_status : %04x\n", *sc->nic_t_status);
|
|
|
|
log(LOG_INFO, "t_mask : %04x\n", *sc->nic_t_mask);
|
|
|
|
log(LOG_INFO, "t_mode : %04x\n", *sc->nic_t_mode);
|
|
|
|
log(LOG_INFO, "r_status : %04x\n", *sc->nic_r_status);
|
|
|
|
log(LOG_INFO, "r_mask : %04x\n", *sc->nic_r_mask);
|
|
|
|
log(LOG_INFO, "r_mode : %04x\n", *sc->nic_r_mode);
|
|
|
|
log(LOG_INFO, "pending : %02x\n", sc->transmit_pending);
|
1997-03-15 21:09:08 +03:00
|
|
|
log(LOG_INFO, "if_flags : %04x\n", sc->sc_ethercom.ec_if.if_flags);
|
1995-11-30 03:56:23 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-10-07 21:04:27 +03:00
|
|
|
#endif /* NQN > 0 */
|