diff mbox series

[v5,1/2] cros_ec_proto: Consolidate ec_response_get_next_event

Message ID fc251d6935c1cfc39d7a31d3cfe735d31a0371d1.1719531519.git.dnojiri@chromium.org (mailing list archive)
State Superseded
Headers show
Series Consolidate ec_response_get_next_event | expand

Commit Message

Daisuke Nojiri June 27, 2024, 11:53 p.m. UTC
Consolidate struct ec_response_get_next_event_v*.

Let X->Y indicate kernel X sending EC_CMD_GET_NEXT_EVENT to FW Y.

Old->New:
   Existing kernels send a smaller container (e.g.
   ec_response_get_next_data) which may or may not fit the last few
   bytes. The FW copies as many bytes as possible to the container. The
   kernel processes as many leading bytes as it can understand.

New->Old:
   New kernels send a bigger container. Existing FW copies as many bytes
   as it wants, leaving the last few bytes empty. The kernel knows it
   didn't receive full size data from the returned data length.

Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
---
 drivers/platform/chrome/cros_ec_proto.c       | 16 ++++-----
 .../linux/platform_data/cros_ec_commands.h    | 34 +------------------
 include/linux/platform_data/cros_ec_proto.h   |  2 +-
 3 files changed, 10 insertions(+), 42 deletions(-)

Comments

Dmitry Torokhov June 27, 2024, 11:58 p.m. UTC | #1
On Thu, Jun 27, 2024 at 04:53:07PM -0700, Daisuke Nojiri wrote:
> Consolidate struct ec_response_get_next_event_v*.
> 
> Let X->Y indicate kernel X sending EC_CMD_GET_NEXT_EVENT to FW Y.
> 
> Old->New:
>    Existing kernels send a smaller container (e.g.
>    ec_response_get_next_data) which may or may not fit the last few
>    bytes. The FW copies as many bytes as possible to the container. The
>    kernel processes as many leading bytes as it can understand.
> 
> New->Old:
>    New kernels send a bigger container. Existing FW copies as many bytes
>    as it wants, leaving the last few bytes empty. The kernel knows it
>    didn't receive full size data from the returned data length.
> 
> Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

Thanks.
Tzung-Bi Shih June 28, 2024, 3 a.m. UTC | #2
On Thu, Jun 27, 2024 at 04:53:07PM -0700, Daisuke Nojiri wrote:

Your previous patches have been applied to for-next branch:
ba098ed9829c ("platform/chrome: Add struct ec_response_get_next_event_v3")
106d67398233 ("platform/chrome: cros_ec_proto: Upgrade get_next_event to v3")

Please send incremental patches based on for-next.

> Consolidate struct ec_response_get_next_event_v*.
> 
> Let X->Y indicate kernel X sending EC_CMD_GET_NEXT_EVENT to FW Y.
> 
> Old->New:
>    Existing kernels send a smaller container (e.g.
>    ec_response_get_next_data) which may or may not fit the last few
>    bytes. The FW copies as many bytes as possible to the container. The
>    kernel processes as many leading bytes as it can understand.
> 
> New->Old:
>    New kernels send a bigger container. Existing FW copies as many bytes
>    as it wants, leaving the last few bytes empty. The kernel knows it
>    didn't receive full size data from the returned data length.
> 
> Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
> ---
>  drivers/platform/chrome/cros_ec_proto.c       | 16 ++++-----
>  .../linux/platform_data/cros_ec_commands.h    | 34 +------------------

NACK, we don't do it: diverging cros_ec_commands.h and EC's ec_commands.h.
kernel test robot June 29, 2024, 1:41 p.m. UTC | #3
Hi Daisuke,

kernel test robot noticed the following build errors:

