Beispiel #1
0
void user_process_init(void){
	//unsigned char err=0;
	UINT32 *stkA, *stkB;
	process_control_block_t *ret;

	stkA=(unsigned long *)os_mem_alloc(PROC_STACK_SIZE);
	stkB=(unsigned long *)os_mem_alloc(PROC_STACK_SIZE);

	

	process_create(procIdA, 1, ret, user_process_a, stkA);
	process_create(procIdB, 2, ret, user_process_b, stkB);
	//current=idle->next;
}
int tls_session_init(tls_handle_t *h, int sockfd,
		     const tls_init_config_t *cfg)
{
	int status;
	tls_session_t *s;

	tls_d("Session init");

	ASSERT(h != NULL);
	ASSERT(sockfd >= 0);
	ASSERT(cfg != NULL);

	s = os_mem_alloc(sizeof(tls_session_t));
	if (!s) {
		tls_e("No memory for tls session");
		return -WM_E_NOMEM;
	}

	memset(s, 0x00, sizeof(tls_session_t));

	if (cfg->flags & TLS_SERVER_MODE)
		status = _tls_session_init_server(s, cfg);
	else
		status = _tls_session_init_client(s, sockfd, cfg);
	if (status != WM_SUCCESS) {
		os_mem_free(s);
		return status;
	}

	*h = (tls_handle_t) s;
	return WM_SUCCESS;
}
Beispiel #3
0
void sem_debug_add(const xSemaphoreHandle handle, const char *name,
		   bool is_semaphore)
{
	int temp, i;
	if (sem_mutex) {
		temp = os_mutex_get(&sem_mutex, OS_WAIT_FOREVER);
		if (temp == -WM_FAIL) {
			wmprintf("[sem-dbg] Failed to get sem-mutex\r\n");
			return;
		}
	}
	for (i = 0;  i < MAX_SEM_INFO_BUF; i++) {
		if (semdbg[i].x_queue == 0) {
			if (name && strlen(name)) {
				semdbg[i].q_name =
					os_mem_alloc(strlen(name)+1);
				if (semdbg[i].q_name == NULL)
					break;
				strcpy(semdbg[i].q_name, name);
			}
			semdbg[i].x_queue = handle;
			semdbg[i].is_semaphore = is_semaphore;
			semcnt++;
			break;
		}
	}
	if (sem_mutex)
		os_mutex_put(&sem_mutex);
	return;
}
int tls_derive_key(tls_session_t *s, size_t len)
{
	struct tls_keys keys;
	unsigned char *rnd, *out;

	if (SSL_get_keys(s->ssl, &keys.master_key, &keys.master_key_len,
			&keys.server_random, &keys.server_random_len,
			&keys.client_random, &keys.client_random_len) ==
				SSL_SUCCESS) {

		out = os_mem_alloc(len);
		if (out == NULL) {
			tls_e("No memory for tls_derive_key");
			goto fail;
		}
		
		if (keys.master_key == NULL || keys.server_random ==NULL ||
			keys.client_random == NULL)
			goto fail;

		rnd = os_mem_alloc(keys.client_random_len + keys.server_random_len);
		if (rnd == NULL) {
			tls_e("No memory for rnd:: %d", keys.client_random_len + keys.server_random_len);
			goto fail;
		}

		memcpy(rnd, keys.client_random, keys.client_random_len);
		memcpy(rnd + keys.client_random_len, keys.server_random,
			keys.server_random_len);

		mrvl_tls_prf(keys.master_key, keys.master_key_len, 
		"client EAP encryption", rnd, keys.client_random_len + keys.server_random_len, out, len);

		memcpy(s->key_data, out, TLS_KEY_LEN);

		os_mem_free(rnd);
		os_mem_free(out);
		return WM_SUCCESS;
	}
	
fail:
	tls_e("EAP-TLS: Failed to derive key");
	return -WM_FAIL;

} 
Beispiel #5
0
void timer_list_init(void){
	timerList = (os_timer_t *)os_mem_alloc((UINT8)sizeof(os_timer_t));
	if(!timerList){
		UARTprintf("Error:create timer list failed!\n");
	}

	timerList->next = timerList;
	timerList->prev = timerList;
}
static void *cyassl_mem_malloc(size_t size)
{
	void *buffer = os_mem_alloc(size);
	if (!buffer) {
		tls_e("failed to allocate mem for CyaSSL");
		return NULL;
	}

	return buffer;
}
Beispiel #7
0
static int rx_buf_init(sspdev_data_t *ssp_data_p)
{
	ssp_data_p->rx_ringbuf.rd_idx = 0;
	ssp_data_p->rx_ringbuf.wr_idx = 0;
	ssp_data_p->rx_ringbuf.buf_p = os_mem_alloc
		(GET_RX_BUF_SIZE(ssp_data_p));
	if (!ssp_data_p->rx_ringbuf.buf_p)
		return -WM_FAIL;
	return WM_SUCCESS;
}
Beispiel #8
0
void *wifi_malloc_eventbuf(int size)
{
	void *ptr = os_mem_alloc(size);

	if (ptr) {
		w_mem_d("[evtbuf] Alloc: A: %p S: %d",
			ptr, size);
	} else {
		w_mem_e("[evtbuf] Alloc: S: %d FAILED", size);
	}

	return ptr;
}
Beispiel #9
0
static void os_dump_seminfo()
{
	int i = 0, temp;
	const unsigned int *px_queue = NULL;
	unsigned int *list;
	char *pc_write_buffer = os_mem_alloc(MAX_WAITER_BUF);
	if (pc_write_buffer == NULL)
		return;

	if (sem_mutex) {
		temp = os_mutex_get(&sem_mutex, OS_WAIT_FOREVER);
		if (temp == -WM_FAIL) {
			wmprintf("[sem-dbg] Failed to get sem-mutex\r\n");
			os_mem_free(pc_write_buffer);
			return;
		}
	}

	if (semcnt > 0) {
		wmprintf("%-32s%-8s%-50s%s", "Name", "Count", "Waiters",
			 "Type\r\n");
	}

	for (i = 0; i < MAX_SEM_INFO_BUF; i++) {
		if (semdbg[i].x_queue == 0)
			continue;
		if (semdbg[i].q_name && isascii(semdbg[i].q_name[0])) {
			wmprintf("%-32s", semdbg[i].q_name);
		} else {
			wmprintf("%-32s", "-");
		}
		px_queue = semdbg[i].x_queue;
		wmprintf("%-8d",
			 os_semaphore_getcount(&semdbg[i].x_queue));
		vGetWaiterListFromHandle(px_queue, &list);
		vGetTaskNamesInList((signed char *) pc_write_buffer,
				    MAX_WAITER_BUF - 1,
				    (const unsigned int *)list);
		pc_write_buffer[MAX_WAITER_BUF - 1] = '\0';
		wmprintf("%-50s ", pc_write_buffer);
		(semdbg[i].is_semaphore == 0) ?
			wmprintf("q") :
			wmprintf("s");
		wmprintf("\r\n");
	}
	if (sem_mutex)
		os_mutex_put(&sem_mutex);
	os_mem_free(pc_write_buffer);
}
Beispiel #10
0
void *wps_mem_malloc(size_t size)
{
	void *buffer_ptr = 0;

	if (size == 0)
		return NULL;

	buffer_ptr = os_mem_alloc(size);

	if (!buffer_ptr) {
		WPS_LOG("Failed to allocate mem: Size: %d", size);
		return NULL;
	}

	return buffer_ptr;
}
/*---------------------------------------------------------------------*/
__task void task3(void){

		void *pointer;
		pointer = os_mem_alloc(box_mem);
		
		if (pointer == NULL)
			printf("Not enough memory\n");
		else 
			printf("malloc'd(): %d \n", pointer);
		os_dly_wait(50);
		if(os_mem_free(box_mem, pointer) == OS_R_OK){
			printf("dealloc'd(): OS_R_OK \n");
		}else{
			printf("dealloc'd(): OS_R_NOK \n");
		}
		os_dly_wait(50);
		os_tsk_delete_self(); 
}
Beispiel #12
0
mlan_status wrapper_moal_malloc(IN t_void *pmoal_handle, IN t_u32 size,
				IN t_u32 flag, OUT t_u8 **ppbuf)
{
	*ppbuf = os_mem_alloc(size);

#ifdef DEBUG_11N_ALLOC

#endif /* DEBUG_11N_ALLOC */

	if (*ppbuf) {
		w_mem_d("[mlan]: Alloc: A: %p S: %d", *ppbuf, size);
		return MLAN_STATUS_SUCCESS;
	} else {
		w_mem_e("[mlan] Alloc: S: %d FAILED", size);
		/*
		 * fixme: check if MLAN_STATUS_SUCCESS is to be returned in
		 * spite of the status failure.
		 */
		return MLAN_STATUS_FAILURE;
	}
}
Beispiel #13
0
/*
 * We only save the params to be used later when BSS is (re-)started.
 */
