mirror of
https://github.com/ipmitool/ipmitool.git
synced 2025-05-11 19:17:22 +00:00
update bmc driver for solaris
This commit is contained in:
parent
1fbd130b9b
commit
3a96ee3272
@ -48,6 +48,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stropts.h>
|
#include <sys/stropts.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stropts.h>
|
||||||
|
|
||||||
#include <ipmitool/ipmi.h>
|
#include <ipmitool/ipmi.h>
|
||||||
#include <ipmitool/ipmi_intf.h>
|
#include <ipmitool/ipmi_intf.h>
|
||||||
@ -56,8 +58,19 @@
|
|||||||
#include "bmc.h"
|
#include "bmc.h"
|
||||||
|
|
||||||
static int curr_seq;
|
static int curr_seq;
|
||||||
|
static int bmc_method(int fd);
|
||||||
|
struct ipmi_rs *(*sendrecv_fn)(struct ipmi_intf *, struct ipmi_rq *) = NULL;
|
||||||
extern int verbose;
|
extern int verbose;
|
||||||
|
|
||||||
|
static void dump_request(bmc_req_t *request);
|
||||||
|
static void dump_response(bmc_rsp_t *response);
|
||||||
|
static struct ipmi_rs *ipmi_bmc_send_cmd_ioctl(struct ipmi_intf *intf,
|
||||||
|
struct ipmi_rq *req);
|
||||||
|
static struct ipmi_rs *ipmi_bmc_send_cmd_putmsg(struct ipmi_intf *intf,
|
||||||
|
struct ipmi_rq *req);
|
||||||
|
|
||||||
|
#define MESSAGE_BUFSIZE 1024
|
||||||
|
|
||||||
struct ipmi_intf ipmi_bmc_intf = {
|
struct ipmi_intf ipmi_bmc_intf = {
|
||||||
name: "bmc",
|
name: "bmc",
|
||||||
desc: "IPMI v2.0 BMC interface",
|
desc: "IPMI v2.0 BMC interface",
|
||||||
@ -91,20 +104,31 @@ ipmi_bmc_open(struct ipmi_intf *intf)
|
|||||||
curr_seq = 0;
|
curr_seq = 0;
|
||||||
|
|
||||||
intf->opened = 1;
|
intf->opened = 1;
|
||||||
|
|
||||||
|
sendrecv_fn = (bmc_method(intf->fd) == BMC_PUTMSG_METHOD) ?
|
||||||
|
ipmi_bmc_send_cmd_putmsg : ipmi_bmc_send_cmd_ioctl;
|
||||||
|
|
||||||
return (intf->fd);
|
return (intf->fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ipmi_rs *
|
struct ipmi_rs *
|
||||||
ipmi_bmc_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req)
|
ipmi_bmc_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req)
|
||||||
{
|
{
|
||||||
struct strioctl istr;
|
|
||||||
static struct bmc_reqrsp reqrsp;
|
|
||||||
static struct ipmi_rs rsp;
|
|
||||||
|
|
||||||
/* If not already opened open the device or network connection */
|
/* If not already opened open the device or network connection */
|
||||||
if (!intf->opened && intf->open && intf->open(intf) < 0)
|
if (!intf->opened && intf->open && intf->open(intf) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
/* sendrecv_fn cannot be NULL at this point */
|
||||||
|
return ((*sendrecv_fn)(intf, req));
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct ipmi_rs *
|
||||||
|
ipmi_bmc_send_cmd_ioctl(struct ipmi_intf *intf, struct ipmi_rq *req)
|
||||||
|
{
|
||||||
|
struct strioctl istr;
|
||||||
|
static struct bmc_reqrsp reqrsp;
|
||||||
|
static struct ipmi_rs rsp;
|
||||||
|
|
||||||
memset(&reqrsp, 0, sizeof (reqrsp));
|
memset(&reqrsp, 0, sizeof (reqrsp));
|
||||||
reqrsp.req.fn = req->msg.netfn;
|
reqrsp.req.fn = req->msg.netfn;
|
||||||
reqrsp.req.lun = 0;
|
reqrsp.req.lun = 0;
|
||||||
@ -119,15 +143,21 @@ ipmi_bmc_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req)
|
|||||||
istr.ic_len = sizeof (struct bmc_reqrsp);
|
istr.ic_len = sizeof (struct bmc_reqrsp);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
printf("BMC req.fn : %x\n", reqrsp.req.fn);
|
printf("--\n");
|
||||||
printf("BMC req.lun : %x\n", reqrsp.req.lun);
|
dump_request(&reqrsp.req);
|
||||||
printf("BMC req.cmd : %x\n", reqrsp.req.cmd);
|
printf("--\n");
|
||||||
printf("BMC req.datalength : %d\n", reqrsp.req.datalength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(intf->fd, I_STR, &istr) < 0) {
|
if (ioctl(intf->fd, I_STR, &istr) < 0) {
|
||||||
perror("BMC IOCTL: I_STR");
|
perror("BMC IOCTL: I_STR");
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (verbose > 2) {
|
||||||
|
dump_response(&reqrsp.rsp);
|
||||||
|
printf("--\n");
|
||||||
|
}
|
||||||
|
|
||||||
memset(&rsp, 0, sizeof (struct ipmi_rs));
|
memset(&rsp, 0, sizeof (struct ipmi_rs));
|
||||||
rsp.ccode = reqrsp.rsp.ccode;
|
rsp.ccode = reqrsp.rsp.ccode;
|
||||||
rsp.data_len = reqrsp.rsp.datalength;
|
rsp.data_len = reqrsp.rsp.datalength;
|
||||||
@ -140,3 +170,162 @@ ipmi_bmc_send_cmd(struct ipmi_intf *intf, struct ipmi_rq *req)
|
|||||||
|
|
||||||
return (&rsp);
|
return (&rsp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct ipmi_rs *
|
||||||
|
ipmi_bmc_send_cmd_putmsg(struct ipmi_intf *intf, struct ipmi_rq *req)
|
||||||
|
{
|
||||||
|
struct strbuf sb;
|
||||||
|
int flags = 0;
|
||||||
|
static uint32_t msg_seq = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The length of the message structure is equal to the size of the
|
||||||
|
* bmc_req_t structure, PLUS any additional data space in excess of
|
||||||
|
* the data space already reserved in the data member + <n> for
|
||||||
|
* the rest of the members in the bmc_msg_t structure.
|
||||||
|
*/
|
||||||
|
int msgsz = offsetof(bmc_msg_t, msg) + sizeof(bmc_req_t) +
|
||||||
|
((req->msg.data_len > SEND_MAX_PAYLOAD_SIZE) ?
|
||||||
|
(req->msg.data_len - SEND_MAX_PAYLOAD_SIZE) : 0);
|
||||||
|
bmc_msg_t *msg = malloc(msgsz);
|
||||||
|
bmc_req_t *request = (bmc_req_t *)&msg->msg[0];
|
||||||
|
bmc_rsp_t *response;
|
||||||
|
static struct ipmi_rs rsp;
|
||||||
|
struct ipmi_rs *ret = NULL;
|
||||||
|
|
||||||
|
msg->m_type = BMC_MSG_REQUEST;
|
||||||
|
msg->m_id = msg_seq++;
|
||||||
|
request->fn = req->msg.netfn;
|
||||||
|
request->lun = 0;
|
||||||
|
request->cmd = req->msg.cmd;
|
||||||
|
request->datalength = req->msg.data_len;
|
||||||
|
memcpy(request->data, req->msg.data, req->msg.data_len);
|
||||||
|
|
||||||
|
sb.len = msgsz;
|
||||||
|
sb.buf = (unsigned char *)msg;
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
printf("--\n");
|
||||||
|
dump_request(request);
|
||||||
|
printf("--\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (putmsg(intf->fd, NULL, &sb, 0) < 0) {
|
||||||
|
perror("BMC putmsg: ");
|
||||||
|
free(msg);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(msg);
|
||||||
|
|
||||||
|
sb.buf = malloc(MESSAGE_BUFSIZE);
|
||||||
|
sb.maxlen = MESSAGE_BUFSIZE;
|
||||||
|
|
||||||
|
if (getmsg(intf->fd, NULL, &sb, &flags) < 0) {
|
||||||
|
perror("BMC getmsg: ");
|
||||||
|
free(sb.buf);
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
msg = (bmc_msg_t *)sb.buf;
|
||||||
|
|
||||||
|
if (verbose > 3) {
|
||||||
|
printf("Got msg (id 0x%x) type 0x%x\n", msg->m_id, msg->m_type);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Did we get an error back from the stream? */
|
||||||
|
switch (msg->m_type) {
|
||||||
|
|
||||||
|
case BMC_MSG_RESPONSE:
|
||||||
|
response = (bmc_rsp_t *)&msg->msg[0];
|
||||||
|
|
||||||
|
if (verbose > 2) {
|
||||||
|
dump_response(response);
|
||||||
|
printf("--\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&rsp, 0, sizeof (struct ipmi_rs));
|
||||||
|
rsp.ccode = response->ccode;
|
||||||
|
rsp.data_len = response->datalength;
|
||||||
|
|
||||||
|
if (!rsp.ccode && (rsp.data_len > 0))
|
||||||
|
memcpy(rsp.data, response->data, rsp.data_len);
|
||||||
|
|
||||||
|
ret = &rsp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BMC_MSG_ERROR:
|
||||||
|
/* In case of an error, msg->msg[0] has the error code */
|
||||||
|
printf("bmc_send_cmd: %s\n", strerror(msg->msg[0]));
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
free(sb.buf);
|
||||||
|
return (ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Determine which interface to use. Returns the interface method
|
||||||
|
* to use.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
bmc_method(int fd)
|
||||||
|
{
|
||||||
|
struct strioctl istr;
|
||||||
|
uint8_t method = 0;
|
||||||
|
|
||||||
|
istr.ic_cmd = IOCTL_IPMI_INTERFACE_METHOD;
|
||||||
|
istr.ic_timout = 0;
|
||||||
|
istr.ic_dp = (uint8_t *)&method;
|
||||||
|
istr.ic_len = 1;
|
||||||
|
|
||||||
|
if (ioctl(fd, I_STR, &istr) < 0) {
|
||||||
|
/* If the IOCTL doesn't exist, use the (old) ioctl interface */
|
||||||
|
return (BMC_IOCTL_METHOD);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (method);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_request(bmc_req_t *request)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf("BMC req.fn : 0x%x\n", request->fn);
|
||||||
|
printf("BMC req.lun : 0x%x\n", request->lun);
|
||||||
|
printf("BMC req.cmd : 0x%x\n", request->cmd);
|
||||||
|
printf("BMC req.datalength : 0x%x\n", request->datalength);
|
||||||
|
printf("BMC req.data : ");
|
||||||
|
|
||||||
|
if (request->datalength > 0) {
|
||||||
|
for (i = 0; i < request->datalength; i++)
|
||||||
|
printf("0x%x ", request->data[i]);
|
||||||
|
} else {
|
||||||
|
printf("<NONE>");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_response(bmc_rsp_t *response)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
printf("BMC rsp.fn : 0x%x\n", response->fn);
|
||||||
|
printf("BMC rsp.lun : 0x%x\n", response->lun);
|
||||||
|
printf("BMC rsp.cmd : 0x%x\n", response->cmd);
|
||||||
|
printf("BMC rsp.ccode : 0x%x\n", response->ccode);
|
||||||
|
printf("BMC rsp.datalength : 0x%x\n", response->datalength);
|
||||||
|
printf("BMC rsp.data : ");
|
||||||
|
|
||||||
|
if (response->datalength > 0) {
|
||||||
|
for (i = 0; i < response->datalength; i++)
|
||||||
|
printf("0x%x ", response->data[i]);
|
||||||
|
} else {
|
||||||
|
printf("<NONE>");
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
@ -34,10 +34,10 @@
|
|||||||
* facility.
|
* facility.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _BMC_INTF_H_
|
#ifndef _BMC_INTF_H
|
||||||
#define _BMC_INTF_H_
|
#define _BMC_INTF_H
|
||||||
|
|
||||||
#pragma ident "@(#)bmc_intf.h 1.2 04/08/25 SMI"
|
#pragma ident "@(#)bmc_intf.h 1.2 05/03/07 SMI"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -46,13 +46,6 @@ extern "C" {
|
|||||||
#define BMC_SUCCESS 0x0
|
#define BMC_SUCCESS 0x0
|
||||||
#define BMC_FAILURE 0x1
|
#define BMC_FAILURE 0x1
|
||||||
|
|
||||||
#define IPMI_SUCCESS BMC_SUCCESS
|
|
||||||
#define IPMI_FAILURE BMC_FAILURE
|
|
||||||
|
|
||||||
/* allau clean up */
|
|
||||||
#define IPMI_FALSE 0
|
|
||||||
#define IPMI_TRUE 1
|
|
||||||
|
|
||||||
#define BMC_NETFN_CHASSIS 0x0
|
#define BMC_NETFN_CHASSIS 0x0
|
||||||
#define BMC_NETFN_BRIDGE 0x2
|
#define BMC_NETFN_BRIDGE 0x2
|
||||||
#define BMC_NETFN_SE 0x4
|
#define BMC_NETFN_SE 0x4
|
||||||
@ -95,27 +88,38 @@ extern "C" {
|
|||||||
|
|
||||||
|
|
||||||
#define IOCTL_IPMI_KCS_ACTION 0x01
|
#define IOCTL_IPMI_KCS_ACTION 0x01
|
||||||
|
#define IOCTL_IPMI_INTERFACE_METHOD 0x02
|
||||||
|
|
||||||
|
/* Interface methods returned from IOCTL_IPMI_INTERFACE_METHOD ioctl: */
|
||||||
|
|
||||||
|
#define BMC_IOCTL_METHOD 0 /* Not returned from ioctl, */
|
||||||
|
/* but can be used by */
|
||||||
|
/* applications that want to */
|
||||||
|
/* compare against an */
|
||||||
|
/* alternative method. */
|
||||||
|
#define BMC_PUTMSG_METHOD 1
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* bmc_req_t is the data structure to send
|
* bmc_req_t is the data structure to send
|
||||||
* request packet from applications to the driver
|
* request packet from applications to the driver
|
||||||
* module.
|
* module.
|
||||||
|
*
|
||||||
* the request pkt is mainly for KCS-interface-BMC
|
* the request pkt is mainly for KCS-interface-BMC
|
||||||
* messages. Since the system interface is session-less
|
* messages. Since the system interface is session-less
|
||||||
* connections, the packet won't have any session
|
* connections, the packet won't have any session
|
||||||
* information.
|
* information.
|
||||||
|
*
|
||||||
* the data payload will be 2 bytes less than max
|
* the data payload will be 2 bytes less than max
|
||||||
* BMC supported packet size.
|
* BMC supported packet size.
|
||||||
* the address of the responder is always BMC and so
|
* the address of the responder is always BMC and so
|
||||||
* rsSa field is not required.
|
* rsSa field is not required.
|
||||||
*/
|
*/
|
||||||
typedef struct bmc_req {
|
typedef struct bmc_req {
|
||||||
unsigned char fn; /* netFn for command */
|
uint8_t fn; /* netFn for command */
|
||||||
unsigned char lun; /* logical unit on responder */
|
uint8_t lun; /* logical unit on responder */
|
||||||
unsigned char cmd; /* command */
|
uint8_t cmd; /* command */
|
||||||
unsigned char datalength; /* length of following data */
|
uint8_t datalength; /* length of following data */
|
||||||
unsigned char data[SEND_MAX_PAYLOAD_SIZE]; /* request data */
|
uint8_t data[SEND_MAX_PAYLOAD_SIZE]; /* request data */
|
||||||
} bmc_req_t;
|
} bmc_req_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -127,20 +131,21 @@ typedef struct bmc_req {
|
|||||||
* messages. Since the system interface is session-less
|
* messages. Since the system interface is session-less
|
||||||
* connections, the packet won't have any session
|
* connections, the packet won't have any session
|
||||||
* information.
|
* information.
|
||||||
|
*
|
||||||
* the data payload will be 2 bytes less than max
|
* the data payload will be 2 bytes less than max
|
||||||
* BMC supported packet size.
|
* BMC supported packet size.
|
||||||
*/
|
*/
|
||||||
typedef struct bmc_rsp {
|
typedef struct bmc_rsp {
|
||||||
unsigned char fn; /* netFn for command */
|
uint8_t fn; /* netFn for command */
|
||||||
unsigned char lun; /* logical unit on responder */
|
uint8_t lun; /* logical unit on responder */
|
||||||
unsigned char cmd; /* command */
|
uint8_t cmd; /* command */
|
||||||
unsigned char ccode; /* completion code */
|
uint8_t ccode; /* completion code */
|
||||||
unsigned char datalength; /* Length */
|
uint8_t datalength; /* Length */
|
||||||
unsigned char data[RECV_MAX_PAYLOAD_SIZE]; /* response */
|
uint8_t data[RECV_MAX_PAYLOAD_SIZE]; /* response */
|
||||||
} bmc_rsp_t;
|
} bmc_rsp_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* the data structure for synchronous operation.
|
* the data structure for synchronous operation via ioctl (DEPRECATED)
|
||||||
*/
|
*/
|
||||||
typedef struct bmc_reqrsp {
|
typedef struct bmc_reqrsp {
|
||||||
bmc_req_t req; /* request half */
|
bmc_req_t req; /* request half */
|
||||||
@ -148,38 +153,59 @@ typedef struct bmc_reqrsp {
|
|||||||
} bmc_reqrsp_t;
|
} bmc_reqrsp_t;
|
||||||
|
|
||||||
|
|
||||||
#ifdef _KERNEL
|
/*
|
||||||
|
* The new way of communicating with the bmc driver is to use putmsg() to
|
||||||
|
* send a message of a particular type. Replies from the driver also have this
|
||||||
|
* form, and will require the user to process the type field before examining
|
||||||
|
* the rest of the reply.
|
||||||
|
*
|
||||||
|
* The only change that must be observed when using the request and response
|
||||||
|
* structures defined above is as follows:
|
||||||
|
* when sending messages to the bmc driver, the data portion is now variable
|
||||||
|
* (the caller must allocate enough space to store the all structure members,
|
||||||
|
* plus enough space to cover the amount of data in the request), e.g.:
|
||||||
|
*
|
||||||
|
* bmc_msg_t *msg = malloc(offsetof(bmc_msg_t, msg) + sizeof(bmc_req_t) + 10);
|
||||||
|
*
|
||||||
|
* The amount allocated for the message is (# of bytes before the msg field) +
|
||||||
|
* the size of a bmc_req_t (which includes SEND_MAX_PAYLOAD_SIZE
|
||||||
|
* bytes in the data field), plus an additional 10 bytes for the data
|
||||||
|
* field (so the data field would occupy (SEND_MAX_PAYLOAD_SIZE + 10)
|
||||||
|
* bytes). The datalength member must reflect the amount of data in the
|
||||||
|
* request's data field (as was required when using the ioctl interface).
|
||||||
|
*/
|
||||||
|
typedef struct bmc_msg {
|
||||||
|
uint8_t m_type; /* Message type (see below) */
|
||||||
|
uint32_t m_id; /* Message ID */
|
||||||
|
uint8_t reserved[32];
|
||||||
|
uint8_t msg[1]; /* Variable length message data */
|
||||||
|
} bmc_msg_t;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* data structure to send a message to BMC.
|
* An error response passed back from the bmc driver will have its m_id
|
||||||
* Ref. IPMI Spec 9.2
|
* field set to BMC_UNKNOWN_MSG_ID if a message is sent to it that is not
|
||||||
|
* at least as large as a bmc_msg_t.
|
||||||
*/
|
*/
|
||||||
typedef struct bmc_send {
|
#define BMC_UNKNOWN_MSG_ID ~((uint32_t)0)
|
||||||
unsigned char fnlun; /* Network Function and LUN */
|
|
||||||
unsigned char cmd; /* command */
|
|
||||||
unsigned char data[SEND_MAX_PAYLOAD_SIZE];
|
|
||||||
} bmc_send_t;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* data structure to receive a message from BMC.
|
* Possible values for the m_type field in bmc_msg_t:
|
||||||
* Ref. IPMI Spec 9.3
|
|
||||||
*/
|
*/
|
||||||
typedef struct bmc_recv {
|
#define BMC_MSG_REQUEST 1 /* BMC request (as above, sent to the */
|
||||||
unsigned char fnlun; /* Network Function and LUN */
|
/* driver by the user), bmc_msg.msg */
|
||||||
unsigned char cmd; /* command */
|
/* begins with the bmc_req_t */
|
||||||
unsigned char ccode; /* completion code */
|
/* structure. */
|
||||||
unsigned char data[RECV_MAX_PAYLOAD_SIZE];
|
#define BMC_MSG_RESPONSE 2 /* BMC response (sent by the driver) */
|
||||||
} bmc_recv_t;
|
/* bmc_msg.msg begins with the */
|
||||||
|
/* bmc_rsp_t structure. */
|
||||||
|
#define BMC_MSG_ERROR 3 /* Error while processing a user msg */
|
||||||
#endif /* _KERNEL */
|
/* msg[0] is the error code */
|
||||||
|
/* (interpret as an errno value) */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#endif /* _BMC_INTF_H */
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* _BMC_INTF_H_ */
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user