/* if_dmc.c 4.12 82/04/16 */
#define printd if(dmcdebug)printf
* DMC11 device driver, internet version
* allow more than one outstanding read or write.
#include "../h/protosw.h"
#include "../net/in_systm.h"
#include "../net/if_uba.h"
#include "../net/if_dmc.h"
#include "../net/ip_var.h"
#include "../net/route.h"
* Driver information for auto-configuration stuff.
int dmcprobe(), dmcattach(), dmcinit(), dmcoutput(), dmcreset();
struct uba_device
*dmcinfo
[NDMC
];
u_short dmcstd
[] = { 0 };
struct uba_driver dmcdriver
=
{ dmcprobe
, 0, dmcattach
, 0, dmcstd
, "dmc", dmcinfo
};
#define DMC_AF 0xff /* 8 bits of address type in ui_flags */
#define DMC_NET 0xff00 /* 8 bits of net number in ui_flags */
* DMC software status per interface.
* Each interface is referenced by a network interface structure,
* sc_if, which the routing code uses to locate the interface.
* This structure contains the output queue for the interface, its address, ...
* We also have, for each interface, a UBA interface structure, which
* contains information about the UNIBUS resources held by the interface:
* map registers, buffered data paths, etc. Information is cached in this
* structure for use by the if_uba.c routines in running the interface
struct ifnet sc_if
; /* network-visible interface */
struct ifuba sc_ifuba
; /* UNIBUS resources */
short sc_flag
; /* flags */
short sc_oactive
; /* output active */
int sc_ubinfo
; /* UBA mapping info for base table */
struct clist sc_que
; /* command queue */
#define DMCBMAPPED 02 /* base table mapped */
short d_base
[128]; /* DMC base table */
#define loword(x) ((short *)&x)[0]
#define hiword(x) ((short *)&x)[1]
register struct dmcdevice
*addr
= (struct dmcdevice
*)reg
;
br
= 0; cvec
= br
; br
= cvec
;
for (i
= 100000; i
&& (addr
->bsel1
& DMC_RUN
) == 0; i
--)
if ((addr
->bsel1
& DMC_RUN
) == 0)
addr
->bsel1
&= ~DMC_MCLR
;
addr
->bsel0
= DMC_RQI
|DMC_IEI
;
for (i
= 100000; i
&& (addr
->bsel1
& DMC_RUN
) == 0; i
--)
br
= 0x16; /* temporary ec hack */
* Interface exists: make available by filling in network interface
* record. System will initialize the interface when it is ready
register struct uba_device
*ui
;
register struct dmc_softc
*sc
= &dmc_softc
[ui
->ui_unit
];
register struct sockaddr_in
*sin
;
sc
->sc_if
.if_unit
= ui
->ui_unit
;
sc
->sc_if
.if_name
= "dmc";
sc
->sc_if
.if_mtu
= DMCMTU
;
sc
->sc_if
.if_net
= (ui
->ui_flags
& DMC_NET
) >> 8;
sc
->sc_if
.if_host
[0] = 17; /* random number */
sin
= (struct sockaddr_in
*)&sc
->sc_if
.if_addr
;
sin
->sa_family
= AF_INET
;
sin
->sin_addr
= if_makeaddr(sc
->sc_if
.if_net
, sc
->sc_if
.if_host
[0]);
sc
->sc_if
.if_init
= dmcinit
;
sc
->sc_if
.if_output
= dmcoutput
;
sc
->sc_if
.if_ubareset
= dmcreset
;
sc
->sc_ifuba
.ifuba_flags
= UBA_NEEDBDP
| UBA_CANTWAIT
;
* Reset of interface after UNIBUS reset.
* If interface is on specified UBA, reset it's state.
register struct uba_device
*ui
;
if (unit
>= NDMC
|| (ui
= dmcinfo
[unit
]) == 0 || ui
->ui_alive
== 0 ||
* Initialization of interface; reinitialize UNIBUS usage.
register struct dmc_softc
*sc
= &dmc_softc
[unit
];
register struct uba_device
*ui
= dmcinfo
[unit
];
register struct dmcdevice
*addr
;
if ((sc
->sc_flag
&DMCBMAPPED
) == 0) {
sc
->sc_ubinfo
= uballoc(ui
->ui_ubanum
,
(caddr_t
)&dmc_base
[unit
], sizeof (struct dmc_base
), 0);
sc
->sc_flag
|= DMCBMAPPED
;
if (if_ubainit(&sc
->sc_ifuba
, ui
->ui_ubanum
, 0,
(int)btoc(DMCMTU
)) == 0) {
printf("dmc%d: can't initialize\n", unit
);
sc
->sc_if
.if_flags
&= ~IFF_UP
;
addr
= (struct dmcdevice
*)ui
->ui_addr
;
base
= sc
->sc_ubinfo
& 0x3ffff;
printd(" base 0x%x\n", base
);
dmcload(sc
, DMC_BASEI
, base
, (base
>>2)&DMC_XMEM
);
dmcload(sc
, DMC_CNTLI
, 0, 0);
base
= sc
->sc_ifuba
.ifu_r
.ifrw_info
& 0x3ffff;
dmcload(sc
, DMC_READ
, base
, ((base
>>2)&DMC_XMEM
)|DMCMTU
);
printd(" first read queued, addr 0x%x\n", base
);
sc
->sc_if
.if_flags
|= IFF_UP
;
/* set up routing table entry */
if ((sc
->sc_if
.if_flags
& IFF_ROUTE
) == 0) {
rtinit(&sc
->sc_if
.if_addr
, &sc
->sc_if
.if_addr
,
RTF_DIRECT
|RTF_HOST
|RTF_UP
);
sc
->sc_if
.if_flags
|= IFF_ROUTE
;
* Start output on interface. Get another datagram
* to send from the interface queue and map it to
* the interface before starting output.
struct uba_device
*ui
= dmcinfo
[unit
];
register struct dmc_softc
*sc
= &dmc_softc
[unit
];
* Dequeue a request and map it to the UNIBUS.
* If no more requests, just return.
IF_DEQUEUE(&sc
->sc_if
.if_snd
, m
);
len
= if_wubaput(&sc
->sc_ifuba
, m
);
* Have request mapped to UNIBUS for transmission.
* Purge any stale data from this BDP and start the output.
if (sc
->sc_ifuba
.ifuba_flags
& UBA_NEEDBDP
)
UBAPURGE(sc
->sc_ifuba
.ifu_uba
, sc
->sc_ifuba
.ifu_w
.ifrw_bdp
);
addr
= sc
->sc_ifuba
.ifu_w
.ifrw_info
& 0x3ffff;
printd(" len %d, addr 0x%x, ", len
, addr
);
printd("mr 0x%x\n", sc
->sc_ifuba
.ifu_w
.ifrw_mr
[0]);
dmcload(sc
, DMC_WRITE
, addr
, (len
&DMC_CCOUNT
)|((addr
>>2)&DMC_XMEM
));
* Utility routine to load the DMC device registers.
dmcload(sc
, type
, w0
, w1
)
register struct dmc_softc
*sc
;
register struct dmcdevice
*addr
;
register int unit
, sps
, n
;
printd("dmcload: 0x%x 0x%x 0x%x\n", type
, w0
, w1
);
addr
= (struct dmcdevice
*)dmcinfo
[unit
]->ui_addr
;
if ((n
= sc
->sc_que
.c_cc
) == 0)
addr
->bsel0
= type
| DMC_RQI
;
(void) putc(type
| DMC_RQI
, &sc
->sc_que
);
(void) putw(w0
, &sc
->sc_que
);
(void) putw(w1
, &sc
->sc_que
);
* DMC interface receiver interrupt.
* Ready to accept another command,
* pull one off the command queue.
register struct dmc_softc
*sc
;
register struct dmcdevice
*addr
;
addr
= (struct dmcdevice
*)dmcinfo
[unit
]->ui_addr
;
while (addr
->bsel0
&DMC_RDYI
) {
w0
= getw(&sc
->sc_que
); /* DEBUG */
addr
->sel4
= w0
; /* DEBUG */
w1
= getw(&sc
->sc_que
); /* DEBUG */
addr
->sel6
= w1
; /* DEBUG */
addr->sel4 = getw(&sc->sc_que);
addr->sel6 = getw(&sc->sc_que);
addr
->bsel0
&= ~(DMC_IEI
|DMC_RQI
);
printd(" w0 0x%x, w1 0x%x\n", w0
, w1
);
while (addr
->bsel0
&DMC_RDYI
)
if (sc
->sc_que
.c_cc
== 0)
addr
->bsel0
= getc(&sc
->sc_que
);
while (n
-- && (addr
->bsel0
&DMC_RDYI
) == 0)
* DMC interface transmitter interrupt.
* A transfer has completed, check for errors.
* If it was a read, notify appropriate protocol.
* If it was a write, pull the next one off the queue.
register struct dmc_softc
*sc
;
struct uba_device
*ui
= dmcinfo
[unit
];
register struct ifqueue
*inq
;
addr
= (struct dmcdevice
*)ui
->ui_addr
;
addr
->bsel2
&= ~DMC_RDYO
;
* A read has completed. Purge input buffered
* data path. Pass packet to type specific
* higher-level input routine.
if (sc
->sc_ifuba
.ifuba_flags
& UBA_NEEDBDP
)
UBAPURGE(sc
->sc_ifuba
.ifu_uba
,
sc
->sc_ifuba
.ifu_r
.ifrw_bdp
);
printd(" read done, len %d\n", len
);
switch (ui
->ui_flags
& DMC_AF
) {
printf("dmc%d: unknown address type %d\n", unit
,
m
= if_rubaget(&sc
->sc_ifuba
, len
, 0);
arg
= sc
->sc_ifuba
.ifu_r
.ifrw_info
& 0x3ffff;
dmcload(sc
, DMC_READ
, arg
, ((arg
>> 2) & DMC_XMEM
) | DMCMTU
);
* A write has completed, start another
* transfer if there is more data to send.
return; /* SHOULD IT BE A FATAL ERROR? */
if (sc
->sc_ifuba
.ifu_xtofree
) {
(void) m_freem(sc
->sc_ifuba
.ifu_xtofree
);
sc
->sc_ifuba
.ifu_xtofree
= 0;
if (sc
->sc_if
.if_snd
.ifq_head
== 0)
/*** DO SOMETHING TO RESTART DEVICE ***/
printf("DMC FATAL ERROR 0%o\n", arg
);
/* ACCUMULATE STATISTICS */
printf("DMC SOFT ERROR 0%o\n", arg
);
printf("dmc%d: bad control %o\n", unit
, cmd
);
* Just send the data, header was supplied by
* upper level protocol routines.
register struct ifnet
*ifp
;
struct uba_device
*ui
= dmcinfo
[ifp
->if_unit
];
if (dst
->sa_family
!= (ui
->ui_flags
& DMC_AF
)) {
printf("dmc%d: af%d not supported\n", ifp
->if_unit
, pf
);
if (IF_QFULL(&ifp
->if_snd
)) {
IF_ENQUEUE(&ifp
->if_snd
, m
);
if (dmc_softc
[ifp
->if_unit
].sc_oactive
== 0)