int wifi_uap_set_domain_params(wifi_domain_param_t *dp)
{
	if (!dp)
		return -WM_E_INVAL;

	if (wm_wifi.dp)
		wuap_w("Overwriting previous configuration");

	/*
	 * We have domain information from caller. Allocate tlv, fill it
	 * up and store as pointer in global wifi structure. It will be
	 * used later by the uap start code.
	 */
	int sz = sizeof(MrvlIEtypes_DomainParamSet_t) +
		(sizeof(IEEEtypes_SubbandSet_t) * dp->no_of_sub_band);
	MrvlIEtypes_DomainParamSet_t *n_dp = os_mem_alloc(sz);
	if (!n_dp)
		return -WM_E_NOMEM;

	n_dp->header.type = TLV_TYPE_DOMAIN;
	n_dp->header.len = sizeof(MrvlIEtypes_DomainParamSet_t) -
		4 + (dp->no_of_sub_band *
		     sizeof(IEEEtypes_SubbandSet_t));

	memcpy(n_dp->country_code, dp->country_code, COUNTRY_CODE_LEN);

	wifi_sub_band_set_t *is = dp->sub_band;
	IEEEtypes_SubbandSet_t *s = n_dp->sub_band;
	int i;
	for (i = 0; i < dp->no_of_sub_band; i++) {
		s[i].first_chan = is[i].first_chan;
		s[i].no_of_chan = is[i].no_of_chan;
		s[i].max_tx_pwr = is[i].max_tx_pwr;
	}

	/* Store for use later */
	wuap_d("Saved domain info for later use");
	wm_wifi.dp = n_dp;
	return 0;
}
/*
 * Write all data in the adapter's battery-backed cache to
 * storage.
 */
