8000 minix/minix/net/inet/mnx_eth.c at R3.3.0 · CookieChen/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
848 lines (735 loc) · 19.5 KB

mnx_eth.c

File metadata and controls

848 lines (735 loc) · 19.5 KB
iovec= eth_port->etp_osdep.etp_rd_iovec;
for (i=0, pack_ptr= pack; i<RD_IOVEC && pack_ptr;
i++, pack_ptr= pack_ptr->acc_next)
{
r= cpf_setgrant_disable(iovec[i].iov_grant);
if (r != 0)
{
ip_panic((
"mnx_eth`read_int: cpf_setgrant_disable failed: %d\n",
errno));
}
}
if (count < ETH_MIN_PACK_SIZE)
{
printf("mnx_eth`read_int: packet size too small (%d)\n",
count);
bf_afree(pack);
}
else if (count > ETH_MAX_PACK_SIZE_TAGGED)
{
printf("mnx_eth`read_int: packet size too big (%d)\n",
count);
bf_afree(pack);
}
else
{
cut_pack= bf_cut(pack, 0, count);
bf_afree(pack);
assert(!no_ethWritePort);
no_ethWritePort= 1;
eth_arrive(eth_port, cut_pack, count);
assert(no_ethWritePort);
no_ethWritePort= 0;
}
eth_port->etp_flags &= ~(EPF_READ_IP|EPF_READ_SP);
setup_read(eth_port);
}
static void setup_read(eth_port)
eth_port_t *eth_port;
{
acc_t *pack, *pack_ptr;
message mess;
iovec_s_t *iovec;
int i, r;
assert(!eth_port->etp_vlan);
assert(!(eth_port->etp_flags & (EPF_READ_IP|EPF_READ_SP)));
if (eth_port->etp_osdep.etp_state != OEPS_IDLE)
{
eth_port->etp_osdep.etp_flags |= OEPF_NEED_RECV;
return;
}
assert (!eth_port->etp_rd_pack);
iovec= eth_port->etp_osdep.etp_rd_iovec;
pack= bf_memreq (ETH_MAX_PACK_SIZE_TAGGED);
for (i=0, pack_ptr= pack; i<RD_IOVEC && pack_ptr;
i++, pack_ptr= pack_ptr->acc_next)
{
r= cpf_setgrant_direct(iovec[i].iov_grant,
eth_port->etp_osdep.etp_task,
(vir_bytes)ptr2acc_data(pack_ptr),
(vir_bytes)pack_ptr->acc_length,
CPF_WRITE);
if (r != 0)
{
ip_panic((
"mnx_eth`setup_read: cpf_setgrant_direct failed: %d\n",
errno));
}
iovec[i].iov_size= (vir_bytes)pack_ptr->acc_length;
}
assert (!pack_ptr);
r= cpf_setgrant_direct(eth_port->etp_osdep.etp_rd_vec_grant,
eth_port->etp_osdep.etp_task,
(vir_bytes)iovec,
(vir_bytes)(i * sizeof(iovec[0])),
CPF_READ);
if (r != 0)
{
ip_panic((
"mnx_eth`setup_read: cpf_setgrant_direct failed: %d\n",
errno));
}
mess.m_type= DL_READV_S;
mess.m_net_netdrv_dl_readv_s.count= i;
mess.m_net_netdrv_dl_readv_s.grant= eth_port->etp_osdep.etp_rd_vec_grant;
assert(eth_port->etp_osdep.etp_state == OEPS_IDLE);
r= asynsend(eth_port->etp_osdep.etp_task, &mess);
eth_port->etp_osdep.etp_state= OEPS_RECV_SENT;
if (r < 0)
{
printf(
"mnx_eth`setup_read: asynsend to %d failed: %d\n",
eth_port->etp_osdep.etp_task, r);
}
eth_port->etp_rd_pack= pack;
eth_port->etp_flags |= EPF_READ_IP;
eth_port->etp_flags |= EPF_READ_SP;
}
static void eth_restart(eth_port_t *eth_port, endpoint_t endpoint)
{
int r;
unsigned flags, dl_flags;
cp_grant_id_t gid;
message mess;
eth_port->etp_osdep.etp_task= endpoint;
switch(eth_port->etp_osdep.etp_state)
{
case OEPS_INIT:
case OEPS_CONF_SENT:
case OEPS_RECV_SENT:
case OEPS_SEND_SENT:
/* We can safely ignore the pending CONF, RECV, and SEND
* requests. If this is the first time that we see this
* driver at all, that's fine too.
*/
eth_port->etp_osdep.etp_state= OEPS_IDLE;
break;
case OEPS_GETSTAT_SENT:
/* Set the OEPF_NEED_STAT to trigger a new request */
eth_port->etp_osdep.etp_flags |= OEPF_NEED_STAT;
eth_port->etp_osdep.etp_state= OEPS_IDLE;
break;
}
/* If there is a pending GETSTAT request then we have to create a
* new grant.
*/
if (eth_port->etp_osdep.etp_flags & OEPF_NEED_STAT)
{
assert(eth_port->etp_osdep.etp_stat_gid != -1);
cpf_revoke(eth_port->etp_osdep.etp_stat_gid);
gid= cpf_grant_direct(eth_port->etp_osdep.etp_task,
(vir_bytes)eth_port->etp_osdep.etp_stat_buf,
sizeof(*eth_port->etp_osdep.etp_stat_buf), CPF_WRITE);
if (gid == -1)
{
ip_panic((
"eth_restart: cpf_grant_direct failed: %d\n",
errno));
}
eth_port->etp_osdep.etp_stat_gid= gid;
}
flags= eth_port->etp_osdep.etp_recvconf;
dl_flags= DL_NOMODE;
if (flags & NWEO_EN_BROAD)
dl_flags |= DL_BROAD_REQ;
if (flags & NWEO_EN_MULTI)
dl_flags |= DL_MULTI_REQ;
if (flags & NWEO_EN_PROMISC)
dl_flags |= DL_PROMISC_REQ;
mess.m_type= DL_CONF;
mess.m_net_netdrv_dl_conf.mode= dl_flags;
compare(eth_port->etp_osdep.etp_state, ==, OEPS_IDLE);
r= asynsend(eth_port->etp_osdep.etp_task, &mess);
if (r<0)
{
printf(
"eth_restart: send to ethernet task %d failed: %d\n",
eth_port->etp_osdep.etp_task, r);
return;
}
eth_port->etp_osdep.etp_state= OEPS_CONF_SENT;
if (eth_port->etp_wr_pack)
{
bf_afree(eth_port->etp_wr_pack);
eth_port->etp_wr_pack= NULL;
eth_restart_write(eth_port);
}
if (eth_port->etp_rd_pack)
{
bf_afree(eth_port->etp_rd_pack);
eth_port->etp_rd_pack= NULL;
eth_port->etp_flags &= ~(EPF_READ_IP|EPF_READ_SP);
}
}
static void send_getstat(eth_port)
eth_port_t *eth_port;
{
int r;
message mess;
mess.m_type= DL_GETSTAT_S;
mess.m_net_netdrv_dl_getstat_s.grant= eth_port->etp_osdep.etp_stat_gid;
assert(eth_port->etp_osdep.etp_state == OEPS_IDLE);
r= asynsend(eth_port->etp_osdep.etp_task, &mess);
eth_port->etp_osdep.etp_state= OEPS_GETSTAT_SENT;
if (r != OK)
ip_panic(( "eth_get_stat: asynsend failed: %d", r));
}
/*
* $PchId: mnx_eth.c,v 1.16 2005/06/28 14:24:37 philip Exp $
*/
0