Commit c7e26631 authored by Evgeniy Polyakov's avatar Evgeniy Polyakov Committed by Linus Torvalds

w1: allow master IO commands

This small patchset extendes existing commands with reset, master IO and
status messages.  Reset is used to reset the bus for given master device,
master IO command allows to initiate IO against bus itself not selecting
slave device first, which can be used to probe the device for example.
And status messages carry command completion status back to the userspace
(namely very useful to get -ENODEV from when requested device was not
found).

Great thanks to Paul Alfille of OWFS for testing and commands suggestions.

This patch:

Allow starting of IO not against already found slave devices, but against
the bus itself, which can be used for example to probe devices.

[akpm@linux-foundation.org: reindent switch statements]
Signed-off-by: default avatarEvgeniy Polyakov <zbr@ioremap.net>
Cc: Paul Alfille <paul.alfille@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent e4e056aa
...@@ -95,51 +95,8 @@ static int w1_process_search_command(struct w1_master *dev, struct cn_msg *msg, ...@@ -95,51 +95,8 @@ static int w1_process_search_command(struct w1_master *dev, struct cn_msg *msg,
return 0; return 0;
} }
static int w1_process_command_master(struct w1_master *dev, struct cn_msg *req_msg, static int w1_send_read_reply(struct cn_msg *msg, struct w1_netlink_msg *hdr,
struct w1_netlink_msg *req_hdr, struct w1_netlink_cmd *req_cmd) struct w1_netlink_cmd *cmd)
{
int err = -EINVAL;
struct cn_msg *msg;
struct w1_netlink_msg *hdr;
struct w1_netlink_cmd *cmd;
msg = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;
msg->id = req_msg->id;
msg->seq = req_msg->seq;
msg->ack = 0;
msg->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd);
hdr = (struct w1_netlink_msg *)(msg + 1);
cmd = (struct w1_netlink_cmd *)(hdr + 1);
hdr->type = W1_MASTER_CMD;
hdr->id = req_hdr->id;
hdr->len = sizeof(struct w1_netlink_cmd);
cmd->cmd = req_cmd->cmd;
cmd->len = 0;
switch (cmd->cmd) {
case W1_CMD_SEARCH:
case W1_CMD_ALARM_SEARCH:
err = w1_process_search_command(dev, msg,
PAGE_SIZE - msg->len - sizeof(struct cn_msg));
break;
default:
cmd->res = EINVAL;
cn_netlink_send(msg, 0, GFP_KERNEL);
break;
}
kfree(msg);
return err;
}
static int w1_send_read_reply(struct w1_slave *sl, struct cn_msg *msg,
struct w1_netlink_msg *hdr, struct w1_netlink_cmd *cmd)
{ {
void *data; void *data;
struct w1_netlink_msg *h; struct w1_netlink_msg *h;
...@@ -163,7 +120,8 @@ static int w1_send_read_reply(struct w1_slave *sl, struct cn_msg *msg, ...@@ -163,7 +120,8 @@ static int w1_send_read_reply(struct w1_slave *sl, struct cn_msg *msg,
memcpy(c, cmd, sizeof(struct w1_netlink_cmd)); memcpy(c, cmd, sizeof(struct w1_netlink_cmd));
cm->ack = msg->seq+1; cm->ack = msg->seq+1;
cm->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd) + cmd->len; cm->len = sizeof(struct w1_netlink_msg) +
sizeof(struct w1_netlink_cmd) + cmd->len;
h->len = sizeof(struct w1_netlink_cmd) + cmd->len; h->len = sizeof(struct w1_netlink_cmd) + cmd->len;
...@@ -176,35 +134,89 @@ static int w1_send_read_reply(struct w1_slave *sl, struct cn_msg *msg, ...@@ -176,35 +134,89 @@ static int w1_send_read_reply(struct w1_slave *sl, struct cn_msg *msg,
return err; return err;
} }
static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg, static int w1_process_command_io(struct w1_master *dev, struct cn_msg *msg,
struct w1_netlink_msg *hdr, struct w1_netlink_cmd *cmd) struct w1_netlink_msg *hdr, struct w1_netlink_cmd *cmd)
{ {
int err = 0; int err = 0;
dev_dbg(&sl->master->dev, "%s: %02x.%012llx.%02x: cmd=%02x, len=%u.\n", switch (cmd->cmd) {
__func__, sl->reg_num.family, (unsigned long long)sl->reg_num.id, sl->reg_num.crc, case W1_CMD_TOUCH:
cmd->cmd, cmd->len); w1_touch_block(dev, cmd->data, cmd->len);
w1_send_read_reply(msg, hdr, cmd);
break;
case W1_CMD_READ:
w1_read_block(dev, cmd->data, cmd->len);
w1_send_read_reply(msg, hdr, cmd);
break;
case W1_CMD_WRITE:
w1_write_block(dev, cmd->data, cmd->len);
break;
default:
err = -1;
break;
}
return err;
}
static int w1_process_command_master(struct w1_master *dev, struct cn_msg *req_msg,
struct w1_netlink_msg *req_hdr, struct w1_netlink_cmd *req_cmd)
{
int err = -EINVAL;
struct cn_msg *msg;
struct w1_netlink_msg *hdr;
struct w1_netlink_cmd *cmd;
msg = kzalloc(PAGE_SIZE, GFP_KERNEL);
if (!msg)
return -ENOMEM;
msg->id = req_msg->id;
msg->seq = req_msg->seq;
msg->ack = 0;
msg->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd);
hdr = (struct w1_netlink_msg *)(msg + 1);
cmd = (struct w1_netlink_cmd *)(hdr + 1);
hdr->type = W1_MASTER_CMD;
hdr->id = req_hdr->id;
hdr->len = sizeof(struct w1_netlink_cmd);
cmd->cmd = req_cmd->cmd;
cmd->len = 0;
switch (cmd->cmd) { switch (cmd->cmd) {
case W1_CMD_TOUCH: case W1_CMD_SEARCH:
w1_touch_block(sl->master, cmd->data, cmd->len); case W1_CMD_ALARM_SEARCH:
w1_send_read_reply(sl, msg, hdr, cmd); err = w1_process_search_command(dev, msg,
break; PAGE_SIZE - msg->len - sizeof(struct cn_msg));
case W1_CMD_READ: break;
w1_read_block(sl->master, cmd->data, cmd->len); case W1_CMD_READ:
w1_send_read_reply(sl, msg, hdr, cmd); case W1_CMD_WRITE:
break; case W1_CMD_TOUCH:
case W1_CMD_WRITE: err = w1_process_command_io(dev, msg, hdr, cmd);
w1_write_block(sl->master, cmd->data, cmd->len); break;
break; default:
default: cmd->res = EINVAL;
err = -1; cn_netlink_send(msg, 0, GFP_KERNEL);
break; break;
} }
kfree(msg);
return err; return err;
} }
static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg,
struct w1_netlink_msg *hdr, struct w1_netlink_cmd *cmd)
{
dev_dbg(&sl->master->dev, "%s: %02x.%012llx.%02x: cmd=%02x, len=%u.\n",
__func__, sl->reg_num.family, (unsigned long long)sl->reg_num.id,
sl->reg_num.crc, cmd->cmd, cmd->len);
return w1_process_command_io(sl->master, msg, hdr, cmd);
}
static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mcmd) static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mcmd)
{ {
struct w1_master *m; struct w1_master *m;
...@@ -214,7 +226,7 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc ...@@ -214,7 +226,7 @@ static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mc
if (mcmd->type != W1_LIST_MASTERS) { if (mcmd->type != W1_LIST_MASTERS) {
printk(KERN_NOTICE "%s: msg: %x.%x, wrong type: %u, len: %u.\n", printk(KERN_NOTICE "%s: msg: %x.%x, wrong type: %u, len: %u.\n",
__func__, msg->id.idx, msg->id.val, mcmd->type, mcmd->len); __func__, msg->id.idx, msg->id.val, mcmd->type, mcmd->len);
return -EPROTO; return -EPROTO;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment