Reverted refactoring of 'interrogate' cmds to 'query'
[acx-mac80211.git] / acx_func.h
blob0315c3512b9c205b568dec847ad4bf374ce46efb
1 #ifndef _ACX_FUNC_H_
2 #define _ACX_FUNC_H_
4 /** (legal) claimer in README
5 ** Copyright (C) 2003 ACX100 Open Source Project
6 */
8 #include <linux/version.h>
9 #include "acx_debug.h"
10 #include "acx_log.h"
12 * FIXME: this file is needed only so that the lock debugging functions have an
13 * acx_device_t structure to play with :(
15 #include "acx_struct.h"
17 /* Optimized out to nothing in non-debug build */
19 /***********************************************************************
20 ** MAC address helpers
22 static inline void
23 MAC_COPY(u8 *mac, const u8 *src)
25 memcpy(mac, src, ETH_ALEN);
28 static inline void
29 MAC_FILL(u8 *mac, u8 val)
31 memset(mac, val, ETH_ALEN);
34 static inline void
35 MAC_BCAST(u8 *mac)
37 ((u16*)mac)[2] = *(u32*)mac = -1;
40 static inline void
41 MAC_ZERO(u8 *mac)
43 ((u16*)mac)[2] = *(u32*)mac = 0;
46 static inline int
47 mac_is_equal(const u8 *a, const u8 *b)
49 /* can't beat this */
50 return memcmp(a, b, ETH_ALEN) == 0;
53 static inline int
54 mac_is_bcast(const u8 *mac)
56 /* AND together 4 first bytes with sign-extended 2 last bytes
57 ** Only bcast address gives 0xffffffff. +1 gives 0 */
58 return ( *(s32*)mac & ((s16*)mac)[2] ) + 1 == 0;
61 static inline int
62 mac_is_zero(const u8 *mac)
64 return ( *(u32*)mac | ((u16*)mac)[2] ) == 0;
67 static inline int
68 mac_is_directed(const u8 *mac)
70 return (mac[0] & 1)==0;
73 static inline int
74 mac_is_mcast(const u8 *mac)
76 return (mac[0] & 1) && !mac_is_bcast(mac);
80 /***********************************************************************
81 ** Random helpers
83 #define TO_STRING(x) #x
84 #define STRING(x) TO_STRING(x)
86 #define CLEAR_BIT(val, mask) ((val) &= ~(mask))
87 #define SET_BIT(val, mask) ((val) |= (mask))
88 #define CHECK_BIT(val, mask) ((val) & (mask))
90 /* undefined if v==0 */
91 static inline unsigned int
92 lowest_bit(u16 v)
94 unsigned int n = 0;
95 while (!(v & 0xf)) { v>>=4; n+=4; }
96 while (!(v & 1)) { v>>=1; n++; }
97 return n;
100 /* undefined if v==0 */
101 static inline unsigned int
102 highest_bit(u16 v)
104 unsigned int n = 0;
105 while (v>0xf) { v>>=4; n+=4; }
106 while (v>1) { v>>=1; n++; }
107 return n;
110 /* undefined if v==0 */
111 static inline int
112 has_only_one_bit(u16 v)
114 return ((v-1) ^ v) >= v;
118 static inline int
119 is_hidden_essid(char *essid)
121 return (('\0' == essid[0]) ||
122 ((' ' == essid[0]) && ('\0' == essid[1])));
125 /***********************************************************************
126 ** LOCKING
127 ** We have adev->sem and adev->spinlock.
129 ** We employ following naming convention in order to get locking right:
131 ** acx_e_xxxx - external entry points called from process context.
132 ** It is okay to sleep. adev->sem is to be taken on entry.
133 ** acx_i_xxxx - external entry points possibly called from atomic context.
134 ** Sleeping is not allowed (and thus down(sem) is not legal!)
135 ** acx_s_xxxx - potentially sleeping functions. Do not ever call under lock!
136 ** acx_l_xxxx - functions which expect lock to be already taken.
137 ** rest - non-sleeping functions which do not require locking
138 ** but may be run under lock
140 ** A small number of local helpers do not have acx_[eisl]_ prefix.
141 ** They are always close to caller and are to be reviewed locally.
143 ** Theory of operation:
145 ** All process-context entry points (_e_ functions) take sem
146 ** immediately. IRQ handler and other 'atomic-context' entry points
147 ** (_i_ functions) take lock immediately on entry, but dont take sem
148 ** because that might sleep.
150 ** Thus *all* code is either protected by sem or lock, or both.
152 ** Code which must not run concurrently with IRQ takes lock.
153 ** Such code is marked with _l_.
155 ** This results in the following rules of thumb useful in code review:
157 ** + If a function calls _s_ fn, it must be an _s_ itself.
158 ** + You can call _l_ fn only (a) from another _l_ fn
159 ** or (b) from _s_, _e_ or _i_ fn by taking lock, calling _l_,
160 ** and dropping lock.
161 ** + All IRQ code runs under lock.
162 ** + Any _s_ fn is running under sem.
163 ** + Code under sem can race only with IRQ code.
164 ** + Code under sem+lock cannot race with anything.
167 /* These functions *must* be inline or they will break horribly on SPARC, due
168 * to its weird semantics for save/restore flags */
170 #if defined(PARANOID_LOCKING) /* Lock debugging */
172 void acx_lock_debug(acx_device_t *adev, const char* where);
173 void acx_unlock_debug(acx_device_t *adev, const char* where);
174 void acx_down_debug(acx_device_t *adev, const char* where);
175 void acx_up_debug(acx_device_t *adev, const char* where);
176 void acx_lock_unhold(void);
177 void acx_sem_unhold(void);
179 static inline void
180 acx_lock_helper(acx_device_t *adev, unsigned long *fp, const char* where)
182 acx_lock_debug(adev, where);
183 spin_lock_irqsave(&adev->spinlock, *fp);
185 static inline void
186 acx_unlock_helper(acx_device_t *adev, unsigned long *fp, const char* where)
188 acx_unlock_debug(adev, where);
189 spin_unlock_irqrestore(&adev->spinlock, *fp);
191 #define acx_lock(adev, flags) acx_lock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
192 #define acx_unlock(adev, flags) acx_unlock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
193 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
194 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
196 #elif defined(DO_LOCKING)
198 #define acx_lock(adev, flags) spin_lock_irqsave(&adev->spinlock, flags)
199 #define acx_unlock(adev, flags) spin_unlock_irqrestore(&adev->spinlock, flags)
200 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
201 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
202 #define acx_lock_unhold() ((void)0)
203 #define acx_sem_unhold() ((void)0)
205 #else /* no locking! :( */
207 #define acx_lock(adev, flags) ((void)0)
208 #define acx_unlock(adev, flags) ((void)0)
209 #define acx_sem_lock(adev) ((void)0)
210 #define acx_sem_unlock(adev) ((void)0)
211 #define acx_lock_unhold() ((void)0)
212 #define acx_sem_unhold() ((void)0)
214 #endif
217 /***********************************************************************
220 /* Can race with rx path (which is not protected by sem):
221 ** rx -> process_[re]assocresp() -> set_status(ASSOCIATED) -> wake_queue()
222 ** Can race with tx_complete IRQ:
223 ** IRQ -> acxpci_l_clean_txdesc -> acx_wake_queue
224 ** Review carefully all callsites */
225 static inline void
226 acx_stop_queue(struct ieee80211_hw *hw, const char *msg)
228 if (netif_queue_stopped(ndev))
229 return;
231 ieee80211_stop_queues(hw);
232 if (msg)
233 acx_log(LOG_DEBUG, L_BUFT, "tx: stop queue %s\n", msg);
236 /*static inline int
237 acx_queue_stopped(struct ieee80211_hw *ieee)
239 return netif_queue_stopped(ieee);
243 static inline void
244 acx_start_queue(struct ieee80211_hw *hw, const char *msg)
246 ieee80211_start_queues(hw);
247 if (msg)
248 log(L_BUFT, "tx: start queue %s\n", msg);
251 static inline void
252 acx_wake_queue(struct ieee80211_hw *hw, const char *msg)
254 ieee80211_wake_queues(hw);
255 if (msg)
256 acx_log(LOG_DEBUG, L_BUFT, "tx: wake queue %s\n", msg);
259 static inline void
260 acx_carrier_off(struct net_device *ndev, const char *msg)
262 netif_carrier_off(ndev);
263 if (msg)
264 log(L_BUFT, "tx: carrier off %s\n", msg);
267 static inline void
268 acx_carrier_on(struct net_device *ndev, const char *msg)
270 netif_carrier_on(ndev);
271 if (msg)
272 log(L_BUFT, "tx: carrier on %s\n", msg);
278 /***********************************************************************
279 ** Communication with firmware
281 #define CMD_TIMEOUT_MS(n) (n)
282 #define ACX_CMD_TIMEOUT_DEFAULT CMD_TIMEOUT_MS(50)
284 #if ACX_DEBUG
286 /* We want to log cmd names */
287 int acxpci_s_issue_cmd_timeo_debug(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout, const char* cmdstr);
288 int acxusb_s_issue_cmd_timeo_debug(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout, const char* cmdstr);
289 static inline int
290 acx_s_issue_cmd_timeo_debug(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout, const char* cmdstr)
292 if (IS_PCI(adev))
293 return acxpci_s_issue_cmd_timeo_debug(adev, cmd, param, len, timeout, cmdstr);
294 return acxusb_s_issue_cmd_timeo_debug(adev, cmd, param, len, timeout, cmdstr);
296 #define acx_s_issue_cmd(adev,cmd,param,len) \
297 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,ACX_CMD_TIMEOUT_DEFAULT,#cmd)
298 #define acx_s_issue_cmd_timeo(adev,cmd,param,len,timeo) \
299 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,timeo,#cmd)
300 int acx_s_configure_debug(acx_device_t *adev, void *pdr, int type, const char* str);
301 #define acx_s_configure(adev,pdr,type) \
302 acx_s_configure_debug(adev,pdr,type,#type)
303 int acx_s_interrogate_debug(acx_device_t *adev, void *pdr, int type, const char* str);
304 #define acx_s_interrogate(adev,pdr,type) \
305 acx_s_interrogate_debug(adev,pdr,type,#type)
307 #else
309 int acxpci_s_issue_cmd_timeo(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout);
310 int acxusb_s_issue_cmd_timeo(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout);
311 static inline int
312 acx_s_issue_cmd_timeo(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout)
314 if (IS_PCI(adev))
315 return acxpci_s_issue_cmd_timeo(adev, cmd, param, len, timeout);
316 return acxusb_s_issue_cmd_timeo(adev, cmd, param, len, timeout);
318 static inline int
319 acx_s_issue_cmd(acx_device_t *adev, unsigned cmd, void *param, unsigned len)
321 if (IS_PCI(adev))
322 return acxpci_s_issue_cmd_timeo(adev, cmd, param, len, ACX_CMD_TIMEOUT_DEFAULT);
323 return acxusb_s_issue_cmd_timeo(adev, cmd, param, len, ACX_CMD_TIMEOUT_DEFAULT);
325 int acx_s_configure(acx_device_t *adev, void *pdr, int type);
326 int acx_s_interrogate(acx_device_t *adev, void *pdr, int type);
328 #endif
330 void acx_s_cmd_start_scan(acx_device_t *adev);
333 /***********************************************************************
334 ** Ioctls
336 /*int
337 acx111pci_ioctl_info(
338 struct net_device *ndev,
339 struct iw_request_info *info,
340 struct iw_param *vwrq,
341 char *extra);
343 acx100pci_ioctl_set_phy_amp_bias(
344 struct net_device *ndev,
345 struct iw_request_info *info,
346 struct iw_param *vwrq,
347 char *extra);
350 /***********************************************************************
351 ** /proc
353 #ifdef CONFIG_PROC_FS
354 int acx_proc_register_entries(struct ieee80211_hw *ieee);
355 int acx_proc_unregister_entries(struct ieee80211_hw *ieee);
356 #else
357 static inline int
358 acx_proc_register_entries(const struct ieee80211_hw *ieee) { return OK; }
359 static inline int
360 acx_proc_unregister_entries(const struct ieee80211_hw *ieee) { return OK; }
361 #endif
364 /***********************************************************************
366 firmware_image_t *acx_s_read_fw(struct device *dev, const char *file, u32 *size);
367 int acxpci_s_upload_radio(acx_device_t *adev);
370 /***********************************************************************
371 ** Unsorted yet :)
373 int acxpci_s_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf);
374 int acxusb_s_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf);
375 static inline int
376 acx_s_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf)
378 if (IS_PCI(adev))
379 return acxpci_s_read_phy_reg(adev, reg, charbuf);
380 return acxusb_s_read_phy_reg(adev, reg, charbuf);
383 int acxpci_s_write_phy_reg(acx_device_t *adev, u32 reg, u8 value);
384 int acxusb_s_write_phy_reg(acx_device_t *adev, u32 reg, u8 value);
385 static inline int
386 acx_s_write_phy_reg(acx_device_t *adev, u32 reg, u8 value)
388 if (IS_PCI(adev))
389 return acxpci_s_write_phy_reg(adev, reg, value);
390 return acxusb_s_write_phy_reg(adev, reg, value);
393 tx_t* acxpci_l_alloc_tx(acx_device_t *adev);
394 tx_t* acxusb_l_alloc_tx(acx_device_t *adev);
395 static inline tx_t*
396 acx_l_alloc_tx(acx_device_t *adev)
398 if (IS_PCI(adev))
399 return acxpci_l_alloc_tx(adev);
400 return acxusb_l_alloc_tx(adev);
403 void acxusb_l_dealloc_tx(tx_t *tx_opaque);
404 static inline void
405 acx_l_dealloc_tx(acx_device_t *adev, tx_t *tx_opaque)
407 if (IS_USB(adev))
408 acxusb_l_dealloc_tx(tx_opaque);
411 void* acxpci_l_get_txbuf(acx_device_t *adev, tx_t *tx_opaque);
412 void* acxusb_l_get_txbuf(acx_device_t *adev, tx_t *tx_opaque);
413 static inline void*
414 acx_l_get_txbuf(acx_device_t *adev, tx_t *tx_opaque)
416 if (IS_PCI(adev))
417 return acxpci_l_get_txbuf(adev, tx_opaque);
418 return acxusb_l_get_txbuf(adev, tx_opaque);
421 void acxpci_l_tx_data(acx_device_t *adev, tx_t *tx_opaque, int len,
422 struct ieee80211_tx_control *ieeectl, struct sk_buff *skb);
423 void acxusb_l_tx_data(acx_device_t *adev, tx_t *tx_opaque, int len, struct ieee80211_tx_control *ieeectl,
424 struct sk_buff *skb);
425 static inline void
426 acx_l_tx_data(acx_device_t *adev, tx_t *tx_opaque, int len,
427 struct ieee80211_tx_control *ieeectl, struct sk_buff *skb)
429 if (IS_PCI(adev))
430 acxpci_l_tx_data(adev, tx_opaque, len, ieeectl,skb);
431 else
432 acxusb_l_tx_data(adev, tx_opaque, len, ieeectl,skb);
435 static inline struct ieee80211_hdr *
436 acx_get_wlan_hdr(acx_device_t *adev, const rxbuffer_t *rxbuf)
438 return (struct ieee80211_hdr *)((u8 *)&rxbuf->hdr_a3 + adev->phy_header_len);
440 void acxpci_l_power_led(acx_device_t *adev, int enable);
441 int acxpci_read_eeprom_byte(acx_device_t *adev, u32 addr, u8 *charbuf);
442 unsigned int acxpci_l_clean_txdesc(acx_device_t *adev);
443 void acxpci_l_clean_txdesc_emergency(acx_device_t *adev);
444 int acxpci_s_create_hostdesc_queues(acx_device_t *adev);
445 void acxpci_create_desc_queues(acx_device_t *adev, u32 tx_queue_start, u32 rx_queue_start);
446 void acxpci_free_desc_queues(acx_device_t *adev);
447 char* acxpci_s_proc_diag_output(char *p, acx_device_t *adev);
448 int acxpci_proc_eeprom_output(char *p, acx_device_t *adev);
449 void acxpci_set_interrupt_mask(acx_device_t *adev);
450 int acx100pci_s_set_tx_level(acx_device_t *adev, u8 level_dbm);
452 void acx_s_mwait(int ms);
453 int acx_s_init_mac(acx_device_t *adev);
454 void acx_set_reg_domain(acx_device_t *adev, unsigned char reg_dom_id);
455 void acx_update_capabilities(acx_device_t *adev);
456 void acx_s_start(acx_device_t *adev);
458 void acx_s_update_card_settings(acx_device_t *adev);
459 void acx_s_parse_configoption(acx_device_t *adev, const acx111_ie_configoption_t *pcfg);
460 void acx_l_update_ratevector(acx_device_t *adev);
462 void acx_init_task_scheduler(acx_device_t *adev);
463 void acx_schedule_task(acx_device_t *adev, unsigned int set_flag);
465 int acx_e_ioctl_old(struct net_device *ndev, struct ifreq *ifr, int cmd);
467 client_t *acx_l_sta_list_get(acx_device_t *adev, const u8 *address);
468 void acx_l_sta_list_del(acx_device_t *adev, client_t *clt);
470 void acx_i_timer(unsigned long a);
472 struct sk_buff *acx_rxbuf_to_ether(acx_device_t *adev, rxbuffer_t *rxbuf);
473 int acx_ether_to_txbuf(acx_device_t *adev, void *txbuf, const struct sk_buff *skb);
475 u8 acx_signal_determine_quality(u8 signal, u8 noise);
477 void acx_l_process_rxbuf(acx_device_t *adev, rxbuffer_t *rxbuf);
478 void acx_l_handle_txrate_auto(acx_device_t *adev, struct client *txc,
479 u16 intended_rate, u8 rate100, u16 rate111, u8 error,
480 int pkts_to_ignore);
482 void acx_dump_bytes(const void *, int);
484 u8 acx_rate111to100(u16);
486 void acx_s_set_defaults(acx_device_t *adev);
488 #if !ACX_DEBUG
489 static inline const char* acx_get_packet_type_string(u16 fc) { return ""; }
490 #else
491 const char* acx_get_packet_type_string(u16 fc);
492 #endif
493 const char* acx_cmd_status_str(unsigned int state);
495 /*** Devicescape functions ***/
496 int acx_setup_modes(acx_device_t *adev);
497 void acx_free_modes(acx_device_t *adev);
498 int acx_i_start_xmit(struct ieee80211_hw* ieee,
499 struct sk_buff *skb,
500 struct ieee80211_tx_control *ctl);
501 int acx_add_interface(struct ieee80211_hw* ieee,
502 struct ieee80211_if_init_conf *conf);
503 void acx_remove_interface(struct ieee80211_hw* ieee,
504 struct ieee80211_if_init_conf *conf);
505 int acx_net_reset(struct ieee80211_hw* ieee);
506 int acx_net_set_key(struct ieee80211_hw *hw,
507 enum set_key_cmd cmd,
508 const u8 *local_addr, const u8 *addr,
509 struct ieee80211_key_conf *key);
511 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
512 extern int acx_config_interface(struct ieee80211_hw* ieee,
513 struct ieee80211_vif *vif,
514 struct ieee80211_if_conf *conf);
515 #else
516 int acx_config_interface(struct ieee80211_hw* ieee, int if_id,
517 struct ieee80211_if_conf *conf);
518 #endif
520 int acx_net_config(struct ieee80211_hw* ieee, struct ieee80211_conf *conf);
521 int acx_net_get_tx_stats(struct ieee80211_hw* ieee, struct ieee80211_tx_queue_stats *stats);
522 int acx_net_conf_tx(struct ieee80211_hw* ieee, int queue,
523 const struct ieee80211_tx_queue_params *params);
524 //int acx_passive_scan(struct net_device *net_dev, int state, struct ieee80211_scan_conf *conf);
525 //static void acx_netdev_init(struct net_device *ndev);
526 int acxpci_s_reset_dev(acx_device_t *adev);
527 void acx_e_after_interrupt_task(struct work_struct* work);
528 void acx_i_set_multicast_list(struct ieee80211_hw *hw,
529 unsigned int changed_flags,
530 unsigned int *total_flags,
531 int mc_count, struct dev_addr_list *mc_list);
533 /*** End DeviceScape Functions **/
535 void great_inquisitor(acx_device_t *adev);
537 void acx_s_get_firmware_version(acx_device_t *adev);
538 void acx_display_hardware_details(acx_device_t *adev);
540 int acx_e_change_mtu(struct ieee80211_hw *hw, int mtu);
541 int acx_e_get_stats(struct ieee80211_hw *hw, struct ieee80211_low_level_stats *stats);
542 struct iw_statistics* acx_e_get_wireless_stats(struct ieee80211_hw *hw);
543 void acx_interrupt_tasklet(struct work_struct *work);
545 int __init acxpci_e_init_module(void);
546 int __init acxusb_e_init_module(void);
547 void __exit acxpci_e_cleanup_module(void);
548 void __exit acxusb_e_cleanup_module(void);
550 #endif /* _ACX_FUNC_H_ */