aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCorey Minyard <cminyard@mvista.com>2017-09-12 23:46:29 -0400
committerCorey Minyard <cminyard@mvista.com>2017-09-27 17:03:45 -0400
commit7a4533087ccbf736396bcbf816e0e45266c4313b (patch)
tree8587e0a7c3b63b4783aec4754f281fc7414e76ce
parent44814ec982d2905d50fe4d0cdaf693b76afe7f64 (diff)
ipmi_si: Move hardcode handling to a separate file.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
-rw-r--r--drivers/char/ipmi/Makefile2
-rw-r--r--drivers/char/ipmi/ipmi_si.h1
-rw-r--r--drivers/char/ipmi/ipmi_si_hardcode.c146
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c152
4 files changed, 154 insertions, 147 deletions
diff --git a/drivers/char/ipmi/Makefile b/drivers/char/ipmi/Makefile
index 61c7d5d32f4a..ebd728497b23 100644
--- a/drivers/char/ipmi/Makefile
+++ b/drivers/char/ipmi/Makefile
@@ -3,7 +3,7 @@
3# 3#
4 4
5ipmi_si-y := ipmi_si_intf.o ipmi_kcs_sm.o ipmi_smic_sm.o ipmi_bt_sm.o \ 5ipmi_si-y := ipmi_si_intf.o ipmi_kcs_sm.o ipmi_smic_sm.o ipmi_bt_sm.o \
6 ipmi_si_hotmod.o 6 ipmi_si_hotmod.o ipmi_si_hardcode.o
7 7
8obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o 8obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o
9obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o 9obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o
diff --git a/drivers/char/ipmi/ipmi_si.h b/drivers/char/ipmi/ipmi_si.h
index 4ceb5ac3ad98..1dbd58afc2d7 100644
--- a/drivers/char/ipmi/ipmi_si.h
+++ b/drivers/char/ipmi/ipmi_si.h
@@ -22,3 +22,4 @@ void ipmi_irq_finish_setup(struct si_sm_io *io);
22int ipmi_si_remove_by_dev(struct device *dev); 22int ipmi_si_remove_by_dev(struct device *dev);
23void ipmi_si_remove_by_data(int addr_space, enum si_type si_type, 23void ipmi_si_remove_by_data(int addr_space, enum si_type si_type,
24 unsigned long addr); 24 unsigned long addr);
25int ipmi_si_hardcode_find_bmc(void);
diff --git a/drivers/char/ipmi/ipmi_si_hardcode.c b/drivers/char/ipmi/ipmi_si_hardcode.c
new file mode 100644
index 000000000000..fa9a4780de36
--- /dev/null
+++ b/drivers/char/ipmi/ipmi_si_hardcode.c
@@ -0,0 +1,146 @@
1
2#include <linux/moduleparam.h>
3#include "ipmi_si.h"
4
5#define PFX "ipmi_hardcode: "
6/*
7 * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
8 * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS.
9 */
10
11#define SI_MAX_PARMS 4
12
13static char *si_type[SI_MAX_PARMS];
14#define MAX_SI_TYPE_STR 30
15static char si_type_str[MAX_SI_TYPE_STR];
16static unsigned long addrs[SI_MAX_PARMS];
17static unsigned int num_addrs;
18static unsigned int ports[SI_MAX_PARMS];
19static unsigned int num_ports;
20static int irqs[SI_MAX_PARMS];
21static unsigned int num_irqs;
22static int regspacings[SI_MAX_PARMS];
23static unsigned int num_regspacings;
24static int regsizes[SI_MAX_PARMS];
25static unsigned int num_regsizes;
26static int regshifts[SI_MAX_PARMS];
27static unsigned int num_regshifts;
28static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */
29static unsigned int num_slave_addrs;
30
31module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
32MODULE_PARM_DESC(type, "Defines the type of each interface, each"
33 " interface separated by commas. The types are 'kcs',"
34 " 'smic', and 'bt'. For example si_type=kcs,bt will set"
35 " the first interface to kcs and the second to bt");
36module_param_hw_array(addrs, ulong, iomem, &num_addrs, 0);
37MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the"
38 " addresses separated by commas. Only use if an interface"
39 " is in memory. Otherwise, set it to zero or leave"
40 " it blank.");
41module_param_hw_array(ports, uint, ioport, &num_ports, 0);
42MODULE_PARM_DESC(ports, "Sets the port address of each interface, the"
43 " addresses separated by commas. Only use if an interface"
44 " is a port. Otherwise, set it to zero or leave"
45 " it blank.");
46module_param_hw_array(irqs, int, irq, &num_irqs, 0);
47MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the"
48 " addresses separated by commas. Only use if an interface"
49 " has an interrupt. Otherwise, set it to zero or leave"
50 " it blank.");
51module_param_hw_array(regspacings, int, other, &num_regspacings, 0);
52MODULE_PARM_DESC(regspacings, "The number of bytes between the start address"
53 " and each successive register used by the interface. For"
54 " instance, if the start address is 0xca2 and the spacing"
55 " is 2, then the second address is at 0xca4. Defaults"
56 " to 1.");
57module_param_hw_array(regsizes, int, other, &num_regsizes, 0);
58MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes."
59 " This should generally be 1, 2, 4, or 8 for an 8-bit,"
60 " 16-bit, 32-bit, or 64-bit register. Use this if you"
61 " the 8-bit IPMI register has to be read from a larger"
62 " register.");
63module_param_hw_array(regshifts, int, other, &num_regshifts, 0);
64MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the."
65 " IPMI register, in bits. For instance, if the data"
66 " is read from a 32-bit word and the IPMI data is in"
67 " bit 8-15, then the shift would be 8");
68module_param_hw_array(slave_addrs, int, other, &num_slave_addrs, 0);
69MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
70 " the controller. Normally this is 0x20, but can be"
71 " overridden by this parm. This is an array indexed"
72 " by interface number.");
73
74int ipmi_si_hardcode_find_bmc(void)
75{
76 int ret = -ENODEV;
77 int i;
78 struct si_sm_io io;
79 char *str;
80
81 /* Parse out the si_type string into its components. */
82 str = si_type_str;
83 if (*str != '\0') {
84 for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
85 si_type[i] = str;
86 str = strchr(str, ',');
87 if (str) {
88 *str = '\0';
89 str++;
90 } else {
91 break;
92 }
93 }
94 }
95
96 memset(&io, 0, sizeof(io));
97 for (i = 0; i < SI_MAX_PARMS; i++) {
98 if (!ports[i] && !addrs[i])
99 continue;
100
101 io.addr_source = SI_HARDCODED;
102 pr_info(PFX "probing via hardcoded address\n");
103
104 if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
105 io.si_type = SI_KCS;
106 } else if (strcmp(si_type[i], "smic") == 0) {
107 io.si_type = SI_SMIC;
108 } else if (strcmp(si_type[i], "bt") == 0) {
109 io.si_type = SI_BT;
110 } else {
111 pr_warn(PFX "Interface type specified for interface %d, was invalid: %s\n",
112 i, si_type[i]);
113 continue;
114 }
115
116 if (ports[i]) {
117 /* An I/O port */
118 io.addr_data = ports[i];
119 io.addr_type = IPMI_IO_ADDR_SPACE;
120 } else if (addrs[i]) {
121 /* A memory port */
122 io.addr_data = addrs[i];
123 io.addr_type = IPMI_MEM_ADDR_SPACE;
124 } else {
125 pr_warn(PFX "Interface type specified for interface %d, but port and address were not set or set to zero.\n",
126 i);
127 continue;
128 }
129
130 io.addr = NULL;
131 io.regspacing = regspacings[i];
132 if (!io.regspacing)
133 io.regspacing = DEFAULT_REGSPACING;
134 io.regsize = regsizes[i];
135 if (!io.regsize)
136 io.regsize = DEFAULT_REGSIZE;
137 io.regshift = regshifts[i];
138 io.irq = irqs[i];
139 if (io.irq)
140 io.irq_setup = ipmi_std_irq_setup;
141 io.slave_addr = slave_addrs[i];
142
143 ret = ipmi_si_add_smi(&io);
144 }
145 return ret;
146}
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 02e263b2152a..58f0ebbcd342 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -291,9 +291,8 @@ struct smi_info {
291#define smi_get_stat(smi, stat) \ 291#define smi_get_stat(smi, stat) \
292 ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat])) 292 ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
293 293
294#define SI_MAX_PARMS 4 294#define IPMI_MAX_INTFS 4
295 295static int force_kipmid[IPMI_MAX_INTFS];
296static int force_kipmid[SI_MAX_PARMS];
297static int num_force_kipmid; 296static int num_force_kipmid;
298#ifdef CONFIG_PCI 297#ifdef CONFIG_PCI
299static bool pci_registered; 298static bool pci_registered;
@@ -302,7 +301,7 @@ static bool pci_registered;
302static bool parisc_registered; 301static bool parisc_registered;
303#endif 302#endif
304 303
305static unsigned int kipmid_max_busy_us[SI_MAX_PARMS]; 304static unsigned int kipmid_max_busy_us[IPMI_MAX_INTFS];
306static int num_max_busy_us; 305static int num_max_busy_us;
307 306
308static bool unload_when_empty = true; 307static bool unload_when_empty = true;
@@ -1271,11 +1270,6 @@ static const struct ipmi_smi_handlers handlers = {
1271 .poll = poll, 1270 .poll = poll,
1272}; 1271};
1273 1272
1274/*
1275 * There can be 4 IO ports passed in (with or without IRQs), 4 addresses,
1276 * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS.
1277 */
1278
1279static LIST_HEAD(smi_infos); 1273static LIST_HEAD(smi_infos);
1280static DEFINE_MUTEX(smi_infos_lock); 1274static DEFINE_MUTEX(smi_infos_lock);
1281static int smi_num; /* Used to sequence the SMIs */ 1275static int smi_num; /* Used to sequence the SMIs */
@@ -1290,23 +1284,6 @@ static bool si_tryplatform = true;
1290#ifdef CONFIG_PCI 1284#ifdef CONFIG_PCI
1291static bool si_trypci = true; 1285static bool si_trypci = true;
1292#endif 1286#endif
1293static char *si_type[SI_MAX_PARMS];
1294#define MAX_SI_TYPE_STR 30
1295static char si_type_str[MAX_SI_TYPE_STR];
1296static unsigned long addrs[SI_MAX_PARMS];
1297static unsigned int num_addrs;
1298static unsigned int ports[SI_MAX_PARMS];
1299static unsigned int num_ports;
1300static int irqs[SI_MAX_PARMS];
1301static unsigned int num_irqs;
1302static int regspacings[SI_MAX_PARMS];
1303static unsigned int num_regspacings;
1304static int regsizes[SI_MAX_PARMS];
1305static unsigned int num_regsizes;
1306static int regshifts[SI_MAX_PARMS];
1307static unsigned int num_regshifts;
1308static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */
1309static unsigned int num_slave_addrs;
1310 1287
1311static const char * const addr_space_to_str[] = { "i/o", "mem" }; 1288static const char * const addr_space_to_str[] = { "i/o", "mem" };
1312 1289
@@ -1329,48 +1306,6 @@ module_param_named(trypci, si_trypci, bool, 0);
1329MODULE_PARM_DESC(trypci, "Setting this to zero will disable the" 1306MODULE_PARM_DESC(trypci, "Setting this to zero will disable the"
1330 " default scan of the interfaces identified via pci"); 1307 " default scan of the interfaces identified via pci");
1331#endif 1308#endif
1332module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
1333MODULE_PARM_DESC(type, "Defines the type of each interface, each"
1334 " interface separated by commas. The types are 'kcs',"
1335 " 'smic', and 'bt'. For example si_type=kcs,bt will set"
1336 " the first interface to kcs and the second to bt");
1337module_param_hw_array(addrs, ulong, iomem, &num_addrs, 0);
1338MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the"
1339 " addresses separated by commas. Only use if an interface"
1340 " is in memory. Otherwise, set it to zero or leave"
1341 " it blank.");
1342module_param_hw_array(ports, uint, ioport, &num_ports, 0);
1343MODULE_PARM_DESC(ports, "Sets the port address of each interface, the"
1344 " addresses separated by commas. Only use if an interface"
1345 " is a port. Otherwise, set it to zero or leave"
1346 " it blank.");
1347module_param_hw_array(irqs, int, irq, &num_irqs, 0);
1348MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the"
1349 " addresses separated by commas. Only use if an interface"
1350 " has an interrupt. Otherwise, set it to zero or leave"
1351 " it blank.");
1352module_param_hw_array(regspacings, int, other, &num_regspacings, 0);
1353MODULE_PARM_DESC(regspacings, "The number of bytes between the start address"
1354 " and each successive register used by the interface. For"
1355 " instance, if the start address is 0xca2 and the spacing"
1356 " is 2, then the second address is at 0xca4. Defaults"
1357 " to 1.");
1358module_param_hw_array(regsizes, int, other, &num_regsizes, 0);
1359MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes."
1360 " This should generally be 1, 2, 4, or 8 for an 8-bit,"
1361 " 16-bit, 32-bit, or 64-bit register. Use this if you"
1362 " the 8-bit IPMI register has to be read from a larger"
1363 " register.");
1364module_param_hw_array(regshifts, int, other, &num_regshifts, 0);
1365MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the."
1366 " IPMI register, in bits. For instance, if the data"
1367 " is read from a 32-bit word and the IPMI data is in"
1368 " bit 8-15, then the shift would be 8");
1369module_param_hw_array(slave_addrs, int, other, &num_slave_addrs, 0);
1370MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for"
1371 " the controller. Normally this is 0x20, but can be"
1372 " overridden by this parm. This is an array indexed"
1373 " by interface number.");
1374module_param_array(force_kipmid, int, &num_force_kipmid, 0); 1309module_param_array(force_kipmid, int, &num_force_kipmid, 0);
1375MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or" 1310MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"
1376 " disabled(0). Normally the IPMI driver auto-detects" 1311 " disabled(0). Normally the IPMI driver auto-detects"
@@ -1691,64 +1626,6 @@ static struct smi_info *smi_info_alloc(void)
1691 return info; 1626 return info;
1692} 1627}
1693 1628
1694static int hardcode_find_bmc(void)
1695{
1696 int ret = -ENODEV;
1697 int i;
1698 struct si_sm_io io;
1699
1700 memset(&io, 0, sizeof(io));
1701 for (i = 0; i < SI_MAX_PARMS; i++) {
1702 if (!ports[i] && !addrs[i])
1703 continue;
1704
1705 io.addr_source = SI_HARDCODED;
1706 pr_info(PFX "probing via hardcoded address\n");
1707
1708 if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) {
1709 io.si_type = SI_KCS;
1710 } else if (strcmp(si_type[i], "smic") == 0) {
1711 io.si_type = SI_SMIC;
1712 } else if (strcmp(si_type[i], "bt") == 0) {
1713 io.si_type = SI_BT;
1714 } else {
1715 pr_warn(PFX "Interface type specified for interface %d, was invalid: %s\n",
1716 i, si_type[i]);
1717 continue;
1718 }
1719
1720 if (ports[i]) {
1721 /* An I/O port */
1722 io.addr_data = ports[i];
1723 io.addr_type = IPMI_IO_ADDR_SPACE;
1724 } else if (addrs[i]) {
1725 /* A memory port */
1726 io.addr_data = addrs[i];
1727 io.addr_type = IPMI_MEM_ADDR_SPACE;
1728 } else {
1729 pr_warn(PFX "Interface type specified for interface %d, but port and address were not set or set to zero.\n",
1730 i);
1731 continue;
1732 }
1733
1734 io.addr = NULL;
1735 io.regspacing = regspacings[i];
1736 if (!io.regspacing)
1737 io.regspacing = DEFAULT_REGSPACING;
1738 io.regsize = regsizes[i];
1739 if (!io.regsize)
1740 io.regsize = DEFAULT_REGSIZE;
1741 io.regshift = regshifts[i];
1742 io.irq = irqs[i];
1743 if (io.irq)
1744 io.irq_setup = ipmi_std_irq_setup;
1745 io.slave_addr = slave_addrs[i];
1746
1747 ret = ipmi_si_add_smi(&io);
1748 }
1749 return ret;
1750}
1751
1752#ifdef CONFIG_ACPI 1629#ifdef CONFIG_ACPI
1753 1630
1754/* 1631/*
@@ -3349,8 +3226,6 @@ out_err:
3349 3226
3350static int init_ipmi_si(void) 3227static int init_ipmi_si(void)
3351{ 3228{
3352 int i;
3353 char *str;
3354 int rv; 3229 int rv;
3355 struct smi_info *e; 3230 struct smi_info *e;
3356 enum ipmi_addr_src type = SI_INVALID; 3231 enum ipmi_addr_src type = SI_INVALID;
@@ -3366,26 +3241,11 @@ static int init_ipmi_si(void)
3366 } 3241 }
3367 } 3242 }
3368 3243
3369 /* Parse out the si_type string into its components. */
3370 str = si_type_str;
3371 if (*str != '\0') {
3372 for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) {
3373 si_type[i] = str;
3374 str = strchr(str, ',');
3375 if (str) {
3376 *str = '\0';
3377 str++;
3378 } else {
3379 break;
3380 }
3381 }
3382 }
3383
3384 pr_info("IPMI System Interface driver.\n"); 3244 pr_info("IPMI System Interface driver.\n");
3385 3245
3386 /* If the user gave us a device, they presumably want us to use it */ 3246 /* If the user gave us a device, they presumably want us to use it */
3387 if (!hardcode_find_bmc()) 3247 if (!ipmi_si_hardcode_find_bmc())
3388 return 0; 3248 goto do_scan;
3389 3249
3390#ifdef CONFIG_PCI 3250#ifdef CONFIG_PCI
3391 if (si_trypci) { 3251 if (si_trypci) {
@@ -3411,7 +3271,7 @@ static int init_ipmi_si(void)
3411 with multiple BMCs we assume that there will be several instances 3271 with multiple BMCs we assume that there will be several instances
3412 of a given type so if we succeed in registering a type then also 3272 of a given type so if we succeed in registering a type then also
3413 try to register everything else of the same type */ 3273 try to register everything else of the same type */
3414 3274do_scan:
3415 mutex_lock(&smi_infos_lock); 3275 mutex_lock(&smi_infos_lock);
3416 list_for_each_entry(e, &smi_infos, link) { 3276 list_for_each_entry(e, &smi_infos, link) {
3417 /* Try to register a device if it has an IRQ and we either 3277 /* Try to register a device if it has an IRQ and we either