42 #include <linux/module.h>
44 #include <linux/sched.h>
47 #include <linux/errno.h>
49 #include <linux/slab.h>
51 #include <linux/list.h>
52 #include <linux/pci.h>
60 #include <linux/ipmi.h>
66 #include <linux/string.h>
67 #include <linux/ctype.h>
74 #define PFX "ipmi_si: "
80 #define SI_TIMEOUT_TIME_USEC 10000
81 #define SI_USEC_PER_JIFFY (1000000/HZ)
82 #define SI_TIMEOUT_JIFFIES (SI_TIMEOUT_TIME_USEC/SI_USEC_PER_JIFFY)
83 #define SI_SHORT_TIMEOUT_USEC 250
101 #define IPMI_BT_INTMASK_REG 2
102 #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2
103 #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1
108 static char *si_to_str[] = {
"kcs",
"smic",
"bt" };
110 static char *ipmi_addr_src_to_str[] = {
NULL,
"hotmod",
"hardcoded",
"SPMI",
111 "ACPI",
"SMBIOS",
"PCI",
112 "device-tree",
"default" };
114 #define DEVICE_NAME "ipmi_si"
204 #define RECEIVE_MSG_AVAIL 0x01
205 #define EVENT_MSG_BUFFER_FULL 0x02
206 #define WDT_PRE_TIMEOUT_INT 0x08
207 #define OEM0_DATA_AVAIL 0x20
208 #define OEM1_DATA_AVAIL 0x40
209 #define OEM2_DATA_AVAIL 0x80
210 #define OEM_DATA_AVAIL (OEM0_DATA_AVAIL | \
286 #define smi_inc_stat(smi, stat) \
287 atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
288 #define smi_get_stat(smi, stat) \
289 ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
291 #define SI_MAX_PARMS 4
294 static int num_force_kipmid;
296 static int pci_registered;
299 static int pnp_registered;
303 static int num_max_busy_us;
305 static int unload_when_empty = 1;
307 static int add_smi(
struct smi_info *smi);
308 static int try_smi_init(
struct smi_info *smi);
309 static void cleanup_one_si(
struct smi_info *to_clean);
310 static void cleanup_ipmi_si(
void);
334 msg->
rsp[0] = msg->
data[0] | 4;
340 deliver_recv_msg(smi_info, msg);
343 static enum si_sm_result start_next_msg(
struct smi_info *smi_info)
354 }
else if (!list_empty(&(smi_info->
xmit_msgs))) {
374 if (err & NOTIFY_STOP_MASK) {
378 err = smi_info->
handlers->start_transaction(
383 return_hosed_msg(smi_info, err);
391 static void start_enable_irq(
struct smi_info *smi_info)
393 unsigned char msg[2];
402 smi_info->
handlers->start_transaction(smi_info->
si_sm, msg, 2);
406 static void start_disable_irq(
struct smi_info *smi_info)
408 unsigned char msg[2];
413 smi_info->
handlers->start_transaction(smi_info->
si_sm, msg, 2);
417 static void start_clear_flags(
struct smi_info *smi_info)
419 unsigned char msg[3];
426 smi_info->
handlers->start_transaction(smi_info->
si_sm, msg, 3);
436 static inline void disable_si_irq(
struct smi_info *smi_info)
439 start_disable_irq(smi_info);
447 static inline void enable_si_irq(
struct smi_info *smi_info)
450 start_enable_irq(smi_info);
455 static void handle_flags(
struct smi_info *smi_info)
462 start_clear_flags(smi_info);
469 disable_si_irq(smi_info);
473 enable_si_irq(smi_info);
479 smi_info->
handlers->start_transaction(
488 disable_si_irq(smi_info);
492 enable_si_irq(smi_info);
498 smi_info->
handlers->start_transaction(
511 static void handle_transaction_done(
struct smi_info *smi_info)
538 deliver_recv_msg(smi_info, msg);
543 unsigned char msg[4];
547 len = smi_info->
handlers->get_result(smi_info->
si_sm, msg, 4);
551 }
else if (len < 4) {
559 handle_flags(smi_info);
567 unsigned char msg[3];
574 "Error clearing flags: %2.2x\n", msg[2]);
577 start_enable_irq(smi_info);
598 if (msg->rsp[2] != 0) {
604 handle_flags(smi_info);
614 handle_flags(smi_info);
616 deliver_recv_msg(smi_info, msg);
636 if (msg->rsp[2] != 0) {
642 handle_flags(smi_info);
652 handle_flags(smi_info);
654 deliver_recv_msg(smi_info, msg);
661 unsigned char msg[4];
666 dev_warn(smi_info->
dev,
"Could not enable interrupts"
667 ", failed get, using polled mode.\n");
675 smi_info->
handlers->start_transaction(
676 smi_info->
si_sm, msg, 3);
684 unsigned char msg[4];
689 dev_warn(smi_info->
dev,
"Could not enable interrupts"
690 ", failed set, using polled mode.\n");
699 unsigned char msg[4];
704 dev_warn(smi_info->
dev,
"Could not disable interrupts"
713 smi_info->
handlers->start_transaction(
714 smi_info->
si_sm, msg, 3);
722 unsigned char msg[4];
727 dev_warn(smi_info->
dev,
"Could not disable interrupts"
741 static enum si_sm_result smi_event_handler(
struct smi_info *smi_info,
755 si_sm_result = smi_info->
handlers->event(smi_info->
si_sm, time);
758 si_sm_result = smi_info->
handlers->event(smi_info->
si_sm, 0);
763 handle_transaction_done(smi_info);
764 si_sm_result = smi_info->
handlers->event(smi_info->
si_sm, 0);
781 si_sm_result = smi_info->
handlers->event(smi_info->
si_sm, 0);
789 unsigned char msg[2];
803 smi_info->
handlers->start_transaction(
804 smi_info->
si_sm, msg, 2);
813 si_sm_result = start_next_msg(smi_info);
834 smi_info->
handlers->start_transaction(
845 static void sender(
void *send_info,
849 struct smi_info *smi_info = send_info;
857 msg->
rsp[0] = msg->
data[0] | 4;
861 deliver_recv_msg(smi_info, msg);
867 printk(
"**Enqueue: %d.%9.9d\n",
t.tv_sec,
t.tv_usec);
883 result = smi_event_handler(smi_info, 0);
886 result = smi_event_handler(smi_info,
912 start_next_msg(smi_info);
913 smi_event_handler(smi_info, 0);
915 spin_unlock_irqrestore(&smi_info->
si_lock, flags);
918 static void set_run_to_completion(
void *send_info,
int i_run_to_completion)
920 struct smi_info *smi_info = send_info;
924 if (i_run_to_completion) {
925 result = smi_event_handler(smi_info, 0);
928 result = smi_event_handler(smi_info,
939 static inline void ipmi_si_set_not_busy(
struct timespec *
ts)
943 static inline int ipmi_si_is_busy(
struct timespec *
ts)
948 static int ipmi_thread_busy_wait(
enum si_sm_result smi_result,
949 const struct smi_info *smi_info,
952 unsigned int max_busy_us = 0;
954 if (smi_info->
intf_num < num_max_busy_us)
955 max_busy_us = kipmid_max_busy_us[smi_info->
intf_num];
957 ipmi_si_set_not_busy(busy_until);
958 else if (!ipmi_si_is_busy(busy_until)) {
964 if (
unlikely(timespec_compare(&now, busy_until) > 0)) {
965 ipmi_si_set_not_busy(busy_until);
982 static int ipmi_thread(
void *
data)
984 struct smi_info *smi_info =
data;
986 enum si_sm_result smi_result;
989 ipmi_si_set_not_busy(&busy_until);
995 smi_result = smi_event_handler(smi_info, 0);
996 spin_unlock_irqrestore(&(smi_info->
si_lock), flags);
997 busy_wait = ipmi_thread_busy_wait(smi_result, smi_info,
1012 static void poll(
void *send_info)
1014 struct smi_info *smi_info = send_info;
1015 unsigned long flags = 0;
1023 if (!run_to_completion)
1025 smi_event_handler(smi_info, 10);
1026 if (!run_to_completion)
1027 spin_unlock_irqrestore(&smi_info->
si_lock, flags);
1030 static void request_events(
void *send_info)
1032 struct smi_info *smi_info = send_info;
1043 static void smi_timeout(
unsigned long data)
1045 struct smi_info *smi_info = (
struct smi_info *) data;
1046 enum si_sm_result smi_result;
1047 unsigned long flags;
1048 unsigned long jiffies_now;
1063 smi_result = smi_event_handler(smi_info, time_diff);
1065 spin_unlock_irqrestore(&(smi_info->
si_lock), flags);
1093 static irqreturn_t si_irq_handler(
int irq,
void *data)
1095 struct smi_info *smi_info =
data;
1096 unsigned long flags;
1109 smi_event_handler(smi_info, 0);
1110 spin_unlock_irqrestore(&(smi_info->
si_lock), flags);
1114 static irqreturn_t si_bt_irq_handler(
int irq,
void *data)
1116 struct smi_info *smi_info =
data;
1121 return si_irq_handler(irq, data);
1124 static int smi_start_processing(
void *send_info,
1127 struct smi_info *new_smi = send_info;
1144 if (new_smi->
intf_num < num_force_kipmid)
1145 enable = force_kipmid[new_smi->
intf_num];
1156 if (IS_ERR(new_smi->
thread)) {
1157 dev_notice(new_smi->
dev,
"Could not start"
1158 " kernel thread due to error %ld, only using"
1159 " timers to drive the interface\n",
1160 PTR_ERR(new_smi->
thread));
1168 static int get_smi_info(
void *send_info,
struct ipmi_smi_info *data)
1170 struct smi_info *smi = send_info;
1180 static void set_maintenance_mode(
void *send_info,
int enable)
1182 struct smi_info *smi_info = send_info;
1190 .start_processing = smi_start_processing,
1208 #define DEFAULT_REGSPACING 1
1209 #define DEFAULT_REGSIZE 1
1211 static bool si_trydefaults = 1;
1213 #define MAX_SI_TYPE_STR 30
1216 static unsigned int num_addrs;
1218 static unsigned int num_ports;
1222 static unsigned int num_regspacings;
1224 static unsigned int num_regsizes;
1226 static unsigned int num_regshifts;
1228 static unsigned int num_slave_addrs;
1230 #define IPMI_IO_ADDR_SPACE 0
1231 #define IPMI_MEM_ADDR_SPACE 1
1232 static char *addr_space_to_str[] = {
"i/o",
"mem" };
1238 " Documentation/IPMI.txt in the kernel sources for the"
1243 " default scan of the KCS and SMIC interface at the standard"
1247 " interface separated by commas. The types are 'kcs',"
1248 " 'smic', and 'bt'. For example si_type=kcs,bt will set"
1249 " the first interface to kcs and the second to bt");
1252 " addresses separated by commas. Only use if an interface"
1253 " is in memory. Otherwise, set it to zero or leave"
1257 " addresses separated by commas. Only use if an interface"
1258 " is a port. Otherwise, set it to zero or leave"
1262 " addresses separated by commas. Only use if an interface"
1263 " has an interrupt. Otherwise, set it to zero or leave"
1266 MODULE_PARM_DESC(regspacings,
"The number of bytes between the start address"
1267 " and each successive register used by the interface. For"
1268 " instance, if the start address is 0xca2 and the spacing"
1269 " is 2, then the second address is at 0xca4. Defaults"
1272 MODULE_PARM_DESC(regsizes,
"The size of the specific IPMI register in bytes."
1273 " This should generally be 1, 2, 4, or 8 for an 8-bit,"
1274 " 16-bit, 32-bit, or 64-bit register. Use this if you"
1275 " the 8-bit IPMI register has to be read from a larger"
1279 " IPMI register, in bits. For instance, if the data"
1280 " is read from a 32-bit word and the IPMI data is in"
1281 " bit 8-15, then the shift would be 8");
1284 " the controller. Normally this is 0x20, but can be"
1285 " overridden by this parm. This is an array indexed"
1286 " by interface number.");
1288 MODULE_PARM_DESC(force_kipmid,
"Force the kipmi daemon to be enabled (1) or"
1289 " disabled(0). Normally the IPMI driver auto-detects"
1290 " this, but the value may be overridden by this parm.");
1292 MODULE_PARM_DESC(unload_when_empty,
"Unload the module if no interfaces are"
1293 " specified or found, default is 1. Setting to 0"
1294 " is useful for hot add of devices using hotmod.");
1297 "Max time (in microseconds) to busy-wait for IPMI data before"
1298 " sleeping. 0 (default) means to wait forever. Set to 100-500"
1299 " if kipmid is using up a lot of CPU time.");
1302 static void std_irq_cleanup(
struct smi_info *
info)
1310 static int std_irq_setup(
struct smi_info *info)
1334 dev_warn(info->
dev,
"%s unable to claim interrupt %d,"
1335 " running polled\n",
1353 static void port_outb(
struct si_sm_io *io,
unsigned int offset,
1361 static unsigned char port_inw(
struct si_sm_io *io,
unsigned int offset)
1368 static void port_outw(
struct si_sm_io *io,
unsigned int offset,
1376 static unsigned char port_inl(
struct si_sm_io *io,
unsigned int offset)
1383 static void port_outl(
struct si_sm_io *io,
unsigned int offset,
1391 static void port_cleanup(
struct smi_info *info)
1393 unsigned int addr = info->
io.addr_data;
1397 for (idx = 0; idx < info->
io_size; idx++)
1403 static int port_setup(
struct smi_info *info)
1405 unsigned int addr = info->
io.addr_data;
1417 switch (info->
io.regsize) {
1419 info->
io.inputb = port_inb;
1420 info->
io.outputb = port_outb;
1423 info->
io.inputb = port_inw;
1424 info->
io.outputb = port_outw;
1427 info->
io.inputb = port_inl;
1428 info->
io.outputb = port_outl;
1431 dev_warn(info->
dev,
"Invalid register size: %d\n",
1442 for (idx = 0; idx < info->
io_size; idx++) {
1456 static unsigned char intf_mem_inb(
struct si_sm_io *io,
unsigned int offset)
1461 static void intf_mem_outb(
struct si_sm_io *io,
unsigned int offset,
1467 static unsigned char intf_mem_inw(
struct si_sm_io *io,
unsigned int offset)
1473 static void intf_mem_outw(
struct si_sm_io *io,
unsigned int offset,
1479 static unsigned char intf_mem_inl(
struct si_sm_io *io,
unsigned int offset)
1485 static void intf_mem_outl(
struct si_sm_io *io,
unsigned int offset,
1492 static unsigned char mem_inq(
struct si_sm_io *io,
unsigned int offset)
1498 static void mem_outq(
struct si_sm_io *io,
unsigned int offset,
1505 static void mem_cleanup(
struct smi_info *info)
1507 unsigned long addr = info->
io.addr_data;
1510 if (info->
io.addr) {
1513 mapsize = ((info->
io_size * info->
io.regspacing)
1514 - (info->
io.regspacing - info->
io.regsize));
1520 static int mem_setup(
struct smi_info *info)
1522 unsigned long addr = info->
io.addr_data;
1534 switch (info->
io.regsize) {
1536 info->
io.inputb = intf_mem_inb;
1537 info->
io.outputb = intf_mem_outb;
1540 info->
io.inputb = intf_mem_inw;
1541 info->
io.outputb = intf_mem_outw;
1544 info->
io.inputb = intf_mem_inl;
1545 info->
io.outputb = intf_mem_outl;
1549 info->
io.inputb = mem_inq;
1550 info->
io.outputb = mem_outq;
1554 dev_warn(info->
dev,
"Invalid register size: %d\n",
1566 mapsize = ((info->
io_size * info->
io.regspacing)
1567 - (info->
io.regspacing - info->
io.regsize));
1573 if (info->
io.addr ==
NULL) {
1624 for (i = 0; hotmod_ops[
i].
name; i++) {
1625 if (
strcmp(*curr, v[i].name) == 0) {
1636 static int check_hotmod_int_op(
const char *curr,
const char *
option,
1637 const char *name,
int *val)
1641 if (
strcmp(curr, name) == 0) {
1644 "No option given for '%s'\n",
1649 if ((*n !=
'\0') || (*option ==
'\0')) {
1651 "Bad option given for '%s'\n",
1660 static struct smi_info *smi_info_alloc(
void)
1662 struct smi_info *info = kzalloc(
sizeof(*info),
GFP_KERNEL);
1669 static int hotmod_handler(
const char *val,
struct kernel_param *kp)
1685 struct smi_info *
info;
1693 while ((ival >= 0) &&
isspace(str[ival])) {
1698 for (curr = str;
curr; curr =
next) {
1705 next =
strchr(curr,
':');
1711 rv = parse_str(hotmod_ops, &ival,
"operation", &curr);
1716 rv = parse_str(hotmod_si, &ival,
"interface type", &curr);
1721 rv = parse_str(hotmod_as, &addr_space,
"address space", &curr);
1731 if ((*n !=
'\0') || (*curr ==
'\0')) {
1749 rv = check_hotmod_int_op(curr, o,
"rsp", ®spacing);
1754 rv = check_hotmod_int_op(curr, o,
"rsi", ®size);
1759 rv = check_hotmod_int_op(curr, o,
"rsh", ®shift);
1764 rv = check_hotmod_int_op(curr, o,
"irq", &irq);
1769 rv = check_hotmod_int_op(curr, o,
"ipmb", &ipmb);
1777 "Invalid hotmod option '%s'\n",
1783 info = smi_info_alloc();
1791 info->
io.addr_data =
addr;
1792 info->
io.addr_type = addr_space;
1799 info->
io.regspacing = regspacing;
1800 if (!info->
io.regspacing)
1802 info->
io.regsize = regsize;
1803 if (!info->
io.regsize)
1805 info->
io.regshift = regshift;
1811 if (!add_smi(info)) {
1812 if (try_smi_init(info))
1813 cleanup_one_si(info);
1819 struct smi_info *
e, *tmp_e;
1823 if (e->
io.addr_type != addr_space)
1827 if (e->
io.addr_data == addr)
1839 static int __devinit hardcode_find_bmc(
void)
1843 struct smi_info *
info;
1846 if (!ports[i] && !addrs[i])
1849 info = smi_info_alloc();
1856 if (!si_type[i] ||
strcmp(si_type[i],
"kcs") == 0) {
1858 }
else if (
strcmp(si_type[i],
"smic") == 0) {
1860 }
else if (
strcmp(si_type[i],
"bt") == 0) {
1864 "for interface %d, was invalid: %s\n",
1873 info->
io.addr_data = ports[
i];
1875 }
else if (addrs[i]) {
1878 info->
io.addr_data = addrs[
i];
1882 "for interface %d, but port and address were "
1883 "not set or set to zero.\n", i);
1889 info->
io.regspacing = regspacings[
i];
1890 if (!info->
io.regspacing)
1892 info->
io.regsize = regsizes[
i];
1893 if (!info->
io.regsize)
1895 info->
io.regshift = regshifts[
i];
1896 info->
irq = irqs[
i];
1901 if (!add_smi(info)) {
1902 if (try_smi_init(info))
1903 cleanup_one_si(info);
1921 static int acpi_failure;
1927 struct smi_info *smi_info =
context;
1928 unsigned long flags;
1939 printk(
"**ACPI_GPE: %d.%9.9d\n",
t.tv_sec,
t.tv_usec);
1941 smi_event_handler(smi_info, 0);
1942 spin_unlock_irqrestore(&(smi_info->
si_lock), flags);
1947 static void acpi_gpe_irq_cleanup(
struct smi_info *info)
1955 static int acpi_gpe_irq_setup(
struct smi_info *info)
1968 if (status !=
AE_OK) {
1969 dev_warn(info->
dev,
"%s unable to claim ACPI GPE %d,"
1993 s8 CreatorRevision[4];
1996 s16 SpecificationRevision;
2016 u32 GlobalSystemInterrupt;
2026 static int __devinit try_init_spmi(
struct SPMITable *spmi)
2028 struct smi_info *
info;
2030 if (spmi->IPMIlegacy != 1) {
2035 info = smi_info_alloc();
2045 switch (spmi->InterfaceType) {
2057 spmi->InterfaceType);
2062 if (spmi->InterruptType & 1) {
2064 info->
irq = spmi->GPE;
2066 }
else if (spmi->InterruptType & 2) {
2068 info->
irq = spmi->GlobalSystemInterrupt;
2076 if (spmi->addr.bit_width) {
2078 info->
io.regspacing = spmi->addr.bit_width / 8;
2082 info->
io.regsize = info->
io.regspacing;
2083 info->
io.regshift = spmi->addr.bit_offset;
2096 info->
io.addr_data = spmi->addr.address;
2098 pr_info(
"ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n",
2100 info->
io.addr_data, info->
io.regsize, info->
io.regspacing,
2109 static void __devinit spmi_find_bmc(
void)
2112 struct SPMITable *spmi;
2121 for (i = 0; ; i++) {
2124 if (status !=
AE_OK)
2127 try_init_spmi(spmi);
2134 struct acpi_device *acpi_dev;
2135 struct smi_info *
info;
2139 unsigned long long tmp;
2145 info = smi_info_alloc();
2152 handle = acpi_dev->handle;
2171 dev_info(&dev->
dev,
"unknown IPMI type %lld\n", tmp);
2187 dev_err(&dev->
dev,
"no I/O or memory address\n");
2190 info->
io.addr_data = res->
start;
2198 if (res_second->
start > info->
io.addr_data)
2199 info->
io.regspacing = res_second->
start - info->
io.addr_data;
2202 info->
io.regshift = 0;
2209 }
else if (pnp_irq_valid(dev, 0)) {
2215 pnp_set_drvdata(dev, info);
2217 dev_info(info->
dev,
"%pR regsize %d spacing %d irq %d\n",
2218 res, info->
io.regsize, info->
io.regspacing,
2233 struct smi_info *info = pnp_get_drvdata(dev);
2235 cleanup_one_si(info);
2245 .probe = ipmi_pnp_probe,
2247 .id_table = pnp_dev_table,
2252 struct dmi_ipmi_data {
2255 unsigned long base_addr;
2262 struct dmi_ipmi_data *dmi)
2264 const u8 *data = (
const u8 *)dm;
2265 unsigned long base_addr;
2269 dmi->type = data[4];
2271 memcpy(&base_addr, data+8,
sizeof(
unsigned long));
2273 if (base_addr & 1) {
2275 base_addr &= 0xFFFE;
2283 dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4);
2285 dmi->irq = data[0x11];
2288 reg_spacing = (data[0x10] & 0xC0) >> 6;
2289 switch (reg_spacing) {
2313 dmi->base_addr = base_addr & 0xfffe;
2318 dmi->slave_addr = data[6];
2323 static void __devinit try_init_dmi(
struct dmi_ipmi_data *ipmi_data)
2325 struct smi_info *
info;
2327 info = smi_info_alloc();
2336 switch (ipmi_data->type) {
2351 switch (ipmi_data->addr_space) {
2365 ipmi_data->addr_space);
2368 info->
io.addr_data = ipmi_data->base_addr;
2370 info->
io.regspacing = ipmi_data->offset;
2371 if (!info->
io.regspacing)
2374 info->
io.regshift = 0;
2378 info->
irq = ipmi_data->irq;
2382 pr_info(
"ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n",
2384 info->
io.addr_data, info->
io.regsize, info->
io.regspacing,
2391 static void __devinit dmi_find_bmc(
void)
2394 struct dmi_ipmi_data data;
2398 memset(&data, 0,
sizeof(data));
2402 try_init_dmi(&data);
2409 #define PCI_ERMC_CLASSCODE 0x0C0700
2410 #define PCI_ERMC_CLASSCODE_MASK 0xffffff00
2411 #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff
2412 #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00
2413 #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01
2414 #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02
2416 #define PCI_HP_VENDOR_ID 0x103C
2417 #define PCI_MMC_DEVICE_ID 0x121A
2418 #define PCI_MMC_ADDR_CW 0x10
2420 static void ipmi_pci_cleanup(
struct smi_info *info)
2427 static int __devinit ipmi_pci_probe_regspacing(
struct smi_info *info)
2434 info->
io.regshift = 0;
2440 info->
io.regspacing = regspacing;
2443 "Could not setup I/O space\n");
2447 info->
io.outputb(&info->
io, 1, 0x10);
2449 status = info->
io.inputb(&info->
io, 1);
2463 int class_type = pdev->
class & PCI_ERMC_CLASSCODE_TYPE_MASK;
2464 struct smi_info *
info;
2466 info = smi_info_alloc();
2473 switch (class_type) {
2474 case PCI_ERMC_CLASSCODE_TYPE_SMIC:
2478 case PCI_ERMC_CLASSCODE_TYPE_KCS:
2482 case PCI_ERMC_CLASSCODE_TYPE_BT:
2488 dev_info(&pdev->
dev,
"Unknown IPMI type: %d\n", class_type);
2494 dev_err(&pdev->
dev,
"couldn't enable PCI device\n");
2511 info->
io.regspacing = ipmi_pci_probe_regspacing(info);
2513 info->
io.regshift = 0;
2520 pci_set_drvdata(pdev, info);
2522 dev_info(&pdev->
dev,
"%pR regsize %d spacing %d irq %d\n",
2523 &pdev->
resource[0], info->
io.regsize, info->
io.regspacing,
2534 struct smi_info *info = pci_get_drvdata(pdev);
2535 cleanup_one_si(info);
2539 {
PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) },
2547 .id_table = ipmi_pci_devices,
2548 .probe = ipmi_pci_probe,
2558 struct smi_info *
info;
2560 const __be32 *regsize, *regspacing, *regshift;
2578 if (regsize && proplen != 4) {
2584 if (regspacing && proplen != 4) {
2590 if (regshift && proplen != 4) {
2595 info = smi_info_alloc();
2599 "could not allocate memory for OF probe\n");
2624 dev_dbg(&dev->
dev,
"addr 0x%lx regsize %d spacing %d irq %d\n",
2625 info->
io.addr_data, info->
io.regsize, info->
io.regspacing,
2630 if (add_smi(info)) {
2648 { .type =
"ipmi", .compatible =
"ipmi-kcs",
2649 .data = (
void *)(
unsigned long)
SI_KCS },
2650 { .type =
"ipmi", .compatible =
"ipmi-smic",
2651 .data = (
void *)(
unsigned long)
SI_SMIC },
2652 { .type =
"ipmi", .compatible =
"ipmi-bt",
2653 .data = (
void *)(
unsigned long)
SI_BT },
2661 .of_match_table = ipmi_match,
2663 .probe = ipmi_probe,
2667 static int wait_for_msg_done(
struct smi_info *smi_info)
2669 enum si_sm_result smi_result;
2676 smi_result = smi_info->
handlers->event(
2677 smi_info->
si_sm, 100);
2679 smi_result = smi_info->
handlers->event(
2680 smi_info->
si_sm, 0);
2694 static int try_get_dev_id(
struct smi_info *smi_info)
2696 unsigned char msg[2];
2697 unsigned char *
resp;
2711 smi_info->
handlers->start_transaction(smi_info->
si_sm, msg, 2);
2713 rv = wait_for_msg_done(smi_info);
2721 rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->
device_id);
2728 static int try_enable_event_buffer(
struct smi_info *smi_info)
2730 unsigned char msg[3];
2731 unsigned char *
resp;
2741 smi_info->
handlers->start_transaction(smi_info->
si_sm, msg, 2);
2743 rv = wait_for_msg_done(smi_info);
2746 " global enables command, the event buffer is not"
2759 " enables command, cannot enable the event buffer.\n");
2771 smi_info->
handlers->start_transaction(smi_info->
si_sm, msg, 3);
2773 rv = wait_for_msg_done(smi_info);
2776 " global, enables command, the event buffer is not"
2788 "enables command, not enable the event buffer.\n");
2804 static int smi_type_proc_show(
struct seq_file *
m,
void *v)
2806 struct smi_info *smi = m->
private;
2813 return single_open(file, smi_type_proc_show, PDE(inode)->data);
2817 .open = smi_type_proc_open,
2823 static int smi_si_stats_proc_show(
struct seq_file *
m,
void *v)
2825 struct smi_info *smi = m->
private;
2854 static int smi_si_stats_proc_open(
struct inode *inode,
struct file *file)
2856 return single_open(file, smi_si_stats_proc_show, PDE(inode)->data);
2860 .open = smi_si_stats_proc_open,
2866 static int smi_params_proc_show(
struct seq_file *m,
void *v)
2868 struct smi_info *smi = m->
private;
2871 "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n",
2873 addr_space_to_str[smi->
io.addr_type],
2882 static int smi_params_proc_open(
struct inode *inode,
struct file *file)
2884 return single_open(file, smi_params_proc_show, PDE(inode)->data);
2888 .open = smi_params_proc_open,
2901 static int oem_data_avail_to_receive_msg_avail(
struct smi_info *smi_info)
2933 #define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20
2934 #define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80
2935 #define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51
2936 #define DELL_IANA_MFR_ID 0x0002a2
2937 static void setup_dell_poweredge_oem_data_handler(
struct smi_info *smi_info)
2945 oem_data_avail_to_receive_msg_avail;
2950 oem_data_avail_to_receive_msg_avail;
2955 #define CANNOT_RETURN_REQUESTED_LENGTH 0xCA
2956 static void return_hosed_msg_badsize(
struct smi_info *smi_info)
2961 msg->
rsp[0] = msg->
data[0] | 4;
2966 deliver_recv_msg(smi_info, msg);
2980 #define STORAGE_NETFN 0x0A
2981 #define STORAGE_CMD_GET_SDR 0x23
2982 static int dell_poweredge_bt_xaction_handler(
struct notifier_block *
self,
2986 struct smi_info *smi_info =
in;
2987 unsigned char *data = smi_info->
curr_msg->data;
2993 return_hosed_msg_badsize(smi_info);
2999 static struct notifier_block dell_poweredge_bt_xaction_notifier = {
3000 .notifier_call = dell_poweredge_bt_xaction_handler,
3011 setup_dell_poweredge_bt_xaction_handler(
struct smi_info *smi_info)
3016 register_xaction_notifier(&dell_poweredge_bt_xaction_notifier);
3027 static void setup_oem_data_handler(
struct smi_info *smi_info)
3029 setup_dell_poweredge_oem_data_handler(smi_info);
3032 static void setup_xaction_handlers(
struct smi_info *smi_info)
3034 setup_dell_poweredge_bt_xaction_handler(smi_info);
3037 static inline void wait_for_timer_and_thread(
struct smi_info *smi_info)
3039 if (smi_info->
intf) {
3056 { .type =
SI_KCS, .port = 0xca2 },
3057 { .type =
SI_SMIC, .port = 0xca9 },
3058 { .type =
SI_BT, .port = 0xe4 },
3062 static void __devinit default_find_bmc(
void)
3064 struct smi_info *
info;
3067 for (i = 0; ; i++) {
3068 if (!ipmi_defaults[i].
port)
3074 info = smi_info_alloc();
3080 info->
si_type = ipmi_defaults[
i].type;
3082 info->
io.addr_data = ipmi_defaults[
i].port;
3088 info->
io.regshift = 0;
3090 if (add_smi(info) == 0) {
3091 if ((try_smi_init(info)) == 0) {
3094 " state machine at %s address 0x%lx\n",
3096 addr_space_to_str[info->
io.addr_type],
3097 info->
io.addr_data);
3099 cleanup_one_si(info);
3106 static int is_new_interface(
struct smi_info *info)
3111 if (e->
io.addr_type != info->
io.addr_type)
3113 if (e->
io.addr_data == info->
io.addr_data)
3120 static int add_smi(
struct smi_info *new_smi)
3128 if (!is_new_interface(new_smi)) {
3148 static int try_smi_init(
struct smi_info *new_smi)
3154 " machine at %s address 0x%lx, slave address 0x%x,"
3158 addr_space_to_str[new_smi->
io.addr_type],
3159 new_smi->
io.addr_data,
3183 if (!new_smi->
si_sm) {
3185 "Could not allocate state machine memory\n");
3211 rv = try_get_dev_id(new_smi);
3215 " at this location\n");
3219 setup_oem_data_handler(new_smi);
3220 setup_xaction_handlers(new_smi);
3235 rv = try_enable_event_buffer(new_smi);
3243 start_clear_flags(new_smi);
3248 if (!new_smi->
dev) {
3255 if (!new_smi->
pdev) {
3257 "Unable to allocate platform device\n");
3260 new_smi->
dev = &new_smi->
pdev->dev;
3261 new_smi->
dev->driver = &ipmi_driver.
driver;
3266 "Unable to register system interface device:"
3281 dev_err(new_smi->
dev,
"Unable to register device: error %d\n",
3283 goto out_err_stop_timer;
3290 dev_err(new_smi->
dev,
"Unable to create proc entry: %d\n", rv);
3291 goto out_err_stop_timer;
3295 &smi_si_stats_proc_ops,
3298 dev_err(new_smi->
dev,
"Unable to create proc entry: %d\n", rv);
3299 goto out_err_stop_timer;
3303 &smi_params_proc_ops,
3306 dev_err(new_smi->
dev,
"Unable to create proc entry: %d\n", rv);
3307 goto out_err_stop_timer;
3310 dev_info(new_smi->
dev,
"IPMI %s interface initialized\n",
3317 wait_for_timer_and_thread(new_smi);
3322 if (new_smi->
intf) {
3339 if (new_smi->
si_sm) {
3384 for (i = 0; (i <
SI_MAX_PARMS) && (*str !=
'\0'); i++) {
3399 if (!hardcode_find_bmc())
3403 rv = pci_register_driver(&ipmi_pci_driver);
3434 if (!try_smi_init(e)) {
3450 if (!try_smi_init(e)) {
3460 if (si_trydefaults) {
3462 if (list_empty(&smi_infos)) {
3471 if (unload_when_empty && list_empty(&smi_infos)) {
3475 "Unable to find any System Interface(s)\n");
3484 static void cleanup_one_si(
struct smi_info *to_clean)
3487 unsigned long flags;
3501 wait_for_timer_and_thread(to_clean);
3510 spin_unlock_irqrestore(&to_clean->
si_lock, flags);
3515 disable_si_irq(to_clean);
3516 spin_unlock_irqrestore(&to_clean->
si_lock, flags);
3554 static void cleanup_ipmi_si(
void)
3556 struct smi_info *
e, *tmp_e;