Skip to content

Commit 10269d5

Browse files
ij-intelkwilczynski
authored andcommitted
PCI/sysfs: Move reset related sysfs code to correct file
Most PCI sysfs code and structs are in a dedicated file but a few reset related things remain in pci.c. Move also them to pci-sysfs.c and drop pci_dev_reset_method_attr_is_visible() as it is 100% duplicate of pci_dev_reset_attr_is_visible(). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ilpo Järvinen <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]>
1 parent 40384c8 commit 10269d5

File tree

3 files changed

+114
-126
lines changed

3 files changed

+114
-126
lines changed

drivers/pci/pci-sysfs.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,118 @@ static const struct attribute_group pci_dev_reset_attr_group = {
14211421
.is_visible = pci_dev_reset_attr_is_visible,
14221422
};
14231423

1424+
static ssize_t reset_method_show(struct device *dev,
1425+
struct device_attribute *attr, char *buf)
1426+
{
1427+
struct pci_dev *pdev = to_pci_dev(dev);
1428+
ssize_t len = 0;
1429+
int i, m;
1430+
1431+
for (i = 0; i < PCI_NUM_RESET_METHODS; i++) {
1432+
m = pdev->reset_methods[i];
1433+
if (!m)
1434+
break;
1435+
1436+
len += sysfs_emit_at(buf, len, "%s%s", len ? " " : "",
1437+
pci_reset_fn_methods[m].name);
1438+
}
1439+
1440+
if (len)
1441+
len += sysfs_emit_at(buf, len, "\n");
1442+
1443+
return len;
1444+
}
1445+
1446+
static int reset_method_lookup(const char *name)
1447+
{
1448+
int m;
1449+
1450+
for (m = 1; m < PCI_NUM_RESET_METHODS; m++) {
1451+
if (sysfs_streq(name, pci_reset_fn_methods[m].name))
1452+
return m;
1453+
}
1454+
1455+
return 0; /* not found */
1456+
}
1457+
1458+
static ssize_t reset_method_store(struct device *dev,
1459+
struct device_attribute *attr,
1460+
const char *buf, size_t count)
1461+
{
1462+
struct pci_dev *pdev = to_pci_dev(dev);
1463+
char *options, *tmp_options, *name;
1464+
int m, n;
1465+
u8 reset_methods[PCI_NUM_RESET_METHODS] = { 0 };
1466+
1467+
if (sysfs_streq(buf, "")) {
1468+
pdev->reset_methods[0] = 0;
1469+
pci_warn(pdev, "All device reset methods disabled by user");
1470+
return count;
1471+
}
1472+
1473+
if (sysfs_streq(buf, "default")) {
1474+
pci_init_reset_methods(pdev);
1475+
return count;
1476+
}
1477+
1478+
options = kstrndup(buf, count, GFP_KERNEL);
1479+
if (!options)
1480+
return -ENOMEM;
1481+
1482+
n = 0;
1483+
tmp_options = options;
1484+
while ((name = strsep(&tmp_options, " ")) != NULL) {
1485+
if (sysfs_streq(name, ""))
1486+
continue;
1487+
1488+
name = strim(name);
1489+
1490+
m = reset_method_lookup(name);
1491+
if (!m) {
1492+
pci_err(pdev, "Invalid reset method '%s'", name);
1493+
goto error;
1494+
}
1495+
1496+
if (pci_reset_fn_methods[m].reset_fn(pdev, PCI_RESET_PROBE)) {
1497+
pci_err(pdev, "Unsupported reset method '%s'", name);
1498+
goto error;
1499+
}
1500+
1501+
if (n == PCI_NUM_RESET_METHODS - 1) {
1502+
pci_err(pdev, "Too many reset methods\n");
1503+
goto error;
1504+
}
1505+
1506+
reset_methods[n++] = m;
1507+
}
1508+
1509+
reset_methods[n] = 0;
1510+
1511+
/* Warn if dev-specific supported but not highest priority */
1512+
if (pci_reset_fn_methods[1].reset_fn(pdev, PCI_RESET_PROBE) == 0 &&
1513+
reset_methods[0] != 1)
1514+
pci_warn(pdev, "Device-specific reset disabled/de-prioritized by user");
1515+
memcpy(pdev->reset_methods, reset_methods, sizeof(pdev->reset_methods));
1516+
kfree(options);
1517+
return count;
1518+
1519+
error:
1520+
/* Leave previous methods unchanged */
1521+
kfree(options);
1522+
return -EINVAL;
1523+
}
1524+
static DEVICE_ATTR_RW(reset_method);
1525+
1526+
static struct attribute *pci_dev_reset_method_attrs[] = {
1527+
&dev_attr_reset_method.attr,
1528+
NULL,
1529+
};
1530+
1531+
static const struct attribute_group pci_dev_reset_method_attr_group = {
1532+
.attrs = pci_dev_reset_method_attrs,
1533+
.is_visible = pci_dev_reset_attr_is_visible,
1534+
};
1535+
14241536
static ssize_t __resource_resize_show(struct device *dev, int n, char *buf)
14251537
{
14261538
struct pci_dev *pdev = to_pci_dev(dev);

drivers/pci/pci.c

Lines changed: 1 addition & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -5204,7 +5204,7 @@ static void pci_dev_restore(struct pci_dev *dev)
52045204
}
52055205

