CAM API Documentation
Loading...
Searching...
No Matches
Hardware Managed BCAM Public API

Overview

First a ccam_arg struct is declared. The ccam_arg struct needs to be initialized with pointers to the hw read/write functions, debug flags and optimization flags. The ccam_arg struct is then passed to cbcam_init(). Memory for the cbcam instance must be allocated before calling cbcam_init (the size is given by cbcam_size()). No additional memory is allocated by the driver during runtime. cbcam_init() copies all the information in the ccam_arg allowing the ccam_arg to be destroyed after the cbcam_init() call. cbcam_init() returns a cbcam handle which is used for the other API functions.

Functions

size_t cbcam_size (void)
 
int cbcam_init (const struct ccam_arg *arg, struct cbcam *cbcam)
 
int cbcam_insert (struct cbcam *cbcam, const uint8_t key[], const uint8_t response[])
 
int cbcam_update (struct cbcam *cbcam, const uint8_t key[], const uint8_t response[])
 
int cbcam_get_by_key (struct cbcam *cbcam, const uint8_t key[], uint8_t response[])
 
int cbcam_delete_all (struct cbcam *cbcam)
 
int cbcam_delete (struct cbcam *cbcam, const uint8_t key[])
 
int cbcam_get_by_response (struct cbcam *cbcam, const uint8_t in_response[], const uint8_t response_mask[], uint32_t *pos, uint8_t out_key[], uint8_t out_response[])
 
int cbcam_get_by_key_and_response (struct cbcam *cbcam, const uint8_t key[], const uint8_t key_mask[], const uint8_t response[], const uint8_t response_mask[], uint32_t *pos, uint8_t out_key[], uint8_t out_response[])
 

Function Documentation

◆ cbcam_size()

size_t cbcam_size ( void )

Returns the size of cbcam instance in bytes. The size is useful for allocating the right amount of memory for the cbcam instance.

Returns
The size of cbcam in bytes

◆ cbcam_init()

int cbcam_init ( const struct ccam_arg * arg,
struct cbcam * cbcam )

Initializes a cbcam instance. Returns 0 if successful, otherwise an error code. Memory for the cbcam instance must be allocated but not necessarily cleared prior to calling cbcam_init. The instance is initialized using passed arguments containing hw read/write functions, debug flags and optimization flags and other infromation. In addition to this HW configuration data is read from the HW itself. This way the CAM driver can be used for many different HW configurations. The cbcam is HW managed which means that the basic insert, update, delete and get_by_key functions are implemented in HW and that the CAM driver writes high level commands to the HW to get them executed. The CAM driver does not use shadow memory and no heap allocations take place inside the driver. A cbcam instance is a superset of a ccam instance. This means that all the functions in the ccam.h API can be used for the cbcam after typecasting to ccam.

Parameters
[in]argArguments used to initialize the cbcam instance. the content of arg is copied to the cbcam instance
[out]cbcamReturns the initialized cbcam instance.
Returns
Returns 0 for success, otherwise the error code.

◆ cbcam_insert()

int cbcam_insert ( struct cbcam * cbcam,
const uint8_t key[],
const uint8_t response[] )

Inserts an entry to the cbcam instance. If an entry with the same key is found, the function fails by returning error code CCAM_ERROR_DUPLICATE_FOUND. If the entry is not found, then it is inserted in the cbcam instance. Returns 0 if successful, otherwise an error code. If an error code is returned nothing is inserted.

Parameters
[in]cbcamPointer to the cbcam instance
[in]keyThe key of the entry. The key width is read from the HW configuration during cbcam_init. Any contents outside the scope of the key width is ignored. The key is assumed to be in little-endian format. key[0] bit 0 is the least significant bit of the key. key[1] bit 0 is bit 8 of the key and so on.
[in]responseThe response of the entry. The response width is read from the HW configuration during cbcam_init. Any contents outside the scope of the response width is ignored. The response is assumed to be in little-endian format. response[0] bit 0 is the least significant bit of the response. response[1] bit 0 is bit 8 of the response and so on.
Returns
Returns 0 for success, otherwise the error code.

◆ cbcam_update()

int cbcam_update ( struct cbcam * cbcam,
const uint8_t key[],
const uint8_t response[] )

Updates an entry in the cbcam instance. If the entry is found, the response is updated. If the entry is not found, the function fails with error code CCAM_NOT_FOUND. Returns 0 if successful, otherwise an error code.

Parameters
[in]cbcamPointer to the cbcam instance
[in]keySee key for cbcam_insert
[in]responseSee response for cbcam_insert
Returns
Returns 0 for success, otherwise the error code.

◆ cbcam_get_by_key()

int cbcam_get_by_key ( struct cbcam * cbcam,
const uint8_t key[],
uint8_t response[] )

Gets an entry with matching key from the cbcam instance. If an entry is not found, the return code is CCAM_NOT_FOUND. If an entry is found in the instance, the function returns 0 and the response associated with the key is passed.

