Re: [PATCH net-next v09 1/8] hinic3: Async Event Queue interfaces

From: Jakub Kicinski
Date: Wed Jul 16 2025 - 21:33:52 EST


On Tue, 15 Jul 2025 08:28:36 +0800 Fan Gong wrote:
> +/* Data provided to/by cmdq is arranged in structs with little endian fields but
> + * every dword (32bits) should be swapped since HW swaps it again when it
> + * copies it from/to host memory. This is a mandatory swap regardless of the
> + * CPU endianness.

This comment makes no sense, FWIW. The device writes a byte steam
to host memory. For what you're saying to make sense the device would
have to intentionally switch the endian based on the host CPU.
And if it could do that why wouldn't it do it in the opposite
direction, avoiding the swap ? :/

I suppose the device is always writing in be32 words, and you should
be converting from be32.

> + /* Ensure handler can observe our intent to unregister. */
> + mb();

What is "our intent"? I suppose you mean the change to the cb_state
bitfield? Please document the barriers explaining what two (or more)
memory accesses are separated. Not what they are achieving at the high
level.

> + clear_bit(HINIC3_AEQ_CB_REG, cb_state);
> + /* Ensure handler can observe our intent to unregister. */
> + mb();
> + while (test_bit(HINIC3_AEQ_CB_RUNNING, cb_state))
> + usleep_range(HINIC3_EQ_USLEEP_LOW_BOUND,
> + HINIC3_EQ_USLEEP_HIGH_BOUND);

Please do not try to implement locks manually using bits ops.
Use standard synchronization primitives like wait queues or normal
locks, so that lockdep can help you validate your code is correct.

> + val = EQ_CI_SIMPLE_INDIR_SET(arm_state, ARMED);
> + val = val |
> + EQ_CI_SIMPLE_INDIR_SET(eq_wrap_ci, CI) |
> + EQ_CI_SIMPLE_INDIR_SET(eq->q_id, AEQ_IDX);

Why not:

val = EQ_CI_SIMPLE_INDIR_SET(arm_state, ARMED) |
EQ_CI_SIMPLE_INDIR_SET(eq_wrap_ci, CI) |
EQ_CI_SIMPLE_INDIR_SET(eq->q_id, AEQ_IDX);
--
pw-bot: cr