diff mbox

[PATCHv2] linux-generic: crypto: eliminate buffer type hack for completions

Message ID 1433981534-31243-1-git-send-email-bill.fischofer@linaro.org
State Accepted
Commit 3d85d592b3dee612c9233f8dcb386d9d56c943bd
Headers show

Commit Message

Bill Fischofer June 11, 2015, 12:12 a.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 .../linux-generic/include/odp_buffer_inlines.h     |  9 ++++++
 .../linux-generic/include/odp_buffer_internal.h    |  1 +
 .../linux-generic/include/odp_packet_internal.h    |  4 +++
 platform/linux-generic/odp_crypto.c                | 32 ++++++----------------
 platform/linux-generic/odp_event.c                 |  7 ++---
 platform/linux-generic/odp_pool.c                  |  1 +
 6 files changed, 25 insertions(+), 29 deletions(-)

Comments

Mike Holmes June 12, 2015, 2:25 p.m. UTC | #1
On 10 June 2015 at 20:12, Bill Fischofer <bill.fischofer@linaro.org> wrote:

> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
>

I am guessing we should add
Reported-by: Christophe Milard <christophe.milard@linaro.org>


> ---
>  .../linux-generic/include/odp_buffer_inlines.h     |  9 ++++++
>  .../linux-generic/include/odp_buffer_internal.h    |  1 +
>  .../linux-generic/include/odp_packet_internal.h    |  4 +++
>  platform/linux-generic/odp_crypto.c                | 32
> ++++++----------------
>  platform/linux-generic/odp_event.c                 |  7 ++---
>  platform/linux-generic/odp_pool.c                  |  1 +
>  6 files changed, 25 insertions(+), 29 deletions(-)
>
> diff --git a/platform/linux-generic/include/odp_buffer_inlines.h
> b/platform/linux-generic/include/odp_buffer_inlines.h
> index 2c792e2..91e56bd 100644
> --- a/platform/linux-generic/include/odp_buffer_inlines.h
> +++ b/platform/linux-generic/include/odp_buffer_inlines.h
> @@ -188,6 +188,15 @@ static inline void *segment_map(odp_buffer_hdr_t *buf,
>         return (void *)seg_addr;
>  }
>
> +static inline int _odp_buffer_event_type(odp_buffer_t buf)
> +{
> +       return odp_buf_to_hdr(buf)->event_type;
> +}
> +
> +static inline void _odp_buffer_event_type_set(odp_buffer_t buf, int ev)
> +{
> +       odp_buf_to_hdr(buf)->event_type = ev;
> +}
>
>  #ifdef __cplusplus
>  }
> diff --git a/platform/linux-generic/include/odp_buffer_internal.h
> b/platform/linux-generic/include/odp_buffer_internal.h
> index e7b7568..a3632fe 100644
> --- a/platform/linux-generic/include/odp_buffer_internal.h
> +++ b/platform/linux-generic/include/odp_buffer_internal.h
> @@ -117,6 +117,7 @@ typedef struct odp_buffer_hdr_t {
>                 };
>         } flags;
>         int                      type;       /* buffer type */
> +       int                      event_type; /* for reuse as event */
>         uint32_t                 size;       /* max data size */
>         odp_atomic_u32_t         ref_count;  /* reference count */
>         odp_pool_t               pool_hdl;   /* buffer pool handle */
> diff --git a/platform/linux-generic/include/odp_packet_internal.h
> b/platform/linux-generic/include/odp_packet_internal.h
> index 9890dc8..8c41491 100644
> --- a/platform/linux-generic/include/odp_packet_internal.h
> +++ b/platform/linux-generic/include/odp_packet_internal.h
> @@ -25,6 +25,8 @@ extern "C" {
>  #include <odp_buffer_inlines.h>
>  #include <odp/packet.h>
>  #include <odp/packet_io.h>
> +#include <odp/crypto.h>
> +#include <odp_crypto_internal.h>
>
>  /**
>   * Packet input & protocol flags
> @@ -134,6 +136,8 @@ typedef struct {
>         uint32_t tailroom;
>
>         odp_pktio_t input;
> +
> +       odp_crypto_generic_op_result_t op_result;  /**< Result for crypto
> */
>  } odp_packet_hdr_t;
>
>  typedef struct odp_packet_hdr_stride {
> diff --git a/platform/linux-generic/odp_crypto.c
> b/platform/linux-generic/odp_crypto.c
> index b16316c..515f508 100644
> --- a/platform/linux-generic/odp_crypto.c
> +++ b/platform/linux-generic/odp_crypto.c
> @@ -37,28 +37,10 @@ struct odp_crypto_global_s {
>
>  static odp_crypto_global_t *global;
>
> -/*
> - * @todo This is a serious hack to allow us to use packet buffer to convey
> - *       crypto operation results by placing them at the very end of the
> - *       packet buffer.  The issue should be resolved shortly once the
> issue
> - *       of packets versus events on completion queues is closed.
> - */
>  static
>  odp_crypto_generic_op_result_t *get_op_result_from_event(odp_event_t ev)
>  {
> -       uint8_t   *temp;
> -       odp_crypto_generic_op_result_t *result;
> -       odp_buffer_t buf;
> -
> -       /* HACK: Buffer is not packet any more in the API.
> -        * Implementation still works that way. */
> -       buf = odp_buffer_from_event(ev);
> -
> -       temp  = odp_buffer_addr(buf);
> -       temp += odp_buffer_size(buf);
> -       temp -= sizeof(*result);
> -       result = (odp_crypto_generic_op_result_t *)(void *)temp;
> -       return result;
> +       return &(odp_packet_hdr(odp_packet_from_event(ev))->op_result);
>  }
>
>  static
> @@ -424,9 +406,9 @@ odp_crypto_operation(odp_crypto_op_params_t *params,
>
>                 /* Linux generic will always use packet for completion
> event */
>                 completion_event = odp_packet_to_event(params->out_pkt);
> -
>  _odp_buffer_type_set(odp_buffer_from_event(completion_event),
> -                                    ODP_EVENT_CRYPTO_COMPL);
> -
> +               _odp_buffer_event_type_set(
> +                       odp_buffer_from_event(completion_event),
> +                       ODP_EVENT_CRYPTO_COMPL);
>                 /* Asynchronous, build result (no HW so no errors) and
> send it*/
>                 op_result = get_op_result_from_event(completion_event);
>                 op_result->magic = OP_RESULT_MAGIC;
> @@ -537,7 +519,9 @@ odp_crypto_compl_result(odp_crypto_compl_t
> completion_event,
>  }
>
>  void
> -odp_crypto_compl_free(odp_crypto_compl_t completion_event ODP_UNUSED)
> +odp_crypto_compl_free(odp_crypto_compl_t completion_event)
>  {
> -       /* We use the packet as the completion event so nothing to do here
> */
> +       _odp_buffer_event_type_set(
> +               odp_buffer_from_event((odp_event_t)completion_event),
> +               ODP_EVENT_PACKET);
>  }
> diff --git a/platform/linux-generic/odp_event.c
> b/platform/linux-generic/odp_event.c
> index 17f4f43..d9e86a9 100644
> --- a/platform/linux-generic/odp_event.c
> +++ b/platform/linux-generic/odp_event.c
> @@ -8,12 +8,9 @@
>  #include <odp/buffer.h>
>  #include <odp/pool.h>
>  #include <odp_buffer_internal.h>
> +#include <odp_buffer_inlines.h>
>
>  int odp_event_type(odp_event_t event)
>  {
> -       odp_buffer_t buf;
> -
> -       buf = odp_buffer_from_event(event);
> -
> -       return _odp_buffer_type(buf);
> +       return _odp_buffer_event_type(odp_buffer_from_event(event));
>  }
> diff --git a/platform/linux-generic/odp_pool.c
> b/platform/linux-generic/odp_pool.c
> index 35e79a0..d92596e 100644
> --- a/platform/linux-generic/odp_pool.c
> +++ b/platform/linux-generic/odp_pool.c
> @@ -364,6 +364,7 @@ odp_pool_t odp_pool_create(const char *name,
>                         tmp->size = 0;
>                         odp_atomic_init_u32(&tmp->ref_count, 0);
>                         tmp->type = params->type;
> +                       tmp->event_type = params->type;
>                         tmp->pool_hdl = pool->s.pool_hdl;
>                         tmp->uarea_addr = (void *)udat;
>                         tmp->uarea_size = p_udata_size;
> --
> 2.1.0
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
Bill Fischofer June 12, 2015, 2:28 p.m. UTC | #2
Yes, of course.  Sorry about that.

On Fri, Jun 12, 2015 at 9:25 AM, Mike Holmes <mike.holmes@linaro.org> wrote:

>
>
> On 10 June 2015 at 20:12, Bill Fischofer <bill.fischofer@linaro.org>
> wrote:
>
>> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
>>
>
> I am guessing we should add
> Reported-by: Christophe Milard <christophe.milard@linaro.org>
>
>
>> ---
>>  .../linux-generic/include/odp_buffer_inlines.h     |  9 ++++++
>>  .../linux-generic/include/odp_buffer_internal.h    |  1 +
>>  .../linux-generic/include/odp_packet_internal.h    |  4 +++
>>  platform/linux-generic/odp_crypto.c                | 32
>> ++++++----------------
>>  platform/linux-generic/odp_event.c                 |  7 ++---
>>  platform/linux-generic/odp_pool.c                  |  1 +
>>  6 files changed, 25 insertions(+), 29 deletions(-)
>>
>> diff --git a/platform/linux-generic/include/odp_buffer_inlines.h
>> b/platform/linux-generic/include/odp_buffer_inlines.h
>> index 2c792e2..91e56bd 100644
>> --- a/platform/linux-generic/include/odp_buffer_inlines.h
>> +++ b/platform/linux-generic/include/odp_buffer_inlines.h
>> @@ -188,6 +188,15 @@ static inline void *segment_map(odp_buffer_hdr_t
>> *buf,
>>         return (void *)seg_addr;
>>  }
>>
>> +static inline int _odp_buffer_event_type(odp_buffer_t buf)
>> +{
>> +       return odp_buf_to_hdr(buf)->event_type;
>> +}
>> +
>> +static inline void _odp_buffer_event_type_set(odp_buffer_t buf, int ev)
>> +{
>> +       odp_buf_to_hdr(buf)->event_type = ev;
>> +}
>>
>>  #ifdef __cplusplus
>>  }
>> diff --git a/platform/linux-generic/include/odp_buffer_internal.h
>> b/platform/linux-generic/include/odp_buffer_internal.h
>> index e7b7568..a3632fe 100644
>> --- a/platform/linux-generic/include/odp_buffer_internal.h
>> +++ b/platform/linux-generic/include/odp_buffer_internal.h
>> @@ -117,6 +117,7 @@ typedef struct odp_buffer_hdr_t {
>>                 };
>>         } flags;
>>         int                      type;       /* buffer type */
>> +       int                      event_type; /* for reuse as event */
>>         uint32_t                 size;       /* max data size */
>>         odp_atomic_u32_t         ref_count;  /* reference count */
>>         odp_pool_t               pool_hdl;   /* buffer pool handle */
>> diff --git a/platform/linux-generic/include/odp_packet_internal.h
>> b/platform/linux-generic/include/odp_packet_internal.h
>> index 9890dc8..8c41491 100644
>> --- a/platform/linux-generic/include/odp_packet_internal.h
>> +++ b/platform/linux-generic/include/odp_packet_internal.h
>> @@ -25,6 +25,8 @@ extern "C" {
>>  #include <odp_buffer_inlines.h>
>>  #include <odp/packet.h>
>>  #include <odp/packet_io.h>
>> +#include <odp/crypto.h>
>> +#include <odp_crypto_internal.h>
>>
>>  /**
>>   * Packet input & protocol flags
>> @@ -134,6 +136,8 @@ typedef struct {
>>         uint32_t tailroom;
>>
>>         odp_pktio_t input;
>> +
>> +       odp_crypto_generic_op_result_t op_result;  /**< Result for crypto
>> */
>>  } odp_packet_hdr_t;
>>
>>  typedef struct odp_packet_hdr_stride {
>> diff --git a/platform/linux-generic/odp_crypto.c
>> b/platform/linux-generic/odp_crypto.c
>> index b16316c..515f508 100644
>> --- a/platform/linux-generic/odp_crypto.c
>> +++ b/platform/linux-generic/odp_crypto.c
>> @@ -37,28 +37,10 @@ struct odp_crypto_global_s {
>>
>>  static odp_crypto_global_t *global;
>>
>> -/*
>> - * @todo This is a serious hack to allow us to use packet buffer to
>> convey
>> - *       crypto operation results by placing them at the very end of the
>> - *       packet buffer.  The issue should be resolved shortly once the
>> issue
>> - *       of packets versus events on completion queues is closed.
>> - */
>>  static
>>  odp_crypto_generic_op_result_t *get_op_result_from_event(odp_event_t ev)
>>  {
>> -       uint8_t   *temp;
>> -       odp_crypto_generic_op_result_t *result;
>> -       odp_buffer_t buf;
>> -
>> -       /* HACK: Buffer is not packet any more in the API.
>> -        * Implementation still works that way. */
>> -       buf = odp_buffer_from_event(ev);
>> -
>> -       temp  = odp_buffer_addr(buf);
>> -       temp += odp_buffer_size(buf);
>> -       temp -= sizeof(*result);
>> -       result = (odp_crypto_generic_op_result_t *)(void *)temp;
>> -       return result;
>> +       return &(odp_packet_hdr(odp_packet_from_event(ev))->op_result);
>>  }
>>
>>  static
>> @@ -424,9 +406,9 @@ odp_crypto_operation(odp_crypto_op_params_t *params,
>>
>>                 /* Linux generic will always use packet for completion
>> event */
>>                 completion_event = odp_packet_to_event(params->out_pkt);
>> -
>>  _odp_buffer_type_set(odp_buffer_from_event(completion_event),
>> -                                    ODP_EVENT_CRYPTO_COMPL);
>> -
>> +               _odp_buffer_event_type_set(
>> +                       odp_buffer_from_event(completion_event),
>> +                       ODP_EVENT_CRYPTO_COMPL);
>>                 /* Asynchronous, build result (no HW so no errors) and
>> send it*/
>>                 op_result = get_op_result_from_event(completion_event);
>>                 op_result->magic = OP_RESULT_MAGIC;
>> @@ -537,7 +519,9 @@ odp_crypto_compl_result(odp_crypto_compl_t
>> completion_event,
>>  }
>>
>>  void
>> -odp_crypto_compl_free(odp_crypto_compl_t completion_event ODP_UNUSED)
>> +odp_crypto_compl_free(odp_crypto_compl_t completion_event)
>>  {
>> -       /* We use the packet as the completion event so nothing to do
>> here */
>> +       _odp_buffer_event_type_set(
>> +               odp_buffer_from_event((odp_event_t)completion_event),
>> +               ODP_EVENT_PACKET);
>>  }
>> diff --git a/platform/linux-generic/odp_event.c
>> b/platform/linux-generic/odp_event.c
>> index 17f4f43..d9e86a9 100644
>> --- a/platform/linux-generic/odp_event.c
>> +++ b/platform/linux-generic/odp_event.c
>> @@ -8,12 +8,9 @@
>>  #include <odp/buffer.h>
>>  #include <odp/pool.h>
>>  #include <odp_buffer_internal.h>
>> +#include <odp_buffer_inlines.h>
>>
>>  int odp_event_type(odp_event_t event)
>>  {
>> -       odp_buffer_t buf;
>> -
>> -       buf = odp_buffer_from_event(event);
>> -
>> -       return _odp_buffer_type(buf);
>> +       return _odp_buffer_event_type(odp_buffer_from_event(event));
>>  }
>> diff --git a/platform/linux-generic/odp_pool.c
>> b/platform/linux-generic/odp_pool.c
>> index 35e79a0..d92596e 100644
>> --- a/platform/linux-generic/odp_pool.c
>> +++ b/platform/linux-generic/odp_pool.c
>> @@ -364,6 +364,7 @@ odp_pool_t odp_pool_create(const char *name,
>>                         tmp->size = 0;
>>                         odp_atomic_init_u32(&tmp->ref_count, 0);
>>                         tmp->type = params->type;
>> +                       tmp->event_type = params->type;
>>                         tmp->pool_hdl = pool->s.pool_hdl;
>>                         tmp->uarea_addr = (void *)udat;
>>                         tmp->uarea_size = p_udata_size;
>> --
>> 2.1.0
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
>>
>
>
>
> --
> Mike Holmes
> Technical Manager - Linaro Networking Group
> Linaro.org <http://www.linaro.org/> *│ *Open source software for ARM SoCs
>
>
>
Maxim Uvarov June 16, 2015, 4:22 p.m. UTC | #3
On 06/11/15 03:12, Bill Fischofer wrote:
>   int odp_event_type(odp_event_t event)
>   {
> -	odp_buffer_t buf;
> -
> -	buf = odp_buffer_from_event(event);
> -
> -	return _odp_buffer_type(buf);
> +	return _odp_buffer_event_type(odp_buffer_from_event(event));
>   }

Bill, I think it's reasonable to write this in debug-friendly manner. 
And not use folding functions.

Maxim.
Bill Fischofer June 16, 2015, 6:38 p.m. UTC | #4
Not sure I understand the point being made.  How is a required cast
function not "debug friendly"?

On Tue, Jun 16, 2015 at 9:22 AM, Maxim Uvarov <maxim.uvarov@linaro.org>
wrote:

> On 06/11/15 03:12, Bill Fischofer wrote:
>
>>   int odp_event_type(odp_event_t event)
>>   {
>> -       odp_buffer_t buf;
>> -
>> -       buf = odp_buffer_from_event(event);
>> -
>> -       return _odp_buffer_type(buf);
>> +       return _odp_buffer_event_type(odp_buffer_from_event(event));
>>   }
>>
>
> Bill, I think it's reasonable to write this in debug-friendly manner. And
> not use folding functions.
>
> Maxim.
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
Maxim Uvarov June 16, 2015, 6:45 p.m. UTC | #5
On 06/16/15 21:38, Bill Fischofer wrote:
> Not sure I understand the point being made.  How is a required cast 
> function not "debug friendly"?

aga,  odp_buffer_from_event() is simple cast. So it's ok. (Initially I 
thought to keep origin code with separate buf,
to print it in gdb. But it's not needed if it's the same as event.).

Discard my note.

Maxim.

>
> On Tue, Jun 16, 2015 at 9:22 AM, Maxim Uvarov <maxim.uvarov@linaro.org 
> <mailto:maxim.uvarov@linaro.org>> wrote:
>
>     On 06/11/15 03:12, Bill Fischofer wrote:
>
>           int odp_event_type(odp_event_t event)
>           {
>         -       odp_buffer_t buf;
>         -
>         -       buf = odp_buffer_from_event(event);
>         -
>         -       return _odp_buffer_type(buf);
>         +       return
>         _odp_buffer_event_type(odp_buffer_from_event(event));
>           }
>
>
>     Bill, I think it's reasonable to write this in debug-friendly
>     manner. And not use folding functions.
>
>     Maxim.
>
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
Ola Liljedahl June 16, 2015, 6:45 p.m. UTC | #6
On 16 June 2015 at 20:38, Bill Fischofer <bill.fischofer@linaro.org> wrote:

> Not sure I understand the point being made.  How is a required cast
> function not "debug friendly"?
>
I assume Maxim refers to the combination of these functions calls into one
expression. This makes e.g. single-stepping more complicated.
Keeping the functions calls on separate lines makes debugging simpler,
easier to set breakpoints or step over/into.



>
> On Tue, Jun 16, 2015 at 9:22 AM, Maxim Uvarov <maxim.uvarov@linaro.org>
> wrote:
>
>> On 06/11/15 03:12, Bill Fischofer wrote:
>>
>>>   int odp_event_type(odp_event_t event)
>>>   {
>>> -       odp_buffer_t buf;
>>> -
>>> -       buf = odp_buffer_from_event(event);
>>> -
>>> -       return _odp_buffer_type(buf);
>>> +       return _odp_buffer_event_type(odp_buffer_from_event(event));
>>>   }
>>>
>>
>> Bill, I think it's reasonable to write this in debug-friendly manner. And
>> not use folding functions.
>>
>> Maxim.
>>
>>
>> _______________________________________________
>> lng-odp mailing list
>> lng-odp@lists.linaro.org
>> https://lists.linaro.org/mailman/listinfo/lng-odp
>>
>
>
> _______________________________________________
> lng-odp mailing list
> lng-odp@lists.linaro.org
> https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
Maxim Uvarov June 16, 2015, 6:48 p.m. UTC | #7
On 06/16/15 21:45, Ola Liljedahl wrote:
> On 16 June 2015 at 20:38, Bill Fischofer <bill.fischofer@linaro.org 
> <mailto:bill.fischofer@linaro.org>> wrote:
>
>     Not sure I understand the point being made.  How is a required
>     cast function not "debug friendly"?
>
> I assume Maxim refers to the combination of these functions calls into 
> one expression. This makes e.g. single-stepping more complicated.
> Keeping the functions calls on separate lines makes debugging simpler, 
> easier to set breakpoints or step over/into.
>

Yes, I meant that, thanks. But now I took a look that 
odp_buffer_from_event() is simple cast.

Maxim.
>
>
>     On Tue, Jun 16, 2015 at 9:22 AM, Maxim Uvarov
>     <maxim.uvarov@linaro.org <mailto:maxim.uvarov@linaro.org>> wrote:
>
>         On 06/11/15 03:12, Bill Fischofer wrote:
>
>               int odp_event_type(odp_event_t event)
>               {
>             -       odp_buffer_t buf;
>             -
>             -       buf = odp_buffer_from_event(event);
>             -
>             -       return _odp_buffer_type(buf);
>             +       return
>             _odp_buffer_event_type(odp_buffer_from_event(event));
>               }
>
>
>         Bill, I think it's reasonable to write this in debug-friendly
>         manner. And not use folding functions.
>
>         Maxim.
>
>
>         _______________________________________________
>         lng-odp mailing list
>         lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>         https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
Maxim Uvarov June 16, 2015, 7:53 p.m. UTC | #8
Merged,

Thanks,
Maxim.

On 06/11/15 03:12, Bill Fischofer wrote:
> Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
> ---
>   .../linux-generic/include/odp_buffer_inlines.h     |  9 ++++++
>   .../linux-generic/include/odp_buffer_internal.h    |  1 +
>   .../linux-generic/include/odp_packet_internal.h    |  4 +++
>   platform/linux-generic/odp_crypto.c                | 32 ++++++----------------
>   platform/linux-generic/odp_event.c                 |  7 ++---
>   platform/linux-generic/odp_pool.c                  |  1 +
>   6 files changed, 25 insertions(+), 29 deletions(-)
>
> diff --git a/platform/linux-generic/include/odp_buffer_inlines.h b/platform/linux-generic/include/odp_buffer_inlines.h
> index 2c792e2..91e56bd 100644
> --- a/platform/linux-generic/include/odp_buffer_inlines.h
> +++ b/platform/linux-generic/include/odp_buffer_inlines.h
> @@ -188,6 +188,15 @@ static inline void *segment_map(odp_buffer_hdr_t *buf,
>   	return (void *)seg_addr;
>   }
>   
> +static inline int _odp_buffer_event_type(odp_buffer_t buf)
> +{
> +	return odp_buf_to_hdr(buf)->event_type;
> +}
> +
> +static inline void _odp_buffer_event_type_set(odp_buffer_t buf, int ev)
> +{
> +	odp_buf_to_hdr(buf)->event_type = ev;
> +}
>   
>   #ifdef __cplusplus
>   }
> diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h
> index e7b7568..a3632fe 100644
> --- a/platform/linux-generic/include/odp_buffer_internal.h
> +++ b/platform/linux-generic/include/odp_buffer_internal.h
> @@ -117,6 +117,7 @@ typedef struct odp_buffer_hdr_t {
>   		};
>   	} flags;
>   	int                      type;       /* buffer type */
> +	int                      event_type; /* for reuse as event */
>   	uint32_t                 size;       /* max data size */
>   	odp_atomic_u32_t         ref_count;  /* reference count */
>   	odp_pool_t               pool_hdl;   /* buffer pool handle */
> diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
> index 9890dc8..8c41491 100644
> --- a/platform/linux-generic/include/odp_packet_internal.h
> +++ b/platform/linux-generic/include/odp_packet_internal.h
> @@ -25,6 +25,8 @@ extern "C" {
>   #include <odp_buffer_inlines.h>
>   #include <odp/packet.h>
>   #include <odp/packet_io.h>
> +#include <odp/crypto.h>
> +#include <odp_crypto_internal.h>
>   
>   /**
>    * Packet input & protocol flags
> @@ -134,6 +136,8 @@ typedef struct {
>   	uint32_t tailroom;
>   
>   	odp_pktio_t input;
> +
> +	odp_crypto_generic_op_result_t op_result;  /**< Result for crypto */
>   } odp_packet_hdr_t;
>   
>   typedef struct odp_packet_hdr_stride {
> diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
> index b16316c..515f508 100644
> --- a/platform/linux-generic/odp_crypto.c
> +++ b/platform/linux-generic/odp_crypto.c
> @@ -37,28 +37,10 @@ struct odp_crypto_global_s {
>   
>   static odp_crypto_global_t *global;
>   
> -/*
> - * @todo This is a serious hack to allow us to use packet buffer to convey
> - *       crypto operation results by placing them at the very end of the
> - *       packet buffer.  The issue should be resolved shortly once the issue
> - *       of packets versus events on completion queues is closed.
> - */
>   static
>   odp_crypto_generic_op_result_t *get_op_result_from_event(odp_event_t ev)
>   {
> -	uint8_t   *temp;
> -	odp_crypto_generic_op_result_t *result;
> -	odp_buffer_t buf;
> -
> -	/* HACK: Buffer is not packet any more in the API.
> -	 * Implementation still works that way. */
> -	buf = odp_buffer_from_event(ev);
> -
> -	temp  = odp_buffer_addr(buf);
> -	temp += odp_buffer_size(buf);
> -	temp -= sizeof(*result);
> -	result = (odp_crypto_generic_op_result_t *)(void *)temp;
> -	return result;
> +	return &(odp_packet_hdr(odp_packet_from_event(ev))->op_result);
>   }
>   
>   static
> @@ -424,9 +406,9 @@ odp_crypto_operation(odp_crypto_op_params_t *params,
>   
>   		/* Linux generic will always use packet for completion event */
>   		completion_event = odp_packet_to_event(params->out_pkt);
> -		_odp_buffer_type_set(odp_buffer_from_event(completion_event),
> -				     ODP_EVENT_CRYPTO_COMPL);
> -
> +		_odp_buffer_event_type_set(
> +			odp_buffer_from_event(completion_event),
> +			ODP_EVENT_CRYPTO_COMPL);
>   		/* Asynchronous, build result (no HW so no errors) and send it*/
>   		op_result = get_op_result_from_event(completion_event);
>   		op_result->magic = OP_RESULT_MAGIC;
> @@ -537,7 +519,9 @@ odp_crypto_compl_result(odp_crypto_compl_t completion_event,
>   }
>   
>   void
> -odp_crypto_compl_free(odp_crypto_compl_t completion_event ODP_UNUSED)
> +odp_crypto_compl_free(odp_crypto_compl_t completion_event)
>   {
> -	/* We use the packet as the completion event so nothing to do here */
> +	_odp_buffer_event_type_set(
> +		odp_buffer_from_event((odp_event_t)completion_event),
> +		ODP_EVENT_PACKET);
>   }
> diff --git a/platform/linux-generic/odp_event.c b/platform/linux-generic/odp_event.c
> index 17f4f43..d9e86a9 100644
> --- a/platform/linux-generic/odp_event.c
> +++ b/platform/linux-generic/odp_event.c
> @@ -8,12 +8,9 @@
>   #include <odp/buffer.h>
>   #include <odp/pool.h>
>   #include <odp_buffer_internal.h>
> +#include <odp_buffer_inlines.h>
>   
>   int odp_event_type(odp_event_t event)
>   {
> -	odp_buffer_t buf;
> -
> -	buf = odp_buffer_from_event(event);
> -
> -	return _odp_buffer_type(buf);
> +	return _odp_buffer_event_type(odp_buffer_from_event(event));
>   }
> diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
> index 35e79a0..d92596e 100644
> --- a/platform/linux-generic/odp_pool.c
> +++ b/platform/linux-generic/odp_pool.c
> @@ -364,6 +364,7 @@ odp_pool_t odp_pool_create(const char *name,
>   			tmp->size = 0;
>   			odp_atomic_init_u32(&tmp->ref_count, 0);
>   			tmp->type = params->type;
> +			tmp->event_type = params->type;
>   			tmp->pool_hdl = pool->s.pool_hdl;
>   			tmp->uarea_addr = (void *)udat;
>   			tmp->uarea_size = p_udata_size;
diff mbox

Patch

diff --git a/platform/linux-generic/include/odp_buffer_inlines.h b/platform/linux-generic/include/odp_buffer_inlines.h
index 2c792e2..91e56bd 100644
--- a/platform/linux-generic/include/odp_buffer_inlines.h
+++ b/platform/linux-generic/include/odp_buffer_inlines.h
@@ -188,6 +188,15 @@  static inline void *segment_map(odp_buffer_hdr_t *buf,
 	return (void *)seg_addr;
 }
 
+static inline int _odp_buffer_event_type(odp_buffer_t buf)
+{
+	return odp_buf_to_hdr(buf)->event_type;
+}
+
+static inline void _odp_buffer_event_type_set(odp_buffer_t buf, int ev)
+{
+	odp_buf_to_hdr(buf)->event_type = ev;
+}
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/include/odp_buffer_internal.h b/platform/linux-generic/include/odp_buffer_internal.h
index e7b7568..a3632fe 100644
--- a/platform/linux-generic/include/odp_buffer_internal.h
+++ b/platform/linux-generic/include/odp_buffer_internal.h
@@ -117,6 +117,7 @@  typedef struct odp_buffer_hdr_t {
 		};
 	} flags;
 	int                      type;       /* buffer type */
+	int                      event_type; /* for reuse as event */
 	uint32_t                 size;       /* max data size */
 	odp_atomic_u32_t         ref_count;  /* reference count */
 	odp_pool_t               pool_hdl;   /* buffer pool handle */
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h
index 9890dc8..8c41491 100644
--- a/platform/linux-generic/include/odp_packet_internal.h
+++ b/platform/linux-generic/include/odp_packet_internal.h
@@ -25,6 +25,8 @@  extern "C" {
 #include <odp_buffer_inlines.h>
 #include <odp/packet.h>
 #include <odp/packet_io.h>
+#include <odp/crypto.h>
+#include <odp_crypto_internal.h>
 
 /**
  * Packet input & protocol flags
@@ -134,6 +136,8 @@  typedef struct {
 	uint32_t tailroom;
 
 	odp_pktio_t input;
+
+	odp_crypto_generic_op_result_t op_result;  /**< Result for crypto */
 } odp_packet_hdr_t;
 
 typedef struct odp_packet_hdr_stride {
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c
index b16316c..515f508 100644
--- a/platform/linux-generic/odp_crypto.c
+++ b/platform/linux-generic/odp_crypto.c
@@ -37,28 +37,10 @@  struct odp_crypto_global_s {
 
 static odp_crypto_global_t *global;
 
-/*
- * @todo This is a serious hack to allow us to use packet buffer to convey
- *       crypto operation results by placing them at the very end of the
- *       packet buffer.  The issue should be resolved shortly once the issue
- *       of packets versus events on completion queues is closed.
- */
 static
 odp_crypto_generic_op_result_t *get_op_result_from_event(odp_event_t ev)
 {
-	uint8_t   *temp;
-	odp_crypto_generic_op_result_t *result;
-	odp_buffer_t buf;
-
-	/* HACK: Buffer is not packet any more in the API.
-	 * Implementation still works that way. */
-	buf = odp_buffer_from_event(ev);
-
-	temp  = odp_buffer_addr(buf);
-	temp += odp_buffer_size(buf);
-	temp -= sizeof(*result);
-	result = (odp_crypto_generic_op_result_t *)(void *)temp;
-	return result;
+	return &(odp_packet_hdr(odp_packet_from_event(ev))->op_result);
 }
 
 static
@@ -424,9 +406,9 @@  odp_crypto_operation(odp_crypto_op_params_t *params,
 
 		/* Linux generic will always use packet for completion event */
 		completion_event = odp_packet_to_event(params->out_pkt);
-		_odp_buffer_type_set(odp_buffer_from_event(completion_event),
-				     ODP_EVENT_CRYPTO_COMPL);
-
+		_odp_buffer_event_type_set(
+			odp_buffer_from_event(completion_event),
+			ODP_EVENT_CRYPTO_COMPL);
 		/* Asynchronous, build result (no HW so no errors) and send it*/
 		op_result = get_op_result_from_event(completion_event);
 		op_result->magic = OP_RESULT_MAGIC;
@@ -537,7 +519,9 @@  odp_crypto_compl_result(odp_crypto_compl_t completion_event,
 }
 
 void
-odp_crypto_compl_free(odp_crypto_compl_t completion_event ODP_UNUSED)
+odp_crypto_compl_free(odp_crypto_compl_t completion_event)
 {
-	/* We use the packet as the completion event so nothing to do here */
+	_odp_buffer_event_type_set(
+		odp_buffer_from_event((odp_event_t)completion_event),
+		ODP_EVENT_PACKET);
 }
diff --git a/platform/linux-generic/odp_event.c b/platform/linux-generic/odp_event.c
index 17f4f43..d9e86a9 100644
--- a/platform/linux-generic/odp_event.c
+++ b/platform/linux-generic/odp_event.c
@@ -8,12 +8,9 @@ 
 #include <odp/buffer.h>
 #include <odp/pool.h>
 #include <odp_buffer_internal.h>
+#include <odp_buffer_inlines.h>
 
 int odp_event_type(odp_event_t event)
 {
-	odp_buffer_t buf;
-
-	buf = odp_buffer_from_event(event);
-
-	return _odp_buffer_type(buf);
+	return _odp_buffer_event_type(odp_buffer_from_event(event));
 }
diff --git a/platform/linux-generic/odp_pool.c b/platform/linux-generic/odp_pool.c
index 35e79a0..d92596e 100644
--- a/platform/linux-generic/odp_pool.c
+++ b/platform/linux-generic/odp_pool.c
@@ -364,6 +364,7 @@  odp_pool_t odp_pool_create(const char *name,
 			tmp->size = 0;
 			odp_atomic_init_u32(&tmp->ref_count, 0);
 			tmp->type = params->type;
+			tmp->event_type = params->type;
 			tmp->pool_hdl = pool->s.pool_hdl;
 			tmp->uarea_addr = (void *)udat;
 			tmp->uarea_size = p_udata_size;