18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2003 Evgeniy Polyakov <zbr@ioremap.net>
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __W1_NETLINK_H
78c2ecf20Sopenharmony_ci#define __W1_NETLINK_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <asm/types.h>
108c2ecf20Sopenharmony_ci#include <linux/connector.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include "w1_internal.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/**
158c2ecf20Sopenharmony_ci * enum w1_cn_msg_flags - bitfield flags for struct cn_msg.flags
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * @W1_CN_BUNDLE: Request bundling replies into fewer messagse.  Be prepared
188c2ecf20Sopenharmony_ci * to handle multiple struct cn_msg, struct w1_netlink_msg, and
198c2ecf20Sopenharmony_ci * struct w1_netlink_cmd in one packet.
208c2ecf20Sopenharmony_ci */
218c2ecf20Sopenharmony_cienum w1_cn_msg_flags {
228c2ecf20Sopenharmony_ci	W1_CN_BUNDLE = 1,
238c2ecf20Sopenharmony_ci};
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci/**
268c2ecf20Sopenharmony_ci * enum w1_netlink_message_types - message type
278c2ecf20Sopenharmony_ci *
288c2ecf20Sopenharmony_ci * @W1_SLAVE_ADD: notification that a slave device was added
298c2ecf20Sopenharmony_ci * @W1_SLAVE_REMOVE: notification that a slave device was removed
308c2ecf20Sopenharmony_ci * @W1_MASTER_ADD: notification that a new bus master was added
318c2ecf20Sopenharmony_ci * @W1_MASTER_REMOVE: notification that a bus masterwas removed
328c2ecf20Sopenharmony_ci * @W1_MASTER_CMD: initiate operations on a specific master
338c2ecf20Sopenharmony_ci * @W1_SLAVE_CMD: sends reset, selects the slave, then does a read/write/touch
348c2ecf20Sopenharmony_ci * operation
358c2ecf20Sopenharmony_ci * @W1_LIST_MASTERS: used to determine the bus master identifiers
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_cienum w1_netlink_message_types {
388c2ecf20Sopenharmony_ci	W1_SLAVE_ADD = 0,
398c2ecf20Sopenharmony_ci	W1_SLAVE_REMOVE,
408c2ecf20Sopenharmony_ci	W1_MASTER_ADD,
418c2ecf20Sopenharmony_ci	W1_MASTER_REMOVE,
428c2ecf20Sopenharmony_ci	W1_MASTER_CMD,
438c2ecf20Sopenharmony_ci	W1_SLAVE_CMD,
448c2ecf20Sopenharmony_ci	W1_LIST_MASTERS,
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/**
488c2ecf20Sopenharmony_ci * struct w1_netlink_msg - holds w1 message type, id, and result
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * @type: one of enum w1_netlink_message_types
518c2ecf20Sopenharmony_ci * @status: kernel feedback for success 0 or errno failure value
528c2ecf20Sopenharmony_ci * @len: length of data following w1_netlink_msg
538c2ecf20Sopenharmony_ci * @id: union holding bus master id (msg.id) and slave device id (id[8]).
548c2ecf20Sopenharmony_ci * @id.id: Slave ID (8 bytes)
558c2ecf20Sopenharmony_ci * @id.mst: bus master identification
568c2ecf20Sopenharmony_ci * @id.mst.id: bus master ID
578c2ecf20Sopenharmony_ci * @id.mst.res: bus master reserved
588c2ecf20Sopenharmony_ci * @data: start address of any following data
598c2ecf20Sopenharmony_ci *
608c2ecf20Sopenharmony_ci * The base message structure for w1 messages over netlink.
618c2ecf20Sopenharmony_ci * The netlink connector data sequence is, struct nlmsghdr, struct cn_msg,
628c2ecf20Sopenharmony_ci * then one or more struct w1_netlink_msg (each with optional data).
638c2ecf20Sopenharmony_ci */
648c2ecf20Sopenharmony_cistruct w1_netlink_msg
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci	__u8				type;
678c2ecf20Sopenharmony_ci	__u8				status;
688c2ecf20Sopenharmony_ci	__u16				len;
698c2ecf20Sopenharmony_ci	union {
708c2ecf20Sopenharmony_ci		__u8			id[8];
718c2ecf20Sopenharmony_ci		struct w1_mst {
728c2ecf20Sopenharmony_ci			__u32		id;
738c2ecf20Sopenharmony_ci			__u32		res;
748c2ecf20Sopenharmony_ci		} mst;
758c2ecf20Sopenharmony_ci	} id;
768c2ecf20Sopenharmony_ci	__u8				data[];
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/**
808c2ecf20Sopenharmony_ci * enum w1_commands - commands available for master or slave operations
818c2ecf20Sopenharmony_ci *
828c2ecf20Sopenharmony_ci * @W1_CMD_READ: read len bytes
838c2ecf20Sopenharmony_ci * @W1_CMD_WRITE: write len bytes
848c2ecf20Sopenharmony_ci * @W1_CMD_SEARCH: initiate a standard search, returns only the slave
858c2ecf20Sopenharmony_ci * devices found during that search
868c2ecf20Sopenharmony_ci * @W1_CMD_ALARM_SEARCH: search for devices that are currently alarming
878c2ecf20Sopenharmony_ci * @W1_CMD_TOUCH: Touches a series of bytes.
888c2ecf20Sopenharmony_ci * @W1_CMD_RESET: sends a bus reset on the given master
898c2ecf20Sopenharmony_ci * @W1_CMD_SLAVE_ADD: adds a slave to the given master,
908c2ecf20Sopenharmony_ci * 8 byte slave id at data[0]
918c2ecf20Sopenharmony_ci * @W1_CMD_SLAVE_REMOVE: removes a slave to the given master,
928c2ecf20Sopenharmony_ci * 8 byte slave id at data[0]
938c2ecf20Sopenharmony_ci * @W1_CMD_LIST_SLAVES: list of slaves registered on this master
948c2ecf20Sopenharmony_ci * @W1_CMD_MAX: number of available commands
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_cienum w1_commands {
978c2ecf20Sopenharmony_ci	W1_CMD_READ = 0,
988c2ecf20Sopenharmony_ci	W1_CMD_WRITE,
998c2ecf20Sopenharmony_ci	W1_CMD_SEARCH,
1008c2ecf20Sopenharmony_ci	W1_CMD_ALARM_SEARCH,
1018c2ecf20Sopenharmony_ci	W1_CMD_TOUCH,
1028c2ecf20Sopenharmony_ci	W1_CMD_RESET,
1038c2ecf20Sopenharmony_ci	W1_CMD_SLAVE_ADD,
1048c2ecf20Sopenharmony_ci	W1_CMD_SLAVE_REMOVE,
1058c2ecf20Sopenharmony_ci	W1_CMD_LIST_SLAVES,
1068c2ecf20Sopenharmony_ci	W1_CMD_MAX
1078c2ecf20Sopenharmony_ci};
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/**
1108c2ecf20Sopenharmony_ci * struct w1_netlink_cmd - holds the command and data
1118c2ecf20Sopenharmony_ci *
1128c2ecf20Sopenharmony_ci * @cmd: one of enum w1_commands
1138c2ecf20Sopenharmony_ci * @res: reserved
1148c2ecf20Sopenharmony_ci * @len: length of data following w1_netlink_cmd
1158c2ecf20Sopenharmony_ci * @data: start address of any following data
1168c2ecf20Sopenharmony_ci *
1178c2ecf20Sopenharmony_ci * One or more struct w1_netlink_cmd is placed starting at w1_netlink_msg.data
1188c2ecf20Sopenharmony_ci * each with optional data.
1198c2ecf20Sopenharmony_ci */
1208c2ecf20Sopenharmony_cistruct w1_netlink_cmd
1218c2ecf20Sopenharmony_ci{
1228c2ecf20Sopenharmony_ci	__u8				cmd;
1238c2ecf20Sopenharmony_ci	__u8				res;
1248c2ecf20Sopenharmony_ci	__u16				len;
1258c2ecf20Sopenharmony_ci	__u8				data[];
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#ifdef __KERNEL__
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_civoid w1_netlink_send(struct w1_master *, struct w1_netlink_msg *);
1318c2ecf20Sopenharmony_ciint w1_init_netlink(void);
1328c2ecf20Sopenharmony_civoid w1_fini_netlink(void);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci#endif /* __KERNEL__ */
1358c2ecf20Sopenharmony_ci#endif /* __W1_NETLINK_H */
136