Beispiel #1
0
void init_fec_ioports(struct fs_platform_info *fpi)
{
	int fec_no = fs_get_fec_index(fpi->fs_no);

	switch (fec_no) {
	case 0:
		init_fec1_ioports(fpi);
		break;
	case 1:
		init_fec2_ioports(fpi);
		break;
	default:
		printk(KERN_ERR "init_fec_ioports: invalid FEC number\n");
		return;
	}
}
Beispiel #2
0
static struct net_device *fs_init_instance(struct device *dev,
		const struct fs_platform_info *fpi)
{
	struct net_device *ndev = NULL;
	struct fs_enet_private *fep = NULL;
	int privsize, i, r, err = 0, registered = 0;

	/* guard */
	if ((unsigned int)fpi->fs_no >= FS_MAX_INDEX)
		return ERR_PTR(-EINVAL);

	privsize = sizeof(*fep) + (sizeof(struct sk_buff **) *
			    (fpi->rx_ring + fpi->tx_ring));

	ndev = alloc_etherdev(privsize);
	if (!ndev) {
		err = -ENOMEM;
		goto err;
	}
	SET_MODULE_OWNER(ndev);

	fep = netdev_priv(ndev);
	memset(fep, 0, privsize);	/* clear everything */

	fep->dev = dev;
	dev_set_drvdata(dev, ndev);
	fep->fpi = fpi;
	if (fpi->init_ioports)
		fpi->init_ioports();

#ifdef CONFIG_FS_ENET_HAS_FEC
	if (fs_get_fec_index(fpi->fs_no) >= 0)
		fep->ops = &fs_fec_ops;
#endif

#ifdef CONFIG_FS_ENET_HAS_SCC
	if (fs_get_scc_index(fpi->fs_no) >=0 )
		fep->ops = &fs_scc_ops;
#endif

#ifdef CONFIG_FS_ENET_HAS_FCC
	if (fs_get_fcc_index(fpi->fs_no) >= 0)
		fep->ops = &fs_fcc_ops;
#endif

	if (fep->ops == NULL) {
		printk(KERN_ERR DRV_MODULE_NAME
		       ": %s No matching ops found (%d).\n",
		       ndev->name, fpi->fs_no);
		err = -EINVAL;
		goto err;
	}

	r = (*fep->ops->setup_data)(ndev);
	if (r != 0) {
		printk(KERN_ERR DRV_MODULE_NAME
		       ": %s setup_data failed\n",
			ndev->name);
		err = r;
		goto err;
	}

	/* point rx_skbuff, tx_skbuff */
	fep->rx_skbuff = (struct sk_buff **)&fep[1];
	fep->tx_skbuff = fep->rx_skbuff + fpi->rx_ring;

	/* init locks */
	spin_lock_init(&fep->lock);
	spin_lock_init(&fep->tx_lock);

	/*
	 * Set the Ethernet address.
	 */
	for (i = 0; i < 6; i++)
		ndev->dev_addr[i] = fpi->macaddr[i];

	r = (*fep->ops->allocate_bd)(ndev);

	if (fep->ring_base == NULL) {
		printk(KERN_ERR DRV_MODULE_NAME
		       ": %s buffer descriptor alloc failed (%d).\n", ndev->name, r);
		err = r;
		goto err;
	}

	/*
	 * Set receive and transmit descriptor base.
	 */
	fep->rx_bd_base = fep->ring_base;
	fep->tx_bd_base = fep->rx_bd_base + fpi->rx_ring;

	/* initialize ring size variables */
	fep->tx_ring = fpi->tx_ring;
	fep->rx_ring = fpi->rx_ring;

	/*
	 * The FEC Ethernet specific entries in the device structure.
	 */
	ndev->open = fs_enet_open;
	ndev->hard_start_xmit = fs_enet_start_xmit;
	ndev->tx_timeout = fs_timeout;
	ndev->watchdog_timeo = 2 * HZ;
	ndev->stop = fs_enet_close;
	ndev->get_stats = fs_enet_get_stats;
	ndev->set_multicast_list = fs_set_multicast_list;
	if (fpi->use_napi) {
		ndev->poll = fs_enet_rx_napi;
		ndev->weight = fpi->napi_weight;
	}
	ndev->ethtool_ops = &fs_ethtool_ops;
	ndev->do_ioctl = fs_ioctl;

	init_timer(&fep->phy_timer_list);

	netif_carrier_off(ndev);

	err = register_netdev(ndev);
	if (err != 0) {
		printk(KERN_ERR DRV_MODULE_NAME
		       ": %s register_netdev failed.\n", ndev->name);
		goto err;
	}
	registered = 1;


	return ndev;

      err:
	if (ndev != NULL) {

		if (registered)
			unregister_netdev(ndev);

		if (fep != NULL) {
			(*fep->ops->free_bd)(ndev);
			(*fep->ops->cleanup_data)(ndev);
		}

		free_netdev(ndev);
	}

	dev_set_drvdata(dev, NULL);

	return ERR_PTR(err);
}