52065206
/* dev->reset_methods[] is a 0-terminated list of indices into this array */
5207-
static const struct pci_reset_fn_method pci_reset_fn_methods[] = {
5207+
const struct pci_reset_fn_method pci_reset_fn_methods[] = {
52085208
{ },
52095209
{ pci_dev_specific_reset, .name = "device_specific" },
52105210
{ pci_dev_acpi_reset, .name = "acpi" },
@@ -5215,129 +5215,6 @@ static const struct pci_reset_fn_method pci_reset_fn_methods[] = {
52155215
{ cxl_reset_bus_function, .name = "cxl_bus" },
52165216
};
52175217

5218-
static ssize_t reset_method_show(struct device *dev,
5219-
struct device_attribute *attr, char *buf)
5220-
{
5221-
struct pci_dev *pdev = to_pci_dev(dev);
5222-
ssize_t len = 0;
5223-
int i, m;
5224-
5225-
for (i = 0; i < PCI_NUM_RESET_METHODS; i++) {
5226-
m = pdev->reset_methods[i];
5227-
if (!m)
5228-
break;
5229-
5230-
len += sysfs_emit_at(buf, len, "%s%s", len ? " " : "",
5231-
pci_reset_fn_methods[m].name);
5232-
}
5233-
5234-
if (len)
5235-
len += sysfs_emit_at(buf, len, "\n");
5236-
5237-
return len;
5238-
}
5239-
5240-
static int reset_method_lookup(const char *name)
5241-
{
5242-
int m;
5243-
5244-
for (m = 1; m < PCI_NUM_RESET_METHODS; m++) {
5245-
if (sysfs_streq(name, pci_reset_fn_methods[m].name))
5246-
return m;
5247-
}
5248-
5249-
return 0; /* not found */
5250-
}
5251-
5252-
static ssize_t reset_method_store(struct device *dev,
5253-
struct device_attribute *attr,
5254-
const char *buf, size_t count)
5255-
{
5256-
struct pci_dev *pdev = to_pci_dev(dev);
5257-
char *options, *tmp_options, *name;
5258-
int m, n;
5259-
u8 reset_methods[PCI_NUM_RESET_METHODS] = { 0 };
5260-
5261-
if (sysfs_streq(buf, "")) {
5262-
pdev->reset_methods[0] = 0;
5263-
pci_warn(pdev, "All device reset methods disabled by user");
5264-
return count;
5265-
}
5266-
5267-
if (sysfs_streq(buf, "default")) {
5268-
pci_init_reset_methods(pdev);
5269-
return count;
5270-
}
5271-
5272-
options = kstrndup(buf, count, GFP_KERNEL);
5273-
if (!options)
5274-
return -ENOMEM;
5275-
5276-
n = 0;
5277-
tmp_options = options;
5278-
while ((name = strsep(&tmp_options, " ")) != NULL) {
5279-
if (sysfs_streq(name, ""))
5280-
continue;
5281-
5282-
name = strim(name);
5283-
5284-
m = reset_method_lookup(name);
5285-
if (!m) {
5286-
pci_err(pdev, "Invalid reset method '%s'", name);
5287-
goto error;
5288-
}
5289-
5290-
if (pci_reset_fn_methods[m].reset_fn(pdev, PCI_RESET_PROBE)) {
5291-
pci_err(pdev, "Unsupported reset method '%s'", name);
5292-
goto error;
5293-
}
5294-
5295-
if (n == PCI_NUM_RESET_METHODS - 1) {
5296-
pci_err(pdev, "Too many reset methods\n");
5297-
goto error;
5298-
}
5299-
5300-
reset_methods[n++] = m;
5301-
}
5302-
5303-
reset_methods[n] = 0;
5304-
5305-
/* Warn if dev-specific supported but not highest priority */
5306-
if (pci_reset_fn_methods[1].reset_fn(pdev, PCI_RESET_PROBE) == 0 &&
5307-
reset_methods[0] != 1)
5308-
pci_warn(pdev, "Device-specific reset disabled/de-prioritized by user");
5309-
memcpy(pdev->reset_methods, reset_methods, sizeof(pdev->reset_methods));
5310-
kfree(options);
5311-
return count;
5312-
5313-
error:
5314-
/* Leave previous methods unchanged */
5315-
kfree(options);
5316-
return -EINVAL;
5317-
}
5318-
static DEVICE_ATTR_RW(reset_method);
5319-
5320-
static struct attribute *pci_dev_reset_method_attrs[] = {
5321-
&dev_attr_reset_method.attr,
5322-
NULL,
5323-
};
5324-
5325-
static umode_t pci_dev_reset_method_attr_is_visible(struct kobject *kobj,
5326-
struct attribute *a, int n)
5327-
{
5328-
struct pci_dev *pdev = to_pci_dev(kobj_to_dev(kobj));
5329-
5330-
if (!pci_reset_supported(pdev))
5331-
return 0;
5332-
5333-
return a->mode;
5334-
}
5335-
5336-
const struct attribute_group pci_dev_reset_method_attr_group = {
5337-
.attrs = pci_dev_reset_method_attrs,
5338-
.is_visible = pci_dev_reset_method_attr_is_visible,
5339-
};
5340-
53415218
/**
53425219
* __pci_reset_function_locked - reset a PCI device function while holding
53435220
* the @dev mutex lock.

drivers/pci/pci.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,7 @@ struct pci_reset_fn_method {
766766
int (*reset_fn)(struct pci_dev *pdev, bool probe);
767767
char *name;
768768
};
769+
extern const struct pci_reset_fn_method pci_reset_fn_methods[];
769770

770771
#ifdef CONFIG_PCI_QUIRKS
771772
int pci_dev_specific_reset(struct pci_dev *dev, bool probe);
@@ -960,8 +961,6 @@ static inline pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
960961
extern const struct attribute_group aspm_ctrl_attr_group;
961962
#endif
962963

963-
extern const struct attribute_group pci_dev_reset_method_attr_group;
964-
965964
#ifdef CONFIG_X86_INTEL_MID
966965
bool pci_use_mid_pm(void);
967966
int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state);

0 commit comments

Comments
 (0)