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
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Simon Piriou <spiriou31@gmail.com>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-10-29 23:56:24 +01:00
|
|
|
struct __attribute__((packed)) bcmf_sdpcm_header
|
|
|
|
{
|
|
|
|
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;
|
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
|
|
|
|
|
|
|
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;
|
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
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Request free frame buffer */
|
2017-04-23 22:17:43 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
sframe = bcmf_sdio_allocate_frame(priv, false, false);
|
|
|
|
|
|
|
|
if (sframe == NULL)
|
|
|
|
{
|
|
|
|
wlinfo("fail alloc\n");
|
|
|
|
return -EAGAIN;
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
header = (struct bcmf_sdpcm_header *)sframe->data;
|
2017-04-13 20:31:39 +02:00
|
|
|
|
|
|
|
/* Read header */
|
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
ret = bcmf_transfer_bytes(sbus, false, 2, 0, (uint8_t *)header, 4);
|
2017-04-13 20:31:39 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
2017-04-24 00:24:47 +02:00
|
|
|
wlinfo("failread size\n");
|
2017-04-13 20:31:39 +02:00
|
|
|
ret = -EIO;
|
|
|
|
goto exit_abort;
|
|
|
|
}
|
|
|
|
|
2017-04-16 11:28:08 +02:00
|
|
|
len = header->size;
|
|
|
|
checksum = header->checksum;
|
2017-04-13 20:31:39 +02:00
|
|
|
|
|
|
|
/* All zero means no more to read */
|
|
|
|
|
|
|
|
if (!(len | checksum))
|
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
ret = -ENODATA;
|
|
|
|
goto exit_free_frame;
|
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);
|
2017-04-16 13:13:11 +02:00
|
|
|
ret = -EINVAL;
|
2017-04-13 20:31:39 +02:00
|
|
|
goto exit_abort;
|
|
|
|
}
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
if (len > sframe->header.len)
|
2017-04-13 20:31:39 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
wlerr("Frame is too large, cancel %d %d\n", len, sframe->header.len);
|
2017-04-13 20:31:39 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto exit_abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read remaining frame data */
|
|
|
|
|
2017-05-04 02:20:57 +02:00
|
|
|
ret = bcmf_transfer_bytes(sbus, false, 2, 0, (uint8_t *)header + 4, len - 4);
|
2017-04-13 20:31:39 +02:00
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
ret = -EIO;
|
2017-04-30 20:29:48 +02:00
|
|
|
goto exit_abort;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
ret = bcmf_transfer_bytes(sbus, true, 2, 0, sframe->header.base,
|
|
|
|
sframe->header.len);
|
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;
|
|
|
|
struct bcmf_sdpcm_header *header = (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
|
|
|
}
|