added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.git] / include / linux / ipmi_smi.h
1 /*
2  * ipmi_smi.h
3  *
4  * MontaVista IPMI system management interface
5  *
6  * Author: MontaVista Software, Inc.
7  *         Corey Minyard <minyard@mvista.com>
8  *         source@mvista.com
9  *
10  * Copyright 2002 MontaVista Software Inc.
11  *
12  *  This program is free software; you can redistribute it and/or modify it
13  *  under the terms of the GNU General Public License as published by the
14  *  Free Software Foundation; either version 2 of the License, or (at your
15  *  option) any later version.
16  *
17  *
18  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
26  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
27  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  *  You should have received a copy of the GNU General Public License along
30  *  with this program; if not, write to the Free Software Foundation, Inc.,
31  *  675 Mass Ave, Cambridge, MA 02139, USA.
32  */
33
34 #ifndef __LINUX_IPMI_SMI_H
35 #define __LINUX_IPMI_SMI_H
36
37 #include <linux/ipmi_msgdefs.h>
38
39 /* This files describes the interface for IPMI system management interface
40    drivers to bind into the IPMI message handler. */
41
42 /* Structure for the low-level drivers. */
43 typedef struct ipmi_smi *ipmi_smi_t;
44
45 /*
46  * Messages to/from the lower layer.  The smi interface will take one
47  * of these to send. After the send has occurred and a response has
48  * been received, it will report this same data structure back up to
49  * the upper layer.  If an error occurs, it should fill in the
50  * response with an error code in the completion code location. When
51  * asyncronous data is received, one of these is allocated, the
52  * data_size is set to zero and the response holds the data from the
53  * get message or get event command that the interface initiated.
54  * Note that it is the interfaces responsibility to detect
55  * asynchronous data and messages and request them from the
56  * interface.
57  */
58 struct ipmi_smi_msg
59 {
60         struct list_head link;
61
62         long    msgid;
63         void    *user_data;
64
65         /* If 0, add to the end of the queue.  If 1, add to the beginning. */
66         int     prio;
67
68         int           data_size;
69         unsigned char data[IPMI_MAX_MSG_LENGTH];
70
71         int           rsp_size;
72         unsigned char rsp[IPMI_MAX_MSG_LENGTH];
73
74         /* Will be called when the system is done with the message
75            (presumably to free it). */
76         void (*done)(struct ipmi_smi_msg *msg);
77 };
78
79 struct ipmi_smi_handlers
80 {
81         /* Called to enqueue an SMI message to be sent.  This
82            operation is not allowed to fail.  If an error occurs, it
83            should report back the error in a received message.  It may
84            do this in the current call context, since no write locks
85            are held when this is run.  If the priority is > 0, the
86            message will go into a high-priority queue and be sent
87            first.  Otherwise, it goes into a normal-priority queue. */
88         void (*sender)(void                *send_info,
89                        struct ipmi_smi_msg *msg,
90                        int                 priority);
91
92         /* Called by the upper layer to request that we try to get
93            events from the BMC we are attached to. */
94         void (*request_events)(void *send_info);
95
96         /* Called when someone is using the interface, so the module can
97            adjust it's use count.  Return zero if successful, or an
98            errno if not. */
99         int (*new_user)(void *send_info);
100
101         /* Called when someone is no longer using the interface, so the
102            module can adjust it's use count. */
103         void (*user_left)(void *send_info);
104
105         /* Called when the interface should go into "run to
106            completion" mode.  If this call sets the value to true, the
107            interface should make sure that all messages are flushed
108            out and that none are pending, and any new requests are run
109            to completion immediately. */
110         void (*set_run_to_completion)(void *send_info, int run_to_completion);
111 };
112
113 /* Add a low-level interface to the IPMI driver. */
114 int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
115                       void                     *send_info,
116                       unsigned char            version_major,
117                       unsigned char            version_minor,
118                       ipmi_smi_t               *intf);
119
120 /*
121  * Remove a low-level interface from the IPMI driver.  This will
122  * return an error if the interface is still in use by a user.
123  */
124 int ipmi_unregister_smi(ipmi_smi_t intf);
125
126 /*
127  * The lower layer reports received messages through this interface.
128  * The data_size should be zero if this is an asyncronous message.  If
129  * the lower layer gets an error sending a message, it should format
130  * an error response in the message response.
131  */
132 void ipmi_smi_msg_received(ipmi_smi_t          intf,
133                            struct ipmi_smi_msg *msg);
134
135 /* The lower layer received a watchdog pre-timeout on interface. */
136 void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf);
137
138 struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
139 static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
140 {
141         msg->done(msg);
142 }
143
144 #endif /* __LINUX_IPMI_SMI_H */