Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ipmi_si.c |
| 3 | * |
| 4 | * The interface to the IPMI driver for the system interfaces (KCS, SMIC, |
| 5 | * BT). |
| 6 | * |
| 7 | * Author: MontaVista Software, Inc. |
| 8 | * Corey Minyard <minyard@mvista.com> |
| 9 | * source@mvista.com |
| 10 | * |
| 11 | * Copyright 2002 MontaVista Software Inc. |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 12 | * Copyright 2006 IBM Corp., Christian Krafft <krafft@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify it |
| 15 | * under the terms of the GNU General Public License as published by the |
| 16 | * Free Software Foundation; either version 2 of the License, or (at your |
| 17 | * option) any later version. |
| 18 | * |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 26 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 27 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 28 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 29 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | * |
| 31 | * You should have received a copy of the GNU General Public License along |
| 32 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 33 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | * This file holds the "policy" for the interface to the SMI state |
| 38 | * machine. It does the configuration, handles timers and interrupts, |
| 39 | * and drives the real SMI state machine. |
| 40 | */ |
| 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/module.h> |
| 43 | #include <linux/moduleparam.h> |
| 44 | #include <asm/system.h> |
| 45 | #include <linux/sched.h> |
| 46 | #include <linux/timer.h> |
| 47 | #include <linux/errno.h> |
| 48 | #include <linux/spinlock.h> |
| 49 | #include <linux/slab.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/list.h> |
| 52 | #include <linux/pci.h> |
| 53 | #include <linux/ioport.h> |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 54 | #include <linux/notifier.h> |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 55 | #include <linux/mutex.h> |
Matt Domsch | e9a705a | 2005-11-07 01:00:04 -0800 | [diff] [blame] | 56 | #include <linux/kthread.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #include <linux/interrupt.h> |
| 59 | #include <linux/rcupdate.h> |
| 60 | #include <linux/ipmi_smi.h> |
| 61 | #include <asm/io.h> |
| 62 | #include "ipmi_si_sm.h" |
| 63 | #include <linux/init.h> |
Andrey Panin | b224cd3 | 2005-09-06 15:18:37 -0700 | [diff] [blame] | 64 | #include <linux/dmi.h> |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 65 | #include <linux/string.h> |
| 66 | #include <linux/ctype.h> |
Bjorn Helgaas | 9e368fa | 2009-11-17 17:05:34 -0700 | [diff] [blame] | 67 | #include <linux/pnp.h> |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 68 | |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 69 | #ifdef CONFIG_PPC_OF |
Stephen Rothwell | 11c675c | 2008-05-23 16:22:42 +1000 | [diff] [blame] | 70 | #include <linux/of_device.h> |
| 71 | #include <linux/of_platform.h> |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 72 | #endif |
| 73 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 74 | #define PFX "ipmi_si: " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* Measure times between events in the driver. */ |
| 77 | #undef DEBUG_TIMING |
| 78 | |
| 79 | /* Call every 10 ms. */ |
| 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 /* .25ms when the SM request a |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 84 | short timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | enum si_intf_state { |
| 87 | SI_NORMAL, |
| 88 | SI_GETTING_FLAGS, |
| 89 | SI_GETTING_EVENTS, |
| 90 | SI_CLEARING_FLAGS, |
| 91 | SI_CLEARING_FLAGS_THEN_SET_IRQ, |
| 92 | SI_GETTING_MESSAGES, |
| 93 | SI_ENABLE_INTERRUPTS1, |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 94 | SI_ENABLE_INTERRUPTS2, |
| 95 | SI_DISABLE_INTERRUPTS1, |
| 96 | SI_DISABLE_INTERRUPTS2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | /* FIXME - add watchdog stuff. */ |
| 98 | }; |
| 99 | |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 100 | /* Some BT-specific defines we need here. */ |
| 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 |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | enum si_type { |
| 106 | SI_KCS, SI_SMIC, SI_BT |
| 107 | }; |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 108 | static char *si_to_str[] = { "kcs", "smic", "bt" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 110 | #define DEVICE_NAME "ipmi_si" |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 111 | |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 112 | static struct platform_driver ipmi_driver = { |
| 113 | .driver = { |
| 114 | .name = DEVICE_NAME, |
| 115 | .bus = &platform_bus_type |
| 116 | } |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 117 | }; |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 118 | |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * Indexes into stats[] in smi_info below. |
| 122 | */ |
Corey Minyard | ba8ff1c | 2008-04-29 01:01:08 -0700 | [diff] [blame] | 123 | enum si_stat_indexes { |
| 124 | /* |
| 125 | * Number of times the driver requested a timer while an operation |
| 126 | * was in progress. |
| 127 | */ |
| 128 | SI_STAT_short_timeouts = 0, |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 129 | |
Corey Minyard | ba8ff1c | 2008-04-29 01:01:08 -0700 | [diff] [blame] | 130 | /* |
| 131 | * Number of times the driver requested a timer while nothing was in |
| 132 | * progress. |
| 133 | */ |
| 134 | SI_STAT_long_timeouts, |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 135 | |
Corey Minyard | ba8ff1c | 2008-04-29 01:01:08 -0700 | [diff] [blame] | 136 | /* Number of times the interface was idle while being polled. */ |
| 137 | SI_STAT_idles, |
| 138 | |
| 139 | /* Number of interrupts the driver handled. */ |
| 140 | SI_STAT_interrupts, |
| 141 | |
| 142 | /* Number of time the driver got an ATTN from the hardware. */ |
| 143 | SI_STAT_attentions, |
| 144 | |
| 145 | /* Number of times the driver requested flags from the hardware. */ |
| 146 | SI_STAT_flag_fetches, |
| 147 | |
| 148 | /* Number of times the hardware didn't follow the state machine. */ |
| 149 | SI_STAT_hosed_count, |
| 150 | |
| 151 | /* Number of completed messages. */ |
| 152 | SI_STAT_complete_transactions, |
| 153 | |
| 154 | /* Number of IPMI events received from the hardware. */ |
| 155 | SI_STAT_events, |
| 156 | |
| 157 | /* Number of watchdog pretimeouts. */ |
| 158 | SI_STAT_watchdog_pretimeouts, |
| 159 | |
| 160 | /* Number of asyncronous messages received. */ |
| 161 | SI_STAT_incoming_messages, |
| 162 | |
| 163 | |
| 164 | /* This *must* remain last, add new values above this. */ |
| 165 | SI_NUM_STATS |
| 166 | }; |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 167 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 168 | struct smi_info { |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 169 | int intf_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | ipmi_smi_t intf; |
| 171 | struct si_sm_data *si_sm; |
| 172 | struct si_sm_handlers *handlers; |
| 173 | enum si_type si_type; |
| 174 | spinlock_t si_lock; |
| 175 | spinlock_t msg_lock; |
| 176 | struct list_head xmit_msgs; |
| 177 | struct list_head hp_xmit_msgs; |
| 178 | struct ipmi_smi_msg *curr_msg; |
| 179 | enum si_intf_state si_state; |
| 180 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 181 | /* |
| 182 | * Used to handle the various types of I/O that can occur with |
| 183 | * IPMI |
| 184 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | struct si_sm_io io; |
| 186 | int (*io_setup)(struct smi_info *info); |
| 187 | void (*io_cleanup)(struct smi_info *info); |
| 188 | int (*irq_setup)(struct smi_info *info); |
| 189 | void (*irq_cleanup)(struct smi_info *info); |
| 190 | unsigned int io_size; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 191 | char *addr_source; /* ACPI, PCI, SMBIOS, hardcode, default. */ |
| 192 | void (*addr_source_cleanup)(struct smi_info *info); |
| 193 | void *addr_source_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 195 | /* |
| 196 | * Per-OEM handler, called from handle_flags(). Returns 1 |
| 197 | * when handle_flags() needs to be re-run or 0 indicating it |
| 198 | * set si_state itself. |
| 199 | */ |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 200 | int (*oem_data_avail_handler)(struct smi_info *smi_info); |
| 201 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 202 | /* |
| 203 | * Flags from the last GET_MSG_FLAGS command, used when an ATTN |
| 204 | * is set to hold the flags until we are done handling everything |
| 205 | * from the flags. |
| 206 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | #define RECEIVE_MSG_AVAIL 0x01 |
| 208 | #define EVENT_MSG_BUFFER_FULL 0x02 |
| 209 | #define WDT_PRE_TIMEOUT_INT 0x08 |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 210 | #define OEM0_DATA_AVAIL 0x20 |
| 211 | #define OEM1_DATA_AVAIL 0x40 |
| 212 | #define OEM2_DATA_AVAIL 0x80 |
| 213 | #define OEM_DATA_AVAIL (OEM0_DATA_AVAIL | \ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 214 | OEM1_DATA_AVAIL | \ |
| 215 | OEM2_DATA_AVAIL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | unsigned char msg_flags; |
| 217 | |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 218 | /* Does the BMC have an event buffer? */ |
| 219 | char has_event_buffer; |
| 220 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 221 | /* |
| 222 | * If set to true, this will request events the next time the |
| 223 | * state machine is idle. |
| 224 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | atomic_t req_events; |
| 226 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 227 | /* |
| 228 | * If true, run the state machine to completion on every send |
| 229 | * call. Generally used after a panic to make sure stuff goes |
| 230 | * out. |
| 231 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | int run_to_completion; |
| 233 | |
| 234 | /* The I/O port of an SI interface. */ |
| 235 | int port; |
| 236 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 237 | /* |
| 238 | * The space between start addresses of the two ports. For |
| 239 | * instance, if the first port is 0xca2 and the spacing is 4, then |
| 240 | * the second port is 0xca6. |
| 241 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | unsigned int spacing; |
| 243 | |
| 244 | /* zero if no irq; */ |
| 245 | int irq; |
| 246 | |
| 247 | /* The timer for this si. */ |
| 248 | struct timer_list si_timer; |
| 249 | |
| 250 | /* The time (in jiffies) the last timeout occurred at. */ |
| 251 | unsigned long last_timeout_jiffies; |
| 252 | |
| 253 | /* Used to gracefully stop the timer without race conditions. */ |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 254 | atomic_t stop_operation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 256 | /* |
| 257 | * The driver will disable interrupts when it gets into a |
| 258 | * situation where it cannot handle messages due to lack of |
| 259 | * memory. Once that situation clears up, it will re-enable |
| 260 | * interrupts. |
| 261 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | int interrupt_disabled; |
| 263 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 264 | /* From the get device id response... */ |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 265 | struct ipmi_device_id device_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 267 | /* Driver model stuff. */ |
| 268 | struct device *dev; |
| 269 | struct platform_device *pdev; |
| 270 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 271 | /* |
| 272 | * True if we allocated the device, false if it came from |
| 273 | * someplace else (like PCI). |
| 274 | */ |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 275 | int dev_registered; |
| 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /* Slave address, could be reported from DMI. */ |
| 278 | unsigned char slave_addr; |
| 279 | |
| 280 | /* Counters and things for the proc filesystem. */ |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 281 | atomic_t stats[SI_NUM_STATS]; |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 282 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 283 | struct task_struct *thread; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 284 | |
| 285 | struct list_head link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | }; |
| 287 | |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 288 | #define smi_inc_stat(smi, stat) \ |
| 289 | atomic_inc(&(smi)->stats[SI_STAT_ ## stat]) |
| 290 | #define smi_get_stat(smi, stat) \ |
| 291 | ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat])) |
| 292 | |
Corey Minyard | a51f4a8 | 2006-10-03 01:13:59 -0700 | [diff] [blame] | 293 | #define SI_MAX_PARMS 4 |
| 294 | |
| 295 | static int force_kipmid[SI_MAX_PARMS]; |
| 296 | static int num_force_kipmid; |
| 297 | |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 298 | static unsigned int kipmid_max_busy_us[SI_MAX_PARMS]; |
| 299 | static int num_max_busy_us; |
| 300 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 301 | static int unload_when_empty = 1; |
| 302 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 303 | static int try_smi_init(struct smi_info *smi); |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 304 | static void cleanup_one_si(struct smi_info *to_clean); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 305 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 306 | static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 307 | static int register_xaction_notifier(struct notifier_block *nb) |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 308 | { |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 309 | return atomic_notifier_chain_register(&xaction_notifier_list, nb); |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | static void deliver_recv_msg(struct smi_info *smi_info, |
| 313 | struct ipmi_smi_msg *msg) |
| 314 | { |
| 315 | /* Deliver the message to the upper layer with the lock |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 316 | released. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | spin_unlock(&(smi_info->si_lock)); |
| 318 | ipmi_smi_msg_received(smi_info->intf, msg); |
| 319 | spin_lock(&(smi_info->si_lock)); |
| 320 | } |
| 321 | |
Corey Minyard | 4d7cbac | 2006-12-06 20:41:14 -0800 | [diff] [blame] | 322 | static void return_hosed_msg(struct smi_info *smi_info, int cCode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
| 324 | struct ipmi_smi_msg *msg = smi_info->curr_msg; |
| 325 | |
Corey Minyard | 4d7cbac | 2006-12-06 20:41:14 -0800 | [diff] [blame] | 326 | if (cCode < 0 || cCode > IPMI_ERR_UNSPECIFIED) |
| 327 | cCode = IPMI_ERR_UNSPECIFIED; |
| 328 | /* else use it as is */ |
| 329 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | /* Make it a reponse */ |
| 331 | msg->rsp[0] = msg->data[0] | 4; |
| 332 | msg->rsp[1] = msg->data[1]; |
Corey Minyard | 4d7cbac | 2006-12-06 20:41:14 -0800 | [diff] [blame] | 333 | msg->rsp[2] = cCode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | msg->rsp_size = 3; |
| 335 | |
| 336 | smi_info->curr_msg = NULL; |
| 337 | deliver_recv_msg(smi_info, msg); |
| 338 | } |
| 339 | |
| 340 | static enum si_sm_result start_next_msg(struct smi_info *smi_info) |
| 341 | { |
| 342 | int rv; |
| 343 | struct list_head *entry = NULL; |
| 344 | #ifdef DEBUG_TIMING |
| 345 | struct timeval t; |
| 346 | #endif |
| 347 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 348 | /* |
| 349 | * No need to save flags, we aleady have interrupts off and we |
| 350 | * already hold the SMI lock. |
| 351 | */ |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 352 | if (!smi_info->run_to_completion) |
| 353 | spin_lock(&(smi_info->msg_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | /* Pick the high priority queue first. */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 356 | if (!list_empty(&(smi_info->hp_xmit_msgs))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | entry = smi_info->hp_xmit_msgs.next; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 358 | } else if (!list_empty(&(smi_info->xmit_msgs))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | entry = smi_info->xmit_msgs.next; |
| 360 | } |
| 361 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 362 | if (!entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | smi_info->curr_msg = NULL; |
| 364 | rv = SI_SM_IDLE; |
| 365 | } else { |
| 366 | int err; |
| 367 | |
| 368 | list_del(entry); |
| 369 | smi_info->curr_msg = list_entry(entry, |
| 370 | struct ipmi_smi_msg, |
| 371 | link); |
| 372 | #ifdef DEBUG_TIMING |
| 373 | do_gettimeofday(&t); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 374 | printk(KERN_DEBUG "**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | #endif |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 376 | err = atomic_notifier_call_chain(&xaction_notifier_list, |
| 377 | 0, smi_info); |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 378 | if (err & NOTIFY_STOP_MASK) { |
| 379 | rv = SI_SM_CALL_WITHOUT_DELAY; |
| 380 | goto out; |
| 381 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | err = smi_info->handlers->start_transaction( |
| 383 | smi_info->si_sm, |
| 384 | smi_info->curr_msg->data, |
| 385 | smi_info->curr_msg->data_size); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 386 | if (err) |
Corey Minyard | 4d7cbac | 2006-12-06 20:41:14 -0800 | [diff] [blame] | 387 | return_hosed_msg(smi_info, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | rv = SI_SM_CALL_WITHOUT_DELAY; |
| 390 | } |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 391 | out: |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 392 | if (!smi_info->run_to_completion) |
| 393 | spin_unlock(&(smi_info->msg_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | return rv; |
| 396 | } |
| 397 | |
| 398 | static void start_enable_irq(struct smi_info *smi_info) |
| 399 | { |
| 400 | unsigned char msg[2]; |
| 401 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 402 | /* |
| 403 | * If we are enabling interrupts, we have to tell the |
| 404 | * BMC to use them. |
| 405 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 407 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
| 408 | |
| 409 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
| 410 | smi_info->si_state = SI_ENABLE_INTERRUPTS1; |
| 411 | } |
| 412 | |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 413 | static void start_disable_irq(struct smi_info *smi_info) |
| 414 | { |
| 415 | unsigned char msg[2]; |
| 416 | |
| 417 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 418 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
| 419 | |
| 420 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
| 421 | smi_info->si_state = SI_DISABLE_INTERRUPTS1; |
| 422 | } |
| 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | static void start_clear_flags(struct smi_info *smi_info) |
| 425 | { |
| 426 | unsigned char msg[3]; |
| 427 | |
| 428 | /* Make sure the watchdog pre-timeout flag is not set at startup. */ |
| 429 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 430 | msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD; |
| 431 | msg[2] = WDT_PRE_TIMEOUT_INT; |
| 432 | |
| 433 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3); |
| 434 | smi_info->si_state = SI_CLEARING_FLAGS; |
| 435 | } |
| 436 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 437 | /* |
| 438 | * When we have a situtaion where we run out of memory and cannot |
| 439 | * allocate messages, we just leave them in the BMC and run the system |
| 440 | * polled until we can allocate some memory. Once we have some |
| 441 | * memory, we will re-enable the interrupt. |
| 442 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | static inline void disable_si_irq(struct smi_info *smi_info) |
| 444 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 445 | if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 446 | start_disable_irq(smi_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | smi_info->interrupt_disabled = 1; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | static inline void enable_si_irq(struct smi_info *smi_info) |
| 452 | { |
| 453 | if ((smi_info->irq) && (smi_info->interrupt_disabled)) { |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 454 | start_enable_irq(smi_info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | smi_info->interrupt_disabled = 0; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | static void handle_flags(struct smi_info *smi_info) |
| 460 | { |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 461 | retry: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | if (smi_info->msg_flags & WDT_PRE_TIMEOUT_INT) { |
| 463 | /* Watchdog pre-timeout */ |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 464 | smi_inc_stat(smi_info, watchdog_pretimeouts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | start_clear_flags(smi_info); |
| 467 | smi_info->msg_flags &= ~WDT_PRE_TIMEOUT_INT; |
| 468 | spin_unlock(&(smi_info->si_lock)); |
| 469 | ipmi_smi_watchdog_pretimeout(smi_info->intf); |
| 470 | spin_lock(&(smi_info->si_lock)); |
| 471 | } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) { |
| 472 | /* Messages available. */ |
| 473 | smi_info->curr_msg = ipmi_alloc_smi_msg(); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 474 | if (!smi_info->curr_msg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | disable_si_irq(smi_info); |
| 476 | smi_info->si_state = SI_NORMAL; |
| 477 | return; |
| 478 | } |
| 479 | enable_si_irq(smi_info); |
| 480 | |
| 481 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 482 | smi_info->curr_msg->data[1] = IPMI_GET_MSG_CMD; |
| 483 | smi_info->curr_msg->data_size = 2; |
| 484 | |
| 485 | smi_info->handlers->start_transaction( |
| 486 | smi_info->si_sm, |
| 487 | smi_info->curr_msg->data, |
| 488 | smi_info->curr_msg->data_size); |
| 489 | smi_info->si_state = SI_GETTING_MESSAGES; |
| 490 | } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) { |
| 491 | /* Events available. */ |
| 492 | smi_info->curr_msg = ipmi_alloc_smi_msg(); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 493 | if (!smi_info->curr_msg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | disable_si_irq(smi_info); |
| 495 | smi_info->si_state = SI_NORMAL; |
| 496 | return; |
| 497 | } |
| 498 | enable_si_irq(smi_info); |
| 499 | |
| 500 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 501 | smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD; |
| 502 | smi_info->curr_msg->data_size = 2; |
| 503 | |
| 504 | smi_info->handlers->start_transaction( |
| 505 | smi_info->si_sm, |
| 506 | smi_info->curr_msg->data, |
| 507 | smi_info->curr_msg->data_size); |
| 508 | smi_info->si_state = SI_GETTING_EVENTS; |
Corey Minyard | 4064d5e | 2006-09-16 12:15:41 -0700 | [diff] [blame] | 509 | } else if (smi_info->msg_flags & OEM_DATA_AVAIL && |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 510 | smi_info->oem_data_avail_handler) { |
Corey Minyard | 4064d5e | 2006-09-16 12:15:41 -0700 | [diff] [blame] | 511 | if (smi_info->oem_data_avail_handler(smi_info)) |
| 512 | goto retry; |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 513 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | smi_info->si_state = SI_NORMAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | static void handle_transaction_done(struct smi_info *smi_info) |
| 518 | { |
| 519 | struct ipmi_smi_msg *msg; |
| 520 | #ifdef DEBUG_TIMING |
| 521 | struct timeval t; |
| 522 | |
| 523 | do_gettimeofday(&t); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 524 | printk(KERN_DEBUG "**Done: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | #endif |
| 526 | switch (smi_info->si_state) { |
| 527 | case SI_NORMAL: |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 528 | if (!smi_info->curr_msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | break; |
| 530 | |
| 531 | smi_info->curr_msg->rsp_size |
| 532 | = smi_info->handlers->get_result( |
| 533 | smi_info->si_sm, |
| 534 | smi_info->curr_msg->rsp, |
| 535 | IPMI_MAX_MSG_LENGTH); |
| 536 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 537 | /* |
| 538 | * Do this here becase deliver_recv_msg() releases the |
| 539 | * lock, and a new message can be put in during the |
| 540 | * time the lock is released. |
| 541 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | msg = smi_info->curr_msg; |
| 543 | smi_info->curr_msg = NULL; |
| 544 | deliver_recv_msg(smi_info, msg); |
| 545 | break; |
| 546 | |
| 547 | case SI_GETTING_FLAGS: |
| 548 | { |
| 549 | unsigned char msg[4]; |
| 550 | unsigned int len; |
| 551 | |
| 552 | /* We got the flags from the SMI, now handle them. */ |
| 553 | len = smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
| 554 | if (msg[2] != 0) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 555 | /* Error fetching flags, just give up for now. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | smi_info->si_state = SI_NORMAL; |
| 557 | } else if (len < 4) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 558 | /* |
| 559 | * Hmm, no flags. That's technically illegal, but |
| 560 | * don't use uninitialized data. |
| 561 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | smi_info->si_state = SI_NORMAL; |
| 563 | } else { |
| 564 | smi_info->msg_flags = msg[3]; |
| 565 | handle_flags(smi_info); |
| 566 | } |
| 567 | break; |
| 568 | } |
| 569 | |
| 570 | case SI_CLEARING_FLAGS: |
| 571 | case SI_CLEARING_FLAGS_THEN_SET_IRQ: |
| 572 | { |
| 573 | unsigned char msg[3]; |
| 574 | |
| 575 | /* We cleared the flags. */ |
| 576 | smi_info->handlers->get_result(smi_info->si_sm, msg, 3); |
| 577 | if (msg[2] != 0) { |
| 578 | /* Error clearing flags */ |
| 579 | printk(KERN_WARNING |
| 580 | "ipmi_si: Error clearing flags: %2.2x\n", |
| 581 | msg[2]); |
| 582 | } |
| 583 | if (smi_info->si_state == SI_CLEARING_FLAGS_THEN_SET_IRQ) |
| 584 | start_enable_irq(smi_info); |
| 585 | else |
| 586 | smi_info->si_state = SI_NORMAL; |
| 587 | break; |
| 588 | } |
| 589 | |
| 590 | case SI_GETTING_EVENTS: |
| 591 | { |
| 592 | smi_info->curr_msg->rsp_size |
| 593 | = smi_info->handlers->get_result( |
| 594 | smi_info->si_sm, |
| 595 | smi_info->curr_msg->rsp, |
| 596 | IPMI_MAX_MSG_LENGTH); |
| 597 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 598 | /* |
| 599 | * Do this here becase deliver_recv_msg() releases the |
| 600 | * lock, and a new message can be put in during the |
| 601 | * time the lock is released. |
| 602 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | msg = smi_info->curr_msg; |
| 604 | smi_info->curr_msg = NULL; |
| 605 | if (msg->rsp[2] != 0) { |
| 606 | /* Error getting event, probably done. */ |
| 607 | msg->done(msg); |
| 608 | |
| 609 | /* Take off the event flag. */ |
| 610 | smi_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL; |
| 611 | handle_flags(smi_info); |
| 612 | } else { |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 613 | smi_inc_stat(smi_info, events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 615 | /* |
| 616 | * Do this before we deliver the message |
| 617 | * because delivering the message releases the |
| 618 | * lock and something else can mess with the |
| 619 | * state. |
| 620 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | handle_flags(smi_info); |
| 622 | |
| 623 | deliver_recv_msg(smi_info, msg); |
| 624 | } |
| 625 | break; |
| 626 | } |
| 627 | |
| 628 | case SI_GETTING_MESSAGES: |
| 629 | { |
| 630 | smi_info->curr_msg->rsp_size |
| 631 | = smi_info->handlers->get_result( |
| 632 | smi_info->si_sm, |
| 633 | smi_info->curr_msg->rsp, |
| 634 | IPMI_MAX_MSG_LENGTH); |
| 635 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 636 | /* |
| 637 | * Do this here becase deliver_recv_msg() releases the |
| 638 | * lock, and a new message can be put in during the |
| 639 | * time the lock is released. |
| 640 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | msg = smi_info->curr_msg; |
| 642 | smi_info->curr_msg = NULL; |
| 643 | if (msg->rsp[2] != 0) { |
| 644 | /* Error getting event, probably done. */ |
| 645 | msg->done(msg); |
| 646 | |
| 647 | /* Take off the msg flag. */ |
| 648 | smi_info->msg_flags &= ~RECEIVE_MSG_AVAIL; |
| 649 | handle_flags(smi_info); |
| 650 | } else { |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 651 | smi_inc_stat(smi_info, incoming_messages); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 653 | /* |
| 654 | * Do this before we deliver the message |
| 655 | * because delivering the message releases the |
| 656 | * lock and something else can mess with the |
| 657 | * state. |
| 658 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | handle_flags(smi_info); |
| 660 | |
| 661 | deliver_recv_msg(smi_info, msg); |
| 662 | } |
| 663 | break; |
| 664 | } |
| 665 | |
| 666 | case SI_ENABLE_INTERRUPTS1: |
| 667 | { |
| 668 | unsigned char msg[4]; |
| 669 | |
| 670 | /* We got the flags from the SMI, now handle them. */ |
| 671 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
| 672 | if (msg[2] != 0) { |
| 673 | printk(KERN_WARNING |
| 674 | "ipmi_si: Could not enable interrupts" |
| 675 | ", failed get, using polled mode.\n"); |
| 676 | smi_info->si_state = SI_NORMAL; |
| 677 | } else { |
| 678 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 679 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 680 | msg[2] = (msg[3] | |
| 681 | IPMI_BMC_RCV_MSG_INTR | |
| 682 | IPMI_BMC_EVT_MSG_INTR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | smi_info->handlers->start_transaction( |
| 684 | smi_info->si_sm, msg, 3); |
| 685 | smi_info->si_state = SI_ENABLE_INTERRUPTS2; |
| 686 | } |
| 687 | break; |
| 688 | } |
| 689 | |
| 690 | case SI_ENABLE_INTERRUPTS2: |
| 691 | { |
| 692 | unsigned char msg[4]; |
| 693 | |
| 694 | /* We got the flags from the SMI, now handle them. */ |
| 695 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
| 696 | if (msg[2] != 0) { |
| 697 | printk(KERN_WARNING |
| 698 | "ipmi_si: Could not enable interrupts" |
| 699 | ", failed set, using polled mode.\n"); |
| 700 | } |
| 701 | smi_info->si_state = SI_NORMAL; |
| 702 | break; |
| 703 | } |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 704 | |
| 705 | case SI_DISABLE_INTERRUPTS1: |
| 706 | { |
| 707 | unsigned char msg[4]; |
| 708 | |
| 709 | /* We got the flags from the SMI, now handle them. */ |
| 710 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
| 711 | if (msg[2] != 0) { |
| 712 | printk(KERN_WARNING |
| 713 | "ipmi_si: Could not disable interrupts" |
| 714 | ", failed get.\n"); |
| 715 | smi_info->si_state = SI_NORMAL; |
| 716 | } else { |
| 717 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 718 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; |
| 719 | msg[2] = (msg[3] & |
| 720 | ~(IPMI_BMC_RCV_MSG_INTR | |
| 721 | IPMI_BMC_EVT_MSG_INTR)); |
| 722 | smi_info->handlers->start_transaction( |
| 723 | smi_info->si_sm, msg, 3); |
| 724 | smi_info->si_state = SI_DISABLE_INTERRUPTS2; |
| 725 | } |
| 726 | break; |
| 727 | } |
| 728 | |
| 729 | case SI_DISABLE_INTERRUPTS2: |
| 730 | { |
| 731 | unsigned char msg[4]; |
| 732 | |
| 733 | /* We got the flags from the SMI, now handle them. */ |
| 734 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
| 735 | if (msg[2] != 0) { |
| 736 | printk(KERN_WARNING |
| 737 | "ipmi_si: Could not disable interrupts" |
| 738 | ", failed set.\n"); |
| 739 | } |
| 740 | smi_info->si_state = SI_NORMAL; |
| 741 | break; |
| 742 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 746 | /* |
| 747 | * Called on timeouts and events. Timeouts should pass the elapsed |
| 748 | * time, interrupts should pass in zero. Must be called with |
| 749 | * si_lock held and interrupts disabled. |
| 750 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | static enum si_sm_result smi_event_handler(struct smi_info *smi_info, |
| 752 | int time) |
| 753 | { |
| 754 | enum si_sm_result si_sm_result; |
| 755 | |
| 756 | restart: |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 757 | /* |
| 758 | * There used to be a loop here that waited a little while |
| 759 | * (around 25us) before giving up. That turned out to be |
| 760 | * pointless, the minimum delays I was seeing were in the 300us |
| 761 | * range, which is far too long to wait in an interrupt. So |
| 762 | * we just run until the state machine tells us something |
| 763 | * happened or it needs a delay. |
| 764 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, time); |
| 766 | time = 0; |
| 767 | while (si_sm_result == SI_SM_CALL_WITHOUT_DELAY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 770 | if (si_sm_result == SI_SM_TRANSACTION_COMPLETE) { |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 771 | smi_inc_stat(smi_info, complete_transactions); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
| 773 | handle_transaction_done(smi_info); |
| 774 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 775 | } else if (si_sm_result == SI_SM_HOSED) { |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 776 | smi_inc_stat(smi_info, hosed_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 778 | /* |
| 779 | * Do the before return_hosed_msg, because that |
| 780 | * releases the lock. |
| 781 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | smi_info->si_state = SI_NORMAL; |
| 783 | if (smi_info->curr_msg != NULL) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 784 | /* |
| 785 | * If we were handling a user message, format |
| 786 | * a response to send to the upper layer to |
| 787 | * tell it about the error. |
| 788 | */ |
Corey Minyard | 4d7cbac | 2006-12-06 20:41:14 -0800 | [diff] [blame] | 789 | return_hosed_msg(smi_info, IPMI_ERR_UNSPECIFIED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | } |
| 791 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); |
| 792 | } |
| 793 | |
Corey Minyard | 4ea1842 | 2008-04-29 01:01:01 -0700 | [diff] [blame] | 794 | /* |
| 795 | * We prefer handling attn over new messages. But don't do |
| 796 | * this if there is not yet an upper layer to handle anything. |
| 797 | */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 798 | if (likely(smi_info->intf) && si_sm_result == SI_SM_ATTN) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | unsigned char msg[2]; |
| 800 | |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 801 | smi_inc_stat(smi_info, attentions); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 803 | /* |
| 804 | * Got a attn, send down a get message flags to see |
| 805 | * what's causing it. It would be better to handle |
| 806 | * this in the upper layer, but due to the way |
| 807 | * interrupts work with the SMI, that's not really |
| 808 | * possible. |
| 809 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 811 | msg[1] = IPMI_GET_MSG_FLAGS_CMD; |
| 812 | |
| 813 | smi_info->handlers->start_transaction( |
| 814 | smi_info->si_sm, msg, 2); |
| 815 | smi_info->si_state = SI_GETTING_FLAGS; |
| 816 | goto restart; |
| 817 | } |
| 818 | |
| 819 | /* If we are currently idle, try to start the next message. */ |
| 820 | if (si_sm_result == SI_SM_IDLE) { |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 821 | smi_inc_stat(smi_info, idles); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | |
| 823 | si_sm_result = start_next_msg(smi_info); |
| 824 | if (si_sm_result != SI_SM_IDLE) |
| 825 | goto restart; |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | |
| 828 | if ((si_sm_result == SI_SM_IDLE) |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 829 | && (atomic_read(&smi_info->req_events))) { |
| 830 | /* |
| 831 | * We are idle and the upper layer requested that I fetch |
| 832 | * events, so do so. |
| 833 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | atomic_set(&smi_info->req_events, 0); |
Corey Minyard | 55162fb | 2006-12-06 20:41:04 -0800 | [diff] [blame] | 835 | |
| 836 | smi_info->curr_msg = ipmi_alloc_smi_msg(); |
| 837 | if (!smi_info->curr_msg) |
| 838 | goto out; |
| 839 | |
| 840 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 841 | smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD; |
| 842 | smi_info->curr_msg->data_size = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | smi_info->handlers->start_transaction( |
Corey Minyard | 55162fb | 2006-12-06 20:41:04 -0800 | [diff] [blame] | 845 | smi_info->si_sm, |
| 846 | smi_info->curr_msg->data, |
| 847 | smi_info->curr_msg->data_size); |
| 848 | smi_info->si_state = SI_GETTING_EVENTS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | goto restart; |
| 850 | } |
Corey Minyard | 55162fb | 2006-12-06 20:41:04 -0800 | [diff] [blame] | 851 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | return si_sm_result; |
| 853 | } |
| 854 | |
| 855 | static void sender(void *send_info, |
| 856 | struct ipmi_smi_msg *msg, |
| 857 | int priority) |
| 858 | { |
| 859 | struct smi_info *smi_info = send_info; |
| 860 | enum si_sm_result result; |
| 861 | unsigned long flags; |
| 862 | #ifdef DEBUG_TIMING |
| 863 | struct timeval t; |
| 864 | #endif |
| 865 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 866 | if (atomic_read(&smi_info->stop_operation)) { |
| 867 | msg->rsp[0] = msg->data[0] | 4; |
| 868 | msg->rsp[1] = msg->data[1]; |
| 869 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; |
| 870 | msg->rsp_size = 3; |
| 871 | deliver_recv_msg(smi_info, msg); |
| 872 | return; |
| 873 | } |
| 874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | #ifdef DEBUG_TIMING |
| 876 | do_gettimeofday(&t); |
| 877 | printk("**Enqueue: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
| 878 | #endif |
| 879 | |
| 880 | if (smi_info->run_to_completion) { |
Corey Minyard | bda4c30 | 2008-04-29 01:01:02 -0700 | [diff] [blame] | 881 | /* |
| 882 | * If we are running to completion, then throw it in |
| 883 | * the list and run transactions until everything is |
| 884 | * clear. Priority doesn't matter here. |
| 885 | */ |
| 886 | |
| 887 | /* |
| 888 | * Run to completion means we are single-threaded, no |
| 889 | * need for locks. |
| 890 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | list_add_tail(&(msg->link), &(smi_info->xmit_msgs)); |
| 892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | result = smi_event_handler(smi_info, 0); |
| 894 | while (result != SI_SM_IDLE) { |
| 895 | udelay(SI_SHORT_TIMEOUT_USEC); |
| 896 | result = smi_event_handler(smi_info, |
| 897 | SI_SHORT_TIMEOUT_USEC); |
| 898 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
Corey Minyard | bda4c30 | 2008-04-29 01:01:02 -0700 | [diff] [blame] | 902 | spin_lock_irqsave(&smi_info->msg_lock, flags); |
| 903 | if (priority > 0) |
| 904 | list_add_tail(&msg->link, &smi_info->hp_xmit_msgs); |
| 905 | else |
| 906 | list_add_tail(&msg->link, &smi_info->xmit_msgs); |
| 907 | spin_unlock_irqrestore(&smi_info->msg_lock, flags); |
| 908 | |
| 909 | spin_lock_irqsave(&smi_info->si_lock, flags); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 910 | if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | start_next_msg(smi_info); |
Corey Minyard | bda4c30 | 2008-04-29 01:01:02 -0700 | [diff] [blame] | 912 | spin_unlock_irqrestore(&smi_info->si_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | static void set_run_to_completion(void *send_info, int i_run_to_completion) |
| 916 | { |
| 917 | struct smi_info *smi_info = send_info; |
| 918 | enum si_sm_result result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
| 920 | smi_info->run_to_completion = i_run_to_completion; |
| 921 | if (i_run_to_completion) { |
| 922 | result = smi_event_handler(smi_info, 0); |
| 923 | while (result != SI_SM_IDLE) { |
| 924 | udelay(SI_SHORT_TIMEOUT_USEC); |
| 925 | result = smi_event_handler(smi_info, |
| 926 | SI_SHORT_TIMEOUT_USEC); |
| 927 | } |
| 928 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 931 | /* |
| 932 | * Use -1 in the nsec value of the busy waiting timespec to tell that |
| 933 | * we are spinning in kipmid looking for something and not delaying |
| 934 | * between checks |
| 935 | */ |
| 936 | static inline void ipmi_si_set_not_busy(struct timespec *ts) |
| 937 | { |
| 938 | ts->tv_nsec = -1; |
| 939 | } |
| 940 | static inline int ipmi_si_is_busy(struct timespec *ts) |
| 941 | { |
| 942 | return ts->tv_nsec != -1; |
| 943 | } |
| 944 | |
| 945 | static int ipmi_thread_busy_wait(enum si_sm_result smi_result, |
| 946 | const struct smi_info *smi_info, |
| 947 | struct timespec *busy_until) |
| 948 | { |
| 949 | unsigned int max_busy_us = 0; |
| 950 | |
| 951 | if (smi_info->intf_num < num_max_busy_us) |
| 952 | max_busy_us = kipmid_max_busy_us[smi_info->intf_num]; |
| 953 | if (max_busy_us == 0 || smi_result != SI_SM_CALL_WITH_DELAY) |
| 954 | ipmi_si_set_not_busy(busy_until); |
| 955 | else if (!ipmi_si_is_busy(busy_until)) { |
| 956 | getnstimeofday(busy_until); |
| 957 | timespec_add_ns(busy_until, max_busy_us*NSEC_PER_USEC); |
| 958 | } else { |
| 959 | struct timespec now; |
| 960 | getnstimeofday(&now); |
| 961 | if (unlikely(timespec_compare(&now, busy_until) > 0)) { |
| 962 | ipmi_si_set_not_busy(busy_until); |
| 963 | return 0; |
| 964 | } |
| 965 | } |
| 966 | return 1; |
| 967 | } |
| 968 | |
| 969 | |
| 970 | /* |
| 971 | * A busy-waiting loop for speeding up IPMI operation. |
| 972 | * |
| 973 | * Lousy hardware makes this hard. This is only enabled for systems |
| 974 | * that are not BT and do not have interrupts. It starts spinning |
| 975 | * when an operation is complete or until max_busy tells it to stop |
| 976 | * (if that is enabled). See the paragraph on kimid_max_busy_us in |
| 977 | * Documentation/IPMI.txt for details. |
| 978 | */ |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 979 | static int ipmi_thread(void *data) |
| 980 | { |
| 981 | struct smi_info *smi_info = data; |
Matt Domsch | e9a705a | 2005-11-07 01:00:04 -0800 | [diff] [blame] | 982 | unsigned long flags; |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 983 | enum si_sm_result smi_result; |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 984 | struct timespec busy_until; |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 985 | |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 986 | ipmi_si_set_not_busy(&busy_until); |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 987 | set_user_nice(current, 19); |
Matt Domsch | e9a705a | 2005-11-07 01:00:04 -0800 | [diff] [blame] | 988 | while (!kthread_should_stop()) { |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 989 | int busy_wait; |
| 990 | |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 991 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 992 | smi_result = smi_event_handler(smi_info, 0); |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 993 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 994 | busy_wait = ipmi_thread_busy_wait(smi_result, smi_info, |
| 995 | &busy_until); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 996 | if (smi_result == SI_SM_CALL_WITHOUT_DELAY) |
| 997 | ; /* do nothing */ |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 998 | else if (smi_result == SI_SM_CALL_WITH_DELAY && busy_wait) |
akpm@osdl.org | 3397973 | 2006-06-27 02:54:04 -0700 | [diff] [blame] | 999 | schedule(); |
Matt Domsch | e9a705a | 2005-11-07 01:00:04 -0800 | [diff] [blame] | 1000 | else |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 1001 | schedule_timeout_interruptible(0); |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 1002 | } |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | static void poll(void *send_info) |
| 1008 | { |
| 1009 | struct smi_info *smi_info = send_info; |
Corey Minyard | fcfa472 | 2007-10-18 03:07:09 -0700 | [diff] [blame] | 1010 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
Corey Minyard | 15c62e1 | 2006-12-06 20:41:06 -0800 | [diff] [blame] | 1012 | /* |
| 1013 | * Make sure there is some delay in the poll loop so we can |
| 1014 | * drive time forward and timeout things. |
| 1015 | */ |
| 1016 | udelay(10); |
Corey Minyard | fcfa472 | 2007-10-18 03:07:09 -0700 | [diff] [blame] | 1017 | spin_lock_irqsave(&smi_info->si_lock, flags); |
Corey Minyard | 15c62e1 | 2006-12-06 20:41:06 -0800 | [diff] [blame] | 1018 | smi_event_handler(smi_info, 10); |
Corey Minyard | fcfa472 | 2007-10-18 03:07:09 -0700 | [diff] [blame] | 1019 | spin_unlock_irqrestore(&smi_info->si_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | static void request_events(void *send_info) |
| 1023 | { |
| 1024 | struct smi_info *smi_info = send_info; |
| 1025 | |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 1026 | if (atomic_read(&smi_info->stop_operation) || |
| 1027 | !smi_info->has_event_buffer) |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1028 | return; |
| 1029 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | atomic_set(&smi_info->req_events, 1); |
| 1031 | } |
| 1032 | |
Randy Dunlap | 0c8204b | 2006-12-10 02:19:06 -0800 | [diff] [blame] | 1033 | static int initialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | static void smi_timeout(unsigned long data) |
| 1036 | { |
| 1037 | struct smi_info *smi_info = (struct smi_info *) data; |
| 1038 | enum si_sm_result smi_result; |
| 1039 | unsigned long flags; |
| 1040 | unsigned long jiffies_now; |
Corey Minyard | c4edff1 | 2005-11-07 00:59:56 -0800 | [diff] [blame] | 1041 | long time_diff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | #ifdef DEBUG_TIMING |
| 1043 | struct timeval t; |
| 1044 | #endif |
| 1045 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
| 1047 | #ifdef DEBUG_TIMING |
| 1048 | do_gettimeofday(&t); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1049 | printk(KERN_DEBUG "**Timer: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | #endif |
| 1051 | jiffies_now = jiffies; |
Corey Minyard | c4edff1 | 2005-11-07 00:59:56 -0800 | [diff] [blame] | 1052 | time_diff = (((long)jiffies_now - (long)smi_info->last_timeout_jiffies) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | * SI_USEC_PER_JIFFY); |
| 1054 | smi_result = smi_event_handler(smi_info, time_diff); |
| 1055 | |
| 1056 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
| 1057 | |
| 1058 | smi_info->last_timeout_jiffies = jiffies_now; |
| 1059 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1060 | if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | /* Running with interrupts, only do long timeouts. */ |
| 1062 | smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES; |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 1063 | smi_inc_stat(smi_info, long_timeouts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | goto do_add_timer; |
| 1065 | } |
| 1066 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1067 | /* |
| 1068 | * If the state machine asks for a short delay, then shorten |
| 1069 | * the timer timeout. |
| 1070 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | if (smi_result == SI_SM_CALL_WITH_DELAY) { |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 1072 | smi_inc_stat(smi_info, short_timeouts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | smi_info->si_timer.expires = jiffies + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 | } else { |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 1075 | smi_inc_stat(smi_info, long_timeouts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | do_add_timer: |
| 1080 | add_timer(&(smi_info->si_timer)); |
| 1081 | } |
| 1082 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1083 | static irqreturn_t si_irq_handler(int irq, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | { |
| 1085 | struct smi_info *smi_info = data; |
| 1086 | unsigned long flags; |
| 1087 | #ifdef DEBUG_TIMING |
| 1088 | struct timeval t; |
| 1089 | #endif |
| 1090 | |
| 1091 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
| 1092 | |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 1093 | smi_inc_stat(smi_info, interrupts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | #ifdef DEBUG_TIMING |
| 1096 | do_gettimeofday(&t); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1097 | printk(KERN_DEBUG "**Interrupt: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | #endif |
| 1099 | smi_event_handler(smi_info, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
| 1101 | return IRQ_HANDLED; |
| 1102 | } |
| 1103 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1104 | static irqreturn_t si_bt_irq_handler(int irq, void *data) |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 1105 | { |
| 1106 | struct smi_info *smi_info = data; |
| 1107 | /* We need to clear the IRQ flag for the BT interface. */ |
| 1108 | smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG, |
| 1109 | IPMI_BT_INTMASK_CLEAR_IRQ_BIT |
| 1110 | | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1111 | return si_irq_handler(irq, data); |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 1114 | static int smi_start_processing(void *send_info, |
| 1115 | ipmi_smi_t intf) |
| 1116 | { |
| 1117 | struct smi_info *new_smi = send_info; |
Corey Minyard | a51f4a8 | 2006-10-03 01:13:59 -0700 | [diff] [blame] | 1118 | int enable = 0; |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 1119 | |
| 1120 | new_smi->intf = intf; |
| 1121 | |
Corey Minyard | c45adc3 | 2007-10-18 03:07:08 -0700 | [diff] [blame] | 1122 | /* Try to claim any interrupts. */ |
| 1123 | if (new_smi->irq_setup) |
| 1124 | new_smi->irq_setup(new_smi); |
| 1125 | |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 1126 | /* Set up the timer that drives the interface. */ |
| 1127 | setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi); |
| 1128 | new_smi->last_timeout_jiffies = jiffies; |
| 1129 | mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES); |
| 1130 | |
Corey Minyard | df3fe8d | 2006-09-30 23:28:20 -0700 | [diff] [blame] | 1131 | /* |
Corey Minyard | a51f4a8 | 2006-10-03 01:13:59 -0700 | [diff] [blame] | 1132 | * Check if the user forcefully enabled the daemon. |
| 1133 | */ |
| 1134 | if (new_smi->intf_num < num_force_kipmid) |
| 1135 | enable = force_kipmid[new_smi->intf_num]; |
| 1136 | /* |
Corey Minyard | df3fe8d | 2006-09-30 23:28:20 -0700 | [diff] [blame] | 1137 | * The BT interface is efficient enough to not need a thread, |
| 1138 | * and there is no need for a thread if we have interrupts. |
| 1139 | */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1140 | else if ((new_smi->si_type != SI_BT) && (!new_smi->irq)) |
Corey Minyard | a51f4a8 | 2006-10-03 01:13:59 -0700 | [diff] [blame] | 1141 | enable = 1; |
| 1142 | |
| 1143 | if (enable) { |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 1144 | new_smi->thread = kthread_run(ipmi_thread, new_smi, |
| 1145 | "kipmi%d", new_smi->intf_num); |
| 1146 | if (IS_ERR(new_smi->thread)) { |
| 1147 | printk(KERN_NOTICE "ipmi_si_intf: Could not start" |
| 1148 | " kernel thread due to error %ld, only using" |
| 1149 | " timers to drive the interface\n", |
| 1150 | PTR_ERR(new_smi->thread)); |
| 1151 | new_smi->thread = NULL; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 1157 | |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 1158 | static void set_maintenance_mode(void *send_info, int enable) |
| 1159 | { |
| 1160 | struct smi_info *smi_info = send_info; |
| 1161 | |
| 1162 | if (!enable) |
| 1163 | atomic_set(&smi_info->req_events, 0); |
| 1164 | } |
| 1165 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1166 | static struct ipmi_smi_handlers handlers = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | .owner = THIS_MODULE, |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 1168 | .start_processing = smi_start_processing, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | .sender = sender, |
| 1170 | .request_events = request_events, |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 1171 | .set_maintenance_mode = set_maintenance_mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | .set_run_to_completion = set_run_to_completion, |
| 1173 | .poll = poll, |
| 1174 | }; |
| 1175 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1176 | /* |
| 1177 | * There can be 4 IO ports passed in (with or without IRQs), 4 addresses, |
| 1178 | * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS. |
| 1179 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1181 | static LIST_HEAD(smi_infos); |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 1182 | static DEFINE_MUTEX(smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1183 | static int smi_num; /* Used to sequence the SMIs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | #define DEFAULT_REGSPACING 1 |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 1186 | #define DEFAULT_REGSIZE 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1187 | |
| 1188 | static int si_trydefaults = 1; |
| 1189 | static char *si_type[SI_MAX_PARMS]; |
| 1190 | #define MAX_SI_TYPE_STR 30 |
| 1191 | static char si_type_str[MAX_SI_TYPE_STR]; |
| 1192 | static unsigned long addrs[SI_MAX_PARMS]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1193 | static unsigned int num_addrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | static unsigned int ports[SI_MAX_PARMS]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1195 | static unsigned int num_ports; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | static int irqs[SI_MAX_PARMS]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1197 | static unsigned int num_irqs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | static int regspacings[SI_MAX_PARMS]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1199 | static unsigned int num_regspacings; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | static int regsizes[SI_MAX_PARMS]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1201 | static unsigned int num_regsizes; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | static int regshifts[SI_MAX_PARMS]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1203 | static unsigned int num_regshifts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | static int slave_addrs[SI_MAX_PARMS]; |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1205 | static unsigned int num_slave_addrs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1207 | #define IPMI_IO_ADDR_SPACE 0 |
| 1208 | #define IPMI_MEM_ADDR_SPACE 1 |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1209 | static char *addr_space_to_str[] = { "i/o", "mem" }; |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1210 | |
| 1211 | static int hotmod_handler(const char *val, struct kernel_param *kp); |
| 1212 | |
| 1213 | module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200); |
| 1214 | MODULE_PARM_DESC(hotmod, "Add and remove interfaces. See" |
| 1215 | " Documentation/IPMI.txt in the kernel sources for the" |
| 1216 | " gory details."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | |
| 1218 | module_param_named(trydefaults, si_trydefaults, bool, 0); |
| 1219 | MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the" |
| 1220 | " default scan of the KCS and SMIC interface at the standard" |
| 1221 | " address"); |
| 1222 | module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0); |
| 1223 | MODULE_PARM_DESC(type, "Defines the type of each interface, each" |
| 1224 | " interface separated by commas. The types are 'kcs'," |
| 1225 | " 'smic', and 'bt'. For example si_type=kcs,bt will set" |
| 1226 | " the first interface to kcs and the second to bt"); |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1227 | module_param_array(addrs, ulong, &num_addrs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the" |
| 1229 | " addresses separated by commas. Only use if an interface" |
| 1230 | " is in memory. Otherwise, set it to zero or leave" |
| 1231 | " it blank."); |
Al Viro | 64a6f95 | 2007-10-14 19:35:30 +0100 | [diff] [blame] | 1232 | module_param_array(ports, uint, &num_ports, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | MODULE_PARM_DESC(ports, "Sets the port address of each interface, the" |
| 1234 | " addresses separated by commas. Only use if an interface" |
| 1235 | " is a port. Otherwise, set it to zero or leave" |
| 1236 | " it blank."); |
| 1237 | module_param_array(irqs, int, &num_irqs, 0); |
| 1238 | MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the" |
| 1239 | " addresses separated by commas. Only use if an interface" |
| 1240 | " has an interrupt. Otherwise, set it to zero or leave" |
| 1241 | " it blank."); |
| 1242 | module_param_array(regspacings, int, &num_regspacings, 0); |
| 1243 | MODULE_PARM_DESC(regspacings, "The number of bytes between the start address" |
| 1244 | " and each successive register used by the interface. For" |
| 1245 | " instance, if the start address is 0xca2 and the spacing" |
| 1246 | " is 2, then the second address is at 0xca4. Defaults" |
| 1247 | " to 1."); |
| 1248 | module_param_array(regsizes, int, &num_regsizes, 0); |
| 1249 | MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes." |
| 1250 | " This should generally be 1, 2, 4, or 8 for an 8-bit," |
| 1251 | " 16-bit, 32-bit, or 64-bit register. Use this if you" |
| 1252 | " the 8-bit IPMI register has to be read from a larger" |
| 1253 | " register."); |
| 1254 | module_param_array(regshifts, int, &num_regshifts, 0); |
| 1255 | MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the." |
| 1256 | " IPMI register, in bits. For instance, if the data" |
| 1257 | " is read from a 32-bit word and the IPMI data is in" |
| 1258 | " bit 8-15, then the shift would be 8"); |
| 1259 | module_param_array(slave_addrs, int, &num_slave_addrs, 0); |
| 1260 | MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for" |
| 1261 | " the controller. Normally this is 0x20, but can be" |
| 1262 | " overridden by this parm. This is an array indexed" |
| 1263 | " by interface number."); |
Corey Minyard | a51f4a8 | 2006-10-03 01:13:59 -0700 | [diff] [blame] | 1264 | module_param_array(force_kipmid, int, &num_force_kipmid, 0); |
| 1265 | MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or" |
| 1266 | " disabled(0). Normally the IPMI driver auto-detects" |
| 1267 | " this, but the value may be overridden by this parm."); |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1268 | module_param(unload_when_empty, int, 0); |
| 1269 | MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are" |
| 1270 | " specified or found, default is 1. Setting to 0" |
| 1271 | " is useful for hot add of devices using hotmod."); |
Martin Wilck | ae74e82 | 2010-03-10 15:23:06 -0800 | [diff] [blame^] | 1272 | module_param_array(kipmid_max_busy_us, uint, &num_max_busy_us, 0644); |
| 1273 | MODULE_PARM_DESC(kipmid_max_busy_us, |
| 1274 | "Max time (in microseconds) to busy-wait for IPMI data before" |
| 1275 | " sleeping. 0 (default) means to wait forever. Set to 100-500" |
| 1276 | " if kipmid is using up a lot of CPU time."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
| 1278 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1279 | static void std_irq_cleanup(struct smi_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1281 | if (info->si_type == SI_BT) |
| 1282 | /* Disable the interrupt in the BT interface. */ |
| 1283 | info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0); |
| 1284 | free_irq(info->irq, info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
| 1287 | static int std_irq_setup(struct smi_info *info) |
| 1288 | { |
| 1289 | int rv; |
| 1290 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1291 | if (!info->irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | return 0; |
| 1293 | |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 1294 | if (info->si_type == SI_BT) { |
| 1295 | rv = request_irq(info->irq, |
| 1296 | si_bt_irq_handler, |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 1297 | IRQF_SHARED | IRQF_DISABLED, |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 1298 | DEVICE_NAME, |
| 1299 | info); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1300 | if (!rv) |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 1301 | /* Enable the interrupt in the BT interface. */ |
| 1302 | info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, |
| 1303 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); |
| 1304 | } else |
| 1305 | rv = request_irq(info->irq, |
| 1306 | si_irq_handler, |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 1307 | IRQF_SHARED | IRQF_DISABLED, |
Corey Minyard | 9dbf68f | 2005-05-01 08:59:11 -0700 | [diff] [blame] | 1308 | DEVICE_NAME, |
| 1309 | info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1310 | if (rv) { |
| 1311 | printk(KERN_WARNING |
| 1312 | "ipmi_si: %s unable to claim interrupt %d," |
| 1313 | " running polled\n", |
| 1314 | DEVICE_NAME, info->irq); |
| 1315 | info->irq = 0; |
| 1316 | } else { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1317 | info->irq_cleanup = std_irq_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | printk(" Using irq %d\n", info->irq); |
| 1319 | } |
| 1320 | |
| 1321 | return rv; |
| 1322 | } |
| 1323 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | static unsigned char port_inb(struct si_sm_io *io, unsigned int offset) |
| 1325 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1326 | unsigned int addr = io->addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1328 | return inb(addr + (offset * io->regspacing)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | static void port_outb(struct si_sm_io *io, unsigned int offset, |
| 1332 | unsigned char b) |
| 1333 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1334 | unsigned int addr = io->addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1336 | outb(b, addr + (offset * io->regspacing)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | static unsigned char port_inw(struct si_sm_io *io, unsigned int offset) |
| 1340 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1341 | unsigned int addr = io->addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1343 | return (inw(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
| 1346 | static void port_outw(struct si_sm_io *io, unsigned int offset, |
| 1347 | unsigned char b) |
| 1348 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1349 | unsigned int addr = io->addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1351 | outw(b << io->regshift, addr + (offset * io->regspacing)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | static unsigned char port_inl(struct si_sm_io *io, unsigned int offset) |
| 1355 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1356 | unsigned int addr = io->addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1357 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1358 | return (inl(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | static void port_outl(struct si_sm_io *io, unsigned int offset, |
| 1362 | unsigned char b) |
| 1363 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1364 | unsigned int addr = io->addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1366 | outl(b << io->regshift, addr+(offset * io->regspacing)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | } |
| 1368 | |
| 1369 | static void port_cleanup(struct smi_info *info) |
| 1370 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1371 | unsigned int addr = info->io.addr_data; |
Corey Minyard | d61a3ea | 2006-05-30 21:25:57 -0700 | [diff] [blame] | 1372 | int idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1374 | if (addr) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1375 | for (idx = 0; idx < info->io_size; idx++) |
Corey Minyard | d61a3ea | 2006-05-30 21:25:57 -0700 | [diff] [blame] | 1376 | release_region(addr + idx * info->io.regspacing, |
| 1377 | info->io.regsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static int port_setup(struct smi_info *info) |
| 1382 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1383 | unsigned int addr = info->io.addr_data; |
Corey Minyard | d61a3ea | 2006-05-30 21:25:57 -0700 | [diff] [blame] | 1384 | int idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1386 | if (!addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | return -ENODEV; |
| 1388 | |
| 1389 | info->io_cleanup = port_cleanup; |
| 1390 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1391 | /* |
| 1392 | * Figure out the actual inb/inw/inl/etc routine to use based |
| 1393 | * upon the register size. |
| 1394 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | switch (info->io.regsize) { |
| 1396 | case 1: |
| 1397 | info->io.inputb = port_inb; |
| 1398 | info->io.outputb = port_outb; |
| 1399 | break; |
| 1400 | case 2: |
| 1401 | info->io.inputb = port_inw; |
| 1402 | info->io.outputb = port_outw; |
| 1403 | break; |
| 1404 | case 4: |
| 1405 | info->io.inputb = port_inl; |
| 1406 | info->io.outputb = port_outl; |
| 1407 | break; |
| 1408 | default: |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1409 | printk(KERN_WARNING "ipmi_si: Invalid register size: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | info->io.regsize); |
| 1411 | return -EINVAL; |
| 1412 | } |
| 1413 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1414 | /* |
| 1415 | * Some BIOSes reserve disjoint I/O regions in their ACPI |
Corey Minyard | d61a3ea | 2006-05-30 21:25:57 -0700 | [diff] [blame] | 1416 | * tables. This causes problems when trying to register the |
| 1417 | * entire I/O region. Therefore we must register each I/O |
| 1418 | * port separately. |
| 1419 | */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1420 | for (idx = 0; idx < info->io_size; idx++) { |
Corey Minyard | d61a3ea | 2006-05-30 21:25:57 -0700 | [diff] [blame] | 1421 | if (request_region(addr + idx * info->io.regspacing, |
| 1422 | info->io.regsize, DEVICE_NAME) == NULL) { |
| 1423 | /* Undo allocations */ |
| 1424 | while (idx--) { |
| 1425 | release_region(addr + idx * info->io.regspacing, |
| 1426 | info->io.regsize); |
| 1427 | } |
| 1428 | return -EIO; |
| 1429 | } |
| 1430 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | return 0; |
| 1432 | } |
| 1433 | |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1434 | static unsigned char intf_mem_inb(struct si_sm_io *io, unsigned int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | { |
| 1436 | return readb((io->addr)+(offset * io->regspacing)); |
| 1437 | } |
| 1438 | |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1439 | static void intf_mem_outb(struct si_sm_io *io, unsigned int offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | unsigned char b) |
| 1441 | { |
| 1442 | writeb(b, (io->addr)+(offset * io->regspacing)); |
| 1443 | } |
| 1444 | |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1445 | static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | { |
| 1447 | return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift) |
Alexey Dobriyan | 64d9fe6 | 2006-11-08 17:44:56 -0800 | [diff] [blame] | 1448 | & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1451 | static void intf_mem_outw(struct si_sm_io *io, unsigned int offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | unsigned char b) |
| 1453 | { |
| 1454 | writeb(b << io->regshift, (io->addr)+(offset * io->regspacing)); |
| 1455 | } |
| 1456 | |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1457 | static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | { |
| 1459 | return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift) |
Alexey Dobriyan | 64d9fe6 | 2006-11-08 17:44:56 -0800 | [diff] [blame] | 1460 | & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | } |
| 1462 | |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1463 | static void intf_mem_outl(struct si_sm_io *io, unsigned int offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | unsigned char b) |
| 1465 | { |
| 1466 | writel(b << io->regshift, (io->addr)+(offset * io->regspacing)); |
| 1467 | } |
| 1468 | |
| 1469 | #ifdef readq |
| 1470 | static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset) |
| 1471 | { |
| 1472 | return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift) |
Alexey Dobriyan | 64d9fe6 | 2006-11-08 17:44:56 -0800 | [diff] [blame] | 1473 | & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | static void mem_outq(struct si_sm_io *io, unsigned int offset, |
| 1477 | unsigned char b) |
| 1478 | { |
| 1479 | writeq(b << io->regshift, (io->addr)+(offset * io->regspacing)); |
| 1480 | } |
| 1481 | #endif |
| 1482 | |
| 1483 | static void mem_cleanup(struct smi_info *info) |
| 1484 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1485 | unsigned long addr = info->io.addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | int mapsize; |
| 1487 | |
| 1488 | if (info->io.addr) { |
| 1489 | iounmap(info->io.addr); |
| 1490 | |
| 1491 | mapsize = ((info->io_size * info->io.regspacing) |
| 1492 | - (info->io.regspacing - info->io.regsize)); |
| 1493 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1494 | release_mem_region(addr, mapsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | static int mem_setup(struct smi_info *info) |
| 1499 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1500 | unsigned long addr = info->io.addr_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | int mapsize; |
| 1502 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1503 | if (!addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | return -ENODEV; |
| 1505 | |
| 1506 | info->io_cleanup = mem_cleanup; |
| 1507 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1508 | /* |
| 1509 | * Figure out the actual readb/readw/readl/etc routine to use based |
| 1510 | * upon the register size. |
| 1511 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1512 | switch (info->io.regsize) { |
| 1513 | case 1: |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1514 | info->io.inputb = intf_mem_inb; |
| 1515 | info->io.outputb = intf_mem_outb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | break; |
| 1517 | case 2: |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1518 | info->io.inputb = intf_mem_inw; |
| 1519 | info->io.outputb = intf_mem_outw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | break; |
| 1521 | case 4: |
Alexey Dobriyan | 546cfdf | 2006-02-03 03:04:40 -0800 | [diff] [blame] | 1522 | info->io.inputb = intf_mem_inl; |
| 1523 | info->io.outputb = intf_mem_outl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | break; |
| 1525 | #ifdef readq |
| 1526 | case 8: |
| 1527 | info->io.inputb = mem_inq; |
| 1528 | info->io.outputb = mem_outq; |
| 1529 | break; |
| 1530 | #endif |
| 1531 | default: |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1532 | printk(KERN_WARNING "ipmi_si: Invalid register size: %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | info->io.regsize); |
| 1534 | return -EINVAL; |
| 1535 | } |
| 1536 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1537 | /* |
| 1538 | * Calculate the total amount of memory to claim. This is an |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | * unusual looking calculation, but it avoids claiming any |
| 1540 | * more memory than it has to. It will claim everything |
| 1541 | * between the first address to the end of the last full |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1542 | * register. |
| 1543 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1544 | mapsize = ((info->io_size * info->io.regspacing) |
| 1545 | - (info->io.regspacing - info->io.regsize)); |
| 1546 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1547 | if (request_mem_region(addr, mapsize, DEVICE_NAME) == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | return -EIO; |
| 1549 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1550 | info->io.addr = ioremap(addr, mapsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | if (info->io.addr == NULL) { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1552 | release_mem_region(addr, mapsize); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | return -EIO; |
| 1554 | } |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1558 | /* |
| 1559 | * Parms come in as <op1>[:op2[:op3...]]. ops are: |
| 1560 | * add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]] |
| 1561 | * Options are: |
| 1562 | * rsp=<regspacing> |
| 1563 | * rsi=<regsize> |
| 1564 | * rsh=<regshift> |
| 1565 | * irq=<irq> |
| 1566 | * ipmb=<ipmb addr> |
| 1567 | */ |
| 1568 | enum hotmod_op { HM_ADD, HM_REMOVE }; |
| 1569 | struct hotmod_vals { |
| 1570 | char *name; |
| 1571 | int val; |
| 1572 | }; |
| 1573 | static struct hotmod_vals hotmod_ops[] = { |
| 1574 | { "add", HM_ADD }, |
| 1575 | { "remove", HM_REMOVE }, |
| 1576 | { NULL } |
| 1577 | }; |
| 1578 | static struct hotmod_vals hotmod_si[] = { |
| 1579 | { "kcs", SI_KCS }, |
| 1580 | { "smic", SI_SMIC }, |
| 1581 | { "bt", SI_BT }, |
| 1582 | { NULL } |
| 1583 | }; |
| 1584 | static struct hotmod_vals hotmod_as[] = { |
| 1585 | { "mem", IPMI_MEM_ADDR_SPACE }, |
| 1586 | { "i/o", IPMI_IO_ADDR_SPACE }, |
| 1587 | { NULL } |
| 1588 | }; |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1589 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1590 | static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr) |
| 1591 | { |
| 1592 | char *s; |
| 1593 | int i; |
| 1594 | |
| 1595 | s = strchr(*curr, ','); |
| 1596 | if (!s) { |
| 1597 | printk(KERN_WARNING PFX "No hotmod %s given.\n", name); |
| 1598 | return -EINVAL; |
| 1599 | } |
| 1600 | *s = '\0'; |
| 1601 | s++; |
| 1602 | for (i = 0; hotmod_ops[i].name; i++) { |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1603 | if (strcmp(*curr, v[i].name) == 0) { |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1604 | *val = v[i].val; |
| 1605 | *curr = s; |
| 1606 | return 0; |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr); |
| 1611 | return -EINVAL; |
| 1612 | } |
| 1613 | |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1614 | static int check_hotmod_int_op(const char *curr, const char *option, |
| 1615 | const char *name, int *val) |
| 1616 | { |
| 1617 | char *n; |
| 1618 | |
| 1619 | if (strcmp(curr, name) == 0) { |
| 1620 | if (!option) { |
| 1621 | printk(KERN_WARNING PFX |
| 1622 | "No option given for '%s'\n", |
| 1623 | curr); |
| 1624 | return -EINVAL; |
| 1625 | } |
| 1626 | *val = simple_strtoul(option, &n, 0); |
| 1627 | if ((*n != '\0') || (*option == '\0')) { |
| 1628 | printk(KERN_WARNING PFX |
| 1629 | "Bad option given for '%s'\n", |
| 1630 | curr); |
| 1631 | return -EINVAL; |
| 1632 | } |
| 1633 | return 1; |
| 1634 | } |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1638 | static int hotmod_handler(const char *val, struct kernel_param *kp) |
| 1639 | { |
| 1640 | char *str = kstrdup(val, GFP_KERNEL); |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1641 | int rv; |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1642 | char *next, *curr, *s, *n, *o; |
| 1643 | enum hotmod_op op; |
| 1644 | enum si_type si_type; |
| 1645 | int addr_space; |
| 1646 | unsigned long addr; |
| 1647 | int regspacing; |
| 1648 | int regsize; |
| 1649 | int regshift; |
| 1650 | int irq; |
| 1651 | int ipmb; |
| 1652 | int ival; |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1653 | int len; |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1654 | struct smi_info *info; |
| 1655 | |
| 1656 | if (!str) |
| 1657 | return -ENOMEM; |
| 1658 | |
| 1659 | /* Kill any trailing spaces, as we can get a "\n" from echo. */ |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1660 | len = strlen(str); |
| 1661 | ival = len - 1; |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1662 | while ((ival >= 0) && isspace(str[ival])) { |
| 1663 | str[ival] = '\0'; |
| 1664 | ival--; |
| 1665 | } |
| 1666 | |
| 1667 | for (curr = str; curr; curr = next) { |
| 1668 | regspacing = 1; |
| 1669 | regsize = 1; |
| 1670 | regshift = 0; |
| 1671 | irq = 0; |
| 1672 | ipmb = 0x20; |
| 1673 | |
| 1674 | next = strchr(curr, ':'); |
| 1675 | if (next) { |
| 1676 | *next = '\0'; |
| 1677 | next++; |
| 1678 | } |
| 1679 | |
| 1680 | rv = parse_str(hotmod_ops, &ival, "operation", &curr); |
| 1681 | if (rv) |
| 1682 | break; |
| 1683 | op = ival; |
| 1684 | |
| 1685 | rv = parse_str(hotmod_si, &ival, "interface type", &curr); |
| 1686 | if (rv) |
| 1687 | break; |
| 1688 | si_type = ival; |
| 1689 | |
| 1690 | rv = parse_str(hotmod_as, &addr_space, "address space", &curr); |
| 1691 | if (rv) |
| 1692 | break; |
| 1693 | |
| 1694 | s = strchr(curr, ','); |
| 1695 | if (s) { |
| 1696 | *s = '\0'; |
| 1697 | s++; |
| 1698 | } |
| 1699 | addr = simple_strtoul(curr, &n, 0); |
| 1700 | if ((*n != '\0') || (*curr == '\0')) { |
| 1701 | printk(KERN_WARNING PFX "Invalid hotmod address" |
| 1702 | " '%s'\n", curr); |
| 1703 | break; |
| 1704 | } |
| 1705 | |
| 1706 | while (s) { |
| 1707 | curr = s; |
| 1708 | s = strchr(curr, ','); |
| 1709 | if (s) { |
| 1710 | *s = '\0'; |
| 1711 | s++; |
| 1712 | } |
| 1713 | o = strchr(curr, '='); |
| 1714 | if (o) { |
| 1715 | *o = '\0'; |
| 1716 | o++; |
| 1717 | } |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1718 | rv = check_hotmod_int_op(curr, o, "rsp", ®spacing); |
| 1719 | if (rv < 0) |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1720 | goto out; |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1721 | else if (rv) |
| 1722 | continue; |
| 1723 | rv = check_hotmod_int_op(curr, o, "rsi", ®size); |
| 1724 | if (rv < 0) |
| 1725 | goto out; |
| 1726 | else if (rv) |
| 1727 | continue; |
| 1728 | rv = check_hotmod_int_op(curr, o, "rsh", ®shift); |
| 1729 | if (rv < 0) |
| 1730 | goto out; |
| 1731 | else if (rv) |
| 1732 | continue; |
| 1733 | rv = check_hotmod_int_op(curr, o, "irq", &irq); |
| 1734 | if (rv < 0) |
| 1735 | goto out; |
| 1736 | else if (rv) |
| 1737 | continue; |
| 1738 | rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb); |
| 1739 | if (rv < 0) |
| 1740 | goto out; |
| 1741 | else if (rv) |
| 1742 | continue; |
| 1743 | |
| 1744 | rv = -EINVAL; |
| 1745 | printk(KERN_WARNING PFX |
| 1746 | "Invalid hotmod option '%s'\n", |
| 1747 | curr); |
| 1748 | goto out; |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | if (op == HM_ADD) { |
| 1752 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 1753 | if (!info) { |
| 1754 | rv = -ENOMEM; |
| 1755 | goto out; |
| 1756 | } |
| 1757 | |
| 1758 | info->addr_source = "hotmod"; |
| 1759 | info->si_type = si_type; |
| 1760 | info->io.addr_data = addr; |
| 1761 | info->io.addr_type = addr_space; |
| 1762 | if (addr_space == IPMI_MEM_ADDR_SPACE) |
| 1763 | info->io_setup = mem_setup; |
| 1764 | else |
| 1765 | info->io_setup = port_setup; |
| 1766 | |
| 1767 | info->io.addr = NULL; |
| 1768 | info->io.regspacing = regspacing; |
| 1769 | if (!info->io.regspacing) |
| 1770 | info->io.regspacing = DEFAULT_REGSPACING; |
| 1771 | info->io.regsize = regsize; |
| 1772 | if (!info->io.regsize) |
| 1773 | info->io.regsize = DEFAULT_REGSPACING; |
| 1774 | info->io.regshift = regshift; |
| 1775 | info->irq = irq; |
| 1776 | if (info->irq) |
| 1777 | info->irq_setup = std_irq_setup; |
| 1778 | info->slave_addr = ipmb; |
| 1779 | |
| 1780 | try_smi_init(info); |
| 1781 | } else { |
| 1782 | /* remove */ |
| 1783 | struct smi_info *e, *tmp_e; |
| 1784 | |
| 1785 | mutex_lock(&smi_infos_lock); |
| 1786 | list_for_each_entry_safe(e, tmp_e, &smi_infos, link) { |
| 1787 | if (e->io.addr_type != addr_space) |
| 1788 | continue; |
| 1789 | if (e->si_type != si_type) |
| 1790 | continue; |
| 1791 | if (e->io.addr_data == addr) |
| 1792 | cleanup_one_si(e); |
| 1793 | } |
| 1794 | mutex_unlock(&smi_infos_lock); |
| 1795 | } |
| 1796 | } |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1797 | rv = len; |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 1798 | out: |
| 1799 | kfree(str); |
| 1800 | return rv; |
| 1801 | } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1802 | |
| 1803 | static __devinit void hardcode_find_bmc(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1805 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | struct smi_info *info; |
| 1807 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1808 | for (i = 0; i < SI_MAX_PARMS; i++) { |
| 1809 | if (!ports[i] && !addrs[i]) |
| 1810 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1812 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 1813 | if (!info) |
| 1814 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1816 | info->addr_source = "hardcoded"; |
| 1817 | |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1818 | if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1819 | info->si_type = SI_KCS; |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1820 | } else if (strcmp(si_type[i], "smic") == 0) { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1821 | info->si_type = SI_SMIC; |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 1822 | } else if (strcmp(si_type[i], "bt") == 0) { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1823 | info->si_type = SI_BT; |
| 1824 | } else { |
| 1825 | printk(KERN_WARNING |
| 1826 | "ipmi_si: Interface type specified " |
| 1827 | "for interface %d, was invalid: %s\n", |
| 1828 | i, si_type[i]); |
| 1829 | kfree(info); |
| 1830 | continue; |
| 1831 | } |
| 1832 | |
| 1833 | if (ports[i]) { |
| 1834 | /* An I/O port */ |
| 1835 | info->io_setup = port_setup; |
| 1836 | info->io.addr_data = ports[i]; |
| 1837 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
| 1838 | } else if (addrs[i]) { |
| 1839 | /* A memory port */ |
| 1840 | info->io_setup = mem_setup; |
| 1841 | info->io.addr_data = addrs[i]; |
| 1842 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
| 1843 | } else { |
| 1844 | printk(KERN_WARNING |
| 1845 | "ipmi_si: Interface type specified " |
| 1846 | "for interface %d, " |
| 1847 | "but port and address were not set or " |
| 1848 | "set to zero.\n", i); |
| 1849 | kfree(info); |
| 1850 | continue; |
| 1851 | } |
| 1852 | |
| 1853 | info->io.addr = NULL; |
| 1854 | info->io.regspacing = regspacings[i]; |
| 1855 | if (!info->io.regspacing) |
| 1856 | info->io.regspacing = DEFAULT_REGSPACING; |
| 1857 | info->io.regsize = regsizes[i]; |
| 1858 | if (!info->io.regsize) |
| 1859 | info->io.regsize = DEFAULT_REGSPACING; |
| 1860 | info->io.regshift = regshifts[i]; |
| 1861 | info->irq = irqs[i]; |
| 1862 | if (info->irq) |
| 1863 | info->irq_setup = std_irq_setup; |
| 1864 | |
| 1865 | try_smi_init(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | } |
| 1868 | |
Len Brown | 8466361 | 2005-08-24 12:09:07 -0400 | [diff] [blame] | 1869 | #ifdef CONFIG_ACPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
| 1871 | #include <linux/acpi.h> |
| 1872 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1873 | /* |
| 1874 | * Once we get an ACPI failure, we don't try any more, because we go |
| 1875 | * through the tables sequentially. Once we don't find a table, there |
| 1876 | * are no more. |
| 1877 | */ |
Randy Dunlap | 0c8204b | 2006-12-10 02:19:06 -0800 | [diff] [blame] | 1878 | static int acpi_failure; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
| 1880 | /* For GPE-type interrupts. */ |
| 1881 | static u32 ipmi_acpi_gpe(void *context) |
| 1882 | { |
| 1883 | struct smi_info *smi_info = context; |
| 1884 | unsigned long flags; |
| 1885 | #ifdef DEBUG_TIMING |
| 1886 | struct timeval t; |
| 1887 | #endif |
| 1888 | |
| 1889 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
| 1890 | |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 1891 | smi_inc_stat(smi_info, interrupts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | #ifdef DEBUG_TIMING |
| 1894 | do_gettimeofday(&t); |
| 1895 | printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
| 1896 | #endif |
| 1897 | smi_event_handler(smi_info, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
| 1899 | |
| 1900 | return ACPI_INTERRUPT_HANDLED; |
| 1901 | } |
| 1902 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1903 | static void acpi_gpe_irq_cleanup(struct smi_info *info) |
| 1904 | { |
| 1905 | if (!info->irq) |
| 1906 | return; |
| 1907 | |
| 1908 | acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe); |
| 1909 | } |
| 1910 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | static int acpi_gpe_irq_setup(struct smi_info *info) |
| 1912 | { |
| 1913 | acpi_status status; |
| 1914 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1915 | if (!info->irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | return 0; |
| 1917 | |
| 1918 | /* FIXME - is level triggered right? */ |
| 1919 | status = acpi_install_gpe_handler(NULL, |
| 1920 | info->irq, |
| 1921 | ACPI_GPE_LEVEL_TRIGGERED, |
| 1922 | &ipmi_acpi_gpe, |
| 1923 | info); |
| 1924 | if (status != AE_OK) { |
| 1925 | printk(KERN_WARNING |
| 1926 | "ipmi_si: %s unable to claim ACPI GPE %d," |
| 1927 | " running polled\n", |
| 1928 | DEVICE_NAME, info->irq); |
| 1929 | info->irq = 0; |
| 1930 | return -EINVAL; |
| 1931 | } else { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1932 | info->irq_cleanup = acpi_gpe_irq_cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | printk(" Using ACPI GPE %d\n", info->irq); |
| 1934 | return 0; |
| 1935 | } |
| 1936 | } |
| 1937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | /* |
| 1939 | * Defined at |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1940 | * http://h21007.www2.hp.com/dspp/files/unprotected/devresource/ |
| 1941 | * Docs/TechPapers/IA64/hpspmi.pdf |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | */ |
| 1943 | struct SPMITable { |
| 1944 | s8 Signature[4]; |
| 1945 | u32 Length; |
| 1946 | u8 Revision; |
| 1947 | u8 Checksum; |
| 1948 | s8 OEMID[6]; |
| 1949 | s8 OEMTableID[8]; |
| 1950 | s8 OEMRevision[4]; |
| 1951 | s8 CreatorID[4]; |
| 1952 | s8 CreatorRevision[4]; |
| 1953 | u8 InterfaceType; |
| 1954 | u8 IPMIlegacy; |
| 1955 | s16 SpecificationRevision; |
| 1956 | |
| 1957 | /* |
| 1958 | * Bit 0 - SCI interrupt supported |
| 1959 | * Bit 1 - I/O APIC/SAPIC |
| 1960 | */ |
| 1961 | u8 InterruptType; |
| 1962 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1963 | /* |
| 1964 | * If bit 0 of InterruptType is set, then this is the SCI |
| 1965 | * interrupt in the GPEx_STS register. |
| 1966 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | u8 GPE; |
| 1968 | |
| 1969 | s16 Reserved; |
| 1970 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1971 | /* |
| 1972 | * If bit 1 of InterruptType is set, then this is the I/O |
| 1973 | * APIC/SAPIC interrupt. |
| 1974 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1975 | u32 GlobalSystemInterrupt; |
| 1976 | |
| 1977 | /* The actual register address. */ |
| 1978 | struct acpi_generic_address addr; |
| 1979 | |
| 1980 | u8 UID[4]; |
| 1981 | |
| 1982 | s8 spmi_id[1]; /* A '\0' terminated array starts here. */ |
| 1983 | }; |
| 1984 | |
Bjorn Helgaas | 18a3e0b | 2009-11-17 17:05:29 -0700 | [diff] [blame] | 1985 | static __devinit int try_init_spmi(struct SPMITable *spmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | { |
| 1987 | struct smi_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | u8 addr_space; |
| 1989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | if (spmi->IPMIlegacy != 1) { |
| 1991 | printk(KERN_INFO "IPMI: Bad SPMI legacy %d\n", spmi->IPMIlegacy); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 1992 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 1995 | if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | addr_space = IPMI_MEM_ADDR_SPACE; |
| 1997 | else |
| 1998 | addr_space = IPMI_IO_ADDR_SPACE; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 1999 | |
| 2000 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 2001 | if (!info) { |
| 2002 | printk(KERN_ERR "ipmi_si: Could not allocate SI data (3)\n"); |
| 2003 | return -ENOMEM; |
| 2004 | } |
| 2005 | |
Bjorn Helgaas | 18a3e0b | 2009-11-17 17:05:29 -0700 | [diff] [blame] | 2006 | info->addr_source = "SPMI"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2008 | /* Figure out the interface type. */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2009 | switch (spmi->InterfaceType) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | case 1: /* KCS */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2011 | info->si_type = SI_KCS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2012 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | case 2: /* SMIC */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2014 | info->si_type = SI_SMIC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | case 3: /* BT */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2017 | info->si_type = SI_BT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | default: |
| 2020 | printk(KERN_INFO "ipmi_si: Unknown ACPI/SPMI SI type %d\n", |
| 2021 | spmi->InterfaceType); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2022 | kfree(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | return -EIO; |
| 2024 | } |
| 2025 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | if (spmi->InterruptType & 1) { |
| 2027 | /* We've got a GPE interrupt. */ |
| 2028 | info->irq = spmi->GPE; |
| 2029 | info->irq_setup = acpi_gpe_irq_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } else if (spmi->InterruptType & 2) { |
| 2031 | /* We've got an APIC/SAPIC interrupt. */ |
| 2032 | info->irq = spmi->GlobalSystemInterrupt; |
| 2033 | info->irq_setup = std_irq_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | } else { |
| 2035 | /* Use the default interrupt setting. */ |
| 2036 | info->irq = 0; |
| 2037 | info->irq_setup = NULL; |
| 2038 | } |
| 2039 | |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 2040 | if (spmi->addr.bit_width) { |
Corey Minyard | 35bc37a | 2005-05-01 08:59:10 -0700 | [diff] [blame] | 2041 | /* A (hopefully) properly formed register bit width. */ |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 2042 | info->io.regspacing = spmi->addr.bit_width / 8; |
Corey Minyard | 35bc37a | 2005-05-01 08:59:10 -0700 | [diff] [blame] | 2043 | } else { |
Corey Minyard | 35bc37a | 2005-05-01 08:59:10 -0700 | [diff] [blame] | 2044 | info->io.regspacing = DEFAULT_REGSPACING; |
| 2045 | } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2046 | info->io.regsize = info->io.regspacing; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 2047 | info->io.regshift = spmi->addr.bit_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2048 | |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 2049 | if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | info->io_setup = mem_setup; |
Corey Minyard | 8fe1425 | 2007-05-12 10:36:58 -0700 | [diff] [blame] | 2051 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 2052 | } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | info->io_setup = port_setup; |
Corey Minyard | 8fe1425 | 2007-05-12 10:36:58 -0700 | [diff] [blame] | 2054 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | } else { |
| 2056 | kfree(info); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2057 | printk(KERN_WARNING |
| 2058 | "ipmi_si: Unknown ACPI I/O Address type\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | return -EIO; |
| 2060 | } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2061 | info->io.addr_data = spmi->addr.address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2063 | try_smi_init(info); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | return 0; |
| 2066 | } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2067 | |
Bjorn Helgaas | 18a3e0b | 2009-11-17 17:05:29 -0700 | [diff] [blame] | 2068 | static __devinit void spmi_find_bmc(void) |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2069 | { |
| 2070 | acpi_status status; |
| 2071 | struct SPMITable *spmi; |
| 2072 | int i; |
| 2073 | |
| 2074 | if (acpi_disabled) |
| 2075 | return; |
| 2076 | |
| 2077 | if (acpi_failure) |
| 2078 | return; |
| 2079 | |
| 2080 | for (i = 0; ; i++) { |
Alexey Starikovskiy | 15a58ed | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 2081 | status = acpi_get_table(ACPI_SIG_SPMI, i+1, |
| 2082 | (struct acpi_table_header **)&spmi); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2083 | if (status != AE_OK) |
| 2084 | return; |
| 2085 | |
Bjorn Helgaas | 18a3e0b | 2009-11-17 17:05:29 -0700 | [diff] [blame] | 2086 | try_init_spmi(spmi); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2087 | } |
| 2088 | } |
Bjorn Helgaas | 9e368fa | 2009-11-17 17:05:34 -0700 | [diff] [blame] | 2089 | |
| 2090 | static int __devinit ipmi_pnp_probe(struct pnp_dev *dev, |
| 2091 | const struct pnp_device_id *dev_id) |
| 2092 | { |
| 2093 | struct acpi_device *acpi_dev; |
| 2094 | struct smi_info *info; |
| 2095 | acpi_handle handle; |
| 2096 | acpi_status status; |
| 2097 | unsigned long long tmp; |
| 2098 | |
| 2099 | acpi_dev = pnp_acpi_device(dev); |
| 2100 | if (!acpi_dev) |
| 2101 | return -ENODEV; |
| 2102 | |
| 2103 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 2104 | if (!info) |
| 2105 | return -ENOMEM; |
| 2106 | |
| 2107 | info->addr_source = "ACPI"; |
| 2108 | |
| 2109 | handle = acpi_dev->handle; |
| 2110 | |
| 2111 | /* _IFT tells us the interface type: KCS, BT, etc */ |
| 2112 | status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp); |
| 2113 | if (ACPI_FAILURE(status)) |
| 2114 | goto err_free; |
| 2115 | |
| 2116 | switch (tmp) { |
| 2117 | case 1: |
| 2118 | info->si_type = SI_KCS; |
| 2119 | break; |
| 2120 | case 2: |
| 2121 | info->si_type = SI_SMIC; |
| 2122 | break; |
| 2123 | case 3: |
| 2124 | info->si_type = SI_BT; |
| 2125 | break; |
| 2126 | default: |
| 2127 | dev_info(&dev->dev, "unknown interface type %lld\n", tmp); |
| 2128 | goto err_free; |
| 2129 | } |
| 2130 | |
| 2131 | if (pnp_port_valid(dev, 0)) { |
| 2132 | info->io_setup = port_setup; |
| 2133 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
| 2134 | info->io.addr_data = pnp_port_start(dev, 0); |
| 2135 | } else if (pnp_mem_valid(dev, 0)) { |
| 2136 | info->io_setup = mem_setup; |
| 2137 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
| 2138 | info->io.addr_data = pnp_mem_start(dev, 0); |
| 2139 | } else { |
| 2140 | dev_err(&dev->dev, "no I/O or memory address\n"); |
| 2141 | goto err_free; |
| 2142 | } |
| 2143 | |
| 2144 | info->io.regspacing = DEFAULT_REGSPACING; |
| 2145 | info->io.regsize = DEFAULT_REGSPACING; |
| 2146 | info->io.regshift = 0; |
| 2147 | |
| 2148 | /* If _GPE exists, use it; otherwise use standard interrupts */ |
| 2149 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp); |
| 2150 | if (ACPI_SUCCESS(status)) { |
| 2151 | info->irq = tmp; |
| 2152 | info->irq_setup = acpi_gpe_irq_setup; |
| 2153 | } else if (pnp_irq_valid(dev, 0)) { |
| 2154 | info->irq = pnp_irq(dev, 0); |
| 2155 | info->irq_setup = std_irq_setup; |
| 2156 | } |
| 2157 | |
| 2158 | info->dev = &acpi_dev->dev; |
| 2159 | pnp_set_drvdata(dev, info); |
| 2160 | |
| 2161 | return try_smi_init(info); |
| 2162 | |
| 2163 | err_free: |
| 2164 | kfree(info); |
| 2165 | return -EINVAL; |
| 2166 | } |
| 2167 | |
| 2168 | static void __devexit ipmi_pnp_remove(struct pnp_dev *dev) |
| 2169 | { |
| 2170 | struct smi_info *info = pnp_get_drvdata(dev); |
| 2171 | |
| 2172 | cleanup_one_si(info); |
| 2173 | } |
| 2174 | |
| 2175 | static const struct pnp_device_id pnp_dev_table[] = { |
| 2176 | {"IPI0001", 0}, |
| 2177 | {"", 0}, |
| 2178 | }; |
| 2179 | |
| 2180 | static struct pnp_driver ipmi_pnp_driver = { |
| 2181 | .name = DEVICE_NAME, |
| 2182 | .probe = ipmi_pnp_probe, |
| 2183 | .remove = __devexit_p(ipmi_pnp_remove), |
| 2184 | .id_table = pnp_dev_table, |
| 2185 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | #endif |
| 2187 | |
Matt Domsch | a9fad4c | 2006-01-11 12:17:44 -0800 | [diff] [blame] | 2188 | #ifdef CONFIG_DMI |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2189 | struct dmi_ipmi_data { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | u8 type; |
| 2191 | u8 addr_space; |
| 2192 | unsigned long base_addr; |
| 2193 | u8 irq; |
| 2194 | u8 offset; |
| 2195 | u8 slave_addr; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2196 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 2198 | static int __devinit decode_dmi(const struct dmi_header *dm, |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2199 | struct dmi_ipmi_data *dmi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 2201 | const u8 *data = (const u8 *)dm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2202 | unsigned long base_addr; |
| 2203 | u8 reg_spacing; |
Andrey Panin | b224cd3 | 2005-09-06 15:18:37 -0700 | [diff] [blame] | 2204 | u8 len = dm->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2206 | dmi->type = data[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | |
| 2208 | memcpy(&base_addr, data+8, sizeof(unsigned long)); |
| 2209 | if (len >= 0x11) { |
| 2210 | if (base_addr & 1) { |
| 2211 | /* I/O */ |
| 2212 | base_addr &= 0xFFFE; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2213 | dmi->addr_space = IPMI_IO_ADDR_SPACE; |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2214 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | /* Memory */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2216 | dmi->addr_space = IPMI_MEM_ADDR_SPACE; |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | /* If bit 4 of byte 0x10 is set, then the lsb for the address |
| 2219 | is odd. */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2220 | dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2222 | dmi->irq = data[0x11]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | |
| 2224 | /* The top two bits of byte 0x10 hold the register spacing. */ |
Andrey Panin | b224cd3 | 2005-09-06 15:18:37 -0700 | [diff] [blame] | 2225 | reg_spacing = (data[0x10] & 0xC0) >> 6; |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2226 | switch (reg_spacing) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | case 0x00: /* Byte boundaries */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2228 | dmi->offset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | break; |
| 2230 | case 0x01: /* 32-bit boundaries */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2231 | dmi->offset = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | break; |
| 2233 | case 0x02: /* 16-byte boundaries */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2234 | dmi->offset = 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | break; |
| 2236 | default: |
| 2237 | /* Some other interface, just ignore it. */ |
| 2238 | return -EIO; |
| 2239 | } |
| 2240 | } else { |
| 2241 | /* Old DMI spec. */ |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2242 | /* |
| 2243 | * Note that technically, the lower bit of the base |
Corey Minyard | 9206880 | 2005-05-01 08:59:10 -0700 | [diff] [blame] | 2244 | * address should be 1 if the address is I/O and 0 if |
| 2245 | * the address is in memory. So many systems get that |
| 2246 | * wrong (and all that I have seen are I/O) so we just |
| 2247 | * ignore that bit and assume I/O. Systems that use |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2248 | * memory should use the newer spec, anyway. |
| 2249 | */ |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2250 | dmi->base_addr = base_addr & 0xfffe; |
| 2251 | dmi->addr_space = IPMI_IO_ADDR_SPACE; |
| 2252 | dmi->offset = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2253 | } |
| 2254 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2255 | dmi->slave_addr = data[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2257 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2260 | static __devinit void try_init_dmi(struct dmi_ipmi_data *ipmi_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2261 | { |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 2262 | struct smi_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2264 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 2265 | if (!info) { |
| 2266 | printk(KERN_ERR |
| 2267 | "ipmi_si: Could not allocate SI data\n"); |
| 2268 | return; |
| 2269 | } |
| 2270 | |
| 2271 | info->addr_source = "SMBIOS"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 2273 | switch (ipmi_data->type) { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2274 | case 0x01: /* KCS */ |
| 2275 | info->si_type = SI_KCS; |
| 2276 | break; |
| 2277 | case 0x02: /* SMIC */ |
| 2278 | info->si_type = SI_SMIC; |
| 2279 | break; |
| 2280 | case 0x03: /* BT */ |
| 2281 | info->si_type = SI_BT; |
| 2282 | break; |
| 2283 | default: |
Jesper Juhl | 80cd692 | 2007-07-31 00:39:05 -0700 | [diff] [blame] | 2284 | kfree(info); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2285 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2288 | switch (ipmi_data->addr_space) { |
| 2289 | case IPMI_MEM_ADDR_SPACE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2290 | info->io_setup = mem_setup; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2291 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
| 2292 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2293 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2294 | case IPMI_IO_ADDR_SPACE: |
| 2295 | info->io_setup = port_setup; |
| 2296 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
| 2297 | break; |
| 2298 | |
| 2299 | default: |
| 2300 | kfree(info); |
| 2301 | printk(KERN_WARNING |
| 2302 | "ipmi_si: Unknown SMBIOS I/O Address type: %d.\n", |
| 2303 | ipmi_data->addr_space); |
| 2304 | return; |
| 2305 | } |
| 2306 | info->io.addr_data = ipmi_data->base_addr; |
| 2307 | |
| 2308 | info->io.regspacing = ipmi_data->offset; |
| 2309 | if (!info->io.regspacing) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | info->io.regspacing = DEFAULT_REGSPACING; |
| 2311 | info->io.regsize = DEFAULT_REGSPACING; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2312 | info->io.regshift = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | |
| 2314 | info->slave_addr = ipmi_data->slave_addr; |
| 2315 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2316 | info->irq = ipmi_data->irq; |
| 2317 | if (info->irq) |
| 2318 | info->irq_setup = std_irq_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2320 | try_smi_init(info); |
| 2321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2322 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2323 | static void __devinit dmi_find_bmc(void) |
| 2324 | { |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 2325 | const struct dmi_device *dev = NULL; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2326 | struct dmi_ipmi_data data; |
| 2327 | int rv; |
| 2328 | |
| 2329 | while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { |
Jeff Garzik | 397f4eb | 2006-10-03 01:13:52 -0700 | [diff] [blame] | 2330 | memset(&data, 0, sizeof(data)); |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 2331 | rv = decode_dmi((const struct dmi_header *) dev->device_data, |
| 2332 | &data); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2333 | if (!rv) |
| 2334 | try_init_dmi(&data); |
| 2335 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | } |
Matt Domsch | a9fad4c | 2006-01-11 12:17:44 -0800 | [diff] [blame] | 2337 | #endif /* CONFIG_DMI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2338 | |
| 2339 | #ifdef CONFIG_PCI |
| 2340 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2341 | #define PCI_ERMC_CLASSCODE 0x0C0700 |
| 2342 | #define PCI_ERMC_CLASSCODE_MASK 0xffffff00 |
| 2343 | #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff |
| 2344 | #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00 |
| 2345 | #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01 |
| 2346 | #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02 |
| 2347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | #define PCI_HP_VENDOR_ID 0x103C |
| 2349 | #define PCI_MMC_DEVICE_ID 0x121A |
| 2350 | #define PCI_MMC_ADDR_CW 0x10 |
| 2351 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2352 | static void ipmi_pci_cleanup(struct smi_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2354 | struct pci_dev *pdev = info->addr_source_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2356 | pci_disable_device(pdev); |
| 2357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2359 | static int __devinit ipmi_pci_probe(struct pci_dev *pdev, |
| 2360 | const struct pci_device_id *ent) |
| 2361 | { |
| 2362 | int rv; |
| 2363 | int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK; |
| 2364 | struct smi_info *info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2366 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 2367 | if (!info) |
Dave Jones | 1cd441f | 2006-10-19 23:29:09 -0700 | [diff] [blame] | 2368 | return -ENOMEM; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2369 | |
| 2370 | info->addr_source = "PCI"; |
| 2371 | |
| 2372 | switch (class_type) { |
| 2373 | case PCI_ERMC_CLASSCODE_TYPE_SMIC: |
| 2374 | info->si_type = SI_SMIC; |
| 2375 | break; |
| 2376 | |
| 2377 | case PCI_ERMC_CLASSCODE_TYPE_KCS: |
| 2378 | info->si_type = SI_KCS; |
| 2379 | break; |
| 2380 | |
| 2381 | case PCI_ERMC_CLASSCODE_TYPE_BT: |
| 2382 | info->si_type = SI_BT; |
| 2383 | break; |
| 2384 | |
| 2385 | default: |
| 2386 | kfree(info); |
| 2387 | printk(KERN_INFO "ipmi_si: %s: Unknown IPMI type: %d\n", |
| 2388 | pci_name(pdev), class_type); |
Dave Jones | 1cd441f | 2006-10-19 23:29:09 -0700 | [diff] [blame] | 2389 | return -ENOMEM; |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 2390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2392 | rv = pci_enable_device(pdev); |
| 2393 | if (rv) { |
| 2394 | printk(KERN_ERR "ipmi_si: %s: couldn't enable PCI device\n", |
| 2395 | pci_name(pdev)); |
| 2396 | kfree(info); |
| 2397 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | } |
| 2399 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2400 | info->addr_source_cleanup = ipmi_pci_cleanup; |
| 2401 | info->addr_source_data = pdev; |
| 2402 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2403 | if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) { |
| 2404 | info->io_setup = port_setup; |
| 2405 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
| 2406 | } else { |
| 2407 | info->io_setup = mem_setup; |
| 2408 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2410 | info->io.addr_data = pci_resource_start(pdev, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2411 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2412 | info->io.regspacing = DEFAULT_REGSPACING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | info->io.regsize = DEFAULT_REGSPACING; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2414 | info->io.regshift = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2416 | info->irq = pdev->irq; |
| 2417 | if (info->irq) |
| 2418 | info->irq_setup = std_irq_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2420 | info->dev = &pdev->dev; |
Corey Minyard | fca3b74 | 2007-05-08 00:23:59 -0700 | [diff] [blame] | 2421 | pci_set_drvdata(pdev, info); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2422 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2423 | return try_smi_init(info); |
| 2424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2426 | static void __devexit ipmi_pci_remove(struct pci_dev *pdev) |
| 2427 | { |
Corey Minyard | fca3b74 | 2007-05-08 00:23:59 -0700 | [diff] [blame] | 2428 | struct smi_info *info = pci_get_drvdata(pdev); |
| 2429 | cleanup_one_si(info); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2430 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2432 | #ifdef CONFIG_PM |
| 2433 | static int ipmi_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2434 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2435 | return 0; |
| 2436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2438 | static int ipmi_pci_resume(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2440 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2442 | #endif |
| 2443 | |
| 2444 | static struct pci_device_id ipmi_pci_devices[] = { |
| 2445 | { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) }, |
Kees Cook | 248bdd5 | 2007-09-18 22:46:32 -0700 | [diff] [blame] | 2446 | { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) }, |
| 2447 | { 0, } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2448 | }; |
| 2449 | MODULE_DEVICE_TABLE(pci, ipmi_pci_devices); |
| 2450 | |
| 2451 | static struct pci_driver ipmi_pci_driver = { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2452 | .name = DEVICE_NAME, |
| 2453 | .id_table = ipmi_pci_devices, |
| 2454 | .probe = ipmi_pci_probe, |
| 2455 | .remove = __devexit_p(ipmi_pci_remove), |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2456 | #ifdef CONFIG_PM |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2457 | .suspend = ipmi_pci_suspend, |
| 2458 | .resume = ipmi_pci_resume, |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2459 | #endif |
| 2460 | }; |
| 2461 | #endif /* CONFIG_PCI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | |
| 2463 | |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2464 | #ifdef CONFIG_PPC_OF |
| 2465 | static int __devinit ipmi_of_probe(struct of_device *dev, |
| 2466 | const struct of_device_id *match) |
| 2467 | { |
| 2468 | struct smi_info *info; |
| 2469 | struct resource resource; |
| 2470 | const int *regsize, *regspacing, *regshift; |
| 2471 | struct device_node *np = dev->node; |
| 2472 | int ret; |
| 2473 | int proplen; |
| 2474 | |
| 2475 | dev_info(&dev->dev, PFX "probing via device tree\n"); |
| 2476 | |
| 2477 | ret = of_address_to_resource(np, 0, &resource); |
| 2478 | if (ret) { |
| 2479 | dev_warn(&dev->dev, PFX "invalid address from OF\n"); |
| 2480 | return ret; |
| 2481 | } |
| 2482 | |
Stephen Rothwell | 9c25099 | 2007-08-15 16:42:12 +1000 | [diff] [blame] | 2483 | regsize = of_get_property(np, "reg-size", &proplen); |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2484 | if (regsize && proplen != 4) { |
| 2485 | dev_warn(&dev->dev, PFX "invalid regsize from OF\n"); |
| 2486 | return -EINVAL; |
| 2487 | } |
| 2488 | |
Stephen Rothwell | 9c25099 | 2007-08-15 16:42:12 +1000 | [diff] [blame] | 2489 | regspacing = of_get_property(np, "reg-spacing", &proplen); |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2490 | if (regspacing && proplen != 4) { |
| 2491 | dev_warn(&dev->dev, PFX "invalid regspacing from OF\n"); |
| 2492 | return -EINVAL; |
| 2493 | } |
| 2494 | |
Stephen Rothwell | 9c25099 | 2007-08-15 16:42:12 +1000 | [diff] [blame] | 2495 | regshift = of_get_property(np, "reg-shift", &proplen); |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2496 | if (regshift && proplen != 4) { |
| 2497 | dev_warn(&dev->dev, PFX "invalid regshift from OF\n"); |
| 2498 | return -EINVAL; |
| 2499 | } |
| 2500 | |
| 2501 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 2502 | |
| 2503 | if (!info) { |
| 2504 | dev_err(&dev->dev, |
| 2505 | PFX "could not allocate memory for OF probe\n"); |
| 2506 | return -ENOMEM; |
| 2507 | } |
| 2508 | |
| 2509 | info->si_type = (enum si_type) match->data; |
| 2510 | info->addr_source = "device-tree"; |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2511 | info->irq_setup = std_irq_setup; |
| 2512 | |
Nate Case | 3b7ec11 | 2008-05-14 16:05:39 -0700 | [diff] [blame] | 2513 | if (resource.flags & IORESOURCE_IO) { |
| 2514 | info->io_setup = port_setup; |
| 2515 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
| 2516 | } else { |
| 2517 | info->io_setup = mem_setup; |
| 2518 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
| 2519 | } |
| 2520 | |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2521 | info->io.addr_data = resource.start; |
| 2522 | |
| 2523 | info->io.regsize = regsize ? *regsize : DEFAULT_REGSIZE; |
| 2524 | info->io.regspacing = regspacing ? *regspacing : DEFAULT_REGSPACING; |
| 2525 | info->io.regshift = regshift ? *regshift : 0; |
| 2526 | |
| 2527 | info->irq = irq_of_parse_and_map(dev->node, 0); |
| 2528 | info->dev = &dev->dev; |
| 2529 | |
Mijo Safradin | 32d2198 | 2007-08-22 14:01:48 -0700 | [diff] [blame] | 2530 | dev_dbg(&dev->dev, "addr 0x%lx regsize %d spacing %d irq %x\n", |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2531 | info->io.addr_data, info->io.regsize, info->io.regspacing, |
| 2532 | info->irq); |
| 2533 | |
Greg Kroah-Hartman | 9de33df | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2534 | dev_set_drvdata(&dev->dev, info); |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2535 | |
| 2536 | return try_smi_init(info); |
| 2537 | } |
| 2538 | |
| 2539 | static int __devexit ipmi_of_remove(struct of_device *dev) |
| 2540 | { |
Greg Kroah-Hartman | 9de33df | 2009-05-04 12:40:54 -0700 | [diff] [blame] | 2541 | cleanup_one_si(dev_get_drvdata(&dev->dev)); |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2542 | return 0; |
| 2543 | } |
| 2544 | |
| 2545 | static struct of_device_id ipmi_match[] = |
| 2546 | { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2547 | { .type = "ipmi", .compatible = "ipmi-kcs", |
| 2548 | .data = (void *)(unsigned long) SI_KCS }, |
| 2549 | { .type = "ipmi", .compatible = "ipmi-smic", |
| 2550 | .data = (void *)(unsigned long) SI_SMIC }, |
| 2551 | { .type = "ipmi", .compatible = "ipmi-bt", |
| 2552 | .data = (void *)(unsigned long) SI_BT }, |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2553 | {}, |
| 2554 | }; |
| 2555 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2556 | static struct of_platform_driver ipmi_of_platform_driver = { |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 2557 | .name = "ipmi", |
| 2558 | .match_table = ipmi_match, |
| 2559 | .probe = ipmi_of_probe, |
| 2560 | .remove = __devexit_p(ipmi_of_remove), |
| 2561 | }; |
| 2562 | #endif /* CONFIG_PPC_OF */ |
| 2563 | |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 2564 | static int wait_for_msg_done(struct smi_info *smi_info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | { |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2566 | enum si_sm_result smi_result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | |
| 2568 | smi_result = smi_info->handlers->event(smi_info->si_sm, 0); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2569 | for (;;) { |
Corey Minyard | c3e7e79 | 2005-11-07 01:00:02 -0800 | [diff] [blame] | 2570 | if (smi_result == SI_SM_CALL_WITH_DELAY || |
| 2571 | smi_result == SI_SM_CALL_WITH_TICK_DELAY) { |
Nishanth Aravamudan | da4cd8d | 2005-09-10 00:27:30 -0700 | [diff] [blame] | 2572 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | smi_result = smi_info->handlers->event( |
| 2574 | smi_info->si_sm, 100); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2575 | } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | smi_result = smi_info->handlers->event( |
| 2577 | smi_info->si_sm, 0); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2578 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | break; |
| 2580 | } |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 2581 | if (smi_result == SI_SM_HOSED) |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2582 | /* |
| 2583 | * We couldn't get the state machine to run, so whatever's at |
| 2584 | * the port is probably not an IPMI SMI interface. |
| 2585 | */ |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 2586 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 2588 | return 0; |
| 2589 | } |
| 2590 | |
| 2591 | static int try_get_dev_id(struct smi_info *smi_info) |
| 2592 | { |
| 2593 | unsigned char msg[2]; |
| 2594 | unsigned char *resp; |
| 2595 | unsigned long resp_len; |
| 2596 | int rv = 0; |
| 2597 | |
| 2598 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); |
| 2599 | if (!resp) |
| 2600 | return -ENOMEM; |
| 2601 | |
| 2602 | /* |
| 2603 | * Do a Get Device ID command, since it comes back with some |
| 2604 | * useful info. |
| 2605 | */ |
| 2606 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
| 2607 | msg[1] = IPMI_GET_DEVICE_ID_CMD; |
| 2608 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
| 2609 | |
| 2610 | rv = wait_for_msg_done(smi_info); |
| 2611 | if (rv) |
| 2612 | goto out; |
| 2613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, |
| 2615 | resp, IPMI_MAX_MSG_LENGTH); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2616 | |
Corey Minyard | d8c9861 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 2617 | /* Check and record info from the get device id, in case we need it. */ |
| 2618 | rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | |
| 2620 | out: |
| 2621 | kfree(resp); |
| 2622 | return rv; |
| 2623 | } |
| 2624 | |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 2625 | static int try_enable_event_buffer(struct smi_info *smi_info) |
| 2626 | { |
| 2627 | unsigned char msg[3]; |
| 2628 | unsigned char *resp; |
| 2629 | unsigned long resp_len; |
| 2630 | int rv = 0; |
| 2631 | |
| 2632 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); |
| 2633 | if (!resp) |
| 2634 | return -ENOMEM; |
| 2635 | |
| 2636 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
| 2637 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
| 2638 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
| 2639 | |
| 2640 | rv = wait_for_msg_done(smi_info); |
| 2641 | if (rv) { |
| 2642 | printk(KERN_WARNING |
| 2643 | "ipmi_si: Error getting response from get global," |
| 2644 | " enables command, the event buffer is not" |
| 2645 | " enabled.\n"); |
| 2646 | goto out; |
| 2647 | } |
| 2648 | |
| 2649 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, |
| 2650 | resp, IPMI_MAX_MSG_LENGTH); |
| 2651 | |
| 2652 | if (resp_len < 4 || |
| 2653 | resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || |
| 2654 | resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD || |
| 2655 | resp[2] != 0) { |
| 2656 | printk(KERN_WARNING |
| 2657 | "ipmi_si: Invalid return from get global" |
| 2658 | " enables command, cannot enable the event" |
| 2659 | " buffer.\n"); |
| 2660 | rv = -EINVAL; |
| 2661 | goto out; |
| 2662 | } |
| 2663 | |
| 2664 | if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) |
| 2665 | /* buffer is already enabled, nothing to do. */ |
| 2666 | goto out; |
| 2667 | |
| 2668 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
| 2669 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; |
| 2670 | msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF; |
| 2671 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3); |
| 2672 | |
| 2673 | rv = wait_for_msg_done(smi_info); |
| 2674 | if (rv) { |
| 2675 | printk(KERN_WARNING |
| 2676 | "ipmi_si: Error getting response from set global," |
| 2677 | " enables command, the event buffer is not" |
| 2678 | " enabled.\n"); |
| 2679 | goto out; |
| 2680 | } |
| 2681 | |
| 2682 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, |
| 2683 | resp, IPMI_MAX_MSG_LENGTH); |
| 2684 | |
| 2685 | if (resp_len < 3 || |
| 2686 | resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || |
| 2687 | resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) { |
| 2688 | printk(KERN_WARNING |
| 2689 | "ipmi_si: Invalid return from get global," |
| 2690 | "enables command, not enable the event" |
| 2691 | " buffer.\n"); |
| 2692 | rv = -EINVAL; |
| 2693 | goto out; |
| 2694 | } |
| 2695 | |
| 2696 | if (resp[2] != 0) |
| 2697 | /* |
| 2698 | * An error when setting the event buffer bit means |
| 2699 | * that the event buffer is not supported. |
| 2700 | */ |
| 2701 | rv = -ENOENT; |
| 2702 | out: |
| 2703 | kfree(resp); |
| 2704 | return rv; |
| 2705 | } |
| 2706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | static int type_file_read_proc(char *page, char **start, off_t off, |
| 2708 | int count, int *eof, void *data) |
| 2709 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | struct smi_info *smi = data; |
| 2711 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 2712 | return sprintf(page, "%s\n", si_to_str[smi->si_type]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | static int stat_file_read_proc(char *page, char **start, off_t off, |
| 2716 | int count, int *eof, void *data) |
| 2717 | { |
| 2718 | char *out = (char *) page; |
| 2719 | struct smi_info *smi = data; |
| 2720 | |
| 2721 | out += sprintf(out, "interrupts_enabled: %d\n", |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2722 | smi->irq && !smi->interrupt_disabled); |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 2723 | out += sprintf(out, "short_timeouts: %u\n", |
| 2724 | smi_get_stat(smi, short_timeouts)); |
| 2725 | out += sprintf(out, "long_timeouts: %u\n", |
| 2726 | smi_get_stat(smi, long_timeouts)); |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 2727 | out += sprintf(out, "idles: %u\n", |
| 2728 | smi_get_stat(smi, idles)); |
| 2729 | out += sprintf(out, "interrupts: %u\n", |
| 2730 | smi_get_stat(smi, interrupts)); |
| 2731 | out += sprintf(out, "attentions: %u\n", |
| 2732 | smi_get_stat(smi, attentions)); |
| 2733 | out += sprintf(out, "flag_fetches: %u\n", |
| 2734 | smi_get_stat(smi, flag_fetches)); |
| 2735 | out += sprintf(out, "hosed_count: %u\n", |
| 2736 | smi_get_stat(smi, hosed_count)); |
| 2737 | out += sprintf(out, "complete_transactions: %u\n", |
| 2738 | smi_get_stat(smi, complete_transactions)); |
| 2739 | out += sprintf(out, "events: %u\n", |
| 2740 | smi_get_stat(smi, events)); |
| 2741 | out += sprintf(out, "watchdog_pretimeouts: %u\n", |
| 2742 | smi_get_stat(smi, watchdog_pretimeouts)); |
| 2743 | out += sprintf(out, "incoming_messages: %u\n", |
| 2744 | smi_get_stat(smi, incoming_messages)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 2746 | return out - page; |
| 2747 | } |
| 2748 | |
| 2749 | static int param_read_proc(char *page, char **start, off_t off, |
| 2750 | int count, int *eof, void *data) |
| 2751 | { |
| 2752 | struct smi_info *smi = data; |
| 2753 | |
| 2754 | return sprintf(page, |
| 2755 | "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n", |
| 2756 | si_to_str[smi->si_type], |
| 2757 | addr_space_to_str[smi->io.addr_type], |
| 2758 | smi->io.addr_data, |
| 2759 | smi->io.regspacing, |
| 2760 | smi->io.regsize, |
| 2761 | smi->io.regshift, |
| 2762 | smi->irq, |
| 2763 | smi->slave_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2764 | } |
| 2765 | |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 2766 | /* |
| 2767 | * oem_data_avail_to_receive_msg_avail |
| 2768 | * @info - smi_info structure with msg_flags set |
| 2769 | * |
| 2770 | * Converts flags from OEM_DATA_AVAIL to RECEIVE_MSG_AVAIL |
| 2771 | * Returns 1 indicating need to re-run handle_flags(). |
| 2772 | */ |
| 2773 | static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info) |
| 2774 | { |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 2775 | smi_info->msg_flags = ((smi_info->msg_flags & ~OEM_DATA_AVAIL) | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2776 | RECEIVE_MSG_AVAIL); |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 2777 | return 1; |
| 2778 | } |
| 2779 | |
| 2780 | /* |
| 2781 | * setup_dell_poweredge_oem_data_handler |
| 2782 | * @info - smi_info.device_id must be populated |
| 2783 | * |
| 2784 | * Systems that match, but have firmware version < 1.40 may assert |
| 2785 | * OEM0_DATA_AVAIL on their own, without being told via Set Flags that |
| 2786 | * it's safe to do so. Such systems will de-assert OEM1_DATA_AVAIL |
| 2787 | * upon receipt of IPMI_GET_MSG_CMD, so we should treat these flags |
| 2788 | * as RECEIVE_MSG_AVAIL instead. |
| 2789 | * |
| 2790 | * As Dell has no plans to release IPMI 1.5 firmware that *ever* |
| 2791 | * assert the OEM[012] bits, and if it did, the driver would have to |
| 2792 | * change to handle that properly, we don't actually check for the |
| 2793 | * firmware version. |
| 2794 | * Device ID = 0x20 BMC on PowerEdge 8G servers |
| 2795 | * Device Revision = 0x80 |
| 2796 | * Firmware Revision1 = 0x01 BMC version 1.40 |
| 2797 | * Firmware Revision2 = 0x40 BCD encoded |
| 2798 | * IPMI Version = 0x51 IPMI 1.5 |
| 2799 | * Manufacturer ID = A2 02 00 Dell IANA |
| 2800 | * |
Corey Minyard | d5a2b89 | 2005-11-07 00:59:58 -0800 | [diff] [blame] | 2801 | * Additionally, PowerEdge systems with IPMI < 1.5 may also assert |
| 2802 | * OEM0_DATA_AVAIL and needs to be treated as RECEIVE_MSG_AVAIL. |
| 2803 | * |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 2804 | */ |
| 2805 | #define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20 |
| 2806 | #define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80 |
| 2807 | #define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51 |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2808 | #define DELL_IANA_MFR_ID 0x0002a2 |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 2809 | static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info) |
| 2810 | { |
| 2811 | struct ipmi_device_id *id = &smi_info->device_id; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2812 | if (id->manufacturer_id == DELL_IANA_MFR_ID) { |
Corey Minyard | d5a2b89 | 2005-11-07 00:59:58 -0800 | [diff] [blame] | 2813 | if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID && |
| 2814 | id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV && |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2815 | id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) { |
Corey Minyard | d5a2b89 | 2005-11-07 00:59:58 -0800 | [diff] [blame] | 2816 | smi_info->oem_data_avail_handler = |
| 2817 | oem_data_avail_to_receive_msg_avail; |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2818 | } else if (ipmi_version_major(id) < 1 || |
| 2819 | (ipmi_version_major(id) == 1 && |
| 2820 | ipmi_version_minor(id) < 5)) { |
Corey Minyard | d5a2b89 | 2005-11-07 00:59:58 -0800 | [diff] [blame] | 2821 | smi_info->oem_data_avail_handler = |
| 2822 | oem_data_avail_to_receive_msg_avail; |
| 2823 | } |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 2824 | } |
| 2825 | } |
| 2826 | |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 2827 | #define CANNOT_RETURN_REQUESTED_LENGTH 0xCA |
| 2828 | static void return_hosed_msg_badsize(struct smi_info *smi_info) |
| 2829 | { |
| 2830 | struct ipmi_smi_msg *msg = smi_info->curr_msg; |
| 2831 | |
| 2832 | /* Make it a reponse */ |
| 2833 | msg->rsp[0] = msg->data[0] | 4; |
| 2834 | msg->rsp[1] = msg->data[1]; |
| 2835 | msg->rsp[2] = CANNOT_RETURN_REQUESTED_LENGTH; |
| 2836 | msg->rsp_size = 3; |
| 2837 | smi_info->curr_msg = NULL; |
| 2838 | deliver_recv_msg(smi_info, msg); |
| 2839 | } |
| 2840 | |
| 2841 | /* |
| 2842 | * dell_poweredge_bt_xaction_handler |
| 2843 | * @info - smi_info.device_id must be populated |
| 2844 | * |
| 2845 | * Dell PowerEdge servers with the BT interface (x6xx and 1750) will |
| 2846 | * not respond to a Get SDR command if the length of the data |
| 2847 | * requested is exactly 0x3A, which leads to command timeouts and no |
| 2848 | * data returned. This intercepts such commands, and causes userspace |
| 2849 | * callers to try again with a different-sized buffer, which succeeds. |
| 2850 | */ |
| 2851 | |
| 2852 | #define STORAGE_NETFN 0x0A |
| 2853 | #define STORAGE_CMD_GET_SDR 0x23 |
| 2854 | static int dell_poweredge_bt_xaction_handler(struct notifier_block *self, |
| 2855 | unsigned long unused, |
| 2856 | void *in) |
| 2857 | { |
| 2858 | struct smi_info *smi_info = in; |
| 2859 | unsigned char *data = smi_info->curr_msg->data; |
| 2860 | unsigned int size = smi_info->curr_msg->data_size; |
| 2861 | if (size >= 8 && |
| 2862 | (data[0]>>2) == STORAGE_NETFN && |
| 2863 | data[1] == STORAGE_CMD_GET_SDR && |
| 2864 | data[7] == 0x3A) { |
| 2865 | return_hosed_msg_badsize(smi_info); |
| 2866 | return NOTIFY_STOP; |
| 2867 | } |
| 2868 | return NOTIFY_DONE; |
| 2869 | } |
| 2870 | |
| 2871 | static struct notifier_block dell_poweredge_bt_xaction_notifier = { |
| 2872 | .notifier_call = dell_poweredge_bt_xaction_handler, |
| 2873 | }; |
| 2874 | |
| 2875 | /* |
| 2876 | * setup_dell_poweredge_bt_xaction_handler |
| 2877 | * @info - smi_info.device_id must be filled in already |
| 2878 | * |
| 2879 | * Fills in smi_info.device_id.start_transaction_pre_hook |
| 2880 | * when we know what function to use there. |
| 2881 | */ |
| 2882 | static void |
| 2883 | setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info) |
| 2884 | { |
| 2885 | struct ipmi_device_id *id = &smi_info->device_id; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2886 | if (id->manufacturer_id == DELL_IANA_MFR_ID && |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 2887 | smi_info->si_type == SI_BT) |
| 2888 | register_xaction_notifier(&dell_poweredge_bt_xaction_notifier); |
| 2889 | } |
| 2890 | |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 2891 | /* |
| 2892 | * setup_oem_data_handler |
| 2893 | * @info - smi_info.device_id must be filled in already |
| 2894 | * |
| 2895 | * Fills in smi_info.device_id.oem_data_available_handler |
| 2896 | * when we know what function to use there. |
| 2897 | */ |
| 2898 | |
| 2899 | static void setup_oem_data_handler(struct smi_info *smi_info) |
| 2900 | { |
| 2901 | setup_dell_poweredge_oem_data_handler(smi_info); |
| 2902 | } |
| 2903 | |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 2904 | static void setup_xaction_handlers(struct smi_info *smi_info) |
| 2905 | { |
| 2906 | setup_dell_poweredge_bt_xaction_handler(smi_info); |
| 2907 | } |
| 2908 | |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 2909 | static inline void wait_for_timer_and_thread(struct smi_info *smi_info) |
| 2910 | { |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 2911 | if (smi_info->intf) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 2912 | /* |
| 2913 | * The timer and thread are only running if the |
| 2914 | * interface has been started up and registered. |
| 2915 | */ |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 2916 | if (smi_info->thread != NULL) |
| 2917 | kthread_stop(smi_info->thread); |
| 2918 | del_timer_sync(&smi_info->si_timer); |
| 2919 | } |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 2920 | } |
| 2921 | |
Randy Dunlap | 7420884 | 2006-04-18 22:21:52 -0700 | [diff] [blame] | 2922 | static __devinitdata struct ipmi_default_vals |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2924 | int type; |
| 2925 | int port; |
Randy Dunlap | 7420884 | 2006-04-18 22:21:52 -0700 | [diff] [blame] | 2926 | } ipmi_defaults[] = |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2927 | { |
| 2928 | { .type = SI_KCS, .port = 0xca2 }, |
| 2929 | { .type = SI_SMIC, .port = 0xca9 }, |
| 2930 | { .type = SI_BT, .port = 0xe4 }, |
| 2931 | { .port = 0 } |
| 2932 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2934 | static __devinit void default_find_bmc(void) |
| 2935 | { |
| 2936 | struct smi_info *info; |
| 2937 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2938 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2939 | for (i = 0; ; i++) { |
| 2940 | if (!ipmi_defaults[i].port) |
| 2941 | break; |
Kumar Gala | 68e1ee6 | 2008-09-22 14:41:31 -0700 | [diff] [blame] | 2942 | #ifdef CONFIG_PPC |
Christian Krafft | 4ff31d7 | 2007-03-05 00:30:48 -0800 | [diff] [blame] | 2943 | if (check_legacy_ioport(ipmi_defaults[i].port)) |
| 2944 | continue; |
| 2945 | #endif |
Andrew Morton | a09f485 | 2008-08-20 14:09:14 -0700 | [diff] [blame] | 2946 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
| 2947 | if (!info) |
| 2948 | return; |
Christian Krafft | 4ff31d7 | 2007-03-05 00:30:48 -0800 | [diff] [blame] | 2949 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2950 | info->addr_source = NULL; |
| 2951 | |
| 2952 | info->si_type = ipmi_defaults[i].type; |
| 2953 | info->io_setup = port_setup; |
| 2954 | info->io.addr_data = ipmi_defaults[i].port; |
| 2955 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
| 2956 | |
| 2957 | info->io.addr = NULL; |
| 2958 | info->io.regspacing = DEFAULT_REGSPACING; |
| 2959 | info->io.regsize = DEFAULT_REGSPACING; |
| 2960 | info->io.regshift = 0; |
| 2961 | |
| 2962 | if (try_smi_init(info) == 0) { |
| 2963 | /* Found one... */ |
| 2964 | printk(KERN_INFO "ipmi_si: Found default %s state" |
| 2965 | " machine at %s address 0x%lx\n", |
| 2966 | si_to_str[info->si_type], |
| 2967 | addr_space_to_str[info->io.addr_type], |
| 2968 | info->io.addr_data); |
| 2969 | return; |
| 2970 | } |
| 2971 | } |
| 2972 | } |
| 2973 | |
| 2974 | static int is_new_interface(struct smi_info *info) |
| 2975 | { |
| 2976 | struct smi_info *e; |
| 2977 | |
| 2978 | list_for_each_entry(e, &smi_infos, link) { |
| 2979 | if (e->io.addr_type != info->io.addr_type) |
| 2980 | continue; |
| 2981 | if (e->io.addr_data == info->io.addr_data) |
| 2982 | return 0; |
| 2983 | } |
| 2984 | |
| 2985 | return 1; |
| 2986 | } |
| 2987 | |
| 2988 | static int try_smi_init(struct smi_info *new_smi) |
| 2989 | { |
| 2990 | int rv; |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 2991 | int i; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 2992 | |
| 2993 | if (new_smi->addr_source) { |
| 2994 | printk(KERN_INFO "ipmi_si: Trying %s-specified %s state" |
| 2995 | " machine at %s address 0x%lx, slave address 0x%x," |
| 2996 | " irq %d\n", |
| 2997 | new_smi->addr_source, |
| 2998 | si_to_str[new_smi->si_type], |
| 2999 | addr_space_to_str[new_smi->io.addr_type], |
| 3000 | new_smi->io.addr_data, |
| 3001 | new_smi->slave_addr, new_smi->irq); |
| 3002 | } |
| 3003 | |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3004 | mutex_lock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3005 | if (!is_new_interface(new_smi)) { |
| 3006 | printk(KERN_WARNING "ipmi_si: duplicate interface\n"); |
| 3007 | rv = -EBUSY; |
| 3008 | goto out_err; |
| 3009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | |
| 3011 | /* So we know not to free it unless we have allocated one. */ |
| 3012 | new_smi->intf = NULL; |
| 3013 | new_smi->si_sm = NULL; |
| 3014 | new_smi->handlers = NULL; |
| 3015 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3016 | switch (new_smi->si_type) { |
| 3017 | case SI_KCS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | new_smi->handlers = &kcs_smi_handlers; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3019 | break; |
| 3020 | |
| 3021 | case SI_SMIC: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | new_smi->handlers = &smic_smi_handlers; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3023 | break; |
| 3024 | |
| 3025 | case SI_BT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | new_smi->handlers = &bt_smi_handlers; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3027 | break; |
| 3028 | |
| 3029 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | /* No support for anything else yet. */ |
| 3031 | rv = -EIO; |
| 3032 | goto out_err; |
| 3033 | } |
| 3034 | |
| 3035 | /* Allocate the state machine's data and initialize it. */ |
| 3036 | new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3037 | if (!new_smi->si_sm) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3038 | printk(KERN_ERR "Could not allocate state machine memory\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3039 | rv = -ENOMEM; |
| 3040 | goto out_err; |
| 3041 | } |
| 3042 | new_smi->io_size = new_smi->handlers->init_data(new_smi->si_sm, |
| 3043 | &new_smi->io); |
| 3044 | |
| 3045 | /* Now that we know the I/O size, we can set up the I/O. */ |
| 3046 | rv = new_smi->io_setup(new_smi); |
| 3047 | if (rv) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3048 | printk(KERN_ERR "Could not set up I/O space\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | goto out_err; |
| 3050 | } |
| 3051 | |
| 3052 | spin_lock_init(&(new_smi->si_lock)); |
| 3053 | spin_lock_init(&(new_smi->msg_lock)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3054 | |
| 3055 | /* Do low-level detection first. */ |
| 3056 | if (new_smi->handlers->detect(new_smi->si_sm)) { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3057 | if (new_smi->addr_source) |
| 3058 | printk(KERN_INFO "ipmi_si: Interface detection" |
| 3059 | " failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3060 | rv = -ENODEV; |
| 3061 | goto out_err; |
| 3062 | } |
| 3063 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3064 | /* |
| 3065 | * Attempt a get device id command. If it fails, we probably |
| 3066 | * don't have a BMC here. |
| 3067 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | rv = try_get_dev_id(new_smi); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3069 | if (rv) { |
| 3070 | if (new_smi->addr_source) |
| 3071 | printk(KERN_INFO "ipmi_si: There appears to be no BMC" |
| 3072 | " at this location\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3073 | goto out_err; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3074 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 3076 | setup_oem_data_handler(new_smi); |
Corey Minyard | ea94027 | 2005-11-07 00:59:59 -0800 | [diff] [blame] | 3077 | setup_xaction_handlers(new_smi); |
Corey Minyard | 3ae0e0f | 2005-09-06 15:18:41 -0700 | [diff] [blame] | 3078 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3079 | INIT_LIST_HEAD(&(new_smi->xmit_msgs)); |
| 3080 | INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs)); |
| 3081 | new_smi->curr_msg = NULL; |
| 3082 | atomic_set(&new_smi->req_events, 0); |
| 3083 | new_smi->run_to_completion = 0; |
Corey Minyard | 64959e2 | 2008-04-29 01:01:07 -0700 | [diff] [blame] | 3084 | for (i = 0; i < SI_NUM_STATS; i++) |
| 3085 | atomic_set(&new_smi->stats[i], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3086 | |
| 3087 | new_smi->interrupt_disabled = 0; |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 3088 | atomic_set(&new_smi->stop_operation, 0); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3089 | new_smi->intf_num = smi_num; |
| 3090 | smi_num++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3091 | |
Corey Minyard | 40112ae | 2009-04-21 12:24:03 -0700 | [diff] [blame] | 3092 | rv = try_enable_event_buffer(new_smi); |
| 3093 | if (rv == 0) |
| 3094 | new_smi->has_event_buffer = 1; |
| 3095 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3096 | /* |
| 3097 | * Start clearing the flags before we enable interrupts or the |
| 3098 | * timer to avoid racing with the timer. |
| 3099 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3100 | start_clear_flags(new_smi); |
| 3101 | /* IRQ is defined to be set when non-zero. */ |
| 3102 | if (new_smi->irq) |
| 3103 | new_smi->si_state = SI_CLEARING_FLAGS_THEN_SET_IRQ; |
| 3104 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3105 | if (!new_smi->dev) { |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3106 | /* |
| 3107 | * If we don't already have a device from something |
| 3108 | * else (like PCI), then register a new one. |
| 3109 | */ |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3110 | new_smi->pdev = platform_device_alloc("ipmi_si", |
| 3111 | new_smi->intf_num); |
Corey Minyard | 8b32b5d | 2009-04-21 12:24:02 -0700 | [diff] [blame] | 3112 | if (!new_smi->pdev) { |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3113 | printk(KERN_ERR |
| 3114 | "ipmi_si_intf:" |
| 3115 | " Unable to allocate platform device\n"); |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 3116 | goto out_err; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3117 | } |
| 3118 | new_smi->dev = &new_smi->pdev->dev; |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 3119 | new_smi->dev->driver = &ipmi_driver.driver; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3120 | |
Zhang, Yanmin | b48f545 | 2006-11-16 01:19:08 -0800 | [diff] [blame] | 3121 | rv = platform_device_add(new_smi->pdev); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3122 | if (rv) { |
| 3123 | printk(KERN_ERR |
| 3124 | "ipmi_si_intf:" |
| 3125 | " Unable to register system interface device:" |
| 3126 | " %d\n", |
| 3127 | rv); |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 3128 | goto out_err; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3129 | } |
| 3130 | new_smi->dev_registered = 1; |
| 3131 | } |
| 3132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3133 | rv = ipmi_register_smi(&handlers, |
| 3134 | new_smi, |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3135 | &new_smi->device_id, |
| 3136 | new_smi->dev, |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 3137 | "bmc", |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 3138 | new_smi->slave_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3139 | if (rv) { |
| 3140 | printk(KERN_ERR |
| 3141 | "ipmi_si: Unable to register device: error %d\n", |
| 3142 | rv); |
| 3143 | goto out_err_stop_timer; |
| 3144 | } |
| 3145 | |
| 3146 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "type", |
Alexey Dobriyan | fa68be0 | 2008-04-29 01:01:13 -0700 | [diff] [blame] | 3147 | type_file_read_proc, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 3148 | new_smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3149 | if (rv) { |
| 3150 | printk(KERN_ERR |
| 3151 | "ipmi_si: Unable to create proc entry: %d\n", |
| 3152 | rv); |
| 3153 | goto out_err_stop_timer; |
| 3154 | } |
| 3155 | |
| 3156 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "si_stats", |
Alexey Dobriyan | fa68be0 | 2008-04-29 01:01:13 -0700 | [diff] [blame] | 3157 | stat_file_read_proc, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 3158 | new_smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | if (rv) { |
| 3160 | printk(KERN_ERR |
| 3161 | "ipmi_si: Unable to create proc entry: %d\n", |
| 3162 | rv); |
| 3163 | goto out_err_stop_timer; |
| 3164 | } |
| 3165 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 3166 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "params", |
Alexey Dobriyan | fa68be0 | 2008-04-29 01:01:13 -0700 | [diff] [blame] | 3167 | param_read_proc, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 3168 | new_smi); |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 3169 | if (rv) { |
| 3170 | printk(KERN_ERR |
| 3171 | "ipmi_si: Unable to create proc entry: %d\n", |
| 3172 | rv); |
| 3173 | goto out_err_stop_timer; |
| 3174 | } |
| 3175 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3176 | list_add_tail(&new_smi->link, &smi_infos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3178 | mutex_unlock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3179 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3180 | printk(KERN_INFO "IPMI %s interface initialized\n", |
| 3181 | si_to_str[new_smi->si_type]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | |
| 3183 | return 0; |
| 3184 | |
| 3185 | out_err_stop_timer: |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 3186 | atomic_inc(&new_smi->stop_operation); |
| 3187 | wait_for_timer_and_thread(new_smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | |
| 3189 | out_err: |
| 3190 | if (new_smi->intf) |
| 3191 | ipmi_unregister_smi(new_smi->intf); |
| 3192 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3193 | if (new_smi->irq_cleanup) |
| 3194 | new_smi->irq_cleanup(new_smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3196 | /* |
| 3197 | * Wait until we know that we are out of any interrupt |
| 3198 | * handlers might have been running before we freed the |
| 3199 | * interrupt. |
| 3200 | */ |
Paul E. McKenney | fbd568a3e | 2005-05-01 08:59:04 -0700 | [diff] [blame] | 3201 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3202 | |
| 3203 | if (new_smi->si_sm) { |
| 3204 | if (new_smi->handlers) |
| 3205 | new_smi->handlers->cleanup(new_smi->si_sm); |
| 3206 | kfree(new_smi->si_sm); |
| 3207 | } |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3208 | if (new_smi->addr_source_cleanup) |
| 3209 | new_smi->addr_source_cleanup(new_smi); |
Paolo Galtieri | 7767e12 | 2005-12-15 12:34:28 -0800 | [diff] [blame] | 3210 | if (new_smi->io_cleanup) |
| 3211 | new_smi->io_cleanup(new_smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3212 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3213 | if (new_smi->dev_registered) |
| 3214 | platform_device_unregister(new_smi->pdev); |
| 3215 | |
| 3216 | kfree(new_smi); |
| 3217 | |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3218 | mutex_unlock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3220 | return rv; |
| 3221 | } |
| 3222 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3223 | static __devinit int init_ipmi_si(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | int i; |
| 3226 | char *str; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3227 | int rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3228 | |
| 3229 | if (initialized) |
| 3230 | return 0; |
| 3231 | initialized = 1; |
| 3232 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3233 | /* Register the device drivers. */ |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 3234 | rv = driver_register(&ipmi_driver.driver); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3235 | if (rv) { |
| 3236 | printk(KERN_ERR |
| 3237 | "init_ipmi_si: Unable to register driver: %d\n", |
| 3238 | rv); |
| 3239 | return rv; |
| 3240 | } |
| 3241 | |
| 3242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3243 | /* Parse out the si_type string into its components. */ |
| 3244 | str = si_type_str; |
| 3245 | if (*str != '\0') { |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 3246 | for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | si_type[i] = str; |
| 3248 | str = strchr(str, ','); |
| 3249 | if (str) { |
| 3250 | *str = '\0'; |
| 3251 | str++; |
| 3252 | } else { |
| 3253 | break; |
| 3254 | } |
| 3255 | } |
| 3256 | } |
| 3257 | |
Corey Minyard | 1fdd75b | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 3258 | printk(KERN_INFO "IPMI System Interface driver.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3260 | hardcode_find_bmc(); |
| 3261 | |
Matt Domsch | a9fad4c | 2006-01-11 12:17:44 -0800 | [diff] [blame] | 3262 | #ifdef CONFIG_DMI |
Andrey Panin | b224cd3 | 2005-09-06 15:18:37 -0700 | [diff] [blame] | 3263 | dmi_find_bmc(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3264 | #endif |
| 3265 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3266 | #ifdef CONFIG_ACPI |
Bjorn Helgaas | 18a3e0b | 2009-11-17 17:05:29 -0700 | [diff] [blame] | 3267 | spmi_find_bmc(); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3268 | #endif |
Ingo Molnar | 27d0567 | 2009-12-17 08:50:25 +0100 | [diff] [blame] | 3269 | #ifdef CONFIG_ACPI |
Bjorn Helgaas | 9e368fa | 2009-11-17 17:05:34 -0700 | [diff] [blame] | 3270 | pnp_register_driver(&ipmi_pnp_driver); |
| 3271 | #endif |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3272 | |
| 3273 | #ifdef CONFIG_PCI |
Corey Minyard | 168b35a | 2006-12-06 20:41:11 -0800 | [diff] [blame] | 3274 | rv = pci_register_driver(&ipmi_pci_driver); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3275 | if (rv) |
Corey Minyard | 168b35a | 2006-12-06 20:41:11 -0800 | [diff] [blame] | 3276 | printk(KERN_ERR |
| 3277 | "init_ipmi_si: Unable to register PCI driver: %d\n", |
| 3278 | rv); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3279 | #endif |
| 3280 | |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 3281 | #ifdef CONFIG_PPC_OF |
| 3282 | of_register_platform_driver(&ipmi_of_platform_driver); |
| 3283 | #endif |
| 3284 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3285 | if (si_trydefaults) { |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3286 | mutex_lock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3287 | if (list_empty(&smi_infos)) { |
| 3288 | /* No BMC was found, try defaults. */ |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3289 | mutex_unlock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3290 | default_find_bmc(); |
| 3291 | } else { |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3292 | mutex_unlock(&smi_infos_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | } |
| 3294 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3295 | |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3296 | mutex_lock(&smi_infos_lock); |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 3297 | if (unload_when_empty && list_empty(&smi_infos)) { |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3298 | mutex_unlock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3299 | #ifdef CONFIG_PCI |
| 3300 | pci_unregister_driver(&ipmi_pci_driver); |
| 3301 | #endif |
Christian Krafft | 10fb62e | 2007-05-12 10:37:01 -0700 | [diff] [blame] | 3302 | |
| 3303 | #ifdef CONFIG_PPC_OF |
| 3304 | of_unregister_platform_driver(&ipmi_of_platform_driver); |
| 3305 | #endif |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 3306 | driver_unregister(&ipmi_driver.driver); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3307 | printk(KERN_WARNING |
| 3308 | "ipmi_si: Unable to find any System Interface(s)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | return -ENODEV; |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3310 | } else { |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3311 | mutex_unlock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3312 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3314 | } |
| 3315 | module_init(init_ipmi_si); |
| 3316 | |
Corey Minyard | b361e27 | 2006-12-06 20:41:07 -0800 | [diff] [blame] | 3317 | static void cleanup_one_si(struct smi_info *to_clean) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | { |
| 3319 | int rv; |
| 3320 | unsigned long flags; |
| 3321 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3322 | if (!to_clean) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | return; |
| 3324 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3325 | list_del(&to_clean->link); |
| 3326 | |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 3327 | /* Tell the driver that we are shutting down. */ |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 3328 | atomic_inc(&to_clean->stop_operation); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3329 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3330 | /* |
| 3331 | * Make sure the timer and thread are stopped and will not run |
| 3332 | * again. |
| 3333 | */ |
Corey Minyard | a9a2c44 | 2005-11-07 01:00:03 -0800 | [diff] [blame] | 3334 | wait_for_timer_and_thread(to_clean); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3336 | /* |
| 3337 | * Timeouts are stopped, now make sure the interrupts are off |
| 3338 | * for the device. A little tricky with locks to make sure |
| 3339 | * there are no races. |
| 3340 | */ |
Corey Minyard | ee6cd5f | 2007-05-08 00:23:54 -0700 | [diff] [blame] | 3341 | spin_lock_irqsave(&to_clean->si_lock, flags); |
| 3342 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { |
| 3343 | spin_unlock_irqrestore(&to_clean->si_lock, flags); |
| 3344 | poll(to_clean); |
| 3345 | schedule_timeout_uninterruptible(1); |
| 3346 | spin_lock_irqsave(&to_clean->si_lock, flags); |
| 3347 | } |
| 3348 | disable_si_irq(to_clean); |
| 3349 | spin_unlock_irqrestore(&to_clean->si_lock, flags); |
| 3350 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { |
| 3351 | poll(to_clean); |
| 3352 | schedule_timeout_uninterruptible(1); |
| 3353 | } |
| 3354 | |
| 3355 | /* Clean up interrupts and make sure that everything is done. */ |
| 3356 | if (to_clean->irq_cleanup) |
| 3357 | to_clean->irq_cleanup(to_clean); |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 3358 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | poll(to_clean); |
Nishanth Aravamudan | da4cd8d | 2005-09-10 00:27:30 -0700 | [diff] [blame] | 3360 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | rv = ipmi_unregister_smi(to_clean->intf); |
| 3364 | if (rv) { |
| 3365 | printk(KERN_ERR |
| 3366 | "ipmi_si: Unable to unregister device: errno=%d\n", |
| 3367 | rv); |
| 3368 | } |
| 3369 | |
| 3370 | to_clean->handlers->cleanup(to_clean->si_sm); |
| 3371 | |
| 3372 | kfree(to_clean->si_sm); |
| 3373 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3374 | if (to_clean->addr_source_cleanup) |
| 3375 | to_clean->addr_source_cleanup(to_clean); |
Paolo Galtieri | 7767e12 | 2005-12-15 12:34:28 -0800 | [diff] [blame] | 3376 | if (to_clean->io_cleanup) |
| 3377 | to_clean->io_cleanup(to_clean); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3378 | |
| 3379 | if (to_clean->dev_registered) |
| 3380 | platform_device_unregister(to_clean->pdev); |
| 3381 | |
| 3382 | kfree(to_clean); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | static __exit void cleanup_ipmi_si(void) |
| 3386 | { |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3387 | struct smi_info *e, *tmp_e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3389 | if (!initialized) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3390 | return; |
| 3391 | |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3392 | #ifdef CONFIG_PCI |
| 3393 | pci_unregister_driver(&ipmi_pci_driver); |
| 3394 | #endif |
Ingo Molnar | 27d0567 | 2009-12-17 08:50:25 +0100 | [diff] [blame] | 3395 | #ifdef CONFIG_ACPI |
Bjorn Helgaas | 9e368fa | 2009-11-17 17:05:34 -0700 | [diff] [blame] | 3396 | pnp_unregister_driver(&ipmi_pnp_driver); |
| 3397 | #endif |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3398 | |
Corey Minyard | dba9b4f | 2007-05-08 00:23:51 -0700 | [diff] [blame] | 3399 | #ifdef CONFIG_PPC_OF |
| 3400 | of_unregister_platform_driver(&ipmi_of_platform_driver); |
| 3401 | #endif |
| 3402 | |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3403 | mutex_lock(&smi_infos_lock); |
Corey Minyard | b0defcd | 2006-03-26 01:37:20 -0800 | [diff] [blame] | 3404 | list_for_each_entry_safe(e, tmp_e, &smi_infos, link) |
| 3405 | cleanup_one_si(e); |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 3406 | mutex_unlock(&smi_infos_lock); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 3407 | |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 3408 | driver_unregister(&ipmi_driver.driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3409 | } |
| 3410 | module_exit(cleanup_ipmi_si); |
| 3411 | |
| 3412 | MODULE_LICENSE("GPL"); |
Corey Minyard | 1fdd75b | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 3413 | MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>"); |
Corey Minyard | c305e3d | 2008-04-29 01:01:10 -0700 | [diff] [blame] | 3414 | MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT" |
| 3415 | " system interfaces."); |