int eth_init(bd_t *bd) {
	int r;
	u8 dev_addr[6];
	char ethaddr[20];

	PRINTK("### eth_init\n");

	if (!pbuf) {
		pbuf = malloc(2000);
		if (!pbuf) {
			printf("Cannot allocate rx buffer\n");
			return -1;
		}
	}

#ifdef CONFIG_DRIVER_NE2000_CCR
	{
		vu_char *p = (vu_char *) CONFIG_DRIVER_NE2000_CCR;

		PRINTK("CCR before is %x\n", *p);
		*p = CONFIG_DRIVER_NE2000_VAL;
		PRINTK("CCR after is %x\n", *p);
	}
#endif

	nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE;

	r = get_prom(dev_addr, nic.base);
	if (!r)
		return -1;

	sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
		 dev_addr[0], dev_addr[1],
		 dev_addr[2], dev_addr[3],
		 dev_addr[4], dev_addr[5]) ;
	PRINTK("Set environment from HW MAC addr = \"%s\"\n", ethaddr);
	setenv ("ethaddr", ethaddr);

	nic.data = nic.base + DP_DATA;
	nic.tx_buf1 = START_PG;
	nic.tx_buf2 = START_PG2;
	nic.rx_buf_start = RX_START;
	nic.rx_buf_end = RX_END;

	if (dp83902a_init() == false)
		return -1;

	dp83902a_start(dev_addr);
	initialized = 1;

	return 0;
}
Beispiel #2
0
int eth_init(bd_t *bd) {
	static hw_info_t * r;
	char ethaddr[20];

	PRINTK("### eth_init\n");

	if (!pbuf) {
		pbuf = malloc(NB*2000);
		if (!pbuf) {
			printf("Cannot allocate rx buffers\n");
			return -1;
		}
	}

#ifdef CONFIG_DRIVER_NE2000_CCR
	{
		volatile unsigned char *p =  (volatile unsigned char *) CONFIG_DRIVER_NE2000_CCR;

		PRINTK("CCR before is %x\n", *p);
		*p = CONFIG_DRIVER_NE2000_VAL;
		PRINTK("CCR after is %x\n", *p);
	}
#endif

	nic_base = CONFIG_DRIVER_NE2000_BASE;
	nic.base = (cyg_uint8 *) CONFIG_DRIVER_NE2000_BASE;

	r = get_prom();
	if (!r)
		return -1;

	sprintf (ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X",
		 dev_addr[0], dev_addr[1],
		 dev_addr[2], dev_addr[3],
		 dev_addr[4], dev_addr[5]) ;
	PRINTK("Set environment from HW MAC addr = \"%s\"\n", ethaddr);
	setenv ("ethaddr", ethaddr);


#define DP_DATA		0x10
	nic.data = nic.base + DP_DATA;
	nic.tx_buf1 = 0x40;
	nic.tx_buf2 = 0x48;
	nic.rx_buf_start = 0x50;
	nic.rx_buf_end = 0x80;

	if (dp83902a_init() == false)
		return -1;
	dp83902a_start(dev_addr);
	return 0;
}
Beispiel #3
0
/**
 * Setup the driver and init MAC address according to doc/README.enetaddr
 * Called by ne2k_register() before registering the driver @eth layer
 *
 * @param struct ethdevice of this instance of the driver for dev->enetaddr
 * @return 0 on success, -1 on error (causing caller to print error msg)
 */
static int ne2k_setup_driver(struct eth_device *dev)
{
    PRINTK("### ne2k_setup_driver\n");

    if (!pbuf) {
        pbuf = malloc(2000);
        if (!pbuf) {
            printf("Cannot allocate rx buffer\n");
            return -1;
        }
    }

#ifdef CONFIG_DRIVER_NE2000_CCR
    {
        vu_char *p = (vu_char *) CONFIG_DRIVER_NE2000_CCR;

        PRINTK("CCR before is %x\n", *p);
        *p = CONFIG_DRIVER_NE2000_VAL;
        PRINTK("CCR after is %x\n", *p);
    }
#endif

    nic.base = (u8 *) CONFIG_DRIVER_NE2000_BASE;

    nic.data = nic.base + DP_DATA;
    nic.tx_buf1 = START_PG;
    nic.tx_buf2 = START_PG2;
    nic.rx_buf_start = RX_START;
    nic.rx_buf_end = RX_END;

    /*
     * According to doc/README.enetaddr, drivers shall give priority
     * to the MAC address value in the environment, so we do not read
     * it from the prom or eeprom if it is specified in the environment.
     */
    if (!eth_getenv_enetaddr("ethaddr", dev->enetaddr)) {
        /* If the MAC address is not in the environment, get it: */
        if (!get_prom(dev->enetaddr, nic.base)) /* get MAC from prom */
            dp83902a_init(dev->enetaddr);   /* fallback: seeprom */
        /* And write it into the environment otherwise eth_write_hwaddr
         * returns -1 due to eth_getenv_enetaddr_by_index() failing,
         * and this causes "Warning: failed to set MAC address", and
         * cmd_bdinfo has no ethaddr value which it can show: */
        eth_setenv_enetaddr("ethaddr", dev->enetaddr);
    }
    return 0;
}
Beispiel #4
0
int ne2k_init(struct nic_priv_data *nic_data)
{
	int r;
	u8 eth_addr[6];

	if (!nic_data) {
		return VMM_EFAIL;
	}

	if (!nic_data->rx_rb) {
		nic_data->rx_rb = vmm_ringbuf_alloc(1, 2000);
		if (!nic_data->rx_rb) {
			vmm_printf("Cannot allocate receive buffer\n");
			return VMM_EFAIL;
		}
	}

	nic_data->base = (u8 *) (isa_vbase + CONFIG_DRIVER_NE2000_BASE);

	r = get_prom(nic_data, eth_addr);
	if (r != VMM_OK)
		return VMM_EFAIL;

	nic_data->data = nic_data->base + DP_DATA;
	nic_data->tx_buf1 = START_PG;
	nic_data->tx_buf2 = START_PG2;
	nic_data->rx_buf_start = RX_START;
	nic_data->rx_buf_end = RX_END;
	vmm_memcpy(nic_data->esa, eth_addr, sizeof(nic_data->esa));

	if (dp83902a_init(nic_data) != true) {
		return VMM_EFAIL;
	}

	dp83902a_start(nic_data, eth_addr);
	nic_data->initialized = 1;

	return VMM_OK;
}