Generic FDDI support by Matt Thomas. Support for DEC "PDQ" FDDI chipset

and for the PCI attachment of said chipset ("if_fpa"), also from Matt Thomas.
Arguably, pdq* doesn't belong in sys/dev/ic, but it's going to be shared by
various bus attachment devices at some point in the future, and there's no
other place that seems to fit as well.
This commit is contained in:
cgd 1995-08-19 00:59:47 +00:00
parent 1bac9e2b7c
commit 9980150670
6 changed files with 4124 additions and 0 deletions

1607
sys/dev/ic/pdq.c Normal file

File diff suppressed because it is too large Load Diff

1088
sys/dev/ic/pdqreg.h Normal file

File diff suppressed because it is too large Load Diff

292
sys/dev/ic/pdqvar.h Normal file
View File

@ -0,0 +1,292 @@
/*-
* Copyright (c) 1995 Matt Thomas (thomas@lkg.dec.com)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software withough 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.
*
* $Id: pdqvar.h,v 1.1.1.1 1995/08/19 00:59:48 cgd Exp $
*
* $Log: pdqvar.h,v $
* Revision 1.1.1.1 1995/08/19 00:59:48 cgd
* Generic FDDI support by Matt Thomas. Support for DEC "PDQ" FDDI chipset
* and for the PCI attachment of said chipset ("if_fpa"), also from Matt Thomas.
* Arguably, pdq* doesn't belong in sys/dev/ic, but it's going to be shared by
* various bus attachment devices at some point in the future, and there's no
* other place that seems to fit as well.
*
* Revision 1.10 1995/08/16 22:57:28 thomas
* Add support for NetBSD
*
* Revision 1.9 1995/06/21 18:29:27 thomas
* SVR4.2 changes
*
* Revision 1.8 1995/06/12 17:49:37 thomas
* Add SVR4.2 support
*
* Revision 1.7 1995/04/20 20:17:33 thomas
* Add PCI support for BSD/OS.
* Fix BSD/OS EISA support.
* Set latency timer for DEFPA to recommended value if 0.
*
* Revision 1.6 1995/03/14 01:52:52 thomas
* Update for new FreeBSD PCI Interrupt interface
* Use inl/inb/... inline macros provided by FreeBSD and BSDI
*
* Revision 1.5 1995/03/10 17:42:24 thomas
* More changes for BSDI
*
* Revision 1.4 1995/03/06 17:08:56 thomas
* Add copyright/disclaimer
* Add inx/outx macros
*
* Revision 1.3 1995/03/03 13:48:35 thomas
* more fixes
*
*
*/
/*
* DEC PDQ FDDI Controller; PDQ O/S dependent definitions
*
* Written by Matt Thomas
*
*/
#ifndef _PDQ_OS_H
#define _PDQ_OS_H
#define PDQ_OS_TX_TIMEOUT 5 /* seconds */
#if defined(PDQTEST)
#include <pdq_os_test.h>
#elif defined(__FreeBSD__) || defined(__bsdi__) || defined(__NetBSD__)
#include <sys/param.h>
#ifndef M_MCAST
#include <sys/mbuf.h>
#endif /* M_CAST */
#include <sys/malloc.h>
#include <vm/vm.h>
#include <vm/vm_kern.h>
#define PDQ_USE_MBUFS
#define PDQ_OS_PREFIX "%s%d: "
#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
#define PDQ_OS_PAGESIZE NBPG
#define PDQ_OS_USEC_DELAY(n) DELAY(n)
#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
#define PDQ_OS_VA_TO_PA(p) vtophys(p)
#define PDQ_OS_MEMALLOC(n) malloc(n, M_DEVBUF, M_NOWAIT)
#define PDQ_OS_MEMFREE(p, n) free((void *) p, M_DEVBUF)
#ifdef __FreeBSD__
#define PDQ_OS_MEMALLOC_CONTIG(n) vm_page_alloc_contig(n, 0, 0xffffffff, PAGE_SIZE)
#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
#else
#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_alloc(kernel_map, round_page(n))
#define PDQ_OS_MEMFREE_CONTIG(p, n) kmem_free(kernel_map, (vm_offset_t) p, n)
#endif /* __FreeBSD__ */
#if !defined(PDQ_HWSUPPORT)
#if defined(__FreeBSD__)
#include <machine/cpufunc.h>
typedef void ifnet_ret_t;
typedef int ioctl_cmd_t;
#elif defined(__bsdi__)
#include <machine/inline.h>
typedef int ifnet_ret_t;
typedef int ioctl_cmd_t;
#elif defined(__NetBSD__)
typedef void ifnet_ret_t;
typedef u_long ioctl_cmd_t;
#endif
#define PDQ_OS_IORD_32(port) inl(port)
#define PDQ_OS_IOWR_32(port, data) outl(port, data)
#define PDQ_OS_IORD_8(port) inb(port)
#define PDQ_OS_IOWR_8(port, data) outb(port, data)
typedef struct {
#ifdef __bsdi__
struct device sc_dev; /* base device */
struct isadev sc_id; /* ISA device */
struct intrhand sc_ih; /* intrrupt vectoring */
struct atshutdown sc_ats; /* shutdown routine */
#elif defined(__NetBSD__)
struct device sc_dev; /* base device */
void *sc_ih; /* intrrupt vectoring */
void *sc_ats; /* shutdown hook */
#endif
struct arpcom sc_ac;
pdq_t *sc_pdq;
unsigned sc_iobase;
} pdq_softc_t;
#define sc_if sc_ac.ac_if
#define sc_bpf sc_if.if_bpf
extern void pdq_ifreset(pdq_softc_t *sc);
extern void pdq_ifinit(pdq_softc_t *sc);
extern void pdq_ifwatchdog(pdq_softc_t *sc);
extern ifnet_ret_t pdq_ifstart(struct ifnet *ifp);
extern int pdq_ifioctl(struct ifnet *ifp, ioctl_cmd_t cmd, caddr_t data);
extern void pdq_ifattach(pdq_softc_t *sc, ifnet_ret_t (*ifinit)(int unit),
ifnet_ret_t (*ifwatchdog)(int unit));
#endif /* PDQ_HWSUPPORT */
#elif defined(DLPI_PDQ)
#include <sys/param.h>
#include <sys/kmem.h>
#include <sys/ddi.h>
#include <sys/stream.h>
#define PDQ_USE_STREAMS
#define PDQ_OS_PREFIX "%s board %d "
#define PDQ_OS_PREFIX_ARGS pdq->pdq_os_name, pdq->pdq_unit
#define PDQ_OS_PAGESIZE PAGESIZE
#define PDQ_OS_USEC_DELAY(n) drv_usecwait(n)
#define PDQ_OS_MEMZERO(p, n) bzero((caddr_t)(p), (n))
#define PDQ_OS_VA_TO_PA(p) vtop((caddr_t)p, NULL)
#define PDQ_OS_MEMALLOC(n) kmem_zalloc(n, KM_NOSLEEP)
#define PDQ_OS_MEMFREE(p, n) kmem_free((caddr_t) p, n)
#define PDQ_OS_MEMALLOC_CONTIG(n) kmem_zalloc_physreq(n, decfddiphysreq_db, KM_NOSLEEP)
#define PDQ_OS_MEMFREE_CONTIG(p, n) PDQ_OS_MEMFREE(p, n)
extern physreq_t *decfddiphysreq_db;
extern physreq_t *decfddiphysreq_mblk;
#define PDQ_OS_DATABUF_ALLOC(b) ((void) (((b) = allocb_physreq(PDQ_OS_DATABUF_SIZE, BPRI_MED, decfddiphysreq_mblk)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
#define PDQ_OS_IORD_8(port) inb(port)
#define PDQ_OS_IOWR_8(port, data) outb(port, data)
#endif
#ifdef PDQ_USE_MBUFS
#define PDQ_OS_DATABUF_SIZE (MCLBYTES)
#define PDQ_OS_DATABUF_FREE(b) (m_freem(b))
#define PDQ_OS_DATABUF_NEXT(b) ((b)->m_next)
#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->m_next = (b1))
#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->m_nextpkt)
#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->m_nextpkt = (b1))
#define PDQ_OS_DATABUF_LEN(b) ((b)->m_len)
#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->m_len = (n))
/* #define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->m_len += (n)) */
#define PDQ_OS_DATABUF_PTR(b) (mtod((b), pdq_uint8_t *))
#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->m_data += (n), (b)->m_len -= (n))
typedef struct mbuf PDQ_OS_DATABUF_T;
#define PDQ_OS_DATABUF_ALLOC(b) do { \
PDQ_OS_DATABUF_T *x_m0; \
MGETHDR(x_m0, M_DONTWAIT, MT_DATA); \
if (x_m0 != NULL) { \
MCLGET(x_m0, M_DONTWAIT); \
if ((x_m0->m_flags & M_EXT) == 0) { \
m_free(x_m0); \
(b) = NULL; \
} else { \
(b) = x_m0; \
x_m0->m_len = PDQ_OS_DATABUF_SIZE; \
} \
} else { \
(b) = NULL; \
} \
} while (0)
#define PDQ_OS_DATABUF_RESET(b) ((b)->m_data = (b)->m_ext.ext_buf, (b)->m_len = MCLBYTES)
#endif /* PDQ_USE_MBUFS */
#ifdef PDQ_USE_STREAMS
#define PDQ_OS_DATABUF_SIZE (2048)
#define PDQ_OS_DATABUF_FREE(b) (freemsg(b))
#define PDQ_OS_DATABUF_NEXT(b) ((b)->b_cont)
#define PDQ_OS_DATABUF_NEXT_SET(b, b1) ((b)->b_cont = (b1))
#define PDQ_OS_DATABUF_NEXTPKT(b) ((b)->b_next)
#define PDQ_OS_DATABUF_NEXTPKT_SET(b, b1) ((b)->b_next = (b1))
#define PDQ_OS_DATABUF_LEN(b) ((b)->b_wptr - (b)->b_rptr)
#define PDQ_OS_DATABUF_LEN_SET(b, n) ((b)->b_wptr = (b)->b_rptr + (n))
/*#define PDQ_OS_DATABUF_LEN_ADJ(b, n) ((b)->b_wptr += (n))*/
#define PDQ_OS_DATABUF_PTR(b) ((pdq_uint8_t *) (b)->b_rptr)
#define PDQ_OS_DATABUF_ADJ(b, n) ((b)->b_rptr += (n))
typedef mblk_t PDQ_OS_DATABUF_T;
#ifndef PDQ_OS_DATABUF_ALLOC
#define PDQ_OS_DATABUF_ALLOC(b) ((void) (((b) = allocb(PDQ_OS_DATABUF_SIZE, BPRI_MED)) && ((b)->b_wptr = (b)->b_rptr + PDQ_OS_DATABUF_SIZE)))
#endif /* PDQ_OS_DATABUF_ALLOC */
#endif /* PDQ_USE_STREAMS */
#define PDQ_OS_TX_TRANSMIT 5
#define PDQ_OS_DATABUF_ENQUEUE(q, b) do { \
PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
if ((q)->q_tail == NULL) \
(q)->q_head = (b); \
else \
PDQ_OS_DATABUF_NEXTPKT_SET(((PDQ_OS_DATABUF_T *)(q)->q_tail), b); \
(q)->q_tail = (b); \
} while (0)
#define PDQ_OS_DATABUF_DEQUEUE(q, b) do { \
if (((b) = (PDQ_OS_DATABUF_T *) (q)->q_head) != NULL) { \
if (((q)->q_head = PDQ_OS_DATABUF_NEXTPKT(b)) == NULL) \
(q)->q_tail = NULL; \
PDQ_OS_DATABUF_NEXTPKT_SET(b, NULL); \
} \
} while (0)
extern void pdq_os_addr_fill(pdq_t *pdq, pdq_lanaddr_t *addrs, size_t numaddrs);
extern void pdq_os_receive_pdu(pdq_t *, PDQ_OS_DATABUF_T *pdu, size_t pdulen);
extern void pdq_os_restart_transmitter(pdq_t *pdq);
extern void pdq_os_transmit_done(pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
extern void pdq_print_fddi_chars(pdq_t *pdq, const pdq_response_status_chars_get_t *rsp);
extern void pdq_init_csrs(pdq_csrs_t *csrs, void *csrs_va, size_t csr_size);
extern void pdq_init_pci_csrs(pdq_pci_csrs_t *csrs, void *csrs_va, size_t csr_size);
extern void pdq_flush_databuf_queue(pdq_databuf_queue_t *q);
extern pdq_boolean_t pdq_do_port_control(const pdq_csrs_t * const csrs, pdq_uint32_t cmd);
extern void pdq_read_mla(const pdq_csrs_t * const csrs, pdq_lanaddr_t *hwaddr);
extern void pdq_read_fwrev(const pdq_csrs_t * const csrs, pdq_fwrev_t *fwrev);
extern pdq_boolean_t pdq_read_error_log(pdq_t *pdq, pdq_response_error_log_get_t *log_entry);
extern pdq_chip_rev_t pdq_read_chiprev(const pdq_csrs_t * const csrs);
extern void pdq_queue_commands(pdq_t *pdq);
extern void pdq_process_command_responses(pdq_t *pdq);
extern void pdq_process_unsolicited_events(pdq_t *pdq);
extern void pdq_process_received_data(pdq_t *pdq, pdq_rx_info_t *rx,
pdq_rxdesc_t *receives,
pdq_uint32_t completion_goal,
pdq_uint32_t ring_mask);
extern pdq_boolean_t pdq_queue_transmit_data(pdq_t *pdq, PDQ_OS_DATABUF_T *pdu);
extern void pdq_process_transmitted_data(pdq_t *pdq);
extern void pdq_flush_transmitter(pdq_t *pdq);
extern void pdq_hwreset(pdq_t *pdq);
extern pdq_state_t pdq_stop(pdq_t *pdq);
extern void pdq_run(pdq_t *pdq);
extern int pdq_interrupt(pdq_t *pdq);
extern pdq_t *pdq_initialize(void *csr_va, const char *name, int unit, void *ctx, pdq_type_t type);
#endif /* _PDQ_OS_H */

462
sys/dev/pci/if_fpa.c Normal file
View File

@ -0,0 +1,462 @@
/*-
* Copyright (c) 1995 Matt Thomas (thomas@lkg.dec.com)
* 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. The name of the author may not be used to endorse or promote products
* derived from this software withough 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.
*
* $Id: if_fpa.c,v 1.1.1.1 1995/08/19 00:59:48 cgd Exp $
*
* $Log: if_fpa.c,v $
* Revision 1.1.1.1 1995/08/19 00:59:48 cgd
* Generic FDDI support by Matt Thomas. Support for DEC "PDQ" FDDI chipset
* and for the PCI attachment of said chipset ("if_fpa"), also from Matt Thomas.
* Arguably, pdq* doesn't belong in sys/dev/ic, but it's going to be shared by
* various bus attachment devices at some point in the future, and there's no
* other place that seems to fit as well.
*
* Revision 1.1 1995/08/16 22:57:28 thomas
* Initial revision
*
* Revision 1.13 1995/08/04 21:54:56 thomas
* Clean IRQ processing under BSD/OS.
* A receive tweaks. (print source of MAC CRC errors, etc.)
*
* Revision 1.12 1995/06/02 16:04:22 thomas
* Use correct PCI defs for BSDI now that they have fixed them.
* Increment the slot number 0x1000, not one! (*duh*)
*
* Revision 1.11 1995/04/21 13:23:55 thomas
* Fix a few pub in the DEFPA BSDI support
*
* Revision 1.10 1995/04/20 21:46:42 thomas
* Why???
* ,
*
* Revision 1.9 1995/04/20 20:17:33 thomas
* Add PCI support for BSD/OS.
* Fix BSD/OS EISA support.
* Set latency timer for DEFPA to recommended value if 0.
*
* Revision 1.8 1995/04/04 22:54:29 thomas
* Fix DEFEA support
*
* Revision 1.7 1995/03/14 01:52:52 thomas
* Update for new FreeBSD PCI Interrupt interface
*
* Revision 1.6 1995/03/10 17:06:59 thomas
* Update for latest version of FreeBSD.
* Compensate for the fast that the ifp will not be first thing
* in softc on BSDI.
*
* Revision 1.5 1995/03/07 19:59:42 thomas
* First pass at BSDI EISA support
*
* Revision 1.4 1995/03/06 17:06:03 thomas
* Add transmit timeout support.
* Add support DEFEA (untested).
*
* Revision 1.3 1995/03/03 13:48:35 thomas
* more fixes
*
*
*/
/*
* DEC PDQ FDDI Controller; code for BSD derived operating systems
*
* Written by Matt Thomas
*
* This module supports the DEC DEFPA PCI FDDI Controller
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/malloc.h>
#if defined(__FreeBSD__)
#include <sys/devconf.h>
#elif defined(__bsdi__) || defined(__NetBSD__)
#include <sys/device.h>
#endif
#include <net/if.h>
#include <net/if_types.h>
#include <net/if_dl.h>
#include <net/route.h>
#include "bpfilter.h"
#if NBPFILTER > 0
#include <net/bpf.h>
#include <net/bpfdesc.h>
#endif
#ifdef INET
#include <netinet/in.h>
#include <netinet/if_ether.h>
#endif
#if defined(__FreeBSD__)
#include <netinet/if_fddi.h>
#else
#include <net/if_fddi.h>
#endif
#include <vm/vm.h>
#include <vm/vm_kern.h>
#include <vm/vm_param.h>
#if defined(__FreeBSD__)
#include "fpa.h"
#include <pci/pcivar.h>
#include <i386/isa/icu.h>
#include <pci/pdqreg.h>
#include <pci/pdq_os.h>
#elif defined(__bsdi__)
#include <i386/pci/pci.h>
#include <i386/pci/pdqreg.h>
#include <i386/pci/pdq_os.h>
#elif defined(__NetBSD__)
#include <dev/pci/pcivar.h>
#include <dev/ic/pdqreg.h>
#include <dev/ic/pdq_os.h>
#endif /* __NetBSD__ */
#define DEC_VENDORID 0x1011
#define DEFPA_CHIPID 0x000F
#define PCI_VENDORID(x) ((x) & 0xFFFF)
#define PCI_CHIPID(x) (((x) >> 16) & 0xFFFF)
#define DEFPA_LATENCY 0x88
#define PCI_CFLT 0x0C /* Configuration Latency */
#define PCI_CBMA 0x10 /* Configuration Base Memory Address */
#if defined(__FreeBSD__)
/*
* This is the PCI configuration support. Since the PDQ is available
* on both EISA and PCI boards, one must be careful in how defines the
* PDQ in the config file.
*/
static char *pdq_pci_probe (pcici_t config_id, pcidi_t device_id);
static void pdq_pci_attach(pcici_t config_id, int unit);
static int pdq_pci_shutdown(struct kern_devconf *, int);
static u_long pdq_pci_count;
struct pci_device fpadevice = {
"fpa",
pdq_pci_probe,
pdq_pci_attach,
&pdq_pci_count,
pdq_pci_shutdown,
};
#ifdef DATA_SET
DATA_SET (pcidevice_set, fpadevice);
#endif
static pdq_softc_t *pdqs_pci[NFPA];
#define PDQ_PCI_UNIT_TO_SOFTC(unit) (pdqs_pci[unit])
#endif /* __FreeBSD__ */
#if defined(__bsdi__) || defined(__NetBSD__)
extern struct cfdriver fpacd;
#define PDQ_PCI_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)fpacd.cd_devs[unit])
#endif
static ifnet_ret_t
pdq_pci_ifinit(
int unit)
{
pdq_ifinit(PDQ_PCI_UNIT_TO_SOFTC(unit));
}
static ifnet_ret_t
pdq_pci_ifwatchdog(
int unit)
{
pdq_ifwatchdog(PDQ_PCI_UNIT_TO_SOFTC(unit));
}
static int
pdq_pci_ifintr(
void *arg)
{
pdq_softc_t * const sc = (pdq_softc_t *) arg;
#ifdef __FreeBSD__
return pdq_interrupt(sc->sc_pdq);
#elif defined(__bsdi__) || defined(__NetBSD__)
(void) pdq_interrupt(sc->sc_pdq);
return 1;
#endif
}
#if defined(__FreeBSD__)
static char *
pdq_pci_probe(
pcici_t config_id,
pcidi_t device_id)
{
if (PCI_VENDORID(device_id) == DEC_VENDORID &&
PCI_CHIPID(device_id) == DEFPA_CHIPID)
return "Digital DEFPA PCI FDDI Controller";
return NULL;
}
static void
pdq_pci_attach(
pcici_t config_id,
int unit)
{
pdq_softc_t *sc;
vm_offset_t va_csrs, pa_csrs;
pdq_uint32_t data;
if (unit > NFPA) {
printf("fpa%d: not configured; kernel is built for only %d device%s.\n",
unit, NFPA, NFPA == 1 ? "" : "s");
return;
}
data = pci_conf_read(config_id, PCI_CFLT);
if ((data & 0xFF00) == 0) {
data &= ~0xFF00;
data |= DEFPA_LATENCY << 8;
pci_conf_write(config_id, PCI_CFLT, data);
}
sc = (pdq_softc_t *) malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT);
if (sc == NULL)
return;
bzero(sc, sizeof(pdq_softc_t)); /* Zero out the softc*/
if (!pci_map_mem(config_id, PCI_CBMA, &va_csrs, &pa_csrs)) {
free((void *) sc, M_DEVBUF);
return;
}
sc->sc_if.if_name = "fpa";
sc->sc_if.if_unit = unit;
sc->sc_pdq = pdq_initialize((void *) va_csrs, "fpa", unit,
(void *) sc, PDQ_DEFPA);
if (sc->sc_pdq == NULL) {
free((void *) sc, M_DEVBUF);
return;
}
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
pdqs_pci[unit] = sc;
pdq_ifattach(sc, pdq_pci_ifinit, pdq_pci_ifwatchdog);
pci_map_int(config_id, pdq_pci_ifintr, (void*) sc, &net_imask);
}
static int
pdq_pci_shutdown(
struct kern_devconf *kdc,
int force)
{
if (kdc->kdc_unit < NFPA)
pdq_hwreset(PDQ_PCI_UNIT_TO_SOFTC(kdc->kdc_unit)->sc_pdq);
(void) dev_detach(kdc);
return 0;
}
#elif defined(__bsdi__)
static int
pdq_pci_match(
pci_devaddr_t *pa)
{
int irq;
int id;
id = pci_inl(pa, PCI_VENDOR_ID);
if (PCI_VENDORID(id) != DEC_VENDORID || PCI_CHIPID(id) != DEFPA_CHIPID)
return 0;
irq = pci_inl(pa, PCI_I_LINE) & 0xFF;
if (irq == 0 || irq >= 16)
return 0;
return 1;
}
int
pdq_pci_probe(
struct device *parent,
struct cfdata *cf,
void *aux)
{
struct isa_attach_args *ia = (struct isa_attach_args *) aux;
pdq_uint32_t irq, data;
pci_devaddr_t *pa;
pa = pci_scan(pdq_pci_match);
if (pa == NULL)
return 0;
irq = (1 << (pci_inl(pa, PCI_I_LINE) & 0xFF));
if (ia->ia_irq != IRQUNK && irq != ia->ia_irq) {
printf("fpa%d: error: desired IRQ of %d does not match device's actual IRQ of %d\n",
cf->cf_unit,
ffs(ia->ia_irq) - 1, ffs(irq) - 1);
return 0;
}
if (ia->ia_irq == IRQUNK && (ia->ia_irq = isa_irqalloc(irq)) == 0) {
printf("fpa%d: error: IRQ %d is already in use\n", cf->cf_unit,
ffs(irq) - 1);
return 0;
}
/* PCI bus masters don't use host DMA channels */
ia->ia_drq = DRQNONE;
/* Get the memory base address; assume the BIOS set it up correctly */
ia->ia_maddr = (caddr_t) (pci_inl(pa, PCI_CBMA) & ~7);
pci_outl(pa, PCI_CBMA, 0xFFFFFFFF);
ia->ia_msize = ((~pci_inl(pa, PCI_CBMA)) | 7) + 1;
pci_outl(pa, PCI_CBMA, (int) ia->ia_maddr);
/* Disable I/O space access */
pci_outl(pa, PCI_COMMAND, pci_inl(pa, PCI_COMMAND) & ~1);
ia->ia_iobase = 0;
ia->ia_iosize = 0;
/* Make sure the latency timer is what the DEFPA likes */
data = pci_inl(pa, PCI_CFLT);
if ((data & 0xFF00) == 0) {
data &= ~0xFF00;
data |= DEFPA_LATENCY << 8;
pci_outl(pa, PCI_CFLT, data);
}
return 1;
}
void
pdq_pci_attach(
struct device *parent,
struct device *self,
void *aux)
{
pdq_softc_t *sc = (pdq_softc_t *) self;
register struct isa_attach_args *ia = (struct isa_attach_args *) aux;
register struct ifnet *ifp = &sc->sc_if;
int i;
sc->sc_if.if_unit = sc->sc_dev.dv_unit;
sc->sc_if.if_name = "fpa";
sc->sc_if.if_flags = 0;
sc->sc_pdq = pdq_initialize((void *) mapphys((vm_offset_t)ia->ia_maddr, ia->ia_msize), "fpa",
sc->sc_if.if_unit, (void *) sc, PDQ_DEFPA);
if (sc->sc_pdq == NULL) {
printf("fpa%d: initialization failed\n", sc->sc_if.if_unit);
return;
}
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
pdq_ifattach(sc, pdq_pci_ifinit, pdq_pci_ifwatchdog);
isa_establish(&sc->sc_id, &sc->sc_dev);
sc->sc_ih.ih_fun = pdq_pci_ifintr;
sc->sc_ih.ih_arg = (void *)sc;
intr_establish(ia->ia_irq, &sc->sc_ih, DV_NET);
sc->sc_ats.func = (void (*)(void *)) pdq_hwreset;
sc->sc_ats.arg = (void *) sc->sc_pdq;
atshutdown(&sc->sc_ats, ATSH_ADD);
}
struct cfdriver fpacd = {
0, "fpa", pdq_pci_probe, pdq_pci_attach, DV_IFNET, sizeof(pdq_softc_t)
};
#elif defined(__NetBSD__)
static int
pdq_pci_probe(
struct device *parent,
void *match,
void *aux)
{
struct pci_attach_args *pa = (struct pci_attach_args *) aux;
if (PCI_VENDORID(pa->pa_id) != DEC_VENDORID)
return 0;
if (PCI_CHIPID(pa->pa_id) == DEFPA_CHIPID)
return 1;
return 0;
}
static void
pdq_pci_attach(
struct device * const parent,
struct device * const self,
void * const aux)
{
vm_offset_t va_csrs, pa_csrs;
pdq_uint32_t data;
pdq_softc_t * const sc = (pdq_softc_t *) self;
struct pci_attach_args * const pa = (struct pci_attach_args *) aux;
data = pci_conf_read(pa->pa_tag, PCI_CFLT);
if ((data & 0xFF00) == 0) {
data &= ~0xFF00;
data |= DEFPA_LATENCY << 8;
pci_conf_write(pa->pa_tag, PCI_CFLT, data);
}
if (pci_map_mem(pa->pa_tag, PCI_CBMA, &va_csrs, &pa_csrs))
return;
sc->sc_if.if_name = "fpa";
sc->sc_if.if_unit = sc->sc_dev.dv_unit;
sc->sc_if.if_flags = 0;
sc->sc_pdq = pdq_initialize((void *) va_csrs, sc->sc_if.if_name,
sc->sc_if.if_unit, (void *) sc, PDQ_DEFPA);
if (sc->sc_pdq == NULL)
return;
bcopy((caddr_t) sc->sc_pdq->pdq_hwaddr.lanaddr_bytes, sc->sc_ac.ac_enaddr, 6);
pdq_ifattach(sc, pdq_pci_ifinit, pdq_pci_ifwatchdog);
sc->sc_ih = pci_map_int(pa->pa_tag, PCI_IPL_NET, pdq_pci_ifintr, sc);
if (sc->sc_ih == NULL) {
printf("fpa%d: error: couldn't map interrupt\n", sc->sc_if.if_unit);
return;
}
#if 0
sc->sc_ats = shutdownhook_establish(pdq_hwreset, sc);
if (sc->sc_ats == NULL)
printf("fpa%d: warning: couldn't establish shutdown hook\n",
sc->sc_if.if_unit);
#endif
}
struct cfdriver fpacd = {
0, "fpa", pdq_pci_probe, pdq_pci_attach, DV_IFNET, sizeof(pdq_softc_t)
};
#endif /* __NetBSD__ */

