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.
|
| 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 (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[]) |
| |
| 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
| 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] | arg | Arguments used to initialize the cbcam instance. the content of arg is copied to the cbcam instance |
| [out] | cbcam | Returns the initialized cbcam instance. |
- Returns
- Returns 0 for success, otherwise the error code.
| 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] | cbcam | Pointer to the cbcam instance |
| [in] | key | The 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] | response | The 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.
| 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] | cbcam | Pointer to the cbcam instance |
| [in] | key | See key for cbcam_insert |
| [in] | response | See response for cbcam_insert |
- Returns
- Returns 0 for success, otherwise the error code.
| 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] | cbcam | Pointer to the cbcam instance |
| [in] | key | See key for cbcam_insert |
| [out] | response | The 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.
| 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] | cbcam | Pointer to the cbcam instance |
| [in] | key | See key for cbcam_insert |
- Returns
- Returns 0 for success, otherwise the error code.
| 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] | cbcam | Pointer to the cbcam instance |
| [in] | in_response | The 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_mask | The 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] | pos | The 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_key | The 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_response | The 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.