Skip to content

Commit 7a45330

Browse files
committed
ipmi_si: Move hardcode handling to a separate file.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
1 parent 44814ec commit 7a45330

4 files changed

Lines changed: 154 additions & 147 deletions

File tree

‎drivers/char/ipmi/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
ipmi_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
77

88
obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o
99
obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o

‎drivers/char/ipmi/ipmi_si.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ void ipmi_irq_finish_setup(struct si_sm_io *io);
2222
int ipmi_si_remove_by_dev(struct device *dev);
2323
void ipmi_si_remove_by_data(int addr_space, enum si_type si_type,
2424
unsigned long addr);
25+
int ipmi_si_hardcode_find_bmc(void);
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
13+
static char *si_type[SI_MAX_PARMS];
14+
#define MAX_SI_TYPE_STR 30
15+
static char si_type_str[MAX_SI_TYPE_STR];
16+
static unsigned long addrs[SI_MAX_PARMS];
17+
static unsigned int num_addrs;
18+
static unsigned int ports[SI_MAX_PARMS];
19+
static unsigned int num_ports;
20+
static int irqs[SI_MAX_PARMS];
21+
static unsigned int num_irqs;
22+
static int regspacings[SI_MAX_PARMS];
23+
static unsigned int num_regspacings;
24+
static int regsizes[SI_MAX_PARMS];
25+
static unsigned int num_regsizes;
26+
static int regshifts[SI_MAX_PARMS];
27+
static unsigned int num_regshifts;
28+
static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */
29+
static unsigned int num_slave_addrs;
30+
31+
module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
32+
MODULE_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");
36+
module_param_hw_array(addrs, ulong, iomem, &num_addrs, 0);
37+
MODULE_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.");
41+
module_param_hw_array(ports, uint, ioport, &num_ports, 0);
42+
MODULE_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.");
46+
module_param_hw_array(irqs, int, irq, &num_irqs, 0);
47+
MODULE_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.");
51+
module_param_hw_array(regspacings, int, other, &num_regspacings, 0);
52+
MODULE_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.");
57+
module_param_hw_array(regsizes, int, other, &num_regsizes, 0);
58+
MODULE_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.");
63+
module_param_hw_array(regshifts, int, other, &num_regshifts, 0);
64+
MODULE_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");
68+
module_param_hw_array(slave_addrs, int, other, &num_slave_addrs, 0);
69+
MODULE_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+
74+
int 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+
}

‎drivers/char/ipmi/ipmi_si_intf.c‎

