Ejemplo n.º 1
0
void nic_init_all(void)
{
	int i;
	unsigned g;

	for (i = 0; i < MAX_DEVS; i++) {
		devices[i].drv_ep = NONE;
		devices[i].is_default = 0;

		if (cpf_getgrants(&devices[i].rx_iogrant, 1) != 1)
			panic("Cannot initialize grants");
		if (cpf_getgrants(&devices[i].rx_iovec[0].iov_grant, 1) != 1)
			panic("Cannot initialize grants");
		if (cpf_getgrants(&devices[i].tx_iogrant, 1) != 1)
			panic("Cannot initialize grants");
		for (g = 0; g < TX_IOVEC_NUM; g++) {
			cp_grant_id_t * gid = &devices[i].tx_iovec[g].iov_grant;
			if (cpf_getgrants(gid, 1) != 1)
				panic("Cannot initialize grants");
		}
		devices[i].raw_socket = NULL;
	}
}
Ejemplo n.º 2
0
PUBLIC void osdep_eth_init()
{
	int i, j, rport;
	struct eth_conf *ecp;
	eth_port_t *eth_port, *rep;
	cp_grant_id_t gid;

	/* First initialize normal ethernet interfaces */
	for (i= 0, ecp= eth_conf, eth_port= eth_port_table;
		i<eth_conf_nr; i++, ecp++, eth_port++)
	{
		/* Set all grants to invalid */
		for (j= 0; j<IOVEC_NR; j++)
			eth_port->etp_osdep.etp_wr_iovec[j].iov_grant= -1;
		eth_port->etp_osdep.etp_wr_vec_grant= -1;
		for (j= 0; j<RD_IOVEC; j++)
			eth_port->etp_osdep.etp_rd_iovec[j].iov_grant= -1;
		eth_port->etp_osdep.etp_rd_vec_grant= -1;

		eth_port->etp_osdep.etp_state= OEPS_INIT;
		eth_port->etp_osdep.etp_flags= OEPF_EMPTY;
		eth_port->etp_osdep.etp_stat_gid= -1;
		eth_port->etp_osdep.etp_stat_buf= NULL;

		if (eth_is_vlan(ecp))
			continue;

		/* Allocate grants */
		for (j= 0; j<IOVEC_NR; j++)
		{
			if (cpf_getgrants(&gid, 1) != 1)
			{
				ip_panic((
			"osdep_eth_init: cpf_getgrants failed: %d\n",
					errno));
			}
			eth_port->etp_osdep.etp_wr_iovec[j].iov_grant= gid;
		}
		if (cpf_getgrants(&gid, 1) != 1)
		{
			ip_panic((
		"osdep_eth_init: cpf_getgrants failed: %d\n",
				errno));
		}
		eth_port->etp_osdep.etp_wr_vec_grant= gid;
		for (j= 0; j<RD_IOVEC; j++)
		{
			if (cpf_getgrants(&gid, 1) != 1)
			{
				ip_panic((
			"osdep_eth_init: cpf_getgrants failed: %d\n",
					errno));
			}
			eth_port->etp_osdep.etp_rd_iovec[j].iov_grant= gid;
		}
		if (cpf_getgrants(&gid, 1) != 1)
		{
			ip_panic((
		"osdep_eth_init: cpf_getgrants failed: %d\n",
				errno));
		}
		eth_port->etp_osdep.etp_rd_vec_grant= gid;

		eth_port->etp_osdep.etp_task= NONE;
		eth_port->etp_osdep.etp_recvconf= 0;
		ev_init(&eth_port->etp_osdep.etp_recvev);

		sr_add_minor(if2minor(ecp->ec_ifno, ETH_DEV_OFF),
			i, eth_open, eth_close, eth_read, 
			eth_write, eth_ioctl, eth_cancel, eth_select);

		eth_port->etp_flags |= EPF_ENABLED;
		eth_port->etp_vlan= 0;
		eth_port->etp_vlan_port= NULL;
		eth_port->etp_wr_pack= 0;
		eth_port->etp_rd_pack= 0;
	}

	/* And now come the VLANs */
	for (i= 0, ecp= eth_conf, eth_port= eth_port_table;
		i<eth_conf_nr; i++, ecp++, eth_port++)
	{
		if (!eth_is_vlan(ecp))
			continue;

		eth_port->etp_osdep.etp_task= NONE;
		ev_init(&eth_port->etp_osdep.etp_recvev);

		rport= ecp->ec_port;
		assert(rport >= 0 && rport < eth_conf_nr);
		rep= &eth_port_table[rport];
		if (!(rep->etp_flags & EPF_ENABLED))
		{
			printf(
			"eth%d: underlying ethernet device %d not enabled",
				i, rport);
			continue;
		}
		if (rep->etp_vlan != 0)
		{
			printf(
			"eth%d: underlying ethernet device %d is a VLAN",
				i, rport);
			continue;
		}
		
		if (rep->etp_flags & EPF_GOT_ADDR)
		{
			eth_port->etp_ethaddr= rep->etp_ethaddr;
			printf("osdep_eth_init: setting EPF_GOT_ADDR\n");
			eth_port->etp_flags |= EPF_GOT_ADDR;
		}

		sr_add_minor(if2minor(ecp->ec_ifno, ETH_DEV_OFF),
			i, eth_open, eth_close, eth_read, 
			eth_write, eth_ioctl, eth_cancel, eth_select);

		eth_port->etp_flags |= EPF_ENABLED;
		eth_port->etp_vlan= ecp->ec_vlan;
		eth_port->etp_vlan_port= rep;
		assert(eth_port->etp_vlan != 0);
		eth_port->etp_wr_pack= 0;
		eth_port->etp_rd_pack= 0;
		eth_reg_vlan(rep, eth_port);
	}
}