~ubuntu-branches/ubuntu/raring/libvirt/raring

« back to all changes in this revision

Viewing changes to src/util/pci.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-11-19 10:41:02 UTC
  • mfrom: (1.2.15) (223.1.2 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121119104102-l6ewdppikysbzztu
Tags: 1.0.0-0ubuntu2
debian/patches/add-armhf-sysinfo-infomration.patch: Disable
to fix FTBFS on arm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
 * Lesser General Public License for more details.
13
13
 *
14
14
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this library; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
15
 * License along with this library.  If not, see
 
16
 * <http://www.gnu.org/licenses/>.
17
17
 *
18
18
 * Authors:
19
19
 *     Mark McLoughlin <markmc@redhat.com>
82
82
/* For virReportOOMError()  and virReportSystemError() */
83
83
#define VIR_FROM_THIS VIR_FROM_NONE
84
84
 
85
 
#define pciReportError(code, ...)                              \
86
 
    virReportErrorHelper(VIR_FROM_NONE, code, __FILE__,        \
87
 
                         __FUNCTION__, __LINE__, __VA_ARGS__)
88
 
 
89
85
/* Specifications referenced in comments:
90
86
 *  PCI30  - PCI Local Bus Specification 3.0
91
87
 *  PCIe20 - PCI Express Base Specification 2.0
609
605
    uint16_t ctl;
610
606
    int ret = -1;
611
607
 
612
 
    /* For now, we just refuse to do a secondary bus reset
613
 
     * if there are other devices/functions behind the bus.
614
 
     * In future, we could allow it so long as those devices
615
 
     * are not in use by the host or other guests.
 
608
    /* Refuse to do a secondary bus reset if there are other
 
609
     * devices/functions behind the bus are used by the host
 
610
     * or other guests.
616
611
     */
617
612
    if ((conflict = pciBusContainsActiveDevices(dev, inactiveDevs))) {
618
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
613
        virReportError(VIR_ERR_INTERNAL_ERROR,
619
614
                       _("Active %s devices on bus with %s, not doing bus reset"),
620
615
                       conflict->name, dev->name);
621
616
        return -1;
625
620
    if (pciGetParentDevice(dev, &parent) < 0)
626
621
        return -1;
627
622
    if (!parent) {
628
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
623
        virReportError(VIR_ERR_INTERNAL_ERROR,
629
624
                       _("Failed to find parent device for %s"),
630
625
                       dev->name);
631
626
        return -1;
638
633
     * are multiple devices/functions
639
634
     */
640
635
    if (pciRead(dev, 0, config_space, PCI_CONF_LEN) < 0) {
641
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
636
        virReportError(VIR_ERR_INTERNAL_ERROR,
642
637
                       _("Failed to read PCI config space for %s"),
643
638
                       dev->name);
644
639
        goto out;
658
653
    usleep(200 * 1000); /* sleep 200ms */
659
654
 
660
655
    if (pciWrite(dev, 0, config_space, PCI_CONF_LEN) < 0) {
661
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
656
        virReportError(VIR_ERR_INTERNAL_ERROR,
662
657
                       _("Failed to restore PCI config space for %s"),
663
658
                       dev->name);
664
659
        goto out;
684
679
 
685
680
    /* Save and restore the device's config space. */
686
681
    if (pciRead(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
687
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
682
        virReportError(VIR_ERR_INTERNAL_ERROR,
688
683
                       _("Failed to read PCI config space for %s"),
689
684
                       dev->name);
690
685
        return -1;
704
699
    usleep(10 * 1000); /* sleep 10ms */
705
700
 
706
701
    if (pciWrite(dev, 0, &config_space[0], PCI_CONF_LEN) < 0) {
707
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
702
        virReportError(VIR_ERR_INTERNAL_ERROR,
708
703
                       _("Failed to restore PCI config space for %s"),
709
704
                       dev->name);
710
705
        return -1;
744
739
    int ret = -1;
745
740
 
746
741
    if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
747
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
742
        virReportError(VIR_ERR_INTERNAL_ERROR,
748
743
                       _("Not resetting active device %s"), dev->name);
749
744
        return -1;
750
745
    }
771
766
 
772
767
    if (ret < 0) {
773
768
        virErrorPtr err = virGetLastError();
774
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
769
        virReportError(VIR_ERR_INTERNAL_ERROR,
775
770
                       _("Unable to reset PCI device %s: %s"),
776
771
                       dev->name,
777
772
                       err ? err->message : _("no FLR, PM reset or bus reset available"));
1118
1113
{
1119
1114
    const char *driver = pciFindStubDriver();
1120
1115
    if (!driver) {
1121
 
        pciReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1116
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
1122
1117
                       _("cannot find any PCI stub module"));
1123
1118
        return -1;
1124
1119
    }
1125
1120
 
1126
1121
    if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
1127
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1122
        virReportError(VIR_ERR_INTERNAL_ERROR,
1128
1123
                       _("Not detaching active device %s"), dev->name);
1129
1124
        return -1;
1130
1125
    }
1148
1143
{
1149
1144
    const char *driver = pciFindStubDriver();
1150
1145
    if (!driver) {
1151
 
        pciReportError(VIR_ERR_INTERNAL_ERROR, "%s",
 
1146
        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
1152
1147
                       _("cannot find any PCI stub module"));
1153
1148
        return -1;
1154
1149
    }
1155
1150
 
1156
1151
    if (activeDevs && pciDeviceListFind(activeDevs, dev)) {
1157
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1152
        virReportError(VIR_ERR_INTERNAL_ERROR,
1158
1153
                       _("Not reattaching active device %s"), dev->name);
1159
1154
        return -1;
1160
1155
    }
1356
1351
    if (snprintf(dev->name, sizeof(dev->name), "%.4x:%.2x:%.2x.%.1x",
1357
1352
                 dev->domain, dev->bus, dev->slot,
1358
1353
                 dev->function) >= sizeof(dev->name)) {
1359
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1354
        virReportError(VIR_ERR_INTERNAL_ERROR,
1360
1355
                       _("dev->name buffer overflow: %.4x:%.2x:%.2x.%.1x"),
1361
1356
                       dev->domain, dev->bus, dev->slot, dev->function);
1362
1357
        goto error;
1378
1373
    product = pciReadDeviceID(dev, "device");
1379
1374
 
1380
1375
    if (!vendor || !product) {
1381
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1376
        virReportError(VIR_ERR_INTERNAL_ERROR,
1382
1377
                       _("Failed to read product/vendor ID for %s"),
1383
1378
                       dev->name);
1384
1379
        goto error;
1387
1382
    /* strings contain '0x' prefix */
1388
1383
    if (snprintf(dev->id, sizeof(dev->id), "%s %s", &vendor[2],
1389
1384
                 &product[2]) >= sizeof(dev->id)) {
1390
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1385
        virReportError(VIR_ERR_INTERNAL_ERROR,
1391
1386
                       _("dev->id buffer overflow: %s %s"),
1392
1387
                       &vendor[2], &product[2]);
1393
1388
        goto error;
1525
1520
                 pciDevice *dev)
1526
1521
{
1527
1522
    if (pciDeviceListFind(list, dev)) {
1528
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1523
        virReportError(VIR_ERR_INTERNAL_ERROR,
1529
1524
                       _("Device %s is already in use"), dev->name);
1530
1525
        return -1;
1531
1526
    }
1715
1710
        if (dev->bus == 0)
1716
1711
            return 0;
1717
1712
        else {
1718
 
            pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1713
            virReportError(VIR_ERR_INTERNAL_ERROR,
1719
1714
                           _("Failed to find parent device for %s"),
1720
1715
                           dev->name);
1721
1716
            return -1;
1770
1765
            VIR_DEBUG("%s %s: strict ACS check disabled; device assignment allowed",
1771
1766
                      dev->id, dev->name);
1772
1767
        } else {
1773
 
            pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1768
            virReportError(VIR_ERR_INTERNAL_ERROR,
1774
1769
                           _("Device %s is behind a switch lacking ACS and "
1775
1770
                             "cannot be assigned"),
1776
1771
                           dev->name);
1867
1862
    device_path = canonicalize_file_name (device_link);
1868
1863
    if (device_path == NULL) {
1869
1864
        memset(errbuf, '\0', sizeof(errbuf));
1870
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1865
        virReportError(VIR_ERR_INTERNAL_ERROR,
1871
1866
                       _("Failed to resolve device link '%s': '%s'"),
1872
1867
                       device_link, virStrerror(errno, errbuf,
1873
1868
                       sizeof(errbuf)));
1881
1876
    }
1882
1877
 
1883
1878
    if (pciParsePciConfigAddress(config_address, *bdf) != 0) {
1884
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1879
        virReportError(VIR_ERR_INTERNAL_ERROR,
1885
1880
                       _("Failed to parse PCI config address '%s'"),
1886
1881
                       config_address);
1887
1882
        VIR_FREE(*bdf);
1948
1943
    dir = opendir(sysfs_path);
1949
1944
    if (dir == NULL) {
1950
1945
        memset(errbuf, '\0', sizeof(errbuf));
1951
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1946
        virReportError(VIR_ERR_INTERNAL_ERROR,
1952
1947
                       _("Failed to open dir '%s': '%s'"),
1953
1948
                       sysfs_path, virStrerror(errno, errbuf,
1954
1949
                       sizeof(errbuf)));
1979
1974
                SRIOV_FOUND) {
1980
1975
                /* We should not get back SRIOV_NOT_FOUND in this
1981
1976
                 * case, so if we do, it's an error. */
1982
 
                pciReportError(VIR_ERR_INTERNAL_ERROR,
 
1977
                virReportError(VIR_ERR_INTERNAL_ERROR,
1983
1978
                               _("Failed to get SR IOV function from device "
1984
1979
                               "link '%s'"), device_link);
1985
1980
                VIR_FREE(device_link);
2041
2036
 
2042
2037
    if (pciGetVirtualFunctions(pf_sysfs_device_link, &virt_fns,
2043
2038
        &num_virt_fns) < 0) {
2044
 
        pciReportError(VIR_ERR_INTERNAL_ERROR,
 
2039
        virReportError(VIR_ERR_INTERNAL_ERROR,
2045
2040
                       _("Error getting physical function's '%s' "
2046
2041
                      "virtual_functions"), pf_sysfs_device_link);
2047
2042
        goto out;
2178
2173
pciGetPhysicalFunction(const char *vf_sysfs_path ATTRIBUTE_UNUSED,
2179
2174
              struct pci_config_address **physical_function ATTRIBUTE_UNUSED)
2180
2175
{
2181
 
    pciReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
 
2176
    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
2182
2177
    return -1;
2183
2178
}
2184
2179
 
2187
2182
             struct pci_config_address ***virtual_functions ATTRIBUTE_UNUSED,
2188
2183
             unsigned int *num_virtual_functions ATTRIBUTE_UNUSED)
2189
2184
{
2190
 
    pciReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
 
2185
    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
2191
2186
    return -1;
2192
2187
}
2193
2188
 
2194
2189
int
2195
2190
pciDeviceIsVirtualFunction(const char *vf_sysfs_device_link ATTRIBUTE_UNUSED)
2196
2191
{
2197
 
    pciReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
 
2192
    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
2198
2193
    return -1;
2199
2194
}
2200
2195
 
2203
2198
                           const char *vf_sysfs_device_link ATTRIBUTE_UNUSED,
2204
2199
                           int *vf_index ATTRIBUTE_UNUSED)
2205
2200
{
2206
 
    pciReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
 
2201
    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
2207
2202
    return -1;
2208
2203
 
2209
2204
}
2212
2207
pciConfigAddressToSysfsFile(struct pci_config_address *dev ATTRIBUTE_UNUSED,
2213
2208
                            char **pci_sysfs_device_link ATTRIBUTE_UNUSED)
2214
2209
{
2215
 
    pciReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
 
2210
    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
2216
2211
    return -1;
2217
2212
}
2218
2213
 
2220
2215
pciDeviceNetName(char *device_link_sysfs_path ATTRIBUTE_UNUSED,
2221
2216
                 char **netname ATTRIBUTE_UNUSED)
2222
2217
{
2223
 
    pciReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
 
2218
    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
2224
2219
    return -1;
2225
2220
}
2226
2221
 
2229
2224
                                char **pfname ATTRIBUTE_UNUSED,
2230
2225
                                int *vf_index ATTRIBUTE_UNUSED)
2231
2226
{
2232
 
    pciReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
 
2227
    virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
2233
2228
    return -1;
2234
2229
}
2235
2230
#endif /* __linux__ */