Skip to content

Commit

Permalink
cw1200: Fix up a large pile of sparse warnings
Browse files Browse the repository at this point in the history
Most of these relate to endianness problems, and are purely cosmetic.

But a couple of them were legit -- listen interval parsing and some of
the rate selection code would malfunction on BE systems.

There's still one cosmetic warning remaining, in the (admittedly) ugly
code in cw1200_spi.c.  It's there because the hardware needs 16-bit SPI
transfers, but many SPI controllers only operate 8 bits at a time.

If there's a cleaner way of handling this, I'm all ears.

Signed-off-by: Solomon Peachy <pizza@shaftnet.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Solomon Peachy authored and John W. Linville committed Jun 24, 2013
1 parent 5d9e3bc commit 7258416
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 97 deletions.
2 changes: 1 addition & 1 deletion drivers/net/wireless/cw1200/cw1200.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ struct cw1200_common {
struct delayed_work bss_loss_work;
spinlock_t bss_loss_lock; /* Protect BSS loss state */
int bss_loss_state;
int bss_loss_confirm_id;
u32 bss_loss_confirm_id;
int delayed_link_loss;
struct work_struct bss_params_work;

Expand Down
32 changes: 20 additions & 12 deletions drivers/net/wireless/cw1200/cw1200_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ static int cw1200_spi_memcpy_fromio(struct hwbus_priv *self,
void *dst, int count)
{
int ret, i;
uint16_t regaddr;
u16 regaddr;
struct spi_message m;

struct spi_transfer t_addr = {
Expand All @@ -76,15 +76,18 @@ static int cw1200_spi_memcpy_fromio(struct hwbus_priv *self,
regaddr = (SDIO_TO_SPI_ADDR(addr))<<12;
regaddr |= SET_READ;
regaddr |= (count>>1);
regaddr = cpu_to_le16(regaddr);

#ifdef SPI_DEBUG
pr_info("READ : %04d from 0x%02x (%04x)\n", count, addr,
le16_to_cpu(regaddr));
pr_info("READ : %04d from 0x%02x (%04x)\n", count, addr, regaddr);
#endif

/* Header is LE16 */
regaddr = cpu_to_le16(regaddr);

/* We have to byteswap if the SPI bus is limited to 8b operation
or we are running on a Big Endian system
*/
#if defined(__LITTLE_ENDIAN)
/* We have to byteswap if the SPI bus is limited to 8b operation */
if (self->func->bits_per_word == 8)
#endif
regaddr = swab16(regaddr);
Expand All @@ -104,8 +107,10 @@ static int cw1200_spi_memcpy_fromio(struct hwbus_priv *self,
printk("\n");
#endif

/* We have to byteswap if the SPI bus is limited to 8b operation
or we are running on a Big Endian system
*/
#if defined(__LITTLE_ENDIAN)
/* We have to byteswap if the SPI bus is limited to 8b operation */
if (self->func->bits_per_word == 8)
#endif
{
Expand All @@ -122,7 +127,7 @@ static int cw1200_spi_memcpy_toio(struct hwbus_priv *self,
const void *src, int count)
{
int rval, i;
uint16_t regaddr;
u16 regaddr;
struct spi_transfer t_addr = {
.tx_buf = &regaddr,
.len = sizeof(regaddr),
Expand All @@ -136,20 +141,23 @@ static int cw1200_spi_memcpy_toio(struct hwbus_priv *self,
regaddr = (SDIO_TO_SPI_ADDR(addr))<<12;
regaddr &= SET_WRITE;
regaddr |= (count>>1);
regaddr = cpu_to_le16(regaddr);

#ifdef SPI_DEBUG
pr_info("WRITE: %04d to 0x%02x (%04x)\n", count, addr,
le16_to_cpu(regaddr));
pr_info("WRITE: %04d to 0x%02x (%04x)\n", count, addr, regaddr);
#endif

/* Header is LE16 */
regaddr = cpu_to_le16(regaddr);

/* We have to byteswap if the SPI bus is limited to 8b operation
or we are running on a Big Endian system
*/
#if defined(__LITTLE_ENDIAN)
/* We have to byteswap if the SPI bus is limited to 8b operation */
if (self->func->bits_per_word == 8)
#endif
{
uint16_t *buf = (uint16_t *)src;
regaddr = swab16(regaddr);
regaddr = swab16(regaddr);
for (i = 0; i < ((count + 1) >> 1); i++)
buf[i] = swab16(buf[i]);
}
Expand Down
18 changes: 10 additions & 8 deletions drivers/net/wireless/cw1200/hwio.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,33 @@ static int __cw1200_reg_write(struct cw1200_common *priv, u16 addr,
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);
__le32 tmp;
int i = __cw1200_reg_read(priv, addr, &tmp, sizeof(tmp), 0);
*val = le32_to_cpu(tmp);
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);
__le32 tmp = cpu_to_le32(val);
return __cw1200_reg_write(priv, addr, &tmp, sizeof(tmp), 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);
__le16 tmp;
int i = __cw1200_reg_read(priv, addr, &tmp, sizeof(tmp), 0);
*val = le16_to_cpu(tmp);
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);
__le16 tmp = cpu_to_le16(val);
return __cw1200_reg_write(priv, addr, &tmp, sizeof(tmp), 0);
}

int cw1200_reg_read(struct cw1200_common *priv, u16 addr, void *buf,
Expand Down
31 changes: 16 additions & 15 deletions drivers/net/wireless/cw1200/hwio.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,35 +169,34 @@ int cw1200_reg_write(struct cw1200_common *priv, u16 addr,
static inline int cw1200_reg_read_16(struct cw1200_common *priv,
u16 addr, u16 *val)
{
u32 tmp;
__le32 tmp;
int i;
i = cw1200_reg_read(priv, addr, &tmp, sizeof(tmp));
tmp = le32_to_cpu(tmp);
*val = tmp & 0xffff;
*val = le32_to_cpu(tmp) & 0xfffff;
return i;
}

static inline int cw1200_reg_write_16(struct cw1200_common *priv,
u16 addr, u16 val)
{
u32 tmp = val;
tmp = cpu_to_le32(tmp);
__le32 tmp = cpu_to_le32((u32)val);
return cw1200_reg_write(priv, addr, &tmp, sizeof(tmp));
}

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));
*val = le32_to_cpu(*val);
__le32 tmp;
int i = cw1200_reg_read(priv, addr, &tmp, sizeof(tmp));
*val = le32_to_cpu(tmp);
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));
__le32 tmp = cpu_to_le32(val);
return cw1200_reg_write(priv, addr, &tmp, sizeof(val));
}

int cw1200_indirect_read(struct cw1200_common *priv, u32 addr, void *buf,
Expand All @@ -224,22 +223,24 @@ static inline int cw1200_ahb_read(struct cw1200_common *priv, u32 addr,
static inline int cw1200_apb_read_32(struct cw1200_common *priv,
u32 addr, u32 *val)
{
int i = cw1200_apb_read(priv, addr, val, sizeof(*val));
*val = le32_to_cpu(*val);
__le32 tmp;
int i = cw1200_apb_read(priv, addr, &tmp, sizeof(tmp));
*val = le32_to_cpu(tmp);
return i;
}

static inline int cw1200_apb_write_32(struct cw1200_common *priv,
u32 addr, u32 val)
{
val = cpu_to_le32(val);
return cw1200_apb_write(priv, addr, &val, sizeof(val));
__le32 tmp = cpu_to_le32(val);
return cw1200_apb_write(priv, addr, &tmp, sizeof(val));
}
static inline int cw1200_ahb_read_32(struct cw1200_common *priv,
u32 addr, u32 *val)
{
int i = cw1200_ahb_read(priv, addr, val, sizeof(*val));
*val = le32_to_cpu(*val);
__le32 tmp;
int i = cw1200_ahb_read(priv, addr, &tmp, sizeof(tmp));
*val = le32_to_cpu(tmp);
return i;
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/cw1200/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ static const struct ieee80211_ops cw1200_ops = {
/*.cancel_remain_on_channel = cw1200_cancel_remain_on_channel, */
};

int cw1200_ba_rx_tids = -1;
int cw1200_ba_tx_tids = -1;
static int cw1200_ba_rx_tids = -1;
static int cw1200_ba_tx_tids = -1;
module_param(cw1200_ba_rx_tids, int, 0644);
module_param(cw1200_ba_tx_tids, int, 0644);
MODULE_PARM_DESC(cw1200_ba_rx_tids, "Block ACK RX TIDs");
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/wireless/cw1200/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ int cw1200_queue_get(struct cw1200_queue *queue,
*tx = (struct wsm_tx *)item->skb->data;
*tx_info = IEEE80211_SKB_CB(item->skb);
*txpriv = &item->txpriv;
(*tx)->packet_id = __cpu_to_le32(item->packet_id);
(*tx)->packet_id = item->packet_id;
list_move_tail(&item->head, &queue->pending);
++queue->num_pending;
--queue->link_map_cache[item->txpriv.link_id];
Expand Down
23 changes: 11 additions & 12 deletions drivers/net/wireless/cw1200/sta.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ int cw1200_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
mutex_lock(&priv->conf_mutex);

if (queue < dev->queues) {
old_uapsd_flags = priv->uapsd_info.uapsd_flags;
old_uapsd_flags = le16_to_cpu(priv->uapsd_info.uapsd_flags);

WSM_TX_QUEUE_SET(&priv->tx_queue_params, queue, 0, 0, 0);
ret = wsm_set_tx_queue_params(priv,
Expand All @@ -645,7 +645,7 @@ int cw1200_conf_tx(struct ieee80211_hw *dev, struct ieee80211_vif *vif,
ret = cw1200_set_uapsd_param(priv, &priv->edca);
if (!ret && priv->setbssparams_done &&
(priv->join_status == CW1200_JOIN_STATUS_STA) &&
(old_uapsd_flags != priv->uapsd_info.uapsd_flags))
(old_uapsd_flags != le16_to_cpu(priv->uapsd_info.uapsd_flags)))
ret = cw1200_set_pm(priv, &priv->powersave_mode);
}
} else {
Expand Down Expand Up @@ -1089,18 +1089,18 @@ static int cw1200_parse_sdd_file(struct cw1200_common *priv)
ret = -1;
break;
}
v = le16_to_cpu(*((u16 *)(p + 2)));
v = le16_to_cpu(*((__le16 *)(p + 2)));
if (!v) /* non-zero means this is enabled */
break;

v = le16_to_cpu(*((u16 *)(p + 4)));
v = le16_to_cpu(*((__le16 *)(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)));
u16 clk = le16_to_cpu(*((__le16 *)(p + 2)));
if (clk != priv->hw_refclk)
pr_warn("SDD file doesn't match configured refclk (%d vs %d)\n",
clk, priv->hw_refclk);
Expand Down Expand Up @@ -1785,9 +1785,9 @@ static int cw1200_set_btcoexinfo(struct cw1200_common *priv)
} else {
pr_debug("[STA] STA has non ERP rates\n");
/* B only mode */
arg.internalTxRate = (__ffs(priv->association_mode.basic_rate_set));
arg.internalTxRate = (__ffs(le32_to_cpu(priv->association_mode.basic_rate_set)));
}
arg.nonErpInternalTxRate = (__ffs(priv->association_mode.basic_rate_set));
arg.nonErpInternalTxRate = (__ffs(le32_to_cpu(priv->association_mode.basic_rate_set)));
} else {
/* P2P mode */
arg.internalTxRate = (__ffs(priv->bss_params.operational_rate_set & ~0xF));
Expand Down Expand Up @@ -1908,7 +1908,7 @@ void cw1200_bss_info_changed(struct ieee80211_hw *dev,

if (info->assoc || info->ibss_joined) {
struct ieee80211_sta *sta = NULL;
u32 val = 0;
__le32 htprot = 0;

if (info->dtim_period)
priv->join_dtim_period = info->dtim_period;
Expand All @@ -1935,19 +1935,18 @@ void cw1200_bss_info_changed(struct ieee80211_hw *dev,
/* Non Greenfield stations present */
if (priv->ht_info.operation_mode &
IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT)
val |= WSM_NON_GREENFIELD_STA_PRESENT;
htprot |= cpu_to_le32(WSM_NON_GREENFIELD_STA_PRESENT);

/* Set HT protection method */
val |= (priv->ht_info.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION) << 2;
htprot |= cpu_to_le32((priv->ht_info.operation_mode & IEEE80211_HT_OP_MODE_PROTECTION) << 2);

/* TODO:
* STBC_param.dual_cts
* STBC_param.LSIG_TXOP_FILL
*/

val = cpu_to_le32(val);
wsm_write_mib(priv, WSM_MIB_ID_SET_HT_PROTECTION,
&val, sizeof(val));
&htprot, sizeof(htprot));

priv->association_mode.greenfield =
cw1200_ht_greenfield(&priv->ht_info);
Expand Down
9 changes: 4 additions & 5 deletions drivers/net/wireless/cw1200/txrx.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,24 +599,23 @@ cw1200_tx_h_bt(struct cw1200_common *priv,
} 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))
__be16 *ethertype = (__be16 *)&payload[6];
if (be16_to_cpu(*ethertype) == 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 <
if (le16_to_cpu(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;
mgt_frame->u.assoc_req.listen_interval = cpu_to_le16(priv->listen_interval);
}
}

Expand Down
Loading

0 comments on commit 7258416

Please sign in to comment.