2009-12-07 19:33:41 +01:00
|
|
|
/**
|
|
|
|
* @file e1000.c
|
|
|
|
*
|
|
|
|
* @brief This file contains a device driver for Intel Pro/1000
|
|
|
|
* Gigabit Ethernet Controllers.
|
|
|
|
*/
|
|
|
|
|
2010-03-22 22:25:22 +01:00
|
|
|
#include <minix/drivers.h>
|
2010-04-08 15:41:35 +02:00
|
|
|
#include <minix/netdriver.h>
|
2009-12-07 19:33:41 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <net/gen/ether.h>
|
|
|
|
#include <net/gen/eth_io.h>
|
2010-03-08 12:04:59 +01:00
|
|
|
#include <machine/pci.h>
|
2009-12-07 19:33:41 +01:00
|
|
|
#include <minix/ds.h>
|
|
|
|
#include <minix/vm.h>
|
2013-09-19 10:57:10 +02:00
|
|
|
#include <minix/timers.h>
|
2010-06-07 18:30:10 +02:00
|
|
|
#include <sys/mman.h>
|
2009-12-07 19:33:41 +01:00
|
|
|
#include "assert.h"
|
|
|
|
#include "e1000.h"
|
|
|
|
#include "e1000_hw.h"
|
|
|
|
#include "e1000_reg.h"
|
|
|
|
#include "e1000_pci.h"
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static int e1000_instance;
|
|
|
|
static e1000_t e1000_state;
|
|
|
|
|
|
|
|
static void e1000_init(message *mp);
|
|
|
|
static void e1000_init_pci(void);
|
|
|
|
static int e1000_probe(e1000_t *e, int skip);
|
|
|
|
static int e1000_init_hw(e1000_t *e);
|
|
|
|
static void e1000_init_addr(e1000_t *e);
|
|
|
|
static void e1000_init_buf(e1000_t *e);
|
|
|
|
static void e1000_reset_hw(e1000_t *e);
|
|
|
|
static void e1000_writev_s(message *mp, int from_int);
|
|
|
|
static void e1000_readv_s(message *mp, int from_int);
|
|
|
|
static void e1000_getstat_s(message *mp);
|
|
|
|
static void e1000_interrupt(message *mp);
|
|
|
|
static int e1000_link_changed(e1000_t *e);
|
|
|
|
static void e1000_stop(e1000_t *e);
|
|
|
|
static uint32_t e1000_reg_read(e1000_t *e, uint32_t reg);
|
|
|
|
static void e1000_reg_write(e1000_t *e, uint32_t reg, uint32_t value);
|
|
|
|
static void e1000_reg_set(e1000_t *e, uint32_t reg, uint32_t value);
|
|
|
|
static void e1000_reg_unset(e1000_t *e, uint32_t reg, uint32_t value);
|
|
|
|
static u16_t eeprom_eerd(void *e, int reg);
|
|
|
|
static u16_t eeprom_ich(void *e, int reg);
|
|
|
|
static int eeprom_ich_init(e1000_t *e);
|
|
|
|
static int eeprom_ich_cycle(const e1000_t *e, u32_t timeout);
|
|
|
|
static void reply(e1000_t *e);
|
|
|
|
static void mess_reply(message *req, message *reply);
|
2009-12-07 19:33:41 +01: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 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);
|
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
|
|
|
|
2009-12-07 19:33:41 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* main *
|
|
|
|
*===========================================================================*/
|
|
|
|
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;
|
2009-12-07 19:33:41 +01: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. */
|
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
|
|
|
env_setargs(argc, argv);
|
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();
|
|
|
|
|
2009-12-07 19:33:41 +01:00
|
|
|
/*
|
|
|
|
* Enter the main driver loop.
|
|
|
|
*/
|
|
|
|
while (TRUE)
|
|
|
|
{
|
2010-04-08 15:41:35 +02:00
|
|
|
if ((r= netdriver_receive(ANY, &m, &ipc_status)) != OK)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2010-04-08 15:41:35 +02:00
|
|
|
panic("netdriver_receive failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
2010-04-08 15:41:35 +02:00
|
|
|
|
|
|
|
if (is_ipc_notify(ipc_status))
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
switch (_ENDPOINT_P(m.m_source))
|
|
|
|
{
|
|
|
|
case HARDWARE:
|
|
|
|
e1000_interrupt(&m);
|
|
|
|
break;
|
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
|
|
|
|
2009-12-07 19:33:41 +01:00
|
|
|
case CLOCK:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (m.m_type)
|
|
|
|
{
|
|
|
|
case DL_WRITEV_S: e1000_writev_s(&m, FALSE); break;
|
|
|
|
case DL_READV_S: e1000_readv_s(&m, FALSE); break;
|
|
|
|
case DL_CONF: e1000_init(&m); break;
|
|
|
|
case DL_GETSTAT_S: e1000_getstat_s(&m); break;
|
|
|
|
default:
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("illegal message: %d", m.m_type);
|
2009-12-07 19:33:41 +01: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 UNUSED(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 e1000 driver. */
|
2010-05-18 00:22:53 +02:00
|
|
|
long 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
|
|
|
int r;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
v = 0;
|
|
|
|
(void) env_parse("instance", "d", 0, &v, 0, 255);
|
|
|
|
e1000_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
|
|
|
|
|
|
|
/* Clear state. */
|
2010-05-18 00:22:53 +02:00
|
|
|
memset(&e1000_state, 0, sizeof(e1000_state));
|
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
|
|
|
|
|
|
|
/* Perform calibration. */
|
2010-01-14 16:24:16 +01:00
|
|
|
if((r = tsc_calibrate()) != OK)
|
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-03-05 16:05:11 +01:00
|
|
|
panic("tsc_calibrate failed: %d", r);
|
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
|
|
|
{
|
2012-01-30 15:32:31 +01:00
|
|
|
e1000_t *e;
|
|
|
|
e = &e1000_state;
|
|
|
|
|
|
|
|
E1000_DEBUG(3, ("%s: got signal\n", e->name));
|
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;
|
|
|
|
|
2012-01-30 15:32:31 +01:00
|
|
|
e1000_stop(e);
|
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
|
|
|
}
|
|
|
|
|
2009-12-07 19:33:41 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_init *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_init(message *mp)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
static int first_time = 1;
|
|
|
|
message reply_mess;
|
|
|
|
e1000_t *e;
|
|
|
|
|
|
|
|
E1000_DEBUG(3, ("e1000: init()\n"));
|
|
|
|
|
|
|
|
/* Configure PCI devices, if needed. */
|
|
|
|
if (first_time)
|
|
|
|
{
|
|
|
|
first_time = 0;
|
|
|
|
e1000_init_pci();
|
|
|
|
}
|
2010-05-18 00:22:53 +02:00
|
|
|
e = &e1000_state;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Initialize hardware, if needed. */
|
|
|
|
if (!(e->status & E1000_ENABLED) && !(e1000_init_hw(e)))
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
reply_mess.m_type = DL_CONF_REPLY;
|
2014-05-19 19:19:14 +02:00
|
|
|
reply_mess.m_netdrv_net_dl_conf.stat = ENXIO;
|
2009-12-07 19:33:41 +01:00
|
|
|
mess_reply(mp, &reply_mess);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Reply back to INET. */
|
2010-05-18 00:22:53 +02:00
|
|
|
reply_mess.m_type = DL_CONF_REPLY;
|
2014-05-19 19:19:14 +02:00
|
|
|
reply_mess.m_netdrv_net_dl_conf.stat = OK;
|
|
|
|
memcpy(reply_mess.m_netdrv_net_dl_conf.hw_addr, e->address.ea_addr,
|
|
|
|
sizeof(reply_mess.m_netdrv_net_dl_conf.hw_addr));
|
2009-12-07 19:33:41 +01:00
|
|
|
mess_reply(mp, &reply_mess);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_int_pci *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_init_pci()
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
e1000_t *e;
|
|
|
|
|
|
|
|
/* Initialize the PCI bus. */
|
|
|
|
pci_init();
|
|
|
|
|
|
|
|
/* Try to detect e1000's. */
|
2010-05-18 00:22:53 +02:00
|
|
|
e = &e1000_state;
|
2012-08-03 18:10:24 +02:00
|
|
|
strlcpy(e->name, "e1000#0", sizeof(e->name));
|
|
|
|
e->name[6] += e1000_instance;
|
2010-05-18 00:22:53 +02:00
|
|
|
e1000_probe(e, e1000_instance);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_probe *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int e1000_probe(e1000_t *e, int skip)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2012-03-05 12:58:33 +01:00
|
|
|
int r, devind, ioflag;
|
|
|
|
u16_t vid, did, cr;
|
2009-12-07 19:33:41 +01:00
|
|
|
u32_t status[2];
|
2012-03-05 12:58:33 +01:00
|
|
|
u32_t base, size;
|
2010-04-15 20:49:36 +02:00
|
|
|
u32_t gfpreg, sector_base_addr;
|
2010-01-15 22:45:30 +01:00
|
|
|
char *dname;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
E1000_DEBUG(3, ("%s: probe()\n", e->name));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to iterate the PCI bus. Start at the beginning.
|
|
|
|
*/
|
|
|
|
if ((r = pci_first_dev(&devind, &vid, &did)) == 0)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* Loop devices on the PCI bus. */
|
2012-03-07 00:49:16 +01:00
|
|
|
while (skip--)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2011-07-07 19:26:39 +02:00
|
|
|
E1000_DEBUG(3, ("%s: probe() devind %d vid 0x%x did 0x%x\n",
|
|
|
|
e->name, devind, vid, did));
|
|
|
|
|
2009-12-07 19:33:41 +01:00
|
|
|
if (!(r = pci_next_dev(&devind, &vid, &did)))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Successfully detected an Intel Pro/1000 on the PCI bus.
|
|
|
|
*/
|
|
|
|
e->status |= E1000_DETECTED;
|
|
|
|
e->eeprom_read = eeprom_eerd;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set card specific properties.
|
|
|
|
*/
|
|
|
|
switch (did)
|
|
|
|
{
|
2011-03-15 11:04:35 +01:00
|
|
|
case E1000_DEV_ID_ICH10_D_BM_LM:
|
2009-12-07 19:33:41 +01:00
|
|
|
case E1000_DEV_ID_ICH10_R_BM_LF:
|
|
|
|
e->eeprom_read = eeprom_ich;
|
|
|
|
break;
|
|
|
|
|
2011-07-07 19:20:15 +02:00
|
|
|
case E1000_DEV_ID_82540EM:
|
2012-03-05 12:58:33 +01:00
|
|
|
case E1000_DEV_ID_82545EM:
|
2011-07-07 19:20:15 +02:00
|
|
|
e->eeprom_done_bit = (1 << 4);
|
|
|
|
e->eeprom_addr_off = 8;
|
2009-12-07 19:33:41 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-07-07 19:20:15 +02:00
|
|
|
e->eeprom_done_bit = (1 << 1);
|
|
|
|
e->eeprom_addr_off = 2;
|
2009-12-07 19:33:41 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Inform the user about the new card. */
|
|
|
|
if (!(dname = pci_dev_name(vid, did)))
|
|
|
|
{
|
|
|
|
dname = "Intel Pro/1000 Gigabit Ethernet Card";
|
|
|
|
}
|
|
|
|
E1000_DEBUG(1, ("%s: %s (%04x/%04x/%02x) at %s\n",
|
|
|
|
e->name, dname, vid, did, e->revision,
|
|
|
|
pci_slot_name(devind)));
|
|
|
|
|
|
|
|
/* Reserve PCI resources found. */
|
|
|
|
if ((r = pci_reserve_ok(devind)) != OK)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("failed to reserve PCI device: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
/* Read PCI configuration. */
|
|
|
|
e->irq = pci_attr_r8(devind, PCI_ILR);
|
2012-03-05 12:58:33 +01:00
|
|
|
|
|
|
|
if ((r = pci_get_bar(devind, PCI_BAR, &base, &size, &ioflag)) != OK)
|
|
|
|
panic("failed to get PCI BAR (%d)", r);
|
|
|
|
if (ioflag) panic("PCI BAR is not for memory");
|
|
|
|
|
|
|
|
e->regs = vm_map_phys(SELF, (void *) base, size);
|
2010-03-05 16:05:11 +01:00
|
|
|
if (e->regs == (u8_t *) -1) {
|
|
|
|
panic("failed to map hardware registers from PCI");
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
2012-03-05 12:58:33 +01:00
|
|
|
|
|
|
|
/* FIXME: enable DMA bus mastering if necessary. This is disabled by
|
|
|
|
* default on VMware. Eventually, the PCI driver should deal with this.
|
|
|
|
*/
|
|
|
|
cr = pci_attr_r16(devind, PCI_CR);
|
|
|
|
if (!(cr & PCI_CR_MAST_EN))
|
|
|
|
pci_attr_w16(devind, PCI_CR, cr | PCI_CR_MAST_EN);
|
|
|
|
|
2009-12-07 19:33:41 +01:00
|
|
|
/* Optionally map flash memory. */
|
2010-10-15 10:53:22 +02:00
|
|
|
if (did != E1000_DEV_ID_82540EM &&
|
2012-03-05 12:58:33 +01:00
|
|
|
did != E1000_DEV_ID_82545EM &&
|
2010-10-15 10:53:22 +02:00
|
|
|
did != E1000_DEV_ID_82540EP &&
|
|
|
|
pci_attr_r32(devind, PCI_BAR_2))
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2011-03-15 11:04:35 +01:00
|
|
|
size_t flash_size;
|
|
|
|
|
|
|
|
/* 82566/82567/82562V series support mapping 4kB of flash memory */
|
|
|
|
switch(did)
|
|
|
|
{
|
|
|
|
case E1000_DEV_ID_ICH10_D_BM_LM:
|
|
|
|
case E1000_DEV_ID_ICH10_R_BM_LF:
|
|
|
|
flash_size = 0x1000;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
flash_size = 0x10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((e->flash = vm_map_phys(SELF,
|
|
|
|
(void *) pci_attr_r32(devind, PCI_BAR_2),
|
|
|
|
flash_size)) == MAP_FAILED) {
|
|
|
|
panic("e1000: couldn't map in flash.");
|
|
|
|
}
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
gfpreg = E1000_READ_FLASH_REG(e, ICH_FLASH_GFPREG);
|
|
|
|
/*
|
2010-04-15 20:49:36 +02:00
|
|
|
* sector_base_addr is a "sector"-aligned address (4096 bytes)
|
2009-12-07 19:33:41 +01:00
|
|
|
*/
|
|
|
|
sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
|
|
|
|
|
|
|
|
/* flash_base_addr is byte-aligned */
|
|
|
|
e->flash_base_addr = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Output debug information.
|
|
|
|
*/
|
|
|
|
status[0] = e1000_reg_read(e, E1000_REG_STATUS);
|
2010-05-18 00:22:53 +02:00
|
|
|
E1000_DEBUG(3, ("%s: MEM at %p, IRQ %d\n",
|
2009-12-07 19:33:41 +01:00
|
|
|
e->name, e->regs, e->irq));
|
|
|
|
E1000_DEBUG(3, ("%s: link %s, %s duplex\n",
|
|
|
|
e->name, status[0] & 3 ? "up" : "down",
|
|
|
|
status[0] & 1 ? "full" : "half"));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_init_hw *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int e1000_init_hw(e)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
{
|
|
|
|
int r, i;
|
|
|
|
|
|
|
|
e->status |= E1000_ENABLED;
|
|
|
|
e->irq_hook = e->irq;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the interrupt handler and policy. Do not automatically
|
|
|
|
* re-enable interrupts. Return the IRQ line number on interrupts.
|
|
|
|
*/
|
|
|
|
if ((r = sys_irqsetpolicy(e->irq, 0, &e->irq_hook)) != OK)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_irqsetpolicy failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
if ((r = sys_irqenable(&e->irq_hook)) != OK)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_irqenable failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
/* Reset hardware. */
|
|
|
|
e1000_reset_hw(e);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize appropriately, according to section 14.3 General Configuration
|
|
|
|
* of Intel's Gigabit Ethernet Controllers Software Developer's Manual.
|
|
|
|
*/
|
|
|
|
e1000_reg_set(e, E1000_REG_CTRL, E1000_REG_CTRL_ASDE | E1000_REG_CTRL_SLU);
|
|
|
|
e1000_reg_unset(e, E1000_REG_CTRL, E1000_REG_CTRL_LRST);
|
|
|
|
e1000_reg_unset(e, E1000_REG_CTRL, E1000_REG_CTRL_PHY_RST);
|
|
|
|
e1000_reg_unset(e, E1000_REG_CTRL, E1000_REG_CTRL_ILOS);
|
|
|
|
e1000_reg_write(e, E1000_REG_FCAL, 0);
|
|
|
|
e1000_reg_write(e, E1000_REG_FCAH, 0);
|
|
|
|
e1000_reg_write(e, E1000_REG_FCT, 0);
|
|
|
|
e1000_reg_write(e, E1000_REG_FCTTV, 0);
|
|
|
|
e1000_reg_unset(e, E1000_REG_CTRL, E1000_REG_CTRL_VME);
|
|
|
|
|
|
|
|
/* Clear Multicast Table Array (MTA). */
|
|
|
|
for (i = 0; i < 128; i++)
|
|
|
|
{
|
|
|
|
e1000_reg_write(e, E1000_REG_MTA + i, 0);
|
|
|
|
}
|
|
|
|
/* Initialize statistics registers. */
|
|
|
|
for (i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
e1000_reg_write(e, E1000_REG_CRCERRS + (i * 4), 0);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Aquire MAC address and setup RX/TX buffers.
|
|
|
|
*/
|
|
|
|
e1000_init_addr(e);
|
|
|
|
e1000_init_buf(e);
|
|
|
|
|
|
|
|
/* Enable interrupts. */
|
|
|
|
e1000_reg_set(e, E1000_REG_IMS, E1000_REG_IMS_LSC |
|
|
|
|
E1000_REG_IMS_RXO |
|
|
|
|
E1000_REG_IMS_RXT |
|
|
|
|
E1000_REG_IMS_TXQE |
|
|
|
|
E1000_REG_IMS_TXDW);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_init_addr *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_init_addr(e)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
{
|
|
|
|
static char eakey[]= E1000_ENVVAR "#_EA";
|
|
|
|
static char eafmt[]= "x:x:x:x:x:x";
|
|
|
|
u16_t word;
|
|
|
|
int i;
|
|
|
|
long v;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do we have a user defined ethernet address?
|
|
|
|
*/
|
2010-05-18 00:22:53 +02:00
|
|
|
eakey[sizeof(E1000_ENVVAR)-1] = '0' + e1000_instance;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
for (i= 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
if (env_parse(eakey, eafmt, i, &v, 0x00L, 0xFFL) != EP_SET)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
e->address.ea_addr[i]= v;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If that fails, read Ethernet Address from EEPROM.
|
|
|
|
*/
|
2010-05-18 00:22:53 +02:00
|
|
|
if (i != 6)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
word = e->eeprom_read(e, i);
|
|
|
|
e->address.ea_addr[(i * 2)] = (word & 0xff);
|
|
|
|
e->address.ea_addr[(i * 2) + 1] = (word & 0xff00) >> 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Set Receive Address.
|
|
|
|
*/
|
|
|
|
e1000_reg_write(e, E1000_REG_RAL, *(u32_t *)(&e->address.ea_addr[0]));
|
|
|
|
e1000_reg_write(e, E1000_REG_RAH, *(u16_t *)(&e->address.ea_addr[4]));
|
|
|
|
e1000_reg_set(e, E1000_REG_RAH, E1000_REG_RAH_AV);
|
|
|
|
e1000_reg_set(e, E1000_REG_RCTL, E1000_REG_RCTL_MPE);
|
|
|
|
|
|
|
|
E1000_DEBUG(3, ("%s: Ethernet Address %x:%x:%x:%x:%x:%x\n", e->name,
|
|
|
|
e->address.ea_addr[0], e->address.ea_addr[1],
|
|
|
|
e->address.ea_addr[2], e->address.ea_addr[3],
|
|
|
|
e->address.ea_addr[4], e->address.ea_addr[5]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_init_buf *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_init_buf(e)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
{
|
2012-08-03 18:10:24 +02:00
|
|
|
phys_bytes rx_buff_p;
|
|
|
|
phys_bytes tx_buff_p;
|
2009-12-07 19:33:41 +01:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Number of descriptors. */
|
|
|
|
e->rx_desc_count = E1000_RXDESC_NR;
|
|
|
|
e->tx_desc_count = E1000_TXDESC_NR;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First, allocate the receive descriptors.
|
|
|
|
*/
|
|
|
|
if (!e->rx_desc)
|
|
|
|
{
|
|
|
|
if ((e->rx_desc = alloc_contig(sizeof(e1000_rx_desc_t) *
|
|
|
|
e->rx_desc_count, AC_ALIGN4K,
|
2012-08-03 18:10:24 +02:00
|
|
|
&e->rx_desc_p)) == NULL) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("failed to allocate RX descriptors");
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
memset(e->rx_desc, 0, sizeof(e1000_rx_desc_t) * e->rx_desc_count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate 2048-byte buffers.
|
|
|
|
*/
|
|
|
|
e->rx_buffer_size = E1000_RXDESC_NR * E1000_IOBUF_SIZE;
|
|
|
|
|
|
|
|
/* Attempt to allocate. */
|
|
|
|
if ((e->rx_buffer = alloc_contig(e->rx_buffer_size,
|
|
|
|
AC_ALIGN4K, &rx_buff_p)) == NULL)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("failed to allocate RX buffers");
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
/* Setup receive descriptors. */
|
|
|
|
for (i = 0; i < E1000_RXDESC_NR; i++)
|
|
|
|
{
|
|
|
|
e->rx_desc[i].buffer = rx_buff_p + (i * E1000_IOBUF_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Then, allocate transmit descriptors.
|
|
|
|
*/
|
|
|
|
if (!e->tx_desc)
|
|
|
|
{
|
|
|
|
if ((e->tx_desc = alloc_contig(sizeof(e1000_tx_desc_t) *
|
|
|
|
e->tx_desc_count, AC_ALIGN4K,
|
2012-08-03 18:10:24 +02:00
|
|
|
&e->tx_desc_p)) == NULL) {
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("failed to allocate TX descriptors");
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
memset(e->tx_desc, 0, sizeof(e1000_tx_desc_t) * e->tx_desc_count);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate 2048-byte buffers.
|
|
|
|
*/
|
|
|
|
e->tx_buffer_size = E1000_TXDESC_NR * E1000_IOBUF_SIZE;
|
|
|
|
|
|
|
|
/* Attempt to allocate. */
|
|
|
|
if ((e->tx_buffer = alloc_contig(e->tx_buffer_size,
|
|
|
|
AC_ALIGN4K, &tx_buff_p)) == NULL)
|
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("failed to allocate TX buffers");
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
/* Setup transmit descriptors. */
|
2012-03-05 12:58:33 +01:00
|
|
|
for (i = 0; i < E1000_TXDESC_NR; i++)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
e->tx_desc[i].buffer = tx_buff_p + (i * E1000_IOBUF_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Setup the receive ring registers.
|
|
|
|
*/
|
2012-08-03 18:10:24 +02:00
|
|
|
e1000_reg_write(e, E1000_REG_RDBAL, e->rx_desc_p);
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_reg_write(e, E1000_REG_RDBAH, 0);
|
|
|
|
e1000_reg_write(e, E1000_REG_RDLEN, e->rx_desc_count *
|
|
|
|
sizeof(e1000_rx_desc_t));
|
|
|
|
e1000_reg_write(e, E1000_REG_RDH, 0);
|
|
|
|
e1000_reg_write(e, E1000_REG_RDT, e->rx_desc_count - 1);
|
|
|
|
e1000_reg_unset(e, E1000_REG_RCTL, E1000_REG_RCTL_BSIZE);
|
|
|
|
e1000_reg_set(e, E1000_REG_RCTL, E1000_REG_RCTL_EN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the transmit ring registers.
|
|
|
|
*/
|
2012-08-03 18:10:24 +02:00
|
|
|
e1000_reg_write(e, E1000_REG_TDBAL, e->tx_desc_p);
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_reg_write(e, E1000_REG_TDBAH, 0);
|
|
|
|
e1000_reg_write(e, E1000_REG_TDLEN, e->tx_desc_count *
|
|
|
|
sizeof(e1000_tx_desc_t));
|
|
|
|
e1000_reg_write(e, E1000_REG_TDH, 0);
|
|
|
|
e1000_reg_write(e, E1000_REG_TDT, 0);
|
|
|
|
e1000_reg_set( e, E1000_REG_TCTL, E1000_REG_TCTL_EN | E1000_REG_TCTL_PSP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_reset_hw *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_reset_hw(e)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
{
|
|
|
|
/* Assert a Device Reset signal. */
|
|
|
|
e1000_reg_set(e, E1000_REG_CTRL, E1000_REG_CTRL_RST);
|
|
|
|
|
|
|
|
/* Wait one microsecond. */
|
|
|
|
tickdelay(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_writev_s *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_writev_s(mp, from_int)
|
2009-12-07 19:33:41 +01:00
|
|
|
message *mp;
|
|
|
|
int from_int;
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
e1000_t *e = &e1000_state;
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_tx_desc_t *desc;
|
|
|
|
iovec_s_t iovec[E1000_IOVEC_NR];
|
|
|
|
int r, head, tail, i, bytes = 0, size;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
E1000_DEBUG(3, ("e1000: writev_s(%p,%d)\n", mp, from_int));
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Are we called from the interrupt handler? */
|
|
|
|
if (!from_int)
|
|
|
|
{
|
|
|
|
/* We cannot write twice simultaneously.
|
|
|
|
assert(!(e->status & E1000_WRITING)); */
|
|
|
|
|
|
|
|
/* Copy write message. */
|
|
|
|
e->tx_message = *mp;
|
2010-05-18 00:22:53 +02:00
|
|
|
e->client = mp->m_source;
|
2009-12-07 19:33:41 +01:00
|
|
|
e->status |= E1000_WRITING;
|
|
|
|
|
|
|
|
/* Must be a sane vector count. */
|
2014-05-20 11:19:27 +02:00
|
|
|
assert(e->tx_message.m_net_netdrv_dl_writev_s.count > 0);
|
|
|
|
assert(e->tx_message.m_net_netdrv_dl_writev_s.count < E1000_IOVEC_NR);
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the I/O vector table.
|
|
|
|
*/
|
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
|
|
|
if ((r = sys_safecopyfrom(e->tx_message.m_source,
|
2014-05-20 11:19:27 +02:00
|
|
|
e->tx_message.m_net_netdrv_dl_writev_s.grant, 0,
|
|
|
|
(vir_bytes) iovec,
|
|
|
|
e->tx_message.m_net_netdrv_dl_writev_s.count *
|
2012-06-16 03:46:15 +02:00
|
|
|
sizeof(iovec_s_t))) != OK)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_safecopyfrom() failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
/* Find the head, tail and current descriptors. */
|
|
|
|
head = e1000_reg_read(e, E1000_REG_TDH);
|
|
|
|
tail = e1000_reg_read(e, E1000_REG_TDT);
|
|
|
|
desc = &e->tx_desc[tail];
|
|
|
|
|
|
|
|
E1000_DEBUG(4, ("%s: head=%d, tail=%d\n",
|
|
|
|
e->name, head, tail));
|
|
|
|
|
|
|
|
/* Loop vector elements. */
|
2014-05-20 11:19:27 +02:00
|
|
|
for (i = 0; i < e->tx_message.m_net_netdrv_dl_writev_s.count; i++)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
size = iovec[i].iov_size < (E1000_IOBUF_SIZE - bytes) ?
|
|
|
|
iovec[i].iov_size : (E1000_IOBUF_SIZE - bytes);
|
|
|
|
|
|
|
|
E1000_DEBUG(4, ("iovec[%d] = %d\n", i, size));
|
|
|
|
|
|
|
|
/* Copy bytes to TX queue buffers. */
|
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
|
|
|
if ((r = sys_safecopyfrom(e->tx_message.m_source,
|
2010-05-18 00:22:53 +02:00
|
|
|
iovec[i].iov_grant, 0,
|
2009-12-07 19:33:41 +01:00
|
|
|
(vir_bytes) e->tx_buffer +
|
|
|
|
(tail * E1000_IOBUF_SIZE),
|
2012-06-16 03:46:15 +02:00
|
|
|
size)) != OK)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_safecopyfrom() failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
/* Mark this descriptor ready. */
|
|
|
|
desc->status = 0;
|
|
|
|
desc->command = 0;
|
|
|
|
desc->length = size;
|
|
|
|
|
|
|
|
/* Marks End-of-Packet. */
|
2014-05-20 11:19:27 +02:00
|
|
|
if (i == e->tx_message.m_net_netdrv_dl_writev_s.count - 1)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
desc->command = E1000_TX_CMD_EOP |
|
|
|
|
E1000_TX_CMD_FCS |
|
|
|
|
E1000_TX_CMD_RS;
|
|
|
|
}
|
|
|
|
/* Move to next descriptor. */
|
|
|
|
tail = (tail + 1) % e->tx_desc_count;
|
|
|
|
bytes += size;
|
|
|
|
desc = &e->tx_desc[tail];
|
|
|
|
}
|
|
|
|
/* Increment tail. Start transmission. */
|
|
|
|
e1000_reg_write(e, E1000_REG_TDT, tail);
|
|
|
|
|
|
|
|
E1000_DEBUG(2, ("e1000: wrote %d byte packet\n", bytes));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
e->status |= E1000_TRANSMIT;
|
|
|
|
}
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(e);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_readv_s *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_readv_s(mp, from_int)
|
2009-12-07 19:33:41 +01:00
|
|
|
message *mp;
|
|
|
|
int from_int;
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
e1000_t *e = &e1000_state;
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_rx_desc_t *desc;
|
|
|
|
iovec_s_t iovec[E1000_IOVEC_NR];
|
|
|
|
int i, r, head, tail, cur, bytes = 0, size;
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
E1000_DEBUG(3, ("e1000: readv_s(%p,%d)\n", mp, from_int));
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Are we called from the interrupt handler? */
|
|
|
|
if (!from_int)
|
|
|
|
{
|
|
|
|
e->rx_message = *mp;
|
2010-05-18 00:22:53 +02:00
|
|
|
e->client = mp->m_source;
|
2009-12-07 19:33:41 +01:00
|
|
|
e->status |= E1000_READING;
|
|
|
|
e->rx_size = 0;
|
|
|
|
|
2014-05-20 11:19:27 +02:00
|
|
|
assert(e->rx_message.m_net_netdrv_dl_readv_s.count > 0);
|
|
|
|
assert(e->rx_message.m_net_netdrv_dl_readv_s.count < E1000_IOVEC_NR);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
if (e->status & E1000_READING)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Copy the I/O vector table first.
|
|
|
|
*/
|
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
|
|
|
if ((r = sys_safecopyfrom(e->rx_message.m_source,
|
2014-05-20 11:19:27 +02:00
|
|
|
e->rx_message.m_net_netdrv_dl_readv_s.grant, 0,
|
|
|
|
(vir_bytes) iovec,
|
|
|
|
e->rx_message.m_net_netdrv_dl_readv_s.count *
|
2012-06-16 03:46:15 +02:00
|
|
|
sizeof(iovec_s_t))) != OK)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_safecopyfrom() failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
/* Find the head, tail and current descriptors. */
|
|
|
|
head = e1000_reg_read(e, E1000_REG_RDH);
|
|
|
|
tail = e1000_reg_read(e, E1000_REG_RDT);
|
|
|
|
cur = (tail + 1) % e->rx_desc_count;
|
|
|
|
desc = &e->rx_desc[cur];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only handle one packet at a time.
|
|
|
|
*/
|
|
|
|
if (!(desc->status & E1000_RX_STATUS_EOP))
|
|
|
|
{
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(e);
|
2009-12-07 19:33:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
E1000_DEBUG(4, ("%s: head=%x, tail=%d\n",
|
|
|
|
e->name, head, tail));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy to vector elements.
|
|
|
|
*/
|
2014-05-20 11:19:27 +02:00
|
|
|
for (i = 0; i < e->rx_message.m_net_netdrv_dl_readv_s.count &&
|
|
|
|
bytes < desc->length; i++)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
size = iovec[i].iov_size < (desc->length - bytes) ?
|
|
|
|
iovec[i].iov_size : (desc->length - bytes);
|
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
E1000_DEBUG(4, ("iovec[%d] = %lu[%d]\n",
|
2009-12-07 19:33:41 +01:00
|
|
|
i, iovec[i].iov_size, size));
|
|
|
|
|
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
|
|
|
if ((r = sys_safecopyto(e->rx_message.m_source, iovec[i].iov_grant,
|
2010-05-18 00:22:53 +02:00
|
|
|
0, (vir_bytes) e->rx_buffer + bytes +
|
2009-12-07 19:33:41 +01:00
|
|
|
(cur * E1000_IOBUF_SIZE),
|
2012-06-16 03:46:15 +02:00
|
|
|
size)) != OK)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("sys_safecopyto() failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
bytes += size;
|
|
|
|
}
|
|
|
|
desc->status = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update state.
|
|
|
|
*/
|
|
|
|
e->rx_size = bytes;
|
|
|
|
e->status |= E1000_RECEIVED;
|
|
|
|
E1000_DEBUG(2, ("e1000: got %d byte packet\n", e->rx_size));
|
|
|
|
|
|
|
|
/* Increment tail. */
|
|
|
|
e1000_reg_write(e, E1000_REG_RDT, (tail + 1) % e->rx_desc_count);
|
|
|
|
}
|
2010-05-18 00:22:53 +02:00
|
|
|
reply(e);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_getstat_s *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_getstat_s(mp)
|
2009-12-07 19:33:41 +01:00
|
|
|
message *mp;
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
eth_stat_t stats;
|
2010-05-18 00:22:53 +02:00
|
|
|
e1000_t *e = &e1000_state;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
E1000_DEBUG(3, ("e1000: getstat_s()\n"));
|
|
|
|
|
|
|
|
stats.ets_recvErr = e1000_reg_read(e, E1000_REG_RXERRC);
|
|
|
|
stats.ets_sendErr = 0;
|
|
|
|
stats.ets_OVW = 0;
|
|
|
|
stats.ets_CRCerr = e1000_reg_read(e, E1000_REG_CRCERRS);
|
|
|
|
stats.ets_frameAll = 0;
|
|
|
|
stats.ets_missedP = e1000_reg_read(e, E1000_REG_MPC);
|
|
|
|
stats.ets_packetR = e1000_reg_read(e, E1000_REG_TPR);
|
|
|
|
stats.ets_packetT = e1000_reg_read(e, E1000_REG_TPT);
|
|
|
|
stats.ets_collision = e1000_reg_read(e, E1000_REG_COLC);
|
|
|
|
stats.ets_transAb = 0;
|
|
|
|
stats.ets_carrSense = 0;
|
|
|
|
stats.ets_fifoUnder = 0;
|
|
|
|
stats.ets_fifoOver = 0;
|
|
|
|
stats.ets_CDheartbeat = 0;
|
|
|
|
stats.ets_OWC = 0;
|
|
|
|
|
2014-05-19 19:40:12 +02:00
|
|
|
sys_safecopyto(mp->m_source, mp->m_net_netdrv_dl_getstat_s.grant, 0,
|
|
|
|
(vir_bytes)&stats, sizeof(stats));
|
2009-12-07 19:33:41 +01:00
|
|
|
mp->m_type = DL_STAT_REPLY;
|
2013-11-01 13:34:14 +01:00
|
|
|
if((r=ipc_send(mp->m_source, mp)) != OK)
|
|
|
|
panic("e1000_getstat: ipc_send() failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_interrupt *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_interrupt(mp)
|
2009-12-07 19:33:41 +01:00
|
|
|
message *mp;
|
|
|
|
{
|
|
|
|
e1000_t *e;
|
|
|
|
u32_t cause;
|
|
|
|
|
|
|
|
E1000_DEBUG(3, ("e1000: interrupt\n"));
|
|
|
|
|
|
|
|
/*
|
2010-05-18 00:22:53 +02:00
|
|
|
* Check the card for interrupt reason(s).
|
2009-12-07 19:33:41 +01:00
|
|
|
*/
|
2010-05-18 00:22:53 +02:00
|
|
|
e = &e1000_state;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
/* Re-enable interrupts. */
|
|
|
|
if (sys_irqenable(&e->irq_hook) != OK)
|
|
|
|
{
|
|
|
|
panic("failed to re-enable IRQ");
|
|
|
|
}
|
2009-12-07 19:33:41 +01:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
/* Read the Interrupt Cause Read register. */
|
|
|
|
if ((cause = e1000_reg_read(e, E1000_REG_ICR)))
|
|
|
|
{
|
|
|
|
if (cause & E1000_REG_ICR_LSC)
|
|
|
|
e1000_link_changed(e);
|
2009-12-07 19:33:41 +01:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
if (cause & (E1000_REG_ICR_RXO | E1000_REG_ICR_RXT))
|
|
|
|
e1000_readv_s(&e->rx_message, TRUE);
|
2009-12-07 19:33:41 +01:00
|
|
|
|
2010-05-18 00:22:53 +02:00
|
|
|
if ((cause & E1000_REG_ICR_TXQE) ||
|
|
|
|
(cause & E1000_REG_ICR_TXDW))
|
|
|
|
e1000_writev_s(&e->tx_message, TRUE);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_link_changed *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int e1000_link_changed(e)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
{
|
|
|
|
E1000_DEBUG(4, ("%s: link_changed()\n", e->name));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_stop *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_stop(e)
|
2012-01-30 15:32:31 +01:00
|
|
|
e1000_t *e;
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2012-01-30 15:32:31 +01:00
|
|
|
E1000_DEBUG(3, ("%s: stop()\n", e->name));
|
|
|
|
|
|
|
|
e1000_reset_hw(e);
|
|
|
|
|
2009-12-07 19:33:41 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_reg_read *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static uint32_t e1000_reg_read(e, reg)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
uint32_t reg;
|
|
|
|
{
|
|
|
|
uint32_t value;
|
|
|
|
|
|
|
|
/* Assume a sane register. */
|
|
|
|
assert(reg < 0x1ffff);
|
|
|
|
|
|
|
|
/* Read from memory mapped register. */
|
2011-07-04 10:46:51 +02:00
|
|
|
value = *(volatile u32_t *)(e->regs + reg);
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Return the result. */
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_reg_write *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_reg_write(e, reg, value)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
uint32_t reg;
|
|
|
|
uint32_t value;
|
|
|
|
{
|
|
|
|
/* Assume a sane register. */
|
|
|
|
assert(reg < 0x1ffff);
|
|
|
|
|
|
|
|
/* Write to memory mapped register. */
|
2011-07-04 10:46:51 +02:00
|
|
|
*(volatile u32_t *)(e->regs + reg) = value;
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_reg_set *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_reg_set(e, reg, value)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
uint32_t reg;
|
|
|
|
uint32_t value;
|
|
|
|
{
|
|
|
|
uint32_t data;
|
|
|
|
|
|
|
|
/* First read the current value. */
|
|
|
|
data = e1000_reg_read(e, reg);
|
|
|
|
|
|
|
|
/* Set value, and write back. */
|
|
|
|
e1000_reg_write(e, reg, data | value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* e1000_reg_unset *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void e1000_reg_unset(e, reg, value)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
uint32_t reg;
|
|
|
|
uint32_t value;
|
|
|
|
{
|
|
|
|
uint32_t data;
|
|
|
|
|
|
|
|
/* First read the current value. */
|
|
|
|
data = e1000_reg_read(e, reg);
|
|
|
|
|
|
|
|
/* Unset value, and write back. */
|
|
|
|
e1000_reg_write(e, reg, data & ~value);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* eeprom_eerd *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static u16_t eeprom_eerd(v, reg)
|
2009-12-07 19:33:41 +01:00
|
|
|
void *v;
|
|
|
|
int reg;
|
|
|
|
{
|
|
|
|
e1000_t *e = (e1000_t *) v;
|
2011-07-07 19:24:26 +02:00
|
|
|
u32_t data;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Request EEPROM read. */
|
|
|
|
e1000_reg_write(e, E1000_REG_EERD,
|
|
|
|
(reg << e->eeprom_addr_off) | (E1000_REG_EERD_START));
|
|
|
|
|
|
|
|
/* Wait until ready. */
|
2011-07-13 11:36:10 +02:00
|
|
|
while (!((data = (e1000_reg_read(e, E1000_REG_EERD))) & e->eeprom_done_bit));
|
2009-12-07 19:33:41 +01:00
|
|
|
|
2011-07-07 19:24:26 +02:00
|
|
|
return data >> 16;
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* eeprom_ich_init *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int eeprom_ich_init(e)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
{
|
|
|
|
union ich8_hws_flash_status hsfsts;
|
|
|
|
int ret_val = -1;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
hsfsts.regval = E1000_READ_FLASH_REG16(e, ICH_FLASH_HSFSTS);
|
|
|
|
|
|
|
|
/* Check if the flash descriptor is valid */
|
|
|
|
if (hsfsts.hsf_status.fldesvalid == 0)
|
|
|
|
{
|
|
|
|
E1000_DEBUG(3, ("Flash descriptor invalid. "
|
|
|
|
"SW Sequencing must be used."));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* Clear FCERR and DAEL in hw status by writing 1 */
|
|
|
|
hsfsts.hsf_status.flcerr = 1;
|
|
|
|
hsfsts.hsf_status.dael = 1;
|
|
|
|
|
|
|
|
E1000_WRITE_FLASH_REG16(e, ICH_FLASH_HSFSTS, hsfsts.regval);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Either we should have a hardware SPI cycle in progress
|
|
|
|
* bit to check against, in order to start a new cycle or
|
|
|
|
* FDONE bit should be changed in the hardware so that it
|
|
|
|
* is 1 after hardware reset, which can then be used as an
|
|
|
|
* indication whether a cycle is in progress or has been
|
|
|
|
* completed.
|
|
|
|
*/
|
|
|
|
if (hsfsts.hsf_status.flcinprog == 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* There is no cycle running at present,
|
|
|
|
* so we can start a cycle.
|
|
|
|
* Begin by setting Flash Cycle Done.
|
|
|
|
*/
|
|
|
|
hsfsts.hsf_status.flcdone = 1;
|
|
|
|
E1000_WRITE_FLASH_REG16(e, ICH_FLASH_HSFSTS, hsfsts.regval);
|
|
|
|
ret_val = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Otherwise poll for sometime so the current
|
|
|
|
* cycle has a chance to end before giving up.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++)
|
|
|
|
{
|
|
|
|
hsfsts.regval = E1000_READ_FLASH_REG16(e, ICH_FLASH_HSFSTS);
|
|
|
|
|
|
|
|
if (hsfsts.hsf_status.flcinprog == 0)
|
|
|
|
{
|
|
|
|
ret_val = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tickdelay(1);
|
|
|
|
}
|
|
|
|
if (ret_val == 0)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Successful in waiting for previous cycle to timeout,
|
|
|
|
* now set the Flash Cycle Done.
|
|
|
|
*/
|
|
|
|
hsfsts.hsf_status.flcdone = 1;
|
|
|
|
E1000_WRITE_FLASH_REG16(e, ICH_FLASH_HSFSTS,
|
|
|
|
hsfsts.regval);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
E1000_DEBUG(3, ("Flash controller busy, cannot get access"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* eeprom_ich_cycle *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static int eeprom_ich_cycle(const e1000_t *e, u32_t timeout)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
|
|
|
union ich8_hws_flash_ctrl hsflctl;
|
|
|
|
union ich8_hws_flash_status hsfsts;
|
|
|
|
int ret_val = -1;
|
|
|
|
u32_t i = 0;
|
|
|
|
|
|
|
|
E1000_DEBUG(3, ("e1000_flash_cycle_ich8lan"));
|
|
|
|
|
|
|
|
/* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
|
|
|
|
hsflctl.regval = E1000_READ_FLASH_REG16(e, ICH_FLASH_HSFCTL);
|
|
|
|
hsflctl.hsf_ctrl.flcgo = 1;
|
|
|
|
E1000_WRITE_FLASH_REG16(e, ICH_FLASH_HSFCTL, hsflctl.regval);
|
|
|
|
|
|
|
|
/* wait till FDONE bit is set to 1 */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
hsfsts.regval = E1000_READ_FLASH_REG16(e, ICH_FLASH_HSFSTS);
|
|
|
|
if (hsfsts.hsf_status.flcdone == 1)
|
|
|
|
break;
|
|
|
|
tickdelay(1);
|
|
|
|
}
|
|
|
|
while (i++ < timeout);
|
|
|
|
|
|
|
|
if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
|
|
|
|
ret_val = 0;
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* eeprom_ich *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static u16_t eeprom_ich(v, reg)
|
2009-12-07 19:33:41 +01:00
|
|
|
void *v;
|
|
|
|
int reg;
|
|
|
|
{
|
|
|
|
union ich8_hws_flash_status hsfsts;
|
|
|
|
union ich8_hws_flash_ctrl hsflctl;
|
|
|
|
u32_t flash_linear_addr;
|
|
|
|
u32_t flash_data = 0;
|
|
|
|
int ret_val = -1;
|
|
|
|
u8_t count = 0;
|
|
|
|
e1000_t *e = (e1000_t *) v;
|
2010-05-18 00:22:53 +02:00
|
|
|
u16_t data = 0;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
E1000_DEBUG(3, ("e1000_read_flash_data_ich8lan"));
|
|
|
|
|
|
|
|
if (reg > ICH_FLASH_LINEAR_ADDR_MASK)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
reg *= sizeof(u16_t);
|
|
|
|
flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & reg) +
|
|
|
|
e->flash_base_addr;
|
|
|
|
|
|
|
|
do {
|
|
|
|
tickdelay(1);
|
|
|
|
|
|
|
|
/* Steps */
|
|
|
|
ret_val = eeprom_ich_init(e);
|
|
|
|
if (ret_val != 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
hsflctl.regval = E1000_READ_FLASH_REG16(e, ICH_FLASH_HSFCTL);
|
|
|
|
/* 0b/1b corresponds to 1 or 2 byte size, respectively. */
|
|
|
|
hsflctl.hsf_ctrl.fldbcount = 1;
|
|
|
|
hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
|
|
|
|
E1000_WRITE_FLASH_REG16(e, ICH_FLASH_HSFCTL, hsflctl.regval);
|
|
|
|
E1000_WRITE_FLASH_REG(e, ICH_FLASH_FADDR, flash_linear_addr);
|
|
|
|
|
|
|
|
ret_val = eeprom_ich_cycle(v, ICH_FLASH_READ_COMMAND_TIMEOUT);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if FCERR is set to 1, if set to 1, clear it
|
|
|
|
* and try the whole sequence a few more times, else
|
|
|
|
* read in (shift in) the Flash Data0, the order is
|
|
|
|
* least significant byte first msb to lsb
|
|
|
|
*/
|
|
|
|
if (ret_val == 0)
|
|
|
|
{
|
|
|
|
flash_data = E1000_READ_FLASH_REG(e, ICH_FLASH_FDATA0);
|
|
|
|
data = (u16_t)(flash_data & 0x0000FFFF);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If we've gotten here, then things are probably
|
|
|
|
* completely hosed, but if the error condition is
|
|
|
|
* detected, it won't hurt to give it another try...
|
|
|
|
* ICH_FLASH_CYCLE_REPEAT_COUNT times.
|
|
|
|
*/
|
|
|
|
hsfsts.regval = E1000_READ_FLASH_REG16(e, ICH_FLASH_HSFSTS);
|
|
|
|
|
|
|
|
if (hsfsts.hsf_status.flcerr == 1)
|
|
|
|
{
|
|
|
|
/* Repeat for some time before giving up. */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (hsfsts.hsf_status.flcdone == 0)
|
|
|
|
{
|
|
|
|
E1000_DEBUG(3, ("Timeout error - flash cycle "
|
|
|
|
"did not complete."));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
|
|
|
|
|
|
|
|
out:
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* reply *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void reply(e)
|
2009-12-07 19:33:41 +01:00
|
|
|
e1000_t *e;
|
|
|
|
{
|
|
|
|
message msg;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
/* Only reply to client for read/write request. */
|
|
|
|
if (!(e->status & E1000_READING ||
|
|
|
|
e->status & E1000_WRITING))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Construct reply message. */
|
|
|
|
msg.m_type = DL_TASK_REPLY;
|
2014-05-20 09:13:26 +02:00
|
|
|
msg.m_netdrv_net_dl_task.flags = DL_NOFLAGS;
|
|
|
|
msg.m_netdrv_net_dl_task.count = 0;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Did we successfully receive packet(s)? */
|
|
|
|
if (e->status & E1000_READING &&
|
|
|
|
e->status & E1000_RECEIVED)
|
|
|
|
{
|
2014-05-20 09:13:26 +02:00
|
|
|
msg.m_netdrv_net_dl_task.flags |= DL_PACK_RECV;
|
|
|
|
msg.m_netdrv_net_dl_task.count =
|
|
|
|
e->rx_size >= ETH_MIN_PACK_SIZE ?
|
|
|
|
e->rx_size : ETH_MIN_PACK_SIZE;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Clear flags. */
|
|
|
|
e->status &= ~(E1000_READING | E1000_RECEIVED);
|
|
|
|
}
|
|
|
|
/* Did we successfully transmit packet(s)? */
|
|
|
|
if (e->status & E1000_TRANSMIT &&
|
|
|
|
e->status & E1000_WRITING)
|
|
|
|
{
|
2014-05-20 09:13:26 +02:00
|
|
|
msg.m_netdrv_net_dl_task.flags |= DL_PACK_SEND;
|
2009-12-07 19:33:41 +01:00
|
|
|
|
|
|
|
/* Clear flags. */
|
|
|
|
e->status &= ~(E1000_WRITING | E1000_TRANSMIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Acknowledge to INET. */
|
2013-11-01 13:34:14 +01:00
|
|
|
if ((r = ipc_send(e->client, &msg)) != OK)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2013-11-01 13:34:14 +01:00
|
|
|
panic("ipc_send() failed: %d", r);
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* mess_reply *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
static void mess_reply(req, reply_mess)
|
2009-12-07 19:33:41 +01:00
|
|
|
message *req;
|
|
|
|
message *reply_mess;
|
|
|
|
{
|
2013-11-01 13:34:14 +01:00
|
|
|
if (ipc_send(req->m_source, reply_mess) != OK)
|
2009-12-07 19:33:41 +01:00
|
|
|
{
|
2010-03-05 16:05:11 +01:00
|
|
|
panic("unable to send reply message");
|
2009-12-07 19:33:41 +01:00
|
|
|
}
|
|
|
|
}
|