2017-04-13 20:31:39 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* drivers/wireless/ieee80211/bcm43xxx/bcmf_sdpcm.c
|
2017-04-13 20:31:39 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-04-13 20:31:39 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-04-13 20:31:39 +02:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-04-13 20:31:39 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
2017-04-30 20:29:48 +02:00
|
|
|
#include <assert.h>
|
2017-04-13 20:31:39 +02:00
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
2020-02-01 08:17:32 +01:00
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
#include <stddef.h>
|
2017-04-16 11:28:08 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <queue.h>
|
2017-04-13 20:31:39 +02:00
|
|
|
|
|
|
|
#include "bcmf_sdio.h"
|
|
|
|
#include "bcmf_core.h"
|
|
|
|
#include "bcmf_sdpcm.h"
|
2017-04-23 22:17:43 +02:00
|
|
|
#include "bcmf_cdc.h"
|
2017-04-28 19:28:29 +02:00
|
|
|
#include "bcmf_bdc.h"
|
2017-04-23 22:17:43 +02:00
|
|
|
#include "bcmf_utils.h"
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
#include "bcmf_netdev.h"
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
#include "bcmf_sdio_regs.h"
|
2017-04-16 11:28:08 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2017-04-28 19:28:29 +02:00
|
|
|
#define SDPCM_CONTROL_CHANNEL 0 /* Control frame id */
|
|
|
|
#define SDPCM_EVENT_CHANNEL 1 /* Asynchronous event frame id */
|
|
|
|
#define SDPCM_DATA_CHANNEL 2 /* Data frame id */
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-07-27 02:43:12 +02:00
|
|
|
begin_packed_struct struct bcmf_sdpcm_header
|
2019-10-29 23:56:24 +01:00
|
|
|
{
|
|
|
|
uint16_t size;
|
|
|
|
uint16_t checksum;
|
|
|
|
uint8_t sequence;
|
|
|
|
uint8_t channel;
|
|
|
|
uint8_t next_length;
|
|
|
|
uint8_t data_offset;
|
|
|
|
uint8_t flow_control;
|
|
|
|
uint8_t credit;
|
|
|
|
uint16_t padding;
|
2021-07-27 02:43:12 +02:00
|
|
|
} end_packed_struct;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
static int bcmf_sdpcm_rxfail(FAR struct bcmf_sdio_dev_s *sbus, bool retry);
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
static int bcmf_sdpcm_process_header(FAR struct bcmf_sdio_dev_s *sbus,
|
2017-04-16 11:28:08 +02:00
|
|
|
struct bcmf_sdpcm_header *header);
|
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
int bcmf_sdpcm_rxfail(FAR struct bcmf_sdio_dev_s *sbus, bool retry)
|
2017-04-13 20:31:39 +02:00
|
|
|
{
|
|
|
|
/* issue abort command for F2 through F0 */
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
bcmf_write_reg(sbus, 0, SDIO_CCCR_IOABORT, 2);
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
bcmf_write_reg(sbus, 1, SBSDIO_FUNC1_FRAMECTRL, SFC_RF_TERM);
|
2017-04-13 20:31:39 +02:00
|
|
|
|
|
|
|
/* TODO Wait until the packet has been flushed (device/FIFO stable) */
|
|
|
|
|
|
|
|
if (retry)
|
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Send NAK to retry to read frame */
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
bcmf_write_sbregb(sbus,
|
|
|
|
CORE_BUS_REG(sbus->chip->core_base[SDIOD_CORE_ID],
|
2017-04-13 20:31:39 +02:00
|
|
|
tosbmailbox), SMB_NAK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
int bcmf_sdpcm_process_header(FAR struct bcmf_sdio_dev_s *sbus,
|
2017-04-13 20:31:39 +02:00
|
|
|
struct bcmf_sdpcm_header *header)
|
|
|
|
{
|
|
|
|
if (header->data_offset < sizeof(struct bcmf_sdpcm_header) ||
|
2017-04-16 11:28:08 +02:00
|
|
|
header->data_offset > header->size)
|
2017-04-13 20:31:39 +02:00
|
|
|
{
|
2017-04-24 00:24:47 +02:00
|
|
|
wlerr("Invalid data offset\n");
|
2017-04-23 22:17:43 +02:00
|
|
|
bcmf_sdpcm_rxfail(sbus, false);
|
2017-04-13 20:31:39 +02:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update tx credits */
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
sbus->max_seq = header->credit;
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
/* Update flow control status */
|
|
|
|
|
|
|
|
sbus->flow_ctrl = (header->flow_control != 0);
|
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-04-16 11:28:08 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
int bcmf_sdpcm_readframe(FAR struct bcmf_dev_s *priv)
|
|
|
|
{
|
|
|
|
int ret;
|
2019-10-29 23:56:24 +01:00
|
|
|
uint16_t len;
|
|
|
|
uint16_t checksum;
|
2017-04-23 22:17:43 +02:00
|
|
|
struct bcmf_sdpcm_header *header;
|
2021-09-16 05:19:44 +02:00
|
|
|
struct bcmf_sdpcm_header tmp_hdr;
|
2017-04-30 20:29:48 +02:00
|
|
|
struct bcmf_sdio_frame *sframe;
|
2017-05-04 02:20:57 +02:00
|
|
|
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s *)priv->bus;
|
2017-04-23 22:17:43 +02:00
|
|
|
|
2021-07-27 02:43:12 +02:00
|
|
|
/* Read the first 4 bytes of sdpcm header
|
|
|
|
* to get the length of the following data to be read
|
|
|
|
*/
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2021-07-27 02:43:12 +02:00
|
|
|
ret = bcmf_transfer_bytes(sbus, false, 2, 0,
|
2021-09-16 05:19:44 +02:00
|
|
|
(uint8_t *)&tmp_hdr,
|
2021-07-27 02:43:12 +02:00
|
|
|
FIRST_WORD_SIZE);
|
2017-04-13 20:31:39 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2021-09-16 05:19:44 +02:00
|
|
|
wlinfo("Failed to read size\n");
|
|
|
|
bcmf_sdpcm_rxfail(sbus, false);
|
|
|
|
return -EIO;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
len = tmp_hdr.size;
|
|
|
|
checksum = tmp_hdr.checksum;
|
2017-04-13 20:31:39 +02:00
|
|
|
|
|
|
|
/* All zero means no more to read */
|
|
|
|
|
|
|
|
if (!(len | checksum))
|
|
|
|
{
|
2021-09-16 05:19:44 +02:00
|
|
|
return -ENODATA;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (((~len & 0xffff) ^ checksum) || len < sizeof(struct bcmf_sdpcm_header))
|
|
|
|
{
|
2017-04-24 00:24:47 +02:00
|
|
|
wlerr("Invalid header checksum or len %x %x\n", len, checksum);
|
2021-09-16 05:19:44 +02:00
|
|
|
bcmf_sdpcm_rxfail(sbus, false);
|
|
|
|
return -EINVAL;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
if (len == FC_UPDATE_PKT_LENGTH)
|
2017-04-13 20:31:39 +02:00
|
|
|
{
|
2021-09-16 05:19:44 +02:00
|
|
|
/* Flow control update packet with no data */
|
|
|
|
|
|
|
|
ret = bcmf_transfer_bytes(sbus, false, 2, 0,
|
|
|
|
(uint8_t *)&tmp_hdr + FIRST_WORD_SIZE,
|
|
|
|
FC_UPDATE_PKT_LENGTH - FIRST_WORD_SIZE);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
wlinfo("Failed to read the rest 8 bytes\n");
|
|
|
|
bcmf_sdpcm_rxfail(sbus, false);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = bcmf_sdpcm_process_header(sbus, &tmp_hdr);
|
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
wlerr("Error while processing header %d\n", ret);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request free frame buffer */
|
|
|
|
|
|
|
|
sframe = bcmf_sdio_allocate_frame(priv, false, false);
|
|
|
|
|
|
|
|
if (sframe == NULL)
|
|
|
|
{
|
|
|
|
wlinfo("fail alloc\n");
|
|
|
|
|
|
|
|
/* Read out the rest of the header to get the bus credit information */
|
|
|
|
|
|
|
|
ret = bcmf_transfer_bytes(sbus, false, 2, 0,
|
|
|
|
(uint8_t *)&tmp_hdr + FIRST_WORD_SIZE,
|
|
|
|
FC_UPDATE_PKT_LENGTH - FIRST_WORD_SIZE);
|
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
wlinfo("Failed to read the rest 8 bytes\n");
|
|
|
|
bcmf_sdpcm_rxfail(sbus, false);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
bcmf_sdpcm_rxfail(sbus, false);
|
|
|
|
|
|
|
|
ret = bcmf_sdpcm_process_header(sbus, &tmp_hdr);
|
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
wlerr("Error while processing header %d\n", ret);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EAGAIN;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
header = (struct bcmf_sdpcm_header *)sframe->data;
|
|
|
|
|
2021-07-27 02:43:12 +02:00
|
|
|
/* Read the remaining frame data (the buffer is DMA aligned here) */
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
if (len <= FIRST_WORD_SIZE)
|
|
|
|
{
|
|
|
|
ret = OK;
|
|
|
|
goto exit_free_frame;
|
|
|
|
}
|
|
|
|
|
2021-04-04 11:58:11 +02:00
|
|
|
ret = bcmf_transfer_bytes(sbus, false, 2, 0,
|
2021-07-27 02:43:12 +02:00
|
|
|
(uint8_t *)header + FIRST_WORD_SIZE,
|
|
|
|
len - FIRST_WORD_SIZE);
|
2017-04-13 20:31:39 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2021-09-16 05:19:44 +02:00
|
|
|
wlinfo("Failed to read remaining frame data\n");
|
2017-04-13 20:31:39 +02:00
|
|
|
ret = -EIO;
|
2017-04-30 20:29:48 +02:00
|
|
|
goto exit_abort;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
memcpy(header, &tmp_hdr, FIRST_WORD_SIZE);
|
|
|
|
|
|
|
|
if (len > sframe->header.len)
|
|
|
|
{
|
|
|
|
wlerr("Frame is too large, cancel %d %d\n", len, sframe->header.len);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto exit_abort;
|
|
|
|
}
|
|
|
|
|
2018-08-23 01:35:17 +02:00
|
|
|
#if 0
|
|
|
|
wlinfo("Receive frame %p %d\n", sframe, len);
|
|
|
|
|
|
|
|
bcmf_hexdump((uint8_t *)header, header->size, (unsigned int)header);
|
|
|
|
#endif
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
/* Process and validate header */
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
ret = bcmf_sdpcm_process_header(sbus, header);
|
2017-04-13 20:31:39 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2017-04-24 00:24:47 +02:00
|
|
|
wlerr("Error while processing header %d\n", ret);
|
2017-04-16 13:13:11 +02:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto exit_free_frame;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 02:30:40 +02:00
|
|
|
/* Update frame structure */
|
2017-04-23 22:17:43 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
sframe->header.len = header->size;
|
|
|
|
sframe->header.data += header->data_offset;
|
2017-04-23 22:17:43 +02:00
|
|
|
|
2017-04-16 13:13:11 +02:00
|
|
|
/* Process received frame content */
|
|
|
|
|
|
|
|
switch (header->channel & 0x0f)
|
|
|
|
{
|
|
|
|
case SDPCM_CONTROL_CHANNEL:
|
2017-04-30 20:29:48 +02:00
|
|
|
ret = bcmf_cdc_process_control_frame(priv, &sframe->header);
|
|
|
|
goto exit_free_frame;
|
2017-04-16 13:13:11 +02:00
|
|
|
|
|
|
|
case SDPCM_EVENT_CHANNEL:
|
2017-04-28 19:28:29 +02:00
|
|
|
if (header->data_offset == header->size)
|
|
|
|
{
|
|
|
|
/* Empty event, ignore */
|
|
|
|
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
ret = bcmf_bdc_process_event_frame(priv, &sframe->header);
|
2017-04-28 19:28:29 +02:00
|
|
|
}
|
2019-10-29 23:56:24 +01:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
goto exit_free_frame;
|
2017-04-16 13:13:11 +02:00
|
|
|
|
|
|
|
case SDPCM_DATA_CHANNEL:
|
2017-04-30 20:29:48 +02:00
|
|
|
|
|
|
|
/* Queue frame and notify network layer frame is available */
|
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
if (nxsem_wait(&sbus->queue_mutex) < 0)
|
2017-04-30 20:29:48 +02:00
|
|
|
{
|
2018-08-24 14:21:15 +02:00
|
|
|
DEBUGPANIC();
|
2017-04-30 20:29:48 +02:00
|
|
|
}
|
2017-10-04 23:22:27 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
bcmf_dqueue_push(&sbus->rx_queue, &sframe->list_entry);
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&sbus->queue_mutex);
|
2017-04-30 20:29:48 +02:00
|
|
|
|
|
|
|
bcmf_netdev_notify_rx(priv);
|
|
|
|
|
|
|
|
/* Upper layer have to free all received frames */
|
|
|
|
|
|
|
|
ret = OK;
|
2017-04-16 13:13:11 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-04-24 00:24:47 +02:00
|
|
|
wlerr("Got unexpected message type %d\n", header->channel);
|
2017-04-30 20:29:48 +02:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto exit_free_frame;
|
2017-04-16 13:13:11 +02:00
|
|
|
}
|
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
exit_abort:
|
2017-04-23 22:17:43 +02:00
|
|
|
bcmf_sdpcm_rxfail(sbus, false);
|
2017-04-30 20:29:48 +02:00
|
|
|
exit_free_frame:
|
|
|
|
bcmf_sdio_free_frame(priv, sframe);
|
2017-04-13 20:31:39 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-16 11:28:08 +02:00
|
|
|
int bcmf_sdpcm_sendframe(FAR struct bcmf_dev_s *priv)
|
2017-04-13 20:31:39 +02:00
|
|
|
{
|
2017-04-16 11:28:08 +02:00
|
|
|
int ret;
|
2017-04-30 20:29:48 +02:00
|
|
|
bool is_txframe;
|
|
|
|
dq_entry_t *entry;
|
|
|
|
struct bcmf_sdio_frame *sframe;
|
2017-04-23 22:17:43 +02:00
|
|
|
struct bcmf_sdpcm_header *header;
|
2017-05-04 02:20:57 +02:00
|
|
|
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s *)priv->bus;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
if (sbus->tx_queue.tail == NULL)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
|
|
|
/* No more frames to send */
|
|
|
|
|
|
|
|
return -ENODATA;
|
|
|
|
}
|
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
if (sbus->flow_ctrl)
|
|
|
|
{
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
if (sbus->tx_seq == sbus->max_seq)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2018-08-23 01:35:17 +02:00
|
|
|
/* TODO handle this case */
|
|
|
|
|
2017-04-24 00:24:47 +02:00
|
|
|
wlerr("No credit to send frame\n");
|
2017-04-16 11:28:08 +02:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
if (nxsem_wait(&sbus->queue_mutex) < 0)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2018-08-24 14:21:15 +02:00
|
|
|
DEBUGPANIC();
|
2017-04-16 11:28:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
entry = sbus->tx_queue.tail;
|
|
|
|
sframe = container_of(entry, struct bcmf_sdio_frame, list_entry);
|
2017-05-04 02:20:57 +02:00
|
|
|
header = (struct bcmf_sdpcm_header *)sframe->header.base;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
|
|
|
/* Set frame sequence id */
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
header->sequence = sbus->tx_seq++;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2018-08-23 01:35:17 +02:00
|
|
|
#if 0
|
|
|
|
wlinfo("Send frame %p\n", sframe);
|
|
|
|
|
|
|
|
bcmf_hexdump(sframe->header.base, sframe->header.len,
|
|
|
|
(unsigned long)sframe->header.base);
|
|
|
|
#endif
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2021-07-27 02:43:12 +02:00
|
|
|
/* Write the first 4 bytes of sdpcm header */
|
|
|
|
|
|
|
|
ret = bcmf_transfer_bytes(sbus, true, 2, 0,
|
|
|
|
sframe->header.base,
|
|
|
|
FIRST_WORD_SIZE);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
/* TODO handle retry count and remove frame from queue + abort TX */
|
|
|
|
|
|
|
|
wlinfo("fail send frame %d\n", ret);
|
|
|
|
ret = -EIO;
|
|
|
|
goto exit_abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write the remaining frame data (the buffer is DMA aligned here) */
|
|
|
|
|
|
|
|
ret = bcmf_transfer_bytes(sbus, true, 2, 0,
|
|
|
|
sframe->header.base + FIRST_WORD_SIZE,
|
|
|
|
sframe->header.len - FIRST_WORD_SIZE);
|
2017-04-16 11:28:08 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2018-08-23 01:35:17 +02:00
|
|
|
/* TODO handle retry count and remove frame from queue + abort TX */
|
|
|
|
|
2017-04-24 00:24:47 +02:00
|
|
|
wlinfo("fail send frame %d\n", ret);
|
2017-04-16 11:28:08 +02:00
|
|
|
ret = -EIO;
|
|
|
|
goto exit_abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Frame sent, remove it from queue */
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
bcmf_dqueue_pop_tail(&sbus->tx_queue);
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&sbus->queue_mutex);
|
2017-04-30 20:29:48 +02:00
|
|
|
is_txframe = sframe->tx;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Free frame buffer */
|
|
|
|
|
|
|
|
bcmf_sdio_free_frame(priv, sframe);
|
|
|
|
|
|
|
|
if (is_txframe)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Notify upper layer at least one TX buffer is available */
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
bcmf_netdev_notify_tx_done(priv);
|
|
|
|
}
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
return OK;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
|
|
|
exit_abort:
|
2018-08-23 01:35:17 +02:00
|
|
|
#if 0
|
|
|
|
bcmf_sdpcm_txfail(sbus, false);
|
|
|
|
#endif
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&sbus->queue_mutex);
|
2017-04-16 11:28:08 +02:00
|
|
|
return ret;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
int bcmf_sdpcm_queue_frame(FAR struct bcmf_dev_s *priv,
|
|
|
|
struct bcmf_frame_s *frame, bool control)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2017-05-04 02:20:57 +02:00
|
|
|
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s *)priv->bus;
|
|
|
|
struct bcmf_sdio_frame *sframe = (struct bcmf_sdio_frame *)frame;
|
2021-04-04 11:58:11 +02:00
|
|
|
struct bcmf_sdpcm_header *header =
|
2021-07-27 02:43:12 +02:00
|
|
|
(struct bcmf_sdpcm_header *)sframe->data;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
|
|
|
/* Prepare sw header */
|
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
memset(header, 0, sizeof(struct bcmf_sdpcm_header));
|
2017-04-30 20:29:48 +02:00
|
|
|
header->size = frame->len;
|
2017-04-23 22:17:43 +02:00
|
|
|
header->checksum = ~header->size;
|
2017-04-30 20:29:48 +02:00
|
|
|
header->data_offset = (uint8_t)(frame->data - frame->base);
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-23 22:17:43 +02:00
|
|
|
if (control)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2017-04-23 22:17:43 +02:00
|
|
|
header->channel = SDPCM_CONTROL_CHANNEL;
|
2017-04-16 11:28:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-04-23 22:17:43 +02:00
|
|
|
header->channel = SDPCM_DATA_CHANNEL;
|
2017-04-16 11:28:08 +02:00
|
|
|
}
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Add frame in tx queue */
|
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
if (nxsem_wait(&sbus->queue_mutex) < 0)
|
2017-04-30 20:29:48 +02:00
|
|
|
{
|
2018-08-24 14:21:15 +02:00
|
|
|
DEBUGPANIC();
|
2017-04-30 20:29:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bcmf_dqueue_push(&sbus->tx_queue, &sframe->list_entry);
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&sbus->queue_mutex);
|
2017-04-30 20:29:48 +02:00
|
|
|
|
|
|
|
/* Notify bcmf thread tx frame is ready */
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&sbus->thread_signal);
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
return OK;
|
2017-04-16 11:28:08 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
struct bcmf_frame_s *bcmf_sdpcm_alloc_frame(FAR struct bcmf_dev_s *priv,
|
|
|
|
unsigned int len, bool block,
|
|
|
|
bool control)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
struct bcmf_sdio_frame *sframe;
|
|
|
|
unsigned int header_len = sizeof(struct bcmf_sdpcm_header);
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
if (!control)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
header_len += 2; /* Data frames need alignment padding */
|
2017-04-16 11:28:08 +02:00
|
|
|
}
|
|
|
|
|
2018-10-26 13:26:26 +02:00
|
|
|
if (len + header_len > MAX_NETDEV_PKTSIZE + HEADER_SIZE)
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
wlerr("Invalid size %d\n", len);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Allocate a frame for RX in case of control frame */
|
2017-04-16 13:13:11 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
sframe = bcmf_sdio_allocate_frame(priv, block, !control);
|
|
|
|
|
|
|
|
if (sframe == NULL)
|
2017-04-22 15:57:51 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-10-26 13:26:26 +02:00
|
|
|
sframe->header.len = header_len + len;
|
2017-04-30 20:29:48 +02:00
|
|
|
sframe->header.data += header_len;
|
|
|
|
return &sframe->header;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bcmf_sdpcm_free_frame(FAR struct bcmf_dev_s *priv,
|
|
|
|
struct bcmf_frame_s *frame)
|
|
|
|
{
|
2017-05-04 02:20:57 +02:00
|
|
|
return bcmf_sdio_free_frame(priv, (struct bcmf_sdio_frame *)frame);
|
2017-04-30 20:29:48 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
struct bcmf_frame_s *bcmf_sdpcm_get_rx_frame(FAR struct bcmf_dev_s *priv)
|
2017-04-30 20:29:48 +02:00
|
|
|
{
|
|
|
|
dq_entry_t *entry;
|
|
|
|
struct bcmf_sdio_frame *sframe;
|
2017-05-04 02:20:57 +02:00
|
|
|
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s *)priv->bus;
|
2017-04-23 22:17:43 +02:00
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
if (nxsem_wait(&sbus->queue_mutex) < 0)
|
2017-04-30 20:29:48 +02:00
|
|
|
{
|
2018-08-24 14:21:15 +02:00
|
|
|
DEBUGPANIC();
|
2017-04-22 15:57:51 +02:00
|
|
|
}
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
entry = bcmf_dqueue_pop_tail(&sbus->rx_queue);
|
2017-04-16 13:13:11 +02:00
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&sbus->queue_mutex);
|
2017-04-22 15:57:51 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
if (entry == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-04-22 15:57:51 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
sframe = container_of(entry, struct bcmf_sdio_frame, list_entry);
|
|
|
|
return &sframe->header;
|
2017-05-04 02:20:57 +02:00
|
|
|
}
|