[auto build test ERROR on chrome-platform/for-firmware-next]
[also build test ERROR on dtor-input/next dtor-input/for-linus robh/for-next linus/master v6.10-rc5]
[cannot apply to chrome-platform/for-next next-20240628]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Daisuke-Nojiri/cros_ec_proto-Consolidate-ec_response_get_next_event/20240629-053834
base:   https://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux.git for-firmware-next
patch link:    https://lore.kernel.org/r/fc251d6935c1cfc39d7a31d3cfe735d31a0371d1.1719531519.git.dnojiri%40chromium.org
patch subject: [PATCH v5 1/2] cros_ec_proto: Consolidate ec_response_get_next_event
config: i386-randconfig-141-20240629
compiler: gcc-13 (Ubuntu 13.2.0-4ubuntu3) 13.2.0
reproduce (this is a W=1 build):

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202406292107.TQKTW6ey-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/platform/chrome/cros_ec_proto_test.c: In function 'cros_ec_proto_test_get_next_event_no_mkbp_event':
>> drivers/platform/chrome/cros_ec_proto_test.c:2065:64: error: invalid application of 'sizeof' to incomplete type 'union ec_response_get_next_data_v1'
    2065 |                 mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
         |                                                                ^
>> drivers/platform/chrome/cros_ec_proto_test.c:2069:21: error: invalid use of undefined type 'union ec_response_get_next_data_v1'
    2069 |                 data->host_event = 0xbeef;
         |                     ^~
   In file included from drivers/platform/chrome/cros_ec_proto_test.c:6:
   drivers/platform/chrome/cros_ec_proto_test.c:2073:43: error: invalid application of 'sizeof' to incomplete type 'union ec_response_get_next_data_v1'
    2073 |         KUNIT_EXPECT_EQ(test, ret, sizeof(union ec_response_get_next_data_v1));
         |                                           ^~~~~
   include/kunit/test.h:708:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                      ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2073:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2073 |         KUNIT_EXPECT_EQ(test, ret, sizeof(union ec_response_get_next_data_v1));
         |         ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2073:43: error: invalid application of 'sizeof' to incomplete type 'union ec_response_get_next_data_v1'
    2073 |         KUNIT_EXPECT_EQ(test, ret, sizeof(union ec_response_get_next_data_v1));
         |                                           ^~~~~
   include/kunit/test.h:708:40: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                                        ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2073:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2073 |         KUNIT_EXPECT_EQ(test, ret, sizeof(union ec_response_get_next_data_v1));
         |         ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2088:64: error: invalid application of 'sizeof' to incomplete type 'union ec_response_get_next_data_v1'
    2088 |                 KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(union ec_response_get_next_data_v1));
         |                                                                ^~~~~
   include/kunit/test.h:708:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                      ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2088:17: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2088 |                 KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(union ec_response_get_next_data_v1));
         |                 ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2088:64: error: invalid application of 'sizeof' to incomplete type 'union ec_response_get_next_data_v1'
    2088 |                 KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(union ec_response_get_next_data_v1));
         |                                                                ^~~~~
   include/kunit/test.h:708:40: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                                        ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2088:17: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2088 |                 KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(union ec_response_get_next_data_v1));
         |                 ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c: In function 'cros_ec_proto_test_get_next_event_mkbp_event_version2':
>> drivers/platform/chrome/cros_ec_proto_test.c:2175:64: error: invalid application of 'sizeof' to incomplete type 'struct ec_response_get_next_event_v1'
    2175 |                 mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
         |                                                                ^
