drop 2.6.24 support
[acx-mac80211.git] / acx_func.h
blob2fa8d1d372cd7f24ef9ba72d5b390cae6461b4f4
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 void acx_print_mac(const char *head, const u8 *mac, const char *tail);
14 /* Optimized out to nothing in non-debug build */
16 /***********************************************************************
17 ** MAC address helpers
19 static inline void
20 MAC_COPY(u8 *mac, const u8 *src)
22 memcpy(mac, src, ETH_ALEN);
25 static inline void
26 MAC_FILL(u8 *mac, u8 val)
28 memset(mac, val, ETH_ALEN);
31 static inline void
32 MAC_BCAST(u8 *mac)
34 ((u16*)mac)[2] = *(u32*)mac = -1;
37 static inline void
38 MAC_ZERO(u8 *mac)
40 ((u16*)mac)[2] = *(u32*)mac = 0;
43 static inline int
44 mac_is_equal(const u8 *a, const u8 *b)
46 /* can't beat this */
47 return memcmp(a, b, ETH_ALEN) == 0;
50 static inline int
51 mac_is_bcast(const u8 *mac)
53 /* AND together 4 first bytes with sign-extended 2 last bytes
54 ** Only bcast address gives 0xffffffff. +1 gives 0 */
55 return ( *(s32*)mac & ((s16*)mac)[2] ) + 1 == 0;
58 static inline int
59 mac_is_zero(const u8 *mac)
61 return ( *(u32*)mac | ((u16*)mac)[2] ) == 0;
64 static inline int
65 mac_is_directed(const u8 *mac)
67 return (mac[0] & 1)==0;
70 static inline int
71 mac_is_mcast(const u8 *mac)
73 return (mac[0] & 1) && !mac_is_bcast(mac);
77 /***********************************************************************
78 ** Random helpers
80 #define TO_STRING(x) #x
81 #define STRING(x) TO_STRING(x)
83 #define CLEAR_BIT(val, mask) ((val) &= ~(mask))
84 #define SET_BIT(val, mask) ((val) |= (mask))
85 #define CHECK_BIT(val, mask) ((val) & (mask))
87 /* undefined if v==0 */
88 static inline unsigned int
89 lowest_bit(u16 v)
91 unsigned int n = 0;
92 while (!(v & 0xf)) { v>>=4; n+=4; }
93 while (!(v & 1)) { v>>=1; n++; }
94 return n;
97 /* undefined if v==0 */
98 static inline unsigned int
99 highest_bit(u16 v)
101 unsigned int n = 0;
102 while (v>0xf) { v>>=4; n+=4; }
103 while (v>1) { v>>=1; n++; }
104 return n;
107 /* undefined if v==0 */
108 static inline int
109 has_only_one_bit(u16 v)
111 return ((v-1) ^ v) >= v;
115 static inline int
116 is_hidden_essid(char *essid)
118 return (('\0' == essid[0]) ||
119 ((' ' == essid[0]) && ('\0' == essid[1])));
122 /***********************************************************************
123 ** LOCKING
124 ** We have adev->sem and adev->spinlock.
126 ** We employ following naming convention in order to get locking right:
128 ** acx_e_xxxx - external entry points called from process context.
129 ** It is okay to sleep. adev->sem is to be taken on entry.
130 ** acx_i_xxxx - external entry points possibly called from atomic context.
131 ** Sleeping is not allowed (and thus down(sem) is not legal!)
132 ** acx_s_xxxx - potentially sleeping functions. Do not ever call under lock!
133 ** acx_l_xxxx - functions which expect lock to be already taken.
134 ** rest - non-sleeping functions which do not require locking
135 ** but may be run under lock
137 ** A small number of local helpers do not have acx_[eisl]_ prefix.
138 ** They are always close to caller and are to be reviewed locally.
140 ** Theory of operation:
142 ** All process-context entry points (_e_ functions) take sem
143 ** immediately. IRQ handler and other 'atomic-context' entry points
144 ** (_i_ functions) take lock immediately on entry, but dont take sem
145 ** because that might sleep.
147 ** Thus *all* code is either protected by sem or lock, or both.
149 ** Code which must not run concurrently with IRQ takes lock.
150 ** Such code is marked with _l_.
152 ** This results in the following rules of thumb useful in code review:
154 ** + If a function calls _s_ fn, it must be an _s_ itself.
155 ** + You can call _l_ fn only (a) from another _l_ fn
156 ** or (b) from _s_, _e_ or _i_ fn by taking lock, calling _l_,
157 ** and dropping lock.
158 ** + All IRQ code runs under lock.
159 ** + Any _s_ fn is running under sem.
160 ** + Code under sem can race only with IRQ code.
161 ** + Code under sem+lock cannot race with anything.
164 /* These functions *must* be inline or they will break horribly on SPARC, due
165 * to its weird semantics for save/restore flags */
167 #if defined(PARANOID_LOCKING) /* Lock debugging */
169 void acx_lock_debug(acx_device_t *adev, const char* where);
170 void acx_unlock_debug(acx_device_t *adev, const char* where);
171 void acx_down_debug(acx_device_t *adev, const char* where);
172 void acx_up_debug(acx_device_t *adev, const char* where);
173 void acx_lock_unhold(void);
174 void acx_sem_unhold(void);
176 static inline void
177 acx_lock_helper(acx_device_t *adev, unsigned long *fp, const char* where)
179 acx_lock_debug(adev, where);
180 spin_lock_irqsave(&adev->spinlock, *fp);
182 static inline void
183 acx_unlock_helper(acx_device_t *adev, unsigned long *fp, const char* where)
185 acx_unlock_debug(adev, where);
186 spin_unlock_irqrestore(&adev->spinlock, *fp);
188 #define acx_lock(adev, flags) acx_lock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
189 #define acx_unlock(adev, flags) acx_unlock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
190 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
191 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
193 #elif defined(DO_LOCKING)
195 #define acx_lock(adev, flags) spin_lock_irqsave(&adev->spinlock, flags)
196 #define acx_unlock(adev, flags) spin_unlock_irqrestore(&adev->spinlock, flags)
197 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
198 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
199 #define acx_lock_unhold() ((void)0)
200 #define acx_sem_unhold() ((void)0)
202 #else /* no locking! :( */
204 #define acx_lock(adev, flags) ((void)0)
205 #define acx_unlock(adev, flags) ((void)0)
206 #define acx_sem_lock(adev) ((void)0)
207 #define acx_sem_unlock(adev) ((void)0)
208 #define acx_lock_unhold() ((void)0)
209 #define acx_sem_unhold() ((void)0)
211 #endif
214 /***********************************************************************
217 /* Can race with rx path (which is not protected by sem):
218 ** rx -> process_[re]assocresp() -> set_status(ASSOCIATED) -> wake_queue()
219 ** Can race with tx_complete IRQ:
220 ** IRQ -> acxpci_l_clean_txdesc -> acx_wake_queue
221 ** Review carefully all callsites */
222 static inline void
223 acx_stop_queue(struct ieee80211_hw *hw, const char *msg)
225 if (netif_queue_stopped(ndev))
226 return;
228 ieee80211_stop_queues(hw);
229 if (msg)
230 acx_log(LOG_DEBUG, L_BUFT, "tx: stop queue %s\n", msg);
233 /*static inline int
234 acx_queue_stopped(struct ieee80211_hw *ieee)
236 return netif_queue_stopped(ieee);
240 static inline void
241 acx_start_queue(struct ieee80211_hw *hw, const char *msg)
243 ieee80211_start_queues(hw);
244 if (msg)
245 log(L_BUFT, "tx: start queue %s\n", msg);
248 static inline void
249 acx_wake_queue(struct ieee80211_hw *hw, const char *msg)
251 ieee80211_wake_queues(hw);
252 if (msg)
253 acx_log(LOG_DEBUG, L_BUFT, "tx: wake queue %s\n", msg);
256 static inline void
257 acx_carrier_off(struct net_device *ndev, const char *msg)
259 netif_carrier_off(ndev);
260 if (msg)
261 log(L_BUFT, "tx: carrier off %s\n", msg);
264 static inline void
265 acx_carrier_on(struct net_device *ndev, const char *msg)
267 netif_carrier_on(ndev);
268 if (msg)
269 log(L_BUFT, "tx: carrier on %s\n", msg);
275 /***********************************************************************
276 ** Communication with firmware
278 #define CMD_TIMEOUT_MS(n) (n)
279 #define ACX_CMD_TIMEOUT_DEFAULT CMD_TIMEOUT_MS(50)
281 #if ACX_DEBUG
283 /* We want to log cmd names */
284 int acxpci_s_issue_cmd_timeo_debug(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout, const char* cmdstr);
285 int acxusb_s_issue_cmd_timeo_debug(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout, const char* cmdstr);
286 static inline int
287 acx_s_issue_cmd_timeo_debug(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout, const char* cmdstr)
289 if (IS_PCI(adev))
290 return acxpci_s_issue_cmd_timeo_debug(adev, cmd, param, len, timeout, cmdstr);
291 return acxusb_s_issue_cmd_timeo_debug(adev, cmd, param, len, timeout, cmdstr);
293 #define acx_s_issue_cmd(adev,cmd,param,len) \
294 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,ACX_CMD_TIMEOUT_DEFAULT,#cmd)
295 #define acx_s_issue_cmd_timeo(adev,cmd,param,len,timeo) \
296 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,timeo,#cmd)
297 int acx_s_configure_debug(acx_device_t *adev, void *pdr, int type, const char* str);
298 #define acx_s_configure(adev,pdr,type) \
299 acx_s_configure_debug(adev,pdr,type,#type)
300 int acx_s_interrogate_debug(acx_device_t *adev, void *pdr, int type, const char* str);
301 #define acx_s_interrogate(adev,pdr,type) \
302 acx_s_interrogate_debug(adev,pdr,type,#type)
304 #else
306 int acxpci_s_issue_cmd_timeo(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout);
307 int acxusb_s_issue_cmd_timeo(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout);
308 static inline int
309 acx_s_issue_cmd_timeo(acx_device_t *adev, unsigned cmd, void *param, unsigned len, unsigned timeout)
311 if (IS_PCI(adev))
312 return acxpci_s_issue_cmd_timeo(adev, cmd, param, len, timeout);
313 return acxusb_s_issue_cmd_timeo(adev, cmd, param, len, timeout);
315 static inline int
316 acx_s_issue_cmd(acx_device_t *adev, unsigned cmd, void *param, unsigned len)
318 if (IS_PCI(adev))
319 return acxpci_s_issue_cmd_timeo(adev, cmd, param, len, ACX_CMD_TIMEOUT_DEFAULT);
320 return acxusb_s_issue_cmd_timeo(adev, cmd, param, len, ACX_CMD_TIMEOUT_DEFAULT);
322 int acx_s_configure(acx_device_t *adev, void *pdr, int type);
323 int acx_s_interrogate(acx_device_t *adev, void *pdr, int type);
325 #endif
327 void acx_s_cmd_start_scan(acx_device_t *adev);
330 /***********************************************************************
331 ** Ioctls
333 /*int
334 acx111pci_ioctl_info(
335 struct net_device *ndev,
336 struct iw_request_info *info,
337 struct iw_param *vwrq,
338 char *extra);
340 acx100pci_ioctl_set_phy_amp_bias(
341 struct net_device *ndev,
342 struct iw_request_info *info,
343 struct iw_param *vwrq,
344 char *extra);
347 /***********************************************************************
348 ** /proc
350 #ifdef CONFIG_PROC_FS
351 int acx_proc_register_entries(struct ieee80211_hw *ieee);
352 int acx_proc_unregister_entries(struct ieee80211_hw *ieee);
353 #else
354 static inline int
355 acx_proc_register_entries(const struct ieee80211_hw *ieee) { return OK; }
356 static inline int
357 acx_proc_unregister_entries(const struct ieee80211_hw *ieee) { return OK; }
358 #endif
361 /***********************************************************************
363 firmware_image_t *acx_s_read_fw(struct device *dev, const char *file, u32 *size);
364 int acxpci_s_upload_radio(acx_device_t *adev);
367 /***********************************************************************
368 ** Unsorted yet :)
370 int acxpci_s_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf);
371 int acxusb_s_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf);
372 static inline int
373 acx_s_read_phy_reg(acx_device_t *adev, u32 reg, u8 *charbuf)
375 if (IS_PCI(adev))
376 return acxpci_s_read_phy_reg(adev, reg, charbuf);
377 return acxusb_s_read_phy_reg(adev, reg, charbuf);
380 int acxpci_s_write_phy_reg(acx_device_t *adev, u32 reg, u8 value);
381 int acxusb_s_write_phy_reg(acx_device_t *adev, u32 reg, u8 value);
382 static inline int
383 acx_s_write_phy_reg(acx_device_t *adev, u32 reg, u8 value)
385 if (IS_PCI(adev))
386 return acxpci_s_write_phy_reg(adev, reg, value);
387 return acxusb_s_write_phy_reg(adev, reg, value);
390 tx_t* acxpci_l_alloc_tx(acx_device_t *adev);
391 tx_t* acxusb_l_alloc_tx(acx_device_t *adev);
392 static inline tx_t*
393 acx_l_alloc_tx(acx_device_t *adev)
395 if (IS_PCI(adev))
396 return acxpci_l_alloc_tx(adev);
397 return acxusb_l_alloc_tx(adev);
400 void acxusb_l_dealloc_tx(tx_t *tx_opaque);
401 static inline void
402 acx_l_dealloc_tx(acx_device_t *adev, tx_t *tx_opaque)
404 if (IS_USB(adev))
405 acxusb_l_dealloc_tx(tx_opaque);
408 void* acxpci_l_get_txbuf(acx_device_t *adev, tx_t *tx_opaque);
409 void* acxusb_l_get_txbuf(acx_device_t *adev, tx_t *tx_opaque);
410 static inline void*
411 acx_l_get_txbuf(acx_device_t *adev, tx_t *tx_opaque)
413 if (IS_PCI(adev))
414 return acxpci_l_get_txbuf(adev, tx_opaque);
415 return acxusb_l_get_txbuf(adev, tx_opaque);
418 void acxpci_l_tx_data(acx_device_t *adev, tx_t *tx_opaque, int len,
419 struct ieee80211_tx_control *ieeectl, struct sk_buff *skb);
420 void acxusb_l_tx_data(acx_device_t *adev, tx_t *tx_opaque, int len, struct ieee80211_tx_control *ieeectl,
421 struct sk_buff *skb);
422 static inline void
423 acx_l_tx_data(acx_device_t *adev, tx_t *tx_opaque, int len,
424 struct ieee80211_tx_control *ieeectl, struct sk_buff *skb)
426 if (IS_PCI(adev))
427 acxpci_l_tx_data(adev, tx_opaque, len, ieeectl,skb);
428 else
429 acxusb_l_tx_data(adev, tx_opaque, len, ieeectl,skb);
432 static inline struct ieee80211_hdr *
433 acx_get_wlan_hdr(acx_device_t *adev, const rxbuffer_t *rxbuf)
435 return (struct ieee80211_hdr *)((u8 *)&rxbuf->hdr_a3 + adev->phy_header_len);
437 void acxpci_l_power_led(acx_device_t *adev, int enable);
438 int acxpci_read_eeprom_byte(acx_device_t *adev, u32 addr, u8 *charbuf);
439 unsigned int acxpci_l_clean_txdesc(acx_device_t *adev);
440 void acxpci_l_clean_txdesc_emergency(acx_device_t *adev);
441 int acxpci_s_create_hostdesc_queues(acx_device_t *adev);
442 void acxpci_create_desc_queues(acx_device_t *adev, u32 tx_queue_start, u32 rx_queue_start);
443 void acxpci_free_desc_queues(acx_device_t *adev);
444 char* acxpci_s_proc_diag_output(char *p, acx_device_t *adev);
445 int acxpci_proc_eeprom_output(char *p, acx_device_t *adev);
446 void acxpci_set_interrupt_mask(acx_device_t *adev);
447 int acx100pci_s_set_tx_level(acx_device_t *adev, u8 level_dbm);
449 void acx_s_mwait(int ms);
450 int acx_s_init_mac(acx_device_t *adev);
451 void acx_set_reg_domain(acx_device_t *adev, unsigned char reg_dom_id);
452 void acx_update_capabilities(acx_device_t *adev);
453 void acx_s_start(acx_device_t *adev);
455 void acx_s_update_card_settings(acx_device_t *adev);
456 void acx_s_parse_configoption(acx_device_t *adev, const acx111_ie_configoption_t *pcfg);
457 void acx_l_update_ratevector(acx_device_t *adev);
459 void acx_init_task_scheduler(acx_device_t *adev);
460 void acx_schedule_task(acx_device_t *adev, unsigned int set_flag);
462 int acx_e_ioctl_old(struct net_device *ndev, struct ifreq *ifr, int cmd);
464 client_t *acx_l_sta_list_get(acx_device_t *adev, const u8 *address);
465 void acx_l_sta_list_del(acx_device_t *adev, client_t *clt);
467 void acx_i_timer(unsigned long a);
469 struct sk_buff *acx_rxbuf_to_ether(acx_device_t *adev, rxbuffer_t *rxbuf);
470 int acx_ether_to_txbuf(acx_device_t *adev, void *txbuf, const struct sk_buff *skb);
472 u8 acx_signal_determine_quality(u8 signal, u8 noise);
474 void acx_l_process_rxbuf(acx_device_t *adev, rxbuffer_t *rxbuf);
475 void acx_l_handle_txrate_auto(acx_device_t *adev, struct client *txc,
476 u16 intended_rate, u8 rate100, u16 rate111, u8 error,
477 int pkts_to_ignore);
479 void acx_dump_bytes(const void *, int);
481 u8 acx_rate111to100(u16);
483 void acx_s_set_defaults(acx_device_t *adev);
485 #if !ACX_DEBUG
486 static inline const char* acx_get_packet_type_string(u16 fc) { return ""; }
487 #else
488 const char* acx_get_packet_type_string(u16 fc);
489 #endif
490 const char* acx_cmd_status_str(unsigned int state);
492 /*** Devicescape functions ***/
493 int acx_setup_modes(acx_device_t *adev);
494 void acx_free_modes(acx_device_t *adev);
495 int acx_i_start_xmit(struct ieee80211_hw* ieee,
496 struct sk_buff *skb,
497 struct ieee80211_tx_control *ctl);
498 int acx_add_interface(struct ieee80211_hw* ieee,
499 struct ieee80211_if_init_conf *conf);
500 void acx_remove_interface(struct ieee80211_hw* ieee,
501 struct ieee80211_if_init_conf *conf);
502 int acx_net_reset(struct ieee80211_hw* ieee);
503 int acx_net_set_key(struct ieee80211_hw *hw,
504 enum set_key_cmd cmd,
505 const u8 *local_addr, const u8 *addr,
506 struct ieee80211_key_conf *key);
508 extern int acx_config_interface(struct ieee80211_hw* ieee,
509 struct ieee80211_vif *vif,
510 struct ieee80211_if_conf *conf);
512 int acx_net_config(struct ieee80211_hw* ieee, struct ieee80211_conf *conf);
513 int acx_net_get_tx_stats(struct ieee80211_hw* ieee, struct ieee80211_tx_queue_stats *stats);
514 int acx_net_conf_tx(struct ieee80211_hw* ieee, int queue,
515 const struct ieee80211_tx_queue_params *params);
516 //int acx_passive_scan(struct net_device *net_dev, int state, struct ieee80211_scan_conf *conf);
517 //static void acx_netdev_init(struct net_device *ndev);
518 int acxpci_s_reset_dev(acx_device_t *adev);
519 void acx_e_after_interrupt_task(struct work_struct* work);
520 void acx_i_set_multicast_list(struct ieee80211_hw *hw,
521 unsigned int changed_flags,
522 unsigned int *total_flags,
523 int mc_count, struct dev_addr_list *mc_list);
525 /*** End DeviceScape Functions **/
527 void great_inquisitor(acx_device_t *adev);
529 void acx_s_get_firmware_version(acx_device_t *adev);
530 void acx_display_hardware_details(acx_device_t *adev);
532 int acx_e_change_mtu(struct ieee80211_hw *hw, int mtu);
533 int acx_e_get_stats(struct ieee80211_hw *hw, struct ieee80211_low_level_stats *stats);
534 struct iw_statistics* acx_e_get_wireless_stats(struct ieee80211_hw *hw);
535 void acx_interrupt_tasklet(struct work_struct *work);
537 int __init acxpci_e_init_module(void);
538 int __init acxusb_e_init_module(void);
539 void __exit acxpci_e_cleanup_module(void);
540 void __exit acxusb_e_cleanup_module(void);
542 #endif /* _ACX_FUNC_H_ */