2 * Enables/disables PCIe ECRC checking.
4 * (C) Copyright 2009 Hewlett-Packard Development Company, L.P.
5 * Andrew Patterson <andrew.patterson@hp.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <linux/pci.h>
27 #include <linux/pci_regs.h>
28 #include <linux/errno.h>
29 #include "../../pci.h"
31 #define ECRC_POLICY_DEFAULT 0 /* ECRC set by BIOS */
32 #define ECRC_POLICY_OFF 1 /* ECRC off for performance */
33 #define ECRC_POLICY_ON 2 /* ECRC on for data integrity */
35 static int ecrc_policy
= ECRC_POLICY_DEFAULT
;
37 static const char *ecrc_policy_str
[] = {
38 [ECRC_POLICY_DEFAULT
] = "bios",
39 [ECRC_POLICY_OFF
] = "off",
40 [ECRC_POLICY_ON
] = "on"
44 * enable_ercr_checking - enable PCIe ECRC checking for a device
45 * @dev: the PCI device
47 * Returns 0 on success, or negative on failure.
49 static int enable_ecrc_checking(struct pci_dev
*dev
)
57 pos
= pci_find_ext_capability(dev
, PCI_EXT_CAP_ID_ERR
);
61 pci_read_config_dword(dev
, pos
+ PCI_ERR_CAP
, ®32
);
62 if (reg32
& PCI_ERR_CAP_ECRC_GENC
)
63 reg32
|= PCI_ERR_CAP_ECRC_GENE
;
64 if (reg32
& PCI_ERR_CAP_ECRC_CHKC
)
65 reg32
|= PCI_ERR_CAP_ECRC_CHKE
;
66 pci_write_config_dword(dev
, pos
+ PCI_ERR_CAP
, reg32
);
72 * disable_ercr_checking - disables PCIe ECRC checking for a device
73 * @dev: the PCI device
75 * Returns 0 on success, or negative on failure.
77 static int disable_ecrc_checking(struct pci_dev
*dev
)
85 pos
= pci_find_ext_capability(dev
, PCI_EXT_CAP_ID_ERR
);
89 pci_read_config_dword(dev
, pos
+ PCI_ERR_CAP
, ®32
);
90 reg32
&= ~(PCI_ERR_CAP_ECRC_GENE
| PCI_ERR_CAP_ECRC_CHKE
);
91 pci_write_config_dword(dev
, pos
+ PCI_ERR_CAP
, reg32
);
97 * pcie_set_ecrc_checking - set/unset PCIe ECRC checking for a device based on global policy
98 * @dev: the PCI device
100 void pcie_set_ecrc_checking(struct pci_dev
*dev
)
102 switch (ecrc_policy
) {
103 case ECRC_POLICY_DEFAULT
:
105 case ECRC_POLICY_OFF
:
106 disable_ecrc_checking(dev
);
109 enable_ecrc_checking(dev
);
117 * pcie_ecrc_get_policy - parse kernel command-line ecrc option
119 void pcie_ecrc_get_policy(char *str
)
123 for (i
= 0; i
< ARRAY_SIZE(ecrc_policy_str
); i
++)
124 if (!strncmp(str
, ecrc_policy_str
[i
],
125 strlen(ecrc_policy_str
[i
])))
127 if (i
>= ARRAY_SIZE(ecrc_policy_str
))