bcmf: add netdev support for Broadcom FullMAC driver

This commit is contained in:
Simon Piriou
2017-04-30 20:29:48 +02:00
parent 407fe13b8f
commit fe77735960
14 changed files with 808 additions and 511 deletions
+47 -10
View File
@@ -16,7 +16,7 @@ CONFIG_HOST_LINUX=y
#
# Build Configuration
#
# CONFIG_APPS_DIR="../apps"
CONFIG_APPS_DIR="../apps"
CONFIG_BUILD_FLAT=y
# CONFIG_BUILD_2PASS is not set
@@ -65,7 +65,10 @@ CONFIG_DEBUG_INFO=y
# CONFIG_DEBUG_GRAPHICS is not set
# CONFIG_DEBUG_LIB is not set
# CONFIG_DEBUG_MM is not set
# CONFIG_DEBUG_NET is not set
CONFIG_DEBUG_NET=y
CONFIG_DEBUG_NET_ERROR=y
CONFIG_DEBUG_NET_WARN=y
CONFIG_DEBUG_NET_INFO=y
CONFIG_DEBUG_WIRELESS=y
CONFIG_DEBUG_WIRELESS_ERROR=y
CONFIG_DEBUG_WIRELESS_WARN=y
@@ -986,9 +989,9 @@ CONFIG_NET=y
#
# Driver buffer configuration
#
CONFIG_NET_ETH_MTU=590
CONFIG_NET_ETH_MTU=800
CONFIG_NET_ETH_TCP_RECVWNDO=536
CONFIG_NET_GUARDSIZE=2
CONFIG_NET_GUARDSIZE=32
#
# Data link support
@@ -1018,12 +1021,14 @@ CONFIG_NET_IPv4=y
#
CONFIG_NSOCKET_DESCRIPTORS=8
CONFIG_NET_NACTIVESOCKETS=16
# CONFIG_NET_SOCKOPTS is not set
CONFIG_NET_SOCKOPTS=y
# CONFIG_NET_SOLINGER is not set
#
# Raw Socket Support
#
# CONFIG_NET_PKT is not set
CONFIG_NET_PKT=y
CONFIG_NET_PKT_CONNS=1
#
# Unix Domain Socket Support
@@ -1049,13 +1054,19 @@ CONFIG_NET_TCP_RECVDELAY=0
#
# UDP Networking
#
# CONFIG_NET_UDP is not set
CONFIG_NET_UDP=y
# CONFIG_NET_UDP_NO_STACK is not set
# CONFIG_NET_UDP_CHECKSUMS is not set
CONFIG_NET_UDP_CONNS=8
CONFIG_NET_BROADCAST=y
# CONFIG_NET_RXAVAIL is not set
CONFIG_NET_UDP_READAHEAD=y
#
# ICMP Networking Support
#
# CONFIG_NET_ICMP is not set
CONFIG_NET_ICMP=y
# CONFIG_NET_ICMP_PING is not set
#
# IGMPv2 Client Support
@@ -1070,6 +1081,7 @@ CONFIG_NET_ARPTAB_SIZE=16
CONFIG_NET_ARP_MAXAGE=120
# CONFIG_NET_ARP_IPIN is not set
# CONFIG_NET_ARP_SEND is not set
# CONFIG_NET_ARP_DUMP is not set
#
# User-space networking stack API
@@ -1106,6 +1118,7 @@ CONFIG_FS_READABLE=y
CONFIG_FS_MQUEUE_MPATH="/var/mqueue"
# CONFIG_FS_RAMMAP is not set
# CONFIG_FS_FAT is not set
# CONFIG_NFS is not set
# CONFIG_FS_NXFFS is not set
# CONFIG_FS_ROMFS is not set
# CONFIG_FS_TMPFS is not set
@@ -1251,6 +1264,15 @@ CONFIG_LIBC_NETDB=y
# NETDB Support
#
# CONFIG_NETDB_HOSTFILE is not set
CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDB_DNSCLIENT_ENTRIES=8
CONFIG_NETDB_DNSCLIENT_NAMESIZE=32
CONFIG_NETDB_DNSCLIENT_LIFESEC=3600
CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=96
# CONFIG_NETDB_RESOLVCONF is not set
# CONFIG_NETDB_DNSSERVER_NOADDR is not set
CONFIG_NETDB_DNSSERVER_IPv4=y
CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x0a000001
# CONFIG_LIBC_IOCTL_VARIADIC is not set
CONFIG_LIB_SENDFILE_BUFSIZE=512
@@ -1306,6 +1328,7 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
# CONFIG_EXAMPLES_CONFIGDATA is not set
# CONFIG_EXAMPLES_CXXTEST is not set
# CONFIG_EXAMPLES_DHCPD is not set
# CONFIG_EXAMPLES_DISCOVER is not set
# CONFIG_EXAMPLES_ELF is not set
# CONFIG_EXAMPLES_FTPC is not set
# CONFIG_EXAMPLES_FTPD is not set
@@ -1320,6 +1343,7 @@ CONFIG_BUILTIN_PROXY_STACKSIZE=1024
# CONFIG_EXAMPLES_MM is not set
# CONFIG_EXAMPLES_MODBUS is not set
# CONFIG_EXAMPLES_MOUNT is not set
# CONFIG_EXAMPLES_NETPKT is not set
# CONFIG_EXAMPLES_NETTEST is not set
# CONFIG_EXAMPLES_NRF24L01TERM is not set
CONFIG_EXAMPLES_NSH=y
@@ -1351,6 +1375,8 @@ CONFIG_EXAMPLES_NSH=y
# CONFIG_EXAMPLES_TELNETD is not set
# CONFIG_EXAMPLES_TIFF is not set
# CONFIG_EXAMPLES_TOUCHSCREEN is not set
# CONFIG_EXAMPLES_UDP is not set
# CONFIG_EXAMPLES_UDPBLASTER is not set
# CONFIG_EXAMPLES_USBSERIAL is not set
# CONFIG_EXAMPLES_WATCHDOG is not set
# CONFIG_EXAMPLES_WEBSERVER is not set
@@ -1391,12 +1417,20 @@ CONFIG_EXAMPLES_NSH=y
# Network Utilities
#
# CONFIG_NETUTILS_CODECS is not set
CONFIG_NETUTILS_DHCPC=y
# CONFIG_NETUTILS_DHCPD is not set
# CONFIG_NETUTILS_DISCOVER is not set
# CONFIG_NETUTILS_ESP8266 is not set
# CONFIG_NETUTILS_FTPC is not set
# CONFIG_NETUTILS_JSON is not set
CONFIG_NETUTILS_NETLIB=y
# CONFIG_NETUTILS_NTPCLIENT is not set
CONFIG_NETUTILS_PING=y
CONFIG_NETUTILS_PING_SIGNO=13
# CONFIG_NETUTILS_PPPD is not set
# CONFIG_NETUTILS_SMTP is not set
# CONFIG_NETUTILS_TELNETD is not set
# CONFIG_NETUTILS_TFTPC is not set
# CONFIG_NETUTILS_WEBCLIENT is not set
# CONFIG_NETUTILS_WEBSERVER is not set
# CONFIG_NETUTILS_XMLRPC is not set
@@ -1456,8 +1490,10 @@ CONFIG_NSH_DISABLE_LOSMART=y
# CONFIG_NSH_DISABLE_MOUNT is not set
# CONFIG_NSH_DISABLE_MV is not set
# CONFIG_NSH_DISABLE_MW is not set
# CONFIG_NSH_DISABLE_NSLOOKUP is not set
CONFIG_NSH_DISABLE_PRINTF=y
# CONFIG_NSH_DISABLE_PS is not set
# CONFIG_NSH_DISABLE_PING is not set
# CONFIG_NSH_DISABLE_PUT is not set
# CONFIG_NSH_DISABLE_PWD is not set
# CONFIG_NSH_DISABLE_RM is not set
@@ -1510,13 +1546,14 @@ CONFIG_NSH_NETINIT=y
#
# IP Address Configuration
#
CONFIG_NSH_DHCPC=y
#
# IPv4 Addresses
#
CONFIG_NSH_IPADDR=0x0a000002
CONFIG_NSH_DRIPADDR=0x0a000001
CONFIG_NSH_DRIPADDR=0xc0a80001
CONFIG_NSH_NETMASK=0xffffff00
# CONFIG_NSH_DNS is not set
# CONFIG_NSH_NOMAC is not set
CONFIG_NSH_MAX_ROUNDTRIP=20
# CONFIG_NSH_LOGIN is not set
+62 -20
View File
@@ -101,31 +101,29 @@ static const uint8_t bcmf_broadcom_oui[] = {0x00, 0x10, 0x18};
* Private Functions
****************************************************************************/
struct bcmf_frame_s* bcmf_bdc_allocate_frame(FAR struct bcmf_dev_s *priv,
uint32_t len, bool block)
{
if (len <= 0)
{
return NULL;
}
/* Allocate data frame */
return priv->bus->allocate_frame(priv,
sizeof(struct bcmf_bdc_header) + len,
false, block);
}
/****************************************************************************
* Public Functions
****************************************************************************/
int bcmf_bdc_process_data_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame)
struct bcmf_frame_s* bcmf_bdc_allocate_frame(FAR struct bcmf_dev_s *priv,
uint32_t len, bool block)
{
wlinfo("Data message\n");
bcmf_hexdump(frame->base, frame->len, (unsigned long)frame->base);
return OK;
struct bcmf_frame_s *frame;
/* Allocate data frame */
// TODO check for integer overflow
frame = priv->bus->allocate_frame(priv,
sizeof(struct bcmf_bdc_header) + len, block, false);
if (!frame)
{
return NULL;
}
frame->data += sizeof(struct bcmf_bdc_header);
return frame;
}
int bcmf_bdc_process_event_frame(FAR struct bcmf_dev_s *priv,
@@ -240,4 +238,48 @@ int bcmf_event_push_config(FAR struct bcmf_dev_s *priv)
}
return OK;
}
int bcmf_bdc_transmit_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame)
{
struct bcmf_bdc_header* header;
/* Set frame data for lower layer */
frame->data -= sizeof(struct bcmf_bdc_header);
header = (struct bcmf_bdc_header*)frame->data;
/* Setup data frame header */
header->flags = 0x20; /* Set bdc protocol version */
header->priority = 0; // TODO handle priority
header->flags2 = CHIP_STA_INTERFACE;
header->data_offset = 0;
/* Send frame */
return priv->bus->txframe(priv, frame, false);
}
struct bcmf_frame_s* bcmf_bdc_rx_frame(FAR struct bcmf_dev_s *priv)
{
unsigned int frame_len;
struct bcmf_frame_s *frame = priv->bus->rxframe(priv);
/* Process bdc header */
frame_len = frame->len - (unsigned int)(frame->data - frame->base);
if (frame_len < sizeof(struct bcmf_bdc_header))
{
wlerr("Data frame too small\n");
priv->bus->free_frame(priv, frame);
return NULL;
}
/* Transmit frame to upper layer */
frame->data += sizeof(struct bcmf_bdc_header);
return frame;
}
+13 -2
View File
@@ -69,12 +69,23 @@ typedef void (*event_handler_t)(FAR struct bcmf_dev_s *priv,
* Public Function Prototypes
****************************************************************************/
int bcmf_bdc_process_data_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame);
/* Function called from lower layer */
int bcmf_bdc_process_event_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame);
/* Function called from upper layer */
struct bcmf_frame_s* bcmf_bdc_allocate_frame(FAR struct bcmf_dev_s *priv,
uint32_t len, bool block);
int bcmf_bdc_transmit_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame);
struct bcmf_frame_s* bcmf_bdc_rx_frame(FAR struct bcmf_dev_s *priv);
/* Event frames API */
int bcmf_event_register(FAR struct bcmf_dev_s *priv, event_handler_t handler,
unsigned int event_id);
+4 -9
View File
@@ -128,13 +128,6 @@ struct bcmf_frame_s* bcmf_cdc_allocate_frame(FAR struct bcmf_dev_s *priv,
data_len = 0;
}
if (data_len + name_len + sizeof(struct bcmf_cdc_header) < data_len)
{
/* Integer overflow */
return NULL;
}
/* Allocate control frame */
frame = priv->bus->allocate_frame(priv,
@@ -177,7 +170,7 @@ int bcmf_cdc_sendframe(FAR struct bcmf_dev_s *priv, uint32_t cmd,
/* Send frame */
return priv->bus->txframe(priv, frame);
return priv->bus->txframe(priv, frame, true);
}
int bcmf_cdc_control_request(FAR struct bcmf_dev_s *priv,
@@ -230,7 +223,9 @@ int bcmf_cdc_control_request_unsafe(FAR struct bcmf_dev_s *priv,
ret = bcmf_cdc_sendframe(priv, cmd, ifidx, set, frame);
if (ret != OK)
{
// TODO free allocated iovar buffer here
/* Free allocated iovar buffer */
priv->bus->free_frame(priv, frame);
return ret;
}
+55 -21
View File
@@ -49,13 +49,13 @@
#include <nuttx/kmalloc.h>
#include <nuttx/wdog.h>
#include <nuttx/sdio.h>
#include "bcmf_driver.h"
#include "bcmf_cdc.h"
#include "bcmf_ioctl.h"
#include "bcmf_utils.h"
#include <nuttx/sdio.h>
#include "bcmf_netdev.h"
#include "bcmf_sdio.h"
/****************************************************************************
@@ -90,9 +90,6 @@ static void bcmf_free_device(FAR struct bcmf_dev_s *priv);
static int bcmf_driver_initialize(FAR struct bcmf_dev_s *priv);
// FIXME add bcmf_netdev.h file
int bcmf_netdev_register(FAR struct bcmf_dev_s *priv);
// FIXME only for debug purpose
static void bcmf_wl_default_event_handler(FAR struct bcmf_dev_s *priv,
struct bcmf_event_s *event, unsigned int len);
@@ -103,9 +100,8 @@ static void bcmf_wl_radio_event_handler(FAR struct bcmf_dev_s *priv,
static void bcmf_wl_scan_event_handler(FAR struct bcmf_dev_s *priv,
struct bcmf_event_s *event, unsigned int len);
#if 0
static int bcmf_run_escan(FAR struct bcmf_dev_s *priv);
#endif
static void bcmf_wl_auth_event_handler(FAR struct bcmf_dev_s *priv,
struct bcmf_event_s *event, unsigned int len);
/****************************************************************************
* Private Data
@@ -149,6 +145,18 @@ FAR struct bcmf_dev_s* bcmf_allocate_device(void)
goto exit_free_priv;
}
/* Init authentication signal semaphore */
if ((ret = sem_init(&priv->auth_signal, 0, 0)) != OK)
{
goto exit_free_priv;
}
if ((ret = sem_setprotocol(&priv->auth_signal, SEM_PRIO_NONE)) != OK)
{
goto exit_free_priv;
}
/* Init scan timeout timer */
priv->scan_status = BCMF_SCAN_DISABLED;
@@ -173,23 +181,27 @@ void bcmf_free_device(FAR struct bcmf_dev_s *priv)
kmm_free(priv);
}
int bcmf_wl_set_mac_address(FAR struct bcmf_dev_s *priv, uint8_t *addr)
int bcmf_wl_set_mac_address(FAR struct bcmf_dev_s *priv, struct ifreq *req)
{
int ret;
uint32_t out_len = 6;
uint32_t out_len = IFHWADDRLEN;
ret = bcmf_cdc_iovar_request(priv, CHIP_STA_INTERFACE, true,
IOVAR_STR_CUR_ETHERADDR, addr,
&out_len);
IOVAR_STR_CUR_ETHERADDR,
(uint8_t*)req->ifr_hwaddr.sa_data,
&out_len);
if (ret != OK)
{
return ret;
}
wlinfo("MAC address updated %02X:%02X:%02X:%02X:%02X:%02X\n",
addr[0], addr[1], addr[2],
addr[3], addr[4], addr[5]);
memcpy(priv->bc_dev.d_mac.ether.ether_addr_octet, addr, ETHER_ADDR_LEN);
req->ifr_hwaddr.sa_data[0], req->ifr_hwaddr.sa_data[1],
req->ifr_hwaddr.sa_data[2], req->ifr_hwaddr.sa_data[3],
req->ifr_hwaddr.sa_data[4], req->ifr_hwaddr.sa_data[5]);
memcpy(priv->bc_dev.d_mac.ether.ether_addr_octet,
req->ifr_hwaddr.sa_data, ETHER_ADDR_LEN);
return OK;
}
@@ -281,6 +293,10 @@ int bcmf_driver_initialize(FAR struct bcmf_dev_s *priv)
bcmf_event_register(priv, bcmf_wl_scan_event_handler, WLC_E_ESCAN_RESULT);
/* Register SET_SSID event */
bcmf_event_register(priv, bcmf_wl_auth_event_handler, WLC_E_SET_SSID);
if (bcmf_event_push_config(priv))
{
return -EIO;
@@ -301,8 +317,25 @@ void bcmf_wl_default_event_handler(FAR struct bcmf_dev_s *priv,
void bcmf_wl_radio_event_handler(FAR struct bcmf_dev_s *priv,
struct bcmf_event_s *event, unsigned int len)
{
wlinfo("Got radio event %d from <%s>\n", bcmf_getle32(&event->type),
event->src_name);
// wlinfo("Got radio event %d from <%s>\n", bcmf_getle32(&event->type),
// event->src_name);
}
void bcmf_wl_auth_event_handler(FAR struct bcmf_dev_s *priv,
struct bcmf_event_s *event, unsigned int len)
{
uint32_t type;
type = bcmf_getle32(&event->type);
wlinfo("Got auth event %d from <%s>\n", type, event->src_name);
if (type == WLC_E_SET_SSID)
{
/* Auth complete */
sem_post(&priv->auth_signal);
}
}
void bcmf_wl_scan_event_handler(FAR struct bcmf_dev_s *priv,
@@ -508,8 +541,6 @@ int bcmf_wl_start_scan(FAR struct bcmf_dev_s *priv)
uint32_t out_len;
uint32_t value;
wlinfo("Enter\n");
/* Set active scan mode */
value = 0;
@@ -517,14 +548,15 @@ int bcmf_wl_start_scan(FAR struct bcmf_dev_s *priv)
if (bcmf_cdc_ioctl(priv, CHIP_STA_INTERFACE, true,
WLC_SET_PASSIVE_SCAN, (uint8_t*)&value, &out_len))
{
return -EIO;
ret = -EIO;
goto exit_failed;
}
/* Lock control_mutex semaphore */
if ((ret = sem_wait(&priv->control_mutex)) != OK)
{
return ret;
goto exit_failed;
}
/* Default request structure */
@@ -581,6 +613,8 @@ exit_free_params:
exit_sem_post:
sem_post(&priv->control_mutex);
priv->scan_status = BCMF_SCAN_DISABLED;
exit_failed:
wlinfo("Failed\n");
return ret;
}
+24 -10
View File
@@ -41,6 +41,7 @@
#include <semaphore.h>
#include <nuttx/net/netdev.h>
#include <net/if.h>
#include <nuttx/wdog.h>
#include <nuttx/wqueue.h>
@@ -65,13 +66,13 @@ struct bcmf_dev_s
bool bc_bifup; /* true:ifup false:ifdown */
WDOG_ID bc_txpoll; /* TX poll timer */
WDOG_ID bc_txtimeout; /* TX timeout timer */
struct work_s bc_irqwork; /* For deferring interrupt work to the work queue */
struct work_s bc_pollwork; /* For deferring poll work to the work queue */
/* This holds the information visible to the NuttX network */
struct net_driver_s bc_dev; /* Network interface structure */
struct net_driver_s bc_dev; /* Network interface structure */
struct bcmf_frame_s *cur_tx_frame; /* Frame used to interface network layer */
/* Event registration array */
@@ -91,35 +92,48 @@ struct bcmf_dev_s
int scan_status; /* Current scan status */
WDOG_ID scan_timeout; /* Scan timeout timer */
struct wl_escan_params *scan_params; /* Current scan parameters */
sem_t auth_signal; /* Authentication notification signal */
};
/* Default bus interface structure */
struct bcmf_bus_dev_s {
struct bcmf_bus_dev_s
{
void (*stop)(FAR struct bcmf_dev_s *priv);
int (*txframe)(FAR struct bcmf_dev_s *priv, struct bcmf_frame_s *frame);
int (*txframe)(FAR struct bcmf_dev_s *priv, struct bcmf_frame_s *frame,
bool control);
struct bcmf_frame_s* (*rxframe)(FAR struct bcmf_dev_s *priv);
/* Frame buffer allocation primitive
/* Frame buffer allocation primitives
* len - requested payload length
* control - true if control frame else false
* block - true to block until free frame is available
*/
struct bcmf_frame_s* (*allocate_frame)(FAR struct bcmf_dev_s *priv,
unsigned int len, bool control, bool block);
unsigned int len, bool block,
bool control);
void (*free_frame)(FAR struct bcmf_dev_s *priv, struct bcmf_frame_s* frame);
};
/* bcmf frame definition */
struct bcmf_frame_s {
uint8_t *base; /* Frame base buffer used by low level layer (SDIO) */
uint8_t *data; /* Payload data (Control, data and event messages) */
unsigned int len; /* Frame buffer size */
struct bcmf_frame_s
{
uint8_t *base; /* Frame base buffer used by low level layer (SDIO) */
uint8_t *data; /* Payload data (Control, data and event messages) */
uint16_t len; /* Frame buffer size */
};
int bcmf_wl_set_mac_address(FAR struct bcmf_dev_s *priv, struct ifreq *req);
int bcmf_wl_enable(FAR struct bcmf_dev_s *priv, bool enable);
int bcmf_wl_start_scan(FAR struct bcmf_dev_s *priv);
int bcmf_wl_is_scan_done(FAR struct bcmf_dev_s *priv);
int bcmf_wl_associate(FAR struct bcmf_dev_s *priv);
#endif /* __DRIVERS_WIRELESS_IEEE80211_BCMF_DRIVER_H */
File diff suppressed because it is too large Load Diff
+47
View File
@@ -0,0 +1,47 @@
/****************************************************************************
* drivers/wireless/ieee80211/bcmf_netdev.h
*
* 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.
*
****************************************************************************/
#ifndef __DRIVERS_WIRELESS_IEEE80211_BCMF_NETDEV_H
#define __DRIVERS_WIRELESS_IEEE80211_BCMF_NETDEV_H
#include "bcmf_driver.h"
int bcmf_netdev_register(FAR struct bcmf_dev_s *priv);
void bcmf_netdev_notify_rx(FAR struct bcmf_dev_s *priv);
void bcmf_netdev_notify_tx_done(FAR struct bcmf_dev_s *priv);
#endif /* __DRIVERS_WIRELESS_IEEE80211_BCMF_NETDEV_H */
+107 -9
View File
@@ -47,6 +47,7 @@
#include <errno.h>
#include <queue.h>
#include <semaphore.h>
#include <assert.h>
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
@@ -60,6 +61,7 @@
#include "bcmf_sdio.h"
#include "bcmf_core.h"
#include "bcmf_sdpcm.h"
#include "bcmf_utils.h"
#include "bcmf_sdio_core.h"
#include "bcmf_sdio_regs.h"
@@ -114,6 +116,13 @@ static int bcmf_sdio_find_block_size(unsigned int size);
/* FIXME remove */
FAR struct bcmf_dev_s *g_sdio_priv;
/* Buffer pool for SDIO bus interface
This pool is shared between all driver devices */
static struct bcmf_sdio_frame g_pktframes[BCMF_PKT_POOL_SIZE];
// TODO free_queue should be static
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -564,16 +573,28 @@ int bcmf_bus_sdio_initialize(FAR struct bcmf_dev_s *priv,
sbus->sleeping = true;
sbus->bus.txframe = bcmf_sdpcm_queue_frame;
sbus->bus.allocate_frame = bcmf_sdpcm_allocate_frame;
sbus->bus.rxframe = bcmf_sdpcm_get_rx_frame;
sbus->bus.allocate_frame = bcmf_sdpcm_alloc_frame;
sbus->bus.free_frame = bcmf_sdpcm_free_frame;
sbus->bus.stop = NULL; // TODO
/* Init transmit frames queue */
if ((ret = sem_init(&sbus->tx_queue_mutex, 0, 1)) != OK)
if ((ret = sem_init(&sbus->queue_mutex, 0, 1)) != OK)
{
goto exit_free_bus;
}
sq_init(&sbus->tx_queue);
sq_init(&sbus->rx_queue);
sq_init(&sbus->free_queue);
/* Setup free buffer list */
// FIXME this should be static to driver
for (ret = 0; ret < BCMF_PKT_POOL_SIZE; ret++)
{
bcmf_dqueue_push(&sbus->free_queue, &g_pktframes[ret].list_entry);
}
/* Init thread semaphore */
@@ -622,7 +643,6 @@ int bcmf_bus_sdio_initialize(FAR struct bcmf_dev_s *priv,
goto exit_uninit_hw;
}
up_mdelay(100);
sbus->ready = true;
@@ -642,7 +662,8 @@ int bcmf_bus_sdio_initialize(FAR struct bcmf_dev_s *priv,
/* Start the waitdog timer */
wd_start(sbus->waitdog, BCMF_WAITDOG_TIMEOUT_TICK, bcmf_sdio_waitdog_timeout, 0);
wd_start(sbus->waitdog, BCMF_WAITDOG_TIMEOUT_TICK, bcmf_sdio_waitdog_timeout,
(wdparm_t)priv);
/* Spawn bcmf daemon thread */
@@ -659,8 +680,6 @@ int bcmf_bus_sdio_initialize(FAR struct bcmf_dev_s *priv,
sbus->thread_id = ret;
/* sdio bus is up and running */
return OK;
@@ -685,7 +704,6 @@ int bcmf_chipinitialize(FAR struct bcmf_sdio_dev_s *sbus)
{
return ret;
}
wlinfo("chip id is 0x%x\n", value);
int chipid = value & 0xffff;
switch (chipid)
@@ -705,11 +723,12 @@ int bcmf_chipinitialize(FAR struct bcmf_sdio_dev_s *sbus)
void bcmf_sdio_waitdog_timeout(int argc, wdparm_t arg1, ...)
{
FAR struct bcmf_dev_s *priv = g_sdio_priv;
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s*)arg1;
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s*)priv->bus;
/* Notify bcmf thread */
wlinfo("Notify bcmf thread\n");
sem_post(&sbus->thread_signal);
}
@@ -739,7 +758,7 @@ int bcmf_sdio_thread(int argc, char **argv)
/* Restart the waitdog timer */
wd_start(sbus->waitdog, BCMF_WAITDOG_TIMEOUT_TICK,
bcmf_sdio_waitdog_timeout, 0);
bcmf_sdio_waitdog_timeout, (wdparm_t)priv);
/* Wake up device */
@@ -789,6 +808,15 @@ int bcmf_sdio_thread(int argc, char **argv)
ret = bcmf_sdpcm_sendframe(priv);
} while (ret == OK);
/* Check if RX frames are available */
if (sbus->intstatus & I_HMB_FRAME_IND)
{
/* Try again */
wlinfo("Try read again\n");
continue;
}
/* If we're done for now, turn off clock request. */
// TODO add wakelock
@@ -798,4 +826,74 @@ int bcmf_sdio_thread(int argc, char **argv)
wlinfo("Exit\n");
return 0;
}
struct bcmf_sdio_frame* bcmf_sdio_allocate_frame(FAR struct bcmf_dev_s *priv,
bool block, bool tx)
{
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s*)priv->bus;
struct bcmf_sdio_frame *sframe;
dq_entry_t *entry = NULL;
while (1)
{
if (sem_wait(&sbus->queue_mutex))
{
PANIC();
}
// if (!tx || sbus->tx_queue_count < BCMF_PKT_POOL_SIZE-1)
{
if ((entry = bcmf_dqueue_pop_tail(&sbus->free_queue)) != NULL)
{
if (tx)
{
sbus->tx_queue_count += 1;
}
sem_post(&sbus->queue_mutex);
break;
}
}
sem_post(&sbus->queue_mutex);
if (block)
{
// TODO use signaling semaphore
wlinfo("alloc failed %d\n", tx);
up_mdelay(100);
continue;
}
wlinfo("No avail buffer\n");
return NULL;
}
sframe = container_of(entry, struct bcmf_sdio_frame, list_entry);
sframe->header.len = HEADER_SIZE + MAX_NET_DEV_MTU;
sframe->header.base = sframe->data;
sframe->header.data = sframe->data;
sframe->tx = tx;
return sframe;
}
void bcmf_sdio_free_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_sdio_frame *sframe)
{
// wlinfo("free %p\n", sframe);
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s*)priv->bus;
if (sem_wait(&sbus->queue_mutex))
{
PANIC();
}
bcmf_dqueue_push(&sbus->free_queue, &sframe->list_entry);
if (sframe->tx)
{
sbus->tx_queue_count -= 1;
}
sem_post(&sbus->queue_mutex);
}
+24 -1
View File
@@ -49,6 +49,10 @@
#include "bcmf_sdio_core.h"
#define HEADER_SIZE 0x12 /* Default sdpcm + bdc header size */
// TODO move to Kconfig
#define BCMF_PKT_POOL_SIZE 4 /* Frame pool size */
/****************************************************************************
* Public Types
****************************************************************************/
@@ -93,8 +97,21 @@ struct bcmf_sdio_dev_s
uint8_t tx_seq; /* Transmit sequence number (next) */
uint8_t rx_seq; /* Receive sequence number (expected) */
sem_t tx_queue_mutex; /* Lock for transmit queue */
sem_t queue_mutex; /* Lock for TX/RX/free queues */
dq_queue_t free_queue; /* Queue of available frames */
dq_queue_t tx_queue; /* Queue of frames to tramsmit */
dq_queue_t rx_queue; /* Queue of frames used to receive */
volatile int tx_queue_count; /* Count of items in TX queue */
};
/* Structure used to manage SDIO frames */
struct bcmf_sdio_frame {
struct bcmf_frame_s header;
bool tx;
dq_entry_t list_entry;
uint8_t data[HEADER_SIZE + MAX_NET_DEV_MTU +
CONFIG_NET_GUARDSIZE];
};
/****************************************************************************
@@ -120,4 +137,10 @@ int bcmf_read_reg(FAR struct bcmf_sdio_dev_s *sbus, uint8_t function,
int bcmf_write_reg(FAR struct bcmf_sdio_dev_s *sbus, uint8_t function,
uint32_t address, uint8_t reg);
struct bcmf_sdio_frame* bcmf_sdio_allocate_frame(FAR struct bcmf_dev_s *priv,
bool block, bool tx);
void bcmf_sdio_free_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_sdio_frame *sframe);
#endif /* __DRIVERS_WIRELESS_IEEE80211_BCMF_SDIO_H */
+150 -145
View File
@@ -42,6 +42,7 @@
#include <debug.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/arch.h>
#include <stddef.h>
@@ -56,6 +57,8 @@
#include "bcmf_bdc.h"
#include "bcmf_utils.h"
#include "bcmf_netdev.h"
#include "bcmf_sdio_regs.h"
/****************************************************************************
@@ -66,9 +69,6 @@
#define SDPCM_EVENT_CHANNEL 1 /* Asynchronous event frame id */
#define SDPCM_DATA_CHANNEL 2 /* Data frame id */
#define container_of(ptr, type, member) \
(type *)( (uint8_t *)(ptr) - offsetof(type,member) )
/****************************************************************************
* Private Types
****************************************************************************/
@@ -85,11 +85,6 @@ struct __attribute__((packed)) bcmf_sdpcm_header {
uint16_t padding;
};
struct bcmf_sdpcm_frame {
struct bcmf_frame_s frame_header;
dq_entry_t list_entry;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@@ -117,9 +112,10 @@ int bcmf_sdpcm_rxfail(FAR struct bcmf_sdio_dev_s *sbus, bool retry)
/* TODO Wait until the packet has been flushed (device/FIFO stable) */
/* Send NAK to retry to read frame */
if (retry)
{
/* Send NAK to retry to read frame */
bcmf_write_sbregb(sbus,
CORE_BUS_REG(sbus->chip->core_base[SDIOD_CORE_ID],
tosbmailbox), SMB_NAK);
@@ -141,18 +137,7 @@ int bcmf_sdpcm_process_header(FAR struct bcmf_sdio_dev_s *sbus,
/* Update tx credits */
// wlinfo("update credit %x %x %x\n", header->credit,
// sbus->tx_seq, sbus->max_seq);
if (header->credit - sbus->tx_seq > 0x40)
{
wlerr("seq %d: max tx seq number error\n", sbus->tx_seq);
sbus->max_seq = sbus->tx_seq + 2;
}
else
{
sbus->max_seq = header->credit;
}
sbus->max_seq = header->credit;
return OK;
}
@@ -161,20 +146,25 @@ int bcmf_sdpcm_process_header(FAR struct bcmf_sdio_dev_s *sbus,
* Public Functions
****************************************************************************/
// FIXME remove
uint8_t tmp_buffer[1024];
int bcmf_sdpcm_readframe(FAR struct bcmf_dev_s *priv)
{
int ret;
uint16_t len, checksum;
struct bcmf_sdpcm_header *header;
struct bcmf_sdpcm_frame *sframe;
struct bcmf_sdio_frame *sframe;
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s*)priv->bus;
/* TODO request free frame buffer */
/* Request free frame buffer */
sframe = (struct bcmf_sdpcm_frame*)tmp_buffer;
header = (struct bcmf_sdpcm_header*)&sframe[1];
sframe = bcmf_sdio_allocate_frame(priv, false, false);
if (sframe == NULL)
{
wlinfo("fail alloc\n");
return -EAGAIN;
}
header = (struct bcmf_sdpcm_header*)sframe->data;
/* Read header */
@@ -193,7 +183,8 @@ int bcmf_sdpcm_readframe(FAR struct bcmf_dev_s *priv)
if (!(len | checksum))
{
return -ENODATA;
ret = -ENODATA;
goto exit_free_frame;
}
if (((~len & 0xffff) ^ checksum) || len < sizeof(struct bcmf_sdpcm_header))
@@ -203,25 +194,23 @@ int bcmf_sdpcm_readframe(FAR struct bcmf_dev_s *priv)
goto exit_abort;
}
// FIXME define for size
if (len > sizeof(tmp_buffer))
if (len > sframe->header.len)
{
wlerr("Frame is too large, cancel %d\n", len);
wlerr("Frame is too large, cancel %d %d\n", len, sframe->header.len);
ret = -ENOMEM;
goto exit_abort;
}
/* Read remaining frame data */
// TODO allocate buffer
ret = bcmf_transfer_bytes(sbus, false, 2, 0, (uint8_t*)header+4, len - 4);
if (ret != OK)
{
ret = -EIO;
goto exit_free_abort;
goto exit_abort;
}
// wlinfo("Receive frame\n");
// wlinfo("Receive frame %p %d\n", sframe, len);
// bcmf_hexdump((uint8_t*)header, header->size, (unsigned int)header);
/* Process and validate header */
@@ -234,19 +223,18 @@ int bcmf_sdpcm_readframe(FAR struct bcmf_dev_s *priv)
goto exit_free_frame;
}
/* Setup new frame structure */
/* Update frame structure */
sframe->frame_header.len = header->size;
sframe->frame_header.data = (uint8_t*)header + header->data_offset;
sframe->frame_header.base = (uint8_t*)header;
sframe->header.len = header->size;
sframe->header.data += header->data_offset;
/* Process received frame content */
switch (header->channel & 0x0f)
{
case SDPCM_CONTROL_CHANNEL:
ret = bcmf_cdc_process_control_frame(priv, &sframe->frame_header);
break;
ret = bcmf_cdc_process_control_frame(priv, &sframe->header);
goto exit_free_frame;
case SDPCM_EVENT_CHANNEL:
if (header->data_offset == header->size)
@@ -257,34 +245,49 @@ int bcmf_sdpcm_readframe(FAR struct bcmf_dev_s *priv)
}
else
{
ret = bcmf_bdc_process_event_frame(priv, &sframe->frame_header);
ret = bcmf_bdc_process_event_frame(priv, &sframe->header);
}
break;
goto exit_free_frame;
case SDPCM_DATA_CHANNEL:
ret = bcmf_bdc_process_data_frame(priv, &sframe->frame_header);
/* Queue frame and notify network layer frame is available */
if (sem_wait(&sbus->queue_mutex))
{
PANIC();
}
bcmf_dqueue_push(&sbus->rx_queue, &sframe->list_entry);
sem_post(&sbus->queue_mutex);
bcmf_netdev_notify_rx(priv);
/* Upper layer have to free all received frames */
ret = OK;
break;
default:
wlerr("Got unexpected message type %d\n", header->channel);
ret = OK;
ret = -EINVAL;
goto exit_free_frame;
}
exit_free_frame:
// TODO free frame buffer
return ret;
exit_free_abort:
// TODO free frame buffer
exit_abort:
bcmf_sdpcm_rxfail(sbus, false);
exit_free_frame:
bcmf_sdio_free_frame(priv, sframe);
return ret;
}
int bcmf_sdpcm_sendframe(FAR struct bcmf_dev_s *priv)
{
int ret;
struct bcmf_sdpcm_frame *sframe;
bool is_txframe;
dq_entry_t *entry;
struct bcmf_sdio_frame *sframe;
struct bcmf_sdpcm_header *header;
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s*)priv->bus;
@@ -303,25 +306,25 @@ int bcmf_sdpcm_sendframe(FAR struct bcmf_dev_s *priv)
}
if ((ret = sem_wait(&sbus->tx_queue_mutex)) != OK)
if (sem_wait(&sbus->queue_mutex))
{
return ret;
PANIC();
}
sframe = container_of(sbus->tx_queue.tail,
struct bcmf_sdpcm_frame, list_entry);
header = (struct bcmf_sdpcm_header*)sframe->frame_header.base;
entry = sbus->tx_queue.tail;
sframe = container_of(entry, struct bcmf_sdio_frame, list_entry);
header = (struct bcmf_sdpcm_header*)sframe->header.base;
/* Set frame sequence id */
header->sequence = sbus->tx_seq++;
// wlinfo("Send frame\n");
// bcmf_hexdump(sframe->frame_header.base, sframe->frame_header.len,
// (unsigned long)sframe->frame_header.base);
// wlinfo("Send frame %p\n", sframe);
// bcmf_hexdump(sframe->header.base, sframe->header.len,
// (unsigned long)sframe->header.base);
ret = bcmf_transfer_bytes(sbus, true, 2, 0, sframe->frame_header.base,
sframe->frame_header.len);
ret = bcmf_transfer_bytes(sbus, true, 2, 0, sframe->header.base,
sframe->header.len);
if (ret != OK)
{
wlinfo("fail send frame %d\n", ret);
@@ -332,128 +335,130 @@ int bcmf_sdpcm_sendframe(FAR struct bcmf_dev_s *priv)
/* Frame sent, remove it from queue */
if (sbus->tx_queue.head == &sframe->list_entry)
{
/* List is empty */
bcmf_dqueue_pop_tail(&sbus->tx_queue);
sem_post(&sbus->queue_mutex);
is_txframe = sframe->tx;
sbus->tx_queue.head = NULL;
sbus->tx_queue.tail = NULL;
}
else
/* Free frame buffer */
bcmf_sdio_free_frame(priv, sframe);
if (is_txframe)
{
sbus->tx_queue.tail = sframe->list_entry.blink;
sframe->list_entry.blink->flink = sbus->tx_queue.head;
/* Notify upper layer at least one TX buffer is available */
bcmf_netdev_notify_tx_done(priv);
}
/* TODO free frame buffer */
goto exit_post_sem;
return OK;
exit_abort:
// bcmf_sdpcm_txfail(sbus, false);
exit_post_sem:
sem_post(&sbus->tx_queue_mutex);
sem_post(&sbus->queue_mutex);
return ret;
}
// FIXME remove
uint8_t tmp_buffer2[512];
struct bcmf_frame_s* bcmf_sdpcm_allocate_frame(FAR struct bcmf_dev_s *priv,
unsigned int len, bool control, bool block)
int bcmf_sdpcm_queue_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame, bool control)
{
unsigned int frame_len;
/* Integer overflow check */
if (len > 512)
{
return NULL;
}
frame_len = len + sizeof(struct bcmf_sdpcm_frame)
+ sizeof(struct bcmf_sdpcm_header);
if (!control)
{
/* Data frames needs 2 bytes padding */
frame_len += 2;
}
if (frame_len > 512)
{
return NULL;
}
// FIXME allocate buffer and use max_size instead of 512
// allocate buffer len + sizeof(struct bcmf_sdpcm_frame)
struct bcmf_sdpcm_frame *sframe = (struct bcmf_sdpcm_frame*)tmp_buffer2;
struct bcmf_sdpcm_header *header = (struct bcmf_sdpcm_header*)&sframe[1];
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;
/* Prepare sw header */
memset(header, 0, sizeof(struct bcmf_sdpcm_header));
header->size = frame_len - sizeof(struct bcmf_sdpcm_frame);
header->size = frame->len;
header->checksum = ~header->size;
header->data_offset = (uint8_t)(frame->data - frame->base);
if (control)
{
header->channel = SDPCM_CONTROL_CHANNEL;
header->data_offset = sizeof(struct bcmf_sdpcm_header);
}
else
{
header->channel = SDPCM_DATA_CHANNEL;
header->data_offset = sizeof(struct bcmf_sdpcm_header)+2;
}
sframe->frame_header.len = header->size;
sframe->frame_header.base = (uint8_t*)header;
sframe->frame_header.data = (uint8_t*)header + header->data_offset;
return &sframe->frame_header;
}
int bcmf_sdpcm_queue_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame)
{
int ret;
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s*)priv->bus;
struct bcmf_sdpcm_frame *sframe = (struct bcmf_sdpcm_frame*)frame;
/* Add frame in tx queue */
if ((ret = sem_wait(&sbus->tx_queue_mutex)) != OK)
if (sem_wait(&sbus->queue_mutex))
{
return ret;
PANIC();
}
if (sbus->tx_queue.head == NULL)
{
/* List is empty */
bcmf_dqueue_push(&sbus->tx_queue, &sframe->list_entry);
sbus->tx_queue.head = &sframe->list_entry;
sbus->tx_queue.tail = &sframe->list_entry;
sframe->list_entry.flink = &sframe->list_entry;
sframe->list_entry.blink = &sframe->list_entry;
}
else
{
/* Insert entry at list head */
sframe->list_entry.flink = sbus->tx_queue.head;
sframe->list_entry.blink = sbus->tx_queue.tail;
sbus->tx_queue.head->blink = &sframe->list_entry;
sbus->tx_queue.head = &sframe->list_entry;
}
sem_post(&sbus->tx_queue_mutex);
sem_post(&sbus->queue_mutex);
/* Notify bcmf thread tx frame is ready */
sem_post(&sbus->thread_signal);
return OK;
}
struct bcmf_frame_s* bcmf_sdpcm_alloc_frame(FAR struct bcmf_dev_s *priv,
unsigned int len, bool block,
bool control)
{
struct bcmf_sdio_frame *sframe;
unsigned int header_len = sizeof(struct bcmf_sdpcm_header);
if (!control)
{
header_len += 2; /* Data frames need alignment padding */
}
if (len + header_len > MAX_NET_DEV_MTU + HEADER_SIZE ||
len > len + header_len)
{
wlerr("Invalid size %d\n", len);
return NULL;
}
/* Allocate a frame for RX in case of control frame */
sframe = bcmf_sdio_allocate_frame(priv, block, !control);
if (sframe == NULL)
{
return NULL;
}
sframe->header.len = header_len + len;
sframe->header.data += header_len;
return &sframe->header;
}
void bcmf_sdpcm_free_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame)
{
return bcmf_sdio_free_frame(priv, (struct bcmf_sdio_frame*)frame);
}
struct bcmf_frame_s* bcmf_sdpcm_get_rx_frame(FAR struct bcmf_dev_s *priv)
{
dq_entry_t *entry;
struct bcmf_sdio_frame *sframe;
FAR struct bcmf_sdio_dev_s *sbus = (FAR struct bcmf_sdio_dev_s*)priv->bus;
if (sem_wait(&sbus->queue_mutex))
{
PANIC();
}
entry = bcmf_dqueue_pop_tail(&sbus->rx_queue);
sem_post(&sbus->queue_mutex);
if (entry == NULL)
{
return NULL;
}
sframe = container_of(entry, struct bcmf_sdio_frame, list_entry);
return &sframe->header;
}
+7 -4
View File
@@ -51,10 +51,13 @@ int bcmf_sdpcm_readframe(FAR struct bcmf_dev_s *priv);
int bcmf_sdpcm_sendframe(FAR struct bcmf_dev_s *priv);
int bcmf_sdpcm_queue_frame(FAR struct bcmf_dev_s *priv,
struct bcmf_frame_s *frame);
struct bcmf_frame_s *frame, bool control);
struct bcmf_frame_s *bcmf_sdpcm_allocate_frame(FAR struct bcmf_dev_s *priv,
unsigned int len, bool control,
bool block);
void bcmf_sdpcm_free_frame(FAR struct bcmf_dev_s *priv, struct bcmf_frame_s *frame);
struct bcmf_frame_s* bcmf_sdpcm_alloc_frame(FAR struct bcmf_dev_s *priv,
unsigned int len, bool block, bool control);
struct bcmf_frame_s* bcmf_sdpcm_get_rx_frame(FAR struct bcmf_dev_s *priv);
#endif /* __DRIVERS_WIRELESS_IEEE80211_BCMF_SDPCM_H */
+65
View File
@@ -43,6 +43,7 @@
#include <semaphore.h>
#include <debug.h>
#include <stdio.h>
#include <queue.h>
#include "bcmf_utils.h"
@@ -114,4 +115,68 @@ int bcmf_sem_wait(sem_t *sem, unsigned int timeout_ms)
}
return sem_timedwait(sem, &abstime);
}
void bcmf_dqueue_push(dq_queue_t *queue, dq_entry_t *entry)
{
if (queue->head == NULL)
{
/* List is empty */
queue->tail = entry;
entry->flink = entry;
entry->blink = entry;
}
else
{
/* Insert entry at list head */
entry->flink = queue->head;
entry->blink = queue->tail;
queue->head->blink = entry;
}
queue->head = entry;
}
dq_entry_t* bcmf_dqueue_pop_tail(dq_queue_t *queue)
{
dq_entry_t *entry = queue->tail;
if (queue->head == queue->tail)
{
/* List is empty */
queue->head = NULL;
queue->tail = NULL;
}
else
{
/* Pop from queue tail */
queue->tail = entry->blink;
entry->blink->flink = queue->head;
}
return entry;
}
void bcmf_squeue_push(sq_queue_t *queue, sq_entry_t *entry)
{
entry->flink = queue->head;
queue->head = entry;
}
sq_entry_t* bcmf_squeue_pop(sq_queue_t *queue)
{
sq_entry_t *entry = queue->head;
if (queue->head != NULL)
{
queue->head = entry->flink;
}
return entry;
}
+10
View File
@@ -42,6 +42,10 @@
#include <stdint.h>
#include <semaphore.h>
#include <queue.h>
#define container_of(ptr, type, member) \
(type *)( (uint8_t *)(ptr) - offsetof(type,member) )
/****************************************************************************
* Public Function Prototypes
@@ -51,6 +55,12 @@ void bcmf_hexdump(uint8_t *data, unsigned int len, unsigned long offset);
int bcmf_sem_wait(sem_t *sem, unsigned int timeout_ms);
sq_entry_t* bcmf_squeue_pop(sq_queue_t *queue);
void bcmf_squeue_push(sq_queue_t *queue, sq_entry_t *entry);
dq_entry_t* bcmf_dqueue_pop_tail(dq_queue_t *queue);
void bcmf_dqueue_push(dq_queue_t *queue, dq_entry_t *entry);
static inline uint16_t bcmf_getle16(uint16_t *val)
{
uint8_t *valb = (uint8_t*)val;