Commit a649dfcb authored by Ben Hutchings's avatar Ben Hutchings

sfc: Fill out the set of MCDI accessors

We need to access arrays of 16-bit words and 32-bit dwords in MCDI
buffers based on the MCDI protocol definitions.

We should also be able to read and write fields within structures,
without specifying an array index each time.  So add MCDI_FIELD()
and make MCDI_ARRAY_FIELD() use it.  Also add MCDI_SET_FIELD().

Split MCDI_ARRAY_PTR() into MCDI_ARRAY_STRUCT_PTR() and
_MCDI_ARRAY_PTR(), which are currently identical but will diverge in
later changes.
Signed-off-by: default avatarBen Hutchings <bhutchings@solarflare.com>
parent 30af6910
...@@ -87,8 +87,10 @@ extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); ...@@ -87,8 +87,10 @@ extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
#define MCDI_DECLARE_BUF(_name, _len) \ #define MCDI_DECLARE_BUF(_name, _len) \
u8 _name[ALIGN(_len, 4)] u8 _name[ALIGN(_len, 4)]
#define _MCDI_PTR(_buf, _offset) \
((u8 *)(_buf) + (_offset))
#define MCDI_PTR(_buf, _field) \ #define MCDI_PTR(_buf, _field) \
((u8 *)(_buf) + MC_CMD_ ## _field ## _OFST) _MCDI_PTR(_buf, MC_CMD_ ## _field ## _OFST)
#define _MCDI_DWORD(_buf, _field) \ #define _MCDI_DWORD(_buf, _field) \
((efx_dword_t *)MCDI_PTR(_buf, _field)) ((efx_dword_t *)MCDI_PTR(_buf, _field))
...@@ -102,18 +104,38 @@ extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev); ...@@ -102,18 +104,38 @@ extern void efx_mcdi_sensor_event(struct efx_nic *efx, efx_qword_t *ev);
#define MCDI_QWORD(_buf, _field) \ #define MCDI_QWORD(_buf, _field) \
(EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \ (EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[0], EFX_DWORD_0) | \
(u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32) (u64)EFX_DWORD_FIELD(_MCDI_DWORD(_buf, _field)[1], EFX_DWORD_0) << 32)
#define MCDI_FIELD(_ptr, _type, _field) \
EFX_EXTRACT_DWORD( \
*(efx_dword_t *) \
_MCDI_PTR(_ptr, MC_CMD_ ## _type ## _ ## _field ## _OFST & ~3),\
MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f, \
(MC_CMD_ ## _type ## _ ## _field ## _LBN & 0x1f) + \
MC_CMD_ ## _type ## _ ## _field ## _WIDTH - 1)
#define MCDI_ARRAY_PTR(_buf, _field, _type, _index) \ #define _MCDI_ARRAY_PTR(_buf, _field, _index) \
(MCDI_PTR(_buf, _field) + \ (MCDI_PTR(_buf, _field) + \
(_index) * MC_CMD_ ## _type ## _TYPEDEF_LEN) (_index) * MC_CMD_ ## _field ## _LEN)
#define MCDI_DECLARE_STRUCT_PTR(_name) \
u8 *_name
#define MCDI_ARRAY_STRUCT_PTR _MCDI_ARRAY_PTR
#define MCDI_VAR_ARRAY_LEN(_len, _field) \
min_t(size_t, MC_CMD_ ## _field ## _MAXNUM, \
((_len) - MC_CMD_ ## _field ## _OFST) / MC_CMD_ ## _field ## _LEN)
#define MCDI_ARRAY_WORD(_buf, _field, _index) \
(BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 2) + \
le16_to_cpu(*(__force const __le16 *) \
_MCDI_ARRAY_PTR(_buf, _field, _index)))
#define _MCDI_ARRAY_DWORD(_buf, _field, _index) \
(BUILD_BUG_ON_ZERO(MC_CMD_ ## _field ## _LEN != 4) + \
(efx_dword_t *)_MCDI_ARRAY_PTR(_buf, _field, _index))
#define MCDI_SET_ARRAY_DWORD(_buf, _field, _index, _value) \
EFX_SET_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), \
EFX_DWORD_0, _value)
#define MCDI_ARRAY_DWORD(_buf, _field, _index) \
EFX_DWORD_FIELD(*_MCDI_ARRAY_DWORD(_buf, _field, _index), EFX_DWORD_0)
#define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \ #define MCDI_ARRAY_FIELD(_buf, _field1, _type, _index, _field2) \
EFX_EXTRACT_DWORD( \ MCDI_FIELD(MCDI_ARRAY_STRUCT_PTR(_buf, _field1, _index), \
*((efx_dword_t *) \ _type ## _TYPEDEF, _field2)
(MCDI_ARRAY_PTR(_buf, _field1, _type, _index) + \
(MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _OFST & ~3))), \
MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _LBN & 0x1f, \
(MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _LBN & 0x1f) + \
MC_CMD_ ## _type ## _TYPEDEF_ ## _field2 ## _WIDTH - 1)
#define MCDI_EVENT_FIELD(_ev, _field) \ #define MCDI_EVENT_FIELD(_ev, _field) \
EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field) EFX_QWORD_FIELD(_ev, MCDI_EVENT_ ## _field)
......
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