Hi Cédric

> Subject: Re: [PATCH v1 06/22] hw/misc/aspeed_hace: Support accumulative
> mode for direct access mode
> 
> On 3/21/25 10:26, Jamin Lin wrote:
> > Enable accumulative mode for direct access mode operations. In direct
> > access mode, only a single source buffer is used, so the "iovec" count is 
> > set to
> 1.
> > If "acc_mode" is enabled:
> > 1. Accumulate "total_req_len" with the current request length ("plen").
> > 2. Check for padding and determine whether this is the final request.
> >
> > Signed-off-by: Jamin Lin <jamin_...@aspeedtech.com>
> > ---
> >   hw/misc/aspeed_hace.c | 15 ++++++++++++++-
> >   1 file changed, 14 insertions(+), 1 deletion(-)
> >
> > diff --git a/hw/misc/aspeed_hace.c b/hw/misc/aspeed_hace.c index
> > 8cf3f194a5..d06158dffd 100644
> > --- a/hw/misc/aspeed_hace.c
> > +++ b/hw/misc/aspeed_hace.c
> > @@ -223,8 +223,21 @@ static void do_hash_operation(AspeedHACEState *s,
> int algo, bool sg_mode,
> >               return;
> >           }
> >           iov[0].iov_base = haddr;
> > -        iov[0].iov_len = plen;
> >           i = 1;
> > +        if (acc_mode) {
> 
> hmm, more complexity is being added to do_hash_operation(). I would
> introduce a sub routine do_hash_operation_acc() to handle accumulative
> mode.
> 
Thanks for the review and suggestion.
I refactor "do_hash_operation" and changes looks like as following

New Helper functions:

hash_get_source_addr
hash_prepare_direct_iov
hash_prepare_sg_iov
hash_get_digest_addr
hash_write_digest_and_unmap_iov
hash_execute_non_acc_mode
hash_execute_acc_mode

```
static void do_hash_operation(AspeedHACEState *s, int algo, bool sg_mode,
                              bool acc_mode)
{
    struct iovec iov[ASPEED_HACE_MAX_SG];
    bool acc_final_request = false;
    int iov_idx = -1;

    /* Prepares the iov for hashing operations based on the selected mode */
    if (sg_mode) {
        iov_idx = hash_prepare_sg_iov(s, iov, acc_mode, &acc_final_request);
    } else {
        iov_idx = hash_prepare_direct_iov(s, iov);
    }

    if (iov_idx <= 0) {
        qemu_log_mask(LOG_GUEST_ERROR,
                      "%s: Failed to prepare iov\n", __func__);
         return;
    }

    /* Executes the hash operation */
    if (acc_mode) {
        hash_execute_acc_mode(s, algo, iov, iov_idx, acc_final_request);
    } else {
        hash_execute_non_acc_mode(s, algo, iov, iov_idx);
    }
}
```
Thanks-Jamin

> Thanks,
> 
> C.
> 
> 
> 
> > +            s->total_req_len += plen;
> > +
> > +            if (has_padding(s, &iov[0], plen, &total_msg_len,
> > +                            &pad_offset)) {
> > +                /* Padding being present indicates the final request */
> > +                sg_acc_mode_final_request = true;
> > +                iov[0].iov_len = pad_offset;
> > +            } else {
> > +                iov[0].iov_len = plen;
> > +            }
> > +        } else {
> > +            iov[0].iov_len = plen;
> > +        }
> >       }
> >
> >       if (acc_mode) {

Reply via email to