diff --git a/minix/drivers/net/dp8390/3c503.c b/minix/drivers/net/dp8390/3c503.c index fd2f9d121..54702c677 100644 --- a/minix/drivers/net/dp8390/3c503.c +++ b/minix/drivers/net/dp8390/3c503.c @@ -12,6 +12,7 @@ */ #include +#include #include #include diff --git a/minix/drivers/net/dp8390/Makefile b/minix/drivers/net/dp8390/Makefile index 0fcbcc86d..d48227ef7 100644 --- a/minix/drivers/net/dp8390/Makefile +++ b/minix/drivers/net/dp8390/Makefile @@ -2,7 +2,7 @@ PROG= dp8390 SRCS= 3c503.c dp8390.c ne2000.c rtl8029.c wdeth.c -DPADD+= ${LIBNETDRIVER} ${LIBSYS} ${LIBTIMERS} -LDADD+= -lnetdriver -lsys -ltimers +DPADD+= ${LIBNETDRIVER} ${LIBSYS} +LDADD+= -lnetdriver -lsys .include diff --git a/minix/drivers/net/dp8390/dp8390.c b/minix/drivers/net/dp8390/dp8390.c index 3d23db40b..c68d634cb 100644 --- a/minix/drivers/net/dp8390/dp8390.c +++ b/minix/drivers/net/dp8390/dp8390.c @@ -16,14 +16,7 @@ #include #include -#include -#include -#include -#include #include -#include -#include -#include #include #include "assert.h" @@ -70,203 +63,100 @@ static dp_conf_t dp_conf[DP_CONF_NR]= /* Card addresses */ */ #define CR_EXTRA CR_STA -#if ENABLE_PCI +static int do_init(unsigned int instance, ether_addr_t *addr); static void pci_conf(void); -#endif -static void do_vwrite_s(message *mp, int from_int); -static void do_vread_s(message *mp); -static void do_init(message *mp); -static void do_int(dpeth_t *dep); -static void do_getstat_s(message *mp); -static void dp_stop(dpeth_t *dep); +static int do_send(struct netdriver_data *data, size_t size); +static ssize_t do_recv(struct netdriver_data *data, size_t max); +static void do_mode(unsigned int mode); +static void do_stat(eth_stat_t *stat); +static void do_stop(void); static void dp_init(dpeth_t *dep); static void dp_confaddr(dpeth_t *dep); -static void dp_reinit(dpeth_t *dep); static void dp_reset(dpeth_t *dep); -static void dp_check_ints(dpeth_t *dep); -static void dp_recv(dpeth_t *dep); -static void dp_send(dpeth_t *dep); +static void do_intr(unsigned int mask); static void dp_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst); static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst); static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset, size_t size, void *dst); -static int dp_pkt2user_s(dpeth_t *dep, int page, vir_bytes length); -static void dp_user2nic_s(dpeth_t *dep, iovec_dat_s_t *iovp, vir_bytes - offset, int nic_addr, vir_bytes count); -static void dp_pio8_user2nic_s(dpeth_t *dep, iovec_dat_s_t *iovp, - vir_bytes offset, int nic_addr, vir_bytes count); -static void dp_pio16_user2nic_s(dpeth_t *dep, iovec_dat_s_t *iovp, - vir_bytes offset, int nic_addr, vir_bytes count); -static void dp_nic2user_s(dpeth_t *dep, int nic_addr, iovec_dat_s_t - *iovp, vir_bytes offset, vir_bytes count); -static void dp_pio8_nic2user_s(dpeth_t *dep, int nic_addr, iovec_dat_s_t - *iovp, vir_bytes offset, vir_bytes count); -static void dp_pio16_nic2user_s(dpeth_t *dep, int nic_addr, - iovec_dat_s_t *iovp, vir_bytes offset, vir_bytes count); -static void dp_next_iovec_s(iovec_dat_s_t *iovp); +static void dp_pkt2user_s(dpeth_t *dep, struct netdriver_data *data, int page, + size_t length); +static void dp_user2nic_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count); +static void dp_pio8_user2nic_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count); +static void dp_pio16_user2nic_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count); +static void dp_nic2user_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count); +static void dp_pio8_nic2user_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count); +static void dp_pio16_nic2user_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count); static void conf_hw(dpeth_t *dep); static void update_conf(dpeth_t *dep, dp_conf_t *dcp); static void map_hw_buffer(dpeth_t *dep); -static int calc_iovec_size_s(iovec_dat_s_t *iovp); -static void reply(dpeth_t *dep); -static void mess_reply(message *req, message *reply); -static void get_userdata_s(int user_proc, cp_grant_id_t grant, vir_bytes - offset, vir_bytes count, void *loc_addr); -static void put_userdata_s(int user_proc, cp_grant_id_t grant, size_t - count, void *loc_addr); static void insb(port_t port, void *buf, size_t size); static void insw(port_t port, void *buf, size_t size); -static void do_vir_insb(port_t port, int proc, vir_bytes buf, size_t - size); -static void do_vir_insw(port_t port, int proc, vir_bytes buf, size_t - size); -/* SEF functions and variables. */ -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); - -static void handle_hw_intr(void) -{ - int r, irq; - dpeth_t *dep; - - dep = &de_state; - - if (dep->de_mode != DEM_ENABLED) - return; - assert(dep->de_flags & DEF_ENABLED); - irq= dep->de_irq; - assert(irq >= 0 && irq < NR_IRQ_VECTORS); - if (dep->de_int_pending || 1) - { - dep->de_int_pending= 0; - dp_check_ints(dep); - do_int(dep); - r= sys_irqenable(&dep->de_hook); - if (r != OK) { - panic("unable enable interrupts: %d", r); - } - } -} +static const struct netdriver dp_table = { + .ndr_init = do_init, + .ndr_stop = do_stop, + .ndr_mode = do_mode, + .ndr_recv = do_recv, + .ndr_send = do_send, + .ndr_stat = do_stat, + .ndr_intr = do_intr +}; /*===========================================================================* - * dpeth_task * + * main * *===========================================================================*/ int main(int argc, char *argv[]) { - message m; - int ipc_status; - int r; - - /* SEF local startup. */ env_setargs(argc, argv); - sef_local_startup(); - while (TRUE) - { - if ((r= netdriver_receive(ANY, &m, &ipc_status)) != OK) - panic("dp8390: netdriver_receive failed: %d", r); + netdriver_task(&dp_table); - if (is_ipc_notify(ipc_status)) { - switch (_ENDPOINT_P(m.m_source)) { - case HARDWARE: - handle_hw_intr(); - break; - case CLOCK: - printf("dp8390: notify from CLOCK\n"); - break; - default: - panic("dp8390: illegal notify from: %d", - m.m_source); - } - - /* done, get a new message */ - continue; - } - - switch (m.m_type) - { - case DL_WRITEV_S: do_vwrite_s(&m, FALSE); break; - case DL_READV_S: do_vread_s(&m); break; - case DL_CONF: do_init(&m); break; - case DL_GETSTAT_S: do_getstat_s(&m); break; - default: - panic("dp8390: illegal message: %d", m.m_type); - } - } + return 0; } /*===========================================================================* - * sef_local_startup * + * do_init * *===========================================================================*/ -static void sef_local_startup() -{ - /* Register init callbacks. */ - sef_setcb_init_fresh(sef_cb_init_fresh); - sef_setcb_init_lu(sef_cb_init_fresh); - sef_setcb_init_restart(sef_cb_init_fresh); - - /* 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); - - /* Register signal callbacks. */ - sef_setcb_signal_handler(sef_cb_signal_handler); - - /* Let SEF perform startup. */ - sef_startup(); -} - -/*===========================================================================* - * sef_cb_init_fresh * - *===========================================================================*/ -static int sef_cb_init_fresh(int type, sef_init_info_t *UNUSED(info)) +static int do_init(unsigned int instance, ether_addr_t *addr) { /* Initialize the dp8390 driver. */ dpeth_t *dep; - long v; system_hz = sys_hz(); - if (env_argc < 1) { - panic("A head which at this time has no name"); - } - - v = 0; - (void) env_parse("instance", "d", 0, &v, 0, 255); - de_instance = (int) v; + de_instance = instance; dep = &de_state; + memset(dep, 0, sizeof(*dep)); strlcpy(dep->de_name, "dp8390#0", sizeof(dep->de_name)); dep->de_name[7] += de_instance; - /* Announce we are up! */ - netdriver_announce(); + pci_conf(); /* Configure PCI devices. */ - return(OK); -} + /* This is the default, try to (re)locate the device. */ + conf_hw(dep); -/*===========================================================================* - * sef_cb_signal_handler * - *===========================================================================*/ -static void sef_cb_signal_handler(int signo) -{ - /* Only check for termination signal, ignore anything else. */ - if (signo != SIGTERM) return; + dp_init(dep); - if (de_state.de_mode == DEM_ENABLED) - dp_stop(&de_state); + memcpy(addr, dep->de_address.ea_addr, sizeof(*addr)); + + return OK; } #if 0 /*===========================================================================* * dp8390_dump * *===========================================================================*/ -void dp8390_dump() +void dp8390_dump(void) { dpeth_t *dep; int isr; @@ -274,16 +164,6 @@ void dp8390_dump() dep = &de_state; printf("\n"); -#if XXX - if (dep->de_mode == DEM_DISABLED) - printf("dp8390 instance %d is disabled\n", de_instance); - else if (dep->de_mode == DEM_SINK) - printf("dp8390 instance %d is in sink mode\n", de_instance); -#endif - - if (dep->de_mode != DEM_ENABLED) - return; - printf("dp8390 statistics of instance %d:\n", de_instance); printf("recvErr :%8ld\t", dep->de_stat.ets_recvErr); @@ -314,20 +194,14 @@ void dp8390_dump() } #endif -#if ENABLE_PCI /*===========================================================================* * pci_conf * *===========================================================================*/ -static void pci_conf() +static void pci_conf(void) { char envvar[16]; struct dpeth *dep; int i, pci_instance; - static int first_time= 1; - - if (!first_time) - return; - first_time= 0; dep= &de_state; @@ -347,69 +221,26 @@ static void pci_conf() } if (!rtl_probe(dep, pci_instance)) - dep->de_pci= -1; + panic("no matching PCI device found"); } -#endif /* ENABLE_PCI */ /*===========================================================================* - * do_vwrite_s * + * do_send * *===========================================================================*/ -static void do_vwrite_s(mp, from_int) -message *mp; -int from_int; +static int do_send(struct netdriver_data *data, size_t size) { - int count, size; int sendq_head; dpeth_t *dep; dep= &de_state; - count = mp->m_net_netdrv_dl_writev_s.count; - dep->de_client= mp->m_source; - - if (dep->de_mode == DEM_SINK) - { - assert(!from_int); - dep->de_flags |= DEF_PACK_SEND; - reply(dep); - return; - } - assert(dep->de_mode == DEM_ENABLED); - assert(dep->de_flags & DEF_ENABLED); - if (dep->de_flags & DEF_SEND_AVAIL) - panic("dp8390: send already in progress"); - sendq_head= dep->de_sendq_head; if (dep->de_sendq[sendq_head].sq_filled) - { - if (from_int) - panic("dp8390: should not be sending"); - dep->de_sendmsg= *mp; - dep->de_flags |= DEF_SEND_AVAIL; - reply(dep); - return; - } - assert(!(dep->de_flags & DEF_PACK_SEND)); + return SUSPEND; - get_userdata_s(mp->m_source, mp->m_net_netdrv_dl_writev_s.grant, 0, - (count > IOVEC_NR ? IOVEC_NR : count) * - sizeof(dep->de_write_iovec_s.iod_iovec[0]), - dep->de_write_iovec_s.iod_iovec); - dep->de_write_iovec_s.iod_iovec_s = count; - dep->de_write_iovec_s.iod_proc_nr = mp->m_source; - dep->de_write_iovec_s.iod_grant = mp->m_net_netdrv_dl_writev_s.grant; - dep->de_write_iovec_s.iod_iovec_offset = 0; + (dep->de_user2nicf_s)(dep, data, + dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE, 0, size); - dep->de_tmp_iovec_s = dep->de_write_iovec_s; - size = calc_iovec_size_s(&dep->de_tmp_iovec_s); - - if (size < ETH_MIN_PACK_SIZE || size > ETH_MAX_PACK_SIZE_TAGGED) - { - panic("dp8390: invalid packet size: %d", size); - } - (dep->de_user2nicf_s)(dep, &dep->de_write_iovec_s, 0, - dep->de_sendq[sendq_head].sq_sendpage * DP_PAGESIZE, - size); dep->de_sendq[sendq_head].sq_filled= TRUE; if (dep->de_sendq_tail == sendq_head) { @@ -426,215 +257,65 @@ int from_int; assert(sendq_head < SENDQ_NR); dep->de_sendq_head= sendq_head; - dep->de_flags |= DEF_PACK_SEND; - - /* If the interrupt handler called, don't send a reply. The reply - * will be sent after all interrupts are handled. - */ - if (from_int) - return; - reply(dep); - - assert(dep->de_mode == DEM_ENABLED); - assert(dep->de_flags & DEF_ENABLED); + return OK; } /*===========================================================================* - * do_vread_s * + * do_mode * *===========================================================================*/ -static void do_vread_s(mp) -message *mp; +static void do_mode(unsigned int mode) +{ + dpeth_t *dep; + int dp_rcr_reg; + + dep = &de_state; + + outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA); + + dp_rcr_reg = 0; + if (mode & NDEV_PROMISC) + dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM; + if (mode & NDEV_BROAD) + dp_rcr_reg |= RCR_AB; + if (mode & NDEV_MULTI) + dp_rcr_reg |= RCR_AM; + outb_reg0(dep, DP_RCR, dp_rcr_reg); +} + +/*===========================================================================* + * do_stat * + *===========================================================================*/ +static void do_stat(eth_stat_t *stat) { - int count; - int size; dpeth_t *dep; dep= &de_state; - count = mp->m_net_netdrv_dl_readv_s.count; - dep->de_client= mp->m_source; - if (dep->de_mode == DEM_SINK) - { - reply(dep); - return; - } - assert(dep->de_mode == DEM_ENABLED); - assert(dep->de_flags & DEF_ENABLED); - - if(dep->de_flags & DEF_READING) - panic("dp8390: read already in progress"); - - get_userdata_s(mp->m_source, mp->m_net_netdrv_dl_readv_s.grant, 0, - (count > IOVEC_NR ? IOVEC_NR : count) * - sizeof(dep->de_read_iovec_s.iod_iovec[0]), - dep->de_read_iovec_s.iod_iovec); - dep->de_read_iovec_s.iod_iovec_s = count; - dep->de_read_iovec_s.iod_proc_nr = mp->m_source; - dep->de_read_iovec_s.iod_grant = mp->m_net_netdrv_dl_readv_s.grant; - dep->de_read_iovec_s.iod_iovec_offset = 0; - - dep->de_tmp_iovec_s = dep->de_read_iovec_s; - size= calc_iovec_size_s(&dep->de_tmp_iovec_s); - - if (size < ETH_MAX_PACK_SIZE_TAGGED) - panic("dp8390: wrong packet size: %d", size); - dep->de_flags |= DEF_READING; - - dp_recv(dep); - - if ((dep->de_flags & (DEF_READING|DEF_STOPPED)) == - (DEF_READING|DEF_STOPPED)) - { - /* The chip is stopped, and all arrived packets are - * delivered. - */ - dp_reset(dep); - } - reply(dep); -} - -/*===========================================================================* - * do_init * - *===========================================================================*/ -static void do_init(message *mp) -{ - dpeth_t *dep; - message reply_mess; - -#if ENABLE_PCI - pci_conf(); /* Configure PCI devices. */ -#endif - - dep= &de_state; - - if (dep->de_mode == DEM_DISABLED) - { - /* This is the default, try to (re)locate the device. */ - conf_hw(dep); - if (dep->de_mode == DEM_DISABLED) - { - /* Probe failed, or the device is configured off. */ - reply_mess.m_type = DL_CONF_REPLY; - reply_mess.m_netdrv_net_dl_conf.stat = ENXIO; - mess_reply(mp, &reply_mess); - return; - } - if (dep->de_mode == DEM_ENABLED) - dp_init(dep); - } - - if (dep->de_mode == DEM_SINK) - { - strncpy((char *) dep->de_address.ea_addr, "ZDP", 6); - dep->de_address.ea_addr[5] = de_instance; - dp_confaddr(dep); - reply_mess.m_type = DL_CONF_REPLY; - reply_mess.m_netdrv_net_dl_conf.stat = OK; - memcpy(reply_mess.m_netdrv_net_dl_conf.hw_addr, - dep->de_address.ea_addr, - sizeof(reply_mess.m_netdrv_net_dl_conf.hw_addr)); - mess_reply(mp, &reply_mess); - return; - } - assert(dep->de_mode == DEM_ENABLED); - assert(dep->de_flags & DEF_ENABLED); - - dep->de_flags &= ~(DEF_PROMISC | DEF_MULTI | DEF_BROAD); - - if (mp->m_net_netdrv_dl_conf.mode & DL_PROMISC_REQ) - dep->de_flags |= DEF_PROMISC | DEF_MULTI | DEF_BROAD; - if (mp->m_net_netdrv_dl_conf.mode & DL_MULTI_REQ) - dep->de_flags |= DEF_MULTI; - if (mp->m_net_netdrv_dl_conf.mode & DL_BROAD_REQ) - dep->de_flags |= DEF_BROAD; - - dp_reinit(dep); - - reply_mess.m_type = DL_CONF_REPLY; - reply_mess.m_netdrv_net_dl_conf.stat = OK; - - memcpy(reply_mess.m_netdrv_net_dl_conf.hw_addr, dep->de_address.ea_addr, - sizeof(reply_mess.m_netdrv_net_dl_conf.hw_addr)); - - mess_reply(mp, &reply_mess); -} - -/*===========================================================================* - * do_int * - *===========================================================================*/ -static void do_int(dep) -dpeth_t *dep; -{ - if (dep->de_flags & (DEF_PACK_SEND | DEF_PACK_RECV)) - reply(dep); -} - -/*===========================================================================* - * do_getstat_s * - *===========================================================================*/ -static void do_getstat_s(mp) -message *mp; -{ - int r; - dpeth_t *dep; - - dep= &de_state; - - if (dep->de_mode == DEM_SINK) - { - put_userdata_s(mp->m_source, - mp->m_net_netdrv_dl_getstat_s.grant, - (vir_bytes) sizeof(dep->de_stat), &dep->de_stat); - - mp->m_type= DL_STAT_REPLY; - r= ipc_send(mp->m_source, mp); - if (r != OK) - panic("do_getstat: ipc_send failed: %d", r); - return; - } - assert(dep->de_mode == DEM_ENABLED); - assert(dep->de_flags & DEF_ENABLED); - dep->de_stat.ets_CRCerr += inb_reg0(dep, DP_CNTR0); dep->de_stat.ets_frameAll += inb_reg0(dep, DP_CNTR1); dep->de_stat.ets_missedP += inb_reg0(dep, DP_CNTR2); - put_userdata_s(mp->m_source, mp->m_net_netdrv_dl_getstat_s.grant, - sizeof(dep->de_stat), &dep->de_stat); - - mp->m_type= DL_STAT_REPLY; - r= ipc_send(mp->m_source, mp); - if (r != OK) - panic("do_getstat: ipc_send failed: %d", r); + memcpy(stat, &dep->de_stat, sizeof(*stat)); } /*===========================================================================* - * dp_stop * + * do_stop * *===========================================================================*/ -static void dp_stop(dep) -dpeth_t *dep; +static void do_stop(void) { + dpeth_t *dep; - if (dep->de_mode == DEM_SINK) - return; - assert(dep->de_mode == DEM_ENABLED); - - if (!(dep->de_flags & DEF_ENABLED)) - return; + dep = &de_state; outb_reg0(dep, DP_CR, CR_STP | CR_DM_ABORT); (dep->de_stopf)(dep); - - dep->de_flags= DEF_EMPTY; } /*===========================================================================* * dp_init * *===========================================================================*/ -static void dp_init(dep) -dpeth_t *dep; +static void dp_init(dpeth_t *dep) { - int dp_rcr_reg; int i, r; /* General initialization */ @@ -669,14 +350,7 @@ dpeth_t *dep; outb_reg0(dep, DP_RBCR0, 0); outb_reg0(dep, DP_RBCR1, 0); /* Step 4: */ - dp_rcr_reg = 0; - if (dep->de_flags & DEF_PROMISC) - dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM; - if (dep->de_flags & DEF_BROAD) - dp_rcr_reg |= RCR_AB; - if (dep->de_flags & DEF_MULTI) - dp_rcr_reg |= RCR_AM; - outb_reg0(dep, DP_RCR, dp_rcr_reg); + outb_reg0(dep, DP_RCR, 0); /* Step 5: */ outb_reg0(dep, DP_TCR, TCR_INTERNAL); /* Step 6: */ @@ -718,7 +392,6 @@ dpeth_t *dep; inb_reg0(dep, DP_CNTR2); /* Finish the initialization. */ - dep->de_flags |= DEF_ENABLED; for (i= 0; ide_sendq_nr; i++) dep->de_sendq[i].sq_filled= 0; dep->de_sendq_head= 0; @@ -752,16 +425,13 @@ dpeth_t *dep; r= sys_irqenable(&dep->de_hook); if (r != OK) - { - panic("unable enable interrupts: %d", r); - } + panic("unable to enable interrupts: %d", r); } /*===========================================================================* * dp_confaddr * *===========================================================================*/ -static void dp_confaddr(dep) -dpeth_t *dep; +static void dp_confaddr(dpeth_t *dep) { int i; char eakey[16]; @@ -785,31 +455,10 @@ dpeth_t *dep; if (i != 0 && i != 6) env_panic(eakey); /* It's all or nothing */ } -/*===========================================================================* - * dp_reinit * - *===========================================================================*/ -static void dp_reinit(dep) -dpeth_t *dep; -{ - int dp_rcr_reg; - - outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA); - - dp_rcr_reg = 0; - if (dep->de_flags & DEF_PROMISC) - dp_rcr_reg |= RCR_AB | RCR_PRO | RCR_AM; - if (dep->de_flags & DEF_BROAD) - dp_rcr_reg |= RCR_AB; - if (dep->de_flags & DEF_MULTI) - dp_rcr_reg |= RCR_AM; - outb_reg0(dep, DP_RCR, dp_rcr_reg); -} - /*===========================================================================* * dp_reset * *===========================================================================*/ -static void dp_reset(dep) -dpeth_t *dep; +static void dp_reset(dpeth_t *dep) { int i; @@ -835,21 +484,20 @@ dpeth_t *dep; dep->de_sendq_head= dep->de_sendq_tail= 0; for (i= 0; ide_sendq_nr; i++) dep->de_sendq[i].sq_filled= 0; - dp_send(dep); + netdriver_send(); dep->de_flags &= ~DEF_STOPPED; } /*===========================================================================* - * dp_check_ints * + * do_intr * *===========================================================================*/ -static void dp_check_ints(dep) -dpeth_t *dep; +static void do_intr(unsigned int __unused mask) { + dpeth_t *dep; int isr, tsr; - int size, sendq_tail; + int r, size, sendq_tail; - if (!(dep->de_flags & DEF_ENABLED)) - panic("dp8390: got premature interrupt"); + dep = &de_state; for(;;) { @@ -924,17 +572,12 @@ dpeth_t *dep; outb_reg0(dep, DP_TBCR0, size & 0xff); outb_reg0(dep, DP_CR, CR_TXP | CR_EXTRA); } - if (dep->de_flags & DEF_SEND_AVAIL) - dp_send(dep); + netdriver_send(); } if (isr & ISR_PRX) - { - /* Only call dp_recv if there is a read request */ - if (dep->de_flags & DEF_READING) - dp_recv(dep); - } - + netdriver_recv(); + if (isr & ISR_RXE) dep->de_stat.ets_recvErr++; if (isr & ISR_CNT) { @@ -949,12 +592,6 @@ dpeth_t *dep; { printW(); printf( "%s: got overwrite warning\n", dep->de_name); } #endif - if (dep->de_flags & DEF_READING) - { - printf( -"dp_check_ints: strange: overwrite warning and pending read request\n"); - dp_recv(dep); - } } if (isr & ISR_RDC) { @@ -972,31 +609,29 @@ dpeth_t *dep; "%s: NIC stopped\n", dep->de_name); } #endif dep->de_flags |= DEF_STOPPED; + netdriver_recv(); /* see if we can reset right now */ break; } } - if ((dep->de_flags & (DEF_READING|DEF_STOPPED)) == - (DEF_READING|DEF_STOPPED)) - { - /* The chip is stopped, and all arrived packets are - * delivered. - */ - dp_reset(dep); - } + + if ((r = sys_irqenable(&dep->de_hook)) != OK) + panic("unable enable interrupts: %d", r); } /*===========================================================================* - * dp_recv * + * do_recv * *===========================================================================*/ -static void dp_recv(dep) -dpeth_t *dep; +static ssize_t do_recv(struct netdriver_data *data, size_t max) { + dpeth_t *dep; dp_rcvhdr_t header; unsigned pageno, curr, next; - vir_bytes length; - int packet_processed, r; + size_t length; + int packet_processed; u16_t eth_type; + dep = &de_state; + packet_processed = FALSE; pageno = inb_reg0(dep, DP_BNRY) + 1; if (pageno == dep->de_stoppage) pageno = dep->de_startpage; @@ -1007,7 +642,16 @@ dpeth_t *dep; curr = inb_reg1(dep, DP_CURR); outb_reg0(dep, DP_CR, CR_PS_P0 | CR_EXTRA); - if (curr == pageno) break; + if (curr == pageno) { + if (dep->de_flags & DEF_STOPPED) { + /* The chip is stopped, and all arrived packets + * are delivered. + */ + dp_reset(dep); + } + + return SUSPEND; + } (dep->de_getblockf)(dep, pageno, (size_t)0, sizeof(header), &header); @@ -1017,8 +661,7 @@ dpeth_t *dep; length = (header.dr_rbcl | (header.dr_rbch << 8)) - sizeof(dp_rcvhdr_t); next = header.dr_next; - if (length < ETH_MIN_PACK_SIZE || - length > ETH_MAX_PACK_SIZE_TAGGED) + if (length < ETH_MIN_PACK_SIZE || length > max) { printf("%s: packet with strange length arrived: %d\n", dep->de_name, (int) length); @@ -1038,12 +681,9 @@ dpeth_t *dep; dep->de_stat.ets_fifoOver++; next = curr; } - else if ((header.dr_status & RSR_PRX) && - (dep->de_flags & DEF_ENABLED)) + else if (header.dr_status & RSR_PRX) { - r = dp_pkt2user_s(dep, pageno, length); - if (r != OK) - return; + dp_pkt2user_s(dep, data, pageno, length); packet_processed = TRUE; dep->de_stat.ets_packetR++; @@ -1054,32 +694,16 @@ dpeth_t *dep; outb_reg0(dep, DP_BNRY, next - 1); pageno = next; - } - while (!packet_processed); -} + } while (!packet_processed); -/*===========================================================================* - * dp_send * - *===========================================================================*/ -static void dp_send(dep) -dpeth_t *dep; -{ - if (!(dep->de_flags & DEF_SEND_AVAIL)) - return; - - dep->de_flags &= ~DEF_SEND_AVAIL; - do_vwrite_s(&dep->de_sendmsg, TRUE); + return length; } /*===========================================================================* * dp_getblock * *===========================================================================*/ -static void dp_getblock(dep, page, offset, size, dst) -dpeth_t *dep; -int page; -size_t offset; -size_t size; -void *dst; +static void dp_getblock(dpeth_t *dep, int page, size_t offset, size_t size, + void *dst) { offset = page * DP_PAGESIZE + offset; @@ -1089,12 +713,8 @@ void *dst; /*===========================================================================* * dp_pio8_getblock * *===========================================================================*/ -static void dp_pio8_getblock(dep, page, offset, size, dst) -dpeth_t *dep; -int page; -size_t offset; -size_t size; -void *dst; +static void dp_pio8_getblock(dpeth_t *dep, int page, size_t offset, + size_t size, void *dst) { offset = page * DP_PAGESIZE + offset; outb_reg0(dep, DP_RBCR0, size & 0xFF); @@ -1109,12 +729,8 @@ void *dst; /*===========================================================================* * dp_pio16_getblock * *===========================================================================*/ -static void dp_pio16_getblock(dep, page, offset, size, dst) -dpeth_t *dep; -int page; -size_t offset; -size_t size; -void *dst; +static void dp_pio16_getblock(dpeth_t *dep, int page, size_t offset, + size_t size, void *dst) { offset = page * DP_PAGESIZE + offset; outb_reg0(dep, DP_RBCR0, size & 0xFF); @@ -1130,99 +746,45 @@ void *dst; /*===========================================================================* * dp_pkt2user_s * *===========================================================================*/ -static int dp_pkt2user_s(dpeth_t *dep, int page, vir_bytes length) +static void dp_pkt2user_s(dpeth_t *dep, struct netdriver_data *data, int page, + size_t length) { int last, count; - if (!(dep->de_flags & DEF_READING)) - return EGENERIC; - last = page + (length - 1) / DP_PAGESIZE; if (last >= dep->de_stoppage) { count = (dep->de_stoppage - page) * DP_PAGESIZE - sizeof(dp_rcvhdr_t); - /* Save read_iovec since we need it twice. */ - dep->de_tmp_iovec_s = dep->de_read_iovec_s; - (dep->de_nic2userf_s)(dep, page * DP_PAGESIZE + - sizeof(dp_rcvhdr_t), &dep->de_tmp_iovec_s, 0, count); - (dep->de_nic2userf_s)(dep, dep->de_startpage * DP_PAGESIZE, - &dep->de_read_iovec_s, count, length - count); + (dep->de_nic2userf_s)(dep, data, + page * DP_PAGESIZE + sizeof(dp_rcvhdr_t), 0, count); + (dep->de_nic2userf_s)(dep, data, + dep->de_startpage * DP_PAGESIZE, count, length - count); } else { - (dep->de_nic2userf_s)(dep, page * DP_PAGESIZE + - sizeof(dp_rcvhdr_t), &dep->de_read_iovec_s, 0, length); + (dep->de_nic2userf_s)(dep, data, + page * DP_PAGESIZE + sizeof(dp_rcvhdr_t), 0, length); } - - dep->de_read_s = length; - dep->de_flags |= DEF_PACK_RECV; - dep->de_flags &= ~DEF_READING; - - return OK; } /*===========================================================================* * dp_user2nic_s * *===========================================================================*/ -static void dp_user2nic_s(dep, iovp, offset, nic_addr, count) -dpeth_t *dep; -iovec_dat_s_t *iovp; -vir_bytes offset; -int nic_addr; -vir_bytes count; +static void dp_user2nic_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count) { - vir_bytes vir_hw; - int bytes, i, r; - - vir_hw = (vir_bytes)dep->de_locmem + nic_addr; - - i= 0; - while (count > 0) - { - if (i >= IOVEC_NR) - { - dp_next_iovec_s(iovp); - i= 0; - continue; - } - assert(i < iovp->iod_iovec_s); - if (offset >= iovp->iod_iovec[i].iov_size) - { - offset -= iovp->iod_iovec[i].iov_size; - i++; - continue; - } - bytes = iovp->iod_iovec[i].iov_size - offset; - if (bytes > count) - bytes = count; - - r= sys_safecopyfrom(iovp->iod_proc_nr, - iovp->iod_iovec[i].iov_grant, offset, - vir_hw, bytes); - if (r != OK) { - panic("dp_user2nic_s: sys_safecopyfrom failed: %d", r); - } - - count -= bytes; - vir_hw += bytes; - offset += bytes; - } - assert(count == 0); + netdriver_copyin(data, offset, dep->de_locmem + nic_addr, count); } /*===========================================================================* * dp_pio8_user2nic_s * *===========================================================================*/ -static void dp_pio8_user2nic_s(dep, iovp, offset, nic_addr, count) -dpeth_t *dep; -iovec_dat_s_t *iovp; -vir_bytes offset; -int nic_addr; -vir_bytes count; +static void dp_pio8_user2nic_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count) { - int bytes, i, r; + int i; outb_reg0(dep, DP_ISR, ISR_RDC); @@ -1232,36 +794,7 @@ vir_bytes count; outb_reg0(dep, DP_RSAR1, nic_addr >> 8); outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA); - i= 0; - while (count > 0) - { - if (i >= IOVEC_NR) - { - dp_next_iovec_s(iovp); - i= 0; - continue; - } - assert(i < iovp->iod_iovec_s); - if (offset >= iovp->iod_iovec[i].iov_size) - { - offset -= iovp->iod_iovec[i].iov_size; - i++; - continue; - } - bytes = iovp->iod_iovec[i].iov_size - offset; - if (bytes > count) - bytes = count; - - r= sys_safe_outsb(dep->de_data_port, iovp->iod_proc_nr, - iovp->iod_iovec[i].iov_grant, offset, bytes); - if (r != OK) { - panic("dp_pio8_user2nic_s: sys_safe_outsb failed: %d", - r); - } - count -= bytes; - offset += bytes; - } - assert(count == 0); + netdriver_portoutb(data, offset, dep->de_data_port, count); for (i= 0; i<100; i++) { @@ -1277,21 +810,13 @@ vir_bytes count; /*===========================================================================* * dp_pio16_user2nic_s * *===========================================================================*/ -static void dp_pio16_user2nic_s(dep, iovp, offset, nic_addr, count) -dpeth_t *dep; -iovec_dat_s_t *iovp; -vir_bytes offset; -int nic_addr; -vir_bytes count; +static void dp_pio16_user2nic_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count) { - vir_bytes ecount; - cp_grant_id_t gid; - int i, r, bytes, user_proc; - u8_t two_bytes[2]; - int odd_byte; + size_t ecount; + int i; ecount= (count+1) & ~1; - odd_byte= 0; outb_reg0(dep, DP_ISR, ISR_RDC); outb_reg0(dep, DP_RBCR0, ecount & 0xFF); @@ -1300,73 +825,7 @@ vir_bytes count; outb_reg0(dep, DP_RSAR1, nic_addr >> 8); outb_reg0(dep, DP_CR, CR_DM_RW | CR_PS_P0 | CR_STA); - i= 0; - while (count > 0) - { - if (i >= IOVEC_NR) - { - dp_next_iovec_s(iovp); - i= 0; - continue; - } - assert(i < iovp->iod_iovec_s); - if (offset >= iovp->iod_iovec[i].iov_size) - { - offset -= iovp->iod_iovec[i].iov_size; - i++; - continue; - } - bytes = iovp->iod_iovec[i].iov_size - offset; - if (bytes > count) - bytes = count; - - user_proc= iovp->iod_proc_nr; - gid= iovp->iod_iovec[i].iov_grant; - if (odd_byte) - { - r= sys_safecopyfrom(user_proc, gid, offset, - (vir_bytes)&two_bytes[1], 1); - if (r != OK) { - panic("dp_pio16_user2nic: sys_safecopyfrom failed: %d", r); - } - outw(dep->de_data_port, *(u16_t *)two_bytes); - count--; - offset++; - bytes--; - odd_byte= 0; - if (!bytes) - continue; - } - ecount= bytes & ~1; - if (ecount != 0) - { - r= sys_safe_outsw(dep->de_data_port, user_proc, - gid, offset, ecount); - if (r != OK) { - panic("dp_pio16_user2nic: sys_safe_outsw failed: %d", r); - } - count -= ecount; - offset += ecount; - bytes -= ecount; - } - if (bytes) - { - assert(bytes == 1); - r= sys_safecopyfrom(user_proc, gid, offset, - (vir_bytes)&two_bytes[0], 1); - if (r != OK) { - panic("dp_pio16_user2nic: sys_safecopyfrom failed: %d", r); - } - count--; - offset++; - bytes--; - odd_byte= 1; - } - } - assert(count == 0); - - if (odd_byte) - outw(dep->de_data_port, *(u16_t *)two_bytes); + netdriver_portoutw(data, offset, dep->de_data_port, count); for (i= 0; i<100; i++) { @@ -1382,118 +841,36 @@ vir_bytes count; /*===========================================================================* * dp_nic2user_s * *===========================================================================*/ -static void dp_nic2user_s(dep, nic_addr, iovp, offset, count) -dpeth_t *dep; -int nic_addr; -iovec_dat_s_t *iovp; -vir_bytes offset; -vir_bytes count; +static void dp_nic2user_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count) { - vir_bytes vir_hw; - int bytes, i, r; - - vir_hw = (vir_bytes)dep->de_locmem + nic_addr; - - i= 0; - while (count > 0) - { - if (i >= IOVEC_NR) - { - dp_next_iovec_s(iovp); - i= 0; - continue; - } - assert(i < iovp->iod_iovec_s); - if (offset >= iovp->iod_iovec[i].iov_size) - { - offset -= iovp->iod_iovec[i].iov_size; - i++; - continue; - } - bytes = iovp->iod_iovec[i].iov_size - offset; - if (bytes > count) - bytes = count; - - r= sys_safecopyto(iovp->iod_proc_nr, - iovp->iod_iovec[i].iov_grant, offset, - vir_hw, bytes); - if (r != OK) - panic("dp_nic2user_s: sys_safecopyto failed: %d", r); - - count -= bytes; - vir_hw += bytes; - offset += bytes; - } - assert(count == 0); + netdriver_copyout(data, offset, dep->de_locmem + nic_addr, count); } /*===========================================================================* * dp_pio8_nic2user_s * *===========================================================================*/ -static void dp_pio8_nic2user_s(dep, nic_addr, iovp, offset, count) -dpeth_t *dep; -int nic_addr; -iovec_dat_s_t *iovp; -vir_bytes offset; -vir_bytes count; +static void dp_pio8_nic2user_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count) { - int bytes, i, r; - outb_reg0(dep, DP_RBCR0, count & 0xFF); outb_reg0(dep, DP_RBCR1, count >> 8); outb_reg0(dep, DP_RSAR0, nic_addr & 0xFF); outb_reg0(dep, DP_RSAR1, nic_addr >> 8); outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); - i= 0; - while (count > 0) - { - if (i >= IOVEC_NR) - { - dp_next_iovec_s(iovp); - i= 0; - continue; - } - assert(i < iovp->iod_iovec_s); - if (offset >= iovp->iod_iovec[i].iov_size) - { - offset -= iovp->iod_iovec[i].iov_size; - i++; - continue; - } - bytes = iovp->iod_iovec[i].iov_size - offset; - if (bytes > count) - bytes = count; - - r= sys_safe_insb(dep->de_data_port, iovp->iod_proc_nr, - iovp->iod_iovec[i].iov_grant, offset, bytes); - if (r != OK) { - panic("dp_pio8_nic2user_s: sys_safe_insb failed: %d", r); - } - count -= bytes; - offset += bytes; - } - assert(count == 0); + netdriver_portinb(data, offset, dep->de_data_port, count); } /*===========================================================================* * dp_pio16_nic2user_s * *===========================================================================*/ -static void dp_pio16_nic2user_s(dep, nic_addr, iovp, offset, count) -dpeth_t *dep; -int nic_addr; -iovec_dat_s_t *iovp; -vir_bytes offset; -vir_bytes count; +static void dp_pio16_nic2user_s(dpeth_t *dep, struct netdriver_data *data, + int nic_addr, size_t offset, size_t count) { - vir_bytes ecount; - cp_grant_id_t gid; - int i, r, bytes, user_proc; - u8_t two_bytes[2]; - int odd_byte; + size_t ecount; ecount= (count+1) & ~1; - odd_byte= 0; outb_reg0(dep, DP_RBCR0, ecount & 0xFF); outb_reg0(dep, DP_RBCR1, ecount >> 8); @@ -1501,166 +878,49 @@ vir_bytes count; outb_reg0(dep, DP_RSAR1, nic_addr >> 8); outb_reg0(dep, DP_CR, CR_DM_RR | CR_PS_P0 | CR_STA); - i= 0; - while (count > 0) - { - if (i >= IOVEC_NR) - { - dp_next_iovec_s(iovp); - i= 0; - continue; - } - assert(i < iovp->iod_iovec_s); - if (offset >= iovp->iod_iovec[i].iov_size) - { - offset -= iovp->iod_iovec[i].iov_size; - i++; - continue; - } - bytes = iovp->iod_iovec[i].iov_size - offset; - if (bytes > count) - bytes = count; - - user_proc= iovp->iod_proc_nr; - gid= iovp->iod_iovec[i].iov_grant; - if (odd_byte) - { - r= sys_safecopyto(user_proc, gid, offset, - (vir_bytes)&two_bytes[1], 1); - if (r != OK) { - panic("dp_pio16_nic2user: sys_safecopyto failed: %d", r); - } - count--; - offset++; - bytes--; - odd_byte= 0; - if (!bytes) - continue; - } - ecount= bytes & ~1; - if (ecount != 0) - { - r= sys_safe_insw(dep->de_data_port, user_proc, gid, - offset, ecount); - if (r != OK) { - panic("dp_pio16_nic2user: sys_safe_insw failed: %d", - r); - } - count -= ecount; - offset += ecount; - bytes -= ecount; - } - if (bytes) - { - assert(bytes == 1); - *(u16_t *)two_bytes= inw(dep->de_data_port); - r= sys_safecopyto(user_proc, gid, offset, - (vir_bytes)&two_bytes[0], 1); - if (r != OK) - { - panic("dp_pio16_nic2user: sys_safecopyto failed: %d", - r); - } - count--; - offset++; - bytes--; - odd_byte= 1; - } - } - assert(count == 0); -} - -/*===========================================================================* - * dp_next_iovec_s * - *===========================================================================*/ -static void dp_next_iovec_s(iovp) -iovec_dat_s_t *iovp; -{ - assert(iovp->iod_iovec_s > IOVEC_NR); - - iovp->iod_iovec_s -= IOVEC_NR; - - iovp->iod_iovec_offset += IOVEC_NR * sizeof(iovec_t); - - get_userdata_s(iovp->iod_proc_nr, iovp->iod_grant, - iovp->iod_iovec_offset, - (iovp->iod_iovec_s > IOVEC_NR ? IOVEC_NR : iovp->iod_iovec_s) * - sizeof(iovp->iod_iovec[0]), iovp->iod_iovec); + netdriver_portinw(data, offset, dep->de_data_port, count); } /*===========================================================================* * conf_hw * *===========================================================================*/ -static void conf_hw(dep) -dpeth_t *dep; +static void conf_hw(dpeth_t *dep) { - static eth_stat_t empty_stat = {0, 0, 0, 0, 0, 0 /* ,... */ }; - int confnr; dp_conf_t *dcp; - dep->de_mode= DEM_DISABLED; /* Superfluous */ - /* Pick a default configuration for this instance. */ confnr= MIN(de_instance, DP_CONF_NR-1); dcp= &dp_conf[confnr]; update_conf(dep, dcp); - if (dep->de_mode != DEM_ENABLED) - return; if (!wdeth_probe(dep) && !ne_probe(dep) && !el2_probe(dep)) - { - printf("%s: No ethernet card found at 0x%x\n", - dep->de_name, dep->de_base_port); - dep->de_mode= DEM_DISABLED; - return; - } + panic("no ethernet card found at 0x%x\n", dep->de_base_port); /* XXX */ if (dep->de_linmem == 0) dep->de_linmem= 0xFFFF0000; - - dep->de_flags = DEF_EMPTY; - dep->de_stat = empty_stat; } /*===========================================================================* * update_conf * *===========================================================================*/ -static void update_conf(dep, dcp) -dpeth_t *dep; -dp_conf_t *dcp; +static void update_conf(dpeth_t *dep, dp_conf_t *dcp) { long v; static char dpc_fmt[] = "x:d:x:x"; char eckey[16]; -#if ENABLE_PCI if (dep->de_pci) { - if (dep->de_pci == 1) - { - /* PCI device is present */ - dep->de_mode= DEM_ENABLED; - } + /* PCI device is present */ return; /* Already configured */ } -#endif strlcpy(eckey, "DPETH0", sizeof(eckey)); eckey[5] += de_instance; /* Get the default settings and modify them from the environment. */ - dep->de_mode= DEM_SINK; v= dcp->dpc_port; - switch (env_parse(eckey, dpc_fmt, 0, &v, 0x0000L, 0xFFFFL)) { - case EP_OFF: - dep->de_mode= DEM_DISABLED; - break; - case EP_ON: - case EP_SET: - dep->de_mode= DEM_ENABLED; /* Might become disabled if - * all probes fail */ - break; - } + (void) env_parse(eckey, dpc_fmt, 0, &v, 0x0000L, 0xFFFFL); dep->de_base_port= v; v= dcp->dpc_irq | DEI_DEFAULT; @@ -1679,8 +939,7 @@ dp_conf_t *dcp; /*===========================================================================* * map_hw_buffer * *===========================================================================*/ -static void map_hw_buffer(dep) -dpeth_t *dep; +static void map_hw_buffer(dpeth_t *dep) { if (dep->de_prog_IO) @@ -1699,108 +958,6 @@ dpeth_t *dep; panic("map_hw_buffer: vm_map_phys failed"); } -/*===========================================================================* - * calc_iovec_size_s * - *===========================================================================*/ -static int calc_iovec_size_s(iovp) -iovec_dat_s_t *iovp; -{ - /* Calculate the size of a request. Note that the iovec_dat - * structure will be unusable after calc_iovec_size_s. - */ - int size; - int i; - - size= 0; - i= 0; - while (i < iovp->iod_iovec_s) - { - if (i >= IOVEC_NR) - { - dp_next_iovec_s(iovp); - i= 0; - continue; - } - size += iovp->iod_iovec[i].iov_size; - i++; - } - return size; -} - -/*===========================================================================* - * reply * - *===========================================================================*/ -static void reply(dep) -dpeth_t *dep; -{ - message reply; - int flags; - int r; - - flags = DL_NOFLAGS; - if (dep->de_flags & DEF_PACK_SEND) - flags |= DL_PACK_SEND; - if (dep->de_flags & DEF_PACK_RECV) - flags |= DL_PACK_RECV; - - reply.m_type = DL_TASK_REPLY; - reply.m_netdrv_net_dl_task.flags = flags; - reply.m_netdrv_net_dl_task.count = dep->de_read_s; - r= ipc_send(dep->de_client, &reply); - - if (r < 0) - panic("dp8390: ipc_send failed: %d", r); - - dep->de_read_s = 0; - dep->de_flags &= ~(DEF_PACK_SEND | DEF_PACK_RECV); -} - -/*===========================================================================* - * mess_reply * - *===========================================================================*/ -static void mess_reply(req, reply_mess) -message *req; -message *reply_mess; -{ - if (ipc_send(req->m_source, reply_mess) != OK) - panic("dp8390: unable to mess_reply"); -} - -/*===========================================================================* - * get_userdata_s * - *===========================================================================*/ -static void get_userdata_s(user_proc, grant, offset, count, loc_addr) -int user_proc; -cp_grant_id_t grant; -vir_bytes offset; -vir_bytes count; -void *loc_addr; -{ - int r; - - r= sys_safecopyfrom(user_proc, grant, offset, - (vir_bytes)loc_addr, count); - if (r != OK) - panic("get_userdata: sys_safecopyfrom failed: %d", r); -} - -/*===========================================================================* - * put_userdata_s * - *===========================================================================*/ -static void put_userdata_s(user_proc, grant, count, loc_addr) -int user_proc; -cp_grant_id_t grant; -size_t count; -void *loc_addr; -{ - int r; - - r= sys_safecopyto(user_proc, grant, 0, (vir_bytes)loc_addr, - count); - if (r != OK) - panic("put_userdata: sys_safecopyto failed: %d", r); -} - u8_t inb(port_t port) { int r; @@ -1845,29 +1002,19 @@ void outw(port_t port, u16_t value) } static void insb(port_t port, void *buf, size_t size) -{ - do_vir_insb(port, SELF, (vir_bytes)buf, size); -} - -static void insw(port_t port, void *buf, size_t size) -{ - do_vir_insw(port, SELF, (vir_bytes)buf, size); -} - -static void do_vir_insb(port_t port, int proc, vir_bytes buf, size_t size) { int r; - r= sys_insb(port, proc, (void *) buf, size); + r= sys_insb(port, SELF, buf, size); if (r != OK) panic("sys_sdevio failed: %d", r); } -static void do_vir_insw(port_t port, int proc, vir_bytes buf, size_t size) +static void insw(port_t port, void *buf, size_t size) { int r; - r= sys_insw(port, proc, (void *) buf, size); + r= sys_insw(port, SELF, buf, size); if (r != OK) panic("sys_sdevio failed: %d", r); } diff --git a/minix/drivers/net/dp8390/dp8390.h b/minix/drivers/net/dp8390/dp8390.h index 342bb632b..ab02f7baf 100644 --- a/minix/drivers/net/dp8390/dp8390.h +++ b/minix/drivers/net/dp8390/dp8390.h @@ -173,45 +173,19 @@ typedef struct dp_rcvhdr struct dpeth; struct iovec_dat; struct iovec_dat_s; -typedef void(*dp_initf_t) (struct dpeth *dep); -typedef void(*dp_stopf_t) (struct dpeth *dep); -typedef void(*dp_user2nicf_t) (struct dpeth *dep, struct iovec_dat - *iovp, vir_bytes offset, int nic_addr, vir_bytes count); -typedef void(*dp_user2nicf_s_t) (struct dpeth *dep, struct iovec_dat_s - *iovp, vir_bytes offset, int nic_addr, vir_bytes count); -typedef void(*dp_nic2userf_t) (struct dpeth *dep, int nic_addr, struct - iovec_dat *iovp, vir_bytes offset, vir_bytes count); -typedef void(*dp_nic2userf_s_t) (struct dpeth *dep, int nic_addr, struct - iovec_dat_s *iovp, vir_bytes offset, vir_bytes count); -#if 0 -typedef void(*dp_getheaderf_t) (struct dpeth *dep, int page, struct - dp_rcvhdr *h, u16_t *eth_type); -#endif -typedef void(*dp_getblock_t) (struct dpeth *dep, int page, size_t +typedef void (*dp_initf_t)(struct dpeth *dep); +typedef void (*dp_stopf_t)(struct dpeth *dep); +typedef void (*dp_user2nicf_s_t)(struct dpeth *dep, + struct netdriver_data *data, int nic_addr, size_t offset, + size_t count); +typedef void (*dp_nic2userf_s_t)(struct dpeth *dep, + struct netdriver_data *data, int nic_addr, size_t offset, + size_t count); +typedef void (*dp_getblock_t)(struct dpeth *dep, int page, size_t offset, size_t size, void *dst); -/* iovectors are handled IOVEC_NR entries at a time. */ -#define IOVEC_NR 16 - typedef int irq_hook_t; -typedef struct iovec_dat -{ - iovec_t iod_iovec[IOVEC_NR]; - int iod_iovec_s; - endpoint_t iod_proc_nr; - vir_bytes iod_iovec_addr; -} iovec_dat_t; - -typedef struct iovec_dat_s -{ - iovec_s_t iod_iovec[IOVEC_NR]; - int iod_iovec_s; - int iod_proc_nr; - cp_grant_id_t iod_grant; - vir_bytes iod_iovec_offset; -} iovec_dat_s_t; - #define SENDQ_NR 2 /* Maximum size of the send queue */ #define SENDQ_PAGES 6 /* 6 * DP_PAGESIZE >= 1514 bytes */ @@ -250,10 +224,8 @@ typedef struct dpeth int de_startpage; int de_stoppage; -#if ENABLE_PCI /* PCI config */ char de_pci; /* TRUE iff PCI device */ -#endif /* Do it yourself send queue */ struct sendq @@ -268,14 +240,7 @@ typedef struct dpeth /* Fields for internal use by the dp8390 driver. */ int de_flags; - int de_mode; eth_stat_t de_stat; - iovec_dat_s_t de_read_iovec_s; - iovec_dat_s_t de_write_iovec_s; - iovec_dat_s_t de_tmp_iovec_s; - vir_bytes de_read_s; - endpoint_t de_client; - message de_sendmsg; dp_user2nicf_s_t de_user2nicf_s; dp_nic2userf_s_t de_nic2userf_s; dp_getblock_t de_getblockf; @@ -283,24 +248,10 @@ typedef struct dpeth #define DEI_DEFAULT 0x8000 -#define DEF_EMPTY 0x000 -#define DEF_PACK_SEND 0x001 -#define DEF_PACK_RECV 0x002 -#define DEF_SEND_AVAIL 0x004 -#define DEF_READING 0x010 -#define DEF_PROMISC 0x040 -#define DEF_MULTI 0x080 -#define DEF_BROAD 0x100 -#define DEF_ENABLED 0x200 -#define DEF_STOPPED 0x400 +#define DEF_EMPTY 0x00 +#define DEF_STOPPED 0x01 -#define DEM_DISABLED 0x0 -#define DEM_SINK 0x1 -#define DEM_ENABLED 0x2 - -#if !__minix_vmd -#define debug 0 /* Standard Minix lacks debug variable */ -#endif +#define debug 0 /* * $PchId: dp8390.h,v 1.10 2005/02/10 17:26:06 philip Exp $ diff --git a/minix/drivers/net/dp8390/local.h b/minix/drivers/net/dp8390/local.h index 3ee5ba3f1..be8a25015 100644 --- a/minix/drivers/net/dp8390/local.h +++ b/minix/drivers/net/dp8390/local.h @@ -5,7 +5,6 @@ local.h #define ENABLE_WDETH 1 #define ENABLE_NE2000 1 #define ENABLE_3C503 1 -#define ENABLE_PCI 1 struct dpeth; diff --git a/minix/drivers/net/dp8390/ne2000.c b/minix/drivers/net/dp8390/ne2000.c index f6d47d4c8..de0ee889d 100644 --- a/minix/drivers/net/dp8390/ne2000.c +++ b/minix/drivers/net/dp8390/ne2000.c @@ -8,12 +8,10 @@ Created: March 15, 1994 by Philip Homburg */ #include +#include #include #include -#if __minix_vmd -#include "config.h" -#endif #include "local.h" #include "dp8390.h" diff --git a/minix/drivers/net/dp8390/rtl8029.c b/minix/drivers/net/dp8390/rtl8029.c index f69453da9..c66f43bae 100644 --- a/minix/drivers/net/dp8390/rtl8029.c +++ b/minix/drivers/net/dp8390/rtl8029.c @@ -7,6 +7,7 @@ Created: April 2000 by Philip Homburg */ #include +#include #include #include @@ -20,8 +21,6 @@ Created: April 2000 by Philip Homburg #include "dp8390.h" #include "rtl8029.h" -#if ENABLE_PCI - static void rtl_init(struct dpeth *dep); #if 0 static u16_t get_ee_word(dpeth_t *dep, int a); @@ -312,8 +311,6 @@ dpeth_t *dep; } #endif -#endif /* ENABLE_PCI */ - /* * $PchId: rtl8029.c,v 1.7 2004/08/03 12:16:58 philip Exp $ */ diff --git a/minix/drivers/net/dp8390/wdeth.c b/minix/drivers/net/dp8390/wdeth.c index 2d21f5af4..e9feb7991 100644 --- a/minix/drivers/net/dp8390/wdeth.c +++ b/minix/drivers/net/dp8390/wdeth.c @@ -5,6 +5,7 @@ Created: March 14, 1994 by Philip Homburg */ #include +#include #include #include @@ -70,9 +71,6 @@ dpeth_t *dep; int we_type; int sendq_nr; - assert(dep->de_mode == DEM_ENABLED); - assert(!(dep->de_flags & DEF_ENABLED)); - dep->de_address.ea_addr[0] = inb_we(dep, EPL_EA0); dep->de_address.ea_addr[1] = inb_we(dep, EPL_EA1); dep->de_address.ea_addr[2] = inb_we(dep, EPL_EA2);