84
sys/net/if_fddi.h Normal file
View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 1982, 1986, 1993
* The Regents of the University of California. 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 the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)if_fddi.h 8.1 (Berkeley) 6/10/93
* $Id: if_fddi.h,v 1.1.1.1 1995/08/19 00:59:47 cgd Exp $
*/
#ifndef _NETINET_IF_FDDI_H_
#define _NETINET_IF_FDDI_H_
/*
* Structure of an 100Mb/s FDDI header.
*/
struct fddi_header {
u_char fddi_fc;
u_char fddi_dhost[6];
u_char fddi_shost[6];
};
#define FDDIMTU 4470
#define FDDIMIN 3
#define FDDIFC_C 0x80 /* 0b10000000 */
#define FDDIFC_L 0x40 /* 0b01000000 */
#define FDDIFC_F 0x30 /* 0b00110000 */
#define FDDIFC_Z 0x0F /* 0b00001111 */
#define FDDIFC_LLC_ASYNC 0x50
#define FDDIFC_LLC_PRIO0 0
#define FDDIFC_LLC_PRIO1 1
#define FDDIFC_LLC_PRIO2 2
#define FDDIFC_LLC_PRIO3 3
#define FDDIFC_LLC_PRIO4 4
#define FDDIFC_LLC_PRIO5 5
#define FDDIFC_LLC_PRIO6 6
#define FDDIFC_LLC_PRIO7 7
#define FDDIFC_LLC_SYNC 0xd0
#define FDDIFC_SMT 0x40
#if defined(KERNEL) || defined(_KERNEL)
#define fddibroadcastaddr etherbroadcastaddr
#define fddi_ipmulticast_min ether_ipmulticast_min
#define fddi_ipmulticast_max ether_ipmulticast_max
#define fddi_addmulti ether_addmulti
#define fddi_delmulti ether_delmulti
#define fddi_sprintf ether_sprintf
void fddi_ifattach __P((struct ifnet *));
void fddi_input __P((struct ifnet *, struct fddi_header *, struct mbuf *));
int fddi_output __P((struct ifnet *,
struct mbuf *, struct sockaddr *, struct rtentry *));
#endif
#endif

