2005-08-05 11:53:08 +02:00
|
|
|
/*
|
|
|
|
* dp8390.c
|
|
|
|
*
|
|
|
|
* This file contains a ethernet device driver for NS dp8390 based ethernet
|
|
|
|
* cards.
|
|
|
|
*
|
|
|
|
* Created: before Dec 28, 1992 by Philip Homburg <philip@f-mnx.phicoh.com>
|
|
|
|
*
|
|
|
|
* Modified Mar 10 1994 by Philip Homburg
|
|
|
|
* Become a generic dp8390 driver.
|
|
|
|
*
|
|
|
|
* Modified Dec 20 1996 by G. Falzoni <falzoni@marina.scn.de>
|
|
|
|
* Added support for 3c503 boards.
|
|
|
|
*/
|
|
|
|
|
2010-03-22 22:25:22 +01:00
|
|
|
#include <minix/drivers.h>
|
2010-04-08 15:41:35 +02:00
|
|
|
#include <minix/netdriver.h>
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <minix/com.h>
|
2009-09-29 20:47:56 +02:00
|
|
|
#include <minix/endpoint.h>
|
2010-04-08 15:41:35 +02:00
|
|
|
#include <minix/ds.h>
|
2005-08-05 11:53:08 +02:00
|
|
|
#include <net/hton.h>
|
|
|
|
#include <net/gen/ether.h>
|
|
|
|
#include <net/gen/eth_io.h>
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/vm.h>
|
2012-03-07 23:57:34 +01:00
|
|
|
#include <sys/mman.h>
|
2005-08-05 11:53:08 +02:00
|
|
|
#include "assert.h"
|
|
|
|
|
|
|
|
#include "local.h"
|
|
|
|
#include "dp8390.h"
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
static dpeth_t de_state;
|
|
|
|
static int de_instance;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2008-12-11 15:42:23 +01:00
|
|
|
u32_t system_hz;
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/* Configuration */
|
|
|
|
typedef struct dp_conf
|
|
|
|
{
|
|
|
|
port_t dpc_port;
|
|
|
|
int dpc_irq;
|
|
|
|
phys_bytes dpc_mem;
|
|
|
|
} dp_conf_t;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
#define DP_CONF_NR 4
|
2012-03-25 20:25:53 +02:00
|
|
|
static dp_conf_t dp_conf[DP_CONF_NR]= /* Card addresses */
|
2005-08-05 11:53:08 +02:00
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
/* I/O port, IRQ, Buffer address. */
|
|
|
|
{ 0x280, 3, 0xD0000, },
|
|
|
|
{ 0x300, 5, 0xC8000, },
|
|
|
|
{ 0x380, 10, 0xD8000, },
|
|
|
|
{ 0x000, 0, 0x00000, },
|
2005-08-05 11:53:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Card inits configured out? */
|
|
|
|
#if !ENABLE_WDETH
|
|
|
|
#define wdeth_probe(dep) (0)
|
|
|
|
#endif
|
|
|
|
#if !ENABLE_NE2000
|
|
|
|
#define ne_probe(dep) (0)
|
|
|
|
#endif
|
|
|
|
#if !ENABLE_3C503
|
|
|
|
#define el2_probe(dep) (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Some clones of the dp8390 and the PC emulator 'Bochs' require the CR_STA
|
|
|
|
* on writes to the CR register. Additional CR_STAs do not appear to hurt
|
|
|
|
* genuine dp8390s
|
|
|
|
*/
|
|
|
|
#define CR_EXTRA CR_STA
|
|
|
|
|
|
|
|
#if ENABLE_PCI
|
2012-03-24 16:16:34 +01:00
|
|
|
static void pci_conf(void);
|
2005-08-05 11:53:08 +02:00
|
|
|
#endif
|
2012-03-24 16:16:34 +01:00
|
|
|
static void do_vwrite_s(message *mp, int from_int);
|
|
|
|
static void do_vread_s(message *mp);
|
|
|
|
static void do_init(message *mp);
|
|
|
|
static void do_int(dpeth_t *dep);
|
|
|
|
static void do_getstat_s(message *mp);
|
|
|
|
static void dp_stop(dpeth_t *dep);
|
|
|
|
static void dp_init(dpeth_t *dep);
|
|
|
|
static void dp_confaddr(dpeth_t *dep);
|
|
|
|
static void dp_reinit(dpeth_t *dep);
|
|
|
|
static void dp_reset(dpeth_t *dep);
|
|
|
|
static void dp_check_ints(dpeth_t *dep);
|
|
|
|
static void dp_recv(dpeth_t *dep);
|
|
|
|
static void dp_send(dpeth_t *dep);
|
|
|
|
static void dp_getblock(dpeth_t *dep, int page, size_t offset, size_t
|
|
|
|
size, void *dst);
|
|
|
|
static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset,
|
|
|
|
size_t size, void *dst);
|
|
|
|
static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset,
|
|
|
|
size_t size, void *dst);
|
|
|
|
static int dp_pkt2user_s(dpeth_t *dep, int page, vir_bytes length);
|
|
|
|
static void dp_user2nic_s(dpeth_t *dep, iovec_dat_s_t *iovp, vir_bytes
|
|
|
|
offset, int nic_addr, vir_bytes count);
|
|
|
|
static void dp_pio8_user2nic_s(dpeth_t *dep, iovec_dat_s_t *iovp,
|
|
|
|
vir_bytes offset, int nic_addr, vir_bytes count);
|
|
|
|
static void dp_pio16_user2nic_s(dpeth_t *dep, iovec_dat_s_t *iovp,
|
|
|
|
vir_bytes offset, int nic_addr, vir_bytes count);
|
|
|
|
static void dp_nic2user_s(dpeth_t *dep, int nic_addr, iovec_dat_s_t
|
|
|
|
*iovp, vir_bytes offset, vir_bytes count);
|
|
|
|
static void dp_pio8_nic2user_s(dpeth_t *dep, int nic_addr, iovec_dat_s_t
|
|
|
|
*iovp, vir_bytes offset, vir_bytes count);
|
|
|
|
static void dp_pio16_nic2user_s(dpeth_t *dep, int nic_addr,
|
|
|
|
iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count);
|
|
|
|
static void dp_next_iovec_s(iovec_dat_s_t *iovp);
|
|
|
|
static void conf_hw(dpeth_t *dep);
|
|
|
|
static void update_conf(dpeth_t *dep, dp_conf_t *dcp);
|
|
|
|
static void map_hw_buffer(dpeth_t *dep);
|
|
|
|
static int calc_iovec_size_s(iovec_dat_s_t *iovp);
|
|
|
|
static void reply(dpeth_t *dep);
|
|
|
|
static void mess_reply(message *req, message *reply);
|
|
|
|
static void get_userdata_s(int user_proc, cp_grant_id_t grant, vir_bytes
|
|
|
|
offset, vir_bytes count, void *loc_addr);
|
|
|
|
static void put_userdata_s(int user_proc, cp_grant_id_t grant, size_t
|
|
|
|
count, void *loc_addr);
|
|
|
|
static void insb(port_t port, void *buf, size_t size);
|
|
|
|
static void insw(port_t port, void *buf, size_t size);
|
|
|
|
static void do_vir_insb(port_t port, int proc, vir_bytes buf, size_t
|
|
|
|
size);
|
|
|
|
static void do_vir_insw(port_t port, int proc, vir_bytes buf, size_t
|
|
|
|
size);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-04-08 15:41:35 +02:00
|
|
|
/* SEF functions and variables. */
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sef_local_startup(void);
|
|
|
|
static int sef_cb_init_fresh(int type, sef_init_info_t *info);
|
|
|
|
static void sef_cb_signal_handler(int signo);
|
2010-04-08 15:41:35 +02:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static void handle_hw_intr(void)
|
2009-09-29 20:47:56 +02:00
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
int r, irq;
|
2009-09-29 20:47:56 +02:00
|
|
|
dpeth_t *dep;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
dep = &de_state;
|
|
|
|
|
|
|
|
if (dep->de_mode != DEM_ENABLED)
|
|
|
|
return;
|
|
|
|
assert(dep->de_flags & DEF_ENABLED);
|
|
|
|
irq= dep->de_irq;
|
|
|
|
assert(irq >= 0 && irq < NR_IRQ_VECTORS);
|
|
|
|
if (dep->de_int_pending || 1)
|
|
|
|
{
|
|
|
|
dep->de_int_pending= 0;
|
|
|
|
dp_check_ints(dep);
|
|
|
|
do_int(dep);
|
|
|
|
r= sys_irqenable(&dep->de_hook);
|
|
|
|
if (r != OK) {
|
|
|
|
panic("unable enable interrupts: %d", r);
|
2009-09-29 20:47:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dpeth_task *
|
|
|
|
*===========================================================================*/
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
message m;
|
2010-04-08 15:41:35 +02:00
|
|
|
int ipc_status;
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
int r;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* SEF local startup. */
|
2005-08-05 16:20:05 +02:00
|
|
|
env_setargs(argc, argv);
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
sef_local_startup();
|
2005-10-21 19:09:08 +02:00
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
while (TRUE)
|
|
|
|
{
|
2010-04-08 15:41:35 +02:00
|
|
|
if ((r= netdriver_receive(ANY, &m, &ipc_status)) != OK)
|
|
|
|
panic("dp8390: netdriver_receive failed: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-04-08 15:41:35 +02:00
|
|
|
if (is_ipc_notify(ipc_status)) {
|
2009-09-29 20:47:56 +02:00
|
|
|
switch (_ENDPOINT_P(m.m_source)) {
|
|
|
|
case HARDWARE:
|
2010-05-18 00:22:53 +02:00
|
|
|
handle_hw_intr();
|
2009-09-29 20:47:56 +02:00
|
|
|
break;
|
|
|
|
case CLOCK:
|
|
|
|
printf("dp8390: notify from CLOCK\n");
|
|
|
|
break;
|
|
|
|
default:
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: illegal notify from: %d",
|
|
|
|
m.m_source);
|
2009-09-29 20:47:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* done, get a new message */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
switch (m.m_type)
|
|
|
|
{
|
2006-07-10 14:43:38 +02:00
|
|
|
case DL_WRITEV_S: do_vwrite_s(&m, FALSE); break;
|
|
|
|
case DL_READV_S: do_vread_s(&m); break;
|
|
|
|
case DL_CONF: do_init(&m); break;
|
|
|
|
case DL_GETSTAT_S: do_getstat_s(&m); break;
|
2005-08-05 11:53:08 +02:00
|
|
|
default:
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: illegal message: %d", m.m_type);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_local_startup *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sef_local_startup()
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
{
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/* Register init callbacks. */
|
|
|
|
sef_setcb_init_fresh(sef_cb_init_fresh);
|
2010-04-08 15:41:35 +02:00
|
|
|
sef_setcb_init_lu(sef_cb_init_fresh);
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
sef_setcb_init_restart(sef_cb_init_fresh);
|
|
|
|
|
2010-04-08 15:41:35 +02:00
|
|
|
/* Register live update callbacks. */
|
|
|
|
sef_setcb_lu_prepare(sef_cb_lu_prepare_always_ready);
|
|
|
|
sef_setcb_lu_state_isvalid(sef_cb_lu_state_isvalid_workfree);
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
|
New RS and new signal handling for system processes.
UPDATING INFO:
20100317:
/usr/src/etc/system.conf updated to ignore default kernel calls: copy
it (or merge it) to /etc/system.conf.
The hello driver (/dev/hello) added to the distribution:
# cd /usr/src/commands/scripts && make clean install
# cd /dev && MAKEDEV hello
KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.
PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.
SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.
VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().
RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.
DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.
DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
2010-03-17 02:15:29 +01:00
|
|
|
/* Register signal callbacks. */
|
|
|
|
sef_setcb_signal_handler(sef_cb_signal_handler);
|
|
|
|
|
Basic System Event Framework (SEF) with ping and live update.
SYSLIB CHANGES:
- SEF must be used by every system process and is thereby part of the system
library.
- The framework provides a receive() interface (sef_receive) for system
processes to automatically catch known system even messages and process them.
- SEF provides a default behavior for each type of system event, but allows
system processes to register callbacks to override the default behavior.
- Custom (local to the process) or predefined (provided by SEF) callback
implementations can be registered to SEF.
- SEF currently includes support for 2 types of system events:
1. SEF Ping. The event occurs every time RS sends a ping to figure out
whether a system process is still alive. The default callback implementation
provided by SEF is to notify RS back to let it know the process is alive
and kicking.
2. SEF Live update. The event occurs every time RS sends a prepare to update
message to let a system process know an update is available and to prepare
for it. The live update support is very basic for now. SEF only deals with
verifying if the prepare state can be supported by the process, dumping the
state for debugging purposes, and providing an event-driven programming
model to the process to react to state changes check-in when ready to update.
- SEF should be extended in the future to integrate support for more types of
system events. Ideally, all the cross-cutting concerns should be integrated into
SEF to avoid duplicating code and ease extensibility. Examples include:
* PM notify messages primarily used at shutdown.
* SYSTEM notify messages primarily used for signals.
* CLOCK notify messages used for system alarms.
* Debug messages. IS could still be in charge of fkey handling but would
forward the debug message to the target process (e.g. PM, if the user
requested debug information about PM). SEF would then catch the message and
do nothing unless the process has registered an appropriate callback to
deal with the event. This simplifies the programming model to print debug
information, avoids duplicating code, and reduces the effort to print
debug information.
SYSTEM PROCESSES CHANGES:
- Every system process registers SEF callbacks it needs to override the default
system behavior and calls sef_startup() right after being started.
- sef_startup() does almost nothing now, but will be extended in the future to
support callbacks of its own to let RS control and synchronize with every
system process at initialization time.
- Every system process calls sef_receive() now rather than receive() directly,
to let SEF handle predefined system events.
RS CHANGES:
- RS supports a basic single-component live update protocol now, as follows:
* When an update command is issued (via "service update *"), RS notifies the
target system process to prepare for a specific update state.
* If the process doesn't respond back in time, the update is aborted.
* When the process responds back, RS kills it and marks it for refreshing.
* The process is then automatically restarted as for a buggy process and can
start running again.
* Live update is currently prototyped as a controlled failure.
2009-12-21 15:12:21 +01:00
|
|
|
/* Let SEF perform startup. */
|
|
|
|
sef_startup();
|
|
|
|
}
|
|
|
|
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_cb_init_fresh *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int sef_cb_init_fresh(int type, sef_init_info_t *UNUSED(info))
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
{
|
|
|
|
/* Initialize the dp8390 driver. */
|
|
|
|
dpeth_t *dep;
|
|
|
|
long v;
|
|
|
|
|
|
|
|
system_hz = sys_hz();
|
|
|
|
|
2010-03-05 16:05:11 +01:00
|
|
|
if (env_argc < 1) {
|
|
|
|
panic("A head which at this time has no name");
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
}
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
v = 0;
|
|
|
|
(void) env_parse("instance", "d", 0, &v, 0, 255);
|
|
|
|
de_instance = (int) v;
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
dep = &de_state;
|
|
|
|
|
|
|
|
strcpy(dep->de_name, "dp8390#0");
|
|
|
|
dep->de_name[7] += de_instance;
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
|
2010-04-08 15:41:35 +02:00
|
|
|
/* Announce we are up! */
|
|
|
|
netdriver_announce();
|
Initialization protocol for system services.
SYSLIB CHANGES:
- SEF framework now supports a new SEF Init request type from RS. 3 different
callbacks are available (init_fresh, init_lu, init_restart) to specify
initialization code when a service starts fresh, starts after a live update,
or restarts.
SYSTEM SERVICE CHANGES:
- Initialization code for system services is now enclosed in a callback SEF will
automatically call at init time. The return code of the callback will
tell RS whether the initialization completed successfully.
- Each init callback can access information passed by RS to initialize. As of
now, each system service has access to the public entries of RS's system process
table to gather all the information required to initialize. This design
eliminates many existing or potential races at boot time and provides a uniform
initialization interface to system services. The same interface will be reused
for the upcoming publish/subscribe model to handle dynamic
registration / deregistration of system services.
VM CHANGES:
- Uniform privilege management for all system services. Every service uses the
same call mask format. For boot services, VM copies the call mask from init
data. For dynamic services, VM still receives the call mask via rs_set_priv
call that will be soon replaced by the upcoming publish/subscribe model.
RS CHANGES:
- The system process table has been reorganized and split into private entries
and public entries. Only the latter ones are exposed to system services.
- VM call masks are now entirely configured in rs/table.c
- RS has now its own slot in the system process table. Only kernel tasks and
user processes not included in the boot image are now left out from the system
process table.
- RS implements the initialization protocol for system services.
- For services in the boot image, RS blocks till initialization is complete and
panics when failure is reported back. Services are initialized in their order of
appearance in the boot image priv table and RS blocks to implements synchronous
initialization for every system service having the flag SF_SYNCH_BOOT set.
- For services started dynamically, the initialization protocol is implemented
as though it were the first ping for the service. In this case, if the
system service fails to report back (or reports failure), RS brings the service
down rather than trying to restart it.
2010-01-08 02:20:42 +01:00
|
|
|
|
|
|
|
return(OK);
|
|
|
|
}
|
|
|
|
|
New RS and new signal handling for system processes.
UPDATING INFO:
20100317:
/usr/src/etc/system.conf updated to ignore default kernel calls: copy
it (or merge it) to /etc/system.conf.
The hello driver (/dev/hello) added to the distribution:
# cd /usr/src/commands/scripts && make clean install
# cd /dev && MAKEDEV hello
KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.
PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.
SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.
VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().
RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.
DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.
DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
2010-03-17 02:15:29 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* sef_cb_signal_handler *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void sef_cb_signal_handler(int signo)
|
New RS and new signal handling for system processes.
UPDATING INFO:
20100317:
/usr/src/etc/system.conf updated to ignore default kernel calls: copy
it (or merge it) to /etc/system.conf.
The hello driver (/dev/hello) added to the distribution:
# cd /usr/src/commands/scripts && make clean install
# cd /dev && MAKEDEV hello
KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.
PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.
SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.
VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().
RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.
DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.
DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
2010-03-17 02:15:29 +01:00
|
|
|
{
|
|
|
|
/* Only check for termination signal, ignore anything else. */
|
|
|
|
if (signo != SIGTERM) return;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
if (de_state.de_mode == DEM_ENABLED)
|
|
|
|
dp_stop(&de_state);
|
New RS and new signal handling for system processes.
UPDATING INFO:
20100317:
/usr/src/etc/system.conf updated to ignore default kernel calls: copy
it (or merge it) to /etc/system.conf.
The hello driver (/dev/hello) added to the distribution:
# cd /usr/src/commands/scripts && make clean install
# cd /dev && MAKEDEV hello
KERNEL CHANGES:
- Generic signal handling support. The kernel no longer assumes PM as a signal
manager for every process. The signal manager of a given process can now be
specified in its privilege slot. When a signal has to be delivered, the kernel
performs the lookup and forwards the signal to the appropriate signal manager.
PM is the default signal manager for user processes, RS is the default signal
manager for system processes. To enable ptrace()ing for system processes, it
is sufficient to change the default signal manager to PM. This will temporarily
disable crash recovery, though.
- sys_exit() is now split into sys_exit() (i.e. exit() for system processes,
which generates a self-termination signal), and sys_clear() (i.e. used by PM
to ask the kernel to clear a process slot when a process exits).
- Added a new kernel call (i.e. sys_update()) to swap two process slots and
implement live update.
PM CHANGES:
- Posix signal handling is no longer allowed for system processes. System
signals are split into two fixed categories: termination and non-termination
signals. When a non-termination signaled is processed, PM transforms the signal
into an IPC message and delivers the message to the system process. When a
termination signal is processed, PM terminates the process.
- PM no longer assumes itself as the signal manager for system processes. It now
makes sure that every system signal goes through the kernel before being
actually processes. The kernel will then dispatch the signal to the appropriate
signal manager which may or may not be PM.
SYSLIB CHANGES:
- Simplified SEF init and LU callbacks.
- Added additional predefined SEF callbacks to debug crash recovery and
live update.
- Fixed a temporary ack in the SEF init protocol. SEF init reply is now
completely synchronous.
- Added SEF signal event type to provide a uniform interface for system
processes to deal with signals. A sef_cb_signal_handler() callback is
available for system processes to handle every received signal. A
sef_cb_signal_manager() callback is used by signal managers to process
system signals on behalf of the kernel.
- Fixed a few bugs with memory mapping and DS.
VM CHANGES:
- Page faults and memory requests coming from the kernel are now implemented
using signals.
- Added a new VM call to swap two process slots and implement live update.
- The call is used by RS at update time and in turn invokes the kernel call
sys_update().
RS CHANGES:
- RS has been reworked with a better functional decomposition.
- Better kernel call masks. com.h now defines the set of very basic kernel calls
every system service is allowed to use. This makes system.conf simpler and
easier to maintain. In addition, this guarantees a higher level of isolation
for system libraries that use one or more kernel calls internally (e.g. printf).
- RS is the default signal manager for system processes. By default, RS
intercepts every signal delivered to every system process. This makes crash
recovery possible before bringing PM and friends in the loop.
- RS now supports fast rollback when something goes wrong while initializing
the new version during a live update.
- Live update is now implemented by keeping the two versions side-by-side and
swapping the process slots when the old version is ready to update.
- Crash recovery is now implemented by keeping the two versions side-by-side
and cleaning up the old version only when the recovery process is complete.
DS CHANGES:
- Fixed a bug when the process doing ds_publish() or ds_delete() is not known
by DS.
- Fixed the completely broken support for strings. String publishing is now
implemented in the system library and simply wraps publishing of memory ranges.
Ideally, we should adopt a similar approach for other data types as well.
- Test suite fixed.
DRIVER CHANGES:
- The hello driver has been added to the Minix distribution to demonstrate basic
live update and crash recovery functionalities.
- Other drivers have been adapted to conform the new SEF interface.
2010-03-17 02:15:29 +01:00
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
#if 0
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp8390_dump *
|
|
|
|
*===========================================================================*/
|
|
|
|
void dp8390_dump()
|
|
|
|
{
|
|
|
|
dpeth_t *dep;
|
2010-05-18 00:22:53 +02:00
|
|
|
int isr;
|
|
|
|
|
|
|
|
dep = &de_state;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
#if XXX
|
2010-05-18 00:22:53 +02:00
|
|
|
if (dep->de_mode == DEM_DISABLED)
|
|
|
|
printf("dp8390 instance %d is disabled\n", de_instance);
|
|
|
|
else if (dep->de_mode == DEM_SINK)
|
|
|
|
printf("dp8390 instance %d is in sink mode\n", de_instance);
|
2005-08-05 11:53:08 +02:00
|
|
|
#endif
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
if (dep->de_mode != DEM_ENABLED)
|
|
|
|
return;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
printf("dp8390 statistics of instance %d:\n", de_instance);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
printf("recvErr :%8ld\t", dep->de_stat.ets_recvErr);
|
|
|
|
printf("sendErr :%8ld\t", dep->de_stat.ets_sendErr);
|
|
|
|
printf("OVW :%8ld\n", dep->de_stat.ets_OVW);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
printf("CRCerr :%8ld\t", dep->de_stat.ets_CRCerr);
|
|
|
|
printf("frameAll :%8ld\t", dep->de_stat.ets_frameAll);
|
|
|
|
printf("missedP :%8ld\n", dep->de_stat.ets_missedP);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
printf("packetR :%8ld\t", dep->de_stat.ets_packetR);
|
|
|
|
printf("packetT :%8ld\t", dep->de_stat.ets_packetT);
|
|
|
|
printf("transDef :%8ld\n", dep->de_stat.ets_transDef);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
printf("collision :%8ld\t", dep->de_stat.ets_collision);
|
|
|
|
printf("transAb :%8ld\t", dep->de_stat.ets_transAb);
|
|
|
|
printf("carrSense :%8ld\n", dep->de_stat.ets_carrSense);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
printf("fifoUnder :%8ld\t", dep->de_stat.ets_fifoUnder);
|
|
|
|
printf("fifoOver :%8ld\t", dep->de_stat.ets_fifoOver);
|
|
|
|
printf("CDheartbeat:%8ld\n", dep->de_stat.ets_CDheartbeat);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
printf("OWC :%8ld\t", dep->de_stat.ets_OWC);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
isr= inb_reg0(dep, DP_ISR);
|
|
|
|
printf("dp_isr = 0x%x + 0x%x, de_flags = 0x%x\n", isr,
|
|
|
|
inb_reg0(dep, DP_ISR), dep->de_flags);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLE_PCI
|
|
|
|
/*===========================================================================*
|
|
|
|
* pci_conf *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void pci_conf()
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
char envvar[16];
|
2005-08-05 11:53:08 +02:00
|
|
|
struct dpeth *dep;
|
2012-03-07 00:49:16 +01:00
|
|
|
int i, pci_instance;
|
2005-08-05 11:53:08 +02:00
|
|
|
static int first_time= 1;
|
|
|
|
|
|
|
|
if (!first_time)
|
|
|
|
return;
|
|
|
|
first_time= 0;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
dep= &de_state;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
strcpy(envvar, "DPETH0");
|
|
|
|
envvar[5] += de_instance;
|
|
|
|
if (!(dep->de_pci= env_prefix(envvar, "pci")))
|
|
|
|
return; /* no PCI config */
|
2012-03-07 00:49:16 +01:00
|
|
|
|
|
|
|
/* Count the number of dp instances before this one that are configured
|
|
|
|
* for PCI, so that we can skip that many when enumerating PCI devices.
|
|
|
|
*/
|
|
|
|
pci_instance= 0;
|
|
|
|
for (i= 0; i < de_instance; i++) {
|
|
|
|
envvar[5]= i;
|
|
|
|
if (env_prefix(envvar, "pci"))
|
|
|
|
pci_instance++;
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
2012-03-07 00:49:16 +01:00
|
|
|
if (!rtl_probe(dep, pci_instance))
|
2010-05-18 00:22:53 +02:00
|
|
|
dep->de_pci= -1;
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
2010-05-18 00:22:53 +02:00
|
|
|
#endif /* ENABLE_PCI */
|
2005-08-05 11:53:08 +02:00
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_vwrite_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void do_vwrite_s(mp, from_int)
|
|
|
|
message *mp;
|
|
|
|
int from_int;
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
int count, size;
|
2006-07-10 14:43:38 +02:00
|
|
|
int sendq_head;
|
|
|
|
dpeth_t *dep;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
dep= &de_state;
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
count = mp->DL_COUNT;
|
2010-05-18 00:22:53 +02:00
|
|
|
dep->de_client= mp->m_source;
|
2006-07-10 14:43:38 +02:00
|
|
|
|
|
|
|
if (dep->de_mode == DEM_SINK)
|
|
|
|
{
|
|
|
|
assert(!from_int);
|
|
|
|
dep->de_flags |= DEF_PACK_SEND;
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(dep);
|
2006-07-10 14:43:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(dep->de_mode == DEM_ENABLED);
|
|
|
|
assert(dep->de_flags & DEF_ENABLED);
|
|
|
|
if (dep->de_flags & DEF_SEND_AVAIL)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: send already in progress");
|
2006-07-10 14:43:38 +02:00
|
|
|
|
|
|
|
sendq_head= dep->de_sendq_head;
|
|
|
|
if (dep->de_sendq[sendq_head].sq_filled)
|
|
|
|
{
|
|
|
|
if (from_int)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: should not be sending");
|
2006-07-10 14:43:38 +02:00
|
|
|
dep->de_sendmsg= *mp;
|
|
|
|
dep->de_flags |= DEF_SEND_AVAIL;
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(dep);
|
2006-07-10 14:43:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(!(dep->de_flags & DEF_PACK_SEND));
|
|
|
|
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
get_userdata_s(mp->m_source, mp->DL_GRANT, 0,
|
2006-07-10 14:43:38 +02:00
|
|
|
(count > IOVEC_NR ? IOVEC_NR : count) *
|
|
|
|
sizeof(dep->de_write_iovec_s.iod_iovec[0]),
|
|
|
|
dep->de_write_iovec_s.iod_iovec);
|
|
|
|
dep->de_write_iovec_s.iod_iovec_s = count;
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
dep->de_write_iovec_s.iod_proc_nr = mp->m_source;
|
2006-07-10 14:43:38 +02:00
|
|
|
dep->de_write_iovec_s.iod_grant = mp->DL_GRANT;
|
|
|
|
dep->de_write_iovec_s.iod_iovec_offset = 0;
|
|
|
|
|
|
|
|
dep->de_tmp_iovec_s = dep->de_write_iovec_s;
|
|
|
|
size = calc_iovec_size_s(&dep->de_tmp_iovec_s);
|
|
|
|
|
|
|
|
if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: invalid packet size: %d", size);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
(dep->de_user2nicf_s)(dep, &dep->de_write_iovec_s, 0,
|
|
|
|
dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE,
|
|
|
|
size);
|
|
|
|
dep->de_sendq[sendq_head].sq_filled= TRUE;
|
|
|
|
if (dep->de_sendq_tail == sendq_head)
|
|
|
|
{
|
|
|
|
outb_reg0(dep, DP_TPSR, dep->de_sendq[sendq_head].sq_sendpage);
|
|
|
|
outb_reg0(dep, DP_TBCR1, size >> 8);
|
|
|
|
outb_reg0(dep, DP_TBCR0, size & 0xff);
|
|
|
|
outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);/* there it goes.. */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dep->de_sendq[sendq_head].sq_size= size;
|
|
|
|
|
|
|
|
if (++sendq_head == dep->de_sendq_nr)
|
|
|
|
sendq_head= 0;
|
|
|
|
assert(sendq_head < SENDQ_NR);
|
|
|
|
dep->de_sendq_head= sendq_head;
|
|
|
|
|
|
|
|
dep->de_flags |= DEF_PACK_SEND;
|
|
|
|
|
|
|
|
/* If the interrupt handler called, don't send a reply. The reply
|
|
|
|
* will be sent after all interrupts are handled.
|
|
|
|
*/
|
|
|
|
if (from_int)
|
|
|
|
return;
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(dep);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
assert(dep->de_mode == DEM_ENABLED);
|
|
|
|
assert(dep->de_flags & DEF_ENABLED);
|
|
|
|
}
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_vread_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void do_vread_s(mp)
|
|
|
|
message *mp;
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
int count;
|
2006-07-10 14:43:38 +02:00
|
|
|
int size;
|
|
|
|
dpeth_t *dep;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
dep= &de_state;
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
count = mp->DL_COUNT;
|
2010-05-18 00:22:53 +02:00
|
|
|
dep->de_client= mp->m_source;
|
2006-07-10 14:43:38 +02:00
|
|
|
if (dep->de_mode == DEM_SINK)
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(dep);
|
2006-07-10 14:43:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(dep->de_mode == DEM_ENABLED);
|
|
|
|
assert(dep->de_flags & DEF_ENABLED);
|
|
|
|
|
|
|
|
if(dep->de_flags & DEF_READING)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: read already in progress");
|
2006-07-10 14:43:38 +02:00
|
|
|
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
get_userdata_s(mp->m_source, mp->DL_GRANT, 0,
|
2006-07-10 14:43:38 +02:00
|
|
|
(count > IOVEC_NR ? IOVEC_NR : count) *
|
|
|
|
sizeof(dep->de_read_iovec_s.iod_iovec[0]),
|
|
|
|
dep->de_read_iovec_s.iod_iovec);
|
|
|
|
dep->de_read_iovec_s.iod_iovec_s = count;
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
dep->de_read_iovec_s.iod_proc_nr = mp->m_source;
|
2006-07-10 14:43:38 +02:00
|
|
|
dep->de_read_iovec_s.iod_grant = mp->DL_GRANT;
|
|
|
|
dep->de_read_iovec_s.iod_iovec_offset = 0;
|
|
|
|
|
|
|
|
dep->de_tmp_iovec_s = dep->de_read_iovec_s;
|
|
|
|
size= calc_iovec_size_s(&dep->de_tmp_iovec_s);
|
|
|
|
|
|
|
|
if (size < ETH_MAX_PACK_SIZE_TAGGED)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: wrong packet size: %d", size);
|
2006-07-10 14:43:38 +02:00
|
|
|
dep->de_flags |= DEF_READING;
|
|
|
|
|
|
|
|
dp_recv(dep);
|
|
|
|
|
|
|
|
if ((dep->de_flags & (DEF_READING|DEF_STOPPED)) ==
|
|
|
|
(DEF_READING|DEF_STOPPED))
|
|
|
|
{
|
|
|
|
/* The chip is stopped, and all arrived packets are
|
|
|
|
* delivered.
|
|
|
|
*/
|
|
|
|
dp_reset(dep);
|
|
|
|
}
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(dep);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_init *
|
|
|
|
*===========================================================================*/
|
2010-03-30 16:07:15 +02:00
|
|
|
static void do_init(message *mp)
|
2005-08-05 11:53:08 +02:00
|
|
|
{
|
|
|
|
dpeth_t *dep;
|
|
|
|
message reply_mess;
|
|
|
|
|
|
|
|
#if ENABLE_PCI
|
|
|
|
pci_conf(); /* Configure PCI devices. */
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
dep= &de_state;
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
if (dep->de_mode == DEM_DISABLED)
|
|
|
|
{
|
|
|
|
/* This is the default, try to (re)locate the device. */
|
|
|
|
conf_hw(dep);
|
|
|
|
if (dep->de_mode == DEM_DISABLED)
|
|
|
|
{
|
|
|
|
/* Probe failed, or the device is configured off. */
|
2006-07-10 14:43:38 +02:00
|
|
|
reply_mess.m_type= DL_CONF_REPLY;
|
2010-05-18 00:22:53 +02:00
|
|
|
reply_mess.DL_STAT= ENXIO;
|
2005-08-05 11:53:08 +02:00
|
|
|
mess_reply(mp, &reply_mess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (dep->de_mode == DEM_ENABLED)
|
|
|
|
dp_init(dep);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dep->de_mode == DEM_SINK)
|
|
|
|
{
|
|
|
|
strncpy((char *) dep->de_address.ea_addr, "ZDP", 6);
|
2010-05-18 00:22:53 +02:00
|
|
|
dep->de_address.ea_addr[5] = de_instance;
|
2005-08-05 11:53:08 +02:00
|
|
|
dp_confaddr(dep);
|
2006-07-10 14:43:38 +02:00
|
|
|
reply_mess.m_type = DL_CONF_REPLY;
|
2010-05-18 00:22:53 +02:00
|
|
|
reply_mess.DL_STAT = OK;
|
|
|
|
*(ether_addr_t *) reply_mess.DL_HWADDR = dep->de_address;
|
2005-08-05 11:53:08 +02:00
|
|
|
mess_reply(mp, &reply_mess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(dep->de_mode == DEM_ENABLED);
|
|
|
|
assert(dep->de_flags & DEF_ENABLED);
|
|
|
|
|
|
|
|
dep->de_flags &= ~(DEF_PROMISC | DEF_MULTI | DEF_BROAD);
|
|
|
|
|
|
|
|
if (mp->DL_MODE & DL_PROMISC_REQ)
|
|
|
|
dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD;
|
|
|
|
if (mp->DL_MODE & DL_MULTI_REQ)
|
|
|
|
dep->de_flags |= DEF_MULTI;
|
|
|
|
if (mp->DL_MODE & DL_BROAD_REQ)
|
|
|
|
dep->de_flags |= DEF_BROAD;
|
|
|
|
|
|
|
|
dp_reinit(dep);
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
reply_mess.m_type = DL_CONF_REPLY;
|
2010-05-18 00:22:53 +02:00
|
|
|
reply_mess.DL_STAT = OK;
|
|
|
|
*(ether_addr_t *) reply_mess.DL_HWADDR = dep->de_address;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
mess_reply(mp, &reply_mess);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_int *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void do_int(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
if (dep->de_flags & (DEF_PACK_SEND | DEF_PACK_RECV))
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(dep);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_getstat_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void do_getstat_s(mp)
|
|
|
|
message *mp;
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
int r;
|
2006-07-10 14:43:38 +02:00
|
|
|
dpeth_t *dep;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
dep= &de_state;
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
if (dep->de_mode == DEM_SINK)
|
|
|
|
{
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
put_userdata_s(mp->m_source, (vir_bytes) mp->DL_GRANT,
|
2006-07-10 14:43:38 +02:00
|
|
|
(vir_bytes) sizeof(dep->de_stat), &dep->de_stat);
|
2007-04-23 17:38:00 +02:00
|
|
|
|
|
|
|
mp->m_type= DL_STAT_REPLY;
|
|
|
|
r= send(mp->m_source, mp);
|
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_getstat: send failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert(dep->de_mode == DEM_ENABLED);
|
|
|
|
assert(dep->de_flags & DEF_ENABLED);
|
|
|
|
|
|
|
|
dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0);
|
|
|
|
dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1);
|
|
|
|
dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2);
|
|
|
|
|
Server/driver protocols: no longer allow third-party copies.
Before safecopies, the IO_ENDPT and DL_ENDPT message fields were needed
to know which actual process to copy data from/to, as that process may
not always be the caller. Now that we have full safecopy support, these
fields have become useless for that purpose: the owner of the grant is
*always* the caller. Allowing the caller to supply another endpoint is
in fact dangerous, because the callee may then end up using a grant
from a third party. One could call this a variant of the confused
deputy problem.
From now on, safecopy calls should always use the caller's endpoint as
grant owner. This fully obsoletes the DL_ENDPT field in the
inet/ethernet protocol. IO_ENDPT has other uses besides identifying the
grant owner though. This patch renames IO_ENDPT to USER_ENDPT, not only
because that is a more fitting name (it should never be used for I/O
after all), but also in order to intentionally break any old system
source code outside the base system. If this patch breaks your code,
fixing it is fairly simple:
- DL_ENDPT should be replaced with m_source;
- IO_ENDPT should be replaced with m_source when used for safecopies;
- IO_ENDPT should be replaced with USER_ENDPT for any other use, e.g.
when setting REP_ENDPT, matching requests in CANCEL calls, getting
DEV_SELECT flags, and retrieving of the real user process's endpoint
in DEV_OPEN.
The changes in this patch are binary backward compatible.
2011-04-11 19:35:05 +02:00
|
|
|
put_userdata_s(mp->m_source, mp->DL_GRANT,
|
2006-07-10 14:43:38 +02:00
|
|
|
sizeof(dep->de_stat), &dep->de_stat);
|
2007-04-23 17:38:00 +02:00
|
|
|
|
|
|
|
mp->m_type= DL_STAT_REPLY;
|
|
|
|
r= send(mp->m_source, mp);
|
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("do_getstat: send failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
|
2005-10-21 19:09:08 +02:00
|
|
|
/*===========================================================================*
|
2010-05-18 00:22:53 +02:00
|
|
|
* dp_stop *
|
2005-08-05 11:53:08 +02:00
|
|
|
*===========================================================================*/
|
2010-05-18 00:22:53 +02:00
|
|
|
static void dp_stop(dep)
|
|
|
|
dpeth_t *dep;
|
2005-08-05 11:53:08 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
if (dep->de_mode == DEM_SINK)
|
|
|
|
return;
|
|
|
|
assert(dep->de_mode == DEM_ENABLED);
|
|
|
|
|
|
|
|
if (!(dep->de_flags & DEF_ENABLED))
|
|
|
|
return;
|
|
|
|
|
|
|
|
outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
|
|
|
|
(dep->de_stopf)(dep);
|
|
|
|
|
|
|
|
dep->de_flags= DEF_EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_init *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_init(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
int dp_rcr_reg;
|
|
|
|
int i, r;
|
|
|
|
|
|
|
|
/* General initialization */
|
|
|
|
dep->de_flags = DEF_EMPTY;
|
|
|
|
(*dep->de_initf)(dep);
|
|
|
|
|
|
|
|
dp_confaddr(dep);
|
|
|
|
|
|
|
|
if (debug)
|
|
|
|
{
|
|
|
|
printf("%s: Ethernet address ", dep->de_name);
|
|
|
|
for (i= 0; i < 6; i++)
|
|
|
|
printf("%x%c", dep->de_address.ea_addr[i],
|
|
|
|
i < 5 ? ':' : '\n');
|
|
|
|
}
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
/* Map buffer */
|
|
|
|
map_hw_buffer(dep);
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/* Initialization of the dp8390 following the mandatory procedure
|
|
|
|
* in reference manual ("DP8390D/NS32490D NIC Network Interface
|
|
|
|
* Controller", National Semiconductor, July 1995, Page 29).
|
|
|
|
*/
|
|
|
|
/* Step 1: */
|
|
|
|
outb_reg0(dep, DP_CR, CR_PS_P0 | CR_STP | CR_DM_ABORT);
|
|
|
|
/* Step 2: */
|
|
|
|
if (dep->de_16bit)
|
|
|
|
outb_reg0(dep, DP_DCR, DCR_WORDWIDE | DCR_8BYTES | DCR_BMS);
|
|
|
|
else
|
|
|
|
outb_reg0(dep, DP_DCR, DCR_BYTEWIDE | DCR_8BYTES | DCR_BMS);
|
|
|
|
/* Step 3: */
|
|
|
|
outb_reg0(dep, DP_RBCR0, 0);
|
|
|
|
outb_reg0(dep, DP_RBCR1, 0);
|
|
|
|
/* Step 4: */
|
|
|
|
dp_rcr_reg = 0;
|
|
|
|
if (dep->de_flags & DEF_PROMISC)
|
|
|
|
dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
|
|
|
|
if (dep->de_flags & DEF_BROAD)
|
|
|
|
dp_rcr_reg |= RCR_AB;
|
|
|
|
if (dep->de_flags & DEF_MULTI)
|
|
|
|
dp_rcr_reg |= RCR_AM;
|
|
|
|
outb_reg0(dep, DP_RCR, dp_rcr_reg);
|
|
|
|
/* Step 5: */
|
|
|
|
outb_reg0(dep, DP_TCR, TCR_INTERNAL);
|
|
|
|
/* Step 6: */
|
|
|
|
outb_reg0(dep, DP_BNRY, dep->de_startpage);
|
|
|
|
outb_reg0(dep, DP_PSTART, dep->de_startpage);
|
|
|
|
outb_reg0(dep, DP_PSTOP, dep->de_stoppage);
|
|
|
|
/* Step 7: */
|
|
|
|
outb_reg0(dep, DP_ISR, 0xFF);
|
|
|
|
/* Step 8: */
|
|
|
|
outb_reg0(dep, DP_IMR, IMR_PRXE | IMR_PTXE | IMR_RXEE | IMR_TXEE |
|
|
|
|
IMR_OVWE | IMR_CNTE);
|
|
|
|
/* Step 9: */
|
|
|
|
outb_reg0(dep, DP_CR, CR_PS_P1 | CR_DM_ABORT | CR_STP);
|
|
|
|
|
|
|
|
outb_reg1(dep, DP_PAR0, dep->de_address.ea_addr[0]);
|
|
|
|
outb_reg1(dep, DP_PAR1, dep->de_address.ea_addr[1]);
|
|
|
|
outb_reg1(dep, DP_PAR2, dep->de_address.ea_addr[2]);
|
|
|
|
outb_reg1(dep, DP_PAR3, dep->de_address.ea_addr[3]);
|
|
|
|
outb_reg1(dep, DP_PAR4, dep->de_address.ea_addr[4]);
|
|
|
|
outb_reg1(dep, DP_PAR5, dep->de_address.ea_addr[5]);
|
|
|
|
|
|
|
|
outb_reg1(dep, DP_MAR0, 0xff);
|
|
|
|
outb_reg1(dep, DP_MAR1, 0xff);
|
|
|
|
outb_reg1(dep, DP_MAR2, 0xff);
|
|
|
|
outb_reg1(dep, DP_MAR3, 0xff);
|
|
|
|
outb_reg1(dep, DP_MAR4, 0xff);
|
|
|
|
outb_reg1(dep, DP_MAR5, 0xff);
|
|
|
|
outb_reg1(dep, DP_MAR6, 0xff);
|
|
|
|
outb_reg1(dep, DP_MAR7, 0xff);
|
|
|
|
|
|
|
|
outb_reg1(dep, DP_CURR, dep->de_startpage + 1);
|
|
|
|
/* Step 10: */
|
|
|
|
outb_reg0(dep, DP_CR, CR_DM_ABORT | CR_STA);
|
|
|
|
/* Step 11: */
|
|
|
|
outb_reg0(dep, DP_TCR, TCR_NORMAL);
|
|
|
|
|
|
|
|
inb_reg0(dep, DP_CNTR0); /* reset counters by reading */
|
|
|
|
inb_reg0(dep, DP_CNTR1);
|
|
|
|
inb_reg0(dep, DP_CNTR2);
|
|
|
|
|
|
|
|
/* Finish the initialization. */
|
|
|
|
dep->de_flags |= DEF_ENABLED;
|
|
|
|
for (i= 0; i<dep->de_sendq_nr; i++)
|
|
|
|
dep->de_sendq[i].sq_filled= 0;
|
|
|
|
dep->de_sendq_head= 0;
|
|
|
|
dep->de_sendq_tail= 0;
|
|
|
|
if (!dep->de_prog_IO)
|
|
|
|
{
|
2006-07-10 14:43:38 +02:00
|
|
|
dep->de_user2nicf_s= dp_user2nic_s;
|
|
|
|
dep->de_nic2userf_s= dp_nic2user_s;
|
2005-08-05 11:53:08 +02:00
|
|
|
dep->de_getblockf= dp_getblock;
|
|
|
|
}
|
|
|
|
else if (dep->de_16bit)
|
|
|
|
{
|
2006-07-10 14:43:38 +02:00
|
|
|
dep->de_user2nicf_s= dp_pio16_user2nic_s;
|
|
|
|
dep->de_nic2userf_s= dp_pio16_nic2user_s;
|
2005-08-05 11:53:08 +02:00
|
|
|
dep->de_getblockf= dp_pio16_getblock;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-10 14:43:38 +02:00
|
|
|
dep->de_user2nicf_s= dp_pio8_user2nic_s;
|
|
|
|
dep->de_nic2userf_s= dp_pio8_nic2user_s;
|
2005-08-05 11:53:08 +02:00
|
|
|
dep->de_getblockf= dp_pio8_getblock;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the interrupt handler and policy. Do not automatically
|
|
|
|
* reenable interrupts. Return the IRQ line number on interrupts.
|
|
|
|
*/
|
|
|
|
dep->de_hook = dep->de_irq;
|
|
|
|
r= sys_irqsetpolicy(dep->de_irq, 0, &dep->de_hook);
|
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_irqsetpolicy failed: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
r= sys_irqenable(&dep->de_hook);
|
|
|
|
if (r != OK)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("unable enable interrupts: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_confaddr *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_confaddr(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char eakey[16];
|
|
|
|
static char eafmt[]= "x:x:x:x:x:x";
|
|
|
|
long v;
|
|
|
|
|
|
|
|
/* User defined ethernet address? */
|
2010-05-18 00:22:53 +02:00
|
|
|
strcpy(eakey, "DPETH0_EA");
|
|
|
|
eakey[5] += de_instance;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
for (i= 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
v= dep->de_address.ea_addr[i];
|
2005-08-05 16:20:05 +02:00
|
|
|
if (env_parse(eakey, eafmt, i, &v, 0x00L, 0xFFL) != EP_SET)
|
2005-08-05 11:53:08 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dep->de_address.ea_addr[i]= v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != 0 && i != 6) env_panic(eakey); /* It's all or nothing */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_reinit *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_reinit(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
int dp_rcr_reg;
|
|
|
|
|
|
|
|
outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
|
|
|
|
|
|
|
|
dp_rcr_reg = 0;
|
|
|
|
if (dep->de_flags & DEF_PROMISC)
|
|
|
|
dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM;
|
|
|
|
if (dep->de_flags & DEF_BROAD)
|
|
|
|
dp_rcr_reg |= RCR_AB;
|
|
|
|
if (dep->de_flags & DEF_MULTI)
|
|
|
|
dp_rcr_reg |= RCR_AM;
|
|
|
|
outb_reg0(dep, DP_RCR, dp_rcr_reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_reset *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_reset(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Stop chip */
|
|
|
|
outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT);
|
|
|
|
outb_reg0(dep, DP_RBCR0, 0);
|
|
|
|
outb_reg0(dep, DP_RBCR1, 0);
|
|
|
|
for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RST) == 0); i++)
|
|
|
|
; /* Do nothing */
|
|
|
|
outb_reg0(dep, DP_TCR, TCR_1EXTERNAL|TCR_OFST);
|
|
|
|
outb_reg0(dep, DP_CR, CR_STA|CR_DM_ABORT);
|
|
|
|
outb_reg0(dep, DP_TCR, TCR_NORMAL);
|
|
|
|
|
|
|
|
/* Acknowledge the ISR_RDC (remote dma) interrupt. */
|
|
|
|
for (i= 0; i < 0x1000 && ((inb_reg0(dep, DP_ISR) & ISR_RDC) == 0); i++)
|
|
|
|
; /* Do nothing */
|
|
|
|
outb_reg0(dep, DP_ISR, inb_reg0(dep, DP_ISR) & ~ISR_RDC);
|
|
|
|
|
|
|
|
/* Reset the transmit ring. If we were transmitting a packet, we
|
|
|
|
* pretend that the packet is processed. Higher layers will
|
|
|
|
* retransmit if the packet wasn't actually sent.
|
|
|
|
*/
|
|
|
|
dep->de_sendq_head= dep->de_sendq_tail= 0;
|
|
|
|
for (i= 0; i<dep->de_sendq_nr; i++)
|
|
|
|
dep->de_sendq[i].sq_filled= 0;
|
|
|
|
dp_send(dep);
|
|
|
|
dep->de_flags &= ~DEF_STOPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_check_ints *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_check_ints(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
int isr, tsr;
|
|
|
|
int size, sendq_tail;
|
|
|
|
|
|
|
|
if (!(dep->de_flags & DEF_ENABLED))
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: got premature interrupt");
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
isr = inb_reg0(dep, DP_ISR);
|
|
|
|
if (!isr)
|
|
|
|
break;
|
|
|
|
outb_reg0(dep, DP_ISR, isr);
|
|
|
|
if (isr & (ISR_PTX|ISR_TXE))
|
|
|
|
{
|
|
|
|
if (isr & ISR_TXE)
|
|
|
|
{
|
|
|
|
#if DEBUG
|
|
|
|
{ printf("%s: got send Error\n", dep->de_name); }
|
|
|
|
#endif
|
|
|
|
dep->de_stat.ets_sendErr++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tsr = inb_reg0(dep, DP_TSR);
|
|
|
|
|
|
|
|
if (tsr & TSR_PTX) dep->de_stat.ets_packetT++;
|
|
|
|
#if 0 /* Reserved in later manuals, should be ignored */
|
|
|
|
if (!(tsr & TSR_DFR))
|
|
|
|
{
|
|
|
|
/* In most (all?) implementations of
|
|
|
|
* the dp8390, this bit is set
|
|
|
|
* when the packet is not deferred
|
|
|
|
*/
|
|
|
|
dep->de_stat.ets_transDef++;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (tsr & TSR_COL) dep->de_stat.ets_collision++;
|
|
|
|
if (tsr & TSR_ABT) dep->de_stat.ets_transAb++;
|
|
|
|
if (tsr & TSR_CRS) dep->de_stat.ets_carrSense++;
|
|
|
|
if (tsr & TSR_FU
|
|
|
|
&& ++dep->de_stat.ets_fifoUnder <= 10)
|
|
|
|
{
|
|
|
|
printf("%s: fifo underrun\n",
|
|
|
|
dep->de_name);
|
|
|
|
}
|
|
|
|
if (tsr & TSR_CDH
|
|
|
|
&& ++dep->de_stat.ets_CDheartbeat <= 10)
|
|
|
|
{
|
|
|
|
printf("%s: CD heart beat failure\n",
|
|
|
|
dep->de_name);
|
|
|
|
}
|
|
|
|
if (tsr & TSR_OWC) dep->de_stat.ets_OWC++;
|
|
|
|
}
|
|
|
|
sendq_tail= dep->de_sendq_tail;
|
|
|
|
|
|
|
|
if (!(dep->de_sendq[sendq_tail].sq_filled))
|
|
|
|
{
|
|
|
|
/* Software bug? */
|
|
|
|
assert(!debug);
|
|
|
|
|
|
|
|
/* Or hardware bug? */
|
|
|
|
printf(
|
|
|
|
"%s: transmit interrupt, but not sending\n",
|
|
|
|
dep->de_name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
dep->de_sendq[sendq_tail].sq_filled= 0;
|
|
|
|
if (++sendq_tail == dep->de_sendq_nr)
|
|
|
|
sendq_tail= 0;
|
|
|
|
dep->de_sendq_tail= sendq_tail;
|
|
|
|
if (dep->de_sendq[sendq_tail].sq_filled)
|
|
|
|
{
|
|
|
|
size= dep->de_sendq[sendq_tail].sq_size;
|
|
|
|
outb_reg0(dep, DP_TPSR,
|
|
|
|
dep->de_sendq[sendq_tail].sq_sendpage);
|
|
|
|
outb_reg0(dep, DP_TBCR1, size >> 8);
|
|
|
|
outb_reg0(dep, DP_TBCR0, size & 0xff);
|
|
|
|
outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA);
|
|
|
|
}
|
|
|
|
if (dep->de_flags & DEF_SEND_AVAIL)
|
|
|
|
dp_send(dep);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isr & ISR_PRX)
|
|
|
|
{
|
|
|
|
/* Only call dp_recv if there is a read request */
|
|
|
|
if (dep->de_flags & DEF_READING)
|
|
|
|
dp_recv(dep);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isr & ISR_RXE) dep->de_stat.ets_recvErr++;
|
|
|
|
if (isr & ISR_CNT)
|
|
|
|
{
|
|
|
|
dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0);
|
|
|
|
dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1);
|
|
|
|
dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2);
|
|
|
|
}
|
|
|
|
if (isr & ISR_OVW)
|
|
|
|
{
|
|
|
|
dep->de_stat.ets_OVW++;
|
|
|
|
#if 0
|
|
|
|
{ printW(); printf(
|
|
|
|
"%s: got overwrite warning\n", dep->de_name); }
|
|
|
|
#endif
|
|
|
|
if (dep->de_flags & DEF_READING)
|
|
|
|
{
|
|
|
|
printf(
|
|
|
|
"dp_check_ints: strange: overwrite warning and pending read request\n");
|
|
|
|
dp_recv(dep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isr & ISR_RDC)
|
|
|
|
{
|
|
|
|
/* Nothing to do */
|
|
|
|
}
|
|
|
|
if (isr & ISR_RST)
|
|
|
|
{
|
|
|
|
/* this means we got an interrupt but the ethernet
|
|
|
|
* chip is shutdown. We set the flag DEF_STOPPED,
|
|
|
|
* and continue processing arrived packets. When the
|
|
|
|
* receive buffer is empty, we reset the dp8390.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
{ printW(); printf(
|
|
|
|
"%s: NIC stopped\n", dep->de_name); }
|
|
|
|
#endif
|
|
|
|
dep->de_flags |= DEF_STOPPED;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((dep->de_flags & (DEF_READING|DEF_STOPPED)) ==
|
|
|
|
(DEF_READING|DEF_STOPPED))
|
|
|
|
{
|
|
|
|
/* The chip is stopped, and all arrived packets are
|
|
|
|
* delivered.
|
|
|
|
*/
|
|
|
|
dp_reset(dep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_recv *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_recv(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
dp_rcvhdr_t header;
|
|
|
|
unsigned pageno, curr, next;
|
|
|
|
vir_bytes length;
|
|
|
|
int packet_processed, r;
|
|
|
|
u16_t eth_type;
|
|
|
|
|
|
|
|
packet_processed = FALSE;
|
|
|
|
pageno = inb_reg0(dep, DP_BNRY) + 1;
|
|
|
|
if (pageno == dep->de_stoppage) pageno = dep->de_startpage;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
outb_reg0(dep, DP_CR, CR_PS_P1 | CR_EXTRA);
|
|
|
|
curr = inb_reg1(dep, DP_CURR);
|
|
|
|
outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA);
|
|
|
|
|
|
|
|
if (curr == pageno) break;
|
|
|
|
|
|
|
|
(dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header),
|
|
|
|
&header);
|
|
|
|
(dep->de_getblockf)(dep, pageno, sizeof(header) +
|
|
|
|
2*sizeof(ether_addr_t), sizeof(eth_type), ð_type);
|
|
|
|
|
|
|
|
length = (header.dr_rbcl | (header.dr_rbch << 8)) -
|
|
|
|
sizeof(dp_rcvhdr_t);
|
|
|
|
next = header.dr_next;
|
|
|
|
if (length < ETH_MIN_PACK_SIZE ||
|
|
|
|
length > ETH_MAX_PACK_SIZE_TAGGED)
|
|
|
|
{
|
|
|
|
printf("%s: packet with strange length arrived: %d\n",
|
|
|
|
dep->de_name, (int) length);
|
|
|
|
next= curr;
|
|
|
|
}
|
|
|
|
else if (next < dep->de_startpage || next >= dep->de_stoppage)
|
|
|
|
{
|
|
|
|
printf("%s: strange next page\n", dep->de_name);
|
|
|
|
next= curr;
|
|
|
|
}
|
|
|
|
else if (header.dr_status & RSR_FO)
|
|
|
|
{
|
|
|
|
/* This is very serious, so we issue a warning and
|
|
|
|
* reset the buffers */
|
|
|
|
printf("%s: fifo overrun, resetting receive buffer\n",
|
|
|
|
dep->de_name);
|
|
|
|
dep->de_stat.ets_fifoOver++;
|
|
|
|
next = curr;
|
|
|
|
}
|
|
|
|
else if ((header.dr_status & RSR_PRX) &&
|
|
|
|
(dep->de_flags & DEF_ENABLED))
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
r = dp_pkt2user_s(dep, pageno, length);
|
2005-08-05 11:53:08 +02:00
|
|
|
if (r != OK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
packet_processed = TRUE;
|
|
|
|
dep->de_stat.ets_packetR++;
|
|
|
|
}
|
|
|
|
if (next == dep->de_startpage)
|
|
|
|
outb_reg0(dep, DP_BNRY, dep->de_stoppage - 1);
|
|
|
|
else
|
|
|
|
outb_reg0(dep, DP_BNRY, next - 1);
|
|
|
|
|
|
|
|
pageno = next;
|
|
|
|
}
|
|
|
|
while (!packet_processed);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_send *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_send(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
if (!(dep->de_flags & DEF_SEND_AVAIL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
dep->de_flags &= ~DEF_SEND_AVAIL;
|
2010-05-18 00:22:53 +02:00
|
|
|
do_vwrite_s(&dep->de_sendmsg, TRUE);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_getblock *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_getblock(dep, page, offset, size, dst)
|
|
|
|
dpeth_t *dep;
|
|
|
|
int page;
|
|
|
|
size_t offset;
|
|
|
|
size_t size;
|
|
|
|
void *dst;
|
|
|
|
{
|
|
|
|
offset = page * DP_PAGESIZE + offset;
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
memcpy(dst, dep->de_locmem + offset, size);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_pio8_getblock *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_pio8_getblock(dep, page, offset, size, dst)
|
|
|
|
dpeth_t *dep;
|
|
|
|
int page;
|
|
|
|
size_t offset;
|
|
|
|
size_t size;
|
|
|
|
void *dst;
|
|
|
|
{
|
|
|
|
offset = page * DP_PAGESIZE + offset;
|
|
|
|
outb_reg0(dep, DP_RBCR0, size & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RBCR1, size >> 8);
|
|
|
|
outb_reg0(dep, DP_RSAR0, offset & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RSAR1, offset >> 8);
|
|
|
|
outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
|
|
|
|
|
|
|
|
insb(dep->de_data_port, dst, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_pio16_getblock *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_pio16_getblock(dep, page, offset, size, dst)
|
|
|
|
dpeth_t *dep;
|
|
|
|
int page;
|
|
|
|
size_t offset;
|
|
|
|
size_t size;
|
|
|
|
void *dst;
|
|
|
|
{
|
|
|
|
offset = page * DP_PAGESIZE + offset;
|
|
|
|
outb_reg0(dep, DP_RBCR0, size & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RBCR1, size >> 8);
|
|
|
|
outb_reg0(dep, DP_RSAR0, offset & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RSAR1, offset >> 8);
|
|
|
|
outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
|
|
|
|
|
|
|
|
assert (!(size & 1));
|
|
|
|
insw(dep->de_data_port, dst, size);
|
|
|
|
}
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* dp_pkt2user_s *
|
|
|
|
*===========================================================================*/
|
2010-03-30 16:07:15 +02:00
|
|
|
static int dp_pkt2user_s(dpeth_t *dep, int page, vir_bytes length)
|
2006-07-10 14:43:38 +02:00
|
|
|
{
|
|
|
|
int last, count;
|
|
|
|
|
|
|
|
if (!(dep->de_flags & DEF_READING))
|
|
|
|
return EGENERIC;
|
|
|
|
|
|
|
|
last = page + (length - 1) / DP_PAGESIZE;
|
|
|
|
if (last >= dep->de_stoppage)
|
|
|
|
{
|
|
|
|
count = (dep->de_stoppage - page) * DP_PAGESIZE -
|
|
|
|
sizeof(dp_rcvhdr_t);
|
|
|
|
|
|
|
|
/* Save read_iovec since we need it twice. */
|
|
|
|
dep->de_tmp_iovec_s = dep->de_read_iovec_s;
|
|
|
|
(dep->de_nic2userf_s)(dep, page * DP_PAGESIZE +
|
|
|
|
sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec_s, 0, count);
|
|
|
|
(dep->de_nic2userf_s)(dep, dep->de_startpage * DP_PAGESIZE,
|
|
|
|
&dep->de_read_iovec_s, count, length - count);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(dep->de_nic2userf_s)(dep, page * DP_PAGESIZE +
|
|
|
|
sizeof(dp_rcvhdr_t), &dep->de_read_iovec_s, 0, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
dep->de_read_s = length;
|
|
|
|
dep->de_flags |= DEF_PACK_RECV;
|
|
|
|
dep->de_flags &= ~DEF_READING;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/*===========================================================================*
|
2010-05-18 00:22:53 +02:00
|
|
|
* dp_user2nic_s *
|
2005-08-05 11:53:08 +02:00
|
|
|
*===========================================================================*/
|
2010-05-18 00:22:53 +02:00
|
|
|
static void dp_user2nic_s(dep, iovp, offset, nic_addr, count)
|
2005-08-05 11:53:08 +02:00
|
|
|
dpeth_t *dep;
|
2010-05-18 00:22:53 +02:00
|
|
|
iovec_dat_s_t *iovp;
|
2006-07-10 14:43:38 +02:00
|
|
|
vir_bytes offset;
|
|
|
|
int nic_addr;
|
|
|
|
vir_bytes count;
|
|
|
|
{
|
2010-01-15 22:45:30 +01:00
|
|
|
vir_bytes vir_hw;
|
2006-07-10 14:43:38 +02:00
|
|
|
int bytes, i, r;
|
|
|
|
|
|
|
|
vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
|
|
|
|
|
|
|
|
i= 0;
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
if (i >= IOVEC_NR)
|
|
|
|
{
|
|
|
|
dp_next_iovec_s(iovp);
|
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(i < iovp->iod_iovec_s);
|
|
|
|
if (offset >= iovp->iod_iovec[i].iov_size)
|
|
|
|
{
|
|
|
|
offset -= iovp->iod_iovec[i].iov_size;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bytes = iovp->iod_iovec[i].iov_size - offset;
|
|
|
|
if (bytes > count)
|
|
|
|
bytes = count;
|
|
|
|
|
|
|
|
r= sys_safecopyfrom(iovp->iod_proc_nr,
|
|
|
|
iovp->iod_iovec[i].iov_grant, offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
vir_hw, bytes);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_user2nic_s: sys_safecopyfrom failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
count -= bytes;
|
|
|
|
vir_hw += bytes;
|
|
|
|
offset += bytes;
|
|
|
|
}
|
|
|
|
assert(count == 0);
|
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/*===========================================================================*
|
2006-07-10 14:43:38 +02:00
|
|
|
* dp_pio8_user2nic_s *
|
2005-08-05 11:53:08 +02:00
|
|
|
*===========================================================================*/
|
2006-07-10 14:43:38 +02:00
|
|
|
static void dp_pio8_user2nic_s(dep, iovp, offset, nic_addr, count)
|
2005-08-05 11:53:08 +02:00
|
|
|
dpeth_t *dep;
|
2006-07-10 14:43:38 +02:00
|
|
|
iovec_dat_s_t *iovp;
|
2005-08-05 11:53:08 +02:00
|
|
|
vir_bytes offset;
|
|
|
|
int nic_addr;
|
|
|
|
vir_bytes count;
|
|
|
|
{
|
2006-07-10 14:43:38 +02:00
|
|
|
int bytes, i, r;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
outb_reg0(dep, DP_ISR, ISR_RDC);
|
2006-07-10 14:43:38 +02:00
|
|
|
|
|
|
|
outb_reg0(dep, DP_RBCR0, count & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RBCR1, count >> 8);
|
2005-08-05 11:53:08 +02:00
|
|
|
outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
|
|
|
|
outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
|
|
|
|
|
|
|
|
i= 0;
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
if (i >= IOVEC_NR)
|
|
|
|
{
|
2006-07-10 14:43:38 +02:00
|
|
|
dp_next_iovec_s(iovp);
|
2005-08-05 11:53:08 +02:00
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(i < iovp->iod_iovec_s);
|
|
|
|
if (offset >= iovp->iod_iovec[i].iov_size)
|
|
|
|
{
|
|
|
|
offset -= iovp->iod_iovec[i].iov_size;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bytes = iovp->iod_iovec[i].iov_size - offset;
|
|
|
|
if (bytes > count)
|
|
|
|
bytes = count;
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
r= sys_safe_outsb(dep->de_data_port, iovp->iod_proc_nr,
|
|
|
|
iovp->iod_iovec[i].iov_grant, offset, bytes);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_pio8_user2nic_s: sys_safe_outsb failed: %d",
|
|
|
|
r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
count -= bytes;
|
|
|
|
offset += bytes;
|
|
|
|
}
|
|
|
|
assert(count == 0);
|
|
|
|
|
|
|
|
for (i= 0; i<100; i++)
|
|
|
|
{
|
|
|
|
if (inb_reg0(dep, DP_ISR) & ISR_RDC)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == 100)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: remote dma failed to complete");
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_pio16_user2nic_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_pio16_user2nic_s(dep, iovp, offset, nic_addr, count)
|
|
|
|
dpeth_t *dep;
|
|
|
|
iovec_dat_s_t *iovp;
|
|
|
|
vir_bytes offset;
|
|
|
|
int nic_addr;
|
|
|
|
vir_bytes count;
|
|
|
|
{
|
|
|
|
vir_bytes ecount;
|
|
|
|
cp_grant_id_t gid;
|
|
|
|
int i, r, bytes, user_proc;
|
|
|
|
u8_t two_bytes[2];
|
|
|
|
int odd_byte;
|
|
|
|
|
|
|
|
ecount= (count+1) & ~1;
|
|
|
|
odd_byte= 0;
|
|
|
|
|
|
|
|
outb_reg0(dep, DP_ISR, ISR_RDC);
|
|
|
|
outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RBCR1, ecount >> 8);
|
|
|
|
outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
|
|
|
|
outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA);
|
|
|
|
|
|
|
|
i= 0;
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
if (i >= IOVEC_NR)
|
|
|
|
{
|
|
|
|
dp_next_iovec_s(iovp);
|
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(i < iovp->iod_iovec_s);
|
|
|
|
if (offset >= iovp->iod_iovec[i].iov_size)
|
|
|
|
{
|
|
|
|
offset -= iovp->iod_iovec[i].iov_size;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bytes = iovp->iod_iovec[i].iov_size - offset;
|
|
|
|
if (bytes > count)
|
|
|
|
bytes = count;
|
|
|
|
|
|
|
|
user_proc= iovp->iod_proc_nr;
|
|
|
|
gid= iovp->iod_iovec[i].iov_grant;
|
|
|
|
if (odd_byte)
|
|
|
|
{
|
|
|
|
r= sys_safecopyfrom(user_proc, gid, offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes)&two_bytes[1], 1);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_pio16_user2nic: sys_safecopyfrom failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
outw(dep->de_data_port, *(u16_t *)two_bytes);
|
|
|
|
count--;
|
|
|
|
offset++;
|
|
|
|
bytes--;
|
|
|
|
odd_byte= 0;
|
|
|
|
if (!bytes)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ecount= bytes & ~1;
|
|
|
|
if (ecount != 0)
|
|
|
|
{
|
|
|
|
r= sys_safe_outsw(dep->de_data_port, user_proc,
|
|
|
|
gid, offset, ecount);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_pio16_user2nic: sys_safe_outsw failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
count -= ecount;
|
|
|
|
offset += ecount;
|
|
|
|
bytes -= ecount;
|
|
|
|
}
|
|
|
|
if (bytes)
|
|
|
|
{
|
|
|
|
assert(bytes == 1);
|
|
|
|
r= sys_safecopyfrom(user_proc, gid, offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes)&two_bytes[0], 1);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_pio16_user2nic: sys_safecopyfrom failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
count--;
|
|
|
|
offset++;
|
|
|
|
bytes--;
|
|
|
|
odd_byte= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(count == 0);
|
|
|
|
|
|
|
|
if (odd_byte)
|
|
|
|
outw(dep->de_data_port, *(u16_t *)two_bytes);
|
|
|
|
|
|
|
|
for (i= 0; i<100; i++)
|
|
|
|
{
|
|
|
|
if (inb_reg0(dep, DP_ISR) & ISR_RDC)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == 100)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: remote dma failed to complete");
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_nic2user_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_nic2user_s(dep, nic_addr, iovp, offset, count)
|
|
|
|
dpeth_t *dep;
|
|
|
|
int nic_addr;
|
|
|
|
iovec_dat_s_t *iovp;
|
|
|
|
vir_bytes offset;
|
|
|
|
vir_bytes count;
|
|
|
|
{
|
2010-01-15 22:45:30 +01:00
|
|
|
vir_bytes vir_hw;
|
2006-07-10 14:43:38 +02:00
|
|
|
int bytes, i, r;
|
|
|
|
|
|
|
|
vir_hw = (vir_bytes)dep->de_locmem + nic_addr;
|
|
|
|
|
|
|
|
i= 0;
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
if (i >= IOVEC_NR)
|
|
|
|
{
|
|
|
|
dp_next_iovec_s(iovp);
|
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(i < iovp->iod_iovec_s);
|
|
|
|
if (offset >= iovp->iod_iovec[i].iov_size)
|
|
|
|
{
|
|
|
|
offset -= iovp->iod_iovec[i].iov_size;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bytes = iovp->iod_iovec[i].iov_size - offset;
|
|
|
|
if (bytes > count)
|
|
|
|
bytes = count;
|
|
|
|
|
|
|
|
r= sys_safecopyto(iovp->iod_proc_nr,
|
|
|
|
iovp->iod_iovec[i].iov_grant, offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
vir_hw, bytes);
|
2006-07-10 14:43:38 +02:00
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp_nic2user_s: sys_safecopyto failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
|
|
|
|
count -= bytes;
|
|
|
|
vir_hw += bytes;
|
|
|
|
offset += bytes;
|
|
|
|
}
|
|
|
|
assert(count == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_pio8_nic2user_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_pio8_nic2user_s(dep, nic_addr, iovp, offset, count)
|
|
|
|
dpeth_t *dep;
|
|
|
|
int nic_addr;
|
|
|
|
iovec_dat_s_t *iovp;
|
|
|
|
vir_bytes offset;
|
|
|
|
vir_bytes count;
|
|
|
|
{
|
|
|
|
int bytes, i, r;
|
|
|
|
|
|
|
|
outb_reg0(dep, DP_RBCR0, count & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RBCR1, count >> 8);
|
|
|
|
outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
|
|
|
|
outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
|
|
|
|
|
|
|
|
i= 0;
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
if (i >= IOVEC_NR)
|
|
|
|
{
|
|
|
|
dp_next_iovec_s(iovp);
|
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(i < iovp->iod_iovec_s);
|
|
|
|
if (offset >= iovp->iod_iovec[i].iov_size)
|
|
|
|
{
|
|
|
|
offset -= iovp->iod_iovec[i].iov_size;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bytes = iovp->iod_iovec[i].iov_size - offset;
|
|
|
|
if (bytes > count)
|
|
|
|
bytes = count;
|
|
|
|
|
|
|
|
r= sys_safe_insb(dep->de_data_port, iovp->iod_proc_nr,
|
|
|
|
iovp->iod_iovec[i].iov_grant, offset, bytes);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_pio8_nic2user_s: sys_safe_insb failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
count -= bytes;
|
|
|
|
offset += bytes;
|
|
|
|
}
|
|
|
|
assert(count == 0);
|
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/*===========================================================================*
|
2006-07-10 14:43:38 +02:00
|
|
|
* dp_pio16_nic2user_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_pio16_nic2user_s(dep, nic_addr, iovp, offset, count)
|
|
|
|
dpeth_t *dep;
|
|
|
|
int nic_addr;
|
|
|
|
iovec_dat_s_t *iovp;
|
|
|
|
vir_bytes offset;
|
|
|
|
vir_bytes count;
|
|
|
|
{
|
|
|
|
vir_bytes ecount;
|
|
|
|
cp_grant_id_t gid;
|
|
|
|
int i, r, bytes, user_proc;
|
|
|
|
u8_t two_bytes[2];
|
|
|
|
int odd_byte;
|
|
|
|
|
|
|
|
ecount= (count+1) & ~1;
|
|
|
|
odd_byte= 0;
|
|
|
|
|
|
|
|
outb_reg0(dep, DP_RBCR0, ecount & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RBCR1, ecount >> 8);
|
|
|
|
outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF);
|
|
|
|
outb_reg0(dep, DP_RSAR1, nic_addr >> 8);
|
|
|
|
outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA);
|
|
|
|
|
|
|
|
i= 0;
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
if (i >= IOVEC_NR)
|
|
|
|
{
|
|
|
|
dp_next_iovec_s(iovp);
|
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
assert(i < iovp->iod_iovec_s);
|
|
|
|
if (offset >= iovp->iod_iovec[i].iov_size)
|
|
|
|
{
|
|
|
|
offset -= iovp->iod_iovec[i].iov_size;
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bytes = iovp->iod_iovec[i].iov_size - offset;
|
|
|
|
if (bytes > count)
|
|
|
|
bytes = count;
|
|
|
|
|
|
|
|
user_proc= iovp->iod_proc_nr;
|
|
|
|
gid= iovp->iod_iovec[i].iov_grant;
|
|
|
|
if (odd_byte)
|
|
|
|
{
|
|
|
|
r= sys_safecopyto(user_proc, gid, offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes)&two_bytes[1], 1);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_pio16_nic2user: sys_safecopyto failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
count--;
|
|
|
|
offset++;
|
|
|
|
bytes--;
|
|
|
|
odd_byte= 0;
|
|
|
|
if (!bytes)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ecount= bytes & ~1;
|
|
|
|
if (ecount != 0)
|
|
|
|
{
|
|
|
|
r= sys_safe_insw(dep->de_data_port, user_proc, gid,
|
|
|
|
offset, ecount);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (r != OK) {
|
|
|
|
panic("dp_pio16_nic2user: sys_safe_insw failed: %d",
|
|
|
|
r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
count -= ecount;
|
|
|
|
offset += ecount;
|
|
|
|
bytes -= ecount;
|
|
|
|
}
|
|
|
|
if (bytes)
|
|
|
|
{
|
|
|
|
assert(bytes == 1);
|
|
|
|
*(u16_t *)two_bytes= inw(dep->de_data_port);
|
|
|
|
r= sys_safecopyto(user_proc, gid, offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes)&two_bytes[0], 1);
|
2006-07-10 14:43:38 +02:00
|
|
|
if (r != OK)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp_pio16_nic2user: sys_safecopyto failed: %d",
|
2006-07-10 14:43:38 +02:00
|
|
|
r);
|
|
|
|
}
|
|
|
|
count--;
|
|
|
|
offset++;
|
|
|
|
bytes--;
|
|
|
|
odd_byte= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(count == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* dp_next_iovec_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void dp_next_iovec_s(iovp)
|
|
|
|
iovec_dat_s_t *iovp;
|
|
|
|
{
|
|
|
|
assert(iovp->iod_iovec_s > IOVEC_NR);
|
|
|
|
|
|
|
|
iovp->iod_iovec_s -= IOVEC_NR;
|
|
|
|
|
|
|
|
iovp->iod_iovec_offset += IOVEC_NR * sizeof(iovec_t);
|
|
|
|
|
|
|
|
get_userdata_s(iovp->iod_proc_nr, iovp->iod_grant,
|
|
|
|
iovp->iod_iovec_offset,
|
|
|
|
(iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) *
|
|
|
|
sizeof(iovp->iod_iovec[0]), iovp->iod_iovec);
|
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* conf_hw *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void conf_hw(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0 /* ,... */ };
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
int confnr;
|
2005-08-05 11:53:08 +02:00
|
|
|
dp_conf_t *dcp;
|
|
|
|
|
|
|
|
dep->de_mode= DEM_DISABLED; /* Superfluous */
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
/* Pick a default configuration for this instance. */
|
|
|
|
confnr= MIN(de_instance, DP_CONF_NR-1);
|
|
|
|
|
|
|
|
dcp= &dp_conf[confnr];
|
2005-08-05 11:53:08 +02:00
|
|
|
update_conf(dep, dcp);
|
|
|
|
if (dep->de_mode != DEM_ENABLED)
|
|
|
|
return;
|
|
|
|
if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep))
|
|
|
|
{
|
|
|
|
printf("%s: No ethernet card found at 0x%x\n",
|
|
|
|
dep->de_name, dep->de_base_port);
|
|
|
|
dep->de_mode= DEM_DISABLED;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000;
|
|
|
|
|
|
|
|
dep->de_flags = DEF_EMPTY;
|
|
|
|
dep->de_stat = empty_stat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* update_conf *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void update_conf(dep, dcp)
|
|
|
|
dpeth_t *dep;
|
|
|
|
dp_conf_t *dcp;
|
|
|
|
{
|
|
|
|
long v;
|
|
|
|
static char dpc_fmt[] = "x:d:x:x";
|
2010-05-18 00:22:53 +02:00
|
|
|
char eckey[16];
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
#if ENABLE_PCI
|
|
|
|
if (dep->de_pci)
|
|
|
|
{
|
|
|
|
if (dep->de_pci == 1)
|
|
|
|
{
|
|
|
|
/* PCI device is present */
|
|
|
|
dep->de_mode= DEM_ENABLED;
|
|
|
|
}
|
|
|
|
return; /* Already configured */
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
strcpy(eckey, "DPETH0");
|
|
|
|
eckey[5] += de_instance;
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/* Get the default settings and modify them from the environment. */
|
|
|
|
dep->de_mode= DEM_SINK;
|
|
|
|
v= dcp->dpc_port;
|
2010-05-18 00:22:53 +02:00
|
|
|
switch (env_parse(eckey, dpc_fmt, 0, &v, 0x0000L, 0xFFFFL)) {
|
2005-08-05 11:53:08 +02:00
|
|
|
case EP_OFF:
|
|
|
|
dep->de_mode= DEM_DISABLED;
|
|
|
|
break;
|
|
|
|
case EP_ON:
|
|
|
|
case EP_SET:
|
|
|
|
dep->de_mode= DEM_ENABLED; /* Might become disabled if
|
|
|
|
* all probes fail */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dep->de_base_port= v;
|
|
|
|
|
|
|
|
v= dcp->dpc_irq | DEI_DEFAULT;
|
2010-05-18 00:22:53 +02:00
|
|
|
(void) env_parse(eckey, dpc_fmt, 1, &v, 0L, (long) NR_IRQ_VECTORS - 1);
|
2005-08-05 11:53:08 +02:00
|
|
|
dep->de_irq= v;
|
|
|
|
|
|
|
|
v= dcp->dpc_mem;
|
2010-05-18 00:22:53 +02:00
|
|
|
(void) env_parse(eckey, dpc_fmt, 2, &v, 0L, 0xFFFFFL);
|
2005-08-05 11:53:08 +02:00
|
|
|
dep->de_linmem= v;
|
|
|
|
|
|
|
|
v= 0;
|
2010-05-18 00:22:53 +02:00
|
|
|
(void) env_parse(eckey, dpc_fmt, 3, &v, 0x2000L, 0x8000L);
|
2005-08-05 11:53:08 +02:00
|
|
|
dep->de_ramsize= v;
|
|
|
|
}
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* map_hw_buffer *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void map_hw_buffer(dep)
|
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (dep->de_prog_IO)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
printf(
|
|
|
|
"map_hw_buffer: programmed I/O, no need to map buffer\n");
|
|
|
|
#endif
|
|
|
|
dep->de_locmem = (char *)-dep->de_ramsize; /* trap errors */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-07 23:57:34 +01:00
|
|
|
dep->de_locmem=
|
|
|
|
vm_map_phys(SELF, (void *) dep->de_linmem, dep->de_ramsize);
|
|
|
|
if (dep->de_locmem == MAP_FAILED)
|
|
|
|
panic("map_hw_buffer: vm_map_phys failed");
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* calc_iovec_size_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static int calc_iovec_size_s(iovp)
|
|
|
|
iovec_dat_s_t *iovp;
|
|
|
|
{
|
|
|
|
/* Calculate the size of a request. Note that the iovec_dat
|
|
|
|
* structure will be unusable after calc_iovec_size_s.
|
|
|
|
*/
|
|
|
|
int size;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
size= 0;
|
|
|
|
i= 0;
|
|
|
|
while (i < iovp->iod_iovec_s)
|
|
|
|
{
|
|
|
|
if (i >= IOVEC_NR)
|
|
|
|
{
|
|
|
|
dp_next_iovec_s(iovp);
|
|
|
|
i= 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
size += iovp->iod_iovec[i].iov_size;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* reply *
|
|
|
|
*===========================================================================*/
|
2010-05-18 00:22:53 +02:00
|
|
|
static void reply(dep)
|
2005-08-05 11:53:08 +02:00
|
|
|
dpeth_t *dep;
|
|
|
|
{
|
|
|
|
message reply;
|
2010-05-18 00:22:53 +02:00
|
|
|
int flags;
|
2005-08-05 11:53:08 +02:00
|
|
|
int r;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
flags = DL_NOFLAGS;
|
2005-08-05 11:53:08 +02:00
|
|
|
if (dep->de_flags & DEF_PACK_SEND)
|
2010-05-18 00:22:53 +02:00
|
|
|
flags |= DL_PACK_SEND;
|
2005-08-05 11:53:08 +02:00
|
|
|
if (dep->de_flags & DEF_PACK_RECV)
|
2010-05-18 00:22:53 +02:00
|
|
|
flags |= DL_PACK_RECV;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
reply.m_type = DL_TASK_REPLY;
|
2010-05-18 00:22:53 +02:00
|
|
|
reply.DL_FLAGS = flags;
|
2005-08-05 11:53:08 +02:00
|
|
|
reply.DL_COUNT = dep->de_read_s;
|
|
|
|
r= send(dep->de_client, &reply);
|
|
|
|
|
|
|
|
if (r < 0)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: send failed: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
dep->de_read_s = 0;
|
|
|
|
dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* mess_reply *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void mess_reply(req, reply_mess)
|
|
|
|
message *req;
|
|
|
|
message *reply_mess;
|
|
|
|
{
|
|
|
|
if (send(req->m_source, reply_mess) != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("dp8390: unable to mess_reply");
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
2006-07-10 14:43:38 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* get_userdata_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void get_userdata_s(user_proc, grant, offset, count, loc_addr)
|
|
|
|
int user_proc;
|
|
|
|
cp_grant_id_t grant;
|
|
|
|
vir_bytes offset;
|
|
|
|
vir_bytes count;
|
|
|
|
void *loc_addr;
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r= sys_safecopyfrom(user_proc, grant, offset,
|
2012-06-16 03:46:15 +02:00
|
|
|
(vir_bytes)loc_addr, count);
|
2006-07-10 14:43:38 +02:00
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("get_userdata: sys_safecopyfrom failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* put_userdata_s *
|
|
|
|
*===========================================================================*/
|
|
|
|
static void put_userdata_s(user_proc, grant, count, loc_addr)
|
|
|
|
int user_proc;
|
|
|
|
cp_grant_id_t grant;
|
|
|
|
size_t count;
|
|
|
|
void *loc_addr;
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r= sys_safecopyto(user_proc, grant, 0, (vir_bytes)loc_addr,
|
2012-06-16 03:46:15 +02:00
|
|
|
count);
|
2006-07-10 14:43:38 +02:00
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("put_userdata: sys_safecopyto failed: %d", r);
|
2006-07-10 14:43:38 +02:00
|
|
|
}
|
|
|
|
|
2005-08-05 11:53:08 +02:00
|
|
|
u8_t inb(port_t port)
|
|
|
|
{
|
|
|
|
int r;
|
2005-10-21 19:09:08 +02:00
|
|
|
u32_t value;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
r= sys_inb(port, &value);
|
|
|
|
if (r != OK)
|
2007-04-23 17:38:00 +02:00
|
|
|
{
|
|
|
|
printf("inb failed for port 0x%x\n", port);
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_inb failed: %d", r);
|
2007-04-23 17:38:00 +02:00
|
|
|
}
|
2005-08-05 11:53:08 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
u16_t inw(port_t port)
|
|
|
|
{
|
|
|
|
int r;
|
2012-03-05 00:11:41 +01:00
|
|
|
u32_t value;
|
2005-08-05 11:53:08 +02:00
|
|
|
|
|
|
|
r= sys_inw(port, &value);
|
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_inw failed: %d", r);
|
2006-03-25 00:08:19 +01:00
|
|
|
return (u16_t) value;
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void outb(port_t port, u8_t value)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r= sys_outb(port, value);
|
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_outb failed: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void outw(port_t port, u16_t value)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
r= sys_outw(port, value);
|
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_outw failed: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void insb(port_t port, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
do_vir_insb(port, SELF, (vir_bytes)buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void insw(port_t port, void *buf, size_t size)
|
|
|
|
{
|
|
|
|
do_vir_insw(port, SELF, (vir_bytes)buf, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_vir_insb(port_t port, int proc, vir_bytes buf, size_t size)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2006-06-20 11:48:26 +02:00
|
|
|
r= sys_insb(port, proc, (void *) buf, size);
|
2005-08-05 11:53:08 +02:00
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_sdevio failed: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void do_vir_insw(port_t port, int proc, vir_bytes buf, size_t size)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2006-06-20 11:48:26 +02:00
|
|
|
r= sys_insw(port, proc, (void *) buf, size);
|
2005-08-05 11:53:08 +02:00
|
|
|
if (r != OK)
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_sdevio failed: %d", r);
|
2005-08-05 11:53:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* $PchId: dp8390.c,v 1.25 2005/02/10 17:32:07 philip Exp $
|
|
|
|
*/
|