4 /** (legal) claimer in README
5 ** Copyright (C) 2003 ACX100 Open Source Project
8 #include <linux/version.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 void acx_print_mac(const char *head
, const u8
*mac
, const char *tail
);
19 /* Optimized out to nothing in non-debug build */
21 /***********************************************************************
22 ** MAC address helpers
25 MAC_COPY(u8
*mac
, const u8
*src
)
27 memcpy(mac
, src
, ETH_ALEN
);
31 MAC_FILL(u8
*mac
, u8 val
)
33 memset(mac
, val
, ETH_ALEN
);
39 ((u16
*)mac
)[2] = *(u32
*)mac
= -1;
45 ((u16
*)mac
)[2] = *(u32
*)mac
= 0;
49 mac_is_equal(const u8
*a
, const u8
*b
)
52 return memcmp(a
, b
, ETH_ALEN
) == 0;
56 mac_is_bcast(const u8
*mac
)
58 /* AND together 4 first bytes with sign-extended 2 last bytes
59 ** Only bcast address gives 0xffffffff. +1 gives 0 */
60 return ( *(s32
*)mac
& ((s16
*)mac
)[2] ) + 1 == 0;
64 mac_is_zero(const u8
*mac
)
66 return ( *(u32
*)mac
| ((u16
*)mac
)[2] ) == 0;
70 mac_is_directed(const u8
*mac
)
72 return (mac
[0] & 1)==0;
76 mac_is_mcast(const u8
*mac
)
78 return (mac
[0] & 1) && !mac_is_bcast(mac
);
82 /***********************************************************************
85 #define TO_STRING(x) #x
86 #define STRING(x) TO_STRING(x)
88 #define CLEAR_BIT(val, mask) ((val) &= ~(mask))
89 #define SET_BIT(val, mask) ((val) |= (mask))
90 #define CHECK_BIT(val, mask) ((val) & (mask))
92 /* undefined if v==0 */
93 static inline unsigned int
97 while (!(v
& 0xf)) { v
>>=4; n
+=4; }
98 while (!(v
& 1)) { v
>>=1; n
++; }
102 /* undefined if v==0 */
103 static inline unsigned int
107 while (v
>0xf) { v
>>=4; n
+=4; }
108 while (v
>1) { v
>>=1; n
++; }
112 /* undefined if v==0 */
114 has_only_one_bit(u16 v
)
116 return ((v
-1) ^ v
) >= v
;
121 is_hidden_essid(char *essid
)
123 return (('\0' == essid
[0]) ||
124 ((' ' == essid
[0]) && ('\0' == essid
[1])));
127 /***********************************************************************
129 ** We have adev->sem and adev->spinlock.
131 ** We employ following naming convention in order to get locking right:
133 ** acx_e_xxxx - external entry points called from process context.
134 ** It is okay to sleep. adev->sem is to be taken on entry.
135 ** acx_i_xxxx - external entry points possibly called from atomic context.
136 ** Sleeping is not allowed (and thus down(sem) is not legal!)
137 ** acx_s_xxxx - potentially sleeping functions. Do not ever call under lock!
138 ** acx_l_xxxx - functions which expect lock to be already taken.
139 ** rest - non-sleeping functions which do not require locking
140 ** but may be run under lock
142 ** A small number of local helpers do not have acx_[eisl]_ prefix.
143 ** They are always close to caller and are to be reviewed locally.
145 ** Theory of operation:
147 ** All process-context entry points (_e_ functions) take sem
148 ** immediately. IRQ handler and other 'atomic-context' entry points
149 ** (_i_ functions) take lock immediately on entry, but dont take sem
150 ** because that might sleep.
152 ** Thus *all* code is either protected by sem or lock, or both.
154 ** Code which must not run concurrently with IRQ takes lock.
155 ** Such code is marked with _l_.
157 ** This results in the following rules of thumb useful in code review:
159 ** + If a function calls _s_ fn, it must be an _s_ itself.
160 ** + You can call _l_ fn only (a) from another _l_ fn
161 ** or (b) from _s_, _e_ or _i_ fn by taking lock, calling _l_,
162 ** and dropping lock.
163 ** + All IRQ code runs under lock.
164 ** + Any _s_ fn is running under sem.
165 ** + Code under sem can race only with IRQ code.
166 ** + Code under sem+lock cannot race with anything.
169 /* These functions *must* be inline or they will break horribly on SPARC, due
170 * to its weird semantics for save/restore flags */
172 #if defined(PARANOID_LOCKING) /* Lock debugging */
174 void acx_lock_debug(acx_device_t
*adev
, const char* where
);
175 void acx_unlock_debug(acx_device_t
*adev
, const char* where
);
176 void acx_down_debug(acx_device_t
*adev
, const char* where
);
177 void acx_up_debug(acx_device_t
*adev
, const char* where
);
178 void acx_lock_unhold(void);
179 void acx_sem_unhold(void);
182 acx_lock_helper(acx_device_t
*adev
, unsigned long *fp
, const char* where
)
184 acx_lock_debug(adev
, where
);
185 spin_lock_irqsave(&adev
->spinlock
, *fp
);
188 acx_unlock_helper(acx_device_t
*adev
, unsigned long *fp
, const char* where
)
190 acx_unlock_debug(adev
, where
);
191 spin_unlock_irqrestore(&adev
->spinlock
, *fp
);
193 #define acx_lock(adev, flags) acx_lock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
194 #define acx_unlock(adev, flags) acx_unlock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
195 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
196 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
198 #elif defined(DO_LOCKING)
200 #define acx_lock(adev, flags) spin_lock_irqsave(&adev->spinlock, flags)
201 #define acx_unlock(adev, flags) spin_unlock_irqrestore(&adev->spinlock, flags)
202 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
203 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
204 #define acx_lock_unhold() ((void)0)
205 #define acx_sem_unhold() ((void)0)
207 #else /* no locking! :( */
209 #define acx_lock(adev, flags) ((void)0)
210 #define acx_unlock(adev, flags) ((void)0)
211 #define acx_sem_lock(adev) ((void)0)
212 #define acx_sem_unlock(adev) ((void)0)
213 #define acx_lock_unhold() ((void)0)
214 #define acx_sem_unhold() ((void)0)
219 /***********************************************************************
222 /* Can race with rx path (which is not protected by sem):
223 ** rx -> process_[re]assocresp() -> set_status(ASSOCIATED) -> wake_queue()
224 ** Can race with tx_complete IRQ:
225 ** IRQ -> acxpci_l_clean_txdesc -> acx_wake_queue
226 ** Review carefully all callsites */
228 acx_stop_queue(struct ieee80211_hw
*hw
, const char *msg
)
230 if (netif_queue_stopped(ndev))
233 ieee80211_stop_queues(hw
);
235 acx_log(LOG_DEBUG
, L_BUFT
, "tx: stop queue %s\n", msg
);
239 acx_queue_stopped(struct ieee80211_hw *ieee)
241 return netif_queue_stopped(ieee);
246 acx_start_queue(struct ieee80211_hw *hw, const char *msg)
248 ieee80211_start_queues(hw);
250 log(L_BUFT, "tx: start queue %s\n", msg);
254 acx_wake_queue(struct ieee80211_hw
*hw
, const char *msg
)
256 ieee80211_wake_queues(hw
);
258 acx_log(LOG_DEBUG
, L_BUFT
, "tx: wake queue %s\n", msg
);
262 acx_carrier_off(struct net_device *ndev, const char *msg)
264 netif_carrier_off(ndev);
266 log(L_BUFT, "tx: carrier off %s\n", msg);
270 acx_carrier_on(struct net_device *ndev, const char *msg)
272 netif_carrier_on(ndev);
274 log(L_BUFT, "tx: carrier on %s\n", msg);
280 /***********************************************************************
281 ** Communication with firmware
283 #define CMD_TIMEOUT_MS(n) (n)
284 #define ACX_CMD_TIMEOUT_DEFAULT CMD_TIMEOUT_MS(50)
288 /* We want to log cmd names */
289 int acxpci_s_issue_cmd_timeo_debug(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
, const char* cmdstr
);
290 int acxusb_s_issue_cmd_timeo_debug(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
, const char* cmdstr
);
292 acx_s_issue_cmd_timeo_debug(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
, const char* cmdstr
)
295 return acxpci_s_issue_cmd_timeo_debug(adev
, cmd
, param
, len
, timeout
, cmdstr
);
296 return acxusb_s_issue_cmd_timeo_debug(adev
, cmd
, param
, len
, timeout
, cmdstr
);
298 #define acx_s_issue_cmd(adev,cmd,param,len) \
299 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,ACX_CMD_TIMEOUT_DEFAULT,#cmd)
300 #define acx_s_issue_cmd_timeo(adev,cmd,param,len,timeo) \
301 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,timeo,#cmd)
302 int acx_s_configure_debug(acx_device_t
*adev
, void *pdr
, int type
, const char* str
);
303 #define acx_s_configure(adev,pdr,type) \
304 acx_s_configure_debug(adev,pdr,type,#type)
305 int acx_s_interrogate_debug(acx_device_t
*adev
, void *pdr
, int type
, const char* str
);
306 #define acx_s_interrogate(adev,pdr,type) \
307 acx_s_interrogate_debug(adev,pdr,type,#type)
311 int acxpci_s_issue_cmd_timeo(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
);
312 int acxusb_s_issue_cmd_timeo(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
);
314 acx_s_issue_cmd_timeo(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
)
317 return acxpci_s_issue_cmd_timeo(adev
, cmd
, param
, len
, timeout
);
318 return acxusb_s_issue_cmd_timeo(adev
, cmd
, param
, len
, timeout
);
321 acx_s_issue_cmd(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
)
324 return acxpci_s_issue_cmd_timeo(adev
, cmd
, param
, len
, ACX_CMD_TIMEOUT_DEFAULT
);
325 return acxusb_s_issue_cmd_timeo(adev
, cmd
, param
, len
, ACX_CMD_TIMEOUT_DEFAULT
);
327 int acx_s_configure(acx_device_t
*adev
, void *pdr
, int type
);
328 int acx_s_interrogate(acx_device_t
*adev
, void *pdr
, int type
);
332 void acx_s_cmd_start_scan(acx_device_t
*adev
);
335 /***********************************************************************
339 acx111pci_ioctl_info(
340 struct net_device *ndev,
341 struct iw_request_info *info,
342 struct iw_param *vwrq,
345 acx100pci_ioctl_set_phy_amp_bias(
346 struct net_device *ndev,
347 struct iw_request_info *info,
348 struct iw_param *vwrq,
352 /***********************************************************************
355 #ifdef CONFIG_PROC_FS
356 int acx_proc_register_entries(struct ieee80211_hw
*ieee
);
357 int acx_proc_unregister_entries(struct ieee80211_hw
*ieee
);
360 acx_proc_register_entries(const struct ieee80211_hw
*ieee
) { return OK
; }
362 acx_proc_unregister_entries(const struct ieee80211_hw
*ieee
) { return OK
; }
366 /***********************************************************************
368 firmware_image_t
*acx_s_read_fw(struct device
*dev
, const char *file
, u32
*size
);
369 int acxpci_s_upload_radio(acx_device_t
*adev
);
372 /***********************************************************************
375 int acxpci_s_read_phy_reg(acx_device_t
*adev
, u32 reg
, u8
*charbuf
);
376 int acxusb_s_read_phy_reg(acx_device_t
*adev
, u32 reg
, u8
*charbuf
);
378 acx_s_read_phy_reg(acx_device_t
*adev
, u32 reg
, u8
*charbuf
)
381 return acxpci_s_read_phy_reg(adev
, reg
, charbuf
);
382 return acxusb_s_read_phy_reg(adev
, reg
, charbuf
);
385 int acxpci_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
);
386 int acxusb_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
);
388 acx_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
)
391 return acxpci_s_write_phy_reg(adev
, reg
, value
);
392 return acxusb_s_write_phy_reg(adev
, reg
, value
);
395 tx_t
* acxpci_l_alloc_tx(acx_device_t
*adev
);
396 tx_t
* acxusb_l_alloc_tx(acx_device_t
*adev
);
398 acx_l_alloc_tx(acx_device_t
*adev
)
401 return acxpci_l_alloc_tx(adev
);
402 return acxusb_l_alloc_tx(adev
);
405 void acxusb_l_dealloc_tx(tx_t
*tx_opaque
);
407 acx_l_dealloc_tx(acx_device_t
*adev
, tx_t
*tx_opaque
)
410 acxusb_l_dealloc_tx(tx_opaque
);
413 void* acxpci_l_get_txbuf(acx_device_t
*adev
, tx_t
*tx_opaque
);
414 void* acxusb_l_get_txbuf(acx_device_t
*adev
, tx_t
*tx_opaque
);
416 acx_l_get_txbuf(acx_device_t
*adev
, tx_t
*tx_opaque
)
419 return acxpci_l_get_txbuf(adev
, tx_opaque
);
420 return acxusb_l_get_txbuf(adev
, tx_opaque
);
423 void acxpci_l_tx_data(acx_device_t
*adev
, tx_t
*tx_opaque
, int len
,
424 struct ieee80211_tx_control
*ieeectl
, struct sk_buff
*skb
);
425 void acxusb_l_tx_data(acx_device_t
*adev
, tx_t
*tx_opaque
, int len
, struct ieee80211_tx_control
*ieeectl
,
426 struct sk_buff
*skb
);
428 acx_l_tx_data(acx_device_t
*adev
, tx_t
*tx_opaque
, int len
,
429 struct ieee80211_tx_control
*ieeectl
, struct sk_buff
*skb
)
432 acxpci_l_tx_data(adev
, tx_opaque
, len
, ieeectl
,skb
);
434 acxusb_l_tx_data(adev
, tx_opaque
, len
, ieeectl
,skb
);
437 static inline struct ieee80211_hdr
*
438 acx_get_wlan_hdr(acx_device_t
*adev
, const rxbuffer_t
*rxbuf
)
440 return (struct ieee80211_hdr
*)((u8
*)&rxbuf
->hdr_a3
+ adev
->phy_header_len
);
442 void acxpci_l_power_led(acx_device_t
*adev
, int enable
);
443 int acxpci_read_eeprom_byte(acx_device_t
*adev
, u32 addr
, u8
*charbuf
);
444 unsigned int acxpci_l_clean_txdesc(acx_device_t
*adev
);
445 void acxpci_l_clean_txdesc_emergency(acx_device_t
*adev
);
446 int acxpci_s_create_hostdesc_queues(acx_device_t
*adev
);
447 void acxpci_create_desc_queues(acx_device_t
*adev
, u32 tx_queue_start
, u32 rx_queue_start
);
448 void acxpci_free_desc_queues(acx_device_t
*adev
);
449 char* acxpci_s_proc_diag_output(char *p
, acx_device_t
*adev
);
450 int acxpci_proc_eeprom_output(char *p
, acx_device_t
*adev
);
451 void acxpci_set_interrupt_mask(acx_device_t
*adev
);
452 int acx100pci_s_set_tx_level(acx_device_t
*adev
, u8 level_dbm
);
454 void acx_s_mwait(int ms
);
455 int acx_s_init_mac(acx_device_t
*adev
);
456 void acx_set_reg_domain(acx_device_t
*adev
, unsigned char reg_dom_id
);
457 void acx_update_capabilities(acx_device_t
*adev
);
458 void acx_s_start(acx_device_t
*adev
);
460 void acx_s_update_card_settings(acx_device_t
*adev
);
461 void acx_s_parse_configoption(acx_device_t
*adev
, const acx111_ie_configoption_t
*pcfg
);
462 void acx_l_update_ratevector(acx_device_t
*adev
);
464 void acx_init_task_scheduler(acx_device_t
*adev
);
465 void acx_schedule_task(acx_device_t
*adev
, unsigned int set_flag
);
467 int acx_e_ioctl_old(struct net_device
*ndev
, struct ifreq
*ifr
, int cmd
);
469 client_t
*acx_l_sta_list_get(acx_device_t
*adev
, const u8
*address
);
470 void acx_l_sta_list_del(acx_device_t
*adev
, client_t
*clt
);
472 void acx_i_timer(unsigned long a
);
474 struct sk_buff
*acx_rxbuf_to_ether(acx_device_t
*adev
, rxbuffer_t
*rxbuf
);
475 int acx_ether_to_txbuf(acx_device_t
*adev
, void *txbuf
, const struct sk_buff
*skb
);
477 u8
acx_signal_determine_quality(u8 signal
, u8 noise
);
479 void acx_l_process_rxbuf(acx_device_t
*adev
, rxbuffer_t
*rxbuf
);
480 void acx_l_handle_txrate_auto(acx_device_t
*adev
, struct client
*txc
,
481 u16 intended_rate
, u8 rate100
, u16 rate111
, u8 error
,
484 void acx_dump_bytes(const void *, int);
486 u8
acx_rate111to100(u16
);
488 void acx_s_set_defaults(acx_device_t
*adev
);
491 static inline const char* acx_get_packet_type_string(u16 fc
) { return ""; }
493 const char* acx_get_packet_type_string(u16 fc
);
495 const char* acx_cmd_status_str(unsigned int state
);
497 /*** Devicescape functions ***/
498 int acx_setup_modes(acx_device_t
*adev
);
499 void acx_free_modes(acx_device_t
*adev
);
500 int acx_i_start_xmit(struct ieee80211_hw
* ieee
,
502 struct ieee80211_tx_control
*ctl
);
503 int acx_add_interface(struct ieee80211_hw
* ieee
,
504 struct ieee80211_if_init_conf
*conf
);
505 void acx_remove_interface(struct ieee80211_hw
* ieee
,
506 struct ieee80211_if_init_conf
*conf
);
507 int acx_net_reset(struct ieee80211_hw
* ieee
);
508 int acx_net_set_key(struct ieee80211_hw
*hw
,
509 enum set_key_cmd cmd
,
510 const u8
*local_addr
, const u8
*addr
,
511 struct ieee80211_key_conf
*key
);
513 extern int acx_config_interface(struct ieee80211_hw
* ieee
,
514 struct ieee80211_vif
*vif
,
515 struct ieee80211_if_conf
*conf
);
517 int acx_net_config(struct ieee80211_hw
* ieee
, struct ieee80211_conf
*conf
);
518 int acx_net_get_tx_stats(struct ieee80211_hw
* ieee
, struct ieee80211_tx_queue_stats
*stats
);
519 int acx_net_conf_tx(struct ieee80211_hw
* ieee
, int queue
,
520 const struct ieee80211_tx_queue_params
*params
);
521 //int acx_passive_scan(struct net_device *net_dev, int state, struct ieee80211_scan_conf *conf);
522 //static void acx_netdev_init(struct net_device *ndev);
523 int acxpci_s_reset_dev(acx_device_t
*adev
);
524 void acx_e_after_interrupt_task(struct work_struct
* work
);
525 void acx_i_set_multicast_list(struct ieee80211_hw
*hw
,
526 unsigned int changed_flags
,
527 unsigned int *total_flags
,
528 int mc_count
, struct dev_addr_list
*mc_list
);
530 /*** End DeviceScape Functions **/
532 void great_inquisitor(acx_device_t
*adev
);
534 void acx_s_get_firmware_version(acx_device_t
*adev
);
535 void acx_display_hardware_details(acx_device_t
*adev
);
537 int acx_e_change_mtu(struct ieee80211_hw
*hw
, int mtu
);
538 int acx_e_get_stats(struct ieee80211_hw
*hw
, struct ieee80211_low_level_stats
*stats
);
539 struct iw_statistics
* acx_e_get_wireless_stats(struct ieee80211_hw
*hw
);
540 void acx_interrupt_tasklet(struct work_struct
*work
);
542 int __init
acxpci_e_init_module(void);
543 int __init
acxusb_e_init_module(void);
544 void __exit
acxpci_e_cleanup_module(void);
545 void __exit
acxusb_e_cleanup_module(void);
547 #endif /* _ACX_FUNC_H_ */