Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-linus-4.13-v2' of git://github.com/cminyard/linux-ipmi

Pull IPMI updates from Corey Minyard:
"Some small fixes for IPMI, and one medium sized changed.

The medium sized change is adding a platform device for IPMI entries
in the DMI table. Otherwise there is no auto loading for IPMI devices
if they are only in the DMI table"

* tag 'for-linus-4.13-v2' of git://github.com/cminyard/linux-ipmi:
ipmi:ssif: Add missing unlock in error branch
char: ipmi: constify bmc_dev_attr_group and bmc_device_type
ipmi:ssif: Check dev before setting drvdata
ipmi: Convert DMI handling over to a platform device
ipmi: Create a platform device for a DMI-specified IPMI interface
ipmi: use rcu lock around call to intf->handlers->sender()
ipmi:ssif: Use i2c_adapter_id instead of adapter->nr
ipmi: Use the proper default value for register size in ACPI
ipmi_ssif: remove redundant null check on array client->adapter->name
ipmi/watchdog: fix watchdog timeout set on reboot
ipmi_ssif: unlock on allocation failure

+533 -214
+4
drivers/char/ipmi/Kconfig
··· 5 5 menuconfig IPMI_HANDLER 6 6 tristate 'IPMI top-level message handler' 7 7 depends on HAS_IOMEM 8 + select IPMI_DMI_DECODE if DMI 8 9 help 9 10 This enables the central IPMI message handler, required for IPMI 10 11 to work. ··· 16 15 See <file:Documentation/IPMI.txt> for more details on the driver. 17 16 18 17 If unsure, say N. 18 + 19 + config IPMI_DMI_DECODE 20 + bool 19 21 20 22 if IPMI_HANDLER 21 23
+1
drivers/char/ipmi/Makefile
··· 7 7 obj-$(CONFIG_IPMI_HANDLER) += ipmi_msghandler.o 8 8 obj-$(CONFIG_IPMI_DEVICE_INTERFACE) += ipmi_devintf.o 9 9 obj-$(CONFIG_IPMI_SI) += ipmi_si.o 10 + obj-$(CONFIG_IPMI_DMI_DECODE) += ipmi_dmi.o 10 11 obj-$(CONFIG_IPMI_SSIF) += ipmi_ssif.o 11 12 obj-$(CONFIG_IPMI_POWERNV) += ipmi_powernv.o 12 13 obj-$(CONFIG_IPMI_WATCHDOG) += ipmi_watchdog.o
+273
drivers/char/ipmi/ipmi_dmi.c
··· 1 + /* 2 + * A hack to create a platform device from a DMI entry. This will 3 + * allow autoloading of the IPMI drive based on SMBIOS entries. 4 + */ 5 + 6 + #include <linux/ipmi.h> 7 + #include <linux/init.h> 8 + #include <linux/dmi.h> 9 + #include <linux/platform_device.h> 10 + #include <linux/property.h> 11 + #include "ipmi_dmi.h" 12 + 13 + struct ipmi_dmi_info { 14 + int type; 15 + u32 flags; 16 + unsigned long addr; 17 + u8 slave_addr; 18 + struct ipmi_dmi_info *next; 19 + }; 20 + 21 + static struct ipmi_dmi_info *ipmi_dmi_infos; 22 + 23 + static int ipmi_dmi_nr __initdata; 24 + 25 + static void __init dmi_add_platform_ipmi(unsigned long base_addr, 26 + u32 flags, 27 + u8 slave_addr, 28 + int irq, 29 + int offset, 30 + int type) 31 + { 32 + struct platform_device *pdev; 33 + struct resource r[4]; 34 + unsigned int num_r = 1, size; 35 + struct property_entry p[4] = { 36 + PROPERTY_ENTRY_U8("slave-addr", slave_addr), 37 + PROPERTY_ENTRY_U8("ipmi-type", type), 38 + PROPERTY_ENTRY_U16("i2c-addr", base_addr), 39 + { } 40 + }; 41 + char *name, *override; 42 + int rv; 43 + struct ipmi_dmi_info *info; 44 + 45 + info = kmalloc(sizeof(*info), GFP_KERNEL); 46 + if (!info) { 47 + pr_warn("ipmi:dmi: Could not allocate dmi info\n"); 48 + } else { 49 + info->type = type; 50 + info->flags = flags; 51 + info->addr = base_addr; 52 + info->slave_addr = slave_addr; 53 + info->next = ipmi_dmi_infos; 54 + ipmi_dmi_infos = info; 55 + } 56 + 57 + name = "dmi-ipmi-si"; 58 + override = "ipmi_si"; 59 + switch (type) { 60 + case IPMI_DMI_TYPE_SSIF: 61 + name = "dmi-ipmi-ssif"; 62 + override = "ipmi_ssif"; 63 + offset = 1; 64 + size = 1; 65 + break; 66 + case IPMI_DMI_TYPE_BT: 67 + size = 3; 68 + break; 69 + case IPMI_DMI_TYPE_KCS: 70 + case IPMI_DMI_TYPE_SMIC: 71 + size = 2; 72 + break; 73 + default: 74 + pr_err("ipmi:dmi: Invalid IPMI type: %d", type); 75 + return; 76 + } 77 + 78 + pdev = platform_device_alloc(name, ipmi_dmi_nr); 79 + if (!pdev) { 80 + pr_err("ipmi:dmi: Error allocation IPMI platform device"); 81 + return; 82 + } 83 + pdev->driver_override = override; 84 + 85 + if (type == IPMI_DMI_TYPE_SSIF) 86 + goto add_properties; 87 + 88 + memset(r, 0, sizeof(r)); 89 + 90 + r[0].start = base_addr; 91 + r[0].end = r[0].start + offset - 1; 92 + r[0].name = "IPMI Address 1"; 93 + r[0].flags = flags; 94 + 95 + if (size > 1) { 96 + r[1].start = r[0].start + offset; 97 + r[1].end = r[1].start + offset - 1; 98 + r[1].name = "IPMI Address 2"; 99 + r[1].flags = flags; 100 + num_r++; 101 + } 102 + 103 + if (size > 2) { 104 + r[2].start = r[1].start + offset; 105 + r[2].end = r[2].start + offset - 1; 106 + r[2].name = "IPMI Address 3"; 107 + r[2].flags = flags; 108 + num_r++; 109 + } 110 + 111 + if (irq) { 112 + r[num_r].start = irq; 113 + r[num_r].end = irq; 114 + r[num_r].name = "IPMI IRQ"; 115 + r[num_r].flags = IORESOURCE_IRQ; 116 + num_r++; 117 + } 118 + 119 + rv = platform_device_add_resources(pdev, r, num_r); 120 + if (rv) { 121 + dev_err(&pdev->dev, 122 + "ipmi:dmi: Unable to add resources: %d\n", rv); 123 + goto err; 124 + } 125 + 126 + add_properties: 127 + rv = platform_device_add_properties(pdev, p); 128 + if (rv) { 129 + dev_err(&pdev->dev, 130 + "ipmi:dmi: Unable to add properties: %d\n", rv); 131 + goto err; 132 + } 133 + 134 + rv = platform_device_add(pdev); 135 + if (rv) { 136 + dev_err(&pdev->dev, "ipmi:dmi: Unable to add device: %d\n", rv); 137 + goto err; 138 + } 139 + 140 + ipmi_dmi_nr++; 141 + return; 142 + 143 + err: 144 + platform_device_put(pdev); 145 + } 146 + 147 + /* 148 + * Look up the slave address for a given interface. This is here 149 + * because ACPI doesn't have a slave address while SMBIOS does, but we 150 + * prefer using ACPI so the ACPI code can use the IPMI namespace. 151 + * This function allows an ACPI-specified IPMI device to look up the 152 + * slave address from the DMI table. 153 + */ 154 + int ipmi_dmi_get_slave_addr(int type, u32 flags, unsigned long base_addr) 155 + { 156 + struct ipmi_dmi_info *info = ipmi_dmi_infos; 157 + 158 + while (info) { 159 + if (info->type == type && 160 + info->flags == flags && 161 + info->addr == base_addr) 162 + return info->slave_addr; 163 + info = info->next; 164 + } 165 + 166 + return 0; 167 + } 168 + EXPORT_SYMBOL(ipmi_dmi_get_slave_addr); 169 + 170 + #define DMI_IPMI_MIN_LENGTH 0x10 171 + #define DMI_IPMI_VER2_LENGTH 0x12 172 + #define DMI_IPMI_TYPE 4 173 + #define DMI_IPMI_SLAVEADDR 6 174 + #define DMI_IPMI_ADDR 8 175 + #define DMI_IPMI_ACCESS 0x10 176 + #define DMI_IPMI_IRQ 0x11 177 + #define DMI_IPMI_IO_MASK 0xfffe 178 + 179 + static void __init dmi_decode_ipmi(const struct dmi_header *dm) 180 + { 181 + const u8 *data = (const u8 *) dm; 182 + u32 flags = IORESOURCE_IO; 183 + unsigned long base_addr; 184 + u8 len = dm->length; 185 + u8 slave_addr; 186 + int irq = 0, offset; 187 + int type; 188 + 189 + if (len < DMI_IPMI_MIN_LENGTH) 190 + return; 191 + 192 + type = data[DMI_IPMI_TYPE]; 193 + slave_addr = data[DMI_IPMI_SLAVEADDR]; 194 + 195 + memcpy(&base_addr, data + DMI_IPMI_ADDR, sizeof(unsigned long)); 196 + if (len >= DMI_IPMI_VER2_LENGTH) { 197 + if (type == IPMI_DMI_TYPE_SSIF) { 198 + offset = 0; 199 + flags = 0; 200 + base_addr = data[DMI_IPMI_ADDR] >> 1; 201 + if (base_addr == 0) { 202 + /* 203 + * Some broken systems put the I2C address in 204 + * the slave address field. We try to 205 + * accommodate them here. 206 + */ 207 + base_addr = data[DMI_IPMI_SLAVEADDR] >> 1; 208 + slave_addr = 0; 209 + } 210 + } else { 211 + if (base_addr & 1) { 212 + /* I/O */ 213 + base_addr &= DMI_IPMI_IO_MASK; 214 + } else { 215 + /* Memory */ 216 + flags = IORESOURCE_MEM; 217 + } 218 + 219 + /* 220 + * If bit 4 of byte 0x10 is set, then the lsb 221 + * for the address is odd. 222 + */ 223 + base_addr |= (data[DMI_IPMI_ACCESS] >> 4) & 1; 224 + 225 + irq = data[DMI_IPMI_IRQ]; 226 + 227 + /* 228 + * The top two bits of byte 0x10 hold the 229 + * register spacing. 230 + */ 231 + switch ((data[DMI_IPMI_ACCESS] >> 6) & 3) { 232 + case 0: /* Byte boundaries */ 233 + offset = 1; 234 + break; 235 + case 1: /* 32-bit boundaries */ 236 + offset = 4; 237 + break; 238 + case 2: /* 16-byte boundaries */ 239 + offset = 16; 240 + break; 241 + default: 242 + pr_err("ipmi:dmi: Invalid offset: 0"); 243 + return; 244 + } 245 + } 246 + } else { 247 + /* Old DMI spec. */ 248 + /* 249 + * Note that technically, the lower bit of the base 250 + * address should be 1 if the address is I/O and 0 if 251 + * the address is in memory. So many systems get that 252 + * wrong (and all that I have seen are I/O) so we just 253 + * ignore that bit and assume I/O. Systems that use 254 + * memory should use the newer spec, anyway. 255 + */ 256 + base_addr = base_addr & DMI_IPMI_IO_MASK; 257 + offset = 1; 258 + } 259 + 260 + dmi_add_platform_ipmi(base_addr, flags, slave_addr, irq, 261 + offset, type); 262 + } 263 + 264 + static int __init scan_for_dmi_ipmi(void) 265 + { 266 + const struct dmi_device *dev = NULL; 267 + 268 + while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) 269 + dmi_decode_ipmi((const struct dmi_header *) dev->device_data); 270 + 271 + return 0; 272 + } 273 + subsys_initcall(scan_for_dmi_ipmi);
+12
drivers/char/ipmi/ipmi_dmi.h
··· 1 + /* 2 + * DMI defines for use by IPMI 3 + */ 4 + 5 + #define IPMI_DMI_TYPE_KCS 0x01 6 + #define IPMI_DMI_TYPE_SMIC 0x02 7 + #define IPMI_DMI_TYPE_BT 0x03 8 + #define IPMI_DMI_TYPE_SSIF 0x04 9 + 10 + #ifdef CONFIG_IPMI_DMI_DECODE 11 + int ipmi_dmi_get_slave_addr(int type, u32 flags, unsigned long base_addr); 12 + #endif
+7 -2
drivers/char/ipmi/ipmi_msghandler.c
··· 2397 2397 return mode; 2398 2398 } 2399 2399 2400 - static struct attribute_group bmc_dev_attr_group = { 2400 + static const struct attribute_group bmc_dev_attr_group = { 2401 2401 .attrs = bmc_dev_attrs, 2402 2402 .is_visible = bmc_dev_attr_is_visible, 2403 2403 }; ··· 2407 2407 NULL 2408 2408 }; 2409 2409 2410 - static struct device_type bmc_device_type = { 2410 + static const struct device_type bmc_device_type = { 2411 2411 .groups = bmc_dev_attr_groups, 2412 2412 }; 2413 2413 ··· 3878 3878 * because the lower layer is allowed to hold locks while calling 3879 3879 * message delivery. 3880 3880 */ 3881 + 3882 + rcu_read_lock(); 3883 + 3881 3884 if (!run_to_completion) 3882 3885 spin_lock_irqsave(&intf->xmit_msgs_lock, flags); 3883 3886 if (intf->curr_msg == NULL && !intf->in_shutdown) { ··· 3902 3899 spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags); 3903 3900 if (newmsg) 3904 3901 intf->handlers->sender(intf->send_info, newmsg); 3902 + 3903 + rcu_read_unlock(); 3905 3904 3906 3905 handle_new_recv_msgs(intf); 3907 3906 }
+119 -146
drivers/char/ipmi/ipmi_si_intf.c
··· 61 61 #include <linux/ipmi_smi.h> 62 62 #include <asm/io.h> 63 63 #include "ipmi_si_sm.h" 64 + #include "ipmi_dmi.h" 64 65 #include <linux/dmi.h> 65 66 #include <linux/string.h> 66 67 #include <linux/ctype.h> ··· 1943 1942 info->io.regspacing = DEFAULT_REGSPACING; 1944 1943 info->io.regsize = regsize; 1945 1944 if (!info->io.regsize) 1946 - info->io.regsize = DEFAULT_REGSPACING; 1945 + info->io.regsize = DEFAULT_REGSIZE; 1947 1946 info->io.regshift = regshift; 1948 1947 info->irq = irq; 1949 1948 if (info->irq) ··· 2037 2036 info->io.regspacing = DEFAULT_REGSPACING; 2038 2037 info->io.regsize = regsizes[i]; 2039 2038 if (!info->io.regsize) 2040 - info->io.regsize = DEFAULT_REGSPACING; 2039 + info->io.regsize = DEFAULT_REGSIZE; 2041 2040 info->io.regshift = regshifts[i]; 2042 2041 info->irq = irqs[i]; 2043 2042 if (info->irq) ··· 2274 2273 } 2275 2274 #endif 2276 2275 2277 - #ifdef CONFIG_DMI 2278 - struct dmi_ipmi_data { 2279 - u8 type; 2280 - u8 addr_space; 2281 - unsigned long base_addr; 2282 - u8 irq; 2283 - u8 offset; 2284 - u8 slave_addr; 2285 - }; 2286 - 2287 - static int decode_dmi(const struct dmi_header *dm, 2288 - struct dmi_ipmi_data *dmi) 2276 + #if defined(CONFIG_DMI) || defined(CONFIG_ACPI) 2277 + struct resource *ipmi_get_info_from_resources(struct platform_device *pdev, 2278 + struct smi_info *info) 2289 2279 { 2290 - const u8 *data = (const u8 *)dm; 2291 - unsigned long base_addr; 2292 - u8 reg_spacing; 2293 - u8 len = dm->length; 2280 + struct resource *res, *res_second; 2294 2281 2295 - dmi->type = data[4]; 2296 - 2297 - memcpy(&base_addr, data+8, sizeof(unsigned long)); 2298 - if (len >= 0x11) { 2299 - if (base_addr & 1) { 2300 - /* I/O */ 2301 - base_addr &= 0xFFFE; 2302 - dmi->addr_space = IPMI_IO_ADDR_SPACE; 2303 - } else 2304 - /* Memory */ 2305 - dmi->addr_space = IPMI_MEM_ADDR_SPACE; 2306 - 2307 - /* If bit 4 of byte 0x10 is set, then the lsb for the address 2308 - is odd. */ 2309 - dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4); 2310 - 2311 - dmi->irq = data[0x11]; 2312 - 2313 - /* The top two bits of byte 0x10 hold the register spacing. */ 2314 - reg_spacing = (data[0x10] & 0xC0) >> 6; 2315 - switch (reg_spacing) { 2316 - case 0x00: /* Byte boundaries */ 2317 - dmi->offset = 1; 2318 - break; 2319 - case 0x01: /* 32-bit boundaries */ 2320 - dmi->offset = 4; 2321 - break; 2322 - case 0x02: /* 16-byte boundaries */ 2323 - dmi->offset = 16; 2324 - break; 2325 - default: 2326 - /* Some other interface, just ignore it. */ 2327 - return -EIO; 2328 - } 2282 + res = platform_get_resource(pdev, IORESOURCE_IO, 0); 2283 + if (res) { 2284 + info->io_setup = port_setup; 2285 + info->io.addr_type = IPMI_IO_ADDR_SPACE; 2329 2286 } else { 2330 - /* Old DMI spec. */ 2331 - /* 2332 - * Note that technically, the lower bit of the base 2333 - * address should be 1 if the address is I/O and 0 if 2334 - * the address is in memory. So many systems get that 2335 - * wrong (and all that I have seen are I/O) so we just 2336 - * ignore that bit and assume I/O. Systems that use 2337 - * memory should use the newer spec, anyway. 2338 - */ 2339 - dmi->base_addr = base_addr & 0xfffe; 2340 - dmi->addr_space = IPMI_IO_ADDR_SPACE; 2341 - dmi->offset = 1; 2287 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2288 + if (res) { 2289 + info->io_setup = mem_setup; 2290 + info->io.addr_type = IPMI_MEM_ADDR_SPACE; 2291 + } 2342 2292 } 2293 + if (!res) { 2294 + dev_err(&pdev->dev, "no I/O or memory address\n"); 2295 + return NULL; 2296 + } 2297 + info->io.addr_data = res->start; 2343 2298 2344 - dmi->slave_addr = data[6]; 2299 + info->io.regspacing = DEFAULT_REGSPACING; 2300 + res_second = platform_get_resource(pdev, 2301 + (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? 2302 + IORESOURCE_IO : IORESOURCE_MEM, 2303 + 1); 2304 + if (res_second) { 2305 + if (res_second->start > info->io.addr_data) 2306 + info->io.regspacing = 2307 + res_second->start - info->io.addr_data; 2308 + } 2309 + info->io.regsize = DEFAULT_REGSIZE; 2310 + info->io.regshift = 0; 2345 2311 2346 - return 0; 2312 + return res; 2347 2313 } 2348 2314 2349 - static void try_init_dmi(struct dmi_ipmi_data *ipmi_data) 2315 + #endif 2316 + 2317 + #ifdef CONFIG_DMI 2318 + static int dmi_ipmi_probe(struct platform_device *pdev) 2350 2319 { 2351 2320 struct smi_info *info; 2321 + u8 type, slave_addr; 2322 + int rv; 2323 + 2324 + if (!si_trydmi) 2325 + return -ENODEV; 2326 + 2327 + rv = device_property_read_u8(&pdev->dev, "ipmi-type", &type); 2328 + if (rv) 2329 + return -ENODEV; 2352 2330 2353 2331 info = smi_info_alloc(); 2354 2332 if (!info) { 2355 2333 pr_err(PFX "Could not allocate SI data\n"); 2356 - return; 2334 + return -ENOMEM; 2357 2335 } 2358 2336 2359 2337 info->addr_source = SI_SMBIOS; 2360 2338 pr_info(PFX "probing via SMBIOS\n"); 2361 2339 2362 - switch (ipmi_data->type) { 2363 - case 0x01: /* KCS */ 2340 + switch (type) { 2341 + case IPMI_DMI_TYPE_KCS: 2364 2342 info->si_type = SI_KCS; 2365 2343 break; 2366 - case 0x02: /* SMIC */ 2344 + case IPMI_DMI_TYPE_SMIC: 2367 2345 info->si_type = SI_SMIC; 2368 2346 break; 2369 - case 0x03: /* BT */ 2347 + case IPMI_DMI_TYPE_BT: 2370 2348 info->si_type = SI_BT; 2371 2349 break; 2372 2350 default: 2373 2351 kfree(info); 2374 - return; 2352 + return -EINVAL; 2375 2353 } 2376 2354 2377 - switch (ipmi_data->addr_space) { 2378 - case IPMI_MEM_ADDR_SPACE: 2379 - info->io_setup = mem_setup; 2380 - info->io.addr_type = IPMI_MEM_ADDR_SPACE; 2381 - break; 2382 - 2383 - case IPMI_IO_ADDR_SPACE: 2384 - info->io_setup = port_setup; 2385 - info->io.addr_type = IPMI_IO_ADDR_SPACE; 2386 - break; 2387 - 2388 - default: 2389 - kfree(info); 2390 - pr_warn(PFX "Unknown SMBIOS I/O Address type: %d\n", 2391 - ipmi_data->addr_space); 2392 - return; 2355 + if (!ipmi_get_info_from_resources(pdev, info)) { 2356 + rv = -EINVAL; 2357 + goto err_free; 2393 2358 } 2394 - info->io.addr_data = ipmi_data->base_addr; 2395 2359 2396 - info->io.regspacing = ipmi_data->offset; 2397 - if (!info->io.regspacing) 2398 - info->io.regspacing = DEFAULT_REGSPACING; 2399 - info->io.regsize = DEFAULT_REGSPACING; 2400 - info->io.regshift = 0; 2360 + rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr); 2361 + if (rv) { 2362 + dev_warn(&pdev->dev, "device has no slave-addr property"); 2363 + info->slave_addr = 0x20; 2364 + } else { 2365 + info->slave_addr = slave_addr; 2366 + } 2401 2367 2402 - info->slave_addr = ipmi_data->slave_addr; 2403 - 2404 - info->irq = ipmi_data->irq; 2405 - if (info->irq) 2368 + info->irq = platform_get_irq(pdev, 0); 2369 + if (info->irq > 0) 2406 2370 info->irq_setup = std_irq_setup; 2371 + else 2372 + info->irq = 0; 2373 + 2374 + info->dev = &pdev->dev; 2407 2375 2408 2376 pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n", 2409 2377 (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem", ··· 2381 2411 2382 2412 if (add_smi(info)) 2383 2413 kfree(info); 2414 + 2415 + return 0; 2416 + 2417 + err_free: 2418 + kfree(info); 2419 + return rv; 2384 2420 } 2385 - 2386 - static void dmi_find_bmc(void) 2421 + #else 2422 + static int dmi_ipmi_probe(struct platform_device *pdev) 2387 2423 { 2388 - const struct dmi_device *dev = NULL; 2389 - struct dmi_ipmi_data data; 2390 - int rv; 2391 - 2392 - while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { 2393 - memset(&data, 0, sizeof(data)); 2394 - rv = decode_dmi((const struct dmi_header *) dev->device_data, 2395 - &data); 2396 - if (!rv) 2397 - try_init_dmi(&data); 2398 - } 2424 + return -ENODEV; 2399 2425 } 2400 2426 #endif /* CONFIG_DMI */ 2401 2427 ··· 2650 2684 #endif 2651 2685 2652 2686 #ifdef CONFIG_ACPI 2687 + static int find_slave_address(struct smi_info *info, int slave_addr) 2688 + { 2689 + #ifdef CONFIG_IPMI_DMI_DECODE 2690 + if (!slave_addr) { 2691 + int type = -1; 2692 + u32 flags = IORESOURCE_IO; 2693 + 2694 + switch (info->si_type) { 2695 + case SI_KCS: 2696 + type = IPMI_DMI_TYPE_KCS; 2697 + break; 2698 + case SI_BT: 2699 + type = IPMI_DMI_TYPE_BT; 2700 + break; 2701 + case SI_SMIC: 2702 + type = IPMI_DMI_TYPE_SMIC; 2703 + break; 2704 + } 2705 + 2706 + if (info->io.addr_type == IPMI_MEM_ADDR_SPACE) 2707 + flags = IORESOURCE_MEM; 2708 + 2709 + slave_addr = ipmi_dmi_get_slave_addr(type, flags, 2710 + info->io.addr_data); 2711 + } 2712 + #endif 2713 + 2714 + return slave_addr; 2715 + } 2716 + 2653 2717 static int acpi_ipmi_probe(struct platform_device *dev) 2654 2718 { 2655 2719 struct smi_info *info; 2656 - struct resource *res, *res_second; 2657 2720 acpi_handle handle; 2658 2721 acpi_status status; 2659 2722 unsigned long long tmp; 2723 + struct resource *res; 2660 2724 int rv = -EINVAL; 2661 2725 2662 2726 if (!si_tryacpi) 2663 - return 0; 2727 + return -ENODEV; 2664 2728 2665 2729 handle = ACPI_HANDLE(&dev->dev); 2666 2730 if (!handle) ··· 2730 2734 goto err_free; 2731 2735 } 2732 2736 2733 - res = platform_get_resource(dev, IORESOURCE_IO, 0); 2734 - if (res) { 2735 - info->io_setup = port_setup; 2736 - info->io.addr_type = IPMI_IO_ADDR_SPACE; 2737 - } else { 2738 - res = platform_get_resource(dev, IORESOURCE_MEM, 0); 2739 - if (res) { 2740 - info->io_setup = mem_setup; 2741 - info->io.addr_type = IPMI_MEM_ADDR_SPACE; 2742 - } 2743 - } 2737 + res = ipmi_get_info_from_resources(dev, info); 2744 2738 if (!res) { 2745 - dev_err(&dev->dev, "no I/O or memory address\n"); 2739 + rv = -EINVAL; 2746 2740 goto err_free; 2747 2741 } 2748 - info->io.addr_data = res->start; 2749 - 2750 - info->io.regspacing = DEFAULT_REGSPACING; 2751 - res_second = platform_get_resource(dev, 2752 - (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? 2753 - IORESOURCE_IO : IORESOURCE_MEM, 2754 - 1); 2755 - if (res_second) { 2756 - if (res_second->start > info->io.addr_data) 2757 - info->io.regspacing = 2758 - res_second->start - info->io.addr_data; 2759 - } 2760 - info->io.regsize = DEFAULT_REGSPACING; 2761 - info->io.regshift = 0; 2762 2742 2763 2743 /* If _GPE exists, use it; otherwise use standard interrupts */ 2764 2744 status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp); ··· 2749 2777 info->irq_setup = std_irq_setup; 2750 2778 } 2751 2779 } 2780 + 2781 + info->slave_addr = find_slave_address(info, info->slave_addr); 2752 2782 2753 2783 info->dev = &dev->dev; 2754 2784 platform_set_drvdata(dev, info); ··· 2787 2813 if (of_ipmi_probe(dev) == 0) 2788 2814 return 0; 2789 2815 2790 - return acpi_ipmi_probe(dev); 2816 + if (acpi_ipmi_probe(dev) == 0) 2817 + return 0; 2818 + 2819 + return dmi_ipmi_probe(dev); 2791 2820 } 2792 2821 2793 2822 static int ipmi_remove(struct platform_device *dev) ··· 3763 3786 } 3764 3787 #endif 3765 3788 3766 - #ifdef CONFIG_DMI 3767 - if (si_trydmi) 3768 - dmi_find_bmc(); 3769 - #endif 3770 - 3771 3789 #ifdef CONFIG_ACPI 3772 3790 if (si_tryacpi) 3773 3791 spmi_find_bmc(); ··· 3910 3938 } 3911 3939 module_exit(cleanup_ipmi_si); 3912 3940 3941 + MODULE_ALIAS("platform:dmi-ipmi-si"); 3913 3942 MODULE_LICENSE("GPL"); 3914 3943 MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>"); 3915 3944 MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT"
+113 -63
drivers/char/ipmi/ipmi_ssif.c
··· 53 53 #include <linux/acpi.h> 54 54 #include <linux/ctype.h> 55 55 #include <linux/time64.h> 56 + #include "ipmi_dmi.h" 56 57 57 58 #define PFX "ipmi_ssif: " 58 59 #define DEVICE_NAME "ipmi_ssif" ··· 181 180 int slave_addr; 182 181 enum ipmi_addr_src addr_src; 183 182 union ipmi_smi_info_union addr_info; 183 + struct device *dev; 184 + struct i2c_client *client; 184 185 185 186 struct mutex clients_mutex; 186 187 struct list_head clients; ··· 411 408 msg = ipmi_alloc_smi_msg(); 412 409 if (!msg) { 413 410 ssif_info->ssif_state = SSIF_NORMAL; 411 + ipmi_ssif_unlock_cond(ssif_info, flags); 414 412 return; 415 413 } 416 414 ··· 434 430 msg = ipmi_alloc_smi_msg(); 435 431 if (!msg) { 436 432 ssif_info->ssif_state = SSIF_NORMAL; 433 + ipmi_ssif_unlock_cond(ssif_info, flags); 437 434 return; 438 435 } 439 436 ··· 766 761 result, len, data[2]); 767 762 } else if (data[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 768 763 || data[1] != IPMI_GET_MSG_FLAGS_CMD) { 764 + /* 765 + * Don't abort here, maybe it was a queued 766 + * response to a previous command. 767 + */ 768 + ipmi_ssif_unlock_cond(ssif_info, flags); 769 769 pr_warn(PFX "Invalid response getting flags: %x %x\n", 770 770 data[0], data[1]); 771 771 } else { ··· 1104 1094 { 1105 1095 struct ssif_info *ssif_info = send_info; 1106 1096 1107 - if (!i2c_get_adapter(ssif_info->client->adapter->nr)) 1097 + if (!i2c_get_adapter(i2c_adapter_id(ssif_info->client->adapter))) 1108 1098 return -ENODEV; 1109 1099 1110 1100 i2c_use_client(ssif_info->client); ··· 1179 1169 static int ssif_remove(struct i2c_client *client) 1180 1170 { 1181 1171 struct ssif_info *ssif_info = i2c_get_clientdata(client); 1172 + struct ssif_addr_info *addr_info; 1182 1173 int rv; 1183 1174 1184 1175 if (!ssif_info) ··· 1205 1194 if (ssif_info->thread) { 1206 1195 complete(&ssif_info->wake_thread); 1207 1196 kthread_stop(ssif_info->thread); 1197 + } 1198 + 1199 + list_for_each_entry(addr_info, &ssif_infos, link) { 1200 + if (addr_info->client == client) { 1201 + addr_info->client = NULL; 1202 + break; 1203 + } 1208 1204 } 1209 1205 1210 1206 /* ··· 1422 1404 1423 1405 static int find_slave_address(struct i2c_client *client, int slave_addr) 1424 1406 { 1425 - struct ssif_addr_info *info; 1426 - 1427 - if (slave_addr) 1428 - return slave_addr; 1429 - 1430 - /* 1431 - * Came in without a slave address, search around to see if 1432 - * the other sources have a slave address. This lets us pick 1433 - * up an SMBIOS slave address when using ACPI. 1434 - */ 1435 - list_for_each_entry(info, &ssif_infos, link) { 1436 - if (info->binfo.addr != client->addr) 1437 - continue; 1438 - if (info->adapter_name && client->adapter->name && 1439 - strcmp_nospace(info->adapter_name, 1440 - client->adapter->name)) 1441 - continue; 1442 - if (info->slave_addr) { 1443 - slave_addr = info->slave_addr; 1444 - break; 1445 - } 1446 - } 1407 + #ifdef CONFIG_IPMI_DMI_DECODE 1408 + if (!slave_addr) 1409 + slave_addr = ipmi_dmi_get_slave_addr( 1410 + IPMI_DMI_TYPE_SSIF, 1411 + i2c_adapter_id(client->adapter), 1412 + client->addr); 1413 + #endif 1447 1414 1448 1415 return slave_addr; 1449 1416 } ··· 1450 1447 u8 slave_addr = 0; 1451 1448 struct ssif_addr_info *addr_info = NULL; 1452 1449 1453 - 1454 1450 resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); 1455 1451 if (!resp) 1456 1452 return -ENOMEM; ··· 1470 1468 ssif_info->addr_source = addr_info->addr_src; 1471 1469 ssif_info->ssif_debug = addr_info->debug; 1472 1470 ssif_info->addr_info = addr_info->addr_info; 1471 + addr_info->client = client; 1473 1472 slave_addr = addr_info->slave_addr; 1474 1473 } 1475 1474 } ··· 1667 1664 { 1668 1665 unsigned int thread_num; 1669 1666 1670 - thread_num = ((ssif_info->client->adapter->nr << 8) | 1667 + thread_num = ((i2c_adapter_id(ssif_info->client->adapter) 1668 + << 8) | 1671 1669 ssif_info->client->addr); 1672 1670 init_completion(&ssif_info->wake_thread); 1673 1671 ssif_info->thread = kthread_run(ipmi_ssif_thread, ssif_info, ··· 1709 1705 } 1710 1706 1711 1707 out: 1712 - if (rv) 1708 + if (rv) { 1709 + /* 1710 + * Note that if addr_info->client is assigned, we 1711 + * leave it. The i2c client hangs around even if we 1712 + * return a failure here, and the failure here is not 1713 + * propagated back to the i2c code. This seems to be 1714 + * design intent, strange as it may be. But if we 1715 + * don't leave it, ssif_platform_remove will not remove 1716 + * the client like it should. 1717 + */ 1718 + dev_err(&client->dev, "Unable to start IPMI SSIF: %d\n", rv); 1713 1719 kfree(ssif_info); 1720 + } 1714 1721 kfree(resp); 1715 1722 return rv; 1716 1723 ··· 1746 1731 1747 1732 static int new_ssif_client(int addr, char *adapter_name, 1748 1733 int debug, int slave_addr, 1749 - enum ipmi_addr_src addr_src) 1734 + enum ipmi_addr_src addr_src, 1735 + struct device *dev) 1750 1736 { 1751 1737 struct ssif_addr_info *addr_info; 1752 1738 int rv = 0; ··· 1780 1764 addr_info->debug = debug; 1781 1765 addr_info->slave_addr = slave_addr; 1782 1766 addr_info->addr_src = addr_src; 1767 + addr_info->dev = dev; 1768 + 1769 + if (dev) 1770 + dev_set_drvdata(dev, addr_info); 1783 1771 1784 1772 list_add_tail(&addr_info->link, &ssif_infos); 1785 1773 ··· 1922 1902 1923 1903 myaddr = spmi->addr.address & 0x7f; 1924 1904 1925 - return new_ssif_client(myaddr, NULL, 0, 0, SI_SPMI); 1905 + return new_ssif_client(myaddr, NULL, 0, 0, SI_SPMI, NULL); 1926 1906 } 1927 1907 1928 1908 static void spmi_find_bmc(void) ··· 1951 1931 #endif 1952 1932 1953 1933 #ifdef CONFIG_DMI 1954 - static int decode_dmi(const struct dmi_device *dmi_dev) 1934 + static int dmi_ipmi_probe(struct platform_device *pdev) 1955 1935 { 1956 - struct dmi_header *dm = dmi_dev->device_data; 1957 - u8 *data = (u8 *) dm; 1958 - u8 len = dm->length; 1959 - unsigned short myaddr; 1960 - int slave_addr; 1936 + u8 type, slave_addr = 0; 1937 + u16 i2c_addr; 1938 + int rv; 1961 1939 1962 - if (num_addrs >= MAX_SSIF_BMCS) 1963 - return -1; 1940 + if (!ssif_trydmi) 1941 + return -ENODEV; 1964 1942 1965 - if (len < 9) 1966 - return -1; 1943 + rv = device_property_read_u8(&pdev->dev, "ipmi-type", &type); 1944 + if (rv) 1945 + return -ENODEV; 1967 1946 1968 - if (data[0x04] != 4) /* Not SSIF */ 1969 - return -1; 1947 + if (type != IPMI_DMI_TYPE_SSIF) 1948 + return -ENODEV; 1970 1949 1971 - if ((data[8] >> 1) == 0) { 1972 - /* 1973 - * Some broken systems put the I2C address in 1974 - * the slave address field. We try to 1975 - * accommodate them here. 1976 - */ 1977 - myaddr = data[6] >> 1; 1978 - slave_addr = 0; 1979 - } else { 1980 - myaddr = data[8] >> 1; 1981 - slave_addr = data[6]; 1950 + rv = device_property_read_u16(&pdev->dev, "i2c-addr", &i2c_addr); 1951 + if (rv) { 1952 + dev_warn(&pdev->dev, PFX "No i2c-addr property\n"); 1953 + return -ENODEV; 1982 1954 } 1983 1955 1984 - return new_ssif_client(myaddr, NULL, 0, slave_addr, SI_SMBIOS); 1985 - } 1956 + rv = device_property_read_u8(&pdev->dev, "slave-addr", &slave_addr); 1957 + if (rv) 1958 + dev_warn(&pdev->dev, "device has no slave-addr property"); 1986 1959 1987 - static void dmi_iterator(void) 1988 - { 1989 - const struct dmi_device *dev = NULL; 1990 - 1991 - while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) 1992 - decode_dmi(dev); 1960 + return new_ssif_client(i2c_addr, NULL, 0, 1961 + slave_addr, SI_SMBIOS, &pdev->dev); 1993 1962 } 1994 1963 #else 1995 - static void dmi_iterator(void) { } 1964 + static int dmi_ipmi_probe(struct platform_device *pdev) 1965 + { 1966 + return -ENODEV; 1967 + } 1996 1968 #endif 1997 1969 1998 1970 static const struct i2c_device_id ssif_id[] = { ··· 2005 1993 .detect = ssif_detect 2006 1994 }; 2007 1995 1996 + static int ssif_platform_probe(struct platform_device *dev) 1997 + { 1998 + return dmi_ipmi_probe(dev); 1999 + } 2000 + 2001 + static int ssif_platform_remove(struct platform_device *dev) 2002 + { 2003 + struct ssif_addr_info *addr_info = dev_get_drvdata(&dev->dev); 2004 + 2005 + if (!addr_info) 2006 + return 0; 2007 + 2008 + mutex_lock(&ssif_infos_mutex); 2009 + if (addr_info->client) 2010 + i2c_unregister_device(addr_info->client); 2011 + 2012 + list_del(&addr_info->link); 2013 + kfree(addr_info); 2014 + mutex_unlock(&ssif_infos_mutex); 2015 + return 0; 2016 + } 2017 + 2018 + static struct platform_driver ipmi_driver = { 2019 + .driver = { 2020 + .name = DEVICE_NAME, 2021 + }, 2022 + .probe = ssif_platform_probe, 2023 + .remove = ssif_platform_remove, 2024 + }; 2025 + 2008 2026 static int init_ipmi_ssif(void) 2009 2027 { 2010 2028 int i; ··· 2049 2007 for (i = 0; i < num_addrs; i++) { 2050 2008 rv = new_ssif_client(addr[i], adapter_name[i], 2051 2009 dbg[i], slave_addrs[i], 2052 - SI_HARDCODED); 2010 + SI_HARDCODED, NULL); 2053 2011 if (rv) 2054 2012 pr_err(PFX 2055 2013 "Couldn't add hardcoded device at addr 0x%x\n", ··· 2059 2017 if (ssif_tryacpi) 2060 2018 ssif_i2c_driver.driver.acpi_match_table = 2061 2019 ACPI_PTR(ssif_acpi_match); 2062 - if (ssif_trydmi) 2063 - dmi_iterator(); 2020 + 2064 2021 if (ssif_tryacpi) 2065 2022 spmi_find_bmc(); 2023 + 2024 + if (ssif_trydmi) { 2025 + rv = platform_driver_register(&ipmi_driver); 2026 + if (rv) 2027 + pr_err(PFX "Unable to register driver: %d\n", rv); 2028 + } 2066 2029 2067 2030 ssif_i2c_driver.address_list = ssif_address_list(); 2068 2031 ··· 2088 2041 2089 2042 i2c_del_driver(&ssif_i2c_driver); 2090 2043 2044 + platform_driver_unregister(&ipmi_driver); 2045 + 2091 2046 free_ssif_clients(); 2092 2047 } 2093 2048 module_exit(cleanup_ipmi_ssif); 2094 2049 2050 + MODULE_ALIAS("platform:dmi-ipmi-ssif"); 2095 2051 MODULE_AUTHOR("Todd C Davis <todd.c.davis@intel.com>, Corey Minyard <minyard@acm.org>"); 2096 2052 MODULE_DESCRIPTION("IPMI driver for management controllers on a SMBus"); 2097 2053 MODULE_LICENSE("GPL");
+4 -3
drivers/char/ipmi/ipmi_watchdog.c
··· 1163 1163 ipmi_watchdog_state = WDOG_TIMEOUT_NONE; 1164 1164 ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB); 1165 1165 } else if (ipmi_watchdog_state != WDOG_TIMEOUT_NONE) { 1166 - /* Set a long timer to let the reboot happens, but 1167 - reboot if it hangs, but only if the watchdog 1166 + /* Set a long timer to let the reboot happen or 1167 + reset if it hangs, but only if the watchdog 1168 1168 timer was already running. */ 1169 - timeout = 120; 1169 + if (timeout < 120) 1170 + timeout = 120; 1170 1171 pretimeout = 0; 1171 1172 ipmi_watchdog_state = WDOG_TIMEOUT_RESET; 1172 1173 ipmi_set_timeout(IPMI_SET_TIMEOUT_NO_HB);