Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/smartpqi/smartpqi_tag.c
/*- | /*- | ||||
* Copyright (c) 2018 Microsemi Corporation. | * Copyright (c) 2016-2019 Microsemi Corporation. | ||||
* Copyright (c) 2020 Microchip Technology Inc. and it's subsidiaries. | |||||
* | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
Context not available. | |||||
{ | { | ||||
OS_ACQUIRE_SPINLOCK(&(taglist->lock)); | OS_ACQUIRE_SPINLOCK(&(taglist->lock)); | ||||
/*DBG_FUNC("IN\n");*/ | /* DBG_FUNC("IN\n");*/ | ||||
ASSERT(taglist->num_elem < taglist->max_elem); | ASSERT(taglist->num_elem < taglist->max_elem); | ||||
Context not available. | |||||
OS_RELEASE_SPINLOCK(&taglist->lock); | OS_RELEASE_SPINLOCK(&taglist->lock); | ||||
/*DBG_FUNC("OUT\n");*/ | /* DBG_FUNC("OUT\n");*/ | ||||
} | } | ||||
/* | /* | ||||
Context not available. | |||||
{ | { | ||||
uint32_t elem = INVALID_ELEM; | uint32_t elem = INVALID_ELEM; | ||||
/*DBG_FUNC("IN\n");*/ | /* DBG_FUNC("IN\n");*/ | ||||
OS_ACQUIRE_SPINLOCK(&taglist->lock); | OS_ACQUIRE_SPINLOCK(&taglist->lock); | ||||
Context not available. | |||||
OS_RELEASE_SPINLOCK(&taglist->lock); | OS_RELEASE_SPINLOCK(&taglist->lock); | ||||
/*DBG_FUNC("OUT got %d\n", elem);*/ | /* DBG_FUNC("OUT got %d\n", elem);*/ | ||||
return elem; | return elem; | ||||
} | } | ||||
Context not available. | |||||
{ | { | ||||
int ret = PQI_STATUS_SUCCESS; | int ret = PQI_STATUS_SUCCESS; | ||||
int i = 0; | int i = 0; | ||||
DBG_FUNC("IN\n"); | DBG_FUNC("IN\n"); | ||||
taglist->max_elem = max_elem; | taglist->max_elem = max_elem; | ||||
Context not available. | |||||
taglist->head = 0; | taglist->head = 0; | ||||
taglist->tail = 0; | taglist->tail = 0; | ||||
taglist->elem_array = os_mem_alloc(softs, | taglist->elem_array = os_mem_alloc(softs, | ||||
(max_elem * sizeof(uint32_t))); | (max_elem * sizeof(uint32_t))); | ||||
if (!(taglist->elem_array)) { | if (!(taglist->elem_array)) { | ||||
DBG_FUNC("Unable to allocate memory for taglist\n"); | DBG_FUNC("Unable to allocate memory for taglist\n"); | ||||
ret = PQI_STATUS_FAILURE; | ret = PQI_STATUS_FAILURE; | ||||
goto err_out; | goto err_out; | ||||
} | } | ||||
os_strlcpy(taglist->lockname, "tag_lock", LOCKNAME_SIZE); | os_strlcpy(taglist->lockname, "tag_lock", LOCKNAME_SIZE); | ||||
ret = os_init_spinlock(softs, &taglist->lock, taglist->lockname); | ret = os_init_spinlock(softs, &taglist->lock, taglist->lockname); | ||||
if(ret){ | if(ret){ | ||||
DBG_ERR("tag lock initialization failed\n"); | DBG_ERR("tag lock initialization failed\n"); | ||||
taglist->lockcreated=false; | taglist->lockcreated=false; | ||||
goto err_lock; | goto err_lock; | ||||
} | } | ||||
taglist->lockcreated = true; | taglist->lockcreated = true; | ||||
/* indices 1 to max_elem are considered as valid tags */ | /* indices 1 to max_elem are considered as valid tags */ | ||||
for (i=1; i <= max_elem; i++) { | for (i=1; i <= max_elem; i++) { | ||||
softs->rcb[i].tag = INVALID_ELEM; | softs->rcb[i].tag = INVALID_ELEM; | ||||
pqisrc_put_tag(taglist, i); | pqisrc_put_tag(taglist, i); | ||||
} | } | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
return ret; | return ret; | ||||
err_lock: | err_lock: | ||||
os_mem_free(softs, (char *)taglist->elem_array, | os_mem_free(softs, (char *)taglist->elem_array, | ||||
(taglist->max_elem * sizeof(uint32_t))); | (taglist->max_elem * sizeof(uint32_t))); | ||||
taglist->elem_array = NULL; | taglist->elem_array = NULL; | ||||
err_out: | err_out: | ||||
Context not available. | |||||
void pqisrc_destroy_taglist(pqisrc_softstate_t *softs, pqi_taglist_t *taglist) | void pqisrc_destroy_taglist(pqisrc_softstate_t *softs, pqi_taglist_t *taglist) | ||||
{ | { | ||||
DBG_FUNC("IN\n"); | DBG_FUNC("IN\n"); | ||||
os_mem_free(softs, (char *)taglist->elem_array, | os_mem_free(softs, (char *)taglist->elem_array, | ||||
(taglist->max_elem * sizeof(uint32_t))); | (taglist->max_elem * sizeof(uint32_t))); | ||||
taglist->elem_array = NULL; | taglist->elem_array = NULL; | ||||
if(taglist->lockcreated==true){ | if(taglist->lockcreated==true){ | ||||
os_uninit_spinlock(&taglist->lock); | os_uninit_spinlock(&taglist->lock); | ||||
taglist->lockcreated = false; | taglist->lockcreated = false; | ||||
} | } | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
} | } | ||||
#else /* LOCKFREE_STACK */ | #else /* LOCKFREE_STACK */ | ||||
/* | /* | ||||
* Initialize circular queue implementation of tag list. | * Initialize circular queue implementation of tag list. | ||||
Context not available. | |||||
{ | { | ||||
int ret = PQI_STATUS_SUCCESS; | int ret = PQI_STATUS_SUCCESS; | ||||
int index = 0; | int index = 0; | ||||
DBG_FUNC("IN\n"); | DBG_FUNC("IN\n"); | ||||
/* indices 1 to max_elem are considered as valid tags */ | /* indices 1 to max_elem are considered as valid tags */ | ||||
stack->num_elements = max_elem + 1; | stack->max_elem = max_elem + 1; | ||||
stack->head.data = 0; | stack->head.data = 0; | ||||
DBG_INFO("Stack head address :%p\n",&stack->head); | DBG_INFO("Stack head address :%p\n",&stack->head); | ||||
/*Allocate memory for stack*/ | /*Allocate memory for stack*/ | ||||
stack->next_index_array = (uint32_t*)os_mem_alloc(softs, | stack->next_index_array = (uint32_t*)os_mem_alloc(softs, | ||||
(stack->num_elements * sizeof(uint32_t))); | (stack->max_elem * sizeof(uint32_t))); | ||||
if (!(stack->next_index_array)) { | if (!(stack->next_index_array)) { | ||||
DBG_ERR("Unable to allocate memory for stack\n"); | DBG_ERR("Unable to allocate memory for stack\n"); | ||||
ret = PQI_STATUS_FAILURE; | ret = PQI_STATUS_FAILURE; | ||||
goto err_out; | goto err_out; | ||||
} | } | ||||
/* push all the entries to the stack */ | /* push all the entries to the stack */ | ||||
for (index = 1; index < stack->num_elements ; index++) { | for (index = 1; index < stack->max_elem ; index++) { | ||||
softs->rcb[index].tag = INVALID_ELEM; | softs->rcb[index].tag = INVALID_ELEM; | ||||
pqisrc_put_tag(stack, index); | pqisrc_put_tag(stack, index); | ||||
} | } | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
return ret; | return ret; | ||||
err_out: | err_out: | ||||
Context not available. | |||||
void pqisrc_destroy_taglist(pqisrc_softstate_t *softs, lockless_stack_t *stack) | void pqisrc_destroy_taglist(pqisrc_softstate_t *softs, lockless_stack_t *stack) | ||||
{ | { | ||||
DBG_FUNC("IN\n"); | DBG_FUNC("IN\n"); | ||||
/* de-allocate stack memory */ | /* de-allocate stack memory */ | ||||
if (stack->next_index_array) { | if (stack->next_index_array) { | ||||
os_mem_free(softs,(char*)stack->next_index_array, | os_mem_free(softs,(char*)stack->next_index_array, | ||||
(stack->num_elements * sizeof(uint32_t))); | (stack->max_elem * sizeof(uint32_t))); | ||||
stack->next_index_array = NULL; | stack->next_index_array = NULL; | ||||
} | } | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
} | } | ||||
Context not available. | |||||
*/ | */ | ||||
void pqisrc_put_tag(lockless_stack_t *stack, uint32_t index) | void pqisrc_put_tag(lockless_stack_t *stack, uint32_t index) | ||||
{ | { | ||||
union head_list cur_head, new_head; | union head_list cur_head, new_head; | ||||
DBG_FUNC("IN\n"); | DBG_FUNC("IN\n"); | ||||
DBG_INFO("push tag :%d\n",index); | DBG_INFO("push tag :%d\n",index); | ||||
if ( index >= stack->num_elements ) { | if (index >= stack->max_elem) { | ||||
ASSERT(false); | ASSERT(false); | ||||
DBG_ERR("Pushed Invalid index\n"); /* stack full */ | DBG_INFO("Pushed Invalid index\n"); /* stack full */ | ||||
return; | return; | ||||
} | } | ||||
if ( stack->next_index_array[index] != 0) { | if (stack->next_index_array[index] != 0) { | ||||
ASSERT(false); | ASSERT(false); | ||||
DBG_ERR("Index already present as tag in the stack\n"); | DBG_INFO("Index already present as tag in the stack\n"); | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
new_head.top.index = index; | new_head.top.index = index; | ||||
/* Create a link to the previous index */ | /* Create a link to the previous index */ | ||||
stack->next_index_array[index] = cur_head.top.index; | stack->next_index_array[index] = cur_head.top.index; | ||||
}while(OS_ATOMIC64_CAS(&stack->head.data,cur_head.data,new_head.data) | }while(!os_atomic64_cas(&stack->head.data,cur_head.data,new_head.data)); | ||||
!= cur_head.data); | stack->num_elem++; | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
return; | return; | ||||
} | } | ||||
Context not available. | |||||
new_head.top.seq_no = cur_head.top.seq_no + 1; | new_head.top.seq_no = cur_head.top.seq_no + 1; | ||||
/* update the index at the top of the stack with the next index */ | /* update the index at the top of the stack with the next index */ | ||||
new_head.top.index = stack->next_index_array[cur_head.top.index]; | new_head.top.index = stack->next_index_array[cur_head.top.index]; | ||||
}while(OS_ATOMIC64_CAS(&stack->head.data,cur_head.data,new_head.data) | }while(!os_atomic64_cas(&stack->head.data,cur_head.data,new_head.data)); | ||||
!= cur_head.data); | |||||
stack->next_index_array[cur_head.top.index] = 0; | stack->next_index_array[cur_head.top.index] = 0; | ||||
stack->num_elem--; | |||||
DBG_INFO("pop tag: %d\n",cur_head.top.index); | DBG_INFO("pop tag: %d\n",cur_head.top.index); | ||||
DBG_FUNC("OUT\n"); | DBG_FUNC("OUT\n"); | ||||
Context not available. |