2017-11-07 20:07:50 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2018-08-03 10:56:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2018-06-19 18:44:19 +00:00
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/ip.h>
|
2019-06-26 12:40:52 +00:00
|
|
|
#include "wilc_wfi_cfgoperations.h"
|
2015-10-02 05:22:07 +00:00
|
|
|
#include "wilc_wlan_cfg.h"
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-08-03 10:56:14 +00:00
|
|
|
static inline bool is_wilc1000(u32 id)
|
|
|
|
{
|
2019-04-06 09:45:27 +00:00
|
|
|
return (id & 0xfffff000) == 0x100000;
|
2018-08-03 10:56:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-11 14:12:18 +00:00
|
|
|
static inline void acquire_bus(struct wilc *wilc, enum bus_acquire acquire)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-11-16 14:05:10 +00:00
|
|
|
mutex_lock(&wilc->hif_cs);
|
2018-11-12 05:45:20 +00:00
|
|
|
if (acquire == WILC_BUS_ACQUIRE_AND_WAKEUP)
|
2016-01-25 07:35:06 +00:00
|
|
|
chip_wakeup(wilc);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2015-11-06 02:12:28 +00:00
|
|
|
|
2018-01-11 14:12:19 +00:00
|
|
|
static inline void release_bus(struct wilc *wilc, enum bus_release release)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-11-12 05:45:20 +00:00
|
|
|
if (release == WILC_BUS_RELEASE_ALLOW_SLEEP)
|
2015-11-18 06:11:25 +00:00
|
|
|
chip_allow_sleep(wilc);
|
2015-11-16 14:05:10 +00:00
|
|
|
mutex_unlock(&wilc->hif_cs);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 09:15:23 +00:00
|
|
|
static void wilc_wlan_txq_remove(struct wilc *wilc, struct txq_entry_t *tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-06-04 05:29:07 +00:00
|
|
|
list_del(&tqe->list);
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->txq_entries -= 1;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 03:18:43 +00:00
|
|
|
static struct txq_entry_t *
|
|
|
|
wilc_wlan_txq_remove_from_head(struct net_device *dev)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-06-04 05:29:07 +00:00
|
|
|
struct txq_entry_t *tqe = NULL;
|
2015-05-11 05:30:56 +00:00
|
|
|
unsigned long flags;
|
2018-07-18 22:45:19 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-10-29 03:18:43 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&wilc->txq_spinlock, flags);
|
2015-10-09 04:18:03 +00:00
|
|
|
|
2018-06-04 05:29:07 +00:00
|
|
|
if (!list_empty(&wilc->txq_head.list)) {
|
|
|
|
tqe = list_first_entry(&wilc->txq_head.list, struct txq_entry_t,
|
|
|
|
list);
|
|
|
|
list_del(&tqe->list);
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->txq_entries -= 1;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2015-10-29 03:18:43 +00:00
|
|
|
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
return tqe;
|
|
|
|
}
|
|
|
|
|
2015-10-29 03:18:45 +00:00
|
|
|
static void wilc_wlan_txq_add_to_tail(struct net_device *dev,
|
|
|
|
struct txq_entry_t *tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2018-07-18 22:45:19 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-10-29 03:18:45 +00:00
|
|
|
|
|
|
|
spin_lock_irqsave(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-06-04 05:29:07 +00:00
|
|
|
list_add_tail(&tqe->list, &wilc->txq_head.list);
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->txq_entries += 1;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-10-29 03:18:45 +00:00
|
|
|
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-06-15 05:30:34 +00:00
|
|
|
complete(&wilc->txq_event);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 06:23:22 +00:00
|
|
|
static void wilc_wlan_txq_add_to_head(struct wilc_vif *vif,
|
|
|
|
struct txq_entry_t *tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2016-02-04 09:15:31 +00:00
|
|
|
struct wilc *wilc = vif->wilc;
|
|
|
|
|
2016-06-15 05:30:35 +00:00
|
|
|
mutex_lock(&wilc->txq_add_to_head_cs);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-16 14:05:10 +00:00
|
|
|
spin_lock_irqsave(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-06-04 05:29:07 +00:00
|
|
|
list_add(&tqe->list, &wilc->txq_head.list);
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->txq_entries += 1;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-16 14:05:10 +00:00
|
|
|
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
|
2016-06-15 05:30:35 +00:00
|
|
|
mutex_unlock(&wilc->txq_add_to_head_cs);
|
2016-06-15 05:30:34 +00:00
|
|
|
complete(&wilc->txq_event);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NOT_TCP_ACK (-1)
|
|
|
|
|
2018-09-25 06:23:23 +00:00
|
|
|
static inline void add_tcp_session(struct wilc_vif *vif, u32 src_prt,
|
|
|
|
u32 dst_prt, u32 seq)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-09-04 06:39:33 +00:00
|
|
|
struct tcp_ack_filter *f = &vif->ack_filter;
|
|
|
|
|
|
|
|
if (f->tcp_session < 2 * MAX_TCP_SESSION) {
|
|
|
|
f->ack_session_info[f->tcp_session].seq_num = seq;
|
|
|
|
f->ack_session_info[f->tcp_session].bigger_ack_num = 0;
|
|
|
|
f->ack_session_info[f->tcp_session].src_port = src_prt;
|
|
|
|
f->ack_session_info[f->tcp_session].dst_port = dst_prt;
|
|
|
|
f->tcp_session++;
|
2016-02-04 09:15:24 +00:00
|
|
|
}
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 06:23:23 +00:00
|
|
|
static inline void update_tcp_session(struct wilc_vif *vif, u32 index, u32 ack)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-09-04 06:39:33 +00:00
|
|
|
struct tcp_ack_filter *f = &vif->ack_filter;
|
|
|
|
|
2016-02-04 09:15:24 +00:00
|
|
|
if (index < 2 * MAX_TCP_SESSION &&
|
2018-09-04 06:39:33 +00:00
|
|
|
ack > f->ack_session_info[index].bigger_ack_num)
|
|
|
|
f->ack_session_info[index].bigger_ack_num = ack;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2015-11-06 02:12:28 +00:00
|
|
|
|
2018-09-25 06:23:23 +00:00
|
|
|
static inline void add_tcp_pending_ack(struct wilc_vif *vif, u32 ack,
|
|
|
|
u32 session_index,
|
|
|
|
struct txq_entry_t *txqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-09-04 06:39:33 +00:00
|
|
|
struct tcp_ack_filter *f = &vif->ack_filter;
|
2018-09-04 06:39:35 +00:00
|
|
|
u32 i = f->pending_base + f->pending_acks_idx;
|
2018-02-16 15:11:46 +00:00
|
|
|
|
|
|
|
if (i < MAX_PENDING_ACKS) {
|
2018-09-04 06:39:35 +00:00
|
|
|
f->pending_acks[i].ack_num = ack;
|
|
|
|
f->pending_acks[i].txqe = txqe;
|
|
|
|
f->pending_acks[i].session_index = session_index;
|
|
|
|
txqe->ack_idx = i;
|
|
|
|
f->pending_acks_idx++;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-16 19:07:00 +00:00
|
|
|
static inline void tcp_process(struct net_device *dev, struct txq_entry_t *tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-06-19 18:44:19 +00:00
|
|
|
void *buffer = tqe->buffer;
|
|
|
|
const struct ethhdr *eth_hdr_ptr = buffer;
|
2015-05-11 05:30:56 +00:00
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
2018-07-18 22:45:19 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
|
|
|
struct wilc *wilc = vif->wilc;
|
2018-09-04 06:39:33 +00:00
|
|
|
struct tcp_ack_filter *f = &vif->ack_filter;
|
2018-09-04 06:39:31 +00:00
|
|
|
const struct iphdr *ip_hdr_ptr;
|
|
|
|
const struct tcphdr *tcp_hdr_ptr;
|
2018-09-04 06:39:32 +00:00
|
|
|
u32 ihl, total_length, data_offset;
|
2015-10-27 09:28:03 +00:00
|
|
|
|
2016-02-04 09:15:22 +00:00
|
|
|
spin_lock_irqsave(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-09-04 06:39:31 +00:00
|
|
|
if (eth_hdr_ptr->h_proto != htons(ETH_P_IP))
|
|
|
|
goto out;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-09-04 06:39:31 +00:00
|
|
|
ip_hdr_ptr = buffer + ETH_HLEN;
|
2015-08-18 14:18:11 +00:00
|
|
|
|
2018-09-04 06:39:31 +00:00
|
|
|
if (ip_hdr_ptr->protocol != IPPROTO_TCP)
|
|
|
|
goto out;
|
2018-06-19 18:44:19 +00:00
|
|
|
|
2018-09-04 06:39:32 +00:00
|
|
|
ihl = ip_hdr_ptr->ihl << 2;
|
|
|
|
tcp_hdr_ptr = buffer + ETH_HLEN + ihl;
|
2018-09-04 06:39:31 +00:00
|
|
|
total_length = ntohs(ip_hdr_ptr->tot_len);
|
2015-08-18 14:18:11 +00:00
|
|
|
|
2018-09-04 06:39:31 +00:00
|
|
|
data_offset = tcp_hdr_ptr->doff << 2;
|
2018-09-04 06:39:32 +00:00
|
|
|
if (total_length == (ihl + data_offset)) {
|
2018-09-04 06:39:31 +00:00
|
|
|
u32 seq_no, ack_no;
|
2018-02-16 15:11:47 +00:00
|
|
|
|
2018-09-04 06:39:31 +00:00
|
|
|
seq_no = ntohl(tcp_hdr_ptr->seq);
|
|
|
|
ack_no = ntohl(tcp_hdr_ptr->ack_seq);
|
2018-09-04 06:39:33 +00:00
|
|
|
for (i = 0; i < f->tcp_session; i++) {
|
|
|
|
u32 j = f->ack_session_info[i].seq_num;
|
2015-10-09 04:18:03 +00:00
|
|
|
|
2018-09-04 06:39:31 +00:00
|
|
|
if (i < 2 * MAX_TCP_SESSION &&
|
|
|
|
j == seq_no) {
|
2018-09-04 06:39:33 +00:00
|
|
|
update_tcp_session(vif, i, ack_no);
|
2018-09-04 06:39:31 +00:00
|
|
|
break;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-04 06:39:33 +00:00
|
|
|
if (i == f->tcp_session)
|
|
|
|
add_tcp_session(vif, 0, 0, seq_no);
|
2018-09-04 06:39:31 +00:00
|
|
|
|
2018-09-04 06:39:33 +00:00
|
|
|
add_tcp_pending_ack(vif, ack_no, i, tqe);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2018-09-04 06:39:31 +00:00
|
|
|
|
|
|
|
out:
|
2015-10-27 09:28:03 +00:00
|
|
|
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2018-09-25 06:23:24 +00:00
|
|
|
static void wilc_wlan_txq_filter_dup_tcp_ack(struct net_device *dev)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-07-18 22:45:19 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
|
|
|
struct wilc *wilc = vif->wilc;
|
2018-09-04 06:39:33 +00:00
|
|
|
struct tcp_ack_filter *f = &vif->ack_filter;
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 i = 0;
|
2015-11-06 02:12:55 +00:00
|
|
|
u32 dropped = 0;
|
2018-06-04 05:29:10 +00:00
|
|
|
unsigned long flags;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-06-04 05:29:10 +00:00
|
|
|
spin_lock_irqsave(&wilc->txq_spinlock, flags);
|
2018-09-04 06:39:34 +00:00
|
|
|
for (i = f->pending_base;
|
2018-09-04 06:39:35 +00:00
|
|
|
i < (f->pending_base + f->pending_acks_idx); i++) {
|
2018-09-04 06:39:34 +00:00
|
|
|
u32 index;
|
2018-02-16 15:11:48 +00:00
|
|
|
u32 bigger_ack_num;
|
|
|
|
|
|
|
|
if (i >= MAX_PENDING_ACKS)
|
|
|
|
break;
|
|
|
|
|
2018-09-04 06:39:35 +00:00
|
|
|
index = f->pending_acks[i].session_index;
|
2018-02-16 15:11:48 +00:00
|
|
|
|
2018-09-04 06:39:34 +00:00
|
|
|
if (index >= 2 * MAX_TCP_SESSION)
|
2016-02-04 09:15:24 +00:00
|
|
|
break;
|
2018-02-16 15:11:48 +00:00
|
|
|
|
2018-09-04 06:39:34 +00:00
|
|
|
bigger_ack_num = f->ack_session_info[index].bigger_ack_num;
|
2018-02-16 15:11:48 +00:00
|
|
|
|
2018-09-04 06:39:35 +00:00
|
|
|
if (f->pending_acks[i].ack_num < bigger_ack_num) {
|
2015-05-11 05:30:56 +00:00
|
|
|
struct txq_entry_t *tqe;
|
2015-08-18 14:18:11 +00:00
|
|
|
|
2018-09-04 06:39:35 +00:00
|
|
|
tqe = f->pending_acks[i].txqe;
|
2015-05-11 05:30:56 +00:00
|
|
|
if (tqe) {
|
2016-02-04 09:15:23 +00:00
|
|
|
wilc_wlan_txq_remove(wilc, tqe);
|
2015-11-06 02:12:25 +00:00
|
|
|
tqe->status = 1;
|
2015-05-11 05:30:56 +00:00
|
|
|
if (tqe->tx_complete_func)
|
2015-11-06 02:19:54 +00:00
|
|
|
tqe->tx_complete_func(tqe->priv,
|
|
|
|
tqe->status);
|
2015-09-04 02:04:19 +00:00
|
|
|
kfree(tqe);
|
2015-11-06 02:12:55 +00:00
|
|
|
dropped++;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-04 06:39:35 +00:00
|
|
|
f->pending_acks_idx = 0;
|
2018-09-04 06:39:33 +00:00
|
|
|
f->tcp_session = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-09-04 06:39:33 +00:00
|
|
|
if (f->pending_base == 0)
|
|
|
|
f->pending_base = MAX_TCP_SESSION;
|
2015-08-08 12:11:36 +00:00
|
|
|
else
|
2018-09-04 06:39:33 +00:00
|
|
|
f->pending_base = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-06-04 05:29:10 +00:00
|
|
|
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-06 02:12:55 +00:00
|
|
|
while (dropped > 0) {
|
2016-06-15 05:30:34 +00:00
|
|
|
wait_for_completion_timeout(&wilc->txq_event,
|
2017-03-04 15:57:38 +00:00
|
|
|
msecs_to_jiffies(1));
|
2015-11-06 02:12:55 +00:00
|
|
|
dropped--;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-04 06:39:33 +00:00
|
|
|
void wilc_enable_tcp_ack_filter(struct wilc_vif *vif, bool value)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-09-04 06:39:33 +00:00
|
|
|
vif->ack_filter.enabled = value;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 09:15:31 +00:00
|
|
|
static int wilc_wlan_txq_add_cfg_pkt(struct wilc_vif *vif, u8 *buffer,
|
|
|
|
u32 buffer_size)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
struct txq_entry_t *tqe;
|
2016-02-04 09:15:31 +00:00
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-02-04 09:15:31 +00:00
|
|
|
netdev_dbg(vif->ndev, "Adding config packet ...\n");
|
2015-12-21 05:18:12 +00:00
|
|
|
if (wilc->quit) {
|
2016-02-04 09:15:31 +00:00
|
|
|
netdev_dbg(vif->ndev, "Return due to clear function\n");
|
2016-06-15 05:30:36 +00:00
|
|
|
complete(&wilc->cfg_event);
|
2015-05-11 05:30:56 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-06 02:12:59 +00:00
|
|
|
tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
|
2016-03-11 14:19:50 +00:00
|
|
|
if (!tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
tqe->type = WILC_CFG_PKT;
|
|
|
|
tqe->buffer = buffer;
|
|
|
|
tqe->buffer_size = buffer_size;
|
|
|
|
tqe->tx_complete_func = NULL;
|
|
|
|
tqe->priv = NULL;
|
2018-09-04 06:39:35 +00:00
|
|
|
tqe->ack_idx = NOT_TCP_ACK;
|
2019-06-26 12:40:52 +00:00
|
|
|
tqe->vif = vif;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-09-25 06:23:22 +00:00
|
|
|
wilc_wlan_txq_add_to_head(vif, tqe);
|
2016-04-24 23:07:18 +00:00
|
|
|
|
2015-05-11 05:30:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-27 09:28:02 +00:00
|
|
|
int wilc_wlan_txq_add_net_pkt(struct net_device *dev, void *priv, u8 *buffer,
|
2019-01-17 13:21:44 +00:00
|
|
|
u32 buffer_size,
|
|
|
|
void (*tx_complete_fn)(void *, int))
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
struct txq_entry_t *tqe;
|
2015-12-21 05:18:36 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
2015-12-21 05:18:12 +00:00
|
|
|
struct wilc *wilc;
|
|
|
|
|
2015-12-21 05:18:36 +00:00
|
|
|
wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
if (wilc->quit)
|
2015-05-11 05:30:56 +00:00
|
|
|
return 0;
|
|
|
|
|
2015-11-06 02:12:59 +00:00
|
|
|
tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-06 02:12:31 +00:00
|
|
|
if (!tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
return 0;
|
|
|
|
tqe->type = WILC_NET_PKT;
|
|
|
|
tqe->buffer = buffer;
|
|
|
|
tqe->buffer_size = buffer_size;
|
2019-01-17 13:21:44 +00:00
|
|
|
tqe->tx_complete_func = tx_complete_fn;
|
2015-05-11 05:30:56 +00:00
|
|
|
tqe->priv = priv;
|
2019-06-26 12:40:52 +00:00
|
|
|
tqe->vif = vif;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-09-04 06:39:35 +00:00
|
|
|
tqe->ack_idx = NOT_TCP_ACK;
|
2018-09-04 06:39:33 +00:00
|
|
|
if (vif->ack_filter.enabled)
|
2015-10-27 09:28:03 +00:00
|
|
|
tcp_process(dev, tqe);
|
2015-10-29 03:18:45 +00:00
|
|
|
wilc_wlan_txq_add_to_tail(dev, tqe);
|
2015-12-21 05:18:12 +00:00
|
|
|
return wilc->txq_entries;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2015-09-16 09:53:21 +00:00
|
|
|
|
2015-10-29 03:18:44 +00:00
|
|
|
int wilc_wlan_txq_add_mgmt_pkt(struct net_device *dev, void *priv, u8 *buffer,
|
2019-01-17 13:21:44 +00:00
|
|
|
u32 buffer_size,
|
|
|
|
void (*tx_complete_fn)(void *, int))
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
struct txq_entry_t *tqe;
|
2015-12-21 05:18:36 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
2015-12-21 05:18:12 +00:00
|
|
|
struct wilc *wilc;
|
|
|
|
|
2015-12-21 05:18:36 +00:00
|
|
|
wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
if (wilc->quit)
|
2015-05-11 05:30:56 +00:00
|
|
|
return 0;
|
|
|
|
|
2019-04-16 23:17:07 +00:00
|
|
|
tqe = kmalloc(sizeof(*tqe), GFP_ATOMIC);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-06 02:12:31 +00:00
|
|
|
if (!tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
return 0;
|
|
|
|
tqe->type = WILC_MGMT_PKT;
|
|
|
|
tqe->buffer = buffer;
|
|
|
|
tqe->buffer_size = buffer_size;
|
2019-01-17 13:21:44 +00:00
|
|
|
tqe->tx_complete_func = tx_complete_fn;
|
2015-05-11 05:30:56 +00:00
|
|
|
tqe->priv = priv;
|
2018-09-04 06:39:35 +00:00
|
|
|
tqe->ack_idx = NOT_TCP_ACK;
|
2019-06-26 12:40:52 +00:00
|
|
|
tqe->vif = vif;
|
2015-10-29 03:18:45 +00:00
|
|
|
wilc_wlan_txq_add_to_tail(dev, tqe);
|
2015-05-11 05:30:56 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2015-09-16 09:53:21 +00:00
|
|
|
|
2015-10-29 03:18:41 +00:00
|
|
|
static struct txq_entry_t *wilc_wlan_txq_get_first(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-06-04 05:29:07 +00:00
|
|
|
struct txq_entry_t *tqe = NULL;
|
2015-05-11 05:30:56 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2015-10-29 03:18:41 +00:00
|
|
|
spin_lock_irqsave(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-06-04 05:29:07 +00:00
|
|
|
if (!list_empty(&wilc->txq_head.list))
|
|
|
|
tqe = list_first_entry(&wilc->txq_head.list, struct txq_entry_t,
|
|
|
|
list);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-10-29 03:18:41 +00:00
|
|
|
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return tqe;
|
|
|
|
}
|
|
|
|
|
2015-10-27 09:28:00 +00:00
|
|
|
static struct txq_entry_t *wilc_wlan_txq_get_next(struct wilc *wilc,
|
|
|
|
struct txq_entry_t *tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2015-11-06 02:12:29 +00:00
|
|
|
|
2015-10-27 09:28:00 +00:00
|
|
|
spin_lock_irqsave(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-06-04 05:29:07 +00:00
|
|
|
if (!list_is_last(&tqe->list, &wilc->txq_head.list))
|
|
|
|
tqe = list_next_entry(tqe, list);
|
|
|
|
else
|
|
|
|
tqe = NULL;
|
2015-10-27 09:28:00 +00:00
|
|
|
spin_unlock_irqrestore(&wilc->txq_spinlock, flags);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return tqe;
|
|
|
|
}
|
|
|
|
|
2018-06-04 05:29:09 +00:00
|
|
|
static void wilc_wlan_rxq_add(struct wilc *wilc, struct rxq_entry_t *rqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-12-21 05:18:12 +00:00
|
|
|
if (wilc->quit)
|
2018-06-04 05:29:09 +00:00
|
|
|
return;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-10-27 09:27:59 +00:00
|
|
|
mutex_lock(&wilc->rxq_cs);
|
2018-06-04 05:29:08 +00:00
|
|
|
list_add_tail(&rqe->list, &wilc->rxq_head.list);
|
2015-10-27 09:27:59 +00:00
|
|
|
mutex_unlock(&wilc->rxq_cs);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 09:27:55 +00:00
|
|
|
static struct rxq_entry_t *wilc_wlan_rxq_remove(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-06-04 05:29:08 +00:00
|
|
|
struct rxq_entry_t *rqe = NULL;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-06-04 05:29:08 +00:00
|
|
|
mutex_lock(&wilc->rxq_cs);
|
|
|
|
if (!list_empty(&wilc->rxq_head.list)) {
|
|
|
|
rqe = list_first_entry(&wilc->rxq_head.list, struct rxq_entry_t,
|
|
|
|
list);
|
|
|
|
list_del(&rqe->list);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2018-06-04 05:29:08 +00:00
|
|
|
mutex_unlock(&wilc->rxq_cs);
|
|
|
|
return rqe;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2016-01-25 07:35:08 +00:00
|
|
|
void chip_allow_sleep(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 reg = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0xf0, ®);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0xf0, reg & ~BIT(0));
|
2016-01-25 07:35:07 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0xfa, 0);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2018-08-13 21:20:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(chip_allow_sleep);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-01-25 07:35:08 +00:00
|
|
|
void chip_wakeup(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2016-02-23 12:10:53 +00:00
|
|
|
u32 reg, clk_status_reg;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
if ((wilc->io_type & 0x1) == WILC_HIF_SPI) {
|
2015-05-11 05:30:56 +00:00
|
|
|
do {
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 1, ®);
|
|
|
|
wilc->hif_func->hif_write_reg(wilc, 1, reg | BIT(1));
|
|
|
|
wilc->hif_func->hif_write_reg(wilc, 1, reg & ~BIT(1));
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
do {
|
2019-04-11 03:31:21 +00:00
|
|
|
usleep_range(2000, 2500);
|
2016-02-22 04:41:13 +00:00
|
|
|
wilc_get_chipid(wilc, true);
|
2016-02-23 12:10:53 +00:00
|
|
|
} while (wilc_get_chipid(wilc, true) == 0);
|
2015-11-18 06:11:25 +00:00
|
|
|
} while (wilc_get_chipid(wilc, true) == 0);
|
2018-11-12 05:45:20 +00:00
|
|
|
} else if ((wilc->io_type & 0x1) == WILC_HIF_SDIO) {
|
2016-01-25 07:35:07 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0xfa, 1);
|
2018-09-25 06:23:42 +00:00
|
|
|
usleep_range(200, 400);
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0xf0, ®);
|
2015-05-11 05:30:56 +00:00
|
|
|
do {
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0xf0,
|
2015-11-18 06:11:26 +00:00
|
|
|
reg | BIT(0));
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0xf1,
|
2015-11-18 06:11:26 +00:00
|
|
|
&clk_status_reg);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-02-23 12:10:53 +00:00
|
|
|
while ((clk_status_reg & 0x1) == 0) {
|
2019-04-11 03:31:21 +00:00
|
|
|
usleep_range(2000, 2500);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0xf1,
|
2015-11-18 06:11:26 +00:00
|
|
|
&clk_status_reg);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
if ((clk_status_reg & 0x1) == 0) {
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0xf0,
|
2015-11-18 06:11:26 +00:00
|
|
|
reg & (~BIT(0)));
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
} while ((clk_status_reg & 0x1) == 0);
|
|
|
|
}
|
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
if (wilc->chip_ps_state == WILC_CHIP_SLEEPING_MANUAL) {
|
2016-01-25 07:35:07 +00:00
|
|
|
if (wilc_get_chipid(wilc, false) < 0x1002b0) {
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 val32;
|
2015-08-18 14:18:11 +00:00
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0x1e1c, &val32);
|
2015-09-29 19:15:49 +00:00
|
|
|
val32 |= BIT(6);
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0x1e1c, val32);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0x1e9c, &val32);
|
2015-09-29 19:15:49 +00:00
|
|
|
val32 |= BIT(6);
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0x1e9c, val32);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-12 05:45:20 +00:00
|
|
|
wilc->chip_ps_state = WILC_CHIP_WAKEDUP;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2018-08-13 21:20:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(chip_wakeup);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-01-25 07:35:07 +00:00
|
|
|
void host_wakeup_notify(struct wilc *wilc)
|
|
|
|
{
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
|
2016-01-25 07:35:07 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0x10b0, 1);
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2016-01-25 07:35:07 +00:00
|
|
|
}
|
2018-08-13 21:20:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(host_wakeup_notify);
|
2016-01-25 07:35:07 +00:00
|
|
|
|
|
|
|
void host_sleep_notify(struct wilc *wilc)
|
|
|
|
{
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
|
2016-01-25 07:35:07 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, 0x10ac, 1);
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2016-01-25 07:35:07 +00:00
|
|
|
}
|
2018-08-13 21:20:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(host_sleep_notify);
|
2016-01-25 07:35:07 +00:00
|
|
|
|
2019-06-26 12:40:52 +00:00
|
|
|
int wilc_wlan_handle_txq(struct wilc *wilc, u32 *txq_count)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
int i, entries = 0;
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 sum;
|
|
|
|
u32 reg;
|
|
|
|
u32 offset = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
int vmm_sz = 0;
|
|
|
|
struct txq_entry_t *tqe;
|
|
|
|
int ret = 0;
|
|
|
|
int counter;
|
|
|
|
int timeout;
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 vmm_table[WILC_VMM_TBL_SIZE];
|
2018-02-16 15:11:49 +00:00
|
|
|
const struct wilc_hif_func *func;
|
2018-07-18 22:45:19 +00:00
|
|
|
u8 *txb = wilc->tx_buffer;
|
2019-06-26 12:40:52 +00:00
|
|
|
struct net_device *dev;
|
|
|
|
struct wilc_vif *vif;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
if (wilc->quit)
|
|
|
|
goto out;
|
2015-10-09 04:18:03 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
mutex_lock(&wilc->txq_add_to_head_cs);
|
|
|
|
tqe = wilc_wlan_txq_get_first(wilc);
|
2019-06-26 12:40:52 +00:00
|
|
|
if (!tqe)
|
|
|
|
goto out;
|
|
|
|
dev = tqe->vif->ndev;
|
|
|
|
wilc_wlan_txq_filter_dup_tcp_ack(dev);
|
2018-02-26 16:31:55 +00:00
|
|
|
i = 0;
|
|
|
|
sum = 0;
|
|
|
|
do {
|
|
|
|
if (tqe && (i < (WILC_VMM_TBL_SIZE - 1))) {
|
|
|
|
if (tqe->type == WILC_CFG_PKT)
|
|
|
|
vmm_sz = ETH_CONFIG_PKT_HDR_OFFSET;
|
2015-10-09 04:18:03 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
else if (tqe->type == WILC_NET_PKT)
|
|
|
|
vmm_sz = ETH_ETHERNET_HDR_OFFSET;
|
2016-02-04 09:15:50 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
else
|
|
|
|
vmm_sz = HOST_HDR_OFFSET;
|
2015-11-06 02:12:25 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
vmm_sz += tqe->buffer_size;
|
2015-10-09 04:18:03 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
if (vmm_sz & 0x3)
|
|
|
|
vmm_sz = (vmm_sz + 4) & ~0x3;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2019-02-07 11:29:01 +00:00
|
|
|
if ((sum + vmm_sz) > WILC_TX_BUFF_SIZE)
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
vmm_table[i] = vmm_sz / 4;
|
|
|
|
if (tqe->type == WILC_CFG_PKT)
|
|
|
|
vmm_table[i] |= BIT(10);
|
2018-08-01 11:11:00 +00:00
|
|
|
cpu_to_le32s(&vmm_table[i]);
|
2018-02-26 16:31:55 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
sum += vmm_sz;
|
|
|
|
tqe = wilc_wlan_txq_get_next(wilc, tqe);
|
|
|
|
} else {
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
2018-02-26 16:31:55 +00:00
|
|
|
}
|
|
|
|
} while (1);
|
2016-02-04 09:24:05 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
if (i == 0)
|
|
|
|
goto out;
|
|
|
|
vmm_table[i] = 0x0;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
|
2018-02-26 16:31:55 +00:00
|
|
|
counter = 0;
|
|
|
|
func = wilc->hif_func;
|
|
|
|
do {
|
|
|
|
ret = func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, ®);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2016-09-30 19:15:09 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
if ((reg & 0x1) == 0)
|
|
|
|
break;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
counter++;
|
|
|
|
if (counter > 200) {
|
|
|
|
counter = 0;
|
|
|
|
ret = func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!wilc->quit);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
if (!ret)
|
2018-02-26 16:31:56 +00:00
|
|
|
goto out_release_bus;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
timeout = 200;
|
|
|
|
do {
|
|
|
|
ret = func->hif_block_tx(wilc,
|
|
|
|
WILC_VMM_TBL_RX_SHADOW_BASE,
|
|
|
|
(u8 *)vmm_table,
|
|
|
|
((i + 1) * 4));
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
ret = func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x2);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
do {
|
|
|
|
ret = func->hif_read_reg(wilc, WILC_HOST_VMM_CTL, ®);
|
2015-10-09 04:18:03 +00:00
|
|
|
if (!ret)
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
2018-02-26 16:31:55 +00:00
|
|
|
if ((reg >> 2) & 0x1) {
|
|
|
|
entries = ((reg >> 3) & 0x3f);
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2018-02-26 16:31:55 +00:00
|
|
|
} while (--timeout);
|
|
|
|
if (timeout <= 0) {
|
|
|
|
ret = func->hif_write_reg(wilc, WILC_HOST_VMM_CTL, 0x0);
|
2016-03-13 09:44:38 +00:00
|
|
|
break;
|
2018-02-26 16:31:55 +00:00
|
|
|
}
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-10-09 04:18:03 +00:00
|
|
|
if (!ret)
|
2018-02-26 16:31:55 +00:00
|
|
|
break;
|
2015-10-09 04:18:03 +00:00
|
|
|
|
2015-05-11 05:30:56 +00:00
|
|
|
if (entries == 0) {
|
2018-02-26 16:31:55 +00:00
|
|
|
ret = func->hif_read_reg(wilc, WILC_HOST_TX_CTRL, ®);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
reg &= ~BIT(0);
|
|
|
|
ret = func->hif_write_reg(wilc, WILC_HOST_TX_CTRL, reg);
|
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
break;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2018-02-26 16:31:55 +00:00
|
|
|
break;
|
|
|
|
} while (1);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
if (!ret)
|
2018-02-26 16:31:56 +00:00
|
|
|
goto out_release_bus;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
if (entries == 0) {
|
2018-11-12 05:45:32 +00:00
|
|
|
ret = -ENOBUFS;
|
2018-02-26 16:31:56 +00:00
|
|
|
goto out_release_bus;
|
2018-02-26 16:31:55 +00:00
|
|
|
}
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2018-02-26 16:31:55 +00:00
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
i = 0;
|
|
|
|
do {
|
2018-02-26 16:31:57 +00:00
|
|
|
u32 header, buffer_offset;
|
|
|
|
char *bssid;
|
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
tqe = wilc_wlan_txq_remove_from_head(dev);
|
2018-02-26 16:31:57 +00:00
|
|
|
if (!tqe)
|
|
|
|
break;
|
2018-02-26 16:31:55 +00:00
|
|
|
|
2019-06-26 12:40:52 +00:00
|
|
|
vif = tqe->vif;
|
2018-02-26 16:31:57 +00:00
|
|
|
if (vmm_table[i] == 0)
|
|
|
|
break;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-08-01 11:11:00 +00:00
|
|
|
le32_to_cpus(&vmm_table[i]);
|
2018-02-26 16:31:57 +00:00
|
|
|
vmm_sz = (vmm_table[i] & 0x3ff);
|
|
|
|
vmm_sz *= 4;
|
|
|
|
header = (tqe->type << 31) |
|
|
|
|
(tqe->buffer_size << 15) |
|
|
|
|
vmm_sz;
|
|
|
|
if (tqe->type == WILC_MGMT_PKT)
|
|
|
|
header |= BIT(30);
|
|
|
|
else
|
|
|
|
header &= ~BIT(30);
|
|
|
|
|
2018-08-01 11:11:00 +00:00
|
|
|
cpu_to_le32s(&header);
|
2018-02-26 16:31:57 +00:00
|
|
|
memcpy(&txb[offset], &header, 4);
|
|
|
|
if (tqe->type == WILC_CFG_PKT) {
|
|
|
|
buffer_offset = ETH_CONFIG_PKT_HDR_OFFSET;
|
|
|
|
} else if (tqe->type == WILC_NET_PKT) {
|
2019-06-26 12:40:52 +00:00
|
|
|
bssid = tqe->vif->bssid;
|
2018-02-26 16:31:57 +00:00
|
|
|
buffer_offset = ETH_ETHERNET_HDR_OFFSET;
|
|
|
|
memcpy(&txb[offset + 8], bssid, 6);
|
2018-02-26 16:31:55 +00:00
|
|
|
} else {
|
2018-02-26 16:31:57 +00:00
|
|
|
buffer_offset = HOST_HDR_OFFSET;
|
2018-02-26 16:31:55 +00:00
|
|
|
}
|
2018-02-26 16:31:57 +00:00
|
|
|
|
|
|
|
memcpy(&txb[offset + buffer_offset],
|
|
|
|
tqe->buffer, tqe->buffer_size);
|
|
|
|
offset += vmm_sz;
|
|
|
|
i++;
|
|
|
|
tqe->status = 1;
|
|
|
|
if (tqe->tx_complete_func)
|
|
|
|
tqe->tx_complete_func(tqe->priv, tqe->status);
|
2018-09-04 06:39:35 +00:00
|
|
|
if (tqe->ack_idx != NOT_TCP_ACK &&
|
|
|
|
tqe->ack_idx < MAX_PENDING_ACKS)
|
|
|
|
vif->ack_filter.pending_acks[tqe->ack_idx].txqe = NULL;
|
2018-02-26 16:31:57 +00:00
|
|
|
kfree(tqe);
|
2018-02-26 16:31:55 +00:00
|
|
|
} while (--entries);
|
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
ret = func->hif_clear_int_ext(wilc, ENABLE_TX_VMM);
|
|
|
|
if (!ret)
|
2018-02-26 16:31:56 +00:00
|
|
|
goto out_release_bus;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
ret = func->hif_block_tx_ext(wilc, 0, txb, offset);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:56 +00:00
|
|
|
out_release_bus:
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-02-26 16:31:55 +00:00
|
|
|
out:
|
2016-06-15 05:30:35 +00:00
|
|
|
mutex_unlock(&wilc->txq_add_to_head_cs);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
*txq_count = wilc->txq_entries;
|
2015-05-11 05:30:56 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-02 14:17:20 +00:00
|
|
|
static void wilc_wlan_handle_rx_buff(struct wilc *wilc, u8 *buffer, int size)
|
|
|
|
{
|
|
|
|
int offset = 0;
|
|
|
|
u32 header;
|
|
|
|
u32 pkt_len, pkt_offset, tp_len;
|
|
|
|
int is_cfg_packet;
|
|
|
|
u8 *buff_ptr;
|
|
|
|
|
|
|
|
do {
|
|
|
|
buff_ptr = buffer + offset;
|
2019-07-25 02:52:03 +00:00
|
|
|
header = get_unaligned_le32(buff_ptr);
|
2018-03-02 14:17:20 +00:00
|
|
|
|
|
|
|
is_cfg_packet = (header >> 31) & 0x1;
|
|
|
|
pkt_offset = (header >> 22) & 0x1ff;
|
|
|
|
tp_len = (header >> 11) & 0x7ff;
|
|
|
|
pkt_len = header & 0x7ff;
|
|
|
|
|
|
|
|
if (pkt_len == 0 || tp_len == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (pkt_offset & IS_MANAGMEMENT) {
|
|
|
|
buff_ptr += HOST_HDR_OFFSET;
|
|
|
|
wilc_wfi_mgmt_rx(wilc, buff_ptr, pkt_len);
|
|
|
|
} else {
|
|
|
|
if (!is_cfg_packet) {
|
|
|
|
if (pkt_len > 0) {
|
2019-02-07 11:29:13 +00:00
|
|
|
wilc_frmw_to_host(wilc, buff_ptr,
|
|
|
|
pkt_len, pkt_offset);
|
2018-03-02 14:17:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct wilc_cfg_rsp rsp;
|
|
|
|
|
|
|
|
buff_ptr += pkt_offset;
|
|
|
|
|
|
|
|
wilc_wlan_cfg_indicate_rx(wilc, buff_ptr,
|
|
|
|
pkt_len,
|
|
|
|
&rsp);
|
|
|
|
if (rsp.type == WILC_CFG_RSP) {
|
|
|
|
if (wilc->cfg_seq_no == rsp.seq_no)
|
|
|
|
complete(&wilc->cfg_event);
|
|
|
|
} else if (rsp.type == WILC_CFG_RSP_STATUS) {
|
2018-05-11 08:13:27 +00:00
|
|
|
wilc_mac_indicate(wilc);
|
2018-03-02 14:17:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
offset += tp_len;
|
|
|
|
if (offset >= size)
|
|
|
|
break;
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2015-10-27 09:27:42 +00:00
|
|
|
static void wilc_wlan_handle_rxq(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2018-03-02 14:17:20 +00:00
|
|
|
int size;
|
2015-09-15 05:06:14 +00:00
|
|
|
u8 *buffer;
|
2015-05-11 05:30:56 +00:00
|
|
|
struct rxq_entry_t *rqe;
|
|
|
|
|
|
|
|
do {
|
2015-12-21 05:18:12 +00:00
|
|
|
if (wilc->quit) {
|
2016-06-15 05:30:36 +00:00
|
|
|
complete(&wilc->cfg_event);
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-10-27 09:27:55 +00:00
|
|
|
rqe = wilc_wlan_rxq_remove(wilc);
|
2016-02-04 09:15:50 +00:00
|
|
|
if (!rqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
2016-02-04 09:15:50 +00:00
|
|
|
|
2015-05-11 05:30:56 +00:00
|
|
|
buffer = rqe->buffer;
|
|
|
|
size = rqe->buffer_size;
|
2018-03-02 14:17:20 +00:00
|
|
|
wilc_wlan_handle_rx_buff(wilc, buffer, size);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-09-04 02:04:19 +00:00
|
|
|
kfree(rqe);
|
2015-05-11 05:30:56 +00:00
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2015-11-18 06:11:25 +00:00
|
|
|
static void wilc_unknown_isr_ext(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_clear_int_ext(wilc, 0);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2015-11-06 02:12:28 +00:00
|
|
|
|
2015-10-27 09:27:41 +00:00
|
|
|
static void wilc_wlan_handle_isr_ext(struct wilc *wilc, u32 int_status)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-12-21 05:18:12 +00:00
|
|
|
u32 offset = wilc->rx_buffer_offset;
|
2015-09-15 05:06:14 +00:00
|
|
|
u8 *buffer = NULL;
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 size;
|
|
|
|
u32 retries = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
int ret = 0;
|
|
|
|
struct rxq_entry_t *rqe;
|
|
|
|
|
2016-02-11 05:34:41 +00:00
|
|
|
size = (int_status & 0x7fff) << 2;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
while (!size && retries < 10) {
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_size(wilc, &size);
|
2016-02-11 05:34:41 +00:00
|
|
|
size = (size & 0x7fff) << 2;
|
2015-05-11 05:30:56 +00:00
|
|
|
retries++;
|
|
|
|
}
|
|
|
|
|
2018-08-01 05:03:41 +00:00
|
|
|
if (size <= 0)
|
|
|
|
return;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2019-02-07 11:29:01 +00:00
|
|
|
if (WILC_RX_BUFF_SIZE - offset < size)
|
2018-08-01 05:03:41 +00:00
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
buffer = &wilc->rx_buffer[offset];
|
|
|
|
|
|
|
|
wilc->hif_func->hif_clear_int_ext(wilc, DATA_INT_CLR | ENABLE_RX_VMM);
|
|
|
|
ret = wilc->hif_func->hif_block_rx_ext(wilc, 0, buffer, size);
|
|
|
|
if (!ret)
|
|
|
|
return;
|
|
|
|
|
|
|
|
offset += size;
|
|
|
|
wilc->rx_buffer_offset = offset;
|
|
|
|
rqe = kmalloc(sizeof(*rqe), GFP_KERNEL);
|
|
|
|
if (!rqe)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rqe->buffer = buffer;
|
|
|
|
rqe->buffer_size = size;
|
|
|
|
wilc_wlan_rxq_add(wilc, rqe);
|
2015-10-27 09:27:42 +00:00
|
|
|
wilc_wlan_handle_rxq(wilc);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-16 14:05:10 +00:00
|
|
|
void wilc_handle_isr(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 int_status;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_int(wilc, &int_status);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-02-04 09:15:52 +00:00
|
|
|
if (int_status & DATA_INT_EXT)
|
2015-10-27 09:27:41 +00:00
|
|
|
wilc_wlan_handle_isr_ext(wilc, int_status);
|
2016-02-04 09:15:52 +00:00
|
|
|
|
|
|
|
if (!(int_status & (ALL_INT_EXT)))
|
2015-11-18 06:11:25 +00:00
|
|
|
wilc_unknown_isr_ext(wilc);
|
2016-02-04 09:15:52 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2018-08-13 21:20:33 +00:00
|
|
|
EXPORT_SYMBOL_GPL(wilc_handle_isr);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-02-04 09:15:49 +00:00
|
|
|
int wilc_wlan_firmware_download(struct wilc *wilc, const u8 *buffer,
|
|
|
|
u32 buffer_size)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 offset;
|
|
|
|
u32 addr, size, size2, blksz;
|
2015-09-15 05:06:14 +00:00
|
|
|
u8 *dma_buffer;
|
2015-05-11 05:30:56 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2015-09-29 19:15:49 +00:00
|
|
|
blksz = BIT(12);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-09-04 01:50:27 +00:00
|
|
|
dma_buffer = kmalloc(blksz, GFP_KERNEL);
|
2016-03-15 09:48:13 +00:00
|
|
|
if (!dma_buffer)
|
|
|
|
return -EIO;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
do {
|
2019-07-25 02:52:03 +00:00
|
|
|
addr = get_unaligned_le32(&buffer[offset]);
|
|
|
|
size = get_unaligned_le32(&buffer[offset + 4]);
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
|
2015-05-11 05:30:56 +00:00
|
|
|
offset += 8;
|
|
|
|
while (((int)size) && (offset < buffer_size)) {
|
2015-08-08 12:11:36 +00:00
|
|
|
if (size <= blksz)
|
2015-05-11 05:30:56 +00:00
|
|
|
size2 = size;
|
2015-08-08 12:11:36 +00:00
|
|
|
else
|
2015-05-11 05:30:56 +00:00
|
|
|
size2 = blksz;
|
2015-11-06 02:12:25 +00:00
|
|
|
|
2015-05-11 05:30:56 +00:00
|
|
|
memcpy(dma_buffer, &buffer[offset], size2);
|
2016-02-04 09:15:49 +00:00
|
|
|
ret = wilc->hif_func->hif_block_tx(wilc, addr,
|
|
|
|
dma_buffer, size2);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
addr += size2;
|
|
|
|
offset += size2;
|
|
|
|
size -= size2;
|
|
|
|
}
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
if (!ret) {
|
2015-11-06 02:19:55 +00:00
|
|
|
ret = -EIO;
|
2018-04-23 16:33:32 +00:00
|
|
|
goto fail;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
} while (offset < buffer_size);
|
|
|
|
|
2018-04-23 16:33:32 +00:00
|
|
|
fail:
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-09-04 02:04:19 +00:00
|
|
|
kfree(dma_buffer);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return (ret < 0) ? ret : 0;
|
|
|
|
}
|
|
|
|
|
2015-11-16 14:05:10 +00:00
|
|
|
int wilc_wlan_start(struct wilc *wilc)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 reg = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
int ret;
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 chipid;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
if (wilc->io_type == WILC_HIF_SDIO) {
|
2015-05-11 05:30:56 +00:00
|
|
|
reg = 0;
|
2015-11-06 02:12:25 +00:00
|
|
|
reg |= BIT(3);
|
2018-11-12 05:45:20 +00:00
|
|
|
} else if (wilc->io_type == WILC_HIF_SPI) {
|
2015-05-11 05:30:56 +00:00
|
|
|
reg = 1;
|
|
|
|
}
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
|
2015-12-21 05:18:09 +00:00
|
|
|
ret = wilc->hif_func->hif_write_reg(wilc, WILC_VMM_CORE_CFG, reg);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2016-09-20 07:48:40 +00:00
|
|
|
return -EIO;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
reg = 0;
|
2018-11-12 05:45:20 +00:00
|
|
|
if (wilc->io_type == WILC_HIF_SDIO && wilc->dev_irq_num)
|
2015-11-16 14:05:04 +00:00
|
|
|
reg |= WILC_HAVE_SDIO_IRQ_GPIO;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
#ifdef WILC_DISABLE_PMU
|
|
|
|
#else
|
|
|
|
reg |= WILC_HAVE_USE_PMU;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WILC_SLEEP_CLK_SRC_XO
|
|
|
|
reg |= WILC_HAVE_SLEEP_CLK_SRC_XO;
|
|
|
|
#elif defined WILC_SLEEP_CLK_SRC_RTC
|
|
|
|
reg |= WILC_HAVE_SLEEP_CLK_SRC_RTC;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef WILC_EXT_PA_INV_TX_RX
|
|
|
|
reg |= WILC_HAVE_EXT_PA_INV_TX_RX;
|
|
|
|
#endif
|
2016-01-25 07:35:07 +00:00
|
|
|
reg |= WILC_HAVE_USE_IRQ_AS_HOST_WAKE;
|
2015-05-11 05:30:56 +00:00
|
|
|
reg |= WILC_HAVE_LEGACY_RF_SETTINGS;
|
|
|
|
#ifdef XTAL_24
|
|
|
|
reg |= WILC_HAVE_XTAL_24;
|
|
|
|
#endif
|
|
|
|
#ifdef DISABLE_WILC_UART
|
|
|
|
reg |= WILC_HAVE_DISABLE_WILC_UART;
|
|
|
|
#endif
|
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_1, reg);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2016-09-30 13:44:36 +00:00
|
|
|
return -EIO;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_sync_ext(wilc, NUM_INT_EXT);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
ret = wilc->hif_func->hif_read_reg(wilc, 0x1000, &chipid);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2016-09-30 13:44:36 +00:00
|
|
|
return -EIO;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
|
2015-09-29 19:15:49 +00:00
|
|
|
if ((reg & BIT(10)) == BIT(10)) {
|
|
|
|
reg &= ~BIT(10);
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
|
|
|
|
wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-29 19:15:49 +00:00
|
|
|
reg |= BIT(10);
|
2015-12-21 05:18:09 +00:00
|
|
|
ret = wilc->hif_func->hif_write_reg(wilc, WILC_GLB_RESET_0, reg);
|
|
|
|
wilc->hif_func->hif_read_reg(wilc, WILC_GLB_RESET_0, ®);
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return (ret < 0) ? ret : 0;
|
|
|
|
}
|
|
|
|
|
2019-08-09 18:25:18 +00:00
|
|
|
int wilc_wlan_stop(struct wilc *wilc, struct wilc_vif *vif)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 reg = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
int ret;
|
2016-02-04 09:15:53 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_AND_WAKEUP);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2019-08-09 18:25:18 +00:00
|
|
|
ret = wilc->hif_func->hif_read_reg(wilc, WILC_GP_REG_0, ®);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2019-08-09 18:25:18 +00:00
|
|
|
netdev_err(vif->ndev, "Error while reading reg\n");
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2019-08-09 18:25:19 +00:00
|
|
|
return -EIO;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 18:25:18 +00:00
|
|
|
ret = wilc->hif_func->hif_write_reg(wilc, WILC_GP_REG_0,
|
|
|
|
(reg | WILC_ABORT_REQ_BIT));
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2019-08-09 18:25:18 +00:00
|
|
|
netdev_err(vif->ndev, "Error while writing reg\n");
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2019-08-09 18:25:19 +00:00
|
|
|
return -EIO;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2019-08-09 18:25:18 +00:00
|
|
|
ret = wilc->hif_func->hif_read_reg(wilc, WILC_FW_HOST_COMM, ®);
|
|
|
|
if (!ret) {
|
|
|
|
netdev_err(vif->ndev, "Error while reading reg\n");
|
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2019-08-09 18:25:19 +00:00
|
|
|
return -EIO;
|
2019-08-09 18:25:18 +00:00
|
|
|
}
|
|
|
|
reg = BIT(0);
|
2015-09-29 19:15:48 +00:00
|
|
|
|
2019-08-09 18:25:18 +00:00
|
|
|
ret = wilc->hif_func->hif_write_reg(wilc, WILC_FW_HOST_COMM, reg);
|
|
|
|
if (!ret) {
|
|
|
|
netdev_err(vif->ndev, "Error while writing reg\n");
|
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2019-08-09 18:25:19 +00:00
|
|
|
return -EIO;
|
2019-08-09 18:25:18 +00:00
|
|
|
}
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ALLOW_SLEEP);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2019-08-09 18:25:19 +00:00
|
|
|
return 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-27 09:27:54 +00:00
|
|
|
void wilc_wlan_cleanup(struct net_device *dev)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
struct txq_entry_t *tqe;
|
|
|
|
struct rxq_entry_t *rqe;
|
2018-07-18 22:45:19 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->quit = 1;
|
2015-05-11 05:30:56 +00:00
|
|
|
do {
|
2015-10-29 03:18:43 +00:00
|
|
|
tqe = wilc_wlan_txq_remove_from_head(dev);
|
2015-11-06 02:12:31 +00:00
|
|
|
if (!tqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
|
|
|
if (tqe->tx_complete_func)
|
|
|
|
tqe->tx_complete_func(tqe->priv, 0);
|
2015-09-04 02:04:19 +00:00
|
|
|
kfree(tqe);
|
2015-05-11 05:30:56 +00:00
|
|
|
} while (1);
|
|
|
|
|
|
|
|
do {
|
2015-10-27 09:27:55 +00:00
|
|
|
rqe = wilc_wlan_rxq_remove(wilc);
|
2015-11-06 02:12:31 +00:00
|
|
|
if (!rqe)
|
2015-05-11 05:30:56 +00:00
|
|
|
break;
|
2015-09-04 02:04:19 +00:00
|
|
|
kfree(rqe);
|
2015-05-11 05:30:56 +00:00
|
|
|
} while (1);
|
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
kfree(wilc->rx_buffer);
|
|
|
|
wilc->rx_buffer = NULL;
|
|
|
|
kfree(wilc->tx_buffer);
|
2015-12-21 05:18:50 +00:00
|
|
|
wilc->tx_buffer = NULL;
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_deinit(NULL);
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2016-02-04 09:15:31 +00:00
|
|
|
static int wilc_wlan_cfg_commit(struct wilc_vif *vif, int type,
|
|
|
|
u32 drv_handler)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2016-02-04 09:15:31 +00:00
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-12-21 05:18:12 +00:00
|
|
|
struct wilc_cfg_frame *cfg = &wilc->cfg_frame;
|
2019-01-17 13:21:15 +00:00
|
|
|
int t_len = wilc->cfg_frame_offset + sizeof(struct wilc_cfg_cmd_hdr);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-06 02:13:07 +00:00
|
|
|
if (type == WILC_CFG_SET)
|
2019-01-17 13:21:15 +00:00
|
|
|
cfg->hdr.cmd_type = 'W';
|
2015-11-06 02:13:07 +00:00
|
|
|
else
|
2019-01-17 13:21:15 +00:00
|
|
|
cfg->hdr.cmd_type = 'Q';
|
|
|
|
|
|
|
|
cfg->hdr.seq_no = wilc->cfg_seq_no % 256;
|
|
|
|
cfg->hdr.total_len = cpu_to_le16(t_len);
|
|
|
|
cfg->hdr.driver_handler = cpu_to_le32(drv_handler);
|
|
|
|
wilc->cfg_seq_no = cfg->hdr.seq_no;
|
|
|
|
|
|
|
|
if (!wilc_wlan_txq_add_cfg_pkt(vif, (u8 *)&cfg->hdr, t_len))
|
2015-05-11 05:30:56 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-28 04:55:56 +00:00
|
|
|
int wilc_wlan_cfg_set(struct wilc_vif *vif, int start, u16 wid, u8 *buffer,
|
2015-11-18 06:11:34 +00:00
|
|
|
u32 buffer_size, int commit, u32 drv_handler)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 offset;
|
2015-05-11 05:30:56 +00:00
|
|
|
int ret_size;
|
2016-02-04 09:15:31 +00:00
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-12-02 18:02:25 +00:00
|
|
|
mutex_lock(&wilc->cfg_cmd_lock);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
if (start)
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->cfg_frame_offset = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
offset = wilc->cfg_frame_offset;
|
|
|
|
ret_size = wilc_wlan_cfg_set_wid(wilc->cfg_frame.frame, offset,
|
2016-03-28 04:55:56 +00:00
|
|
|
wid, buffer, buffer_size);
|
2015-05-11 05:30:56 +00:00
|
|
|
offset += ret_size;
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->cfg_frame_offset = offset;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-12-02 18:02:25 +00:00
|
|
|
if (!commit) {
|
|
|
|
mutex_unlock(&wilc->cfg_cmd_lock);
|
2018-03-02 14:17:19 +00:00
|
|
|
return ret_size;
|
2018-12-02 18:02:25 +00:00
|
|
|
}
|
2016-06-15 05:30:36 +00:00
|
|
|
|
2018-07-29 06:06:53 +00:00
|
|
|
netdev_dbg(vif->ndev, "%s: seqno[%d]\n", __func__, wilc->cfg_seq_no);
|
2018-03-02 14:17:19 +00:00
|
|
|
|
|
|
|
if (wilc_wlan_cfg_commit(vif, WILC_CFG_SET, drv_handler))
|
|
|
|
ret_size = 0;
|
|
|
|
|
|
|
|
if (!wait_for_completion_timeout(&wilc->cfg_event,
|
2019-02-02 19:17:05 +00:00
|
|
|
WILC_CFG_PKTS_TIMEOUT)) {
|
2018-07-29 06:06:53 +00:00
|
|
|
netdev_dbg(vif->ndev, "%s: Timed Out\n", __func__);
|
2018-03-02 14:17:19 +00:00
|
|
|
ret_size = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 14:17:19 +00:00
|
|
|
wilc->cfg_frame_offset = 0;
|
|
|
|
wilc->cfg_seq_no += 1;
|
2018-12-02 18:02:25 +00:00
|
|
|
mutex_unlock(&wilc->cfg_cmd_lock);
|
2018-03-02 14:17:19 +00:00
|
|
|
|
2015-05-11 05:30:56 +00:00
|
|
|
return ret_size;
|
|
|
|
}
|
2015-11-06 02:12:28 +00:00
|
|
|
|
2016-03-28 04:55:57 +00:00
|
|
|
int wilc_wlan_cfg_get(struct wilc_vif *vif, int start, u16 wid, int commit,
|
2015-11-18 06:11:35 +00:00
|
|
|
u32 drv_handler)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 offset;
|
2015-05-11 05:30:56 +00:00
|
|
|
int ret_size;
|
2016-02-04 09:15:31 +00:00
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-12-02 18:02:25 +00:00
|
|
|
mutex_lock(&wilc->cfg_cmd_lock);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
if (start)
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->cfg_frame_offset = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
offset = wilc->cfg_frame_offset;
|
2016-03-28 04:55:57 +00:00
|
|
|
ret_size = wilc_wlan_cfg_get_wid(wilc->cfg_frame.frame, offset, wid);
|
2015-05-11 05:30:56 +00:00
|
|
|
offset += ret_size;
|
2015-12-21 05:18:12 +00:00
|
|
|
wilc->cfg_frame_offset = offset;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-12-02 18:02:25 +00:00
|
|
|
if (!commit) {
|
|
|
|
mutex_unlock(&wilc->cfg_cmd_lock);
|
2018-03-02 14:17:18 +00:00
|
|
|
return ret_size;
|
2018-12-02 18:02:25 +00:00
|
|
|
}
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-03-02 14:17:18 +00:00
|
|
|
if (wilc_wlan_cfg_commit(vif, WILC_CFG_QUERY, drv_handler))
|
|
|
|
ret_size = 0;
|
|
|
|
|
|
|
|
if (!wait_for_completion_timeout(&wilc->cfg_event,
|
2019-02-02 19:17:05 +00:00
|
|
|
WILC_CFG_PKTS_TIMEOUT)) {
|
2018-07-29 06:06:53 +00:00
|
|
|
netdev_dbg(vif->ndev, "%s: Timed Out\n", __func__);
|
2018-03-02 14:17:18 +00:00
|
|
|
ret_size = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2018-03-02 14:17:18 +00:00
|
|
|
wilc->cfg_frame_offset = 0;
|
|
|
|
wilc->cfg_seq_no += 1;
|
2018-12-02 18:02:25 +00:00
|
|
|
mutex_unlock(&wilc->cfg_cmd_lock);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return ret_size;
|
|
|
|
}
|
|
|
|
|
2016-02-11 04:46:22 +00:00
|
|
|
int wilc_send_config_pkt(struct wilc_vif *vif, u8 mode, struct wid *wids,
|
2019-06-26 12:41:04 +00:00
|
|
|
u32 count)
|
2016-02-04 09:15:30 +00:00
|
|
|
{
|
2016-02-11 04:46:25 +00:00
|
|
|
int i;
|
2016-02-11 04:46:22 +00:00
|
|
|
int ret = 0;
|
2019-06-26 12:41:04 +00:00
|
|
|
u32 drv = wilc_get_vif_idx(vif);
|
2016-02-04 09:15:30 +00:00
|
|
|
|
2018-11-12 05:45:29 +00:00
|
|
|
if (mode == WILC_GET_CFG) {
|
2016-02-11 04:46:25 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (!wilc_wlan_cfg_get(vif, !i,
|
|
|
|
wids[i].id,
|
|
|
|
(i == count - 1),
|
2016-02-04 09:15:30 +00:00
|
|
|
drv)) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 04:46:25 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2018-09-25 06:23:32 +00:00
|
|
|
wids[i].size = wilc_wlan_cfg_get_val(vif->wilc,
|
|
|
|
wids[i].id,
|
2016-02-11 04:46:25 +00:00
|
|
|
wids[i].val,
|
|
|
|
wids[i].size);
|
2016-02-04 09:15:30 +00:00
|
|
|
}
|
2018-11-12 05:45:29 +00:00
|
|
|
} else if (mode == WILC_SET_CFG) {
|
2016-02-11 04:46:25 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (!wilc_wlan_cfg_set(vif, !i,
|
|
|
|
wids[i].id,
|
|
|
|
wids[i].val,
|
|
|
|
wids[i].size,
|
|
|
|
(i == count - 1),
|
2016-02-04 09:15:30 +00:00
|
|
|
drv)) {
|
|
|
|
ret = -ETIMEDOUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-11-16 14:04:53 +00:00
|
|
|
static u32 init_chip(struct net_device *dev)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
u32 chipid;
|
|
|
|
u32 reg, ret = 0;
|
2018-07-18 22:45:19 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
|
|
|
struct wilc *wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2018-11-12 05:45:20 +00:00
|
|
|
acquire_bus(wilc, WILC_BUS_ACQUIRE_ONLY);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-11-18 06:11:25 +00:00
|
|
|
chipid = wilc_get_chipid(wilc, true);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
if ((chipid & 0xfff) != 0xa0) {
|
2015-12-21 05:18:09 +00:00
|
|
|
ret = wilc->hif_func->hif_read_reg(wilc, 0x1118, ®);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2016-02-22 04:41:11 +00:00
|
|
|
netdev_err(dev, "fail read reg 0x1118\n");
|
2018-12-21 09:12:02 +00:00
|
|
|
goto release;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2015-09-29 19:15:49 +00:00
|
|
|
reg |= BIT(0);
|
2015-12-21 05:18:09 +00:00
|
|
|
ret = wilc->hif_func->hif_write_reg(wilc, 0x1118, reg);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2016-02-22 04:41:11 +00:00
|
|
|
netdev_err(dev, "fail write reg 0x1118\n");
|
2018-12-21 09:12:02 +00:00
|
|
|
goto release;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
2015-12-21 05:18:09 +00:00
|
|
|
ret = wilc->hif_func->hif_write_reg(wilc, 0xc0000, 0x71);
|
2015-05-11 05:30:56 +00:00
|
|
|
if (!ret) {
|
2016-02-22 04:41:11 +00:00
|
|
|
netdev_err(dev, "fail write reg 0xc0000\n");
|
2018-12-21 09:12:02 +00:00
|
|
|
goto release;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-21 09:12:02 +00:00
|
|
|
release:
|
2018-11-12 05:45:20 +00:00
|
|
|
release_bus(wilc, WILC_BUS_RELEASE_ONLY);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-02-04 09:15:54 +00:00
|
|
|
u32 wilc_get_chipid(struct wilc *wilc, bool update)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
2015-09-15 05:06:16 +00:00
|
|
|
static u32 chipid;
|
|
|
|
u32 tempchipid = 0;
|
2016-02-04 09:15:54 +00:00
|
|
|
u32 rfrevid = 0;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-02-04 09:15:54 +00:00
|
|
|
if (chipid == 0 || update) {
|
2015-12-21 05:18:09 +00:00
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0x1000, &tempchipid);
|
|
|
|
wilc->hif_func->hif_read_reg(wilc, 0x13f4, &rfrevid);
|
2018-08-03 10:56:14 +00:00
|
|
|
if (!is_wilc1000(tempchipid)) {
|
2015-05-11 05:30:56 +00:00
|
|
|
chipid = 0;
|
2016-02-04 09:15:54 +00:00
|
|
|
return chipid;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
if (tempchipid == 0x1002a0) {
|
2016-02-04 09:15:54 +00:00
|
|
|
if (rfrevid != 0x1)
|
2015-05-11 05:30:56 +00:00
|
|
|
tempchipid = 0x1002a1;
|
|
|
|
} else if (tempchipid == 0x1002b0) {
|
2016-02-04 09:15:54 +00:00
|
|
|
if (rfrevid == 0x4)
|
2015-05-11 05:30:56 +00:00
|
|
|
tempchipid = 0x1002b1;
|
2016-02-04 09:15:54 +00:00
|
|
|
else if (rfrevid != 0x3)
|
2015-05-11 05:30:56 +00:00
|
|
|
tempchipid = 0x1002b2;
|
|
|
|
}
|
|
|
|
|
|
|
|
chipid = tempchipid;
|
|
|
|
}
|
|
|
|
return chipid;
|
|
|
|
}
|
|
|
|
|
2015-11-16 14:04:59 +00:00
|
|
|
int wilc_wlan_init(struct net_device *dev)
|
2015-05-11 05:30:56 +00:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2015-12-21 05:18:36 +00:00
|
|
|
struct wilc_vif *vif = netdev_priv(dev);
|
2015-11-06 09:40:22 +00:00
|
|
|
struct wilc *wilc;
|
|
|
|
|
2015-12-21 05:18:36 +00:00
|
|
|
wilc = vif->wilc;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2016-01-25 07:35:05 +00:00
|
|
|
wilc->quit = 0;
|
|
|
|
|
2016-01-25 07:35:09 +00:00
|
|
|
if (!wilc->hif_func->hif_init(wilc, false)) {
|
2015-11-06 09:39:58 +00:00
|
|
|
ret = -EIO;
|
2018-04-23 16:33:32 +00:00
|
|
|
goto fail;
|
2015-11-06 09:39:58 +00:00
|
|
|
}
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
if (!wilc->tx_buffer)
|
2019-02-07 11:29:01 +00:00
|
|
|
wilc->tx_buffer = kmalloc(WILC_TX_BUFF_SIZE, GFP_KERNEL);
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
if (!wilc->tx_buffer) {
|
2015-11-06 02:19:55 +00:00
|
|
|
ret = -ENOBUFS;
|
2018-04-23 16:33:32 +00:00
|
|
|
goto fail;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
if (!wilc->rx_buffer)
|
2019-02-07 11:29:01 +00:00
|
|
|
wilc->rx_buffer = kmalloc(WILC_RX_BUFF_SIZE, GFP_KERNEL);
|
2016-02-04 09:15:50 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
if (!wilc->rx_buffer) {
|
2015-11-06 02:19:55 +00:00
|
|
|
ret = -ENOBUFS;
|
2018-04-23 16:33:32 +00:00
|
|
|
goto fail;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
2015-10-29 03:18:48 +00:00
|
|
|
if (!init_chip(dev)) {
|
2015-11-06 02:19:55 +00:00
|
|
|
ret = -EIO;
|
2018-04-23 16:33:32 +00:00
|
|
|
goto fail;
|
2015-05-11 05:30:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
2018-04-23 16:33:32 +00:00
|
|
|
fail:
|
2015-05-11 05:30:56 +00:00
|
|
|
|
2015-12-21 05:18:12 +00:00
|
|
|
kfree(wilc->rx_buffer);
|
|
|
|
wilc->rx_buffer = NULL;
|
|
|
|
kfree(wilc->tx_buffer);
|
|
|
|
wilc->tx_buffer = NULL;
|
2015-05-11 05:30:56 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|