1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012 - 2018 Microchip Technology Inc., and its subsidiaries.
8 #include <linux/kthread.h>
9 #include <linux/firmware.h>
10 #include <linux/netdevice.h>
11 #include <linux/inetdevice.h>
16 #define WILC_MULTICAST_TABLE_SIZE 8
17 #define WILC_MAX_FW_VERSION_STR_SIZE 50
19 /* latest API version supported */
20 #define WILC1000_API_VER 1
22 #define WILC1000_FW_PREFIX "atmel/wilc1000_wifi_firmware-"
23 #define __WILC1000_FW(api) WILC1000_FW_PREFIX #api ".bin"
24 #define WILC1000_FW(api) __WILC1000_FW(api)
26 #define WILC3000_API_VER 1
28 #define WILC3000_FW_PREFIX "atmel/wilc3000_wifi_firmware-"
29 #define __WILC3000_FW(api) WILC3000_FW_PREFIX #api ".bin"
30 #define WILC3000_FW(api) __WILC3000_FW(api)
32 static irqreturn_t
isr_uh_routine(int irq
, void *user_data
)
34 struct wilc
*wilc
= user_data
;
37 pr_err("Can't handle UH interrupt\n");
40 return IRQ_WAKE_THREAD
;
43 static irqreturn_t
isr_bh_routine(int irq
, void *userdata
)
45 struct wilc
*wilc
= userdata
;
48 pr_err("Can't handle BH interrupt\n");
52 wilc_handle_isr(wilc
);
57 static int init_irq(struct net_device
*dev
)
59 struct wilc_vif
*vif
= netdev_priv(dev
);
60 struct wilc
*wl
= vif
->wilc
;
63 ret
= request_threaded_irq(wl
->dev_irq_num
, isr_uh_routine
,
65 IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
,
68 netdev_err(dev
, "Failed to request IRQ [%d]\n", ret
);
71 netdev_dbg(dev
, "IRQ request succeeded IRQ-NUM= %d\n", wl
->dev_irq_num
);
76 static void deinit_irq(struct net_device
*dev
)
78 struct wilc_vif
*vif
= netdev_priv(dev
);
79 struct wilc
*wilc
= vif
->wilc
;
81 /* Deinitialize IRQ */
82 if (wilc
->dev_irq_num
)
83 free_irq(wilc
->dev_irq_num
, wilc
);
86 void wilc_mac_indicate(struct wilc
*wilc
)
90 wilc_wlan_cfg_get_val(wilc
, WID_STATUS
, &status
, 1);
91 if (wilc
->mac_status
== WILC_MAC_STATUS_INIT
) {
92 wilc
->mac_status
= status
;
93 complete(&wilc
->sync_event
);
95 wilc
->mac_status
= status
;
99 static struct net_device
*get_if_handler(struct wilc
*wilc
, u8
*mac_header
)
101 struct net_device
*ndev
= NULL
;
102 struct wilc_vif
*vif
;
103 struct ieee80211_hdr
*h
= (struct ieee80211_hdr
*)mac_header
;
105 wilc_for_each_vif(wilc
, vif
) {
106 if (vif
->iftype
== WILC_STATION_MODE
)
107 if (ether_addr_equal_unaligned(h
->addr2
, vif
->bssid
)) {
111 if (vif
->iftype
== WILC_AP_MODE
)
112 if (ether_addr_equal_unaligned(h
->addr1
, vif
->bssid
)) {
121 void wilc_wlan_set_bssid(struct net_device
*wilc_netdev
, const u8
*bssid
,
124 struct wilc_vif
*vif
= netdev_priv(wilc_netdev
);
127 ether_addr_copy(vif
->bssid
, bssid
);
129 eth_zero_addr(vif
->bssid
);
134 int wilc_wlan_get_num_conn_ifcs(struct wilc
*wilc
)
138 struct wilc_vif
*vif
;
140 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
141 wilc_for_each_vif(wilc
, vif
) {
142 if (!is_zero_ether_addr(vif
->bssid
))
145 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
149 static void wilc_wake_tx_queues(struct wilc
*wl
)
152 struct wilc_vif
*ifc
;
154 srcu_idx
= srcu_read_lock(&wl
->srcu
);
155 wilc_for_each_vif(wl
, ifc
) {
156 if (ifc
->mac_opened
&& netif_queue_stopped(ifc
->ndev
))
157 netif_wake_queue(ifc
->ndev
);
159 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
162 static int wilc_txq_task(void *vp
)
166 struct wilc
*wl
= vp
;
168 complete(&wl
->txq_thread_started
);
170 if (wait_for_completion_interruptible(&wl
->txq_event
))
173 complete(&wl
->txq_thread_started
);
175 while (!kthread_should_stop())
180 ret
= wilc_wlan_handle_txq(wl
, &txq_count
);
181 if (txq_count
< FLOW_CONTROL_LOWER_THRESHOLD
) {
182 wilc_wake_tx_queues(wl
);
184 if (ret
!= WILC_VMM_ENTRY_FULL_RETRY
)
186 /* Back off TX task from sending packets for some time.
187 * msleep_interruptible will allow RX task to run and
188 * free buffers. TX task will be in TASK_INTERRUPTIBLE
189 * state which will put the thread back to CPU running
190 * queue when it's signaled even if the timeout isn't
191 * elapsed. This gives faster chance for reserved SK
192 * buffers to be free.
194 msleep_interruptible(TX_BACKOFF_WEIGHT_MS
);
195 } while (!wl
->close
);
200 static int wilc_wlan_get_firmware(struct net_device
*dev
)
202 struct wilc_vif
*vif
= netdev_priv(dev
);
203 struct wilc
*wilc
= vif
->wilc
;
204 const struct firmware
*wilc_fw
;
208 if (is_wilc1000(wilc
->chipid
))
209 firmware
= WILC1000_FW(WILC1000_API_VER
);
210 else if (is_wilc3000(wilc
->chipid
))
211 firmware
= WILC3000_FW(WILC3000_API_VER
);
215 netdev_info(dev
, "WILC%d loading firmware [%s]\n",
216 is_wilc1000(wilc
->chipid
) ? 1000 : 3000,
219 ret
= request_firmware(&wilc_fw
, firmware
, wilc
->dev
);
221 netdev_err(dev
, "%s - firmware not available\n", firmware
);
224 wilc
->firmware
= wilc_fw
;
229 static int wilc_start_firmware(struct net_device
*dev
)
231 struct wilc_vif
*vif
= netdev_priv(dev
);
232 struct wilc
*wilc
= vif
->wilc
;
235 ret
= wilc_wlan_start(wilc
);
239 if (!wait_for_completion_timeout(&wilc
->sync_event
,
240 msecs_to_jiffies(5000)))
246 static int wilc_firmware_download(struct net_device
*dev
)
248 struct wilc_vif
*vif
= netdev_priv(dev
);
249 struct wilc
*wilc
= vif
->wilc
;
252 if (!wilc
->firmware
) {
253 netdev_err(dev
, "Firmware buffer is NULL\n");
257 ret
= wilc_wlan_firmware_download(wilc
, wilc
->firmware
->data
,
258 wilc
->firmware
->size
);
262 release_firmware(wilc
->firmware
);
263 wilc
->firmware
= NULL
;
265 netdev_dbg(dev
, "Download Succeeded\n");
270 static int wilc_init_fw_config(struct net_device
*dev
, struct wilc_vif
*vif
)
272 struct wilc_priv
*priv
= &vif
->priv
;
273 struct host_if_drv
*hif_drv
;
278 netdev_dbg(dev
, "Start configuring Firmware\n");
279 hif_drv
= (struct host_if_drv
*)priv
->hif_drv
;
280 netdev_dbg(dev
, "Host = %p\n", hif_drv
);
284 if (!wilc_wlan_cfg_set(vif
, 1, WID_SET_OPERATION_MODE
, (u8
*)&w
, 4,
288 b
= WILC_FW_BSS_TYPE_INFRA
;
289 if (!wilc_wlan_cfg_set(vif
, 0, WID_BSS_TYPE
, &b
, 1, 0, 0))
292 b
= WILC_FW_TX_RATE_AUTO
;
293 if (!wilc_wlan_cfg_set(vif
, 0, WID_CURRENT_TX_RATE
, &b
, 1, 0, 0))
296 b
= WILC_FW_OPER_MODE_G_MIXED_11B_2
;
297 if (!wilc_wlan_cfg_set(vif
, 0, WID_11G_OPERATING_MODE
, &b
, 1, 0, 0))
300 b
= WILC_FW_PREAMBLE_AUTO
;
301 if (!wilc_wlan_cfg_set(vif
, 0, WID_PREAMBLE
, &b
, 1, 0, 0))
304 b
= WILC_FW_11N_PROT_AUTO
;
305 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_PROT_MECH
, &b
, 1, 0, 0))
308 b
= WILC_FW_ACTIVE_SCAN
;
309 if (!wilc_wlan_cfg_set(vif
, 0, WID_SCAN_TYPE
, &b
, 1, 0, 0))
312 b
= WILC_FW_SITE_SURVEY_OFF
;
313 if (!wilc_wlan_cfg_set(vif
, 0, WID_SITE_SURVEY
, &b
, 1, 0, 0))
318 if (!wilc_wlan_cfg_set(vif
, 0, WID_RTS_THRESHOLD
, (u8
*)&hw
, 2, 0, 0))
323 if (!wilc_wlan_cfg_set(vif
, 0, WID_FRAG_THRESHOLD
, (u8
*)&hw
, 2, 0, 0))
327 if (!wilc_wlan_cfg_set(vif
, 0, WID_BCAST_SSID
, &b
, 1, 0, 0))
331 if (!wilc_wlan_cfg_set(vif
, 0, WID_QOS_ENABLE
, &b
, 1, 0, 0))
334 b
= WILC_FW_NO_POWERSAVE
;
335 if (!wilc_wlan_cfg_set(vif
, 0, WID_POWER_MANAGEMENT
, &b
, 1, 0, 0))
339 if (!wilc_wlan_cfg_set(vif
, 0, WID_11I_MODE
, &b
, 1, 0, 0))
342 b
= WILC_FW_AUTH_OPEN_SYSTEM
;
343 if (!wilc_wlan_cfg_set(vif
, 0, WID_AUTH_TYPE
, &b
, 1, 0, 0))
347 if (!wilc_wlan_cfg_set(vif
, 0, WID_LISTEN_INTERVAL
, &b
, 1, 0, 0))
351 if (!wilc_wlan_cfg_set(vif
, 0, WID_DTIM_PERIOD
, &b
, 1, 0, 0))
354 b
= WILC_FW_ACK_POLICY_NORMAL
;
355 if (!wilc_wlan_cfg_set(vif
, 0, WID_ACK_POLICY
, &b
, 1, 0, 0))
359 if (!wilc_wlan_cfg_set(vif
, 0, WID_USER_CONTROL_ON_TX_POWER
, &b
, 1,
364 if (!wilc_wlan_cfg_set(vif
, 0, WID_TX_POWER_LEVEL_11A
, &b
, 1, 0, 0))
368 if (!wilc_wlan_cfg_set(vif
, 0, WID_TX_POWER_LEVEL_11B
, &b
, 1, 0, 0))
373 if (!wilc_wlan_cfg_set(vif
, 0, WID_BEACON_INTERVAL
, (u8
*)&hw
, 2, 0, 0))
376 b
= WILC_FW_REKEY_POLICY_DISABLE
;
377 if (!wilc_wlan_cfg_set(vif
, 0, WID_REKEY_POLICY
, &b
, 1, 0, 0))
382 if (!wilc_wlan_cfg_set(vif
, 0, WID_REKEY_PERIOD
, (u8
*)&w
, 4, 0, 0))
387 if (!wilc_wlan_cfg_set(vif
, 0, WID_REKEY_PACKET_COUNT
, (u8
*)&w
, 4, 0,
392 if (!wilc_wlan_cfg_set(vif
, 0, WID_SHORT_SLOT_ALLOWED
, &b
, 1, 0,
396 b
= WILC_FW_ERP_PROT_SELF_CTS
;
397 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_ERP_PROT_TYPE
, &b
, 1, 0, 0))
401 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_ENABLE
, &b
, 1, 0, 0))
404 b
= WILC_FW_11N_OP_MODE_HT_MIXED
;
405 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_OPERATING_MODE
, &b
, 1, 0, 0))
409 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_TXOP_PROT_DISABLE
, &b
, 1, 0, 0))
412 b
= WILC_FW_OBBS_NONHT_DETECT_PROTECT_REPORT
;
413 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_OBSS_NONHT_DETECTION
, &b
, 1,
417 b
= WILC_FW_HT_PROT_RTS_CTS_NONHT
;
418 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_HT_PROT_TYPE
, &b
, 1, 0, 0))
422 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_RIFS_PROT_ENABLE
, &b
, 1, 0,
427 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_CURRENT_TX_MCS
, &b
, 1, 0, 0))
431 if (!wilc_wlan_cfg_set(vif
, 0, WID_11N_IMMEDIATE_BA_ENABLED
, &b
, 1,
441 static void wlan_deinitialize_threads(struct net_device
*dev
)
443 struct wilc_vif
*vif
= netdev_priv(dev
);
444 struct wilc
*wl
= vif
->wilc
;
448 complete(&wl
->txq_event
);
450 if (wl
->txq_thread
) {
451 kthread_stop(wl
->txq_thread
);
452 wl
->txq_thread
= NULL
;
456 static void wilc_wlan_deinitialize(struct net_device
*dev
)
458 struct wilc_vif
*vif
= netdev_priv(dev
);
459 struct wilc
*wl
= vif
->wilc
;
462 netdev_err(dev
, "wl is NULL\n");
466 if (wl
->initialized
) {
467 netdev_info(dev
, "Deinitializing wilc1000...\n");
469 if (!wl
->dev_irq_num
&&
470 wl
->hif_func
->disable_interrupt
) {
471 mutex_lock(&wl
->hif_cs
);
472 wl
->hif_func
->disable_interrupt(wl
);
473 mutex_unlock(&wl
->hif_cs
);
475 complete(&wl
->txq_event
);
477 wlan_deinitialize_threads(dev
);
480 wilc_wlan_stop(wl
, vif
);
481 wilc_wlan_cleanup(dev
);
483 wl
->initialized
= false;
485 netdev_dbg(dev
, "wilc1000 deinitialization Done\n");
487 netdev_dbg(dev
, "wilc1000 is not initialized\n");
491 static int wlan_initialize_threads(struct net_device
*dev
)
493 struct wilc_vif
*vif
= netdev_priv(dev
);
494 struct wilc
*wilc
= vif
->wilc
;
496 wilc
->txq_thread
= kthread_run(wilc_txq_task
, (void *)wilc
,
498 if (IS_ERR(wilc
->txq_thread
)) {
499 netdev_err(dev
, "couldn't create TXQ thread\n");
501 return PTR_ERR(wilc
->txq_thread
);
503 wait_for_completion(&wilc
->txq_thread_started
);
508 static int wilc_wlan_initialize(struct net_device
*dev
, struct wilc_vif
*vif
)
511 struct wilc
*wl
= vif
->wilc
;
513 if (!wl
->initialized
) {
514 wl
->mac_status
= WILC_MAC_STATUS_INIT
;
517 ret
= wilc_wlan_init(dev
);
521 ret
= wlan_initialize_threads(dev
);
525 if (wl
->dev_irq_num
&& init_irq(dev
)) {
530 if (!wl
->dev_irq_num
&&
531 wl
->hif_func
->enable_interrupt
&&
532 wl
->hif_func
->enable_interrupt(wl
)) {
537 ret
= wilc_wlan_get_firmware(dev
);
539 goto fail_irq_enable
;
541 ret
= wilc_firmware_download(dev
);
543 goto fail_irq_enable
;
545 ret
= wilc_start_firmware(dev
);
547 goto fail_irq_enable
;
549 if (wilc_wlan_cfg_get(vif
, 1, WID_FIRMWARE_VERSION
, 1, 0)) {
551 char firmware_ver
[WILC_MAX_FW_VERSION_STR_SIZE
];
553 size
= wilc_wlan_cfg_get_val(wl
, WID_FIRMWARE_VERSION
,
555 sizeof(firmware_ver
));
556 firmware_ver
[size
] = '\0';
557 netdev_dbg(dev
, "Firmware Ver = %s\n", firmware_ver
);
560 ret
= wilc_init_fw_config(dev
, vif
);
562 netdev_err(dev
, "Failed to configure firmware\n");
565 wl
->initialized
= true;
569 wilc_wlan_stop(wl
, vif
);
572 if (!wl
->dev_irq_num
&&
573 wl
->hif_func
->disable_interrupt
)
574 wl
->hif_func
->disable_interrupt(wl
);
579 wlan_deinitialize_threads(dev
);
581 wilc_wlan_cleanup(dev
);
582 netdev_err(dev
, "WLAN initialization FAILED\n");
584 netdev_dbg(dev
, "wilc1000 already initialized\n");
589 static int mac_init_fn(struct net_device
*ndev
)
591 netif_start_queue(ndev
);
592 netif_stop_queue(ndev
);
597 static int wilc_mac_open(struct net_device
*ndev
)
599 struct wilc_vif
*vif
= netdev_priv(ndev
);
600 struct wilc
*wl
= vif
->wilc
;
602 struct mgmt_frame_regs mgmt_regs
= {};
604 if (!wl
|| !wl
->dev
) {
605 netdev_err(ndev
, "device not ready\n");
609 netdev_dbg(ndev
, "MAC OPEN[%p]\n", ndev
);
611 ret
= wilc_init_host_int(ndev
);
615 ret
= wilc_wlan_initialize(ndev
, vif
);
617 wilc_deinit_host_int(ndev
);
621 wilc_set_operation_mode(vif
, wilc_get_vif_idx(vif
), vif
->iftype
,
624 netdev_dbg(ndev
, "Mac address: %pM\n", ndev
->dev_addr
);
625 ret
= wilc_set_mac_address(vif
, ndev
->dev_addr
);
627 netdev_err(ndev
, "Failed to enforce MAC address in chip");
628 wilc_deinit_host_int(ndev
);
630 wilc_wlan_deinitialize(ndev
);
634 mgmt_regs
.interface_stypes
= vif
->mgmt_reg_stypes
;
635 /* so we detect a change */
636 vif
->mgmt_reg_stypes
= 0;
637 wilc_update_mgmt_frame_registrations(vif
->ndev
->ieee80211_ptr
->wiphy
,
638 vif
->ndev
->ieee80211_ptr
,
640 netif_wake_queue(ndev
);
646 static struct net_device_stats
*mac_stats(struct net_device
*dev
)
648 struct wilc_vif
*vif
= netdev_priv(dev
);
650 return &vif
->netstats
;
653 static int wilc_set_mac_addr(struct net_device
*dev
, void *p
)
656 struct wilc_vif
*vif
= netdev_priv(dev
);
657 struct wilc
*wilc
= vif
->wilc
;
658 struct sockaddr
*addr
= (struct sockaddr
*)p
;
659 unsigned char mac_addr
[ETH_ALEN
];
660 struct wilc_vif
*tmp_vif
;
663 if (!is_valid_ether_addr(addr
->sa_data
))
664 return -EADDRNOTAVAIL
;
666 if (!vif
->mac_opened
) {
667 eth_commit_mac_addr_change(dev
, p
);
671 /* Verify MAC Address is not already in use: */
673 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
674 wilc_for_each_vif(wilc
, tmp_vif
) {
675 wilc_get_mac_address(tmp_vif
, mac_addr
);
676 if (ether_addr_equal(addr
->sa_data
, mac_addr
)) {
677 if (vif
!= tmp_vif
) {
678 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
679 return -EADDRNOTAVAIL
;
681 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
685 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
687 result
= wilc_set_mac_address(vif
, addr
->sa_data
);
691 eth_commit_mac_addr_change(dev
, p
);
695 static void wilc_set_multicast_list(struct net_device
*dev
)
697 struct netdev_hw_addr
*ha
;
698 struct wilc_vif
*vif
= netdev_priv(dev
);
703 if (dev
->flags
& IFF_PROMISC
)
706 if (dev
->flags
& IFF_ALLMULTI
||
707 dev
->mc
.count
> WILC_MULTICAST_TABLE_SIZE
) {
708 wilc_setup_multicast_filter(vif
, 0, 0, NULL
);
712 if (dev
->mc
.count
== 0) {
713 wilc_setup_multicast_filter(vif
, 1, 0, NULL
);
717 mc_list
= kmalloc_array(dev
->mc
.count
, ETH_ALEN
, GFP_ATOMIC
);
723 netdev_for_each_mc_addr(ha
, dev
) {
724 memcpy(cur_mc
, ha
->addr
, ETH_ALEN
);
725 netdev_dbg(dev
, "Entry[%d]: %pM\n", i
, cur_mc
);
730 if (wilc_setup_multicast_filter(vif
, 1, dev
->mc
.count
, mc_list
))
734 static void wilc_tx_complete(void *priv
, int status
)
736 struct tx_complete_data
*pv_data
= priv
;
738 dev_kfree_skb(pv_data
->skb
);
742 netdev_tx_t
wilc_mac_xmit(struct sk_buff
*skb
, struct net_device
*ndev
)
744 struct wilc_vif
*vif
= netdev_priv(ndev
);
745 struct wilc
*wilc
= vif
->wilc
;
746 struct tx_complete_data
*tx_data
= NULL
;
749 if (skb
->dev
!= ndev
) {
750 netdev_err(ndev
, "Packet not destined to this device\n");
755 tx_data
= kmalloc(sizeof(*tx_data
), GFP_ATOMIC
);
758 netif_wake_queue(ndev
);
762 tx_data
->buff
= skb
->data
;
763 tx_data
->size
= skb
->len
;
766 vif
->netstats
.tx_packets
++;
767 vif
->netstats
.tx_bytes
+= tx_data
->size
;
768 queue_count
= wilc_wlan_txq_add_net_pkt(ndev
, tx_data
,
769 tx_data
->buff
, tx_data
->size
,
772 if (queue_count
> FLOW_CONTROL_UPPER_THRESHOLD
) {
774 struct wilc_vif
*vif
;
776 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
777 wilc_for_each_vif(wilc
, vif
) {
779 netif_stop_queue(vif
->ndev
);
781 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
787 static int wilc_mac_close(struct net_device
*ndev
)
789 struct wilc_vif
*vif
= netdev_priv(ndev
);
790 struct wilc
*wl
= vif
->wilc
;
792 netdev_dbg(ndev
, "Mac close\n");
794 if (wl
->open_ifcs
> 0)
800 netif_stop_queue(vif
->ndev
);
802 wilc_handle_disconnect(vif
);
803 wilc_deinit_host_int(vif
->ndev
);
806 if (wl
->open_ifcs
== 0) {
807 netdev_dbg(ndev
, "Deinitializing wilc1000\n");
809 wilc_wlan_deinitialize(ndev
);
817 void wilc_frmw_to_host(struct wilc
*wilc
, u8
*buff
, u32 size
,
820 unsigned char *buff_to_send
= NULL
;
821 struct net_device
*wilc_netdev
;
822 unsigned int frame_len
= 0;
823 struct wilc_vif
*vif
;
831 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
832 wilc_netdev
= get_if_handler(wilc
, buff
);
837 vif
= netdev_priv(wilc_netdev
);
843 skb
= dev_alloc_skb(frame_len
);
847 skb
->dev
= wilc_netdev
;
849 skb_put_data(skb
, buff_to_send
, frame_len
);
851 skb
->protocol
= eth_type_trans(skb
, wilc_netdev
);
852 vif
->netstats
.rx_packets
++;
853 vif
->netstats
.rx_bytes
+= frame_len
;
854 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
855 stats
= netif_rx(skb
);
856 netdev_dbg(wilc_netdev
, "netif_rx ret value is: %d\n", stats
);
859 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
862 void wilc_wfi_mgmt_rx(struct wilc
*wilc
, u8
*buff
, u32 size
, bool is_auth
)
865 struct wilc_vif
*vif
;
867 srcu_idx
= srcu_read_lock(&wilc
->srcu
);
868 wilc_for_each_vif(wilc
, vif
) {
869 struct ieee80211_mgmt
*mgmt
= (struct ieee80211_mgmt
*)buff
;
870 u16 type
= le16_to_cpup((__le16
*)buff
);
871 u32 type_bit
= BIT(type
>> 4);
872 u32 auth_bit
= BIT(IEEE80211_STYPE_AUTH
>> 4);
874 if ((vif
->mgmt_reg_stypes
& auth_bit
&&
875 ieee80211_is_auth(mgmt
->frame_control
)) &&
876 vif
->iftype
== WILC_STATION_MODE
&& is_auth
) {
877 wilc_wfi_mgmt_frame_rx(vif
, buff
, size
);
881 if (vif
->priv
.p2p_listen_state
&&
882 vif
->mgmt_reg_stypes
& type_bit
)
883 wilc_wfi_p2p_rx(vif
, buff
, size
);
885 if (vif
->monitor_flag
)
886 wilc_wfi_monitor_rx(wilc
->monitor_dev
, buff
, size
);
888 srcu_read_unlock(&wilc
->srcu
, srcu_idx
);
891 static const struct net_device_ops wilc_netdev_ops
= {
892 .ndo_init
= mac_init_fn
,
893 .ndo_open
= wilc_mac_open
,
894 .ndo_stop
= wilc_mac_close
,
895 .ndo_set_mac_address
= wilc_set_mac_addr
,
896 .ndo_start_xmit
= wilc_mac_xmit
,
897 .ndo_get_stats
= mac_stats
,
898 .ndo_set_rx_mode
= wilc_set_multicast_list
,
901 void wilc_netdev_cleanup(struct wilc
*wilc
)
903 struct wilc_vif
*vif
, *vif_tmp
;
908 if (wilc
->firmware
) {
909 release_firmware(wilc
->firmware
);
910 wilc
->firmware
= NULL
;
913 list_for_each_entry_safe(vif
, vif_tmp
, &wilc
->vif_list
, list
) {
914 mutex_lock(&wilc
->vif_mutex
);
915 list_del_rcu(&vif
->list
);
917 mutex_unlock(&wilc
->vif_mutex
);
918 synchronize_srcu(&wilc
->srcu
);
920 unregister_netdev(vif
->ndev
);
923 wilc_wfi_deinit_mon_interface(wilc
, false);
924 destroy_workqueue(wilc
->hif_workqueue
);
926 wilc_wlan_cfg_deinit(wilc
);
927 wlan_deinit_locks(wilc
);
928 wiphy_unregister(wilc
->wiphy
);
929 wiphy_free(wilc
->wiphy
);
931 EXPORT_SYMBOL_GPL(wilc_netdev_cleanup
);
933 static u8
wilc_get_available_idx(struct wilc
*wl
)
936 struct wilc_vif
*vif
;
939 srcu_idx
= srcu_read_lock(&wl
->srcu
);
940 wilc_for_each_vif(wl
, vif
) {
946 srcu_read_unlock(&wl
->srcu
, srcu_idx
);
950 struct wilc_vif
*wilc_netdev_ifc_init(struct wilc
*wl
, const char *name
,
951 int vif_type
, enum nl80211_iftype type
,
954 u8 mac_address
[ETH_ALEN
];
955 struct net_device
*ndev
;
956 struct wilc_vif
*vif
;
959 ndev
= alloc_etherdev(sizeof(*vif
));
961 return ERR_PTR(-ENOMEM
);
963 vif
= netdev_priv(ndev
);
964 ndev
->ieee80211_ptr
= &vif
->priv
.wdev
;
965 strcpy(ndev
->name
, name
);
970 ndev
->netdev_ops
= &wilc_netdev_ops
;
972 SET_NETDEV_DEV(ndev
, wiphy_dev(wl
->wiphy
));
974 vif
->priv
.wdev
.wiphy
= wl
->wiphy
;
975 vif
->priv
.wdev
.netdev
= ndev
;
976 vif
->priv
.wdev
.iftype
= type
;
977 vif
->priv
.dev
= ndev
;
979 ndev
->needs_free_netdev
= true;
980 vif
->iftype
= vif_type
;
981 vif
->idx
= wilc_get_available_idx(wl
);
984 memcpy(mac_address
, wl
->nv_mac_address
, ETH_ALEN
);
985 /* WILC firmware uses locally administered MAC address for the
986 * second virtual interface (bit 1 of first byte set), but
987 * since it is possibly not loaded/running yet, reproduce this behavior
988 * in the driver during interface creation.
991 mac_address
[0] |= 0x2;
993 eth_hw_addr_set(vif
->ndev
, mac_address
);
995 mutex_lock(&wl
->vif_mutex
);
996 list_add_tail_rcu(&vif
->list
, &wl
->vif_list
);
998 mutex_unlock(&wl
->vif_mutex
);
999 synchronize_srcu(&wl
->srcu
);
1002 ret
= cfg80211_register_netdevice(ndev
);
1004 ret
= register_netdev(ndev
);
1008 goto error_remove_vif
;
1014 mutex_lock(&wl
->vif_mutex
);
1015 list_del_rcu(&vif
->list
);
1017 mutex_unlock(&wl
->vif_mutex
);
1018 synchronize_srcu(&wl
->srcu
);
1020 return ERR_PTR(ret
);
1022 EXPORT_SYMBOL_GPL(wilc_netdev_ifc_init
);
1024 MODULE_DESCRIPTION("Atmel WILC1000 core wireless driver");
1025 MODULE_LICENSE("GPL");
1026 MODULE_FIRMWARE(WILC1000_FW(WILC1000_API_VER
));
1027 MODULE_FIRMWARE(WILC3000_FW(WILC3000_API_VER
));