Lines changed: 6 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,8 @@ struct smi_info {
291291
#define smi_get_stat(smi, stat) \
292292
((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
293293

294-
#define SI_MAX_PARMS 4
295-
296-
static int force_kipmid[SI_MAX_PARMS];
294+
#define IPMI_MAX_INTFS 4
295+
static int force_kipmid[IPMI_MAX_INTFS];
297296
static int num_force_kipmid;
298297
#ifdef CONFIG_PCI
299298
static bool pci_registered;
@@ -302,7 +301,7 @@ static bool pci_registered;
302301
static bool parisc_registered;
303302
#endif
304303

305-
static unsigned int kipmid_max_busy_us[SI_MAX_PARMS];
304+
static unsigned int kipmid_max_busy_us[IPMI_MAX_INTFS];
306305
static int num_max_busy_us;
307306

308307
static bool unload_when_empty = true;
@@ -1271,11 +1270,6 @@ static const struct ipmi_smi_handlers handlers = {
12711270
.poll = poll,
12721271
};
12731272

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-
12791273
static LIST_HEAD(smi_infos);
12801274
static DEFINE_MUTEX(smi_infos_lock);
12811275
static int smi_num; /* Used to sequence the SMIs */
@@ -1290,23 +1284,6 @@ static bool si_tryplatform = true;
12901284
#ifdef CONFIG_PCI
12911285
static bool si_trypci = true;
12921286
#endif
1293-
static char *si_type[SI_MAX_PARMS];
1294-
#define MAX_SI_TYPE_STR 30
1295-
static char si_type_str[MAX_SI_TYPE_STR];
1296-
static unsigned long addrs[SI_MAX_PARMS];
1297-
static unsigned int num_addrs;
1298-
static unsigned int ports[SI_MAX_PARMS];
1299-
static unsigned int num_ports;
1300-
static int irqs[SI_MAX_PARMS];
1301-
static unsigned int num_irqs;
1302-
static int regspacings[SI_MAX_PARMS];
1303-
static unsigned int num_regspacings;
1304-
static int regsizes[SI_MAX_PARMS];
1305-
static unsigned int num_regsizes;
1306-
static int regshifts[SI_MAX_PARMS];
1307-
static unsigned int num_regshifts;
1308-
static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */
1309-
static unsigned int num_slave_addrs;
13101287

13111288
static const char * const addr_space_to_str[] = { "i/o", "mem" };
13121289

@@ -1329,48 +1306,6 @@ module_param_named(trypci, si_trypci, bool, 0);
13291306
MODULE_PARM_DESC(trypci, "Setting this to zero will disable the"
13301307
" default scan of the interfaces identified via pci");
13311308
#endif
1332-
module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0);
1333-
MODULE_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");
1337-
module_param_hw_array(addrs, ulong, iomem, &num_addrs, 0);
1338-
MODULE_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.");
1342-
module_param_hw_array(ports, uint, ioport, &num_ports, 0);
1343-
MODULE_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.");
1347-
module_param_hw_array(irqs, int, irq, &num_irqs, 0);
1348-
MODULE_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.");
1352-
module_param_hw_array(regspacings, int, other, &num_regspacings, 0);
1353-
MODULE_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.");
1358-
module_param_hw_array(regsizes, int, other, &num_regsizes, 0);
1359-
MODULE_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.");
1364-
module_param_hw_array(regshifts, int, other, &num_regshifts, 0);
1365-
MODULE_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");
1369-
module_param_hw_array(slave_addrs, int, other, &num_slave_addrs, 0);
1370-
MODULE_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.");
13741309
module_param_array(force_kipmid, int, &num_force_kipmid, 0);
13751310
MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or"
13761311
" disabled(0). Normally the IPMI driver auto-detects"
@@ -1691,64 +1626,6 @@ static struct smi_info *smi_info_alloc(void)
16911626
return info;
16921627
}
16931628

1694-
static 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-
17521629
#ifdef CONFIG_ACPI
17531630

17541631
/*
@@ -3349,8 +3226,6 @@ static int try_smi_init(struct smi_info *new_smi)
33493226

33503227
static int init_ipmi_si(void)
33513228
{
3352-
int i;
3353-
char *str;
33543229
int rv;
33553230
struct smi_info *e;
33563231
enum ipmi_addr_src type = SI_INVALID;
@@ -3366,26 +3241,11 @@ static int init_ipmi_si(void)
33663241
}
33673242
}
33683243

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-
33843244
pr_info("IPMI System Interface driver.\n");
33853245

33863246
/* If the user gave us a device, they presumably want us to use it */
3387-
if (!hardcode_find_bmc())
3388-
return 0;
3247+
if (!ipmi_si_hardcode_find_bmc())
3248+
goto do_scan;
33893249

33903250
#ifdef CONFIG_PCI
33913251
if (si_trypci) {
@@ -3411,7 +3271,7 @@ static int init_ipmi_si(void)
34113271
with multiple BMCs we assume that there will be several instances
34123272
of a given type so if we succeed in registering a type then also
34133273
try to register everything else of the same type */
3414-
3274+
do_scan:
34153275
mutex_lock(&smi_infos_lock);
34163276
list_for_each_entry(e, &smi_infos, link) {
34173277
/* Try to register a device if it has an IRQ and we either

0 commit comments

Comments
 (0)