* [W1] Added list masters w1 command.
2008-12-04 14:50 ` Evgeniy Polyakov
@ 2008-12-04 14:50 ` Evgeniy Polyakov
2008-12-04 15:41 ` Frederik Deweerdt
0 siblings, 1 reply; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-12-04 14:50 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, Evgeniy Polyakov
Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
---
drivers/w1/w1_netlink.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
drivers/w1/w1_netlink.h | 1 +
2 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index 65c5ebd..a3b2630 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -128,6 +128,59 @@ static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg,
return err;
}
+static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mcmd)
+{
+ struct w1_master *m;
+ struct cn_msg *cn;
+ struct w1_netlink_msg *w;
+ u32 *id;
+
+ if (mcmd->type != W1_LIST_MASTERS) {
+ printk(KERN_NOTICE "%s: msg: %x.%x, wrong type: %u, len: %u.\n",
+ __func__, msg->id.idx, msg->id.val, mcmd->type, mcmd->len);
+ return -EPROTO;
+ }
+
+ cn = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!cn)
+ return -ENOMEM;
+
+ cn->id.idx = CN_W1_IDX;
+ cn->id.val = CN_W1_VAL;
+
+ cn->seq = msg->seq;
+ cn->ack = 1;
+ cn->len = sizeof(struct w1_netlink_msg);
+ w = (struct w1_netlink_msg *)(cn + 1);
+
+ w->type = W1_LIST_MASTERS;
+ w->reserved = 0;
+ w->len = 0;
+ id = (u32 *)(w + 1);
+
+ mutex_lock(&w1_mlock);
+ list_for_each_entry(m, &w1_masters, w1_master_entry) {
+ if (cn->len + sizeof(*id) > PAGE_SIZE - sizeof(struct cn_msg)) {
+ cn_netlink_send(cn, 0, GFP_KERNEL);
+ cn->ack++
+ cn->len = sizeof(struct w1_netlink_msg);
+ w->len = 0;
+ id = (u32 *)(w + 1);
+ }
+
+ *id = m->id;
+ w->len += sizeof(*id);
+ cn->len += sizeof(*id);
+ id++;
+ }
+ cn->ack = 0;
+ cn_netlink_send(cn, 0, GFP_KERNEL);
+ mutex_unlock(&w1_mlock);
+
+ kfree(cn);
+ return 0;
+}
+
static void w1_cn_callback(void *data)
{
struct cn_msg *msg = data;
@@ -164,6 +217,9 @@ static void w1_cn_callback(void *data)
sl = w1_search_slave(&id);
if (sl)
dev = sl->master;
+ } else {
+ err = w1_process_command_root(msg, m);
+ goto out_cont;
}
if (!dev) {
diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h
index 56122b9..21913df 100644
--- a/drivers/w1/w1_netlink.h
+++ b/drivers/w1/w1_netlink.h
@@ -34,6 +34,7 @@ enum w1_netlink_message_types {
W1_MASTER_REMOVE,
W1_MASTER_CMD,
W1_SLAVE_CMD,
+ W1_LIST_MASTERS,
};
struct w1_netlink_msg
--
1.5.2.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [W1] Added list masters w1 command.
2008-12-04 14:50 ` [W1] Added list masters w1 command Evgeniy Polyakov
@ 2008-12-04 15:41 ` Frederik Deweerdt
0 siblings, 0 replies; 9+ messages in thread
From: Frederik Deweerdt @ 2008-12-04 15:41 UTC (permalink / raw)
To: Evgeniy Polyakov; +Cc: Andrew Morton, linux-kernel
Hi Evgeniy,
On Thu, Dec 04, 2008 at 05:50:06PM +0300, Evgeniy Polyakov wrote:
> + mutex_lock(&w1_mlock);
> + list_for_each_entry(m, &w1_masters, w1_master_entry) {
> + if (cn->len + sizeof(*id) > PAGE_SIZE - sizeof(struct cn_msg)) {
> + cn_netlink_send(cn, 0, GFP_KERNEL);
> + cn->ack++
^^^^^^^^^^
';' is missing here
Regards,
Frederik
^ permalink raw reply [flat|nested] 9+ messages in thread
* [W1 take2]: extend userspace commands.
@ 2008-12-05 12:41 Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Added list masters w1 command Evgeniy Polyakov
0 siblings, 1 reply; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-12-05 12:41 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Frederik Deweerdt, Randy Dunlap, Evgeniy Polyakov
Hi.
This patch series introduces and extends several userspace commands
used with netlink protocol.
Touch block command allows to write data and return sampled data to
the userspace.
Extended search and alarm seach commands to return list of slave
devices found during given search.
List masters command allows to send all registered master IDs to the
userspace.
Great thanks to Paul Alfille <paul.alfille@gmail.com> (owfs) who
tested this implementation and wrote w1-to-network daemon
http://sourceforge.net/projects/w1repeater/ and
Frederik Deweerdt <frederik.deweerdt@xprog.eu> and
Randy Dunlap <randy.dunlap@oracle.com> for review.
Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
^ permalink raw reply [flat|nested] 9+ messages in thread
* [W1] Added list masters w1 command.
2008-12-05 12:41 [W1 take2]: extend userspace commands Evgeniy Polyakov
@ 2008-12-05 12:41 ` Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Added touch block command Evgeniy Polyakov
0 siblings, 1 reply; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-12-05 12:41 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Frederik Deweerdt, Randy Dunlap, Evgeniy Polyakov
Returns list of registered bus master devices.
Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
---
drivers/w1/w1_netlink.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++
drivers/w1/w1_netlink.h | 1 +
2 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index 65c5ebd..a3b2630 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -128,6 +128,59 @@ static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg,
return err;
}
+static int w1_process_command_root(struct cn_msg *msg, struct w1_netlink_msg *mcmd)
+{
+ struct w1_master *m;
+ struct cn_msg *cn;
+ struct w1_netlink_msg *w;
+ u32 *id;
+
+ if (mcmd->type != W1_LIST_MASTERS) {
+ printk(KERN_NOTICE "%s: msg: %x.%x, wrong type: %u, len: %u.\n",
+ __func__, msg->id.idx, msg->id.val, mcmd->type, mcmd->len);
+ return -EPROTO;
+ }
+
+ cn = kmalloc(PAGE_SIZE, GFP_KERNEL);
+ if (!cn)
+ return -ENOMEM;
+
+ cn->id.idx = CN_W1_IDX;
+ cn->id.val = CN_W1_VAL;
+
+ cn->seq = msg->seq;
+ cn->ack = 1;
+ cn->len = sizeof(struct w1_netlink_msg);
+ w = (struct w1_netlink_msg *)(cn + 1);
+
+ w->type = W1_LIST_MASTERS;
+ w->reserved = 0;
+ w->len = 0;
+ id = (u32 *)(w + 1);
+
+ mutex_lock(&w1_mlock);
+ list_for_each_entry(m, &w1_masters, w1_master_entry) {
+ if (cn->len + sizeof(*id) > PAGE_SIZE - sizeof(struct cn_msg)) {
+ cn_netlink_send(cn, 0, GFP_KERNEL);
+ cn->ack++;
+ cn->len = sizeof(struct w1_netlink_msg);
+ w->len = 0;
+ id = (u32 *)(w + 1);
+ }
+
+ *id = m->id;
+ w->len += sizeof(*id);
+ cn->len += sizeof(*id);
+ id++;
+ }
+ cn->ack = 0;
+ cn_netlink_send(cn, 0, GFP_KERNEL);
+ mutex_unlock(&w1_mlock);
+
+ kfree(cn);
+ return 0;
+}
+
static void w1_cn_callback(void *data)
{
struct cn_msg *msg = data;
@@ -164,6 +217,9 @@ static void w1_cn_callback(void *data)
sl = w1_search_slave(&id);
if (sl)
dev = sl->master;
+ } else {
+ err = w1_process_command_root(msg, m);
+ goto out_cont;
}
if (!dev) {
diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h
index 56122b9..21913df 100644
--- a/drivers/w1/w1_netlink.h
+++ b/drivers/w1/w1_netlink.h
@@ -34,6 +34,7 @@ enum w1_netlink_message_types {
W1_MASTER_REMOVE,
W1_MASTER_CMD,
W1_SLAVE_CMD,
+ W1_LIST_MASTERS,
};
struct w1_netlink_msg
--
1.5.2.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [W1] Added touch block command.
2008-12-05 12:41 ` [W1] Added list masters w1 command Evgeniy Polyakov
@ 2008-12-05 12:41 ` Evgeniy Polyakov
2008-12-05 12:41 ` [W1] List slaves commands Evgeniy Polyakov
0 siblings, 1 reply; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-12-05 12:41 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Frederik Deweerdt, Randy Dunlap, Evgeniy Polyakov
Writes and returns sampled data back to userspace.
Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
---
drivers/w1/w1.h | 1 +
drivers/w1/w1_io.c | 26 +++++++++++++++++++++++++-
drivers/w1/w1_netlink.c | 13 +++++++++----
drivers/w1/w1_netlink.h | 1 +
4 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index 97304bd..d8a9709 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -210,6 +210,7 @@ u8 w1_read_8(struct w1_master *);
int w1_reset_bus(struct w1_master *);
u8 w1_calc_crc8(u8 *, int);
void w1_write_block(struct w1_master *, const u8 *, int);
+void w1_touch_block(struct w1_master *, u8 *, int);
u8 w1_read_block(struct w1_master *, u8 *, int);
int w1_reset_select_slave(struct w1_slave *sl);
void w1_next_pullup(struct w1_master *, int);
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
index 0d15b0e..3d781f8 100644
--- a/drivers/w1/w1_io.c
+++ b/drivers/w1/w1_io.c
@@ -238,7 +238,6 @@ EXPORT_SYMBOL_GPL(w1_read_8);
* @param dev the master device
* @param buf pointer to the data to write
* @param len the number of bytes to write
- * @return the byte read
*/
void w1_write_block(struct w1_master *dev, const u8 *buf, int len)
{
@@ -256,6 +255,31 @@ void w1_write_block(struct w1_master *dev, const u8 *buf, int len)
EXPORT_SYMBOL_GPL(w1_write_block);
/**
+ * Touches a series of bytes.
+ *
+ * @param dev the master device
+ * @param buf pointer to the data to write
+ * @param len the number of bytes to write
+ */
+void w1_touch_block(struct w1_master *dev, u8 *buf, int len)
+{
+ int i, j;
+ u8 tmp;
+
+ for (i = 0; i < len; ++i) {
+ tmp = 0;
+ for (j = 0; j < 8; ++j) {
+ if (j == 7)
+ w1_pre_write(dev);
+ tmp |= w1_touch_bit(dev, (buf[i] >> j) & 0x1) << j;
+ }
+
+ buf[i] = tmp;
+ }
+}
+EXPORT_SYMBOL_GPL(w1_touch_block);
+
+/**
* Reads a series of bytes.
*
* @param dev the master device
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index a3b2630..cae556c 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -108,6 +108,10 @@ static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg,
cmd->cmd, cmd->len);
switch (cmd->cmd) {
+ case W1_CMD_TOUCH:
+ w1_touch_block(sl->master, cmd->data, cmd->len);
+ w1_send_read_reply(sl, msg, hdr, cmd);
+ break;
case W1_CMD_READ:
w1_read_block(sl->master, cmd->data, cmd->len);
w1_send_read_reply(sl, msg, hdr, cmd);
@@ -208,9 +212,6 @@ static void w1_cn_callback(void *data)
break;
}
- if (!mlen)
- goto out_cont;
-
if (m->type == W1_MASTER_CMD) {
dev = w1_search_master_id(m->id.mst.id);
} else if (m->type == W1_SLAVE_CMD) {
@@ -227,6 +228,10 @@ static void w1_cn_callback(void *data)
goto out_cont;
}
+ err = 0;
+ if (!mlen)
+ goto out_cont;
+
mutex_lock(&dev->mutex);
if (sl && w1_reset_select_slave(sl)) {
diff --git a/drivers/w1/w1_netlink.h b/drivers/w1/w1_netlink.h
index 21913df..99dd21b 100644
--- a/drivers/w1/w1_netlink.h
+++ b/drivers/w1/w1_netlink.h
@@ -56,6 +56,7 @@ struct w1_netlink_msg
#define W1_CMD_WRITE 0x1
#define W1_CMD_SEARCH 0x2
#define W1_CMD_ALARM_SEARCH 0x3
+#define W1_CMD_TOUCH 0x4
struct w1_netlink_cmd
{
--
1.5.2.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [W1] List slaves commands.
2008-12-05 12:41 ` [W1] Added touch block command Evgeniy Polyakov
@ 2008-12-05 12:41 ` Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Documentation update Evgeniy Polyakov
2008-12-08 21:58 ` [W1] List slaves commands Andrew Morton
0 siblings, 2 replies; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-12-05 12:41 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Frederik Deweerdt, Randy Dunlap, Evgeniy Polyakov
Initiates search (or alarm search) and returns all found devices to userspace.
Found devices are not added into the system (i.e. they are not attached
to family devices or bus masters), it will be done via (if was not done yet)
usual timed searching.
Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
---
drivers/w1/w1_netlink.c | 102 +++++++++++++++++++++++++++++++++++++++--------
1 files changed, 85 insertions(+), 17 deletions(-)
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index cae556c..24ad6bb 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -47,19 +47,97 @@ void w1_netlink_send(struct w1_master *dev, struct w1_netlink_msg *msg)
cn_netlink_send(m, 0, GFP_KERNEL);
}
-static int w1_process_command_master(struct w1_master *dev, struct cn_msg *msg,
- struct w1_netlink_msg *hdr, struct w1_netlink_cmd *cmd)
+static void w1_send_slave(struct w1_master *dev, u64 rn)
{
- dev_dbg(&dev->dev, "%s: %s: cmd=%02x, len=%u.\n",
- __func__, dev->name, cmd->cmd, cmd->len);
+ struct cn_msg *msg = dev->priv;
+ struct w1_netlink_msg *hdr = (struct w1_netlink_msg *)(msg + 1);
+ struct w1_netlink_cmd *cmd = (struct w1_netlink_cmd *)(hdr + 1);
+ int avail;
+
+ avail = dev->priv_size - cmd->len;
+
+ if (avail > 8) {
+ u64 *data = (void *)(cmd + 1) + cmd->len;
+
+ *data = rn;
+ cmd->len += 8;
+ hdr->len += 8;
+ msg->len += 8;
+ return;
+ }
+
+ msg->ack++;
+ cn_netlink_send(msg, 0, GFP_KERNEL);
+
+ msg->len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd);
+ hdr->len = sizeof(struct w1_netlink_cmd);
+ cmd->len = 0;
+}
+
+static int w1_process_search_command(struct w1_master *dev, struct cn_msg *msg,
+ unsigned int avail)
+{
+ struct w1_netlink_msg *hdr = (struct w1_netlink_msg *)(msg + 1);
+ struct w1_netlink_cmd *cmd = (struct w1_netlink_cmd *)(hdr + 1);
+ int search_type = (cmd->cmd == W1_CMD_ALARM_SEARCH)?W1_ALARM_SEARCH:W1_SEARCH;
+
+ dev->priv = msg;
+ dev->priv_size = avail;
+
+ w1_search_devices(dev, search_type, w1_send_slave);
- if (cmd->cmd != W1_CMD_SEARCH && cmd->cmd != W1_CMD_ALARM_SEARCH)
- return -EINVAL;
+ msg->ack = 0;
+ cn_netlink_send(msg, 0, GFP_KERNEL);
+
+ dev->priv = NULL;
+ dev->priv_size = 0;
- w1_search_process(dev, (cmd->cmd == W1_CMD_ALARM_SEARCH)?W1_ALARM_SEARCH:W1_SEARCH);
return 0;
}
+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) {
+ 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)
{
@@ -119,11 +197,6 @@ static int w1_process_command_slave(struct w1_slave *sl, struct cn_msg *msg,
case W1_CMD_WRITE:
w1_write_block(sl->master, cmd->data, cmd->len);
break;
- case W1_CMD_SEARCH:
- case W1_CMD_ALARM_SEARCH:
- w1_search_process(sl->master,
- (cmd->cmd == W1_CMD_ALARM_SEARCH)?W1_ALARM_SEARCH:W1_SEARCH);
- break;
default:
err = -1;
break;
@@ -270,11 +343,6 @@ out_cont:
if (err == -ENODEV)
err = 0;
}
-#if 0
- if (err) {
- printk("%s: malformed message. Dropping.\n", __func__);
- }
-#endif
}
int w1_init_netlink(void)
--
1.5.2.5
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [W1] Documentation update.
2008-12-05 12:41 ` [W1] List slaves commands Evgeniy Polyakov
@ 2008-12-05 12:41 ` Evgeniy Polyakov
2008-12-08 21:58 ` [W1] List slaves commands Andrew Morton
1 sibling, 0 replies; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-12-05 12:41 UTC (permalink / raw)
To: Andrew Morton
Cc: linux-kernel, Frederik Deweerdt, Randy Dunlap, Evgeniy Polyakov
Signed-off-by: Evgeniy Polyakov <zbr@ioremap.net>
---
diff --git a/Documentation/w1/w1.netlink b/Documentation/w1/w1.netlink
index 3640c7c..4560180 100644
--- a/Documentation/w1/w1.netlink
+++ b/Documentation/w1/w1.netlink
@@ -5,69 +5,122 @@ Message types.
=============
There are three types of messages between w1 core and userspace:
-1. Events. They are generated each time new master or slave device found
- either due to automatic or requested search.
-2. Userspace commands. Includes read/write and search/alarm search comamnds.
+1. Events. They are generated each time new master or slave device
+ found either due to automatic or requested search.
+2. Userspace commands.
3. Replies to userspace commands.
Protocol.
========
-[struct cn_msg] - connector header. It's length field is equal to size of the attached data.
+[struct cn_msg] - connector header.
+ Its length field is equal to size of the attached data
[struct w1_netlink_msg] - w1 netlink header.
__u8 type - message type.
- W1_SLAVE_ADD/W1_SLAVE_REMOVE - slave add/remove events.
- W1_MASTER_ADD/W1_MASTER_REMOVE - master add/remove events.
- W1_MASTER_CMD - userspace command for bus master device (search/alarm search).
- W1_SLAVE_CMD - userspace command for slave device (read/write/ search/alarm search
- for bus master device where given slave device found).
+ W1_LIST_MASTERS
+ list current bus masters
+ W1_SLAVE_ADD/W1_SLAVE_REMOVE
+ slave add/remove events
+ W1_MASTER_ADD/W1_MASTER_REMOVE
+ master add/remove events
+ W1_MASTER_CMD
+ userspace command for bus master
+ device (search/alarm search)
+ W1_SLAVE_CMD
+ userspace command for slave device
+ (read/write/touch)
__u8 res - reserved
- __u16 len - size of attached to this header data.
+ __u16 len - size of data attached to this header data
union {
- __u8 id; - slave unique device id
+ __u8 id[8]; - slave unique device id
struct w1_mst {
- __u32 id; - master's id.
+ __u32 id; - master's id
__u32 res; - reserved
} mst;
} id;
-[strucrt w1_netlink_cmd] - command for gived master or slave device.
+[struct w1_netlink_cmd] - command for given master or slave device.
__u8 cmd - command opcode.
- W1_CMD_READ - read command.
- W1_CMD_WRITE - write command.
- W1_CMD_SEARCH - search command.
- W1_CMD_ALARM_SEARCH - alarm search command.
+ W1_CMD_READ - read command
+ W1_CMD_WRITE - write command
+ W1_CMD_TOUCH - touch command
+ (write and sample data back to userspace)
+ W1_CMD_SEARCH - search command
+ W1_CMD_ALARM_SEARCH - alarm search command
__u8 res - reserved
- __u16 len - length of data for this command.
- For read command data must be allocated like for write command.
- __u8 data[0] - data for this command.
+ __u16 len - length of data for this command
+ For read command data must be allocated like for write command
+ __u8 data[0] - data for this command
-Each connector message can include one or more w1_netlink_msg with zero of more attached w1_netlink_cmd messages.
+Each connector message can include one or more w1_netlink_msg with
+zero or more attached w1_netlink_cmd messages.
-For event messages there are no w1_netlink_cmd embedded structures, only connector header
-and w1_netlink_msg strucutre with "len" field being zero and filled type (one of event types)
-and id - either 8 bytes of slave unique id in host order, or master's id, which is assigned
-to bus master device when it is added to w1 core.
+For event messages there are no w1_netlink_cmd embedded structures,
+only connector header and w1_netlink_msg strucutre with "len" field
+being zero and filled type (one of event types) and id:
+either 8 bytes of slave unique id in host order,
+or master's id, which is assigned to bus master device
+when it is added to w1 core.
+
+Currently replies to userspace commands are only generated for read
+command request. One reply is generated exactly for one w1_netlink_cmd
+read request. Replies are not combined when sent - i.e. typical reply
+messages looks like the following:
-Currently replies to userspace commands are only generated for read command request.
-One reply is generated exactly for one w1_netlink_cmd read request.
-Replies are not combined when sent - i.e. typical reply messages looks like the following:
[cn_msg][w1_netlink_msg][w1_netlink_cmd]
-cn_msg.len = sizeof(struct w1_netlink_msg) + sizeof(struct w1_netlink_cmd) + cmd->len;
+cn_msg.len = sizeof(struct w1_netlink_msg) +
+ sizeof(struct w1_netlink_cmd) +
+ cmd->len;
w1_netlink_msg.len = sizeof(struct w1_netlink_cmd) + cmd->len;
w1_netlink_cmd.len = cmd->len;
+Replies to W1_LIST_MASTERS should send a message back to the userspace
+which will contain list of all registered master ids in the following
+format:
+
+ cn_msg (CN_W1_IDX.CN_W1_VAL as id, len is equal to sizeof(struct
+ w1_netlink_msg) plus number of masters multipled by 4)
+ w1_netlink_msg (type: W1_LIST_MASTERS, len is equal to
+ number of masters multiplied by 4 (u32 size))
+ id0 ... idN
+
+ Each message is at most 4k in size, so if number of master devices
+ exceeds this, it will be split into several messages,
+ cn.seq will be increased for each one.
+
+W1 search and alarm search commands.
+request:
+[cn_msg]
+ [w1_netlink_msg type = W1_MASTER_CMD
+ id is equal to the bus master id to use for searching]
+ [w1_netlink_cmd cmd = W1_CMD_SEARCH or W1_CMD_ALARM_SEARCH]
+
+reply:
+ [cn_msg, ack = 1 and increasing, 0 means the last message,
+ seq is equal to the request seq]
+ [w1_netlink_msg type = W1_MASTER_CMD]
+ [w1_netlink_cmd cmd = W1_CMD_SEARCH or W1_CMD_ALARM_SEARCH
+ len is equal to number of IDs multiplied by 8]
+ [64bit-id0 ... 64bit-idN]
+Length in each header corresponds to the size of the data behind it, so
+w1_netlink_cmd->len = N * 8; where N is number of IDs in this message.
+ Can be zero.
+w1_netlink_msg->len = sizeof(struct w1_netlink_cmd) + N * 8;
+cn_msg->len = sizeof(struct w1_netlink_msg) +
+ sizeof(struct w1_netlink_cmd) +
+ N*8;
Operation steps in w1 core when new command is received.
=======================================================
-When new message (w1_netlink_msg) is received w1 core detects if it is master of slave request,
-according to w1_netlink_msg.type field.
+When new message (w1_netlink_msg) is received w1 core detects if it is
+master or slave request, according to w1_netlink_msg.type field.
Then master or slave device is searched for.
-When found, master device (requested or those one on where slave device is found) is locked.
-If slave command is requested, then reset/select procedure is started to select given device.
+When found, master device (requested or those one on where slave device
+is found) is locked. If slave command is requested, then reset/select
+procedure is started to select given device.
Then all requested in w1_netlink_msg operations are performed one by one.
If command requires reply (like read command) it is sent on command completion.
@@ -82,8 +135,8 @@ Connector [1] specific documentation.
Each connector message includes two u32 fields as "address".
w1 uses CN_W1_IDX and CN_W1_VAL defined in include/linux/connector.h header.
Each message also includes sequence and acknowledge numbers.
-Sequence number for event messages is appropriate bus master sequence number increased with
-each event message sent "through" this master.
+Sequence number for event messages is appropriate bus master sequence number
+increased with each event message sent "through" this master.
Sequence number for userspace requests is set by userspace application.
Sequence number for reply is the same as was in request, and
acknowledge number is set to seq+1.
@@ -93,6 +146,6 @@ Additional documantion, source code examples.
============================================
1. Documentation/connector
-2. http://tservice.net.ru/~s0mbre/archive/w1
-This archive includes userspace application w1d.c which
-uses read/write/search commands for all master/slave devices found on the bus.
+2. http://www.ioremap.net/archive/w1
+This archive includes userspace application w1d.c which uses
+read/write/search commands for all master/slave devices found on the bus.
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [W1] List slaves commands.
2008-12-05 12:41 ` [W1] List slaves commands Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Documentation update Evgeniy Polyakov
@ 2008-12-08 21:58 ` Andrew Morton
2008-12-08 22:49 ` Evgeniy Polyakov
1 sibling, 1 reply; 9+ messages in thread
From: Andrew Morton @ 2008-12-08 21:58 UTC (permalink / raw)
To: Evgeniy Polyakov; +Cc: linux-kernel, frederik.deweerdt, randy.dunlap, zbr
On Fri, 5 Dec 2008 15:41:27 +0300
Evgeniy Polyakov <zbr@ioremap.net> wrote:
> + u64 *data = (void *)(cmd + 1) + cmd->len;
> +
> + *data = rn;
This code performs quite a lot of potentially unaligned acceses.
Is there anything which guarantees that all these accesses are
well-aligned?
If not, will there be issues with platforms which don't handle
unaligned accesses as well as x86?
Should this code be using the unaligned access interfaces
(get_unaligned, put_unaligned, etc. Might be wrong. Keeps changing.
Harvey Harrison is the guy to ask)?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [W1] List slaves commands.
2008-12-08 21:58 ` [W1] List slaves commands Andrew Morton
@ 2008-12-08 22:49 ` Evgeniy Polyakov
0 siblings, 0 replies; 9+ messages in thread
From: Evgeniy Polyakov @ 2008-12-08 22:49 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, frederik.deweerdt, randy.dunlap
On Mon, Dec 08, 2008 at 01:58:48PM -0800, Andrew Morton (akpm@linux-foundation.org) wrote:
> This code performs quite a lot of potentially unaligned acceses.
>
> Is there anything which guarantees that all these accesses are
> well-aligned?
>
> If not, will there be issues with platforms which don't handle
> unaligned accesses as well as x86?
>
> Should this code be using the unaligned access interfaces
> (get_unaligned, put_unaligned, etc. Might be wrong. Keeps changing.
> Harvey Harrison is the guy to ask)?
Every store should be at least 4-bytes aligned because of used headers.
Particular mentioned command is 8-bytes aligned (and all its writes)
as long as others in this patchset (pointer alignment + 40 or 32 bytes
of the headers).
--
Evgeniy Polyakov
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-12-08 22:50 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-05 12:41 [W1 take2]: extend userspace commands Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Added list masters w1 command Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Added touch block command Evgeniy Polyakov
2008-12-05 12:41 ` [W1] List slaves commands Evgeniy Polyakov
2008-12-05 12:41 ` [W1] Documentation update Evgeniy Polyakov
2008-12-08 21:58 ` [W1] List slaves commands Andrew Morton
2008-12-08 22:49 ` Evgeniy Polyakov
-- strict thread matches above, loose matches on Subject: below --
2008-12-04 14:50 [W1] extend userspace commands Evgeniy Polyakov
2008-12-04 14:50 ` Evgeniy Polyakov
2008-12-04 14:50 ` [W1] Added list masters w1 command Evgeniy Polyakov
2008-12-04 15:41 ` Frederik Deweerdt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox