Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Common private data.
0004  *
0005  * Copyright (c) 2017-2020, Silicon Laboratories, Inc.
0006  * Copyright (c) 2010, ST-Ericsson
0007  * Copyright (c) 2006, Michael Wu <flamingice@sourmilk.net>
0008  * Copyright 2004-2006 Jean-Baptiste Note <jbnote@gmail.com>, et al.
0009  */
0010 #ifndef WFX_H
0011 #define WFX_H
0012 
0013 #include <linux/completion.h>
0014 #include <linux/workqueue.h>
0015 #include <linux/mutex.h>
0016 #include <linux/nospec.h>
0017 #include <net/mac80211.h>
0018 
0019 #include "bh.h"
0020 #include "data_tx.h"
0021 #include "main.h"
0022 #include "queue.h"
0023 #include "hif_tx.h"
0024 
0025 #define USEC_PER_TXOP 32 /* see struct ieee80211_tx_queue_params */
0026 #define USEC_PER_TU 1024
0027 
0028 struct wfx_hwbus_ops;
0029 
0030 struct wfx_dev {
0031     struct wfx_platform_data   pdata;
0032     struct device              *dev;
0033     struct ieee80211_hw        *hw;
0034     struct ieee80211_vif       *vif[2];
0035     struct mac_address         addresses[2];
0036     const struct wfx_hwbus_ops *hwbus_ops;
0037     void                       *hwbus_priv;
0038 
0039     u8                         keyset;
0040     struct completion          firmware_ready;
0041     struct wfx_hif_ind_startup hw_caps;
0042     struct wfx_hif             hif;
0043     struct delayed_work        cooling_timeout_work;
0044     bool                       poll_irq;
0045     bool                       chip_frozen;
0046     struct mutex               conf_mutex;
0047 
0048     struct wfx_hif_cmd         hif_cmd;
0049     struct sk_buff_head        tx_pending;
0050     wait_queue_head_t          tx_dequeue;
0051     atomic_t                   tx_lock;
0052 
0053     atomic_t                   packet_id;
0054     u32                        key_map;
0055 
0056     struct wfx_hif_rx_stats    rx_stats;
0057     struct mutex               rx_stats_lock;
0058     struct wfx_hif_tx_power_loop_info tx_power_loop_info;
0059     struct mutex               tx_power_loop_info_lock;
0060     struct workqueue_struct    *bh_wq;
0061 };
0062 
0063 struct wfx_vif {
0064     struct wfx_dev             *wdev;
0065     struct ieee80211_channel   *channel;
0066     int                        id;
0067 
0068     u32                        link_id_map;
0069 
0070     bool                       after_dtim_tx_allowed;
0071     bool                       join_in_progress;
0072 
0073     struct delayed_work        beacon_loss_work;
0074 
0075     struct wfx_queue           tx_queue[4];
0076     struct wfx_tx_policy_cache tx_policy_cache;
0077     struct work_struct         tx_policy_upload_work;
0078 
0079     struct work_struct         update_tim_work;
0080 
0081     unsigned long              uapsd_mask;
0082 
0083     /* avoid some operations in parallel with scan */
0084     struct mutex               scan_lock;
0085     struct work_struct         scan_work;
0086     struct completion          scan_complete;
0087     int                        scan_nb_chan_done;
0088     bool                       scan_abort;
0089     struct ieee80211_scan_request *scan_req;
0090 
0091     struct completion          set_pm_mode_complete;
0092 };
0093 
0094 static inline struct ieee80211_vif *wvif_to_vif(struct wfx_vif *wvif)
0095 {
0096     return container_of((void *)wvif, struct ieee80211_vif, drv_priv);
0097 }
0098 
0099 static inline struct wfx_vif *wdev_to_wvif(struct wfx_dev *wdev, int vif_id)
0100 {
0101     if (vif_id >= ARRAY_SIZE(wdev->vif)) {
0102         dev_dbg(wdev->dev, "requesting non-existent vif: %d\n", vif_id);
0103         return NULL;
0104     }
0105     vif_id = array_index_nospec(vif_id, ARRAY_SIZE(wdev->vif));
0106     if (!wdev->vif[vif_id])
0107         return NULL;
0108     return (struct wfx_vif *)wdev->vif[vif_id]->drv_priv;
0109 }
0110 
0111 static inline struct wfx_vif *wvif_iterate(struct wfx_dev *wdev, struct wfx_vif *cur)
0112 {
0113     int i;
0114     int mark = 0;
0115     struct wfx_vif *tmp;
0116 
0117     if (!cur)
0118         mark = 1;
0119     for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
0120         tmp = wdev_to_wvif(wdev, i);
0121         if (mark && tmp)
0122             return tmp;
0123         if (tmp == cur)
0124             mark = 1;
0125     }
0126     return NULL;
0127 }
0128 
0129 static inline int wvif_count(struct wfx_dev *wdev)
0130 {
0131     int i;
0132     int ret = 0;
0133     struct wfx_vif *wvif;
0134 
0135     for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) {
0136         wvif = wdev_to_wvif(wdev, i);
0137         if (wvif)
0138             ret++;
0139     }
0140     return ret;
0141 }
0142 
0143 static inline void memreverse(u8 *src, u8 length)
0144 {
0145     u8 *lo = src;
0146     u8 *hi = src + length - 1;
0147     u8 swap;
0148 
0149     while (lo < hi) {
0150         swap = *lo;
0151         *lo++ = *hi;
0152         *hi-- = swap;
0153     }
0154 }
0155 
0156 static inline int memzcmp(void *src, unsigned int size)
0157 {
0158     u8 *buf = src;
0159 
0160     if (!size)
0161         return 0;
0162     if (*buf)
0163         return 1;
0164     return memcmp(buf, buf + 1, size - 1);
0165 }
0166 
0167 #endif