Blame view

include/linux/ipmi_smi.h 8.98 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  /*
   * ipmi_smi.h
   *
   * MontaVista IPMI system management interface
   *
   * Author: MontaVista Software, Inc.
   *         Corey Minyard <minyard@mvista.com>
   *         source@mvista.com
   *
   * Copyright 2002 MontaVista Software Inc.
   *
   *  This program is free software; you can redistribute it and/or modify it
   *  under the terms of the GNU General Public License as published by the
   *  Free Software Foundation; either version 2 of the License, or (at your
   *  option) any later version.
   *
   *
   *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
   *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
   *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
   *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
   *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   *  You should have received a copy of the GNU General Public License along
   *  with this program; if not, write to the Free Software Foundation, Inc.,
   *  675 Mass Ave, Cambridge, MA 02139, USA.
   */
  
  #ifndef __LINUX_IPMI_SMI_H
  #define __LINUX_IPMI_SMI_H
  
  #include <linux/ipmi_msgdefs.h>
  #include <linux/proc_fs.h>
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
39
  #include <linux/platform_device.h>
16f4232ce   Zhao Yakui   IPMI: Add one int...
40
  #include <linux/ipmi.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41

313162d0b   Paul Gortmaker   device.h: audit a...
42
  struct device;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  /* This files describes the interface for IPMI system management interface
     drivers to bind into the IPMI message handler. */
  
  /* Structure for the low-level drivers. */
  typedef struct ipmi_smi *ipmi_smi_t;
  
  /*
   * Messages to/from the lower layer.  The smi interface will take one
   * of these to send. After the send has occurred and a response has
   * been received, it will report this same data structure back up to
   * the upper layer.  If an error occurs, it should fill in the
   * response with an error code in the completion code location. When
   * asynchronous data is received, one of these is allocated, the
   * data_size is set to zero and the response holds the data from the
   * get message or get event command that the interface initiated.
   * Note that it is the interfaces responsibility to detect
   * asynchronous data and messages and request them from the
   * interface.
   */
c70d74998   Corey Minyard   ipmi: style fixes...
62
  struct ipmi_smi_msg {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
66
67
68
69
70
71
72
73
74
  	struct list_head link;
  
  	long    msgid;
  	void    *user_data;
  
  	int           data_size;
  	unsigned char data[IPMI_MAX_MSG_LENGTH];
  
  	int           rsp_size;
  	unsigned char rsp[IPMI_MAX_MSG_LENGTH];
  
  	/* Will be called when the system is done with the message
c70d74998   Corey Minyard   ipmi: style fixes...
75
  	   (presumably to free it). */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
77
  	void (*done)(struct ipmi_smi_msg *msg);
  };
