Commit 074127367a503de0168e2ca5d0b36a6f761f026a
Committed by
Linus Torvalds
1 parent
997c136f51
Exists in
master
and in
7 other branches
ipmi: convert to seq_file interface
The ->read_proc interface is going away, convert to seq_file. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com> Cc:Corey Minyard <minyard@acm.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 3 changed files with 142 additions and 86 deletions Inline Diff
drivers/char/ipmi/ipmi_msghandler.c
1 | /* | 1 | /* |
2 | * ipmi_msghandler.c | 2 | * ipmi_msghandler.c |
3 | * | 3 | * |
4 | * Incoming and outgoing message routing for an IPMI interface. | 4 | * Incoming and outgoing message routing for an IPMI interface. |
5 | * | 5 | * |
6 | * Author: MontaVista Software, Inc. | 6 | * Author: MontaVista Software, Inc. |
7 | * Corey Minyard <minyard@mvista.com> | 7 | * Corey Minyard <minyard@mvista.com> |
8 | * source@mvista.com | 8 | * source@mvista.com |
9 | * | 9 | * |
10 | * Copyright 2002 MontaVista Software Inc. | 10 | * Copyright 2002 MontaVista Software Inc. |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or modify it | 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 | 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 | 14 | * Free Software Foundation; either version 2 of the License, or (at your |
15 | * option) any later version. | 15 | * option) any later version. |
16 | * | 16 | * |
17 | * | 17 | * |
18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | 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 | 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. | 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * | 28 | * |
29 | * You should have received a copy of the GNU General Public License along | 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., | 30 | * with this program; if not, write to the Free Software Foundation, Inc., |
31 | * 675 Mass Ave, Cambridge, MA 02139, USA. | 31 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
35 | #include <linux/errno.h> | 35 | #include <linux/errno.h> |
36 | #include <asm/system.h> | 36 | #include <asm/system.h> |
37 | #include <linux/poll.h> | 37 | #include <linux/poll.h> |
38 | #include <linux/sched.h> | 38 | #include <linux/sched.h> |
39 | #include <linux/seq_file.h> | ||
39 | #include <linux/spinlock.h> | 40 | #include <linux/spinlock.h> |
40 | #include <linux/mutex.h> | 41 | #include <linux/mutex.h> |
41 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
42 | #include <linux/ipmi.h> | 43 | #include <linux/ipmi.h> |
43 | #include <linux/ipmi_smi.h> | 44 | #include <linux/ipmi_smi.h> |
44 | #include <linux/notifier.h> | 45 | #include <linux/notifier.h> |
45 | #include <linux/init.h> | 46 | #include <linux/init.h> |
46 | #include <linux/proc_fs.h> | 47 | #include <linux/proc_fs.h> |
47 | #include <linux/rcupdate.h> | 48 | #include <linux/rcupdate.h> |
48 | 49 | ||
49 | #define PFX "IPMI message handler: " | 50 | #define PFX "IPMI message handler: " |
50 | 51 | ||
51 | #define IPMI_DRIVER_VERSION "39.2" | 52 | #define IPMI_DRIVER_VERSION "39.2" |
52 | 53 | ||
53 | static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); | 54 | static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void); |
54 | static int ipmi_init_msghandler(void); | 55 | static int ipmi_init_msghandler(void); |
55 | 56 | ||
56 | static int initialized; | 57 | static int initialized; |
57 | 58 | ||
58 | #ifdef CONFIG_PROC_FS | 59 | #ifdef CONFIG_PROC_FS |
59 | static struct proc_dir_entry *proc_ipmi_root; | 60 | static struct proc_dir_entry *proc_ipmi_root; |
60 | #endif /* CONFIG_PROC_FS */ | 61 | #endif /* CONFIG_PROC_FS */ |
61 | 62 | ||
62 | /* Remain in auto-maintenance mode for this amount of time (in ms). */ | 63 | /* Remain in auto-maintenance mode for this amount of time (in ms). */ |
63 | #define IPMI_MAINTENANCE_MODE_TIMEOUT 30000 | 64 | #define IPMI_MAINTENANCE_MODE_TIMEOUT 30000 |
64 | 65 | ||
65 | #define MAX_EVENTS_IN_QUEUE 25 | 66 | #define MAX_EVENTS_IN_QUEUE 25 |
66 | 67 | ||
67 | /* | 68 | /* |
68 | * Don't let a message sit in a queue forever, always time it with at lest | 69 | * Don't let a message sit in a queue forever, always time it with at lest |
69 | * the max message timer. This is in milliseconds. | 70 | * the max message timer. This is in milliseconds. |
70 | */ | 71 | */ |
71 | #define MAX_MSG_TIMEOUT 60000 | 72 | #define MAX_MSG_TIMEOUT 60000 |
72 | 73 | ||
73 | /* | 74 | /* |
74 | * The main "user" data structure. | 75 | * The main "user" data structure. |
75 | */ | 76 | */ |
76 | struct ipmi_user { | 77 | struct ipmi_user { |
77 | struct list_head link; | 78 | struct list_head link; |
78 | 79 | ||
79 | /* Set to "0" when the user is destroyed. */ | 80 | /* Set to "0" when the user is destroyed. */ |
80 | int valid; | 81 | int valid; |
81 | 82 | ||
82 | struct kref refcount; | 83 | struct kref refcount; |
83 | 84 | ||
84 | /* The upper layer that handles receive messages. */ | 85 | /* The upper layer that handles receive messages. */ |
85 | struct ipmi_user_hndl *handler; | 86 | struct ipmi_user_hndl *handler; |
86 | void *handler_data; | 87 | void *handler_data; |
87 | 88 | ||
88 | /* The interface this user is bound to. */ | 89 | /* The interface this user is bound to. */ |
89 | ipmi_smi_t intf; | 90 | ipmi_smi_t intf; |
90 | 91 | ||
91 | /* Does this interface receive IPMI events? */ | 92 | /* Does this interface receive IPMI events? */ |
92 | int gets_events; | 93 | int gets_events; |
93 | }; | 94 | }; |
94 | 95 | ||
95 | struct cmd_rcvr { | 96 | struct cmd_rcvr { |
96 | struct list_head link; | 97 | struct list_head link; |
97 | 98 | ||
98 | ipmi_user_t user; | 99 | ipmi_user_t user; |
99 | unsigned char netfn; | 100 | unsigned char netfn; |
100 | unsigned char cmd; | 101 | unsigned char cmd; |
101 | unsigned int chans; | 102 | unsigned int chans; |
102 | 103 | ||
103 | /* | 104 | /* |
104 | * This is used to form a linked lised during mass deletion. | 105 | * This is used to form a linked lised during mass deletion. |
105 | * Since this is in an RCU list, we cannot use the link above | 106 | * Since this is in an RCU list, we cannot use the link above |
106 | * or change any data until the RCU period completes. So we | 107 | * or change any data until the RCU period completes. So we |
107 | * use this next variable during mass deletion so we can have | 108 | * use this next variable during mass deletion so we can have |
108 | * a list and don't have to wait and restart the search on | 109 | * a list and don't have to wait and restart the search on |
109 | * every individual deletion of a command. | 110 | * every individual deletion of a command. |
110 | */ | 111 | */ |
111 | struct cmd_rcvr *next; | 112 | struct cmd_rcvr *next; |
112 | }; | 113 | }; |
113 | 114 | ||
114 | struct seq_table { | 115 | struct seq_table { |
115 | unsigned int inuse : 1; | 116 | unsigned int inuse : 1; |
116 | unsigned int broadcast : 1; | 117 | unsigned int broadcast : 1; |
117 | 118 | ||
118 | unsigned long timeout; | 119 | unsigned long timeout; |
119 | unsigned long orig_timeout; | 120 | unsigned long orig_timeout; |
120 | unsigned int retries_left; | 121 | unsigned int retries_left; |
121 | 122 | ||
122 | /* | 123 | /* |
123 | * To verify on an incoming send message response that this is | 124 | * To verify on an incoming send message response that this is |
124 | * the message that the response is for, we keep a sequence id | 125 | * the message that the response is for, we keep a sequence id |
125 | * and increment it every time we send a message. | 126 | * and increment it every time we send a message. |
126 | */ | 127 | */ |
127 | long seqid; | 128 | long seqid; |
128 | 129 | ||
129 | /* | 130 | /* |
130 | * This is held so we can properly respond to the message on a | 131 | * This is held so we can properly respond to the message on a |
131 | * timeout, and it is used to hold the temporary data for | 132 | * timeout, and it is used to hold the temporary data for |
132 | * retransmission, too. | 133 | * retransmission, too. |
133 | */ | 134 | */ |
134 | struct ipmi_recv_msg *recv_msg; | 135 | struct ipmi_recv_msg *recv_msg; |
135 | }; | 136 | }; |
136 | 137 | ||
137 | /* | 138 | /* |
138 | * Store the information in a msgid (long) to allow us to find a | 139 | * Store the information in a msgid (long) to allow us to find a |
139 | * sequence table entry from the msgid. | 140 | * sequence table entry from the msgid. |
140 | */ | 141 | */ |
141 | #define STORE_SEQ_IN_MSGID(seq, seqid) (((seq&0xff)<<26) | (seqid&0x3ffffff)) | 142 | #define STORE_SEQ_IN_MSGID(seq, seqid) (((seq&0xff)<<26) | (seqid&0x3ffffff)) |
142 | 143 | ||
143 | #define GET_SEQ_FROM_MSGID(msgid, seq, seqid) \ | 144 | #define GET_SEQ_FROM_MSGID(msgid, seq, seqid) \ |
144 | do { \ | 145 | do { \ |
145 | seq = ((msgid >> 26) & 0x3f); \ | 146 | seq = ((msgid >> 26) & 0x3f); \ |
146 | seqid = (msgid & 0x3fffff); \ | 147 | seqid = (msgid & 0x3fffff); \ |
147 | } while (0) | 148 | } while (0) |
148 | 149 | ||
149 | #define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff) | 150 | #define NEXT_SEQID(seqid) (((seqid) + 1) & 0x3fffff) |
150 | 151 | ||
151 | struct ipmi_channel { | 152 | struct ipmi_channel { |
152 | unsigned char medium; | 153 | unsigned char medium; |
153 | unsigned char protocol; | 154 | unsigned char protocol; |
154 | 155 | ||
155 | /* | 156 | /* |
156 | * My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR, | 157 | * My slave address. This is initialized to IPMI_BMC_SLAVE_ADDR, |
157 | * but may be changed by the user. | 158 | * but may be changed by the user. |
158 | */ | 159 | */ |
159 | unsigned char address; | 160 | unsigned char address; |
160 | 161 | ||
161 | /* | 162 | /* |
162 | * My LUN. This should generally stay the SMS LUN, but just in | 163 | * My LUN. This should generally stay the SMS LUN, but just in |
163 | * case... | 164 | * case... |
164 | */ | 165 | */ |
165 | unsigned char lun; | 166 | unsigned char lun; |
166 | }; | 167 | }; |
167 | 168 | ||
168 | #ifdef CONFIG_PROC_FS | 169 | #ifdef CONFIG_PROC_FS |
169 | struct ipmi_proc_entry { | 170 | struct ipmi_proc_entry { |
170 | char *name; | 171 | char *name; |
171 | struct ipmi_proc_entry *next; | 172 | struct ipmi_proc_entry *next; |
172 | }; | 173 | }; |
173 | #endif | 174 | #endif |
174 | 175 | ||
175 | struct bmc_device { | 176 | struct bmc_device { |
176 | struct platform_device *dev; | 177 | struct platform_device *dev; |
177 | struct ipmi_device_id id; | 178 | struct ipmi_device_id id; |
178 | unsigned char guid[16]; | 179 | unsigned char guid[16]; |
179 | int guid_set; | 180 | int guid_set; |
180 | 181 | ||
181 | struct kref refcount; | 182 | struct kref refcount; |
182 | 183 | ||
183 | /* bmc device attributes */ | 184 | /* bmc device attributes */ |
184 | struct device_attribute device_id_attr; | 185 | struct device_attribute device_id_attr; |
185 | struct device_attribute provides_dev_sdrs_attr; | 186 | struct device_attribute provides_dev_sdrs_attr; |
186 | struct device_attribute revision_attr; | 187 | struct device_attribute revision_attr; |
187 | struct device_attribute firmware_rev_attr; | 188 | struct device_attribute firmware_rev_attr; |
188 | struct device_attribute version_attr; | 189 | struct device_attribute version_attr; |
189 | struct device_attribute add_dev_support_attr; | 190 | struct device_attribute add_dev_support_attr; |
190 | struct device_attribute manufacturer_id_attr; | 191 | struct device_attribute manufacturer_id_attr; |
191 | struct device_attribute product_id_attr; | 192 | struct device_attribute product_id_attr; |
192 | struct device_attribute guid_attr; | 193 | struct device_attribute guid_attr; |
193 | struct device_attribute aux_firmware_rev_attr; | 194 | struct device_attribute aux_firmware_rev_attr; |
194 | }; | 195 | }; |
195 | 196 | ||
196 | /* | 197 | /* |
197 | * Various statistics for IPMI, these index stats[] in the ipmi_smi | 198 | * Various statistics for IPMI, these index stats[] in the ipmi_smi |
198 | * structure. | 199 | * structure. |
199 | */ | 200 | */ |
200 | enum ipmi_stat_indexes { | 201 | enum ipmi_stat_indexes { |
201 | /* Commands we got from the user that were invalid. */ | 202 | /* Commands we got from the user that were invalid. */ |
202 | IPMI_STAT_sent_invalid_commands = 0, | 203 | IPMI_STAT_sent_invalid_commands = 0, |
203 | 204 | ||
204 | /* Commands we sent to the MC. */ | 205 | /* Commands we sent to the MC. */ |
205 | IPMI_STAT_sent_local_commands, | 206 | IPMI_STAT_sent_local_commands, |
206 | 207 | ||
207 | /* Responses from the MC that were delivered to a user. */ | 208 | /* Responses from the MC that were delivered to a user. */ |
208 | IPMI_STAT_handled_local_responses, | 209 | IPMI_STAT_handled_local_responses, |
209 | 210 | ||
210 | /* Responses from the MC that were not delivered to a user. */ | 211 | /* Responses from the MC that were not delivered to a user. */ |
211 | IPMI_STAT_unhandled_local_responses, | 212 | IPMI_STAT_unhandled_local_responses, |
212 | 213 | ||
213 | /* Commands we sent out to the IPMB bus. */ | 214 | /* Commands we sent out to the IPMB bus. */ |
214 | IPMI_STAT_sent_ipmb_commands, | 215 | IPMI_STAT_sent_ipmb_commands, |
215 | 216 | ||
216 | /* Commands sent on the IPMB that had errors on the SEND CMD */ | 217 | /* Commands sent on the IPMB that had errors on the SEND CMD */ |
217 | IPMI_STAT_sent_ipmb_command_errs, | 218 | IPMI_STAT_sent_ipmb_command_errs, |
218 | 219 | ||
219 | /* Each retransmit increments this count. */ | 220 | /* Each retransmit increments this count. */ |
220 | IPMI_STAT_retransmitted_ipmb_commands, | 221 | IPMI_STAT_retransmitted_ipmb_commands, |
221 | 222 | ||
222 | /* | 223 | /* |
223 | * When a message times out (runs out of retransmits) this is | 224 | * When a message times out (runs out of retransmits) this is |
224 | * incremented. | 225 | * incremented. |
225 | */ | 226 | */ |
226 | IPMI_STAT_timed_out_ipmb_commands, | 227 | IPMI_STAT_timed_out_ipmb_commands, |
227 | 228 | ||
228 | /* | 229 | /* |
229 | * This is like above, but for broadcasts. Broadcasts are | 230 | * This is like above, but for broadcasts. Broadcasts are |
230 | * *not* included in the above count (they are expected to | 231 | * *not* included in the above count (they are expected to |
231 | * time out). | 232 | * time out). |
232 | */ | 233 | */ |
233 | IPMI_STAT_timed_out_ipmb_broadcasts, | 234 | IPMI_STAT_timed_out_ipmb_broadcasts, |
234 | 235 | ||
235 | /* Responses I have sent to the IPMB bus. */ | 236 | /* Responses I have sent to the IPMB bus. */ |
236 | IPMI_STAT_sent_ipmb_responses, | 237 | IPMI_STAT_sent_ipmb_responses, |
237 | 238 | ||
238 | /* The response was delivered to the user. */ | 239 | /* The response was delivered to the user. */ |
239 | IPMI_STAT_handled_ipmb_responses, | 240 | IPMI_STAT_handled_ipmb_responses, |
240 | 241 | ||
241 | /* The response had invalid data in it. */ | 242 | /* The response had invalid data in it. */ |
242 | IPMI_STAT_invalid_ipmb_responses, | 243 | IPMI_STAT_invalid_ipmb_responses, |
243 | 244 | ||
244 | /* The response didn't have anyone waiting for it. */ | 245 | /* The response didn't have anyone waiting for it. */ |
245 | IPMI_STAT_unhandled_ipmb_responses, | 246 | IPMI_STAT_unhandled_ipmb_responses, |
246 | 247 | ||
247 | /* Commands we sent out to the IPMB bus. */ | 248 | /* Commands we sent out to the IPMB bus. */ |
248 | IPMI_STAT_sent_lan_commands, | 249 | IPMI_STAT_sent_lan_commands, |
249 | 250 | ||
250 | /* Commands sent on the IPMB that had errors on the SEND CMD */ | 251 | /* Commands sent on the IPMB that had errors on the SEND CMD */ |
251 | IPMI_STAT_sent_lan_command_errs, | 252 | IPMI_STAT_sent_lan_command_errs, |
252 | 253 | ||
253 | /* Each retransmit increments this count. */ | 254 | /* Each retransmit increments this count. */ |
254 | IPMI_STAT_retransmitted_lan_commands, | 255 | IPMI_STAT_retransmitted_lan_commands, |
255 | 256 | ||
256 | /* | 257 | /* |
257 | * When a message times out (runs out of retransmits) this is | 258 | * When a message times out (runs out of retransmits) this is |
258 | * incremented. | 259 | * incremented. |
259 | */ | 260 | */ |
260 | IPMI_STAT_timed_out_lan_commands, | 261 | IPMI_STAT_timed_out_lan_commands, |
261 | 262 | ||
262 | /* Responses I have sent to the IPMB bus. */ | 263 | /* Responses I have sent to the IPMB bus. */ |
263 | IPMI_STAT_sent_lan_responses, | 264 | IPMI_STAT_sent_lan_responses, |
264 | 265 | ||
265 | /* The response was delivered to the user. */ | 266 | /* The response was delivered to the user. */ |
266 | IPMI_STAT_handled_lan_responses, | 267 | IPMI_STAT_handled_lan_responses, |
267 | 268 | ||
268 | /* The response had invalid data in it. */ | 269 | /* The response had invalid data in it. */ |
269 | IPMI_STAT_invalid_lan_responses, | 270 | IPMI_STAT_invalid_lan_responses, |
270 | 271 | ||
271 | /* The response didn't have anyone waiting for it. */ | 272 | /* The response didn't have anyone waiting for it. */ |
272 | IPMI_STAT_unhandled_lan_responses, | 273 | IPMI_STAT_unhandled_lan_responses, |
273 | 274 | ||
274 | /* The command was delivered to the user. */ | 275 | /* The command was delivered to the user. */ |
275 | IPMI_STAT_handled_commands, | 276 | IPMI_STAT_handled_commands, |
276 | 277 | ||
277 | /* The command had invalid data in it. */ | 278 | /* The command had invalid data in it. */ |
278 | IPMI_STAT_invalid_commands, | 279 | IPMI_STAT_invalid_commands, |
279 | 280 | ||
280 | /* The command didn't have anyone waiting for it. */ | 281 | /* The command didn't have anyone waiting for it. */ |
281 | IPMI_STAT_unhandled_commands, | 282 | IPMI_STAT_unhandled_commands, |
282 | 283 | ||
283 | /* Invalid data in an event. */ | 284 | /* Invalid data in an event. */ |
284 | IPMI_STAT_invalid_events, | 285 | IPMI_STAT_invalid_events, |
285 | 286 | ||
286 | /* Events that were received with the proper format. */ | 287 | /* Events that were received with the proper format. */ |
287 | IPMI_STAT_events, | 288 | IPMI_STAT_events, |
288 | 289 | ||
289 | /* Retransmissions on IPMB that failed. */ | 290 | /* Retransmissions on IPMB that failed. */ |
290 | IPMI_STAT_dropped_rexmit_ipmb_commands, | 291 | IPMI_STAT_dropped_rexmit_ipmb_commands, |
291 | 292 | ||
292 | /* Retransmissions on LAN that failed. */ | 293 | /* Retransmissions on LAN that failed. */ |
293 | IPMI_STAT_dropped_rexmit_lan_commands, | 294 | IPMI_STAT_dropped_rexmit_lan_commands, |
294 | 295 | ||
295 | /* This *must* remain last, add new values above this. */ | 296 | /* This *must* remain last, add new values above this. */ |
296 | IPMI_NUM_STATS | 297 | IPMI_NUM_STATS |
297 | }; | 298 | }; |
298 | 299 | ||
299 | 300 | ||
300 | #define IPMI_IPMB_NUM_SEQ 64 | 301 | #define IPMI_IPMB_NUM_SEQ 64 |
301 | #define IPMI_MAX_CHANNELS 16 | 302 | #define IPMI_MAX_CHANNELS 16 |
302 | struct ipmi_smi { | 303 | struct ipmi_smi { |
303 | /* What interface number are we? */ | 304 | /* What interface number are we? */ |
304 | int intf_num; | 305 | int intf_num; |
305 | 306 | ||
306 | struct kref refcount; | 307 | struct kref refcount; |
307 | 308 | ||
308 | /* Used for a list of interfaces. */ | 309 | /* Used for a list of interfaces. */ |
309 | struct list_head link; | 310 | struct list_head link; |
310 | 311 | ||
311 | /* | 312 | /* |
312 | * The list of upper layers that are using me. seq_lock | 313 | * The list of upper layers that are using me. seq_lock |
313 | * protects this. | 314 | * protects this. |
314 | */ | 315 | */ |
315 | struct list_head users; | 316 | struct list_head users; |
316 | 317 | ||
317 | /* Information to supply to users. */ | 318 | /* Information to supply to users. */ |
318 | unsigned char ipmi_version_major; | 319 | unsigned char ipmi_version_major; |
319 | unsigned char ipmi_version_minor; | 320 | unsigned char ipmi_version_minor; |
320 | 321 | ||
321 | /* Used for wake ups at startup. */ | 322 | /* Used for wake ups at startup. */ |
322 | wait_queue_head_t waitq; | 323 | wait_queue_head_t waitq; |
323 | 324 | ||
324 | struct bmc_device *bmc; | 325 | struct bmc_device *bmc; |
325 | char *my_dev_name; | 326 | char *my_dev_name; |
326 | char *sysfs_name; | 327 | char *sysfs_name; |
327 | 328 | ||
328 | /* | 329 | /* |
329 | * This is the lower-layer's sender routine. Note that you | 330 | * This is the lower-layer's sender routine. Note that you |
330 | * must either be holding the ipmi_interfaces_mutex or be in | 331 | * must either be holding the ipmi_interfaces_mutex or be in |
331 | * an umpreemptible region to use this. You must fetch the | 332 | * an umpreemptible region to use this. You must fetch the |
332 | * value into a local variable and make sure it is not NULL. | 333 | * value into a local variable and make sure it is not NULL. |
333 | */ | 334 | */ |
334 | struct ipmi_smi_handlers *handlers; | 335 | struct ipmi_smi_handlers *handlers; |
335 | void *send_info; | 336 | void *send_info; |
336 | 337 | ||
337 | #ifdef CONFIG_PROC_FS | 338 | #ifdef CONFIG_PROC_FS |
338 | /* A list of proc entries for this interface. */ | 339 | /* A list of proc entries for this interface. */ |
339 | struct mutex proc_entry_lock; | 340 | struct mutex proc_entry_lock; |
340 | struct ipmi_proc_entry *proc_entries; | 341 | struct ipmi_proc_entry *proc_entries; |
341 | #endif | 342 | #endif |
342 | 343 | ||
343 | /* Driver-model device for the system interface. */ | 344 | /* Driver-model device for the system interface. */ |
344 | struct device *si_dev; | 345 | struct device *si_dev; |
345 | 346 | ||
346 | /* | 347 | /* |
347 | * A table of sequence numbers for this interface. We use the | 348 | * A table of sequence numbers for this interface. We use the |
348 | * sequence numbers for IPMB messages that go out of the | 349 | * sequence numbers for IPMB messages that go out of the |
349 | * interface to match them up with their responses. A routine | 350 | * interface to match them up with their responses. A routine |
350 | * is called periodically to time the items in this list. | 351 | * is called periodically to time the items in this list. |
351 | */ | 352 | */ |
352 | spinlock_t seq_lock; | 353 | spinlock_t seq_lock; |
353 | struct seq_table seq_table[IPMI_IPMB_NUM_SEQ]; | 354 | struct seq_table seq_table[IPMI_IPMB_NUM_SEQ]; |
354 | int curr_seq; | 355 | int curr_seq; |
355 | 356 | ||
356 | /* | 357 | /* |
357 | * Messages that were delayed for some reason (out of memory, | 358 | * Messages that were delayed for some reason (out of memory, |
358 | * for instance), will go in here to be processed later in a | 359 | * for instance), will go in here to be processed later in a |
359 | * periodic timer interrupt. | 360 | * periodic timer interrupt. |
360 | */ | 361 | */ |
361 | spinlock_t waiting_msgs_lock; | 362 | spinlock_t waiting_msgs_lock; |
362 | struct list_head waiting_msgs; | 363 | struct list_head waiting_msgs; |
363 | 364 | ||
364 | /* | 365 | /* |
365 | * The list of command receivers that are registered for commands | 366 | * The list of command receivers that are registered for commands |
366 | * on this interface. | 367 | * on this interface. |
367 | */ | 368 | */ |
368 | struct mutex cmd_rcvrs_mutex; | 369 | struct mutex cmd_rcvrs_mutex; |
369 | struct list_head cmd_rcvrs; | 370 | struct list_head cmd_rcvrs; |
370 | 371 | ||
371 | /* | 372 | /* |
372 | * Events that were queues because no one was there to receive | 373 | * Events that were queues because no one was there to receive |
373 | * them. | 374 | * them. |
374 | */ | 375 | */ |
375 | spinlock_t events_lock; /* For dealing with event stuff. */ | 376 | spinlock_t events_lock; /* For dealing with event stuff. */ |
376 | struct list_head waiting_events; | 377 | struct list_head waiting_events; |
377 | unsigned int waiting_events_count; /* How many events in queue? */ | 378 | unsigned int waiting_events_count; /* How many events in queue? */ |
378 | char delivering_events; | 379 | char delivering_events; |
379 | char event_msg_printed; | 380 | char event_msg_printed; |
380 | 381 | ||
381 | /* | 382 | /* |
382 | * The event receiver for my BMC, only really used at panic | 383 | * The event receiver for my BMC, only really used at panic |
383 | * shutdown as a place to store this. | 384 | * shutdown as a place to store this. |
384 | */ | 385 | */ |
385 | unsigned char event_receiver; | 386 | unsigned char event_receiver; |
386 | unsigned char event_receiver_lun; | 387 | unsigned char event_receiver_lun; |
387 | unsigned char local_sel_device; | 388 | unsigned char local_sel_device; |
388 | unsigned char local_event_generator; | 389 | unsigned char local_event_generator; |
389 | 390 | ||
390 | /* For handling of maintenance mode. */ | 391 | /* For handling of maintenance mode. */ |
391 | int maintenance_mode; | 392 | int maintenance_mode; |
392 | int maintenance_mode_enable; | 393 | int maintenance_mode_enable; |
393 | int auto_maintenance_timeout; | 394 | int auto_maintenance_timeout; |
394 | spinlock_t maintenance_mode_lock; /* Used in a timer... */ | 395 | spinlock_t maintenance_mode_lock; /* Used in a timer... */ |
395 | 396 | ||
396 | /* | 397 | /* |
397 | * A cheap hack, if this is non-null and a message to an | 398 | * A cheap hack, if this is non-null and a message to an |
398 | * interface comes in with a NULL user, call this routine with | 399 | * interface comes in with a NULL user, call this routine with |
399 | * it. Note that the message will still be freed by the | 400 | * it. Note that the message will still be freed by the |
400 | * caller. This only works on the system interface. | 401 | * caller. This only works on the system interface. |
401 | */ | 402 | */ |
402 | void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_recv_msg *msg); | 403 | void (*null_user_handler)(ipmi_smi_t intf, struct ipmi_recv_msg *msg); |
403 | 404 | ||
404 | /* | 405 | /* |
405 | * When we are scanning the channels for an SMI, this will | 406 | * When we are scanning the channels for an SMI, this will |
406 | * tell which channel we are scanning. | 407 | * tell which channel we are scanning. |
407 | */ | 408 | */ |
408 | int curr_channel; | 409 | int curr_channel; |
409 | 410 | ||
410 | /* Channel information */ | 411 | /* Channel information */ |
411 | struct ipmi_channel channels[IPMI_MAX_CHANNELS]; | 412 | struct ipmi_channel channels[IPMI_MAX_CHANNELS]; |
412 | 413 | ||
413 | /* Proc FS stuff. */ | 414 | /* Proc FS stuff. */ |
414 | struct proc_dir_entry *proc_dir; | 415 | struct proc_dir_entry *proc_dir; |
415 | char proc_dir_name[10]; | 416 | char proc_dir_name[10]; |
416 | 417 | ||
417 | atomic_t stats[IPMI_NUM_STATS]; | 418 | atomic_t stats[IPMI_NUM_STATS]; |
418 | 419 | ||
419 | /* | 420 | /* |
420 | * run_to_completion duplicate of smb_info, smi_info | 421 | * run_to_completion duplicate of smb_info, smi_info |
421 | * and ipmi_serial_info structures. Used to decrease numbers of | 422 | * and ipmi_serial_info structures. Used to decrease numbers of |
422 | * parameters passed by "low" level IPMI code. | 423 | * parameters passed by "low" level IPMI code. |
423 | */ | 424 | */ |
424 | int run_to_completion; | 425 | int run_to_completion; |
425 | }; | 426 | }; |
426 | #define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev) | 427 | #define to_si_intf_from_dev(device) container_of(device, struct ipmi_smi, dev) |
427 | 428 | ||
428 | /** | 429 | /** |
429 | * The driver model view of the IPMI messaging driver. | 430 | * The driver model view of the IPMI messaging driver. |
430 | */ | 431 | */ |
431 | static struct platform_driver ipmidriver = { | 432 | static struct platform_driver ipmidriver = { |
432 | .driver = { | 433 | .driver = { |
433 | .name = "ipmi", | 434 | .name = "ipmi", |
434 | .bus = &platform_bus_type | 435 | .bus = &platform_bus_type |
435 | } | 436 | } |
436 | }; | 437 | }; |
437 | static DEFINE_MUTEX(ipmidriver_mutex); | 438 | static DEFINE_MUTEX(ipmidriver_mutex); |
438 | 439 | ||
439 | static LIST_HEAD(ipmi_interfaces); | 440 | static LIST_HEAD(ipmi_interfaces); |
440 | static DEFINE_MUTEX(ipmi_interfaces_mutex); | 441 | static DEFINE_MUTEX(ipmi_interfaces_mutex); |
441 | 442 | ||
442 | /* | 443 | /* |
443 | * List of watchers that want to know when smi's are added and deleted. | 444 | * List of watchers that want to know when smi's are added and deleted. |
444 | */ | 445 | */ |
445 | static LIST_HEAD(smi_watchers); | 446 | static LIST_HEAD(smi_watchers); |
446 | static DEFINE_MUTEX(smi_watchers_mutex); | 447 | static DEFINE_MUTEX(smi_watchers_mutex); |
447 | 448 | ||
448 | 449 | ||
449 | #define ipmi_inc_stat(intf, stat) \ | 450 | #define ipmi_inc_stat(intf, stat) \ |
450 | atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat]) | 451 | atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat]) |
451 | #define ipmi_get_stat(intf, stat) \ | 452 | #define ipmi_get_stat(intf, stat) \ |
452 | ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat])) | 453 | ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat])) |
453 | 454 | ||
454 | static int is_lan_addr(struct ipmi_addr *addr) | 455 | static int is_lan_addr(struct ipmi_addr *addr) |
455 | { | 456 | { |
456 | return addr->addr_type == IPMI_LAN_ADDR_TYPE; | 457 | return addr->addr_type == IPMI_LAN_ADDR_TYPE; |
457 | } | 458 | } |
458 | 459 | ||
459 | static int is_ipmb_addr(struct ipmi_addr *addr) | 460 | static int is_ipmb_addr(struct ipmi_addr *addr) |
460 | { | 461 | { |
461 | return addr->addr_type == IPMI_IPMB_ADDR_TYPE; | 462 | return addr->addr_type == IPMI_IPMB_ADDR_TYPE; |
462 | } | 463 | } |
463 | 464 | ||
464 | static int is_ipmb_bcast_addr(struct ipmi_addr *addr) | 465 | static int is_ipmb_bcast_addr(struct ipmi_addr *addr) |
465 | { | 466 | { |
466 | return addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE; | 467 | return addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE; |
467 | } | 468 | } |
468 | 469 | ||
469 | static void free_recv_msg_list(struct list_head *q) | 470 | static void free_recv_msg_list(struct list_head *q) |
470 | { | 471 | { |
471 | struct ipmi_recv_msg *msg, *msg2; | 472 | struct ipmi_recv_msg *msg, *msg2; |
472 | 473 | ||
473 | list_for_each_entry_safe(msg, msg2, q, link) { | 474 | list_for_each_entry_safe(msg, msg2, q, link) { |
474 | list_del(&msg->link); | 475 | list_del(&msg->link); |
475 | ipmi_free_recv_msg(msg); | 476 | ipmi_free_recv_msg(msg); |
476 | } | 477 | } |
477 | } | 478 | } |
478 | 479 | ||
479 | static void free_smi_msg_list(struct list_head *q) | 480 | static void free_smi_msg_list(struct list_head *q) |
480 | { | 481 | { |
481 | struct ipmi_smi_msg *msg, *msg2; | 482 | struct ipmi_smi_msg *msg, *msg2; |
482 | 483 | ||
483 | list_for_each_entry_safe(msg, msg2, q, link) { | 484 | list_for_each_entry_safe(msg, msg2, q, link) { |
484 | list_del(&msg->link); | 485 | list_del(&msg->link); |
485 | ipmi_free_smi_msg(msg); | 486 | ipmi_free_smi_msg(msg); |
486 | } | 487 | } |
487 | } | 488 | } |
488 | 489 | ||
489 | static void clean_up_interface_data(ipmi_smi_t intf) | 490 | static void clean_up_interface_data(ipmi_smi_t intf) |
490 | { | 491 | { |
491 | int i; | 492 | int i; |
492 | struct cmd_rcvr *rcvr, *rcvr2; | 493 | struct cmd_rcvr *rcvr, *rcvr2; |
493 | struct list_head list; | 494 | struct list_head list; |
494 | 495 | ||
495 | free_smi_msg_list(&intf->waiting_msgs); | 496 | free_smi_msg_list(&intf->waiting_msgs); |
496 | free_recv_msg_list(&intf->waiting_events); | 497 | free_recv_msg_list(&intf->waiting_events); |
497 | 498 | ||
498 | /* | 499 | /* |
499 | * Wholesale remove all the entries from the list in the | 500 | * Wholesale remove all the entries from the list in the |
500 | * interface and wait for RCU to know that none are in use. | 501 | * interface and wait for RCU to know that none are in use. |
501 | */ | 502 | */ |
502 | mutex_lock(&intf->cmd_rcvrs_mutex); | 503 | mutex_lock(&intf->cmd_rcvrs_mutex); |
503 | INIT_LIST_HEAD(&list); | 504 | INIT_LIST_HEAD(&list); |
504 | list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu); | 505 | list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu); |
505 | mutex_unlock(&intf->cmd_rcvrs_mutex); | 506 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
506 | 507 | ||
507 | list_for_each_entry_safe(rcvr, rcvr2, &list, link) | 508 | list_for_each_entry_safe(rcvr, rcvr2, &list, link) |
508 | kfree(rcvr); | 509 | kfree(rcvr); |
509 | 510 | ||
510 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { | 511 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { |
511 | if ((intf->seq_table[i].inuse) | 512 | if ((intf->seq_table[i].inuse) |
512 | && (intf->seq_table[i].recv_msg)) | 513 | && (intf->seq_table[i].recv_msg)) |
513 | ipmi_free_recv_msg(intf->seq_table[i].recv_msg); | 514 | ipmi_free_recv_msg(intf->seq_table[i].recv_msg); |
514 | } | 515 | } |
515 | } | 516 | } |
516 | 517 | ||
517 | static void intf_free(struct kref *ref) | 518 | static void intf_free(struct kref *ref) |
518 | { | 519 | { |
519 | ipmi_smi_t intf = container_of(ref, struct ipmi_smi, refcount); | 520 | ipmi_smi_t intf = container_of(ref, struct ipmi_smi, refcount); |
520 | 521 | ||
521 | clean_up_interface_data(intf); | 522 | clean_up_interface_data(intf); |
522 | kfree(intf); | 523 | kfree(intf); |
523 | } | 524 | } |
524 | 525 | ||
525 | struct watcher_entry { | 526 | struct watcher_entry { |
526 | int intf_num; | 527 | int intf_num; |
527 | ipmi_smi_t intf; | 528 | ipmi_smi_t intf; |
528 | struct list_head link; | 529 | struct list_head link; |
529 | }; | 530 | }; |
530 | 531 | ||
531 | int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher) | 532 | int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher) |
532 | { | 533 | { |
533 | ipmi_smi_t intf; | 534 | ipmi_smi_t intf; |
534 | LIST_HEAD(to_deliver); | 535 | LIST_HEAD(to_deliver); |
535 | struct watcher_entry *e, *e2; | 536 | struct watcher_entry *e, *e2; |
536 | 537 | ||
537 | mutex_lock(&smi_watchers_mutex); | 538 | mutex_lock(&smi_watchers_mutex); |
538 | 539 | ||
539 | mutex_lock(&ipmi_interfaces_mutex); | 540 | mutex_lock(&ipmi_interfaces_mutex); |
540 | 541 | ||
541 | /* Build a list of things to deliver. */ | 542 | /* Build a list of things to deliver. */ |
542 | list_for_each_entry(intf, &ipmi_interfaces, link) { | 543 | list_for_each_entry(intf, &ipmi_interfaces, link) { |
543 | if (intf->intf_num == -1) | 544 | if (intf->intf_num == -1) |
544 | continue; | 545 | continue; |
545 | e = kmalloc(sizeof(*e), GFP_KERNEL); | 546 | e = kmalloc(sizeof(*e), GFP_KERNEL); |
546 | if (!e) | 547 | if (!e) |
547 | goto out_err; | 548 | goto out_err; |
548 | kref_get(&intf->refcount); | 549 | kref_get(&intf->refcount); |
549 | e->intf = intf; | 550 | e->intf = intf; |
550 | e->intf_num = intf->intf_num; | 551 | e->intf_num = intf->intf_num; |
551 | list_add_tail(&e->link, &to_deliver); | 552 | list_add_tail(&e->link, &to_deliver); |
552 | } | 553 | } |
553 | 554 | ||
554 | /* We will succeed, so add it to the list. */ | 555 | /* We will succeed, so add it to the list. */ |
555 | list_add(&watcher->link, &smi_watchers); | 556 | list_add(&watcher->link, &smi_watchers); |
556 | 557 | ||
557 | mutex_unlock(&ipmi_interfaces_mutex); | 558 | mutex_unlock(&ipmi_interfaces_mutex); |
558 | 559 | ||
559 | list_for_each_entry_safe(e, e2, &to_deliver, link) { | 560 | list_for_each_entry_safe(e, e2, &to_deliver, link) { |
560 | list_del(&e->link); | 561 | list_del(&e->link); |
561 | watcher->new_smi(e->intf_num, e->intf->si_dev); | 562 | watcher->new_smi(e->intf_num, e->intf->si_dev); |
562 | kref_put(&e->intf->refcount, intf_free); | 563 | kref_put(&e->intf->refcount, intf_free); |
563 | kfree(e); | 564 | kfree(e); |
564 | } | 565 | } |
565 | 566 | ||
566 | mutex_unlock(&smi_watchers_mutex); | 567 | mutex_unlock(&smi_watchers_mutex); |
567 | 568 | ||
568 | return 0; | 569 | return 0; |
569 | 570 | ||
570 | out_err: | 571 | out_err: |
571 | mutex_unlock(&ipmi_interfaces_mutex); | 572 | mutex_unlock(&ipmi_interfaces_mutex); |
572 | mutex_unlock(&smi_watchers_mutex); | 573 | mutex_unlock(&smi_watchers_mutex); |
573 | list_for_each_entry_safe(e, e2, &to_deliver, link) { | 574 | list_for_each_entry_safe(e, e2, &to_deliver, link) { |
574 | list_del(&e->link); | 575 | list_del(&e->link); |
575 | kref_put(&e->intf->refcount, intf_free); | 576 | kref_put(&e->intf->refcount, intf_free); |
576 | kfree(e); | 577 | kfree(e); |
577 | } | 578 | } |
578 | return -ENOMEM; | 579 | return -ENOMEM; |
579 | } | 580 | } |
580 | EXPORT_SYMBOL(ipmi_smi_watcher_register); | 581 | EXPORT_SYMBOL(ipmi_smi_watcher_register); |
581 | 582 | ||
582 | int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher) | 583 | int ipmi_smi_watcher_unregister(struct ipmi_smi_watcher *watcher) |
583 | { | 584 | { |
584 | mutex_lock(&smi_watchers_mutex); | 585 | mutex_lock(&smi_watchers_mutex); |
585 | list_del(&(watcher->link)); | 586 | list_del(&(watcher->link)); |
586 | mutex_unlock(&smi_watchers_mutex); | 587 | mutex_unlock(&smi_watchers_mutex); |
587 | return 0; | 588 | return 0; |
588 | } | 589 | } |
589 | EXPORT_SYMBOL(ipmi_smi_watcher_unregister); | 590 | EXPORT_SYMBOL(ipmi_smi_watcher_unregister); |
590 | 591 | ||
591 | /* | 592 | /* |
592 | * Must be called with smi_watchers_mutex held. | 593 | * Must be called with smi_watchers_mutex held. |
593 | */ | 594 | */ |
594 | static void | 595 | static void |
595 | call_smi_watchers(int i, struct device *dev) | 596 | call_smi_watchers(int i, struct device *dev) |
596 | { | 597 | { |
597 | struct ipmi_smi_watcher *w; | 598 | struct ipmi_smi_watcher *w; |
598 | 599 | ||
599 | list_for_each_entry(w, &smi_watchers, link) { | 600 | list_for_each_entry(w, &smi_watchers, link) { |
600 | if (try_module_get(w->owner)) { | 601 | if (try_module_get(w->owner)) { |
601 | w->new_smi(i, dev); | 602 | w->new_smi(i, dev); |
602 | module_put(w->owner); | 603 | module_put(w->owner); |
603 | } | 604 | } |
604 | } | 605 | } |
605 | } | 606 | } |
606 | 607 | ||
607 | static int | 608 | static int |
608 | ipmi_addr_equal(struct ipmi_addr *addr1, struct ipmi_addr *addr2) | 609 | ipmi_addr_equal(struct ipmi_addr *addr1, struct ipmi_addr *addr2) |
609 | { | 610 | { |
610 | if (addr1->addr_type != addr2->addr_type) | 611 | if (addr1->addr_type != addr2->addr_type) |
611 | return 0; | 612 | return 0; |
612 | 613 | ||
613 | if (addr1->channel != addr2->channel) | 614 | if (addr1->channel != addr2->channel) |
614 | return 0; | 615 | return 0; |
615 | 616 | ||
616 | if (addr1->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { | 617 | if (addr1->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { |
617 | struct ipmi_system_interface_addr *smi_addr1 | 618 | struct ipmi_system_interface_addr *smi_addr1 |
618 | = (struct ipmi_system_interface_addr *) addr1; | 619 | = (struct ipmi_system_interface_addr *) addr1; |
619 | struct ipmi_system_interface_addr *smi_addr2 | 620 | struct ipmi_system_interface_addr *smi_addr2 |
620 | = (struct ipmi_system_interface_addr *) addr2; | 621 | = (struct ipmi_system_interface_addr *) addr2; |
621 | return (smi_addr1->lun == smi_addr2->lun); | 622 | return (smi_addr1->lun == smi_addr2->lun); |
622 | } | 623 | } |
623 | 624 | ||
624 | if (is_ipmb_addr(addr1) || is_ipmb_bcast_addr(addr1)) { | 625 | if (is_ipmb_addr(addr1) || is_ipmb_bcast_addr(addr1)) { |
625 | struct ipmi_ipmb_addr *ipmb_addr1 | 626 | struct ipmi_ipmb_addr *ipmb_addr1 |
626 | = (struct ipmi_ipmb_addr *) addr1; | 627 | = (struct ipmi_ipmb_addr *) addr1; |
627 | struct ipmi_ipmb_addr *ipmb_addr2 | 628 | struct ipmi_ipmb_addr *ipmb_addr2 |
628 | = (struct ipmi_ipmb_addr *) addr2; | 629 | = (struct ipmi_ipmb_addr *) addr2; |
629 | 630 | ||
630 | return ((ipmb_addr1->slave_addr == ipmb_addr2->slave_addr) | 631 | return ((ipmb_addr1->slave_addr == ipmb_addr2->slave_addr) |
631 | && (ipmb_addr1->lun == ipmb_addr2->lun)); | 632 | && (ipmb_addr1->lun == ipmb_addr2->lun)); |
632 | } | 633 | } |
633 | 634 | ||
634 | if (is_lan_addr(addr1)) { | 635 | if (is_lan_addr(addr1)) { |
635 | struct ipmi_lan_addr *lan_addr1 | 636 | struct ipmi_lan_addr *lan_addr1 |
636 | = (struct ipmi_lan_addr *) addr1; | 637 | = (struct ipmi_lan_addr *) addr1; |
637 | struct ipmi_lan_addr *lan_addr2 | 638 | struct ipmi_lan_addr *lan_addr2 |
638 | = (struct ipmi_lan_addr *) addr2; | 639 | = (struct ipmi_lan_addr *) addr2; |
639 | 640 | ||
640 | return ((lan_addr1->remote_SWID == lan_addr2->remote_SWID) | 641 | return ((lan_addr1->remote_SWID == lan_addr2->remote_SWID) |
641 | && (lan_addr1->local_SWID == lan_addr2->local_SWID) | 642 | && (lan_addr1->local_SWID == lan_addr2->local_SWID) |
642 | && (lan_addr1->session_handle | 643 | && (lan_addr1->session_handle |
643 | == lan_addr2->session_handle) | 644 | == lan_addr2->session_handle) |
644 | && (lan_addr1->lun == lan_addr2->lun)); | 645 | && (lan_addr1->lun == lan_addr2->lun)); |
645 | } | 646 | } |
646 | 647 | ||
647 | return 1; | 648 | return 1; |
648 | } | 649 | } |
649 | 650 | ||
650 | int ipmi_validate_addr(struct ipmi_addr *addr, int len) | 651 | int ipmi_validate_addr(struct ipmi_addr *addr, int len) |
651 | { | 652 | { |
652 | if (len < sizeof(struct ipmi_system_interface_addr)) | 653 | if (len < sizeof(struct ipmi_system_interface_addr)) |
653 | return -EINVAL; | 654 | return -EINVAL; |
654 | 655 | ||
655 | if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { | 656 | if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { |
656 | if (addr->channel != IPMI_BMC_CHANNEL) | 657 | if (addr->channel != IPMI_BMC_CHANNEL) |
657 | return -EINVAL; | 658 | return -EINVAL; |
658 | return 0; | 659 | return 0; |
659 | } | 660 | } |
660 | 661 | ||
661 | if ((addr->channel == IPMI_BMC_CHANNEL) | 662 | if ((addr->channel == IPMI_BMC_CHANNEL) |
662 | || (addr->channel >= IPMI_MAX_CHANNELS) | 663 | || (addr->channel >= IPMI_MAX_CHANNELS) |
663 | || (addr->channel < 0)) | 664 | || (addr->channel < 0)) |
664 | return -EINVAL; | 665 | return -EINVAL; |
665 | 666 | ||
666 | if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) { | 667 | if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) { |
667 | if (len < sizeof(struct ipmi_ipmb_addr)) | 668 | if (len < sizeof(struct ipmi_ipmb_addr)) |
668 | return -EINVAL; | 669 | return -EINVAL; |
669 | return 0; | 670 | return 0; |
670 | } | 671 | } |
671 | 672 | ||
672 | if (is_lan_addr(addr)) { | 673 | if (is_lan_addr(addr)) { |
673 | if (len < sizeof(struct ipmi_lan_addr)) | 674 | if (len < sizeof(struct ipmi_lan_addr)) |
674 | return -EINVAL; | 675 | return -EINVAL; |
675 | return 0; | 676 | return 0; |
676 | } | 677 | } |
677 | 678 | ||
678 | return -EINVAL; | 679 | return -EINVAL; |
679 | } | 680 | } |
680 | EXPORT_SYMBOL(ipmi_validate_addr); | 681 | EXPORT_SYMBOL(ipmi_validate_addr); |
681 | 682 | ||
682 | unsigned int ipmi_addr_length(int addr_type) | 683 | unsigned int ipmi_addr_length(int addr_type) |
683 | { | 684 | { |
684 | if (addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) | 685 | if (addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
685 | return sizeof(struct ipmi_system_interface_addr); | 686 | return sizeof(struct ipmi_system_interface_addr); |
686 | 687 | ||
687 | if ((addr_type == IPMI_IPMB_ADDR_TYPE) | 688 | if ((addr_type == IPMI_IPMB_ADDR_TYPE) |
688 | || (addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)) | 689 | || (addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE)) |
689 | return sizeof(struct ipmi_ipmb_addr); | 690 | return sizeof(struct ipmi_ipmb_addr); |
690 | 691 | ||
691 | if (addr_type == IPMI_LAN_ADDR_TYPE) | 692 | if (addr_type == IPMI_LAN_ADDR_TYPE) |
692 | return sizeof(struct ipmi_lan_addr); | 693 | return sizeof(struct ipmi_lan_addr); |
693 | 694 | ||
694 | return 0; | 695 | return 0; |
695 | } | 696 | } |
696 | EXPORT_SYMBOL(ipmi_addr_length); | 697 | EXPORT_SYMBOL(ipmi_addr_length); |
697 | 698 | ||
698 | static void deliver_response(struct ipmi_recv_msg *msg) | 699 | static void deliver_response(struct ipmi_recv_msg *msg) |
699 | { | 700 | { |
700 | if (!msg->user) { | 701 | if (!msg->user) { |
701 | ipmi_smi_t intf = msg->user_msg_data; | 702 | ipmi_smi_t intf = msg->user_msg_data; |
702 | 703 | ||
703 | /* Special handling for NULL users. */ | 704 | /* Special handling for NULL users. */ |
704 | if (intf->null_user_handler) { | 705 | if (intf->null_user_handler) { |
705 | intf->null_user_handler(intf, msg); | 706 | intf->null_user_handler(intf, msg); |
706 | ipmi_inc_stat(intf, handled_local_responses); | 707 | ipmi_inc_stat(intf, handled_local_responses); |
707 | } else { | 708 | } else { |
708 | /* No handler, so give up. */ | 709 | /* No handler, so give up. */ |
709 | ipmi_inc_stat(intf, unhandled_local_responses); | 710 | ipmi_inc_stat(intf, unhandled_local_responses); |
710 | } | 711 | } |
711 | ipmi_free_recv_msg(msg); | 712 | ipmi_free_recv_msg(msg); |
712 | } else { | 713 | } else { |
713 | ipmi_user_t user = msg->user; | 714 | ipmi_user_t user = msg->user; |
714 | user->handler->ipmi_recv_hndl(msg, user->handler_data); | 715 | user->handler->ipmi_recv_hndl(msg, user->handler_data); |
715 | } | 716 | } |
716 | } | 717 | } |
717 | 718 | ||
718 | static void | 719 | static void |
719 | deliver_err_response(struct ipmi_recv_msg *msg, int err) | 720 | deliver_err_response(struct ipmi_recv_msg *msg, int err) |
720 | { | 721 | { |
721 | msg->recv_type = IPMI_RESPONSE_RECV_TYPE; | 722 | msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
722 | msg->msg_data[0] = err; | 723 | msg->msg_data[0] = err; |
723 | msg->msg.netfn |= 1; /* Convert to a response. */ | 724 | msg->msg.netfn |= 1; /* Convert to a response. */ |
724 | msg->msg.data_len = 1; | 725 | msg->msg.data_len = 1; |
725 | msg->msg.data = msg->msg_data; | 726 | msg->msg.data = msg->msg_data; |
726 | deliver_response(msg); | 727 | deliver_response(msg); |
727 | } | 728 | } |
728 | 729 | ||
729 | /* | 730 | /* |
730 | * Find the next sequence number not being used and add the given | 731 | * Find the next sequence number not being used and add the given |
731 | * message with the given timeout to the sequence table. This must be | 732 | * message with the given timeout to the sequence table. This must be |
732 | * called with the interface's seq_lock held. | 733 | * called with the interface's seq_lock held. |
733 | */ | 734 | */ |
734 | static int intf_next_seq(ipmi_smi_t intf, | 735 | static int intf_next_seq(ipmi_smi_t intf, |
735 | struct ipmi_recv_msg *recv_msg, | 736 | struct ipmi_recv_msg *recv_msg, |
736 | unsigned long timeout, | 737 | unsigned long timeout, |
737 | int retries, | 738 | int retries, |
738 | int broadcast, | 739 | int broadcast, |
739 | unsigned char *seq, | 740 | unsigned char *seq, |
740 | long *seqid) | 741 | long *seqid) |
741 | { | 742 | { |
742 | int rv = 0; | 743 | int rv = 0; |
743 | unsigned int i; | 744 | unsigned int i; |
744 | 745 | ||
745 | for (i = intf->curr_seq; (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq; | 746 | for (i = intf->curr_seq; (i+1)%IPMI_IPMB_NUM_SEQ != intf->curr_seq; |
746 | i = (i+1)%IPMI_IPMB_NUM_SEQ) { | 747 | i = (i+1)%IPMI_IPMB_NUM_SEQ) { |
747 | if (!intf->seq_table[i].inuse) | 748 | if (!intf->seq_table[i].inuse) |
748 | break; | 749 | break; |
749 | } | 750 | } |
750 | 751 | ||
751 | if (!intf->seq_table[i].inuse) { | 752 | if (!intf->seq_table[i].inuse) { |
752 | intf->seq_table[i].recv_msg = recv_msg; | 753 | intf->seq_table[i].recv_msg = recv_msg; |
753 | 754 | ||
754 | /* | 755 | /* |
755 | * Start with the maximum timeout, when the send response | 756 | * Start with the maximum timeout, when the send response |
756 | * comes in we will start the real timer. | 757 | * comes in we will start the real timer. |
757 | */ | 758 | */ |
758 | intf->seq_table[i].timeout = MAX_MSG_TIMEOUT; | 759 | intf->seq_table[i].timeout = MAX_MSG_TIMEOUT; |
759 | intf->seq_table[i].orig_timeout = timeout; | 760 | intf->seq_table[i].orig_timeout = timeout; |
760 | intf->seq_table[i].retries_left = retries; | 761 | intf->seq_table[i].retries_left = retries; |
761 | intf->seq_table[i].broadcast = broadcast; | 762 | intf->seq_table[i].broadcast = broadcast; |
762 | intf->seq_table[i].inuse = 1; | 763 | intf->seq_table[i].inuse = 1; |
763 | intf->seq_table[i].seqid = NEXT_SEQID(intf->seq_table[i].seqid); | 764 | intf->seq_table[i].seqid = NEXT_SEQID(intf->seq_table[i].seqid); |
764 | *seq = i; | 765 | *seq = i; |
765 | *seqid = intf->seq_table[i].seqid; | 766 | *seqid = intf->seq_table[i].seqid; |
766 | intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ; | 767 | intf->curr_seq = (i+1)%IPMI_IPMB_NUM_SEQ; |
767 | } else { | 768 | } else { |
768 | rv = -EAGAIN; | 769 | rv = -EAGAIN; |
769 | } | 770 | } |
770 | 771 | ||
771 | return rv; | 772 | return rv; |
772 | } | 773 | } |
773 | 774 | ||
774 | /* | 775 | /* |
775 | * Return the receive message for the given sequence number and | 776 | * Return the receive message for the given sequence number and |
776 | * release the sequence number so it can be reused. Some other data | 777 | * release the sequence number so it can be reused. Some other data |
777 | * is passed in to be sure the message matches up correctly (to help | 778 | * is passed in to be sure the message matches up correctly (to help |
778 | * guard against message coming in after their timeout and the | 779 | * guard against message coming in after their timeout and the |
779 | * sequence number being reused). | 780 | * sequence number being reused). |
780 | */ | 781 | */ |
781 | static int intf_find_seq(ipmi_smi_t intf, | 782 | static int intf_find_seq(ipmi_smi_t intf, |
782 | unsigned char seq, | 783 | unsigned char seq, |
783 | short channel, | 784 | short channel, |
784 | unsigned char cmd, | 785 | unsigned char cmd, |
785 | unsigned char netfn, | 786 | unsigned char netfn, |
786 | struct ipmi_addr *addr, | 787 | struct ipmi_addr *addr, |
787 | struct ipmi_recv_msg **recv_msg) | 788 | struct ipmi_recv_msg **recv_msg) |
788 | { | 789 | { |
789 | int rv = -ENODEV; | 790 | int rv = -ENODEV; |
790 | unsigned long flags; | 791 | unsigned long flags; |
791 | 792 | ||
792 | if (seq >= IPMI_IPMB_NUM_SEQ) | 793 | if (seq >= IPMI_IPMB_NUM_SEQ) |
793 | return -EINVAL; | 794 | return -EINVAL; |
794 | 795 | ||
795 | spin_lock_irqsave(&(intf->seq_lock), flags); | 796 | spin_lock_irqsave(&(intf->seq_lock), flags); |
796 | if (intf->seq_table[seq].inuse) { | 797 | if (intf->seq_table[seq].inuse) { |
797 | struct ipmi_recv_msg *msg = intf->seq_table[seq].recv_msg; | 798 | struct ipmi_recv_msg *msg = intf->seq_table[seq].recv_msg; |
798 | 799 | ||
799 | if ((msg->addr.channel == channel) && (msg->msg.cmd == cmd) | 800 | if ((msg->addr.channel == channel) && (msg->msg.cmd == cmd) |
800 | && (msg->msg.netfn == netfn) | 801 | && (msg->msg.netfn == netfn) |
801 | && (ipmi_addr_equal(addr, &(msg->addr)))) { | 802 | && (ipmi_addr_equal(addr, &(msg->addr)))) { |
802 | *recv_msg = msg; | 803 | *recv_msg = msg; |
803 | intf->seq_table[seq].inuse = 0; | 804 | intf->seq_table[seq].inuse = 0; |
804 | rv = 0; | 805 | rv = 0; |
805 | } | 806 | } |
806 | } | 807 | } |
807 | spin_unlock_irqrestore(&(intf->seq_lock), flags); | 808 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
808 | 809 | ||
809 | return rv; | 810 | return rv; |
810 | } | 811 | } |
811 | 812 | ||
812 | 813 | ||
813 | /* Start the timer for a specific sequence table entry. */ | 814 | /* Start the timer for a specific sequence table entry. */ |
814 | static int intf_start_seq_timer(ipmi_smi_t intf, | 815 | static int intf_start_seq_timer(ipmi_smi_t intf, |
815 | long msgid) | 816 | long msgid) |
816 | { | 817 | { |
817 | int rv = -ENODEV; | 818 | int rv = -ENODEV; |
818 | unsigned long flags; | 819 | unsigned long flags; |
819 | unsigned char seq; | 820 | unsigned char seq; |
820 | unsigned long seqid; | 821 | unsigned long seqid; |
821 | 822 | ||
822 | 823 | ||
823 | GET_SEQ_FROM_MSGID(msgid, seq, seqid); | 824 | GET_SEQ_FROM_MSGID(msgid, seq, seqid); |
824 | 825 | ||
825 | spin_lock_irqsave(&(intf->seq_lock), flags); | 826 | spin_lock_irqsave(&(intf->seq_lock), flags); |
826 | /* | 827 | /* |
827 | * We do this verification because the user can be deleted | 828 | * We do this verification because the user can be deleted |
828 | * while a message is outstanding. | 829 | * while a message is outstanding. |
829 | */ | 830 | */ |
830 | if ((intf->seq_table[seq].inuse) | 831 | if ((intf->seq_table[seq].inuse) |
831 | && (intf->seq_table[seq].seqid == seqid)) { | 832 | && (intf->seq_table[seq].seqid == seqid)) { |
832 | struct seq_table *ent = &(intf->seq_table[seq]); | 833 | struct seq_table *ent = &(intf->seq_table[seq]); |
833 | ent->timeout = ent->orig_timeout; | 834 | ent->timeout = ent->orig_timeout; |
834 | rv = 0; | 835 | rv = 0; |
835 | } | 836 | } |
836 | spin_unlock_irqrestore(&(intf->seq_lock), flags); | 837 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
837 | 838 | ||
838 | return rv; | 839 | return rv; |
839 | } | 840 | } |
840 | 841 | ||
841 | /* Got an error for the send message for a specific sequence number. */ | 842 | /* Got an error for the send message for a specific sequence number. */ |
842 | static int intf_err_seq(ipmi_smi_t intf, | 843 | static int intf_err_seq(ipmi_smi_t intf, |
843 | long msgid, | 844 | long msgid, |
844 | unsigned int err) | 845 | unsigned int err) |
845 | { | 846 | { |
846 | int rv = -ENODEV; | 847 | int rv = -ENODEV; |
847 | unsigned long flags; | 848 | unsigned long flags; |
848 | unsigned char seq; | 849 | unsigned char seq; |
849 | unsigned long seqid; | 850 | unsigned long seqid; |
850 | struct ipmi_recv_msg *msg = NULL; | 851 | struct ipmi_recv_msg *msg = NULL; |
851 | 852 | ||
852 | 853 | ||
853 | GET_SEQ_FROM_MSGID(msgid, seq, seqid); | 854 | GET_SEQ_FROM_MSGID(msgid, seq, seqid); |
854 | 855 | ||
855 | spin_lock_irqsave(&(intf->seq_lock), flags); | 856 | spin_lock_irqsave(&(intf->seq_lock), flags); |
856 | /* | 857 | /* |
857 | * We do this verification because the user can be deleted | 858 | * We do this verification because the user can be deleted |
858 | * while a message is outstanding. | 859 | * while a message is outstanding. |
859 | */ | 860 | */ |
860 | if ((intf->seq_table[seq].inuse) | 861 | if ((intf->seq_table[seq].inuse) |
861 | && (intf->seq_table[seq].seqid == seqid)) { | 862 | && (intf->seq_table[seq].seqid == seqid)) { |
862 | struct seq_table *ent = &(intf->seq_table[seq]); | 863 | struct seq_table *ent = &(intf->seq_table[seq]); |
863 | 864 | ||
864 | ent->inuse = 0; | 865 | ent->inuse = 0; |
865 | msg = ent->recv_msg; | 866 | msg = ent->recv_msg; |
866 | rv = 0; | 867 | rv = 0; |
867 | } | 868 | } |
868 | spin_unlock_irqrestore(&(intf->seq_lock), flags); | 869 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
869 | 870 | ||
870 | if (msg) | 871 | if (msg) |
871 | deliver_err_response(msg, err); | 872 | deliver_err_response(msg, err); |
872 | 873 | ||
873 | return rv; | 874 | return rv; |
874 | } | 875 | } |
875 | 876 | ||
876 | 877 | ||
877 | int ipmi_create_user(unsigned int if_num, | 878 | int ipmi_create_user(unsigned int if_num, |
878 | struct ipmi_user_hndl *handler, | 879 | struct ipmi_user_hndl *handler, |
879 | void *handler_data, | 880 | void *handler_data, |
880 | ipmi_user_t *user) | 881 | ipmi_user_t *user) |
881 | { | 882 | { |
882 | unsigned long flags; | 883 | unsigned long flags; |
883 | ipmi_user_t new_user; | 884 | ipmi_user_t new_user; |
884 | int rv = 0; | 885 | int rv = 0; |
885 | ipmi_smi_t intf; | 886 | ipmi_smi_t intf; |
886 | 887 | ||
887 | /* | 888 | /* |
888 | * There is no module usecount here, because it's not | 889 | * There is no module usecount here, because it's not |
889 | * required. Since this can only be used by and called from | 890 | * required. Since this can only be used by and called from |
890 | * other modules, they will implicitly use this module, and | 891 | * other modules, they will implicitly use this module, and |
891 | * thus this can't be removed unless the other modules are | 892 | * thus this can't be removed unless the other modules are |
892 | * removed. | 893 | * removed. |
893 | */ | 894 | */ |
894 | 895 | ||
895 | if (handler == NULL) | 896 | if (handler == NULL) |
896 | return -EINVAL; | 897 | return -EINVAL; |
897 | 898 | ||
898 | /* | 899 | /* |
899 | * Make sure the driver is actually initialized, this handles | 900 | * Make sure the driver is actually initialized, this handles |
900 | * problems with initialization order. | 901 | * problems with initialization order. |
901 | */ | 902 | */ |
902 | if (!initialized) { | 903 | if (!initialized) { |
903 | rv = ipmi_init_msghandler(); | 904 | rv = ipmi_init_msghandler(); |
904 | if (rv) | 905 | if (rv) |
905 | return rv; | 906 | return rv; |
906 | 907 | ||
907 | /* | 908 | /* |
908 | * The init code doesn't return an error if it was turned | 909 | * The init code doesn't return an error if it was turned |
909 | * off, but it won't initialize. Check that. | 910 | * off, but it won't initialize. Check that. |
910 | */ | 911 | */ |
911 | if (!initialized) | 912 | if (!initialized) |
912 | return -ENODEV; | 913 | return -ENODEV; |
913 | } | 914 | } |
914 | 915 | ||
915 | new_user = kmalloc(sizeof(*new_user), GFP_KERNEL); | 916 | new_user = kmalloc(sizeof(*new_user), GFP_KERNEL); |
916 | if (!new_user) | 917 | if (!new_user) |
917 | return -ENOMEM; | 918 | return -ENOMEM; |
918 | 919 | ||
919 | mutex_lock(&ipmi_interfaces_mutex); | 920 | mutex_lock(&ipmi_interfaces_mutex); |
920 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { | 921 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
921 | if (intf->intf_num == if_num) | 922 | if (intf->intf_num == if_num) |
922 | goto found; | 923 | goto found; |
923 | } | 924 | } |
924 | /* Not found, return an error */ | 925 | /* Not found, return an error */ |
925 | rv = -EINVAL; | 926 | rv = -EINVAL; |
926 | goto out_kfree; | 927 | goto out_kfree; |
927 | 928 | ||
928 | found: | 929 | found: |
929 | /* Note that each existing user holds a refcount to the interface. */ | 930 | /* Note that each existing user holds a refcount to the interface. */ |
930 | kref_get(&intf->refcount); | 931 | kref_get(&intf->refcount); |
931 | 932 | ||
932 | kref_init(&new_user->refcount); | 933 | kref_init(&new_user->refcount); |
933 | new_user->handler = handler; | 934 | new_user->handler = handler; |
934 | new_user->handler_data = handler_data; | 935 | new_user->handler_data = handler_data; |
935 | new_user->intf = intf; | 936 | new_user->intf = intf; |
936 | new_user->gets_events = 0; | 937 | new_user->gets_events = 0; |
937 | 938 | ||
938 | if (!try_module_get(intf->handlers->owner)) { | 939 | if (!try_module_get(intf->handlers->owner)) { |
939 | rv = -ENODEV; | 940 | rv = -ENODEV; |
940 | goto out_kref; | 941 | goto out_kref; |
941 | } | 942 | } |
942 | 943 | ||
943 | if (intf->handlers->inc_usecount) { | 944 | if (intf->handlers->inc_usecount) { |
944 | rv = intf->handlers->inc_usecount(intf->send_info); | 945 | rv = intf->handlers->inc_usecount(intf->send_info); |
945 | if (rv) { | 946 | if (rv) { |
946 | module_put(intf->handlers->owner); | 947 | module_put(intf->handlers->owner); |
947 | goto out_kref; | 948 | goto out_kref; |
948 | } | 949 | } |
949 | } | 950 | } |
950 | 951 | ||
951 | /* | 952 | /* |
952 | * Hold the lock so intf->handlers is guaranteed to be good | 953 | * Hold the lock so intf->handlers is guaranteed to be good |
953 | * until now | 954 | * until now |
954 | */ | 955 | */ |
955 | mutex_unlock(&ipmi_interfaces_mutex); | 956 | mutex_unlock(&ipmi_interfaces_mutex); |
956 | 957 | ||
957 | new_user->valid = 1; | 958 | new_user->valid = 1; |
958 | spin_lock_irqsave(&intf->seq_lock, flags); | 959 | spin_lock_irqsave(&intf->seq_lock, flags); |
959 | list_add_rcu(&new_user->link, &intf->users); | 960 | list_add_rcu(&new_user->link, &intf->users); |
960 | spin_unlock_irqrestore(&intf->seq_lock, flags); | 961 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
961 | *user = new_user; | 962 | *user = new_user; |
962 | return 0; | 963 | return 0; |
963 | 964 | ||
964 | out_kref: | 965 | out_kref: |
965 | kref_put(&intf->refcount, intf_free); | 966 | kref_put(&intf->refcount, intf_free); |
966 | out_kfree: | 967 | out_kfree: |
967 | mutex_unlock(&ipmi_interfaces_mutex); | 968 | mutex_unlock(&ipmi_interfaces_mutex); |
968 | kfree(new_user); | 969 | kfree(new_user); |
969 | return rv; | 970 | return rv; |
970 | } | 971 | } |
971 | EXPORT_SYMBOL(ipmi_create_user); | 972 | EXPORT_SYMBOL(ipmi_create_user); |
972 | 973 | ||
973 | int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data) | 974 | int ipmi_get_smi_info(int if_num, struct ipmi_smi_info *data) |
974 | { | 975 | { |
975 | int rv = 0; | 976 | int rv = 0; |
976 | ipmi_smi_t intf; | 977 | ipmi_smi_t intf; |
977 | struct ipmi_smi_handlers *handlers; | 978 | struct ipmi_smi_handlers *handlers; |
978 | 979 | ||
979 | mutex_lock(&ipmi_interfaces_mutex); | 980 | mutex_lock(&ipmi_interfaces_mutex); |
980 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { | 981 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
981 | if (intf->intf_num == if_num) | 982 | if (intf->intf_num == if_num) |
982 | goto found; | 983 | goto found; |
983 | } | 984 | } |
984 | /* Not found, return an error */ | 985 | /* Not found, return an error */ |
985 | rv = -EINVAL; | 986 | rv = -EINVAL; |
986 | mutex_unlock(&ipmi_interfaces_mutex); | 987 | mutex_unlock(&ipmi_interfaces_mutex); |
987 | return rv; | 988 | return rv; |
988 | 989 | ||
989 | found: | 990 | found: |
990 | handlers = intf->handlers; | 991 | handlers = intf->handlers; |
991 | rv = -ENOSYS; | 992 | rv = -ENOSYS; |
992 | if (handlers->get_smi_info) | 993 | if (handlers->get_smi_info) |
993 | rv = handlers->get_smi_info(intf->send_info, data); | 994 | rv = handlers->get_smi_info(intf->send_info, data); |
994 | mutex_unlock(&ipmi_interfaces_mutex); | 995 | mutex_unlock(&ipmi_interfaces_mutex); |
995 | 996 | ||
996 | return rv; | 997 | return rv; |
997 | } | 998 | } |
998 | EXPORT_SYMBOL(ipmi_get_smi_info); | 999 | EXPORT_SYMBOL(ipmi_get_smi_info); |
999 | 1000 | ||
1000 | static void free_user(struct kref *ref) | 1001 | static void free_user(struct kref *ref) |
1001 | { | 1002 | { |
1002 | ipmi_user_t user = container_of(ref, struct ipmi_user, refcount); | 1003 | ipmi_user_t user = container_of(ref, struct ipmi_user, refcount); |
1003 | kfree(user); | 1004 | kfree(user); |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | int ipmi_destroy_user(ipmi_user_t user) | 1007 | int ipmi_destroy_user(ipmi_user_t user) |
1007 | { | 1008 | { |
1008 | ipmi_smi_t intf = user->intf; | 1009 | ipmi_smi_t intf = user->intf; |
1009 | int i; | 1010 | int i; |
1010 | unsigned long flags; | 1011 | unsigned long flags; |
1011 | struct cmd_rcvr *rcvr; | 1012 | struct cmd_rcvr *rcvr; |
1012 | struct cmd_rcvr *rcvrs = NULL; | 1013 | struct cmd_rcvr *rcvrs = NULL; |
1013 | 1014 | ||
1014 | user->valid = 0; | 1015 | user->valid = 0; |
1015 | 1016 | ||
1016 | /* Remove the user from the interface's sequence table. */ | 1017 | /* Remove the user from the interface's sequence table. */ |
1017 | spin_lock_irqsave(&intf->seq_lock, flags); | 1018 | spin_lock_irqsave(&intf->seq_lock, flags); |
1018 | list_del_rcu(&user->link); | 1019 | list_del_rcu(&user->link); |
1019 | 1020 | ||
1020 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { | 1021 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { |
1021 | if (intf->seq_table[i].inuse | 1022 | if (intf->seq_table[i].inuse |
1022 | && (intf->seq_table[i].recv_msg->user == user)) { | 1023 | && (intf->seq_table[i].recv_msg->user == user)) { |
1023 | intf->seq_table[i].inuse = 0; | 1024 | intf->seq_table[i].inuse = 0; |
1024 | ipmi_free_recv_msg(intf->seq_table[i].recv_msg); | 1025 | ipmi_free_recv_msg(intf->seq_table[i].recv_msg); |
1025 | } | 1026 | } |
1026 | } | 1027 | } |
1027 | spin_unlock_irqrestore(&intf->seq_lock, flags); | 1028 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
1028 | 1029 | ||
1029 | /* | 1030 | /* |
1030 | * Remove the user from the command receiver's table. First | 1031 | * Remove the user from the command receiver's table. First |
1031 | * we build a list of everything (not using the standard link, | 1032 | * we build a list of everything (not using the standard link, |
1032 | * since other things may be using it till we do | 1033 | * since other things may be using it till we do |
1033 | * synchronize_rcu()) then free everything in that list. | 1034 | * synchronize_rcu()) then free everything in that list. |
1034 | */ | 1035 | */ |
1035 | mutex_lock(&intf->cmd_rcvrs_mutex); | 1036 | mutex_lock(&intf->cmd_rcvrs_mutex); |
1036 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { | 1037 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { |
1037 | if (rcvr->user == user) { | 1038 | if (rcvr->user == user) { |
1038 | list_del_rcu(&rcvr->link); | 1039 | list_del_rcu(&rcvr->link); |
1039 | rcvr->next = rcvrs; | 1040 | rcvr->next = rcvrs; |
1040 | rcvrs = rcvr; | 1041 | rcvrs = rcvr; |
1041 | } | 1042 | } |
1042 | } | 1043 | } |
1043 | mutex_unlock(&intf->cmd_rcvrs_mutex); | 1044 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
1044 | synchronize_rcu(); | 1045 | synchronize_rcu(); |
1045 | while (rcvrs) { | 1046 | while (rcvrs) { |
1046 | rcvr = rcvrs; | 1047 | rcvr = rcvrs; |
1047 | rcvrs = rcvr->next; | 1048 | rcvrs = rcvr->next; |
1048 | kfree(rcvr); | 1049 | kfree(rcvr); |
1049 | } | 1050 | } |
1050 | 1051 | ||
1051 | mutex_lock(&ipmi_interfaces_mutex); | 1052 | mutex_lock(&ipmi_interfaces_mutex); |
1052 | if (intf->handlers) { | 1053 | if (intf->handlers) { |
1053 | module_put(intf->handlers->owner); | 1054 | module_put(intf->handlers->owner); |
1054 | if (intf->handlers->dec_usecount) | 1055 | if (intf->handlers->dec_usecount) |
1055 | intf->handlers->dec_usecount(intf->send_info); | 1056 | intf->handlers->dec_usecount(intf->send_info); |
1056 | } | 1057 | } |
1057 | mutex_unlock(&ipmi_interfaces_mutex); | 1058 | mutex_unlock(&ipmi_interfaces_mutex); |
1058 | 1059 | ||
1059 | kref_put(&intf->refcount, intf_free); | 1060 | kref_put(&intf->refcount, intf_free); |
1060 | 1061 | ||
1061 | kref_put(&user->refcount, free_user); | 1062 | kref_put(&user->refcount, free_user); |
1062 | 1063 | ||
1063 | return 0; | 1064 | return 0; |
1064 | } | 1065 | } |
1065 | EXPORT_SYMBOL(ipmi_destroy_user); | 1066 | EXPORT_SYMBOL(ipmi_destroy_user); |
1066 | 1067 | ||
1067 | void ipmi_get_version(ipmi_user_t user, | 1068 | void ipmi_get_version(ipmi_user_t user, |
1068 | unsigned char *major, | 1069 | unsigned char *major, |
1069 | unsigned char *minor) | 1070 | unsigned char *minor) |
1070 | { | 1071 | { |
1071 | *major = user->intf->ipmi_version_major; | 1072 | *major = user->intf->ipmi_version_major; |
1072 | *minor = user->intf->ipmi_version_minor; | 1073 | *minor = user->intf->ipmi_version_minor; |
1073 | } | 1074 | } |
1074 | EXPORT_SYMBOL(ipmi_get_version); | 1075 | EXPORT_SYMBOL(ipmi_get_version); |
1075 | 1076 | ||
1076 | int ipmi_set_my_address(ipmi_user_t user, | 1077 | int ipmi_set_my_address(ipmi_user_t user, |
1077 | unsigned int channel, | 1078 | unsigned int channel, |
1078 | unsigned char address) | 1079 | unsigned char address) |
1079 | { | 1080 | { |
1080 | if (channel >= IPMI_MAX_CHANNELS) | 1081 | if (channel >= IPMI_MAX_CHANNELS) |
1081 | return -EINVAL; | 1082 | return -EINVAL; |
1082 | user->intf->channels[channel].address = address; | 1083 | user->intf->channels[channel].address = address; |
1083 | return 0; | 1084 | return 0; |
1084 | } | 1085 | } |
1085 | EXPORT_SYMBOL(ipmi_set_my_address); | 1086 | EXPORT_SYMBOL(ipmi_set_my_address); |
1086 | 1087 | ||
1087 | int ipmi_get_my_address(ipmi_user_t user, | 1088 | int ipmi_get_my_address(ipmi_user_t user, |
1088 | unsigned int channel, | 1089 | unsigned int channel, |
1089 | unsigned char *address) | 1090 | unsigned char *address) |
1090 | { | 1091 | { |
1091 | if (channel >= IPMI_MAX_CHANNELS) | 1092 | if (channel >= IPMI_MAX_CHANNELS) |
1092 | return -EINVAL; | 1093 | return -EINVAL; |
1093 | *address = user->intf->channels[channel].address; | 1094 | *address = user->intf->channels[channel].address; |
1094 | return 0; | 1095 | return 0; |
1095 | } | 1096 | } |
1096 | EXPORT_SYMBOL(ipmi_get_my_address); | 1097 | EXPORT_SYMBOL(ipmi_get_my_address); |
1097 | 1098 | ||
1098 | int ipmi_set_my_LUN(ipmi_user_t user, | 1099 | int ipmi_set_my_LUN(ipmi_user_t user, |
1099 | unsigned int channel, | 1100 | unsigned int channel, |
1100 | unsigned char LUN) | 1101 | unsigned char LUN) |
1101 | { | 1102 | { |
1102 | if (channel >= IPMI_MAX_CHANNELS) | 1103 | if (channel >= IPMI_MAX_CHANNELS) |
1103 | return -EINVAL; | 1104 | return -EINVAL; |
1104 | user->intf->channels[channel].lun = LUN & 0x3; | 1105 | user->intf->channels[channel].lun = LUN & 0x3; |
1105 | return 0; | 1106 | return 0; |
1106 | } | 1107 | } |
1107 | EXPORT_SYMBOL(ipmi_set_my_LUN); | 1108 | EXPORT_SYMBOL(ipmi_set_my_LUN); |
1108 | 1109 | ||
1109 | int ipmi_get_my_LUN(ipmi_user_t user, | 1110 | int ipmi_get_my_LUN(ipmi_user_t user, |
1110 | unsigned int channel, | 1111 | unsigned int channel, |
1111 | unsigned char *address) | 1112 | unsigned char *address) |
1112 | { | 1113 | { |
1113 | if (channel >= IPMI_MAX_CHANNELS) | 1114 | if (channel >= IPMI_MAX_CHANNELS) |
1114 | return -EINVAL; | 1115 | return -EINVAL; |
1115 | *address = user->intf->channels[channel].lun; | 1116 | *address = user->intf->channels[channel].lun; |
1116 | return 0; | 1117 | return 0; |
1117 | } | 1118 | } |
1118 | EXPORT_SYMBOL(ipmi_get_my_LUN); | 1119 | EXPORT_SYMBOL(ipmi_get_my_LUN); |
1119 | 1120 | ||
1120 | int ipmi_get_maintenance_mode(ipmi_user_t user) | 1121 | int ipmi_get_maintenance_mode(ipmi_user_t user) |
1121 | { | 1122 | { |
1122 | int mode; | 1123 | int mode; |
1123 | unsigned long flags; | 1124 | unsigned long flags; |
1124 | 1125 | ||
1125 | spin_lock_irqsave(&user->intf->maintenance_mode_lock, flags); | 1126 | spin_lock_irqsave(&user->intf->maintenance_mode_lock, flags); |
1126 | mode = user->intf->maintenance_mode; | 1127 | mode = user->intf->maintenance_mode; |
1127 | spin_unlock_irqrestore(&user->intf->maintenance_mode_lock, flags); | 1128 | spin_unlock_irqrestore(&user->intf->maintenance_mode_lock, flags); |
1128 | 1129 | ||
1129 | return mode; | 1130 | return mode; |
1130 | } | 1131 | } |
1131 | EXPORT_SYMBOL(ipmi_get_maintenance_mode); | 1132 | EXPORT_SYMBOL(ipmi_get_maintenance_mode); |
1132 | 1133 | ||
1133 | static void maintenance_mode_update(ipmi_smi_t intf) | 1134 | static void maintenance_mode_update(ipmi_smi_t intf) |
1134 | { | 1135 | { |
1135 | if (intf->handlers->set_maintenance_mode) | 1136 | if (intf->handlers->set_maintenance_mode) |
1136 | intf->handlers->set_maintenance_mode( | 1137 | intf->handlers->set_maintenance_mode( |
1137 | intf->send_info, intf->maintenance_mode_enable); | 1138 | intf->send_info, intf->maintenance_mode_enable); |
1138 | } | 1139 | } |
1139 | 1140 | ||
1140 | int ipmi_set_maintenance_mode(ipmi_user_t user, int mode) | 1141 | int ipmi_set_maintenance_mode(ipmi_user_t user, int mode) |
1141 | { | 1142 | { |
1142 | int rv = 0; | 1143 | int rv = 0; |
1143 | unsigned long flags; | 1144 | unsigned long flags; |
1144 | ipmi_smi_t intf = user->intf; | 1145 | ipmi_smi_t intf = user->intf; |
1145 | 1146 | ||
1146 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); | 1147 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); |
1147 | if (intf->maintenance_mode != mode) { | 1148 | if (intf->maintenance_mode != mode) { |
1148 | switch (mode) { | 1149 | switch (mode) { |
1149 | case IPMI_MAINTENANCE_MODE_AUTO: | 1150 | case IPMI_MAINTENANCE_MODE_AUTO: |
1150 | intf->maintenance_mode = mode; | 1151 | intf->maintenance_mode = mode; |
1151 | intf->maintenance_mode_enable | 1152 | intf->maintenance_mode_enable |
1152 | = (intf->auto_maintenance_timeout > 0); | 1153 | = (intf->auto_maintenance_timeout > 0); |
1153 | break; | 1154 | break; |
1154 | 1155 | ||
1155 | case IPMI_MAINTENANCE_MODE_OFF: | 1156 | case IPMI_MAINTENANCE_MODE_OFF: |
1156 | intf->maintenance_mode = mode; | 1157 | intf->maintenance_mode = mode; |
1157 | intf->maintenance_mode_enable = 0; | 1158 | intf->maintenance_mode_enable = 0; |
1158 | break; | 1159 | break; |
1159 | 1160 | ||
1160 | case IPMI_MAINTENANCE_MODE_ON: | 1161 | case IPMI_MAINTENANCE_MODE_ON: |
1161 | intf->maintenance_mode = mode; | 1162 | intf->maintenance_mode = mode; |
1162 | intf->maintenance_mode_enable = 1; | 1163 | intf->maintenance_mode_enable = 1; |
1163 | break; | 1164 | break; |
1164 | 1165 | ||
1165 | default: | 1166 | default: |
1166 | rv = -EINVAL; | 1167 | rv = -EINVAL; |
1167 | goto out_unlock; | 1168 | goto out_unlock; |
1168 | } | 1169 | } |
1169 | 1170 | ||
1170 | maintenance_mode_update(intf); | 1171 | maintenance_mode_update(intf); |
1171 | } | 1172 | } |
1172 | out_unlock: | 1173 | out_unlock: |
1173 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, flags); | 1174 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, flags); |
1174 | 1175 | ||
1175 | return rv; | 1176 | return rv; |
1176 | } | 1177 | } |
1177 | EXPORT_SYMBOL(ipmi_set_maintenance_mode); | 1178 | EXPORT_SYMBOL(ipmi_set_maintenance_mode); |
1178 | 1179 | ||
1179 | int ipmi_set_gets_events(ipmi_user_t user, int val) | 1180 | int ipmi_set_gets_events(ipmi_user_t user, int val) |
1180 | { | 1181 | { |
1181 | unsigned long flags; | 1182 | unsigned long flags; |
1182 | ipmi_smi_t intf = user->intf; | 1183 | ipmi_smi_t intf = user->intf; |
1183 | struct ipmi_recv_msg *msg, *msg2; | 1184 | struct ipmi_recv_msg *msg, *msg2; |
1184 | struct list_head msgs; | 1185 | struct list_head msgs; |
1185 | 1186 | ||
1186 | INIT_LIST_HEAD(&msgs); | 1187 | INIT_LIST_HEAD(&msgs); |
1187 | 1188 | ||
1188 | spin_lock_irqsave(&intf->events_lock, flags); | 1189 | spin_lock_irqsave(&intf->events_lock, flags); |
1189 | user->gets_events = val; | 1190 | user->gets_events = val; |
1190 | 1191 | ||
1191 | if (intf->delivering_events) | 1192 | if (intf->delivering_events) |
1192 | /* | 1193 | /* |
1193 | * Another thread is delivering events for this, so | 1194 | * Another thread is delivering events for this, so |
1194 | * let it handle any new events. | 1195 | * let it handle any new events. |
1195 | */ | 1196 | */ |
1196 | goto out; | 1197 | goto out; |
1197 | 1198 | ||
1198 | /* Deliver any queued events. */ | 1199 | /* Deliver any queued events. */ |
1199 | while (user->gets_events && !list_empty(&intf->waiting_events)) { | 1200 | while (user->gets_events && !list_empty(&intf->waiting_events)) { |
1200 | list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) | 1201 | list_for_each_entry_safe(msg, msg2, &intf->waiting_events, link) |
1201 | list_move_tail(&msg->link, &msgs); | 1202 | list_move_tail(&msg->link, &msgs); |
1202 | intf->waiting_events_count = 0; | 1203 | intf->waiting_events_count = 0; |
1203 | if (intf->event_msg_printed) { | 1204 | if (intf->event_msg_printed) { |
1204 | printk(KERN_WARNING PFX "Event queue no longer" | 1205 | printk(KERN_WARNING PFX "Event queue no longer" |
1205 | " full\n"); | 1206 | " full\n"); |
1206 | intf->event_msg_printed = 0; | 1207 | intf->event_msg_printed = 0; |
1207 | } | 1208 | } |
1208 | 1209 | ||
1209 | intf->delivering_events = 1; | 1210 | intf->delivering_events = 1; |
1210 | spin_unlock_irqrestore(&intf->events_lock, flags); | 1211 | spin_unlock_irqrestore(&intf->events_lock, flags); |
1211 | 1212 | ||
1212 | list_for_each_entry_safe(msg, msg2, &msgs, link) { | 1213 | list_for_each_entry_safe(msg, msg2, &msgs, link) { |
1213 | msg->user = user; | 1214 | msg->user = user; |
1214 | kref_get(&user->refcount); | 1215 | kref_get(&user->refcount); |
1215 | deliver_response(msg); | 1216 | deliver_response(msg); |
1216 | } | 1217 | } |
1217 | 1218 | ||
1218 | spin_lock_irqsave(&intf->events_lock, flags); | 1219 | spin_lock_irqsave(&intf->events_lock, flags); |
1219 | intf->delivering_events = 0; | 1220 | intf->delivering_events = 0; |
1220 | } | 1221 | } |
1221 | 1222 | ||
1222 | out: | 1223 | out: |
1223 | spin_unlock_irqrestore(&intf->events_lock, flags); | 1224 | spin_unlock_irqrestore(&intf->events_lock, flags); |
1224 | 1225 | ||
1225 | return 0; | 1226 | return 0; |
1226 | } | 1227 | } |
1227 | EXPORT_SYMBOL(ipmi_set_gets_events); | 1228 | EXPORT_SYMBOL(ipmi_set_gets_events); |
1228 | 1229 | ||
1229 | static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf, | 1230 | static struct cmd_rcvr *find_cmd_rcvr(ipmi_smi_t intf, |
1230 | unsigned char netfn, | 1231 | unsigned char netfn, |
1231 | unsigned char cmd, | 1232 | unsigned char cmd, |
1232 | unsigned char chan) | 1233 | unsigned char chan) |
1233 | { | 1234 | { |
1234 | struct cmd_rcvr *rcvr; | 1235 | struct cmd_rcvr *rcvr; |
1235 | 1236 | ||
1236 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { | 1237 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { |
1237 | if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) | 1238 | if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) |
1238 | && (rcvr->chans & (1 << chan))) | 1239 | && (rcvr->chans & (1 << chan))) |
1239 | return rcvr; | 1240 | return rcvr; |
1240 | } | 1241 | } |
1241 | return NULL; | 1242 | return NULL; |
1242 | } | 1243 | } |
1243 | 1244 | ||
1244 | static int is_cmd_rcvr_exclusive(ipmi_smi_t intf, | 1245 | static int is_cmd_rcvr_exclusive(ipmi_smi_t intf, |
1245 | unsigned char netfn, | 1246 | unsigned char netfn, |
1246 | unsigned char cmd, | 1247 | unsigned char cmd, |
1247 | unsigned int chans) | 1248 | unsigned int chans) |
1248 | { | 1249 | { |
1249 | struct cmd_rcvr *rcvr; | 1250 | struct cmd_rcvr *rcvr; |
1250 | 1251 | ||
1251 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { | 1252 | list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { |
1252 | if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) | 1253 | if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) |
1253 | && (rcvr->chans & chans)) | 1254 | && (rcvr->chans & chans)) |
1254 | return 0; | 1255 | return 0; |
1255 | } | 1256 | } |
1256 | return 1; | 1257 | return 1; |
1257 | } | 1258 | } |
1258 | 1259 | ||
1259 | int ipmi_register_for_cmd(ipmi_user_t user, | 1260 | int ipmi_register_for_cmd(ipmi_user_t user, |
1260 | unsigned char netfn, | 1261 | unsigned char netfn, |
1261 | unsigned char cmd, | 1262 | unsigned char cmd, |
1262 | unsigned int chans) | 1263 | unsigned int chans) |
1263 | { | 1264 | { |
1264 | ipmi_smi_t intf = user->intf; | 1265 | ipmi_smi_t intf = user->intf; |
1265 | struct cmd_rcvr *rcvr; | 1266 | struct cmd_rcvr *rcvr; |
1266 | int rv = 0; | 1267 | int rv = 0; |
1267 | 1268 | ||
1268 | 1269 | ||
1269 | rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL); | 1270 | rcvr = kmalloc(sizeof(*rcvr), GFP_KERNEL); |
1270 | if (!rcvr) | 1271 | if (!rcvr) |
1271 | return -ENOMEM; | 1272 | return -ENOMEM; |
1272 | rcvr->cmd = cmd; | 1273 | rcvr->cmd = cmd; |
1273 | rcvr->netfn = netfn; | 1274 | rcvr->netfn = netfn; |
1274 | rcvr->chans = chans; | 1275 | rcvr->chans = chans; |
1275 | rcvr->user = user; | 1276 | rcvr->user = user; |
1276 | 1277 | ||
1277 | mutex_lock(&intf->cmd_rcvrs_mutex); | 1278 | mutex_lock(&intf->cmd_rcvrs_mutex); |
1278 | /* Make sure the command/netfn is not already registered. */ | 1279 | /* Make sure the command/netfn is not already registered. */ |
1279 | if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) { | 1280 | if (!is_cmd_rcvr_exclusive(intf, netfn, cmd, chans)) { |
1280 | rv = -EBUSY; | 1281 | rv = -EBUSY; |
1281 | goto out_unlock; | 1282 | goto out_unlock; |
1282 | } | 1283 | } |
1283 | 1284 | ||
1284 | list_add_rcu(&rcvr->link, &intf->cmd_rcvrs); | 1285 | list_add_rcu(&rcvr->link, &intf->cmd_rcvrs); |
1285 | 1286 | ||
1286 | out_unlock: | 1287 | out_unlock: |
1287 | mutex_unlock(&intf->cmd_rcvrs_mutex); | 1288 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
1288 | if (rv) | 1289 | if (rv) |
1289 | kfree(rcvr); | 1290 | kfree(rcvr); |
1290 | 1291 | ||
1291 | return rv; | 1292 | return rv; |
1292 | } | 1293 | } |
1293 | EXPORT_SYMBOL(ipmi_register_for_cmd); | 1294 | EXPORT_SYMBOL(ipmi_register_for_cmd); |
1294 | 1295 | ||
1295 | int ipmi_unregister_for_cmd(ipmi_user_t user, | 1296 | int ipmi_unregister_for_cmd(ipmi_user_t user, |
1296 | unsigned char netfn, | 1297 | unsigned char netfn, |
1297 | unsigned char cmd, | 1298 | unsigned char cmd, |
1298 | unsigned int chans) | 1299 | unsigned int chans) |
1299 | { | 1300 | { |
1300 | ipmi_smi_t intf = user->intf; | 1301 | ipmi_smi_t intf = user->intf; |
1301 | struct cmd_rcvr *rcvr; | 1302 | struct cmd_rcvr *rcvr; |
1302 | struct cmd_rcvr *rcvrs = NULL; | 1303 | struct cmd_rcvr *rcvrs = NULL; |
1303 | int i, rv = -ENOENT; | 1304 | int i, rv = -ENOENT; |
1304 | 1305 | ||
1305 | mutex_lock(&intf->cmd_rcvrs_mutex); | 1306 | mutex_lock(&intf->cmd_rcvrs_mutex); |
1306 | for (i = 0; i < IPMI_NUM_CHANNELS; i++) { | 1307 | for (i = 0; i < IPMI_NUM_CHANNELS; i++) { |
1307 | if (((1 << i) & chans) == 0) | 1308 | if (((1 << i) & chans) == 0) |
1308 | continue; | 1309 | continue; |
1309 | rcvr = find_cmd_rcvr(intf, netfn, cmd, i); | 1310 | rcvr = find_cmd_rcvr(intf, netfn, cmd, i); |
1310 | if (rcvr == NULL) | 1311 | if (rcvr == NULL) |
1311 | continue; | 1312 | continue; |
1312 | if (rcvr->user == user) { | 1313 | if (rcvr->user == user) { |
1313 | rv = 0; | 1314 | rv = 0; |
1314 | rcvr->chans &= ~chans; | 1315 | rcvr->chans &= ~chans; |
1315 | if (rcvr->chans == 0) { | 1316 | if (rcvr->chans == 0) { |
1316 | list_del_rcu(&rcvr->link); | 1317 | list_del_rcu(&rcvr->link); |
1317 | rcvr->next = rcvrs; | 1318 | rcvr->next = rcvrs; |
1318 | rcvrs = rcvr; | 1319 | rcvrs = rcvr; |
1319 | } | 1320 | } |
1320 | } | 1321 | } |
1321 | } | 1322 | } |
1322 | mutex_unlock(&intf->cmd_rcvrs_mutex); | 1323 | mutex_unlock(&intf->cmd_rcvrs_mutex); |
1323 | synchronize_rcu(); | 1324 | synchronize_rcu(); |
1324 | while (rcvrs) { | 1325 | while (rcvrs) { |
1325 | rcvr = rcvrs; | 1326 | rcvr = rcvrs; |
1326 | rcvrs = rcvr->next; | 1327 | rcvrs = rcvr->next; |
1327 | kfree(rcvr); | 1328 | kfree(rcvr); |
1328 | } | 1329 | } |
1329 | return rv; | 1330 | return rv; |
1330 | } | 1331 | } |
1331 | EXPORT_SYMBOL(ipmi_unregister_for_cmd); | 1332 | EXPORT_SYMBOL(ipmi_unregister_for_cmd); |
1332 | 1333 | ||
1333 | static unsigned char | 1334 | static unsigned char |
1334 | ipmb_checksum(unsigned char *data, int size) | 1335 | ipmb_checksum(unsigned char *data, int size) |
1335 | { | 1336 | { |
1336 | unsigned char csum = 0; | 1337 | unsigned char csum = 0; |
1337 | 1338 | ||
1338 | for (; size > 0; size--, data++) | 1339 | for (; size > 0; size--, data++) |
1339 | csum += *data; | 1340 | csum += *data; |
1340 | 1341 | ||
1341 | return -csum; | 1342 | return -csum; |
1342 | } | 1343 | } |
1343 | 1344 | ||
1344 | static inline void format_ipmb_msg(struct ipmi_smi_msg *smi_msg, | 1345 | static inline void format_ipmb_msg(struct ipmi_smi_msg *smi_msg, |
1345 | struct kernel_ipmi_msg *msg, | 1346 | struct kernel_ipmi_msg *msg, |
1346 | struct ipmi_ipmb_addr *ipmb_addr, | 1347 | struct ipmi_ipmb_addr *ipmb_addr, |
1347 | long msgid, | 1348 | long msgid, |
1348 | unsigned char ipmb_seq, | 1349 | unsigned char ipmb_seq, |
1349 | int broadcast, | 1350 | int broadcast, |
1350 | unsigned char source_address, | 1351 | unsigned char source_address, |
1351 | unsigned char source_lun) | 1352 | unsigned char source_lun) |
1352 | { | 1353 | { |
1353 | int i = broadcast; | 1354 | int i = broadcast; |
1354 | 1355 | ||
1355 | /* Format the IPMB header data. */ | 1356 | /* Format the IPMB header data. */ |
1356 | smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); | 1357 | smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
1357 | smi_msg->data[1] = IPMI_SEND_MSG_CMD; | 1358 | smi_msg->data[1] = IPMI_SEND_MSG_CMD; |
1358 | smi_msg->data[2] = ipmb_addr->channel; | 1359 | smi_msg->data[2] = ipmb_addr->channel; |
1359 | if (broadcast) | 1360 | if (broadcast) |
1360 | smi_msg->data[3] = 0; | 1361 | smi_msg->data[3] = 0; |
1361 | smi_msg->data[i+3] = ipmb_addr->slave_addr; | 1362 | smi_msg->data[i+3] = ipmb_addr->slave_addr; |
1362 | smi_msg->data[i+4] = (msg->netfn << 2) | (ipmb_addr->lun & 0x3); | 1363 | smi_msg->data[i+4] = (msg->netfn << 2) | (ipmb_addr->lun & 0x3); |
1363 | smi_msg->data[i+5] = ipmb_checksum(&(smi_msg->data[i+3]), 2); | 1364 | smi_msg->data[i+5] = ipmb_checksum(&(smi_msg->data[i+3]), 2); |
1364 | smi_msg->data[i+6] = source_address; | 1365 | smi_msg->data[i+6] = source_address; |
1365 | smi_msg->data[i+7] = (ipmb_seq << 2) | source_lun; | 1366 | smi_msg->data[i+7] = (ipmb_seq << 2) | source_lun; |
1366 | smi_msg->data[i+8] = msg->cmd; | 1367 | smi_msg->data[i+8] = msg->cmd; |
1367 | 1368 | ||
1368 | /* Now tack on the data to the message. */ | 1369 | /* Now tack on the data to the message. */ |
1369 | if (msg->data_len > 0) | 1370 | if (msg->data_len > 0) |
1370 | memcpy(&(smi_msg->data[i+9]), msg->data, | 1371 | memcpy(&(smi_msg->data[i+9]), msg->data, |
1371 | msg->data_len); | 1372 | msg->data_len); |
1372 | smi_msg->data_size = msg->data_len + 9; | 1373 | smi_msg->data_size = msg->data_len + 9; |
1373 | 1374 | ||
1374 | /* Now calculate the checksum and tack it on. */ | 1375 | /* Now calculate the checksum and tack it on. */ |
1375 | smi_msg->data[i+smi_msg->data_size] | 1376 | smi_msg->data[i+smi_msg->data_size] |
1376 | = ipmb_checksum(&(smi_msg->data[i+6]), | 1377 | = ipmb_checksum(&(smi_msg->data[i+6]), |
1377 | smi_msg->data_size-6); | 1378 | smi_msg->data_size-6); |
1378 | 1379 | ||
1379 | /* | 1380 | /* |
1380 | * Add on the checksum size and the offset from the | 1381 | * Add on the checksum size and the offset from the |
1381 | * broadcast. | 1382 | * broadcast. |
1382 | */ | 1383 | */ |
1383 | smi_msg->data_size += 1 + i; | 1384 | smi_msg->data_size += 1 + i; |
1384 | 1385 | ||
1385 | smi_msg->msgid = msgid; | 1386 | smi_msg->msgid = msgid; |
1386 | } | 1387 | } |
1387 | 1388 | ||
1388 | static inline void format_lan_msg(struct ipmi_smi_msg *smi_msg, | 1389 | static inline void format_lan_msg(struct ipmi_smi_msg *smi_msg, |
1389 | struct kernel_ipmi_msg *msg, | 1390 | struct kernel_ipmi_msg *msg, |
1390 | struct ipmi_lan_addr *lan_addr, | 1391 | struct ipmi_lan_addr *lan_addr, |
1391 | long msgid, | 1392 | long msgid, |
1392 | unsigned char ipmb_seq, | 1393 | unsigned char ipmb_seq, |
1393 | unsigned char source_lun) | 1394 | unsigned char source_lun) |
1394 | { | 1395 | { |
1395 | /* Format the IPMB header data. */ | 1396 | /* Format the IPMB header data. */ |
1396 | smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); | 1397 | smi_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
1397 | smi_msg->data[1] = IPMI_SEND_MSG_CMD; | 1398 | smi_msg->data[1] = IPMI_SEND_MSG_CMD; |
1398 | smi_msg->data[2] = lan_addr->channel; | 1399 | smi_msg->data[2] = lan_addr->channel; |
1399 | smi_msg->data[3] = lan_addr->session_handle; | 1400 | smi_msg->data[3] = lan_addr->session_handle; |
1400 | smi_msg->data[4] = lan_addr->remote_SWID; | 1401 | smi_msg->data[4] = lan_addr->remote_SWID; |
1401 | smi_msg->data[5] = (msg->netfn << 2) | (lan_addr->lun & 0x3); | 1402 | smi_msg->data[5] = (msg->netfn << 2) | (lan_addr->lun & 0x3); |
1402 | smi_msg->data[6] = ipmb_checksum(&(smi_msg->data[4]), 2); | 1403 | smi_msg->data[6] = ipmb_checksum(&(smi_msg->data[4]), 2); |
1403 | smi_msg->data[7] = lan_addr->local_SWID; | 1404 | smi_msg->data[7] = lan_addr->local_SWID; |
1404 | smi_msg->data[8] = (ipmb_seq << 2) | source_lun; | 1405 | smi_msg->data[8] = (ipmb_seq << 2) | source_lun; |
1405 | smi_msg->data[9] = msg->cmd; | 1406 | smi_msg->data[9] = msg->cmd; |
1406 | 1407 | ||
1407 | /* Now tack on the data to the message. */ | 1408 | /* Now tack on the data to the message. */ |
1408 | if (msg->data_len > 0) | 1409 | if (msg->data_len > 0) |
1409 | memcpy(&(smi_msg->data[10]), msg->data, | 1410 | memcpy(&(smi_msg->data[10]), msg->data, |
1410 | msg->data_len); | 1411 | msg->data_len); |
1411 | smi_msg->data_size = msg->data_len + 10; | 1412 | smi_msg->data_size = msg->data_len + 10; |
1412 | 1413 | ||
1413 | /* Now calculate the checksum and tack it on. */ | 1414 | /* Now calculate the checksum and tack it on. */ |
1414 | smi_msg->data[smi_msg->data_size] | 1415 | smi_msg->data[smi_msg->data_size] |
1415 | = ipmb_checksum(&(smi_msg->data[7]), | 1416 | = ipmb_checksum(&(smi_msg->data[7]), |
1416 | smi_msg->data_size-7); | 1417 | smi_msg->data_size-7); |
1417 | 1418 | ||
1418 | /* | 1419 | /* |
1419 | * Add on the checksum size and the offset from the | 1420 | * Add on the checksum size and the offset from the |
1420 | * broadcast. | 1421 | * broadcast. |
1421 | */ | 1422 | */ |
1422 | smi_msg->data_size += 1; | 1423 | smi_msg->data_size += 1; |
1423 | 1424 | ||
1424 | smi_msg->msgid = msgid; | 1425 | smi_msg->msgid = msgid; |
1425 | } | 1426 | } |
1426 | 1427 | ||
1427 | /* | 1428 | /* |
1428 | * Separate from ipmi_request so that the user does not have to be | 1429 | * Separate from ipmi_request so that the user does not have to be |
1429 | * supplied in certain circumstances (mainly at panic time). If | 1430 | * supplied in certain circumstances (mainly at panic time). If |
1430 | * messages are supplied, they will be freed, even if an error | 1431 | * messages are supplied, they will be freed, even if an error |
1431 | * occurs. | 1432 | * occurs. |
1432 | */ | 1433 | */ |
1433 | static int i_ipmi_request(ipmi_user_t user, | 1434 | static int i_ipmi_request(ipmi_user_t user, |
1434 | ipmi_smi_t intf, | 1435 | ipmi_smi_t intf, |
1435 | struct ipmi_addr *addr, | 1436 | struct ipmi_addr *addr, |
1436 | long msgid, | 1437 | long msgid, |
1437 | struct kernel_ipmi_msg *msg, | 1438 | struct kernel_ipmi_msg *msg, |
1438 | void *user_msg_data, | 1439 | void *user_msg_data, |
1439 | void *supplied_smi, | 1440 | void *supplied_smi, |
1440 | struct ipmi_recv_msg *supplied_recv, | 1441 | struct ipmi_recv_msg *supplied_recv, |
1441 | int priority, | 1442 | int priority, |
1442 | unsigned char source_address, | 1443 | unsigned char source_address, |
1443 | unsigned char source_lun, | 1444 | unsigned char source_lun, |
1444 | int retries, | 1445 | int retries, |
1445 | unsigned int retry_time_ms) | 1446 | unsigned int retry_time_ms) |
1446 | { | 1447 | { |
1447 | int rv = 0; | 1448 | int rv = 0; |
1448 | struct ipmi_smi_msg *smi_msg; | 1449 | struct ipmi_smi_msg *smi_msg; |
1449 | struct ipmi_recv_msg *recv_msg; | 1450 | struct ipmi_recv_msg *recv_msg; |
1450 | unsigned long flags; | 1451 | unsigned long flags; |
1451 | struct ipmi_smi_handlers *handlers; | 1452 | struct ipmi_smi_handlers *handlers; |
1452 | 1453 | ||
1453 | 1454 | ||
1454 | if (supplied_recv) | 1455 | if (supplied_recv) |
1455 | recv_msg = supplied_recv; | 1456 | recv_msg = supplied_recv; |
1456 | else { | 1457 | else { |
1457 | recv_msg = ipmi_alloc_recv_msg(); | 1458 | recv_msg = ipmi_alloc_recv_msg(); |
1458 | if (recv_msg == NULL) | 1459 | if (recv_msg == NULL) |
1459 | return -ENOMEM; | 1460 | return -ENOMEM; |
1460 | } | 1461 | } |
1461 | recv_msg->user_msg_data = user_msg_data; | 1462 | recv_msg->user_msg_data = user_msg_data; |
1462 | 1463 | ||
1463 | if (supplied_smi) | 1464 | if (supplied_smi) |
1464 | smi_msg = (struct ipmi_smi_msg *) supplied_smi; | 1465 | smi_msg = (struct ipmi_smi_msg *) supplied_smi; |
1465 | else { | 1466 | else { |
1466 | smi_msg = ipmi_alloc_smi_msg(); | 1467 | smi_msg = ipmi_alloc_smi_msg(); |
1467 | if (smi_msg == NULL) { | 1468 | if (smi_msg == NULL) { |
1468 | ipmi_free_recv_msg(recv_msg); | 1469 | ipmi_free_recv_msg(recv_msg); |
1469 | return -ENOMEM; | 1470 | return -ENOMEM; |
1470 | } | 1471 | } |
1471 | } | 1472 | } |
1472 | 1473 | ||
1473 | rcu_read_lock(); | 1474 | rcu_read_lock(); |
1474 | handlers = intf->handlers; | 1475 | handlers = intf->handlers; |
1475 | if (!handlers) { | 1476 | if (!handlers) { |
1476 | rv = -ENODEV; | 1477 | rv = -ENODEV; |
1477 | goto out_err; | 1478 | goto out_err; |
1478 | } | 1479 | } |
1479 | 1480 | ||
1480 | recv_msg->user = user; | 1481 | recv_msg->user = user; |
1481 | if (user) | 1482 | if (user) |
1482 | kref_get(&user->refcount); | 1483 | kref_get(&user->refcount); |
1483 | recv_msg->msgid = msgid; | 1484 | recv_msg->msgid = msgid; |
1484 | /* | 1485 | /* |
1485 | * Store the message to send in the receive message so timeout | 1486 | * Store the message to send in the receive message so timeout |
1486 | * responses can get the proper response data. | 1487 | * responses can get the proper response data. |
1487 | */ | 1488 | */ |
1488 | recv_msg->msg = *msg; | 1489 | recv_msg->msg = *msg; |
1489 | 1490 | ||
1490 | if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { | 1491 | if (addr->addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) { |
1491 | struct ipmi_system_interface_addr *smi_addr; | 1492 | struct ipmi_system_interface_addr *smi_addr; |
1492 | 1493 | ||
1493 | if (msg->netfn & 1) { | 1494 | if (msg->netfn & 1) { |
1494 | /* Responses are not allowed to the SMI. */ | 1495 | /* Responses are not allowed to the SMI. */ |
1495 | rv = -EINVAL; | 1496 | rv = -EINVAL; |
1496 | goto out_err; | 1497 | goto out_err; |
1497 | } | 1498 | } |
1498 | 1499 | ||
1499 | smi_addr = (struct ipmi_system_interface_addr *) addr; | 1500 | smi_addr = (struct ipmi_system_interface_addr *) addr; |
1500 | if (smi_addr->lun > 3) { | 1501 | if (smi_addr->lun > 3) { |
1501 | ipmi_inc_stat(intf, sent_invalid_commands); | 1502 | ipmi_inc_stat(intf, sent_invalid_commands); |
1502 | rv = -EINVAL; | 1503 | rv = -EINVAL; |
1503 | goto out_err; | 1504 | goto out_err; |
1504 | } | 1505 | } |
1505 | 1506 | ||
1506 | memcpy(&recv_msg->addr, smi_addr, sizeof(*smi_addr)); | 1507 | memcpy(&recv_msg->addr, smi_addr, sizeof(*smi_addr)); |
1507 | 1508 | ||
1508 | if ((msg->netfn == IPMI_NETFN_APP_REQUEST) | 1509 | if ((msg->netfn == IPMI_NETFN_APP_REQUEST) |
1509 | && ((msg->cmd == IPMI_SEND_MSG_CMD) | 1510 | && ((msg->cmd == IPMI_SEND_MSG_CMD) |
1510 | || (msg->cmd == IPMI_GET_MSG_CMD) | 1511 | || (msg->cmd == IPMI_GET_MSG_CMD) |
1511 | || (msg->cmd == IPMI_READ_EVENT_MSG_BUFFER_CMD))) { | 1512 | || (msg->cmd == IPMI_READ_EVENT_MSG_BUFFER_CMD))) { |
1512 | /* | 1513 | /* |
1513 | * We don't let the user do these, since we manage | 1514 | * We don't let the user do these, since we manage |
1514 | * the sequence numbers. | 1515 | * the sequence numbers. |
1515 | */ | 1516 | */ |
1516 | ipmi_inc_stat(intf, sent_invalid_commands); | 1517 | ipmi_inc_stat(intf, sent_invalid_commands); |
1517 | rv = -EINVAL; | 1518 | rv = -EINVAL; |
1518 | goto out_err; | 1519 | goto out_err; |
1519 | } | 1520 | } |
1520 | 1521 | ||
1521 | if (((msg->netfn == IPMI_NETFN_APP_REQUEST) | 1522 | if (((msg->netfn == IPMI_NETFN_APP_REQUEST) |
1522 | && ((msg->cmd == IPMI_COLD_RESET_CMD) | 1523 | && ((msg->cmd == IPMI_COLD_RESET_CMD) |
1523 | || (msg->cmd == IPMI_WARM_RESET_CMD))) | 1524 | || (msg->cmd == IPMI_WARM_RESET_CMD))) |
1524 | || (msg->netfn == IPMI_NETFN_FIRMWARE_REQUEST)) { | 1525 | || (msg->netfn == IPMI_NETFN_FIRMWARE_REQUEST)) { |
1525 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); | 1526 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); |
1526 | intf->auto_maintenance_timeout | 1527 | intf->auto_maintenance_timeout |
1527 | = IPMI_MAINTENANCE_MODE_TIMEOUT; | 1528 | = IPMI_MAINTENANCE_MODE_TIMEOUT; |
1528 | if (!intf->maintenance_mode | 1529 | if (!intf->maintenance_mode |
1529 | && !intf->maintenance_mode_enable) { | 1530 | && !intf->maintenance_mode_enable) { |
1530 | intf->maintenance_mode_enable = 1; | 1531 | intf->maintenance_mode_enable = 1; |
1531 | maintenance_mode_update(intf); | 1532 | maintenance_mode_update(intf); |
1532 | } | 1533 | } |
1533 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, | 1534 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, |
1534 | flags); | 1535 | flags); |
1535 | } | 1536 | } |
1536 | 1537 | ||
1537 | if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) { | 1538 | if ((msg->data_len + 2) > IPMI_MAX_MSG_LENGTH) { |
1538 | ipmi_inc_stat(intf, sent_invalid_commands); | 1539 | ipmi_inc_stat(intf, sent_invalid_commands); |
1539 | rv = -EMSGSIZE; | 1540 | rv = -EMSGSIZE; |
1540 | goto out_err; | 1541 | goto out_err; |
1541 | } | 1542 | } |
1542 | 1543 | ||
1543 | smi_msg->data[0] = (msg->netfn << 2) | (smi_addr->lun & 0x3); | 1544 | smi_msg->data[0] = (msg->netfn << 2) | (smi_addr->lun & 0x3); |
1544 | smi_msg->data[1] = msg->cmd; | 1545 | smi_msg->data[1] = msg->cmd; |
1545 | smi_msg->msgid = msgid; | 1546 | smi_msg->msgid = msgid; |
1546 | smi_msg->user_data = recv_msg; | 1547 | smi_msg->user_data = recv_msg; |
1547 | if (msg->data_len > 0) | 1548 | if (msg->data_len > 0) |
1548 | memcpy(&(smi_msg->data[2]), msg->data, msg->data_len); | 1549 | memcpy(&(smi_msg->data[2]), msg->data, msg->data_len); |
1549 | smi_msg->data_size = msg->data_len + 2; | 1550 | smi_msg->data_size = msg->data_len + 2; |
1550 | ipmi_inc_stat(intf, sent_local_commands); | 1551 | ipmi_inc_stat(intf, sent_local_commands); |
1551 | } else if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) { | 1552 | } else if (is_ipmb_addr(addr) || is_ipmb_bcast_addr(addr)) { |
1552 | struct ipmi_ipmb_addr *ipmb_addr; | 1553 | struct ipmi_ipmb_addr *ipmb_addr; |
1553 | unsigned char ipmb_seq; | 1554 | unsigned char ipmb_seq; |
1554 | long seqid; | 1555 | long seqid; |
1555 | int broadcast = 0; | 1556 | int broadcast = 0; |
1556 | 1557 | ||
1557 | if (addr->channel >= IPMI_MAX_CHANNELS) { | 1558 | if (addr->channel >= IPMI_MAX_CHANNELS) { |
1558 | ipmi_inc_stat(intf, sent_invalid_commands); | 1559 | ipmi_inc_stat(intf, sent_invalid_commands); |
1559 | rv = -EINVAL; | 1560 | rv = -EINVAL; |
1560 | goto out_err; | 1561 | goto out_err; |
1561 | } | 1562 | } |
1562 | 1563 | ||
1563 | if (intf->channels[addr->channel].medium | 1564 | if (intf->channels[addr->channel].medium |
1564 | != IPMI_CHANNEL_MEDIUM_IPMB) { | 1565 | != IPMI_CHANNEL_MEDIUM_IPMB) { |
1565 | ipmi_inc_stat(intf, sent_invalid_commands); | 1566 | ipmi_inc_stat(intf, sent_invalid_commands); |
1566 | rv = -EINVAL; | 1567 | rv = -EINVAL; |
1567 | goto out_err; | 1568 | goto out_err; |
1568 | } | 1569 | } |
1569 | 1570 | ||
1570 | if (retries < 0) { | 1571 | if (retries < 0) { |
1571 | if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) | 1572 | if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) |
1572 | retries = 0; /* Don't retry broadcasts. */ | 1573 | retries = 0; /* Don't retry broadcasts. */ |
1573 | else | 1574 | else |
1574 | retries = 4; | 1575 | retries = 4; |
1575 | } | 1576 | } |
1576 | if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) { | 1577 | if (addr->addr_type == IPMI_IPMB_BROADCAST_ADDR_TYPE) { |
1577 | /* | 1578 | /* |
1578 | * Broadcasts add a zero at the beginning of the | 1579 | * Broadcasts add a zero at the beginning of the |
1579 | * message, but otherwise is the same as an IPMB | 1580 | * message, but otherwise is the same as an IPMB |
1580 | * address. | 1581 | * address. |
1581 | */ | 1582 | */ |
1582 | addr->addr_type = IPMI_IPMB_ADDR_TYPE; | 1583 | addr->addr_type = IPMI_IPMB_ADDR_TYPE; |
1583 | broadcast = 1; | 1584 | broadcast = 1; |
1584 | } | 1585 | } |
1585 | 1586 | ||
1586 | 1587 | ||
1587 | /* Default to 1 second retries. */ | 1588 | /* Default to 1 second retries. */ |
1588 | if (retry_time_ms == 0) | 1589 | if (retry_time_ms == 0) |
1589 | retry_time_ms = 1000; | 1590 | retry_time_ms = 1000; |
1590 | 1591 | ||
1591 | /* | 1592 | /* |
1592 | * 9 for the header and 1 for the checksum, plus | 1593 | * 9 for the header and 1 for the checksum, plus |
1593 | * possibly one for the broadcast. | 1594 | * possibly one for the broadcast. |
1594 | */ | 1595 | */ |
1595 | if ((msg->data_len + 10 + broadcast) > IPMI_MAX_MSG_LENGTH) { | 1596 | if ((msg->data_len + 10 + broadcast) > IPMI_MAX_MSG_LENGTH) { |
1596 | ipmi_inc_stat(intf, sent_invalid_commands); | 1597 | ipmi_inc_stat(intf, sent_invalid_commands); |
1597 | rv = -EMSGSIZE; | 1598 | rv = -EMSGSIZE; |
1598 | goto out_err; | 1599 | goto out_err; |
1599 | } | 1600 | } |
1600 | 1601 | ||
1601 | ipmb_addr = (struct ipmi_ipmb_addr *) addr; | 1602 | ipmb_addr = (struct ipmi_ipmb_addr *) addr; |
1602 | if (ipmb_addr->lun > 3) { | 1603 | if (ipmb_addr->lun > 3) { |
1603 | ipmi_inc_stat(intf, sent_invalid_commands); | 1604 | ipmi_inc_stat(intf, sent_invalid_commands); |
1604 | rv = -EINVAL; | 1605 | rv = -EINVAL; |
1605 | goto out_err; | 1606 | goto out_err; |
1606 | } | 1607 | } |
1607 | 1608 | ||
1608 | memcpy(&recv_msg->addr, ipmb_addr, sizeof(*ipmb_addr)); | 1609 | memcpy(&recv_msg->addr, ipmb_addr, sizeof(*ipmb_addr)); |
1609 | 1610 | ||
1610 | if (recv_msg->msg.netfn & 0x1) { | 1611 | if (recv_msg->msg.netfn & 0x1) { |
1611 | /* | 1612 | /* |
1612 | * It's a response, so use the user's sequence | 1613 | * It's a response, so use the user's sequence |
1613 | * from msgid. | 1614 | * from msgid. |
1614 | */ | 1615 | */ |
1615 | ipmi_inc_stat(intf, sent_ipmb_responses); | 1616 | ipmi_inc_stat(intf, sent_ipmb_responses); |
1616 | format_ipmb_msg(smi_msg, msg, ipmb_addr, msgid, | 1617 | format_ipmb_msg(smi_msg, msg, ipmb_addr, msgid, |
1617 | msgid, broadcast, | 1618 | msgid, broadcast, |
1618 | source_address, source_lun); | 1619 | source_address, source_lun); |
1619 | 1620 | ||
1620 | /* | 1621 | /* |
1621 | * Save the receive message so we can use it | 1622 | * Save the receive message so we can use it |
1622 | * to deliver the response. | 1623 | * to deliver the response. |
1623 | */ | 1624 | */ |
1624 | smi_msg->user_data = recv_msg; | 1625 | smi_msg->user_data = recv_msg; |
1625 | } else { | 1626 | } else { |
1626 | /* It's a command, so get a sequence for it. */ | 1627 | /* It's a command, so get a sequence for it. */ |
1627 | 1628 | ||
1628 | spin_lock_irqsave(&(intf->seq_lock), flags); | 1629 | spin_lock_irqsave(&(intf->seq_lock), flags); |
1629 | 1630 | ||
1630 | /* | 1631 | /* |
1631 | * Create a sequence number with a 1 second | 1632 | * Create a sequence number with a 1 second |
1632 | * timeout and 4 retries. | 1633 | * timeout and 4 retries. |
1633 | */ | 1634 | */ |
1634 | rv = intf_next_seq(intf, | 1635 | rv = intf_next_seq(intf, |
1635 | recv_msg, | 1636 | recv_msg, |
1636 | retry_time_ms, | 1637 | retry_time_ms, |
1637 | retries, | 1638 | retries, |
1638 | broadcast, | 1639 | broadcast, |
1639 | &ipmb_seq, | 1640 | &ipmb_seq, |
1640 | &seqid); | 1641 | &seqid); |
1641 | if (rv) { | 1642 | if (rv) { |
1642 | /* | 1643 | /* |
1643 | * We have used up all the sequence numbers, | 1644 | * We have used up all the sequence numbers, |
1644 | * probably, so abort. | 1645 | * probably, so abort. |
1645 | */ | 1646 | */ |
1646 | spin_unlock_irqrestore(&(intf->seq_lock), | 1647 | spin_unlock_irqrestore(&(intf->seq_lock), |
1647 | flags); | 1648 | flags); |
1648 | goto out_err; | 1649 | goto out_err; |
1649 | } | 1650 | } |
1650 | 1651 | ||
1651 | ipmi_inc_stat(intf, sent_ipmb_commands); | 1652 | ipmi_inc_stat(intf, sent_ipmb_commands); |
1652 | 1653 | ||
1653 | /* | 1654 | /* |
1654 | * Store the sequence number in the message, | 1655 | * Store the sequence number in the message, |
1655 | * so that when the send message response | 1656 | * so that when the send message response |
1656 | * comes back we can start the timer. | 1657 | * comes back we can start the timer. |
1657 | */ | 1658 | */ |
1658 | format_ipmb_msg(smi_msg, msg, ipmb_addr, | 1659 | format_ipmb_msg(smi_msg, msg, ipmb_addr, |
1659 | STORE_SEQ_IN_MSGID(ipmb_seq, seqid), | 1660 | STORE_SEQ_IN_MSGID(ipmb_seq, seqid), |
1660 | ipmb_seq, broadcast, | 1661 | ipmb_seq, broadcast, |
1661 | source_address, source_lun); | 1662 | source_address, source_lun); |
1662 | 1663 | ||
1663 | /* | 1664 | /* |
1664 | * Copy the message into the recv message data, so we | 1665 | * Copy the message into the recv message data, so we |
1665 | * can retransmit it later if necessary. | 1666 | * can retransmit it later if necessary. |
1666 | */ | 1667 | */ |
1667 | memcpy(recv_msg->msg_data, smi_msg->data, | 1668 | memcpy(recv_msg->msg_data, smi_msg->data, |
1668 | smi_msg->data_size); | 1669 | smi_msg->data_size); |
1669 | recv_msg->msg.data = recv_msg->msg_data; | 1670 | recv_msg->msg.data = recv_msg->msg_data; |
1670 | recv_msg->msg.data_len = smi_msg->data_size; | 1671 | recv_msg->msg.data_len = smi_msg->data_size; |
1671 | 1672 | ||
1672 | /* | 1673 | /* |
1673 | * We don't unlock until here, because we need | 1674 | * We don't unlock until here, because we need |
1674 | * to copy the completed message into the | 1675 | * to copy the completed message into the |
1675 | * recv_msg before we release the lock. | 1676 | * recv_msg before we release the lock. |
1676 | * Otherwise, race conditions may bite us. I | 1677 | * Otherwise, race conditions may bite us. I |
1677 | * know that's pretty paranoid, but I prefer | 1678 | * know that's pretty paranoid, but I prefer |
1678 | * to be correct. | 1679 | * to be correct. |
1679 | */ | 1680 | */ |
1680 | spin_unlock_irqrestore(&(intf->seq_lock), flags); | 1681 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
1681 | } | 1682 | } |
1682 | } else if (is_lan_addr(addr)) { | 1683 | } else if (is_lan_addr(addr)) { |
1683 | struct ipmi_lan_addr *lan_addr; | 1684 | struct ipmi_lan_addr *lan_addr; |
1684 | unsigned char ipmb_seq; | 1685 | unsigned char ipmb_seq; |
1685 | long seqid; | 1686 | long seqid; |
1686 | 1687 | ||
1687 | if (addr->channel >= IPMI_MAX_CHANNELS) { | 1688 | if (addr->channel >= IPMI_MAX_CHANNELS) { |
1688 | ipmi_inc_stat(intf, sent_invalid_commands); | 1689 | ipmi_inc_stat(intf, sent_invalid_commands); |
1689 | rv = -EINVAL; | 1690 | rv = -EINVAL; |
1690 | goto out_err; | 1691 | goto out_err; |
1691 | } | 1692 | } |
1692 | 1693 | ||
1693 | if ((intf->channels[addr->channel].medium | 1694 | if ((intf->channels[addr->channel].medium |
1694 | != IPMI_CHANNEL_MEDIUM_8023LAN) | 1695 | != IPMI_CHANNEL_MEDIUM_8023LAN) |
1695 | && (intf->channels[addr->channel].medium | 1696 | && (intf->channels[addr->channel].medium |
1696 | != IPMI_CHANNEL_MEDIUM_ASYNC)) { | 1697 | != IPMI_CHANNEL_MEDIUM_ASYNC)) { |
1697 | ipmi_inc_stat(intf, sent_invalid_commands); | 1698 | ipmi_inc_stat(intf, sent_invalid_commands); |
1698 | rv = -EINVAL; | 1699 | rv = -EINVAL; |
1699 | goto out_err; | 1700 | goto out_err; |
1700 | } | 1701 | } |
1701 | 1702 | ||
1702 | retries = 4; | 1703 | retries = 4; |
1703 | 1704 | ||
1704 | /* Default to 1 second retries. */ | 1705 | /* Default to 1 second retries. */ |
1705 | if (retry_time_ms == 0) | 1706 | if (retry_time_ms == 0) |
1706 | retry_time_ms = 1000; | 1707 | retry_time_ms = 1000; |
1707 | 1708 | ||
1708 | /* 11 for the header and 1 for the checksum. */ | 1709 | /* 11 for the header and 1 for the checksum. */ |
1709 | if ((msg->data_len + 12) > IPMI_MAX_MSG_LENGTH) { | 1710 | if ((msg->data_len + 12) > IPMI_MAX_MSG_LENGTH) { |
1710 | ipmi_inc_stat(intf, sent_invalid_commands); | 1711 | ipmi_inc_stat(intf, sent_invalid_commands); |
1711 | rv = -EMSGSIZE; | 1712 | rv = -EMSGSIZE; |
1712 | goto out_err; | 1713 | goto out_err; |
1713 | } | 1714 | } |
1714 | 1715 | ||
1715 | lan_addr = (struct ipmi_lan_addr *) addr; | 1716 | lan_addr = (struct ipmi_lan_addr *) addr; |
1716 | if (lan_addr->lun > 3) { | 1717 | if (lan_addr->lun > 3) { |
1717 | ipmi_inc_stat(intf, sent_invalid_commands); | 1718 | ipmi_inc_stat(intf, sent_invalid_commands); |
1718 | rv = -EINVAL; | 1719 | rv = -EINVAL; |
1719 | goto out_err; | 1720 | goto out_err; |
1720 | } | 1721 | } |
1721 | 1722 | ||
1722 | memcpy(&recv_msg->addr, lan_addr, sizeof(*lan_addr)); | 1723 | memcpy(&recv_msg->addr, lan_addr, sizeof(*lan_addr)); |
1723 | 1724 | ||
1724 | if (recv_msg->msg.netfn & 0x1) { | 1725 | if (recv_msg->msg.netfn & 0x1) { |
1725 | /* | 1726 | /* |
1726 | * It's a response, so use the user's sequence | 1727 | * It's a response, so use the user's sequence |
1727 | * from msgid. | 1728 | * from msgid. |
1728 | */ | 1729 | */ |
1729 | ipmi_inc_stat(intf, sent_lan_responses); | 1730 | ipmi_inc_stat(intf, sent_lan_responses); |
1730 | format_lan_msg(smi_msg, msg, lan_addr, msgid, | 1731 | format_lan_msg(smi_msg, msg, lan_addr, msgid, |
1731 | msgid, source_lun); | 1732 | msgid, source_lun); |
1732 | 1733 | ||
1733 | /* | 1734 | /* |
1734 | * Save the receive message so we can use it | 1735 | * Save the receive message so we can use it |
1735 | * to deliver the response. | 1736 | * to deliver the response. |
1736 | */ | 1737 | */ |
1737 | smi_msg->user_data = recv_msg; | 1738 | smi_msg->user_data = recv_msg; |
1738 | } else { | 1739 | } else { |
1739 | /* It's a command, so get a sequence for it. */ | 1740 | /* It's a command, so get a sequence for it. */ |
1740 | 1741 | ||
1741 | spin_lock_irqsave(&(intf->seq_lock), flags); | 1742 | spin_lock_irqsave(&(intf->seq_lock), flags); |
1742 | 1743 | ||
1743 | /* | 1744 | /* |
1744 | * Create a sequence number with a 1 second | 1745 | * Create a sequence number with a 1 second |
1745 | * timeout and 4 retries. | 1746 | * timeout and 4 retries. |
1746 | */ | 1747 | */ |
1747 | rv = intf_next_seq(intf, | 1748 | rv = intf_next_seq(intf, |
1748 | recv_msg, | 1749 | recv_msg, |
1749 | retry_time_ms, | 1750 | retry_time_ms, |
1750 | retries, | 1751 | retries, |
1751 | 0, | 1752 | 0, |
1752 | &ipmb_seq, | 1753 | &ipmb_seq, |
1753 | &seqid); | 1754 | &seqid); |
1754 | if (rv) { | 1755 | if (rv) { |
1755 | /* | 1756 | /* |
1756 | * We have used up all the sequence numbers, | 1757 | * We have used up all the sequence numbers, |
1757 | * probably, so abort. | 1758 | * probably, so abort. |
1758 | */ | 1759 | */ |
1759 | spin_unlock_irqrestore(&(intf->seq_lock), | 1760 | spin_unlock_irqrestore(&(intf->seq_lock), |
1760 | flags); | 1761 | flags); |
1761 | goto out_err; | 1762 | goto out_err; |
1762 | } | 1763 | } |
1763 | 1764 | ||
1764 | ipmi_inc_stat(intf, sent_lan_commands); | 1765 | ipmi_inc_stat(intf, sent_lan_commands); |
1765 | 1766 | ||
1766 | /* | 1767 | /* |
1767 | * Store the sequence number in the message, | 1768 | * Store the sequence number in the message, |
1768 | * so that when the send message response | 1769 | * so that when the send message response |
1769 | * comes back we can start the timer. | 1770 | * comes back we can start the timer. |
1770 | */ | 1771 | */ |
1771 | format_lan_msg(smi_msg, msg, lan_addr, | 1772 | format_lan_msg(smi_msg, msg, lan_addr, |
1772 | STORE_SEQ_IN_MSGID(ipmb_seq, seqid), | 1773 | STORE_SEQ_IN_MSGID(ipmb_seq, seqid), |
1773 | ipmb_seq, source_lun); | 1774 | ipmb_seq, source_lun); |
1774 | 1775 | ||
1775 | /* | 1776 | /* |
1776 | * Copy the message into the recv message data, so we | 1777 | * Copy the message into the recv message data, so we |
1777 | * can retransmit it later if necessary. | 1778 | * can retransmit it later if necessary. |
1778 | */ | 1779 | */ |
1779 | memcpy(recv_msg->msg_data, smi_msg->data, | 1780 | memcpy(recv_msg->msg_data, smi_msg->data, |
1780 | smi_msg->data_size); | 1781 | smi_msg->data_size); |
1781 | recv_msg->msg.data = recv_msg->msg_data; | 1782 | recv_msg->msg.data = recv_msg->msg_data; |
1782 | recv_msg->msg.data_len = smi_msg->data_size; | 1783 | recv_msg->msg.data_len = smi_msg->data_size; |
1783 | 1784 | ||
1784 | /* | 1785 | /* |
1785 | * We don't unlock until here, because we need | 1786 | * We don't unlock until here, because we need |
1786 | * to copy the completed message into the | 1787 | * to copy the completed message into the |
1787 | * recv_msg before we release the lock. | 1788 | * recv_msg before we release the lock. |
1788 | * Otherwise, race conditions may bite us. I | 1789 | * Otherwise, race conditions may bite us. I |
1789 | * know that's pretty paranoid, but I prefer | 1790 | * know that's pretty paranoid, but I prefer |
1790 | * to be correct. | 1791 | * to be correct. |
1791 | */ | 1792 | */ |
1792 | spin_unlock_irqrestore(&(intf->seq_lock), flags); | 1793 | spin_unlock_irqrestore(&(intf->seq_lock), flags); |
1793 | } | 1794 | } |
1794 | } else { | 1795 | } else { |
1795 | /* Unknown address type. */ | 1796 | /* Unknown address type. */ |
1796 | ipmi_inc_stat(intf, sent_invalid_commands); | 1797 | ipmi_inc_stat(intf, sent_invalid_commands); |
1797 | rv = -EINVAL; | 1798 | rv = -EINVAL; |
1798 | goto out_err; | 1799 | goto out_err; |
1799 | } | 1800 | } |
1800 | 1801 | ||
1801 | #ifdef DEBUG_MSGING | 1802 | #ifdef DEBUG_MSGING |
1802 | { | 1803 | { |
1803 | int m; | 1804 | int m; |
1804 | for (m = 0; m < smi_msg->data_size; m++) | 1805 | for (m = 0; m < smi_msg->data_size; m++) |
1805 | printk(" %2.2x", smi_msg->data[m]); | 1806 | printk(" %2.2x", smi_msg->data[m]); |
1806 | printk("\n"); | 1807 | printk("\n"); |
1807 | } | 1808 | } |
1808 | #endif | 1809 | #endif |
1809 | 1810 | ||
1810 | handlers->sender(intf->send_info, smi_msg, priority); | 1811 | handlers->sender(intf->send_info, smi_msg, priority); |
1811 | rcu_read_unlock(); | 1812 | rcu_read_unlock(); |
1812 | 1813 | ||
1813 | return 0; | 1814 | return 0; |
1814 | 1815 | ||
1815 | out_err: | 1816 | out_err: |
1816 | rcu_read_unlock(); | 1817 | rcu_read_unlock(); |
1817 | ipmi_free_smi_msg(smi_msg); | 1818 | ipmi_free_smi_msg(smi_msg); |
1818 | ipmi_free_recv_msg(recv_msg); | 1819 | ipmi_free_recv_msg(recv_msg); |
1819 | return rv; | 1820 | return rv; |
1820 | } | 1821 | } |
1821 | 1822 | ||
1822 | static int check_addr(ipmi_smi_t intf, | 1823 | static int check_addr(ipmi_smi_t intf, |
1823 | struct ipmi_addr *addr, | 1824 | struct ipmi_addr *addr, |
1824 | unsigned char *saddr, | 1825 | unsigned char *saddr, |
1825 | unsigned char *lun) | 1826 | unsigned char *lun) |
1826 | { | 1827 | { |
1827 | if (addr->channel >= IPMI_MAX_CHANNELS) | 1828 | if (addr->channel >= IPMI_MAX_CHANNELS) |
1828 | return -EINVAL; | 1829 | return -EINVAL; |
1829 | *lun = intf->channels[addr->channel].lun; | 1830 | *lun = intf->channels[addr->channel].lun; |
1830 | *saddr = intf->channels[addr->channel].address; | 1831 | *saddr = intf->channels[addr->channel].address; |
1831 | return 0; | 1832 | return 0; |
1832 | } | 1833 | } |
1833 | 1834 | ||
1834 | int ipmi_request_settime(ipmi_user_t user, | 1835 | int ipmi_request_settime(ipmi_user_t user, |
1835 | struct ipmi_addr *addr, | 1836 | struct ipmi_addr *addr, |
1836 | long msgid, | 1837 | long msgid, |
1837 | struct kernel_ipmi_msg *msg, | 1838 | struct kernel_ipmi_msg *msg, |
1838 | void *user_msg_data, | 1839 | void *user_msg_data, |
1839 | int priority, | 1840 | int priority, |
1840 | int retries, | 1841 | int retries, |
1841 | unsigned int retry_time_ms) | 1842 | unsigned int retry_time_ms) |
1842 | { | 1843 | { |
1843 | unsigned char saddr, lun; | 1844 | unsigned char saddr, lun; |
1844 | int rv; | 1845 | int rv; |
1845 | 1846 | ||
1846 | if (!user) | 1847 | if (!user) |
1847 | return -EINVAL; | 1848 | return -EINVAL; |
1848 | rv = check_addr(user->intf, addr, &saddr, &lun); | 1849 | rv = check_addr(user->intf, addr, &saddr, &lun); |
1849 | if (rv) | 1850 | if (rv) |
1850 | return rv; | 1851 | return rv; |
1851 | return i_ipmi_request(user, | 1852 | return i_ipmi_request(user, |
1852 | user->intf, | 1853 | user->intf, |
1853 | addr, | 1854 | addr, |
1854 | msgid, | 1855 | msgid, |
1855 | msg, | 1856 | msg, |
1856 | user_msg_data, | 1857 | user_msg_data, |
1857 | NULL, NULL, | 1858 | NULL, NULL, |
1858 | priority, | 1859 | priority, |
1859 | saddr, | 1860 | saddr, |
1860 | lun, | 1861 | lun, |
1861 | retries, | 1862 | retries, |
1862 | retry_time_ms); | 1863 | retry_time_ms); |
1863 | } | 1864 | } |
1864 | EXPORT_SYMBOL(ipmi_request_settime); | 1865 | EXPORT_SYMBOL(ipmi_request_settime); |
1865 | 1866 | ||
1866 | int ipmi_request_supply_msgs(ipmi_user_t user, | 1867 | int ipmi_request_supply_msgs(ipmi_user_t user, |
1867 | struct ipmi_addr *addr, | 1868 | struct ipmi_addr *addr, |
1868 | long msgid, | 1869 | long msgid, |
1869 | struct kernel_ipmi_msg *msg, | 1870 | struct kernel_ipmi_msg *msg, |
1870 | void *user_msg_data, | 1871 | void *user_msg_data, |
1871 | void *supplied_smi, | 1872 | void *supplied_smi, |
1872 | struct ipmi_recv_msg *supplied_recv, | 1873 | struct ipmi_recv_msg *supplied_recv, |
1873 | int priority) | 1874 | int priority) |
1874 | { | 1875 | { |
1875 | unsigned char saddr, lun; | 1876 | unsigned char saddr, lun; |
1876 | int rv; | 1877 | int rv; |
1877 | 1878 | ||
1878 | if (!user) | 1879 | if (!user) |
1879 | return -EINVAL; | 1880 | return -EINVAL; |
1880 | rv = check_addr(user->intf, addr, &saddr, &lun); | 1881 | rv = check_addr(user->intf, addr, &saddr, &lun); |
1881 | if (rv) | 1882 | if (rv) |
1882 | return rv; | 1883 | return rv; |
1883 | return i_ipmi_request(user, | 1884 | return i_ipmi_request(user, |
1884 | user->intf, | 1885 | user->intf, |
1885 | addr, | 1886 | addr, |
1886 | msgid, | 1887 | msgid, |
1887 | msg, | 1888 | msg, |
1888 | user_msg_data, | 1889 | user_msg_data, |
1889 | supplied_smi, | 1890 | supplied_smi, |
1890 | supplied_recv, | 1891 | supplied_recv, |
1891 | priority, | 1892 | priority, |
1892 | saddr, | 1893 | saddr, |
1893 | lun, | 1894 | lun, |
1894 | -1, 0); | 1895 | -1, 0); |
1895 | } | 1896 | } |
1896 | EXPORT_SYMBOL(ipmi_request_supply_msgs); | 1897 | EXPORT_SYMBOL(ipmi_request_supply_msgs); |
1897 | 1898 | ||
1898 | #ifdef CONFIG_PROC_FS | 1899 | #ifdef CONFIG_PROC_FS |
1899 | static int ipmb_file_read_proc(char *page, char **start, off_t off, | 1900 | static int smi_ipmb_proc_show(struct seq_file *m, void *v) |
1900 | int count, int *eof, void *data) | ||
1901 | { | 1901 | { |
1902 | char *out = (char *) page; | 1902 | ipmi_smi_t intf = m->private; |
1903 | ipmi_smi_t intf = data; | ||
1904 | int i; | 1903 | int i; |
1905 | int rv = 0; | ||
1906 | 1904 | ||
1907 | for (i = 0; i < IPMI_MAX_CHANNELS; i++) | 1905 | seq_printf(m, "%x", intf->channels[0].address); |
1908 | rv += sprintf(out+rv, "%x ", intf->channels[i].address); | 1906 | for (i = 1; i < IPMI_MAX_CHANNELS; i++) |
1909 | out[rv-1] = '\n'; /* Replace the final space with a newline */ | 1907 | seq_printf(m, " %x", intf->channels[i].address); |
1910 | out[rv] = '\0'; | 1908 | return seq_putc(m, '\n'); |
1911 | rv++; | ||
1912 | return rv; | ||
1913 | } | 1909 | } |
1914 | 1910 | ||
1915 | static int version_file_read_proc(char *page, char **start, off_t off, | 1911 | static int smi_ipmb_proc_open(struct inode *inode, struct file *file) |
1916 | int count, int *eof, void *data) | ||
1917 | { | 1912 | { |
1918 | char *out = (char *) page; | 1913 | return single_open(file, smi_ipmb_proc_show, PDE(inode)->data); |
1919 | ipmi_smi_t intf = data; | 1914 | } |
1920 | 1915 | ||
1921 | return sprintf(out, "%u.%u\n", | 1916 | static const struct file_operations smi_ipmb_proc_ops = { |
1917 | .open = smi_ipmb_proc_open, | ||
1918 | .read = seq_read, | ||
1919 | .llseek = seq_lseek, | ||
1920 | .release = single_release, | ||
1921 | }; | ||
1922 | |||
1923 | static int smi_version_proc_show(struct seq_file *m, void *v) | ||
1924 | { | ||
1925 | ipmi_smi_t intf = m->private; | ||
1926 | |||
1927 | return seq_printf(m, "%u.%u\n", | ||
1922 | ipmi_version_major(&intf->bmc->id), | 1928 | ipmi_version_major(&intf->bmc->id), |
1923 | ipmi_version_minor(&intf->bmc->id)); | 1929 | ipmi_version_minor(&intf->bmc->id)); |
1924 | } | 1930 | } |
1925 | 1931 | ||
1926 | static int stat_file_read_proc(char *page, char **start, off_t off, | 1932 | static int smi_version_proc_open(struct inode *inode, struct file *file) |
1927 | int count, int *eof, void *data) | ||
1928 | { | 1933 | { |
1929 | char *out = (char *) page; | 1934 | return single_open(file, smi_version_proc_show, PDE(inode)->data); |
1930 | ipmi_smi_t intf = data; | 1935 | } |
1931 | 1936 | ||
1932 | out += sprintf(out, "sent_invalid_commands: %u\n", | 1937 | static const struct file_operations smi_version_proc_ops = { |
1938 | .open = smi_version_proc_open, | ||
1939 | .read = seq_read, | ||
1940 | .llseek = seq_lseek, | ||
1941 | .release = single_release, | ||
1942 | }; | ||
1943 | |||
1944 | static int smi_stats_proc_show(struct seq_file *m, void *v) | ||
1945 | { | ||
1946 | ipmi_smi_t intf = m->private; | ||
1947 | |||
1948 | seq_printf(m, "sent_invalid_commands: %u\n", | ||
1933 | ipmi_get_stat(intf, sent_invalid_commands)); | 1949 | ipmi_get_stat(intf, sent_invalid_commands)); |
1934 | out += sprintf(out, "sent_local_commands: %u\n", | 1950 | seq_printf(m, "sent_local_commands: %u\n", |
1935 | ipmi_get_stat(intf, sent_local_commands)); | 1951 | ipmi_get_stat(intf, sent_local_commands)); |
1936 | out += sprintf(out, "handled_local_responses: %u\n", | 1952 | seq_printf(m, "handled_local_responses: %u\n", |
1937 | ipmi_get_stat(intf, handled_local_responses)); | 1953 | ipmi_get_stat(intf, handled_local_responses)); |
1938 | out += sprintf(out, "unhandled_local_responses: %u\n", | 1954 | seq_printf(m, "unhandled_local_responses: %u\n", |
1939 | ipmi_get_stat(intf, unhandled_local_responses)); | 1955 | ipmi_get_stat(intf, unhandled_local_responses)); |
1940 | out += sprintf(out, "sent_ipmb_commands: %u\n", | 1956 | seq_printf(m, "sent_ipmb_commands: %u\n", |
1941 | ipmi_get_stat(intf, sent_ipmb_commands)); | 1957 | ipmi_get_stat(intf, sent_ipmb_commands)); |
1942 | out += sprintf(out, "sent_ipmb_command_errs: %u\n", | 1958 | seq_printf(m, "sent_ipmb_command_errs: %u\n", |
1943 | ipmi_get_stat(intf, sent_ipmb_command_errs)); | 1959 | ipmi_get_stat(intf, sent_ipmb_command_errs)); |
1944 | out += sprintf(out, "retransmitted_ipmb_commands: %u\n", | 1960 | seq_printf(m, "retransmitted_ipmb_commands: %u\n", |
1945 | ipmi_get_stat(intf, retransmitted_ipmb_commands)); | 1961 | ipmi_get_stat(intf, retransmitted_ipmb_commands)); |
1946 | out += sprintf(out, "timed_out_ipmb_commands: %u\n", | 1962 | seq_printf(m, "timed_out_ipmb_commands: %u\n", |
1947 | ipmi_get_stat(intf, timed_out_ipmb_commands)); | 1963 | ipmi_get_stat(intf, timed_out_ipmb_commands)); |
1948 | out += sprintf(out, "timed_out_ipmb_broadcasts: %u\n", | 1964 | seq_printf(m, "timed_out_ipmb_broadcasts: %u\n", |
1949 | ipmi_get_stat(intf, timed_out_ipmb_broadcasts)); | 1965 | ipmi_get_stat(intf, timed_out_ipmb_broadcasts)); |
1950 | out += sprintf(out, "sent_ipmb_responses: %u\n", | 1966 | seq_printf(m, "sent_ipmb_responses: %u\n", |
1951 | ipmi_get_stat(intf, sent_ipmb_responses)); | 1967 | ipmi_get_stat(intf, sent_ipmb_responses)); |
1952 | out += sprintf(out, "handled_ipmb_responses: %u\n", | 1968 | seq_printf(m, "handled_ipmb_responses: %u\n", |
1953 | ipmi_get_stat(intf, handled_ipmb_responses)); | 1969 | ipmi_get_stat(intf, handled_ipmb_responses)); |
1954 | out += sprintf(out, "invalid_ipmb_responses: %u\n", | 1970 | seq_printf(m, "invalid_ipmb_responses: %u\n", |
1955 | ipmi_get_stat(intf, invalid_ipmb_responses)); | 1971 | ipmi_get_stat(intf, invalid_ipmb_responses)); |
1956 | out += sprintf(out, "unhandled_ipmb_responses: %u\n", | 1972 | seq_printf(m, "unhandled_ipmb_responses: %u\n", |
1957 | ipmi_get_stat(intf, unhandled_ipmb_responses)); | 1973 | ipmi_get_stat(intf, unhandled_ipmb_responses)); |
1958 | out += sprintf(out, "sent_lan_commands: %u\n", | 1974 | seq_printf(m, "sent_lan_commands: %u\n", |
1959 | ipmi_get_stat(intf, sent_lan_commands)); | 1975 | ipmi_get_stat(intf, sent_lan_commands)); |
1960 | out += sprintf(out, "sent_lan_command_errs: %u\n", | 1976 | seq_printf(m, "sent_lan_command_errs: %u\n", |
1961 | ipmi_get_stat(intf, sent_lan_command_errs)); | 1977 | ipmi_get_stat(intf, sent_lan_command_errs)); |
1962 | out += sprintf(out, "retransmitted_lan_commands: %u\n", | 1978 | seq_printf(m, "retransmitted_lan_commands: %u\n", |
1963 | ipmi_get_stat(intf, retransmitted_lan_commands)); | 1979 | ipmi_get_stat(intf, retransmitted_lan_commands)); |
1964 | out += sprintf(out, "timed_out_lan_commands: %u\n", | 1980 | seq_printf(m, "timed_out_lan_commands: %u\n", |
1965 | ipmi_get_stat(intf, timed_out_lan_commands)); | 1981 | ipmi_get_stat(intf, timed_out_lan_commands)); |
1966 | out += sprintf(out, "sent_lan_responses: %u\n", | 1982 | seq_printf(m, "sent_lan_responses: %u\n", |
1967 | ipmi_get_stat(intf, sent_lan_responses)); | 1983 | ipmi_get_stat(intf, sent_lan_responses)); |
1968 | out += sprintf(out, "handled_lan_responses: %u\n", | 1984 | seq_printf(m, "handled_lan_responses: %u\n", |
1969 | ipmi_get_stat(intf, handled_lan_responses)); | 1985 | ipmi_get_stat(intf, handled_lan_responses)); |
1970 | out += sprintf(out, "invalid_lan_responses: %u\n", | 1986 | seq_printf(m, "invalid_lan_responses: %u\n", |
1971 | ipmi_get_stat(intf, invalid_lan_responses)); | 1987 | ipmi_get_stat(intf, invalid_lan_responses)); |
1972 | out += sprintf(out, "unhandled_lan_responses: %u\n", | 1988 | seq_printf(m, "unhandled_lan_responses: %u\n", |
1973 | ipmi_get_stat(intf, unhandled_lan_responses)); | 1989 | ipmi_get_stat(intf, unhandled_lan_responses)); |
1974 | out += sprintf(out, "handled_commands: %u\n", | 1990 | seq_printf(m, "handled_commands: %u\n", |
1975 | ipmi_get_stat(intf, handled_commands)); | 1991 | ipmi_get_stat(intf, handled_commands)); |
1976 | out += sprintf(out, "invalid_commands: %u\n", | 1992 | seq_printf(m, "invalid_commands: %u\n", |
1977 | ipmi_get_stat(intf, invalid_commands)); | 1993 | ipmi_get_stat(intf, invalid_commands)); |
1978 | out += sprintf(out, "unhandled_commands: %u\n", | 1994 | seq_printf(m, "unhandled_commands: %u\n", |
1979 | ipmi_get_stat(intf, unhandled_commands)); | 1995 | ipmi_get_stat(intf, unhandled_commands)); |
1980 | out += sprintf(out, "invalid_events: %u\n", | 1996 | seq_printf(m, "invalid_events: %u\n", |
1981 | ipmi_get_stat(intf, invalid_events)); | 1997 | ipmi_get_stat(intf, invalid_events)); |
1982 | out += sprintf(out, "events: %u\n", | 1998 | seq_printf(m, "events: %u\n", |
1983 | ipmi_get_stat(intf, events)); | 1999 | ipmi_get_stat(intf, events)); |
1984 | out += sprintf(out, "failed rexmit LAN msgs: %u\n", | 2000 | seq_printf(m, "failed rexmit LAN msgs: %u\n", |
1985 | ipmi_get_stat(intf, dropped_rexmit_lan_commands)); | 2001 | ipmi_get_stat(intf, dropped_rexmit_lan_commands)); |
1986 | out += sprintf(out, "failed rexmit IPMB msgs: %u\n", | 2002 | seq_printf(m, "failed rexmit IPMB msgs: %u\n", |
1987 | ipmi_get_stat(intf, dropped_rexmit_ipmb_commands)); | 2003 | ipmi_get_stat(intf, dropped_rexmit_ipmb_commands)); |
2004 | return 0; | ||
2005 | } | ||
1988 | 2006 | ||
1989 | return (out - ((char *) page)); | 2007 | static int smi_stats_proc_open(struct inode *inode, struct file *file) |
2008 | { | ||
2009 | return single_open(file, smi_stats_proc_show, PDE(inode)->data); | ||
1990 | } | 2010 | } |
2011 | |||
2012 | static const struct file_operations smi_stats_proc_ops = { | ||
2013 | .open = smi_stats_proc_open, | ||
2014 | .read = seq_read, | ||
2015 | .llseek = seq_lseek, | ||
2016 | .release = single_release, | ||
2017 | }; | ||
1991 | #endif /* CONFIG_PROC_FS */ | 2018 | #endif /* CONFIG_PROC_FS */ |
1992 | 2019 | ||
1993 | int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, | 2020 | int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, |
1994 | read_proc_t *read_proc, | 2021 | const struct file_operations *proc_ops, |
1995 | void *data) | 2022 | void *data) |
1996 | { | 2023 | { |
1997 | int rv = 0; | 2024 | int rv = 0; |
1998 | #ifdef CONFIG_PROC_FS | 2025 | #ifdef CONFIG_PROC_FS |
1999 | struct proc_dir_entry *file; | 2026 | struct proc_dir_entry *file; |
2000 | struct ipmi_proc_entry *entry; | 2027 | struct ipmi_proc_entry *entry; |
2001 | 2028 | ||
2002 | /* Create a list element. */ | 2029 | /* Create a list element. */ |
2003 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); | 2030 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
2004 | if (!entry) | 2031 | if (!entry) |
2005 | return -ENOMEM; | 2032 | return -ENOMEM; |
2006 | entry->name = kmalloc(strlen(name)+1, GFP_KERNEL); | 2033 | entry->name = kmalloc(strlen(name)+1, GFP_KERNEL); |
2007 | if (!entry->name) { | 2034 | if (!entry->name) { |
2008 | kfree(entry); | 2035 | kfree(entry); |
2009 | return -ENOMEM; | 2036 | return -ENOMEM; |
2010 | } | 2037 | } |
2011 | strcpy(entry->name, name); | 2038 | strcpy(entry->name, name); |
2012 | 2039 | ||
2013 | file = create_proc_entry(name, 0, smi->proc_dir); | 2040 | file = proc_create_data(name, 0, smi->proc_dir, proc_ops, data); |
2014 | if (!file) { | 2041 | if (!file) { |
2015 | kfree(entry->name); | 2042 | kfree(entry->name); |
2016 | kfree(entry); | 2043 | kfree(entry); |
2017 | rv = -ENOMEM; | 2044 | rv = -ENOMEM; |
2018 | } else { | 2045 | } else { |
2019 | file->data = data; | ||
2020 | file->read_proc = read_proc; | ||
2021 | |||
2022 | mutex_lock(&smi->proc_entry_lock); | 2046 | mutex_lock(&smi->proc_entry_lock); |
2023 | /* Stick it on the list. */ | 2047 | /* Stick it on the list. */ |
2024 | entry->next = smi->proc_entries; | 2048 | entry->next = smi->proc_entries; |
2025 | smi->proc_entries = entry; | 2049 | smi->proc_entries = entry; |
2026 | mutex_unlock(&smi->proc_entry_lock); | 2050 | mutex_unlock(&smi->proc_entry_lock); |
2027 | } | 2051 | } |
2028 | #endif /* CONFIG_PROC_FS */ | 2052 | #endif /* CONFIG_PROC_FS */ |
2029 | 2053 | ||
2030 | return rv; | 2054 | return rv; |
2031 | } | 2055 | } |
2032 | EXPORT_SYMBOL(ipmi_smi_add_proc_entry); | 2056 | EXPORT_SYMBOL(ipmi_smi_add_proc_entry); |
2033 | 2057 | ||
2034 | static int add_proc_entries(ipmi_smi_t smi, int num) | 2058 | static int add_proc_entries(ipmi_smi_t smi, int num) |
2035 | { | 2059 | { |
2036 | int rv = 0; | 2060 | int rv = 0; |
2037 | 2061 | ||
2038 | #ifdef CONFIG_PROC_FS | 2062 | #ifdef CONFIG_PROC_FS |
2039 | sprintf(smi->proc_dir_name, "%d", num); | 2063 | sprintf(smi->proc_dir_name, "%d", num); |
2040 | smi->proc_dir = proc_mkdir(smi->proc_dir_name, proc_ipmi_root); | 2064 | smi->proc_dir = proc_mkdir(smi->proc_dir_name, proc_ipmi_root); |
2041 | if (!smi->proc_dir) | 2065 | if (!smi->proc_dir) |
2042 | rv = -ENOMEM; | 2066 | rv = -ENOMEM; |
2043 | 2067 | ||
2044 | if (rv == 0) | 2068 | if (rv == 0) |
2045 | rv = ipmi_smi_add_proc_entry(smi, "stats", | 2069 | rv = ipmi_smi_add_proc_entry(smi, "stats", |
2046 | stat_file_read_proc, | 2070 | &smi_stats_proc_ops, |
2047 | smi); | 2071 | smi); |
2048 | 2072 | ||
2049 | if (rv == 0) | 2073 | if (rv == 0) |
2050 | rv = ipmi_smi_add_proc_entry(smi, "ipmb", | 2074 | rv = ipmi_smi_add_proc_entry(smi, "ipmb", |
2051 | ipmb_file_read_proc, | 2075 | &smi_ipmb_proc_ops, |
2052 | smi); | 2076 | smi); |
2053 | 2077 | ||
2054 | if (rv == 0) | 2078 | if (rv == 0) |
2055 | rv = ipmi_smi_add_proc_entry(smi, "version", | 2079 | rv = ipmi_smi_add_proc_entry(smi, "version", |
2056 | version_file_read_proc, | 2080 | &smi_version_proc_ops, |
2057 | smi); | 2081 | smi); |
2058 | #endif /* CONFIG_PROC_FS */ | 2082 | #endif /* CONFIG_PROC_FS */ |
2059 | 2083 | ||
2060 | return rv; | 2084 | return rv; |
2061 | } | 2085 | } |
2062 | 2086 | ||
2063 | static void remove_proc_entries(ipmi_smi_t smi) | 2087 | static void remove_proc_entries(ipmi_smi_t smi) |
2064 | { | 2088 | { |
2065 | #ifdef CONFIG_PROC_FS | 2089 | #ifdef CONFIG_PROC_FS |
2066 | struct ipmi_proc_entry *entry; | 2090 | struct ipmi_proc_entry *entry; |
2067 | 2091 | ||
2068 | mutex_lock(&smi->proc_entry_lock); | 2092 | mutex_lock(&smi->proc_entry_lock); |
2069 | while (smi->proc_entries) { | 2093 | while (smi->proc_entries) { |
2070 | entry = smi->proc_entries; | 2094 | entry = smi->proc_entries; |
2071 | smi->proc_entries = entry->next; | 2095 | smi->proc_entries = entry->next; |
2072 | 2096 | ||
2073 | remove_proc_entry(entry->name, smi->proc_dir); | 2097 | remove_proc_entry(entry->name, smi->proc_dir); |
2074 | kfree(entry->name); | 2098 | kfree(entry->name); |
2075 | kfree(entry); | 2099 | kfree(entry); |
2076 | } | 2100 | } |
2077 | mutex_unlock(&smi->proc_entry_lock); | 2101 | mutex_unlock(&smi->proc_entry_lock); |
2078 | remove_proc_entry(smi->proc_dir_name, proc_ipmi_root); | 2102 | remove_proc_entry(smi->proc_dir_name, proc_ipmi_root); |
2079 | #endif /* CONFIG_PROC_FS */ | 2103 | #endif /* CONFIG_PROC_FS */ |
2080 | } | 2104 | } |
2081 | 2105 | ||
2082 | static int __find_bmc_guid(struct device *dev, void *data) | 2106 | static int __find_bmc_guid(struct device *dev, void *data) |
2083 | { | 2107 | { |
2084 | unsigned char *id = data; | 2108 | unsigned char *id = data; |
2085 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2109 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2086 | return memcmp(bmc->guid, id, 16) == 0; | 2110 | return memcmp(bmc->guid, id, 16) == 0; |
2087 | } | 2111 | } |
2088 | 2112 | ||
2089 | static struct bmc_device *ipmi_find_bmc_guid(struct device_driver *drv, | 2113 | static struct bmc_device *ipmi_find_bmc_guid(struct device_driver *drv, |
2090 | unsigned char *guid) | 2114 | unsigned char *guid) |
2091 | { | 2115 | { |
2092 | struct device *dev; | 2116 | struct device *dev; |
2093 | 2117 | ||
2094 | dev = driver_find_device(drv, NULL, guid, __find_bmc_guid); | 2118 | dev = driver_find_device(drv, NULL, guid, __find_bmc_guid); |
2095 | if (dev) | 2119 | if (dev) |
2096 | return dev_get_drvdata(dev); | 2120 | return dev_get_drvdata(dev); |
2097 | else | 2121 | else |
2098 | return NULL; | 2122 | return NULL; |
2099 | } | 2123 | } |
2100 | 2124 | ||
2101 | struct prod_dev_id { | 2125 | struct prod_dev_id { |
2102 | unsigned int product_id; | 2126 | unsigned int product_id; |
2103 | unsigned char device_id; | 2127 | unsigned char device_id; |
2104 | }; | 2128 | }; |
2105 | 2129 | ||
2106 | static int __find_bmc_prod_dev_id(struct device *dev, void *data) | 2130 | static int __find_bmc_prod_dev_id(struct device *dev, void *data) |
2107 | { | 2131 | { |
2108 | struct prod_dev_id *id = data; | 2132 | struct prod_dev_id *id = data; |
2109 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2133 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2110 | 2134 | ||
2111 | return (bmc->id.product_id == id->product_id | 2135 | return (bmc->id.product_id == id->product_id |
2112 | && bmc->id.device_id == id->device_id); | 2136 | && bmc->id.device_id == id->device_id); |
2113 | } | 2137 | } |
2114 | 2138 | ||
2115 | static struct bmc_device *ipmi_find_bmc_prod_dev_id( | 2139 | static struct bmc_device *ipmi_find_bmc_prod_dev_id( |
2116 | struct device_driver *drv, | 2140 | struct device_driver *drv, |
2117 | unsigned int product_id, unsigned char device_id) | 2141 | unsigned int product_id, unsigned char device_id) |
2118 | { | 2142 | { |
2119 | struct prod_dev_id id = { | 2143 | struct prod_dev_id id = { |
2120 | .product_id = product_id, | 2144 | .product_id = product_id, |
2121 | .device_id = device_id, | 2145 | .device_id = device_id, |
2122 | }; | 2146 | }; |
2123 | struct device *dev; | 2147 | struct device *dev; |
2124 | 2148 | ||
2125 | dev = driver_find_device(drv, NULL, &id, __find_bmc_prod_dev_id); | 2149 | dev = driver_find_device(drv, NULL, &id, __find_bmc_prod_dev_id); |
2126 | if (dev) | 2150 | if (dev) |
2127 | return dev_get_drvdata(dev); | 2151 | return dev_get_drvdata(dev); |
2128 | else | 2152 | else |
2129 | return NULL; | 2153 | return NULL; |
2130 | } | 2154 | } |
2131 | 2155 | ||
2132 | static ssize_t device_id_show(struct device *dev, | 2156 | static ssize_t device_id_show(struct device *dev, |
2133 | struct device_attribute *attr, | 2157 | struct device_attribute *attr, |
2134 | char *buf) | 2158 | char *buf) |
2135 | { | 2159 | { |
2136 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2160 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2137 | 2161 | ||
2138 | return snprintf(buf, 10, "%u\n", bmc->id.device_id); | 2162 | return snprintf(buf, 10, "%u\n", bmc->id.device_id); |
2139 | } | 2163 | } |
2140 | 2164 | ||
2141 | static ssize_t provides_dev_sdrs_show(struct device *dev, | 2165 | static ssize_t provides_dev_sdrs_show(struct device *dev, |
2142 | struct device_attribute *attr, | 2166 | struct device_attribute *attr, |
2143 | char *buf) | 2167 | char *buf) |
2144 | { | 2168 | { |
2145 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2169 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2146 | 2170 | ||
2147 | return snprintf(buf, 10, "%u\n", | 2171 | return snprintf(buf, 10, "%u\n", |
2148 | (bmc->id.device_revision & 0x80) >> 7); | 2172 | (bmc->id.device_revision & 0x80) >> 7); |
2149 | } | 2173 | } |
2150 | 2174 | ||
2151 | static ssize_t revision_show(struct device *dev, struct device_attribute *attr, | 2175 | static ssize_t revision_show(struct device *dev, struct device_attribute *attr, |
2152 | char *buf) | 2176 | char *buf) |
2153 | { | 2177 | { |
2154 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2178 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2155 | 2179 | ||
2156 | return snprintf(buf, 20, "%u\n", | 2180 | return snprintf(buf, 20, "%u\n", |
2157 | bmc->id.device_revision & 0x0F); | 2181 | bmc->id.device_revision & 0x0F); |
2158 | } | 2182 | } |
2159 | 2183 | ||
2160 | static ssize_t firmware_rev_show(struct device *dev, | 2184 | static ssize_t firmware_rev_show(struct device *dev, |
2161 | struct device_attribute *attr, | 2185 | struct device_attribute *attr, |
2162 | char *buf) | 2186 | char *buf) |
2163 | { | 2187 | { |
2164 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2188 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2165 | 2189 | ||
2166 | return snprintf(buf, 20, "%u.%x\n", bmc->id.firmware_revision_1, | 2190 | return snprintf(buf, 20, "%u.%x\n", bmc->id.firmware_revision_1, |
2167 | bmc->id.firmware_revision_2); | 2191 | bmc->id.firmware_revision_2); |
2168 | } | 2192 | } |
2169 | 2193 | ||
2170 | static ssize_t ipmi_version_show(struct device *dev, | 2194 | static ssize_t ipmi_version_show(struct device *dev, |
2171 | struct device_attribute *attr, | 2195 | struct device_attribute *attr, |
2172 | char *buf) | 2196 | char *buf) |
2173 | { | 2197 | { |
2174 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2198 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2175 | 2199 | ||
2176 | return snprintf(buf, 20, "%u.%u\n", | 2200 | return snprintf(buf, 20, "%u.%u\n", |
2177 | ipmi_version_major(&bmc->id), | 2201 | ipmi_version_major(&bmc->id), |
2178 | ipmi_version_minor(&bmc->id)); | 2202 | ipmi_version_minor(&bmc->id)); |
2179 | } | 2203 | } |
2180 | 2204 | ||
2181 | static ssize_t add_dev_support_show(struct device *dev, | 2205 | static ssize_t add_dev_support_show(struct device *dev, |
2182 | struct device_attribute *attr, | 2206 | struct device_attribute *attr, |
2183 | char *buf) | 2207 | char *buf) |
2184 | { | 2208 | { |
2185 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2209 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2186 | 2210 | ||
2187 | return snprintf(buf, 10, "0x%02x\n", | 2211 | return snprintf(buf, 10, "0x%02x\n", |
2188 | bmc->id.additional_device_support); | 2212 | bmc->id.additional_device_support); |
2189 | } | 2213 | } |
2190 | 2214 | ||
2191 | static ssize_t manufacturer_id_show(struct device *dev, | 2215 | static ssize_t manufacturer_id_show(struct device *dev, |
2192 | struct device_attribute *attr, | 2216 | struct device_attribute *attr, |
2193 | char *buf) | 2217 | char *buf) |
2194 | { | 2218 | { |
2195 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2219 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2196 | 2220 | ||
2197 | return snprintf(buf, 20, "0x%6.6x\n", bmc->id.manufacturer_id); | 2221 | return snprintf(buf, 20, "0x%6.6x\n", bmc->id.manufacturer_id); |
2198 | } | 2222 | } |
2199 | 2223 | ||
2200 | static ssize_t product_id_show(struct device *dev, | 2224 | static ssize_t product_id_show(struct device *dev, |
2201 | struct device_attribute *attr, | 2225 | struct device_attribute *attr, |
2202 | char *buf) | 2226 | char *buf) |
2203 | { | 2227 | { |
2204 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2228 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2205 | 2229 | ||
2206 | return snprintf(buf, 10, "0x%4.4x\n", bmc->id.product_id); | 2230 | return snprintf(buf, 10, "0x%4.4x\n", bmc->id.product_id); |
2207 | } | 2231 | } |
2208 | 2232 | ||
2209 | static ssize_t aux_firmware_rev_show(struct device *dev, | 2233 | static ssize_t aux_firmware_rev_show(struct device *dev, |
2210 | struct device_attribute *attr, | 2234 | struct device_attribute *attr, |
2211 | char *buf) | 2235 | char *buf) |
2212 | { | 2236 | { |
2213 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2237 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2214 | 2238 | ||
2215 | return snprintf(buf, 21, "0x%02x 0x%02x 0x%02x 0x%02x\n", | 2239 | return snprintf(buf, 21, "0x%02x 0x%02x 0x%02x 0x%02x\n", |
2216 | bmc->id.aux_firmware_revision[3], | 2240 | bmc->id.aux_firmware_revision[3], |
2217 | bmc->id.aux_firmware_revision[2], | 2241 | bmc->id.aux_firmware_revision[2], |
2218 | bmc->id.aux_firmware_revision[1], | 2242 | bmc->id.aux_firmware_revision[1], |
2219 | bmc->id.aux_firmware_revision[0]); | 2243 | bmc->id.aux_firmware_revision[0]); |
2220 | } | 2244 | } |
2221 | 2245 | ||
2222 | static ssize_t guid_show(struct device *dev, struct device_attribute *attr, | 2246 | static ssize_t guid_show(struct device *dev, struct device_attribute *attr, |
2223 | char *buf) | 2247 | char *buf) |
2224 | { | 2248 | { |
2225 | struct bmc_device *bmc = dev_get_drvdata(dev); | 2249 | struct bmc_device *bmc = dev_get_drvdata(dev); |
2226 | 2250 | ||
2227 | return snprintf(buf, 100, "%Lx%Lx\n", | 2251 | return snprintf(buf, 100, "%Lx%Lx\n", |
2228 | (long long) bmc->guid[0], | 2252 | (long long) bmc->guid[0], |
2229 | (long long) bmc->guid[8]); | 2253 | (long long) bmc->guid[8]); |
2230 | } | 2254 | } |
2231 | 2255 | ||
2232 | static void remove_files(struct bmc_device *bmc) | 2256 | static void remove_files(struct bmc_device *bmc) |
2233 | { | 2257 | { |
2234 | if (!bmc->dev) | 2258 | if (!bmc->dev) |
2235 | return; | 2259 | return; |
2236 | 2260 | ||
2237 | device_remove_file(&bmc->dev->dev, | 2261 | device_remove_file(&bmc->dev->dev, |
2238 | &bmc->device_id_attr); | 2262 | &bmc->device_id_attr); |
2239 | device_remove_file(&bmc->dev->dev, | 2263 | device_remove_file(&bmc->dev->dev, |
2240 | &bmc->provides_dev_sdrs_attr); | 2264 | &bmc->provides_dev_sdrs_attr); |
2241 | device_remove_file(&bmc->dev->dev, | 2265 | device_remove_file(&bmc->dev->dev, |
2242 | &bmc->revision_attr); | 2266 | &bmc->revision_attr); |
2243 | device_remove_file(&bmc->dev->dev, | 2267 | device_remove_file(&bmc->dev->dev, |
2244 | &bmc->firmware_rev_attr); | 2268 | &bmc->firmware_rev_attr); |
2245 | device_remove_file(&bmc->dev->dev, | 2269 | device_remove_file(&bmc->dev->dev, |
2246 | &bmc->version_attr); | 2270 | &bmc->version_attr); |
2247 | device_remove_file(&bmc->dev->dev, | 2271 | device_remove_file(&bmc->dev->dev, |
2248 | &bmc->add_dev_support_attr); | 2272 | &bmc->add_dev_support_attr); |
2249 | device_remove_file(&bmc->dev->dev, | 2273 | device_remove_file(&bmc->dev->dev, |
2250 | &bmc->manufacturer_id_attr); | 2274 | &bmc->manufacturer_id_attr); |
2251 | device_remove_file(&bmc->dev->dev, | 2275 | device_remove_file(&bmc->dev->dev, |
2252 | &bmc->product_id_attr); | 2276 | &bmc->product_id_attr); |
2253 | 2277 | ||
2254 | if (bmc->id.aux_firmware_revision_set) | 2278 | if (bmc->id.aux_firmware_revision_set) |
2255 | device_remove_file(&bmc->dev->dev, | 2279 | device_remove_file(&bmc->dev->dev, |
2256 | &bmc->aux_firmware_rev_attr); | 2280 | &bmc->aux_firmware_rev_attr); |
2257 | if (bmc->guid_set) | 2281 | if (bmc->guid_set) |
2258 | device_remove_file(&bmc->dev->dev, | 2282 | device_remove_file(&bmc->dev->dev, |
2259 | &bmc->guid_attr); | 2283 | &bmc->guid_attr); |
2260 | } | 2284 | } |
2261 | 2285 | ||
2262 | static void | 2286 | static void |
2263 | cleanup_bmc_device(struct kref *ref) | 2287 | cleanup_bmc_device(struct kref *ref) |
2264 | { | 2288 | { |
2265 | struct bmc_device *bmc; | 2289 | struct bmc_device *bmc; |
2266 | 2290 | ||
2267 | bmc = container_of(ref, struct bmc_device, refcount); | 2291 | bmc = container_of(ref, struct bmc_device, refcount); |
2268 | 2292 | ||
2269 | remove_files(bmc); | 2293 | remove_files(bmc); |
2270 | platform_device_unregister(bmc->dev); | 2294 | platform_device_unregister(bmc->dev); |
2271 | kfree(bmc); | 2295 | kfree(bmc); |
2272 | } | 2296 | } |
2273 | 2297 | ||
2274 | static void ipmi_bmc_unregister(ipmi_smi_t intf) | 2298 | static void ipmi_bmc_unregister(ipmi_smi_t intf) |
2275 | { | 2299 | { |
2276 | struct bmc_device *bmc = intf->bmc; | 2300 | struct bmc_device *bmc = intf->bmc; |
2277 | 2301 | ||
2278 | if (intf->sysfs_name) { | 2302 | if (intf->sysfs_name) { |
2279 | sysfs_remove_link(&intf->si_dev->kobj, intf->sysfs_name); | 2303 | sysfs_remove_link(&intf->si_dev->kobj, intf->sysfs_name); |
2280 | kfree(intf->sysfs_name); | 2304 | kfree(intf->sysfs_name); |
2281 | intf->sysfs_name = NULL; | 2305 | intf->sysfs_name = NULL; |
2282 | } | 2306 | } |
2283 | if (intf->my_dev_name) { | 2307 | if (intf->my_dev_name) { |
2284 | sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name); | 2308 | sysfs_remove_link(&bmc->dev->dev.kobj, intf->my_dev_name); |
2285 | kfree(intf->my_dev_name); | 2309 | kfree(intf->my_dev_name); |
2286 | intf->my_dev_name = NULL; | 2310 | intf->my_dev_name = NULL; |
2287 | } | 2311 | } |
2288 | 2312 | ||
2289 | mutex_lock(&ipmidriver_mutex); | 2313 | mutex_lock(&ipmidriver_mutex); |
2290 | kref_put(&bmc->refcount, cleanup_bmc_device); | 2314 | kref_put(&bmc->refcount, cleanup_bmc_device); |
2291 | intf->bmc = NULL; | 2315 | intf->bmc = NULL; |
2292 | mutex_unlock(&ipmidriver_mutex); | 2316 | mutex_unlock(&ipmidriver_mutex); |
2293 | } | 2317 | } |
2294 | 2318 | ||
2295 | static int create_files(struct bmc_device *bmc) | 2319 | static int create_files(struct bmc_device *bmc) |
2296 | { | 2320 | { |
2297 | int err; | 2321 | int err; |
2298 | 2322 | ||
2299 | bmc->device_id_attr.attr.name = "device_id"; | 2323 | bmc->device_id_attr.attr.name = "device_id"; |
2300 | bmc->device_id_attr.attr.mode = S_IRUGO; | 2324 | bmc->device_id_attr.attr.mode = S_IRUGO; |
2301 | bmc->device_id_attr.show = device_id_show; | 2325 | bmc->device_id_attr.show = device_id_show; |
2302 | sysfs_attr_init(&bmc->device_id_attr.attr); | 2326 | sysfs_attr_init(&bmc->device_id_attr.attr); |
2303 | 2327 | ||
2304 | bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; | 2328 | bmc->provides_dev_sdrs_attr.attr.name = "provides_device_sdrs"; |
2305 | bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; | 2329 | bmc->provides_dev_sdrs_attr.attr.mode = S_IRUGO; |
2306 | bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; | 2330 | bmc->provides_dev_sdrs_attr.show = provides_dev_sdrs_show; |
2307 | sysfs_attr_init(&bmc->provides_dev_sdrs_attr.attr); | 2331 | sysfs_attr_init(&bmc->provides_dev_sdrs_attr.attr); |
2308 | 2332 | ||
2309 | bmc->revision_attr.attr.name = "revision"; | 2333 | bmc->revision_attr.attr.name = "revision"; |
2310 | bmc->revision_attr.attr.mode = S_IRUGO; | 2334 | bmc->revision_attr.attr.mode = S_IRUGO; |
2311 | bmc->revision_attr.show = revision_show; | 2335 | bmc->revision_attr.show = revision_show; |
2312 | sysfs_attr_init(&bmc->revision_attr.attr); | 2336 | sysfs_attr_init(&bmc->revision_attr.attr); |
2313 | 2337 | ||
2314 | bmc->firmware_rev_attr.attr.name = "firmware_revision"; | 2338 | bmc->firmware_rev_attr.attr.name = "firmware_revision"; |
2315 | bmc->firmware_rev_attr.attr.mode = S_IRUGO; | 2339 | bmc->firmware_rev_attr.attr.mode = S_IRUGO; |
2316 | bmc->firmware_rev_attr.show = firmware_rev_show; | 2340 | bmc->firmware_rev_attr.show = firmware_rev_show; |
2317 | sysfs_attr_init(&bmc->firmware_rev_attr.attr); | 2341 | sysfs_attr_init(&bmc->firmware_rev_attr.attr); |
2318 | 2342 | ||
2319 | bmc->version_attr.attr.name = "ipmi_version"; | 2343 | bmc->version_attr.attr.name = "ipmi_version"; |
2320 | bmc->version_attr.attr.mode = S_IRUGO; | 2344 | bmc->version_attr.attr.mode = S_IRUGO; |
2321 | bmc->version_attr.show = ipmi_version_show; | 2345 | bmc->version_attr.show = ipmi_version_show; |
2322 | sysfs_attr_init(&bmc->version_attr.attr); | 2346 | sysfs_attr_init(&bmc->version_attr.attr); |
2323 | 2347 | ||
2324 | bmc->add_dev_support_attr.attr.name = "additional_device_support"; | 2348 | bmc->add_dev_support_attr.attr.name = "additional_device_support"; |
2325 | bmc->add_dev_support_attr.attr.mode = S_IRUGO; | 2349 | bmc->add_dev_support_attr.attr.mode = S_IRUGO; |
2326 | bmc->add_dev_support_attr.show = add_dev_support_show; | 2350 | bmc->add_dev_support_attr.show = add_dev_support_show; |
2327 | sysfs_attr_init(&bmc->add_dev_support_attr.attr); | 2351 | sysfs_attr_init(&bmc->add_dev_support_attr.attr); |
2328 | 2352 | ||
2329 | bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; | 2353 | bmc->manufacturer_id_attr.attr.name = "manufacturer_id"; |
2330 | bmc->manufacturer_id_attr.attr.mode = S_IRUGO; | 2354 | bmc->manufacturer_id_attr.attr.mode = S_IRUGO; |
2331 | bmc->manufacturer_id_attr.show = manufacturer_id_show; | 2355 | bmc->manufacturer_id_attr.show = manufacturer_id_show; |
2332 | sysfs_attr_init(&bmc->manufacturer_id_attr.attr); | 2356 | sysfs_attr_init(&bmc->manufacturer_id_attr.attr); |
2333 | 2357 | ||
2334 | bmc->product_id_attr.attr.name = "product_id"; | 2358 | bmc->product_id_attr.attr.name = "product_id"; |
2335 | bmc->product_id_attr.attr.mode = S_IRUGO; | 2359 | bmc->product_id_attr.attr.mode = S_IRUGO; |
2336 | bmc->product_id_attr.show = product_id_show; | 2360 | bmc->product_id_attr.show = product_id_show; |
2337 | sysfs_attr_init(&bmc->product_id_attr.attr); | 2361 | sysfs_attr_init(&bmc->product_id_attr.attr); |
2338 | 2362 | ||
2339 | bmc->guid_attr.attr.name = "guid"; | 2363 | bmc->guid_attr.attr.name = "guid"; |
2340 | bmc->guid_attr.attr.mode = S_IRUGO; | 2364 | bmc->guid_attr.attr.mode = S_IRUGO; |
2341 | bmc->guid_attr.show = guid_show; | 2365 | bmc->guid_attr.show = guid_show; |
2342 | sysfs_attr_init(&bmc->guid_attr.attr); | 2366 | sysfs_attr_init(&bmc->guid_attr.attr); |
2343 | 2367 | ||
2344 | bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; | 2368 | bmc->aux_firmware_rev_attr.attr.name = "aux_firmware_revision"; |
2345 | bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; | 2369 | bmc->aux_firmware_rev_attr.attr.mode = S_IRUGO; |
2346 | bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; | 2370 | bmc->aux_firmware_rev_attr.show = aux_firmware_rev_show; |
2347 | sysfs_attr_init(&bmc->aux_firmware_rev_attr.attr); | 2371 | sysfs_attr_init(&bmc->aux_firmware_rev_attr.attr); |
2348 | 2372 | ||
2349 | err = device_create_file(&bmc->dev->dev, | 2373 | err = device_create_file(&bmc->dev->dev, |
2350 | &bmc->device_id_attr); | 2374 | &bmc->device_id_attr); |
2351 | if (err) | 2375 | if (err) |
2352 | goto out; | 2376 | goto out; |
2353 | err = device_create_file(&bmc->dev->dev, | 2377 | err = device_create_file(&bmc->dev->dev, |
2354 | &bmc->provides_dev_sdrs_attr); | 2378 | &bmc->provides_dev_sdrs_attr); |
2355 | if (err) | 2379 | if (err) |
2356 | goto out_devid; | 2380 | goto out_devid; |
2357 | err = device_create_file(&bmc->dev->dev, | 2381 | err = device_create_file(&bmc->dev->dev, |
2358 | &bmc->revision_attr); | 2382 | &bmc->revision_attr); |
2359 | if (err) | 2383 | if (err) |
2360 | goto out_sdrs; | 2384 | goto out_sdrs; |
2361 | err = device_create_file(&bmc->dev->dev, | 2385 | err = device_create_file(&bmc->dev->dev, |
2362 | &bmc->firmware_rev_attr); | 2386 | &bmc->firmware_rev_attr); |
2363 | if (err) | 2387 | if (err) |
2364 | goto out_rev; | 2388 | goto out_rev; |
2365 | err = device_create_file(&bmc->dev->dev, | 2389 | err = device_create_file(&bmc->dev->dev, |
2366 | &bmc->version_attr); | 2390 | &bmc->version_attr); |
2367 | if (err) | 2391 | if (err) |
2368 | goto out_firm; | 2392 | goto out_firm; |
2369 | err = device_create_file(&bmc->dev->dev, | 2393 | err = device_create_file(&bmc->dev->dev, |
2370 | &bmc->add_dev_support_attr); | 2394 | &bmc->add_dev_support_attr); |
2371 | if (err) | 2395 | if (err) |
2372 | goto out_version; | 2396 | goto out_version; |
2373 | err = device_create_file(&bmc->dev->dev, | 2397 | err = device_create_file(&bmc->dev->dev, |
2374 | &bmc->manufacturer_id_attr); | 2398 | &bmc->manufacturer_id_attr); |
2375 | if (err) | 2399 | if (err) |
2376 | goto out_add_dev; | 2400 | goto out_add_dev; |
2377 | err = device_create_file(&bmc->dev->dev, | 2401 | err = device_create_file(&bmc->dev->dev, |
2378 | &bmc->product_id_attr); | 2402 | &bmc->product_id_attr); |
2379 | if (err) | 2403 | if (err) |
2380 | goto out_manu; | 2404 | goto out_manu; |
2381 | if (bmc->id.aux_firmware_revision_set) { | 2405 | if (bmc->id.aux_firmware_revision_set) { |
2382 | err = device_create_file(&bmc->dev->dev, | 2406 | err = device_create_file(&bmc->dev->dev, |
2383 | &bmc->aux_firmware_rev_attr); | 2407 | &bmc->aux_firmware_rev_attr); |
2384 | if (err) | 2408 | if (err) |
2385 | goto out_prod_id; | 2409 | goto out_prod_id; |
2386 | } | 2410 | } |
2387 | if (bmc->guid_set) { | 2411 | if (bmc->guid_set) { |
2388 | err = device_create_file(&bmc->dev->dev, | 2412 | err = device_create_file(&bmc->dev->dev, |
2389 | &bmc->guid_attr); | 2413 | &bmc->guid_attr); |
2390 | if (err) | 2414 | if (err) |
2391 | goto out_aux_firm; | 2415 | goto out_aux_firm; |
2392 | } | 2416 | } |
2393 | 2417 | ||
2394 | return 0; | 2418 | return 0; |
2395 | 2419 | ||
2396 | out_aux_firm: | 2420 | out_aux_firm: |
2397 | if (bmc->id.aux_firmware_revision_set) | 2421 | if (bmc->id.aux_firmware_revision_set) |
2398 | device_remove_file(&bmc->dev->dev, | 2422 | device_remove_file(&bmc->dev->dev, |
2399 | &bmc->aux_firmware_rev_attr); | 2423 | &bmc->aux_firmware_rev_attr); |
2400 | out_prod_id: | 2424 | out_prod_id: |
2401 | device_remove_file(&bmc->dev->dev, | 2425 | device_remove_file(&bmc->dev->dev, |
2402 | &bmc->product_id_attr); | 2426 | &bmc->product_id_attr); |
2403 | out_manu: | 2427 | out_manu: |
2404 | device_remove_file(&bmc->dev->dev, | 2428 | device_remove_file(&bmc->dev->dev, |
2405 | &bmc->manufacturer_id_attr); | 2429 | &bmc->manufacturer_id_attr); |
2406 | out_add_dev: | 2430 | out_add_dev: |
2407 | device_remove_file(&bmc->dev->dev, | 2431 | device_remove_file(&bmc->dev->dev, |
2408 | &bmc->add_dev_support_attr); | 2432 | &bmc->add_dev_support_attr); |
2409 | out_version: | 2433 | out_version: |
2410 | device_remove_file(&bmc->dev->dev, | 2434 | device_remove_file(&bmc->dev->dev, |
2411 | &bmc->version_attr); | 2435 | &bmc->version_attr); |
2412 | out_firm: | 2436 | out_firm: |
2413 | device_remove_file(&bmc->dev->dev, | 2437 | device_remove_file(&bmc->dev->dev, |
2414 | &bmc->firmware_rev_attr); | 2438 | &bmc->firmware_rev_attr); |
2415 | out_rev: | 2439 | out_rev: |
2416 | device_remove_file(&bmc->dev->dev, | 2440 | device_remove_file(&bmc->dev->dev, |
2417 | &bmc->revision_attr); | 2441 | &bmc->revision_attr); |
2418 | out_sdrs: | 2442 | out_sdrs: |
2419 | device_remove_file(&bmc->dev->dev, | 2443 | device_remove_file(&bmc->dev->dev, |
2420 | &bmc->provides_dev_sdrs_attr); | 2444 | &bmc->provides_dev_sdrs_attr); |
2421 | out_devid: | 2445 | out_devid: |
2422 | device_remove_file(&bmc->dev->dev, | 2446 | device_remove_file(&bmc->dev->dev, |
2423 | &bmc->device_id_attr); | 2447 | &bmc->device_id_attr); |
2424 | out: | 2448 | out: |
2425 | return err; | 2449 | return err; |
2426 | } | 2450 | } |
2427 | 2451 | ||
2428 | static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, | 2452 | static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum, |
2429 | const char *sysfs_name) | 2453 | const char *sysfs_name) |
2430 | { | 2454 | { |
2431 | int rv; | 2455 | int rv; |
2432 | struct bmc_device *bmc = intf->bmc; | 2456 | struct bmc_device *bmc = intf->bmc; |
2433 | struct bmc_device *old_bmc; | 2457 | struct bmc_device *old_bmc; |
2434 | int size; | 2458 | int size; |
2435 | char dummy[1]; | 2459 | char dummy[1]; |
2436 | 2460 | ||
2437 | mutex_lock(&ipmidriver_mutex); | 2461 | mutex_lock(&ipmidriver_mutex); |
2438 | 2462 | ||
2439 | /* | 2463 | /* |
2440 | * Try to find if there is an bmc_device struct | 2464 | * Try to find if there is an bmc_device struct |
2441 | * representing the interfaced BMC already | 2465 | * representing the interfaced BMC already |
2442 | */ | 2466 | */ |
2443 | if (bmc->guid_set) | 2467 | if (bmc->guid_set) |
2444 | old_bmc = ipmi_find_bmc_guid(&ipmidriver.driver, bmc->guid); | 2468 | old_bmc = ipmi_find_bmc_guid(&ipmidriver.driver, bmc->guid); |
2445 | else | 2469 | else |
2446 | old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, | 2470 | old_bmc = ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, |
2447 | bmc->id.product_id, | 2471 | bmc->id.product_id, |
2448 | bmc->id.device_id); | 2472 | bmc->id.device_id); |
2449 | 2473 | ||
2450 | /* | 2474 | /* |
2451 | * If there is already an bmc_device, free the new one, | 2475 | * If there is already an bmc_device, free the new one, |
2452 | * otherwise register the new BMC device | 2476 | * otherwise register the new BMC device |
2453 | */ | 2477 | */ |
2454 | if (old_bmc) { | 2478 | if (old_bmc) { |
2455 | kfree(bmc); | 2479 | kfree(bmc); |
2456 | intf->bmc = old_bmc; | 2480 | intf->bmc = old_bmc; |
2457 | bmc = old_bmc; | 2481 | bmc = old_bmc; |
2458 | 2482 | ||
2459 | kref_get(&bmc->refcount); | 2483 | kref_get(&bmc->refcount); |
2460 | mutex_unlock(&ipmidriver_mutex); | 2484 | mutex_unlock(&ipmidriver_mutex); |
2461 | 2485 | ||
2462 | printk(KERN_INFO | 2486 | printk(KERN_INFO |
2463 | "ipmi: interfacing existing BMC (man_id: 0x%6.6x," | 2487 | "ipmi: interfacing existing BMC (man_id: 0x%6.6x," |
2464 | " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", | 2488 | " prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", |
2465 | bmc->id.manufacturer_id, | 2489 | bmc->id.manufacturer_id, |
2466 | bmc->id.product_id, | 2490 | bmc->id.product_id, |
2467 | bmc->id.device_id); | 2491 | bmc->id.device_id); |
2468 | } else { | 2492 | } else { |
2469 | char name[14]; | 2493 | char name[14]; |
2470 | unsigned char orig_dev_id = bmc->id.device_id; | 2494 | unsigned char orig_dev_id = bmc->id.device_id; |
2471 | int warn_printed = 0; | 2495 | int warn_printed = 0; |
2472 | 2496 | ||
2473 | snprintf(name, sizeof(name), | 2497 | snprintf(name, sizeof(name), |
2474 | "ipmi_bmc.%4.4x", bmc->id.product_id); | 2498 | "ipmi_bmc.%4.4x", bmc->id.product_id); |
2475 | 2499 | ||
2476 | while (ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, | 2500 | while (ipmi_find_bmc_prod_dev_id(&ipmidriver.driver, |
2477 | bmc->id.product_id, | 2501 | bmc->id.product_id, |
2478 | bmc->id.device_id)) { | 2502 | bmc->id.device_id)) { |
2479 | if (!warn_printed) { | 2503 | if (!warn_printed) { |
2480 | printk(KERN_WARNING PFX | 2504 | printk(KERN_WARNING PFX |
2481 | "This machine has two different BMCs" | 2505 | "This machine has two different BMCs" |
2482 | " with the same product id and device" | 2506 | " with the same product id and device" |
2483 | " id. This is an error in the" | 2507 | " id. This is an error in the" |
2484 | " firmware, but incrementing the" | 2508 | " firmware, but incrementing the" |
2485 | " device id to work around the problem." | 2509 | " device id to work around the problem." |
2486 | " Prod ID = 0x%x, Dev ID = 0x%x\n", | 2510 | " Prod ID = 0x%x, Dev ID = 0x%x\n", |
2487 | bmc->id.product_id, bmc->id.device_id); | 2511 | bmc->id.product_id, bmc->id.device_id); |
2488 | warn_printed = 1; | 2512 | warn_printed = 1; |
2489 | } | 2513 | } |
2490 | bmc->id.device_id++; /* Wraps at 255 */ | 2514 | bmc->id.device_id++; /* Wraps at 255 */ |
2491 | if (bmc->id.device_id == orig_dev_id) { | 2515 | if (bmc->id.device_id == orig_dev_id) { |
2492 | printk(KERN_ERR PFX | 2516 | printk(KERN_ERR PFX |
2493 | "Out of device ids!\n"); | 2517 | "Out of device ids!\n"); |
2494 | break; | 2518 | break; |
2495 | } | 2519 | } |
2496 | } | 2520 | } |
2497 | 2521 | ||
2498 | bmc->dev = platform_device_alloc(name, bmc->id.device_id); | 2522 | bmc->dev = platform_device_alloc(name, bmc->id.device_id); |
2499 | if (!bmc->dev) { | 2523 | if (!bmc->dev) { |
2500 | mutex_unlock(&ipmidriver_mutex); | 2524 | mutex_unlock(&ipmidriver_mutex); |
2501 | printk(KERN_ERR | 2525 | printk(KERN_ERR |
2502 | "ipmi_msghandler:" | 2526 | "ipmi_msghandler:" |
2503 | " Unable to allocate platform device\n"); | 2527 | " Unable to allocate platform device\n"); |
2504 | return -ENOMEM; | 2528 | return -ENOMEM; |
2505 | } | 2529 | } |
2506 | bmc->dev->dev.driver = &ipmidriver.driver; | 2530 | bmc->dev->dev.driver = &ipmidriver.driver; |
2507 | dev_set_drvdata(&bmc->dev->dev, bmc); | 2531 | dev_set_drvdata(&bmc->dev->dev, bmc); |
2508 | kref_init(&bmc->refcount); | 2532 | kref_init(&bmc->refcount); |
2509 | 2533 | ||
2510 | rv = platform_device_add(bmc->dev); | 2534 | rv = platform_device_add(bmc->dev); |
2511 | mutex_unlock(&ipmidriver_mutex); | 2535 | mutex_unlock(&ipmidriver_mutex); |
2512 | if (rv) { | 2536 | if (rv) { |
2513 | platform_device_put(bmc->dev); | 2537 | platform_device_put(bmc->dev); |
2514 | bmc->dev = NULL; | 2538 | bmc->dev = NULL; |
2515 | printk(KERN_ERR | 2539 | printk(KERN_ERR |
2516 | "ipmi_msghandler:" | 2540 | "ipmi_msghandler:" |
2517 | " Unable to register bmc device: %d\n", | 2541 | " Unable to register bmc device: %d\n", |
2518 | rv); | 2542 | rv); |
2519 | /* | 2543 | /* |
2520 | * Don't go to out_err, you can only do that if | 2544 | * Don't go to out_err, you can only do that if |
2521 | * the device is registered already. | 2545 | * the device is registered already. |
2522 | */ | 2546 | */ |
2523 | return rv; | 2547 | return rv; |
2524 | } | 2548 | } |
2525 | 2549 | ||
2526 | rv = create_files(bmc); | 2550 | rv = create_files(bmc); |
2527 | if (rv) { | 2551 | if (rv) { |
2528 | mutex_lock(&ipmidriver_mutex); | 2552 | mutex_lock(&ipmidriver_mutex); |
2529 | platform_device_unregister(bmc->dev); | 2553 | platform_device_unregister(bmc->dev); |
2530 | mutex_unlock(&ipmidriver_mutex); | 2554 | mutex_unlock(&ipmidriver_mutex); |
2531 | 2555 | ||
2532 | return rv; | 2556 | return rv; |
2533 | } | 2557 | } |
2534 | 2558 | ||
2535 | dev_info(intf->si_dev, "Found new BMC (man_id: 0x%6.6x, " | 2559 | dev_info(intf->si_dev, "Found new BMC (man_id: 0x%6.6x, " |
2536 | "prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", | 2560 | "prod_id: 0x%4.4x, dev_id: 0x%2.2x)\n", |
2537 | bmc->id.manufacturer_id, | 2561 | bmc->id.manufacturer_id, |
2538 | bmc->id.product_id, | 2562 | bmc->id.product_id, |
2539 | bmc->id.device_id); | 2563 | bmc->id.device_id); |
2540 | } | 2564 | } |
2541 | 2565 | ||
2542 | /* | 2566 | /* |
2543 | * create symlink from system interface device to bmc device | 2567 | * create symlink from system interface device to bmc device |
2544 | * and back. | 2568 | * and back. |
2545 | */ | 2569 | */ |
2546 | intf->sysfs_name = kstrdup(sysfs_name, GFP_KERNEL); | 2570 | intf->sysfs_name = kstrdup(sysfs_name, GFP_KERNEL); |
2547 | if (!intf->sysfs_name) { | 2571 | if (!intf->sysfs_name) { |
2548 | rv = -ENOMEM; | 2572 | rv = -ENOMEM; |
2549 | printk(KERN_ERR | 2573 | printk(KERN_ERR |
2550 | "ipmi_msghandler: allocate link to BMC: %d\n", | 2574 | "ipmi_msghandler: allocate link to BMC: %d\n", |
2551 | rv); | 2575 | rv); |
2552 | goto out_err; | 2576 | goto out_err; |
2553 | } | 2577 | } |
2554 | 2578 | ||
2555 | rv = sysfs_create_link(&intf->si_dev->kobj, | 2579 | rv = sysfs_create_link(&intf->si_dev->kobj, |
2556 | &bmc->dev->dev.kobj, intf->sysfs_name); | 2580 | &bmc->dev->dev.kobj, intf->sysfs_name); |
2557 | if (rv) { | 2581 | if (rv) { |
2558 | kfree(intf->sysfs_name); | 2582 | kfree(intf->sysfs_name); |
2559 | intf->sysfs_name = NULL; | 2583 | intf->sysfs_name = NULL; |
2560 | printk(KERN_ERR | 2584 | printk(KERN_ERR |
2561 | "ipmi_msghandler: Unable to create bmc symlink: %d\n", | 2585 | "ipmi_msghandler: Unable to create bmc symlink: %d\n", |
2562 | rv); | 2586 | rv); |
2563 | goto out_err; | 2587 | goto out_err; |
2564 | } | 2588 | } |
2565 | 2589 | ||
2566 | size = snprintf(dummy, 0, "ipmi%d", ifnum); | 2590 | size = snprintf(dummy, 0, "ipmi%d", ifnum); |
2567 | intf->my_dev_name = kmalloc(size+1, GFP_KERNEL); | 2591 | intf->my_dev_name = kmalloc(size+1, GFP_KERNEL); |
2568 | if (!intf->my_dev_name) { | 2592 | if (!intf->my_dev_name) { |
2569 | kfree(intf->sysfs_name); | 2593 | kfree(intf->sysfs_name); |
2570 | intf->sysfs_name = NULL; | 2594 | intf->sysfs_name = NULL; |
2571 | rv = -ENOMEM; | 2595 | rv = -ENOMEM; |
2572 | printk(KERN_ERR | 2596 | printk(KERN_ERR |
2573 | "ipmi_msghandler: allocate link from BMC: %d\n", | 2597 | "ipmi_msghandler: allocate link from BMC: %d\n", |
2574 | rv); | 2598 | rv); |
2575 | goto out_err; | 2599 | goto out_err; |
2576 | } | 2600 | } |
2577 | snprintf(intf->my_dev_name, size+1, "ipmi%d", ifnum); | 2601 | snprintf(intf->my_dev_name, size+1, "ipmi%d", ifnum); |
2578 | 2602 | ||
2579 | rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj, | 2603 | rv = sysfs_create_link(&bmc->dev->dev.kobj, &intf->si_dev->kobj, |
2580 | intf->my_dev_name); | 2604 | intf->my_dev_name); |
2581 | if (rv) { | 2605 | if (rv) { |
2582 | kfree(intf->sysfs_name); | 2606 | kfree(intf->sysfs_name); |
2583 | intf->sysfs_name = NULL; | 2607 | intf->sysfs_name = NULL; |
2584 | kfree(intf->my_dev_name); | 2608 | kfree(intf->my_dev_name); |
2585 | intf->my_dev_name = NULL; | 2609 | intf->my_dev_name = NULL; |
2586 | printk(KERN_ERR | 2610 | printk(KERN_ERR |
2587 | "ipmi_msghandler:" | 2611 | "ipmi_msghandler:" |
2588 | " Unable to create symlink to bmc: %d\n", | 2612 | " Unable to create symlink to bmc: %d\n", |
2589 | rv); | 2613 | rv); |
2590 | goto out_err; | 2614 | goto out_err; |
2591 | } | 2615 | } |
2592 | 2616 | ||
2593 | return 0; | 2617 | return 0; |
2594 | 2618 | ||
2595 | out_err: | 2619 | out_err: |
2596 | ipmi_bmc_unregister(intf); | 2620 | ipmi_bmc_unregister(intf); |
2597 | return rv; | 2621 | return rv; |
2598 | } | 2622 | } |
2599 | 2623 | ||
2600 | static int | 2624 | static int |
2601 | send_guid_cmd(ipmi_smi_t intf, int chan) | 2625 | send_guid_cmd(ipmi_smi_t intf, int chan) |
2602 | { | 2626 | { |
2603 | struct kernel_ipmi_msg msg; | 2627 | struct kernel_ipmi_msg msg; |
2604 | struct ipmi_system_interface_addr si; | 2628 | struct ipmi_system_interface_addr si; |
2605 | 2629 | ||
2606 | si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | 2630 | si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
2607 | si.channel = IPMI_BMC_CHANNEL; | 2631 | si.channel = IPMI_BMC_CHANNEL; |
2608 | si.lun = 0; | 2632 | si.lun = 0; |
2609 | 2633 | ||
2610 | msg.netfn = IPMI_NETFN_APP_REQUEST; | 2634 | msg.netfn = IPMI_NETFN_APP_REQUEST; |
2611 | msg.cmd = IPMI_GET_DEVICE_GUID_CMD; | 2635 | msg.cmd = IPMI_GET_DEVICE_GUID_CMD; |
2612 | msg.data = NULL; | 2636 | msg.data = NULL; |
2613 | msg.data_len = 0; | 2637 | msg.data_len = 0; |
2614 | return i_ipmi_request(NULL, | 2638 | return i_ipmi_request(NULL, |
2615 | intf, | 2639 | intf, |
2616 | (struct ipmi_addr *) &si, | 2640 | (struct ipmi_addr *) &si, |
2617 | 0, | 2641 | 0, |
2618 | &msg, | 2642 | &msg, |
2619 | intf, | 2643 | intf, |
2620 | NULL, | 2644 | NULL, |
2621 | NULL, | 2645 | NULL, |
2622 | 0, | 2646 | 0, |
2623 | intf->channels[0].address, | 2647 | intf->channels[0].address, |
2624 | intf->channels[0].lun, | 2648 | intf->channels[0].lun, |
2625 | -1, 0); | 2649 | -1, 0); |
2626 | } | 2650 | } |
2627 | 2651 | ||
2628 | static void | 2652 | static void |
2629 | guid_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg) | 2653 | guid_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
2630 | { | 2654 | { |
2631 | if ((msg->addr.addr_type != IPMI_SYSTEM_INTERFACE_ADDR_TYPE) | 2655 | if ((msg->addr.addr_type != IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
2632 | || (msg->msg.netfn != IPMI_NETFN_APP_RESPONSE) | 2656 | || (msg->msg.netfn != IPMI_NETFN_APP_RESPONSE) |
2633 | || (msg->msg.cmd != IPMI_GET_DEVICE_GUID_CMD)) | 2657 | || (msg->msg.cmd != IPMI_GET_DEVICE_GUID_CMD)) |
2634 | /* Not for me */ | 2658 | /* Not for me */ |
2635 | return; | 2659 | return; |
2636 | 2660 | ||
2637 | if (msg->msg.data[0] != 0) { | 2661 | if (msg->msg.data[0] != 0) { |
2638 | /* Error from getting the GUID, the BMC doesn't have one. */ | 2662 | /* Error from getting the GUID, the BMC doesn't have one. */ |
2639 | intf->bmc->guid_set = 0; | 2663 | intf->bmc->guid_set = 0; |
2640 | goto out; | 2664 | goto out; |
2641 | } | 2665 | } |
2642 | 2666 | ||
2643 | if (msg->msg.data_len < 17) { | 2667 | if (msg->msg.data_len < 17) { |
2644 | intf->bmc->guid_set = 0; | 2668 | intf->bmc->guid_set = 0; |
2645 | printk(KERN_WARNING PFX | 2669 | printk(KERN_WARNING PFX |
2646 | "guid_handler: The GUID response from the BMC was too" | 2670 | "guid_handler: The GUID response from the BMC was too" |
2647 | " short, it was %d but should have been 17. Assuming" | 2671 | " short, it was %d but should have been 17. Assuming" |
2648 | " GUID is not available.\n", | 2672 | " GUID is not available.\n", |
2649 | msg->msg.data_len); | 2673 | msg->msg.data_len); |
2650 | goto out; | 2674 | goto out; |
2651 | } | 2675 | } |
2652 | 2676 | ||
2653 | memcpy(intf->bmc->guid, msg->msg.data, 16); | 2677 | memcpy(intf->bmc->guid, msg->msg.data, 16); |
2654 | intf->bmc->guid_set = 1; | 2678 | intf->bmc->guid_set = 1; |
2655 | out: | 2679 | out: |
2656 | wake_up(&intf->waitq); | 2680 | wake_up(&intf->waitq); |
2657 | } | 2681 | } |
2658 | 2682 | ||
2659 | static void | 2683 | static void |
2660 | get_guid(ipmi_smi_t intf) | 2684 | get_guid(ipmi_smi_t intf) |
2661 | { | 2685 | { |
2662 | int rv; | 2686 | int rv; |
2663 | 2687 | ||
2664 | intf->bmc->guid_set = 0x2; | 2688 | intf->bmc->guid_set = 0x2; |
2665 | intf->null_user_handler = guid_handler; | 2689 | intf->null_user_handler = guid_handler; |
2666 | rv = send_guid_cmd(intf, 0); | 2690 | rv = send_guid_cmd(intf, 0); |
2667 | if (rv) | 2691 | if (rv) |
2668 | /* Send failed, no GUID available. */ | 2692 | /* Send failed, no GUID available. */ |
2669 | intf->bmc->guid_set = 0; | 2693 | intf->bmc->guid_set = 0; |
2670 | wait_event(intf->waitq, intf->bmc->guid_set != 2); | 2694 | wait_event(intf->waitq, intf->bmc->guid_set != 2); |
2671 | intf->null_user_handler = NULL; | 2695 | intf->null_user_handler = NULL; |
2672 | } | 2696 | } |
2673 | 2697 | ||
2674 | static int | 2698 | static int |
2675 | send_channel_info_cmd(ipmi_smi_t intf, int chan) | 2699 | send_channel_info_cmd(ipmi_smi_t intf, int chan) |
2676 | { | 2700 | { |
2677 | struct kernel_ipmi_msg msg; | 2701 | struct kernel_ipmi_msg msg; |
2678 | unsigned char data[1]; | 2702 | unsigned char data[1]; |
2679 | struct ipmi_system_interface_addr si; | 2703 | struct ipmi_system_interface_addr si; |
2680 | 2704 | ||
2681 | si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | 2705 | si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
2682 | si.channel = IPMI_BMC_CHANNEL; | 2706 | si.channel = IPMI_BMC_CHANNEL; |
2683 | si.lun = 0; | 2707 | si.lun = 0; |
2684 | 2708 | ||
2685 | msg.netfn = IPMI_NETFN_APP_REQUEST; | 2709 | msg.netfn = IPMI_NETFN_APP_REQUEST; |
2686 | msg.cmd = IPMI_GET_CHANNEL_INFO_CMD; | 2710 | msg.cmd = IPMI_GET_CHANNEL_INFO_CMD; |
2687 | msg.data = data; | 2711 | msg.data = data; |
2688 | msg.data_len = 1; | 2712 | msg.data_len = 1; |
2689 | data[0] = chan; | 2713 | data[0] = chan; |
2690 | return i_ipmi_request(NULL, | 2714 | return i_ipmi_request(NULL, |
2691 | intf, | 2715 | intf, |
2692 | (struct ipmi_addr *) &si, | 2716 | (struct ipmi_addr *) &si, |
2693 | 0, | 2717 | 0, |
2694 | &msg, | 2718 | &msg, |
2695 | intf, | 2719 | intf, |
2696 | NULL, | 2720 | NULL, |
2697 | NULL, | 2721 | NULL, |
2698 | 0, | 2722 | 0, |
2699 | intf->channels[0].address, | 2723 | intf->channels[0].address, |
2700 | intf->channels[0].lun, | 2724 | intf->channels[0].lun, |
2701 | -1, 0); | 2725 | -1, 0); |
2702 | } | 2726 | } |
2703 | 2727 | ||
2704 | static void | 2728 | static void |
2705 | channel_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg) | 2729 | channel_handler(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
2706 | { | 2730 | { |
2707 | int rv = 0; | 2731 | int rv = 0; |
2708 | int chan; | 2732 | int chan; |
2709 | 2733 | ||
2710 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) | 2734 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
2711 | && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE) | 2735 | && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE) |
2712 | && (msg->msg.cmd == IPMI_GET_CHANNEL_INFO_CMD)) { | 2736 | && (msg->msg.cmd == IPMI_GET_CHANNEL_INFO_CMD)) { |
2713 | /* It's the one we want */ | 2737 | /* It's the one we want */ |
2714 | if (msg->msg.data[0] != 0) { | 2738 | if (msg->msg.data[0] != 0) { |
2715 | /* Got an error from the channel, just go on. */ | 2739 | /* Got an error from the channel, just go on. */ |
2716 | 2740 | ||
2717 | if (msg->msg.data[0] == IPMI_INVALID_COMMAND_ERR) { | 2741 | if (msg->msg.data[0] == IPMI_INVALID_COMMAND_ERR) { |
2718 | /* | 2742 | /* |
2719 | * If the MC does not support this | 2743 | * If the MC does not support this |
2720 | * command, that is legal. We just | 2744 | * command, that is legal. We just |
2721 | * assume it has one IPMB at channel | 2745 | * assume it has one IPMB at channel |
2722 | * zero. | 2746 | * zero. |
2723 | */ | 2747 | */ |
2724 | intf->channels[0].medium | 2748 | intf->channels[0].medium |
2725 | = IPMI_CHANNEL_MEDIUM_IPMB; | 2749 | = IPMI_CHANNEL_MEDIUM_IPMB; |
2726 | intf->channels[0].protocol | 2750 | intf->channels[0].protocol |
2727 | = IPMI_CHANNEL_PROTOCOL_IPMB; | 2751 | = IPMI_CHANNEL_PROTOCOL_IPMB; |
2728 | rv = -ENOSYS; | 2752 | rv = -ENOSYS; |
2729 | 2753 | ||
2730 | intf->curr_channel = IPMI_MAX_CHANNELS; | 2754 | intf->curr_channel = IPMI_MAX_CHANNELS; |
2731 | wake_up(&intf->waitq); | 2755 | wake_up(&intf->waitq); |
2732 | goto out; | 2756 | goto out; |
2733 | } | 2757 | } |
2734 | goto next_channel; | 2758 | goto next_channel; |
2735 | } | 2759 | } |
2736 | if (msg->msg.data_len < 4) { | 2760 | if (msg->msg.data_len < 4) { |
2737 | /* Message not big enough, just go on. */ | 2761 | /* Message not big enough, just go on. */ |
2738 | goto next_channel; | 2762 | goto next_channel; |
2739 | } | 2763 | } |
2740 | chan = intf->curr_channel; | 2764 | chan = intf->curr_channel; |
2741 | intf->channels[chan].medium = msg->msg.data[2] & 0x7f; | 2765 | intf->channels[chan].medium = msg->msg.data[2] & 0x7f; |
2742 | intf->channels[chan].protocol = msg->msg.data[3] & 0x1f; | 2766 | intf->channels[chan].protocol = msg->msg.data[3] & 0x1f; |
2743 | 2767 | ||
2744 | next_channel: | 2768 | next_channel: |
2745 | intf->curr_channel++; | 2769 | intf->curr_channel++; |
2746 | if (intf->curr_channel >= IPMI_MAX_CHANNELS) | 2770 | if (intf->curr_channel >= IPMI_MAX_CHANNELS) |
2747 | wake_up(&intf->waitq); | 2771 | wake_up(&intf->waitq); |
2748 | else | 2772 | else |
2749 | rv = send_channel_info_cmd(intf, intf->curr_channel); | 2773 | rv = send_channel_info_cmd(intf, intf->curr_channel); |
2750 | 2774 | ||
2751 | if (rv) { | 2775 | if (rv) { |
2752 | /* Got an error somehow, just give up. */ | 2776 | /* Got an error somehow, just give up. */ |
2753 | intf->curr_channel = IPMI_MAX_CHANNELS; | 2777 | intf->curr_channel = IPMI_MAX_CHANNELS; |
2754 | wake_up(&intf->waitq); | 2778 | wake_up(&intf->waitq); |
2755 | 2779 | ||
2756 | printk(KERN_WARNING PFX | 2780 | printk(KERN_WARNING PFX |
2757 | "Error sending channel information: %d\n", | 2781 | "Error sending channel information: %d\n", |
2758 | rv); | 2782 | rv); |
2759 | } | 2783 | } |
2760 | } | 2784 | } |
2761 | out: | 2785 | out: |
2762 | return; | 2786 | return; |
2763 | } | 2787 | } |
2764 | 2788 | ||
2765 | void ipmi_poll_interface(ipmi_user_t user) | 2789 | void ipmi_poll_interface(ipmi_user_t user) |
2766 | { | 2790 | { |
2767 | ipmi_smi_t intf = user->intf; | 2791 | ipmi_smi_t intf = user->intf; |
2768 | 2792 | ||
2769 | if (intf->handlers->poll) | 2793 | if (intf->handlers->poll) |
2770 | intf->handlers->poll(intf->send_info); | 2794 | intf->handlers->poll(intf->send_info); |
2771 | } | 2795 | } |
2772 | EXPORT_SYMBOL(ipmi_poll_interface); | 2796 | EXPORT_SYMBOL(ipmi_poll_interface); |
2773 | 2797 | ||
2774 | int ipmi_register_smi(struct ipmi_smi_handlers *handlers, | 2798 | int ipmi_register_smi(struct ipmi_smi_handlers *handlers, |
2775 | void *send_info, | 2799 | void *send_info, |
2776 | struct ipmi_device_id *device_id, | 2800 | struct ipmi_device_id *device_id, |
2777 | struct device *si_dev, | 2801 | struct device *si_dev, |
2778 | const char *sysfs_name, | 2802 | const char *sysfs_name, |
2779 | unsigned char slave_addr) | 2803 | unsigned char slave_addr) |
2780 | { | 2804 | { |
2781 | int i, j; | 2805 | int i, j; |
2782 | int rv; | 2806 | int rv; |
2783 | ipmi_smi_t intf; | 2807 | ipmi_smi_t intf; |
2784 | ipmi_smi_t tintf; | 2808 | ipmi_smi_t tintf; |
2785 | struct list_head *link; | 2809 | struct list_head *link; |
2786 | 2810 | ||
2787 | /* | 2811 | /* |
2788 | * Make sure the driver is actually initialized, this handles | 2812 | * Make sure the driver is actually initialized, this handles |
2789 | * problems with initialization order. | 2813 | * problems with initialization order. |
2790 | */ | 2814 | */ |
2791 | if (!initialized) { | 2815 | if (!initialized) { |
2792 | rv = ipmi_init_msghandler(); | 2816 | rv = ipmi_init_msghandler(); |
2793 | if (rv) | 2817 | if (rv) |
2794 | return rv; | 2818 | return rv; |
2795 | /* | 2819 | /* |
2796 | * The init code doesn't return an error if it was turned | 2820 | * The init code doesn't return an error if it was turned |
2797 | * off, but it won't initialize. Check that. | 2821 | * off, but it won't initialize. Check that. |
2798 | */ | 2822 | */ |
2799 | if (!initialized) | 2823 | if (!initialized) |
2800 | return -ENODEV; | 2824 | return -ENODEV; |
2801 | } | 2825 | } |
2802 | 2826 | ||
2803 | intf = kzalloc(sizeof(*intf), GFP_KERNEL); | 2827 | intf = kzalloc(sizeof(*intf), GFP_KERNEL); |
2804 | if (!intf) | 2828 | if (!intf) |
2805 | return -ENOMEM; | 2829 | return -ENOMEM; |
2806 | 2830 | ||
2807 | intf->ipmi_version_major = ipmi_version_major(device_id); | 2831 | intf->ipmi_version_major = ipmi_version_major(device_id); |
2808 | intf->ipmi_version_minor = ipmi_version_minor(device_id); | 2832 | intf->ipmi_version_minor = ipmi_version_minor(device_id); |
2809 | 2833 | ||
2810 | intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL); | 2834 | intf->bmc = kzalloc(sizeof(*intf->bmc), GFP_KERNEL); |
2811 | if (!intf->bmc) { | 2835 | if (!intf->bmc) { |
2812 | kfree(intf); | 2836 | kfree(intf); |
2813 | return -ENOMEM; | 2837 | return -ENOMEM; |
2814 | } | 2838 | } |
2815 | intf->intf_num = -1; /* Mark it invalid for now. */ | 2839 | intf->intf_num = -1; /* Mark it invalid for now. */ |
2816 | kref_init(&intf->refcount); | 2840 | kref_init(&intf->refcount); |
2817 | intf->bmc->id = *device_id; | 2841 | intf->bmc->id = *device_id; |
2818 | intf->si_dev = si_dev; | 2842 | intf->si_dev = si_dev; |
2819 | for (j = 0; j < IPMI_MAX_CHANNELS; j++) { | 2843 | for (j = 0; j < IPMI_MAX_CHANNELS; j++) { |
2820 | intf->channels[j].address = IPMI_BMC_SLAVE_ADDR; | 2844 | intf->channels[j].address = IPMI_BMC_SLAVE_ADDR; |
2821 | intf->channels[j].lun = 2; | 2845 | intf->channels[j].lun = 2; |
2822 | } | 2846 | } |
2823 | if (slave_addr != 0) | 2847 | if (slave_addr != 0) |
2824 | intf->channels[0].address = slave_addr; | 2848 | intf->channels[0].address = slave_addr; |
2825 | INIT_LIST_HEAD(&intf->users); | 2849 | INIT_LIST_HEAD(&intf->users); |
2826 | intf->handlers = handlers; | 2850 | intf->handlers = handlers; |
2827 | intf->send_info = send_info; | 2851 | intf->send_info = send_info; |
2828 | spin_lock_init(&intf->seq_lock); | 2852 | spin_lock_init(&intf->seq_lock); |
2829 | for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) { | 2853 | for (j = 0; j < IPMI_IPMB_NUM_SEQ; j++) { |
2830 | intf->seq_table[j].inuse = 0; | 2854 | intf->seq_table[j].inuse = 0; |
2831 | intf->seq_table[j].seqid = 0; | 2855 | intf->seq_table[j].seqid = 0; |
2832 | } | 2856 | } |
2833 | intf->curr_seq = 0; | 2857 | intf->curr_seq = 0; |
2834 | #ifdef CONFIG_PROC_FS | 2858 | #ifdef CONFIG_PROC_FS |
2835 | mutex_init(&intf->proc_entry_lock); | 2859 | mutex_init(&intf->proc_entry_lock); |
2836 | #endif | 2860 | #endif |
2837 | spin_lock_init(&intf->waiting_msgs_lock); | 2861 | spin_lock_init(&intf->waiting_msgs_lock); |
2838 | INIT_LIST_HEAD(&intf->waiting_msgs); | 2862 | INIT_LIST_HEAD(&intf->waiting_msgs); |
2839 | spin_lock_init(&intf->events_lock); | 2863 | spin_lock_init(&intf->events_lock); |
2840 | INIT_LIST_HEAD(&intf->waiting_events); | 2864 | INIT_LIST_HEAD(&intf->waiting_events); |
2841 | intf->waiting_events_count = 0; | 2865 | intf->waiting_events_count = 0; |
2842 | mutex_init(&intf->cmd_rcvrs_mutex); | 2866 | mutex_init(&intf->cmd_rcvrs_mutex); |
2843 | spin_lock_init(&intf->maintenance_mode_lock); | 2867 | spin_lock_init(&intf->maintenance_mode_lock); |
2844 | INIT_LIST_HEAD(&intf->cmd_rcvrs); | 2868 | INIT_LIST_HEAD(&intf->cmd_rcvrs); |
2845 | init_waitqueue_head(&intf->waitq); | 2869 | init_waitqueue_head(&intf->waitq); |
2846 | for (i = 0; i < IPMI_NUM_STATS; i++) | 2870 | for (i = 0; i < IPMI_NUM_STATS; i++) |
2847 | atomic_set(&intf->stats[i], 0); | 2871 | atomic_set(&intf->stats[i], 0); |
2848 | 2872 | ||
2849 | intf->proc_dir = NULL; | 2873 | intf->proc_dir = NULL; |
2850 | 2874 | ||
2851 | mutex_lock(&smi_watchers_mutex); | 2875 | mutex_lock(&smi_watchers_mutex); |
2852 | mutex_lock(&ipmi_interfaces_mutex); | 2876 | mutex_lock(&ipmi_interfaces_mutex); |
2853 | /* Look for a hole in the numbers. */ | 2877 | /* Look for a hole in the numbers. */ |
2854 | i = 0; | 2878 | i = 0; |
2855 | link = &ipmi_interfaces; | 2879 | link = &ipmi_interfaces; |
2856 | list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { | 2880 | list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { |
2857 | if (tintf->intf_num != i) { | 2881 | if (tintf->intf_num != i) { |
2858 | link = &tintf->link; | 2882 | link = &tintf->link; |
2859 | break; | 2883 | break; |
2860 | } | 2884 | } |
2861 | i++; | 2885 | i++; |
2862 | } | 2886 | } |
2863 | /* Add the new interface in numeric order. */ | 2887 | /* Add the new interface in numeric order. */ |
2864 | if (i == 0) | 2888 | if (i == 0) |
2865 | list_add_rcu(&intf->link, &ipmi_interfaces); | 2889 | list_add_rcu(&intf->link, &ipmi_interfaces); |
2866 | else | 2890 | else |
2867 | list_add_tail_rcu(&intf->link, link); | 2891 | list_add_tail_rcu(&intf->link, link); |
2868 | 2892 | ||
2869 | rv = handlers->start_processing(send_info, intf); | 2893 | rv = handlers->start_processing(send_info, intf); |
2870 | if (rv) | 2894 | if (rv) |
2871 | goto out; | 2895 | goto out; |
2872 | 2896 | ||
2873 | get_guid(intf); | 2897 | get_guid(intf); |
2874 | 2898 | ||
2875 | if ((intf->ipmi_version_major > 1) | 2899 | if ((intf->ipmi_version_major > 1) |
2876 | || ((intf->ipmi_version_major == 1) | 2900 | || ((intf->ipmi_version_major == 1) |
2877 | && (intf->ipmi_version_minor >= 5))) { | 2901 | && (intf->ipmi_version_minor >= 5))) { |
2878 | /* | 2902 | /* |
2879 | * Start scanning the channels to see what is | 2903 | * Start scanning the channels to see what is |
2880 | * available. | 2904 | * available. |
2881 | */ | 2905 | */ |
2882 | intf->null_user_handler = channel_handler; | 2906 | intf->null_user_handler = channel_handler; |
2883 | intf->curr_channel = 0; | 2907 | intf->curr_channel = 0; |
2884 | rv = send_channel_info_cmd(intf, 0); | 2908 | rv = send_channel_info_cmd(intf, 0); |
2885 | if (rv) | 2909 | if (rv) |
2886 | goto out; | 2910 | goto out; |
2887 | 2911 | ||
2888 | /* Wait for the channel info to be read. */ | 2912 | /* Wait for the channel info to be read. */ |
2889 | wait_event(intf->waitq, | 2913 | wait_event(intf->waitq, |
2890 | intf->curr_channel >= IPMI_MAX_CHANNELS); | 2914 | intf->curr_channel >= IPMI_MAX_CHANNELS); |
2891 | intf->null_user_handler = NULL; | 2915 | intf->null_user_handler = NULL; |
2892 | } else { | 2916 | } else { |
2893 | /* Assume a single IPMB channel at zero. */ | 2917 | /* Assume a single IPMB channel at zero. */ |
2894 | intf->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB; | 2918 | intf->channels[0].medium = IPMI_CHANNEL_MEDIUM_IPMB; |
2895 | intf->channels[0].protocol = IPMI_CHANNEL_PROTOCOL_IPMB; | 2919 | intf->channels[0].protocol = IPMI_CHANNEL_PROTOCOL_IPMB; |
2896 | intf->curr_channel = IPMI_MAX_CHANNELS; | 2920 | intf->curr_channel = IPMI_MAX_CHANNELS; |
2897 | } | 2921 | } |
2898 | 2922 | ||
2899 | if (rv == 0) | 2923 | if (rv == 0) |
2900 | rv = add_proc_entries(intf, i); | 2924 | rv = add_proc_entries(intf, i); |
2901 | 2925 | ||
2902 | rv = ipmi_bmc_register(intf, i, sysfs_name); | 2926 | rv = ipmi_bmc_register(intf, i, sysfs_name); |
2903 | 2927 | ||
2904 | out: | 2928 | out: |
2905 | if (rv) { | 2929 | if (rv) { |
2906 | if (intf->proc_dir) | 2930 | if (intf->proc_dir) |
2907 | remove_proc_entries(intf); | 2931 | remove_proc_entries(intf); |
2908 | intf->handlers = NULL; | 2932 | intf->handlers = NULL; |
2909 | list_del_rcu(&intf->link); | 2933 | list_del_rcu(&intf->link); |
2910 | mutex_unlock(&ipmi_interfaces_mutex); | 2934 | mutex_unlock(&ipmi_interfaces_mutex); |
2911 | mutex_unlock(&smi_watchers_mutex); | 2935 | mutex_unlock(&smi_watchers_mutex); |
2912 | synchronize_rcu(); | 2936 | synchronize_rcu(); |
2913 | kref_put(&intf->refcount, intf_free); | 2937 | kref_put(&intf->refcount, intf_free); |
2914 | } else { | 2938 | } else { |
2915 | /* | 2939 | /* |
2916 | * Keep memory order straight for RCU readers. Make | 2940 | * Keep memory order straight for RCU readers. Make |
2917 | * sure everything else is committed to memory before | 2941 | * sure everything else is committed to memory before |
2918 | * setting intf_num to mark the interface valid. | 2942 | * setting intf_num to mark the interface valid. |
2919 | */ | 2943 | */ |
2920 | smp_wmb(); | 2944 | smp_wmb(); |
2921 | intf->intf_num = i; | 2945 | intf->intf_num = i; |
2922 | mutex_unlock(&ipmi_interfaces_mutex); | 2946 | mutex_unlock(&ipmi_interfaces_mutex); |
2923 | /* After this point the interface is legal to use. */ | 2947 | /* After this point the interface is legal to use. */ |
2924 | call_smi_watchers(i, intf->si_dev); | 2948 | call_smi_watchers(i, intf->si_dev); |
2925 | mutex_unlock(&smi_watchers_mutex); | 2949 | mutex_unlock(&smi_watchers_mutex); |
2926 | } | 2950 | } |
2927 | 2951 | ||
2928 | return rv; | 2952 | return rv; |
2929 | } | 2953 | } |
2930 | EXPORT_SYMBOL(ipmi_register_smi); | 2954 | EXPORT_SYMBOL(ipmi_register_smi); |
2931 | 2955 | ||
2932 | static void cleanup_smi_msgs(ipmi_smi_t intf) | 2956 | static void cleanup_smi_msgs(ipmi_smi_t intf) |
2933 | { | 2957 | { |
2934 | int i; | 2958 | int i; |
2935 | struct seq_table *ent; | 2959 | struct seq_table *ent; |
2936 | 2960 | ||
2937 | /* No need for locks, the interface is down. */ | 2961 | /* No need for locks, the interface is down. */ |
2938 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { | 2962 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) { |
2939 | ent = &(intf->seq_table[i]); | 2963 | ent = &(intf->seq_table[i]); |
2940 | if (!ent->inuse) | 2964 | if (!ent->inuse) |
2941 | continue; | 2965 | continue; |
2942 | deliver_err_response(ent->recv_msg, IPMI_ERR_UNSPECIFIED); | 2966 | deliver_err_response(ent->recv_msg, IPMI_ERR_UNSPECIFIED); |
2943 | } | 2967 | } |
2944 | } | 2968 | } |
2945 | 2969 | ||
2946 | int ipmi_unregister_smi(ipmi_smi_t intf) | 2970 | int ipmi_unregister_smi(ipmi_smi_t intf) |
2947 | { | 2971 | { |
2948 | struct ipmi_smi_watcher *w; | 2972 | struct ipmi_smi_watcher *w; |
2949 | int intf_num = intf->intf_num; | 2973 | int intf_num = intf->intf_num; |
2950 | 2974 | ||
2951 | ipmi_bmc_unregister(intf); | 2975 | ipmi_bmc_unregister(intf); |
2952 | 2976 | ||
2953 | mutex_lock(&smi_watchers_mutex); | 2977 | mutex_lock(&smi_watchers_mutex); |
2954 | mutex_lock(&ipmi_interfaces_mutex); | 2978 | mutex_lock(&ipmi_interfaces_mutex); |
2955 | intf->intf_num = -1; | 2979 | intf->intf_num = -1; |
2956 | intf->handlers = NULL; | 2980 | intf->handlers = NULL; |
2957 | list_del_rcu(&intf->link); | 2981 | list_del_rcu(&intf->link); |
2958 | mutex_unlock(&ipmi_interfaces_mutex); | 2982 | mutex_unlock(&ipmi_interfaces_mutex); |
2959 | synchronize_rcu(); | 2983 | synchronize_rcu(); |
2960 | 2984 | ||
2961 | cleanup_smi_msgs(intf); | 2985 | cleanup_smi_msgs(intf); |
2962 | 2986 | ||
2963 | remove_proc_entries(intf); | 2987 | remove_proc_entries(intf); |
2964 | 2988 | ||
2965 | /* | 2989 | /* |
2966 | * Call all the watcher interfaces to tell them that | 2990 | * Call all the watcher interfaces to tell them that |
2967 | * an interface is gone. | 2991 | * an interface is gone. |
2968 | */ | 2992 | */ |
2969 | list_for_each_entry(w, &smi_watchers, link) | 2993 | list_for_each_entry(w, &smi_watchers, link) |
2970 | w->smi_gone(intf_num); | 2994 | w->smi_gone(intf_num); |
2971 | mutex_unlock(&smi_watchers_mutex); | 2995 | mutex_unlock(&smi_watchers_mutex); |
2972 | 2996 | ||
2973 | kref_put(&intf->refcount, intf_free); | 2997 | kref_put(&intf->refcount, intf_free); |
2974 | return 0; | 2998 | return 0; |
2975 | } | 2999 | } |
2976 | EXPORT_SYMBOL(ipmi_unregister_smi); | 3000 | EXPORT_SYMBOL(ipmi_unregister_smi); |
2977 | 3001 | ||
2978 | static int handle_ipmb_get_msg_rsp(ipmi_smi_t intf, | 3002 | static int handle_ipmb_get_msg_rsp(ipmi_smi_t intf, |
2979 | struct ipmi_smi_msg *msg) | 3003 | struct ipmi_smi_msg *msg) |
2980 | { | 3004 | { |
2981 | struct ipmi_ipmb_addr ipmb_addr; | 3005 | struct ipmi_ipmb_addr ipmb_addr; |
2982 | struct ipmi_recv_msg *recv_msg; | 3006 | struct ipmi_recv_msg *recv_msg; |
2983 | 3007 | ||
2984 | /* | 3008 | /* |
2985 | * This is 11, not 10, because the response must contain a | 3009 | * This is 11, not 10, because the response must contain a |
2986 | * completion code. | 3010 | * completion code. |
2987 | */ | 3011 | */ |
2988 | if (msg->rsp_size < 11) { | 3012 | if (msg->rsp_size < 11) { |
2989 | /* Message not big enough, just ignore it. */ | 3013 | /* Message not big enough, just ignore it. */ |
2990 | ipmi_inc_stat(intf, invalid_ipmb_responses); | 3014 | ipmi_inc_stat(intf, invalid_ipmb_responses); |
2991 | return 0; | 3015 | return 0; |
2992 | } | 3016 | } |
2993 | 3017 | ||
2994 | if (msg->rsp[2] != 0) { | 3018 | if (msg->rsp[2] != 0) { |
2995 | /* An error getting the response, just ignore it. */ | 3019 | /* An error getting the response, just ignore it. */ |
2996 | return 0; | 3020 | return 0; |
2997 | } | 3021 | } |
2998 | 3022 | ||
2999 | ipmb_addr.addr_type = IPMI_IPMB_ADDR_TYPE; | 3023 | ipmb_addr.addr_type = IPMI_IPMB_ADDR_TYPE; |
3000 | ipmb_addr.slave_addr = msg->rsp[6]; | 3024 | ipmb_addr.slave_addr = msg->rsp[6]; |
3001 | ipmb_addr.channel = msg->rsp[3] & 0x0f; | 3025 | ipmb_addr.channel = msg->rsp[3] & 0x0f; |
3002 | ipmb_addr.lun = msg->rsp[7] & 3; | 3026 | ipmb_addr.lun = msg->rsp[7] & 3; |
3003 | 3027 | ||
3004 | /* | 3028 | /* |
3005 | * It's a response from a remote entity. Look up the sequence | 3029 | * It's a response from a remote entity. Look up the sequence |
3006 | * number and handle the response. | 3030 | * number and handle the response. |
3007 | */ | 3031 | */ |
3008 | if (intf_find_seq(intf, | 3032 | if (intf_find_seq(intf, |
3009 | msg->rsp[7] >> 2, | 3033 | msg->rsp[7] >> 2, |
3010 | msg->rsp[3] & 0x0f, | 3034 | msg->rsp[3] & 0x0f, |
3011 | msg->rsp[8], | 3035 | msg->rsp[8], |
3012 | (msg->rsp[4] >> 2) & (~1), | 3036 | (msg->rsp[4] >> 2) & (~1), |
3013 | (struct ipmi_addr *) &(ipmb_addr), | 3037 | (struct ipmi_addr *) &(ipmb_addr), |
3014 | &recv_msg)) { | 3038 | &recv_msg)) { |
3015 | /* | 3039 | /* |
3016 | * We were unable to find the sequence number, | 3040 | * We were unable to find the sequence number, |
3017 | * so just nuke the message. | 3041 | * so just nuke the message. |
3018 | */ | 3042 | */ |
3019 | ipmi_inc_stat(intf, unhandled_ipmb_responses); | 3043 | ipmi_inc_stat(intf, unhandled_ipmb_responses); |
3020 | return 0; | 3044 | return 0; |
3021 | } | 3045 | } |
3022 | 3046 | ||
3023 | memcpy(recv_msg->msg_data, | 3047 | memcpy(recv_msg->msg_data, |
3024 | &(msg->rsp[9]), | 3048 | &(msg->rsp[9]), |
3025 | msg->rsp_size - 9); | 3049 | msg->rsp_size - 9); |
3026 | /* | 3050 | /* |
3027 | * The other fields matched, so no need to set them, except | 3051 | * The other fields matched, so no need to set them, except |
3028 | * for netfn, which needs to be the response that was | 3052 | * for netfn, which needs to be the response that was |
3029 | * returned, not the request value. | 3053 | * returned, not the request value. |
3030 | */ | 3054 | */ |
3031 | recv_msg->msg.netfn = msg->rsp[4] >> 2; | 3055 | recv_msg->msg.netfn = msg->rsp[4] >> 2; |
3032 | recv_msg->msg.data = recv_msg->msg_data; | 3056 | recv_msg->msg.data = recv_msg->msg_data; |
3033 | recv_msg->msg.data_len = msg->rsp_size - 10; | 3057 | recv_msg->msg.data_len = msg->rsp_size - 10; |
3034 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; | 3058 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
3035 | ipmi_inc_stat(intf, handled_ipmb_responses); | 3059 | ipmi_inc_stat(intf, handled_ipmb_responses); |
3036 | deliver_response(recv_msg); | 3060 | deliver_response(recv_msg); |
3037 | 3061 | ||
3038 | return 0; | 3062 | return 0; |
3039 | } | 3063 | } |
3040 | 3064 | ||
3041 | static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf, | 3065 | static int handle_ipmb_get_msg_cmd(ipmi_smi_t intf, |
3042 | struct ipmi_smi_msg *msg) | 3066 | struct ipmi_smi_msg *msg) |
3043 | { | 3067 | { |
3044 | struct cmd_rcvr *rcvr; | 3068 | struct cmd_rcvr *rcvr; |
3045 | int rv = 0; | 3069 | int rv = 0; |
3046 | unsigned char netfn; | 3070 | unsigned char netfn; |
3047 | unsigned char cmd; | 3071 | unsigned char cmd; |
3048 | unsigned char chan; | 3072 | unsigned char chan; |
3049 | ipmi_user_t user = NULL; | 3073 | ipmi_user_t user = NULL; |
3050 | struct ipmi_ipmb_addr *ipmb_addr; | 3074 | struct ipmi_ipmb_addr *ipmb_addr; |
3051 | struct ipmi_recv_msg *recv_msg; | 3075 | struct ipmi_recv_msg *recv_msg; |
3052 | struct ipmi_smi_handlers *handlers; | 3076 | struct ipmi_smi_handlers *handlers; |
3053 | 3077 | ||
3054 | if (msg->rsp_size < 10) { | 3078 | if (msg->rsp_size < 10) { |
3055 | /* Message not big enough, just ignore it. */ | 3079 | /* Message not big enough, just ignore it. */ |
3056 | ipmi_inc_stat(intf, invalid_commands); | 3080 | ipmi_inc_stat(intf, invalid_commands); |
3057 | return 0; | 3081 | return 0; |
3058 | } | 3082 | } |
3059 | 3083 | ||
3060 | if (msg->rsp[2] != 0) { | 3084 | if (msg->rsp[2] != 0) { |
3061 | /* An error getting the response, just ignore it. */ | 3085 | /* An error getting the response, just ignore it. */ |
3062 | return 0; | 3086 | return 0; |
3063 | } | 3087 | } |
3064 | 3088 | ||
3065 | netfn = msg->rsp[4] >> 2; | 3089 | netfn = msg->rsp[4] >> 2; |
3066 | cmd = msg->rsp[8]; | 3090 | cmd = msg->rsp[8]; |
3067 | chan = msg->rsp[3] & 0xf; | 3091 | chan = msg->rsp[3] & 0xf; |
3068 | 3092 | ||
3069 | rcu_read_lock(); | 3093 | rcu_read_lock(); |
3070 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); | 3094 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); |
3071 | if (rcvr) { | 3095 | if (rcvr) { |
3072 | user = rcvr->user; | 3096 | user = rcvr->user; |
3073 | kref_get(&user->refcount); | 3097 | kref_get(&user->refcount); |
3074 | } else | 3098 | } else |
3075 | user = NULL; | 3099 | user = NULL; |
3076 | rcu_read_unlock(); | 3100 | rcu_read_unlock(); |
3077 | 3101 | ||
3078 | if (user == NULL) { | 3102 | if (user == NULL) { |
3079 | /* We didn't find a user, deliver an error response. */ | 3103 | /* We didn't find a user, deliver an error response. */ |
3080 | ipmi_inc_stat(intf, unhandled_commands); | 3104 | ipmi_inc_stat(intf, unhandled_commands); |
3081 | 3105 | ||
3082 | msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); | 3106 | msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
3083 | msg->data[1] = IPMI_SEND_MSG_CMD; | 3107 | msg->data[1] = IPMI_SEND_MSG_CMD; |
3084 | msg->data[2] = msg->rsp[3]; | 3108 | msg->data[2] = msg->rsp[3]; |
3085 | msg->data[3] = msg->rsp[6]; | 3109 | msg->data[3] = msg->rsp[6]; |
3086 | msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3); | 3110 | msg->data[4] = ((netfn + 1) << 2) | (msg->rsp[7] & 0x3); |
3087 | msg->data[5] = ipmb_checksum(&(msg->data[3]), 2); | 3111 | msg->data[5] = ipmb_checksum(&(msg->data[3]), 2); |
3088 | msg->data[6] = intf->channels[msg->rsp[3] & 0xf].address; | 3112 | msg->data[6] = intf->channels[msg->rsp[3] & 0xf].address; |
3089 | /* rqseq/lun */ | 3113 | /* rqseq/lun */ |
3090 | msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3); | 3114 | msg->data[7] = (msg->rsp[7] & 0xfc) | (msg->rsp[4] & 0x3); |
3091 | msg->data[8] = msg->rsp[8]; /* cmd */ | 3115 | msg->data[8] = msg->rsp[8]; /* cmd */ |
3092 | msg->data[9] = IPMI_INVALID_CMD_COMPLETION_CODE; | 3116 | msg->data[9] = IPMI_INVALID_CMD_COMPLETION_CODE; |
3093 | msg->data[10] = ipmb_checksum(&(msg->data[6]), 4); | 3117 | msg->data[10] = ipmb_checksum(&(msg->data[6]), 4); |
3094 | msg->data_size = 11; | 3118 | msg->data_size = 11; |
3095 | 3119 | ||
3096 | #ifdef DEBUG_MSGING | 3120 | #ifdef DEBUG_MSGING |
3097 | { | 3121 | { |
3098 | int m; | 3122 | int m; |
3099 | printk("Invalid command:"); | 3123 | printk("Invalid command:"); |
3100 | for (m = 0; m < msg->data_size; m++) | 3124 | for (m = 0; m < msg->data_size; m++) |
3101 | printk(" %2.2x", msg->data[m]); | 3125 | printk(" %2.2x", msg->data[m]); |
3102 | printk("\n"); | 3126 | printk("\n"); |
3103 | } | 3127 | } |
3104 | #endif | 3128 | #endif |
3105 | rcu_read_lock(); | 3129 | rcu_read_lock(); |
3106 | handlers = intf->handlers; | 3130 | handlers = intf->handlers; |
3107 | if (handlers) { | 3131 | if (handlers) { |
3108 | handlers->sender(intf->send_info, msg, 0); | 3132 | handlers->sender(intf->send_info, msg, 0); |
3109 | /* | 3133 | /* |
3110 | * We used the message, so return the value | 3134 | * We used the message, so return the value |
3111 | * that causes it to not be freed or | 3135 | * that causes it to not be freed or |
3112 | * queued. | 3136 | * queued. |
3113 | */ | 3137 | */ |
3114 | rv = -1; | 3138 | rv = -1; |
3115 | } | 3139 | } |
3116 | rcu_read_unlock(); | 3140 | rcu_read_unlock(); |
3117 | } else { | 3141 | } else { |
3118 | /* Deliver the message to the user. */ | 3142 | /* Deliver the message to the user. */ |
3119 | ipmi_inc_stat(intf, handled_commands); | 3143 | ipmi_inc_stat(intf, handled_commands); |
3120 | 3144 | ||
3121 | recv_msg = ipmi_alloc_recv_msg(); | 3145 | recv_msg = ipmi_alloc_recv_msg(); |
3122 | if (!recv_msg) { | 3146 | if (!recv_msg) { |
3123 | /* | 3147 | /* |
3124 | * We couldn't allocate memory for the | 3148 | * We couldn't allocate memory for the |
3125 | * message, so requeue it for handling | 3149 | * message, so requeue it for handling |
3126 | * later. | 3150 | * later. |
3127 | */ | 3151 | */ |
3128 | rv = 1; | 3152 | rv = 1; |
3129 | kref_put(&user->refcount, free_user); | 3153 | kref_put(&user->refcount, free_user); |
3130 | } else { | 3154 | } else { |
3131 | /* Extract the source address from the data. */ | 3155 | /* Extract the source address from the data. */ |
3132 | ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr; | 3156 | ipmb_addr = (struct ipmi_ipmb_addr *) &recv_msg->addr; |
3133 | ipmb_addr->addr_type = IPMI_IPMB_ADDR_TYPE; | 3157 | ipmb_addr->addr_type = IPMI_IPMB_ADDR_TYPE; |
3134 | ipmb_addr->slave_addr = msg->rsp[6]; | 3158 | ipmb_addr->slave_addr = msg->rsp[6]; |
3135 | ipmb_addr->lun = msg->rsp[7] & 3; | 3159 | ipmb_addr->lun = msg->rsp[7] & 3; |
3136 | ipmb_addr->channel = msg->rsp[3] & 0xf; | 3160 | ipmb_addr->channel = msg->rsp[3] & 0xf; |
3137 | 3161 | ||
3138 | /* | 3162 | /* |
3139 | * Extract the rest of the message information | 3163 | * Extract the rest of the message information |
3140 | * from the IPMB header. | 3164 | * from the IPMB header. |
3141 | */ | 3165 | */ |
3142 | recv_msg->user = user; | 3166 | recv_msg->user = user; |
3143 | recv_msg->recv_type = IPMI_CMD_RECV_TYPE; | 3167 | recv_msg->recv_type = IPMI_CMD_RECV_TYPE; |
3144 | recv_msg->msgid = msg->rsp[7] >> 2; | 3168 | recv_msg->msgid = msg->rsp[7] >> 2; |
3145 | recv_msg->msg.netfn = msg->rsp[4] >> 2; | 3169 | recv_msg->msg.netfn = msg->rsp[4] >> 2; |
3146 | recv_msg->msg.cmd = msg->rsp[8]; | 3170 | recv_msg->msg.cmd = msg->rsp[8]; |
3147 | recv_msg->msg.data = recv_msg->msg_data; | 3171 | recv_msg->msg.data = recv_msg->msg_data; |
3148 | 3172 | ||
3149 | /* | 3173 | /* |
3150 | * We chop off 10, not 9 bytes because the checksum | 3174 | * We chop off 10, not 9 bytes because the checksum |
3151 | * at the end also needs to be removed. | 3175 | * at the end also needs to be removed. |
3152 | */ | 3176 | */ |
3153 | recv_msg->msg.data_len = msg->rsp_size - 10; | 3177 | recv_msg->msg.data_len = msg->rsp_size - 10; |
3154 | memcpy(recv_msg->msg_data, | 3178 | memcpy(recv_msg->msg_data, |
3155 | &(msg->rsp[9]), | 3179 | &(msg->rsp[9]), |
3156 | msg->rsp_size - 10); | 3180 | msg->rsp_size - 10); |
3157 | deliver_response(recv_msg); | 3181 | deliver_response(recv_msg); |
3158 | } | 3182 | } |
3159 | } | 3183 | } |
3160 | 3184 | ||
3161 | return rv; | 3185 | return rv; |
3162 | } | 3186 | } |
3163 | 3187 | ||
3164 | static int handle_lan_get_msg_rsp(ipmi_smi_t intf, | 3188 | static int handle_lan_get_msg_rsp(ipmi_smi_t intf, |
3165 | struct ipmi_smi_msg *msg) | 3189 | struct ipmi_smi_msg *msg) |
3166 | { | 3190 | { |
3167 | struct ipmi_lan_addr lan_addr; | 3191 | struct ipmi_lan_addr lan_addr; |
3168 | struct ipmi_recv_msg *recv_msg; | 3192 | struct ipmi_recv_msg *recv_msg; |
3169 | 3193 | ||
3170 | 3194 | ||
3171 | /* | 3195 | /* |
3172 | * This is 13, not 12, because the response must contain a | 3196 | * This is 13, not 12, because the response must contain a |
3173 | * completion code. | 3197 | * completion code. |
3174 | */ | 3198 | */ |
3175 | if (msg->rsp_size < 13) { | 3199 | if (msg->rsp_size < 13) { |
3176 | /* Message not big enough, just ignore it. */ | 3200 | /* Message not big enough, just ignore it. */ |
3177 | ipmi_inc_stat(intf, invalid_lan_responses); | 3201 | ipmi_inc_stat(intf, invalid_lan_responses); |
3178 | return 0; | 3202 | return 0; |
3179 | } | 3203 | } |
3180 | 3204 | ||
3181 | if (msg->rsp[2] != 0) { | 3205 | if (msg->rsp[2] != 0) { |
3182 | /* An error getting the response, just ignore it. */ | 3206 | /* An error getting the response, just ignore it. */ |
3183 | return 0; | 3207 | return 0; |
3184 | } | 3208 | } |
3185 | 3209 | ||
3186 | lan_addr.addr_type = IPMI_LAN_ADDR_TYPE; | 3210 | lan_addr.addr_type = IPMI_LAN_ADDR_TYPE; |
3187 | lan_addr.session_handle = msg->rsp[4]; | 3211 | lan_addr.session_handle = msg->rsp[4]; |
3188 | lan_addr.remote_SWID = msg->rsp[8]; | 3212 | lan_addr.remote_SWID = msg->rsp[8]; |
3189 | lan_addr.local_SWID = msg->rsp[5]; | 3213 | lan_addr.local_SWID = msg->rsp[5]; |
3190 | lan_addr.channel = msg->rsp[3] & 0x0f; | 3214 | lan_addr.channel = msg->rsp[3] & 0x0f; |
3191 | lan_addr.privilege = msg->rsp[3] >> 4; | 3215 | lan_addr.privilege = msg->rsp[3] >> 4; |
3192 | lan_addr.lun = msg->rsp[9] & 3; | 3216 | lan_addr.lun = msg->rsp[9] & 3; |
3193 | 3217 | ||
3194 | /* | 3218 | /* |
3195 | * It's a response from a remote entity. Look up the sequence | 3219 | * It's a response from a remote entity. Look up the sequence |
3196 | * number and handle the response. | 3220 | * number and handle the response. |
3197 | */ | 3221 | */ |
3198 | if (intf_find_seq(intf, | 3222 | if (intf_find_seq(intf, |
3199 | msg->rsp[9] >> 2, | 3223 | msg->rsp[9] >> 2, |
3200 | msg->rsp[3] & 0x0f, | 3224 | msg->rsp[3] & 0x0f, |
3201 | msg->rsp[10], | 3225 | msg->rsp[10], |
3202 | (msg->rsp[6] >> 2) & (~1), | 3226 | (msg->rsp[6] >> 2) & (~1), |
3203 | (struct ipmi_addr *) &(lan_addr), | 3227 | (struct ipmi_addr *) &(lan_addr), |
3204 | &recv_msg)) { | 3228 | &recv_msg)) { |
3205 | /* | 3229 | /* |
3206 | * We were unable to find the sequence number, | 3230 | * We were unable to find the sequence number, |
3207 | * so just nuke the message. | 3231 | * so just nuke the message. |
3208 | */ | 3232 | */ |
3209 | ipmi_inc_stat(intf, unhandled_lan_responses); | 3233 | ipmi_inc_stat(intf, unhandled_lan_responses); |
3210 | return 0; | 3234 | return 0; |
3211 | } | 3235 | } |
3212 | 3236 | ||
3213 | memcpy(recv_msg->msg_data, | 3237 | memcpy(recv_msg->msg_data, |
3214 | &(msg->rsp[11]), | 3238 | &(msg->rsp[11]), |
3215 | msg->rsp_size - 11); | 3239 | msg->rsp_size - 11); |
3216 | /* | 3240 | /* |
3217 | * The other fields matched, so no need to set them, except | 3241 | * The other fields matched, so no need to set them, except |
3218 | * for netfn, which needs to be the response that was | 3242 | * for netfn, which needs to be the response that was |
3219 | * returned, not the request value. | 3243 | * returned, not the request value. |
3220 | */ | 3244 | */ |
3221 | recv_msg->msg.netfn = msg->rsp[6] >> 2; | 3245 | recv_msg->msg.netfn = msg->rsp[6] >> 2; |
3222 | recv_msg->msg.data = recv_msg->msg_data; | 3246 | recv_msg->msg.data = recv_msg->msg_data; |
3223 | recv_msg->msg.data_len = msg->rsp_size - 12; | 3247 | recv_msg->msg.data_len = msg->rsp_size - 12; |
3224 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; | 3248 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
3225 | ipmi_inc_stat(intf, handled_lan_responses); | 3249 | ipmi_inc_stat(intf, handled_lan_responses); |
3226 | deliver_response(recv_msg); | 3250 | deliver_response(recv_msg); |
3227 | 3251 | ||
3228 | return 0; | 3252 | return 0; |
3229 | } | 3253 | } |
3230 | 3254 | ||
3231 | static int handle_lan_get_msg_cmd(ipmi_smi_t intf, | 3255 | static int handle_lan_get_msg_cmd(ipmi_smi_t intf, |
3232 | struct ipmi_smi_msg *msg) | 3256 | struct ipmi_smi_msg *msg) |
3233 | { | 3257 | { |
3234 | struct cmd_rcvr *rcvr; | 3258 | struct cmd_rcvr *rcvr; |
3235 | int rv = 0; | 3259 | int rv = 0; |
3236 | unsigned char netfn; | 3260 | unsigned char netfn; |
3237 | unsigned char cmd; | 3261 | unsigned char cmd; |
3238 | unsigned char chan; | 3262 | unsigned char chan; |
3239 | ipmi_user_t user = NULL; | 3263 | ipmi_user_t user = NULL; |
3240 | struct ipmi_lan_addr *lan_addr; | 3264 | struct ipmi_lan_addr *lan_addr; |
3241 | struct ipmi_recv_msg *recv_msg; | 3265 | struct ipmi_recv_msg *recv_msg; |
3242 | 3266 | ||
3243 | if (msg->rsp_size < 12) { | 3267 | if (msg->rsp_size < 12) { |
3244 | /* Message not big enough, just ignore it. */ | 3268 | /* Message not big enough, just ignore it. */ |
3245 | ipmi_inc_stat(intf, invalid_commands); | 3269 | ipmi_inc_stat(intf, invalid_commands); |
3246 | return 0; | 3270 | return 0; |
3247 | } | 3271 | } |
3248 | 3272 | ||
3249 | if (msg->rsp[2] != 0) { | 3273 | if (msg->rsp[2] != 0) { |
3250 | /* An error getting the response, just ignore it. */ | 3274 | /* An error getting the response, just ignore it. */ |
3251 | return 0; | 3275 | return 0; |
3252 | } | 3276 | } |
3253 | 3277 | ||
3254 | netfn = msg->rsp[6] >> 2; | 3278 | netfn = msg->rsp[6] >> 2; |
3255 | cmd = msg->rsp[10]; | 3279 | cmd = msg->rsp[10]; |
3256 | chan = msg->rsp[3] & 0xf; | 3280 | chan = msg->rsp[3] & 0xf; |
3257 | 3281 | ||
3258 | rcu_read_lock(); | 3282 | rcu_read_lock(); |
3259 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); | 3283 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); |
3260 | if (rcvr) { | 3284 | if (rcvr) { |
3261 | user = rcvr->user; | 3285 | user = rcvr->user; |
3262 | kref_get(&user->refcount); | 3286 | kref_get(&user->refcount); |
3263 | } else | 3287 | } else |
3264 | user = NULL; | 3288 | user = NULL; |
3265 | rcu_read_unlock(); | 3289 | rcu_read_unlock(); |
3266 | 3290 | ||
3267 | if (user == NULL) { | 3291 | if (user == NULL) { |
3268 | /* We didn't find a user, just give up. */ | 3292 | /* We didn't find a user, just give up. */ |
3269 | ipmi_inc_stat(intf, unhandled_commands); | 3293 | ipmi_inc_stat(intf, unhandled_commands); |
3270 | 3294 | ||
3271 | /* | 3295 | /* |
3272 | * Don't do anything with these messages, just allow | 3296 | * Don't do anything with these messages, just allow |
3273 | * them to be freed. | 3297 | * them to be freed. |
3274 | */ | 3298 | */ |
3275 | rv = 0; | 3299 | rv = 0; |
3276 | } else { | 3300 | } else { |
3277 | /* Deliver the message to the user. */ | 3301 | /* Deliver the message to the user. */ |
3278 | ipmi_inc_stat(intf, handled_commands); | 3302 | ipmi_inc_stat(intf, handled_commands); |
3279 | 3303 | ||
3280 | recv_msg = ipmi_alloc_recv_msg(); | 3304 | recv_msg = ipmi_alloc_recv_msg(); |
3281 | if (!recv_msg) { | 3305 | if (!recv_msg) { |
3282 | /* | 3306 | /* |
3283 | * We couldn't allocate memory for the | 3307 | * We couldn't allocate memory for the |
3284 | * message, so requeue it for handling later. | 3308 | * message, so requeue it for handling later. |
3285 | */ | 3309 | */ |
3286 | rv = 1; | 3310 | rv = 1; |
3287 | kref_put(&user->refcount, free_user); | 3311 | kref_put(&user->refcount, free_user); |
3288 | } else { | 3312 | } else { |
3289 | /* Extract the source address from the data. */ | 3313 | /* Extract the source address from the data. */ |
3290 | lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr; | 3314 | lan_addr = (struct ipmi_lan_addr *) &recv_msg->addr; |
3291 | lan_addr->addr_type = IPMI_LAN_ADDR_TYPE; | 3315 | lan_addr->addr_type = IPMI_LAN_ADDR_TYPE; |
3292 | lan_addr->session_handle = msg->rsp[4]; | 3316 | lan_addr->session_handle = msg->rsp[4]; |
3293 | lan_addr->remote_SWID = msg->rsp[8]; | 3317 | lan_addr->remote_SWID = msg->rsp[8]; |
3294 | lan_addr->local_SWID = msg->rsp[5]; | 3318 | lan_addr->local_SWID = msg->rsp[5]; |
3295 | lan_addr->lun = msg->rsp[9] & 3; | 3319 | lan_addr->lun = msg->rsp[9] & 3; |
3296 | lan_addr->channel = msg->rsp[3] & 0xf; | 3320 | lan_addr->channel = msg->rsp[3] & 0xf; |
3297 | lan_addr->privilege = msg->rsp[3] >> 4; | 3321 | lan_addr->privilege = msg->rsp[3] >> 4; |
3298 | 3322 | ||
3299 | /* | 3323 | /* |
3300 | * Extract the rest of the message information | 3324 | * Extract the rest of the message information |
3301 | * from the IPMB header. | 3325 | * from the IPMB header. |
3302 | */ | 3326 | */ |
3303 | recv_msg->user = user; | 3327 | recv_msg->user = user; |
3304 | recv_msg->recv_type = IPMI_CMD_RECV_TYPE; | 3328 | recv_msg->recv_type = IPMI_CMD_RECV_TYPE; |
3305 | recv_msg->msgid = msg->rsp[9] >> 2; | 3329 | recv_msg->msgid = msg->rsp[9] >> 2; |
3306 | recv_msg->msg.netfn = msg->rsp[6] >> 2; | 3330 | recv_msg->msg.netfn = msg->rsp[6] >> 2; |
3307 | recv_msg->msg.cmd = msg->rsp[10]; | 3331 | recv_msg->msg.cmd = msg->rsp[10]; |
3308 | recv_msg->msg.data = recv_msg->msg_data; | 3332 | recv_msg->msg.data = recv_msg->msg_data; |
3309 | 3333 | ||
3310 | /* | 3334 | /* |
3311 | * We chop off 12, not 11 bytes because the checksum | 3335 | * We chop off 12, not 11 bytes because the checksum |
3312 | * at the end also needs to be removed. | 3336 | * at the end also needs to be removed. |
3313 | */ | 3337 | */ |
3314 | recv_msg->msg.data_len = msg->rsp_size - 12; | 3338 | recv_msg->msg.data_len = msg->rsp_size - 12; |
3315 | memcpy(recv_msg->msg_data, | 3339 | memcpy(recv_msg->msg_data, |
3316 | &(msg->rsp[11]), | 3340 | &(msg->rsp[11]), |
3317 | msg->rsp_size - 12); | 3341 | msg->rsp_size - 12); |
3318 | deliver_response(recv_msg); | 3342 | deliver_response(recv_msg); |
3319 | } | 3343 | } |
3320 | } | 3344 | } |
3321 | 3345 | ||
3322 | return rv; | 3346 | return rv; |
3323 | } | 3347 | } |
3324 | 3348 | ||
3325 | /* | 3349 | /* |
3326 | * This routine will handle "Get Message" command responses with | 3350 | * This routine will handle "Get Message" command responses with |
3327 | * channels that use an OEM Medium. The message format belongs to | 3351 | * channels that use an OEM Medium. The message format belongs to |
3328 | * the OEM. See IPMI 2.0 specification, Chapter 6 and | 3352 | * the OEM. See IPMI 2.0 specification, Chapter 6 and |
3329 | * Chapter 22, sections 22.6 and 22.24 for more details. | 3353 | * Chapter 22, sections 22.6 and 22.24 for more details. |
3330 | */ | 3354 | */ |
3331 | static int handle_oem_get_msg_cmd(ipmi_smi_t intf, | 3355 | static int handle_oem_get_msg_cmd(ipmi_smi_t intf, |
3332 | struct ipmi_smi_msg *msg) | 3356 | struct ipmi_smi_msg *msg) |
3333 | { | 3357 | { |
3334 | struct cmd_rcvr *rcvr; | 3358 | struct cmd_rcvr *rcvr; |
3335 | int rv = 0; | 3359 | int rv = 0; |
3336 | unsigned char netfn; | 3360 | unsigned char netfn; |
3337 | unsigned char cmd; | 3361 | unsigned char cmd; |
3338 | unsigned char chan; | 3362 | unsigned char chan; |
3339 | ipmi_user_t user = NULL; | 3363 | ipmi_user_t user = NULL; |
3340 | struct ipmi_system_interface_addr *smi_addr; | 3364 | struct ipmi_system_interface_addr *smi_addr; |
3341 | struct ipmi_recv_msg *recv_msg; | 3365 | struct ipmi_recv_msg *recv_msg; |
3342 | 3366 | ||
3343 | /* | 3367 | /* |
3344 | * We expect the OEM SW to perform error checking | 3368 | * We expect the OEM SW to perform error checking |
3345 | * so we just do some basic sanity checks | 3369 | * so we just do some basic sanity checks |
3346 | */ | 3370 | */ |
3347 | if (msg->rsp_size < 4) { | 3371 | if (msg->rsp_size < 4) { |
3348 | /* Message not big enough, just ignore it. */ | 3372 | /* Message not big enough, just ignore it. */ |
3349 | ipmi_inc_stat(intf, invalid_commands); | 3373 | ipmi_inc_stat(intf, invalid_commands); |
3350 | return 0; | 3374 | return 0; |
3351 | } | 3375 | } |
3352 | 3376 | ||
3353 | if (msg->rsp[2] != 0) { | 3377 | if (msg->rsp[2] != 0) { |
3354 | /* An error getting the response, just ignore it. */ | 3378 | /* An error getting the response, just ignore it. */ |
3355 | return 0; | 3379 | return 0; |
3356 | } | 3380 | } |
3357 | 3381 | ||
3358 | /* | 3382 | /* |
3359 | * This is an OEM Message so the OEM needs to know how | 3383 | * This is an OEM Message so the OEM needs to know how |
3360 | * handle the message. We do no interpretation. | 3384 | * handle the message. We do no interpretation. |
3361 | */ | 3385 | */ |
3362 | netfn = msg->rsp[0] >> 2; | 3386 | netfn = msg->rsp[0] >> 2; |
3363 | cmd = msg->rsp[1]; | 3387 | cmd = msg->rsp[1]; |
3364 | chan = msg->rsp[3] & 0xf; | 3388 | chan = msg->rsp[3] & 0xf; |
3365 | 3389 | ||
3366 | rcu_read_lock(); | 3390 | rcu_read_lock(); |
3367 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); | 3391 | rcvr = find_cmd_rcvr(intf, netfn, cmd, chan); |
3368 | if (rcvr) { | 3392 | if (rcvr) { |
3369 | user = rcvr->user; | 3393 | user = rcvr->user; |
3370 | kref_get(&user->refcount); | 3394 | kref_get(&user->refcount); |
3371 | } else | 3395 | } else |
3372 | user = NULL; | 3396 | user = NULL; |
3373 | rcu_read_unlock(); | 3397 | rcu_read_unlock(); |
3374 | 3398 | ||
3375 | if (user == NULL) { | 3399 | if (user == NULL) { |
3376 | /* We didn't find a user, just give up. */ | 3400 | /* We didn't find a user, just give up. */ |
3377 | ipmi_inc_stat(intf, unhandled_commands); | 3401 | ipmi_inc_stat(intf, unhandled_commands); |
3378 | 3402 | ||
3379 | /* | 3403 | /* |
3380 | * Don't do anything with these messages, just allow | 3404 | * Don't do anything with these messages, just allow |
3381 | * them to be freed. | 3405 | * them to be freed. |
3382 | */ | 3406 | */ |
3383 | 3407 | ||
3384 | rv = 0; | 3408 | rv = 0; |
3385 | } else { | 3409 | } else { |
3386 | /* Deliver the message to the user. */ | 3410 | /* Deliver the message to the user. */ |
3387 | ipmi_inc_stat(intf, handled_commands); | 3411 | ipmi_inc_stat(intf, handled_commands); |
3388 | 3412 | ||
3389 | recv_msg = ipmi_alloc_recv_msg(); | 3413 | recv_msg = ipmi_alloc_recv_msg(); |
3390 | if (!recv_msg) { | 3414 | if (!recv_msg) { |
3391 | /* | 3415 | /* |
3392 | * We couldn't allocate memory for the | 3416 | * We couldn't allocate memory for the |
3393 | * message, so requeue it for handling | 3417 | * message, so requeue it for handling |
3394 | * later. | 3418 | * later. |
3395 | */ | 3419 | */ |
3396 | rv = 1; | 3420 | rv = 1; |
3397 | kref_put(&user->refcount, free_user); | 3421 | kref_put(&user->refcount, free_user); |
3398 | } else { | 3422 | } else { |
3399 | /* | 3423 | /* |
3400 | * OEM Messages are expected to be delivered via | 3424 | * OEM Messages are expected to be delivered via |
3401 | * the system interface to SMS software. We might | 3425 | * the system interface to SMS software. We might |
3402 | * need to visit this again depending on OEM | 3426 | * need to visit this again depending on OEM |
3403 | * requirements | 3427 | * requirements |
3404 | */ | 3428 | */ |
3405 | smi_addr = ((struct ipmi_system_interface_addr *) | 3429 | smi_addr = ((struct ipmi_system_interface_addr *) |
3406 | &(recv_msg->addr)); | 3430 | &(recv_msg->addr)); |
3407 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | 3431 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
3408 | smi_addr->channel = IPMI_BMC_CHANNEL; | 3432 | smi_addr->channel = IPMI_BMC_CHANNEL; |
3409 | smi_addr->lun = msg->rsp[0] & 3; | 3433 | smi_addr->lun = msg->rsp[0] & 3; |
3410 | 3434 | ||
3411 | recv_msg->user = user; | 3435 | recv_msg->user = user; |
3412 | recv_msg->user_msg_data = NULL; | 3436 | recv_msg->user_msg_data = NULL; |
3413 | recv_msg->recv_type = IPMI_OEM_RECV_TYPE; | 3437 | recv_msg->recv_type = IPMI_OEM_RECV_TYPE; |
3414 | recv_msg->msg.netfn = msg->rsp[0] >> 2; | 3438 | recv_msg->msg.netfn = msg->rsp[0] >> 2; |
3415 | recv_msg->msg.cmd = msg->rsp[1]; | 3439 | recv_msg->msg.cmd = msg->rsp[1]; |
3416 | recv_msg->msg.data = recv_msg->msg_data; | 3440 | recv_msg->msg.data = recv_msg->msg_data; |
3417 | 3441 | ||
3418 | /* | 3442 | /* |
3419 | * The message starts at byte 4 which follows the | 3443 | * The message starts at byte 4 which follows the |
3420 | * the Channel Byte in the "GET MESSAGE" command | 3444 | * the Channel Byte in the "GET MESSAGE" command |
3421 | */ | 3445 | */ |
3422 | recv_msg->msg.data_len = msg->rsp_size - 4; | 3446 | recv_msg->msg.data_len = msg->rsp_size - 4; |
3423 | memcpy(recv_msg->msg_data, | 3447 | memcpy(recv_msg->msg_data, |
3424 | &(msg->rsp[4]), | 3448 | &(msg->rsp[4]), |
3425 | msg->rsp_size - 4); | 3449 | msg->rsp_size - 4); |
3426 | deliver_response(recv_msg); | 3450 | deliver_response(recv_msg); |
3427 | } | 3451 | } |
3428 | } | 3452 | } |
3429 | 3453 | ||
3430 | return rv; | 3454 | return rv; |
3431 | } | 3455 | } |
3432 | 3456 | ||
3433 | static void copy_event_into_recv_msg(struct ipmi_recv_msg *recv_msg, | 3457 | static void copy_event_into_recv_msg(struct ipmi_recv_msg *recv_msg, |
3434 | struct ipmi_smi_msg *msg) | 3458 | struct ipmi_smi_msg *msg) |
3435 | { | 3459 | { |
3436 | struct ipmi_system_interface_addr *smi_addr; | 3460 | struct ipmi_system_interface_addr *smi_addr; |
3437 | 3461 | ||
3438 | recv_msg->msgid = 0; | 3462 | recv_msg->msgid = 0; |
3439 | smi_addr = (struct ipmi_system_interface_addr *) &(recv_msg->addr); | 3463 | smi_addr = (struct ipmi_system_interface_addr *) &(recv_msg->addr); |
3440 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | 3464 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
3441 | smi_addr->channel = IPMI_BMC_CHANNEL; | 3465 | smi_addr->channel = IPMI_BMC_CHANNEL; |
3442 | smi_addr->lun = msg->rsp[0] & 3; | 3466 | smi_addr->lun = msg->rsp[0] & 3; |
3443 | recv_msg->recv_type = IPMI_ASYNC_EVENT_RECV_TYPE; | 3467 | recv_msg->recv_type = IPMI_ASYNC_EVENT_RECV_TYPE; |
3444 | recv_msg->msg.netfn = msg->rsp[0] >> 2; | 3468 | recv_msg->msg.netfn = msg->rsp[0] >> 2; |
3445 | recv_msg->msg.cmd = msg->rsp[1]; | 3469 | recv_msg->msg.cmd = msg->rsp[1]; |
3446 | memcpy(recv_msg->msg_data, &(msg->rsp[3]), msg->rsp_size - 3); | 3470 | memcpy(recv_msg->msg_data, &(msg->rsp[3]), msg->rsp_size - 3); |
3447 | recv_msg->msg.data = recv_msg->msg_data; | 3471 | recv_msg->msg.data = recv_msg->msg_data; |
3448 | recv_msg->msg.data_len = msg->rsp_size - 3; | 3472 | recv_msg->msg.data_len = msg->rsp_size - 3; |
3449 | } | 3473 | } |
3450 | 3474 | ||
3451 | static int handle_read_event_rsp(ipmi_smi_t intf, | 3475 | static int handle_read_event_rsp(ipmi_smi_t intf, |
3452 | struct ipmi_smi_msg *msg) | 3476 | struct ipmi_smi_msg *msg) |
3453 | { | 3477 | { |
3454 | struct ipmi_recv_msg *recv_msg, *recv_msg2; | 3478 | struct ipmi_recv_msg *recv_msg, *recv_msg2; |
3455 | struct list_head msgs; | 3479 | struct list_head msgs; |
3456 | ipmi_user_t user; | 3480 | ipmi_user_t user; |
3457 | int rv = 0; | 3481 | int rv = 0; |
3458 | int deliver_count = 0; | 3482 | int deliver_count = 0; |
3459 | unsigned long flags; | 3483 | unsigned long flags; |
3460 | 3484 | ||
3461 | if (msg->rsp_size < 19) { | 3485 | if (msg->rsp_size < 19) { |
3462 | /* Message is too small to be an IPMB event. */ | 3486 | /* Message is too small to be an IPMB event. */ |
3463 | ipmi_inc_stat(intf, invalid_events); | 3487 | ipmi_inc_stat(intf, invalid_events); |
3464 | return 0; | 3488 | return 0; |
3465 | } | 3489 | } |
3466 | 3490 | ||
3467 | if (msg->rsp[2] != 0) { | 3491 | if (msg->rsp[2] != 0) { |
3468 | /* An error getting the event, just ignore it. */ | 3492 | /* An error getting the event, just ignore it. */ |
3469 | return 0; | 3493 | return 0; |
3470 | } | 3494 | } |
3471 | 3495 | ||
3472 | INIT_LIST_HEAD(&msgs); | 3496 | INIT_LIST_HEAD(&msgs); |
3473 | 3497 | ||
3474 | spin_lock_irqsave(&intf->events_lock, flags); | 3498 | spin_lock_irqsave(&intf->events_lock, flags); |
3475 | 3499 | ||
3476 | ipmi_inc_stat(intf, events); | 3500 | ipmi_inc_stat(intf, events); |
3477 | 3501 | ||
3478 | /* | 3502 | /* |
3479 | * Allocate and fill in one message for every user that is | 3503 | * Allocate and fill in one message for every user that is |
3480 | * getting events. | 3504 | * getting events. |
3481 | */ | 3505 | */ |
3482 | rcu_read_lock(); | 3506 | rcu_read_lock(); |
3483 | list_for_each_entry_rcu(user, &intf->users, link) { | 3507 | list_for_each_entry_rcu(user, &intf->users, link) { |
3484 | if (!user->gets_events) | 3508 | if (!user->gets_events) |
3485 | continue; | 3509 | continue; |
3486 | 3510 | ||
3487 | recv_msg = ipmi_alloc_recv_msg(); | 3511 | recv_msg = ipmi_alloc_recv_msg(); |
3488 | if (!recv_msg) { | 3512 | if (!recv_msg) { |
3489 | rcu_read_unlock(); | 3513 | rcu_read_unlock(); |
3490 | list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, | 3514 | list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, |
3491 | link) { | 3515 | link) { |
3492 | list_del(&recv_msg->link); | 3516 | list_del(&recv_msg->link); |
3493 | ipmi_free_recv_msg(recv_msg); | 3517 | ipmi_free_recv_msg(recv_msg); |
3494 | } | 3518 | } |
3495 | /* | 3519 | /* |
3496 | * We couldn't allocate memory for the | 3520 | * We couldn't allocate memory for the |
3497 | * message, so requeue it for handling | 3521 | * message, so requeue it for handling |
3498 | * later. | 3522 | * later. |
3499 | */ | 3523 | */ |
3500 | rv = 1; | 3524 | rv = 1; |
3501 | goto out; | 3525 | goto out; |
3502 | } | 3526 | } |
3503 | 3527 | ||
3504 | deliver_count++; | 3528 | deliver_count++; |
3505 | 3529 | ||
3506 | copy_event_into_recv_msg(recv_msg, msg); | 3530 | copy_event_into_recv_msg(recv_msg, msg); |
3507 | recv_msg->user = user; | 3531 | recv_msg->user = user; |
3508 | kref_get(&user->refcount); | 3532 | kref_get(&user->refcount); |
3509 | list_add_tail(&(recv_msg->link), &msgs); | 3533 | list_add_tail(&(recv_msg->link), &msgs); |
3510 | } | 3534 | } |
3511 | rcu_read_unlock(); | 3535 | rcu_read_unlock(); |
3512 | 3536 | ||
3513 | if (deliver_count) { | 3537 | if (deliver_count) { |
3514 | /* Now deliver all the messages. */ | 3538 | /* Now deliver all the messages. */ |
3515 | list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) { | 3539 | list_for_each_entry_safe(recv_msg, recv_msg2, &msgs, link) { |
3516 | list_del(&recv_msg->link); | 3540 | list_del(&recv_msg->link); |
3517 | deliver_response(recv_msg); | 3541 | deliver_response(recv_msg); |
3518 | } | 3542 | } |
3519 | } else if (intf->waiting_events_count < MAX_EVENTS_IN_QUEUE) { | 3543 | } else if (intf->waiting_events_count < MAX_EVENTS_IN_QUEUE) { |
3520 | /* | 3544 | /* |
3521 | * No one to receive the message, put it in queue if there's | 3545 | * No one to receive the message, put it in queue if there's |
3522 | * not already too many things in the queue. | 3546 | * not already too many things in the queue. |
3523 | */ | 3547 | */ |
3524 | recv_msg = ipmi_alloc_recv_msg(); | 3548 | recv_msg = ipmi_alloc_recv_msg(); |
3525 | if (!recv_msg) { | 3549 | if (!recv_msg) { |
3526 | /* | 3550 | /* |
3527 | * We couldn't allocate memory for the | 3551 | * We couldn't allocate memory for the |
3528 | * message, so requeue it for handling | 3552 | * message, so requeue it for handling |
3529 | * later. | 3553 | * later. |
3530 | */ | 3554 | */ |
3531 | rv = 1; | 3555 | rv = 1; |
3532 | goto out; | 3556 | goto out; |
3533 | } | 3557 | } |
3534 | 3558 | ||
3535 | copy_event_into_recv_msg(recv_msg, msg); | 3559 | copy_event_into_recv_msg(recv_msg, msg); |
3536 | list_add_tail(&(recv_msg->link), &(intf->waiting_events)); | 3560 | list_add_tail(&(recv_msg->link), &(intf->waiting_events)); |
3537 | intf->waiting_events_count++; | 3561 | intf->waiting_events_count++; |
3538 | } else if (!intf->event_msg_printed) { | 3562 | } else if (!intf->event_msg_printed) { |
3539 | /* | 3563 | /* |
3540 | * There's too many things in the queue, discard this | 3564 | * There's too many things in the queue, discard this |
3541 | * message. | 3565 | * message. |
3542 | */ | 3566 | */ |
3543 | printk(KERN_WARNING PFX "Event queue full, discarding" | 3567 | printk(KERN_WARNING PFX "Event queue full, discarding" |
3544 | " incoming events\n"); | 3568 | " incoming events\n"); |
3545 | intf->event_msg_printed = 1; | 3569 | intf->event_msg_printed = 1; |
3546 | } | 3570 | } |
3547 | 3571 | ||
3548 | out: | 3572 | out: |
3549 | spin_unlock_irqrestore(&(intf->events_lock), flags); | 3573 | spin_unlock_irqrestore(&(intf->events_lock), flags); |
3550 | 3574 | ||
3551 | return rv; | 3575 | return rv; |
3552 | } | 3576 | } |
3553 | 3577 | ||
3554 | static int handle_bmc_rsp(ipmi_smi_t intf, | 3578 | static int handle_bmc_rsp(ipmi_smi_t intf, |
3555 | struct ipmi_smi_msg *msg) | 3579 | struct ipmi_smi_msg *msg) |
3556 | { | 3580 | { |
3557 | struct ipmi_recv_msg *recv_msg; | 3581 | struct ipmi_recv_msg *recv_msg; |
3558 | struct ipmi_user *user; | 3582 | struct ipmi_user *user; |
3559 | 3583 | ||
3560 | recv_msg = (struct ipmi_recv_msg *) msg->user_data; | 3584 | recv_msg = (struct ipmi_recv_msg *) msg->user_data; |
3561 | if (recv_msg == NULL) { | 3585 | if (recv_msg == NULL) { |
3562 | printk(KERN_WARNING | 3586 | printk(KERN_WARNING |
3563 | "IPMI message received with no owner. This\n" | 3587 | "IPMI message received with no owner. This\n" |
3564 | "could be because of a malformed message, or\n" | 3588 | "could be because of a malformed message, or\n" |
3565 | "because of a hardware error. Contact your\n" | 3589 | "because of a hardware error. Contact your\n" |
3566 | "hardware vender for assistance\n"); | 3590 | "hardware vender for assistance\n"); |
3567 | return 0; | 3591 | return 0; |
3568 | } | 3592 | } |
3569 | 3593 | ||
3570 | user = recv_msg->user; | 3594 | user = recv_msg->user; |
3571 | /* Make sure the user still exists. */ | 3595 | /* Make sure the user still exists. */ |
3572 | if (user && !user->valid) { | 3596 | if (user && !user->valid) { |
3573 | /* The user for the message went away, so give up. */ | 3597 | /* The user for the message went away, so give up. */ |
3574 | ipmi_inc_stat(intf, unhandled_local_responses); | 3598 | ipmi_inc_stat(intf, unhandled_local_responses); |
3575 | ipmi_free_recv_msg(recv_msg); | 3599 | ipmi_free_recv_msg(recv_msg); |
3576 | } else { | 3600 | } else { |
3577 | struct ipmi_system_interface_addr *smi_addr; | 3601 | struct ipmi_system_interface_addr *smi_addr; |
3578 | 3602 | ||
3579 | ipmi_inc_stat(intf, handled_local_responses); | 3603 | ipmi_inc_stat(intf, handled_local_responses); |
3580 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; | 3604 | recv_msg->recv_type = IPMI_RESPONSE_RECV_TYPE; |
3581 | recv_msg->msgid = msg->msgid; | 3605 | recv_msg->msgid = msg->msgid; |
3582 | smi_addr = ((struct ipmi_system_interface_addr *) | 3606 | smi_addr = ((struct ipmi_system_interface_addr *) |
3583 | &(recv_msg->addr)); | 3607 | &(recv_msg->addr)); |
3584 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | 3608 | smi_addr->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
3585 | smi_addr->channel = IPMI_BMC_CHANNEL; | 3609 | smi_addr->channel = IPMI_BMC_CHANNEL; |
3586 | smi_addr->lun = msg->rsp[0] & 3; | 3610 | smi_addr->lun = msg->rsp[0] & 3; |
3587 | recv_msg->msg.netfn = msg->rsp[0] >> 2; | 3611 | recv_msg->msg.netfn = msg->rsp[0] >> 2; |
3588 | recv_msg->msg.cmd = msg->rsp[1]; | 3612 | recv_msg->msg.cmd = msg->rsp[1]; |
3589 | memcpy(recv_msg->msg_data, | 3613 | memcpy(recv_msg->msg_data, |
3590 | &(msg->rsp[2]), | 3614 | &(msg->rsp[2]), |
3591 | msg->rsp_size - 2); | 3615 | msg->rsp_size - 2); |
3592 | recv_msg->msg.data = recv_msg->msg_data; | 3616 | recv_msg->msg.data = recv_msg->msg_data; |
3593 | recv_msg->msg.data_len = msg->rsp_size - 2; | 3617 | recv_msg->msg.data_len = msg->rsp_size - 2; |
3594 | deliver_response(recv_msg); | 3618 | deliver_response(recv_msg); |
3595 | } | 3619 | } |
3596 | 3620 | ||
3597 | return 0; | 3621 | return 0; |
3598 | } | 3622 | } |
3599 | 3623 | ||
3600 | /* | 3624 | /* |
3601 | * Handle a new message. Return 1 if the message should be requeued, | 3625 | * Handle a new message. Return 1 if the message should be requeued, |
3602 | * 0 if the message should be freed, or -1 if the message should not | 3626 | * 0 if the message should be freed, or -1 if the message should not |
3603 | * be freed or requeued. | 3627 | * be freed or requeued. |
3604 | */ | 3628 | */ |
3605 | static int handle_new_recv_msg(ipmi_smi_t intf, | 3629 | static int handle_new_recv_msg(ipmi_smi_t intf, |
3606 | struct ipmi_smi_msg *msg) | 3630 | struct ipmi_smi_msg *msg) |
3607 | { | 3631 | { |
3608 | int requeue; | 3632 | int requeue; |
3609 | int chan; | 3633 | int chan; |
3610 | 3634 | ||
3611 | #ifdef DEBUG_MSGING | 3635 | #ifdef DEBUG_MSGING |
3612 | int m; | 3636 | int m; |
3613 | printk("Recv:"); | 3637 | printk("Recv:"); |
3614 | for (m = 0; m < msg->rsp_size; m++) | 3638 | for (m = 0; m < msg->rsp_size; m++) |
3615 | printk(" %2.2x", msg->rsp[m]); | 3639 | printk(" %2.2x", msg->rsp[m]); |
3616 | printk("\n"); | 3640 | printk("\n"); |
3617 | #endif | 3641 | #endif |
3618 | if (msg->rsp_size < 2) { | 3642 | if (msg->rsp_size < 2) { |
3619 | /* Message is too small to be correct. */ | 3643 | /* Message is too small to be correct. */ |
3620 | printk(KERN_WARNING PFX "BMC returned to small a message" | 3644 | printk(KERN_WARNING PFX "BMC returned to small a message" |
3621 | " for netfn %x cmd %x, got %d bytes\n", | 3645 | " for netfn %x cmd %x, got %d bytes\n", |
3622 | (msg->data[0] >> 2) | 1, msg->data[1], msg->rsp_size); | 3646 | (msg->data[0] >> 2) | 1, msg->data[1], msg->rsp_size); |
3623 | 3647 | ||
3624 | /* Generate an error response for the message. */ | 3648 | /* Generate an error response for the message. */ |
3625 | msg->rsp[0] = msg->data[0] | (1 << 2); | 3649 | msg->rsp[0] = msg->data[0] | (1 << 2); |
3626 | msg->rsp[1] = msg->data[1]; | 3650 | msg->rsp[1] = msg->data[1]; |
3627 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; | 3651 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; |
3628 | msg->rsp_size = 3; | 3652 | msg->rsp_size = 3; |
3629 | } else if (((msg->rsp[0] >> 2) != ((msg->data[0] >> 2) | 1)) | 3653 | } else if (((msg->rsp[0] >> 2) != ((msg->data[0] >> 2) | 1)) |
3630 | || (msg->rsp[1] != msg->data[1])) { | 3654 | || (msg->rsp[1] != msg->data[1])) { |
3631 | /* | 3655 | /* |
3632 | * The NetFN and Command in the response is not even | 3656 | * The NetFN and Command in the response is not even |
3633 | * marginally correct. | 3657 | * marginally correct. |
3634 | */ | 3658 | */ |
3635 | printk(KERN_WARNING PFX "BMC returned incorrect response," | 3659 | printk(KERN_WARNING PFX "BMC returned incorrect response," |
3636 | " expected netfn %x cmd %x, got netfn %x cmd %x\n", | 3660 | " expected netfn %x cmd %x, got netfn %x cmd %x\n", |
3637 | (msg->data[0] >> 2) | 1, msg->data[1], | 3661 | (msg->data[0] >> 2) | 1, msg->data[1], |
3638 | msg->rsp[0] >> 2, msg->rsp[1]); | 3662 | msg->rsp[0] >> 2, msg->rsp[1]); |
3639 | 3663 | ||
3640 | /* Generate an error response for the message. */ | 3664 | /* Generate an error response for the message. */ |
3641 | msg->rsp[0] = msg->data[0] | (1 << 2); | 3665 | msg->rsp[0] = msg->data[0] | (1 << 2); |
3642 | msg->rsp[1] = msg->data[1]; | 3666 | msg->rsp[1] = msg->data[1]; |
3643 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; | 3667 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; |
3644 | msg->rsp_size = 3; | 3668 | msg->rsp_size = 3; |
3645 | } | 3669 | } |
3646 | 3670 | ||
3647 | if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) | 3671 | if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) |
3648 | && (msg->rsp[1] == IPMI_SEND_MSG_CMD) | 3672 | && (msg->rsp[1] == IPMI_SEND_MSG_CMD) |
3649 | && (msg->user_data != NULL)) { | 3673 | && (msg->user_data != NULL)) { |
3650 | /* | 3674 | /* |
3651 | * It's a response to a response we sent. For this we | 3675 | * It's a response to a response we sent. For this we |
3652 | * deliver a send message response to the user. | 3676 | * deliver a send message response to the user. |
3653 | */ | 3677 | */ |
3654 | struct ipmi_recv_msg *recv_msg = msg->user_data; | 3678 | struct ipmi_recv_msg *recv_msg = msg->user_data; |
3655 | 3679 | ||
3656 | requeue = 0; | 3680 | requeue = 0; |
3657 | if (msg->rsp_size < 2) | 3681 | if (msg->rsp_size < 2) |
3658 | /* Message is too small to be correct. */ | 3682 | /* Message is too small to be correct. */ |
3659 | goto out; | 3683 | goto out; |
3660 | 3684 | ||
3661 | chan = msg->data[2] & 0x0f; | 3685 | chan = msg->data[2] & 0x0f; |
3662 | if (chan >= IPMI_MAX_CHANNELS) | 3686 | if (chan >= IPMI_MAX_CHANNELS) |
3663 | /* Invalid channel number */ | 3687 | /* Invalid channel number */ |
3664 | goto out; | 3688 | goto out; |
3665 | 3689 | ||
3666 | if (!recv_msg) | 3690 | if (!recv_msg) |
3667 | goto out; | 3691 | goto out; |
3668 | 3692 | ||
3669 | /* Make sure the user still exists. */ | 3693 | /* Make sure the user still exists. */ |
3670 | if (!recv_msg->user || !recv_msg->user->valid) | 3694 | if (!recv_msg->user || !recv_msg->user->valid) |
3671 | goto out; | 3695 | goto out; |
3672 | 3696 | ||
3673 | recv_msg->recv_type = IPMI_RESPONSE_RESPONSE_TYPE; | 3697 | recv_msg->recv_type = IPMI_RESPONSE_RESPONSE_TYPE; |
3674 | recv_msg->msg.data = recv_msg->msg_data; | 3698 | recv_msg->msg.data = recv_msg->msg_data; |
3675 | recv_msg->msg.data_len = 1; | 3699 | recv_msg->msg.data_len = 1; |
3676 | recv_msg->msg_data[0] = msg->rsp[2]; | 3700 | recv_msg->msg_data[0] = msg->rsp[2]; |
3677 | deliver_response(recv_msg); | 3701 | deliver_response(recv_msg); |
3678 | } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) | 3702 | } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) |
3679 | && (msg->rsp[1] == IPMI_GET_MSG_CMD)) { | 3703 | && (msg->rsp[1] == IPMI_GET_MSG_CMD)) { |
3680 | /* It's from the receive queue. */ | 3704 | /* It's from the receive queue. */ |
3681 | chan = msg->rsp[3] & 0xf; | 3705 | chan = msg->rsp[3] & 0xf; |
3682 | if (chan >= IPMI_MAX_CHANNELS) { | 3706 | if (chan >= IPMI_MAX_CHANNELS) { |
3683 | /* Invalid channel number */ | 3707 | /* Invalid channel number */ |
3684 | requeue = 0; | 3708 | requeue = 0; |
3685 | goto out; | 3709 | goto out; |
3686 | } | 3710 | } |
3687 | 3711 | ||
3688 | /* | 3712 | /* |
3689 | * We need to make sure the channels have been initialized. | 3713 | * We need to make sure the channels have been initialized. |
3690 | * The channel_handler routine will set the "curr_channel" | 3714 | * The channel_handler routine will set the "curr_channel" |
3691 | * equal to or greater than IPMI_MAX_CHANNELS when all the | 3715 | * equal to or greater than IPMI_MAX_CHANNELS when all the |
3692 | * channels for this interface have been initialized. | 3716 | * channels for this interface have been initialized. |
3693 | */ | 3717 | */ |
3694 | if (intf->curr_channel < IPMI_MAX_CHANNELS) { | 3718 | if (intf->curr_channel < IPMI_MAX_CHANNELS) { |
3695 | requeue = 0; /* Throw the message away */ | 3719 | requeue = 0; /* Throw the message away */ |
3696 | goto out; | 3720 | goto out; |
3697 | } | 3721 | } |
3698 | 3722 | ||
3699 | switch (intf->channels[chan].medium) { | 3723 | switch (intf->channels[chan].medium) { |
3700 | case IPMI_CHANNEL_MEDIUM_IPMB: | 3724 | case IPMI_CHANNEL_MEDIUM_IPMB: |
3701 | if (msg->rsp[4] & 0x04) { | 3725 | if (msg->rsp[4] & 0x04) { |
3702 | /* | 3726 | /* |
3703 | * It's a response, so find the | 3727 | * It's a response, so find the |
3704 | * requesting message and send it up. | 3728 | * requesting message and send it up. |
3705 | */ | 3729 | */ |
3706 | requeue = handle_ipmb_get_msg_rsp(intf, msg); | 3730 | requeue = handle_ipmb_get_msg_rsp(intf, msg); |
3707 | } else { | 3731 | } else { |
3708 | /* | 3732 | /* |
3709 | * It's a command to the SMS from some other | 3733 | * It's a command to the SMS from some other |
3710 | * entity. Handle that. | 3734 | * entity. Handle that. |
3711 | */ | 3735 | */ |
3712 | requeue = handle_ipmb_get_msg_cmd(intf, msg); | 3736 | requeue = handle_ipmb_get_msg_cmd(intf, msg); |
3713 | } | 3737 | } |
3714 | break; | 3738 | break; |
3715 | 3739 | ||
3716 | case IPMI_CHANNEL_MEDIUM_8023LAN: | 3740 | case IPMI_CHANNEL_MEDIUM_8023LAN: |
3717 | case IPMI_CHANNEL_MEDIUM_ASYNC: | 3741 | case IPMI_CHANNEL_MEDIUM_ASYNC: |
3718 | if (msg->rsp[6] & 0x04) { | 3742 | if (msg->rsp[6] & 0x04) { |
3719 | /* | 3743 | /* |
3720 | * It's a response, so find the | 3744 | * It's a response, so find the |
3721 | * requesting message and send it up. | 3745 | * requesting message and send it up. |
3722 | */ | 3746 | */ |
3723 | requeue = handle_lan_get_msg_rsp(intf, msg); | 3747 | requeue = handle_lan_get_msg_rsp(intf, msg); |
3724 | } else { | 3748 | } else { |
3725 | /* | 3749 | /* |
3726 | * It's a command to the SMS from some other | 3750 | * It's a command to the SMS from some other |
3727 | * entity. Handle that. | 3751 | * entity. Handle that. |
3728 | */ | 3752 | */ |
3729 | requeue = handle_lan_get_msg_cmd(intf, msg); | 3753 | requeue = handle_lan_get_msg_cmd(intf, msg); |
3730 | } | 3754 | } |
3731 | break; | 3755 | break; |
3732 | 3756 | ||
3733 | default: | 3757 | default: |
3734 | /* Check for OEM Channels. Clients had better | 3758 | /* Check for OEM Channels. Clients had better |
3735 | register for these commands. */ | 3759 | register for these commands. */ |
3736 | if ((intf->channels[chan].medium | 3760 | if ((intf->channels[chan].medium |
3737 | >= IPMI_CHANNEL_MEDIUM_OEM_MIN) | 3761 | >= IPMI_CHANNEL_MEDIUM_OEM_MIN) |
3738 | && (intf->channels[chan].medium | 3762 | && (intf->channels[chan].medium |
3739 | <= IPMI_CHANNEL_MEDIUM_OEM_MAX)) { | 3763 | <= IPMI_CHANNEL_MEDIUM_OEM_MAX)) { |
3740 | requeue = handle_oem_get_msg_cmd(intf, msg); | 3764 | requeue = handle_oem_get_msg_cmd(intf, msg); |
3741 | } else { | 3765 | } else { |
3742 | /* | 3766 | /* |
3743 | * We don't handle the channel type, so just | 3767 | * We don't handle the channel type, so just |
3744 | * free the message. | 3768 | * free the message. |
3745 | */ | 3769 | */ |
3746 | requeue = 0; | 3770 | requeue = 0; |
3747 | } | 3771 | } |
3748 | } | 3772 | } |
3749 | 3773 | ||
3750 | } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) | 3774 | } else if ((msg->rsp[0] == ((IPMI_NETFN_APP_REQUEST|1) << 2)) |
3751 | && (msg->rsp[1] == IPMI_READ_EVENT_MSG_BUFFER_CMD)) { | 3775 | && (msg->rsp[1] == IPMI_READ_EVENT_MSG_BUFFER_CMD)) { |
3752 | /* It's an asyncronous event. */ | 3776 | /* It's an asyncronous event. */ |
3753 | requeue = handle_read_event_rsp(intf, msg); | 3777 | requeue = handle_read_event_rsp(intf, msg); |
3754 | } else { | 3778 | } else { |
3755 | /* It's a response from the local BMC. */ | 3779 | /* It's a response from the local BMC. */ |
3756 | requeue = handle_bmc_rsp(intf, msg); | 3780 | requeue = handle_bmc_rsp(intf, msg); |
3757 | } | 3781 | } |
3758 | 3782 | ||
3759 | out: | 3783 | out: |
3760 | return requeue; | 3784 | return requeue; |
3761 | } | 3785 | } |
3762 | 3786 | ||
3763 | /* Handle a new message from the lower layer. */ | 3787 | /* Handle a new message from the lower layer. */ |
3764 | void ipmi_smi_msg_received(ipmi_smi_t intf, | 3788 | void ipmi_smi_msg_received(ipmi_smi_t intf, |
3765 | struct ipmi_smi_msg *msg) | 3789 | struct ipmi_smi_msg *msg) |
3766 | { | 3790 | { |
3767 | unsigned long flags = 0; /* keep us warning-free. */ | 3791 | unsigned long flags = 0; /* keep us warning-free. */ |
3768 | int rv; | 3792 | int rv; |
3769 | int run_to_completion; | 3793 | int run_to_completion; |
3770 | 3794 | ||
3771 | 3795 | ||
3772 | if ((msg->data_size >= 2) | 3796 | if ((msg->data_size >= 2) |
3773 | && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2)) | 3797 | && (msg->data[0] == (IPMI_NETFN_APP_REQUEST << 2)) |
3774 | && (msg->data[1] == IPMI_SEND_MSG_CMD) | 3798 | && (msg->data[1] == IPMI_SEND_MSG_CMD) |
3775 | && (msg->user_data == NULL)) { | 3799 | && (msg->user_data == NULL)) { |
3776 | /* | 3800 | /* |
3777 | * This is the local response to a command send, start | 3801 | * This is the local response to a command send, start |
3778 | * the timer for these. The user_data will not be | 3802 | * the timer for these. The user_data will not be |
3779 | * NULL if this is a response send, and we will let | 3803 | * NULL if this is a response send, and we will let |
3780 | * response sends just go through. | 3804 | * response sends just go through. |
3781 | */ | 3805 | */ |
3782 | 3806 | ||
3783 | /* | 3807 | /* |
3784 | * Check for errors, if we get certain errors (ones | 3808 | * Check for errors, if we get certain errors (ones |
3785 | * that mean basically we can try again later), we | 3809 | * that mean basically we can try again later), we |
3786 | * ignore them and start the timer. Otherwise we | 3810 | * ignore them and start the timer. Otherwise we |
3787 | * report the error immediately. | 3811 | * report the error immediately. |
3788 | */ | 3812 | */ |
3789 | if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0) | 3813 | if ((msg->rsp_size >= 3) && (msg->rsp[2] != 0) |
3790 | && (msg->rsp[2] != IPMI_NODE_BUSY_ERR) | 3814 | && (msg->rsp[2] != IPMI_NODE_BUSY_ERR) |
3791 | && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR) | 3815 | && (msg->rsp[2] != IPMI_LOST_ARBITRATION_ERR) |
3792 | && (msg->rsp[2] != IPMI_BUS_ERR) | 3816 | && (msg->rsp[2] != IPMI_BUS_ERR) |
3793 | && (msg->rsp[2] != IPMI_NAK_ON_WRITE_ERR)) { | 3817 | && (msg->rsp[2] != IPMI_NAK_ON_WRITE_ERR)) { |
3794 | int chan = msg->rsp[3] & 0xf; | 3818 | int chan = msg->rsp[3] & 0xf; |
3795 | 3819 | ||
3796 | /* Got an error sending the message, handle it. */ | 3820 | /* Got an error sending the message, handle it. */ |
3797 | if (chan >= IPMI_MAX_CHANNELS) | 3821 | if (chan >= IPMI_MAX_CHANNELS) |
3798 | ; /* This shouldn't happen */ | 3822 | ; /* This shouldn't happen */ |
3799 | else if ((intf->channels[chan].medium | 3823 | else if ((intf->channels[chan].medium |
3800 | == IPMI_CHANNEL_MEDIUM_8023LAN) | 3824 | == IPMI_CHANNEL_MEDIUM_8023LAN) |
3801 | || (intf->channels[chan].medium | 3825 | || (intf->channels[chan].medium |
3802 | == IPMI_CHANNEL_MEDIUM_ASYNC)) | 3826 | == IPMI_CHANNEL_MEDIUM_ASYNC)) |
3803 | ipmi_inc_stat(intf, sent_lan_command_errs); | 3827 | ipmi_inc_stat(intf, sent_lan_command_errs); |
3804 | else | 3828 | else |
3805 | ipmi_inc_stat(intf, sent_ipmb_command_errs); | 3829 | ipmi_inc_stat(intf, sent_ipmb_command_errs); |
3806 | intf_err_seq(intf, msg->msgid, msg->rsp[2]); | 3830 | intf_err_seq(intf, msg->msgid, msg->rsp[2]); |
3807 | } else | 3831 | } else |
3808 | /* The message was sent, start the timer. */ | 3832 | /* The message was sent, start the timer. */ |
3809 | intf_start_seq_timer(intf, msg->msgid); | 3833 | intf_start_seq_timer(intf, msg->msgid); |
3810 | 3834 | ||
3811 | ipmi_free_smi_msg(msg); | 3835 | ipmi_free_smi_msg(msg); |
3812 | goto out; | 3836 | goto out; |
3813 | } | 3837 | } |
3814 | 3838 | ||
3815 | /* | 3839 | /* |
3816 | * To preserve message order, if the list is not empty, we | 3840 | * To preserve message order, if the list is not empty, we |
3817 | * tack this message onto the end of the list. | 3841 | * tack this message onto the end of the list. |
3818 | */ | 3842 | */ |
3819 | run_to_completion = intf->run_to_completion; | 3843 | run_to_completion = intf->run_to_completion; |
3820 | if (!run_to_completion) | 3844 | if (!run_to_completion) |
3821 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); | 3845 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); |
3822 | if (!list_empty(&intf->waiting_msgs)) { | 3846 | if (!list_empty(&intf->waiting_msgs)) { |
3823 | list_add_tail(&msg->link, &intf->waiting_msgs); | 3847 | list_add_tail(&msg->link, &intf->waiting_msgs); |
3824 | if (!run_to_completion) | 3848 | if (!run_to_completion) |
3825 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); | 3849 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); |
3826 | goto out; | 3850 | goto out; |
3827 | } | 3851 | } |
3828 | if (!run_to_completion) | 3852 | if (!run_to_completion) |
3829 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); | 3853 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); |
3830 | 3854 | ||
3831 | rv = handle_new_recv_msg(intf, msg); | 3855 | rv = handle_new_recv_msg(intf, msg); |
3832 | if (rv > 0) { | 3856 | if (rv > 0) { |
3833 | /* | 3857 | /* |
3834 | * Could not handle the message now, just add it to a | 3858 | * Could not handle the message now, just add it to a |
3835 | * list to handle later. | 3859 | * list to handle later. |
3836 | */ | 3860 | */ |
3837 | run_to_completion = intf->run_to_completion; | 3861 | run_to_completion = intf->run_to_completion; |
3838 | if (!run_to_completion) | 3862 | if (!run_to_completion) |
3839 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); | 3863 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); |
3840 | list_add_tail(&msg->link, &intf->waiting_msgs); | 3864 | list_add_tail(&msg->link, &intf->waiting_msgs); |
3841 | if (!run_to_completion) | 3865 | if (!run_to_completion) |
3842 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); | 3866 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); |
3843 | } else if (rv == 0) { | 3867 | } else if (rv == 0) { |
3844 | ipmi_free_smi_msg(msg); | 3868 | ipmi_free_smi_msg(msg); |
3845 | } | 3869 | } |
3846 | 3870 | ||
3847 | out: | 3871 | out: |
3848 | return; | 3872 | return; |
3849 | } | 3873 | } |
3850 | EXPORT_SYMBOL(ipmi_smi_msg_received); | 3874 | EXPORT_SYMBOL(ipmi_smi_msg_received); |
3851 | 3875 | ||
3852 | void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf) | 3876 | void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf) |
3853 | { | 3877 | { |
3854 | ipmi_user_t user; | 3878 | ipmi_user_t user; |
3855 | 3879 | ||
3856 | rcu_read_lock(); | 3880 | rcu_read_lock(); |
3857 | list_for_each_entry_rcu(user, &intf->users, link) { | 3881 | list_for_each_entry_rcu(user, &intf->users, link) { |
3858 | if (!user->handler->ipmi_watchdog_pretimeout) | 3882 | if (!user->handler->ipmi_watchdog_pretimeout) |
3859 | continue; | 3883 | continue; |
3860 | 3884 | ||
3861 | user->handler->ipmi_watchdog_pretimeout(user->handler_data); | 3885 | user->handler->ipmi_watchdog_pretimeout(user->handler_data); |
3862 | } | 3886 | } |
3863 | rcu_read_unlock(); | 3887 | rcu_read_unlock(); |
3864 | } | 3888 | } |
3865 | EXPORT_SYMBOL(ipmi_smi_watchdog_pretimeout); | 3889 | EXPORT_SYMBOL(ipmi_smi_watchdog_pretimeout); |
3866 | 3890 | ||
3867 | static struct ipmi_smi_msg * | 3891 | static struct ipmi_smi_msg * |
3868 | smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg, | 3892 | smi_from_recv_msg(ipmi_smi_t intf, struct ipmi_recv_msg *recv_msg, |
3869 | unsigned char seq, long seqid) | 3893 | unsigned char seq, long seqid) |
3870 | { | 3894 | { |
3871 | struct ipmi_smi_msg *smi_msg = ipmi_alloc_smi_msg(); | 3895 | struct ipmi_smi_msg *smi_msg = ipmi_alloc_smi_msg(); |
3872 | if (!smi_msg) | 3896 | if (!smi_msg) |
3873 | /* | 3897 | /* |
3874 | * If we can't allocate the message, then just return, we | 3898 | * If we can't allocate the message, then just return, we |
3875 | * get 4 retries, so this should be ok. | 3899 | * get 4 retries, so this should be ok. |
3876 | */ | 3900 | */ |
3877 | return NULL; | 3901 | return NULL; |
3878 | 3902 | ||
3879 | memcpy(smi_msg->data, recv_msg->msg.data, recv_msg->msg.data_len); | 3903 | memcpy(smi_msg->data, recv_msg->msg.data, recv_msg->msg.data_len); |
3880 | smi_msg->data_size = recv_msg->msg.data_len; | 3904 | smi_msg->data_size = recv_msg->msg.data_len; |
3881 | smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid); | 3905 | smi_msg->msgid = STORE_SEQ_IN_MSGID(seq, seqid); |
3882 | 3906 | ||
3883 | #ifdef DEBUG_MSGING | 3907 | #ifdef DEBUG_MSGING |
3884 | { | 3908 | { |
3885 | int m; | 3909 | int m; |
3886 | printk("Resend: "); | 3910 | printk("Resend: "); |
3887 | for (m = 0; m < smi_msg->data_size; m++) | 3911 | for (m = 0; m < smi_msg->data_size; m++) |
3888 | printk(" %2.2x", smi_msg->data[m]); | 3912 | printk(" %2.2x", smi_msg->data[m]); |
3889 | printk("\n"); | 3913 | printk("\n"); |
3890 | } | 3914 | } |
3891 | #endif | 3915 | #endif |
3892 | return smi_msg; | 3916 | return smi_msg; |
3893 | } | 3917 | } |
3894 | 3918 | ||
3895 | static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent, | 3919 | static void check_msg_timeout(ipmi_smi_t intf, struct seq_table *ent, |
3896 | struct list_head *timeouts, long timeout_period, | 3920 | struct list_head *timeouts, long timeout_period, |
3897 | int slot, unsigned long *flags) | 3921 | int slot, unsigned long *flags) |
3898 | { | 3922 | { |
3899 | struct ipmi_recv_msg *msg; | 3923 | struct ipmi_recv_msg *msg; |
3900 | struct ipmi_smi_handlers *handlers; | 3924 | struct ipmi_smi_handlers *handlers; |
3901 | 3925 | ||
3902 | if (intf->intf_num == -1) | 3926 | if (intf->intf_num == -1) |
3903 | return; | 3927 | return; |
3904 | 3928 | ||
3905 | if (!ent->inuse) | 3929 | if (!ent->inuse) |
3906 | return; | 3930 | return; |
3907 | 3931 | ||
3908 | ent->timeout -= timeout_period; | 3932 | ent->timeout -= timeout_period; |
3909 | if (ent->timeout > 0) | 3933 | if (ent->timeout > 0) |
3910 | return; | 3934 | return; |
3911 | 3935 | ||
3912 | if (ent->retries_left == 0) { | 3936 | if (ent->retries_left == 0) { |
3913 | /* The message has used all its retries. */ | 3937 | /* The message has used all its retries. */ |
3914 | ent->inuse = 0; | 3938 | ent->inuse = 0; |
3915 | msg = ent->recv_msg; | 3939 | msg = ent->recv_msg; |
3916 | list_add_tail(&msg->link, timeouts); | 3940 | list_add_tail(&msg->link, timeouts); |
3917 | if (ent->broadcast) | 3941 | if (ent->broadcast) |
3918 | ipmi_inc_stat(intf, timed_out_ipmb_broadcasts); | 3942 | ipmi_inc_stat(intf, timed_out_ipmb_broadcasts); |
3919 | else if (is_lan_addr(&ent->recv_msg->addr)) | 3943 | else if (is_lan_addr(&ent->recv_msg->addr)) |
3920 | ipmi_inc_stat(intf, timed_out_lan_commands); | 3944 | ipmi_inc_stat(intf, timed_out_lan_commands); |
3921 | else | 3945 | else |
3922 | ipmi_inc_stat(intf, timed_out_ipmb_commands); | 3946 | ipmi_inc_stat(intf, timed_out_ipmb_commands); |
3923 | } else { | 3947 | } else { |
3924 | struct ipmi_smi_msg *smi_msg; | 3948 | struct ipmi_smi_msg *smi_msg; |
3925 | /* More retries, send again. */ | 3949 | /* More retries, send again. */ |
3926 | 3950 | ||
3927 | /* | 3951 | /* |
3928 | * Start with the max timer, set to normal timer after | 3952 | * Start with the max timer, set to normal timer after |
3929 | * the message is sent. | 3953 | * the message is sent. |
3930 | */ | 3954 | */ |
3931 | ent->timeout = MAX_MSG_TIMEOUT; | 3955 | ent->timeout = MAX_MSG_TIMEOUT; |
3932 | ent->retries_left--; | 3956 | ent->retries_left--; |
3933 | smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot, | 3957 | smi_msg = smi_from_recv_msg(intf, ent->recv_msg, slot, |
3934 | ent->seqid); | 3958 | ent->seqid); |
3935 | if (!smi_msg) { | 3959 | if (!smi_msg) { |
3936 | if (is_lan_addr(&ent->recv_msg->addr)) | 3960 | if (is_lan_addr(&ent->recv_msg->addr)) |
3937 | ipmi_inc_stat(intf, | 3961 | ipmi_inc_stat(intf, |
3938 | dropped_rexmit_lan_commands); | 3962 | dropped_rexmit_lan_commands); |
3939 | else | 3963 | else |
3940 | ipmi_inc_stat(intf, | 3964 | ipmi_inc_stat(intf, |
3941 | dropped_rexmit_ipmb_commands); | 3965 | dropped_rexmit_ipmb_commands); |
3942 | return; | 3966 | return; |
3943 | } | 3967 | } |
3944 | 3968 | ||
3945 | spin_unlock_irqrestore(&intf->seq_lock, *flags); | 3969 | spin_unlock_irqrestore(&intf->seq_lock, *flags); |
3946 | 3970 | ||
3947 | /* | 3971 | /* |
3948 | * Send the new message. We send with a zero | 3972 | * Send the new message. We send with a zero |
3949 | * priority. It timed out, I doubt time is that | 3973 | * priority. It timed out, I doubt time is that |
3950 | * critical now, and high priority messages are really | 3974 | * critical now, and high priority messages are really |
3951 | * only for messages to the local MC, which don't get | 3975 | * only for messages to the local MC, which don't get |
3952 | * resent. | 3976 | * resent. |
3953 | */ | 3977 | */ |
3954 | handlers = intf->handlers; | 3978 | handlers = intf->handlers; |
3955 | if (handlers) { | 3979 | if (handlers) { |
3956 | if (is_lan_addr(&ent->recv_msg->addr)) | 3980 | if (is_lan_addr(&ent->recv_msg->addr)) |
3957 | ipmi_inc_stat(intf, | 3981 | ipmi_inc_stat(intf, |
3958 | retransmitted_lan_commands); | 3982 | retransmitted_lan_commands); |
3959 | else | 3983 | else |
3960 | ipmi_inc_stat(intf, | 3984 | ipmi_inc_stat(intf, |
3961 | retransmitted_ipmb_commands); | 3985 | retransmitted_ipmb_commands); |
3962 | 3986 | ||
3963 | intf->handlers->sender(intf->send_info, | 3987 | intf->handlers->sender(intf->send_info, |
3964 | smi_msg, 0); | 3988 | smi_msg, 0); |
3965 | } else | 3989 | } else |
3966 | ipmi_free_smi_msg(smi_msg); | 3990 | ipmi_free_smi_msg(smi_msg); |
3967 | 3991 | ||
3968 | spin_lock_irqsave(&intf->seq_lock, *flags); | 3992 | spin_lock_irqsave(&intf->seq_lock, *flags); |
3969 | } | 3993 | } |
3970 | } | 3994 | } |
3971 | 3995 | ||
3972 | static void ipmi_timeout_handler(long timeout_period) | 3996 | static void ipmi_timeout_handler(long timeout_period) |
3973 | { | 3997 | { |
3974 | ipmi_smi_t intf; | 3998 | ipmi_smi_t intf; |
3975 | struct list_head timeouts; | 3999 | struct list_head timeouts; |
3976 | struct ipmi_recv_msg *msg, *msg2; | 4000 | struct ipmi_recv_msg *msg, *msg2; |
3977 | struct ipmi_smi_msg *smi_msg, *smi_msg2; | 4001 | struct ipmi_smi_msg *smi_msg, *smi_msg2; |
3978 | unsigned long flags; | 4002 | unsigned long flags; |
3979 | int i; | 4003 | int i; |
3980 | 4004 | ||
3981 | rcu_read_lock(); | 4005 | rcu_read_lock(); |
3982 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { | 4006 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
3983 | /* See if any waiting messages need to be processed. */ | 4007 | /* See if any waiting messages need to be processed. */ |
3984 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); | 4008 | spin_lock_irqsave(&intf->waiting_msgs_lock, flags); |
3985 | list_for_each_entry_safe(smi_msg, smi_msg2, | 4009 | list_for_each_entry_safe(smi_msg, smi_msg2, |
3986 | &intf->waiting_msgs, link) { | 4010 | &intf->waiting_msgs, link) { |
3987 | if (!handle_new_recv_msg(intf, smi_msg)) { | 4011 | if (!handle_new_recv_msg(intf, smi_msg)) { |
3988 | list_del(&smi_msg->link); | 4012 | list_del(&smi_msg->link); |
3989 | ipmi_free_smi_msg(smi_msg); | 4013 | ipmi_free_smi_msg(smi_msg); |
3990 | } else { | 4014 | } else { |
3991 | /* | 4015 | /* |
3992 | * To preserve message order, quit if we | 4016 | * To preserve message order, quit if we |
3993 | * can't handle a message. | 4017 | * can't handle a message. |
3994 | */ | 4018 | */ |
3995 | break; | 4019 | break; |
3996 | } | 4020 | } |
3997 | } | 4021 | } |
3998 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); | 4022 | spin_unlock_irqrestore(&intf->waiting_msgs_lock, flags); |
3999 | 4023 | ||
4000 | /* | 4024 | /* |
4001 | * Go through the seq table and find any messages that | 4025 | * Go through the seq table and find any messages that |
4002 | * have timed out, putting them in the timeouts | 4026 | * have timed out, putting them in the timeouts |
4003 | * list. | 4027 | * list. |
4004 | */ | 4028 | */ |
4005 | INIT_LIST_HEAD(&timeouts); | 4029 | INIT_LIST_HEAD(&timeouts); |
4006 | spin_lock_irqsave(&intf->seq_lock, flags); | 4030 | spin_lock_irqsave(&intf->seq_lock, flags); |
4007 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) | 4031 | for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++) |
4008 | check_msg_timeout(intf, &(intf->seq_table[i]), | 4032 | check_msg_timeout(intf, &(intf->seq_table[i]), |
4009 | &timeouts, timeout_period, i, | 4033 | &timeouts, timeout_period, i, |
4010 | &flags); | 4034 | &flags); |
4011 | spin_unlock_irqrestore(&intf->seq_lock, flags); | 4035 | spin_unlock_irqrestore(&intf->seq_lock, flags); |
4012 | 4036 | ||
4013 | list_for_each_entry_safe(msg, msg2, &timeouts, link) | 4037 | list_for_each_entry_safe(msg, msg2, &timeouts, link) |
4014 | deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE); | 4038 | deliver_err_response(msg, IPMI_TIMEOUT_COMPLETION_CODE); |
4015 | 4039 | ||
4016 | /* | 4040 | /* |
4017 | * Maintenance mode handling. Check the timeout | 4041 | * Maintenance mode handling. Check the timeout |
4018 | * optimistically before we claim the lock. It may | 4042 | * optimistically before we claim the lock. It may |
4019 | * mean a timeout gets missed occasionally, but that | 4043 | * mean a timeout gets missed occasionally, but that |
4020 | * only means the timeout gets extended by one period | 4044 | * only means the timeout gets extended by one period |
4021 | * in that case. No big deal, and it avoids the lock | 4045 | * in that case. No big deal, and it avoids the lock |
4022 | * most of the time. | 4046 | * most of the time. |
4023 | */ | 4047 | */ |
4024 | if (intf->auto_maintenance_timeout > 0) { | 4048 | if (intf->auto_maintenance_timeout > 0) { |
4025 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); | 4049 | spin_lock_irqsave(&intf->maintenance_mode_lock, flags); |
4026 | if (intf->auto_maintenance_timeout > 0) { | 4050 | if (intf->auto_maintenance_timeout > 0) { |
4027 | intf->auto_maintenance_timeout | 4051 | intf->auto_maintenance_timeout |
4028 | -= timeout_period; | 4052 | -= timeout_period; |
4029 | if (!intf->maintenance_mode | 4053 | if (!intf->maintenance_mode |
4030 | && (intf->auto_maintenance_timeout <= 0)) { | 4054 | && (intf->auto_maintenance_timeout <= 0)) { |
4031 | intf->maintenance_mode_enable = 0; | 4055 | intf->maintenance_mode_enable = 0; |
4032 | maintenance_mode_update(intf); | 4056 | maintenance_mode_update(intf); |
4033 | } | 4057 | } |
4034 | } | 4058 | } |
4035 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, | 4059 | spin_unlock_irqrestore(&intf->maintenance_mode_lock, |
4036 | flags); | 4060 | flags); |
4037 | } | 4061 | } |
4038 | } | 4062 | } |
4039 | rcu_read_unlock(); | 4063 | rcu_read_unlock(); |
4040 | } | 4064 | } |
4041 | 4065 | ||
4042 | static void ipmi_request_event(void) | 4066 | static void ipmi_request_event(void) |
4043 | { | 4067 | { |
4044 | ipmi_smi_t intf; | 4068 | ipmi_smi_t intf; |
4045 | struct ipmi_smi_handlers *handlers; | 4069 | struct ipmi_smi_handlers *handlers; |
4046 | 4070 | ||
4047 | rcu_read_lock(); | 4071 | rcu_read_lock(); |
4048 | /* | 4072 | /* |
4049 | * Called from the timer, no need to check if handlers is | 4073 | * Called from the timer, no need to check if handlers is |
4050 | * valid. | 4074 | * valid. |
4051 | */ | 4075 | */ |
4052 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { | 4076 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
4053 | /* No event requests when in maintenance mode. */ | 4077 | /* No event requests when in maintenance mode. */ |
4054 | if (intf->maintenance_mode_enable) | 4078 | if (intf->maintenance_mode_enable) |
4055 | continue; | 4079 | continue; |
4056 | 4080 | ||
4057 | handlers = intf->handlers; | 4081 | handlers = intf->handlers; |
4058 | if (handlers) | 4082 | if (handlers) |
4059 | handlers->request_events(intf->send_info); | 4083 | handlers->request_events(intf->send_info); |
4060 | } | 4084 | } |
4061 | rcu_read_unlock(); | 4085 | rcu_read_unlock(); |
4062 | } | 4086 | } |
4063 | 4087 | ||
4064 | static struct timer_list ipmi_timer; | 4088 | static struct timer_list ipmi_timer; |
4065 | 4089 | ||
4066 | /* Call every ~1000 ms. */ | 4090 | /* Call every ~1000 ms. */ |
4067 | #define IPMI_TIMEOUT_TIME 1000 | 4091 | #define IPMI_TIMEOUT_TIME 1000 |
4068 | 4092 | ||
4069 | /* How many jiffies does it take to get to the timeout time. */ | 4093 | /* How many jiffies does it take to get to the timeout time. */ |
4070 | #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000) | 4094 | #define IPMI_TIMEOUT_JIFFIES ((IPMI_TIMEOUT_TIME * HZ) / 1000) |
4071 | 4095 | ||
4072 | /* | 4096 | /* |
4073 | * Request events from the queue every second (this is the number of | 4097 | * Request events from the queue every second (this is the number of |
4074 | * IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the | 4098 | * IPMI_TIMEOUT_TIMES between event requests). Hopefully, in the |
4075 | * future, IPMI will add a way to know immediately if an event is in | 4099 | * future, IPMI will add a way to know immediately if an event is in |
4076 | * the queue and this silliness can go away. | 4100 | * the queue and this silliness can go away. |
4077 | */ | 4101 | */ |
4078 | #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME)) | 4102 | #define IPMI_REQUEST_EV_TIME (1000 / (IPMI_TIMEOUT_TIME)) |
4079 | 4103 | ||
4080 | static atomic_t stop_operation; | 4104 | static atomic_t stop_operation; |
4081 | static unsigned int ticks_to_req_ev = IPMI_REQUEST_EV_TIME; | 4105 | static unsigned int ticks_to_req_ev = IPMI_REQUEST_EV_TIME; |
4082 | 4106 | ||
4083 | static void ipmi_timeout(unsigned long data) | 4107 | static void ipmi_timeout(unsigned long data) |
4084 | { | 4108 | { |
4085 | if (atomic_read(&stop_operation)) | 4109 | if (atomic_read(&stop_operation)) |
4086 | return; | 4110 | return; |
4087 | 4111 | ||
4088 | ticks_to_req_ev--; | 4112 | ticks_to_req_ev--; |
4089 | if (ticks_to_req_ev == 0) { | 4113 | if (ticks_to_req_ev == 0) { |
4090 | ipmi_request_event(); | 4114 | ipmi_request_event(); |
4091 | ticks_to_req_ev = IPMI_REQUEST_EV_TIME; | 4115 | ticks_to_req_ev = IPMI_REQUEST_EV_TIME; |
4092 | } | 4116 | } |
4093 | 4117 | ||
4094 | ipmi_timeout_handler(IPMI_TIMEOUT_TIME); | 4118 | ipmi_timeout_handler(IPMI_TIMEOUT_TIME); |
4095 | 4119 | ||
4096 | mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); | 4120 | mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); |
4097 | } | 4121 | } |
4098 | 4122 | ||
4099 | 4123 | ||
4100 | static atomic_t smi_msg_inuse_count = ATOMIC_INIT(0); | 4124 | static atomic_t smi_msg_inuse_count = ATOMIC_INIT(0); |
4101 | static atomic_t recv_msg_inuse_count = ATOMIC_INIT(0); | 4125 | static atomic_t recv_msg_inuse_count = ATOMIC_INIT(0); |
4102 | 4126 | ||
4103 | /* FIXME - convert these to slabs. */ | 4127 | /* FIXME - convert these to slabs. */ |
4104 | static void free_smi_msg(struct ipmi_smi_msg *msg) | 4128 | static void free_smi_msg(struct ipmi_smi_msg *msg) |
4105 | { | 4129 | { |
4106 | atomic_dec(&smi_msg_inuse_count); | 4130 | atomic_dec(&smi_msg_inuse_count); |
4107 | kfree(msg); | 4131 | kfree(msg); |
4108 | } | 4132 | } |
4109 | 4133 | ||
4110 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void) | 4134 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void) |
4111 | { | 4135 | { |
4112 | struct ipmi_smi_msg *rv; | 4136 | struct ipmi_smi_msg *rv; |
4113 | rv = kmalloc(sizeof(struct ipmi_smi_msg), GFP_ATOMIC); | 4137 | rv = kmalloc(sizeof(struct ipmi_smi_msg), GFP_ATOMIC); |
4114 | if (rv) { | 4138 | if (rv) { |
4115 | rv->done = free_smi_msg; | 4139 | rv->done = free_smi_msg; |
4116 | rv->user_data = NULL; | 4140 | rv->user_data = NULL; |
4117 | atomic_inc(&smi_msg_inuse_count); | 4141 | atomic_inc(&smi_msg_inuse_count); |
4118 | } | 4142 | } |
4119 | return rv; | 4143 | return rv; |
4120 | } | 4144 | } |
4121 | EXPORT_SYMBOL(ipmi_alloc_smi_msg); | 4145 | EXPORT_SYMBOL(ipmi_alloc_smi_msg); |
4122 | 4146 | ||
4123 | static void free_recv_msg(struct ipmi_recv_msg *msg) | 4147 | static void free_recv_msg(struct ipmi_recv_msg *msg) |
4124 | { | 4148 | { |
4125 | atomic_dec(&recv_msg_inuse_count); | 4149 | atomic_dec(&recv_msg_inuse_count); |
4126 | kfree(msg); | 4150 | kfree(msg); |
4127 | } | 4151 | } |
4128 | 4152 | ||
4129 | static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void) | 4153 | static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void) |
4130 | { | 4154 | { |
4131 | struct ipmi_recv_msg *rv; | 4155 | struct ipmi_recv_msg *rv; |
4132 | 4156 | ||
4133 | rv = kmalloc(sizeof(struct ipmi_recv_msg), GFP_ATOMIC); | 4157 | rv = kmalloc(sizeof(struct ipmi_recv_msg), GFP_ATOMIC); |
4134 | if (rv) { | 4158 | if (rv) { |
4135 | rv->user = NULL; | 4159 | rv->user = NULL; |
4136 | rv->done = free_recv_msg; | 4160 | rv->done = free_recv_msg; |
4137 | atomic_inc(&recv_msg_inuse_count); | 4161 | atomic_inc(&recv_msg_inuse_count); |
4138 | } | 4162 | } |
4139 | return rv; | 4163 | return rv; |
4140 | } | 4164 | } |
4141 | 4165 | ||
4142 | void ipmi_free_recv_msg(struct ipmi_recv_msg *msg) | 4166 | void ipmi_free_recv_msg(struct ipmi_recv_msg *msg) |
4143 | { | 4167 | { |
4144 | if (msg->user) | 4168 | if (msg->user) |
4145 | kref_put(&msg->user->refcount, free_user); | 4169 | kref_put(&msg->user->refcount, free_user); |
4146 | msg->done(msg); | 4170 | msg->done(msg); |
4147 | } | 4171 | } |
4148 | EXPORT_SYMBOL(ipmi_free_recv_msg); | 4172 | EXPORT_SYMBOL(ipmi_free_recv_msg); |
4149 | 4173 | ||
4150 | #ifdef CONFIG_IPMI_PANIC_EVENT | 4174 | #ifdef CONFIG_IPMI_PANIC_EVENT |
4151 | 4175 | ||
4152 | static void dummy_smi_done_handler(struct ipmi_smi_msg *msg) | 4176 | static void dummy_smi_done_handler(struct ipmi_smi_msg *msg) |
4153 | { | 4177 | { |
4154 | } | 4178 | } |
4155 | 4179 | ||
4156 | static void dummy_recv_done_handler(struct ipmi_recv_msg *msg) | 4180 | static void dummy_recv_done_handler(struct ipmi_recv_msg *msg) |
4157 | { | 4181 | { |
4158 | } | 4182 | } |
4159 | 4183 | ||
4160 | #ifdef CONFIG_IPMI_PANIC_STRING | 4184 | #ifdef CONFIG_IPMI_PANIC_STRING |
4161 | static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg) | 4185 | static void event_receiver_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
4162 | { | 4186 | { |
4163 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) | 4187 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
4164 | && (msg->msg.netfn == IPMI_NETFN_SENSOR_EVENT_RESPONSE) | 4188 | && (msg->msg.netfn == IPMI_NETFN_SENSOR_EVENT_RESPONSE) |
4165 | && (msg->msg.cmd == IPMI_GET_EVENT_RECEIVER_CMD) | 4189 | && (msg->msg.cmd == IPMI_GET_EVENT_RECEIVER_CMD) |
4166 | && (msg->msg.data[0] == IPMI_CC_NO_ERROR)) { | 4190 | && (msg->msg.data[0] == IPMI_CC_NO_ERROR)) { |
4167 | /* A get event receiver command, save it. */ | 4191 | /* A get event receiver command, save it. */ |
4168 | intf->event_receiver = msg->msg.data[1]; | 4192 | intf->event_receiver = msg->msg.data[1]; |
4169 | intf->event_receiver_lun = msg->msg.data[2] & 0x3; | 4193 | intf->event_receiver_lun = msg->msg.data[2] & 0x3; |
4170 | } | 4194 | } |
4171 | } | 4195 | } |
4172 | 4196 | ||
4173 | static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg) | 4197 | static void device_id_fetcher(ipmi_smi_t intf, struct ipmi_recv_msg *msg) |
4174 | { | 4198 | { |
4175 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) | 4199 | if ((msg->addr.addr_type == IPMI_SYSTEM_INTERFACE_ADDR_TYPE) |
4176 | && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE) | 4200 | && (msg->msg.netfn == IPMI_NETFN_APP_RESPONSE) |
4177 | && (msg->msg.cmd == IPMI_GET_DEVICE_ID_CMD) | 4201 | && (msg->msg.cmd == IPMI_GET_DEVICE_ID_CMD) |
4178 | && (msg->msg.data[0] == IPMI_CC_NO_ERROR)) { | 4202 | && (msg->msg.data[0] == IPMI_CC_NO_ERROR)) { |
4179 | /* | 4203 | /* |
4180 | * A get device id command, save if we are an event | 4204 | * A get device id command, save if we are an event |
4181 | * receiver or generator. | 4205 | * receiver or generator. |
4182 | */ | 4206 | */ |
4183 | intf->local_sel_device = (msg->msg.data[6] >> 2) & 1; | 4207 | intf->local_sel_device = (msg->msg.data[6] >> 2) & 1; |
4184 | intf->local_event_generator = (msg->msg.data[6] >> 5) & 1; | 4208 | intf->local_event_generator = (msg->msg.data[6] >> 5) & 1; |
4185 | } | 4209 | } |
4186 | } | 4210 | } |
4187 | #endif | 4211 | #endif |
4188 | 4212 | ||
4189 | static void send_panic_events(char *str) | 4213 | static void send_panic_events(char *str) |
4190 | { | 4214 | { |
4191 | struct kernel_ipmi_msg msg; | 4215 | struct kernel_ipmi_msg msg; |
4192 | ipmi_smi_t intf; | 4216 | ipmi_smi_t intf; |
4193 | unsigned char data[16]; | 4217 | unsigned char data[16]; |
4194 | struct ipmi_system_interface_addr *si; | 4218 | struct ipmi_system_interface_addr *si; |
4195 | struct ipmi_addr addr; | 4219 | struct ipmi_addr addr; |
4196 | struct ipmi_smi_msg smi_msg; | 4220 | struct ipmi_smi_msg smi_msg; |
4197 | struct ipmi_recv_msg recv_msg; | 4221 | struct ipmi_recv_msg recv_msg; |
4198 | 4222 | ||
4199 | si = (struct ipmi_system_interface_addr *) &addr; | 4223 | si = (struct ipmi_system_interface_addr *) &addr; |
4200 | si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | 4224 | si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
4201 | si->channel = IPMI_BMC_CHANNEL; | 4225 | si->channel = IPMI_BMC_CHANNEL; |
4202 | si->lun = 0; | 4226 | si->lun = 0; |
4203 | 4227 | ||
4204 | /* Fill in an event telling that we have failed. */ | 4228 | /* Fill in an event telling that we have failed. */ |
4205 | msg.netfn = 0x04; /* Sensor or Event. */ | 4229 | msg.netfn = 0x04; /* Sensor or Event. */ |
4206 | msg.cmd = 2; /* Platform event command. */ | 4230 | msg.cmd = 2; /* Platform event command. */ |
4207 | msg.data = data; | 4231 | msg.data = data; |
4208 | msg.data_len = 8; | 4232 | msg.data_len = 8; |
4209 | data[0] = 0x41; /* Kernel generator ID, IPMI table 5-4 */ | 4233 | data[0] = 0x41; /* Kernel generator ID, IPMI table 5-4 */ |
4210 | data[1] = 0x03; /* This is for IPMI 1.0. */ | 4234 | data[1] = 0x03; /* This is for IPMI 1.0. */ |
4211 | data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */ | 4235 | data[2] = 0x20; /* OS Critical Stop, IPMI table 36-3 */ |
4212 | data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */ | 4236 | data[4] = 0x6f; /* Sensor specific, IPMI table 36-1 */ |
4213 | data[5] = 0xa1; /* Runtime stop OEM bytes 2 & 3. */ | 4237 | data[5] = 0xa1; /* Runtime stop OEM bytes 2 & 3. */ |
4214 | 4238 | ||
4215 | /* | 4239 | /* |
4216 | * Put a few breadcrumbs in. Hopefully later we can add more things | 4240 | * Put a few breadcrumbs in. Hopefully later we can add more things |
4217 | * to make the panic events more useful. | 4241 | * to make the panic events more useful. |
4218 | */ | 4242 | */ |
4219 | if (str) { | 4243 | if (str) { |
4220 | data[3] = str[0]; | 4244 | data[3] = str[0]; |
4221 | data[6] = str[1]; | 4245 | data[6] = str[1]; |
4222 | data[7] = str[2]; | 4246 | data[7] = str[2]; |
4223 | } | 4247 | } |
4224 | 4248 | ||
4225 | smi_msg.done = dummy_smi_done_handler; | 4249 | smi_msg.done = dummy_smi_done_handler; |
4226 | recv_msg.done = dummy_recv_done_handler; | 4250 | recv_msg.done = dummy_recv_done_handler; |
4227 | 4251 | ||
4228 | /* For every registered interface, send the event. */ | 4252 | /* For every registered interface, send the event. */ |
4229 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { | 4253 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
4230 | if (!intf->handlers) | 4254 | if (!intf->handlers) |
4231 | /* Interface is not ready. */ | 4255 | /* Interface is not ready. */ |
4232 | continue; | 4256 | continue; |
4233 | 4257 | ||
4234 | intf->run_to_completion = 1; | 4258 | intf->run_to_completion = 1; |
4235 | /* Send the event announcing the panic. */ | 4259 | /* Send the event announcing the panic. */ |
4236 | intf->handlers->set_run_to_completion(intf->send_info, 1); | 4260 | intf->handlers->set_run_to_completion(intf->send_info, 1); |
4237 | i_ipmi_request(NULL, | 4261 | i_ipmi_request(NULL, |
4238 | intf, | 4262 | intf, |
4239 | &addr, | 4263 | &addr, |
4240 | 0, | 4264 | 0, |
4241 | &msg, | 4265 | &msg, |
4242 | intf, | 4266 | intf, |
4243 | &smi_msg, | 4267 | &smi_msg, |
4244 | &recv_msg, | 4268 | &recv_msg, |
4245 | 0, | 4269 | 0, |
4246 | intf->channels[0].address, | 4270 | intf->channels[0].address, |
4247 | intf->channels[0].lun, | 4271 | intf->channels[0].lun, |
4248 | 0, 1); /* Don't retry, and don't wait. */ | 4272 | 0, 1); /* Don't retry, and don't wait. */ |
4249 | } | 4273 | } |
4250 | 4274 | ||
4251 | #ifdef CONFIG_IPMI_PANIC_STRING | 4275 | #ifdef CONFIG_IPMI_PANIC_STRING |
4252 | /* | 4276 | /* |
4253 | * On every interface, dump a bunch of OEM event holding the | 4277 | * On every interface, dump a bunch of OEM event holding the |
4254 | * string. | 4278 | * string. |
4255 | */ | 4279 | */ |
4256 | if (!str) | 4280 | if (!str) |
4257 | return; | 4281 | return; |
4258 | 4282 | ||
4259 | /* For every registered interface, send the event. */ | 4283 | /* For every registered interface, send the event. */ |
4260 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { | 4284 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
4261 | char *p = str; | 4285 | char *p = str; |
4262 | struct ipmi_ipmb_addr *ipmb; | 4286 | struct ipmi_ipmb_addr *ipmb; |
4263 | int j; | 4287 | int j; |
4264 | 4288 | ||
4265 | if (intf->intf_num == -1) | 4289 | if (intf->intf_num == -1) |
4266 | /* Interface was not ready yet. */ | 4290 | /* Interface was not ready yet. */ |
4267 | continue; | 4291 | continue; |
4268 | 4292 | ||
4269 | /* | 4293 | /* |
4270 | * intf_num is used as an marker to tell if the | 4294 | * intf_num is used as an marker to tell if the |
4271 | * interface is valid. Thus we need a read barrier to | 4295 | * interface is valid. Thus we need a read barrier to |
4272 | * make sure data fetched before checking intf_num | 4296 | * make sure data fetched before checking intf_num |
4273 | * won't be used. | 4297 | * won't be used. |
4274 | */ | 4298 | */ |
4275 | smp_rmb(); | 4299 | smp_rmb(); |
4276 | 4300 | ||
4277 | /* | 4301 | /* |
4278 | * First job here is to figure out where to send the | 4302 | * First job here is to figure out where to send the |
4279 | * OEM events. There's no way in IPMI to send OEM | 4303 | * OEM events. There's no way in IPMI to send OEM |
4280 | * events using an event send command, so we have to | 4304 | * events using an event send command, so we have to |
4281 | * find the SEL to put them in and stick them in | 4305 | * find the SEL to put them in and stick them in |
4282 | * there. | 4306 | * there. |
4283 | */ | 4307 | */ |
4284 | 4308 | ||
4285 | /* Get capabilities from the get device id. */ | 4309 | /* Get capabilities from the get device id. */ |
4286 | intf->local_sel_device = 0; | 4310 | intf->local_sel_device = 0; |
4287 | intf->local_event_generator = 0; | 4311 | intf->local_event_generator = 0; |
4288 | intf->event_receiver = 0; | 4312 | intf->event_receiver = 0; |
4289 | 4313 | ||
4290 | /* Request the device info from the local MC. */ | 4314 | /* Request the device info from the local MC. */ |
4291 | msg.netfn = IPMI_NETFN_APP_REQUEST; | 4315 | msg.netfn = IPMI_NETFN_APP_REQUEST; |
4292 | msg.cmd = IPMI_GET_DEVICE_ID_CMD; | 4316 | msg.cmd = IPMI_GET_DEVICE_ID_CMD; |
4293 | msg.data = NULL; | 4317 | msg.data = NULL; |
4294 | msg.data_len = 0; | 4318 | msg.data_len = 0; |
4295 | intf->null_user_handler = device_id_fetcher; | 4319 | intf->null_user_handler = device_id_fetcher; |
4296 | i_ipmi_request(NULL, | 4320 | i_ipmi_request(NULL, |
4297 | intf, | 4321 | intf, |
4298 | &addr, | 4322 | &addr, |
4299 | 0, | 4323 | 0, |
4300 | &msg, | 4324 | &msg, |
4301 | intf, | 4325 | intf, |
4302 | &smi_msg, | 4326 | &smi_msg, |
4303 | &recv_msg, | 4327 | &recv_msg, |
4304 | 0, | 4328 | 0, |
4305 | intf->channels[0].address, | 4329 | intf->channels[0].address, |
4306 | intf->channels[0].lun, | 4330 | intf->channels[0].lun, |
4307 | 0, 1); /* Don't retry, and don't wait. */ | 4331 | 0, 1); /* Don't retry, and don't wait. */ |
4308 | 4332 | ||
4309 | if (intf->local_event_generator) { | 4333 | if (intf->local_event_generator) { |
4310 | /* Request the event receiver from the local MC. */ | 4334 | /* Request the event receiver from the local MC. */ |
4311 | msg.netfn = IPMI_NETFN_SENSOR_EVENT_REQUEST; | 4335 | msg.netfn = IPMI_NETFN_SENSOR_EVENT_REQUEST; |
4312 | msg.cmd = IPMI_GET_EVENT_RECEIVER_CMD; | 4336 | msg.cmd = IPMI_GET_EVENT_RECEIVER_CMD; |
4313 | msg.data = NULL; | 4337 | msg.data = NULL; |
4314 | msg.data_len = 0; | 4338 | msg.data_len = 0; |
4315 | intf->null_user_handler = event_receiver_fetcher; | 4339 | intf->null_user_handler = event_receiver_fetcher; |
4316 | i_ipmi_request(NULL, | 4340 | i_ipmi_request(NULL, |
4317 | intf, | 4341 | intf, |
4318 | &addr, | 4342 | &addr, |
4319 | 0, | 4343 | 0, |
4320 | &msg, | 4344 | &msg, |
4321 | intf, | 4345 | intf, |
4322 | &smi_msg, | 4346 | &smi_msg, |
4323 | &recv_msg, | 4347 | &recv_msg, |
4324 | 0, | 4348 | 0, |
4325 | intf->channels[0].address, | 4349 | intf->channels[0].address, |
4326 | intf->channels[0].lun, | 4350 | intf->channels[0].lun, |
4327 | 0, 1); /* no retry, and no wait. */ | 4351 | 0, 1); /* no retry, and no wait. */ |
4328 | } | 4352 | } |
4329 | intf->null_user_handler = NULL; | 4353 | intf->null_user_handler = NULL; |
4330 | 4354 | ||
4331 | /* | 4355 | /* |
4332 | * Validate the event receiver. The low bit must not | 4356 | * Validate the event receiver. The low bit must not |
4333 | * be 1 (it must be a valid IPMB address), it cannot | 4357 | * be 1 (it must be a valid IPMB address), it cannot |
4334 | * be zero, and it must not be my address. | 4358 | * be zero, and it must not be my address. |
4335 | */ | 4359 | */ |
4336 | if (((intf->event_receiver & 1) == 0) | 4360 | if (((intf->event_receiver & 1) == 0) |
4337 | && (intf->event_receiver != 0) | 4361 | && (intf->event_receiver != 0) |
4338 | && (intf->event_receiver != intf->channels[0].address)) { | 4362 | && (intf->event_receiver != intf->channels[0].address)) { |
4339 | /* | 4363 | /* |
4340 | * The event receiver is valid, send an IPMB | 4364 | * The event receiver is valid, send an IPMB |
4341 | * message. | 4365 | * message. |
4342 | */ | 4366 | */ |
4343 | ipmb = (struct ipmi_ipmb_addr *) &addr; | 4367 | ipmb = (struct ipmi_ipmb_addr *) &addr; |
4344 | ipmb->addr_type = IPMI_IPMB_ADDR_TYPE; | 4368 | ipmb->addr_type = IPMI_IPMB_ADDR_TYPE; |
4345 | ipmb->channel = 0; /* FIXME - is this right? */ | 4369 | ipmb->channel = 0; /* FIXME - is this right? */ |
4346 | ipmb->lun = intf->event_receiver_lun; | 4370 | ipmb->lun = intf->event_receiver_lun; |
4347 | ipmb->slave_addr = intf->event_receiver; | 4371 | ipmb->slave_addr = intf->event_receiver; |
4348 | } else if (intf->local_sel_device) { | 4372 | } else if (intf->local_sel_device) { |
4349 | /* | 4373 | /* |
4350 | * The event receiver was not valid (or was | 4374 | * The event receiver was not valid (or was |
4351 | * me), but I am an SEL device, just dump it | 4375 | * me), but I am an SEL device, just dump it |
4352 | * in my SEL. | 4376 | * in my SEL. |
4353 | */ | 4377 | */ |
4354 | si = (struct ipmi_system_interface_addr *) &addr; | 4378 | si = (struct ipmi_system_interface_addr *) &addr; |
4355 | si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; | 4379 | si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE; |
4356 | si->channel = IPMI_BMC_CHANNEL; | 4380 | si->channel = IPMI_BMC_CHANNEL; |
4357 | si->lun = 0; | 4381 | si->lun = 0; |
4358 | } else | 4382 | } else |
4359 | continue; /* No where to send the event. */ | 4383 | continue; /* No where to send the event. */ |
4360 | 4384 | ||
4361 | msg.netfn = IPMI_NETFN_STORAGE_REQUEST; /* Storage. */ | 4385 | msg.netfn = IPMI_NETFN_STORAGE_REQUEST; /* Storage. */ |
4362 | msg.cmd = IPMI_ADD_SEL_ENTRY_CMD; | 4386 | msg.cmd = IPMI_ADD_SEL_ENTRY_CMD; |
4363 | msg.data = data; | 4387 | msg.data = data; |
4364 | msg.data_len = 16; | 4388 | msg.data_len = 16; |
4365 | 4389 | ||
4366 | j = 0; | 4390 | j = 0; |
4367 | while (*p) { | 4391 | while (*p) { |
4368 | int size = strlen(p); | 4392 | int size = strlen(p); |
4369 | 4393 | ||
4370 | if (size > 11) | 4394 | if (size > 11) |
4371 | size = 11; | 4395 | size = 11; |
4372 | data[0] = 0; | 4396 | data[0] = 0; |
4373 | data[1] = 0; | 4397 | data[1] = 0; |
4374 | data[2] = 0xf0; /* OEM event without timestamp. */ | 4398 | data[2] = 0xf0; /* OEM event without timestamp. */ |
4375 | data[3] = intf->channels[0].address; | 4399 | data[3] = intf->channels[0].address; |
4376 | data[4] = j++; /* sequence # */ | 4400 | data[4] = j++; /* sequence # */ |
4377 | /* | 4401 | /* |
4378 | * Always give 11 bytes, so strncpy will fill | 4402 | * Always give 11 bytes, so strncpy will fill |
4379 | * it with zeroes for me. | 4403 | * it with zeroes for me. |
4380 | */ | 4404 | */ |
4381 | strncpy(data+5, p, 11); | 4405 | strncpy(data+5, p, 11); |
4382 | p += size; | 4406 | p += size; |
4383 | 4407 | ||
4384 | i_ipmi_request(NULL, | 4408 | i_ipmi_request(NULL, |
4385 | intf, | 4409 | intf, |
4386 | &addr, | 4410 | &addr, |
4387 | 0, | 4411 | 0, |
4388 | &msg, | 4412 | &msg, |
4389 | intf, | 4413 | intf, |
4390 | &smi_msg, | 4414 | &smi_msg, |
4391 | &recv_msg, | 4415 | &recv_msg, |
4392 | 0, | 4416 | 0, |
4393 | intf->channels[0].address, | 4417 | intf->channels[0].address, |
4394 | intf->channels[0].lun, | 4418 | intf->channels[0].lun, |
4395 | 0, 1); /* no retry, and no wait. */ | 4419 | 0, 1); /* no retry, and no wait. */ |
4396 | } | 4420 | } |
4397 | } | 4421 | } |
4398 | #endif /* CONFIG_IPMI_PANIC_STRING */ | 4422 | #endif /* CONFIG_IPMI_PANIC_STRING */ |
4399 | } | 4423 | } |
4400 | #endif /* CONFIG_IPMI_PANIC_EVENT */ | 4424 | #endif /* CONFIG_IPMI_PANIC_EVENT */ |
4401 | 4425 | ||
4402 | static int has_panicked; | 4426 | static int has_panicked; |
4403 | 4427 | ||
4404 | static int panic_event(struct notifier_block *this, | 4428 | static int panic_event(struct notifier_block *this, |
4405 | unsigned long event, | 4429 | unsigned long event, |
4406 | void *ptr) | 4430 | void *ptr) |
4407 | { | 4431 | { |
4408 | ipmi_smi_t intf; | 4432 | ipmi_smi_t intf; |
4409 | 4433 | ||
4410 | if (has_panicked) | 4434 | if (has_panicked) |
4411 | return NOTIFY_DONE; | 4435 | return NOTIFY_DONE; |
4412 | has_panicked = 1; | 4436 | has_panicked = 1; |
4413 | 4437 | ||
4414 | /* For every registered interface, set it to run to completion. */ | 4438 | /* For every registered interface, set it to run to completion. */ |
4415 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { | 4439 | list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { |
4416 | if (!intf->handlers) | 4440 | if (!intf->handlers) |
4417 | /* Interface is not ready. */ | 4441 | /* Interface is not ready. */ |
4418 | continue; | 4442 | continue; |
4419 | 4443 | ||
4420 | intf->run_to_completion = 1; | 4444 | intf->run_to_completion = 1; |
4421 | intf->handlers->set_run_to_completion(intf->send_info, 1); | 4445 | intf->handlers->set_run_to_completion(intf->send_info, 1); |
4422 | } | 4446 | } |
4423 | 4447 | ||
4424 | #ifdef CONFIG_IPMI_PANIC_EVENT | 4448 | #ifdef CONFIG_IPMI_PANIC_EVENT |
4425 | send_panic_events(ptr); | 4449 | send_panic_events(ptr); |
4426 | #endif | 4450 | #endif |
4427 | 4451 | ||
4428 | return NOTIFY_DONE; | 4452 | return NOTIFY_DONE; |
4429 | } | 4453 | } |
4430 | 4454 | ||
4431 | static struct notifier_block panic_block = { | 4455 | static struct notifier_block panic_block = { |
4432 | .notifier_call = panic_event, | 4456 | .notifier_call = panic_event, |
4433 | .next = NULL, | 4457 | .next = NULL, |
4434 | .priority = 200 /* priority: INT_MAX >= x >= 0 */ | 4458 | .priority = 200 /* priority: INT_MAX >= x >= 0 */ |
4435 | }; | 4459 | }; |
4436 | 4460 | ||
4437 | static int ipmi_init_msghandler(void) | 4461 | static int ipmi_init_msghandler(void) |
4438 | { | 4462 | { |
4439 | int rv; | 4463 | int rv; |
4440 | 4464 | ||
4441 | if (initialized) | 4465 | if (initialized) |
4442 | return 0; | 4466 | return 0; |
4443 | 4467 | ||
4444 | rv = driver_register(&ipmidriver.driver); | 4468 | rv = driver_register(&ipmidriver.driver); |
4445 | if (rv) { | 4469 | if (rv) { |
4446 | printk(KERN_ERR PFX "Could not register IPMI driver\n"); | 4470 | printk(KERN_ERR PFX "Could not register IPMI driver\n"); |
4447 | return rv; | 4471 | return rv; |
4448 | } | 4472 | } |
4449 | 4473 | ||
4450 | printk(KERN_INFO "ipmi message handler version " | 4474 | printk(KERN_INFO "ipmi message handler version " |
4451 | IPMI_DRIVER_VERSION "\n"); | 4475 | IPMI_DRIVER_VERSION "\n"); |
4452 | 4476 | ||
4453 | #ifdef CONFIG_PROC_FS | 4477 | #ifdef CONFIG_PROC_FS |
4454 | proc_ipmi_root = proc_mkdir("ipmi", NULL); | 4478 | proc_ipmi_root = proc_mkdir("ipmi", NULL); |
4455 | if (!proc_ipmi_root) { | 4479 | if (!proc_ipmi_root) { |
4456 | printk(KERN_ERR PFX "Unable to create IPMI proc dir"); | 4480 | printk(KERN_ERR PFX "Unable to create IPMI proc dir"); |
4457 | return -ENOMEM; | 4481 | return -ENOMEM; |
4458 | } | 4482 | } |
4459 | 4483 | ||
4460 | #endif /* CONFIG_PROC_FS */ | 4484 | #endif /* CONFIG_PROC_FS */ |
4461 | 4485 | ||
4462 | setup_timer(&ipmi_timer, ipmi_timeout, 0); | 4486 | setup_timer(&ipmi_timer, ipmi_timeout, 0); |
4463 | mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); | 4487 | mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES); |
4464 | 4488 | ||
4465 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); | 4489 | atomic_notifier_chain_register(&panic_notifier_list, &panic_block); |
4466 | 4490 | ||
4467 | initialized = 1; | 4491 | initialized = 1; |
4468 | 4492 | ||
4469 | return 0; | 4493 | return 0; |
4470 | } | 4494 | } |
4471 | 4495 | ||
4472 | static int __init ipmi_init_msghandler_mod(void) | 4496 | static int __init ipmi_init_msghandler_mod(void) |
4473 | { | 4497 | { |
4474 | ipmi_init_msghandler(); | 4498 | ipmi_init_msghandler(); |
4475 | return 0; | 4499 | return 0; |
4476 | } | 4500 | } |
4477 | 4501 | ||
4478 | static void __exit cleanup_ipmi(void) | 4502 | static void __exit cleanup_ipmi(void) |
4479 | { | 4503 | { |
4480 | int count; | 4504 | int count; |
4481 | 4505 | ||
4482 | if (!initialized) | 4506 | if (!initialized) |
4483 | return; | 4507 | return; |
4484 | 4508 | ||
4485 | atomic_notifier_chain_unregister(&panic_notifier_list, &panic_block); | 4509 | atomic_notifier_chain_unregister(&panic_notifier_list, &panic_block); |
4486 | 4510 | ||
4487 | /* | 4511 | /* |
4488 | * This can't be called if any interfaces exist, so no worry | 4512 | * This can't be called if any interfaces exist, so no worry |
4489 | * about shutting down the interfaces. | 4513 | * about shutting down the interfaces. |
4490 | */ | 4514 | */ |
4491 | 4515 | ||
4492 | /* | 4516 | /* |
4493 | * Tell the timer to stop, then wait for it to stop. This | 4517 | * Tell the timer to stop, then wait for it to stop. This |
4494 | * avoids problems with race conditions removing the timer | 4518 | * avoids problems with race conditions removing the timer |
4495 | * here. | 4519 | * here. |
4496 | */ | 4520 | */ |
4497 | atomic_inc(&stop_operation); | 4521 | atomic_inc(&stop_operation); |
4498 | del_timer_sync(&ipmi_timer); | 4522 | del_timer_sync(&ipmi_timer); |
4499 | 4523 | ||
4500 | #ifdef CONFIG_PROC_FS | 4524 | #ifdef CONFIG_PROC_FS |
4501 | remove_proc_entry(proc_ipmi_root->name, NULL); | 4525 | remove_proc_entry(proc_ipmi_root->name, NULL); |
4502 | #endif /* CONFIG_PROC_FS */ | 4526 | #endif /* CONFIG_PROC_FS */ |
4503 | 4527 | ||
4504 | driver_unregister(&ipmidriver.driver); | 4528 | driver_unregister(&ipmidriver.driver); |
4505 | 4529 | ||
4506 | initialized = 0; | 4530 | initialized = 0; |
4507 | 4531 | ||
4508 | /* Check for buffer leaks. */ | 4532 | /* Check for buffer leaks. */ |
4509 | count = atomic_read(&smi_msg_inuse_count); | 4533 | count = atomic_read(&smi_msg_inuse_count); |
4510 | if (count != 0) | 4534 | if (count != 0) |
4511 | printk(KERN_WARNING PFX "SMI message count %d at exit\n", | 4535 | printk(KERN_WARNING PFX "SMI message count %d at exit\n", |
4512 | count); | 4536 | count); |
4513 | count = atomic_read(&recv_msg_inuse_count); | 4537 | count = atomic_read(&recv_msg_inuse_count); |
4514 | if (count != 0) | 4538 | if (count != 0) |
4515 | printk(KERN_WARNING PFX "recv message count %d at exit\n", | 4539 | printk(KERN_WARNING PFX "recv message count %d at exit\n", |
4516 | count); | 4540 | count); |
drivers/char/ipmi/ipmi_si_intf.c
1 | /* | 1 | /* |
2 | * ipmi_si.c | 2 | * ipmi_si.c |
3 | * | 3 | * |
4 | * The interface to the IPMI driver for the system interfaces (KCS, SMIC, | 4 | * The interface to the IPMI driver for the system interfaces (KCS, SMIC, |
5 | * BT). | 5 | * BT). |
6 | * | 6 | * |
7 | * Author: MontaVista Software, Inc. | 7 | * Author: MontaVista Software, Inc. |
8 | * Corey Minyard <minyard@mvista.com> | 8 | * Corey Minyard <minyard@mvista.com> |
9 | * source@mvista.com | 9 | * source@mvista.com |
10 | * | 10 | * |
11 | * Copyright 2002 MontaVista Software Inc. | 11 | * Copyright 2002 MontaVista Software Inc. |
12 | * Copyright 2006 IBM Corp., Christian Krafft <krafft@de.ibm.com> | 12 | * Copyright 2006 IBM Corp., Christian Krafft <krafft@de.ibm.com> |
13 | * | 13 | * |
14 | * This program is free software; you can redistribute it and/or modify it | 14 | * This program is free software; you can redistribute it and/or modify it |
15 | * under the terms of the GNU General Public License as published by the | 15 | * under the terms of the GNU General Public License as published by the |
16 | * Free Software Foundation; either version 2 of the License, or (at your | 16 | * Free Software Foundation; either version 2 of the License, or (at your |
17 | * option) any later version. | 17 | * option) any later version. |
18 | * | 18 | * |
19 | * | 19 | * |
20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | 20 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 21 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 22 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 23 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
26 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 26 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
27 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | 27 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
28 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | 28 | * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
29 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | * | 30 | * |
31 | * You should have received a copy of the GNU General Public License along | 31 | * You should have received a copy of the GNU General Public License along |
32 | * with this program; if not, write to the Free Software Foundation, Inc., | 32 | * with this program; if not, write to the Free Software Foundation, Inc., |
33 | * 675 Mass Ave, Cambridge, MA 02139, USA. | 33 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
34 | */ | 34 | */ |
35 | 35 | ||
36 | /* | 36 | /* |
37 | * This file holds the "policy" for the interface to the SMI state | 37 | * This file holds the "policy" for the interface to the SMI state |
38 | * machine. It does the configuration, handles timers and interrupts, | 38 | * machine. It does the configuration, handles timers and interrupts, |
39 | * and drives the real SMI state machine. | 39 | * and drives the real SMI state machine. |
40 | */ | 40 | */ |
41 | 41 | ||
42 | #include <linux/module.h> | 42 | #include <linux/module.h> |
43 | #include <linux/moduleparam.h> | 43 | #include <linux/moduleparam.h> |
44 | #include <asm/system.h> | 44 | #include <asm/system.h> |
45 | #include <linux/sched.h> | 45 | #include <linux/sched.h> |
46 | #include <linux/seq_file.h> | ||
46 | #include <linux/timer.h> | 47 | #include <linux/timer.h> |
47 | #include <linux/errno.h> | 48 | #include <linux/errno.h> |
48 | #include <linux/spinlock.h> | 49 | #include <linux/spinlock.h> |
49 | #include <linux/slab.h> | 50 | #include <linux/slab.h> |
50 | #include <linux/delay.h> | 51 | #include <linux/delay.h> |
51 | #include <linux/list.h> | 52 | #include <linux/list.h> |
52 | #include <linux/pci.h> | 53 | #include <linux/pci.h> |
53 | #include <linux/ioport.h> | 54 | #include <linux/ioport.h> |
54 | #include <linux/notifier.h> | 55 | #include <linux/notifier.h> |
55 | #include <linux/mutex.h> | 56 | #include <linux/mutex.h> |
56 | #include <linux/kthread.h> | 57 | #include <linux/kthread.h> |
57 | #include <asm/irq.h> | 58 | #include <asm/irq.h> |
58 | #include <linux/interrupt.h> | 59 | #include <linux/interrupt.h> |
59 | #include <linux/rcupdate.h> | 60 | #include <linux/rcupdate.h> |
60 | #include <linux/ipmi.h> | 61 | #include <linux/ipmi.h> |
61 | #include <linux/ipmi_smi.h> | 62 | #include <linux/ipmi_smi.h> |
62 | #include <asm/io.h> | 63 | #include <asm/io.h> |
63 | #include "ipmi_si_sm.h" | 64 | #include "ipmi_si_sm.h" |
64 | #include <linux/init.h> | 65 | #include <linux/init.h> |
65 | #include <linux/dmi.h> | 66 | #include <linux/dmi.h> |
66 | #include <linux/string.h> | 67 | #include <linux/string.h> |
67 | #include <linux/ctype.h> | 68 | #include <linux/ctype.h> |
68 | #include <linux/pnp.h> | 69 | #include <linux/pnp.h> |
69 | #include <linux/of_device.h> | 70 | #include <linux/of_device.h> |
70 | #include <linux/of_platform.h> | 71 | #include <linux/of_platform.h> |
71 | #include <linux/of_address.h> | 72 | #include <linux/of_address.h> |
72 | #include <linux/of_irq.h> | 73 | #include <linux/of_irq.h> |
73 | 74 | ||
74 | #define PFX "ipmi_si: " | 75 | #define PFX "ipmi_si: " |
75 | 76 | ||
76 | /* Measure times between events in the driver. */ | 77 | /* Measure times between events in the driver. */ |
77 | #undef DEBUG_TIMING | 78 | #undef DEBUG_TIMING |
78 | 79 | ||
79 | /* Call every 10 ms. */ | 80 | /* Call every 10 ms. */ |
80 | #define SI_TIMEOUT_TIME_USEC 10000 | 81 | #define SI_TIMEOUT_TIME_USEC 10000 |
81 | #define SI_USEC_PER_JIFFY (1000000/HZ) | 82 | #define SI_USEC_PER_JIFFY (1000000/HZ) |
82 | #define SI_TIMEOUT_JIFFIES (SI_TIMEOUT_TIME_USEC/SI_USEC_PER_JIFFY) | 83 | #define SI_TIMEOUT_JIFFIES (SI_TIMEOUT_TIME_USEC/SI_USEC_PER_JIFFY) |
83 | #define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a | 84 | #define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a |
84 | short timeout */ | 85 | short timeout */ |
85 | 86 | ||
86 | enum si_intf_state { | 87 | enum si_intf_state { |
87 | SI_NORMAL, | 88 | SI_NORMAL, |
88 | SI_GETTING_FLAGS, | 89 | SI_GETTING_FLAGS, |
89 | SI_GETTING_EVENTS, | 90 | SI_GETTING_EVENTS, |
90 | SI_CLEARING_FLAGS, | 91 | SI_CLEARING_FLAGS, |
91 | SI_CLEARING_FLAGS_THEN_SET_IRQ, | 92 | SI_CLEARING_FLAGS_THEN_SET_IRQ, |
92 | SI_GETTING_MESSAGES, | 93 | SI_GETTING_MESSAGES, |
93 | SI_ENABLE_INTERRUPTS1, | 94 | SI_ENABLE_INTERRUPTS1, |
94 | SI_ENABLE_INTERRUPTS2, | 95 | SI_ENABLE_INTERRUPTS2, |
95 | SI_DISABLE_INTERRUPTS1, | 96 | SI_DISABLE_INTERRUPTS1, |
96 | SI_DISABLE_INTERRUPTS2 | 97 | SI_DISABLE_INTERRUPTS2 |
97 | /* FIXME - add watchdog stuff. */ | 98 | /* FIXME - add watchdog stuff. */ |
98 | }; | 99 | }; |
99 | 100 | ||
100 | /* Some BT-specific defines we need here. */ | 101 | /* Some BT-specific defines we need here. */ |
101 | #define IPMI_BT_INTMASK_REG 2 | 102 | #define IPMI_BT_INTMASK_REG 2 |
102 | #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2 | 103 | #define IPMI_BT_INTMASK_CLEAR_IRQ_BIT 2 |
103 | #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1 | 104 | #define IPMI_BT_INTMASK_ENABLE_IRQ_BIT 1 |
104 | 105 | ||
105 | enum si_type { | 106 | enum si_type { |
106 | SI_KCS, SI_SMIC, SI_BT | 107 | SI_KCS, SI_SMIC, SI_BT |
107 | }; | 108 | }; |
108 | static char *si_to_str[] = { "kcs", "smic", "bt" }; | 109 | static char *si_to_str[] = { "kcs", "smic", "bt" }; |
109 | 110 | ||
110 | static char *ipmi_addr_src_to_str[] = { NULL, "hotmod", "hardcoded", "SPMI", | 111 | static char *ipmi_addr_src_to_str[] = { NULL, "hotmod", "hardcoded", "SPMI", |
111 | "ACPI", "SMBIOS", "PCI", | 112 | "ACPI", "SMBIOS", "PCI", |
112 | "device-tree", "default" }; | 113 | "device-tree", "default" }; |
113 | 114 | ||
114 | #define DEVICE_NAME "ipmi_si" | 115 | #define DEVICE_NAME "ipmi_si" |
115 | 116 | ||
116 | static struct platform_driver ipmi_driver; | 117 | static struct platform_driver ipmi_driver; |
117 | 118 | ||
118 | /* | 119 | /* |
119 | * Indexes into stats[] in smi_info below. | 120 | * Indexes into stats[] in smi_info below. |
120 | */ | 121 | */ |
121 | enum si_stat_indexes { | 122 | enum si_stat_indexes { |
122 | /* | 123 | /* |
123 | * Number of times the driver requested a timer while an operation | 124 | * Number of times the driver requested a timer while an operation |
124 | * was in progress. | 125 | * was in progress. |
125 | */ | 126 | */ |
126 | SI_STAT_short_timeouts = 0, | 127 | SI_STAT_short_timeouts = 0, |
127 | 128 | ||
128 | /* | 129 | /* |
129 | * Number of times the driver requested a timer while nothing was in | 130 | * Number of times the driver requested a timer while nothing was in |
130 | * progress. | 131 | * progress. |
131 | */ | 132 | */ |
132 | SI_STAT_long_timeouts, | 133 | SI_STAT_long_timeouts, |
133 | 134 | ||
134 | /* Number of times the interface was idle while being polled. */ | 135 | /* Number of times the interface was idle while being polled. */ |
135 | SI_STAT_idles, | 136 | SI_STAT_idles, |
136 | 137 | ||
137 | /* Number of interrupts the driver handled. */ | 138 | /* Number of interrupts the driver handled. */ |
138 | SI_STAT_interrupts, | 139 | SI_STAT_interrupts, |
139 | 140 | ||
140 | /* Number of time the driver got an ATTN from the hardware. */ | 141 | /* Number of time the driver got an ATTN from the hardware. */ |
141 | SI_STAT_attentions, | 142 | SI_STAT_attentions, |
142 | 143 | ||
143 | /* Number of times the driver requested flags from the hardware. */ | 144 | /* Number of times the driver requested flags from the hardware. */ |
144 | SI_STAT_flag_fetches, | 145 | SI_STAT_flag_fetches, |
145 | 146 | ||
146 | /* Number of times the hardware didn't follow the state machine. */ | 147 | /* Number of times the hardware didn't follow the state machine. */ |
147 | SI_STAT_hosed_count, | 148 | SI_STAT_hosed_count, |
148 | 149 | ||
149 | /* Number of completed messages. */ | 150 | /* Number of completed messages. */ |
150 | SI_STAT_complete_transactions, | 151 | SI_STAT_complete_transactions, |
151 | 152 | ||
152 | /* Number of IPMI events received from the hardware. */ | 153 | /* Number of IPMI events received from the hardware. */ |
153 | SI_STAT_events, | 154 | SI_STAT_events, |
154 | 155 | ||
155 | /* Number of watchdog pretimeouts. */ | 156 | /* Number of watchdog pretimeouts. */ |
156 | SI_STAT_watchdog_pretimeouts, | 157 | SI_STAT_watchdog_pretimeouts, |
157 | 158 | ||
158 | /* Number of asyncronous messages received. */ | 159 | /* Number of asyncronous messages received. */ |
159 | SI_STAT_incoming_messages, | 160 | SI_STAT_incoming_messages, |
160 | 161 | ||
161 | 162 | ||
162 | /* This *must* remain last, add new values above this. */ | 163 | /* This *must* remain last, add new values above this. */ |
163 | SI_NUM_STATS | 164 | SI_NUM_STATS |
164 | }; | 165 | }; |
165 | 166 | ||
166 | struct smi_info { | 167 | struct smi_info { |
167 | int intf_num; | 168 | int intf_num; |
168 | ipmi_smi_t intf; | 169 | ipmi_smi_t intf; |
169 | struct si_sm_data *si_sm; | 170 | struct si_sm_data *si_sm; |
170 | struct si_sm_handlers *handlers; | 171 | struct si_sm_handlers *handlers; |
171 | enum si_type si_type; | 172 | enum si_type si_type; |
172 | spinlock_t si_lock; | 173 | spinlock_t si_lock; |
173 | spinlock_t msg_lock; | 174 | spinlock_t msg_lock; |
174 | struct list_head xmit_msgs; | 175 | struct list_head xmit_msgs; |
175 | struct list_head hp_xmit_msgs; | 176 | struct list_head hp_xmit_msgs; |
176 | struct ipmi_smi_msg *curr_msg; | 177 | struct ipmi_smi_msg *curr_msg; |
177 | enum si_intf_state si_state; | 178 | enum si_intf_state si_state; |
178 | 179 | ||
179 | /* | 180 | /* |
180 | * Used to handle the various types of I/O that can occur with | 181 | * Used to handle the various types of I/O that can occur with |
181 | * IPMI | 182 | * IPMI |
182 | */ | 183 | */ |
183 | struct si_sm_io io; | 184 | struct si_sm_io io; |
184 | int (*io_setup)(struct smi_info *info); | 185 | int (*io_setup)(struct smi_info *info); |
185 | void (*io_cleanup)(struct smi_info *info); | 186 | void (*io_cleanup)(struct smi_info *info); |
186 | int (*irq_setup)(struct smi_info *info); | 187 | int (*irq_setup)(struct smi_info *info); |
187 | void (*irq_cleanup)(struct smi_info *info); | 188 | void (*irq_cleanup)(struct smi_info *info); |
188 | unsigned int io_size; | 189 | unsigned int io_size; |
189 | enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */ | 190 | enum ipmi_addr_src addr_source; /* ACPI, PCI, SMBIOS, hardcode, etc. */ |
190 | void (*addr_source_cleanup)(struct smi_info *info); | 191 | void (*addr_source_cleanup)(struct smi_info *info); |
191 | void *addr_source_data; | 192 | void *addr_source_data; |
192 | 193 | ||
193 | /* | 194 | /* |
194 | * Per-OEM handler, called from handle_flags(). Returns 1 | 195 | * Per-OEM handler, called from handle_flags(). Returns 1 |
195 | * when handle_flags() needs to be re-run or 0 indicating it | 196 | * when handle_flags() needs to be re-run or 0 indicating it |
196 | * set si_state itself. | 197 | * set si_state itself. |
197 | */ | 198 | */ |
198 | int (*oem_data_avail_handler)(struct smi_info *smi_info); | 199 | int (*oem_data_avail_handler)(struct smi_info *smi_info); |
199 | 200 | ||
200 | /* | 201 | /* |
201 | * Flags from the last GET_MSG_FLAGS command, used when an ATTN | 202 | * Flags from the last GET_MSG_FLAGS command, used when an ATTN |
202 | * is set to hold the flags until we are done handling everything | 203 | * is set to hold the flags until we are done handling everything |
203 | * from the flags. | 204 | * from the flags. |
204 | */ | 205 | */ |
205 | #define RECEIVE_MSG_AVAIL 0x01 | 206 | #define RECEIVE_MSG_AVAIL 0x01 |
206 | #define EVENT_MSG_BUFFER_FULL 0x02 | 207 | #define EVENT_MSG_BUFFER_FULL 0x02 |
207 | #define WDT_PRE_TIMEOUT_INT 0x08 | 208 | #define WDT_PRE_TIMEOUT_INT 0x08 |
208 | #define OEM0_DATA_AVAIL 0x20 | 209 | #define OEM0_DATA_AVAIL 0x20 |
209 | #define OEM1_DATA_AVAIL 0x40 | 210 | #define OEM1_DATA_AVAIL 0x40 |
210 | #define OEM2_DATA_AVAIL 0x80 | 211 | #define OEM2_DATA_AVAIL 0x80 |
211 | #define OEM_DATA_AVAIL (OEM0_DATA_AVAIL | \ | 212 | #define OEM_DATA_AVAIL (OEM0_DATA_AVAIL | \ |
212 | OEM1_DATA_AVAIL | \ | 213 | OEM1_DATA_AVAIL | \ |
213 | OEM2_DATA_AVAIL) | 214 | OEM2_DATA_AVAIL) |
214 | unsigned char msg_flags; | 215 | unsigned char msg_flags; |
215 | 216 | ||
216 | /* Does the BMC have an event buffer? */ | 217 | /* Does the BMC have an event buffer? */ |
217 | char has_event_buffer; | 218 | char has_event_buffer; |
218 | 219 | ||
219 | /* | 220 | /* |
220 | * If set to true, this will request events the next time the | 221 | * If set to true, this will request events the next time the |
221 | * state machine is idle. | 222 | * state machine is idle. |
222 | */ | 223 | */ |
223 | atomic_t req_events; | 224 | atomic_t req_events; |
224 | 225 | ||
225 | /* | 226 | /* |
226 | * If true, run the state machine to completion on every send | 227 | * If true, run the state machine to completion on every send |
227 | * call. Generally used after a panic to make sure stuff goes | 228 | * call. Generally used after a panic to make sure stuff goes |
228 | * out. | 229 | * out. |
229 | */ | 230 | */ |
230 | int run_to_completion; | 231 | int run_to_completion; |
231 | 232 | ||
232 | /* The I/O port of an SI interface. */ | 233 | /* The I/O port of an SI interface. */ |
233 | int port; | 234 | int port; |
234 | 235 | ||
235 | /* | 236 | /* |
236 | * The space between start addresses of the two ports. For | 237 | * The space between start addresses of the two ports. For |
237 | * instance, if the first port is 0xca2 and the spacing is 4, then | 238 | * instance, if the first port is 0xca2 and the spacing is 4, then |
238 | * the second port is 0xca6. | 239 | * the second port is 0xca6. |
239 | */ | 240 | */ |
240 | unsigned int spacing; | 241 | unsigned int spacing; |
241 | 242 | ||
242 | /* zero if no irq; */ | 243 | /* zero if no irq; */ |
243 | int irq; | 244 | int irq; |
244 | 245 | ||
245 | /* The timer for this si. */ | 246 | /* The timer for this si. */ |
246 | struct timer_list si_timer; | 247 | struct timer_list si_timer; |
247 | 248 | ||
248 | /* The time (in jiffies) the last timeout occurred at. */ | 249 | /* The time (in jiffies) the last timeout occurred at. */ |
249 | unsigned long last_timeout_jiffies; | 250 | unsigned long last_timeout_jiffies; |
250 | 251 | ||
251 | /* Used to gracefully stop the timer without race conditions. */ | 252 | /* Used to gracefully stop the timer without race conditions. */ |
252 | atomic_t stop_operation; | 253 | atomic_t stop_operation; |
253 | 254 | ||
254 | /* | 255 | /* |
255 | * The driver will disable interrupts when it gets into a | 256 | * The driver will disable interrupts when it gets into a |
256 | * situation where it cannot handle messages due to lack of | 257 | * situation where it cannot handle messages due to lack of |
257 | * memory. Once that situation clears up, it will re-enable | 258 | * memory. Once that situation clears up, it will re-enable |
258 | * interrupts. | 259 | * interrupts. |
259 | */ | 260 | */ |
260 | int interrupt_disabled; | 261 | int interrupt_disabled; |
261 | 262 | ||
262 | /* From the get device id response... */ | 263 | /* From the get device id response... */ |
263 | struct ipmi_device_id device_id; | 264 | struct ipmi_device_id device_id; |
264 | 265 | ||
265 | /* Driver model stuff. */ | 266 | /* Driver model stuff. */ |
266 | struct device *dev; | 267 | struct device *dev; |
267 | struct platform_device *pdev; | 268 | struct platform_device *pdev; |
268 | 269 | ||
269 | /* | 270 | /* |
270 | * True if we allocated the device, false if it came from | 271 | * True if we allocated the device, false if it came from |
271 | * someplace else (like PCI). | 272 | * someplace else (like PCI). |
272 | */ | 273 | */ |
273 | int dev_registered; | 274 | int dev_registered; |
274 | 275 | ||
275 | /* Slave address, could be reported from DMI. */ | 276 | /* Slave address, could be reported from DMI. */ |
276 | unsigned char slave_addr; | 277 | unsigned char slave_addr; |
277 | 278 | ||
278 | /* Counters and things for the proc filesystem. */ | 279 | /* Counters and things for the proc filesystem. */ |
279 | atomic_t stats[SI_NUM_STATS]; | 280 | atomic_t stats[SI_NUM_STATS]; |
280 | 281 | ||
281 | struct task_struct *thread; | 282 | struct task_struct *thread; |
282 | 283 | ||
283 | struct list_head link; | 284 | struct list_head link; |
284 | union ipmi_smi_info_union addr_info; | 285 | union ipmi_smi_info_union addr_info; |
285 | }; | 286 | }; |
286 | 287 | ||
287 | #define smi_inc_stat(smi, stat) \ | 288 | #define smi_inc_stat(smi, stat) \ |
288 | atomic_inc(&(smi)->stats[SI_STAT_ ## stat]) | 289 | atomic_inc(&(smi)->stats[SI_STAT_ ## stat]) |
289 | #define smi_get_stat(smi, stat) \ | 290 | #define smi_get_stat(smi, stat) \ |
290 | ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat])) | 291 | ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat])) |
291 | 292 | ||
292 | #define SI_MAX_PARMS 4 | 293 | #define SI_MAX_PARMS 4 |
293 | 294 | ||
294 | static int force_kipmid[SI_MAX_PARMS]; | 295 | static int force_kipmid[SI_MAX_PARMS]; |
295 | static int num_force_kipmid; | 296 | static int num_force_kipmid; |
296 | #ifdef CONFIG_PCI | 297 | #ifdef CONFIG_PCI |
297 | static int pci_registered; | 298 | static int pci_registered; |
298 | #endif | 299 | #endif |
299 | #ifdef CONFIG_ACPI | 300 | #ifdef CONFIG_ACPI |
300 | static int pnp_registered; | 301 | static int pnp_registered; |
301 | #endif | 302 | #endif |
302 | 303 | ||
303 | static unsigned int kipmid_max_busy_us[SI_MAX_PARMS]; | 304 | static unsigned int kipmid_max_busy_us[SI_MAX_PARMS]; |
304 | static int num_max_busy_us; | 305 | static int num_max_busy_us; |
305 | 306 | ||
306 | static int unload_when_empty = 1; | 307 | static int unload_when_empty = 1; |
307 | 308 | ||
308 | static int add_smi(struct smi_info *smi); | 309 | static int add_smi(struct smi_info *smi); |
309 | static int try_smi_init(struct smi_info *smi); | 310 | static int try_smi_init(struct smi_info *smi); |
310 | static void cleanup_one_si(struct smi_info *to_clean); | 311 | static void cleanup_one_si(struct smi_info *to_clean); |
311 | static void cleanup_ipmi_si(void); | 312 | static void cleanup_ipmi_si(void); |
312 | 313 | ||
313 | static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list); | 314 | static ATOMIC_NOTIFIER_HEAD(xaction_notifier_list); |
314 | static int register_xaction_notifier(struct notifier_block *nb) | 315 | static int register_xaction_notifier(struct notifier_block *nb) |
315 | { | 316 | { |
316 | return atomic_notifier_chain_register(&xaction_notifier_list, nb); | 317 | return atomic_notifier_chain_register(&xaction_notifier_list, nb); |
317 | } | 318 | } |
318 | 319 | ||
319 | static void deliver_recv_msg(struct smi_info *smi_info, | 320 | static void deliver_recv_msg(struct smi_info *smi_info, |
320 | struct ipmi_smi_msg *msg) | 321 | struct ipmi_smi_msg *msg) |
321 | { | 322 | { |
322 | /* Deliver the message to the upper layer with the lock | 323 | /* Deliver the message to the upper layer with the lock |
323 | released. */ | 324 | released. */ |
324 | 325 | ||
325 | if (smi_info->run_to_completion) { | 326 | if (smi_info->run_to_completion) { |
326 | ipmi_smi_msg_received(smi_info->intf, msg); | 327 | ipmi_smi_msg_received(smi_info->intf, msg); |
327 | } else { | 328 | } else { |
328 | spin_unlock(&(smi_info->si_lock)); | 329 | spin_unlock(&(smi_info->si_lock)); |
329 | ipmi_smi_msg_received(smi_info->intf, msg); | 330 | ipmi_smi_msg_received(smi_info->intf, msg); |
330 | spin_lock(&(smi_info->si_lock)); | 331 | spin_lock(&(smi_info->si_lock)); |
331 | } | 332 | } |
332 | } | 333 | } |
333 | 334 | ||
334 | static void return_hosed_msg(struct smi_info *smi_info, int cCode) | 335 | static void return_hosed_msg(struct smi_info *smi_info, int cCode) |
335 | { | 336 | { |
336 | struct ipmi_smi_msg *msg = smi_info->curr_msg; | 337 | struct ipmi_smi_msg *msg = smi_info->curr_msg; |
337 | 338 | ||
338 | if (cCode < 0 || cCode > IPMI_ERR_UNSPECIFIED) | 339 | if (cCode < 0 || cCode > IPMI_ERR_UNSPECIFIED) |
339 | cCode = IPMI_ERR_UNSPECIFIED; | 340 | cCode = IPMI_ERR_UNSPECIFIED; |
340 | /* else use it as is */ | 341 | /* else use it as is */ |
341 | 342 | ||
342 | /* Make it a response */ | 343 | /* Make it a response */ |
343 | msg->rsp[0] = msg->data[0] | 4; | 344 | msg->rsp[0] = msg->data[0] | 4; |
344 | msg->rsp[1] = msg->data[1]; | 345 | msg->rsp[1] = msg->data[1]; |
345 | msg->rsp[2] = cCode; | 346 | msg->rsp[2] = cCode; |
346 | msg->rsp_size = 3; | 347 | msg->rsp_size = 3; |
347 | 348 | ||
348 | smi_info->curr_msg = NULL; | 349 | smi_info->curr_msg = NULL; |
349 | deliver_recv_msg(smi_info, msg); | 350 | deliver_recv_msg(smi_info, msg); |
350 | } | 351 | } |
351 | 352 | ||
352 | static enum si_sm_result start_next_msg(struct smi_info *smi_info) | 353 | static enum si_sm_result start_next_msg(struct smi_info *smi_info) |
353 | { | 354 | { |
354 | int rv; | 355 | int rv; |
355 | struct list_head *entry = NULL; | 356 | struct list_head *entry = NULL; |
356 | #ifdef DEBUG_TIMING | 357 | #ifdef DEBUG_TIMING |
357 | struct timeval t; | 358 | struct timeval t; |
358 | #endif | 359 | #endif |
359 | 360 | ||
360 | /* | 361 | /* |
361 | * No need to save flags, we aleady have interrupts off and we | 362 | * No need to save flags, we aleady have interrupts off and we |
362 | * already hold the SMI lock. | 363 | * already hold the SMI lock. |
363 | */ | 364 | */ |
364 | if (!smi_info->run_to_completion) | 365 | if (!smi_info->run_to_completion) |
365 | spin_lock(&(smi_info->msg_lock)); | 366 | spin_lock(&(smi_info->msg_lock)); |
366 | 367 | ||
367 | /* Pick the high priority queue first. */ | 368 | /* Pick the high priority queue first. */ |
368 | if (!list_empty(&(smi_info->hp_xmit_msgs))) { | 369 | if (!list_empty(&(smi_info->hp_xmit_msgs))) { |
369 | entry = smi_info->hp_xmit_msgs.next; | 370 | entry = smi_info->hp_xmit_msgs.next; |
370 | } else if (!list_empty(&(smi_info->xmit_msgs))) { | 371 | } else if (!list_empty(&(smi_info->xmit_msgs))) { |
371 | entry = smi_info->xmit_msgs.next; | 372 | entry = smi_info->xmit_msgs.next; |
372 | } | 373 | } |
373 | 374 | ||
374 | if (!entry) { | 375 | if (!entry) { |
375 | smi_info->curr_msg = NULL; | 376 | smi_info->curr_msg = NULL; |
376 | rv = SI_SM_IDLE; | 377 | rv = SI_SM_IDLE; |
377 | } else { | 378 | } else { |
378 | int err; | 379 | int err; |
379 | 380 | ||
380 | list_del(entry); | 381 | list_del(entry); |
381 | smi_info->curr_msg = list_entry(entry, | 382 | smi_info->curr_msg = list_entry(entry, |
382 | struct ipmi_smi_msg, | 383 | struct ipmi_smi_msg, |
383 | link); | 384 | link); |
384 | #ifdef DEBUG_TIMING | 385 | #ifdef DEBUG_TIMING |
385 | do_gettimeofday(&t); | 386 | do_gettimeofday(&t); |
386 | printk(KERN_DEBUG "**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec); | 387 | printk(KERN_DEBUG "**Start2: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
387 | #endif | 388 | #endif |
388 | err = atomic_notifier_call_chain(&xaction_notifier_list, | 389 | err = atomic_notifier_call_chain(&xaction_notifier_list, |
389 | 0, smi_info); | 390 | 0, smi_info); |
390 | if (err & NOTIFY_STOP_MASK) { | 391 | if (err & NOTIFY_STOP_MASK) { |
391 | rv = SI_SM_CALL_WITHOUT_DELAY; | 392 | rv = SI_SM_CALL_WITHOUT_DELAY; |
392 | goto out; | 393 | goto out; |
393 | } | 394 | } |
394 | err = smi_info->handlers->start_transaction( | 395 | err = smi_info->handlers->start_transaction( |
395 | smi_info->si_sm, | 396 | smi_info->si_sm, |
396 | smi_info->curr_msg->data, | 397 | smi_info->curr_msg->data, |
397 | smi_info->curr_msg->data_size); | 398 | smi_info->curr_msg->data_size); |
398 | if (err) | 399 | if (err) |
399 | return_hosed_msg(smi_info, err); | 400 | return_hosed_msg(smi_info, err); |
400 | 401 | ||
401 | rv = SI_SM_CALL_WITHOUT_DELAY; | 402 | rv = SI_SM_CALL_WITHOUT_DELAY; |
402 | } | 403 | } |
403 | out: | 404 | out: |
404 | if (!smi_info->run_to_completion) | 405 | if (!smi_info->run_to_completion) |
405 | spin_unlock(&(smi_info->msg_lock)); | 406 | spin_unlock(&(smi_info->msg_lock)); |
406 | 407 | ||
407 | return rv; | 408 | return rv; |
408 | } | 409 | } |
409 | 410 | ||
410 | static void start_enable_irq(struct smi_info *smi_info) | 411 | static void start_enable_irq(struct smi_info *smi_info) |
411 | { | 412 | { |
412 | unsigned char msg[2]; | 413 | unsigned char msg[2]; |
413 | 414 | ||
414 | /* | 415 | /* |
415 | * If we are enabling interrupts, we have to tell the | 416 | * If we are enabling interrupts, we have to tell the |
416 | * BMC to use them. | 417 | * BMC to use them. |
417 | */ | 418 | */ |
418 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); | 419 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
419 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; | 420 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
420 | 421 | ||
421 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); | 422 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
422 | smi_info->si_state = SI_ENABLE_INTERRUPTS1; | 423 | smi_info->si_state = SI_ENABLE_INTERRUPTS1; |
423 | } | 424 | } |
424 | 425 | ||
425 | static void start_disable_irq(struct smi_info *smi_info) | 426 | static void start_disable_irq(struct smi_info *smi_info) |
426 | { | 427 | { |
427 | unsigned char msg[2]; | 428 | unsigned char msg[2]; |
428 | 429 | ||
429 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); | 430 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
430 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; | 431 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
431 | 432 | ||
432 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); | 433 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
433 | smi_info->si_state = SI_DISABLE_INTERRUPTS1; | 434 | smi_info->si_state = SI_DISABLE_INTERRUPTS1; |
434 | } | 435 | } |
435 | 436 | ||
436 | static void start_clear_flags(struct smi_info *smi_info) | 437 | static void start_clear_flags(struct smi_info *smi_info) |
437 | { | 438 | { |
438 | unsigned char msg[3]; | 439 | unsigned char msg[3]; |
439 | 440 | ||
440 | /* Make sure the watchdog pre-timeout flag is not set at startup. */ | 441 | /* Make sure the watchdog pre-timeout flag is not set at startup. */ |
441 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); | 442 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
442 | msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD; | 443 | msg[1] = IPMI_CLEAR_MSG_FLAGS_CMD; |
443 | msg[2] = WDT_PRE_TIMEOUT_INT; | 444 | msg[2] = WDT_PRE_TIMEOUT_INT; |
444 | 445 | ||
445 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3); | 446 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3); |
446 | smi_info->si_state = SI_CLEARING_FLAGS; | 447 | smi_info->si_state = SI_CLEARING_FLAGS; |
447 | } | 448 | } |
448 | 449 | ||
449 | /* | 450 | /* |
450 | * When we have a situtaion where we run out of memory and cannot | 451 | * When we have a situtaion where we run out of memory and cannot |
451 | * allocate messages, we just leave them in the BMC and run the system | 452 | * allocate messages, we just leave them in the BMC and run the system |
452 | * polled until we can allocate some memory. Once we have some | 453 | * polled until we can allocate some memory. Once we have some |
453 | * memory, we will re-enable the interrupt. | 454 | * memory, we will re-enable the interrupt. |
454 | */ | 455 | */ |
455 | static inline void disable_si_irq(struct smi_info *smi_info) | 456 | static inline void disable_si_irq(struct smi_info *smi_info) |
456 | { | 457 | { |
457 | if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { | 458 | if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { |
458 | start_disable_irq(smi_info); | 459 | start_disable_irq(smi_info); |
459 | smi_info->interrupt_disabled = 1; | 460 | smi_info->interrupt_disabled = 1; |
460 | if (!atomic_read(&smi_info->stop_operation)) | 461 | if (!atomic_read(&smi_info->stop_operation)) |
461 | mod_timer(&smi_info->si_timer, | 462 | mod_timer(&smi_info->si_timer, |
462 | jiffies + SI_TIMEOUT_JIFFIES); | 463 | jiffies + SI_TIMEOUT_JIFFIES); |
463 | } | 464 | } |
464 | } | 465 | } |
465 | 466 | ||
466 | static inline void enable_si_irq(struct smi_info *smi_info) | 467 | static inline void enable_si_irq(struct smi_info *smi_info) |
467 | { | 468 | { |
468 | if ((smi_info->irq) && (smi_info->interrupt_disabled)) { | 469 | if ((smi_info->irq) && (smi_info->interrupt_disabled)) { |
469 | start_enable_irq(smi_info); | 470 | start_enable_irq(smi_info); |
470 | smi_info->interrupt_disabled = 0; | 471 | smi_info->interrupt_disabled = 0; |
471 | } | 472 | } |
472 | } | 473 | } |
473 | 474 | ||
474 | static void handle_flags(struct smi_info *smi_info) | 475 | static void handle_flags(struct smi_info *smi_info) |
475 | { | 476 | { |
476 | retry: | 477 | retry: |
477 | if (smi_info->msg_flags & WDT_PRE_TIMEOUT_INT) { | 478 | if (smi_info->msg_flags & WDT_PRE_TIMEOUT_INT) { |
478 | /* Watchdog pre-timeout */ | 479 | /* Watchdog pre-timeout */ |
479 | smi_inc_stat(smi_info, watchdog_pretimeouts); | 480 | smi_inc_stat(smi_info, watchdog_pretimeouts); |
480 | 481 | ||
481 | start_clear_flags(smi_info); | 482 | start_clear_flags(smi_info); |
482 | smi_info->msg_flags &= ~WDT_PRE_TIMEOUT_INT; | 483 | smi_info->msg_flags &= ~WDT_PRE_TIMEOUT_INT; |
483 | spin_unlock(&(smi_info->si_lock)); | 484 | spin_unlock(&(smi_info->si_lock)); |
484 | ipmi_smi_watchdog_pretimeout(smi_info->intf); | 485 | ipmi_smi_watchdog_pretimeout(smi_info->intf); |
485 | spin_lock(&(smi_info->si_lock)); | 486 | spin_lock(&(smi_info->si_lock)); |
486 | } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) { | 487 | } else if (smi_info->msg_flags & RECEIVE_MSG_AVAIL) { |
487 | /* Messages available. */ | 488 | /* Messages available. */ |
488 | smi_info->curr_msg = ipmi_alloc_smi_msg(); | 489 | smi_info->curr_msg = ipmi_alloc_smi_msg(); |
489 | if (!smi_info->curr_msg) { | 490 | if (!smi_info->curr_msg) { |
490 | disable_si_irq(smi_info); | 491 | disable_si_irq(smi_info); |
491 | smi_info->si_state = SI_NORMAL; | 492 | smi_info->si_state = SI_NORMAL; |
492 | return; | 493 | return; |
493 | } | 494 | } |
494 | enable_si_irq(smi_info); | 495 | enable_si_irq(smi_info); |
495 | 496 | ||
496 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); | 497 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
497 | smi_info->curr_msg->data[1] = IPMI_GET_MSG_CMD; | 498 | smi_info->curr_msg->data[1] = IPMI_GET_MSG_CMD; |
498 | smi_info->curr_msg->data_size = 2; | 499 | smi_info->curr_msg->data_size = 2; |
499 | 500 | ||
500 | smi_info->handlers->start_transaction( | 501 | smi_info->handlers->start_transaction( |
501 | smi_info->si_sm, | 502 | smi_info->si_sm, |
502 | smi_info->curr_msg->data, | 503 | smi_info->curr_msg->data, |
503 | smi_info->curr_msg->data_size); | 504 | smi_info->curr_msg->data_size); |
504 | smi_info->si_state = SI_GETTING_MESSAGES; | 505 | smi_info->si_state = SI_GETTING_MESSAGES; |
505 | } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) { | 506 | } else if (smi_info->msg_flags & EVENT_MSG_BUFFER_FULL) { |
506 | /* Events available. */ | 507 | /* Events available. */ |
507 | smi_info->curr_msg = ipmi_alloc_smi_msg(); | 508 | smi_info->curr_msg = ipmi_alloc_smi_msg(); |
508 | if (!smi_info->curr_msg) { | 509 | if (!smi_info->curr_msg) { |
509 | disable_si_irq(smi_info); | 510 | disable_si_irq(smi_info); |
510 | smi_info->si_state = SI_NORMAL; | 511 | smi_info->si_state = SI_NORMAL; |
511 | return; | 512 | return; |
512 | } | 513 | } |
513 | enable_si_irq(smi_info); | 514 | enable_si_irq(smi_info); |
514 | 515 | ||
515 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); | 516 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
516 | smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD; | 517 | smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD; |
517 | smi_info->curr_msg->data_size = 2; | 518 | smi_info->curr_msg->data_size = 2; |
518 | 519 | ||
519 | smi_info->handlers->start_transaction( | 520 | smi_info->handlers->start_transaction( |
520 | smi_info->si_sm, | 521 | smi_info->si_sm, |
521 | smi_info->curr_msg->data, | 522 | smi_info->curr_msg->data, |
522 | smi_info->curr_msg->data_size); | 523 | smi_info->curr_msg->data_size); |
523 | smi_info->si_state = SI_GETTING_EVENTS; | 524 | smi_info->si_state = SI_GETTING_EVENTS; |
524 | } else if (smi_info->msg_flags & OEM_DATA_AVAIL && | 525 | } else if (smi_info->msg_flags & OEM_DATA_AVAIL && |
525 | smi_info->oem_data_avail_handler) { | 526 | smi_info->oem_data_avail_handler) { |
526 | if (smi_info->oem_data_avail_handler(smi_info)) | 527 | if (smi_info->oem_data_avail_handler(smi_info)) |
527 | goto retry; | 528 | goto retry; |
528 | } else | 529 | } else |
529 | smi_info->si_state = SI_NORMAL; | 530 | smi_info->si_state = SI_NORMAL; |
530 | } | 531 | } |
531 | 532 | ||
532 | static void handle_transaction_done(struct smi_info *smi_info) | 533 | static void handle_transaction_done(struct smi_info *smi_info) |
533 | { | 534 | { |
534 | struct ipmi_smi_msg *msg; | 535 | struct ipmi_smi_msg *msg; |
535 | #ifdef DEBUG_TIMING | 536 | #ifdef DEBUG_TIMING |
536 | struct timeval t; | 537 | struct timeval t; |
537 | 538 | ||
538 | do_gettimeofday(&t); | 539 | do_gettimeofday(&t); |
539 | printk(KERN_DEBUG "**Done: %d.%9.9d\n", t.tv_sec, t.tv_usec); | 540 | printk(KERN_DEBUG "**Done: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
540 | #endif | 541 | #endif |
541 | switch (smi_info->si_state) { | 542 | switch (smi_info->si_state) { |
542 | case SI_NORMAL: | 543 | case SI_NORMAL: |
543 | if (!smi_info->curr_msg) | 544 | if (!smi_info->curr_msg) |
544 | break; | 545 | break; |
545 | 546 | ||
546 | smi_info->curr_msg->rsp_size | 547 | smi_info->curr_msg->rsp_size |
547 | = smi_info->handlers->get_result( | 548 | = smi_info->handlers->get_result( |
548 | smi_info->si_sm, | 549 | smi_info->si_sm, |
549 | smi_info->curr_msg->rsp, | 550 | smi_info->curr_msg->rsp, |
550 | IPMI_MAX_MSG_LENGTH); | 551 | IPMI_MAX_MSG_LENGTH); |
551 | 552 | ||
552 | /* | 553 | /* |
553 | * Do this here becase deliver_recv_msg() releases the | 554 | * Do this here becase deliver_recv_msg() releases the |
554 | * lock, and a new message can be put in during the | 555 | * lock, and a new message can be put in during the |
555 | * time the lock is released. | 556 | * time the lock is released. |
556 | */ | 557 | */ |
557 | msg = smi_info->curr_msg; | 558 | msg = smi_info->curr_msg; |
558 | smi_info->curr_msg = NULL; | 559 | smi_info->curr_msg = NULL; |
559 | deliver_recv_msg(smi_info, msg); | 560 | deliver_recv_msg(smi_info, msg); |
560 | break; | 561 | break; |
561 | 562 | ||
562 | case SI_GETTING_FLAGS: | 563 | case SI_GETTING_FLAGS: |
563 | { | 564 | { |
564 | unsigned char msg[4]; | 565 | unsigned char msg[4]; |
565 | unsigned int len; | 566 | unsigned int len; |
566 | 567 | ||
567 | /* We got the flags from the SMI, now handle them. */ | 568 | /* We got the flags from the SMI, now handle them. */ |
568 | len = smi_info->handlers->get_result(smi_info->si_sm, msg, 4); | 569 | len = smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
569 | if (msg[2] != 0) { | 570 | if (msg[2] != 0) { |
570 | /* Error fetching flags, just give up for now. */ | 571 | /* Error fetching flags, just give up for now. */ |
571 | smi_info->si_state = SI_NORMAL; | 572 | smi_info->si_state = SI_NORMAL; |
572 | } else if (len < 4) { | 573 | } else if (len < 4) { |
573 | /* | 574 | /* |
574 | * Hmm, no flags. That's technically illegal, but | 575 | * Hmm, no flags. That's technically illegal, but |
575 | * don't use uninitialized data. | 576 | * don't use uninitialized data. |
576 | */ | 577 | */ |
577 | smi_info->si_state = SI_NORMAL; | 578 | smi_info->si_state = SI_NORMAL; |
578 | } else { | 579 | } else { |
579 | smi_info->msg_flags = msg[3]; | 580 | smi_info->msg_flags = msg[3]; |
580 | handle_flags(smi_info); | 581 | handle_flags(smi_info); |
581 | } | 582 | } |
582 | break; | 583 | break; |
583 | } | 584 | } |
584 | 585 | ||
585 | case SI_CLEARING_FLAGS: | 586 | case SI_CLEARING_FLAGS: |
586 | case SI_CLEARING_FLAGS_THEN_SET_IRQ: | 587 | case SI_CLEARING_FLAGS_THEN_SET_IRQ: |
587 | { | 588 | { |
588 | unsigned char msg[3]; | 589 | unsigned char msg[3]; |
589 | 590 | ||
590 | /* We cleared the flags. */ | 591 | /* We cleared the flags. */ |
591 | smi_info->handlers->get_result(smi_info->si_sm, msg, 3); | 592 | smi_info->handlers->get_result(smi_info->si_sm, msg, 3); |
592 | if (msg[2] != 0) { | 593 | if (msg[2] != 0) { |
593 | /* Error clearing flags */ | 594 | /* Error clearing flags */ |
594 | dev_warn(smi_info->dev, | 595 | dev_warn(smi_info->dev, |
595 | "Error clearing flags: %2.2x\n", msg[2]); | 596 | "Error clearing flags: %2.2x\n", msg[2]); |
596 | } | 597 | } |
597 | if (smi_info->si_state == SI_CLEARING_FLAGS_THEN_SET_IRQ) | 598 | if (smi_info->si_state == SI_CLEARING_FLAGS_THEN_SET_IRQ) |
598 | start_enable_irq(smi_info); | 599 | start_enable_irq(smi_info); |
599 | else | 600 | else |
600 | smi_info->si_state = SI_NORMAL; | 601 | smi_info->si_state = SI_NORMAL; |
601 | break; | 602 | break; |
602 | } | 603 | } |
603 | 604 | ||
604 | case SI_GETTING_EVENTS: | 605 | case SI_GETTING_EVENTS: |
605 | { | 606 | { |
606 | smi_info->curr_msg->rsp_size | 607 | smi_info->curr_msg->rsp_size |
607 | = smi_info->handlers->get_result( | 608 | = smi_info->handlers->get_result( |
608 | smi_info->si_sm, | 609 | smi_info->si_sm, |
609 | smi_info->curr_msg->rsp, | 610 | smi_info->curr_msg->rsp, |
610 | IPMI_MAX_MSG_LENGTH); | 611 | IPMI_MAX_MSG_LENGTH); |
611 | 612 | ||
612 | /* | 613 | /* |
613 | * Do this here becase deliver_recv_msg() releases the | 614 | * Do this here becase deliver_recv_msg() releases the |
614 | * lock, and a new message can be put in during the | 615 | * lock, and a new message can be put in during the |
615 | * time the lock is released. | 616 | * time the lock is released. |
616 | */ | 617 | */ |
617 | msg = smi_info->curr_msg; | 618 | msg = smi_info->curr_msg; |
618 | smi_info->curr_msg = NULL; | 619 | smi_info->curr_msg = NULL; |
619 | if (msg->rsp[2] != 0) { | 620 | if (msg->rsp[2] != 0) { |
620 | /* Error getting event, probably done. */ | 621 | /* Error getting event, probably done. */ |
621 | msg->done(msg); | 622 | msg->done(msg); |
622 | 623 | ||
623 | /* Take off the event flag. */ | 624 | /* Take off the event flag. */ |
624 | smi_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL; | 625 | smi_info->msg_flags &= ~EVENT_MSG_BUFFER_FULL; |
625 | handle_flags(smi_info); | 626 | handle_flags(smi_info); |
626 | } else { | 627 | } else { |
627 | smi_inc_stat(smi_info, events); | 628 | smi_inc_stat(smi_info, events); |
628 | 629 | ||
629 | /* | 630 | /* |
630 | * Do this before we deliver the message | 631 | * Do this before we deliver the message |
631 | * because delivering the message releases the | 632 | * because delivering the message releases the |
632 | * lock and something else can mess with the | 633 | * lock and something else can mess with the |
633 | * state. | 634 | * state. |
634 | */ | 635 | */ |
635 | handle_flags(smi_info); | 636 | handle_flags(smi_info); |
636 | 637 | ||
637 | deliver_recv_msg(smi_info, msg); | 638 | deliver_recv_msg(smi_info, msg); |
638 | } | 639 | } |
639 | break; | 640 | break; |
640 | } | 641 | } |
641 | 642 | ||
642 | case SI_GETTING_MESSAGES: | 643 | case SI_GETTING_MESSAGES: |
643 | { | 644 | { |
644 | smi_info->curr_msg->rsp_size | 645 | smi_info->curr_msg->rsp_size |
645 | = smi_info->handlers->get_result( | 646 | = smi_info->handlers->get_result( |
646 | smi_info->si_sm, | 647 | smi_info->si_sm, |
647 | smi_info->curr_msg->rsp, | 648 | smi_info->curr_msg->rsp, |
648 | IPMI_MAX_MSG_LENGTH); | 649 | IPMI_MAX_MSG_LENGTH); |
649 | 650 | ||
650 | /* | 651 | /* |
651 | * Do this here becase deliver_recv_msg() releases the | 652 | * Do this here becase deliver_recv_msg() releases the |
652 | * lock, and a new message can be put in during the | 653 | * lock, and a new message can be put in during the |
653 | * time the lock is released. | 654 | * time the lock is released. |
654 | */ | 655 | */ |
655 | msg = smi_info->curr_msg; | 656 | msg = smi_info->curr_msg; |
656 | smi_info->curr_msg = NULL; | 657 | smi_info->curr_msg = NULL; |
657 | if (msg->rsp[2] != 0) { | 658 | if (msg->rsp[2] != 0) { |
658 | /* Error getting event, probably done. */ | 659 | /* Error getting event, probably done. */ |
659 | msg->done(msg); | 660 | msg->done(msg); |
660 | 661 | ||
661 | /* Take off the msg flag. */ | 662 | /* Take off the msg flag. */ |
662 | smi_info->msg_flags &= ~RECEIVE_MSG_AVAIL; | 663 | smi_info->msg_flags &= ~RECEIVE_MSG_AVAIL; |
663 | handle_flags(smi_info); | 664 | handle_flags(smi_info); |
664 | } else { | 665 | } else { |
665 | smi_inc_stat(smi_info, incoming_messages); | 666 | smi_inc_stat(smi_info, incoming_messages); |
666 | 667 | ||
667 | /* | 668 | /* |
668 | * Do this before we deliver the message | 669 | * Do this before we deliver the message |
669 | * because delivering the message releases the | 670 | * because delivering the message releases the |
670 | * lock and something else can mess with the | 671 | * lock and something else can mess with the |
671 | * state. | 672 | * state. |
672 | */ | 673 | */ |
673 | handle_flags(smi_info); | 674 | handle_flags(smi_info); |
674 | 675 | ||
675 | deliver_recv_msg(smi_info, msg); | 676 | deliver_recv_msg(smi_info, msg); |
676 | } | 677 | } |
677 | break; | 678 | break; |
678 | } | 679 | } |
679 | 680 | ||
680 | case SI_ENABLE_INTERRUPTS1: | 681 | case SI_ENABLE_INTERRUPTS1: |
681 | { | 682 | { |
682 | unsigned char msg[4]; | 683 | unsigned char msg[4]; |
683 | 684 | ||
684 | /* We got the flags from the SMI, now handle them. */ | 685 | /* We got the flags from the SMI, now handle them. */ |
685 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); | 686 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
686 | if (msg[2] != 0) { | 687 | if (msg[2] != 0) { |
687 | dev_warn(smi_info->dev, "Could not enable interrupts" | 688 | dev_warn(smi_info->dev, "Could not enable interrupts" |
688 | ", failed get, using polled mode.\n"); | 689 | ", failed get, using polled mode.\n"); |
689 | smi_info->si_state = SI_NORMAL; | 690 | smi_info->si_state = SI_NORMAL; |
690 | } else { | 691 | } else { |
691 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); | 692 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
692 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; | 693 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; |
693 | msg[2] = (msg[3] | | 694 | msg[2] = (msg[3] | |
694 | IPMI_BMC_RCV_MSG_INTR | | 695 | IPMI_BMC_RCV_MSG_INTR | |
695 | IPMI_BMC_EVT_MSG_INTR); | 696 | IPMI_BMC_EVT_MSG_INTR); |
696 | smi_info->handlers->start_transaction( | 697 | smi_info->handlers->start_transaction( |
697 | smi_info->si_sm, msg, 3); | 698 | smi_info->si_sm, msg, 3); |
698 | smi_info->si_state = SI_ENABLE_INTERRUPTS2; | 699 | smi_info->si_state = SI_ENABLE_INTERRUPTS2; |
699 | } | 700 | } |
700 | break; | 701 | break; |
701 | } | 702 | } |
702 | 703 | ||
703 | case SI_ENABLE_INTERRUPTS2: | 704 | case SI_ENABLE_INTERRUPTS2: |
704 | { | 705 | { |
705 | unsigned char msg[4]; | 706 | unsigned char msg[4]; |
706 | 707 | ||
707 | /* We got the flags from the SMI, now handle them. */ | 708 | /* We got the flags from the SMI, now handle them. */ |
708 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); | 709 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
709 | if (msg[2] != 0) | 710 | if (msg[2] != 0) |
710 | dev_warn(smi_info->dev, "Could not enable interrupts" | 711 | dev_warn(smi_info->dev, "Could not enable interrupts" |
711 | ", failed set, using polled mode.\n"); | 712 | ", failed set, using polled mode.\n"); |
712 | else | 713 | else |
713 | smi_info->interrupt_disabled = 0; | 714 | smi_info->interrupt_disabled = 0; |
714 | smi_info->si_state = SI_NORMAL; | 715 | smi_info->si_state = SI_NORMAL; |
715 | break; | 716 | break; |
716 | } | 717 | } |
717 | 718 | ||
718 | case SI_DISABLE_INTERRUPTS1: | 719 | case SI_DISABLE_INTERRUPTS1: |
719 | { | 720 | { |
720 | unsigned char msg[4]; | 721 | unsigned char msg[4]; |
721 | 722 | ||
722 | /* We got the flags from the SMI, now handle them. */ | 723 | /* We got the flags from the SMI, now handle them. */ |
723 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); | 724 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
724 | if (msg[2] != 0) { | 725 | if (msg[2] != 0) { |
725 | dev_warn(smi_info->dev, "Could not disable interrupts" | 726 | dev_warn(smi_info->dev, "Could not disable interrupts" |
726 | ", failed get.\n"); | 727 | ", failed get.\n"); |
727 | smi_info->si_state = SI_NORMAL; | 728 | smi_info->si_state = SI_NORMAL; |
728 | } else { | 729 | } else { |
729 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); | 730 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
730 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; | 731 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; |
731 | msg[2] = (msg[3] & | 732 | msg[2] = (msg[3] & |
732 | ~(IPMI_BMC_RCV_MSG_INTR | | 733 | ~(IPMI_BMC_RCV_MSG_INTR | |
733 | IPMI_BMC_EVT_MSG_INTR)); | 734 | IPMI_BMC_EVT_MSG_INTR)); |
734 | smi_info->handlers->start_transaction( | 735 | smi_info->handlers->start_transaction( |
735 | smi_info->si_sm, msg, 3); | 736 | smi_info->si_sm, msg, 3); |
736 | smi_info->si_state = SI_DISABLE_INTERRUPTS2; | 737 | smi_info->si_state = SI_DISABLE_INTERRUPTS2; |
737 | } | 738 | } |
738 | break; | 739 | break; |
739 | } | 740 | } |
740 | 741 | ||
741 | case SI_DISABLE_INTERRUPTS2: | 742 | case SI_DISABLE_INTERRUPTS2: |
742 | { | 743 | { |
743 | unsigned char msg[4]; | 744 | unsigned char msg[4]; |
744 | 745 | ||
745 | /* We got the flags from the SMI, now handle them. */ | 746 | /* We got the flags from the SMI, now handle them. */ |
746 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); | 747 | smi_info->handlers->get_result(smi_info->si_sm, msg, 4); |
747 | if (msg[2] != 0) { | 748 | if (msg[2] != 0) { |
748 | dev_warn(smi_info->dev, "Could not disable interrupts" | 749 | dev_warn(smi_info->dev, "Could not disable interrupts" |
749 | ", failed set.\n"); | 750 | ", failed set.\n"); |
750 | } | 751 | } |
751 | smi_info->si_state = SI_NORMAL; | 752 | smi_info->si_state = SI_NORMAL; |
752 | break; | 753 | break; |
753 | } | 754 | } |
754 | } | 755 | } |
755 | } | 756 | } |
756 | 757 | ||
757 | /* | 758 | /* |
758 | * Called on timeouts and events. Timeouts should pass the elapsed | 759 | * Called on timeouts and events. Timeouts should pass the elapsed |
759 | * time, interrupts should pass in zero. Must be called with | 760 | * time, interrupts should pass in zero. Must be called with |
760 | * si_lock held and interrupts disabled. | 761 | * si_lock held and interrupts disabled. |
761 | */ | 762 | */ |
762 | static enum si_sm_result smi_event_handler(struct smi_info *smi_info, | 763 | static enum si_sm_result smi_event_handler(struct smi_info *smi_info, |
763 | int time) | 764 | int time) |
764 | { | 765 | { |
765 | enum si_sm_result si_sm_result; | 766 | enum si_sm_result si_sm_result; |
766 | 767 | ||
767 | restart: | 768 | restart: |
768 | /* | 769 | /* |
769 | * There used to be a loop here that waited a little while | 770 | * There used to be a loop here that waited a little while |
770 | * (around 25us) before giving up. That turned out to be | 771 | * (around 25us) before giving up. That turned out to be |
771 | * pointless, the minimum delays I was seeing were in the 300us | 772 | * pointless, the minimum delays I was seeing were in the 300us |
772 | * range, which is far too long to wait in an interrupt. So | 773 | * range, which is far too long to wait in an interrupt. So |
773 | * we just run until the state machine tells us something | 774 | * we just run until the state machine tells us something |
774 | * happened or it needs a delay. | 775 | * happened or it needs a delay. |
775 | */ | 776 | */ |
776 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, time); | 777 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, time); |
777 | time = 0; | 778 | time = 0; |
778 | while (si_sm_result == SI_SM_CALL_WITHOUT_DELAY) | 779 | while (si_sm_result == SI_SM_CALL_WITHOUT_DELAY) |
779 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); | 780 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); |
780 | 781 | ||
781 | if (si_sm_result == SI_SM_TRANSACTION_COMPLETE) { | 782 | if (si_sm_result == SI_SM_TRANSACTION_COMPLETE) { |
782 | smi_inc_stat(smi_info, complete_transactions); | 783 | smi_inc_stat(smi_info, complete_transactions); |
783 | 784 | ||
784 | handle_transaction_done(smi_info); | 785 | handle_transaction_done(smi_info); |
785 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); | 786 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); |
786 | } else if (si_sm_result == SI_SM_HOSED) { | 787 | } else if (si_sm_result == SI_SM_HOSED) { |
787 | smi_inc_stat(smi_info, hosed_count); | 788 | smi_inc_stat(smi_info, hosed_count); |
788 | 789 | ||
789 | /* | 790 | /* |
790 | * Do the before return_hosed_msg, because that | 791 | * Do the before return_hosed_msg, because that |
791 | * releases the lock. | 792 | * releases the lock. |
792 | */ | 793 | */ |
793 | smi_info->si_state = SI_NORMAL; | 794 | smi_info->si_state = SI_NORMAL; |
794 | if (smi_info->curr_msg != NULL) { | 795 | if (smi_info->curr_msg != NULL) { |
795 | /* | 796 | /* |
796 | * If we were handling a user message, format | 797 | * If we were handling a user message, format |
797 | * a response to send to the upper layer to | 798 | * a response to send to the upper layer to |
798 | * tell it about the error. | 799 | * tell it about the error. |
799 | */ | 800 | */ |
800 | return_hosed_msg(smi_info, IPMI_ERR_UNSPECIFIED); | 801 | return_hosed_msg(smi_info, IPMI_ERR_UNSPECIFIED); |
801 | } | 802 | } |
802 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); | 803 | si_sm_result = smi_info->handlers->event(smi_info->si_sm, 0); |
803 | } | 804 | } |
804 | 805 | ||
805 | /* | 806 | /* |
806 | * We prefer handling attn over new messages. But don't do | 807 | * We prefer handling attn over new messages. But don't do |
807 | * this if there is not yet an upper layer to handle anything. | 808 | * this if there is not yet an upper layer to handle anything. |
808 | */ | 809 | */ |
809 | if (likely(smi_info->intf) && si_sm_result == SI_SM_ATTN) { | 810 | if (likely(smi_info->intf) && si_sm_result == SI_SM_ATTN) { |
810 | unsigned char msg[2]; | 811 | unsigned char msg[2]; |
811 | 812 | ||
812 | smi_inc_stat(smi_info, attentions); | 813 | smi_inc_stat(smi_info, attentions); |
813 | 814 | ||
814 | /* | 815 | /* |
815 | * Got a attn, send down a get message flags to see | 816 | * Got a attn, send down a get message flags to see |
816 | * what's causing it. It would be better to handle | 817 | * what's causing it. It would be better to handle |
817 | * this in the upper layer, but due to the way | 818 | * this in the upper layer, but due to the way |
818 | * interrupts work with the SMI, that's not really | 819 | * interrupts work with the SMI, that's not really |
819 | * possible. | 820 | * possible. |
820 | */ | 821 | */ |
821 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); | 822 | msg[0] = (IPMI_NETFN_APP_REQUEST << 2); |
822 | msg[1] = IPMI_GET_MSG_FLAGS_CMD; | 823 | msg[1] = IPMI_GET_MSG_FLAGS_CMD; |
823 | 824 | ||
824 | smi_info->handlers->start_transaction( | 825 | smi_info->handlers->start_transaction( |
825 | smi_info->si_sm, msg, 2); | 826 | smi_info->si_sm, msg, 2); |
826 | smi_info->si_state = SI_GETTING_FLAGS; | 827 | smi_info->si_state = SI_GETTING_FLAGS; |
827 | goto restart; | 828 | goto restart; |
828 | } | 829 | } |
829 | 830 | ||
830 | /* If we are currently idle, try to start the next message. */ | 831 | /* If we are currently idle, try to start the next message. */ |
831 | if (si_sm_result == SI_SM_IDLE) { | 832 | if (si_sm_result == SI_SM_IDLE) { |
832 | smi_inc_stat(smi_info, idles); | 833 | smi_inc_stat(smi_info, idles); |
833 | 834 | ||
834 | si_sm_result = start_next_msg(smi_info); | 835 | si_sm_result = start_next_msg(smi_info); |
835 | if (si_sm_result != SI_SM_IDLE) | 836 | if (si_sm_result != SI_SM_IDLE) |
836 | goto restart; | 837 | goto restart; |
837 | } | 838 | } |
838 | 839 | ||
839 | if ((si_sm_result == SI_SM_IDLE) | 840 | if ((si_sm_result == SI_SM_IDLE) |
840 | && (atomic_read(&smi_info->req_events))) { | 841 | && (atomic_read(&smi_info->req_events))) { |
841 | /* | 842 | /* |
842 | * We are idle and the upper layer requested that I fetch | 843 | * We are idle and the upper layer requested that I fetch |
843 | * events, so do so. | 844 | * events, so do so. |
844 | */ | 845 | */ |
845 | atomic_set(&smi_info->req_events, 0); | 846 | atomic_set(&smi_info->req_events, 0); |
846 | 847 | ||
847 | smi_info->curr_msg = ipmi_alloc_smi_msg(); | 848 | smi_info->curr_msg = ipmi_alloc_smi_msg(); |
848 | if (!smi_info->curr_msg) | 849 | if (!smi_info->curr_msg) |
849 | goto out; | 850 | goto out; |
850 | 851 | ||
851 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); | 852 | smi_info->curr_msg->data[0] = (IPMI_NETFN_APP_REQUEST << 2); |
852 | smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD; | 853 | smi_info->curr_msg->data[1] = IPMI_READ_EVENT_MSG_BUFFER_CMD; |
853 | smi_info->curr_msg->data_size = 2; | 854 | smi_info->curr_msg->data_size = 2; |
854 | 855 | ||
855 | smi_info->handlers->start_transaction( | 856 | smi_info->handlers->start_transaction( |
856 | smi_info->si_sm, | 857 | smi_info->si_sm, |
857 | smi_info->curr_msg->data, | 858 | smi_info->curr_msg->data, |
858 | smi_info->curr_msg->data_size); | 859 | smi_info->curr_msg->data_size); |
859 | smi_info->si_state = SI_GETTING_EVENTS; | 860 | smi_info->si_state = SI_GETTING_EVENTS; |
860 | goto restart; | 861 | goto restart; |
861 | } | 862 | } |
862 | out: | 863 | out: |
863 | return si_sm_result; | 864 | return si_sm_result; |
864 | } | 865 | } |
865 | 866 | ||
866 | static void sender(void *send_info, | 867 | static void sender(void *send_info, |
867 | struct ipmi_smi_msg *msg, | 868 | struct ipmi_smi_msg *msg, |
868 | int priority) | 869 | int priority) |
869 | { | 870 | { |
870 | struct smi_info *smi_info = send_info; | 871 | struct smi_info *smi_info = send_info; |
871 | enum si_sm_result result; | 872 | enum si_sm_result result; |
872 | unsigned long flags; | 873 | unsigned long flags; |
873 | #ifdef DEBUG_TIMING | 874 | #ifdef DEBUG_TIMING |
874 | struct timeval t; | 875 | struct timeval t; |
875 | #endif | 876 | #endif |
876 | 877 | ||
877 | if (atomic_read(&smi_info->stop_operation)) { | 878 | if (atomic_read(&smi_info->stop_operation)) { |
878 | msg->rsp[0] = msg->data[0] | 4; | 879 | msg->rsp[0] = msg->data[0] | 4; |
879 | msg->rsp[1] = msg->data[1]; | 880 | msg->rsp[1] = msg->data[1]; |
880 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; | 881 | msg->rsp[2] = IPMI_ERR_UNSPECIFIED; |
881 | msg->rsp_size = 3; | 882 | msg->rsp_size = 3; |
882 | deliver_recv_msg(smi_info, msg); | 883 | deliver_recv_msg(smi_info, msg); |
883 | return; | 884 | return; |
884 | } | 885 | } |
885 | 886 | ||
886 | #ifdef DEBUG_TIMING | 887 | #ifdef DEBUG_TIMING |
887 | do_gettimeofday(&t); | 888 | do_gettimeofday(&t); |
888 | printk("**Enqueue: %d.%9.9d\n", t.tv_sec, t.tv_usec); | 889 | printk("**Enqueue: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
889 | #endif | 890 | #endif |
890 | 891 | ||
891 | /* | 892 | /* |
892 | * last_timeout_jiffies is updated here to avoid | 893 | * last_timeout_jiffies is updated here to avoid |
893 | * smi_timeout() handler passing very large time_diff | 894 | * smi_timeout() handler passing very large time_diff |
894 | * value to smi_event_handler() that causes | 895 | * value to smi_event_handler() that causes |
895 | * the send command to abort. | 896 | * the send command to abort. |
896 | */ | 897 | */ |
897 | smi_info->last_timeout_jiffies = jiffies; | 898 | smi_info->last_timeout_jiffies = jiffies; |
898 | 899 | ||
899 | mod_timer(&smi_info->si_timer, jiffies + SI_TIMEOUT_JIFFIES); | 900 | mod_timer(&smi_info->si_timer, jiffies + SI_TIMEOUT_JIFFIES); |
900 | 901 | ||
901 | if (smi_info->thread) | 902 | if (smi_info->thread) |
902 | wake_up_process(smi_info->thread); | 903 | wake_up_process(smi_info->thread); |
903 | 904 | ||
904 | if (smi_info->run_to_completion) { | 905 | if (smi_info->run_to_completion) { |
905 | /* | 906 | /* |
906 | * If we are running to completion, then throw it in | 907 | * If we are running to completion, then throw it in |
907 | * the list and run transactions until everything is | 908 | * the list and run transactions until everything is |
908 | * clear. Priority doesn't matter here. | 909 | * clear. Priority doesn't matter here. |
909 | */ | 910 | */ |
910 | 911 | ||
911 | /* | 912 | /* |
912 | * Run to completion means we are single-threaded, no | 913 | * Run to completion means we are single-threaded, no |
913 | * need for locks. | 914 | * need for locks. |
914 | */ | 915 | */ |
915 | list_add_tail(&(msg->link), &(smi_info->xmit_msgs)); | 916 | list_add_tail(&(msg->link), &(smi_info->xmit_msgs)); |
916 | 917 | ||
917 | result = smi_event_handler(smi_info, 0); | 918 | result = smi_event_handler(smi_info, 0); |
918 | while (result != SI_SM_IDLE) { | 919 | while (result != SI_SM_IDLE) { |
919 | udelay(SI_SHORT_TIMEOUT_USEC); | 920 | udelay(SI_SHORT_TIMEOUT_USEC); |
920 | result = smi_event_handler(smi_info, | 921 | result = smi_event_handler(smi_info, |
921 | SI_SHORT_TIMEOUT_USEC); | 922 | SI_SHORT_TIMEOUT_USEC); |
922 | } | 923 | } |
923 | return; | 924 | return; |
924 | } | 925 | } |
925 | 926 | ||
926 | spin_lock_irqsave(&smi_info->msg_lock, flags); | 927 | spin_lock_irqsave(&smi_info->msg_lock, flags); |
927 | if (priority > 0) | 928 | if (priority > 0) |
928 | list_add_tail(&msg->link, &smi_info->hp_xmit_msgs); | 929 | list_add_tail(&msg->link, &smi_info->hp_xmit_msgs); |
929 | else | 930 | else |
930 | list_add_tail(&msg->link, &smi_info->xmit_msgs); | 931 | list_add_tail(&msg->link, &smi_info->xmit_msgs); |
931 | spin_unlock_irqrestore(&smi_info->msg_lock, flags); | 932 | spin_unlock_irqrestore(&smi_info->msg_lock, flags); |
932 | 933 | ||
933 | spin_lock_irqsave(&smi_info->si_lock, flags); | 934 | spin_lock_irqsave(&smi_info->si_lock, flags); |
934 | if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) | 935 | if (smi_info->si_state == SI_NORMAL && smi_info->curr_msg == NULL) |
935 | start_next_msg(smi_info); | 936 | start_next_msg(smi_info); |
936 | spin_unlock_irqrestore(&smi_info->si_lock, flags); | 937 | spin_unlock_irqrestore(&smi_info->si_lock, flags); |
937 | } | 938 | } |
938 | 939 | ||
939 | static void set_run_to_completion(void *send_info, int i_run_to_completion) | 940 | static void set_run_to_completion(void *send_info, int i_run_to_completion) |
940 | { | 941 | { |
941 | struct smi_info *smi_info = send_info; | 942 | struct smi_info *smi_info = send_info; |
942 | enum si_sm_result result; | 943 | enum si_sm_result result; |
943 | 944 | ||
944 | smi_info->run_to_completion = i_run_to_completion; | 945 | smi_info->run_to_completion = i_run_to_completion; |
945 | if (i_run_to_completion) { | 946 | if (i_run_to_completion) { |
946 | result = smi_event_handler(smi_info, 0); | 947 | result = smi_event_handler(smi_info, 0); |
947 | while (result != SI_SM_IDLE) { | 948 | while (result != SI_SM_IDLE) { |
948 | udelay(SI_SHORT_TIMEOUT_USEC); | 949 | udelay(SI_SHORT_TIMEOUT_USEC); |
949 | result = smi_event_handler(smi_info, | 950 | result = smi_event_handler(smi_info, |
950 | SI_SHORT_TIMEOUT_USEC); | 951 | SI_SHORT_TIMEOUT_USEC); |
951 | } | 952 | } |
952 | } | 953 | } |
953 | } | 954 | } |
954 | 955 | ||
955 | /* | 956 | /* |
956 | * Use -1 in the nsec value of the busy waiting timespec to tell that | 957 | * Use -1 in the nsec value of the busy waiting timespec to tell that |
957 | * we are spinning in kipmid looking for something and not delaying | 958 | * we are spinning in kipmid looking for something and not delaying |
958 | * between checks | 959 | * between checks |
959 | */ | 960 | */ |
960 | static inline void ipmi_si_set_not_busy(struct timespec *ts) | 961 | static inline void ipmi_si_set_not_busy(struct timespec *ts) |
961 | { | 962 | { |
962 | ts->tv_nsec = -1; | 963 | ts->tv_nsec = -1; |
963 | } | 964 | } |
964 | static inline int ipmi_si_is_busy(struct timespec *ts) | 965 | static inline int ipmi_si_is_busy(struct timespec *ts) |
965 | { | 966 | { |
966 | return ts->tv_nsec != -1; | 967 | return ts->tv_nsec != -1; |
967 | } | 968 | } |
968 | 969 | ||
969 | static int ipmi_thread_busy_wait(enum si_sm_result smi_result, | 970 | static int ipmi_thread_busy_wait(enum si_sm_result smi_result, |
970 | const struct smi_info *smi_info, | 971 | const struct smi_info *smi_info, |
971 | struct timespec *busy_until) | 972 | struct timespec *busy_until) |
972 | { | 973 | { |
973 | unsigned int max_busy_us = 0; | 974 | unsigned int max_busy_us = 0; |
974 | 975 | ||
975 | if (smi_info->intf_num < num_max_busy_us) | 976 | if (smi_info->intf_num < num_max_busy_us) |
976 | max_busy_us = kipmid_max_busy_us[smi_info->intf_num]; | 977 | max_busy_us = kipmid_max_busy_us[smi_info->intf_num]; |
977 | if (max_busy_us == 0 || smi_result != SI_SM_CALL_WITH_DELAY) | 978 | if (max_busy_us == 0 || smi_result != SI_SM_CALL_WITH_DELAY) |
978 | ipmi_si_set_not_busy(busy_until); | 979 | ipmi_si_set_not_busy(busy_until); |
979 | else if (!ipmi_si_is_busy(busy_until)) { | 980 | else if (!ipmi_si_is_busy(busy_until)) { |
980 | getnstimeofday(busy_until); | 981 | getnstimeofday(busy_until); |
981 | timespec_add_ns(busy_until, max_busy_us*NSEC_PER_USEC); | 982 | timespec_add_ns(busy_until, max_busy_us*NSEC_PER_USEC); |
982 | } else { | 983 | } else { |
983 | struct timespec now; | 984 | struct timespec now; |
984 | getnstimeofday(&now); | 985 | getnstimeofday(&now); |
985 | if (unlikely(timespec_compare(&now, busy_until) > 0)) { | 986 | if (unlikely(timespec_compare(&now, busy_until) > 0)) { |
986 | ipmi_si_set_not_busy(busy_until); | 987 | ipmi_si_set_not_busy(busy_until); |
987 | return 0; | 988 | return 0; |
988 | } | 989 | } |
989 | } | 990 | } |
990 | return 1; | 991 | return 1; |
991 | } | 992 | } |
992 | 993 | ||
993 | 994 | ||
994 | /* | 995 | /* |
995 | * A busy-waiting loop for speeding up IPMI operation. | 996 | * A busy-waiting loop for speeding up IPMI operation. |
996 | * | 997 | * |
997 | * Lousy hardware makes this hard. This is only enabled for systems | 998 | * Lousy hardware makes this hard. This is only enabled for systems |
998 | * that are not BT and do not have interrupts. It starts spinning | 999 | * that are not BT and do not have interrupts. It starts spinning |
999 | * when an operation is complete or until max_busy tells it to stop | 1000 | * when an operation is complete or until max_busy tells it to stop |
1000 | * (if that is enabled). See the paragraph on kimid_max_busy_us in | 1001 | * (if that is enabled). See the paragraph on kimid_max_busy_us in |
1001 | * Documentation/IPMI.txt for details. | 1002 | * Documentation/IPMI.txt for details. |
1002 | */ | 1003 | */ |
1003 | static int ipmi_thread(void *data) | 1004 | static int ipmi_thread(void *data) |
1004 | { | 1005 | { |
1005 | struct smi_info *smi_info = data; | 1006 | struct smi_info *smi_info = data; |
1006 | unsigned long flags; | 1007 | unsigned long flags; |
1007 | enum si_sm_result smi_result; | 1008 | enum si_sm_result smi_result; |
1008 | struct timespec busy_until; | 1009 | struct timespec busy_until; |
1009 | 1010 | ||
1010 | ipmi_si_set_not_busy(&busy_until); | 1011 | ipmi_si_set_not_busy(&busy_until); |
1011 | set_user_nice(current, 19); | 1012 | set_user_nice(current, 19); |
1012 | while (!kthread_should_stop()) { | 1013 | while (!kthread_should_stop()) { |
1013 | int busy_wait; | 1014 | int busy_wait; |
1014 | 1015 | ||
1015 | spin_lock_irqsave(&(smi_info->si_lock), flags); | 1016 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
1016 | smi_result = smi_event_handler(smi_info, 0); | 1017 | smi_result = smi_event_handler(smi_info, 0); |
1017 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); | 1018 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
1018 | busy_wait = ipmi_thread_busy_wait(smi_result, smi_info, | 1019 | busy_wait = ipmi_thread_busy_wait(smi_result, smi_info, |
1019 | &busy_until); | 1020 | &busy_until); |
1020 | if (smi_result == SI_SM_CALL_WITHOUT_DELAY) | 1021 | if (smi_result == SI_SM_CALL_WITHOUT_DELAY) |
1021 | ; /* do nothing */ | 1022 | ; /* do nothing */ |
1022 | else if (smi_result == SI_SM_CALL_WITH_DELAY && busy_wait) | 1023 | else if (smi_result == SI_SM_CALL_WITH_DELAY && busy_wait) |
1023 | schedule(); | 1024 | schedule(); |
1024 | else if (smi_result == SI_SM_IDLE) | 1025 | else if (smi_result == SI_SM_IDLE) |
1025 | schedule_timeout_interruptible(100); | 1026 | schedule_timeout_interruptible(100); |
1026 | else | 1027 | else |
1027 | schedule_timeout_interruptible(1); | 1028 | schedule_timeout_interruptible(1); |
1028 | } | 1029 | } |
1029 | return 0; | 1030 | return 0; |
1030 | } | 1031 | } |
1031 | 1032 | ||
1032 | 1033 | ||
1033 | static void poll(void *send_info) | 1034 | static void poll(void *send_info) |
1034 | { | 1035 | { |
1035 | struct smi_info *smi_info = send_info; | 1036 | struct smi_info *smi_info = send_info; |
1036 | unsigned long flags; | 1037 | unsigned long flags; |
1037 | 1038 | ||
1038 | /* | 1039 | /* |
1039 | * Make sure there is some delay in the poll loop so we can | 1040 | * Make sure there is some delay in the poll loop so we can |
1040 | * drive time forward and timeout things. | 1041 | * drive time forward and timeout things. |
1041 | */ | 1042 | */ |
1042 | udelay(10); | 1043 | udelay(10); |
1043 | spin_lock_irqsave(&smi_info->si_lock, flags); | 1044 | spin_lock_irqsave(&smi_info->si_lock, flags); |
1044 | smi_event_handler(smi_info, 10); | 1045 | smi_event_handler(smi_info, 10); |
1045 | spin_unlock_irqrestore(&smi_info->si_lock, flags); | 1046 | spin_unlock_irqrestore(&smi_info->si_lock, flags); |
1046 | } | 1047 | } |
1047 | 1048 | ||
1048 | static void request_events(void *send_info) | 1049 | static void request_events(void *send_info) |
1049 | { | 1050 | { |
1050 | struct smi_info *smi_info = send_info; | 1051 | struct smi_info *smi_info = send_info; |
1051 | 1052 | ||
1052 | if (atomic_read(&smi_info->stop_operation) || | 1053 | if (atomic_read(&smi_info->stop_operation) || |
1053 | !smi_info->has_event_buffer) | 1054 | !smi_info->has_event_buffer) |
1054 | return; | 1055 | return; |
1055 | 1056 | ||
1056 | atomic_set(&smi_info->req_events, 1); | 1057 | atomic_set(&smi_info->req_events, 1); |
1057 | } | 1058 | } |
1058 | 1059 | ||
1059 | static int initialized; | 1060 | static int initialized; |
1060 | 1061 | ||
1061 | static void smi_timeout(unsigned long data) | 1062 | static void smi_timeout(unsigned long data) |
1062 | { | 1063 | { |
1063 | struct smi_info *smi_info = (struct smi_info *) data; | 1064 | struct smi_info *smi_info = (struct smi_info *) data; |
1064 | enum si_sm_result smi_result; | 1065 | enum si_sm_result smi_result; |
1065 | unsigned long flags; | 1066 | unsigned long flags; |
1066 | unsigned long jiffies_now; | 1067 | unsigned long jiffies_now; |
1067 | long time_diff; | 1068 | long time_diff; |
1068 | long timeout; | 1069 | long timeout; |
1069 | #ifdef DEBUG_TIMING | 1070 | #ifdef DEBUG_TIMING |
1070 | struct timeval t; | 1071 | struct timeval t; |
1071 | #endif | 1072 | #endif |
1072 | 1073 | ||
1073 | spin_lock_irqsave(&(smi_info->si_lock), flags); | 1074 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
1074 | #ifdef DEBUG_TIMING | 1075 | #ifdef DEBUG_TIMING |
1075 | do_gettimeofday(&t); | 1076 | do_gettimeofday(&t); |
1076 | printk(KERN_DEBUG "**Timer: %d.%9.9d\n", t.tv_sec, t.tv_usec); | 1077 | printk(KERN_DEBUG "**Timer: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
1077 | #endif | 1078 | #endif |
1078 | jiffies_now = jiffies; | 1079 | jiffies_now = jiffies; |
1079 | time_diff = (((long)jiffies_now - (long)smi_info->last_timeout_jiffies) | 1080 | time_diff = (((long)jiffies_now - (long)smi_info->last_timeout_jiffies) |
1080 | * SI_USEC_PER_JIFFY); | 1081 | * SI_USEC_PER_JIFFY); |
1081 | smi_result = smi_event_handler(smi_info, time_diff); | 1082 | smi_result = smi_event_handler(smi_info, time_diff); |
1082 | 1083 | ||
1083 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); | 1084 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
1084 | 1085 | ||
1085 | smi_info->last_timeout_jiffies = jiffies_now; | 1086 | smi_info->last_timeout_jiffies = jiffies_now; |
1086 | 1087 | ||
1087 | if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { | 1088 | if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { |
1088 | /* Running with interrupts, only do long timeouts. */ | 1089 | /* Running with interrupts, only do long timeouts. */ |
1089 | timeout = jiffies + SI_TIMEOUT_JIFFIES; | 1090 | timeout = jiffies + SI_TIMEOUT_JIFFIES; |
1090 | smi_inc_stat(smi_info, long_timeouts); | 1091 | smi_inc_stat(smi_info, long_timeouts); |
1091 | goto do_mod_timer; | 1092 | goto do_mod_timer; |
1092 | } | 1093 | } |
1093 | 1094 | ||
1094 | /* | 1095 | /* |
1095 | * If the state machine asks for a short delay, then shorten | 1096 | * If the state machine asks for a short delay, then shorten |
1096 | * the timer timeout. | 1097 | * the timer timeout. |
1097 | */ | 1098 | */ |
1098 | if (smi_result == SI_SM_CALL_WITH_DELAY) { | 1099 | if (smi_result == SI_SM_CALL_WITH_DELAY) { |
1099 | smi_inc_stat(smi_info, short_timeouts); | 1100 | smi_inc_stat(smi_info, short_timeouts); |
1100 | timeout = jiffies + 1; | 1101 | timeout = jiffies + 1; |
1101 | } else { | 1102 | } else { |
1102 | smi_inc_stat(smi_info, long_timeouts); | 1103 | smi_inc_stat(smi_info, long_timeouts); |
1103 | timeout = jiffies + SI_TIMEOUT_JIFFIES; | 1104 | timeout = jiffies + SI_TIMEOUT_JIFFIES; |
1104 | } | 1105 | } |
1105 | 1106 | ||
1106 | do_mod_timer: | 1107 | do_mod_timer: |
1107 | if (smi_result != SI_SM_IDLE) | 1108 | if (smi_result != SI_SM_IDLE) |
1108 | mod_timer(&(smi_info->si_timer), timeout); | 1109 | mod_timer(&(smi_info->si_timer), timeout); |
1109 | } | 1110 | } |
1110 | 1111 | ||
1111 | static irqreturn_t si_irq_handler(int irq, void *data) | 1112 | static irqreturn_t si_irq_handler(int irq, void *data) |
1112 | { | 1113 | { |
1113 | struct smi_info *smi_info = data; | 1114 | struct smi_info *smi_info = data; |
1114 | unsigned long flags; | 1115 | unsigned long flags; |
1115 | #ifdef DEBUG_TIMING | 1116 | #ifdef DEBUG_TIMING |
1116 | struct timeval t; | 1117 | struct timeval t; |
1117 | #endif | 1118 | #endif |
1118 | 1119 | ||
1119 | spin_lock_irqsave(&(smi_info->si_lock), flags); | 1120 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
1120 | 1121 | ||
1121 | smi_inc_stat(smi_info, interrupts); | 1122 | smi_inc_stat(smi_info, interrupts); |
1122 | 1123 | ||
1123 | #ifdef DEBUG_TIMING | 1124 | #ifdef DEBUG_TIMING |
1124 | do_gettimeofday(&t); | 1125 | do_gettimeofday(&t); |
1125 | printk(KERN_DEBUG "**Interrupt: %d.%9.9d\n", t.tv_sec, t.tv_usec); | 1126 | printk(KERN_DEBUG "**Interrupt: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
1126 | #endif | 1127 | #endif |
1127 | smi_event_handler(smi_info, 0); | 1128 | smi_event_handler(smi_info, 0); |
1128 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); | 1129 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
1129 | return IRQ_HANDLED; | 1130 | return IRQ_HANDLED; |
1130 | } | 1131 | } |
1131 | 1132 | ||
1132 | static irqreturn_t si_bt_irq_handler(int irq, void *data) | 1133 | static irqreturn_t si_bt_irq_handler(int irq, void *data) |
1133 | { | 1134 | { |
1134 | struct smi_info *smi_info = data; | 1135 | struct smi_info *smi_info = data; |
1135 | /* We need to clear the IRQ flag for the BT interface. */ | 1136 | /* We need to clear the IRQ flag for the BT interface. */ |
1136 | smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG, | 1137 | smi_info->io.outputb(&smi_info->io, IPMI_BT_INTMASK_REG, |
1137 | IPMI_BT_INTMASK_CLEAR_IRQ_BIT | 1138 | IPMI_BT_INTMASK_CLEAR_IRQ_BIT |
1138 | | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); | 1139 | | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); |
1139 | return si_irq_handler(irq, data); | 1140 | return si_irq_handler(irq, data); |
1140 | } | 1141 | } |
1141 | 1142 | ||
1142 | static int smi_start_processing(void *send_info, | 1143 | static int smi_start_processing(void *send_info, |
1143 | ipmi_smi_t intf) | 1144 | ipmi_smi_t intf) |
1144 | { | 1145 | { |
1145 | struct smi_info *new_smi = send_info; | 1146 | struct smi_info *new_smi = send_info; |
1146 | int enable = 0; | 1147 | int enable = 0; |
1147 | 1148 | ||
1148 | new_smi->intf = intf; | 1149 | new_smi->intf = intf; |
1149 | 1150 | ||
1150 | /* Try to claim any interrupts. */ | 1151 | /* Try to claim any interrupts. */ |
1151 | if (new_smi->irq_setup) | 1152 | if (new_smi->irq_setup) |
1152 | new_smi->irq_setup(new_smi); | 1153 | new_smi->irq_setup(new_smi); |
1153 | 1154 | ||
1154 | /* Set up the timer that drives the interface. */ | 1155 | /* Set up the timer that drives the interface. */ |
1155 | setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi); | 1156 | setup_timer(&new_smi->si_timer, smi_timeout, (long)new_smi); |
1156 | new_smi->last_timeout_jiffies = jiffies; | 1157 | new_smi->last_timeout_jiffies = jiffies; |
1157 | mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES); | 1158 | mod_timer(&new_smi->si_timer, jiffies + SI_TIMEOUT_JIFFIES); |
1158 | 1159 | ||
1159 | /* | 1160 | /* |
1160 | * Check if the user forcefully enabled the daemon. | 1161 | * Check if the user forcefully enabled the daemon. |
1161 | */ | 1162 | */ |
1162 | if (new_smi->intf_num < num_force_kipmid) | 1163 | if (new_smi->intf_num < num_force_kipmid) |
1163 | enable = force_kipmid[new_smi->intf_num]; | 1164 | enable = force_kipmid[new_smi->intf_num]; |
1164 | /* | 1165 | /* |
1165 | * The BT interface is efficient enough to not need a thread, | 1166 | * The BT interface is efficient enough to not need a thread, |
1166 | * and there is no need for a thread if we have interrupts. | 1167 | * and there is no need for a thread if we have interrupts. |
1167 | */ | 1168 | */ |
1168 | else if ((new_smi->si_type != SI_BT) && (!new_smi->irq)) | 1169 | else if ((new_smi->si_type != SI_BT) && (!new_smi->irq)) |
1169 | enable = 1; | 1170 | enable = 1; |
1170 | 1171 | ||
1171 | if (enable) { | 1172 | if (enable) { |
1172 | new_smi->thread = kthread_run(ipmi_thread, new_smi, | 1173 | new_smi->thread = kthread_run(ipmi_thread, new_smi, |
1173 | "kipmi%d", new_smi->intf_num); | 1174 | "kipmi%d", new_smi->intf_num); |
1174 | if (IS_ERR(new_smi->thread)) { | 1175 | if (IS_ERR(new_smi->thread)) { |
1175 | dev_notice(new_smi->dev, "Could not start" | 1176 | dev_notice(new_smi->dev, "Could not start" |
1176 | " kernel thread due to error %ld, only using" | 1177 | " kernel thread due to error %ld, only using" |
1177 | " timers to drive the interface\n", | 1178 | " timers to drive the interface\n", |
1178 | PTR_ERR(new_smi->thread)); | 1179 | PTR_ERR(new_smi->thread)); |
1179 | new_smi->thread = NULL; | 1180 | new_smi->thread = NULL; |
1180 | } | 1181 | } |
1181 | } | 1182 | } |
1182 | 1183 | ||
1183 | return 0; | 1184 | return 0; |
1184 | } | 1185 | } |
1185 | 1186 | ||
1186 | static int get_smi_info(void *send_info, struct ipmi_smi_info *data) | 1187 | static int get_smi_info(void *send_info, struct ipmi_smi_info *data) |
1187 | { | 1188 | { |
1188 | struct smi_info *smi = send_info; | 1189 | struct smi_info *smi = send_info; |
1189 | 1190 | ||
1190 | data->addr_src = smi->addr_source; | 1191 | data->addr_src = smi->addr_source; |
1191 | data->dev = smi->dev; | 1192 | data->dev = smi->dev; |
1192 | data->addr_info = smi->addr_info; | 1193 | data->addr_info = smi->addr_info; |
1193 | get_device(smi->dev); | 1194 | get_device(smi->dev); |
1194 | 1195 | ||
1195 | return 0; | 1196 | return 0; |
1196 | } | 1197 | } |
1197 | 1198 | ||
1198 | static void set_maintenance_mode(void *send_info, int enable) | 1199 | static void set_maintenance_mode(void *send_info, int enable) |
1199 | { | 1200 | { |
1200 | struct smi_info *smi_info = send_info; | 1201 | struct smi_info *smi_info = send_info; |
1201 | 1202 | ||
1202 | if (!enable) | 1203 | if (!enable) |
1203 | atomic_set(&smi_info->req_events, 0); | 1204 | atomic_set(&smi_info->req_events, 0); |
1204 | } | 1205 | } |
1205 | 1206 | ||
1206 | static struct ipmi_smi_handlers handlers = { | 1207 | static struct ipmi_smi_handlers handlers = { |
1207 | .owner = THIS_MODULE, | 1208 | .owner = THIS_MODULE, |
1208 | .start_processing = smi_start_processing, | 1209 | .start_processing = smi_start_processing, |
1209 | .get_smi_info = get_smi_info, | 1210 | .get_smi_info = get_smi_info, |
1210 | .sender = sender, | 1211 | .sender = sender, |
1211 | .request_events = request_events, | 1212 | .request_events = request_events, |
1212 | .set_maintenance_mode = set_maintenance_mode, | 1213 | .set_maintenance_mode = set_maintenance_mode, |
1213 | .set_run_to_completion = set_run_to_completion, | 1214 | .set_run_to_completion = set_run_to_completion, |
1214 | .poll = poll, | 1215 | .poll = poll, |
1215 | }; | 1216 | }; |
1216 | 1217 | ||
1217 | /* | 1218 | /* |
1218 | * There can be 4 IO ports passed in (with or without IRQs), 4 addresses, | 1219 | * There can be 4 IO ports passed in (with or without IRQs), 4 addresses, |
1219 | * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS. | 1220 | * a default IO port, and 1 ACPI/SPMI address. That sets SI_MAX_DRIVERS. |
1220 | */ | 1221 | */ |
1221 | 1222 | ||
1222 | static LIST_HEAD(smi_infos); | 1223 | static LIST_HEAD(smi_infos); |
1223 | static DEFINE_MUTEX(smi_infos_lock); | 1224 | static DEFINE_MUTEX(smi_infos_lock); |
1224 | static int smi_num; /* Used to sequence the SMIs */ | 1225 | static int smi_num; /* Used to sequence the SMIs */ |
1225 | 1226 | ||
1226 | #define DEFAULT_REGSPACING 1 | 1227 | #define DEFAULT_REGSPACING 1 |
1227 | #define DEFAULT_REGSIZE 1 | 1228 | #define DEFAULT_REGSIZE 1 |
1228 | 1229 | ||
1229 | static int si_trydefaults = 1; | 1230 | static int si_trydefaults = 1; |
1230 | static char *si_type[SI_MAX_PARMS]; | 1231 | static char *si_type[SI_MAX_PARMS]; |
1231 | #define MAX_SI_TYPE_STR 30 | 1232 | #define MAX_SI_TYPE_STR 30 |
1232 | static char si_type_str[MAX_SI_TYPE_STR]; | 1233 | static char si_type_str[MAX_SI_TYPE_STR]; |
1233 | static unsigned long addrs[SI_MAX_PARMS]; | 1234 | static unsigned long addrs[SI_MAX_PARMS]; |
1234 | static unsigned int num_addrs; | 1235 | static unsigned int num_addrs; |
1235 | static unsigned int ports[SI_MAX_PARMS]; | 1236 | static unsigned int ports[SI_MAX_PARMS]; |
1236 | static unsigned int num_ports; | 1237 | static unsigned int num_ports; |
1237 | static int irqs[SI_MAX_PARMS]; | 1238 | static int irqs[SI_MAX_PARMS]; |
1238 | static unsigned int num_irqs; | 1239 | static unsigned int num_irqs; |
1239 | static int regspacings[SI_MAX_PARMS]; | 1240 | static int regspacings[SI_MAX_PARMS]; |
1240 | static unsigned int num_regspacings; | 1241 | static unsigned int num_regspacings; |
1241 | static int regsizes[SI_MAX_PARMS]; | 1242 | static int regsizes[SI_MAX_PARMS]; |
1242 | static unsigned int num_regsizes; | 1243 | static unsigned int num_regsizes; |
1243 | static int regshifts[SI_MAX_PARMS]; | 1244 | static int regshifts[SI_MAX_PARMS]; |
1244 | static unsigned int num_regshifts; | 1245 | static unsigned int num_regshifts; |
1245 | static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */ | 1246 | static int slave_addrs[SI_MAX_PARMS]; /* Leaving 0 chooses the default value */ |
1246 | static unsigned int num_slave_addrs; | 1247 | static unsigned int num_slave_addrs; |
1247 | 1248 | ||
1248 | #define IPMI_IO_ADDR_SPACE 0 | 1249 | #define IPMI_IO_ADDR_SPACE 0 |
1249 | #define IPMI_MEM_ADDR_SPACE 1 | 1250 | #define IPMI_MEM_ADDR_SPACE 1 |
1250 | static char *addr_space_to_str[] = { "i/o", "mem" }; | 1251 | static char *addr_space_to_str[] = { "i/o", "mem" }; |
1251 | 1252 | ||
1252 | static int hotmod_handler(const char *val, struct kernel_param *kp); | 1253 | static int hotmod_handler(const char *val, struct kernel_param *kp); |
1253 | 1254 | ||
1254 | module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200); | 1255 | module_param_call(hotmod, hotmod_handler, NULL, NULL, 0200); |
1255 | MODULE_PARM_DESC(hotmod, "Add and remove interfaces. See" | 1256 | MODULE_PARM_DESC(hotmod, "Add and remove interfaces. See" |
1256 | " Documentation/IPMI.txt in the kernel sources for the" | 1257 | " Documentation/IPMI.txt in the kernel sources for the" |
1257 | " gory details."); | 1258 | " gory details."); |
1258 | 1259 | ||
1259 | module_param_named(trydefaults, si_trydefaults, bool, 0); | 1260 | module_param_named(trydefaults, si_trydefaults, bool, 0); |
1260 | MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the" | 1261 | MODULE_PARM_DESC(trydefaults, "Setting this to 'false' will disable the" |
1261 | " default scan of the KCS and SMIC interface at the standard" | 1262 | " default scan of the KCS and SMIC interface at the standard" |
1262 | " address"); | 1263 | " address"); |
1263 | module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0); | 1264 | module_param_string(type, si_type_str, MAX_SI_TYPE_STR, 0); |
1264 | MODULE_PARM_DESC(type, "Defines the type of each interface, each" | 1265 | MODULE_PARM_DESC(type, "Defines the type of each interface, each" |
1265 | " interface separated by commas. The types are 'kcs'," | 1266 | " interface separated by commas. The types are 'kcs'," |
1266 | " 'smic', and 'bt'. For example si_type=kcs,bt will set" | 1267 | " 'smic', and 'bt'. For example si_type=kcs,bt will set" |
1267 | " the first interface to kcs and the second to bt"); | 1268 | " the first interface to kcs and the second to bt"); |
1268 | module_param_array(addrs, ulong, &num_addrs, 0); | 1269 | module_param_array(addrs, ulong, &num_addrs, 0); |
1269 | MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the" | 1270 | MODULE_PARM_DESC(addrs, "Sets the memory address of each interface, the" |
1270 | " addresses separated by commas. Only use if an interface" | 1271 | " addresses separated by commas. Only use if an interface" |
1271 | " is in memory. Otherwise, set it to zero or leave" | 1272 | " is in memory. Otherwise, set it to zero or leave" |
1272 | " it blank."); | 1273 | " it blank."); |
1273 | module_param_array(ports, uint, &num_ports, 0); | 1274 | module_param_array(ports, uint, &num_ports, 0); |
1274 | MODULE_PARM_DESC(ports, "Sets the port address of each interface, the" | 1275 | MODULE_PARM_DESC(ports, "Sets the port address of each interface, the" |
1275 | " addresses separated by commas. Only use if an interface" | 1276 | " addresses separated by commas. Only use if an interface" |
1276 | " is a port. Otherwise, set it to zero or leave" | 1277 | " is a port. Otherwise, set it to zero or leave" |
1277 | " it blank."); | 1278 | " it blank."); |
1278 | module_param_array(irqs, int, &num_irqs, 0); | 1279 | module_param_array(irqs, int, &num_irqs, 0); |
1279 | MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the" | 1280 | MODULE_PARM_DESC(irqs, "Sets the interrupt of each interface, the" |
1280 | " addresses separated by commas. Only use if an interface" | 1281 | " addresses separated by commas. Only use if an interface" |
1281 | " has an interrupt. Otherwise, set it to zero or leave" | 1282 | " has an interrupt. Otherwise, set it to zero or leave" |
1282 | " it blank."); | 1283 | " it blank."); |
1283 | module_param_array(regspacings, int, &num_regspacings, 0); | 1284 | module_param_array(regspacings, int, &num_regspacings, 0); |
1284 | MODULE_PARM_DESC(regspacings, "The number of bytes between the start address" | 1285 | MODULE_PARM_DESC(regspacings, "The number of bytes between the start address" |
1285 | " and each successive register used by the interface. For" | 1286 | " and each successive register used by the interface. For" |
1286 | " instance, if the start address is 0xca2 and the spacing" | 1287 | " instance, if the start address is 0xca2 and the spacing" |
1287 | " is 2, then the second address is at 0xca4. Defaults" | 1288 | " is 2, then the second address is at 0xca4. Defaults" |
1288 | " to 1."); | 1289 | " to 1."); |
1289 | module_param_array(regsizes, int, &num_regsizes, 0); | 1290 | module_param_array(regsizes, int, &num_regsizes, 0); |
1290 | MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes." | 1291 | MODULE_PARM_DESC(regsizes, "The size of the specific IPMI register in bytes." |
1291 | " This should generally be 1, 2, 4, or 8 for an 8-bit," | 1292 | " This should generally be 1, 2, 4, or 8 for an 8-bit," |
1292 | " 16-bit, 32-bit, or 64-bit register. Use this if you" | 1293 | " 16-bit, 32-bit, or 64-bit register. Use this if you" |
1293 | " the 8-bit IPMI register has to be read from a larger" | 1294 | " the 8-bit IPMI register has to be read from a larger" |
1294 | " register."); | 1295 | " register."); |
1295 | module_param_array(regshifts, int, &num_regshifts, 0); | 1296 | module_param_array(regshifts, int, &num_regshifts, 0); |
1296 | MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the." | 1297 | MODULE_PARM_DESC(regshifts, "The amount to shift the data read from the." |
1297 | " IPMI register, in bits. For instance, if the data" | 1298 | " IPMI register, in bits. For instance, if the data" |
1298 | " is read from a 32-bit word and the IPMI data is in" | 1299 | " is read from a 32-bit word and the IPMI data is in" |
1299 | " bit 8-15, then the shift would be 8"); | 1300 | " bit 8-15, then the shift would be 8"); |
1300 | module_param_array(slave_addrs, int, &num_slave_addrs, 0); | 1301 | module_param_array(slave_addrs, int, &num_slave_addrs, 0); |
1301 | MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for" | 1302 | MODULE_PARM_DESC(slave_addrs, "Set the default IPMB slave address for" |
1302 | " the controller. Normally this is 0x20, but can be" | 1303 | " the controller. Normally this is 0x20, but can be" |
1303 | " overridden by this parm. This is an array indexed" | 1304 | " overridden by this parm. This is an array indexed" |
1304 | " by interface number."); | 1305 | " by interface number."); |
1305 | module_param_array(force_kipmid, int, &num_force_kipmid, 0); | 1306 | module_param_array(force_kipmid, int, &num_force_kipmid, 0); |
1306 | MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or" | 1307 | MODULE_PARM_DESC(force_kipmid, "Force the kipmi daemon to be enabled (1) or" |
1307 | " disabled(0). Normally the IPMI driver auto-detects" | 1308 | " disabled(0). Normally the IPMI driver auto-detects" |
1308 | " this, but the value may be overridden by this parm."); | 1309 | " this, but the value may be overridden by this parm."); |
1309 | module_param(unload_when_empty, int, 0); | 1310 | module_param(unload_when_empty, int, 0); |
1310 | MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are" | 1311 | MODULE_PARM_DESC(unload_when_empty, "Unload the module if no interfaces are" |
1311 | " specified or found, default is 1. Setting to 0" | 1312 | " specified or found, default is 1. Setting to 0" |
1312 | " is useful for hot add of devices using hotmod."); | 1313 | " is useful for hot add of devices using hotmod."); |
1313 | module_param_array(kipmid_max_busy_us, uint, &num_max_busy_us, 0644); | 1314 | module_param_array(kipmid_max_busy_us, uint, &num_max_busy_us, 0644); |
1314 | MODULE_PARM_DESC(kipmid_max_busy_us, | 1315 | MODULE_PARM_DESC(kipmid_max_busy_us, |
1315 | "Max time (in microseconds) to busy-wait for IPMI data before" | 1316 | "Max time (in microseconds) to busy-wait for IPMI data before" |
1316 | " sleeping. 0 (default) means to wait forever. Set to 100-500" | 1317 | " sleeping. 0 (default) means to wait forever. Set to 100-500" |
1317 | " if kipmid is using up a lot of CPU time."); | 1318 | " if kipmid is using up a lot of CPU time."); |
1318 | 1319 | ||
1319 | 1320 | ||
1320 | static void std_irq_cleanup(struct smi_info *info) | 1321 | static void std_irq_cleanup(struct smi_info *info) |
1321 | { | 1322 | { |
1322 | if (info->si_type == SI_BT) | 1323 | if (info->si_type == SI_BT) |
1323 | /* Disable the interrupt in the BT interface. */ | 1324 | /* Disable the interrupt in the BT interface. */ |
1324 | info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0); | 1325 | info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, 0); |
1325 | free_irq(info->irq, info); | 1326 | free_irq(info->irq, info); |
1326 | } | 1327 | } |
1327 | 1328 | ||
1328 | static int std_irq_setup(struct smi_info *info) | 1329 | static int std_irq_setup(struct smi_info *info) |
1329 | { | 1330 | { |
1330 | int rv; | 1331 | int rv; |
1331 | 1332 | ||
1332 | if (!info->irq) | 1333 | if (!info->irq) |
1333 | return 0; | 1334 | return 0; |
1334 | 1335 | ||
1335 | if (info->si_type == SI_BT) { | 1336 | if (info->si_type == SI_BT) { |
1336 | rv = request_irq(info->irq, | 1337 | rv = request_irq(info->irq, |
1337 | si_bt_irq_handler, | 1338 | si_bt_irq_handler, |
1338 | IRQF_SHARED | IRQF_DISABLED, | 1339 | IRQF_SHARED | IRQF_DISABLED, |
1339 | DEVICE_NAME, | 1340 | DEVICE_NAME, |
1340 | info); | 1341 | info); |
1341 | if (!rv) | 1342 | if (!rv) |
1342 | /* Enable the interrupt in the BT interface. */ | 1343 | /* Enable the interrupt in the BT interface. */ |
1343 | info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, | 1344 | info->io.outputb(&info->io, IPMI_BT_INTMASK_REG, |
1344 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); | 1345 | IPMI_BT_INTMASK_ENABLE_IRQ_BIT); |
1345 | } else | 1346 | } else |
1346 | rv = request_irq(info->irq, | 1347 | rv = request_irq(info->irq, |
1347 | si_irq_handler, | 1348 | si_irq_handler, |
1348 | IRQF_SHARED | IRQF_DISABLED, | 1349 | IRQF_SHARED | IRQF_DISABLED, |
1349 | DEVICE_NAME, | 1350 | DEVICE_NAME, |
1350 | info); | 1351 | info); |
1351 | if (rv) { | 1352 | if (rv) { |
1352 | dev_warn(info->dev, "%s unable to claim interrupt %d," | 1353 | dev_warn(info->dev, "%s unable to claim interrupt %d," |
1353 | " running polled\n", | 1354 | " running polled\n", |
1354 | DEVICE_NAME, info->irq); | 1355 | DEVICE_NAME, info->irq); |
1355 | info->irq = 0; | 1356 | info->irq = 0; |
1356 | } else { | 1357 | } else { |
1357 | info->irq_cleanup = std_irq_cleanup; | 1358 | info->irq_cleanup = std_irq_cleanup; |
1358 | dev_info(info->dev, "Using irq %d\n", info->irq); | 1359 | dev_info(info->dev, "Using irq %d\n", info->irq); |
1359 | } | 1360 | } |
1360 | 1361 | ||
1361 | return rv; | 1362 | return rv; |
1362 | } | 1363 | } |
1363 | 1364 | ||
1364 | static unsigned char port_inb(struct si_sm_io *io, unsigned int offset) | 1365 | static unsigned char port_inb(struct si_sm_io *io, unsigned int offset) |
1365 | { | 1366 | { |
1366 | unsigned int addr = io->addr_data; | 1367 | unsigned int addr = io->addr_data; |
1367 | 1368 | ||
1368 | return inb(addr + (offset * io->regspacing)); | 1369 | return inb(addr + (offset * io->regspacing)); |
1369 | } | 1370 | } |
1370 | 1371 | ||
1371 | static void port_outb(struct si_sm_io *io, unsigned int offset, | 1372 | static void port_outb(struct si_sm_io *io, unsigned int offset, |
1372 | unsigned char b) | 1373 | unsigned char b) |
1373 | { | 1374 | { |
1374 | unsigned int addr = io->addr_data; | 1375 | unsigned int addr = io->addr_data; |
1375 | 1376 | ||
1376 | outb(b, addr + (offset * io->regspacing)); | 1377 | outb(b, addr + (offset * io->regspacing)); |
1377 | } | 1378 | } |
1378 | 1379 | ||
1379 | static unsigned char port_inw(struct si_sm_io *io, unsigned int offset) | 1380 | static unsigned char port_inw(struct si_sm_io *io, unsigned int offset) |
1380 | { | 1381 | { |
1381 | unsigned int addr = io->addr_data; | 1382 | unsigned int addr = io->addr_data; |
1382 | 1383 | ||
1383 | return (inw(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; | 1384 | return (inw(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; |
1384 | } | 1385 | } |
1385 | 1386 | ||
1386 | static void port_outw(struct si_sm_io *io, unsigned int offset, | 1387 | static void port_outw(struct si_sm_io *io, unsigned int offset, |
1387 | unsigned char b) | 1388 | unsigned char b) |
1388 | { | 1389 | { |
1389 | unsigned int addr = io->addr_data; | 1390 | unsigned int addr = io->addr_data; |
1390 | 1391 | ||
1391 | outw(b << io->regshift, addr + (offset * io->regspacing)); | 1392 | outw(b << io->regshift, addr + (offset * io->regspacing)); |
1392 | } | 1393 | } |
1393 | 1394 | ||
1394 | static unsigned char port_inl(struct si_sm_io *io, unsigned int offset) | 1395 | static unsigned char port_inl(struct si_sm_io *io, unsigned int offset) |
1395 | { | 1396 | { |
1396 | unsigned int addr = io->addr_data; | 1397 | unsigned int addr = io->addr_data; |
1397 | 1398 | ||
1398 | return (inl(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; | 1399 | return (inl(addr + (offset * io->regspacing)) >> io->regshift) & 0xff; |
1399 | } | 1400 | } |
1400 | 1401 | ||
1401 | static void port_outl(struct si_sm_io *io, unsigned int offset, | 1402 | static void port_outl(struct si_sm_io *io, unsigned int offset, |
1402 | unsigned char b) | 1403 | unsigned char b) |
1403 | { | 1404 | { |
1404 | unsigned int addr = io->addr_data; | 1405 | unsigned int addr = io->addr_data; |
1405 | 1406 | ||
1406 | outl(b << io->regshift, addr+(offset * io->regspacing)); | 1407 | outl(b << io->regshift, addr+(offset * io->regspacing)); |
1407 | } | 1408 | } |
1408 | 1409 | ||
1409 | static void port_cleanup(struct smi_info *info) | 1410 | static void port_cleanup(struct smi_info *info) |
1410 | { | 1411 | { |
1411 | unsigned int addr = info->io.addr_data; | 1412 | unsigned int addr = info->io.addr_data; |
1412 | int idx; | 1413 | int idx; |
1413 | 1414 | ||
1414 | if (addr) { | 1415 | if (addr) { |
1415 | for (idx = 0; idx < info->io_size; idx++) | 1416 | for (idx = 0; idx < info->io_size; idx++) |
1416 | release_region(addr + idx * info->io.regspacing, | 1417 | release_region(addr + idx * info->io.regspacing, |
1417 | info->io.regsize); | 1418 | info->io.regsize); |
1418 | } | 1419 | } |
1419 | } | 1420 | } |
1420 | 1421 | ||
1421 | static int port_setup(struct smi_info *info) | 1422 | static int port_setup(struct smi_info *info) |
1422 | { | 1423 | { |
1423 | unsigned int addr = info->io.addr_data; | 1424 | unsigned int addr = info->io.addr_data; |
1424 | int idx; | 1425 | int idx; |
1425 | 1426 | ||
1426 | if (!addr) | 1427 | if (!addr) |
1427 | return -ENODEV; | 1428 | return -ENODEV; |
1428 | 1429 | ||
1429 | info->io_cleanup = port_cleanup; | 1430 | info->io_cleanup = port_cleanup; |
1430 | 1431 | ||
1431 | /* | 1432 | /* |
1432 | * Figure out the actual inb/inw/inl/etc routine to use based | 1433 | * Figure out the actual inb/inw/inl/etc routine to use based |
1433 | * upon the register size. | 1434 | * upon the register size. |
1434 | */ | 1435 | */ |
1435 | switch (info->io.regsize) { | 1436 | switch (info->io.regsize) { |
1436 | case 1: | 1437 | case 1: |
1437 | info->io.inputb = port_inb; | 1438 | info->io.inputb = port_inb; |
1438 | info->io.outputb = port_outb; | 1439 | info->io.outputb = port_outb; |
1439 | break; | 1440 | break; |
1440 | case 2: | 1441 | case 2: |
1441 | info->io.inputb = port_inw; | 1442 | info->io.inputb = port_inw; |
1442 | info->io.outputb = port_outw; | 1443 | info->io.outputb = port_outw; |
1443 | break; | 1444 | break; |
1444 | case 4: | 1445 | case 4: |
1445 | info->io.inputb = port_inl; | 1446 | info->io.inputb = port_inl; |
1446 | info->io.outputb = port_outl; | 1447 | info->io.outputb = port_outl; |
1447 | break; | 1448 | break; |
1448 | default: | 1449 | default: |
1449 | dev_warn(info->dev, "Invalid register size: %d\n", | 1450 | dev_warn(info->dev, "Invalid register size: %d\n", |
1450 | info->io.regsize); | 1451 | info->io.regsize); |
1451 | return -EINVAL; | 1452 | return -EINVAL; |
1452 | } | 1453 | } |
1453 | 1454 | ||
1454 | /* | 1455 | /* |
1455 | * Some BIOSes reserve disjoint I/O regions in their ACPI | 1456 | * Some BIOSes reserve disjoint I/O regions in their ACPI |
1456 | * tables. This causes problems when trying to register the | 1457 | * tables. This causes problems when trying to register the |
1457 | * entire I/O region. Therefore we must register each I/O | 1458 | * entire I/O region. Therefore we must register each I/O |
1458 | * port separately. | 1459 | * port separately. |
1459 | */ | 1460 | */ |
1460 | for (idx = 0; idx < info->io_size; idx++) { | 1461 | for (idx = 0; idx < info->io_size; idx++) { |
1461 | if (request_region(addr + idx * info->io.regspacing, | 1462 | if (request_region(addr + idx * info->io.regspacing, |
1462 | info->io.regsize, DEVICE_NAME) == NULL) { | 1463 | info->io.regsize, DEVICE_NAME) == NULL) { |
1463 | /* Undo allocations */ | 1464 | /* Undo allocations */ |
1464 | while (idx--) { | 1465 | while (idx--) { |
1465 | release_region(addr + idx * info->io.regspacing, | 1466 | release_region(addr + idx * info->io.regspacing, |
1466 | info->io.regsize); | 1467 | info->io.regsize); |
1467 | } | 1468 | } |
1468 | return -EIO; | 1469 | return -EIO; |
1469 | } | 1470 | } |
1470 | } | 1471 | } |
1471 | return 0; | 1472 | return 0; |
1472 | } | 1473 | } |
1473 | 1474 | ||
1474 | static unsigned char intf_mem_inb(struct si_sm_io *io, unsigned int offset) | 1475 | static unsigned char intf_mem_inb(struct si_sm_io *io, unsigned int offset) |
1475 | { | 1476 | { |
1476 | return readb((io->addr)+(offset * io->regspacing)); | 1477 | return readb((io->addr)+(offset * io->regspacing)); |
1477 | } | 1478 | } |
1478 | 1479 | ||
1479 | static void intf_mem_outb(struct si_sm_io *io, unsigned int offset, | 1480 | static void intf_mem_outb(struct si_sm_io *io, unsigned int offset, |
1480 | unsigned char b) | 1481 | unsigned char b) |
1481 | { | 1482 | { |
1482 | writeb(b, (io->addr)+(offset * io->regspacing)); | 1483 | writeb(b, (io->addr)+(offset * io->regspacing)); |
1483 | } | 1484 | } |
1484 | 1485 | ||
1485 | static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset) | 1486 | static unsigned char intf_mem_inw(struct si_sm_io *io, unsigned int offset) |
1486 | { | 1487 | { |
1487 | return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift) | 1488 | return (readw((io->addr)+(offset * io->regspacing)) >> io->regshift) |
1488 | & 0xff; | 1489 | & 0xff; |
1489 | } | 1490 | } |
1490 | 1491 | ||
1491 | static void intf_mem_outw(struct si_sm_io *io, unsigned int offset, | 1492 | static void intf_mem_outw(struct si_sm_io *io, unsigned int offset, |
1492 | unsigned char b) | 1493 | unsigned char b) |
1493 | { | 1494 | { |
1494 | writeb(b << io->regshift, (io->addr)+(offset * io->regspacing)); | 1495 | writeb(b << io->regshift, (io->addr)+(offset * io->regspacing)); |
1495 | } | 1496 | } |
1496 | 1497 | ||
1497 | static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset) | 1498 | static unsigned char intf_mem_inl(struct si_sm_io *io, unsigned int offset) |
1498 | { | 1499 | { |
1499 | return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift) | 1500 | return (readl((io->addr)+(offset * io->regspacing)) >> io->regshift) |
1500 | & 0xff; | 1501 | & 0xff; |
1501 | } | 1502 | } |
1502 | 1503 | ||
1503 | static void intf_mem_outl(struct si_sm_io *io, unsigned int offset, | 1504 | static void intf_mem_outl(struct si_sm_io *io, unsigned int offset, |
1504 | unsigned char b) | 1505 | unsigned char b) |
1505 | { | 1506 | { |
1506 | writel(b << io->regshift, (io->addr)+(offset * io->regspacing)); | 1507 | writel(b << io->regshift, (io->addr)+(offset * io->regspacing)); |
1507 | } | 1508 | } |
1508 | 1509 | ||
1509 | #ifdef readq | 1510 | #ifdef readq |
1510 | static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset) | 1511 | static unsigned char mem_inq(struct si_sm_io *io, unsigned int offset) |
1511 | { | 1512 | { |
1512 | return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift) | 1513 | return (readq((io->addr)+(offset * io->regspacing)) >> io->regshift) |
1513 | & 0xff; | 1514 | & 0xff; |
1514 | } | 1515 | } |
1515 | 1516 | ||
1516 | static void mem_outq(struct si_sm_io *io, unsigned int offset, | 1517 | static void mem_outq(struct si_sm_io *io, unsigned int offset, |
1517 | unsigned char b) | 1518 | unsigned char b) |
1518 | { | 1519 | { |
1519 | writeq(b << io->regshift, (io->addr)+(offset * io->regspacing)); | 1520 | writeq(b << io->regshift, (io->addr)+(offset * io->regspacing)); |
1520 | } | 1521 | } |
1521 | #endif | 1522 | #endif |
1522 | 1523 | ||
1523 | static void mem_cleanup(struct smi_info *info) | 1524 | static void mem_cleanup(struct smi_info *info) |
1524 | { | 1525 | { |
1525 | unsigned long addr = info->io.addr_data; | 1526 | unsigned long addr = info->io.addr_data; |
1526 | int mapsize; | 1527 | int mapsize; |
1527 | 1528 | ||
1528 | if (info->io.addr) { | 1529 | if (info->io.addr) { |
1529 | iounmap(info->io.addr); | 1530 | iounmap(info->io.addr); |
1530 | 1531 | ||
1531 | mapsize = ((info->io_size * info->io.regspacing) | 1532 | mapsize = ((info->io_size * info->io.regspacing) |
1532 | - (info->io.regspacing - info->io.regsize)); | 1533 | - (info->io.regspacing - info->io.regsize)); |
1533 | 1534 | ||
1534 | release_mem_region(addr, mapsize); | 1535 | release_mem_region(addr, mapsize); |
1535 | } | 1536 | } |
1536 | } | 1537 | } |
1537 | 1538 | ||
1538 | static int mem_setup(struct smi_info *info) | 1539 | static int mem_setup(struct smi_info *info) |
1539 | { | 1540 | { |
1540 | unsigned long addr = info->io.addr_data; | 1541 | unsigned long addr = info->io.addr_data; |
1541 | int mapsize; | 1542 | int mapsize; |
1542 | 1543 | ||
1543 | if (!addr) | 1544 | if (!addr) |
1544 | return -ENODEV; | 1545 | return -ENODEV; |
1545 | 1546 | ||
1546 | info->io_cleanup = mem_cleanup; | 1547 | info->io_cleanup = mem_cleanup; |
1547 | 1548 | ||
1548 | /* | 1549 | /* |
1549 | * Figure out the actual readb/readw/readl/etc routine to use based | 1550 | * Figure out the actual readb/readw/readl/etc routine to use based |
1550 | * upon the register size. | 1551 | * upon the register size. |
1551 | */ | 1552 | */ |
1552 | switch (info->io.regsize) { | 1553 | switch (info->io.regsize) { |
1553 | case 1: | 1554 | case 1: |
1554 | info->io.inputb = intf_mem_inb; | 1555 | info->io.inputb = intf_mem_inb; |
1555 | info->io.outputb = intf_mem_outb; | 1556 | info->io.outputb = intf_mem_outb; |
1556 | break; | 1557 | break; |
1557 | case 2: | 1558 | case 2: |
1558 | info->io.inputb = intf_mem_inw; | 1559 | info->io.inputb = intf_mem_inw; |
1559 | info->io.outputb = intf_mem_outw; | 1560 | info->io.outputb = intf_mem_outw; |
1560 | break; | 1561 | break; |
1561 | case 4: | 1562 | case 4: |
1562 | info->io.inputb = intf_mem_inl; | 1563 | info->io.inputb = intf_mem_inl; |
1563 | info->io.outputb = intf_mem_outl; | 1564 | info->io.outputb = intf_mem_outl; |
1564 | break; | 1565 | break; |
1565 | #ifdef readq | 1566 | #ifdef readq |
1566 | case 8: | 1567 | case 8: |
1567 | info->io.inputb = mem_inq; | 1568 | info->io.inputb = mem_inq; |
1568 | info->io.outputb = mem_outq; | 1569 | info->io.outputb = mem_outq; |
1569 | break; | 1570 | break; |
1570 | #endif | 1571 | #endif |
1571 | default: | 1572 | default: |
1572 | dev_warn(info->dev, "Invalid register size: %d\n", | 1573 | dev_warn(info->dev, "Invalid register size: %d\n", |
1573 | info->io.regsize); | 1574 | info->io.regsize); |
1574 | return -EINVAL; | 1575 | return -EINVAL; |
1575 | } | 1576 | } |
1576 | 1577 | ||
1577 | /* | 1578 | /* |
1578 | * Calculate the total amount of memory to claim. This is an | 1579 | * Calculate the total amount of memory to claim. This is an |
1579 | * unusual looking calculation, but it avoids claiming any | 1580 | * unusual looking calculation, but it avoids claiming any |
1580 | * more memory than it has to. It will claim everything | 1581 | * more memory than it has to. It will claim everything |
1581 | * between the first address to the end of the last full | 1582 | * between the first address to the end of the last full |
1582 | * register. | 1583 | * register. |
1583 | */ | 1584 | */ |
1584 | mapsize = ((info->io_size * info->io.regspacing) | 1585 | mapsize = ((info->io_size * info->io.regspacing) |
1585 | - (info->io.regspacing - info->io.regsize)); | 1586 | - (info->io.regspacing - info->io.regsize)); |
1586 | 1587 | ||
1587 | if (request_mem_region(addr, mapsize, DEVICE_NAME) == NULL) | 1588 | if (request_mem_region(addr, mapsize, DEVICE_NAME) == NULL) |
1588 | return -EIO; | 1589 | return -EIO; |
1589 | 1590 | ||
1590 | info->io.addr = ioremap(addr, mapsize); | 1591 | info->io.addr = ioremap(addr, mapsize); |
1591 | if (info->io.addr == NULL) { | 1592 | if (info->io.addr == NULL) { |
1592 | release_mem_region(addr, mapsize); | 1593 | release_mem_region(addr, mapsize); |
1593 | return -EIO; | 1594 | return -EIO; |
1594 | } | 1595 | } |
1595 | return 0; | 1596 | return 0; |
1596 | } | 1597 | } |
1597 | 1598 | ||
1598 | /* | 1599 | /* |
1599 | * Parms come in as <op1>[:op2[:op3...]]. ops are: | 1600 | * Parms come in as <op1>[:op2[:op3...]]. ops are: |
1600 | * add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]] | 1601 | * add|remove,kcs|bt|smic,mem|i/o,<address>[,<opt1>[,<opt2>[,...]]] |
1601 | * Options are: | 1602 | * Options are: |
1602 | * rsp=<regspacing> | 1603 | * rsp=<regspacing> |
1603 | * rsi=<regsize> | 1604 | * rsi=<regsize> |
1604 | * rsh=<regshift> | 1605 | * rsh=<regshift> |
1605 | * irq=<irq> | 1606 | * irq=<irq> |
1606 | * ipmb=<ipmb addr> | 1607 | * ipmb=<ipmb addr> |
1607 | */ | 1608 | */ |
1608 | enum hotmod_op { HM_ADD, HM_REMOVE }; | 1609 | enum hotmod_op { HM_ADD, HM_REMOVE }; |
1609 | struct hotmod_vals { | 1610 | struct hotmod_vals { |
1610 | char *name; | 1611 | char *name; |
1611 | int val; | 1612 | int val; |
1612 | }; | 1613 | }; |
1613 | static struct hotmod_vals hotmod_ops[] = { | 1614 | static struct hotmod_vals hotmod_ops[] = { |
1614 | { "add", HM_ADD }, | 1615 | { "add", HM_ADD }, |
1615 | { "remove", HM_REMOVE }, | 1616 | { "remove", HM_REMOVE }, |
1616 | { NULL } | 1617 | { NULL } |
1617 | }; | 1618 | }; |
1618 | static struct hotmod_vals hotmod_si[] = { | 1619 | static struct hotmod_vals hotmod_si[] = { |
1619 | { "kcs", SI_KCS }, | 1620 | { "kcs", SI_KCS }, |
1620 | { "smic", SI_SMIC }, | 1621 | { "smic", SI_SMIC }, |
1621 | { "bt", SI_BT }, | 1622 | { "bt", SI_BT }, |
1622 | { NULL } | 1623 | { NULL } |
1623 | }; | 1624 | }; |
1624 | static struct hotmod_vals hotmod_as[] = { | 1625 | static struct hotmod_vals hotmod_as[] = { |
1625 | { "mem", IPMI_MEM_ADDR_SPACE }, | 1626 | { "mem", IPMI_MEM_ADDR_SPACE }, |
1626 | { "i/o", IPMI_IO_ADDR_SPACE }, | 1627 | { "i/o", IPMI_IO_ADDR_SPACE }, |
1627 | { NULL } | 1628 | { NULL } |
1628 | }; | 1629 | }; |
1629 | 1630 | ||
1630 | static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr) | 1631 | static int parse_str(struct hotmod_vals *v, int *val, char *name, char **curr) |
1631 | { | 1632 | { |
1632 | char *s; | 1633 | char *s; |
1633 | int i; | 1634 | int i; |
1634 | 1635 | ||
1635 | s = strchr(*curr, ','); | 1636 | s = strchr(*curr, ','); |
1636 | if (!s) { | 1637 | if (!s) { |
1637 | printk(KERN_WARNING PFX "No hotmod %s given.\n", name); | 1638 | printk(KERN_WARNING PFX "No hotmod %s given.\n", name); |
1638 | return -EINVAL; | 1639 | return -EINVAL; |
1639 | } | 1640 | } |
1640 | *s = '\0'; | 1641 | *s = '\0'; |
1641 | s++; | 1642 | s++; |
1642 | for (i = 0; hotmod_ops[i].name; i++) { | 1643 | for (i = 0; hotmod_ops[i].name; i++) { |
1643 | if (strcmp(*curr, v[i].name) == 0) { | 1644 | if (strcmp(*curr, v[i].name) == 0) { |
1644 | *val = v[i].val; | 1645 | *val = v[i].val; |
1645 | *curr = s; | 1646 | *curr = s; |
1646 | return 0; | 1647 | return 0; |
1647 | } | 1648 | } |
1648 | } | 1649 | } |
1649 | 1650 | ||
1650 | printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr); | 1651 | printk(KERN_WARNING PFX "Invalid hotmod %s '%s'\n", name, *curr); |
1651 | return -EINVAL; | 1652 | return -EINVAL; |
1652 | } | 1653 | } |
1653 | 1654 | ||
1654 | static int check_hotmod_int_op(const char *curr, const char *option, | 1655 | static int check_hotmod_int_op(const char *curr, const char *option, |
1655 | const char *name, int *val) | 1656 | const char *name, int *val) |
1656 | { | 1657 | { |
1657 | char *n; | 1658 | char *n; |
1658 | 1659 | ||
1659 | if (strcmp(curr, name) == 0) { | 1660 | if (strcmp(curr, name) == 0) { |
1660 | if (!option) { | 1661 | if (!option) { |
1661 | printk(KERN_WARNING PFX | 1662 | printk(KERN_WARNING PFX |
1662 | "No option given for '%s'\n", | 1663 | "No option given for '%s'\n", |
1663 | curr); | 1664 | curr); |
1664 | return -EINVAL; | 1665 | return -EINVAL; |
1665 | } | 1666 | } |
1666 | *val = simple_strtoul(option, &n, 0); | 1667 | *val = simple_strtoul(option, &n, 0); |
1667 | if ((*n != '\0') || (*option == '\0')) { | 1668 | if ((*n != '\0') || (*option == '\0')) { |
1668 | printk(KERN_WARNING PFX | 1669 | printk(KERN_WARNING PFX |
1669 | "Bad option given for '%s'\n", | 1670 | "Bad option given for '%s'\n", |
1670 | curr); | 1671 | curr); |
1671 | return -EINVAL; | 1672 | return -EINVAL; |
1672 | } | 1673 | } |
1673 | return 1; | 1674 | return 1; |
1674 | } | 1675 | } |
1675 | return 0; | 1676 | return 0; |
1676 | } | 1677 | } |
1677 | 1678 | ||
1678 | static struct smi_info *smi_info_alloc(void) | 1679 | static struct smi_info *smi_info_alloc(void) |
1679 | { | 1680 | { |
1680 | struct smi_info *info = kzalloc(sizeof(*info), GFP_KERNEL); | 1681 | struct smi_info *info = kzalloc(sizeof(*info), GFP_KERNEL); |
1681 | 1682 | ||
1682 | if (info) { | 1683 | if (info) { |
1683 | spin_lock_init(&info->si_lock); | 1684 | spin_lock_init(&info->si_lock); |
1684 | spin_lock_init(&info->msg_lock); | 1685 | spin_lock_init(&info->msg_lock); |
1685 | } | 1686 | } |
1686 | return info; | 1687 | return info; |
1687 | } | 1688 | } |
1688 | 1689 | ||
1689 | static int hotmod_handler(const char *val, struct kernel_param *kp) | 1690 | static int hotmod_handler(const char *val, struct kernel_param *kp) |
1690 | { | 1691 | { |
1691 | char *str = kstrdup(val, GFP_KERNEL); | 1692 | char *str = kstrdup(val, GFP_KERNEL); |
1692 | int rv; | 1693 | int rv; |
1693 | char *next, *curr, *s, *n, *o; | 1694 | char *next, *curr, *s, *n, *o; |
1694 | enum hotmod_op op; | 1695 | enum hotmod_op op; |
1695 | enum si_type si_type; | 1696 | enum si_type si_type; |
1696 | int addr_space; | 1697 | int addr_space; |
1697 | unsigned long addr; | 1698 | unsigned long addr; |
1698 | int regspacing; | 1699 | int regspacing; |
1699 | int regsize; | 1700 | int regsize; |
1700 | int regshift; | 1701 | int regshift; |
1701 | int irq; | 1702 | int irq; |
1702 | int ipmb; | 1703 | int ipmb; |
1703 | int ival; | 1704 | int ival; |
1704 | int len; | 1705 | int len; |
1705 | struct smi_info *info; | 1706 | struct smi_info *info; |
1706 | 1707 | ||
1707 | if (!str) | 1708 | if (!str) |
1708 | return -ENOMEM; | 1709 | return -ENOMEM; |
1709 | 1710 | ||
1710 | /* Kill any trailing spaces, as we can get a "\n" from echo. */ | 1711 | /* Kill any trailing spaces, as we can get a "\n" from echo. */ |
1711 | len = strlen(str); | 1712 | len = strlen(str); |
1712 | ival = len - 1; | 1713 | ival = len - 1; |
1713 | while ((ival >= 0) && isspace(str[ival])) { | 1714 | while ((ival >= 0) && isspace(str[ival])) { |
1714 | str[ival] = '\0'; | 1715 | str[ival] = '\0'; |
1715 | ival--; | 1716 | ival--; |
1716 | } | 1717 | } |
1717 | 1718 | ||
1718 | for (curr = str; curr; curr = next) { | 1719 | for (curr = str; curr; curr = next) { |
1719 | regspacing = 1; | 1720 | regspacing = 1; |
1720 | regsize = 1; | 1721 | regsize = 1; |
1721 | regshift = 0; | 1722 | regshift = 0; |
1722 | irq = 0; | 1723 | irq = 0; |
1723 | ipmb = 0; /* Choose the default if not specified */ | 1724 | ipmb = 0; /* Choose the default if not specified */ |
1724 | 1725 | ||
1725 | next = strchr(curr, ':'); | 1726 | next = strchr(curr, ':'); |
1726 | if (next) { | 1727 | if (next) { |
1727 | *next = '\0'; | 1728 | *next = '\0'; |
1728 | next++; | 1729 | next++; |
1729 | } | 1730 | } |
1730 | 1731 | ||
1731 | rv = parse_str(hotmod_ops, &ival, "operation", &curr); | 1732 | rv = parse_str(hotmod_ops, &ival, "operation", &curr); |
1732 | if (rv) | 1733 | if (rv) |
1733 | break; | 1734 | break; |
1734 | op = ival; | 1735 | op = ival; |
1735 | 1736 | ||
1736 | rv = parse_str(hotmod_si, &ival, "interface type", &curr); | 1737 | rv = parse_str(hotmod_si, &ival, "interface type", &curr); |
1737 | if (rv) | 1738 | if (rv) |
1738 | break; | 1739 | break; |
1739 | si_type = ival; | 1740 | si_type = ival; |
1740 | 1741 | ||
1741 | rv = parse_str(hotmod_as, &addr_space, "address space", &curr); | 1742 | rv = parse_str(hotmod_as, &addr_space, "address space", &curr); |
1742 | if (rv) | 1743 | if (rv) |
1743 | break; | 1744 | break; |
1744 | 1745 | ||
1745 | s = strchr(curr, ','); | 1746 | s = strchr(curr, ','); |
1746 | if (s) { | 1747 | if (s) { |
1747 | *s = '\0'; | 1748 | *s = '\0'; |
1748 | s++; | 1749 | s++; |
1749 | } | 1750 | } |
1750 | addr = simple_strtoul(curr, &n, 0); | 1751 | addr = simple_strtoul(curr, &n, 0); |
1751 | if ((*n != '\0') || (*curr == '\0')) { | 1752 | if ((*n != '\0') || (*curr == '\0')) { |
1752 | printk(KERN_WARNING PFX "Invalid hotmod address" | 1753 | printk(KERN_WARNING PFX "Invalid hotmod address" |
1753 | " '%s'\n", curr); | 1754 | " '%s'\n", curr); |
1754 | break; | 1755 | break; |
1755 | } | 1756 | } |
1756 | 1757 | ||
1757 | while (s) { | 1758 | while (s) { |
1758 | curr = s; | 1759 | curr = s; |
1759 | s = strchr(curr, ','); | 1760 | s = strchr(curr, ','); |
1760 | if (s) { | 1761 | if (s) { |
1761 | *s = '\0'; | 1762 | *s = '\0'; |
1762 | s++; | 1763 | s++; |
1763 | } | 1764 | } |
1764 | o = strchr(curr, '='); | 1765 | o = strchr(curr, '='); |
1765 | if (o) { | 1766 | if (o) { |
1766 | *o = '\0'; | 1767 | *o = '\0'; |
1767 | o++; | 1768 | o++; |
1768 | } | 1769 | } |
1769 | rv = check_hotmod_int_op(curr, o, "rsp", ®spacing); | 1770 | rv = check_hotmod_int_op(curr, o, "rsp", ®spacing); |
1770 | if (rv < 0) | 1771 | if (rv < 0) |
1771 | goto out; | 1772 | goto out; |
1772 | else if (rv) | 1773 | else if (rv) |
1773 | continue; | 1774 | continue; |
1774 | rv = check_hotmod_int_op(curr, o, "rsi", ®size); | 1775 | rv = check_hotmod_int_op(curr, o, "rsi", ®size); |
1775 | if (rv < 0) | 1776 | if (rv < 0) |
1776 | goto out; | 1777 | goto out; |
1777 | else if (rv) | 1778 | else if (rv) |
1778 | continue; | 1779 | continue; |
1779 | rv = check_hotmod_int_op(curr, o, "rsh", ®shift); | 1780 | rv = check_hotmod_int_op(curr, o, "rsh", ®shift); |
1780 | if (rv < 0) | 1781 | if (rv < 0) |
1781 | goto out; | 1782 | goto out; |
1782 | else if (rv) | 1783 | else if (rv) |
1783 | continue; | 1784 | continue; |
1784 | rv = check_hotmod_int_op(curr, o, "irq", &irq); | 1785 | rv = check_hotmod_int_op(curr, o, "irq", &irq); |
1785 | if (rv < 0) | 1786 | if (rv < 0) |
1786 | goto out; | 1787 | goto out; |
1787 | else if (rv) | 1788 | else if (rv) |
1788 | continue; | 1789 | continue; |
1789 | rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb); | 1790 | rv = check_hotmod_int_op(curr, o, "ipmb", &ipmb); |
1790 | if (rv < 0) | 1791 | if (rv < 0) |
1791 | goto out; | 1792 | goto out; |
1792 | else if (rv) | 1793 | else if (rv) |
1793 | continue; | 1794 | continue; |
1794 | 1795 | ||
1795 | rv = -EINVAL; | 1796 | rv = -EINVAL; |
1796 | printk(KERN_WARNING PFX | 1797 | printk(KERN_WARNING PFX |
1797 | "Invalid hotmod option '%s'\n", | 1798 | "Invalid hotmod option '%s'\n", |
1798 | curr); | 1799 | curr); |
1799 | goto out; | 1800 | goto out; |
1800 | } | 1801 | } |
1801 | 1802 | ||
1802 | if (op == HM_ADD) { | 1803 | if (op == HM_ADD) { |
1803 | info = smi_info_alloc(); | 1804 | info = smi_info_alloc(); |
1804 | if (!info) { | 1805 | if (!info) { |
1805 | rv = -ENOMEM; | 1806 | rv = -ENOMEM; |
1806 | goto out; | 1807 | goto out; |
1807 | } | 1808 | } |
1808 | 1809 | ||
1809 | info->addr_source = SI_HOTMOD; | 1810 | info->addr_source = SI_HOTMOD; |
1810 | info->si_type = si_type; | 1811 | info->si_type = si_type; |
1811 | info->io.addr_data = addr; | 1812 | info->io.addr_data = addr; |
1812 | info->io.addr_type = addr_space; | 1813 | info->io.addr_type = addr_space; |
1813 | if (addr_space == IPMI_MEM_ADDR_SPACE) | 1814 | if (addr_space == IPMI_MEM_ADDR_SPACE) |
1814 | info->io_setup = mem_setup; | 1815 | info->io_setup = mem_setup; |
1815 | else | 1816 | else |
1816 | info->io_setup = port_setup; | 1817 | info->io_setup = port_setup; |
1817 | 1818 | ||
1818 | info->io.addr = NULL; | 1819 | info->io.addr = NULL; |
1819 | info->io.regspacing = regspacing; | 1820 | info->io.regspacing = regspacing; |
1820 | if (!info->io.regspacing) | 1821 | if (!info->io.regspacing) |
1821 | info->io.regspacing = DEFAULT_REGSPACING; | 1822 | info->io.regspacing = DEFAULT_REGSPACING; |
1822 | info->io.regsize = regsize; | 1823 | info->io.regsize = regsize; |
1823 | if (!info->io.regsize) | 1824 | if (!info->io.regsize) |
1824 | info->io.regsize = DEFAULT_REGSPACING; | 1825 | info->io.regsize = DEFAULT_REGSPACING; |
1825 | info->io.regshift = regshift; | 1826 | info->io.regshift = regshift; |
1826 | info->irq = irq; | 1827 | info->irq = irq; |
1827 | if (info->irq) | 1828 | if (info->irq) |
1828 | info->irq_setup = std_irq_setup; | 1829 | info->irq_setup = std_irq_setup; |
1829 | info->slave_addr = ipmb; | 1830 | info->slave_addr = ipmb; |
1830 | 1831 | ||
1831 | if (!add_smi(info)) { | 1832 | if (!add_smi(info)) { |
1832 | if (try_smi_init(info)) | 1833 | if (try_smi_init(info)) |
1833 | cleanup_one_si(info); | 1834 | cleanup_one_si(info); |
1834 | } else { | 1835 | } else { |
1835 | kfree(info); | 1836 | kfree(info); |
1836 | } | 1837 | } |
1837 | } else { | 1838 | } else { |
1838 | /* remove */ | 1839 | /* remove */ |
1839 | struct smi_info *e, *tmp_e; | 1840 | struct smi_info *e, *tmp_e; |
1840 | 1841 | ||
1841 | mutex_lock(&smi_infos_lock); | 1842 | mutex_lock(&smi_infos_lock); |
1842 | list_for_each_entry_safe(e, tmp_e, &smi_infos, link) { | 1843 | list_for_each_entry_safe(e, tmp_e, &smi_infos, link) { |
1843 | if (e->io.addr_type != addr_space) | 1844 | if (e->io.addr_type != addr_space) |
1844 | continue; | 1845 | continue; |
1845 | if (e->si_type != si_type) | 1846 | if (e->si_type != si_type) |
1846 | continue; | 1847 | continue; |
1847 | if (e->io.addr_data == addr) | 1848 | if (e->io.addr_data == addr) |
1848 | cleanup_one_si(e); | 1849 | cleanup_one_si(e); |
1849 | } | 1850 | } |
1850 | mutex_unlock(&smi_infos_lock); | 1851 | mutex_unlock(&smi_infos_lock); |
1851 | } | 1852 | } |
1852 | } | 1853 | } |
1853 | rv = len; | 1854 | rv = len; |
1854 | out: | 1855 | out: |
1855 | kfree(str); | 1856 | kfree(str); |
1856 | return rv; | 1857 | return rv; |
1857 | } | 1858 | } |
1858 | 1859 | ||
1859 | static int __devinit hardcode_find_bmc(void) | 1860 | static int __devinit hardcode_find_bmc(void) |
1860 | { | 1861 | { |
1861 | int ret = -ENODEV; | 1862 | int ret = -ENODEV; |
1862 | int i; | 1863 | int i; |
1863 | struct smi_info *info; | 1864 | struct smi_info *info; |
1864 | 1865 | ||
1865 | for (i = 0; i < SI_MAX_PARMS; i++) { | 1866 | for (i = 0; i < SI_MAX_PARMS; i++) { |
1866 | if (!ports[i] && !addrs[i]) | 1867 | if (!ports[i] && !addrs[i]) |
1867 | continue; | 1868 | continue; |
1868 | 1869 | ||
1869 | info = smi_info_alloc(); | 1870 | info = smi_info_alloc(); |
1870 | if (!info) | 1871 | if (!info) |
1871 | return -ENOMEM; | 1872 | return -ENOMEM; |
1872 | 1873 | ||
1873 | info->addr_source = SI_HARDCODED; | 1874 | info->addr_source = SI_HARDCODED; |
1874 | printk(KERN_INFO PFX "probing via hardcoded address\n"); | 1875 | printk(KERN_INFO PFX "probing via hardcoded address\n"); |
1875 | 1876 | ||
1876 | if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) { | 1877 | if (!si_type[i] || strcmp(si_type[i], "kcs") == 0) { |
1877 | info->si_type = SI_KCS; | 1878 | info->si_type = SI_KCS; |
1878 | } else if (strcmp(si_type[i], "smic") == 0) { | 1879 | } else if (strcmp(si_type[i], "smic") == 0) { |
1879 | info->si_type = SI_SMIC; | 1880 | info->si_type = SI_SMIC; |
1880 | } else if (strcmp(si_type[i], "bt") == 0) { | 1881 | } else if (strcmp(si_type[i], "bt") == 0) { |
1881 | info->si_type = SI_BT; | 1882 | info->si_type = SI_BT; |
1882 | } else { | 1883 | } else { |
1883 | printk(KERN_WARNING PFX "Interface type specified " | 1884 | printk(KERN_WARNING PFX "Interface type specified " |
1884 | "for interface %d, was invalid: %s\n", | 1885 | "for interface %d, was invalid: %s\n", |
1885 | i, si_type[i]); | 1886 | i, si_type[i]); |
1886 | kfree(info); | 1887 | kfree(info); |
1887 | continue; | 1888 | continue; |
1888 | } | 1889 | } |
1889 | 1890 | ||
1890 | if (ports[i]) { | 1891 | if (ports[i]) { |
1891 | /* An I/O port */ | 1892 | /* An I/O port */ |
1892 | info->io_setup = port_setup; | 1893 | info->io_setup = port_setup; |
1893 | info->io.addr_data = ports[i]; | 1894 | info->io.addr_data = ports[i]; |
1894 | info->io.addr_type = IPMI_IO_ADDR_SPACE; | 1895 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
1895 | } else if (addrs[i]) { | 1896 | } else if (addrs[i]) { |
1896 | /* A memory port */ | 1897 | /* A memory port */ |
1897 | info->io_setup = mem_setup; | 1898 | info->io_setup = mem_setup; |
1898 | info->io.addr_data = addrs[i]; | 1899 | info->io.addr_data = addrs[i]; |
1899 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; | 1900 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
1900 | } else { | 1901 | } else { |
1901 | printk(KERN_WARNING PFX "Interface type specified " | 1902 | printk(KERN_WARNING PFX "Interface type specified " |
1902 | "for interface %d, but port and address were " | 1903 | "for interface %d, but port and address were " |
1903 | "not set or set to zero.\n", i); | 1904 | "not set or set to zero.\n", i); |
1904 | kfree(info); | 1905 | kfree(info); |
1905 | continue; | 1906 | continue; |
1906 | } | 1907 | } |
1907 | 1908 | ||
1908 | info->io.addr = NULL; | 1909 | info->io.addr = NULL; |
1909 | info->io.regspacing = regspacings[i]; | 1910 | info->io.regspacing = regspacings[i]; |
1910 | if (!info->io.regspacing) | 1911 | if (!info->io.regspacing) |
1911 | info->io.regspacing = DEFAULT_REGSPACING; | 1912 | info->io.regspacing = DEFAULT_REGSPACING; |
1912 | info->io.regsize = regsizes[i]; | 1913 | info->io.regsize = regsizes[i]; |
1913 | if (!info->io.regsize) | 1914 | if (!info->io.regsize) |
1914 | info->io.regsize = DEFAULT_REGSPACING; | 1915 | info->io.regsize = DEFAULT_REGSPACING; |
1915 | info->io.regshift = regshifts[i]; | 1916 | info->io.regshift = regshifts[i]; |
1916 | info->irq = irqs[i]; | 1917 | info->irq = irqs[i]; |
1917 | if (info->irq) | 1918 | if (info->irq) |
1918 | info->irq_setup = std_irq_setup; | 1919 | info->irq_setup = std_irq_setup; |
1919 | info->slave_addr = slave_addrs[i]; | 1920 | info->slave_addr = slave_addrs[i]; |
1920 | 1921 | ||
1921 | if (!add_smi(info)) { | 1922 | if (!add_smi(info)) { |
1922 | if (try_smi_init(info)) | 1923 | if (try_smi_init(info)) |
1923 | cleanup_one_si(info); | 1924 | cleanup_one_si(info); |
1924 | ret = 0; | 1925 | ret = 0; |
1925 | } else { | 1926 | } else { |
1926 | kfree(info); | 1927 | kfree(info); |
1927 | } | 1928 | } |
1928 | } | 1929 | } |
1929 | return ret; | 1930 | return ret; |
1930 | } | 1931 | } |
1931 | 1932 | ||
1932 | #ifdef CONFIG_ACPI | 1933 | #ifdef CONFIG_ACPI |
1933 | 1934 | ||
1934 | #include <linux/acpi.h> | 1935 | #include <linux/acpi.h> |
1935 | 1936 | ||
1936 | /* | 1937 | /* |
1937 | * Once we get an ACPI failure, we don't try any more, because we go | 1938 | * Once we get an ACPI failure, we don't try any more, because we go |
1938 | * through the tables sequentially. Once we don't find a table, there | 1939 | * through the tables sequentially. Once we don't find a table, there |
1939 | * are no more. | 1940 | * are no more. |
1940 | */ | 1941 | */ |
1941 | static int acpi_failure; | 1942 | static int acpi_failure; |
1942 | 1943 | ||
1943 | /* For GPE-type interrupts. */ | 1944 | /* For GPE-type interrupts. */ |
1944 | static u32 ipmi_acpi_gpe(acpi_handle gpe_device, | 1945 | static u32 ipmi_acpi_gpe(acpi_handle gpe_device, |
1945 | u32 gpe_number, void *context) | 1946 | u32 gpe_number, void *context) |
1946 | { | 1947 | { |
1947 | struct smi_info *smi_info = context; | 1948 | struct smi_info *smi_info = context; |
1948 | unsigned long flags; | 1949 | unsigned long flags; |
1949 | #ifdef DEBUG_TIMING | 1950 | #ifdef DEBUG_TIMING |
1950 | struct timeval t; | 1951 | struct timeval t; |
1951 | #endif | 1952 | #endif |
1952 | 1953 | ||
1953 | spin_lock_irqsave(&(smi_info->si_lock), flags); | 1954 | spin_lock_irqsave(&(smi_info->si_lock), flags); |
1954 | 1955 | ||
1955 | smi_inc_stat(smi_info, interrupts); | 1956 | smi_inc_stat(smi_info, interrupts); |
1956 | 1957 | ||
1957 | #ifdef DEBUG_TIMING | 1958 | #ifdef DEBUG_TIMING |
1958 | do_gettimeofday(&t); | 1959 | do_gettimeofday(&t); |
1959 | printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec); | 1960 | printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec); |
1960 | #endif | 1961 | #endif |
1961 | smi_event_handler(smi_info, 0); | 1962 | smi_event_handler(smi_info, 0); |
1962 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); | 1963 | spin_unlock_irqrestore(&(smi_info->si_lock), flags); |
1963 | 1964 | ||
1964 | return ACPI_INTERRUPT_HANDLED; | 1965 | return ACPI_INTERRUPT_HANDLED; |
1965 | } | 1966 | } |
1966 | 1967 | ||
1967 | static void acpi_gpe_irq_cleanup(struct smi_info *info) | 1968 | static void acpi_gpe_irq_cleanup(struct smi_info *info) |
1968 | { | 1969 | { |
1969 | if (!info->irq) | 1970 | if (!info->irq) |
1970 | return; | 1971 | return; |
1971 | 1972 | ||
1972 | acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe); | 1973 | acpi_remove_gpe_handler(NULL, info->irq, &ipmi_acpi_gpe); |
1973 | } | 1974 | } |
1974 | 1975 | ||
1975 | static int acpi_gpe_irq_setup(struct smi_info *info) | 1976 | static int acpi_gpe_irq_setup(struct smi_info *info) |
1976 | { | 1977 | { |
1977 | acpi_status status; | 1978 | acpi_status status; |
1978 | 1979 | ||
1979 | if (!info->irq) | 1980 | if (!info->irq) |
1980 | return 0; | 1981 | return 0; |
1981 | 1982 | ||
1982 | /* FIXME - is level triggered right? */ | 1983 | /* FIXME - is level triggered right? */ |
1983 | status = acpi_install_gpe_handler(NULL, | 1984 | status = acpi_install_gpe_handler(NULL, |
1984 | info->irq, | 1985 | info->irq, |
1985 | ACPI_GPE_LEVEL_TRIGGERED, | 1986 | ACPI_GPE_LEVEL_TRIGGERED, |
1986 | &ipmi_acpi_gpe, | 1987 | &ipmi_acpi_gpe, |
1987 | info); | 1988 | info); |
1988 | if (status != AE_OK) { | 1989 | if (status != AE_OK) { |
1989 | dev_warn(info->dev, "%s unable to claim ACPI GPE %d," | 1990 | dev_warn(info->dev, "%s unable to claim ACPI GPE %d," |
1990 | " running polled\n", DEVICE_NAME, info->irq); | 1991 | " running polled\n", DEVICE_NAME, info->irq); |
1991 | info->irq = 0; | 1992 | info->irq = 0; |
1992 | return -EINVAL; | 1993 | return -EINVAL; |
1993 | } else { | 1994 | } else { |
1994 | info->irq_cleanup = acpi_gpe_irq_cleanup; | 1995 | info->irq_cleanup = acpi_gpe_irq_cleanup; |
1995 | dev_info(info->dev, "Using ACPI GPE %d\n", info->irq); | 1996 | dev_info(info->dev, "Using ACPI GPE %d\n", info->irq); |
1996 | return 0; | 1997 | return 0; |
1997 | } | 1998 | } |
1998 | } | 1999 | } |
1999 | 2000 | ||
2000 | /* | 2001 | /* |
2001 | * Defined at | 2002 | * Defined at |
2002 | * http://h21007.www2.hp.com/portal/download/files/unprot/hpspmi.pdf | 2003 | * http://h21007.www2.hp.com/portal/download/files/unprot/hpspmi.pdf |
2003 | */ | 2004 | */ |
2004 | struct SPMITable { | 2005 | struct SPMITable { |
2005 | s8 Signature[4]; | 2006 | s8 Signature[4]; |
2006 | u32 Length; | 2007 | u32 Length; |
2007 | u8 Revision; | 2008 | u8 Revision; |
2008 | u8 Checksum; | 2009 | u8 Checksum; |
2009 | s8 OEMID[6]; | 2010 | s8 OEMID[6]; |
2010 | s8 OEMTableID[8]; | 2011 | s8 OEMTableID[8]; |
2011 | s8 OEMRevision[4]; | 2012 | s8 OEMRevision[4]; |
2012 | s8 CreatorID[4]; | 2013 | s8 CreatorID[4]; |
2013 | s8 CreatorRevision[4]; | 2014 | s8 CreatorRevision[4]; |
2014 | u8 InterfaceType; | 2015 | u8 InterfaceType; |
2015 | u8 IPMIlegacy; | 2016 | u8 IPMIlegacy; |
2016 | s16 SpecificationRevision; | 2017 | s16 SpecificationRevision; |
2017 | 2018 | ||
2018 | /* | 2019 | /* |
2019 | * Bit 0 - SCI interrupt supported | 2020 | * Bit 0 - SCI interrupt supported |
2020 | * Bit 1 - I/O APIC/SAPIC | 2021 | * Bit 1 - I/O APIC/SAPIC |
2021 | */ | 2022 | */ |
2022 | u8 InterruptType; | 2023 | u8 InterruptType; |
2023 | 2024 | ||
2024 | /* | 2025 | /* |
2025 | * If bit 0 of InterruptType is set, then this is the SCI | 2026 | * If bit 0 of InterruptType is set, then this is the SCI |
2026 | * interrupt in the GPEx_STS register. | 2027 | * interrupt in the GPEx_STS register. |
2027 | */ | 2028 | */ |
2028 | u8 GPE; | 2029 | u8 GPE; |
2029 | 2030 | ||
2030 | s16 Reserved; | 2031 | s16 Reserved; |
2031 | 2032 | ||
2032 | /* | 2033 | /* |
2033 | * If bit 1 of InterruptType is set, then this is the I/O | 2034 | * If bit 1 of InterruptType is set, then this is the I/O |
2034 | * APIC/SAPIC interrupt. | 2035 | * APIC/SAPIC interrupt. |
2035 | */ | 2036 | */ |
2036 | u32 GlobalSystemInterrupt; | 2037 | u32 GlobalSystemInterrupt; |
2037 | 2038 | ||
2038 | /* The actual register address. */ | 2039 | /* The actual register address. */ |
2039 | struct acpi_generic_address addr; | 2040 | struct acpi_generic_address addr; |
2040 | 2041 | ||
2041 | u8 UID[4]; | 2042 | u8 UID[4]; |
2042 | 2043 | ||
2043 | s8 spmi_id[1]; /* A '\0' terminated array starts here. */ | 2044 | s8 spmi_id[1]; /* A '\0' terminated array starts here. */ |
2044 | }; | 2045 | }; |
2045 | 2046 | ||
2046 | static int __devinit try_init_spmi(struct SPMITable *spmi) | 2047 | static int __devinit try_init_spmi(struct SPMITable *spmi) |
2047 | { | 2048 | { |
2048 | struct smi_info *info; | 2049 | struct smi_info *info; |
2049 | 2050 | ||
2050 | if (spmi->IPMIlegacy != 1) { | 2051 | if (spmi->IPMIlegacy != 1) { |
2051 | printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy); | 2052 | printk(KERN_INFO PFX "Bad SPMI legacy %d\n", spmi->IPMIlegacy); |
2052 | return -ENODEV; | 2053 | return -ENODEV; |
2053 | } | 2054 | } |
2054 | 2055 | ||
2055 | info = smi_info_alloc(); | 2056 | info = smi_info_alloc(); |
2056 | if (!info) { | 2057 | if (!info) { |
2057 | printk(KERN_ERR PFX "Could not allocate SI data (3)\n"); | 2058 | printk(KERN_ERR PFX "Could not allocate SI data (3)\n"); |
2058 | return -ENOMEM; | 2059 | return -ENOMEM; |
2059 | } | 2060 | } |
2060 | 2061 | ||
2061 | info->addr_source = SI_SPMI; | 2062 | info->addr_source = SI_SPMI; |
2062 | printk(KERN_INFO PFX "probing via SPMI\n"); | 2063 | printk(KERN_INFO PFX "probing via SPMI\n"); |
2063 | 2064 | ||
2064 | /* Figure out the interface type. */ | 2065 | /* Figure out the interface type. */ |
2065 | switch (spmi->InterfaceType) { | 2066 | switch (spmi->InterfaceType) { |
2066 | case 1: /* KCS */ | 2067 | case 1: /* KCS */ |
2067 | info->si_type = SI_KCS; | 2068 | info->si_type = SI_KCS; |
2068 | break; | 2069 | break; |
2069 | case 2: /* SMIC */ | 2070 | case 2: /* SMIC */ |
2070 | info->si_type = SI_SMIC; | 2071 | info->si_type = SI_SMIC; |
2071 | break; | 2072 | break; |
2072 | case 3: /* BT */ | 2073 | case 3: /* BT */ |
2073 | info->si_type = SI_BT; | 2074 | info->si_type = SI_BT; |
2074 | break; | 2075 | break; |
2075 | default: | 2076 | default: |
2076 | printk(KERN_INFO PFX "Unknown ACPI/SPMI SI type %d\n", | 2077 | printk(KERN_INFO PFX "Unknown ACPI/SPMI SI type %d\n", |
2077 | spmi->InterfaceType); | 2078 | spmi->InterfaceType); |
2078 | kfree(info); | 2079 | kfree(info); |
2079 | return -EIO; | 2080 | return -EIO; |
2080 | } | 2081 | } |
2081 | 2082 | ||
2082 | if (spmi->InterruptType & 1) { | 2083 | if (spmi->InterruptType & 1) { |
2083 | /* We've got a GPE interrupt. */ | 2084 | /* We've got a GPE interrupt. */ |
2084 | info->irq = spmi->GPE; | 2085 | info->irq = spmi->GPE; |
2085 | info->irq_setup = acpi_gpe_irq_setup; | 2086 | info->irq_setup = acpi_gpe_irq_setup; |
2086 | } else if (spmi->InterruptType & 2) { | 2087 | } else if (spmi->InterruptType & 2) { |
2087 | /* We've got an APIC/SAPIC interrupt. */ | 2088 | /* We've got an APIC/SAPIC interrupt. */ |
2088 | info->irq = spmi->GlobalSystemInterrupt; | 2089 | info->irq = spmi->GlobalSystemInterrupt; |
2089 | info->irq_setup = std_irq_setup; | 2090 | info->irq_setup = std_irq_setup; |
2090 | } else { | 2091 | } else { |
2091 | /* Use the default interrupt setting. */ | 2092 | /* Use the default interrupt setting. */ |
2092 | info->irq = 0; | 2093 | info->irq = 0; |
2093 | info->irq_setup = NULL; | 2094 | info->irq_setup = NULL; |
2094 | } | 2095 | } |
2095 | 2096 | ||
2096 | if (spmi->addr.bit_width) { | 2097 | if (spmi->addr.bit_width) { |
2097 | /* A (hopefully) properly formed register bit width. */ | 2098 | /* A (hopefully) properly formed register bit width. */ |
2098 | info->io.regspacing = spmi->addr.bit_width / 8; | 2099 | info->io.regspacing = spmi->addr.bit_width / 8; |
2099 | } else { | 2100 | } else { |
2100 | info->io.regspacing = DEFAULT_REGSPACING; | 2101 | info->io.regspacing = DEFAULT_REGSPACING; |
2101 | } | 2102 | } |
2102 | info->io.regsize = info->io.regspacing; | 2103 | info->io.regsize = info->io.regspacing; |
2103 | info->io.regshift = spmi->addr.bit_offset; | 2104 | info->io.regshift = spmi->addr.bit_offset; |
2104 | 2105 | ||
2105 | if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { | 2106 | if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { |
2106 | info->io_setup = mem_setup; | 2107 | info->io_setup = mem_setup; |
2107 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; | 2108 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
2108 | } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) { | 2109 | } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) { |
2109 | info->io_setup = port_setup; | 2110 | info->io_setup = port_setup; |
2110 | info->io.addr_type = IPMI_IO_ADDR_SPACE; | 2111 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
2111 | } else { | 2112 | } else { |
2112 | kfree(info); | 2113 | kfree(info); |
2113 | printk(KERN_WARNING PFX "Unknown ACPI I/O Address type\n"); | 2114 | printk(KERN_WARNING PFX "Unknown ACPI I/O Address type\n"); |
2114 | return -EIO; | 2115 | return -EIO; |
2115 | } | 2116 | } |
2116 | info->io.addr_data = spmi->addr.address; | 2117 | info->io.addr_data = spmi->addr.address; |
2117 | 2118 | ||
2118 | pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n", | 2119 | pr_info("ipmi_si: SPMI: %s %#lx regsize %d spacing %d irq %d\n", |
2119 | (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem", | 2120 | (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem", |
2120 | info->io.addr_data, info->io.regsize, info->io.regspacing, | 2121 | info->io.addr_data, info->io.regsize, info->io.regspacing, |
2121 | info->irq); | 2122 | info->irq); |
2122 | 2123 | ||
2123 | if (add_smi(info)) | 2124 | if (add_smi(info)) |
2124 | kfree(info); | 2125 | kfree(info); |
2125 | 2126 | ||
2126 | return 0; | 2127 | return 0; |
2127 | } | 2128 | } |
2128 | 2129 | ||
2129 | static void __devinit spmi_find_bmc(void) | 2130 | static void __devinit spmi_find_bmc(void) |
2130 | { | 2131 | { |
2131 | acpi_status status; | 2132 | acpi_status status; |
2132 | struct SPMITable *spmi; | 2133 | struct SPMITable *spmi; |
2133 | int i; | 2134 | int i; |
2134 | 2135 | ||
2135 | if (acpi_disabled) | 2136 | if (acpi_disabled) |
2136 | return; | 2137 | return; |
2137 | 2138 | ||
2138 | if (acpi_failure) | 2139 | if (acpi_failure) |
2139 | return; | 2140 | return; |
2140 | 2141 | ||
2141 | for (i = 0; ; i++) { | 2142 | for (i = 0; ; i++) { |
2142 | status = acpi_get_table(ACPI_SIG_SPMI, i+1, | 2143 | status = acpi_get_table(ACPI_SIG_SPMI, i+1, |
2143 | (struct acpi_table_header **)&spmi); | 2144 | (struct acpi_table_header **)&spmi); |
2144 | if (status != AE_OK) | 2145 | if (status != AE_OK) |
2145 | return; | 2146 | return; |
2146 | 2147 | ||
2147 | try_init_spmi(spmi); | 2148 | try_init_spmi(spmi); |
2148 | } | 2149 | } |
2149 | } | 2150 | } |
2150 | 2151 | ||
2151 | static int __devinit ipmi_pnp_probe(struct pnp_dev *dev, | 2152 | static int __devinit ipmi_pnp_probe(struct pnp_dev *dev, |
2152 | const struct pnp_device_id *dev_id) | 2153 | const struct pnp_device_id *dev_id) |
2153 | { | 2154 | { |
2154 | struct acpi_device *acpi_dev; | 2155 | struct acpi_device *acpi_dev; |
2155 | struct smi_info *info; | 2156 | struct smi_info *info; |
2156 | struct resource *res, *res_second; | 2157 | struct resource *res, *res_second; |
2157 | acpi_handle handle; | 2158 | acpi_handle handle; |
2158 | acpi_status status; | 2159 | acpi_status status; |
2159 | unsigned long long tmp; | 2160 | unsigned long long tmp; |
2160 | 2161 | ||
2161 | acpi_dev = pnp_acpi_device(dev); | 2162 | acpi_dev = pnp_acpi_device(dev); |
2162 | if (!acpi_dev) | 2163 | if (!acpi_dev) |
2163 | return -ENODEV; | 2164 | return -ENODEV; |
2164 | 2165 | ||
2165 | info = smi_info_alloc(); | 2166 | info = smi_info_alloc(); |
2166 | if (!info) | 2167 | if (!info) |
2167 | return -ENOMEM; | 2168 | return -ENOMEM; |
2168 | 2169 | ||
2169 | info->addr_source = SI_ACPI; | 2170 | info->addr_source = SI_ACPI; |
2170 | printk(KERN_INFO PFX "probing via ACPI\n"); | 2171 | printk(KERN_INFO PFX "probing via ACPI\n"); |
2171 | 2172 | ||
2172 | handle = acpi_dev->handle; | 2173 | handle = acpi_dev->handle; |
2173 | info->addr_info.acpi_info.acpi_handle = handle; | 2174 | info->addr_info.acpi_info.acpi_handle = handle; |
2174 | 2175 | ||
2175 | /* _IFT tells us the interface type: KCS, BT, etc */ | 2176 | /* _IFT tells us the interface type: KCS, BT, etc */ |
2176 | status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp); | 2177 | status = acpi_evaluate_integer(handle, "_IFT", NULL, &tmp); |
2177 | if (ACPI_FAILURE(status)) | 2178 | if (ACPI_FAILURE(status)) |
2178 | goto err_free; | 2179 | goto err_free; |
2179 | 2180 | ||
2180 | switch (tmp) { | 2181 | switch (tmp) { |
2181 | case 1: | 2182 | case 1: |
2182 | info->si_type = SI_KCS; | 2183 | info->si_type = SI_KCS; |
2183 | break; | 2184 | break; |
2184 | case 2: | 2185 | case 2: |
2185 | info->si_type = SI_SMIC; | 2186 | info->si_type = SI_SMIC; |
2186 | break; | 2187 | break; |
2187 | case 3: | 2188 | case 3: |
2188 | info->si_type = SI_BT; | 2189 | info->si_type = SI_BT; |
2189 | break; | 2190 | break; |
2190 | default: | 2191 | default: |
2191 | dev_info(&dev->dev, "unknown IPMI type %lld\n", tmp); | 2192 | dev_info(&dev->dev, "unknown IPMI type %lld\n", tmp); |
2192 | goto err_free; | 2193 | goto err_free; |
2193 | } | 2194 | } |
2194 | 2195 | ||
2195 | res = pnp_get_resource(dev, IORESOURCE_IO, 0); | 2196 | res = pnp_get_resource(dev, IORESOURCE_IO, 0); |
2196 | if (res) { | 2197 | if (res) { |
2197 | info->io_setup = port_setup; | 2198 | info->io_setup = port_setup; |
2198 | info->io.addr_type = IPMI_IO_ADDR_SPACE; | 2199 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
2199 | } else { | 2200 | } else { |
2200 | res = pnp_get_resource(dev, IORESOURCE_MEM, 0); | 2201 | res = pnp_get_resource(dev, IORESOURCE_MEM, 0); |
2201 | if (res) { | 2202 | if (res) { |
2202 | info->io_setup = mem_setup; | 2203 | info->io_setup = mem_setup; |
2203 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; | 2204 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
2204 | } | 2205 | } |
2205 | } | 2206 | } |
2206 | if (!res) { | 2207 | if (!res) { |
2207 | dev_err(&dev->dev, "no I/O or memory address\n"); | 2208 | dev_err(&dev->dev, "no I/O or memory address\n"); |
2208 | goto err_free; | 2209 | goto err_free; |
2209 | } | 2210 | } |
2210 | info->io.addr_data = res->start; | 2211 | info->io.addr_data = res->start; |
2211 | 2212 | ||
2212 | info->io.regspacing = DEFAULT_REGSPACING; | 2213 | info->io.regspacing = DEFAULT_REGSPACING; |
2213 | res_second = pnp_get_resource(dev, | 2214 | res_second = pnp_get_resource(dev, |
2214 | (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? | 2215 | (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? |
2215 | IORESOURCE_IO : IORESOURCE_MEM, | 2216 | IORESOURCE_IO : IORESOURCE_MEM, |
2216 | 1); | 2217 | 1); |
2217 | if (res_second) { | 2218 | if (res_second) { |
2218 | if (res_second->start > info->io.addr_data) | 2219 | if (res_second->start > info->io.addr_data) |
2219 | info->io.regspacing = res_second->start - info->io.addr_data; | 2220 | info->io.regspacing = res_second->start - info->io.addr_data; |
2220 | } | 2221 | } |
2221 | info->io.regsize = DEFAULT_REGSPACING; | 2222 | info->io.regsize = DEFAULT_REGSPACING; |
2222 | info->io.regshift = 0; | 2223 | info->io.regshift = 0; |
2223 | 2224 | ||
2224 | /* If _GPE exists, use it; otherwise use standard interrupts */ | 2225 | /* If _GPE exists, use it; otherwise use standard interrupts */ |
2225 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp); | 2226 | status = acpi_evaluate_integer(handle, "_GPE", NULL, &tmp); |
2226 | if (ACPI_SUCCESS(status)) { | 2227 | if (ACPI_SUCCESS(status)) { |
2227 | info->irq = tmp; | 2228 | info->irq = tmp; |
2228 | info->irq_setup = acpi_gpe_irq_setup; | 2229 | info->irq_setup = acpi_gpe_irq_setup; |
2229 | } else if (pnp_irq_valid(dev, 0)) { | 2230 | } else if (pnp_irq_valid(dev, 0)) { |
2230 | info->irq = pnp_irq(dev, 0); | 2231 | info->irq = pnp_irq(dev, 0); |
2231 | info->irq_setup = std_irq_setup; | 2232 | info->irq_setup = std_irq_setup; |
2232 | } | 2233 | } |
2233 | 2234 | ||
2234 | info->dev = &dev->dev; | 2235 | info->dev = &dev->dev; |
2235 | pnp_set_drvdata(dev, info); | 2236 | pnp_set_drvdata(dev, info); |
2236 | 2237 | ||
2237 | dev_info(info->dev, "%pR regsize %d spacing %d irq %d\n", | 2238 | dev_info(info->dev, "%pR regsize %d spacing %d irq %d\n", |
2238 | res, info->io.regsize, info->io.regspacing, | 2239 | res, info->io.regsize, info->io.regspacing, |
2239 | info->irq); | 2240 | info->irq); |
2240 | 2241 | ||
2241 | if (add_smi(info)) | 2242 | if (add_smi(info)) |
2242 | goto err_free; | 2243 | goto err_free; |
2243 | 2244 | ||
2244 | return 0; | 2245 | return 0; |
2245 | 2246 | ||
2246 | err_free: | 2247 | err_free: |
2247 | kfree(info); | 2248 | kfree(info); |
2248 | return -EINVAL; | 2249 | return -EINVAL; |
2249 | } | 2250 | } |
2250 | 2251 | ||
2251 | static void __devexit ipmi_pnp_remove(struct pnp_dev *dev) | 2252 | static void __devexit ipmi_pnp_remove(struct pnp_dev *dev) |
2252 | { | 2253 | { |
2253 | struct smi_info *info = pnp_get_drvdata(dev); | 2254 | struct smi_info *info = pnp_get_drvdata(dev); |
2254 | 2255 | ||
2255 | cleanup_one_si(info); | 2256 | cleanup_one_si(info); |
2256 | } | 2257 | } |
2257 | 2258 | ||
2258 | static const struct pnp_device_id pnp_dev_table[] = { | 2259 | static const struct pnp_device_id pnp_dev_table[] = { |
2259 | {"IPI0001", 0}, | 2260 | {"IPI0001", 0}, |
2260 | {"", 0}, | 2261 | {"", 0}, |
2261 | }; | 2262 | }; |
2262 | 2263 | ||
2263 | static struct pnp_driver ipmi_pnp_driver = { | 2264 | static struct pnp_driver ipmi_pnp_driver = { |
2264 | .name = DEVICE_NAME, | 2265 | .name = DEVICE_NAME, |
2265 | .probe = ipmi_pnp_probe, | 2266 | .probe = ipmi_pnp_probe, |
2266 | .remove = __devexit_p(ipmi_pnp_remove), | 2267 | .remove = __devexit_p(ipmi_pnp_remove), |
2267 | .id_table = pnp_dev_table, | 2268 | .id_table = pnp_dev_table, |
2268 | }; | 2269 | }; |
2269 | #endif | 2270 | #endif |
2270 | 2271 | ||
2271 | #ifdef CONFIG_DMI | 2272 | #ifdef CONFIG_DMI |
2272 | struct dmi_ipmi_data { | 2273 | struct dmi_ipmi_data { |
2273 | u8 type; | 2274 | u8 type; |
2274 | u8 addr_space; | 2275 | u8 addr_space; |
2275 | unsigned long base_addr; | 2276 | unsigned long base_addr; |
2276 | u8 irq; | 2277 | u8 irq; |
2277 | u8 offset; | 2278 | u8 offset; |
2278 | u8 slave_addr; | 2279 | u8 slave_addr; |
2279 | }; | 2280 | }; |
2280 | 2281 | ||
2281 | static int __devinit decode_dmi(const struct dmi_header *dm, | 2282 | static int __devinit decode_dmi(const struct dmi_header *dm, |
2282 | struct dmi_ipmi_data *dmi) | 2283 | struct dmi_ipmi_data *dmi) |
2283 | { | 2284 | { |
2284 | const u8 *data = (const u8 *)dm; | 2285 | const u8 *data = (const u8 *)dm; |
2285 | unsigned long base_addr; | 2286 | unsigned long base_addr; |
2286 | u8 reg_spacing; | 2287 | u8 reg_spacing; |
2287 | u8 len = dm->length; | 2288 | u8 len = dm->length; |
2288 | 2289 | ||
2289 | dmi->type = data[4]; | 2290 | dmi->type = data[4]; |
2290 | 2291 | ||
2291 | memcpy(&base_addr, data+8, sizeof(unsigned long)); | 2292 | memcpy(&base_addr, data+8, sizeof(unsigned long)); |
2292 | if (len >= 0x11) { | 2293 | if (len >= 0x11) { |
2293 | if (base_addr & 1) { | 2294 | if (base_addr & 1) { |
2294 | /* I/O */ | 2295 | /* I/O */ |
2295 | base_addr &= 0xFFFE; | 2296 | base_addr &= 0xFFFE; |
2296 | dmi->addr_space = IPMI_IO_ADDR_SPACE; | 2297 | dmi->addr_space = IPMI_IO_ADDR_SPACE; |
2297 | } else | 2298 | } else |
2298 | /* Memory */ | 2299 | /* Memory */ |
2299 | dmi->addr_space = IPMI_MEM_ADDR_SPACE; | 2300 | dmi->addr_space = IPMI_MEM_ADDR_SPACE; |
2300 | 2301 | ||
2301 | /* If bit 4 of byte 0x10 is set, then the lsb for the address | 2302 | /* If bit 4 of byte 0x10 is set, then the lsb for the address |
2302 | is odd. */ | 2303 | is odd. */ |
2303 | dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4); | 2304 | dmi->base_addr = base_addr | ((data[0x10] & 0x10) >> 4); |
2304 | 2305 | ||
2305 | dmi->irq = data[0x11]; | 2306 | dmi->irq = data[0x11]; |
2306 | 2307 | ||
2307 | /* The top two bits of byte 0x10 hold the register spacing. */ | 2308 | /* The top two bits of byte 0x10 hold the register spacing. */ |
2308 | reg_spacing = (data[0x10] & 0xC0) >> 6; | 2309 | reg_spacing = (data[0x10] & 0xC0) >> 6; |
2309 | switch (reg_spacing) { | 2310 | switch (reg_spacing) { |
2310 | case 0x00: /* Byte boundaries */ | 2311 | case 0x00: /* Byte boundaries */ |
2311 | dmi->offset = 1; | 2312 | dmi->offset = 1; |
2312 | break; | 2313 | break; |
2313 | case 0x01: /* 32-bit boundaries */ | 2314 | case 0x01: /* 32-bit boundaries */ |
2314 | dmi->offset = 4; | 2315 | dmi->offset = 4; |
2315 | break; | 2316 | break; |
2316 | case 0x02: /* 16-byte boundaries */ | 2317 | case 0x02: /* 16-byte boundaries */ |
2317 | dmi->offset = 16; | 2318 | dmi->offset = 16; |
2318 | break; | 2319 | break; |
2319 | default: | 2320 | default: |
2320 | /* Some other interface, just ignore it. */ | 2321 | /* Some other interface, just ignore it. */ |
2321 | return -EIO; | 2322 | return -EIO; |
2322 | } | 2323 | } |
2323 | } else { | 2324 | } else { |
2324 | /* Old DMI spec. */ | 2325 | /* Old DMI spec. */ |
2325 | /* | 2326 | /* |
2326 | * Note that technically, the lower bit of the base | 2327 | * Note that technically, the lower bit of the base |
2327 | * address should be 1 if the address is I/O and 0 if | 2328 | * address should be 1 if the address is I/O and 0 if |
2328 | * the address is in memory. So many systems get that | 2329 | * the address is in memory. So many systems get that |
2329 | * wrong (and all that I have seen are I/O) so we just | 2330 | * wrong (and all that I have seen are I/O) so we just |
2330 | * ignore that bit and assume I/O. Systems that use | 2331 | * ignore that bit and assume I/O. Systems that use |
2331 | * memory should use the newer spec, anyway. | 2332 | * memory should use the newer spec, anyway. |
2332 | */ | 2333 | */ |
2333 | dmi->base_addr = base_addr & 0xfffe; | 2334 | dmi->base_addr = base_addr & 0xfffe; |
2334 | dmi->addr_space = IPMI_IO_ADDR_SPACE; | 2335 | dmi->addr_space = IPMI_IO_ADDR_SPACE; |
2335 | dmi->offset = 1; | 2336 | dmi->offset = 1; |
2336 | } | 2337 | } |
2337 | 2338 | ||
2338 | dmi->slave_addr = data[6]; | 2339 | dmi->slave_addr = data[6]; |
2339 | 2340 | ||
2340 | return 0; | 2341 | return 0; |
2341 | } | 2342 | } |
2342 | 2343 | ||
2343 | static void __devinit try_init_dmi(struct dmi_ipmi_data *ipmi_data) | 2344 | static void __devinit try_init_dmi(struct dmi_ipmi_data *ipmi_data) |
2344 | { | 2345 | { |
2345 | struct smi_info *info; | 2346 | struct smi_info *info; |
2346 | 2347 | ||
2347 | info = smi_info_alloc(); | 2348 | info = smi_info_alloc(); |
2348 | if (!info) { | 2349 | if (!info) { |
2349 | printk(KERN_ERR PFX "Could not allocate SI data\n"); | 2350 | printk(KERN_ERR PFX "Could not allocate SI data\n"); |
2350 | return; | 2351 | return; |
2351 | } | 2352 | } |
2352 | 2353 | ||
2353 | info->addr_source = SI_SMBIOS; | 2354 | info->addr_source = SI_SMBIOS; |
2354 | printk(KERN_INFO PFX "probing via SMBIOS\n"); | 2355 | printk(KERN_INFO PFX "probing via SMBIOS\n"); |
2355 | 2356 | ||
2356 | switch (ipmi_data->type) { | 2357 | switch (ipmi_data->type) { |
2357 | case 0x01: /* KCS */ | 2358 | case 0x01: /* KCS */ |
2358 | info->si_type = SI_KCS; | 2359 | info->si_type = SI_KCS; |
2359 | break; | 2360 | break; |
2360 | case 0x02: /* SMIC */ | 2361 | case 0x02: /* SMIC */ |
2361 | info->si_type = SI_SMIC; | 2362 | info->si_type = SI_SMIC; |
2362 | break; | 2363 | break; |
2363 | case 0x03: /* BT */ | 2364 | case 0x03: /* BT */ |
2364 | info->si_type = SI_BT; | 2365 | info->si_type = SI_BT; |
2365 | break; | 2366 | break; |
2366 | default: | 2367 | default: |
2367 | kfree(info); | 2368 | kfree(info); |
2368 | return; | 2369 | return; |
2369 | } | 2370 | } |
2370 | 2371 | ||
2371 | switch (ipmi_data->addr_space) { | 2372 | switch (ipmi_data->addr_space) { |
2372 | case IPMI_MEM_ADDR_SPACE: | 2373 | case IPMI_MEM_ADDR_SPACE: |
2373 | info->io_setup = mem_setup; | 2374 | info->io_setup = mem_setup; |
2374 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; | 2375 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
2375 | break; | 2376 | break; |
2376 | 2377 | ||
2377 | case IPMI_IO_ADDR_SPACE: | 2378 | case IPMI_IO_ADDR_SPACE: |
2378 | info->io_setup = port_setup; | 2379 | info->io_setup = port_setup; |
2379 | info->io.addr_type = IPMI_IO_ADDR_SPACE; | 2380 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
2380 | break; | 2381 | break; |
2381 | 2382 | ||
2382 | default: | 2383 | default: |
2383 | kfree(info); | 2384 | kfree(info); |
2384 | printk(KERN_WARNING PFX "Unknown SMBIOS I/O Address type: %d\n", | 2385 | printk(KERN_WARNING PFX "Unknown SMBIOS I/O Address type: %d\n", |
2385 | ipmi_data->addr_space); | 2386 | ipmi_data->addr_space); |
2386 | return; | 2387 | return; |
2387 | } | 2388 | } |
2388 | info->io.addr_data = ipmi_data->base_addr; | 2389 | info->io.addr_data = ipmi_data->base_addr; |
2389 | 2390 | ||
2390 | info->io.regspacing = ipmi_data->offset; | 2391 | info->io.regspacing = ipmi_data->offset; |
2391 | if (!info->io.regspacing) | 2392 | if (!info->io.regspacing) |
2392 | info->io.regspacing = DEFAULT_REGSPACING; | 2393 | info->io.regspacing = DEFAULT_REGSPACING; |
2393 | info->io.regsize = DEFAULT_REGSPACING; | 2394 | info->io.regsize = DEFAULT_REGSPACING; |
2394 | info->io.regshift = 0; | 2395 | info->io.regshift = 0; |
2395 | 2396 | ||
2396 | info->slave_addr = ipmi_data->slave_addr; | 2397 | info->slave_addr = ipmi_data->slave_addr; |
2397 | 2398 | ||
2398 | info->irq = ipmi_data->irq; | 2399 | info->irq = ipmi_data->irq; |
2399 | if (info->irq) | 2400 | if (info->irq) |
2400 | info->irq_setup = std_irq_setup; | 2401 | info->irq_setup = std_irq_setup; |
2401 | 2402 | ||
2402 | pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n", | 2403 | pr_info("ipmi_si: SMBIOS: %s %#lx regsize %d spacing %d irq %d\n", |
2403 | (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem", | 2404 | (info->io.addr_type == IPMI_IO_ADDR_SPACE) ? "io" : "mem", |
2404 | info->io.addr_data, info->io.regsize, info->io.regspacing, | 2405 | info->io.addr_data, info->io.regsize, info->io.regspacing, |
2405 | info->irq); | 2406 | info->irq); |
2406 | 2407 | ||
2407 | if (add_smi(info)) | 2408 | if (add_smi(info)) |
2408 | kfree(info); | 2409 | kfree(info); |
2409 | } | 2410 | } |
2410 | 2411 | ||
2411 | static void __devinit dmi_find_bmc(void) | 2412 | static void __devinit dmi_find_bmc(void) |
2412 | { | 2413 | { |
2413 | const struct dmi_device *dev = NULL; | 2414 | const struct dmi_device *dev = NULL; |
2414 | struct dmi_ipmi_data data; | 2415 | struct dmi_ipmi_data data; |
2415 | int rv; | 2416 | int rv; |
2416 | 2417 | ||
2417 | while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { | 2418 | while ((dev = dmi_find_device(DMI_DEV_TYPE_IPMI, NULL, dev))) { |
2418 | memset(&data, 0, sizeof(data)); | 2419 | memset(&data, 0, sizeof(data)); |
2419 | rv = decode_dmi((const struct dmi_header *) dev->device_data, | 2420 | rv = decode_dmi((const struct dmi_header *) dev->device_data, |
2420 | &data); | 2421 | &data); |
2421 | if (!rv) | 2422 | if (!rv) |
2422 | try_init_dmi(&data); | 2423 | try_init_dmi(&data); |
2423 | } | 2424 | } |
2424 | } | 2425 | } |
2425 | #endif /* CONFIG_DMI */ | 2426 | #endif /* CONFIG_DMI */ |
2426 | 2427 | ||
2427 | #ifdef CONFIG_PCI | 2428 | #ifdef CONFIG_PCI |
2428 | 2429 | ||
2429 | #define PCI_ERMC_CLASSCODE 0x0C0700 | 2430 | #define PCI_ERMC_CLASSCODE 0x0C0700 |
2430 | #define PCI_ERMC_CLASSCODE_MASK 0xffffff00 | 2431 | #define PCI_ERMC_CLASSCODE_MASK 0xffffff00 |
2431 | #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff | 2432 | #define PCI_ERMC_CLASSCODE_TYPE_MASK 0xff |
2432 | #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00 | 2433 | #define PCI_ERMC_CLASSCODE_TYPE_SMIC 0x00 |
2433 | #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01 | 2434 | #define PCI_ERMC_CLASSCODE_TYPE_KCS 0x01 |
2434 | #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02 | 2435 | #define PCI_ERMC_CLASSCODE_TYPE_BT 0x02 |
2435 | 2436 | ||
2436 | #define PCI_HP_VENDOR_ID 0x103C | 2437 | #define PCI_HP_VENDOR_ID 0x103C |
2437 | #define PCI_MMC_DEVICE_ID 0x121A | 2438 | #define PCI_MMC_DEVICE_ID 0x121A |
2438 | #define PCI_MMC_ADDR_CW 0x10 | 2439 | #define PCI_MMC_ADDR_CW 0x10 |
2439 | 2440 | ||
2440 | static void ipmi_pci_cleanup(struct smi_info *info) | 2441 | static void ipmi_pci_cleanup(struct smi_info *info) |
2441 | { | 2442 | { |
2442 | struct pci_dev *pdev = info->addr_source_data; | 2443 | struct pci_dev *pdev = info->addr_source_data; |
2443 | 2444 | ||
2444 | pci_disable_device(pdev); | 2445 | pci_disable_device(pdev); |
2445 | } | 2446 | } |
2446 | 2447 | ||
2447 | static int __devinit ipmi_pci_probe(struct pci_dev *pdev, | 2448 | static int __devinit ipmi_pci_probe(struct pci_dev *pdev, |
2448 | const struct pci_device_id *ent) | 2449 | const struct pci_device_id *ent) |
2449 | { | 2450 | { |
2450 | int rv; | 2451 | int rv; |
2451 | int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK; | 2452 | int class_type = pdev->class & PCI_ERMC_CLASSCODE_TYPE_MASK; |
2452 | struct smi_info *info; | 2453 | struct smi_info *info; |
2453 | 2454 | ||
2454 | info = smi_info_alloc(); | 2455 | info = smi_info_alloc(); |
2455 | if (!info) | 2456 | if (!info) |
2456 | return -ENOMEM; | 2457 | return -ENOMEM; |
2457 | 2458 | ||
2458 | info->addr_source = SI_PCI; | 2459 | info->addr_source = SI_PCI; |
2459 | dev_info(&pdev->dev, "probing via PCI"); | 2460 | dev_info(&pdev->dev, "probing via PCI"); |
2460 | 2461 | ||
2461 | switch (class_type) { | 2462 | switch (class_type) { |
2462 | case PCI_ERMC_CLASSCODE_TYPE_SMIC: | 2463 | case PCI_ERMC_CLASSCODE_TYPE_SMIC: |
2463 | info->si_type = SI_SMIC; | 2464 | info->si_type = SI_SMIC; |
2464 | break; | 2465 | break; |
2465 | 2466 | ||
2466 | case PCI_ERMC_CLASSCODE_TYPE_KCS: | 2467 | case PCI_ERMC_CLASSCODE_TYPE_KCS: |
2467 | info->si_type = SI_KCS; | 2468 | info->si_type = SI_KCS; |
2468 | break; | 2469 | break; |
2469 | 2470 | ||
2470 | case PCI_ERMC_CLASSCODE_TYPE_BT: | 2471 | case PCI_ERMC_CLASSCODE_TYPE_BT: |
2471 | info->si_type = SI_BT; | 2472 | info->si_type = SI_BT; |
2472 | break; | 2473 | break; |
2473 | 2474 | ||
2474 | default: | 2475 | default: |
2475 | kfree(info); | 2476 | kfree(info); |
2476 | dev_info(&pdev->dev, "Unknown IPMI type: %d\n", class_type); | 2477 | dev_info(&pdev->dev, "Unknown IPMI type: %d\n", class_type); |
2477 | return -ENOMEM; | 2478 | return -ENOMEM; |
2478 | } | 2479 | } |
2479 | 2480 | ||
2480 | rv = pci_enable_device(pdev); | 2481 | rv = pci_enable_device(pdev); |
2481 | if (rv) { | 2482 | if (rv) { |
2482 | dev_err(&pdev->dev, "couldn't enable PCI device\n"); | 2483 | dev_err(&pdev->dev, "couldn't enable PCI device\n"); |
2483 | kfree(info); | 2484 | kfree(info); |
2484 | return rv; | 2485 | return rv; |
2485 | } | 2486 | } |
2486 | 2487 | ||
2487 | info->addr_source_cleanup = ipmi_pci_cleanup; | 2488 | info->addr_source_cleanup = ipmi_pci_cleanup; |
2488 | info->addr_source_data = pdev; | 2489 | info->addr_source_data = pdev; |
2489 | 2490 | ||
2490 | if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) { | 2491 | if (pci_resource_flags(pdev, 0) & IORESOURCE_IO) { |
2491 | info->io_setup = port_setup; | 2492 | info->io_setup = port_setup; |
2492 | info->io.addr_type = IPMI_IO_ADDR_SPACE; | 2493 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
2493 | } else { | 2494 | } else { |
2494 | info->io_setup = mem_setup; | 2495 | info->io_setup = mem_setup; |
2495 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; | 2496 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
2496 | } | 2497 | } |
2497 | info->io.addr_data = pci_resource_start(pdev, 0); | 2498 | info->io.addr_data = pci_resource_start(pdev, 0); |
2498 | 2499 | ||
2499 | info->io.regspacing = DEFAULT_REGSPACING; | 2500 | info->io.regspacing = DEFAULT_REGSPACING; |
2500 | info->io.regsize = DEFAULT_REGSPACING; | 2501 | info->io.regsize = DEFAULT_REGSPACING; |
2501 | info->io.regshift = 0; | 2502 | info->io.regshift = 0; |
2502 | 2503 | ||
2503 | info->irq = pdev->irq; | 2504 | info->irq = pdev->irq; |
2504 | if (info->irq) | 2505 | if (info->irq) |
2505 | info->irq_setup = std_irq_setup; | 2506 | info->irq_setup = std_irq_setup; |
2506 | 2507 | ||
2507 | info->dev = &pdev->dev; | 2508 | info->dev = &pdev->dev; |
2508 | pci_set_drvdata(pdev, info); | 2509 | pci_set_drvdata(pdev, info); |
2509 | 2510 | ||
2510 | dev_info(&pdev->dev, "%pR regsize %d spacing %d irq %d\n", | 2511 | dev_info(&pdev->dev, "%pR regsize %d spacing %d irq %d\n", |
2511 | &pdev->resource[0], info->io.regsize, info->io.regspacing, | 2512 | &pdev->resource[0], info->io.regsize, info->io.regspacing, |
2512 | info->irq); | 2513 | info->irq); |
2513 | 2514 | ||
2514 | if (add_smi(info)) | 2515 | if (add_smi(info)) |
2515 | kfree(info); | 2516 | kfree(info); |
2516 | 2517 | ||
2517 | return 0; | 2518 | return 0; |
2518 | } | 2519 | } |
2519 | 2520 | ||
2520 | static void __devexit ipmi_pci_remove(struct pci_dev *pdev) | 2521 | static void __devexit ipmi_pci_remove(struct pci_dev *pdev) |
2521 | { | 2522 | { |
2522 | struct smi_info *info = pci_get_drvdata(pdev); | 2523 | struct smi_info *info = pci_get_drvdata(pdev); |
2523 | cleanup_one_si(info); | 2524 | cleanup_one_si(info); |
2524 | } | 2525 | } |
2525 | 2526 | ||
2526 | #ifdef CONFIG_PM | 2527 | #ifdef CONFIG_PM |
2527 | static int ipmi_pci_suspend(struct pci_dev *pdev, pm_message_t state) | 2528 | static int ipmi_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
2528 | { | 2529 | { |
2529 | return 0; | 2530 | return 0; |
2530 | } | 2531 | } |
2531 | 2532 | ||
2532 | static int ipmi_pci_resume(struct pci_dev *pdev) | 2533 | static int ipmi_pci_resume(struct pci_dev *pdev) |
2533 | { | 2534 | { |
2534 | return 0; | 2535 | return 0; |
2535 | } | 2536 | } |
2536 | #endif | 2537 | #endif |
2537 | 2538 | ||
2538 | static struct pci_device_id ipmi_pci_devices[] = { | 2539 | static struct pci_device_id ipmi_pci_devices[] = { |
2539 | { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) }, | 2540 | { PCI_DEVICE(PCI_HP_VENDOR_ID, PCI_MMC_DEVICE_ID) }, |
2540 | { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) }, | 2541 | { PCI_DEVICE_CLASS(PCI_ERMC_CLASSCODE, PCI_ERMC_CLASSCODE_MASK) }, |
2541 | { 0, } | 2542 | { 0, } |
2542 | }; | 2543 | }; |
2543 | MODULE_DEVICE_TABLE(pci, ipmi_pci_devices); | 2544 | MODULE_DEVICE_TABLE(pci, ipmi_pci_devices); |
2544 | 2545 | ||
2545 | static struct pci_driver ipmi_pci_driver = { | 2546 | static struct pci_driver ipmi_pci_driver = { |
2546 | .name = DEVICE_NAME, | 2547 | .name = DEVICE_NAME, |
2547 | .id_table = ipmi_pci_devices, | 2548 | .id_table = ipmi_pci_devices, |
2548 | .probe = ipmi_pci_probe, | 2549 | .probe = ipmi_pci_probe, |
2549 | .remove = __devexit_p(ipmi_pci_remove), | 2550 | .remove = __devexit_p(ipmi_pci_remove), |
2550 | #ifdef CONFIG_PM | 2551 | #ifdef CONFIG_PM |
2551 | .suspend = ipmi_pci_suspend, | 2552 | .suspend = ipmi_pci_suspend, |
2552 | .resume = ipmi_pci_resume, | 2553 | .resume = ipmi_pci_resume, |
2553 | #endif | 2554 | #endif |
2554 | }; | 2555 | }; |
2555 | #endif /* CONFIG_PCI */ | 2556 | #endif /* CONFIG_PCI */ |
2556 | 2557 | ||
2557 | static struct of_device_id ipmi_match[]; | 2558 | static struct of_device_id ipmi_match[]; |
2558 | static int __devinit ipmi_probe(struct platform_device *dev) | 2559 | static int __devinit ipmi_probe(struct platform_device *dev) |
2559 | { | 2560 | { |
2560 | #ifdef CONFIG_OF | 2561 | #ifdef CONFIG_OF |
2561 | const struct of_device_id *match; | 2562 | const struct of_device_id *match; |
2562 | struct smi_info *info; | 2563 | struct smi_info *info; |
2563 | struct resource resource; | 2564 | struct resource resource; |
2564 | const __be32 *regsize, *regspacing, *regshift; | 2565 | const __be32 *regsize, *regspacing, *regshift; |
2565 | struct device_node *np = dev->dev.of_node; | 2566 | struct device_node *np = dev->dev.of_node; |
2566 | int ret; | 2567 | int ret; |
2567 | int proplen; | 2568 | int proplen; |
2568 | 2569 | ||
2569 | dev_info(&dev->dev, "probing via device tree\n"); | 2570 | dev_info(&dev->dev, "probing via device tree\n"); |
2570 | 2571 | ||
2571 | match = of_match_device(ipmi_match, &dev->dev); | 2572 | match = of_match_device(ipmi_match, &dev->dev); |
2572 | if (!match) | 2573 | if (!match) |
2573 | return -EINVAL; | 2574 | return -EINVAL; |
2574 | 2575 | ||
2575 | ret = of_address_to_resource(np, 0, &resource); | 2576 | ret = of_address_to_resource(np, 0, &resource); |
2576 | if (ret) { | 2577 | if (ret) { |
2577 | dev_warn(&dev->dev, PFX "invalid address from OF\n"); | 2578 | dev_warn(&dev->dev, PFX "invalid address from OF\n"); |
2578 | return ret; | 2579 | return ret; |
2579 | } | 2580 | } |
2580 | 2581 | ||
2581 | regsize = of_get_property(np, "reg-size", &proplen); | 2582 | regsize = of_get_property(np, "reg-size", &proplen); |
2582 | if (regsize && proplen != 4) { | 2583 | if (regsize && proplen != 4) { |
2583 | dev_warn(&dev->dev, PFX "invalid regsize from OF\n"); | 2584 | dev_warn(&dev->dev, PFX "invalid regsize from OF\n"); |
2584 | return -EINVAL; | 2585 | return -EINVAL; |
2585 | } | 2586 | } |
2586 | 2587 | ||
2587 | regspacing = of_get_property(np, "reg-spacing", &proplen); | 2588 | regspacing = of_get_property(np, "reg-spacing", &proplen); |
2588 | if (regspacing && proplen != 4) { | 2589 | if (regspacing && proplen != 4) { |
2589 | dev_warn(&dev->dev, PFX "invalid regspacing from OF\n"); | 2590 | dev_warn(&dev->dev, PFX "invalid regspacing from OF\n"); |
2590 | return -EINVAL; | 2591 | return -EINVAL; |
2591 | } | 2592 | } |
2592 | 2593 | ||
2593 | regshift = of_get_property(np, "reg-shift", &proplen); | 2594 | regshift = of_get_property(np, "reg-shift", &proplen); |
2594 | if (regshift && proplen != 4) { | 2595 | if (regshift && proplen != 4) { |
2595 | dev_warn(&dev->dev, PFX "invalid regshift from OF\n"); | 2596 | dev_warn(&dev->dev, PFX "invalid regshift from OF\n"); |
2596 | return -EINVAL; | 2597 | return -EINVAL; |
2597 | } | 2598 | } |
2598 | 2599 | ||
2599 | info = smi_info_alloc(); | 2600 | info = smi_info_alloc(); |
2600 | 2601 | ||
2601 | if (!info) { | 2602 | if (!info) { |
2602 | dev_err(&dev->dev, | 2603 | dev_err(&dev->dev, |
2603 | "could not allocate memory for OF probe\n"); | 2604 | "could not allocate memory for OF probe\n"); |
2604 | return -ENOMEM; | 2605 | return -ENOMEM; |
2605 | } | 2606 | } |
2606 | 2607 | ||
2607 | info->si_type = (enum si_type) match->data; | 2608 | info->si_type = (enum si_type) match->data; |
2608 | info->addr_source = SI_DEVICETREE; | 2609 | info->addr_source = SI_DEVICETREE; |
2609 | info->irq_setup = std_irq_setup; | 2610 | info->irq_setup = std_irq_setup; |
2610 | 2611 | ||
2611 | if (resource.flags & IORESOURCE_IO) { | 2612 | if (resource.flags & IORESOURCE_IO) { |
2612 | info->io_setup = port_setup; | 2613 | info->io_setup = port_setup; |
2613 | info->io.addr_type = IPMI_IO_ADDR_SPACE; | 2614 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
2614 | } else { | 2615 | } else { |
2615 | info->io_setup = mem_setup; | 2616 | info->io_setup = mem_setup; |
2616 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; | 2617 | info->io.addr_type = IPMI_MEM_ADDR_SPACE; |
2617 | } | 2618 | } |
2618 | 2619 | ||
2619 | info->io.addr_data = resource.start; | 2620 | info->io.addr_data = resource.start; |
2620 | 2621 | ||
2621 | info->io.regsize = regsize ? be32_to_cpup(regsize) : DEFAULT_REGSIZE; | 2622 | info->io.regsize = regsize ? be32_to_cpup(regsize) : DEFAULT_REGSIZE; |
2622 | info->io.regspacing = regspacing ? be32_to_cpup(regspacing) : DEFAULT_REGSPACING; | 2623 | info->io.regspacing = regspacing ? be32_to_cpup(regspacing) : DEFAULT_REGSPACING; |
2623 | info->io.regshift = regshift ? be32_to_cpup(regshift) : 0; | 2624 | info->io.regshift = regshift ? be32_to_cpup(regshift) : 0; |
2624 | 2625 | ||
2625 | info->irq = irq_of_parse_and_map(dev->dev.of_node, 0); | 2626 | info->irq = irq_of_parse_and_map(dev->dev.of_node, 0); |
2626 | info->dev = &dev->dev; | 2627 | info->dev = &dev->dev; |
2627 | 2628 | ||
2628 | dev_dbg(&dev->dev, "addr 0x%lx regsize %d spacing %d irq %d\n", | 2629 | dev_dbg(&dev->dev, "addr 0x%lx regsize %d spacing %d irq %d\n", |
2629 | info->io.addr_data, info->io.regsize, info->io.regspacing, | 2630 | info->io.addr_data, info->io.regsize, info->io.regspacing, |
2630 | info->irq); | 2631 | info->irq); |
2631 | 2632 | ||
2632 | dev_set_drvdata(&dev->dev, info); | 2633 | dev_set_drvdata(&dev->dev, info); |
2633 | 2634 | ||
2634 | if (add_smi(info)) { | 2635 | if (add_smi(info)) { |
2635 | kfree(info); | 2636 | kfree(info); |
2636 | return -EBUSY; | 2637 | return -EBUSY; |
2637 | } | 2638 | } |
2638 | #endif | 2639 | #endif |
2639 | return 0; | 2640 | return 0; |
2640 | } | 2641 | } |
2641 | 2642 | ||
2642 | static int __devexit ipmi_remove(struct platform_device *dev) | 2643 | static int __devexit ipmi_remove(struct platform_device *dev) |
2643 | { | 2644 | { |
2644 | #ifdef CONFIG_OF | 2645 | #ifdef CONFIG_OF |
2645 | cleanup_one_si(dev_get_drvdata(&dev->dev)); | 2646 | cleanup_one_si(dev_get_drvdata(&dev->dev)); |
2646 | #endif | 2647 | #endif |
2647 | return 0; | 2648 | return 0; |
2648 | } | 2649 | } |
2649 | 2650 | ||
2650 | static struct of_device_id ipmi_match[] = | 2651 | static struct of_device_id ipmi_match[] = |
2651 | { | 2652 | { |
2652 | { .type = "ipmi", .compatible = "ipmi-kcs", | 2653 | { .type = "ipmi", .compatible = "ipmi-kcs", |
2653 | .data = (void *)(unsigned long) SI_KCS }, | 2654 | .data = (void *)(unsigned long) SI_KCS }, |
2654 | { .type = "ipmi", .compatible = "ipmi-smic", | 2655 | { .type = "ipmi", .compatible = "ipmi-smic", |
2655 | .data = (void *)(unsigned long) SI_SMIC }, | 2656 | .data = (void *)(unsigned long) SI_SMIC }, |
2656 | { .type = "ipmi", .compatible = "ipmi-bt", | 2657 | { .type = "ipmi", .compatible = "ipmi-bt", |
2657 | .data = (void *)(unsigned long) SI_BT }, | 2658 | .data = (void *)(unsigned long) SI_BT }, |
2658 | {}, | 2659 | {}, |
2659 | }; | 2660 | }; |
2660 | 2661 | ||
2661 | static struct platform_driver ipmi_driver = { | 2662 | static struct platform_driver ipmi_driver = { |
2662 | .driver = { | 2663 | .driver = { |
2663 | .name = DEVICE_NAME, | 2664 | .name = DEVICE_NAME, |
2664 | .owner = THIS_MODULE, | 2665 | .owner = THIS_MODULE, |
2665 | .of_match_table = ipmi_match, | 2666 | .of_match_table = ipmi_match, |
2666 | }, | 2667 | }, |
2667 | .probe = ipmi_probe, | 2668 | .probe = ipmi_probe, |
2668 | .remove = __devexit_p(ipmi_remove), | 2669 | .remove = __devexit_p(ipmi_remove), |
2669 | }; | 2670 | }; |
2670 | 2671 | ||
2671 | static int wait_for_msg_done(struct smi_info *smi_info) | 2672 | static int wait_for_msg_done(struct smi_info *smi_info) |
2672 | { | 2673 | { |
2673 | enum si_sm_result smi_result; | 2674 | enum si_sm_result smi_result; |
2674 | 2675 | ||
2675 | smi_result = smi_info->handlers->event(smi_info->si_sm, 0); | 2676 | smi_result = smi_info->handlers->event(smi_info->si_sm, 0); |
2676 | for (;;) { | 2677 | for (;;) { |
2677 | if (smi_result == SI_SM_CALL_WITH_DELAY || | 2678 | if (smi_result == SI_SM_CALL_WITH_DELAY || |
2678 | smi_result == SI_SM_CALL_WITH_TICK_DELAY) { | 2679 | smi_result == SI_SM_CALL_WITH_TICK_DELAY) { |
2679 | schedule_timeout_uninterruptible(1); | 2680 | schedule_timeout_uninterruptible(1); |
2680 | smi_result = smi_info->handlers->event( | 2681 | smi_result = smi_info->handlers->event( |
2681 | smi_info->si_sm, 100); | 2682 | smi_info->si_sm, 100); |
2682 | } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) { | 2683 | } else if (smi_result == SI_SM_CALL_WITHOUT_DELAY) { |
2683 | smi_result = smi_info->handlers->event( | 2684 | smi_result = smi_info->handlers->event( |
2684 | smi_info->si_sm, 0); | 2685 | smi_info->si_sm, 0); |
2685 | } else | 2686 | } else |
2686 | break; | 2687 | break; |
2687 | } | 2688 | } |
2688 | if (smi_result == SI_SM_HOSED) | 2689 | if (smi_result == SI_SM_HOSED) |
2689 | /* | 2690 | /* |
2690 | * We couldn't get the state machine to run, so whatever's at | 2691 | * We couldn't get the state machine to run, so whatever's at |
2691 | * the port is probably not an IPMI SMI interface. | 2692 | * the port is probably not an IPMI SMI interface. |
2692 | */ | 2693 | */ |
2693 | return -ENODEV; | 2694 | return -ENODEV; |
2694 | 2695 | ||
2695 | return 0; | 2696 | return 0; |
2696 | } | 2697 | } |
2697 | 2698 | ||
2698 | static int try_get_dev_id(struct smi_info *smi_info) | 2699 | static int try_get_dev_id(struct smi_info *smi_info) |
2699 | { | 2700 | { |
2700 | unsigned char msg[2]; | 2701 | unsigned char msg[2]; |
2701 | unsigned char *resp; | 2702 | unsigned char *resp; |
2702 | unsigned long resp_len; | 2703 | unsigned long resp_len; |
2703 | int rv = 0; | 2704 | int rv = 0; |
2704 | 2705 | ||
2705 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); | 2706 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); |
2706 | if (!resp) | 2707 | if (!resp) |
2707 | return -ENOMEM; | 2708 | return -ENOMEM; |
2708 | 2709 | ||
2709 | /* | 2710 | /* |
2710 | * Do a Get Device ID command, since it comes back with some | 2711 | * Do a Get Device ID command, since it comes back with some |
2711 | * useful info. | 2712 | * useful info. |
2712 | */ | 2713 | */ |
2713 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; | 2714 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
2714 | msg[1] = IPMI_GET_DEVICE_ID_CMD; | 2715 | msg[1] = IPMI_GET_DEVICE_ID_CMD; |
2715 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); | 2716 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
2716 | 2717 | ||
2717 | rv = wait_for_msg_done(smi_info); | 2718 | rv = wait_for_msg_done(smi_info); |
2718 | if (rv) | 2719 | if (rv) |
2719 | goto out; | 2720 | goto out; |
2720 | 2721 | ||
2721 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, | 2722 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, |
2722 | resp, IPMI_MAX_MSG_LENGTH); | 2723 | resp, IPMI_MAX_MSG_LENGTH); |
2723 | 2724 | ||
2724 | /* Check and record info from the get device id, in case we need it. */ | 2725 | /* Check and record info from the get device id, in case we need it. */ |
2725 | rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id); | 2726 | rv = ipmi_demangle_device_id(resp, resp_len, &smi_info->device_id); |
2726 | 2727 | ||
2727 | out: | 2728 | out: |
2728 | kfree(resp); | 2729 | kfree(resp); |
2729 | return rv; | 2730 | return rv; |
2730 | } | 2731 | } |
2731 | 2732 | ||
2732 | static int try_enable_event_buffer(struct smi_info *smi_info) | 2733 | static int try_enable_event_buffer(struct smi_info *smi_info) |
2733 | { | 2734 | { |
2734 | unsigned char msg[3]; | 2735 | unsigned char msg[3]; |
2735 | unsigned char *resp; | 2736 | unsigned char *resp; |
2736 | unsigned long resp_len; | 2737 | unsigned long resp_len; |
2737 | int rv = 0; | 2738 | int rv = 0; |
2738 | 2739 | ||
2739 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); | 2740 | resp = kmalloc(IPMI_MAX_MSG_LENGTH, GFP_KERNEL); |
2740 | if (!resp) | 2741 | if (!resp) |
2741 | return -ENOMEM; | 2742 | return -ENOMEM; |
2742 | 2743 | ||
2743 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; | 2744 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
2744 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; | 2745 | msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD; |
2745 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); | 2746 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2); |
2746 | 2747 | ||
2747 | rv = wait_for_msg_done(smi_info); | 2748 | rv = wait_for_msg_done(smi_info); |
2748 | if (rv) { | 2749 | if (rv) { |
2749 | printk(KERN_WARNING PFX "Error getting response from get" | 2750 | printk(KERN_WARNING PFX "Error getting response from get" |
2750 | " global enables command, the event buffer is not" | 2751 | " global enables command, the event buffer is not" |
2751 | " enabled.\n"); | 2752 | " enabled.\n"); |
2752 | goto out; | 2753 | goto out; |
2753 | } | 2754 | } |
2754 | 2755 | ||
2755 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, | 2756 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, |
2756 | resp, IPMI_MAX_MSG_LENGTH); | 2757 | resp, IPMI_MAX_MSG_LENGTH); |
2757 | 2758 | ||
2758 | if (resp_len < 4 || | 2759 | if (resp_len < 4 || |
2759 | resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || | 2760 | resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || |
2760 | resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD || | 2761 | resp[1] != IPMI_GET_BMC_GLOBAL_ENABLES_CMD || |
2761 | resp[2] != 0) { | 2762 | resp[2] != 0) { |
2762 | printk(KERN_WARNING PFX "Invalid return from get global" | 2763 | printk(KERN_WARNING PFX "Invalid return from get global" |
2763 | " enables command, cannot enable the event buffer.\n"); | 2764 | " enables command, cannot enable the event buffer.\n"); |
2764 | rv = -EINVAL; | 2765 | rv = -EINVAL; |
2765 | goto out; | 2766 | goto out; |
2766 | } | 2767 | } |
2767 | 2768 | ||
2768 | if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) | 2769 | if (resp[3] & IPMI_BMC_EVT_MSG_BUFF) |
2769 | /* buffer is already enabled, nothing to do. */ | 2770 | /* buffer is already enabled, nothing to do. */ |
2770 | goto out; | 2771 | goto out; |
2771 | 2772 | ||
2772 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; | 2773 | msg[0] = IPMI_NETFN_APP_REQUEST << 2; |
2773 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; | 2774 | msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; |
2774 | msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF; | 2775 | msg[2] = resp[3] | IPMI_BMC_EVT_MSG_BUFF; |
2775 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3); | 2776 | smi_info->handlers->start_transaction(smi_info->si_sm, msg, 3); |
2776 | 2777 | ||
2777 | rv = wait_for_msg_done(smi_info); | 2778 | rv = wait_for_msg_done(smi_info); |
2778 | if (rv) { | 2779 | if (rv) { |
2779 | printk(KERN_WARNING PFX "Error getting response from set" | 2780 | printk(KERN_WARNING PFX "Error getting response from set" |
2780 | " global, enables command, the event buffer is not" | 2781 | " global, enables command, the event buffer is not" |
2781 | " enabled.\n"); | 2782 | " enabled.\n"); |
2782 | goto out; | 2783 | goto out; |
2783 | } | 2784 | } |
2784 | 2785 | ||
2785 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, | 2786 | resp_len = smi_info->handlers->get_result(smi_info->si_sm, |
2786 | resp, IPMI_MAX_MSG_LENGTH); | 2787 | resp, IPMI_MAX_MSG_LENGTH); |
2787 | 2788 | ||
2788 | if (resp_len < 3 || | 2789 | if (resp_len < 3 || |
2789 | resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || | 2790 | resp[0] != (IPMI_NETFN_APP_REQUEST | 1) << 2 || |
2790 | resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) { | 2791 | resp[1] != IPMI_SET_BMC_GLOBAL_ENABLES_CMD) { |
2791 | printk(KERN_WARNING PFX "Invalid return from get global," | 2792 | printk(KERN_WARNING PFX "Invalid return from get global," |
2792 | "enables command, not enable the event buffer.\n"); | 2793 | "enables command, not enable the event buffer.\n"); |
2793 | rv = -EINVAL; | 2794 | rv = -EINVAL; |
2794 | goto out; | 2795 | goto out; |
2795 | } | 2796 | } |
2796 | 2797 | ||
2797 | if (resp[2] != 0) | 2798 | if (resp[2] != 0) |
2798 | /* | 2799 | /* |
2799 | * An error when setting the event buffer bit means | 2800 | * An error when setting the event buffer bit means |
2800 | * that the event buffer is not supported. | 2801 | * that the event buffer is not supported. |
2801 | */ | 2802 | */ |
2802 | rv = -ENOENT; | 2803 | rv = -ENOENT; |
2803 | out: | 2804 | out: |
2804 | kfree(resp); | 2805 | kfree(resp); |
2805 | return rv; | 2806 | return rv; |
2806 | } | 2807 | } |
2807 | 2808 | ||
2808 | static int type_file_read_proc(char *page, char **start, off_t off, | 2809 | static int smi_type_proc_show(struct seq_file *m, void *v) |
2809 | int count, int *eof, void *data) | ||
2810 | { | 2810 | { |
2811 | struct smi_info *smi = data; | 2811 | struct smi_info *smi = m->private; |
2812 | 2812 | ||
2813 | return sprintf(page, "%s\n", si_to_str[smi->si_type]); | 2813 | return seq_printf(m, "%s\n", si_to_str[smi->si_type]); |
2814 | } | 2814 | } |
2815 | 2815 | ||
2816 | static int stat_file_read_proc(char *page, char **start, off_t off, | 2816 | static int smi_type_proc_open(struct inode *inode, struct file *file) |
2817 | int count, int *eof, void *data) | ||
2818 | { | 2817 | { |
2819 | char *out = (char *) page; | 2818 | return single_open(file, smi_type_proc_show, PDE(inode)->data); |
2820 | struct smi_info *smi = data; | 2819 | } |
2821 | 2820 | ||
2822 | out += sprintf(out, "interrupts_enabled: %d\n", | 2821 | static const struct file_operations smi_type_proc_ops = { |
2822 | .open = smi_type_proc_open, | ||
2823 | .read = seq_read, | ||
2824 | .llseek = seq_lseek, | ||
2825 | .release = single_release, | ||
2826 | }; | ||
2827 | |||
2828 | static int smi_si_stats_proc_show(struct seq_file *m, void *v) | ||
2829 | { | ||
2830 | struct smi_info *smi = m->private; | ||
2831 | |||
2832 | seq_printf(m, "interrupts_enabled: %d\n", | ||
2823 | smi->irq && !smi->interrupt_disabled); | 2833 | smi->irq && !smi->interrupt_disabled); |
2824 | out += sprintf(out, "short_timeouts: %u\n", | 2834 | seq_printf(m, "short_timeouts: %u\n", |
2825 | smi_get_stat(smi, short_timeouts)); | 2835 | smi_get_stat(smi, short_timeouts)); |
2826 | out += sprintf(out, "long_timeouts: %u\n", | 2836 | seq_printf(m, "long_timeouts: %u\n", |
2827 | smi_get_stat(smi, long_timeouts)); | 2837 | smi_get_stat(smi, long_timeouts)); |
2828 | out += sprintf(out, "idles: %u\n", | 2838 | seq_printf(m, "idles: %u\n", |
2829 | smi_get_stat(smi, idles)); | 2839 | smi_get_stat(smi, idles)); |
2830 | out += sprintf(out, "interrupts: %u\n", | 2840 | seq_printf(m, "interrupts: %u\n", |
2831 | smi_get_stat(smi, interrupts)); | 2841 | smi_get_stat(smi, interrupts)); |
2832 | out += sprintf(out, "attentions: %u\n", | 2842 | seq_printf(m, "attentions: %u\n", |
2833 | smi_get_stat(smi, attentions)); | 2843 | smi_get_stat(smi, attentions)); |
2834 | out += sprintf(out, "flag_fetches: %u\n", | 2844 | seq_printf(m, "flag_fetches: %u\n", |
2835 | smi_get_stat(smi, flag_fetches)); | 2845 | smi_get_stat(smi, flag_fetches)); |
2836 | out += sprintf(out, "hosed_count: %u\n", | 2846 | seq_printf(m, "hosed_count: %u\n", |
2837 | smi_get_stat(smi, hosed_count)); | 2847 | smi_get_stat(smi, hosed_count)); |
2838 | out += sprintf(out, "complete_transactions: %u\n", | 2848 | seq_printf(m, "complete_transactions: %u\n", |
2839 | smi_get_stat(smi, complete_transactions)); | 2849 | smi_get_stat(smi, complete_transactions)); |
2840 | out += sprintf(out, "events: %u\n", | 2850 | seq_printf(m, "events: %u\n", |
2841 | smi_get_stat(smi, events)); | 2851 | smi_get_stat(smi, events)); |
2842 | out += sprintf(out, "watchdog_pretimeouts: %u\n", | 2852 | seq_printf(m, "watchdog_pretimeouts: %u\n", |
2843 | smi_get_stat(smi, watchdog_pretimeouts)); | 2853 | smi_get_stat(smi, watchdog_pretimeouts)); |
2844 | out += sprintf(out, "incoming_messages: %u\n", | 2854 | seq_printf(m, "incoming_messages: %u\n", |
2845 | smi_get_stat(smi, incoming_messages)); | 2855 | smi_get_stat(smi, incoming_messages)); |
2856 | return 0; | ||
2857 | } | ||
2846 | 2858 | ||
2847 | return out - page; | 2859 | static int smi_si_stats_proc_open(struct inode *inode, struct file *file) |
2860 | { | ||
2861 | return single_open(file, smi_si_stats_proc_show, PDE(inode)->data); | ||
2848 | } | 2862 | } |
2849 | 2863 | ||
2850 | static int param_read_proc(char *page, char **start, off_t off, | 2864 | static const struct file_operations smi_si_stats_proc_ops = { |
2851 | int count, int *eof, void *data) | 2865 | .open = smi_si_stats_proc_open, |
2866 | .read = seq_read, | ||
2867 | .llseek = seq_lseek, | ||
2868 | .release = single_release, | ||
2869 | }; | ||
2870 | |||
2871 | static int smi_params_proc_show(struct seq_file *m, void *v) | ||
2852 | { | 2872 | { |
2853 | struct smi_info *smi = data; | 2873 | struct smi_info *smi = m->private; |
2854 | 2874 | ||
2855 | return sprintf(page, | 2875 | return seq_printf(m, |
2856 | "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n", | 2876 | "%s,%s,0x%lx,rsp=%d,rsi=%d,rsh=%d,irq=%d,ipmb=%d\n", |
2857 | si_to_str[smi->si_type], | 2877 | si_to_str[smi->si_type], |
2858 | addr_space_to_str[smi->io.addr_type], | 2878 | addr_space_to_str[smi->io.addr_type], |
2859 | smi->io.addr_data, | 2879 | smi->io.addr_data, |
2860 | smi->io.regspacing, | 2880 | smi->io.regspacing, |
2861 | smi->io.regsize, | 2881 | smi->io.regsize, |
2862 | smi->io.regshift, | 2882 | smi->io.regshift, |
2863 | smi->irq, | 2883 | smi->irq, |
2864 | smi->slave_addr); | 2884 | smi->slave_addr); |
2865 | } | 2885 | } |
2866 | 2886 | ||
2887 | static int smi_params_proc_open(struct inode *inode, struct file *file) | ||
2888 | { | ||
2889 | return single_open(file, smi_params_proc_show, PDE(inode)->data); | ||
2890 | } | ||
2891 | |||
2892 | static const struct file_operations smi_params_proc_ops = { | ||
2893 | .open = smi_params_proc_open, | ||
2894 | .read = seq_read, | ||
2895 | .llseek = seq_lseek, | ||
2896 | .release = single_release, | ||
2897 | }; | ||
2898 | |||
2867 | /* | 2899 | /* |
2868 | * oem_data_avail_to_receive_msg_avail | 2900 | * oem_data_avail_to_receive_msg_avail |
2869 | * @info - smi_info structure with msg_flags set | 2901 | * @info - smi_info structure with msg_flags set |
2870 | * | 2902 | * |
2871 | * Converts flags from OEM_DATA_AVAIL to RECEIVE_MSG_AVAIL | 2903 | * Converts flags from OEM_DATA_AVAIL to RECEIVE_MSG_AVAIL |
2872 | * Returns 1 indicating need to re-run handle_flags(). | 2904 | * Returns 1 indicating need to re-run handle_flags(). |
2873 | */ | 2905 | */ |
2874 | static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info) | 2906 | static int oem_data_avail_to_receive_msg_avail(struct smi_info *smi_info) |
2875 | { | 2907 | { |
2876 | smi_info->msg_flags = ((smi_info->msg_flags & ~OEM_DATA_AVAIL) | | 2908 | smi_info->msg_flags = ((smi_info->msg_flags & ~OEM_DATA_AVAIL) | |
2877 | RECEIVE_MSG_AVAIL); | 2909 | RECEIVE_MSG_AVAIL); |
2878 | return 1; | 2910 | return 1; |
2879 | } | 2911 | } |
2880 | 2912 | ||
2881 | /* | 2913 | /* |
2882 | * setup_dell_poweredge_oem_data_handler | 2914 | * setup_dell_poweredge_oem_data_handler |
2883 | * @info - smi_info.device_id must be populated | 2915 | * @info - smi_info.device_id must be populated |
2884 | * | 2916 | * |
2885 | * Systems that match, but have firmware version < 1.40 may assert | 2917 | * Systems that match, but have firmware version < 1.40 may assert |
2886 | * OEM0_DATA_AVAIL on their own, without being told via Set Flags that | 2918 | * OEM0_DATA_AVAIL on their own, without being told via Set Flags that |
2887 | * it's safe to do so. Such systems will de-assert OEM1_DATA_AVAIL | 2919 | * it's safe to do so. Such systems will de-assert OEM1_DATA_AVAIL |
2888 | * upon receipt of IPMI_GET_MSG_CMD, so we should treat these flags | 2920 | * upon receipt of IPMI_GET_MSG_CMD, so we should treat these flags |
2889 | * as RECEIVE_MSG_AVAIL instead. | 2921 | * as RECEIVE_MSG_AVAIL instead. |
2890 | * | 2922 | * |
2891 | * As Dell has no plans to release IPMI 1.5 firmware that *ever* | 2923 | * As Dell has no plans to release IPMI 1.5 firmware that *ever* |
2892 | * assert the OEM[012] bits, and if it did, the driver would have to | 2924 | * assert the OEM[012] bits, and if it did, the driver would have to |
2893 | * change to handle that properly, we don't actually check for the | 2925 | * change to handle that properly, we don't actually check for the |
2894 | * firmware version. | 2926 | * firmware version. |
2895 | * Device ID = 0x20 BMC on PowerEdge 8G servers | 2927 | * Device ID = 0x20 BMC on PowerEdge 8G servers |
2896 | * Device Revision = 0x80 | 2928 | * Device Revision = 0x80 |
2897 | * Firmware Revision1 = 0x01 BMC version 1.40 | 2929 | * Firmware Revision1 = 0x01 BMC version 1.40 |
2898 | * Firmware Revision2 = 0x40 BCD encoded | 2930 | * Firmware Revision2 = 0x40 BCD encoded |
2899 | * IPMI Version = 0x51 IPMI 1.5 | 2931 | * IPMI Version = 0x51 IPMI 1.5 |
2900 | * Manufacturer ID = A2 02 00 Dell IANA | 2932 | * Manufacturer ID = A2 02 00 Dell IANA |
2901 | * | 2933 | * |
2902 | * Additionally, PowerEdge systems with IPMI < 1.5 may also assert | 2934 | * Additionally, PowerEdge systems with IPMI < 1.5 may also assert |
2903 | * OEM0_DATA_AVAIL and needs to be treated as RECEIVE_MSG_AVAIL. | 2935 | * OEM0_DATA_AVAIL and needs to be treated as RECEIVE_MSG_AVAIL. |
2904 | * | 2936 | * |
2905 | */ | 2937 | */ |
2906 | #define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20 | 2938 | #define DELL_POWEREDGE_8G_BMC_DEVICE_ID 0x20 |
2907 | #define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80 | 2939 | #define DELL_POWEREDGE_8G_BMC_DEVICE_REV 0x80 |
2908 | #define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51 | 2940 | #define DELL_POWEREDGE_8G_BMC_IPMI_VERSION 0x51 |
2909 | #define DELL_IANA_MFR_ID 0x0002a2 | 2941 | #define DELL_IANA_MFR_ID 0x0002a2 |
2910 | static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info) | 2942 | static void setup_dell_poweredge_oem_data_handler(struct smi_info *smi_info) |
2911 | { | 2943 | { |
2912 | struct ipmi_device_id *id = &smi_info->device_id; | 2944 | struct ipmi_device_id *id = &smi_info->device_id; |
2913 | if (id->manufacturer_id == DELL_IANA_MFR_ID) { | 2945 | if (id->manufacturer_id == DELL_IANA_MFR_ID) { |
2914 | if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID && | 2946 | if (id->device_id == DELL_POWEREDGE_8G_BMC_DEVICE_ID && |
2915 | id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV && | 2947 | id->device_revision == DELL_POWEREDGE_8G_BMC_DEVICE_REV && |
2916 | id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) { | 2948 | id->ipmi_version == DELL_POWEREDGE_8G_BMC_IPMI_VERSION) { |
2917 | smi_info->oem_data_avail_handler = | 2949 | smi_info->oem_data_avail_handler = |
2918 | oem_data_avail_to_receive_msg_avail; | 2950 | oem_data_avail_to_receive_msg_avail; |
2919 | } else if (ipmi_version_major(id) < 1 || | 2951 | } else if (ipmi_version_major(id) < 1 || |
2920 | (ipmi_version_major(id) == 1 && | 2952 | (ipmi_version_major(id) == 1 && |
2921 | ipmi_version_minor(id) < 5)) { | 2953 | ipmi_version_minor(id) < 5)) { |
2922 | smi_info->oem_data_avail_handler = | 2954 | smi_info->oem_data_avail_handler = |
2923 | oem_data_avail_to_receive_msg_avail; | 2955 | oem_data_avail_to_receive_msg_avail; |
2924 | } | 2956 | } |
2925 | } | 2957 | } |
2926 | } | 2958 | } |
2927 | 2959 | ||
2928 | #define CANNOT_RETURN_REQUESTED_LENGTH 0xCA | 2960 | #define CANNOT_RETURN_REQUESTED_LENGTH 0xCA |
2929 | static void return_hosed_msg_badsize(struct smi_info *smi_info) | 2961 | static void return_hosed_msg_badsize(struct smi_info *smi_info) |
2930 | { | 2962 | { |
2931 | struct ipmi_smi_msg *msg = smi_info->curr_msg; | 2963 | struct ipmi_smi_msg *msg = smi_info->curr_msg; |
2932 | 2964 | ||
2933 | /* Make it a response */ | 2965 | /* Make it a response */ |
2934 | msg->rsp[0] = msg->data[0] | 4; | 2966 | msg->rsp[0] = msg->data[0] | 4; |
2935 | msg->rsp[1] = msg->data[1]; | 2967 | msg->rsp[1] = msg->data[1]; |
2936 | msg->rsp[2] = CANNOT_RETURN_REQUESTED_LENGTH; | 2968 | msg->rsp[2] = CANNOT_RETURN_REQUESTED_LENGTH; |
2937 | msg->rsp_size = 3; | 2969 | msg->rsp_size = 3; |
2938 | smi_info->curr_msg = NULL; | 2970 | smi_info->curr_msg = NULL; |
2939 | deliver_recv_msg(smi_info, msg); | 2971 | deliver_recv_msg(smi_info, msg); |
2940 | } | 2972 | } |
2941 | 2973 | ||
2942 | /* | 2974 | /* |
2943 | * dell_poweredge_bt_xaction_handler | 2975 | * dell_poweredge_bt_xaction_handler |
2944 | * @info - smi_info.device_id must be populated | 2976 | * @info - smi_info.device_id must be populated |
2945 | * | 2977 | * |
2946 | * Dell PowerEdge servers with the BT interface (x6xx and 1750) will | 2978 | * Dell PowerEdge servers with the BT interface (x6xx and 1750) will |
2947 | * not respond to a Get SDR command if the length of the data | 2979 | * not respond to a Get SDR command if the length of the data |
2948 | * requested is exactly 0x3A, which leads to command timeouts and no | 2980 | * requested is exactly 0x3A, which leads to command timeouts and no |
2949 | * data returned. This intercepts such commands, and causes userspace | 2981 | * data returned. This intercepts such commands, and causes userspace |
2950 | * callers to try again with a different-sized buffer, which succeeds. | 2982 | * callers to try again with a different-sized buffer, which succeeds. |
2951 | */ | 2983 | */ |
2952 | 2984 | ||
2953 | #define STORAGE_NETFN 0x0A | 2985 | #define STORAGE_NETFN 0x0A |
2954 | #define STORAGE_CMD_GET_SDR 0x23 | 2986 | #define STORAGE_CMD_GET_SDR 0x23 |
2955 | static int dell_poweredge_bt_xaction_handler(struct notifier_block *self, | 2987 | static int dell_poweredge_bt_xaction_handler(struct notifier_block *self, |
2956 | unsigned long unused, | 2988 | unsigned long unused, |
2957 | void *in) | 2989 | void *in) |
2958 | { | 2990 | { |
2959 | struct smi_info *smi_info = in; | 2991 | struct smi_info *smi_info = in; |
2960 | unsigned char *data = smi_info->curr_msg->data; | 2992 | unsigned char *data = smi_info->curr_msg->data; |
2961 | unsigned int size = smi_info->curr_msg->data_size; | 2993 | unsigned int size = smi_info->curr_msg->data_size; |
2962 | if (size >= 8 && | 2994 | if (size >= 8 && |
2963 | (data[0]>>2) == STORAGE_NETFN && | 2995 | (data[0]>>2) == STORAGE_NETFN && |
2964 | data[1] == STORAGE_CMD_GET_SDR && | 2996 | data[1] == STORAGE_CMD_GET_SDR && |
2965 | data[7] == 0x3A) { | 2997 | data[7] == 0x3A) { |
2966 | return_hosed_msg_badsize(smi_info); | 2998 | return_hosed_msg_badsize(smi_info); |
2967 | return NOTIFY_STOP; | 2999 | return NOTIFY_STOP; |
2968 | } | 3000 | } |
2969 | return NOTIFY_DONE; | 3001 | return NOTIFY_DONE; |
2970 | } | 3002 | } |
2971 | 3003 | ||
2972 | static struct notifier_block dell_poweredge_bt_xaction_notifier = { | 3004 | static struct notifier_block dell_poweredge_bt_xaction_notifier = { |
2973 | .notifier_call = dell_poweredge_bt_xaction_handler, | 3005 | .notifier_call = dell_poweredge_bt_xaction_handler, |
2974 | }; | 3006 | }; |
2975 | 3007 | ||
2976 | /* | 3008 | /* |
2977 | * setup_dell_poweredge_bt_xaction_handler | 3009 | * setup_dell_poweredge_bt_xaction_handler |
2978 | * @info - smi_info.device_id must be filled in already | 3010 | * @info - smi_info.device_id must be filled in already |
2979 | * | 3011 | * |
2980 | * Fills in smi_info.device_id.start_transaction_pre_hook | 3012 | * Fills in smi_info.device_id.start_transaction_pre_hook |
2981 | * when we know what function to use there. | 3013 | * when we know what function to use there. |
2982 | */ | 3014 | */ |
2983 | static void | 3015 | static void |
2984 | setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info) | 3016 | setup_dell_poweredge_bt_xaction_handler(struct smi_info *smi_info) |
2985 | { | 3017 | { |
2986 | struct ipmi_device_id *id = &smi_info->device_id; | 3018 | struct ipmi_device_id *id = &smi_info->device_id; |
2987 | if (id->manufacturer_id == DELL_IANA_MFR_ID && | 3019 | if (id->manufacturer_id == DELL_IANA_MFR_ID && |
2988 | smi_info->si_type == SI_BT) | 3020 | smi_info->si_type == SI_BT) |
2989 | register_xaction_notifier(&dell_poweredge_bt_xaction_notifier); | 3021 | register_xaction_notifier(&dell_poweredge_bt_xaction_notifier); |
2990 | } | 3022 | } |
2991 | 3023 | ||
2992 | /* | 3024 | /* |
2993 | * setup_oem_data_handler | 3025 | * setup_oem_data_handler |
2994 | * @info - smi_info.device_id must be filled in already | 3026 | * @info - smi_info.device_id must be filled in already |
2995 | * | 3027 | * |
2996 | * Fills in smi_info.device_id.oem_data_available_handler | 3028 | * Fills in smi_info.device_id.oem_data_available_handler |
2997 | * when we know what function to use there. | 3029 | * when we know what function to use there. |
2998 | */ | 3030 | */ |
2999 | 3031 | ||
3000 | static void setup_oem_data_handler(struct smi_info *smi_info) | 3032 | static void setup_oem_data_handler(struct smi_info *smi_info) |
3001 | { | 3033 | { |
3002 | setup_dell_poweredge_oem_data_handler(smi_info); | 3034 | setup_dell_poweredge_oem_data_handler(smi_info); |
3003 | } | 3035 | } |
3004 | 3036 | ||
3005 | static void setup_xaction_handlers(struct smi_info *smi_info) | 3037 | static void setup_xaction_handlers(struct smi_info *smi_info) |
3006 | { | 3038 | { |
3007 | setup_dell_poweredge_bt_xaction_handler(smi_info); | 3039 | setup_dell_poweredge_bt_xaction_handler(smi_info); |
3008 | } | 3040 | } |
3009 | 3041 | ||
3010 | static inline void wait_for_timer_and_thread(struct smi_info *smi_info) | 3042 | static inline void wait_for_timer_and_thread(struct smi_info *smi_info) |
3011 | { | 3043 | { |
3012 | if (smi_info->intf) { | 3044 | if (smi_info->intf) { |
3013 | /* | 3045 | /* |
3014 | * The timer and thread are only running if the | 3046 | * The timer and thread are only running if the |
3015 | * interface has been started up and registered. | 3047 | * interface has been started up and registered. |
3016 | */ | 3048 | */ |
3017 | if (smi_info->thread != NULL) | 3049 | if (smi_info->thread != NULL) |
3018 | kthread_stop(smi_info->thread); | 3050 | kthread_stop(smi_info->thread); |
3019 | del_timer_sync(&smi_info->si_timer); | 3051 | del_timer_sync(&smi_info->si_timer); |
3020 | } | 3052 | } |
3021 | } | 3053 | } |
3022 | 3054 | ||
3023 | static __devinitdata struct ipmi_default_vals | 3055 | static __devinitdata struct ipmi_default_vals |
3024 | { | 3056 | { |
3025 | int type; | 3057 | int type; |
3026 | int port; | 3058 | int port; |
3027 | } ipmi_defaults[] = | 3059 | } ipmi_defaults[] = |
3028 | { | 3060 | { |
3029 | { .type = SI_KCS, .port = 0xca2 }, | 3061 | { .type = SI_KCS, .port = 0xca2 }, |
3030 | { .type = SI_SMIC, .port = 0xca9 }, | 3062 | { .type = SI_SMIC, .port = 0xca9 }, |
3031 | { .type = SI_BT, .port = 0xe4 }, | 3063 | { .type = SI_BT, .port = 0xe4 }, |
3032 | { .port = 0 } | 3064 | { .port = 0 } |
3033 | }; | 3065 | }; |
3034 | 3066 | ||
3035 | static void __devinit default_find_bmc(void) | 3067 | static void __devinit default_find_bmc(void) |
3036 | { | 3068 | { |
3037 | struct smi_info *info; | 3069 | struct smi_info *info; |
3038 | int i; | 3070 | int i; |
3039 | 3071 | ||
3040 | for (i = 0; ; i++) { | 3072 | for (i = 0; ; i++) { |
3041 | if (!ipmi_defaults[i].port) | 3073 | if (!ipmi_defaults[i].port) |
3042 | break; | 3074 | break; |
3043 | #ifdef CONFIG_PPC | 3075 | #ifdef CONFIG_PPC |
3044 | if (check_legacy_ioport(ipmi_defaults[i].port)) | 3076 | if (check_legacy_ioport(ipmi_defaults[i].port)) |
3045 | continue; | 3077 | continue; |
3046 | #endif | 3078 | #endif |
3047 | info = smi_info_alloc(); | 3079 | info = smi_info_alloc(); |
3048 | if (!info) | 3080 | if (!info) |
3049 | return; | 3081 | return; |
3050 | 3082 | ||
3051 | info->addr_source = SI_DEFAULT; | 3083 | info->addr_source = SI_DEFAULT; |
3052 | 3084 | ||
3053 | info->si_type = ipmi_defaults[i].type; | 3085 | info->si_type = ipmi_defaults[i].type; |
3054 | info->io_setup = port_setup; | 3086 | info->io_setup = port_setup; |
3055 | info->io.addr_data = ipmi_defaults[i].port; | 3087 | info->io.addr_data = ipmi_defaults[i].port; |
3056 | info->io.addr_type = IPMI_IO_ADDR_SPACE; | 3088 | info->io.addr_type = IPMI_IO_ADDR_SPACE; |
3057 | 3089 | ||
3058 | info->io.addr = NULL; | 3090 | info->io.addr = NULL; |
3059 | info->io.regspacing = DEFAULT_REGSPACING; | 3091 | info->io.regspacing = DEFAULT_REGSPACING; |
3060 | info->io.regsize = DEFAULT_REGSPACING; | 3092 | info->io.regsize = DEFAULT_REGSPACING; |
3061 | info->io.regshift = 0; | 3093 | info->io.regshift = 0; |
3062 | 3094 | ||
3063 | if (add_smi(info) == 0) { | 3095 | if (add_smi(info) == 0) { |
3064 | if ((try_smi_init(info)) == 0) { | 3096 | if ((try_smi_init(info)) == 0) { |
3065 | /* Found one... */ | 3097 | /* Found one... */ |
3066 | printk(KERN_INFO PFX "Found default %s" | 3098 | printk(KERN_INFO PFX "Found default %s" |
3067 | " state machine at %s address 0x%lx\n", | 3099 | " state machine at %s address 0x%lx\n", |
3068 | si_to_str[info->si_type], | 3100 | si_to_str[info->si_type], |
3069 | addr_space_to_str[info->io.addr_type], | 3101 | addr_space_to_str[info->io.addr_type], |
3070 | info->io.addr_data); | 3102 | info->io.addr_data); |
3071 | } else | 3103 | } else |
3072 | cleanup_one_si(info); | 3104 | cleanup_one_si(info); |
3073 | } else { | 3105 | } else { |
3074 | kfree(info); | 3106 | kfree(info); |
3075 | } | 3107 | } |
3076 | } | 3108 | } |
3077 | } | 3109 | } |
3078 | 3110 | ||
3079 | static int is_new_interface(struct smi_info *info) | 3111 | static int is_new_interface(struct smi_info *info) |
3080 | { | 3112 | { |
3081 | struct smi_info *e; | 3113 | struct smi_info *e; |
3082 | 3114 | ||
3083 | list_for_each_entry(e, &smi_infos, link) { | 3115 | list_for_each_entry(e, &smi_infos, link) { |
3084 | if (e->io.addr_type != info->io.addr_type) | 3116 | if (e->io.addr_type != info->io.addr_type) |
3085 | continue; | 3117 | continue; |
3086 | if (e->io.addr_data == info->io.addr_data) | 3118 | if (e->io.addr_data == info->io.addr_data) |
3087 | return 0; | 3119 | return 0; |
3088 | } | 3120 | } |
3089 | 3121 | ||
3090 | return 1; | 3122 | return 1; |
3091 | } | 3123 | } |
3092 | 3124 | ||
3093 | static int add_smi(struct smi_info *new_smi) | 3125 | static int add_smi(struct smi_info *new_smi) |
3094 | { | 3126 | { |
3095 | int rv = 0; | 3127 | int rv = 0; |
3096 | 3128 | ||
3097 | printk(KERN_INFO PFX "Adding %s-specified %s state machine", | 3129 | printk(KERN_INFO PFX "Adding %s-specified %s state machine", |
3098 | ipmi_addr_src_to_str[new_smi->addr_source], | 3130 | ipmi_addr_src_to_str[new_smi->addr_source], |
3099 | si_to_str[new_smi->si_type]); | 3131 | si_to_str[new_smi->si_type]); |
3100 | mutex_lock(&smi_infos_lock); | 3132 | mutex_lock(&smi_infos_lock); |
3101 | if (!is_new_interface(new_smi)) { | 3133 | if (!is_new_interface(new_smi)) { |
3102 | printk(KERN_CONT " duplicate interface\n"); | 3134 | printk(KERN_CONT " duplicate interface\n"); |
3103 | rv = -EBUSY; | 3135 | rv = -EBUSY; |
3104 | goto out_err; | 3136 | goto out_err; |
3105 | } | 3137 | } |
3106 | 3138 | ||
3107 | printk(KERN_CONT "\n"); | 3139 | printk(KERN_CONT "\n"); |
3108 | 3140 | ||
3109 | /* So we know not to free it unless we have allocated one. */ | 3141 | /* So we know not to free it unless we have allocated one. */ |
3110 | new_smi->intf = NULL; | 3142 | new_smi->intf = NULL; |
3111 | new_smi->si_sm = NULL; | 3143 | new_smi->si_sm = NULL; |
3112 | new_smi->handlers = NULL; | 3144 | new_smi->handlers = NULL; |
3113 | 3145 | ||
3114 | list_add_tail(&new_smi->link, &smi_infos); | 3146 | list_add_tail(&new_smi->link, &smi_infos); |
3115 | 3147 | ||
3116 | out_err: | 3148 | out_err: |
3117 | mutex_unlock(&smi_infos_lock); | 3149 | mutex_unlock(&smi_infos_lock); |
3118 | return rv; | 3150 | return rv; |
3119 | } | 3151 | } |
3120 | 3152 | ||
3121 | static int try_smi_init(struct smi_info *new_smi) | 3153 | static int try_smi_init(struct smi_info *new_smi) |
3122 | { | 3154 | { |
3123 | int rv = 0; | 3155 | int rv = 0; |
3124 | int i; | 3156 | int i; |
3125 | 3157 | ||
3126 | printk(KERN_INFO PFX "Trying %s-specified %s state" | 3158 | printk(KERN_INFO PFX "Trying %s-specified %s state" |
3127 | " machine at %s address 0x%lx, slave address 0x%x," | 3159 | " machine at %s address 0x%lx, slave address 0x%x," |
3128 | " irq %d\n", | 3160 | " irq %d\n", |
3129 | ipmi_addr_src_to_str[new_smi->addr_source], | 3161 | ipmi_addr_src_to_str[new_smi->addr_source], |
3130 | si_to_str[new_smi->si_type], | 3162 | si_to_str[new_smi->si_type], |
3131 | addr_space_to_str[new_smi->io.addr_type], | 3163 | addr_space_to_str[new_smi->io.addr_type], |
3132 | new_smi->io.addr_data, | 3164 | new_smi->io.addr_data, |
3133 | new_smi->slave_addr, new_smi->irq); | 3165 | new_smi->slave_addr, new_smi->irq); |
3134 | 3166 | ||
3135 | switch (new_smi->si_type) { | 3167 | switch (new_smi->si_type) { |
3136 | case SI_KCS: | 3168 | case SI_KCS: |
3137 | new_smi->handlers = &kcs_smi_handlers; | 3169 | new_smi->handlers = &kcs_smi_handlers; |
3138 | break; | 3170 | break; |
3139 | 3171 | ||
3140 | case SI_SMIC: | 3172 | case SI_SMIC: |
3141 | new_smi->handlers = &smic_smi_handlers; | 3173 | new_smi->handlers = &smic_smi_handlers; |
3142 | break; | 3174 | break; |
3143 | 3175 | ||
3144 | case SI_BT: | 3176 | case SI_BT: |
3145 | new_smi->handlers = &bt_smi_handlers; | 3177 | new_smi->handlers = &bt_smi_handlers; |
3146 | break; | 3178 | break; |
3147 | 3179 | ||
3148 | default: | 3180 | default: |
3149 | /* No support for anything else yet. */ | 3181 | /* No support for anything else yet. */ |
3150 | rv = -EIO; | 3182 | rv = -EIO; |
3151 | goto out_err; | 3183 | goto out_err; |
3152 | } | 3184 | } |
3153 | 3185 | ||
3154 | /* Allocate the state machine's data and initialize it. */ | 3186 | /* Allocate the state machine's data and initialize it. */ |
3155 | new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL); | 3187 | new_smi->si_sm = kmalloc(new_smi->handlers->size(), GFP_KERNEL); |
3156 | if (!new_smi->si_sm) { | 3188 | if (!new_smi->si_sm) { |
3157 | printk(KERN_ERR PFX | 3189 | printk(KERN_ERR PFX |
3158 | "Could not allocate state machine memory\n"); | 3190 | "Could not allocate state machine memory\n"); |
3159 | rv = -ENOMEM; | 3191 | rv = -ENOMEM; |
3160 | goto out_err; | 3192 | goto out_err; |
3161 | } | 3193 | } |
3162 | new_smi->io_size = new_smi->handlers->init_data(new_smi->si_sm, | 3194 | new_smi->io_size = new_smi->handlers->init_data(new_smi->si_sm, |
3163 | &new_smi->io); | 3195 | &new_smi->io); |
3164 | 3196 | ||
3165 | /* Now that we know the I/O size, we can set up the I/O. */ | 3197 | /* Now that we know the I/O size, we can set up the I/O. */ |
3166 | rv = new_smi->io_setup(new_smi); | 3198 | rv = new_smi->io_setup(new_smi); |
3167 | if (rv) { | 3199 | if (rv) { |
3168 | printk(KERN_ERR PFX "Could not set up I/O space\n"); | 3200 | printk(KERN_ERR PFX "Could not set up I/O space\n"); |
3169 | goto out_err; | 3201 | goto out_err; |
3170 | } | 3202 | } |
3171 | 3203 | ||
3172 | /* Do low-level detection first. */ | 3204 | /* Do low-level detection first. */ |
3173 | if (new_smi->handlers->detect(new_smi->si_sm)) { | 3205 | if (new_smi->handlers->detect(new_smi->si_sm)) { |
3174 | if (new_smi->addr_source) | 3206 | if (new_smi->addr_source) |
3175 | printk(KERN_INFO PFX "Interface detection failed\n"); | 3207 | printk(KERN_INFO PFX "Interface detection failed\n"); |
3176 | rv = -ENODEV; | 3208 | rv = -ENODEV; |
3177 | goto out_err; | 3209 | goto out_err; |
3178 | } | 3210 | } |
3179 | 3211 | ||
3180 | /* | 3212 | /* |
3181 | * Attempt a get device id command. If it fails, we probably | 3213 | * Attempt a get device id command. If it fails, we probably |
3182 | * don't have a BMC here. | 3214 | * don't have a BMC here. |
3183 | */ | 3215 | */ |
3184 | rv = try_get_dev_id(new_smi); | 3216 | rv = try_get_dev_id(new_smi); |
3185 | if (rv) { | 3217 | if (rv) { |
3186 | if (new_smi->addr_source) | 3218 | if (new_smi->addr_source) |
3187 | printk(KERN_INFO PFX "There appears to be no BMC" | 3219 | printk(KERN_INFO PFX "There appears to be no BMC" |
3188 | " at this location\n"); | 3220 | " at this location\n"); |
3189 | goto out_err; | 3221 | goto out_err; |
3190 | } | 3222 | } |
3191 | 3223 | ||
3192 | setup_oem_data_handler(new_smi); | 3224 | setup_oem_data_handler(new_smi); |
3193 | setup_xaction_handlers(new_smi); | 3225 | setup_xaction_handlers(new_smi); |
3194 | 3226 | ||
3195 | INIT_LIST_HEAD(&(new_smi->xmit_msgs)); | 3227 | INIT_LIST_HEAD(&(new_smi->xmit_msgs)); |
3196 | INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs)); | 3228 | INIT_LIST_HEAD(&(new_smi->hp_xmit_msgs)); |
3197 | new_smi->curr_msg = NULL; | 3229 | new_smi->curr_msg = NULL; |
3198 | atomic_set(&new_smi->req_events, 0); | 3230 | atomic_set(&new_smi->req_events, 0); |
3199 | new_smi->run_to_completion = 0; | 3231 | new_smi->run_to_completion = 0; |
3200 | for (i = 0; i < SI_NUM_STATS; i++) | 3232 | for (i = 0; i < SI_NUM_STATS; i++) |
3201 | atomic_set(&new_smi->stats[i], 0); | 3233 | atomic_set(&new_smi->stats[i], 0); |
3202 | 3234 | ||
3203 | new_smi->interrupt_disabled = 1; | 3235 | new_smi->interrupt_disabled = 1; |
3204 | atomic_set(&new_smi->stop_operation, 0); | 3236 | atomic_set(&new_smi->stop_operation, 0); |
3205 | new_smi->intf_num = smi_num; | 3237 | new_smi->intf_num = smi_num; |
3206 | smi_num++; | 3238 | smi_num++; |
3207 | 3239 | ||
3208 | rv = try_enable_event_buffer(new_smi); | 3240 | rv = try_enable_event_buffer(new_smi); |
3209 | if (rv == 0) | 3241 | if (rv == 0) |
3210 | new_smi->has_event_buffer = 1; | 3242 | new_smi->has_event_buffer = 1; |
3211 | 3243 | ||
3212 | /* | 3244 | /* |
3213 | * Start clearing the flags before we enable interrupts or the | 3245 | * Start clearing the flags before we enable interrupts or the |
3214 | * timer to avoid racing with the timer. | 3246 | * timer to avoid racing with the timer. |
3215 | */ | 3247 | */ |
3216 | start_clear_flags(new_smi); | 3248 | start_clear_flags(new_smi); |
3217 | /* IRQ is defined to be set when non-zero. */ | 3249 | /* IRQ is defined to be set when non-zero. */ |
3218 | if (new_smi->irq) | 3250 | if (new_smi->irq) |
3219 | new_smi->si_state = SI_CLEARING_FLAGS_THEN_SET_IRQ; | 3251 | new_smi->si_state = SI_CLEARING_FLAGS_THEN_SET_IRQ; |
3220 | 3252 | ||
3221 | if (!new_smi->dev) { | 3253 | if (!new_smi->dev) { |
3222 | /* | 3254 | /* |
3223 | * If we don't already have a device from something | 3255 | * If we don't already have a device from something |
3224 | * else (like PCI), then register a new one. | 3256 | * else (like PCI), then register a new one. |
3225 | */ | 3257 | */ |
3226 | new_smi->pdev = platform_device_alloc("ipmi_si", | 3258 | new_smi->pdev = platform_device_alloc("ipmi_si", |
3227 | new_smi->intf_num); | 3259 | new_smi->intf_num); |
3228 | if (!new_smi->pdev) { | 3260 | if (!new_smi->pdev) { |
3229 | printk(KERN_ERR PFX | 3261 | printk(KERN_ERR PFX |
3230 | "Unable to allocate platform device\n"); | 3262 | "Unable to allocate platform device\n"); |
3231 | goto out_err; | 3263 | goto out_err; |
3232 | } | 3264 | } |
3233 | new_smi->dev = &new_smi->pdev->dev; | 3265 | new_smi->dev = &new_smi->pdev->dev; |
3234 | new_smi->dev->driver = &ipmi_driver.driver; | 3266 | new_smi->dev->driver = &ipmi_driver.driver; |
3235 | 3267 | ||
3236 | rv = platform_device_add(new_smi->pdev); | 3268 | rv = platform_device_add(new_smi->pdev); |
3237 | if (rv) { | 3269 | if (rv) { |
3238 | printk(KERN_ERR PFX | 3270 | printk(KERN_ERR PFX |
3239 | "Unable to register system interface device:" | 3271 | "Unable to register system interface device:" |
3240 | " %d\n", | 3272 | " %d\n", |
3241 | rv); | 3273 | rv); |
3242 | goto out_err; | 3274 | goto out_err; |
3243 | } | 3275 | } |
3244 | new_smi->dev_registered = 1; | 3276 | new_smi->dev_registered = 1; |
3245 | } | 3277 | } |
3246 | 3278 | ||
3247 | rv = ipmi_register_smi(&handlers, | 3279 | rv = ipmi_register_smi(&handlers, |
3248 | new_smi, | 3280 | new_smi, |
3249 | &new_smi->device_id, | 3281 | &new_smi->device_id, |
3250 | new_smi->dev, | 3282 | new_smi->dev, |
3251 | "bmc", | 3283 | "bmc", |
3252 | new_smi->slave_addr); | 3284 | new_smi->slave_addr); |
3253 | if (rv) { | 3285 | if (rv) { |
3254 | dev_err(new_smi->dev, "Unable to register device: error %d\n", | 3286 | dev_err(new_smi->dev, "Unable to register device: error %d\n", |
3255 | rv); | 3287 | rv); |
3256 | goto out_err_stop_timer; | 3288 | goto out_err_stop_timer; |
3257 | } | 3289 | } |
3258 | 3290 | ||
3259 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "type", | 3291 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "type", |
3260 | type_file_read_proc, | 3292 | &smi_type_proc_ops, |
3261 | new_smi); | 3293 | new_smi); |
3262 | if (rv) { | 3294 | if (rv) { |
3263 | dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv); | 3295 | dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv); |
3264 | goto out_err_stop_timer; | 3296 | goto out_err_stop_timer; |
3265 | } | 3297 | } |
3266 | 3298 | ||
3267 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "si_stats", | 3299 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "si_stats", |
3268 | stat_file_read_proc, | 3300 | &smi_si_stats_proc_ops, |
3269 | new_smi); | 3301 | new_smi); |
3270 | if (rv) { | 3302 | if (rv) { |
3271 | dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv); | 3303 | dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv); |
3272 | goto out_err_stop_timer; | 3304 | goto out_err_stop_timer; |
3273 | } | 3305 | } |
3274 | 3306 | ||
3275 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "params", | 3307 | rv = ipmi_smi_add_proc_entry(new_smi->intf, "params", |
3276 | param_read_proc, | 3308 | &smi_params_proc_ops, |
3277 | new_smi); | 3309 | new_smi); |
3278 | if (rv) { | 3310 | if (rv) { |
3279 | dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv); | 3311 | dev_err(new_smi->dev, "Unable to create proc entry: %d\n", rv); |
3280 | goto out_err_stop_timer; | 3312 | goto out_err_stop_timer; |
3281 | } | 3313 | } |
3282 | 3314 | ||
3283 | dev_info(new_smi->dev, "IPMI %s interface initialized\n", | 3315 | dev_info(new_smi->dev, "IPMI %s interface initialized\n", |
3284 | si_to_str[new_smi->si_type]); | 3316 | si_to_str[new_smi->si_type]); |
3285 | 3317 | ||
3286 | return 0; | 3318 | return 0; |
3287 | 3319 | ||
3288 | out_err_stop_timer: | 3320 | out_err_stop_timer: |
3289 | atomic_inc(&new_smi->stop_operation); | 3321 | atomic_inc(&new_smi->stop_operation); |
3290 | wait_for_timer_and_thread(new_smi); | 3322 | wait_for_timer_and_thread(new_smi); |
3291 | 3323 | ||
3292 | out_err: | 3324 | out_err: |
3293 | new_smi->interrupt_disabled = 1; | 3325 | new_smi->interrupt_disabled = 1; |
3294 | 3326 | ||
3295 | if (new_smi->intf) { | 3327 | if (new_smi->intf) { |
3296 | ipmi_unregister_smi(new_smi->intf); | 3328 | ipmi_unregister_smi(new_smi->intf); |
3297 | new_smi->intf = NULL; | 3329 | new_smi->intf = NULL; |
3298 | } | 3330 | } |
3299 | 3331 | ||
3300 | if (new_smi->irq_cleanup) { | 3332 | if (new_smi->irq_cleanup) { |
3301 | new_smi->irq_cleanup(new_smi); | 3333 | new_smi->irq_cleanup(new_smi); |
3302 | new_smi->irq_cleanup = NULL; | 3334 | new_smi->irq_cleanup = NULL; |
3303 | } | 3335 | } |
3304 | 3336 | ||
3305 | /* | 3337 | /* |
3306 | * Wait until we know that we are out of any interrupt | 3338 | * Wait until we know that we are out of any interrupt |
3307 | * handlers might have been running before we freed the | 3339 | * handlers might have been running before we freed the |
3308 | * interrupt. | 3340 | * interrupt. |
3309 | */ | 3341 | */ |
3310 | synchronize_sched(); | 3342 | synchronize_sched(); |
3311 | 3343 | ||
3312 | if (new_smi->si_sm) { | 3344 | if (new_smi->si_sm) { |
3313 | if (new_smi->handlers) | 3345 | if (new_smi->handlers) |
3314 | new_smi->handlers->cleanup(new_smi->si_sm); | 3346 | new_smi->handlers->cleanup(new_smi->si_sm); |
3315 | kfree(new_smi->si_sm); | 3347 | kfree(new_smi->si_sm); |
3316 | new_smi->si_sm = NULL; | 3348 | new_smi->si_sm = NULL; |
3317 | } | 3349 | } |
3318 | if (new_smi->addr_source_cleanup) { | 3350 | if (new_smi->addr_source_cleanup) { |
3319 | new_smi->addr_source_cleanup(new_smi); | 3351 | new_smi->addr_source_cleanup(new_smi); |
3320 | new_smi->addr_source_cleanup = NULL; | 3352 | new_smi->addr_source_cleanup = NULL; |
3321 | } | 3353 | } |
3322 | if (new_smi->io_cleanup) { | 3354 | if (new_smi->io_cleanup) { |
3323 | new_smi->io_cleanup(new_smi); | 3355 | new_smi->io_cleanup(new_smi); |
3324 | new_smi->io_cleanup = NULL; | 3356 | new_smi->io_cleanup = NULL; |
3325 | } | 3357 | } |
3326 | 3358 | ||
3327 | if (new_smi->dev_registered) { | 3359 | if (new_smi->dev_registered) { |
3328 | platform_device_unregister(new_smi->pdev); | 3360 | platform_device_unregister(new_smi->pdev); |
3329 | new_smi->dev_registered = 0; | 3361 | new_smi->dev_registered = 0; |
3330 | } | 3362 | } |
3331 | 3363 | ||
3332 | return rv; | 3364 | return rv; |
3333 | } | 3365 | } |
3334 | 3366 | ||
3335 | static int __devinit init_ipmi_si(void) | 3367 | static int __devinit init_ipmi_si(void) |
3336 | { | 3368 | { |
3337 | int i; | 3369 | int i; |
3338 | char *str; | 3370 | char *str; |
3339 | int rv; | 3371 | int rv; |
3340 | struct smi_info *e; | 3372 | struct smi_info *e; |
3341 | enum ipmi_addr_src type = SI_INVALID; | 3373 | enum ipmi_addr_src type = SI_INVALID; |
3342 | 3374 | ||
3343 | if (initialized) | 3375 | if (initialized) |
3344 | return 0; | 3376 | return 0; |
3345 | initialized = 1; | 3377 | initialized = 1; |
3346 | 3378 | ||
3347 | rv = platform_driver_register(&ipmi_driver); | 3379 | rv = platform_driver_register(&ipmi_driver); |
3348 | if (rv) { | 3380 | if (rv) { |
3349 | printk(KERN_ERR PFX "Unable to register driver: %d\n", rv); | 3381 | printk(KERN_ERR PFX "Unable to register driver: %d\n", rv); |
3350 | return rv; | 3382 | return rv; |
3351 | } | 3383 | } |
3352 | 3384 | ||
3353 | 3385 | ||
3354 | /* Parse out the si_type string into its components. */ | 3386 | /* Parse out the si_type string into its components. */ |
3355 | str = si_type_str; | 3387 | str = si_type_str; |
3356 | if (*str != '\0') { | 3388 | if (*str != '\0') { |
3357 | for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) { | 3389 | for (i = 0; (i < SI_MAX_PARMS) && (*str != '\0'); i++) { |
3358 | si_type[i] = str; | 3390 | si_type[i] = str; |
3359 | str = strchr(str, ','); | 3391 | str = strchr(str, ','); |
3360 | if (str) { | 3392 | if (str) { |
3361 | *str = '\0'; | 3393 | *str = '\0'; |
3362 | str++; | 3394 | str++; |
3363 | } else { | 3395 | } else { |
3364 | break; | 3396 | break; |
3365 | } | 3397 | } |
3366 | } | 3398 | } |
3367 | } | 3399 | } |
3368 | 3400 | ||
3369 | printk(KERN_INFO "IPMI System Interface driver.\n"); | 3401 | printk(KERN_INFO "IPMI System Interface driver.\n"); |
3370 | 3402 | ||
3371 | /* If the user gave us a device, they presumably want us to use it */ | 3403 | /* If the user gave us a device, they presumably want us to use it */ |
3372 | if (!hardcode_find_bmc()) | 3404 | if (!hardcode_find_bmc()) |
3373 | return 0; | 3405 | return 0; |
3374 | 3406 | ||
3375 | #ifdef CONFIG_PCI | 3407 | #ifdef CONFIG_PCI |
3376 | rv = pci_register_driver(&ipmi_pci_driver); | 3408 | rv = pci_register_driver(&ipmi_pci_driver); |
3377 | if (rv) | 3409 | if (rv) |
3378 | printk(KERN_ERR PFX "Unable to register PCI driver: %d\n", rv); | 3410 | printk(KERN_ERR PFX "Unable to register PCI driver: %d\n", rv); |
3379 | else | 3411 | else |
3380 | pci_registered = 1; | 3412 | pci_registered = 1; |
3381 | #endif | 3413 | #endif |
3382 | 3414 | ||
3383 | #ifdef CONFIG_ACPI | 3415 | #ifdef CONFIG_ACPI |
3384 | pnp_register_driver(&ipmi_pnp_driver); | 3416 | pnp_register_driver(&ipmi_pnp_driver); |
3385 | pnp_registered = 1; | 3417 | pnp_registered = 1; |
3386 | #endif | 3418 | #endif |
3387 | 3419 | ||
3388 | #ifdef CONFIG_DMI | 3420 | #ifdef CONFIG_DMI |
3389 | dmi_find_bmc(); | 3421 | dmi_find_bmc(); |
3390 | #endif | 3422 | #endif |
3391 | 3423 | ||
3392 | #ifdef CONFIG_ACPI | 3424 | #ifdef CONFIG_ACPI |
3393 | spmi_find_bmc(); | 3425 | spmi_find_bmc(); |
3394 | #endif | 3426 | #endif |
3395 | 3427 | ||
3396 | /* We prefer devices with interrupts, but in the case of a machine | 3428 | /* We prefer devices with interrupts, but in the case of a machine |
3397 | with multiple BMCs we assume that there will be several instances | 3429 | with multiple BMCs we assume that there will be several instances |
3398 | of a given type so if we succeed in registering a type then also | 3430 | of a given type so if we succeed in registering a type then also |
3399 | try to register everything else of the same type */ | 3431 | try to register everything else of the same type */ |
3400 | 3432 | ||
3401 | mutex_lock(&smi_infos_lock); | 3433 | mutex_lock(&smi_infos_lock); |
3402 | list_for_each_entry(e, &smi_infos, link) { | 3434 | list_for_each_entry(e, &smi_infos, link) { |
3403 | /* Try to register a device if it has an IRQ and we either | 3435 | /* Try to register a device if it has an IRQ and we either |
3404 | haven't successfully registered a device yet or this | 3436 | haven't successfully registered a device yet or this |
3405 | device has the same type as one we successfully registered */ | 3437 | device has the same type as one we successfully registered */ |
3406 | if (e->irq && (!type || e->addr_source == type)) { | 3438 | if (e->irq && (!type || e->addr_source == type)) { |
3407 | if (!try_smi_init(e)) { | 3439 | if (!try_smi_init(e)) { |
3408 | type = e->addr_source; | 3440 | type = e->addr_source; |
3409 | } | 3441 | } |
3410 | } | 3442 | } |
3411 | } | 3443 | } |
3412 | 3444 | ||
3413 | /* type will only have been set if we successfully registered an si */ | 3445 | /* type will only have been set if we successfully registered an si */ |
3414 | if (type) { | 3446 | if (type) { |
3415 | mutex_unlock(&smi_infos_lock); | 3447 | mutex_unlock(&smi_infos_lock); |
3416 | return 0; | 3448 | return 0; |
3417 | } | 3449 | } |
3418 | 3450 | ||
3419 | /* Fall back to the preferred device */ | 3451 | /* Fall back to the preferred device */ |
3420 | 3452 | ||
3421 | list_for_each_entry(e, &smi_infos, link) { | 3453 | list_for_each_entry(e, &smi_infos, link) { |
3422 | if (!e->irq && (!type || e->addr_source == type)) { | 3454 | if (!e->irq && (!type || e->addr_source == type)) { |
3423 | if (!try_smi_init(e)) { | 3455 | if (!try_smi_init(e)) { |
3424 | type = e->addr_source; | 3456 | type = e->addr_source; |
3425 | } | 3457 | } |
3426 | } | 3458 | } |
3427 | } | 3459 | } |
3428 | mutex_unlock(&smi_infos_lock); | 3460 | mutex_unlock(&smi_infos_lock); |
3429 | 3461 | ||
3430 | if (type) | 3462 | if (type) |
3431 | return 0; | 3463 | return 0; |
3432 | 3464 | ||
3433 | if (si_trydefaults) { | 3465 | if (si_trydefaults) { |
3434 | mutex_lock(&smi_infos_lock); | 3466 | mutex_lock(&smi_infos_lock); |
3435 | if (list_empty(&smi_infos)) { | 3467 | if (list_empty(&smi_infos)) { |
3436 | /* No BMC was found, try defaults. */ | 3468 | /* No BMC was found, try defaults. */ |
3437 | mutex_unlock(&smi_infos_lock); | 3469 | mutex_unlock(&smi_infos_lock); |
3438 | default_find_bmc(); | 3470 | default_find_bmc(); |
3439 | } else | 3471 | } else |
3440 | mutex_unlock(&smi_infos_lock); | 3472 | mutex_unlock(&smi_infos_lock); |
3441 | } | 3473 | } |
3442 | 3474 | ||
3443 | mutex_lock(&smi_infos_lock); | 3475 | mutex_lock(&smi_infos_lock); |
3444 | if (unload_when_empty && list_empty(&smi_infos)) { | 3476 | if (unload_when_empty && list_empty(&smi_infos)) { |
3445 | mutex_unlock(&smi_infos_lock); | 3477 | mutex_unlock(&smi_infos_lock); |
3446 | cleanup_ipmi_si(); | 3478 | cleanup_ipmi_si(); |
3447 | printk(KERN_WARNING PFX | 3479 | printk(KERN_WARNING PFX |
3448 | "Unable to find any System Interface(s)\n"); | 3480 | "Unable to find any System Interface(s)\n"); |
3449 | return -ENODEV; | 3481 | return -ENODEV; |
3450 | } else { | 3482 | } else { |
3451 | mutex_unlock(&smi_infos_lock); | 3483 | mutex_unlock(&smi_infos_lock); |
3452 | return 0; | 3484 | return 0; |
3453 | } | 3485 | } |
3454 | } | 3486 | } |
3455 | module_init(init_ipmi_si); | 3487 | module_init(init_ipmi_si); |
3456 | 3488 | ||
3457 | static void cleanup_one_si(struct smi_info *to_clean) | 3489 | static void cleanup_one_si(struct smi_info *to_clean) |
3458 | { | 3490 | { |
3459 | int rv = 0; | 3491 | int rv = 0; |
3460 | unsigned long flags; | 3492 | unsigned long flags; |
3461 | 3493 | ||
3462 | if (!to_clean) | 3494 | if (!to_clean) |
3463 | return; | 3495 | return; |
3464 | 3496 | ||
3465 | list_del(&to_clean->link); | 3497 | list_del(&to_clean->link); |
3466 | 3498 | ||
3467 | /* Tell the driver that we are shutting down. */ | 3499 | /* Tell the driver that we are shutting down. */ |
3468 | atomic_inc(&to_clean->stop_operation); | 3500 | atomic_inc(&to_clean->stop_operation); |
3469 | 3501 | ||
3470 | /* | 3502 | /* |
3471 | * Make sure the timer and thread are stopped and will not run | 3503 | * Make sure the timer and thread are stopped and will not run |
3472 | * again. | 3504 | * again. |
3473 | */ | 3505 | */ |
3474 | wait_for_timer_and_thread(to_clean); | 3506 | wait_for_timer_and_thread(to_clean); |
3475 | 3507 | ||
3476 | /* | 3508 | /* |
3477 | * Timeouts are stopped, now make sure the interrupts are off | 3509 | * Timeouts are stopped, now make sure the interrupts are off |
3478 | * for the device. A little tricky with locks to make sure | 3510 | * for the device. A little tricky with locks to make sure |
3479 | * there are no races. | 3511 | * there are no races. |
3480 | */ | 3512 | */ |
3481 | spin_lock_irqsave(&to_clean->si_lock, flags); | 3513 | spin_lock_irqsave(&to_clean->si_lock, flags); |
3482 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { | 3514 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { |
3483 | spin_unlock_irqrestore(&to_clean->si_lock, flags); | 3515 | spin_unlock_irqrestore(&to_clean->si_lock, flags); |
3484 | poll(to_clean); | 3516 | poll(to_clean); |
3485 | schedule_timeout_uninterruptible(1); | 3517 | schedule_timeout_uninterruptible(1); |
3486 | spin_lock_irqsave(&to_clean->si_lock, flags); | 3518 | spin_lock_irqsave(&to_clean->si_lock, flags); |
3487 | } | 3519 | } |
3488 | disable_si_irq(to_clean); | 3520 | disable_si_irq(to_clean); |
3489 | spin_unlock_irqrestore(&to_clean->si_lock, flags); | 3521 | spin_unlock_irqrestore(&to_clean->si_lock, flags); |
3490 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { | 3522 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { |
3491 | poll(to_clean); | 3523 | poll(to_clean); |
3492 | schedule_timeout_uninterruptible(1); | 3524 | schedule_timeout_uninterruptible(1); |
3493 | } | 3525 | } |
3494 | 3526 | ||
3495 | /* Clean up interrupts and make sure that everything is done. */ | 3527 | /* Clean up interrupts and make sure that everything is done. */ |
3496 | if (to_clean->irq_cleanup) | 3528 | if (to_clean->irq_cleanup) |
3497 | to_clean->irq_cleanup(to_clean); | 3529 | to_clean->irq_cleanup(to_clean); |
3498 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { | 3530 | while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { |
3499 | poll(to_clean); | 3531 | poll(to_clean); |
3500 | schedule_timeout_uninterruptible(1); | 3532 | schedule_timeout_uninterruptible(1); |
3501 | } | 3533 | } |
3502 | 3534 | ||
3503 | if (to_clean->intf) | 3535 | if (to_clean->intf) |
3504 | rv = ipmi_unregister_smi(to_clean->intf); | 3536 | rv = ipmi_unregister_smi(to_clean->intf); |
3505 | 3537 | ||
3506 | if (rv) { | 3538 | if (rv) { |
3507 | printk(KERN_ERR PFX "Unable to unregister device: errno=%d\n", | 3539 | printk(KERN_ERR PFX "Unable to unregister device: errno=%d\n", |
3508 | rv); | 3540 | rv); |
3509 | } | 3541 | } |
3510 | 3542 | ||
3511 | if (to_clean->handlers) | 3543 | if (to_clean->handlers) |
3512 | to_clean->handlers->cleanup(to_clean->si_sm); | 3544 | to_clean->handlers->cleanup(to_clean->si_sm); |
3513 | 3545 | ||
3514 | kfree(to_clean->si_sm); | 3546 | kfree(to_clean->si_sm); |
3515 | 3547 | ||
3516 | if (to_clean->addr_source_cleanup) | 3548 | if (to_clean->addr_source_cleanup) |
3517 | to_clean->addr_source_cleanup(to_clean); | 3549 | to_clean->addr_source_cleanup(to_clean); |
3518 | if (to_clean->io_cleanup) | 3550 | if (to_clean->io_cleanup) |
3519 | to_clean->io_cleanup(to_clean); | 3551 | to_clean->io_cleanup(to_clean); |
3520 | 3552 | ||
3521 | if (to_clean->dev_registered) | 3553 | if (to_clean->dev_registered) |
3522 | platform_device_unregister(to_clean->pdev); | 3554 | platform_device_unregister(to_clean->pdev); |
3523 | 3555 | ||
3524 | kfree(to_clean); | 3556 | kfree(to_clean); |
3525 | } | 3557 | } |
3526 | 3558 | ||
3527 | static void cleanup_ipmi_si(void) | 3559 | static void cleanup_ipmi_si(void) |
3528 | { | 3560 | { |
3529 | struct smi_info *e, *tmp_e; | 3561 | struct smi_info *e, *tmp_e; |
3530 | 3562 | ||
3531 | if (!initialized) | 3563 | if (!initialized) |
3532 | return; | 3564 | return; |
3533 | 3565 | ||
3534 | #ifdef CONFIG_PCI | 3566 | #ifdef CONFIG_PCI |
3535 | if (pci_registered) | 3567 | if (pci_registered) |
3536 | pci_unregister_driver(&ipmi_pci_driver); | 3568 | pci_unregister_driver(&ipmi_pci_driver); |
3537 | #endif | 3569 | #endif |
3538 | #ifdef CONFIG_ACPI | 3570 | #ifdef CONFIG_ACPI |
3539 | if (pnp_registered) | 3571 | if (pnp_registered) |
3540 | pnp_unregister_driver(&ipmi_pnp_driver); | 3572 | pnp_unregister_driver(&ipmi_pnp_driver); |
3541 | #endif | 3573 | #endif |
3542 | 3574 | ||
3543 | platform_driver_unregister(&ipmi_driver); | 3575 | platform_driver_unregister(&ipmi_driver); |
3544 | 3576 | ||
3545 | mutex_lock(&smi_infos_lock); | 3577 | mutex_lock(&smi_infos_lock); |
3546 | list_for_each_entry_safe(e, tmp_e, &smi_infos, link) | 3578 | list_for_each_entry_safe(e, tmp_e, &smi_infos, link) |
3547 | cleanup_one_si(e); | 3579 | cleanup_one_si(e); |
3548 | mutex_unlock(&smi_infos_lock); | 3580 | mutex_unlock(&smi_infos_lock); |
3549 | } | 3581 | } |
3550 | module_exit(cleanup_ipmi_si); | 3582 | module_exit(cleanup_ipmi_si); |
3551 | 3583 | ||
3552 | MODULE_LICENSE("GPL"); | 3584 | MODULE_LICENSE("GPL"); |
3553 | MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>"); | 3585 | MODULE_AUTHOR("Corey Minyard <minyard@mvista.com>"); |
3554 | MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT" | 3586 | MODULE_DESCRIPTION("Interface to the IPMI driver for the KCS, SMIC, and BT" |
include/linux/ipmi_smi.h
1 | /* | 1 | /* |
2 | * ipmi_smi.h | 2 | * ipmi_smi.h |
3 | * | 3 | * |
4 | * MontaVista IPMI system management interface | 4 | * MontaVista IPMI system management interface |
5 | * | 5 | * |
6 | * Author: MontaVista Software, Inc. | 6 | * Author: MontaVista Software, Inc. |
7 | * Corey Minyard <minyard@mvista.com> | 7 | * Corey Minyard <minyard@mvista.com> |
8 | * source@mvista.com | 8 | * source@mvista.com |
9 | * | 9 | * |
10 | * Copyright 2002 MontaVista Software Inc. | 10 | * Copyright 2002 MontaVista Software Inc. |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or modify it | 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 | 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 | 14 | * Free Software Foundation; either version 2 of the License, or (at your |
15 | * option) any later version. | 15 | * option) any later version. |
16 | * | 16 | * |
17 | * | 17 | * |
18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR | 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 | 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. | 27 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | * | 28 | * |
29 | * You should have received a copy of the GNU General Public License along | 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., | 30 | * with this program; if not, write to the Free Software Foundation, Inc., |
31 | * 675 Mass Ave, Cambridge, MA 02139, USA. | 31 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef __LINUX_IPMI_SMI_H | 34 | #ifndef __LINUX_IPMI_SMI_H |
35 | #define __LINUX_IPMI_SMI_H | 35 | #define __LINUX_IPMI_SMI_H |
36 | 36 | ||
37 | #include <linux/ipmi_msgdefs.h> | 37 | #include <linux/ipmi_msgdefs.h> |
38 | #include <linux/proc_fs.h> | 38 | #include <linux/proc_fs.h> |
39 | #include <linux/module.h> | 39 | #include <linux/module.h> |
40 | #include <linux/device.h> | 40 | #include <linux/device.h> |
41 | #include <linux/platform_device.h> | 41 | #include <linux/platform_device.h> |
42 | #include <linux/ipmi.h> | 42 | #include <linux/ipmi.h> |
43 | 43 | ||
44 | /* This files describes the interface for IPMI system management interface | 44 | /* This files describes the interface for IPMI system management interface |
45 | drivers to bind into the IPMI message handler. */ | 45 | drivers to bind into the IPMI message handler. */ |
46 | 46 | ||
47 | /* Structure for the low-level drivers. */ | 47 | /* Structure for the low-level drivers. */ |
48 | typedef struct ipmi_smi *ipmi_smi_t; | 48 | typedef struct ipmi_smi *ipmi_smi_t; |
49 | 49 | ||
50 | /* | 50 | /* |
51 | * Messages to/from the lower layer. The smi interface will take one | 51 | * Messages to/from the lower layer. The smi interface will take one |
52 | * of these to send. After the send has occurred and a response has | 52 | * of these to send. After the send has occurred and a response has |
53 | * been received, it will report this same data structure back up to | 53 | * been received, it will report this same data structure back up to |
54 | * the upper layer. If an error occurs, it should fill in the | 54 | * the upper layer. If an error occurs, it should fill in the |
55 | * response with an error code in the completion code location. When | 55 | * response with an error code in the completion code location. When |
56 | * asynchronous data is received, one of these is allocated, the | 56 | * asynchronous data is received, one of these is allocated, the |
57 | * data_size is set to zero and the response holds the data from the | 57 | * data_size is set to zero and the response holds the data from the |
58 | * get message or get event command that the interface initiated. | 58 | * get message or get event command that the interface initiated. |
59 | * Note that it is the interfaces responsibility to detect | 59 | * Note that it is the interfaces responsibility to detect |
60 | * asynchronous data and messages and request them from the | 60 | * asynchronous data and messages and request them from the |
61 | * interface. | 61 | * interface. |
62 | */ | 62 | */ |
63 | struct ipmi_smi_msg { | 63 | struct ipmi_smi_msg { |
64 | struct list_head link; | 64 | struct list_head link; |
65 | 65 | ||
66 | long msgid; | 66 | long msgid; |
67 | void *user_data; | 67 | void *user_data; |
68 | 68 | ||
69 | int data_size; | 69 | int data_size; |
70 | unsigned char data[IPMI_MAX_MSG_LENGTH]; | 70 | unsigned char data[IPMI_MAX_MSG_LENGTH]; |
71 | 71 | ||
72 | int rsp_size; | 72 | int rsp_size; |
73 | unsigned char rsp[IPMI_MAX_MSG_LENGTH]; | 73 | unsigned char rsp[IPMI_MAX_MSG_LENGTH]; |
74 | 74 | ||
75 | /* Will be called when the system is done with the message | 75 | /* Will be called when the system is done with the message |
76 | (presumably to free it). */ | 76 | (presumably to free it). */ |
77 | void (*done)(struct ipmi_smi_msg *msg); | 77 | void (*done)(struct ipmi_smi_msg *msg); |
78 | }; | 78 | }; |
79 | 79 | ||
80 | struct ipmi_smi_handlers { | 80 | struct ipmi_smi_handlers { |
81 | struct module *owner; | 81 | struct module *owner; |
82 | 82 | ||
83 | /* The low-level interface cannot start sending messages to | 83 | /* The low-level interface cannot start sending messages to |
84 | the upper layer until this function is called. This may | 84 | the upper layer until this function is called. This may |
85 | not be NULL, the lower layer must take the interface from | 85 | not be NULL, the lower layer must take the interface from |
86 | this call. */ | 86 | this call. */ |
87 | int (*start_processing)(void *send_info, | 87 | int (*start_processing)(void *send_info, |
88 | ipmi_smi_t new_intf); | 88 | ipmi_smi_t new_intf); |
89 | 89 | ||
90 | /* | 90 | /* |
91 | * Get the detailed private info of the low level interface and store | 91 | * Get the detailed private info of the low level interface and store |
92 | * it into the structure of ipmi_smi_data. For example: the | 92 | * it into the structure of ipmi_smi_data. For example: the |
93 | * ACPI device handle will be returned for the pnp_acpi IPMI device. | 93 | * ACPI device handle will be returned for the pnp_acpi IPMI device. |
94 | */ | 94 | */ |
95 | int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data); | 95 | int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data); |
96 | 96 | ||
97 | /* Called to enqueue an SMI message to be sent. This | 97 | /* Called to enqueue an SMI message to be sent. This |
98 | operation is not allowed to fail. If an error occurs, it | 98 | operation is not allowed to fail. If an error occurs, it |
99 | should report back the error in a received message. It may | 99 | should report back the error in a received message. It may |
100 | do this in the current call context, since no write locks | 100 | do this in the current call context, since no write locks |
101 | are held when this is run. If the priority is > 0, the | 101 | are held when this is run. If the priority is > 0, the |
102 | message will go into a high-priority queue and be sent | 102 | message will go into a high-priority queue and be sent |
103 | first. Otherwise, it goes into a normal-priority queue. */ | 103 | first. Otherwise, it goes into a normal-priority queue. */ |
104 | void (*sender)(void *send_info, | 104 | void (*sender)(void *send_info, |
105 | struct ipmi_smi_msg *msg, | 105 | struct ipmi_smi_msg *msg, |
106 | int priority); | 106 | int priority); |
107 | 107 | ||
108 | /* Called by the upper layer to request that we try to get | 108 | /* Called by the upper layer to request that we try to get |
109 | events from the BMC we are attached to. */ | 109 | events from the BMC we are attached to. */ |
110 | void (*request_events)(void *send_info); | 110 | void (*request_events)(void *send_info); |
111 | 111 | ||
112 | /* Called when the interface should go into "run to | 112 | /* Called when the interface should go into "run to |
113 | completion" mode. If this call sets the value to true, the | 113 | completion" mode. If this call sets the value to true, the |
114 | interface should make sure that all messages are flushed | 114 | interface should make sure that all messages are flushed |
115 | out and that none are pending, and any new requests are run | 115 | out and that none are pending, and any new requests are run |
116 | to completion immediately. */ | 116 | to completion immediately. */ |
117 | void (*set_run_to_completion)(void *send_info, int run_to_completion); | 117 | void (*set_run_to_completion)(void *send_info, int run_to_completion); |
118 | 118 | ||
119 | /* Called to poll for work to do. This is so upper layers can | 119 | /* Called to poll for work to do. This is so upper layers can |
120 | poll for operations during things like crash dumps. */ | 120 | poll for operations during things like crash dumps. */ |
121 | void (*poll)(void *send_info); | 121 | void (*poll)(void *send_info); |
122 | 122 | ||
123 | /* Enable/disable firmware maintenance mode. Note that this | 123 | /* Enable/disable firmware maintenance mode. Note that this |
124 | is *not* the modes defined, this is simply an on/off | 124 | is *not* the modes defined, this is simply an on/off |
125 | setting. The message handler does the mode handling. Note | 125 | setting. The message handler does the mode handling. Note |
126 | that this is called from interrupt context, so it cannot | 126 | that this is called from interrupt context, so it cannot |
127 | block. */ | 127 | block. */ |
128 | void (*set_maintenance_mode)(void *send_info, int enable); | 128 | void (*set_maintenance_mode)(void *send_info, int enable); |
129 | 129 | ||
130 | /* Tell the handler that we are using it/not using it. The | 130 | /* Tell the handler that we are using it/not using it. The |
131 | message handler get the modules that this handler belongs | 131 | message handler get the modules that this handler belongs |
132 | to; this function lets the SMI claim any modules that it | 132 | to; this function lets the SMI claim any modules that it |
133 | uses. These may be NULL if this is not required. */ | 133 | uses. These may be NULL if this is not required. */ |
134 | int (*inc_usecount)(void *send_info); | 134 | int (*inc_usecount)(void *send_info); |
135 | void (*dec_usecount)(void *send_info); | 135 | void (*dec_usecount)(void *send_info); |
136 | }; | 136 | }; |
137 | 137 | ||
138 | struct ipmi_device_id { | 138 | struct ipmi_device_id { |
139 | unsigned char device_id; | 139 | unsigned char device_id; |
140 | unsigned char device_revision; | 140 | unsigned char device_revision; |
141 | unsigned char firmware_revision_1; | 141 | unsigned char firmware_revision_1; |
142 | unsigned char firmware_revision_2; | 142 | unsigned char firmware_revision_2; |
143 | unsigned char ipmi_version; | 143 | unsigned char ipmi_version; |
144 | unsigned char additional_device_support; | 144 | unsigned char additional_device_support; |
145 | unsigned int manufacturer_id; | 145 | unsigned int manufacturer_id; |
146 | unsigned int product_id; | 146 | unsigned int product_id; |
147 | unsigned char aux_firmware_revision[4]; | 147 | unsigned char aux_firmware_revision[4]; |
148 | unsigned int aux_firmware_revision_set : 1; | 148 | unsigned int aux_firmware_revision_set : 1; |
149 | }; | 149 | }; |
150 | 150 | ||
151 | #define ipmi_version_major(v) ((v)->ipmi_version & 0xf) | 151 | #define ipmi_version_major(v) ((v)->ipmi_version & 0xf) |
152 | #define ipmi_version_minor(v) ((v)->ipmi_version >> 4) | 152 | #define ipmi_version_minor(v) ((v)->ipmi_version >> 4) |
153 | 153 | ||
154 | /* Take a pointer to a raw data buffer and a length and extract device | 154 | /* Take a pointer to a raw data buffer and a length and extract device |
155 | id information from it. The first byte of data must point to the | 155 | id information from it. The first byte of data must point to the |
156 | netfn << 2, the data should be of the format: | 156 | netfn << 2, the data should be of the format: |
157 | netfn << 2, cmd, completion code, data | 157 | netfn << 2, cmd, completion code, data |
158 | as normally comes from a device interface. */ | 158 | as normally comes from a device interface. */ |
159 | static inline int ipmi_demangle_device_id(const unsigned char *data, | 159 | static inline int ipmi_demangle_device_id(const unsigned char *data, |
160 | unsigned int data_len, | 160 | unsigned int data_len, |
161 | struct ipmi_device_id *id) | 161 | struct ipmi_device_id *id) |
162 | { | 162 | { |
163 | if (data_len < 9) | 163 | if (data_len < 9) |
164 | return -EINVAL; | 164 | return -EINVAL; |
165 | if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 || | 165 | if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 || |
166 | data[1] != IPMI_GET_DEVICE_ID_CMD) | 166 | data[1] != IPMI_GET_DEVICE_ID_CMD) |
167 | /* Strange, didn't get the response we expected. */ | 167 | /* Strange, didn't get the response we expected. */ |
168 | return -EINVAL; | 168 | return -EINVAL; |
169 | if (data[2] != 0) | 169 | if (data[2] != 0) |
170 | /* That's odd, it shouldn't be able to fail. */ | 170 | /* That's odd, it shouldn't be able to fail. */ |
171 | return -EINVAL; | 171 | return -EINVAL; |
172 | 172 | ||
173 | data += 3; | 173 | data += 3; |
174 | data_len -= 3; | 174 | data_len -= 3; |
175 | id->device_id = data[0]; | 175 | id->device_id = data[0]; |
176 | id->device_revision = data[1]; | 176 | id->device_revision = data[1]; |
177 | id->firmware_revision_1 = data[2]; | 177 | id->firmware_revision_1 = data[2]; |
178 | id->firmware_revision_2 = data[3]; | 178 | id->firmware_revision_2 = data[3]; |
179 | id->ipmi_version = data[4]; | 179 | id->ipmi_version = data[4]; |
180 | id->additional_device_support = data[5]; | 180 | id->additional_device_support = data[5]; |
181 | if (data_len >= 11) { | 181 | if (data_len >= 11) { |
182 | id->manufacturer_id = (data[6] | (data[7] << 8) | | 182 | id->manufacturer_id = (data[6] | (data[7] << 8) | |
183 | (data[8] << 16)); | 183 | (data[8] << 16)); |
184 | id->product_id = data[9] | (data[10] << 8); | 184 | id->product_id = data[9] | (data[10] << 8); |
185 | } else { | 185 | } else { |
186 | id->manufacturer_id = 0; | 186 | id->manufacturer_id = 0; |
187 | id->product_id = 0; | 187 | id->product_id = 0; |
188 | } | 188 | } |
189 | if (data_len >= 15) { | 189 | if (data_len >= 15) { |
190 | memcpy(id->aux_firmware_revision, data+11, 4); | 190 | memcpy(id->aux_firmware_revision, data+11, 4); |
191 | id->aux_firmware_revision_set = 1; | 191 | id->aux_firmware_revision_set = 1; |
192 | } else | 192 | } else |
193 | id->aux_firmware_revision_set = 0; | 193 | id->aux_firmware_revision_set = 0; |
194 | 194 | ||
195 | return 0; | 195 | return 0; |
196 | } | 196 | } |
197 | 197 | ||
198 | /* Add a low-level interface to the IPMI driver. Note that if the | 198 | /* Add a low-level interface to the IPMI driver. Note that if the |
199 | interface doesn't know its slave address, it should pass in zero. | 199 | interface doesn't know its slave address, it should pass in zero. |
200 | The low-level interface should not deliver any messages to the | 200 | The low-level interface should not deliver any messages to the |
201 | upper layer until the start_processing() function in the handlers | 201 | upper layer until the start_processing() function in the handlers |
202 | is called, and the lower layer must get the interface from that | 202 | is called, and the lower layer must get the interface from that |
203 | call. */ | 203 | call. */ |
204 | int ipmi_register_smi(struct ipmi_smi_handlers *handlers, | 204 | int ipmi_register_smi(struct ipmi_smi_handlers *handlers, |
205 | void *send_info, | 205 | void *send_info, |
206 | struct ipmi_device_id *device_id, | 206 | struct ipmi_device_id *device_id, |
207 | struct device *dev, | 207 | struct device *dev, |
208 | const char *sysfs_name, | 208 | const char *sysfs_name, |
209 | unsigned char slave_addr); | 209 | unsigned char slave_addr); |
210 | 210 | ||
211 | /* | 211 | /* |
212 | * Remove a low-level interface from the IPMI driver. This will | 212 | * Remove a low-level interface from the IPMI driver. This will |
213 | * return an error if the interface is still in use by a user. | 213 | * return an error if the interface is still in use by a user. |
214 | */ | 214 | */ |
215 | int ipmi_unregister_smi(ipmi_smi_t intf); | 215 | int ipmi_unregister_smi(ipmi_smi_t intf); |
216 | 216 | ||
217 | /* | 217 | /* |
218 | * The lower layer reports received messages through this interface. | 218 | * The lower layer reports received messages through this interface. |
219 | * The data_size should be zero if this is an asyncronous message. If | 219 | * The data_size should be zero if this is an asyncronous message. If |
220 | * the lower layer gets an error sending a message, it should format | 220 | * the lower layer gets an error sending a message, it should format |
221 | * an error response in the message response. | 221 | * an error response in the message response. |
222 | */ | 222 | */ |
223 | void ipmi_smi_msg_received(ipmi_smi_t intf, | 223 | void ipmi_smi_msg_received(ipmi_smi_t intf, |
224 | struct ipmi_smi_msg *msg); | 224 | struct ipmi_smi_msg *msg); |
225 | 225 | ||
226 | /* The lower layer received a watchdog pre-timeout on interface. */ | 226 | /* The lower layer received a watchdog pre-timeout on interface. */ |
227 | void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf); | 227 | void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf); |
228 | 228 | ||
229 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void); | 229 | struct ipmi_smi_msg *ipmi_alloc_smi_msg(void); |
230 | static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg) | 230 | static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg) |
231 | { | 231 | { |
232 | msg->done(msg); | 232 | msg->done(msg); |
233 | } | 233 | } |
234 | 234 | ||
235 | /* Allow the lower layer to add things to the proc filesystem | 235 | /* Allow the lower layer to add things to the proc filesystem |
236 | directory for this interface. Note that the entry will | 236 | directory for this interface. Note that the entry will |
237 | automatically be dstroyed when the interface is destroyed. */ | 237 | automatically be dstroyed when the interface is destroyed. */ |
238 | int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, | 238 | int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name, |
239 | read_proc_t *read_proc, | 239 | const struct file_operations *proc_ops, |
240 | void *data); | 240 | void *data); |
241 | 241 | ||
242 | #endif /* __LINUX_IPMI_SMI_H */ | 242 | #endif /* __LINUX_IPMI_SMI_H */ |
243 | 243 |