>> drivers/platform/chrome/cros_ec_proto_test.c:2179:21: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2179 |                 data->event_type = EC_MKBP_EVENT_FINGERPRINT;
         |                     ^~
   drivers/platform/chrome/cros_ec_proto_test.c:2180:21: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2180 |                 data->data.sysrq = 0xbeef;
         |                     ^~
   drivers/platform/chrome/cros_ec_proto_test.c:2184:43: error: invalid application of 'sizeof' to incomplete type 'struct ec_response_get_next_event_v1'
    2184 |         KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event_v1));
         |                                           ^~~~~~
   include/kunit/test.h:708:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                      ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2184:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2184 |         KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event_v1));
         |         ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2184:43: error: invalid application of 'sizeof' to incomplete type 'struct ec_response_get_next_event_v1'
    2184 |         KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event_v1));
         |                                           ^~~~~~
   include/kunit/test.h:708:40: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                                        ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2184:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2184 |         KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event_v1));
         |         ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2200:40: error: invalid application of 'sizeof' to incomplete type 'struct ec_response_get_next_event_v1'
    2200 |                                 sizeof(struct ec_response_get_next_event_v1));
         |                                        ^~~~~~
   include/kunit/test.h:708:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                      ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2199:17: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2199 |                 KUNIT_EXPECT_EQ(test, mock->msg.insize,
         |                 ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2200:40: error: invalid application of 'sizeof' to incomplete type 'struct ec_response_get_next_event_v1'
    2200 |                                 sizeof(struct ec_response_get_next_event_v1));
         |                                        ^~~~~~
   include/kunit/test.h:708:40: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                                        ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2199:17: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2199 |                 KUNIT_EXPECT_EQ(test, mock->msg.insize,
         |                 ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c: In function 'cros_ec_proto_test_get_next_event_mkbp_event_host_event_rtc':
   drivers/platform/chrome/cros_ec_proto_test.c:2225:63: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2225 |                                                    sizeof(data->event_type) +
         |                                                               ^~
   drivers/platform/chrome/cros_ec_proto_test.c:2226:63: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2226 |                                                    sizeof(data->data.host_event));
         |                                                               ^~
   drivers/platform/chrome/cros_ec_proto_test.c:2230:21: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2230 |                 data->event_type = EC_MKBP_EVENT_HOST_EVENT;
         |                     ^~
   drivers/platform/chrome/cros_ec_proto_test.c:2231:80: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2231 |                 put_unaligned_le32(EC_HOST_EVENT_MASK(EC_HOST_EVENT_RTC), &data->data.host_event);
         |                                                                                ^~
   drivers/platform/chrome/cros_ec_proto_test.c:2235:47: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2235 |         KUNIT_EXPECT_EQ(test, ret, sizeof(data->event_type) + sizeof(data->data.host_event));
         |                                               ^~
   include/kunit/test.h:708:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                      ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'
     903 |         KUNIT_BINARY_INT_ASSERTION(test,                                       \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~
   include/kunit/test.h:900:9: note: in expansion of macro 'KUNIT_EXPECT_EQ_MSG'
     900 |         KUNIT_EXPECT_EQ_MSG(test, left, right, NULL)
         |         ^~~~~~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2235:9: note: in expansion of macro 'KUNIT_EXPECT_EQ'
    2235 |         KUNIT_EXPECT_EQ(test, ret, sizeof(data->event_type) + sizeof(data->data.host_event));
         |         ^~~~~~~~~~~~~~~
   drivers/platform/chrome/cros_ec_proto_test.c:2235:74: error: invalid use of undefined type 'struct ec_response_get_next_event_v1'
    2235 |         KUNIT_EXPECT_EQ(test, ret, sizeof(data->event_type) + sizeof(data->data.host_event));
         |                                                                          ^~
   include/kunit/test.h:708:22: note: in definition of macro 'KUNIT_BASE_BINARY_ASSERTION'
     708 |         const typeof(right) __right = (right);                                 \
         |                      ^~~~~
   include/kunit/test.h:903:9: note: in expansion of macro 'KUNIT_BINARY_INT_ASSERTION'


vim +2065 drivers/platform/chrome/cros_ec_proto_test.c

1242688fc2f0805 Tzung-Bi Shih 2022-06-22  2044  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2045  static void cros_ec_proto_test_get_next_event_no_mkbp_event(struct kunit *test)
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2046  {
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2047  	struct cros_ec_proto_test_priv *priv = test->priv;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2048  	struct cros_ec_device *ec_dev = &priv->ec_dev;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2049  	struct ec_xfer_mock *mock;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2050  	int ret;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2051  	bool wake_event, more_events;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2052  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2053  	ec_dev->max_request = 0xff;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2054  	ec_dev->max_response = 0xee;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2055  	ec_dev->mkbp_event_supported = 0;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2056  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2057  	/* Set some garbage bytes. */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2058  	wake_event = false;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2059  	more_events = true;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2060  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2061  	/* For get_keyboard_state_event(). */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2062  	{
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2063  		union ec_response_get_next_data_v1 *data;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2064  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22 @2065  		mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2066  		KUNIT_ASSERT_PTR_NE(test, mock, NULL);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2067  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2068  		data = (union ec_response_get_next_data_v1 *)mock->o_data;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22 @2069  		data->host_event = 0xbeef;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2070  	}
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2071  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2072  	ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2073  	KUNIT_EXPECT_EQ(test, ret, sizeof(union ec_response_get_next_data_v1));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2074  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2075  	KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_KEY_MATRIX);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2076  	KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.host_event, 0xbeef);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2077  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2078  	KUNIT_EXPECT_TRUE(test, wake_event);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2079  	KUNIT_EXPECT_FALSE(test, more_events);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2080  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2081  	/* For get_keyboard_state_event(). */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2082  	{
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2083  		mock = cros_kunit_ec_xfer_mock_next();
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2084  		KUNIT_EXPECT_PTR_NE(test, mock, NULL);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2085  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2086  		KUNIT_EXPECT_EQ(test, mock->msg.version, 0);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2087  		KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_MKBP_STATE);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22 @2088  		KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(union ec_response_get_next_data_v1));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2089  		KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2090  	}
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2091  }
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2092  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2093  static void cros_ec_proto_test_get_next_event_mkbp_event_ec_suspended(struct kunit *test)
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2094  {
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2095  	struct cros_ec_proto_test_priv *priv = test->priv;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2096  	struct cros_ec_device *ec_dev = &priv->ec_dev;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2097  	int ret;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2098  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2099  	ec_dev->mkbp_event_supported = 1;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2100  	ec_dev->suspended = true;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2101  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2102  	ret = cros_ec_get_next_event(ec_dev, NULL, NULL);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2103  	KUNIT_EXPECT_EQ(test, ret, -EHOSTDOWN);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2104  }
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2105  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2106  static void cros_ec_proto_test_get_next_event_mkbp_event_version0(struct kunit *test)
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2107  {
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2108  	struct cros_ec_proto_test_priv *priv = test->priv;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2109  	struct cros_ec_device *ec_dev = &priv->ec_dev;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2110  	struct ec_xfer_mock *mock;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2111  	int ret;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2112  	bool wake_event, more_events;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2113  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2114  	ec_dev->max_request = 0xff;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2115  	ec_dev->max_response = 0xee;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2116  	ec_dev->mkbp_event_supported = 1;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2117  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2118  	/* Set some garbage bytes. */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2119  	wake_event = true;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2120  	more_events = false;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2121  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2122  	/* For get_next_event_xfer(). */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2123  	{
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2124  		struct ec_response_get_next_event *data;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2125  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2126  		mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2127  		KUNIT_ASSERT_PTR_NE(test, mock, NULL);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2128  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2129  		data = (struct ec_response_get_next_event *)mock->o_data;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2130  		data->event_type = EC_MKBP_EVENT_SENSOR_FIFO | EC_MKBP_HAS_MORE_EVENTS;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2131  		data->data.sysrq = 0xbeef;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2132  	}
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2133  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2134  	ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2135  	KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2136  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2137  	KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_SENSOR_FIFO);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2138  	KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.sysrq, 0xbeef);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2139  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2140  	KUNIT_EXPECT_FALSE(test, wake_event);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2141  	KUNIT_EXPECT_TRUE(test, more_events);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2142  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2143  	/* For get_next_event_xfer(). */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2144  	{
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2145  		mock = cros_kunit_ec_xfer_mock_next();
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2146  		KUNIT_EXPECT_PTR_NE(test, mock, NULL);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2147  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2148  		KUNIT_EXPECT_EQ(test, mock->msg.version, 0);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2149  		KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2150  		KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_get_next_event));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2151  		KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2152  	}
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2153  }
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2154  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2155  static void cros_ec_proto_test_get_next_event_mkbp_event_version2(struct kunit *test)
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2156  {
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2157  	struct cros_ec_proto_test_priv *priv = test->priv;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2158  	struct cros_ec_device *ec_dev = &priv->ec_dev;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2159  	struct ec_xfer_mock *mock;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2160  	int ret;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2161  	bool wake_event, more_events;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2162  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2163  	ec_dev->max_request = 0xff;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2164  	ec_dev->max_response = 0xee;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2165  	ec_dev->mkbp_event_supported = 3;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2166  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2167  	/* Set some garbage bytes. */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2168  	wake_event = false;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2169  	more_events = true;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2170  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2171  	/* For get_next_event_xfer(). */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2172  	{
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2173  		struct ec_response_get_next_event_v1 *data;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2174  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22 @2175  		mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2176  		KUNIT_ASSERT_PTR_NE(test, mock, NULL);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2177  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2178  		data = (struct ec_response_get_next_event_v1 *)mock->o_data;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22 @2179  		data->event_type = EC_MKBP_EVENT_FINGERPRINT;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2180  		data->data.sysrq = 0xbeef;
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2181  	}
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2182  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2183  	ret = cros_ec_get_next_event(ec_dev, &wake_event, &more_events);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2184  	KUNIT_EXPECT_EQ(test, ret, sizeof(struct ec_response_get_next_event_v1));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2185  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2186  	KUNIT_EXPECT_EQ(test, ec_dev->event_data.event_type, EC_MKBP_EVENT_FINGERPRINT);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2187  	KUNIT_EXPECT_EQ(test, ec_dev->event_data.data.sysrq, 0xbeef);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2188  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2189  	KUNIT_EXPECT_TRUE(test, wake_event);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2190  	KUNIT_EXPECT_FALSE(test, more_events);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2191  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2192  	/* For get_next_event_xfer(). */
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2193  	{
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2194  		mock = cros_kunit_ec_xfer_mock_next();
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2195  		KUNIT_EXPECT_PTR_NE(test, mock, NULL);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2196  
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2197  		KUNIT_EXPECT_EQ(test, mock->msg.version, 2);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2198  		KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_NEXT_EVENT);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2199  		KUNIT_EXPECT_EQ(test, mock->msg.insize,
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2200  				sizeof(struct ec_response_get_next_event_v1));
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2201  		KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0);
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2202  	}
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2203  }
2b7ed927953f30e Tzung-Bi Shih 2022-06-22  2204
diff mbox series

Patch

diff --git a/drivers/platform/chrome/cros_ec_proto.c b/drivers/platform/chrome/cros_ec_proto.c
index 945b1b15a04c..a849c29f125b 100644
--- a/drivers/platform/chrome/cros_ec_proto.c
+++ b/drivers/platform/chrome/cros_ec_proto.c
@@ -686,7 +686,7 @@  EXPORT_SYMBOL(cros_ec_cmd_xfer_status);
 
 static int get_next_event_xfer(struct cros_ec_device *ec_dev,
 			       struct cros_ec_command *msg,
-			       struct ec_response_get_next_event_v1 *event,
+			       struct ec_response_get_next_event *event,
 			       int version, uint32_t size)
 {
 	int ret;
@@ -709,11 +709,11 @@  static int get_next_event(struct cros_ec_device *ec_dev)
 {
 	struct {
 		struct cros_ec_command msg;
-		struct ec_response_get_next_event_v1 event;
+		struct ec_response_get_next_event event;
 	} __packed buf;
 	struct cros_ec_command *msg = &buf.msg;
-	struct ec_response_get_next_event_v1 *event = &buf.event;
-	const int cmd_version = ec_dev->mkbp_event_supported - 1;
+	struct ec_response_get_next_event *event = &buf.event;
+	int cmd_version = ec_dev->mkbp_event_supported - 1;
 
 	memset(msg, 0, sizeof(*msg));
 	if (ec_dev->suspended) {
@@ -721,12 +721,12 @@  static int get_next_event(struct cros_ec_device *ec_dev)
 		return -EHOSTDOWN;
 	}
 
-	if (cmd_version == 0)
-		return get_next_event_xfer(ec_dev, msg, event, 0,
-				  sizeof(struct ec_response_get_next_event));
+	/* The max version we support is v3 */
+	if (cmd_version > 3)
+		cmd_version = 3;
 
 	return get_next_event_xfer(ec_dev, msg, event, cmd_version,
-				sizeof(struct ec_response_get_next_event_v1));
+				   sizeof(*event));
 }
 
 static int get_keyboard_state_event(struct cros_ec_device *ec_dev)
diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h
index 070e49c5381e..00c06c130dd5 100644
--- a/include/linux/platform_data/cros_ec_commands.h
+++ b/include/linux/platform_data/cros_ec_commands.h
@@ -3475,32 +3475,7 @@  enum ec_mkbp_event {
 BUILD_ASSERT(EC_MKBP_EVENT_COUNT <= EC_MKBP_EVENT_TYPE_MASK);
 
 union __ec_align_offset1 ec_response_get_next_data {
-	uint8_t key_matrix[13];
-
-	/* Unaligned */
-	uint32_t host_event;
-	uint64_t host_event64;
-
-	struct __ec_todo_unpacked {
-		/* For aligning the fifo_info */
-		uint8_t reserved[3];
-		struct ec_response_motion_sense_fifo_info info;
-	} sensor_fifo;
-
-	uint32_t buttons;
-
-	uint32_t switches;
-
-	uint32_t fp_events;
-
-	uint32_t sysrq;
-
-	/* CEC events from enum mkbp_cec_event */
-	uint32_t cec_events;
-};
-
-union __ec_align_offset1 ec_response_get_next_data_v1 {
-	uint8_t key_matrix[16];
+	uint8_t key_matrix[18];
 
 	/* Unaligned */
 	uint32_t host_event;
@@ -3525,7 +3500,6 @@  union __ec_align_offset1 ec_response_get_next_data_v1 {
 
 	uint8_t cec_message[16];
 };
-BUILD_ASSERT(sizeof(union ec_response_get_next_data_v1) == 16);
 
 struct ec_response_get_next_event {
 	uint8_t event_type;
@@ -3533,12 +3507,6 @@  struct ec_response_get_next_event {
 	union ec_response_get_next_data data;
 } __ec_align1;
 
-struct ec_response_get_next_event_v1 {
-	uint8_t event_type;
-	/* Followed by event data if any */
-	union ec_response_get_next_data_v1 data;
-} __ec_align1;
-
 /* Bit indices for buttons and switches.*/
 /* Buttons */
 #define EC_MKBP_POWER_BUTTON	0
diff --git a/include/linux/platform_data/cros_ec_proto.h b/include/linux/platform_data/cros_ec_proto.h
index 8865e350c12a..a795fe260a38 100644
--- a/include/linux/platform_data/cros_ec_proto.h
+++ b/include/linux/platform_data/cros_ec_proto.h
@@ -185,7 +185,7 @@  struct cros_ec_device {
 	bool host_sleep_v1;
 	struct blocking_notifier_head event_notifier;
 
-	struct ec_response_get_next_event_v1 event_data;
+	struct ec_response_get_next_event event_data;
 	int event_size;
 	u32 host_event_wake_mask;
 	u32 last_resume_result;