c70d74998   Corey Minyard   ipmi: style fixes...
78
  struct ipmi_smi_handlers {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
79
  	struct module *owner;
453823ba0   Corey Minyard   [PATCH] IPMI: fix...
80
81
82
83
84
85
  	/* The low-level interface cannot start sending messages to
  	   the upper layer until this function is called.  This may
  	   not be NULL, the lower layer must take the interface from
  	   this call. */
  	int (*start_processing)(void       *send_info,
  				ipmi_smi_t new_intf);
16f4232ce   Zhao Yakui   IPMI: Add one int...
86
87
88
89
90
91
  	/*
  	 * Get the detailed private info of the low level interface and store
  	 * it into the structure of ipmi_smi_data. For example: the
  	 * ACPI device handle will be returned for the pnp_acpi IPMI device.
  	 */
  	int (*get_smi_info)(void *send_info, struct ipmi_smi_info *data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  	/* Called to enqueue an SMI message to be sent.  This
  	   operation is not allowed to fail.  If an error occurs, it
  	   should report back the error in a received message.  It may
  	   do this in the current call context, since no write locks
  	   are held when this is run.  If the priority is > 0, the
  	   message will go into a high-priority queue and be sent
  	   first.  Otherwise, it goes into a normal-priority queue. */
  	void (*sender)(void                *send_info,
  		       struct ipmi_smi_msg *msg,
  		       int                 priority);
  
  	/* Called by the upper layer to request that we try to get
  	   events from the BMC we are attached to. */
  	void (*request_events)(void *send_info);
89986496d   Corey Minyard   ipmi: Turn off al...
106
107
108
109
110
  	/* Called by the upper layer when some user requires that the
  	   interface watch for events, received messages, watchdog
  	   pretimeouts, or not.  Used by the SMI to know if it should
  	   watch for these.  This may be NULL if the SMI does not
  	   implement it. */
7aefac26f   Corey Minyard   ipmi: boolify som...
111
  	void (*set_need_watch)(void *send_info, bool enable);
89986496d   Corey Minyard   ipmi: Turn off al...
112

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
113
114
115
116
117
  	/* Called when the interface should go into "run to
  	   completion" mode.  If this call sets the value to true, the
  	   interface should make sure that all messages are flushed
  	   out and that none are pending, and any new requests are run
  	   to completion immediately. */
7aefac26f   Corey Minyard   ipmi: boolify som...
118
  	void (*set_run_to_completion)(void *send_info, bool run_to_completion);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
120
121
122
  
  	/* Called to poll for work to do.  This is so upper layers can
  	   poll for operations during things like crash dumps. */
  	void (*poll)(void *send_info);
b9675136e   Corey Minyard   [PATCH] IPMI: Add...
123
124
125
  	/* Enable/disable firmware maintenance mode.  Note that this
  	   is *not* the modes defined, this is simply an on/off
  	   setting.  The message handler does the mode handling.  Note
3a4fa0a25   Robert P. J. Day   Fix misspellings ...
126
  	   that this is called from interrupt context, so it cannot
b9675136e   Corey Minyard   [PATCH] IPMI: Add...
127
  	   block. */
7aefac26f   Corey Minyard   ipmi: boolify som...
128
  	void (*set_maintenance_mode)(void *send_info, bool enable);
b9675136e   Corey Minyard   [PATCH] IPMI: Add...
129

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130
131
132
133
134
135
136
  	/* Tell the handler that we are using it/not using it.  The
  	   message handler get the modules that this handler belongs
  	   to; this function lets the SMI claim any modules that it
  	   uses.  These may be NULL if this is not required. */
  	int (*inc_usecount)(void *send_info);
  	void (*dec_usecount)(void *send_info);
  };
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  struct ipmi_device_id {
  	unsigned char device_id;
  	unsigned char device_revision;
  	unsigned char firmware_revision_1;
  	unsigned char firmware_revision_2;
  	unsigned char ipmi_version;
  	unsigned char additional_device_support;
  	unsigned int  manufacturer_id;
  	unsigned int  product_id;
  	unsigned char aux_firmware_revision[4];
  	unsigned int  aux_firmware_revision_set : 1;
  };
  
  #define ipmi_version_major(v) ((v)->ipmi_version & 0xf)
  #define ipmi_version_minor(v) ((v)->ipmi_version >> 4)
  
  /* Take a pointer to a raw data buffer and a length and extract device
     id information from it.  The first byte of data must point to the
d8c98618f   Corey Minyard   IPMI: add 0.9 sup...
155
156
157
158
159
160
     netfn << 2, the data should be of the format:
        netfn << 2, cmd, completion code, data
     as normally comes from a device interface. */
  static inline int ipmi_demangle_device_id(const unsigned char *data,
  					  unsigned int data_len,
  					  struct ipmi_device_id *id)
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
161
  {
d8c98618f   Corey Minyard   IPMI: add 0.9 sup...
162
163
164
165
166
167
168
169
170
171
172
173
  	if (data_len < 9)
  		return -EINVAL;
  	if (data[0] != IPMI_NETFN_APP_RESPONSE << 2 ||
  	    data[1] != IPMI_GET_DEVICE_ID_CMD)
  		/* Strange, didn't get the response we expected. */
  		return -EINVAL;
  	if (data[2] != 0)
  		/* That's odd, it shouldn't be able to fail. */
  		return -EINVAL;
  
  	data += 3;
  	data_len -= 3;
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
174
175
176
177
178
179
  	id->device_id = data[0];
  	id->device_revision = data[1];
  	id->firmware_revision_1 = data[2];
  	id->firmware_revision_2 = data[3];
  	id->ipmi_version = data[4];
  	id->additional_device_support = data[5];
64e862a57   Corey Minyard   IPMI: fix compari...
180
  	if (data_len >= 11) {
d8c98618f   Corey Minyard   IPMI: add 0.9 sup...
181
182
183
184
185
186
187
  		id->manufacturer_id = (data[6] | (data[7] << 8) |
  				       (data[8] << 16));
  		id->product_id = data[9] | (data[10] << 8);
  	} else {
  		id->manufacturer_id = 0;
  		id->product_id = 0;
  	}
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
188
189
190
191
192
  	if (data_len >= 15) {
  		memcpy(id->aux_firmware_revision, data+11, 4);
  		id->aux_firmware_revision_set = 1;
  	} else
  		id->aux_firmware_revision_set = 0;
d8c98618f   Corey Minyard   IPMI: add 0.9 sup...
193
194
  
  	return 0;
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
195
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196
  /* Add a low-level interface to the IPMI driver.  Note that if the
453823ba0   Corey Minyard   [PATCH] IPMI: fix...
197
198
199
200
201
     interface doesn't know its slave address, it should pass in zero.
     The low-level interface should not deliver any messages to the
     upper layer until the start_processing() function in the handlers
     is called, and the lower layer must get the interface from that
     call. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
202
203
  int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
  		      void                     *send_info,
50c812b2b   Corey Minyard   [PATCH] ipmi: add...
204
205
  		      struct ipmi_device_id    *device_id,
  		      struct device            *dev,
759643b87   Corey Minyard   [PATCH] IPMI: pas...
206
  		      const char               *sysfs_name,
453823ba0   Corey Minyard   [PATCH] IPMI: fix...
207
  		      unsigned char            slave_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
208
209
210
211
212
213
214
215
216
  
  /*
   * Remove a low-level interface from the IPMI driver.  This will
   * return an error if the interface is still in use by a user.
   */
  int ipmi_unregister_smi(ipmi_smi_t intf);
  
  /*
   * The lower layer reports received messages through this interface.
b3834be5c   Adam Buchbinder   various: Fix spel...
217
   * The data_size should be zero if this is an asynchronous message.  If
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
   * the lower layer gets an error sending a message, it should format
   * an error response in the message response.
   */
  void ipmi_smi_msg_received(ipmi_smi_t          intf,
  			   struct ipmi_smi_msg *msg);
  
  /* The lower layer received a watchdog pre-timeout on interface. */
  void ipmi_smi_watchdog_pretimeout(ipmi_smi_t intf);
  
  struct ipmi_smi_msg *ipmi_alloc_smi_msg(void);
  static inline void ipmi_free_smi_msg(struct ipmi_smi_msg *msg)
  {
  	msg->done(msg);
  }
  
  /* Allow the lower layer to add things to the proc filesystem
     directory for this interface.  Note that the entry will
     automatically be dstroyed when the interface is destroyed. */
  int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
074127367   Alexey Dobriyan   ipmi: convert to ...
237
  			    const struct file_operations *proc_ops,
99b762338   Alexey Dobriyan   proc 2/2: remove ...
238
  			    void *data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
239
240
  
  #endif /* __LINUX_IPMI_SMI_H */