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