int pqisrc_flush_cache( pqisrc_softstate_t *softs,
			enum pqisrc_flush_cache_event_type event_type)
{
	int rval = PQI_STATUS_SUCCESS;
	pqisrc_raid_req_t request;
	pqisrc_bmic_flush_cache_t *flush_buff = NULL;

	DBG_FUNC("IN\n");

	if (pqisrc_ctrl_offline(softs))
		return PQI_STATUS_FAILURE;

	flush_buff = os_mem_alloc(softs, sizeof(pqisrc_bmic_flush_cache_t)); 
	if (!flush_buff) {
		DBG_ERR("Failed to allocate memory for flush cache params\n");
		rval = PQI_STATUS_FAILURE;
		return rval;
	}

	flush_buff->halt_event = event_type;

	memset(&request, 0, sizeof(request));

	rval = pqisrc_build_send_raid_request(softs, &request, flush_buff,
			sizeof(*flush_buff), SA_CACHE_FLUSH, 0,
			(uint8_t *)RAID_CTLR_LUNID, NULL);
	if (rval) {
		DBG_ERR("error in build send raid req ret=%d\n", rval);
	}

	if (flush_buff)
		os_mem_free(softs, (void *)flush_buff,
			sizeof(pqisrc_bmic_flush_cache_t));

	DBG_FUNC("OUT\n");

	return rval;
}
Beispiel #15
0
/* This task configures Evrythng client and connects to the Evrythng cloud  */
static void evrythng_task()
{
    psm_handle_t handle;
    int rc;

    if ((rc = psm_open(&handle, "evrythng")) != 0)
    {
        wmprintf("psm_open failed with: %d (Is the module name registered?)\n\r", rc);
        goto exit;
    }

    char api_key[128];
    if (psm_get(&handle, "api_key", api_key, 128) == 0)
    {
        wmprintf("api_key: %s\n\r", api_key);
    }
    else
    {
        wmprintf("api_key doesn't exist\n\r");
        goto exit;
    }

    char thng_id_buf[64];
    if (psm_get(&handle, "thng_id", thng_id_buf, 64) == 0)
    {
        if (thng_id != NULL)
        {
            os_mem_free(thng_id);
        }
        thng_id = (char*)os_mem_alloc((strlen(thng_id_buf)+1)*sizeof(char));
        strcpy(thng_id, thng_id_buf);
        wmprintf("thng_id: %s\n\r", thng_id);
    }
    else
    {
        wmprintf("thng_id doesn't exist\n\r");
        goto exit;
    }

    char url_buf[64];
    if (psm_get(&handle, "url", url_buf, 64) == 0)
    {
        wmprintf("Evrythng URL: %s\n\r", url_buf);
    }
    else
    {
        wmprintf("Evrythng URL doesn't exist\n\r");
        goto exit;
    }
    psm_close(&handle);

    EvrythngInitHandle(&evt_handle);
    EvrythngSetUrl(evt_handle, url_buf);
    EvrythngSetKey(evt_handle, api_key);
    EvrythngSetLogCallback(evt_handle, log_callback);
    EvrythngSetConnectionCallbacks(evt_handle, on_connection_lost, on_connection_restored);

    while (EvrythngConnect(evt_handle) != EVRYTHNG_SUCCESS)
    {
        wmprintf("Retry\n\r");
        os_thread_sleep(os_msec_to_ticks(5000));
    }
    wmprintf("Connected\n\r");

    os_semaphore_create_counting(&button1_sem, "button1_sem", 1000, 0);
    os_semaphore_create_counting(&button2_sem, "button1_sem", 1000, 0);

    EvrythngSubThngAction(evt_handle, thng_id, "_led1", 0, action_led_callback);
    EvrythngSubThngAction(evt_handle, thng_id, "_led2", 0, action_led_callback);

    os_thread_create(&button1_thread, "button1_task", button_task, (void*)button_1, &button_stack, OS_PRIO_3);
    os_thread_create(&button2_thread, "button2_task", button_task, (void*)button_2, &button_stack, OS_PRIO_3);

exit:
    os_thread_self_complete(0);
}
/*
 * Get the PQI configuration table parameters.
 * Currently using for heart-beat counter scratch-pad register.
 */