591
sys/net/if_fddisubr.c Normal file
View File

@ -0,0 +1,591 @@
/*
* Copyright (c) 1995
* Matt Thomas. All rights reserved.
* Copyright (c) 1982, 1989, 1993
* The Regents of the University of California. 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 the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)if_fddisubr.c 8.1 (Berkeley) 6/10/93
*
* $Id: if_fddisubr.c,v 1.1.1.1 1995/08/19 00:59:47 cgd Exp $
* $Log: if_fddisubr.c,v $
* Revision 1.1.1.1 1995/08/19 00:59:47 cgd
* Generic FDDI support by Matt Thomas. Support for DEC "PDQ" FDDI chipset
* and for the PCI attachment of said chipset ("if_fpa"), also from Matt Thomas.
* Arguably, pdq* doesn't belong in sys/dev/ic, but it's going to be shared by
* various bus attachment devices at some point in the future, and there's no
* other place that seems to fit as well.
*
* Revision 1.8 1995/08/16 22:57:28 thomas
* Add support for NetBSD
*
* Revision 1.7 1995/04/20 20:17:33 thomas
* fix typo
*
* Revision 1.6 1995/04/20 19:21:58 thomas
* *** empty log message ***
*
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/errno.h>
#include <sys/syslog.h>
#include <machine/cpu.h>
#include <net/if.h>
#include <net/netisr.h>
#include <net/route.h>
#include <net/if_llc.h>
#include <net/if_dl.h>
#include <net/if_types.h>
#ifdef INET
#include <netinet/in.h>
#include <netinet/in_var.h>
#endif
#include <netinet/if_ether.h>
#if defined(__FreeBSD__)
#include <netinet/if_fddi.h>
#else
#include <net/if_fddi.h>
#endif
#ifdef NS
#include <netns/ns.h>
#include <netns/ns_if.h>
#endif
#ifdef DECNET
#include <netdnet/dn.h>
#endif
#ifdef ISO
#include <netiso/argo_debug.h>
#include <netiso/iso.h>
#include <netiso/iso_var.h>
#include <netiso/iso_snpac.h>
#endif
#include "bpfilter.h"
#ifdef LLC
#include <netccitt/dll.h>
#include <netccitt/llc_var.h>
#endif
#if defined(LLC) && defined(CCITT)
extern struct ifqueue pkintrq;
#endif
#define senderr(e) { error = (e); goto bad;}
/*
* This really should be defined in if_llc.h but in case it isn't.
*/
#ifndef llc_snap
#define llc_snap llc_un.type_snap
#endif
#if defined(__bsdi__) || defined(__NetBSD__)
#define RTALLOC1(a, b) rtalloc1(a, b)
#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e)
#define TYPEHTONS(t) (t)
#elif defined(__FreeBSD__)
#define RTALLOC1(a, b) rtalloc1(a, b, 0UL)
#define ARPRESOLVE(a, b, c, d, e, f) arpresolve(a, b, c, d, e, f)
#define TYPEHTONS(t) (htons(t))
#endif
/*
* FDDI output routine.
* Encapsulate a packet of type family for the local net.
* Use trailer local net encapsulation if enough data in first
* packet leaves a multiple of 512 bytes of data in remainder.
* Assumes that ifp is actually pointer to arpcom structure.
*/
int
fddi_output(ifp, m0, dst, rt0)
register struct ifnet *ifp;
struct mbuf *m0;
struct sockaddr *dst;
struct rtentry *rt0;
{
short type;
int s, error = 0;
u_char edst[6];
register struct mbuf *m = m0;
register struct rtentry *rt;
struct mbuf *mcopy = (struct mbuf *)0;
register struct fddi_header *fh;
struct arpcom *ac = (struct arpcom *)ifp;
if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
senderr(ENETDOWN);
ifp->if_lastchange = time;
if (rt = rt0) {
if ((rt->rt_flags & RTF_UP) == 0) {
if (rt0 = rt = RTALLOC1(dst, 1))
rt->rt_refcnt--;
else
senderr(EHOSTUNREACH);
}
if (rt->rt_flags & RTF_GATEWAY) {
if (rt->rt_gwroute == 0)
goto lookup;
if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) {
rtfree(rt); rt = rt0;
lookup: rt->rt_gwroute = RTALLOC1(rt->rt_gateway, 1);
if ((rt = rt->rt_gwroute) == 0)
senderr(EHOSTUNREACH);
}
}
if (rt->rt_flags & RTF_REJECT)
if (rt->rt_rmx.rmx_expire == 0 ||
time.tv_sec < rt->rt_rmx.rmx_expire)
senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH);
}
switch (dst->sa_family) {
#ifdef INET
case AF_INET:
if (!ARPRESOLVE(ac, rt, m, dst, edst, rt0))
return (0); /* if not yet resolved */
/* If broadcasting on a simplex interface, loopback a copy */
if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
mcopy = m_copy(m, 0, (int)M_COPYALL);
type = htons(ETHERTYPE_IP);
break;
#endif
#ifdef NS
case AF_NS:
type = htons(ETHERTYPE_NS);
bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host),
(caddr_t)edst, sizeof (edst));
if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst)))
return (looutput(ifp, m, dst, rt));
/* If broadcasting on a simplex interface, loopback a copy */
if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX))
mcopy = m_copy(m, 0, (int)M_COPYALL);
break;
#endif
#ifdef ISO
case AF_ISO: {
int snpalen;
struct llc *l;
register struct sockaddr_dl *sdl;
if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) &&
sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) {
bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst));
} else if (error =
iso_snparesolve(ifp, (struct sockaddr_iso *)dst,
(char *)edst, &snpalen))
goto bad; /* Not Resolved */
/* If broadcasting on a simplex interface, loopback a copy */
if (*edst & 1)
m->m_flags |= (M_BCAST|M_MCAST);
if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) &&
(mcopy = m_copy(m, 0, (int)M_COPYALL))) {
M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
if (mcopy) {
fh = mtod(mcopy, struct fddi_header *);
bcopy((caddr_t)edst,
(caddr_t)fh->fddi_dhost, sizeof (edst));
bcopy((caddr_t)ac->ac_enaddr,
(caddr_t)fh->fddi_shost, sizeof (edst));
}
}
M_PREPEND(m, 3, M_DONTWAIT);
if (m == NULL)
return (0);
type = 0;
l = mtod(m, struct llc *);
l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP;
l->llc_control = LLC_UI;
IFDEBUG(D_ETHER)
int i;
printf("unoutput: sending pkt to: ");
for (i=0; i<6; i++)
printf("%x ", edst[i] & 0xff);
printf("\n");
ENDDEBUG
} break;
#endif /* ISO */
#ifdef LLC
/* case AF_NSAP: */
case AF_CCITT: {
register struct sockaddr_dl *sdl =
(struct sockaddr_dl *) rt -> rt_gateway;
if (sdl && sdl->sdl_family == AF_LINK
&& sdl->sdl_alen > 0) {
bcopy(LLADDR(sdl), (char *)edst,
sizeof(edst));
} else goto bad; /* Not a link interface ? Funny ... */
if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) &&
(mcopy = m_copy(m, 0, (int)M_COPYALL))) {
M_PREPEND(mcopy, sizeof (*fh), M_DONTWAIT);
if (mcopy) {
fh = mtod(mcopy, struct fddi_header *);
bcopy((caddr_t)edst,
(caddr_t)fh->fddi_dhost, sizeof (edst));
bcopy((caddr_t)ac->ac_enaddr,
(caddr_t)fh->fddi_shost, sizeof (edst));
fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
}
}
type = 0;
#ifdef LLC_DEBUG
{
int i;
register struct llc *l = mtod(m, struct llc *);
printf("fddi_output: sending LLC2 pkt to: ");
for (i=0; i<6; i++)
printf("%x ", edst[i] & 0xff);
printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n",
type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff,
l->llc_control & 0xff);
}
#endif /* LLC_DEBUG */
} break;
#endif /* LLC */
case AF_UNSPEC:
{
struct ether_header *eh;
eh = (struct ether_header *)dst->sa_data;
bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, sizeof (edst));
if (*edst & 1)
m->m_flags |= (M_BCAST|M_MCAST);
type = TYPEHTONS(eh->ether_type);
break;
}
#if NBPFILTER > 0
case AF_IMPLINK:
{
fh = mtod(m, struct fddi_header *);
error = EPROTONOSUPPORT;
switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
case FDDIFC_LLC_ASYNC: {
/* legal priorities are 0 through 7 */
if ((fh->fddi_fc & FDDIFC_Z) > 7)
goto bad;
break;
}
case FDDIFC_LLC_SYNC: {
/* FDDIFC_Z bits reserved, must be zero */
if (fh->fddi_fc & FDDIFC_Z)
goto bad;
break;
}
case FDDIFC_SMT: {
/* FDDIFC_Z bits must be non zero */
if ((fh->fddi_fc & FDDIFC_Z) == 0)
goto bad;
break;
}
default: {
/* anything else is too dangerous */
goto bad;
}
}
error = 0;
if (fh->fddi_dhost[0] & 1)
m->m_flags |= (M_BCAST|M_MCAST);
goto queue_it;
}
#endif
default:
printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit,
dst->sa_family);
senderr(EAFNOSUPPORT);
}
if (mcopy)
(void) looutput(ifp, mcopy, dst, rt);
if (type != 0) {
register struct llc *l;
M_PREPEND(m, sizeof (struct llc), M_DONTWAIT);
if (m == 0)
senderr(ENOBUFS);
l = mtod(m, struct llc *);
l->llc_control = LLC_UI;
l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
l->llc_snap.org_code[0] = l->llc_snap.org_code[1] = l->llc_snap.org_code[2] = 0;
bcopy((caddr_t) &type, (caddr_t) &l->llc_snap.ether_type,
sizeof(u_short));
}
/*
* Add local net header. If no space in first mbuf,
* allocate another.
*/
M_PREPEND(m, sizeof (struct fddi_header), M_DONTWAIT);
if (m == 0)
senderr(ENOBUFS);
fh = mtod(m, struct fddi_header *);
fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, sizeof (edst));
queue_it:
bcopy((caddr_t)ac->ac_enaddr, (caddr_t)fh->fddi_shost,
sizeof(fh->fddi_shost));
s = splimp();
/*
* Queue message on interface, and start output if interface
* not yet active.
*/
if (IF_QFULL(&ifp->if_snd)) {
IF_DROP(&ifp->if_snd);
splx(s);
senderr(ENOBUFS);
}
ifp->if_obytes += m->m_pkthdr.len;
IF_ENQUEUE(&ifp->if_snd, m);
if ((ifp->if_flags & IFF_OACTIVE) == 0)
(*ifp->if_start)(ifp);
splx(s);
if (m->m_flags & M_MCAST)
ifp->if_omcasts++;
return (error);
bad:
if (m)
m_freem(m);
return (error);
}
/*
* Process a received FDDI packet;
* the packet is in the mbuf chain m without
* the fddi header, which is provided separately.
*/
void
fddi_input(ifp, fh, m)
struct ifnet *ifp;
register struct fddi_header *fh;
struct mbuf *m;
{
register struct ifqueue *inq;
register struct llc *l;
int s;
if ((ifp->if_flags & IFF_UP) == 0) {
m_freem(m);
return;
}
ifp->if_lastchange = time;
ifp->if_ibytes += m->m_pkthdr.len + sizeof (*fh);
if (bcmp((caddr_t)fddibroadcastaddr, (caddr_t)fh->fddi_dhost,
sizeof(fddibroadcastaddr)) == 0)
m->m_flags |= M_BCAST;
else if (fh->fddi_dhost[0] & 1)
m->m_flags |= M_MCAST;
if (m->m_flags & (M_BCAST|M_MCAST))
ifp->if_imcasts++;
l = mtod(m, struct llc *);
switch (l->llc_dsap) {
#if defined(INET) || defined(NS) || defined(DECNET)
case LLC_SNAP_LSAP:
{
unsigned fddi_type;
if (l->llc_control != LLC_UI || l->llc_ssap != LLC_SNAP_LSAP)
goto dropanyway;
if (l->llc_snap.org_code[0] != 0 || l->llc_snap.org_code[1] != 0|| l->llc_snap.org_code[2] != 0)
goto dropanyway;
fddi_type = ntohs(l->llc_snap.ether_type);
m_adj(m, 8);
switch (fddi_type) {
#ifdef INET
case ETHERTYPE_IP:
schednetisr(NETISR_IP);
inq = &ipintrq;
break;
case ETHERTYPE_ARP:
schednetisr(NETISR_ARP);
inq = &arpintrq;
break;
#endif
#ifdef NS
case ETHERTYPE_NS:
schednetisr(NETISR_NS);
inq = &nsintrq;
break;
#endif
#ifdef DECNET
case ETHERTYPE_DECENT:
schednetisr(NETISR_DECNET);
inq = &decnetintrq;
break;
#endif
default:
/* printf("fddi_input: unknown protocol 0x%x\n", fddi_type); */
ifp->if_noproto++;
goto dropanyway;
}
break;
}
#endif /* INET || NS */
#ifdef ISO
case LLC_ISO_LSAP:
switch (l->llc_control) {
case LLC_UI:
/* LLC_UI_P forbidden in class 1 service */
if ((l->llc_dsap == LLC_ISO_LSAP) &&
(l->llc_ssap == LLC_ISO_LSAP)) {
/* LSAP for ISO */
m->m_data += 3; /* XXX */
m->m_len -= 3; /* XXX */
m->m_pkthdr.len -= 3; /* XXX */
M_PREPEND(m, sizeof *fh, M_DONTWAIT);
if (m == 0)
return;
*mtod(m, struct fddi_header *) = *fh;
IFDEBUG(D_ETHER)
printf("clnp packet");
ENDDEBUG
schednetisr(NETISR_ISO);
inq = &clnlintrq;
break;
}
goto dropanyway;
case LLC_XID:
case LLC_XID_P:
if(m->m_len < 6)
goto dropanyway;
l->llc_window = 0;
l->llc_fid = 9;
l->llc_class = 1;
l->llc_dsap = l->llc_ssap = 0;
/* Fall through to */
case LLC_TEST:
case LLC_TEST_P:
{
struct sockaddr sa;
register struct ether_header *eh2;
int i;
u_char c = l->llc_dsap;
l->llc_dsap = l->llc_ssap;
l->llc_ssap = c;
if (m->m_flags & (M_BCAST | M_MCAST))
bcopy((caddr_t)ac->ac_enaddr,
(caddr_t)eh->ether_dhost, 6);
sa.sa_family = AF_UNSPEC;
sa.sa_len = sizeof(sa);
eh2 = (struct ether_header *)sa.sa_data;
for (i = 0; i < 6; i++) {
eh2->ether_shost[i] = c = eh->fddi_dhost[i];
eh2->ether_dhost[i] =
eh->ether_dhost[i] = eh->fddi_shost[i];
eh2->ether_shost[i] = c;
}
eh2->ether_type = 0;
ifp->if_output(ifp, m, &sa, NULL);
return;
}
default:
m_freem(m);
return;
}
break;
#endif /* ISO */
#ifdef LLC
case LLC_X25_LSAP:
{
M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT);
if (m == 0)
return;
if ( !sdl_sethdrif(ifp, fh->fddi_shost, LLC_X25_LSAP,
fh->fddi_dhost, LLC_X25_LSAP, 6,
mtod(m, struct sdl_hdr *)))
panic("ETHER cons addr failure");
mtod(m, struct sdl_hdr *)->sdlhdr_len = m->m_pkthdr.len - sizeof(struct sdl_hdr);
#ifdef LLC_DEBUG
printf("llc packet\n");
#endif /* LLC_DEBUG */
schednetisr(NETISR_CCITT);
inq = &llcintrq;
break;
}
#endif /* LLC */
default:
/* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
ifp->if_noproto++;
dropanyway:
m_freem(m);
return;
}
s = splimp();
if (IF_QFULL(inq)) {
IF_DROP(inq);
m_freem(m);
} else
IF_ENQUEUE(inq, m);
splx(s);
}
/*
* Perform common duties while attaching to interface list
*/
void
fddi_ifattach(ifp)
register struct ifnet *ifp;
{
register struct ifaddr *ifa;
register struct sockaddr_dl *sdl;
ifp->if_type = IFT_FDDI;
ifp->if_addrlen = 6;
ifp->if_hdrlen = 21;
ifp->if_mtu = FDDIMTU;
for (ifa = ifp->if_addrlist; ifa; ifa = ifa->ifa_next)
if ((sdl = (struct sockaddr_dl *)ifa->ifa_addr) &&
sdl->sdl_family == AF_LINK) {
sdl->sdl_type = IFT_FDDI;
sdl->sdl_alen = ifp->if_addrlen;
bcopy((caddr_t)((struct arpcom *)ifp)->ac_enaddr,
LLADDR(sdl), ifp->if_addrlen);
break;
}
}