Minor bug fixes for IPMI
I know this is late; I've been travelling and, well, I've been distracted. This is just a few bug fixes and adding i2c support to the IPMB driver, which is something I wanted from the beginning for it. It would be nice for the people doing IPMB to get this in. -corey -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE/Q1c5nzg9ZpmiCaGYfOMkJGb/4EFAl5B8nsACgkQYfOMkJGb /4F0Vg//SsvGNoEVMbjXFEAq671fYslNLa1p7lEzvhoSFAFs0bOiu0LnEwkCGEof k3alCw8RgWAchf16iQk3OEthdbMMJzA/6X7ec87uOXNUOpmZT/S5LaonOlPdA1GZ p3qOrBdsy1VCptxVBRvv4dJFLSbiocd0ElunIKDzfwAPUXLkmHKklS9o2DmKD27F CgXi/9cdRz6MleUubosKeG4WXEgsSmMmytjgRMqVpCA8QcG+4EKefLfqC7Iez5C4 Ol3rHOOUn/InXlHLyb1NR66s69J5CqdNt8yEZAAmc7PypnGt0Qc6RTPV2UI+CZ6/ ahJqpZmJ1vYeVJKyT9A6Bdy89uASk4y5+p72hXR4jaoRS4dHXTimmiJZHGGbEAXw 3u2qRRBvrbyi91+lpDXKV+Bp4le43J+dRVlaBW/xhipOqycwD1all4h6185jD7er VEsrOcU2gd5AeMQ0OudRR6LvNcyS6XhF/DYC/lc1932ojLjTP4MNPbv8mFbIYN7d JgbzvFTNCEs5x1+QHdXJ5thqv18n6OMAxIKSfJkm4ywojR0Rv1Oj7/Ov+yHJZ2s6 DBGMJhQJrQJWCXgWXQY/s+x5MSbDrlAUPWhUzKrv5BXJaqbq+fr+zYOJWW3v9q+a FGXHQXBI8EwBLsVXASfwT5tf5GHj7QyKdV3qEWu+moZtdGBT6HE= =y+e9 -----END PGP SIGNATURE----- Merge tag 'for-linus-5.6-1' of https://github.com/cminyard/linux-ipmi Pull IPMI update from Corey Minyard: "Minor bug fixes for IPMI I know this is late; I've been travelling and, well, I've been distracted. This is just a few bug fixes and adding i2c support to the IPMB driver, which is something I wanted from the beginning for it" * tag 'for-linus-5.6-1' of https://github.com/cminyard/linux-ipmi: drivers: ipmi: fix off-by-one bounds check that leads to a out-of-bounds write ipmi:ssif: Handle a possible NULL pointer reference drivers: ipmi: Modify max length of IPMB packet drivers: ipmi: Support raw i2c packet in IPMB
This commit is contained in:
commit
ab02b61f24
|
@ -71,9 +71,13 @@ b) Example for device tree::
|
|||
ipmb@10 {
|
||||
compatible = "ipmb-dev";
|
||||
reg = <0x10>;
|
||||
i2c-protocol;
|
||||
};
|
||||
};
|
||||
|
||||
If xmit of data to be done using raw i2c block vs smbus
|
||||
then "i2c-protocol" needs to be defined as above.
|
||||
|
||||
2) Manually from Linux::
|
||||
|
||||
modprobe ipmb-dev-int
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <linux/spinlock.h>
|
||||
#include <linux/wait.h>
|
||||
|
||||
#define MAX_MSG_LEN 128
|
||||
#define MAX_MSG_LEN 240
|
||||
#define IPMB_REQUEST_LEN_MIN 7
|
||||
#define NETFN_RSP_BIT_MASK 0x4
|
||||
#define REQUEST_QUEUE_MAX_LEN 256
|
||||
|
@ -63,6 +63,7 @@ struct ipmb_dev {
|
|||
spinlock_t lock;
|
||||
wait_queue_head_t wait_queue;
|
||||
struct mutex file_mutex;
|
||||
bool is_i2c_protocol;
|
||||
};
|
||||
|
||||
static inline struct ipmb_dev *to_ipmb_dev(struct file *file)
|
||||
|
@ -112,6 +113,25 @@ static ssize_t ipmb_read(struct file *file, char __user *buf, size_t count,
|
|||
return ret < 0 ? ret : count;
|
||||
}
|
||||
|
||||
static int ipmb_i2c_write(struct i2c_client *client, u8 *msg, u8 addr)
|
||||
{
|
||||
struct i2c_msg i2c_msg;
|
||||
|
||||
/*
|
||||
* subtract 1 byte (rq_sa) from the length of the msg passed to
|
||||
* raw i2c_transfer
|
||||
*/
|
||||
i2c_msg.len = msg[IPMB_MSG_LEN_IDX] - 1;
|
||||
|
||||
/* Assign message to buffer except first 2 bytes (length and address) */
|
||||
i2c_msg.buf = msg + 2;
|
||||
|
||||
i2c_msg.addr = addr;
|
||||
i2c_msg.flags = client->flags & I2C_CLIENT_PEC;
|
||||
|
||||
return i2c_transfer(client->adapter, &i2c_msg, 1);
|
||||
}
|
||||
|
||||
static ssize_t ipmb_write(struct file *file, const char __user *buf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
|
@ -133,6 +153,12 @@ static ssize_t ipmb_write(struct file *file, const char __user *buf,
|
|||
rq_sa = GET_7BIT_ADDR(msg[RQ_SA_8BIT_IDX]);
|
||||
netf_rq_lun = msg[NETFN_LUN_IDX];
|
||||
|
||||
/* Check i2c block transfer vs smbus */
|
||||
if (ipmb_dev->is_i2c_protocol) {
|
||||
ret = ipmb_i2c_write(ipmb_dev->client, msg, rq_sa);
|
||||
return (ret == 1) ? count : ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* subtract rq_sa and netf_rq_lun from the length of the msg passed to
|
||||
* i2c_smbus_xfer
|
||||
|
@ -253,7 +279,7 @@ static int ipmb_slave_cb(struct i2c_client *client,
|
|||
break;
|
||||
|
||||
case I2C_SLAVE_WRITE_RECEIVED:
|
||||
if (ipmb_dev->msg_idx >= sizeof(struct ipmb_msg))
|
||||
if (ipmb_dev->msg_idx >= sizeof(struct ipmb_msg) - 1)
|
||||
break;
|
||||
|
||||
buf[++ipmb_dev->msg_idx] = *val;
|
||||
|
@ -302,6 +328,9 @@ static int ipmb_probe(struct i2c_client *client,
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
ipmb_dev->is_i2c_protocol
|
||||
= device_property_read_bool(&client->dev, "i2c-protocol");
|
||||
|
||||
ipmb_dev->client = client;
|
||||
i2c_set_clientdata(client, ipmb_dev);
|
||||
ret = i2c_slave_register(client, ipmb_slave_cb);
|
||||
|
|
|
@ -775,10 +775,14 @@ static void msg_done_handler(struct ssif_info *ssif_info, int result,
|
|||
flags = ipmi_ssif_lock_cond(ssif_info, &oflags);
|
||||
msg = ssif_info->curr_msg;
|
||||
if (msg) {
|
||||
if (data) {
|
||||
if (len > IPMI_MAX_MSG_LENGTH)
|
||||
len = IPMI_MAX_MSG_LENGTH;
|
||||
memcpy(msg->rsp, data, len);
|
||||
} else {
|
||||
len = 0;
|
||||
}
|
||||
msg->rsp_size = len;
|
||||
if (msg->rsp_size > IPMI_MAX_MSG_LENGTH)
|
||||
msg->rsp_size = IPMI_MAX_MSG_LENGTH;
|
||||
memcpy(msg->rsp, data, msg->rsp_size);
|
||||
ssif_info->curr_msg = NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue