Skip to contentSkip to conversation

[PATCH} Network interface for IPMI

PATCH Corey Minyard 2 participants 4 messages Nov 17, 2004 – Nov 18, 2004

Subsystems (3)
lore
Share & tools
lore
#1 lore raw
In reply to Corey Minyard

include/linux/net.h line 29

Quoted 13 lines · Corey Minyard

IPMI is a manage standard that allows intelligent management controllers to monitor things about the system (temperature, fan speed, etc.). The management controllers sit on a bus, and have addresses, and such. After seeing the ugliness required for the 32-bit ioctl compatability layers for 64-bit kernels, I have decided that the network interface for IPMI is a good thing, as the IPMI device ioctls have pointers and require ugly hacks. None should be needed for the network interface.

This patch adds that layer.

include/linux/net.h +1 -1
-#define NPROTO		32		/* should be enough for now..	*/
+#define NPROTO		64		/* should be enough for now..	*/

Boy, that was a big bump. Was this intentional?

net/ipmi/af_ipmi.c line 519

Quoted 6 lines
net/ipmi/af_ipmi.c +6 -0
+static struct ipmi_sock *ipmi_socket_create1(struct socket *sock)
+{
+	struct ipmi_sock *i;
+
+	if (atomic_read(&ipmi_nr_socks) >= 2*files_stat.max_files)
+		return NULL;

Why this test?

net/Kconfig line 83

Quoted 10 lines
net/Kconfig +10 -0
+config IPMI_SOCKET
+	tristate "IPMI sockets"
+	depends on IPMI_HANDLER
+	---help---
+	  If you say Y here, you will include support for IPMI sockets;
+	  This way you don't have to use devices to access IPMI.  You
+	  must also enable the IPMI message handler and a low-level
+	  driver in the Character Drivers if you enable this.
+	  
+	  If unsure, say N.

Is this new kernel interface documented somewhere?

#2 lore raw
Quoted 5 lines · Andrew Morton
Quoted 2 lines · Corey Minyard

IPMI is a manage standard that allows intelligent management controllers to monitor things about the system (temperature, fan speed, etc.). The management controllers sit on a bus, and have addresses, and such. After seeing the ugliness required for the 32-bit ioctl compatability layers for 64-bit kernels, I have decided that the network interface for IPMI is a good thing, as the IPMI device ioctls have pointers and require ugly hacks. None should be needed for the network interface.

Quoted 10 lines

include/linux/net.h line 29

Quoted 6 lines

This patch adds that layer.

include/linux/net.h +1 -1
-#define NPROTO		32		/* should be enough for now..	*/
+#define NPROTO		64		/* should be enough for now..	*/

Boy, that was a big bump. Was this intentional?

It's the next power of 2 :). Any value larger than 32 should work, I'll just set it to 33.

Quoted 14 lines

net/ipmi/af_ipmi.c line 519

Quoted 10 lines
net/ipmi/af_ipmi.c +6 -0
+static struct ipmi_sock *ipmi_socket_create1(struct socket *sock)
+{
+	struct ipmi_sock *i;
+
+	if (atomic_read(&ipmi_nr_socks) >= 2*files_stat.max_files)
+		return NULL;

Why this test?

It snuck in from the original patch writer and I missed it. Not necessary.

Quoted 18 lines
Quoted 4 lines

net/Kconfig line 83

Quoted 10 lines
net/Kconfig +10 -0
+config IPMI_SOCKET
+	tristate "IPMI sockets"
+	depends on IPMI_HANDLER
+	---help---
+	  If you say Y here, you will include support for IPMI sockets;
+	  This way you don't have to use devices to access IPMI.  You
+	  must also enable the IPMI message handler and a low-level
+	  driver in the Character Drivers if you enable this.
+	  
+	  If unsure, say N.

Is this new kernel interface documented somewhere?

I thought I had done it, but it doesn't appear to be there. I'll add some and repost a patch.

Thanks,

-Corey

#3 lore raw
In reply to Andrew Morton

Here is a patch that fixed the problems you mentioned.

Thanks,

-Corey

Documentation/IPMI.txt +121 -1
Index: linux-ipmi/Documentation/IPMI.txt
===================================================================
@@ -104,7 +104,7 @@
 af_ipmi - A network socket interface to IPMI.  This doesn't take up
 a character device in your system.
 
-Note that the KCS-only interface ahs been removed.
+Note that the KCS-only interface has been removed.
 
 Much documentation for the interface is in the include files.  The
 IPMI include files are:
@@ -218,6 +218,125 @@
 appropriately.
 
 
+Using the Socket Interface
+--------------------------
+
+The socket interface to IPMI removes a lot of the evils of the ioctl
+interface, including taking a character device and passing pointers
+between userland and the kernel in ioctl structures.  Plus, IPMI is
+really kind of a network, you have addressing, message options, and
+things of that nature that fit naturally into the socket interface.  I
+should have done that from the beginning.
+
+This is the recommended interface to use for IPMI.  It is a lot
+cleaner than the ioctl interface.
+
+To create an IPMI socket, do something like the following:
+
+    int                  fd;
+    int                  rv;
+    struct sockaddr_ipmi addr;
+
+    fd = socket(PF_IPMI, SOCK_DGRAM, 0);
+    if (fd == -1)
+	<return error>
+    addr.sipmi_family = AF_IPMI;
+    addr.if_num = if_num;
+    rv = bind(fd, (struct sockaddr *) &addr, sizeof(addr));
+    if (rv != -1) {
+        close(fd)
+	<return error>
+    }
+
+The "if_num" variable above is which IPMI interface you are binding
+to, generally zero.  To send a message, do something like:
+
+    struct sockaddr_ipmi     saddr;
+    char                     smsg_data[sizeof(struct ipmi_sock_msg)
+                                       + IPMI_MAX_MSG_LENGTH];
+    struct ipmi_sock_msg     *smsg = (void *) smsg_data;
+
+    saddr.sipmi_family = AF_IPMI;
+    memcpy(&saddr.ipmi_addr, addr, addr_len);
+
+    smsg->netfn = netfn;
+    smsg->cmd = cmd;
+    smsg->data_len = data_len;
+    smsg->msgid = msgid;
+    memcpy(smsg->data, data, smsg->data_len);
+
+    rv = sendto(fd, smsg, sizeof(*smsg) + msg->data_len, 0,
+                (struct sockaddr *) &saddr,
+                addr_len + SOCKADDR_IPMI_OVERHEAD);
+
+The "addr" variable here is an address as described by the addressing
+section above.  The message data is the same as described in the
+messaging section above.
+
+    struct sockaddr_ipmi addr;
+    socklen_t            addr_len;
+    struct ipmi_sock_msg *smsg;
+    unsigned char        data[MAX_IPMI_DATA_SIZE + sizeof(*smsg)];
+    
+
+    addr_len = sizeof(addr);
+    rv = recvfrom(fd, data, sizeof(data), 0,
+		  (struct sockaddr *) &addr, &addr_len);
+    if (rv < 0) {
+        <handle error>
+    }
+
+    if (rv < sizeof(*smsg)) {
+        <handle error, msg too short>
+    }
+
+    smsg = (struct ipmi_sock_msg *) data;
+    if (rv < (sizeof(*smsg) + smsg->data_len)) {
+        <handle error, msg too short>
+    }
+
+    recv_type = smsg->recv_type;
+    ipmi_addr = (struct ipmi_addr *) &addr.ipmi_addr;
+    ipmi_addr_len = addr_len - SOCKADDR_IPMI_OVERHEAD;
+    msgid = smsg->msgid;
+    msg.netfn = smsg->netfn;
+    msg.cmd = smsg->cmd;
+    msg.data = smsg->data;
+    msg.data_len = smsg->data_len;
+
+You must handle the received message based upon the receive type.
+
+There are a few other things that are ioctls for the socket.  This is
+a few things that cannot be done in any easy way besides an ioctl, but
+these don't contain any nasty things like pointers.
+
+The following sets the local address for the BMC.  IPMI provides no
+way for the driver to discover what the IPMB address for the BMC
+should be.  So this has to be set by the software using it.
+
+    unsigned int slave_addr;
+    rv = ioctl(fd, SIOCIPMISETADDR, &slave_addr);
+
+The following enabled events to be received from the interface.  If
+you set this to true, incoming events will be delivered to the fd.
+
+    int enable_events;
+    rv = ioctl(fd, SIOCIPMIGETEVENT, &enable_events);
+
+To receive external command addressed to LUN 2 of the BMC, register
+with the following ioctl:
+
+    struct ipmi_cmdspec reg;
+    reg.netfn = netfn;
+    reg.cmd = cmd;
+    rv = ioctl(fd, SIOCIPMIREGCMD, &reg);
+
+The deregistration call is:
+
+    rv = ioctl(fd, SIOCIPMIUNREGCMD, &reg);
+
+
+
 The Upper Layer Interface (Message Handler)
 -------------------------------------------
 
@@ -293,6 +412,7 @@
 
 
 Events and Incoming Commands
+----------------------------
 
 The driver takes care of polling for IPMI events and receiving
 commands (commands are messages that are not responses, they are
include/linux/net.h +1 -1
Index: linux-ipmi/include/linux/net.h
===================================================================
@@ -26,7 +26,7 @@
 struct poll_table_struct;
 struct inode;
 
-#define NPROTO		32		/* should be enough for now..	*/
+#define NPROTO		33		/* should be enough for now..	*/
 
 #define SYS_SOCKET	1		/* sys_socket(2)		*/
 #define SYS_BIND	2		/* sys_bind(2)			*/
include/linux/socket.h +3 -1
Index: linux-ipmi/include/linux/socket.h
===================================================================
@@ -177,7 +177,8 @@
 #define AF_WANPIPE	25	/* Wanpipe API Sockets */
 #define AF_LLC		26	/* Linux LLC			*/
 #define AF_BLUETOOTH	31	/* Bluetooth sockets 		*/
-#define AF_MAX		32	/* For now.. */
+#define AF_IPMI		32	/* IPMI sockers 		*/
+#define AF_MAX		33	/* For now.. */
 
 /* Protocol families, same as address families. */
 #define PF_UNSPEC	AF_UNSPEC
@@ -209,6 +210,7 @@
 #define PF_WANPIPE	AF_WANPIPE
 #define PF_LLC		AF_LLC
 #define PF_BLUETOOTH	AF_BLUETOOTH
+#define PF_IPMI		AF_IPMI
 #define PF_MAX		AF_MAX
 
 /* Maximum queue length specifiable by listen.  */
include/net/af_ipmi.h +59 -0

59 lines not on this page · raw message

net/ipmi/af_ipmi.c +608 -0

608 lines not on this page · raw message

net/ipmi/Makefile +1 -0
Index: linux-ipmi/net/ipmi/Makefile
===================================================================
@@ -0,0 +1 @@
+obj-$(CONFIG_IPMI_SOCKET) = af_ipmi.o
net/Kconfig +11 -0
Index: linux-ipmi/net/Kconfig
===================================================================
@@ -71,6 +71,17 @@
 
 	  Say Y unless you know what you are doing.
 
+config IPMI_SOCKET
+	tristate "IPMI sockets"
+	depends on IPMI_HANDLER
+	---help---
+	  If you say Y here, you will include support for IPMI sockets;
+	  This way you don't have to use devices to access IPMI.  You
+	  must also enable the IPMI message handler and a low-level
+	  driver in the Character Drivers if you enable this.
+	  
+	  If unsure, say N.
+
 config NET_KEY
 	tristate "PF_KEY sockets"
 	select XFRM
net/Makefile +1 -0
Index: linux-ipmi/net/Makefile
===================================================================
@@ -42,6 +42,7 @@
 obj-$(CONFIG_ECONET)		+= econet/
 obj-$(CONFIG_VLAN_8021Q)	+= 8021q/
 obj-$(CONFIG_IP_SCTP)		+= sctp/
+obj-$(CONFIG_IPMI_SOCKET)	+= ipmi/
 
 ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_SYSCTL)		+= sysctl_net.o
#0 lore raw

IPMI is a manage standard that allows intelligent management controllers to monitor things about the system (temperature, fan speed, etc.). The management controllers sit on a bus, and have addresses, and such. After seeing the ugliness required for the 32-bit ioctl compatability layers for 64-bit kernels, I have decided that the network interface for IPMI is a good thing, as the IPMI device ioctls have pointers and require ugly hacks. None should be needed for the network interface.

This patch adds that layer.

Relative to 2.6.10-rc2-mm1

-Corey

include/linux/net.h +1 -1
Index: linux-ipmi/include/linux/net.h
===================================================================
@@ -26,7 +26,7 @@
 struct poll_table_struct;
 struct inode;
 
-#define NPROTO		32		/* should be enough for now..	*/
+#define NPROTO		64		/* should be enough for now..	*/
 
 #define SYS_SOCKET	1		/* sys_socket(2)		*/
 #define SYS_BIND	2		/* sys_bind(2)			*/
include/linux/socket.h +3 -1
Index: linux-ipmi/include/linux/socket.h
===================================================================
@@ -177,7 +177,8 @@
 #define AF_WANPIPE	25	/* Wanpipe API Sockets */
 #define AF_LLC		26	/* Linux LLC			*/
 #define AF_BLUETOOTH	31	/* Bluetooth sockets 		*/
-#define AF_MAX		32	/* For now.. */
+#define AF_IPMI		32	/* IPMI sockers 		*/
+#define AF_MAX		33	/* For now.. */
 
 /* Protocol families, same as address families. */
 #define PF_UNSPEC	AF_UNSPEC
@@ -209,6 +210,7 @@
 #define PF_WANPIPE	AF_WANPIPE
 #define PF_LLC		AF_LLC
 #define PF_BLUETOOTH	AF_BLUETOOTH
+#define PF_IPMI		AF_IPMI
 #define PF_MAX		AF_MAX
 
 /* Maximum queue length specifiable by listen.  */
include/net/af_ipmi.h +59 -0

59 lines not on this page · raw message

net/ipmi/af_ipmi.c +612 -0

612 lines not on this page · raw message

net/ipmi/Makefile +1 -0
Index: linux-ipmi/net/ipmi/Makefile
===================================================================
@@ -0,0 +1 @@
+obj-$(CONFIG_IPMI_SOCKET) = af_ipmi.o
net/Kconfig +11 -0
Index: linux-ipmi/net/Kconfig
===================================================================
@@ -71,6 +71,17 @@
 
 	  Say Y unless you know what you are doing.
 
+config IPMI_SOCKET
+	tristate "IPMI sockets"
+	depends on IPMI_HANDLER
+	---help---
+	  If you say Y here, you will include support for IPMI sockets;
+	  This way you don't have to use devices to access IPMI.  You
+	  must also enable the IPMI message handler and a low-level
+	  driver in the Character Drivers if you enable this.
+	  
+	  If unsure, say N.
+
 config NET_KEY
 	tristate "PF_KEY sockets"
 	select XFRM
net/Makefile +1 -0
Index: linux-ipmi/net/Makefile
===================================================================
@@ -42,6 +42,7 @@
 obj-$(CONFIG_ECONET)		+= econet/
 obj-$(CONFIG_VLAN_8021Q)	+= 8021q/
 obj-$(CONFIG_IP_SCTP)		+= sctp/
+obj-$(CONFIG_IPMI_SOCKET)	+= ipmi/
 
 ifeq ($(CONFIG_NET),y)
 obj-$(CONFIG_SYSCTL)		+= sysctl_net.o