4 /** (legal) claimer in README
5 ** Copyright (C) 2003 ACX100 Open Source Project
8 #include <linux/version.h>
10 /***********************************************************************
13 ** - Avoid SHOUTING needlessly. Avoid excessive verbosity.
14 ** Gradually remove messages which are old debugging aids.
16 ** - Use printk() for messages which are to be always logged.
17 ** Supply either 'acx:' or '<devname>:' prefix so that user
18 ** can figure out who's speaking among other kernel chatter.
19 ** acx: is for general issues (e.g. "acx: no firmware image!")
20 ** while <devname>: is related to a particular device
21 ** (think about multi-card setup). Double check that message
22 ** is not confusing to the average user.
24 ** - use printk KERN_xxx level only if message is not a WARNING
25 ** but is INFO, ERR etc.
27 ** - Use printk_ratelimited() for messages which may flood
28 ** (e.g. "rx DUP pkt!").
30 ** - Use log() for messages which may be omitted (and they
31 ** _will_ be omitted in non-debug builds). Note that
32 ** message levels may be disabled at compile-time selectively,
33 ** thus select them wisely. Example: L_DEBUG is the lowest
34 ** (most likely to be compiled out) -> use for less important stuff.
36 ** - Do not print important stuff with log(), or else people
37 ** will never build non-debug driver.
40 ** hex: capital letters, zero filled (e.g. 0x02AC)
41 ** str: dont start from capitals, no trailing periods ("tx: queue is stopped")
45 void log_fn_enter(const char *funcname
);
46 void log_fn_exit(const char *funcname
);
47 void log_fn_exit_v(const char *funcname
, int v
);
51 if (unlikely(acx_debug & L_FUNC)) { \
52 log_fn_enter(__func__); \
58 if (unlikely(acx_debug & L_FUNC)) { \
59 log_fn_exit_v(__func__, v); \
64 if (unlikely(acx_debug & L_FUNC)) { \
65 log_fn_exit(__func__); \
75 #endif /* ACX_DEBUG > 1 */
80 #define log(chan, args...) \
82 if (acx_debug & (chan)) \
85 #define printk_ratelimited(args...) printk(args)
87 #else /* Non-debug build: */
89 #define log(chan, args...)
90 /* Standard way of log flood prevention */
91 #define printk_ratelimited(args...) \
93 if (printk_ratelimit()) \
97 #endif /* ACX_DEBUG */
99 void acx_print_mac(const char *head
, const u8
*mac
, const char *tail
);
101 /* Optimized out to nothing in non-debug build */
103 acxlog_mac(int level
, const char *head
, const u8
*mac
, const char *tail
)
105 if (acx_debug
& level
) {
106 acx_print_mac(head
, mac
, tail
);
111 /***********************************************************************
112 ** MAC address helpers
115 MAC_COPY(u8
*mac
, const u8
*src
)
117 memcpy(mac
, src
, ETH_ALEN
);
121 MAC_FILL(u8
*mac
, u8 val
)
123 memset(mac
, val
, ETH_ALEN
);
129 ((u16
*)mac
)[2] = *(u32
*)mac
= -1;
135 ((u16
*)mac
)[2] = *(u32
*)mac
= 0;
139 mac_is_equal(const u8
*a
, const u8
*b
)
141 /* can't beat this */
142 return memcmp(a
, b
, ETH_ALEN
) == 0;
146 mac_is_bcast(const u8
*mac
)
148 /* AND together 4 first bytes with sign-extended 2 last bytes
149 ** Only bcast address gives 0xffffffff. +1 gives 0 */
150 return ( *(s32
*)mac
& ((s16
*)mac
)[2] ) + 1 == 0;
154 mac_is_zero(const u8
*mac
)
156 return ( *(u32
*)mac
| ((u16
*)mac
)[2] ) == 0;
160 mac_is_directed(const u8
*mac
)
162 return (mac
[0] & 1)==0;
166 mac_is_mcast(const u8
*mac
)
168 return (mac
[0] & 1) && !mac_is_bcast(mac
);
171 #define MACSTR "%02X:%02X:%02X:%02X:%02X:%02X"
172 #define MAC(bytevector) \
173 ((unsigned char *)bytevector)[0], \
174 ((unsigned char *)bytevector)[1], \
175 ((unsigned char *)bytevector)[2], \
176 ((unsigned char *)bytevector)[3], \
177 ((unsigned char *)bytevector)[4], \
178 ((unsigned char *)bytevector)[5]
181 /***********************************************************************
184 #define TO_STRING(x) #x
185 #define STRING(x) TO_STRING(x)
187 #define CLEAR_BIT(val, mask) ((val) &= ~(mask))
188 #define SET_BIT(val, mask) ((val) |= (mask))
189 #define CHECK_BIT(val, mask) ((val) & (mask))
191 /* undefined if v==0 */
192 static inline unsigned int
196 while (!(v
& 0xf)) { v
>>=4; n
+=4; }
197 while (!(v
& 1)) { v
>>=1; n
++; }
201 /* undefined if v==0 */
202 static inline unsigned int
206 while (v
>0xf) { v
>>=4; n
+=4; }
207 while (v
>1) { v
>>=1; n
++; }
211 /* undefined if v==0 */
213 has_only_one_bit(u16 v
)
215 return ((v
-1) ^ v
) >= v
;
220 is_hidden_essid(char *essid
)
222 return (('\0' == essid
[0]) ||
223 ((' ' == essid
[0]) && ('\0' == essid
[1])));
226 /***********************************************************************
228 ** We have adev->sem and adev->spinlock.
230 ** We employ following naming convention in order to get locking right:
232 ** acx_e_xxxx - external entry points called from process context.
233 ** It is okay to sleep. adev->sem is to be taken on entry.
234 ** acx_i_xxxx - external entry points possibly called from atomic context.
235 ** Sleeping is not allowed (and thus down(sem) is not legal!)
236 ** acx_s_xxxx - potentially sleeping functions. Do not ever call under lock!
237 ** acx_l_xxxx - functions which expect lock to be already taken.
238 ** rest - non-sleeping functions which do not require locking
239 ** but may be run under lock
241 ** A small number of local helpers do not have acx_[eisl]_ prefix.
242 ** They are always close to caller and are to be reviewed locally.
244 ** Theory of operation:
246 ** All process-context entry points (_e_ functions) take sem
247 ** immediately. IRQ handler and other 'atomic-context' entry points
248 ** (_i_ functions) take lock immediately on entry, but dont take sem
249 ** because that might sleep.
251 ** Thus *all* code is either protected by sem or lock, or both.
253 ** Code which must not run concurrently with IRQ takes lock.
254 ** Such code is marked with _l_.
256 ** This results in the following rules of thumb useful in code review:
258 ** + If a function calls _s_ fn, it must be an _s_ itself.
259 ** + You can call _l_ fn only (a) from another _l_ fn
260 ** or (b) from _s_, _e_ or _i_ fn by taking lock, calling _l_,
261 ** and dropping lock.
262 ** + All IRQ code runs under lock.
263 ** + Any _s_ fn is running under sem.
264 ** + Code under sem can race only with IRQ code.
265 ** + Code under sem+lock cannot race with anything.
268 /* These functions *must* be inline or they will break horribly on SPARC, due
269 * to its weird semantics for save/restore flags */
271 #if defined(PARANOID_LOCKING) /* Lock debugging */
273 void acx_lock_debug(acx_device_t
*adev
, const char* where
);
274 void acx_unlock_debug(acx_device_t
*adev
, const char* where
);
275 void acx_down_debug(acx_device_t
*adev
, const char* where
);
276 void acx_up_debug(acx_device_t
*adev
, const char* where
);
277 void acx_lock_unhold(void);
278 void acx_sem_unhold(void);
281 acx_lock_helper(acx_device_t
*adev
, unsigned long *fp
, const char* where
)
283 acx_lock_debug(adev
, where
);
284 spin_lock_irqsave(&adev
->spinlock
, *fp
);
287 acx_unlock_helper(acx_device_t
*adev
, unsigned long *fp
, const char* where
)
289 acx_unlock_debug(adev
, where
);
290 spin_unlock_irqrestore(&adev
->spinlock
, *fp
);
292 #define acx_lock(adev, flags) acx_lock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
293 #define acx_unlock(adev, flags) acx_unlock_helper(adev, &(flags), __FILE__ ":" STRING(__LINE__))
294 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
295 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
297 #elif defined(DO_LOCKING)
299 #define acx_lock(adev, flags) spin_lock_irqsave(&adev->spinlock, flags)
300 #define acx_unlock(adev, flags) spin_unlock_irqrestore(&adev->spinlock, flags)
301 #define acx_sem_lock(adev) mutex_lock(&(adev)->mutex)
302 #define acx_sem_unlock(adev) mutex_unlock(&(adev)->mutex)
303 #define acx_lock_unhold() ((void)0)
304 #define acx_sem_unhold() ((void)0)
306 #else /* no locking! :( */
308 #define acx_lock(adev, flags) ((void)0)
309 #define acx_unlock(adev, flags) ((void)0)
310 #define acx_sem_lock(adev) ((void)0)
311 #define acx_sem_unlock(adev) ((void)0)
312 #define acx_lock_unhold() ((void)0)
313 #define acx_sem_unhold() ((void)0)
318 /***********************************************************************
321 /* Can race with rx path (which is not protected by sem):
322 ** rx -> process_[re]assocresp() -> set_status(ASSOCIATED) -> wake_queue()
323 ** Can race with tx_complete IRQ:
324 ** IRQ -> acxpci_l_clean_txdesc -> acx_wake_queue
325 ** Review carefully all callsites */
327 acx_stop_queue(struct ieee80211_hw
*hw
, const char *msg
)
329 if (netif_queue_stopped(ndev))
332 ieee80211_stop_queues(hw
);
334 log(L_BUFT
, "tx: stop queue %s\n", msg
);
338 acx_queue_stopped(struct ieee80211_hw *ieee)
340 return netif_queue_stopped(ieee);
345 acx_start_queue(struct ieee80211_hw *hw, const char *msg)
347 ieee80211_start_queues(hw);
349 log(L_BUFT, "tx: start queue %s\n", msg);
353 acx_wake_queue(struct ieee80211_hw
*hw
, const char *msg
)
355 ieee80211_wake_queues(hw
);
357 log(L_BUFT
, "tx: wake queue %s\n", msg
);
361 acx_carrier_off(struct net_device *ndev, const char *msg)
363 netif_carrier_off(ndev);
365 log(L_BUFT, "tx: carrier off %s\n", msg);
369 acx_carrier_on(struct net_device *ndev, const char *msg)
371 netif_carrier_on(ndev);
373 log(L_BUFT, "tx: carrier on %s\n", msg);
379 /***********************************************************************
380 ** Communication with firmware
382 #define CMD_TIMEOUT_MS(n) (n)
383 #define ACX_CMD_TIMEOUT_DEFAULT CMD_TIMEOUT_MS(50)
387 /* We want to log cmd names */
388 int acxpci_s_issue_cmd_timeo_debug(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
, const char* cmdstr
);
389 int acxusb_s_issue_cmd_timeo_debug(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
, const char* cmdstr
);
391 acx_s_issue_cmd_timeo_debug(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
, const char* cmdstr
)
394 return acxpci_s_issue_cmd_timeo_debug(adev
, cmd
, param
, len
, timeout
, cmdstr
);
395 return acxusb_s_issue_cmd_timeo_debug(adev
, cmd
, param
, len
, timeout
, cmdstr
);
397 #define acx_s_issue_cmd(adev,cmd,param,len) \
398 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,ACX_CMD_TIMEOUT_DEFAULT,#cmd)
399 #define acx_s_issue_cmd_timeo(adev,cmd,param,len,timeo) \
400 acx_s_issue_cmd_timeo_debug(adev,cmd,param,len,timeo,#cmd)
401 int acx_s_configure_debug(acx_device_t
*adev
, void *pdr
, int type
, const char* str
);
402 #define acx_s_configure(adev,pdr,type) \
403 acx_s_configure_debug(adev,pdr,type,#type)
404 int acx_s_interrogate_debug(acx_device_t
*adev
, void *pdr
, int type
, const char* str
);
405 #define acx_s_interrogate(adev,pdr,type) \
406 acx_s_interrogate_debug(adev,pdr,type,#type)
410 int acxpci_s_issue_cmd_timeo(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
);
411 int acxusb_s_issue_cmd_timeo(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
);
413 acx_s_issue_cmd_timeo(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
, unsigned timeout
)
416 return acxpci_s_issue_cmd_timeo(adev
, cmd
, param
, len
, timeout
);
417 return acxusb_s_issue_cmd_timeo(adev
, cmd
, param
, len
, timeout
);
420 acx_s_issue_cmd(acx_device_t
*adev
, unsigned cmd
, void *param
, unsigned len
)
423 return acxpci_s_issue_cmd_timeo(adev
, cmd
, param
, len
, ACX_CMD_TIMEOUT_DEFAULT
);
424 return acxusb_s_issue_cmd_timeo(adev
, cmd
, param
, len
, ACX_CMD_TIMEOUT_DEFAULT
);
426 int acx_s_configure(acx_device_t
*adev
, void *pdr
, int type
);
427 int acx_s_interrogate(acx_device_t
*adev
, void *pdr
, int type
);
431 void acx_s_cmd_start_scan(acx_device_t
*adev
);
434 /***********************************************************************
438 acx111pci_ioctl_info(
439 struct net_device *ndev,
440 struct iw_request_info *info,
441 struct iw_param *vwrq,
444 acx100pci_ioctl_set_phy_amp_bias(
445 struct net_device *ndev,
446 struct iw_request_info *info,
447 struct iw_param *vwrq,
451 /***********************************************************************
454 #ifdef CONFIG_PROC_FS
455 int acx_proc_register_entries(struct ieee80211_hw
*ieee
);
456 int acx_proc_unregister_entries(struct ieee80211_hw
*ieee
);
459 acx_proc_register_entries(const struct ieee80211_hw
*ieee
) { return OK
; }
461 acx_proc_unregister_entries(const struct ieee80211_hw
*ieee
) { return OK
; }
465 /***********************************************************************
467 firmware_image_t
*acx_s_read_fw(struct device
*dev
, const char *file
, u32
*size
);
468 int acxpci_s_upload_radio(acx_device_t
*adev
);
471 /***********************************************************************
474 int acxpci_s_read_phy_reg(acx_device_t
*adev
, u32 reg
, u8
*charbuf
);
475 int acxusb_s_read_phy_reg(acx_device_t
*adev
, u32 reg
, u8
*charbuf
);
477 acx_s_read_phy_reg(acx_device_t
*adev
, u32 reg
, u8
*charbuf
)
480 return acxpci_s_read_phy_reg(adev
, reg
, charbuf
);
481 return acxusb_s_read_phy_reg(adev
, reg
, charbuf
);
484 int acxpci_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
);
485 int acxusb_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
);
487 acx_s_write_phy_reg(acx_device_t
*adev
, u32 reg
, u8 value
)
490 return acxpci_s_write_phy_reg(adev
, reg
, value
);
491 return acxusb_s_write_phy_reg(adev
, reg
, value
);
494 tx_t
* acxpci_l_alloc_tx(acx_device_t
*adev
);
495 tx_t
* acxusb_l_alloc_tx(acx_device_t
*adev
);
497 acx_l_alloc_tx(acx_device_t
*adev
)
500 return acxpci_l_alloc_tx(adev
);
501 return acxusb_l_alloc_tx(adev
);
504 void acxusb_l_dealloc_tx(tx_t
*tx_opaque
);
506 acx_l_dealloc_tx(acx_device_t
*adev
, tx_t
*tx_opaque
)
509 acxusb_l_dealloc_tx(tx_opaque
);
512 void* acxpci_l_get_txbuf(acx_device_t
*adev
, tx_t
*tx_opaque
);
513 void* acxusb_l_get_txbuf(acx_device_t
*adev
, tx_t
*tx_opaque
);
515 acx_l_get_txbuf(acx_device_t
*adev
, tx_t
*tx_opaque
)
518 return acxpci_l_get_txbuf(adev
, tx_opaque
);
519 return acxusb_l_get_txbuf(adev
, tx_opaque
);
522 void acxpci_l_tx_data(acx_device_t
*adev
, tx_t
*tx_opaque
, int len
,
523 struct ieee80211_tx_control
*ieeectl
, struct sk_buff
*skb
);
524 void acxusb_l_tx_data(acx_device_t
*adev
, tx_t
*tx_opaque
, int len
, struct ieee80211_tx_control
*ieeectl
,
525 struct sk_buff
*skb
);
527 acx_l_tx_data(acx_device_t
*adev
, tx_t
*tx_opaque
, int len
,
528 struct ieee80211_tx_control
*ieeectl
, struct sk_buff
*skb
)
531 acxpci_l_tx_data(adev
, tx_opaque
, len
, ieeectl
,skb
);
533 acxusb_l_tx_data(adev
, tx_opaque
, len
, ieeectl
,skb
);
536 static inline struct ieee80211_hdr
*
537 acx_get_wlan_hdr(acx_device_t
*adev
, const rxbuffer_t
*rxbuf
)
539 return (struct ieee80211_hdr
*)((u8
*)&rxbuf
->hdr_a3
+ adev
->phy_header_len
);
541 void acxpci_l_power_led(acx_device_t
*adev
, int enable
);
542 int acxpci_read_eeprom_byte(acx_device_t
*adev
, u32 addr
, u8
*charbuf
);
543 unsigned int acxpci_l_clean_txdesc(acx_device_t
*adev
);
544 void acxpci_l_clean_txdesc_emergency(acx_device_t
*adev
);
545 int acxpci_s_create_hostdesc_queues(acx_device_t
*adev
);
546 void acxpci_create_desc_queues(acx_device_t
*adev
, u32 tx_queue_start
, u32 rx_queue_start
);
547 void acxpci_free_desc_queues(acx_device_t
*adev
);
548 char* acxpci_s_proc_diag_output(char *p
, acx_device_t
*adev
);
549 int acxpci_proc_eeprom_output(char *p
, acx_device_t
*adev
);
550 void acxpci_set_interrupt_mask(acx_device_t
*adev
);
551 int acx100pci_s_set_tx_level(acx_device_t
*adev
, u8 level_dbm
);
553 void acx_s_mwait(int ms
);
554 int acx_s_init_mac(acx_device_t
*adev
);
555 void acx_set_reg_domain(acx_device_t
*adev
, unsigned char reg_dom_id
);
556 void acx_update_capabilities(acx_device_t
*adev
);
557 void acx_s_start(acx_device_t
*adev
);
559 void acx_s_update_card_settings(acx_device_t
*adev
);
560 void acx_s_parse_configoption(acx_device_t
*adev
, const acx111_ie_configoption_t
*pcfg
);
561 void acx_l_update_ratevector(acx_device_t
*adev
);
563 void acx_init_task_scheduler(acx_device_t
*adev
);
564 void acx_schedule_task(acx_device_t
*adev
, unsigned int set_flag
);
566 int acx_e_ioctl_old(struct net_device
*ndev
, struct ifreq
*ifr
, int cmd
);
568 client_t
*acx_l_sta_list_get(acx_device_t
*adev
, const u8
*address
);
569 void acx_l_sta_list_del(acx_device_t
*adev
, client_t
*clt
);
571 void acx_i_timer(unsigned long a
);
573 struct sk_buff
*acx_rxbuf_to_ether(acx_device_t
*adev
, rxbuffer_t
*rxbuf
);
574 int acx_ether_to_txbuf(acx_device_t
*adev
, void *txbuf
, const struct sk_buff
*skb
);
576 u8
acx_signal_determine_quality(u8 signal
, u8 noise
);
578 void acx_l_process_rxbuf(acx_device_t
*adev
, rxbuffer_t
*rxbuf
);
579 void acx_l_handle_txrate_auto(acx_device_t
*adev
, struct client
*txc
,
580 u16 intended_rate
, u8 rate100
, u16 rate111
, u8 error
,
583 void acx_dump_bytes(const void *, int);
585 u8
acx_rate111to100(u16
);
587 void acx_s_set_defaults(acx_device_t
*adev
);
590 static inline const char* acx_get_packet_type_string(u16 fc
) { return ""; }
592 const char* acx_get_packet_type_string(u16 fc
);
594 const char* acx_cmd_status_str(unsigned int state
);
596 /*** Devicescape functions ***/
597 int acx_setup_modes(acx_device_t
*adev
);
598 void acx_free_modes(acx_device_t
*adev
);
599 int acx_i_start_xmit(struct ieee80211_hw
* ieee
,
601 struct ieee80211_tx_control
*ctl
);
602 int acx_add_interface(struct ieee80211_hw
* ieee
,
603 struct ieee80211_if_init_conf
*conf
);
604 void acx_remove_interface(struct ieee80211_hw
* ieee
,
605 struct ieee80211_if_init_conf
*conf
);
606 int acx_net_reset(struct ieee80211_hw
* ieee
);
607 int acx_net_set_key(struct ieee80211_hw
*hw
,
608 enum set_key_cmd cmd
,
609 const u8
*local_addr
, const u8
*addr
,
610 struct ieee80211_key_conf
*key
);
612 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)
613 extern int acx_config_interface(struct ieee80211_hw
* ieee
,
614 struct ieee80211_vif
*vif
,
615 struct ieee80211_if_conf
*conf
);
617 int acx_config_interface(struct ieee80211_hw
* ieee
, int if_id
,
618 struct ieee80211_if_conf
*conf
);
621 int acx_net_config(struct ieee80211_hw
* ieee
, struct ieee80211_conf
*conf
);
622 int acx_net_get_tx_stats(struct ieee80211_hw
* ieee
, struct ieee80211_tx_queue_stats
*stats
);
623 int acx_net_conf_tx(struct ieee80211_hw
* ieee
, int queue
,
624 const struct ieee80211_tx_queue_params
*params
);
625 //int acx_passive_scan(struct net_device *net_dev, int state, struct ieee80211_scan_conf *conf);
626 //static void acx_netdev_init(struct net_device *ndev);
627 int acxpci_s_reset_dev(acx_device_t
*adev
);
628 void acx_e_after_interrupt_task(struct work_struct
* work
);
629 void acx_i_set_multicast_list(struct ieee80211_hw
*hw
,
630 unsigned int changed_flags
,
631 unsigned int *total_flags
,
632 int mc_count
, struct dev_addr_list
*mc_list
);
634 /*** End DeviceScape Functions **/
636 void great_inquisitor(acx_device_t
*adev
);
638 void acx_s_get_firmware_version(acx_device_t
*adev
);
639 void acx_display_hardware_details(acx_device_t
*adev
);
641 int acx_e_change_mtu(struct ieee80211_hw
*hw
, int mtu
);
642 int acx_e_get_stats(struct ieee80211_hw
*hw
, struct ieee80211_low_level_stats
*stats
);
643 struct iw_statistics
* acx_e_get_wireless_stats(struct ieee80211_hw
*hw
);
644 void acx_interrupt_tasklet(struct work_struct
*work
);
646 int __init
acxpci_e_init_module(void);
647 int __init
acxusb_e_init_module(void);
648 void __exit
acxpci_e_cleanup_module(void);
649 void __exit
acxusb_e_cleanup_module(void);
651 #endif /* _ACX_FUNC_H_ */