1.. SPDX-License-Identifier: GPL-2.0
2.. include:: <isonum.txt>
3.. include:: ../disclaimer-zh_CN.rst
4
5:Original: Documentation/PCI/pci-iov-howto.rst
6
7:������:
8
9 ��������� Yanteng Si <siyanteng@loongson.cn>
10
11:������:
12
13
14
15.. _cn_pci-iov-howto:
16
17==========================
18PCI Express I/O ���������������
19==========================
20
21:������: |copy| 2009 Intel Corporation
22:������: - Yu Zhao <yu.zhao@intel.com>
23          - Donald Dutile <ddutile@redhat.com>
24
25������
26====
27
28���������SR-IOV
29------------
30
31������I/O������������SR-IOV������������PCI Express������������������������������������������������������
32���������������������������������������������������PF���������������������������������������������VF������VF������
33������������PF������������������������������������������������������������������������������������������������PF���
34���������������PCIe������������������������������VF���PCI������������������������������������������������������
35���������������������ID���������������������������VF������PCI���������������������������������������������VF���
36������������������������������������������������������������������������������������������������������������PCI������
37���������
38
39������������
40========
41
42���������������������SR-IOV������
43------------------------
44
45������������������������SR-IOV���������������������������������������������������PF������������������SR-IOV
46���������������API���������������������������������������������������SR-IOV������������������PF���������������
47������������PF���������������VF���������PF������������������������������������������������������������VF������������
48���������������������������sysfs������sriov_numvfs������������������������������PCIe PF���������VF���
49���������������������������PF���VF������/���������������������������������������������������������������PF������������
50PCI SRIOV������������������������/������������������������������������������������������������������������������
51���������������������������VF���������numvfs == 0���������numvfs <= totalvfs���
52���������������������������/���������VF������������������������
53
54���������������������������������
55----------------------
56
57���������������VF���������������������PCI������������������������������������������������PCI���������������������
58���������VF������������������������������PCI������������������������
59
60���������������
61==========
62
63SR-IOV API
64----------
65
66������������SR-IOV������:
67
68(a) ������������������������������������������::
69
70	int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
71
72nr_virtfn'���������������VF������������
73
74(b) ���������������������������sysfs::
75
76	echo 'nr_virtfn' > \
77        /sys/bus/pci/devices/<DOMAIN:BUS:DEVICE.FUNCTION>/sriov_numvfs
78
79������������SR-IOV������:
80
81(a) ������������������������������������������::
82
83	void pci_disable_sriov(struct pci_dev *dev);
84
85(b) ���������������������������sysfs::
86
87	echo  0 > \
88        /sys/bus/pci/devices/<DOMAIN:BUS:DEVICE.FUNCTION>/sriov_numvfs
89
90������������������������������������������������������VF������������SR-IOV���������������������������������������
91���������������������
92::
93
94	echo 1 > \
95        /sys/bus/pci/devices/<DOMAIN:BUS:DEVICE.FUNCTION>/sriov_drivers_autoprobe
96
97���������������������������������������������VF���������������SR-IOV���������������������������������������������
98������������������������������������VF���
99::
100
101	echo  0 > \
102        /sys/bus/pci/devices/<DOMAIN:BUS:DEVICE.FUNCTION>/sriov_drivers_autoprobe
103
104������
105----
106
107������������������������SR-IOV API���������
108::
109
110	static int dev_probe(struct pci_dev *dev, const struct pci_device_id *id)
111	{
112		pci_enable_sriov(dev, NR_VIRTFN);
113
114		...
115
116		return 0;
117	}
118
119	static void dev_remove(struct pci_dev *dev)
120	{
121		pci_disable_sriov(dev);
122
123		...
124	}
125
126	static int dev_suspend(struct device *dev)
127	{
128		...
129
130		return 0;
131	}
132
133	static int dev_resume(struct device *dev)
134	{
135		...
136
137		return 0;
138	}
139
140	static void dev_shutdown(struct pci_dev *dev)
141	{
142		...
143	}
144
145	static int dev_sriov_configure(struct pci_dev *dev, int numvfs)
146	{
147		if (numvfs > 0) {
148			...
149			pci_enable_sriov(dev, numvfs);
150			...
151			return numvfs;
152		}
153		if (numvfs == 0) {
154			....
155			pci_disable_sriov(dev);
156			...
157			return 0;
158		}
159	}
160
161	static struct pci_driver dev_driver = {
162		.name =		"SR-IOV Physical Function driver",
163		.id_table =	dev_id_table,
164		.probe =	dev_probe,
165		.remove =	dev_remove,
166		.driver.pm =    &dev_pm_ops
167		.shutdown =	dev_shutdown,
168		.sriov_configure = dev_sriov_configure,
169	};
170