drivers/net/ethernet/dec/tulip/xircom_cb.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/dec/tulip/xircom_cb.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/dec/tulip/xircom_cb.c
Extension
.c
Size
29693 bytes
Lines
1173
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 struct pci_driver xircom_driver = {
	.name		= "xircom_cb",
	.id_table	= xircom_pci_table,
	.probe		= xircom_probe,
	.remove		= xircom_remove,
};


#if defined DEBUG && DEBUG > 1
static void print_binary(unsigned int number)
{
	int i,i2;
	char buffer[64];
	memset(buffer,0,64);
	i2=0;
	for (i=31;i>=0;i--) {
		if (number & (1<<i))
			buffer[i2++]='1';
		else
			buffer[i2++]='0';
		if ((i&3)==0)
			buffer[i2++]=' ';
	}
	pr_debug("%s\n",buffer);
}
#endif

static const struct net_device_ops netdev_ops = {
	.ndo_open		= xircom_open,
	.ndo_stop		= xircom_close,
	.ndo_start_xmit		= xircom_start_xmit,
	.ndo_set_mac_address	= eth_mac_addr,
	.ndo_validate_addr	= eth_validate_addr,
#ifdef CONFIG_NET_POLL_CONTROLLER
	.ndo_poll_controller	= xircom_poll_controller,
#endif
};

/* xircom_probe is the code that gets called on device insertion.
   it sets up the hardware and registers the device to the networklayer.

   TODO: Send 1 or 2 "dummy" packets here as the card seems to discard the
         first two packets that get send, and pump hates that.

 */
static int xircom_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
	struct device *d = &pdev->dev;
	struct net_device *dev = NULL;
	struct xircom_private *private;
	unsigned long flags;
	unsigned short tmp16;
	int rc;

	/* First do the PCI initialisation */

	rc = pci_enable_device(pdev);
	if (rc < 0)
		goto out;

	/* disable all powermanagement */
	pci_write_config_dword(pdev, PCI_POWERMGMT, 0x0000);

	pci_set_master(pdev); /* Why isn't this done by pci_enable_device ?*/

	/* clear PCI status, if any */
	pci_read_config_word (pdev,PCI_STATUS, &tmp16);
	pci_write_config_word (pdev, PCI_STATUS,tmp16);

	rc = pci_request_regions(pdev, "xircom_cb");
	if (rc < 0) {
		pr_err("%s: failed to allocate io-region\n", __func__);
		goto err_disable;
	}

	rc = -ENOMEM;
	/*
	   Before changing the hardware, allocate the memory.
	   This way, we can fail gracefully if not enough memory
	   is available.
	 */
	dev = alloc_etherdev(sizeof(struct xircom_private));
	if (!dev)
		goto err_release;

	private = netdev_priv(dev);

	/* Allocate the send/receive buffers */
	private->rx_buffer = dma_alloc_coherent(d, 8192,
						&private->rx_dma_handle,

Annotation

Implementation Notes