Commit 7c9e2b1c authored by Dean Nelson's avatar Dean Nelson Committed by Jesse Barnes

PCI: cleanup error return for pcix get and set mmrbc functions

pcix_get_mmrbc() returns the maximum memory read byte count (mmrbc), if
successful, or an appropriate error value, if not.

Distinguishing errors from correct values and understanding the meaning of an
error can be somewhat confusing in that:

	correct values: 512, 1024, 2048, 4096
	errors: -EINVAL  			-22
 		PCIBIOS_FUNC_NOT_SUPPORTED	0x81
		PCIBIOS_BAD_VENDOR_ID		0x83
		PCIBIOS_DEVICE_NOT_FOUND	0x86
		PCIBIOS_BAD_REGISTER_NUMBER	0x87
		PCIBIOS_SET_FAILED		0x88
		PCIBIOS_BUFFER_TOO_SMALL	0x89

The PCIBIOS_ errors are returned from the PCI functions generated by the
PCI_OP_READ() and PCI_OP_WRITE() macros.

In a similar manner, pcix_set_mmrbc() also returns the PCIBIOS_ error values
returned from pci_read_config_[word|dword]() and pci_write_config_word().

Following pcix_get_max_mmrbc()'s example, the following patch simply returns
-EINVAL for all PCIBIOS_ errors encountered by pcix_get_mmrbc(), and -EINVAL
or -EIO for those encountered by pcix_set_mmrbc().

This simplification was chosen in light of the fact that none of the current
callers of these functions are interested in the specific type of error
encountered. In the future, should this change, one could simply create a
function that maps each PCIBIOS_ error to a corresponding unique errno value,
which could be called by pcix_get_max_mmrbc(), pcix_get_mmrbc(), and
pcix_set_mmrbc().

Additionally, this patch eliminates some unnecessary variables.

Cc: stable@kernel.org
Signed-off-by: default avatarDean Nelson <dnelson@redhat.com>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent bdc2bda7
...@@ -2576,15 +2576,14 @@ EXPORT_SYMBOL_GPL(pci_reset_function); ...@@ -2576,15 +2576,14 @@ EXPORT_SYMBOL_GPL(pci_reset_function);
*/ */
int pcix_get_max_mmrbc(struct pci_dev *dev) int pcix_get_max_mmrbc(struct pci_dev *dev)
{ {
int err, cap; int cap;
u32 stat; u32 stat;
cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
if (!cap) if (!cap)
return -EINVAL; return -EINVAL;
err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat); if (pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat))
if (err)
return -EINVAL; return -EINVAL;
return 512 << ((stat & PCI_X_STATUS_MAX_READ) >> 21); return 512 << ((stat & PCI_X_STATUS_MAX_READ) >> 21);
...@@ -2600,18 +2599,17 @@ EXPORT_SYMBOL(pcix_get_max_mmrbc); ...@@ -2600,18 +2599,17 @@ EXPORT_SYMBOL(pcix_get_max_mmrbc);
*/ */
int pcix_get_mmrbc(struct pci_dev *dev) int pcix_get_mmrbc(struct pci_dev *dev)
{ {
int ret, cap; int cap;
u16 cmd; u16 cmd;
cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
if (!cap) if (!cap)
return -EINVAL; return -EINVAL;
ret = pci_read_config_word(dev, cap + PCI_X_CMD, &cmd); if (pci_read_config_word(dev, cap + PCI_X_CMD, &cmd))
if (!ret) return -EINVAL;
ret = 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2);
return ret; return 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2);
} }
EXPORT_SYMBOL(pcix_get_mmrbc); EXPORT_SYMBOL(pcix_get_mmrbc);
...@@ -2626,29 +2624,27 @@ EXPORT_SYMBOL(pcix_get_mmrbc); ...@@ -2626,29 +2624,27 @@ EXPORT_SYMBOL(pcix_get_mmrbc);
*/ */
int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc) int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc)
{ {
int cap, err = -EINVAL; int cap;
u32 stat, v, o; u32 stat, v, o;
u16 cmd; u16 cmd;
if (mmrbc < 512 || mmrbc > 4096 || !is_power_of_2(mmrbc)) if (mmrbc < 512 || mmrbc > 4096 || !is_power_of_2(mmrbc))
goto out; return -EINVAL;
v = ffs(mmrbc) - 10; v = ffs(mmrbc) - 10;
cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); cap = pci_find_capability(dev, PCI_CAP_ID_PCIX);
if (!cap) if (!cap)
goto out; return -EINVAL;
err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat); if (pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat))
if (err) return -EINVAL;
goto out;
if (v > (stat & PCI_X_STATUS_MAX_READ) >> 21) if (v > (stat & PCI_X_STATUS_MAX_READ) >> 21)
return -E2BIG; return -E2BIG;
err = pci_read_config_word(dev, cap + PCI_X_CMD, &cmd); if (pci_read_config_word(dev, cap + PCI_X_CMD, &cmd))
if (err) return -EINVAL;
goto out;
o = (cmd & PCI_X_CMD_MAX_READ) >> 2; o = (cmd & PCI_X_CMD_MAX_READ) >> 2;
if (o != v) { if (o != v) {
...@@ -2658,10 +2654,10 @@ int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc) ...@@ -2658,10 +2654,10 @@ int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc)
cmd &= ~PCI_X_CMD_MAX_READ; cmd &= ~PCI_X_CMD_MAX_READ;
cmd |= v << 2; cmd |= v << 2;
err = pci_write_config_word(dev, cap + PCI_X_CMD, cmd); if (pci_write_config_word(dev, cap + PCI_X_CMD, cmd))
return -EIO;
} }
out: return 0;
return err;
} }
EXPORT_SYMBOL(pcix_set_mmrbc); EXPORT_SYMBOL(pcix_set_mmrbc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment