Skip to content

Commit

Permalink
Mustang/BF3 changes
Browse files Browse the repository at this point in the history
* Number of PKA devices is now increased to 24.
  3 Clusters of 8 PKA devices each.

* The bit positions for configuration registers are also changed.
  Hence the change in window ram bitmask.

Signed-off-by: Mahantesh Salimath <mahantesh@nvidia.com>
  • Loading branch information
mahantesh-nvidia committed Aug 3, 2021
1 parent 65016c6 commit b0f32fa
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
10 changes: 9 additions & 1 deletion include/pka_config.h
Expand Up @@ -37,13 +37,17 @@
#include "pka_addrs.h"

// The maximum number of PKA shims refered to as IO blocks.
#define PKA_MAX_NUM_IO_BLOCKS 8
#define PKA_MAX_NUM_IO_BLOCKS 24
// The maximum number of Rings supported by IO block (shim).
#define PKA_MAX_NUM_IO_BLOCK_RINGS 4

#define PKA_MAX_NUM_RINGS \
(PKA_MAX_NUM_IO_BLOCK_RINGS * PKA_MAX_NUM_IO_BLOCKS)

// Bitmask to represent rings, grouped into 8 bit (uint8_t) blocks.
#define PKA_RING_NUM_BITMASK \
((PKA_MAX_NUM_RINGS / 8) + 1)

// Resources are regions which include info control/status words,
// count registers and host window ram.
#define PKA_MAX_NUM_RING_RESOURCES 3
Expand Down Expand Up @@ -72,8 +76,12 @@
#define PKA_WINDOW_RAM_RING_MEM_SIZE 0x0800 // 2KB
#define PKA_WINDOW_RAM_DATA_MEM_SIZE 0x3800 // 14KB

// Window RAM/Alternate Window RAM offset mask for BF1 and BF2
#define PKA_WINDOW_RAM_OFFSET_MASK1 0x730000

// Window RAM/Alternate Window RAM offset mask for BF3
#define PKA_WINDOW_RAM_OFFSET_MASK2 0x70000

// Macro for mapping PKA Ring address into Window RAM address. It converts the
// ring address, either physical address or virtual address, to valid address
// into the Window RAM. This is done assuming the Window RAM base, size and
Expand Down
8 changes: 4 additions & 4 deletions lib/pka.c
Expand Up @@ -267,7 +267,7 @@ pka_instance_t pka_init_global(const char *name,
pka_get_rings_byte_order(PKA_HANDLE_INVALID);
ret = pka_ring_lookup(pka_gbl_info->rings, ring_cnt,
pka_gbl_info->rings_byte_order,
&pka_gbl_info->rings_mask,
pka_gbl_info->rings_mask,
&pka_gbl_info->rings_cnt);
if (ret)
{
Expand Down Expand Up @@ -314,8 +314,8 @@ void pka_term_global(pka_instance_t instance)
"longer usable\n");

PKA_DEBUG(PKA_USER, "release PKA rings\n");
pka_ring_free(pka_gbl_info->rings, &pka_gbl_info->rings_mask,
&pka_gbl_info->rings_cnt);
pka_ring_free(pka_gbl_info->rings, pka_gbl_info->rings_mask,
&pka_gbl_info->rings_cnt);

free(pka_gbl_info);
pka_gbl_info = NULL;
Expand Down Expand Up @@ -383,7 +383,7 @@ uint32_t pka_get_rings_count(pka_instance_t instance)
return 0;
}

uint32_t pka_get_rings_bitmask(pka_instance_t instance)
uint8_t* pka_get_rings_bitmask(pka_instance_t instance)
{
if (instance == (pka_instance_t) pka_gbl_info->main_pid)
return pka_gbl_info->rings_mask;
Expand Down
4 changes: 2 additions & 2 deletions lib/pka.h
Expand Up @@ -220,8 +220,8 @@ uint32_t pka_get_rings_count(pka_instance_t instance);
///
/// @param instance A PK instance handle.
///
/// @return The bitmask of allocated HW rings.
uint32_t pka_get_rings_bitmask(pka_instance_t instance);
/// @return The bitmask(array of uint8_t) of allocated HW rings.
uint8_t* pka_get_rings_bitmask(pka_instance_t instance);

/// Thread local PKA initialization. All threads must call this function before
/// calling any other PKA API functions. The instance parameter specifies which
Expand Down
2 changes: 1 addition & 1 deletion lib/pka_internal.h
Expand Up @@ -75,7 +75,7 @@ typedef struct
/// thread workers.

uint32_t rings_byte_order; ///< byte order whether BE or LE.
uint32_t rings_mask; ///< bitmask of allocated HW rings.
uint8_t rings_mask[PKA_RING_NUM_BITMASK]; ///< bitmask of allocated HW rings.
uint32_t rings_cnt; ///< number of allocated Rings.
pka_ring_info_t rings[PKA_MAX_NUM_RINGS]; ///< table of allocated rings
/// to process PK commands.
Expand Down
19 changes: 14 additions & 5 deletions lib/pka_ring.c
Expand Up @@ -139,14 +139,14 @@ static void pka_ring_reset_mem(pka_ring_info_t *ring)
int pka_ring_lookup(pka_ring_info_t rings[],
uint32_t req_rings_num,
uint8_t byte_order,
uint32_t *mask,
uint8_t mask[],
uint32_t *cnt)
{
pka_ring_info_t *ring;
uint32_t ring_idx;
uint8_t mask_idx, mask_bit;
int container;

*mask = 0;
*cnt = 0;

if (!req_rings_num)
Expand Down Expand Up @@ -178,6 +178,9 @@ int pka_ring_lookup(pka_ring_info_t rings[],
return -EFAULT;
}

// Clear HW rings bitmask
memset(mask, 0, PKA_RING_NUM_BITMASK * sizeof(*mask));

// Lookup for available ring.
for (ring_idx = 0; ring_idx < req_rings_num; ring_idx++)
{
Expand Down Expand Up @@ -221,8 +224,11 @@ int pka_ring_lookup(pka_ring_info_t rings[],

ring->idx = ring_idx;
ring->big_endian = byte_order;

// Set ring bit in mask
*mask |= 1 << ring->ring_id;
mask_idx = ring->ring_id / 8;
mask_bit = ring->ring_id % 8;
mask[mask_idx] |= 1 << mask_bit;
*cnt += 1;
}

Expand Down Expand Up @@ -250,9 +256,10 @@ static int pka_ring_put(pka_ring_info_t *ring, uint32_t cnt)
}

// Free the set of assigned rings.
int pka_ring_free(pka_ring_info_t rings[], uint32_t *mask, uint32_t *cnt)
int pka_ring_free(pka_ring_info_t rings[], uint8_t mask[], uint32_t *cnt)
{
pka_ring_info_t *ring;
uint8_t mask_idx, mask_bit;
uint32_t ring_idx = 0;

if (!rings)
Expand All @@ -263,7 +270,9 @@ int pka_ring_free(pka_ring_info_t rings[], uint32_t *mask, uint32_t *cnt)
ring = &rings[ring_idx];

// Reset ring bit in mask (or toggle the bit i ^= (1 << bit))
*mask &= ~(1 << ring->ring_id);
mask_idx = ring->ring_id / 8;
mask_bit = ring->ring_id % 8;
mask[mask_idx] &= ~(1 << mask_bit);
*cnt -= 1;

// Clear memory content.
Expand Down
4 changes: 2 additions & 2 deletions lib/pka_ring.h
Expand Up @@ -292,12 +292,12 @@ typedef struct
int pka_ring_lookup(pka_ring_info_t rings[],
uint32_t req_rings_num,
uint8_t byte_order,
uint32_t *mask,
uint8_t mask[],
uint32_t *cnt);

/// Free a set of assigned rings, referred by their number (cnt), their mask.
/// It returns 0 on success, a negative error code on failure.
int pka_ring_free(pka_ring_info_t rings[], uint32_t *mask, uint32_t *cnt);
int pka_ring_free(pka_ring_info_t rings[], uint8_t mask[], uint32_t *cnt);

/// Returns the number of available of rooms to append a command descriptors
/// within a given ring.
Expand Down
9 changes: 7 additions & 2 deletions tests/power/pka_test_power.c
Expand Up @@ -928,19 +928,24 @@ static void ParseArgs(int argc, char *argv[], app_args_t *app_args)

static void PrintInfo(char *progname, app_args_t *app_args)
{
int8_t mask_idx;
uint8_t *mask;

printf("Running PKA test: %s\n"
"--------------------------\n"
"Avail rings : %d\n"
"HW rings in use : %x\n"
"Nb of objs per queue : %d\n"
"RSA key size in bits : %d\n"
"Expected duration : %ds\n",
progname,
pka_get_rings_count(pka_instance),
pka_get_rings_bitmask(pka_instance),
app_args->queue_size,
app_args->key_size * 1024,
app_args->duration);
mask = pka_get_rings_bitmask(pka_instance);
printf("HW rings in use : ");
for (mask_idx = PKA_RING_NUM_BITMASK - 1; mask_idx >= 0; mask_idx--)
printf("%x", mask[mask_idx]);
printf("\n\n");
fflush(NULL);
}
Expand Down
14 changes: 10 additions & 4 deletions tests/validation/pka_test_validation.c
Expand Up @@ -1836,6 +1836,8 @@ static void ParseArgs(int argc, char *argv[], app_args_t *app_args)

static void PrintInfo(char *progname, app_args_t *app_args)
{
int8_t mask_idx;
uint8_t *mask;
printf("\n"
"PKA system info\n"
"---------------\n"
Expand All @@ -1851,11 +1853,15 @@ static void PrintInfo(char *progname, app_args_t *app_args)

printf("Running PKA inst: %s\n"
"-----------------\n"
"Avail rings: %d\n"
"HW rings in use: %x\n",
"Avail rings: %d\n",
progname,
pka_get_rings_count(app_args->instance),
pka_get_rings_bitmask(app_args->instance));
pka_get_rings_count(app_args->instance));

mask = pka_get_rings_bitmask(app_args->instance);
printf("HW rings in use : ");
for (mask_idx = PKA_RING_NUM_BITMASK - 1; mask_idx >= 0; mask_idx--)
printf("%x", mask[mask_idx]);
printf("\n\n");
printf("Mode: ");
switch (app_args->mode)
{
Expand Down

0 comments on commit b0f32fa

Please sign in to comment.