int pqisrc_process_config_table(pqisrc_softstate_t *softs)
{
	int ret = PQI_STATUS_FAILURE;
	uint32_t config_table_size;
	uint32_t section_off;
	uint8_t *config_table_abs_addr;
	struct pqi_conf_table *conf_table;
	struct pqi_conf_table_section_header *section_hdr;

	config_table_size = softs->pqi_cap.conf_tab_sz;

	if (config_table_size < sizeof(*conf_table) ||
		config_table_size > PQI_CONF_TABLE_MAX_LEN) {
		DBG_ERR("Invalid PQI conf table length of %u\n",
			config_table_size);
		return ret;
	}

	conf_table = os_mem_alloc(softs, config_table_size);
	if (!conf_table) {
		DBG_ERR("Failed to allocate memory for PQI conf table\n");
		return ret;
	}

	config_table_abs_addr = (uint8_t *)(softs->pci_mem_base_vaddr +
					softs->pqi_cap.conf_tab_off);

	PCI_MEM_GET_BUF(softs, config_table_abs_addr,
			softs->pqi_cap.conf_tab_off,
			(uint8_t*)conf_table, config_table_size);


	if (memcmp(conf_table->sign, PQI_CONF_TABLE_SIGNATURE,
			sizeof(conf_table->sign)) != 0) {
		DBG_ERR("Invalid PQI config signature\n");
		goto out;
	}

	section_off = LE_32(conf_table->first_section_off);

	while (section_off) {

		if (section_off+ sizeof(*section_hdr) >= config_table_size) {
			DBG_ERR("PQI config table section offset (%u) beyond \
			end of config table (config table length: %u)\n",
					section_off, config_table_size);
			break;
		}
		
		section_hdr = (struct pqi_conf_table_section_header *)((uint8_t *)conf_table + section_off);
		
		switch (LE_16(section_hdr->section_id)) {
		case PQI_CONF_TABLE_SECTION_GENERAL_INFO:
		case PQI_CONF_TABLE_SECTION_FIRMWARE_FEATURES:
		case PQI_CONF_TABLE_SECTION_FIRMWARE_ERRATA:
		case PQI_CONF_TABLE_SECTION_DEBUG:
		break;
		case PQI_CONF_TABLE_SECTION_HEARTBEAT:
		softs->heartbeat_counter_off = softs->pqi_cap.conf_tab_off +
						section_off +
						offsetof(struct pqi_conf_table_heartbeat,
						heartbeat_counter);
		softs->heartbeat_counter_abs_addr = (uint64_t *)(softs->pci_mem_base_vaddr +
							softs->heartbeat_counter_off);
		ret = PQI_STATUS_SUCCESS;
		break;
		default:
		DBG_ERR("unrecognized PQI config table section ID: 0x%x\n",
					LE_16(section_hdr->section_id));
		break;
		}
		section_off = LE_16(section_hdr->next_section_off);
	}
/*
 * Request the adapter to get PQI capabilities supported.
 */
static int pqisrc_report_pqi_capability(pqisrc_softstate_t *softs)
{
	int ret = PQI_STATUS_SUCCESS;
	
	DBG_FUNC("IN\n");

	gen_adm_req_iu_t	admin_req;
	gen_adm_resp_iu_t 	admin_resp;
	dma_mem_t		pqi_cap_dma_buf;
	pqi_dev_cap_t 		*capability = NULL;
	pqi_iu_layer_desc_t	*iu_layer_desc = NULL;

	/* Allocate Non DMA memory */
	capability = os_mem_alloc(softs, sizeof(*capability));
	if (!capability) {
		DBG_ERR("Failed to allocate memory for capability\n");
		ret = PQI_STATUS_FAILURE;
		goto err_out;
	}

	memset(&admin_req, 0, sizeof(admin_req));
	memset(&admin_resp, 0, sizeof(admin_resp));

	memset(&pqi_cap_dma_buf, 0, sizeof(struct dma_mem));
	pqi_cap_dma_buf.tag = "pqi_cap_buf";
	pqi_cap_dma_buf.size = REPORT_PQI_DEV_CAP_DATA_BUF_SIZE;
	pqi_cap_dma_buf.align = PQISRC_DEFAULT_DMA_ALIGN;

	ret = os_dma_mem_alloc(softs, &pqi_cap_dma_buf);
	if (ret) {
		DBG_ERR("Failed to allocate capability DMA buffer : %d\n", ret);
		goto err_dma_alloc;
	}
	
	admin_req.fn_code = PQI_FUNCTION_REPORT_DEV_CAP;
	admin_req.req_type.general_func.buf_size = pqi_cap_dma_buf.size;
	admin_req.req_type.general_func.sg_desc.length = pqi_cap_dma_buf.size;
	admin_req.req_type.general_func.sg_desc.addr = pqi_cap_dma_buf.dma_addr;
	admin_req.req_type.general_func.sg_desc.type =	SGL_DESCRIPTOR_CODE_DATA_BLOCK;

	ret = pqisrc_submit_admin_req(softs, &admin_req, &admin_resp);
	if( PQI_STATUS_SUCCESS == ret) {
                memcpy(capability,
			pqi_cap_dma_buf.virt_addr,
			pqi_cap_dma_buf.size);
	} else {
		DBG_ERR("Failed to send admin req report pqi device capability\n");
		goto err_admin_req;
		
	}

	softs->pqi_dev_cap.max_iqs = capability->max_iqs;
	softs->pqi_dev_cap.max_iq_elements = capability->max_iq_elements;
	softs->pqi_dev_cap.max_iq_elem_len = capability->max_iq_elem_len;
	softs->pqi_dev_cap.min_iq_elem_len = capability->min_iq_elem_len;
	softs->pqi_dev_cap.max_oqs = capability->max_oqs;
	softs->pqi_dev_cap.max_oq_elements = capability->max_oq_elements;
	softs->pqi_dev_cap.max_oq_elem_len = capability->max_oq_elem_len;
	softs->pqi_dev_cap.intr_coales_time_granularity = capability->intr_coales_time_granularity;

	iu_layer_desc = &capability->iu_layer_desc[PQI_PROTOCOL_SOP];
	softs->max_ib_iu_length_per_fw = iu_layer_desc->max_ib_iu_len;
	softs->ib_spanning_supported = iu_layer_desc->ib_spanning_supported;
	softs->ob_spanning_supported = iu_layer_desc->ob_spanning_supported;

	DBG_INIT("softs->pqi_dev_cap.max_iqs: %d\n", softs->pqi_dev_cap.max_iqs);
	DBG_INIT("softs->pqi_dev_cap.max_iq_elements: %d\n", softs->pqi_dev_cap.max_iq_elements);
	DBG_INIT("softs->pqi_dev_cap.max_iq_elem_len: %d\n", softs->pqi_dev_cap.max_iq_elem_len);
	DBG_INIT("softs->pqi_dev_cap.min_iq_elem_len: %d\n", softs->pqi_dev_cap.min_iq_elem_len);
	DBG_INIT("softs->pqi_dev_cap.max_oqs: %d\n", softs->pqi_dev_cap.max_oqs);
	DBG_INIT("softs->pqi_dev_cap.max_oq_elements: %d\n", softs->pqi_dev_cap.max_oq_elements);
	DBG_INIT("softs->pqi_dev_cap.max_oq_elem_len: %d\n", softs->pqi_dev_cap.max_oq_elem_len);
	DBG_INIT("softs->pqi_dev_cap.intr_coales_time_granularity: %d\n", softs->pqi_dev_cap.intr_coales_time_granularity);
	DBG_INIT("softs->max_ib_iu_length_per_fw: %d\n", softs->max_ib_iu_length_per_fw);
	DBG_INIT("softs->ib_spanning_supported: %d\n", softs->ib_spanning_supported);
	DBG_INIT("softs->ob_spanning_supported: %d\n", softs->ob_spanning_supported);
	

	os_mem_free(softs, (void *)capability,
		    REPORT_PQI_DEV_CAP_DATA_BUF_SIZE);
	os_dma_mem_free(softs, &pqi_cap_dma_buf);

	DBG_FUNC("OUT\n");
	return ret;

err_admin_req:
	os_dma_mem_free(softs, &pqi_cap_dma_buf);
err_dma_alloc:
	if (capability)
		os_mem_free(softs, (void *)capability,
			    REPORT_PQI_DEV_CAP_DATA_BUF_SIZE);
err_out:
	DBG_FUNC("failed OUT\n");
	return PQI_STATUS_FAILURE;
}
/*
 * Allocate memory for rcb and SG descriptors.
 */
static int pqisrc_allocate_rcb(pqisrc_softstate_t *softs)
{
	int ret = PQI_STATUS_SUCCESS;
	int i = 0;
	uint32_t num_req = 0;
	uint32_t sg_buf_size = 0;
	uint64_t alloc_size = 0;
	rcb_t *rcb = NULL;
	rcb_t *prcb = NULL;
	DBG_FUNC("IN\n");

	/* Set maximum outstanding requests */
	/* The valid tag values are from 1, 2, ..., softs->max_outstanding_io
	 * The rcb will be accessed by using the tag as index
	 * * As 0 tag index is not used, we need to allocate one extra.
	 */
	softs->max_outstanding_io = softs->pqi_cap.max_outstanding_io;
	num_req = softs->max_outstanding_io + 1;
	DBG_INIT("Max Outstanding IO reset to %d\n", num_req);

	alloc_size = num_req * sizeof(rcb_t);

	/* Allocate Non DMA memory */
	rcb = os_mem_alloc(softs, alloc_size);
	if (!rcb) {
		DBG_ERR("Failed to allocate memory for rcb\n");
		ret = PQI_STATUS_FAILURE;
		goto err_out;
	}
	softs->rcb = rcb;
	
	/* Allocate sg dma memory for sg chain  */
	sg_buf_size = softs->pqi_cap.max_sg_elem *
			sizeof(sgt_t);

	prcb = &softs->rcb[1];
	/* Initialize rcb */
	for(i=1; i < num_req; i++) {
		char tag[15];
		sprintf(tag, "sg_dma_buf%d", i);
		softs->sg_dma_desc[i].tag = tag;
		softs->sg_dma_desc[i].size = sg_buf_size;
		softs->sg_dma_desc[i].align = PQISRC_DEFAULT_DMA_ALIGN;

		ret = os_dma_mem_alloc(softs, &softs->sg_dma_desc[i]);
		if (ret) {
			DBG_ERR("Failed to Allocate sg desc %d\n", ret);
			ret = PQI_STATUS_FAILURE;
			goto error;
		}
		prcb->sg_chain_virt = (sgt_t *)(softs->sg_dma_desc[i].virt_addr);
		prcb->sg_chain_dma = (dma_addr_t)(softs->sg_dma_desc[i].dma_addr);
		prcb ++;
	}

	DBG_FUNC("OUT\n");
	return ret;
error:
	pqisrc_free_rcb(softs, i);
err_out:
	DBG_FUNC("failed OUT\n");
	return ret;
}
int httpd_handle_file(httpd_request_t *req_p, struct fs *fs)
{
	const char *anchor = "/";
	char tmp[HTTPD_MAX_URI_LENGTH+1];
	const char *encoding = NULL;
	char *msg_in, *ptr, *type = NULL;
	int err, msg_in_len = HTTPD_MAX_MESSAGE - 1, conn = req_p->sock;
	int ret;

	msg_in = os_mem_alloc(HTTPD_MAX_MESSAGE + 2);
	if (!msg_in) {
		httpd_e("Failed to allocate memory for file handling");
		/* Check what needs to be returned */
		return -WM_FAIL;
	}
	memset(msg_in, 0, HTTPD_MAX_MESSAGE + 2);

	SYS_FILE_DECL;

	if (!fs) {
		/* The filesystem wasn't mounted properly */
		httpd_send_hdr_from_str(conn, http_header_404,
					CONTENT_TYPE_PLAIN, encoding,
					NO_CACHE_HEADERS, UNUSED_PARAM);
		httpd_send_default_headers(conn,
				req_p->wsgi->hdr_fields);
		httpd_send_crlf(conn);
		httpd_send(conn, FILE_NOT_FOUND, sizeof(FILE_NOT_FOUND));
		ret = WM_SUCCESS;
		goto out;
	}
	struct ftfs_super *f_super = fs_to_ftfs_sb(fs);

	/* Ensure that the anchor is the first part of the filename */
	ptr = strstr(req_p->filename, anchor);
	if (ptr == NULL ||
	    ptr != req_p->filename) {
		httpd_d("No anchor in filename\r\n");
		ret = httpd_send_error(conn, HTTP_500);
		goto out;
	}

	/* Zap the anchor from the filename */
	ptr = req_p->filename + strlen(anchor);
	err = 0;
	/* anchors are only across directory boundaries */
	if (*ptr != '/')
		req_p->filename[err++] = '/';

	while (*ptr && (*ptr != '?')) {
		req_p->filename[err] = *ptr;
		ptr++;
		err++;
	}
	req_p->filename[err] = '\0';

	/* "/" implies a request for index.html */
	if (strncmp(req_p->filename, "/", 2) == 0) {
		strncpy(req_p->filename, http_index_html,
			sizeof(http_index_html));
	}

	/* Find if .gz version exists for file, if it is then serve that */
	type = strrchr(req_p->filename, ISO_period);
	if (type) {
		strncpy(tmp, req_p->filename, sizeof(tmp));
		strncat(tmp, ".gz", 3);
		httpd_d("Look for gz file if it exists: %s\r\n", tmp);
		if (htsys_file_open(fs, tmp, sys_filep) == WM_SUCCESS) {
			/* Gzipped version exists, serve that */
			httpd_d("Serve gzipped file\r\n");
			strncpy(req_p->filename, tmp, HTTPD_MAX_URI_LENGTH + 1);
			encoding = ".gz";
			htsys_close(fs, sys_filep);
		}
	}

	ret = httpd_parse_hdr_tags(req_p, conn, msg_in, msg_in_len);
	if (ret < 0) {
		httpd_d("Parsing headers failed \r\n");
		ret = httpd_send_error(conn, HTTP_500);
		goto out;
	}

	/* It is not a WSGI, check to see if the file exists */
	if (htsys_file_open(fs, req_p->filename, sys_filep) == -WM_FAIL) {
		httpd_w("file not found: %s\r\n", req_p->filename);

		ret = httpd_send_hdr_from_str(conn, http_header_404,
					      type, encoding, NO_CACHE_HEADERS,
					      UNUSED_PARAM);
		httpd_send_default_headers(conn,
				req_p->wsgi->hdr_fields);
		httpd_send_crlf(conn);
		if (ret != WM_SUCCESS)
			goto out;

		ret = htsys_file_open(fs, http_404_html, sys_filep);
		if (ret == WM_SUCCESS) {
			ret = httpd_send_file(fs, conn, sys_filep);
			goto out;
		} else
			httpd_w("No local 404 file.  Sending empty 404"
			      " response.\r\n");
	} else {
		/* Ok, the file exists, is it a script html or just html */
		g_wm_stats.wm_hd_file++;
		if (req_p->if_none_match &&
		    (f_super->fs_crc32 == req_p->etag_val)) {
			/* We do not need the file handle now */
			htsys_close(fs, sys_filep);

			/* Send Not Modified header */

			/* Send header prologue */
			ret = httpd_send(conn, http_header_304_prologue,
					 strlen(http_header_304_prologue));
			if (ret != WM_SUCCESS)
				goto out;
			httpd_send_header(conn, "Server", "Marvell-WM");
			httpd_send_header(conn, "Connection", "Close");

			/* Send ETag */
			int len;
			const char *h = httpd_get_etag_hdr(req_p->etag_val,
							   &len);
			ret = httpd_send(conn, h, len);
			if (ret != WM_SUCCESS)
				goto out;
			/* Close the header */
			ret = httpd_send_crlf(conn);
			goto out;
		} else  {
			ret = httpd_send_hdr_from_str(conn, http_header_200,
						      type, encoding,
						      SEND_CACHE_HEADERS,
						      f_super->fs_crc32);
			httpd_send_default_headers(conn,
					req_p->wsgi->hdr_fields);
			httpd_send_crlf(conn);

			if (ret != WM_SUCCESS)
				goto out;
			ptr = strchr(req_p->filename, ISO_period);
			if (ptr != NULL && strncmp(ptr, http_shtml,
						   sizeof(http_shtml)
						   - 1) == 0) {
				httpd_d("Handling script: %s", req_p->filename);
				ret = handle_script(fs, req_p, conn,
						    sys_filep, msg_in);
				htsys_close(fs, sys_filep);
				if (ret != WM_SUCCESS) {
					httpd_d("Script failed\r\n");
					goto out;
				}
			} else {
				ret = httpd_send_file(fs, conn, sys_filep);
				if (ret != WM_SUCCESS)
					goto out;
			}
		}
	}
	ret = httpd_send_last_chunk(conn);
out:
	os_mem_free(msg_in);
	return ret;
}
/**
 * mu3d_hal_alloc_qmu_mem - allocate gpd and bd memory for all ep
 *
 */
void mu3d_hal_alloc_qmu_mem(void)
{
	DEV_UINT32 i, size;
	TGPD *ptr, *io_ptr;
	TBD *bptr, *io_bptr;

	for (i = 1; i <= MAX_QMU_EP; i++) {
		/* Allocate Tx GPD */
		size = sizeof(TGPD);
		size *= MAX_GPD_NUM;
		ptr = (TGPD *) os_mem_alloc(size);
		os_memset(ptr, 0, size);

		io_ptr = (TGPD *) dma_map_single(NULL, ptr, size, DMA_TO_DEVICE);
		/* io_ptr = (TGPD*)os_ioremap(os_virt_to_phys(ptr),size); */
		/* io_ptr = (TGPD*)(os_virt_to_phys(ptr)); */
		/* init_gpd_list(USB_RX,i,ptr,io_ptr,MAX_GPD_NUM); */
		init_gpd_list(USB_RX, i, ptr, io_ptr, MAX_GPD_NUM);
		Rx_gpd_end[i] = ptr;
		os_printk(K_DEBUG, "ALLOC RX GPD End [%d] Virtual Mem=%p, DMA addr=%p\n", i,
			  Rx_gpd_end[i], io_ptr);
		/* os_memset(Rx_gpd_end[i], 0 , sizeof(TGPD)); */
		TGPD_CLR_FLAGS_HWO(Rx_gpd_end[i]);
		Rx_gpd_head[i] = Rx_gpd_last[i] = Rx_gpd_end[i];
		os_printk(K_DEBUG, "RQSAR[%d]=%p\n", i,
			  (void *)mu3d_hal_gpd_virt_to_phys(Rx_gpd_end[i], USB_RX, i));

		/* Allocate Rx GPD */
		size = sizeof(TGPD);
		size += AT_GPD_EXT_LEN;
		size *= MAX_GPD_NUM;
		ptr = (TGPD *) os_mem_alloc(size);
		os_memset(ptr, 0, size);

		io_ptr = (TGPD *) dma_map_single(NULL, ptr, size, DMA_TO_DEVICE);
		/* io_ptr = (TGPD*)os_ioremap(os_virt_to_phys(ptr),size); */
		init_gpd_list(USB_TX, i, ptr, io_ptr, MAX_GPD_NUM);
		Tx_gpd_end[i] = ptr;
		os_printk(K_DEBUG, "ALLOC TX GPD End [%d] Virtual Mem=%p, DMA addr=%p\n", i,
			  Tx_gpd_end[i], io_ptr);
		/* os_memset(Tx_gpd_end[i], 0 , sizeof(TGPD)+AT_GPD_EXT_LEN); */
		TGPD_CLR_FLAGS_HWO(Tx_gpd_end[i]);
		Tx_gpd_head[i] = Tx_gpd_last[i] = Tx_gpd_end[i];
		os_printk(K_DEBUG, "TQSAR[%d]=%p\n", i,
			  (void *)mu3d_hal_gpd_virt_to_phys(Tx_gpd_end[i], USB_TX, i));

		/* Allocate Tx BD */
		size = (sizeof(TBD));
		size *= MAX_BD_NUM;
		bptr = (TBD *) os_mem_alloc(size);
		os_memset(bptr, 0, size);
		io_bptr = (TBD *) dma_map_single(NULL, bptr, size, DMA_TO_DEVICE);
		/* io_bptr = (TBD*)os_ioremap(os_virt_to_phys(bptr),size); */
		init_bd_list(USB_RX, i, bptr, io_bptr, MAX_BD_NUM);

		/* Allocate Rx BD */
		size = (sizeof(TBD));
		size += AT_BD_EXT_LEN;
		size *= MAX_BD_NUM;
		bptr = (TBD *) os_mem_alloc(size);
		os_memset(bptr, 0, size);
		io_bptr = (TBD *) dma_map_single(NULL, bptr, size, DMA_TO_DEVICE);
		/* io_bptr = (TBD*)os_ioremap(os_virt_to_phys(bptr),size); */
		init_bd_list(USB_TX, i, bptr, io_bptr, MAX_BD_NUM);
	}
}