RFCv4: ST-E CW1100/1200 WLAN driver
Subsystems (3)
Here's the fourth patch series, now under drivers/net/wireless
This code submission has seen a fair amount of testing across SDIO and SPI interfaces, using multiple vendors' cw1200 implementations.
It's stabilizing nicely. Except for the fact that IBSS is still broken, I consider this driver ready for submission. As you can tell from the changelog below, there have been a lot of changes since the last submission.
Most of the changes revolve around further simplifying IRQ handling and eliminating various Kconfig flags. API updates to v3.8 kernels, major roaming state machine fixes, eliminating dynamic block ack configuration (due to firmware bugs), and a pile of minor fixes and cleanups round this out.
There are still a couple bits of code present for older (<2.6.36 and <3.2) kernels, which I will strip out for inclusion in compat-drivers once this is mainlined. (Is there a better process I should follow here?)
As always, comments and feedback welcome.
Changes from v3:
* Remove excessive [un]likely() compiler hinting (Pontus Fuchs)
* Update to 3.7 API
* Move from drivers/staging to drivers/net/wireless
* Fix memory leak when FW download fails (Pontus Fuchs)
* Incorrect length calculation for 16-bit I/O (Pontus Fuchs)
* Minor sparse/smatch warnings (Pontus Fuchs)
* Eliminate sbus_ops.reset() and code that it uses
* Elimnate CONFIG_CW1200_DEBUGFS (Pontus Fuchs)
* Use SSID directly out of ieee80211_bss_conf
* Eliminate __devinit/__devexit and friends (Pontus Fuchs)
* Convert CONFIG_CW1200_5GHZ_SUPPORT to a platform data flag (Pontus Fuchs)
* Move NON_POWER_OF_TWO_BLOCKSIZES into platform data
* Move platform data to include/linux
* cfg80211_find_ie -> ieee80211_bss_get_ie (Pontus Fuchs)
* Add proper RCU locking for v3.8 (Pontus Fuchs)
* Convert CONFIG_CW1200_USE_SDIO_IRQ into platform data flag
* Eliminate rid of sbus_ops.irq_enable()
* Elimnate IRQ polling support
* Push IRQ registration into the bus handling code
* Moved code from ap.[ch] into more appropriate places
* Eliminated CONFIG_CW1200_PM
* Elminate workarounds for former bad IRQ handling
* Don't log cmd timeout errors caused by device removal
* Always disable interrupts when irq handler is called
* FW Command timeout now triggers a full connection teardown
* cw1200_unjoin_work() triggers iee80211_connection_loss()
* Schedule unjoin_work() when we've detected a beacon loss event
* Cleanups in tx_unlock code
* Always trigger unjoin_work() when we report a connection loss
* Use threded IRQ handle for GPIO irq (Pontus Fuchs)
* Access Func 0 in standard way (Pontus Fuchs)
* Update to 3.8-rc5 API
* Eliminate dynamic BlockACK policy configuration
* Eliminated a pile of BUG_ON() and WARN_ON() calls
* Prevent deadlock on subsequent cmds after a cmd timeout happens
PATCH 1/14 cw1200: v4: low-level hardware I/O functions
--- drivers/net/wireless/cw1200/hwio.c | 326 +++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/hwio.h | 250 ++++++++++++++++++++++++++++ 2 files changed, 576 insertions(+) create mode 100644 drivers/net/wireless/cw1200/hwio.c create mode 100644 drivers/net/wireless/cw1200/hwio.h
drivers/net/wireless/cw1200/hwio.c new file +326 -0
@@ -0,0 +1,326 @@ +/* +* Low-level device IO routines for ST-Ericsson CW1200 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* Based on: +* ST-Ericsson UMAC CW1200 driver, which is +* Copyright (c) 2010, ST-Ericsson +* Author: Ajitpal Singh <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/types.h> + +#include "cw1200.h" +#include "hwio.h" +#include "sbus.h" + +/* Sdio addr is 4*spi_addr */ +#define SPI_REG_ADDR_TO_SDIO (spi_reg_addr) ((spi_reg_addr) << 2) +#define SDIO_ADDR17BIT (buf_id, mpf, rfu, reg_id_ofs) \ + ((((buf_id) & 0x1F) << 7) \ + | (((mpf) & 1) << 6) \ + | (((rfu) & 1) << 5) \ + | (((reg_id_ofs) & 0x1F) << 0)) +#define MAX_RETRY 3 + + +static int __cw1200_reg_read (struct cw1200_common *priv,u16 addr, +void *buf,size_t buf_len,int buf_id) +{ +u16 addr_sdio; +u32 sdio_reg_addr_17bit ; + +/* Check if buffer is aligned to 4 byte boundary */ +if (WARN_ON (((unsigned long )buf &3 ) && (buf_len >4 ))) { +pr_err ("%s: buffer is not aligned.\n" , __func__); +return -EINVAL ; + } + +/* Convert to SDIO Register Address */ + addr_sdio =SPI_REG_ADDR_TO_SDIO (addr); + sdio_reg_addr_17bit =SDIO_ADDR17BIT (buf_id,0 ,0 , addr_sdio); + +return priv->sbus_ops->sbus_memcpy_fromio (priv->sbus_priv, + sdio_reg_addr_17bit, + buf, buf_len); +} + +static int __cw1200_reg_write (struct cw1200_common *priv,u16 addr, +const void *buf,size_t buf_len,int buf_id) +{ +u16 addr_sdio; +u32 sdio_reg_addr_17bit ; + +/* Convert to SDIO Register Address */ + addr_sdio =SPI_REG_ADDR_TO_SDIO (addr); + sdio_reg_addr_17bit =SDIO_ADDR17BIT (buf_id,0 ,0 , addr_sdio); + +return priv->sbus_ops->sbus_memcpy_toio (priv->sbus_priv, + sdio_reg_addr_17bit, + buf, buf_len); +} + +static inline int __cw1200_reg_read_32 (struct cw1200_common *priv, +u16 addr,u32 *val) +{ +int i =__cw1200_reg_read (priv, addr, val,sizeof (*val),0 ); + *val =le32_to_cpu (*val); +return i; +} + +static inline int __cw1200_reg_write_32 (struct cw1200_common *priv, +u16 addr,u32 val) +{ + val =cpu_to_le32 (val); +return __cw1200_reg_write (priv, addr, &val,sizeof (val),0 ); +} + +static inline int __cw1200_reg_read_16 (struct cw1200_common *priv, +u16 addr,u16 *val) +{ +int i =__cw1200_reg_read (priv, addr, val,sizeof (*val),0 ); + *val =le16_to_cpu (*val); +return i; +} + +static inline int __cw1200_reg_write_16 (struct cw1200_common *priv, +u16 addr,u16 val) +{ + val =cpu_to_le16 (val); +return __cw1200_reg_write (priv, addr, &val,sizeof (val),0 ); +} + +int cw1200_reg_read (struct cw1200_common *priv,u16 addr,void *buf, +size_t buf_len) +{ +int ret; + priv->sbus_ops->lock (priv->sbus_priv); + ret =__cw1200_reg_read (priv, addr, buf, buf_len,0 ); + priv->sbus_ops->unlock (priv->sbus_priv); +return ret; +} + +int cw1200_reg_write (struct cw1200_common *priv,u16 addr,const void *buf, +size_t buf_len) +{ +int ret; + priv->sbus_ops->lock (priv->sbus_priv); + ret =__cw1200_reg_write (priv, addr, buf, buf_len,0 ); + priv->sbus_ops->unlock (priv->sbus_priv); +return ret; +} + +int cw1200_data_read (struct cw1200_common *priv,void *buf,size_t buf_len) +{ +int ret, retry =1 ; + priv->sbus_ops->lock (priv->sbus_priv); + { +int buf_id_rx = priv->buf_id_rx; +while (retry <=MAX_RETRY ) { + ret =__cw1200_reg_read (priv, +ST90TDS_IN_OUT_QUEUE_REG_ID , buf, + buf_len, buf_id_rx +1 ); +if (!ret) { + buf_id_rx = (buf_id_rx +1 ) &3 ; + priv->buf_id_rx = buf_id_rx; +break ; + }else { + retry++; +mdelay (1 ); +pr_err ("%s,error :[%d]\n" , + __func__, ret); + } + } + } + priv->sbus_ops->unlock (priv->sbus_priv); +return ret; +} + +int cw1200_data_write (struct cw1200_common *priv,const void *buf, +size_t buf_len) +{ +int ret, retry =1 ; + priv->sbus_ops->lock (priv->sbus_priv); + { +int buf_id_tx = priv->buf_id_tx; +while (retry <=MAX_RETRY ) { + ret =__cw1200_reg_write (priv, +ST90TDS_IN_OUT_QUEUE_REG_ID , buf, + buf_len, buf_id_tx); +if (!ret) { + buf_id_tx = (buf_id_tx +1 ) &31 ; + priv->buf_id_tx = buf_id_tx; +break ; + }else { + retry++; +mdelay (1 ); +pr_err ("%s,error :[%d]\n" , + __func__, ret); + } + } + } + priv->sbus_ops->unlock (priv->sbus_priv); +return ret; +} + +int cw1200_indirect_read (struct cw1200_common *priv,u32 addr,void *buf, +size_t buf_len,u32 prefetch,u16 port_addr) +{ +u32 val32 =0 ; +int i, ret; + +if ((buf_len /2 ) >=0x1000 ) { +pr_err ("%s: Can't read more than 0xfff words.\n" , + __func__); +return -EINVAL ; + goto out; + } + + priv->sbus_ops->lock (priv->sbus_priv); +/* Write address */ + ret =__cw1200_reg_write_32 (priv,ST90TDS_SRAM_BASE_ADDR_REG_ID , addr); +if (ret <0 ) { +pr_err ("%s: Can't write address register.\n" , + __func__); + goto out; + } + +/* Read CONFIG Register Value - We will read 32 bits */ + ret =__cw1200_reg_read_32 (priv,ST90TDS_CONFIG_REG_ID , &val32); +if (ret <0 ) { +pr_err ("%s: Can't read config register.\n" , + __func__); + goto out; + } + +/* Set PREFETCH bit */ + ret =__cw1200_reg_write_32 (priv,ST90TDS_CONFIG_REG_ID , + val32 | prefetch); +if (ret <0 ) { +pr_err ("%s: Can't write prefetch bit.\n" , + __func__); + goto out; + } + +/* Check for PRE-FETCH bit to be cleared */ +for (i =0 ; i <20 ; i++) { + ret =__cw1200_reg_read_32 (priv,ST90TDS_CONFIG_REG_ID , &val32); +if (ret <0 ) { +pr_err ("%s: Can't check prefetch bit.\n" , + __func__); + goto out; + } +if (!(val32 & prefetch)) +break ; + +mdelay (i); + } + +if (val32 & prefetch) { +pr_err ("%s: Prefetch bit is not cleared.\n" , + __func__); + goto out; + } + +/* Read data port */ + ret =__cw1200_reg_read (priv, port_addr, buf, buf_len,0 ); +if (ret <0 ) { +pr_err ("%s: Can't read data port.\n" , + __func__); + goto out; + } + +out: + priv->sbus_ops->unlock (priv->sbus_priv); +return ret; +} + +int cw1200_apb_write (struct cw1200_common *priv,u32 addr,const void *buf, +size_t buf_len) +{ +int ret; + +if ((buf_len /2 ) >=0x1000 ) { +pr_err ("%s: Can't wrire more than 0xfff words.\n" , + __func__); +return -EINVAL ; + } + + priv->sbus_ops->lock (priv->sbus_priv); + +/* Write address */ + ret =__cw1200_reg_write_32 (priv,ST90TDS_SRAM_BASE_ADDR_REG_ID , addr); +if (ret <0 ) { +pr_err ("%s: Can't write address register.\n" , + __func__); + goto out; + } + +/* Write data port */ + ret =__cw1200_reg_write (priv,ST90TDS_SRAM_DPORT_REG_ID , + buf, buf_len,0 ); +if (ret <0 ) { +pr_err ("%s: Can't write data port.\n" , + __func__); + goto out; + } + +out: + priv->sbus_ops->unlock (priv->sbus_priv); +return ret; +} + +int __cw1200_irq_enable (struct cw1200_common *priv,int enable) +{ +u32 val32; +u16 val16; +int ret; + +if (HIF_8601_SILICON == priv->hw_type) { +/* If device is CW1200 the IRQ enable/disable bits +* are in CONFIG register */ + ret =__cw1200_reg_read_32 (priv,ST90TDS_CONFIG_REG_ID , &val32); +if (ret <0 ) { +pr_err ("%s: enable_irq: can't read config register.\n" , __func__); +return ret; + } + +if (enable) + val32 |=ST90TDS_CONF_IRQ_RDY_ENABLE ; +else + val32 &= ~ST90TDS_CONF_IRQ_RDY_ENABLE ; + + ret =__cw1200_reg_write_32 (priv,ST90TDS_CONFIG_REG_ID , val32); +if (ret <0 ) { +pr_err ("%s: enable_irq: can't write config register.\n" , __func__); +return ret; + } + }else { +/* If device is STLC9000 the IRQ enable/disable bits +* are in CONTROL register */ +/* Enable device interrupts - Both DATA_RDY and WLAN_RDY */ + ret =__cw1200_reg_read_16 (priv,ST90TDS_CONFIG_REG_ID , &val16); +if (ret <0 ) { +pr_err ("%s: enable_irq: can't read control register.\n" , __func__); +return ret; + } + +if (enable) + val16 |=ST90TDS_CONT_IRQ_RDY_ENABLE ; +else + val16 &= ~ST90TDS_CONT_IRQ_RDY_ENABLE ; + + ret =__cw1200_reg_write_16 (priv,ST90TDS_CONFIG_REG_ID , val16); +if (ret <0 ) { +pr_err ("%s: enable_irq: can't write control register.\n" , __func__); +return ret; + } + } +return 0 ; +}
drivers/net/wireless/cw1200/hwio.h new file +250 -0
250 lines not on this page · raw message
Signature · 1 line
1.8.1.2
Re: [PATCH 01/14] cw1200: v4: low-level hardware I/O functions
Quoted 1 line · Solomon Peachy
Signed-off-by Solomon Peachy <[email protected]>
Could you please run your patches through scripts/checkpatch.pl --strict
drivers/net/wireless/cw1200/hwio.c line 58
Quoted 7 lines
drivers/net/wireless/cw1200/hwio.c +5
-0+static int __cw1200_reg_write (struct cw1200_common *priv,u16 addr, +const void *buf,size_t buf_len,int buf_id) +{ +u16 addr_sdio; +u32 sdio_reg_addr_17bit ;
Odd layout with space before semi
[]
drivers/net/wireless/cw1200/hwio.c line 124
Quoted 7 lines
drivers/net/wireless/cw1200/hwio.c +6
-0+int cw1200_data_read (struct cw1200_common *priv,void *buf,size_t buf_len) +{ +int ret, retry =1 ; + priv->sbus_ops->lock (priv->sbus_priv); + { +int buf_id_rx = priv->buf_id_rx;
declare buf_id_rx at the top of the function please and avoid the extra indentation level.
drivers/net/wireless/cw1200/hwio.c line 137
Quoted 13 lines
drivers/net/wireless/cw1200/hwio.c +13
-0+while (retry <=MAX_RETRY ) { + ret =__cw1200_reg_read (priv, +ST90TDS_IN_OUT_QUEUE_REG_ID , buf, + buf_len, buf_id_rx +1 ); +if (!ret) { + buf_id_rx = (buf_id_rx +1 ) &3 ; + priv->buf_id_rx = buf_id_rx; +break ; + }else { + retry++; +mdelay (1 ); +pr_err ("%s,error :[%d]\n" , + __func__, ret);
This would fit on a single line if indented correctly.
If you are always going to use "%s", __func__ you should probably instead add
#define pr_fmt(fmt) KBUILD_MODNAME ":%s: " fmt, __func__
before any include and remove all the "%s"/__func__ uses from the logging messages.
[]
drivers/net/wireless/cw1200/hwio.c line 251
Quoted 8 lines
drivers/net/wireless/cw1200/hwio.c +8
-0+int cw1200_apb_write (struct cw1200_common *priv,u32 addr,const void *buf, +size_t buf_len) +{ +int ret; + +if ((buf_len /2 ) >=0x1000 ) { +pr_err ("%s: Can't wrire more than 0xfff words.\n" , + __func__);
write
Consider using netdev_err instead of pr_err
etc.
Re: [PATCH 01/14] cw1200: v4: low-level hardware I/O functions
Quoted 2 lines · Joe Perches
Could you please run your patches through
scripts/checkpatch.pl--strict
If you think it's bad now, you should have seen the state of the code when I first "inherited" it. :)
Question -- as a matter of policy, is the goal to have a completely clean checkpatch run? I get that there should be no ERRORs, but WARNINGs/CHECKs are not considered fatal for a reason, right?
As I write this, there are 550 WARNINGs and 243 CHECKs in the patch set.
There are three general classes of WARNINGs in the code -- alignment/indentation issues (mostly caused by the conversion to pr_XXX() calls versus printk()), >80char lines (unfortunately resolving these tends to make the code less readable), and a boatload of CamelCase variable names (which this codebase inherited from vendor header files)
I consider the >80 line stuff to be generally noise, but I'll revisit it once everything else is handled.
As for your other suggestions, I'll add them to the to-do list and knock them out as time permits. Now that the major problems are solved, I guess it's time for the tedious patch iteration until it's acceptible for wireless-next.
- Solomon
Signature · 3 lines
Solomon Peachy pizza at shaftnet dot org Melbourne, FL ^^ (mail/jabber/gtalk) ^^ Quidquid latine dictum sit, altum viditur.
Re: [PATCH 01/14] cw1200: v4: low-level hardware I/O functions
Quoted 6 lines · Solomon Peachy
Quoted 2 lines · Joe Perches
Could you please run your patches through
scripts/checkpatch.pl--strictIf you think it's bad now, you should have seen the state of the code when I first "inherited" it. :)
No doubt, but that wasn't my point.
Quoted 3 lines
Question -- as a matter of policy, is the goal to have a completely clean checkpatch run? I get that there should be no ERRORs, but WARNINGs/CHECKs are not considered fatal for a reason, right?
No. It's just a guideline. As far as I'm concerned, ignore every checkpatch message you don't agree with.
Just be aware that there's a tool to help you get your code looking more like what most others generally consider "kernel style".
Though when you add "new" code, stuff like
> + u32 sdio_reg_addr_17bit ;
is untidy because of the space before the semicolon.
Re: [PATCH 01/14] cw1200: v4: low-level hardware I/O functions
Quoted 2 lines · Joe Perches
No. It's just a guideline. As far as I'm concerned, ignore every checkpatch message you don't agree with.
Okay, glad to hear that. (there are still several hundred that should be fixed, but mass renaming variables is a bit of a PITA..)
Quoted 3 lines
Just be aware that there's a tool to help you get your code looking more like what most others generally consider "kernel style".
Yeah, I've known about checkpatch; but when it generates the better part of 800 complaints, sometimes finding the ones that matter is a little difficult.
Quoted 5 lines
Though when you add "new" code, stuff like
> + u32 sdio_reg_addr_17bit ;is untidy because of the space before the semicolon.
No argument from here.
FWIW, while I've worked quite a bit of this codebase, there are still large swaths of this driver I haven't given more than a cursory glance because they haven't needed debugging.
- Solomon
Signature · 3 lines
Solomon Peachy pizza at shaftnet dot org Melbourne, FL ^^ (mail/jabber/gtalk) ^^ Quidquid latine dictum sit, altum viditur.
Re: [PATCH 01/14] cw1200: v4: low-level hardware I/O functions
In reply to Joe PerchesQuoted 6 lines · Joe Perches
Quoted 3 lines
Question -- as a matter of policy, is the goal to have a completely clean checkpatch run? I get that there should be no ERRORs, but WARNINGs/CHECKs are not considered fatal for a reason, right?
No. It's just a guideline. As far as I'm concerned, ignore every checkpatch message you don't agree with.
BTW, I think this is becoming a major problem. I have had discussions with various people who consider checkpatch as some sort of automatic upstream compliance system. I'm a bit worried about that. People should consider just as a tool next to other tools, not as the holy bible.
Joe, when working with checkpatch documentation you could try to emphasise that part (or it might be that you have already done that).
Just my 0.02 EUR.
Signature · 1 line
Kalle Valo
Re: [PATCH 01/14] cw1200: v4: low-level hardware I/O functions
Quoted 6 lines · Kalle Valo
Quoted 4 lines · Joe Perches
Quoted 3 lines
Question -- as a matter of policy, is the goal to have a completely clean checkpatch run? I get that there should be no ERRORs, but WARNINGs/CHECKs are not considered fatal for a reason, right?
Quoted 7 lines
Quoted 2 lines
No. It's just a guideline. As far as I'm concerned, ignore every checkpatch message you don't agree with.
BTW, I think this is becoming a major problem. I have had discussions with various people who consider checkpatch as some sort of automatic upstream compliance system. I'm a bit worried about that. People should consider just as a tool next to other tools, not as the holy bible.
Hi Kalle.
As you probably know, I am not an upstream maintainer.
For drivers/net and drivers/staging, the two primary upstream maintainers do seem to prefer that most all checkpatch messages be addressed before acceptance.
Those two paths are ~20% of all patches.
Most other maintainers don't seem to care so much.
Quoted 2 lines
Joe, when working with checkpatch documentation you could try to emphasise that part (or it might be that you have already done that).
Patches welcome.
cheers, Joe
Re: [PATCH 01/14] cw1200: v4: low-level hardware I/O functions
In reply to Joe PerchesQuoted 2 lines · Joe Perches
Could you please run your patches through
scripts/checkpatch.pl--strict
As an aside, the output of scripts/Lindent actually results in checkpatch ERRORs -- 'u16 *ctrl_reg' gets converted to 'u16 * ctrl_reg', for example.
(Using GNU indent 2.2.11)
- Solomon
Signature · 3 lines
Solomon Peachy pizza at shaftnet dot org Melbourne, FL ^^ (mail/jabber/gtalk) ^^ Quidquid latine dictum sit, altum viditur.
PATCH 1/1 scripts: Remove Lindent and suggestions to use it
Lindent had its last good day more than a decade ago. Time to put it down.
Remove suggestions to use it too.
--- Documentation/CodingStyle | 15 --------------- Documentation/hwmon/submitting-patches | 5 ----- scripts/Lindent | 18 ------------------ 3 files changed, 38 deletions(-) delete mode 100755 scripts/Lindent
Documentation/CodingStyle +0 -15
@@ -514,21 +514,6 @@ values. To do the latter, you can stick the following in your .emacs file: This will make emacs go better with the kernel coding style for C files below ~/src/linux-trees. -But even if you fail in getting emacs to do sane formatting, not -everything is lost: use "indent". - -Now, again, GNU indent has the same brain-dead settings that GNU emacs -has, which is why you need to give it a few command line options. -However, that's not too bad, because even the makers of GNU indent -recognize the authority of K&R (the GNU people aren't evil, they are -just severely misguided in this matter), so you just give indent the -options "-kr -i8" (stands for "K&R, 8 character indents"), or use -"scripts/Lindent", which indents in the latest style. - -"indent" has a lot of options, and especially when it comes to comment -re-formatting you may want to take a look at the man page. But -remember: "indent" is not a fix for bad programming. - Chapter 10: Kconfig configuration files
Documentation/hwmon/submitting-patches +0 -5
@@ -49,11 +49,6 @@ increase the chances of your change being accepted. 3. New drivers -------------- -* Running your patch or driver file(s) through checkpatch does not mean its - formatting is clean. If unsure about formatting in your new driver, run it - through Lindent. Lindent is not perfect, and you may have to do some minor - cleanup, but it is a good start. - * Consider adding yourself to MAINTAINERS. * Document the driver in Documentation/hwmon/<driver_name>.
scripts/Lindent deleted +0 -18
@@ -1,18 +0,0 @@ -#!/bin/sh -PARAM="-npro -kr -i8 -ts8 -sob -l80 -ss -ncs -cp1" -RES=`indent --version` -V1=`echo $RES | cut -d' ' -f3 | cut -d'.' -f1` -V2=`echo $RES | cut -d' ' -f3 | cut -d'.' -f2` -V3=`echo $RES | cut -d' ' -f3 | cut -d'.' -f3` -if [ $V1 -gt 2 ]; then - PARAM="$PARAM -il0" -elif [ $V1 -eq 2 ]; then - if [ $V2 -gt 2 ]; then - PARAM="$PARAM -il0"; - elif [ $V2 -eq 2 ]; then - if [ $V3 -ge 10 ]; then - PARAM="$PARAM -il0" - fi - fi -fi -indent $PARAM "$@"
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
PATCH 2/14 cw1200: v4: Internal TX queue handling and tracking
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/queue.c | 582 ++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/queue.h | 116 +++++++ 2 files changed, 698 insertions(+) create mode 100644 drivers/net/wireless/cw1200/queue.c create mode 100644 drivers/net/wireless/cw1200/queue.h
drivers/net/wireless/cw1200/queue.c new file +582 -0
@@ -0,0 +1,582 @@ +/* +* O(1) TX queue with built-in allocator for ST-Ericsson CW1200 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <net/mac80211.h> +#include <linux/sched.h> +#include "queue.h" +#include "cw1200.h" +#include "debug.h" + +/* private */ struct cw1200_queue_item +{ +struct list_head head; +struct sk_buff *skb; +u32 packetID; +unsigned long queue_timestamp; +unsigned long xmit_timestamp; +struct cw1200_txpriv txpriv; +u8 generation; +}; + +static inline void __cw1200_queue_lock (struct cw1200_queue *queue) +{ +struct cw1200_queue_stats *stats = queue->stats; +if (queue->tx_locked_cnt++ ==0 ) { +pr_debug ("[TX] Queue %d is locked.\n" , + queue->queue_id); +ieee80211_stop_queue (stats->priv->hw, queue->queue_id); + } +} + +static inline void __cw1200_queue_unlock (struct cw1200_queue *queue) +{ +struct cw1200_queue_stats *stats = queue->stats; +BUG_ON (!queue->tx_locked_cnt); +if (--queue->tx_locked_cnt ==0 ) { +pr_debug ("[TX] Queue %d is unlocked.\n" , + queue->queue_id); +ieee80211_wake_queue (stats->priv->hw, queue->queue_id); + } +} + +static inline void cw1200_queue_parse_id (u32 packetID,u8 *queue_generation, +u8 *queue_id, +u8 *item_generation, +u8 *item_id) +{ + *item_id = (packetID >>0 ) &0xFF ; + *item_generation = (packetID >>8 ) &0xFF ; + *queue_id = (packetID >>16 ) &0xFF ; + *queue_generation = (packetID >>24 ) &0xFF ; +} + +static inline u32 cw1200_queue_make_packet_id (u8 queue_generation,u8 queue_id, +u8 item_generation,u8 item_id) +{ +return ((u32 )item_id <<0 ) | + ((u32 )item_generation <<8 ) | + ((u32 )queue_id <<16 ) | + ((u32 )queue_generation <<24 ); +} + +static void cw1200_queue_post_gc (struct cw1200_queue_stats *stats, +struct list_head *gc_list) +{ +struct cw1200_queue_item *item, *tmp; + +list_for_each_entry_safe (item, tmp, gc_list, head) { +list_del (&item->head); + stats->skb_dtor (stats->priv, item->skb, &item->txpriv); +kfree (item); + } +} + +static void cw1200_queue_register_post_gc (struct list_head *gc_list, +struct cw1200_queue_item *item) +{ +struct cw1200_queue_item *gc_item; + gc_item =kmalloc (sizeof (struct cw1200_queue_item ), +GFP_ATOMIC ); +BUG_ON (!gc_item); +memcpy (gc_item, item,sizeof (struct cw1200_queue_item )); +list_add_tail (&gc_item->head, gc_list); +} + +static void __cw1200_queue_gc (struct cw1200_queue *queue, +struct list_head *head, +bool unlock) +{ +struct cw1200_queue_stats *stats = queue->stats; +struct cw1200_queue_item *item =NULL , *tmp; +bool wakeup_stats = false; + +list_for_each_entry_safe (item, tmp, &queue->queue, head) { +if (jiffies - item->queue_timestamp < queue->ttl) +break ; + --queue->num_queued; + --queue->link_map_cache[item->txpriv.link_id]; +spin_lock_bh (&stats->lock); + --stats->num_queued; +if (!--stats->link_map_cache[item->txpriv.link_id]) + wakeup_stats = true; +spin_unlock_bh (&stats->lock); +cw1200_debug_tx_ttl (stats->priv); +cw1200_queue_register_post_gc (head, item); + item->skb =NULL ; +list_move_tail (&item->head, &queue->free_pool); + } + +if (wakeup_stats) +wake_up (&stats->wait_link_id_empty); + +if (queue->overfull) { +if (queue->num_queued <= (queue->capacity >>1 )) { + queue->overfull = false; +if (unlock) +__cw1200_queue_unlock (queue); + }else if (item) { +unsigned long tmo = item->queue_timestamp + queue->ttl; +mod_timer (&queue->gc, tmo); +cw1200_pm_stay_awake (&stats->priv->pm_state, + tmo - jiffies); + } + } +} + +static void cw1200_queue_gc (unsigned long arg) +{ +LIST_HEAD (list); +struct cw1200_queue *queue = + (struct cw1200_queue *)arg; + +spin_lock_bh (&queue->lock); +__cw1200_queue_gc (queue, &list, true); +spin_unlock_bh (&queue->lock); +cw1200_queue_post_gc (queue->stats, &list); +} + +int cw1200_queue_stats_init (struct cw1200_queue_stats *stats, +size_t map_capacity, +cw1200_queue_skb_dtor_t skb_dtor, +struct cw1200_common *priv) +{ +memset (stats,0 ,sizeof (*stats)); + stats->map_capacity = map_capacity; + stats->skb_dtor = skb_dtor; + stats->priv = priv; +spin_lock_init (&stats->lock); +init_waitqueue_head (&stats->wait_link_id_empty); + + stats->link_map_cache =kzalloc (sizeof (int ) * map_capacity, +GFP_KERNEL ); +if (!stats->link_map_cache) +return -ENOMEM ; + +return 0 ; +} + +int cw1200_queue_init (struct cw1200_queue *queue, +struct cw1200_queue_stats *stats, +u8 queue_id, +size_t capacity, +unsigned long ttl) +{ +size_t i; + +memset (queue,0 ,sizeof (*queue)); + queue->stats = stats; + queue->capacity = capacity; + queue->queue_id = queue_id; + queue->ttl = ttl; +INIT_LIST_HEAD (&queue->queue); +INIT_LIST_HEAD (&queue->pending); +INIT_LIST_HEAD (&queue->free_pool); +spin_lock_init (&queue->lock); +init_timer (&queue->gc); + queue->gc.data = (unsigned long )queue; + queue->gc.function = cw1200_queue_gc; + + queue->pool =kzalloc (sizeof (struct cw1200_queue_item ) * capacity, +GFP_KERNEL ); +if (!queue->pool) +return -ENOMEM ; + + queue->link_map_cache =kzalloc (sizeof (int ) * stats->map_capacity, +GFP_KERNEL ); +if (!queue->link_map_cache) { +kfree (queue->pool); + queue->pool =NULL ; +return -ENOMEM ; + } + +for (i =0 ; i < capacity; ++i) +list_add_tail (&queue->pool[i].head, &queue->free_pool); + +return 0 ; +} + +int cw1200_queue_clear (struct cw1200_queue *queue) +{ +int i; +LIST_HEAD (gc_list); +struct cw1200_queue_stats *stats = queue->stats; +struct cw1200_queue_item *item, *tmp; + +spin_lock_bh (&queue->lock); + queue->generation++; +list_splice_tail_init (&queue->queue, &queue->pending); +list_for_each_entry_safe (item, tmp, &queue->pending, head) { +WARN_ON (!item->skb); +cw1200_queue_register_post_gc (&gc_list, item); + item->skb =NULL ; +list_move_tail (&item->head, &queue->free_pool); + } + queue->num_queued =0 ; + queue->num_pending =0 ; + +spin_lock_bh (&stats->lock); +for (i =0 ; i < stats->map_capacity; ++i) { + stats->num_queued -= queue->link_map_cache[i]; + stats->link_map_cache[i] -= queue->link_map_cache[i]; + queue->link_map_cache[i] =0 ; + } +spin_unlock_bh (&stats->lock); +if (queue->overfull) { + queue->overfull = false; +__cw1200_queue_unlock (queue); + } +spin_unlock_bh (&queue->lock); +wake_up (&stats->wait_link_id_empty); +cw1200_queue_post_gc (stats, &gc_list); +return 0 ; +} + +void cw1200_queue_stats_deinit (struct cw1200_queue_stats *stats) +{ +kfree (stats->link_map_cache); + stats->link_map_cache =NULL ; +} + +void cw1200_queue_deinit (struct cw1200_queue *queue) +{ +cw1200_queue_clear (queue); +del_timer_sync (&queue->gc); +INIT_LIST_HEAD (&queue->free_pool); +kfree (queue->pool); +kfree (queue->link_map_cache); + queue->pool =NULL ; + queue->link_map_cache =NULL ; + queue->capacity =0 ; +} + +size_t cw1200_queue_get_num_queued (struct cw1200_queue *queue, +u32 link_id_map) +{ +size_t ret; +int i, bit; +size_t map_capacity = queue->stats->map_capacity; + +if (!link_id_map) +return 0 ; + +spin_lock_bh (&queue->lock); +if (link_id_map == (u32) -1 ) + ret = queue->num_queued - queue->num_pending; +else { + ret =0 ; +for (i =0 , bit =1 ; i < map_capacity; ++i, bit <<=1 ) { +if (link_id_map & bit) + ret += queue->link_map_cache[i]; + } + } +spin_unlock_bh (&queue->lock); +return ret; +} + +int cw1200_queue_put (struct cw1200_queue *queue, +struct sk_buff *skb, +struct cw1200_txpriv *txpriv) +{ +int ret =0 ; +LIST_HEAD (gc_list); +struct cw1200_queue_stats *stats = queue->stats; + +if (txpriv->link_id >= queue->stats->map_capacity) +return -EINVAL ; + +spin_lock_bh (&queue->lock); +if (!WARN_ON (list_empty (&queue->free_pool))) { +struct cw1200_queue_item *item =list_first_entry ( + &queue->free_pool, struct cw1200_queue_item, head); +BUG_ON (item->skb); + +list_move_tail (&item->head, &queue->queue); + item->skb = skb; + item->txpriv = *txpriv; + item->generation =0 ; + item->packetID =cw1200_queue_make_packet_id ( + queue->generation, queue->queue_id, + item->generation, item - queue->pool); + item->queue_timestamp = jiffies; + + ++queue->num_queued; + ++queue->link_map_cache[txpriv->link_id]; + +spin_lock_bh (&stats->lock); + ++stats->num_queued; + ++stats->link_map_cache[txpriv->link_id]; +spin_unlock_bh (&stats->lock); + +/* +* TX may happen in parallel sometimes. +* Leave extra queue slots so we don't overflow. +*/ +if (queue->overfull == false && + queue->num_queued >= + (queue->capacity - (num_present_cpus () -1 ))) { + queue->overfull = true; +__cw1200_queue_lock (queue); +mod_timer (&queue->gc, jiffies); + } + }else { + ret = -ENOENT ; + } +spin_unlock_bh (&queue->lock); +return ret; +} + +int cw1200_queue_get (struct cw1200_queue *queue, +u32 link_id_map, +struct wsm_tx **tx, +struct ieee80211_tx_info **tx_info, +const struct cw1200_txpriv **txpriv) +{ +int ret = -ENOENT ; +struct cw1200_queue_item *item; +struct cw1200_queue_stats *stats = queue->stats; +bool wakeup_stats = false; + +spin_lock_bh (&queue->lock); +list_for_each_entry (item, &queue->queue, head) { +if (link_id_map &BIT (item->txpriv.link_id)) { + ret =0 ; +break ; + } + } + +if (!WARN_ON (ret)) { + *tx = (struct wsm_tx *)item->skb->data; + *tx_info =IEEE80211_SKB_CB (item->skb); + *txpriv = &item->txpriv; + (*tx)->packetID =__cpu_to_le32 (item->packetID); +list_move_tail (&item->head, &queue->pending); + ++queue->num_pending; + --queue->link_map_cache[item->txpriv.link_id]; + item->xmit_timestamp = jiffies; + +spin_lock_bh (&stats->lock); + --stats->num_queued; +if (!--stats->link_map_cache[item->txpriv.link_id]) + wakeup_stats = true; +spin_unlock_bh (&stats->lock); + } +spin_unlock_bh (&queue->lock); +if (wakeup_stats) +wake_up (&stats->wait_link_id_empty); +return ret; +} + +int cw1200_queue_requeue (struct cw1200_queue *queue,u32 packetID) +{ +int ret =0 ; +u8 queue_generation, queue_id, item_generation, item_id; +struct cw1200_queue_item *item; +struct cw1200_queue_stats *stats = queue->stats; + +cw1200_queue_parse_id (packetID, &queue_generation, &queue_id, + &item_generation, &item_id); + + item = &queue->pool[item_id]; + +spin_lock_bh (&queue->lock); +BUG_ON (queue_id != queue->queue_id); +if (queue_generation != queue->generation) { + ret = -ENOENT ; + }else if (item_id >= (unsigned ) queue->capacity) { +WARN_ON (1 ); + ret = -EINVAL ; + }else if (item->generation != item_generation) { +WARN_ON (1 ); + ret = -ENOENT ; + }else { + --queue->num_pending; + ++queue->link_map_cache[item->txpriv.link_id]; + +spin_lock_bh (&stats->lock); + ++stats->num_queued; + ++stats->link_map_cache[item->txpriv.link_id]; +spin_unlock_bh (&stats->lock); + + item->generation = ++item_generation; + item->packetID =cw1200_queue_make_packet_id ( + queue_generation, queue_id, item_generation, item_id); +list_move (&item->head, &queue->queue); + } +spin_unlock_bh (&queue->lock); +return ret; +} + +int cw1200_queue_requeue_all (struct cw1200_queue *queue) +{ +struct cw1200_queue_item *item, *tmp; +struct cw1200_queue_stats *stats = queue->stats; +spin_lock_bh (&queue->lock); + +list_for_each_entry_safe_reverse (item, tmp, &queue->pending, head) { + + --queue->num_pending; + ++queue->link_map_cache[item->txpriv.link_id]; + +spin_lock_bh (&stats->lock); + ++stats->num_queued; + ++stats->link_map_cache[item->txpriv.link_id]; +spin_unlock_bh (&stats->lock); + + ++item->generation; + item->packetID =cw1200_queue_make_packet_id ( + queue->generation, queue->queue_id, + item->generation, item - queue->pool); +list_move (&item->head, &queue->queue); + } +spin_unlock_bh (&queue->lock); + +return 0 ; +} + +int cw1200_queue_remove (struct cw1200_queue *queue,u32 packetID) +{ +int ret =0 ; +u8 queue_generation, queue_id, item_generation, item_id; +struct cw1200_queue_item *item; +struct cw1200_queue_stats *stats = queue->stats; +struct sk_buff *gc_skb =NULL ; +struct cw1200_txpriv gc_txpriv; + +cw1200_queue_parse_id (packetID, &queue_generation, &queue_id, + &item_generation, &item_id); + + item = &queue->pool[item_id]; + +spin_lock_bh (&queue->lock); +BUG_ON (queue_id != queue->queue_id); +if (queue_generation != queue->generation) { + ret = -ENOENT ; + }else if (item_id >= (unsigned ) queue->capacity) { +WARN_ON (1 ); + ret = -EINVAL ; + }else if (item->generation != item_generation) { +WARN_ON (1 ); + ret = -ENOENT ; + }else { + gc_txpriv = item->txpriv; + gc_skb = item->skb; + item->skb =NULL ; + --queue->num_pending; + --queue->num_queued; + ++queue->num_sent; + ++item->generation; +/* Do not use list_move_tail here, but list_move: +* try to utilize cache row. +*/ +list_move (&item->head, &queue->free_pool); + +if (queue->overfull && + (queue->num_queued <= (queue->capacity >>1 ))) { + queue->overfull = false; +__cw1200_queue_unlock (queue); + } + } +spin_unlock_bh (&queue->lock); + +if (gc_skb) + stats->skb_dtor (stats->priv, gc_skb, &gc_txpriv); + +return ret; +} + +int cw1200_queue_get_skb (struct cw1200_queue *queue,u32 packetID, +struct sk_buff **skb, +const struct cw1200_txpriv **txpriv) +{ +int ret =0 ; +u8 queue_generation, queue_id, item_generation, item_id; +struct cw1200_queue_item *item; +cw1200_queue_parse_id (packetID, &queue_generation, &queue_id, + &item_generation, &item_id); + + item = &queue->pool[item_id]; + +spin_lock_bh (&queue->lock); +BUG_ON (queue_id != queue->queue_id); +if (queue_generation != queue->generation) { + ret = -ENOENT ; + }else if (item_id >= (unsigned ) queue->capacity) { +WARN_ON (1 ); + ret = -EINVAL ; + }else if (item->generation != item_generation) { +WARN_ON (1 ); + ret = -ENOENT ; + }else { + *skb = item->skb; + *txpriv = &item->txpriv; + } +spin_unlock_bh (&queue->lock); +return ret; +} + +void cw1200_queue_lock (struct cw1200_queue *queue) +{ +spin_lock_bh (&queue->lock); +__cw1200_queue_lock (queue); +spin_unlock_bh (&queue->lock); +} + +void cw1200_queue_unlock (struct cw1200_queue *queue) +{ +spin_lock_bh (&queue->lock); +__cw1200_queue_unlock (queue); +spin_unlock_bh (&queue->lock); +} + +bool cw1200_queue_get_xmit_timestamp (struct cw1200_queue *queue, +unsigned long *timestamp, +u32 pending_frame_id) +{ +struct cw1200_queue_item *item; +bool ret; + +spin_lock_bh (&queue->lock); + ret = !list_empty (&queue->pending); +if (ret) { +list_for_each_entry (item, &queue->pending, head) { +if (item->packetID != pending_frame_id) +if (time_before (item->xmit_timestamp, + *timestamp)) + *timestamp = item->xmit_timestamp; + } + } +spin_unlock_bh (&queue->lock); +return ret; +} + +bool cw1200_queue_stats_is_empty (struct cw1200_queue_stats *stats, +u32 link_id_map) +{ +bool empty = true; + +spin_lock_bh (&stats->lock); +if (link_id_map == (u32)-1 ) + empty = stats->num_queued ==0 ; +else { +int i; +for (i =0 ; i < stats->map_capacity; ++i) { +if (link_id_map &BIT (i)) { +if (stats->link_map_cache[i]) { + empty = false; +break ; + } + } + } + } +spin_unlock_bh (&stats->lock); + +return empty; +}
drivers/net/wireless/cw1200/queue.h new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 3/14 cw1200: v4: Scanning implementation
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/scan.c | 475 +++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/scan.h | 56 +++++ 2 files changed, 531 insertions(+) create mode 100644 drivers/net/wireless/cw1200/scan.c create mode 100644 drivers/net/wireless/cw1200/scan.h
drivers/net/wireless/cw1200/scan.c new file +475 -0
@@ -0,0 +1,475 @@ +/* +* Scan implementation for ST-Ericsson CW1200 mac80211 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/sched.h> +#include "cw1200.h" +#include "scan.h" +#include "sta.h" +#include "pm.h" + +static void cw1200_scan_restart_delayed (struct cw1200_common *priv); + +static int cw1200_scan_start (struct cw1200_common *priv,struct wsm_scan *scan) +{ +int ret, i; +int tmo =2000 ; + +switch (priv->join_status) { +case CW1200_JOIN_STATUS_PRE_STA : +case CW1200_JOIN_STATUS_JOINING : +return -EBUSY ; +default : +break ; + } + +for (i =0 ; i < scan->numOfChannels; ++i) + tmo += scan->ch[i].maxChannelTime +10 ; + +cancel_delayed_work_sync (&priv->clear_recent_scan_work); +atomic_set (&priv->scan.in_progress,1 ); +atomic_set (&priv->recent_scan,1 ); +cw1200_pm_stay_awake (&priv->pm_state, tmo *HZ /1000 ); +queue_delayed_work (priv->workqueue, &priv->scan.timeout, + tmo *HZ /1000 ); + ret =wsm_scan (priv, scan); +if (ret) { +atomic_set (&priv->scan.in_progress,0 ); +cancel_delayed_work_sync (&priv->scan.timeout); +cw1200_scan_restart_delayed (priv); + } +return ret; +} + +int cw1200_hw_scan (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +struct cfg80211_scan_request *req) +{ +struct cw1200_common *priv = hw->priv; +struct wsm_template_frame frame = { + .frame_type =WSM_FRAME_TYPE_PROBE_REQUEST , + }; +int i, ret; + +if (!priv->vif) +return -EINVAL ; + +/* Scan when P2P_GO corrupt firmware MiniAP mode */ +if (priv->join_status ==CW1200_JOIN_STATUS_AP ) +return -EOPNOTSUPP ; + +if (req->n_ssids ==1 && !req->ssids[0 ].ssid_len) + req->n_ssids =0 ; + +wiphy_dbg (hw->wiphy,"[SCAN] Scan request for %d SSIDs.\n" , + req->n_ssids); + +if (req->n_ssids >WSM_SCAN_MAX_NUM_OF_SSIDS ) +return -EINVAL ; + + frame.skb =ieee80211_probereq_get (hw, priv->vif,NULL ,0 , + req->ie_len); +if (!frame.skb) +return -ENOMEM ; + +if (req->ie_len) +memcpy (skb_put (frame.skb, req->ie_len), req->ie, req->ie_len); + +/* will be unlocked in cw1200_scan_work() */ +down (&priv->scan.lock); +mutex_lock (&priv->conf_mutex); + + ret =wsm_set_template_frame (priv, &frame); +if (!ret) { +/* Host want to be the probe responder. */ + ret =wsm_set_probe_responder (priv, true); + } +if (ret) { +mutex_unlock (&priv->conf_mutex); +up (&priv->scan.lock); +dev_kfree_skb (frame.skb); +return ret; + } + +wsm_lock_tx (priv); + +BUG_ON (priv->scan.req); + priv->scan.req = req; + priv->scan.n_ssids =0 ; + priv->scan.status =0 ; + priv->scan.begin = &req->channels[0 ]; + priv->scan.curr = priv->scan.begin; + priv->scan.end = &req->channels[req->n_channels]; + priv->scan.output_power = priv->output_power; + +for (i =0 ; i < req->n_ssids; ++i) { +struct wsm_ssid *dst = + &priv->scan.ssids[priv->scan.n_ssids]; +memcpy (&dst->ssid[0 ], req->ssids[i].ssid, +sizeof (dst->ssid)); + dst->length = req->ssids[i].ssid_len; + ++priv->scan.n_ssids; + } + +mutex_unlock (&priv->conf_mutex); + +if (frame.skb) +dev_kfree_skb (frame.skb); +queue_work (priv->workqueue, &priv->scan.work); +return 0 ; +} + +void cw1200_scan_work (struct work_struct *work) +{ + struct cw1200_common *priv = container_of(work, struct cw1200_common, + scan.work); +struct ieee80211_channel **it; +struct wsm_scan scan = { + .scanType =WSM_SCAN_TYPE_FOREGROUND , + .scanFlags =WSM_SCAN_FLAG_SPLIT_METHOD , + }; +bool first_run = priv->scan.begin == priv->scan.curr && + priv->scan.begin != priv->scan.end; +int i; + +if (first_run) { +/* Firmware gets crazy if scan request is sent +* when STA is joined but not yet associated. +* Force unjoin in this case. */ +if (cancel_delayed_work_sync (&priv->join_timeout) >0 ) +cw1200_join_timeout (&priv->join_timeout.work); + } + +mutex_lock (&priv->conf_mutex); + +if (first_run) { +if (priv->join_status ==CW1200_JOIN_STATUS_STA && + !(priv->powersave_mode.pmMode &WSM_PSM_PS )) { +struct wsm_set_pm pm = priv->powersave_mode; + pm.pmMode =WSM_PSM_PS ; +cw1200_set_pm (priv, &pm); + }else if (priv->join_status ==CW1200_JOIN_STATUS_MONITOR ) { +/* FW bug: driver has to restart p2p-dev mode +* after scan */ +cw1200_disable_listening (priv); + } + } + +if (!priv->scan.req || (priv->scan.curr == priv->scan.end)) { +if (priv->scan.output_power != priv->output_power) +WARN_ON (wsm_set_output_power (priv, + priv->output_power *10 )); +if (priv->join_status ==CW1200_JOIN_STATUS_STA && + !(priv->powersave_mode.pmMode &WSM_PSM_PS )) +cw1200_set_pm (priv, &priv->powersave_mode); + +if (priv->scan.status <0 ) +wiphy_dbg (priv->hw->wiphy, +"[SCAN] Scan failed (%d).\n" , + priv->scan.status); +else if (priv->scan.req) +wiphy_dbg (priv->hw->wiphy, +"[SCAN] Scan completed.\n" ); +else +wiphy_dbg (priv->hw->wiphy, +"[SCAN] Scan canceled.\n" ); + + priv->scan.req =NULL ; +cw1200_scan_restart_delayed (priv); +wsm_unlock_tx (priv); +mutex_unlock (&priv->conf_mutex); +ieee80211_scan_completed (priv->hw, priv->scan.status ?1 :0 ); +up (&priv->scan.lock); +return ; + }else { +struct ieee80211_channel *first = *priv->scan.curr; +for (it = priv->scan.curr +1 , i =1 ; + it != priv->scan.end && i <WSM_SCAN_MAX_NUM_OF_CHANNELS ; + ++it, ++i) { +if ((*it)->band != first->band) +break ; +if (((*it)->flags ^ first->flags) & +IEEE80211_CHAN_PASSIVE_SCAN ) +break ; +if (!(first->flags &IEEE80211_CHAN_PASSIVE_SCAN ) && + (*it)->max_power != first->max_power) +break ; + } + scan.band = first->band; + +if (priv->scan.req->no_cck) + scan.maxTransmitRate =WSM_TRANSMIT_RATE_6 ; +else + scan.maxTransmitRate =WSM_TRANSMIT_RATE_1 ; + scan.numOfProbeRequests = + (first->flags &IEEE80211_CHAN_PASSIVE_SCAN ) ?0 :2 ; + scan.numOfSSIDs = priv->scan.n_ssids; + scan.ssids = &priv->scan.ssids[0 ]; + scan.numOfChannels = it - priv->scan.curr; +/* TODO: Is it optimal? */ + scan.probeDelay =100 ; +/* It is not stated in WSM specification, however +* FW team says that driver may not use FG scan +* when joined. */ +if (priv->join_status ==CW1200_JOIN_STATUS_STA ) { + scan.scanType =WSM_SCAN_TYPE_BACKGROUND ; + scan.scanFlags =WSM_SCAN_FLAG_FORCE_BACKGROUND ; + } + scan.ch =kzalloc ( +sizeof (struct wsm_scan_ch ) * (it - priv->scan.curr), +GFP_KERNEL ); +if (!scan.ch) { + priv->scan.status = -ENOMEM ; + goto fail; + } +for (i =0 ; i < scan.numOfChannels; ++i) { + scan.ch[i].number = priv->scan.curr[i]->hw_value; +if (priv->scan.curr[i]->flags &IEEE80211_CHAN_PASSIVE_SCAN ) { + scan.ch[i].minChannelTime =50 ; + scan.ch[i].maxChannelTime =100 ; + }else { + scan.ch[i].minChannelTime =10 ; + scan.ch[i].maxChannelTime =25 ; + } + } +if (!(first->flags &IEEE80211_CHAN_PASSIVE_SCAN ) && + priv->scan.output_power != first->max_power) { + priv->scan.output_power = first->max_power; +WARN_ON (wsm_set_output_power (priv, + priv->scan.output_power *10 )); + } + priv->scan.status =cw1200_scan_start (priv, &scan); +kfree (scan.ch); +if (priv->scan.status) + goto fail; + priv->scan.curr = it; + } +mutex_unlock (&priv->conf_mutex); +return ; + +fail: + priv->scan.curr = priv->scan.end; +mutex_unlock (&priv->conf_mutex); +queue_work (priv->workqueue, &priv->scan.work); +return ; +} + +static void cw1200_scan_restart_delayed (struct cw1200_common *priv) +{ +if (priv->delayed_link_loss) { +int tmo = priv->cqm_beacon_loss_count; + +if (priv->scan.direct_probe) + tmo =0 ; + + priv->delayed_link_loss =0 ; +/* Restart beacon loss timer and requeue +BSS loss work. */ +wiphy_dbg (priv->hw->wiphy, +"[CQM] Requeue BSS loss in %d beacons.\n" , tmo); +spin_lock (&priv->bss_loss_lock); + priv->bss_loss_status =CW1200_BSS_LOSS_NONE ; + priv->bss_loss_checking =0 ; +spin_unlock (&priv->bss_loss_lock); +cancel_delayed_work_sync (&priv->bss_loss_work); +queue_delayed_work (priv->workqueue, + &priv->bss_loss_work, + tmo *HZ /10 ); + } + +/* FW bug: driver has to restart p2p-dev mode after scan. */ +if (priv->join_status ==CW1200_JOIN_STATUS_MONITOR ) { +cw1200_enable_listening (priv); +cw1200_update_filtering (priv); + } + +if (priv->delayed_unjoin) { + priv->delayed_unjoin = false; +if (queue_work (priv->workqueue, &priv->unjoin_work) <=0 ) +wsm_unlock_tx (priv); + } +} + +static void cw1200_scan_complete (struct cw1200_common *priv) +{ +queue_delayed_work (priv->workqueue, &priv->clear_recent_scan_work,HZ ); +if (priv->scan.direct_probe) { +wiphy_dbg (priv->hw->wiphy,"[SCAN] Direct probe complete.\n" ); +cw1200_scan_restart_delayed (priv); + priv->scan.direct_probe =0 ; +up (&priv->scan.lock); +wsm_unlock_tx (priv); + }else { +cw1200_scan_work (&priv->scan.work); + } +} + +void cw1200_scan_failed_cb (struct cw1200_common *priv) +{ +if (priv->mode ==NL80211_IFTYPE_UNSPECIFIED ) +/* STA is stopped. */ +return ; + +if (cancel_delayed_work_sync (&priv->scan.timeout) >0 ) { + priv->scan.status = -EIO ; +queue_delayed_work (priv->workqueue, + &priv->scan.timeout,0 ); + } +} + + +void cw1200_scan_complete_cb (struct cw1200_common *priv, +struct wsm_scan_complete *arg) +{ +if (priv->mode ==NL80211_IFTYPE_UNSPECIFIED ) +/* STA is stopped. */ +return ; + +if (cancel_delayed_work_sync (&priv->scan.timeout) >0 ) { + priv->scan.status =1 ; +queue_delayed_work (priv->workqueue, + &priv->scan.timeout,0 ); + } +} + +void cw1200_clear_recent_scan_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, clear_recent_scan_work.work); +atomic_xchg (&priv->recent_scan,0 ); +} + +void cw1200_scan_timeout (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, scan.timeout.work); +if (atomic_xchg (&priv->scan.in_progress,0 )) { +if (priv->scan.status >0 ) + priv->scan.status =0 ; +else if (!priv->scan.status) { +wiphy_warn (priv->hw->wiphy, +"Timeout waiting for scan " +"complete notification.\n" ); + priv->scan.status = -ETIMEDOUT ; + priv->scan.curr = priv->scan.end; +WARN_ON (wsm_stop_scan (priv)); + } +cw1200_scan_complete (priv); + } +} + +void cw1200_probe_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, scan.probe_work.work); +u8 queueId =cw1200_queue_get_queue_id (priv->pending_frame_id); +struct cw1200_queue *queue = &priv->tx_queue[queueId]; +const struct cw1200_txpriv *txpriv; +struct wsm_tx *wsm; +struct wsm_template_frame frame = { + .frame_type =WSM_FRAME_TYPE_PROBE_REQUEST , + }; +struct wsm_ssid ssids[1 ] = {{ + .length =0 , + } }; +struct wsm_scan_ch ch[1 ] = {{ + .minChannelTime =0 , + .maxChannelTime =10 , + } }; +struct wsm_scan scan = { + .scanType =WSM_SCAN_TYPE_FOREGROUND , + .numOfProbeRequests =1 , + .probeDelay =0 , + .numOfChannels =1 , + .ssids = ssids, + .ch = ch, + }; +u8 *ies; +size_t ies_len; +int ret; + +wiphy_dbg (priv->hw->wiphy,"[SCAN] Direct probe work.\n" ); + +mutex_lock (&priv->conf_mutex); +if (down_trylock (&priv->scan.lock)) { +/* Scan is already in progress. Requeue self. */ +schedule (); +queue_delayed_work (priv->workqueue, + &priv->scan.probe_work,HZ /10 ); +mutex_unlock (&priv->conf_mutex); +return ; + } + +if (cw1200_queue_get_skb (queue, priv->pending_frame_id, + &frame.skb, &txpriv)) { +up (&priv->scan.lock); +mutex_unlock (&priv->conf_mutex); +wsm_unlock_tx (priv); +return ; + } + wsm = (struct wsm_tx *)frame.skb->data; + scan.maxTransmitRate = wsm->maxTxRate; + scan.band = (priv->channel->band ==IEEE80211_BAND_5GHZ ) ? +WSM_PHY_BAND_5G :WSM_PHY_BAND_2_4G ; +if (priv->join_status ==CW1200_JOIN_STATUS_STA ) { + scan.scanType =WSM_SCAN_TYPE_BACKGROUND ; + scan.scanFlags =WSM_SCAN_FLAG_FORCE_BACKGROUND ; + } + ch[0 ].number = priv->channel->hw_value; + +skb_pull (frame.skb, txpriv->offset); + + ies = &frame.skb->data[sizeof (struct ieee80211_hdr_3addr )]; + ies_len = frame.skb->len -sizeof (struct ieee80211_hdr_3addr ); + +if (ies_len) { +u8 *ssidie = + (u8 *)cfg80211_find_ie (WLAN_EID_SSID , ies, ies_len); +if (ssidie && ssidie[1 ] && ssidie[1 ] <=sizeof (ssids[0 ].ssid)) { +u8 *nextie = &ssidie[2 + ssidie[1 ]]; +/* Remove SSID from the IE list. It has to be provided +* as a separate argument in cw1200_scan_start call */ + +/* Store SSID localy */ + ssids[0 ].length = ssidie[1 ]; +memcpy (ssids[0 ].ssid, &ssidie[2 ], ssids[0 ].length); + scan.numOfSSIDs =1 ; + +/* Remove SSID from IE list */ + ssidie[1 ] =0 ; +memmove (&ssidie[2 ], nextie, &ies[ies_len] - nextie); +skb_trim (frame.skb, frame.skb->len - ssids[0 ].length); + } + } + +/* FW bug: driver has to restart p2p-dev mode after scan */ +if (priv->join_status ==CW1200_JOIN_STATUS_MONITOR ) +cw1200_disable_listening (priv); + ret =WARN_ON (wsm_set_template_frame (priv, &frame)); + priv->scan.direct_probe =1 ; +if (!ret) { +wsm_flush_tx (priv); + ret =WARN_ON (cw1200_scan_start (priv, &scan)); + } +mutex_unlock (&priv->conf_mutex); + +skb_push (frame.skb, txpriv->offset); +if (!ret) +IEEE80211_SKB_CB (frame.skb)->flags |=IEEE80211_TX_STAT_ACK ; +BUG_ON (cw1200_queue_remove (queue, priv->pending_frame_id)); + +if (ret) { + priv->scan.direct_probe =0 ; +up (&priv->scan.lock); +wsm_unlock_tx (priv); + } + +return ; +}
drivers/net/wireless/cw1200/scan.h new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 4/14 cw1200: v4: Power Management (WoWLAN)
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/pm.c | 375 +++++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/pm.h | 38 ++++ 2 files changed, 413 insertions(+) create mode 100644 drivers/net/wireless/cw1200/pm.c create mode 100644 drivers/net/wireless/cw1200/pm.h
drivers/net/wireless/cw1200/pm.c new file +375 -0
@@ -0,0 +1,375 @@ +/* +* Mac80211 power management API for ST-Ericsson CW1200 drivers +* +* Copyright (c) 2011, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/module.h> +#include <linux/if_ether.h> +#include "cw1200.h" +#include "pm.h" +#include "sta.h" +#include "bh.h" +#include "sbus.h" + +#define CW1200_BEACON_SKIPPING_MULTIPLIER 3 + +struct cw1200_udp_port_filter { +struct wsm_udp_port_filter_hdr hdr; +/* Up to 4 filters are allowed. */ +struct wsm_udp_port_filter filters[WSM_MAX_FILTER_ELEMENTS ]; +} __packed; + +struct cw1200_ether_type_filter { +struct wsm_ether_type_filter_hdr hdr; +/* Up to 4 filters are allowed. */ +struct wsm_ether_type_filter filters[WSM_MAX_FILTER_ELEMENTS ]; +} __packed; + +static struct cw1200_udp_port_filter cw1200_udp_port_filter_on = { + .hdr.nrFilters =2 , + .filters = { + [0 ] = { + .filterAction =WSM_FILTER_ACTION_FILTER_OUT , + .portType =WSM_FILTER_PORT_TYPE_DST , + .udpPort =__cpu_to_le16 (67 ),/* DHCP Bootps */ + }, + [1 ] = { + .filterAction =WSM_FILTER_ACTION_FILTER_OUT , + .portType =WSM_FILTER_PORT_TYPE_DST , + .udpPort =__cpu_to_le16 (68 ),/* DHCP Bootpc */ + }, + } +}; + +static struct wsm_udp_port_filter_hdr cw1200_udp_port_filter_off = { + .nrFilters =0 , +}; + +#ifndef ETH_P_WAPI +#define ETH_P_WAPI 0x88B4 +#endif + +static struct cw1200_ether_type_filter cw1200_ether_type_filter_on = { + .hdr.nrFilters =4 , + .filters = { + [0 ] = { + .filterAction =WSM_FILTER_ACTION_FILTER_IN , + .etherType =__cpu_to_le16 (ETH_P_IP ), + }, + [1 ] = { + .filterAction =WSM_FILTER_ACTION_FILTER_IN , + .etherType =__cpu_to_le16 (ETH_P_PAE ), + }, + [2 ] = { + .filterAction =WSM_FILTER_ACTION_FILTER_IN , + .etherType =__cpu_to_le16 (ETH_P_WAPI ), + }, + [3 ] = { + .filterAction =WSM_FILTER_ACTION_FILTER_IN , + .etherType =__cpu_to_le16 (ETH_P_ARP ), + }, + }, +}; + +static struct wsm_ether_type_filter_hdr cw1200_ether_type_filter_off = { + .nrFilters =0 , +}; + +/* private */ +struct cw1200_suspend_state { +unsigned long bss_loss_tmo; +unsigned long connection_loss_tmo; +unsigned long join_tmo; +unsigned long direct_probe; +unsigned long link_id_gc; +bool beacon_skipping; +u8 prev_ps_mode; +}; + +static void cw1200_pm_stay_awake_tmo (unsigned long arg) +{ +/* XXX what's the point of this ? */ +} + +int cw1200_pm_init (struct cw1200_pm_state *pm, +struct cw1200_common *priv) +{ +spin_lock_init (&pm->lock); + +init_timer (&pm->stay_awake); + pm->stay_awake.data = (unsigned long )pm; + pm->stay_awake.function = cw1200_pm_stay_awake_tmo; + +return 0 ; +} + +void cw1200_pm_deinit (struct cw1200_pm_state *pm) +{ +del_timer_sync (&pm->stay_awake); +} + +void cw1200_pm_stay_awake (struct cw1200_pm_state *pm, +unsigned long tmo) +{ +long cur_tmo; +spin_lock_bh (&pm->lock); + cur_tmo = pm->stay_awake.expires - jiffies; +if (!timer_pending (&pm->stay_awake) || + cur_tmo < (long )tmo) +mod_timer (&pm->stay_awake, jiffies + tmo); +spin_unlock_bh (&pm->lock); +} + +static long cw1200_suspend_work (struct delayed_work *work) +{ +int ret =cancel_delayed_work (work); +long tmo; +if (ret >0 ) { +/* Timer is pending */ + tmo = work->timer.expires - jiffies; +if (tmo <0 ) + tmo =0 ; + }else { + tmo =-1 ; + } +return tmo; +} + +static int cw1200_resume_work (struct cw1200_common *priv, +struct delayed_work *work, +unsigned long tmo) +{ +if ((long )tmo <0 ) +return 1 ; + +return queue_delayed_work (priv->workqueue, work, tmo); +} + +int cw1200_can_suspend (struct cw1200_common *priv) +{ +if (atomic_read (&priv->bh_rx)) { +wiphy_dbg (priv->hw->wiphy,"%s: Suspend interrupted.\n" , + __func__); +return 0 ; + } +return 1 ; +} +EXPORT_SYMBOL_GPL (cw1200_can_suspend); + +int cw1200_wow_suspend (struct ieee80211_hw *hw,struct cfg80211_wowlan *wowlan) +{ +struct cw1200_common *priv = hw->priv; +struct cw1200_pm_state *pm_state = &priv->pm_state; +struct cw1200_suspend_state *state; +int ret; + +spin_lock_bh (&pm_state->lock); + ret =timer_pending (&pm_state->stay_awake); +spin_unlock_bh (&pm_state->lock); +if (ret) +return -EAGAIN ; + +/* Do not suspend when datapath is not idle */ +if (priv->tx_queue_stats.num_queued) +return -EBUSY ; + +/* Make sure there is no configuration requests in progress. */ +if (!mutex_trylock (&priv->conf_mutex)) +return -EBUSY ; + +/* Ensure pending operations are done. +* Note also that wow_suspend must return in ~2.5sec, before +* watchdog is triggered. */ +if (priv->channel_switch_in_progress) + goto revert1; + +/* Do not suspend when join work is scheduled */ +if (work_pending (&priv->join_work)) + goto revert1; + +/* Do not suspend when scanning */ +if (down_trylock (&priv->scan.lock)) + goto revert1; + +/* Lock TX. */ +wsm_lock_tx_async (priv); + +/* Wait to avoid possible race with bh code. +* But do not wait too long... */ +if (wait_event_timeout (priv->bh_evt_wq, + !priv->hw_bufs_used,HZ /10 ) <=0 ) + goto revert2; + +/* Set UDP filter */ +wsm_set_udp_port_filter (priv, &cw1200_udp_port_filter_on.hdr); + +/* Set ethernet frame type filter */ +wsm_set_ether_type_filter (priv, &cw1200_ether_type_filter_on.hdr); + +/* Allocate state */ + state =kzalloc (sizeof (struct cw1200_suspend_state ),GFP_KERNEL ); +if (!state) + goto revert3; + +/* Change to legacy PS while going to suspend */ +if (!priv->vif->p2p && + priv->join_status ==CW1200_JOIN_STATUS_STA && + priv->powersave_mode.pmMode !=WSM_PSM_PS ) { + state->prev_ps_mode = priv->powersave_mode.pmMode; + priv->powersave_mode.pmMode =WSM_PSM_PS ; +cw1200_set_pm (priv, &priv->powersave_mode); +if (wait_event_interruptible_timeout (priv->ps_mode_switch_done, + !priv->ps_mode_switch_in_progress,1 *HZ ) <=0 ) { + goto revert3; + } + } + +/* Store delayed work states. */ + state->bss_loss_tmo = +cw1200_suspend_work (&priv->bss_loss_work); + state->connection_loss_tmo = +cw1200_suspend_work (&priv->connection_loss_work); + state->join_tmo = +cw1200_suspend_work (&priv->join_timeout); + state->direct_probe = +cw1200_suspend_work (&priv->scan.probe_work); + state->link_id_gc = +cw1200_suspend_work (&priv->link_id_gc_work); + +cancel_delayed_work_sync (&priv->clear_recent_scan_work); +atomic_set (&priv->recent_scan,0 ); + +/* Enable beacon skipping */ +if (priv->join_status ==CW1200_JOIN_STATUS_STA + && priv->join_dtim_period + && !priv->has_multicast_subscription) { + state->beacon_skipping = true; +wsm_set_beacon_wakeup_period (priv, + priv->join_dtim_period, +CW1200_BEACON_SKIPPING_MULTIPLIER * + priv->join_dtim_period); + } + +/* Stop serving thread */ +if (cw1200_bh_suspend (priv)) + goto revert4; + + ret =timer_pending (&priv->mcast_timeout); +if (ret) + goto revert5; + +/* Store suspend state */ + pm_state->suspend_state = state; + +/* Enable IRQ wake */ + ret = priv->sbus_ops->power_mgmt (priv->sbus_priv, true); +if (ret) { +wiphy_err (priv->hw->wiphy, +"%s: PM request failed: %d. WoW is disabled.\n" , + __func__, ret); +cw1200_wow_resume (hw); +return -EBUSY ; + } + +/* Force resume if event is coming from the device. */ +if (atomic_read (&priv->bh_rx)) { +cw1200_wow_resume (hw); +return -EAGAIN ; + } + +return 0 ; + +revert5: +WARN_ON (cw1200_bh_resume (priv)); +revert4: +cw1200_resume_work (priv, &priv->bss_loss_work, + state->bss_loss_tmo); +cw1200_resume_work (priv, &priv->connection_loss_work, + state->connection_loss_tmo); +cw1200_resume_work (priv, &priv->join_timeout, + state->join_tmo); +cw1200_resume_work (priv, &priv->scan.probe_work, + state->direct_probe); +cw1200_resume_work (priv, &priv->link_id_gc_work, + state->link_id_gc); +kfree (state); +revert3: +wsm_set_udp_port_filter (priv, &cw1200_udp_port_filter_off); +wsm_set_ether_type_filter (priv, &cw1200_ether_type_filter_off); +revert2: +wsm_unlock_tx (priv); +up (&priv->scan.lock); +revert1: +mutex_unlock (&priv->conf_mutex); +return -EBUSY ; +} + +int cw1200_wow_resume (struct ieee80211_hw *hw) +{ +struct cw1200_common *priv = hw->priv; +struct cw1200_pm_state *pm_state = &priv->pm_state; +struct cw1200_suspend_state *state; + + state = pm_state->suspend_state; + pm_state->suspend_state =NULL ; + +/* Disable IRQ wake */ + priv->sbus_ops->power_mgmt (priv->sbus_priv, false); + +/* Scan.lock must be released before BH is resumed other way +* in case when BSS_LOST command arrived the processing of the +* command will be delayed. */ +up (&priv->scan.lock); + +/* Resume BH thread */ +WARN_ON (cw1200_bh_resume (priv)); + +/* Restores previous PS mode */ +if (!priv->vif->p2p && priv->join_status ==CW1200_JOIN_STATUS_STA ) { + priv->powersave_mode.pmMode = state->prev_ps_mode; +cw1200_set_pm (priv, &priv->powersave_mode); + } + +if (state->beacon_skipping) { +wsm_set_beacon_wakeup_period (priv, priv->beacon_int * + priv->join_dtim_period > +MAX_BEACON_SKIP_TIME_MS ?1 : + priv->join_dtim_period,0 ); + state->beacon_skipping = false; + } + +/* Resume delayed work */ +cw1200_resume_work (priv, &priv->bss_loss_work, + state->bss_loss_tmo); +cw1200_resume_work (priv, &priv->connection_loss_work, + state->connection_loss_tmo); +cw1200_resume_work (priv, &priv->join_timeout, + state->join_tmo); +cw1200_resume_work (priv, &priv->scan.probe_work, + state->direct_probe); +cw1200_resume_work (priv, &priv->link_id_gc_work, + state->link_id_gc); + +/* Remove UDP port filter */ +wsm_set_udp_port_filter (priv, &cw1200_udp_port_filter_off); + +/* Remove ethernet frame type filter */ +wsm_set_ether_type_filter (priv, &cw1200_ether_type_filter_off); + +/* Unlock datapath */ +wsm_unlock_tx (priv); + +/* Unlock configuration mutex */ +mutex_unlock (&priv->conf_mutex); + +/* Free memory */ +kfree (state); + +return 0 ; +}
drivers/net/wireless/cw1200/pm.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Mac80211 power management interface for ST-Ericsson CW1200 mac80211 drivers +* +* Copyright (c) 2011, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef PM_H_INCLUDED +#define PM_H_INCLUDED + +/* ******************************************************************** */ +/* mac80211 API */ + +/* extern */ struct cw1200_common ; +/* private */ struct cw1200_suspend_state ; + +struct cw1200_pm_state { +struct cw1200_suspend_state *suspend_state; +struct timer_list stay_awake; +struct platform_device *pm_dev; +spinlock_t lock; +}; + +int cw1200_pm_init (struct cw1200_pm_state *pm, +struct cw1200_common *priv); +void cw1200_pm_deinit (struct cw1200_pm_state *pm); +void cw1200_pm_stay_awake (struct cw1200_pm_state *pm, +unsigned long tmo); +int cw1200_wow_suspend (struct ieee80211_hw *hw, +struct cfg80211_wowlan *wowlan); +int cw1200_wow_resume (struct ieee80211_hw *hw); +int cw1200_can_suspend (struct cw1200_common *priv); + +#endif
Signature · 1 line
1.8.1.2
PATCH 5/14 cw1200: v4: Firmware loading
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/fwio.c | 531 +++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/fwio.h | 41 +++ 2 files changed, 572 insertions(+) create mode 100644 drivers/net/wireless/cw1200/fwio.c create mode 100644 drivers/net/wireless/cw1200/fwio.h
drivers/net/wireless/cw1200/fwio.c new file +531 -0
@@ -0,0 +1,531 @@ +/* +* Firmware I/O code for mac80211 ST-Ericsson CW1200 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* Based on: +* ST-Ericsson UMAC CW1200 driver which is +* Copyright (c) 2010, ST-Ericsson +* Author: Ajitpal Singh <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/init.h> +#include <linux/vmalloc.h> +#include <linux/sched.h> +#include <linux/firmware.h> + +#include "cw1200.h" +#include "fwio.h" +#include "hwio.h" +#include "sbus.h" +#include "bh.h" + +static int cw1200_get_hw_type (u32 config_reg_val,int *major_revision) +{ +int hw_type =-1 ; +u32 silicon_type = (config_reg_val >>24 ) &0x3 ; +u32 silicon_vers = (config_reg_val >>31 ) &0x1 ; + +/* Check if we have CW1200 or STLC9000 */ +if ((silicon_type ==0x1 ) || (silicon_type ==0x2 )) { + *major_revision = silicon_type; +if (silicon_vers) + hw_type =HIF_8601_VERSATILE ; +else + hw_type =HIF_8601_SILICON ; + }else { + *major_revision =1 ; + hw_type =HIF_9000_SILICON_VERSTAILE ; + } + +return hw_type; +} + +static int cw1200_load_firmware_cw1200 (struct cw1200_common *priv) +{ +int ret, block, num_blocks; +unsigned i; +u32 val32; +u32 put =0 , get =0 ; +u8 *buf =NULL ; +const char *fw_path; +const struct firmware *firmware =NULL ; + +/* Macroses are local. */ +#define APB_WRITE (reg, val) \ + do { \ + ret = cw1200_apb_write_32(priv, CW12000_APB(reg), (val)); \ + if (ret < 0) { \ + pr_err("%s: can't write %s at line %d.\n", \ + __func__, #reg, __LINE__); \ + goto error; \ + } \ + } while (0) +#define APB_READ (reg, val) \ + do { \ + ret = cw1200_apb_read_32(priv, CW12000_APB(reg), &(val)); \ + if (ret < 0) { \ + pr_err("%s: can't read %s at line %d.\n", \ + __func__, #reg, __LINE__); \ + goto error; \ + } \ + } while (0) +#define REG_WRITE (reg, val) \ + do { \ + ret = cw1200_reg_write_32(priv, (reg), (val)); \ + if (ret < 0) { \ + pr_err("%s: can't write %s at line %d.\n", \ + __func__, #reg, __LINE__); \ + goto error; \ + } \ + } while (0) +#define REG_READ (reg, val) \ + do { \ + ret = cw1200_reg_read_32(priv, (reg), &(val)); \ + if (ret < 0) { \ + pr_err("%s: can't read %s at line %d.\n", \ + __func__, #reg, __LINE__); \ + goto error; \ + } \ + } while (0) + +switch (priv->hw_revision) { +case CW1200_HW_REV_CUT10 : + fw_path =FIRMWARE_CUT10 ; +if (!priv->sdd_path) + priv->sdd_path =SDD_FILE_10 ; +break ; +case CW1200_HW_REV_CUT11 : + fw_path =FIRMWARE_CUT11 ; +if (!priv->sdd_path) + priv->sdd_path =SDD_FILE_11 ; +break ; +case CW1200_HW_REV_CUT20 : + fw_path =FIRMWARE_CUT20 ; +if (!priv->sdd_path) + priv->sdd_path =SDD_FILE_20 ; +break ; +case CW1200_HW_REV_CUT22 : + fw_path =FIRMWARE_CUT22 ; +if (!priv->sdd_path) + priv->sdd_path =SDD_FILE_22 ; +break ; +default : +pr_err ("%s: invalid silicon revision %d.\n" , + __func__, priv->hw_revision); +return -EINVAL ; + } + +/* Initialize common registers */ +APB_WRITE (DOWNLOAD_IMAGE_SIZE_REG ,DOWNLOAD_ARE_YOU_HERE ); +APB_WRITE (DOWNLOAD_PUT_REG ,0 ); +APB_WRITE (DOWNLOAD_GET_REG ,0 ); +APB_WRITE (DOWNLOAD_STATUS_REG ,DOWNLOAD_PENDING ); +APB_WRITE (DOWNLOAD_FLAGS_REG ,0 ); + +/* Write the NOP Instruction */ +REG_WRITE (ST90TDS_SRAM_BASE_ADDR_REG_ID ,0xFFF20000 ); +REG_WRITE (ST90TDS_AHB_DPORT_REG_ID ,0xEAFFFFFE ); + +/* Release CPU from RESET */ +REG_READ (ST90TDS_CONFIG_REG_ID , val32); + val32 &= ~ST90TDS_CONFIG_CPU_RESET_BIT ; +REG_WRITE (ST90TDS_CONFIG_REG_ID , val32); + +/* Enable Clock */ + val32 &= ~ST90TDS_CONFIG_CPU_CLK_DIS_BIT ; +REG_WRITE (ST90TDS_CONFIG_REG_ID , val32); + +#ifdef CONFIG_CW1200_ETF +if (etf_mode) + fw_path = etf_firmware; +#endif + +/* Load a firmware file */ + ret =request_firmware (&firmware, fw_path, priv->pdev); +if (ret) { +pr_err ("%s: can't load firmware file %s.\n" , + __func__, fw_path); + goto error; + } + + buf =kmalloc (DOWNLOAD_BLOCK_SIZE ,GFP_KERNEL |GFP_DMA ); +if (!buf) { +pr_err ("%s: can't allocate firmware buffer.\n" , __func__); + ret = -ENOMEM ; + goto error; + } + +/* Check if the bootloader is ready */ +for (i =0 ; i <100 ; i +=1 + i /2 ) { +APB_READ (DOWNLOAD_IMAGE_SIZE_REG , val32); +if (val32 ==DOWNLOAD_I_AM_HERE ) +break ; +mdelay (i); + }/* End of for loop */ + +if (val32 !=DOWNLOAD_I_AM_HERE ) { +pr_err ("%s: bootloader is not ready.\n" , __func__); + ret = -ETIMEDOUT ; + goto error; + } + +/* Calculcate number of download blocks */ + num_blocks = (firmware->size -1 ) /DOWNLOAD_BLOCK_SIZE +1 ; + +/* Updating the length in Download Ctrl Area */ + val32 = firmware->size;/* Explicit cast from size_t to u32 */ +APB_WRITE (DOWNLOAD_IMAGE_SIZE_REG , val32); + +/* Firmware downloading loop */ +for (block =0 ; block < num_blocks ; block++) { +size_t tx_size; +size_t block_size; + +/* check the download status */ +APB_READ (DOWNLOAD_STATUS_REG , val32); +if (val32 !=DOWNLOAD_PENDING ) { +pr_err ("%s: bootloader reported error %d.\n" , + __func__, val32); + ret = -EIO ; + goto error; + } + +/* loop until put - get <= 24K */ +for (i =0 ; i <100 ; i++) { +APB_READ (DOWNLOAD_GET_REG , get); +if ((put - get) <= + (DOWNLOAD_FIFO_SIZE -DOWNLOAD_BLOCK_SIZE )) +break ; +mdelay (i); + } + +if ((put - get) > (DOWNLOAD_FIFO_SIZE -DOWNLOAD_BLOCK_SIZE )) { +pr_err ("%s: Timeout waiting for FIFO.\n" , + __func__); + ret = -ETIMEDOUT ; + goto error; + } + +/* calculate the block size */ + tx_size = block_size =min ((size_t )(firmware->size - put), + (size_t )DOWNLOAD_BLOCK_SIZE ); + +memcpy (buf, &firmware->data[put], block_size); +if (block_size <DOWNLOAD_BLOCK_SIZE ) { +memset (&buf[block_size], +0 ,DOWNLOAD_BLOCK_SIZE - block_size); + tx_size =DOWNLOAD_BLOCK_SIZE ; + } + +/* send the block to sram */ + ret =cw1200_apb_write (priv, +CW12000_APB (DOWNLOAD_FIFO_OFFSET + + (put & (DOWNLOAD_FIFO_SIZE -1 ))), + buf, tx_size); +if (ret <0 ) { +pr_err ("%s: can't write block at line %d.\n" , + __func__, __LINE__); + goto error; + } + +/* update the put register */ + put += block_size; +APB_WRITE (DOWNLOAD_PUT_REG , put); + }/* End of firmware download loop */ + +/* Wait for the download completion */ +for (i =0 ; i <300 ; i +=1 + i /2 ) { +APB_READ (DOWNLOAD_STATUS_REG , val32); +if (val32 !=DOWNLOAD_PENDING ) +break ; +mdelay (i); + } +if (val32 !=DOWNLOAD_SUCCESS ) { +pr_err ("%s: wait for download completion failed. Read: 0x%.8X\n" , __func__, val32); + ret = -ETIMEDOUT ; + goto error; + }else { +pr_info ("Firmware download completed.\n" ); + ret =0 ; + } + +error: +kfree (buf); +if (firmware) +release_firmware (firmware); +return ret; + +#undef APB_WRITE +#undef APB_READ +#undef REG_WRITE +#undef REG_READ +} + + +static int config_reg_read (struct cw1200_common *priv,u32 *val) +{ +switch (priv->hw_type) { +case HIF_9000_SILICON_VERSTAILE : { +u16 val16; +int ret =cw1200_reg_read_16 (priv,ST90TDS_CONFIG_REG_ID , &val16); +if (ret <0 ) +return ret; + *val = val16; +return 0 ; + } +case HIF_8601_VERSATILE : +case HIF_8601_SILICON : +default : +cw1200_reg_read_32 (priv,ST90TDS_CONFIG_REG_ID , val); +break ; + } +return 0 ; +} + +static int config_reg_write (struct cw1200_common *priv,u32 val) +{ +switch (priv->hw_type) { +case HIF_9000_SILICON_VERSTAILE : +return cw1200_reg_write_16 (priv,ST90TDS_CONFIG_REG_ID , (u16 )val); +case HIF_8601_VERSATILE : +case HIF_8601_SILICON : +default : +return cw1200_reg_write_32 (priv,ST90TDS_CONFIG_REG_ID , val); +break ; + } +return 0 ; +} + +int cw1200_load_firmware (struct cw1200_common *priv) +{ +int ret; +int i; +u32 val32; +u16 val16; +int major_revision; + +/* Read CONFIG Register */ + ret =cw1200_reg_read_32 (priv,ST90TDS_CONFIG_REG_ID , &val32); +if (ret <0 ) { +pr_err ("%s: can't read config register.\n" , __func__); + goto out; + } + +if (val32 ==0 || val32 ==0xffffffff ) { +pr_err ("%s: bad config register value (0x%08x)\n" , __func__, val32); + ret = -EIO ; + goto out; + } + + priv->hw_type =cw1200_get_hw_type (val32, &major_revision); +if (priv->hw_type <0 ) { +pr_err ("%s: can't deduct hardware type.\n" , __func__); + ret = -ENOTSUPP ; + goto out; + } + +/* Set DPLL Reg value, and read back to confirm writes work */ + ret =cw1200_reg_write_32 (priv,ST90TDS_TSET_GEN_R_W_REG_ID ,cw1200_dpll_from_clk (priv->hw_refclk)); +if (ret <0 ) { +pr_err ("%s: can't write DPLL register.\n" , __func__); + goto out; + } + +msleep (20 ); + + ret =cw1200_reg_read_32 (priv, +ST90TDS_TSET_GEN_R_W_REG_ID , &val32); +if (ret <0 ) { +pr_err ("%s: can't read DPLL register.\n" , __func__); + goto out; + } + +if (val32 !=cw1200_dpll_from_clk (priv->hw_refclk)) { +pr_err ("%s: unable to initialise DPLL register. Wrote 0x%.8X, read 0x%.8X.\n" , + __func__,cw1200_dpll_from_clk (priv->hw_refclk), val32); + ret = -EIO ; + goto out; + } + +/* Set wakeup bit in device */ + ret =cw1200_reg_read_16 (priv,ST90TDS_CONTROL_REG_ID , &val16); +if (ret <0 ) { +pr_err ("%s: set_wakeup: can't read control register.\n" , __func__); + goto out; + } + + ret =cw1200_reg_write_16 (priv,ST90TDS_CONTROL_REG_ID , + val16 |ST90TDS_CONT_WUP_BIT ); +if (ret <0 ) { +pr_err ("%s: set_wakeup: can't write control register.\n" , __func__); + goto out; + } + +/* Wait for wakeup */ +for (i =0 ; i <300 ; i +=1 + i /2 ) { + ret =cw1200_reg_read_16 (priv, +ST90TDS_CONTROL_REG_ID , &val16); +if (ret <0 ) { +pr_err ("%s: wait_for_wakeup: can't read control register.\n" , __func__); + goto out; + } + +if (val16 &ST90TDS_CONT_RDY_BIT ) +break ; + +msleep (i); + } + +if ((val16 &ST90TDS_CONT_RDY_BIT ) ==0 ) { +pr_err ("%s: wait_for_wakeup: device is not responding.\n" , + __func__); + ret = -ETIMEDOUT ; + goto out; + } + +if (major_revision ==1 ) { +/* CW1200 Hardware detection logic : Check for CUT1.1 */ + ret =cw1200_ahb_read_32 (priv,CW1200_CUT_ID_ADDR , &val32); +if (ret) { +pr_err ("%s: HW detection: can't read CUT ID.\n" , + __func__); + goto out; + } + +switch (val32) { +case CW1200_CUT_11_ID_STR : +pr_info ("Cut 1.1 silicon is detected.\n" ); + priv->hw_revision =CW1200_HW_REV_CUT11 ; +break ; +default : +pr_info ("Cut 1.0 silicon is detected.\n" ); + priv->hw_revision =CW1200_HW_REV_CUT10 ; +break ; + } + +/* According to ST-E, CUT<2.0 has busted BA TID0-3. +Just disable it entirely... */ + priv->ba_rx_tid_mask =0 ; + priv->ba_tx_tid_mask =0 ; + }else if (major_revision ==2 ) { +u32 ar1, ar2, ar3; + ret =cw1200_ahb_read_32 (priv,CW1200_CUT2_ID_ADDR , &ar1); +if (ret) { +pr_err ("%s: (1) HW detection: can't read CUT ID.\n" , + __func__); + goto out; + } + ret =cw1200_ahb_read_32 (priv,CW1200_CUT2_ID_ADDR +4 , &ar2); +if (ret) { +pr_err ("%s: (2) HW detection: can't read CUT ID.\n" , + __func__); + goto out; + } + + ret =cw1200_ahb_read_32 (priv,CW1200_CUT2_ID_ADDR +8 , &ar3); +if (ret) { +pr_err ( +"%s: (3) HW detection: can't read CUT ID.\n" , + __func__); + goto out; + } + +if (ar1 ==CW1200_CUT_22_ID_STR1 && + ar2 ==CW1200_CUT_22_ID_STR2 && + ar3 ==CW1200_CUT_22_ID_STR3 ) { +pr_info ("Cut 2.2 silicon is detected.\n" ); + priv->hw_revision =CW1200_HW_REV_CUT22 ; + }else { +pr_info ("Cut 2.0 silicon is detected.\n" ); + priv->hw_revision =CW1200_HW_REV_CUT20 ; + } + }else { +pr_err ("%s: unsupported silicon major revision %d.\n" , + __func__, major_revision); + ret = -ENOTSUPP ; + goto out; + } + +/* Checking for access mode */ + ret =config_reg_read (priv, &val32); +if (ret <0 ) { +pr_err ("%s: check_access_mode: can't read config register.\n" , __func__); + goto out; + } + +if (!(val32 &ST90TDS_CONFIG_ACCESS_MODE_BIT )) { +pr_err ("%s: check_access_mode: device is already in QUEUE mode.\n" , __func__); + ret = -EINVAL ; + goto out; + } + +switch (priv->hw_type) { +case HIF_8601_SILICON : +pr_info ("%s: CW1200 detected.\n" , __func__); + ret =cw1200_load_firmware_cw1200 (priv); +break ; +case HIF_8601_VERSATILE : +/* TODO: Not implemented yet! +ret = cw1200_load_firmware_cw1100(priv); +*/ + ret = -ENOTSUPP ; + goto out; +case HIF_9000_SILICON_VERSTAILE : +/* TODO: Not implemented yet! +ret = cw1200_load_firmware_stlc9000(priv); +*/ + ret = -ENOTSUPP ; + goto out; +default : +pr_err ("%s: Unknown hardware: %d.\n" , + __func__, priv->hw_type); + ret = -ENOTSUPP ; + goto out; + } +if (ret <0 ) { +pr_err ("%s: can't download firmware.\n" , __func__); + goto out; + } + +/* Enable interrupt signalling */ + priv->sbus_ops->lock (priv->sbus_priv); + ret =__cw1200_irq_enable (priv,1 ); + priv->sbus_ops->unlock (priv->sbus_priv); +if (ret <0 ) + goto unsubscribe; + +/* Configure device for MESSSAGE MODE */ + ret =config_reg_read (priv, &val32); +if (ret <0 ) { +pr_err ("%s: set_mode: can't read config register.\n" , + __func__); + goto unsubscribe; + } + ret =config_reg_write (priv, val32 & ~ST90TDS_CONFIG_ACCESS_MODE_BIT ); +if (ret <0 ) { +pr_err ("%s: set_mode: can't write config register.\n" , + __func__); + goto unsubscribe; + } + +/* Unless we read the CONFIG Register we are +* not able to get an interrupt */ +mdelay (10 ); +config_reg_read (priv, &val32); + +out: +return ret; + +unsubscribe: +/* Disable interrupt signalling */ + priv->sbus_ops->lock (priv->sbus_priv); + ret =__cw1200_irq_enable (priv,0 ); + priv->sbus_ops->unlock (priv->sbus_priv); +return ret; +}
drivers/net/wireless/cw1200/fwio.h new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 6/14 cw1200: v4: Debugging hooks and test tool support
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/debug.c | 673 ++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/debug.h | 100 +++++ drivers/net/wireless/cw1200/itp.c | 737 ++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/itp.h | 150 ++++++++ 4 files changed, 1660 insertions(+) create mode 100644 drivers/net/wireless/cw1200/debug.c create mode 100644 drivers/net/wireless/cw1200/debug.h create mode 100644 drivers/net/wireless/cw1200/itp.c create mode 100644 drivers/net/wireless/cw1200/itp.h
drivers/net/wireless/cw1200/debug.c new file +673 -0
@@ -0,0 +1,673 @@ +/* +* mac80211 glue code for mac80211 ST-Ericsson CW1200 drivers +* DebugFS code +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/module.h> +#include <linux/debugfs.h> +#include <linux/seq_file.h> +#include "cw1200.h" +#include "debug.h" +#include "fwio.h" + +/* join_status */ +static const char *const cw1200_debug_join_status[] = { +"passive" , +"monitor" , +"station (joining)" , +"station (not authenticated yet)" , +"station" , +"access point" , +}; + +/* WSM_JOIN_PREAMBLE_... */ +static const char *const cw1200_debug_preamble[] = { +"long" , +"short" , +"long on 1 and 2 Mbps" , +}; + +static const char *const cw1200_debug_fw_types[] = { +"ETF" , +"WFM" , +"WSM" , +"HI test" , +"Platform test" , +}; + +static const char *const cw1200_debug_link_id[] = { +"OFF" , +"REQ" , +"SOFT" , +"HARD" , +}; + +static const char *cw1200_debug_mode (int mode) +{ +switch (mode) { +case NL80211_IFTYPE_UNSPECIFIED : +return "unspecified" ; +case NL80211_IFTYPE_MONITOR : +return "monitor" ; +case NL80211_IFTYPE_STATION : +return "station" ; +case NL80211_IFTYPE_ADHOC : +return "ad-hok" ; +case NL80211_IFTYPE_MESH_POINT : +return "mesh point" ; +case NL80211_IFTYPE_AP : +return "access point" ; +case NL80211_IFTYPE_P2P_CLIENT : +return "p2p client" ; +case NL80211_IFTYPE_P2P_GO : +return "p2p go" ; +default : +return "unsupported" ; + } +} + +static void cw1200_queue_status_show (struct seq_file *seq, +struct cw1200_queue *q) +{ +int i; +seq_printf (seq,"Queue %d:\n" , q->queue_id); +seq_printf (seq," capacity: %zu\n" , q->capacity); +seq_printf (seq," queued: %zu\n" , q->num_queued); +seq_printf (seq," pending: %zu\n" , q->num_pending); +seq_printf (seq," sent: %zu\n" , q->num_sent); +seq_printf (seq," locked: %s\n" , q->tx_locked_cnt ?"yes" :"no" ); +seq_printf (seq," overfull: %s\n" , q->overfull ?"yes" :"no" ); +seq_puts (seq," link map: 0-> " ); +for (i =0 ; i < q->stats->map_capacity; ++i) +seq_printf (seq,"%.2d " , q->link_map_cache[i]); +seq_printf (seq,"<-%zu\n" , q->stats->map_capacity); +} + +static void cw1200_debug_print_map (struct seq_file *seq, +struct cw1200_common *priv, +const char *label, +u32 map) +{ +int i; +seq_printf (seq,"%s0-> " , label); +for (i =0 ; i < priv->tx_queue_stats.map_capacity; ++i) +seq_printf (seq,"%s " , (map &BIT (i)) ?"**" :".." ); +seq_printf (seq,"<-%zu\n" , priv->tx_queue_stats.map_capacity -1 ); +} + +static int cw1200_status_show (struct seq_file *seq,void *v) +{ +int i; +struct list_head *item; +struct cw1200_common *priv = seq->private; +struct cw1200_debug_priv *d = priv->debug; + +seq_puts (seq,"CW1200 Wireless LAN driver status\n" ); +seq_printf (seq,"Hardware: %d.%d\n" , + priv->wsm_caps.hardwareId, + priv->wsm_caps.hardwareSubId); +seq_printf (seq,"Firmware: %s %d.%d\n" , + cw1200_debug_fw_types[priv->wsm_caps.firmwareType], + priv->wsm_caps.firmwareVersion, + priv->wsm_caps.firmwareBuildNumber); +seq_printf (seq,"FW API: %d\n" , + priv->wsm_caps.firmwareApiVer); +seq_printf (seq,"FW caps: 0x%.4X\n" , + priv->wsm_caps.firmwareCap); +seq_printf (seq,"Mode: %s%s\n" , +cw1200_debug_mode (priv->mode), + priv->listening ?" (listening)" :"" ); +seq_printf (seq,"Assoc: %s\n" , + cw1200_debug_join_status[priv->join_status]); +if (priv->channel) +seq_printf (seq,"Channel: %d%s\n" , + priv->channel->hw_value, + priv->channel_switch_in_progress ? +" (switching)" :"" ); +if (priv->rx_filter.promiscuous) +seq_puts (seq,"Filter: promisc\n" ); +else if (priv->rx_filter.fcs) +seq_puts (seq,"Filter: fcs\n" ); +if (priv->rx_filter.bssid) +seq_puts (seq,"Filter: bssid\n" ); +if (priv->bf_control.bcn_count) +seq_puts (seq,"Filter: beacons\n" ); + +if (priv->enable_beacon || + priv->mode ==NL80211_IFTYPE_AP || + priv->mode ==NL80211_IFTYPE_ADHOC || + priv->mode ==NL80211_IFTYPE_MESH_POINT || + priv->mode ==NL80211_IFTYPE_P2P_GO ) +seq_printf (seq,"Beaconing: %s\n" , + priv->enable_beacon ? +"enabled" :"disabled" ); + +for (i =0 ; i <4 ; ++i) { +seq_printf (seq,"EDCA(%d): %d, %d, %d, %d, %d\n" , i, + priv->edca.params[i].cwMin, + priv->edca.params[i].cwMax, + priv->edca.params[i].aifns, + priv->edca.params[i].txOpLimit, + priv->edca.params[i].maxReceiveLifetime); + } +if (priv->join_status ==CW1200_JOIN_STATUS_STA ) { +static const char *pmMode ="unknown" ; +switch (priv->powersave_mode.pmMode) { +case WSM_PSM_ACTIVE : + pmMode ="off" ; +break ; +case WSM_PSM_PS : + pmMode ="on" ; +break ; +case WSM_PSM_FAST_PS : + pmMode ="dynamic" ; +break ; + } +seq_printf (seq,"Preamble: %s\n" , + cw1200_debug_preamble[ + priv->association_mode.preambleType]); +seq_printf (seq,"AMPDU spcn: %d\n" , + priv->association_mode.mpduStartSpacing); +seq_printf (seq,"Basic rate: 0x%.8X\n" , +le32_to_cpu (priv->association_mode.basicRateSet)); +seq_printf (seq,"Bss lost: %d beacons\n" , + priv->bss_params.beaconLostCount); +seq_printf (seq,"AID: %d\n" , + priv->bss_params.aid); +seq_printf (seq,"Rates: 0x%.8X\n" , + priv->bss_params.operationalRateSet); +seq_printf (seq,"Powersave: %s\n" , pmMode); + } +seq_printf (seq,"HT: %s\n" , +cw1200_is_ht (&priv->ht_info) ?"on" :"off" ); +if (cw1200_is_ht (&priv->ht_info)) { +seq_printf (seq,"Greenfield: %s\n" , +cw1200_ht_greenfield (&priv->ht_info) ?"yes" :"no" ); +seq_printf (seq,"AMPDU dens: %d\n" , +cw1200_ht_ampdu_density (&priv->ht_info)); + } +seq_printf (seq,"RSSI thold: %d\n" , + priv->cqm_rssi_thold); +seq_printf (seq,"RSSI hyst: %d\n" , + priv->cqm_rssi_hyst); +seq_printf (seq,"Bcnloss: %d\n" , + priv->cqm_beacon_loss_count); +seq_printf (seq,"Long retr: %d\n" , + priv->long_frame_max_tx_count); +seq_printf (seq,"Short retr: %d\n" , + priv->short_frame_max_tx_count); +spin_lock_bh (&priv->tx_policy_cache.lock); + i =0 ; +list_for_each (item, &priv->tx_policy_cache.used) + ++i; +spin_unlock_bh (&priv->tx_policy_cache.lock); +seq_printf (seq,"RC in use: %d\n" , i); + +seq_puts (seq,"\n" ); +for (i =0 ; i <4 ; ++i) { +cw1200_queue_status_show (seq, &priv->tx_queue[i]); +seq_puts (seq,"\n" ); + } + +cw1200_debug_print_map (seq, priv,"Link map: " , + priv->link_id_map); +cw1200_debug_print_map (seq, priv,"Asleep map: " , + priv->sta_asleep_mask); +cw1200_debug_print_map (seq, priv,"PSPOLL map: " , + priv->pspoll_mask); + +seq_puts (seq,"\n" ); + +for (i =0 ; i <CW1200_MAX_STA_IN_AP_MODE ; ++i) { +if (priv->link_id_db[i].status) { +seq_printf (seq,"Link %d: %s, %pM\n" , + i +1 , cw1200_debug_link_id[ + priv->link_id_db[i].status], + priv->link_id_db[i].mac); + } + } + +seq_puts (seq,"\n" ); + +seq_printf (seq,"BH status: %s\n" , +atomic_read (&priv->bh_term) ?"terminated" :"alive" ); +seq_printf (seq,"Pending RX: %d\n" , +atomic_read (&priv->bh_rx)); +seq_printf (seq,"Pending TX: %d\n" , +atomic_read (&priv->bh_tx)); +if (priv->bh_error) +seq_printf (seq,"BH errcode: %d\n" , + priv->bh_error); +seq_printf (seq,"TX bufs: %d x %d bytes\n" , + priv->wsm_caps.numInpChBufs, + priv->wsm_caps.sizeInpChBuf); +seq_printf (seq,"Used bufs: %d\n" , + priv->hw_bufs_used); +seq_printf (seq,"Powermgmt: %s\n" , + priv->powersave_enabled ?"on" :"off" ); +seq_printf (seq,"Device: %s\n" , + priv->device_can_sleep ?"asleep" :"awake" ); + +spin_lock (&priv->wsm_cmd.lock); +seq_printf (seq,"WSM status: %s\n" , + priv->wsm_cmd.done ?"idle" :"active" ); +seq_printf (seq,"WSM cmd: 0x%.4X (%td bytes)\n" , + priv->wsm_cmd.cmd, priv->wsm_cmd.len); +seq_printf (seq,"WSM retval: %d\n" , + priv->wsm_cmd.ret); +spin_unlock (&priv->wsm_cmd.lock); + +seq_printf (seq,"Datapath: %s\n" , +atomic_read (&priv->tx_lock) ?"locked" :"unlocked" ); +if (atomic_read (&priv->tx_lock)) +seq_printf (seq,"TXlock cnt: %d\n" , +atomic_read (&priv->tx_lock)); + +seq_printf (seq,"TXed: %d\n" , + d->tx); +seq_printf (seq,"AGG TXed: %d\n" , + d->tx_agg); +seq_printf (seq,"MULTI TXed: %d (%d)\n" , + d->tx_multi, d->tx_multi_frames); +seq_printf (seq,"RXed: %d\n" , + d->rx); +seq_printf (seq,"AGG RXed: %d\n" , + d->rx_agg); +seq_printf (seq,"TX miss: %d\n" , + d->tx_cache_miss); +seq_printf (seq,"TX align: %d\n" , + d->tx_align); +seq_printf (seq,"TX burst: %d\n" , + d->tx_burst); +seq_printf (seq,"TX TTL: %d\n" , + d->tx_ttl); +seq_printf (seq,"Scan: %s\n" , +atomic_read (&priv->scan.in_progress) ?"active" :"idle" ); + +return 0 ; +} + +static int cw1200_status_open (struct inode *inode,struct file *file) +{ +return single_open (file, &cw1200_status_show, + inode->i_private); +} + +static const struct file_operations fops_status = { + .open = cw1200_status_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner =THIS_MODULE , +}; + +static int cw1200_counters_show (struct seq_file *seq,void *v) +{ +int ret; +struct cw1200_common *priv = seq->private; +struct wsm_counters_table counters; + + ret =wsm_get_counters_table (priv, &counters); +if (ret) +return ret; + +#define CAT_STR (x, y) x ## y +#define PUT_COUNTER (tab, name) \ + seq_printf(seq, "%s:" tab "%d\n", #name, \ + __le32_to_cpu(counters.CAT_STR(count, name))) + +PUT_COUNTER ("\t\t" , PlcpErrors); +PUT_COUNTER ("\t\t" , FcsErrors); +PUT_COUNTER ("\t\t" , TxPackets); +PUT_COUNTER ("\t\t" , RxPackets); +PUT_COUNTER ("\t\t" , RxPacketErrors); +PUT_COUNTER ("\t" , RxDecryptionFailures); +PUT_COUNTER ("\t\t" , RxMicFailures); +PUT_COUNTER ("\t" , RxNoKeyFailures); +PUT_COUNTER ("\t" , TxMulticastFrames); +PUT_COUNTER ("\t" , TxFramesSuccess); +PUT_COUNTER ("\t" , TxFrameFailures); +PUT_COUNTER ("\t" , TxFramesRetried); +PUT_COUNTER ("\t" , TxFramesMultiRetried); +PUT_COUNTER ("\t" , RxFrameDuplicates); +PUT_COUNTER ("\t\t" , RtsSuccess); +PUT_COUNTER ("\t\t" , RtsFailures); +PUT_COUNTER ("\t\t" , AckFailures); +PUT_COUNTER ("\t" , RxMulticastFrames); +PUT_COUNTER ("\t" , RxFramesSuccess); +PUT_COUNTER ("\t" , RxCMACICVErrors); +PUT_COUNTER ("\t\t" , RxCMACReplays); +PUT_COUNTER ("\t" , RxMgmtCCMPReplays); + +#undef PUT_COUNTER +#undef CAT_STR + +return 0 ; +} + +static int cw1200_counters_open (struct inode *inode,struct file *file) +{ +return single_open (file, &cw1200_counters_show, + inode->i_private); +} + +static const struct file_operations fops_counters = { + .open = cw1200_counters_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner =THIS_MODULE , +}; + +static int cw1200_generic_open (struct inode *inode,struct file *file) +{ + file->private_data = inode->i_private; +return 0 ; +} + +#ifdef CONFIG_CW1200_ETF +static int cw1200_etf_out_show (struct seq_file *seq,void *v) +{ +struct cw1200_common *priv = seq->private; +struct sk_buff *skb; +u32 len =0 ; + + skb =skb_dequeue (&priv->etf_q); + +if (skb) + len = skb->len; + +seq_write (seq, &len,sizeof (len)); + +if (skb) { +seq_write (seq, skb->data, len); +kfree_skb (skb); + } + +return 0 ; +} + +static int cw1200_etf_out_open (struct inode *inode,struct file *file) +{ +return single_open (file, &cw1200_etf_out_show, + inode->i_private); +} + +static const struct file_operations fops_etf_out = { + .open = cw1200_etf_out_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .owner =THIS_MODULE , +}; + +struct etf_req_msg ; +int ETF_Request (struct cw1200_common *priv,struct etf_req_msg *msg,u32 len); + +#define MAX_RX_SZE 2600 + +struct etf_in_state { +struct cw1200_common *priv; +u32 total_len; +u8 buf[MAX_RX_SZE ]; +u32 written; +}; + +static int cw1200_etf_in_open (struct inode *inode,struct file *file) +{ +struct etf_in_state *etf =kmalloc (sizeof (struct etf_in_state ),GFP_KERNEL ); + +if (!etf) +return -ENOMEM ; + + etf->written =0 ; + etf->total_len =0 ; + etf->priv = inode->i_private; + + file->private_data = etf; + +return 0 ; +} + +static int cw1200_etf_in_release (struct inode *inode,struct file *file) +{ +kfree (file->private_data); +return 0 ; +} + +static ssize_t cw1200_etf_in_write (struct file *file, +const char __user *user_buf,size_t count,loff_t *ppos) +{ +struct etf_in_state *etf = file->private_data; + +ssize_t written =0 ; + +if (!etf->total_len) { +if (count <sizeof (etf->total_len)) { +pr_err ("count < sizeof(total_len)\n" ); +return -EINVAL ; + } + +if (copy_from_user (&etf->total_len, user_buf,sizeof (etf->total_len))) { +pr_err ("copy_from_user (len) failed\n" ); +return -EFAULT ; + } + + written +=sizeof (etf->total_len); + count -=sizeof (etf->total_len); + } + +if (!count) + goto done; + +if (copy_from_user (etf->buf + etf->written, user_buf + written, count)) { +pr_err ("copy_from_user (payload %zu) failed\n" , count); +return -EFAULT ; + } + + written += count; + etf->written += count; + +if (etf->written >= etf->total_len) { +if (ETF_Request (etf->priv, (struct etf_req_msg *)etf->buf, etf->total_len)) { +pr_err ("ETF_Request failed\n" ); +return -EIO ; + } + } + +done: +return written; +} + +static const struct file_operations fops_etf_in = { + .open = cw1200_etf_in_open, + .release = cw1200_etf_in_release, + .write = cw1200_etf_in_write, + .llseek = default_llseek, + .owner =THIS_MODULE , +}; +#endif /* CONFIG_CW1200_ETF */ + +static ssize_t cw1200_wsm_dumps (struct file *file, +const char __user *user_buf,size_t count,loff_t *ppos) +{ +struct cw1200_common *priv = file->private_data; +char buf[1 ]; + +if (!count) +return -EINVAL ; +if (copy_from_user (buf, user_buf,1 )) +return -EFAULT ; + +if (buf[0 ] =='1' ) + priv->wsm_enable_wsm_dumps =1 ; +else + priv->wsm_enable_wsm_dumps =0 ; + +return count; +} + +static const struct file_operations fops_wsm_dumps = { + .open = cw1200_generic_open, + .write = cw1200_wsm_dumps, + .llseek = default_llseek, +}; + +int cw1200_debug_init (struct cw1200_common *priv) +{ +int ret = -ENOMEM ; +struct cw1200_debug_priv *d =kzalloc (sizeof (struct cw1200_debug_priv ), +GFP_KERNEL ); + priv->debug = d; +if (!d) +return ret; + + d->debugfs_phy =debugfs_create_dir ("cw1200" , + priv->hw->wiphy->debugfsdir); +if (!d->debugfs_phy) + goto err; + +if (!debugfs_create_file ("status" ,S_IRUSR , d->debugfs_phy, + priv, &fops_status)) + goto err; + +if (!debugfs_create_file ("counters" ,S_IRUSR , d->debugfs_phy, + priv, &fops_counters)) + goto err; + +#ifdef CONFIG_CW1200_ETF +if (etf_mode) { +skb_queue_head_init (&priv->etf_q); + +if (!debugfs_create_file ("etf_out" ,S_IRUSR , d->debugfs_phy, + priv, &fops_etf_out)) + goto err; +if (!debugfs_create_file ("etf_in" ,S_IWUSR , d->debugfs_phy, + priv, &fops_etf_in)) + goto err; + } +#endif /* CONFIG_CW1200_ETF */ + +if (!debugfs_create_file ("wsm_dumps" ,S_IWUSR , d->debugfs_phy, + priv, &fops_wsm_dumps)) + goto err; + + ret =cw1200_itp_init (priv); +if (ret) + goto err; + +return 0 ; + +err: + priv->debug =NULL ; +debugfs_remove_recursive (d->debugfs_phy); +kfree (d); +return ret; +} + +void cw1200_debug_release (struct cw1200_common *priv) +{ +struct cw1200_debug_priv *d = priv->debug; +if (d) { +cw1200_itp_release (priv); + priv->debug =NULL ; +kfree (d); + } +} + +int cw1200_print_fw_version (struct cw1200_common *priv,u8 *buf,size_t len) +{ +return snprintf (buf, len,"%s %d.%d" , + cw1200_debug_fw_types[priv->wsm_caps.firmwareType], + priv->wsm_caps.firmwareVersion, + priv->wsm_caps.firmwareBuildNumber); +} + +#ifdef CONFIG_CW1200_ETF +struct cw1200_sdd { +u8 id; +u8 len; +u8 data[]; +}; + +struct etf_req_msg { +u32 id; +u32 len; +u8 data[]; +}; + +static int Parse_SDD_File (struct cw1200_common *priv,u8 *data,u32 length) +{ +struct cw1200_sdd *ie; + +while (length >0 ) { + ie = (struct cw1200_sdd *) data; +if (ie->id ==SDD_REFERENCE_FREQUENCY_ELT_ID ) { + priv->hw_refclk =cpu_to_le16 (*((u16 *)ie->data)); +pr_info ("Using Reference clock frequency %d KHz\n" , priv->hw_refclk); +break ; + } + + length -= ie->len +sizeof (*ie); + data += ie->len +sizeof (*ie); + } +return 0 ; +} + +char *etf_firmware; + +#define ST90TDS_START_ADAPTER 0x09/* Loads Firmware and start the adapter */ +#define ST90TDS_STOP_ADAPTER 0x0A/* Stops the adapter */ +#define ST90TDS_CONFIG_ADAPTER 0x0E/* send adapter configuration params */ +#define ST90TDS_SBUS_READ 0x13 +#define ST90TDS_SBUS_WRITE 0x14 +#define ST90TDS_GET_DEVICE_OPTION 0x19 +#define ST90TDS_SET_DEVICE_OPTION 0x1A +#define ST90TDS_SEND_SDD 0x1D/* SDD File used to find DPLL */ + +#include "fwio.h" + +int ETF_Request (struct cw1200_common *priv,struct etf_req_msg *msg,u32 len) +{ +int rval =-1 ; +switch (msg->id) { +case ST90TDS_START_ADAPTER : + etf_firmware ="cw1200_etf.bin" ; +pr_info ("ETF_START (len %d, '%s')\n" , len, etf_firmware); + rval =cw1200_load_firmware (priv); +break ; +case ST90TDS_STOP_ADAPTER : +pr_info ("ETF_STOP (unhandled)\n" ); +break ; +case ST90TDS_SEND_SDD : +pr_info ("ETF_SDD\n" ); + rval =Parse_SDD_File (priv, msg->data, msg->len); +break ; +case ST90TDS_CONFIG_ADAPTER : +pr_info ("ETF_CONFIG_ADAP (unhandled)\n" ); +break ; +case ST90TDS_SBUS_READ : +pr_info ("ETF_SBUS_READ (unhandled)\n" ); +break ; +case ST90TDS_SBUS_WRITE : +pr_info ("ETF_SBUS_WRITE (unhandled)\n" ); +break ; +case ST90TDS_SET_DEVICE_OPTION : +pr_info ("ETF_SET_DEV_OPT (unhandled)\n" ); +break ; +default : +pr_info ("ETF_PASSTHRU (0x%08x)\n" , msg->id); + rval =wsm_raw_cmd (priv, (u8 *)msg, len); +break ; + } + +return rval; +} +#endif /* CONFIG_CW1200_ETF */
drivers/net/wireless/cw1200/debug.h new file +100 -0
100 lines not on this page · raw message
drivers/net/wireless/cw1200/itp.c new file +737 -0
737 lines not on this page · raw message
drivers/net/wireless/cw1200/itp.h new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 7/14 cw1200: v4: mac80211 API implementation
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/sta.c | 2485 +++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/sta.h | 122 ++ 2 files changed, 2607 insertions(+) create mode 100644 drivers/net/wireless/cw1200/sta.c create mode 100644 drivers/net/wireless/cw1200/sta.h
drivers/net/wireless/cw1200/sta.c new file +2485 -0
@@ -0,0 +1,2485 @@ +/* +* Mac80211 STA API for ST-Ericsson CW1200 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/vmalloc.h> +#include <linux/sched.h> +#include <linux/firmware.h> + +#include "cw1200.h" +#include "sta.h" +#include "fwio.h" +#include "bh.h" +#include "debug.h" + +#ifndef ERP_INFO_BYTE_OFFSET +#define ERP_INFO_BYTE_OFFSET 2 +#endif + + +static int cw1200_upload_beacon (struct cw1200_common *priv); +static int cw1200_upload_pspoll (struct cw1200_common *priv); +static int cw1200_upload_null (struct cw1200_common *priv); +static int cw1200_upload_qosnull (struct cw1200_common *priv); +static int cw1200_start_ap (struct cw1200_common *priv); +static int cw1200_update_beaconing (struct cw1200_common *priv); +static int cw1200_enable_beaconing (struct cw1200_common *priv, +bool enable); +static void __cw1200_sta_notify (struct ieee80211_hw *dev, +struct ieee80211_vif *vif, +enum sta_notify_cmd notify_cmd, +int link_id); +static int __cw1200_flush (struct cw1200_common *priv,bool drop); + +static inline void __cw1200_free_event_queue (struct list_head *list) +{ +struct cw1200_wsm_event *event, *tmp; +list_for_each_entry_safe (event, tmp, list, link) { +list_del (&event->link); +kfree (event); + } +} + +static inline void __cw1200_bf_configure (struct cw1200_common *priv) +{ + priv->bf_table.numOfIEs =__cpu_to_le32 (3 ); + priv->bf_table.entry[0 ].ieId =WLAN_EID_VENDOR_SPECIFIC ; + priv->bf_table.entry[0 ].actionFlags =WSM_BEACON_FILTER_IE_HAS_CHANGED | +WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | +WSM_BEACON_FILTER_IE_HAS_APPEARED ; + priv->bf_table.entry[0 ].oui[0 ] =0x50 ; + priv->bf_table.entry[0 ].oui[1 ] =0x6F ; + priv->bf_table.entry[0 ].oui[2 ] =0x9A ; + priv->bf_table.entry[1 ].ieId =WLAN_EID_ERP_INFO ; + priv->bf_table.entry[1 ].actionFlags =WSM_BEACON_FILTER_IE_HAS_CHANGED | +WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | +WSM_BEACON_FILTER_IE_HAS_APPEARED ; + priv->bf_table.entry[2 ].ieId =WLAN_EID_HT_OPERATION ; + priv->bf_table.entry[2 ].actionFlags =WSM_BEACON_FILTER_IE_HAS_CHANGED | +WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | +WSM_BEACON_FILTER_IE_HAS_APPEARED ; + + priv->bf_control.enabled =WSM_BEACON_FILTER_ENABLE ; +} + +/* ******************************************************************** */ +/* STA API */ + +int cw1200_start (struct ieee80211_hw *dev) +{ +struct cw1200_common *priv = dev->priv; +int ret =0 ; + +cw1200_pm_stay_awake (&priv->pm_state,HZ ); + +mutex_lock (&priv->conf_mutex); + +/* default EDCA */ +WSM_EDCA_SET (&priv->edca,0 ,0x0002 ,0x0003 ,0x0007 ,47 ,0xc8 , false); +WSM_EDCA_SET (&priv->edca,1 ,0x0002 ,0x0007 ,0x000f ,94 ,0xc8 , false); +WSM_EDCA_SET (&priv->edca,2 ,0x0003 ,0x000f ,0x03ff ,0 ,0xc8 , false); +WSM_EDCA_SET (&priv->edca,3 ,0x0007 ,0x000f ,0x03ff ,0 ,0xc8 , false); + ret =wsm_set_edca_params (priv, &priv->edca); +if (WARN_ON (ret)) + goto out; + + ret =cw1200_set_uapsd_param (priv, &priv->edca); +if (WARN_ON (ret)) + goto out; + + priv->setbssparams_done = false; + +memcpy (priv->mac_addr, dev->wiphy->perm_addr,ETH_ALEN ); + priv->mode =NL80211_IFTYPE_MONITOR ; + priv->wep_default_key_id =-1 ; + + priv->cqm_beacon_loss_count =20 ; + +/* Temporary configuration - beacon filter table */ +__cw1200_bf_configure (priv); + + ret =cw1200_setup_mac (priv); +if (WARN_ON (ret)) + goto out; + +/* err = cw1200_set_leds(priv); */ + +out: +mutex_unlock (&priv->conf_mutex); +return ret; +} + +void cw1200_stop (struct ieee80211_hw *dev) +{ +struct cw1200_common *priv = dev->priv; +LIST_HEAD (list); +int i; + +wsm_lock_tx (priv); + +while (down_trylock (&priv->scan.lock)) { +/* Scan is in progress. Force it to stop. */ + priv->scan.req =NULL ; +schedule (); + } +up (&priv->scan.lock); + +cancel_delayed_work_sync (&priv->scan.probe_work); +cancel_delayed_work_sync (&priv->scan.timeout); +cancel_delayed_work_sync (&priv->clear_recent_scan_work); +cancel_delayed_work_sync (&priv->join_timeout); +cancel_delayed_work_sync (&priv->bss_loss_work); +cancel_delayed_work_sync (&priv->connection_loss_work); +cancel_work_sync (&priv->unjoin_work); +cancel_delayed_work_sync (&priv->link_id_gc_work); +flush_workqueue (priv->workqueue); +del_timer_sync (&priv->mcast_timeout); +mutex_lock (&priv->conf_mutex); + priv->mode =NL80211_IFTYPE_UNSPECIFIED ; + priv->listening = false; + +spin_lock (&priv->event_queue_lock); +list_splice_init (&priv->event_queue, &list); +spin_unlock (&priv->event_queue_lock); +__cw1200_free_event_queue (&list); + + priv->delayed_link_loss =0 ; +spin_lock (&priv->bss_loss_lock); + priv->bss_loss_status =CW1200_BSS_LOSS_NONE ; + priv->bss_loss_checking =0 ; +spin_unlock (&priv->bss_loss_lock); + + priv->join_status =CW1200_JOIN_STATUS_PASSIVE ; + priv->join_pending =0 ; + +for (i =0 ; i <4 ; i++) +cw1200_queue_clear (&priv->tx_queue[i]); +mutex_unlock (&priv->conf_mutex); +tx_policy_clean (priv); + +/* HACK! */ +if (atomic_xchg (&priv->tx_lock,1 ) !=1 ) +pr_debug ("[STA] TX is force-unlocked due to stop request.\n" ); + +wsm_unlock_tx (priv); +atomic_xchg (&priv->tx_lock,0 );/* for recovery to work */ +} + +int cw1200_add_interface (struct ieee80211_hw *dev, +struct ieee80211_vif *vif) +{ +int ret; +struct cw1200_common *priv = dev->priv; +/* __le32 auto_calibration_mode = __cpu_to_le32(1); */ + + vif->driver_flags |=IEEE80211_VIF_BEACON_FILTER | +IEEE80211_VIF_SUPPORTS_CQM_RSSI ; + +mutex_lock (&priv->conf_mutex); + +if (priv->mode !=NL80211_IFTYPE_MONITOR ) { +mutex_unlock (&priv->conf_mutex); +return -EOPNOTSUPP ; + } + +switch (vif->type) { +case NL80211_IFTYPE_STATION : +case NL80211_IFTYPE_ADHOC : +case NL80211_IFTYPE_MESH_POINT : +case NL80211_IFTYPE_AP : + priv->mode = vif->type; +break ; +default : +mutex_unlock (&priv->conf_mutex); +return -EOPNOTSUPP ; + } + + priv->vif = vif; +memcpy (priv->mac_addr, vif->addr,ETH_ALEN ); + ret =WARN_ON (cw1200_setup_mac (priv)); +/* Enable auto-calibration */ +/* Exception in subsequent channel switch; disabled. +WARN_ON(wsm_write_mib(priv, WSM_MIB_ID_SET_AUTO_CALIBRATION_MODE, +&auto_calibration_mode, sizeof(auto_calibration_mode))); +*/ + +mutex_unlock (&priv->conf_mutex); +return ret; +} + +void cw1200_remove_interface (struct ieee80211_hw *dev, +struct ieee80211_vif *vif) +{ +struct cw1200_common *priv = dev->priv; +struct wsm_reset reset = { + .reset_statistics = true, + }; +int i; + +mutex_lock (&priv->conf_mutex); +wsm_lock_tx (priv); +switch (priv->join_status) { +case CW1200_JOIN_STATUS_JOINING : +case CW1200_JOIN_STATUS_PRE_STA : +case CW1200_JOIN_STATUS_STA : +wsm_lock_tx (priv); +if (queue_work (priv->workqueue, &priv->unjoin_work) <=0 ) +wsm_unlock_tx (priv); +break ; +case CW1200_JOIN_STATUS_AP : +for (i =0 ; priv->link_id_map; ++i) { +if (priv->link_id_map &BIT (i)) { + reset.link_id = i; +wsm_reset (priv, &reset); + priv->link_id_map &= ~BIT (i); + } + } +memset (priv->link_id_db,0 , +sizeof (priv->link_id_db)); + priv->sta_asleep_mask =0 ; + priv->enable_beacon = false; + priv->tx_multicast = false; + priv->aid0_bit_set = false; + priv->buffered_multicasts = false; + priv->pspoll_mask =0 ; + reset.link_id =0 ; +wsm_reset (priv, &reset); +break ; +case CW1200_JOIN_STATUS_MONITOR : +cw1200_update_listening (priv, false); +break ; +default : +break ; + } + priv->vif =NULL ; + priv->mode =NL80211_IFTYPE_MONITOR ; +memset (priv->mac_addr,0 ,ETH_ALEN ); +memset (&priv->p2p_ps_modeinfo,0 ,sizeof (priv->p2p_ps_modeinfo)); +cw1200_free_keys (priv); +cw1200_setup_mac (priv); + priv->listening = false; + priv->join_status =CW1200_JOIN_STATUS_PASSIVE ; +__cw1200_flush (priv, true); +wsm_unlock_tx (priv); + +mutex_unlock (&priv->conf_mutex); +} + +int cw1200_change_interface (struct ieee80211_hw *dev, +struct ieee80211_vif *vif, +enum nl80211_iftype new_type, +bool p2p) +{ +int ret =0 ; +pr_debug ("%s called: new_type: %d (%d), old_type: %d (%d)\n" , __func__, new_type, + p2p, vif->type, vif->p2p); + +if (new_type != vif->type || vif->p2p != p2p) { +cw1200_remove_interface (dev, vif); + vif->type = new_type; + vif->p2p = p2p; + ret =cw1200_add_interface (dev, vif); + } + +return ret; +} + +int cw1200_config (struct ieee80211_hw *dev,u32 changed) +{ +int ret =0 ; +struct cw1200_common *priv = dev->priv; +struct ieee80211_conf *conf = &dev->conf; + +down (&priv->scan.lock); +mutex_lock (&priv->conf_mutex); +/* TODO: IEEE80211_CONF_CHANGE_QOS */ +if (changed &IEEE80211_CONF_CHANGE_POWER ) { + priv->output_power = conf->power_level; +pr_debug ("[STA] TX power: %d\n" , + priv->output_power); +WARN_ON (wsm_set_output_power (priv, priv->output_power *10 )); + } + +if ((changed &IEEE80211_CONF_CHANGE_CHANNEL ) && + (priv->channel != conf->channel)) { +struct ieee80211_channel *ch = conf->channel; +struct wsm_switch_channel channel = { + .newChannelNumber = ch->hw_value, + }; +pr_debug ("[STA] Freq %d (wsm ch: %d).\n" , + ch->center_freq, ch->hw_value); + + ret =__cw1200_flush (priv, false); +if (!ret) { + ret =WARN_ON (wsm_switch_channel (priv, &channel)); +if (!ret) { + ret =wait_event_timeout ( + priv->channel_switch_done, + !priv->channel_switch_in_progress, +3 *HZ ); +/* TODO: We should check also switch channel +* complete indication +*/ +if (ret) { + priv->channel = ch; + ret =0 ; + }else + ret = -ETIMEDOUT ; + }else +wsm_unlock_tx (priv); + } + } + +if (changed &IEEE80211_CONF_CHANGE_PS ) { +if (!(conf->flags &IEEE80211_CONF_PS )) + priv->powersave_mode.pmMode =WSM_PSM_ACTIVE ; +else if (conf->dynamic_ps_timeout <=0 ) + priv->powersave_mode.pmMode =WSM_PSM_PS ; +else + priv->powersave_mode.pmMode =WSM_PSM_FAST_PS ; + +/* Firmware requires that value for this 1-byte field must +* be specified in units of 500us. Values above the 128ms +* threshold are not supported. */ +if (conf->dynamic_ps_timeout >=0x80 ) + priv->powersave_mode.fastPsmIdlePeriod =0xFF ; +else + priv->powersave_mode.fastPsmIdlePeriod = + conf->dynamic_ps_timeout <<1 ; + +if (priv->join_status ==CW1200_JOIN_STATUS_STA && + priv->bss_params.aid) +cw1200_set_pm (priv, &priv->powersave_mode); + } + +if (changed &IEEE80211_CONF_CHANGE_MONITOR ) { +/* TBD: It looks like it's transparent +* there's a monitor interface present -- use this +* to determine for example whether to calculate +* timestamps for packets or not, do not use instead +* of filter flags! */ + } + +if (changed &IEEE80211_CONF_CHANGE_IDLE ) { +struct wsm_operational_mode mode = { + .power_mode = cw1200_power_mode, + .disableMoreFlagUsage = true, + }; + +wsm_lock_tx (priv); +/* Disable p2p-dev mode forced by TX request */ +if ((priv->join_status ==CW1200_JOIN_STATUS_MONITOR ) && + (conf->flags &IEEE80211_CONF_IDLE ) && + !priv->listening) { +cw1200_disable_listening (priv); + priv->join_status =CW1200_JOIN_STATUS_PASSIVE ; + } +WARN_ON (wsm_set_operational_mode (priv, &mode)); +wsm_unlock_tx (priv); + } + +if (changed &IEEE80211_CONF_CHANGE_RETRY_LIMITS ) { +pr_debug ("[STA] Retry limits: %d (long), " \ +"%d (short).\n" , + conf->long_frame_max_tx_count, + conf->short_frame_max_tx_count); +spin_lock_bh (&priv->tx_policy_cache.lock); + priv->long_frame_max_tx_count = conf->long_frame_max_tx_count; + priv->short_frame_max_tx_count = + (conf->short_frame_max_tx_count <0x0F ) ? + conf->short_frame_max_tx_count :0x0F ; + priv->hw->max_rate_tries = priv->short_frame_max_tx_count; +spin_unlock_bh (&priv->tx_policy_cache.lock); +/* TBD: I think we don't need tx_policy_force_upload(). +* Outdated policies will leave cache in a normal way. */ +/* WARN_ON(tx_policy_force_upload(priv)); */ + } +mutex_unlock (&priv->conf_mutex); +up (&priv->scan.lock); +return ret; +} + +void cw1200_update_filtering (struct cw1200_common *priv) +{ +int ret; +bool bssid_filtering = !priv->rx_filter.bssid; +bool is_p2p = priv->vif && priv->vif->p2p; +bool is_sta = priv->vif &&NL80211_IFTYPE_STATION == priv->vif->type; +static struct wsm_beacon_filter_control bf_disabled = { + .enabled =0 , + .bcn_count =1 , + }; +static struct wsm_beacon_filter_table bf_table_auto = { + .numOfIEs =__cpu_to_le32 (2 ), + .entry[0 ].ieId =WLAN_EID_VENDOR_SPECIFIC , + .entry[0 ].actionFlags =WSM_BEACON_FILTER_IE_HAS_CHANGED | +WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | +WSM_BEACON_FILTER_IE_HAS_APPEARED , + .entry[0 ].oui[0 ] =0x50 , + .entry[0 ].oui[1 ] =0x6F , + .entry[0 ].oui[2 ] =0x9A , + .entry[1 ].ieId =WLAN_EID_HT_OPERATION , + .entry[1 ].actionFlags =WSM_BEACON_FILTER_IE_HAS_CHANGED | +WSM_BEACON_FILTER_IE_NO_LONGER_PRESENT | +WSM_BEACON_FILTER_IE_HAS_APPEARED , + }; +static struct wsm_beacon_filter_control bf_auto = { + .enabled =WSM_BEACON_FILTER_ENABLE | +WSM_BEACON_FILTER_AUTO_ERP , + .bcn_count =1 , + }; + bf_auto.bcn_count = priv->bf_control.bcn_count; + +if (priv->join_status ==CW1200_JOIN_STATUS_PASSIVE ) +return ; +else if (priv->join_status ==CW1200_JOIN_STATUS_MONITOR ) + bssid_filtering = false; + +/* +* When acting as p2p client being connected to p2p GO, in order to +* receive frames from a different p2p device, turn off bssid filter. +* +* WARNING: FW dependency! +* This can only be used with FW WSM371 and its successors. +* In that FW version even with bssid filter turned off, +* device will block most of the unwanted frames. +*/ +if (is_p2p) + bssid_filtering = false; + + ret =wsm_set_rx_filter (priv, &priv->rx_filter); +if (!ret) { +if (is_p2p || !is_sta) + ret =wsm_set_beacon_filter_table (priv, &priv->bf_table); +else + ret =wsm_set_beacon_filter_table (priv, &bf_table_auto); + } +if (!ret) { +if (priv->disable_beacon_filter) { + ret =wsm_beacon_filter_control (priv, + &bf_disabled); + }else { +if (is_p2p || !is_sta) + ret =wsm_beacon_filter_control (priv, + &priv->bf_control); +else + ret =wsm_beacon_filter_control (priv, + &bf_auto); + } + } +if (!ret) + ret =wsm_set_bssid_filtering (priv, bssid_filtering); +if (!ret) + ret =wsm_set_multicast_filter (priv, &priv->multicast_filter); +if (ret) +wiphy_err (priv->hw->wiphy, +"%s: Update filtering failed: %d.\n" , + __func__, ret); +return ; +} + +void cw1200_update_filtering_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, + update_filtering_work); + +cw1200_update_filtering (priv); +} + +void cw1200_set_beacon_wakeup_period_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, + set_beacon_wakeup_period_work); + +WARN_ON (wsm_set_beacon_wakeup_period (priv, + priv->beacon_int * priv->join_dtim_period > +MAX_BEACON_SKIP_TIME_MS ?1 : + priv->join_dtim_period,0 )); +} + +u64 cw1200_prepare_multicast (struct ieee80211_hw *hw, +struct netdev_hw_addr_list *mc_list) +{ +static u8 broadcast_ipv6[ETH_ALEN ] = { +0x33 ,0x33 ,0x00 ,0x00 ,0x00 ,0x01 + }; +static u8 broadcast_ipv4[ETH_ALEN ] = { +0x01 ,0x00 ,0x5e ,0x00 ,0x00 ,0x01 + }; +struct cw1200_common *priv = hw->priv; +struct netdev_hw_addr *ha; +int count =0 ; + +/* Disable multicast filtering */ + priv->has_multicast_subscription = false; +memset (&priv->multicast_filter,0x00 ,sizeof (priv->multicast_filter)); + +if (netdev_hw_addr_list_count (mc_list) >WSM_MAX_GRP_ADDRTABLE_ENTRIES ) +return 0 ; + +/* Enable if requested */ +netdev_hw_addr_list_for_each (ha, mc_list) { +pr_debug ("[STA] multicast: %pM\n" , ha->addr); +memcpy (&priv->multicast_filter.macAddress[count], + ha->addr,ETH_ALEN ); +if (memcmp (ha->addr, broadcast_ipv4,ETH_ALEN ) && +memcmp (ha->addr, broadcast_ipv6,ETH_ALEN )) + priv->has_multicast_subscription = true; + count++; + } + +if (count) { + priv->multicast_filter.enable =__cpu_to_le32 (1 ); + priv->multicast_filter.numOfAddresses =__cpu_to_le32 (count); + } + +return netdev_hw_addr_list_count (mc_list); +} + +void cw1200_configure_filter (struct ieee80211_hw *dev, +unsigned int changed_flags, +unsigned int *total_flags, +u64 multicast) +{ +struct cw1200_common *priv = dev->priv; +bool listening = !!(*total_flags & + (FIF_PROMISC_IN_BSS | +FIF_OTHER_BSS | +FIF_BCN_PRBRESP_PROMISC | +FIF_PROBE_REQ )); + + *total_flags &=FIF_PROMISC_IN_BSS | +FIF_OTHER_BSS | +FIF_FCSFAIL | +FIF_BCN_PRBRESP_PROMISC | +FIF_PROBE_REQ ; + +down (&priv->scan.lock); +mutex_lock (&priv->conf_mutex); + + priv->rx_filter.promiscuous = (*total_flags &FIF_PROMISC_IN_BSS ) + ?1 :0 ; + priv->rx_filter.bssid = (*total_flags & (FIF_OTHER_BSS | +FIF_PROBE_REQ )) ?1 :0 ; + priv->rx_filter.fcs = (*total_flags &FIF_FCSFAIL ) ?1 :0 ; + priv->bf_control.bcn_count = (*total_flags & + (FIF_BCN_PRBRESP_PROMISC | +FIF_PROMISC_IN_BSS | +FIF_PROBE_REQ )) ?1 :0 ; +if (priv->listening != listening) { + priv->listening = listening; +wsm_lock_tx (priv); +cw1200_update_listening (priv, listening); +wsm_unlock_tx (priv); + } +cw1200_update_filtering (priv); +mutex_unlock (&priv->conf_mutex); +up (&priv->scan.lock); +} + +int cw1200_conf_tx (struct ieee80211_hw *dev,struct ieee80211_vif *vif, +u16 queue,const struct ieee80211_tx_queue_params *params) +{ +struct cw1200_common *priv = dev->priv; +int ret =0 ; +/* To prevent re-applying PM request OID again and again*/ +bool old_uapsdFlags; + +mutex_lock (&priv->conf_mutex); + +if (queue < dev->queues) { + old_uapsdFlags = priv->uapsd_info.uapsdFlags; + +WSM_TX_QUEUE_SET (&priv->tx_queue_params, queue,0 ,0 ,0 ); + ret =wsm_set_tx_queue_params (priv, + &priv->tx_queue_params.params[queue], queue); +if (ret) { + ret = -EINVAL ; + goto out; + } + +WSM_EDCA_SET (&priv->edca, queue, params->aifs, + params->cw_min, params->cw_max, params->txop,0xc8 , + params->uapsd); + ret =wsm_set_edca_params (priv, &priv->edca); +if (ret) { + ret = -EINVAL ; + goto out; + } + +if (priv->mode ==NL80211_IFTYPE_STATION ) { + ret =cw1200_set_uapsd_param (priv, &priv->edca); +if (!ret && priv->setbssparams_done && + (priv->join_status ==CW1200_JOIN_STATUS_STA ) && + (old_uapsdFlags != priv->uapsd_info.uapsdFlags)) +cw1200_set_pm (priv, &priv->powersave_mode); + } + }else + ret = -EINVAL ; + +out: +mutex_unlock (&priv->conf_mutex); +return ret; +} + +int cw1200_get_stats (struct ieee80211_hw *dev, +struct ieee80211_low_level_stats *stats) +{ +struct cw1200_common *priv = dev->priv; + +memcpy (stats, &priv->stats,sizeof (*stats)); +return 0 ; +} + +/* +int cw1200_get_tx_stats(struct ieee80211_hw *dev, +struct ieee80211_tx_queue_stats *stats) +{ +int i; +struct cw1200_common *priv = dev->priv; + +for (i = 0; i < dev->queues; ++i) +cw1200_queue_get_stats(&priv->tx_queue[i], &stats[i]); + +return 0; +} +*/ + +int cw1200_set_pm (struct cw1200_common *priv,const struct wsm_set_pm *arg) +{ +struct wsm_set_pm pm = *arg; + +if (priv->uapsd_info.uapsdFlags !=0 ) + pm.pmMode &= ~WSM_PSM_FAST_PS_FLAG ; + +if (memcmp (&pm, &priv->firmware_ps_mode, +sizeof (struct wsm_set_pm ))) { + priv->firmware_ps_mode = pm; +return wsm_set_pm (priv, &pm); + }else { +return 0 ; + } +} + +int cw1200_set_key (struct ieee80211_hw *dev,enum set_key_cmd cmd, +struct ieee80211_vif *vif,struct ieee80211_sta *sta, +struct ieee80211_key_conf *key) +{ +int ret = -EOPNOTSUPP ; +struct cw1200_common *priv = dev->priv; + +mutex_lock (&priv->conf_mutex); + +if (cmd ==SET_KEY ) { +u8 *peer_addr =NULL ; +int pairwise = (key->flags &IEEE80211_KEY_FLAG_PAIRWISE ) ? +1 :0 ; +int idx =cw1200_alloc_key (priv); +struct wsm_add_key *wsm_key = &priv->keys[idx]; + +if (idx <0 ) { + ret = -EINVAL ; + goto finally; + } + +if (sta) + peer_addr = sta->addr; + + key->flags |=IEEE80211_KEY_FLAG_PUT_IV_SPACE ; + +switch (key->cipher) { +case WLAN_CIPHER_SUITE_WEP40 : +case WLAN_CIPHER_SUITE_WEP104 : +if (key->keylen >16 ) { +cw1200_free_key (priv, idx); + ret = -EINVAL ; + goto finally; + } + +if (pairwise) { + wsm_key->type =WSM_KEY_TYPE_WEP_PAIRWISE ; +memcpy (wsm_key->wepPairwiseKey.peerAddress, + peer_addr,ETH_ALEN ); +memcpy (wsm_key->wepPairwiseKey.keyData, + &key->key[0 ], key->keylen); + wsm_key->wepPairwiseKey.keyLength = key->keylen; + }else { + wsm_key->type =WSM_KEY_TYPE_WEP_DEFAULT ; +memcpy (wsm_key->wepGroupKey.keyData, + &key->key[0 ], key->keylen); + wsm_key->wepGroupKey.keyLength = key->keylen; + wsm_key->wepGroupKey.keyId = key->keyidx; + } +break ; +case WLAN_CIPHER_SUITE_TKIP : +if (pairwise) { + wsm_key->type =WSM_KEY_TYPE_TKIP_PAIRWISE ; +memcpy (wsm_key->tkipPairwiseKey.peerAddress, + peer_addr,ETH_ALEN ); +memcpy (wsm_key->tkipPairwiseKey.tkipKeyData, + &key->key[0 ],16 ); +memcpy (wsm_key->tkipPairwiseKey.txMicKey, + &key->key[16 ],8 ); +memcpy (wsm_key->tkipPairwiseKey.rxMicKey, + &key->key[24 ],8 ); + }else { +size_t mic_offset = + (priv->mode ==NL80211_IFTYPE_AP ) ? +16 :24 ; + wsm_key->type =WSM_KEY_TYPE_TKIP_GROUP ; +memcpy (wsm_key->tkipGroupKey.tkipKeyData, + &key->key[0 ],16 ); +memcpy (wsm_key->tkipGroupKey.rxMicKey, + &key->key[mic_offset],8 ); + +/* TODO: Where can I find TKIP SEQ? */ +memset (wsm_key->tkipGroupKey.rxSeqCounter, +0 ,8 ); + wsm_key->tkipGroupKey.keyId = key->keyidx; + } +break ; +case WLAN_CIPHER_SUITE_CCMP : +if (pairwise) { + wsm_key->type =WSM_KEY_TYPE_AES_PAIRWISE ; +memcpy (wsm_key->aesPairwiseKey.peerAddress, + peer_addr,ETH_ALEN ); +memcpy (wsm_key->aesPairwiseKey.aesKeyData, + &key->key[0 ],16 ); + }else { + wsm_key->type =WSM_KEY_TYPE_AES_GROUP ; +memcpy (wsm_key->aesGroupKey.aesKeyData, + &key->key[0 ],16 ); +/* TODO: Where can I find AES SEQ? */ +memset (wsm_key->aesGroupKey.rxSeqCounter, +0 ,8 ); + wsm_key->aesGroupKey.keyId = key->keyidx; + } +break ; +case WLAN_CIPHER_SUITE_SMS4 : +if (pairwise) { + wsm_key->type =WSM_KEY_TYPE_WAPI_PAIRWISE ; +memcpy (wsm_key->wapiPairwiseKey.peerAddress, + peer_addr,ETH_ALEN ); +memcpy (wsm_key->wapiPairwiseKey.wapiKeyData, + &key->key[0 ],16 ); +memcpy (wsm_key->wapiPairwiseKey.micKeyData, + &key->key[16 ],16 ); + wsm_key->wapiPairwiseKey.keyId = key->keyidx; + }else { + wsm_key->type =WSM_KEY_TYPE_WAPI_GROUP ; +memcpy (wsm_key->wapiGroupKey.wapiKeyData, + &key->key[0 ],16 ); +memcpy (wsm_key->wapiGroupKey.micKeyData, + &key->key[16 ],16 ); + wsm_key->wapiGroupKey.keyId = key->keyidx; + } +break ; +default : +WARN_ON (1 ); +cw1200_free_key (priv, idx); + ret = -EOPNOTSUPP ; + goto finally; + } + ret =WARN_ON (wsm_add_key (priv, wsm_key)); +if (!ret) + key->hw_key_idx = idx; +else +cw1200_free_key (priv, idx); + }else if (cmd ==DISABLE_KEY ) { +struct wsm_remove_key wsm_key = { + .entryIndex = key->hw_key_idx, + }; + +if (wsm_key.entryIndex >WSM_KEY_MAX_INDEX ) { + ret = -EINVAL ; + goto finally; + } + +cw1200_free_key (priv, wsm_key.entryIndex); + ret =wsm_remove_key (priv, &wsm_key); + }else { +BUG_ON ("Unsupported command" ); + } + +finally: +mutex_unlock (&priv->conf_mutex); +return ret; +} + +void cw1200_wep_key_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, wep_key_work); +u8 queueId =cw1200_queue_get_queue_id (priv->pending_frame_id); +struct cw1200_queue *queue = &priv->tx_queue[queueId]; +__le32 wep_default_key_id =__cpu_to_le32 ( + priv->wep_default_key_id); + +pr_debug ("[STA] Setting default WEP key: %d\n" , + priv->wep_default_key_id); +wsm_flush_tx (priv); +WARN_ON (wsm_write_mib (priv,WSM_MIB_ID_DOT11_WEP_DEFAULT_KEY_ID , + &wep_default_key_id,sizeof (wep_default_key_id))); +cw1200_queue_requeue (queue, priv->pending_frame_id); +wsm_unlock_tx (priv); +} + +int cw1200_set_rts_threshold (struct ieee80211_hw *hw,u32 value) +{ +int ret =0 ; +__le32 val32; +struct cw1200_common *priv = hw->priv; + +if (priv->mode ==NL80211_IFTYPE_UNSPECIFIED ) +return 0 ; + +if (value != (u32) -1 ) + val32 =__cpu_to_le32 (value); +else + val32 =0 ;/* disabled */ + +if (priv->mode ==NL80211_IFTYPE_UNSPECIFIED ) { +/* device is down, can _not_ set threshold */ + ret = -ENODEV ; + goto out; + } + +if (priv->rts_threshold == value) + goto out; + +pr_debug ("[STA] Setting RTS threshold: %d\n" , + priv->rts_threshold); + +/* mutex_lock(&priv->conf_mutex); */ + ret =WARN_ON (wsm_write_mib (priv,WSM_MIB_ID_DOT11_RTS_THRESHOLD , + &val32,sizeof (val32))); +if (!ret) + priv->rts_threshold = value; +/* mutex_unlock(&priv->conf_mutex); */ + +out: +return ret; +} + +static int __cw1200_flush (struct cw1200_common *priv,bool drop) +{ +int i, ret; + +for (;;) { +/* TODO: correct flush handling is required when dev_stop. +* Temporary workaround: 2s +*/ +if (drop) { +for (i =0 ; i <4 ; ++i) +cw1200_queue_clear (&priv->tx_queue[i]); + }else { + ret =wait_event_timeout ( + priv->tx_queue_stats.wait_link_id_empty, +cw1200_queue_stats_is_empty ( + &priv->tx_queue_stats,-1 ), +2 *HZ ); + } + +if (!drop && ret <=0 ) { + ret = -ETIMEDOUT ; +break ; + }else { + ret =0 ; + } + +wsm_lock_tx (priv); +if (!cw1200_queue_stats_is_empty (&priv->tx_queue_stats,-1 )) { +/* Highly unlekely: WSM requeued frames. */ +wsm_unlock_tx (priv); +continue ; + } +break ; + } +return ret; +} + +void cw1200_flush (struct ieee80211_hw *hw,bool drop) +{ +struct cw1200_common *priv = hw->priv; + +switch (priv->mode) { +case NL80211_IFTYPE_MONITOR : + drop = true; +break ; +case NL80211_IFTYPE_AP : +if (!priv->enable_beacon) + drop = true; +break ; + } + +__cw1200_flush (priv, drop); +wsm_unlock_tx (priv); + +return ; +} + +/* ******************************************************************** */ +/* WSM callbacks */ + +void cw1200_channel_switch_cb (struct cw1200_common *priv) +{ +wsm_unlock_tx (priv); +} + +void cw1200_free_event_queue (struct cw1200_common *priv) +{ +LIST_HEAD (list); + +spin_lock (&priv->event_queue_lock); +list_splice_init (&priv->event_queue, &list); +spin_unlock (&priv->event_queue_lock); + +__cw1200_free_event_queue (&list); +} + +void cw1200_event_handler (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, event_handler); +struct cw1200_wsm_event *event; +LIST_HEAD (list); + +spin_lock (&priv->event_queue_lock); +list_splice_init (&priv->event_queue, &list); +spin_unlock (&priv->event_queue_lock); + +list_for_each_entry (event, &list, link) { +switch (event->evt.eventId) { +case WSM_EVENT_ERROR : +pr_err ("Unhandled WSM Error from LMAC\n" ); +break ; +case WSM_EVENT_BSS_LOST : + { +spin_lock (&priv->bss_loss_lock); +if (priv->bss_loss_status >CW1200_BSS_LOSS_NONE ) { +spin_unlock (&priv->bss_loss_lock); +break ; + } + priv->bss_loss_status =CW1200_BSS_LOSS_CHECKING ; +spin_unlock (&priv->bss_loss_lock); + +pr_debug ("[CQM] BSS lost.\n" ); +cancel_delayed_work_sync (&priv->bss_loss_work); +cancel_delayed_work_sync (&priv->connection_loss_work); +cancel_work_sync (&priv->unjoin_work); +if (!down_trylock (&priv->scan.lock)) { +up (&priv->scan.lock); + priv->delayed_link_loss =0 ; +queue_delayed_work (priv->workqueue, + &priv->bss_loss_work,0 ); + }else { +/* Scan is in progress. Delay reporting. */ +/* Scan complete will trigger bss_loss_work */ + priv->delayed_link_loss =1 ; +/* Also we're starting watchdog. */ +queue_delayed_work (priv->workqueue, + &priv->bss_loss_work,10 *HZ ); + } +break ; + } +case WSM_EVENT_BSS_REGAINED : + { +pr_debug ("[CQM] BSS regained.\n" ); + priv->delayed_link_loss =0 ; +spin_lock (&priv->bss_loss_lock); + priv->bss_loss_status =CW1200_BSS_LOSS_NONE ; + priv->bss_loss_checking =0 ; +spin_unlock (&priv->bss_loss_lock); +cancel_delayed_work_sync (&priv->bss_loss_work); +cancel_delayed_work_sync (&priv->connection_loss_work); +cancel_work_sync (&priv->unjoin_work); +break ; + } +case WSM_EVENT_RADAR_DETECTED : +wiphy_info (priv->hw->wiphy,"radar pulse detected\n" ); +break ; +case WSM_EVENT_RCPI_RSSI : + { +/* RSSI: signed Q8.0, RCPI: unsigned Q7.1 +* RSSI = RCPI / 2 - 110 */ +int rcpiRssi = (int )(event->evt.eventData &0xFF ); +int cqm_evt; +if (priv->cqm_use_rssi) + rcpiRssi = (s8 )rcpiRssi; +else + rcpiRssi = rcpiRssi /2 -110 ; + + cqm_evt = (rcpiRssi <= priv->cqm_rssi_thold) ? +NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW : +NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH ; +pr_debug ("[CQM] RSSI event: %d.\n" , rcpiRssi); +ieee80211_cqm_rssi_notify (priv->vif, cqm_evt, +GFP_KERNEL ); +break ; + } +case WSM_EVENT_BT_INACTIVE : +pr_warn ("Unhandled BT INACTIVE from LMAC\n" ); +break ; +case WSM_EVENT_BT_ACTIVE : +pr_warn ("Unhandled BT ACTIVE from LMAC\n" ); +break ; + } + } +__cw1200_free_event_queue (&list); +} + +void cw1200_bss_loss_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, bss_loss_work.work); +int timeout;/* in beacons */ +struct sk_buff *skb; + + timeout = priv->cqm_beacon_loss_count *3 ; + +/* Skip the confimration procedure in P2P case */ +if (priv->vif->p2p) + goto report; + +spin_lock (&priv->bss_loss_lock); +if (priv->bss_loss_status ==CW1200_BSS_LOSS_CHECKING ) { +spin_unlock (&priv->bss_loss_lock); + skb =ieee80211_nullfunc_get (priv->hw, priv->vif); +if (!(WARN_ON (!skb))) { +cw1200_tx (priv->hw,NULL , skb); +/* Start watchdog -- if nullfunc TX doesn't fail +* in 1 sec, forward event to upper layers */ +queue_delayed_work (priv->workqueue, + &priv->bss_loss_work,1 *HZ ); + } +return ; + }else if (priv->bss_loss_status ==CW1200_BSS_LOSS_CONFIRMING ) { + priv->bss_loss_status =CW1200_BSS_LOSS_NONE ; + priv->bss_loss_checking =0 ; +spin_unlock (&priv->bss_loss_lock); +return ; + } +spin_unlock (&priv->bss_loss_lock); + +report: +if (priv->cqm_beacon_loss_count) { +pr_debug ("[CQM] Beacon loss.\n" ); +if (timeout <=0 ) + timeout =0 ; + }else { + timeout =0 ; + } + +cancel_work_sync (&priv->unjoin_work); +cancel_delayed_work_sync (&priv->connection_loss_work); +queue_delayed_work (priv->workqueue, + &priv->connection_loss_work, + timeout *HZ /10 ); + +spin_lock (&priv->bss_loss_lock); + priv->bss_loss_status =CW1200_BSS_LOSS_NONE ; + priv->bss_loss_checking =0 ; +spin_unlock (&priv->bss_loss_lock); +} + +void cw1200_connection_loss_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, + connection_loss_work.work); + +pr_debug ("[CQM] Reporting connection loss.\n" ); +wsm_lock_tx (priv); +if (queue_work (priv->workqueue, &priv->unjoin_work) <=0 ) +wsm_unlock_tx (priv); +} + +/* ******************************************************************** */ +/* Internal API */ + +/* +* This function is called to Parse the SDD file +* to extract listen_interval and PTA related information +* sdd is a TLV: u8 id, u8 len, u8 data[] +*/ +static int cw1200_parse_SDD_file (struct cw1200_common *priv) +{ +const u8 *p = priv->sdd->data; +int ret =0 ; + +while (p +2 <= priv->sdd->data + priv->sdd->size) { +if (p + p[1 ] +2 > priv->sdd->data + priv->sdd->size) { +printk (KERN_WARNING "Malformed sdd structure\n" ); +return -1 ; + } +switch (p[0 ]) { +case SDD_PTA_CFG_ELT_ID : { +u16 v; +if (p[1 ] <4 ) { +pr_warning ("SDD_PTA_CFG_ELT_ID malformed\n" ); + ret =-1 ; +break ; + } + v =le16_to_cpu (*((u16 *)(p +2 ))); +if (!v)/* non-zero means this is enabled */ +break ; + + v =le16_to_cpu (*((u16 *)(p +4 ))); + priv->conf_listen_interval = (v >>7 ) &0x1F ; +pr_debug ("PTA found; Listen Interval %d\n" , priv->conf_listen_interval); +break ; + } +case SDD_REFERENCE_FREQUENCY_ELT_ID : { +u16 clk =le16_to_cpu (*((u16 *)(p +2 ))); +if (clk != priv->hw_refclk) { +pr_warn ("SDD file doesn't match configured refclk (%d vs %d)\n" , + priv->hw_refclk, clk); + } +break ; + } +default : +break ; + } + p += p[1 ] +2 ; + + } + +if (priv->is_BT_Present == false) { +pr_debug ("PTA element NOT found.\n" ); + priv->conf_listen_interval =0 ; + } +return ret; + +} + +int cw1200_setup_mac (struct cw1200_common *priv) +{ +int ret =0 ; + +/* NOTE: There is a bug in FW: it reports signal +* as RSSI if RSSI subscription is enabled. +* It's not enough to set WSM_RCPI_RSSI_USE_RSSI. */ +/* NOTE2: RSSI based reports have been switched to RCPI, since +* FW has a bug and RSSI reported values are not stable, +* what can leads to signal level oscilations in user-end applications */ +struct wsm_rcpi_rssi_threshold threshold = { + .rssiRcpiMode =WSM_RCPI_RSSI_THRESHOLD_ENABLE | +WSM_RCPI_RSSI_DONT_USE_UPPER | +WSM_RCPI_RSSI_DONT_USE_LOWER , + .rollingAverageCount =16 , + }; + +struct wsm_configuration cfg = { + .dot11StationId = &priv->mac_addr[0 ], + }; + +/* Remember the decission here to make sure, we will handle +* the RCPI/RSSI value correctly on WSM_EVENT_RCPI_RSS */ +if (threshold.rssiRcpiMode &WSM_RCPI_RSSI_USE_RSSI ) + priv->cqm_use_rssi = true; + +if (!priv->sdd) { + ret =request_firmware (&priv->sdd, + priv->sdd_path, priv->pdev); + +if (ret) { +pr_err ("%s: can't load sdd file %s.\n" , + __func__, priv->sdd_path); +return ret; + } +/* Parse SDD file for PTA element */ +cw1200_parse_SDD_file (priv); + } + + cfg.dpdData = priv->sdd->data; + cfg.dpdData_size = priv->sdd->size; + ret =WARN_ON (wsm_configuration (priv, &cfg)); +if (ret) +return ret; + +/* Configure RSSI/SCPI reporting as RSSI. */ +WARN_ON (wsm_set_rcpi_rssi_threshold (priv, &threshold)); + +return 0 ; +} + +void cw1200_offchannel_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, offchannel_work); +u8 queueId =cw1200_queue_get_queue_id (priv->pending_frame_id); +struct cw1200_queue *queue = &priv->tx_queue[queueId]; + +mutex_lock (&priv->conf_mutex); +if (!priv->join_status) { +wsm_flush_tx (priv); +cw1200_update_listening (priv, true); +cw1200_update_filtering (priv); + } +if (!priv->join_status) +cw1200_queue_remove (queue, priv->pending_frame_id); +else +cw1200_queue_requeue (queue, priv->pending_frame_id); +mutex_unlock (&priv->conf_mutex); +wsm_unlock_tx (priv); +} + +static void cw1200_join_complete (struct cw1200_common *priv) +{ +pr_debug ("[STA] Join complete.\n" ); + +mutex_lock (&priv->conf_mutex); + priv->join_pending = false; +if (priv->join_complete_status) { + priv->join_status =CW1200_JOIN_STATUS_PASSIVE ; +memset (&priv->join_bssid[0 ],0 ,sizeof (priv->join_bssid)); +wsm_lock_tx (priv); +cw1200_update_listening (priv, priv->listening); +wsm_unlock_tx (priv); + }else { + priv->join_status =CW1200_JOIN_STATUS_PRE_STA ; +/* Assoc timeout, not to leave device in full power. */ +queue_delayed_work (priv->workqueue, + &priv->join_timeout,CW1200_AUTH_TIMEOUT ); +/* Due to beacon filtering it is possible that the +* AP's beacon is not known for the mac80211 stack. +* Disable filtering temporary to make sure the stack +* receives at least one */ + priv->disable_beacon_filter = true; +cw1200_update_filtering (priv); + } +mutex_unlock (&priv->conf_mutex); +} + +void cw1200_join_complete_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, join_complete_work); +cw1200_join_complete (priv); +} + +void cw1200_join_complete_cb (struct cw1200_common *priv, +struct wsm_join_complete *arg) +{ +pr_debug ("[STA] cw1200_join_complete_cb called, status=%d.\n" , arg->status); + +if (cancel_delayed_work (&priv->join_timeout)) { + priv->join_complete_status = arg->status; +queue_work (priv->workqueue, &priv->join_complete_work); + } +} + +void cw1200_join_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, join_work); +u8 queueId =cw1200_queue_get_queue_id (priv->pending_frame_id); +struct cw1200_queue *queue = &priv->tx_queue[queueId]; +const struct cw1200_txpriv *txpriv =NULL ; +struct sk_buff *skb =NULL ; +const struct wsm_tx *wsm; +const struct ieee80211_hdr *frame; +const u8 *bssid; +struct cfg80211_bss *bss; +const u8 *ssidie; +struct wsm_protected_mgmt_policy mgmt_policy; + +if (delayed_work_pending (&priv->join_timeout)) { +pr_warn ("[STA] Skipping join request - previous request yet to be completed\n" ); +wsm_unlock_tx (priv); +return ; + } + +if (cw1200_queue_get_skb (queue, priv->pending_frame_id, + &skb, &txpriv)) { +wsm_unlock_tx (priv); + priv->join_pending = false; +return ; + } + wsm = (struct wsm_tx *)skb->data; + frame = (struct ieee80211_hdr *)&skb->data[txpriv->offset]; + bssid = frame->addr3;/* BSSID is A3 in TODS/FROMDS/NODS */ + +if (priv->join_status) { +wsm_lock_tx (priv); +cw1200_unjoin_work (&priv->unjoin_work); + } + + bss =cfg80211_get_bss (priv->hw->wiphy, priv->channel, + bssid,NULL ,0 ,0 ,0 ); +if (!bss) { +cw1200_queue_remove (queue, priv->pending_frame_id); +wsm_unlock_tx (priv); + priv->join_pending = false; +return ; + } + +mutex_lock (&priv->conf_mutex); + { +struct wsm_join join = { + .mode = (bss->capability &WLAN_CAPABILITY_IBSS ) ? +WSM_JOIN_MODE_IBSS :WSM_JOIN_MODE_BSS , + .preambleType =WSM_JOIN_PREAMBLE_SHORT , + .probeForJoin =1 , + .atimWindow =1 , + .beaconInterval = bss->beacon_interval, +/* basicRateSet will be updated after association */ + .basicRateSet =7 , + }; + +/* Under the conf lock: check scan status and +* bail out if it is in progress. */ +if (atomic_read (&priv->scan.in_progress)) { +cw1200_queue_remove (queue, priv->pending_frame_id); +mutex_unlock (&priv->conf_mutex); +wsm_unlock_tx (priv); +return ; + } + +/* BT Coex related changes */ +if (priv->is_BT_Present) { +if (((priv->conf_listen_interval *100 ) % + bss->beacon_interval) ==0 ) + priv->listen_interval = + ((priv->conf_listen_interval *100 ) / + bss->beacon_interval); +else + priv->listen_interval = + ((priv->conf_listen_interval *100 ) / + bss->beacon_interval +1 ); + } + +if (priv->hw->conf.ps_dtim_period) + priv->join_dtim_period = priv->hw->conf.ps_dtim_period; + join.dtimPeriod = priv->join_dtim_period; + + priv->beacon_int = bss->beacon_interval; + join.channelNumber = priv->channel->hw_value; + join.band = (priv->channel->band ==IEEE80211_BAND_5GHZ ) ? +WSM_PHY_BAND_5G :WSM_PHY_BAND_2_4G ; + +pr_debug ("[STA] Join DTIM: %d, interval: %d\n" , + join.dtimPeriod, priv->beacon_int); + +memcpy (&join.bssid[0 ], bssid,sizeof (join.bssid)); +memcpy (&priv->join_bssid[0 ], bssid,sizeof (priv->join_bssid)); + +rcu_read_lock (); + ssidie =ieee80211_bss_get_ie (bss,WLAN_EID_SSID ); +if (ssidie) { + join.ssidLength = ssidie[1 ]; +if (WARN_ON (join.ssidLength >sizeof (join.ssid))) + join.ssidLength =sizeof (join.ssid); +memcpy (&join.ssid[0 ], &ssidie[2 ], join.ssidLength); + } +rcu_read_unlock (); + +if (priv->vif->p2p) { + join.flags |=WSM_JOIN_FLAGS_P2P_GO ; + join.basicRateSet = +cw1200_rate_mask_to_wsm (priv,0xFF0 ); + } + +/* Enable asynchronous join calls */ + join.flags |=WSM_JOIN_FLAGS_FORCE ; + join.flags |=WSM_JOIN_FLAGS_FORCE_WITH_COMPLETE_IND ; + +wsm_flush_tx (priv); + +queue_delayed_work (priv->workqueue, + &priv->join_timeout,CW1200_JOIN_TIMEOUT ); + +/* Stay Awake for Join and Auth Timeouts and a bit more */ +cw1200_pm_stay_awake (&priv->pm_state,CW1200_JOIN_TIMEOUT +CW1200_AUTH_TIMEOUT ); + +cw1200_update_listening (priv, false); + +/* Turn on Block ACKs */ +WARN_ON (wsm_set_block_ack_policy (priv, + priv->ba_tx_tid_mask, priv->ba_rx_tid_mask)); + + mgmt_policy.protectedMgmtEnable =0 ; + mgmt_policy.unprotectedMgmtFramesAllowed =1 ; + mgmt_policy.encryptionForAuthFrame =1 ; +wsm_set_protected_mgmt_policy (priv, &mgmt_policy); + +if (wsm_join (priv, &join)) { +pr_err ("[STA] cw1200_join_work: wsm_join request failed!\n" ); +memset (&priv->join_bssid[0 ], +0 ,sizeof (priv->join_bssid)); +cw1200_queue_remove (queue, priv->pending_frame_id); +cancel_delayed_work_sync (&priv->join_timeout); +cw1200_update_listening (priv, priv->listening); + }else { +pr_debug ("[STA] cw1200_join_work: wsm_join request send succesfully\n" ); + priv->join_status =CW1200_JOIN_STATUS_JOINING ; +/* Upload keys */ +WARN_ON (cw1200_upload_keys (priv)); +cw1200_queue_requeue (queue, priv->pending_frame_id); + +/* Due to beacon filtering it is possible that the +* AP's beacon is not known for the mac80211 stack. +* Disable filtering temporary to make sure the stack +* receives at least one */ + priv->disable_beacon_filter = true; + + } +cw1200_update_filtering (priv); + } +mutex_unlock (&priv->conf_mutex); +cfg80211_put_bss (bss); +wsm_unlock_tx (priv); +} + +void cw1200_join_timeout (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, join_timeout.work); +pr_debug ("[WSM] Issue unjoin command (TMO).\n" ); +wsm_lock_tx (priv); +cw1200_unjoin_work (&priv->unjoin_work); +} + +void cw1200_unjoin_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, unjoin_work); + +struct wsm_reset reset = { + .reset_statistics = true, + }; + +cancel_delayed_work (&priv->join_timeout); + +mutex_lock (&priv->conf_mutex); + priv->join_pending = false; + +if (atomic_read (&priv->scan.in_progress)) { +if (priv->delayed_unjoin) { +wiphy_dbg (priv->hw->wiphy,"Delayed unjoin is already scheduled.\n" ); +wsm_unlock_tx (priv); + }else { + priv->delayed_unjoin = true; + } +mutex_unlock (&priv->conf_mutex); +return ; + } + +if (priv->join_status) { +if (priv->join_status >CW1200_JOIN_STATUS_STA ) { +wiphy_err (priv->hw->wiphy,"Unexpected: join status: %d\n" , + priv->join_status); +BUG_ON (1 ); + } + +cancel_work_sync (&priv->update_filtering_work); +cancel_work_sync (&priv->set_beacon_wakeup_period_work); +memset (&priv->join_bssid[0 ],0 ,sizeof (priv->join_bssid)); + priv->join_status =CW1200_JOIN_STATUS_PASSIVE ; + +/* Unjoin is a reset. */ +wsm_flush_tx (priv); +WARN_ON (wsm_keep_alive_period (priv,0 )); +WARN_ON (wsm_reset (priv, &reset)); +WARN_ON (wsm_set_output_power (priv, priv->output_power *10 )); + priv->join_dtim_period =0 ; +WARN_ON (cw1200_setup_mac (priv)); +cw1200_free_event_queue (priv); +cancel_work_sync (&priv->event_handler); +cancel_delayed_work_sync (&priv->connection_loss_work); +cw1200_update_listening (priv, priv->listening); + +/* Disable Block ACKs */ +WARN_ON (wsm_set_block_ack_policy (priv,0 ,0 )); + + priv->disable_beacon_filter = false; +cw1200_update_filtering (priv); + priv->setbssparams_done = false; +memset (&priv->association_mode,0 , +sizeof (priv->association_mode)); +memset (&priv->bss_params,0 ,sizeof (priv->bss_params)); +memset (&priv->firmware_ps_mode,0 , +sizeof (priv->firmware_ps_mode)); +pr_debug ("[STA] Unjoin.\n" ); + +/* Tell the stack we're dead */ +ieee80211_connection_loss (priv->vif); + } +mutex_unlock (&priv->conf_mutex); +wsm_unlock_tx (priv); +} + +int cw1200_enable_listening (struct cw1200_common *priv) +{ +struct wsm_start start = { + .mode =WSM_START_MODE_P2P_DEV , + .band =WSM_PHY_BAND_2_4G , + .channelNumber =1 , + .beaconInterval =100 , + .DTIMPeriod =1 , + .probeDelay =0 , + .basicRateSet =0x0F , + }; + +if (priv->channel) { + start.band = priv->channel->band ==IEEE80211_BAND_5GHZ ? +WSM_PHY_BAND_5G :WSM_PHY_BAND_2_4G ; + start.channelNumber = priv->channel->hw_value; + } + +return wsm_start (priv, &start); +} + +int cw1200_disable_listening (struct cw1200_common *priv) +{ +int ret; +struct wsm_reset reset = { + .reset_statistics = true, + }; + ret =wsm_reset (priv, &reset); +return ret; +} + +void cw1200_update_listening (struct cw1200_common *priv,bool enabled) +{ +if (enabled) { +switch (priv->join_status) { +case CW1200_JOIN_STATUS_PASSIVE : +if (!WARN_ON (cw1200_enable_listening (priv))) + priv->join_status =CW1200_JOIN_STATUS_MONITOR ; +WARN_ON (wsm_set_probe_responder (priv, true)); +break ; +default : +break ; + } + }else { +switch (priv->join_status) { +case CW1200_JOIN_STATUS_MONITOR : +if (!WARN_ON (cw1200_disable_listening (priv))) + priv->join_status =CW1200_JOIN_STATUS_PASSIVE ; +WARN_ON (wsm_set_probe_responder (priv, false)); +default : +break ; + } + } +} + +int cw1200_set_uapsd_param (struct cw1200_common *priv, +const struct wsm_edca_params *arg) +{ +int ret; +u16 uapsdFlags =0 ; + +/* Here's the mapping AC [queue, bit] +VO [0,3], VI [1, 2], BE [2, 1], BK [3, 0]*/ + +if (arg->params[0 ].uapsdEnable) + uapsdFlags |=1 <<3 ; + +if (arg->params[1 ].uapsdEnable) + uapsdFlags |=1 <<2 ; + +if (arg->params[2 ].uapsdEnable) + uapsdFlags |=1 <<1 ; + +if (arg->params[3 ].uapsdEnable) + uapsdFlags |=1 ; + +/* Currently pseudo U-APSD operation is not supported, so setting +* MinAutoTriggerInterval, MaxAutoTriggerInterval and +* AutoTriggerStep to 0 */ + + priv->uapsd_info.uapsdFlags =cpu_to_le16 (uapsdFlags); + priv->uapsd_info.minAutoTriggerInterval =0 ; + priv->uapsd_info.maxAutoTriggerInterval =0 ; + priv->uapsd_info.autoTriggerStep =0 ; + + ret =wsm_set_uapsd_info (priv, &priv->uapsd_info); +return ret; +} + +/* ******************************************************************** */ +/* AP API */ + +int cw1200_sta_add (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +struct cw1200_common *priv = hw->priv; +struct cw1200_sta_priv *sta_priv = + (struct cw1200_sta_priv *)&sta->drv_priv; +struct cw1200_link_entry *entry; +struct sk_buff *skb; + +if (priv->mode !=NL80211_IFTYPE_AP ) +return 0 ; + + sta_priv->link_id =cw1200_find_link_id (priv, sta->addr); +if (WARN_ON (!sta_priv->link_id)) { +/* Impossible error */ +wiphy_info (priv->hw->wiphy, +"[AP] No more link IDs available.\n" ); +return -ENOENT ; + } + + entry = &priv->link_id_db[sta_priv->link_id -1 ]; +spin_lock_bh (&priv->ps_state_lock); +if ((sta->uapsd_queues &IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK ) == +IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK ) + priv->sta_asleep_mask |=BIT (sta_priv->link_id); + entry->status =CW1200_LINK_HARD ; +while ((skb =skb_dequeue (&entry->rx_queue))) +ieee80211_rx_irqsafe (priv->hw, skb); +spin_unlock_bh (&priv->ps_state_lock); +return 0 ; +} + +int cw1200_sta_remove (struct ieee80211_hw *hw,struct ieee80211_vif *vif, +struct ieee80211_sta *sta) +{ +struct cw1200_common *priv = hw->priv; +struct cw1200_sta_priv *sta_priv = + (struct cw1200_sta_priv *)&sta->drv_priv; +struct cw1200_link_entry *entry; + +if (priv->mode !=NL80211_IFTYPE_AP || !sta_priv->link_id) +return 0 ; + + entry = &priv->link_id_db[sta_priv->link_id -1 ]; +spin_lock_bh (&priv->ps_state_lock); + entry->status =CW1200_LINK_RESERVE ; + entry->timestamp = jiffies; +wsm_lock_tx_async (priv); +if (queue_work (priv->workqueue, &priv->link_id_work) <=0 ) +wsm_unlock_tx (priv); +spin_unlock_bh (&priv->ps_state_lock); +flush_workqueue (priv->workqueue); +return 0 ; +} + +static void __cw1200_sta_notify (struct ieee80211_hw *dev, +struct ieee80211_vif *vif, +enum sta_notify_cmd notify_cmd, +int link_id) +{ +struct cw1200_common *priv = dev->priv; +u32 bit, prev; + +/* Zero link id means "for all link IDs" */ +if (link_id) + bit =BIT (link_id); +else if (WARN_ON_ONCE (notify_cmd !=STA_NOTIFY_AWAKE )) + bit =0 ; +else + bit = priv->link_id_map; + prev = priv->sta_asleep_mask & bit; + +switch (notify_cmd) { +case STA_NOTIFY_SLEEP : +if (!prev) { +if (priv->buffered_multicasts && + !priv->sta_asleep_mask) +queue_work (priv->workqueue, + &priv->multicast_start_work); + priv->sta_asleep_mask |= bit; + } +break ; +case STA_NOTIFY_AWAKE : +if (prev) { + priv->sta_asleep_mask &= ~bit; + priv->pspoll_mask &= ~bit; +if (priv->tx_multicast && link_id && + !priv->sta_asleep_mask) +queue_work (priv->workqueue, + &priv->multicast_stop_work); +cw1200_bh_wakeup (priv); + } +break ; + } +} + +void cw1200_sta_notify (struct ieee80211_hw *dev, +struct ieee80211_vif *vif, +enum sta_notify_cmd notify_cmd, +struct ieee80211_sta *sta) +{ +struct cw1200_common *priv = dev->priv; +struct cw1200_sta_priv *sta_priv = + (struct cw1200_sta_priv *)&sta->drv_priv; + +spin_lock_bh (&priv->ps_state_lock); +__cw1200_sta_notify (dev, vif, notify_cmd, sta_priv->link_id); +spin_unlock_bh (&priv->ps_state_lock); +} + +static void cw1200_ps_notify (struct cw1200_common *priv, +int link_id,bool ps) +{ +if (link_id >CW1200_MAX_STA_IN_AP_MODE ) +return ; + +pr_debug ("%s for LinkId: %d. STAs asleep: %.8X\n" , + ps ?"Stop" :"Start" , + link_id, priv->sta_asleep_mask); + +__cw1200_sta_notify (priv->hw, priv->vif, + ps ?STA_NOTIFY_SLEEP :STA_NOTIFY_AWAKE , link_id); +} + +static int cw1200_set_tim_impl (struct cw1200_common *priv,bool aid0_bit_set) +{ +struct sk_buff *skb; +struct wsm_update_ie update_ie = { + .what =WSM_UPDATE_IE_BEACON , + .count =1 , + }; +u16 tim_offset, tim_length; + +pr_debug ("[AP] %s mcast: %s.\n" , + __func__, aid0_bit_set ?"ena" :"dis" ); + + skb =ieee80211_beacon_get_tim (priv->hw, priv->vif, + &tim_offset, &tim_length); +if (!skb) { +if (!__cw1200_flush (priv, true)) +wsm_unlock_tx (priv); +return -ENOENT ; + } + +if (tim_offset && tim_length >=6 ) { +/* Ignore DTIM count from mac80211: +* firmware handles DTIM internally. */ + skb->data[tim_offset +2 ] =0 ; + +/* Set/reset aid0 bit */ +if (aid0_bit_set) + skb->data[tim_offset +4 ] |=1 ; +else + skb->data[tim_offset +4 ] &= ~1 ; + } + + update_ie.ies = &skb->data[tim_offset]; + update_ie.length = tim_length; +WARN_ON (wsm_update_ie (priv, &update_ie)); + +dev_kfree_skb (skb); + +return 0 ; +} + +void cw1200_set_tim_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, set_tim_work); + (void )cw1200_set_tim_impl (priv, priv->aid0_bit_set); +} + +int cw1200_set_tim (struct ieee80211_hw *dev,struct ieee80211_sta *sta, +bool set) +{ +struct cw1200_common *priv = dev->priv; +queue_work (priv->workqueue, &priv->set_tim_work); +return 0 ; +} + +void cw1200_set_cts_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, set_cts_work); + +u8 erp_ie[3 ] = {WLAN_EID_ERP_INFO ,0x1 ,0 }; +struct wsm_update_ie update_ie = { + .what =WSM_UPDATE_IE_BEACON , + .count =1 , + .ies = erp_ie, + .length =3 , + }; +u32 erp_info; +__le32 use_cts_prot; +mutex_lock (&priv->conf_mutex); + erp_info = priv->erp_info; +mutex_unlock (&priv->conf_mutex); + use_cts_prot = + erp_info &WLAN_ERP_USE_PROTECTION ? +__cpu_to_le32 (1 ) :0 ; + + erp_ie[ERP_INFO_BYTE_OFFSET ] = erp_info; + +pr_debug ("[STA] ERP information 0x%x\n" , erp_info); + +WARN_ON (wsm_write_mib (priv,WSM_MIB_ID_NON_ERP_PROTECTION , + &use_cts_prot,sizeof (use_cts_prot))); +WARN_ON (wsm_update_ie (priv, &update_ie)); + +return ; +} + +static int cw1200_set_btcoexinfo (struct cw1200_common *priv) +{ +struct wsm_override_internal_txrate arg; +int ret =0 ; + +if (priv->mode ==NL80211_IFTYPE_STATION ) { +/* Plumb PSPOLL and NULL template */ +WARN_ON (cw1200_upload_pspoll (priv)); +WARN_ON (cw1200_upload_null (priv)); +WARN_ON (cw1200_upload_qosnull (priv)); + }else { +return 0 ; + } + +memset (&arg,0 ,sizeof (struct wsm_override_internal_txrate )); + +if (!priv->vif->p2p) { +/* STATION mode */ +if (priv->bss_params.operationalRateSet & ~0xF ) { +pr_debug ("[STA] STA has ERP rates\n" ); +/* G or BG mode */ + arg.internalTxRate = (__ffs ( + priv->bss_params.operationalRateSet & ~0xF )); + }else { +pr_debug ("[STA] STA has non ERP rates\n" ); +/* B only mode */ + arg.internalTxRate = (__ffs ( + priv->association_mode.basicRateSet)); + } + arg.nonErpInternalTxRate = (__ffs ( + priv->association_mode.basicRateSet)); + }else { +/* P2P mode */ + arg.internalTxRate = (__ffs ( + priv->bss_params.operationalRateSet & ~0xF )); + arg.nonErpInternalTxRate = (__ffs ( + priv->bss_params.operationalRateSet & ~0xF )); + } + +pr_debug ("[STA] BTCOEX_INFO MODE %d, internalTxRate : %x, nonErpInternalTxRate: %x\n" , + priv->mode, + arg.internalTxRate, + arg.nonErpInternalTxRate); + + ret =WARN_ON (wsm_write_mib (priv,WSM_MIB_ID_OVERRIDE_INTERNAL_TX_RATE , + &arg,sizeof (arg))); + +return ret; +} + +void cw1200_bss_info_changed (struct ieee80211_hw *dev, +struct ieee80211_vif *vif, +struct ieee80211_bss_conf *info, +u32 changed) +{ +struct cw1200_common *priv = dev->priv; + +mutex_lock (&priv->conf_mutex); + +if (changed &BSS_CHANGED_ARP_FILTER ) { +struct wsm_arp_ipv4_filter filter = {0 }; +int i; + +pr_debug ("[STA] BSS_CHANGED_ARP_FILTER enabled: %d, cnt: %d\n" , + info->arp_filter_enabled, + info->arp_addr_cnt); + +if (info->arp_filter_enabled) + filter.enable =__cpu_to_le32 (1 ); + +/* Currently only one IP address is supported by firmware. +* In case of more IPs arp filtering will be disabled. */ +if (info->arp_addr_cnt >0 && + info->arp_addr_cnt <=WSM_MAX_ARP_IP_ADDRTABLE_ENTRIES ) { +for (i =0 ; i < info->arp_addr_cnt; i++) { + filter.ipv4Address[i] = info->arp_addr_list[i]; +pr_debug ("[STA] addr[%d]: 0x%X\n" , + i, filter.ipv4Address[i]); + } + }else + filter.enable =0 ; + +pr_debug ("[STA] arp ip filter enable: %d\n" , +__le32_to_cpu (filter.enable)); + +if (wsm_set_arp_ipv4_filter (priv, &filter)) +WARN_ON (1 ); + } + + +if (changed & + (BSS_CHANGED_BEACON | +BSS_CHANGED_IBSS )) { +pr_debug ("BSS_CHANGED_BEACON\n" ); +WARN_ON (cw1200_update_beaconing (priv)); +WARN_ON (cw1200_upload_beacon (priv)); + } + +if (changed &BSS_CHANGED_BEACON_ENABLED ) { +pr_debug ("BSS_CHANGED_BEACON_ENABLED\n" ); + +if (priv->enable_beacon != info->enable_beacon) { +WARN_ON (cw1200_enable_beaconing (priv, + info->enable_beacon)); + priv->enable_beacon = info->enable_beacon; + } + } + +if (changed &BSS_CHANGED_BEACON_INT ) { +pr_debug ("CHANGED_BEACON_INT\n" ); +/* Restart AP only when connected */ +if (priv->join_status ==CW1200_JOIN_STATUS_AP || info->ibss_joined) +WARN_ON (cw1200_update_beaconing (priv)); + } + +/* assoc/disassoc, or maybe AID changed */ +if (changed &BSS_CHANGED_ASSOC ) { +wsm_lock_tx (priv); + priv->wep_default_key_id =-1 ; +wsm_unlock_tx (priv); + +if (info->assoc && !info->ibss_joined) + priv->cqm_beacon_loss_count =20 ; + } + +if (changed & + (BSS_CHANGED_ASSOC | +BSS_CHANGED_BSSID | +BSS_CHANGED_IBSS | +BSS_CHANGED_BASIC_RATES | +BSS_CHANGED_ERP_PREAMBLE | +BSS_CHANGED_HT | +BSS_CHANGED_ERP_SLOT )) { +pr_debug ("BSS_CHANGED_ASSOC.\n" ); +if (info->assoc) { +int i, join_tmo =10 *CW1200_JOIN_TIMEOUT /HZ +1 ; +/* "Associated but not joined" sounds like a nonsense, +* but might happen. It is a quite seldom corner case, +* so it is implemented as simple as possible, +* efficiency has no priority here :) */ +for (i =0 ; i < join_tmo && priv->join_status == +CW1200_JOIN_STATUS_JOINING ; ++i) { +mutex_unlock (&priv->conf_mutex); +/* 100 ms busy wait is not so bad approach +* as it looks like: firmware joins +* on beacons. And this is a slowpath. */ +msleep (100 ); +mutex_lock (&priv->conf_mutex); + } + +if (priv->join_status <CW1200_JOIN_STATUS_PRE_STA ) { +ieee80211_connection_loss (vif); +mutex_unlock (&priv->conf_mutex); +return ; + }else if (priv->join_status ==CW1200_JOIN_STATUS_PRE_STA ) { +/* Check for a quite unlikely race: if timeout +* work has been already scheduled, but not yet +* executed.*/ +if (!cancel_delayed_work_sync (&priv->join_timeout)) { +ieee80211_connection_loss (vif); +mutex_unlock (&priv->conf_mutex); +return ; + } + priv->join_status =CW1200_JOIN_STATUS_STA ; + } + } +if (info->assoc || info->ibss_joined) { +struct ieee80211_sta *sta =NULL ; +if (info->dtim_period) + priv->join_dtim_period = info->dtim_period; + priv->beacon_int = info->beacon_int; + +rcu_read_lock (); + +if (info->bssid && !info->ibss_joined) + sta =ieee80211_find_sta (vif, info->bssid); +if (sta) { + priv->ht_info.ht_cap = sta->ht_cap; + priv->bss_params.operationalRateSet = +__cpu_to_le32 ( +cw1200_rate_mask_to_wsm (priv, + sta->supp_rates[priv->channel->band])); + priv->ht_info.channel_type = dev->conf.channel_type; + priv->ht_info.operation_mode = info->ht_operation_mode; + }else { +memset (&priv->ht_info,0 , +sizeof (priv->ht_info)); + priv->bss_params.operationalRateSet =-1 ; + } +rcu_read_unlock (); + +if (sta) { +__le32 val =0 ; +if (priv->ht_info.operation_mode & +IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT ) { +pr_debug ("[STA] Non-GF STA present\n" ); +/* Non Green field capable STA */ + val =__cpu_to_le32 (WSM_NON_GREENFIELD_STA_PRESENT ); + } +WARN_ON (wsm_write_mib (priv, +WSM_MID_ID_SET_HT_PROTECTION , + &val,sizeof (val))); + } + + priv->association_mode.greenfieldMode = +cw1200_ht_greenfield (&priv->ht_info); + priv->association_mode.flags = +WSM_ASSOCIATION_MODE_SNOOP_ASSOC_FRAMES | +WSM_ASSOCIATION_MODE_USE_PREAMBLE_TYPE | +WSM_ASSOCIATION_MODE_USE_HT_MODE | +WSM_ASSOCIATION_MODE_USE_BASIC_RATE_SET | +WSM_ASSOCIATION_MODE_USE_MPDU_START_SPACING ; + priv->association_mode.preambleType = + info->use_short_preamble ? +WSM_JOIN_PREAMBLE_SHORT : +WSM_JOIN_PREAMBLE_LONG ; + priv->association_mode.basicRateSet =__cpu_to_le32 ( +cw1200_rate_mask_to_wsm (priv, + info->basic_rates)); + priv->association_mode.mpduStartSpacing = +cw1200_ht_ampdu_density (&priv->ht_info); + + priv->delayed_link_loss =0 ; +spin_lock (&priv->bss_loss_lock); + priv->bss_loss_status =CW1200_BSS_LOSS_NONE ; +spin_unlock (&priv->bss_loss_lock); + + priv->delayed_link_loss =0 ; +spin_lock (&priv->bss_loss_lock); + priv->bss_loss_status =CW1200_BSS_LOSS_NONE ; + priv->bss_loss_checking =0 ; +spin_unlock (&priv->bss_loss_lock); +cancel_delayed_work_sync (&priv->bss_loss_work); +cancel_delayed_work_sync (&priv->connection_loss_work); +cancel_work_sync (&priv->unjoin_work); + + priv->bss_params.beaconLostCount = priv->cqm_beacon_loss_count; + + priv->bss_params.aid = info->aid; + +if (priv->join_dtim_period <1 ) + priv->join_dtim_period =1 ; + +pr_debug ("[STA] DTIM %d, interval: %d\n" , + priv->join_dtim_period, priv->beacon_int); +pr_debug ("[STA] Preamble: %d, " \ +"Greenfield: %d, Aid: %d, " \ +"Rates: 0x%.8X, Basic: 0x%.8X\n" , + priv->association_mode.preambleType, + priv->association_mode.greenfieldMode, + priv->bss_params.aid, + priv->bss_params.operationalRateSet, + priv->association_mode.basicRateSet); +WARN_ON (wsm_set_association_mode (priv, + &priv->association_mode)); +WARN_ON (wsm_keep_alive_period (priv,30 /* sec */ )); +WARN_ON (wsm_set_bss_params (priv, &priv->bss_params)); + priv->setbssparams_done = true; +WARN_ON (wsm_set_beacon_wakeup_period (priv, + priv->beacon_int * priv->join_dtim_period > +MAX_BEACON_SKIP_TIME_MS ?1 : + priv->join_dtim_period,0 )); + +cw1200_set_pm (priv, &priv->powersave_mode); +if (priv->vif->p2p) { +pr_debug ("[STA] Setting p2p powersave configuration.\n" ); +WARN_ON (wsm_set_p2p_ps_modeinfo (priv, + &priv->p2p_ps_modeinfo)); + } + +if (priv->is_BT_Present) +WARN_ON (cw1200_set_btcoexinfo (priv)); + }else { +memset (&priv->association_mode,0 , +sizeof (priv->association_mode)); +memset (&priv->bss_params,0 ,sizeof (priv->bss_params)); + } + } + +if (changed & (BSS_CHANGED_ASSOC |BSS_CHANGED_ERP_CTS_PROT )) { +u32 prev_erp_info = priv->erp_info; + +if (info->use_cts_prot) + priv->erp_info |=WLAN_ERP_USE_PROTECTION ; +else if (!(prev_erp_info &WLAN_ERP_NON_ERP_PRESENT )) + priv->erp_info &= ~WLAN_ERP_USE_PROTECTION ; + +if (prev_erp_info != priv->erp_info) +queue_work (priv->workqueue, &priv->set_cts_work); + } + +if (changed & (BSS_CHANGED_ASSOC |BSS_CHANGED_ERP_SLOT )) { +__le32 slot_time = info->use_short_slot ? +__cpu_to_le32 (9 ) :__cpu_to_le32 (20 ); +pr_debug ("[STA] Slot time :%d us.\n" , +__le32_to_cpu (slot_time)); +WARN_ON (wsm_write_mib (priv,WSM_MIB_ID_DOT11_SLOT_TIME , + &slot_time,sizeof (slot_time))); + } +if (changed & (BSS_CHANGED_ASSOC |BSS_CHANGED_CQM )) { +struct wsm_rcpi_rssi_threshold threshold = { + .rollingAverageCount =8 , + }; + +pr_debug ("[CQM] RSSI threshold subscribe: %d +- %d\n" , + info->cqm_rssi_thold, info->cqm_rssi_hyst); + priv->cqm_rssi_thold = info->cqm_rssi_thold; + priv->cqm_rssi_hyst = info->cqm_rssi_hyst; + +if (info->cqm_rssi_thold || info->cqm_rssi_hyst) { +/* RSSI subscription enabled */ +/* TODO: It's not a correct way of setting threshold. +* Upper and lower must be set equal here and adjusted +* in callback. However current implementation is much +* more relaible and stable. */ + +/* RSSI: signed Q8.0, RCPI: unsigned Q7.1 +* RSSI = RCPI / 2 - 110 */ +if (priv->cqm_use_rssi) { + threshold.upperThreshold = + info->cqm_rssi_thold + info->cqm_rssi_hyst; + threshold.lowerThreshold = + info->cqm_rssi_thold; + threshold.rssiRcpiMode |=WSM_RCPI_RSSI_USE_RSSI ; + }else { + threshold.upperThreshold = (info->cqm_rssi_thold + info->cqm_rssi_hyst +110 ) *2 ; + threshold.lowerThreshold = (info->cqm_rssi_thold +110 ) *2 ; + } + threshold.rssiRcpiMode |=WSM_RCPI_RSSI_THRESHOLD_ENABLE ; + }else { +/* There is a bug in FW, see sta.c. We have to enable +* dummy subscription to get correct RSSI values. */ + threshold.rssiRcpiMode |= +WSM_RCPI_RSSI_THRESHOLD_ENABLE | +WSM_RCPI_RSSI_DONT_USE_UPPER | +WSM_RCPI_RSSI_DONT_USE_LOWER ; +if (priv->cqm_use_rssi) + threshold.rssiRcpiMode |=WSM_RCPI_RSSI_USE_RSSI ; + } +WARN_ON (wsm_set_rcpi_rssi_threshold (priv, &threshold)); + } +mutex_unlock (&priv->conf_mutex); +} + +void cw1200_multicast_start_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, multicast_start_work); +long tmo = priv->join_dtim_period * + (priv->beacon_int +20 ) *HZ /1024 ; + +cancel_work_sync (&priv->multicast_stop_work); + +if (!priv->aid0_bit_set) { +wsm_lock_tx (priv); +cw1200_set_tim_impl (priv, true); + priv->aid0_bit_set = true; +mod_timer (&priv->mcast_timeout, jiffies + tmo); +wsm_unlock_tx (priv); + } +} + +void cw1200_multicast_stop_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, multicast_stop_work); + +if (priv->aid0_bit_set) { +del_timer_sync (&priv->mcast_timeout); +wsm_lock_tx (priv); + priv->aid0_bit_set = false; +cw1200_set_tim_impl (priv, false); +wsm_unlock_tx (priv); + } +} + +void cw1200_mcast_timeout (unsigned long arg) +{ +struct cw1200_common *priv = + (struct cw1200_common *)arg; + +wiphy_warn (priv->hw->wiphy, +"Multicast delivery timeout.\n" ); +spin_lock_bh (&priv->ps_state_lock); + priv->tx_multicast = priv->aid0_bit_set && + priv->buffered_multicasts; +if (priv->tx_multicast) +cw1200_bh_wakeup (priv); +spin_unlock_bh (&priv->ps_state_lock); +} + +int cw1200_ampdu_action (struct ieee80211_hw *hw, +struct ieee80211_vif *vif, +enum ieee80211_ampdu_mlme_action action, +struct ieee80211_sta *sta,u16 tid,u16 *ssn, +u8 buf_size) +{ +/* Aggregation is implemented fully in firmware, +* including block ack negotiation. Do not allow +* mac80211 stack to do anything: it interferes with +* the firmware. */ + +/* Note that we still need this function stubbed. */ +return -ENOTSUPP ; +} + +/* ******************************************************************** */ +/* WSM callback */ +void cw1200_suspend_resume (struct cw1200_common *priv, +struct wsm_suspend_resume *arg) +{ +pr_debug ("[AP] %s: %s\n" , + arg->stop ?"stop" :"start" , + arg->multicast ?"broadcast" :"unicast" ); + +if (arg->multicast) { +bool cancel_tmo = false; +spin_lock_bh (&priv->ps_state_lock); +if (arg->stop) { + priv->tx_multicast = false; + }else { +/* Firmware sends this indication every DTIM if there +* is a STA in powersave connected. There is no reason +* to suspend, following wakeup will consume much more +* power than it could be saved. */ +cw1200_pm_stay_awake (&priv->pm_state, + priv->join_dtim_period * + (priv->beacon_int +20 ) *HZ /1024 ); + priv->tx_multicast = priv->aid0_bit_set && + priv->buffered_multicasts; +if (priv->tx_multicast) { + cancel_tmo = true; +cw1200_bh_wakeup (priv); + } + } +spin_unlock_bh (&priv->ps_state_lock); +if (cancel_tmo) +del_timer_sync (&priv->mcast_timeout); + }else { +spin_lock_bh (&priv->ps_state_lock); +cw1200_ps_notify (priv, arg->link_id, arg->stop); +spin_unlock_bh (&priv->ps_state_lock); +if (!arg->stop) +cw1200_bh_wakeup (priv); + } +return ; +} + +/* ******************************************************************** */ +/* AP privates */ + +static int cw1200_upload_beacon (struct cw1200_common *priv) +{ +int ret =0 ; +struct wsm_template_frame frame = { + .frame_type =WSM_FRAME_TYPE_BEACON , + }; +struct ieee80211_mgmt *mgmt; +u8 *erp_inf, *ies; +u32 ies_len; + +if (priv->vif->p2p) + frame.rate =WSM_TRANSMIT_RATE_6 ; + + frame.skb =ieee80211_beacon_get (priv->hw, priv->vif); +if (WARN_ON (!frame.skb)) +return -ENOMEM ; + + mgmt = (void *)frame.skb->data; + ies = mgmt->u.beacon.variable; + ies_len = frame.skb->len - (u32)(ies - (u8 *)mgmt); + erp_inf = (u8 *)cfg80211_find_ie (WLAN_EID_ERP_INFO , ies, ies_len); +if (erp_inf) { +if (erp_inf[ERP_INFO_BYTE_OFFSET ] + &WLAN_ERP_BARKER_PREAMBLE ) + priv->erp_info |=WLAN_ERP_BARKER_PREAMBLE ; +else + priv->erp_info &= ~WLAN_ERP_BARKER_PREAMBLE ; + +if (erp_inf[ERP_INFO_BYTE_OFFSET ] + &WLAN_ERP_NON_ERP_PRESENT ) { + priv->erp_info |=WLAN_ERP_USE_PROTECTION ; + priv->erp_info |=WLAN_ERP_NON_ERP_PRESENT ; + }else { + priv->erp_info &= ~WLAN_ERP_USE_PROTECTION ; + priv->erp_info &= ~WLAN_ERP_NON_ERP_PRESENT ; + } + } + + ret =wsm_set_template_frame (priv, &frame); +if (!ret) { +/* TODO: Distill probe resp; remove TIM +* and other beacon-specific IEs */ + *(__le16 *)frame.skb->data = +__cpu_to_le16 (IEEE80211_FTYPE_MGMT | +IEEE80211_STYPE_PROBE_RESP ); + frame.frame_type =WSM_FRAME_TYPE_PROBE_RESPONSE ; +if (priv->vif->p2p) { + ret =wsm_set_probe_responder (priv, true); + }else { + ret =wsm_set_template_frame (priv, &frame); +WARN_ON (wsm_set_probe_responder (priv, false)); + } + } +dev_kfree_skb (frame.skb); + +return ret; +} + +static int cw1200_upload_pspoll (struct cw1200_common *priv) +{ +int ret =0 ; +struct wsm_template_frame frame = { + .frame_type =WSM_FRAME_TYPE_PS_POLL , + .rate =0xFF , + }; + + + frame.skb =ieee80211_pspoll_get (priv->hw, priv->vif); +if (WARN_ON (!frame.skb)) +return -ENOMEM ; + + ret =wsm_set_template_frame (priv, &frame); + +dev_kfree_skb (frame.skb); + +return ret; +} + +static int cw1200_upload_null (struct cw1200_common *priv) +{ +int ret =0 ; +struct wsm_template_frame frame = { + .frame_type =WSM_FRAME_TYPE_NULL , + .rate =0xFF , + }; + + frame.skb =ieee80211_nullfunc_get (priv->hw, priv->vif); +if (WARN_ON (!frame.skb)) +return -ENOMEM ; + + ret =wsm_set_template_frame (priv, &frame); + +dev_kfree_skb (frame.skb); + +return ret; +} + +static int cw1200_upload_qosnull (struct cw1200_common *priv) +{ +int ret =0 ; +#if 0 /* XXX this needs to be implemented.. */ +struct wsm_template_frame frame = { + .frame_type =WSM_FRAME_TYPE_QOS_NULL , + .rate =0xFF , + }; + + frame.skb =ieee80211_qosnullfunc_get (priv->hw, priv->vif); +if (WARN_ON (!frame.skb)) +return -ENOMEM ; + + ret =wsm_set_template_frame (priv, &frame); + +dev_kfree_skb (frame.skb); +#endif +return ret; +} + +static int cw1200_enable_beaconing (struct cw1200_common *priv, +bool enable) +{ +struct wsm_beacon_transmit transmit = { + .enableBeaconing = enable, + }; + +return wsm_beacon_transmit (priv, &transmit); +} + +static int cw1200_start_ap (struct cw1200_common *priv) +{ +int ret; +struct ieee80211_bss_conf *conf = &priv->vif->bss_conf; +struct wsm_start start = { + .mode = priv->vif->p2p ? +WSM_START_MODE_P2P_GO :WSM_START_MODE_AP , + .band = (priv->channel->band ==IEEE80211_BAND_5GHZ ) ? +WSM_PHY_BAND_5G :WSM_PHY_BAND_2_4G , + .channelNumber = priv->channel->hw_value, + .beaconInterval = conf->beacon_int, + .DTIMPeriod = conf->dtim_period, + .preambleType = conf->use_short_preamble ? +WSM_JOIN_PREAMBLE_SHORT : +WSM_JOIN_PREAMBLE_LONG , + .probeDelay =100 , + .basicRateSet =cw1200_rate_mask_to_wsm (priv, + conf->basic_rates), + }; +struct wsm_operational_mode mode = { + .power_mode = cw1200_power_mode, + .disableMoreFlagUsage = true, + }; + +memset (start.ssid,0 ,sizeof (start.ssid)); +if (!conf->hidden_ssid) { + start.ssidLength = conf->ssid_len; +memcpy (start.ssid, conf->ssid, start.ssidLength); + } + + priv->beacon_int = conf->beacon_int; + priv->join_dtim_period = conf->dtim_period; + +memset (&priv->link_id_db,0 ,sizeof (priv->link_id_db)); + +pr_debug ("[AP] ch: %d(%d), bcn: %d(%d), brt: 0x%.8X, ssid: %.*s.\n" , + start.channelNumber, start.band, + start.beaconInterval, start.DTIMPeriod, + start.basicRateSet, + start.ssidLength, start.ssid); + ret =WARN_ON (wsm_start (priv, &start)); +if (!ret) + ret =WARN_ON (cw1200_upload_keys (priv)); +if (!ret && priv->vif->p2p) { +pr_debug ("[AP] Setting p2p powersave configuration.\n" ); +WARN_ON (wsm_set_p2p_ps_modeinfo (priv, + &priv->p2p_ps_modeinfo)); + } +if (!ret) { +WARN_ON (wsm_set_block_ack_policy (priv,0 ,0 )); + priv->join_status =CW1200_JOIN_STATUS_AP ; +cw1200_update_filtering (priv); + } +WARN_ON (wsm_set_operational_mode (priv, &mode)); +return ret; +} + +static int cw1200_update_beaconing (struct cw1200_common *priv) +{ +struct ieee80211_bss_conf *conf = &priv->vif->bss_conf; +struct wsm_reset reset = { + .link_id =0 , + .reset_statistics = true, + }; + +if (priv->mode ==NL80211_IFTYPE_AP ) { +/* TODO: check if changed channel, band */ +if (priv->join_status !=CW1200_JOIN_STATUS_AP || + priv->beacon_int != conf->beacon_int) { +pr_debug ("ap restarting\n" ); +wsm_lock_tx (priv); +if (priv->join_status !=CW1200_JOIN_STATUS_PASSIVE ) +WARN_ON (wsm_reset (priv, &reset)); + priv->join_status =CW1200_JOIN_STATUS_PASSIVE ; +WARN_ON (cw1200_start_ap (priv)); +wsm_unlock_tx (priv); + }else +pr_debug ("ap started join_status: %d\n" , + priv->join_status); + } +return 0 ; +} +
drivers/net/wireless/cw1200/sta.h new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 8/14 cw1200: v4: Packet TX/RX
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/txrx.c | 1520 ++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/txrx.h | 104 +++ 2 files changed, 1624 insertions(+) create mode 100644 drivers/net/wireless/cw1200/txrx.c create mode 100644 drivers/net/wireless/cw1200/txrx.h
drivers/net/wireless/cw1200/txrx.c new file +1520 -0
@@ -0,0 +1,1520 @@ +/* +* Datapath implementation for ST-Ericsson CW1200 mac80211 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <net/mac80211.h> +#include <linux/etherdevice.h> +#include <linux/skbuff.h> + +#include "cw1200.h" +#include "wsm.h" +#include "bh.h" +#include "sta.h" +#include "debug.h" + +#define CW1200_INVALID_RATE_ID (0xFF) + +static int cw1200_handle_action_rx (struct cw1200_common *priv, +struct sk_buff *skb); +static const struct ieee80211_rate * +cw1200_get_tx_rate (const struct cw1200_common *priv, +const struct ieee80211_tx_rate *rate); + +/* ******************************************************************** */ +/* TX queue lock / unlock */ + +static inline void cw1200_tx_queues_lock (struct cw1200_common *priv) +{ +int i; +for (i =0 ; i <4 ; ++i) +cw1200_queue_lock (&priv->tx_queue[i]); +} + +static inline void cw1200_tx_queues_unlock (struct cw1200_common *priv) +{ +int i; +for (i =0 ; i <4 ; ++i) +cw1200_queue_unlock (&priv->tx_queue[i]); +} + +/* ******************************************************************** */ +/* TX policy cache implementation */ + +static void tx_policy_dump (struct tx_policy *policy) +{ +pr_debug ("[TX policy] %.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X %.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X %.1X%.1X%.1X%.1X%.1X%.1X%.1X%.1X: %d\n" , + policy->raw[0 ] &0x0F , policy->raw[0 ] >>4 , + policy->raw[1 ] &0x0F , policy->raw[1 ] >>4 , + policy->raw[2 ] &0x0F , policy->raw[2 ] >>4 , + policy->raw[3 ] &0x0F , policy->raw[3 ] >>4 , + policy->raw[4 ] &0x0F , policy->raw[4 ] >>4 , + policy->raw[5 ] &0x0F , policy->raw[5 ] >>4 , + policy->raw[6 ] &0x0F , policy->raw[6 ] >>4 , + policy->raw[7 ] &0x0F , policy->raw[7 ] >>4 , + policy->raw[8 ] &0x0F , policy->raw[8 ] >>4 , + policy->raw[9 ] &0x0F , policy->raw[9 ] >>4 , + policy->raw[10 ] &0x0F , policy->raw[10 ] >>4 , + policy->raw[11 ] &0x0F , policy->raw[11 ] >>4 , + policy->defined); +} + +static void tx_policy_build (const struct cw1200_common *priv, +/* [out] */ struct tx_policy *policy, +struct ieee80211_tx_rate *rates,size_t count) +{ +int i, j; +unsigned limit = priv->short_frame_max_tx_count; +unsigned total =0 ; +BUG_ON (rates[0 ].idx <0 ); +memset (policy,0 ,sizeof (*policy)); + +/* minstrel is buggy a little bit, so distille +* incoming rates first. */ + +/* Sort rates in descending order. */ +for (i =1 ; i < count; ++i) { +if (rates[i].idx <0 ) { + count = i; +break ; + } +if (rates[i].idx > rates[i -1 ].idx) { +struct ieee80211_tx_rate tmp = rates[i -1 ]; + rates[i -1 ] = rates[i]; + rates[i] = tmp; + } + } + +/* Eliminate duplicates. */ + total = rates[0 ].count; +for (i =0 , j =1 ; j < count; ++j) { +if (rates[j].idx == rates[i].idx) { + rates[i].count += rates[j].count; + }else if (rates[j].idx > rates[i].idx) { +break ; + }else { + ++i; +if (i != j) + rates[i] = rates[j]; + } + total += rates[j].count; + } + count = i +1 ; + +/* Re-fill policy trying to keep every requested rate and with +* respect to the global max tx retransmission count. */ +if (limit < count) + limit = count; +if (total > limit) { +for (i =0 ; i < count; ++i) { +int left = count - i -1 ; +if (rates[i].count > limit - left) + rates[i].count = limit - left; + limit -= rates[i].count; + } + } + +/* HACK!!! Device has problems (at least) switching from +* 54Mbps CTS to 1Mbps. This switch takes enormous amount +* of time (100-200 ms), leading to valuable throughput drop. +* As a workaround, additional g-rates are injected to the +* policy. +*/ +if (count ==2 && !(rates[0 ].flags &IEEE80211_TX_RC_MCS ) && + rates[0 ].idx >4 && rates[0 ].count >2 && + rates[1 ].idx <2 ) { +/* ">> 1" is an equivalent of "/ 2", but faster */ +int mid_rate = (rates[0 ].idx +4 ) >>1 ; + +/* Decrease number of retries for the initial rate */ + rates[0 ].count -=2 ; + +if (mid_rate !=4 ) { +/* Keep fallback rate at 1Mbps. */ + rates[3 ] = rates[1 ]; + +/* Inject 1 transmission on lowest g-rate */ + rates[2 ].idx =4 ; + rates[2 ].count =1 ; + rates[2 ].flags = rates[1 ].flags; + +/* Inject 1 transmission on mid-rate */ + rates[1 ].idx = mid_rate; + rates[1 ].count =1 ; + +/* Fallback to 1 Mbps is a really bad thing, +* so let's try to increase probability of +* successful transmission on the lowest g rate +* even more */ +if (rates[0 ].count >=3 ) { + --rates[0 ].count; + ++rates[2 ].count; + } + +/* Adjust amount of rates defined */ + count +=2 ; + }else { +/* Keep fallback rate at 1Mbps. */ + rates[2 ] = rates[1 ]; + +/* Inject 2 transmissions on lowest g-rate */ + rates[1 ].idx =4 ; + rates[1 ].count =2 ; + +/* Adjust amount of rates defined */ + count +=1 ; + } + } + + policy->defined =cw1200_get_tx_rate (priv, &rates[0 ])->hw_value +1 ; + +for (i =0 ; i < count; ++i) { + registerunsigned rateid, off, shift, retries; + + rateid =cw1200_get_tx_rate (priv, &rates[i])->hw_value; + off = rateid >>3 ;/* eq. rateid / 8 */ + shift = (rateid &0x07 ) <<2 ;/* eq. (rateid % 8) * 4 */ + + retries = rates[i].count; +if (retries >0x0F ) + rates[i].count = retries =0x0F ; + policy->tbl[off] |=__cpu_to_le32 (retries << shift); + policy->retry_count += retries; + } + +pr_debug ("[TX policy] Policy (%zu): %d:%d, %d:%d, %d:%d, %d:%d, %d:%d\n" , + count, + rates[0 ].idx, rates[0 ].count, + rates[1 ].idx, rates[1 ].count, + rates[2 ].idx, rates[2 ].count, + rates[3 ].idx, rates[3 ].count, + rates[4 ].idx, rates[4 ].count); +} + +static inline bool tx_policy_is_equal (const struct tx_policy *wanted, +const struct tx_policy *cached) +{ +size_t count = wanted->defined >>1 ; +if (wanted->defined > cached->defined) +return false; +if (count) { +if (memcmp (wanted->raw, cached->raw, count)) +return false; + } +if (wanted->defined &1 ) { +if ((wanted->raw[count] &0x0F ) != (cached->raw[count] &0x0F )) +return false; + } +return true; +} + +static int tx_policy_find (struct tx_policy_cache *cache, +const struct tx_policy *wanted) +{ +/* O(n) complexity. Not so good, but there's only 8 entries in +* the cache. +* Also lru helps to reduce search time. */ +struct tx_policy_cache_entry *it; +/* First search for policy in "used" list */ +list_for_each_entry (it, &cache->used, link) { +if (tx_policy_is_equal (wanted, &it->policy)) +return it - cache->cache; + } +/* Then - in "free list" */ +list_for_each_entry (it, &cache->free, link) { +if (tx_policy_is_equal (wanted, &it->policy)) +return it - cache->cache; + } +return -1 ; +} + +static inline void tx_policy_use (struct tx_policy_cache *cache, +struct tx_policy_cache_entry *entry) +{ + ++entry->policy.usage_count; +list_move (&entry->link, &cache->used); +} + +static inline int tx_policy_release (struct tx_policy_cache *cache, +struct tx_policy_cache_entry *entry) +{ +int ret = --entry->policy.usage_count; +if (!ret) +list_move (&entry->link, &cache->free); +return ret; +} + +void tx_policy_clean (struct cw1200_common *priv) +{ +int idx, locked; +struct tx_policy_cache *cache = &priv->tx_policy_cache; +struct tx_policy_cache_entry *entry; + +cw1200_tx_queues_lock (priv); +spin_lock_bh (&cache->lock); + locked =list_empty (&cache->free); + +for (idx =0 ; idx <TX_POLICY_CACHE_SIZE ; idx++) { + entry = &cache->cache[idx]; +/* Policy usage count should be 0 at this time as all queues +should be empty */ +if (entry->policy.usage_count) { +WARN_ON (1 ); + entry->policy.usage_count =0 ; +list_move (&entry->link, &cache->free); + } +memset (&entry->policy,0 ,sizeof (entry->policy)); + } +if (locked) +cw1200_tx_queues_unlock (priv); + +cw1200_tx_queues_unlock (priv); +spin_unlock_bh (&cache->lock); +} + +/* ******************************************************************** */ +/* External TX policy cache API */ + +void tx_policy_init (struct cw1200_common *priv) +{ +struct tx_policy_cache *cache = &priv->tx_policy_cache; +int i; + +memset (cache,0 ,sizeof (*cache)); + +spin_lock_init (&cache->lock); +INIT_LIST_HEAD (&cache->used); +INIT_LIST_HEAD (&cache->free); + +for (i =0 ; i <TX_POLICY_CACHE_SIZE ; ++i) +list_add (&cache->cache[i].link, &cache->free); +} + +static int tx_policy_get (struct cw1200_common *priv, +struct ieee80211_tx_rate *rates, +size_t count,bool *renew) +{ +int idx; +struct tx_policy_cache *cache = &priv->tx_policy_cache; +struct tx_policy wanted; + +tx_policy_build (priv, &wanted, rates, count); + +spin_lock_bh (&cache->lock); +if (WARN_ON_ONCE (list_empty (&cache->free))) { +spin_unlock_bh (&cache->lock); +return CW1200_INVALID_RATE_ID ; + } + idx =tx_policy_find (cache, &wanted); +if (idx >=0 ) { +pr_debug ("[TX policy] Used TX policy: %d\n" , + idx); + *renew = false; + }else { +struct tx_policy_cache_entry *entry; + *renew = true; +/* If policy is not found create a new one +* using the oldest entry in "free" list */ + entry =list_entry (cache->free.prev, + struct tx_policy_cache_entry, link); + entry->policy = wanted; + idx = entry - cache->cache; +pr_debug ("[TX policy] New TX policy: %d\n" , idx); +tx_policy_dump (&entry->policy); + } +tx_policy_use (cache, &cache->cache[idx]); +if (list_empty (&cache->free)) { +/* Lock TX queues. */ +cw1200_tx_queues_lock (priv); + } +spin_unlock_bh (&cache->lock); +return idx; +} + +static void tx_policy_put (struct cw1200_common *priv,int idx) +{ +int usage, locked; +struct tx_policy_cache *cache = &priv->tx_policy_cache; + +spin_lock_bh (&cache->lock); + locked =list_empty (&cache->free); + usage =tx_policy_release (cache, &cache->cache[idx]); +if (locked && !usage) { +/* Unlock TX queues. */ +cw1200_tx_queues_unlock (priv); + } +spin_unlock_bh (&cache->lock); +} + +/* +bool tx_policy_cache_full(struct cw1200_common *priv) +{ +bool ret; +struct tx_policy_cache *cache = &priv->tx_policy_cache; +spin_lock_bh(&cache->lock); +ret = list_empty(&cache->free); +spin_unlock_bh(&cache->lock); +return ret; +} +*/ + +static int tx_policy_upload (struct cw1200_common *priv) +{ +struct tx_policy_cache *cache = &priv->tx_policy_cache; +int i; +struct wsm_set_tx_rate_retry_policy arg = { + .hdr = { + .numTxRatePolicies =0 , + } + }; +spin_lock_bh (&cache->lock); + +/* Upload only modified entries. */ +for (i =0 ; i <TX_POLICY_CACHE_SIZE ; ++i) { +struct tx_policy *src = &cache->cache[i].policy; +if (src->retry_count && !src->uploaded) { +struct wsm_set_tx_rate_retry_policy_policy *dst = + &arg.tbl[arg.hdr.numTxRatePolicies]; + dst->policyIndex = i; + dst->shortRetryCount = priv->short_frame_max_tx_count; + dst->longRetryCount = priv->long_frame_max_tx_count; + +/* BIT(2) - Terminate retries when Tx rate retry policy +* finishes. +* BIT(3) - Count initial frame transmission as part of +* rate retry counting but not as a retry +* attempt */ + dst->policyFlags =BIT (2 ) |BIT (3 ); + +memcpy (dst->rateCountIndices, src->tbl, +sizeof (dst->rateCountIndices)); + src->uploaded =1 ; + ++arg.hdr.numTxRatePolicies; + } + } +spin_unlock_bh (&cache->lock); +cw1200_debug_tx_cache_miss (priv); +pr_debug ("[TX policy] Upload %d policies\n" , + arg.hdr.numTxRatePolicies); +return wsm_set_tx_rate_retry_policy (priv, &arg); +} + +void tx_policy_upload_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, tx_policy_upload_work); + +pr_debug ("[TX] TX policy upload.\n" ); +WARN_ON (tx_policy_upload (priv)); + +wsm_unlock_tx (priv); +cw1200_tx_queues_unlock (priv); +} + +/* ******************************************************************** */ +/* cw1200 TX implementation */ + +struct cw1200_txinfo { +struct sk_buff *skb; +unsigned queue; +struct ieee80211_tx_info *tx_info; +const struct ieee80211_rate *rate; +struct ieee80211_hdr *hdr; +size_t hdrlen; +const u8 *da; +struct cw1200_sta_priv *sta_priv; +struct ieee80211_sta *sta; +struct cw1200_txpriv txpriv; +}; + +u32 cw1200_rate_mask_to_wsm (struct cw1200_common *priv,u32 rates) +{ +u32 ret =0 ; +int i; +for (i =0 ; i <32 ; ++i) { +if (rates &BIT (i)) + ret |=BIT (priv->rates[i].hw_value); + } +return ret; +} + +static const struct ieee80211_rate * +cw1200_get_tx_rate (const struct cw1200_common *priv, +const struct ieee80211_tx_rate *rate) +{ +if (rate->idx <0 ) +return NULL ; +if (rate->flags &IEEE80211_TX_RC_MCS ) +return &priv->mcs_rates[rate->idx]; +return &priv->hw->wiphy->bands[priv->channel->band]-> + bitrates[rate->idx]; +} + +static int +cw1200_tx_h_calc_link_ids (struct cw1200_common *priv, +struct cw1200_txinfo *t) +{ +if (t->sta && t->sta_priv->link_id) + t->txpriv.raw_link_id = + t->txpriv.link_id = + t->sta_priv->link_id; +else if (priv->mode !=NL80211_IFTYPE_AP ) + t->txpriv.raw_link_id = + t->txpriv.link_id =0 ; +else if (is_multicast_ether_addr (t->da)) { +if (priv->enable_beacon) { + t->txpriv.raw_link_id =0 ; + t->txpriv.link_id =CW1200_LINK_ID_AFTER_DTIM ; + }else { + t->txpriv.raw_link_id =0 ; + t->txpriv.link_id =0 ; + } + }else { + t->txpriv.link_id =cw1200_find_link_id (priv, t->da); +if (!t->txpriv.link_id) + t->txpriv.link_id =cw1200_alloc_link_id (priv, t->da); +if (!t->txpriv.link_id) { +wiphy_err (priv->hw->wiphy, +"%s: No more link IDs available.\n" , + __func__); +return -ENOENT ; + } + t->txpriv.raw_link_id = t->txpriv.link_id; + } +if (t->txpriv.raw_link_id) + priv->link_id_db[t->txpriv.raw_link_id -1 ].timestamp = + jiffies; +if (t->sta && (t->sta->uapsd_queues &BIT (t->queue))) + t->txpriv.link_id =CW1200_LINK_ID_UAPSD ; +return 0 ; +} + +static void +cw1200_tx_h_pm (struct cw1200_common *priv, +struct cw1200_txinfo *t) +{ +if (ieee80211_is_auth (t->hdr->frame_control)) { +u32 mask = ~BIT (t->txpriv.raw_link_id); +spin_lock_bh (&priv->ps_state_lock); + priv->sta_asleep_mask &= mask; + priv->pspoll_mask &= mask; +spin_unlock_bh (&priv->ps_state_lock); + } +} + +static void +cw1200_tx_h_calc_tid (struct cw1200_common *priv, +struct cw1200_txinfo *t) +{ +if (ieee80211_is_data_qos (t->hdr->frame_control)) { +u8 *qos =ieee80211_get_qos_ctl (t->hdr); + t->txpriv.tid = qos[0 ] &IEEE80211_QOS_CTL_TID_MASK ; + }else if (ieee80211_is_data (t->hdr->frame_control)) { + t->txpriv.tid =0 ; + } +} + +static int +cw1200_tx_h_crypt (struct cw1200_common *priv, +struct cw1200_txinfo *t) +{ +if (!t->tx_info->control.hw_key || + !ieee80211_has_protected (t->hdr->frame_control)) +return 0 ; + + t->hdrlen += t->tx_info->control.hw_key->iv_len; +skb_put (t->skb, t->tx_info->control.hw_key->icv_len); + +if (t->tx_info->control.hw_key->cipher ==WLAN_CIPHER_SUITE_TKIP ) +skb_put (t->skb,8 );/* MIC space */ + +return 0 ; +} + +static int +cw1200_tx_h_align (struct cw1200_common *priv, +struct cw1200_txinfo *t, +u8 *flags) +{ +size_t offset = (size_t )t->skb->data &3 ; + +if (!offset) +return 0 ; + +if (offset &1 ) { +wiphy_err (priv->hw->wiphy, +"Bug: attempt to transmit a frame " +"with wrong alignment: %zu\n" , + offset); +return -EINVAL ; + } + +if (skb_headroom (t->skb) < offset) { +wiphy_err (priv->hw->wiphy, +"Bug: no space allocated " +"for DMA alignment.\n" +"headroom: %d\n" , +skb_headroom (t->skb)); +return -ENOMEM ; + } +skb_push (t->skb, offset); + t->hdrlen += offset; + t->txpriv.offset += offset; + *flags |=WSM_TX_2BYTES_SHIFT ; +cw1200_debug_tx_align (priv); +return 0 ; +} + +static int +cw1200_tx_h_action (struct cw1200_common *priv, +struct cw1200_txinfo *t) +{ +struct ieee80211_mgmt *mgmt = + (struct ieee80211_mgmt *)t->hdr; +if (ieee80211_is_action (t->hdr->frame_control) && + mgmt->u.action.category ==WLAN_CATEGORY_BACK ) +return 1 ; +else +return 0 ; +} + +/* Add WSM header */ +static struct wsm_tx * +cw1200_tx_h_wsm (struct cw1200_common *priv, +struct cw1200_txinfo *t) +{ +struct wsm_tx *wsm; + +if (skb_headroom (t->skb) <sizeof (struct wsm_tx )) { +wiphy_err (priv->hw->wiphy, +"Bug: no space allocated " +"for WSM header.\n" +"headroom: %d\n" , +skb_headroom (t->skb)); +return NULL ; + } + + wsm = (struct wsm_tx *)skb_push (t->skb,sizeof (struct wsm_tx )); + t->txpriv.offset +=sizeof (struct wsm_tx ); +memset (wsm,0 ,sizeof (*wsm)); + wsm->hdr.len =__cpu_to_le16 (t->skb->len); + wsm->hdr.id =__cpu_to_le16 (0x0004 ); + wsm->queueId =wsm_queue_id_to_wsm (t->queue); +return wsm; +} + +/* BT Coex specific handling */ +static void +cw1200_tx_h_bt (struct cw1200_common *priv, +struct cw1200_txinfo *t, +struct wsm_tx *wsm) +{ +u8 priority =0 ; + +if (!priv->is_BT_Present) +return ; + +if (ieee80211_is_nullfunc (t->hdr->frame_control)) + priority =WSM_EPTA_PRIORITY_MGT ; +else if (ieee80211_is_data (t->hdr->frame_control)) { +/* Skip LLC SNAP header (+6) */ +u8 *payload = &t->skb->data[t->hdrlen]; +u16 *ethertype = (u16 *) &payload[6 ]; +if (*ethertype ==__be16_to_cpu (ETH_P_PAE )) + priority =WSM_EPTA_PRIORITY_EAPOL ; + }else if (ieee80211_is_assoc_req (t->hdr->frame_control) || +ieee80211_is_reassoc_req (t->hdr->frame_control)) { +struct ieee80211_mgmt *mgt_frame = + (struct ieee80211_mgmt *)t->hdr; + +if (mgt_frame->u.assoc_req.listen_interval < + priv->listen_interval) { +pr_debug ("Modified Listen Interval to %d from %d\n" , + priv->listen_interval, + mgt_frame->u.assoc_req.listen_interval); +/* Replace listen interval derieved from +* the one read from SDD */ + mgt_frame->u.assoc_req.listen_interval = + priv->listen_interval; + } + } + +if (!priority) { +if (ieee80211_is_action (t->hdr->frame_control)) + priority =WSM_EPTA_PRIORITY_ACTION ; +else if (ieee80211_is_mgmt (t->hdr->frame_control)) + priority =WSM_EPTA_PRIORITY_MGT ; +else if ((wsm->queueId ==WSM_QUEUE_VOICE )) + priority =WSM_EPTA_PRIORITY_VOICE ; +else if ((wsm->queueId ==WSM_QUEUE_VIDEO )) + priority =WSM_EPTA_PRIORITY_VIDEO ; +else + priority =WSM_EPTA_PRIORITY_DATA ; + } + +pr_debug ("[TX] EPTA priority %d.\n" , + priority); + + wsm->flags |= priority <<1 ; +} + +static int +cw1200_tx_h_rate_policy (struct cw1200_common *priv, +struct cw1200_txinfo *t, +struct wsm_tx *wsm) +{ +bool tx_policy_renew = false; + + t->txpriv.rate_id =tx_policy_get (priv, + t->tx_info->control.rates,IEEE80211_TX_MAX_RATES , + &tx_policy_renew); +if (t->txpriv.rate_id ==CW1200_INVALID_RATE_ID ) +return -EFAULT ; + + wsm->flags |= t->txpriv.rate_id <<4 ; + + t->rate =cw1200_get_tx_rate (priv, + &t->tx_info->control.rates[0 ]), + wsm->maxTxRate = t->rate->hw_value; +if (t->rate->flags &IEEE80211_TX_RC_MCS ) { +if (cw1200_ht_greenfield (&priv->ht_info)) + wsm->htTxParameters |= +__cpu_to_le32 (WSM_HT_TX_GREENFIELD ); +else + wsm->htTxParameters |= +__cpu_to_le32 (WSM_HT_TX_MIXED ); + } + +if (tx_policy_renew) { +pr_debug ("[TX] TX policy renew.\n" ); +/* It's not so optimal to stop TX queues every now and then. +* Maybe it's better to reimplement task scheduling with +* a counter. */ +/* cw1200_tx_queues_lock(priv); */ +/* Definetly better. TODO. */ +wsm_lock_tx_async (priv); +cw1200_tx_queues_lock (priv); +if (queue_work (priv->workqueue, + &priv->tx_policy_upload_work) <=0 ) { +cw1200_tx_queues_unlock (priv); +wsm_unlock_tx (priv); + } + } +return 0 ; +} + +static bool +cw1200_tx_h_pm_state (struct cw1200_common *priv, +struct cw1200_txinfo *t) +{ +int was_buffered =1 ; + +if (t->txpriv.link_id ==CW1200_LINK_ID_AFTER_DTIM && + !priv->buffered_multicasts) { + priv->buffered_multicasts = true; +if (priv->sta_asleep_mask) +queue_work (priv->workqueue, + &priv->multicast_start_work); + } + +if (t->txpriv.raw_link_id && t->txpriv.tid <CW1200_MAX_TID ) + was_buffered = priv->link_id_db[t->txpriv.raw_link_id -1 ] + .buffered[t->txpriv.tid]++; + +return !was_buffered; +} + +/* ******************************************************************** */ + +void cw1200_tx (struct ieee80211_hw *dev, +struct ieee80211_tx_control *control, +struct sk_buff *skb) +{ +struct cw1200_common *priv = dev->priv; +struct cw1200_txinfo t = { + .skb = skb, + .queue =skb_get_queue_mapping (skb), + .tx_info =IEEE80211_SKB_CB (skb), + .hdr = (struct ieee80211_hdr *)skb->data, + .txpriv.tid =CW1200_MAX_TID , + .txpriv.rate_id =CW1200_INVALID_RATE_ID , + }; +struct ieee80211_sta *sta; +struct wsm_tx *wsm; +bool tid_update =0 ; +u8 flags =0 ; +int ret; + +if (priv->bh_error) + goto drop; + + t.hdrlen =ieee80211_hdrlen (t.hdr->frame_control); + t.da =ieee80211_get_DA (t.hdr); +if (control) { + t.sta = control->sta; + t.sta_priv = (struct cw1200_sta_priv *)&t.sta->drv_priv; + } + +if (WARN_ON (t.queue >=4 )) + goto drop; + + ret =cw1200_tx_h_calc_link_ids (priv, &t); +if (ret) + goto drop; + +pr_debug ("[TX] TX %d bytes (queue: %d, link_id: %d (%d)).\n" , + skb->len, t.queue, t.txpriv.link_id, + t.txpriv.raw_link_id); + +cw1200_tx_h_pm (priv, &t); +cw1200_tx_h_calc_tid (priv, &t); + ret =cw1200_tx_h_crypt (priv, &t); +if (ret) + goto drop; + ret =cw1200_tx_h_align (priv, &t, &flags); +if (ret) + goto drop; + ret =cw1200_tx_h_action (priv, &t); +if (ret) + goto drop; + wsm =cw1200_tx_h_wsm (priv, &t); +if (!wsm) { + ret = -ENOMEM ; + goto drop; + } + wsm->flags |= flags; +cw1200_tx_h_bt (priv, &t, wsm); + ret =cw1200_tx_h_rate_policy (priv, &t, wsm); +if (ret) + goto drop; + +rcu_read_lock (); + sta =rcu_dereference (t.sta); + +spin_lock_bh (&priv->ps_state_lock); + { + tid_update =cw1200_tx_h_pm_state (priv, &t); +BUG_ON (cw1200_queue_put (&priv->tx_queue[t.queue], + t.skb, &t.txpriv)); + } +spin_unlock_bh (&priv->ps_state_lock); + +if (tid_update && sta) +ieee80211_sta_set_buffered (sta, + t.txpriv.tid, true); + +rcu_read_unlock (); + +cw1200_bh_wakeup (priv); + +return ; + +drop: +cw1200_skb_dtor (priv, skb, &t.txpriv); +return ; +} + +/* ******************************************************************** */ + +static int cw1200_handle_action_rx (struct cw1200_common *priv, +struct sk_buff *skb) +{ +struct ieee80211_mgmt *mgmt = (void *)skb->data; + +/* Filter block ACK negotiation: fully controlled by firmware */ +if (mgmt->u.action.category ==WLAN_CATEGORY_BACK ) +return 1 ; + +return 0 ; +} + +static int cw1200_handle_pspoll (struct cw1200_common *priv, +struct sk_buff *skb) +{ +struct ieee80211_sta *sta; +struct ieee80211_pspoll *pspoll = + (struct ieee80211_pspoll *) skb->data; +int link_id =0 ; +u32 pspoll_mask =0 ; +int drop =1 ; +int i; + +if (priv->join_status !=CW1200_JOIN_STATUS_AP ) + goto done; +if (memcmp (priv->vif->addr, pspoll->bssid,ETH_ALEN )) + goto done; + +rcu_read_lock (); + sta =ieee80211_find_sta (priv->vif, pspoll->ta); +if (sta) { +struct cw1200_sta_priv *sta_priv; + sta_priv = (struct cw1200_sta_priv *)&sta->drv_priv; + link_id = sta_priv->link_id; + pspoll_mask =BIT (sta_priv->link_id); + } +rcu_read_unlock (); +if (!link_id) + goto done; + + priv->pspoll_mask |= pspoll_mask; + drop =0 ; + +/* Do not report pspols if data for given link id is +* queued already. */ +for (i =0 ; i <4 ; ++i) { +if (cw1200_queue_get_num_queued ( + &priv->tx_queue[i], + pspoll_mask)) { +cw1200_bh_wakeup (priv); + drop =1 ; +break ; + } + } +pr_debug ("[RX] PSPOLL: %s\n" , drop ?"local" :"fwd" ); +done: +return drop; +} + +/* ******************************************************************** */ + +void cw1200_tx_confirm_cb (struct cw1200_common *priv, +struct wsm_tx_confirm *arg) +{ +u8 queue_id =cw1200_queue_get_queue_id (arg->packetID); +struct cw1200_queue *queue = &priv->tx_queue[queue_id]; +struct sk_buff *skb; +const struct cw1200_txpriv *txpriv; + +pr_debug ("[TX] TX confirm: %d, %d.\n" , + arg->status, arg->ackFailures); + +if (cw1200_itp_tx_running (priv)) +return ; + +if (priv->mode ==NL80211_IFTYPE_UNSPECIFIED ) { +/* STA is stopped. */ +return ; + } + +if (WARN_ON (queue_id >=4 )) +return ; + +if (arg->status) +pr_debug ("TX failed: %d.\n" , + arg->status); + +if ((arg->status ==WSM_REQUEUE ) && + (arg->flags &WSM_TX_STATUS_REQUEUE )) { +/* "Requeue" means "implicit suspend" */ +struct wsm_suspend_resume suspend = { + .link_id = arg->link_id, + .stop =1 , + .multicast = !arg->link_id, + }; +cw1200_suspend_resume (priv, &suspend); +wiphy_warn (priv->hw->wiphy,"Requeue for link_id %d (try %d). STAs asleep: 0x%.8X\n" , + arg->link_id, +cw1200_queue_get_generation (arg->packetID) +1 , + priv->sta_asleep_mask); +WARN_ON (cw1200_queue_requeue (queue, + arg->packetID)); +spin_lock_bh (&priv->ps_state_lock); +if (!arg->link_id) { + priv->buffered_multicasts = true; +if (priv->sta_asleep_mask) { +queue_work (priv->workqueue, + &priv->multicast_start_work); + } + } +spin_unlock_bh (&priv->ps_state_lock); + }else if (!WARN_ON (cw1200_queue_get_skb ( + queue, arg->packetID, &skb, &txpriv))) { +struct ieee80211_tx_info *tx =IEEE80211_SKB_CB (skb); +int tx_count = arg->ackFailures; +u8 ht_flags =0 ; +int i; + +if (cw1200_ht_greenfield (&priv->ht_info)) + ht_flags |=IEEE80211_TX_RC_GREEN_FIELD ; + +if (!arg->status) { +spin_lock (&priv->bss_loss_lock); +if ((priv->bss_loss_status ==CW1200_BSS_LOSS_CONFIRMING ) && + (priv->bss_loss_checking <BSS_LOSS_CHECKING_MAX_TRY )) { + priv->bss_loss_status =CW1200_BSS_LOSS_CHECKING ; + priv->bss_loss_checking++; +spin_unlock (&priv->bss_loss_lock); +cancel_delayed_work (&priv->bss_loss_work); +queue_delayed_work (priv->workqueue, + &priv->bss_loss_work,0 ); + }else +spin_unlock (&priv->bss_loss_lock); + tx->flags |=IEEE80211_TX_STAT_ACK ; + ++tx_count; +cw1200_debug_txed (priv); +if (arg->flags &WSM_TX_STATUS_AGGREGATION ) { +/* Do not report aggregation to mac80211: +* it confuses minstrel a lot. */ +/* tx->flags |= IEEE80211_TX_STAT_AMPDU; */ +cw1200_debug_txed_agg (priv); + } + }else { +spin_lock (&priv->bss_loss_lock); +if (priv->bss_loss_status == +CW1200_BSS_LOSS_CONFIRMING && + priv->bss_loss_confirm_id == + arg->packetID) { + priv->bss_loss_status = +CW1200_BSS_LOSS_CONFIRMED ; + priv->bss_loss_checking =0 ; +spin_unlock (&priv->bss_loss_lock); +cancel_delayed_work (&priv->bss_loss_work); +queue_delayed_work (priv->workqueue, + &priv->bss_loss_work,0 ); + }else +spin_unlock (&priv->bss_loss_lock); + +if (tx_count) + ++tx_count; + } + +for (i =0 ; i <IEEE80211_TX_MAX_RATES ; ++i) { +if (tx->status.rates[i].count >= tx_count) { + tx->status.rates[i].count = tx_count; +break ; + } + tx_count -= tx->status.rates[i].count; +if (tx->status.rates[i].flags &IEEE80211_TX_RC_MCS ) + tx->status.rates[i].flags |= ht_flags; + } + +for (++i; i <IEEE80211_TX_MAX_RATES ; ++i) { + tx->status.rates[i].count =0 ; + tx->status.rates[i].idx =-1 ; + } + +/* Pull off any crypto trailers that we added on */ +if (tx->control.hw_key) { +skb_trim (skb, skb->len - tx->control.hw_key->icv_len); +if (tx->control.hw_key->cipher ==WLAN_CIPHER_SUITE_TKIP ) +skb_trim (skb, skb->len -8 );/* MIC space */ + } +cw1200_queue_remove (queue, arg->packetID); + } +cw1200_bh_wakeup (priv);/* XXX TODO: Only wake if there are pending transmits.. */ +} + +static void cw1200_notify_buffered_tx (struct cw1200_common *priv, +struct sk_buff *skb,int link_id,int tid) +{ +struct ieee80211_sta *sta; +struct ieee80211_hdr *hdr; +u8 *buffered; +u8 still_buffered =0 ; + +if (link_id && tid <CW1200_MAX_TID ) { + buffered = priv->link_id_db + [link_id -1 ].buffered; + +spin_lock_bh (&priv->ps_state_lock); +if (!WARN_ON (!buffered[tid])) + still_buffered = --buffered[tid]; +spin_unlock_bh (&priv->ps_state_lock); + +if (!still_buffered && tid <CW1200_MAX_TID ) { + hdr = (struct ieee80211_hdr *) skb->data; +rcu_read_lock (); + sta =ieee80211_find_sta (priv->vif, hdr->addr1); +if (sta) +ieee80211_sta_set_buffered (sta, tid, false); +rcu_read_unlock (); + } + } +} + +void cw1200_skb_dtor (struct cw1200_common *priv, +struct sk_buff *skb, +const struct cw1200_txpriv *txpriv) +{ +skb_pull (skb, txpriv->offset); +if (txpriv->rate_id !=CW1200_INVALID_RATE_ID ) { +cw1200_notify_buffered_tx (priv, skb, + txpriv->raw_link_id, txpriv->tid); +tx_policy_put (priv, txpriv->rate_id); + } +if (!cw1200_is_itp (priv)) +ieee80211_tx_status (priv->hw, skb); +} + +void cw1200_rx_cb (struct cw1200_common *priv, +struct wsm_rx *arg, +struct sk_buff **skb_p) +{ +struct sk_buff *skb = *skb_p; +struct ieee80211_rx_status *hdr =IEEE80211_SKB_RXCB (skb); +struct ieee80211_hdr *frame = (struct ieee80211_hdr *)skb->data; +struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; +struct cw1200_link_entry *entry =NULL ; +unsigned long grace_period; + +bool early_data = false; +bool p2p = priv->vif && priv->vif->p2p; +size_t hdrlen; + hdr->flag =0 ; + +if (priv->mode ==NL80211_IFTYPE_UNSPECIFIED ) { +/* STA is stopped. */ + goto drop; + } + +if (arg->link_id && arg->link_id <=CW1200_MAX_STA_IN_AP_MODE ) { + entry = &priv->link_id_db[arg->link_id -1 ]; +if (entry->status ==CW1200_LINK_SOFT && +ieee80211_is_data (frame->frame_control)) + early_data = true; + entry->timestamp = jiffies; + }else if (p2p && +ieee80211_is_action (frame->frame_control) && + (mgmt->u.action.category ==WLAN_CATEGORY_PUBLIC )) { +pr_debug ("[RX] Going to MAP&RESET link ID\n" ); + +if (work_pending (&priv->linkid_reset_work)) +WARN_ON (1 ); + +memcpy (&priv->action_frame_sa[0 ], +ieee80211_get_SA (frame),ETH_ALEN ); + priv->action_linkid =0 ; +schedule_work (&priv->linkid_reset_work); + } + +if (arg->link_id && p2p && +ieee80211_is_action (frame->frame_control) && + (mgmt->u.action.category ==WLAN_CATEGORY_PUBLIC )) { +/* Link ID already exists for the ACTION frame. +* Reset and Remap */ +if (work_pending (&priv->linkid_reset_work)) +WARN_ON (1 ); +memcpy (&priv->action_frame_sa[0 ], +ieee80211_get_SA (frame),ETH_ALEN ); + priv->action_linkid = arg->link_id; +schedule_work (&priv->linkid_reset_work); + } +if (arg->status) { +if (arg->status ==WSM_STATUS_MICFAILURE ) { +pr_debug ("[RX] MIC failure.\n" ); + hdr->flag |=RX_FLAG_MMIC_ERROR ; + }else if (arg->status ==WSM_STATUS_NO_KEY_FOUND ) { +pr_debug ("[RX] No key found.\n" ); + goto drop; + }else { +pr_debug ("[RX] Receive failure: %d.\n" , + arg->status); + goto drop; + } + } + +if (skb->len <sizeof (struct ieee80211_pspoll )) { +wiphy_warn (priv->hw->wiphy,"Mailformed SDU rx'ed. Size is lesser than IEEE header.\n" ); + goto drop; + } + +if (ieee80211_is_pspoll (frame->frame_control)) +if (cw1200_handle_pspoll (priv, skb)) + goto drop; + + hdr->mactime =0 ;/* Not supported by WSM */ + hdr->band = ((arg->channelNumber &0xff00 ) || (arg->channelNumber >14 )) ? +IEEE80211_BAND_5GHZ :IEEE80211_BAND_2GHZ ; + hdr->freq =ieee80211_channel_to_frequency ( + arg->channelNumber, + hdr->band); + +if (arg->rxedRate >=14 ) { + hdr->flag |=RX_FLAG_HT ; + hdr->rate_idx = arg->rxedRate -14 ; + }else if (arg->rxedRate >=4 ) { + hdr->rate_idx = arg->rxedRate -2 ; + }else { + hdr->rate_idx = arg->rxedRate; + } + + hdr->signal = (s8 )arg->rcpiRssi; + hdr->antenna =0 ; + + hdrlen =ieee80211_hdrlen (frame->frame_control); + +if (WSM_RX_STATUS_ENCRYPTION (arg->flags)) { +size_t iv_len =0 , icv_len =0 ; + + hdr->flag |=RX_FLAG_DECRYPTED |RX_FLAG_IV_STRIPPED ; + +/* Oops... There is no fast way to ask mac80211 about +* IV/ICV lengths. Even defineas are not exposed.*/ +switch (WSM_RX_STATUS_ENCRYPTION (arg->flags)) { +case WSM_RX_STATUS_WEP : + iv_len =4 /* WEP_IV_LEN */ ; + icv_len =4 /* WEP_ICV_LEN */ ; +break ; +case WSM_RX_STATUS_TKIP : + iv_len =8 /* TKIP_IV_LEN */ ; + icv_len =4 /* TKIP_ICV_LEN */ + +8 /*MICHAEL_MIC_LEN*/ ; + hdr->flag |=RX_FLAG_MMIC_STRIPPED ; +break ; +case WSM_RX_STATUS_AES : + iv_len =8 /* CCMP_HDR_LEN */ ; + icv_len =8 /* CCMP_MIC_LEN */ ; +break ; +case WSM_RX_STATUS_WAPI : + iv_len =18 /* WAPI_HDR_LEN */ ; + icv_len =16 /* WAPI_MIC_LEN */ ; +break ; +default : +WARN_ON ("Unknown encryption type" ); + goto drop; + } + +/* Firmware strips ICV in case of MIC failure. */ +if (arg->status ==WSM_STATUS_MICFAILURE ) + icv_len =0 ; + +if (skb->len < hdrlen + iv_len + icv_len) { +wiphy_warn (priv->hw->wiphy,"Malformed SDU rx'ed. Size is lesser than crypto headers.\n" ); + goto drop; + } + +/* Remove IV, ICV and MIC */ +skb_trim (skb, skb->len - icv_len); +memmove (skb->data + iv_len, skb->data, hdrlen); +skb_pull (skb, iv_len); + } + +/* Remove TSF from the end of frame */ +if (arg->flags &WSM_RX_STATUS_TSF_INCLUDED ) { +memcpy (&hdr->mactime, skb->data + skb->len -8 ,8 ); + hdr->mactime =le64_to_cpu (hdr->mactime); +if (skb->len >=8 ) +skb_trim (skb, skb->len -8 ); + } + +cw1200_debug_rxed (priv); +if (arg->flags &WSM_RX_STATUS_AGGREGATE ) +cw1200_debug_rxed_agg (priv); + +if (ieee80211_is_action (frame->frame_control) && + (arg->flags &WSM_RX_STATUS_ADDRESS1 )) { +if (cw1200_handle_action_rx (priv, skb)) +return ; + }else if (ieee80211_is_beacon (frame->frame_control) && + !arg->status && + !memcmp (ieee80211_get_SA (frame), priv->join_bssid, +ETH_ALEN )) { +const u8 *tim_ie; +u8 *ies = ((struct ieee80211_mgmt *) + (skb->data))->u.beacon.variable; +size_t ies_len = skb->len - (ies - (u8 *)(skb->data)); + + tim_ie =cfg80211_find_ie (WLAN_EID_TIM , ies, ies_len); +if (tim_ie) { +struct ieee80211_tim_ie *tim = + (struct ieee80211_tim_ie *)&tim_ie[2 ]; + +if (priv->join_dtim_period != tim->dtim_period) { + priv->join_dtim_period = tim->dtim_period; +queue_work (priv->workqueue, + &priv->set_beacon_wakeup_period_work); + } + } +if (priv->disable_beacon_filter) { + priv->disable_beacon_filter = false; +queue_work (priv->workqueue, + &priv->update_filtering_work); + } + } + +/* Stay awake for 1sec. after frame is received to give +* userspace chance to react and acquire appropriate +* wakelock. */ +if (ieee80211_is_auth (frame->frame_control)) + grace_period =5 *HZ ; +else if (ieee80211_is_deauth (frame->frame_control)) + grace_period =5 *HZ ; +else + grace_period =1 *HZ ; +cw1200_pm_stay_awake (&priv->pm_state, grace_period); + +if (cw1200_itp_rxed (priv, skb)) +consume_skb (skb); +else if (early_data) { +spin_lock_bh (&priv->ps_state_lock); +/* Double-check status with lock held */ +if (entry->status ==CW1200_LINK_SOFT ) +skb_queue_tail (&entry->rx_queue, skb); +else +ieee80211_rx_irqsafe (priv->hw, skb); +spin_unlock_bh (&priv->ps_state_lock); + }else { +ieee80211_rx_irqsafe (priv->hw, skb); + } + *skb_p =NULL ; + +return ; + +drop: +/* TODO: update failure counters */ +return ; +} + +/* ******************************************************************** */ +/* Security */ + +int cw1200_alloc_key (struct cw1200_common *priv) +{ +int idx; + + idx =ffs (~priv->key_map) -1 ; +if (idx <0 || idx >WSM_KEY_MAX_INDEX ) +return -1 ; + + priv->key_map |=BIT (idx); + priv->keys[idx].entryIndex = idx; +return idx; +} + +void cw1200_free_key (struct cw1200_common *priv,int idx) +{ +BUG_ON (!(priv->key_map &BIT (idx))); +memset (&priv->keys[idx],0 ,sizeof (priv->keys[idx])); + priv->key_map &= ~BIT (idx); +} + +void cw1200_free_keys (struct cw1200_common *priv) +{ +memset (&priv->keys,0 ,sizeof (priv->keys)); + priv->key_map =0 ; +} + +int cw1200_upload_keys (struct cw1200_common *priv) +{ +int idx, ret =0 ; +for (idx =0 ; idx <=WSM_KEY_MAX_INDEX ; ++idx) +if (priv->key_map &BIT (idx)) { + ret =wsm_add_key (priv, &priv->keys[idx]); +if (ret <0 ) +break ; + } +return ret; +} + +/* Workaround for WFD test case 6.1.10 */ +void cw1200_link_id_reset (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, linkid_reset_work); +int temp_linkid; + +if (!priv->action_linkid) { +/* In GO mode we can receive ACTION frames without a linkID */ + temp_linkid =cw1200_alloc_link_id (priv, + &priv->action_frame_sa[0 ]); +WARN_ON (!temp_linkid); +if (temp_linkid) { +/* Make sure we execute the WQ */ +flush_workqueue (priv->workqueue); +/* Release the link ID */ +spin_lock_bh (&priv->ps_state_lock); + priv->link_id_db[temp_linkid -1 ].prev_status = + priv->link_id_db[temp_linkid -1 ].status; + priv->link_id_db[temp_linkid -1 ].status = +CW1200_LINK_RESET ; +spin_unlock_bh (&priv->ps_state_lock); +wsm_lock_tx_async (priv); +if (queue_work (priv->workqueue, + &priv->link_id_work) <=0 ) +wsm_unlock_tx (priv); + } + }else { +spin_lock_bh (&priv->ps_state_lock); + priv->link_id_db[priv->action_linkid -1 ].prev_status = + priv->link_id_db[priv->action_linkid -1 ].status; + priv->link_id_db[priv->action_linkid -1 ].status = +CW1200_LINK_RESET_REMAP ; +spin_unlock_bh (&priv->ps_state_lock); +wsm_lock_tx_async (priv); +if (queue_work (priv->workqueue, &priv->link_id_work) <=0 ) +wsm_unlock_tx (priv); +flush_workqueue (priv->workqueue); + } +} + +int cw1200_find_link_id (struct cw1200_common *priv,const u8 *mac) +{ +int i, ret =0 ; +spin_lock_bh (&priv->ps_state_lock); +for (i =0 ; i <CW1200_MAX_STA_IN_AP_MODE ; ++i) { +if (!memcmp (mac, priv->link_id_db[i].mac,ETH_ALEN ) && + priv->link_id_db[i].status) { + priv->link_id_db[i].timestamp = jiffies; + ret = i +1 ; +break ; + } + } +spin_unlock_bh (&priv->ps_state_lock); +return ret; +} + +int cw1200_alloc_link_id (struct cw1200_common *priv,const u8 *mac) +{ +int i, ret =0 ; +unsigned long max_inactivity =0 ; +unsigned long now = jiffies; + +spin_lock_bh (&priv->ps_state_lock); +for (i =0 ; i <CW1200_MAX_STA_IN_AP_MODE ; ++i) { +if (!priv->link_id_db[i].status) { + ret = i +1 ; +break ; + }else if (priv->link_id_db[i].status !=CW1200_LINK_HARD && + !priv->tx_queue_stats.link_map_cache[i +1 ]) { + +unsigned long inactivity = + now - priv->link_id_db[i].timestamp; +if (inactivity < max_inactivity) +continue ; + max_inactivity = inactivity; + ret = i +1 ; + } + } +if (ret) { +struct cw1200_link_entry *entry = &priv->link_id_db[ret -1 ]; +pr_debug ("[AP] STA added, link_id: %d\n" , + ret); + entry->status =CW1200_LINK_RESERVE ; +memcpy (&entry->mac, mac,ETH_ALEN ); +memset (&entry->buffered,0 ,CW1200_MAX_TID ); +skb_queue_head_init (&entry->rx_queue); +wsm_lock_tx_async (priv); +if (queue_work (priv->workqueue, &priv->link_id_work) <=0 ) +wsm_unlock_tx (priv); + }else { +wiphy_info (priv->hw->wiphy, +"[AP] Early: no more link IDs available.\n" ); + } + +spin_unlock_bh (&priv->ps_state_lock); +return ret; +} + +void cw1200_link_id_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, link_id_work); +wsm_flush_tx (priv); +cw1200_link_id_gc_work (&priv->link_id_gc_work.work); +wsm_unlock_tx (priv); +} + +void cw1200_link_id_gc_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, link_id_gc_work.work); +struct wsm_reset reset = { + .reset_statistics = false, + }; +struct wsm_map_link map_link = { + .link_id =0 , + }; +unsigned long now = jiffies; +unsigned long next_gc =-1 ; +long ttl; +bool need_reset; +u32 mask; +int i; + +if (priv->join_status !=CW1200_JOIN_STATUS_AP ) +return ; + +wsm_lock_tx (priv); +spin_lock_bh (&priv->ps_state_lock); +for (i =0 ; i <CW1200_MAX_STA_IN_AP_MODE ; ++i) { + need_reset = false; + mask =BIT (i +1 ); +if (priv->link_id_db[i].status ==CW1200_LINK_RESERVE || + (priv->link_id_db[i].status ==CW1200_LINK_HARD && + !(priv->link_id_map & mask))) { +if (priv->link_id_map & mask) { + priv->sta_asleep_mask &= ~mask; + priv->pspoll_mask &= ~mask; + need_reset = true; + } + priv->link_id_map |= mask; +if (priv->link_id_db[i].status !=CW1200_LINK_HARD ) + priv->link_id_db[i].status =CW1200_LINK_SOFT ; +memcpy (map_link.mac_addr, priv->link_id_db[i].mac, +ETH_ALEN ); +spin_unlock_bh (&priv->ps_state_lock); +if (need_reset) { + reset.link_id = i +1 ; +WARN_ON (wsm_reset (priv, &reset)); + } + map_link.link_id = i +1 ; +WARN_ON (wsm_map_link (priv, &map_link)); + next_gc =min (next_gc,CW1200_LINK_ID_GC_TIMEOUT ); +spin_lock_bh (&priv->ps_state_lock); + }else if (priv->link_id_db[i].status ==CW1200_LINK_SOFT ) { + ttl = priv->link_id_db[i].timestamp - now + +CW1200_LINK_ID_GC_TIMEOUT ; +if (ttl <=0 ) { + need_reset = true; + priv->link_id_db[i].status =CW1200_LINK_OFF ; + priv->link_id_map &= ~mask; + priv->sta_asleep_mask &= ~mask; + priv->pspoll_mask &= ~mask; +memset (map_link.mac_addr,0 ,ETH_ALEN ); +spin_unlock_bh (&priv->ps_state_lock); + reset.link_id = i +1 ; +WARN_ON (wsm_reset (priv, &reset)); +spin_lock_bh (&priv->ps_state_lock); + }else { + next_gc = min_t(unsigned long, next_gc, ttl); + } + }else if (priv->link_id_db[i].status ==CW1200_LINK_RESET || + priv->link_id_db[i].status == +CW1200_LINK_RESET_REMAP ) { +int status = priv->link_id_db[i].status; + priv->link_id_db[i].status = + priv->link_id_db[i].prev_status; + priv->link_id_db[i].timestamp = now; + reset.link_id = i +1 ; +spin_unlock_bh (&priv->ps_state_lock); +WARN_ON (wsm_reset (priv, &reset)); +if (status ==CW1200_LINK_RESET_REMAP ) { +memcpy (map_link.mac_addr, + priv->link_id_db[i].mac, +ETH_ALEN ); + map_link.link_id = i +1 ; +WARN_ON (wsm_map_link (priv, &map_link)); + next_gc =min (next_gc, +CW1200_LINK_ID_GC_TIMEOUT ); + } +spin_lock_bh (&priv->ps_state_lock); + } +if (need_reset) { +skb_queue_purge (&priv->link_id_db[i].rx_queue); +pr_debug ("[AP] STA removed, link_id: %d\n" , + reset.link_id); + } + } +spin_unlock_bh (&priv->ps_state_lock); +if (next_gc !=-1 ) +queue_delayed_work (priv->workqueue, + &priv->link_id_gc_work, next_gc); +wsm_unlock_tx (priv); +} +
drivers/net/wireless/cw1200/txrx.h new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 9/14 cw1200: v4: WSM (host-firmware) interface
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/wsm.c | 1938 +++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/wsm.h | 1862 +++++++++++++++++++++++++++++++++++ 2 files changed, 3800 insertions(+) create mode 100644 drivers/net/wireless/cw1200/wsm.c create mode 100644 drivers/net/wireless/cw1200/wsm.h
drivers/net/wireless/cw1200/wsm.c new file +1938 -0
@@ -0,0 +1,1938 @@ +/* +* WSM host interface (HI) implementation for +* ST-Ericsson CW1200 mac80211 drivers. +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/skbuff.h> +#include <linux/wait.h> +#include <linux/skbuff.h> +#include <linux/delay.h> +#include <linux/sched.h> +#include <linux/random.h> + +#include "cw1200.h" +#include "wsm.h" +#include "bh.h" +#include "sta.h" +#include "debug.h" +#include "itp.h" + +#define WSM_CMD_TIMEOUT (2 * HZ)/* With respect to interrupt loss */ +#define WSM_CMD_START_TIMEOUT (7 * HZ) +#define WSM_CMD_RESET_TIMEOUT (3 * HZ)/* 2 sec. timeout was observed. */ +#define WSM_CMD_MAX_TIMEOUT (3 * HZ) + +#define WSM_SKIP (buf, size) \ + do { \ + if ((buf)->data + size > (buf)->end) \ + goto underflow; \ + (buf)->data += size; \ + } while (0) + +#define WSM_GET (buf, ptr, size) \ + do { \ + if ((buf)->data + size > (buf)->end) \ + goto underflow; \ + memcpy(ptr, (buf)->data, size); \ + (buf)->data += size; \ + } while (0) + +#define __WSM_GET (buf, type, cvt) \ + ({ \ + type val; \ + if ((buf)->data + sizeof(type) > (buf)->end) \ + goto underflow; \ + val = cvt(*(type *)(buf)->data); \ + (buf)->data += sizeof(type); \ + val; \ + }) + +#define WSM_GET8 (buf) __WSM_GET(buf, u8, (u8)) +#define WSM_GET16 (buf) __WSM_GET(buf, u16, __le16_to_cpu) +#define WSM_GET32 (buf) __WSM_GET(buf, u32, __le32_to_cpu) + +#define WSM_PUT (buf, ptr, size) \ + do { \ + if ((buf)->data + size > (buf)->end) \ + if (wsm_buf_reserve((buf), size)) \ + goto nomem; \ + memcpy((buf)->data, ptr, size); \ + (buf)->data += size; \ + } while (0) + +#define __WSM_PUT (buf, val, type, cvt) \ + do { \ + if ((buf)->data + sizeof(type) > (buf)->end) \ + if (wsm_buf_reserve((buf), sizeof(type))) \ + goto nomem; \ + *(type *)(buf)->data = cvt(val); \ + (buf)->data += sizeof(type); \ + } while (0) + +#define WSM_PUT8 (buf, val) __WSM_PUT(buf, val, u8, (u8)) +#define WSM_PUT16 (buf, val) __WSM_PUT(buf, val, u16, __cpu_to_le16) +#define WSM_PUT32 (buf, val) __WSM_PUT(buf, val, u32, __cpu_to_le32) + +static void wsm_buf_reset (struct wsm_buf *buf); +static int wsm_buf_reserve (struct wsm_buf *buf,size_t extra_size); + +static int wsm_cmd_send (struct cw1200_common *priv, +struct wsm_buf *buf, +void *arg,u16 cmd,long tmo); + +static inline void wsm_cmd_lock (struct cw1200_common *priv) +{ +mutex_lock (&priv->wsm_cmd_mux); +} + +static inline void wsm_cmd_unlock (struct cw1200_common *priv) +{ +mutex_unlock (&priv->wsm_cmd_mux); +} + +/* ******************************************************************** */ +/* WSM API implementation */ + +static int wsm_generic_confirm (struct cw1200_common *priv, +void *arg, +struct wsm_buf *buf) +{ +u32 status =WSM_GET32 (buf); +if (status !=WSM_STATUS_SUCCESS ) +return -EINVAL ; +return 0 ; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +int wsm_configuration (struct cw1200_common *priv,struct wsm_configuration *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +WSM_PUT32 (buf, arg->dot11MaxTransmitMsduLifeTime); +WSM_PUT32 (buf, arg->dot11MaxReceiveLifeTime); +WSM_PUT32 (buf, arg->dot11RtsThreshold); + +/* DPD block. */ +WSM_PUT16 (buf, arg->dpdData_size +12 ); +WSM_PUT16 (buf,1 );/* DPD version */ +WSM_PUT (buf, arg->dot11StationId,ETH_ALEN ); +WSM_PUT16 (buf,5 );/* DPD flags */ +WSM_PUT (buf, arg->dpdData, arg->dpdData_size); + + ret =wsm_cmd_send (priv, buf, arg,0x0009 ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +static int wsm_configuration_confirm (struct cw1200_common *priv, +struct wsm_configuration *arg, +struct wsm_buf *buf) +{ +int i; +int status; + + status =WSM_GET32 (buf); +if (WARN_ON (status !=WSM_STATUS_SUCCESS )) +return -EINVAL ; + +WSM_GET (buf, arg->dot11StationId,ETH_ALEN ); + arg->dot11FrequencyBandsSupported =WSM_GET8 (buf); +WSM_SKIP (buf,1 ); + arg->supportedRateMask =WSM_GET32 (buf); +for (i =0 ; i <2 ; ++i) { + arg->txPowerRange[i].min_power_level =WSM_GET32 (buf); + arg->txPowerRange[i].max_power_level =WSM_GET32 (buf); + arg->txPowerRange[i].stepping =WSM_GET32 (buf); + } +return 0 ; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +/* ******************************************************************** */ + +int wsm_reset (struct cw1200_common *priv,const struct wsm_reset *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; +u16 cmd =0x000A |WSM_TX_LINK_ID (arg->link_id); + +wsm_cmd_lock (priv); + +WSM_PUT32 (buf, arg->reset_statistics ?0 :1 ); + ret =wsm_cmd_send (priv, buf,NULL , cmd,WSM_CMD_RESET_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +struct wsm_mib { +u16 mibId; +void *buf; +size_t buf_size; +}; + +int wsm_read_mib (struct cw1200_common *priv,u16 mibId,void *_buf, +size_t buf_size) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; +struct wsm_mib mib_buf = { + .mibId = mibId, + .buf = _buf, + .buf_size = buf_size, + }; +wsm_cmd_lock (priv); + +WSM_PUT16 (buf, mibId); +WSM_PUT16 (buf,0 ); + + ret =wsm_cmd_send (priv, buf, &mib_buf,0x0005 ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +static int wsm_read_mib_confirm (struct cw1200_common *priv, +struct wsm_mib *arg, +struct wsm_buf *buf) +{ +u16 size; +if (WARN_ON (WSM_GET32 (buf) !=WSM_STATUS_SUCCESS )) +return -EINVAL ; + +if (WARN_ON (WSM_GET16 (buf) != arg->mibId)) +return -EINVAL ; + + size =WSM_GET16 (buf); +if (size > arg->buf_size) + size = arg->buf_size; + +WSM_GET (buf, arg->buf, size); + arg->buf_size = size; +return 0 ; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +/* ******************************************************************** */ + +int wsm_write_mib (struct cw1200_common *priv,u16 mibId,void *_buf, +size_t buf_size) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; +struct wsm_mib mib_buf = { + .mibId = mibId, + .buf = _buf, + .buf_size = buf_size, + }; + +wsm_cmd_lock (priv); + +WSM_PUT16 (buf, mibId); +WSM_PUT16 (buf, buf_size); +WSM_PUT (buf, _buf, buf_size); + + ret =wsm_cmd_send (priv, buf, &mib_buf,0x0006 ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +static int wsm_write_mib_confirm (struct cw1200_common *priv, +struct wsm_mib *arg, +struct wsm_buf *buf) +{ +int ret; + + ret =wsm_generic_confirm (priv, arg, buf); +if (ret) +return ret; + +if (arg->mibId ==0x1006 ) { +/* OperationalMode: update PM status. */ +const char *p = arg->buf; +cw1200_enable_powersave (priv, + (p[0 ] &0x0F ) ? true : false); + } +return 0 ; +} + +/* ******************************************************************** */ + +int wsm_scan (struct cw1200_common *priv,const struct wsm_scan *arg) +{ +int i; +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +if (arg->numOfChannels >48 ) +return -EINVAL ; + +if (arg->numOfSSIDs >2 ) +return -EINVAL ; + +if (arg->band >1 ) +return -EINVAL ; + +wsm_cmd_lock (priv); + +WSM_PUT8 (buf, arg->band); +WSM_PUT8 (buf, arg->scanType); +WSM_PUT8 (buf, arg->scanFlags); +WSM_PUT8 (buf, arg->maxTransmitRate); +WSM_PUT32 (buf, arg->autoScanInterval); +WSM_PUT8 (buf, arg->numOfProbeRequests); +WSM_PUT8 (buf, arg->numOfChannels); +WSM_PUT8 (buf, arg->numOfSSIDs); +WSM_PUT8 (buf, arg->probeDelay); + +for (i =0 ; i < arg->numOfChannels; ++i) { +WSM_PUT16 (buf, arg->ch[i].number); +WSM_PUT16 (buf,0 ); +WSM_PUT32 (buf, arg->ch[i].minChannelTime); +WSM_PUT32 (buf, arg->ch[i].maxChannelTime); +WSM_PUT32 (buf,0 ); + } + +for (i =0 ; i < arg->numOfSSIDs; ++i) { +WSM_PUT32 (buf, arg->ssids[i].length); +WSM_PUT (buf, &arg->ssids[i].ssid[0 ], +sizeof (arg->ssids[i].ssid)); + } + + ret =wsm_cmd_send (priv, buf,NULL ,0x0007 ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_stop_scan (struct cw1200_common *priv) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; +wsm_cmd_lock (priv); + ret =wsm_cmd_send (priv, buf,NULL ,0x0008 ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; +} + + +static int wsm_tx_confirm (struct cw1200_common *priv, +struct wsm_buf *buf, +int link_id) +{ +struct wsm_tx_confirm tx_confirm; + + tx_confirm.packetID =WSM_GET32 (buf); + tx_confirm.status =WSM_GET32 (buf); + tx_confirm.txedRate =WSM_GET8 (buf); + tx_confirm.ackFailures =WSM_GET8 (buf); + tx_confirm.flags =WSM_GET16 (buf); + tx_confirm.mediaDelay =WSM_GET32 (buf); + tx_confirm.txQueueDelay =WSM_GET32 (buf); + tx_confirm.link_id = link_id; + +if (priv->wsm_cbc.tx_confirm) + priv->wsm_cbc.tx_confirm (priv, &tx_confirm); +return 0 ; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +static int wsm_multi_tx_confirm (struct cw1200_common *priv, +struct wsm_buf *buf,int link_id) +{ +int ret; +int count; +int i; + + count =WSM_GET32 (buf); +if (WARN_ON (count <=0 )) +return -EINVAL ; +else if (count >1 ) { + ret =wsm_release_tx_buffer (priv, count -1 ); +if (ret <0 ) +return ret; +else if (ret >0 ) +cw1200_bh_wakeup (priv); + } + +cw1200_debug_txed_multi (priv, count); +for (i =0 ; i < count; ++i) { + ret =wsm_tx_confirm (priv, buf, link_id); +if (ret) +return ret; + } +return ret; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +/* ******************************************************************** */ + +static int wsm_join_confirm (struct cw1200_common *priv, +struct wsm_join *arg, +struct wsm_buf *buf) +{ +if (WARN_ON (WSM_GET32 (buf) !=WSM_STATUS_SUCCESS )) +return -EINVAL ; + + arg->minPowerLevel =WSM_GET32 (buf); + arg->maxPowerLevel =WSM_GET32 (buf); + +return 0 ; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +int wsm_join (struct cw1200_common *priv,struct wsm_join *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; +wsm_cmd_lock (priv); + +WSM_PUT8 (buf, arg->mode); +WSM_PUT8 (buf, arg->band); +WSM_PUT16 (buf, arg->channelNumber); +WSM_PUT (buf, &arg->bssid[0 ],sizeof (arg->bssid)); +WSM_PUT16 (buf, arg->atimWindow); +WSM_PUT8 (buf, arg->preambleType); +WSM_PUT8 (buf, arg->probeForJoin); +WSM_PUT8 (buf, arg->dtimPeriod); +WSM_PUT8 (buf, arg->flags); +WSM_PUT32 (buf, arg->ssidLength); +WSM_PUT (buf, &arg->ssid[0 ],sizeof (arg->ssid)); +WSM_PUT32 (buf, arg->beaconInterval); +WSM_PUT32 (buf, arg->basicRateSet); + + priv->tx_burst_idx =-1 ; + ret =wsm_cmd_send (priv, buf, arg,0x000B ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_set_bss_params (struct cw1200_common *priv, +const struct wsm_set_bss_params *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +WSM_PUT8 (buf,0 ); +WSM_PUT8 (buf, arg->beaconLostCount); +WSM_PUT16 (buf, arg->aid); +WSM_PUT32 (buf, arg->operationalRateSet); + + ret =wsm_cmd_send (priv, buf,NULL ,0x0011 ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_add_key (struct cw1200_common *priv,const struct wsm_add_key *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +WSM_PUT (buf, arg,sizeof (*arg)); + + ret =wsm_cmd_send (priv, buf,NULL ,0x000C ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_remove_key (struct cw1200_common *priv,const struct wsm_remove_key *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +WSM_PUT8 (buf, arg->entryIndex); +WSM_PUT8 (buf,0 ); +WSM_PUT16 (buf,0 ); + + ret =wsm_cmd_send (priv, buf,NULL ,0x000D ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_set_tx_queue_params (struct cw1200_common *priv, +const struct wsm_set_tx_queue_params *arg,u8 id) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; +u8 queue_id_to_wmm_aci[] = {3 ,2 ,0 ,1 }; + +wsm_cmd_lock (priv); + +WSM_PUT8 (buf, queue_id_to_wmm_aci[id]); +WSM_PUT8 (buf,0 ); +WSM_PUT8 (buf, arg->ackPolicy); +WSM_PUT8 (buf,0 ); +WSM_PUT32 (buf, arg->maxTransmitLifetime); +WSM_PUT16 (buf, arg->allowedMediumTime); +WSM_PUT16 (buf,0 ); + + ret =wsm_cmd_send (priv, buf,NULL ,0x0012 ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_set_edca_params (struct cw1200_common *priv, +const struct wsm_edca_params *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +/* Implemented according to specification. */ + +WSM_PUT16 (buf, arg->params[3 ].cwMin); +WSM_PUT16 (buf, arg->params[2 ].cwMin); +WSM_PUT16 (buf, arg->params[1 ].cwMin); +WSM_PUT16 (buf, arg->params[0 ].cwMin); + +WSM_PUT16 (buf, arg->params[3 ].cwMax); +WSM_PUT16 (buf, arg->params[2 ].cwMax); +WSM_PUT16 (buf, arg->params[1 ].cwMax); +WSM_PUT16 (buf, arg->params[0 ].cwMax); + +WSM_PUT8 (buf, arg->params[3 ].aifns); +WSM_PUT8 (buf, arg->params[2 ].aifns); +WSM_PUT8 (buf, arg->params[1 ].aifns); +WSM_PUT8 (buf, arg->params[0 ].aifns); + +WSM_PUT16 (buf, arg->params[3 ].txOpLimit); +WSM_PUT16 (buf, arg->params[2 ].txOpLimit); +WSM_PUT16 (buf, arg->params[1 ].txOpLimit); +WSM_PUT16 (buf, arg->params[0 ].txOpLimit); + +WSM_PUT32 (buf, arg->params[3 ].maxReceiveLifetime); +WSM_PUT32 (buf, arg->params[2 ].maxReceiveLifetime); +WSM_PUT32 (buf, arg->params[1 ].maxReceiveLifetime); +WSM_PUT32 (buf, arg->params[0 ].maxReceiveLifetime); + + ret =wsm_cmd_send (priv, buf,NULL ,0x0013 ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_switch_channel (struct cw1200_common *priv, +const struct wsm_switch_channel *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_lock_tx (priv); +wsm_cmd_lock (priv); + +WSM_PUT8 (buf, arg->channelMode); +WSM_PUT8 (buf, arg->channelSwitchCount); +WSM_PUT16 (buf, arg->newChannelNumber); + + priv->channel_switch_in_progress =1 ; + + ret =wsm_cmd_send (priv, buf,NULL ,0x0016 ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +if (ret) { +wsm_unlock_tx (priv); + priv->channel_switch_in_progress =0 ; + } +return ret; + +nomem: +wsm_cmd_unlock (priv); +wsm_unlock_tx (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_set_pm (struct cw1200_common *priv,const struct wsm_set_pm *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + priv->ps_mode_switch_in_progress =1 ; + +wsm_cmd_lock (priv); + +WSM_PUT8 (buf, arg->pmMode); +WSM_PUT8 (buf, arg->fastPsmIdlePeriod); +WSM_PUT8 (buf, arg->apPsmChangePeriod); +WSM_PUT8 (buf, arg->minAutoPsPollPeriod); + + ret =wsm_cmd_send (priv, buf,NULL ,0x0010 ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_start (struct cw1200_common *priv,const struct wsm_start *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +WSM_PUT8 (buf, arg->mode); +WSM_PUT8 (buf, arg->band); +WSM_PUT16 (buf, arg->channelNumber); +WSM_PUT32 (buf, arg->CTWindow); +WSM_PUT32 (buf, arg->beaconInterval); +WSM_PUT8 (buf, arg->DTIMPeriod); +WSM_PUT8 (buf, arg->preambleType); +WSM_PUT8 (buf, arg->probeDelay); +WSM_PUT8 (buf, arg->ssidLength); +WSM_PUT (buf, arg->ssid,sizeof (arg->ssid)); +WSM_PUT32 (buf, arg->basicRateSet); + + priv->tx_burst_idx =-1 ; + ret =wsm_cmd_send (priv, buf,NULL ,0x0017 ,WSM_CMD_START_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_beacon_transmit (struct cw1200_common *priv, +const struct wsm_beacon_transmit *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +WSM_PUT32 (buf, arg->enableBeaconing ?1 :0 ); + + ret =wsm_cmd_send (priv, buf,NULL ,0x0018 ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_start_find (struct cw1200_common *priv) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + ret =wsm_cmd_send (priv, buf,NULL ,0x0019 ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; +} + +/* ******************************************************************** */ + +int wsm_stop_find (struct cw1200_common *priv) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + ret =wsm_cmd_send (priv, buf,NULL ,0x001A ,WSM_CMD_TIMEOUT ); +wsm_cmd_unlock (priv); +return ret; +} + +/* ******************************************************************** */ + +int wsm_map_link (struct cw1200_common *priv,const struct wsm_map_link *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; +u16 cmd =0x001C |WSM_TX_LINK_ID (arg->link_id); + +wsm_cmd_lock (priv); + +WSM_PUT (buf, &arg->mac_addr[0 ],sizeof (arg->mac_addr)); +WSM_PUT16 (buf,0 ); + + ret =wsm_cmd_send (priv, buf,NULL , cmd,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} + +/* ******************************************************************** */ + +int wsm_update_ie (struct cw1200_common *priv, +const struct wsm_update_ie *arg) +{ +int ret; +struct wsm_buf *buf = &priv->wsm_cmd_buf; + +wsm_cmd_lock (priv); + +WSM_PUT16 (buf, arg->what); +WSM_PUT16 (buf, arg->count); +WSM_PUT (buf, arg->ies, arg->length); + + ret =wsm_cmd_send (priv, buf,NULL ,0x001B ,WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; + +} + +/* ******************************************************************** */ +int wsm_set_probe_responder (struct cw1200_common *priv,bool enable) +{ + priv->rx_filter.probeResponder = enable; +return wsm_set_rx_filter (priv, &priv->rx_filter); +} + +/* ******************************************************************** */ +/* WSM indication events implementation */ + +static int wsm_startup_indication (struct cw1200_common *priv, +struct wsm_buf *buf) +{ +u16 status; +char fw_label[129 ]; +static const char *const fw_types[] = { +"ETF" , +"WFM" , +"WSM" , +"HI test" , +"Platform test" + }; + + priv->wsm_caps.numInpChBufs =WSM_GET16 (buf); + priv->wsm_caps.sizeInpChBuf =WSM_GET16 (buf); + priv->wsm_caps.hardwareId =WSM_GET16 (buf); + priv->wsm_caps.hardwareSubId =WSM_GET16 (buf); + status =WSM_GET16 (buf); + priv->wsm_caps.firmwareCap =WSM_GET16 (buf); + priv->wsm_caps.firmwareType =WSM_GET16 (buf); + priv->wsm_caps.firmwareApiVer =WSM_GET16 (buf); + priv->wsm_caps.firmwareBuildNumber =WSM_GET16 (buf); + priv->wsm_caps.firmwareVersion =WSM_GET16 (buf); +WSM_GET (buf, &fw_label[0 ],sizeof (fw_label) -1 ); + fw_label[sizeof (fw_label) -1 ] =0 ;/* Do not trust FW too much. */ + +if (WARN_ON (status)) +return -EINVAL ; + +if (WARN_ON (priv->wsm_caps.firmwareType >4 )) +return -EINVAL ; + +pr_info ("CW1200 WSM init done.\n" +" Input buffers: %d x %d bytes\n" +" Hardware: %d.%d\n" +" %s firmware [%s], ver: %d, build: %d," +" api: %d, cap: 0x%.4X\n" , + priv->wsm_caps.numInpChBufs, priv->wsm_caps.sizeInpChBuf, + priv->wsm_caps.hardwareId, priv->wsm_caps.hardwareSubId, + fw_types[priv->wsm_caps.firmwareType], + &fw_label[0 ], priv->wsm_caps.firmwareVersion, + priv->wsm_caps.firmwareBuildNumber, + priv->wsm_caps.firmwareApiVer, priv->wsm_caps.firmwareCap); + + priv->wsm_caps.firmwareReady =1 ; + +/* Disable unsupported frequency bands */ +if (!(priv->wsm_caps.firmwareCap &0x1 )) + priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ ] =NULL ; +if (!(priv->wsm_caps.firmwareCap &0x2 )) + priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ ] =NULL ; + +wake_up (&priv->wsm_startup_done); +return 0 ; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +static int wsm_receive_indication (struct cw1200_common *priv, +int link_id, +struct wsm_buf *buf, +struct sk_buff **skb_p) +{ + priv->rx_timestamp = jiffies; +if (priv->wsm_cbc.rx) { +struct wsm_rx rx; +struct ieee80211_hdr *hdr; +size_t hdr_len; +__le16 fctl; + + rx.status =WSM_GET32 (buf); + rx.channelNumber =WSM_GET16 (buf); + rx.rxedRate =WSM_GET8 (buf); + rx.rcpiRssi =WSM_GET8 (buf); + rx.flags =WSM_GET32 (buf); + +/* FW Workaround: Drop probe resp or +beacon when RSSI is 0 */ + hdr = (struct ieee80211_hdr *) (*skb_p)->data; + +if (!rx.rcpiRssi && + (ieee80211_is_probe_resp (hdr->frame_control) || +ieee80211_is_beacon (hdr->frame_control))) +return 0 ; + +/* If no RSSI subscription has been made, +* convert RCPI to RSSI here */ +if (!priv->cqm_use_rssi) + rx.rcpiRssi = rx.rcpiRssi /2 -110 ; + + rx.link_id = link_id; + fctl = *(__le16 *)buf->data; + hdr_len = buf->data - buf->begin; +skb_pull (*skb_p, hdr_len); +if (!rx.status &&ieee80211_is_deauth (fctl)) { +if (priv->join_status ==CW1200_JOIN_STATUS_STA ) { +/* Shedule unjoin work */ +pr_debug ("[WSM] Issue unjoin command (RX).\n" ); +wsm_lock_tx_async (priv); +if (queue_work (priv->workqueue, + &priv->unjoin_work) <=0 ) +wsm_unlock_tx (priv); + } + } + priv->wsm_cbc.rx (priv, &rx, skb_p); +if (*skb_p) +skb_push (*skb_p, hdr_len); + } +return 0 ; + +underflow: +return -EINVAL ; +} + +static int wsm_event_indication (struct cw1200_common *priv,struct wsm_buf *buf) +{ +int first; +struct cw1200_wsm_event *event; + +if (priv->mode ==NL80211_IFTYPE_UNSPECIFIED ) { +/* STA is stopped. */ +return 0 ; + } + + event =kzalloc (sizeof (struct cw1200_wsm_event ),GFP_KERNEL ); + + event->evt.eventId =__le32_to_cpu (WSM_GET32 (buf)); + event->evt.eventData =__le32_to_cpu (WSM_GET32 (buf)); + +pr_debug ("[WSM] Event: %d(%d)\n" , + event->evt.eventId, event->evt.eventData); + +spin_lock (&priv->event_queue_lock); + first =list_empty (&priv->event_queue); +list_add_tail (&event->link, &priv->event_queue); +spin_unlock (&priv->event_queue_lock); + +if (first) +queue_work (priv->workqueue, &priv->event_handler); + +return 0 ; + +underflow: +kfree (event); +return -EINVAL ; +} + +static int wsm_channel_switch_indication (struct cw1200_common *priv, +struct wsm_buf *buf) +{ +wsm_unlock_tx (priv);/* Re-enable datapath */ +WARN_ON (WSM_GET32 (buf)); + + priv->channel_switch_in_progress =0 ; +wake_up (&priv->channel_switch_done); + +if (priv->wsm_cbc.channel_switch) + priv->wsm_cbc.channel_switch (priv); +return 0 ; + +underflow: +return -EINVAL ; +} + +static int wsm_set_pm_indication (struct cw1200_common *priv, +struct wsm_buf *buf) +{ +if (priv->ps_mode_switch_in_progress) { + priv->ps_mode_switch_in_progress =0 ; +wake_up (&priv->ps_mode_switch_done); + } +return 0 ; +} + +static int wsm_scan_started (struct cw1200_common *priv, +void *arg, +struct wsm_buf *buf) +{ +u32 status =WSM_GET32 (buf); +if (status !=WSM_STATUS_SUCCESS ) { +if (priv->wsm_cbc.scan_failed) { + priv->wsm_cbc.scan_failed (priv); + } +return -EINVAL ; + } +return 0 ; + +underflow: +WARN_ON (1 ); +return -EINVAL ; +} + +static int wsm_scan_complete_indication (struct cw1200_common *priv, +struct wsm_buf *buf) +{ +if (priv->wsm_cbc.scan_complete) { +struct wsm_scan_complete arg; + arg.status =WSM_GET32 (buf); + arg.psm =WSM_GET8 (buf); + arg.numChannels =WSM_GET8 (buf); + priv->wsm_cbc.scan_complete (priv, &arg); + } +return 0 ; + +underflow: +return -EINVAL ; +} + +static int wsm_join_complete_indication (struct cw1200_common *priv, +struct wsm_buf *buf) +{ +if (priv->wsm_cbc.join_complete) { +struct wsm_join_complete arg; + arg.status =WSM_GET32 (buf); +pr_debug ("[WSM] Join complete indication, status: %d\n" , + arg.status); + priv->wsm_cbc.join_complete (priv, &arg); + } +return 0 ; +underflow: +return -EINVAL ; +} + +static int wsm_find_complete_indication (struct cw1200_common *priv, +struct wsm_buf *buf) +{ +pr_warn ("Implement find_complete_indication\n" ); +return 0 ; +} + +static int wsm_ba_timeout_indication (struct cw1200_common *priv, +struct wsm_buf *buf) +{ +u32 dummy; +u8 tid; +u8 dummy2; +u8 addr[ETH_ALEN ]; + + dummy =WSM_GET32 (buf); + tid =WSM_GET8 (buf); + dummy2 =WSM_GET8 (buf); +WSM_GET (buf, addr,ETH_ALEN ); + +pr_info ("BlockACK timeout, tid %d, addr %pM\n" , + tid, addr); + +return 0 ; + +underflow: +return -EINVAL ; +} + +static int wsm_suspend_resume_indication (struct cw1200_common *priv, +int link_id,struct wsm_buf *buf) +{ +if (priv->wsm_cbc.suspend_resume) { +u32 flags; +struct wsm_suspend_resume arg; + + flags =WSM_GET32 (buf); + arg.link_id = link_id; + arg.stop = !(flags &1 ); + arg.multicast = !!(flags &8 ); + arg.queue = (flags >>1 ) &3 ; + + priv->wsm_cbc.suspend_resume (priv, &arg); + } +return 0 ; + +underflow: +return -EINVAL ; +} + + +/* ******************************************************************** */ +/* WSM TX */ + +static int wsm_cmd_send (struct cw1200_common *priv, +struct wsm_buf *buf, +void *arg,u16 cmd,long tmo) +{ +size_t buf_len = buf->data - buf->begin; +int ret; + +/* Don't bother if we're dead. */ +if (priv->bh_error) { + ret =0 ; + goto done; + } + +/* Block until the cmd buffer is completed. Tortuous. */ +spin_lock (&priv->wsm_cmd.lock); +while (!priv->wsm_cmd.done) { +spin_unlock (&priv->wsm_cmd.lock); +spin_lock (&priv->wsm_cmd.lock); + } + priv->wsm_cmd.done =0 ; +spin_unlock (&priv->wsm_cmd.lock); + +if (cmd ==0x0006 || cmd ==0x0005 )/* Write/Read MIB */ +pr_debug ("[WSM] >>> 0x%.4X [MIB: 0x%.4X] (%zu)\n" , + cmd,__le16_to_cpu (((__le16 *)buf->begin)[2 ]), + buf_len); +else +pr_debug ("[WSM] >>> 0x%.4X (%zu)\n" , cmd, buf_len); + +/* XXX HACK!! +* Due to buggy SPI on CW1200, we need to +* pad the message by a few bytes to ensure +* that it's completely received. +*/ +#ifdef CONFIG_CW1200_ETF +if (!etf_mode) +#endif + buf_len +=4 ; + +/* Fill HI message header */ +/* BH will add sequence number */ + ((__le16 *)buf->begin)[0 ] =__cpu_to_le16 (buf_len); + ((__le16 *)buf->begin)[1 ] =__cpu_to_le16 (cmd); + +spin_lock (&priv->wsm_cmd.lock); +BUG_ON (priv->wsm_cmd.ptr); + priv->wsm_cmd.ptr = buf->begin; + priv->wsm_cmd.len = buf_len; + priv->wsm_cmd.arg = arg; + priv->wsm_cmd.cmd = cmd; +spin_unlock (&priv->wsm_cmd.lock); + +cw1200_bh_wakeup (priv); + +/* Wait for command completion */ + ret =wait_event_timeout (priv->wsm_cmd_wq, + priv->wsm_cmd.done, tmo); + +if (!ret && !priv->wsm_cmd.done) { +spin_lock (&priv->wsm_cmd.lock); + priv->wsm_cmd.done =1 ; + priv->wsm_cmd.ptr =NULL ; +spin_unlock (&priv->wsm_cmd.lock); +if (priv->bh_error) { +/* Return ok to help system cleanup */ + ret =0 ; + }else { +pr_err ("CMD req (0x%04x) stuck in firmware, killing BH\n" , priv->wsm_cmd.cmd); +print_hex_dump_bytes ("REQDUMP: " ,DUMP_PREFIX_NONE , + buf->begin, buf_len); +pr_err ("Outstanding outgoing frames: %d\n" , priv->hw_bufs_used); + +/* Kill BH thread to report the error to the top layer. */ +atomic_add (1 , &priv->bh_term); +wake_up (&priv->bh_wq); + ret = -ETIMEDOUT ; + } + }else { +spin_lock (&priv->wsm_cmd.lock); +BUG_ON (!priv->wsm_cmd.done); + ret = priv->wsm_cmd.ret; +spin_unlock (&priv->wsm_cmd.lock); + } +done: +wsm_buf_reset (buf); +return ret; +} + +#ifdef CONFIG_CW1200_ETF +int wsm_raw_cmd (struct cw1200_common *priv,u8 *data,size_t len) +{ +struct wsm_buf *buf = &priv->wsm_cmd_buf; +int ret; + +u16 *cmd = (u16 *)(data +2 ); + +wsm_cmd_lock (priv); + +WSM_PUT (buf, data +4 , len -4 );/* Skip over header (u16+u16) */ + + ret =wsm_cmd_send (priv, buf,NULL ,__le16_to_cpu (*cmd),WSM_CMD_TIMEOUT ); + +wsm_cmd_unlock (priv); +return ret; + +nomem: +wsm_cmd_unlock (priv); +return -ENOMEM ; +} +#endif /* CONFIG_CW1200_ETF */ + +/* ******************************************************************** */ +/* WSM TX port control */ + +void wsm_lock_tx (struct cw1200_common *priv) +{ +wsm_cmd_lock (priv); +if (atomic_add_return (1 , &priv->tx_lock) ==1 ) { +if (wsm_flush_tx (priv)) +pr_debug ("[WSM] TX is locked.\n" ); + } +wsm_cmd_unlock (priv); +} + +void wsm_lock_tx_async (struct cw1200_common *priv) +{ +if (atomic_add_return (1 , &priv->tx_lock) ==1 ) +pr_debug ("[WSM] TX is locked (async).\n" ); +} + +bool wsm_flush_tx (struct cw1200_common *priv) +{ +unsigned long timestamp = jiffies; +bool pending = false; +long timeout; +int i; + +/* Flush must be called with TX lock held. */ +BUG_ON (!atomic_read (&priv->tx_lock)); + +/* First check if we really need to do something. +* It is safe to use unprotected access, as hw_bufs_used +* can only decrements. */ +if (!priv->hw_bufs_used) +return true; + +if (priv->bh_error) { +/* In case of failure do not wait for magic. */ +pr_err ("[WSM] Fatal error occured, will not flush TX.\n" ); +return false; + }else { +/* Get a timestamp of "oldest" frame */ +for (i =0 ; i <4 ; ++i) + pending |=cw1200_queue_get_xmit_timestamp ( + &priv->tx_queue[i], + ×tamp,0xffffffff ); +/* It is allowed to lock TX with only a command in the pipe. */ +if (!pending) +return true; + + timeout = timestamp +WSM_CMD_LAST_CHANCE_TIMEOUT - jiffies; +if (timeout <0 ||wait_event_timeout (priv->bh_evt_wq, + !priv->hw_bufs_used, + timeout) <=0 ) { +/* Hmmm... Not good. Frame had stuck in firmware. */ + priv->bh_error =1 ; +wiphy_err (priv->hw->wiphy,"[WSM] TX Frames (%d) stuck in firmware, killing BH\n" , priv->hw_bufs_used); +wake_up (&priv->bh_wq); +return false; + } + +/* Ok, everything is flushed. */ +return true; + } +} + +void wsm_unlock_tx (struct cw1200_common *priv) +{ +int tx_lock; + tx_lock =atomic_sub_return (1 , &priv->tx_lock); +BUG_ON (tx_lock <0 ); + +if (tx_lock ==0 ) { +if (!priv->bh_error) +cw1200_bh_wakeup (priv); +pr_debug ("[WSM] TX is unlocked.\n" ); + } +} + +/* ******************************************************************** */ +/* WSM RX */ + +int wsm_handle_exception (struct cw1200_common *priv,u8 *data,size_t len) +{ +struct wsm_buf buf; +u32 reason; +u32 reg[18 ]; +char fname[48 ]; +unsigned int i; + +static const char *const reason_str[] = { +"undefined instruction" , +"prefetch abort" , +"data abort" , +"unknown error" , + }; + + buf.begin = buf.data = data; + buf.end = &buf.begin[len]; + + reason =WSM_GET32 (&buf); +for (i =0 ; i <ARRAY_SIZE (reg); ++i) + reg[i] =WSM_GET32 (&buf); +WSM_GET (&buf, fname,sizeof (fname)); + +if (reason <4 ) +wiphy_err (priv->hw->wiphy, +"Firmware exception: %s.\n" , + reason_str[reason]); +else +wiphy_err (priv->hw->wiphy, +"Firmware assert at %.*s, line %d\n" , + (int )sizeof (fname), fname, reg[1 ]); + +for (i =0 ; i <12 ; i +=4 ) +wiphy_err (priv->hw->wiphy, +"R%d: 0x%.8X, R%d: 0x%.8X, R%d: 0x%.8X, R%d: 0x%.8X,\n" , + i +0 , reg[i +0 ], i +1 , reg[i +1 ], + i +2 , reg[i +2 ], i +3 , reg[i +3 ]); +wiphy_err (priv->hw->wiphy, +"R12: 0x%.8X, SP: 0x%.8X, LR: 0x%.8X, PC: 0x%.8X,\n" , + reg[i +0 ], reg[i +1 ], reg[i +2 ], reg[i +3 ]); + i +=4 ; +wiphy_err (priv->hw->wiphy, +"CPSR: 0x%.8X, SPSR: 0x%.8X\n" , + reg[i +0 ], reg[i +1 ]); + +print_hex_dump_bytes ("R1: " ,DUMP_PREFIX_NONE , + fname,sizeof (fname)); +return 0 ; + +underflow: +wiphy_err (priv->hw->wiphy, +"Firmware exception.\n" ); +print_hex_dump_bytes ("Exception: " ,DUMP_PREFIX_NONE , + data, len); +return -EINVAL ; +} + +int wsm_handle_rx (struct cw1200_common *priv,u16 id, +struct wsm_hdr *wsm,struct sk_buff **skb_p) +{ +int ret =0 ; +struct wsm_buf wsm_buf; +int link_id = (id >>6 ) &0x0F ; + +/* Strip link id. */ + id &= ~WSM_TX_LINK_ID (WSM_TX_LINK_ID_MAX ); + + wsm_buf.begin = (u8 *)&wsm[0 ]; + wsm_buf.data = (u8 *)&wsm[1 ]; + wsm_buf.end = &wsm_buf.begin[__le32_to_cpu (wsm->len)]; + +pr_debug ("[WSM] <<< 0x%.4X (%td)\n" , id, + wsm_buf.end - wsm_buf.begin); + +#ifdef CONFIG_CW1200_ETF +if (etf_mode) { +struct sk_buff *skb =alloc_skb (wsm_buf.end - wsm_buf.begin,GFP_KERNEL ); + +/* Strip out Sequence num before passing up */ + wsm->id =__le16_to_cpu (wsm->id); + wsm->id &=0x0FFF ; + wsm->id =__cpu_to_le16 (wsm->id); + +memcpy (skb_put (skb, wsm_buf.end - wsm_buf.begin), + wsm_buf.begin, + wsm_buf.end - wsm_buf.begin); +skb_queue_tail (&priv->etf_q, skb); + + +/* Special case for startup */ +if (id ==0x0801 ) +wsm_startup_indication (priv, &wsm_buf); +if (id &0x0400 ) { +spin_lock (&priv->wsm_cmd.lock); + priv->wsm_cmd.done =1 ; +spin_unlock (&priv->wsm_cmd.lock); +wake_up (&priv->wsm_cmd_wq); + } + + goto out; + } +#endif + +if (id ==0x404 ) { + ret =wsm_tx_confirm (priv, &wsm_buf, link_id); + }else if (id ==0x41E ) { + ret =wsm_multi_tx_confirm (priv, &wsm_buf, link_id); + }else if (id &0x0400 ) { +void *wsm_arg; +u16 wsm_cmd; + +/* Do not trust FW too much. Protection against repeated +* response and race condition removal (see above). */ +spin_lock (&priv->wsm_cmd.lock); + wsm_arg = priv->wsm_cmd.arg; + wsm_cmd = priv->wsm_cmd.cmd & + ~WSM_TX_LINK_ID (WSM_TX_LINK_ID_MAX ); + priv->wsm_cmd.cmd =0xFFFF ; +spin_unlock (&priv->wsm_cmd.lock); + +if (WARN_ON ((id & ~0x0400 ) != wsm_cmd)) { +/* Note that any non-zero is a fatal retcode. */ + ret = -EINVAL ; + goto out; + } + +switch (id) { +case 0x0405 : +if (wsm_arg) + ret =wsm_read_mib_confirm (priv, wsm_arg, + &wsm_buf); +break ; +case 0x0406 : +if (wsm_arg) + ret =wsm_write_mib_confirm (priv, wsm_arg, + &wsm_buf); +break ; +case 0x0407 :/* start-scan */ +if (wsm_arg) + ret =wsm_scan_started (priv, wsm_arg, &wsm_buf); +break ; +case 0x0409 : +/* Note that wsm_arg can be NULL in case of timeout in +* wsm_cmd_send(). */ +if (wsm_arg) + ret =wsm_configuration_confirm (priv, wsm_arg, + &wsm_buf); +break ; +case 0x040B : +if (wsm_arg) + ret =wsm_join_confirm (priv, wsm_arg, &wsm_buf); +break ; +case 0x0408 :/* stop-scan */ +case 0x040A :/* wsm_reset */ +case 0x040C :/* add_key */ +case 0x040D :/* remove_key */ +case 0x0410 :/* wsm_set_pm */ +case 0x0411 :/* set_bss_params */ +case 0x0412 :/* set_tx_queue_params */ +case 0x0413 :/* set_edca_params */ +case 0x0416 :/* switch_channel */ +case 0x0417 :/* start */ +case 0x0418 :/* beacon_transmit */ +case 0x0419 :/* start_find */ +case 0x041A :/* stop_find */ +case 0x041B :/* update_ie */ +case 0x041C :/* map_link */ +WARN_ON (wsm_arg !=NULL ); + ret =wsm_generic_confirm (priv, wsm_arg, &wsm_buf); +if (ret) { +wiphy_warn (priv->hw->wiphy, +"wsm_generic_confirm failed for request 0x%04x.\n" , + id & ~0x0400 ); + +/* often 0x407 and 0x410 occur, this means we're dead.. */ +if (priv->join_status >=CW1200_JOIN_STATUS_JOINING ) { +wsm_lock_tx (priv); +if (queue_work (priv->workqueue, &priv->unjoin_work) <=0 ) +wsm_unlock_tx (priv); + } + } +break ; +default : +wiphy_warn (priv->hw->wiphy, +"Unrecognized confirmation 0x%04x\n" , + id & ~0x0400 ); + } + +spin_lock (&priv->wsm_cmd.lock); + priv->wsm_cmd.ret = ret; + priv->wsm_cmd.done =1 ; +spin_unlock (&priv->wsm_cmd.lock); + + ret =0 ;/* Error response from device should ne stop BH. */ + +wake_up (&priv->wsm_cmd_wq); + }else if (id &0x0800 ) { +switch (id) { +case 0x0801 : + ret =wsm_startup_indication (priv, &wsm_buf); +break ; +case 0x0804 : + ret =wsm_receive_indication (priv, link_id, + &wsm_buf, skb_p); +break ; +case 0x0805 : + ret =wsm_event_indication (priv, &wsm_buf); +break ; +case 0x0806 : + ret =wsm_scan_complete_indication (priv, &wsm_buf); +break ; +case 0x0808 : + ret =wsm_ba_timeout_indication (priv, &wsm_buf); +break ; +case 0x080A : + ret =wsm_channel_switch_indication (priv, &wsm_buf); +break ; +case 0x0809 : + ret =wsm_set_pm_indication (priv, &wsm_buf); +break ; +case 0x080B : + ret =wsm_find_complete_indication (priv, &wsm_buf); +break ; +case 0x080C : + ret =wsm_suspend_resume_indication (priv, + link_id, &wsm_buf); +break ; +case 0x080F : + ret =wsm_join_complete_indication (priv, &wsm_buf); +break ; +default : +pr_warn ("Unrecognised WSM ID %04x\n" , id); + } + }else { +WARN_ON (1 ); + ret = -EINVAL ; + } +out: +return ret; +} + +static bool wsm_handle_tx_data (struct cw1200_common *priv, +const struct wsm_tx *wsm, +const struct ieee80211_tx_info *tx_info, +const struct cw1200_txpriv *txpriv, +struct cw1200_queue *queue) +{ +bool handled = false; +const struct ieee80211_hdr *frame = + (struct ieee80211_hdr *) &((u8 *)wsm)[txpriv->offset]; +__le16 fctl = frame->frame_control; +enum { + doProbe, + doDrop, + doJoin, + doOffchannel, + doWep, + doTx, + } action = doTx; + +switch (priv->mode) { +case NL80211_IFTYPE_STATION : +if ((priv->join_status ==CW1200_JOIN_STATUS_STA ) && +ieee80211_is_nullfunc (fctl)) { +spin_lock (&priv->bss_loss_lock); +if (priv->bss_loss_status ==CW1200_BSS_LOSS_CHECKING ) { + priv->bss_loss_status = +CW1200_BSS_LOSS_CONFIRMING ; + priv->bss_loss_confirm_id = wsm->packetID; + } +spin_unlock (&priv->bss_loss_lock); + }else if ((priv->join_status <=CW1200_JOIN_STATUS_MONITOR ) || +memcmp (frame->addr3, priv->join_bssid, +sizeof (priv->join_bssid))) { +if (ieee80211_is_auth (fctl)) + action = doJoin; +else if (ieee80211_is_probe_req (fctl)) + action = doTx; +else if (priv->join_status >= +CW1200_JOIN_STATUS_MONITOR ) + action = doTx; +else + action = doOffchannel; + } +break ; +case NL80211_IFTYPE_AP : +if (!priv->join_status) + action = doDrop; +else if (!(BIT (txpriv->raw_link_id) & + (BIT (0 ) | priv->link_id_map))) { +wiphy_warn (priv->hw->wiphy, +"A frame with expired link id is dropped.\n" ); + action = doDrop; + } +if (cw1200_queue_get_generation (wsm->packetID) > +CW1200_MAX_REQUEUE_ATTEMPTS ) { +/* HACK!!! WSM324 firmware has tendency to requeue +* multicast frames in a loop, causing performance +* drop and high power consumption of the driver. +* In this situation it is better just to drop +* the problematic frame. */ +wiphy_warn (priv->hw->wiphy, +"Too many attempts to requeue a frame; dropped.\n" ); + action = doDrop; + } +break ; +case NL80211_IFTYPE_ADHOC : +/* Let everything through in IBSS mode */ +break ; +case NL80211_IFTYPE_MESH_POINT : +pr_warn ("MESH_POINT not tested yet\n" ); +case NL80211_IFTYPE_MONITOR : +default : + action = doDrop; +break ; + } + +if (action == doTx) { +if (ieee80211_is_probe_req (fctl)) + action = doProbe; +else if ((fctl &__cpu_to_le32 (IEEE80211_FCTL_PROTECTED )) && + tx_info->control.hw_key && + tx_info->control.hw_key->keyidx != + priv->wep_default_key_id && + (tx_info->control.hw_key->cipher == +WLAN_CIPHER_SUITE_WEP40 || + tx_info->control.hw_key->cipher == +WLAN_CIPHER_SUITE_WEP104 )) + action = doWep; + } + +switch (action) { +case doProbe: + { +/* An interesting FW "feature". Device filters +* probe responses. +* The easiest way to get it back is to convert +* probe request into WSM start_scan command. */ +pr_debug ("[WSM] Convert probe request to scan.\n" ); +wsm_lock_tx_async (priv); + priv->pending_frame_id =__le32_to_cpu (wsm->packetID); +queue_delayed_work (priv->workqueue, + &priv->scan.probe_work,0 ); + handled = true; + } +break ; +case doDrop: + { +/* See detailed description of "join" below. +* We are dropping everything except AUTH in non-joined mode. */ +pr_debug ("[WSM] Drop frame (0x%.4X).\n" , fctl); +BUG_ON (cw1200_queue_remove (queue, +__le32_to_cpu (wsm->packetID))); + handled = true; + } +break ; +case doJoin: + { +/* There is one more interesting "feature" +* in FW: it can't do RX/TX before "join". +* "Join" here is not an association, +* but just a syncronization between AP and STA. +* priv->join_status is used only in bh thread and does +* not require protection */ + +mutex_lock (&priv->conf_mutex); +if (priv->join_pending) { +pr_debug ("[WSM] Auth pending. Drop duplicate.\n" ); +cw1200_queue_remove (queue, +__le32_to_cpu (wsm->packetID)); + }else { + priv->join_pending = true; +pr_debug ("[WSM] Issue join command.\n" ); +wsm_lock_tx_async (priv); + priv->pending_frame_id =__le32_to_cpu (wsm->packetID); +if (queue_work (priv->workqueue, &priv->join_work) <=0 ) +wsm_unlock_tx (priv); + } +mutex_unlock (&priv->conf_mutex); + handled = true; + } +break ; +case doOffchannel: + { +pr_debug ("[WSM] Offchannel TX request.\n" ); +wsm_lock_tx_async (priv); + priv->pending_frame_id =__le32_to_cpu (wsm->packetID); +if (queue_work (priv->workqueue, &priv->offchannel_work) <=0 ) +wsm_unlock_tx (priv); + handled = true; + } +break ; +case doWep: + { +pr_debug ("[WSM] Issue set_default_wep_key.\n" ); +wsm_lock_tx_async (priv); + priv->wep_default_key_id = tx_info->control.hw_key->keyidx; + priv->pending_frame_id =__le32_to_cpu (wsm->packetID); +if (queue_work (priv->workqueue, &priv->wep_key_work) <=0 ) +wsm_unlock_tx (priv); + handled = true; + } +break ; +case doTx: + { +if (ieee80211_is_deauth (fctl) && + priv->mode !=NL80211_IFTYPE_AP ) { +/* Shedule unjoin work */ +pr_debug ("[WSM] Issue unjoin command (TX).\n" ); +wsm_lock_tx_async (priv); +if (queue_work (priv->workqueue, + &priv->unjoin_work) <=0 ) +wsm_unlock_tx (priv); + } + } +break ; + } +return handled; +} + +static int cw1200_get_prio_queue (struct cw1200_common *priv, +u32 link_id_map,int *total) +{ +static const int urgent =BIT (CW1200_LINK_ID_AFTER_DTIM ) | +BIT (CW1200_LINK_ID_UAPSD ); +struct wsm_edca_queue_params *edca; +unsigned score, best =-1 ; +int winner =-1 ; +int queued; +int i; + +/* search for a winner using edca params */ +for (i =0 ; i <4 ; ++i) { + queued =cw1200_queue_get_num_queued (&priv->tx_queue[i], + link_id_map); +if (!queued) +continue ; + *total += queued; + edca = &priv->edca.params[i]; + score = ((edca->aifns + edca->cwMin) <<16 ) + + (edca->cwMax - edca->cwMin) * + (random32 () &0xFFFF ); +if (score < best && (winner <0 || i !=3 )) { + best = score; + winner = i; + } + } + +/* override winner if bursting */ +if (winner >=0 && priv->tx_burst_idx >=0 && + winner != priv->tx_burst_idx && + !cw1200_queue_get_num_queued ( + &priv->tx_queue[winner], + link_id_map & urgent) && +cw1200_queue_get_num_queued ( + &priv->tx_queue[priv->tx_burst_idx], + link_id_map)) + winner = priv->tx_burst_idx; + +return winner; +} + +static int wsm_get_tx_queue_and_mask (struct cw1200_common *priv, +struct cw1200_queue **queue_p, +u32 *tx_allowed_mask_p, +bool *more) +{ +int idx; +u32 tx_allowed_mask; +int total =0 ; + +/* Search for a queue with multicast frames buffered */ +if (priv->tx_multicast) { + tx_allowed_mask =BIT (CW1200_LINK_ID_AFTER_DTIM ); + idx =cw1200_get_prio_queue (priv, + tx_allowed_mask, &total); +if (idx >=0 ) { + *more = total >1 ; + goto found; + } + } + +/* Search for unicast traffic */ + tx_allowed_mask = ~priv->sta_asleep_mask; + tx_allowed_mask |=BIT (CW1200_LINK_ID_UAPSD ); +if (priv->sta_asleep_mask) { + tx_allowed_mask |= priv->pspoll_mask; + tx_allowed_mask &= ~BIT (CW1200_LINK_ID_AFTER_DTIM ); + }else { + tx_allowed_mask |=BIT (CW1200_LINK_ID_AFTER_DTIM ); + } + idx =cw1200_get_prio_queue (priv, + tx_allowed_mask, &total); +if (idx <0 ) +return -ENOENT ; + +found: + *queue_p = &priv->tx_queue[idx]; + *tx_allowed_mask_p = tx_allowed_mask; +return 0 ; +} + +int wsm_get_tx (struct cw1200_common *priv,u8 **data, +size_t *tx_len,int *burst) +{ +struct wsm_tx *wsm =NULL ; +struct ieee80211_tx_info *tx_info; +struct cw1200_queue *queue =NULL ; +int queue_num; +u32 tx_allowed_mask =0 ; +const struct cw1200_txpriv *txpriv =NULL ; +int count =0 ; + +/* More is used only for broadcasts. */ +bool more = false; + +#ifdef CONFIG_CW1200_ITP + count =cw1200_itp_get_tx (priv, data, tx_len, burst); +if (count) +return count; +#endif + +if (priv->wsm_cmd.ptr) {/* CMD request */ + ++count; +spin_lock (&priv->wsm_cmd.lock); +BUG_ON (!priv->wsm_cmd.ptr); + *data = priv->wsm_cmd.ptr; + *tx_len = priv->wsm_cmd.len; + *burst =1 ; +spin_unlock (&priv->wsm_cmd.lock); + }else { +for (;;) { +int ret; + +if (atomic_add_return (0 , &priv->tx_lock)) +break ; + +spin_lock_bh (&priv->ps_state_lock); + + ret =wsm_get_tx_queue_and_mask (priv, &queue, + &tx_allowed_mask, &more); + queue_num = queue - priv->tx_queue; + +if (priv->buffered_multicasts && + (ret || !more) && + (priv->tx_multicast || + !priv->sta_asleep_mask)) { + priv->buffered_multicasts = false; +if (priv->tx_multicast) { + priv->tx_multicast = false; +queue_work (priv->workqueue, + &priv->multicast_stop_work); + } + } + +spin_unlock_bh (&priv->ps_state_lock); + +if (ret) +break ; + +if (cw1200_queue_get (queue, + tx_allowed_mask, + &wsm, &tx_info, &txpriv)) +continue ; + +if (wsm_handle_tx_data (priv, wsm, + tx_info, txpriv, queue)) +continue ;/* Handled by WSM */ + + wsm->hdr.id &=__cpu_to_le16 ( + ~WSM_TX_LINK_ID (WSM_TX_LINK_ID_MAX )); + wsm->hdr.id |=cpu_to_le16 ( +WSM_TX_LINK_ID (txpriv->raw_link_id)); + priv->pspoll_mask &= ~BIT (txpriv->raw_link_id); + + *data = (u8 *)wsm; + *tx_len =__le16_to_cpu (wsm->hdr.len); + +/* allow bursting if txop is set */ +if (priv->edca.params[queue_num].txOpLimit) + *burst =min (*burst, + (int )cw1200_queue_get_num_queued ( + queue, tx_allowed_mask) +1 ); +else + *burst =1 ; + +/* store index of bursting queue */ +if (*burst >1 ) + priv->tx_burst_idx = queue_num; +else + priv->tx_burst_idx =-1 ; + +if (more) { +struct ieee80211_hdr *hdr = + (struct ieee80211_hdr *) + &((u8 *)wsm)[txpriv->offset]; +/* more buffered multicast/broadcast frames +* ==> set MoreData flag in IEEE 802.11 header +* to inform PS STAs */ + hdr->frame_control |= +cpu_to_le16 (IEEE80211_FCTL_MOREDATA ); + } + +pr_debug ("[WSM] >>> 0x%.4X (%zu) %p %c\n" , +0x0004 , *tx_len, *data, + wsm->more ?'M' :' ' ); + ++count; +break ; + } + } + +return count; +} + +void wsm_txed (struct cw1200_common *priv,u8 *data) +{ +if (data == priv->wsm_cmd.ptr) { +spin_lock (&priv->wsm_cmd.lock); + priv->wsm_cmd.ptr =NULL ; +spin_unlock (&priv->wsm_cmd.lock); + } +} + +/* ******************************************************************** */ +/* WSM buffer */ + +void wsm_buf_init (struct wsm_buf *buf) +{ +BUG_ON (buf->begin); + buf->begin =kmalloc (FWLOAD_BLOCK_SIZE ,GFP_KERNEL |GFP_DMA ); + buf->end = buf->begin ? &buf->begin[FWLOAD_BLOCK_SIZE ] : buf->begin; +wsm_buf_reset (buf); +} + +void wsm_buf_deinit (struct wsm_buf *buf) +{ +kfree (buf->begin); + buf->begin = buf->data = buf->end =NULL ; +} + +static void wsm_buf_reset (struct wsm_buf *buf) +{ +if (buf->begin) { + buf->data = &buf->begin[4 ]; + *(u32 *)buf->begin =0 ; + }else + buf->data = buf->begin; +} + +static int wsm_buf_reserve (struct wsm_buf *buf,size_t extra_size) +{ +size_t pos = buf->data - buf->begin; +size_t size = pos + extra_size; + + size =round_up (size,FWLOAD_BLOCK_SIZE ); + + buf->begin =krealloc (buf->begin, size,GFP_KERNEL |GFP_DMA ); +if (buf->begin) { + buf->data = &buf->begin[pos]; + buf->end = &buf->begin[size]; +return 0 ; + }else { + buf->end = buf->data = buf->begin; +return -ENOMEM ; + } +}
drivers/net/wireless/cw1200/wsm.h new file +1862 -0
1,062 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.1.2
Part of the diff is not shown here. View the raw message.
PATCH 10/14 cw1200: v4: Main processing loop
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/bh.c | 661 +++++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/bh.h | 28 ++ 2 files changed, 689 insertions(+) create mode 100644 drivers/net/wireless/cw1200/bh.c create mode 100644 drivers/net/wireless/cw1200/bh.h
drivers/net/wireless/cw1200/bh.c new file +661 -0
@@ -0,0 +1,661 @@ +/* +* Device handling thread implementation for mac80211 ST-Ericsson CW1200 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* Based on: +* ST-Ericsson UMAC CW1200 driver, which is +* Copyright (c) 2010, ST-Ericsson +* Author: Ajitpal Singh <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/module.h> +#include <net/mac80211.h> +#include <linux/kthread.h> +#include <linux/timer.h> + +#include "cw1200.h" +#include "bh.h" +#include "hwio.h" +#include "wsm.h" +#include "sbus.h" +#include "debug.h" +#include "fwio.h" + +static int cw1200_bh (void *arg); + +/* TODO: Verify these numbers with WSM specification. */ +#define DOWNLOAD_BLOCK_SIZE_WR (0x1000 - 4) +/* an SPI message cannot be bigger than (2"12-1)*2 bytes +* "*2" to cvt to bytes */ +#define MAX_SZ_RD_WR_BUFFERS (DOWNLOAD_BLOCK_SIZE_WR*2) +#define PIGGYBACK_CTRL_REG (2) +#define EFFECTIVE_BUF_SIZE (MAX_SZ_RD_WR_BUFFERS - PIGGYBACK_CTRL_REG) + +/* Suspend state privates */ +enum cw1200_bh_pm_state { +CW1200_BH_RESUMED =0 , +CW1200_BH_SUSPEND , +CW1200_BH_SUSPENDED , +CW1200_BH_RESUME , +}; + +typedef int (*cw1200_wsm_handler )(struct cw1200_common *priv, +u8 *data,size_t size); + +#ifndef CW1200_USE_COMPAT_KTHREAD +static void cw1200_bh_work (struct work_struct *work) +{ +struct cw1200_common *priv = + container_of(work, struct cw1200_common, bh_work); +pr_debug ("[BH] %s enter\n" , __func__); +cw1200_bh (priv); +pr_debug ("[BH] %s exit\n" , __func__); +} +#endif + +int cw1200_register_bh (struct cw1200_common *priv) +{ +int err =0 ; +#ifdef CW1200_USE_COMPAT_KTHREAD +struct sched_param param = { .sched_priority =1 }; +BUG_ON (priv->bh_thread); +#else +/* Realtime workqueue */ + priv->bh_workqueue =alloc_workqueue ("cw1200_bh" , +WQ_MEM_RECLAIM |WQ_HIGHPRI + |WQ_CPU_INTENSIVE ,1 ); + +if (!priv->bh_workqueue) +return -ENOMEM ; + +INIT_WORK (&priv->bh_work, cw1200_bh_work); +#endif + +pr_debug ("[BH] register.\n" ); + +atomic_set (&priv->bh_rx,0 ); +atomic_set (&priv->bh_tx,0 ); +atomic_set (&priv->bh_term,0 ); +atomic_set (&priv->bh_suspend,CW1200_BH_RESUMED ); + priv->bh_error =0 ; + priv->hw_bufs_used =0 ; + priv->buf_id_tx =0 ; + priv->buf_id_rx =0 ; +init_waitqueue_head (&priv->bh_wq); +init_waitqueue_head (&priv->bh_evt_wq); + +#ifdef CW1200_USE_COMPAT_KTHREAD + priv->bh_thread =kthread_create (&cw1200_bh, priv,"cw1200_bh" ); +if (IS_ERR (priv->bh_thread)) { + err =PTR_ERR (priv->bh_thread); + priv->bh_thread =NULL ; + }else { +WARN_ON (sched_setscheduler (priv->bh_thread, +SCHED_FIFO , ¶m)); +#ifndef CW1200_NO_PUT_TASK_STRUCT +get_task_struct (priv->bh_thread); +#endif +wake_up_process (priv->bh_thread); + } +#else + err = !queue_work (priv->bh_workqueue, &priv->bh_work); +WARN_ON (err); +#endif +return err; +} + +void cw1200_unregister_bh (struct cw1200_common *priv) +{ +#ifdef CW1200_USE_COMPAT_KTHREAD +struct task_struct *thread = priv->bh_thread; +if (WARN_ON (!thread)) +return ; +#endif + +atomic_add (1 , &priv->bh_term); +wake_up (&priv->bh_wq); + +#ifdef CW1200_USE_COMPAT_KTHREAD +kthread_stop (thread); +#ifndef CW1200_NO_PUT_TASK_STRUCT +put_task_struct (thread); +#endif + priv->bh_thread =NULL ; +#else +flush_workqueue (priv->bh_workqueue); + +destroy_workqueue (priv->bh_workqueue); + priv->bh_workqueue =NULL ; +#endif + +pr_debug ("[BH] unregistered.\n" ); +} + +void cw1200_irq_handler (struct cw1200_common *priv) +{ +pr_debug ("[BH] irq.\n" ); + +/* Disable Interrupts! */ +/* NOTE: sbus_ops->lock already held */ +__cw1200_irq_enable (priv,0 ); + +if (/* WARN_ON */ (priv->bh_error)) +return ; + +if (atomic_add_return (1 , &priv->bh_rx) ==1 ) +wake_up (&priv->bh_wq); +} +EXPORT_SYMBOL_GPL (cw1200_irq_handler); + +void cw1200_bh_wakeup (struct cw1200_common *priv) +{ +pr_debug ("[BH] wakeup.\n" ); +if (priv->bh_error) { +pr_err ("[BH] wakeup failed (BH error)\n" ); +return ; + } + +if (atomic_add_return (1 , &priv->bh_tx) ==1 ) +wake_up (&priv->bh_wq); +} + +int cw1200_bh_suspend (struct cw1200_common *priv) +{ +pr_debug ("[BH] suspend.\n" ); +if (priv->bh_error) { +wiphy_warn (priv->hw->wiphy,"BH error -- can't suspend\n" ); +return -EINVAL ; + } + +atomic_set (&priv->bh_suspend,CW1200_BH_SUSPEND ); +wake_up (&priv->bh_wq); +return wait_event_timeout (priv->bh_evt_wq, priv->bh_error || + (CW1200_BH_SUSPENDED ==atomic_read (&priv->bh_suspend)), +1 *HZ ) ?0 : -ETIMEDOUT ; +} + +int cw1200_bh_resume (struct cw1200_common *priv) +{ +pr_debug ("[BH] resume.\n" ); +if (priv->bh_error) { +wiphy_warn (priv->hw->wiphy,"BH error -- can't resume\n" ); +return -EINVAL ; + } + +atomic_set (&priv->bh_suspend,CW1200_BH_RESUME ); +wake_up (&priv->bh_wq); +return wait_event_timeout (priv->bh_evt_wq, priv->bh_error || + (CW1200_BH_RESUMED ==atomic_read (&priv->bh_suspend)), +1 *HZ ) ?0 : -ETIMEDOUT ; +} + +static inline void wsm_alloc_tx_buffer (struct cw1200_common *priv) +{ + ++priv->hw_bufs_used; +} + +int wsm_release_tx_buffer (struct cw1200_common *priv,int count) +{ +int ret =0 ; +int hw_bufs_used = priv->hw_bufs_used; + + priv->hw_bufs_used -= count; +if (WARN_ON (priv->hw_bufs_used <0 )) + ret =-1 ; +else if (hw_bufs_used >= priv->wsm_caps.numInpChBufs) + ret =1 ; +if (!priv->hw_bufs_used) +wake_up (&priv->bh_evt_wq); +return ret; +} + +static int cw1200_bh_read_ctrl_reg (struct cw1200_common *priv, +u16 *ctrl_reg) +{ +int ret; + + ret =cw1200_reg_read_16 (priv, +ST90TDS_CONTROL_REG_ID , ctrl_reg); +if (ret) { + ret =cw1200_reg_read_16 (priv, +ST90TDS_CONTROL_REG_ID , ctrl_reg); +if (ret) +pr_err ("[BH] Failed to read control register.\n" ); + } + +return ret; +} + +static int cw1200_device_wakeup (struct cw1200_common *priv) +{ +u16 ctrl_reg; +int ret; + +pr_debug ("[BH] Device wakeup.\n" ); + +/* First, set the dpll register */ + ret =cw1200_reg_write_32 (priv,ST90TDS_TSET_GEN_R_W_REG_ID ,cw1200_dpll_from_clk (priv->hw_refclk)); +if (WARN_ON (ret)) +return ret; + +/* To force the device to be always-on, the host sets WLAN_UP to 1 */ + ret =cw1200_reg_write_16 (priv,ST90TDS_CONTROL_REG_ID , +ST90TDS_CONT_WUP_BIT ); +if (WARN_ON (ret)) +return ret; + + ret =cw1200_bh_read_ctrl_reg (priv, &ctrl_reg); +if (WARN_ON (ret)) +return ret; + +/* If the device returns WLAN_RDY as 1, the device is active and will +* remain active. */ +if (ctrl_reg &ST90TDS_CONT_RDY_BIT ) { +pr_debug ("[BH] Device awake.\n" ); +return 1 ; + } + +return 0 ; +} + +/* Must be called from BH thraed. */ +void cw1200_enable_powersave (struct cw1200_common *priv, +bool enable) +{ +pr_debug ("[BH] Powerave is %s.\n" , + enable ?"enabled" :"disabled" ); + priv->powersave_enabled = enable; +} + +static int cw1200_bh_rx_helper (struct cw1200_common *priv, +uint16_t *ctrl_reg, +int *tx) +{ +size_t read_len =0 ; +struct sk_buff *skb_rx =NULL ; +struct wsm_hdr *wsm; +size_t wsm_len; +u16 wsm_id; +u8 wsm_seq; +int rx_resync =1 ; + +size_t alloc_len; +u8 *data; + + read_len = (*ctrl_reg &ST90TDS_CONT_NEXT_LEN_MASK ) *2 ; +if (!read_len) +return 0 ;/* No more work */ + +if (WARN_ON ((read_len <sizeof (struct wsm_hdr )) || + (read_len >EFFECTIVE_BUF_SIZE ))) { +pr_debug ("Invalid read len: %zu (%04x)" , + read_len, *ctrl_reg); + goto err; + } + +/* Add SIZE of PIGGYBACK reg (CONTROL Reg) +* to the NEXT Message length + 2 Bytes for SKB */ + read_len = read_len +2 ; + + alloc_len = priv->sbus_ops->align_size ( + priv->sbus_priv, read_len); + +/* Check if not exceeding CW1200 capabilities */ +if (WARN_ON_ONCE (alloc_len >EFFECTIVE_BUF_SIZE )) { +pr_debug ("Read aligned len: %zu\n" , + alloc_len); + } + + skb_rx =dev_alloc_skb (alloc_len); +if (WARN_ON (!skb_rx)) + goto err; + +skb_trim (skb_rx,0 ); +skb_put (skb_rx, read_len); + data = skb_rx->data; +if (WARN_ON (!data)) + goto err; + +if (WARN_ON (cw1200_data_read (priv, data, alloc_len))) { +pr_err ("rx blew up, len %zu\n" , alloc_len); + goto err; + } + +/* Piggyback */ + *ctrl_reg =__le16_to_cpu ( + ((__le16 *)data)[alloc_len /2 -1 ]); + + wsm = (struct wsm_hdr *)data; + wsm_len =__le16_to_cpu (wsm->len); +if (WARN_ON (wsm_len > read_len)) + goto err; + +if (priv->wsm_enable_wsm_dumps) +print_hex_dump_bytes ("<-- " , +DUMP_PREFIX_NONE , + data, wsm_len); + + wsm_id =__le16_to_cpu (wsm->id) &0xFFF ; + wsm_seq = (__le16_to_cpu (wsm->id) >>13 ) &7 ; + +skb_trim (skb_rx, wsm_len); + +if (wsm_id ==0x0800 ) { +wsm_handle_exception (priv, + &data[sizeof (*wsm)], + wsm_len -sizeof (*wsm)); + goto err; + }else if (!rx_resync) { +if (WARN_ON (wsm_seq != priv->wsm_rx_seq)) + goto err; + } + priv->wsm_rx_seq = (wsm_seq +1 ) &7 ; + rx_resync =0 ; + +if (wsm_id &0x0400 ) { +int rc =wsm_release_tx_buffer (priv,1 ); +if (WARN_ON (rc <0 )) +return rc; +else if (rc >0 ) + *tx =1 ; + } + +/* cw1200_wsm_rx takes care on SKB livetime */ +if (WARN_ON (wsm_handle_rx (priv, wsm_id, wsm, &skb_rx))) + goto err; + +if (skb_rx) { +dev_kfree_skb (skb_rx); + skb_rx =NULL ; + } + +return 0 ; + +err: +if (skb_rx) { +dev_kfree_skb (skb_rx); + skb_rx =NULL ; + } +return -1 ; +} + +static int cw1200_bh_tx_helper (struct cw1200_common *priv, +int *pending_tx, +int *tx_burst) +{ +size_t tx_len; +u8 *data; +int ret; +struct wsm_hdr *wsm; + +if (priv->device_can_sleep) { + ret =cw1200_device_wakeup (priv); +if (WARN_ON (ret <0 )) {/* Error in wakeup */ + *pending_tx =1 ; +return 0 ; + }else if (ret) {/* Woke up */ + priv->device_can_sleep = false; + }else {/* Did not awake */ + *pending_tx =1 ; +return 0 ; + } + } + +wsm_alloc_tx_buffer (priv); + ret =wsm_get_tx (priv, &data, &tx_len, tx_burst); +if (ret <=0 ) { +wsm_release_tx_buffer (priv,1 ); +if (WARN_ON (ret <0 )) +return ret;/* Error */ +return 0 ;/* No work */ + } + + wsm = (struct wsm_hdr *)data; +BUG_ON (tx_len <sizeof (*wsm)); +BUG_ON (__le16_to_cpu (wsm->len) != tx_len); + +atomic_add (1 , &priv->bh_tx); + + tx_len = priv->sbus_ops->align_size ( + priv->sbus_priv, tx_len); + +/* Check if not exceeding CW1200 capabilities */ +if (WARN_ON_ONCE (tx_len >EFFECTIVE_BUF_SIZE )) +pr_debug ("Write aligned len: %zu\n" , tx_len); + + wsm->id &=__cpu_to_le16 (0xffff ^WSM_TX_SEQ (WSM_TX_SEQ_MAX )); + wsm->id |=__cpu_to_le16 (WSM_TX_SEQ (priv->wsm_tx_seq)); + +if (WARN_ON (cw1200_data_write (priv, data, tx_len))) { +pr_err ("tx blew up, len %zu\n" , tx_len); +wsm_release_tx_buffer (priv,1 ); +return -1 ;/* Error */ + } + +if (priv->wsm_enable_wsm_dumps) +print_hex_dump_bytes ("--> " , +DUMP_PREFIX_NONE , + data, +__le16_to_cpu (wsm->len)); + +wsm_txed (priv, data); + priv->wsm_tx_seq = (priv->wsm_tx_seq +1 ) &WSM_TX_SEQ_MAX ; + +if (*tx_burst >1 ) { +cw1200_debug_tx_burst (priv); +return 1 ;/* Work remains */ + } + +return 0 ; +} + +static int cw1200_bh (void *arg) +{ +struct cw1200_common *priv = arg; +int rx, tx, term, suspend; +u16 ctrl_reg =0 ; +int tx_allowed; +int pending_tx =0 ; +int tx_burst; +long status; +u32 dummy; +int ret; + +for (;;) { +if (!priv->hw_bufs_used && + priv->powersave_enabled && + !priv->device_can_sleep && + !atomic_read (&priv->recent_scan)) { + status =1 *HZ ; +pr_debug ("[BH] Device wakedown. No data.\n" ); +WARN_ON (cw1200_reg_write_16 (priv, +ST90TDS_CONTROL_REG_ID ,0 )); + priv->device_can_sleep = true; + }else if (priv->hw_bufs_used) { +/* Interrupt loss detection */ + status =1 *HZ ; + }else { + status =MAX_SCHEDULE_TIMEOUT ; + } + +/* Dummy Read for SDIO retry mechanism*/ +if ((priv->hw_type !=-1 ) && + (atomic_read (&priv->bh_rx) ==0 ) && + (atomic_read (&priv->bh_tx) ==0 )) +cw1200_reg_read (priv,ST90TDS_CONFIG_REG_ID , + &dummy,sizeof (dummy)); + +pr_debug ("[BH] waiting ...\n" ); + status =wait_event_interruptible_timeout (priv->bh_wq, ({ + rx =atomic_xchg (&priv->bh_rx,0 ); + tx =atomic_xchg (&priv->bh_tx,0 ); + term =atomic_xchg (&priv->bh_term,0 ); + suspend = pending_tx ? +0 :atomic_read (&priv->bh_suspend); + (rx || tx || term || suspend || priv->bh_error); + }), status); + +pr_debug ("[BH] - rx: %d, tx: %d, term: %d, suspend: %d, status: %ld\n" , + rx, tx, term, suspend, status); + +/* Did an error occur? */ +if ((status <0 && status != -ERESTARTSYS ) || + term || priv->bh_error) { +break ; + } +if (!status) {/* wait_event timed out */ +unsigned long timestamp = jiffies; +long timeout; +int pending =0 ; +int i; + +/* Check to see if we have any outstanding frames */ +if (priv->hw_bufs_used && (!rx || !tx)) { +wiphy_warn (priv->hw->wiphy,"Missed interrupt? (%d frames outstanding)\n" , priv->hw_bufs_used); + rx =1 ; + +/* Get a timestamp of "oldest" frame */ +for (i =0 ; i <4 ; ++i) + pending +=cw1200_queue_get_xmit_timestamp ( + &priv->tx_queue[i], + ×tamp, priv->pending_frame_id); + +/* Check if frame transmission is timed out. +* Add an extra second with respect to possible +* interrupt loss. */ + timeout = timestamp + +WSM_CMD_LAST_CHANCE_TIMEOUT + +1 *HZ - + jiffies; + +/* And terminate BH thread if the frame is "stuck" */ +if (pending && timeout <0 ) { +wiphy_warn (priv->hw->wiphy, +"Timeout waiting for TX confirm (%d/%d pending, %ld vs %lu).\n" , priv->hw_bufs_used, pending, timestamp, jiffies); +break ; + } + }else if (!priv->device_can_sleep + && !atomic_read (&priv->recent_scan)) { +pr_debug ("[BH] Device wakedown. Timeout.\n" ); +WARN_ON (cw1200_reg_write_16 (priv,ST90TDS_CONTROL_REG_ID ,0 )); + priv->device_can_sleep = true; + } + goto done; + }else if (suspend) { +pr_debug ("[BH] Device suspend.\n" ); +if (priv->powersave_enabled) { +pr_debug ("[BH] Device wakedown. Suspend.\n" ); +WARN_ON (cw1200_reg_write_16 (priv, +ST90TDS_CONTROL_REG_ID ,0 )); + priv->device_can_sleep = true; + } + +atomic_set (&priv->bh_suspend,CW1200_BH_SUSPENDED ); +wake_up (&priv->bh_evt_wq); + status =wait_event_interruptible (priv->bh_wq, +CW1200_BH_RESUME ==atomic_read ( + &priv->bh_suspend)); +if (status <0 ) { +wiphy_err (priv->hw->wiphy, +"%s: Failed to wait for resume: %ld.\n" , + __func__, status); +break ; + } +pr_debug ("[BH] Device resume.\n" ); +atomic_set (&priv->bh_suspend,CW1200_BH_RESUMED ); +wake_up (&priv->bh_evt_wq); +atomic_add (1 , &priv->bh_rx); + goto done; + } + + rx: + tx += pending_tx; + pending_tx =0 ; + +if (cw1200_bh_read_ctrl_reg (priv, &ctrl_reg)) +break ; + +/* Don't bother trying to rx unless we have data to read */ +if (ctrl_reg &ST90TDS_CONT_NEXT_LEN_MASK ) { + ret =cw1200_bh_rx_helper (priv, &ctrl_reg, &tx); +if (ret <0 ) +break ; +/* Double up here if there's more data.. */ +if (ctrl_reg &ST90TDS_CONT_NEXT_LEN_MASK ) { + ret =cw1200_bh_rx_helper (priv, &ctrl_reg, &tx); +if (ret <0 ) +break ; + } + } + + tx: +if (tx) { + tx =0 ; + +BUG_ON (priv->hw_bufs_used > priv->wsm_caps.numInpChBufs); + tx_burst = priv->wsm_caps.numInpChBufs - priv->hw_bufs_used; + tx_allowed = tx_burst >0 ; + +if (!tx_allowed) { +/* Buffers full. Ensure we process tx after we handle rx.. */ + pending_tx = tx; + goto done_rx; + } + ret =cw1200_bh_tx_helper (priv, &pending_tx, &tx_burst); +if (ret <0 ) +break ; +if (ret >0 )/* More to transmit */ + tx = ret; + +/* Re-read ctrl reg */ +if (cw1200_bh_read_ctrl_reg (priv, &ctrl_reg)) +break ; + } + + done_rx: +if (priv->bh_error) +break ; +if (ctrl_reg &ST90TDS_CONT_NEXT_LEN_MASK ) + goto rx; +if (tx) + goto tx; + + done: +/* Re-enable device interrupts */ + priv->sbus_ops->lock (priv->sbus_priv); +__cw1200_irq_enable (priv,1 ); + priv->sbus_ops->unlock (priv->sbus_priv); + } + +/* Explicitly disable device interrupts */ + priv->sbus_ops->lock (priv->sbus_priv); +__cw1200_irq_enable (priv,0 ); + priv->sbus_ops->unlock (priv->sbus_priv); + +if (!term) { +pr_err ("[BH] Fatal error, exiting.\n" ); + priv->bh_error =1 ; +/* TODO: schedule_work(recovery) */ +#ifdef CW1200_USE_COMPAT_KTHREAD +#ifndef CW1200_NO_PUT_TASK_STRUCT +put_task_struct (priv->bh_thread); +#else +for (;;) { +int status =wait_event_interruptible (priv->bh_wq, ({ + term =atomic_xchg (&priv->bh_term,0 ); + (term); + })); +if (status || term) +break ; + } +#endif +#endif + } +return 0 ; +}
drivers/net/wireless/cw1200/bh.h new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Device handling thread interface for mac80211 ST-Ericsson CW1200 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef CW1200_BH_H +#define CW1200_BH_H + +/* extern */ struct cw1200_common ; + +int cw1200_register_bh (struct cw1200_common *priv); +void cw1200_unregister_bh (struct cw1200_common *priv); +void cw1200_irq_handler (struct cw1200_common *priv); +void cw1200_bh_wakeup (struct cw1200_common *priv); +int cw1200_bh_suspend (struct cw1200_common *priv); +int cw1200_bh_resume (struct cw1200_common *priv); +/* Must be called from BH thread. */ +void cw1200_enable_powersave (struct cw1200_common *priv, +bool enable); +int wsm_release_tx_buffer (struct cw1200_common *priv,int count); + +#endif /* CW1200_BH_H */
Signature · 1 line
1.8.1.2
PATCH 11/14 cw1200: v4: common state, definitions, and registration handling
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/cw1200.h | 348 +++++++++++++++++++ drivers/net/wireless/cw1200/main.c | 628 +++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/sbus.h | 35 ++ 3 files changed, 1011 insertions(+) create mode 100644 drivers/net/wireless/cw1200/cw1200.h create mode 100644 drivers/net/wireless/cw1200/main.c create mode 100644 drivers/net/wireless/cw1200/sbus.h
drivers/net/wireless/cw1200/cw1200.h new file +348 -0
@@ -0,0 +1,348 @@ +/* +* Common private data for ST-Ericsson CW1200 drivers +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* Based on the mac80211 Prism54 code, which is +* Copyright (c) 2006, Michael Wu <[email protected]> +* +* Based on the islsm (softmac prism54) driver, which is: +* Copyright 2004-2006 Jean-Baptiste Note <[email protected]>, et al. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef CW1200_H +#define CW1200_H + +#include <linux/wait.h> +#include <linux/version.h> +#include <linux/mutex.h> +#include <linux/workqueue.h> +#include <net/mac80211.h> + +#include "queue.h" +#include "wsm.h" +#include "scan.h" +#include "txrx.h" +#include "pm.h" + +#if (LINUX_VERSION_CODE <KERNEL_VERSION (2 ,6 ,36 )) +#define CW1200_USE_COMPAT_KTHREAD +#endif +#if (LINUX_VERSION_CODE <KERNEL_VERSION (2 ,6 ,39 )) +#define CW1200_NO_PUT_TASK_STRUCT +#endif + +/* Forward declarations */ +struct sbus_ops ; +struct task_struct ; +struct cw1200_debug_priv ; +struct firmware ; + +#ifdef CONFIG_CW1200_ETF +extern int etf_mode; +extern char *etf_firmware; +#endif + +#define CW1200_MAX_CTRL_FRAME_LEN (0x1000) + +#define CW1200_MAX_STA_IN_AP_MODE (5) +#define CW1200_LINK_ID_AFTER_DTIM (CW1200_MAX_STA_IN_AP_MODE + 1) +#define CW1200_LINK_ID_UAPSD (CW1200_MAX_STA_IN_AP_MODE + 2) +#define CW1200_LINK_ID_MAX (CW1200_MAX_STA_IN_AP_MODE + 3) +#define CW1200_MAX_REQUEUE_ATTEMPTS (5) + +#define CW1200_MAX_TID (8) + +#define CW1200_BLOCK_ACK_CNT (30) +#define CW1200_BLOCK_ACK_THLD (800) +#define CW1200_BLOCK_ACK_HIST (3) +#define CW1200_BLOCK_ACK_INTERVAL (1 * HZ / CW1200_BLOCK_ACK_HIST) + +#define CW1200_JOIN_TIMEOUT (1 * HZ) +#define CW1200_AUTH_TIMEOUT (5 * HZ) + +#define BSS_LOSS_CHECKING_MAX_TRY 10 + +struct cw1200_ht_info { +struct ieee80211_sta_ht_cap ht_cap; +enum nl80211_channel_type channel_type; +u16 operation_mode; +}; + +/* Please keep order */ +enum cw1200_join_status { +CW1200_JOIN_STATUS_PASSIVE =0 , +CW1200_JOIN_STATUS_MONITOR , +CW1200_JOIN_STATUS_JOINING , +CW1200_JOIN_STATUS_PRE_STA , +CW1200_JOIN_STATUS_STA , +CW1200_JOIN_STATUS_AP , +}; + +enum cw1200_link_status { +CW1200_LINK_OFF , +CW1200_LINK_RESERVE , +CW1200_LINK_SOFT , +CW1200_LINK_HARD , +CW1200_LINK_RESET , +CW1200_LINK_RESET_REMAP , +}; + +enum cw1200_bss_loss_status { +CW1200_BSS_LOSS_NONE , +CW1200_BSS_LOSS_CHECKING , +CW1200_BSS_LOSS_CONFIRMING , +CW1200_BSS_LOSS_CONFIRMED , +}; + +extern int cw1200_power_mode; + +struct cw1200_link_entry { +unsigned long timestamp; +enum cw1200_link_status status; +enum cw1200_link_status prev_status; +u8 mac[ETH_ALEN ]; +u8 buffered[CW1200_MAX_TID ]; +struct sk_buff_head rx_queue; +}; + +struct cw1200_common { +/* interfaces to the rest of the stack */ +struct ieee80211_hw *hw; +struct ieee80211_vif *vif; +struct device *pdev; + +/* Statistics */ +struct ieee80211_low_level_stats stats; + +/* Our macaddr */ +u8 mac_addr[ETH_ALEN ]; + +/* Hardware interface */ +const struct sbus_ops *sbus_ops; +struct sbus_priv *sbus_priv; + +/* Hardware information */ +int hw_type; +int hw_revision; +int hw_refclk; +bool hw_have_5ghz; +const struct firmware *sdd; +char *sdd_path; + +struct cw1200_debug_priv *debug; + +struct workqueue_struct *workqueue; +struct mutex conf_mutex; + +struct cw1200_queue tx_queue[4 ]; +struct cw1200_queue_stats tx_queue_stats; +int tx_burst_idx; + +/* firmware/hardware info */ +unsigned int tx_hdr_len; + +/* Radio data */ +int output_power; + +/* BBP/MAC state */ +struct ieee80211_rate *rates; +struct ieee80211_rate *mcs_rates; +struct ieee80211_channel *channel; +struct wsm_edca_params edca; +struct wsm_tx_queue_params tx_queue_params; +struct wsm_association_mode association_mode; +struct wsm_set_bss_params bss_params; +struct cw1200_ht_info ht_info; +struct wsm_set_pm powersave_mode; +struct wsm_set_pm firmware_ps_mode; +int cqm_rssi_thold; +unsigned cqm_rssi_hyst; +bool cqm_use_rssi; +int cqm_beacon_loss_count; +int channel_switch_in_progress; +wait_queue_head_t channel_switch_done; +u8 long_frame_max_tx_count; +u8 short_frame_max_tx_count; +int mode; +bool enable_beacon; +int beacon_int; +bool listening; +struct wsm_rx_filter rx_filter; +struct wsm_beacon_filter_table bf_table; +struct wsm_beacon_filter_control bf_control; +struct wsm_multicast_filter multicast_filter; +bool has_multicast_subscription; +bool disable_beacon_filter; +struct work_struct update_filtering_work; +struct work_struct set_beacon_wakeup_period_work; + +u8 ba_rx_tid_mask; +u8 ba_tx_tid_mask; + +struct cw1200_pm_state pm_state; + +struct wsm_p2p_ps_modeinfo p2p_ps_modeinfo; +struct wsm_uapsd_info uapsd_info; +bool setbssparams_done; +bool is_BT_Present; +u8 conf_listen_interval; +u32 listen_interval; +u32 erp_info; +u32 rts_threshold; + +/* BH */ +atomic_t bh_rx; +atomic_t bh_tx; +atomic_t bh_term; +atomic_t bh_suspend; + +#ifdef CW1200_USE_COMPAT_KTHREAD +struct task_struct *bh_thread; +#else +struct workqueue_struct *bh_workqueue; +struct work_struct bh_work; +#endif + +int bh_error; +wait_queue_head_t bh_wq; +wait_queue_head_t bh_evt_wq; +int buf_id_tx;/* byte */ +int buf_id_rx;/* byte */ +int wsm_rx_seq;/* byte */ +int wsm_tx_seq;/* byte */ +int hw_bufs_used; +bool powersave_enabled; +bool device_can_sleep; + +/* Keep cw1200 awake (WUP = 1) 1 second after each scan to avoid +* FW issue with sleeping/waking up. */ +atomic_t recent_scan; +struct delayed_work clear_recent_scan_work; + +/* WSM */ +struct wsm_caps wsm_caps; +struct mutex wsm_cmd_mux; +struct wsm_buf wsm_cmd_buf; +struct wsm_cmd wsm_cmd; +wait_queue_head_t wsm_cmd_wq; +wait_queue_head_t wsm_startup_done; +struct wsm_cbc wsm_cbc; +atomic_t tx_lock; + +/* WSM debug */ +int wsm_enable_wsm_dumps; + +/* Scan status */ +struct cw1200_scan scan; + +/* WSM Join */ +enum cw1200_join_status join_status; +u8 join_bssid[ETH_ALEN ]; +u32 pending_frame_id; +bool join_pending; +struct work_struct join_work; +struct delayed_work join_timeout; +struct work_struct unjoin_work; +struct work_struct offchannel_work; +struct work_struct join_complete_work; +int join_complete_status; +int join_dtim_period; +bool delayed_unjoin; + +/* TX/RX and security */ +s8 wep_default_key_id; +struct work_struct wep_key_work; +u32 key_map; +struct wsm_add_key keys[WSM_KEY_MAX_INDEX +1 ]; +unsigned long rx_timestamp; + +/* AP powersave */ +u32 link_id_map; +struct cw1200_link_entry link_id_db[CW1200_MAX_STA_IN_AP_MODE ]; +struct work_struct link_id_work; +struct delayed_work link_id_gc_work; +u32 sta_asleep_mask; +u32 pspoll_mask; +bool aid0_bit_set; +spinlock_t ps_state_lock; +bool buffered_multicasts; +bool tx_multicast; +struct work_struct set_tim_work; +struct work_struct set_cts_work; +struct work_struct multicast_start_work; +struct work_struct multicast_stop_work; +struct timer_list mcast_timeout; + +/* WSM events and CQM implementation */ +spinlock_t event_queue_lock; +struct list_head event_queue; +struct work_struct event_handler; +struct delayed_work bss_loss_work; +struct delayed_work connection_loss_work; +int delayed_link_loss; +spinlock_t bss_loss_lock; +int bss_loss_status; +int bss_loss_checking; +int bss_loss_confirm_id; + +/* TX rate policy cache */ +struct tx_policy_cache tx_policy_cache; +struct work_struct tx_policy_upload_work; + +/* legacy PS mode switch in suspend */ +int ps_mode_switch_in_progress; +wait_queue_head_t ps_mode_switch_done; + +/* Workaround for WFD testcase 6.1.10*/ +struct work_struct linkid_reset_work; +u8 action_frame_sa[ETH_ALEN ]; +u8 action_linkid; + +#ifdef CONFIG_CW1200_ETF +struct sk_buff_head etf_q; +#endif + +}; + +struct cw1200_sta_priv { +int link_id; +}; + +/* interfaces for the drivers */ +int cw1200_core_probe (const struct sbus_ops *sbus_ops, +struct sbus_priv *sbus, +struct device *pdev, +struct cw1200_common **pself, +int ref_clk,const u8 *macaddr, +const char *sdd_path,bool have_5ghz); +void cw1200_core_release (struct cw1200_common *self); + +#define FWLOAD_BLOCK_SIZE (1024) + +static inline int cw1200_is_ht (const struct cw1200_ht_info *ht_info) +{ +return ht_info->channel_type !=NL80211_CHAN_NO_HT ; +} + +static inline int cw1200_ht_greenfield (const struct cw1200_ht_info *ht_info) +{ +return cw1200_is_ht (ht_info) && + (ht_info->ht_cap.cap &IEEE80211_HT_CAP_GRN_FLD ) && + !(ht_info->operation_mode & +IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT ); +} + +static inline int cw1200_ht_ampdu_density (const struct cw1200_ht_info *ht_info) +{ +if (!cw1200_is_ht (ht_info)) +return 0 ; +return ht_info->ht_cap.ampdu_density; +} + +#endif /* CW1200_H */
drivers/net/wireless/cw1200/main.c new file +628 -0
628 lines not on this page · raw message
drivers/net/wireless/cw1200/sbus.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Common sbus abstraction layer interface for cw1200 wireless driver +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef CW1200_SBUS_H +#define CW1200_SBUS_H + +/* +* sbus priv forward definition. +* Implemented and instantiated in particular modules. +*/ +struct sbus_priv ; + +void cw1200_irq_handler (struct cw1200_common *priv); +int __cw1200_irq_enable (struct cw1200_common *priv,int enable);/* Must be wrapped with sbus_ops->lock/unlock! */ + +struct sbus_ops { +int (*sbus_memcpy_fromio)(struct sbus_priv *self,unsigned int addr, +void *dst,int count); +int (*sbus_memcpy_toio)(struct sbus_priv *self,unsigned int addr, +const void *src,int count); +void (*lock)(struct sbus_priv *self); +void (*unlock)(struct sbus_priv *self); +size_t (*align_size)(struct sbus_priv *self,size_t size); +int (*power_mgmt)(struct sbus_priv *self,bool suspend); +}; + +#endif /* CW1200_SBUS_H */
Signature · 1 line
1.8.1.2
PATCH 12/14 cw1200: v4: SDIO and SPI glue code and platform definitions
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/cw1200_sdio.c | 486 +++++++++++++++++++++++++++ drivers/net/wireless/cw1200/cw1200_spi.c | 529 ++++++++++++++++++++++++++++++ include/linux/cw1200_platform.h | 44 +++ 3 files changed, 1059 insertions(+) create mode 100644 drivers/net/wireless/cw1200/cw1200_sdio.c create mode 100644 drivers/net/wireless/cw1200/cw1200_spi.c create mode 100644 include/linux/cw1200_platform.h
drivers/net/wireless/cw1200/cw1200_sdio.c new file +486 -0
@@ -0,0 +1,486 @@ +/* +* Mac80211 SDIO driver for ST-Ericsson CW1200 device +* +* Copyright (c) 2010, ST-Ericsson +* Author: Dmitry Tarnyagin <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#include <linux/version.h> +#include <linux/module.h> +#include <linux/gpio.h> +#include <linux/delay.h> +#include <linux/mmc/host.h> +#include <linux/mmc/sdio_func.h> +#include <linux/mmc/card.h> +#include <linux/mmc/sdio.h> +#include <net/mac80211.h> + +#include "cw1200.h" +#include "sbus.h" +#include <linux/cw1200_platform.h> +#include "hwio.h" + +MODULE_AUTHOR ("Dmitry Tarnyagin <[email protected]>" ); +MODULE_DESCRIPTION ("mac80211 ST-Ericsson CW1200 SDIO driver" ); +MODULE_LICENSE ("GPL" ); + +#define SDIO_BLOCK_SIZE (512) + +#define USE_INTERNAL_RESOURCE_LIST +/* XXX The intent is that this info is part of the board platform data in arch/mach-xxxx/mach-yyyy.c -- listed here for convenience.. */ + +/* Declaration only. Should be implemented in arch/xxx/mach-yyy */ +const struct cw1200_platform_data_sdio *cw1200_get_platform_data (void ); + +#ifdef USE_INTERNAL_RESOURCE_LIST +#if 0 +static struct resource cw1200_href_resources[] = { + { + .start =215 ,/* fix me as appropriate */ + .end =215 ,/* ditto */ + .flags =IORESOURCE_IO , + .name ="cw1200_wlan_reset" , + }, + { + .start =216 ,/* fix me as appropriate */ + .end =216 ,/* ditto */ + .flags =IORESOURCE_IO , + .name ="cw1200_wlan_powerup" , + }, + { + .start =NOMADIK_GPIO_TO_IRQ (216 ),/* fix me as appropriate */ + .end =NOMADIK_GPIO_TO_IRQ (216 ),/* ditto */ + .flags =IORESOURCE_IRQ , + .name ="cw1200_wlan_irq" , + }, +}; +#endif + +static int cw1200_power_ctrl (const struct cw1200_platform_data_sdio *pdata, +bool enable) +{ +/* Control 3v3 and 1v8 to hardware as appropriate */ +/* Note this is not needed if it's controlled elsewhere or always on */ + +/* May require delay for power to stabilize */ +return 0 ; +} + +static int cw1200_clk_ctrl (const struct cw1200_platform_data_sdio *pdata, +bool enable) +{ +/* Turn CLK_32K off and on as appropriate. */ +/* Note this is not needed if it's always on */ + +/* May require delay for clock to stabilize */ +return 0 ; +} + +static struct cw1200_platform_data_sdio cw1200_platform_data = { + .ref_clk =38400 , + .have_5ghz = false, +#if 0 + .reset = &cw1200_href_resources[0 ], + .powerup = &cw1200_href_resources[1 ], + .irq = &cw1200_href_resources[2 ], +#endif + .power_ctrl = cw1200_power_ctrl, + .clk_ctrl = cw1200_clk_ctrl, +/* .macaddr = ??? */ + .sdd_file ="sdd_sagrad_1091_1098.bin" , +}; + +const struct cw1200_platform_data_sdio *cw1200_get_platform_data (void ) +{ +return &cw1200_platform_data; +} +EXPORT_SYMBOL_GPL (cw1200_get_platform_data); +#endif + +struct sbus_priv { +struct sdio_func *func; +struct cw1200_common *core; +const struct cw1200_platform_data_sdio *pdata; +}; + +#ifndef SDIO_VENDOR_ID_STE +#define SDIO_VENDOR_ID_STE 0x0020 +#endif + +#ifndef SDIO_DEVICE_ID_STE_CW1200 +#define SDIO_DEVICE_ID_STE_CW1200 0x2280 +#endif + +static const struct sdio_device_id cw1200_sdio_ids[] = { + {SDIO_DEVICE (SDIO_VENDOR_ID_STE ,SDIO_DEVICE_ID_STE_CW1200 ) }, + {/* end: all zeroes */ }, +}; + +/* sbus_ops implemetation */ + +static int cw1200_sdio_memcpy_fromio (struct sbus_priv *self, +unsigned int addr, +void *dst,int count) +{ +return sdio_memcpy_fromio (self->func, dst, addr, count); +} + +static int cw1200_sdio_memcpy_toio (struct sbus_priv *self, +unsigned int addr, +const void *src,int count) +{ +return sdio_memcpy_toio (self->func, addr, (void *)src, count); +} + +static void cw1200_sdio_lock (struct sbus_priv *self) +{ +sdio_claim_host (self->func); +} + +static void cw1200_sdio_unlock (struct sbus_priv *self) +{ +sdio_release_host (self->func); +} + +static void cw1200_sdio_irq_handler (struct sdio_func *func) +{ +struct sbus_priv *self =sdio_get_drvdata (func); + +/* note: sdio_host already claimed here. */ +if (self->core) +cw1200_irq_handler (self->core); +} + +static irqreturn_t cw1200_gpio_hardirq (int irq,void *dev_id) +{ +return IRQ_WAKE_THREAD ; +} + +static irqreturn_t cw1200_gpio_irq (int irq,void *dev_id) +{ +struct sbus_priv *self = dev_id; + +if (self->core) { +sdio_claim_host (self->func); +cw1200_irq_handler (self->core); +sdio_release_host (self->func); +return IRQ_HANDLED ; + }else { +return IRQ_NONE ; + } +} + +static int cw1200_request_irq (struct sbus_priv *self) +{ +int ret; +const struct resource *irq = self->pdata->irq; +u8 cccr; + + cccr =sdio_f0_readb (self->func, SDIO_CCCR_IENx, &ret); +if (WARN_ON (ret)) + goto err; + +/* Master interrupt enable ... */ + cccr |=BIT (0 ); + +/* ... for our function */ + cccr |=BIT (self->func->num); + +sdio_f0_writeb (self->func, cccr, SDIO_CCCR_IENx, &ret); +if (WARN_ON (ret)) + goto err; + + ret =enable_irq_wake (irq->start); +if (WARN_ON (ret)) + goto err; + +/* Request the IRQ */ + ret =request_threaded_irq (irq->start, cw1200_gpio_hardirq, + cw1200_gpio_irq, +IRQF_TRIGGER_HIGH |IRQF_ONESHOT , + irq->name, self); +if (WARN_ON (ret)) + goto err; + +return 0 ; + +err: +return ret; +} + +static int cw1200_sdio_irq_subscribe (struct sbus_priv *self) +{ +int ret =0 ; + +pr_debug ("SW IRQ subscribe\n" ); +sdio_claim_host (self->func); +if (self->pdata->irq) + ret =cw1200_request_irq (self); +else + ret =sdio_claim_irq (self->func, cw1200_sdio_irq_handler); + +sdio_release_host (self->func); +return ret; +} + +static int cw1200_sdio_irq_unsubscribe (struct sbus_priv *self) +{ +int ret =0 ; + +pr_debug ("SW IRQ unsubscribe\n" ); + +if (self->pdata->irq) { +disable_irq_wake (self->pdata->irq->start); +free_irq (self->pdata->irq->start, self); + }else { +sdio_claim_host (self->func); + ret =sdio_release_irq (self->func); +sdio_release_host (self->func); + } +return ret; +} + +static int cw1200_sdio_off (const struct cw1200_platform_data_sdio *pdata) +{ +const struct resource *reset = pdata->reset; + +if (reset) { +gpio_set_value (reset->start,0 ); +msleep (30 );/* Min is 2 * CLK32K cycles */ +gpio_free (reset->start); + } + +if (pdata->power_ctrl) + pdata->power_ctrl (pdata, false); +if (pdata->clk_ctrl) + pdata->clk_ctrl (pdata, false); + +return 0 ; +} + +static int cw1200_sdio_on (const struct cw1200_platform_data_sdio *pdata) +{ +const struct resource *reset = pdata->reset; +const struct resource *powerup = pdata->reset; + +/* Ensure I/Os are pulled low */ +if (reset) { +gpio_request (reset->start, reset->name); +gpio_direction_output (reset->start,0 ); + } +if (powerup) { +gpio_request (powerup->start, powerup->name); +gpio_direction_output (powerup->start,0 ); + } +if (reset || powerup) +msleep (50 );/* Settle time */ + +/* Enable 3v3 and 1v8 to hardware */ +if (pdata->power_ctrl) { +if (pdata->power_ctrl (pdata, true)) { +pr_err ("power_ctrl() failed!\n" ); +return -1 ; + } + } + +/* Enable CLK32K */ +if (pdata->clk_ctrl) { +if (pdata->clk_ctrl (pdata, true)) { +pr_err ("clk_ctrl() failed!\n" ); +return -1 ; + } +msleep (10 );/* Delay until clock is stable for 2 cycles */ + } + +/* Enable POWERUP signal */ +if (powerup) { +gpio_set_value (powerup->start,1 ); +msleep (250 );/* or more..? */ + } +/* Enable RSTn signal */ +if (reset) { +gpio_set_value (reset->start,1 ); +msleep (50 );/* Or more..? */ + } +return 0 ; +} + +static size_t cw1200_sdio_align_size (struct sbus_priv *self,size_t size) +{ +if (self->pdata->no_nptb) + size =round_up (size,SDIO_BLOCK_SIZE ); +else + size =sdio_align_size (self->func, size); + +#if (LINUX_VERSION_CODE <KERNEL_VERSION (3 ,2 ,0 )) +/* A quirk to handle this was committed in 3.2-rc */ +if (size ==SDIO_BLOCK_SIZE ) + size +=SDIO_BLOCK_SIZE ;/* HW bug; force use of block mode */ +#endif + +return size; +} + +static int cw1200_sdio_pm (struct sbus_priv *self,bool suspend) +{ +int ret =0 ; + +if (self->pdata->irq) + ret =irq_set_irq_wake (self->pdata->irq->start, suspend); +return ret; +} + +static struct sbus_ops cw1200_sdio_sbus_ops = { + .sbus_memcpy_fromio = cw1200_sdio_memcpy_fromio, + .sbus_memcpy_toio = cw1200_sdio_memcpy_toio, + .lock = cw1200_sdio_lock, + .unlock = cw1200_sdio_unlock, + .align_size = cw1200_sdio_align_size, + .power_mgmt = cw1200_sdio_pm, +}; + +/* Probe Function to be called by SDIO stack when device is discovered */ +static int cw1200_sdio_probe (struct sdio_func *func, +const struct sdio_device_id *id) +{ +struct sbus_priv *self; +int status; + +pr_info ("cw1200_wlan_sdio: Probe called\n" ); + +/* We are only able to handle the wlan function */ +if (func->num !=0x01 ) +return -ENODEV ; + + self =kzalloc (sizeof (*self),GFP_KERNEL ); +if (!self) { +pr_err ("Can't allocate SDIO sbus_priv.\n" ); +return -ENOMEM ; + } + + func->card->quirks |=MMC_QUIRK_LENIENT_FN0 ; + + self->pdata =cw1200_get_platform_data (); + self->func = func; +sdio_set_drvdata (func, self); +sdio_claim_host (func); +sdio_enable_func (func); +sdio_release_host (func); + + status =cw1200_sdio_irq_subscribe (self); + + status =cw1200_core_probe (&cw1200_sdio_sbus_ops, + self, &func->dev, &self->core, + self->pdata->ref_clk, + self->pdata->macaddr, + self->pdata->sdd_file, + self->pdata->have_5ghz); +if (status) { +cw1200_sdio_irq_unsubscribe (self); +sdio_claim_host (func); +sdio_disable_func (func); +sdio_release_host (func); +sdio_set_drvdata (func,NULL ); +kfree (self); + } + +return status; +} + +/* Disconnect Function to be called by SDIO stack when +* device is disconnected */ +static void cw1200_sdio_disconnect (struct sdio_func *func) +{ +struct sbus_priv *self =sdio_get_drvdata (func); + +if (self) { +cw1200_sdio_irq_unsubscribe (self); +if (self->core) { +cw1200_core_release (self->core); + self->core =NULL ; + } +sdio_claim_host (func); +sdio_disable_func (func); +sdio_release_host (func); +sdio_set_drvdata (func,NULL ); +kfree (self); + } +} + +static int cw1200_sdio_suspend (struct device *dev) +{ +int ret; +struct sdio_func *func =dev_to_sdio_func (dev); +struct sbus_priv *self =sdio_get_drvdata (func); + +if (!cw1200_can_suspend (self->core)) +return -EAGAIN ; + +/* Notify SDIO that CW1200 will remain powered during suspend */ + ret =sdio_set_host_pm_flags (func,MMC_PM_KEEP_POWER ); +if (ret) +pr_err ("Error setting SDIO pm flags: %i\n" , ret); + +return ret; +} + +static int cw1200_sdio_resume (struct device *dev) +{ +return 0 ; +} + +static const struct dev_pm_ops cw1200_pm_ops = { + .suspend = cw1200_sdio_suspend, + .resume = cw1200_sdio_resume, +}; + +static struct sdio_driver sdio_driver = { + .name ="cw1200_wlan_sdio" , + .id_table = cw1200_sdio_ids, + .probe = cw1200_sdio_probe, + .remove = cw1200_sdio_disconnect, + .drv = { + .pm = &cw1200_pm_ops, + } +}; + +/* Init Module function -> Called by insmod */ +static int __init cw1200_sdio_init (void ) +{ +const struct cw1200_platform_data_sdio *pdata; +int ret; + + pdata =cw1200_get_platform_data (); + +if (cw1200_sdio_on (pdata)) { + ret =-1 ; + goto err; + } + + ret =sdio_register_driver (&sdio_driver); +if (ret) + goto err; + +return 0 ; + +err: +cw1200_sdio_off (pdata); +return ret; +} + +/* Called at Driver Unloading */ +static void __exit cw1200_sdio_exit(void) +{ +const struct cw1200_platform_data_sdio *pdata; + pdata =cw1200_get_platform_data (); +sdio_unregister_driver (&sdio_driver); +cw1200_sdio_off (pdata); +} + + +module_init (cw1200_sdio_init); +module_exit (cw1200_sdio_exit);
drivers/net/wireless/cw1200/cw1200_spi.c new file +529 -0
529 lines not on this page · raw message
include/linux/cw1200_platform.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
1.8.1.2
PATCH 13/14 cw1200: v4: Kbuild integration
In reply to Solomon Peachy--- drivers/net/wireless/cw1200/Kconfig | 38 ++++++++++++++++++++++++++++++++++++ drivers/net/wireless/cw1200/Makefile | 22 +++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 drivers/net/wireless/cw1200/Kconfig create mode 100644 drivers/net/wireless/cw1200/Makefile
drivers/net/wireless/cw1200/Kconfig new file +38 -0
@@ -0,0 +1,38 @@ +config CW1200 + tristate "CW1200 WLAN support" + depends on MAC80211 && CFG80211 + help + This is driver for the ST-E CW1100 & CW1200 WLAN chipsets. + This option just enables the driver core, see below for + specific bus support. + +if CW1200 + +config CW1200_WLAN_SDIO + tristate "Support SDIO platforms" + depends on CW1200 && MMC + help + This enables support for the CW1200 via an SDIO bus. + +config CW1200_WLAN_SPI + tristate "Support SPI platforms" + depends on CW1200 && SPI + help + This enables support for the CW1200 via a SPI bus. + +menu "Driver debug features" + depends on CW1200 && DEBUGFS + +config CW1200_ETF + bool "Enable CW1200 Engineering Test Framework hooks" + help + If you don't know what this is, just say N. + +config CW1200_ITP + bool "Enable ITP access" + help + If you don't know what this is, just say N. + +endmenu + +endif
drivers/net/wireless/cw1200/Makefile new file +22 -0
@@ -0,0 +1,22 @@ +cw1200_core-y := \ + fwio.o \ + txrx.o \ + main.o \ + queue.o \ + hwio.o \ + bh.o \ + wsm.o \ + sta.o \ + scan.o \ + pm.o \ + debug.o +cw1200_core-$(CONFIG_CW1200_ITP) += itp.o + +cw1200_wlan_sdio-y := cw1200_sdio.o +cw1200_wlan_spi-y := cw1200_spi.o + +obj-$(CONFIG_CW1200) += cw1200_core.o +obj-$(CONFIG_CW1200_WLAN_SDIO) += cw1200_wlan_sdio.o +obj-$(CONFIG_CW1200_WLAN_SPI) += cw1200_wlan_spi.o + +
Signature · 1 line
1.8.1.2
PATCH 14/14 cw1200: v4: Add to drivers/net/wireless kbuild, plus MAINTAINERS entry.
In reply to Solomon Peachy--- MAINTAINERS | 5 +++++ drivers/net/wireless/Kconfig | 1 + drivers/net/wireless/Makefile | 3 +++ 3 files changed, 9 insertions(+)
MAINTAINERS +5 -0
@@ -2187,6 +2187,11 @@ M: Jaya Kumar <[email protected]> S: Maintained F: sound/pci/cs5535audio/ +CW1200 WLAN driver +M: Solomon Peachy <[email protected]> +S: Maintained +F: drivers/net/wireless/cw1200/ + CX18 VIDEO4LINUX DRIVER M: Andy Walls <[email protected]> L: [email protected] (moderated for non-subscribers)
drivers/net/wireless/Kconfig +1 -0
@@ -280,5 +280,6 @@ source "drivers/net/wireless/rtlwifi/Kconfig" source "drivers/net/wireless/ti/Kconfig" source "drivers/net/wireless/zd1211rw/Kconfig" source "drivers/net/wireless/mwifiex/Kconfig" +source "drivers/net/wireless/cw1200/Kconfig" endif # WLAN
drivers/net/wireless/Makefile +3 -0
@@ -57,3 +57,6 @@ obj-$(CONFIG_MWIFIEX) += mwifiex/ obj-$(CONFIG_BRCMFMAC) += brcm80211/ obj-$(CONFIG_BRCMSMAC) += brcm80211/ + +obj-$(CONFIG_CW1200) += cw1200/ +
Signature · 1 line
1.8.1.2
Johannes Berg
maintainerQuoted 3 lines · Solomon Peachy
There are still a couple bits of code present for older (<2.6.36 and <3.2) kernels, which I will strip out for inclusion in compat-drivers once this is mainlined. (Is there a better process I should follow here?)
You should probably just submit it without those bits for the wireless-next tree and then to the relevant compat-drivers patches as needed.
johannes
Quoted 7 lines · Johannes Berg
Quoted 3 lines
There are still a couple bits of code present for older (<2.6.36 and <3.2) kernels, which I will strip out for inclusion in compat-drivers once this is mainlined. (Is there a better process I should follow here?)
You should probably just submit it without those bits for the wireless-next tree and then to the relevant compat-drivers patches as needed.
I'm now working on silencing checkpatch's complaints (about 3/4 done now); most of them revolve around the use of CamelCase variable names all over the place. In the process I'm doing other low-risk opportunistic cleanups.
Once I'm done with that, I'll prepare another submission without the backwards compability bits, rebased against wireless-next.
- Solomon
Signature · 3 lines
Solomon Peachy pizza at shaftnet dot org Melbourne, FL ^^ (mail/jabber/gtalk) ^^ Quidquid latine dictum sit, altum viditur.
2013/2/14 Solomon Peachy <[email protected]>:
Quoted 14 lines · Johannes Berg
Quoted 7 lines
Quoted 3 lines
There are still a couple bits of code present for older (<2.6.36 and <3.2) kernels, which I will strip out for inclusion in compat-drivers once this is mainlined. (Is there a better process I should follow here?)
You should probably just submit it without those bits for the wireless-next tree and then to the relevant compat-drivers patches as needed.
I'm now working on silencing checkpatch's complaints (about 3/4 done now); most of them revolve around the use of CamelCase variable names all over the place. In the process I'm doing other low-risk opportunistic cleanups.
Quoted 5 lines
Once I'm done with that, I'll prepare another submission without the backwards compability bits, rebased against wireless-next.
- Solomon
--
Hi Salomon,
Is the upstream process dropped or you plan to continue in the near future?
-Bartosz
Quoted 1 line · Bartosz Markowski
Is the upstream process dropped or you plan to continue in the near future?
At least as far as I'm concerned, the upstreaming process is still ongoing. The last major holdup from that perspective was the voluminious pile of checkpatch warnings.
There's also been a surprising amount of non-trivial development going on too, and I wanted to take the time to let the testing shake loose bugs.
Over the past two weeks I've been distracted with other goings-on, but that's all sorted now and I expect to be able to submit another patch set by Friday.
- Solomon
Signature · 3 lines
Solomon Peachy pizza at shaftnet dot org Melbourne, FL ^^ (mail/jabber/gtalk) ^^ Quidquid latine dictum sit, altum viditur.