drivers/net/rionet.c

Source file repositories/reference/linux-study-clean/drivers/net/rionet.c

File Facts

System
Linux kernel
Corpus path
drivers/net/rionet.c
Extension
.c
Size
18750 bytes
Lines
749
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct net_device_ops rionet_netdev_ops = {
	.ndo_open		= rionet_open,
	.ndo_stop		= rionet_close,
	.ndo_start_xmit		= rionet_start_xmit,
	.ndo_validate_addr	= eth_validate_addr,
	.ndo_set_mac_address	= eth_mac_addr,
};

static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
{
	int rc = 0;
	struct rionet_private *rnet;
	u8 addr[ETH_ALEN];
	u16 device_id;
	const size_t rionet_active_bytes = sizeof(void *) *
				RIO_MAX_ROUTE_ENTRIES(mport->sys_size);

	nets[mport->id].active = (struct rio_dev **)__get_free_pages(GFP_KERNEL,
						get_order(rionet_active_bytes));
	if (!nets[mport->id].active) {
		rc = -ENOMEM;
		goto out;
	}
	memset((void *)nets[mport->id].active, 0, rionet_active_bytes);

	/* Set up private area */
	rnet = netdev_priv(ndev);
	rnet->mport = mport;
	rnet->open = false;

	/* Set the default MAC address */
	device_id = rio_local_get_device_id(mport);
	addr[0] = 0x00;
	addr[1] = 0x01;
	addr[2] = 0x00;
	addr[3] = 0x01;
	addr[4] = device_id >> 8;
	addr[5] = device_id & 0xff;
	eth_hw_addr_set(ndev, addr);

	ndev->netdev_ops = &rionet_netdev_ops;
	ndev->mtu = RIONET_MAX_MTU;
	/* MTU range: 68 - 4082 */
	ndev->min_mtu = ETH_MIN_MTU;
	ndev->max_mtu = RIONET_MAX_MTU;
	ndev->lltx = true;
	SET_NETDEV_DEV(ndev, &mport->dev);
	ndev->ethtool_ops = &rionet_ethtool_ops;

	spin_lock_init(&rnet->lock);
	spin_lock_init(&rnet->tx_lock);

	rnet->msg_enable = RIONET_DEFAULT_MSGLEVEL;

	rc = register_netdev(ndev);
	if (rc != 0) {
		free_pages((unsigned long)nets[mport->id].active,
			   get_order(rionet_active_bytes));
		goto out;
	}

	printk(KERN_INFO "%s: %s %s Version %s, MAC %pM, %s\n",
	       ndev->name,
	       DRV_NAME,
	       DRV_DESC,
	       DRV_VERSION,
	       ndev->dev_addr,
	       mport->name);

      out:
	return rc;
}

static int rionet_add_dev(struct device *dev, struct subsys_interface *sif)
{
	int rc = -ENODEV;
	u32 lsrc_ops, ldst_ops;
	struct rionet_peer *peer;
	struct net_device *ndev = NULL;
	struct rio_dev *rdev = to_rio_dev(dev);
	unsigned char netid = rdev->net->hport->id;

	if (netid >= RIONET_MAX_NETS)
		return rc;

	/*
	 * If first time through this net, make sure local device is rionet
	 * capable and setup netdev (this step will be skipped in later probes
	 * on the same net).
	 */

Annotation

Implementation Notes