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>
|
2017-04-13 20:31:39 +02:00
|
|
|
|
|
|
|
#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"
|
2022-08-14 21:04:18 +02:00
|
|
|
#include "bcmf_interface.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
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
static int bcmf_sdpcm_rxfail(FAR bcmf_interface_dev_t *ibus, bool retry);
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
static int bcmf_sdpcm_process_header(FAR bcmf_interface_dev_t *ibus,
|
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
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
int bcmf_sdpcm_rxfail(FAR bcmf_interface_dev_t *ibus, bool retry)
|
2017-04-13 20:31:39 +02:00
|
|
|
{
|
|
|
|
/* issue abort command for F2 through F0 */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_bus_io_abort(ibus);
|
2017-04-13 20:31:39 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_write_reg(ibus, 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 */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_write_sbregb(ibus,
|
|
|
|
CORE_BUS_REG(ibus->chip->core_base[SDIOD_CORE_ID],
|
2017-04-13 20:31:39 +02:00
|
|
|
tosbmailbox), SMB_NAK);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
int bcmf_sdpcm_process_header(FAR bcmf_interface_dev_t *ibus,
|
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");
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_sdpcm_rxfail(ibus, false);
|
2017-04-13 20:31:39 +02:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update tx credits */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ibus->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;
|
2021-09-16 05:19:44 +02:00
|
|
|
struct bcmf_sdpcm_header tmp_hdr;
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_interface_frame_t *iframe;
|
|
|
|
FAR bcmf_interface_dev_t *ibus = (FAR bcmf_interface_dev_t *)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
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_transfer_bytes(ibus, 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");
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_sdpcm_rxfail(ibus, false);
|
2021-09-16 05:19:44 +02:00
|
|
|
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 */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
if (len == 0)
|
2017-04-13 20:31:39 +02:00
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
wlinfo("No data\n");
|
|
|
|
|
2021-09-16 05:19:44 +02:00
|
|
|
return -ENODATA;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
wlinfo("len: %d Header checksum: 0x%04x\n", len, checksum);
|
|
|
|
|
2017-04-13 20:31:39 +02:00
|
|
|
if (((~len & 0xffff) ^ checksum) || len < sizeof(struct bcmf_sdpcm_header))
|
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
wlerr("Invalid header checksum or len %d 0x%04x\n", len, checksum);
|
|
|
|
bcmf_sdpcm_rxfail(ibus, false);
|
2021-09-16 05:19:44 +02:00
|
|
|
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 */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
wlinfo("Flow control\n");
|
|
|
|
|
|
|
|
ret = bcmf_transfer_bytes(ibus, false, 2, 0,
|
2021-09-16 05:19:44 +02:00
|
|
|
(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");
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_sdpcm_rxfail(ibus, false);
|
2021-09-16 05:19:44 +02:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_sdpcm_process_header(ibus, &tmp_hdr);
|
2021-09-16 05:19:44 +02:00
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
wlerr("Error while processing header %d\n", ret);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Request free frame buffer */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
iframe = bcmf_interface_allocate_frame(priv, false, false);
|
2021-09-16 05:19:44 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
if (iframe == NULL)
|
2021-09-16 05:19:44 +02:00
|
|
|
{
|
|
|
|
wlinfo("fail alloc\n");
|
|
|
|
|
|
|
|
/* Read out the rest of the header to get the bus credit information */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_transfer_bytes(ibus, false, 2, 0,
|
2021-09-16 05:19:44 +02:00
|
|
|
(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");
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_sdpcm_rxfail(ibus, false);
|
2021-09-16 05:19:44 +02:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_sdpcm_rxfail(ibus, false);
|
2021-09-16 05:19:44 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_sdpcm_process_header(ibus, &tmp_hdr);
|
2021-09-16 05:19:44 +02:00
|
|
|
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
wlerr("Error while processing header %d\n", ret);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EAGAIN;
|
2017-04-13 20:31:39 +02:00
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
header = (struct bcmf_sdpcm_header *)iframe->data;
|
2021-09-16 05:19:44 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_transfer_bytes(ibus, false, 2, 0,
|
|
|
|
(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);
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
if (len > iframe->header.len)
|
2021-09-16 05:19:44 +02:00
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
wlerr("Frame is too large, cancel %d %d\n", len, iframe->header.len);
|
2021-09-16 05:19:44 +02:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto exit_abort;
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
#if 1
|
|
|
|
wlinfo("Receive frame %p %d\n", iframe, len);
|
|
|
|
|
|
|
|
wlinfo("size:%d seq: %d, channel: %d next len: %d\n",
|
|
|
|
header->size,
|
|
|
|
header->sequence,
|
|
|
|
header->channel,
|
|
|
|
header->next_length);
|
|
|
|
|
|
|
|
wlinfo("data offset:0x%02X flow: %d, credit: %d\n",
|
|
|
|
header->data_offset,
|
|
|
|
header->flow_control,
|
|
|
|
header->credit);
|
2018-08-23 01:35:17 +02:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_sdpcm_process_header(ibus, 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
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
iframe->header.len = header->size;
|
|
|
|
iframe->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:
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_cdc_process_control_frame(priv, &iframe->header);
|
2017-04-30 20:29:48 +02:00
|
|
|
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
|
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_bdc_process_event_frame(priv, &iframe->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 */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
if (nxmutex_lock(&ibus->queue_lock) < 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
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
list_add_tail(&ibus->rx_queue, &iframe->list_entry);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&ibus->queue_lock);
|
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:
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_sdpcm_rxfail(ibus, false);
|
2017-04-30 20:29:48 +02:00
|
|
|
exit_free_frame:
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_interface_free_frame(priv, iframe);
|
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;
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_interface_frame_t *iframe;
|
2017-04-23 22:17:43 +02:00
|
|
|
struct bcmf_sdpcm_header *header;
|
2022-08-14 21:04:18 +02:00
|
|
|
FAR bcmf_interface_dev_t *ibus = (FAR bcmf_interface_dev_t *)priv->bus;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
if (list_is_empty(&ibus->tx_queue))
|
2017-04-16 11:28:08 +02:00
|
|
|
{
|
|
|
|
/* No more frames to send */
|
|
|
|
|
|
|
|
return -ENODATA;
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
if (ibus->tx_seq == ibus->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;
|
|
|
|
}
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
if (nxmutex_lock(&ibus->queue_lock) < 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
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
iframe = list_remove_head_type(&ibus->tx_queue, bcmf_interface_frame_t,
|
2022-07-02 06:39:48 +02:00
|
|
|
list_entry);
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&ibus->queue_lock);
|
2022-07-02 06:39:48 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
header = (struct bcmf_sdpcm_header *)iframe->header.base;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
|
|
|
/* Set frame sequence id */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
header->sequence = ibus->tx_seq++;
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
#if 1
|
|
|
|
wlinfo("Send frame %p\n", iframe);
|
2018-08-23 01:35:17 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_hexdump(iframe->header.base, iframe->header.len,
|
|
|
|
(unsigned long)iframe->header.base);
|
2018-08-23 01:35:17 +02:00
|
|
|
#endif
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2022-06-19 12:41:47 +02:00
|
|
|
/* Write the frame data (the buffer is DMA aligned here) */
|
2021-07-27 02:43:12 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
ret = bcmf_transfer_bytes(ibus, true, 2, 0,
|
|
|
|
iframe->header.base,
|
|
|
|
iframe->header.len);
|
|
|
|
is_txframe = iframe->tx;
|
2018-08-23 01:35:17 +02:00
|
|
|
|
2022-06-29 10:19:01 +02:00
|
|
|
/* Free frame buffer */
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_interface_free_frame(priv, iframe);
|
2017-04-30 20:29:48 +02:00
|
|
|
|
2022-06-29 10:19:01 +02:00
|
|
|
if (ret == OK && is_txframe)
|
|
|
|
{
|
|
|
|
/* Notify upper layer at least one TX buffer is available */
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2022-06-29 10:19:01 +02:00
|
|
|
bcmf_netdev_notify_tx(priv);
|
2017-04-30 20:29:48 +02:00
|
|
|
}
|
2017-04-16 11:28:08 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
wlinfo("return %d\n", ret);
|
|
|
|
|
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
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
FAR bcmf_interface_dev_t *ibus = (FAR bcmf_interface_dev_t *)priv->bus;
|
|
|
|
bcmf_interface_frame_t *iframe = (bcmf_interface_frame_t *)frame;
|
2021-04-04 11:58:11 +02:00
|
|
|
struct bcmf_sdpcm_header *header =
|
2022-08-14 21:04:18 +02:00
|
|
|
(struct bcmf_sdpcm_header *)iframe->data;
|
2022-06-23 06:54:30 +02:00
|
|
|
int semcount;
|
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 */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
if (nxmutex_lock(&ibus->queue_lock) < 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
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
list_add_tail(&ibus->tx_queue, &iframe->list_entry);
|
2017-04-30 20:29:48 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&ibus->queue_lock);
|
2017-04-30 20:29:48 +02:00
|
|
|
|
|
|
|
/* Notify bcmf thread tx frame is ready */
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
nxsem_get_value(&ibus->thread_signal, &semcount);
|
2022-06-23 06:54:30 +02:00
|
|
|
if (semcount < 1)
|
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
nxsem_post(&ibus->thread_signal);
|
2022-06-23 06:54:30 +02:00
|
|
|
}
|
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
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_interface_frame_t *iframe;
|
2017-04-30 20:29:48 +02:00
|
|
|
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
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
iframe = bcmf_interface_allocate_frame(priv, block, !control);
|
2017-04-30 20:29:48 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
if (iframe == NULL)
|
2017-04-22 15:57:51 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
iframe->header.len = header_len + len;
|
|
|
|
iframe->header.data += header_len;
|
|
|
|
return &iframe->header;
|
2017-04-30 20:29:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void bcmf_sdpcm_free_frame(FAR struct bcmf_dev_s *priv,
|
2022-02-03 04:53:01 +01:00
|
|
|
struct bcmf_frame_s *frame)
|
2017-04-30 20:29:48 +02:00
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_interface_free_frame(priv, (bcmf_interface_frame_t *)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
|
|
|
{
|
2022-08-14 21:04:18 +02:00
|
|
|
bcmf_interface_frame_t *iframe;
|
|
|
|
FAR bcmf_interface_dev_t *ibus = (FAR bcmf_interface_dev_t *)priv->bus;
|
2017-04-23 22:17:43 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
if (nxmutex_lock(&ibus->queue_lock) < 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
|
|
|
}
|
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
iframe = list_remove_head_type(&ibus->rx_queue,
|
|
|
|
bcmf_interface_frame_t,
|
2022-07-02 06:39:48 +02:00
|
|
|
list_entry);
|
2017-04-16 13:13:11 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&ibus->queue_lock);
|
2017-04-22 15:57:51 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
if (iframe == NULL)
|
2017-04-30 20:29:48 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-04-22 15:57:51 +02:00
|
|
|
|
2022-08-14 21:04:18 +02:00
|
|
|
return &iframe->header;
|
2017-05-04 02:20:57 +02:00
|
|
|
}
|