Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ipmi_msghandler.c |
| 3 | * |
| 4 | * Incoming and outgoing message routing for an IPMI interface. |
| 5 | * |
| 6 | * Author: MontaVista Software, Inc. |
| 7 | * Corey Minyard <minyard@mvista.com> |
| 8 | * source@mvista.com |
| 9 | * |
| 10 | * Copyright 2002 MontaVista Software Inc. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License as published by the |
| 14 | * Free Software Foundation; either version 2 of the License, or (at your |
| 15 | * option) any later version. |
| 16 | * |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
| 26 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
| 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License along |
| 30 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 31 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 32 | */ |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/module.h> |
| 35 | #include <linux/errno.h> |
| 36 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/poll.h> |
Alexey Dobriyan | a99bbaf | 2009-10-04 16:11:37 +0400 | [diff] [blame] | 38 | #include <linux/sched.h> |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 39 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <linux/spinlock.h> |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 41 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/slab.h> |
| 43 | #include <linux/ipmi.h> |
| 44 | #include <linux/ipmi_smi.h> |
| 45 | #include <linux/notifier.h> |
| 46 | #include <linux/init.h> |
| 47 | #include <linux/proc_fs.h> |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 48 | #include <linux/rcupdate.h> |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 49 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #define PFX "IPMI message handler: " |
Corey Minyard | 1fdd75b | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 52 | |
Corey Minyard | f7caa1b | 2008-04-29 01:01:04 -0700 | [diff] [blame] | 53 | #define IPMI_DRIVER_VERSION "39.2" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); |
| 56 | static int ipmi_init_msghandler(void); |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 57 | static void smi_recv_tasklet(unsigned long); |
| 58 | static void handle_new_recv_msgs(ipmi_smi_t intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Randy Dunlap | 0c8204b | 2006-12-10 02:19:06 -0800 | [diff] [blame] | 60 | static int initialized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 62 | #ifdef CONFIG_PROC_FS |
Randy Dunlap | 0c8204b | 2006-12-10 02:19:06 -0800 | [diff] [blame] | 63 | static struct proc_dir_entry *proc_ipmi_root; |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 64 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 66 | /* Remain in auto-maintenance mode for this amount of time (in ms). */ |
| 67 | #define IPMI_MAINTENANCE_MODE_TIMEOUT 30000 |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | #define MAX_EVENTS_IN_QUEUE 25 |
| 70 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 71 | /* |
| 72 | * Don't let a message sit in a queue forever, always time it with at lest |
| 73 | * the max message timer. This is in milliseconds. |
| 74 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define MAX_MSG_TIMEOUT 60000 |
| 76 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 77 | /* |
| 78 | * The main "user" data structure. |
| 79 | */ |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 80 | struct ipmi_user { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | struct list_head link; |
| 82 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 83 | /* Set to "0" when the user is destroyed. */ |
| 84 | int valid; |
| 85 | |
| 86 | struct kref refcount; |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* The upper layer that handles receive messages. */ |
| 89 | struct ipmi_user_hndl *handler; |
| 90 | void *handler_data; |
| 91 | |
| 92 | /* The interface this user is bound to. */ |
| 93 | ipmi_smi_t intf; |
| 94 | |
| 95 | /* Does this interface receive IPMI events? */ |
| 96 | int gets_events; |
| 97 | }; |
| 98 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 99 | struct cmd_rcvr { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | struct list_head link; |
| 101 | |
| 102 | ipmi_user_t user; |
| 103 | unsigned char netfn; |
| 104 | unsigned char cmd; |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 105 | unsigned int chans; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * This is used to form a linked lised during mass deletion. |
| 109 | * Since this is in an RCU list, we cannot use the link above |
| 110 | * or change any data until the RCU period completes. So we |
| 111 | * use this next variable during mass deletion so we can have |
| 112 | * a list and don't have to wait and restart the search on |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 113 | * every individual deletion of a command. |
| 114 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 115 | struct cmd_rcvr *next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | }; |
| 117 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 118 | struct seq_table { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | unsigned int inuse : 1; |
| 120 | unsigned int broadcast : 1; |
| 121 | |
| 122 | unsigned long timeout; |
| 123 | unsigned long orig_timeout; |
| 124 | unsigned int retries_left; |
| 125 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 126 | /* |
| 127 | * To verify on an incoming send message response that this is |
| 128 | * the message that the response is for, we keep a sequence id |
| 129 | * and increment it every time we send a message. |
| 130 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | long seqid; |
| 132 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 133 | /* |
| 134 | * This is held so we can properly respond to the message on a |
| 135 | * timeout, and it is used to hold the temporary data for |
| 136 | * retransmission, too. |
| 137 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | struct ipmi_recv_msg *recv_msg; |
| 139 | }; |
| 140 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 141 | /* |
| 142 | * Store the information in a msgid (long) to allow us to find a |
| 143 | * sequence table entry from the msgid. |
| 144 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | #define STORE_SEQ_IN_MSGID(seq, seqid) (((seq&0xff)<<26) | (seqid&0x3ffffff)) |
| 146 | |
| 147 | #define GET_SEQ_FROM_MSGID(msgid, seq, seqid) \ |
| 148 | do { \ |
| 149 | seq = ((msgid >> 26) & 0x3f); \ |
| 150 | seqid = (msgid & 0x3fffff); \ |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 151 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
| 153 | #define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff) |
| 154 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 155 | struct ipmi_channel { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | unsigned char medium; |
| 157 | unsigned char protocol; |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 158 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 159 | /* |
| 160 | * My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR, |
| 161 | * but may be changed by the user. |
| 162 | */ |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 163 | unsigned char address; |
| 164 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 165 | /* |
| 166 | * My LUN. This should generally stay the SMS LUN, but just in |
| 167 | * case... |
| 168 | */ |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 169 | unsigned char lun; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | }; |
| 171 | |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 172 | #ifdef CONFIG_PROC_FS |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 173 | struct ipmi_proc_entry { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | char *name; |
| 175 | struct ipmi_proc_entry *next; |
| 176 | }; |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 177 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 179 | struct bmc_device { |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 180 | struct platform_device *dev; |
| 181 | struct ipmi_device_id id; |
| 182 | unsigned char guid[16]; |
| 183 | int guid_set; |
| 184 | |
| 185 | struct kref refcount; |
| 186 | |
| 187 | /* bmc device attributes */ |
| 188 | struct device_attribute device_id_attr; |
| 189 | struct device_attribute provides_dev_sdrs_attr; |
| 190 | struct device_attribute revision_attr; |
| 191 | struct device_attribute firmware_rev_attr; |
| 192 | struct device_attribute version_attr; |
| 193 | struct device_attribute add_dev_support_attr; |
| 194 | struct device_attribute manufacturer_id_attr; |
| 195 | struct device_attribute product_id_attr; |
| 196 | struct device_attribute guid_attr; |
| 197 | struct device_attribute aux_firmware_rev_attr; |
| 198 | }; |
| 199 | |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 200 | /* |
| 201 | * Various statistics for IPMI, these index stats[] in the ipmi_smi |
| 202 | * structure. |
| 203 | */ |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 204 | enum ipmi_stat_indexes { |
| 205 | /* Commands we got from the user that were invalid. */ |
| 206 | IPMI_STAT_sent_invalid_commands = 0, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 207 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 208 | /* Commands we sent to the MC. */ |
| 209 | IPMI_STAT_sent_local_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 210 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 211 | /* Responses from the MC that were delivered to a user. */ |
| 212 | IPMI_STAT_handled_local_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 213 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 214 | /* Responses from the MC that were not delivered to a user. */ |
| 215 | IPMI_STAT_unhandled_local_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 216 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 217 | /* Commands we sent out to the IPMB bus. */ |
| 218 | IPMI_STAT_sent_ipmb_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 219 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 220 | /* Commands sent on the IPMB that had errors on the SEND CMD */ |
| 221 | IPMI_STAT_sent_ipmb_command_errs, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 222 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 223 | /* Each retransmit increments this count. */ |
| 224 | IPMI_STAT_retransmitted_ipmb_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 225 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 226 | /* |
| 227 | * When a message times out (runs out of retransmits) this is |
| 228 | * incremented. |
| 229 | */ |
| 230 | IPMI_STAT_timed_out_ipmb_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 231 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 232 | /* |
| 233 | * This is like above, but for broadcasts. Broadcasts are |
| 234 | * *not* included in the above count (they are expected to |
| 235 | * time out). |
| 236 | */ |
| 237 | IPMI_STAT_timed_out_ipmb_broadcasts, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 238 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 239 | /* Responses I have sent to the IPMB bus. */ |
| 240 | IPMI_STAT_sent_ipmb_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 241 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 242 | /* The response was delivered to the user. */ |
| 243 | IPMI_STAT_handled_ipmb_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 244 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 245 | /* The response had invalid data in it. */ |
| 246 | IPMI_STAT_invalid_ipmb_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 247 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 248 | /* The response didn't have anyone waiting for it. */ |
| 249 | IPMI_STAT_unhandled_ipmb_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 250 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 251 | /* Commands we sent out to the IPMB bus. */ |
| 252 | IPMI_STAT_sent_lan_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 253 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 254 | /* Commands sent on the IPMB that had errors on the SEND CMD */ |
| 255 | IPMI_STAT_sent_lan_command_errs, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 256 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 257 | /* Each retransmit increments this count. */ |
| 258 | IPMI_STAT_retransmitted_lan_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 259 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 260 | /* |
| 261 | * When a message times out (runs out of retransmits) this is |
| 262 | * incremented. |
| 263 | */ |
| 264 | IPMI_STAT_timed_out_lan_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 265 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 266 | /* Responses I have sent to the IPMB bus. */ |
| 267 | IPMI_STAT_sent_lan_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 268 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 269 | /* The response was delivered to the user. */ |
| 270 | IPMI_STAT_handled_lan_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 271 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 272 | /* The response had invalid data in it. */ |
| 273 | IPMI_STAT_invalid_lan_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 274 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 275 | /* The response didn't have anyone waiting for it. */ |
| 276 | IPMI_STAT_unhandled_lan_responses, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 277 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 278 | /* The command was delivered to the user. */ |
| 279 | IPMI_STAT_handled_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 280 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 281 | /* The command had invalid data in it. */ |
| 282 | IPMI_STAT_invalid_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 283 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 284 | /* The command didn't have anyone waiting for it. */ |
| 285 | IPMI_STAT_unhandled_commands, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 286 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 287 | /* Invalid data in an event. */ |
| 288 | IPMI_STAT_invalid_events, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 289 | |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 290 | /* Events that were received with the proper format. */ |
| 291 | IPMI_STAT_events, |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 292 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 293 | /* Retransmissions on IPMB that failed. */ |
| 294 | IPMI_STAT_dropped_rexmit_ipmb_commands, |
| 295 | |
| 296 | /* Retransmissions on LAN that failed. */ |
| 297 | IPMI_STAT_dropped_rexmit_lan_commands, |
Corey Minyard | 73f2bdb | 2008-04-29 01:01:06 -0700 | [diff] [blame] | 298 | |
| 299 | /* This *must* remain last, add new values above this. */ |
| 300 | IPMI_NUM_STATS |
| 301 | }; |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 302 | |
| 303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | #define IPMI_IPMB_NUM_SEQ 64 |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 305 | #define IPMI_MAX_CHANNELS 16 |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 306 | struct ipmi_smi { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | /* What interface number are we? */ |
| 308 | int intf_num; |
| 309 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 310 | struct kref refcount; |
| 311 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 312 | /* Used for a list of interfaces. */ |
| 313 | struct list_head link; |
| 314 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 315 | /* |
| 316 | * The list of upper layers that are using me. seq_lock |
| 317 | * protects this. |
| 318 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 319 | struct list_head users; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 321 | /* Information to supply to users. */ |
| 322 | unsigned char ipmi_version_major; |
| 323 | unsigned char ipmi_version_minor; |
| 324 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | /* Used for wake ups at startup. */ |
| 326 | wait_queue_head_t waitq; |
| 327 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 328 | struct bmc_device *bmc; |
| 329 | char *my_dev_name; |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 330 | char *sysfs_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 332 | /* |
| 333 | * This is the lower-layer's sender routine. Note that you |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 334 | * must either be holding the ipmi_interfaces_mutex or be in |
| 335 | * an umpreemptible region to use this. You must fetch the |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 336 | * value into a local variable and make sure it is not NULL. |
| 337 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | struct ipmi_smi_handlers *handlers; |
| 339 | void *send_info; |
| 340 | |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 341 | #ifdef CONFIG_PROC_FS |
Corey Minyard | ac01915 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 342 | /* A list of proc entries for this interface. */ |
| 343 | struct mutex proc_entry_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | struct ipmi_proc_entry *proc_entries; |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 345 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 347 | /* Driver-model device for the system interface. */ |
| 348 | struct device *si_dev; |
| 349 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 350 | /* |
| 351 | * A table of sequence numbers for this interface. We use the |
| 352 | * sequence numbers for IPMB messages that go out of the |
| 353 | * interface to match them up with their responses. A routine |
| 354 | * is called periodically to time the items in this list. |
| 355 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | spinlock_t seq_lock; |
| 357 | struct seq_table seq_table[IPMI_IPMB_NUM_SEQ]; |
| 358 | int curr_seq; |
| 359 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 360 | /* |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 361 | * Messages queued for delivery. If delivery fails (out of memory |
| 362 | * for instance), They will stay in here to be processed later in a |
| 363 | * periodic timer interrupt. The tasklet is for handling received |
| 364 | * messages directly from the handler. |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 365 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | spinlock_t waiting_msgs_lock; |
| 367 | struct list_head waiting_msgs; |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 368 | atomic_t watchdog_pretimeouts_to_deliver; |
| 369 | struct tasklet_struct recv_tasklet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 371 | /* |
| 372 | * The list of command receivers that are registered for commands |
| 373 | * on this interface. |
| 374 | */ |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 375 | struct mutex cmd_rcvrs_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | struct list_head cmd_rcvrs; |
| 377 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 378 | /* |
| 379 | * Events that were queues because no one was there to receive |
| 380 | * them. |
| 381 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | spinlock_t events_lock; /* For dealing with event stuff. */ |
| 383 | struct list_head waiting_events; |
| 384 | unsigned int waiting_events_count; /* How many events in queue? */ |
Corey Minyard | 87ebd06 | 2008-04-29 01:01:04 -0700 | [diff] [blame] | 385 | char delivering_events; |
| 386 | char event_msg_printed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 388 | /* |
| 389 | * The event receiver for my BMC, only really used at panic |
| 390 | * shutdown as a place to store this. |
| 391 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | unsigned char event_receiver; |
| 393 | unsigned char event_receiver_lun; |
| 394 | unsigned char local_sel_device; |
| 395 | unsigned char local_event_generator; |
| 396 | |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 397 | /* For handling of maintenance mode. */ |
| 398 | int maintenance_mode; |
| 399 | int maintenance_mode_enable; |
| 400 | int auto_maintenance_timeout; |
| 401 | spinlock_t maintenance_mode_lock; /* Used in a timer... */ |
| 402 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 403 | /* |
| 404 | * A cheap hack, if this is non-null and a message to an |
| 405 | * interface comes in with a NULL user, call this routine with |
| 406 | * it. Note that the message will still be freed by the |
| 407 | * caller. This only works on the system interface. |
| 408 | */ |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 409 | void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_recv_msg *msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 411 | /* |
| 412 | * When we are scanning the channels for an SMI, this will |
| 413 | * tell which channel we are scanning. |
| 414 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | int curr_channel; |
| 416 | |
| 417 | /* Channel information */ |
| 418 | struct ipmi_channel channels[IPMI_MAX_CHANNELS]; |
| 419 | |
| 420 | /* Proc FS stuff. */ |
| 421 | struct proc_dir_entry *proc_dir; |
| 422 | char proc_dir_name[10]; |
| 423 | |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 424 | atomic_t stats[IPMI_NUM_STATS]; |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 425 | |
| 426 | /* |
| 427 | * run_to_completion duplicate of smb_info, smi_info |
| 428 | * and ipmi_serial_info structures. Used to decrease numbers of |
| 429 | * parameters passed by "low" level IPMI code. |
| 430 | */ |
| 431 | int run_to_completion; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | }; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 433 | #define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 435 | /** |
| 436 | * The driver model view of the IPMI messaging driver. |
| 437 | */ |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 438 | static struct platform_driver ipmidriver = { |
| 439 | .driver = { |
| 440 | .name = "ipmi", |
| 441 | .bus = &platform_bus_type |
| 442 | } |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 443 | }; |
| 444 | static DEFINE_MUTEX(ipmidriver_mutex); |
| 445 | |
Denis Cheng | bed9759 | 2008-02-06 01:37:35 -0800 | [diff] [blame] | 446 | static LIST_HEAD(ipmi_interfaces); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 447 | static DEFINE_MUTEX(ipmi_interfaces_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 449 | /* |
| 450 | * List of watchers that want to know when smi's are added and deleted. |
| 451 | */ |
Denis Cheng | bed9759 | 2008-02-06 01:37:35 -0800 | [diff] [blame] | 452 | static LIST_HEAD(smi_watchers); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 453 | static DEFINE_MUTEX(smi_watchers_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 456 | #define ipmi_inc_stat(intf, stat) \ |
| 457 | atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat]) |
| 458 | #define ipmi_get_stat(intf, stat) \ |
| 459 | ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat])) |
| 460 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 461 | static int is_lan_addr(struct ipmi_addr *addr) |
| 462 | { |
| 463 | return addr->addr_type == IPMI_LAN_ADDR_TYPE; |
| 464 | } |
| 465 | |
| 466 | static int is_ipmb_addr(struct ipmi_addr *addr) |
| 467 | { |
| 468 | return addr->addr_type == IPMI_IPMB_ADDR_TYPE; |
| 469 | } |
| 470 | |
| 471 | static int is_ipmb_bcast_addr(struct ipmi_addr *addr) |
| 472 | { |
| 473 | return addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE; |
| 474 | } |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 475 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 476 | static void free_recv_msg_list(struct list_head *q) |
| 477 | { |
| 478 | struct ipmi_recv_msg *msg, *msg2; |
| 479 | |
| 480 | list_for_each_entry_safe(msg, msg2, q, link) { |
| 481 | list_del(&msg->link); |
| 482 | ipmi_free_recv_msg(msg); |
| 483 | } |
| 484 | } |
| 485 | |
Corey Minyard | f3ce6a0 | 2006-11-08 17:44:52 -0800 | [diff] [blame] | 486 | static void free_smi_msg_list(struct list_head *q) |
| 487 | { |
| 488 | struct ipmi_smi_msg *msg, *msg2; |
| 489 | |
| 490 | list_for_each_entry_safe(msg, msg2, q, link) { |
| 491 | list_del(&msg->link); |
| 492 | ipmi_free_smi_msg(msg); |
| 493 | } |
| 494 | } |
| 495 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 496 | static void clean_up_interface_data(ipmi_smi_t intf) |
| 497 | { |
| 498 | int i; |
| 499 | struct cmd_rcvr *rcvr, *rcvr2; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 500 | struct list_head list; |
| 501 | |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 502 | tasklet_kill(&intf->recv_tasklet); |
| 503 | |
Corey Minyard | f3ce6a0 | 2006-11-08 17:44:52 -0800 | [diff] [blame] | 504 | free_smi_msg_list(&intf->waiting_msgs); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 505 | free_recv_msg_list(&intf->waiting_events); |
| 506 | |
Corey Minyard | 78ba2fa | 2007-02-10 01:45:45 -0800 | [diff] [blame] | 507 | /* |
| 508 | * Wholesale remove all the entries from the list in the |
| 509 | * interface and wait for RCU to know that none are in use. |
| 510 | */ |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 511 | mutex_lock(&intf->cmd_rcvrs_mutex); |
Corey Minyard | 78ba2fa | 2007-02-10 01:45:45 -0800 | [diff] [blame] | 512 | INIT_LIST_HEAD(&list); |
| 513 | list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu); |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 514 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 515 | |
| 516 | list_for_each_entry_safe(rcvr, rcvr2, &list, link) |
| 517 | kfree(rcvr); |
| 518 | |
| 519 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { |
| 520 | if ((intf->seq_table[i].inuse) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 521 | && (intf->seq_table[i].recv_msg)) |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 522 | ipmi_free_recv_msg(intf->seq_table[i].recv_msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static void intf_free(struct kref *ref) |
| 527 | { |
| 528 | ipmi_smi_t intf = container_of(ref, struct ipmi_smi, refcount); |
| 529 | |
| 530 | clean_up_interface_data(intf); |
| 531 | kfree(intf); |
| 532 | } |
| 533 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 534 | struct watcher_entry { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 535 | int intf_num; |
| 536 | ipmi_smi_t intf; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 537 | struct list_head link; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 538 | }; |
| 539 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 540 | int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher) |
| 541 | { |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 542 | ipmi_smi_t intf; |
Denis Cheng | e381d1c | 2008-02-06 01:37:39 -0800 | [diff] [blame] | 543 | LIST_HEAD(to_deliver); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 544 | struct watcher_entry *e, *e2; |
| 545 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 546 | mutex_lock(&smi_watchers_mutex); |
| 547 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 548 | mutex_lock(&ipmi_interfaces_mutex); |
| 549 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 550 | /* Build a list of things to deliver. */ |
Corey Minyard | 78ba2fa | 2007-02-10 01:45:45 -0800 | [diff] [blame] | 551 | list_for_each_entry(intf, &ipmi_interfaces, link) { |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 552 | if (intf->intf_num == -1) |
| 553 | continue; |
| 554 | e = kmalloc(sizeof(*e), GFP_KERNEL); |
| 555 | if (!e) |
| 556 | goto out_err; |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 557 | kref_get(&intf->refcount); |
| 558 | e->intf = intf; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 559 | e->intf_num = intf->intf_num; |
| 560 | list_add_tail(&e->link, &to_deliver); |
| 561 | } |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 562 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 563 | /* We will succeed, so add it to the list. */ |
| 564 | list_add(&watcher->link, &smi_watchers); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 565 | |
| 566 | mutex_unlock(&ipmi_interfaces_mutex); |
| 567 | |
| 568 | list_for_each_entry_safe(e, e2, &to_deliver, link) { |
| 569 | list_del(&e->link); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 570 | watcher->new_smi(e->intf_num, e->intf->si_dev); |
| 571 | kref_put(&e->intf->refcount, intf_free); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 572 | kfree(e); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 573 | } |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 574 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 575 | mutex_unlock(&smi_watchers_mutex); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return 0; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 578 | |
| 579 | out_err: |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 580 | mutex_unlock(&ipmi_interfaces_mutex); |
| 581 | mutex_unlock(&smi_watchers_mutex); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 582 | list_for_each_entry_safe(e, e2, &to_deliver, link) { |
| 583 | list_del(&e->link); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 584 | kref_put(&e->intf->refcount, intf_free); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 585 | kfree(e); |
| 586 | } |
| 587 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 589 | EXPORT_SYMBOL(ipmi_smi_watcher_register); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
| 591 | int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher) |
| 592 | { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 593 | mutex_lock(&smi_watchers_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | list_del(&(watcher->link)); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 595 | mutex_unlock(&smi_watchers_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | return 0; |
| 597 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 598 | EXPORT_SYMBOL(ipmi_smi_watcher_unregister); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 600 | /* |
| 601 | * Must be called with smi_watchers_mutex held. |
| 602 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | static void |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 604 | call_smi_watchers(int i, struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | { |
| 606 | struct ipmi_smi_watcher *w; |
| 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | list_for_each_entry(w, &smi_watchers, link) { |
| 609 | if (try_module_get(w->owner)) { |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 610 | w->new_smi(i, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | module_put(w->owner); |
| 612 | } |
| 613 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | static int |
| 617 | ipmi_addr_equal(struct ipmi_addr *addr1, struct ipmi_addr *addr2) |
| 618 | { |
| 619 | if (addr1->addr_type != addr2->addr_type) |
| 620 | return 0; |
| 621 | |
| 622 | if (addr1->channel != addr2->channel) |
| 623 | return 0; |
| 624 | |
| 625 | if (addr1->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { |
| 626 | struct ipmi_system_interface_addr *smi_addr1 |
| 627 | = (struct ipmi_system_interface_addr *) addr1; |
| 628 | struct ipmi_system_interface_addr *smi_addr2 |
| 629 | = (struct ipmi_system_interface_addr *) addr2; |
| 630 | return (smi_addr1->lun == smi_addr2->lun); |
| 631 | } |
| 632 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 633 | if (is_ipmb_addr(addr1) || is_ipmb_bcast_addr(addr1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | struct ipmi_ipmb_addr *ipmb_addr1 |
| 635 | = (struct ipmi_ipmb_addr *) addr1; |
| 636 | struct ipmi_ipmb_addr *ipmb_addr2 |
| 637 | = (struct ipmi_ipmb_addr *) addr2; |
| 638 | |
| 639 | return ((ipmb_addr1->slave_addr == ipmb_addr2->slave_addr) |
| 640 | && (ipmb_addr1->lun == ipmb_addr2->lun)); |
| 641 | } |
| 642 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 643 | if (is_lan_addr(addr1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | struct ipmi_lan_addr *lan_addr1 |
| 645 | = (struct ipmi_lan_addr *) addr1; |
| 646 | struct ipmi_lan_addr *lan_addr2 |
| 647 | = (struct ipmi_lan_addr *) addr2; |
| 648 | |
| 649 | return ((lan_addr1->remote_SWID == lan_addr2->remote_SWID) |
| 650 | && (lan_addr1->local_SWID == lan_addr2->local_SWID) |
| 651 | && (lan_addr1->session_handle |
| 652 | == lan_addr2->session_handle) |
| 653 | && (lan_addr1->lun == lan_addr2->lun)); |
| 654 | } |
| 655 | |
| 656 | return 1; |
| 657 | } |
| 658 | |
| 659 | int ipmi_validate_addr(struct ipmi_addr *addr, int len) |
| 660 | { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 661 | if (len < sizeof(struct ipmi_system_interface_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
| 664 | if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { |
| 665 | if (addr->channel != IPMI_BMC_CHANNEL) |
| 666 | return -EINVAL; |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | if ((addr->channel == IPMI_BMC_CHANNEL) |
Jayachandran C | 12fc1d7 | 2006-02-03 03:04:51 -0800 | [diff] [blame] | 671 | || (addr->channel >= IPMI_MAX_CHANNELS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | || (addr->channel < 0)) |
| 673 | return -EINVAL; |
| 674 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 675 | if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 676 | if (len < sizeof(struct ipmi_ipmb_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | return 0; |
| 679 | } |
| 680 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 681 | if (is_lan_addr(addr)) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 682 | if (len < sizeof(struct ipmi_lan_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
| 687 | return -EINVAL; |
| 688 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 689 | EXPORT_SYMBOL(ipmi_validate_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | |
| 691 | unsigned int ipmi_addr_length(int addr_type) |
| 692 | { |
| 693 | if (addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
| 694 | return sizeof(struct ipmi_system_interface_addr); |
| 695 | |
| 696 | if ((addr_type == IPMI_IPMB_ADDR_TYPE) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 697 | || (addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | return sizeof(struct ipmi_ipmb_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | |
| 700 | if (addr_type == IPMI_LAN_ADDR_TYPE) |
| 701 | return sizeof(struct ipmi_lan_addr); |
| 702 | |
| 703 | return 0; |
| 704 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 705 | EXPORT_SYMBOL(ipmi_addr_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | static void deliver_response(struct ipmi_recv_msg *msg) |
| 708 | { |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 709 | if (!msg->user) { |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 710 | ipmi_smi_t intf = msg->user_msg_data; |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 711 | |
| 712 | /* Special handling for NULL users. */ |
| 713 | if (intf->null_user_handler) { |
| 714 | intf->null_user_handler(intf, msg); |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 715 | ipmi_inc_stat(intf, handled_local_responses); |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 716 | } else { |
| 717 | /* No handler, so give up. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 718 | ipmi_inc_stat(intf, unhandled_local_responses); |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 719 | } |
| 720 | ipmi_free_recv_msg(msg); |
| 721 | } else { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 722 | ipmi_user_t user = msg->user; |
| 723 | user->handler->ipmi_recv_hndl(msg, user->handler_data); |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 724 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 727 | static void |
| 728 | deliver_err_response(struct ipmi_recv_msg *msg, int err) |
| 729 | { |
| 730 | msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
| 731 | msg->msg_data[0] = err; |
| 732 | msg->msg.netfn |= 1; /* Convert to a response. */ |
| 733 | msg->msg.data_len = 1; |
| 734 | msg->msg.data = msg->msg_data; |
| 735 | deliver_response(msg); |
| 736 | } |
| 737 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 738 | /* |
| 739 | * Find the next sequence number not being used and add the given |
| 740 | * message with the given timeout to the sequence table. This must be |
| 741 | * called with the interface's seq_lock held. |
| 742 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | static int intf_next_seq(ipmi_smi_t intf, |
| 744 | struct ipmi_recv_msg *recv_msg, |
| 745 | unsigned long timeout, |
| 746 | int retries, |
| 747 | int broadcast, |
| 748 | unsigned char *seq, |
| 749 | long *seqid) |
| 750 | { |
| 751 | int rv = 0; |
| 752 | unsigned int i; |
| 753 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 754 | for (i = intf->curr_seq; (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq; |
| 755 | i = (i+1)%IPMI_IPMB_NUM_SEQ) { |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 756 | if (!intf->seq_table[i].inuse) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | break; |
| 758 | } |
| 759 | |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 760 | if (!intf->seq_table[i].inuse) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | intf->seq_table[i].recv_msg = recv_msg; |
| 762 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 763 | /* |
| 764 | * Start with the maximum timeout, when the send response |
| 765 | * comes in we will start the real timer. |
| 766 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | intf->seq_table[i].timeout = MAX_MSG_TIMEOUT; |
| 768 | intf->seq_table[i].orig_timeout = timeout; |
| 769 | intf->seq_table[i].retries_left = retries; |
| 770 | intf->seq_table[i].broadcast = broadcast; |
| 771 | intf->seq_table[i].inuse = 1; |
| 772 | intf->seq_table[i].seqid = NEXT_SEQID(intf->seq_table[i].seqid); |
| 773 | *seq = i; |
| 774 | *seqid = intf->seq_table[i].seqid; |
| 775 | intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ; |
| 776 | } else { |
| 777 | rv = -EAGAIN; |
| 778 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | return rv; |
| 781 | } |
| 782 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 783 | /* |
| 784 | * Return the receive message for the given sequence number and |
| 785 | * release the sequence number so it can be reused. Some other data |
| 786 | * is passed in to be sure the message matches up correctly (to help |
| 787 | * guard against message coming in after their timeout and the |
| 788 | * sequence number being reused). |
| 789 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | static int intf_find_seq(ipmi_smi_t intf, |
| 791 | unsigned char seq, |
| 792 | short channel, |
| 793 | unsigned char cmd, |
| 794 | unsigned char netfn, |
| 795 | struct ipmi_addr *addr, |
| 796 | struct ipmi_recv_msg **recv_msg) |
| 797 | { |
| 798 | int rv = -ENODEV; |
| 799 | unsigned long flags; |
| 800 | |
| 801 | if (seq >= IPMI_IPMB_NUM_SEQ) |
| 802 | return -EINVAL; |
| 803 | |
| 804 | spin_lock_irqsave(&(intf->seq_lock), flags); |
| 805 | if (intf->seq_table[seq].inuse) { |
| 806 | struct ipmi_recv_msg *msg = intf->seq_table[seq].recv_msg; |
| 807 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 808 | if ((msg->addr.channel == channel) && (msg->msg.cmd == cmd) |
| 809 | && (msg->msg.netfn == netfn) |
| 810 | && (ipmi_addr_equal(addr, &(msg->addr)))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | *recv_msg = msg; |
| 812 | intf->seq_table[seq].inuse = 0; |
| 813 | rv = 0; |
| 814 | } |
| 815 | } |
| 816 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
| 817 | |
| 818 | return rv; |
| 819 | } |
| 820 | |
| 821 | |
| 822 | /* Start the timer for a specific sequence table entry. */ |
| 823 | static int intf_start_seq_timer(ipmi_smi_t intf, |
| 824 | long msgid) |
| 825 | { |
| 826 | int rv = -ENODEV; |
| 827 | unsigned long flags; |
| 828 | unsigned char seq; |
| 829 | unsigned long seqid; |
| 830 | |
| 831 | |
| 832 | GET_SEQ_FROM_MSGID(msgid, seq, seqid); |
| 833 | |
| 834 | spin_lock_irqsave(&(intf->seq_lock), flags); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 835 | /* |
| 836 | * We do this verification because the user can be deleted |
| 837 | * while a message is outstanding. |
| 838 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | if ((intf->seq_table[seq].inuse) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 840 | && (intf->seq_table[seq].seqid == seqid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | struct seq_table *ent = &(intf->seq_table[seq]); |
| 842 | ent->timeout = ent->orig_timeout; |
| 843 | rv = 0; |
| 844 | } |
| 845 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
| 846 | |
| 847 | return rv; |
| 848 | } |
| 849 | |
| 850 | /* Got an error for the send message for a specific sequence number. */ |
| 851 | static int intf_err_seq(ipmi_smi_t intf, |
| 852 | long msgid, |
| 853 | unsigned int err) |
| 854 | { |
| 855 | int rv = -ENODEV; |
| 856 | unsigned long flags; |
| 857 | unsigned char seq; |
| 858 | unsigned long seqid; |
| 859 | struct ipmi_recv_msg *msg = NULL; |
| 860 | |
| 861 | |
| 862 | GET_SEQ_FROM_MSGID(msgid, seq, seqid); |
| 863 | |
| 864 | spin_lock_irqsave(&(intf->seq_lock), flags); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 865 | /* |
| 866 | * We do this verification because the user can be deleted |
| 867 | * while a message is outstanding. |
| 868 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | if ((intf->seq_table[seq].inuse) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 870 | && (intf->seq_table[seq].seqid == seqid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | struct seq_table *ent = &(intf->seq_table[seq]); |
| 872 | |
| 873 | ent->inuse = 0; |
| 874 | msg = ent->recv_msg; |
| 875 | rv = 0; |
| 876 | } |
| 877 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
| 878 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 879 | if (msg) |
| 880 | deliver_err_response(msg, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | |
| 882 | return rv; |
| 883 | } |
| 884 | |
| 885 | |
| 886 | int ipmi_create_user(unsigned int if_num, |
| 887 | struct ipmi_user_hndl *handler, |
| 888 | void *handler_data, |
| 889 | ipmi_user_t *user) |
| 890 | { |
| 891 | unsigned long flags; |
| 892 | ipmi_user_t new_user; |
| 893 | int rv = 0; |
| 894 | ipmi_smi_t intf; |
| 895 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 896 | /* |
| 897 | * There is no module usecount here, because it's not |
| 898 | * required. Since this can only be used by and called from |
| 899 | * other modules, they will implicitly use this module, and |
| 900 | * thus this can't be removed unless the other modules are |
| 901 | * removed. |
| 902 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | if (handler == NULL) |
| 905 | return -EINVAL; |
| 906 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 907 | /* |
| 908 | * Make sure the driver is actually initialized, this handles |
| 909 | * problems with initialization order. |
| 910 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | if (!initialized) { |
| 912 | rv = ipmi_init_msghandler(); |
| 913 | if (rv) |
| 914 | return rv; |
| 915 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 916 | /* |
| 917 | * The init code doesn't return an error if it was turned |
| 918 | * off, but it won't initialize. Check that. |
| 919 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | if (!initialized) |
| 921 | return -ENODEV; |
| 922 | } |
| 923 | |
| 924 | new_user = kmalloc(sizeof(*new_user), GFP_KERNEL); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 925 | if (!new_user) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | return -ENOMEM; |
| 927 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 928 | mutex_lock(&ipmi_interfaces_mutex); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 929 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
| 930 | if (intf->intf_num == if_num) |
| 931 | goto found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 933 | /* Not found, return an error */ |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 934 | rv = -EINVAL; |
| 935 | goto out_kfree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 937 | found: |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 938 | /* Note that each existing user holds a refcount to the interface. */ |
| 939 | kref_get(&intf->refcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 941 | kref_init(&new_user->refcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | new_user->handler = handler; |
| 943 | new_user->handler_data = handler_data; |
| 944 | new_user->intf = intf; |
| 945 | new_user->gets_events = 0; |
| 946 | |
| 947 | if (!try_module_get(intf->handlers->owner)) { |
| 948 | rv = -ENODEV; |
Adrian Bunk | 5c98d29 | 2006-03-25 03:07:52 -0800 | [diff] [blame] | 949 | goto out_kref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | if (intf->handlers->inc_usecount) { |
| 953 | rv = intf->handlers->inc_usecount(intf->send_info); |
| 954 | if (rv) { |
| 955 | module_put(intf->handlers->owner); |
Adrian Bunk | 5c98d29 | 2006-03-25 03:07:52 -0800 | [diff] [blame] | 956 | goto out_kref; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } |
| 958 | } |
| 959 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 960 | /* |
| 961 | * Hold the lock so intf->handlers is guaranteed to be good |
| 962 | * until now |
| 963 | */ |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 964 | mutex_unlock(&ipmi_interfaces_mutex); |
| 965 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 966 | new_user->valid = 1; |
| 967 | spin_lock_irqsave(&intf->seq_lock, flags); |
| 968 | list_add_rcu(&new_user->link, &intf->users); |
| 969 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
| 970 | *user = new_user; |
| 971 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
Adrian Bunk | 5c98d29 | 2006-03-25 03:07:52 -0800 | [diff] [blame] | 973 | out_kref: |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 974 | kref_put(&intf->refcount, intf_free); |
Adrian Bunk | 5c98d29 | 2006-03-25 03:07:52 -0800 | [diff] [blame] | 975 | out_kfree: |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 976 | mutex_unlock(&ipmi_interfaces_mutex); |
Adrian Bunk | 5c98d29 | 2006-03-25 03:07:52 -0800 | [diff] [blame] | 977 | kfree(new_user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | return rv; |
| 979 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 980 | EXPORT_SYMBOL(ipmi_create_user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
Zhao Yakui | 16f4232 | 2010-12-08 10:10:16 +0800 | [diff] [blame] | 982 | int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data) |
| 983 | { |
| 984 | int rv = 0; |
| 985 | ipmi_smi_t intf; |
| 986 | struct ipmi_smi_handlers *handlers; |
| 987 | |
| 988 | mutex_lock(&ipmi_interfaces_mutex); |
| 989 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
| 990 | if (intf->intf_num == if_num) |
| 991 | goto found; |
| 992 | } |
| 993 | /* Not found, return an error */ |
| 994 | rv = -EINVAL; |
| 995 | mutex_unlock(&ipmi_interfaces_mutex); |
| 996 | return rv; |
| 997 | |
| 998 | found: |
| 999 | handlers = intf->handlers; |
| 1000 | rv = -ENOSYS; |
| 1001 | if (handlers->get_smi_info) |
| 1002 | rv = handlers->get_smi_info(intf->send_info, data); |
| 1003 | mutex_unlock(&ipmi_interfaces_mutex); |
| 1004 | |
| 1005 | return rv; |
| 1006 | } |
| 1007 | EXPORT_SYMBOL(ipmi_get_smi_info); |
| 1008 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1009 | static void free_user(struct kref *ref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1011 | ipmi_user_t user = container_of(ref, struct ipmi_user, refcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | kfree(user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | int ipmi_destroy_user(ipmi_user_t user) |
| 1016 | { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1017 | ipmi_smi_t intf = user->intf; |
| 1018 | int i; |
| 1019 | unsigned long flags; |
| 1020 | struct cmd_rcvr *rcvr; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1021 | struct cmd_rcvr *rcvrs = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 1023 | user->valid = 0; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1024 | |
| 1025 | /* Remove the user from the interface's sequence table. */ |
| 1026 | spin_lock_irqsave(&intf->seq_lock, flags); |
| 1027 | list_del_rcu(&user->link); |
| 1028 | |
| 1029 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { |
| 1030 | if (intf->seq_table[i].inuse |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1031 | && (intf->seq_table[i].recv_msg->user == user)) { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1032 | intf->seq_table[i].inuse = 0; |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1033 | ipmi_free_recv_msg(intf->seq_table[i].recv_msg); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1034 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | } |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1036 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
| 1037 | |
| 1038 | /* |
| 1039 | * Remove the user from the command receiver's table. First |
| 1040 | * we build a list of everything (not using the standard link, |
| 1041 | * since other things may be using it till we do |
| 1042 | * synchronize_rcu()) then free everything in that list. |
| 1043 | */ |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 1044 | mutex_lock(&intf->cmd_rcvrs_mutex); |
Paul E. McKenney | 066bb8d | 2006-01-06 00:19:53 -0800 | [diff] [blame] | 1045 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1046 | if (rcvr->user == user) { |
| 1047 | list_del_rcu(&rcvr->link); |
| 1048 | rcvr->next = rcvrs; |
| 1049 | rcvrs = rcvr; |
| 1050 | } |
| 1051 | } |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 1052 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1053 | synchronize_rcu(); |
| 1054 | while (rcvrs) { |
| 1055 | rcvr = rcvrs; |
| 1056 | rcvrs = rcvr->next; |
| 1057 | kfree(rcvr); |
| 1058 | } |
| 1059 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1060 | mutex_lock(&ipmi_interfaces_mutex); |
| 1061 | if (intf->handlers) { |
| 1062 | module_put(intf->handlers->owner); |
| 1063 | if (intf->handlers->dec_usecount) |
| 1064 | intf->handlers->dec_usecount(intf->send_info); |
| 1065 | } |
| 1066 | mutex_unlock(&ipmi_interfaces_mutex); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1067 | |
| 1068 | kref_put(&intf->refcount, intf_free); |
| 1069 | |
| 1070 | kref_put(&user->refcount, free_user); |
| 1071 | |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 1072 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1074 | EXPORT_SYMBOL(ipmi_destroy_user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | |
| 1076 | void ipmi_get_version(ipmi_user_t user, |
| 1077 | unsigned char *major, |
| 1078 | unsigned char *minor) |
| 1079 | { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1080 | *major = user->intf->ipmi_version_major; |
| 1081 | *minor = user->intf->ipmi_version_minor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1083 | EXPORT_SYMBOL(ipmi_get_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1085 | int ipmi_set_my_address(ipmi_user_t user, |
| 1086 | unsigned int channel, |
| 1087 | unsigned char address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | { |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1089 | if (channel >= IPMI_MAX_CHANNELS) |
| 1090 | return -EINVAL; |
| 1091 | user->intf->channels[channel].address = address; |
| 1092 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1094 | EXPORT_SYMBOL(ipmi_set_my_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1096 | int ipmi_get_my_address(ipmi_user_t user, |
| 1097 | unsigned int channel, |
| 1098 | unsigned char *address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | { |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1100 | if (channel >= IPMI_MAX_CHANNELS) |
| 1101 | return -EINVAL; |
| 1102 | *address = user->intf->channels[channel].address; |
| 1103 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1105 | EXPORT_SYMBOL(ipmi_get_my_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1107 | int ipmi_set_my_LUN(ipmi_user_t user, |
| 1108 | unsigned int channel, |
| 1109 | unsigned char LUN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | { |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1111 | if (channel >= IPMI_MAX_CHANNELS) |
| 1112 | return -EINVAL; |
| 1113 | user->intf->channels[channel].lun = LUN & 0x3; |
| 1114 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1116 | EXPORT_SYMBOL(ipmi_set_my_LUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1118 | int ipmi_get_my_LUN(ipmi_user_t user, |
| 1119 | unsigned int channel, |
| 1120 | unsigned char *address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | { |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1122 | if (channel >= IPMI_MAX_CHANNELS) |
| 1123 | return -EINVAL; |
| 1124 | *address = user->intf->channels[channel].lun; |
| 1125 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1127 | EXPORT_SYMBOL(ipmi_get_my_LUN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 1129 | int ipmi_get_maintenance_mode(ipmi_user_t user) |
| 1130 | { |
| 1131 | int mode; |
| 1132 | unsigned long flags; |
| 1133 | |
| 1134 | spin_lock_irqsave(&user->intf->maintenance_mode_lock, flags); |
| 1135 | mode = user->intf->maintenance_mode; |
| 1136 | spin_unlock_irqrestore(&user->intf->maintenance_mode_lock, flags); |
| 1137 | |
| 1138 | return mode; |
| 1139 | } |
| 1140 | EXPORT_SYMBOL(ipmi_get_maintenance_mode); |
| 1141 | |
| 1142 | static void maintenance_mode_update(ipmi_smi_t intf) |
| 1143 | { |
| 1144 | if (intf->handlers->set_maintenance_mode) |
| 1145 | intf->handlers->set_maintenance_mode( |
| 1146 | intf->send_info, intf->maintenance_mode_enable); |
| 1147 | } |
| 1148 | |
| 1149 | int ipmi_set_maintenance_mode(ipmi_user_t user, int mode) |
| 1150 | { |
| 1151 | int rv = 0; |
| 1152 | unsigned long flags; |
| 1153 | ipmi_smi_t intf = user->intf; |
| 1154 | |
| 1155 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); |
| 1156 | if (intf->maintenance_mode != mode) { |
| 1157 | switch (mode) { |
| 1158 | case IPMI_MAINTENANCE_MODE_AUTO: |
| 1159 | intf->maintenance_mode = mode; |
| 1160 | intf->maintenance_mode_enable |
| 1161 | = (intf->auto_maintenance_timeout > 0); |
| 1162 | break; |
| 1163 | |
| 1164 | case IPMI_MAINTENANCE_MODE_OFF: |
| 1165 | intf->maintenance_mode = mode; |
| 1166 | intf->maintenance_mode_enable = 0; |
| 1167 | break; |
| 1168 | |
| 1169 | case IPMI_MAINTENANCE_MODE_ON: |
| 1170 | intf->maintenance_mode = mode; |
| 1171 | intf->maintenance_mode_enable = 1; |
| 1172 | break; |
| 1173 | |
| 1174 | default: |
| 1175 | rv = -EINVAL; |
| 1176 | goto out_unlock; |
| 1177 | } |
| 1178 | |
| 1179 | maintenance_mode_update(intf); |
| 1180 | } |
| 1181 | out_unlock: |
| 1182 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, flags); |
| 1183 | |
| 1184 | return rv; |
| 1185 | } |
| 1186 | EXPORT_SYMBOL(ipmi_set_maintenance_mode); |
| 1187 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | int ipmi_set_gets_events(ipmi_user_t user, int val) |
| 1189 | { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1190 | unsigned long flags; |
| 1191 | ipmi_smi_t intf = user->intf; |
| 1192 | struct ipmi_recv_msg *msg, *msg2; |
| 1193 | struct list_head msgs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1195 | INIT_LIST_HEAD(&msgs); |
| 1196 | |
| 1197 | spin_lock_irqsave(&intf->events_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | user->gets_events = val; |
| 1199 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1200 | if (intf->delivering_events) |
| 1201 | /* |
| 1202 | * Another thread is delivering events for this, so |
| 1203 | * let it handle any new events. |
| 1204 | */ |
| 1205 | goto out; |
| 1206 | |
| 1207 | /* Deliver any queued events. */ |
| 1208 | while (user->gets_events && !list_empty(&intf->waiting_events)) { |
Akinobu Mita | 179e091 | 2006-06-26 00:24:41 -0700 | [diff] [blame] | 1209 | list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) |
| 1210 | list_move_tail(&msg->link, &msgs); |
Corey Minyard | 4791c03 | 2006-04-10 22:54:31 -0700 | [diff] [blame] | 1211 | intf->waiting_events_count = 0; |
Corey Minyard | 87ebd06 | 2008-04-29 01:01:04 -0700 | [diff] [blame] | 1212 | if (intf->event_msg_printed) { |
| 1213 | printk(KERN_WARNING PFX "Event queue no longer" |
| 1214 | " full\n"); |
| 1215 | intf->event_msg_printed = 0; |
| 1216 | } |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1217 | |
| 1218 | intf->delivering_events = 1; |
| 1219 | spin_unlock_irqrestore(&intf->events_lock, flags); |
| 1220 | |
| 1221 | list_for_each_entry_safe(msg, msg2, &msgs, link) { |
| 1222 | msg->user = user; |
| 1223 | kref_get(&user->refcount); |
| 1224 | deliver_response(msg); |
| 1225 | } |
| 1226 | |
| 1227 | spin_lock_irqsave(&intf->events_lock, flags); |
| 1228 | intf->delivering_events = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | } |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1230 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1231 | out: |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1232 | spin_unlock_irqrestore(&intf->events_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | |
| 1234 | return 0; |
| 1235 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1236 | EXPORT_SYMBOL(ipmi_set_gets_events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1238 | static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf, |
| 1239 | unsigned char netfn, |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1240 | unsigned char cmd, |
| 1241 | unsigned char chan) |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1242 | { |
| 1243 | struct cmd_rcvr *rcvr; |
| 1244 | |
| 1245 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1246 | if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) |
| 1247 | && (rcvr->chans & (1 << chan))) |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1248 | return rcvr; |
| 1249 | } |
| 1250 | return NULL; |
| 1251 | } |
| 1252 | |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1253 | static int is_cmd_rcvr_exclusive(ipmi_smi_t intf, |
| 1254 | unsigned char netfn, |
| 1255 | unsigned char cmd, |
| 1256 | unsigned int chans) |
| 1257 | { |
| 1258 | struct cmd_rcvr *rcvr; |
| 1259 | |
| 1260 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { |
| 1261 | if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) |
| 1262 | && (rcvr->chans & chans)) |
| 1263 | return 0; |
| 1264 | } |
| 1265 | return 1; |
| 1266 | } |
| 1267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | int ipmi_register_for_cmd(ipmi_user_t user, |
| 1269 | unsigned char netfn, |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1270 | unsigned char cmd, |
| 1271 | unsigned int chans) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1273 | ipmi_smi_t intf = user->intf; |
| 1274 | struct cmd_rcvr *rcvr; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1275 | int rv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | |
| 1277 | |
| 1278 | rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 1279 | if (!rcvr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | return -ENOMEM; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1281 | rcvr->cmd = cmd; |
| 1282 | rcvr->netfn = netfn; |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1283 | rcvr->chans = chans; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1284 | rcvr->user = user; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 1286 | mutex_lock(&intf->cmd_rcvrs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | /* Make sure the command/netfn is not already registered. */ |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1288 | if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1289 | rv = -EBUSY; |
| 1290 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | } |
| 1292 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1293 | list_add_rcu(&rcvr->link, &intf->cmd_rcvrs); |
Corey Minyard | 877197e | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 1294 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1295 | out_unlock: |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 1296 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | if (rv) |
| 1298 | kfree(rcvr); |
| 1299 | |
| 1300 | return rv; |
| 1301 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1302 | EXPORT_SYMBOL(ipmi_register_for_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | |
| 1304 | int ipmi_unregister_for_cmd(ipmi_user_t user, |
| 1305 | unsigned char netfn, |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1306 | unsigned char cmd, |
| 1307 | unsigned int chans) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1309 | ipmi_smi_t intf = user->intf; |
| 1310 | struct cmd_rcvr *rcvr; |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1311 | struct cmd_rcvr *rcvrs = NULL; |
| 1312 | int i, rv = -ENOENT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 1314 | mutex_lock(&intf->cmd_rcvrs_mutex); |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1315 | for (i = 0; i < IPMI_NUM_CHANNELS; i++) { |
| 1316 | if (((1 << i) & chans) == 0) |
| 1317 | continue; |
| 1318 | rcvr = find_cmd_rcvr(intf, netfn, cmd, i); |
| 1319 | if (rcvr == NULL) |
| 1320 | continue; |
| 1321 | if (rcvr->user == user) { |
| 1322 | rv = 0; |
| 1323 | rcvr->chans &= ~chans; |
| 1324 | if (rcvr->chans == 0) { |
| 1325 | list_del_rcu(&rcvr->link); |
| 1326 | rcvr->next = rcvrs; |
| 1327 | rcvrs = rcvr; |
| 1328 | } |
| 1329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | } |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 1331 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
| 1332 | synchronize_rcu(); |
| 1333 | while (rcvrs) { |
| 1334 | rcvr = rcvrs; |
| 1335 | rcvrs = rcvr->next; |
| 1336 | kfree(rcvr); |
| 1337 | } |
| 1338 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1340 | EXPORT_SYMBOL(ipmi_unregister_for_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | static unsigned char |
| 1343 | ipmb_checksum(unsigned char *data, int size) |
| 1344 | { |
| 1345 | unsigned char csum = 0; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | for (; size > 0; size--, data++) |
| 1348 | csum += *data; |
| 1349 | |
| 1350 | return -csum; |
| 1351 | } |
| 1352 | |
| 1353 | static inline void format_ipmb_msg(struct ipmi_smi_msg *smi_msg, |
| 1354 | struct kernel_ipmi_msg *msg, |
| 1355 | struct ipmi_ipmb_addr *ipmb_addr, |
| 1356 | long msgid, |
| 1357 | unsigned char ipmb_seq, |
| 1358 | int broadcast, |
| 1359 | unsigned char source_address, |
| 1360 | unsigned char source_lun) |
| 1361 | { |
| 1362 | int i = broadcast; |
| 1363 | |
| 1364 | /* Format the IPMB header data. */ |
| 1365 | smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 1366 | smi_msg->data[1] = IPMI_SEND_MSG_CMD; |
| 1367 | smi_msg->data[2] = ipmb_addr->channel; |
| 1368 | if (broadcast) |
| 1369 | smi_msg->data[3] = 0; |
| 1370 | smi_msg->data[i+3] = ipmb_addr->slave_addr; |
| 1371 | smi_msg->data[i+4] = (msg->netfn << 2) | (ipmb_addr->lun & 0x3); |
| 1372 | smi_msg->data[i+5] = ipmb_checksum(&(smi_msg->data[i+3]), 2); |
| 1373 | smi_msg->data[i+6] = source_address; |
| 1374 | smi_msg->data[i+7] = (ipmb_seq << 2) | source_lun; |
| 1375 | smi_msg->data[i+8] = msg->cmd; |
| 1376 | |
| 1377 | /* Now tack on the data to the message. */ |
| 1378 | if (msg->data_len > 0) |
| 1379 | memcpy(&(smi_msg->data[i+9]), msg->data, |
| 1380 | msg->data_len); |
| 1381 | smi_msg->data_size = msg->data_len + 9; |
| 1382 | |
| 1383 | /* Now calculate the checksum and tack it on. */ |
| 1384 | smi_msg->data[i+smi_msg->data_size] |
| 1385 | = ipmb_checksum(&(smi_msg->data[i+6]), |
| 1386 | smi_msg->data_size-6); |
| 1387 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1388 | /* |
| 1389 | * Add on the checksum size and the offset from the |
| 1390 | * broadcast. |
| 1391 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | smi_msg->data_size += 1 + i; |
| 1393 | |
| 1394 | smi_msg->msgid = msgid; |
| 1395 | } |
| 1396 | |
| 1397 | static inline void format_lan_msg(struct ipmi_smi_msg *smi_msg, |
| 1398 | struct kernel_ipmi_msg *msg, |
| 1399 | struct ipmi_lan_addr *lan_addr, |
| 1400 | long msgid, |
| 1401 | unsigned char ipmb_seq, |
| 1402 | unsigned char source_lun) |
| 1403 | { |
| 1404 | /* Format the IPMB header data. */ |
| 1405 | smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 1406 | smi_msg->data[1] = IPMI_SEND_MSG_CMD; |
| 1407 | smi_msg->data[2] = lan_addr->channel; |
| 1408 | smi_msg->data[3] = lan_addr->session_handle; |
| 1409 | smi_msg->data[4] = lan_addr->remote_SWID; |
| 1410 | smi_msg->data[5] = (msg->netfn << 2) | (lan_addr->lun & 0x3); |
| 1411 | smi_msg->data[6] = ipmb_checksum(&(smi_msg->data[4]), 2); |
| 1412 | smi_msg->data[7] = lan_addr->local_SWID; |
| 1413 | smi_msg->data[8] = (ipmb_seq << 2) | source_lun; |
| 1414 | smi_msg->data[9] = msg->cmd; |
| 1415 | |
| 1416 | /* Now tack on the data to the message. */ |
| 1417 | if (msg->data_len > 0) |
| 1418 | memcpy(&(smi_msg->data[10]), msg->data, |
| 1419 | msg->data_len); |
| 1420 | smi_msg->data_size = msg->data_len + 10; |
| 1421 | |
| 1422 | /* Now calculate the checksum and tack it on. */ |
| 1423 | smi_msg->data[smi_msg->data_size] |
| 1424 | = ipmb_checksum(&(smi_msg->data[7]), |
| 1425 | smi_msg->data_size-7); |
| 1426 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1427 | /* |
| 1428 | * Add on the checksum size and the offset from the |
| 1429 | * broadcast. |
| 1430 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | smi_msg->data_size += 1; |
| 1432 | |
| 1433 | smi_msg->msgid = msgid; |
| 1434 | } |
| 1435 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1436 | /* |
| 1437 | * Separate from ipmi_request so that the user does not have to be |
| 1438 | * supplied in certain circumstances (mainly at panic time). If |
| 1439 | * messages are supplied, they will be freed, even if an error |
| 1440 | * occurs. |
| 1441 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1442 | static int i_ipmi_request(ipmi_user_t user, |
| 1443 | ipmi_smi_t intf, |
| 1444 | struct ipmi_addr *addr, |
| 1445 | long msgid, |
| 1446 | struct kernel_ipmi_msg *msg, |
| 1447 | void *user_msg_data, |
| 1448 | void *supplied_smi, |
| 1449 | struct ipmi_recv_msg *supplied_recv, |
| 1450 | int priority, |
| 1451 | unsigned char source_address, |
| 1452 | unsigned char source_lun, |
| 1453 | int retries, |
| 1454 | unsigned int retry_time_ms) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1456 | int rv = 0; |
| 1457 | struct ipmi_smi_msg *smi_msg; |
| 1458 | struct ipmi_recv_msg *recv_msg; |
| 1459 | unsigned long flags; |
| 1460 | struct ipmi_smi_handlers *handlers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
| 1462 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1463 | if (supplied_recv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | recv_msg = supplied_recv; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1465 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | recv_msg = ipmi_alloc_recv_msg(); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1467 | if (recv_msg == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | } |
| 1470 | recv_msg->user_msg_data = user_msg_data; |
| 1471 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1472 | if (supplied_smi) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1473 | smi_msg = (struct ipmi_smi_msg *) supplied_smi; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1474 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | smi_msg = ipmi_alloc_smi_msg(); |
| 1476 | if (smi_msg == NULL) { |
| 1477 | ipmi_free_recv_msg(recv_msg); |
| 1478 | return -ENOMEM; |
| 1479 | } |
| 1480 | } |
| 1481 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1482 | rcu_read_lock(); |
| 1483 | handlers = intf->handlers; |
| 1484 | if (!handlers) { |
| 1485 | rv = -ENODEV; |
| 1486 | goto out_err; |
| 1487 | } |
| 1488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | recv_msg->user = user; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 1490 | if (user) |
| 1491 | kref_get(&user->refcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | recv_msg->msgid = msgid; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1493 | /* |
| 1494 | * Store the message to send in the receive message so timeout |
| 1495 | * responses can get the proper response data. |
| 1496 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | recv_msg->msg = *msg; |
| 1498 | |
| 1499 | if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { |
| 1500 | struct ipmi_system_interface_addr *smi_addr; |
| 1501 | |
| 1502 | if (msg->netfn & 1) { |
| 1503 | /* Responses are not allowed to the SMI. */ |
| 1504 | rv = -EINVAL; |
| 1505 | goto out_err; |
| 1506 | } |
| 1507 | |
| 1508 | smi_addr = (struct ipmi_system_interface_addr *) addr; |
| 1509 | if (smi_addr->lun > 3) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1510 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | rv = -EINVAL; |
| 1512 | goto out_err; |
| 1513 | } |
| 1514 | |
| 1515 | memcpy(&recv_msg->addr, smi_addr, sizeof(*smi_addr)); |
| 1516 | |
| 1517 | if ((msg->netfn == IPMI_NETFN_APP_REQUEST) |
| 1518 | && ((msg->cmd == IPMI_SEND_MSG_CMD) |
| 1519 | || (msg->cmd == IPMI_GET_MSG_CMD) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1520 | || (msg->cmd == IPMI_READ_EVENT_MSG_BUFFER_CMD))) { |
| 1521 | /* |
| 1522 | * We don't let the user do these, since we manage |
| 1523 | * the sequence numbers. |
| 1524 | */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1525 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | rv = -EINVAL; |
| 1527 | goto out_err; |
| 1528 | } |
| 1529 | |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 1530 | if (((msg->netfn == IPMI_NETFN_APP_REQUEST) |
| 1531 | && ((msg->cmd == IPMI_COLD_RESET_CMD) |
| 1532 | || (msg->cmd == IPMI_WARM_RESET_CMD))) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1533 | || (msg->netfn == IPMI_NETFN_FIRMWARE_REQUEST)) { |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 1534 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); |
| 1535 | intf->auto_maintenance_timeout |
| 1536 | = IPMI_MAINTENANCE_MODE_TIMEOUT; |
| 1537 | if (!intf->maintenance_mode |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1538 | && !intf->maintenance_mode_enable) { |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 1539 | intf->maintenance_mode_enable = 1; |
| 1540 | maintenance_mode_update(intf); |
| 1541 | } |
| 1542 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, |
| 1543 | flags); |
| 1544 | } |
| 1545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1547 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | rv = -EMSGSIZE; |
| 1549 | goto out_err; |
| 1550 | } |
| 1551 | |
| 1552 | smi_msg->data[0] = (msg->netfn << 2) | (smi_addr->lun & 0x3); |
| 1553 | smi_msg->data[1] = msg->cmd; |
| 1554 | smi_msg->msgid = msgid; |
| 1555 | smi_msg->user_data = recv_msg; |
| 1556 | if (msg->data_len > 0) |
| 1557 | memcpy(&(smi_msg->data[2]), msg->data, msg->data_len); |
| 1558 | smi_msg->data_size = msg->data_len + 2; |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1559 | ipmi_inc_stat(intf, sent_local_commands); |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 1560 | } else if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | struct ipmi_ipmb_addr *ipmb_addr; |
| 1562 | unsigned char ipmb_seq; |
| 1563 | long seqid; |
| 1564 | int broadcast = 0; |
| 1565 | |
KAMBAROV, ZAUR | 9c101fd | 2005-06-28 20:45:08 -0700 | [diff] [blame] | 1566 | if (addr->channel >= IPMI_MAX_CHANNELS) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1567 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | rv = -EINVAL; |
| 1569 | goto out_err; |
| 1570 | } |
| 1571 | |
| 1572 | if (intf->channels[addr->channel].medium |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1573 | != IPMI_CHANNEL_MEDIUM_IPMB) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1574 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | rv = -EINVAL; |
| 1576 | goto out_err; |
| 1577 | } |
| 1578 | |
| 1579 | if (retries < 0) { |
| 1580 | if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) |
| 1581 | retries = 0; /* Don't retry broadcasts. */ |
| 1582 | else |
| 1583 | retries = 4; |
| 1584 | } |
| 1585 | if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1586 | /* |
| 1587 | * Broadcasts add a zero at the beginning of the |
| 1588 | * message, but otherwise is the same as an IPMB |
| 1589 | * address. |
| 1590 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | addr->addr_type = IPMI_IPMB_ADDR_TYPE; |
| 1592 | broadcast = 1; |
| 1593 | } |
| 1594 | |
| 1595 | |
| 1596 | /* Default to 1 second retries. */ |
| 1597 | if (retry_time_ms == 0) |
| 1598 | retry_time_ms = 1000; |
| 1599 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1600 | /* |
| 1601 | * 9 for the header and 1 for the checksum, plus |
| 1602 | * possibly one for the broadcast. |
| 1603 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | if ((msg->data_len + 10 + broadcast) > IPMI_MAX_MSG_LENGTH) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1605 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | rv = -EMSGSIZE; |
| 1607 | goto out_err; |
| 1608 | } |
| 1609 | |
| 1610 | ipmb_addr = (struct ipmi_ipmb_addr *) addr; |
| 1611 | if (ipmb_addr->lun > 3) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1612 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | rv = -EINVAL; |
| 1614 | goto out_err; |
| 1615 | } |
| 1616 | |
| 1617 | memcpy(&recv_msg->addr, ipmb_addr, sizeof(*ipmb_addr)); |
| 1618 | |
| 1619 | if (recv_msg->msg.netfn & 0x1) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1620 | /* |
| 1621 | * It's a response, so use the user's sequence |
| 1622 | * from msgid. |
| 1623 | */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1624 | ipmi_inc_stat(intf, sent_ipmb_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | format_ipmb_msg(smi_msg, msg, ipmb_addr, msgid, |
| 1626 | msgid, broadcast, |
| 1627 | source_address, source_lun); |
| 1628 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1629 | /* |
| 1630 | * Save the receive message so we can use it |
| 1631 | * to deliver the response. |
| 1632 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | smi_msg->user_data = recv_msg; |
| 1634 | } else { |
| 1635 | /* It's a command, so get a sequence for it. */ |
| 1636 | |
| 1637 | spin_lock_irqsave(&(intf->seq_lock), flags); |
| 1638 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1639 | /* |
| 1640 | * Create a sequence number with a 1 second |
| 1641 | * timeout and 4 retries. |
| 1642 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | rv = intf_next_seq(intf, |
| 1644 | recv_msg, |
| 1645 | retry_time_ms, |
| 1646 | retries, |
| 1647 | broadcast, |
| 1648 | &ipmb_seq, |
| 1649 | &seqid); |
| 1650 | if (rv) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1651 | /* |
| 1652 | * We have used up all the sequence numbers, |
| 1653 | * probably, so abort. |
| 1654 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | spin_unlock_irqrestore(&(intf->seq_lock), |
| 1656 | flags); |
| 1657 | goto out_err; |
| 1658 | } |
| 1659 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 1660 | ipmi_inc_stat(intf, sent_ipmb_commands); |
| 1661 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1662 | /* |
| 1663 | * Store the sequence number in the message, |
| 1664 | * so that when the send message response |
| 1665 | * comes back we can start the timer. |
| 1666 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1667 | format_ipmb_msg(smi_msg, msg, ipmb_addr, |
| 1668 | STORE_SEQ_IN_MSGID(ipmb_seq, seqid), |
| 1669 | ipmb_seq, broadcast, |
| 1670 | source_address, source_lun); |
| 1671 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1672 | /* |
| 1673 | * Copy the message into the recv message data, so we |
| 1674 | * can retransmit it later if necessary. |
| 1675 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | memcpy(recv_msg->msg_data, smi_msg->data, |
| 1677 | smi_msg->data_size); |
| 1678 | recv_msg->msg.data = recv_msg->msg_data; |
| 1679 | recv_msg->msg.data_len = smi_msg->data_size; |
| 1680 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1681 | /* |
| 1682 | * We don't unlock until here, because we need |
| 1683 | * to copy the completed message into the |
| 1684 | * recv_msg before we release the lock. |
| 1685 | * Otherwise, race conditions may bite us. I |
| 1686 | * know that's pretty paranoid, but I prefer |
| 1687 | * to be correct. |
| 1688 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
| 1690 | } |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 1691 | } else if (is_lan_addr(addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | struct ipmi_lan_addr *lan_addr; |
| 1693 | unsigned char ipmb_seq; |
| 1694 | long seqid; |
| 1695 | |
Jayachandran C | 12fc1d7 | 2006-02-03 03:04:51 -0800 | [diff] [blame] | 1696 | if (addr->channel >= IPMI_MAX_CHANNELS) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1697 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | rv = -EINVAL; |
| 1699 | goto out_err; |
| 1700 | } |
| 1701 | |
| 1702 | if ((intf->channels[addr->channel].medium |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1703 | != IPMI_CHANNEL_MEDIUM_8023LAN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1704 | && (intf->channels[addr->channel].medium |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1705 | != IPMI_CHANNEL_MEDIUM_ASYNC)) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1706 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | rv = -EINVAL; |
| 1708 | goto out_err; |
| 1709 | } |
| 1710 | |
| 1711 | retries = 4; |
| 1712 | |
| 1713 | /* Default to 1 second retries. */ |
| 1714 | if (retry_time_ms == 0) |
| 1715 | retry_time_ms = 1000; |
| 1716 | |
| 1717 | /* 11 for the header and 1 for the checksum. */ |
| 1718 | if ((msg->data_len + 12) > IPMI_MAX_MSG_LENGTH) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1719 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | rv = -EMSGSIZE; |
| 1721 | goto out_err; |
| 1722 | } |
| 1723 | |
| 1724 | lan_addr = (struct ipmi_lan_addr *) addr; |
| 1725 | if (lan_addr->lun > 3) { |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1726 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1727 | rv = -EINVAL; |
| 1728 | goto out_err; |
| 1729 | } |
| 1730 | |
| 1731 | memcpy(&recv_msg->addr, lan_addr, sizeof(*lan_addr)); |
| 1732 | |
| 1733 | if (recv_msg->msg.netfn & 0x1) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1734 | /* |
| 1735 | * It's a response, so use the user's sequence |
| 1736 | * from msgid. |
| 1737 | */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1738 | ipmi_inc_stat(intf, sent_lan_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | format_lan_msg(smi_msg, msg, lan_addr, msgid, |
| 1740 | msgid, source_lun); |
| 1741 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1742 | /* |
| 1743 | * Save the receive message so we can use it |
| 1744 | * to deliver the response. |
| 1745 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | smi_msg->user_data = recv_msg; |
| 1747 | } else { |
| 1748 | /* It's a command, so get a sequence for it. */ |
| 1749 | |
| 1750 | spin_lock_irqsave(&(intf->seq_lock), flags); |
| 1751 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1752 | /* |
| 1753 | * Create a sequence number with a 1 second |
| 1754 | * timeout and 4 retries. |
| 1755 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | rv = intf_next_seq(intf, |
| 1757 | recv_msg, |
| 1758 | retry_time_ms, |
| 1759 | retries, |
| 1760 | 0, |
| 1761 | &ipmb_seq, |
| 1762 | &seqid); |
| 1763 | if (rv) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1764 | /* |
| 1765 | * We have used up all the sequence numbers, |
| 1766 | * probably, so abort. |
| 1767 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | spin_unlock_irqrestore(&(intf->seq_lock), |
| 1769 | flags); |
| 1770 | goto out_err; |
| 1771 | } |
| 1772 | |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 1773 | ipmi_inc_stat(intf, sent_lan_commands); |
| 1774 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1775 | /* |
| 1776 | * Store the sequence number in the message, |
| 1777 | * so that when the send message response |
| 1778 | * comes back we can start the timer. |
| 1779 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | format_lan_msg(smi_msg, msg, lan_addr, |
| 1781 | STORE_SEQ_IN_MSGID(ipmb_seq, seqid), |
| 1782 | ipmb_seq, source_lun); |
| 1783 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1784 | /* |
| 1785 | * Copy the message into the recv message data, so we |
| 1786 | * can retransmit it later if necessary. |
| 1787 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | memcpy(recv_msg->msg_data, smi_msg->data, |
| 1789 | smi_msg->data_size); |
| 1790 | recv_msg->msg.data = recv_msg->msg_data; |
| 1791 | recv_msg->msg.data_len = smi_msg->data_size; |
| 1792 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1793 | /* |
| 1794 | * We don't unlock until here, because we need |
| 1795 | * to copy the completed message into the |
| 1796 | * recv_msg before we release the lock. |
| 1797 | * Otherwise, race conditions may bite us. I |
| 1798 | * know that's pretty paranoid, but I prefer |
| 1799 | * to be correct. |
| 1800 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
| 1802 | } |
| 1803 | } else { |
| 1804 | /* Unknown address type. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 1805 | ipmi_inc_stat(intf, sent_invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1806 | rv = -EINVAL; |
| 1807 | goto out_err; |
| 1808 | } |
| 1809 | |
| 1810 | #ifdef DEBUG_MSGING |
| 1811 | { |
| 1812 | int m; |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 1813 | for (m = 0; m < smi_msg->data_size; m++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | printk(" %2.2x", smi_msg->data[m]); |
| 1815 | printk("\n"); |
| 1816 | } |
| 1817 | #endif |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1818 | |
| 1819 | handlers->sender(intf->send_info, smi_msg, priority); |
| 1820 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | |
| 1822 | return 0; |
| 1823 | |
| 1824 | out_err: |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 1825 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | ipmi_free_smi_msg(smi_msg); |
| 1827 | ipmi_free_recv_msg(recv_msg); |
| 1828 | return rv; |
| 1829 | } |
| 1830 | |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1831 | static int check_addr(ipmi_smi_t intf, |
| 1832 | struct ipmi_addr *addr, |
| 1833 | unsigned char *saddr, |
| 1834 | unsigned char *lun) |
| 1835 | { |
| 1836 | if (addr->channel >= IPMI_MAX_CHANNELS) |
| 1837 | return -EINVAL; |
| 1838 | *lun = intf->channels[addr->channel].lun; |
| 1839 | *saddr = intf->channels[addr->channel].address; |
| 1840 | return 0; |
| 1841 | } |
| 1842 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | int ipmi_request_settime(ipmi_user_t user, |
| 1844 | struct ipmi_addr *addr, |
| 1845 | long msgid, |
| 1846 | struct kernel_ipmi_msg *msg, |
| 1847 | void *user_msg_data, |
| 1848 | int priority, |
| 1849 | int retries, |
| 1850 | unsigned int retry_time_ms) |
| 1851 | { |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1852 | unsigned char saddr, lun; |
| 1853 | int rv; |
| 1854 | |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 1855 | if (!user) |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 1856 | return -EINVAL; |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1857 | rv = check_addr(user->intf, addr, &saddr, &lun); |
| 1858 | if (rv) |
| 1859 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | return i_ipmi_request(user, |
| 1861 | user->intf, |
| 1862 | addr, |
| 1863 | msgid, |
| 1864 | msg, |
| 1865 | user_msg_data, |
| 1866 | NULL, NULL, |
| 1867 | priority, |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1868 | saddr, |
| 1869 | lun, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | retries, |
| 1871 | retry_time_ms); |
| 1872 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1873 | EXPORT_SYMBOL(ipmi_request_settime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | |
| 1875 | int ipmi_request_supply_msgs(ipmi_user_t user, |
| 1876 | struct ipmi_addr *addr, |
| 1877 | long msgid, |
| 1878 | struct kernel_ipmi_msg *msg, |
| 1879 | void *user_msg_data, |
| 1880 | void *supplied_smi, |
| 1881 | struct ipmi_recv_msg *supplied_recv, |
| 1882 | int priority) |
| 1883 | { |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1884 | unsigned char saddr, lun; |
| 1885 | int rv; |
| 1886 | |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 1887 | if (!user) |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 1888 | return -EINVAL; |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1889 | rv = check_addr(user->intf, addr, &saddr, &lun); |
| 1890 | if (rv) |
| 1891 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | return i_ipmi_request(user, |
| 1893 | user->intf, |
| 1894 | addr, |
| 1895 | msgid, |
| 1896 | msg, |
| 1897 | user_msg_data, |
| 1898 | supplied_smi, |
| 1899 | supplied_recv, |
| 1900 | priority, |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1901 | saddr, |
| 1902 | lun, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | -1, 0); |
| 1904 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 1905 | EXPORT_SYMBOL(ipmi_request_supply_msgs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | |
Randy Dunlap | 1aa16ee | 2006-12-06 20:41:20 -0800 | [diff] [blame] | 1907 | #ifdef CONFIG_PROC_FS |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1908 | static int smi_ipmb_proc_show(struct seq_file *m, void *v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1909 | { |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1910 | ipmi_smi_t intf = m->private; |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 1911 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1913 | seq_printf(m, "%x", intf->channels[0].address); |
| 1914 | for (i = 1; i < IPMI_MAX_CHANNELS; i++) |
| 1915 | seq_printf(m, " %x", intf->channels[i].address); |
| 1916 | return seq_putc(m, '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1919 | static int smi_ipmb_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | { |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1921 | return single_open(file, smi_ipmb_proc_show, PDE(inode)->data); |
| 1922 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1924 | static const struct file_operations smi_ipmb_proc_ops = { |
| 1925 | .open = smi_ipmb_proc_open, |
| 1926 | .read = seq_read, |
| 1927 | .llseek = seq_lseek, |
| 1928 | .release = single_release, |
| 1929 | }; |
| 1930 | |
| 1931 | static int smi_version_proc_show(struct seq_file *m, void *v) |
| 1932 | { |
| 1933 | ipmi_smi_t intf = m->private; |
| 1934 | |
| 1935 | return seq_printf(m, "%u.%u\n", |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 1936 | ipmi_version_major(&intf->bmc->id), |
| 1937 | ipmi_version_minor(&intf->bmc->id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1940 | static int smi_version_proc_open(struct inode *inode, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | { |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1942 | return single_open(file, smi_version_proc_show, PDE(inode)->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1943 | } |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 1944 | |
| 1945 | static const struct file_operations smi_version_proc_ops = { |
| 1946 | .open = smi_version_proc_open, |
| 1947 | .read = seq_read, |
| 1948 | .llseek = seq_lseek, |
| 1949 | .release = single_release, |
| 1950 | }; |
| 1951 | |
| 1952 | static int smi_stats_proc_show(struct seq_file *m, void *v) |
| 1953 | { |
| 1954 | ipmi_smi_t intf = m->private; |
| 1955 | |
| 1956 | seq_printf(m, "sent_invalid_commands: %u\n", |
| 1957 | ipmi_get_stat(intf, sent_invalid_commands)); |
| 1958 | seq_printf(m, "sent_local_commands: %u\n", |
| 1959 | ipmi_get_stat(intf, sent_local_commands)); |
| 1960 | seq_printf(m, "handled_local_responses: %u\n", |
| 1961 | ipmi_get_stat(intf, handled_local_responses)); |
| 1962 | seq_printf(m, "unhandled_local_responses: %u\n", |
| 1963 | ipmi_get_stat(intf, unhandled_local_responses)); |
| 1964 | seq_printf(m, "sent_ipmb_commands: %u\n", |
| 1965 | ipmi_get_stat(intf, sent_ipmb_commands)); |
| 1966 | seq_printf(m, "sent_ipmb_command_errs: %u\n", |
| 1967 | ipmi_get_stat(intf, sent_ipmb_command_errs)); |
| 1968 | seq_printf(m, "retransmitted_ipmb_commands: %u\n", |
| 1969 | ipmi_get_stat(intf, retransmitted_ipmb_commands)); |
| 1970 | seq_printf(m, "timed_out_ipmb_commands: %u\n", |
| 1971 | ipmi_get_stat(intf, timed_out_ipmb_commands)); |
| 1972 | seq_printf(m, "timed_out_ipmb_broadcasts: %u\n", |
| 1973 | ipmi_get_stat(intf, timed_out_ipmb_broadcasts)); |
| 1974 | seq_printf(m, "sent_ipmb_responses: %u\n", |
| 1975 | ipmi_get_stat(intf, sent_ipmb_responses)); |
| 1976 | seq_printf(m, "handled_ipmb_responses: %u\n", |
| 1977 | ipmi_get_stat(intf, handled_ipmb_responses)); |
| 1978 | seq_printf(m, "invalid_ipmb_responses: %u\n", |
| 1979 | ipmi_get_stat(intf, invalid_ipmb_responses)); |
| 1980 | seq_printf(m, "unhandled_ipmb_responses: %u\n", |
| 1981 | ipmi_get_stat(intf, unhandled_ipmb_responses)); |
| 1982 | seq_printf(m, "sent_lan_commands: %u\n", |
| 1983 | ipmi_get_stat(intf, sent_lan_commands)); |
| 1984 | seq_printf(m, "sent_lan_command_errs: %u\n", |
| 1985 | ipmi_get_stat(intf, sent_lan_command_errs)); |
| 1986 | seq_printf(m, "retransmitted_lan_commands: %u\n", |
| 1987 | ipmi_get_stat(intf, retransmitted_lan_commands)); |
| 1988 | seq_printf(m, "timed_out_lan_commands: %u\n", |
| 1989 | ipmi_get_stat(intf, timed_out_lan_commands)); |
| 1990 | seq_printf(m, "sent_lan_responses: %u\n", |
| 1991 | ipmi_get_stat(intf, sent_lan_responses)); |
| 1992 | seq_printf(m, "handled_lan_responses: %u\n", |
| 1993 | ipmi_get_stat(intf, handled_lan_responses)); |
| 1994 | seq_printf(m, "invalid_lan_responses: %u\n", |
| 1995 | ipmi_get_stat(intf, invalid_lan_responses)); |
| 1996 | seq_printf(m, "unhandled_lan_responses: %u\n", |
| 1997 | ipmi_get_stat(intf, unhandled_lan_responses)); |
| 1998 | seq_printf(m, "handled_commands: %u\n", |
| 1999 | ipmi_get_stat(intf, handled_commands)); |
| 2000 | seq_printf(m, "invalid_commands: %u\n", |
| 2001 | ipmi_get_stat(intf, invalid_commands)); |
| 2002 | seq_printf(m, "unhandled_commands: %u\n", |
| 2003 | ipmi_get_stat(intf, unhandled_commands)); |
| 2004 | seq_printf(m, "invalid_events: %u\n", |
| 2005 | ipmi_get_stat(intf, invalid_events)); |
| 2006 | seq_printf(m, "events: %u\n", |
| 2007 | ipmi_get_stat(intf, events)); |
| 2008 | seq_printf(m, "failed rexmit LAN msgs: %u\n", |
| 2009 | ipmi_get_stat(intf, dropped_rexmit_lan_commands)); |
| 2010 | seq_printf(m, "failed rexmit IPMB msgs: %u\n", |
| 2011 | ipmi_get_stat(intf, dropped_rexmit_ipmb_commands)); |
| 2012 | return 0; |
| 2013 | } |
| 2014 | |
| 2015 | static int smi_stats_proc_open(struct inode *inode, struct file *file) |
| 2016 | { |
| 2017 | return single_open(file, smi_stats_proc_show, PDE(inode)->data); |
| 2018 | } |
| 2019 | |
| 2020 | static const struct file_operations smi_stats_proc_ops = { |
| 2021 | .open = smi_stats_proc_open, |
| 2022 | .read = seq_read, |
| 2023 | .llseek = seq_lseek, |
| 2024 | .release = single_release, |
| 2025 | }; |
Randy Dunlap | 1aa16ee | 2006-12-06 20:41:20 -0800 | [diff] [blame] | 2026 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2027 | |
| 2028 | int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 2029 | const struct file_operations *proc_ops, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 2030 | void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2031 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | int rv = 0; |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 2033 | #ifdef CONFIG_PROC_FS |
| 2034 | struct proc_dir_entry *file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2035 | struct ipmi_proc_entry *entry; |
| 2036 | |
| 2037 | /* Create a list element. */ |
| 2038 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
| 2039 | if (!entry) |
| 2040 | return -ENOMEM; |
| 2041 | entry->name = kmalloc(strlen(name)+1, GFP_KERNEL); |
| 2042 | if (!entry->name) { |
| 2043 | kfree(entry); |
| 2044 | return -ENOMEM; |
| 2045 | } |
| 2046 | strcpy(entry->name, name); |
| 2047 | |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 2048 | file = proc_create_data(name, 0, smi->proc_dir, proc_ops, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2049 | if (!file) { |
| 2050 | kfree(entry->name); |
| 2051 | kfree(entry); |
| 2052 | rv = -ENOMEM; |
| 2053 | } else { |
Corey Minyard | ac01915 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 2054 | mutex_lock(&smi->proc_entry_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | /* Stick it on the list. */ |
| 2056 | entry->next = smi->proc_entries; |
| 2057 | smi->proc_entries = entry; |
Corey Minyard | ac01915 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 2058 | mutex_unlock(&smi->proc_entry_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | } |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 2060 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | |
| 2062 | return rv; |
| 2063 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2064 | EXPORT_SYMBOL(ipmi_smi_add_proc_entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | |
| 2066 | static int add_proc_entries(ipmi_smi_t smi, int num) |
| 2067 | { |
| 2068 | int rv = 0; |
| 2069 | |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 2070 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | sprintf(smi->proc_dir_name, "%d", num); |
| 2072 | smi->proc_dir = proc_mkdir(smi->proc_dir_name, proc_ipmi_root); |
| 2073 | if (!smi->proc_dir) |
| 2074 | rv = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | |
| 2076 | if (rv == 0) |
| 2077 | rv = ipmi_smi_add_proc_entry(smi, "stats", |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 2078 | &smi_stats_proc_ops, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 2079 | smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | |
| 2081 | if (rv == 0) |
| 2082 | rv = ipmi_smi_add_proc_entry(smi, "ipmb", |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 2083 | &smi_ipmb_proc_ops, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 2084 | smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | |
| 2086 | if (rv == 0) |
| 2087 | rv = ipmi_smi_add_proc_entry(smi, "version", |
Alexey Dobriyan | 0741273 | 2011-05-26 16:25:55 -0700 | [diff] [blame] | 2088 | &smi_version_proc_ops, |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 2089 | smi); |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 2090 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | |
| 2092 | return rv; |
| 2093 | } |
| 2094 | |
| 2095 | static void remove_proc_entries(ipmi_smi_t smi) |
| 2096 | { |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 2097 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | struct ipmi_proc_entry *entry; |
| 2099 | |
Corey Minyard | ac01915 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 2100 | mutex_lock(&smi->proc_entry_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | while (smi->proc_entries) { |
| 2102 | entry = smi->proc_entries; |
| 2103 | smi->proc_entries = entry->next; |
| 2104 | |
| 2105 | remove_proc_entry(entry->name, smi->proc_dir); |
| 2106 | kfree(entry->name); |
| 2107 | kfree(entry); |
| 2108 | } |
Corey Minyard | ac01915 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 2109 | mutex_unlock(&smi->proc_entry_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | remove_proc_entry(smi->proc_dir_name, proc_ipmi_root); |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 2111 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2114 | static int __find_bmc_guid(struct device *dev, void *data) |
| 2115 | { |
| 2116 | unsigned char *id = data; |
| 2117 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2118 | return memcmp(bmc->guid, id, 16) == 0; |
| 2119 | } |
| 2120 | |
| 2121 | static struct bmc_device *ipmi_find_bmc_guid(struct device_driver *drv, |
| 2122 | unsigned char *guid) |
| 2123 | { |
| 2124 | struct device *dev; |
| 2125 | |
| 2126 | dev = driver_find_device(drv, NULL, guid, __find_bmc_guid); |
| 2127 | if (dev) |
| 2128 | return dev_get_drvdata(dev); |
| 2129 | else |
| 2130 | return NULL; |
| 2131 | } |
| 2132 | |
| 2133 | struct prod_dev_id { |
| 2134 | unsigned int product_id; |
| 2135 | unsigned char device_id; |
| 2136 | }; |
| 2137 | |
| 2138 | static int __find_bmc_prod_dev_id(struct device *dev, void *data) |
| 2139 | { |
| 2140 | struct prod_dev_id *id = data; |
| 2141 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2142 | |
| 2143 | return (bmc->id.product_id == id->product_id |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2144 | && bmc->id.device_id == id->device_id); |
| 2145 | } |
| 2146 | |
| 2147 | static struct bmc_device *ipmi_find_bmc_prod_dev_id( |
| 2148 | struct device_driver *drv, |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2149 | unsigned int product_id, unsigned char device_id) |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2150 | { |
| 2151 | struct prod_dev_id id = { |
| 2152 | .product_id = product_id, |
| 2153 | .device_id = device_id, |
| 2154 | }; |
| 2155 | struct device *dev; |
| 2156 | |
| 2157 | dev = driver_find_device(drv, NULL, &id, __find_bmc_prod_dev_id); |
| 2158 | if (dev) |
| 2159 | return dev_get_drvdata(dev); |
| 2160 | else |
| 2161 | return NULL; |
| 2162 | } |
| 2163 | |
| 2164 | static ssize_t device_id_show(struct device *dev, |
| 2165 | struct device_attribute *attr, |
| 2166 | char *buf) |
| 2167 | { |
| 2168 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2169 | |
| 2170 | return snprintf(buf, 10, "%u\n", bmc->id.device_id); |
| 2171 | } |
| 2172 | |
| 2173 | static ssize_t provides_dev_sdrs_show(struct device *dev, |
| 2174 | struct device_attribute *attr, |
| 2175 | char *buf) |
| 2176 | { |
| 2177 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2178 | |
| 2179 | return snprintf(buf, 10, "%u\n", |
Corey Minyard | 7947d2c | 2006-11-10 12:27:50 -0800 | [diff] [blame] | 2180 | (bmc->id.device_revision & 0x80) >> 7); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2181 | } |
| 2182 | |
| 2183 | static ssize_t revision_show(struct device *dev, struct device_attribute *attr, |
| 2184 | char *buf) |
| 2185 | { |
| 2186 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2187 | |
| 2188 | return snprintf(buf, 20, "%u\n", |
Corey Minyard | 7947d2c | 2006-11-10 12:27:50 -0800 | [diff] [blame] | 2189 | bmc->id.device_revision & 0x0F); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2190 | } |
| 2191 | |
| 2192 | static ssize_t firmware_rev_show(struct device *dev, |
| 2193 | struct device_attribute *attr, |
| 2194 | char *buf) |
| 2195 | { |
| 2196 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2197 | |
| 2198 | return snprintf(buf, 20, "%u.%x\n", bmc->id.firmware_revision_1, |
| 2199 | bmc->id.firmware_revision_2); |
| 2200 | } |
| 2201 | |
| 2202 | static ssize_t ipmi_version_show(struct device *dev, |
| 2203 | struct device_attribute *attr, |
| 2204 | char *buf) |
| 2205 | { |
| 2206 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2207 | |
| 2208 | return snprintf(buf, 20, "%u.%u\n", |
| 2209 | ipmi_version_major(&bmc->id), |
| 2210 | ipmi_version_minor(&bmc->id)); |
| 2211 | } |
| 2212 | |
| 2213 | static ssize_t add_dev_support_show(struct device *dev, |
| 2214 | struct device_attribute *attr, |
| 2215 | char *buf) |
| 2216 | { |
| 2217 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2218 | |
| 2219 | return snprintf(buf, 10, "0x%02x\n", |
| 2220 | bmc->id.additional_device_support); |
| 2221 | } |
| 2222 | |
| 2223 | static ssize_t manufacturer_id_show(struct device *dev, |
| 2224 | struct device_attribute *attr, |
| 2225 | char *buf) |
| 2226 | { |
| 2227 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2228 | |
| 2229 | return snprintf(buf, 20, "0x%6.6x\n", bmc->id.manufacturer_id); |
| 2230 | } |
| 2231 | |
| 2232 | static ssize_t product_id_show(struct device *dev, |
| 2233 | struct device_attribute *attr, |
| 2234 | char *buf) |
| 2235 | { |
| 2236 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2237 | |
| 2238 | return snprintf(buf, 10, "0x%4.4x\n", bmc->id.product_id); |
| 2239 | } |
| 2240 | |
| 2241 | static ssize_t aux_firmware_rev_show(struct device *dev, |
| 2242 | struct device_attribute *attr, |
| 2243 | char *buf) |
| 2244 | { |
| 2245 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2246 | |
| 2247 | return snprintf(buf, 21, "0x%02x 0x%02x 0x%02x 0x%02x\n", |
| 2248 | bmc->id.aux_firmware_revision[3], |
| 2249 | bmc->id.aux_firmware_revision[2], |
| 2250 | bmc->id.aux_firmware_revision[1], |
| 2251 | bmc->id.aux_firmware_revision[0]); |
| 2252 | } |
| 2253 | |
| 2254 | static ssize_t guid_show(struct device *dev, struct device_attribute *attr, |
| 2255 | char *buf) |
| 2256 | { |
| 2257 | struct bmc_device *bmc = dev_get_drvdata(dev); |
| 2258 | |
| 2259 | return snprintf(buf, 100, "%Lx%Lx\n", |
| 2260 | (long long) bmc->guid[0], |
| 2261 | (long long) bmc->guid[8]); |
| 2262 | } |
| 2263 | |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2264 | static void remove_files(struct bmc_device *bmc) |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2265 | { |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2266 | if (!bmc->dev) |
| 2267 | return; |
| 2268 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2269 | device_remove_file(&bmc->dev->dev, |
| 2270 | &bmc->device_id_attr); |
| 2271 | device_remove_file(&bmc->dev->dev, |
| 2272 | &bmc->provides_dev_sdrs_attr); |
| 2273 | device_remove_file(&bmc->dev->dev, |
| 2274 | &bmc->revision_attr); |
| 2275 | device_remove_file(&bmc->dev->dev, |
| 2276 | &bmc->firmware_rev_attr); |
| 2277 | device_remove_file(&bmc->dev->dev, |
| 2278 | &bmc->version_attr); |
| 2279 | device_remove_file(&bmc->dev->dev, |
| 2280 | &bmc->add_dev_support_attr); |
| 2281 | device_remove_file(&bmc->dev->dev, |
| 2282 | &bmc->manufacturer_id_attr); |
| 2283 | device_remove_file(&bmc->dev->dev, |
| 2284 | &bmc->product_id_attr); |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2285 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2286 | if (bmc->id.aux_firmware_revision_set) |
| 2287 | device_remove_file(&bmc->dev->dev, |
| 2288 | &bmc->aux_firmware_rev_attr); |
| 2289 | if (bmc->guid_set) |
| 2290 | device_remove_file(&bmc->dev->dev, |
| 2291 | &bmc->guid_attr); |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | static void |
| 2295 | cleanup_bmc_device(struct kref *ref) |
| 2296 | { |
| 2297 | struct bmc_device *bmc; |
| 2298 | |
| 2299 | bmc = container_of(ref, struct bmc_device, refcount); |
| 2300 | |
| 2301 | remove_files(bmc); |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 2302 | platform_device_unregister(bmc->dev); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2303 | kfree(bmc); |
| 2304 | } |
| 2305 | |
| 2306 | static void ipmi_bmc_unregister(ipmi_smi_t intf) |
| 2307 | { |
| 2308 | struct bmc_device *bmc = intf->bmc; |
| 2309 | |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2310 | if (intf->sysfs_name) { |
| 2311 | sysfs_remove_link(&intf->si_dev->kobj, intf->sysfs_name); |
| 2312 | kfree(intf->sysfs_name); |
| 2313 | intf->sysfs_name = NULL; |
| 2314 | } |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2315 | if (intf->my_dev_name) { |
| 2316 | sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name); |
| 2317 | kfree(intf->my_dev_name); |
| 2318 | intf->my_dev_name = NULL; |
| 2319 | } |
| 2320 | |
| 2321 | mutex_lock(&ipmidriver_mutex); |
| 2322 | kref_put(&bmc->refcount, cleanup_bmc_device); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2323 | intf->bmc = NULL; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2324 | mutex_unlock(&ipmidriver_mutex); |
| 2325 | } |
| 2326 | |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2327 | static int create_files(struct bmc_device *bmc) |
| 2328 | { |
| 2329 | int err; |
| 2330 | |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2331 | bmc->device_id_attr.attr.name = "device_id"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2332 | bmc->device_id_attr.attr.mode = S_IRUGO; |
| 2333 | bmc->device_id_attr.show = device_id_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2334 | sysfs_attr_init(&bmc->device_id_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2335 | |
| 2336 | bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2337 | bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; |
| 2338 | bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2339 | sysfs_attr_init(&bmc->provides_dev_sdrs_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2340 | |
| 2341 | bmc->revision_attr.attr.name = "revision"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2342 | bmc->revision_attr.attr.mode = S_IRUGO; |
| 2343 | bmc->revision_attr.show = revision_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2344 | sysfs_attr_init(&bmc->revision_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2345 | |
| 2346 | bmc->firmware_rev_attr.attr.name = "firmware_revision"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2347 | bmc->firmware_rev_attr.attr.mode = S_IRUGO; |
| 2348 | bmc->firmware_rev_attr.show = firmware_rev_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2349 | sysfs_attr_init(&bmc->firmware_rev_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2350 | |
| 2351 | bmc->version_attr.attr.name = "ipmi_version"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2352 | bmc->version_attr.attr.mode = S_IRUGO; |
| 2353 | bmc->version_attr.show = ipmi_version_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2354 | sysfs_attr_init(&bmc->version_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2355 | |
| 2356 | bmc->add_dev_support_attr.attr.name = "additional_device_support"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2357 | bmc->add_dev_support_attr.attr.mode = S_IRUGO; |
| 2358 | bmc->add_dev_support_attr.show = add_dev_support_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2359 | sysfs_attr_init(&bmc->add_dev_support_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2360 | |
| 2361 | bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2362 | bmc->manufacturer_id_attr.attr.mode = S_IRUGO; |
| 2363 | bmc->manufacturer_id_attr.show = manufacturer_id_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2364 | sysfs_attr_init(&bmc->manufacturer_id_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2365 | |
| 2366 | bmc->product_id_attr.attr.name = "product_id"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2367 | bmc->product_id_attr.attr.mode = S_IRUGO; |
| 2368 | bmc->product_id_attr.show = product_id_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2369 | sysfs_attr_init(&bmc->product_id_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2370 | |
| 2371 | bmc->guid_attr.attr.name = "guid"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2372 | bmc->guid_attr.attr.mode = S_IRUGO; |
| 2373 | bmc->guid_attr.show = guid_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2374 | sysfs_attr_init(&bmc->guid_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2375 | |
| 2376 | bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2377 | bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; |
| 2378 | bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; |
Greg Kroah-Hartman | c7df670 | 2010-03-15 13:59:51 -0700 | [diff] [blame] | 2379 | sysfs_attr_init(&bmc->aux_firmware_rev_attr.attr); |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2380 | |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2381 | err = device_create_file(&bmc->dev->dev, |
| 2382 | &bmc->device_id_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2383 | if (err) |
| 2384 | goto out; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2385 | err = device_create_file(&bmc->dev->dev, |
| 2386 | &bmc->provides_dev_sdrs_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2387 | if (err) |
| 2388 | goto out_devid; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2389 | err = device_create_file(&bmc->dev->dev, |
| 2390 | &bmc->revision_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2391 | if (err) |
| 2392 | goto out_sdrs; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2393 | err = device_create_file(&bmc->dev->dev, |
| 2394 | &bmc->firmware_rev_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2395 | if (err) |
| 2396 | goto out_rev; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2397 | err = device_create_file(&bmc->dev->dev, |
| 2398 | &bmc->version_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2399 | if (err) |
| 2400 | goto out_firm; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2401 | err = device_create_file(&bmc->dev->dev, |
| 2402 | &bmc->add_dev_support_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2403 | if (err) |
| 2404 | goto out_version; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2405 | err = device_create_file(&bmc->dev->dev, |
| 2406 | &bmc->manufacturer_id_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2407 | if (err) |
| 2408 | goto out_add_dev; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2409 | err = device_create_file(&bmc->dev->dev, |
| 2410 | &bmc->product_id_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2411 | if (err) |
| 2412 | goto out_manu; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2413 | if (bmc->id.aux_firmware_revision_set) { |
| 2414 | err = device_create_file(&bmc->dev->dev, |
| 2415 | &bmc->aux_firmware_rev_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2416 | if (err) |
| 2417 | goto out_prod_id; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2418 | } |
| 2419 | if (bmc->guid_set) { |
| 2420 | err = device_create_file(&bmc->dev->dev, |
| 2421 | &bmc->guid_attr); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2422 | if (err) |
| 2423 | goto out_aux_firm; |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | return 0; |
| 2427 | |
| 2428 | out_aux_firm: |
| 2429 | if (bmc->id.aux_firmware_revision_set) |
| 2430 | device_remove_file(&bmc->dev->dev, |
| 2431 | &bmc->aux_firmware_rev_attr); |
| 2432 | out_prod_id: |
| 2433 | device_remove_file(&bmc->dev->dev, |
| 2434 | &bmc->product_id_attr); |
| 2435 | out_manu: |
| 2436 | device_remove_file(&bmc->dev->dev, |
| 2437 | &bmc->manufacturer_id_attr); |
| 2438 | out_add_dev: |
| 2439 | device_remove_file(&bmc->dev->dev, |
| 2440 | &bmc->add_dev_support_attr); |
| 2441 | out_version: |
| 2442 | device_remove_file(&bmc->dev->dev, |
| 2443 | &bmc->version_attr); |
| 2444 | out_firm: |
| 2445 | device_remove_file(&bmc->dev->dev, |
| 2446 | &bmc->firmware_rev_attr); |
| 2447 | out_rev: |
| 2448 | device_remove_file(&bmc->dev->dev, |
| 2449 | &bmc->revision_attr); |
| 2450 | out_sdrs: |
| 2451 | device_remove_file(&bmc->dev->dev, |
| 2452 | &bmc->provides_dev_sdrs_attr); |
| 2453 | out_devid: |
| 2454 | device_remove_file(&bmc->dev->dev, |
| 2455 | &bmc->device_id_attr); |
| 2456 | out: |
| 2457 | return err; |
| 2458 | } |
| 2459 | |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2460 | static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, |
| 2461 | const char *sysfs_name) |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2462 | { |
| 2463 | int rv; |
| 2464 | struct bmc_device *bmc = intf->bmc; |
| 2465 | struct bmc_device *old_bmc; |
| 2466 | int size; |
| 2467 | char dummy[1]; |
| 2468 | |
| 2469 | mutex_lock(&ipmidriver_mutex); |
| 2470 | |
| 2471 | /* |
| 2472 | * Try to find if there is an bmc_device struct |
| 2473 | * representing the interfaced BMC already |
| 2474 | */ |
| 2475 | if (bmc->guid_set) |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 2476 | old_bmc = ipmi_find_bmc_guid(&ipmidriver.driver, bmc->guid); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2477 | else |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 2478 | old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2479 | bmc->id.product_id, |
| 2480 | bmc->id.device_id); |
| 2481 | |
| 2482 | /* |
| 2483 | * If there is already an bmc_device, free the new one, |
| 2484 | * otherwise register the new BMC device |
| 2485 | */ |
| 2486 | if (old_bmc) { |
| 2487 | kfree(bmc); |
| 2488 | intf->bmc = old_bmc; |
| 2489 | bmc = old_bmc; |
| 2490 | |
| 2491 | kref_get(&bmc->refcount); |
| 2492 | mutex_unlock(&ipmidriver_mutex); |
| 2493 | |
| 2494 | printk(KERN_INFO |
| 2495 | "ipmi: interfacing existing BMC (man_id: 0x%6.6x," |
| 2496 | " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", |
| 2497 | bmc->id.manufacturer_id, |
| 2498 | bmc->id.product_id, |
| 2499 | bmc->id.device_id); |
| 2500 | } else { |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2501 | char name[14]; |
| 2502 | unsigned char orig_dev_id = bmc->id.device_id; |
| 2503 | int warn_printed = 0; |
| 2504 | |
| 2505 | snprintf(name, sizeof(name), |
| 2506 | "ipmi_bmc.%4.4x", bmc->id.product_id); |
| 2507 | |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 2508 | while (ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2509 | bmc->id.product_id, |
Corey Minyard | 1d5636c | 2006-12-10 02:19:08 -0800 | [diff] [blame] | 2510 | bmc->id.device_id)) { |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2511 | if (!warn_printed) { |
| 2512 | printk(KERN_WARNING PFX |
| 2513 | "This machine has two different BMCs" |
| 2514 | " with the same product id and device" |
| 2515 | " id. This is an error in the" |
| 2516 | " firmware, but incrementing the" |
| 2517 | " device id to work around the problem." |
| 2518 | " Prod ID = 0x%x, Dev ID = 0x%x\n", |
| 2519 | bmc->id.product_id, bmc->id.device_id); |
| 2520 | warn_printed = 1; |
| 2521 | } |
| 2522 | bmc->id.device_id++; /* Wraps at 255 */ |
| 2523 | if (bmc->id.device_id == orig_dev_id) { |
| 2524 | printk(KERN_ERR PFX |
| 2525 | "Out of device ids!\n"); |
| 2526 | break; |
| 2527 | } |
| 2528 | } |
| 2529 | |
| 2530 | bmc->dev = platform_device_alloc(name, bmc->id.device_id); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 2531 | if (!bmc->dev) { |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2532 | mutex_unlock(&ipmidriver_mutex); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2533 | printk(KERN_ERR |
| 2534 | "ipmi_msghandler:" |
| 2535 | " Unable to allocate platform device\n"); |
| 2536 | return -ENOMEM; |
| 2537 | } |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 2538 | bmc->dev->dev.driver = &ipmidriver.driver; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2539 | dev_set_drvdata(&bmc->dev->dev, bmc); |
| 2540 | kref_init(&bmc->refcount); |
| 2541 | |
Zhang, Yanmin | b48f545 | 2006-11-16 01:19:08 -0800 | [diff] [blame] | 2542 | rv = platform_device_add(bmc->dev); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2543 | mutex_unlock(&ipmidriver_mutex); |
| 2544 | if (rv) { |
Corey Minyard | f0b55da | 2006-12-06 20:40:54 -0800 | [diff] [blame] | 2545 | platform_device_put(bmc->dev); |
| 2546 | bmc->dev = NULL; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2547 | printk(KERN_ERR |
| 2548 | "ipmi_msghandler:" |
| 2549 | " Unable to register bmc device: %d\n", |
| 2550 | rv); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2551 | /* |
| 2552 | * Don't go to out_err, you can only do that if |
| 2553 | * the device is registered already. |
| 2554 | */ |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2555 | return rv; |
| 2556 | } |
| 2557 | |
Jeff Garzik | 5e59393 | 2006-10-11 01:22:21 -0700 | [diff] [blame] | 2558 | rv = create_files(bmc); |
| 2559 | if (rv) { |
| 2560 | mutex_lock(&ipmidriver_mutex); |
| 2561 | platform_device_unregister(bmc->dev); |
| 2562 | mutex_unlock(&ipmidriver_mutex); |
| 2563 | |
| 2564 | return rv; |
| 2565 | } |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2566 | |
Myron Stowe | 279fbd0 | 2010-05-26 14:43:52 -0700 | [diff] [blame] | 2567 | dev_info(intf->si_dev, "Found new BMC (man_id: 0x%6.6x, " |
| 2568 | "prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", |
| 2569 | bmc->id.manufacturer_id, |
| 2570 | bmc->id.product_id, |
| 2571 | bmc->id.device_id); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | /* |
| 2575 | * create symlink from system interface device to bmc device |
| 2576 | * and back. |
| 2577 | */ |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2578 | intf->sysfs_name = kstrdup(sysfs_name, GFP_KERNEL); |
| 2579 | if (!intf->sysfs_name) { |
| 2580 | rv = -ENOMEM; |
| 2581 | printk(KERN_ERR |
| 2582 | "ipmi_msghandler: allocate link to BMC: %d\n", |
| 2583 | rv); |
| 2584 | goto out_err; |
| 2585 | } |
| 2586 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2587 | rv = sysfs_create_link(&intf->si_dev->kobj, |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2588 | &bmc->dev->dev.kobj, intf->sysfs_name); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2589 | if (rv) { |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2590 | kfree(intf->sysfs_name); |
| 2591 | intf->sysfs_name = NULL; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2592 | printk(KERN_ERR |
| 2593 | "ipmi_msghandler: Unable to create bmc symlink: %d\n", |
| 2594 | rv); |
| 2595 | goto out_err; |
| 2596 | } |
| 2597 | |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2598 | size = snprintf(dummy, 0, "ipmi%d", ifnum); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2599 | intf->my_dev_name = kmalloc(size+1, GFP_KERNEL); |
| 2600 | if (!intf->my_dev_name) { |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2601 | kfree(intf->sysfs_name); |
| 2602 | intf->sysfs_name = NULL; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2603 | rv = -ENOMEM; |
| 2604 | printk(KERN_ERR |
| 2605 | "ipmi_msghandler: allocate link from BMC: %d\n", |
| 2606 | rv); |
| 2607 | goto out_err; |
| 2608 | } |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2609 | snprintf(intf->my_dev_name, size+1, "ipmi%d", ifnum); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2610 | |
| 2611 | rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj, |
| 2612 | intf->my_dev_name); |
| 2613 | if (rv) { |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2614 | kfree(intf->sysfs_name); |
| 2615 | intf->sysfs_name = NULL; |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2616 | kfree(intf->my_dev_name); |
| 2617 | intf->my_dev_name = NULL; |
| 2618 | printk(KERN_ERR |
| 2619 | "ipmi_msghandler:" |
| 2620 | " Unable to create symlink to bmc: %d\n", |
| 2621 | rv); |
| 2622 | goto out_err; |
| 2623 | } |
| 2624 | |
| 2625 | return 0; |
| 2626 | |
| 2627 | out_err: |
| 2628 | ipmi_bmc_unregister(intf); |
| 2629 | return rv; |
| 2630 | } |
| 2631 | |
| 2632 | static int |
| 2633 | send_guid_cmd(ipmi_smi_t intf, int chan) |
| 2634 | { |
| 2635 | struct kernel_ipmi_msg msg; |
| 2636 | struct ipmi_system_interface_addr si; |
| 2637 | |
| 2638 | si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
| 2639 | si.channel = IPMI_BMC_CHANNEL; |
| 2640 | si.lun = 0; |
| 2641 | |
| 2642 | msg.netfn = IPMI_NETFN_APP_REQUEST; |
| 2643 | msg.cmd = IPMI_GET_DEVICE_GUID_CMD; |
| 2644 | msg.data = NULL; |
| 2645 | msg.data_len = 0; |
| 2646 | return i_ipmi_request(NULL, |
| 2647 | intf, |
| 2648 | (struct ipmi_addr *) &si, |
| 2649 | 0, |
| 2650 | &msg, |
| 2651 | intf, |
| 2652 | NULL, |
| 2653 | NULL, |
| 2654 | 0, |
| 2655 | intf->channels[0].address, |
| 2656 | intf->channels[0].lun, |
| 2657 | -1, 0); |
| 2658 | } |
| 2659 | |
| 2660 | static void |
| 2661 | guid_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
| 2662 | { |
| 2663 | if ((msg->addr.addr_type != IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
| 2664 | || (msg->msg.netfn != IPMI_NETFN_APP_RESPONSE) |
| 2665 | || (msg->msg.cmd != IPMI_GET_DEVICE_GUID_CMD)) |
| 2666 | /* Not for me */ |
| 2667 | return; |
| 2668 | |
| 2669 | if (msg->msg.data[0] != 0) { |
| 2670 | /* Error from getting the GUID, the BMC doesn't have one. */ |
| 2671 | intf->bmc->guid_set = 0; |
| 2672 | goto out; |
| 2673 | } |
| 2674 | |
| 2675 | if (msg->msg.data_len < 17) { |
| 2676 | intf->bmc->guid_set = 0; |
| 2677 | printk(KERN_WARNING PFX |
| 2678 | "guid_handler: The GUID response from the BMC was too" |
| 2679 | " short, it was %d but should have been 17. Assuming" |
| 2680 | " GUID is not available.\n", |
| 2681 | msg->msg.data_len); |
| 2682 | goto out; |
| 2683 | } |
| 2684 | |
| 2685 | memcpy(intf->bmc->guid, msg->msg.data, 16); |
| 2686 | intf->bmc->guid_set = 1; |
| 2687 | out: |
| 2688 | wake_up(&intf->waitq); |
| 2689 | } |
| 2690 | |
| 2691 | static void |
| 2692 | get_guid(ipmi_smi_t intf) |
| 2693 | { |
| 2694 | int rv; |
| 2695 | |
| 2696 | intf->bmc->guid_set = 0x2; |
| 2697 | intf->null_user_handler = guid_handler; |
| 2698 | rv = send_guid_cmd(intf, 0); |
| 2699 | if (rv) |
| 2700 | /* Send failed, no GUID available. */ |
| 2701 | intf->bmc->guid_set = 0; |
| 2702 | wait_event(intf->waitq, intf->bmc->guid_set != 2); |
| 2703 | intf->null_user_handler = NULL; |
| 2704 | } |
| 2705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | static int |
| 2707 | send_channel_info_cmd(ipmi_smi_t intf, int chan) |
| 2708 | { |
| 2709 | struct kernel_ipmi_msg msg; |
| 2710 | unsigned char data[1]; |
| 2711 | struct ipmi_system_interface_addr si; |
| 2712 | |
| 2713 | si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
| 2714 | si.channel = IPMI_BMC_CHANNEL; |
| 2715 | si.lun = 0; |
| 2716 | |
| 2717 | msg.netfn = IPMI_NETFN_APP_REQUEST; |
| 2718 | msg.cmd = IPMI_GET_CHANNEL_INFO_CMD; |
| 2719 | msg.data = data; |
| 2720 | msg.data_len = 1; |
| 2721 | data[0] = chan; |
| 2722 | return i_ipmi_request(NULL, |
| 2723 | intf, |
| 2724 | (struct ipmi_addr *) &si, |
| 2725 | 0, |
| 2726 | &msg, |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 2727 | intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | NULL, |
| 2729 | NULL, |
| 2730 | 0, |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 2731 | intf->channels[0].address, |
| 2732 | intf->channels[0].lun, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | -1, 0); |
| 2734 | } |
| 2735 | |
| 2736 | static void |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 2737 | channel_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | { |
| 2739 | int rv = 0; |
| 2740 | int chan; |
| 2741 | |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 2742 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
| 2743 | && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2744 | && (msg->msg.cmd == IPMI_GET_CHANNEL_INFO_CMD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | /* It's the one we want */ |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 2746 | if (msg->msg.data[0] != 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | /* Got an error from the channel, just go on. */ |
| 2748 | |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 2749 | if (msg->msg.data[0] == IPMI_INVALID_COMMAND_ERR) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2750 | /* |
| 2751 | * If the MC does not support this |
| 2752 | * command, that is legal. We just |
| 2753 | * assume it has one IPMB at channel |
| 2754 | * zero. |
| 2755 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | intf->channels[0].medium |
| 2757 | = IPMI_CHANNEL_MEDIUM_IPMB; |
| 2758 | intf->channels[0].protocol |
| 2759 | = IPMI_CHANNEL_PROTOCOL_IPMB; |
| 2760 | rv = -ENOSYS; |
| 2761 | |
| 2762 | intf->curr_channel = IPMI_MAX_CHANNELS; |
| 2763 | wake_up(&intf->waitq); |
| 2764 | goto out; |
| 2765 | } |
| 2766 | goto next_channel; |
| 2767 | } |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 2768 | if (msg->msg.data_len < 4) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | /* Message not big enough, just go on. */ |
| 2770 | goto next_channel; |
| 2771 | } |
| 2772 | chan = intf->curr_channel; |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 2773 | intf->channels[chan].medium = msg->msg.data[2] & 0x7f; |
| 2774 | intf->channels[chan].protocol = msg->msg.data[3] & 0x1f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2776 | next_channel: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | intf->curr_channel++; |
| 2778 | if (intf->curr_channel >= IPMI_MAX_CHANNELS) |
| 2779 | wake_up(&intf->waitq); |
| 2780 | else |
| 2781 | rv = send_channel_info_cmd(intf, intf->curr_channel); |
| 2782 | |
| 2783 | if (rv) { |
| 2784 | /* Got an error somehow, just give up. */ |
| 2785 | intf->curr_channel = IPMI_MAX_CHANNELS; |
| 2786 | wake_up(&intf->waitq); |
| 2787 | |
| 2788 | printk(KERN_WARNING PFX |
| 2789 | "Error sending channel information: %d\n", |
| 2790 | rv); |
| 2791 | } |
| 2792 | } |
| 2793 | out: |
| 2794 | return; |
| 2795 | } |
| 2796 | |
Corey Minyard | fcfa472 | 2007-10-18 03:07:09 -0700 | [diff] [blame] | 2797 | void ipmi_poll_interface(ipmi_user_t user) |
| 2798 | { |
| 2799 | ipmi_smi_t intf = user->intf; |
| 2800 | |
| 2801 | if (intf->handlers->poll) |
| 2802 | intf->handlers->poll(intf->send_info); |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 2803 | |
| 2804 | /* In case something came in */ |
| 2805 | handle_new_recv_msgs(intf); |
Corey Minyard | fcfa472 | 2007-10-18 03:07:09 -0700 | [diff] [blame] | 2806 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2807 | EXPORT_SYMBOL(ipmi_poll_interface); |
Corey Minyard | fcfa472 | 2007-10-18 03:07:09 -0700 | [diff] [blame] | 2808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2809 | int ipmi_register_smi(struct ipmi_smi_handlers *handlers, |
| 2810 | void *send_info, |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2811 | struct ipmi_device_id *device_id, |
| 2812 | struct device *si_dev, |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2813 | const char *sysfs_name, |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 2814 | unsigned char slave_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2815 | { |
| 2816 | int i, j; |
| 2817 | int rv; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2818 | ipmi_smi_t intf; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2819 | ipmi_smi_t tintf; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2820 | struct list_head *link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2822 | /* |
| 2823 | * Make sure the driver is actually initialized, this handles |
| 2824 | * problems with initialization order. |
| 2825 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | if (!initialized) { |
| 2827 | rv = ipmi_init_msghandler(); |
| 2828 | if (rv) |
| 2829 | return rv; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2830 | /* |
| 2831 | * The init code doesn't return an error if it was turned |
| 2832 | * off, but it won't initialize. Check that. |
| 2833 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2834 | if (!initialized) |
| 2835 | return -ENODEV; |
| 2836 | } |
| 2837 | |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 2838 | intf = kzalloc(sizeof(*intf), GFP_KERNEL); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2839 | if (!intf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | return -ENOMEM; |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2841 | |
| 2842 | intf->ipmi_version_major = ipmi_version_major(device_id); |
| 2843 | intf->ipmi_version_minor = ipmi_version_minor(device_id); |
| 2844 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2845 | intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL); |
| 2846 | if (!intf->bmc) { |
| 2847 | kfree(intf); |
| 2848 | return -ENOMEM; |
| 2849 | } |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2850 | intf->intf_num = -1; /* Mark it invalid for now. */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2851 | kref_init(&intf->refcount); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2852 | intf->bmc->id = *device_id; |
| 2853 | intf->si_dev = si_dev; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2854 | for (j = 0; j < IPMI_MAX_CHANNELS; j++) { |
| 2855 | intf->channels[j].address = IPMI_BMC_SLAVE_ADDR; |
| 2856 | intf->channels[j].lun = 2; |
| 2857 | } |
| 2858 | if (slave_addr != 0) |
| 2859 | intf->channels[0].address = slave_addr; |
| 2860 | INIT_LIST_HEAD(&intf->users); |
| 2861 | intf->handlers = handlers; |
| 2862 | intf->send_info = send_info; |
| 2863 | spin_lock_init(&intf->seq_lock); |
| 2864 | for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) { |
| 2865 | intf->seq_table[j].inuse = 0; |
| 2866 | intf->seq_table[j].seqid = 0; |
| 2867 | } |
| 2868 | intf->curr_seq = 0; |
| 2869 | #ifdef CONFIG_PROC_FS |
Corey Minyard | ac01915 | 2007-10-18 03:07:11 -0700 | [diff] [blame] | 2870 | mutex_init(&intf->proc_entry_lock); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2871 | #endif |
| 2872 | spin_lock_init(&intf->waiting_msgs_lock); |
| 2873 | INIT_LIST_HEAD(&intf->waiting_msgs); |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 2874 | tasklet_init(&intf->recv_tasklet, |
| 2875 | smi_recv_tasklet, |
| 2876 | (unsigned long) intf); |
| 2877 | atomic_set(&intf->watchdog_pretimeouts_to_deliver, 0); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2878 | spin_lock_init(&intf->events_lock); |
| 2879 | INIT_LIST_HEAD(&intf->waiting_events); |
| 2880 | intf->waiting_events_count = 0; |
Corey Minyard | d6dfd13 | 2006-03-31 02:30:41 -0800 | [diff] [blame] | 2881 | mutex_init(&intf->cmd_rcvrs_mutex); |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 2882 | spin_lock_init(&intf->maintenance_mode_lock); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2883 | INIT_LIST_HEAD(&intf->cmd_rcvrs); |
| 2884 | init_waitqueue_head(&intf->waitq); |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 2885 | for (i = 0; i < IPMI_NUM_STATS; i++) |
| 2886 | atomic_set(&intf->stats[i], 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2887 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2888 | intf->proc_dir = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2890 | mutex_lock(&smi_watchers_mutex); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2891 | mutex_lock(&ipmi_interfaces_mutex); |
| 2892 | /* Look for a hole in the numbers. */ |
| 2893 | i = 0; |
| 2894 | link = &ipmi_interfaces; |
| 2895 | list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { |
| 2896 | if (tintf->intf_num != i) { |
| 2897 | link = &tintf->link; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | break; |
| 2899 | } |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2900 | i++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | } |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2902 | /* Add the new interface in numeric order. */ |
| 2903 | if (i == 0) |
| 2904 | list_add_rcu(&intf->link, &ipmi_interfaces); |
| 2905 | else |
| 2906 | list_add_tail_rcu(&intf->link, link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | |
Corey Minyard | 453823b | 2006-03-31 02:30:39 -0800 | [diff] [blame] | 2908 | rv = handlers->start_processing(send_info, intf); |
| 2909 | if (rv) |
| 2910 | goto out; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2911 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2912 | get_guid(intf); |
| 2913 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2914 | if ((intf->ipmi_version_major > 1) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2915 | || ((intf->ipmi_version_major == 1) |
| 2916 | && (intf->ipmi_version_minor >= 5))) { |
| 2917 | /* |
| 2918 | * Start scanning the channels to see what is |
| 2919 | * available. |
| 2920 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2921 | intf->null_user_handler = channel_handler; |
| 2922 | intf->curr_channel = 0; |
| 2923 | rv = send_channel_info_cmd(intf, 0); |
| 2924 | if (rv) |
| 2925 | goto out; |
| 2926 | |
| 2927 | /* Wait for the channel info to be read. */ |
| 2928 | wait_event(intf->waitq, |
| 2929 | intf->curr_channel >= IPMI_MAX_CHANNELS); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2930 | intf->null_user_handler = NULL; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2931 | } else { |
| 2932 | /* Assume a single IPMB channel at zero. */ |
| 2933 | intf->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB; |
| 2934 | intf->channels[0].protocol = IPMI_CHANNEL_PROTOCOL_IPMB; |
Corey Minyard | 9a2845c | 2009-05-20 13:36:17 -0500 | [diff] [blame] | 2935 | intf->curr_channel = IPMI_MAX_CHANNELS; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2936 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | |
| 2938 | if (rv == 0) |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2939 | rv = add_proc_entries(intf, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2940 | |
Corey Minyard | 759643b | 2006-12-06 20:40:59 -0800 | [diff] [blame] | 2941 | rv = ipmi_bmc_register(intf, i, sysfs_name); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2942 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2943 | out: |
| 2944 | if (rv) { |
| 2945 | if (intf->proc_dir) |
| 2946 | remove_proc_entries(intf); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2947 | intf->handlers = NULL; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2948 | list_del_rcu(&intf->link); |
| 2949 | mutex_unlock(&ipmi_interfaces_mutex); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2950 | mutex_unlock(&smi_watchers_mutex); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2951 | synchronize_rcu(); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2952 | kref_put(&intf->refcount, intf_free); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 2953 | } else { |
Corey Minyard | 78ba2fa | 2007-02-10 01:45:45 -0800 | [diff] [blame] | 2954 | /* |
| 2955 | * Keep memory order straight for RCU readers. Make |
| 2956 | * sure everything else is committed to memory before |
| 2957 | * setting intf_num to mark the interface valid. |
| 2958 | */ |
| 2959 | smp_wmb(); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2960 | intf->intf_num = i; |
| 2961 | mutex_unlock(&ipmi_interfaces_mutex); |
Corey Minyard | 78ba2fa | 2007-02-10 01:45:45 -0800 | [diff] [blame] | 2962 | /* After this point the interface is legal to use. */ |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2963 | call_smi_watchers(i, intf->si_dev); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2964 | mutex_unlock(&smi_watchers_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | return rv; |
| 2968 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 2969 | EXPORT_SYMBOL(ipmi_register_smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2971 | static void cleanup_smi_msgs(ipmi_smi_t intf) |
| 2972 | { |
| 2973 | int i; |
| 2974 | struct seq_table *ent; |
| 2975 | |
| 2976 | /* No need for locks, the interface is down. */ |
| 2977 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { |
| 2978 | ent = &(intf->seq_table[i]); |
| 2979 | if (!ent->inuse) |
| 2980 | continue; |
| 2981 | deliver_err_response(ent->recv_msg, IPMI_ERR_UNSPECIFIED); |
| 2982 | } |
| 2983 | } |
| 2984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | int ipmi_unregister_smi(ipmi_smi_t intf) |
| 2986 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2987 | struct ipmi_smi_watcher *w; |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2988 | int intf_num = intf->intf_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 2990 | ipmi_bmc_unregister(intf); |
| 2991 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2992 | mutex_lock(&smi_watchers_mutex); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2993 | mutex_lock(&ipmi_interfaces_mutex); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 2994 | intf->intf_num = -1; |
| 2995 | intf->handlers = NULL; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 2996 | list_del_rcu(&intf->link); |
| 2997 | mutex_unlock(&ipmi_interfaces_mutex); |
| 2998 | synchronize_rcu(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 3000 | cleanup_smi_msgs(intf); |
| 3001 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3002 | remove_proc_entries(intf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3004 | /* |
| 3005 | * Call all the watcher interfaces to tell them that |
| 3006 | * an interface is gone. |
| 3007 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3008 | list_for_each_entry(w, &smi_watchers, link) |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 3009 | w->smi_gone(intf_num); |
| 3010 | mutex_unlock(&smi_watchers_mutex); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3011 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3012 | kref_put(&intf->refcount, intf_free); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | return 0; |
| 3014 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3015 | EXPORT_SYMBOL(ipmi_unregister_smi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | |
| 3017 | static int handle_ipmb_get_msg_rsp(ipmi_smi_t intf, |
| 3018 | struct ipmi_smi_msg *msg) |
| 3019 | { |
| 3020 | struct ipmi_ipmb_addr ipmb_addr; |
| 3021 | struct ipmi_recv_msg *recv_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3023 | /* |
| 3024 | * This is 11, not 10, because the response must contain a |
| 3025 | * completion code. |
| 3026 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | if (msg->rsp_size < 11) { |
| 3028 | /* Message not big enough, just ignore it. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3029 | ipmi_inc_stat(intf, invalid_ipmb_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3030 | return 0; |
| 3031 | } |
| 3032 | |
| 3033 | if (msg->rsp[2] != 0) { |
| 3034 | /* An error getting the response, just ignore it. */ |
| 3035 | return 0; |
| 3036 | } |
| 3037 | |
| 3038 | ipmb_addr.addr_type = IPMI_IPMB_ADDR_TYPE; |
| 3039 | ipmb_addr.slave_addr = msg->rsp[6]; |
| 3040 | ipmb_addr.channel = msg->rsp[3] & 0x0f; |
| 3041 | ipmb_addr.lun = msg->rsp[7] & 3; |
| 3042 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3043 | /* |
| 3044 | * It's a response from a remote entity. Look up the sequence |
| 3045 | * number and handle the response. |
| 3046 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3047 | if (intf_find_seq(intf, |
| 3048 | msg->rsp[7] >> 2, |
| 3049 | msg->rsp[3] & 0x0f, |
| 3050 | msg->rsp[8], |
| 3051 | (msg->rsp[4] >> 2) & (~1), |
| 3052 | (struct ipmi_addr *) &(ipmb_addr), |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3053 | &recv_msg)) { |
| 3054 | /* |
| 3055 | * We were unable to find the sequence number, |
| 3056 | * so just nuke the message. |
| 3057 | */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3058 | ipmi_inc_stat(intf, unhandled_ipmb_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | return 0; |
| 3060 | } |
| 3061 | |
| 3062 | memcpy(recv_msg->msg_data, |
| 3063 | &(msg->rsp[9]), |
| 3064 | msg->rsp_size - 9); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3065 | /* |
| 3066 | * The other fields matched, so no need to set them, except |
| 3067 | * for netfn, which needs to be the response that was |
| 3068 | * returned, not the request value. |
| 3069 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3070 | recv_msg->msg.netfn = msg->rsp[4] >> 2; |
| 3071 | recv_msg->msg.data = recv_msg->msg_data; |
| 3072 | recv_msg->msg.data_len = msg->rsp_size - 10; |
| 3073 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3074 | ipmi_inc_stat(intf, handled_ipmb_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3075 | deliver_response(recv_msg); |
| 3076 | |
| 3077 | return 0; |
| 3078 | } |
| 3079 | |
| 3080 | static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf, |
| 3081 | struct ipmi_smi_msg *msg) |
| 3082 | { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3083 | struct cmd_rcvr *rcvr; |
| 3084 | int rv = 0; |
| 3085 | unsigned char netfn; |
| 3086 | unsigned char cmd; |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 3087 | unsigned char chan; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3088 | ipmi_user_t user = NULL; |
| 3089 | struct ipmi_ipmb_addr *ipmb_addr; |
| 3090 | struct ipmi_recv_msg *recv_msg; |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 3091 | struct ipmi_smi_handlers *handlers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | |
| 3093 | if (msg->rsp_size < 10) { |
| 3094 | /* Message not big enough, just ignore it. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3095 | ipmi_inc_stat(intf, invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3096 | return 0; |
| 3097 | } |
| 3098 | |
| 3099 | if (msg->rsp[2] != 0) { |
| 3100 | /* An error getting the response, just ignore it. */ |
| 3101 | return 0; |
| 3102 | } |
| 3103 | |
| 3104 | netfn = msg->rsp[4] >> 2; |
| 3105 | cmd = msg->rsp[8]; |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 3106 | chan = msg->rsp[3] & 0xf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | |
Corey Minyard | e61fb5b | 2005-11-07 01:00:05 -0800 | [diff] [blame] | 3108 | rcu_read_lock(); |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 3109 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3110 | if (rcvr) { |
| 3111 | user = rcvr->user; |
| 3112 | kref_get(&user->refcount); |
| 3113 | } else |
| 3114 | user = NULL; |
Corey Minyard | e61fb5b | 2005-11-07 01:00:05 -0800 | [diff] [blame] | 3115 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3116 | |
| 3117 | if (user == NULL) { |
| 3118 | /* We didn't find a user, deliver an error response. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3119 | ipmi_inc_stat(intf, unhandled_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | |
| 3121 | msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
| 3122 | msg->data[1] = IPMI_SEND_MSG_CMD; |
| 3123 | msg->data[2] = msg->rsp[3]; |
| 3124 | msg->data[3] = msg->rsp[6]; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3125 | msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | msg->data[5] = ipmb_checksum(&(msg->data[3]), 2); |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 3127 | msg->data[6] = intf->channels[msg->rsp[3] & 0xf].address; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3128 | /* rqseq/lun */ |
| 3129 | msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | msg->data[8] = msg->rsp[8]; /* cmd */ |
| 3131 | msg->data[9] = IPMI_INVALID_CMD_COMPLETION_CODE; |
| 3132 | msg->data[10] = ipmb_checksum(&(msg->data[6]), 4); |
| 3133 | msg->data_size = 11; |
| 3134 | |
| 3135 | #ifdef DEBUG_MSGING |
| 3136 | { |
| 3137 | int m; |
| 3138 | printk("Invalid command:"); |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 3139 | for (m = 0; m < msg->data_size; m++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | printk(" %2.2x", msg->data[m]); |
| 3141 | printk("\n"); |
| 3142 | } |
| 3143 | #endif |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 3144 | rcu_read_lock(); |
| 3145 | handlers = intf->handlers; |
| 3146 | if (handlers) { |
| 3147 | handlers->sender(intf->send_info, msg, 0); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3148 | /* |
| 3149 | * We used the message, so return the value |
| 3150 | * that causes it to not be freed or |
| 3151 | * queued. |
| 3152 | */ |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 3153 | rv = -1; |
| 3154 | } |
| 3155 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3156 | } else { |
| 3157 | /* Deliver the message to the user. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3158 | ipmi_inc_stat(intf, handled_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | |
| 3160 | recv_msg = ipmi_alloc_recv_msg(); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 3161 | if (!recv_msg) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3162 | /* |
| 3163 | * We couldn't allocate memory for the |
| 3164 | * message, so requeue it for handling |
| 3165 | * later. |
| 3166 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | rv = 1; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3168 | kref_put(&user->refcount, free_user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3169 | } else { |
| 3170 | /* Extract the source address from the data. */ |
| 3171 | ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr; |
| 3172 | ipmb_addr->addr_type = IPMI_IPMB_ADDR_TYPE; |
| 3173 | ipmb_addr->slave_addr = msg->rsp[6]; |
| 3174 | ipmb_addr->lun = msg->rsp[7] & 3; |
| 3175 | ipmb_addr->channel = msg->rsp[3] & 0xf; |
| 3176 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3177 | /* |
| 3178 | * Extract the rest of the message information |
| 3179 | * from the IPMB header. |
| 3180 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3181 | recv_msg->user = user; |
| 3182 | recv_msg->recv_type = IPMI_CMD_RECV_TYPE; |
| 3183 | recv_msg->msgid = msg->rsp[7] >> 2; |
| 3184 | recv_msg->msg.netfn = msg->rsp[4] >> 2; |
| 3185 | recv_msg->msg.cmd = msg->rsp[8]; |
| 3186 | recv_msg->msg.data = recv_msg->msg_data; |
| 3187 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3188 | /* |
| 3189 | * We chop off 10, not 9 bytes because the checksum |
| 3190 | * at the end also needs to be removed. |
| 3191 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3192 | recv_msg->msg.data_len = msg->rsp_size - 10; |
| 3193 | memcpy(recv_msg->msg_data, |
| 3194 | &(msg->rsp[9]), |
| 3195 | msg->rsp_size - 10); |
| 3196 | deliver_response(recv_msg); |
| 3197 | } |
| 3198 | } |
| 3199 | |
| 3200 | return rv; |
| 3201 | } |
| 3202 | |
| 3203 | static int handle_lan_get_msg_rsp(ipmi_smi_t intf, |
| 3204 | struct ipmi_smi_msg *msg) |
| 3205 | { |
| 3206 | struct ipmi_lan_addr lan_addr; |
| 3207 | struct ipmi_recv_msg *recv_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | |
| 3209 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3210 | /* |
| 3211 | * This is 13, not 12, because the response must contain a |
| 3212 | * completion code. |
| 3213 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | if (msg->rsp_size < 13) { |
| 3215 | /* Message not big enough, just ignore it. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3216 | ipmi_inc_stat(intf, invalid_lan_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3217 | return 0; |
| 3218 | } |
| 3219 | |
| 3220 | if (msg->rsp[2] != 0) { |
| 3221 | /* An error getting the response, just ignore it. */ |
| 3222 | return 0; |
| 3223 | } |
| 3224 | |
| 3225 | lan_addr.addr_type = IPMI_LAN_ADDR_TYPE; |
| 3226 | lan_addr.session_handle = msg->rsp[4]; |
| 3227 | lan_addr.remote_SWID = msg->rsp[8]; |
| 3228 | lan_addr.local_SWID = msg->rsp[5]; |
| 3229 | lan_addr.channel = msg->rsp[3] & 0x0f; |
| 3230 | lan_addr.privilege = msg->rsp[3] >> 4; |
| 3231 | lan_addr.lun = msg->rsp[9] & 3; |
| 3232 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3233 | /* |
| 3234 | * It's a response from a remote entity. Look up the sequence |
| 3235 | * number and handle the response. |
| 3236 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3237 | if (intf_find_seq(intf, |
| 3238 | msg->rsp[9] >> 2, |
| 3239 | msg->rsp[3] & 0x0f, |
| 3240 | msg->rsp[10], |
| 3241 | (msg->rsp[6] >> 2) & (~1), |
| 3242 | (struct ipmi_addr *) &(lan_addr), |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3243 | &recv_msg)) { |
| 3244 | /* |
| 3245 | * We were unable to find the sequence number, |
| 3246 | * so just nuke the message. |
| 3247 | */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3248 | ipmi_inc_stat(intf, unhandled_lan_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | return 0; |
| 3250 | } |
| 3251 | |
| 3252 | memcpy(recv_msg->msg_data, |
| 3253 | &(msg->rsp[11]), |
| 3254 | msg->rsp_size - 11); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3255 | /* |
| 3256 | * The other fields matched, so no need to set them, except |
| 3257 | * for netfn, which needs to be the response that was |
| 3258 | * returned, not the request value. |
| 3259 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | recv_msg->msg.netfn = msg->rsp[6] >> 2; |
| 3261 | recv_msg->msg.data = recv_msg->msg_data; |
| 3262 | recv_msg->msg.data_len = msg->rsp_size - 12; |
| 3263 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3264 | ipmi_inc_stat(intf, handled_lan_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | deliver_response(recv_msg); |
| 3266 | |
| 3267 | return 0; |
| 3268 | } |
| 3269 | |
| 3270 | static int handle_lan_get_msg_cmd(ipmi_smi_t intf, |
| 3271 | struct ipmi_smi_msg *msg) |
| 3272 | { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3273 | struct cmd_rcvr *rcvr; |
| 3274 | int rv = 0; |
| 3275 | unsigned char netfn; |
| 3276 | unsigned char cmd; |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 3277 | unsigned char chan; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3278 | ipmi_user_t user = NULL; |
| 3279 | struct ipmi_lan_addr *lan_addr; |
| 3280 | struct ipmi_recv_msg *recv_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | |
| 3282 | if (msg->rsp_size < 12) { |
| 3283 | /* Message not big enough, just ignore it. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3284 | ipmi_inc_stat(intf, invalid_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3285 | return 0; |
| 3286 | } |
| 3287 | |
| 3288 | if (msg->rsp[2] != 0) { |
| 3289 | /* An error getting the response, just ignore it. */ |
| 3290 | return 0; |
| 3291 | } |
| 3292 | |
| 3293 | netfn = msg->rsp[6] >> 2; |
| 3294 | cmd = msg->rsp[10]; |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 3295 | chan = msg->rsp[3] & 0xf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | |
Corey Minyard | e61fb5b | 2005-11-07 01:00:05 -0800 | [diff] [blame] | 3297 | rcu_read_lock(); |
Corey Minyard | c69c312 | 2006-09-30 23:27:56 -0700 | [diff] [blame] | 3298 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3299 | if (rcvr) { |
| 3300 | user = rcvr->user; |
| 3301 | kref_get(&user->refcount); |
| 3302 | } else |
| 3303 | user = NULL; |
Corey Minyard | e61fb5b | 2005-11-07 01:00:05 -0800 | [diff] [blame] | 3304 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | |
| 3306 | if (user == NULL) { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3307 | /* We didn't find a user, just give up. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3308 | ipmi_inc_stat(intf, unhandled_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3310 | /* |
| 3311 | * Don't do anything with these messages, just allow |
| 3312 | * them to be freed. |
| 3313 | */ |
| 3314 | rv = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | } else { |
| 3316 | /* Deliver the message to the user. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3317 | ipmi_inc_stat(intf, handled_commands); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3318 | |
| 3319 | recv_msg = ipmi_alloc_recv_msg(); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 3320 | if (!recv_msg) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3321 | /* |
| 3322 | * We couldn't allocate memory for the |
| 3323 | * message, so requeue it for handling later. |
| 3324 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | rv = 1; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3326 | kref_put(&user->refcount, free_user); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | } else { |
| 3328 | /* Extract the source address from the data. */ |
| 3329 | lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr; |
| 3330 | lan_addr->addr_type = IPMI_LAN_ADDR_TYPE; |
| 3331 | lan_addr->session_handle = msg->rsp[4]; |
| 3332 | lan_addr->remote_SWID = msg->rsp[8]; |
| 3333 | lan_addr->local_SWID = msg->rsp[5]; |
| 3334 | lan_addr->lun = msg->rsp[9] & 3; |
| 3335 | lan_addr->channel = msg->rsp[3] & 0xf; |
| 3336 | lan_addr->privilege = msg->rsp[3] >> 4; |
| 3337 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3338 | /* |
| 3339 | * Extract the rest of the message information |
| 3340 | * from the IPMB header. |
| 3341 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | recv_msg->user = user; |
| 3343 | recv_msg->recv_type = IPMI_CMD_RECV_TYPE; |
| 3344 | recv_msg->msgid = msg->rsp[9] >> 2; |
| 3345 | recv_msg->msg.netfn = msg->rsp[6] >> 2; |
| 3346 | recv_msg->msg.cmd = msg->rsp[10]; |
| 3347 | recv_msg->msg.data = recv_msg->msg_data; |
| 3348 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3349 | /* |
| 3350 | * We chop off 12, not 11 bytes because the checksum |
| 3351 | * at the end also needs to be removed. |
| 3352 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3353 | recv_msg->msg.data_len = msg->rsp_size - 12; |
| 3354 | memcpy(recv_msg->msg_data, |
| 3355 | &(msg->rsp[11]), |
| 3356 | msg->rsp_size - 12); |
| 3357 | deliver_response(recv_msg); |
| 3358 | } |
| 3359 | } |
| 3360 | |
| 3361 | return rv; |
| 3362 | } |
| 3363 | |
dann frazier | 4dec302 | 2009-04-21 12:24:05 -0700 | [diff] [blame] | 3364 | /* |
| 3365 | * This routine will handle "Get Message" command responses with |
| 3366 | * channels that use an OEM Medium. The message format belongs to |
| 3367 | * the OEM. See IPMI 2.0 specification, Chapter 6 and |
| 3368 | * Chapter 22, sections 22.6 and 22.24 for more details. |
| 3369 | */ |
| 3370 | static int handle_oem_get_msg_cmd(ipmi_smi_t intf, |
| 3371 | struct ipmi_smi_msg *msg) |
| 3372 | { |
| 3373 | struct cmd_rcvr *rcvr; |
| 3374 | int rv = 0; |
| 3375 | unsigned char netfn; |
| 3376 | unsigned char cmd; |
| 3377 | unsigned char chan; |
| 3378 | ipmi_user_t user = NULL; |
| 3379 | struct ipmi_system_interface_addr *smi_addr; |
| 3380 | struct ipmi_recv_msg *recv_msg; |
| 3381 | |
| 3382 | /* |
| 3383 | * We expect the OEM SW to perform error checking |
| 3384 | * so we just do some basic sanity checks |
| 3385 | */ |
| 3386 | if (msg->rsp_size < 4) { |
| 3387 | /* Message not big enough, just ignore it. */ |
| 3388 | ipmi_inc_stat(intf, invalid_commands); |
| 3389 | return 0; |
| 3390 | } |
| 3391 | |
| 3392 | if (msg->rsp[2] != 0) { |
| 3393 | /* An error getting the response, just ignore it. */ |
| 3394 | return 0; |
| 3395 | } |
| 3396 | |
| 3397 | /* |
| 3398 | * This is an OEM Message so the OEM needs to know how |
| 3399 | * handle the message. We do no interpretation. |
| 3400 | */ |
| 3401 | netfn = msg->rsp[0] >> 2; |
| 3402 | cmd = msg->rsp[1]; |
| 3403 | chan = msg->rsp[3] & 0xf; |
| 3404 | |
| 3405 | rcu_read_lock(); |
| 3406 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); |
| 3407 | if (rcvr) { |
| 3408 | user = rcvr->user; |
| 3409 | kref_get(&user->refcount); |
| 3410 | } else |
| 3411 | user = NULL; |
| 3412 | rcu_read_unlock(); |
| 3413 | |
| 3414 | if (user == NULL) { |
| 3415 | /* We didn't find a user, just give up. */ |
| 3416 | ipmi_inc_stat(intf, unhandled_commands); |
| 3417 | |
| 3418 | /* |
| 3419 | * Don't do anything with these messages, just allow |
| 3420 | * them to be freed. |
| 3421 | */ |
| 3422 | |
| 3423 | rv = 0; |
| 3424 | } else { |
| 3425 | /* Deliver the message to the user. */ |
| 3426 | ipmi_inc_stat(intf, handled_commands); |
| 3427 | |
| 3428 | recv_msg = ipmi_alloc_recv_msg(); |
| 3429 | if (!recv_msg) { |
| 3430 | /* |
| 3431 | * We couldn't allocate memory for the |
| 3432 | * message, so requeue it for handling |
| 3433 | * later. |
| 3434 | */ |
| 3435 | rv = 1; |
| 3436 | kref_put(&user->refcount, free_user); |
| 3437 | } else { |
| 3438 | /* |
| 3439 | * OEM Messages are expected to be delivered via |
| 3440 | * the system interface to SMS software. We might |
| 3441 | * need to visit this again depending on OEM |
| 3442 | * requirements |
| 3443 | */ |
| 3444 | smi_addr = ((struct ipmi_system_interface_addr *) |
| 3445 | &(recv_msg->addr)); |
| 3446 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
| 3447 | smi_addr->channel = IPMI_BMC_CHANNEL; |
| 3448 | smi_addr->lun = msg->rsp[0] & 3; |
| 3449 | |
| 3450 | recv_msg->user = user; |
| 3451 | recv_msg->user_msg_data = NULL; |
| 3452 | recv_msg->recv_type = IPMI_OEM_RECV_TYPE; |
| 3453 | recv_msg->msg.netfn = msg->rsp[0] >> 2; |
| 3454 | recv_msg->msg.cmd = msg->rsp[1]; |
| 3455 | recv_msg->msg.data = recv_msg->msg_data; |
| 3456 | |
| 3457 | /* |
| 3458 | * The message starts at byte 4 which follows the |
| 3459 | * the Channel Byte in the "GET MESSAGE" command |
| 3460 | */ |
| 3461 | recv_msg->msg.data_len = msg->rsp_size - 4; |
| 3462 | memcpy(recv_msg->msg_data, |
| 3463 | &(msg->rsp[4]), |
| 3464 | msg->rsp_size - 4); |
| 3465 | deliver_response(recv_msg); |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | return rv; |
| 3470 | } |
| 3471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | static void copy_event_into_recv_msg(struct ipmi_recv_msg *recv_msg, |
| 3473 | struct ipmi_smi_msg *msg) |
| 3474 | { |
| 3475 | struct ipmi_system_interface_addr *smi_addr; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3476 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3477 | recv_msg->msgid = 0; |
| 3478 | smi_addr = (struct ipmi_system_interface_addr *) &(recv_msg->addr); |
| 3479 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
| 3480 | smi_addr->channel = IPMI_BMC_CHANNEL; |
| 3481 | smi_addr->lun = msg->rsp[0] & 3; |
| 3482 | recv_msg->recv_type = IPMI_ASYNC_EVENT_RECV_TYPE; |
| 3483 | recv_msg->msg.netfn = msg->rsp[0] >> 2; |
| 3484 | recv_msg->msg.cmd = msg->rsp[1]; |
| 3485 | memcpy(recv_msg->msg_data, &(msg->rsp[3]), msg->rsp_size - 3); |
| 3486 | recv_msg->msg.data = recv_msg->msg_data; |
| 3487 | recv_msg->msg.data_len = msg->rsp_size - 3; |
| 3488 | } |
| 3489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3490 | static int handle_read_event_rsp(ipmi_smi_t intf, |
| 3491 | struct ipmi_smi_msg *msg) |
| 3492 | { |
| 3493 | struct ipmi_recv_msg *recv_msg, *recv_msg2; |
| 3494 | struct list_head msgs; |
| 3495 | ipmi_user_t user; |
| 3496 | int rv = 0; |
| 3497 | int deliver_count = 0; |
| 3498 | unsigned long flags; |
| 3499 | |
| 3500 | if (msg->rsp_size < 19) { |
| 3501 | /* Message is too small to be an IPMB event. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3502 | ipmi_inc_stat(intf, invalid_events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3503 | return 0; |
| 3504 | } |
| 3505 | |
| 3506 | if (msg->rsp[2] != 0) { |
| 3507 | /* An error getting the event, just ignore it. */ |
| 3508 | return 0; |
| 3509 | } |
| 3510 | |
| 3511 | INIT_LIST_HEAD(&msgs); |
| 3512 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3513 | spin_lock_irqsave(&intf->events_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3514 | |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3515 | ipmi_inc_stat(intf, events); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3516 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3517 | /* |
| 3518 | * Allocate and fill in one message for every user that is |
| 3519 | * getting events. |
| 3520 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3521 | rcu_read_lock(); |
| 3522 | list_for_each_entry_rcu(user, &intf->users, link) { |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 3523 | if (!user->gets_events) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | continue; |
| 3525 | |
| 3526 | recv_msg = ipmi_alloc_recv_msg(); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 3527 | if (!recv_msg) { |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3528 | rcu_read_unlock(); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 3529 | list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, |
| 3530 | link) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | list_del(&recv_msg->link); |
| 3532 | ipmi_free_recv_msg(recv_msg); |
| 3533 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3534 | /* |
| 3535 | * We couldn't allocate memory for the |
| 3536 | * message, so requeue it for handling |
| 3537 | * later. |
| 3538 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3539 | rv = 1; |
| 3540 | goto out; |
| 3541 | } |
| 3542 | |
| 3543 | deliver_count++; |
| 3544 | |
| 3545 | copy_event_into_recv_msg(recv_msg, msg); |
| 3546 | recv_msg->user = user; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3547 | kref_get(&user->refcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3548 | list_add_tail(&(recv_msg->link), &msgs); |
| 3549 | } |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3550 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | |
| 3552 | if (deliver_count) { |
| 3553 | /* Now deliver all the messages. */ |
| 3554 | list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) { |
| 3555 | list_del(&recv_msg->link); |
| 3556 | deliver_response(recv_msg); |
| 3557 | } |
| 3558 | } else if (intf->waiting_events_count < MAX_EVENTS_IN_QUEUE) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3559 | /* |
| 3560 | * No one to receive the message, put it in queue if there's |
| 3561 | * not already too many things in the queue. |
| 3562 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3563 | recv_msg = ipmi_alloc_recv_msg(); |
Corey Minyard | 8a3628d | 2006-03-31 02:30:40 -0800 | [diff] [blame] | 3564 | if (!recv_msg) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3565 | /* |
| 3566 | * We couldn't allocate memory for the |
| 3567 | * message, so requeue it for handling |
| 3568 | * later. |
| 3569 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | rv = 1; |
| 3571 | goto out; |
| 3572 | } |
| 3573 | |
| 3574 | copy_event_into_recv_msg(recv_msg, msg); |
| 3575 | list_add_tail(&(recv_msg->link), &(intf->waiting_events)); |
Corey Minyard | 4791c03 | 2006-04-10 22:54:31 -0700 | [diff] [blame] | 3576 | intf->waiting_events_count++; |
Corey Minyard | 87ebd06 | 2008-04-29 01:01:04 -0700 | [diff] [blame] | 3577 | } else if (!intf->event_msg_printed) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3578 | /* |
| 3579 | * There's too many things in the queue, discard this |
| 3580 | * message. |
| 3581 | */ |
Corey Minyard | 87ebd06 | 2008-04-29 01:01:04 -0700 | [diff] [blame] | 3582 | printk(KERN_WARNING PFX "Event queue full, discarding" |
| 3583 | " incoming events\n"); |
| 3584 | intf->event_msg_printed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
| 3587 | out: |
| 3588 | spin_unlock_irqrestore(&(intf->events_lock), flags); |
| 3589 | |
| 3590 | return rv; |
| 3591 | } |
| 3592 | |
| 3593 | static int handle_bmc_rsp(ipmi_smi_t intf, |
| 3594 | struct ipmi_smi_msg *msg) |
| 3595 | { |
| 3596 | struct ipmi_recv_msg *recv_msg; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3597 | struct ipmi_user *user; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | |
| 3599 | recv_msg = (struct ipmi_recv_msg *) msg->user_data; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3600 | if (recv_msg == NULL) { |
| 3601 | printk(KERN_WARNING |
| 3602 | "IPMI message received with no owner. This\n" |
| 3603 | "could be because of a malformed message, or\n" |
| 3604 | "because of a hardware error. Contact your\n" |
| 3605 | "hardware vender for assistance\n"); |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 3606 | return 0; |
| 3607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3609 | user = recv_msg->user; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | /* Make sure the user still exists. */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3611 | if (user && !user->valid) { |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 3612 | /* The user for the message went away, so give up. */ |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3613 | ipmi_inc_stat(intf, unhandled_local_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | ipmi_free_recv_msg(recv_msg); |
| 3615 | } else { |
| 3616 | struct ipmi_system_interface_addr *smi_addr; |
| 3617 | |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3618 | ipmi_inc_stat(intf, handled_local_responses); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3619 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
| 3620 | recv_msg->msgid = msg->msgid; |
| 3621 | smi_addr = ((struct ipmi_system_interface_addr *) |
| 3622 | &(recv_msg->addr)); |
| 3623 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
| 3624 | smi_addr->channel = IPMI_BMC_CHANNEL; |
| 3625 | smi_addr->lun = msg->rsp[0] & 3; |
| 3626 | recv_msg->msg.netfn = msg->rsp[0] >> 2; |
| 3627 | recv_msg->msg.cmd = msg->rsp[1]; |
| 3628 | memcpy(recv_msg->msg_data, |
| 3629 | &(msg->rsp[2]), |
| 3630 | msg->rsp_size - 2); |
| 3631 | recv_msg->msg.data = recv_msg->msg_data; |
| 3632 | recv_msg->msg.data_len = msg->rsp_size - 2; |
| 3633 | deliver_response(recv_msg); |
| 3634 | } |
| 3635 | |
| 3636 | return 0; |
| 3637 | } |
| 3638 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3639 | /* |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 3640 | * Handle a received message. Return 1 if the message should be requeued, |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3641 | * 0 if the message should be freed, or -1 if the message should not |
| 3642 | * be freed or requeued. |
| 3643 | */ |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 3644 | static int handle_one_recv_msg(ipmi_smi_t intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3645 | struct ipmi_smi_msg *msg) |
| 3646 | { |
| 3647 | int requeue; |
| 3648 | int chan; |
| 3649 | |
| 3650 | #ifdef DEBUG_MSGING |
| 3651 | int m; |
| 3652 | printk("Recv:"); |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 3653 | for (m = 0; m < msg->rsp_size; m++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3654 | printk(" %2.2x", msg->rsp[m]); |
| 3655 | printk("\n"); |
| 3656 | #endif |
| 3657 | if (msg->rsp_size < 2) { |
| 3658 | /* Message is too small to be correct. */ |
| 3659 | printk(KERN_WARNING PFX "BMC returned to small a message" |
| 3660 | " for netfn %x cmd %x, got %d bytes\n", |
| 3661 | (msg->data[0] >> 2) | 1, msg->data[1], msg->rsp_size); |
| 3662 | |
| 3663 | /* Generate an error response for the message. */ |
| 3664 | msg->rsp[0] = msg->data[0] | (1 << 2); |
| 3665 | msg->rsp[1] = msg->data[1]; |
| 3666 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; |
| 3667 | msg->rsp_size = 3; |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3668 | } else if (((msg->rsp[0] >> 2) != ((msg->data[0] >> 2) | 1)) |
| 3669 | || (msg->rsp[1] != msg->data[1])) { |
| 3670 | /* |
| 3671 | * The NetFN and Command in the response is not even |
| 3672 | * marginally correct. |
| 3673 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3674 | printk(KERN_WARNING PFX "BMC returned incorrect response," |
| 3675 | " expected netfn %x cmd %x, got netfn %x cmd %x\n", |
| 3676 | (msg->data[0] >> 2) | 1, msg->data[1], |
| 3677 | msg->rsp[0] >> 2, msg->rsp[1]); |
| 3678 | |
| 3679 | /* Generate an error response for the message. */ |
| 3680 | msg->rsp[0] = msg->data[0] | (1 << 2); |
| 3681 | msg->rsp[1] = msg->data[1]; |
| 3682 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; |
| 3683 | msg->rsp_size = 3; |
| 3684 | } |
| 3685 | |
| 3686 | if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) |
| 3687 | && (msg->rsp[1] == IPMI_SEND_MSG_CMD) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3688 | && (msg->user_data != NULL)) { |
| 3689 | /* |
| 3690 | * It's a response to a response we sent. For this we |
| 3691 | * deliver a send message response to the user. |
| 3692 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3693 | struct ipmi_recv_msg *recv_msg = msg->user_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | |
| 3695 | requeue = 0; |
| 3696 | if (msg->rsp_size < 2) |
| 3697 | /* Message is too small to be correct. */ |
| 3698 | goto out; |
| 3699 | |
| 3700 | chan = msg->data[2] & 0x0f; |
| 3701 | if (chan >= IPMI_MAX_CHANNELS) |
| 3702 | /* Invalid channel number */ |
| 3703 | goto out; |
| 3704 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3705 | if (!recv_msg) |
| 3706 | goto out; |
| 3707 | |
| 3708 | /* Make sure the user still exists. */ |
| 3709 | if (!recv_msg->user || !recv_msg->user->valid) |
| 3710 | goto out; |
| 3711 | |
| 3712 | recv_msg->recv_type = IPMI_RESPONSE_RESPONSE_TYPE; |
| 3713 | recv_msg->msg.data = recv_msg->msg_data; |
| 3714 | recv_msg->msg.data_len = 1; |
| 3715 | recv_msg->msg_data[0] = msg->rsp[2]; |
| 3716 | deliver_response(recv_msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3718 | && (msg->rsp[1] == IPMI_GET_MSG_CMD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | /* It's from the receive queue. */ |
| 3720 | chan = msg->rsp[3] & 0xf; |
| 3721 | if (chan >= IPMI_MAX_CHANNELS) { |
| 3722 | /* Invalid channel number */ |
| 3723 | requeue = 0; |
| 3724 | goto out; |
| 3725 | } |
| 3726 | |
dann frazier | 4dec302 | 2009-04-21 12:24:05 -0700 | [diff] [blame] | 3727 | /* |
Corey Minyard | 9a2845c | 2009-05-20 13:36:17 -0500 | [diff] [blame] | 3728 | * We need to make sure the channels have been initialized. |
| 3729 | * The channel_handler routine will set the "curr_channel" |
| 3730 | * equal to or greater than IPMI_MAX_CHANNELS when all the |
| 3731 | * channels for this interface have been initialized. |
| 3732 | */ |
dann frazier | 4dec302 | 2009-04-21 12:24:05 -0700 | [diff] [blame] | 3733 | if (intf->curr_channel < IPMI_MAX_CHANNELS) { |
Corey Minyard | 9a2845c | 2009-05-20 13:36:17 -0500 | [diff] [blame] | 3734 | requeue = 0; /* Throw the message away */ |
dann frazier | 4dec302 | 2009-04-21 12:24:05 -0700 | [diff] [blame] | 3735 | goto out; |
| 3736 | } |
| 3737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | switch (intf->channels[chan].medium) { |
| 3739 | case IPMI_CHANNEL_MEDIUM_IPMB: |
| 3740 | if (msg->rsp[4] & 0x04) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3741 | /* |
| 3742 | * It's a response, so find the |
| 3743 | * requesting message and send it up. |
| 3744 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3745 | requeue = handle_ipmb_get_msg_rsp(intf, msg); |
| 3746 | } else { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3747 | /* |
| 3748 | * It's a command to the SMS from some other |
| 3749 | * entity. Handle that. |
| 3750 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3751 | requeue = handle_ipmb_get_msg_cmd(intf, msg); |
| 3752 | } |
| 3753 | break; |
| 3754 | |
| 3755 | case IPMI_CHANNEL_MEDIUM_8023LAN: |
| 3756 | case IPMI_CHANNEL_MEDIUM_ASYNC: |
| 3757 | if (msg->rsp[6] & 0x04) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3758 | /* |
| 3759 | * It's a response, so find the |
| 3760 | * requesting message and send it up. |
| 3761 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3762 | requeue = handle_lan_get_msg_rsp(intf, msg); |
| 3763 | } else { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3764 | /* |
| 3765 | * It's a command to the SMS from some other |
| 3766 | * entity. Handle that. |
| 3767 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | requeue = handle_lan_get_msg_cmd(intf, msg); |
| 3769 | } |
| 3770 | break; |
| 3771 | |
| 3772 | default: |
dann frazier | 4dec302 | 2009-04-21 12:24:05 -0700 | [diff] [blame] | 3773 | /* Check for OEM Channels. Clients had better |
| 3774 | register for these commands. */ |
| 3775 | if ((intf->channels[chan].medium |
| 3776 | >= IPMI_CHANNEL_MEDIUM_OEM_MIN) |
| 3777 | && (intf->channels[chan].medium |
| 3778 | <= IPMI_CHANNEL_MEDIUM_OEM_MAX)) { |
| 3779 | requeue = handle_oem_get_msg_cmd(intf, msg); |
| 3780 | } else { |
| 3781 | /* |
| 3782 | * We don't handle the channel type, so just |
| 3783 | * free the message. |
| 3784 | */ |
| 3785 | requeue = 0; |
| 3786 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3790 | && (msg->rsp[1] == IPMI_READ_EVENT_MSG_BUFFER_CMD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | /* It's an asyncronous event. */ |
| 3792 | requeue = handle_read_event_rsp(intf, msg); |
| 3793 | } else { |
| 3794 | /* It's a response from the local BMC. */ |
| 3795 | requeue = handle_bmc_rsp(intf, msg); |
| 3796 | } |
| 3797 | |
| 3798 | out: |
| 3799 | return requeue; |
| 3800 | } |
| 3801 | |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 3802 | /* |
| 3803 | * If there are messages in the queue or pretimeouts, handle them. |
| 3804 | */ |
| 3805 | static void handle_new_recv_msgs(ipmi_smi_t intf) |
| 3806 | { |
| 3807 | struct ipmi_smi_msg *smi_msg; |
| 3808 | unsigned long flags = 0; |
| 3809 | int rv; |
| 3810 | int run_to_completion = intf->run_to_completion; |
| 3811 | |
| 3812 | /* See if any waiting messages need to be processed. */ |
| 3813 | if (!run_to_completion) |
| 3814 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); |
| 3815 | while (!list_empty(&intf->waiting_msgs)) { |
| 3816 | smi_msg = list_entry(intf->waiting_msgs.next, |
| 3817 | struct ipmi_smi_msg, link); |
| 3818 | list_del(&smi_msg->link); |
| 3819 | if (!run_to_completion) |
| 3820 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); |
| 3821 | rv = handle_one_recv_msg(intf, smi_msg); |
| 3822 | if (!run_to_completion) |
| 3823 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); |
| 3824 | if (rv == 0) { |
| 3825 | /* Message handled */ |
| 3826 | ipmi_free_smi_msg(smi_msg); |
| 3827 | } else if (rv < 0) { |
| 3828 | /* Fatal error on the message, del but don't free. */ |
| 3829 | } else { |
| 3830 | /* |
| 3831 | * To preserve message order, quit if we |
| 3832 | * can't handle a message. |
| 3833 | */ |
| 3834 | list_add(&smi_msg->link, &intf->waiting_msgs); |
| 3835 | break; |
| 3836 | } |
| 3837 | } |
| 3838 | if (!run_to_completion) |
| 3839 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); |
| 3840 | |
| 3841 | /* |
| 3842 | * If the pretimout count is non-zero, decrement one from it and |
| 3843 | * deliver pretimeouts to all the users. |
| 3844 | */ |
| 3845 | if (atomic_add_unless(&intf->watchdog_pretimeouts_to_deliver, -1, 0)) { |
| 3846 | ipmi_user_t user; |
| 3847 | |
| 3848 | rcu_read_lock(); |
| 3849 | list_for_each_entry_rcu(user, &intf->users, link) { |
| 3850 | if (user->handler->ipmi_watchdog_pretimeout) |
| 3851 | user->handler->ipmi_watchdog_pretimeout( |
| 3852 | user->handler_data); |
| 3853 | } |
| 3854 | rcu_read_unlock(); |
| 3855 | } |
| 3856 | } |
| 3857 | |
| 3858 | static void smi_recv_tasklet(unsigned long val) |
| 3859 | { |
| 3860 | handle_new_recv_msgs((ipmi_smi_t) val); |
| 3861 | } |
| 3862 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3863 | /* Handle a new message from the lower layer. */ |
| 3864 | void ipmi_smi_msg_received(ipmi_smi_t intf, |
| 3865 | struct ipmi_smi_msg *msg) |
| 3866 | { |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 3867 | unsigned long flags = 0; /* keep us warning-free. */ |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 3868 | int run_to_completion; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3869 | |
| 3870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3871 | if ((msg->data_size >= 2) |
| 3872 | && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2)) |
| 3873 | && (msg->data[1] == IPMI_SEND_MSG_CMD) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3874 | && (msg->user_data == NULL)) { |
| 3875 | /* |
| 3876 | * This is the local response to a command send, start |
| 3877 | * the timer for these. The user_data will not be |
| 3878 | * NULL if this is a response send, and we will let |
| 3879 | * response sends just go through. |
| 3880 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3882 | /* |
| 3883 | * Check for errors, if we get certain errors (ones |
| 3884 | * that mean basically we can try again later), we |
| 3885 | * ignore them and start the timer. Otherwise we |
| 3886 | * report the error immediately. |
| 3887 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3888 | if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0) |
| 3889 | && (msg->rsp[2] != IPMI_NODE_BUSY_ERR) |
Corey Minyard | 46d52b0 | 2006-11-08 17:44:55 -0800 | [diff] [blame] | 3890 | && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR) |
| 3891 | && (msg->rsp[2] != IPMI_BUS_ERR) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3892 | && (msg->rsp[2] != IPMI_NAK_ON_WRITE_ERR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3893 | int chan = msg->rsp[3] & 0xf; |
| 3894 | |
| 3895 | /* Got an error sending the message, handle it. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | if (chan >= IPMI_MAX_CHANNELS) |
| 3897 | ; /* This shouldn't happen */ |
| 3898 | else if ((intf->channels[chan].medium |
| 3899 | == IPMI_CHANNEL_MEDIUM_8023LAN) |
| 3900 | || (intf->channels[chan].medium |
| 3901 | == IPMI_CHANNEL_MEDIUM_ASYNC)) |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3902 | ipmi_inc_stat(intf, sent_lan_command_errs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | else |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3904 | ipmi_inc_stat(intf, sent_ipmb_command_errs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | intf_err_seq(intf, msg->msgid, msg->rsp[2]); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3906 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3907 | /* The message was sent, start the timer. */ |
| 3908 | intf_start_seq_timer(intf, msg->msgid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3909 | |
| 3910 | ipmi_free_smi_msg(msg); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3911 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3914 | /* |
| 3915 | * To preserve message order, if the list is not empty, we |
| 3916 | * tack this message onto the end of the list. |
| 3917 | */ |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 3918 | run_to_completion = intf->run_to_completion; |
| 3919 | if (!run_to_completion) |
| 3920 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 3921 | list_add_tail(&msg->link, &intf->waiting_msgs); |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 3922 | if (!run_to_completion) |
| 3923 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3924 | |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 3925 | tasklet_schedule(&intf->recv_tasklet); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3926 | out: |
| 3927 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3929 | EXPORT_SYMBOL(ipmi_smi_msg_received); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | |
| 3931 | void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf) |
| 3932 | { |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 3933 | atomic_set(&intf->watchdog_pretimeouts_to_deliver, 1); |
| 3934 | tasklet_schedule(&intf->recv_tasklet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3936 | EXPORT_SYMBOL(ipmi_smi_watchdog_pretimeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3937 | |
Corey Minyard | 882fe01 | 2005-05-01 08:59:12 -0700 | [diff] [blame] | 3938 | static struct ipmi_smi_msg * |
| 3939 | smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg, |
| 3940 | unsigned char seq, long seqid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3941 | { |
Corey Minyard | 882fe01 | 2005-05-01 08:59:12 -0700 | [diff] [blame] | 3942 | struct ipmi_smi_msg *smi_msg = ipmi_alloc_smi_msg(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3943 | if (!smi_msg) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3944 | /* |
| 3945 | * If we can't allocate the message, then just return, we |
| 3946 | * get 4 retries, so this should be ok. |
| 3947 | */ |
Corey Minyard | 882fe01 | 2005-05-01 08:59:12 -0700 | [diff] [blame] | 3948 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3949 | |
| 3950 | memcpy(smi_msg->data, recv_msg->msg.data, recv_msg->msg.data_len); |
| 3951 | smi_msg->data_size = recv_msg->msg.data_len; |
| 3952 | smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | #ifdef DEBUG_MSGING |
| 3955 | { |
| 3956 | int m; |
| 3957 | printk("Resend: "); |
Corey Minyard | e8b3361 | 2005-09-06 15:18:45 -0700 | [diff] [blame] | 3958 | for (m = 0; m < smi_msg->data_size; m++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3959 | printk(" %2.2x", smi_msg->data[m]); |
| 3960 | printk("\n"); |
| 3961 | } |
| 3962 | #endif |
Corey Minyard | 882fe01 | 2005-05-01 08:59:12 -0700 | [diff] [blame] | 3963 | return smi_msg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3964 | } |
| 3965 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3966 | static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent, |
| 3967 | struct list_head *timeouts, long timeout_period, |
| 3968 | int slot, unsigned long *flags) |
| 3969 | { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 3970 | struct ipmi_recv_msg *msg; |
| 3971 | struct ipmi_smi_handlers *handlers; |
| 3972 | |
| 3973 | if (intf->intf_num == -1) |
| 3974 | return; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3975 | |
| 3976 | if (!ent->inuse) |
| 3977 | return; |
| 3978 | |
| 3979 | ent->timeout -= timeout_period; |
| 3980 | if (ent->timeout > 0) |
| 3981 | return; |
| 3982 | |
| 3983 | if (ent->retries_left == 0) { |
| 3984 | /* The message has used all its retries. */ |
| 3985 | ent->inuse = 0; |
| 3986 | msg = ent->recv_msg; |
| 3987 | list_add_tail(&msg->link, timeouts); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3988 | if (ent->broadcast) |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3989 | ipmi_inc_stat(intf, timed_out_ipmb_broadcasts); |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 3990 | else if (is_lan_addr(&ent->recv_msg->addr)) |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3991 | ipmi_inc_stat(intf, timed_out_lan_commands); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3992 | else |
Konstantin Baydarov | b2655f2 | 2008-04-29 01:01:05 -0700 | [diff] [blame] | 3993 | ipmi_inc_stat(intf, timed_out_ipmb_commands); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 3994 | } else { |
| 3995 | struct ipmi_smi_msg *smi_msg; |
| 3996 | /* More retries, send again. */ |
| 3997 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 3998 | /* |
| 3999 | * Start with the max timer, set to normal timer after |
| 4000 | * the message is sent. |
| 4001 | */ |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4002 | ent->timeout = MAX_MSG_TIMEOUT; |
| 4003 | ent->retries_left--; |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4004 | smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot, |
| 4005 | ent->seqid); |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 4006 | if (!smi_msg) { |
| 4007 | if (is_lan_addr(&ent->recv_msg->addr)) |
| 4008 | ipmi_inc_stat(intf, |
| 4009 | dropped_rexmit_lan_commands); |
| 4010 | else |
| 4011 | ipmi_inc_stat(intf, |
| 4012 | dropped_rexmit_ipmb_commands); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4013 | return; |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 4014 | } |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4015 | |
| 4016 | spin_unlock_irqrestore(&intf->seq_lock, *flags); |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4017 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4018 | /* |
| 4019 | * Send the new message. We send with a zero |
| 4020 | * priority. It timed out, I doubt time is that |
| 4021 | * critical now, and high priority messages are really |
| 4022 | * only for messages to the local MC, which don't get |
| 4023 | * resent. |
| 4024 | */ |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4025 | handlers = intf->handlers; |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 4026 | if (handlers) { |
| 4027 | if (is_lan_addr(&ent->recv_msg->addr)) |
| 4028 | ipmi_inc_stat(intf, |
| 4029 | retransmitted_lan_commands); |
| 4030 | else |
| 4031 | ipmi_inc_stat(intf, |
| 4032 | retransmitted_ipmb_commands); |
| 4033 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4034 | intf->handlers->sender(intf->send_info, |
| 4035 | smi_msg, 0); |
Corey Minyard | 25176ed | 2009-04-21 12:24:04 -0700 | [diff] [blame] | 4036 | } else |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4037 | ipmi_free_smi_msg(smi_msg); |
| 4038 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4039 | spin_lock_irqsave(&intf->seq_lock, *flags); |
| 4040 | } |
| 4041 | } |
| 4042 | |
| 4043 | static void ipmi_timeout_handler(long timeout_period) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4044 | { |
| 4045 | ipmi_smi_t intf; |
| 4046 | struct list_head timeouts; |
| 4047 | struct ipmi_recv_msg *msg, *msg2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4048 | unsigned long flags; |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4049 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4051 | rcu_read_lock(); |
| 4052 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
Corey Minyard | 7adf579 | 2012-03-28 14:42:49 -0700 | [diff] [blame^] | 4053 | tasklet_schedule(&intf->recv_tasklet); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4055 | /* |
| 4056 | * Go through the seq table and find any messages that |
| 4057 | * have timed out, putting them in the timeouts |
| 4058 | * list. |
| 4059 | */ |
David Barksdale | 41c57a8 | 2007-01-30 14:36:25 -0800 | [diff] [blame] | 4060 | INIT_LIST_HEAD(&timeouts); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4061 | spin_lock_irqsave(&intf->seq_lock, flags); |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4062 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) |
| 4063 | check_msg_timeout(intf, &(intf->seq_table[i]), |
| 4064 | &timeouts, timeout_period, i, |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4065 | &flags); |
| 4066 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4068 | list_for_each_entry_safe(msg, msg2, &timeouts, link) |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4069 | deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE); |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 4070 | |
| 4071 | /* |
| 4072 | * Maintenance mode handling. Check the timeout |
| 4073 | * optimistically before we claim the lock. It may |
| 4074 | * mean a timeout gets missed occasionally, but that |
| 4075 | * only means the timeout gets extended by one period |
| 4076 | * in that case. No big deal, and it avoids the lock |
| 4077 | * most of the time. |
| 4078 | */ |
| 4079 | if (intf->auto_maintenance_timeout > 0) { |
| 4080 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); |
| 4081 | if (intf->auto_maintenance_timeout > 0) { |
| 4082 | intf->auto_maintenance_timeout |
| 4083 | -= timeout_period; |
| 4084 | if (!intf->maintenance_mode |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4085 | && (intf->auto_maintenance_timeout <= 0)) { |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 4086 | intf->maintenance_mode_enable = 0; |
| 4087 | maintenance_mode_update(intf); |
| 4088 | } |
| 4089 | } |
| 4090 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, |
| 4091 | flags); |
| 4092 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | } |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4094 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
| 4097 | static void ipmi_request_event(void) |
| 4098 | { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4099 | ipmi_smi_t intf; |
| 4100 | struct ipmi_smi_handlers *handlers; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4101 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4102 | rcu_read_lock(); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4103 | /* |
| 4104 | * Called from the timer, no need to check if handlers is |
| 4105 | * valid. |
| 4106 | */ |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4107 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
Corey Minyard | b967513 | 2006-12-06 20:41:02 -0800 | [diff] [blame] | 4108 | /* No event requests when in maintenance mode. */ |
| 4109 | if (intf->maintenance_mode_enable) |
| 4110 | continue; |
| 4111 | |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4112 | handlers = intf->handlers; |
| 4113 | if (handlers) |
| 4114 | handlers->request_events(intf->send_info); |
| 4115 | } |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4116 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | static struct timer_list ipmi_timer; |
| 4120 | |
Corey Minyard | ddac44b | 2010-05-26 14:43:50 -0700 | [diff] [blame] | 4121 | /* Call every ~1000 ms. */ |
| 4122 | #define IPMI_TIMEOUT_TIME 1000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | |
| 4124 | /* How many jiffies does it take to get to the timeout time. */ |
| 4125 | #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000) |
| 4126 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4127 | /* |
| 4128 | * Request events from the queue every second (this is the number of |
| 4129 | * IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the |
| 4130 | * future, IPMI will add a way to know immediately if an event is in |
| 4131 | * the queue and this silliness can go away. |
| 4132 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4133 | #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME)) |
| 4134 | |
Corey Minyard | 8f43f84 | 2005-06-23 22:01:40 -0700 | [diff] [blame] | 4135 | static atomic_t stop_operation; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | static unsigned int ticks_to_req_ev = IPMI_REQUEST_EV_TIME; |
| 4137 | |
| 4138 | static void ipmi_timeout(unsigned long data) |
| 4139 | { |
Corey Minyard | 8f43f84 | 2005-06-23 22:01:40 -0700 | [diff] [blame] | 4140 | if (atomic_read(&stop_operation)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4141 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4142 | |
| 4143 | ticks_to_req_ev--; |
| 4144 | if (ticks_to_req_ev == 0) { |
| 4145 | ipmi_request_event(); |
| 4146 | ticks_to_req_ev = IPMI_REQUEST_EV_TIME; |
| 4147 | } |
| 4148 | |
| 4149 | ipmi_timeout_handler(IPMI_TIMEOUT_TIME); |
| 4150 | |
Corey Minyard | 8f43f84 | 2005-06-23 22:01:40 -0700 | [diff] [blame] | 4151 | mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | |
| 4155 | static atomic_t smi_msg_inuse_count = ATOMIC_INIT(0); |
| 4156 | static atomic_t recv_msg_inuse_count = ATOMIC_INIT(0); |
| 4157 | |
| 4158 | /* FIXME - convert these to slabs. */ |
| 4159 | static void free_smi_msg(struct ipmi_smi_msg *msg) |
| 4160 | { |
| 4161 | atomic_dec(&smi_msg_inuse_count); |
| 4162 | kfree(msg); |
| 4163 | } |
| 4164 | |
| 4165 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void) |
| 4166 | { |
| 4167 | struct ipmi_smi_msg *rv; |
| 4168 | rv = kmalloc(sizeof(struct ipmi_smi_msg), GFP_ATOMIC); |
| 4169 | if (rv) { |
| 4170 | rv->done = free_smi_msg; |
| 4171 | rv->user_data = NULL; |
| 4172 | atomic_inc(&smi_msg_inuse_count); |
| 4173 | } |
| 4174 | return rv; |
| 4175 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4176 | EXPORT_SYMBOL(ipmi_alloc_smi_msg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | |
| 4178 | static void free_recv_msg(struct ipmi_recv_msg *msg) |
| 4179 | { |
| 4180 | atomic_dec(&recv_msg_inuse_count); |
| 4181 | kfree(msg); |
| 4182 | } |
| 4183 | |
Adrian Bunk | 7400630 | 2008-04-29 01:01:14 -0700 | [diff] [blame] | 4184 | static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | { |
| 4186 | struct ipmi_recv_msg *rv; |
| 4187 | |
| 4188 | rv = kmalloc(sizeof(struct ipmi_recv_msg), GFP_ATOMIC); |
| 4189 | if (rv) { |
Corey Minyard | a9eec55 | 2006-08-31 21:27:45 -0700 | [diff] [blame] | 4190 | rv->user = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | rv->done = free_recv_msg; |
| 4192 | atomic_inc(&recv_msg_inuse_count); |
| 4193 | } |
| 4194 | return rv; |
| 4195 | } |
| 4196 | |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4197 | void ipmi_free_recv_msg(struct ipmi_recv_msg *msg) |
| 4198 | { |
| 4199 | if (msg->user) |
| 4200 | kref_put(&msg->user->refcount, free_user); |
| 4201 | msg->done(msg); |
| 4202 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4203 | EXPORT_SYMBOL(ipmi_free_recv_msg); |
Corey Minyard | 393d2cc | 2005-11-07 00:59:54 -0800 | [diff] [blame] | 4204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4205 | #ifdef CONFIG_IPMI_PANIC_EVENT |
| 4206 | |
| 4207 | static void dummy_smi_done_handler(struct ipmi_smi_msg *msg) |
| 4208 | { |
| 4209 | } |
| 4210 | |
| 4211 | static void dummy_recv_done_handler(struct ipmi_recv_msg *msg) |
| 4212 | { |
| 4213 | } |
| 4214 | |
| 4215 | #ifdef CONFIG_IPMI_PANIC_STRING |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4216 | static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4217 | { |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4218 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
| 4219 | && (msg->msg.netfn == IPMI_NETFN_SENSOR_EVENT_RESPONSE) |
| 4220 | && (msg->msg.cmd == IPMI_GET_EVENT_RECEIVER_CMD) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4221 | && (msg->msg.data[0] == IPMI_CC_NO_ERROR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4222 | /* A get event receiver command, save it. */ |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4223 | intf->event_receiver = msg->msg.data[1]; |
| 4224 | intf->event_receiver_lun = msg->msg.data[2] & 0x3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | } |
| 4226 | } |
| 4227 | |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4228 | static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | { |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4230 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
| 4231 | && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE) |
| 4232 | && (msg->msg.cmd == IPMI_GET_DEVICE_ID_CMD) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4233 | && (msg->msg.data[0] == IPMI_CC_NO_ERROR)) { |
| 4234 | /* |
| 4235 | * A get device id command, save if we are an event |
| 4236 | * receiver or generator. |
| 4237 | */ |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4238 | intf->local_sel_device = (msg->msg.data[6] >> 2) & 1; |
| 4239 | intf->local_event_generator = (msg->msg.data[6] >> 5) & 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | } |
| 4241 | } |
| 4242 | #endif |
| 4243 | |
| 4244 | static void send_panic_events(char *str) |
| 4245 | { |
| 4246 | struct kernel_ipmi_msg msg; |
| 4247 | ipmi_smi_t intf; |
| 4248 | unsigned char data[16]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4249 | struct ipmi_system_interface_addr *si; |
| 4250 | struct ipmi_addr addr; |
| 4251 | struct ipmi_smi_msg smi_msg; |
| 4252 | struct ipmi_recv_msg recv_msg; |
| 4253 | |
| 4254 | si = (struct ipmi_system_interface_addr *) &addr; |
| 4255 | si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
| 4256 | si->channel = IPMI_BMC_CHANNEL; |
| 4257 | si->lun = 0; |
| 4258 | |
| 4259 | /* Fill in an event telling that we have failed. */ |
| 4260 | msg.netfn = 0x04; /* Sensor or Event. */ |
| 4261 | msg.cmd = 2; /* Platform event command. */ |
| 4262 | msg.data = data; |
| 4263 | msg.data_len = 8; |
Matt Domsch | cda315a | 2005-12-12 00:37:32 -0800 | [diff] [blame] | 4264 | data[0] = 0x41; /* Kernel generator ID, IPMI table 5-4 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | data[1] = 0x03; /* This is for IPMI 1.0. */ |
| 4266 | data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */ |
| 4267 | data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */ |
| 4268 | data[5] = 0xa1; /* Runtime stop OEM bytes 2 & 3. */ |
| 4269 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4270 | /* |
| 4271 | * Put a few breadcrumbs in. Hopefully later we can add more things |
| 4272 | * to make the panic events more useful. |
| 4273 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | if (str) { |
| 4275 | data[3] = str[0]; |
| 4276 | data[6] = str[1]; |
| 4277 | data[7] = str[2]; |
| 4278 | } |
| 4279 | |
| 4280 | smi_msg.done = dummy_smi_done_handler; |
| 4281 | recv_msg.done = dummy_recv_done_handler; |
| 4282 | |
| 4283 | /* For every registered interface, send the event. */ |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4284 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4285 | if (!intf->handlers) |
| 4286 | /* Interface is not ready. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | continue; |
| 4288 | |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 4289 | intf->run_to_completion = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | /* Send the event announcing the panic. */ |
| 4291 | intf->handlers->set_run_to_completion(intf->send_info, 1); |
| 4292 | i_ipmi_request(NULL, |
| 4293 | intf, |
| 4294 | &addr, |
| 4295 | 0, |
| 4296 | &msg, |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4297 | intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4298 | &smi_msg, |
| 4299 | &recv_msg, |
| 4300 | 0, |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 4301 | intf->channels[0].address, |
| 4302 | intf->channels[0].lun, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | 0, 1); /* Don't retry, and don't wait. */ |
| 4304 | } |
| 4305 | |
| 4306 | #ifdef CONFIG_IPMI_PANIC_STRING |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4307 | /* |
| 4308 | * On every interface, dump a bunch of OEM event holding the |
| 4309 | * string. |
| 4310 | */ |
| 4311 | if (!str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4312 | return; |
| 4313 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4314 | /* For every registered interface, send the event. */ |
| 4315 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4316 | char *p = str; |
| 4317 | struct ipmi_ipmb_addr *ipmb; |
| 4318 | int j; |
| 4319 | |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4320 | if (intf->intf_num == -1) |
| 4321 | /* Interface was not ready yet. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | continue; |
| 4323 | |
Corey Minyard | 78ba2fa | 2007-02-10 01:45:45 -0800 | [diff] [blame] | 4324 | /* |
| 4325 | * intf_num is used as an marker to tell if the |
| 4326 | * interface is valid. Thus we need a read barrier to |
| 4327 | * make sure data fetched before checking intf_num |
| 4328 | * won't be used. |
| 4329 | */ |
| 4330 | smp_rmb(); |
| 4331 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4332 | /* |
| 4333 | * First job here is to figure out where to send the |
| 4334 | * OEM events. There's no way in IPMI to send OEM |
| 4335 | * events using an event send command, so we have to |
| 4336 | * find the SEL to put them in and stick them in |
| 4337 | * there. |
| 4338 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4339 | |
| 4340 | /* Get capabilities from the get device id. */ |
| 4341 | intf->local_sel_device = 0; |
| 4342 | intf->local_event_generator = 0; |
| 4343 | intf->event_receiver = 0; |
| 4344 | |
| 4345 | /* Request the device info from the local MC. */ |
| 4346 | msg.netfn = IPMI_NETFN_APP_REQUEST; |
| 4347 | msg.cmd = IPMI_GET_DEVICE_ID_CMD; |
| 4348 | msg.data = NULL; |
| 4349 | msg.data_len = 0; |
| 4350 | intf->null_user_handler = device_id_fetcher; |
| 4351 | i_ipmi_request(NULL, |
| 4352 | intf, |
| 4353 | &addr, |
| 4354 | 0, |
| 4355 | &msg, |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4356 | intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | &smi_msg, |
| 4358 | &recv_msg, |
| 4359 | 0, |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 4360 | intf->channels[0].address, |
| 4361 | intf->channels[0].lun, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | 0, 1); /* Don't retry, and don't wait. */ |
| 4363 | |
| 4364 | if (intf->local_event_generator) { |
| 4365 | /* Request the event receiver from the local MC. */ |
| 4366 | msg.netfn = IPMI_NETFN_SENSOR_EVENT_REQUEST; |
| 4367 | msg.cmd = IPMI_GET_EVENT_RECEIVER_CMD; |
| 4368 | msg.data = NULL; |
| 4369 | msg.data_len = 0; |
| 4370 | intf->null_user_handler = event_receiver_fetcher; |
| 4371 | i_ipmi_request(NULL, |
| 4372 | intf, |
| 4373 | &addr, |
| 4374 | 0, |
| 4375 | &msg, |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4376 | intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4377 | &smi_msg, |
| 4378 | &recv_msg, |
| 4379 | 0, |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 4380 | intf->channels[0].address, |
| 4381 | intf->channels[0].lun, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4382 | 0, 1); /* no retry, and no wait. */ |
| 4383 | } |
| 4384 | intf->null_user_handler = NULL; |
| 4385 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4386 | /* |
| 4387 | * Validate the event receiver. The low bit must not |
| 4388 | * be 1 (it must be a valid IPMB address), it cannot |
| 4389 | * be zero, and it must not be my address. |
| 4390 | */ |
| 4391 | if (((intf->event_receiver & 1) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | && (intf->event_receiver != 0) |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4393 | && (intf->event_receiver != intf->channels[0].address)) { |
| 4394 | /* |
| 4395 | * The event receiver is valid, send an IPMB |
| 4396 | * message. |
| 4397 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4398 | ipmb = (struct ipmi_ipmb_addr *) &addr; |
| 4399 | ipmb->addr_type = IPMI_IPMB_ADDR_TYPE; |
| 4400 | ipmb->channel = 0; /* FIXME - is this right? */ |
| 4401 | ipmb->lun = intf->event_receiver_lun; |
| 4402 | ipmb->slave_addr = intf->event_receiver; |
| 4403 | } else if (intf->local_sel_device) { |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4404 | /* |
| 4405 | * The event receiver was not valid (or was |
| 4406 | * me), but I am an SEL device, just dump it |
| 4407 | * in my SEL. |
| 4408 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4409 | si = (struct ipmi_system_interface_addr *) &addr; |
| 4410 | si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
| 4411 | si->channel = IPMI_BMC_CHANNEL; |
| 4412 | si->lun = 0; |
| 4413 | } else |
| 4414 | continue; /* No where to send the event. */ |
| 4415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4416 | msg.netfn = IPMI_NETFN_STORAGE_REQUEST; /* Storage. */ |
| 4417 | msg.cmd = IPMI_ADD_SEL_ENTRY_CMD; |
| 4418 | msg.data = data; |
| 4419 | msg.data_len = 16; |
| 4420 | |
| 4421 | j = 0; |
| 4422 | while (*p) { |
| 4423 | int size = strlen(p); |
| 4424 | |
| 4425 | if (size > 11) |
| 4426 | size = 11; |
| 4427 | data[0] = 0; |
| 4428 | data[1] = 0; |
| 4429 | data[2] = 0xf0; /* OEM event without timestamp. */ |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 4430 | data[3] = intf->channels[0].address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4431 | data[4] = j++; /* sequence # */ |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4432 | /* |
| 4433 | * Always give 11 bytes, so strncpy will fill |
| 4434 | * it with zeroes for me. |
| 4435 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4436 | strncpy(data+5, p, 11); |
| 4437 | p += size; |
| 4438 | |
| 4439 | i_ipmi_request(NULL, |
| 4440 | intf, |
| 4441 | &addr, |
| 4442 | 0, |
| 4443 | &msg, |
Corey Minyard | 56a55ec | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4444 | intf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | &smi_msg, |
| 4446 | &recv_msg, |
| 4447 | 0, |
Corey Minyard | c14979b | 2005-09-06 15:18:38 -0700 | [diff] [blame] | 4448 | intf->channels[0].address, |
| 4449 | intf->channels[0].lun, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4450 | 0, 1); /* no retry, and no wait. */ |
| 4451 | } |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4453 | #endif /* CONFIG_IPMI_PANIC_STRING */ |
| 4454 | } |
| 4455 | #endif /* CONFIG_IPMI_PANIC_EVENT */ |
| 4456 | |
Randy Dunlap | 0c8204b | 2006-12-10 02:19:06 -0800 | [diff] [blame] | 4457 | static int has_panicked; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4458 | |
| 4459 | static int panic_event(struct notifier_block *this, |
| 4460 | unsigned long event, |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4461 | void *ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4462 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | ipmi_smi_t intf; |
| 4464 | |
Lee Revell | f18190b | 2006-06-26 18:30:00 +0200 | [diff] [blame] | 4465 | if (has_panicked) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | return NOTIFY_DONE; |
Lee Revell | f18190b | 2006-06-26 18:30:00 +0200 | [diff] [blame] | 4467 | has_panicked = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4468 | |
| 4469 | /* For every registered interface, set it to run to completion. */ |
Corey Minyard | bca0324 | 2006-12-06 20:40:57 -0800 | [diff] [blame] | 4470 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
Corey Minyard | b2c0394 | 2006-12-06 20:41:00 -0800 | [diff] [blame] | 4471 | if (!intf->handlers) |
| 4472 | /* Interface is not ready. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | continue; |
| 4474 | |
Konstantin Baydarov | 5956dce | 2008-04-29 01:01:03 -0700 | [diff] [blame] | 4475 | intf->run_to_completion = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4476 | intf->handlers->set_run_to_completion(intf->send_info, 1); |
| 4477 | } |
| 4478 | |
| 4479 | #ifdef CONFIG_IPMI_PANIC_EVENT |
| 4480 | send_panic_events(ptr); |
| 4481 | #endif |
| 4482 | |
| 4483 | return NOTIFY_DONE; |
| 4484 | } |
| 4485 | |
| 4486 | static struct notifier_block panic_block = { |
| 4487 | .notifier_call = panic_event, |
| 4488 | .next = NULL, |
| 4489 | .priority = 200 /* priority: INT_MAX >= x >= 0 */ |
| 4490 | }; |
| 4491 | |
| 4492 | static int ipmi_init_msghandler(void) |
| 4493 | { |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 4494 | int rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4495 | |
| 4496 | if (initialized) |
| 4497 | return 0; |
| 4498 | |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 4499 | rv = driver_register(&ipmidriver.driver); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 4500 | if (rv) { |
| 4501 | printk(KERN_ERR PFX "Could not register IPMI driver\n"); |
| 4502 | return rv; |
| 4503 | } |
| 4504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4505 | printk(KERN_INFO "ipmi message handler version " |
Corey Minyard | 1fdd75b | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4506 | IPMI_DRIVER_VERSION "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 4508 | #ifdef CONFIG_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | proc_ipmi_root = proc_mkdir("ipmi", NULL); |
| 4510 | if (!proc_ipmi_root) { |
| 4511 | printk(KERN_ERR PFX "Unable to create IPMI proc dir"); |
| 4512 | return -ENOMEM; |
| 4513 | } |
| 4514 | |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 4515 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | |
Corey Minyard | 409035e | 2006-06-28 04:26:53 -0700 | [diff] [blame] | 4517 | setup_timer(&ipmi_timer, ipmi_timeout, 0); |
| 4518 | mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 4520 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4521 | |
| 4522 | initialized = 1; |
| 4523 | |
| 4524 | return 0; |
| 4525 | } |
| 4526 | |
Corey Minyard | 60ee6d5 | 2010-10-27 15:34:18 -0700 | [diff] [blame] | 4527 | static int __init ipmi_init_msghandler_mod(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4528 | { |
| 4529 | ipmi_init_msghandler(); |
| 4530 | return 0; |
| 4531 | } |
| 4532 | |
Corey Minyard | 60ee6d5 | 2010-10-27 15:34:18 -0700 | [diff] [blame] | 4533 | static void __exit cleanup_ipmi(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4534 | { |
| 4535 | int count; |
| 4536 | |
| 4537 | if (!initialized) |
| 4538 | return; |
| 4539 | |
Alan Stern | e041c68 | 2006-03-27 01:16:30 -0800 | [diff] [blame] | 4540 | atomic_notifier_chain_unregister(&panic_notifier_list, &panic_block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4541 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4542 | /* |
| 4543 | * This can't be called if any interfaces exist, so no worry |
| 4544 | * about shutting down the interfaces. |
| 4545 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4547 | /* |
| 4548 | * Tell the timer to stop, then wait for it to stop. This |
| 4549 | * avoids problems with race conditions removing the timer |
| 4550 | * here. |
| 4551 | */ |
Corey Minyard | 8f43f84 | 2005-06-23 22:01:40 -0700 | [diff] [blame] | 4552 | atomic_inc(&stop_operation); |
| 4553 | del_timer_sync(&ipmi_timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4554 | |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 4555 | #ifdef CONFIG_PROC_FS |
Alexey Dobriyan | 3542ae4 | 2007-10-16 23:26:50 -0700 | [diff] [blame] | 4556 | remove_proc_entry(proc_ipmi_root->name, NULL); |
Corey Minyard | 3b62594 | 2005-06-23 22:01:42 -0700 | [diff] [blame] | 4557 | #endif /* CONFIG_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | |
Darrick J. Wong | fe2d5ff | 2008-11-12 13:25:00 -0800 | [diff] [blame] | 4559 | driver_unregister(&ipmidriver.driver); |
Corey Minyard | 50c812b | 2006-03-26 01:37:21 -0800 | [diff] [blame] | 4560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | initialized = 0; |
| 4562 | |
| 4563 | /* Check for buffer leaks. */ |
| 4564 | count = atomic_read(&smi_msg_inuse_count); |
| 4565 | if (count != 0) |
| 4566 | printk(KERN_WARNING PFX "SMI message count %d at exit\n", |
| 4567 | count); |
| 4568 | count = atomic_read(&recv_msg_inuse_count); |
| 4569 | if (count != 0) |
| 4570 | printk(KERN_WARNING PFX "recv message count %d at exit\n", |
| 4571 | count); |
| 4572 | } |
| 4573 | module_exit(cleanup_ipmi); |
| 4574 | |
| 4575 | module_init(ipmi_init_msghandler_mod); |
| 4576 | MODULE_LICENSE("GPL"); |
Corey Minyard | 1fdd75b | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4577 | MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>"); |
Corey Minyard | c70d749 | 2008-04-29 01:01:09 -0700 | [diff] [blame] | 4578 | MODULE_DESCRIPTION("Incoming and outgoing message routing for an IPMI" |
| 4579 | " interface."); |
Corey Minyard | 1fdd75b | 2005-09-06 15:18:42 -0700 | [diff] [blame] | 4580 | MODULE_VERSION(IPMI_DRIVER_VERSION); |