Parameters
[in]cbcamPointer to the cbcam instance
[in]keySee key for cbcam_insert
[out]responseThe response width is read from the HW configuration during cbcam_init. Only response width bits are written to the out argument. The response is assumed to be in little-endian format. response[0] bit 0 is the least significant bit of the response. response[1] bit 0 is bit 8 of the response and so on.
Returns
Returns 0 for success, otherwise the error code.

◆ cbcam_delete_all()

int cbcam_delete_all ( struct cbcam * cbcam)

Deletes all entries from the cbcam instance.

Parameters
[in]cbcamPointer to the cbcam instance
Returns
Returns 0 for success, otherwise the error code.

◆ cbcam_delete()

int cbcam_delete ( struct cbcam * cbcam,
const uint8_t key[] )

Deletes an entry from the cbcam instance. If the entry is found, the function returns 0. If an entry is not found, the function fails with error code CCAM_NOT_FOUND.

Parameters
[in]cbcamPointer to the cbcam instance
[in]keySee key for cbcam_insert
Returns
Returns 0 for success, otherwise the error code.

◆ cbcam_get_by_response()

int cbcam_get_by_response ( struct cbcam * cbcam,
const uint8_t in_response[],
const uint8_t response_mask[],
uint32_t * pos,
uint8_t out_key[],
uint8_t out_response[] )

Gets an entry with matching response from the cbcam instance. The function uses linear search and reads address by address form the HW. Many entries might have a matching response. To get all matching responses cbcam_get_by_response can be called repeatedly until CCAM_NOT_FOUND is returned. The first time a response is searched, pos should be cleared. For succeeding calls the returned pos should be passed in again. pos keeps track of the address in the linear search that takes place.

Parameters
[in]cbcamPointer to the cbcam instance
[in]in_responseThe response to search for. The response width is read from the HW configuration during cbcam_init. Any contents outside the scope of the response width is ignored. The in_response is assumed to be in little-endian format. in_response[0] bit 0 is the least significant bit of the in_response. in_response[1] bit 0 is bit 8 of the in_response and so on.
[in]response_maskThe in_response is masked (ANDed) with response_mask and then compared with response_mask masked (ANDed) with the stored response. If the comparision is successful there is a match. This way sub-fields of the response can be searched for. The response width is read from the HW configuration during cbcam_init. Any contents outside the scope of the response width is ignored. The response_mask is assumed to be in little-endian format. response_mask[0] bit 0 is the least significant bit of the response_mask. response_mask[1] bit 0 is bit 8 of the response_mask and so on.
[in,out]posThe position pointer used for the linear search. Should be cleared the first time a response is searched. Should be fed in again for consecutive searches of the same response
[out]out_keyThe key for the matching response. The key width is read from the HW configuration during cbcam_init. Only key width bits are written to out_key. The out_key is assumed to be in little-endian format. out_key[0] bit 0 is the least significant bit of the out_key. out_key[1] bit 0 is bit 8 of the out_key and so on.
[out]out_responseThe stored response of the matching response. If the response_mask is all 'ones' then out_respone and in_response are equal. The response width is read from the HW configuration during cbcam_init. Only response width bits are written to out_response. The out_response is assumed to be in little-endian format. out_response[0] bit 0 is the least significant bit of the out_resposne. out_response[1] bit 0 is bit 8 of the out_response and so on.
Returns
Returns 0 for success, otherwise the error code.

◆ cbcam_get_by_key_and_response()

int cbcam_get_by_key_and_response ( struct cbcam * cbcam,
const uint8_t key[],
const uint8_t key_mask[],
const uint8_t response[],
const uint8_t response_mask[],
uint32_t * pos,
uint8_t out_key[],
uint8_t out_response[] )

Iterate over entries in the CAM.

The key, key_mask, response and response_mask allow the returned values to be limited to those which contain particular bit values in particular positions.

The pos argument should be set to zero when the function is first called. If it returns success, it can be called again with the same pos value to find the next matching entry. The search is complete when it returns CAM_ERROR_KEY_NOT_FOUND.

Any of the output parameters may be NULL if the caller is not interested in the corresponding value.

Parameters
[in]cbcamDriver instance.
[in]keyThe key value to search for. May be NULL to specify that any stored key should match.
[in]key_maskMask limiting the search to certain subfields of the key. Set bits in this mask specify bits of the key which should be matched against the stored entry; clear bits in this mask will match against any value in the stored entry. May be NULL to specify that any stored key should match.
[in]responseThe response value to search for. May be NULL to specify that any stored response should match.
[in]response_maskMask limiting the search to certain subfields of the response. Set bits in this mask specify bits of the response which should be matched against the stored entry; clear bits in this mask will match against any value in the stored entry. May be NULL to specify that any stored response should match.
[in,out]posCurrent position of the iteration. Use 0 for the first call.
[out]out_keyThe matched key.
[out]out_responseThe matched response.
[in]optsNot currently used; pass NULL
Returns
0 for success. CUE_ERROR_KEY_NOT_FOUND if no matching entries were found. This also indicates the end of the iteration. CUE_ERROR_ENVIRONMENT if the hardware reported a bus error. CUE_ERROR_ENVIRONMENT_POLLED_OUT if the hardware reported a timeout.