summaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci-stub.c
blob: 4c0336b31cafb5fa3b0c00d51b9f7ab03bbb5c8c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* pci-stub - simple stub driver to reserve a pci device
 *
 * Copyright (C) 2008 Red Hat, Inc.
 * Author:
 * 	Chris Wright
 *
 * This work is licensed under the terms of the GNU GPL, version 2.
 *
 * Usage is simple, allocate a new id to the stub driver and bind the
 * device to it.  For example:
 * 
 * # echo "8086 10f5" > /sys/bus/pci/drivers/pci-stub/new_id
 * # echo -n 0000:00:19.0 > /sys/bus/pci/drivers/e1000e/unbind
 * # echo -n 0000:00:19.0 > /sys/bus/pci/drivers/pci-stub/bind
 * # ls -l /sys/bus/pci/devices/0000:00:19.0/driver
 * .../0000:00:19.0/driver -> ../../../bus/pci/drivers/pci-stub
 */

#include <linux/module.h>
#include <linux/pci.h>

static char ids[1024] __initdata;

module_param_string(ids, ids, sizeof(ids), 0);
MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the stub driver, format is "
		 "\"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\""
		 " and multiple comma separated entries can be specified");

static int pci_stub_probe(struct pci_dev *dev, const struct pci_device_id *id)
{
	dev_printk(KERN_INFO, &dev->dev, "claimed by stub\n");
	return 0;
}

static struct pci_driver stub_driver = {
	.name		= "pci-stub",
	.id_table	= NULL,	/* only dynamic id's */
	.probe		= pci_stub_probe,
};

static int __init pci_stub_init(void)
{
	char *p, *id;
	int rc;

	rc = pci_register_driver(&stub_driver);
	if (rc)
		return rc;

	/* no ids passed actually */
	if (ids[0] == '\0')
		return 0;

	/* add ids specified in the module parameter */
	p = ids;
	while ((id = strsep(&p, ","))) {
		unsigned int vendor, device, subvendor = PCI_ANY_ID,
			subdevice = PCI_ANY_ID, class=0, class_mask=0;
		int fields;

		fields = sscanf(id, "%x:%x:%x:%x:%x:%x",
				&vendor, &device, &subvendor, &subdevice,
				&class, &class_mask);

		if (fields < 2) {
			printk(KERN_WARNING
			       "pci-stub: invalid id string \"%s\"\n", id);
			continue;
		}

		printk(KERN_INFO
		       "pci-stub: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
		       vendor, device, subvendor, subdevice, class, class_mask);

		rc = pci_add_dynid(&stub_driver, vendor, device,
				   subvendor, subdevice, class, class_mask, 0);
		if (rc)
			printk(KERN_WARNING
			       "pci-stub: failed to add dynamic id (%d)\n", rc);
	}

	return 0;
}

static void __exit pci_stub_exit(void)
{
	pci_unregister_driver(&stub_driver);
}

module_init(pci_stub_init);
module_exit(pci_stub_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Chris Wright <chrisw@sous-sol.org>");
* available on the card. */ #define TX_BUF_START 0x0100 #define TX_BUF_SIZE ((24+ETH_FRAME_LEN+31)&~0x1f) #define RX_BUF_SIZE ((32+ETH_FRAME_LEN+31)&~0x1f) /* * SCB defines */ /* these functions take the SCB status word and test the relevant status bit */ #define SCB_complete(s) ((s&0x8000)!=0) #define SCB_rxdframe(s) ((s&0x4000)!=0) #define SCB_CUdead(s) ((s&0x2000)!=0) #define SCB_RUdead(s) ((s&0x1000)!=0) #define SCB_ack(s) (s & 0xf000) /* Command unit status: 0=idle, 1=suspended, 2=active */ #define SCB_CUstat(s) ((s&0x0300)>>8) /* Receive unit status: 0=idle, 1=suspended, 2=out of resources, 4=ready */ #define SCB_RUstat(s) ((s&0x0070)>>4) /* SCB commands */ #define SCB_CUnop 0x0000 #define SCB_CUstart 0x0100 #define SCB_CUresume 0x0200 #define SCB_CUsuspend 0x0300 #define SCB_CUabort 0x0400 #define SCB_resetchip 0x0080 #define SCB_RUnop 0x0000 #define SCB_RUstart 0x0010 #define SCB_RUresume 0x0020 #define SCB_RUsuspend 0x0030 #define SCB_RUabort 0x0040 /* * Command block defines */ #define Stat_Done(s) ((s&0x8000)!=0) #define Stat_Busy(s) ((s&0x4000)!=0) #define Stat_OK(s) ((s&0x2000)!=0) #define Stat_Abort(s) ((s&0x1000)!=0) #define Stat_STFail ((s&0x0800)!=0) #define Stat_TNoCar(s) ((s&0x0400)!=0) #define Stat_TNoCTS(s) ((s&0x0200)!=0) #define Stat_TNoDMA(s) ((s&0x0100)!=0) #define Stat_TDefer(s) ((s&0x0080)!=0) #define Stat_TColl(s) ((s&0x0040)!=0) #define Stat_TXColl(s) ((s&0x0020)!=0) #define Stat_NoColl(s) (s&0x000f) /* Cmd_END will end AFTER the command if this is the first * command block after an SCB_CUstart, but BEFORE the command * for all subsequent commands. Best strategy is to place * Cmd_INT on the last command in the sequence, followed by a * dummy Cmd_Nop with Cmd_END after this. */ #define Cmd_END 0x8000 #define Cmd_SUS 0x4000 #define Cmd_INT 0x2000 #define Cmd_Nop 0x0000 #define Cmd_SetAddr 0x0001 #define Cmd_Config 0x0002 #define Cmd_MCast 0x0003 #define Cmd_Xmit 0x0004 #define Cmd_TDR 0x0005 #define Cmd_Dump 0x0006 #define Cmd_Diag 0x0007 /* * Frame Descriptor (Receive block) defines */ #define FD_Done(s) ((s&0x8000)!=0) #define FD_Busy(s) ((s&0x4000)!=0) #define FD_OK(s) ((s&0x2000)!=0) #define FD_CRC(s) ((s&0x0800)!=0) #define FD_Align(s) ((s&0x0400)!=0) #define FD_Resrc(s) ((s&0x0200)!=0) #define FD_DMA(s) ((s&0x0100)!=0) #define FD_Short(s) ((s&0x0080)!=0) #define FD_NoEOF(s) ((s&0x0040)!=0) struct rfd_header { volatile unsigned long flags; volatile unsigned short link; volatile unsigned short rbd_offset; volatile unsigned short dstaddr1; volatile unsigned short dstaddr2; volatile unsigned short dstaddr3; volatile unsigned short srcaddr1; volatile unsigned short srcaddr2; volatile unsigned short srcaddr3; volatile unsigned short length; /* This is actually a Receive Buffer Descriptor. The way we * arrange memory means that an RBD always follows the RFD that * points to it, so they might as well be in the same structure. */ volatile unsigned short actual_count; volatile unsigned short next_rbd; volatile unsigned short buf_addr1; volatile unsigned short buf_addr2; volatile unsigned short size; }; /* Returned data from the Time Domain Reflectometer */ #define TDR_LINKOK (1<<15) #define TDR_XCVRPROBLEM (1<<14) #define TDR_OPEN (1<<13) #define TDR_SHORT (1<<12) #define TDR_TIME 0x7ff