Re: [PATCH v4] i2c: virtio: add a virtio i2c frontend driver

From: Viresh Kumar
Date: Thu Feb 25 2021 - 02:22:24 EST


On 12-10-20, 09:55, Jie Deng wrote:
> Add an I2C bus driver for virtio para-virtualization.
>
> The controller can be emulated by the backend driver in
> any device model software by following the virtio protocol.
>
> This driver communicates with the backend driver through a
> virtio I2C message structure which includes following parts:
>
> - Header: i2c_msg addr, flags, len.
> - Data buffer: the pointer to the I2C msg data.
> - Status: the processing result from the backend.
>
> People may implement different backend drivers to emulate
> different controllers according to their needs. A backend
> example can be found in the device model of the open source
> project ACRN. For more information, please refer to
> https://projectacrn.org.

> diff --git a/include/uapi/linux/virtio_i2c.h b/include/uapi/linux/virtio_i2c.h
> new file mode 100644
> index 0000000..7413e45
> --- /dev/null
> +++ b/include/uapi/linux/virtio_i2c.h
> @@ -0,0 +1,31 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause */
> +/*
> + * Definitions for virtio I2C Adpter
> + *
> + * Copyright (c) 2020 Intel Corporation. All rights reserved.
> + */
> +
> +#ifndef _UAPI_LINUX_VIRTIO_I2C_H
> +#define _UAPI_LINUX_VIRTIO_I2C_H
> +
> +#include <linux/types.h>
> +#include <linux/virtio_ids.h>
> +#include <linux/virtio_config.h>
> +
> +/**
> + * struct virtio_i2c_hdr - the virtio I2C message header structure
> + * @addr: i2c_msg addr, the slave address
> + * @flags: i2c_msg flags
> + * @len: i2c_msg len
> + */
> +struct virtio_i2c_hdr {
> + __le16 addr;
> + __le16 flags;
> + __le16 len;
> +};

Hi Jie,

I am a bit confused about the header and the format in which data is being
processed here. When I look at the specification present here:

https://lists.oasis-open.org/archives/virtio-comment/202009/msg00021.html

it talks about

struct virtio_i2c_out_hdr {
le16 addr;
le16 padding;
le32 flags;
};
struct virtio_i2c_in_hdr {
u8 status;
};

struct virtio_i2c_req {
struct virtio_i2c_out_hdr out_hdr;
u8 write_buf [];
u8 read_buf [];
struct virtio_i2c_in_hdr in_hdr;
};

while what we have above is completely different. What am I missing ?

--
viresh