2 *****************************************************************************
6 * PURPOSE : Private header file for unifi driver.
8 * UDI = UniFi Debug Interface
10 * Copyright (C) 2005-2009 by Cambridge Silicon Radio Ltd.
12 * Refer to LICENSE.txt included with this source code for details on
15 *****************************************************************************
17 #ifndef __LINUX_UNIFI_PRIV_H__
18 #define __LINUX_UNIFI_PRIV_H__ 1
20 #include <linux/version.h>
21 #include <linux/module.h>
22 #include <linux/string.h>
23 #include <linux/errno.h>
24 #include <linux/kernel.h>
25 #include <linux/wait.h>
26 #include <linux/sched.h>
27 #include <linux/delay.h>
28 #include <linux/netdevice.h>
29 #include <linux/wireless.h>
30 #include <linux/cdev.h>
31 #include <linux/kthread.h>
32 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,19)
33 #include <linux/freezer.h>
36 #ifdef CSR_WIFI_SUPPORT_MMC_DRIVER
37 #include <linux/mmc/core.h>
38 #include <linux/mmc/card.h>
39 #include <linux/mmc/host.h>
40 #include <linux/mmc/sdio_func.h>
41 #include <linux/mmc/sdio_ids.h>
42 #include <linux/mmc/sdio.h>
43 #endif /* CSR_WIFI_SUPPORT_MMC_DRIVER */
47 #include "csr_wifi_hip_unifi.h"
48 #include "csr_wifi_hip_unifi_udi.h"
49 #include "csr_wifi_router_lib.h"
51 #ifndef CSR_WIFI_HIP_TA_DISABLE
52 #include "csr_wifi_vif_utils.h"
55 /* Define the unifi_priv_t before include the unifi_native.h */
57 typedef struct unifi_priv unifi_priv_t;
58 #ifdef CSR_SUPPORT_WEXT_AP
59 struct CsrWifiSmeApConfig;
60 typedef struct CsrWifiSmeApConfig CsrWifiSmeApConfig_t;
62 #ifdef CSR_SUPPORT_WEXT
63 #include "unifi_wext.h"
66 #include "unifi_clients.h"
69 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
70 #include <linux/workqueue.h>
73 #define INIT_WORK(_work, _func) \
75 INIT_LIST_HEAD(&(_work)->entry); \
76 (_work)->pending = 0; \
77 PREPARE_WORK((_work), (_func), (_work)); \
78 init_timer(&(_work)->timer); \
81 #endif /* Linux kernel < 2.6.20 */
84 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27)
85 #define UF_NETIF_TX_WAKE_ALL_QUEUES(_netdev) netif_tx_wake_all_queues(_netdev)
86 #define UF_NETIF_TX_START_ALL_QUEUES(_netdev) netif_tx_start_all_queues(_netdev)
87 #define UF_NETIF_TX_STOP_ALL_QUEUES(_netdev) netif_tx_stop_all_queues(_netdev)
89 #define UF_NETIF_TX_WAKE_ALL_QUEUES(_netdev) netif_wake_queue(_netdev)
90 #define UF_NETIF_TX_START_ALL_QUEUES(_netdev) netif_start_queue(_netdev)
91 #define UF_NETIF_TX_STOP_ALL_QUEUES(_netdev) netif_stop_queue(_netdev)
92 #endif /* Linux kernel >= 2.6.27 */
95 #ifdef CSR_NATIVE_LINUX
96 #include "sme_native/unifi_native.h"
98 #include "unifi_sme.h"
101 #undef COMPARE_HOST_TAG_TO_ENQUEUE
102 #define COMPARE_HOST_TAG_TO_ENQUEUE(tx_q_item_hosttag,maPktHostTag) \
103 if(tx_q_item_hosttag > maPktHostTag){ \
104 locationFound = TRUE; \
111 /* The device major number to use when registering the udi driver */
112 #define UNIFI_NAME "unifi"
113 #define MAX_UNIFI_DEVS 2
115 /* 802.11 Mac header offsets */
116 #define MAC_HEADER_SIZE 24
117 #define QOS_CONTROL_HEADER_SIZE 2
118 #define HT_CONTROL_HEADER_SIZE 4
120 #define QOS_DATA_NULL 0xc
121 #define DATA_NULL 0x04
122 #define FRAME_CONTROL_ORDER_BIT 0x8000
123 #define FRAME_CONTROL_TYPE_FIELD_OFFSET 2
124 #define FRAME_CONTROL_SUBTYPE_FIELD_OFFSET 4
125 #define IEEE802_11_FRAMETYPE_DATA 0x02
126 #define IEEE802_11_FRAMETYPE_CONTROL 0x01
127 #define IEEE802_11_FRAMETYPE_MANAGEMENT 0x00
128 #define IEEE802_11_FRAMETYPE_RESERVED 0x03
130 /* octet offset from start of mac header for certain fields */
131 #define IEEE802_11_ADDR3_OFFSET 16
132 #define IEEE802_11_SEQUENCE_CONTROL_OFFSET 22
133 #define IEEE802_11_MAX_DATA_LEN 2304
135 /* frame control (FC) masks, for frame control as 16 bit integer */
136 #define IEEE802_11_FC_TO_DS_MASK 0x100
137 #define IEEE802_11_FC_FROM_DS_MASK 0x200
138 #define IEEE802_11_FC_MOREDATA_MASK 0x2000
139 #define IEEE802_11_FC_PROTECTED_MASK 0x4000
140 #define IEEE80211_FC_ORDER_MASK 0x8000
141 #define IEEE80211_FC_SUBTYPE_MASK 0x00f0
142 #define IEEE80211_FC_TYPE_MASK 0x000c
143 #define IEEE80211_FC_PROTO_VERSION_MASK 0x0003
145 /* selected type and subtype combinations as in 7.1.3.1 table 1
146 For frame control as 16 bit integer, or for ls octet
148 #define IEEE802_11_FC_TYPE_DATA 0x08
149 #define IEEE802_11_FC_TYPE_NULL 0x48
150 #define IEEE802_11_FC_TYPE_QOS_NULL 0xc8
151 #define IEEE802_11_FC_TYPE_QOS_DATA 0x88
153 #define IEEE802_11_FC_TYPE_DATA_SUBTYPE_RESERVED 0x0D
155 /* qos control (QC) masks for qos control as 16 bit integer, or for ls octet */
156 #define IEEE802_11_QC_TID_MASK 0x0f
157 #define IEEE802_11_QC_A_MSDU_PRESENT 0x80
159 #define CSR_WIFI_EAPOL_M4_HOST_TAG 0x50000000
160 #define IEEE802_11_DATA_FRAME_MAC_HEADER_SIZE 36
161 #define MAX_ACCESS_CATOGORY 4
163 /* Time in us to check for inactivity of stations 5 mins */
164 #define INACTIVITY_CHECK_INTERVAL 300000000
165 /* Time in us before a station is flagged as inactive */
166 #define MAX_INACTIVITY_INTERVAL 300000000
169 /* Define for maximum BA session */
170 #define MAX_SUPPORTED_BA_SESSIONS_TX 1
171 #define MAX_SUPPORTED_BA_SESSIONS_RX 4
173 #define MAX_BA_WIND_SIZE 64
174 #define MAC_HEADER_ADDR1_OFFSET 4
175 #define MAC_HEADER_ADDR2_OFFSET 10
177 /* Define for age (in us) value for frames in MPDU reorder buffer */
178 #define CSR_WIFI_BA_MPDU_FRAME_AGE_TIMEOUT 30000 /* 30 milli seconds */
180 /* This macro used in prepare_and_add_macheader*/
181 #define ADDRESS_ONE_OFFSET 20
183 /* Defines for STA inactivity detection */
184 #define STA_INACTIVE_DETECTION_TRIGGER_THRESHOLD 1 /* in number of stations */
185 #define STA_INACTIVE_DETECTION_TIMER_INTERVAL 30 /* in seconds */
186 #define STA_INACTIVE_TIMEOUT_VAL 120*1000*1000 /* 120 seconds */
189 /* Defines used in beacon filtering in case of P2P */
190 #define CSR_WIFI_P2P_WILDCARD_SSID_LENGTH 0x7
191 #define CSR_WIFI_80211_FRAME_SUBTYPE_BEACON 0x8
192 #define CSR_WIFI_BEACON_FIXED_LENGTH 12
193 #define CSR_WIFI_FRAME_SUBTYPE_BIT_OFFSET 4
194 #define CSR_WIFI_80211_FRAME_SUBTYPE_BIT_MASK ((CsrUint8)(0xF << CSR_WIFI_FRAME_SUBTYPE_BIT_OFFSET))
196 #define CSR_WIFI_80211_GET_FRAME_SUBTYPE(frameBuffer) \
197 ((CsrUint8)(((CsrUint8 *)frameBuffer)[0] & CSR_WIFI_80211_FRAME_SUBTYPE_BIT_MASK) >> CSR_WIFI_FRAME_SUBTYPE_BIT_OFFSET)
199 /* For M4 request received via netdev*/
201 typedef CsrUint8 CsrWifiPacketType;
202 #define CSR_WIFI_UNICAST_PDU ((CsrWifiPacketType) 0x00)
203 #define CSR_WIFI_MULTICAST_PDU ((CsrWifiPacketType) 0x1)
204 #define CSR_WIFI_BROADCAST_PDU ((CsrWifiPacketType) 0x2)
206 #define PRIO_TO_NICE(prio) ((prio) - MAX_RT_PRIO - 20)
208 /* Module parameter variables */
210 extern int sdio_clock;
212 extern int disable_hw_reset;
213 extern int disable_power_control;
214 extern int enable_wol;
215 extern int sme_debug;
216 extern int fw_init[MAX_UNIFI_DEVS];
217 extern int tl_80211d;
218 extern int sdio_byte_mode;
219 extern int sdio_block_size;
220 extern int coredump_max;
221 extern int run_bh_once;
222 extern int bh_priority;
225 const unsigned char *dl_data;
233 struct task_struct *thread_task;
235 /* wait_queue for waking the unifi_thread kernel thread */
236 wait_queue_head_t wakeup_q;
237 unsigned int wakeup_flag;
240 * Use it to block the I/O thread when
241 * an error occurs or UniFi is reinitialised.
250 * Link list to hold the received packets for the period the port
253 typedef struct rx_buffered_packets {
254 /* List link structure */
256 /* Packet to indicate when the port reopens */
258 /* Bulkdata to free in case the port closes and need to discard the packet */
259 bulk_data_param_t bulkdata;
260 /* The source address of the packet */
261 CsrWifiMacAddress sa;
262 /* The destination address of the packet */
263 CsrWifiMacAddress da;
264 /* Corresponding signal */
266 } rx_buffered_packets_t;
269 typedef CsrUint8 CsrWifiAcPowersaveMode;
270 #define CSR_WIFI_AC_TRIGGER_ONLY_ENABLED 0x00
271 #define CSR_WIFI_AC_DELIVERY_ONLY_ENABLE 0X01
272 #define CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED 0X03
273 #define CSR_WIFI_AC_LEGACY_POWER_SAVE 0X02
276 #define IS_DELIVERY_ENABLED(mode) (mode & CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)? 1: 0
277 #define IS_DELIVERY_AND_TRIGGER_ENABLED(mode) ((mode & CSR_WIFI_AC_DELIVERY_ONLY_ENABLE)||(mode & CSR_WIFI_AC_TRIGGER_AND_DELIVERY_ENABLED))? 1: 0
278 #define IS_DTIM_ACTIVE(flag,hostTag) ((flag == TRUE || hostTag != INVALID_HOST_TAG))
279 #define INVALID_HOST_TAG 0xFFFFFFFF
280 #define UNIFI_TRAFFIC_Q_CONTENTION UNIFI_TRAFFIC_Q_BE
285 /* Queue to be used for contention priority */
288 * Link list to hold the tx packets for the period the peer
289 * powersave/free slots in unifi
291 typedef struct tx_buffered_packets {
292 /* List link structure */
294 CsrUint16 interfaceTag;
295 CSR_CLIENT_TAG hostTag;
296 CSR_PROCESS_ID leSenderProcessId;
297 CSR_TRANSMISSION_CONTROL transmissionControl;
299 /* Bulkdata to free in case the port closes and need to discard the packet */
300 bulk_data_desc_t bulkdata;
301 /* The source address of the packet */
302 CsrWifiMacAddress peerMacAddress;
303 CSR_PRIORITY priority;
304 } tx_buffered_packets_t;
306 /* station record has this data structure */
307 typedef struct CsrWifiRouterCtrlStaInfo_t {
309 /* Sme sends these parameters */
310 CsrWifiMacAddress peerMacAddress;
311 CsrUint32 assignedHandle;
312 CsrBool wmmOrQosEnabled;
313 CsrWifiAcPowersaveMode powersaveMode[MAX_ACCESS_CATOGORY];
314 CsrUint16 maxSpLength;
316 CsrUint16 noOfSpFramesSent;
318 /* Router/Driver database */
319 #ifdef CSR_SUPPORT_SME
320 unifi_port_cfg_t *peerControlledPort;
321 unifi_port_cfg_t *peerUnControlledPort;
323 /* Inactivity feature parameters */
324 struct netInterface_priv *interfacePriv;
325 struct work_struct send_disconnected_ind_task;
326 CsrBool activity_flag;
327 CsrUint16 listenIntervalInTus;
328 CSR_CLIENT_TAG nullDataHostTag;
330 /* Activity timestamps for the station */
331 CsrTime lastActivity;
333 /* during m/c transmission sp suspended */
334 CsrBool uapsdSuspended;
336 CsrWifiRouterCtrlPeerStatus currentPeerState;
337 struct list_head dataPdu[MAX_ACCESS_CATOGORY];
338 struct list_head mgtFrames;
340 CsrUint8 prevFrmType;
341 CsrUint8 prevFrmAccessCatogory;
346 /* Dont change the value of below macro for SET & RESET */
347 #define CSR_WIFI_TIM_RESET 0
348 #define CSR_WIFI_TIM_SET 1
349 #define CSR_WIFI_TIM_RESETTING 2
350 #define CSR_WIFI_TIM_SETTING 3
352 CsrUint16 noOfPktQueued;
353 }CsrWifiRouterCtrlStaInfo_t;
355 #ifdef CSR_SUPPORT_WEXT_AP
356 struct CsrWifiSmeApConfig {
359 CsrWifiNmeApCredentials credentials;
360 CsrUint8 max_connections;
365 #ifdef CSR_WIFI_RX_PATH_SPLIT
366 /* This is a test code and may be removed later*/
367 #define CSR_WIFI_RX_SIGNAL_BUFFER_SIZE (60+1)
371 CsrUint8 *bufptr; /* Signal Primitive */
372 bulk_data_param_t data_ptrs; /* Bulk Data pointers */
378 CsrUint8 writePointer; /**< write pointer */
379 CsrUint8 readPointer; /**< read pointer */
380 CsrUint8 size; /**< size of circular buffer */
381 rx_buff_struct_t rx_buff[CSR_WIFI_RX_SIGNAL_BUFFER_SIZE]; /**< Element of ciruclar buffer */
382 } rxCircularBuffer_t;
384 void rx_wq_handler(struct work_struct *work);
390 CsrSdioFunction *sdio;
392 /* Index into Unifi_instances[] for this device. */
394 /* Reference count for this instance */
397 /* Firmware images */
398 struct dlpriv fw_sta;
399 struct dlpriv fw_conv; /* used for conversion of production test image */
401 /* Char device related structures */
402 struct cdev unifi_cdev;
403 struct cdev unifiudi_cdev;
404 struct device *unifi_device;
406 /* Which wireless interface to use (1 - 2.4GHz, 2 - 5GHz) */
407 CSR_IFINTERFACE if_index;
409 /* For multiple interface support */
410 struct net_device *netdev[CSR_WIFI_NUM_INTERFACES];
411 struct netInterface_priv *interfacePriv[CSR_WIFI_NUM_INTERFACES];
413 CsrUint8 totalInterfaceCount;
417 /* Name of node under /proc */
418 char proc_entry_name[64];
425 * - whether the netdev has been registered.
427 unsigned int drop_unencrypted : 1;
429 /* Our list of unifi linux clients. */
430 ul_client_t ul_clients[MAX_UDI_CLIENTS];
432 /* Mutex to protect using the logging hook after UDI client is gone */
433 struct semaphore udi_logging_mutex;
434 /* Pointer to the ul_clients[] array */
435 ul_client_t *logging_client;
437 /* A ul_client_t* used to send the netdev related MIB requests. */
438 ul_client_t *netdev_client;
440 /* The SME ul_client_t pointer. */
441 ul_client_t *sme_cli;
443 /* The AMP ul_client_t pointer. */
444 ul_client_t *amp_client;
447 * Semaphore for locking the top-half to one user process.
448 * This is necessary to prevent multiple processes calling driver
449 * operations. This can happen because the network driver entry points
450 * can be called from multiple processes.
452 #ifdef USE_DRIVER_LOCK
453 struct semaphore lock;
454 #endif /* USE_DRIVER_LOCK */
456 /* Flag to say that an operation was aborted */
459 struct uf_thread bh_thread;
461 #define UNIFI_INIT_NONE 0x00
462 #define UNIFI_INIT_IN_PROGRESS 0x01
463 #define UNIFI_INIT_FW_DOWNLOADED 0x02
464 #define UNIFI_INIT_COMPLETED 0x04
465 unsigned char init_progress;
469 /* The WMM features that UniFi uses in the current BSS */
470 unsigned int sta_wmm_capabilities;
473 char last_debug_string[256];
474 unsigned short last_debug_word16[16];
476 #ifdef CSR_SUPPORT_SME
477 /* lock to protect the tx queues list */
478 spinlock_t tx_q_lock;
479 CsrUint8 allPeerDozing;
480 CsrUint8 pausedStaHandle[MAX_ACCESS_CATOGORY];
481 /* Max packet the driver can queue, irrespective of interface number */
482 CsrUint16 noOfPktQueuedInDriver;
483 #define CSR_WIFI_DRIVER_SUPPORT_FOR_MAX_PKT_QUEUEING 512
484 #define CSR_WIFI_DRIVER_MAX_PKT_QUEUING_THRESHOLD_PER_PEER 64
485 #define CSR_WIFI_DRIVER_MINIMUM_BROADCAST_PKT_THRESHOLD 3
487 CsrBool routerBufferEnable[MAX_ACCESS_CATOGORY];
488 /* lock to protect stainfo members and priv members*/
489 spinlock_t staRecord_lock;
491 #ifdef CSR_NATIVE_LINUX
492 #ifdef CSR_SUPPORT_WEXT
493 /* wireless config */
494 struct wext_config wext_conf;
497 /* Mutex to protect the MLME blocking requests */
498 struct semaphore mlme_blocking_mutex;
500 /* The ul_client that provides the blocking API for WEXT calls */
501 ul_client_t *wext_client;
503 #endif /* CSR_NATIVE_LINUX */
505 #ifdef CSR_SUPPORT_SME
506 wait_queue_head_t sme_request_wq;
507 /* Semaphore to protect the SME blocking requests */
508 struct semaphore sme_sem;
509 /* Structure to hold the SME blocking requests data*/
510 sme_reply_t sme_reply;
512 /* Structure to hold a traffic protocol indication */
514 struct work_struct task;
515 CsrWifiRouterCtrlTrafficPacketType packet_type;
516 CsrWifiRouterCtrlProtocolDirection direction;
517 CsrWifiMacAddress src_addr;
521 struct ta_sample_ind {
522 struct work_struct task;
523 CsrWifiRouterCtrlTrafficStats stats;
525 } ta_sample_ind_work;
527 __be32 sta_ip_address;
528 CsrWifiRouterCtrlSmeVersions sme_versions;
531 * Flag to reflect state of unifi_sys_wifi_on_*() progress.
532 * This indicates whether we are in an "wifi on" state when we are
533 * allowed to indication errors with unifi_mgt_wifi_off_ind()
536 wifi_on_unspecified = -1,
537 wifi_on_in_progress = 0,
541 /* Userspace TaskId for the SME Set when a wifi on req is received */
542 CsrSchedQid CSR_WIFI_SME_IFACEQUEUE;
544 struct work_struct multicast_list_task;
546 * The SME installs filters to ask for specific MA-UNITDATA.req
547 * to be passed to different SME components.
549 #define MAX_MA_UNIDATA_IND_FILTERS 8
550 sme_ma_unidata_ind_filter_t sme_unidata_ind_filters[MAX_MA_UNIDATA_IND_FILTERS];
552 /* UNIFI_CFG related parameters */
553 uf_cfg_bcast_packet_filter_t packet_filters;
554 unsigned char *filter_tclas_ies;
555 /* The structure that holds all the connection configuration. */
556 CsrWifiSmeConnectionConfig connection_config;
557 #ifdef CSR_SUPPORT_WEXT
559 int ignore_bssid_join;
560 struct iw_statistics wext_wireless_stats;
562 /* The MIB and MAC address files contents, read from userspace */
563 CsrWifiSmeDataBlock mib_data;
564 CsrWifiMacAddress sta_mac_address;
566 int wep_tx_key_index;
567 wep_key_t wep_keys[NUM_WEPKEYS];
570 #ifdef CSR_SUPPORT_WEXT_AP
571 CsrWifiSmeApMacConfig ap_mac_config;
572 CsrWifiNmeApConfig group_sec_config;
573 CsrWifiSmeApConfig_t ap_config;
575 struct work_struct sme_config_task;
577 #endif /* CSR_SUPPORT_WEXT */
579 #endif /* CSR_SUPPORT_SME */
581 #ifdef CSR_SME_USERSPACE
583 #endif /* CSR_SME_USERSPACE */
585 card_info_t card_info;
587 /* Mutex to protect unifi_send_signal() */
588 spinlock_t send_signal_lock;
592 * The workqueue to offload the TA run
593 * and the multicast addresses list set
595 struct workqueue_struct *unifi_workqueue;
597 unsigned char *mib_cfm_buffer;
598 unsigned int mib_cfm_buffer_length;
600 int ptest_mode; /* Set when in production test mode */
601 int coredump_mode; /* Set when SME has requested a coredump */
602 CsrBool wol_suspend; /* Set when suspending with UniFi powered */
604 #define UF_UNCONTROLLED_PORT_Q 0
605 #define UF_CONTROLLED_PORT_Q 1
607 /* Semaphore to protect the rx queues list */
608 struct semaphore rx_q_sem;
610 /* Spinlock to protect M4 data */
612 /* Spinlock to protect BA RX data */
614 #ifndef ALLOW_Q_PAUSE
615 /* Array to indicate if a particular Tx queue is paused, this may not be
616 * required in a multiqueue implementation since we can directly stop kernel
618 CsrUint8 tx_q_paused_flag[UNIFI_TRAFFIC_Q_MAX];
621 #ifdef CSR_WIFI_RX_PATH_SPLIT
622 struct workqueue_struct *rx_workqueue;
623 struct work_struct rx_work_struct;
624 rxCircularBuffer_t rxSignalBuffer;
628 CsrUint32 rxTcpThroughput;
629 CsrUint32 txTcpThroughput;
630 CsrUint32 rxUdpThroughput;
631 CsrUint32 txUdpThroughput;
634 CsrUint8 wapi_multicast_filter;
635 CsrUint8 wapi_unicast_filter;
636 CsrUint8 wapi_unicast_queued_pkt_filter;
640 CsrUint16 queue_length[4];
641 CsrUint8 os_queue_paused;
647 bulk_data_param_t bulkdata;
654 frame_desc_struct *buffer;
656 CsrUint16 occupied_slots;
657 struct timer_list timer;
659 CsrUint16 expected_sn;
661 CsrBool trigger_ba_after_ssn;
662 struct netInterface_priv *interfacePriv;
664 CsrWifiMacAddress macAddress;
665 struct work_struct send_ba_err_task;
666 } ba_session_rx_struct;
670 struct netInterface_priv *interfacePriv;
672 CsrWifiMacAddress macAddress;
673 } ba_session_tx_struct;
675 typedef struct netInterface_priv
677 CsrUint16 InterfaceTag;
678 struct unifi_priv *privPtr;
679 ba_session_tx_struct *ba_session_tx[MAX_SUPPORTED_BA_SESSIONS_TX];
680 ba_session_rx_struct *ba_session_rx[MAX_SUPPORTED_BA_SESSIONS_RX];
681 frame_desc_struct ba_complete[MAX_BA_WIND_SIZE];
682 CsrUint8 ba_complete_index;
683 CsrUint8 queueEnabled[UNIFI_NO_OF_TX_QS];
684 struct work_struct send_m4_ready_task;
685 struct net_device_stats stats;
686 CsrUint8 interfaceMode;
688 CsrWifiMacAddress bssid;
690 * Flag to reflect state of CONNECTED indication signal.
691 * This indicates whether we are "joined" an Access Point (i.e. have
692 * nominated an AP and are receiving beacons) but give no indication
693 * of whether we are authenticated and/or associated.
696 UnifiConnectedUnknown = -1,
697 UnifiNotConnected = 0,
700 #ifdef CSR_SUPPORT_WEXT
701 /* Tracks when we are waiting for a netdevice state change callback */
702 CsrBool wait_netdev_change;
703 /* True if we have successfully registered for netdev callbacks */
704 CsrBool netdev_callback_registered;
705 #endif /* CSR_SUPPORT_WEXT */
706 unsigned int netdev_registered;
707 #define UNIFI_MAX_MULTICAST_ADDRESSES 10
708 /* The multicast addresses list that the thread needs to set. */
709 u8 mc_list[UNIFI_MAX_MULTICAST_ADDRESSES*ETH_ALEN];
710 /* The multicast addresses count that the thread needs to set. */
713 #ifdef CSR_SUPPORT_SME
714 /* (un)controlled port configuration */
715 unifi_port_config_t controlled_data_port;
716 unifi_port_config_t uncontrolled_data_port;
718 /* station record maintenance related data structures */
719 CsrUint8 num_stations_joined;
720 CsrWifiRouterCtrlStaInfo_t *(staInfo)[UNIFI_MAX_CONNECTIONS];
721 struct list_head genericMgtFrames;
722 struct list_head genericMulticastOrBroadCastFrames;
723 struct list_head genericMulticastOrBroadCastMgtFrames;
724 struct list_head directedMaPktReq;
726 /* Timer for detecting station inactivity */
727 struct timer_list sta_activity_check_timer;
728 CsrBool sta_activity_check_enabled;
730 /* Timestamp when the last inactivity check was done */
731 CsrTime last_inactivity_check;
733 /*number of multicast or borad cast packets queued*/
734 CsrUint16 noOfbroadcastPktQueued;
736 /* A list to hold the buffered uncontrolled port packets */
737 struct list_head rx_uncontrolled_list;
738 /* A list to hold the buffered controlled port packets */
739 struct list_head rx_controlled_list;
740 /* Buffered M4 signal to take care of WPA race condition */
741 CSR_SIGNAL m4_signal;
742 bulk_data_desc_t m4_bulk_data;
743 /* This should be removed and m4_hostTag should be used for checking*/
745 CSR_CLIENT_TAG m4_hostTag;
747 CsrBool intraBssEnabled;
748 CsrUint32 multicastPduHostTag; /* Used to set the tim after getting
750 } netInterface_priv_t;
752 typedef struct maPktReqList{
756 CSR_CLIENT_TAG hostTag;
757 CsrUint32 staHandler;
758 unsigned long jiffeTime;
761 #ifndef ALLOW_Q_PAUSE
762 #define net_is_tx_q_paused(priv, q) (priv->tx_q_paused_flag[q])
763 #define net_tx_q_unpause(priv, q) (priv->tx_q_paused_flag[q] = 0)
764 #define net_tx_q_pause(priv, q) (priv->tx_q_paused_flag[q] = 1)
767 #ifdef CSR_SUPPORT_SME
768 #define routerStartBuffering(priv,queue) priv->routerBufferEnable[(queue)] = TRUE;
769 #define routerStopBuffering(priv,queue) priv->routerBufferEnable[(queue)] = FALSE;
770 #define isRouterBufferEnabled(priv,queue) priv->routerBufferEnable[(queue)]
773 #ifdef USE_DRIVER_LOCK
774 #define LOCK_DRIVER(_p) down_interruptible(&(_p)->lock)
775 #define UNLOCK_DRIVER(_p) up(&(_p)->lock)
777 #define LOCK_DRIVER(_p) (void)(_p); /* as nothing */
778 #define UNLOCK_DRIVER(_p) (void)(_p); /* as nothing */
779 #endif /* USE_DRIVER_LOCK */
781 CsrInt32 CsrHipResultToStatus(CsrResult csrResult);
785 * SDIO related functions and callbacks
787 int uf_sdio_load(void);
788 void uf_sdio_unload(void);
789 unifi_priv_t *uf_find_instance(int inst);
790 int uf_find_priv(unifi_priv_t *priv);
791 int uf_find_netdev_priv(netInterface_priv_t *priv);
792 unifi_priv_t *uf_get_instance(int inst);
793 void uf_put_instance(int inst);
794 int csr_sdio_linux_install_irq(CsrSdioFunction *sdio);
795 int csr_sdio_linux_remove_irq(CsrSdioFunction *sdio);
797 void uf_add_os_device(int bus_id, struct device *os_device);
798 void uf_remove_os_device(int bus_id);
805 * For multifunction cards, we cannot grub the SDIO lock around the unifi_bh()
806 * as this prevents other functions using SDIO.
807 * Since some of CSR SDIO API is used regardless of trying to lock unifi_bh()
808 * we have followed this scheme:
809 * 1. If a function needs protection only when CSR_WIFI_SINGLE_FUNCTION is defined
810 * then we call CsrSdioClaim/CsrSdioRelease().
811 * 2. If a function needs protection only when CSR_WIFI_SINGLE_FUNCTION is not defined
812 * then we call _sdio_claim_host/_sdio_claim_host(). Use of this should be restricted
813 * to the SDIO glue layer only (e.g. sdio_mmc.c).
814 * 3. If a function needs protection, regardless of the CSR_WIFI_SINGLE_FUNCTION
815 * then we call directly the sdio_claim_host/sdio_release_host().
816 * Use of this must be restricted to the SDIO glue layer only (e.g. sdio_mmc.c).
818 * Note: The _func and function pointers are _not_ the same.
819 * The former is the (struct sdio_func*) context, which restricts the use to the SDIO glue layer.
820 * The latter is the (CsrSdioFunction*) context, which allows calls from all layers.
823 #ifdef CSR_WIFI_SUPPORT_MMC_DRIVER
825 #ifdef CSR_WIFI_SINGLE_FUNCTION
826 #define CsrSdioClaim(function) sdio_claim_host((function)->priv);
827 #define CsrSdioRelease(function) sdio_release_host((function)->priv);
829 #define _sdio_claim_host(_func)
830 #define _sdio_release_host(_func)
833 #define CsrSdioClaim(function)
834 #define CsrSdioRelease(function)
836 #define _sdio_claim_host(_func) sdio_claim_host(_func)
837 #define _sdio_release_host(_func) sdio_release_host(_func)
839 #endif /* CSR_WIFI_SINGLE_FUNCTION */
842 #define _sdio_claim_host(_func)
843 #define _sdio_release_host(_func)
845 #define CsrSdioClaim(function)
846 #define CsrSdioRelease(function)
848 #endif /* CSR_WIFI_SUPPORT_MMC_DRIVER */
852 * Functions to allocate and free an ethernet device.
854 unifi_priv_t *uf_alloc_netdevice(CsrSdioFunction *sdio_dev, int bus_id);
855 int uf_free_netdevice(unifi_priv_t *priv);
857 /* Allocating function for other interfaces */
858 CsrBool uf_alloc_netdevice_for_other_interfaces(unifi_priv_t *priv, CsrUint16 interfaceTag);
861 * Firmware download related functions.
863 int uf_run_unifihelper(unifi_priv_t *priv);
864 int uf_request_firmware_files(unifi_priv_t *priv, int is_fw);
865 int uf_release_firmware_files(unifi_priv_t *priv);
866 int uf_release_firmware(unifi_priv_t *priv, struct dlpriv *to_free);
869 * Functions to create and delete the device nodes.
871 int uf_create_device_nodes(unifi_priv_t *priv, int bus_id);
872 void uf_destroy_device_nodes(unifi_priv_t *priv);
875 * Upper Edge Initialisation functions
877 int uf_init_bh(unifi_priv_t *priv);
878 int uf_init_hw(unifi_priv_t *priv);
880 /* Thread related helper functions */
881 int uf_start_thread(unifi_priv_t *priv, struct uf_thread *thread, int (*func)(void *));
882 void uf_stop_thread(unifi_priv_t *priv, struct uf_thread *thread);
883 void uf_wait_for_thread_to_stop(unifi_priv_t *priv, struct uf_thread *thread);
887 * Unifi Linux functions
889 void ul_init_clients(unifi_priv_t *priv);
891 /* Configuration flags */
892 #define CLI_USING_WIRE_FORMAT 0x0002
893 #define CLI_SME_USERSPACE 0x0020
894 ul_client_t *ul_register_client(unifi_priv_t *priv,
895 unsigned int configuration,
896 udi_event_t udi_event_clbk);
897 int ul_deregister_client(ul_client_t *pcli);
899 int ul_send_signal_unpacked(unifi_priv_t *priv,
901 bulk_data_param_t *bulkdata);
902 int ul_send_signal_raw(unifi_priv_t *priv,
903 unsigned char *sigptr, int siglen,
904 bulk_data_param_t *bulkdata);
906 void ul_log_config_ind(unifi_priv_t *priv, u8 *conf_param, int len);
910 * Data plane operations
915 int uf_verify_m4(unifi_priv_t *priv, const unsigned char *packet,
916 unsigned int length);
918 #ifdef CSR_SUPPORT_SME
919 CsrBool uf_check_broadcast_bssid(unifi_priv_t *priv, const bulk_data_param_t *bulkdata);
920 CsrBool uf_process_pm_bit_for_peer(unifi_priv_t * priv, CsrWifiRouterCtrlStaInfo_t * srcStaInfo,CsrUint8 pmBit,CsrUint16 interfaceTag);
921 void uf_process_ps_poll(unifi_priv_t *priv,CsrUint8* sa,CsrUint8* da,CsrUint8 pmBit,CsrUint16 interfaceTag);
922 int uf_ap_process_data_pdu(unifi_priv_t *priv, struct sk_buff *skb,
923 struct ethhdr *ehdr, CsrWifiRouterCtrlStaInfo_t * srcStaInfo,
924 const CSR_SIGNAL *signal,
925 bulk_data_param_t *bulkdata,
926 CsrUint8 macHeaderLengthInBytes);
927 CsrBool uf_is_more_data_for_non_delivery_ac(CsrWifiRouterCtrlStaInfo_t *staRecord);
928 CsrBool uf_is_more_data_for_delivery_ac(unifi_priv_t *priv,CsrWifiRouterCtrlStaInfo_t *staRecord,CsrBool mgtCheck);
929 void uf_process_wmm_deliver_ac_uapsd ( unifi_priv_t * priv,
930 CsrWifiRouterCtrlStaInfo_t * srcStaInfo,
931 CsrUint16 qosControl,
932 CsrUint16 interfaceTag);
934 void uf_send_buffered_data_from_ac(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_t * staInfo, CsrUint8 queue, struct list_head *txList);
935 void uf_send_buffered_data_from_delivery_ac(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_t * staInfo, CsrUint8 queue, struct list_head *txList);
937 void uf_continue_uapsd(unifi_priv_t *priv, CsrWifiRouterCtrlStaInfo_t * staInfo);
938 void uf_send_qos_null(unifi_priv_t * priv,CsrUint16 interfaceTag, const CsrUint8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo);
939 void uf_send_nulldata(unifi_priv_t * priv,CsrUint16 interfaceTag, const CsrUint8 *da,CSR_PRIORITY priority,CsrWifiRouterCtrlStaInfo_t * srcStaInfo);
940 void uf_store_directed_ma_packet_referenece(unifi_priv_t *priv, bulk_data_param_t *bulkdata,CSR_SIGNAL *sigptr,CsrUint32 alignOffset);
945 CsrResult uf_process_ma_packet_req(unifi_priv_t *priv, CsrUint8 *peerMacAddress, CSR_CLIENT_TAG hostTag, CsrUint16 interfaceTag, CSR_TRANSMISSION_CONTROL transmissionControl, CSR_RATE TransmitRate, CSR_PRIORITY priority, CSR_PROCESS_ID senderId, bulk_data_param_t *bulkdata);
946 void uf_process_ma_vif_availibility_ind(unifi_priv_t *priv,CsrUint8 *sigdata, CsrUint32 siglen);
947 #ifdef CSR_SUPPORT_SME
948 void uf_send_buffered_frames(unifi_priv_t *priv,unifi_TrafficQueue queue);
949 int uf_process_station_records_for_sending_data(unifi_priv_t *priv,CsrUint16 interfaceTag,
950 CsrWifiRouterCtrlStaInfo_t *srcStaInfo,
951 CsrWifiRouterCtrlStaInfo_t *dstStaInfo);
952 void uf_prepare_send_cfm_list_for_queued_pkts(unifi_priv_t * priv,
953 struct list_head *frames_need_cfm_list,
954 struct list_head * list);
955 void send_auto_ma_packet_confirm(unifi_priv_t *priv,
956 netInterface_priv_t *interfacePriv,
957 struct list_head *buffered_frames_list);
958 void uf_flush_list(unifi_priv_t * priv, struct list_head * list);
959 void uf_flush_maPktlist(unifi_priv_t * priv, struct list_head * list);
960 tx_buffered_packets_t *dequeue_tx_data_pdu(unifi_priv_t *priv, struct list_head *txList);
961 void resume_unicast_buffered_frames(unifi_priv_t *priv, CsrUint16 interfaceTag);
962 void update_eosp_to_head_of_broadcast_list_head(unifi_priv_t *priv,CsrUint16 interfaceTag);
963 void resume_suspended_uapsd(unifi_priv_t* priv,CsrUint16 interfaceTag);
969 #ifndef P80211_OUI_LEN
970 #define P80211_OUI_LEN 3
973 u8 dsap; /* always 0xAA */
974 u8 ssap; /* always 0xAA */
975 u8 ctrl; /* always 0x03 */
976 u8 oui[P80211_OUI_LEN]; /* organizational universal id */
978 } __attribute__ ((packed)) llc_snap_hdr_t;
979 int skb_add_llc_snap(struct net_device *dev, struct sk_buff *skb, int proto);
980 int skb_80211_to_ether(unifi_priv_t *priv, struct sk_buff *skb,
981 const unsigned char *daddr, const unsigned char *saddr,
982 const CSR_SIGNAL *signal,
983 bulk_data_param_t *bulkdata);
985 const char *result_code_str(int result);
988 /* prepares & appends the Mac header for the payload */
989 int prepare_and_add_macheader(unifi_priv_t *priv,
991 struct sk_buff *newSkb,
992 CSR_PRIORITY priority,
993 bulk_data_param_t *bulkdata,
994 CsrUint16 interfaceTag,
995 const CsrUint8 *daddr,
996 const CsrUint8 *saddr,
999 get_packet_priority(unifi_priv_t *priv, struct sk_buff *skb, const struct ethhdr *ehdr, netInterface_priv_t *interfacePriv);
1002 unifi_frame_ma_packet_req(unifi_priv_t *priv, CSR_PRIORITY priority,
1003 CSR_RATE TransmitRate, CSR_CLIENT_TAG hostTag,
1004 CsrUint16 interfaceTag, CSR_TRANSMISSION_CONTROL transmissionControl,
1005 CSR_PROCESS_ID leSenderProcessId, CsrUint8 *peerMacAddress,
1006 CSR_SIGNAL *signal);
1009 /* Pack the LSB to include station handle & status of tim set */
1010 #define CSR_WIFI_PACK_SENDER_ID_LSB_FOR_TIM_REQ(handle, timState) ((handle << 2) | timState)
1011 /* get the station record handle from the sender ID */
1012 #define CSR_WIFI_GET_STATION_HANDLE_FROM_RECEIVER_ID(receiverProcessId) (CsrUint8) ((receiverProcessId & 0xff) >> 2)
1013 /* get the timSet status from the sender ID */
1014 #define CSR_WIFI_GET_TIMSET_STATE_FROM_RECEIVER_ID(receiverProcessId) (CsrUint8) (receiverProcessId & 0x03)
1016 /* handle is 6 bits to accomodate in senderId LSB (only 64 station can be associated) */
1017 #define CSR_WIFI_BROADCAST_OR_MULTICAST_HANDLE 0x3F
1019 void update_tim(unifi_priv_t * priv, CsrUint16 aid, CsrUint8 setTim, CsrUint16 interfaceTag, CsrUint32 handle);
1020 void uf_handle_tim_cfm(unifi_priv_t *priv, CSR_MLME_SET_TIM_CONFIRM *cfm, CsrUint16 senderProcessId);
1022 /* Clear the Peer station Record, in case of wifioff/unexpected card removal */
1023 void CsrWifiRouterCtrlInterfaceReset(unifi_priv_t *priv, CsrUint16 interfaceTag);
1025 void scroll_ba_window(unifi_priv_t *priv,
1026 netInterface_priv_t *interfacePriv,
1027 ba_session_rx_struct *ba_session,
1030 CsrBool blockack_session_stop(unifi_priv_t *priv,
1031 CsrUint16 interfaceTag,
1032 CsrWifiRouterCtrlBlockAckRole role,
1034 CsrWifiMacAddress macAddress);
1035 #ifdef CSR_SUPPORT_SME
1036 /* Fetch the protection information from interface Mode */
1037 CsrInt8 uf_get_protection_bit_from_interfacemode(unifi_priv_t *priv, CsrUint16 interfaceTag, const CsrUint8 *daddr);
1040 /* Fetch the station record handler from data base for matching Mac address */
1041 #ifdef CSR_SUPPORT_SME
1042 CsrWifiRouterCtrlStaInfo_t *CsrWifiRouterCtrlGetStationRecordFromPeerMacAddress(unifi_priv_t *priv,
1043 const CsrUint8 *peerMacAddress,
1044 CsrUint16 interfaceTag);
1046 /* Fetch the station record handler from data base for matching handle */
1047 CsrWifiRouterCtrlStaInfo_t * CsrWifiRouterCtrlGetStationRecordFromHandle(unifi_priv_t *priv,
1049 CsrUint16 interfaceTag);
1051 void uf_update_sta_activity(unifi_priv_t *priv, CsrUint16 interfaceTag, const CsrUint8 *peerMacAddress);
1052 void uf_process_ma_pkt_cfm_for_ap(unifi_priv_t *priv,CsrUint16 interfaceTag, const CSR_MA_PACKET_CONFIRM *pkt_cfm);
1054 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
1055 int uf_install_qdisc(struct net_device *dev);
1058 void uf_resume_data_plane(unifi_priv_t *priv, int queue,
1059 CsrWifiMacAddress peer_address,
1060 CsrUint16 interfaceTag);
1061 void uf_free_pending_rx_packets(unifi_priv_t *priv, int queue,
1062 CsrWifiMacAddress peer_address,CsrUint16 interfaceTag);
1064 int uf_register_netdev(unifi_priv_t *priv, int numOfInterface);
1065 void uf_unregister_netdev(unifi_priv_t *priv);
1067 void uf_net_get_name(struct net_device *dev, char *name, int len);
1069 void uf_send_queue_info(unifi_priv_t *priv);
1070 CsrUint16 uf_get_vif_identifier(CsrWifiRouterCtrlMode mode, CsrUint16 tag);
1072 void uf_process_rx_pending_queue(unifi_priv_t *priv, int queue,
1073 CsrWifiMacAddress source_address,
1074 int indicate, CsrUint16 interfaceTag);
1079 void uf_register_inet_notifier(void);
1080 void uf_unregister_inet_notifier(void);
1084 * Suspend / Resume handlers
1086 void unifi_resume(void *ospriv);
1087 void unifi_suspend(void *ospriv);
1090 #define QOS_CAPABILITY_WMM_ENABLED 0x0001
1091 #define QOS_CAPABILITY_WMM_UAPSD 0x0002
1092 #define QOS_CAPABILITY_ACM_BE_ENABLED 0x0010
1093 #define QOS_CAPABILITY_ACM_BK_ENABLED 0x0020
1094 #define QOS_CAPABILITY_ACM_VI_ENABLED 0x0040
1095 #define QOS_CAPABILITY_ACM_VO_ENABLED 0x0080
1096 #define QOS_CAPABILITY_TS_BE_ENABLED 0x0100
1097 #define QOS_CAPABILITY_TS_BK_ENABLED 0x0200
1098 #define QOS_CAPABILITY_TS_VI_ENABLED 0x0400
1099 #define QOS_CAPABILITY_TS_VO_ENABLED 0x0800
1104 #define ETH_P_PAE 0x888e
1107 #define ETH_P_WAI 0x88b4
1112 void debug_string_indication(unifi_priv_t *priv,
1113 const unsigned char *extra,
1114 unsigned int extralen);
1115 void debug_word16_indication(unifi_priv_t *priv, const CSR_SIGNAL *sigptr);
1116 void debug_generic_indication(unifi_priv_t *priv, const CSR_SIGNAL *sigptr);
1122 int unifi_putest_start(unifi_priv_t *priv, unsigned char *arg);
1123 int unifi_putest_cmd52_block_read(unifi_priv_t *priv, unsigned char *arg);
1124 int unifi_putest_stop(unifi_priv_t *priv, unsigned char *arg);
1125 int unifi_putest_set_sdio_clock(unifi_priv_t *priv, unsigned char *arg);
1126 int unifi_putest_cmd52_read(unifi_priv_t *priv, unsigned char *arg);
1127 int unifi_putest_coredump_prepare(unifi_priv_t *priv, unsigned char *arg);
1128 int unifi_putest_cmd52_write(unifi_priv_t *priv, unsigned char *arg);
1129 int unifi_putest_gp_read16(unifi_priv_t *priv, unsigned char *arg);
1130 int unifi_putest_gp_write16(unifi_priv_t *priv, unsigned char *arg);
1132 int unifi_putest_dl_fw(unifi_priv_t *priv, unsigned char *arg);
1133 int unifi_putest_dl_fw_buff(unifi_priv_t *priv, unsigned char *arg);
1136 /* Macro for formatting a MAC address with a prefix string */
1137 #define UF_TRACE_MAC(priv, lvl, msg, addr) \
1138 unifi_trace(priv, lvl, \
1139 "%s %02x-%02x-%02x-%02x-%02x-%02x\n", \
1141 *(((CsrUint8 *)addr)+0), \
1142 *(((CsrUint8 *)addr)+1), \
1143 *(((CsrUint8 *)addr)+2), \
1144 *(((CsrUint8 *)addr)+3), \
1145 *(((CsrUint8 *)addr)+4), \
1146 *(((CsrUint8 *)addr)+5))
1148 #endif /* __LINUX_UNIFI_PRIV_H__ */